diff -Nru cpl-7.1.4+ds/acinclude.m4 cpl-7.2.2+ds/acinclude.m4 --- cpl-7.1.4+ds/acinclude.m4 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/acinclude.m4 2022-04-29 14:56:02.000000000 +0000 @@ -135,6 +135,7 @@ CPLDRS_INCLUDES="-I\$(top_srcdir)/cpldrs -I\$(top_builddir)/cpldrs" CPLUI_INCLUDES='-I$(top_srcdir)/cplui -I$(top_builddir)/cplui' CPLDFS_INCLUDES='-I$(top_srcdir)/cpldfs -I$(top_builddir)/cpldfs' + CPLJAVA_INCLUDES='-I$(top_srcdir)/cpljava -I$(top_builddir)/cpljava' CPL_INCLUDES="$CPLDFS_INCLUDES $CPLUI_INCLUDES $CPLDRS_INCLUDES $CPLCORE_INCLUDES" CPL_LDFLAGS="" @@ -143,6 +144,7 @@ AC_SUBST(CPLDRS_INCLUDES) AC_SUBST(CPLUI_INCLUDES) AC_SUBST(CPLDFS_INCLUDES) + AC_SUBST(CPLJAVA_INCLUDES) AC_SUBST(CPL_LDFLAGS) ]) @@ -260,21 +262,21 @@ cpl_java_path="" AC_ARG_WITH(java, - AC_HELP_STRING([--with-java], + AS_HELP_STRING([--with-java], [location where java is installed]), [ cpl_with_java=$withval ]) AC_ARG_WITH(java-includes, - AC_HELP_STRING([--with-java-includes], + AS_HELP_STRING([--with-java-includes], [location of the java header files]), [ cpl_with_java_includes=$withval ]) AC_ARG_WITH(java-includes-md, - AC_HELP_STRING([--with-java-includes-md], + AS_HELP_STRING([--with-java-includes-md], [location of the machine dependent java header files]), [ cpl_with_java_includes_md=$withval @@ -475,7 +477,7 @@ AC_REQUIRE([CPL_PATH_JAVA]) AC_ARG_ENABLE(gasgano, - AC_HELP_STRING([--enable-gasgano], + AS_HELP_STRING([--enable-gasgano], [build the gasgano support library [[default=yes]]]), cpl_enable_gasgano=$enableval, cpl_enable_gasgano=yes) @@ -524,7 +526,7 @@ AC_ARG_ENABLE(threads, - AC_HELP_STRING([--enable-threads], + AS_HELP_STRING([--enable-threads], [enables thread support [default=$1]]), cpl_enable_threads=$enableval, cpl_enable_threads=$1) @@ -612,7 +614,7 @@ libcext="libcext" AC_ARG_WITH(system-cext, - AC_HELP_STRING([--with-system-cext], + AS_HELP_STRING([--with-system-cext], [Use the system cext installation for building [default=no]]), [ cpl_with_system_cext=$withval @@ -660,7 +662,7 @@ AC_MSG_CHECKING([for extended memory mode]) AC_ARG_ENABLE(memory-mode, - AC_HELP_STRING([--enable-memory-mode=M], + AS_HELP_STRING([--enable-memory-mode=M], [where M=0 switches off the internal memory handling (default), M=1 exits the program whenever a memory allocation fails, @@ -672,7 +674,7 @@ ]) AC_ARG_ENABLE(max-ptrs, - AC_HELP_STRING([--enable-max-ptrs=MAXPTRS], + AS_HELP_STRING([--enable-max-ptrs=MAXPTRS], [MAXPTRS Set MAXPTRS as the maximum number of pointers allowed when using memory-mode=2 (200003)]), [ diff -Nru cpl-7.1.4+ds/aclocal.m4 cpl-7.2.2+ds/aclocal.m4 --- cpl-7.1.4+ds/aclocal.m4 2021-05-07 12:10:07.000000000 +0000 +++ cpl-7.2.2+ds/aclocal.m4 2022-04-29 14:56:27.000000000 +0000 @@ -1,6 +1,6 @@ -# generated automatically by aclocal 1.15.1 -*- Autoconf -*- +# generated automatically by aclocal 1.16.3 -*- Autoconf -*- -# Copyright (C) 1996-2017 Free Software Foundation, Inc. +# Copyright (C) 1996-2020 Free Software Foundation, Inc. # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -14,13 +14,13 @@ 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. +m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.71],, +[m4_warning([this file was generated for autoconf 2.71. 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-2017 Free Software Foundation, Inc. +# Copyright (C) 2002-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -32,10 +32,10 @@ # 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' +[am__api_version='1.16' 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.1], [], +m4_if([$1], [1.16.3], [], [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl ]) @@ -51,14 +51,14 @@ # 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.1])dnl +[AM_AUTOMAKE_VERSION([1.16.3])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-2017 Free Software Foundation, Inc. +# Copyright (C) 2001-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -110,7 +110,7 @@ # AM_CONDITIONAL -*- Autoconf -*- -# Copyright (C) 1997-2017 Free Software Foundation, Inc. +# Copyright (C) 1997-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -141,7 +141,7 @@ Usually this means the macro was only invoked conditionally.]]) fi])]) -# Copyright (C) 1999-2017 Free Software Foundation, Inc. +# Copyright (C) 1999-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -332,13 +332,12 @@ # Generate code to set up dependency tracking. -*- Autoconf -*- -# Copyright (C) 1999-2017 Free Software Foundation, Inc. +# Copyright (C) 1999-2020 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], @@ -346,49 +345,43 @@ # 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 + # TODO: see whether this extra hack can be removed once we start + # requiring Autoconf 2.70 or later. + AS_CASE([$CONFIG_FILES], + [*\'*], [eval set x "$CONFIG_FILES"], + [*], [set x $CONFIG_FILES]) shift - for mf + # Used to flag and report bootstrapping failures. + am_rc=0 + for am_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 + am_mf=`AS_ECHO(["$am_mf"]) | sed -e 's/:.*$//'` + # Check whether this is an Automake generated Makefile which includes + # dependency-tracking related rules and includes. + # Grep'ing the whole file directly is not great: 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 + sed -n 's,^am--depfiles:.*,X,p' "$am_mf" | grep X >/dev/null 2>&1 \ + || continue + am_dirpart=`AS_DIRNAME(["$am_mf"])` + am_filepart=`AS_BASENAME(["$am_mf"])` + AM_RUN_LOG([cd "$am_dirpart" \ + && sed -e '/# am--include-marker/d' "$am_filepart" \ + | $MAKE -f - am--depfiles]) || am_rc=$? done + if test $am_rc -ne 0; then + AC_MSG_FAILURE([Something went wrong bootstrapping makefile fragments + for automatic dependency tracking. If GNU make was not used, consider + re-running the configure script with MAKE="gmake" (or whatever is + necessary). You can also try re-running configure with the + '--disable-dependency-tracking' option to at least be able to build + the package (albeit without support for automatic dependency tracking).]) + fi + AS_UNSET([am_dirpart]) + AS_UNSET([am_filepart]) + AS_UNSET([am_mf]) + AS_UNSET([am_rc]) + rm -f conftest-deps.mk } ])# _AM_OUTPUT_DEPENDENCY_COMMANDS @@ -397,18 +390,17 @@ # ----------------------------- # 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. +# This code is only required when automatic dependency tracking is enabled. +# This creates each '.Po' and '.Plo' makefile fragment that we'll 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"]) -]) + [AMDEP_TRUE="$AMDEP_TRUE" MAKE="${MAKE-make}"])]) # Do all the work for Automake. -*- Autoconf -*- -# Copyright (C) 1996-2017 Free Software Foundation, Inc. +# Copyright (C) 1996-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -472,7 +464,7 @@ [_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]), + m4_ifset([AC_PACKAGE_NAME], [ok]):m4_ifset([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 @@ -495,8 +487,8 @@ 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. @@ -563,7 +555,7 @@ 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: . +that behaves properly: . If you want to complete the configuration process using your problematic 'rm' anyway, export the environment variable ACCEPT_INFERIOR_RM_PROGRAM @@ -605,7 +597,7 @@ done echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count]) -# Copyright (C) 2001-2017 Free Software Foundation, Inc. +# Copyright (C) 2001-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -626,7 +618,7 @@ fi AC_SUBST([install_sh])]) -# Copyright (C) 2003-2017 Free Software Foundation, Inc. +# Copyright (C) 2003-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -648,7 +640,7 @@ # Add --enable-maintainer-mode option to configure. -*- Autoconf -*- # From Jim Meyering -# Copyright (C) 1996-2017 Free Software Foundation, Inc. +# Copyright (C) 1996-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -683,7 +675,7 @@ # Check to see how 'make' treats includes. -*- Autoconf -*- -# Copyright (C) 2001-2017 Free Software Foundation, Inc. +# Copyright (C) 2001-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -691,49 +683,42 @@ # AM_MAKE_INCLUDE() # ----------------- -# Check to see how make treats includes. +# Check whether make has an 'include' directive that can support all +# the idioms we need for our automatic dependency tracking code. AC_DEFUN([AM_MAKE_INCLUDE], -[am_make=${MAKE-make} -cat > confinc << 'END' +[AC_MSG_CHECKING([whether ${MAKE-make} supports the include directive]) +cat > confinc.mk << 'END' am__doit: - @echo this is the am__doit target + @echo this is the am__doit target >confinc.out .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 -]) +# BSD make does it like this. +echo '.include "confinc.mk" # ignored' > confmf.BSD +# Other make implementations (GNU, Solaris 10, AIX) do it like this. +echo 'include confinc.mk # ignored' > confmf.GNU +_am_result=no +for s in GNU BSD; do + AM_RUN_LOG([${MAKE-make} -f confmf.$s && cat confinc.out]) + AS_CASE([$?:`cat confinc.out 2>/dev/null`], + ['0:this is the am__doit target'], + [AS_CASE([$s], + [BSD], [am__include='.include' am__quote='"'], + [am__include='include' am__quote=''])]) + if test "$am__include" != "#"; then + _am_result="yes ($s style)" + break + fi +done +rm -f confinc.* confmf.* +AC_MSG_RESULT([${_am_result}]) +AC_SUBST([am__include])]) +AC_SUBST([am__quote])]) # Fake the existence of programs that GNU maintainers use. -*- Autoconf -*- -# Copyright (C) 1997-2017 Free Software Foundation, Inc. +# Copyright (C) 1997-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -754,12 +739,7 @@ [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 + MISSING="\${SHELL} '$am_aux_dir/missing'" fi # Use eval to expand $SHELL if eval "$MISSING --is-lightweight"; then @@ -772,7 +752,7 @@ # Helper functions for option handling. -*- Autoconf -*- -# Copyright (C) 2001-2017 Free Software Foundation, Inc. +# Copyright (C) 2001-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -801,7 +781,7 @@ AC_DEFUN([_AM_IF_OPTION], [m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])]) -# Copyright (C) 1999-2017 Free Software Foundation, Inc. +# Copyright (C) 1999-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -848,7 +828,7 @@ # For backward compatibility. AC_DEFUN_ONCE([AM_PROG_CC_C_O], [AC_REQUIRE([AC_PROG_CC])]) -# Copyright (C) 2001-2017 Free Software Foundation, Inc. +# Copyright (C) 2001-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -867,7 +847,7 @@ # Check to make sure that the build environment is sane. -*- Autoconf -*- -# Copyright (C) 1996-2017 Free Software Foundation, Inc. +# Copyright (C) 1996-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -948,7 +928,7 @@ rm -f conftest.file ]) -# Copyright (C) 2009-2017 Free Software Foundation, Inc. +# Copyright (C) 2009-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -1008,7 +988,7 @@ _AM_SUBST_NOTMAKE([AM_BACKSLASH])dnl ]) -# Copyright (C) 2001-2017 Free Software Foundation, Inc. +# Copyright (C) 2001-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -1036,7 +1016,7 @@ INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s" AC_SUBST([INSTALL_STRIP_PROGRAM])]) -# Copyright (C) 2006-2017 Free Software Foundation, Inc. +# Copyright (C) 2006-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -1055,7 +1035,7 @@ # Check how to create a tarball. -*- Autoconf -*- -# Copyright (C) 2004-2017 Free Software Foundation, Inc. +# Copyright (C) 2004-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, diff -Nru cpl-7.1.4+ds/admin/compile cpl-7.2.2+ds/admin/compile --- cpl-7.1.4+ds/admin/compile 2021-05-07 12:10:10.000000000 +0000 +++ cpl-7.2.2+ds/admin/compile 2022-04-29 14:56:28.000000000 +0000 @@ -1,9 +1,9 @@ #! /bin/sh # Wrapper for compilers which do not understand '-c -o'. -scriptversion=2016-01-11.22; # UTC +scriptversion=2018-03-07.03; # UTC -# Copyright (C) 1999-2017 Free Software Foundation, Inc. +# Copyright (C) 1999-2020 Free Software Foundation, Inc. # Written by Tom Tromey . # # This program is free software; you can redistribute it and/or modify @@ -17,7 +17,7 @@ # 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 . +# 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 @@ -53,7 +53,7 @@ MINGW*) file_conv=mingw ;; - CYGWIN*) + CYGWIN* | MSYS*) file_conv=cygwin ;; *) @@ -67,7 +67,7 @@ mingw/*) file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` ;; - cygwin/*) + cygwin/* | msys/*) file=`cygpath -m "$file" || echo "$file"` ;; wine/*) @@ -340,7 +340,7 @@ # Local Variables: # mode: shell-script # sh-indentation: 2 -# eval: (add-hook 'write-file-hooks 'time-stamp) +# eval: (add-hook 'before-save-hook 'time-stamp) # time-stamp-start: "scriptversion=" # time-stamp-format: "%:y-%02m-%02d.%02H" # time-stamp-time-zone: "UTC0" diff -Nru cpl-7.1.4+ds/admin/config.guess cpl-7.2.2+ds/admin/config.guess --- cpl-7.1.4+ds/admin/config.guess 2021-05-07 12:10:10.000000000 +0000 +++ cpl-7.2.2+ds/admin/config.guess 2022-04-29 14:56:28.000000000 +0000 @@ -1,8 +1,8 @@ #! /bin/sh # Attempt to guess a canonical system name. -# Copyright 1992-2017 Free Software Foundation, Inc. +# Copyright 1992-2021 Free Software Foundation, Inc. -timestamp='2017-05-27' +timestamp='2021-01-25' # 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 @@ -15,7 +15,7 @@ # 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 . +# 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 @@ -27,19 +27,19 @@ # 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 +# https://git.savannah.gnu.org/cgit/config.git/plain/config.guess # # Please send patches to . -me=`echo "$0" | sed -e 's,.*/,,'` +me=$(echo "$0" | sed -e 's,.*/,,') usage="\ Usage: $0 [OPTION] Output the configuration name of the system \`$me' is run on. -Operation modes: +Options: -h, --help print this help, then exit -t, --time-stamp print date of last modification, then exit -v, --version print version number, then exit @@ -50,7 +50,7 @@ GNU config.guess ($timestamp) Originally written by Per Bothner. -Copyright 1992-2017 Free Software Foundation, Inc. +Copyright 1992-2021 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." @@ -84,8 +84,6 @@ 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 @@ -96,76 +94,89 @@ # 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= ;' +tmp= +# shellcheck disable=SC2172 +trap 'test -z "$tmp" || rm -fr "$tmp"' 0 1 2 13 15 + +set_cc_for_build() { + # prevent multiple calls if $tmp is already set + test "$tmp" && return 0 + : "${TMPDIR=/tmp}" + # shellcheck disable=SC2039 + { 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" 2>/dev/null) ; } || + { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir "$tmp" 2>/dev/null) && echo "Warning: creating insecure temp directory" >&2 ; } || + { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } + dummy=$tmp/dummy + case ${CC_FOR_BUILD-},${HOST_CC-},${CC-} in + ,,) echo "int x;" > "$dummy.c" + for driver in cc gcc c89 c99 ; do + if ($driver -c -o "$dummy.o" "$dummy.c") >/dev/null 2>&1 ; then + CC_FOR_BUILD="$driver" + 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 +} # 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 +if test -f /.attbin/uname ; 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 +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 +case "$UNAME_SYSTEM" in Linux|GNU|GNU/*) - # If the system lacks a compiler, then just pick glibc. - # We could probably try harder. - LIBC=gnu + LIBC=unknown - eval $set_cc_for_build - cat <<-EOF > $dummy.c + set_cc_for_build + cat <<-EOF > "$dummy.c" #include #if defined(__UCLIBC__) LIBC=uclibc #elif defined(__dietlibc__) LIBC=dietlibc - #else + #elif defined(__GLIBC__) LIBC=gnu + #else + #include + /* First heuristic to detect musl libc. */ + #ifdef __DEFINED_va_list + LIBC=musl + #endif #endif EOF - eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^LIBC' | sed 's, ,,g'` - ;; -esac + eval "$($CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^LIBC' | sed 's, ,,g')" + + # Second heuristic to detect musl libc. + if [ "$LIBC" = unknown ] && + command -v ldd >/dev/null && + ldd --version 2>&1 | grep -q ^musl; then + LIBC=musl + fi -case "${UNAME_MACHINE}" in - i?86) - test -z "$VENDOR" && VENDOR=pc - ;; - *) - test -z "$VENDOR" && VENDOR=unknown - ;; + # If the system lacks a compiler, then just pick glibc. + # We could probably try harder. + if [ "$LIBC" = unknown ]; then + LIBC=gnu + fi + ;; esac -test -f /etc/SuSE-release -o -f /.buildenv && VENDOR=suse # Note: order is significant - the case branches are not exclusive. -case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in +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*, @@ -177,32 +188,32 @@ # # 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=`(uname -p 2>/dev/null || \ - /sbin/$sysctl 2>/dev/null || \ - /usr/sbin/$sysctl 2>/dev/null || \ - echo unknown)` - case "${UNAME_MACHINE_ARCH}" in + UNAME_MACHINE_ARCH=$( (uname -p 2>/dev/null || \ + /sbin/sysctl -n hw.machine_arch 2>/dev/null || \ + /usr/sbin/sysctl -n hw.machine_arch 2>/dev/null || \ + echo unknown)) + case "$UNAME_MACHINE_ARCH" in + aarch64eb) machine=aarch64_be-unknown ;; armeb) machine=armeb-unknown ;; arm*) machine=arm-unknown ;; sh3el) machine=shl-unknown ;; sh3eb) machine=sh-unknown ;; sh5el) machine=sh5le-unknown ;; earmv*) - arch=`echo ${UNAME_MACHINE_ARCH} | sed -e 's,^e\(armv[0-9]\).*$,\1,'` - endian=`echo ${UNAME_MACHINE_ARCH} | sed -ne 's,^.*\(eb\)$,\1,p'` - machine=${arch}${endian}-${VENDOR}-unknown + arch=$(echo "$UNAME_MACHINE_ARCH" | sed -e 's,^e\(armv[0-9]\).*$,\1,') + endian=$(echo "$UNAME_MACHINE_ARCH" | sed -ne 's,^.*\(eb\)$,\1,p') + machine="${arch}${endian}"-unknown ;; - *) machine=${UNAME_MACHINE_ARCH}-${VENDOR}-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) and ABI. - case "${UNAME_MACHINE_ARCH}" in + case "$UNAME_MACHINE_ARCH" in earm*) os=netbsdelf ;; arm*|i386|m68k|ns32k|sh3*|sparc|vax) - eval $set_cc_for_build + set_cc_for_build if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \ | grep -q __ELF__ then @@ -218,10 +229,10 @@ ;; esac # Determine ABI tags. - case "${UNAME_MACHINE_ARCH}" in + case "$UNAME_MACHINE_ARCH" in earm*) expr='s/^earmv[0-9]/-eabi/;s/eb$//' - abi=`echo ${UNAME_MACHINE_ARCH} | sed -e "$expr"` + abi=$(echo "$UNAME_MACHINE_ARCH" | sed -e "$expr") ;; esac # The OS release @@ -229,60 +240,75 @@ # 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 + case "$UNAME_VERSION" in Debian*) release='-gnu' ;; *) - release=`echo ${UNAME_RELEASE} | sed -e 's/[-_].*//' | cut -d. -f1,2` + release=$(echo "$UNAME_RELEASE" | sed -e 's/[-_].*//' | cut -d. -f1,2) ;; 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}${abi}" + echo "$machine-${os}${release}${abi-}" exit ;; *:Bitrig:*:*) - UNAME_MACHINE_ARCH=`arch | sed 's/Bitrig.//'` - echo ${UNAME_MACHINE_ARCH}-${VENDOR}-bitrig${UNAME_RELEASE} + 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}-${VENDOR}-openbsd${UNAME_RELEASE} + UNAME_MACHINE_ARCH=$(arch | sed 's/OpenBSD.//') + echo "$UNAME_MACHINE_ARCH"-unknown-openbsd"$UNAME_RELEASE" exit ;; *:LibertyBSD:*:*) - UNAME_MACHINE_ARCH=`arch | sed 's/^.*BSD\.//'` - echo ${UNAME_MACHINE_ARCH}-${VENDOR}-libertybsd${UNAME_RELEASE} + UNAME_MACHINE_ARCH=$(arch | sed 's/^.*BSD\.//') + echo "$UNAME_MACHINE_ARCH"-unknown-libertybsd"$UNAME_RELEASE" + exit ;; + *:MidnightBSD:*:*) + echo "$UNAME_MACHINE"-unknown-midnightbsd"$UNAME_RELEASE" exit ;; *:ekkoBSD:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-ekkobsd${UNAME_RELEASE} + echo "$UNAME_MACHINE"-unknown-ekkobsd"$UNAME_RELEASE" exit ;; *:SolidBSD:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-solidbsd${UNAME_RELEASE} + echo "$UNAME_MACHINE"-unknown-solidbsd"$UNAME_RELEASE" + exit ;; + *:OS108:*:*) + echo "$UNAME_MACHINE"-unknown-os108_"$UNAME_RELEASE" exit ;; macppc:MirBSD:*:*) - echo powerpc-${VENDOR}-mirbsd${UNAME_RELEASE} + echo powerpc-unknown-mirbsd"$UNAME_RELEASE" exit ;; *:MirBSD:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-mirbsd${UNAME_RELEASE} + echo "$UNAME_MACHINE"-unknown-mirbsd"$UNAME_RELEASE" exit ;; *:Sortix:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-sortix + echo "$UNAME_MACHINE"-unknown-sortix + exit ;; + *:Twizzler:*:*) + echo "$UNAME_MACHINE"-unknown-twizzler + exit ;; + *:Redox:*:*) + echo "$UNAME_MACHINE"-unknown-redox + exit ;; + mips:OSF1:*.*) + echo mips-dec-osf1 exit ;; alpha:OSF1:*:*) case $UNAME_RELEASE in *4.0) - UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` + UNAME_RELEASE=$(/usr/sbin/sizer -v | awk '{print $3}') ;; *5.*) - UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'` + 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` + 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 ;; @@ -320,28 +346,19 @@ # 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` + 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-${VENDOR}-sysv4 + echo m68k-unknown-sysv4 exit ;; *:[Aa]miga[Oo][Ss]:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-amigaos + echo "$UNAME_MACHINE"-unknown-amigaos exit ;; *:[Mm]orph[Oo][Ss]:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-morphos + echo "$UNAME_MACHINE"-unknown-morphos exit ;; *:OS/390:*:*) echo i370-ibm-openedition @@ -353,17 +370,17 @@ echo powerpc-ibm-os400 exit ;; arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) - echo arm-acorn-riscix${UNAME_RELEASE} + echo arm-acorn-riscix"$UNAME_RELEASE" exit ;; arm*:riscos:*:*|arm*:RISCOS:*:*) - echo arm-${VENDOR}-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 + if test "$( (/bin/universe) 2>/dev/null)" = att ; then echo pyramid-pyramid-sysv3 else echo pyramid-pyramid-bsd @@ -376,28 +393,28 @@ echo sparc-icl-nx6 exit ;; DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*) - case `/usr/bin/uname -p` in + 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/[^.]*//'` + 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/[^.]*//'` + 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/[^.]*//'` + echo sparc-sun-solaris2"$(echo "$UNAME_RELEASE" | sed -e 's/[^.]*//')" exit ;; i86pc:AuroraUX:5.*:* | i86xen:AuroraUX:5.*:*) - echo i386-pc-auroraux${UNAME_RELEASE} + echo i386-pc-auroraux"$UNAME_RELEASE" exit ;; i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*) - eval $set_cc_for_build + 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 test "$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 @@ -405,40 +422,40 @@ SUN_ARCH=x86_64 fi fi - echo ${SUN_ARCH}-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + 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/[^.]*//'` + echo sparc-sun-solaris3"$(echo "$UNAME_RELEASE"|sed -e 's/[^.]*//')" exit ;; sun4*:SunOS:*:*) - case "`/usr/bin/arch -k`" in + case "$(/usr/bin/arch -k)" in Series*|S4*) - UNAME_RELEASE=`uname -v` + 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/-/_/'` + echo sparc-sun-sunos"$(echo "$UNAME_RELEASE"|sed -e 's/-/_/')" exit ;; sun3*:SunOS:*:*) - echo m68k-sun-sunos${UNAME_RELEASE} + 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 + 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} + echo m68k-sun-sunos"$UNAME_RELEASE" ;; sun4) - echo sparc-sun-sunos${UNAME_RELEASE} + echo sparc-sun-sunos"$UNAME_RELEASE" ;; esac exit ;; aushp:SunOS:*:*) - echo sparc-auspex-sunos${UNAME_RELEASE} + 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 @@ -449,44 +466,44 @@ # 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} + echo m68k-atari-mint"$UNAME_RELEASE" exit ;; atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) - echo m68k-atari-mint${UNAME_RELEASE} + echo m68k-atari-mint"$UNAME_RELEASE" exit ;; *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) - echo m68k-atari-mint${UNAME_RELEASE} + echo m68k-atari-mint"$UNAME_RELEASE" exit ;; milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) - echo m68k-milan-mint${UNAME_RELEASE} + echo m68k-milan-mint"$UNAME_RELEASE" exit ;; hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) - echo m68k-hades-mint${UNAME_RELEASE} + echo m68k-hades-mint"$UNAME_RELEASE" exit ;; *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) - echo m68k-${VENDOR}-mint${UNAME_RELEASE} + echo m68k-unknown-mint"$UNAME_RELEASE" exit ;; m68k:machten:*:*) - echo m68k-apple-machten${UNAME_RELEASE} + echo m68k-apple-machten"$UNAME_RELEASE" exit ;; powerpc:machten:*:*) - echo powerpc-apple-machten${UNAME_RELEASE} + echo powerpc-apple-machten"$UNAME_RELEASE" exit ;; RISC*:Mach:*:*) echo mips-dec-mach_bsd4.3 exit ;; RISC*:ULTRIX:*:*) - echo mips-dec-ultrix${UNAME_RELEASE} + echo mips-dec-ultrix"$UNAME_RELEASE" exit ;; VAX*:ULTRIX*:*:*) - echo vax-dec-ultrix${UNAME_RELEASE} + echo vax-dec-ultrix"$UNAME_RELEASE" exit ;; 2020:CLIX:*:* | 2430:CLIX:*:*) - echo clipper-intergraph-clix${UNAME_RELEASE} + echo clipper-intergraph-clix"$UNAME_RELEASE" exit ;; mips:*:*:UMIPS | mips:*:*:RISCos) - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c + set_cc_for_build + sed 's/^ //' << EOF > "$dummy.c" #ifdef __cplusplus #include /* for printf() prototype */ int main (int argc, char *argv[]) { @@ -495,23 +512,23 @@ #endif #if defined (host_mips) && defined (MIPSEB) #if defined (SYSTYPE_SYSV) - printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0); + 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); + 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); + 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` && + $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} + echo mips-mips-riscos"$UNAME_RELEASE" exit ;; Motorola:PowerMAX_OS:*:*) echo powerpc-motorola-powermax @@ -536,18 +553,18 @@ exit ;; AViiON:dgux:*:*) # DG/UX returns AViiON for all architectures - UNAME_PROCESSOR=`/usr/bin/uname -p` - if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ] + UNAME_PROCESSOR=$(/usr/bin/uname -p) + if test "$UNAME_PROCESSOR" = mc88100 || test "$UNAME_PROCESSOR" = mc88110 then - if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \ - [ ${TARGET_BINARY_INTERFACE}x = x ] + if test "$TARGET_BINARY_INTERFACE"x = m88kdguxelfx || \ + test "$TARGET_BINARY_INTERFACE"x = x then - echo m88k-dg-dgux${UNAME_RELEASE} + echo m88k-dg-dgux"$UNAME_RELEASE" else - echo m88k-dg-dguxbcs${UNAME_RELEASE} + echo m88k-dg-dguxbcs"$UNAME_RELEASE" fi else - echo i586-dg-dgux${UNAME_RELEASE} + echo i586-dg-dgux"$UNAME_RELEASE" fi exit ;; M88*:DolphinOS:*:*) # DolphinOS (SVR3) @@ -564,26 +581,26 @@ echo m68k-tektronix-bsd exit ;; *:IRIX*:*:*) - echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'` + 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 ' + 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` + if test -x /usr/bin/oslevel ; then + IBM_REV=$(/usr/bin/oslevel) else - IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} + IBM_REV="$UNAME_VERSION.$UNAME_RELEASE" fi - echo ${UNAME_MACHINE}-ibm-aix${IBM_REV} + 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 + set_cc_for_build + sed 's/^ //' << EOF > "$dummy.c" #include main() @@ -594,7 +611,7 @@ exit(0); } EOF - if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` + if $CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=$("$dummy") then echo "$SYSTEM_NAME" else @@ -607,28 +624,28 @@ 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_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/` + if test -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} + IBM_REV="$UNAME_VERSION.$UNAME_RELEASE" fi - echo ${IBM_ARCH}-ibm-aix${IBM_REV} + echo "$IBM_ARCH"-ibm-aix"$IBM_REV" exit ;; *:AIX:*:*) echo rs6000-ibm-aix exit ;; - ibmrt:4.4BSD:*|romp-ibm:BSD:*) + ibmrt:4.4BSD:*|romp-ibm:4.4BSD:*) 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 + echo romp-ibm-bsd"$UNAME_RELEASE" # 4.3 with uname added to exit ;; # report: romp-ibm BSD 4.3 *:BOSX:*:*) echo rs6000-bull-bosx @@ -643,28 +660,28 @@ 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 ;; + 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 + if test -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 + 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 + if test "$HP_ARCH" = ""; then + set_cc_for_build + sed 's/^ //' << EOF > "$dummy.c" #define _HPUX_SOURCE #include @@ -697,13 +714,13 @@ exit (0); } EOF - (CCOPTS="" $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy` + (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 ] + if test "$HP_ARCH" = hppa2.0w then - eval $set_cc_for_build + 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 @@ -722,15 +739,15 @@ HP_ARCH=hppa64 fi fi - echo ${HP_ARCH}-hp-hpux${HPUX_REV} + 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} + 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 + set_cc_for_build + sed 's/^ //' << EOF > "$dummy.c" #include int main () @@ -755,11 +772,11 @@ exit (0); } EOF - $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` && + $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:*:* ) + 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:*) echo hppa1.1-hp-bsd exit ;; 9000/8??:4.3bsd:*:*) @@ -768,17 +785,17 @@ *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) echo hppa1.0-hp-mpeix exit ;; - hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* ) + 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}-${VENDOR}-osf1mk + if test -x /usr/sbin/sysversion ; then + echo "$UNAME_MACHINE"-unknown-osf1mk else - echo ${UNAME_MACHINE}-${VENDOR}-osf1 + echo "$UNAME_MACHINE"-unknown-osf1 fi exit ;; parisc*:Lites*:*:*) @@ -803,131 +820,123 @@ echo c4-convex-bsd exit ;; CRAY*Y-MP:*:*:*) - echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + echo ymp-cray-unicos"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/' exit ;; CRAY*[A-Z]90:*:*:*) - echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \ + 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/' + echo t90-cray-unicos"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/' exit ;; CRAY*T3E:*:*:*) - echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + echo alphaev5-cray-unicosmk"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/' exit ;; CRAY*SV1:*:*:*) - echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + echo sv1-cray-unicos"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/' exit ;; *:UNICOS/mp:*:*) - echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + 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/ /_/'` + 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/ /_/'` + 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} + echo "$UNAME_MACHINE"-pc-bsdi"$UNAME_RELEASE" exit ;; sparc*:BSD/OS:*:*) - echo sparc-${VENDOR}-bsdi${UNAME_RELEASE} + echo sparc-unknown-bsdi"$UNAME_RELEASE" exit ;; *:BSD/OS:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-bsdi${UNAME_RELEASE} + echo "$UNAME_MACHINE"-unknown-bsdi"$UNAME_RELEASE" + exit ;; + arm:FreeBSD:*:*) + UNAME_PROCESSOR=$(uname -p) + set_cc_for_build + if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \ + | grep -q __ARM_PCS_VFP + then + echo "${UNAME_PROCESSOR}"-unknown-freebsd"$(echo ${UNAME_RELEASE}|sed -e 's/[-(].*//')"-gnueabi + else + echo "${UNAME_PROCESSOR}"-unknown-freebsd"$(echo ${UNAME_RELEASE}|sed -e 's/[-(].*//')"-gnueabihf + fi exit ;; *:FreeBSD:*:*) - UNAME_PROCESSOR=`/usr/bin/uname -p` - case ${UNAME_PROCESSOR} in + UNAME_PROCESSOR=$(/usr/bin/uname -p) + case "$UNAME_PROCESSOR" in amd64) UNAME_PROCESSOR=x86_64 ;; i386) UNAME_PROCESSOR=i586 ;; esac - echo ${UNAME_PROCESSOR}-${VENDOR}-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` + echo "$UNAME_PROCESSOR"-unknown-freebsd"$(echo "$UNAME_RELEASE"|sed -e 's/[-(].*//')" exit ;; i*:CYGWIN*:*) - echo ${UNAME_MACHINE}-pc-cygwin + echo "$UNAME_MACHINE"-pc-cygwin exit ;; *:MINGW64*:*) - echo ${UNAME_MACHINE}-pc-mingw64 + echo "$UNAME_MACHINE"-pc-mingw64 exit ;; *:MINGW*:*) - echo ${UNAME_MACHINE}-pc-mingw32 + 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 + echo "$UNAME_MACHINE"-pc-msys exit ;; i*:PW*:*) - echo ${UNAME_MACHINE}-pc-pw32 + echo "$UNAME_MACHINE"-pc-pw32 exit ;; *:Interix*:*) - case ${UNAME_MACHINE} in + case "$UNAME_MACHINE" in x86) - echo i586-pc-interix${UNAME_RELEASE} + echo i586-pc-interix"$UNAME_RELEASE" exit ;; authenticamd | genuineintel | EM64T) - echo x86_64-${VENDOR}-interix${UNAME_RELEASE} + echo x86_64-unknown-interix"$UNAME_RELEASE" exit ;; IA64) - echo ia64-${VENDOR}-interix${UNAME_RELEASE} + 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 + echo "$UNAME_MACHINE"-pc-uwin exit ;; amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*) - echo x86_64-${VENDOR}-cygwin - exit ;; - p*:CYGWIN*:*) - echo powerpcle-${VENDOR}-cygwin + echo x86_64-pc-cygwin exit ;; prep*:SunOS:5.*:*) - echo powerpcle-${VENDOR}-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + echo powerpcle-unknown-solaris2"$(echo "$UNAME_RELEASE"|sed -e 's/[^.]*//')" exit ;; *:GNU:*:*) # the GNU system - echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-${VENDOR}-${LIBC}`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'` + 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}-${VENDOR}-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr "[:upper:]" "[:lower:]"``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-${LIBC} + echo "$UNAME_MACHINE-unknown-$(echo "$UNAME_SYSTEM" | sed 's,^[^/]*/,,' | tr "[:upper:]" "[:lower:]")$(echo "$UNAME_RELEASE"|sed -e 's/[-(].*//')-$LIBC" exit ;; - i*86:Minix:*:*) - echo ${UNAME_MACHINE}-pc-minix + *:Minix:*:*) + echo "$UNAME_MACHINE"-unknown-minix exit ;; aarch64:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; aarch64_be:Linux:*:*) UNAME_MACHINE=aarch64_be - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; alpha:Linux:*:*) - case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in + case $(sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' /proc/cpuinfo 2>/dev/null) in EV5) UNAME_MACHINE=alphaev5 ;; EV56) UNAME_MACHINE=alphaev56 ;; PCA56) UNAME_MACHINE=alphapca56 ;; @@ -938,140 +947,181 @@ esac objdump --private-headers /bin/sh | grep -q ld.so.1 if test "$?" = 0 ; then LIBC=gnulibc1 ; fi - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; arc:Linux:*:* | arceb:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; arm*:Linux:*:*) - eval $set_cc_for_build + set_cc_for_build if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \ | grep -q __ARM_EABI__ then - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC} + 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}-${VENDOR}-linux-${LIBC}eabi + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"eabi else - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC}eabihf + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"eabihf fi fi exit ;; avr32*:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; cris:Linux:*:*) - echo ${UNAME_MACHINE}-axis-linux-${LIBC} + echo "$UNAME_MACHINE"-axis-linux-"$LIBC" exit ;; crisv32:Linux:*:*) - echo ${UNAME_MACHINE}-axis-linux-${LIBC} + echo "$UNAME_MACHINE"-axis-linux-"$LIBC" exit ;; e2k:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; frv:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; hexagon:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; i*86:Linux:*:*) - echo ${UNAME_MACHINE}-pc-linux-${LIBC} + echo "$UNAME_MACHINE"-pc-linux-"$LIBC" exit ;; ia64:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; k1om:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" + exit ;; + loongarch32:Linux:*:* | loongarch64:Linux:*:* | loongarchx32:Linux:*:*) + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; m32r*:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; m68*:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; mips:Linux:*:* | mips64:Linux:*:*) - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c + set_cc_for_build + IS_GLIBC=0 + test x"${LIBC}" = xgnu && IS_GLIBC=1 + sed 's/^ //' << EOF > "$dummy.c" #undef CPU - #undef ${UNAME_MACHINE} - #undef ${UNAME_MACHINE}el + #undef mips + #undef mipsel + #undef mips64 + #undef mips64el + #if ${IS_GLIBC} && defined(_ABI64) + LIBCABI=gnuabi64 + #else + #if ${IS_GLIBC} && defined(_ABIN32) + LIBCABI=gnuabin32 + #else + LIBCABI=${LIBC} + #endif + #endif + + #if ${IS_GLIBC} && defined(__mips64) && defined(__mips_isa_rev) && __mips_isa_rev>=6 + CPU=mipsisa64r6 + #else + #if ${IS_GLIBC} && !defined(__mips64) && defined(__mips_isa_rev) && __mips_isa_rev>=6 + CPU=mipsisa32r6 + #else + #if defined(__mips64) + CPU=mips64 + #else + CPU=mips + #endif + #endif + #endif + #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) - CPU=${UNAME_MACHINE}el + MIPS_ENDIAN=el #else #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) - CPU=${UNAME_MACHINE} + MIPS_ENDIAN= #else - CPU= + MIPS_ENDIAN= #endif #endif EOF - eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^CPU'` - test x"${CPU}" != x && { echo "${CPU}-${VENDOR}-linux-${LIBC}"; exit; } + eval "$($CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^CPU\|^MIPS_ENDIAN\|^LIBCABI')" + test "x$CPU" != x && { echo "$CPU${MIPS_ENDIAN}-unknown-linux-$LIBCABI"; exit; } ;; mips64el:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; openrisc*:Linux:*:*) - echo or1k-${VENDOR}-linux-${LIBC} + echo or1k-unknown-linux-"$LIBC" exit ;; or32:Linux:*:* | or1k*:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; padre:Linux:*:*) - echo sparc-${VENDOR}-linux-${LIBC} + echo sparc-unknown-linux-"$LIBC" exit ;; parisc64:Linux:*:* | hppa64:Linux:*:*) - echo hppa64-${VENDOR}-linux-${LIBC} + 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-${VENDOR}-linux-${LIBC} ;; - PA8*) echo hppa2.0-${VENDOR}-linux-${LIBC} ;; - *) echo hppa-${VENDOR}-linux-${LIBC} ;; + 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-${VENDOR}-linux-${LIBC} + echo powerpc64-unknown-linux-"$LIBC" exit ;; ppc:Linux:*:*) - echo powerpc-${VENDOR}-linux-${LIBC} + echo powerpc-unknown-linux-"$LIBC" exit ;; ppc64le:Linux:*:*) - echo powerpc64le-${VENDOR}-linux-${LIBC} + echo powerpc64le-unknown-linux-"$LIBC" exit ;; ppcle:Linux:*:*) - echo powerpcle-${VENDOR}-linux-${LIBC} + echo powerpcle-unknown-linux-"$LIBC" exit ;; - riscv32:Linux:*:* | riscv64:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC} + riscv32:Linux:*:* | riscv32be:Linux:*:* | riscv64:Linux:*:* | riscv64be:Linux:*:*) + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; s390:Linux:*:* | s390x:Linux:*:*) - echo ${UNAME_MACHINE}-ibm-linux-${LIBC} + echo "$UNAME_MACHINE"-ibm-linux-"$LIBC" exit ;; sh64*:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; sh*:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; sparc:Linux:*:* | sparc64:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; tile*:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; vax:Linux:*:*) - echo ${UNAME_MACHINE}-dec-linux-${LIBC} + echo "$UNAME_MACHINE"-dec-linux-"$LIBC" exit ;; x86_64:Linux:*:*) - echo ${UNAME_MACHINE}-pc-linux-${LIBC} + set_cc_for_build + LIBCABI=$LIBC + if test "$CC_FOR_BUILD" != no_compiler_found; then + if (echo '#ifdef __ILP32__'; echo IS_X32; echo '#endif') | \ + (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ + grep IS_X32 >/dev/null + then + LIBCABI="$LIBC"x32 + fi + fi + echo "$UNAME_MACHINE"-pc-linux-"$LIBCABI" exit ;; xtensa*:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; i*86:DYNIX/ptx:4*:*) # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. @@ -1085,51 +1135,51 @@ # 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} + 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 + echo "$UNAME_MACHINE"-pc-os2-emx exit ;; i*86:XTS-300:*:STOP) - echo ${UNAME_MACHINE}-${VENDOR}-stop + echo "$UNAME_MACHINE"-unknown-stop exit ;; i*86:atheos:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-atheos + echo "$UNAME_MACHINE"-unknown-atheos exit ;; i*86:syllable:*:*) - echo ${UNAME_MACHINE}-pc-syllable + echo "$UNAME_MACHINE"-pc-syllable exit ;; i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.[02]*:*) - echo i386-${VENODR}-lynxos${UNAME_RELEASE} + echo i386-unknown-lynxos"$UNAME_RELEASE" exit ;; i*86:*DOS:*:*) - echo ${UNAME_MACHINE}-pc-msdosdjgpp + echo "$UNAME_MACHINE"-pc-msdosdjgpp exit ;; - i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*) - UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'` + i*86:*: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} + echo "$UNAME_MACHINE"-univel-sysv"$UNAME_REL" else - echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL} + 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 + case $(/bin/uname -X | grep "^Machine") in *486*) UNAME_MACHINE=i486 ;; *Pentium) UNAME_MACHINE=i586 ;; *Pent*|*Celeron) UNAME_MACHINE=i686 ;; esac - echo ${UNAME_MACHINE}-${VENDOR}-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} + 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/.*= //')` + 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 @@ -1137,9 +1187,9 @@ && UNAME_MACHINE=i686 (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \ && UNAME_MACHINE=i686 - echo ${UNAME_MACHINE}-pc-sco$UNAME_REL + echo "$UNAME_MACHINE"-pc-sco"$UNAME_REL" else - echo ${UNAME_MACHINE}-pc-sysv32 + echo "$UNAME_MACHINE"-pc-sysv32 fi exit ;; pc:*:*:*) @@ -1159,9 +1209,9 @@ 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 + echo i860-stardent-sysv"$UNAME_RELEASE" # Stardent Vistra i860-SVR4 else # Add other i860-SVR4 vendors below as they are discovered. - echo i860-${VENODR}-sysv${UNAME_RELEASE} # Unknown i860-SVR4 + echo i860-unknown-sysv"$UNAME_RELEASE" # Unknown i860-SVR4 fi exit ;; mini*:CTIX:SYS*5:*) @@ -1179,41 +1229,41 @@ 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` + && 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; } + && { 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; } ;; + && { 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` + && 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; } + && { 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; } + && { 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; } ;; + && { echo i586-ncr-sysv4.3"$OS_REL"; exit; } ;; m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) - echo m68k-${VENDOR}-lynxos${UNAME_RELEASE} + echo m68k-unknown-lynxos"$UNAME_RELEASE" exit ;; mc68030:UNIX_System_V:4.*:*) echo m68k-atari-sysv4 exit ;; TSUNAMI:LynxOS:2.*:*) - echo sparc-${VENDOR}-lynxos${UNAME_RELEASE} + echo sparc-unknown-lynxos"$UNAME_RELEASE" exit ;; rs6000:LynxOS:2.*:*) - echo rs6000-${VENDOR}-lynxos${UNAME_RELEASE} + echo rs6000-unknown-lynxos"$UNAME_RELEASE" exit ;; PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.[02]*:*) - echo powerpc-${VENDOR}-lynxos${UNAME_RELEASE} + echo powerpc-unknown-lynxos"$UNAME_RELEASE" exit ;; SM[BE]S:UNIX_SV:*:*) - echo mips-dde-sysv${UNAME_RELEASE} + echo mips-dde-sysv"$UNAME_RELEASE" exit ;; RM*:ReliantUNIX-*:*:*) echo mips-sni-sysv4 @@ -1223,8 +1273,8 @@ exit ;; *:SINIX-*:*:*) if uname -p 2>/dev/null >/dev/null ; then - UNAME_MACHINE=`(uname -p) 2>/dev/null` - echo ${UNAME_MACHINE}-sni-sysv4 + UNAME_MACHINE=$( (uname -p) 2>/dev/null) + echo "$UNAME_MACHINE"-sni-sysv4 else echo ns32k-sni-sysv fi @@ -1244,23 +1294,23 @@ exit ;; i*86:VOS:*:*) # From Paul.Green@stratus.com. - echo ${UNAME_MACHINE}-stratus-vos + 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} + 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} + if test -d /usr/nec; then + echo mips-nec-sysv"$UNAME_RELEASE" else - echo mips-${VENDOR}-sysv${UNAME_RELEASE} + echo mips-unknown-sysv"$UNAME_RELEASE" fi exit ;; BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. @@ -1276,93 +1326,100 @@ echo i586-pc-haiku exit ;; x86_64:Haiku:*:*) - echo x86_64-${VENDOR}-haiku + echo x86_64-unknown-haiku exit ;; SX-4:SUPER-UX:*:*) - echo sx4-nec-superux${UNAME_RELEASE} + echo sx4-nec-superux"$UNAME_RELEASE" exit ;; SX-5:SUPER-UX:*:*) - echo sx5-nec-superux${UNAME_RELEASE} + echo sx5-nec-superux"$UNAME_RELEASE" exit ;; SX-6:SUPER-UX:*:*) - echo sx6-nec-superux${UNAME_RELEASE} + echo sx6-nec-superux"$UNAME_RELEASE" exit ;; SX-7:SUPER-UX:*:*) - echo sx7-nec-superux${UNAME_RELEASE} + echo sx7-nec-superux"$UNAME_RELEASE" exit ;; SX-8:SUPER-UX:*:*) - echo sx8-nec-superux${UNAME_RELEASE} + echo sx8-nec-superux"$UNAME_RELEASE" exit ;; SX-8R:SUPER-UX:*:*) - echo sx8r-nec-superux${UNAME_RELEASE} + echo sx8r-nec-superux"$UNAME_RELEASE" exit ;; SX-ACE:SUPER-UX:*:*) - echo sxace-nec-superux${UNAME_RELEASE} + echo sxace-nec-superux"$UNAME_RELEASE" exit ;; Power*:Rhapsody:*:*) - echo powerpc-apple-rhapsody${UNAME_RELEASE} + echo powerpc-apple-rhapsody"$UNAME_RELEASE" exit ;; *:Rhapsody:*:*) - echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE} + echo "$UNAME_MACHINE"-apple-rhapsody"$UNAME_RELEASE" + exit ;; + arm64:Darwin:*:*) + echo aarch64-apple-darwin"$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 - # On 10.4-10.6 one might compile for PowerPC via gcc -arch ppc - if (echo '#ifdef __POWERPC__'; echo IS_PPC; echo '#endif') | \ - (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ - grep IS_PPC >/dev/null - then - UNAME_PROCESSOR=powerpc - fi + UNAME_PROCESSOR=$(uname -p) + case $UNAME_PROCESSOR in + unknown) UNAME_PROCESSOR=powerpc ;; + esac + if command -v xcode-select > /dev/null 2> /dev/null && \ + ! xcode-select --print-path > /dev/null 2> /dev/null ; then + # Avoid executing cc if there is no toolchain installed as + # cc will be a stub that puts up a graphical alert + # prompting the user to install developer tools. + CC_FOR_BUILD=no_compiler_found + else + set_cc_for_build + fi + if test "$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 + # On 10.4-10.6 one might compile for PowerPC via gcc -arch ppc + if (echo '#ifdef __POWERPC__'; echo IS_PPC; echo '#endif') | \ + (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ + grep IS_PPC >/dev/null + then + UNAME_PROCESSOR=powerpc 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 + # uname -m returns i386 or x86_64 + UNAME_PROCESSOR=$UNAME_MACHINE fi - echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE} + echo "$UNAME_PROCESSOR"-apple-darwin"$UNAME_RELEASE" exit ;; *:procnto*:*:* | *:QNX:[0123456789]*:*) - UNAME_PROCESSOR=`uname -p` + 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} + 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} + echo neo-tandem-nsk"$UNAME_RELEASE" exit ;; NSE-*:NONSTOP_KERNEL:*:*) - echo nse-tandem-nsk${UNAME_RELEASE} + echo nse-tandem-nsk"$UNAME_RELEASE" exit ;; NSR-*:NONSTOP_KERNEL:*:*) - echo nsr-tandem-nsk${UNAME_RELEASE} + echo nsr-tandem-nsk"$UNAME_RELEASE" + exit ;; + NSV-*:NONSTOP_KERNEL:*:*) + echo nsv-tandem-nsk"$UNAME_RELEASE" exit ;; NSX-*:NONSTOP_KERNEL:*:*) - echo nsx-tandem-nsk${UNAME_RELEASE} + echo nsx-tandem-nsk"$UNAME_RELEASE" exit ;; *:NonStop-UX:*:*) echo mips-compaq-nonstopux @@ -1371,24 +1428,25 @@ echo bs2000-siemens-sysv exit ;; DS/*:UNIX_System_V:*:*) - echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE} + 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. + # shellcheck disable=SC2154 if test "$cputype" = 386; then UNAME_MACHINE=i386 else UNAME_MACHINE="$cputype" fi - echo ${UNAME_MACHINE}-${VENDOR}-plan9 + echo "$UNAME_MACHINE"-unknown-plan9 exit ;; *:TOPS-10:*:*) - echo pdp10-${VENDOR}-tops10 + echo pdp10-unknown-tops10 exit ;; *:TENEX:*:*) - echo pdp10-${VENDOR}-tenex + echo pdp10-unknown-tenex exit ;; KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*) echo pdp10-dec-tops20 @@ -1397,20 +1455,20 @@ echo pdp10-xkl-tops20 exit ;; *:TOPS-20:*:*) - echo pdp10-${VENDOR}-tops20 + echo pdp10-unknown-tops20 exit ;; *:ITS:*:*) - echo pdp10-${VENDOR}-its + echo pdp10-unknown-its exit ;; SEI:*:*:SEIUX) - echo mips-sei-seiux${UNAME_RELEASE} + echo mips-sei-seiux"$UNAME_RELEASE" exit ;; *:DragonFly:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` + echo "$UNAME_MACHINE"-unknown-dragonfly"$(echo "$UNAME_RELEASE"|sed -e 's/[-(].*//')" exit ;; *:*VMS:*:*) - UNAME_MACHINE=`(uname -p) 2>/dev/null` - case "${UNAME_MACHINE}" in + 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 ;; @@ -1419,32 +1477,190 @@ echo i386-pc-xenix exit ;; i*86:skyos:*:*) - echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE} | sed -e 's/ .*$//'` + echo "$UNAME_MACHINE"-pc-skyos"$(echo "$UNAME_RELEASE" | sed -e 's/ .*$//')" exit ;; i*86:rdos:*:*) - echo ${UNAME_MACHINE}-pc-rdos + echo "$UNAME_MACHINE"-pc-rdos exit ;; - i*86:AROS:*:*) - echo ${UNAME_MACHINE}-pc-aros + *:AROS:*:*) + echo "$UNAME_MACHINE"-unknown-aros exit ;; x86_64:VMkernel:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-esx + echo "$UNAME_MACHINE"-unknown-esx exit ;; amd64:Isilon\ OneFS:*:*) - echo x86_64-${VENDOR}-onefs + echo x86_64-unknown-onefs + exit ;; + *:Unleashed:*:*) + echo "$UNAME_MACHINE"-unknown-unleashed"$UNAME_RELEASE" exit ;; esac +# No uname command or uname output not recognized. +set_cc_for_build +cat > "$dummy.c" < +#include +#endif +#if defined(ultrix) || defined(_ultrix) || defined(__ultrix) || defined(__ultrix__) +#if defined (vax) || defined (__vax) || defined (__vax__) || defined(mips) || defined(__mips) || defined(__mips__) || defined(MIPS) || defined(__MIPS__) +#include +#if defined(_SIZE_T_) || defined(SIGLOST) +#include +#endif +#endif +#endif +main () +{ +#if defined (sony) +#if defined (MIPSEB) + /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed, + I don't know.... */ + printf ("mips-sony-bsd\n"); exit (0); +#else +#include + printf ("m68k-sony-newsos%s\n", +#ifdef NEWSOS4 + "4" +#else + "" +#endif + ); exit (0); +#endif +#endif + +#if defined (NeXT) +#if !defined (__ARCHITECTURE__) +#define __ARCHITECTURE__ "m68k" +#endif + int version; + version=$( (hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null); + if (version < 4) + printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version); + else + printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version); + exit (0); +#endif + +#if defined (MULTIMAX) || defined (n16) +#if defined (UMAXV) + printf ("ns32k-encore-sysv\n"); exit (0); +#else +#if defined (CMU) + printf ("ns32k-encore-mach\n"); exit (0); +#else + printf ("ns32k-encore-bsd\n"); exit (0); +#endif +#endif +#endif + +#if defined (__386BSD__) + printf ("i386-pc-bsd\n"); exit (0); +#endif + +#if defined (sequent) +#if defined (i386) + printf ("i386-sequent-dynix\n"); exit (0); +#endif +#if defined (ns32000) + printf ("ns32k-sequent-dynix\n"); exit (0); +#endif +#endif + +#if defined (_SEQUENT_) + struct utsname un; + + uname(&un); + if (strncmp(un.version, "V2", 2) == 0) { + printf ("i386-sequent-ptx2\n"); exit (0); + } + if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */ + printf ("i386-sequent-ptx1\n"); exit (0); + } + printf ("i386-sequent-ptx\n"); exit (0); +#endif + +#if defined (vax) +#if !defined (ultrix) +#include +#if defined (BSD) +#if BSD == 43 + printf ("vax-dec-bsd4.3\n"); exit (0); +#else +#if BSD == 199006 + printf ("vax-dec-bsd4.3reno\n"); exit (0); +#else + printf ("vax-dec-bsd\n"); exit (0); +#endif +#endif +#else + printf ("vax-dec-bsd\n"); exit (0); +#endif +#else +#if defined(_SIZE_T_) || defined(SIGLOST) + struct utsname un; + uname (&un); + printf ("vax-dec-ultrix%s\n", un.release); exit (0); +#else + printf ("vax-dec-ultrix\n"); exit (0); +#endif +#endif +#endif +#if defined(ultrix) || defined(_ultrix) || defined(__ultrix) || defined(__ultrix__) +#if defined(mips) || defined(__mips) || defined(__mips__) || defined(MIPS) || defined(__MIPS__) +#if defined(_SIZE_T_) || defined(SIGLOST) + struct utsname *un; + uname (&un); + printf ("mips-dec-ultrix%s\n", un.release); exit (0); +#else + printf ("mips-dec-ultrix\n"); exit (0); +#endif +#endif +#endif + +#if defined (alliant) && defined (i860) + printf ("i860-alliant-bsd\n"); exit (0); +#endif + + exit (1); +} +EOF + +$CC_FOR_BUILD -o "$dummy" "$dummy.c" 2>/dev/null && SYSTEM_NAME=$($dummy) && + { echo "$SYSTEM_NAME"; exit; } + +# Apollos put the system type in the environment. +test -d /usr/apollo && { echo "$ISP-apollo-$SYSTYPE"; exit; } + +echo "$0: unable to guess system type" >&2 + +case "$UNAME_MACHINE:$UNAME_SYSTEM" in + mips:Linux | mips64:Linux) + # If we got here on MIPS GNU/Linux, output extra information. + cat >&2 <&2 <&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} +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 +fi exit 1 # Local variables: -# eval: (add-hook 'write-file-hooks 'time-stamp) +# eval: (add-hook 'before-save-hook 'time-stamp) # time-stamp-start: "timestamp='" # time-stamp-format: "%:y-%02m-%02d" # time-stamp-end: "'" diff -Nru cpl-7.1.4+ds/admin/config.sub cpl-7.2.2+ds/admin/config.sub --- cpl-7.1.4+ds/admin/config.sub 2021-05-07 12:10:10.000000000 +0000 +++ cpl-7.2.2+ds/admin/config.sub 2022-04-29 14:56:28.000000000 +0000 @@ -1,8 +1,8 @@ #! /bin/sh # Configuration validation subroutine script. -# Copyright 1992-2017 Free Software Foundation, Inc. +# Copyright 1992-2021 Free Software Foundation, Inc. -timestamp='2017-04-02' +timestamp='2021-01-08' # 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 @@ -15,7 +15,7 @@ # 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 . +# 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 @@ -33,7 +33,7 @@ # 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 +# https://git.savannah.gnu.org/cgit/config.git/plain/config.sub # This file is supposed to be the same for all GNU packages # and recognize all the CPU types, system types and aliases @@ -50,14 +50,14 @@ # CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM # It is wrong to echo any other type of specification. -me=`echo "$0" | sed -e 's,.*/,,'` +me=$(echo "$0" | sed -e 's,.*/,,') usage="\ Usage: $0 [OPTION] CPU-MFR-OPSYS or ALIAS Canonicalize a configuration name. -Operation modes: +Options: -h, --help print this help, then exit -t, --time-stamp print date of last modification, then exit -v, --version print version number, then exit @@ -67,7 +67,7 @@ version="\ GNU config.sub ($timestamp) -Copyright 1992-2017 Free Software Foundation, Inc. +Copyright 1992-2021 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." @@ -89,12 +89,12 @@ - ) # Use stdin as input. break ;; -* ) - echo "$me: invalid option $1$help" + echo "$me: invalid option $1$help" >&2 exit 1 ;; *local*) # First pass through any local machine types. - echo $1 + echo "$1" exit ;; * ) @@ -110,1258 +110,1169 @@ 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* | netbsd*-eabi* | \ - kopensolaris*-gnu* | cloudabi*-eabi* | \ - 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 +# Split fields of configuration type +# shellcheck disable=SC2162 +IFS="-" read field1 field2 field3 field4 <&2 + exit 1 ;; - -ptx*) - basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'` + *-*-*-*) + basic_machine=$field1-$field2 + basic_os=$field3-$field4 ;; - -windowsnt*) - os=`echo $os | sed -e 's/windowsnt/winnt/'` + *-*-*) + # Ambiguous whether COMPANY is present, or skipped and KERNEL-OS is two + # parts + maybe_os=$field2-$field3 + case $maybe_os in + nto-qnx* | linux-* | uclinux-uclibc* \ + | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* \ + | netbsd*-eabi* | kopensolaris*-gnu* | cloudabi*-eabi* \ + | storm-chaos* | os2-emx* | rtmk-nova*) + basic_machine=$field1 + basic_os=$maybe_os + ;; + android-linux) + basic_machine=$field1-unknown + basic_os=linux-android + ;; + *) + basic_machine=$field1-$field2 + basic_os=$field3 + ;; + esac ;; - -psos*) - os=-psos + *-*) + # A lone config we happen to match not fitting any pattern + case $field1-$field2 in + decstation-3100) + basic_machine=mips-dec + basic_os= + ;; + *-*) + # Second component is usually, but not always the OS + case $field2 in + # Prevent following clause from handling this valid os + sun*os*) + basic_machine=$field1 + basic_os=$field2 + ;; + # Manufacturers + dec* | mips* | sequent* | encore* | pc533* | 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* | sim | cisco \ + | oki | wec | wrs | winbond) + basic_machine=$field1-$field2 + basic_os= + ;; + *) + basic_machine=$field1 + basic_os=$field2 + ;; + esac + ;; + esac ;; - -mint | -mint[0-9]*) - basic_machine=m68k-atari - os=-mint + *) + # Convert single-component short-hands not valid as part of + # multi-component configurations. + case $field1 in + 386bsd) + basic_machine=i386-pc + basic_os=bsd + ;; + a29khif) + basic_machine=a29k-amd + basic_os=udi + ;; + adobe68k) + basic_machine=m68010-adobe + basic_os=scout + ;; + alliant) + basic_machine=fx80-alliant + basic_os= + ;; + altos | altos3068) + basic_machine=m68k-altos + basic_os= + ;; + am29k) + basic_machine=a29k-none + basic_os=bsd + ;; + amdahl) + basic_machine=580-amdahl + basic_os=sysv + ;; + amiga) + basic_machine=m68k-unknown + basic_os= + ;; + amigaos | amigados) + basic_machine=m68k-unknown + basic_os=amigaos + ;; + amigaunix | amix) + basic_machine=m68k-unknown + basic_os=sysv4 + ;; + apollo68) + basic_machine=m68k-apollo + basic_os=sysv + ;; + apollo68bsd) + basic_machine=m68k-apollo + basic_os=bsd + ;; + aros) + basic_machine=i386-pc + basic_os=aros + ;; + aux) + basic_machine=m68k-apple + basic_os=aux + ;; + balance) + basic_machine=ns32k-sequent + basic_os=dynix + ;; + blackfin) + basic_machine=bfin-unknown + basic_os=linux + ;; + cegcc) + basic_machine=arm-unknown + basic_os=cegcc + ;; + convex-c1) + basic_machine=c1-convex + basic_os=bsd + ;; + convex-c2) + basic_machine=c2-convex + basic_os=bsd + ;; + convex-c32) + basic_machine=c32-convex + basic_os=bsd + ;; + convex-c34) + basic_machine=c34-convex + basic_os=bsd + ;; + convex-c38) + basic_machine=c38-convex + basic_os=bsd + ;; + cray) + basic_machine=j90-cray + basic_os=unicos + ;; + crds | unos) + basic_machine=m68k-crds + basic_os= + ;; + da30) + basic_machine=m68k-da30 + basic_os= + ;; + decstation | pmax | pmin | dec3100 | decstatn) + basic_machine=mips-dec + basic_os= + ;; + delta88) + basic_machine=m88k-motorola + basic_os=sysv3 + ;; + dicos) + basic_machine=i686-pc + basic_os=dicos + ;; + djgpp) + basic_machine=i586-pc + basic_os=msdosdjgpp + ;; + ebmon29k) + basic_machine=a29k-amd + basic_os=ebmon + ;; + es1800 | OSE68k | ose68k | ose | OSE) + basic_machine=m68k-ericsson + basic_os=ose + ;; + gmicro) + basic_machine=tron-gmicro + basic_os=sysv + ;; + go32) + basic_machine=i386-pc + basic_os=go32 + ;; + h8300hms) + basic_machine=h8300-hitachi + basic_os=hms + ;; + h8300xray) + basic_machine=h8300-hitachi + basic_os=xray + ;; + h8500hms) + basic_machine=h8500-hitachi + basic_os=hms + ;; + harris) + basic_machine=m88k-harris + basic_os=sysv3 + ;; + hp300 | hp300hpux) + basic_machine=m68k-hp + basic_os=hpux + ;; + hp300bsd) + basic_machine=m68k-hp + basic_os=bsd + ;; + hppaosf) + basic_machine=hppa1.1-hp + basic_os=osf + ;; + hppro) + basic_machine=hppa1.1-hp + basic_os=proelf + ;; + i386mach) + basic_machine=i386-mach + basic_os=mach + ;; + isi68 | isi) + basic_machine=m68k-isi + basic_os=sysv + ;; + m68knommu) + basic_machine=m68k-unknown + basic_os=linux + ;; + magnum | m3230) + basic_machine=mips-mips + basic_os=sysv + ;; + merlin) + basic_machine=ns32k-utek + basic_os=sysv + ;; + mingw64) + basic_machine=x86_64-pc + basic_os=mingw64 + ;; + mingw32) + basic_machine=i686-pc + basic_os=mingw32 + ;; + mingw32ce) + basic_machine=arm-unknown + basic_os=mingw32ce + ;; + monitor) + basic_machine=m68k-rom68k + basic_os=coff + ;; + morphos) + basic_machine=powerpc-unknown + basic_os=morphos + ;; + moxiebox) + basic_machine=moxie-unknown + basic_os=moxiebox + ;; + msdos) + basic_machine=i386-pc + basic_os=msdos + ;; + msys) + basic_machine=i686-pc + basic_os=msys + ;; + mvs) + basic_machine=i370-ibm + basic_os=mvs + ;; + nacl) + basic_machine=le32-unknown + basic_os=nacl + ;; + ncr3000) + basic_machine=i486-ncr + basic_os=sysv4 + ;; + netbsd386) + basic_machine=i386-pc + basic_os=netbsd + ;; + netwinder) + basic_machine=armv4l-rebel + basic_os=linux + ;; + news | news700 | news800 | news900) + basic_machine=m68k-sony + basic_os=newsos + ;; + news1000) + basic_machine=m68030-sony + basic_os=newsos + ;; + necv70) + basic_machine=v70-nec + basic_os=sysv + ;; + nh3000) + basic_machine=m68k-harris + basic_os=cxux + ;; + nh[45]000) + basic_machine=m88k-harris + basic_os=cxux + ;; + nindy960) + basic_machine=i960-intel + basic_os=nindy + ;; + mon960) + basic_machine=i960-intel + basic_os=mon960 + ;; + nonstopux) + basic_machine=mips-compaq + basic_os=nonstopux + ;; + os400) + basic_machine=powerpc-ibm + basic_os=os400 + ;; + OSE68000 | ose68000) + basic_machine=m68000-ericsson + basic_os=ose + ;; + os68k) + basic_machine=m68k-none + basic_os=os68k + ;; + paragon) + basic_machine=i860-intel + basic_os=osf + ;; + parisc) + basic_machine=hppa-unknown + basic_os=linux + ;; + psp) + basic_machine=mipsallegrexel-sony + basic_os=psp + ;; + pw32) + basic_machine=i586-unknown + basic_os=pw32 + ;; + rdos | rdos64) + basic_machine=x86_64-pc + basic_os=rdos + ;; + rdos32) + basic_machine=i386-pc + basic_os=rdos + ;; + rom68k) + basic_machine=m68k-rom68k + basic_os=coff + ;; + sa29200) + basic_machine=a29k-amd + basic_os=udi + ;; + sei) + basic_machine=mips-sei + basic_os=seiux + ;; + sequent) + basic_machine=i386-sequent + basic_os= + ;; + sps7) + basic_machine=m68k-bull + basic_os=sysv2 + ;; + st2000) + basic_machine=m68k-tandem + basic_os= + ;; + stratus) + basic_machine=i860-stratus + basic_os=sysv4 + ;; + sun2) + basic_machine=m68000-sun + basic_os= + ;; + sun2os3) + basic_machine=m68000-sun + basic_os=sunos3 + ;; + sun2os4) + basic_machine=m68000-sun + basic_os=sunos4 + ;; + sun3) + basic_machine=m68k-sun + basic_os= + ;; + sun3os3) + basic_machine=m68k-sun + basic_os=sunos3 + ;; + sun3os4) + basic_machine=m68k-sun + basic_os=sunos4 + ;; + sun4) + basic_machine=sparc-sun + basic_os= + ;; + sun4os3) + basic_machine=sparc-sun + basic_os=sunos3 + ;; + sun4os4) + basic_machine=sparc-sun + basic_os=sunos4 + ;; + sun4sol2) + basic_machine=sparc-sun + basic_os=solaris2 + ;; + sun386 | sun386i | roadrunner) + basic_machine=i386-sun + basic_os= + ;; + sv1) + basic_machine=sv1-cray + basic_os=unicos + ;; + symmetry) + basic_machine=i386-sequent + basic_os=dynix + ;; + t3e) + basic_machine=alphaev5-cray + basic_os=unicos + ;; + t90) + basic_machine=t90-cray + basic_os=unicos + ;; + toad1) + basic_machine=pdp10-xkl + basic_os=tops20 + ;; + tpf) + basic_machine=s390x-ibm + basic_os=tpf + ;; + udi29k) + basic_machine=a29k-amd + basic_os=udi + ;; + ultra3) + basic_machine=a29k-nyu + basic_os=sym1 + ;; + v810 | necv810) + basic_machine=v810-nec + basic_os=none + ;; + vaxv) + basic_machine=vax-dec + basic_os=sysv + ;; + vms) + basic_machine=vax-dec + basic_os=vms + ;; + vsta) + basic_machine=i386-pc + basic_os=vsta + ;; + vxworks960) + basic_machine=i960-wrs + basic_os=vxworks + ;; + vxworks68) + basic_machine=m68k-wrs + basic_os=vxworks + ;; + vxworks29k) + basic_machine=a29k-wrs + basic_os=vxworks + ;; + xbox) + basic_machine=i686-pc + basic_os=mingw32 + ;; + ymp) + basic_machine=ymp-cray + basic_os=unicos + ;; + *) + basic_machine=$1 + basic_os= + ;; + esac ;; esac -# Decode aliases for certain CPU-COMPANY combinations. +# Decode 1-component or ad-hoc basic machines 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 \ - | ba \ - | be32 | be64 \ - | bfin \ - | c4x | c8051 | clipper \ - | d10v | d30v | dlx | dsp16xx \ - | e2k | epiphany \ - | fido | fr30 | frv | ft32 \ - | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \ - | hexagon \ - | i370 | i860 | i960 | ia16 | 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 \ - | pru \ - | pyramid \ - | riscv32 | riscv64 \ - | rl78 | rx \ - | score \ - | sh | sh[1234] | sh[24]a | sh[24]aeb | sh[23]e | sh[234]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 \ - | wasm32 \ - | 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 + # 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) + cpu=hppa1.1 + vendor=winbond ;; - m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k) + op50n) + cpu=hppa1.1 + vendor=oki ;; - ms1) - basic_machine=mt-unknown + op60c) + cpu=hppa1.1 + vendor=oki ;; - - strongarm | thumb | xscale) - basic_machine=arm-unknown + ibm*) + cpu=i370 + vendor=ibm ;; - xgate) - basic_machine=$basic_machine-unknown - os=-none + orion105) + cpu=clipper + vendor=highlevel ;; - xscaleeb) - basic_machine=armeb-unknown + mac | mpw | mac-mpw) + cpu=m68k + vendor=apple ;; - - xscaleel) - basic_machine=armel-unknown + pmac | pmac-mpw) + cpu=powerpc + vendor=apple ;; - # 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-* \ - | ba-* \ - | be32-* | be64-* \ - | bfin-* | bs2000-* \ - | c[123]* | c30-* | [cjt]90-* | c4x-* \ - | c8051-* | clipper-* | craynv-* | cydra-* \ - | d10v-* | d30v-* | dlx-* \ - | e2k-* | elxsi-* \ - | f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \ - | h8300-* | h8500-* \ - | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \ - | hexagon-* \ - | i*86-* | i860-* | i960-* | ia16-* | 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-* \ - | pru-* \ - | pyramid-* \ - | riscv32-* | riscv64-* \ - | 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-* \ - | wasm32-* \ - | 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 + cpu=m68000 + vendor=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 - ;; - asmjs) - basic_machine=asmjs-unknown - ;; - 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 + cpu=we32k + vendor=att ;; 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 + cpu=powerpc + vendor=ibm + basic_os=cnk ;; decsystem10* | dec10*) - basic_machine=pdp10-dec - os=-tops10 + cpu=pdp10 + vendor=dec + basic_os=tops10 ;; decsystem20* | dec20*) - basic_machine=pdp10-dec - os=-tops20 + cpu=pdp10 + vendor=dec + basic_os=tops20 ;; delta | 3300 | motorola-3300 | motorola-delta \ | 3300-motorola | delta-motorola) - basic_machine=m68k-motorola + cpu=m68k + vendor=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 - ;; - e500v[12]) - basic_machine=powerpc-unknown - os=$os"spe" - ;; - e500v[12]-*) - basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'` - os=$os"spe" - ;; - ebmon29k) - basic_machine=a29k-amd - os=-ebmon - ;; - elxsi) - basic_machine=elxsi-elxsi - os=-bsd + dpx2*) + cpu=m68k + vendor=bull + basic_os=sysv3 ;; encore | umax | mmax) - basic_machine=ns32k-encore + cpu=ns32k + vendor=encore ;; - es1800 | OSE68k | ose68k | ose | OSE) - basic_machine=m68k-ericsson - os=-ose + elxsi) + cpu=elxsi + vendor=elxsi + basic_os=${basic_os:-bsd} ;; fx2800) - basic_machine=i860-alliant + cpu=i860 + vendor=alliant ;; genix) - basic_machine=ns32k-ns - ;; - gmicro) - basic_machine=tron-gmicro - os=-sysv - ;; - go32) - basic_machine=i386-pc - os=-go32 + cpu=ns32k + vendor=ns ;; 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 + cpu=hppa1.1 + vendor=hitachi + basic_os=hiuxwe2 ;; hp3k9[0-9][0-9] | hp9[0-9][0-9]) - basic_machine=hppa1.0-hp + cpu=hppa1.0 + vendor=hp ;; hp9k2[0-9][0-9] | hp9k31[0-9]) - basic_machine=m68000-hp + cpu=m68000 + vendor=hp ;; hp9k3[2-9][0-9]) - basic_machine=m68k-hp + cpu=m68k + vendor=hp ;; hp9k6[0-9][0-9] | hp6[0-9][0-9]) - basic_machine=hppa1.0-hp + cpu=hppa1.0 + vendor=hp ;; hp9k7[0-79][0-9] | hp7[0-79][0-9]) - basic_machine=hppa1.1-hp + cpu=hppa1.1 + vendor=hp ;; hp9k78[0-9] | hp78[0-9]) # FIXME: really hppa2.0-hp - basic_machine=hppa1.1-hp + cpu=hppa1.1 + vendor=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 + cpu=hppa1.1 + vendor=hp ;; hp9k8[0-9][13679] | hp8[0-9][13679]) - basic_machine=hppa1.1-hp + cpu=hppa1.1 + vendor=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 + cpu=hppa1.0 + vendor=hp ;; i*86v32) - basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` - os=-sysv32 + cpu=$(echo "$1" | sed -e 's/86.*/86/') + vendor=pc + basic_os=sysv32 ;; i*86v4*) - basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` - os=-sysv4 + cpu=$(echo "$1" | sed -e 's/86.*/86/') + vendor=pc + basic_os=sysv4 ;; i*86v) - basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` - os=-sysv + cpu=$(echo "$1" | sed -e 's/86.*/86/') + vendor=pc + basic_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 + cpu=$(echo "$1" | sed -e 's/86.*/86/') + vendor=pc + basic_os=solaris2 + ;; + j90 | j90-cray) + cpu=j90 + vendor=cray + basic_os=${basic_os:-unicos} ;; iris | iris4d) - basic_machine=mips-sgi - case $os in - -irix*) + cpu=mips + vendor=sgi + case $basic_os in + irix*) ;; *) - os=-irix4 + basic_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-/'` + cpu=m68000 + vendor=convergent ;; - 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 + *mint | mint[0-9]* | *MiNT | *MiNT[0-9]*) + cpu=m68k + vendor=atari + basic_os=mint ;; 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* ) + cpu=mips + vendor=sony + basic_os=newsos + ;; + next | m*-next) + cpu=m68k + vendor=next + case $basic_os in + openstep*) + ;; + nextstep*) ;; - -ns2*) - os=-nextstep2 + ns2*) + basic_os=nextstep2 ;; *) - os=-nextstep3 + basic_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 - ;; - nsx-tandem) - basic_machine=nsx-tandem + cpu=np1 + vendor=gould ;; 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 + cpu=hppa1.1 + vendor=oki + basic_os=proelf ;; 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 + cpu=hppa1.1 + vendor=hitachi + basic_os=hiuxwe2 ;; pbd) - basic_machine=sparc-tti + cpu=sparc + vendor=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 + cpu=m68k + vendor=tti ;; - pentiumii | pentium2 | pentiumiii | pentium3) - basic_machine=i686-pc + pc532) + cpu=ns32k + vendor=pc532 ;; - 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/^[^-]*-//'` + pn) + cpu=pn + vendor=gould ;; - pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*) - basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` + power) + cpu=power + vendor=ibm ;; - pentium4-*) - basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'` + ps2) + cpu=i386 + vendor=ibm ;; - pn) - basic_machine=pn-gould + rm[46]00) + cpu=mips + vendor=siemens ;; - power) basic_machine=power-ibm + rtpc | rtpc-*) + cpu=romp + vendor=ibm ;; - ppc | ppcbe) basic_machine=powerpc-unknown + sde) + cpu=mipsisa32 + vendor=sde + basic_os=${basic_os:-elf} + ;; + simso-wrs) + cpu=sparclite + vendor=wrs + basic_os=vxworks ;; - ppc-* | ppcbe-*) - basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'` + tower | tower-32) + cpu=m68k + vendor=ncr ;; - ppcle | powerpclittle) - basic_machine=powerpcle-unknown + vpp*|vx|vx-*) + cpu=f301 + vendor=fujitsu ;; - ppcle-* | powerpclittle-*) - basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'` + w65) + cpu=w65 + vendor=wdc ;; - ppc64) basic_machine=powerpc64-unknown + w89k-*) + cpu=hppa1.1 + vendor=winbond + basic_os=proelf ;; - ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'` + none) + cpu=none + vendor=none ;; - ppc64le | powerpc64little) - basic_machine=powerpc64le-unknown + leon|leon[3-9]) + cpu=sparc + vendor=$basic_machine ;; - ppc64le-* | powerpc64little-*) - basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'` + leon-*|leon[3-9]-*) + cpu=sparc + vendor=$(echo "$basic_machine" | sed 's/-.*//') ;; - ps2) - basic_machine=i386-ibm + + *-*) + # shellcheck disable=SC2162 + IFS="-" read cpu vendor <&2 - exit 1 + # Recognize the canonical CPU types that are allowed with any + # company name. + case $cpu in + 1750a | 580 \ + | a29k \ + | aarch64 | aarch64_be \ + | abacus \ + | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] \ + | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] \ + | alphapca5[67] | alpha64pca5[67] \ + | am33_2.0 \ + | amdgcn \ + | arc | arceb \ + | arm | arm[lb]e | arme[lb] | armv* \ + | avr | avr32 \ + | asmjs \ + | ba \ + | be32 | be64 \ + | bfin | bpf | bs2000 \ + | c[123]* | c30 | [cjt]90 | c4x \ + | c8051 | clipper | craynv | csky | cydra \ + | d10v | d30v | dlx | dsp16xx \ + | e2k | elxsi | epiphany \ + | f30[01] | f700 | fido | fr30 | frv | ft32 | fx80 \ + | h8300 | h8500 \ + | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \ + | hexagon \ + | i370 | i*86 | i860 | i960 | ia16 | ia64 \ + | ip2k | iq2000 \ + | k1om \ + | le32 | le64 \ + | lm32 \ + | loongarch32 | loongarch64 | loongarchx32 \ + | m32c | m32r | m32rle \ + | m5200 | m68000 | m680[012346]0 | m68360 | m683?2 | m68k \ + | m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x \ + | m88110 | m88k | maxq | mb | mcore | mep | metag \ + | microblaze | microblazeel \ + | mips | mipsbe | mipseb | mipsel | mipsle \ + | mips16 \ + | mips64 | mips64eb | 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 \ + | mn10200 | mn10300 \ + | moxie \ + | mt \ + | msp430 \ + | nds32 | nds32le | nds32be \ + | nfp \ + | nios | nios2 | nios2eb | nios2el \ + | none | np1 | ns16k | ns32k | nvptx \ + | open8 \ + | or1k* \ + | or32 \ + | orion \ + | picochip \ + | pdp10 | pdp11 | pj | pjl | pn | power \ + | powerpc | powerpc64 | powerpc64le | powerpcle | powerpcspe \ + | pru \ + | pyramid \ + | riscv | riscv32 | riscv32be | riscv64 | riscv64be \ + | rl78 | romp | rs6000 | rx \ + | s390 | s390x \ + | score \ + | sh | shl \ + | sh[1234] | sh[24]a | sh[24]ae[lb] | sh[23]e | she[lb] | sh[lb]e \ + | sh[1234]e[lb] | sh[12345][lb]e | sh[23]ele | sh64 | sh64le \ + | sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet \ + | sparclite \ + | sparcv8 | sparcv9 | sparcv9b | sparcv9v | sv1 | sx* \ + | spu \ + | tahoe \ + | thumbv7* \ + | tic30 | tic4x | tic54x | tic55x | tic6x | tic80 \ + | tron \ + | ubicom32 \ + | v70 | v850 | v850e | v850e1 | v850es | v850e2 | v850e2v3 \ + | vax \ + | visium \ + | w65 \ + | wasm32 | wasm64 \ + | we32k \ + | x86 | x86_64 | xc16x | xgate | xps100 \ + | xstormy16 | xtensa* \ + | ymp \ + | z8k | z80) + ;; + + *) + echo Invalid configuration \`"$1"\': machine \`"$cpu-$vendor"\' not recognized 1>&2 + exit 1 + ;; + esac ;; esac # Here we canonicalize certain aliases for manufacturers. -case $basic_machine in - *-digital*) - basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'` +case $vendor in + digital*) + vendor=dec ;; - *-commodore*) - basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'` + commodore*) + vendor=cbm ;; *) ;; @@ -1369,203 +1280,213 @@ # Decode manufacturer-specific aliases for certain operating systems. -if [ x"$os" != x"" ] +if test x$basic_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 + +# First recognize some ad-hoc caes, or perhaps split kernel-os, or else just +# set os. +case $basic_os in + gnu/linux*) + kernel=linux + os=$(echo $basic_os | sed -e 's|gnu/linux|gnu|') + ;; + os2-emx) + kernel=os2 + os=$(echo $basic_os | sed -e 's|os2-emx|emx|') + ;; + nto-qnx*) + kernel=nto + os=$(echo $basic_os | sed -e 's|nto-qnx|qnx|') + ;; + *-*) + # shellcheck disable=SC2162 + IFS="-" read kernel os <&2 - exit 1 + # No normalization, but not necessarily accepted, that comes below. ;; esac + else # Here we handle the default operating systems that come with various machines. @@ -1578,264 +1499,361 @@ # will signal an error saying that MANUFACTURER isn't an operating # system, and we'll never get to this point. -case $basic_machine in +kernel= +case $cpu-$vendor in score-*) - os=-elf + os=elf ;; spu-*) - os=-elf + os=elf ;; *-acorn) - os=-riscix1.2 + os=riscix1.2 ;; arm*-rebel) - os=-linux + kernel=linux + os=gnu ;; arm*-semi) - os=-aout + os=aout ;; c4x-* | tic4x-*) - os=-coff + os=coff ;; c8051-*) - os=-elf + os=elf + ;; + clipper-intergraph) + os=clix ;; hexagon-*) - os=-elf + os=elf ;; tic54x-*) - os=-coff + os=coff ;; tic55x-*) - os=-coff + os=coff ;; tic6x-*) - os=-coff + os=coff ;; # This must come before the *-dec entry. pdp10-*) - os=-tops20 + os=tops20 ;; pdp11-*) - os=-none + os=none ;; *-dec | vax-*) - os=-ultrix4.2 + os=ultrix4.2 ;; m68*-apollo) - os=-domain + os=domain ;; i386-sun) - os=-sunos4.0.2 + os=sunos4.0.2 ;; m68000-sun) - os=-sunos3 + os=sunos3 ;; m68*-cisco) - os=-aout + os=aout ;; mep-*) - os=-elf + os=elf ;; mips*-cisco) - os=-elf + os=elf ;; mips*-*) - os=-elf + os=elf ;; or32-*) - os=-coff + os=coff ;; *-tti) # must be before sparc entry or we get the wrong os. - os=-sysv3 + os=sysv3 ;; sparc-* | *-sun) - os=-sunos4.1.1 + os=sunos4.1.1 ;; pru-*) - os=-elf + os=elf ;; *-be) - os=-beos - ;; - *-haiku) - os=-haiku + os=beos ;; *-ibm) - os=-aix + os=aix ;; *-knuth) - os=-mmixware + os=mmixware ;; *-wec) - os=-proelf + os=proelf ;; *-winbond) - os=-proelf + os=proelf ;; *-oki) - os=-proelf + os=proelf ;; *-hp) - os=-hpux + os=hpux ;; *-hitachi) - os=-hiux + os=hiux ;; i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent) - os=-sysv + os=sysv ;; *-cbm) - os=-amigaos + os=amigaos ;; *-dg) - os=-dgux + os=dgux ;; *-dolphin) - os=-sysv3 + os=sysv3 ;; m68k-ccur) - os=-rtu + os=rtu ;; m88k-omron*) - os=-luna + os=luna ;; - *-next ) - os=-nextstep + *-next) + os=nextstep ;; *-sequent) - os=-ptx + os=ptx ;; *-crds) - os=-unos + os=unos ;; *-ns) - os=-genix + os=genix ;; i370-*) - os=-mvs - ;; - *-next) - os=-nextstep3 + os=mvs ;; *-gould) - os=-sysv + os=sysv ;; *-highlevel) - os=-bsd + os=bsd ;; *-encore) - os=-bsd + os=bsd ;; *-sgi) - os=-irix + os=irix ;; *-siemens) - os=-sysv4 + os=sysv4 ;; *-masscomp) - os=-rtu + os=rtu ;; f30[01]-fujitsu | f700-fujitsu) - os=-uxpv + os=uxpv ;; *-rom68k) - os=-coff + os=coff ;; *-*bug) - os=-coff + os=coff ;; *-apple) - os=-macos + os=macos ;; *-atari*) - os=-mint + os=mint + ;; + *-wrs) + os=vxworks ;; *) - os=-none + os=none ;; esac + fi +# Now, validate our (potentially fixed-up) OS. +case $os in + # Sometimes we do "kernel-libc", so those need to count as OSes. + musl* | newlib* | uclibc*) + ;; + # Likewise for "kernel-abi" + eabi* | gnueabi*) + ;; + # VxWorks passes extra cpu info in the 4th filed. + simlinux | simwindows | spe) + ;; + # Now accept the basic system types. + # The portable systems comes first. + # Each alternative MUST end in a * to match a version number. + gnu* | android* | bsd* | mach* | minix* | genix* | ultrix* | irix* \ + | *vms* | esix* | aix* | cnk* | sunos | sunos[34]* \ + | hpux* | unos* | osf* | luna* | dgux* | auroraux* | solaris* \ + | sym* | plan9* | psp* | sim* | xray* | os68k* | v88r* \ + | hiux* | abug | nacl* | netware* | windows* \ + | os9* | macos* | osx* | ios* \ + | mpw* | magic* | mmixware* | mon960* | lnews* \ + | amigaos* | amigados* | msdos* | newsos* | unicos* | aof* \ + | aos* | aros* | cloudabi* | sortix* | twizzler* \ + | nindy* | vxsim* | vxworks* | ebmon* | hms* | mvs* \ + | clix* | riscos* | uniplus* | iris* | isc* | rtu* | xenix* \ + | mirbsd* | netbsd* | dicos* | openedition* | ose* \ + | bitrig* | openbsd* | solidbsd* | libertybsd* | os108* \ + | ekkobsd* | freebsd* | riscix* | lynxos* | os400* \ + | bosx* | nextstep* | cxux* | aout* | elf* | oabi* \ + | ptx* | coff* | ecoff* | winnt* | domain* | vsta* \ + | udi* | lites* | ieee* | go32* | aux* | hcos* \ + | chorusrdb* | cegcc* | glidix* \ + | cygwin* | msys* | pe* | moss* | proelf* | rtems* \ + | midipix* | mingw32* | mingw64* | mint* \ + | uxpv* | beos* | mpeix* | udk* | moxiebox* \ + | interix* | uwin* | mks* | rhapsody* | darwin* \ + | openstep* | oskit* | conix* | pw32* | nonstopux* \ + | storm-chaos* | tops10* | tenex* | tops20* | its* \ + | os2* | vos* | palmos* | uclinux* | nucleus* | morphos* \ + | scout* | superux* | sysv* | rtmk* | tpf* | windiss* \ + | powermax* | dnix* | nx6 | nx7 | sei* | dragonfly* \ + | skyos* | haiku* | rdos* | toppers* | drops* | es* \ + | onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \ + | midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \ + | nsk* | powerunix* | genode* | zvmoe* | qnx* | emx*) + ;; + # This one is extra strict with allowed versions + sco3.2v2 | sco3.2v[4-9]* | sco5v6*) + # Don't forget version if it is 3.2v4 or newer. + ;; + none) + ;; + *) + echo Invalid configuration \`"$1"\': OS \`"$os"\' not recognized 1>&2 + exit 1 + ;; +esac + +# As a final step for OS-related things, validate the OS-kernel combination +# (given a valid OS), if there is a kernel. +case $kernel-$os in + linux-gnu* | linux-dietlibc* | linux-android* | linux-newlib* | linux-musl* | linux-uclibc* ) + ;; + uclinux-uclibc* ) + ;; + -dietlibc* | -newlib* | -musl* | -uclibc* ) + # These are just libc implementations, not actual OSes, and thus + # require a kernel. + echo "Invalid configuration \`$1': libc \`$os' needs explicit kernel." 1>&2 + exit 1 + ;; + kfreebsd*-gnu* | kopensolaris*-gnu*) + ;; + vxworks-simlinux | vxworks-simwindows | vxworks-spe) + ;; + nto-qnx*) + ;; + os2-emx) + ;; + *-eabi* | *-gnueabi*) + ;; + -*) + # Blank kernel with real OS is always fine. + ;; + *-*) + echo "Invalid configuration \`$1': Kernel \`$kernel' not known to work with OS \`$os'." 1>&2 + exit 1 + ;; +esac + # 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*) +case $vendor in + unknown) + case $cpu-$os in + *-riscix*) vendor=acorn ;; - -sunos*) + *-sunos*) vendor=sun ;; - -cnk*|-aix*) + *-cnk* | *-aix*) vendor=ibm ;; - -beos*) + *-beos*) vendor=be ;; - -hpux*) + *-hpux*) vendor=hp ;; - -mpeix*) + *-mpeix*) vendor=hp ;; - -hiux*) + *-hiux*) vendor=hitachi ;; - -unos*) + *-unos*) vendor=crds ;; - -dgux*) + *-dgux*) vendor=dg ;; - -luna*) + *-luna*) vendor=omron ;; - -genix*) + *-genix*) vendor=ns ;; - -mvs* | -opened*) + *-clix*) + vendor=intergraph + ;; + *-mvs* | *-opened*) + vendor=ibm + ;; + *-os400*) vendor=ibm ;; - -os400*) + s390-* | s390x-*) vendor=ibm ;; - -ptx*) + *-ptx*) vendor=sequent ;; - -tpf*) + *-tpf*) vendor=ibm ;; - -vxsim* | -vxworks* | -windiss*) + *-vxsim* | *-vxworks* | *-windiss*) vendor=wrs ;; - -aux*) + *-aux*) vendor=apple ;; - -hms*) + *-hms*) vendor=hitachi ;; - -mpw* | -macos*) + *-mpw* | *-macos*) vendor=apple ;; - -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) + *-*mint | *-mint[0-9]* | *-*MiNT | *-MiNT[0-9]*) vendor=atari ;; - -vos*) + *-vos*) vendor=stratus ;; esac - basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"` ;; esac -echo $basic_machine$os +echo "$cpu-$vendor-${kernel:+$kernel-}$os" exit # Local variables: -# eval: (add-hook 'write-file-hooks 'time-stamp) +# eval: (add-hook 'before-save-hook 'time-stamp) # time-stamp-start: "timestamp='" # time-stamp-format: "%:y-%02m-%02d" # time-stamp-end: "'" diff -Nru cpl-7.1.4+ds/admin/depcomp cpl-7.2.2+ds/admin/depcomp --- cpl-7.1.4+ds/admin/depcomp 2021-05-07 12:10:10.000000000 +0000 +++ cpl-7.2.2+ds/admin/depcomp 2022-04-29 14:56:28.000000000 +0000 @@ -1,9 +1,9 @@ #! /bin/sh # depcomp - compile a program generating dependencies as side-effects -scriptversion=2016-01-11.22; # UTC +scriptversion=2018-03-07.03; # UTC -# Copyright (C) 1999-2017 Free Software Foundation, Inc. +# Copyright (C) 1999-2020 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 @@ -16,7 +16,7 @@ # 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 . +# 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 @@ -783,7 +783,7 @@ # Local Variables: # mode: shell-script # sh-indentation: 2 -# eval: (add-hook 'write-file-hooks 'time-stamp) +# eval: (add-hook 'before-save-hook 'time-stamp) # time-stamp-start: "scriptversion=" # time-stamp-format: "%:y-%02m-%02d.%02H" # time-stamp-time-zone: "UTC0" diff -Nru cpl-7.1.4+ds/admin/doxygen.am cpl-7.2.2+ds/admin/doxygen.am --- cpl-7.1.4+ds/admin/doxygen.am 2021-05-07 12:09:09.000000000 +0000 +++ cpl-7.2.2+ds/admin/doxygen.am 2022-04-29 14:56:02.000000000 +0000 @@ -6,7 +6,7 @@ doxygen: doxygen-am -doxygen-am: +doxygen-am: Doxyfile @if test -f $(DOXYGEN_BUILD_DIR)/Doxyfile; then \ echo "cd $(DOXYGEN_BUILD_DIR) && $(DOXYGEN)"; \ d=`pwd`; cd $(DOXYGEN_BUILD_DIR) && $(DOXYGEN); cd $$d; \ @@ -38,9 +38,16 @@ @$(NORMAL_INSTALL) @if test -d $(DOXYGEN_BUILD_DIR)/html; then \ echo "$(mkinstalldirs) $(DESTDIR)$(apidocdir)"; \ - $(mkinstalldirs) $(DESTDIR)$(apidocdir); \ - list="`ls -1 $(DOXYGEN_BUILD_DIR)/html`"; \ - for p in $$list; do \ + $(mkinstalldirs) $(DESTDIR)$(apidocdir) || exit 1; \ + basedirstrip=`echo "$(DOXYGEN_BUILD_DIR)/html" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list="`find $(DOXYGEN_BUILD_DIR)/html -type f`"; \ + docfiles="`for f in $$list; do echo $$f; done | sed -e \"s|^$$basedirstrip/||;t\"`"; \ + case $$docfiles in \ + */*) $(mkinstalldirs) `echo "$$docfiles" | \ + sed '/\//!d;s|^|$(DESTDIR)$(apidocdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for p in $$docfiles; do \ if test -f $(DOXYGEN_BUILD_DIR)/html/$$p; then \ echo " $(INSTALL_DATA) $(DOXYGEN_BUILD_DIR)/html/$$p $(DESTDIR)$(apidocdir)/$$p"; \ $(INSTALL_DATA) $(DOXYGEN_BUILD_DIR)/html/$$p $(DESTDIR)$(apidocdir)/$$p; \ @@ -53,11 +60,20 @@ uninstall-doxygen: @$(NORMAL_UNINSTALL) - @list="`ls -1 $(DESTDIR)$(apidocdir)`"; \ - for p in $$list; do \ - echo " rm -f $(DESTDIR)$(apidocdir)/$$p"; \ - rm -f $(DESTDIR)$(apidocdir)/$$p; \ - done + @if test -d $(DESTDIR)$(apidocdir); then \ + list="`ls -1 $(DESTDIR)$(apidocdir)`"; \ + for p in $$list; do \ + if test -d $(DESTDIR)$(apidocdir)/$$p; then \ + echo " rm -rf $(DESTDIR)$(apidocdir)/$$p"; \ + rm -rf $(DESTDIR)$(apidocdir)/$$p; \ + else \ + echo " rm -f $(DESTDIR)$(apidocdir)/$$p"; \ + rm -f $(DESTDIR)$(apidocdir)/$$p; \ + fi; \ + done; \ + else \ + echo "Nothing to be done for \`$@'."; \ + fi $(DOXYGEN_RECURSIVE_TARGETS): @set fnord $(MAKEFLAGS); amf=$$2; \ diff -Nru cpl-7.1.4+ds/admin/install-sh cpl-7.2.2+ds/admin/install-sh --- cpl-7.1.4+ds/admin/install-sh 2021-05-07 12:10:10.000000000 +0000 +++ cpl-7.2.2+ds/admin/install-sh 2022-04-29 14:56:28.000000000 +0000 @@ -1,7 +1,7 @@ #!/bin/sh # install - install a program, script, or datafile -scriptversion=2016-01-11.22; # UTC +scriptversion=2020-11-14.01; # UTC # This originates from X11R5 (mit/util/scripts/install.sh), which was # later released in X11R6 (xc/config/util/install.sh) with the @@ -69,6 +69,11 @@ # Desired mode of installed file. mode=0755 +# Create dirs (including intermediate dirs) using mode 755. +# This is like GNU 'install' as of coreutils 8.32 (2020). +mkdir_umask=22 + +backupsuffix= chgrpcmd= chmodcmd=$chmodprog chowncmd= @@ -99,18 +104,28 @@ --version display version info and exit. -c (ignored) - -C install only if different (preserve the last data modification time) + -C install only if different (preserve 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. + -p pass -p to $cpprog. -s $stripprog installed files. + -S SUFFIX attempt to back up existing files, with suffix SUFFIX. -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 + +By default, rm is invoked with -f; when overridden with RMPROG, +it's up to you to specify -f if you want it. + +If -S is not specified, no backups are attempted. + +Email bug reports to bug-automake@gnu.org. +Automake home page: https://www.gnu.org/software/automake/ " while test $# -ne 0; do @@ -137,8 +152,13 @@ -o) chowncmd="$chownprog $2" shift;; + -p) cpprog="$cpprog -p";; + -s) stripcmd=$stripprog;; + -S) backupsuffix="$2" + shift;; + -t) is_target_a_directory=always dst_arg=$2 @@ -255,6 +275,10 @@ dstdir=$dst test -d "$dstdir" dstdir_status=$? + # Don't chown directories that already exist. + if test $dstdir_status = 0; then + chowncmd="" + fi else # Waiting for this to be detected by the "$cpprog $src $dsttmp" command @@ -271,15 +295,18 @@ fi dst=$dst_arg - # If destination is a directory, append the input filename; won't work - # if double slashes aren't ignored. + # If destination is a directory, append the input filename. 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"` + dstbase=`basename "$src"` + case $dst in + */) dst=$dst$dstbase;; + *) dst=$dst/$dstbase;; + esac dstdir_status=0 else dstdir=`dirname "$dst"` @@ -288,27 +315,16 @@ fi fi + case $dstdir in + */) dstdirslash=$dstdir;; + *) dstdirslash=$dstdir/;; + esac + 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 @@ -318,43 +334,49 @@ 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;; + # The $RANDOM variable is not portable (e.g., dash). Use it + # here however when possible just to lower collision chance. + tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ + + trap ' + ret=$? + rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null + exit $ret + ' 0 + + # Because "mkdir -p" follows existing symlinks and we likely work + # directly in world-writeable /tmp, make sure that the '$tmpdir' + # directory is successfully created first before we actually test + # 'mkdir -p'. + if (umask $mkdir_umask && + $mkdirprog $mkdir_mode "$tmpdir" && + exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/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. + test_tmpdir="$tmpdir/a" + ls_ld_tmpdir=`ls -ld "$test_tmpdir"` + case $ls_ld_tmpdir in + d????-?r-*) different_mode=700;; + d????-?--*) different_mode=755;; + *) false;; + esac && + $mkdirprog -m$different_mode -p -- "$test_tmpdir" && { + ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"` + test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" + } + } + then posix_mkdir=: + fi + rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" + else + # Remove any dirs left behind by ancient mkdir implementations. + rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null + fi + trap '' 0;; esac if @@ -365,7 +387,7 @@ then : else - # The umask is ridiculous, or mkdir does not conform to POSIX, + # 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. @@ -394,7 +416,7 @@ prefixes= else if $posix_mkdir; then - (umask=$mkdir_umask && + (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 @@ -427,14 +449,25 @@ else # Make a couple of temp file names in the proper directory. - dsttmp=$dstdir/_inst.$$_ - rmtmp=$dstdir/_rm.$$_ + dsttmp=${dstdirslash}_inst.$$_ + rmtmp=${dstdirslash}_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") && + (umask $cp_umask && + { test -z "$stripcmd" || { + # Create $dsttmp read-write so that cp doesn't create it read-only, + # which would cause strip to fail. + if test -z "$doit"; then + : >"$dsttmp" # No need to fork-exec 'touch'. + else + $doit touch "$dsttmp" + fi + } + } && + $doit_exec $cpprog "$src" "$dsttmp") && # and set any options; do chmod last to preserve setuid bits. # @@ -460,6 +493,13 @@ then rm -f "$dsttmp" else + # If $backupsuffix is set, and the file being installed + # already exists, attempt a backup. Don't worry if it fails, + # e.g., if mv doesn't support -f. + if test -n "$backupsuffix" && test -f "$dst"; then + $doit $mvcmd -f "$dst" "$dst$backupsuffix" 2>/dev/null + fi + # Rename the file to the real destination. $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || @@ -474,9 +514,9 @@ # file should still install successfully. { test ! -f "$dst" || - $doit $rmcmd -f "$dst" 2>/dev/null || + $doit $rmcmd "$dst" 2>/dev/null || { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && - { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } + { $doit $rmcmd "$rmtmp" 2>/dev/null; :; } } || { echo "$0: cannot unlink or rename $dst" >&2 (exit 1); exit 1 @@ -493,7 +533,7 @@ done # Local variables: -# eval: (add-hook 'write-file-hooks 'time-stamp) +# eval: (add-hook 'before-save-hook 'time-stamp) # time-stamp-start: "scriptversion=" # time-stamp-format: "%:y-%02m-%02d.%02H" # time-stamp-time-zone: "UTC0" diff -Nru cpl-7.1.4+ds/admin/missing cpl-7.2.2+ds/admin/missing --- cpl-7.1.4+ds/admin/missing 2021-05-07 12:10:10.000000000 +0000 +++ cpl-7.2.2+ds/admin/missing 2022-04-29 14:56:28.000000000 +0000 @@ -1,9 +1,9 @@ #! /bin/sh # Common wrapper for a few potentially missing GNU programs. -scriptversion=2016-01-11.22; # UTC +scriptversion=2018-03-07.03; # UTC -# Copyright (C) 1996-2017 Free Software Foundation, Inc. +# Copyright (C) 1996-2020 Free Software Foundation, Inc. # Originally written by Fran,cois Pinard , 1996. # This program is free software; you can redistribute it and/or modify @@ -17,7 +17,7 @@ # 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 . +# 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 @@ -101,9 +101,9 @@ exit $st fi -perl_URL=http://www.perl.org/ -flex_URL=http://flex.sourceforge.net/ -gnu_software_URL=http://www.gnu.org/software +perl_URL=https://www.perl.org/ +flex_URL=https://github.com/westes/flex +gnu_software_URL=https://www.gnu.org/software program_details () { @@ -207,7 +207,7 @@ exit $st # Local variables: -# eval: (add-hook 'write-file-hooks 'time-stamp) +# eval: (add-hook 'before-save-hook 'time-stamp) # time-stamp-start: "scriptversion=" # time-stamp-format: "%:y-%02m-%02d.%02H" # time-stamp-time-zone: "UTC0" diff -Nru cpl-7.1.4+ds/admin/test-driver cpl-7.2.2+ds/admin/test-driver --- cpl-7.1.4+ds/admin/test-driver 2021-05-07 12:10:11.000000000 +0000 +++ cpl-7.2.2+ds/admin/test-driver 2022-04-29 14:56:28.000000000 +0000 @@ -1,9 +1,9 @@ #! /bin/sh # test-driver - basic testsuite driver script. -scriptversion=2016-01-11.22; # UTC +scriptversion=2018-03-07.03; # UTC -# Copyright (C) 2011-2017 Free Software Foundation, Inc. +# Copyright (C) 2011-2020 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 @@ -16,7 +16,7 @@ # 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 . +# 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 @@ -42,11 +42,13 @@ { cat < header file. */ #undef HAVE_LOCALE_H -/* Define to 1 if the type `long double' works and has more range or precision - than `double'. */ +/* Define to 1 if the system has the type `long double'. */ #undef HAVE_LONG_DOUBLE -/* Define to 1 if the type `long double' works and has more range or precision - than `double'. */ -#undef HAVE_LONG_DOUBLE_WIDER - /* Define this if a modern libltdl is already installed */ #undef HAVE_LTDL @@ -206,9 +207,6 @@ to 0 otherwise. */ #undef HAVE_MALLOC -/* Define to 1 if you have the header file. */ -#undef HAVE_MEMORY_H - /* Define to 1 if you have the `opendir' function. */ #undef HAVE_OPENDIR @@ -243,6 +241,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_STDINT_H +/* Define to 1 if you have the header file. */ +#undef HAVE_STDIO_H + /* Define to 1 if you have the header file. */ #undef HAVE_STDLIB_H @@ -377,7 +378,9 @@ /* The size of `void *', as computed by sizeof. */ #undef SIZEOF_VOID_P -/* Define to 1 if you have the ANSI C header files. */ +/* Define to 1 if all of the C90 standard headers exist (not just the ones + required in a freestanding environment). This macro is provided for + backward compatibility; new code need not use it. */ #undef STDC_HEADERS /* Version number of package */ @@ -395,11 +398,6 @@ # endif #endif -/* 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 diff -Nru cpl-7.1.4+ds/configure cpl-7.2.2+ds/configure --- cpl-7.1.4+ds/configure 2021-05-07 12:10:08.000000000 +0000 +++ cpl-7.2.2+ds/configure 2022-04-29 14:56:27.000000000 +0000 @@ -1,11 +1,12 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for Common Pipeline Library 7.1.4. +# Generated by GNU Autoconf 2.71 for Common Pipeline Library 7.2.2. # # Report bugs to . # # -# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. +# Copyright (C) 1992-1996, 1998-2017, 2020-2021 Free Software Foundation, +# Inc. # # # This configure script is free software; the Free Software Foundation @@ -16,14 +17,16 @@ # Be more Bourne compatible DUALCASE=1; export DUALCASE # for MKS sh -if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : +as_nop=: +if test ${ZSH_VERSION+y} && (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 +else $as_nop case `(set -o) 2>/dev/null` in #( *posix*) : set -o posix ;; #( @@ -33,46 +36,46 @@ fi + +# Reset variables that may have inherited troublesome values from +# the environment. + +# IFS needs to be set, to space, tab, and newline, in precisely that order. +# (If _AS_PATH_WALK were called with IFS unset, it would have the +# side effect of setting IFS to empty, thus disabling word splitting.) +# Quoting is to prevent editors from complaining about space-tab. 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 +IFS=" "" $as_nl" + +PS1='$ ' +PS2='> ' +PS4='+ ' + +# Ensure predictable behavior from utilities with locale-dependent output. +LC_ALL=C +export LC_ALL +LANGUAGE=C +export LANGUAGE + +# We cannot yet rely on "unset" to work, but we need these variables +# to be unset--not just set to an empty or harmless value--now, to +# avoid bugs in old shells (e.g. pre-3.0 UWIN ksh). This construct +# also avoids known problems related to "unset" and subshell syntax +# in other old shells (e.g. bash 2.01 and pdksh 5.2.14). +for as_var in BASH_ENV ENV MAIL MAILPATH CDPATH +do eval test \${$as_var+y} \ + && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : +done + +# Ensure that fds 0, 1, and 2 are open. +if (exec 3>&0) 2>/dev/null; then :; else exec 0&1) 2>/dev/null; then :; else exec 1>/dev/null; fi +if (exec 3>&2) ; then :; else exec 2>/dev/null; fi # The user is always right. -if test "${PATH_SEPARATOR+set}" != set; then +if ${PATH_SEPARATOR+false} :; 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 || @@ -81,13 +84,6 @@ 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 #(( @@ -96,8 +92,12 @@ 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 + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + test -r "$as_dir$0" && as_myself=$as_dir$0 && break done IFS=$as_save_IFS @@ -109,30 +109,10 @@ 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 + printf "%s\n" "$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. @@ -154,20 +134,22 @@ 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 +printf "%s\n" "$0: could not re-execute with $CONFIG_SHELL" >&2 +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 : + as_bourne_compatible="as_nop=: +if test \${ZSH_VERSION+y} && (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 +else \$as_nop case \`(set -o) 2>/dev/null\` in #( *posix*) : set -o posix ;; #( @@ -187,12 +169,15 @@ 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 : +if ( set x; as_fn_ret_success y && test x = \"\$1\" ) +then : -else +else \$as_nop exitcode=1; echo positional parameters were not saved. fi test x\$exitcode = x0 || exit 1 +blah=\$(echo \$(echo blah)) +test x\"\$blah\" = xblah || 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 @@ -207,30 +192,38 @@ test \"X\`printf %s \$ECHO\`\" = \"X\$ECHO\" \\ || test \"X\`print -r -- \$ECHO\`\" = \"X\$ECHO\" ) || exit 1 test \$(( 1 + 1 )) = 2 || exit 1" - if (eval "$as_required") 2>/dev/null; then : + if (eval "$as_required") 2>/dev/null +then : as_have_required=yes -else +else $as_nop as_have_required=no fi - if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null; then : + if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null +then : -else +else $as_nop 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=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac 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 + 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 : + as_run=a "$as_shell" -c "$as_bourne_compatible""$as_required" 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 : + if as_run=a "$as_shell" -c "$as_bourne_compatible""$as_suggested" 2>/dev/null +then : break 2 fi fi @@ -238,14 +231,21 @@ 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 $as_found +then : + +else $as_nop + if { test -f "$SHELL" || test -f "$SHELL.exe"; } && + as_run=a "$SHELL" -c "$as_bourne_compatible""$as_required" 2>/dev/null +then : + CONFIG_SHELL=$SHELL as_have_required=yes +fi +fi - if test "x$CONFIG_SHELL" != x; then : + 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 @@ -263,18 +263,19 @@ 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 +printf "%s\n" "$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." + if test x$as_have_required = xno +then : + printf "%s\n" "$0: This script requires a shell more modern than all" + printf "%s\n" "$0: the shells that I found on your system." + if test ${ZSH_VERSION+y} ; then + printf "%s\n" "$0: In particular, zsh $ZSH_VERSION has bugs and should" + printf "%s\n" "$0: be upgraded to zsh 4.3.4 or later." else - $as_echo "$0: Please tell bug-autoconf@gnu.org and cpl-help@eso.org + printf "%s\n" "$0: Please tell bug-autoconf@gnu.org and cpl-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 @@ -302,6 +303,7 @@ } as_unset=as_fn_unset + # as_fn_set_status STATUS # ----------------------- # Set $? to STATUS, without forking. @@ -319,6 +321,14 @@ as_fn_set_status $1 exit $1 } # as_fn_exit +# as_fn_nop +# --------- +# Do nothing but, unlike ":", preserve the value of $?. +as_fn_nop () +{ + return $? +} +as_nop=as_fn_nop # as_fn_mkdir_p # ------------- @@ -333,7 +343,7 @@ as_dirs= while :; do case $as_dir in #( - *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( + *\'*) as_qdir=`printf "%s\n" "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( *) as_qdir=$as_dir;; esac as_dirs="'$as_qdir' $as_dirs" @@ -342,7 +352,7 @@ X"$as_dir" : 'X\(//\)[^/]' \| \ X"$as_dir" : 'X\(//\)$' \| \ X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || -$as_echo X"$as_dir" | +printf "%s\n" X"$as_dir" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q @@ -381,12 +391,13 @@ # 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 : +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 +else $as_nop as_fn_append () { eval $1=\$$1\$2 @@ -398,18 +409,27 @@ # 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 : +if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null +then : eval 'as_fn_arith () { as_val=$(( $* )) }' -else +else $as_nop as_fn_arith () { as_val=`expr "$@" || test $? -eq 1` } fi # as_fn_arith +# as_fn_nop +# --------- +# Do nothing but, unlike ":", preserve the value of $?. +as_fn_nop () +{ + return $? +} +as_nop=as_fn_nop # as_fn_error STATUS ERROR [LINENO LOG_FD] # ---------------------------------------- @@ -421,9 +441,9 @@ 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 fi - $as_echo "$as_me: error: $2" >&2 + printf "%s\n" "$as_me: error: $2" >&2 as_fn_exit $as_status } # as_fn_error @@ -450,7 +470,7 @@ $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ X"$0" : 'X\(//\)$' \| \ X"$0" : 'X\(/\)' \| . 2>/dev/null || -$as_echo X/"$0" | +printf "%s\n" X/"$0" | sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/ q @@ -494,7 +514,7 @@ 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; } + { printf "%s\n" "$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 @@ -508,6 +528,10 @@ exit } + +# Determine whether it's possible to make 'echo' print without a newline. +# These variables are no longer used directly by Autoconf, but are AC_SUBSTed +# for compatibility with existing Makefiles. ECHO_C= ECHO_N= ECHO_T= case `echo -n x` in #((((( -n*) @@ -521,6 +545,13 @@ ECHO_N='-n';; esac +# For backward compatibility with old third-party macros, we provide +# the shell variables $as_echo and $as_echo_n. New code should use +# AS_ECHO(["message"]) and AS_ECHO_N(["message"]), respectively. +as_echo='printf %s\n' +as_echo_n='printf %s' + + rm -f conf$$ conf$$.exe conf$$.file if test -d conf$$.dir; then rm -f conf$$.dir/conf$$.file @@ -654,50 +685,47 @@ # Identity of this package. PACKAGE_NAME='Common Pipeline Library' PACKAGE_TARNAME='cpl' -PACKAGE_VERSION='7.1.4' -PACKAGE_STRING='Common Pipeline Library 7.1.4' +PACKAGE_VERSION='7.2.2' +PACKAGE_STRING='Common Pipeline Library 7.2.2' PACKAGE_BUGREPORT='cpl-help@eso.org' PACKAGE_URL='' ac_unique_file="cpl.h" # Factoring default headers for most tests. ac_includes_default="\ -#include -#ifdef HAVE_SYS_TYPES_H -# include -#endif -#ifdef HAVE_SYS_STAT_H -# include +#include +#ifdef HAVE_STDIO_H +# include #endif -#ifdef STDC_HEADERS +#ifdef HAVE_STDLIB_H # 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_STRINGS_H +# include +#endif +#ifdef HAVE_SYS_TYPES_H +# include +#endif +#ifdef HAVE_SYS_STAT_H +# include +#endif #ifdef HAVE_UNISTD_H # include #endif" +ac_header_c_list= enable_option_checking=no ac_default_prefix=${CPLDIR:-/usr/local} +ac_func_c_list= ac_subst_vars='ltdl_LTLIBOBJS ltdl_LIBOBJS am__EXEEXT_FALSE @@ -707,6 +735,7 @@ GASGANO_SUPPORT_FALSE GASGANO_SUPPORT_TRUE CPL_CFLAGS +LIBCPLGASGANO LIBCPLDFS LIBCPLUI LIBCPLDRS @@ -714,6 +743,7 @@ configdir apidocdir CPL_LDFLAGS +CPLJAVA_INCLUDES CPLDFS_INCLUDES CPLUI_INCLUDES CPLDRS_INCLUDES @@ -721,6 +751,7 @@ cpl_libraries cpl_includes LIBOBJS +CPP LIBFFTWF FFTWF_LDFLAGS FFTWF_CFLAGS @@ -786,7 +817,6 @@ LTDLDEPS LIBLTDL LIBTOOL_DEPS -CPP LT_SYS_LIBRARY_PATH OTOOL64 OTOOL @@ -815,7 +845,6 @@ AMDEPBACKSLASH AMDEP_FALSE AMDEP_TRUE -am__quote am__include DEPDIR OBJEXT @@ -883,6 +912,7 @@ docdir oldincludedir includedir +runstatedir localstatedir sharedstatedir sysconfdir @@ -901,7 +931,8 @@ PACKAGE_TARNAME PACKAGE_NAME PATH_SEPARATOR -SHELL' +SHELL +am__quote' ac_subst_files='' ac_user_opts=' enable_option_checking @@ -960,7 +991,6 @@ LIBS CPPFLAGS LT_SYS_LIBRARY_PATH -CPP DOXYGEN LATEX JAVA @@ -968,7 +998,8 @@ PKGCONFIG CFITSIODIR WCSDIR -FFTWDIR' +FFTWDIR +CPP' ac_subdirs_all='libltdl libcext' @@ -1008,6 +1039,7 @@ sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' +runstatedir='${localstatedir}/run' includedir='${prefix}/include' oldincludedir='/usr/include' docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' @@ -1037,8 +1069,6 @@ *) ac_optarg=yes ;; esac - # Accept the important Cygnus configure options, so we can diagnose typos. - case $ac_dashdash$ac_option in --) ac_dashdash=yes ;; @@ -1079,9 +1109,9 @@ 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" + as_fn_error $? "invalid feature name: \`$ac_useropt'" ac_useropt_orig=$ac_useropt - ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "enable_$ac_useropt" @@ -1105,9 +1135,9 @@ 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" + as_fn_error $? "invalid feature name: \`$ac_useropt'" ac_useropt_orig=$ac_useropt - ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "enable_$ac_useropt" @@ -1260,6 +1290,15 @@ | -silent | --silent | --silen | --sile | --sil) silent=yes ;; + -runstatedir | --runstatedir | --runstatedi | --runstated \ + | --runstate | --runstat | --runsta | --runst | --runs \ + | --run | --ru | --r) + ac_prev=runstatedir ;; + -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \ + | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \ + | --run=* | --ru=* | --r=*) + runstatedir=$ac_optarg ;; + -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ @@ -1309,9 +1348,9 @@ 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" + as_fn_error $? "invalid package name: \`$ac_useropt'" ac_useropt_orig=$ac_useropt - ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "with_$ac_useropt" @@ -1325,9 +1364,9 @@ 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" + as_fn_error $? "invalid package name: \`$ac_useropt'" ac_useropt_orig=$ac_useropt - ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "with_$ac_useropt" @@ -1371,9 +1410,9 @@ *) # FIXME: should be removed in autoconf 3.0. - $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2 + printf "%s\n" "$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 + printf "%s\n" "$as_me: WARNING: invalid host type: $ac_option" >&2 : "${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}" ;; @@ -1389,7 +1428,7 @@ 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 ;; + *) printf "%s\n" "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;; esac fi @@ -1397,7 +1436,7 @@ 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 + libdir localedir mandir runstatedir do eval ac_val=\$$ac_var # Remove trailing slashes. @@ -1453,7 +1492,7 @@ X"$as_myself" : 'X\(//\)[^/]' \| \ X"$as_myself" : 'X\(//\)$' \| \ X"$as_myself" : 'X\(/\)' \| . 2>/dev/null || -$as_echo X"$as_myself" | +printf "%s\n" X"$as_myself" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q @@ -1510,7 +1549,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 Common Pipeline Library 7.1.4 to adapt to many kinds of systems. +\`configure' configures Common Pipeline Library 7.2.2 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1550,6 +1589,7 @@ --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] + --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] @@ -1580,7 +1620,7 @@ if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of Common Pipeline Library 7.1.4:";; + short | recursive ) echo "Configuration of Common Pipeline Library 7.2.2:";; esac cat <<\_ACEOF @@ -1668,7 +1708,6 @@ you have headers in a nonstandard directory LT_SYS_LIBRARY_PATH User-defined run-time library search path. - CPP C preprocessor DOXYGEN doxygen command LATEX latex command JAVA Java application launcher @@ -1677,6 +1716,7 @@ CFITSIODIR Location where cfitsio is installed WCSDIR Location where wcslib is installed FFTWDIR Location where fftw is installed + CPP C preprocessor Use these variables to override the choices made by `configure' or to help it to find libraries and programs with nonstandard names/locations. @@ -1697,9 +1737,9 @@ case "$ac_dir" in .) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; *) - ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` + ac_dir_suffix=/`printf "%s\n" "$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|/||'` + ac_top_builddir_sub=`printf "%s\n" "$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/ ;; @@ -1727,7 +1767,8 @@ ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix cd "$ac_dir" || { ac_status=$?; continue; } - # Check for guested configure. + # Check for configure.gnu first; this name is used for a wrapper for + # Metaconfig's "Configure" on case-insensitive file systems. if test -f "$ac_srcdir/configure.gnu"; then echo && $SHELL "$ac_srcdir/configure.gnu" --help=recursive @@ -1735,7 +1776,7 @@ echo && $SHELL "$ac_srcdir/configure" --help=recursive else - $as_echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2 + printf "%s\n" "$as_me: WARNING: no configuration information is in $ac_dir" >&2 fi || ac_status=$? cd "$ac_pwd" || { ac_status=$?; break; } done @@ -1744,10 +1785,10 @@ test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -Common Pipeline Library configure 7.1.4 -generated by GNU Autoconf 2.69 +Common Pipeline Library configure 7.2.2 +generated by GNU Autoconf 2.71 -Copyright (C) 2012 Free Software Foundation, Inc. +Copyright (C) 2021 Free Software Foundation, Inc. This configure script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it. _ACEOF @@ -1764,14 +1805,14 @@ ac_fn_c_try_compile () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - rm -f conftest.$ac_objext + rm -f conftest.$ac_objext conftest.beam 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 +printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_compile") 2>conftest.err ac_status=$? if test -s conftest.err; then @@ -1779,14 +1820,15 @@ cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$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 : + } && test -s conftest.$ac_objext +then : ac_retval=0 -else - $as_echo "$as_me: failed program was:" >&5 +else $as_nop + printf "%s\n" "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 @@ -1802,14 +1844,14 @@ 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 + rm -f conftest.$ac_objext conftest.beam 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 +printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_link") 2>conftest.err ac_status=$? if test -s conftest.err; then @@ -1817,17 +1859,18 @@ cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$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 : + } +then : ac_retval=0 -else - $as_echo "$as_me: failed program was:" >&5 +else $as_nop + printf "%s\n" "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 @@ -1849,120 +1892,44 @@ 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +printf %s "checking for $2... " >&6; } +if eval test \${$3+y} +then : + printf %s "(cached) " >&6 +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 #include <$2> _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : eval "$3=yes" -else +else $as_nop eval "$3=no" fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi eval ac_res=\$$3 - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_header_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_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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +printf %s "checking for $2... " >&6; } +if eval test \${$3+y} +then : + printf %s "(cached) " >&6 +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Define $2 to an innocuous variant, in case declares $2. @@ -1970,16 +1937,9 @@ #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 + which can conflict with char $2 (); below. */ +#include #undef $2 /* Override any GCC internal prototype to avoid an error. @@ -1997,47 +1957,51 @@ #endif int -main () +main (void) { return $2 (); ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : eval "$3=yes" -else +else $as_nop eval "$3=no" fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_func -# ac_fn_c_check_decl LINENO SYMBOL VAR INCLUDES -# --------------------------------------------- +# ac_fn_check_decl LINENO SYMBOL VAR INCLUDES EXTRA-OPTIONS FLAG-VAR +# ------------------------------------------------------------------ # Tests whether SYMBOL is declared in INCLUDES, setting cache variable VAR -# accordingly. -ac_fn_c_check_decl () +# accordingly. Pass EXTRA-OPTIONS to the compiler, using FLAG-VAR. +ac_fn_check_decl () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack as_decl_name=`echo $2|sed 's/ *(.*//'` + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $as_decl_name is declared" >&5 +printf %s "checking whether $as_decl_name is declared... " >&6; } +if eval test \${$3+y} +then : + printf %s "(cached) " >&6 +else $as_nop 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 + eval ac_save_FLAGS=\$$6 + as_fn_append $6 " $5" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int -main () +main (void) { #ifndef $as_decl_name #ifdef __cplusplus @@ -2051,19 +2015,22 @@ return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : eval "$3=yes" -else +else $as_nop eval "$3=no" fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext + eval $6=\$ac_save_FLAGS + fi eval ac_res=\$$3 - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno -} # ac_fn_c_check_decl +} # ac_fn_check_decl # ac_fn_c_check_type LINENO TYPE VAR INCLUDES # ------------------------------------------- @@ -2072,17 +2039,18 @@ ac_fn_c_check_type () { 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +printf %s "checking for $2... " >&6; } +if eval test \${$3+y} +then : + printf %s "(cached) " >&6 +else $as_nop eval "$3=no" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int -main () +main (void) { if (sizeof ($2)) return 0; @@ -2090,12 +2058,13 @@ return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int -main () +main (void) { if (sizeof (($2))) return 0; @@ -2103,112 +2072,65 @@ return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : -else +else $as_nop eval "$3=yes" fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi eval ac_res=\$$3 - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_type -# 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 () +# ac_fn_c_try_run LINENO +# ---------------------- +# Try to run 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 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; } + 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\"" +printf "%s\n" "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + printf "%s\n" "$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\"" +printf "%s\n" "$ac_try_echo"; } >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; } +then : + ac_retval=0 +else $as_nop + printf "%s\n" "$as_me: program exited with status $ac_status" >&5 + printf "%s\n" "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 -# 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 cpl-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; } + 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_check_header_mongrel +} # ac_fn_c_try_run # ac_fn_c_compute_int LINENO EXPR VAR INCLUDES # -------------------------------------------- @@ -2224,7 +2146,7 @@ /* end confdefs.h. */ $4 int -main () +main (void) { static int test_array [1 - 2 * !(($2) >= 0)]; test_array [0] = 0; @@ -2234,14 +2156,15 @@ return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : ac_lo=0 ac_mid=0 while :; do cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int -main () +main (void) { static int test_array [1 - 2 * !(($2) <= $ac_mid)]; test_array [0] = 0; @@ -2251,9 +2174,10 @@ return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : ac_hi=$ac_mid; break -else +else $as_nop as_fn_arith $ac_mid + 1 && ac_lo=$as_val if test $ac_lo -le $ac_mid; then ac_lo= ac_hi= @@ -2261,14 +2185,14 @@ fi as_fn_arith 2 '*' $ac_mid + 1 && ac_mid=$as_val fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext done -else +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int -main () +main (void) { static int test_array [1 - 2 * !(($2) < 0)]; test_array [0] = 0; @@ -2278,14 +2202,15 @@ return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : ac_hi=-1 ac_mid=-1 while :; do cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int -main () +main (void) { static int test_array [1 - 2 * !(($2) >= $ac_mid)]; test_array [0] = 0; @@ -2295,9 +2220,10 @@ return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : ac_lo=$ac_mid; break -else +else $as_nop as_fn_arith '(' $ac_mid ')' - 1 && ac_hi=$as_val if test $ac_mid -le $ac_hi; then ac_lo= ac_hi= @@ -2305,14 +2231,14 @@ fi as_fn_arith 2 '*' $ac_mid && ac_mid=$as_val fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext done -else +else $as_nop ac_lo= ac_hi= fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext # Binary search between lo and hi bounds. while test "x$ac_lo" != "x$ac_hi"; do as_fn_arith '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo && ac_mid=$as_val @@ -2320,7 +2246,7 @@ /* end confdefs.h. */ $4 int -main () +main (void) { static int test_array [1 - 2 * !(($2) <= $ac_mid)]; test_array [0] = 0; @@ -2330,12 +2256,13 @@ return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : ac_hi=$ac_mid -else +else $as_nop as_fn_arith '(' $ac_mid ')' + 1 && ac_lo=$as_val fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext done case $ac_lo in #(( ?*) eval "$3=\$ac_lo"; ac_retval=0 ;; @@ -2345,12 +2272,12 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 -static long int longval () { return $2; } -static unsigned long int ulongval () { return $2; } +static long int longval (void) { return $2; } +static unsigned long int ulongval (void) { return $2; } #include #include int -main () +main (void) { FILE *f = fopen ("conftest.val", "w"); @@ -2378,9 +2305,10 @@ return 0; } _ACEOF -if ac_fn_c_try_run "$LINENO"; then : +if ac_fn_c_try_run "$LINENO" +then : echo >>conftest.val; read $3 &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 + printf "%s\n" "$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_nop + printf "%s\n" "$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_configure_args_raw= +for ac_arg +do + case $ac_arg in + *\'*) + ac_arg=`printf "%s\n" "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; + esac + as_fn_append ac_configure_args_raw " '$ac_arg'" +done + +case $ac_configure_args_raw in + *$as_nl*) + ac_safe_unquote= ;; + *) + ac_unsafe_z='|&;<>()$`\\"*?[ '' ' # This string ends in space, tab. + ac_unsafe_a="$ac_unsafe_z#~" + ac_safe_unquote="s/ '\\([^$ac_unsafe_a][^$ac_unsafe_z]*\\)'/ \\1/g" + ac_configure_args_raw=` printf "%s\n" "$ac_configure_args_raw" | sed "$ac_safe_unquote"`;; +esac + 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 Common Pipeline Library $as_me 7.1.4, which was -generated by GNU Autoconf 2.69. Invocation command line was +It was created by Common Pipeline Library $as_me 7.2.2, which was +generated by GNU Autoconf 2.71. Invocation command line was - $ $0 $@ + $ $0$ac_configure_args_raw _ACEOF exec 5>>config.log @@ -2432,8 +2418,12 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - $as_echo "PATH: $as_dir" + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + printf "%s\n" "PATH: $as_dir" done IFS=$as_save_IFS @@ -2468,7 +2458,7 @@ | -silent | --silent | --silen | --sile | --sil) continue ;; *\'*) - ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; + ac_arg=`printf "%s\n" "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; esac case $ac_pass in 1) as_fn_append ac_configure_args0 " '$ac_arg'" ;; @@ -2503,11 +2493,13 @@ # 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=$? + # Sanitize IFS. + IFS=" "" $as_nl" # Save into config.log some information that might help in debugging. { echo - $as_echo "## ---------------- ## + printf "%s\n" "## ---------------- ## ## Cache variables. ## ## ---------------- ##" echo @@ -2518,8 +2510,8 @@ 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;} ;; + *_cv_*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 +printf "%s\n" "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; esac case $ac_var in #( _ | IFS | as_nl) ;; #( @@ -2543,7 +2535,7 @@ ) echo - $as_echo "## ----------------- ## + printf "%s\n" "## ----------------- ## ## Output variables. ## ## ----------------- ##" echo @@ -2551,14 +2543,14 @@ do eval ac_val=\$$ac_var case $ac_val in - *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; + *\'\''*) ac_val=`printf "%s\n" "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; esac - $as_echo "$ac_var='\''$ac_val'\''" + printf "%s\n" "$ac_var='\''$ac_val'\''" done | sort echo if test -n "$ac_subst_files"; then - $as_echo "## ------------------- ## + printf "%s\n" "## ------------------- ## ## File substitutions. ## ## ------------------- ##" echo @@ -2566,15 +2558,15 @@ do eval ac_val=\$$ac_var case $ac_val in - *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; + *\'\''*) ac_val=`printf "%s\n" "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; esac - $as_echo "$ac_var='\''$ac_val'\''" + printf "%s\n" "$ac_var='\''$ac_val'\''" done | sort echo fi if test -s confdefs.h; then - $as_echo "## ----------- ## + printf "%s\n" "## ----------- ## ## confdefs.h. ## ## ----------- ##" echo @@ -2582,8 +2574,8 @@ echo fi test "$ac_signal" != 0 && - $as_echo "$as_me: caught signal $ac_signal" - $as_echo "$as_me: exit $exit_status" + printf "%s\n" "$as_me: caught signal $ac_signal" + printf "%s\n" "$as_me: exit $exit_status" } >&5 rm -f core *.core core.conftest.* && rm -f -r conftest* confdefs* conf$$* $ac_clean_files && @@ -2597,63 +2589,48 @@ # confdefs.h avoids OS command line length limits that DEFS can exceed. rm -f -r conftest* confdefs.h -$as_echo "/* confdefs.h */" > confdefs.h +printf "%s\n" "/* confdefs.h */" > confdefs.h # Predefined preprocessor variables. -cat >>confdefs.h <<_ACEOF -#define PACKAGE_NAME "$PACKAGE_NAME" -_ACEOF +printf "%s\n" "#define PACKAGE_NAME \"$PACKAGE_NAME\"" >>confdefs.h -cat >>confdefs.h <<_ACEOF -#define PACKAGE_TARNAME "$PACKAGE_TARNAME" -_ACEOF +printf "%s\n" "#define PACKAGE_TARNAME \"$PACKAGE_TARNAME\"" >>confdefs.h -cat >>confdefs.h <<_ACEOF -#define PACKAGE_VERSION "$PACKAGE_VERSION" -_ACEOF +printf "%s\n" "#define PACKAGE_VERSION \"$PACKAGE_VERSION\"" >>confdefs.h -cat >>confdefs.h <<_ACEOF -#define PACKAGE_STRING "$PACKAGE_STRING" -_ACEOF +printf "%s\n" "#define PACKAGE_STRING \"$PACKAGE_STRING\"" >>confdefs.h -cat >>confdefs.h <<_ACEOF -#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT" -_ACEOF +printf "%s\n" "#define PACKAGE_BUGREPORT \"$PACKAGE_BUGREPORT\"" >>confdefs.h -cat >>confdefs.h <<_ACEOF -#define PACKAGE_URL "$PACKAGE_URL" -_ACEOF +printf "%s\n" "#define PACKAGE_URL \"$PACKAGE_URL\"" >>confdefs.h # 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 + ac_site_files="$CONFIG_SITE" elif test "x$prefix" != xNONE; then - ac_site_file1=$prefix/share/config.site - ac_site_file2=$prefix/etc/config.site + ac_site_files="$prefix/share/config.site $prefix/etc/config.site" else - ac_site_file1=$ac_default_prefix/share/config.site - ac_site_file2=$ac_default_prefix/etc/config.site + ac_site_files="$ac_default_prefix/share/config.site $ac_default_prefix/etc/config.site" fi -for ac_site_file in "$ac_site_file1" "$ac_site_file2" + +for ac_site_file in $ac_site_files 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;} + case $ac_site_file in #( + */*) : + ;; #( + *) : + ac_site_file=./$ac_site_file ;; +esac + if test -f "$ac_site_file" && test -r "$ac_site_file"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5 +printf "%s\n" "$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;} + || { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$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 @@ -2663,19 +2640,435 @@ # 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;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5 +printf "%s\n" "$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;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5 +printf "%s\n" "$as_me: creating cache $cache_file" >&6;} >$cache_file fi +# Test code for whether the C compiler supports C89 (global declarations) +ac_c_conftest_c89_globals=' +/* Does the compiler advertise C89 conformance? + Do not test the value of __STDC__, because some compilers set it to 0 + while being otherwise adequately conformant. */ +#if !defined __STDC__ +# error "Compiler does not advertise C89 conformance" +#endif + +#include +#include +struct stat; +/* Most of the following tests are stolen from RCS 5.7 src/conf.sh. */ +struct buf { int x; }; +struct buf * (*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 do not provoke an error unfortunately, instead are silently treated + as an "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 is necessary to write \x00 == 0 to get something + that is 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 **, int *(*)(struct buf *, struct stat *, int), + int, int);' + +# Test code for whether the C compiler supports C89 (body of main). +ac_c_conftest_c89_main=' +ok |= (argc == 0 || f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]); +' + +# Test code for whether the C compiler supports C99 (global declarations) +ac_c_conftest_c99_globals=' +// Does the compiler advertise C99 conformance? +#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 199901L +# error "Compiler does not advertise C99 conformance" +#endif + +#include +extern int puts (const char *); +extern int printf (const char *, ...); +extern int dprintf (int, const char *, ...); +extern void *malloc (size_t); + +// Check varargs macros. These examples are taken from C99 6.10.3.5. +// dprintf is used instead of fprintf to avoid needing to declare +// FILE and stderr. +#define debug(...) dprintf (2, __VA_ARGS__) +#define showlist(...) puts (#__VA_ARGS__) +#define report(test,...) ((test) ? puts (#test) : printf (__VA_ARGS__)) +static void +test_varargs_macros (void) +{ + int x = 1234; + int y = 5678; + debug ("Flag"); + debug ("X = %d\n", x); + showlist (The first, second, and third items.); + report (x>y, "x is %d but y is %d", x, y); +} + +// Check long long types. +#define BIG64 18446744073709551615ull +#define BIG32 4294967295ul +#define BIG_OK (BIG64 / BIG32 == 4294967297ull && BIG64 % BIG32 == 0) +#if !BIG_OK + #error "your preprocessor is broken" +#endif +#if BIG_OK +#else + #error "your preprocessor is broken" +#endif +static long long int bignum = -9223372036854775807LL; +static unsigned long long int ubignum = BIG64; + +struct incomplete_array +{ + int datasize; + double data[]; +}; + +struct named_init { + int number; + const wchar_t *name; + double average; +}; + +typedef const char *ccp; + +static inline int +test_restrict (ccp restrict text) +{ + // See if C++-style comments work. + // Iterate through items via the restricted pointer. + // Also check for declarations in for loops. + for (unsigned int i = 0; *(text+i) != '\''\0'\''; ++i) + continue; + return 0; +} + +// Check varargs and va_copy. +static bool +test_varargs (const char *format, ...) +{ + va_list args; + va_start (args, format); + va_list args_copy; + va_copy (args_copy, args); + + const char *str = ""; + int number = 0; + float fnumber = 0; + + while (*format) + { + switch (*format++) + { + case '\''s'\'': // string + str = va_arg (args_copy, const char *); + break; + case '\''d'\'': // int + number = va_arg (args_copy, int); + break; + case '\''f'\'': // float + fnumber = va_arg (args_copy, double); + break; + default: + break; + } + } + va_end (args_copy); + va_end (args); + + return *str && number && fnumber; +} +' + +# Test code for whether the C compiler supports C99 (body of main). +ac_c_conftest_c99_main=' + // Check bool. + _Bool success = false; + success |= (argc != 0); + + // Check restrict. + if (test_restrict ("String literal") == 0) + success = true; + char *restrict newvar = "Another string"; + + // Check varargs. + success &= test_varargs ("s, d'\'' f .", "string", 65, 34.234); + test_varargs_macros (); + + // Check flexible array members. + struct incomplete_array *ia = + malloc (sizeof (struct incomplete_array) + (sizeof (double) * 10)); + ia->datasize = 10; + for (int i = 0; i < ia->datasize; ++i) + ia->data[i] = i * 1.234; + + // Check named initializers. + struct named_init ni = { + .number = 34, + .name = L"Test wide string", + .average = 543.34343, + }; + + ni.number = 58; + + int dynamic_array[ni.number]; + dynamic_array[0] = argv[0][0]; + dynamic_array[ni.number - 1] = 543; + + // work around unused variable warnings + ok |= (!success || bignum == 0LL || ubignum == 0uLL || newvar[0] == '\''x'\'' + || dynamic_array[ni.number - 1] != 543); +' + +# Test code for whether the C compiler supports C11 (global declarations) +ac_c_conftest_c11_globals=' +// Does the compiler advertise C11 conformance? +#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112L +# error "Compiler does not advertise C11 conformance" +#endif + +// Check _Alignas. +char _Alignas (double) aligned_as_double; +char _Alignas (0) no_special_alignment; +extern char aligned_as_int; +char _Alignas (0) _Alignas (int) aligned_as_int; + +// Check _Alignof. +enum +{ + int_alignment = _Alignof (int), + int_array_alignment = _Alignof (int[100]), + char_alignment = _Alignof (char) +}; +_Static_assert (0 < -_Alignof (int), "_Alignof is signed"); + +// Check _Noreturn. +int _Noreturn does_not_return (void) { for (;;) continue; } + +// Check _Static_assert. +struct test_static_assert +{ + int x; + _Static_assert (sizeof (int) <= sizeof (long int), + "_Static_assert does not work in struct"); + long int y; +}; + +// Check UTF-8 literals. +#define u8 syntax error! +char const utf8_literal[] = u8"happens to be ASCII" "another string"; + +// Check duplicate typedefs. +typedef long *long_ptr; +typedef long int *long_ptr; +typedef long_ptr long_ptr; + +// Anonymous structures and unions -- taken from C11 6.7.2.1 Example 1. +struct anonymous +{ + union { + struct { int i; int j; }; + struct { int k; long int l; } w; + }; + int m; +} v1; +' + +# Test code for whether the C compiler supports C11 (body of main). +ac_c_conftest_c11_main=' + _Static_assert ((offsetof (struct anonymous, i) + == offsetof (struct anonymous, w.k)), + "Anonymous union alignment botch"); + v1.i = 2; + v1.w.k = 5; + ok |= v1.i != 5; +' + +# Test code for whether the C compiler supports C11 (complete). +ac_c_conftest_c11_program="${ac_c_conftest_c89_globals} +${ac_c_conftest_c99_globals} +${ac_c_conftest_c11_globals} + +int +main (int argc, char **argv) +{ + int ok = 0; + ${ac_c_conftest_c89_main} + ${ac_c_conftest_c99_main} + ${ac_c_conftest_c11_main} + return ok; +} +" + +# Test code for whether the C compiler supports C99 (complete). +ac_c_conftest_c99_program="${ac_c_conftest_c89_globals} +${ac_c_conftest_c99_globals} + +int +main (int argc, char **argv) +{ + int ok = 0; + ${ac_c_conftest_c89_main} + ${ac_c_conftest_c99_main} + return ok; +} +" + +# Test code for whether the C compiler supports C89 (complete). +ac_c_conftest_c89_program="${ac_c_conftest_c89_globals} + +int +main (int argc, char **argv) +{ + int ok = 0; + ${ac_c_conftest_c89_main} + return ok; +} +" + +as_fn_append ac_header_c_list " stdio.h stdio_h HAVE_STDIO_H" +as_fn_append ac_header_c_list " stdlib.h stdlib_h HAVE_STDLIB_H" +as_fn_append ac_header_c_list " string.h string_h HAVE_STRING_H" +as_fn_append ac_header_c_list " inttypes.h inttypes_h HAVE_INTTYPES_H" +as_fn_append ac_header_c_list " stdint.h stdint_h HAVE_STDINT_H" +as_fn_append ac_header_c_list " strings.h strings_h HAVE_STRINGS_H" +as_fn_append ac_header_c_list " sys/stat.h sys_stat_h HAVE_SYS_STAT_H" +as_fn_append ac_header_c_list " sys/types.h sys_types_h HAVE_SYS_TYPES_H" +as_fn_append ac_header_c_list " unistd.h unistd_h HAVE_UNISTD_H" +as_fn_append ac_func_c_list " vprintf HAVE_VPRINTF" + +# Auxiliary files required by this configure script. +ac_aux_files="compile ltmain.sh missing install-sh config.guess config.sub" + +# Locations in which to look for auxiliary files. +ac_aux_dir_candidates="${srcdir}/admin" + +# Search for a directory containing all of the required auxiliary files, +# $ac_aux_files, from the $PATH-style list $ac_aux_dir_candidates. +# If we don't find one directory that contains all the files we need, +# we report the set of missing files from the *first* directory in +# $ac_aux_dir_candidates and give up. +ac_missing_aux_files="" +ac_first_candidate=: +printf "%s\n" "$as_me:${as_lineno-$LINENO}: looking for aux files: $ac_aux_files" >&5 +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +as_found=false +for as_dir in $ac_aux_dir_candidates +do + IFS=$as_save_IFS + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + as_found=: + + printf "%s\n" "$as_me:${as_lineno-$LINENO}: trying $as_dir" >&5 + ac_aux_dir_found=yes + ac_install_sh= + for ac_aux in $ac_aux_files + do + # As a special case, if "install-sh" is required, that requirement + # can be satisfied by any of "install-sh", "install.sh", or "shtool", + # and $ac_install_sh is set appropriately for whichever one is found. + if test x"$ac_aux" = x"install-sh" + then + if test -f "${as_dir}install-sh"; then + printf "%s\n" "$as_me:${as_lineno-$LINENO}: ${as_dir}install-sh found" >&5 + ac_install_sh="${as_dir}install-sh -c" + elif test -f "${as_dir}install.sh"; then + printf "%s\n" "$as_me:${as_lineno-$LINENO}: ${as_dir}install.sh found" >&5 + ac_install_sh="${as_dir}install.sh -c" + elif test -f "${as_dir}shtool"; then + printf "%s\n" "$as_me:${as_lineno-$LINENO}: ${as_dir}shtool found" >&5 + ac_install_sh="${as_dir}shtool install -c" + else + ac_aux_dir_found=no + if $ac_first_candidate; then + ac_missing_aux_files="${ac_missing_aux_files} install-sh" + else + break + fi + fi + else + if test -f "${as_dir}${ac_aux}"; then + printf "%s\n" "$as_me:${as_lineno-$LINENO}: ${as_dir}${ac_aux} found" >&5 + else + ac_aux_dir_found=no + if $ac_first_candidate; then + ac_missing_aux_files="${ac_missing_aux_files} ${ac_aux}" + else + break + fi + fi + fi + done + if test "$ac_aux_dir_found" = yes; then + ac_aux_dir="$as_dir" + break + fi + ac_first_candidate=false + + as_found=false +done +IFS=$as_save_IFS +if $as_found +then : + +else $as_nop + as_fn_error $? "cannot find required auxiliary files:$ac_missing_aux_files" "$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. +if test -f "${ac_aux_dir}config.guess"; then + ac_config_guess="$SHELL ${ac_aux_dir}config.guess" +fi +if test -f "${ac_aux_dir}config.sub"; then + ac_config_sub="$SHELL ${ac_aux_dir}config.sub" +fi +if test -f "$ac_aux_dir/configure"; then + ac_configure="$SHELL ${ac_aux_dir}configure" +fi + # Check that the precious variables saved in the cache have kept the same # value. ac_cache_corrupted=false @@ -2686,12 +3079,12 @@ 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;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 +printf "%s\n" "$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;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5 +printf "%s\n" "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} ac_cache_corrupted=: ;; ,);; *) @@ -2700,24 +3093,24 @@ 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;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5 +printf "%s\n" "$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;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5 +printf "%s\n" "$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;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: former value: \`$ac_old_val'" >&5 +printf "%s\n" "$as_me: former value: \`$ac_old_val'" >&2;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: current value: \`$ac_new_val'" >&5 +printf "%s\n" "$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=`printf "%s\n" "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;; *) ac_arg=$ac_var=$ac_new_val ;; esac case " $ac_configure_args " in @@ -2727,11 +3120,12 @@ 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5 +printf "%s\n" "$as_me: error: changes in the environment can compromise the build" >&2;} + as_fn_error $? "run \`${MAKE-make} distclean' and/or \`rm $cache_file' + and start over" "$LINENO" 5 fi ## -------------------- ## ## Main body of script. ## @@ -2748,37 +3142,12 @@ -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. + +ac_config_headers="$ac_config_headers config.h" -ac_config_headers="$ac_config_headers config.h" @@ -2788,26 +3157,27 @@ -# 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 + # 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 + +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking build system type" >&5 +printf %s "checking build system type... " >&6; } +if test ${ac_cv_build+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_build_alias=$build_alias test "x$ac_build_alias" = x && - ac_build_alias=`$SHELL "$ac_aux_dir/config.guess"` + 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 +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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_build" >&5 +printf "%s\n" "$ac_cv_build" >&6; } case $ac_cv_build in *-*-*) ;; *) as_fn_error $? "invalid value of canonical build" "$LINENO" 5;; @@ -2827,9 +3197,10 @@ -am__api_version='1.15' +am__api_version='1.16' -# Find a good install program. We prefer a C program (faster), + + # 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 @@ -2843,20 +3214,25 @@ # 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for a BSD-compatible install" >&5 +printf %s "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 +if test ${ac_cv_path_install+y} +then : + printf %s "(cached) " >&6 +else $as_nop 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]/* | \ + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + # Account for fact that we put trailing slashes in our PATH walk. +case $as_dir in #(( + ./ | /[cC]/* | \ /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \ ?:[\\/]os2[\\/]install[\\/]* | ?:[\\/]OS2[\\/]INSTALL[\\/]* | \ /usr/ucb/* ) ;; @@ -2866,13 +3242,13 @@ # 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 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 + 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 + 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 @@ -2880,12 +3256,12 @@ 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" && + 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" + ac_cv_path_install="$as_dir$ac_prog$ac_exec_ext -c" break 3 fi fi @@ -2901,7 +3277,7 @@ rm -rf conftest.one conftest.two conftest.dir fi - if test "${ac_cv_path_install+set}" = set; then + if test ${ac_cv_path_install+y}; then INSTALL=$ac_cv_path_install else # As a last resort, use the slow shell script. Don't cache a @@ -2911,8 +3287,8 @@ INSTALL=$ac_install_sh fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $INSTALL" >&5 -$as_echo "$INSTALL" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $INSTALL" >&5 +printf "%s\n" "$INSTALL" >&6; } # Use test -z because SunOS4 sh mishandles braces in ${var-val}. # It thinks the first close brace ends the variable substitution. @@ -2922,8 +3298,8 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether build environment is sane" >&5 +printf %s "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=' @@ -2977,8 +3353,8 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "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= @@ -2997,26 +3373,23 @@ # 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"` +program_transform_name=`printf "%s\n" "$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 + + if test x"${MISSING+set}" != xset; then + MISSING="\${SHELL} '$am_aux_dir/missing'" 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;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: 'missing' script is too old or missing" >&5 +printf "%s\n" "$as_me: WARNING: 'missing' script is too old or missing" >&2;} fi if test x"${install_sh+set}" != xset; then @@ -3036,11 +3409,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_STRIP+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$STRIP"; then ac_cv_prog_STRIP="$STRIP" # Let the user override the test. else @@ -3048,11 +3422,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -3063,11 +3441,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $STRIP" >&5 +printf "%s\n" "$STRIP" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -3076,11 +3454,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_STRIP+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_STRIP"; then ac_cv_prog_ac_ct_STRIP="$ac_ct_STRIP" # Let the user override the test. else @@ -3088,11 +3467,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -3103,11 +3486,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_STRIP" >&5 +printf "%s\n" "$ac_ct_STRIP" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi if test "x$ac_ct_STRIP" = x; then @@ -3115,8 +3498,8 @@ 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;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac STRIP=$ac_ct_STRIP @@ -3128,25 +3511,31 @@ 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; } + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for a race-free mkdir -p" >&5 +printf %s "checking for a race-free mkdir -p... " >&6; } if test -z "$MKDIR_P"; then - if ${ac_cv_path_mkdir+:} false; then : - $as_echo_n "(cached) " >&6 -else + if test ${ac_cv_path_mkdir+y} +then : + printf %s "(cached) " >&6 +else $as_nop 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=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac 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) '* | \ + 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 ('*'coreutils) '* | \ + 'BusyBox '* | \ 'mkdir (fileutils) '4.1*) - ac_cv_path_mkdir=$as_dir/$ac_prog$ac_exec_ext + ac_cv_path_mkdir=$as_dir$ac_prog$ac_exec_ext break 3;; esac done @@ -3157,7 +3546,7 @@ fi test -d ./--version && rmdir ./--version - if test "${ac_cv_path_mkdir+set}" = set; then + if test ${ac_cv_path_mkdir+y}; then MKDIR_P="$ac_cv_path_mkdir -p" else # As a last resort, use the slow shell script. Don't cache a @@ -3167,18 +3556,19 @@ MKDIR_P="$ac_install_sh -d" fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $MKDIR_P" >&5 -$as_echo "$MKDIR_P" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $MKDIR_P" >&5 +printf "%s\n" "$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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_AWK+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$AWK"; then ac_cv_prog_AWK="$AWK" # Let the user override the test. else @@ -3186,11 +3576,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -3201,24 +3595,25 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $AWK" >&5 +printf "%s\n" "$AWK" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} sets \$(MAKE)" >&5 +printf %s "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 +ac_make=`printf "%s\n" "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'` +if eval test \${ac_cv_prog_make_${ac_make}_set+y} +then : + printf %s "(cached) " >&6 +else $as_nop cat >conftest.make <<\_ACEOF SHELL = /bin/sh all: @@ -3234,12 +3629,12 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } SET_MAKE= else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } SET_MAKE="MAKE=${MAKE-make}" fi @@ -3253,7 +3648,8 @@ rmdir .tst 2>/dev/null # Check whether --enable-silent-rules was given. -if test "${enable_silent_rules+set}" = set; then : +if test ${enable_silent_rules+y} +then : enableval=$enable_silent_rules; fi @@ -3263,12 +3659,13 @@ *) 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)) +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $am_make supports nested variables" >&5 +printf %s "checking whether $am_make supports nested variables... " >&6; } +if test ${am_cv_make_support_nested_variables+y} +then : + printf %s "(cached) " >&6 +else $as_nop + if printf "%s\n" 'TRUE=$(BAR$(V)) BAR0=false BAR1=true V=1 @@ -3280,8 +3677,8 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $am_cv_make_support_nested_variables" >&5 +printf "%s\n" "$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)' @@ -3313,17 +3710,13 @@ # Define the identity of the package. PACKAGE='cpl' - VERSION='7.1.4' + VERSION='7.2.2' -cat >>confdefs.h <<_ACEOF -#define PACKAGE "$PACKAGE" -_ACEOF +printf "%s\n" "#define PACKAGE \"$PACKAGE\"" >>confdefs.h -cat >>confdefs.h <<_ACEOF -#define VERSION "$VERSION" -_ACEOF +printf "%s\n" "#define VERSION \"$VERSION\"" >>confdefs.h # Some tools Automake needs. @@ -3343,8 +3736,8 @@ # 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 @@ -3395,7 +3788,7 @@ 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: . +that behaves properly: . If you want to complete the configuration process using your problematic 'rm' anyway, export the environment variable ACCEPT_INFERIOR_RM_PROGRAM @@ -3407,7 +3800,8 @@ fi # Check whether --enable-silent-rules was given. -if test "${enable_silent_rules+set}" = set; then : +if test ${enable_silent_rules+y} +then : enableval=$enable_silent_rules; fi @@ -3417,12 +3811,13 @@ *) 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)) +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $am_make supports nested variables" >&5 +printf %s "checking whether $am_make supports nested variables... " >&6; } +if test ${am_cv_make_support_nested_variables+y} +then : + printf %s "(cached) " >&6 +else $as_nop + if printf "%s\n" 'TRUE=$(BAR$(V)) BAR0=false BAR1=true V=1 @@ -3434,8 +3829,8 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $am_cv_make_support_nested_variables" >&5 +printf "%s\n" "$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)' @@ -3447,17 +3842,18 @@ -{ $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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether to enable maintainer-specific portions of Makefiles" >&5 +printf %s "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 : +if test ${enable_maintainer_mode+y} +then : enableval=$enable_maintainer_mode; USE_MAINTAINER_MODE=$enableval -else +else $as_nop USE_MAINTAINER_MODE=no fi - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $USE_MAINTAINER_MODE" >&5 -$as_echo "$USE_MAINTAINER_MODE" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $USE_MAINTAINER_MODE" >&5 +printf "%s\n" "$USE_MAINTAINER_MODE" >&6; } if test $USE_MAINTAINER_MODE = yes; then MAINTAINER_MODE_TRUE= MAINTAINER_MODE_FALSE='#' @@ -3472,8 +3868,8 @@ 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;} ;; + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&5 +printf "%s\n" "$as_me: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&2;} ;; esac @@ -3493,23 +3889,25 @@ + ltmain=$ac_aux_dir/ltmain.sh -{ $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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking host system type" >&5 +printf %s "checking host system type... " >&6; } +if test ${ac_cv_host+y} +then : + printf %s "(cached) " >&6 +else $as_nop 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 + 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_host" >&5 +printf "%s\n" "$ac_cv_host" >&6; } case $ac_cv_host in *-*-*) ;; *) as_fn_error $? "invalid value of canonical host" "$LINENO" 5;; @@ -3549,8 +3947,8 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to print strings" >&5 +printf %s "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 @@ -3576,12 +3974,12 @@ } 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; } ;; + printf*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: printf" >&5 +printf "%s\n" "printf" >&6; } ;; + print*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: print -r" >&5 +printf "%s\n" "print -r" >&6; } ;; + *) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: cat" >&5 +printf "%s\n" "cat" >&6; } ;; esac @@ -3597,52 +3995,62 @@ + + + + + + + + + DEPDIR="${am__leading_dot}deps" ac_config_commands="$ac_config_commands depfiles" - -am_make=${MAKE-make} -cat > confinc << 'END' +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} supports the include directive" >&5 +printf %s "checking whether ${MAKE-make} supports the include directive... " >&6; } +cat > confinc.mk << 'END' am__doit: - @echo this is the am__doit target + @echo this is the am__doit target >confinc.out .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 +# BSD make does it like this. +echo '.include "confinc.mk" # ignored' > confmf.BSD +# Other make implementations (GNU, Solaris 10, AIX) do it like this. +echo 'include confinc.mk # ignored' > confmf.GNU +_am_result=no +for s in GNU BSD; do + { echo "$as_me:$LINENO: ${MAKE-make} -f confmf.$s && cat confinc.out" >&5 + (${MAKE-make} -f confmf.$s && cat confinc.out) >&5 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } + case $?:`cat confinc.out 2>/dev/null` in #( + '0:this is the am__doit target') : + case $s in #( + BSD) : + am__include='.include' am__quote='"' ;; #( + *) : + am__include='include' am__quote='' ;; +esac ;; #( + *) : ;; - esac -fi - - -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $_am_result" >&5 -$as_echo "$_am_result" >&6; } -rm -f confinc confmf +esac + if test "$am__include" != "#"; then + _am_result="yes ($s style)" + break + fi +done +rm -f confinc.* confmf.* +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: ${_am_result}" >&5 +printf "%s\n" "${_am_result}" >&6; } # Check whether --enable-dependency-tracking was given. -if test "${enable_dependency_tracking+set}" = set; then : +if test ${enable_dependency_tracking+y} +then : enableval=$enable_dependency_tracking; fi @@ -3668,11 +4076,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_CC+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else @@ -3680,11 +4089,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -3695,11 +4108,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +printf "%s\n" "$CC" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -3708,11 +4121,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_CC+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_CC"; then ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. else @@ -3720,11 +4134,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -3735,11 +4153,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 +printf "%s\n" "$ac_ct_CC" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi if test "x$ac_ct_CC" = x; then @@ -3747,8 +4165,8 @@ 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;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac CC=$ac_ct_CC @@ -3761,11 +4179,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_CC+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else @@ -3773,11 +4192,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -3788,11 +4211,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +printf "%s\n" "$CC" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -3801,11 +4224,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_CC+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else @@ -3814,15 +4238,19 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac 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 + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -3838,18 +4266,18 @@ # 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+' '}$@" + 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +printf "%s\n" "$CC" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -3860,11 +4288,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_CC+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else @@ -3872,11 +4301,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -3887,11 +4320,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +printf "%s\n" "$CC" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -3904,11 +4337,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_CC+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_CC"; then ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. else @@ -3916,11 +4350,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -3931,11 +4369,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 +printf "%s\n" "$ac_ct_CC" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -3947,34 +4385,138 @@ 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;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + CC=$ac_ct_CC + fi +fi + +fi +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}clang", so it can be a program name with args. +set dummy ${ac_tool_prefix}clang; ac_word=$2 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_CC+y} +then : + printf %s "(cached) " >&6 +else $as_nop + 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 + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + 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}clang" + printf "%s\n" "$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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +printf "%s\n" "$CC" >&6; } +else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_CC"; then + ac_ct_CC=$CC + # Extract the first word of "clang", so it can be a program name with args. +set dummy clang; ac_word=$2 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_CC+y} +then : + printf %s "(cached) " >&6 +else $as_nop + 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 + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + 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="clang" + printf "%s\n" "$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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 +printf "%s\n" "$ac_ct_CC" >&6; } +else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } +fi + + if test "x$ac_ct_CC" = x; then + CC="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$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 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;} +test -z "$CC" && { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$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 +printf "%s\n" "$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 +for ac_option in --version -v -V -qversion -version; 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 +printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_compiler $ac_option >&5") 2>conftest.err ac_status=$? if test -s conftest.err; then @@ -3984,7 +4526,7 @@ cat conftest.er1 >&5 fi rm -f conftest.er1 conftest.err - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } done @@ -3992,7 +4534,7 @@ /* end confdefs.h. */ int -main () +main (void) { ; @@ -4004,9 +4546,9 @@ # 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[^ ]*//'` +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5 +printf %s "checking whether the C compiler works... " >&6; } +ac_link_default=`printf "%s\n" "$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.*" @@ -4027,11 +4569,12 @@ *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 +printf "%s\n" "$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 : + printf "%s\n" "$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, @@ -4048,7 +4591,7 @@ # certainly right. break;; *.* ) - if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no; + if test ${ac_cv_exeext+y} && test "$ac_cv_exeext" != no; then :; else ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` fi @@ -4064,44 +4607,46 @@ done test "$ac_cv_exeext" = no && ac_cv_exeext= -else +else $as_nop 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 +if test -z "$ac_file" +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } +printf "%s\n" "$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;} +{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$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; } +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5 +printf %s "checking for C compiler default output file name... " >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5 +printf "%s\n" "$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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5 +printf %s "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 +printf "%s\n" "$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 : + printf "%s\n" "$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 @@ -4115,15 +4660,15 @@ * ) 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;} +else $as_nop + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5 +printf "%s\n" "$ac_cv_exeext" >&6; } rm -f conftest.$ac_ext EXEEXT=$ac_cv_exeext @@ -4132,7 +4677,7 @@ /* end confdefs.h. */ #include int -main () +main (void) { FILE *f = fopen ("conftest.out", "w"); return ferror (f) || fclose (f) != 0; @@ -4144,8 +4689,8 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5 +printf %s "checking whether we are cross compiling... " >&6; } if test "$cross_compiling" != yes; then { { ac_try="$ac_link" case "(($ac_try" in @@ -4153,10 +4698,10 @@ *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 +printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_link") 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } if { ac_try='./conftest$ac_cv_exeext' { { case "(($ac_try" in @@ -4164,39 +4709,40 @@ *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 +printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_try") 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$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. + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error 77 "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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5 +printf "%s\n" "$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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5 +printf %s "checking for suffix of object files... " >&6; } +if test ${ac_cv_objext+y} +then : + printf %s "(cached) " >&6 +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main () +main (void) { ; @@ -4210,11 +4756,12 @@ *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 +printf "%s\n" "$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 : + printf "%s\n" "$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 @@ -4223,31 +4770,32 @@ break;; esac done -else - $as_echo "$as_me: failed program was:" >&5 +else $as_nop + printf "%s\n" "$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;} +{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5 +printf "%s\n" "$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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports GNU C" >&5 +printf %s "checking whether the compiler supports GNU C... " >&6; } +if test ${ac_cv_c_compiler_gnu+y} +then : + printf %s "(cached) " >&6 +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main () +main (void) { #ifndef __GNUC__ choke me @@ -4257,29 +4805,33 @@ return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : ac_compiler_gnu=yes -else +else $as_nop ac_compiler_gnu=no fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5 +printf "%s\n" "$ac_cv_c_compiler_gnu" >&6; } +ac_compiler_gnu=$ac_cv_c_compiler_gnu + if test $ac_compiler_gnu = yes; then GCC=yes else GCC= fi -ac_test_CFLAGS=${CFLAGS+set} +ac_test_CFLAGS=${CFLAGS+y} 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5 +printf %s "checking whether $CC accepts -g... " >&6; } +if test ${ac_cv_prog_cc_g+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_save_c_werror_flag=$ac_c_werror_flag ac_c_werror_flag=yes ac_cv_prog_cc_g=no @@ -4288,57 +4840,60 @@ /* end confdefs.h. */ int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : ac_cv_prog_cc_g=yes -else +else $as_nop CFLAGS="" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : -else +else $as_nop ac_c_werror_flag=$ac_save_c_werror_flag CFLAGS="-g" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +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 +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5 +printf "%s\n" "$ac_cv_prog_cc_g" >&6; } +if test $ac_test_CFLAGS; then CFLAGS=$ac_save_CFLAGS elif test $ac_cv_prog_cc_g = yes; then if test "$GCC" = yes; then @@ -4353,94 +4908,144 @@ 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_prog_cc_stdc=no +if test x$ac_prog_cc_stdc = xno +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC option to enable C11 features" >&5 +printf %s "checking for $CC option to enable C11 features... " >&6; } +if test ${ac_cv_prog_cc_c11+y} +then : + printf %s "(cached) " >&6 +else $as_nop + ac_cv_prog_cc_c11=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]; +$ac_c_conftest_c11_program +_ACEOF +for ac_arg in '' -std=gnu11 +do + CC="$ac_save_CC $ac_arg" + if ac_fn_c_try_compile "$LINENO" +then : + ac_cv_prog_cc_c11=$ac_arg +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam + test "x$ac_cv_prog_cc_c11" != "xno" && break +done +rm -f conftest.$ac_ext +CC=$ac_save_CC +fi -/* 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]; +if test "x$ac_cv_prog_cc_c11" = xno +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 +printf "%s\n" "unsupported" >&6; } +else $as_nop + if test "x$ac_cv_prog_cc_c11" = x +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 +printf "%s\n" "none needed" >&6; } +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c11" >&5 +printf "%s\n" "$ac_cv_prog_cc_c11" >&6; } + CC="$CC $ac_cv_prog_cc_c11" +fi + ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c11 + ac_prog_cc_stdc=c11 +fi +fi +if test x$ac_prog_cc_stdc = xno +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC option to enable C99 features" >&5 +printf %s "checking for $CC option to enable C99 features... " >&6; } +if test ${ac_cv_prog_cc_c99+y} +then : + printf %s "(cached) " >&6 +else $as_nop + ac_cv_prog_cc_c99=no +ac_save_CC=$CC +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$ac_c_conftest_c99_program +_ACEOF +for ac_arg in '' -std=gnu99 -std=c99 -c99 -qlanglvl=extc1x -qlanglvl=extc99 -AC99 -D_STDC_C99= +do + CC="$ac_save_CC $ac_arg" + if ac_fn_c_try_compile "$LINENO" +then : + ac_cv_prog_cc_c99=$ac_arg +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam + test "x$ac_cv_prog_cc_c99" != "xno" && break +done +rm -f conftest.$ac_ext +CC=$ac_save_CC +fi -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; -} +if test "x$ac_cv_prog_cc_c99" = xno +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 +printf "%s\n" "unsupported" >&6; } +else $as_nop + if test "x$ac_cv_prog_cc_c99" = x +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 +printf "%s\n" "none needed" >&6; } +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c99" >&5 +printf "%s\n" "$ac_cv_prog_cc_c99" >&6; } + CC="$CC $ac_cv_prog_cc_c99" +fi + ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c99 + ac_prog_cc_stdc=c99 +fi +fi +if test x$ac_prog_cc_stdc = xno +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC option to enable C89 features" >&5 +printf %s "checking for $CC option to enable C89 features... " >&6; } +if test ${ac_cv_prog_cc_c89+y} +then : + printf %s "(cached) " >&6 +else $as_nop + ac_cv_prog_cc_c89=no +ac_save_CC=$CC +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$ac_c_conftest_c89_program _ACEOF -for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \ - -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" +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 : + if ac_fn_c_try_compile "$LINENO" +then : ac_cv_prog_cc_c89=$ac_arg fi -rm -f core conftest.err conftest.$ac_objext +rm -f core conftest.err conftest.$ac_objext conftest.beam 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 : +if test "x$ac_cv_prog_cc_c89" = xno +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 +printf "%s\n" "unsupported" >&6; } +else $as_nop + if test "x$ac_cv_prog_cc_c89" = x +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 +printf "%s\n" "none needed" >&6; } +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5 +printf "%s\n" "$ac_cv_prog_cc_c89" >&6; } + CC="$CC $ac_cv_prog_cc_c89" +fi + ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c89 + ac_prog_cc_stdc=c89 +fi fi ac_ext=c @@ -4449,21 +5054,23 @@ 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_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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC understands -c and -o together" >&5 +printf %s "checking whether $CC understands -c and -o together... " >&6; } +if test ${am_cv_prog_cc_c_o+y} +then : + printf %s "(cached) " >&6 +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main () +main (void) { ; @@ -4491,8 +5098,8 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $am_cv_prog_cc_c_o" >&5 +printf "%s\n" "$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. @@ -4510,11 +5117,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking dependency style of $depcc" >&5 +printf %s "checking dependency style of $depcc... " >&6; } +if test ${am_cv_CC_dependencies_compiler_type+y} +then : + printf %s "(cached) " >&6 +else $as_nop 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 @@ -4621,8 +5229,8 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $am_cv_CC_dependencies_compiler_type" >&5 +printf "%s\n" "$am_cv_CC_dependencies_compiler_type" >&6; } CCDEPMODE=depmode=$am_cv_CC_dependencies_compiler_type if @@ -4636,11 +5244,12 @@ fi -{ $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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for a sed that does not truncate output" >&5 +printf %s "checking for a sed that does not truncate output... " >&6; } +if test ${ac_cv_path_SED+y} +then : + printf %s "(cached) " >&6 +else $as_nop 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" @@ -4654,10 +5263,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_prog in sed gsed; do + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + 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" + 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 @@ -4666,13 +5280,13 @@ ac_cv_path_SED="$ac_path_SED" ac_path_SED_found=:;; *) ac_count=0 - $as_echo_n 0123456789 >"conftest.in" + printf %s 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" + printf "%s\n" '' >> "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 @@ -4700,8 +5314,8 @@ fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_SED" >&5 -$as_echo "$ac_cv_path_SED" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_SED" >&5 +printf "%s\n" "$ac_cv_path_SED" >&6; } SED="$ac_cv_path_SED" rm -f conftest.sed @@ -4718,11 +5332,12 @@ -{ $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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5 +printf %s "checking for grep that handles long lines and -e... " >&6; } +if test ${ac_cv_path_GREP+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -z "$GREP"; then ac_path_GREP_found=false # Loop through the user's path and test for each of PROGNAME-LIST @@ -4730,10 +5345,15 @@ 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 + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + 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" + 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 @@ -4742,13 +5362,13 @@ ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;; *) ac_count=0 - $as_echo_n 0123456789 >"conftest.in" + printf %s 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" + printf "%s\n" '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 @@ -4776,16 +5396,17 @@ fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5 -$as_echo "$ac_cv_path_GREP" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5 +printf "%s\n" "$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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5 +printf %s "checking for egrep... " >&6; } +if test ${ac_cv_path_EGREP+y} +then : + printf %s "(cached) " >&6 +else $as_nop if echo a | $GREP -E '(a|b)' >/dev/null 2>&1 then ac_cv_path_EGREP="$GREP -E" else @@ -4796,10 +5417,15 @@ 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 + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + 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" + 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 @@ -4808,13 +5434,13 @@ ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;; *) ac_count=0 - $as_echo_n 0123456789 >"conftest.in" + printf %s 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" + printf "%s\n" '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 @@ -4843,16 +5469,17 @@ fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5 -$as_echo "$ac_cv_path_EGREP" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5 +printf "%s\n" "$ac_cv_path_EGREP" >&6; } EGREP="$ac_cv_path_EGREP" -{ $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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for fgrep" >&5 +printf %s "checking for fgrep... " >&6; } +if test ${ac_cv_path_FGREP+y} +then : + printf %s "(cached) " >&6 +else $as_nop if echo 'ab*c' | $GREP -F 'ab*c' >/dev/null 2>&1 then ac_cv_path_FGREP="$GREP -F" else @@ -4863,10 +5490,15 @@ 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 + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + 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" + 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 @@ -4875,13 +5507,13 @@ ac_cv_path_FGREP="$ac_path_FGREP" ac_path_FGREP_found=:;; *) ac_count=0 - $as_echo_n 0123456789 >"conftest.in" + printf %s 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" + printf "%s\n" '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 @@ -4910,8 +5542,8 @@ fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_FGREP" >&5 -$as_echo "$ac_cv_path_FGREP" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_FGREP" >&5 +printf "%s\n" "$ac_cv_path_FGREP" >&6; } FGREP="$ac_cv_path_FGREP" @@ -4936,17 +5568,18 @@ # Check whether --with-gnu-ld was given. -if test "${with_gnu_ld+set}" = set; then : +if test ${with_gnu_ld+y} +then : withval=$with_gnu_ld; test no = "$withval" || with_gnu_ld=yes -else +else $as_nop 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for ld used by $CC" >&5 +printf %s "checking for ld used by $CC... " >&6; } case $host in *-*-mingw*) # gcc leaves a trailing carriage return, which upsets mingw @@ -4975,15 +5608,16 @@ ;; 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for GNU ld" >&5 +printf %s "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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for non-GNU ld" >&5 +printf %s "checking for non-GNU ld... " >&6; } fi -if ${lt_cv_path_LD+:} false; then : - $as_echo_n "(cached) " >&6 -else +if test ${lt_cv_path_LD+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -z "$LD"; then lt_save_ifs=$IFS; IFS=$PATH_SEPARATOR for ac_dir in $PATH; do @@ -5012,18 +5646,19 @@ LD=$lt_cv_path_LD if test -n "$LD"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LD" >&5 -$as_echo "$LD" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $LD" >&5 +printf "%s\n" "$LD" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if the linker ($LD) is GNU ld" >&5 +printf %s "checking if the linker ($LD) is GNU ld... " >&6; } +if test ${lt_cv_prog_gnu_ld+y} +then : + printf %s "(cached) " >&6 +else $as_nop # 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_gnu_ld" >&5 +printf "%s\n" "$lt_cv_prog_gnu_ld" >&6; } with_gnu_ld=$lt_cv_prog_gnu_ld @@ -5046,11 +5681,12 @@ -{ $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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for BSD- or MS-compatible name lister (nm)" >&5 +printf %s "checking for BSD- or MS-compatible name lister (nm)... " >&6; } +if test ${lt_cv_path_NM+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$NM"; then # Let the user override the test. lt_cv_path_NM=$NM @@ -5100,8 +5736,8 @@ : ${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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_path_NM" >&5 +printf "%s\n" "$lt_cv_path_NM" >&6; } if test no != "$lt_cv_path_NM"; then NM=$lt_cv_path_NM else @@ -5114,11 +5750,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_DUMPBIN+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$DUMPBIN"; then ac_cv_prog_DUMPBIN="$DUMPBIN" # Let the user override the test. else @@ -5126,11 +5763,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -5141,11 +5782,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $DUMPBIN" >&5 +printf "%s\n" "$DUMPBIN" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -5158,11 +5799,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_DUMPBIN+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_DUMPBIN"; then ac_cv_prog_ac_ct_DUMPBIN="$ac_ct_DUMPBIN" # Let the user override the test. else @@ -5170,11 +5812,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -5185,11 +5831,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DUMPBIN" >&5 +printf "%s\n" "$ac_ct_DUMPBIN" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -5201,8 +5847,8 @@ 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;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac DUMPBIN=$ac_ct_DUMPBIN @@ -5230,11 +5876,12 @@ -{ $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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking the name lister ($NM) interface" >&5 +printf %s "checking the name lister ($NM) interface... " >&6; } +if test ${lt_cv_nm_interface+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_nm_interface="BSD nm" echo "int some_variable = 0;" > conftest.$ac_ext (eval echo "\"\$as_me:$LINENO: $ac_compile\"" >&5) @@ -5250,26 +5897,27 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_nm_interface" >&5 +printf "%s\n" "$lt_cv_nm_interface" >&6; } -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ln -s works" >&5 -$as_echo_n "checking whether ln -s works... " >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether ln -s works" >&5 +printf %s "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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no, using $LN_S" >&5 -$as_echo "no, using $LN_S" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no, using $LN_S" >&5 +printf "%s\n" "no, using $LN_S" >&6; } fi # 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking the maximum length of command line arguments" >&5 +printf %s "checking the maximum length of command line arguments... " >&6; } +if test ${lt_cv_sys_max_cmd_len+y} +then : + printf %s "(cached) " >&6 +else $as_nop i=0 teststring=ABCD @@ -5396,11 +6044,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_sys_max_cmd_len" >&5 +printf "%s\n" "$lt_cv_sys_max_cmd_len" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: none" >&5 -$as_echo "none" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none" >&5 +printf "%s\n" "none" >&6; } fi max_cmd_len=$lt_cv_sys_max_cmd_len @@ -5444,11 +6092,12 @@ -{ $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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to convert $build file names to $host format" >&5 +printf %s "checking how to convert $build file names to $host format... " >&6; } +if test ${lt_cv_to_host_file_cmd+y} +then : + printf %s "(cached) " >&6 +else $as_nop case $host in *-*-mingw* ) case $build in @@ -5484,18 +6133,19 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_to_host_file_cmd" >&5 +printf "%s\n" "$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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to convert $build file names to toolchain format" >&5 +printf %s "checking how to convert $build file names to toolchain format... " >&6; } +if test ${lt_cv_to_tool_file_cmd+y} +then : + printf %s "(cached) " >&6 +else $as_nop #assume ordinary cross tools, or native build. lt_cv_to_tool_file_cmd=func_convert_file_noop case $host in @@ -5511,22 +6161,23 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_to_tool_file_cmd" >&5 +printf "%s\n" "$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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $LD option to reload object files" >&5 +printf %s "checking for $LD option to reload object files... " >&6; } +if test ${lt_cv_ld_reload_flag+y} +then : + printf %s "(cached) " >&6 +else $as_nop 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_reload_flag" >&5 +printf "%s\n" "$lt_cv_ld_reload_flag" >&6; } reload_flag=$lt_cv_ld_reload_flag case $reload_flag in "" | " "*) ;; @@ -5559,11 +6210,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_OBJDUMP+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$OBJDUMP"; then ac_cv_prog_OBJDUMP="$OBJDUMP" # Let the user override the test. else @@ -5571,11 +6223,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -5586,11 +6242,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $OBJDUMP" >&5 +printf "%s\n" "$OBJDUMP" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -5599,11 +6255,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_OBJDUMP+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_OBJDUMP"; then ac_cv_prog_ac_ct_OBJDUMP="$ac_ct_OBJDUMP" # Let the user override the test. else @@ -5611,11 +6268,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -5626,11 +6287,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OBJDUMP" >&5 +printf "%s\n" "$ac_ct_OBJDUMP" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi if test "x$ac_ct_OBJDUMP" = x; then @@ -5638,8 +6299,8 @@ 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;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac OBJDUMP=$ac_ct_OBJDUMP @@ -5658,11 +6319,12 @@ -{ $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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to recognize dependent libraries" >&5 +printf %s "checking how to recognize dependent libraries... " >&6; } +if test ${lt_cv_deplibs_check_method+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_file_magic_cmd='$MAGIC_CMD' lt_cv_file_magic_test_file= lt_cv_deplibs_check_method='unknown' @@ -5858,8 +6520,8 @@ esac fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_deplibs_check_method" >&5 -$as_echo "$lt_cv_deplibs_check_method" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_deplibs_check_method" >&5 +printf "%s\n" "$lt_cv_deplibs_check_method" >&6; } file_magic_glob= want_nocaseglob=no @@ -5903,11 +6565,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_DLLTOOL+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$DLLTOOL"; then ac_cv_prog_DLLTOOL="$DLLTOOL" # Let the user override the test. else @@ -5915,11 +6578,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -5930,11 +6597,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $DLLTOOL" >&5 +printf "%s\n" "$DLLTOOL" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -5943,11 +6610,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_DLLTOOL+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_DLLTOOL"; then ac_cv_prog_ac_ct_DLLTOOL="$ac_ct_DLLTOOL" # Let the user override the test. else @@ -5955,11 +6623,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -5970,11 +6642,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DLLTOOL" >&5 +printf "%s\n" "$ac_ct_DLLTOOL" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi if test "x$ac_ct_DLLTOOL" = x; then @@ -5982,8 +6654,8 @@ 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;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac DLLTOOL=$ac_ct_DLLTOOL @@ -6003,11 +6675,12 @@ -{ $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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to associate runtime and link libraries" >&5 +printf %s "checking how to associate runtime and link libraries... " >&6; } +if test ${lt_cv_sharedlib_from_linklib_cmd+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_sharedlib_from_linklib_cmd='unknown' case $host_os in @@ -6030,8 +6703,8 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_sharedlib_from_linklib_cmd" >&5 +printf "%s\n" "$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 @@ -6047,11 +6720,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_AR+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$AR"; then ac_cv_prog_AR="$AR" # Let the user override the test. else @@ -6059,11 +6733,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -6074,11 +6752,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $AR" >&5 +printf "%s\n" "$AR" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -6091,11 +6769,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_AR+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_AR"; then ac_cv_prog_ac_ct_AR="$ac_ct_AR" # Let the user override the test. else @@ -6103,11 +6782,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -6118,11 +6801,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_AR" >&5 +printf "%s\n" "$ac_ct_AR" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -6134,8 +6817,8 @@ 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;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac AR=$ac_ct_AR @@ -6155,30 +6838,32 @@ -{ $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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for archiver @FILE support" >&5 +printf %s "checking for archiver @FILE support... " >&6; } +if test ${lt_cv_ar_at_file+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_ar_at_file=no cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +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 + printf "%s\n" "$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. @@ -6186,7 +6871,7 @@ { { 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } if test 0 -ne "$ac_status"; then lt_cv_ar_at_file=@ @@ -6195,11 +6880,11 @@ rm -f conftest.* libconftest.a fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ar_at_file" >&5 +printf "%s\n" "$lt_cv_ar_at_file" >&6; } if test no = "$lt_cv_ar_at_file"; then archiver_list_spec= @@ -6216,11 +6901,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_STRIP+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$STRIP"; then ac_cv_prog_STRIP="$STRIP" # Let the user override the test. else @@ -6228,11 +6914,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -6243,11 +6933,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $STRIP" >&5 +printf "%s\n" "$STRIP" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -6256,11 +6946,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_STRIP+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_STRIP"; then ac_cv_prog_ac_ct_STRIP="$ac_ct_STRIP" # Let the user override the test. else @@ -6268,11 +6959,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -6283,11 +6978,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_STRIP" >&5 +printf "%s\n" "$ac_ct_STRIP" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi if test "x$ac_ct_STRIP" = x; then @@ -6295,8 +6990,8 @@ 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;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac STRIP=$ac_ct_STRIP @@ -6315,11 +7010,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_RANLIB+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$RANLIB"; then ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test. else @@ -6327,11 +7023,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -6342,11 +7042,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5 +printf "%s\n" "$RANLIB" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -6355,11 +7055,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_RANLIB+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_RANLIB"; then ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test. else @@ -6367,11 +7068,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -6382,11 +7087,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RANLIB" >&5 +printf "%s\n" "$ac_ct_RANLIB" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi if test "x$ac_ct_RANLIB" = x; then @@ -6394,8 +7099,8 @@ 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;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac RANLIB=$ac_ct_RANLIB @@ -6484,11 +7189,12 @@ # 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking command to parse $NM output from $compiler object" >&5 +printf %s "checking command to parse $NM output from $compiler object... " >&6; } +if test ${lt_cv_sys_global_symbol_pipe+y} +then : + printf %s "(cached) " >&6 +else $as_nop # These are sane defaults that work on at least a few old systems. # [They come from Ultrix. What could be older than Ultrix?!! ;)] @@ -6640,14 +7346,14 @@ 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 + printf "%s\n" "$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 + printf "%s\n" "$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 @@ -6716,7 +7422,7 @@ 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && test -s conftest$ac_exeext; then pipe_works=yes fi @@ -6751,11 +7457,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: failed" >&5 +printf "%s\n" "failed" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: ok" >&5 -$as_echo "ok" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: ok" >&5 +printf "%s\n" "ok" >&6; } fi # Response file support. @@ -6801,13 +7507,14 @@ -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for sysroot" >&5 -$as_echo_n "checking for sysroot... " >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for sysroot" >&5 +printf %s "checking for sysroot... " >&6; } # Check whether --with-sysroot was given. -if test "${with_sysroot+set}" = set; then : +if test ${with_sysroot+y} +then : withval=$with_sysroot; -else +else $as_nop with_sysroot=no fi @@ -6825,24 +7532,25 @@ no|'') ;; #( *) - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_sysroot" >&5 -$as_echo "$with_sysroot" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $with_sysroot" >&5 +printf "%s\n" "$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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: ${lt_sysroot:-no}" >&5 +printf "%s\n" "${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 "%s\n" "$as_me:${as_lineno-$LINENO}: checking for a working dd" >&5 +printf %s "checking for a working dd... " >&6; } +if test ${ac_cv_path_lt_DD+y} +then : + printf %s "(cached) " >&6 +else $as_nop printf 0123456789abcdef0123456789abcdef >conftest.i cat conftest.i conftest.i >conftest2.i : ${lt_DD:=$DD} @@ -6853,10 +7561,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_prog in dd; do + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + 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" + 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 \ @@ -6876,15 +7589,16 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_lt_DD" >&5 +printf "%s\n" "$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 "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to truncate binary pipes" >&5 +printf %s "checking how to truncate binary pipes... " >&6; } +if test ${lt_cv_truncate_bin+y} +then : + printf %s "(cached) " >&6 +else $as_nop printf 0123456789abcdef0123456789abcdef >conftest.i cat conftest.i conftest.i >conftest2.i lt_cv_truncate_bin= @@ -6895,8 +7609,8 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_truncate_bin" >&5 +printf "%s\n" "$lt_cv_truncate_bin" >&6; } @@ -6919,7 +7633,8 @@ } # Check whether --enable-libtool-lock was given. -if test "${enable_libtool_lock+set}" = set; then : +if test ${enable_libtool_lock+y} +then : enableval=$enable_libtool_lock; fi @@ -6935,7 +7650,7 @@ 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then case `/usr/bin/file conftest.$ac_objext` in *ELF-32*) @@ -6955,7 +7670,7 @@ 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 + printf "%s\n" "$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 @@ -6993,7 +7708,7 @@ 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then emul=elf case `/usr/bin/file conftest.$ac_objext` in @@ -7034,7 +7749,7 @@ 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then case `/usr/bin/file conftest.o` in *32-bit*) @@ -7097,11 +7812,12 @@ # 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the C compiler needs -belf" >&5 +printf %s "checking whether the C compiler needs -belf... " >&6; } +if test ${lt_cv_cc_needs_belf+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' @@ -7112,19 +7828,20 @@ /* end confdefs.h. */ int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : lt_cv_cc_needs_belf=yes -else +else $as_nop lt_cv_cc_needs_belf=no fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext ac_ext=c ac_cpp='$CPP $CPPFLAGS' @@ -7133,8 +7850,8 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_cc_needs_belf" >&5 +printf "%s\n" "$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 @@ -7147,7 +7864,7 @@ 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then case `/usr/bin/file conftest.o` in *64-bit*) @@ -7184,11 +7901,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_MANIFEST_TOOL+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$MANIFEST_TOOL"; then ac_cv_prog_MANIFEST_TOOL="$MANIFEST_TOOL" # Let the user override the test. else @@ -7196,11 +7914,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -7211,11 +7933,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $MANIFEST_TOOL" >&5 +printf "%s\n" "$MANIFEST_TOOL" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -7224,11 +7946,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_MANIFEST_TOOL+y} +then : + printf %s "(cached) " >&6 +else $as_nop 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 @@ -7236,11 +7959,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -7251,11 +7978,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_MANIFEST_TOOL" >&5 +printf "%s\n" "$ac_ct_MANIFEST_TOOL" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi if test "x$ac_ct_MANIFEST_TOOL" = x; then @@ -7263,8 +7990,8 @@ 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;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac MANIFEST_TOOL=$ac_ct_MANIFEST_TOOL @@ -7274,11 +8001,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $MANIFEST_TOOL is a manifest tool" >&5 +printf %s "checking if $MANIFEST_TOOL is a manifest tool... " >&6; } +if test ${lt_cv_path_mainfest_tool+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_path_mainfest_tool=no echo "$as_me:$LINENO: $MANIFEST_TOOL '-?'" >&5 $MANIFEST_TOOL '-?' 2>conftest.err > conftest.out @@ -7288,8 +8016,8 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_path_mainfest_tool" >&5 +printf "%s\n" "$lt_cv_path_mainfest_tool" >&6; } if test yes != "$lt_cv_path_mainfest_tool"; then MANIFEST_TOOL=: fi @@ -7304,11 +8032,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_DSYMUTIL+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$DSYMUTIL"; then ac_cv_prog_DSYMUTIL="$DSYMUTIL" # Let the user override the test. else @@ -7316,11 +8045,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -7331,11 +8064,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $DSYMUTIL" >&5 +printf "%s\n" "$DSYMUTIL" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -7344,11 +8077,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_DSYMUTIL+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_DSYMUTIL"; then ac_cv_prog_ac_ct_DSYMUTIL="$ac_ct_DSYMUTIL" # Let the user override the test. else @@ -7356,11 +8090,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -7371,11 +8109,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DSYMUTIL" >&5 +printf "%s\n" "$ac_ct_DSYMUTIL" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi if test "x$ac_ct_DSYMUTIL" = x; then @@ -7383,8 +8121,8 @@ 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;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac DSYMUTIL=$ac_ct_DSYMUTIL @@ -7396,11 +8134,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_NMEDIT+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$NMEDIT"; then ac_cv_prog_NMEDIT="$NMEDIT" # Let the user override the test. else @@ -7408,11 +8147,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -7423,11 +8166,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $NMEDIT" >&5 +printf "%s\n" "$NMEDIT" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -7436,11 +8179,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_NMEDIT+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_NMEDIT"; then ac_cv_prog_ac_ct_NMEDIT="$ac_ct_NMEDIT" # Let the user override the test. else @@ -7448,11 +8192,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -7463,11 +8211,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_NMEDIT" >&5 +printf "%s\n" "$ac_ct_NMEDIT" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi if test "x$ac_ct_NMEDIT" = x; then @@ -7475,8 +8223,8 @@ 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;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac NMEDIT=$ac_ct_NMEDIT @@ -7488,11 +8236,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_LIPO+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$LIPO"; then ac_cv_prog_LIPO="$LIPO" # Let the user override the test. else @@ -7500,11 +8249,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -7515,11 +8268,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $LIPO" >&5 +printf "%s\n" "$LIPO" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -7528,11 +8281,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_LIPO+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_LIPO"; then ac_cv_prog_ac_ct_LIPO="$ac_ct_LIPO" # Let the user override the test. else @@ -7540,11 +8294,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -7555,11 +8313,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_LIPO" >&5 +printf "%s\n" "$ac_ct_LIPO" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi if test "x$ac_ct_LIPO" = x; then @@ -7567,8 +8325,8 @@ 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;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac LIPO=$ac_ct_LIPO @@ -7580,11 +8338,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_OTOOL+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$OTOOL"; then ac_cv_prog_OTOOL="$OTOOL" # Let the user override the test. else @@ -7592,11 +8351,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -7607,11 +8370,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $OTOOL" >&5 +printf "%s\n" "$OTOOL" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -7620,11 +8383,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_OTOOL+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_OTOOL"; then ac_cv_prog_ac_ct_OTOOL="$ac_ct_OTOOL" # Let the user override the test. else @@ -7632,11 +8396,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -7647,11 +8415,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OTOOL" >&5 +printf "%s\n" "$ac_ct_OTOOL" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi if test "x$ac_ct_OTOOL" = x; then @@ -7659,8 +8427,8 @@ 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;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac OTOOL=$ac_ct_OTOOL @@ -7672,11 +8440,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_OTOOL64+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$OTOOL64"; then ac_cv_prog_OTOOL64="$OTOOL64" # Let the user override the test. else @@ -7684,11 +8453,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -7699,11 +8472,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $OTOOL64" >&5 +printf "%s\n" "$OTOOL64" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -7712,11 +8485,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_OTOOL64+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_OTOOL64"; then ac_cv_prog_ac_ct_OTOOL64="$ac_ct_OTOOL64" # Let the user override the test. else @@ -7724,11 +8498,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -7739,11 +8517,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OTOOL64" >&5 +printf "%s\n" "$ac_ct_OTOOL64" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi if test "x$ac_ct_OTOOL64" = x; then @@ -7751,8 +8529,8 @@ 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;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac OTOOL64=$ac_ct_OTOOL64 @@ -7787,11 +8565,12 @@ - { $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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for -single_module linker flag" >&5 +printf %s "checking for -single_module linker flag... " >&6; } +if test ${lt_cv_apple_cc_single_mod+y} +then : + printf %s "(cached) " >&6 +else $as_nop 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 @@ -7820,14 +8599,15 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_apple_cc_single_mod" >&5 +printf "%s\n" "$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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for -exported_symbols_list linker flag" >&5 +printf %s "checking for -exported_symbols_list linker flag... " >&6; } +if test ${lt_cv_ld_exported_symbols_list+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_ld_exported_symbols_list=no save_LDFLAGS=$LDFLAGS echo "_main" > conftest.sym @@ -7836,31 +8616,33 @@ /* end confdefs.h. */ int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : lt_cv_ld_exported_symbols_list=yes -else +else $as_nop lt_cv_ld_exported_symbols_list=no fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_exported_symbols_list" >&5 +printf "%s\n" "$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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for -force_load linker flag" >&5 +printf %s "checking for -force_load linker flag... " >&6; } +if test ${lt_cv_ld_force_load+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_ld_force_load=no cat > conftest.c << _LT_EOF int forced_loaded() { return 2;} @@ -7888,8 +8670,8 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_force_load" >&5 +printf "%s\n" "$lt_cv_ld_force_load" >&6; } case $host_os in rhapsody* | darwin1.[012]) _lt_dar_allow_undefined='$wl-undefined ${wl}suppress' ;; @@ -7960,293 +8742,51 @@ esac } -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 +ac_header= ac_cache= +for ac_item in $ac_header_c_list 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 - + if test $ac_cache; then + ac_fn_c_check_header_compile "$LINENO" $ac_header ac_cv_header_$ac_cache "$ac_includes_default" + if eval test \"x\$ac_cv_header_$ac_cache\" = xyes; then + printf "%s\n" "#define $ac_item 1" >> confdefs.h + fi + ac_header= ac_cache= + elif test $ac_header; then + ac_cache=$ac_item + else + ac_header=$ac_item + fi 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 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 +if test $ac_cv_header_stdlib_h = yes && test $ac_cv_header_string_h = yes +then : -# 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 +printf "%s\n" "#define STDC_HEADERS 1" >>confdefs.h 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 +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 +if test "x$ac_cv_header_dlfcn_h" = xyes +then : + printf "%s\n" "#define HAVE_DLFCN_H 1" >>confdefs.h fi -done - # Set options # Check whether --enable-static was given. -if test "${enable_static+set}" = set; then : +if test ${enable_static+y} +then : enableval=$enable_static; p=${PACKAGE-default} case $enableval in yes) enable_static=yes ;; @@ -8264,7 +8804,7 @@ IFS=$lt_save_ifs ;; esac -else +else $as_nop enable_static=no fi @@ -8284,7 +8824,8 @@ # Check whether --enable-shared was given. -if test "${enable_shared+set}" = set; then : +if test ${enable_shared+y} +then : enableval=$enable_shared; p=${PACKAGE-default} case $enableval in yes) enable_shared=yes ;; @@ -8302,7 +8843,7 @@ IFS=$lt_save_ifs ;; esac -else +else $as_nop enable_shared=yes fi @@ -8317,7 +8858,8 @@ # Check whether --with-pic was given. -if test "${with_pic+set}" = set; then : +if test ${with_pic+y} +then : withval=$with_pic; lt_p=${PACKAGE-default} case $withval in yes|no) pic_mode=$withval ;; @@ -8334,7 +8876,7 @@ IFS=$lt_save_ifs ;; esac -else +else $as_nop pic_mode=default fi @@ -8346,7 +8888,8 @@ # Check whether --enable-fast-install was given. -if test "${enable_fast_install+set}" = set; then : +if test ${enable_fast_install+y} +then : enableval=$enable_fast_install; p=${PACKAGE-default} case $enableval in yes) enable_fast_install=yes ;; @@ -8364,7 +8907,7 @@ IFS=$lt_save_ifs ;; esac -else +else $as_nop enable_fast_install=yes fi @@ -8378,11 +8921,12 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking which variant of shared library versioning to provide" >&5 +printf %s "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 : +if test ${with_aix_soname+y} +then : withval=$with_aix_soname; case $withval in aix|svr4|both) ;; @@ -8391,18 +8935,19 @@ ;; esac lt_cv_with_aix_soname=$with_aix_soname -else - if ${lt_cv_with_aix_soname+:} false; then : - $as_echo_n "(cached) " >&6 -else +else $as_nop + if test ${lt_cv_with_aix_soname+y} +then : + printf %s "(cached) " >&6 +else $as_nop 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $with_aix_soname" >&5 +printf "%s\n" "$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', @@ -8484,11 +9029,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for objdir" >&5 +printf %s "checking for objdir... " >&6; } +if test ${lt_cv_objdir+y} +then : + printf %s "(cached) " >&6 +else $as_nop rm -f .libs 2>/dev/null mkdir .libs 2>/dev/null if test -d .libs; then @@ -8499,17 +9045,15 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_objdir" >&5 +printf "%s\n" "$lt_cv_objdir" >&6; } objdir=$lt_cv_objdir -cat >>confdefs.h <<_ACEOF -#define LT_OBJDIR "$lt_cv_objdir/" -_ACEOF +printf "%s\n" "#define LT_OBJDIR \"$lt_cv_objdir/\"" >>confdefs.h @@ -8555,11 +9099,12 @@ 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for ${ac_tool_prefix}file" >&5 +printf %s "checking for ${ac_tool_prefix}file... " >&6; } +if test ${lt_cv_path_MAGIC_CMD+y} +then : + printf %s "(cached) " >&6 +else $as_nop case $MAGIC_CMD in [\\/*] | ?:[\\/]*) lt_cv_path_MAGIC_CMD=$MAGIC_CMD # Let the user override the test with a path. @@ -8608,11 +9153,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $MAGIC_CMD" >&5 +printf "%s\n" "$MAGIC_CMD" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -8621,11 +9166,12 @@ 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for file" >&5 +printf %s "checking for file... " >&6; } +if test ${lt_cv_path_MAGIC_CMD+y} +then : + printf %s "(cached) " >&6 +else $as_nop case $MAGIC_CMD in [\\/*] | ?:[\\/]*) lt_cv_path_MAGIC_CMD=$MAGIC_CMD # Let the user override the test with a path. @@ -8674,11 +9220,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $MAGIC_CMD" >&5 +printf "%s\n" "$MAGIC_CMD" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -8763,11 +9309,12 @@ 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -fno-rtti -fno-exceptions" >&5 +printf %s "checking if $compiler supports -fno-rtti -fno-exceptions... " >&6; } +if test ${lt_cv_prog_compiler_rtti_exceptions+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_prog_compiler_rtti_exceptions=no ac_outfile=conftest.$ac_objext echo "$lt_simple_compile_test_code" > conftest.$ac_ext @@ -8798,8 +9345,8 @@ $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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_rtti_exceptions" >&5 +printf "%s\n" "$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" @@ -9156,26 +9703,28 @@ ;; 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $compiler option to produce PIC" >&5 +printf %s "checking for $compiler option to produce PIC... " >&6; } +if test ${lt_cv_prog_compiler_pic+y} +then : + printf %s "(cached) " >&6 +else $as_nop 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic" >&5 +printf "%s\n" "$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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $compiler PIC flag $lt_prog_compiler_pic works" >&5 +printf %s "checking if $compiler PIC flag $lt_prog_compiler_pic works... " >&6; } +if test ${lt_cv_prog_compiler_pic_works+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_prog_compiler_pic_works=no ac_outfile=conftest.$ac_objext echo "$lt_simple_compile_test_code" > conftest.$ac_ext @@ -9206,8 +9755,8 @@ $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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic_works" >&5 +printf "%s\n" "$lt_cv_prog_compiler_pic_works" >&6; } if test yes = "$lt_cv_prog_compiler_pic_works"; then case $lt_prog_compiler_pic in @@ -9235,11 +9784,12 @@ # 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $compiler static flag $lt_tmp_static_flag works" >&5 +printf %s "checking if $compiler static flag $lt_tmp_static_flag works... " >&6; } +if test ${lt_cv_prog_compiler_static_works+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_prog_compiler_static_works=no save_LDFLAGS=$LDFLAGS LDFLAGS="$LDFLAGS $lt_tmp_static_flag" @@ -9263,8 +9813,8 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_static_works" >&5 +printf "%s\n" "$lt_cv_prog_compiler_static_works" >&6; } if test yes = "$lt_cv_prog_compiler_static_works"; then : @@ -9278,11 +9828,12 @@ - { $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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 +printf %s "checking if $compiler supports -c -o file.$ac_objext... " >&6; } +if test ${lt_cv_prog_compiler_c_o+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_prog_compiler_c_o=no $RM -r conftest 2>/dev/null mkdir conftest @@ -9325,19 +9876,20 @@ $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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o" >&5 +printf "%s\n" "$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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 +printf %s "checking if $compiler supports -c -o file.$ac_objext... " >&6; } +if test ${lt_cv_prog_compiler_c_o+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_prog_compiler_c_o=no $RM -r conftest 2>/dev/null mkdir conftest @@ -9380,8 +9932,8 @@ $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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o" >&5 +printf "%s\n" "$lt_cv_prog_compiler_c_o" >&6; } @@ -9389,19 +9941,19 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if we can lock with hard links" >&5 +printf %s "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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $hard_links" >&5 +printf "%s\n" "$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;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: '$CC' does not support '-c -o', so 'make -j' may be unsafe" >&5 +printf "%s\n" "$as_me: WARNING: '$CC' does not support '-c -o', so 'make -j' may be unsafe" >&2;} need_locks=warn fi else @@ -9413,8 +9965,8 @@ - { $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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the $compiler linker ($LD) supports shared libraries" >&5 +printf %s "checking whether the $compiler linker ($LD) supports shared libraries... " >&6; } runpath_var= allow_undefined_flag= @@ -9969,21 +10521,23 @@ 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 + if test ${lt_cv_aix_libpath_+y} +then : + printf %s "(cached) " >&6 +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : lt_aix_libpath_sed=' /Import File Strings/,/^$/ { @@ -9998,7 +10552,7 @@ 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 \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext if test -z "$lt_cv_aix_libpath_"; then lt_cv_aix_libpath_=/usr/lib:/lib @@ -10022,21 +10576,23 @@ 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 + if test ${lt_cv_aix_libpath_+y} +then : + printf %s "(cached) " >&6 +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : lt_aix_libpath_sed=' /Import File Strings/,/^$/ { @@ -10051,7 +10607,7 @@ 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 \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext if test -z "$lt_cv_aix_libpath_"; then lt_cv_aix_libpath_=/usr/lib:/lib @@ -10302,11 +10858,12 @@ # 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $CC understands -b" >&5 +printf %s "checking if $CC understands -b... " >&6; } +if test ${lt_cv_prog_compiler__b+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_prog_compiler__b=no save_LDFLAGS=$LDFLAGS LDFLAGS="$LDFLAGS -b" @@ -10330,8 +10887,8 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler__b" >&5 +printf "%s\n" "$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' @@ -10371,28 +10928,30 @@ # 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the $host_os linker accepts -exported_symbol" >&5 +printf %s "checking whether the $host_os linker accepts -exported_symbol... " >&6; } +if test ${lt_cv_irix_exported_symbol+y} +then : + printf %s "(cached) " >&6 +else $as_nop 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 : +if ac_fn_c_try_link "$LINENO" +then : lt_cv_irix_exported_symbol=yes -else +else $as_nop lt_cv_irix_exported_symbol=no fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_irix_exported_symbol" >&5 +printf "%s\n" "$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 @@ -10672,8 +11231,8 @@ fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ld_shlibs" >&5 -$as_echo "$ld_shlibs" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ld_shlibs" >&5 +printf "%s\n" "$ld_shlibs" >&6; } test no = "$ld_shlibs" && can_build_shared=no with_gnu_ld=$with_gnu_ld @@ -10709,18 +11268,19 @@ # 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether -lc should be explicitly linked in" >&5 +printf %s "checking whether -lc should be explicitly linked in... " >&6; } +if test ${lt_cv_archive_cmds_need_lc+y} +then : + printf %s "(cached) " >&6 +else $as_nop $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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } 2>conftest.err; then soname=conftest lib=conftest @@ -10738,7 +11298,7 @@ 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } then lt_cv_archive_cmds_need_lc=no @@ -10752,8 +11312,8 @@ $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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_archive_cmds_need_lc" >&5 +printf "%s\n" "$lt_cv_archive_cmds_need_lc" >&6; } archive_cmds_need_lc=$lt_cv_archive_cmds_need_lc ;; esac @@ -10912,8 +11472,8 @@ - { $as_echo "$as_me:${as_lineno-$LINENO}: checking dynamic linker characteristics" >&5 -$as_echo_n "checking dynamic linker characteristics... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking dynamic linker characteristics" >&5 +printf %s "checking dynamic linker characteristics... " >&6; } if test yes = "$GCC"; then case $host_os in @@ -11474,9 +12034,10 @@ 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 + if test ${lt_cv_shlibpath_overrides_runpath+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_shlibpath_overrides_runpath=no save_LDFLAGS=$LDFLAGS save_libdir=$libdir @@ -11486,19 +12047,21 @@ /* end confdefs.h. */ int -main () +main (void) { ; 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 : +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 \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext LDFLAGS=$save_LDFLAGS libdir=$save_libdir @@ -11730,8 +12293,8 @@ dynamic_linker=no ;; esac -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $dynamic_linker" >&5 -$as_echo "$dynamic_linker" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $dynamic_linker" >&5 +printf "%s\n" "$dynamic_linker" >&6; } test no = "$dynamic_linker" && can_build_shared=no variables_saved_for_relink="PATH $shlibpath_var $runpath_var" @@ -11852,8 +12415,8 @@ - { $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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to hardcode library paths into programs" >&5 +printf %s "checking how to hardcode library paths into programs... " >&6; } hardcode_action= if test -n "$hardcode_libdir_flag_spec" || test -n "$runpath_var" || @@ -11877,8 +12440,8 @@ # directories. hardcode_action=unsupported fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $hardcode_action" >&5 -$as_echo "$hardcode_action" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $hardcode_action" >&5 +printf "%s\n" "$hardcode_action" >&6; } if test relink = "$hardcode_action" || test yes = "$inherit_rpath"; then @@ -11922,11 +12485,12 @@ 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5 +printf %s "checking for dlopen in -ldl... " >&6; } +if test ${ac_cv_lib_dl_dlopen+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_check_lib_save_LIBS=$LIBS LIBS="-ldl $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -11935,32 +12499,31 @@ /* 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 () +main (void) { return dlopen (); ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : ac_cv_lib_dl_dlopen=yes -else +else $as_nop ac_cv_lib_dl_dlopen=no fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ 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 : +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5 +printf "%s\n" "$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 +else $as_nop lt_cv_dlopen=dyld lt_cv_dlopen_libs= @@ -11980,14 +12543,16 @@ *) ac_fn_c_check_func "$LINENO" "shl_load" "ac_cv_func_shl_load" -if test "x$ac_cv_func_shl_load" = xyes; then : +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 +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for shl_load in -ldld" >&5 +printf %s "checking for shl_load in -ldld... " >&6; } +if test ${ac_cv_lib_dld_shl_load+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_check_lib_save_LIBS=$LIBS LIBS="-ldld $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -11996,41 +12561,42 @@ /* 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 () +main (void) { return shl_load (); ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : ac_cv_lib_dld_shl_load=yes -else +else $as_nop ac_cv_lib_dld_shl_load=no fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ 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 : +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_shl_load" >&5 +printf "%s\n" "$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 +else $as_nop ac_fn_c_check_func "$LINENO" "dlopen" "ac_cv_func_dlopen" -if test "x$ac_cv_func_dlopen" = xyes; then : +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 +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5 +printf %s "checking for dlopen in -ldl... " >&6; } +if test ${ac_cv_lib_dl_dlopen+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_check_lib_save_LIBS=$LIBS LIBS="-ldl $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -12038,38 +12604,38 @@ /* 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 + builtin and then its argument prototype would still apply. */ char dlopen (); int -main () +main (void) { return dlopen (); ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : ac_cv_lib_dl_dlopen=yes -else +else $as_nop ac_cv_lib_dl_dlopen=no fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ 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 : +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5 +printf "%s\n" "$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 +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for dlopen in -lsvld" >&5 +printf %s "checking for dlopen in -lsvld... " >&6; } +if test ${ac_cv_lib_svld_dlopen+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_check_lib_save_LIBS=$LIBS LIBS="-lsvld $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -12078,37 +12644,37 @@ /* 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 () +main (void) { return dlopen (); ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : ac_cv_lib_svld_dlopen=yes -else +else $as_nop ac_cv_lib_svld_dlopen=no fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ 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 : +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_svld_dlopen" >&5 +printf "%s\n" "$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 +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for dld_link in -ldld" >&5 +printf %s "checking for dld_link in -ldld... " >&6; } +if test ${ac_cv_lib_dld_dld_link+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_check_lib_save_LIBS=$LIBS LIBS="-ldld $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -12117,30 +12683,29 @@ /* 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 () +main (void) { return dld_link (); ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : ac_cv_lib_dld_dld_link=yes -else +else $as_nop ac_cv_lib_dld_dld_link=no fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ 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 : +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_dld_link" >&5 +printf "%s\n" "$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 @@ -12179,11 +12744,12 @@ 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether a program can dlopen itself" >&5 +printf %s "checking whether a program can dlopen itself... " >&6; } +if test ${lt_cv_dlopen_self+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test yes = "$cross_compiling"; then : lt_cv_dlopen_self=cross else @@ -12262,7 +12828,7 @@ 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 + printf "%s\n" "$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=$? @@ -12280,16 +12846,17 @@ fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_dlopen_self" >&5 -$as_echo "$lt_cv_dlopen_self" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_dlopen_self" >&5 +printf "%s\n" "$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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether a statically linked program can dlopen itself" >&5 +printf %s "checking whether a statically linked program can dlopen itself... " >&6; } +if test ${lt_cv_dlopen_self_static+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test yes = "$cross_compiling"; then : lt_cv_dlopen_self_static=cross else @@ -12368,7 +12935,7 @@ 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 + printf "%s\n" "$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=$? @@ -12386,8 +12953,8 @@ fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_dlopen_self_static" >&5 -$as_echo "$lt_cv_dlopen_self_static" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_dlopen_self_static" >&5 +printf "%s\n" "$lt_cv_dlopen_self_static" >&6; } fi CPPFLAGS=$save_CPPFLAGS @@ -12425,13 +12992,13 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether stripping libraries is possible" >&5 +printf %s "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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } else # FIXME - insert some real tests, host_os isn't really good enough case $host_os in @@ -12439,16 +13006,16 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi ;; *) - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } ;; esac fi @@ -12465,13 +13032,13 @@ # 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if libtool supports shared libraries" >&5 +printf %s "checking if libtool supports shared libraries... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $can_build_shared" >&5 +printf "%s\n" "$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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether to build shared libraries" >&5 +printf %s "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 @@ -12495,15 +13062,15 @@ fi ;; esac - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_shared" >&5 -$as_echo "$enable_shared" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $enable_shared" >&5 +printf "%s\n" "$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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether to build static libraries" >&5 +printf %s "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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $enable_static" >&5 +printf "%s\n" "$enable_static" >&6; } @@ -12541,11 +13108,92 @@ -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking what extension is used for runtime loadable modules" >&5 -$as_echo_n "checking what extension is used for runtime loadable modules... " >&6; } -if ${libltdl_cv_shlibext+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC options needed to detect all undeclared functions" >&5 +printf %s "checking for $CC options needed to detect all undeclared functions... " >&6; } +if test ${ac_cv_c_undeclared_builtin_options+y} +then : + printf %s "(cached) " >&6 +else $as_nop + ac_save_CFLAGS=$CFLAGS + ac_cv_c_undeclared_builtin_options='cannot detect' + for ac_arg in '' -fno-builtin; do + CFLAGS="$ac_save_CFLAGS $ac_arg" + # This test program should *not* compile successfully. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main (void) +{ +(void) strchr; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO" +then : + +else $as_nop + # This test program should compile successfully. + # No library function is consistently available on + # freestanding implementations, so test against a dummy + # declaration. Include always-available headers on the + # off chance that they somehow elicit warnings. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#include +#include +extern void ac_decl (int, char *); + +int +main (void) +{ +(void) ac_decl (0, (char *) 0); + (void) ac_decl; + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO" +then : + if test x"$ac_arg" = x +then : + ac_cv_c_undeclared_builtin_options='none needed' +else $as_nop + ac_cv_c_undeclared_builtin_options=$ac_arg +fi + break +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext + done + CFLAGS=$ac_save_CFLAGS + +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_undeclared_builtin_options" >&5 +printf "%s\n" "$ac_cv_c_undeclared_builtin_options" >&6; } + case $ac_cv_c_undeclared_builtin_options in #( + 'cannot detect') : + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "cannot make $CC report undeclared builtins +See \`config.log' for more details" "$LINENO" 5; } ;; #( + 'none needed') : + ac_c_undeclared_builtin_options='' ;; #( + *) : + ac_c_undeclared_builtin_options=$ac_cv_c_undeclared_builtin_options ;; +esac + +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking what extension is used for runtime loadable modules" >&5 +printf %s "checking what extension is used for runtime loadable modules... " >&6; } +if test ${libltdl_cv_shlibext+y} +then : + printf %s "(cached) " >&6 +else $as_nop module=yes eval libltdl_cv_shlibext=$shrext_cmds @@ -12553,56 +13201,50 @@ eval libltdl_cv_shrext=$shrext_cmds fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libltdl_cv_shlibext" >&5 -$as_echo "$libltdl_cv_shlibext" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libltdl_cv_shlibext" >&5 +printf "%s\n" "$libltdl_cv_shlibext" >&6; } if test -n "$libltdl_cv_shlibext"; then -cat >>confdefs.h <<_ACEOF -#define LT_MODULE_EXT "$libltdl_cv_shlibext" -_ACEOF +printf "%s\n" "#define LT_MODULE_EXT \"$libltdl_cv_shlibext\"" >>confdefs.h fi if test "$libltdl_cv_shrext" != "$libltdl_cv_shlibext"; then -cat >>confdefs.h <<_ACEOF -#define LT_SHARED_EXT "$libltdl_cv_shrext" -_ACEOF +printf "%s\n" "#define LT_SHARED_EXT \"$libltdl_cv_shrext\"" >>confdefs.h fi if test -n "$shared_archive_member_spec"; then -cat >>confdefs.h <<_ACEOF -#define LT_SHARED_LIB_MEMBER "($shared_archive_member_spec.o)" -_ACEOF +printf "%s\n" "#define LT_SHARED_LIB_MEMBER \"($shared_archive_member_spec.o)\"" >>confdefs.h fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking what variable specifies run-time module search path" >&5 -$as_echo_n "checking what variable specifies run-time module search path... " >&6; } -if ${lt_cv_module_path_var+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking what variable specifies run-time module search path" >&5 +printf %s "checking what variable specifies run-time module search path... " >&6; } +if test ${lt_cv_module_path_var+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_module_path_var=$shlibpath_var fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_module_path_var" >&5 -$as_echo "$lt_cv_module_path_var" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_module_path_var" >&5 +printf "%s\n" "$lt_cv_module_path_var" >&6; } if test -n "$lt_cv_module_path_var"; then -cat >>confdefs.h <<_ACEOF -#define LT_MODULE_PATH_VAR "$lt_cv_module_path_var" -_ACEOF +printf "%s\n" "#define LT_MODULE_PATH_VAR \"$lt_cv_module_path_var\"" >>confdefs.h fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for the default library search path" >&5 -$as_echo_n "checking for the default library search path... " >&6; } -if ${lt_cv_sys_dlsearch_path+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for the default library search path" >&5 +printf %s "checking for the default library search path... " >&6; } +if test ${lt_cv_sys_dlsearch_path+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_sys_dlsearch_path=$sys_lib_dlsearch_path_spec fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_sys_dlsearch_path" >&5 -$as_echo "$lt_cv_sys_dlsearch_path" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_sys_dlsearch_path" >&5 +printf "%s\n" "$lt_cv_sys_dlsearch_path" >&6; } if test -n "$lt_cv_sys_dlsearch_path"; then sys_dlsearch_path= for dir in $lt_cv_sys_dlsearch_path; do @@ -12613,9 +13255,7 @@ fi done -cat >>confdefs.h <<_ACEOF -#define LT_DLSEARCH_PATH "$sys_dlsearch_path" -_ACEOF +printf "%s\n" "#define LT_DLSEARCH_PATH \"$sys_dlsearch_path\"" >>confdefs.h fi @@ -12632,11 +13272,12 @@ lt_dlload_save_LIBS=$LIBS LIBADD_DLOPEN= -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing dlopen" >&5 -$as_echo_n "checking for library containing dlopen... " >&6; } -if ${ac_cv_search_dlopen+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for library containing dlopen" >&5 +printf %s "checking for library containing dlopen... " >&6; } +if test ${ac_cv_search_dlopen+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_func_search_save_LIBS=$LIBS cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -12644,56 +13285,58 @@ /* 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 () +main (void) { return dlopen (); ; return 0; } _ACEOF -for ac_lib in '' dl; do +for ac_lib in '' dl +do if test -z "$ac_lib"; then ac_res="none required" else ac_res=-l$ac_lib LIBS="-l$ac_lib $ac_func_search_save_LIBS" fi - if ac_fn_c_try_link "$LINENO"; then : + if ac_fn_c_try_link "$LINENO" +then : ac_cv_search_dlopen=$ac_res fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext - if ${ac_cv_search_dlopen+:} false; then : + if test ${ac_cv_search_dlopen+y} +then : break fi done -if ${ac_cv_search_dlopen+:} false; then : +if test ${ac_cv_search_dlopen+y} +then : -else +else $as_nop ac_cv_search_dlopen=no fi rm conftest.$ac_ext LIBS=$ac_func_search_save_LIBS fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_dlopen" >&5 -$as_echo "$ac_cv_search_dlopen" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_dlopen" >&5 +printf "%s\n" "$ac_cv_search_dlopen" >&6; } ac_res=$ac_cv_search_dlopen -if test "$ac_res" != no; then : +if test "$ac_res" != no +then : test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" -$as_echo "#define HAVE_LIBDL 1" >>confdefs.h +printf "%s\n" "#define HAVE_LIBDL 1" >>confdefs.h if test "$ac_cv_search_dlopen" != "none required"; then LIBADD_DLOPEN=-ldl fi libltdl_cv_lib_dl_dlopen=yes LT_DLLOADERS="$LT_DLLOADERS ${lt_dlopen_dir+$lt_dlopen_dir/}dlopen.la" -else +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #if HAVE_DLFCN_H @@ -12701,25 +13344,27 @@ #endif int -main () +main (void) { dlopen(0, 0); ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : -$as_echo "#define HAVE_LIBDL 1" >>confdefs.h +printf "%s\n" "#define HAVE_LIBDL 1" >>confdefs.h libltdl_cv_func_dlopen=yes LT_DLLOADERS="$LT_DLLOADERS ${lt_dlopen_dir+$lt_dlopen_dir/}dlopen.la" -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 +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for dlopen in -lsvld" >&5 +printf %s "checking for dlopen in -lsvld... " >&6; } +if test ${ac_cv_lib_svld_dlopen+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_check_lib_save_LIBS=$LIBS LIBS="-lsvld $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -12728,39 +13373,38 @@ /* 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 () +main (void) { return dlopen (); ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : ac_cv_lib_svld_dlopen=yes -else +else $as_nop ac_cv_lib_svld_dlopen=no fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ 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 : +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_svld_dlopen" >&5 +printf "%s\n" "$ac_cv_lib_svld_dlopen" >&6; } +if test "x$ac_cv_lib_svld_dlopen" = xyes +then : -$as_echo "#define HAVE_LIBDL 1" >>confdefs.h +printf "%s\n" "#define HAVE_LIBDL 1" >>confdefs.h LIBADD_DLOPEN=-lsvld libltdl_cv_func_dlopen=yes LT_DLLOADERS="$LT_DLLOADERS ${lt_dlopen_dir+$lt_dlopen_dir/}dlopen.la" fi fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext fi @@ -12768,16 +13412,12 @@ then lt_save_LIBS=$LIBS LIBS="$LIBS $LIBADD_DLOPEN" - for ac_func in dlerror -do : ac_fn_c_check_func "$LINENO" "dlerror" "ac_cv_func_dlerror" -if test "x$ac_cv_func_dlerror" = xyes; then : - cat >>confdefs.h <<_ACEOF -#define HAVE_DLERROR 1 -_ACEOF +if test "x$ac_cv_func_dlerror" = xyes +then : + printf "%s\n" "#define HAVE_DLERROR 1" >>confdefs.h fi -done LIBS=$lt_save_LIBS fi @@ -12785,17 +13425,19 @@ LIBADD_SHL_LOAD= ac_fn_c_check_func "$LINENO" "shl_load" "ac_cv_func_shl_load" -if test "x$ac_cv_func_shl_load" = xyes; then : +if test "x$ac_cv_func_shl_load" = xyes +then : -$as_echo "#define HAVE_SHL_LOAD 1" >>confdefs.h +printf "%s\n" "#define HAVE_SHL_LOAD 1" >>confdefs.h LT_DLLOADERS="$LT_DLLOADERS ${lt_dlopen_dir+$lt_dlopen_dir/}shl_load.la" -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 +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for shl_load in -ldld" >&5 +printf %s "checking for shl_load in -ldld... " >&6; } +if test ${ac_cv_lib_dld_shl_load+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_check_lib_save_LIBS=$LIBS LIBS="-ldld $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -12804,32 +13446,31 @@ /* 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 () +main (void) { return shl_load (); ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : ac_cv_lib_dld_shl_load=yes -else +else $as_nop ac_cv_lib_dld_shl_load=no fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ 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 : +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_shl_load" >&5 +printf "%s\n" "$ac_cv_lib_dld_shl_load" >&6; } +if test "x$ac_cv_lib_dld_shl_load" = xyes +then : -$as_echo "#define HAVE_SHL_LOAD 1" >>confdefs.h +printf "%s\n" "#define HAVE_SHL_LOAD 1" >>confdefs.h LT_DLLOADERS="$LT_DLLOADERS ${lt_dlopen_dir+$lt_dlopen_dir/}shl_load.la" LIBADD_SHL_LOAD=-ldld @@ -12843,9 +13484,10 @@ darwin[1567].*) # We only want this for pre-Mac OS X 10.4. ac_fn_c_check_func "$LINENO" "_dyld_func_lookup" "ac_cv_func__dyld_func_lookup" -if test "x$ac_cv_func__dyld_func_lookup" = xyes; then : +if test "x$ac_cv_func__dyld_func_lookup" = xyes +then : -$as_echo "#define HAVE_DYLD 1" >>confdefs.h +printf "%s\n" "#define HAVE_DYLD 1" >>confdefs.h LT_DLLOADERS="$LT_DLLOADERS ${lt_dlopen_dir+$lt_dlopen_dir/}dyld.la" fi @@ -12855,27 +13497,26 @@ LT_DLLOADERS="$LT_DLLOADERS ${lt_dlopen_dir+$lt_dlopen_dir/}load_add_on.la" ;; cygwin* | mingw* | pw32*) - ac_fn_c_check_decl "$LINENO" "cygwin_conv_path" "ac_cv_have_decl_cygwin_conv_path" "#include -" -if test "x$ac_cv_have_decl_cygwin_conv_path" = xyes; then : + ac_fn_check_decl "$LINENO" "cygwin_conv_path" "ac_cv_have_decl_cygwin_conv_path" "#include +" "$ac_c_undeclared_builtin_options" "CFLAGS" +if test "x$ac_cv_have_decl_cygwin_conv_path" = xyes +then : ac_have_decl=1 -else +else $as_nop ac_have_decl=0 fi - -cat >>confdefs.h <<_ACEOF -#define HAVE_DECL_CYGWIN_CONV_PATH $ac_have_decl -_ACEOF +printf "%s\n" "#define HAVE_DECL_CYGWIN_CONV_PATH $ac_have_decl" >>confdefs.h LT_DLLOADERS="$LT_DLLOADERS ${lt_dlopen_dir+$lt_dlopen_dir/}loadlibrary.la" ;; esac -{ $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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for dld_link in -ldld" >&5 +printf %s "checking for dld_link in -ldld... " >&6; } +if test ${ac_cv_lib_dld_dld_link+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_check_lib_save_LIBS=$LIBS LIBS="-ldld $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -12884,32 +13525,31 @@ /* 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 () +main (void) { return dld_link (); ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : ac_cv_lib_dld_dld_link=yes -else +else $as_nop ac_cv_lib_dld_dld_link=no fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ 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 : +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_dld_link" >&5 +printf "%s\n" "$ac_cv_lib_dld_dld_link" >&6; } +if test "x$ac_cv_lib_dld_dld_link" = xyes +then : -$as_echo "#define HAVE_DLD 1" >>confdefs.h +printf "%s\n" "#define HAVE_DLD 1" >>confdefs.h LT_DLLOADERS="$LT_DLLOADERS ${lt_dlopen_dir+$lt_dlopen_dir/}dld_link.la" fi @@ -12924,7 +13564,7 @@ LT_DLPREOPEN="$LT_DLPREOPEN-dlpreopen $lt_loader " done -$as_echo "#define HAVE_LIBDLLOADER 1" >>confdefs.h +printf "%s\n" "#define HAVE_LIBDLLOADER 1" >>confdefs.h fi @@ -12940,11 +13580,12 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for _ prefix in compiled symbols" >&5 -$as_echo_n "checking for _ prefix in compiled symbols... " >&6; } -if ${lt_cv_sys_symbol_underscore+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for _ prefix in compiled symbols" >&5 +printf %s "checking for _ prefix in compiled symbols... " >&6; } +if test ${lt_cv_sys_symbol_underscore+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_sys_symbol_underscore=no cat > conftest.$ac_ext <<_LT_EOF void nm_test_func(){} @@ -12953,14 +13594,14 @@ 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then # Now try to grab the symbols. ac_nlist=conftest.nm if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$NM conftest.$ac_objext \| $lt_cv_sys_global_symbol_pipe \> $ac_nlist\""; } >&5 (eval $NM conftest.$ac_objext \| $lt_cv_sys_global_symbol_pipe \> $ac_nlist) 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && test -s "$ac_nlist"; then # See whether the symbols have a leading underscore. if grep '^. _nm_test_func' "$ac_nlist" >/dev/null; then @@ -12982,18 +13623,19 @@ rm -rf conftest* fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_sys_symbol_underscore" >&5 -$as_echo "$lt_cv_sys_symbol_underscore" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_sys_symbol_underscore" >&5 +printf "%s\n" "$lt_cv_sys_symbol_underscore" >&6; } sys_symbol_underscore=$lt_cv_sys_symbol_underscore if test yes = "$lt_cv_sys_symbol_underscore"; then if test yes = "$libltdl_cv_func_dlopen" || test yes = "$libltdl_cv_lib_dl_dlopen"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we have to add an underscore for dlsym" >&5 -$as_echo_n "checking whether we have to add an underscore for dlsym... " >&6; } -if ${libltdl_cv_need_uscore+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether we have to add an underscore for dlsym" >&5 +printf %s "checking whether we have to add an underscore for dlsym... " >&6; } +if test ${libltdl_cv_need_uscore+y} +then : + printf %s "(cached) " >&6 +else $as_nop libltdl_cv_need_uscore=unknown dlsym_uscore_save_LIBS=$LIBS LIBS="$LIBS $LIBADD_DLOPEN" @@ -13074,7 +13716,7 @@ 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 + printf "%s\n" "$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 libltdl_status=$? @@ -13088,22 +13730,23 @@ LIBS=$dlsym_uscore_save_LIBS fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libltdl_cv_need_uscore" >&5 -$as_echo "$libltdl_cv_need_uscore" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libltdl_cv_need_uscore" >&5 +printf "%s\n" "$libltdl_cv_need_uscore" >&6; } fi fi if test yes = "$libltdl_cv_need_uscore"; then -$as_echo "#define NEED_USCORE 1" >>confdefs.h +printf "%s\n" "#define NEED_USCORE 1" >>confdefs.h fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether deplibs are loaded by dlopen" >&5 -$as_echo_n "checking whether deplibs are loaded by dlopen... " >&6; } -if ${lt_cv_sys_dlopen_deplibs+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether deplibs are loaded by dlopen" >&5 +printf %s "checking whether deplibs are loaded by dlopen... " >&6; } +if test ${lt_cv_sys_dlopen_deplibs+y} +then : + printf %s "(cached) " >&6 +else $as_nop # PORTME does your system automatically load deplibs for dlopen? # or its logical equivalent (e.g. shl_load for HP-UX < 11) # For now, we just catch OSes we know something about -- in the @@ -13196,76 +13839,73 @@ esac fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_sys_dlopen_deplibs" >&5 -$as_echo "$lt_cv_sys_dlopen_deplibs" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_sys_dlopen_deplibs" >&5 +printf "%s\n" "$lt_cv_sys_dlopen_deplibs" >&6; } if test yes != "$lt_cv_sys_dlopen_deplibs"; then -$as_echo "#define LTDL_DLOPEN_DEPLIBS 1" >>confdefs.h +printf "%s\n" "#define LTDL_DLOPEN_DEPLIBS 1" >>confdefs.h fi -for ac_header in argz.h -do : - ac_fn_c_check_header_compile "$LINENO" "argz.h" "ac_cv_header_argz_h" "$ac_includes_default +ac_fn_c_check_header_compile "$LINENO" "argz.h" "ac_cv_header_argz_h" "$ac_includes_default " -if test "x$ac_cv_header_argz_h" = xyes; then : - cat >>confdefs.h <<_ACEOF -#define HAVE_ARGZ_H 1 -_ACEOF +if test "x$ac_cv_header_argz_h" = xyes +then : + printf "%s\n" "#define HAVE_ARGZ_H 1" >>confdefs.h fi -done - ac_fn_c_check_type "$LINENO" "error_t" "ac_cv_type_error_t" "#if defined(HAVE_ARGZ_H) # include #endif " -if test "x$ac_cv_type_error_t" = xyes; then : +if test "x$ac_cv_type_error_t" = xyes +then : -cat >>confdefs.h <<_ACEOF -#define HAVE_ERROR_T 1 -_ACEOF +printf "%s\n" "#define HAVE_ERROR_T 1" >>confdefs.h -else +else $as_nop -$as_echo "#define error_t int" >>confdefs.h +printf "%s\n" "#define error_t int" >>confdefs.h -$as_echo "#define __error_t_defined 1" >>confdefs.h +printf "%s\n" "#define __error_t_defined 1" >>confdefs.h fi LT_ARGZ_H= -for ac_func in argz_add argz_append argz_count argz_create_sep argz_insert \ - argz_next argz_stringify + + for ac_func in argz_add argz_append argz_count argz_create_sep argz_insert argz_next argz_stringify do : - as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` + as_ac_var=`printf "%s\n" "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 : +if eval test \"x\$"$as_ac_var"\" = x"yes" +then : cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 +#define `printf "%s\n" "HAVE_$ac_func" | $as_tr_cpp` 1 _ACEOF -else +else $as_nop LT_ARGZ_H=lt__argz.h; _LT_LIBOBJS="$_LT_LIBOBJS lt__argz.$ac_objext" fi -done +done -if test -z "$LT_ARGZ_H"; then : - { $as_echo "$as_me:${as_lineno-$LINENO}: checking if argz actually works" >&5 -$as_echo_n "checking if argz actually works... " >&6; } -if ${lt_cv_sys_argz_works+:} false; then : - $as_echo_n "(cached) " >&6 -else +if test -z "$LT_ARGZ_H" +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if argz actually works" >&5 +printf %s "checking if argz actually works... " >&6; } +if test ${lt_cv_sys_argz_works+y} +then : + printf %s "(cached) " >&6 +else $as_nop case $host_os in #( *cygwin*) lt_cv_sys_argz_works=no @@ -13292,13 +13932,14 @@ *) lt_cv_sys_argz_works=yes ;; esac fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_sys_argz_works" >&5 -$as_echo "$lt_cv_sys_argz_works" >&6; } - if test yes = "$lt_cv_sys_argz_works"; then : +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_sys_argz_works" >&5 +printf "%s\n" "$lt_cv_sys_argz_works" >&6; } + if test yes = "$lt_cv_sys_argz_works" +then : -$as_echo "#define HAVE_WORKING_ARGZ 1" >>confdefs.h +printf "%s\n" "#define HAVE_WORKING_ARGZ 1" >>confdefs.h -else +else $as_nop LT_ARGZ_H=lt__argz.h @@ -13309,11 +13950,12 @@ -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether libtool supports -dlopen/-dlpreopen" >&5 -$as_echo_n "checking whether libtool supports -dlopen/-dlpreopen... " >&6; } -if ${libltdl_cv_preloaded_symbols+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether libtool supports -dlopen/-dlpreopen" >&5 +printf %s "checking whether libtool supports -dlopen/-dlpreopen... " >&6; } +if test ${libltdl_cv_preloaded_symbols+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$lt_cv_sys_global_symbol_pipe"; then libltdl_cv_preloaded_symbols=yes else @@ -13321,11 +13963,11 @@ fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libltdl_cv_preloaded_symbols" >&5 -$as_echo "$libltdl_cv_preloaded_symbols" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libltdl_cv_preloaded_symbols" >&5 +printf "%s\n" "$libltdl_cv_preloaded_symbols" >&6; } if test yes = "$libltdl_cv_preloaded_symbols"; then -$as_echo "#define HAVE_PRELOADED_SYMBOLS 1" >>confdefs.h +printf "%s\n" "#define HAVE_PRELOADED_SYMBOLS 1" >>confdefs.h fi @@ -13344,7 +13986,8 @@ # Check whether --with-included_ltdl was given. -if test "${with_included_ltdl+set}" = set; then : +if test ${with_included_ltdl+y} +then : withval=$with_included_ltdl; fi @@ -13355,16 +13998,19 @@ ac_fn_c_check_header_compile "$LINENO" "ltdl.h" "ac_cv_header_ltdl_h" "$ac_includes_default " -if test "x$ac_cv_header_ltdl_h" = xyes; then : - ac_fn_c_check_decl "$LINENO" "lt_dlinterface_register" "ac_cv_have_decl_lt_dlinterface_register" "$ac_includes_default +if test "x$ac_cv_header_ltdl_h" = xyes +then : + ac_fn_check_decl "$LINENO" "lt_dlinterface_register" "ac_cv_have_decl_lt_dlinterface_register" "$ac_includes_default #include -" -if test "x$ac_cv_have_decl_lt_dlinterface_register" = xyes; then : - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for lt_dladvise_preload in -lltdl" >&5 -$as_echo_n "checking for lt_dladvise_preload in -lltdl... " >&6; } -if ${ac_cv_lib_ltdl_lt_dladvise_preload+:} false; then : - $as_echo_n "(cached) " >&6 -else +" "$ac_c_undeclared_builtin_options" "CFLAGS" +if test "x$ac_cv_have_decl_lt_dlinterface_register" = xyes +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for lt_dladvise_preload in -lltdl" >&5 +printf %s "checking for lt_dladvise_preload in -lltdl... " >&6; } +if test ${ac_cv_lib_ltdl_lt_dladvise_preload+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_check_lib_save_LIBS=$LIBS LIBS="-lltdl $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -13373,51 +14019,49 @@ /* 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 lt_dladvise_preload (); int -main () +main (void) { return lt_dladvise_preload (); ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : ac_cv_lib_ltdl_lt_dladvise_preload=yes -else +else $as_nop ac_cv_lib_ltdl_lt_dladvise_preload=no fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_ltdl_lt_dladvise_preload" >&5 -$as_echo "$ac_cv_lib_ltdl_lt_dladvise_preload" >&6; } -if test "x$ac_cv_lib_ltdl_lt_dladvise_preload" = xyes; then : +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_ltdl_lt_dladvise_preload" >&5 +printf "%s\n" "$ac_cv_lib_ltdl_lt_dladvise_preload" >&6; } +if test "x$ac_cv_lib_ltdl_lt_dladvise_preload" = xyes +then : with_included_ltdl=no -else +else $as_nop with_included_ltdl=yes fi -else +else $as_nop with_included_ltdl=yes fi - -else +else $as_nop with_included_ltdl=yes fi - fi # Check whether --with-ltdl_include was given. -if test "${with_ltdl_include+set}" = set; then : +if test ${with_ltdl_include+y} +then : withval=$with_ltdl_include; fi @@ -13433,7 +14077,8 @@ # Check whether --with-ltdl_lib was given. -if test "${with_ltdl_lib+set}" = set; then : +if test ${with_ltdl_lib+y} +then : withval=$with_ltdl_lib; fi @@ -13471,7 +14116,7 @@ # If the included ltdl is not to be used, then use the # preinstalled libltdl we found. -$as_echo "#define HAVE_LTDL 1" >>confdefs.h +printf "%s\n" "#define HAVE_LTDL 1" >>confdefs.h LIBLTDL=-lltdl LTDLDEPS= @@ -13489,19 +14134,20 @@ INCLTDL=$LTDLINCL # Report our decision... -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking where to find libltdl headers" >&5 -$as_echo_n "checking where to find libltdl headers... " >&6; } -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $LTDLINCL" >&5 -$as_echo "$LTDLINCL" >&6; } -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking where to find libltdl library" >&5 -$as_echo_n "checking where to find libltdl library... " >&6; } -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $LIBLTDL" >&5 -$as_echo "$LIBLTDL" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking where to find libltdl headers" >&5 +printf %s "checking where to find libltdl headers... " >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $LTDLINCL" >&5 +printf "%s\n" "$LTDLINCL" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking where to find libltdl library" >&5 +printf %s "checking where to find libltdl library... " >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $LIBLTDL" >&5 +printf "%s\n" "$LIBLTDL" >&6; } # Check whether --enable-ltdl-install was given. -if test "${enable_ltdl_install+set}" = set; then : +if test ${enable_ltdl_install+y} +then : enableval=$enable_ltdl_install; fi @@ -13542,68 +14188,97 @@ -for ac_header in unistd.h dl.h sys/dl.h dld.h mach-o/dyld.h dirent.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 +ac_fn_c_check_header_compile "$LINENO" "unistd.h" "ac_cv_header_unistd_h" "$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 +if test "x$ac_cv_header_unistd_h" = xyes +then : + printf "%s\n" "#define HAVE_UNISTD_H 1" >>confdefs.h + +fi +ac_fn_c_check_header_compile "$LINENO" "dl.h" "ac_cv_header_dl_h" "$ac_includes_default +" +if test "x$ac_cv_header_dl_h" = xyes +then : + printf "%s\n" "#define HAVE_DL_H 1" >>confdefs.h fi +ac_fn_c_check_header_compile "$LINENO" "sys/dl.h" "ac_cv_header_sys_dl_h" "$ac_includes_default +" +if test "x$ac_cv_header_sys_dl_h" = xyes +then : + printf "%s\n" "#define HAVE_SYS_DL_H 1" >>confdefs.h -done +fi +ac_fn_c_check_header_compile "$LINENO" "dld.h" "ac_cv_header_dld_h" "$ac_includes_default +" +if test "x$ac_cv_header_dld_h" = xyes +then : + printf "%s\n" "#define HAVE_DLD_H 1" >>confdefs.h + +fi +ac_fn_c_check_header_compile "$LINENO" "mach-o/dyld.h" "ac_cv_header_mach_o_dyld_h" "$ac_includes_default +" +if test "x$ac_cv_header_mach_o_dyld_h" = xyes +then : + printf "%s\n" "#define HAVE_MACH_O_DYLD_H 1" >>confdefs.h + +fi +ac_fn_c_check_header_compile "$LINENO" "dirent.h" "ac_cv_header_dirent_h" "$ac_includes_default +" +if test "x$ac_cv_header_dirent_h" = xyes +then : + printf "%s\n" "#define HAVE_DIRENT_H 1" >>confdefs.h + +fi -for ac_func in closedir opendir readdir + + for ac_func in closedir opendir readdir do : - as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` + as_ac_var=`printf "%s\n" "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 : +if eval test \"x\$"$as_ac_var"\" = x"yes" +then : cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 +#define `printf "%s\n" "HAVE_$ac_func" | $as_tr_cpp` 1 _ACEOF -else +else $as_nop _LT_LIBOBJS="$_LT_LIBOBJS lt__dirent.$ac_objext" fi + done -for ac_func in strlcat strlcpy + for ac_func in strlcat strlcpy do : - as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` + as_ac_var=`printf "%s\n" "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 : +if eval test \"x\$"$as_ac_var"\" = x"yes" +then : cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 +#define `printf "%s\n" "HAVE_$ac_func" | $as_tr_cpp` 1 _ACEOF -else +else $as_nop _LT_LIBOBJS="$_LT_LIBOBJS lt__strl.$ac_objext" fi -done +done -cat >>confdefs.h <<_ACEOF -#define LT_LIBEXT "$libext" -_ACEOF +printf "%s\n" "#define LT_LIBEXT \"$libext\"" >>confdefs.h name= eval "lt_libprefix=\"$libname_spec\"" -cat >>confdefs.h <<_ACEOF -#define LT_LIBPREFIX "$lt_libprefix" -_ACEOF +printf "%s\n" "#define LT_LIBPREFIX \"$lt_libprefix\"" >>confdefs.h name=ltdl @@ -13677,10 +14352,10 @@ CPL_MINOR_VERSION=$cpl_minor_version CPL_MICRO_VERSION=$cpl_micro_version - if test -z "1"; then + if test -z "2"; then CPL_INTERFACE_AGE=0 else - CPL_INTERFACE_AGE="1" + CPL_INTERFACE_AGE="2" fi CPL_BINARY_AGE=`expr 256 '*' $CPL_MINOR_VERSION + $CPL_MICRO_VERSION` @@ -13696,54 +14371,42 @@ -cat >>confdefs.h <<_ACEOF -#define CPL_MAJOR_VERSION $CPL_MAJOR_VERSION -_ACEOF +printf "%s\n" "#define CPL_MAJOR_VERSION $CPL_MAJOR_VERSION" >>confdefs.h -cat >>confdefs.h <<_ACEOF -#define CPL_MINOR_VERSION $CPL_MINOR_VERSION -_ACEOF +printf "%s\n" "#define CPL_MINOR_VERSION $CPL_MINOR_VERSION" >>confdefs.h -cat >>confdefs.h <<_ACEOF -#define CPL_MICRO_VERSION $CPL_MICRO_VERSION -_ACEOF +printf "%s\n" "#define CPL_MICRO_VERSION $CPL_MICRO_VERSION" >>confdefs.h -cat >>confdefs.h <<_ACEOF -#define CPL_INTERFACE_AGE $CPL_INTERFACE_AGE -_ACEOF +printf "%s\n" "#define CPL_INTERFACE_AGE $CPL_INTERFACE_AGE" >>confdefs.h -cat >>confdefs.h <<_ACEOF -#define CPL_BINARY_VERSION $CPL_BINARY_VERSION -_ACEOF +printf "%s\n" "#define CPL_BINARY_VERSION $CPL_BINARY_VERSION" >>confdefs.h -cat >>confdefs.h <<_ACEOF -#define CPL_BINARY_AGE $CPL_BINARY_AGE -_ACEOF +printf "%s\n" "#define CPL_BINARY_AGE $CPL_BINARY_AGE" >>confdefs.h - if test -z "27"; then + if test -z "28"; then LT_CURRENT=0 else - LT_CURRENT="27" + LT_CURRENT="28" fi - if test -z "4"; then + if test -z "2"; then LT_REVISION=0 else - LT_REVISION="4" + LT_REVISION="2" fi - if test -z "1"; then + if test -z "2"; then LT_AGE=0 else - LT_AGE="1" + LT_AGE="2" fi @@ -13765,11 +14428,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_CC+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else @@ -13777,11 +14441,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -13792,11 +14460,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +printf "%s\n" "$CC" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -13805,11 +14473,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_CC+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_CC"; then ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. else @@ -13817,11 +14486,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -13832,11 +14505,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 +printf "%s\n" "$ac_ct_CC" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi if test "x$ac_ct_CC" = x; then @@ -13844,8 +14517,8 @@ 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;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac CC=$ac_ct_CC @@ -13858,11 +14531,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_CC+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else @@ -13870,11 +14544,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -13885,11 +14563,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +printf "%s\n" "$CC" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -13898,11 +14576,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_CC+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else @@ -13911,15 +14590,19 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac 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 + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -13935,18 +14618,18 @@ # 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+' '}$@" + 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +printf "%s\n" "$CC" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -13957,11 +14640,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_CC+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else @@ -13969,11 +14653,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -13984,11 +14672,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +printf "%s\n" "$CC" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -14001,11 +14689,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_CC+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_CC"; then ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. else @@ -14013,11 +14702,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -14028,11 +14721,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 +printf "%s\n" "$ac_ct_CC" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -14044,34 +14737,138 @@ 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;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + CC=$ac_ct_CC + fi +fi + +fi +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}clang", so it can be a program name with args. +set dummy ${ac_tool_prefix}clang; ac_word=$2 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_CC+y} +then : + printf %s "(cached) " >&6 +else $as_nop + 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 + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + 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}clang" + printf "%s\n" "$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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +printf "%s\n" "$CC" >&6; } +else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_CC"; then + ac_ct_CC=$CC + # Extract the first word of "clang", so it can be a program name with args. +set dummy clang; ac_word=$2 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_CC+y} +then : + printf %s "(cached) " >&6 +else $as_nop + 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 + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + 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="clang" + printf "%s\n" "$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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 +printf "%s\n" "$ac_ct_CC" >&6; } +else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } +fi + + if test "x$ac_ct_CC" = x; then + CC="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$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 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;} +test -z "$CC" && { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$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 +printf "%s\n" "$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 +for ac_option in --version -v -V -qversion -version; 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 +printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_compiler $ac_option >&5") 2>conftest.err ac_status=$? if test -s conftest.err; then @@ -14081,20 +14878,21 @@ cat conftest.er1 >&5 fi rm -f conftest.er1 conftest.err - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } done -{ $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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports GNU C" >&5 +printf %s "checking whether the compiler supports GNU C... " >&6; } +if test ${ac_cv_c_compiler_gnu+y} +then : + printf %s "(cached) " >&6 +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main () +main (void) { #ifndef __GNUC__ choke me @@ -14104,29 +14902,33 @@ return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : ac_compiler_gnu=yes -else +else $as_nop ac_compiler_gnu=no fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5 +printf "%s\n" "$ac_cv_c_compiler_gnu" >&6; } +ac_compiler_gnu=$ac_cv_c_compiler_gnu + if test $ac_compiler_gnu = yes; then GCC=yes else GCC= fi -ac_test_CFLAGS=${CFLAGS+set} +ac_test_CFLAGS=${CFLAGS+y} 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5 +printf %s "checking whether $CC accepts -g... " >&6; } +if test ${ac_cv_prog_cc_g+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_save_c_werror_flag=$ac_c_werror_flag ac_c_werror_flag=yes ac_cv_prog_cc_g=no @@ -14135,57 +14937,60 @@ /* end confdefs.h. */ int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : ac_cv_prog_cc_g=yes -else +else $as_nop CFLAGS="" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : -else +else $as_nop ac_c_werror_flag=$ac_save_c_werror_flag CFLAGS="-g" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +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 +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5 +printf "%s\n" "$ac_cv_prog_cc_g" >&6; } +if test $ac_test_CFLAGS; then CFLAGS=$ac_save_CFLAGS elif test $ac_cv_prog_cc_g = yes; then if test "$GCC" = yes; then @@ -14200,94 +15005,144 @@ 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_prog_cc_stdc=no +if test x$ac_prog_cc_stdc = xno +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC option to enable C11 features" >&5 +printf %s "checking for $CC option to enable C11 features... " >&6; } +if test ${ac_cv_prog_cc_c11+y} +then : + printf %s "(cached) " >&6 +else $as_nop + ac_cv_prog_cc_c11=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]; +$ac_c_conftest_c11_program +_ACEOF +for ac_arg in '' -std=gnu11 +do + CC="$ac_save_CC $ac_arg" + if ac_fn_c_try_compile "$LINENO" +then : + ac_cv_prog_cc_c11=$ac_arg +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam + test "x$ac_cv_prog_cc_c11" != "xno" && break +done +rm -f conftest.$ac_ext +CC=$ac_save_CC +fi -/* 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]; +if test "x$ac_cv_prog_cc_c11" = xno +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 +printf "%s\n" "unsupported" >&6; } +else $as_nop + if test "x$ac_cv_prog_cc_c11" = x +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 +printf "%s\n" "none needed" >&6; } +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c11" >&5 +printf "%s\n" "$ac_cv_prog_cc_c11" >&6; } + CC="$CC $ac_cv_prog_cc_c11" +fi + ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c11 + ac_prog_cc_stdc=c11 +fi +fi +if test x$ac_prog_cc_stdc = xno +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC option to enable C99 features" >&5 +printf %s "checking for $CC option to enable C99 features... " >&6; } +if test ${ac_cv_prog_cc_c99+y} +then : + printf %s "(cached) " >&6 +else $as_nop + ac_cv_prog_cc_c99=no +ac_save_CC=$CC +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$ac_c_conftest_c99_program +_ACEOF +for ac_arg in '' -std=gnu99 -std=c99 -c99 -qlanglvl=extc1x -qlanglvl=extc99 -AC99 -D_STDC_C99= +do + CC="$ac_save_CC $ac_arg" + if ac_fn_c_try_compile "$LINENO" +then : + ac_cv_prog_cc_c99=$ac_arg +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam + test "x$ac_cv_prog_cc_c99" != "xno" && break +done +rm -f conftest.$ac_ext +CC=$ac_save_CC +fi -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; -} +if test "x$ac_cv_prog_cc_c99" = xno +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 +printf "%s\n" "unsupported" >&6; } +else $as_nop + if test "x$ac_cv_prog_cc_c99" = x +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 +printf "%s\n" "none needed" >&6; } +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c99" >&5 +printf "%s\n" "$ac_cv_prog_cc_c99" >&6; } + CC="$CC $ac_cv_prog_cc_c99" +fi + ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c99 + ac_prog_cc_stdc=c99 +fi +fi +if test x$ac_prog_cc_stdc = xno +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC option to enable C89 features" >&5 +printf %s "checking for $CC option to enable C89 features... " >&6; } +if test ${ac_cv_prog_cc_c89+y} +then : + printf %s "(cached) " >&6 +else $as_nop + ac_cv_prog_cc_c89=no +ac_save_CC=$CC +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$ac_c_conftest_c89_program _ACEOF -for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \ - -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" +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 : + if ac_fn_c_try_compile "$LINENO" +then : ac_cv_prog_cc_c89=$ac_arg fi -rm -f core conftest.err conftest.$ac_objext +rm -f core conftest.err conftest.$ac_objext conftest.beam 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 : +if test "x$ac_cv_prog_cc_c89" = xno +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 +printf "%s\n" "unsupported" >&6; } +else $as_nop + if test "x$ac_cv_prog_cc_c89" = x +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 +printf "%s\n" "none needed" >&6; } +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5 +printf "%s\n" "$ac_cv_prog_cc_c89" >&6; } + CC="$CC $ac_cv_prog_cc_c89" +fi + ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c89 + ac_prog_cc_stdc=c89 +fi fi ac_ext=c @@ -14296,21 +15151,23 @@ 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_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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC understands -c and -o together" >&5 +printf %s "checking whether $CC understands -c and -o together... " >&6; } +if test ${am_cv_prog_cc_c_o+y} +then : + printf %s "(cached) " >&6 +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main () +main (void) { ; @@ -14338,8 +15195,8 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $am_cv_prog_cc_c_o" >&5 +printf "%s\n" "$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. @@ -14357,11 +15214,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking dependency style of $depcc" >&5 +printf %s "checking dependency style of $depcc... " >&6; } +if test ${am_cv_CC_dependencies_compiler_type+y} +then : + printf %s "(cached) " >&6 +else $as_nop 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 @@ -14468,8 +15326,8 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $am_cv_CC_dependencies_compiler_type" >&5 +printf "%s\n" "$am_cv_CC_dependencies_compiler_type" >&6; } CCDEPMODE=depmode=$am_cv_CC_dependencies_compiler_type if @@ -14484,22 +15342,23 @@ if test "x$CC" != xcc; then - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC and cc understand -c and -o together" >&5 -$as_echo_n "checking whether $CC and cc understand -c and -o together... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC and cc understand -c and -o together" >&5 +printf %s "checking whether $CC and cc understand -c and -o together... " >&6; } else - { $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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether cc understands -c and -o together" >&5 +printf %s "checking whether cc understands -c and -o together... " >&6; } fi -set dummy $CC; ac_cc=`$as_echo "$2" | +set dummy $CC; ac_cc=`printf "%s\n" "$2" | sed 's/[^a-zA-Z0-9_]/_/g;s/^[0-9]/_/'` -if eval \${ac_cv_prog_cc_${ac_cc}_c_o+:} false; then : - $as_echo_n "(cached) " >&6 -else +if eval test \${ac_cv_prog_cc_${ac_cc}_c_o+y} +then : + printf %s "(cached) " >&6 +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main () +main (void) { ; @@ -14516,20 +15375,20 @@ *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 +printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_try") 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && test -f conftest2.$ac_objext && { { 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 +printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_try") 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then eval ac_cv_prog_cc_${ac_cc}_c_o=yes @@ -14541,10 +15400,10 @@ *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 +printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_try") 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; }; then ac_try='cc -c conftest.$ac_ext -o conftest2.$ac_objext >&5' rm -f conftest2.* @@ -14553,20 +15412,20 @@ *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 +printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_try") 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && test -f conftest2.$ac_objext && { { 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 +printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_try") 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then # cc works too. @@ -14580,17 +15439,17 @@ else eval ac_cv_prog_cc_${ac_cc}_c_o=no fi -rm -f core conftest* +rm -rf core conftest* fi if eval test \$ac_cv_prog_cc_${ac_cc}_c_o = yes; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } -$as_echo "#define NO_MINUS_C_MINUS_O 1" >>confdefs.h +printf "%s\n" "#define NO_MINUS_C_MINUS_O 1" >>confdefs.h fi @@ -14599,11 +15458,12 @@ 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -std=c99" >&5 +printf %s "checking whether $CC supports -std=c99... " >&6; } +if eval test \${eso_cv_prog_cc_$flag+y} +then : + printf %s "(cached) " >&6 +else $as_nop eval "eso_cv_prog_cc_$flag=no" ac_ext=c @@ -14634,8 +15494,8 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then : @@ -14652,11 +15512,12 @@ 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -fno-common" >&5 +printf %s "checking whether $CC supports -fno-common... " >&6; } +if eval test \${eso_cv_prog_cc_$flag+y} +then : + printf %s "(cached) " >&6 +else $as_nop eval "eso_cv_prog_cc_$flag=no" ac_ext=c @@ -14687,8 +15548,8 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then : @@ -14703,22 +15564,24 @@ # Check whether --enable-debug was given. -if test "${enable_debug+set}" = set; then : +if test ${enable_debug+y} +then : enableval=$enable_debug; eso_enable_debug=$enableval -else +else $as_nop 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether debugging code should be created" >&5 +printf %s "checking whether debugging code should be created... " >&6; } +if test ${eso_cv_enable_debug+y} +then : + printf %s "(cached) " >&6 +else $as_nop 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $eso_cv_enable_debug" >&5 +printf "%s\n" "$eso_cv_enable_debug" >&6; } if test x"$eso_cv_enable_debug" = xyes; then @@ -14731,11 +15594,12 @@ 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -g3" >&5 +printf %s "checking whether $CC supports -g3... " >&6; } +if eval test \${eso_cv_prog_cc_$flag+y} +then : + printf %s "(cached) " >&6 +else $as_nop eval "eso_cv_prog_cc_$flag=no" ac_ext=c @@ -14766,8 +15630,8 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then : @@ -14792,11 +15656,12 @@ 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -ggdb" >&5 +printf %s "checking whether $CC supports -ggdb... " >&6; } +if eval test \${eso_cv_prog_cc_$flag+y} +then : + printf %s "(cached) " >&6 +else $as_nop eval "eso_cv_prog_cc_$flag=no" ac_ext=c @@ -14827,8 +15692,8 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then : @@ -14842,11 +15707,12 @@ 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -O0" >&5 +printf %s "checking whether $CC supports -O0... " >&6; } +if eval test \${eso_cv_prog_cc_$flag+y} +then : + printf %s "(cached) " >&6 +else $as_nop eval "eso_cv_prog_cc_$flag=no" ac_ext=c @@ -14877,8 +15743,8 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then : @@ -14892,11 +15758,12 @@ 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -rdynamic" >&5 +printf %s "checking whether $CC supports -rdynamic... " >&6; } +if eval test \${eso_cv_prog_cc_$flag+y} +then : + printf %s "(cached) " >&6 +else $as_nop eval "eso_cv_prog_cc_$flag=no" ac_ext=c @@ -14927,8 +15794,8 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then : @@ -14942,11 +15809,12 @@ 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -Wall" >&5 +printf %s "checking whether $CC supports -Wall... " >&6; } +if eval test \${eso_cv_prog_cc_$flag+y} +then : + printf %s "(cached) " >&6 +else $as_nop eval "eso_cv_prog_cc_$flag=no" ac_ext=c @@ -14977,8 +15845,8 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then : @@ -14992,11 +15860,12 @@ 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -W" >&5 +printf %s "checking whether $CC supports -W... " >&6; } +if eval test \${eso_cv_prog_cc_$flag+y} +then : + printf %s "(cached) " >&6 +else $as_nop eval "eso_cv_prog_cc_$flag=no" ac_ext=c @@ -15027,8 +15896,8 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then : @@ -15052,22 +15921,24 @@ # Check whether --enable-strict was given. -if test "${enable_strict+set}" = set; then : +if test ${enable_strict+y} +then : enableval=$enable_strict; eso_enable_strict=$enableval -else +else $as_nop 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether strict compiler options should be used" >&5 +printf %s "checking whether strict compiler options should be used... " >&6; } +if test ${eso_cv_enable_strict+y} +then : + printf %s "(cached) " >&6 +else $as_nop 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $eso_cv_enable_strict" >&5 +printf "%s\n" "$eso_cv_enable_strict" >&6; } if test x"$eso_cv_enable_strict" = xyes; then @@ -15086,11 +15957,12 @@ 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -std=c99" >&5 +printf %s "checking whether $CC supports -std=c99... " >&6; } +if eval test \${eso_cv_prog_cc_$flag+y} +then : + printf %s "(cached) " >&6 +else $as_nop eval "eso_cv_prog_cc_$flag=no" ac_ext=c @@ -15121,8 +15993,8 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then : @@ -15138,11 +16010,12 @@ 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -pedantic" >&5 +printf %s "checking whether $CC supports -pedantic... " >&6; } +if eval test \${eso_cv_prog_cc_$flag+y} +then : + printf %s "(cached) " >&6 +else $as_nop eval "eso_cv_prog_cc_$flag=no" ac_ext=c @@ -15173,8 +16046,8 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then : @@ -15191,22 +16064,24 @@ # Check whether --enable-profile was given. -if test "${enable_profile+set}" = set; then : +if test ${enable_profile+y} +then : enableval=$enable_profile; eso_enable_profile=$enableval -else +else $as_nop eso_enable_profile=no fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether profiling compiler options should be used" >&5 -$as_echo_n "checking whether profiling compiler options should be used... " >&6; } -if ${eso_cv_enable_profile+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether profiling compiler options should be used" >&5 +printf %s "checking whether profiling compiler options should be used... " >&6; } +if test ${eso_cv_enable_profile+y} +then : + printf %s "(cached) " >&6 +else $as_nop eso_cv_enable_profile=$eso_enable_profile fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $eso_cv_enable_profile" >&5 -$as_echo "$eso_cv_enable_profile" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $eso_cv_enable_profile" >&5 +printf "%s\n" "$eso_cv_enable_profile" >&6; } if test x"$eso_cv_enable_profile" = xyes; then @@ -15214,11 +16089,12 @@ flag=`echo pg | sed 'y%.=/+-%___p_%'` - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -pg" >&5 -$as_echo_n "checking whether $CC supports -pg... " >&6; } -if eval \${eso_cv_prog_cc_$flag+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -pg" >&5 +printf %s "checking whether $CC supports -pg... " >&6; } +if eval test \${eso_cv_prog_cc_$flag+y} +then : + printf %s "(cached) " >&6 +else $as_nop eval "eso_cv_prog_cc_$flag=no" ac_ext=c @@ -15249,8 +16125,8 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then : @@ -15264,11 +16140,12 @@ flag=`echo g | sed 'y%.=/+-%___p_%'` - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -g" >&5 -$as_echo_n "checking whether $CC supports -g... " >&6; } -if eval \${eso_cv_prog_cc_$flag+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -g" >&5 +printf %s "checking whether $CC supports -g... " >&6; } +if eval test \${eso_cv_prog_cc_$flag+y} +then : + printf %s "(cached) " >&6 +else $as_nop eval "eso_cv_prog_cc_$flag=no" ac_ext=c @@ -15299,8 +16176,8 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then : @@ -15314,11 +16191,12 @@ flag=`echo static-libgcc | sed 'y%.=/+-%___p_%'` - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -static-libgcc" >&5 -$as_echo_n "checking whether $CC supports -static-libgcc... " >&6; } -if eval \${eso_cv_prog_cc_$flag+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -static-libgcc" >&5 +printf %s "checking whether $CC supports -static-libgcc... " >&6; } +if eval test \${eso_cv_prog_cc_$flag+y} +then : + printf %s "(cached) " >&6 +else $as_nop eval "eso_cv_prog_cc_$flag=no" ac_ext=c @@ -15349,8 +16227,8 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then : @@ -15362,7 +16240,8 @@ # Check whether --enable-shared was given. -if test "${enable_shared+set}" = set; then : +if test ${enable_shared+y} +then : enableval=$enable_shared; p=${PACKAGE-default} case $enableval in yes) enable_shared=yes ;; @@ -15380,7 +16259,7 @@ IFS=$lt_save_ifs ;; esac -else +else $as_nop enable_shared=no fi @@ -15390,7 +16269,8 @@ # Check whether --enable-static was given. -if test "${enable_static+set}" = set; then : +if test ${enable_static+y} +then : enableval=$enable_static; p=${PACKAGE-default} case $enableval in yes) enable_static=yes ;; @@ -15408,7 +16288,7 @@ IFS=$lt_save_ifs ;; esac -else +else $as_nop enable_static=yes fi @@ -15425,11 +16305,12 @@ # 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_path_DOXYGEN+y} +then : + printf %s "(cached) " >&6 +else $as_nop case $DOXYGEN in [\\/]* | ?:[\\/]*) ac_cv_path_DOXYGEN="$DOXYGEN" # Let the user override the test with a path. @@ -15439,11 +16320,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac 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 + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + ac_cv_path_DOXYGEN="$as_dir$ac_word$ac_exec_ext" + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -15455,11 +16340,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $DOXYGEN" >&5 +printf "%s\n" "$DOXYGEN" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -15467,11 +16352,12 @@ # 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_path_LATEX+y} +then : + printf %s "(cached) " >&6 +else $as_nop case $LATEX in [\\/]* | ?:[\\/]*) ac_cv_path_LATEX="$LATEX" # Let the user override the test with a path. @@ -15481,11 +16367,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac 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 + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + ac_cv_path_LATEX="$as_dir$ac_word$ac_exec_ext" + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -15497,11 +16387,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $LATEX" >&5 +printf "%s\n" "$LATEX" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -15529,7 +16419,8 @@ # Check whether --with-java was given. -if test "${with_java+set}" = set; then : +if test ${with_java+y} +then : withval=$with_java; cpl_with_java=$withval @@ -15538,7 +16429,8 @@ # Check whether --with-java-includes was given. -if test "${with_java_includes+set}" = set; then : +if test ${with_java_includes+y} +then : withval=$with_java_includes; cpl_with_java_includes=$withval @@ -15547,7 +16439,8 @@ # Check whether --with-java-includes-md was given. -if test "${with_java_includes_md+set}" = set; then : +if test ${with_java_includes_md+y} +then : withval=$with_java_includes_md; cpl_with_java_includes_md=$withval @@ -15555,15 +16448,16 @@ - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Java Development Kit" >&5 -$as_echo_n "checking for Java Development Kit... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for Java Development Kit" >&5 +printf %s "checking for Java Development Kit... " >&6; } - if ${cpl_cv_path_java+:} false; then : - $as_echo_n "(cached) " >&6 -else + if test ${cpl_cv_path_java+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test x"$cpl_with_java" != xno; then @@ -15579,7 +16473,7 @@ for i in $cpl_java_dirs; do for j in $cpl_java_check_java; do - echo "configure: 15582: $i/$j" >&5 + echo "configure: 16476: $i/$j" >&5 if test -r "$i/$j"; then echo "taking that" >&5 @@ -15616,9 +16510,10 @@ fi - if ${cpl_cv_env_java_os+:} false; then : - $as_echo_n "(cached) " >&6 -else + if test ${cpl_cv_env_java_os+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test x"$cpl_cv_path_java" = xno; then cpl_cv_env_java_os="unknown" @@ -15670,9 +16565,10 @@ fi - if ${cpl_cv_header_java+:} false; then : - $as_echo_n "(cached) " >&6 -else + if test ${cpl_cv_header_java+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test x"$cpl_cv_path_java" = xno; then cpl_java_includes="no" @@ -15689,7 +16585,7 @@ for i in $cpl_java_incdirs; do for j in $cpl_java_check_header; do - echo "configure: 15692: $i/$j" >&5 + echo "configure: 16588: $i/$j" >&5 if test -r "$i/$j"; then echo "taking that" >&5 @@ -15711,9 +16607,10 @@ - if ${cpl_cv_header_java_md+:} false; then : - $as_echo_n "(cached) " >&6 -else + if test ${cpl_cv_header_java_md+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test x"$cpl_cv_path_java" = xno || test x"$cpl_cv_header_java" = xno; then cpl_cv_header_java_md="no" @@ -15734,7 +16631,7 @@ for i in $cpl_java_incdirs; do for j in $cpl_java_check_header_md; do - echo "configure: 15737: $i/$j" >&5 + echo "configure: 16634: $i/$j" >&5 if test -r "$i/$j"; then echo "taking that" >&5 @@ -15752,7 +16649,7 @@ for i in $cpl_java_incdirs; do for j in $cpl_java_check_header_md; do - echo "configure: 15755: $i/$j" >&5 + echo "configure: 16652: $i/$j" >&5 if test -r "$i/$j"; then echo "taking that" >&5 @@ -15772,8 +16669,8 @@ if test x"$cpl_cv_path_java" = xno; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } else if test x"$cpl_cv_header_java" = xno || test x"$cpl_cv_header_java_md" = xno; then if test x"$cpl_cv_header_java" = xno; then @@ -15785,11 +16682,11 @@ else cpl_java_notfound="$cpl_java_check_header_md" fi - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $cpl_cv_path_java, headers $cpl_java_notfound not found" >&5 -$as_echo "$cpl_cv_path_java, headers $cpl_java_notfound not found" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $cpl_cv_path_java, headers $cpl_java_notfound not found" >&5 +printf "%s\n" "$cpl_cv_path_java, headers $cpl_java_notfound not found" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $cpl_cv_path_java, headers $cpl_cv_header_java, $cpl_cv_header_java_md" >&5 -$as_echo "$cpl_cv_path_java, headers $cpl_cv_header_java, $cpl_cv_header_java_md" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $cpl_cv_path_java, headers $cpl_cv_header_java, $cpl_cv_header_java_md" >&5 +printf "%s\n" "$cpl_cv_path_java, headers $cpl_cv_header_java, $cpl_cv_header_java_md" >&6; } fi fi @@ -15826,11 +16723,12 @@ 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -pthread" >&5 +printf %s "checking whether $CC supports -pthread... " >&6; } +if eval test \${eso_cv_prog_cc_$flag+y} +then : + printf %s "(cached) " >&6 +else $as_nop eval "eso_cv_prog_cc_$flag=no" ac_ext=c @@ -15861,8 +16759,8 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then : @@ -15873,11 +16771,12 @@ fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_create in -lpthread" >&5 -$as_echo_n "checking for pthread_create in -lpthread... " >&6; } -if ${ac_cv_lib_pthread_pthread_create+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for pthread_create in -lpthread" >&5 +printf %s "checking for pthread_create in -lpthread... " >&6; } +if test ${ac_cv_lib_pthread_pthread_create+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_check_lib_save_LIBS=$LIBS LIBS="-lpthread $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -15886,45 +16785,44 @@ /* 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 pthread_create (); int -main () +main (void) { return pthread_create (); ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : ac_cv_lib_pthread_pthread_create=yes -else +else $as_nop ac_cv_lib_pthread_pthread_create=no fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_pthread_pthread_create" >&5 -$as_echo "$ac_cv_lib_pthread_pthread_create" >&6; } -if test "x$ac_cv_lib_pthread_pthread_create" = xyes; then : +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_pthread_pthread_create" >&5 +printf "%s\n" "$ac_cv_lib_pthread_pthread_create" >&6; } +if test "x$ac_cv_lib_pthread_pthread_create" = xyes +then : eso_threads_have_libpthread=yes -else +else $as_nop eso_threads_have_libpthread=no fi - ac_fn_c_check_header_mongrel "$LINENO" "pthread.h" "ac_cv_header_pthread_h" "$ac_includes_default" -if test "x$ac_cv_header_pthread_h" = xyes; then : + ac_fn_c_check_header_compile "$LINENO" "pthread.h" "ac_cv_header_pthread_h" "$ac_includes_default" +if test "x$ac_cv_header_pthread_h" = xyes +then : eso_threads_have_pthread_h=yes -else +else $as_nop eso_threads_have_pthread_h=no fi - if test x"$eso_threads_have_pthread_h" != xyes; then eso_threads_posix=no else @@ -15941,7 +16839,7 @@ if test x"$eso_threads_have_pthread_h" = xyes; then -$as_echo "#define HAVE_PTHREAD_H 1" >>confdefs.h +printf "%s\n" "#define HAVE_PTHREAD_H 1" >>confdefs.h fi @@ -15961,27 +16859,31 @@ fi - if ${eso_cv_threads_posix_header+:} false; then : - $as_echo_n "(cached) " >&6 -else + if test ${eso_cv_threads_posix_header+y} +then : + printf %s "(cached) " >&6 +else $as_nop eso_cv_threads_posix_header=$eso_threads_have_pthread_h fi - if ${eso_cv_threads_posix_lib+:} false; then : - $as_echo_n "(cached) " >&6 -else + if test ${eso_cv_threads_posix_lib+y} +then : + printf %s "(cached) " >&6 +else $as_nop eso_cv_threads_posix_lib=$eso_threads_have_libpthread fi - if ${eso_cv_threads_posix_flags+:} false; then : - $as_echo_n "(cached) " >&6 -else + if test ${eso_cv_threads_posix_flags+y} +then : + printf %s "(cached) " >&6 +else $as_nop eso_cv_threads_posix_flags=$eso_cv_prog_cc_pthread fi - if ${eso_cv_threads_posix+:} false; then : - $as_echo_n "(cached) " >&6 -else + if test ${eso_cv_threads_posix+y} +then : + printf %s "(cached) " >&6 +else $as_nop eso_cv_threads_posix=$eso_threads_posix fi @@ -15992,11 +16894,12 @@ OPENMP_CFLAGS= - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for the compiler option to support OpenMP" >&5 -$as_echo_n "checking for the compiler option to support OpenMP... " >&6; } -if ${ac_cv_prog_c_openmp+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for the compiler option to support OpenMP" >&5 +printf %s "checking for the compiler option to support OpenMP... " >&6; } +if test ${ac_cv_prog_c_openmp+y} +then : + printf %s "(cached) " >&6 +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -16011,9 +16914,10 @@ } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : ac_cv_prog_c_openmp='none needed' -else +else $as_nop ac_cv_prog_c_openmp='unsupported' for ac_option in -fopenmp -xopenmp -openmp -mp -omp -qsmp=omp -homp \ -Popenmp --openmp; do @@ -16033,10 +16937,11 @@ } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : ac_cv_prog_c_openmp=$ac_option fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext CFLAGS=$ac_save_CFLAGS if test "$ac_cv_prog_c_openmp" != unsupported; then @@ -16044,11 +16949,11 @@ fi done fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_c_openmp" >&5 -$as_echo "$ac_cv_prog_c_openmp" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_c_openmp" >&5 +printf "%s\n" "$ac_cv_prog_c_openmp" >&6; } case $ac_cv_prog_c_openmp in #( "none needed" | unsupported) ;; #( @@ -16064,35 +16969,34 @@ # Check whether --enable-threads was given. -if test "${enable_threads+set}" = set; then : +if test ${enable_threads+y} +then : enableval=$enable_threads; cpl_enable_threads=$enableval -else +else $as_nop cpl_enable_threads=yes fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether thread support is available" >&5 -$as_echo_n "checking whether thread support is available... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether thread support is available" >&5 +printf %s "checking whether thread support is available... " >&6; } if test x"$cpl_enable_threads" = xyes; then if test x"$eso_cv_threads_posix" = xno && \ test x"$ac_cv_prog_c_openmp" = xno; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } as_fn_error $? "Thread support was requested, but the system does not support it!" "$LINENO" 5 else CFLAGS="-D_REENTRANT $CFLAGS" - cat >>confdefs.h <<_ACEOF -#define CPL_THREADS_ENABLED 1 -_ACEOF + printf "%s\n" "#define CPL_THREADS_ENABLED 1" >>confdefs.h - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } case $ac_cv_prog_c_openmp in "none needed" | unsupported) @@ -16106,11 +17010,12 @@ *) # FIXME: Explicitly add the OpenMP runtime library, since libtool # removes the compiler flag when linking! - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing omp_get_num_threads" >&5 -$as_echo_n "checking for library containing omp_get_num_threads... " >&6; } -if ${ac_cv_search_omp_get_num_threads+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for library containing omp_get_num_threads" >&5 +printf %s "checking for library containing omp_get_num_threads... " >&6; } +if test ${ac_cv_search_omp_get_num_threads+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_func_search_save_LIBS=$LIBS cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -16118,49 +17023,51 @@ /* 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 omp_get_num_threads (); int -main () +main (void) { return omp_get_num_threads (); ; return 0; } _ACEOF -for ac_lib in '' gomp mtsk omp; do +for ac_lib in '' gomp mtsk omp +do if test -z "$ac_lib"; then ac_res="none required" else ac_res=-l$ac_lib LIBS="-l$ac_lib $ac_func_search_save_LIBS" fi - if ac_fn_c_try_link "$LINENO"; then : + if ac_fn_c_try_link "$LINENO" +then : ac_cv_search_omp_get_num_threads=$ac_res fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext - if ${ac_cv_search_omp_get_num_threads+:} false; then : + if test ${ac_cv_search_omp_get_num_threads+y} +then : break fi done -if ${ac_cv_search_omp_get_num_threads+:} false; then : +if test ${ac_cv_search_omp_get_num_threads+y} +then : -else +else $as_nop ac_cv_search_omp_get_num_threads=no fi rm conftest.$ac_ext LIBS=$ac_func_search_save_LIBS fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_omp_get_num_threads" >&5 -$as_echo "$ac_cv_search_omp_get_num_threads" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_omp_get_num_threads" >&5 +printf "%s\n" "$ac_cv_search_omp_get_num_threads" >&6; } ac_res=$ac_cv_search_omp_get_num_threads -if test "$ac_res" != no; then : +if test "$ac_res" != no +then : test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" -else +else $as_nop as_fn_error $? "OpenMP runtime environment not found!" "$LINENO" 5 fi @@ -16176,13 +17083,14 @@ else cpl_threads_enabled=no - { $as_echo "$as_me:${as_lineno-$LINENO}: result: disabled" >&5 -$as_echo "disabled" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: disabled" >&5 +printf "%s\n" "disabled" >&6; } fi - if ${cpl_cv_threads_enabled+:} false; then : - $as_echo_n "(cached) " >&6 -else + if test ${cpl_cv_threads_enabled+y} +then : + printf %s "(cached) " >&6 +else $as_nop cpl_cv_threads_enabled=$cpl_threads_enabled fi @@ -16190,11 +17098,12 @@ # Checks for libraries. -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for socket in -lsocket" >&5 -$as_echo_n "checking for socket in -lsocket... " >&6; } -if ${ac_cv_lib_socket_socket+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for socket in -lsocket" >&5 +printf %s "checking for socket in -lsocket... " >&6; } +if test ${ac_cv_lib_socket_socket+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_check_lib_save_LIBS=$LIBS LIBS="-lsocket $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -16203,38 +17112,38 @@ /* 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 socket (); int -main () +main (void) { return socket (); ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : ac_cv_lib_socket_socket=yes -else +else $as_nop ac_cv_lib_socket_socket=no fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_socket_socket" >&5 -$as_echo "$ac_cv_lib_socket_socket" >&6; } -if test "x$ac_cv_lib_socket_socket" = xyes; then : +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_socket_socket" >&5 +printf "%s\n" "$ac_cv_lib_socket_socket" >&6; } +if test "x$ac_cv_lib_socket_socket" = xyes +then : LIBS="$LIBS -lsocket" fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for inet_ntoa in -lnsl" >&5 -$as_echo_n "checking for inet_ntoa in -lnsl... " >&6; } -if ${ac_cv_lib_nsl_inet_ntoa+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for inet_ntoa in -lnsl" >&5 +printf %s "checking for inet_ntoa in -lnsl... " >&6; } +if test ${ac_cv_lib_nsl_inet_ntoa+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_check_lib_save_LIBS=$LIBS LIBS="-lnsl $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -16243,30 +17152,29 @@ /* 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 inet_ntoa (); int -main () +main (void) { return inet_ntoa (); ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : ac_cv_lib_nsl_inet_ntoa=yes -else +else $as_nop ac_cv_lib_nsl_inet_ntoa=no fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_nsl_inet_ntoa" >&5 -$as_echo "$ac_cv_lib_nsl_inet_ntoa" >&6; } -if test "x$ac_cv_lib_nsl_inet_ntoa" = xyes; then : +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_nsl_inet_ntoa" >&5 +printf "%s\n" "$ac_cv_lib_nsl_inet_ntoa" >&6; } +if test "x$ac_cv_lib_nsl_inet_ntoa" = xyes +then : LIBS="$LIBS -lnsl" fi @@ -16275,11 +17183,12 @@ # Extract the first word of "pkg-config", so it can be a program name with args. set dummy pkg-config; 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_PKGCONFIG+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_PKGCONFIG+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$PKGCONFIG"; then ac_cv_prog_PKGCONFIG="$PKGCONFIG" # Let the user override the test. else @@ -16287,11 +17196,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_PKGCONFIG="pkg-config" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -16302,11 +17215,11 @@ fi PKGCONFIG=$ac_cv_prog_PKGCONFIG if test -n "$PKGCONFIG"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PKGCONFIG" >&5 -$as_echo "$PKGCONFIG" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $PKGCONFIG" >&5 +printf "%s\n" "$PKGCONFIG" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -16318,7 +17231,8 @@ # Check whether --with-system-cext was given. -if test "${with_system_cext+set}" = set; then : +if test ${with_system_cext+y} +then : withval=$with_system_cext; cpl_with_system_cext=$withval @@ -16349,7 +17263,8 @@ # Check whether --with-cext was given. -if test "${with_cext+set}" = set; then : +if test ${with_cext+y} +then : withval=$with_cext; cpl_with_cext=$withval @@ -16358,22 +17273,25 @@ # Check whether --with-cext-includes was given. -if test "${with_cext_includes+set}" = set; then : +if test ${with_cext_includes+y} +then : withval=$with_cext_includes; cpl_with_cext_includes=$withval fi # Check whether --with-cext-libs was given. -if test "${with_cext_libs+set}" = set; then : +if test ${with_cext_libs+y} +then : withval=$with_cext_libs; cpl_with_cext_libs=$withval fi # Check whether --enable-cext-test was given. -if test "${enable_cext_test+set}" = set; then : +if test ${enable_cext_test+y} +then : enableval=$enable_cext_test; cpl_enable_cext_test=$enableval -else +else $as_nop cpl_enable_cext_test=yes fi @@ -16381,8 +17299,8 @@ if test x"$cpl_enable_cext_test" = xyes; then - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for libcext" >&5 -$as_echo_n "checking for libcext... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for libcext" >&5 +printf %s "checking for libcext... " >&6; } # If include directories and libraries are given as arguments, use them # initially. Otherwise assume a standard system installation of the @@ -16461,7 +17379,7 @@ #include <$cpl_cext_check_header> int -main () +main (void) { cxchar c; @@ -16470,16 +17388,17 @@ return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : cpl_have_cext_headers="yes" -else +else $as_nop cpl_have_cext_headers="no" fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext if test x"$cpl_have_cext_headers" = xyes; then @@ -16489,7 +17408,7 @@ #include int -main () +main (void) { cx_program_set_name("MyProgram"); @@ -16498,16 +17417,17 @@ return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : cpl_have_cext_libraries="yes" -else +else $as_nop cpl_have_cext_libraries="no" fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext fi @@ -16537,13 +17457,13 @@ cpl_cext_notfound="(libraries)" fi - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } as_fn_error $? "libcext $cpl_cext_notfound was not found on your system." "$LINENO" 5 else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } CX_INCLUDES="$cpl_cext_cflags" CX_CFLAGS="$cpl_cext_cflags" @@ -16553,8 +17473,8 @@ else - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: libcext checks have been disabled! This package may not build!" >&5 -$as_echo "$as_me: WARNING: libcext checks have been disabled! This package may not build!" >&2;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: libcext checks have been disabled! This package may not build!" >&5 +printf "%s\n" "$as_me: WARNING: libcext checks have been disabled! This package may not build!" >&2;} CX_INCLUDES="" CX_CFLAGS="" @@ -16579,9 +17499,10 @@ if test ! -d "$srcdir/$libcext"; then as_fn_error $? "libcext source tree was not found in \`$srcdir/$libcext'" "$LINENO" 5 else - if ${cpl_cv_with_system_cext+:} false; then : - $as_echo_n "(cached) " >&6 -else + if test ${cpl_cv_with_system_cext+y} +then : + printf %s "(cached) " >&6 +else $as_nop cpl_cv_with_system_cext=$cpl_with_system_cext fi @@ -16605,17 +17526,19 @@ # Check whether --enable-largefile was given. -if test "${enable_largefile+set}" = set; then : +if test ${enable_largefile+y} +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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for special C compiler options needed for large files" >&5 +printf %s "checking for special C compiler options needed for large files... " >&6; } +if test ${ac_cv_sys_largefile_CC+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_cv_sys_largefile_CC=no if test "$GCC" != yes; then ac_save_CC=$CC @@ -16629,44 +17552,47 @@ 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)) +#define LARGE_OFF_T (((off_t) 1 << 31 << 31) - 1 + ((off_t) 1 << 31 << 31)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; int -main () +main (void) { ; return 0; } _ACEOF - if ac_fn_c_try_compile "$LINENO"; then : + if ac_fn_c_try_compile "$LINENO" +then : break fi -rm -f core conftest.err conftest.$ac_objext +rm -f core conftest.err conftest.$ac_objext conftest.beam CC="$CC -n32" - if ac_fn_c_try_compile "$LINENO"; then : + if ac_fn_c_try_compile "$LINENO" +then : ac_cv_sys_largefile_CC=' -n32'; break fi -rm -f core conftest.err conftest.$ac_objext +rm -f core conftest.err conftest.$ac_objext conftest.beam 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sys_largefile_CC" >&5 +printf "%s\n" "$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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for _FILE_OFFSET_BITS value needed for large files" >&5 +printf %s "checking for _FILE_OFFSET_BITS value needed for large files... " >&6; } +if test ${ac_cv_sys_file_offset_bits+y} +then : + printf %s "(cached) " >&6 +else $as_nop while :; do cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -16675,22 +17601,23 @@ 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)) +#define LARGE_OFF_T (((off_t) 1 << 31 << 31) - 1 + ((off_t) 1 << 31 << 31)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +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 +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #define _FILE_OFFSET_BITS 64 @@ -16699,43 +17626,43 @@ 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)) +#define LARGE_OFF_T (((off_t) 1 << 31 << 31) - 1 + ((off_t) 1 << 31 << 31)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +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 +rm -f core conftest.err conftest.$ac_objext conftest.beam 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sys_file_offset_bits" >&5 +printf "%s\n" "$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 +printf "%s\n" "#define _FILE_OFFSET_BITS $ac_cv_sys_file_offset_bits" >>confdefs.h ;; 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for _LARGE_FILES value needed for large files" >&5 +printf %s "checking for _LARGE_FILES value needed for large files... " >&6; } +if test ${ac_cv_sys_large_files+y} +then : + printf %s "(cached) " >&6 +else $as_nop while :; do cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -16744,22 +17671,23 @@ 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)) +#define LARGE_OFF_T (((off_t) 1 << 31 << 31) - 1 + ((off_t) 1 << 31 << 31)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +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 +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #define _LARGE_FILES 1 @@ -16768,40 +17696,37 @@ 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)) +#define LARGE_OFF_T (((off_t) 1 << 31 << 31) - 1 + ((off_t) 1 << 31 << 31)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +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 +rm -f core conftest.err conftest.$ac_objext conftest.beam 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sys_large_files" >&5 +printf "%s\n" "$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 +printf "%s\n" "#define _LARGE_FILES $ac_cv_sys_large_files" >>confdefs.h ;; esac rm -rf conftest* fi - - fi @@ -16819,7 +17744,8 @@ # Check whether --with-cfitsio was given. -if test "${with_cfitsio+set}" = set; then : +if test ${with_cfitsio+y} +then : withval=$with_cfitsio; cpl_with_cfitsio=$withval @@ -16828,22 +17754,25 @@ # Check whether --with-cfitsio-includes was given. -if test "${with_cfitsio_includes+set}" = set; then : +if test ${with_cfitsio_includes+y} +then : withval=$with_cfitsio_includes; cpl_with_cfitsio_includes=$withval fi # Check whether --with-cfitsio-libs was given. -if test "${with_cfitsio_libs+set}" = set; then : +if test ${with_cfitsio_libs+y} +then : withval=$with_cfitsio_libs; cpl_with_cfitsio_libs=$withval fi # Check whether --enable-cfitsio-test was given. -if test "${enable_cfitsio_test+set}" = set; then : +if test ${enable_cfitsio_test+y} +then : enableval=$enable_cfitsio_test; cpl_enable_cfitsio_test=$enableval -else +else $as_nop cpl_enable_cfitsio_test=yes fi @@ -16853,8 +17782,8 @@ if test x"$cpl_enable_cfitsio_test" = xyes; then - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for cfitsio" >&5 -$as_echo_n "checking for cfitsio... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for cfitsio" >&5 +printf %s "checking for cfitsio... " >&6; } cpl_cfitsio_libs="$cpl_cfitsio_check_libraries" @@ -16918,7 +17847,7 @@ #include <$cpl_cfitsio_check_header> int -main () +main (void) { fitsfile *fp; @@ -16927,16 +17856,17 @@ return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : cpl_have_cfitsio_headers="yes" -else +else $as_nop cpl_have_cfitsio_headers="no" fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext if test x"$cpl_have_cfitsio_headers" = xyes; then @@ -16946,7 +17876,7 @@ #include <$cpl_cfitsio_check_header> int -main () +main (void) { float v; @@ -16956,16 +17886,17 @@ return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : cpl_have_cfitsio_libraries="yes" -else +else $as_nop cpl_have_cfitsio_libraries="no" fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext fi @@ -16995,14 +17926,14 @@ cpl_cfitsio_notfound="(libraries)" fi - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } as_fn_error $? "cfitsio $cpl_cfitsio_notfound was not found on your system." "$LINENO" 5 else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } # Setup the symbols @@ -17015,8 +17946,8 @@ # Check library version - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for a cfitsio version >= $cpl_cfitsio_check_version" >&5 -$as_echo_n "checking for a cfitsio version >= $cpl_cfitsio_check_version... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for a cfitsio version >= $cpl_cfitsio_check_version" >&5 +printf %s "checking for a cfitsio version >= $cpl_cfitsio_check_version... " >&6; } cpl_cfitsio_cflags_save="$CFLAGS" cpl_cfitsio_ldflags_save="$LDFLAGS" @@ -17034,21 +17965,24 @@ LIBS="" cpl_cfitsio_version="" - if ac_fn_c_compute_int "$LINENO" "CFITSIO_MAJOR" "cpl_cfitsio_major" "#include "; then : + if ac_fn_c_compute_int "$LINENO" "CFITSIO_MAJOR" "cpl_cfitsio_major" "#include " +then : -else +else $as_nop cpl_cfitsio_version="no" fi - if ac_fn_c_compute_int "$LINENO" "CFITSIO_MINOR" "cpl_cfitsio_minor" "#include "; then : + if ac_fn_c_compute_int "$LINENO" "CFITSIO_MINOR" "cpl_cfitsio_minor" "#include " +then : -else +else $as_nop cpl_cfitsio_version="no" fi - if test x"$cpl_cfitsio_version" = xno; then : + if test x"$cpl_cfitsio_version" = xno +then : cpl_cfitsio_version_found="unknown" -else +else $as_nop cpl_cfitsio_version_found="$cpl_cfitsio_major.$cpl_cfitsio_minor" fi @@ -17084,12 +18018,16 @@ as_fn_error $? "installed cfitsio ($cpl_cfitsio_version_found) is too old" "$LINENO" 5 else -cat >>confdefs.h <<_ACEOF -#define CPL_CFITSIO_VERSION $cpl_cfitsio_version_found -_ACEOF +printf "%s\n" "#define CPL_CFITSIO_VERSION $cpl_cfitsio_version_found" >>confdefs.h + + +printf "%s\n" "#define CPL_CFITSIO_MAJOR $cpl_cfitsio_major" >>confdefs.h - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $cpl_cfitsio_version_found" >&5 -$as_echo "$cpl_cfitsio_version_found" >&6; } + +printf "%s\n" "#define CPL_CFITSIO_MINOR $cpl_cfitsio_minor" >>confdefs.h + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $cpl_cfitsio_version_found" >&5 +printf "%s\n" "$cpl_cfitsio_version_found" >&6; } fi fi @@ -17113,8 +18051,8 @@ LDFLAGS="$CFITSIO_LDFLAGS" LIBS="$LIBCFITSIO" - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether cfitsio provides fits_hdu_getoff()" >&5 -$as_echo_n "checking whether cfitsio provides fits_hdu_getoff()... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether cfitsio provides fits_hdu_getoff()" >&5 +printf %s "checking whether cfitsio provides fits_hdu_getoff()... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -17122,7 +18060,7 @@ #include int -main () +main (void) { fitsfile f; @@ -17133,18 +18071,19 @@ return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : cpl_cfitsio_have_fits_get_hduoff="yes" -else +else $as_nop cpl_cfitsio_have_fits_get_hduoff="no" fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $cpl_cfitsio_have_fits_get_hduoff" >&5 -$as_echo "$cpl_cfitsio_have_fits_get_hduoff" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $cpl_cfitsio_have_fits_get_hduoff" >&5 +printf "%s\n" "$cpl_cfitsio_have_fits_get_hduoff" >&6; } - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether cfitsio provides fits_get_hduaddrll()" >&5 -$as_echo_n "checking whether cfitsio provides fits_get_hduaddrll()... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether cfitsio provides fits_get_hduaddrll()" >&5 +printf %s "checking whether cfitsio provides fits_get_hduaddrll()... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -17152,7 +18091,7 @@ #include int -main () +main (void) { fitsfile f; @@ -17163,15 +18102,16 @@ return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : cpl_cfitsio_have_fits_get_hduaddrll="yes" -else +else $as_nop cpl_cfitsio_have_fits_get_hduaddrll="no" fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $cpl_cfitsio_have_fits_get_hduaddrll" >&5 -$as_echo "$cpl_cfitsio_have_fits_get_hduaddrll" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $cpl_cfitsio_have_fits_get_hduaddrll" >&5 +printf "%s\n" "$cpl_cfitsio_have_fits_get_hduaddrll" >&6; } ac_ext=c ac_cpp='$CPP $CPPFLAGS' @@ -17188,8 +18128,8 @@ # Check whether cfitsio is thread-safe - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether cfitsio was compiled with thread support" >&5 -$as_echo_n "checking whether cfitsio was compiled with thread support... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether cfitsio was compiled with thread support" >&5 +printf %s "checking whether cfitsio was compiled with thread support... " >&6; } ac_ext=c ac_cpp='$CPP $CPPFLAGS' @@ -17212,7 +18152,7 @@ #include int -main () +main (void) { extern pthread_mutex_t Fitsio_InitLock; @@ -17222,16 +18162,17 @@ return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : cpl_cfitsio_is_thread_safe=yes -else +else $as_nop cpl_cfitsio_is_thread_safe=no fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $cpl_cfitsio_is_thread_safe" >&5 -$as_echo "$cpl_cfitsio_is_thread_safe" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $cpl_cfitsio_is_thread_safe" >&5 +printf "%s\n" "$cpl_cfitsio_is_thread_safe" >&6; } ac_ext=c ac_cpp='$CPP $CPPFLAGS' @@ -17252,11 +18193,11 @@ if test x"$cpl_cfitsio_have_fits_get_hduoff"; then -$as_echo "#define HAVE_FITS_GET_HDUOFF 1" >>confdefs.h +printf "%s\n" "#define HAVE_FITS_GET_HDUOFF 1" >>confdefs.h else -$as_echo "#define HAVE_FITS_GET_HDUADDRLL 1" >>confdefs.h +printf "%s\n" "#define HAVE_FITS_GET_HDUADDRLL 1" >>confdefs.h fi @@ -17264,8 +18205,8 @@ else - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cfitsio checks have been disabled! This package may not build!" >&5 -$as_echo "$as_me: WARNING: cfitsio checks have been disabled! This package may not build!" >&2;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: cfitsio checks have been disabled! This package may not build!" >&5 +printf "%s\n" "$as_me: WARNING: cfitsio checks have been disabled! This package may not build!" >&2;} CFITSIO_INCLUDES="" CFITSIO_CFLAGS="" @@ -17275,9 +18216,10 @@ cpl_cfitsio_is_thread_safe="undefined" fi - if ${cpl_cv_cfitsio_is_thread_safe+:} false; then : - $as_echo_n "(cached) " >&6 -else + if test ${cpl_cv_cfitsio_is_thread_safe+y} +then : + printf %s "(cached) " >&6 +else $as_nop cpl_cv_cfitsio_is_thread_safe=$cpl_cfitsio_is_thread_safe fi @@ -17308,7 +18250,8 @@ # Check whether --with-wcslib was given. -if test "${with_wcslib+set}" = set; then : +if test ${with_wcslib+y} +then : withval=$with_wcslib; cpl_with_wcs=$withval @@ -17317,30 +18260,34 @@ # Check whether --with-wcslib-includes was given. -if test "${with_wcslib_includes+set}" = set; then : +if test ${with_wcslib_includes+y} +then : withval=$with_wcslib_includes; cpl_with_wcs_includes=$withval fi # Check whether --with-wcslib-libs was given. -if test "${with_wcslib_libs+set}" = set; then : +if test ${with_wcslib_libs+y} +then : withval=$with_wcslib_libs; cpl_with_wcs_libs=$withval fi # Check whether --enable-wcs was given. -if test "${enable_wcs+set}" = set; then : +if test ${enable_wcs+y} +then : enableval=$enable_wcs; cpl_enable_wcs=$enable_wcs -else +else $as_nop cpl_enable_wcs="yes" fi - if ${cpl_cv_enable_wcs+:} false; then : - $as_echo_n "(cached) " >&6 -else + if test ${cpl_cv_enable_wcs+y} +then : + printf %s "(cached) " >&6 +else $as_nop cpl_cv_enable_wcs=$cpl_enable_wcs fi @@ -17350,8 +18297,8 @@ if test x"$cpl_enable_wcs" = xyes; then - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for wcslib" >&5 -$as_echo_n "checking for wcslib... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for wcslib" >&5 +printf %s "checking for wcslib... " >&6; } # Initially assume a standard system installation of the package @@ -17421,7 +18368,7 @@ #include <$cpl_wcs_check_header> int -main () +main (void) { struct wcsprm wcs; @@ -17430,16 +18377,17 @@ return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : cpl_have_wcs_headers="yes" -else +else $as_nop cpl_have_wcs_headers="no" fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext if test x"$cpl_have_wcs_headers" = xyes; then @@ -17450,7 +18398,7 @@ #include <$cpl_wcs_check_header> int -main () +main (void) { wcsini(0, 1, (void *)0); @@ -17459,16 +18407,17 @@ return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : cpl_have_wcs_libraries="yes" -else +else $as_nop cpl_have_wcs_libraries="no" fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext fi @@ -17498,14 +18447,14 @@ cpl_wcs_notfound="(libraries)" fi - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } as_fn_error $? "wcslib $cpl_wcs_notfound was not found on your system." "$LINENO" 5 else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } # Setup the symbols @@ -17518,8 +18467,8 @@ # Check library version - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for a wcslib version >= $cpl_wcs_check_version" >&5 -$as_echo_n "checking for a wcslib version >= $cpl_wcs_check_version... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for a wcslib version >= $cpl_wcs_check_version" >&5 +printf %s "checking for a wcslib version >= $cpl_wcs_check_version... " >&6; } ac_ext=c ac_cpp='$CPP $CPPFLAGS' @@ -17537,12 +18486,13 @@ LDFLAGS="$WCS_LDFLAGS" LIBS="" - if test "$cross_compiling" = yes; then : - { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} + if test "$cross_compiling" = yes +then : + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot run test program while cross compiling See \`config.log' for more details" "$LINENO" 5; } -else +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -17553,7 +18503,7 @@ #define stringify_arg(v) #v int -main () +main (void) { char vmin[] = "$cpl_wcs_check_version"; @@ -17598,12 +18548,13 @@ return 0; } _ACEOF -if ac_fn_c_try_run "$LINENO"; then : +if ac_fn_c_try_run "$LINENO" +then : cpl_wcs_version="`cat conftest.out`"; rm -f conftest.out -else +else $as_nop cpl_wcs_version="no"; cpl_wcs_version_found="unknown"; @@ -17616,8 +18567,8 @@ fi - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $cpl_wcs_version" >&5 -$as_echo "$cpl_wcs_version" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $cpl_wcs_version" >&5 +printf "%s\n" "$cpl_wcs_version" >&6; } ac_ext=c ac_cpp='$CPP $CPPFLAGS' @@ -17645,17 +18596,15 @@ fi -cat >>confdefs.h <<_ACEOF -#define CPL_WCS_INSTALLED 1 -_ACEOF +printf "%s\n" "#define CPL_WCS_INSTALLED 1" >>confdefs.h fi else - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: WCS support is disabled! WCS support will not be build!" >&5 -$as_echo "$as_me: WARNING: WCS support is disabled! WCS support will not be build!" >&2;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: WCS support is disabled! WCS support will not be build!" >&5 +printf "%s\n" "$as_me: WARNING: WCS support is disabled! WCS support will not be build!" >&2;} WCS_INCLUDES="" WCS_CFLAGS="" @@ -17685,7 +18634,8 @@ # Check whether --with-fftw was given. -if test "${with_fftw+set}" = set; then : +if test ${with_fftw+y} +then : withval=$with_fftw; cpl_with_fftw=$withval @@ -17694,29 +18644,33 @@ # Check whether --with-fftw-includes was given. -if test "${with_fftw_includes+set}" = set; then : +if test ${with_fftw_includes+y} +then : withval=$with_fftw_includes; cpl_with_fftw_includes=$withval fi # Check whether --with-fftw-libs was given. -if test "${with_fftw_libs+set}" = set; then : +if test ${with_fftw_libs+y} +then : withval=$with_fftw_libs; cpl_with_fftw_libs=$withval fi # Check whether --enable-fft was given. -if test "${enable_fft+set}" = set; then : +if test ${enable_fft+y} +then : enableval=$enable_fft; cpl_enable_fft=$enable_fft -else +else $as_nop cpl_enable_fft="yes" fi - if ${cpl_cv_enable_fft+:} false; then : - $as_echo_n "(cached) " >&6 -else + if test ${cpl_cv_enable_fft+y} +then : + printf %s "(cached) " >&6 +else $as_nop cpl_cv_enable_fft=$cpl_enable_fft fi @@ -17726,8 +18680,8 @@ if test x"$cpl_enable_fft" = xyes; then - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for fftw (double precision)" >&5 -$as_echo_n "checking for fftw (double precision)... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for fftw (double precision)" >&5 +printf %s "checking for fftw (double precision)... " >&6; } # Initially assume a standard system installation of the package @@ -17796,7 +18750,7 @@ #include <$cpl_fftw_check_header> int -main () +main (void) { fftw_plan plan; @@ -17805,16 +18759,17 @@ return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : cpl_have_fftw_headers="yes" -else +else $as_nop cpl_have_fftw_headers="no" fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext if test x"$cpl_have_fftw_headers" = xyes; then @@ -17824,7 +18779,7 @@ #include <$cpl_fftw_check_header> int -main () +main (void) { fftw_plan_dft_1d(0, (void *)0, (void *)0, 0, 0); @@ -17833,16 +18788,17 @@ return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : cpl_have_fftw_libraries="yes" -else +else $as_nop cpl_have_fftw_libraries="no" fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext fi @@ -17872,14 +18828,14 @@ cpl_fftw_notfound="(libraries)" fi - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } as_fn_error $? "fftw $cpl_fftw_notfound was not found on your system." "$LINENO" 5 else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } # Setup the symbols @@ -17892,8 +18848,8 @@ # Check library version - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for a fftw version >= $cpl_fftw_check_version" >&5 -$as_echo_n "checking for a fftw version >= $cpl_fftw_check_version... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for a fftw version >= $cpl_fftw_check_version" >&5 +printf %s "checking for a fftw version >= $cpl_fftw_check_version... " >&6; } ac_ext=c ac_cpp='$CPP $CPPFLAGS' @@ -17910,12 +18866,13 @@ LDFLAGS="$FFTW_LDFLAGS" LIBS="$LIBFFTW" - if test "$cross_compiling" = yes; then : - { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} + if test "$cross_compiling" = yes +then : + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot run test program while cross compiling See \`config.log' for more details" "$LINENO" 5; } -else +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -17925,7 +18882,7 @@ #include int -main () +main (void) { char vmin[] = "$cpl_fftw_check_version"; @@ -17982,12 +18939,13 @@ return 0; } _ACEOF -if ac_fn_c_try_run "$LINENO"; then : +if ac_fn_c_try_run "$LINENO" +then : cpl_fftw_version="`cat conftest.out`"; rm -f conftest.out -else +else $as_nop cpl_fftw_version="no"; cpl_fftw_version_found="unknown"; @@ -18000,8 +18958,8 @@ fi - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $cpl_fftw_version" >&5 -$as_echo "$cpl_fftw_version" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $cpl_fftw_version" >&5 +printf "%s\n" "$cpl_fftw_version" >&6; } ac_ext=c ac_cpp='$CPP $CPPFLAGS' @@ -18027,23 +18985,19 @@ fi -cat >>confdefs.h <<_ACEOF -#define CPL_FFTW_VERSION "$cpl_fftw_version" -_ACEOF +printf "%s\n" "#define CPL_FFTW_VERSION \"$cpl_fftw_version\"" >>confdefs.h fi -cat >>confdefs.h <<_ACEOF -#define CPL_FFTW_INSTALLED 1 -_ACEOF +printf "%s\n" "#define CPL_FFTW_INSTALLED 1" >>confdefs.h fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for fftw (single precision)" >&5 -$as_echo_n "checking for fftw (single precision)... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for fftw (single precision)" >&5 +printf %s "checking for fftw (single precision)... " >&6; } # Initially assume a standard system installation of the package @@ -18112,7 +19066,7 @@ #include <$cpl_fftw_check_header> int -main () +main (void) { fftwf_plan plan; @@ -18121,16 +19075,17 @@ return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : cpl_have_fftw_headers="yes" -else +else $as_nop cpl_have_fftw_headers="no" fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext if test x"$cpl_have_fftw_headers" = xyes; then @@ -18140,7 +19095,7 @@ #include <$cpl_fftw_check_header> int -main () +main (void) { fftwf_plan_dft_1d(0, (void *)0, (void *)0, 0, 0); @@ -18149,16 +19104,17 @@ return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : cpl_have_fftw_libraries="yes" -else +else $as_nop cpl_have_fftw_libraries="no" fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext fi @@ -18188,14 +19144,14 @@ cpl_fftw_notfound="(libraries)" fi - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } as_fn_error $? "fftw $cpl_fftw_notfound was not found on your system." "$LINENO" 5 else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } # Setup the symbols @@ -18208,8 +19164,8 @@ # Check library version - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for a fftw version >= $cpl_fftw_check_version" >&5 -$as_echo_n "checking for a fftw version >= $cpl_fftw_check_version... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for a fftw version >= $cpl_fftw_check_version" >&5 +printf %s "checking for a fftw version >= $cpl_fftw_check_version... " >&6; } ac_ext=c ac_cpp='$CPP $CPPFLAGS' @@ -18226,12 +19182,13 @@ LDFLAGS="$FFTWF_LDFLAGS" LIBS="$LIBFFTWF" - if test "$cross_compiling" = yes; then : - { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} + if test "$cross_compiling" = yes +then : + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot run test program while cross compiling See \`config.log' for more details" "$LINENO" 5; } -else +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -18241,7 +19198,7 @@ #include int -main () +main (void) { char vmin[] = "$cpl_fftw_check_version"; @@ -18298,12 +19255,13 @@ return 0; } _ACEOF -if ac_fn_c_try_run "$LINENO"; then : +if ac_fn_c_try_run "$LINENO" +then : cpl_fftwf_version="`cat conftest.out`"; rm -f conftest.out -else +else $as_nop cpl_fftwf_version="no"; cpl_fftwf_version_found="unknown"; @@ -18316,8 +19274,8 @@ fi - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $cpl_fftwf_version" >&5 -$as_echo "$cpl_fftwf_version" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $cpl_fftwf_version" >&5 +printf "%s\n" "$cpl_fftwf_version" >&6; } ac_ext=c ac_cpp='$CPP $CPPFLAGS' @@ -18343,25 +19301,21 @@ fi -cat >>confdefs.h <<_ACEOF -#define CPL_FFTWF_VERSION "$cpl_fftwf_version" -_ACEOF +printf "%s\n" "#define CPL_FFTWF_VERSION \"$cpl_fftwf_version\"" >>confdefs.h fi -cat >>confdefs.h <<_ACEOF -#define CPL_FFTWF_INSTALLED 1 -_ACEOF +printf "%s\n" "#define CPL_FFTWF_INSTALLED 1" >>confdefs.h fi else - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: FFT support is disabled! FFT support will not be build!" >&5 -$as_echo "$as_me: WARNING: FFT support is disabled! FFT support will not be build!" >&2;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: FFT support is disabled! FFT support will not be build!" >&5 +printf "%s\n" "$as_me: WARNING: FFT support is disabled! FFT support will not be build!" >&2;} FFTW_INCLUDES="" FFTW_CFLAGS="" @@ -18387,123 +19341,145 @@ # 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 +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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5 +printf %s "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 test ${ac_cv_prog_CPP+y} +then : + printf %s "(cached) " >&6 +else $as_nop + # Double quotes because $CC needs to be expanded + for CPP in "$CC -E" "$CC -E -traditional-cpp" 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. + # 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. */ -#include -#include -#include -#include - -int -main () -{ - - ; - return 0; -} +#include + Syntax error _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_header_stdc=yes -else - ac_cv_header_stdc=no +if ac_fn_c_try_cpp "$LINENO" +then : + +else $as_nop + # Broken: fails on valid input. +continue fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f conftest.err conftest.i conftest.$ac_ext -if test $ac_cv_header_stdc = yes; then - # SunOS 4.x string.h does not declare mem*, contrary to ANSI. + # 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 - +#include _ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - $EGREP "memchr" >/dev/null 2>&1; then : - -else - ac_cv_header_stdc=no +if ac_fn_c_try_cpp "$LINENO" +then : + # Broken: success on invalid input. +continue +else $as_nop + # Passes both tests. +ac_preproc_ok=: +break fi -rm -f conftest* +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 -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 : + done + ac_cv_prog_CPP=$CPP +fi + CPP=$ac_cv_prog_CPP else - ac_cv_header_stdc=no + ac_cv_prog_CPP=$CPP fi -rm -f conftest* +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5 +printf "%s\n" "$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. + # 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. */ +#include + Syntax error +_ACEOF +if ac_fn_c_try_cpp "$LINENO" +then : +else $as_nop + # Broken: fails on valid input. +continue fi +rm -f conftest.err conftest.i conftest.$ac_ext -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 + # 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 -#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; -} +#include _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 +if ac_fn_c_try_cpp "$LINENO" +then : + # Broken: success on invalid input. +continue +else $as_nop + # 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_nop + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$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 -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 +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}: checking whether termios.h defines TIOCGWINSZ" >&5 -$as_echo_n "checking whether termios.h defines TIOCGWINSZ... " >&6; } -if ${ac_cv_sys_tiocgwinsz_in_termios_h+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether termios.h defines TIOCGWINSZ" >&5 +printf %s "checking whether termios.h defines TIOCGWINSZ... " >&6; } +if test ${ac_cv_sys_tiocgwinsz_in_termios_h+y} +then : + printf %s "(cached) " >&6 +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include @@ -18514,23 +19490,25 @@ _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - $EGREP "yes" >/dev/null 2>&1; then : + $EGREP "yes" >/dev/null 2>&1 +then : ac_cv_sys_tiocgwinsz_in_termios_h=yes -else +else $as_nop ac_cv_sys_tiocgwinsz_in_termios_h=no fi -rm -f conftest* +rm -rf conftest* fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sys_tiocgwinsz_in_termios_h" >&5 -$as_echo "$ac_cv_sys_tiocgwinsz_in_termios_h" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sys_tiocgwinsz_in_termios_h" >&5 +printf "%s\n" "$ac_cv_sys_tiocgwinsz_in_termios_h" >&6; } if test $ac_cv_sys_tiocgwinsz_in_termios_h != yes; then - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether sys/ioctl.h defines TIOCGWINSZ" >&5 -$as_echo_n "checking whether sys/ioctl.h defines TIOCGWINSZ... " >&6; } -if ${ac_cv_sys_tiocgwinsz_in_sys_ioctl_h+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether sys/ioctl.h defines TIOCGWINSZ" >&5 +printf %s "checking whether sys/ioctl.h defines TIOCGWINSZ... " >&6; } +if test ${ac_cv_sys_tiocgwinsz_in_sys_ioctl_h+y} +then : + printf %s "(cached) " >&6 +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include @@ -18541,52 +19519,130 @@ _ACEOF if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - $EGREP "yes" >/dev/null 2>&1; then : + $EGREP "yes" >/dev/null 2>&1 +then : ac_cv_sys_tiocgwinsz_in_sys_ioctl_h=yes -else +else $as_nop ac_cv_sys_tiocgwinsz_in_sys_ioctl_h=no fi -rm -f conftest* +rm -rf conftest* fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sys_tiocgwinsz_in_sys_ioctl_h" >&5 -$as_echo "$ac_cv_sys_tiocgwinsz_in_sys_ioctl_h" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sys_tiocgwinsz_in_sys_ioctl_h" >&5 +printf "%s\n" "$ac_cv_sys_tiocgwinsz_in_sys_ioctl_h" >&6; } if test $ac_cv_sys_tiocgwinsz_in_sys_ioctl_h = yes; then -$as_echo "#define GWINSZ_IN_SYS_IOCTL 1" >>confdefs.h +printf "%s\n" "#define GWINSZ_IN_SYS_IOCTL 1" >>confdefs.h fi fi -for ac_header in fcntl.h stdlib.h string.h stropts.h sys/ioctl.h \ - sys/stat.h sys/times.h sys/time.h sys/types.h \ - termios.h termio.h unistd.h time.h locale.h xlocale.h -do : - as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -ac_fn_c_check_header_mongrel "$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 +ac_fn_c_check_header_compile "$LINENO" "fcntl.h" "ac_cv_header_fcntl_h" "$ac_includes_default" +if test "x$ac_cv_header_fcntl_h" = xyes +then : + printf "%s\n" "#define HAVE_FCNTL_H 1" >>confdefs.h fi +ac_fn_c_check_header_compile "$LINENO" "stdlib.h" "ac_cv_header_stdlib_h" "$ac_includes_default" +if test "x$ac_cv_header_stdlib_h" = xyes +then : + printf "%s\n" "#define HAVE_STDLIB_H 1" >>confdefs.h -done +fi +ac_fn_c_check_header_compile "$LINENO" "string.h" "ac_cv_header_string_h" "$ac_includes_default" +if test "x$ac_cv_header_string_h" = xyes +then : + printf "%s\n" "#define HAVE_STRING_H 1" >>confdefs.h + +fi +ac_fn_c_check_header_compile "$LINENO" "stropts.h" "ac_cv_header_stropts_h" "$ac_includes_default" +if test "x$ac_cv_header_stropts_h" = xyes +then : + printf "%s\n" "#define HAVE_STROPTS_H 1" >>confdefs.h + +fi +ac_fn_c_check_header_compile "$LINENO" "sys/ioctl.h" "ac_cv_header_sys_ioctl_h" "$ac_includes_default" +if test "x$ac_cv_header_sys_ioctl_h" = xyes +then : + printf "%s\n" "#define HAVE_SYS_IOCTL_H 1" >>confdefs.h + +fi +ac_fn_c_check_header_compile "$LINENO" "sys/stat.h" "ac_cv_header_sys_stat_h" "$ac_includes_default" +if test "x$ac_cv_header_sys_stat_h" = xyes +then : + printf "%s\n" "#define HAVE_SYS_STAT_H 1" >>confdefs.h + +fi +ac_fn_c_check_header_compile "$LINENO" "sys/times.h" "ac_cv_header_sys_times_h" "$ac_includes_default" +if test "x$ac_cv_header_sys_times_h" = xyes +then : + printf "%s\n" "#define HAVE_SYS_TIMES_H 1" >>confdefs.h + +fi +ac_fn_c_check_header_compile "$LINENO" "sys/time.h" "ac_cv_header_sys_time_h" "$ac_includes_default" +if test "x$ac_cv_header_sys_time_h" = xyes +then : + printf "%s\n" "#define HAVE_SYS_TIME_H 1" >>confdefs.h + +fi +ac_fn_c_check_header_compile "$LINENO" "sys/types.h" "ac_cv_header_sys_types_h" "$ac_includes_default" +if test "x$ac_cv_header_sys_types_h" = xyes +then : + printf "%s\n" "#define HAVE_SYS_TYPES_H 1" >>confdefs.h + +fi +ac_fn_c_check_header_compile "$LINENO" "termios.h" "ac_cv_header_termios_h" "$ac_includes_default" +if test "x$ac_cv_header_termios_h" = xyes +then : + printf "%s\n" "#define HAVE_TERMIOS_H 1" >>confdefs.h + +fi +ac_fn_c_check_header_compile "$LINENO" "termio.h" "ac_cv_header_termio_h" "$ac_includes_default" +if test "x$ac_cv_header_termio_h" = xyes +then : + printf "%s\n" "#define HAVE_TERMIO_H 1" >>confdefs.h + +fi +ac_fn_c_check_header_compile "$LINENO" "unistd.h" "ac_cv_header_unistd_h" "$ac_includes_default" +if test "x$ac_cv_header_unistd_h" = xyes +then : + printf "%s\n" "#define HAVE_UNISTD_H 1" >>confdefs.h + +fi +ac_fn_c_check_header_compile "$LINENO" "time.h" "ac_cv_header_time_h" "$ac_includes_default" +if test "x$ac_cv_header_time_h" = xyes +then : + printf "%s\n" "#define HAVE_TIME_H 1" >>confdefs.h + +fi +ac_fn_c_check_header_compile "$LINENO" "locale.h" "ac_cv_header_locale_h" "$ac_includes_default" +if test "x$ac_cv_header_locale_h" = xyes +then : + printf "%s\n" "#define HAVE_LOCALE_H 1" >>confdefs.h + +fi +ac_fn_c_check_header_compile "$LINENO" "xlocale.h" "ac_cv_header_xlocale_h" "$ac_includes_default" +if test "x$ac_cv_header_xlocale_h" = xyes +then : + printf "%s\n" "#define HAVE_XLOCALE_H 1" >>confdefs.h + +fi # 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for an ANSI C-conforming const" >&5 +printf %s "checking for an ANSI C-conforming const... " >&6; } +if test ${ac_cv_c_const+y} +then : + printf %s "(cached) " >&6 +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main () +main (void) { #ifndef __cplusplus @@ -18599,7 +19655,7 @@ /* 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. + /* IBM 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 */ @@ -18627,7 +19683,7 @@ iptr p = 0; ++p; } - { /* AIX XL C 1.02.0.0 rejects this sort of thing, saying + { /* IBM 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; @@ -18643,47 +19699,50 @@ return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : ac_cv_c_const=yes -else +else $as_nop ac_cv_c_const=no fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_const" >&5 -$as_echo "$ac_cv_c_const" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_const" >&5 +printf "%s\n" "$ac_cv_c_const" >&6; } if test $ac_cv_c_const = no; then -$as_echo "#define const /**/" >>confdefs.h +printf "%s\n" "#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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for inline" >&5 +printf %s "checking for inline... " >&6; } +if test ${ac_cv_c_inline+y} +then : + printf %s "(cached) " >&6 +else $as_nop 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; } +static $ac_kw foo_t static_foo (void) {return 0; } +$ac_kw foo_t foo (void) {return 0; } #endif _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +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 +rm -f core conftest.err conftest.$ac_objext conftest.beam 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_inline" >&5 +printf "%s\n" "$ac_cv_c_inline" >&6; } case $ac_cv_c_inline in inline | yes) ;; @@ -18700,11 +19759,12 @@ ;; esac - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether byte ordering is bigendian" >&5 -$as_echo_n "checking whether byte ordering is bigendian... " >&6; } -if ${ac_cv_c_bigendian+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether byte ordering is bigendian" >&5 +printf %s "checking whether byte ordering is bigendian... " >&6; } +if test ${ac_cv_c_bigendian+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_cv_c_bigendian=unknown # See if we're dealing with a universal compiler. cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -18715,7 +19775,8 @@ typedef int dummy; _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : # Check for potential -arch flags. It is not universal unless # there are at least two -arch flags with different values. @@ -18739,7 +19800,7 @@ fi done fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext if test $ac_cv_c_bigendian = unknown; then # See if sys/param.h defines the BYTE_ORDER macro. cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -18748,7 +19809,7 @@ #include int -main () +main (void) { #if ! (defined BYTE_ORDER && defined BIG_ENDIAN \ && defined LITTLE_ENDIAN && BYTE_ORDER && BIG_ENDIAN \ @@ -18760,7 +19821,8 @@ return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : # It does; now see whether it defined to BIG_ENDIAN or not. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -18768,7 +19830,7 @@ #include int -main () +main (void) { #if BYTE_ORDER != BIG_ENDIAN not big endian @@ -18778,14 +19840,15 @@ return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : ac_cv_c_bigendian=yes -else +else $as_nop ac_cv_c_bigendian=no fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi if test $ac_cv_c_bigendian = unknown; then # See if defines _LITTLE_ENDIAN or _BIG_ENDIAN (e.g., Solaris). @@ -18794,7 +19857,7 @@ #include int -main () +main (void) { #if ! (defined _LITTLE_ENDIAN || defined _BIG_ENDIAN) bogus endian macros @@ -18804,14 +19867,15 @@ return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : # It does; now see whether it defined to _BIG_ENDIAN or not. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int -main () +main (void) { #ifndef _BIG_ENDIAN not big endian @@ -18821,31 +19885,33 @@ return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : ac_cv_c_bigendian=yes -else +else $as_nop ac_cv_c_bigendian=no fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi if test $ac_cv_c_bigendian = unknown; then # Compile a test program. - if test "$cross_compiling" = yes; then : + if test "$cross_compiling" = yes +then : # Try to guess by grepping values from an object file. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -short int ascii_mm[] = +unsigned short int ascii_mm[] = { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 }; - short int ascii_ii[] = + unsigned short int ascii_ii[] = { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 }; int use_ascii (int i) { return ascii_mm[i] + ascii_ii[i]; } - short int ebcdic_ii[] = + unsigned short int ebcdic_ii[] = { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 }; - short int ebcdic_mm[] = + unsigned short int ebcdic_mm[] = { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 }; int use_ebcdic (int i) { return ebcdic_mm[i] + ebcdic_ii[i]; @@ -18853,14 +19919,15 @@ extern int foo; int -main () +main (void) { return use_ascii (foo) == use_ebcdic (foo); ; return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : if grep BIGenDianSyS conftest.$ac_objext >/dev/null; then ac_cv_c_bigendian=yes fi @@ -18873,13 +19940,13 @@ fi fi fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -else +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $ac_includes_default int -main () +main (void) { /* Are we little or big endian? From Harbison&Steele. */ @@ -18895,9 +19962,10 @@ return 0; } _ACEOF -if ac_fn_c_try_run "$LINENO"; then : +if ac_fn_c_try_run "$LINENO" +then : ac_cv_c_bigendian=no -else +else $as_nop ac_cv_c_bigendian=yes fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ @@ -18906,17 +19974,17 @@ fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_bigendian" >&5 -$as_echo "$ac_cv_c_bigendian" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_bigendian" >&5 +printf "%s\n" "$ac_cv_c_bigendian" >&6; } case $ac_cv_c_bigendian in #( yes) - $as_echo "#define WORDS_BIGENDIAN 1" >>confdefs.h + printf "%s\n" "#define WORDS_BIGENDIAN 1" >>confdefs.h ;; #( no) ;; #( universal) -$as_echo "#define AC_APPLE_UNIVERSAL_BUILD 1" >>confdefs.h +printf "%s\n" "#define AC_APPLE_UNIVERSAL_BUILD 1" >>confdefs.h ;; #( *) @@ -18926,35 +19994,25 @@ - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for long double with more range or precision than double" >&5 -$as_echo_n "checking for long double with more range or precision than double... " >&6; } -if ${ac_cv_type_long_double_wider+:} false; then : - $as_echo_n "(cached) " >&6 -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for long double" >&5 +printf %s "checking for long double... " >&6; } +if test ${ac_cv_type_long_double+y} +then : + printf %s "(cached) " >&6 +else $as_nop + if test "$GCC" = yes; then + ac_cv_type_long_double=yes + else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -#include - long double const a[] = - { - 0.0L, DBL_MIN, DBL_MAX, DBL_EPSILON, - LDBL_MIN, LDBL_MAX, LDBL_EPSILON - }; - long double - f (long double x) - { - return ((x + (unsigned long int) 10) * (-1 / x) + a[0] - + (x ? f (x) : 'c')); - } - +/* The Stardent Vistra knows sizeof (long double), but does + not support it. */ + long double foo = 0.0L; int -main () +main (void) { -static int test_array [1 - 2 * !((0 < ((DBL_MAX_EXP < LDBL_MAX_EXP) - + (DBL_MANT_DIG < LDBL_MANT_DIG) - - (LDBL_MAX_EXP < DBL_MAX_EXP) - - (LDBL_MANT_DIG < DBL_MANT_DIG))) - && (int) LDBL_EPSILON == 0 - )]; +static int test_array [1 - 2 * !(/* On Ultrix 4.3 cc, long double is 4 and double is 8. */ + sizeof (double) <= sizeof (long double))]; test_array [0] = 0; return test_array [0]; @@ -18962,28 +20020,23 @@ return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_type_long_double_wider=yes -else - ac_cv_type_long_double_wider=no +if ac_fn_c_try_compile "$LINENO" +then : + ac_cv_type_long_double=yes +else $as_nop + ac_cv_type_long_double=no fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext + fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_type_long_double_wider" >&5 -$as_echo "$ac_cv_type_long_double_wider" >&6; } - if test $ac_cv_type_long_double_wider = yes; then +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_type_long_double" >&5 +printf "%s\n" "$ac_cv_type_long_double" >&6; } + if test $ac_cv_type_long_double = yes; then -$as_echo "#define HAVE_LONG_DOUBLE_WIDER 1" >>confdefs.h +printf "%s\n" "#define HAVE_LONG_DOUBLE 1" >>confdefs.h fi - ac_cv_c_long_double=$ac_cv_type_long_double_wider - if test $ac_cv_c_long_double = yes; then - -$as_echo "#define HAVE_LONG_DOUBLE 1" >>confdefs.h - - fi - @@ -18991,29 +20044,30 @@ /* end confdefs.h. */ #define cpl_check_va_args(A, ...) printf(A, __VA_ARGS__) int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : -$as_echo "#define CPL_HAVE_VA_ARGS 1" >>confdefs.h +printf "%s\n" "#define CPL_HAVE_VA_ARGS 1" >>confdefs.h -else - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Variadic macros are not available" >&5 -$as_echo "$as_me: WARNING: Variadic macros are not available" >&2;} +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: Variadic macros are not available" >&5 +printf "%s\n" "$as_me: WARNING: Variadic macros are not available" >&2;} fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether complex number arithmetic is supported" >&5 -$as_echo_n "checking whether complex number arithmetic is supported... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether complex number arithmetic is supported" >&5 +printf %s "checking whether complex number arithmetic is supported... " >&6; } ac_ext=c ac_cpp='$CPP $CPPFLAGS' @@ -19026,7 +20080,7 @@ /* end confdefs.h. */ #include int -main () +main (void) { double _Complex a, b; @@ -19037,12 +20091,13 @@ return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : cpl_have_complex_types_c99=yes -else +else $as_nop cpl_have_complex_types_c99=no fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ac_ext=c ac_cpp='$CPP $CPPFLAGS' @@ -19052,14 +20107,14 @@ if test x"$cpl_have_complex_types_c99" = xno; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } as_fn_error $? "complex number arithmetic is not supported!" "$LINENO" 5 fi - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } - $as_echo "#define CPL_HAVE_COMPLEX_C99 1" >>confdefs.h + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } + printf "%s\n" "#define CPL_HAVE_COMPLEX_C99 1" >>confdefs.h @@ -19067,17 +20122,19 @@ # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. # This bug is HP SR number 8606223364. -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking size of size_t" >&5 -$as_echo_n "checking size of size_t... " >&6; } -if ${ac_cv_sizeof_size_t+:} false; then : - $as_echo_n "(cached) " >&6 -else - if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (size_t))" "ac_cv_sizeof_size_t" "$ac_includes_default"; then : +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking size of size_t" >&5 +printf %s "checking size of size_t... " >&6; } +if test ${ac_cv_sizeof_size_t+y} +then : + printf %s "(cached) " >&6 +else $as_nop + if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (size_t))" "ac_cv_sizeof_size_t" "$ac_includes_default" +then : -else +else $as_nop if test "$ac_cv_type_size_t" = yes; then - { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error 77 "cannot compute sizeof (size_t) See \`config.log' for more details" "$LINENO" 5; } else @@ -19086,31 +20143,31 @@ fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_size_t" >&5 -$as_echo "$ac_cv_sizeof_size_t" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_size_t" >&5 +printf "%s\n" "$ac_cv_sizeof_size_t" >&6; } -cat >>confdefs.h <<_ACEOF -#define SIZEOF_SIZE_T $ac_cv_sizeof_size_t -_ACEOF +printf "%s\n" "#define SIZEOF_SIZE_T $ac_cv_sizeof_size_t" >>confdefs.h # The cast to long int works around a bug in the HP C Compiler # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. # This bug is HP SR number 8606223364. -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking size of void *" >&5 -$as_echo_n "checking size of void *... " >&6; } -if ${ac_cv_sizeof_void_p+:} false; then : - $as_echo_n "(cached) " >&6 -else - if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (void *))" "ac_cv_sizeof_void_p" "$ac_includes_default"; then : +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking size of void *" >&5 +printf %s "checking size of void *... " >&6; } +if test ${ac_cv_sizeof_void_p+y} +then : + printf %s "(cached) " >&6 +else $as_nop + if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (void *))" "ac_cv_sizeof_void_p" "$ac_includes_default" +then : -else +else $as_nop if test "$ac_cv_type_void_p" = yes; then - { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error 77 "cannot compute sizeof (void *) See \`config.log' for more details" "$LINENO" 5; } else @@ -19119,31 +20176,31 @@ fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_void_p" >&5 -$as_echo "$ac_cv_sizeof_void_p" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_void_p" >&5 +printf "%s\n" "$ac_cv_sizeof_void_p" >&6; } -cat >>confdefs.h <<_ACEOF -#define SIZEOF_VOID_P $ac_cv_sizeof_void_p -_ACEOF +printf "%s\n" "#define SIZEOF_VOID_P $ac_cv_sizeof_void_p" >>confdefs.h # The cast to long int works around a bug in the HP C Compiler # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. # This bug is HP SR number 8606223364. -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking size of double" >&5 -$as_echo_n "checking size of double... " >&6; } -if ${ac_cv_sizeof_double+:} false; then : - $as_echo_n "(cached) " >&6 -else - if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (double))" "ac_cv_sizeof_double" "$ac_includes_default"; then : +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking size of double" >&5 +printf %s "checking size of double... " >&6; } +if test ${ac_cv_sizeof_double+y} +then : + printf %s "(cached) " >&6 +else $as_nop + if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (double))" "ac_cv_sizeof_double" "$ac_includes_default" +then : -else +else $as_nop if test "$ac_cv_type_double" = yes; then - { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error 77 "cannot compute sizeof (double) See \`config.log' for more details" "$LINENO" 5; } else @@ -19152,28 +20209,28 @@ fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_double" >&5 -$as_echo "$ac_cv_sizeof_double" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_double" >&5 +printf "%s\n" "$ac_cv_sizeof_double" >&6; } -cat >>confdefs.h <<_ACEOF -#define SIZEOF_DOUBLE $ac_cv_sizeof_double -_ACEOF +printf "%s\n" "#define SIZEOF_DOUBLE $ac_cv_sizeof_double" >>confdefs.h # Check whether --enable-largefile was given. -if test "${enable_largefile+set}" = set; then : +if test ${enable_largefile+y} +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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for special C compiler options needed for large files" >&5 +printf %s "checking for special C compiler options needed for large files... " >&6; } +if test ${ac_cv_sys_largefile_CC+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_cv_sys_largefile_CC=no if test "$GCC" != yes; then ac_save_CC=$CC @@ -19187,44 +20244,47 @@ 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)) +#define LARGE_OFF_T (((off_t) 1 << 31 << 31) - 1 + ((off_t) 1 << 31 << 31)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; int -main () +main (void) { ; return 0; } _ACEOF - if ac_fn_c_try_compile "$LINENO"; then : + if ac_fn_c_try_compile "$LINENO" +then : break fi -rm -f core conftest.err conftest.$ac_objext +rm -f core conftest.err conftest.$ac_objext conftest.beam CC="$CC -n32" - if ac_fn_c_try_compile "$LINENO"; then : + if ac_fn_c_try_compile "$LINENO" +then : ac_cv_sys_largefile_CC=' -n32'; break fi -rm -f core conftest.err conftest.$ac_objext +rm -f core conftest.err conftest.$ac_objext conftest.beam 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sys_largefile_CC" >&5 +printf "%s\n" "$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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for _FILE_OFFSET_BITS value needed for large files" >&5 +printf %s "checking for _FILE_OFFSET_BITS value needed for large files... " >&6; } +if test ${ac_cv_sys_file_offset_bits+y} +then : + printf %s "(cached) " >&6 +else $as_nop while :; do cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -19233,22 +20293,23 @@ 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)) +#define LARGE_OFF_T (((off_t) 1 << 31 << 31) - 1 + ((off_t) 1 << 31 << 31)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +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 +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #define _FILE_OFFSET_BITS 64 @@ -19257,43 +20318,43 @@ 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)) +#define LARGE_OFF_T (((off_t) 1 << 31 << 31) - 1 + ((off_t) 1 << 31 << 31)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +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 +rm -f core conftest.err conftest.$ac_objext conftest.beam 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sys_file_offset_bits" >&5 +printf "%s\n" "$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 +printf "%s\n" "#define _FILE_OFFSET_BITS $ac_cv_sys_file_offset_bits" >>confdefs.h ;; 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for _LARGE_FILES value needed for large files" >&5 +printf %s "checking for _LARGE_FILES value needed for large files... " >&6; } +if test ${ac_cv_sys_large_files+y} +then : + printf %s "(cached) " >&6 +else $as_nop while :; do cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -19302,22 +20363,23 @@ 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)) +#define LARGE_OFF_T (((off_t) 1 << 31 << 31) - 1 + ((off_t) 1 << 31 << 31)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +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 +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #define _LARGE_FILES 1 @@ -19326,84 +20388,78 @@ 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)) +#define LARGE_OFF_T (((off_t) 1 << 31 << 31) - 1 + ((off_t) 1 << 31 << 31)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +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 +rm -f core conftest.err conftest.$ac_objext conftest.beam 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sys_large_files" >&5 +printf "%s\n" "$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 +printf "%s\n" "#define _LARGE_FILES $ac_cv_sys_large_files" >>confdefs.h ;; esac rm -rf conftest* fi - - fi # Checks for library functions. -for ac_header in stdlib.h -do : - ac_fn_c_check_header_mongrel "$LINENO" "stdlib.h" "ac_cv_header_stdlib_h" "$ac_includes_default" -if test "x$ac_cv_header_stdlib_h" = xyes; then : - cat >>confdefs.h <<_ACEOF -#define HAVE_STDLIB_H 1 -_ACEOF - -fi - -done - -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for GNU libc compatible malloc" >&5 -$as_echo_n "checking for GNU libc compatible malloc... " >&6; } -if ${ac_cv_func_malloc_0_nonnull+:} false; then : - $as_echo_n "(cached) " >&6 -else - if test "$cross_compiling" = yes; then : - ac_cv_func_malloc_0_nonnull=no -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for GNU libc compatible malloc" >&5 +printf %s "checking for GNU libc compatible malloc... " >&6; } +if test ${ac_cv_func_malloc_0_nonnull+y} +then : + printf %s "(cached) " >&6 +else $as_nop + if test "$cross_compiling" = yes +then : + case "$host_os" in # (( + # Guess yes on platforms where we know the result. + *-gnu* | freebsd* | netbsd* | openbsd* | bitrig* \ + | hpux* | solaris* | cygwin* | mingw* | msys* ) + ac_cv_func_malloc_0_nonnull=yes ;; + # If we don't know, assume the worst. + *) ac_cv_func_malloc_0_nonnull=no ;; + esac +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -#if defined STDC_HEADERS || defined HAVE_STDLIB_H -# include -#else -char *malloc (); -#endif +#include int -main () +main (void) { -return ! malloc (0); +void *p = malloc (0); + int result = !p; + free (p); + return result; ; return 0; } _ACEOF -if ac_fn_c_try_run "$LINENO"; then : +if ac_fn_c_try_run "$LINENO" +then : ac_cv_func_malloc_0_nonnull=yes -else +else $as_nop ac_cv_func_malloc_0_nonnull=no fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ @@ -19411,14 +20467,15 @@ fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_malloc_0_nonnull" >&5 -$as_echo "$ac_cv_func_malloc_0_nonnull" >&6; } -if test $ac_cv_func_malloc_0_nonnull = yes; then : +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_malloc_0_nonnull" >&5 +printf "%s\n" "$ac_cv_func_malloc_0_nonnull" >&6; } +if test $ac_cv_func_malloc_0_nonnull = yes +then : -$as_echo "#define HAVE_MALLOC 1" >>confdefs.h +printf "%s\n" "#define HAVE_MALLOC 1" >>confdefs.h -else - $as_echo "#define HAVE_MALLOC 0" >>confdefs.h +else $as_nop + printf "%s\n" "#define HAVE_MALLOC 0" >>confdefs.h case " $LIBOBJS " in *" malloc.$ac_objext "* ) ;; @@ -19427,46 +20484,59 @@ esac -$as_echo "#define malloc rpl_malloc" >>confdefs.h +printf "%s\n" "#define malloc rpl_malloc" >>confdefs.h fi -for ac_func in vprintf -do : - ac_fn_c_check_func "$LINENO" "vprintf" "ac_cv_func_vprintf" -if test "x$ac_cv_func_vprintf" = xyes; then : - cat >>confdefs.h <<_ACEOF -#define HAVE_VPRINTF 1 -_ACEOF +ac_func= +for ac_item in $ac_func_c_list +do + if test $ac_func; then + ac_fn_c_check_func "$LINENO" $ac_func ac_cv_func_$ac_func + if eval test \"x\$ac_cv_func_$ac_func\" = xyes; then + echo "#define $ac_item 1" >> confdefs.h + fi + ac_func= + else + ac_func=$ac_item + fi +done -ac_fn_c_check_func "$LINENO" "_doprnt" "ac_cv_func__doprnt" -if test "x$ac_cv_func__doprnt" = xyes; then : +if test "x$ac_cv_func_vprintf" = xno +then : + ac_fn_c_check_func "$LINENO" "_doprnt" "ac_cv_func__doprnt" +if test "x$ac_cv_func__doprnt" = xyes +then : -$as_echo "#define HAVE_DOPRNT 1" >>confdefs.h +printf "%s\n" "#define HAVE_DOPRNT 1" >>confdefs.h fi fi -done - - -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether lstat correctly handles trailing slash" >&5 -$as_echo_n "checking whether lstat correctly handles trailing slash... " >&6; } -if ${ac_cv_func_lstat_dereferences_slashed_symlink+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether lstat correctly handles trailing slash" >&5 +printf %s "checking whether lstat correctly handles trailing slash... " >&6; } +if test ${ac_cv_func_lstat_dereferences_slashed_symlink+y} +then : + printf %s "(cached) " >&6 +else $as_nop rm -f conftest.sym conftest.file echo >conftest.file if test "$as_ln_s" = "ln -s" && ln -s conftest.file conftest.sym; then - if test "$cross_compiling" = yes; then : - ac_cv_func_lstat_dereferences_slashed_symlink=no -else + if test "$cross_compiling" = yes +then : + case "$host_os" in # (( + # Guess yes on glibc systems. + *-gnu*) ac_cv_func_lstat_dereferences_slashed_symlink=yes ;; + # If we don't know, assume the worst. + *) ac_cv_func_lstat_dereferences_slashed_symlink=no ;; + esac +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $ac_includes_default int -main () +main (void) { struct stat sbuf; /* Linux will dereference the symlink and fail, as required by POSIX. @@ -19477,9 +20547,10 @@ return 0; } _ACEOF -if ac_fn_c_try_run "$LINENO"; then : +if ac_fn_c_try_run "$LINENO" +then : ac_cv_func_lstat_dereferences_slashed_symlink=yes -else +else $as_nop ac_cv_func_lstat_dereferences_slashed_symlink=no fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ @@ -19494,14 +20565,12 @@ rm -f conftest.sym conftest.file fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_lstat_dereferences_slashed_symlink" >&5 -$as_echo "$ac_cv_func_lstat_dereferences_slashed_symlink" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_lstat_dereferences_slashed_symlink" >&5 +printf "%s\n" "$ac_cv_func_lstat_dereferences_slashed_symlink" >&6; } test $ac_cv_func_lstat_dereferences_slashed_symlink = yes && -cat >>confdefs.h <<_ACEOF -#define LSTAT_FOLLOWS_SLASHED_SYMLINK 1 -_ACEOF +printf "%s\n" "#define LSTAT_FOLLOWS_SLASHED_SYMLINK 1" >>confdefs.h if test "x$ac_cv_func_lstat_dereferences_slashed_symlink" = xno; then @@ -19513,19 +20582,21 @@ fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether stat accepts an empty string" >&5 -$as_echo_n "checking whether stat accepts an empty string... " >&6; } -if ${ac_cv_func_stat_empty_string_bug+:} false; then : - $as_echo_n "(cached) " >&6 -else - if test "$cross_compiling" = yes; then : +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether stat accepts an empty string" >&5 +printf %s "checking whether stat accepts an empty string... " >&6; } +if test ${ac_cv_func_stat_empty_string_bug+y} +then : + printf %s "(cached) " >&6 +else $as_nop + if test "$cross_compiling" = yes +then : ac_cv_func_stat_empty_string_bug=yes -else +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $ac_includes_default int -main () +main (void) { struct stat sbuf; return stat ("", &sbuf) == 0; @@ -19533,9 +20604,10 @@ return 0; } _ACEOF -if ac_fn_c_try_run "$LINENO"; then : +if ac_fn_c_try_run "$LINENO" +then : ac_cv_func_stat_empty_string_bug=no -else +else $as_nop ac_cv_func_stat_empty_string_bug=yes fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ @@ -19543,8 +20615,8 @@ fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_stat_empty_string_bug" >&5 -$as_echo "$ac_cv_func_stat_empty_string_bug" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_stat_empty_string_bug" >&5 +printf "%s\n" "$ac_cv_func_stat_empty_string_bug" >&6; } if test $ac_cv_func_stat_empty_string_bug = yes; then case " $LIBOBJS " in *" stat.$ac_objext "* ) ;; @@ -19553,80 +20625,152 @@ esac -cat >>confdefs.h <<_ACEOF -#define HAVE_STAT_EMPTY_STRING_BUG 1 -_ACEOF +printf "%s\n" "#define HAVE_STAT_EMPTY_STRING_BUG 1" >>confdefs.h fi # fdopen, fileno and dup allows stream duplication # Additional presence of sigaction sigemptyset allows windows resizing -for ac_func in getcwd strdup strrchr fdopen fileno dup sigaction sigemptyset \ - stat getpid setenv llabs cbrt cbrtf clock_gettime gettimeofday -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 +ac_fn_c_check_func "$LINENO" "getcwd" "ac_cv_func_getcwd" +if test "x$ac_cv_func_getcwd" = xyes +then : + printf "%s\n" "#define HAVE_GETCWD 1" >>confdefs.h + +fi +ac_fn_c_check_func "$LINENO" "strdup" "ac_cv_func_strdup" +if test "x$ac_cv_func_strdup" = xyes +then : + printf "%s\n" "#define HAVE_STRDUP 1" >>confdefs.h + +fi +ac_fn_c_check_func "$LINENO" "strrchr" "ac_cv_func_strrchr" +if test "x$ac_cv_func_strrchr" = xyes +then : + printf "%s\n" "#define HAVE_STRRCHR 1" >>confdefs.h + +fi +ac_fn_c_check_func "$LINENO" "fdopen" "ac_cv_func_fdopen" +if test "x$ac_cv_func_fdopen" = xyes +then : + printf "%s\n" "#define HAVE_FDOPEN 1" >>confdefs.h + +fi +ac_fn_c_check_func "$LINENO" "fileno" "ac_cv_func_fileno" +if test "x$ac_cv_func_fileno" = xyes +then : + printf "%s\n" "#define HAVE_FILENO 1" >>confdefs.h + +fi +ac_fn_c_check_func "$LINENO" "dup" "ac_cv_func_dup" +if test "x$ac_cv_func_dup" = xyes +then : + printf "%s\n" "#define HAVE_DUP 1" >>confdefs.h + +fi +ac_fn_c_check_func "$LINENO" "sigaction" "ac_cv_func_sigaction" +if test "x$ac_cv_func_sigaction" = xyes +then : + printf "%s\n" "#define HAVE_SIGACTION 1" >>confdefs.h + +fi +ac_fn_c_check_func "$LINENO" "sigemptyset" "ac_cv_func_sigemptyset" +if test "x$ac_cv_func_sigemptyset" = xyes +then : + printf "%s\n" "#define HAVE_SIGEMPTYSET 1" >>confdefs.h + +fi +ac_fn_c_check_func "$LINENO" "stat" "ac_cv_func_stat" +if test "x$ac_cv_func_stat" = xyes +then : + printf "%s\n" "#define HAVE_STAT 1" >>confdefs.h + +fi +ac_fn_c_check_func "$LINENO" "getpid" "ac_cv_func_getpid" +if test "x$ac_cv_func_getpid" = xyes +then : + printf "%s\n" "#define HAVE_GETPID 1" >>confdefs.h + +fi +ac_fn_c_check_func "$LINENO" "setenv" "ac_cv_func_setenv" +if test "x$ac_cv_func_setenv" = xyes +then : + printf "%s\n" "#define HAVE_SETENV 1" >>confdefs.h + +fi +ac_fn_c_check_func "$LINENO" "llabs" "ac_cv_func_llabs" +if test "x$ac_cv_func_llabs" = xyes +then : + printf "%s\n" "#define HAVE_LLABS 1" >>confdefs.h + +fi +ac_fn_c_check_func "$LINENO" "cbrt" "ac_cv_func_cbrt" +if test "x$ac_cv_func_cbrt" = xyes +then : + printf "%s\n" "#define HAVE_CBRT 1" >>confdefs.h + +fi +ac_fn_c_check_func "$LINENO" "cbrtf" "ac_cv_func_cbrtf" +if test "x$ac_cv_func_cbrtf" = xyes +then : + printf "%s\n" "#define HAVE_CBRTF 1" >>confdefs.h + +fi +ac_fn_c_check_func "$LINENO" "clock_gettime" "ac_cv_func_clock_gettime" +if test "x$ac_cv_func_clock_gettime" = xyes +then : + printf "%s\n" "#define HAVE_CLOCK_GETTIME 1" >>confdefs.h + +fi +ac_fn_c_check_func "$LINENO" "gettimeofday" "ac_cv_func_gettimeofday" +if test "x$ac_cv_func_gettimeofday" = xyes +then : + printf "%s\n" "#define HAVE_GETTIMEOFDAY 1" >>confdefs.h fi -done # Even with -std=c99 these non-C99 functions may be defined, # so check also if they are declared... -ac_fn_c_check_decl "$LINENO" "stat" "ac_cv_have_decl_stat" "$ac_includes_default" -if test "x$ac_cv_have_decl_stat" = xyes; then : +ac_fn_check_decl "$LINENO" "stat" "ac_cv_have_decl_stat" "$ac_includes_default" "$ac_c_undeclared_builtin_options" "CFLAGS" +if test "x$ac_cv_have_decl_stat" = xyes +then : ac_have_decl=1 -else +else $as_nop ac_have_decl=0 fi - -cat >>confdefs.h <<_ACEOF -#define HAVE_DECL_STAT $ac_have_decl -_ACEOF -ac_fn_c_check_decl "$LINENO" "fdopen" "ac_cv_have_decl_fdopen" "$ac_includes_default" -if test "x$ac_cv_have_decl_fdopen" = xyes; then : +printf "%s\n" "#define HAVE_DECL_STAT $ac_have_decl" >>confdefs.h +ac_fn_check_decl "$LINENO" "fdopen" "ac_cv_have_decl_fdopen" "$ac_includes_default" "$ac_c_undeclared_builtin_options" "CFLAGS" +if test "x$ac_cv_have_decl_fdopen" = xyes +then : ac_have_decl=1 -else +else $as_nop ac_have_decl=0 fi - -cat >>confdefs.h <<_ACEOF -#define HAVE_DECL_FDOPEN $ac_have_decl -_ACEOF -ac_fn_c_check_decl "$LINENO" "fileno" "ac_cv_have_decl_fileno" "$ac_includes_default" -if test "x$ac_cv_have_decl_fileno" = xyes; then : +printf "%s\n" "#define HAVE_DECL_FDOPEN $ac_have_decl" >>confdefs.h +ac_fn_check_decl "$LINENO" "fileno" "ac_cv_have_decl_fileno" "$ac_includes_default" "$ac_c_undeclared_builtin_options" "CFLAGS" +if test "x$ac_cv_have_decl_fileno" = xyes +then : ac_have_decl=1 -else +else $as_nop ac_have_decl=0 fi - -cat >>confdefs.h <<_ACEOF -#define HAVE_DECL_FILENO $ac_have_decl -_ACEOF -ac_fn_c_check_decl "$LINENO" "dup" "ac_cv_have_decl_dup" "$ac_includes_default" -if test "x$ac_cv_have_decl_dup" = xyes; then : +printf "%s\n" "#define HAVE_DECL_FILENO $ac_have_decl" >>confdefs.h +ac_fn_check_decl "$LINENO" "dup" "ac_cv_have_decl_dup" "$ac_includes_default" "$ac_c_undeclared_builtin_options" "CFLAGS" +if test "x$ac_cv_have_decl_dup" = xyes +then : ac_have_decl=1 -else +else $as_nop ac_have_decl=0 fi - -cat >>confdefs.h <<_ACEOF -#define HAVE_DECL_DUP $ac_have_decl -_ACEOF -ac_fn_c_check_decl "$LINENO" "llabs" "ac_cv_have_decl_llabs" "$ac_includes_default" -if test "x$ac_cv_have_decl_llabs" = xyes; then : +printf "%s\n" "#define HAVE_DECL_DUP $ac_have_decl" >>confdefs.h +ac_fn_check_decl "$LINENO" "llabs" "ac_cv_have_decl_llabs" "$ac_includes_default" "$ac_c_undeclared_builtin_options" "CFLAGS" +if test "x$ac_cv_have_decl_llabs" = xyes +then : ac_have_decl=1 -else +else $as_nop ac_have_decl=0 fi - -cat >>confdefs.h <<_ACEOF -#define HAVE_DECL_LLABS $ac_have_decl -_ACEOF +printf "%s\n" "#define HAVE_DECL_LLABS $ac_have_decl" >>confdefs.h @@ -19641,13 +20785,13 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu - ac_fn_c_check_decl "$LINENO" "sysconf" "ac_cv_have_decl_sysconf" "#include -" -if test "x$ac_cv_have_decl_sysconf" = xyes; then : + ac_fn_check_decl "$LINENO" "sysconf" "ac_cv_have_decl_sysconf" "#include +" "$ac_c_undeclared_builtin_options" "CFLAGS" +if test "x$ac_cv_have_decl_sysconf" = xyes +then : fi - eso_save_CFLAGS="$CFLAGS" if test x"$GCC" = xyes; then @@ -19655,7 +20799,8 @@ fi ac_fn_c_check_func "$LINENO" "sysconf" "ac_cv_func_sysconf" -if test "x$ac_cv_func_sysconf" = xyes; then : +if test "x$ac_cv_func_sysconf" = xyes +then : fi @@ -19671,7 +20816,7 @@ if test x"$ac_cv_have_decl_sysconf" = xyes && test x"$ac_cv_func_sysconf" = xyes; then - $as_echo "#define HAVE_SYSCONF 1" >>confdefs.h + printf "%s\n" "#define HAVE_SYSCONF 1" >>confdefs.h fi @@ -19684,27 +20829,30 @@ # Check whether --with-extra-includes was given. -if test "${with_extra_includes+set}" = set; then : +if test ${with_extra_includes+y} +then : withval=$with_extra_includes; eso_with_extra_includes=$withval -else +else $as_nop eso_with_extra_includes=NONE fi # Check whether --with-extra-libs was given. -if test "${with_extra_libs+set}" = set; then : +if test ${with_extra_libs+y} +then : withval=$with_extra_libs; eso_with_extra_libs=$withval -else +else $as_nop eso_with_extra_libs=NONE fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for extra includes" >&5 -$as_echo_n "checking for extra includes... " >&6; } - if ${eso_cv_with_extra_includes+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for extra includes" >&5 +printf %s "checking for extra includes... " >&6; } + if test ${eso_cv_with_extra_includes+y} +then : + printf %s "(cached) " >&6 +else $as_nop eso_cv_with_extra_includes=$eso_with_extra_includes @@ -19720,19 +20868,20 @@ done IFS=$eso_save_IFS - { $as_echo "$as_me:${as_lineno-$LINENO}: result: added" >&5 -$as_echo "added" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: added" >&5 +printf "%s\n" "added" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for extra libs" >&5 -$as_echo_n "checking for extra libs... " >&6; } - if ${eso_cv_with_extra_libs+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for extra libs" >&5 +printf %s "checking for extra libs... " >&6; } + if test ${eso_cv_with_extra_libs+y} +then : + printf %s "(cached) " >&6 +else $as_nop eso_cv_with_extra_libs=$eso_with_extra_libs @@ -19748,11 +20897,11 @@ done IFS=$eso_save_IFS - { $as_echo "$as_me:${as_lineno-$LINENO}: result: added" >&5 -$as_echo "added" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: added" >&5 +printf "%s\n" "added" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -19760,8 +20909,8 @@ - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for CPL" >&5 -$as_echo_n "checking for CPL... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for CPL" >&5 +printf %s "checking for CPL... " >&6; } if test x"${prefix}" = xNONE; then cpl_prefix="$ac_default_prefix" @@ -19771,12 +20920,12 @@ if test x"$exec_prefix" = xNONE; then cpl_exec_prefix="$cpl_prefix" - { $as_echo "$as_me:${as_lineno-$LINENO}: result: will be installed in $cpl_prefix" >&5 -$as_echo "will be installed in $cpl_prefix" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: will be installed in $cpl_prefix" >&5 +printf "%s\n" "will be installed in $cpl_prefix" >&6; } else cpl_exec_prefix="$exec_prefix" - { $as_echo "$as_me:${as_lineno-$LINENO}: result: will be installed in $cpl_prefix and $cpl_exec_prefix" >&5 -$as_echo "will be installed in $cpl_prefix and $cpl_exec_prefix" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: will be installed in $cpl_prefix and $cpl_exec_prefix" >&5 +printf "%s\n" "will be installed in $cpl_prefix and $cpl_exec_prefix" >&6; } fi cpl_libraries="${cpl_exec_prefix}/lib" @@ -19789,6 +20938,7 @@ CPLDRS_INCLUDES="-I\$(top_srcdir)/cpldrs -I\$(top_builddir)/cpldrs" CPLUI_INCLUDES='-I$(top_srcdir)/cplui -I$(top_builddir)/cplui' CPLDFS_INCLUDES='-I$(top_srcdir)/cpldfs -I$(top_builddir)/cpldfs' + CPLJAVA_INCLUDES='-I$(top_srcdir)/cpljava -I$(top_builddir)/cpljava' CPL_INCLUDES="$CPLDFS_INCLUDES $CPLUI_INCLUDES $CPLDRS_INCLUDES $CPLCORE_INCLUDES" CPL_LDFLAGS="" @@ -19804,6 +20954,7 @@ + if test -z "$apidocdir"; then apidocdir='${datadir}/doc/${PACKAGE}/html' fi @@ -19823,9 +20974,7 @@ config_dir="`eval echo $config_dir`" -cat >>confdefs.h <<_ACEOF -#define CPL_CONFIG_DIR "$config_dir" -_ACEOF +printf "%s\n" "#define CPL_CONFIG_DIR \"$config_dir\"" >>confdefs.h @@ -19836,11 +20985,13 @@ LIBCPLDRS='-lcpldrs' LIBCPLUI='-lcplui' LIBCPLDFS='-lcpldfs' + LIBCPLGASGANO='-lcplgasgano' else LIBCPLCORE='$(top_builddir)/cplcore/libcplcore.la' LIBCPLDRS='$(top_builddir)/cpldrs/libcpldrs.la' LIBCPLUI='$(top_builddir)/cplui/libcplui.la' LIBCPLDFS='$(top_builddir)/cpldfs/libcpldfs.la' + LIBCPLGASGANO='$(top_builddir)/cpljava/libcplgasgano.la' fi @@ -19851,6 +21002,7 @@ + for d in htmldir; do eval cpl_propagate_dir="\$$d" ac_configure_args="$ac_configure_args $d='$cpl_propagate_dir'" @@ -19859,11 +21011,12 @@ - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for extended memory mode" >&5 -$as_echo_n "checking for extended memory mode... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for extended memory mode" >&5 +printf %s "checking for extended memory mode... " >&6; } # Check whether --enable-memory-mode was given. -if test "${enable_memory_mode+set}" = set; then : +if test ${enable_memory_mode+y} +then : enableval=$enable_memory_mode; cpl_memory_flag=yes # $enableval=yes when no argument is given @@ -19873,7 +21026,8 @@ # Check whether --enable-max-ptrs was given. -if test "${enable_max_ptrs+set}" = set; then : +if test ${enable_max_ptrs+y} +then : enableval=$enable_max_ptrs; cpl_max_ptrs_flag=yes cpl_max_ptrs=$enableval @@ -19909,34 +21063,30 @@ CPL_CFLAGS="-DCPL_XMEMORY_MODE=0 -DCPL_XMEMORY_MAXPTRS=1" fi - { $as_echo "$as_me:${as_lineno-$LINENO}: result: CPL_CFLAGS=$CPL_CFLAGS" >&5 -$as_echo "CPL_CFLAGS=$CPL_CFLAGS" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: CPL_CFLAGS=$CPL_CFLAGS" >&5 +printf "%s\n" "CPL_CFLAGS=$CPL_CFLAGS" >&6; } - { $as_echo "$as_me:${as_lineno-$LINENO}: checking /proc/cpuinfo for the CPU cache and cores" >&5 -$as_echo_n "checking /proc/cpuinfo for the CPU cache and cores... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking /proc/cpuinfo for the CPU cache and cores" >&5 +printf %s "checking /proc/cpuinfo for the CPU cache and cores... " >&6; } if test -r "/proc/cpuinfo"; then cpl_cpu_cache_string=`grep "cache size" /proc/cpuinfo | head -1 | perl -ne 's/^\D+//;s/\b\s*kB\b\D*/<<10/i || s/\b\s*MB\b\D*/<<20/i;/^\d+/ and print eval'` if test -n "$cpl_cpu_cache_string"; then -cat >>confdefs.h <<_ACEOF -#define CPL_CPU_CACHE $cpl_cpu_cache_string -_ACEOF +printf "%s\n" "#define CPL_CPU_CACHE $cpl_cpu_cache_string" >>confdefs.h - { $as_echo "$as_me:${as_lineno-$LINENO}: result: CPU cache $cpl_cpu_cache_string B" >&5 -$as_echo "CPU cache $cpl_cpu_cache_string B" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: CPU cache $cpl_cpu_cache_string B" >&5 +printf "%s\n" "CPU cache $cpl_cpu_cache_string B" >&6; } fi cpl_cpu_core_string=`grep "cpu cores" /proc/cpuinfo | head -1 | perl -ne 's/^\D+//g;/^\d+/ and print'` if test -n "$cpl_cpu_core_string"; then -cat >>confdefs.h <<_ACEOF -#define CPL_CPU_CORES $cpl_cpu_core_string -_ACEOF +printf "%s\n" "#define CPL_CPU_CORES $cpl_cpu_core_string" >>confdefs.h - { $as_echo "$as_me:${as_lineno-$LINENO}: result: CPU cores $cpl_cpu_core_string" >&5 -$as_echo "CPU cores $cpl_cpu_core_string" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: CPU cores $cpl_cpu_core_string" >&5 +printf "%s\n" "CPU cores $cpl_cpu_core_string" >&6; } fi fi @@ -19947,29 +21097,30 @@ # Check whether --enable-gasgano was given. -if test "${enable_gasgano+set}" = set; then : +if test ${enable_gasgano+y} +then : enableval=$enable_gasgano; cpl_enable_gasgano=$enableval -else +else $as_nop cpl_enable_gasgano=yes fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the Gasgano interface library can be built" >&5 -$as_echo_n "checking whether the Gasgano interface library can be built... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the Gasgano interface library can be built" >&5 +printf %s "checking whether the Gasgano interface library can be built... " >&6; } if test x"$cpl_enable_gasgano" != xyes; then cpl_gasgano_support="no" - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } else if test -n "$JAVA_INCLUDES"; then cpl_gasgano_support="yes" - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } else cpl_gasgano_support="no" - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi fi @@ -20010,12 +21161,13 @@ } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : cpl_cv_func_has_func=__func__ -else +else $as_nop cpl_cv_func_has_func='"\"\""' fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext ac_config_commands="$ac_config_commands cplcore/cpl_func.h.in" @@ -20029,7 +21181,7 @@ fi -ac_config_files="$ac_config_files Makefile Doxyfile cplcore/Makefile cplcore/tests/Makefile cpldrs/Makefile cpldrs/tests/Makefile cplui/Makefile cplui/tests/Makefile cpldfs/Makefile cpldfs/tests/Makefile cpljava/Makefile" +ac_config_files="$ac_config_files Makefile Doxyfile cplcore/Makefile cplcore/tests/Makefile cpldrs/Makefile cpldrs/tests/Makefile cplui/Makefile cplui/tests/Makefile cpldfs/Makefile cpldfs/tests/Makefile cpljava/Makefile cpljava/tests/Makefile" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure @@ -20058,8 +21210,8 @@ 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;} ;; + *_cv_*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 +printf "%s\n" "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; esac case $ac_var in #( _ | IFS | as_nl) ;; #( @@ -20089,15 +21241,15 @@ /^ac_cv_env_/b end t clear :clear - s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/ + s/^\([^=]*\)=\(.*[{}].*\)$/test ${\1+y} || &/ 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;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5 +printf "%s\n" "$as_me: updating cache $cache_file" >&6;} if test ! -f "$cache_file" || test -h "$cache_file"; then cat confcache >"$cache_file" else @@ -20111,8 +21263,8 @@ 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;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5 +printf "%s\n" "$as_me: not updating unwritable cache $cache_file" >&6;} fi fi rm -f confcache @@ -20129,7 +21281,7 @@ 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"` + ac_i=`printf "%s\n" "$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" @@ -20140,14 +21292,14 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking that generated files are newer than configure" >&5 +printf %s "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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: done" >&5 +printf "%s\n" "done" >&6; } if test -n "$EXEEXT"; then am__EXEEXT_TRUE= am__EXEEXT_FALSE='#' @@ -20207,8 +21359,8 @@ 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;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5 +printf "%s\n" "$as_me: creating $CONFIG_STATUS" >&6;} as_write_fail=0 cat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1 #! $SHELL @@ -20231,14 +21383,16 @@ # Be more Bourne compatible DUALCASE=1; export DUALCASE # for MKS sh -if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : +as_nop=: +if test ${ZSH_VERSION+y} && (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 +else $as_nop case `(set -o) 2>/dev/null` in #( *posix*) : set -o posix ;; #( @@ -20248,46 +21402,46 @@ fi + +# Reset variables that may have inherited troublesome values from +# the environment. + +# IFS needs to be set, to space, tab, and newline, in precisely that order. +# (If _AS_PATH_WALK were called with IFS unset, it would have the +# side effect of setting IFS to empty, thus disabling word splitting.) +# Quoting is to prevent editors from complaining about space-tab. 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 +IFS=" "" $as_nl" + +PS1='$ ' +PS2='> ' +PS4='+ ' + +# Ensure predictable behavior from utilities with locale-dependent output. +LC_ALL=C +export LC_ALL +LANGUAGE=C +export LANGUAGE + +# We cannot yet rely on "unset" to work, but we need these variables +# to be unset--not just set to an empty or harmless value--now, to +# avoid bugs in old shells (e.g. pre-3.0 UWIN ksh). This construct +# also avoids known problems related to "unset" and subshell syntax +# in other old shells (e.g. bash 2.01 and pdksh 5.2.14). +for as_var in BASH_ENV ENV MAIL MAILPATH CDPATH +do eval test \${$as_var+y} \ + && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : +done + +# Ensure that fds 0, 1, and 2 are open. +if (exec 3>&0) 2>/dev/null; then :; else exec 0&1) 2>/dev/null; then :; else exec 1>/dev/null; fi +if (exec 3>&2) ; then :; else exec 2>/dev/null; fi # The user is always right. -if test "${PATH_SEPARATOR+set}" != set; then +if ${PATH_SEPARATOR+false} :; 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 || @@ -20296,13 +21450,6 @@ 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 #(( @@ -20311,8 +21458,12 @@ 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 + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + test -r "$as_dir$0" && as_myself=$as_dir$0 && break done IFS=$as_save_IFS @@ -20324,30 +21475,10 @@ 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 + printf "%s\n" "$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] @@ -20360,13 +21491,14 @@ 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 fi - $as_echo "$as_me: error: $2" >&2 + printf "%s\n" "$as_me: error: $2" >&2 as_fn_exit $as_status } # as_fn_error + # as_fn_set_status STATUS # ----------------------- # Set $? to STATUS, without forking. @@ -20393,18 +21525,20 @@ { 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 : +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 +else $as_nop as_fn_append () { eval $1=\$$1\$2 @@ -20416,12 +21550,13 @@ # 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 : +if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null +then : eval 'as_fn_arith () { as_val=$(( $* )) }' -else +else $as_nop as_fn_arith () { as_val=`expr "$@" || test $? -eq 1` @@ -20452,7 +21587,7 @@ $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ X"$0" : 'X\(//\)$' \| \ X"$0" : 'X\(/\)' \| . 2>/dev/null || -$as_echo X/"$0" | +printf "%s\n" X/"$0" | sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/ q @@ -20474,6 +21609,10 @@ as_cr_digits='0123456789' as_cr_alnum=$as_cr_Letters$as_cr_digits + +# Determine whether it's possible to make 'echo' print without a newline. +# These variables are no longer used directly by Autoconf, but are AC_SUBSTed +# for compatibility with existing Makefiles. ECHO_C= ECHO_N= ECHO_T= case `echo -n x` in #((((( -n*) @@ -20487,6 +21626,12 @@ ECHO_N='-n';; esac +# For backward compatibility with old third-party macros, we provide +# the shell variables $as_echo and $as_echo_n. New code should use +# AS_ECHO(["message"]) and AS_ECHO_N(["message"]), respectively. +as_echo='printf %s\n' +as_echo_n='printf %s' + rm -f conf$$ conf$$.exe conf$$.file if test -d conf$$.dir; then rm -f conf$$.dir/conf$$.file @@ -20528,7 +21673,7 @@ as_dirs= while :; do case $as_dir in #( - *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( + *\'*) as_qdir=`printf "%s\n" "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( *) as_qdir=$as_dir;; esac as_dirs="'$as_qdir' $as_dirs" @@ -20537,7 +21682,7 @@ X"$as_dir" : 'X\(//\)[^/]' \| \ X"$as_dir" : 'X\(//\)$' \| \ X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || -$as_echo X"$as_dir" | +printf "%s\n" X"$as_dir" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q @@ -20599,8 +21744,8 @@ # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by Common Pipeline Library $as_me 7.1.4, which was -generated by GNU Autoconf 2.69. Invocation command line was +This file was extended by Common Pipeline Library $as_me 7.2.2, which was +generated by GNU Autoconf 2.71. Invocation command line was CONFIG_FILES = $CONFIG_FILES CONFIG_HEADERS = $CONFIG_HEADERS @@ -20662,14 +21807,16 @@ Report bugs to ." _ACEOF +ac_cs_config=`printf "%s\n" "$ac_configure_args" | sed "$ac_safe_unquote"` +ac_cs_config_escaped=`printf "%s\n" "$ac_cs_config" | sed "s/^ //; s/'/'\\\\\\\\''/g"` cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 -ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" +ac_cs_config='$ac_cs_config_escaped' ac_cs_version="\\ -Common Pipeline Library config.status 7.1.4 -configured by $0, generated by GNU Autoconf 2.69, +Common Pipeline Library config.status 7.2.2 +configured by $0, generated by GNU Autoconf 2.71, with options \\"\$ac_cs_config\\" -Copyright (C) 2012 Free Software Foundation, Inc. +Copyright (C) 2021 Free Software Foundation, Inc. This config.status script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it." @@ -20709,15 +21856,15 @@ -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 ;; + printf "%s\n" "$ac_cs_version"; exit ;; --config | --confi | --conf | --con | --co | --c ) - $as_echo "$ac_cs_config"; exit ;; + printf "%s\n" "$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"` ;; + *\'*) ac_optarg=`printf "%s\n" "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; '') as_fn_error $? "missing file argument" ;; esac as_fn_append CONFIG_FILES " '$ac_optarg'" @@ -20725,7 +21872,7 @@ --header | --heade | --head | --hea ) $ac_shift case $ac_optarg in - *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; + *\'*) ac_optarg=`printf "%s\n" "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; esac as_fn_append CONFIG_HEADERS " '$ac_optarg'" ac_need_defaults=false;; @@ -20734,7 +21881,7 @@ as_fn_error $? "ambiguous option: \`$1' Try \`$0 --help' for more information.";; --help | --hel | -h ) - $as_echo "$ac_cs_usage"; exit ;; + printf "%s\n" "$ac_cs_usage"; exit ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil | --si | --s) ac_cs_silent=: ;; @@ -20762,7 +21909,7 @@ 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 + \printf "%s\n" "running CONFIG_SHELL=$SHELL \$*" >&6 CONFIG_SHELL='$SHELL' export CONFIG_SHELL exec "\$@" @@ -20776,7 +21923,7 @@ sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX ## Running $as_me. ## _ASBOX - $as_echo "$ac_log" + printf "%s\n" "$ac_log" } >&5 _ACEOF @@ -20784,7 +21931,7 @@ # # INIT-COMMANDS # -AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir" +AMDEP_TRUE="$AMDEP_TRUE" MAKE="${MAKE-make}" # The HP-UX ksh and POSIX shell print the target directory to stdout @@ -21095,6 +22242,7 @@ "cpldfs/Makefile") CONFIG_FILES="$CONFIG_FILES cpldfs/Makefile" ;; "cpldfs/tests/Makefile") CONFIG_FILES="$CONFIG_FILES cpldfs/tests/Makefile" ;; "cpljava/Makefile") CONFIG_FILES="$CONFIG_FILES cpljava/Makefile" ;; + "cpljava/tests/Makefile") CONFIG_FILES="$CONFIG_FILES cpljava/tests/Makefile" ;; *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;; esac @@ -21106,9 +22254,9 @@ # 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 + test ${CONFIG_FILES+y} || CONFIG_FILES=$config_files + test ${CONFIG_HEADERS+y} || CONFIG_HEADERS=$config_headers + test ${CONFIG_COMMANDS+y} || CONFIG_COMMANDS=$config_commands fi # Have a temporary directory for convenience. Make it in the build tree @@ -21444,7 +22592,7 @@ 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 + case $ac_f in *\'*) ac_f=`printf "%s\n" "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac as_fn_append ac_file_inputs " '$ac_f'" done @@ -21452,17 +22600,17 @@ # 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' + printf "%s\n" "$*" | 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;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5 +printf "%s\n" "$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" | + ac_sed_conf_input=`printf "%s\n" "$configure_input" | sed 's/[\\\\&|]/\\\\&/g'`;; #( *) ac_sed_conf_input=$configure_input;; esac @@ -21479,7 +22627,7 @@ X"$ac_file" : 'X\(//\)[^/]' \| \ X"$ac_file" : 'X\(//\)$' \| \ X"$ac_file" : 'X\(/\)' \| . 2>/dev/null || -$as_echo X"$ac_file" | +printf "%s\n" X"$ac_file" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q @@ -21503,9 +22651,9 @@ case "$ac_dir" in .) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; *) - ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` + ac_dir_suffix=/`printf "%s\n" "$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|/||'` + ac_top_builddir_sub=`printf "%s\n" "$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/ ;; @@ -21567,8 +22715,8 @@ 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;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5 +printf "%s\n" "$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=' @@ -21612,9 +22760,9 @@ { 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' + { printf "%s\n" "$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' +printf "%s\n" "$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" @@ -21630,20 +22778,20 @@ # if test x"$ac_file" != x-; then { - $as_echo "/* $configure_input */" \ + printf "%s\n" "/* $configure_input */" >&1 \ && 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;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: $ac_file is unchanged" >&5 +printf "%s\n" "$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 */" \ + printf "%s\n" "/* $configure_input */" >&1 \ && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs" \ || as_fn_error $? "could not create -" "$LINENO" 5 fi @@ -21663,7 +22811,7 @@ X"$_am_arg" : 'X\(//\)[^/]' \| \ X"$_am_arg" : 'X\(//\)$' \| \ X"$_am_arg" : 'X\(/\)' \| . 2>/dev/null || -$as_echo X"$_am_arg" | +printf "%s\n" X"$_am_arg" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q @@ -21683,8 +22831,8 @@ 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;} + :C) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: executing $ac_file commands" >&5 +printf "%s\n" "$as_me: executing $ac_file commands" >&6;} ;; esac @@ -21694,29 +22842,35 @@ # 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 + # TODO: see whether this extra hack can be removed once we start + # requiring Autoconf 2.70 or later. + case $CONFIG_FILES in #( + *\'*) : + eval set x "$CONFIG_FILES" ;; #( + *) : + set x $CONFIG_FILES ;; #( + *) : + ;; +esac shift - for mf + # Used to flag and report bootstrapping failures. + am_rc=0 + for am_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 + am_mf=`printf "%s\n" "$am_mf" | sed -e 's/:.*$//'` + # Check whether this is an Automake generated Makefile which includes + # dependency-tracking related rules and includes. + # Grep'ing the whole file directly is not great: 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 -n 's,^am--depfiles:.*,X,p' "$am_mf" | grep X >/dev/null 2>&1 \ + || continue + am_dirpart=`$as_dirname -- "$am_mf" || +$as_expr X"$am_mf" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$am_mf" : 'X\(//\)[^/]' \| \ + X"$am_mf" : 'X\(//\)$' \| \ + X"$am_mf" : 'X\(/\)' \| . 2>/dev/null || +printf "%s\n" X"$am_mf" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q @@ -21734,53 +22888,50 @@ 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\(\/\/\)[^/].*/{ + am_filepart=`$as_basename -- "$am_mf" || +$as_expr X/"$am_mf" : '.*/\([^/][^/]*\)/*$' \| \ + X"$am_mf" : 'X\(//\)$' \| \ + X"$am_mf" : 'X\(/\)' \| . 2>/dev/null || +printf "%s\n" X/"$am_mf" | + sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/ q } - /^X\(\/\/\)$/{ + /^X\/\(\/\/\)$/{ s//\1/ q } - /^X\(\/\).*/{ + /^X\/\(\/\).*/{ s//\1/ q } s/.*/./; q'` - as_dir=$dirpart/$fdir; as_fn_mkdir_p - # echo "creating $dirpart/$file" - echo '# dummy' > "$dirpart/$file" - done + { echo "$as_me:$LINENO: cd "$am_dirpart" \ + && sed -e '/# am--include-marker/d' "$am_filepart" \ + | $MAKE -f - am--depfiles" >&5 + (cd "$am_dirpart" \ + && sed -e '/# am--include-marker/d' "$am_filepart" \ + | $MAKE -f - am--depfiles) >&5 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } || am_rc=$? done + if test $am_rc -ne 0; then + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "Something went wrong bootstrapping makefile fragments + for automatic dependency tracking. If GNU make was not used, consider + re-running the configure script with MAKE=\"gmake\" (or whatever is + necessary). You can also try re-running configure with the + '--disable-dependency-tracking' option to at least be able to build + the package (albeit without support for automatic dependency tracking). +See \`config.log' for more details" "$LINENO" 5; } + fi + { am_dirpart=; unset am_dirpart;} + { am_filepart=; unset am_filepart;} + { am_mf=; unset am_mf;} + { am_rc=; unset am_rc;} + rm -f conftest-deps.mk } ;; "libtool":C) @@ -22310,6 +23461,7 @@ esac + ltmain=$ac_aux_dir/ltmain.sh @@ -22414,7 +23566,7 @@ ;; *) case $ac_arg in - *\'*) ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; + *\'*) ac_arg=`printf "%s\n" "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; esac as_fn_append ac_sub_configure_args " '$ac_arg'" ;; esac @@ -22424,7 +23576,7 @@ # in subdir configurations. ac_arg="--prefix=$prefix" case $ac_arg in - *\'*) ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; + *\'*) ac_arg=`printf "%s\n" "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; esac ac_sub_configure_args="'$ac_arg' $ac_sub_configure_args" @@ -22445,17 +23597,17 @@ 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: $ac_msg" >&5 + printf "%s\n" "$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|^\.[\\/]||'` + ac_dir_suffix=/`printf "%s\n" "$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|/||'` + ac_top_builddir_sub=`printf "%s\n" "$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/ ;; @@ -22485,17 +23637,15 @@ cd "$ac_dir" - # Check for guested configure; otherwise get Cygnus style configure. + # Check for configure.gnu first; this name is used for a wrapper for + # Metaconfig's "Configure" on case-insensitive file systems. 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;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: no configuration information is in $ac_dir" >&5 +printf "%s\n" "$as_me: WARNING: no configuration information is in $ac_dir" >&2;} ac_sub_configure= fi @@ -22508,8 +23658,8 @@ 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;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: running $SHELL $ac_sub_configure $ac_sub_configure_args --cache-file=$ac_sub_cache_file --srcdir=$ac_srcdir" >&5 +printf "%s\n" "$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\"" || @@ -22520,7 +23670,8 @@ 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;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5 +printf "%s\n" "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;} fi + diff -Nru cpl-7.1.4+ds/configure.ac cpl-7.2.2+ds/configure.ac --- cpl-7.1.4+ds/configure.ac 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/configure.ac 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ # Process this file with autoconf to produce a configure script. -AC_INIT([Common Pipeline Library], [7.1.4], [cpl-help@eso.org], [cpl]) +AC_INIT([Common Pipeline Library], [7.2.2], [cpl-help@eso.org], [cpl]) AC_PREREQ([2.59]) LT_PREREQ([2.2.6]) @@ -40,7 +40,7 @@ # Order of arguments: VERSION, CURRENT, REVISION, AGE -CPL_CONFIG_VERSION([$VERSION], [27], [4], [1]) +CPL_CONFIG_VERSION([$VERSION], [28], [2], [2]) # Checks for programs. AC_PROG_CC @@ -73,7 +73,6 @@ CPL_CHECK_FFTW([3.3.3]) # Checks for header files. -AC_HEADER_STDC AC_HEADER_TIOCGWINSZ AC_CHECK_HEADERS([fcntl.h stdlib.h string.h stropts.h sys/ioctl.h \ sys/stat.h sys/times.h sys/time.h sys/types.h \ @@ -84,7 +83,8 @@ AC_C_CONST AC_C_INLINE AC_C_BIGENDIAN -AC_C_LONG_DOUBLE + +AC_TYPE_LONG_DOUBLE CPL_CHECK_VA_ARGS CPL_CHECK_COMPLEX @@ -138,5 +138,6 @@ cplui/tests/Makefile cpldfs/Makefile cpldfs/tests/Makefile - cpljava/Makefile]) + cpljava/Makefile + cpljava/tests/Makefile]) AC_OUTPUT diff -Nru cpl-7.1.4+ds/cplcore/cpl_array.c cpl-7.2.2+ds/cplcore/cpl_array.c --- cpl-7.1.4+ds/cplcore/cpl_array.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_array.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -34,7 +34,6 @@ #include - /** * @defgroup cpl_array Arrays * @@ -53,7 +52,8 @@ * The array type (private); */ -struct _cpl_array_ { +struct _cpl_array_ +{ cpl_column *column; }; @@ -78,44 +78,45 @@ * allowed. */ -cpl_array *cpl_array_new(cpl_size length, cpl_type type) +cpl_array * +cpl_array_new(cpl_size length, cpl_type type) { cpl_column *column; - cpl_array *array; + cpl_array *array; - switch(type) { - case CPL_TYPE_INT: - column = cpl_column_new_int(length); - break; - case CPL_TYPE_LONG: - column = cpl_column_new_long(length); - break; - case CPL_TYPE_LONG_LONG: - column = cpl_column_new_long_long(length); - break; - case CPL_TYPE_SIZE: - column = cpl_column_new_cplsize(length); - break; - case CPL_TYPE_FLOAT: - column = cpl_column_new_float(length); - break; - case CPL_TYPE_DOUBLE: - column = cpl_column_new_double(length); - break; - case CPL_TYPE_FLOAT_COMPLEX: - column = cpl_column_new_float_complex(length); - break; - case CPL_TYPE_DOUBLE_COMPLEX: - column = cpl_column_new_double_complex(length); - break; - case CPL_TYPE_STRING: - column = cpl_column_new_string(length); - break; - default: - (void)cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, "%s", - cpl_type_get_name(type)); - return NULL; + switch (type) { + case CPL_TYPE_INT: + column = cpl_column_new_int(length); + break; + case CPL_TYPE_LONG: + column = cpl_column_new_long(length); + break; + case CPL_TYPE_LONG_LONG: + column = cpl_column_new_long_long(length); + break; + case CPL_TYPE_SIZE: + column = cpl_column_new_cplsize(length); + break; + case CPL_TYPE_FLOAT: + column = cpl_column_new_float(length); + break; + case CPL_TYPE_DOUBLE: + column = cpl_column_new_double(length); + break; + case CPL_TYPE_FLOAT_COMPLEX: + column = cpl_column_new_float_complex(length); + break; + case CPL_TYPE_DOUBLE_COMPLEX: + column = cpl_column_new_double_complex(length); + break; + case CPL_TYPE_STRING: + column = cpl_column_new_string(length); + break; + default: + (void)cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, "%s", + cpl_type_get_name(type)); + return NULL; } if (column == NULL) { @@ -143,17 +144,19 @@ * from the two input arrays, which must be of matching type and length. * For each row any invalid values are or'ed together to form the output value. */ -cpl_array *cpl_array_new_complex_from_arrays(const cpl_array * areal, - const cpl_array * aimag) +cpl_array * +cpl_array_new_complex_from_arrays(const cpl_array *areal, + const cpl_array *aimag) { - cpl_array *self = NULL; + cpl_array *self = NULL; cpl_column *cself; if (areal == NULL) { (void)cpl_error_set_(CPL_ERROR_NULL_INPUT); return NULL; - } else if (aimag == NULL) { + } + else if (aimag == NULL) { (void)cpl_error_set_(CPL_ERROR_NULL_INPUT); return NULL; } @@ -162,7 +165,8 @@ if (cself == NULL) { (void)cpl_error_set_where_(); - } else { + } + else { self = cpl_calloc(1, sizeof(cpl_array)); self->column = cself; } @@ -201,11 +205,11 @@ * only the @c cpl_array_unwrap() destructor can be used. */ -cpl_array *cpl_array_wrap_int(int *data, cpl_size length) +cpl_array * +cpl_array_wrap_int(int *data, cpl_size length) { - cpl_column *column; - cpl_array *array; + cpl_array *array; column = cpl_column_wrap_int(data, length); @@ -219,7 +223,6 @@ array->column = column; return array; - } @@ -254,11 +257,11 @@ * only the @c cpl_array_unwrap() destructor can be used. */ -cpl_array *cpl_array_wrap_long(long *data, cpl_size length) +cpl_array * +cpl_array_wrap_long(long *data, cpl_size length) { - cpl_column *column; - cpl_array *array; + cpl_array *array; column = cpl_column_wrap_long(data, length); @@ -272,7 +275,6 @@ array->column = column; return array; - } @@ -307,11 +309,11 @@ * only the @c cpl_array_unwrap() destructor can be used. */ -cpl_array *cpl_array_wrap_long_long(long long *data, cpl_size length) +cpl_array * +cpl_array_wrap_long_long(long long *data, cpl_size length) { - cpl_column *column; - cpl_array *array; + cpl_array *array; column = cpl_column_wrap_long_long(data, length); @@ -325,7 +327,6 @@ array->column = column; return array; - } @@ -360,11 +361,11 @@ * only the @c cpl_array_unwrap() destructor can be used. */ -cpl_array *cpl_array_wrap_cplsize(cpl_size *data, cpl_size length) +cpl_array * +cpl_array_wrap_cplsize(cpl_size *data, cpl_size length) { - cpl_column *column; - cpl_array *array; + cpl_array *array; column = cpl_column_wrap_cplsize(data, length); @@ -378,7 +379,6 @@ array->column = column; return array; - } @@ -394,11 +394,11 @@ * See documentation of function @c cpl_array_wrap_int(). */ -cpl_array *cpl_array_wrap_float(float *data, cpl_size length) +cpl_array * +cpl_array_wrap_float(float *data, cpl_size length) { - cpl_column *column; - cpl_array *array; + cpl_array *array; column = cpl_column_wrap_float(data, length); @@ -412,7 +412,6 @@ array->column = column; return array; - } @@ -428,11 +427,11 @@ * See documentation of function @c cpl_array_wrap_int(). */ -cpl_array *cpl_array_wrap_float_complex(float complex *data, cpl_size length) +cpl_array * +cpl_array_wrap_float_complex(float complex *data, cpl_size length) { - cpl_column *column; - cpl_array *array; + cpl_array *array; column = cpl_column_wrap_float_complex(data, length); @@ -446,7 +445,6 @@ array->column = column; return array; - } @@ -462,11 +460,11 @@ * See documentation of function @c cpl_array_wrap_int(). */ -cpl_array *cpl_array_wrap_double(double *data, cpl_size length) +cpl_array * +cpl_array_wrap_double(double *data, cpl_size length) { - cpl_column *column; - cpl_array *array; + cpl_array *array; column = cpl_column_wrap_double(data, length); @@ -480,7 +478,6 @@ array->column = column; return array; - } @@ -496,11 +493,11 @@ * See documentation of function @c cpl_array_wrap_int(). */ -cpl_array *cpl_array_wrap_double_complex(double complex *data, cpl_size length) +cpl_array * +cpl_array_wrap_double_complex(double complex *data, cpl_size length) { - cpl_column *column; - cpl_array *array; + cpl_array *array; column = cpl_column_wrap_double_complex(data, length); @@ -514,7 +511,6 @@ array->column = column; return array; - } @@ -530,11 +526,11 @@ * See documentation of function @c cpl_array_wrap_int(). */ -cpl_array *cpl_array_wrap_string(char **data, cpl_size length) +cpl_array * +cpl_array_wrap_string(char **data, cpl_size length) { - cpl_column *column; - cpl_array *array; + cpl_array *array; column = cpl_column_wrap_string(data, length); @@ -548,7 +544,6 @@ array->column = column; return array; - } @@ -574,9 +569,9 @@ * be copied. */ -cpl_error_code cpl_array_copy_data(cpl_array *array, const double *data) +cpl_error_code +cpl_array_copy_data(cpl_array *array, const double *data) { - if (data == NULL || array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -584,7 +579,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -610,10 +604,9 @@ * be copied. */ -cpl_error_code cpl_array_copy_data_complex(cpl_array *array, - const double complex *data) +cpl_error_code +cpl_array_copy_data_complex(cpl_array *array, const double complex *data) { - if (data == NULL || array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -621,7 +614,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -645,9 +637,9 @@ * array buffer. If the array had length zero, no values would be copied. */ -cpl_error_code cpl_array_copy_data_int(cpl_array *array, const int *data) +cpl_error_code +cpl_array_copy_data_int(cpl_array *array, const int *data) { - if (data == NULL || array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -655,7 +647,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -679,9 +670,9 @@ * array buffer. If the array had length zero, no values would be copied. */ -cpl_error_code cpl_array_copy_data_long(cpl_array *array, const long *data) +cpl_error_code +cpl_array_copy_data_long(cpl_array *array, const long *data) { - if (data == NULL || array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -689,7 +680,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -713,10 +703,9 @@ * array buffer. If the array had length zero, no values would be copied. */ -cpl_error_code cpl_array_copy_data_long_long(cpl_array *array, - const long long *data) +cpl_error_code +cpl_array_copy_data_long_long(cpl_array *array, const long long *data) { - if (data == NULL || array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -724,7 +713,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -748,10 +736,9 @@ * array buffer. If the array had length zero, no values would be copied. */ -cpl_error_code cpl_array_copy_data_cplsize(cpl_array *array, - const cpl_size *data) +cpl_error_code +cpl_array_copy_data_cplsize(cpl_array *array, const cpl_size *data) { - if (data == NULL || array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -759,7 +746,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -778,9 +764,9 @@ * See documentation of function @c cpl_array_copy_data_int(). */ -cpl_error_code cpl_array_copy_data_float(cpl_array *array, const float *data) +cpl_error_code +cpl_array_copy_data_float(cpl_array *array, const float *data) { - if (data == NULL || array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -788,7 +774,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -807,10 +792,9 @@ * See documentation of function @c cpl_array_copy_data_int(). */ -cpl_error_code cpl_array_copy_data_float_complex(cpl_array *array, - const float complex *data) +cpl_error_code +cpl_array_copy_data_float_complex(cpl_array *array, const float complex *data) { - if (data == NULL || array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -818,7 +802,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -837,9 +820,9 @@ * See documentation of function @c cpl_array_copy_data_int(). */ -cpl_error_code cpl_array_copy_data_double(cpl_array *array, const double *data) +cpl_error_code +cpl_array_copy_data_double(cpl_array *array, const double *data) { - if (data == NULL || array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -847,7 +830,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -866,10 +848,9 @@ * See documentation of function @c cpl_array_copy_data_int(). */ -cpl_error_code cpl_array_copy_data_double_complex(cpl_array *array, - const double complex *data) +cpl_error_code +cpl_array_copy_data_double_complex(cpl_array *array, const double complex *data) { - if (data == NULL || array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -877,7 +858,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -901,9 +881,9 @@ * are released before being overwritten. */ -cpl_error_code cpl_array_copy_data_string(cpl_array *array, const char **data) +cpl_error_code +cpl_array_copy_data_string(cpl_array *array, const char **data) { - if (data == NULL || array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -911,7 +891,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -927,14 +906,13 @@ * nothing is done, and no error is set. */ -void cpl_array_delete(cpl_array *array) +void +cpl_array_delete(cpl_array *array) { - if (array != NULL) { cpl_column_delete(array->column); cpl_free(array); } - } @@ -953,10 +931,10 @@ * If the input array is @c NULL, nothing is done, and no error is set. */ -void *cpl_array_unwrap(cpl_array *array) +void * +cpl_array_unwrap(cpl_array *array) { - - void *d = NULL; + void *d = NULL; if (array != NULL) { @@ -965,7 +943,6 @@ } return d; - } @@ -982,16 +959,15 @@ * If the array is @em NULL, zero is returned. */ -cpl_size cpl_array_get_size(const cpl_array *array) +cpl_size +cpl_array_get_size(const cpl_array *array) { - if (array) return cpl_column_get_size(array->column); cpl_error_set_(CPL_ERROR_NULL_INPUT); return 0; - } @@ -1019,7 +995,8 @@ * If the array is @em NULL, zero is returned. */ -cpl_error_code cpl_array_set_size(cpl_array *array, cpl_size new_length) +cpl_error_code +cpl_array_set_size(cpl_array *array, cpl_size new_length) { if (array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -1043,16 +1020,15 @@ * If the array is @c NULL, @c CPL_ERROR_NULL_INPUT is set. */ -cpl_type cpl_array_get_type(const cpl_array *array) +cpl_type +cpl_array_get_type(const cpl_array *array) { - if (array) return cpl_column_get_type(array->column); cpl_error_set("cpl_array_get_type", CPL_ERROR_NULL_INPUT); return CPL_TYPE_INVALID; - } @@ -1069,16 +1045,15 @@ * @c NULL pointer, a @c CPL_ERROR_NULL_INPUT is set. */ -int cpl_array_has_invalid(const cpl_array *array) +int +cpl_array_has_invalid(const cpl_array *array) { - if (array == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return -1; } return cpl_column_has_invalid(array->column); - } @@ -1095,16 +1070,15 @@ * @c NULL pointer, a @c CPL_ERROR_NULL_INPUT is set. */ -int cpl_array_has_valid(const cpl_array *array) +int +cpl_array_has_valid(const cpl_array *array) { - if (array == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return -1; } return cpl_column_has_valid(array->column); - } @@ -1121,16 +1095,15 @@ * a @c NULL pointer, an error @c CPL_ERROR_NULL_INPUT is set. */ -cpl_size cpl_array_count_invalid(const cpl_array *array) +cpl_size +cpl_array_count_invalid(const cpl_array *array) { - if (array == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return -1; } return cpl_column_count_invalid(array->column); - } @@ -1165,9 +1138,10 @@ * Check if an array element is valid. */ -int cpl_array_is_valid(const cpl_array *array, cpl_size indx) +int +cpl_array_is_valid(const cpl_array *array, cpl_size indx) { - int validity; + int validity; cpl_errorstate prevstate; @@ -1209,7 +1183,8 @@ * internally and the actual array data. */ -int *cpl_array_get_data_int(cpl_array *array) +int * +cpl_array_get_data_int(cpl_array *array) { /* Function body modified from below */ int *data = NULL; @@ -1243,9 +1218,9 @@ * @c CPL_ERROR_TYPE_MISMATCH is set. */ -const int *cpl_array_get_data_int_const(const cpl_array *array) +const int * +cpl_array_get_data_int_const(const cpl_array *array) { - const int *data = NULL; @@ -1260,7 +1235,6 @@ (void)cpl_error_set_where_(); return data; - } @@ -1284,7 +1258,8 @@ * internally and the actual array data. */ -long *cpl_array_get_data_long(cpl_array *array) +long * +cpl_array_get_data_long(cpl_array *array) { /* Function body modified from below */ long *data = NULL; @@ -1318,9 +1293,9 @@ * @c CPL_ERROR_TYPE_MISMATCH is set. */ -const long *cpl_array_get_data_long_const(const cpl_array *array) +const long * +cpl_array_get_data_long_const(const cpl_array *array) { - const long *data = NULL; @@ -1335,7 +1310,6 @@ (void)cpl_error_set_where_(); return data; - } @@ -1359,7 +1333,8 @@ * internally and the actual array data. */ -long long *cpl_array_get_data_long_long(cpl_array *array) +long long * +cpl_array_get_data_long_long(cpl_array *array) { /* Function body modified from below */ long long *data = NULL; @@ -1393,9 +1368,9 @@ * @c CPL_ERROR_TYPE_MISMATCH is set. */ -const long long *cpl_array_get_data_long_long_const(const cpl_array *array) +const long long * +cpl_array_get_data_long_long_const(const cpl_array *array) { - const long long *data = NULL; @@ -1410,7 +1385,6 @@ (void)cpl_error_set_where_(); return data; - } @@ -1434,7 +1408,8 @@ * internally and the actual array data. */ -cpl_size *cpl_array_get_data_cplsize(cpl_array *array) +cpl_size * +cpl_array_get_data_cplsize(cpl_array *array) { /* Function body modified from below */ cpl_size *data = NULL; @@ -1468,9 +1443,9 @@ * @c CPL_ERROR_TYPE_MISMATCH is set. */ -const cpl_size *cpl_array_get_data_cplsize_const(const cpl_array *array) +const cpl_size * +cpl_array_get_data_cplsize_const(const cpl_array *array) { - const cpl_size *data = NULL; @@ -1485,7 +1460,6 @@ (void)cpl_error_set_where_(); return data; - } @@ -1505,7 +1479,8 @@ * See documentation of function cpl_array_get_data_int(). */ -float *cpl_array_get_data_float(cpl_array *array) +float * +cpl_array_get_data_float(cpl_array *array) { /* Function body modified from below */ float *data = NULL; @@ -1541,9 +1516,9 @@ * See documentation of function cpl_array_get_data_int_const(). */ -const float *cpl_array_get_data_float_const(const cpl_array *array) +const float * +cpl_array_get_data_float_const(const cpl_array *array) { - const float *data = NULL; @@ -1558,7 +1533,6 @@ (void)cpl_error_set_where_(); return data; - } @@ -1578,7 +1552,8 @@ * See documentation of function cpl_array_get_data_int(). */ -float complex *cpl_array_get_data_float_complex(cpl_array *array) +float complex * +cpl_array_get_data_float_complex(cpl_array *array) { /* Function body modified from below */ float complex *data = NULL; @@ -1588,7 +1563,7 @@ (void)cpl_error_set_(CPL_ERROR_NULL_INPUT); return NULL; } - + data = cpl_column_get_data_float_complex(array->column); if (data == NULL) @@ -1618,7 +1593,6 @@ const float complex * cpl_array_get_data_float_complex_const(const cpl_array *array) { - const float complex *data = NULL; @@ -1626,14 +1600,13 @@ (void)cpl_error_set_(CPL_ERROR_NULL_INPUT); return NULL; } - + data = cpl_column_get_data_float_complex_const(array->column); if (data == NULL) (void)cpl_error_set_where_(); return data; - } @@ -1653,7 +1626,8 @@ * See documentation of function cpl_array_get_data_int(). */ -double *cpl_array_get_data_double(cpl_array *array) +double * +cpl_array_get_data_double(cpl_array *array) { /* Function body modified from below */ double *data = NULL; @@ -1670,7 +1644,6 @@ (void)cpl_error_set_where_(); return data; - } @@ -1690,9 +1663,9 @@ * See documentation of function cpl_array_get_data_int_const(). */ -const double *cpl_array_get_data_double_const(const cpl_array *array) +const double * +cpl_array_get_data_double_const(const cpl_array *array) { - const double *data = NULL; @@ -1707,7 +1680,6 @@ (void)cpl_error_set_where_(); return data; - } @@ -1727,7 +1699,8 @@ * See documentation of function cpl_array_get_data_int(). */ -double complex *cpl_array_get_data_double_complex(cpl_array *array) +double complex * +cpl_array_get_data_double_complex(cpl_array *array) { /* Function body modified from below */ double complex *data = NULL; @@ -1744,7 +1717,6 @@ (void)cpl_error_set_where_(); return data; - } @@ -1768,7 +1740,6 @@ const double complex * cpl_array_get_data_double_complex_const(const cpl_array *array) { - const double complex *data = NULL; @@ -1783,7 +1754,6 @@ (void)cpl_error_set_where_(); return data; - } @@ -1792,32 +1762,29 @@ * and listed in cpl_array_impl.h */ -const cpl_column *cpl_array_get_column_const(const cpl_array *array) +const cpl_column * +cpl_array_get_column_const(const cpl_array *array) { - if (array == NULL) { (void)cpl_error_set_(CPL_ERROR_NULL_INPUT); return NULL; } return array->column; - } -cpl_column *cpl_array_get_column(cpl_array *array) +cpl_column * +cpl_array_get_column(cpl_array *array) { - if (array == NULL) { (void)cpl_error_set_(CPL_ERROR_NULL_INPUT); return NULL; } return array->column; - } - /** * @internal * @brief Insert an existing cpl_column into the array, replacing any original @@ -1832,9 +1799,9 @@ * FIXME: May column be NULL ? */ -cpl_error_code cpl_array_set_column(cpl_array *array, cpl_column *column) +cpl_error_code +cpl_array_set_column(cpl_array *array, cpl_column *column) { - if (array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -1844,7 +1811,6 @@ array->column = column; return CPL_ERROR_NONE; - } @@ -1864,7 +1830,8 @@ * See documentation of function cpl_array_get_data_int(). */ -char **cpl_array_get_data_string(cpl_array *array) +char ** +cpl_array_get_data_string(cpl_array *array) { /* Function body modified from below */ char **data = NULL; @@ -1900,9 +1867,9 @@ * See documentation of function cpl_array_get_data_int(). */ -const char **cpl_array_get_data_string_const(const cpl_array *array) +const char ** +cpl_array_get_data_string_const(const cpl_array *array) { - const char **data = NULL; @@ -1917,7 +1884,6 @@ (void)cpl_error_set_where_(); return data; - } @@ -1943,9 +1909,9 @@ * condition (-1). The @em null argument can be left to @c NULL. */ -double cpl_array_get(const cpl_array *array, cpl_size indx, int *null) +double +cpl_array_get(const cpl_array *array, cpl_size indx, int *null) { - cpl_errorstate prestate = cpl_errorstate_get(); double data; @@ -1963,7 +1929,6 @@ cpl_error_set_where_(); return data; - } @@ -1989,10 +1954,9 @@ * condition (-1). The @em null argument can be left to @c NULL. */ -double complex cpl_array_get_complex(const cpl_array *array, - cpl_size indx, int *null) +double complex +cpl_array_get_complex(const cpl_array *array, cpl_size indx, int *null) { - cpl_errorstate prestate = cpl_errorstate_get(); double complex data; @@ -2010,7 +1974,6 @@ cpl_error_set_where_(); return data; - } @@ -2036,9 +1999,9 @@ * an error condition (-1). */ -int cpl_array_get_int(const cpl_array *array, cpl_size indx, int *null) +int +cpl_array_get_int(const cpl_array *array, cpl_size indx, int *null) { - cpl_errorstate prestate = cpl_errorstate_get(); int data = 0; @@ -2056,7 +2019,6 @@ cpl_error_set_where_(); return data; - } @@ -2082,9 +2044,9 @@ * an error condition (-1). */ -long cpl_array_get_long(const cpl_array *array, cpl_size indx, int *null) +long +cpl_array_get_long(const cpl_array *array, cpl_size indx, int *null) { - cpl_errorstate prestate = cpl_errorstate_get(); long data = 0; @@ -2102,7 +2064,6 @@ cpl_error_set_where_(); return data; - } @@ -2128,10 +2089,9 @@ * an error condition (-1). */ -long long cpl_array_get_long_long(const cpl_array *array, cpl_size indx, - int *null) +long long +cpl_array_get_long_long(const cpl_array *array, cpl_size indx, int *null) { - cpl_errorstate prestate = cpl_errorstate_get(); long long data = 0; @@ -2149,7 +2109,6 @@ cpl_error_set_where_(); return data; - } @@ -2175,10 +2134,9 @@ * an error condition (-1). */ -cpl_size cpl_array_get_cplsize(const cpl_array *array, cpl_size indx, - int *null) +cpl_size +cpl_array_get_cplsize(const cpl_array *array, cpl_size indx, int *null) { - cpl_errorstate prestate = cpl_errorstate_get(); cpl_size data = 0; @@ -2196,7 +2154,6 @@ cpl_error_set_where_(); return data; - } @@ -2215,9 +2172,9 @@ * documentation of the function cpl_array_get_int(). */ -float cpl_array_get_float(const cpl_array *array, cpl_size indx, int *null) +float +cpl_array_get_float(const cpl_array *array, cpl_size indx, int *null) { - cpl_errorstate prestate = cpl_errorstate_get(); float data; @@ -2235,7 +2192,6 @@ cpl_error_set_where_(); return data; - } @@ -2254,10 +2210,9 @@ * documentation of the function cpl_array_get_int(). */ -float complex cpl_array_get_float_complex(const cpl_array *array, - cpl_size indx, int *null) +float complex +cpl_array_get_float_complex(const cpl_array *array, cpl_size indx, int *null) { - cpl_errorstate prestate = cpl_errorstate_get(); float complex data; @@ -2275,7 +2230,6 @@ cpl_error_set_where_(); return data; - } @@ -2294,9 +2248,9 @@ * documentation of the function cpl_array_get_int(). */ -double cpl_array_get_double(const cpl_array *array, cpl_size indx, int *null) +double +cpl_array_get_double(const cpl_array *array, cpl_size indx, int *null) { - cpl_errorstate prestate = cpl_errorstate_get(); double data; @@ -2314,7 +2268,6 @@ cpl_error_set_where_(); return data; - } @@ -2333,10 +2286,9 @@ * documentation of the function cpl_array_get_int(). */ -double complex cpl_array_get_double_complex(const cpl_array *array, - cpl_size indx, int *null) +double complex +cpl_array_get_double_complex(const cpl_array *array, cpl_size indx, int *null) { - cpl_errorstate prestate = cpl_errorstate_get(); double complex data; @@ -2354,7 +2306,6 @@ cpl_error_set_where_(); return data; - } @@ -2384,9 +2335,9 @@ * argument of the function @c strdup(). */ -const char *cpl_array_get_string(const cpl_array *array, cpl_size indx) +const char * +cpl_array_get_string(const cpl_array *array, cpl_size indx) { - const char *data; @@ -2401,7 +2352,6 @@ cpl_error_set_where_(); return data; - } @@ -2426,9 +2376,9 @@ * Array elements are counted starting from 0. */ -cpl_error_code cpl_array_set(cpl_array *array, cpl_size indx, double value) +cpl_error_code +cpl_array_set(cpl_array *array, cpl_size indx, double value) { - if (array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -2436,7 +2386,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -2461,10 +2410,9 @@ * Array elements are counted starting from 0. */ -cpl_error_code cpl_array_set_complex(cpl_array *array, - cpl_size indx, double complex value) +cpl_error_code +cpl_array_set_complex(cpl_array *array, cpl_size indx, double complex value) { - if (array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -2472,7 +2420,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -2497,9 +2444,9 @@ * from 0. */ -cpl_error_code cpl_array_set_int(cpl_array *array, cpl_size indx, int value) +cpl_error_code +cpl_array_set_int(cpl_array *array, cpl_size indx, int value) { - if (array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -2507,7 +2454,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -2532,9 +2478,9 @@ * from 0. */ -cpl_error_code cpl_array_set_long(cpl_array *array, cpl_size indx, long value) +cpl_error_code +cpl_array_set_long(cpl_array *array, cpl_size indx, long value) { - if (array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -2542,7 +2488,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -2566,10 +2511,9 @@ * @c cpl_array_set_invalid(). Array elements are counted starting from 0. */ -cpl_error_code cpl_array_set_long_long(cpl_array *array, cpl_size indx, - long long value) +cpl_error_code +cpl_array_set_long_long(cpl_array *array, cpl_size indx, long long value) { - if (array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -2577,7 +2521,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -2601,10 +2544,9 @@ * @c cpl_array_set_invalid(). Array elements are counted starting from 0. */ -cpl_error_code cpl_array_set_cplsize(cpl_array *array, cpl_size indx, - cpl_size value) +cpl_error_code +cpl_array_set_cplsize(cpl_array *array, cpl_size indx, cpl_size value) { - if (array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -2612,7 +2554,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -2637,9 +2578,9 @@ * from 0. */ -cpl_error_code cpl_array_set_float(cpl_array *array, cpl_size indx, float value) +cpl_error_code +cpl_array_set_float(cpl_array *array, cpl_size indx, float value) { - if (array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -2647,7 +2588,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -2672,10 +2612,11 @@ * from 0. */ -cpl_error_code cpl_array_set_float_complex(cpl_array *array, - cpl_size indx, float complex value) +cpl_error_code +cpl_array_set_float_complex(cpl_array *array, + cpl_size indx, + float complex value) { - if (array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -2683,7 +2624,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -2708,10 +2648,9 @@ * from 0. */ -cpl_error_code cpl_array_set_double(cpl_array *array, - cpl_size indx, double value) +cpl_error_code +cpl_array_set_double(cpl_array *array, cpl_size indx, double value) { - if (array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -2719,7 +2658,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -2744,10 +2682,11 @@ * from 0. */ -cpl_error_code cpl_array_set_double_complex(cpl_array *array, cpl_size indx, - double complex value) +cpl_error_code +cpl_array_set_double_complex(cpl_array *array, + cpl_size indx, + double complex value) { - if (array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -2755,7 +2694,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -2782,10 +2720,9 @@ * Array elements are counted starting from zero. */ -cpl_error_code cpl_array_set_string(cpl_array *array, - cpl_size indx, const char *string) +cpl_error_code +cpl_array_set_string(cpl_array *array, cpl_size indx, const char *string) { - if (array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -2793,7 +2730,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -2815,9 +2751,9 @@ * counted starting from zero. */ -cpl_error_code cpl_array_set_invalid(cpl_array *array, cpl_size indx) +cpl_error_code +cpl_array_set_invalid(cpl_array *array, cpl_size indx) { - if (array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -2825,7 +2761,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -2850,10 +2785,12 @@ * valid. To invalidate an array interval use @c cpl_array_fill_window_invalid(). */ -cpl_error_code cpl_array_fill_window(cpl_array *array, cpl_size start, - cpl_size count, double value) +cpl_error_code +cpl_array_fill_window(cpl_array *array, + cpl_size start, + cpl_size count, + double value) { - if (array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -2861,7 +2798,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -2886,11 +2822,12 @@ * valid. To invalidate an array interval use @c cpl_array_fill_window_invalid(). */ -cpl_error_code cpl_array_fill_window_complex(cpl_array *array, - cpl_size start, cpl_size count, - double complex value) +cpl_error_code +cpl_array_fill_window_complex(cpl_array *array, + cpl_size start, + cpl_size count, + double complex value) { - if (array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -2898,7 +2835,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -2927,11 +2863,12 @@ * the array is not modified and no error is set. */ -cpl_error_code cpl_array_fill_window_int(cpl_array *array, - cpl_size start, cpl_size count, - int value) +cpl_error_code +cpl_array_fill_window_int(cpl_array *array, + cpl_size start, + cpl_size count, + int value) { - if (array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -2939,7 +2876,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -2968,11 +2904,12 @@ * the array is not modified and no error is set. */ -cpl_error_code cpl_array_fill_window_long(cpl_array *array, - cpl_size start, cpl_size count, - long value) +cpl_error_code +cpl_array_fill_window_long(cpl_array *array, + cpl_size start, + cpl_size count, + long value) { - if (array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -2980,7 +2917,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -3009,11 +2945,12 @@ * the array is not modified and no error is set. */ -cpl_error_code cpl_array_fill_window_long_long(cpl_array *array, - cpl_size start, cpl_size count, - long long value) +cpl_error_code +cpl_array_fill_window_long_long(cpl_array *array, + cpl_size start, + cpl_size count, + long long value) { - if (array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -3021,7 +2958,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -3050,11 +2986,12 @@ * modified and no error is set. */ -cpl_error_code cpl_array_fill_window_cplsize(cpl_array *array, - cpl_size start, cpl_size count, - cpl_size value) +cpl_error_code +cpl_array_fill_window_cplsize(cpl_array *array, + cpl_size start, + cpl_size count, + cpl_size value) { - if (array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -3062,7 +2999,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -3091,11 +3027,12 @@ * the array is not modified and no error is set. */ -cpl_error_code cpl_array_fill_window_float(cpl_array *array, - cpl_size start, cpl_size count, - float value) +cpl_error_code +cpl_array_fill_window_float(cpl_array *array, + cpl_size start, + cpl_size count, + float value) { - if (array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -3103,7 +3040,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -3132,12 +3068,12 @@ * the array is not modified and no error is set. */ -cpl_error_code cpl_array_fill_window_float_complex(cpl_array *array, - cpl_size start, - cpl_size count, - float complex value) +cpl_error_code +cpl_array_fill_window_float_complex(cpl_array *array, + cpl_size start, + cpl_size count, + float complex value) { - if (array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -3145,7 +3081,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -3174,11 +3109,12 @@ * the array is not modified and no error is set. */ -cpl_error_code cpl_array_fill_window_double(cpl_array *array, - cpl_size start, cpl_size count, - double value) +cpl_error_code +cpl_array_fill_window_double(cpl_array *array, + cpl_size start, + cpl_size count, + double value) { - if (array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -3186,7 +3122,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -3215,12 +3150,12 @@ * the array is not modified and no error is set. */ -cpl_error_code cpl_array_fill_window_double_complex(cpl_array *array, - cpl_size start, - cpl_size count, - double complex value) +cpl_error_code +cpl_array_fill_window_double_complex(cpl_array *array, + cpl_size start, + cpl_size count, + double complex value) { - if (array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -3228,7 +3163,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -3258,12 +3192,12 @@ * the array is not modified and no error is set. */ -cpl_error_code cpl_array_fill_window_string(cpl_array *array, - cpl_size start, - cpl_size count, - const char *value) +cpl_error_code +cpl_array_fill_window_string(cpl_array *array, + cpl_size start, + cpl_size count, + const char *value) { - if (array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -3271,7 +3205,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -3299,10 +3232,9 @@ * as invalid. */ -cpl_error_code cpl_array_fill_window_invalid(cpl_array *array, - cpl_size start, cpl_size count) +cpl_error_code +cpl_array_fill_window_invalid(cpl_array *array, cpl_size start, cpl_size count) { - if (array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -3310,7 +3242,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -3327,11 +3258,11 @@ * also the string elements are duplicated. */ -cpl_array *cpl_array_duplicate(const cpl_array *array) +cpl_array * +cpl_array_duplicate(const cpl_array *array) { - - cpl_column *column = NULL; - cpl_array *new_array; + cpl_column *column = NULL; + cpl_array *new_array; if (array == NULL) { @@ -3342,14 +3273,13 @@ if (array->column) column = cpl_column_duplicate(array->column); - new_array = cpl_array_new(cpl_array_get_size(array), - cpl_array_get_type(array)); + new_array = + cpl_array_new(cpl_array_get_size(array), cpl_array_get_type(array)); cpl_column_delete(new_array->column); new_array->column = column; return new_array; - } @@ -3392,12 +3322,11 @@ * the end of the input array, elements are copied up to the end. */ -cpl_array *cpl_array_extract(const cpl_array *array, - cpl_size start, cpl_size count) +cpl_array * +cpl_array_extract(const cpl_array *array, cpl_size start, cpl_size count) { - - cpl_size length = cpl_array_get_size(array); - cpl_array *new_array = NULL; + cpl_size length = cpl_array_get_size(array); + cpl_array *new_array = NULL; if (array == NULL) { @@ -3462,9 +3391,9 @@ * by the function @c cpl_array_duplicate(). */ -cpl_array *cpl_array_cast(const cpl_array *array, cpl_type type) +cpl_array * +cpl_array_cast(const cpl_array *array, cpl_type type) { - cpl_array *new_array = NULL; @@ -3499,11 +3428,12 @@ new_array->column = cpl_column_cast_to_double(array->column); break; case CPL_TYPE_DOUBLE_COMPLEX: - new_array->column = cpl_column_cast_to_double_complex(array->column); + new_array->column = + cpl_column_cast_to_double_complex(array->column); break; default: - cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); - break; + cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); + break; } if (!(new_array->column)) { @@ -3559,10 +3489,9 @@ * etc., should be discarded. */ -cpl_error_code cpl_array_insert_window(cpl_array *array, - cpl_size start, cpl_size count) +cpl_error_code +cpl_array_insert_window(cpl_array *array, cpl_size start, cpl_size count) { - if (array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -3570,7 +3499,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -3616,10 +3544,9 @@ * of the array. */ -cpl_error_code cpl_array_erase_window(cpl_array *array, - cpl_size start, cpl_size count) +cpl_error_code +cpl_array_erase_window(cpl_array *array, cpl_size start, cpl_size count) { - if (array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -3630,7 +3557,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -3677,10 +3603,11 @@ * should be discarded. */ -cpl_error_code cpl_array_insert(cpl_array *target_array, - const cpl_array *insert_array, cpl_size start) +cpl_error_code +cpl_array_insert(cpl_array *target_array, + const cpl_array *insert_array, + cpl_size start) { - if (target_array == NULL || insert_array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -3688,7 +3615,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -3733,10 +3659,9 @@ * overflows are ignored. */ -cpl_error_code cpl_array_add(cpl_array *to_array, - const cpl_array *from_array) +cpl_error_code +cpl_array_add(cpl_array *to_array, const cpl_array *from_array) { - if (to_array == NULL || from_array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -3744,7 +3669,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -3785,10 +3709,9 @@ * @c cpl_array_add() for further details. */ -cpl_error_code cpl_array_subtract(cpl_array *to_array, - const cpl_array *from_array) +cpl_error_code +cpl_array_subtract(cpl_array *to_array, const cpl_array *from_array) { - if (to_array == NULL || from_array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -3796,7 +3719,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -3837,10 +3759,9 @@ * @c cpl_array_add() for further details. */ -cpl_error_code cpl_array_multiply(cpl_array *to_array, - const cpl_array *from_array) +cpl_error_code +cpl_array_multiply(cpl_array *to_array, const cpl_array *from_array) { - if (to_array == NULL || from_array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -3848,7 +3769,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -3889,10 +3809,9 @@ * @c cpl_array_add() for further details. */ -cpl_error_code cpl_array_divide(cpl_array *to_array, - const cpl_array *from_array) +cpl_error_code +cpl_array_divide(cpl_array *to_array, const cpl_array *from_array) { - if (to_array == NULL || from_array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -3900,7 +3819,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -3935,9 +3853,9 @@ * are not modified by this operation. */ -cpl_error_code cpl_array_add_scalar(cpl_array *array, double value) +cpl_error_code +cpl_array_add_scalar(cpl_array *array, double value) { - if (array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -3945,7 +3863,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -3980,10 +3897,9 @@ * are not modified by this operation. */ -cpl_error_code cpl_array_add_scalar_complex(cpl_array *array, - double complex value) +cpl_error_code +cpl_array_add_scalar_complex(cpl_array *array, double complex value) { - if (array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -3991,7 +3907,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -4026,9 +3941,9 @@ * are not modified by this operation. */ -cpl_error_code cpl_array_subtract_scalar(cpl_array *array, double value) +cpl_error_code +cpl_array_subtract_scalar(cpl_array *array, double value) { - if (array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -4036,7 +3951,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -4071,10 +3985,9 @@ * are not modified by this operation. */ -cpl_error_code cpl_array_subtract_scalar_complex(cpl_array *array, - double complex value) +cpl_error_code +cpl_array_subtract_scalar_complex(cpl_array *array, double complex value) { - if (array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -4082,7 +3995,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -4117,9 +4029,9 @@ * are not modified by this operation. */ -cpl_error_code cpl_array_multiply_scalar(cpl_array *array, double value) +cpl_error_code +cpl_array_multiply_scalar(cpl_array *array, double value) { - if (array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -4127,7 +4039,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -4162,10 +4073,9 @@ * are not modified by this operation. */ -cpl_error_code cpl_array_multiply_scalar_complex(cpl_array *array, - double complex value) +cpl_error_code +cpl_array_multiply_scalar_complex(cpl_array *array, double complex value) { - if (array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -4173,7 +4083,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -4214,9 +4123,9 @@ * not modified by this operation. */ -cpl_error_code cpl_array_divide_scalar(cpl_array *array, double value) +cpl_error_code +cpl_array_divide_scalar(cpl_array *array, double value) { - if (array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -4224,7 +4133,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -4265,10 +4173,9 @@ * not modified by this operation. */ -cpl_error_code cpl_array_divide_scalar_complex(cpl_array *array, - double complex value) +cpl_error_code +cpl_array_divide_scalar_complex(cpl_array *array, double complex value) { - if (array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -4276,7 +4183,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -4315,16 +4221,14 @@ * overflow are marked as invalid. */ -cpl_error_code cpl_array_power(cpl_array *array, double exponent) +cpl_error_code +cpl_array_power(cpl_array *array, double exponent) { - if (array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); - return cpl_column_power(array->column, exponent) - ? cpl_error_set_where_() - : CPL_ERROR_NONE; - + return cpl_column_power(array->column, exponent) ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -4363,16 +4267,15 @@ * overflow are marked as invalid. */ -cpl_error_code cpl_array_power_complex(cpl_array *array, - double complex exponent) +cpl_error_code +cpl_array_power_complex(cpl_array *array, double complex exponent) { - if (array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); return cpl_column_power_complex(array->column, exponent) - ? cpl_error_set_where_() - : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -4416,9 +4319,9 @@ * very close to the origin may cause an overflow. */ -cpl_error_code cpl_array_logarithm(cpl_array *array, double base) +cpl_error_code +cpl_array_logarithm(cpl_array *array, double base) { - if (array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -4426,7 +4329,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -4468,9 +4370,9 @@ * modified by this operation. */ -cpl_error_code cpl_array_exponential(cpl_array *array, double base) +cpl_error_code +cpl_array_exponential(cpl_array *array, double base) { - if (array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -4478,7 +4380,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -4516,10 +4417,10 @@ * @c cpl_array_get_data_double_complex(), etc., should be discarded. */ -cpl_error_code cpl_array_abs(cpl_array *array) +cpl_error_code +cpl_array_abs(cpl_array *array) { - - cpl_type type; + cpl_type type; cpl_column *column; if (array == NULL) @@ -4540,7 +4441,6 @@ } return CPL_ERROR_NONE; - } @@ -4579,12 +4479,12 @@ * @c cpl_array_get_data_double_complex(), etc., should be discarded. */ -cpl_error_code cpl_array_arg(cpl_array *array) +cpl_error_code +cpl_array_arg(cpl_array *array) { - - cpl_type type; + cpl_type type; cpl_column *column; - + if (array == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -4598,19 +4498,18 @@ return cpl_error_set_where_(); } else { - int length = cpl_array_get_size(array); + int length = cpl_array_get_size(array); if (length) { switch (type) { - case CPL_TYPE_FLOAT: - { + case CPL_TYPE_FLOAT: { float *fdata = cpl_array_get_data_float(array); - memset(fdata, 0.0, length * sizeof(float)); // keeps the NULLs + memset(fdata, 0.0, + length * sizeof(float)); // keeps the NULLs break; } - case CPL_TYPE_DOUBLE: - { + case CPL_TYPE_DOUBLE: { double *ddata = cpl_array_get_data_double(array); memset(ddata, 0.0, length * sizeof(double)); @@ -4624,7 +4523,6 @@ } return CPL_ERROR_NONE; - } @@ -4659,12 +4557,12 @@ * if input is CPL_TYPE_DOUBLE_COMPLEX). */ -cpl_array *cpl_array_extract_real(const cpl_array *array) +cpl_array * +cpl_array_extract_real(const cpl_array *array) { - - cpl_type type; + cpl_type type; cpl_column *column; - cpl_array *new_array = NULL; + cpl_array *new_array = NULL; if (array == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -4676,7 +4574,7 @@ if (type & CPL_TYPE_COMPLEX) { column = cpl_column_extract_real(array->column); if (column) { - new_array = cpl_array_new(0, CPL_TYPE_FLOAT); // Irrelevant type + new_array = cpl_array_new(0, CPL_TYPE_FLOAT); // Irrelevant type cpl_array_set_column(new_array, column); } else { @@ -4690,7 +4588,6 @@ } return new_array; - } @@ -4725,12 +4622,12 @@ * if input is CPL_TYPE_DOUBLE_COMPLEX). */ -cpl_array *cpl_array_extract_imag(const cpl_array *array) +cpl_array * +cpl_array_extract_imag(const cpl_array *array) { - - cpl_type type; + cpl_type type; cpl_column *column; - cpl_array *new_array = NULL; + cpl_array *new_array = NULL; if (array == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -4742,7 +4639,7 @@ if (type & CPL_TYPE_COMPLEX) { column = cpl_column_extract_imag(array->column); if (column) { - new_array = cpl_array_new(0, CPL_TYPE_FLOAT); // Irrelevant type + new_array = cpl_array_new(0, CPL_TYPE_FLOAT); // Irrelevant type cpl_array_set_column(new_array, column); } else { @@ -4756,7 +4653,6 @@ } return new_array; - } @@ -4797,7 +4693,8 @@ * or complex are not allowed. */ -double cpl_array_get_mean(const cpl_array *array) +double +cpl_array_get_mean(const cpl_array *array) { cpl_errorstate prestate = cpl_errorstate_get(); double mean; @@ -4854,7 +4751,8 @@ * or numerical are not allowed. */ -double complex cpl_array_get_mean_complex(const cpl_array *array) +double complex +cpl_array_get_mean_complex(const cpl_array *array) { cpl_errorstate prestate = cpl_errorstate_get(); double complex mean; @@ -4911,7 +4809,8 @@ * or complex are not allowed. */ -double cpl_array_get_stdev(const cpl_array *array) +double +cpl_array_get_stdev(const cpl_array *array) { cpl_errorstate prestate = cpl_errorstate_get(); double sigma; @@ -4968,7 +4867,8 @@ * or complex are not allowed. */ -double cpl_array_get_median(const cpl_array *array) +double +cpl_array_get_median(const cpl_array *array) { cpl_errorstate prestate = cpl_errorstate_get(); double median; @@ -5025,7 +4925,8 @@ * or complex are not allowed. */ -double cpl_array_get_max(const cpl_array *array) +double +cpl_array_get_max(const cpl_array *array) { cpl_errorstate prestate = cpl_errorstate_get(); double max; @@ -5082,7 +4983,8 @@ * or complex are not allowed. */ -double cpl_array_get_min(const cpl_array *array) +double +cpl_array_get_min(const cpl_array *array) { cpl_errorstate prestate = cpl_errorstate_get(); double min; @@ -5143,9 +5045,9 @@ * Arrays of strings or complex are not allowed. */ -cpl_error_code cpl_array_get_maxpos(const cpl_array *array, cpl_size *indx) +cpl_error_code +cpl_array_get_maxpos(const cpl_array *array, cpl_size *indx) { - if (array == NULL || indx == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -5153,7 +5055,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -5198,9 +5099,9 @@ * Arrays of strings or complex are not allowed. */ -cpl_error_code cpl_array_get_minpos(const cpl_array *array, cpl_size *indx) +cpl_error_code +cpl_array_get_minpos(const cpl_array *array, cpl_size *indx) { - if (array == NULL || indx == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -5208,7 +5109,6 @@ return cpl_error_set_where_(); return CPL_ERROR_NONE; - } @@ -5232,9 +5132,9 @@ * used for printing is the standard C @c fprintf(). */ -void cpl_array_dump_structure(const cpl_array *array, FILE *stream) +void +cpl_array_dump_structure(const cpl_array *array, FILE *stream) { - if (stream == NULL) stream = stdout; @@ -5243,7 +5143,7 @@ return; } - fprintf(stream, "Array with %" CPL_SIZE_FORMAT, + fprintf(stream, "Array with %" CPL_SIZE_FORMAT, cpl_column_get_size(array->column)); switch (cpl_column_get_type(array->column)) { @@ -5279,8 +5179,8 @@ break; } - fprintf(stream, "elements, of which %" CPL_SIZE_FORMAT - " are flagged invalid.\n", + fprintf(stream, + "elements, of which %" CPL_SIZE_FORMAT " are flagged invalid.\n", cpl_column_count_invalid(array->column)); } @@ -5308,10 +5208,12 @@ * The function used for printing is the standard C @c fprintf(). */ -void cpl_array_dump(const cpl_array *array, - cpl_size start, cpl_size count, FILE *stream) +void +cpl_array_dump(const cpl_array *array, + cpl_size start, + cpl_size count, + FILE *stream) { - cpl_size size; char **fields; char *row_field; @@ -5363,8 +5265,7 @@ for (j = 0; j < nc; j++) { label_len[j] = field_size[j] = strlen("Array"); switch (cpl_column_get_type(array->column)) { - case CPL_TYPE_INT: - { + case CPL_TYPE_INT: { for (i = start; i < end; i++) { int inum = cpl_column_get_int(array->column, i, &null); @@ -5372,16 +5273,15 @@ size = 4; else size = cx_snprintf(NULL, 0, - cpl_column_get_format(array->column), - inum); + cpl_column_get_format(array->column), + inum); if (size > field_size[j]) field_size[j] = size; } break; } - case CPL_TYPE_LONG: - { + case CPL_TYPE_LONG: { for (i = start; i < end; i++) { long lnum = cpl_column_get_long(array->column, i, &null); @@ -5389,52 +5289,49 @@ size = 4; else size = cx_snprintf(NULL, 0, - cpl_column_get_format(array->column), - lnum); + cpl_column_get_format(array->column), + lnum); if (size > field_size[j]) field_size[j] = size; } break; } - case CPL_TYPE_LONG_LONG: - { + case CPL_TYPE_LONG_LONG: { for (i = start; i < end; i++) { long long lnum = - cpl_column_get_long_long(array->column, i, &null); + cpl_column_get_long_long(array->column, i, &null); if (null) size = 4; else size = cx_snprintf(NULL, 0, - cpl_column_get_format(array->column), - lnum); + cpl_column_get_format(array->column), + lnum); if (size > field_size[j]) field_size[j] = size; } break; } - case CPL_TYPE_SIZE: - { + case CPL_TYPE_SIZE: { for (i = start; i < end; i++) { - cpl_size snum = cpl_column_get_cplsize(array->column, - i, &null); + cpl_size snum = + cpl_column_get_cplsize(array->column, i, &null); if (null) size = 4; else size = cx_snprintf(NULL, 0, - cpl_column_get_format(array->column), - snum); + cpl_column_get_format(array->column), + snum); if (size > field_size[j]) field_size[j] = size; } break; } - case CPL_TYPE_FLOAT: - { + case CPL_TYPE_FLOAT: { for (i = start; i < end; i++) { float fnum = cpl_column_get_float(array->column, i, &null); @@ -5442,87 +5339,84 @@ size = 4; else size = cx_snprintf(NULL, 0, - cpl_column_get_format(array->column), - fnum); + cpl_column_get_format(array->column), + fnum); if (size > field_size[j]) field_size[j] = size; } break; } - case CPL_TYPE_DOUBLE: - { + case CPL_TYPE_DOUBLE: { for (i = start; i < end; i++) { - double dnum = cpl_column_get_double(array->column, i, &null); + double dnum = + cpl_column_get_double(array->column, i, &null); if (null) size = 4; else size = cx_snprintf(NULL, 0, - cpl_column_get_format(array->column), - dnum); + cpl_column_get_format(array->column), + dnum); if (size > field_size[j]) field_size[j] = size; } break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { for (i = start; i < end; i++) { float complex cfnum = - cpl_column_get_float_complex(array->column, - i, &null); + cpl_column_get_float_complex(array->column, i, &null); if (null) size = 4; else - size = 3 + cx_snprintf(NULL, 0, - cpl_column_get_format(array->column), - crealf(cfnum)) - + cx_snprintf(NULL, 0, - cpl_column_get_format(array->column), - cimagf(cfnum)); + size = 3 + + cx_snprintf(NULL, 0, + cpl_column_get_format(array->column), + crealf(cfnum)) + + cx_snprintf(NULL, 0, + cpl_column_get_format(array->column), + cimagf(cfnum)); if (size > field_size[j]) field_size[j] = size; } break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { for (i = start; i < end; i++) { double complex cdnum = - cpl_column_get_double_complex(array->column, - i, &null); + cpl_column_get_double_complex(array->column, i, &null); if (null) size = 4; else - size = 3 + cx_snprintf(NULL, 0, - cpl_column_get_format(array->column), - creal(cdnum)) - + cx_snprintf(NULL, 0, - cpl_column_get_format(array->column), - cimag(cdnum)); + size = 3 + + cx_snprintf(NULL, 0, + cpl_column_get_format(array->column), + creal(cdnum)) + + cx_snprintf(NULL, 0, + cpl_column_get_format(array->column), + cimag(cdnum)); if (size > field_size[j]) field_size[j] = size; } break; } - case CPL_TYPE_STRING: - { + case CPL_TYPE_STRING: { for (i = start; i < end; i++) { char *string = - (char *)cpl_column_get_string(array->column, i); + (char *)cpl_column_get_string(array->column, i); if (string == NULL) size = 4; else size = cx_snprintf(NULL, 0, - cpl_column_get_format(array->column), - string); + cpl_column_get_format(array->column), + string); if (size > field_size[j]) field_size[j] = size; @@ -5538,7 +5432,6 @@ label_len[j]++; fields[j] = cpl_malloc(field_size[j] * sizeof(char)); - } fprintf(stream, "%s ", row_field); @@ -5561,8 +5454,7 @@ fprintf(stream, "%*" CPL_SIZE_FORMAT " ", row, i); for (j = 0; j < nc; j++) { switch (cpl_column_get_type(array->column)) { - case CPL_TYPE_INT: - { + case CPL_TYPE_INT: { int inum = cpl_column_get_int(array->column, i, &null); if (null) { @@ -5571,11 +5463,10 @@ } else cx_snprintf(fields[j], field_size[j], - cpl_column_get_format(array->column), inum); + cpl_column_get_format(array->column), inum); break; } - case CPL_TYPE_LONG: - { + case CPL_TYPE_LONG: { long lnum = cpl_column_get_long(array->column, i, &null); if (null) { @@ -5584,13 +5475,12 @@ } else cx_snprintf(fields[j], field_size[j], - cpl_column_get_format(array->column), lnum); + cpl_column_get_format(array->column), lnum); break; } - case CPL_TYPE_LONG_LONG: - { - long long lnum = cpl_column_get_long_long(array->column, - i, &null); + case CPL_TYPE_LONG_LONG: { + long long lnum = + cpl_column_get_long_long(array->column, i, &null); if (null) { memset(fields[j], '-', field_size[j]); @@ -5598,13 +5488,12 @@ } else cx_snprintf(fields[j], field_size[j], - cpl_column_get_format(array->column), lnum); + cpl_column_get_format(array->column), lnum); break; } - case CPL_TYPE_SIZE: - { - cpl_size snum = cpl_column_get_cplsize(array->column, - i, &null); + case CPL_TYPE_SIZE: { + cpl_size snum = + cpl_column_get_cplsize(array->column, i, &null); if (null) { memset(fields[j], '-', field_size[j]); @@ -5612,11 +5501,10 @@ } else cx_snprintf(fields[j], field_size[j], - cpl_column_get_format(array->column), snum); + cpl_column_get_format(array->column), snum); break; } - case CPL_TYPE_FLOAT: - { + case CPL_TYPE_FLOAT: { float fnum = cpl_column_get_float(array->column, i, &null); if (null) { @@ -5625,12 +5513,12 @@ } else cx_snprintf(fields[j], field_size[j], - cpl_column_get_format(array->column), fnum); + cpl_column_get_format(array->column), fnum); break; } - case CPL_TYPE_DOUBLE: - { - double dnum = cpl_column_get_double(array->column, i, &null); + case CPL_TYPE_DOUBLE: { + double dnum = + cpl_column_get_double(array->column, i, &null); if (null) { memset(fields[j], '-', field_size[j]); @@ -5638,55 +5526,52 @@ } else cx_snprintf(fields[j], field_size[j], - cpl_column_get_format(array->column), dnum); + cpl_column_get_format(array->column), dnum); break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex cfnum = - cpl_column_get_float_complex(array->column, - i, &null); + cpl_column_get_float_complex(array->column, i, &null); if (null) { memset(fields[j], '-', field_size[j]); fields[j][field_size[j] - 1] = '\0'; } else { - char *s = cpl_sprintf("(%s,%s)", - cpl_column_get_format(array->column), - cpl_column_get_format(array->column)); + char *s = + cpl_sprintf("(%s,%s)", + cpl_column_get_format(array->column), + cpl_column_get_format(array->column)); - cx_snprintf(fields[j], field_size[j], s, - crealf(cfnum), cimagf(cfnum)); + cx_snprintf(fields[j], field_size[j], s, crealf(cfnum), + cimagf(cfnum)); cpl_free(s); } break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex cdnum = - cpl_column_get_double_complex(array->column, - i, &null); + cpl_column_get_double_complex(array->column, i, &null); if (null) { memset(fields[j], '-', field_size[j]); fields[j][field_size[j] - 1] = '\0'; } else { - char *s = cpl_sprintf("(%s,%s)", - cpl_column_get_format(array->column), - cpl_column_get_format(array->column)); + char *s = + cpl_sprintf("(%s,%s)", + cpl_column_get_format(array->column), + cpl_column_get_format(array->column)); - cx_snprintf(fields[j], field_size[j], s, - creal(cdnum), cimag(cdnum)); + cx_snprintf(fields[j], field_size[j], s, creal(cdnum), + cimag(cdnum)); cpl_free(s); } break; } - case CPL_TYPE_STRING: - { + case CPL_TYPE_STRING: { char *string = - (char *)cpl_column_get_string(array->column, i); + (char *)cpl_column_get_string(array->column, i); if (!string) { memset(fields[j], '-', field_size[j]); @@ -5694,11 +5579,11 @@ } else cx_snprintf(fields[j], field_size[j], - cpl_column_get_format(array->column), string); + cpl_column_get_format(array->column), + string); break; } - default: - { + default: { cpl_array *_array = cpl_column_get_array(array->column, i); if (!_array) { @@ -5713,10 +5598,10 @@ found = 0; for (k = 0; k < field_size[j]; k++) { - if (fields[j][k] == '\0') - found = 1; - if (found) - fields[j][k] = ' '; + if (fields[j][k] == '\0') + found = 1; + if (found) + fields[j][k] = ' '; } fields[j][field_size[j] - 1] = '\0'; fprintf(stream, "%-*s ", field_size[j], fields[j]); @@ -5725,12 +5610,11 @@ } for (j = 0; j < nc; j++) - cpl_free(fields[j]); + cpl_free(fields[j]); cpl_free(fields); cpl_free(row_field); cpl_free(label_len); cpl_free(field_size); - } /* @@ -5740,11 +5624,12 @@ * @return Nothing. * @see cpl_matrix_decomp_lu() */ -void cpl_array_init_perm(cpl_array* self) +void +cpl_array_init_perm(cpl_array *self) { - cpl_column * cself = cpl_array_get_column(self); - int * iself = cpl_column_get_data_int(cself); - const size_t n = (size_t)cpl_column_get_size(cself); + cpl_column *cself = cpl_array_get_column(self); + int *iself = cpl_column_get_data_int(cself); + const size_t n = (size_t)cpl_column_get_size(cself); assert(iself != NULL); diff -Nru cpl-7.1.4+ds/cplcore/cpl_array.h cpl-7.2.2+ds/cplcore/cpl_array.h --- cpl-7.1.4+ds/cplcore/cpl_array.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_array.h 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -22,7 +22,8 @@ #include #if ((defined(__STDC_IEC_559_COMPLEX__) || (__STDC_VERSION__ >= 199901L) || \ - (__GNUC__ >= 3)) && !defined(__cplusplus)) + (__GNUC__ >= 3)) && \ + !defined(__cplusplus)) #include #endif #include @@ -34,29 +35,20 @@ typedef struct _cpl_array_ cpl_array; -cpl_array *cpl_array_new(cpl_size, cpl_type) - CPL_ATTR_ALLOC; -cpl_array *cpl_array_wrap_int(int *, cpl_size) - CPL_ATTR_ALLOC; -cpl_array *cpl_array_wrap_long(long *, cpl_size) - CPL_ATTR_ALLOC; -cpl_array *cpl_array_wrap_long_long(long long *, cpl_size) - CPL_ATTR_ALLOC; -cpl_array *cpl_array_wrap_cplsize(cpl_size *, cpl_size) - CPL_ATTR_ALLOC; -cpl_array *cpl_array_wrap_float(float *, cpl_size) - CPL_ATTR_ALLOC; -cpl_array *cpl_array_wrap_double(double *, cpl_size) - CPL_ATTR_ALLOC; -cpl_array *cpl_array_wrap_float_complex(_Complex float *, cpl_size) - CPL_ATTR_ALLOC; -cpl_array *cpl_array_wrap_double_complex(_Complex double *, cpl_size) - CPL_ATTR_ALLOC; -cpl_array *cpl_array_wrap_string(char **, cpl_size) - CPL_ATTR_ALLOC; +cpl_array *cpl_array_new(cpl_size, cpl_type) CPL_ATTR_ALLOC; +cpl_array *cpl_array_wrap_int(int *, cpl_size) CPL_ATTR_ALLOC; +cpl_array *cpl_array_wrap_long(long *, cpl_size) CPL_ATTR_ALLOC; +cpl_array *cpl_array_wrap_long_long(long long *, cpl_size) CPL_ATTR_ALLOC; +cpl_array *cpl_array_wrap_cplsize(cpl_size *, cpl_size) CPL_ATTR_ALLOC; +cpl_array *cpl_array_wrap_float(float *, cpl_size) CPL_ATTR_ALLOC; +cpl_array *cpl_array_wrap_double(double *, cpl_size) CPL_ATTR_ALLOC; +cpl_array * +cpl_array_wrap_float_complex(_Complex float *, cpl_size) CPL_ATTR_ALLOC; +cpl_array * +cpl_array_wrap_double_complex(_Complex double *, cpl_size) CPL_ATTR_ALLOC; +cpl_array *cpl_array_wrap_string(char **, cpl_size) CPL_ATTR_ALLOC; cpl_array *cpl_array_new_complex_from_arrays(const cpl_array *, - const cpl_array *) - CPL_ATTR_ALLOC; + const cpl_array *) CPL_ATTR_ALLOC; cpl_error_code cpl_array_copy_data(cpl_array *, const double *); cpl_error_code cpl_array_copy_data_int(cpl_array *, const int *); @@ -66,11 +58,12 @@ cpl_error_code cpl_array_copy_data_float(cpl_array *, const float *); cpl_error_code cpl_array_copy_data_double(cpl_array *, const double *); cpl_error_code cpl_array_copy_data_string(cpl_array *, const char **); -cpl_error_code cpl_array_copy_data_complex(cpl_array *, const _Complex double *); -cpl_error_code cpl_array_copy_data_float_complex(cpl_array *, - const _Complex float *); -cpl_error_code cpl_array_copy_data_double_complex(cpl_array *, - const _Complex double *); +cpl_error_code +cpl_array_copy_data_complex(cpl_array *, const _Complex double *); +cpl_error_code +cpl_array_copy_data_float_complex(cpl_array *, const _Complex float *); +cpl_error_code +cpl_array_copy_data_double_complex(cpl_array *, const _Complex double *); void cpl_array_delete(cpl_array *); void *cpl_array_unwrap(cpl_array *); cpl_size cpl_array_get_size(const cpl_array *); @@ -94,8 +87,8 @@ const double *cpl_array_get_data_double_const(const cpl_array *); _Complex float *cpl_array_get_data_float_complex(cpl_array *); const _Complex float *cpl_array_get_data_float_complex_const(const cpl_array *); -const _Complex double *cpl_array_get_data_double_complex_const - (const cpl_array *); +const _Complex double * +cpl_array_get_data_double_complex_const(const cpl_array *); _Complex double *cpl_array_get_data_double_complex(cpl_array *); char **cpl_array_get_data_string(cpl_array *); const char **cpl_array_get_data_string_const(const cpl_array *); @@ -109,7 +102,8 @@ const char *cpl_array_get_string(const cpl_array *, cpl_size); _Complex double cpl_array_get_complex(const cpl_array *, cpl_size, int *); _Complex float cpl_array_get_float_complex(const cpl_array *, cpl_size, int *); -_Complex double cpl_array_get_double_complex(const cpl_array *, cpl_size, int *); +_Complex double +cpl_array_get_double_complex(const cpl_array *, cpl_size, int *); cpl_error_code cpl_array_set(cpl_array *array, cpl_size, double); cpl_error_code cpl_array_set_int(cpl_array *, cpl_size, int); cpl_error_code cpl_array_set_long(cpl_array *, cpl_size, long); @@ -120,37 +114,46 @@ cpl_error_code cpl_array_set_string(cpl_array *, cpl_size, const char *); cpl_error_code cpl_array_set_invalid(cpl_array *, cpl_size); cpl_error_code cpl_array_set_complex(cpl_array *, cpl_size, _Complex double); -cpl_error_code cpl_array_set_float_complex(cpl_array *, cpl_size, _Complex float); -cpl_error_code cpl_array_set_double_complex(cpl_array *, cpl_size, _Complex double); +cpl_error_code +cpl_array_set_float_complex(cpl_array *, cpl_size, _Complex float); +cpl_error_code +cpl_array_set_double_complex(cpl_array *, cpl_size, _Complex double); cpl_error_code cpl_array_fill_window(cpl_array *, cpl_size, cpl_size, double); cpl_error_code cpl_array_fill_window_int(cpl_array *, cpl_size, cpl_size, int); -cpl_error_code cpl_array_fill_window_long(cpl_array *, cpl_size, cpl_size, long); -cpl_error_code cpl_array_fill_window_long_long(cpl_array *, cpl_size, cpl_size, - long long); -cpl_error_code cpl_array_fill_window_cplsize(cpl_array *, cpl_size, cpl_size, - cpl_size); -cpl_error_code cpl_array_fill_window_float(cpl_array *, cpl_size, cpl_size, float); -cpl_error_code cpl_array_fill_window_double(cpl_array *, cpl_size, cpl_size, double); -cpl_error_code cpl_array_fill_window_string(cpl_array *, cpl_size, cpl_size, - const char *); -cpl_error_code cpl_array_fill_window_complex(cpl_array *, - cpl_size, cpl_size, _Complex double); -cpl_error_code cpl_array_fill_window_float_complex(cpl_array *, cpl_size, cpl_size, +cpl_error_code +cpl_array_fill_window_long(cpl_array *, cpl_size, cpl_size, long); +cpl_error_code +cpl_array_fill_window_long_long(cpl_array *, cpl_size, cpl_size, long long); +cpl_error_code +cpl_array_fill_window_cplsize(cpl_array *, cpl_size, cpl_size, cpl_size); +cpl_error_code +cpl_array_fill_window_float(cpl_array *, cpl_size, cpl_size, float); +cpl_error_code +cpl_array_fill_window_double(cpl_array *, cpl_size, cpl_size, double); +cpl_error_code +cpl_array_fill_window_string(cpl_array *, cpl_size, cpl_size, const char *); +cpl_error_code +cpl_array_fill_window_complex(cpl_array *, cpl_size, cpl_size, _Complex double); +cpl_error_code cpl_array_fill_window_float_complex(cpl_array *, + cpl_size, + cpl_size, _Complex float); -cpl_error_code cpl_array_fill_window_double_complex(cpl_array *, cpl_size, cpl_size, +cpl_error_code cpl_array_fill_window_double_complex(cpl_array *, + cpl_size, + cpl_size, _Complex double); cpl_error_code cpl_array_fill_window_invalid(cpl_array *, cpl_size, cpl_size); -cpl_array *cpl_array_duplicate(const cpl_array *) - CPL_ATTR_ALLOC; -cpl_array *cpl_array_extract(const cpl_array *, cpl_size start, cpl_size count) - CPL_ATTR_ALLOC; -cpl_array *cpl_array_extract_real(const cpl_array *) - CPL_ATTR_ALLOC; -cpl_array *cpl_array_extract_imag(const cpl_array *) - CPL_ATTR_ALLOC; -cpl_error_code cpl_array_insert_window(cpl_array *, cpl_size start, cpl_size count); -cpl_error_code cpl_array_erase_window(cpl_array *, cpl_size start, cpl_size count); +cpl_array *cpl_array_duplicate(const cpl_array *) CPL_ATTR_ALLOC; +cpl_array *cpl_array_extract(const cpl_array *, + cpl_size start, + cpl_size count) CPL_ATTR_ALLOC; +cpl_array *cpl_array_extract_real(const cpl_array *) CPL_ATTR_ALLOC; +cpl_array *cpl_array_extract_imag(const cpl_array *) CPL_ATTR_ALLOC; +cpl_error_code +cpl_array_insert_window(cpl_array *, cpl_size start, cpl_size count); +cpl_error_code +cpl_array_erase_window(cpl_array *, cpl_size start, cpl_size count); cpl_error_code cpl_array_insert(cpl_array *, const cpl_array *, cpl_size); cpl_error_code cpl_array_add(cpl_array *, const cpl_array *); @@ -183,11 +186,9 @@ cpl_error_code cpl_array_get_minpos(const cpl_array *, cpl_size *); void cpl_array_dump_structure(const cpl_array *, FILE *); void cpl_array_dump(const cpl_array *, cpl_size start, cpl_size count, FILE *); -cpl_array *cpl_array_cast(const cpl_array *, cpl_type) - CPL_ATTR_ALLOC; +cpl_array *cpl_array_cast(const cpl_array *, cpl_type) CPL_ATTR_ALLOC; CPL_END_DECLS #endif /* end of cpl_array.h */ - diff -Nru cpl-7.1.4+ds/cplcore/cpl_array_impl.h cpl-7.2.2+ds/cplcore/cpl_array_impl.h --- cpl-7.1.4+ds/cplcore/cpl_array_impl.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_array_impl.h 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -22,13 +22,13 @@ #include "cpl_column.h" #include "cpl_array.h" - + CPL_BEGIN_DECLS cpl_column *cpl_array_get_column(cpl_array *); const cpl_column *cpl_array_get_column_const(const cpl_array *); cpl_error_code cpl_array_set_column(cpl_array *, cpl_column *); -void cpl_array_init_perm(cpl_array*) CPL_ATTR_NONNULL CPL_INTERNAL; +void cpl_array_init_perm(cpl_array *) CPL_ATTR_NONNULL CPL_INTERNAL; CPL_END_DECLS diff -Nru cpl-7.1.4+ds/cplcore/cpl_bivector.c cpl-7.2.2+ds/cplcore/cpl_bivector.c --- cpl-7.1.4+ds/cplcore/cpl_bivector.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_bivector.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -39,7 +39,7 @@ Define -----------------------------------------------------------------------------*/ -#define HALF_CENTROID_DOMAIN 5 +#define HALF_CENTROID_DOMAIN 5 /*----------------------------------------------------------------------------*/ /** @@ -66,9 +66,10 @@ Type definition -----------------------------------------------------------------------------*/ -struct _cpl_bivector_ { - cpl_vector * x; - cpl_vector * y; +struct _cpl_bivector_ +{ + cpl_vector *x; + cpl_vector *y; }; /*----------------------------------------------------------------------------- @@ -89,9 +90,10 @@ - CPL_ERROR_ILLEGAL_INPUT if n is < 1. */ /*----------------------------------------------------------------------------*/ -cpl_bivector * cpl_bivector_new(cpl_size n) +cpl_bivector * +cpl_bivector_new(cpl_size n) { - cpl_bivector * f; + cpl_bivector *f; /* Test input */ cpl_ensure(n > 0, CPL_ERROR_ILLEGAL_INPUT, NULL); @@ -124,18 +126,17 @@ - CPL_ERROR_ILLEGAL_INPUT if the input vectors have different sizes */ /*----------------------------------------------------------------------------*/ -cpl_bivector * cpl_bivector_wrap_vectors( - cpl_vector * x, - cpl_vector * y) +cpl_bivector * +cpl_bivector_wrap_vectors(cpl_vector *x, cpl_vector *y) { - cpl_bivector * f; + cpl_bivector *f; /* Test input */ cpl_ensure(x, CPL_ERROR_NULL_INPUT, NULL); cpl_ensure(y, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(cpl_vector_get_size(x)==cpl_vector_get_size(y), - CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(cpl_vector_get_size(x) == cpl_vector_get_size(y), + CPL_ERROR_ILLEGAL_INPUT, NULL); /* Allocate memory */ f = cpl_malloc(sizeof(cpl_bivector)); @@ -159,12 +160,13 @@ different sizes */ /*----------------------------------------------------------------------------*/ -cpl_bivector * cpl_bivector_duplicate(const cpl_bivector * in) +cpl_bivector * +cpl_bivector_duplicate(const cpl_bivector *in) { - cpl_bivector * out; + cpl_bivector *out; cpl_ensure(in, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(cpl_vector_get_size(in->x)==cpl_vector_get_size(in->y), + cpl_ensure(cpl_vector_get_size(in->x) == cpl_vector_get_size(in->y), CPL_ERROR_ILLEGAL_INPUT, NULL); out = cpl_malloc(sizeof(cpl_bivector)); @@ -186,14 +188,15 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_bivector_copy(cpl_bivector * self, - const cpl_bivector * other) +cpl_error_code +cpl_bivector_copy(cpl_bivector *self, const cpl_bivector *other) { return cpl_vector_copy(cpl_bivector_get_x(self), cpl_bivector_get_x_const(other)) || - cpl_vector_copy(cpl_bivector_get_y(self), - cpl_bivector_get_y_const(other)) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + cpl_vector_copy(cpl_bivector_get_y(self), + cpl_bivector_get_y_const(other)) + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } /*----------------------------------------------------------------------------*/ @@ -208,9 +211,11 @@ */ /*----------------------------------------------------------------------------*/ -void cpl_bivector_delete(cpl_bivector * f) +void +cpl_bivector_delete(cpl_bivector *f) { - if (f == NULL) return; + if (f == NULL) + return; cpl_vector_delete(f->x); cpl_vector_delete(f->y); cpl_free(f); @@ -226,7 +231,8 @@ */ /*----------------------------------------------------------------------------*/ -void cpl_bivector_unwrap_vectors(cpl_bivector * f) +void +cpl_bivector_unwrap_vectors(cpl_bivector *f) { cpl_free(f); return; @@ -249,19 +255,22 @@ precision loss due to the limited accuracy of the ASCII representation. */ /*----------------------------------------------------------------------------*/ -void cpl_bivector_dump(const cpl_bivector * f, FILE * stream) +void +cpl_bivector_dump(const cpl_bivector *f, FILE *stream) { - const double * data_x; - const double * data_y; - cpl_size i; + const double *data_x; + const double *data_y; + cpl_size i; - if (stream == NULL) stream = stdout; + if (stream == NULL) + stream = stdout; if (f == NULL) { fprintf(stream, "#NULL bivector\n"); return; } - if (cpl_vector_get_size(f->x) != cpl_vector_get_size(f->y)) return; + if (cpl_vector_get_size(f->x) != cpl_vector_get_size(f->y)) + return; data_x = cpl_vector_get_data_const(f->x); data_y = cpl_vector_get_data_const(f->y); @@ -297,21 +306,22 @@ - CPL_ERROR_BAD_FILE_FORMAT if the file contains no valid lines */ /*----------------------------------------------------------------------------*/ -cpl_bivector * cpl_bivector_read(const char * filename) +cpl_bivector * +cpl_bivector_read(const char *filename) { - FILE * in; - cpl_vector * v1; - cpl_vector * v2; - cpl_size np = 0; - cpl_size size = 1000; /* Default size */ - char line[1024]; - double x, y; + FILE *in; + cpl_vector *v1; + cpl_vector *v2; + cpl_size np = 0; + cpl_size size = 1000; /* Default size */ + char line[1024]; + double x, y; cpl_ensure(filename, CPL_ERROR_NULL_INPUT, NULL); /* Open the file */ in = fopen(filename, "r"); - cpl_ensure(in, CPL_ERROR_FILE_IO, NULL); + cpl_ensure(in, CPL_ERROR_FILE_IO, NULL); /* Create and fill the vectors */ v1 = cpl_vector_new(size); @@ -355,7 +365,6 @@ /* Cannot fail at this point */ return cpl_bivector_wrap_vectors(v1, v2); - } /*----------------------------------------------------------------------------*/ @@ -370,21 +379,20 @@ different sizes */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_bivector_get_size(const cpl_bivector * in) +cpl_size +cpl_bivector_get_size(const cpl_bivector *in) { - - cpl_size size; + cpl_size size; cpl_ensure(in, CPL_ERROR_NULL_INPUT, -1); - assert( in->x ); - assert( in->y ); + assert(in->x); + assert(in->y); /* Get sizes of x and y vectors */ size = cpl_vector_get_size(in->x); - cpl_ensure(size == cpl_vector_get_size(in->y), CPL_ERROR_ILLEGAL_INPUT, - -2); + cpl_ensure(size == cpl_vector_get_size(in->y), CPL_ERROR_ILLEGAL_INPUT, -2); return size; } @@ -401,12 +409,12 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_vector * cpl_bivector_get_x(cpl_bivector * in) +cpl_vector * +cpl_bivector_get_x(cpl_bivector *in) { - cpl_ensure(in, CPL_ERROR_NULL_INPUT, NULL); - assert( in->x ); + assert(in->x); return in->x; } @@ -419,11 +427,12 @@ @see cpl_bivector_get_x */ /*----------------------------------------------------------------------------*/ -const cpl_vector * cpl_bivector_get_x_const (const cpl_bivector * in) +const cpl_vector * +cpl_bivector_get_x_const(const cpl_bivector *in) { cpl_ensure(in, CPL_ERROR_NULL_INPUT, NULL); - assert( in->x ); + assert(in->x); return in->x; } @@ -440,12 +449,12 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_vector * cpl_bivector_get_y(cpl_bivector * in) +cpl_vector * +cpl_bivector_get_y(cpl_bivector *in) { - cpl_ensure(in, CPL_ERROR_NULL_INPUT, NULL); - assert( in->y ); + assert(in->y); return in->y; } @@ -457,11 +466,12 @@ @return Pointer to the y vector or NULL on error */ /*----------------------------------------------------------------------------*/ -const cpl_vector * cpl_bivector_get_y_const(const cpl_bivector * in) +const cpl_vector * +cpl_bivector_get_y_const(const cpl_bivector *in) { cpl_ensure(in, CPL_ERROR_NULL_INPUT, NULL); - assert( in->y ); + assert(in->y); return in->y; } @@ -484,12 +494,12 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -double * cpl_bivector_get_x_data(cpl_bivector * in) +double * +cpl_bivector_get_x_data(cpl_bivector *in) { - cpl_ensure(in, CPL_ERROR_NULL_INPUT, NULL); - assert( in->x ); + assert(in->x); return cpl_vector_get_data(in->x); } @@ -503,11 +513,12 @@ */ /*----------------------------------------------------------------------------*/ -const double * cpl_bivector_get_x_data_const(const cpl_bivector * in) +const double * +cpl_bivector_get_x_data_const(const cpl_bivector *in) { cpl_ensure(in, CPL_ERROR_NULL_INPUT, NULL); - assert( in->x ); + assert(in->x); return cpl_vector_get_data_const(in->x); } @@ -523,12 +534,12 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -double * cpl_bivector_get_y_data(cpl_bivector * in) +double * +cpl_bivector_get_y_data(cpl_bivector *in) { - cpl_ensure(in, CPL_ERROR_NULL_INPUT, NULL); - assert( in->y ); + assert(in->y); return cpl_vector_get_data(in->y); } @@ -541,11 +552,12 @@ @see cpl_bivector_get_y_data */ /*----------------------------------------------------------------------------*/ -const double * cpl_bivector_get_y_data_const(const cpl_bivector * in) +const double * +cpl_bivector_get_y_data_const(const cpl_bivector *in) { cpl_ensure(in, CPL_ERROR_NULL_INPUT, NULL); - assert( in->y ); + assert(in->y); return cpl_vector_get_data_const(in->y); } @@ -582,29 +594,29 @@ abscissa vectors is not met. */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_bivector_interpolate_linear(cpl_bivector * fout, - const cpl_bivector * fref) +cpl_error_code +cpl_bivector_interpolate_linear(cpl_bivector *fout, const cpl_bivector *fref) { - const cpl_size m = cpl_bivector_get_size(fref); - const cpl_size n = cpl_bivector_get_size(fout); - const double * xref = cpl_bivector_get_x_data_const(fref); - const double * yref = cpl_bivector_get_y_data_const(fref); - double * xout = cpl_bivector_get_x_data(fout); - double * yout = cpl_bivector_get_y_data(fout); + const cpl_size m = cpl_bivector_get_size(fref); + const cpl_size n = cpl_bivector_get_size(fout); + const double *xref = cpl_bivector_get_x_data_const(fref); + const double *yref = cpl_bivector_get_y_data_const(fref); + double *xout = cpl_bivector_get_x_data(fout); + double *yout = cpl_bivector_get_y_data(fout); double grad = DBL_MAX; /* Avoid (false) uninit warning */ - double y_0 = DBL_MAX; /* Avoid (false) uninit warning */ + double y_0 = DBL_MAX; /* Avoid (false) uninit warning */ cpl_size ibelow, iabove; cpl_size i; - cpl_ensure_code( xref != NULL, cpl_error_get_code()); - cpl_ensure_code( yref != NULL, cpl_error_get_code()); - cpl_ensure_code( xout != NULL, cpl_error_get_code()); - cpl_ensure_code( yout != NULL, cpl_error_get_code()); + cpl_ensure_code(xref != NULL, cpl_error_get_code()); + cpl_ensure_code(yref != NULL, cpl_error_get_code()); + cpl_ensure_code(xout != NULL, cpl_error_get_code()); + cpl_ensure_code(yout != NULL, cpl_error_get_code()); /* Upper extrapolation not allowed */ - cpl_ensure_code(xout[n-1] <= xref[m-1], CPL_ERROR_DATA_NOT_FOUND); + cpl_ensure_code(xout[n - 1] <= xref[m - 1], CPL_ERROR_DATA_NOT_FOUND); /* Start interpolation from below */ ibelow = cpl_vector_find(cpl_bivector_get_x_const(fref), xout[0]); @@ -623,28 +635,27 @@ /* When possible reuse reference function abscissa points */ if (xref[iabove] < xout[i]) { /* No, need new points */ - while (xref[++iabove] < xout[i]); + while (xref[++iabove] < xout[i]) + ; ibelow = iabove - 1; /* Verify that the pair of reference abscissa points are valid */ - if (xref[iabove] <= xref[ibelow]) break; + if (xref[iabove] <= xref[ibelow]) + break; - grad = (yref[iabove] - yref[ibelow]) - / (xref[iabove] - xref[ibelow]); + grad = + (yref[iabove] - yref[ibelow]) / (xref[iabove] - xref[ibelow]); - y_0 = yref[ibelow] - grad * xref[ibelow]; + y_0 = yref[ibelow] - grad * xref[ibelow]; } if (xref[ibelow] < xout[i]) { - yout[i] = y_0 + grad * xout[i]; - - } else { - + } + else { /* assert( xout[i] == xref[ibelow] ); */ yout[i] = yref[ibelow]; - } } @@ -678,38 +689,40 @@ CPL_SORT_BY_X nor CPL_SORT_BY_Y */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_bivector_sort(cpl_bivector * self, - const cpl_bivector * other, - cpl_sort_direction dir, - cpl_sort_mode mode) +cpl_error_code +cpl_bivector_sort(cpl_bivector *self, + const cpl_bivector *other, + cpl_sort_direction dir, + cpl_sort_mode mode) { - const cpl_size n = cpl_bivector_get_size(self); - cpl_ifalloc permbuf; /* Avoid malloc() on small data sets */ - cpl_size * perm; - const double * data; - int reverse; - cpl_size i; + cpl_ifalloc permbuf; /* Avoid malloc() on small data sets */ + cpl_size *perm; + const double *data; + int reverse; + cpl_size i; cpl_error_code error = CPL_ERROR_NONE; - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(other != NULL, CPL_ERROR_NULL_INPUT); /* At least one of the two bivectors must have two distinct buffers (otherwise the call is utterly pointless) */ cpl_ensure_code(cpl_bivector_get_x_data_const(self) != - cpl_bivector_get_y_data_const(self) || - cpl_bivector_get_x_data_const(other) != - cpl_bivector_get_y_data_const(other), + cpl_bivector_get_y_data_const(self) || + cpl_bivector_get_x_data_const(other) != + cpl_bivector_get_y_data_const(other), CPL_ERROR_UNSUPPORTED_MODE); cpl_ensure_code(cpl_bivector_get_size(other) == n, CPL_ERROR_INCOMPATIBLE_INPUT); if (dir == CPL_SORT_ASCENDING) { reverse = 0; - } else if (dir == CPL_SORT_DESCENDING) { + } + else if (dir == CPL_SORT_DESCENDING) { reverse = 1; - } else { + } + else { return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); } @@ -719,14 +732,16 @@ would be needed as well. This will probably not be requested */ if (mode == CPL_SORT_BY_X) { data = cpl_bivector_get_x_data_const(other); - } else if (mode == CPL_SORT_BY_Y) { + } + else if (mode == CPL_SORT_BY_Y) { data = cpl_bivector_get_y_data_const(other); - } else { + } + else { return cpl_error_set_(CPL_ERROR_UNSUPPORTED_MODE); } cpl_ifalloc_set(&permbuf, (size_t)n * sizeof(*perm)); - perm = (cpl_size*)cpl_ifalloc_get(&permbuf); + perm = (cpl_size *)cpl_ifalloc_get(&permbuf); for (i = 0; i < n; i++) { perm[i] = i; @@ -734,30 +749,29 @@ if (cpl_tools_sort_stable_pattern_double(data, n, reverse, 1, perm)) { error = cpl_error_set_where_(); - } else { - double * dselfx = cpl_bivector_get_x_data(self); - double * dselfy = cpl_bivector_get_y_data(self); - const double * dotherx = cpl_bivector_get_x_data_const(other); - const double * dothery = cpl_bivector_get_y_data_const(other); - - if (dselfx != dotherx && dselfy != dothery && - dselfx != dothery && dselfy != dotherx) { + } + else { + double *dselfx = cpl_bivector_get_x_data(self); + double *dselfy = cpl_bivector_get_y_data(self); + const double *dotherx = cpl_bivector_get_x_data_const(other); + const double *dothery = cpl_bivector_get_y_data_const(other); + if (dselfx != dotherx && dselfy != dothery && dselfx != dothery && + dselfy != dotherx) { /* Out-of place copy of the permuted values to self */ for (i = 0; i < n; i++) { dselfx[i] = dotherx[perm[i]]; dselfy[i] = dothery[perm[i]]; } - - } else if (cpl_tools_permute_double(perm, n, dselfx, dotherx, - dselfy, dothery)) { + } + else if (cpl_tools_permute_double(perm, n, dselfx, dotherx, dselfy, + dothery)) { error = cpl_error_set_where_(); } } cpl_ifalloc_free(&permbuf); return error; - } /**@}*/ diff -Nru cpl-7.1.4+ds/cplcore/cpl_bivector.h cpl-7.2.2+ds/cplcore/cpl_bivector.h --- cpl-7.1.4+ds/cplcore/cpl_bivector.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_bivector.h 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -37,7 +37,8 @@ typedef struct _cpl_bivector_ cpl_bivector; -typedef enum { +typedef enum +{ CPL_SORT_BY_X, CPL_SORT_BY_Y } cpl_sort_mode; @@ -47,35 +48,36 @@ -----------------------------------------------------------------------------*/ /* Constructors and destructors */ -cpl_bivector * cpl_bivector_new(cpl_size) CPL_ATTR_ALLOC; -cpl_bivector * cpl_bivector_wrap_vectors(cpl_vector *, - cpl_vector *) CPL_ATTR_ALLOC; -cpl_bivector * cpl_bivector_duplicate(const cpl_bivector *) CPL_ATTR_ALLOC; +cpl_bivector *cpl_bivector_new(cpl_size) CPL_ATTR_ALLOC; +cpl_bivector * +cpl_bivector_wrap_vectors(cpl_vector *, cpl_vector *) CPL_ATTR_ALLOC; +cpl_bivector *cpl_bivector_duplicate(const cpl_bivector *) CPL_ATTR_ALLOC; void cpl_bivector_delete(cpl_bivector *); void cpl_bivector_unwrap_vectors(cpl_bivector *); void cpl_bivector_dump(const cpl_bivector *, FILE *); -cpl_bivector * cpl_bivector_read(const char *) CPL_ATTR_ALLOC; +cpl_bivector *cpl_bivector_read(const char *) CPL_ATTR_ALLOC; cpl_error_code cpl_bivector_copy(cpl_bivector *, const cpl_bivector *); /* Accessors functions */ cpl_size cpl_bivector_get_size(const cpl_bivector *); - cpl_vector * cpl_bivector_get_x(cpl_bivector *); - cpl_vector * cpl_bivector_get_y(cpl_bivector *); -const cpl_vector * cpl_bivector_get_x_const(const cpl_bivector *); -const cpl_vector * cpl_bivector_get_y_const(const cpl_bivector *); - double * cpl_bivector_get_x_data(cpl_bivector *); - double * cpl_bivector_get_y_data(cpl_bivector *); -const double * cpl_bivector_get_x_data_const(const cpl_bivector *); -const double * cpl_bivector_get_y_data_const(const cpl_bivector *); +cpl_vector *cpl_bivector_get_x(cpl_bivector *); +cpl_vector *cpl_bivector_get_y(cpl_bivector *); +const cpl_vector *cpl_bivector_get_x_const(const cpl_bivector *); +const cpl_vector *cpl_bivector_get_y_const(const cpl_bivector *); +double *cpl_bivector_get_x_data(cpl_bivector *); +double *cpl_bivector_get_y_data(cpl_bivector *); +const double *cpl_bivector_get_x_data_const(const cpl_bivector *); +const double *cpl_bivector_get_y_data_const(const cpl_bivector *); /* Basic functionalities */ -cpl_error_code cpl_bivector_interpolate_linear(cpl_bivector *, - const cpl_bivector *); +cpl_error_code +cpl_bivector_interpolate_linear(cpl_bivector *, const cpl_bivector *); -cpl_error_code cpl_bivector_sort(cpl_bivector *, const cpl_bivector *, - cpl_sort_direction, cpl_sort_mode); +cpl_error_code cpl_bivector_sort(cpl_bivector *, + const cpl_bivector *, + cpl_sort_direction, + cpl_sort_mode); CPL_END_DECLS #endif - diff -Nru cpl-7.1.4+ds/cplcore/cpl_cfitsio.c cpl-7.2.2+ds/cplcore/cpl_cfitsio.c --- cpl-7.1.4+ds/cplcore/cpl_cfitsio.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_cfitsio.c 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -23,6 +23,9 @@ #include "cpl_cfitsio.h" +#ifndef CPL_USE_CFITSIO_STRICT +#include "fitsio2.h" +#endif /* The below doxygen has been inactivated by removing the '**' comment. */ @@ -50,15 +53,22 @@ * @internal * @brief Wrap around the CFISTIO function dropping const modifiers that the * CFITSIO function should have. - * @see fits_read_subset() + * @see fits_read_subset(), ffgsv() */ -int cpl_fits_read_subset(fitsfile *fptr, int datatype, const long *blc, - const long *trc, const long *inc, const void *nulval, - void *array, int *anynul, int *status) +int +cpl_fits_read_subset(fitsfile *fptr, + int datatype, + const long *blc, + const long *trc, + const long *inc, + const void *nulval, + void *array, + int *anynul, + int *status) { CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); - return fits_read_subset(fptr, datatype, (long*)blc, (long*)trc, (long*)inc, - (void*)nulval, array, anynul,status); + return fits_read_subset(fptr, datatype, (long *)blc, (long *)trc, + (long *)inc, (void *)nulval, array, anynul, status); CPL_DIAG_PRAGMA_POP; } @@ -68,12 +78,17 @@ * CFITSIO function should have. * @see fits_read_subset() */ -int cpl_fits_write_pix(fitsfile *fptr, int datatype, const long *firstpix, - LONGLONG nelem, const void *array, int *status) +int +cpl_fits_write_pix(fitsfile *fptr, + int datatype, + const long *firstpix, + LONGLONG nelem, + const void *array, + int *status) { CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); - return fits_write_pix(fptr, datatype, (long*)firstpix, nelem, - (void*)array, status); + return fits_write_pix(fptr, datatype, (long *)firstpix, nelem, + (void *)array, status); CPL_DIAG_PRAGMA_POP; } @@ -84,12 +99,17 @@ * CFITSIO function should have. * @see fits_read_subset() */ -int cpl_fits_write_pixll(fitsfile *fptr, int datatype, const LONGLONG *firstpix, - LONGLONG nelem, const void *array, int *status) +int +cpl_fits_write_pixll(fitsfile *fptr, + int datatype, + const LONGLONG *firstpix, + LONGLONG nelem, + const void *array, + int *status) { CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); - return fits_write_pixll(fptr, datatype, (LONGLONG*)firstpix, nelem, - (void*)array, status); + return fits_write_pixll(fptr, datatype, (LONGLONG *)firstpix, nelem, + (void *)array, status); CPL_DIAG_PRAGMA_POP; } #endif @@ -100,12 +120,15 @@ * CFITSIO function should have. * @see fits_read_subset() */ -int cpl_fits_create_img(fitsfile *fptr, int bitpix, int naxis, - const long *naxes, int *status) +int +cpl_fits_create_img(fitsfile *fptr, + int bitpix, + int naxis, + const long *naxes, + int *status) { CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); - return fits_create_img(fptr, bitpix, naxis, - (long *)naxes, status); + return fits_create_img(fptr, bitpix, naxis, (long *)naxes, status); CPL_DIAG_PRAGMA_POP; } @@ -114,14 +137,17 @@ * @internal * @brief Wrap around the CFISTIO function dropping const modifiers that the * CFITSIO function should have. - * @see fits_read_subset() + * @see fits_read_subset(), ffcrimll(), ffphprll() */ -int cpl_fits_create_imgll(fitsfile *fptr, int bitpix, int naxis, - const LONGLONG *naxes, int *status) +int +cpl_fits_create_imgll(fitsfile *fptr, + int bitpix, + int naxis, + const LONGLONG *naxes, + int *status) { CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); - return fits_create_imgll(fptr, bitpix, naxis, - (LONGLONG *)naxes, status); + return fits_create_imgll(fptr, bitpix, naxis, (LONGLONG *)naxes, status); CPL_DIAG_PRAGMA_POP; } #endif @@ -132,13 +158,19 @@ * CFITSIO function should have. * @see fits_read_subset() */ -int cpl_fits_read_pix(fitsfile *fptr, int datatype, const long *firstpix, - LONGLONG nelem, const void *nulval, void *array, - int *anynul, int *status) +int +cpl_fits_read_pix(fitsfile *fptr, + int datatype, + const long *firstpix, + LONGLONG nelem, + const void *nulval, + void *array, + int *anynul, + int *status) { CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); - return fits_read_pix(fptr, datatype, (long*)firstpix, nelem, - (void*)nulval, array, anynul, status); + return fits_read_pix(fptr, datatype, (long *)firstpix, nelem, + (void *)nulval, array, anynul, status); CPL_DIAG_PRAGMA_POP; } @@ -149,15 +181,48 @@ * CFITSIO function should have. * @see fits_read_subset() */ -int cpl_fits_read_pixll(fitsfile *fptr, int datatype, const LONGLONG *firstpix, - LONGLONG nelem, const void *nulval, void *array, - int *anynul, int *status) +int +cpl_fits_read_pixll(fitsfile *fptr, + int datatype, + const LONGLONG *firstpix, + LONGLONG nelem, + const void *nulval, + void *array, + int *anynul, + int *status) { CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); - return fits_read_pixll(fptr, datatype, (LONGLONG*)firstpix, nelem, - (void*)nulval, array, anynul, status); + return fits_read_pixll(fptr, datatype, (LONGLONG *)firstpix, nelem, + (void *)nulval, array, anynul, status); CPL_DIAG_PRAGMA_POP; } #endif +/** + * @internal + * @brief Wrap around the CFISTIO function + * @see fits_write_record(), ffprec() + */ +int +cpl_fits_write_record(fitsfile *fptr, const char *card, int *status) +{ +#ifdef CPL_USE_CFITSIO_STRICT + ffprec(fptr, card, status); +#else + if (*status > 0) /* inherit input status value if > 0 */ + return (*status); + + ffmbyt(fptr, (fptr->Fptr)->headend, IGNORE_EOF, status); /* move to end */ + + CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); + ffpbyt(fptr, 80, (char *)card, status); /* write the 80 byte card */ + CPL_DIAG_PRAGMA_POP; + + if (*status <= 0) + (fptr->Fptr)->headend += 80; /* update end-of-header position */ +#endif + + return (*status); +} + /**@}*/ diff -Nru cpl-7.1.4+ds/cplcore/cpl_cfitsio.h cpl-7.2.2+ds/cplcore/cpl_cfitsio.h --- cpl-7.1.4+ds/cplcore/cpl_cfitsio.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_cfitsio.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -34,55 +34,82 @@ Function prototypes -----------------------------------------------------------------------------*/ -int cpl_fits_read_subset(fitsfile *fptr, int datatype, const long *blc, - const long *trc, const long *inc, - const void *nulval, void *array, int *anynul, +int cpl_fits_read_subset(fitsfile *fptr, + int datatype, + const long *blc, + const long *trc, + const long *inc, + const void *nulval, + void *array, + int *anynul, int *status) #ifdef CPL_HAVE_ATTR_NONNULL - __attribute__((nonnull(1,3,4,5,7,9))) + __attribute__((nonnull(1, 3, 4, 5, 7, 9))) #endif CPL_INTERNAL; -int cpl_fits_write_pix(fitsfile *fptr, int datatype, - const long *firstpix, LONGLONG nelem, - const void *array, int *status) - CPL_ATTR_NONNULL CPL_INTERNAL; +int cpl_fits_write_pix(fitsfile *fptr, + int datatype, + const long *firstpix, + LONGLONG nelem, + const void *array, + int *status) CPL_ATTR_NONNULL CPL_INTERNAL; #ifdef fits_write_pixll -int cpl_fits_write_pixll(fitsfile *fptr, int datatype, const LONGLONG *firstpix, - LONGLONG nelem, const void *array, int *status) - CPL_ATTR_NONNULL CPL_INTERNAL; +int cpl_fits_write_pixll(fitsfile *fptr, + int datatype, + const LONGLONG *firstpix, + LONGLONG nelem, + const void *array, + int *status) CPL_ATTR_NONNULL CPL_INTERNAL; #endif -int cpl_fits_create_img(fitsfile *fptr, int bitpix, int naxis, - const long *naxes, int *status) - CPL_ATTR_NONNULL CPL_INTERNAL; +int cpl_fits_create_img(fitsfile *fptr, + int bitpix, + int naxis, + const long *naxes, + int *status) CPL_ATTR_NONNULL CPL_INTERNAL; #ifdef fits_create_imgll -int cpl_fits_create_imgll(fitsfile *fptr, int bitpix, int naxis, - const LONGLONG *naxes, int *status) - CPL_ATTR_NONNULL CPL_INTERNAL; +int cpl_fits_create_imgll(fitsfile *fptr, + int bitpix, + int naxis, + const LONGLONG *naxes, + int *status) CPL_ATTR_NONNULL CPL_INTERNAL; #endif -int cpl_fits_read_pix(fitsfile *fptr, int datatype, const long *firstpix, - LONGLONG nelem, const void *nulval, void *array, - int *anynul, int *status) +int cpl_fits_read_pix(fitsfile *fptr, + int datatype, + const long *firstpix, + LONGLONG nelem, + const void *nulval, + void *array, + int *anynul, + int *status) #ifdef CPL_HAVE_ATTR_NONNULL - __attribute__((nonnull(1,3,6,8))) + __attribute__((nonnull(1, 3, 6, 8))) #endif CPL_INTERNAL; #ifdef fits_read_pixll -int cpl_fits_read_pixll(fitsfile *fptr, int datatype, const LONGLONG *firstpix, - LONGLONG nelem, const void *nulval, void *array, - int *anynul, int *status) +int cpl_fits_read_pixll(fitsfile *fptr, + int datatype, + const LONGLONG *firstpix, + LONGLONG nelem, + const void *nulval, + void *array, + int *anynul, + int *status) #ifdef CPL_HAVE_ATTR_NONNULL - __attribute__((nonnull(1,3,6,8))) + __attribute__((nonnull(1, 3, 6, 8))) #endif CPL_INTERNAL; #endif +int cpl_fits_write_record(fitsfile *fptr, + const char *card, + int *status) CPL_ATTR_NONNULL CPL_INTERNAL; CPL_END_DECLS -#endif +#endif diff -Nru cpl-7.1.4+ds/cplcore/cpl_column_body.h cpl-7.2.2+ds/cplcore/cpl_column_body.h --- cpl-7.1.4+ds/cplcore/cpl_column_body.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_column_body.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,5 +1,5 @@ /* This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -43,13 +43,12 @@ static void ADDTYPE(cpl_column_pow)(cpl_column *column, double exponent) { - - const int myerrno = errno; + const int myerrno = errno; const cpl_size nullcount = cpl_column_count_invalid(column); - const cpl_size length = cpl_column_get_size(column); - ELEM_TYPE *fp = ADDTYPE(cpl_column_get_data)(column); - const int *np = nullcount == 0 ? NULL - : cpl_column_get_data_invalid_const(column); + const cpl_size length = cpl_column_get_size(column); + ELEM_TYPE *fp = ADDTYPE(cpl_column_get_data)(column); + const int *np = + nullcount == 0 ? NULL : cpl_column_get_data_invalid_const(column); if (nullcount == length) @@ -71,38 +70,44 @@ ELEM_TYPE value = 0; /* Init avoids (false pos.) warning */ if (fp[i] > 0.0) { value = ELEM_CAST(1.0 / ELEM_SQRT(fp[i])); - } else { + } + else { errno = EDOM; /* Use errno to reuse code */ } if (errno) { errno = 0; cpl_column_set_invalid(column, i); - } else { + } + else { fp[i] = value; } } } #ifdef ELEM_CBRT - } else if (exponent == -1.0 / 3.0) { + } + else if (exponent == -1.0 / 3.0) { /* Column value must be positive */ for (size_t i = 0; i < (size_t)length; i++) { if (np == NULL || np[i] == 0) { ELEM_TYPE value = 0; /* Init avoids (false pos.) warning */ if (fp[i] > 0.0) { value = ELEM_CAST(1.0 / ELEM_CBRT(fp[i])); - } else { + } + else { errno = EDOM; /* Use errno to reuse code */ } if (errno) { errno = 0; cpl_column_set_invalid(column, i); - } else { + } + else { fp[i] = value; } } } #endif - } else if (exponent < 0.0) { + } + else if (exponent < 0.0) { if (exponent != ceil(exponent)) { /* Column value must be positive */ for (size_t i = 0; i < (size_t)length; i++) { @@ -110,57 +115,66 @@ ELEM_TYPE value = 0; /* Init avoids (false pos.) warning */ if (fp[i] > 0.0) { value = ELEM_CAST(ELEM_POW(fp[i], exponent)); - } else { + } + else { errno = EDOM; /* Use errno to reuse code */ } if (errno) { errno = 0; cpl_column_set_invalid(column, i); - } else { + } + else { fp[i] = value; } } } - } else { + } + else { /* Column value must be non-zero */ for (size_t i = 0; i < (size_t)length; i++) { if (np == NULL || np[i] == 0) { ELEM_TYPE value = 0; /* Init avoids (false pos.) warning */ if (fp[i] != 0.0) { - value = ELEM_CAST(cpl_tools_ipow((double)fp[i], - exponent)); - } else { + value = + ELEM_CAST(cpl_tools_ipow((double)fp[i], exponent)); + } + else { errno = EDOM; /* Use errno to reuse code */ } if (errno) { errno = 0; cpl_column_set_invalid(column, i); - } else { + } + else { fp[i] = value; } } } } - } else if (exponent == 0.5) { + } + else if (exponent == 0.5) { /* Column value must be non-negative */ for (size_t i = 0; i < (size_t)length; i++) { if (np == NULL || np[i] == 0) { ELEM_TYPE value = 0; /* Init avoids (false pos.) warning */ if (fp[i] >= 0.0) { value = ELEM_CAST(ELEM_SQRT(fp[i])); - } else { + } + else { errno = EDOM; /* Use errno to reuse code */ } if (errno) { errno = 0; cpl_column_set_invalid(column, i); - } else { + } + else { fp[i] = value; } } } #ifdef ELEM_CBRT - } else if (exponent == 1.0 / 3.0) { + } + else if (exponent == 1.0 / 3.0) { /* Column value may be anything */ for (size_t i = 0; i < (size_t)length; i++) { if (np == NULL || np[i] == 0) { @@ -168,40 +182,42 @@ } } #endif - } else if (exponent != ceil(exponent)) { + } + else if (exponent != ceil(exponent)) { /* Column value must be non-negative */ for (size_t i = 0; i < (size_t)length; i++) { if (np == NULL || np[i] == 0) { ELEM_TYPE value = 0; /* Init avoids (false pos.) warning */ if (fp[i] >= 0.0) { value = ELEM_CAST(ELEM_POW(fp[i], exponent)); - } else { + } + else { errno = EDOM; /* Use errno to reuse code */ } if (errno) { errno = 0; cpl_column_set_invalid(column, i); - } else { + } + else { fp[i] = value; } } } - } else if (exponent != 1.0) { + } + else if (exponent != 1.0) { /* Column value may be anything */ for (size_t i = 0; i < (size_t)length; i++) { if (np == NULL || np[i] == 0) { - fp[i] = ELEM_CAST(cpl_tools_ipow((double)fp[i], - exponent)); + fp[i] = ELEM_CAST(cpl_tools_ipow((double)fp[i], exponent)); } } - } if (exponent != 1.0) { /* FIXME: Counts also bad pixels */ - cpl_tools_add_flops( length ); + cpl_tools_add_flops(length); } errno = myerrno; diff -Nru cpl-7.1.4+ds/cplcore/cpl_column.c cpl-7.2.2+ds/cplcore/cpl_column.c --- cpl-7.1.4+ds/cplcore/cpl_column.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_column.c 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -46,23 +46,23 @@ Defines -----------------------------------------------------------------------------*/ -#define INT_FORM "% 7d" -#define LONG_FORM "% 7ld" +#define INT_FORM "% 7d" +#define LONG_FORM "% 7ld" #define LONG_LONG_FORM "% 7lld" #define SIZE_TYPE_FORM "% 7" CPL_SIZE_FORMAT -#define FLOAT_FORM "% 1.5e" -#define DOUBLE_FORM "% 1.5e" -#define STRING_FORM "%s" +#define FLOAT_FORM "% 1.5e" +#define DOUBLE_FORM "% 1.5e" +#define STRING_FORM "%s" #define CPL_COLUMN_GET_VALUE(SELF, INDX, MEMBER, TYPEBOOL) \ \ if (SELF == NULL) { \ (void)cpl_error_set_where_(); \ return NULL; \ - } else { \ - \ + } \ + else { \ const cpl_size length = cpl_column_get_size(SELF); \ - const cpl_type type = cpl_column_get_type(SELF); \ + const cpl_type type = cpl_column_get_type(SELF); \ \ if (INDX < 0 || INDX >= length) { \ (void)cpl_error_set_message_(CPL_ERROR_ACCESS_OUT_OF_RANGE, \ @@ -78,7 +78,8 @@ (void)cpl_error_set_message_(CPL_ERROR_TYPE_MISMATCH, \ "index=%" CPL_SIZE_FORMAT \ ", length=%" CPL_SIZE_FORMAT \ - ", type=%s", INDX, length, \ + ", type=%s", \ + INDX, length, \ cpl_type_get_name(type)); \ return NULL; \ } \ @@ -86,24 +87,24 @@ \ return SELF->values->MEMBER[indx] -#define CPL_COLUMN_GET_POINTER(SELF, MEMBER, TYPE) \ - \ - if (SELF == NULL) { \ - (void)cpl_error_set_where_(); \ - return NULL; \ - } else { \ - \ - const cpl_type type = cpl_column_get_type(SELF); \ - \ - if (type != (TYPE)) { \ - (void)cpl_error_set_message_(CPL_ERROR_TYPE_MISMATCH, \ - "type=%s != %s", \ - cpl_type_get_name(type), \ - cpl_type_get_name(TYPE)); \ - return NULL; \ - } \ - } \ - \ +#define CPL_COLUMN_GET_POINTER(SELF, MEMBER, TYPE) \ + \ + if (SELF == NULL) { \ + (void)cpl_error_set_where_(); \ + return NULL; \ + } \ + else { \ + const cpl_type type = cpl_column_get_type(SELF); \ + \ + if (type != (TYPE)) { \ + (void)cpl_error_set_message_(CPL_ERROR_TYPE_MISMATCH, \ + "type=%s != %s", \ + cpl_type_get_name(type), \ + cpl_type_get_name(TYPE)); \ + return NULL; \ + } \ + } \ + \ return SELF->values->MEMBER @@ -131,17 +132,18 @@ * Container of column values (mirroring the legal types). Private. */ -typedef union _cpl_column_values_ { - int *i; /* CPL_TYPE_INT */ - long *l; /* CPL_TYPE_LONG */ - long long *ll; /* CPL_TYPE_LONG_LONG */ - cpl_size *sz; /* CPL_TYPE_SIZE */ - float *f; /* CPL_TYPE_FLOAT */ - double *d; /* CPL_TYPE_DOUBLE */ - float complex *cf; /* CPL_TYPE_FLOAT_COMPLEX */ - double complex *cd; /* CPL_TYPE_DOUBLE_COMPLEX */ - char **s; /* CPL_TYPE_STRING */ - cpl_array **array; /* Array types */ +typedef union _cpl_column_values_ +{ + int *i; /* CPL_TYPE_INT */ + long *l; /* CPL_TYPE_LONG */ + long long *ll; /* CPL_TYPE_LONG_LONG */ + cpl_size *sz; /* CPL_TYPE_SIZE */ + float *f; /* CPL_TYPE_FLOAT */ + double *d; /* CPL_TYPE_DOUBLE */ + float complex *cf; /* CPL_TYPE_FLOAT_COMPLEX */ + double complex *cd; /* CPL_TYPE_DOUBLE_COMPLEX */ + char **s; /* CPL_TYPE_STRING */ + cpl_array **array; /* Array types */ } cpl_column_values; @@ -149,18 +151,19 @@ * The real thing: the column type (private); */ -struct _cpl_column_ { - char *name; - char *unit; - char *format; - cpl_size length; - cpl_size depth; - cpl_type type; - cpl_type savetype; +struct _cpl_column_ +{ + char *name; + char *unit; + char *format; + cpl_size length; + cpl_size depth; + cpl_type type; + cpl_type savetype; cpl_column_values *values; - cpl_column_flag *null; /* NULL flags buffer */ - cpl_size nullcount; /* Number of NULLs in column */ - cpl_array *dimensions; /* Number of dimensions in column */ + cpl_column_flag *null; /* NULL flags buffer */ + cpl_size nullcount; /* Number of NULLs in column */ + cpl_array *dimensions; /* Number of dimensions in column */ }; @@ -168,48 +171,50 @@ Static Function Prototypes -----------------------------------------------------------------------------*/ -static inline int cpl_get_error_check_(const char *, const cpl_column *, - cpl_size, int *, cpl_type) +static inline int cpl_get_error_check_(const char *, + const cpl_column *, + cpl_size, + int *, + cpl_type) #ifdef CPL_HAVE_ATTR_NONNULL __attribute__((nonnull(1))) #endif ; -inline static int cpl_set_error_check_(const char *, const cpl_column *, - cpl_size, cpl_type) +inline static int +cpl_set_error_check_(const char *, const cpl_column *, cpl_size, cpl_type) #ifdef CPL_HAVE_ATTR_NONNULL __attribute__((nonnull(1))) #endif ; static inline int cpl_column_base_type_invalid_(const cpl_column *, - cpl_size, cpl_size) - CPL_ATTR_NONNULL; + cpl_size, + cpl_size) CPL_ATTR_NONNULL; -static inline cpl_size cpl_column_get_size_(const cpl_column *) - CPL_ATTR_NONNULL; +static inline cpl_size +cpl_column_get_size_(const cpl_column *) CPL_ATTR_NONNULL; -static inline cpl_type cpl_column_get_type_(const cpl_column *) - CPL_ATTR_NONNULL; +static inline cpl_type +cpl_column_get_type_(const cpl_column *) CPL_ATTR_NONNULL; -static inline cpl_size cpl_column_get_invalid_numerical(const cpl_column *) - CPL_ATTR_NONNULL; +static inline cpl_size +cpl_column_get_invalid_numerical(const cpl_column *) CPL_ATTR_NONNULL; -static void cpl_column_pow_float_complex(cpl_column *, double) - CPL_ATTR_NONNULL; -static void cpl_column_pow_double_complex(cpl_column *, double) - CPL_ATTR_NONNULL; +static void cpl_column_pow_float_complex(cpl_column *, double) CPL_ATTR_NONNULL; +static void +cpl_column_pow_double_complex(cpl_column *, double) CPL_ATTR_NONNULL; -static void cpl_column_cpow_float_complex(cpl_column *, double complex) - CPL_ATTR_NONNULL; +static void +cpl_column_cpow_float_complex(cpl_column *, double complex) CPL_ATTR_NONNULL; -static void cpl_column_cpow_double_complex(cpl_column *, double complex) - CPL_ATTR_NONNULL; +static void +cpl_column_cpow_double_complex(cpl_column *, double complex) CPL_ATTR_NONNULL; /* These macros are needed for support of the different element types */ -#define CONCAT(a,b) a ## _ ## b -#define CONCAT2X(a,b) CONCAT(a,b) +#define CONCAT(a, b) a##_##b +#define CONCAT2X(a, b) CONCAT(a, b) #define ADDTYPE(a) CONCAT2X(a, ELEM_NAME) @@ -300,7 +305,7 @@ #ifdef HAVE_CBRT #define ELEM_CBRT cbrt #endif -#define ELEM_CAST (cpl_size)round +#define ELEM_CAST (cpl_size) round #include "cpl_column_body.h" #undef ELEM_TYPE #undef ELEM_NAME @@ -310,7 +315,6 @@ #undef ELEM_CAST - /*----------------------------------------------------------------------------- Function definitions -----------------------------------------------------------------------------*/ @@ -330,41 +334,41 @@ * union. Undefined or illegal types returns 0. */ -inline static size_t cpl_column_type_size(cpl_type type) +inline static size_t +cpl_column_type_size(cpl_type type) { - size_t sz = 0; switch (type & ~CPL_TYPE_POINTER) { - case CPL_TYPE_INT: - sz = sizeof(int); - break; - case CPL_TYPE_LONG: - sz = sizeof(long); - break; - case CPL_TYPE_LONG_LONG: - sz = sizeof(long long); - break; - case CPL_TYPE_SIZE: - sz = sizeof(cpl_size); - break; - case CPL_TYPE_FLOAT: - sz = sizeof(float); - break; - case CPL_TYPE_DOUBLE: - sz = sizeof(double); - break; - case CPL_TYPE_FLOAT_COMPLEX: - sz = sizeof(float complex); - break; - case CPL_TYPE_DOUBLE_COMPLEX: - sz = sizeof(double complex); - break; - case CPL_TYPE_STRING: - sz = sizeof(char *); - break; - default: - break; + case CPL_TYPE_INT: + sz = sizeof(int); + break; + case CPL_TYPE_LONG: + sz = sizeof(long); + break; + case CPL_TYPE_LONG_LONG: + sz = sizeof(long long); + break; + case CPL_TYPE_SIZE: + sz = sizeof(cpl_size); + break; + case CPL_TYPE_FLOAT: + sz = sizeof(float); + break; + case CPL_TYPE_DOUBLE: + sz = sizeof(double); + break; + case CPL_TYPE_FLOAT_COMPLEX: + sz = sizeof(float complex); + break; + case CPL_TYPE_DOUBLE_COMPLEX: + sz = sizeof(double complex); + break; + case CPL_TYPE_STRING: + sz = sizeof(char *); + break; + default: + break; } if (sz != 0 && (type & CPL_TYPE_POINTER)) { @@ -373,7 +377,6 @@ } return sz; - } @@ -387,16 +390,15 @@ * column values. */ -static cpl_column_values *cpl_column_values_new(void) +static cpl_column_values * +cpl_column_values_new(void) { - cpl_column_values *value = cpl_calloc(1, sizeof(cpl_column_values)); value->i = NULL; return value; - } /* @@ -406,14 +408,13 @@ * @return Pointer to column values container, or @em NULL. */ -static cpl_column_values *cpl_column_get_values(cpl_column *column) +static cpl_column_values * +cpl_column_get_values(cpl_column *column) { - if (column) return column->values; return NULL; - } @@ -431,40 +432,41 @@ * container. */ -static void cpl_column_values_delete(cpl_column_values *values, - cpl_size length, cpl_type type) +static void +cpl_column_values_delete(cpl_column_values *values, + cpl_size length, + cpl_type type) { - if (values) { if (type & CPL_TYPE_POINTER) { switch (type & ~CPL_TYPE_POINTER) { - case CPL_TYPE_INT: - case CPL_TYPE_LONG: - case CPL_TYPE_LONG_LONG: - case CPL_TYPE_SIZE: - case CPL_TYPE_FLOAT: - case CPL_TYPE_DOUBLE: - case CPL_TYPE_STRING: - case CPL_TYPE_FLOAT_COMPLEX: - case CPL_TYPE_DOUBLE_COMPLEX: + case CPL_TYPE_INT: + case CPL_TYPE_LONG: + case CPL_TYPE_LONG_LONG: + case CPL_TYPE_SIZE: + case CPL_TYPE_FLOAT: + case CPL_TYPE_DOUBLE: + case CPL_TYPE_STRING: + case CPL_TYPE_FLOAT_COMPLEX: + case CPL_TYPE_DOUBLE_COMPLEX: - for (cpl_size i = 0; i < length; i++) - cpl_array_delete(values->array[i]); + for (cpl_size i = 0; i < length; i++) + cpl_array_delete(values->array[i]); - cpl_free((void *)values->array); + cpl_free((void *)values->array); - break; - default: - break; + break; + default: + break; } - } else { + } + else { if (type == CPL_TYPE_STRING) { for (cpl_size i = 0; i < length; i++) cpl_free(values->s[i]); } cpl_free((void *)values->s); - } cpl_free(values); } @@ -489,16 +491,16 @@ * already performed by the caller. */ -static int cpl_column_unset_null(cpl_column *column, cpl_size row) +static int +cpl_column_unset_null(cpl_column *column, cpl_size row) { - cpl_size length; - if (column->nullcount == 0) /* There are no nulls to unset */ + if (column->nullcount == 0) /* There are no nulls to unset */ return 0; - if (!column->null) /* There are just nulls */ + if (!column->null) /* There are just nulls */ column->null = cpl_malloc(column->length * sizeof(cpl_column_flag)); length = column->length; @@ -519,7 +521,6 @@ } return 0; - } @@ -541,10 +542,11 @@ * already performed by the caller. */ -static int cpl_column_unset_null_segment(cpl_column *column, - cpl_size start, cpl_size count) +static int +cpl_column_unset_null_segment(cpl_column *column, + cpl_size start, + cpl_size count) { - cpl_size length = cpl_column_get_size(column); @@ -584,22 +586,21 @@ } return 0; - } -void cpl_column_dump_structure(cpl_column *column) +void +cpl_column_dump_structure(cpl_column *column) { cpl_errorstate prevstate = cpl_errorstate_get(); - const char *name = cpl_column_get_name(column); - const char *unit = cpl_column_get_unit(column); + const char *name = cpl_column_get_name(column); + const char *unit = cpl_column_get_unit(column); const char *format = cpl_column_get_format(column); - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); if (column) { - printf("Column name : "); if (name) @@ -624,206 +625,213 @@ printf("Column type : "); switch (type) { - case CPL_TYPE_INT: - printf("int\n"); - break; - case CPL_TYPE_LONG: - printf("long\n"); - break; - case CPL_TYPE_LONG_LONG: - printf("long long\n"); - break; - case CPL_TYPE_SIZE: - printf("size_type\n"); - break; - case CPL_TYPE_FLOAT: - printf("float\n"); - break; - case CPL_TYPE_DOUBLE: - printf("double\n"); - break; - case CPL_TYPE_STRING: - printf("string\n"); - break; - default: - printf("UNDEFINED\n"); - break; + case CPL_TYPE_INT: + printf("int\n"); + break; + case CPL_TYPE_LONG: + printf("long\n"); + break; + case CPL_TYPE_LONG_LONG: + printf("long long\n"); + break; + case CPL_TYPE_SIZE: + printf("size_type\n"); + break; + case CPL_TYPE_FLOAT: + printf("float\n"); + break; + case CPL_TYPE_DOUBLE: + printf("double\n"); + break; + case CPL_TYPE_STRING: + printf("string\n"); + break; + default: + printf("UNDEFINED\n"); + break; } printf("Column length : %" CPL_SIZE_FORMAT "\n", length); - printf("Column nulls : %" CPL_SIZE_FORMAT "\n", cpl_column_count_invalid(column)); - printf(" (the NULL column %sexists)\n", - column->null ? "" : "does not "); - + printf("Column nulls : %" CPL_SIZE_FORMAT "\n", + cpl_column_count_invalid(column)); + printf(" (the NULL column %sexists)\n", + column->null ? "" : "does not "); } else { printf("Column is NULL\n"); cpl_errorstate_set(prevstate); } - } -void cpl_column_dump(cpl_column *column, cpl_size start, cpl_size count) +void +cpl_column_dump(cpl_column *column, cpl_size start, cpl_size count) { - cpl_errorstate prevstate = cpl_errorstate_get(); - cpl_type type = cpl_column_get_type(column); + cpl_type type = cpl_column_get_type(column); cpl_size length = cpl_column_get_size(column); - cpl_size nulls = cpl_column_count_invalid(column); - cpl_size i = start; + cpl_size nulls = cpl_column_count_invalid(column); + cpl_size i = start; if (column) { if (start < length) { - if (count > length - start) count = length - start; switch (type) { - case CPL_TYPE_INT: - if (nulls == 0) { - while (count--) { - printf("%" CPL_SIZE_FORMAT " %d\n", i, column->values->i[i]); - i++; - } - } - else if (nulls == length) { - while (count--) { - printf("%" CPL_SIZE_FORMAT " %d NULL\n", i, column->values->i[i]); - i++; - } - } - else { - while (count--) { - printf("%" CPL_SIZE_FORMAT " %d %d\n", i, - column->values->i[i], column->null[i]); - i++; - } - } - break; - case CPL_TYPE_LONG: - if (nulls == 0) { - while (count--) { - printf("%" CPL_SIZE_FORMAT " %ld\n", i, column->values->l[i]); - i++; - } - } - else if (nulls == length) { - while (count--) { - printf("%" CPL_SIZE_FORMAT " %ld NULL\n", i, column->values->l[i]); - i++; - } - } - else { - while (count--) { - printf("%" CPL_SIZE_FORMAT " %ld %d\n", i, - column->values->l[i], column->null[i]); - i++; - } - } - break; - case CPL_TYPE_LONG_LONG: - if (nulls == 0) { - while (count--) { - printf("%" CPL_SIZE_FORMAT " %lld\n", i, column->values->ll[i]); - i++; - } - } - else if (nulls == length) { - while (count--) { - printf("%" CPL_SIZE_FORMAT " %lld NULL\n", i, column->values->ll[i]); - i++; - } - } - else { - while (count--) { - printf("%" CPL_SIZE_FORMAT " %lld %d\n", i, - column->values->ll[i], column->null[i]); - i++; - } - } - break; - case CPL_TYPE_SIZE: - if (nulls == 0) { - while (count--) { - printf("%" CPL_SIZE_FORMAT " %" CPL_SIZE_FORMAT "\n", - i, column->values->sz[i]); - i++; + case CPL_TYPE_INT: + if (nulls == 0) { + while (count--) { + printf("%" CPL_SIZE_FORMAT " %d\n", i, + column->values->i[i]); + i++; + } + } + else if (nulls == length) { + while (count--) { + printf("%" CPL_SIZE_FORMAT " %d NULL\n", i, + column->values->i[i]); + i++; + } + } + else { + while (count--) { + printf("%" CPL_SIZE_FORMAT " %d %d\n", i, + column->values->i[i], column->null[i]); + i++; + } } - } - else if (nulls == length) { - while (count--) { - printf("%" CPL_SIZE_FORMAT " %" CPL_SIZE_FORMAT - " NULL\n", i, column->values->sz[i]); - i++; + break; + case CPL_TYPE_LONG: + if (nulls == 0) { + while (count--) { + printf("%" CPL_SIZE_FORMAT " %ld\n", i, + column->values->l[i]); + i++; + } + } + else if (nulls == length) { + while (count--) { + printf("%" CPL_SIZE_FORMAT " %ld NULL\n", i, + column->values->l[i]); + i++; + } + } + else { + while (count--) { + printf("%" CPL_SIZE_FORMAT " %ld %d\n", i, + column->values->l[i], column->null[i]); + i++; + } } - } - else { - while (count--) { - printf("%" CPL_SIZE_FORMAT " %" CPL_SIZE_FORMAT - " %d\n", i, column->values->sz[i], - column->null[i]); - i++; + break; + case CPL_TYPE_LONG_LONG: + if (nulls == 0) { + while (count--) { + printf("%" CPL_SIZE_FORMAT " %lld\n", i, + column->values->ll[i]); + i++; + } + } + else if (nulls == length) { + while (count--) { + printf("%" CPL_SIZE_FORMAT " %lld NULL\n", i, + column->values->ll[i]); + i++; + } + } + else { + while (count--) { + printf("%" CPL_SIZE_FORMAT " %lld %d\n", i, + column->values->ll[i], column->null[i]); + i++; + } } - } - break; - case CPL_TYPE_FLOAT: - if (nulls == 0) { - while (count--) { - printf("%" CPL_SIZE_FORMAT " %f\n", - i, column->values->f[i]); - i++; + break; + case CPL_TYPE_SIZE: + if (nulls == 0) { + while (count--) { + printf("%" CPL_SIZE_FORMAT " %" CPL_SIZE_FORMAT + "\n", + i, column->values->sz[i]); + i++; + } + } + else if (nulls == length) { + while (count--) { + printf("%" CPL_SIZE_FORMAT " %" CPL_SIZE_FORMAT + " NULL\n", + i, column->values->sz[i]); + i++; + } + } + else { + while (count--) { + printf("%" CPL_SIZE_FORMAT " %" CPL_SIZE_FORMAT + " %d\n", + i, column->values->sz[i], column->null[i]); + i++; + } } - } - else if (nulls == length) { - while (count--) { - printf("%" CPL_SIZE_FORMAT " %f NULL\n", - i, column->values->f[i]); - i++; + break; + case CPL_TYPE_FLOAT: + if (nulls == 0) { + while (count--) { + printf("%" CPL_SIZE_FORMAT " %f\n", i, + column->values->f[i]); + i++; + } + } + else if (nulls == length) { + while (count--) { + printf("%" CPL_SIZE_FORMAT " %f NULL\n", i, + column->values->f[i]); + i++; + } + } + else { + while (count--) { + printf("%" CPL_SIZE_FORMAT " %f %d\n", i, + column->values->f[i], column->null[i]); + i++; + } } - } - else { - while (count--) { - printf("%" CPL_SIZE_FORMAT " %f %d\n", i, - column->values->f[i], column->null[i]); - i++; - } - } - break; - case CPL_TYPE_DOUBLE: - if (nulls == 0) { - while (count--) { - printf("%" CPL_SIZE_FORMAT " %f\n", - i, column->values->d[i]); - i++; + break; + case CPL_TYPE_DOUBLE: + if (nulls == 0) { + while (count--) { + printf("%" CPL_SIZE_FORMAT " %f\n", i, + column->values->d[i]); + i++; + } + } + else if (nulls == length) { + while (count--) { + printf("%" CPL_SIZE_FORMAT " %f NULL\n", i, + column->values->d[i]); + i++; + } + } + else { + while (count--) { + printf("%" CPL_SIZE_FORMAT " %f %d\n", i, + column->values->d[i], column->null[i]); + i++; + } } - } - else if (nulls == length) { + break; + case CPL_TYPE_STRING: while (count--) { - printf("%" CPL_SIZE_FORMAT " %f NULL\n", - i, column->values->d[i]); + printf("%" CPL_SIZE_FORMAT " %s\n", i, + column->values->s[i] ? column->values->s[i] + : "NULL"); i++; } - } - else { - while (count--) { - printf("%" CPL_SIZE_FORMAT " %f %d\n", i, - column->values->d[i], column->null[i]); - i++; - } - } - break; - case CPL_TYPE_STRING: - while (count--) { - printf("%" CPL_SIZE_FORMAT " %s\n", i, - column->values->s[i] ? column->values->s[i] : "NULL"); - i++; - } - break; - default: - break; + break; + default: + break; } } } @@ -831,7 +839,6 @@ printf("Column is NULL\n"); cpl_errorstate_set(prevstate); } - } @@ -848,26 +855,25 @@ * with all the other column properties. */ -static cpl_column *cpl_column_new(cpl_type type) +static cpl_column * +cpl_column_new(cpl_type type) { - cpl_column *column = cpl_calloc(1, sizeof(cpl_column)); - column->values = cpl_column_values_new(); - column->name = NULL; - column->unit = NULL; - column->format = NULL; - column->length = 0; - column->depth = 0; - column->type = type; - column->savetype = type & (~CPL_TYPE_POINTER); - column->null = NULL; - column->nullcount = 0; + column->values = cpl_column_values_new(); + column->name = NULL; + column->unit = NULL; + column->format = NULL; + column->length = 0; + column->depth = 0; + column->type = type; + column->savetype = type & (~CPL_TYPE_POINTER); + column->null = NULL; + column->nullcount = 0; column->dimensions = NULL; return column; - } @@ -885,10 +891,10 @@ * @c CPL_ERROR_ILLEGAL_INPUT is set. Zero length columns are allowed. */ -cpl_column *cpl_column_new_int(cpl_size length) +cpl_column * +cpl_column_new_int(cpl_size length) { - - cpl_column *column; + cpl_column *column; if (length < 0) { @@ -903,12 +909,11 @@ else column->values->i = NULL; - column->format = cpl_strdup(INT_FORM); - column->length = length; + column->format = cpl_strdup(INT_FORM); + column->length = length; column->nullcount = length; return column; - } @@ -926,10 +931,10 @@ * @c CPL_ERROR_ILLEGAL_INPUT is set. Zero length columns are allowed. */ -cpl_column *cpl_column_new_long(cpl_size length) +cpl_column * +cpl_column_new_long(cpl_size length) { - - cpl_column *column; + cpl_column *column; if (length < 0) { @@ -944,12 +949,11 @@ else column->values->l = NULL; - column->format = cpl_strdup(LONG_FORM); - column->length = length; + column->format = cpl_strdup(LONG_FORM); + column->length = length; column->nullcount = length; return column; - } @@ -967,10 +971,10 @@ * @c CPL_ERROR_ILLEGAL_INPUT is set. Zero length columns are allowed. */ -cpl_column *cpl_column_new_long_long(cpl_size length) +cpl_column * +cpl_column_new_long_long(cpl_size length) { - - cpl_column *column; + cpl_column *column; if (length < 0) { @@ -985,12 +989,11 @@ else column->values->ll = NULL; - column->format = cpl_strdup(LONG_LONG_FORM); - column->length = length; + column->format = cpl_strdup(LONG_LONG_FORM); + column->length = length; column->nullcount = length; return column; - } @@ -1008,10 +1011,10 @@ * @c CPL_ERROR_ILLEGAL_INPUT is set. Zero length columns are allowed. */ -cpl_column *cpl_column_new_cplsize(cpl_size length) +cpl_column * +cpl_column_new_cplsize(cpl_size length) { - - cpl_column *column; + cpl_column *column; if (length < 0) { @@ -1026,12 +1029,11 @@ else column->values->sz = NULL; - column->format = cpl_strdup(SIZE_TYPE_FORM); - column->length = length; + column->format = cpl_strdup(SIZE_TYPE_FORM); + column->length = length; column->nullcount = length; return column; - } @@ -1046,10 +1048,10 @@ * See documentation of @c cpl_column_new_int(). */ -cpl_column *cpl_column_new_float(cpl_size length) +cpl_column * +cpl_column_new_float(cpl_size length) { - - cpl_column *column; + cpl_column *column; if (length < 0) { @@ -1064,12 +1066,11 @@ else column->values->f = NULL; - column->format = cpl_strdup(FLOAT_FORM); - column->length = length; + column->format = cpl_strdup(FLOAT_FORM); + column->length = length; column->nullcount = length; return column; - } @@ -1084,10 +1085,10 @@ * See documentation of @c cpl_column_new_int(). */ -cpl_column *cpl_column_new_float_complex(cpl_size length) +cpl_column * +cpl_column_new_float_complex(cpl_size length) { - - cpl_column *column; + cpl_column *column; if (length < 0) { @@ -1098,17 +1099,16 @@ column = cpl_column_new(CPL_TYPE_FLOAT_COMPLEX); if (length) - column->values->cf = - (float complex *)cpl_malloc(length * sizeof(float complex)); + column->values->cf = + (float complex *)cpl_malloc(length * sizeof(float complex)); else column->values->cf = NULL; - column->format = cpl_strdup(FLOAT_FORM); - column->length = length; + column->format = cpl_strdup(FLOAT_FORM); + column->length = length; column->nullcount = length; return column; - } @@ -1123,10 +1123,10 @@ * See documentation of @c cpl_column_new_int(). */ -cpl_column *cpl_column_new_double(cpl_size length) +cpl_column * +cpl_column_new_double(cpl_size length) { - - cpl_column *column; + cpl_column *column; if (length < 0) { @@ -1141,12 +1141,11 @@ else column->values->d = NULL; - column->format = cpl_strdup(DOUBLE_FORM); - column->length = length; + column->format = cpl_strdup(DOUBLE_FORM); + column->length = length; column->nullcount = length; return column; - } @@ -1161,10 +1160,10 @@ * See documentation of @c cpl_column_new_int(). */ -cpl_column *cpl_column_new_double_complex(cpl_size length) +cpl_column * +cpl_column_new_double_complex(cpl_size length) { - - cpl_column *column; + cpl_column *column; if (length < 0) { @@ -1175,17 +1174,16 @@ column = cpl_column_new(CPL_TYPE_DOUBLE_COMPLEX); if (length) - column->values->cd = - (double complex *)cpl_malloc(length * sizeof(double complex)); + column->values->cd = + (double complex *)cpl_malloc(length * sizeof(double complex)); else column->values->cd = NULL; - column->format = cpl_strdup(DOUBLE_FORM); - column->length = length; + column->format = cpl_strdup(DOUBLE_FORM); + column->length = length; column->nullcount = length; return column; - } @@ -1204,10 +1202,10 @@ * No memory is allocated for the single column elements. */ -cpl_column *cpl_column_new_string(cpl_size length) +cpl_column * +cpl_column_new_string(cpl_size length) { - - cpl_column *column; + cpl_column *column; if (length < 0) { @@ -1218,7 +1216,7 @@ column = cpl_column_new(CPL_TYPE_STRING); if (length) - column->values->s = (char **)cpl_calloc(length, sizeof (char *)); + column->values->s = (char **)cpl_calloc(length, sizeof(char *)); else column->values->s = NULL; @@ -1226,7 +1224,6 @@ column->length = length; return column; - } @@ -1246,10 +1243,10 @@ * @c CPL_ERROR_ILLEGAL_INPUT is set. Zero length columns are allowed. */ -cpl_column *cpl_column_new_array(cpl_type type, cpl_size length, cpl_size depth) +cpl_column * +cpl_column_new_array(cpl_type type, cpl_size length, cpl_size depth) { - - cpl_column *column; + cpl_column *column; if (length < 0 || depth < 0) { @@ -1260,49 +1257,48 @@ column = cpl_column_new(type | CPL_TYPE_POINTER); if (length) - column->values->array = cpl_calloc(length, sizeof (cpl_array *)); + column->values->array = cpl_calloc(length, sizeof(cpl_array *)); else column->values->array = NULL; - switch(type & ~CPL_TYPE_POINTER) { - case CPL_TYPE_INT: - column->format = cpl_strdup(INT_FORM); - break; - case CPL_TYPE_LONG: - column->format = cpl_strdup(LONG_FORM); - break; - case CPL_TYPE_LONG_LONG: - column->format = cpl_strdup(LONG_LONG_FORM); - break; - case CPL_TYPE_SIZE: - column->format = cpl_strdup(SIZE_TYPE_FORM); - break; - case CPL_TYPE_FLOAT: - column->format = cpl_strdup(FLOAT_FORM); - break; - case CPL_TYPE_DOUBLE: - column->format = cpl_strdup(DOUBLE_FORM); - break; - case CPL_TYPE_FLOAT_COMPLEX: - column->format = cpl_strdup(FLOAT_FORM); - break; - case CPL_TYPE_DOUBLE_COMPLEX: - column->format = cpl_strdup(DOUBLE_FORM); - break; - case CPL_TYPE_STRING: - column->format = cpl_strdup(STRING_FORM); - break; - default: - cpl_column_delete(column); - cpl_error_set_(CPL_ERROR_INVALID_TYPE); - return NULL; + switch (type & ~CPL_TYPE_POINTER) { + case CPL_TYPE_INT: + column->format = cpl_strdup(INT_FORM); + break; + case CPL_TYPE_LONG: + column->format = cpl_strdup(LONG_FORM); + break; + case CPL_TYPE_LONG_LONG: + column->format = cpl_strdup(LONG_LONG_FORM); + break; + case CPL_TYPE_SIZE: + column->format = cpl_strdup(SIZE_TYPE_FORM); + break; + case CPL_TYPE_FLOAT: + column->format = cpl_strdup(FLOAT_FORM); + break; + case CPL_TYPE_DOUBLE: + column->format = cpl_strdup(DOUBLE_FORM); + break; + case CPL_TYPE_FLOAT_COMPLEX: + column->format = cpl_strdup(FLOAT_FORM); + break; + case CPL_TYPE_DOUBLE_COMPLEX: + column->format = cpl_strdup(DOUBLE_FORM); + break; + case CPL_TYPE_STRING: + column->format = cpl_strdup(STRING_FORM); + break; + default: + cpl_column_delete(column); + cpl_error_set_(CPL_ERROR_INVALID_TYPE); + return NULL; } column->length = length; column->depth = depth; return column; - } /* @@ -1318,12 +1314,13 @@ * from the two input columns, which must be of matching type and length. * For each row any invalid values are or'ed together to form the output value. */ -cpl_column *cpl_column_new_complex_from_arrays(const cpl_column * real, - const cpl_column * imag) -{ - cpl_column * self = NULL; - const size_t length = (size_t)cpl_column_get_size(real); - const cpl_type type = cpl_column_get_type(imag); +cpl_column * +cpl_column_new_complex_from_arrays(const cpl_column *real, + const cpl_column *imag) +{ + cpl_column *self = NULL; + const size_t length = (size_t)cpl_column_get_size(real); + const cpl_type type = cpl_column_get_type(imag); if (real == NULL) { @@ -1336,18 +1333,22 @@ } if ((size_t)cpl_column_get_size(imag) != length) { - (void)cpl_error_set_message_(CPL_ERROR_INCOMPATIBLE_INPUT, "type=%s. " + (void)cpl_error_set_message_(CPL_ERROR_INCOMPATIBLE_INPUT, + "type=%s. " "length: %zu != %zu", - cpl_type_get_name(type), - length, (size_t)cpl_column_get_size(imag)); + cpl_type_get_name(type), length, + (size_t)cpl_column_get_size(imag)); return NULL; } if (cpl_column_get_type(imag) != type) { - (void)cpl_error_set_message_(CPL_ERROR_TYPE_MISMATCH, "types: %s != %s." - " length=%zu", cpl_type_get_name(type), - cpl_type_get_name - (cpl_column_get_type(imag)), length); + (void)cpl_error_set_message_(CPL_ERROR_TYPE_MISMATCH, + "types: %s != %s." + " length=%zu", + cpl_type_get_name(type), + cpl_type_get_name( + cpl_column_get_type(imag)), + length); return NULL; } @@ -1359,15 +1360,15 @@ for (size_t i = 0; i < length; i++) { if ((real->nullcount == 0 || real->null[i] == 0) && (imag->nullcount == 0 || imag->null[i] == 0)) { - self->values->cd[i] = - real->values->d[i] + - imag->values->d[i] * I; + self->values->cd[i] = + real->values->d[i] + imag->values->d[i] * I; cpl_column_unset_null(self, i); } } } - } else if (type == CPL_TYPE_FLOAT) { + } + else if (type == CPL_TYPE_FLOAT) { self = cpl_column_new_float_complex((cpl_size)length); if ((size_t)real->nullcount < length && @@ -1375,18 +1376,19 @@ for (size_t i = 0; i < length; i++) { if ((real->nullcount == 0 || real->null[i] == 0) && (imag->nullcount == 0 || imag->null[i] == 0)) { - self->values->cf[i] = - real->values->f[i] + - imag->values->f[i] * I; + self->values->cf[i] = + real->values->f[i] + imag->values->f[i] * I; cpl_column_unset_null(self, i); } } } - } else { - (void)cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, "type=%s. " - "length=%zu", cpl_type_get_name(type), - length); + } + else { + (void)cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, + "type=%s. " + "length=%zu", + cpl_type_get_name(type), length); return NULL; } @@ -1465,7 +1467,8 @@ * As it can be seen, only CPL_TYPE_BOOL is currently supported. */ -cpl_error_code cpl_column_set_save_type(cpl_column *column, cpl_type type) +cpl_error_code +cpl_column_set_save_type(cpl_column *column, cpl_type type) { if (column == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -1473,106 +1476,105 @@ type &= ~CPL_TYPE_POINTER; switch (column->type & ~CPL_TYPE_POINTER) { - case CPL_TYPE_INT: - switch (type) { - case CPL_TYPE_INT: /* List of legal types, ended by break */ - case CPL_TYPE_BOOL: - case CPL_TYPE_CHAR: - case CPL_TYPE_UCHAR: - case CPL_TYPE_SHORT: - break; - default: - return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); - } - break; - case CPL_TYPE_LONG: - switch (type) { - case CPL_TYPE_LONG: /* List of legal types, ended by break */ case CPL_TYPE_INT: - case CPL_TYPE_BOOL: - case CPL_TYPE_CHAR: - case CPL_TYPE_UCHAR: - case CPL_TYPE_SHORT: + switch (type) { + case CPL_TYPE_INT: /* List of legal types, ended by break */ + case CPL_TYPE_BOOL: + case CPL_TYPE_CHAR: + case CPL_TYPE_UCHAR: + case CPL_TYPE_SHORT: + break; + default: + return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); + } break; - default: - return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); - } - break; - case CPL_TYPE_LONG_LONG: - switch (type) { - case CPL_TYPE_LONG_LONG: /* List of legal types, ended by break */ case CPL_TYPE_LONG: - case CPL_TYPE_INT: - case CPL_TYPE_BOOL: - case CPL_TYPE_CHAR: - case CPL_TYPE_UCHAR: - case CPL_TYPE_SHORT: + switch (type) { + case CPL_TYPE_LONG: /* List of legal types, ended by break */ + case CPL_TYPE_INT: + case CPL_TYPE_BOOL: + case CPL_TYPE_CHAR: + case CPL_TYPE_UCHAR: + case CPL_TYPE_SHORT: + break; + default: + return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); + } break; - default: - return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); - } - break; - case CPL_TYPE_SIZE: - switch (type) { - case CPL_TYPE_LONG_LONG: /* List of legal types, ended by break */ - case CPL_TYPE_LONG: - case CPL_TYPE_INT: - case CPL_TYPE_BOOL: - case CPL_TYPE_CHAR: - case CPL_TYPE_UCHAR: - case CPL_TYPE_SHORT: + case CPL_TYPE_LONG_LONG: + switch (type) { + case CPL_TYPE_LONG_LONG: /* List of legal types, ended by break */ + case CPL_TYPE_LONG: + case CPL_TYPE_INT: + case CPL_TYPE_BOOL: + case CPL_TYPE_CHAR: + case CPL_TYPE_UCHAR: + case CPL_TYPE_SHORT: + break; + default: + return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); + } break; - default: - return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); - } - break; - case CPL_TYPE_FLOAT: - switch (type) { - case CPL_TYPE_FLOAT: /* List of legal types, ended by break */ + case CPL_TYPE_SIZE: + switch (type) { + case CPL_TYPE_LONG_LONG: /* List of legal types, ended by break */ + case CPL_TYPE_LONG: + case CPL_TYPE_INT: + case CPL_TYPE_BOOL: + case CPL_TYPE_CHAR: + case CPL_TYPE_UCHAR: + case CPL_TYPE_SHORT: + break; + default: + return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); + } break; - default: - return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); - } - break; - case CPL_TYPE_DOUBLE: - switch (type) { - case CPL_TYPE_DOUBLE: /* List of legal types, ended by break */ + case CPL_TYPE_FLOAT: + switch (type) { + case CPL_TYPE_FLOAT: /* List of legal types, ended by break */ + break; + default: + return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); + } break; - default: - return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); - } - break; - case CPL_TYPE_FLOAT_COMPLEX: - switch (type) { - case CPL_TYPE_FLOAT_COMPLEX: /* List of legal types, ended by break */ + case CPL_TYPE_DOUBLE: + switch (type) { + case CPL_TYPE_DOUBLE: /* List of legal types, ended by break */ + break; + default: + return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); + } break; - default: - return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); - } - break; - case CPL_TYPE_DOUBLE_COMPLEX: - switch (type) { - case CPL_TYPE_DOUBLE_COMPLEX: /* List of legal types, ended by break */ + case CPL_TYPE_FLOAT_COMPLEX: + switch (type) { + case CPL_TYPE_FLOAT_COMPLEX: /* List of legal types, ended by break */ + break; + default: + return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); + } break; - default: - return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); - } - break; - case CPL_TYPE_STRING: - switch (type) { - case CPL_TYPE_STRING: /* List of legal types, ended by break */ + case CPL_TYPE_DOUBLE_COMPLEX: + switch (type) { + case CPL_TYPE_DOUBLE_COMPLEX: /* List of legal types, ended by break */ + break; + default: + return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); + } + break; + case CPL_TYPE_STRING: + switch (type) { + case CPL_TYPE_STRING: /* List of legal types, ended by break */ + break; + default: + return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); + } break; default: return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); - } - break; - default: - return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); } column->savetype = type; return CPL_ERROR_NONE; - } @@ -1588,7 +1590,8 @@ * If the column is @c NULL, @c CPL_ERROR_NULL_INPUT is set. */ -cpl_type cpl_column_get_save_type(const cpl_column *column) +cpl_type +cpl_column_get_save_type(const cpl_column *column) { if (column) return column->savetype; @@ -1630,10 +1633,10 @@ * @c cpl_column_unwrap() destructor can be used. */ -cpl_column *cpl_column_wrap_int(int *data, cpl_size length) +cpl_column * +cpl_column_wrap_int(int *data, cpl_size length) { - - cpl_column *column; + cpl_column *column; if (data == NULL) { @@ -1648,12 +1651,11 @@ column = cpl_column_new(CPL_TYPE_INT); - column->format = cpl_strdup(INT_FORM); - column->length = length; + column->format = cpl_strdup(INT_FORM); + column->length = length; column->values->i = data; return column; - } @@ -1688,10 +1690,10 @@ * @c cpl_column_unwrap() destructor can be used. */ -cpl_column *cpl_column_wrap_long(long *data, cpl_size length) +cpl_column * +cpl_column_wrap_long(long *data, cpl_size length) { - - cpl_column *column; + cpl_column *column; if (data == NULL) { @@ -1706,12 +1708,11 @@ column = cpl_column_new(CPL_TYPE_LONG); - column->format = cpl_strdup(LONG_FORM); - column->length = length; + column->format = cpl_strdup(LONG_FORM); + column->length = length; column->values->l = data; return column; - } @@ -1746,10 +1747,10 @@ * @c cpl_column_unwrap() destructor can be used. */ -cpl_column *cpl_column_wrap_long_long(long long *data, cpl_size length) +cpl_column * +cpl_column_wrap_long_long(long long *data, cpl_size length) { - - cpl_column *column; + cpl_column *column; if (data == NULL) { @@ -1764,12 +1765,11 @@ column = cpl_column_new(CPL_TYPE_LONG_LONG); - column->format = cpl_strdup(LONG_LONG_FORM); - column->length = length; + column->format = cpl_strdup(LONG_LONG_FORM); + column->length = length; column->values->ll = data; return column; - } @@ -1804,10 +1804,10 @@ * @c cpl_column_unwrap() destructor can be used. */ -cpl_column *cpl_column_wrap_cplsize(cpl_size *data, cpl_size length) +cpl_column * +cpl_column_wrap_cplsize(cpl_size *data, cpl_size length) { - - cpl_column *column; + cpl_column *column; if (data == NULL) { @@ -1822,12 +1822,11 @@ column = cpl_column_new(CPL_TYPE_SIZE); - column->format = cpl_strdup(SIZE_TYPE_FORM); - column->length = length; + column->format = cpl_strdup(SIZE_TYPE_FORM); + column->length = length; column->values->sz = data; return column; - } @@ -1843,10 +1842,10 @@ * See documentation of function @c cpl_column_wrap_int(). */ -cpl_column *cpl_column_wrap_float(float *data, cpl_size length) +cpl_column * +cpl_column_wrap_float(float *data, cpl_size length) { - - cpl_column *column; + cpl_column *column; if (data == NULL) { @@ -1861,12 +1860,11 @@ column = cpl_column_new(CPL_TYPE_FLOAT); - column->format = cpl_strdup(FLOAT_FORM); - column->length = length; + column->format = cpl_strdup(FLOAT_FORM); + column->length = length; column->values->f = data; return column; - } @@ -1882,10 +1880,10 @@ * See documentation of function @c cpl_column_wrap_int(). */ -cpl_column *cpl_column_wrap_float_complex(float complex *data, cpl_size length) +cpl_column * +cpl_column_wrap_float_complex(float complex *data, cpl_size length) { - - cpl_column *column; + cpl_column *column; if (data == NULL) { @@ -1900,12 +1898,11 @@ column = cpl_column_new(CPL_TYPE_FLOAT_COMPLEX); - column->format = cpl_strdup(FLOAT_FORM); - column->length = length; + column->format = cpl_strdup(FLOAT_FORM); + column->length = length; column->values->cf = data; return column; - } @@ -1921,10 +1918,10 @@ * See documentation of function @c cpl_column_wrap_int(). */ -cpl_column *cpl_column_wrap_double(double *data, cpl_size length) +cpl_column * +cpl_column_wrap_double(double *data, cpl_size length) { - - cpl_column *column; + cpl_column *column; if (data == NULL) { @@ -1939,12 +1936,11 @@ column = cpl_column_new(CPL_TYPE_DOUBLE); - column->format = cpl_strdup(DOUBLE_FORM); - column->length = length; + column->format = cpl_strdup(DOUBLE_FORM); + column->length = length; column->values->d = data; return column; - } @@ -1960,11 +1956,10 @@ * See documentation of function @c cpl_column_wrap_int(). */ -cpl_column *cpl_column_wrap_double_complex(double complex *data, - cpl_size length) +cpl_column * +cpl_column_wrap_double_complex(double complex *data, cpl_size length) { - - cpl_column *column; + cpl_column *column; if (data == NULL) { @@ -1979,12 +1974,11 @@ column = cpl_column_new(CPL_TYPE_DOUBLE_COMPLEX); - column->format = cpl_strdup(DOUBLE_FORM); - column->length = length; + column->format = cpl_strdup(DOUBLE_FORM); + column->length = length; column->values->cd = data; return column; - } @@ -2000,10 +1994,10 @@ * See documentation of function @c cpl_column_wrap_int(). */ -cpl_column *cpl_column_wrap_string(char **data, cpl_size length) +cpl_column * +cpl_column_wrap_string(char **data, cpl_size length) { - - cpl_column *column; + cpl_column *column; if (data == NULL) { @@ -2018,12 +2012,11 @@ column = cpl_column_new(CPL_TYPE_STRING); - column->format = cpl_strdup(STRING_FORM); - column->length = length; + column->format = cpl_strdup(STRING_FORM); + column->length = length; column->values->s = data; return column; - } @@ -2049,11 +2042,11 @@ * be copied. */ -cpl_error_code cpl_column_copy_data(cpl_column *column, const double *data) +cpl_error_code +cpl_column_copy_data(cpl_column *column, const double *data) { - - cpl_size length = cpl_column_get_size(column); - cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + cpl_type type = cpl_column_get_type(column); if (data == NULL || column == NULL) @@ -2064,48 +2057,42 @@ switch (type) { - case CPL_TYPE_INT: - { - int *idata = cpl_column_get_data_int(column); - while (length--) - *idata++ = *data++; - break; - } - case CPL_TYPE_LONG: - { - long *ldata = cpl_column_get_data_long(column); - while (length--) - *ldata++ = *data++; - break; - } - case CPL_TYPE_LONG_LONG: - { - long long *lldata = cpl_column_get_data_long_long(column); - while (length--) - *lldata++ = *data++; - break; - } - case CPL_TYPE_SIZE: - { - cpl_size *szdata = cpl_column_get_data_cplsize(column); - while (length--) - *szdata++ = *data++; - break; - } - case CPL_TYPE_FLOAT: - { - float *fdata = cpl_column_get_data_float(column); - while (length--) - *fdata++ = *data++; - break; - } - case CPL_TYPE_DOUBLE: - { - memcpy(column->values->d, data, column->length * sizeof(double)); - break; - } - default: - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + case CPL_TYPE_INT: { + int *idata = cpl_column_get_data_int(column); + while (length--) + *idata++ = *data++; + break; + } + case CPL_TYPE_LONG: { + long *ldata = cpl_column_get_data_long(column); + while (length--) + *ldata++ = *data++; + break; + } + case CPL_TYPE_LONG_LONG: { + long long *lldata = cpl_column_get_data_long_long(column); + while (length--) + *lldata++ = *data++; + break; + } + case CPL_TYPE_SIZE: { + cpl_size *szdata = cpl_column_get_data_cplsize(column); + while (length--) + *szdata++ = *data++; + break; + } + case CPL_TYPE_FLOAT: { + float *fdata = cpl_column_get_data_float(column); + while (length--) + *fdata++ = *data++; + break; + } + case CPL_TYPE_DOUBLE: { + memcpy(column->values->d, data, column->length * sizeof(double)); + break; + } + default: + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } if (column->null) @@ -2114,7 +2101,6 @@ column->nullcount = 0; return CPL_ERROR_NONE; - } @@ -2140,13 +2126,12 @@ * be copied. */ -cpl_error_code cpl_column_copy_data_complex(cpl_column *column, - const double complex *data) +cpl_error_code +cpl_column_copy_data_complex(cpl_column *column, const double complex *data) { + cpl_size length = cpl_column_get_size(column); + cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); - cpl_type type = cpl_column_get_type(column); - if (data == NULL || column == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -2156,19 +2141,18 @@ switch (type) { - case CPL_TYPE_FLOAT_COMPLEX: - { - float complex *cfdata = cpl_column_get_data_float_complex(column); - while (length--) - *cfdata++ = *data++; - break; - } - case CPL_TYPE_DOUBLE_COMPLEX: - memcpy(column->values->cd, data, - column->length * sizeof(double complex)); - break; - default: - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + case CPL_TYPE_FLOAT_COMPLEX: { + float complex *cfdata = cpl_column_get_data_float_complex(column); + while (length--) + *cfdata++ = *data++; + break; + } + case CPL_TYPE_DOUBLE_COMPLEX: + memcpy(column->values->cd, data, + column->length * sizeof(double complex)); + break; + default: + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } if (column->null) @@ -2177,7 +2161,6 @@ column->nullcount = 0; return CPL_ERROR_NONE; - } @@ -2201,10 +2184,10 @@ * zero, no values would be copied. */ -cpl_error_code cpl_column_copy_data_int(cpl_column *column, const int *data) +cpl_error_code +cpl_column_copy_data_int(cpl_column *column, const int *data) { - - cpl_type type = cpl_column_get_type(column); + cpl_type type = cpl_column_get_type(column); if (data == NULL || column == NULL) @@ -2224,7 +2207,6 @@ column->nullcount = 0; return CPL_ERROR_NONE; - } @@ -2248,10 +2230,10 @@ * zero, no values would be copied. */ -cpl_error_code cpl_column_copy_data_long(cpl_column *column, const long *data) +cpl_error_code +cpl_column_copy_data_long(cpl_column *column, const long *data) { - - cpl_type type = cpl_column_get_type(column); + cpl_type type = cpl_column_get_type(column); if (data == NULL || column == NULL) @@ -2271,7 +2253,6 @@ column->nullcount = 0; return CPL_ERROR_NONE; - } @@ -2295,11 +2276,10 @@ * zero, no values would be copied. */ -cpl_error_code cpl_column_copy_data_long_long(cpl_column *column, - const long long *data) +cpl_error_code +cpl_column_copy_data_long_long(cpl_column *column, const long long *data) { - - cpl_type type = cpl_column_get_type(column); + cpl_type type = cpl_column_get_type(column); if (data == NULL || column == NULL) @@ -2319,7 +2299,6 @@ column->nullcount = 0; return CPL_ERROR_NONE; - } @@ -2343,11 +2322,10 @@ * zero, no values would be copied. */ -cpl_error_code cpl_column_copy_data_cplsize(cpl_column *column, - const cpl_size *data) +cpl_error_code +cpl_column_copy_data_cplsize(cpl_column *column, const cpl_size *data) { - - cpl_type type = cpl_column_get_type(column); + cpl_type type = cpl_column_get_type(column); if (data == NULL || column == NULL) @@ -2367,7 +2345,6 @@ column->nullcount = 0; return CPL_ERROR_NONE; - } @@ -2385,11 +2362,10 @@ * See documentation of function @c cpl_column_copy_data_int(). */ -cpl_error_code cpl_column_copy_data_float(cpl_column *column, - const float *data) +cpl_error_code +cpl_column_copy_data_float(cpl_column *column, const float *data) { - - cpl_type type = cpl_column_get_type(column); + cpl_type type = cpl_column_get_type(column); if (data == NULL || column == NULL) @@ -2409,7 +2385,6 @@ column->nullcount = 0; return CPL_ERROR_NONE; - } @@ -2427,11 +2402,11 @@ * See documentation of function @c cpl_column_copy_data_int(). */ -cpl_error_code cpl_column_copy_data_float_complex(cpl_column *column, - const float complex *data) +cpl_error_code +cpl_column_copy_data_float_complex(cpl_column *column, + const float complex *data) { - - cpl_type type = cpl_column_get_type(column); + cpl_type type = cpl_column_get_type(column); if (data == NULL || column == NULL) @@ -2451,7 +2426,6 @@ column->nullcount = 0; return CPL_ERROR_NONE; - } @@ -2469,11 +2443,10 @@ * See documentation of function @c cpl_column_copy_data_int(). */ -cpl_error_code cpl_column_copy_data_double(cpl_column *column, - const double *data) +cpl_error_code +cpl_column_copy_data_double(cpl_column *column, const double *data) { - - cpl_type type = cpl_column_get_type(column); + cpl_type type = cpl_column_get_type(column); if (data == NULL || column == NULL) @@ -2493,7 +2466,6 @@ column->nullcount = 0; return CPL_ERROR_NONE; - } @@ -2511,11 +2483,11 @@ * See documentation of function @c cpl_column_copy_data_int(). */ -cpl_error_code cpl_column_copy_data_double_complex(cpl_column *column, - const double complex *data) +cpl_error_code +cpl_column_copy_data_double_complex(cpl_column *column, + const double complex *data) { - - cpl_type type = cpl_column_get_type(column); + cpl_type type = cpl_column_get_type(column); if (data == NULL || column == NULL) @@ -2535,7 +2507,6 @@ column->nullcount = 0; return CPL_ERROR_NONE; - } @@ -2561,12 +2532,11 @@ * copied. */ -cpl_error_code cpl_column_copy_data_string(cpl_column *column, - const char **data) +cpl_error_code +cpl_column_copy_data_string(cpl_column *column, const char **data) { - - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); if (data == NULL || column == NULL) @@ -2586,7 +2556,6 @@ } return CPL_ERROR_NONE; - } @@ -2602,16 +2571,16 @@ * nothing is done, and no error is set. */ -void cpl_column_delete(cpl_column *column) +void +cpl_column_delete(cpl_column *column) { - - cpl_type type; + cpl_type type; cpl_column_values *values; - cpl_size length; + cpl_size length; if (column != NULL) { - type = cpl_column_get_type(column); + type = cpl_column_get_type(column); values = cpl_column_get_values(column); length = cpl_column_get_size(column); @@ -2628,7 +2597,6 @@ cpl_array_delete(column->dimensions); cpl_free(column); } - } @@ -2647,11 +2615,11 @@ * If the input column is @c NULL, nothing is done, and no error is set. */ -void *cpl_column_unwrap(cpl_column *column) +void * +cpl_column_unwrap(cpl_column *column) { - void *d = NULL; - + if (column != NULL) { cpl_column_values *values = cpl_column_get_values(column); d = (void *)values->i; @@ -2670,7 +2638,6 @@ } return d; - } @@ -2690,10 +2657,10 @@ * column is not a string column, nothing is done. */ -void cpl_column_delete_but_strings(cpl_column *column) +void +cpl_column_delete_but_strings(cpl_column *column) { - - cpl_type type; + cpl_type type; cpl_column_values *values; @@ -2721,7 +2688,6 @@ } else cpl_error_set_(CPL_ERROR_INVALID_TYPE); - } @@ -2741,10 +2707,10 @@ * column is not an array column, nothing is done. */ -void cpl_column_delete_but_arrays(cpl_column *column) +void +cpl_column_delete_but_arrays(cpl_column *column) { - - cpl_type type; + cpl_type type; cpl_column_values *values; @@ -2774,7 +2740,6 @@ } else cpl_error_set_(CPL_ERROR_INVALID_TYPE); - } @@ -2792,11 +2757,9 @@ * If the new name is a @c NULL pointer the column will be nameless. */ -cpl_error_code cpl_column_set_name(cpl_column *column, const char *name) +cpl_error_code +cpl_column_set_name(cpl_column *column, const char *name) { - - - if (column == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -2809,7 +2772,6 @@ column->name = NULL; return CPL_ERROR_NONE; - } @@ -2832,16 +2794,15 @@ * has no name, a @c NULL is returned. */ -const char *cpl_column_get_name(const cpl_column *column) +const char * +cpl_column_get_name(const cpl_column *column) { - if (column) return column->name; cpl_error_set_(CPL_ERROR_NULL_INPUT); return NULL; - } @@ -2859,11 +2820,11 @@ * The unit string associated to a column has no effect on any operation * performed on columns, and it must be considered just an optional * description of the content of a column. - */ + */ -cpl_error_code cpl_column_set_unit(cpl_column *column, const char *unit) +cpl_error_code +cpl_column_set_unit(cpl_column *column, const char *unit) { - if (column == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -2876,7 +2837,6 @@ column->unit = NULL; return CPL_ERROR_NONE; - } @@ -2899,16 +2859,15 @@ * has no unit, a @c NULL is returned. */ -const char *cpl_column_get_unit(const cpl_column *column) +const char * +cpl_column_get_unit(const cpl_column *column) { - if (column) return column->unit; cpl_error_set_(CPL_ERROR_NULL_INPUT); return NULL; - } @@ -2930,9 +2889,9 @@ * The given format string must conform to the legal standard C formats. */ -cpl_error_code cpl_column_set_format(cpl_column *column, const char *format) +cpl_error_code +cpl_column_set_format(cpl_column *column, const char *format) { - cpl_type type; @@ -2948,39 +2907,38 @@ column->format = cpl_strdup(format); else switch (type & ~CPL_TYPE_POINTER) { - case CPL_TYPE_INT: - column->format = cpl_strdup(INT_FORM); - break; - case CPL_TYPE_LONG: - column->format = cpl_strdup(LONG_FORM); - break; - case CPL_TYPE_LONG_LONG: - column->format = cpl_strdup(LONG_LONG_FORM); - break; - case CPL_TYPE_SIZE: - column->format = cpl_strdup(SIZE_TYPE_FORM); - break; - case CPL_TYPE_FLOAT: - column->format = cpl_strdup(FLOAT_FORM); - break; - case CPL_TYPE_DOUBLE: - column->format = cpl_strdup(DOUBLE_FORM); - break; - case CPL_TYPE_FLOAT_COMPLEX: - column->format = cpl_strdup(FLOAT_FORM); - break; - case CPL_TYPE_DOUBLE_COMPLEX: - column->format = cpl_strdup(DOUBLE_FORM); - break; - case CPL_TYPE_STRING: - column->format = cpl_strdup(STRING_FORM); - break; - default: - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + case CPL_TYPE_INT: + column->format = cpl_strdup(INT_FORM); + break; + case CPL_TYPE_LONG: + column->format = cpl_strdup(LONG_FORM); + break; + case CPL_TYPE_LONG_LONG: + column->format = cpl_strdup(LONG_LONG_FORM); + break; + case CPL_TYPE_SIZE: + column->format = cpl_strdup(SIZE_TYPE_FORM); + break; + case CPL_TYPE_FLOAT: + column->format = cpl_strdup(FLOAT_FORM); + break; + case CPL_TYPE_DOUBLE: + column->format = cpl_strdup(DOUBLE_FORM); + break; + case CPL_TYPE_FLOAT_COMPLEX: + column->format = cpl_strdup(FLOAT_FORM); + break; + case CPL_TYPE_DOUBLE_COMPLEX: + column->format = cpl_strdup(DOUBLE_FORM); + break; + case CPL_TYPE_STRING: + column->format = cpl_strdup(STRING_FORM); + break; + default: + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } return CPL_ERROR_NONE; - } @@ -3003,16 +2961,15 @@ * also a @c NULL input column. */ -const char *cpl_column_get_format(const cpl_column *column) +const char * +cpl_column_get_format(const cpl_column *column) { - if (column) return column->format; cpl_error_set_(CPL_ERROR_NULL_INPUT); return NULL; - } @@ -3027,7 +2984,8 @@ * * No @c NULL check is performed. */ -static inline cpl_size cpl_column_get_size_(const cpl_column *self) +static inline cpl_size +cpl_column_get_size_(const cpl_column *self) { return self->length; } @@ -3045,16 +3003,15 @@ * If the column is @em NULL, zero is returned. */ -cpl_size cpl_column_get_size(const cpl_column *column) +cpl_size +cpl_column_get_size(const cpl_column *column) { - if (column) return cpl_column_get_size_(column); cpl_error_set_(CPL_ERROR_NULL_INPUT); return 0; - } /* @@ -3070,16 +3027,15 @@ * If the column is @em NULL, zero is returned. */ -cpl_size cpl_column_get_depth(const cpl_column *column) +cpl_size +cpl_column_get_depth(const cpl_column *column) { - if (column) return column->depth; cpl_error_set_(CPL_ERROR_NULL_INPUT); return 0; - } @@ -3097,9 +3053,9 @@ * If the column is @em NULL, zero is returned. */ -cpl_size cpl_column_get_dimensions(const cpl_column *column) +cpl_size +cpl_column_get_dimensions(const cpl_column *column) { - if (column) { if (cpl_column_get_type(column) & CPL_TYPE_POINTER) if (column->dimensions) @@ -3110,7 +3066,6 @@ cpl_error_set_(CPL_ERROR_NULL_INPUT); return 0; - } @@ -3133,10 +3088,9 @@ * Set the dimensions of a column. */ -cpl_error_code cpl_column_set_dimensions(cpl_column *column, - const cpl_array *dimensions) +cpl_error_code +cpl_column_set_dimensions(cpl_column *column, const cpl_array *dimensions) { - cpl_type type; cpl_size ndim; cpl_size size = 1; @@ -3175,7 +3129,6 @@ return cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); return CPL_ERROR_NONE; - } @@ -3196,12 +3149,12 @@ * Get size of one dimension of the column. */ -cpl_size cpl_column_get_dimension(const cpl_column *column, cpl_size indx) +cpl_size +cpl_column_get_dimension(const cpl_column *column, cpl_size indx) { - cpl_type type; cpl_size ndim; - + if (column == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -3216,7 +3169,6 @@ type = cpl_column_get_type(column); if (type & CPL_TYPE_POINTER) { - if (column->dimensions) ndim = cpl_array_get_size(column->dimensions); else @@ -3231,13 +3183,9 @@ return cpl_array_get(column->dimensions, indx, NULL); else return column->depth; - } return cpl_error_set_(CPL_ERROR_UNSUPPORTED_MODE); - - - } @@ -3251,7 +3199,8 @@ * * No @c NULL check is performed. */ -static inline cpl_type cpl_column_get_type_(const cpl_column *self) +static inline cpl_type +cpl_column_get_type_(const cpl_column *self) { return self->type; } @@ -3268,16 +3217,15 @@ * If the column is @c NULL, @c CPL_ERROR_NULL_INPUT is set. */ -cpl_type cpl_column_get_type(const cpl_column *column) +cpl_type +cpl_column_get_type(const cpl_column *column) { - if (column) return cpl_column_get_type_(column); cpl_error_set_(CPL_ERROR_NULL_INPUT); return CPL_TYPE_INVALID; - } @@ -3295,9 +3243,10 @@ * That excludes CPL_TYPE_STRING and CPL_TYPE_POINTER. */ -static inline int cpl_column_base_type_invalid_(const cpl_column * self, - cpl_size indx, - cpl_size length) +static inline int +cpl_column_base_type_invalid_(const cpl_column *self, + cpl_size indx, + cpl_size length) { if (self->nullcount == 0) return 0; @@ -3326,11 +3275,11 @@ * is set. */ -int cpl_column_is_invalid(const cpl_column *column, cpl_size indx) +int +cpl_column_is_invalid(const cpl_column *column, cpl_size indx) { - - cpl_type type; - cpl_size length; + cpl_type type; + cpl_size length; if (column == NULL) { @@ -3372,10 +3321,10 @@ * @c NULL pointer, a @c CPL_ERROR_NULL_INPUT is set. */ -int cpl_column_has_invalid(const cpl_column *column) +int +cpl_column_has_invalid(const cpl_column *column) { - - cpl_type type = cpl_column_get_type(column); + cpl_type type = cpl_column_get_type(column); cpl_size length = cpl_column_get_size(column); @@ -3398,7 +3347,6 @@ } return (column->nullcount > 0 ? 1 : 0); - } @@ -3415,11 +3363,11 @@ * @c NULL pointer, a @c CPL_ERROR_NULL_INPUT is set. */ -int cpl_column_has_valid(const cpl_column *column) +int +cpl_column_has_valid(const cpl_column *column) { - - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); if (column == NULL) { @@ -3428,24 +3376,19 @@ } if (type == CPL_TYPE_STRING) { - while (length--) if (column->values->s[length]) return 1; return 0; - } if (type & CPL_TYPE_POINTER) { - while (length--) if (column->values->array[length]) return 1; return 0; - } return (column->nullcount < length ? 1 : 0); - } @@ -3461,7 +3404,8 @@ * @note No @c NULL check is performed, type checks performed with assert() */ -static inline cpl_size cpl_column_get_invalid_numerical(const cpl_column *self) +static inline cpl_size +cpl_column_get_invalid_numerical(const cpl_column *self) { #ifndef NDEBUG const cpl_type type = cpl_column_get_type(self); @@ -3489,12 +3433,12 @@ * a @c NULL pointer, an error @c CPL_ERROR_NULL_INPUT is set. */ -cpl_size cpl_column_count_invalid(cpl_column *column) +cpl_size +cpl_column_count_invalid(cpl_column *column) { - - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); - char **p; + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + char **p; cpl_array **a; @@ -3504,29 +3448,24 @@ } if (type == CPL_TYPE_STRING) { - p = column->values->s; column->nullcount = 0; while (length--) if (*p++ == NULL) column->nullcount++; - } if (type & CPL_TYPE_POINTER) { - a = column->values->array; column->nullcount = 0; while (length--) if (*a++ == NULL) column->nullcount++; - } return column->nullcount; - } @@ -3548,12 +3487,12 @@ * a @c NULL pointer, an error @c CPL_ERROR_NULL_INPUT is set. */ -cpl_size cpl_column_count_invalid_const(const cpl_column *column) +cpl_size +cpl_column_count_invalid_const(const cpl_column *column) { - - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); - char **p; + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + char **p; cpl_array **a; cpl_size nullcount; @@ -3566,29 +3505,24 @@ nullcount = column->nullcount; if (type == CPL_TYPE_STRING) { - p = column->values->s; nullcount = 0; while (length--) if (*p++ == NULL) nullcount++; - } if (type & CPL_TYPE_POINTER) { - a = column->values->array; nullcount = 0; while (length--) if (*a++ == NULL) nullcount++; - } return nullcount; - } @@ -3612,7 +3546,8 @@ * internally and the actual column data. */ -int *cpl_column_get_data_int(cpl_column *self) +int * +cpl_column_get_data_int(cpl_column *self) { CPL_COLUMN_GET_POINTER(self, i, CPL_TYPE_INT); } @@ -3632,7 +3567,8 @@ * @c CPL_ERROR_TYPE_MISMATCH is set. */ -const int *cpl_column_get_data_int_const(const cpl_column *self) +const int * +cpl_column_get_data_int_const(const cpl_column *self) { CPL_COLUMN_GET_POINTER(self, i, CPL_TYPE_INT); } @@ -3658,7 +3594,8 @@ * internally and the actual column data. */ -long *cpl_column_get_data_long(cpl_column *self) +long * +cpl_column_get_data_long(cpl_column *self) { CPL_COLUMN_GET_POINTER(self, l, CPL_TYPE_LONG); } @@ -3678,7 +3615,8 @@ * @c CPL_ERROR_TYPE_MISMATCH is set. */ -const long *cpl_column_get_data_long_const(const cpl_column *self) +const long * +cpl_column_get_data_long_const(const cpl_column *self) { CPL_COLUMN_GET_POINTER(self, l, CPL_TYPE_LONG); } @@ -3704,7 +3642,8 @@ * internally and the actual column data. */ -long long *cpl_column_get_data_long_long(cpl_column *self) +long long * +cpl_column_get_data_long_long(cpl_column *self) { CPL_COLUMN_GET_POINTER(self, ll, CPL_TYPE_LONG_LONG); } @@ -3724,7 +3663,8 @@ * @c CPL_ERROR_TYPE_MISMATCH is set. */ -const long long *cpl_column_get_data_long_long_const(const cpl_column *self) +const long long * +cpl_column_get_data_long_long_const(const cpl_column *self) { CPL_COLUMN_GET_POINTER(self, ll, CPL_TYPE_LONG_LONG); } @@ -3750,7 +3690,8 @@ * internally and the actual column data. */ -cpl_size *cpl_column_get_data_cplsize(cpl_column *self) +cpl_size * +cpl_column_get_data_cplsize(cpl_column *self) { CPL_COLUMN_GET_POINTER(self, sz, CPL_TYPE_SIZE); } @@ -3770,7 +3711,8 @@ * @c CPL_ERROR_TYPE_MISMATCH is set. */ -const cpl_size *cpl_column_get_data_cplsize_const(const cpl_column *self) +const cpl_size * +cpl_column_get_data_cplsize_const(const cpl_column *self) { CPL_COLUMN_GET_POINTER(self, sz, CPL_TYPE_SIZE); } @@ -3792,7 +3734,8 @@ * See documentation of function cpl_column_get_data_int(). */ -float *cpl_column_get_data_float(cpl_column *self) +float * +cpl_column_get_data_float(cpl_column *self) { CPL_COLUMN_GET_POINTER(self, f, CPL_TYPE_FLOAT); } @@ -3814,7 +3757,8 @@ * See documentation of function cpl_column_get_data_int(). */ -const float *cpl_column_get_data_float_const(const cpl_column *self) +const float * +cpl_column_get_data_float_const(const cpl_column *self) { CPL_COLUMN_GET_POINTER(self, f, CPL_TYPE_FLOAT); } @@ -3836,7 +3780,8 @@ * See documentation of function cpl_column_get_data_int(). */ -float complex *cpl_column_get_data_float_complex(cpl_column *self) +float complex * +cpl_column_get_data_float_complex(cpl_column *self) { CPL_COLUMN_GET_POINTER(self, cf, CPL_TYPE_FLOAT_COMPLEX); } @@ -3882,7 +3827,8 @@ * See documentation of function cpl_column_get_data_int(). */ -double *cpl_column_get_data_double(cpl_column *self) +double * +cpl_column_get_data_double(cpl_column *self) { CPL_COLUMN_GET_POINTER(self, d, CPL_TYPE_DOUBLE); } @@ -3904,7 +3850,8 @@ * See documentation of function cpl_column_get_data_int(). */ -const double *cpl_column_get_data_double_const(const cpl_column *self) +const double * +cpl_column_get_data_double_const(const cpl_column *self) { CPL_COLUMN_GET_POINTER(self, d, CPL_TYPE_DOUBLE); } @@ -3926,7 +3873,8 @@ * See documentation of function cpl_column_get_data_int(). */ -double complex *cpl_column_get_data_double_complex(cpl_column *self) +double complex * +cpl_column_get_data_double_complex(cpl_column *self) { CPL_COLUMN_GET_POINTER(self, cd, CPL_TYPE_DOUBLE_COMPLEX); } @@ -3972,7 +3920,8 @@ * See documentation of function cpl_column_get_data_int(). */ -char **cpl_column_get_data_string(cpl_column *self) +char ** +cpl_column_get_data_string(cpl_column *self) { CPL_COLUMN_GET_POINTER(self, s, CPL_TYPE_STRING); } @@ -3994,9 +3943,9 @@ * See documentation of function cpl_column_get_data_int(). */ -const char **cpl_column_get_data_string_const(const cpl_column *self) +const char ** +cpl_column_get_data_string_const(const cpl_column *self) { - cpl_type type = cpl_column_get_type(self); @@ -4032,7 +3981,8 @@ * See documentation of function cpl_column_get_data_int(). */ -cpl_array **cpl_column_get_data_array(cpl_column *self) +cpl_array ** +cpl_column_get_data_array(cpl_column *self) { /* Function body modified from below */ const cpl_type type = cpl_column_get_type(self); @@ -4067,9 +4017,9 @@ * See documentation of function cpl_column_get_data_int(). */ -const cpl_array **cpl_column_get_data_array_const(const cpl_column *self) +const cpl_array ** +cpl_column_get_data_array_const(const cpl_column *self) { - /* Function body modified from above */ const cpl_type type = cpl_column_get_type(self); @@ -4111,16 +4061,15 @@ * and the actual column data. */ -cpl_column_flag *cpl_column_get_data_invalid(cpl_column *column) +cpl_column_flag * +cpl_column_get_data_invalid(cpl_column *column) { - if (column == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return NULL; } return column->null; - } @@ -4142,14 +4091,12 @@ const cpl_column_flag * cpl_column_get_data_invalid_const(const cpl_column *column) { - if (column == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return NULL; } return column->null; - } @@ -4186,12 +4133,13 @@ * and the actual column data. */ -cpl_error_code cpl_column_set_data_invalid(cpl_column *column, - cpl_column_flag *nulls, cpl_size nullcount) +cpl_error_code +cpl_column_set_data_invalid(cpl_column *column, + cpl_column_flag *nulls, + cpl_size nullcount) { - - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); if (column == NULL) @@ -4215,7 +4163,6 @@ length = cpl_column_get_size(column); if (nullcount < 0) { - /* * The total number of NULLs must be evaluated internally. If a * null flag buffer was not passed, the total number of NULLs is @@ -4257,7 +4204,6 @@ column->nullcount = nullcount; return 0; - } @@ -4285,14 +4231,13 @@ * depth implies removing any information about column dimensions. */ -cpl_error_code cpl_column_set_depth(cpl_column *column, cpl_size depth) +cpl_error_code +cpl_column_set_depth(cpl_column *column, cpl_size depth) { - - - cpl_array *array; + cpl_array *array; cpl_column *acolumn; - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); if (column == NULL) @@ -4321,7 +4266,6 @@ } return CPL_ERROR_NONE; - } @@ -4347,19 +4291,19 @@ * of failure, the old data buffer is left intact. */ -cpl_error_code cpl_column_set_size(cpl_column *column, cpl_size new_length) +cpl_error_code +cpl_column_set_size(cpl_column *column, cpl_size new_length) { + cpl_type type = cpl_column_get_type(column); + cpl_size old_length = cpl_column_get_size(column); + size_t element_size = cpl_column_type_size(type); + size_t null_size = old_length * sizeof(cpl_column_flag); + size_t new_size = element_size * new_length; + cpl_size i = 0; - cpl_type type = cpl_column_get_type(column); - cpl_size old_length = cpl_column_get_size(column); - size_t element_size = cpl_column_type_size(type); - size_t null_size = old_length * sizeof(cpl_column_flag); - size_t new_size = element_size * new_length; - cpl_size i = 0; - - cpl_column_flag *np = NULL; - char **sp; - cpl_array **ap; + cpl_column_flag *np = NULL; + char **sp; + cpl_array **ap; if (column == NULL) @@ -4368,35 +4312,36 @@ if (new_length < 0) return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); - if (new_length == old_length) /* Resizing is unnecessary */ + if (new_length == old_length) /* Resizing is unnecessary */ return CPL_ERROR_NONE; - if (new_length == 0) { /* Resizing to zero */ + if (new_length == 0) { /* Resizing to zero */ if (type & CPL_TYPE_POINTER) { switch (type & ~CPL_TYPE_POINTER) { - case CPL_TYPE_INT: - case CPL_TYPE_LONG: - case CPL_TYPE_LONG_LONG: - case CPL_TYPE_SIZE: - case CPL_TYPE_FLOAT: - case CPL_TYPE_DOUBLE: - case CPL_TYPE_FLOAT_COMPLEX: - case CPL_TYPE_DOUBLE_COMPLEX: - case CPL_TYPE_STRING: + case CPL_TYPE_INT: + case CPL_TYPE_LONG: + case CPL_TYPE_LONG_LONG: + case CPL_TYPE_SIZE: + case CPL_TYPE_FLOAT: + case CPL_TYPE_DOUBLE: + case CPL_TYPE_FLOAT_COMPLEX: + case CPL_TYPE_DOUBLE_COMPLEX: + case CPL_TYPE_STRING: - for (i = 0; i < old_length; i++) - if (column->values->array[i]) - cpl_array_delete(column->values->array[i]); + for (i = 0; i < old_length; i++) + if (column->values->array[i]) + cpl_array_delete(column->values->array[i]); - cpl_free((void *)column->values->array); + cpl_free((void *)column->values->array); - break; + break; - default: - break; + default: + break; } - } else { + } + else { if (type == CPL_TYPE_STRING) { for (i = 0; i < old_length; i++) cpl_free(column->values->s[i]); @@ -4414,58 +4359,61 @@ return CPL_ERROR_NONE; } - if (old_length == 0) { /* Resizing from zero */ + if (old_length == 0) { /* Resizing from zero */ if (type & CPL_TYPE_POINTER) { switch (type & ~CPL_TYPE_POINTER) { - case CPL_TYPE_INT: - case CPL_TYPE_LONG: - case CPL_TYPE_LONG_LONG: - case CPL_TYPE_SIZE: - case CPL_TYPE_FLOAT: - case CPL_TYPE_DOUBLE: - case CPL_TYPE_FLOAT_COMPLEX: - case CPL_TYPE_DOUBLE_COMPLEX: - case CPL_TYPE_STRING: - column->values->array = - cpl_calloc(new_length, sizeof(cpl_array *)); - break; - default: - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + case CPL_TYPE_INT: + case CPL_TYPE_LONG: + case CPL_TYPE_LONG_LONG: + case CPL_TYPE_SIZE: + case CPL_TYPE_FLOAT: + case CPL_TYPE_DOUBLE: + case CPL_TYPE_FLOAT_COMPLEX: + case CPL_TYPE_DOUBLE_COMPLEX: + case CPL_TYPE_STRING: + column->values->array = + cpl_calloc(new_length, sizeof(cpl_array *)); + break; + default: + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } - } else { + } + else { switch (type) { - case CPL_TYPE_INT: - column->values->i = cpl_malloc(new_length * sizeof(int)); - break; - case CPL_TYPE_LONG: - column->values->l = cpl_malloc(new_length * sizeof(long)); - break; - case CPL_TYPE_LONG_LONG: - column->values->ll = cpl_malloc(new_length * sizeof(long long)); - break; - case CPL_TYPE_SIZE: - column->values->sz = cpl_malloc(new_length * sizeof(cpl_size)); - break; - case CPL_TYPE_FLOAT: - column->values->f = cpl_malloc(new_length * sizeof(float)); - break; - case CPL_TYPE_DOUBLE: - column->values->d = cpl_malloc(new_length * sizeof(double)); - break; - case CPL_TYPE_FLOAT_COMPLEX: - column->values->cf = - cpl_malloc(new_length * sizeof(float complex)); - break; - case CPL_TYPE_DOUBLE_COMPLEX: - column->values->cd = - cpl_malloc(new_length * sizeof(double complex)); - break; - case CPL_TYPE_STRING: - column->values->s = cpl_calloc(new_length, sizeof(char *)); - break; - default: - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + case CPL_TYPE_INT: + column->values->i = cpl_malloc(new_length * sizeof(int)); + break; + case CPL_TYPE_LONG: + column->values->l = cpl_malloc(new_length * sizeof(long)); + break; + case CPL_TYPE_LONG_LONG: + column->values->ll = + cpl_malloc(new_length * sizeof(long long)); + break; + case CPL_TYPE_SIZE: + column->values->sz = + cpl_malloc(new_length * sizeof(cpl_size)); + break; + case CPL_TYPE_FLOAT: + column->values->f = cpl_malloc(new_length * sizeof(float)); + break; + case CPL_TYPE_DOUBLE: + column->values->d = cpl_malloc(new_length * sizeof(double)); + break; + case CPL_TYPE_FLOAT_COMPLEX: + column->values->cf = + cpl_malloc(new_length * sizeof(float complex)); + break; + case CPL_TYPE_DOUBLE_COMPLEX: + column->values->cd = + cpl_malloc(new_length * sizeof(double complex)); + break; + case CPL_TYPE_STRING: + column->values->s = cpl_calloc(new_length, sizeof(char *)); + break; + default: + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } } @@ -4483,7 +4431,6 @@ */ if (column->null) { - /* * If the null flags buffer exists, it should be reallocated * first. @@ -4493,7 +4440,6 @@ column->null = cpl_realloc((void *)column->null, null_size); if (new_length < old_length) { - /* * If the column was shortened, check whether some * NULLs are still present in column. If no NULL is @@ -4506,15 +4452,13 @@ if (*np++) column->nullcount++; - if (column->nullcount == new_length || - column->nullcount == 0) { + if (column->nullcount == new_length || column->nullcount == 0) { if (column->null) cpl_free(column->null); column->null = NULL; } } else { - /* * Pad with 1s the extra space (by definition, extra space * in the column data buffer is not initialized, therefore @@ -4528,20 +4472,16 @@ *np++ = 1; column->nullcount += new_length - old_length; - } } else { - /* * We don't need to take care of string columns here, because * they take automatically care of their own NULLs. */ if (type != CPL_TYPE_STRING) { - if (new_length > old_length) { - /* * If the null flags buffer doesn't exist, it is * either because there were no NULLs, or there @@ -4554,9 +4494,8 @@ */ if (column->nullcount == 0) { - - column->null = cpl_calloc(new_length, - sizeof(cpl_column_flag)); + column->null = + cpl_calloc(new_length, sizeof(cpl_column_flag)); np = column->null + old_length; for (i = old_length; i < new_length; i++) @@ -4564,12 +4503,11 @@ column->nullcount = new_length - old_length; } - else /* There were just nulls */ + else /* There were just nulls */ column->nullcount = new_length; } - else if (column->nullcount) /* Column of nulls shortened */ + else if (column->nullcount) /* Column of nulls shortened */ column->nullcount = new_length; - } } @@ -4613,7 +4551,6 @@ } return CPL_ERROR_NONE; - } @@ -4641,50 +4578,51 @@ * array columns. */ -double cpl_column_get(const cpl_column *column, cpl_size indx, int *null) +double +cpl_column_get(const cpl_column *column, cpl_size indx, int *null) { - - const cpl_type type = cpl_column_get_type(column); + const cpl_type type = cpl_column_get_type(column); if (type & CPL_TYPE_POINTER) { switch (type & ~CPL_TYPE_POINTER) { - case CPL_TYPE_INT: - case CPL_TYPE_LONG: - case CPL_TYPE_LONG_LONG: - case CPL_TYPE_SIZE: - case CPL_TYPE_FLOAT: - case CPL_TYPE_DOUBLE: - case CPL_TYPE_FLOAT_COMPLEX: - case CPL_TYPE_DOUBLE_COMPLEX: - case CPL_TYPE_STRING: - cpl_error_set_(CPL_ERROR_INVALID_TYPE); - break; - default: - cpl_error_set_(CPL_ERROR_NULL_INPUT); - break; + case CPL_TYPE_INT: + case CPL_TYPE_LONG: + case CPL_TYPE_LONG_LONG: + case CPL_TYPE_SIZE: + case CPL_TYPE_FLOAT: + case CPL_TYPE_DOUBLE: + case CPL_TYPE_FLOAT_COMPLEX: + case CPL_TYPE_DOUBLE_COMPLEX: + case CPL_TYPE_STRING: + cpl_error_set_(CPL_ERROR_INVALID_TYPE); + break; + default: + cpl_error_set_(CPL_ERROR_NULL_INPUT); + break; } - } else { + } + else { switch (type) { - case CPL_TYPE_INT: - return (double)cpl_column_get_int(column, indx, null); - case CPL_TYPE_LONG: - return (double)cpl_column_get_long(column, indx, null); - case CPL_TYPE_LONG_LONG: - return (double)cpl_column_get_long_long(column, indx, null); - case CPL_TYPE_SIZE: - return (double)cpl_column_get_cplsize(column, indx, null); - case CPL_TYPE_FLOAT: - return (double)cpl_column_get_float(column, indx, null); - case CPL_TYPE_DOUBLE: - return cpl_column_get_double(column, indx, null); - case CPL_TYPE_STRING: - case CPL_TYPE_FLOAT_COMPLEX: - case CPL_TYPE_DOUBLE_COMPLEX: - cpl_error_set_(CPL_ERROR_INVALID_TYPE); - break; - default: - cpl_error_set_(CPL_ERROR_NULL_INPUT); - break; + case CPL_TYPE_INT: + return (double)cpl_column_get_int(column, indx, null); + case CPL_TYPE_LONG: + return (double)cpl_column_get_long(column, indx, null); + case CPL_TYPE_LONG_LONG: + return (double)cpl_column_get_long_long(column, indx, null); + case CPL_TYPE_SIZE: + return (double)cpl_column_get_cplsize(column, indx, null); + case CPL_TYPE_FLOAT: + return (double)cpl_column_get_float(column, indx, null); + case CPL_TYPE_DOUBLE: + return cpl_column_get_double(column, indx, null); + case CPL_TYPE_STRING: + case CPL_TYPE_FLOAT_COMPLEX: + case CPL_TYPE_DOUBLE_COMPLEX: + cpl_error_set_(CPL_ERROR_INVALID_TYPE); + break; + default: + cpl_error_set_(CPL_ERROR_NULL_INPUT); + break; } } @@ -4692,7 +4630,6 @@ *null = -1; return 0.0; - } @@ -4720,47 +4657,48 @@ * array columns. */ -double complex cpl_column_get_complex(const cpl_column *column, - cpl_size indx, int *null) +double complex +cpl_column_get_complex(const cpl_column *column, cpl_size indx, int *null) { - - const cpl_type type = cpl_column_get_type(column); + const cpl_type type = cpl_column_get_type(column); if (type & CPL_TYPE_POINTER) { switch (type & ~CPL_TYPE_POINTER) { - case CPL_TYPE_INT: - case CPL_TYPE_LONG: - case CPL_TYPE_LONG_LONG: - case CPL_TYPE_SIZE: - case CPL_TYPE_FLOAT: - case CPL_TYPE_DOUBLE: - case CPL_TYPE_FLOAT_COMPLEX: - case CPL_TYPE_DOUBLE_COMPLEX: - case CPL_TYPE_STRING: - cpl_error_set_(CPL_ERROR_INVALID_TYPE); - break; - default: - cpl_error_set_(CPL_ERROR_NULL_INPUT); - break; + case CPL_TYPE_INT: + case CPL_TYPE_LONG: + case CPL_TYPE_LONG_LONG: + case CPL_TYPE_SIZE: + case CPL_TYPE_FLOAT: + case CPL_TYPE_DOUBLE: + case CPL_TYPE_FLOAT_COMPLEX: + case CPL_TYPE_DOUBLE_COMPLEX: + case CPL_TYPE_STRING: + cpl_error_set_(CPL_ERROR_INVALID_TYPE); + break; + default: + cpl_error_set_(CPL_ERROR_NULL_INPUT); + break; } - } else { + } + else { switch (type) { - case CPL_TYPE_FLOAT_COMPLEX: - return (double complex)cpl_column_get_float_complex(column, indx, null); - case CPL_TYPE_DOUBLE_COMPLEX: - return cpl_column_get_double_complex(column, indx, null); - case CPL_TYPE_INT: - case CPL_TYPE_LONG: - case CPL_TYPE_LONG_LONG: - case CPL_TYPE_SIZE: - case CPL_TYPE_FLOAT: - case CPL_TYPE_DOUBLE: - case CPL_TYPE_STRING: - cpl_error_set_(CPL_ERROR_INVALID_TYPE); - break; - default: - cpl_error_set_(CPL_ERROR_NULL_INPUT); - break; + case CPL_TYPE_FLOAT_COMPLEX: + return (double complex)cpl_column_get_float_complex(column, + indx, null); + case CPL_TYPE_DOUBLE_COMPLEX: + return cpl_column_get_double_complex(column, indx, null); + case CPL_TYPE_INT: + case CPL_TYPE_LONG: + case CPL_TYPE_LONG_LONG: + case CPL_TYPE_SIZE: + case CPL_TYPE_FLOAT: + case CPL_TYPE_DOUBLE: + case CPL_TYPE_STRING: + cpl_error_set_(CPL_ERROR_INVALID_TYPE); + break; + default: + cpl_error_set_(CPL_ERROR_NULL_INPUT); + break; } } @@ -4768,7 +4706,6 @@ *null = -1; return 0.0; - } @@ -4786,28 +4723,30 @@ * @return 0 on error 1 on success * */ -static inline int cpl_get_error_check_(const char * fcall, - const cpl_column * self, - cpl_size indx, int * null, - cpl_type e_type) -{ - cpl_size length; - cpl_type type; - int isnull; +static inline int +cpl_get_error_check_(const char *fcall, + const cpl_column *self, + cpl_size indx, + int *null, + cpl_type e_type) +{ + cpl_size length; + cpl_type type; + int isnull; if (null) *null = -1; if (self == NULL) { cpl_error_set(fcall, CPL_ERROR_NULL_INPUT); - return 0; + return 0; } length = cpl_column_get_size_(self); if (indx < 0 || indx >= length) { cpl_error_set(fcall, CPL_ERROR_ACCESS_OUT_OF_RANGE); - return 0; + return 0; } type = cpl_column_get_type_(self); @@ -4818,7 +4757,7 @@ } isnull = cpl_column_base_type_invalid_(self, indx, length); - + if (null) *null = isnull; @@ -4851,15 +4790,13 @@ * an error condition (-1). */ -int cpl_column_get_int(const cpl_column *column, cpl_size indx, int *null) +int +cpl_column_get_int(const cpl_column *column, cpl_size indx, int *null) { - - if (cpl_get_error_check_(cpl_func, column, indx, null, - CPL_TYPE_INT) == 0) + if (cpl_get_error_check_(cpl_func, column, indx, null, CPL_TYPE_INT) == 0) return 0; return column->values->i[indx]; - } @@ -4885,15 +4822,13 @@ * an error condition (-1). */ -long cpl_column_get_long(const cpl_column *column, cpl_size indx, int *null) +long +cpl_column_get_long(const cpl_column *column, cpl_size indx, int *null) { - - if (cpl_get_error_check_(cpl_func, column, indx, null, - CPL_TYPE_LONG) == 0) + if (cpl_get_error_check_(cpl_func, column, indx, null, CPL_TYPE_LONG) == 0) return 0; return column->values->l[indx]; - } @@ -4922,13 +4857,11 @@ long long cpl_column_get_long_long(const cpl_column *column, cpl_size indx, int *null) { - if (cpl_get_error_check_(cpl_func, column, indx, null, CPL_TYPE_LONG_LONG) == 0) return 0; return column->values->ll[indx]; - } @@ -4954,16 +4887,13 @@ * an error condition (-1). */ -cpl_size cpl_column_get_cplsize(const cpl_column *column, cpl_size indx, - int *null) +cpl_size +cpl_column_get_cplsize(const cpl_column *column, cpl_size indx, int *null) { - - if (cpl_get_error_check_(cpl_func, column, indx, null, - CPL_TYPE_SIZE) == 0) + if (cpl_get_error_check_(cpl_func, column, indx, null, CPL_TYPE_SIZE) == 0) return 0; return column->values->sz[indx]; - } @@ -4982,15 +4912,13 @@ * documentation of the function cpl_column_get_int(). */ -float cpl_column_get_float(const cpl_column *column, cpl_size indx, int *null) +float +cpl_column_get_float(const cpl_column *column, cpl_size indx, int *null) { - - if (cpl_get_error_check_(cpl_func, column, indx, null, - CPL_TYPE_FLOAT) == 0) + if (cpl_get_error_check_(cpl_func, column, indx, null, CPL_TYPE_FLOAT) == 0) return 0; return column->values->f[indx]; - } @@ -5009,16 +4937,14 @@ * documentation of the function cpl_column_get_int(). */ -float complex cpl_column_get_float_complex(const cpl_column *column, - cpl_size indx, int *null) +float complex +cpl_column_get_float_complex(const cpl_column *column, cpl_size indx, int *null) { - if (cpl_get_error_check_(cpl_func, column, indx, null, CPL_TYPE_FLOAT_COMPLEX) == 0) return 0; return column->values->cf[indx]; - } /* @@ -5036,15 +4962,14 @@ * documentation of the function cpl_column_get_int(). */ -double cpl_column_get_double(const cpl_column *column, cpl_size indx, int *null) +double +cpl_column_get_double(const cpl_column *column, cpl_size indx, int *null) { - - if (cpl_get_error_check_(cpl_func, column, indx, null, - CPL_TYPE_DOUBLE) == 0) + if (cpl_get_error_check_(cpl_func, column, indx, null, CPL_TYPE_DOUBLE) == + 0) return 0; return column->values->d[indx]; - } @@ -5063,16 +4988,16 @@ * documentation of the function cpl_column_get_int(). */ -double complex cpl_column_get_double_complex(const cpl_column *column, - cpl_size indx, int *null) +double complex +cpl_column_get_double_complex(const cpl_column *column, + cpl_size indx, + int *null) { - if (cpl_get_error_check_(cpl_func, column, indx, null, CPL_TYPE_DOUBLE_COMPLEX) == 0) return 0; return column->values->cd[indx]; - } @@ -5101,8 +5026,9 @@ * column element is required, this function should be called as an * argument of the function @c cpl_strdup(). */ - -char *cpl_column_get_string(cpl_column *self, cpl_size indx) + +char * +cpl_column_get_string(cpl_column *self, cpl_size indx) { CPL_COLUMN_GET_VALUE(self, indx, s, type == CPL_TYPE_STRING); } @@ -5126,7 +5052,8 @@ * the @c CPL_ERROR_ACCESS_OUT_OF_RANGE is always set. */ -const char *cpl_column_get_string_const(const cpl_column *self, cpl_size indx) +const char * +cpl_column_get_string_const(const cpl_column *self, cpl_size indx) { CPL_COLUMN_GET_VALUE(self, indx, s, type == CPL_TYPE_STRING); } @@ -5158,7 +5085,8 @@ * argument of the function @c cpl_array_duplicate(). */ -cpl_array *cpl_column_get_array(cpl_column *self, cpl_size indx) +cpl_array * +cpl_column_get_array(cpl_column *self, cpl_size indx) { CPL_COLUMN_GET_VALUE(self, indx, array, type & CPL_TYPE_POINTER); } @@ -5182,8 +5110,8 @@ * the @c CPL_ERROR_ACCESS_OUT_OF_RANGE is always set. */ -const cpl_array *cpl_column_get_array_const(const cpl_column *self, - cpl_size indx) +const cpl_array * +cpl_column_get_array_const(const cpl_column *self, cpl_size indx) { CPL_COLUMN_GET_VALUE(self, indx, array, type & CPL_TYPE_POINTER); } @@ -5211,43 +5139,44 @@ * be used on array columns. */ -cpl_error_code cpl_column_set(cpl_column *column, cpl_size indx, double value) +cpl_error_code +cpl_column_set(cpl_column *column, cpl_size indx, double value) { - const cpl_type type = cpl_column_get_type(column); cpl_error_code code; - if (column == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); + if (column == NULL) + return cpl_error_set_(CPL_ERROR_NULL_INPUT); switch (type) { - case CPL_TYPE_INT: - code = cpl_column_set_int(column, indx, value); - break; - case CPL_TYPE_LONG: - code = cpl_column_set_long(column, indx, value); - break; - case CPL_TYPE_LONG_LONG: - code = cpl_column_set_long_long(column, indx, value); - break; - case CPL_TYPE_SIZE: - code = cpl_column_set_cplsize(column, indx, value); - break; - case CPL_TYPE_FLOAT: - code = cpl_column_set_float(column, indx, value); - break; - case CPL_TYPE_DOUBLE: - code = cpl_column_set_double(column, indx, value); - break; - case CPL_TYPE_FLOAT_COMPLEX: - code = cpl_column_set_float_complex(column, indx, value); - break; - case CPL_TYPE_DOUBLE_COMPLEX: - code = cpl_column_set_double_complex(column, indx, value); - break; - default: - return cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, "%s", - cpl_type_get_name(type)); + case CPL_TYPE_INT: + code = cpl_column_set_int(column, indx, value); + break; + case CPL_TYPE_LONG: + code = cpl_column_set_long(column, indx, value); + break; + case CPL_TYPE_LONG_LONG: + code = cpl_column_set_long_long(column, indx, value); + break; + case CPL_TYPE_SIZE: + code = cpl_column_set_cplsize(column, indx, value); + break; + case CPL_TYPE_FLOAT: + code = cpl_column_set_float(column, indx, value); + break; + case CPL_TYPE_DOUBLE: + code = cpl_column_set_double(column, indx, value); + break; + case CPL_TYPE_FLOAT_COMPLEX: + code = cpl_column_set_float_complex(column, indx, value); + break; + case CPL_TYPE_DOUBLE_COMPLEX: + code = cpl_column_set_double_complex(column, indx, value); + break; + default: + return cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, "%s", + cpl_type_get_name(type)); } return code ? cpl_error_set_where_() : CPL_ERROR_NONE; @@ -5276,24 +5205,23 @@ * be used on array columns. */ -cpl_error_code cpl_column_set_complex(cpl_column *column, - cpl_size indx, double complex value) +cpl_error_code +cpl_column_set_complex(cpl_column *column, cpl_size indx, double complex value) { - const cpl_type type = cpl_column_get_type(column); - if (column == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); + if (column == NULL) + return cpl_error_set_(CPL_ERROR_NULL_INPUT); switch (type) { - case CPL_TYPE_FLOAT_COMPLEX: - return cpl_column_set_float_complex(column, indx, value); - case CPL_TYPE_DOUBLE_COMPLEX: - return cpl_column_set_double_complex(column, indx, value); - default: - return cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, "%s", - cpl_type_get_name(type)); + case CPL_TYPE_FLOAT_COMPLEX: + return cpl_column_set_float_complex(column, indx, value); + case CPL_TYPE_DOUBLE_COMPLEX: + return cpl_column_set_double_complex(column, indx, value); + default: + return cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, "%s", + cpl_type_get_name(type)); } - } /* @@ -5310,22 +5238,24 @@ * */ inline static int -cpl_set_error_check_(const char *fcall, const cpl_column *self, - cpl_size indx, cpl_type e_type) +cpl_set_error_check_(const char *fcall, + const cpl_column *self, + cpl_size indx, + cpl_type e_type) { - cpl_size length; - cpl_type type; + cpl_size length; + cpl_type type; if (self == NULL) { cpl_error_set(fcall, CPL_ERROR_NULL_INPUT); - return 0; + return 0; } length = cpl_column_get_size_(self); if (indx < 0 || indx >= length) { cpl_error_set(fcall, CPL_ERROR_ACCESS_OUT_OF_RANGE); - return 0; + return 0; } type = cpl_column_get_type_(self); @@ -5360,11 +5290,10 @@ * from 0. */ -cpl_error_code cpl_column_set_int(cpl_column *column, cpl_size indx, int value) +cpl_error_code +cpl_column_set_int(cpl_column *column, cpl_size indx, int value) { - - if (cpl_set_error_check_(cpl_func, column, indx, - CPL_TYPE_INT) == 0) { + if (cpl_set_error_check_(cpl_func, column, indx, CPL_TYPE_INT) == 0) { return cpl_error_get_code(); } @@ -5372,7 +5301,6 @@ cpl_column_unset_null(column, indx); return CPL_ERROR_NONE; - } @@ -5400,9 +5328,7 @@ cpl_error_code cpl_column_set_long(cpl_column *column, cpl_size indx, long value) { - - if (cpl_set_error_check_(cpl_func, column, indx, - CPL_TYPE_LONG) == 0) { + if (cpl_set_error_check_(cpl_func, column, indx, CPL_TYPE_LONG) == 0) { return cpl_error_get_code(); } @@ -5410,7 +5336,6 @@ cpl_column_unset_null(column, indx); return CPL_ERROR_NONE; - } @@ -5438,9 +5363,7 @@ cpl_error_code cpl_column_set_long_long(cpl_column *column, cpl_size indx, long long value) { - - if (cpl_set_error_check_(cpl_func, column, indx, - CPL_TYPE_LONG_LONG) == 0) { + if (cpl_set_error_check_(cpl_func, column, indx, CPL_TYPE_LONG_LONG) == 0) { return cpl_error_get_code(); } @@ -5448,7 +5371,6 @@ cpl_column_unset_null(column, indx); return CPL_ERROR_NONE; - } @@ -5476,9 +5398,7 @@ cpl_error_code cpl_column_set_cplsize(cpl_column *column, cpl_size indx, cpl_size value) { - - if (cpl_set_error_check_(cpl_func, column, indx, - CPL_TYPE_SIZE) == 0) { + if (cpl_set_error_check_(cpl_func, column, indx, CPL_TYPE_SIZE) == 0) { return cpl_error_get_code(); } @@ -5486,7 +5406,6 @@ cpl_column_unset_null(column, indx); return CPL_ERROR_NONE; - } @@ -5511,12 +5430,10 @@ * from 0. */ -cpl_error_code cpl_column_set_float(cpl_column *column, - cpl_size indx, float value) +cpl_error_code +cpl_column_set_float(cpl_column *column, cpl_size indx, float value) { - - if (cpl_set_error_check_(cpl_func, column, indx, - CPL_TYPE_FLOAT) == 0) { + if (cpl_set_error_check_(cpl_func, column, indx, CPL_TYPE_FLOAT) == 0) { return cpl_error_get_code(); } @@ -5524,7 +5441,6 @@ cpl_column_unset_null(column, indx); return CPL_ERROR_NONE; - } @@ -5549,12 +5465,13 @@ * from 0. */ -cpl_error_code cpl_column_set_float_complex(cpl_column *column, - cpl_size indx, float complex value) +cpl_error_code +cpl_column_set_float_complex(cpl_column *column, + cpl_size indx, + float complex value) { - - if (cpl_set_error_check_(cpl_func, column, indx, - CPL_TYPE_FLOAT_COMPLEX) == 0) { + if (cpl_set_error_check_(cpl_func, column, indx, CPL_TYPE_FLOAT_COMPLEX) == + 0) { return cpl_error_get_code(); } @@ -5562,7 +5479,6 @@ cpl_column_unset_null(column, indx); return CPL_ERROR_NONE; - } @@ -5587,12 +5503,10 @@ * from 0. */ -cpl_error_code cpl_column_set_double(cpl_column *column, cpl_size indx, - double value) +cpl_error_code +cpl_column_set_double(cpl_column *column, cpl_size indx, double value) { - - if (cpl_set_error_check_(cpl_func, column, indx, - CPL_TYPE_DOUBLE) == 0) { + if (cpl_set_error_check_(cpl_func, column, indx, CPL_TYPE_DOUBLE) == 0) { return cpl_error_get_code(); } @@ -5600,7 +5514,6 @@ cpl_column_unset_null(column, indx); return CPL_ERROR_NONE; - } @@ -5625,12 +5538,13 @@ * from 0. */ -cpl_error_code cpl_column_set_double_complex(cpl_column *column, cpl_size indx, - double complex value) +cpl_error_code +cpl_column_set_double_complex(cpl_column *column, + cpl_size indx, + double complex value) { - - if (cpl_set_error_check_(cpl_func, column, indx, - CPL_TYPE_DOUBLE_COMPLEX) == 0) { + if (cpl_set_error_check_(cpl_func, column, indx, CPL_TYPE_DOUBLE_COMPLEX) == + 0) { return cpl_error_get_code(); } @@ -5638,7 +5552,6 @@ cpl_column_unset_null(column, indx); return CPL_ERROR_NONE; - } @@ -5665,12 +5578,11 @@ * Column elements are counted starting from zero. */ -cpl_error_code cpl_column_set_string(cpl_column *column, - cpl_size indx, const char *string) +cpl_error_code +cpl_column_set_string(cpl_column *column, cpl_size indx, const char *string) { - - cpl_size length = cpl_column_get_size(column); - cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + cpl_type type = cpl_column_get_type(column); if (column == NULL) @@ -5691,7 +5603,6 @@ column->values->s[indx] = NULL; return CPL_ERROR_NONE; - } @@ -5720,13 +5631,12 @@ * Column elements are counted starting from zero. */ -cpl_error_code cpl_column_set_array(cpl_column *column, - cpl_size indx, const cpl_array *array) +cpl_error_code +cpl_column_set_array(cpl_column *column, cpl_size indx, const cpl_array *array) { - - cpl_size length = cpl_column_get_size(column); - cpl_type type = cpl_column_get_type(column); - cpl_type atype; + cpl_size length = cpl_column_get_size(column); + cpl_type type = cpl_column_get_type(column); + cpl_type atype; if (column == NULL) @@ -5755,7 +5665,6 @@ column->values->array[indx] = NULL; return CPL_ERROR_NONE; - } @@ -5777,11 +5686,11 @@ * starting from zero. */ -cpl_error_code cpl_column_set_invalid(cpl_column *column, cpl_size indx) +cpl_error_code +cpl_column_set_invalid(cpl_column *column, cpl_size indx) { - - cpl_size length = cpl_column_get_size(column); - cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + cpl_type type = cpl_column_get_type(column); if (column == NULL) @@ -5814,7 +5723,6 @@ column->null = cpl_calloc(column->length, sizeof(cpl_column_flag)); if (column->null[indx] == 0) { - column->null[indx] = 1; column->nullcount++; @@ -5823,11 +5731,9 @@ cpl_free(column->null); column->null = NULL; } - } return CPL_ERROR_NONE; - } @@ -5852,32 +5758,34 @@ * valid. To invalidate a column interval use @c cpl_column_fill_invalid(). */ -cpl_error_code cpl_column_fill(cpl_column *column, - cpl_size start, cpl_size count, double value) +cpl_error_code +cpl_column_fill(cpl_column *column, + cpl_size start, + cpl_size count, + double value) { - - const cpl_type type = cpl_column_get_type(column); + const cpl_type type = cpl_column_get_type(column); - if (column == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); + if (column == NULL) + return cpl_error_set_(CPL_ERROR_NULL_INPUT); switch (type) { - case CPL_TYPE_INT: - return cpl_column_fill_int(column, start, count, value); - case CPL_TYPE_LONG: - return cpl_column_fill_long(column, start, count, value); - case CPL_TYPE_LONG_LONG: - return cpl_column_fill_long_long(column, start, count, value); - case CPL_TYPE_SIZE: - return cpl_column_fill_cplsize(column, start, count, value); - case CPL_TYPE_FLOAT: - return cpl_column_fill_float(column, start, count, value); - case CPL_TYPE_DOUBLE: - return cpl_column_fill_double(column, start, count, value); - default: - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + case CPL_TYPE_INT: + return cpl_column_fill_int(column, start, count, value); + case CPL_TYPE_LONG: + return cpl_column_fill_long(column, start, count, value); + case CPL_TYPE_LONG_LONG: + return cpl_column_fill_long_long(column, start, count, value); + case CPL_TYPE_SIZE: + return cpl_column_fill_cplsize(column, start, count, value); + case CPL_TYPE_FLOAT: + return cpl_column_fill_float(column, start, count, value); + case CPL_TYPE_DOUBLE: + return cpl_column_fill_double(column, start, count, value); + default: + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } - } @@ -5903,24 +5811,26 @@ * @c cpl_column_fill_invalid(). */ -cpl_error_code cpl_column_fill_complex(cpl_column *column, cpl_size start, - cpl_size count, double complex value) +cpl_error_code +cpl_column_fill_complex(cpl_column *column, + cpl_size start, + cpl_size count, + double complex value) { - - const cpl_type type = cpl_column_get_type(column); + const cpl_type type = cpl_column_get_type(column); - if (column == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); + if (column == NULL) + return cpl_error_set_(CPL_ERROR_NULL_INPUT); switch (type) { - case CPL_TYPE_FLOAT_COMPLEX: - return cpl_column_fill_float_complex(column, start, count, value); - case CPL_TYPE_DOUBLE_COMPLEX: - return cpl_column_fill_double_complex(column, start, count, value); - default: - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + case CPL_TYPE_FLOAT_COMPLEX: + return cpl_column_fill_float_complex(column, start, count, value); + case CPL_TYPE_DOUBLE_COMPLEX: + return cpl_column_fill_double_complex(column, start, count, value); + default: + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } - } @@ -5949,13 +5859,15 @@ * the column is not modified and no error is set. */ -cpl_error_code cpl_column_fill_int(cpl_column *column, - cpl_size start, cpl_size count, int value) +cpl_error_code +cpl_column_fill_int(cpl_column *column, + cpl_size start, + cpl_size count, + int value) { - - cpl_size length = cpl_column_get_size(column); - cpl_type type = cpl_column_get_type(column); - int *ip; + cpl_size length = cpl_column_get_size(column); + cpl_type type = cpl_column_get_type(column); + int *ip; if (column == NULL) @@ -5984,7 +5896,6 @@ *ip++ = value; return CPL_ERROR_NONE; - } @@ -6013,13 +5924,15 @@ * the column is not modified and no error is set. */ -cpl_error_code cpl_column_fill_long(cpl_column *column, - cpl_size start, cpl_size count, long value) +cpl_error_code +cpl_column_fill_long(cpl_column *column, + cpl_size start, + cpl_size count, + long value) { - - cpl_size length = cpl_column_get_size(column); - cpl_type type = cpl_column_get_type(column); - long *lp; + cpl_size length = cpl_column_get_size(column); + cpl_type type = cpl_column_get_type(column); + long *lp; if (column == NULL) @@ -6048,7 +5961,6 @@ *lp++ = value; return CPL_ERROR_NONE; - } @@ -6079,12 +5991,13 @@ cpl_error_code cpl_column_fill_long_long(cpl_column *column, - cpl_size start, cpl_size count, long long value) + cpl_size start, + cpl_size count, + long long value) { - - cpl_size length = cpl_column_get_size(column); - cpl_type type = cpl_column_get_type(column); - long long *llp; + cpl_size length = cpl_column_get_size(column); + cpl_type type = cpl_column_get_type(column); + long long *llp; if (column == NULL) @@ -6113,7 +6026,6 @@ *llp++ = value; return CPL_ERROR_NONE; - } @@ -6142,14 +6054,15 @@ * the column is not modified and no error is set. */ -cpl_error_code cpl_column_fill_cplsize(cpl_column *column, - cpl_size start, cpl_size count, - cpl_size value) +cpl_error_code +cpl_column_fill_cplsize(cpl_column *column, + cpl_size start, + cpl_size count, + cpl_size value) { - - cpl_size length = cpl_column_get_size(column); - cpl_type type = cpl_column_get_type(column); - cpl_size *szp; + cpl_size length = cpl_column_get_size(column); + cpl_type type = cpl_column_get_type(column); + cpl_size *szp; if (column == NULL) @@ -6178,7 +6091,6 @@ *szp++ = value; return CPL_ERROR_NONE; - } @@ -6207,13 +6119,15 @@ * the column is not modified and no error is set. */ -cpl_error_code cpl_column_fill_float(cpl_column *column, cpl_size start, - cpl_size count, float value) +cpl_error_code +cpl_column_fill_float(cpl_column *column, + cpl_size start, + cpl_size count, + float value) { - - cpl_size length = cpl_column_get_size(column); - cpl_type type = cpl_column_get_type(column); - float *fp; + cpl_size length = cpl_column_get_size(column); + cpl_type type = cpl_column_get_type(column); + float *fp; if (column == NULL) @@ -6242,7 +6156,6 @@ *fp++ = value; return CPL_ERROR_NONE; - } @@ -6271,13 +6184,14 @@ * the column is not modified and no error is set. */ -cpl_error_code cpl_column_fill_float_complex(cpl_column *column, - cpl_size start, cpl_size count, - float complex value) +cpl_error_code +cpl_column_fill_float_complex(cpl_column *column, + cpl_size start, + cpl_size count, + float complex value) { - - cpl_size length = cpl_column_get_size(column); - cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + cpl_type type = cpl_column_get_type(column); float complex *fp; @@ -6307,7 +6221,6 @@ *fp++ = value; return CPL_ERROR_NONE; - } @@ -6336,13 +6249,15 @@ * the column is not modified and no error is set. */ -cpl_error_code cpl_column_fill_double(cpl_column *column, cpl_size start, - cpl_size count, double value) +cpl_error_code +cpl_column_fill_double(cpl_column *column, + cpl_size start, + cpl_size count, + double value) { - - cpl_size length = cpl_column_get_size(column); - cpl_type type = cpl_column_get_type(column); - double *dp; + cpl_size length = cpl_column_get_size(column); + cpl_type type = cpl_column_get_type(column); + double *dp; if (column == NULL) @@ -6371,7 +6286,6 @@ *dp++ = value; return CPL_ERROR_NONE; - } @@ -6400,15 +6314,16 @@ * the column is not modified and no error is set. */ -cpl_error_code cpl_column_fill_double_complex(cpl_column *column, - cpl_size start, cpl_size count, - double complex value) +cpl_error_code +cpl_column_fill_double_complex(cpl_column *column, + cpl_size start, + cpl_size count, + double complex value) { - - cpl_size length = cpl_column_get_size(column); - cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + cpl_type type = cpl_column_get_type(column); double complex *dp; - + if (column == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -6436,7 +6351,6 @@ *dp++ = value; return CPL_ERROR_NONE; - } @@ -6466,13 +6380,15 @@ * the column is not modified and no error is set. */ -cpl_error_code cpl_column_fill_string(cpl_column *column, cpl_size start, - cpl_size count, const char *value) +cpl_error_code +cpl_column_fill_string(cpl_column *column, + cpl_size start, + cpl_size count, + const char *value) { - - cpl_size length = cpl_column_get_size(column); - cpl_type type = cpl_column_get_type(column); - char **sp; + cpl_size length = cpl_column_get_size(column); + cpl_type type = cpl_column_get_type(column); + char **sp; if (column == NULL) @@ -6504,7 +6420,6 @@ } return CPL_ERROR_NONE; - } @@ -6537,15 +6452,17 @@ * the column is not modified and no error is set. */ -cpl_error_code cpl_column_fill_array(cpl_column *column, cpl_size start, - cpl_size count, const cpl_array *array) +cpl_error_code +cpl_column_fill_array(cpl_column *column, + cpl_size start, + cpl_size count, + const cpl_array *array) { - - cpl_size length = cpl_column_get_size(column); - cpl_type type = cpl_column_get_type(column); - cpl_type atype; + cpl_size length = cpl_column_get_size(column); + cpl_type type = cpl_column_get_type(column); + cpl_type atype; cpl_array **ap; - + if (column == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -6584,7 +6501,6 @@ } return CPL_ERROR_NONE; - } @@ -6612,22 +6528,21 @@ * elements are flagged as invalid. */ -cpl_error_code cpl_column_fill_invalid(cpl_column *column, - cpl_size start, cpl_size count) +cpl_error_code +cpl_column_fill_invalid(cpl_column *column, cpl_size start, cpl_size count) { - - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); - cpl_size c; - cpl_column_flag *np; - char **sp; - cpl_array **ap; + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + cpl_size c; + cpl_column_flag *np; + char **sp; + cpl_array **ap; if (column == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); - if (count < 0) + if (count < 0) return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); if (count == 0) @@ -6652,7 +6567,6 @@ c = count; if (type == CPL_TYPE_STRING) { - sp = column->values->s + start; while (c--) { @@ -6667,10 +6581,9 @@ } if (type & CPL_TYPE_POINTER) { - ap = column->values->array + start; - - while (c--) { + + while (c--) { if (*ap) cpl_array_delete(*ap); ap++; @@ -6711,7 +6624,6 @@ } return CPL_ERROR_NONE; - } @@ -6739,13 +6651,14 @@ * This function doesn't apply to array column types. */ -cpl_error_code cpl_column_copy_segment(cpl_column *column, - cpl_size start, cpl_size count, - double *values) +cpl_error_code +cpl_column_copy_segment(cpl_column *column, + cpl_size start, + cpl_size count, + double *values) { - - cpl_size length = cpl_column_get_size(column); - cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + cpl_type type = cpl_column_get_type(column); if (column == NULL) @@ -6763,40 +6676,35 @@ cpl_column_unset_null_segment(column, start, count); switch (type) { - case CPL_TYPE_INT: - { + case CPL_TYPE_INT: { int *idata = cpl_column_get_data_int(column); idata += start; while (count--) *idata++ = *values++; break; } - case CPL_TYPE_LONG: - { + case CPL_TYPE_LONG: { long *ldata = cpl_column_get_data_long(column); ldata += start; while (count--) *ldata++ = *values++; break; } - case CPL_TYPE_LONG_LONG: - { + case CPL_TYPE_LONG_LONG: { long long *lldata = cpl_column_get_data_long_long(column); lldata += start; while (count--) *lldata++ = *values++; break; } - case CPL_TYPE_SIZE: - { + case CPL_TYPE_SIZE: { cpl_size *szdata = cpl_column_get_data_cplsize(column); szdata += start; while (count--) *szdata++ = *values++; break; } - case CPL_TYPE_FLOAT: - { + case CPL_TYPE_FLOAT: { float *fdata = cpl_column_get_data_float(column); fdata += start; while (count--) @@ -6811,7 +6719,6 @@ } return CPL_ERROR_NONE; - } @@ -6839,15 +6746,16 @@ * This function doesn't apply to array column types. */ -cpl_error_code cpl_column_copy_segment_complex(cpl_column *column, - cpl_size start, cpl_size count, - double complex *values) +cpl_error_code +cpl_column_copy_segment_complex(cpl_column *column, + cpl_size start, + cpl_size count, + double complex *values) { - - cpl_size length = cpl_column_get_size(column); - cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + cpl_type type = cpl_column_get_type(column); float complex *fdata; - + if (column == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -6864,22 +6772,21 @@ cpl_column_unset_null_segment(column, start, count); switch (type) { - case CPL_TYPE_FLOAT_COMPLEX: - fdata = cpl_column_get_data_float_complex(column); - fdata += start; - while (count--) - *fdata++ = *values++; - break; - case CPL_TYPE_DOUBLE_COMPLEX: - memcpy(column->values->cd + start, values, - count * sizeof(double complex)); - break; - default: - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + case CPL_TYPE_FLOAT_COMPLEX: + fdata = cpl_column_get_data_float_complex(column); + fdata += start; + while (count--) + *fdata++ = *values++; + break; + case CPL_TYPE_DOUBLE_COMPLEX: + memcpy(column->values->cd + start, values, + count * sizeof(double complex)); + break; + default: + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } return CPL_ERROR_NONE; - } @@ -6906,13 +6813,14 @@ * be transferred just up to the end of the column. */ -cpl_error_code cpl_column_copy_segment_int(cpl_column *column, - cpl_size start, cpl_size count, - int *values) +cpl_error_code +cpl_column_copy_segment_int(cpl_column *column, + cpl_size start, + cpl_size count, + int *values) { - - cpl_size length = cpl_column_get_size(column); - cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + cpl_type type = cpl_column_get_type(column); if (column == NULL) @@ -6935,7 +6843,6 @@ cpl_column_unset_null_segment(column, start, count); return CPL_ERROR_NONE; - } @@ -6963,13 +6870,14 @@ * values will be transferred just up to the end of the column. */ -cpl_error_code cpl_column_copy_segment_long(cpl_column *column, - cpl_size start, cpl_size count, - long *values) +cpl_error_code +cpl_column_copy_segment_long(cpl_column *column, + cpl_size start, + cpl_size count, + long *values) { - - cpl_size length = cpl_column_get_size(column); - cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + cpl_type type = cpl_column_get_type(column); if (column == NULL) @@ -6992,7 +6900,6 @@ cpl_column_unset_null_segment(column, start, count); return CPL_ERROR_NONE; - } @@ -7020,13 +6927,14 @@ * values will be transferred just up to the end of the column. */ -cpl_error_code cpl_column_copy_segment_long_long(cpl_column *column, - cpl_size start, cpl_size count, - long long *values) +cpl_error_code +cpl_column_copy_segment_long_long(cpl_column *column, + cpl_size start, + cpl_size count, + long long *values) { - - cpl_size length = cpl_column_get_size(column); - cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + cpl_type type = cpl_column_get_type(column); if (column == NULL) @@ -7049,7 +6957,6 @@ cpl_column_unset_null_segment(column, start, count); return CPL_ERROR_NONE; - } @@ -7076,13 +6983,14 @@ * values will be transferred just up to the end of the column. */ -cpl_error_code cpl_column_copy_segment_cplsize(cpl_column *column, - cpl_size start, cpl_size count, - cpl_size *values) +cpl_error_code +cpl_column_copy_segment_cplsize(cpl_column *column, + cpl_size start, + cpl_size count, + cpl_size *values) { - - cpl_size length = cpl_column_get_size(column); - cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + cpl_type type = cpl_column_get_type(column); if (column == NULL) @@ -7105,7 +7013,6 @@ cpl_column_unset_null_segment(column, start, count); return CPL_ERROR_NONE; - } @@ -7132,12 +7039,14 @@ * be transferred just up to the end of the column. */ -cpl_error_code cpl_column_copy_segment_float(cpl_column *column, cpl_size start, - cpl_size count, float *values) +cpl_error_code +cpl_column_copy_segment_float(cpl_column *column, + cpl_size start, + cpl_size count, + float *values) { - - cpl_size length = cpl_column_get_size(column); - cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + cpl_type type = cpl_column_get_type(column); if (column == NULL) @@ -7160,7 +7069,6 @@ cpl_column_unset_null_segment(column, start, count); return CPL_ERROR_NONE; - } @@ -7187,14 +7095,14 @@ * be transferred just up to the end of the column. */ -cpl_error_code cpl_column_copy_segment_float_complex(cpl_column *column, - cpl_size start, - cpl_size count, - float complex *values) +cpl_error_code +cpl_column_copy_segment_float_complex(cpl_column *column, + cpl_size start, + cpl_size count, + float complex *values) { - - cpl_size length = cpl_column_get_size(column); - cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + cpl_type type = cpl_column_get_type(column); if (column == NULL) @@ -7243,14 +7151,14 @@ * be transferred just up to the end of the column. */ -cpl_error_code cpl_column_copy_segment_double_complex(cpl_column *column, - cpl_size start, - cpl_size count, - double complex *values) +cpl_error_code +cpl_column_copy_segment_double_complex(cpl_column *column, + cpl_size start, + cpl_size count, + double complex *values) { - - cpl_size length = cpl_column_get_size(column); - cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + cpl_type type = cpl_column_get_type(column); if (column == NULL) @@ -7299,13 +7207,14 @@ * be transferred just up to the end of the column. */ -cpl_error_code cpl_column_copy_segment_double(cpl_column *column, - cpl_size start, cpl_size count, - double *values) +cpl_error_code +cpl_column_copy_segment_double(cpl_column *column, + cpl_size start, + cpl_size count, + double *values) { - - cpl_size length = cpl_column_get_size(column); - cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + cpl_type type = cpl_column_get_type(column); if (column == NULL) @@ -7324,11 +7233,10 @@ count = length - start; memcpy(column->values->d + start, values, count * sizeof(double)); - + cpl_column_unset_null_segment(column, start, count); - - return CPL_ERROR_NONE; + return CPL_ERROR_NONE; } @@ -7356,15 +7264,16 @@ * values will be transferred just up to the end of the column. */ -cpl_error_code cpl_column_copy_segment_string(cpl_column *column, - cpl_size start, cpl_size count, - char **strings) +cpl_error_code +cpl_column_copy_segment_string(cpl_column *column, + cpl_size start, + cpl_size count, + char **strings) { - - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); - cpl_size i; - char **sp; + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + cpl_size i; + char **sp; if (column == NULL) @@ -7403,7 +7312,6 @@ } return CPL_ERROR_NONE; - } @@ -7434,18 +7342,19 @@ * values will be transferred just up to the end of the column. */ -cpl_error_code cpl_column_copy_segment_array(cpl_column *column, - cpl_size start, cpl_size count, - cpl_array **arrays) +cpl_error_code +cpl_column_copy_segment_array(cpl_column *column, + cpl_size start, + cpl_size count, + cpl_array **arrays) { - - cpl_type type = cpl_column_get_type(column); - cpl_type atype; - cpl_size length = cpl_column_get_size(column); - cpl_size i; + cpl_type type = cpl_column_get_type(column); + cpl_type atype; + cpl_size length = cpl_column_get_size(column); + cpl_size i; cpl_array **ap; cpl_array **keep; - + if (column == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -7465,7 +7374,6 @@ ap = column->values->array + start; if (arrays) { - /* * Check the compatibility of all the input arrays first */ @@ -7503,7 +7411,6 @@ } return CPL_ERROR_NONE; - } /*************** TODO ******************/ @@ -7627,16 +7534,15 @@ * of the column data elements can be removed. */ -cpl_error_code cpl_column_erase_segment(cpl_column *column, - cpl_size start, cpl_size count) +cpl_error_code +cpl_column_erase_segment(cpl_column *column, cpl_size start, cpl_size count) { - - cpl_type type = cpl_column_get_type(column); - cpl_size old_length = cpl_column_get_size(column); - cpl_size new_length; - cpl_size end; - cpl_size i; - cpl_size j; + cpl_type type = cpl_column_get_type(column); + cpl_size old_length = cpl_column_get_size(column); + cpl_size new_length; + cpl_size end; + cpl_size i; + cpl_size j; if (column == NULL) @@ -7654,14 +7560,13 @@ if (count > old_length - start) count = old_length - start; - new_length = old_length - count; + new_length = old_length - count; end = start + count; if (end == old_length) return cpl_column_set_size(column, start); if (type == CPL_TYPE_STRING) { - /* * If a column of character strings is shortened, we must * free explicitly the extra strings. @@ -7675,7 +7580,6 @@ } if (type & CPL_TYPE_POINTER) { - /* * If a column of arrays is shortened, we must * free explicitly the extra arrays. @@ -7695,7 +7599,6 @@ */ if (column->null) { - i = start; while (i < end) { if (column->null[i]) @@ -7704,7 +7607,6 @@ } if (column->nullcount == 0 || column->nullcount == new_length) { - /* * Since either no invalid or just invalid elements are left, * the invalid flag buffer can be released. @@ -7713,10 +7615,8 @@ if (column->null) cpl_free(column->null); column->null = NULL; - } else { - /* * Shift up NULL flags that are after the slice. */ @@ -7733,13 +7633,11 @@ * Get rid of extra memory. */ - column->null = cpl_realloc(column->null, - new_length * sizeof(cpl_column_flag)); - + column->null = + cpl_realloc(column->null, new_length * sizeof(cpl_column_flag)); } } else { - /* * There is no invalid flag buffer, so either there are no * invalid elements or there are just invalid elements. If @@ -7750,7 +7648,6 @@ if (column->nullcount == old_length) column->nullcount = new_length; - } @@ -7762,69 +7659,61 @@ column->nullcount = 0; if (column->nullcount != new_length) { - /* * Column has not just invalid elements. In this case we have to * shift also the data to fill the gap. */ switch (type) { - case CPL_TYPE_INT: - { - int *ip1 = column->values->i + start; - int *ip2 = column->values->i + end; + case CPL_TYPE_INT: { + int *ip1 = column->values->i + start; + int *ip2 = column->values->i + end; for (j = end; j < old_length; j++) *ip1++ = *ip2++; break; } - case CPL_TYPE_LONG: - { - long *lp1 = column->values->l + start; - long *lp2 = column->values->l + end; + case CPL_TYPE_LONG: { + long *lp1 = column->values->l + start; + long *lp2 = column->values->l + end; for (j = end; j < old_length; j++) *lp1++ = *lp2++; break; } - case CPL_TYPE_LONG_LONG: - { - long long *llp1 = column->values->ll + start; - long long *llp2 = column->values->ll + end; + case CPL_TYPE_LONG_LONG: { + long long *llp1 = column->values->ll + start; + long long *llp2 = column->values->ll + end; for (j = end; j < old_length; j++) *llp1++ = *llp2++; break; } - case CPL_TYPE_SIZE: - { - cpl_size *szp1 = column->values->sz + start; - cpl_size *szp2 = column->values->sz + end; + case CPL_TYPE_SIZE: { + cpl_size *szp1 = column->values->sz + start; + cpl_size *szp2 = column->values->sz + end; for (j = end; j < old_length; j++) *szp1++ = *szp2++; break; } - case CPL_TYPE_FLOAT: - { - float *fp1 = column->values->f + start; - float *fp2 = column->values->f + end; + case CPL_TYPE_FLOAT: { + float *fp1 = column->values->f + start; + float *fp2 = column->values->f + end; for (j = end; j < old_length; j++) *fp1++ = *fp2++; break; } - case CPL_TYPE_DOUBLE: - { - double *dp1 = column->values->d + start; - double *dp2 = column->values->d + end; + case CPL_TYPE_DOUBLE: { + double *dp1 = column->values->d + start; + double *dp2 = column->values->d + end; for (j = end; j < old_length; j++) *dp1++ = *dp2++; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *cfp1 = column->values->cf + start; float complex *cfp2 = column->values->cf + end; @@ -7832,8 +7721,7 @@ *cfp1++ = *cfp2++; break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *cdp1 = column->values->cd + start; double complex *cdp2 = column->values->cd + end; @@ -7841,26 +7729,24 @@ *cdp1++ = *cdp2++; break; } - case CPL_TYPE_STRING: - { - char **sp1 = column->values->s + start; - char **sp2 = column->values->s + end; + case CPL_TYPE_STRING: { + char **sp1 = column->values->s + start; + char **sp2 = column->values->s + end; for (j = end; j < old_length; j++) *sp1++ = *sp2++; break; } - default: /* Array columns */ + default: /* Array columns */ { - cpl_array **ap1 = column->values->array + start; - cpl_array **ap2 = column->values->array + end; + cpl_array **ap1 = column->values->array + start; + cpl_array **ap2 = column->values->array + end; for (j = end; j < old_length; j++) *ap1++ = *ap2++; break; } } - } @@ -7868,13 +7754,12 @@ * Finally, reallocate the data buffer. */ - column->values->i = cpl_realloc(column->values->i, - new_length * cpl_column_type_size(type)); + column->values->i = + cpl_realloc(column->values->i, new_length * cpl_column_type_size(type)); column->length = new_length; return 0; - } @@ -7900,15 +7785,14 @@ * The execution time O(n) where n is the column length. */ -cpl_error_code cpl_column_erase_pattern(cpl_column *column, - int *pattern) +cpl_error_code +cpl_column_erase_pattern(cpl_column *column, int *pattern) { - - cpl_type type = cpl_column_get_type(column); - cpl_size old_length = cpl_column_get_size(column); - cpl_size new_length; - cpl_size i; - cpl_size j; + cpl_type type = cpl_column_get_type(column); + cpl_size old_length = cpl_column_get_size(column); + cpl_size new_length; + cpl_size i; + cpl_size j; if (column == NULL) @@ -7919,35 +7803,31 @@ new_length = 0; for (i = 0; i < old_length; i++) - if (!pattern[i]) + if (!pattern[i]) new_length++; if (type == CPL_TYPE_STRING) { - /* * If a column of character strings is shortened, we must * free explicitly the extra strings. */ - for(i = 0; i < old_length; i++) + for (i = 0; i < old_length; i++) if (pattern[i]) if (column->values->s[i]) cpl_free(column->values->s[i]); - } if (type & CPL_TYPE_POINTER) { - /* * If a column of arrays is shortened, we must * free explicitly the extra arrays. */ - for(i = 0; i < old_length; i++) + for (i = 0; i < old_length; i++) if (pattern[i]) if (column->values->array[i]) cpl_array_delete(column->values->array[i]); - } @@ -7955,50 +7835,44 @@ * Shorten the invalid flags buffer, if present, * counting how many invalid elements will be lost. */ - + if (column->null) { - for (i = 0; i < old_length; i++) if (pattern[i]) if (column->null[i]) column->nullcount--; if (column->nullcount == 0 || column->nullcount == new_length) { - /* * Since either no invalid or just invalid elements are left, * the invalid flag buffer can be released. */ - + if (column->null) cpl_free(column->null); column->null = NULL; - } else { - /* * Shift up NULL flags. */ - + i = 0; for (j = 0; j < old_length; j++) if (!pattern[j]) { column->null[i] = column->null[j]; i++; } - + /* * Get rid of extra memory. */ - - column->null = cpl_realloc(column->null, - new_length * sizeof(cpl_column_flag)); - + + column->null = + cpl_realloc(column->null, new_length * sizeof(cpl_column_flag)); } } else { - /* * There is no invalid flag buffer, so either there are no * invalid elements or there are just invalid elements. If @@ -8009,7 +7883,6 @@ if (column->nullcount == old_length) column->nullcount = new_length; - } @@ -8021,115 +7894,104 @@ column->nullcount = 0; if (column->nullcount != new_length) { - /* * Column has not just invalid elements. In this case we have to * shift also the data to fill the gaps. */ switch (type) { - case CPL_TYPE_INT: - { + case CPL_TYPE_INT: { int *ip = column->values->i; i = 0; - for(j = 0; j < old_length; j++) + for (j = 0; j < old_length; j++) if (!pattern[j]) ip[i++] = ip[j]; break; } - case CPL_TYPE_LONG: - { + case CPL_TYPE_LONG: { long *lp = column->values->l; i = 0; - for(j = 0; j < old_length; j++) + for (j = 0; j < old_length; j++) if (!pattern[j]) lp[i++] = lp[j]; break; } - case CPL_TYPE_LONG_LONG: - { + case CPL_TYPE_LONG_LONG: { long long *llp = column->values->ll; i = 0; - for(j = 0; j < old_length; j++) + for (j = 0; j < old_length; j++) if (!pattern[j]) llp[i++] = llp[j]; break; } - case CPL_TYPE_SIZE: - { + case CPL_TYPE_SIZE: { cpl_size *szp = column->values->sz; i = 0; - for(j = 0; j < old_length; j++) + for (j = 0; j < old_length; j++) if (!pattern[j]) szp[i++] = szp[j]; break; } - case CPL_TYPE_FLOAT: - { - float *fp = column->values->f; + case CPL_TYPE_FLOAT: { + float *fp = column->values->f; i = 0; - for(j = 0; j < old_length; j++) + for (j = 0; j < old_length; j++) if (!pattern[j]) fp[i++] = fp[j]; break; } - case CPL_TYPE_DOUBLE: - { - double *dp = column->values->d; + case CPL_TYPE_DOUBLE: { + double *dp = column->values->d; i = 0; - for(j = 0; j < old_length; j++) + for (j = 0; j < old_length; j++) if (!pattern[j]) dp[i++] = dp[j]; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *cfp = column->values->cf; i = 0; - for(j = 0; j < old_length; j++) + for (j = 0; j < old_length; j++) if (!pattern[j]) cfp[i++] = cfp[j]; break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *cdp = column->values->cd; i = 0; - for(j = 0; j < old_length; j++) + for (j = 0; j < old_length; j++) if (!pattern[j]) cdp[i++] = cdp[j]; break; } - case CPL_TYPE_STRING: - { - char **sp = column->values->s; + case CPL_TYPE_STRING: { + char **sp = column->values->s; i = 0; - for(j = 0; j < old_length; j++) + for (j = 0; j < old_length; j++) if (!pattern[j]) sp[i++] = sp[j]; break; } - default: /* Array columns */ + default: /* Array columns */ { - cpl_array **ap = column->values->array; + cpl_array **ap = column->values->array; i = 0; - for(j = 0; j < old_length; j++) + for (j = 0; j < old_length; j++) if (!pattern[j]) ap[i++] = ap[j]; break; } } - } @@ -8137,13 +7999,12 @@ * Finally, reallocate the data buffer. */ - column->values->i = cpl_realloc(column->values->i, - new_length * cpl_column_type_size(type)); + column->values->i = + cpl_realloc(column->values->i, new_length * cpl_column_type_size(type)); column->length = new_length; return 0; - } @@ -8174,14 +8035,13 @@ * @c cpl_column_get_data_string(), etc., should be discarded. */ -cpl_error_code cpl_column_insert_segment(cpl_column *column, - cpl_size start, cpl_size count) +cpl_error_code +cpl_column_insert_segment(cpl_column *column, cpl_size start, cpl_size count) { - - cpl_type type = cpl_column_get_type(column); - cpl_size old_length = cpl_column_get_size(column); - cpl_size new_length = old_length + count; - cpl_size i; + cpl_type type = cpl_column_get_type(column); + cpl_size old_length = cpl_column_get_size(column); + cpl_size new_length = old_length + count; + cpl_size i; if (column == NULL) @@ -8205,10 +8065,9 @@ switch (type) { - case CPL_TYPE_INT: - { - int *ip1 = column->values->i + new_length; - int *ip2 = column->values->i + old_length; + case CPL_TYPE_INT: { + int *ip1 = column->values->i + new_length; + int *ip2 = column->values->i + old_length; for (i = old_length; i > start; i--) { *--ip1 = *--ip2; @@ -8217,10 +8076,9 @@ break; } - case CPL_TYPE_LONG: - { - long *lp1 = column->values->l + new_length; - long *lp2 = column->values->l + old_length; + case CPL_TYPE_LONG: { + long *lp1 = column->values->l + new_length; + long *lp2 = column->values->l + old_length; for (i = old_length; i > start; i--) { *--lp1 = *--lp2; @@ -8229,10 +8087,9 @@ break; } - case CPL_TYPE_LONG_LONG: - { - long long *llp1 = column->values->ll + new_length; - long long *llp2 = column->values->ll + old_length; + case CPL_TYPE_LONG_LONG: { + long long *llp1 = column->values->ll + new_length; + long long *llp2 = column->values->ll + old_length; for (i = old_length; i > start; i--) { *--llp1 = *--llp2; @@ -8241,10 +8098,9 @@ break; } - case CPL_TYPE_SIZE: - { - cpl_size *szp1 = column->values->sz + new_length; - cpl_size *szp2 = column->values->sz + old_length; + case CPL_TYPE_SIZE: { + cpl_size *szp1 = column->values->sz + new_length; + cpl_size *szp2 = column->values->sz + old_length; for (i = old_length; i > start; i--) { *--szp1 = *--szp2; @@ -8253,10 +8109,9 @@ break; } - case CPL_TYPE_FLOAT: - { - float *fp1 = column->values->f + new_length; - float *fp2 = column->values->f + old_length; + case CPL_TYPE_FLOAT: { + float *fp1 = column->values->f + new_length; + float *fp2 = column->values->f + old_length; for (i = old_length; i > start; i--) { *--fp1 = *--fp2; @@ -8265,10 +8120,9 @@ break; } - case CPL_TYPE_DOUBLE: - { - double *dp1 = column->values->d + new_length; - double *dp2 = column->values->d + old_length; + case CPL_TYPE_DOUBLE: { + double *dp1 = column->values->d + new_length; + double *dp2 = column->values->d + old_length; for (i = old_length; i > start; i--) { *--dp1 = *--dp2; @@ -8277,8 +8131,7 @@ break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *cfp1 = column->values->cf + new_length; float complex *cfp2 = column->values->cf + old_length; @@ -8289,8 +8142,7 @@ break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *cdp1 = column->values->cd + new_length; double complex *cdp2 = column->values->cd + old_length; @@ -8301,10 +8153,9 @@ break; } - case CPL_TYPE_STRING: - { - char **sp1 = column->values->s + new_length; - char **sp2 = column->values->s + old_length; + case CPL_TYPE_STRING: { + char **sp1 = column->values->s + new_length; + char **sp2 = column->values->s + old_length; for (i = old_length; i > start; i--) { *--sp1 = *--sp2; @@ -8313,10 +8164,10 @@ break; } - default: /* Array columns */ + default: /* Array columns */ { - cpl_array **ap1 = column->values->array + new_length; - cpl_array **ap2 = column->values->array + old_length; + cpl_array **ap1 = column->values->array + new_length; + cpl_array **ap2 = column->values->array + old_length; for (i = old_length; i > start; i--) { *--ap1 = *--ap2; @@ -8335,7 +8186,6 @@ */ if (column->null) { - int *np1 = column->null + new_length; int *np2 = column->null + old_length; @@ -8343,11 +8193,9 @@ *--np1 = *--np2; *np2 = 1; } - } return CPL_ERROR_NONE; - } @@ -8364,12 +8212,12 @@ * also the string elements are duplicated. */ -cpl_column *cpl_column_duplicate(const cpl_column *column) +cpl_column * +cpl_column_duplicate(const cpl_column *column) { - - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); - cpl_size depth = cpl_column_get_depth(column); + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + cpl_size depth = cpl_column_get_depth(column); cpl_column *new_column = NULL; @@ -8380,72 +8228,73 @@ if (type & CPL_TYPE_POINTER) { switch (type & ~CPL_TYPE_POINTER) { - case CPL_TYPE_INT: - case CPL_TYPE_LONG: - case CPL_TYPE_LONG_LONG: - case CPL_TYPE_SIZE: - case CPL_TYPE_FLOAT: - case CPL_TYPE_DOUBLE: - case CPL_TYPE_FLOAT_COMPLEX: - case CPL_TYPE_DOUBLE_COMPLEX: - case CPL_TYPE_STRING: - new_column = cpl_column_new_array(type, length, depth); - break; - default: - cpl_error_set_(CPL_ERROR_UNSPECIFIED); - return NULL; - } - } else { - switch (type) { - case CPL_TYPE_INT: - new_column = cpl_column_new_int(length); - break; - case CPL_TYPE_LONG: - new_column = cpl_column_new_long(length); - break; - case CPL_TYPE_LONG_LONG: - new_column = cpl_column_new_long_long(length); - break; - case CPL_TYPE_SIZE: - new_column = cpl_column_new_cplsize(length); - break; - case CPL_TYPE_FLOAT: - new_column = cpl_column_new_float(length); - break; - case CPL_TYPE_DOUBLE: - new_column = cpl_column_new_double(length); - break; - case CPL_TYPE_FLOAT_COMPLEX: - new_column = cpl_column_new_float_complex(length); - break; - case CPL_TYPE_DOUBLE_COMPLEX: - new_column = cpl_column_new_double_complex(length); - break; - case CPL_TYPE_STRING: - new_column = cpl_column_new_string(length); - break; - default: - cpl_error_set_(CPL_ERROR_UNSPECIFIED); - return NULL; + case CPL_TYPE_INT: + case CPL_TYPE_LONG: + case CPL_TYPE_LONG_LONG: + case CPL_TYPE_SIZE: + case CPL_TYPE_FLOAT: + case CPL_TYPE_DOUBLE: + case CPL_TYPE_FLOAT_COMPLEX: + case CPL_TYPE_DOUBLE_COMPLEX: + case CPL_TYPE_STRING: + new_column = cpl_column_new_array(type, length, depth); + break; + default: + cpl_error_set_(CPL_ERROR_UNSPECIFIED); + return NULL; } } - - cpl_column_set_name(new_column, cpl_column_get_name(column)); - cpl_column_set_unit(new_column, cpl_column_get_unit(column)); - cpl_column_set_format(new_column, cpl_column_get_format(column)); - - if (length == 0) - return new_column; - - if (type == CPL_TYPE_STRING) { - while (length--) { - if (column->values->s[length]) { - new_column->values->s[length] = - cpl_strdup(column->values->s[length]); - } - else { - new_column->values->s[length] = NULL; - } + else { + switch (type) { + case CPL_TYPE_INT: + new_column = cpl_column_new_int(length); + break; + case CPL_TYPE_LONG: + new_column = cpl_column_new_long(length); + break; + case CPL_TYPE_LONG_LONG: + new_column = cpl_column_new_long_long(length); + break; + case CPL_TYPE_SIZE: + new_column = cpl_column_new_cplsize(length); + break; + case CPL_TYPE_FLOAT: + new_column = cpl_column_new_float(length); + break; + case CPL_TYPE_DOUBLE: + new_column = cpl_column_new_double(length); + break; + case CPL_TYPE_FLOAT_COMPLEX: + new_column = cpl_column_new_float_complex(length); + break; + case CPL_TYPE_DOUBLE_COMPLEX: + new_column = cpl_column_new_double_complex(length); + break; + case CPL_TYPE_STRING: + new_column = cpl_column_new_string(length); + break; + default: + cpl_error_set_(CPL_ERROR_UNSPECIFIED); + return NULL; + } + } + + cpl_column_set_name(new_column, cpl_column_get_name(column)); + cpl_column_set_unit(new_column, cpl_column_get_unit(column)); + cpl_column_set_format(new_column, cpl_column_get_format(column)); + + if (length == 0) + return new_column; + + if (type == CPL_TYPE_STRING) { + while (length--) { + if (column->values->s[length]) { + new_column->values->s[length] = + cpl_strdup(column->values->s[length]); + } + else { + new_column->values->s[length] = NULL; + } } return new_column; } @@ -8467,19 +8316,18 @@ return new_column; } - memcpy(new_column->values->i, column->values->i, + memcpy(new_column->values->i, column->values->i, length * cpl_column_type_size(type)); new_column->nullcount = column->nullcount; if (column->null) { new_column->null = cpl_malloc(length * sizeof(cpl_column_flag)); - memcpy(new_column->null, column->null, + memcpy(new_column->null, column->null, length * sizeof(cpl_column_flag)); } return new_column; - } @@ -8503,14 +8351,14 @@ * a column of arrays into a column of plain integers. */ -cpl_column *cpl_column_cast_to_int(const cpl_column *column) +cpl_column * +cpl_column_cast_to_int(const cpl_column *column) { - - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); cpl_column *new_column = NULL; - int *np; - int *ip; + int *np; + int *ip; if (column == NULL) { @@ -8540,14 +8388,13 @@ cpl_column_set_unit(new_column, cpl_column_get_unit(column)); - if (length == 0) /* No need to cast a 0 length column */ + if (length == 0) /* No need to cast a 0 length column */ return new_column; - if (column->nullcount == length) /* No need to copy just NULLs */ + if (column->nullcount == length) /* No need to copy just NULLs */ return new_column; if (type & CPL_TYPE_POINTER) { - const cpl_array **array = cpl_column_get_data_array_const(column); cpl_array **new_array = cpl_column_get_data_array(new_column); @@ -8563,15 +8410,13 @@ } return new_column; - } ip = cpl_column_get_data_int(new_column); np = column->null; switch (type) { - case CPL_TYPE_LONG: - { + case CPL_TYPE_LONG: { long *lp = column->values->l; if (column->nullcount == 0) { @@ -8588,8 +8433,7 @@ } break; } - case CPL_TYPE_LONG_LONG: - { + case CPL_TYPE_LONG_LONG: { long long *llp = column->values->ll; if (column->nullcount == 0) { @@ -8606,8 +8450,7 @@ } break; } - case CPL_TYPE_SIZE: - { + case CPL_TYPE_SIZE: { cpl_size *szp = column->values->sz; if (column->nullcount == 0) { @@ -8624,8 +8467,7 @@ } break; } - case CPL_TYPE_FLOAT: - { + case CPL_TYPE_FLOAT: { float *fp = column->values->f; if (column->nullcount == 0) { @@ -8642,8 +8484,7 @@ } break; } - case CPL_TYPE_DOUBLE: - { + case CPL_TYPE_DOUBLE: { double *dp = column->values->d; if (column->nullcount == 0) { @@ -8677,18 +8518,17 @@ } return new_column; - } -cpl_column *cpl_column_cast_to_int_array(const cpl_column *column) +cpl_column * +cpl_column_cast_to_int_array(const cpl_column *column) { - - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); - cpl_column *new_column = NULL; - int *np; - cpl_array **array; + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + cpl_column *new_column = NULL; + int *np; + cpl_array **array; if (column == NULL) { @@ -8706,20 +8546,19 @@ return NULL; } - new_column = cpl_column_new_array(CPL_TYPE_INT | CPL_TYPE_POINTER, - length, 1); + new_column = + cpl_column_new_array(CPL_TYPE_INT | CPL_TYPE_POINTER, length, 1); cpl_column_set_unit(new_column, cpl_column_get_unit(column)); - if (length == 0) /* No need to cast a 0 length column */ + if (length == 0) /* No need to cast a 0 length column */ return new_column; array = cpl_column_get_data_array(new_column); np = column->null; switch (type) { - case CPL_TYPE_INT: - { + case CPL_TYPE_INT: { int *ip = column->values->i; if (column->nullcount == 0) { @@ -8742,8 +8581,7 @@ } break; } - case CPL_TYPE_LONG: - { + case CPL_TYPE_LONG: { long *lp = column->values->l; if (column->nullcount == 0) { @@ -8766,8 +8604,7 @@ } break; } - case CPL_TYPE_LONG_LONG: - { + case CPL_TYPE_LONG_LONG: { long long *llp = column->values->ll; if (column->nullcount == 0) { @@ -8790,8 +8627,7 @@ } break; } - case CPL_TYPE_SIZE: - { + case CPL_TYPE_SIZE: { cpl_size *szp = column->values->sz; if (column->nullcount == 0) { @@ -8814,8 +8650,7 @@ } break; } - case CPL_TYPE_FLOAT: - { + case CPL_TYPE_FLOAT: { float *fp = column->values->f; if (column->nullcount == 0) { @@ -8838,8 +8673,7 @@ } break; } - case CPL_TYPE_DOUBLE: - { + case CPL_TYPE_DOUBLE: { double *dp = column->values->d; if (column->nullcount == 0) { @@ -8869,17 +8703,16 @@ } return new_column; - } -cpl_column *cpl_column_cast_to_int_flat(const cpl_column *column) +cpl_column * +cpl_column_cast_to_int_flat(const cpl_column *column) { - - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); - cpl_column *new_column = NULL; - const cpl_array **array; + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + cpl_column *new_column = NULL; + const cpl_array **array; if (column == NULL) { @@ -8901,7 +8734,7 @@ cpl_column_set_unit(new_column, cpl_column_get_unit(column)); - if (length == 0) /* No need to cast a 0 length column */ + if (length == 0) /* No need to cast a 0 length column */ return new_column; array = cpl_column_get_data_array_const(column) + length; @@ -8917,7 +8750,6 @@ } return new_column; - } @@ -8941,14 +8773,14 @@ * a column of arrays into a column of plain long integers. */ -cpl_column *cpl_column_cast_to_long(const cpl_column *column) +cpl_column * +cpl_column_cast_to_long(const cpl_column *column) { - - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); cpl_column *new_column = NULL; - int *np; - long *lp; + int *np; + long *lp; if (column == NULL) { @@ -8978,14 +8810,13 @@ cpl_column_set_unit(new_column, cpl_column_get_unit(column)); - if (length == 0) /* No need to cast a 0 length column */ + if (length == 0) /* No need to cast a 0 length column */ return new_column; - if (column->nullcount == length) /* No need to copy just NULLs */ + if (column->nullcount == length) /* No need to copy just NULLs */ return new_column; if (type & CPL_TYPE_POINTER) { - const cpl_array **array = cpl_column_get_data_array_const(column); cpl_array **new_array = cpl_column_get_data_array(new_column); @@ -9001,15 +8832,13 @@ } return new_column; - } lp = cpl_column_get_data_long(new_column); np = column->null; switch (type) { - case CPL_TYPE_INT: - { + case CPL_TYPE_INT: { int *ip = column->values->i; if (column->nullcount == 0) { @@ -9026,8 +8855,7 @@ } break; } - case CPL_TYPE_LONG_LONG: - { + case CPL_TYPE_LONG_LONG: { long long *llp = column->values->ll; if (column->nullcount == 0) { @@ -9044,8 +8872,7 @@ } break; } - case CPL_TYPE_SIZE: - { + case CPL_TYPE_SIZE: { cpl_size *szp = column->values->sz; if (column->nullcount == 0) { @@ -9062,8 +8889,7 @@ } break; } - case CPL_TYPE_FLOAT: - { + case CPL_TYPE_FLOAT: { float *fp = column->values->f; if (column->nullcount == 0) { @@ -9080,8 +8906,7 @@ } break; } - case CPL_TYPE_DOUBLE: - { + case CPL_TYPE_DOUBLE: { double *dp = column->values->d; if (column->nullcount == 0) { @@ -9110,23 +8935,22 @@ if (column->null) { new_column->null = cpl_malloc(length * sizeof(cpl_column_flag)); - memcpy(new_column->null, column->null, + memcpy(new_column->null, column->null, length * sizeof(cpl_column_flag)); } return new_column; - } -cpl_column *cpl_column_cast_to_long_array(const cpl_column *column) +cpl_column * +cpl_column_cast_to_long_array(const cpl_column *column) { - - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); - cpl_column *new_column = NULL; - int *np; - cpl_array **array; + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + cpl_column *new_column = NULL; + int *np; + cpl_array **array; if (column == NULL) { @@ -9144,20 +8968,19 @@ return NULL; } - new_column = cpl_column_new_array(CPL_TYPE_LONG | CPL_TYPE_POINTER, - length, 1); + new_column = + cpl_column_new_array(CPL_TYPE_LONG | CPL_TYPE_POINTER, length, 1); cpl_column_set_unit(new_column, cpl_column_get_unit(column)); - if (length == 0) /* No need to cast a 0 length column */ + if (length == 0) /* No need to cast a 0 length column */ return new_column; array = cpl_column_get_data_array(new_column); np = column->null; switch (type) { - case CPL_TYPE_INT: - { + case CPL_TYPE_INT: { int *ip = column->values->i; if (column->nullcount == 0) { @@ -9180,8 +9003,7 @@ } break; } - case CPL_TYPE_LONG: - { + case CPL_TYPE_LONG: { long *lp = column->values->l; if (column->nullcount == 0) { @@ -9204,8 +9026,7 @@ } break; } - case CPL_TYPE_LONG_LONG: - { + case CPL_TYPE_LONG_LONG: { long long *llp = column->values->ll; if (column->nullcount == 0) { @@ -9228,8 +9049,7 @@ } break; } - case CPL_TYPE_SIZE: - { + case CPL_TYPE_SIZE: { cpl_size *szp = column->values->sz; if (column->nullcount == 0) { @@ -9252,8 +9072,7 @@ } break; } - case CPL_TYPE_FLOAT: - { + case CPL_TYPE_FLOAT: { float *fp = column->values->f; if (column->nullcount == 0) { @@ -9276,8 +9095,7 @@ } break; } - case CPL_TYPE_DOUBLE: - { + case CPL_TYPE_DOUBLE: { double *dp = column->values->d; if (column->nullcount == 0) { @@ -9307,17 +9125,16 @@ } return new_column; - } -cpl_column *cpl_column_cast_to_long_flat(const cpl_column *column) +cpl_column * +cpl_column_cast_to_long_flat(const cpl_column *column) { - - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); - cpl_column *new_column = NULL; - const cpl_array **array; + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + cpl_column *new_column = NULL; + const cpl_array **array; if (column == NULL) { @@ -9339,7 +9156,7 @@ cpl_column_set_unit(new_column, cpl_column_get_unit(column)); - if (length == 0) /* No need to cast a 0 length column */ + if (length == 0) /* No need to cast a 0 length column */ return new_column; array = cpl_column_get_data_array_const(column) + length; @@ -9355,7 +9172,6 @@ } return new_column; - } @@ -9379,14 +9195,14 @@ * to cast a column of arrays into a column of plain long long integers. */ -cpl_column *cpl_column_cast_to_long_long(const cpl_column *column) +cpl_column * +cpl_column_cast_to_long_long(const cpl_column *column) { - - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); cpl_column *new_column = NULL; - int *np; - long long *llp; + int *np; + long long *llp; if (column == NULL) { @@ -9416,14 +9232,13 @@ cpl_column_set_unit(new_column, cpl_column_get_unit(column)); - if (length == 0) /* No need to cast a 0 length column */ + if (length == 0) /* No need to cast a 0 length column */ return new_column; - if (column->nullcount == length) /* No need to copy just NULLs */ + if (column->nullcount == length) /* No need to copy just NULLs */ return new_column; if (type & CPL_TYPE_POINTER) { - const cpl_array **array = cpl_column_get_data_array_const(column); cpl_array **new_array = cpl_column_get_data_array(new_column); @@ -9432,22 +9247,21 @@ const cpl_column *acolumn = cpl_array_get_column_const(array[length]); cpl_column *llcolumn = cpl_column_cast_to_long_long(acolumn); - new_array[length] = cpl_array_new(cpl_column_get_size(llcolumn), - cpl_column_get_type(llcolumn)); + new_array[length] = + cpl_array_new(cpl_column_get_size(llcolumn), + cpl_column_get_type(llcolumn)); cpl_array_set_column(new_array[length], llcolumn); } } return new_column; - } llp = cpl_column_get_data_long_long(new_column); np = column->null; switch (type) { - case CPL_TYPE_INT: - { + case CPL_TYPE_INT: { int *ip = column->values->i; if (column->nullcount == 0) { @@ -9464,8 +9278,7 @@ } break; } - case CPL_TYPE_LONG: - { + case CPL_TYPE_LONG: { long *lp = column->values->l; if (column->nullcount == 0) { @@ -9482,8 +9295,7 @@ } break; } - case CPL_TYPE_SIZE: - { + case CPL_TYPE_SIZE: { cpl_size *szp = column->values->sz; if (column->nullcount == 0) { @@ -9500,8 +9312,7 @@ } break; } - case CPL_TYPE_FLOAT: - { + case CPL_TYPE_FLOAT: { float *fp = column->values->f; if (column->nullcount == 0) { @@ -9518,8 +9329,7 @@ } break; } - case CPL_TYPE_DOUBLE: - { + case CPL_TYPE_DOUBLE: { double *dp = column->values->d; if (column->nullcount == 0) { @@ -9553,18 +9363,17 @@ } return new_column; - } -cpl_column *cpl_column_cast_to_long_long_array(const cpl_column *column) +cpl_column * +cpl_column_cast_to_long_long_array(const cpl_column *column) { - - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); - cpl_column *new_column = NULL; - int *np; - cpl_array **array; + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + cpl_column *new_column = NULL; + int *np; + cpl_array **array; if (column == NULL) { @@ -9582,20 +9391,19 @@ return NULL; } - new_column = cpl_column_new_array(CPL_TYPE_LONG_LONG | CPL_TYPE_POINTER, - length, 1); + new_column = + cpl_column_new_array(CPL_TYPE_LONG_LONG | CPL_TYPE_POINTER, length, 1); cpl_column_set_unit(new_column, cpl_column_get_unit(column)); - if (length == 0) /* No need to cast a 0 length column */ + if (length == 0) /* No need to cast a 0 length column */ return new_column; array = cpl_column_get_data_array(new_column); np = column->null; switch (type) { - case CPL_TYPE_INT: - { + case CPL_TYPE_INT: { int *ip = column->values->i; if (column->nullcount == 0) { @@ -9618,8 +9426,7 @@ } break; } - case CPL_TYPE_LONG: - { + case CPL_TYPE_LONG: { long *lp = column->values->l; if (column->nullcount == 0) { @@ -9642,8 +9449,7 @@ } break; } - case CPL_TYPE_LONG_LONG: - { + case CPL_TYPE_LONG_LONG: { long long *llp = column->values->ll; if (column->nullcount == 0) { @@ -9666,8 +9472,7 @@ } break; } - case CPL_TYPE_SIZE: - { + case CPL_TYPE_SIZE: { cpl_size *szp = column->values->sz; if (column->nullcount == 0) { @@ -9690,8 +9495,7 @@ } break; } - case CPL_TYPE_FLOAT: - { + case CPL_TYPE_FLOAT: { float *fp = column->values->f; if (column->nullcount == 0) { @@ -9714,8 +9518,7 @@ } break; } - case CPL_TYPE_DOUBLE: - { + case CPL_TYPE_DOUBLE: { double *dp = column->values->d; if (column->nullcount == 0) { @@ -9745,17 +9548,16 @@ } return new_column; - } -cpl_column *cpl_column_cast_to_long_long_flat(const cpl_column *column) +cpl_column * +cpl_column_cast_to_long_long_flat(const cpl_column *column) { - - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); - cpl_column *new_column = NULL; - const cpl_array **array; + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + cpl_column *new_column = NULL; + const cpl_array **array; if (column == NULL) { @@ -9777,7 +9579,7 @@ cpl_column_set_unit(new_column, cpl_column_get_unit(column)); - if (length == 0) /* No need to cast a 0 length column */ + if (length == 0) /* No need to cast a 0 length column */ return new_column; array = cpl_column_get_data_array_const(column) + length; @@ -9793,7 +9595,6 @@ } return new_column; - } @@ -9817,14 +9618,14 @@ * to cast a column of arrays into a column of plain cpl_size. */ -cpl_column *cpl_column_cast_to_cplsize(const cpl_column *column) +cpl_column * +cpl_column_cast_to_cplsize(const cpl_column *column) { - - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); cpl_column *new_column = NULL; - int *np; - cpl_size *szp; + int *np; + cpl_size *szp; if (column == NULL) { @@ -9854,14 +9655,13 @@ cpl_column_set_unit(new_column, cpl_column_get_unit(column)); - if (length == 0) /* No need to cast a 0 length column */ + if (length == 0) /* No need to cast a 0 length column */ return new_column; - if (column->nullcount == length) /* No need to copy just NULLs */ + if (column->nullcount == length) /* No need to copy just NULLs */ return new_column; if (type & CPL_TYPE_POINTER) { - const cpl_array **array = cpl_column_get_data_array_const(column); cpl_array **new_array = cpl_column_get_data_array(new_column); @@ -9870,22 +9670,21 @@ const cpl_column *acolumn = cpl_array_get_column_const(array[length]); cpl_column *szcolumn = cpl_column_cast_to_cplsize(acolumn); - new_array[length] = cpl_array_new(cpl_column_get_size(szcolumn), - cpl_column_get_type(szcolumn)); + new_array[length] = + cpl_array_new(cpl_column_get_size(szcolumn), + cpl_column_get_type(szcolumn)); cpl_array_set_column(new_array[length], szcolumn); } } return new_column; - } szp = cpl_column_get_data_cplsize(new_column); np = column->null; switch (type) { - case CPL_TYPE_INT: - { + case CPL_TYPE_INT: { int *ip = column->values->i; if (column->nullcount == 0) { @@ -9902,8 +9701,7 @@ } break; } - case CPL_TYPE_LONG: - { + case CPL_TYPE_LONG: { long *lp = column->values->l; if (column->nullcount == 0) { @@ -9920,8 +9718,7 @@ } break; } - case CPL_TYPE_LONG_LONG: - { + case CPL_TYPE_LONG_LONG: { long long *llp = column->values->ll; if (column->nullcount == 0) { @@ -9938,8 +9735,7 @@ } break; } - case CPL_TYPE_FLOAT: - { + case CPL_TYPE_FLOAT: { float *fp = column->values->f; if (column->nullcount == 0) { @@ -9956,8 +9752,7 @@ } break; } - case CPL_TYPE_DOUBLE: - { + case CPL_TYPE_DOUBLE: { double *dp = column->values->d; if (column->nullcount == 0) { @@ -9991,18 +9786,17 @@ } return new_column; - } -cpl_column *cpl_column_cast_to_cplsize_array(const cpl_column *column) +cpl_column * +cpl_column_cast_to_cplsize_array(const cpl_column *column) { - - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); - cpl_column *new_column = NULL; - int *np; - cpl_array **array; + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + cpl_column *new_column = NULL; + int *np; + cpl_array **array; if (column == NULL) { @@ -10020,20 +9814,19 @@ return NULL; } - new_column = cpl_column_new_array(CPL_TYPE_SIZE | CPL_TYPE_POINTER, - length, 1); + new_column = + cpl_column_new_array(CPL_TYPE_SIZE | CPL_TYPE_POINTER, length, 1); cpl_column_set_unit(new_column, cpl_column_get_unit(column)); - if (length == 0) /* No need to cast a 0 length column */ + if (length == 0) /* No need to cast a 0 length column */ return new_column; array = cpl_column_get_data_array(new_column); np = column->null; switch (type) { - case CPL_TYPE_INT: - { + case CPL_TYPE_INT: { int *ip = column->values->i; if (column->nullcount == 0) { @@ -10056,8 +9849,7 @@ } break; } - case CPL_TYPE_LONG: - { + case CPL_TYPE_LONG: { long *lp = column->values->l; if (column->nullcount == 0) { @@ -10080,8 +9872,7 @@ } break; } - case CPL_TYPE_LONG_LONG: - { + case CPL_TYPE_LONG_LONG: { long long *llp = column->values->ll; if (column->nullcount == 0) { @@ -10104,8 +9895,7 @@ } break; } - case CPL_TYPE_SIZE: - { + case CPL_TYPE_SIZE: { cpl_size *szp = column->values->sz; if (column->nullcount == 0) { @@ -10128,8 +9918,7 @@ } break; } - case CPL_TYPE_FLOAT: - { + case CPL_TYPE_FLOAT: { float *fp = column->values->f; if (column->nullcount == 0) { @@ -10152,8 +9941,7 @@ } break; } - case CPL_TYPE_DOUBLE: - { + case CPL_TYPE_DOUBLE: { double *dp = column->values->d; if (column->nullcount == 0) { @@ -10183,17 +9971,16 @@ } return new_column; - } -cpl_column *cpl_column_cast_to_cplsize_flat(const cpl_column *column) +cpl_column * +cpl_column_cast_to_cplsize_flat(const cpl_column *column) { - - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); - cpl_column *new_column = NULL; - const cpl_array **array; + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + cpl_column *new_column = NULL; + const cpl_array **array; if (column == NULL) { @@ -10215,7 +10002,7 @@ cpl_column_set_unit(new_column, cpl_column_get_unit(column)); - if (length == 0) /* No need to cast a 0 length column */ + if (length == 0) /* No need to cast a 0 length column */ return new_column; array = cpl_column_get_data_array_const(column) + length; @@ -10231,7 +10018,6 @@ } return new_column; - } @@ -10255,16 +10041,16 @@ * a column of arrays into a column of plain floats. */ -cpl_column *cpl_column_cast_to_float(const cpl_column *column) +cpl_column * +cpl_column_cast_to_float(const cpl_column *column) { - - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); - cpl_column *new_column = NULL; - const cpl_column *acolumn = NULL; - cpl_column *fcolumn = NULL; - int *np; - float *fp; + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + cpl_column *new_column = NULL; + const cpl_column *acolumn = NULL; + cpl_column *fcolumn = NULL; + int *np; + float *fp; if (column == NULL) { @@ -10295,18 +10081,17 @@ cpl_column_set_unit(new_column, cpl_column_get_unit(column)); - if (length == 0) /* No need to cast a 0 length column */ + if (length == 0) /* No need to cast a 0 length column */ return new_column; - - if (column->nullcount == length) /* No need to copy just NULLs */ + + if (column->nullcount == length) /* No need to copy just NULLs */ return new_column; if (type & CPL_TYPE_POINTER) { - const cpl_array **array = cpl_column_get_data_array_const(column); cpl_array **new_array = cpl_column_get_data_array(new_column); - while(length--) { + while (length--) { if (array[length]) { acolumn = cpl_array_get_column_const(array[length]); fcolumn = cpl_column_cast_to_float(acolumn); @@ -10317,112 +10102,106 @@ } return new_column; - } - fp = cpl_column_get_data_float(new_column); - np = column->null; + fp = cpl_column_get_data_float(new_column); + np = column->null; switch (type) { - case CPL_TYPE_INT: - { - int *ip = column->values->i; + case CPL_TYPE_INT: { + int *ip = column->values->i; - if (column->nullcount == 0) { - while (length--) - *fp++ = *ip++; - } - else { - while (length--) { - if (*np++ == 0) - *fp = *ip; - fp++; - ip++; + if (column->nullcount == 0) { + while (length--) + *fp++ = *ip++; } - } - break; - } - - case CPL_TYPE_LONG: - { - long *lp = column->values->l; - - if (column->nullcount == 0) { - while (length--) - *fp++ = *lp++; - } - else { - while (length--) { - if (*np++ == 0) - *fp = *lp; - fp++; - lp++; + else { + while (length--) { + if (*np++ == 0) + *fp = *ip; + fp++; + ip++; + } } + break; } - break; - } - case CPL_TYPE_LONG_LONG: - { - long long *llp = column->values->ll; + case CPL_TYPE_LONG: { + long *lp = column->values->l; - if (column->nullcount == 0) { - while (length--) - *fp++ = *llp++; - } - else { - while (length--) { - if (*np++ == 0) - *fp = *llp; - fp++; - llp++; + if (column->nullcount == 0) { + while (length--) + *fp++ = *lp++; + } + else { + while (length--) { + if (*np++ == 0) + *fp = *lp; + fp++; + lp++; + } } + break; } - break; - } - case CPL_TYPE_SIZE: - { - cpl_size *szp = column->values->sz; + case CPL_TYPE_LONG_LONG: { + long long *llp = column->values->ll; - if (column->nullcount == 0) { - while (length--) - *fp++ = *szp++; - } - else { - while (length--) { - if (*np++ == 0) - *fp = *szp; - fp++; - szp++; + if (column->nullcount == 0) { + while (length--) + *fp++ = *llp++; } + else { + while (length--) { + if (*np++ == 0) + *fp = *llp; + fp++; + llp++; + } + } + break; } - break; - } - case CPL_TYPE_DOUBLE: - { - double *dp = column->values->d; + case CPL_TYPE_SIZE: { + cpl_size *szp = column->values->sz; - if (column->nullcount == 0) { - while (length--) - *fp++ = *dp++; - } - else { - while (length--) { - if (*np++ == 0) - *fp = *dp; - fp++; - dp++; + if (column->nullcount == 0) { + while (length--) + *fp++ = *szp++; } + else { + while (length--) { + if (*np++ == 0) + *fp = *szp; + fp++; + szp++; + } + } + break; } - break; - } - default: - cpl_error_set_(CPL_ERROR_UNSPECIFIED); - cpl_column_delete(new_column); - return NULL; + case CPL_TYPE_DOUBLE: { + double *dp = column->values->d; + + if (column->nullcount == 0) { + while (length--) + *fp++ = *dp++; + } + else { + while (length--) { + if (*np++ == 0) + *fp = *dp; + fp++; + dp++; + } + } + break; + } + + default: + cpl_error_set_(CPL_ERROR_UNSPECIFIED); + cpl_column_delete(new_column); + return NULL; } length = cpl_column_get_size(column); @@ -10431,22 +10210,21 @@ if (column->null) { new_column->null = cpl_malloc(length * sizeof(cpl_column_flag)); - memcpy(new_column->null, column->null, + memcpy(new_column->null, column->null, length * sizeof(cpl_column_flag)); } return new_column; - } -cpl_column *cpl_column_cast_to_float_array(const cpl_column *column) +cpl_column * +cpl_column_cast_to_float_array(const cpl_column *column) { - - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); - cpl_column *new_column = NULL; - int *np; - cpl_array **array; + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + cpl_column *new_column = NULL; + int *np; + cpl_array **array; if (column == NULL) { @@ -10464,21 +10242,20 @@ return NULL; } - new_column = cpl_column_new_array(CPL_TYPE_FLOAT | CPL_TYPE_POINTER, - length, 1); + new_column = + cpl_column_new_array(CPL_TYPE_FLOAT | CPL_TYPE_POINTER, length, 1); cpl_column_set_unit(new_column, cpl_column_get_unit(column)); - if (length == 0) /* No need to cast a 0 length column */ + if (length == 0) /* No need to cast a 0 length column */ return new_column; array = cpl_column_get_data_array(new_column); - np = column->null; + np = column->null; switch (type) { - case CPL_TYPE_INT: - { - int *ip = column->values->i; + case CPL_TYPE_INT: { + int *ip = column->values->i; if (column->nullcount == 0) { while (length--) { @@ -10500,9 +10277,8 @@ } break; } - case CPL_TYPE_LONG: - { - long *lp = column->values->l; + case CPL_TYPE_LONG: { + long *lp = column->values->l; if (column->nullcount == 0) { while (length--) { @@ -10524,9 +10300,8 @@ } break; } - case CPL_TYPE_LONG_LONG: - { - long long *llp = column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *llp = column->values->ll; if (column->nullcount == 0) { while (length--) { @@ -10548,9 +10323,8 @@ } break; } - case CPL_TYPE_SIZE: - { - cpl_size *szp = column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *szp = column->values->sz; if (column->nullcount == 0) { while (length--) { @@ -10572,9 +10346,8 @@ } break; } - case CPL_TYPE_FLOAT: - { - float *fp = column->values->f; + case CPL_TYPE_FLOAT: { + float *fp = column->values->f; if (column->nullcount == 0) { while (length--) { @@ -10596,9 +10369,8 @@ } break; } - case CPL_TYPE_DOUBLE: - { - double *dp = column->values->d; + case CPL_TYPE_DOUBLE: { + double *dp = column->values->d; if (column->nullcount == 0) { while (length--) { @@ -10627,16 +10399,15 @@ } return new_column; - } -cpl_column *cpl_column_cast_to_float_flat(const cpl_column *column) +cpl_column * +cpl_column_cast_to_float_flat(const cpl_column *column) { - - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); - cpl_column *new_column = NULL; - const cpl_array **array; + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + cpl_column *new_column = NULL; + const cpl_array **array; if (column == NULL) { @@ -10658,7 +10429,7 @@ cpl_column_set_unit(new_column, cpl_column_get_unit(column)); - if (length == 0) /* No need to cast a 0 length column */ + if (length == 0) /* No need to cast a 0 length column */ return new_column; array = cpl_column_get_data_array_const(column) + length; @@ -10674,7 +10445,6 @@ } return new_column; - } @@ -10697,16 +10467,16 @@ * a column of arrays into a column of plain doubles. */ -cpl_column *cpl_column_cast_to_double(const cpl_column *column) +cpl_column * +cpl_column_cast_to_double(const cpl_column *column) { - - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); - cpl_column *new_column = NULL; - const cpl_column*acolumn = NULL; - cpl_column *dcolumn = NULL; - int *np; - double *dp; + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + cpl_column *new_column = NULL; + const cpl_column *acolumn = NULL; + cpl_column *dcolumn = NULL; + int *np; + double *dp; if (column == NULL) { @@ -10737,18 +10507,17 @@ cpl_column_set_unit(new_column, cpl_column_get_unit(column)); - if (length == 0) /* No need to cast a 0 length column */ + if (length == 0) /* No need to cast a 0 length column */ return new_column; - if (column->nullcount == length) /* No need to copy just NULLs */ + if (column->nullcount == length) /* No need to copy just NULLs */ return new_column; if (type & CPL_TYPE_POINTER) { - const cpl_array **array = cpl_column_get_data_array_const(column); cpl_array **new_array = cpl_column_get_data_array(new_column); - while(length--) { + while (length--) { if (array[length]) { acolumn = cpl_array_get_column_const(array[length]); dcolumn = cpl_column_cast_to_double(acolumn); @@ -10759,16 +10528,14 @@ } return new_column; - } - dp = cpl_column_get_data_double(new_column); - np = column->null; + dp = cpl_column_get_data_double(new_column); + np = column->null; switch (type) { - case CPL_TYPE_INT: - { - int *ip = column->values->i; + case CPL_TYPE_INT: { + int *ip = column->values->i; if (column->nullcount == 0) { while (length--) @@ -10785,9 +10552,8 @@ break; } - case CPL_TYPE_LONG: - { - long *lp = column->values->l; + case CPL_TYPE_LONG: { + long *lp = column->values->l; if (column->nullcount == 0) { while (length--) @@ -10804,9 +10570,8 @@ break; } - case CPL_TYPE_LONG_LONG: - { - long long *llp = column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *llp = column->values->ll; if (column->nullcount == 0) { while (length--) @@ -10823,9 +10588,8 @@ break; } - case CPL_TYPE_SIZE: - { - cpl_size *szp = column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *szp = column->values->sz; if (column->nullcount == 0) { while (length--) @@ -10842,9 +10606,8 @@ break; } - case CPL_TYPE_FLOAT: - { - float *fp = column->values->f; + case CPL_TYPE_FLOAT: { + float *fp = column->values->f; if (column->nullcount == 0) { while (length--) @@ -10873,22 +10636,21 @@ if (column->null) { new_column->null = cpl_malloc(length * sizeof(cpl_column_flag)); - memcpy(new_column->null, column->null, + memcpy(new_column->null, column->null, length * sizeof(cpl_column_flag)); } return new_column; - } -cpl_column *cpl_column_cast_to_double_array(const cpl_column *column) +cpl_column * +cpl_column_cast_to_double_array(const cpl_column *column) { - - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); - cpl_column *new_column = NULL; - int *np; - cpl_array **array; + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + cpl_column *new_column = NULL; + int *np; + cpl_array **array; if (column == NULL) { @@ -10906,21 +10668,20 @@ return NULL; } - new_column = cpl_column_new_array(CPL_TYPE_DOUBLE | CPL_TYPE_POINTER, - length, 1); + new_column = + cpl_column_new_array(CPL_TYPE_DOUBLE | CPL_TYPE_POINTER, length, 1); cpl_column_set_unit(new_column, cpl_column_get_unit(column)); - if (length == 0) /* No need to cast a 0 length column */ + if (length == 0) /* No need to cast a 0 length column */ return new_column; array = cpl_column_get_data_array(new_column); - np = column->null; + np = column->null; switch (type) { - case CPL_TYPE_INT: - { - int *ip = column->values->i; + case CPL_TYPE_INT: { + int *ip = column->values->i; if (column->nullcount == 0) { while (length--) { @@ -10942,9 +10703,8 @@ } break; } - case CPL_TYPE_LONG: - { - long *lp = column->values->l; + case CPL_TYPE_LONG: { + long *lp = column->values->l; if (column->nullcount == 0) { while (length--) { @@ -10966,9 +10726,8 @@ } break; } - case CPL_TYPE_LONG_LONG: - { - long long *llp = column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *llp = column->values->ll; if (column->nullcount == 0) { while (length--) { @@ -10990,9 +10749,8 @@ } break; } - case CPL_TYPE_SIZE: - { - cpl_size *szp = column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *szp = column->values->sz; if (column->nullcount == 0) { while (length--) { @@ -11014,9 +10772,8 @@ } break; } - case CPL_TYPE_FLOAT: - { - float *fp = column->values->f; + case CPL_TYPE_FLOAT: { + float *fp = column->values->f; if (column->nullcount == 0) { while (length--) { @@ -11038,9 +10795,8 @@ } break; } - case CPL_TYPE_DOUBLE: - { - double *dp = column->values->d; + case CPL_TYPE_DOUBLE: { + double *dp = column->values->d; if (column->nullcount == 0) { while (length--) { @@ -11069,16 +10825,15 @@ } return new_column; - } -cpl_column *cpl_column_cast_to_double_flat(const cpl_column *column) +cpl_column * +cpl_column_cast_to_double_flat(const cpl_column *column) { - - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); - cpl_column *new_column = NULL; - const cpl_array **array; + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + cpl_column *new_column = NULL; + const cpl_array **array; if (column == NULL) { @@ -11100,7 +10855,7 @@ cpl_column_set_unit(new_column, cpl_column_get_unit(column)); - if (length == 0) /* No need to cast a 0 length column */ + if (length == 0) /* No need to cast a 0 length column */ return new_column; array = cpl_column_get_data_array_const(column) + length; @@ -11116,7 +10871,6 @@ } return new_column; - } @@ -11140,16 +10894,16 @@ * a column of arrays into a column of plain floats. */ -cpl_column *cpl_column_cast_to_float_complex(const cpl_column *column) +cpl_column * +cpl_column_cast_to_float_complex(const cpl_column *column) { - - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); - cpl_column *new_column = NULL; - const cpl_column*acolumn = NULL; - cpl_column *icolumn = NULL; - int *np; - float complex *cfp; + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + cpl_column *new_column = NULL; + const cpl_column *acolumn = NULL; + cpl_column *icolumn = NULL; + int *np; + float complex *cfp; if (column == NULL) { @@ -11163,16 +10917,16 @@ } if (!(type & CPL_TYPE_POINTER) && (type & CPL_TYPE_FLOAT) && - (type & CPL_TYPE_COMPLEX)) { + (type & CPL_TYPE_COMPLEX)) { new_column = cpl_column_duplicate(column); cpl_column_set_name(new_column, NULL); return new_column; } if (type & CPL_TYPE_POINTER) { - new_column = cpl_column_new_array(CPL_TYPE_FLOAT_COMPLEX | - CPL_TYPE_POINTER, length, - cpl_column_get_depth(column)); + new_column = + cpl_column_new_array(CPL_TYPE_FLOAT_COMPLEX | CPL_TYPE_POINTER, + length, cpl_column_get_depth(column)); if (column->dimensions) new_column->dimensions = cpl_array_duplicate(column->dimensions); } @@ -11182,18 +10936,17 @@ cpl_column_set_unit(new_column, cpl_column_get_unit(column)); - if (length == 0) /* No need to cast a 0 length column */ + if (length == 0) /* No need to cast a 0 length column */ return new_column; - - if (column->nullcount == length) /* No need to copy just NULLs */ + + if (column->nullcount == length) /* No need to copy just NULLs */ return new_column; if (type & CPL_TYPE_POINTER) { - const cpl_array **array = cpl_column_get_data_array_const(column); cpl_array **new_array = cpl_column_get_data_array(new_column); - while(length--) { + while (length--) { if (array[length]) { acolumn = cpl_array_get_column_const(array[length]); icolumn = cpl_column_cast_to_float_complex(acolumn); @@ -11204,17 +10957,14 @@ } return new_column; - } cfp = cpl_column_get_data_float_complex(new_column); - np = column->null; + np = column->null; switch (type) { - - case CPL_TYPE_INT: - { - int *ip = column->values->i; + case CPL_TYPE_INT: { + int *ip = column->values->i; if (column->nullcount == 0) { while (length--) @@ -11231,9 +10981,8 @@ break; } - case CPL_TYPE_LONG: - { - long *lp = column->values->l; + case CPL_TYPE_LONG: { + long *lp = column->values->l; if (column->nullcount == 0) { while (length--) @@ -11250,9 +10999,8 @@ break; } - case CPL_TYPE_LONG_LONG: - { - long long *llp = column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *llp = column->values->ll; if (column->nullcount == 0) { while (length--) @@ -11269,9 +11017,8 @@ break; } - case CPL_TYPE_SIZE: - { - cpl_size *szp = column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *szp = column->values->sz; if (column->nullcount == 0) { while (length--) @@ -11288,9 +11035,8 @@ break; } - case CPL_TYPE_FLOAT: - { - float *fp = column->values->f; + case CPL_TYPE_FLOAT: { + float *fp = column->values->f; if (column->nullcount == 0) { while (length--) @@ -11307,8 +11053,7 @@ break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *cdp = column->values->cd; if (column->nullcount == 0) { @@ -11338,22 +11083,21 @@ if (column->null) { new_column->null = cpl_malloc(length * sizeof(cpl_column_flag)); - memcpy(new_column->null, column->null, + memcpy(new_column->null, column->null, length * sizeof(cpl_column_flag)); } return new_column; - } -cpl_column *cpl_column_cast_to_float_complex_array(const cpl_column *column) +cpl_column * +cpl_column_cast_to_float_complex_array(const cpl_column *column) { - - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); - cpl_column *new_column = NULL; - int *np; - cpl_array **array; + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + cpl_column *new_column = NULL; + int *np; + cpl_array **array; if (column == NULL) { @@ -11371,21 +11115,20 @@ return NULL; } - new_column = cpl_column_new_array(CPL_TYPE_FLOAT_COMPLEX | - CPL_TYPE_POINTER, length, 1); + new_column = cpl_column_new_array(CPL_TYPE_FLOAT_COMPLEX | CPL_TYPE_POINTER, + length, 1); cpl_column_set_unit(new_column, cpl_column_get_unit(column)); - if (length == 0) /* No need to cast a 0 length column */ + if (length == 0) /* No need to cast a 0 length column */ return new_column; array = cpl_column_get_data_array(new_column); - np = column->null; + np = column->null; switch (type) { - case CPL_TYPE_INT: - { - int *ip = column->values->i; + case CPL_TYPE_INT: { + int *ip = column->values->i; if (column->nullcount == 0) { while (length--) { @@ -11407,9 +11150,8 @@ } break; } - case CPL_TYPE_LONG: - { - long *lp = column->values->l; + case CPL_TYPE_LONG: { + long *lp = column->values->l; if (column->nullcount == 0) { while (length--) { @@ -11431,9 +11173,8 @@ } break; } - case CPL_TYPE_LONG_LONG: - { - long long *llp = column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *llp = column->values->ll; if (column->nullcount == 0) { while (length--) { @@ -11455,9 +11196,8 @@ } break; } - case CPL_TYPE_SIZE: - { - cpl_size *szp = column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *szp = column->values->sz; if (column->nullcount == 0) { while (length--) { @@ -11479,9 +11219,8 @@ } break; } - case CPL_TYPE_FLOAT: - { - float *fp = column->values->f; + case CPL_TYPE_FLOAT: { + float *fp = column->values->f; if (column->nullcount == 0) { while (length--) { @@ -11503,9 +11242,8 @@ } break; } - case CPL_TYPE_DOUBLE: - { - double *dp = column->values->d; + case CPL_TYPE_DOUBLE: { + double *dp = column->values->d; if (column->nullcount == 0) { while (length--) { @@ -11527,9 +11265,8 @@ } break; } - case CPL_TYPE_FLOAT_COMPLEX: - { - float complex *cfp = column->values->cf; + case CPL_TYPE_FLOAT_COMPLEX: { + float complex *cfp = column->values->cf; if (column->nullcount == 0) { while (length--) { @@ -11551,9 +11288,8 @@ } break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { - double complex *cdp = column->values->cd; + case CPL_TYPE_DOUBLE_COMPLEX: { + double complex *cdp = column->values->cd; if (column->nullcount == 0) { while (length--) { @@ -11582,16 +11318,15 @@ } return new_column; - } -cpl_column *cpl_column_cast_to_float_complex_flat(const cpl_column *column) +cpl_column * +cpl_column_cast_to_float_complex_flat(const cpl_column *column) { - - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); - cpl_column *new_column = NULL; - const cpl_array **array; + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + cpl_column *new_column = NULL; + const cpl_array **array; if (column == NULL) { @@ -11613,7 +11348,7 @@ cpl_column_set_unit(new_column, cpl_column_get_unit(column)); - if (length == 0) /* No need to cast a 0 length column */ + if (length == 0) /* No need to cast a 0 length column */ return new_column; array = cpl_column_get_data_array_const(column) + length; @@ -11624,25 +11359,27 @@ if (array && *array) { if (cpl_array_is_valid(*array, 0)) { cpl_column_set_float_complex(new_column, length, - cpl_array_get_complex(*array, 0, NULL)); + cpl_array_get_complex(*array, + 0, + NULL)); } } } - } - else { + } + else { while (length--) { array--; if (array && *array) { if (cpl_array_is_valid(*array, 0)) { cpl_column_set_float_complex(new_column, length, - cpl_array_get(*array, 0, NULL)); + cpl_array_get(*array, 0, + NULL)); } } } } return new_column; - } @@ -11665,15 +11402,15 @@ * a column of arrays into a column of plain doubles. */ -cpl_column *cpl_column_cast_to_double_complex(const cpl_column *column) +cpl_column * +cpl_column_cast_to_double_complex(const cpl_column *column) { - - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); - cpl_column *new_column = NULL; - const cpl_column*acolumn = NULL; - cpl_column *icolumn = NULL; - int *np; + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + cpl_column *new_column = NULL; + const cpl_column *acolumn = NULL; + cpl_column *icolumn = NULL; + int *np; double complex *cdp; @@ -11688,16 +11425,16 @@ } if (!(type & CPL_TYPE_POINTER) && (type & CPL_TYPE_DOUBLE) && - (type & CPL_TYPE_COMPLEX)) { + (type & CPL_TYPE_COMPLEX)) { new_column = cpl_column_duplicate(column); cpl_column_set_name(new_column, NULL); return new_column; } if (type & CPL_TYPE_POINTER) { - new_column = cpl_column_new_array(CPL_TYPE_DOUBLE_COMPLEX | - CPL_TYPE_POINTER, length, - cpl_column_get_depth(column)); + new_column = + cpl_column_new_array(CPL_TYPE_DOUBLE_COMPLEX | CPL_TYPE_POINTER, + length, cpl_column_get_depth(column)); if (column->dimensions) new_column->dimensions = cpl_array_duplicate(column->dimensions); } @@ -11707,18 +11444,17 @@ cpl_column_set_unit(new_column, cpl_column_get_unit(column)); - if (length == 0) /* No need to cast a 0 length column */ + if (length == 0) /* No need to cast a 0 length column */ return new_column; - if (column->nullcount == length) /* No need to copy just NULLs */ + if (column->nullcount == length) /* No need to copy just NULLs */ return new_column; if (type & CPL_TYPE_POINTER) { - const cpl_array **array = cpl_column_get_data_array_const(column); cpl_array **new_array = cpl_column_get_data_array(new_column); - while(length--) { + while (length--) { if (array[length]) { acolumn = cpl_array_get_column_const(array[length]); icolumn = cpl_column_cast_to_double_complex(acolumn); @@ -11729,16 +11465,14 @@ } return new_column; - } - cdp = cpl_column_get_data_double_complex(new_column); - np = column->null; + cdp = cpl_column_get_data_double_complex(new_column); + np = column->null; switch (type) { - case CPL_TYPE_INT: - { - int *ip = column->values->i; + case CPL_TYPE_INT: { + int *ip = column->values->i; if (column->nullcount == 0) { while (length--) @@ -11755,9 +11489,8 @@ break; } - case CPL_TYPE_LONG: - { - long *lp = column->values->l; + case CPL_TYPE_LONG: { + long *lp = column->values->l; if (column->nullcount == 0) { while (length--) @@ -11774,9 +11507,8 @@ break; } - case CPL_TYPE_LONG_LONG: - { - long long *llp = column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *llp = column->values->ll; if (column->nullcount == 0) { while (length--) @@ -11793,9 +11525,8 @@ break; } - case CPL_TYPE_SIZE: - { - cpl_size *szp = column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *szp = column->values->sz; if (column->nullcount == 0) { while (length--) @@ -11812,9 +11543,8 @@ break; } - case CPL_TYPE_FLOAT: - { - float *fp = column->values->f; + case CPL_TYPE_FLOAT: { + float *fp = column->values->f; if (column->nullcount == 0) { while (length--) @@ -11831,9 +11561,8 @@ break; } - case CPL_TYPE_DOUBLE: - { - double *dp = column->values->d; + case CPL_TYPE_DOUBLE: { + double *dp = column->values->d; if (column->nullcount == 0) { while (length--) @@ -11850,9 +11579,8 @@ break; } - case CPL_TYPE_FLOAT_COMPLEX: - { - float complex *cfp = column->values->cf; + case CPL_TYPE_FLOAT_COMPLEX: { + float complex *cfp = column->values->cf; if (column->nullcount == 0) { while (length--) @@ -11881,22 +11609,21 @@ if (column->null) { new_column->null = cpl_malloc(length * sizeof(cpl_column_flag)); - memcpy(new_column->null, column->null, + memcpy(new_column->null, column->null, length * sizeof(cpl_column_flag)); } return new_column; - } -cpl_column *cpl_column_cast_to_double_complex_array(const cpl_column *column) +cpl_column * +cpl_column_cast_to_double_complex_array(const cpl_column *column) { - - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); - cpl_column *new_column = NULL; - int *np; - cpl_array **array; + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + cpl_column *new_column = NULL; + int *np; + cpl_array **array; if (column == NULL) { @@ -11914,21 +11641,21 @@ return NULL; } - new_column = cpl_column_new_array(CPL_TYPE_DOUBLE_COMPLEX | - CPL_TYPE_POINTER, length, 1); + new_column = + cpl_column_new_array(CPL_TYPE_DOUBLE_COMPLEX | CPL_TYPE_POINTER, length, + 1); cpl_column_set_unit(new_column, cpl_column_get_unit(column)); - if (length == 0) /* No need to cast a 0 length column */ + if (length == 0) /* No need to cast a 0 length column */ return new_column; array = cpl_column_get_data_array(new_column); - np = column->null; + np = column->null; switch (type) { - case CPL_TYPE_INT: - { - int *ip = column->values->i; + case CPL_TYPE_INT: { + int *ip = column->values->i; if (column->nullcount == 0) { while (length--) { @@ -11950,9 +11677,8 @@ } break; } - case CPL_TYPE_LONG: - { - long *lp = column->values->l; + case CPL_TYPE_LONG: { + long *lp = column->values->l; if (column->nullcount == 0) { while (length--) { @@ -11974,9 +11700,8 @@ } break; } - case CPL_TYPE_LONG_LONG: - { - long long *llp = column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *llp = column->values->ll; if (column->nullcount == 0) { while (length--) { @@ -11998,9 +11723,8 @@ } break; } - case CPL_TYPE_SIZE: - { - cpl_size *szp = column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *szp = column->values->sz; if (column->nullcount == 0) { while (length--) { @@ -12022,9 +11746,8 @@ } break; } - case CPL_TYPE_FLOAT: - { - float *fp = column->values->f; + case CPL_TYPE_FLOAT: { + float *fp = column->values->f; if (column->nullcount == 0) { while (length--) { @@ -12046,9 +11769,8 @@ } break; } - case CPL_TYPE_DOUBLE: - { - double *dp = column->values->d; + case CPL_TYPE_DOUBLE: { + double *dp = column->values->d; if (column->nullcount == 0) { while (length--) { @@ -12070,8 +11792,7 @@ } break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *cfp = column->values->cf; if (column->nullcount == 0) { @@ -12094,8 +11815,7 @@ } break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *cdp = column->values->cd; if (column->nullcount == 0) { @@ -12125,16 +11845,15 @@ } return new_column; - } -cpl_column *cpl_column_cast_to_double_complex_flat(const cpl_column *column) +cpl_column * +cpl_column_cast_to_double_complex_flat(const cpl_column *column) { - - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); - cpl_column *new_column = NULL; - const cpl_array **array; + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + cpl_column *new_column = NULL; + const cpl_array **array; if (column == NULL) { @@ -12156,7 +11875,7 @@ cpl_column_set_unit(new_column, cpl_column_get_unit(column)); - if (length == 0) /* No need to cast a 0 length column */ + if (length == 0) /* No need to cast a 0 length column */ return new_column; array = cpl_column_get_data_array_const(column) + length; @@ -12167,7 +11886,9 @@ if (array && *array) { if (cpl_array_is_valid(*array, 0)) { cpl_column_set_double_complex(new_column, length, - cpl_array_get_complex(*array, 0, NULL)); + cpl_array_get_complex(*array, + 0, + NULL)); } } } @@ -12178,14 +11899,14 @@ if (array && *array) { if (cpl_array_is_valid(*array, 0)) { cpl_column_set_double_complex(new_column, length, - cpl_array_get(*array, 0, NULL)); + cpl_array_get(*array, 0, + NULL)); } } } } return new_column; - } @@ -12210,16 +11931,16 @@ * invalid element flags are also transferred to the new column. */ -cpl_column *cpl_column_extract(cpl_column *column, - cpl_size start, cpl_size count) +cpl_column * +cpl_column_extract(cpl_column *column, cpl_size start, cpl_size count) { cpl_column *new_column = NULL; - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); - cpl_size depth = cpl_column_get_depth(column); - size_t byte_count; - cpl_size i; - cpl_size j; + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + cpl_size depth = cpl_column_get_depth(column); + size_t byte_count; + cpl_size i; + cpl_size j; if (column == NULL) { @@ -12240,108 +11961,110 @@ if (count > length - start) count = length - start; - byte_count = (size_t)count * cpl_column_type_size(type); + byte_count = (size_t)count * cpl_column_type_size(type); if (type & CPL_TYPE_POINTER) { switch (type & ~CPL_TYPE_POINTER) { - case CPL_TYPE_INT: - case CPL_TYPE_LONG: - case CPL_TYPE_LONG_LONG: - case CPL_TYPE_FLOAT: - case CPL_TYPE_DOUBLE: - case CPL_TYPE_FLOAT_COMPLEX: - case CPL_TYPE_DOUBLE_COMPLEX: - case CPL_TYPE_STRING: - - new_column = cpl_column_new_array(type, count, depth); - for (i = 0, j = start; i < count; i++, j++) { - if (column->values->array[j]) - new_column->values->array[i] = - cpl_array_duplicate(column->values->array[j]); - else - new_column->values->array[i] = NULL; - } - - if (column->dimensions) - new_column->dimensions = cpl_array_duplicate(column->dimensions); - - break; + case CPL_TYPE_INT: + case CPL_TYPE_LONG: + case CPL_TYPE_LONG_LONG: + case CPL_TYPE_FLOAT: + case CPL_TYPE_DOUBLE: + case CPL_TYPE_FLOAT_COMPLEX: + case CPL_TYPE_DOUBLE_COMPLEX: + case CPL_TYPE_STRING: - default: - cpl_error_set_(CPL_ERROR_UNSPECIFIED); - return NULL; + new_column = cpl_column_new_array(type, count, depth); + for (i = 0, j = start; i < count; i++, j++) { + if (column->values->array[j]) + new_column->values->array[i] = + cpl_array_duplicate(column->values->array[j]); + else + new_column->values->array[i] = NULL; + } + + if (column->dimensions) + new_column->dimensions = + cpl_array_duplicate(column->dimensions); + + break; + + default: + cpl_error_set_(CPL_ERROR_UNSPECIFIED); + return NULL; } - } else { + } + else { switch (type) { + case CPL_TYPE_INT: + new_column = cpl_column_new_int(count); + if (count) + memcpy(new_column->values->i, column->values->i + start, + byte_count); + break; - case CPL_TYPE_INT: - new_column = cpl_column_new_int(count); - if (count) - memcpy(new_column->values->i, - column->values->i + start, byte_count); - break; - - case CPL_TYPE_LONG: - new_column = cpl_column_new_long(count); - if (count) - memcpy(new_column->values->l, - column->values->l + start, byte_count); - break; + case CPL_TYPE_LONG: + new_column = cpl_column_new_long(count); + if (count) + memcpy(new_column->values->l, column->values->l + start, + byte_count); + break; - case CPL_TYPE_LONG_LONG: - new_column = cpl_column_new_long_long(count); - if (count) - memcpy(new_column->values->ll, - column->values->ll + start, byte_count); - break; + case CPL_TYPE_LONG_LONG: + new_column = cpl_column_new_long_long(count); + if (count) + memcpy(new_column->values->ll, column->values->ll + start, + byte_count); + break; - case CPL_TYPE_SIZE: - new_column = cpl_column_new_cplsize(count); - if (count) - memcpy(new_column->values->sz, - column->values->sz + start, byte_count); - break; + case CPL_TYPE_SIZE: + new_column = cpl_column_new_cplsize(count); + if (count) + memcpy(new_column->values->sz, column->values->sz + start, + byte_count); + break; - case CPL_TYPE_FLOAT: - new_column = cpl_column_new_float(count); - if (count) - memcpy(new_column->values->f, - column->values->f + start, byte_count); - break; + case CPL_TYPE_FLOAT: + new_column = cpl_column_new_float(count); + if (count) + memcpy(new_column->values->f, column->values->f + start, + byte_count); + break; - case CPL_TYPE_DOUBLE: - new_column = cpl_column_new_double(count); - if (count) - memcpy(new_column->values->d, - column->values->d + start, byte_count); - break; + case CPL_TYPE_DOUBLE: + new_column = cpl_column_new_double(count); + if (count) + memcpy(new_column->values->d, column->values->d + start, + byte_count); + break; - case CPL_TYPE_FLOAT_COMPLEX: - new_column = cpl_column_new_float_complex(count); - if (count) - memcpy(new_column->values->cf, - column->values->cf + start, byte_count); - break; + case CPL_TYPE_FLOAT_COMPLEX: + new_column = cpl_column_new_float_complex(count); + if (count) + memcpy(new_column->values->cf, column->values->cf + start, + byte_count); + break; - case CPL_TYPE_DOUBLE_COMPLEX: - new_column = cpl_column_new_double_complex(count); - if (count) - memcpy(new_column->values->cd, - column->values->cd + start, byte_count); - break; + case CPL_TYPE_DOUBLE_COMPLEX: + new_column = cpl_column_new_double_complex(count); + if (count) + memcpy(new_column->values->cd, column->values->cd + start, + byte_count); + break; - case CPL_TYPE_STRING: - new_column = cpl_column_new_string(count); - for (i = 0, j = start; i < count; i++, j++) - if (column->values->s[j]) - new_column->values->s[i] = cpl_strdup(column->values->s[j]); - else - new_column->values->s[i] = NULL; - break; + case CPL_TYPE_STRING: + new_column = cpl_column_new_string(count); + for (i = 0, j = start; i < count; i++, j++) + if (column->values->s[j]) + new_column->values->s[i] = + cpl_strdup(column->values->s[j]); + else + new_column->values->s[i] = NULL; + break; - default: - cpl_error_set_(CPL_ERROR_UNSPECIFIED); - return NULL; + default: + cpl_error_set_(CPL_ERROR_UNSPECIFIED); + return NULL; } } @@ -12349,7 +12072,6 @@ cpl_column_set_format(new_column, cpl_column_get_format(column)); if (column->null) { - /* * If an invalid flags buffer exists in the original column, * we have to take care of the (possible) duplication of @@ -12361,35 +12083,30 @@ if (column->null[j]) new_column->nullcount++; - if (new_column->nullcount != 0 && - new_column->nullcount != count) { + if (new_column->nullcount != 0 && new_column->nullcount != count) { new_column->null = cpl_calloc(count, sizeof(cpl_column_flag)); for (i = 0, j = start; i < count; i++, j++) if (column->null[j]) new_column->null[i] = 1; } - } else { - - /* + /* * An invalid flag buffer doesn't exist in the original column, * and this means no invalid elements, or all elements are invalid, * also for the subcolumn. */ - if (column->nullcount == 0) - new_column->nullcount = 0; - else - new_column->nullcount = cpl_column_get_size(new_column); - + if (column->nullcount == 0) + new_column->nullcount = 0; + else + new_column->nullcount = cpl_column_get_size(new_column); } return new_column; - } - + /* * @brief * Insert a column into another column of the same type. @@ -12416,23 +12133,24 @@ * (in case of array columns) is ignored. */ -cpl_error_code cpl_column_merge(cpl_column *target_column, - const cpl_column *insert_column, cpl_size position) -{ - - cpl_size t_length = cpl_column_get_size(target_column); - cpl_size i_length = cpl_column_get_size(insert_column); - cpl_type t_type = cpl_column_get_type(target_column); - cpl_type i_type = cpl_column_get_type(insert_column); - size_t i_size = (size_t)i_length * cpl_column_type_size(i_type); - cpl_size i; - cpl_size j; +cpl_error_code +cpl_column_merge(cpl_column *target_column, + const cpl_column *insert_column, + cpl_size position) +{ + cpl_size t_length = cpl_column_get_size(target_column); + cpl_size i_length = cpl_column_get_size(insert_column); + cpl_type t_type = cpl_column_get_type(target_column); + cpl_type i_type = cpl_column_get_type(insert_column); + size_t i_size = (size_t)i_length * cpl_column_type_size(i_type); + cpl_size i; + cpl_size j; if (target_column == NULL || insert_column == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); - if (position < 0) + if (position < 0) return cpl_error_set_(CPL_ERROR_ACCESS_OUT_OF_RANGE); if (t_type != i_type) @@ -12467,83 +12185,80 @@ * to the expanded part of the target column: */ - t_length = cpl_column_get_size(target_column); /* It got longer */ + t_length = cpl_column_get_size(target_column); /* It got longer */ if (i_type & CPL_TYPE_POINTER) { switch (i_type & ~CPL_TYPE_POINTER) { - case CPL_TYPE_INT: - case CPL_TYPE_LONG: - case CPL_TYPE_LONG_LONG: - case CPL_TYPE_FLOAT: - case CPL_TYPE_DOUBLE: - case CPL_TYPE_FLOAT_COMPLEX: - case CPL_TYPE_DOUBLE_COMPLEX: - case CPL_TYPE_STRING: - - for (i = 0, j = position; i < i_length; i++, j++) - if (insert_column->values->array[i]) - target_column->values->array[j] = - cpl_array_duplicate(insert_column->values->array[i]); - break; + case CPL_TYPE_INT: + case CPL_TYPE_LONG: + case CPL_TYPE_LONG_LONG: + case CPL_TYPE_FLOAT: + case CPL_TYPE_DOUBLE: + case CPL_TYPE_FLOAT_COMPLEX: + case CPL_TYPE_DOUBLE_COMPLEX: + case CPL_TYPE_STRING: - default: - return cpl_error_set_(CPL_ERROR_UNSPECIFIED); + for (i = 0, j = position; i < i_length; i++, j++) + if (insert_column->values->array[i]) + target_column->values->array[j] = cpl_array_duplicate( + insert_column->values->array[i]); + break; + default: + return cpl_error_set_(CPL_ERROR_UNSPECIFIED); } - } else { - + } + else { switch (i_type) { + case CPL_TYPE_INT: + memcpy(target_column->values->i + position, + insert_column->values->i, i_size); + break; - case CPL_TYPE_INT: - memcpy(target_column->values->i + position, - insert_column->values->i, i_size); - break; - - case CPL_TYPE_LONG: - memcpy(target_column->values->l + position, - insert_column->values->l, i_size); - break; - - case CPL_TYPE_LONG_LONG: - memcpy(target_column->values->ll + position, - insert_column->values->ll, i_size); - break; + case CPL_TYPE_LONG: + memcpy(target_column->values->l + position, + insert_column->values->l, i_size); + break; - case CPL_TYPE_SIZE: - memcpy(target_column->values->sz + position, - insert_column->values->sz, i_size); - break; + case CPL_TYPE_LONG_LONG: + memcpy(target_column->values->ll + position, + insert_column->values->ll, i_size); + break; - case CPL_TYPE_FLOAT: - memcpy(target_column->values->f + position, - insert_column->values->f, i_size); - break; + case CPL_TYPE_SIZE: + memcpy(target_column->values->sz + position, + insert_column->values->sz, i_size); + break; - case CPL_TYPE_DOUBLE: - memcpy(target_column->values->d + position, - insert_column->values->d, i_size); - break; + case CPL_TYPE_FLOAT: + memcpy(target_column->values->f + position, + insert_column->values->f, i_size); + break; - case CPL_TYPE_FLOAT_COMPLEX: - memcpy(target_column->values->cf + position, - insert_column->values->cf, i_size); - break; + case CPL_TYPE_DOUBLE: + memcpy(target_column->values->d + position, + insert_column->values->d, i_size); + break; - case CPL_TYPE_DOUBLE_COMPLEX: - memcpy(target_column->values->cd + position, - insert_column->values->cd, i_size); - break; + case CPL_TYPE_FLOAT_COMPLEX: + memcpy(target_column->values->cf + position, + insert_column->values->cf, i_size); + break; - case CPL_TYPE_STRING: - for (i = 0, j = position; i < i_length; i++, j++) - if (insert_column->values->s[i]) - target_column->values->s[j] = - cpl_strdup(insert_column->values->s[i]); - break; + case CPL_TYPE_DOUBLE_COMPLEX: + memcpy(target_column->values->cd + position, + insert_column->values->cd, i_size); + break; - default: - return cpl_error_set_(CPL_ERROR_UNSPECIFIED); + case CPL_TYPE_STRING: + for (i = 0, j = position; i < i_length; i++, j++) + if (insert_column->values->s[i]) + target_column->values->s[j] = + cpl_strdup(insert_column->values->s[i]); + break; + default: + return cpl_error_set_(CPL_ERROR_UNSPECIFIED); } } @@ -12556,9 +12271,7 @@ */ if (target_column->null) { - if (insert_column->null) { - /* * Both null flags buffers exist. The expanded part of * the target column already consists of invalid elements, @@ -12569,12 +12282,10 @@ if (!insert_column->null[i]) { target_column->null[j] = 0; target_column->nullcount--; - } - } + } + } } else { - - /* * Just the target column has the invalid flag buffer. This * means necessarily that the column to insert has no invalid @@ -12586,8 +12297,6 @@ */ if (target_column->nullcount > i_length) { - - /* * Surely target_column->nullcount is at least i_length, * i.e., the number of invalid elements added by the @@ -12603,11 +12312,9 @@ } target_column->nullcount -= i_length; - } } else { - /* * The target column invalid flags buffer doesn't exist. * Excluding the case of array or string columns, this is @@ -12625,8 +12332,7 @@ target_column->null[i] = 1; if (insert_column->null) { - - /* + /* * Some invalid elements: */ @@ -12636,10 +12342,8 @@ target_column->nullcount--; } } - } else { - /* * No invalid elements: */ @@ -12663,7 +12367,6 @@ } return 0; - } @@ -12691,15 +12394,15 @@ * overflows are ignored. This function is not applicable to array columns. */ -cpl_error_code cpl_column_add(cpl_column *to_column, cpl_column *from_column) +cpl_error_code +cpl_column_add(cpl_column *to_column, cpl_column *from_column) { - - cpl_size i; - cpl_size to_length = cpl_column_get_size(to_column); - cpl_size from_length = cpl_column_get_size(from_column); - cpl_type to_type = cpl_column_get_type(to_column); - cpl_type from_type = cpl_column_get_type(from_column); - int *tnp; + cpl_size i; + cpl_size to_length = cpl_column_get_size(to_column); + cpl_size from_length = cpl_column_get_size(from_column); + cpl_type to_type = cpl_column_get_type(to_column); + cpl_type from_type = cpl_column_get_type(from_column); + int *tnp; if (to_column == NULL || from_column == NULL) @@ -12723,80 +12426,74 @@ if (to_column->nullcount == 0 && from_column->nullcount == 0) { - /* * If there are no invalid elements in both columns, the operation * can be performed without any check: */ switch (to_type) { - case CPL_TYPE_INT: - { - int *tip = to_column->values->i; + case CPL_TYPE_INT: { + int *tip = to_column->values->i; switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) *tip++ += *fip++; break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) *tip++ += *flp++; break; } - case CPL_TYPE_LONG_LONG: - { - long long *fllp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *fllp = from_column->values->ll; while (to_length--) *tip++ += *fllp++; break; } - case CPL_TYPE_SIZE: - { - cpl_size *fszp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *fszp = from_column->values->sz; while (to_length--) *tip++ += *fszp++; break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; while (to_length--) *tip++ += *ffp++; break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; while (to_length--) *tip++ += *fdp++; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; while (to_length--) - tip[to_length] = tip[to_length] + fcfp[to_length]; /* Support clang */ + tip[to_length] = + tip[to_length] + + fcfp[to_length]; /* Support clang */ break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; while (to_length--) - tip[to_length] = tip[to_length] + fcdp[to_length]; /* Support clang */ + tip[to_length] = + tip[to_length] + + fcdp[to_length]; /* Support clang */ break; } default: @@ -12804,73 +12501,68 @@ } break; } - case CPL_TYPE_LONG: - { - long *tlp = to_column->values->l; + case CPL_TYPE_LONG: { + long *tlp = to_column->values->l; switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) *tlp++ += *fip++; break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) *tlp++ += *flp++; break; } - case CPL_TYPE_LONG_LONG: - { - long long *fllp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *fllp = from_column->values->ll; while (to_length--) *tlp++ += *fllp++; break; } - case CPL_TYPE_SIZE: - { - cpl_size *fszp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *fszp = from_column->values->sz; while (to_length--) *tlp++ += *fszp++; break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; while (to_length--) *tlp++ += *ffp++; break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; while (to_length--) *tlp++ += *fdp++; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; while (to_length--) - tlp[to_length] = tlp[to_length] + fcfp[to_length]; /* Support clang */ + tlp[to_length] = + tlp[to_length] + + fcfp[to_length]; /* Support clang */ break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; while (to_length--) - tlp[to_length] = tlp[to_length] + fcdp[to_length]; /* Support clang */ + tlp[to_length] = + tlp[to_length] + + fcdp[to_length]; /* Support clang */ break; } default: @@ -12878,73 +12570,68 @@ } break; } - case CPL_TYPE_LONG_LONG: - { - long long *tlp = to_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *tlp = to_column->values->ll; switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) *tlp++ += *fip++; break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) *tlp++ += *flp++; break; } - case CPL_TYPE_LONG_LONG: - { - long long *fllp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *fllp = from_column->values->ll; while (to_length--) *tlp++ += *fllp++; break; } - case CPL_TYPE_SIZE: - { - cpl_size *fszp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *fszp = from_column->values->sz; while (to_length--) *tlp++ += *fszp++; break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; while (to_length--) *tlp++ += *ffp++; break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; while (to_length--) *tlp++ += *fdp++; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; while (to_length--) - tlp[to_length] = tlp[to_length] + fcfp[to_length]; /* Support clang */ + tlp[to_length] = + tlp[to_length] + + fcfp[to_length]; /* Support clang */ break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; while (to_length--) - tlp[to_length] = tlp[to_length] + fcdp[to_length]; /* Support clang */ + tlp[to_length] = + tlp[to_length] + + fcdp[to_length]; /* Support clang */ break; } default: @@ -12952,73 +12639,68 @@ } break; } - case CPL_TYPE_SIZE: - { - cpl_size *tlp = to_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *tlp = to_column->values->sz; switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) *tlp++ += *fip++; break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) *tlp++ += *flp++; break; } - case CPL_TYPE_LONG_LONG: - { - long long *fllp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *fllp = from_column->values->ll; while (to_length--) *tlp++ += *fllp++; break; } - case CPL_TYPE_SIZE: - { - cpl_size *fszp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *fszp = from_column->values->sz; while (to_length--) *tlp++ += *fszp++; break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; while (to_length--) *tlp++ += *ffp++; break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; while (to_length--) *tlp++ += *fdp++; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; while (to_length--) - tlp[to_length] = tlp[to_length] + fcfp[to_length]; /* Support clang */ + tlp[to_length] = + tlp[to_length] + + fcfp[to_length]; /* Support clang */ break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; while (to_length--) - tlp[to_length] = tlp[to_length] + fcdp[to_length]; /* Support clang */ + tlp[to_length] = + tlp[to_length] + + fcdp[to_length]; /* Support clang */ break; } default: @@ -13026,73 +12708,68 @@ } break; } - case CPL_TYPE_FLOAT: - { - float *tfp = to_column->values->f; + case CPL_TYPE_FLOAT: { + float *tfp = to_column->values->f; switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) *tfp++ += (double)*fip++; break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) *tfp++ += *flp++; break; } - case CPL_TYPE_LONG_LONG: - { - long long *fllp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *fllp = from_column->values->ll; while (to_length--) *tfp++ += *fllp++; break; } - case CPL_TYPE_SIZE: - { - cpl_size *fszp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *fszp = from_column->values->sz; while (to_length--) *tfp++ += *fszp++; break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; while (to_length--) *tfp++ += (double)*ffp++; break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; while (to_length--) *tfp++ += *fdp++; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; while (to_length--) - tfp[to_length] = tfp[to_length] + fcfp[to_length]; /* Support clang */ + tfp[to_length] = + tfp[to_length] + + fcfp[to_length]; /* Support clang */ break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; while (to_length--) - tfp[to_length] = tfp[to_length] + fcdp[to_length]; /* Support clang */ + tfp[to_length] = + tfp[to_length] + + fcdp[to_length]; /* Support clang */ break; } default: @@ -13100,73 +12777,68 @@ } break; } - case CPL_TYPE_DOUBLE: - { - double *tdp = to_column->values->d; + case CPL_TYPE_DOUBLE: { + double *tdp = to_column->values->d; switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) *tdp++ += *fip++; break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) *tdp++ += *flp++; break; } - case CPL_TYPE_LONG_LONG: - { - long long *fllp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *fllp = from_column->values->ll; while (to_length--) *tdp++ += *fllp++; break; } - case CPL_TYPE_SIZE: - { - cpl_size *fszp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *fszp = from_column->values->sz; while (to_length--) *tdp++ += *fszp++; break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; while (to_length--) *tdp++ += *ffp++; break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; while (to_length--) *tdp++ += *fdp++; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; while (to_length--) - tdp[to_length] = tdp[to_length] + fcfp[to_length]; /* Support clang */ + tdp[to_length] = + tdp[to_length] + + fcfp[to_length]; /* Support clang */ break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; while (to_length--) - tdp[to_length] = tdp[to_length] + fcdp[to_length]; /* Support clang */ + tdp[to_length] = + tdp[to_length] + + fcdp[to_length]; /* Support clang */ break; } default: @@ -13174,69 +12846,60 @@ } break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *tcfp = to_column->values->cf; switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) *tcfp++ += *fip++; break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) *tcfp++ += *flp++; break; } - case CPL_TYPE_LONG_LONG: - { - long long *fllp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *fllp = from_column->values->ll; while (to_length--) *tcfp++ += *fllp++; break; } - case CPL_TYPE_SIZE: - { - cpl_size *fszp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *fszp = from_column->values->sz; while (to_length--) *tcfp++ += *fszp++; break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; while (to_length--) *tcfp++ += *ffp++; break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; while (to_length--) *tcfp++ += *fdp++; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; while (to_length--) *tcfp++ += *fcfp++; break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; while (to_length--) @@ -13248,69 +12911,60 @@ } break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *tcdp = to_column->values->cd; switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) *tcdp++ += *fip++; break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) *tcdp++ += *flp++; break; } - case CPL_TYPE_LONG_LONG: - { - long long *fllp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *fllp = from_column->values->ll; while (to_length--) *tcdp++ += *fllp++; break; } - case CPL_TYPE_SIZE: - { - cpl_size *fszp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *fszp = from_column->values->sz; while (to_length--) *tcdp++ += *fszp++; break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; while (to_length--) *tcdp++ += *ffp++; break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; while (to_length--) *tcdp++ += *fdp++; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; while (to_length--) *tcdp++ += *fcfp++; break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; while (to_length--) @@ -13327,7 +12981,6 @@ } } else { - /* * Here there are some invalid elements, so the operation needs to be * performed with some checks. As a first thing, take care of the @@ -13335,7 +12988,6 @@ */ if (to_column->nullcount == 0 || from_column->nullcount == 0) { - /* * Here there are some invalid elements in just one of the two * columns. If they are just in the column to add, an identical @@ -13343,8 +12995,8 @@ */ if (from_column->nullcount) { - to_column->null = cpl_calloc(to_length, - sizeof(cpl_column_flag)); + to_column->null = + cpl_calloc(to_length, sizeof(cpl_column_flag)); i = to_length; while (i--) @@ -13352,11 +13004,9 @@ to_column->null[i] = 1; to_column->nullcount = from_column->nullcount; - } } else { - /* * Here there are some invalid elements in both columns. */ @@ -13372,7 +13022,6 @@ } if (to_column->nullcount == to_length) { - /* * Just invalid elements in the result: no need to perform * any further operation, and the invalid flag buffer of the @@ -13384,7 +13033,6 @@ to_column->null = NULL; return 0; } - } /* @@ -13395,14 +13043,12 @@ tnp = to_column->null; switch (to_type) { - case CPL_TYPE_INT: - { - int *tip = to_column->values->i; + case CPL_TYPE_INT: { + int *tip = to_column->values->i; switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) { if (*tnp++ == 0) @@ -13412,9 +13058,8 @@ } break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) { if (*tnp++ == 0) @@ -13424,9 +13069,8 @@ } break; } - case CPL_TYPE_LONG_LONG: - { - long long *fllp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *fllp = from_column->values->ll; while (to_length--) { if (*tnp++ == 0) @@ -13436,9 +13080,8 @@ } break; } - case CPL_TYPE_SIZE: - { - cpl_size *fszp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *fszp = from_column->values->sz; while (to_length--) { if (*tnp++ == 0) @@ -13448,9 +13091,8 @@ } break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; while (to_length--) { if (*tnp++ == 0) @@ -13460,9 +13102,8 @@ } break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; while (to_length--) { if (*tnp++ == 0) @@ -13472,8 +13113,7 @@ } break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; while (to_length--) { @@ -13484,8 +13124,7 @@ } break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; while (to_length--) { @@ -13501,14 +13140,12 @@ } break; } - case CPL_TYPE_LONG: - { - long *tlp = to_column->values->l; + case CPL_TYPE_LONG: { + long *tlp = to_column->values->l; switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) { if (*tnp++ == 0) @@ -13518,9 +13155,8 @@ } break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) { if (*tnp++ == 0) @@ -13530,9 +13166,8 @@ } break; } - case CPL_TYPE_LONG_LONG: - { - long long *fllp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *fllp = from_column->values->ll; while (to_length--) { if (*tnp++ == 0) @@ -13542,9 +13177,8 @@ } break; } - case CPL_TYPE_SIZE: - { - cpl_size *fszp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *fszp = from_column->values->sz; while (to_length--) { if (*tnp++ == 0) @@ -13554,9 +13188,8 @@ } break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; while (to_length--) { if (*tnp++ == 0) @@ -13566,9 +13199,8 @@ } break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; while (to_length--) { if (*tnp++ == 0) @@ -13578,8 +13210,7 @@ } break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; while (to_length--) { @@ -13590,8 +13221,7 @@ } break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; while (to_length--) { @@ -13607,14 +13237,12 @@ } break; } - case CPL_TYPE_LONG_LONG: - { - long long *tlp = to_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *tlp = to_column->values->ll; switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) { if (*tnp++ == 0) @@ -13624,9 +13252,8 @@ } break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) { if (*tnp++ == 0) @@ -13636,9 +13263,8 @@ } break; } - case CPL_TYPE_LONG_LONG: - { - long long *fllp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *fllp = from_column->values->ll; while (to_length--) { if (*tnp++ == 0) @@ -13648,9 +13274,8 @@ } break; } - case CPL_TYPE_SIZE: - { - cpl_size *fszp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *fszp = from_column->values->sz; while (to_length--) { if (*tnp++ == 0) @@ -13660,9 +13285,8 @@ } break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; while (to_length--) { if (*tnp++ == 0) @@ -13672,9 +13296,8 @@ } break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; while (to_length--) { if (*tnp++ == 0) @@ -13684,8 +13307,7 @@ } break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; while (to_length--) { @@ -13696,8 +13318,7 @@ } break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; while (to_length--) { @@ -13713,14 +13334,12 @@ } break; } - case CPL_TYPE_SIZE: - { - cpl_size *tlp = to_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *tlp = to_column->values->sz; switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) { if (*tnp++ == 0) @@ -13730,9 +13349,8 @@ } break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) { if (*tnp++ == 0) @@ -13742,9 +13360,8 @@ } break; } - case CPL_TYPE_LONG_LONG: - { - long long *fllp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *fllp = from_column->values->ll; while (to_length--) { if (*tnp++ == 0) @@ -13754,9 +13371,8 @@ } break; } - case CPL_TYPE_SIZE: - { - cpl_size *fszp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *fszp = from_column->values->sz; while (to_length--) { if (*tnp++ == 0) @@ -13766,9 +13382,8 @@ } break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; while (to_length--) { if (*tnp++ == 0) @@ -13778,9 +13393,8 @@ } break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; while (to_length--) { if (*tnp++ == 0) @@ -13790,8 +13404,7 @@ } break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; while (to_length--) { @@ -13802,8 +13415,7 @@ } break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; while (to_length--) { @@ -13819,14 +13431,12 @@ } break; } - case CPL_TYPE_FLOAT: - { - float *tfp = to_column->values->f; + case CPL_TYPE_FLOAT: { + float *tfp = to_column->values->f; switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) { if (*tnp++ == 0) @@ -13836,9 +13446,8 @@ } break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) { if (*tnp++ == 0) @@ -13848,9 +13457,8 @@ } break; } - case CPL_TYPE_LONG_LONG: - { - long long *fllp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *fllp = from_column->values->ll; while (to_length--) { if (*tnp++ == 0) @@ -13860,9 +13468,8 @@ } break; } - case CPL_TYPE_SIZE: - { - cpl_size *fszp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *fszp = from_column->values->sz; while (to_length--) { if (*tnp++ == 0) @@ -13872,9 +13479,8 @@ } break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; while (to_length--) { if (*tnp++ == 0) @@ -13884,9 +13490,8 @@ } break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; while (to_length--) { if (*tnp++ == 0) @@ -13896,8 +13501,7 @@ } break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; while (to_length--) { @@ -13908,8 +13512,7 @@ } break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; while (to_length--) { @@ -13925,14 +13528,12 @@ } break; } - case CPL_TYPE_DOUBLE: - { - double *tdp = to_column->values->d; + case CPL_TYPE_DOUBLE: { + double *tdp = to_column->values->d; switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) { if (*tnp++ == 0) @@ -13942,9 +13543,8 @@ } break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) { if (*tnp++ == 0) @@ -13954,9 +13554,8 @@ } break; } - case CPL_TYPE_LONG_LONG: - { - long long *fllp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *fllp = from_column->values->ll; while (to_length--) { if (*tnp++ == 0) @@ -13966,9 +13565,8 @@ } break; } - case CPL_TYPE_SIZE: - { - cpl_size *fszp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *fszp = from_column->values->sz; while (to_length--) { if (*tnp++ == 0) @@ -13978,9 +13576,8 @@ } break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; while (to_length--) { if (*tnp++ == 0) @@ -13990,9 +13587,8 @@ } break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; while (to_length--) { if (*tnp++ == 0) @@ -14002,8 +13598,7 @@ } break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; while (to_length--) { @@ -14014,8 +13609,7 @@ } break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; while (to_length--) { @@ -14031,14 +13625,12 @@ } break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *tcfp = to_column->values->cf; switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) { if (*tnp++ == 0) @@ -14048,9 +13640,8 @@ } break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) { if (*tnp++ == 0) @@ -14060,9 +13651,8 @@ } break; } - case CPL_TYPE_LONG_LONG: - { - long long *fllp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *fllp = from_column->values->ll; while (to_length--) { if (*tnp++ == 0) @@ -14072,9 +13662,8 @@ } break; } - case CPL_TYPE_SIZE: - { - cpl_size *fszp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *fszp = from_column->values->sz; while (to_length--) { if (*tnp++ == 0) @@ -14084,9 +13673,8 @@ } break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; while (to_length--) { if (*tnp++ == 0) @@ -14096,9 +13684,8 @@ } break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; while (to_length--) { if (*tnp++ == 0) @@ -14108,8 +13695,7 @@ } break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; while (to_length--) { @@ -14120,8 +13706,7 @@ } break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; while (to_length--) { @@ -14137,14 +13722,12 @@ } break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *tcdp = to_column->values->cd; switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) { if (*tnp++ == 0) @@ -14154,9 +13737,8 @@ } break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) { if (*tnp++ == 0) @@ -14166,9 +13748,8 @@ } break; } - case CPL_TYPE_LONG_LONG: - { - long long *fllp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *fllp = from_column->values->ll; while (to_length--) { if (*tnp++ == 0) @@ -14178,9 +13759,8 @@ } break; } - case CPL_TYPE_SIZE: - { - cpl_size *fszp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *fszp = from_column->values->sz; while (to_length--) { if (*tnp++ == 0) @@ -14190,9 +13770,8 @@ } break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; while (to_length--) { if (*tnp++ == 0) @@ -14202,9 +13781,8 @@ } break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; while (to_length--) { if (*tnp++ == 0) @@ -14214,8 +13792,7 @@ } break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; while (to_length--) { @@ -14226,8 +13803,7 @@ } break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; while (to_length--) { @@ -14249,7 +13825,6 @@ } return CPL_ERROR_NONE; - } @@ -14278,16 +13853,15 @@ * is not applicable to array columns. */ -cpl_error_code cpl_column_subtract(cpl_column *to_column, - cpl_column *from_column) +cpl_error_code +cpl_column_subtract(cpl_column *to_column, cpl_column *from_column) { - - cpl_size i; - cpl_size to_length = cpl_column_get_size(to_column); - cpl_size from_length = cpl_column_get_size(from_column); - cpl_type to_type = cpl_column_get_type(to_column); - cpl_type from_type = cpl_column_get_type(from_column); - int *tnp; + cpl_size i; + cpl_size to_length = cpl_column_get_size(to_column); + cpl_size from_length = cpl_column_get_size(from_column); + cpl_type to_type = cpl_column_get_type(to_column); + cpl_type from_type = cpl_column_get_type(from_column); + int *tnp; if (to_column == NULL || from_column == NULL) @@ -14311,81 +13885,74 @@ if (to_column->nullcount == 0 && from_column->nullcount == 0) { - /* * If there are no invalid elements in both columns, the operation * can be performed without any check: */ switch (to_type) { - case CPL_TYPE_INT: - { - - int *tip = to_column->values->i; + case CPL_TYPE_INT: { + int *tip = to_column->values->i; switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) *tip++ -= *fip++; break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) *tip++ -= *flp++; break; } - case CPL_TYPE_LONG_LONG: - { - long long *fllp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *fllp = from_column->values->ll; while (to_length--) *tip++ -= *fllp++; break; } - case CPL_TYPE_SIZE: - { - cpl_size *fszp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *fszp = from_column->values->sz; while (to_length--) *tip++ -= *fszp++; break; } - case CPL_TYPE_FLOAT: - { + case CPL_TYPE_FLOAT: { float *ffp = from_column->values->f; while (to_length--) *tip++ -= *ffp++; break; } - case CPL_TYPE_DOUBLE: - { + case CPL_TYPE_DOUBLE: { double *fdp = from_column->values->d; while (to_length--) *tip++ -= *fdp++; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { - float complex *fcfp = from_column->values->cf; + case CPL_TYPE_FLOAT_COMPLEX: { + float complex *fcfp = from_column->values->cf; while (to_length--) - tip[to_length] = tip[to_length] - fcfp[to_length]; /* Support clang */ + tip[to_length] = + tip[to_length] - + fcfp[to_length]; /* Support clang */ break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { - double complex *fcdp = from_column->values->cd; + case CPL_TYPE_DOUBLE_COMPLEX: { + double complex *fcdp = from_column->values->cd; while (to_length--) - tip[to_length] = tip[to_length] - fcdp[to_length]; /* Support clang */ + tip[to_length] = + tip[to_length] - + fcdp[to_length]; /* Support clang */ break; } default: @@ -14393,74 +13960,68 @@ } break; } - case CPL_TYPE_LONG: - { - - long *tlp = to_column->values->l; + case CPL_TYPE_LONG: { + long *tlp = to_column->values->l; switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) *tlp++ -= *fip++; break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) *tlp++ -= *flp++; break; } - case CPL_TYPE_LONG_LONG: - { - long long *fllp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *fllp = from_column->values->ll; while (to_length--) *tlp++ -= *fllp++; break; } - case CPL_TYPE_SIZE: - { - cpl_size *fszp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *fszp = from_column->values->sz; while (to_length--) *tlp++ -= *fszp++; break; } - case CPL_TYPE_FLOAT: - { + case CPL_TYPE_FLOAT: { float *ffp = from_column->values->f; while (to_length--) *tlp++ -= *ffp++; break; } - case CPL_TYPE_DOUBLE: - { + case CPL_TYPE_DOUBLE: { double *fdp = from_column->values->d; while (to_length--) *tlp++ -= *fdp++; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { - float complex *fcfp = from_column->values->cf; + case CPL_TYPE_FLOAT_COMPLEX: { + float complex *fcfp = from_column->values->cf; while (to_length--) - tlp[to_length] = tlp[to_length] - fcfp[to_length]; /* Support clang */ + tlp[to_length] = + tlp[to_length] - + fcfp[to_length]; /* Support clang */ break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { - double complex *fcdp = from_column->values->cd; + case CPL_TYPE_DOUBLE_COMPLEX: { + double complex *fcdp = from_column->values->cd; while (to_length--) - tlp[to_length] = tlp[to_length] - fcdp[to_length]; /* Support clang */ + tlp[to_length] = + tlp[to_length] - + fcdp[to_length]; /* Support clang */ break; } default: @@ -14468,74 +14029,68 @@ } break; } - case CPL_TYPE_LONG_LONG: - { - - long long *tlp = to_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *tlp = to_column->values->ll; switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) *tlp++ -= *fip++; break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) *tlp++ -= *flp++; break; } - case CPL_TYPE_LONG_LONG: - { - long long *fllp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *fllp = from_column->values->ll; while (to_length--) *tlp++ -= *fllp++; break; } - case CPL_TYPE_SIZE: - { - cpl_size *fszp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *fszp = from_column->values->sz; while (to_length--) *tlp++ -= *fszp++; break; } - case CPL_TYPE_FLOAT: - { + case CPL_TYPE_FLOAT: { float *ffp = from_column->values->f; while (to_length--) *tlp++ -= *ffp++; break; } - case CPL_TYPE_DOUBLE: - { + case CPL_TYPE_DOUBLE: { double *fdp = from_column->values->d; while (to_length--) *tlp++ -= *fdp++; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { - float complex *fcfp = from_column->values->cf; + case CPL_TYPE_FLOAT_COMPLEX: { + float complex *fcfp = from_column->values->cf; while (to_length--) - tlp[to_length] = tlp[to_length] - fcfp[to_length]; /* Support clang */ + tlp[to_length] = + tlp[to_length] - + fcfp[to_length]; /* Support clang */ break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { - double complex *fcdp = from_column->values->cd; + case CPL_TYPE_DOUBLE_COMPLEX: { + double complex *fcdp = from_column->values->cd; while (to_length--) - tlp[to_length] = tlp[to_length] - fcdp[to_length]; /* Support clang */ + tlp[to_length] = + tlp[to_length] - + fcdp[to_length]; /* Support clang */ break; } default: @@ -14543,74 +14098,68 @@ } break; } - case CPL_TYPE_SIZE: - { - - cpl_size *tlp = to_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *tlp = to_column->values->sz; switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) *tlp++ -= *fip++; break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) *tlp++ -= *flp++; break; } - case CPL_TYPE_LONG_LONG: - { - long long *fllp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *fllp = from_column->values->ll; while (to_length--) *tlp++ -= *fllp++; break; } - case CPL_TYPE_SIZE: - { - cpl_size *fszp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *fszp = from_column->values->sz; while (to_length--) *tlp++ -= *fszp++; break; } - case CPL_TYPE_FLOAT: - { + case CPL_TYPE_FLOAT: { float *ffp = from_column->values->f; while (to_length--) *tlp++ -= *ffp++; break; } - case CPL_TYPE_DOUBLE: - { + case CPL_TYPE_DOUBLE: { double *fdp = from_column->values->d; while (to_length--) *tlp++ -= *fdp++; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { - float complex *fcfp = from_column->values->cf; + case CPL_TYPE_FLOAT_COMPLEX: { + float complex *fcfp = from_column->values->cf; while (to_length--) - tlp[to_length] = tlp[to_length] - fcfp[to_length]; /* Support clang */ + tlp[to_length] = + tlp[to_length] - + fcfp[to_length]; /* Support clang */ break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { - double complex *fcdp = from_column->values->cd; + case CPL_TYPE_DOUBLE_COMPLEX: { + double complex *fcdp = from_column->values->cd; while (to_length--) - tlp[to_length] = tlp[to_length] - fcdp[to_length]; /* Support clang */ + tlp[to_length] = + tlp[to_length] - + fcdp[to_length]; /* Support clang */ break; } default: @@ -14618,74 +14167,68 @@ } break; } - case CPL_TYPE_FLOAT: - { - - float *tfp = to_column->values->f; + case CPL_TYPE_FLOAT: { + float *tfp = to_column->values->f; - switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + switch (from_type) { + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) *tfp++ -= (double)*fip++; break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) *tfp++ -= *flp++; break; } - case CPL_TYPE_LONG_LONG: - { - long long *fllp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *fllp = from_column->values->ll; while (to_length--) *tfp++ -= *fllp++; break; } - case CPL_TYPE_SIZE: - { - cpl_size *fszp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *fszp = from_column->values->sz; while (to_length--) *tfp++ -= *fszp++; break; } - case CPL_TYPE_FLOAT: - { + case CPL_TYPE_FLOAT: { float *ffp = from_column->values->f; while (to_length--) *tfp++ -= (double)*ffp++; break; } - case CPL_TYPE_DOUBLE: - { + case CPL_TYPE_DOUBLE: { double *fdp = from_column->values->d; while (to_length--) *tfp++ -= *fdp++; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { - float complex *fcfp = from_column->values->cf; + case CPL_TYPE_FLOAT_COMPLEX: { + float complex *fcfp = from_column->values->cf; while (to_length--) - tfp[to_length] = tfp[to_length] - fcfp[to_length]; /* Support clang */ + tfp[to_length] = + tfp[to_length] - + fcfp[to_length]; /* Support clang */ break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { - double complex *fcdp = from_column->values->cd; + case CPL_TYPE_DOUBLE_COMPLEX: { + double complex *fcdp = from_column->values->cd; while (to_length--) - tfp[to_length] = tfp[to_length] - fcdp[to_length]; /* Support clang */ + tfp[to_length] = + tfp[to_length] - + fcdp[to_length]; /* Support clang */ break; } default: @@ -14693,74 +14236,68 @@ } break; } - case CPL_TYPE_DOUBLE: - { - - double *tdp = to_column->values->d; + case CPL_TYPE_DOUBLE: { + double *tdp = to_column->values->d; switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) *tdp++ -= *fip++; break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) *tdp++ -= *flp++; break; } - case CPL_TYPE_LONG_LONG: - { - long long *fllp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *fllp = from_column->values->ll; while (to_length--) *tdp++ -= *fllp++; break; } - case CPL_TYPE_SIZE: - { - cpl_size *fszp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *fszp = from_column->values->sz; while (to_length--) *tdp++ -= *fszp++; break; } - case CPL_TYPE_FLOAT: - { + case CPL_TYPE_FLOAT: { float *ffp = from_column->values->f; while (to_length--) *tdp++ -= *ffp++; break; } - case CPL_TYPE_DOUBLE: - { + case CPL_TYPE_DOUBLE: { double *fdp = from_column->values->d; while (to_length--) *tdp++ -= *fdp++; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { - float complex *fcfp = from_column->values->cf; + case CPL_TYPE_FLOAT_COMPLEX: { + float complex *fcfp = from_column->values->cf; while (to_length--) - tdp[to_length] = tdp[to_length] - fcfp[to_length]; /* Support clang */ + tdp[to_length] = + tdp[to_length] - + fcfp[to_length]; /* Support clang */ break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { - double complex *fcdp = from_column->values->cd; + case CPL_TYPE_DOUBLE_COMPLEX: { + double complex *fcdp = from_column->values->cd; while (to_length--) - tdp[to_length] = tdp[to_length] - fcdp[to_length]; /* Support clang */ + tdp[to_length] = + tdp[to_length] - + fcdp[to_length]; /* Support clang */ break; } default: @@ -14768,71 +14305,61 @@ } break; } - case CPL_TYPE_FLOAT_COMPLEX: - { - + case CPL_TYPE_FLOAT_COMPLEX: { float complex *tcfp = to_column->values->cf; switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) *tcfp++ -= *fip++; break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) *tcfp++ -= *flp++; break; } - case CPL_TYPE_LONG_LONG: - { - long long *fllp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *fllp = from_column->values->ll; while (to_length--) *tcfp++ -= *fllp++; break; } - case CPL_TYPE_SIZE: - { - cpl_size *fszp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *fszp = from_column->values->sz; while (to_length--) *tcfp++ -= *fszp++; break; } - case CPL_TYPE_FLOAT: - { + case CPL_TYPE_FLOAT: { float *ffp = from_column->values->f; while (to_length--) *tcfp++ -= *ffp++; break; } - case CPL_TYPE_DOUBLE: - { + case CPL_TYPE_DOUBLE: { double *fdp = from_column->values->d; while (to_length--) *tcfp++ -= *fdp++; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { - float complex *fcfp = from_column->values->cf; + case CPL_TYPE_FLOAT_COMPLEX: { + float complex *fcfp = from_column->values->cf; while (to_length--) *tcfp++ -= *fcfp++; break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { - double complex *fcdp = from_column->values->cd; + case CPL_TYPE_DOUBLE_COMPLEX: { + double complex *fcdp = from_column->values->cd; while (to_length--) *tcfp++ -= *fcdp++; @@ -14843,71 +14370,61 @@ } break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { - + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *tcdp = to_column->values->cd; switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) *tcdp++ -= *fip++; break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) *tcdp++ -= *flp++; break; } - case CPL_TYPE_LONG_LONG: - { - long long *fllp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *fllp = from_column->values->ll; while (to_length--) *tcdp++ -= *fllp++; break; } - case CPL_TYPE_SIZE: - { - cpl_size *fszp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *fszp = from_column->values->sz; while (to_length--) *tcdp++ -= *fszp++; break; } - case CPL_TYPE_FLOAT: - { + case CPL_TYPE_FLOAT: { float *ffp = from_column->values->f; while (to_length--) *tcdp++ -= *ffp++; break; } - case CPL_TYPE_DOUBLE: - { + case CPL_TYPE_DOUBLE: { double *fdp = from_column->values->d; while (to_length--) *tcdp++ -= *fdp++; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { - float complex *fcfp = from_column->values->cf; + case CPL_TYPE_FLOAT_COMPLEX: { + float complex *fcfp = from_column->values->cf; while (to_length--) *tcdp++ -= *fcfp++; break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { - double complex *fcdp = from_column->values->cd; + case CPL_TYPE_DOUBLE_COMPLEX: { + double complex *fcdp = from_column->values->cd; while (to_length--) *tcdp++ -= *fcdp++; @@ -14923,7 +14440,6 @@ } } else { - /* * Here there are some invalid elements, so the operation needs to be * performed with some checks. As a first thing, take care of the @@ -14931,7 +14447,6 @@ */ if (to_column->nullcount == 0 || from_column->nullcount == 0) { - /* * Here there are some invalids in just one of the two columns. * If they are just in the column to add, an identical invalid @@ -14939,8 +14454,8 @@ */ if (from_column->nullcount) { - to_column->null = cpl_calloc(to_length, - sizeof(cpl_column_flag)); + to_column->null = + cpl_calloc(to_length, sizeof(cpl_column_flag)); i = to_length; while (i--) @@ -14948,11 +14463,9 @@ to_column->null[i] = 1; to_column->nullcount = from_column->nullcount; - } } else { - /* * Here there are some invalids in both columns. */ @@ -14968,7 +14481,6 @@ } if (to_column->nullcount == to_length) { - /* * Just invalids in the result: no need to perform any further * operation, and the invalid buffer of the target column can @@ -14980,7 +14492,6 @@ to_column->null = NULL; return 0; } - } /* @@ -14991,864 +14502,788 @@ tnp = to_column->null; switch (to_type) { - case CPL_TYPE_INT: - { - int *tip = to_column->values->i; + case CPL_TYPE_INT: { + int *tip = to_column->values->i; - switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + switch (from_type) { + case CPL_TYPE_INT: { + int *fip = from_column->values->i; - while (to_length--) { - if (*tnp++ == 0) - *tip -= *fip; - tip++; - fip++; + while (to_length--) { + if (*tnp++ == 0) + *tip -= *fip; + tip++; + fip++; + } + break; } - break; - } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; - while (to_length--) { - if (*tnp++ == 0) - *tip -= *flp; - tip++; - flp++; + while (to_length--) { + if (*tnp++ == 0) + *tip -= *flp; + tip++; + flp++; + } + break; } - break; - } - case CPL_TYPE_LONG_LONG: - { - long long *fllp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *fllp = from_column->values->ll; - while (to_length--) { - if (*tnp++ == 0) - *tip -= *fllp; - tip++; - fllp++; + while (to_length--) { + if (*tnp++ == 0) + *tip -= *fllp; + tip++; + fllp++; + } + break; } - break; - } - case CPL_TYPE_SIZE: - { - cpl_size *fszp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *fszp = from_column->values->sz; - while (to_length--) { - if (*tnp++ == 0) - *tip -= *fszp; - tip++; - fszp++; + while (to_length--) { + if (*tnp++ == 0) + *tip -= *fszp; + tip++; + fszp++; + } + break; } - break; - } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; - while (to_length--) { - if (*tnp++ == 0) - *tip -= *ffp; - tip++; - ffp++; + while (to_length--) { + if (*tnp++ == 0) + *tip -= *ffp; + tip++; + ffp++; + } + break; } - break; - } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; - while (to_length--) { - if (*tnp++ == 0) - *tip -= *fdp; - tip++; - fdp++; + while (to_length--) { + if (*tnp++ == 0) + *tip -= *fdp; + tip++; + fdp++; + } + break; } - break; - } - case CPL_TYPE_FLOAT_COMPLEX: - { - float complex *fcfp = from_column->values->cf; + case CPL_TYPE_FLOAT_COMPLEX: { + float complex *fcfp = from_column->values->cf; - while (to_length--) { - if (*tnp++ == 0) - *tip = *tip - *fcfp; /* Support clang */ - tip++; - fcfp++; + while (to_length--) { + if (*tnp++ == 0) + *tip = *tip - *fcfp; /* Support clang */ + tip++; + fcfp++; + } + break; } - break; - } - case CPL_TYPE_DOUBLE_COMPLEX: - { - double complex *fcdp = from_column->values->cd; + case CPL_TYPE_DOUBLE_COMPLEX: { + double complex *fcdp = from_column->values->cd; - while (to_length--) { - if (*tnp++ == 0) - *tip = *tip - *fcdp; /* Support clang */ - tip++; - fcdp++; + while (to_length--) { + if (*tnp++ == 0) + *tip = *tip - *fcdp; /* Support clang */ + tip++; + fcdp++; + } + break; } - break; + default: + break; } - default: - break; + break; } - break; - } - case CPL_TYPE_LONG: - { - long *tlp = to_column->values->l; + case CPL_TYPE_LONG: { + long *tlp = to_column->values->l; - switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + switch (from_type) { + case CPL_TYPE_INT: { + int *fip = from_column->values->i; - while (to_length--) { - if (*tnp++ == 0) - *tlp -= *fip; - tlp++; - fip++; + while (to_length--) { + if (*tnp++ == 0) + *tlp -= *fip; + tlp++; + fip++; + } + break; } - break; - } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; - while (to_length--) { - if (*tnp++ == 0) - *tlp -= *flp; - tlp++; - flp++; + while (to_length--) { + if (*tnp++ == 0) + *tlp -= *flp; + tlp++; + flp++; + } + break; } - break; - } - case CPL_TYPE_LONG_LONG: - { - long long *fllp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *fllp = from_column->values->ll; - while (to_length--) { - if (*tnp++ == 0) - *tlp -= *fllp; - tlp++; - fllp++; + while (to_length--) { + if (*tnp++ == 0) + *tlp -= *fllp; + tlp++; + fllp++; + } + break; } - break; - } - case CPL_TYPE_SIZE: - { - cpl_size *fszp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *fszp = from_column->values->sz; - while (to_length--) { - if (*tnp++ == 0) - *tlp -= *fszp; - tlp++; - fszp++; + while (to_length--) { + if (*tnp++ == 0) + *tlp -= *fszp; + tlp++; + fszp++; + } + break; } - break; - } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; - while (to_length--) { - if (*tnp++ == 0) - *tlp -= *ffp; - tlp++; - ffp++; + while (to_length--) { + if (*tnp++ == 0) + *tlp -= *ffp; + tlp++; + ffp++; + } + break; } - break; - } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; - while (to_length--) { - if (*tnp++ == 0) - *tlp -= *fdp; - tlp++; - fdp++; + while (to_length--) { + if (*tnp++ == 0) + *tlp -= *fdp; + tlp++; + fdp++; + } + break; } - break; - } - case CPL_TYPE_FLOAT_COMPLEX: - { - float complex *fcfp = from_column->values->cf; + case CPL_TYPE_FLOAT_COMPLEX: { + float complex *fcfp = from_column->values->cf; - while (to_length--) { - if (*tnp++ == 0) - *tlp = *tlp - *fcfp; /* Support clang */ - tlp++; - fcfp++; + while (to_length--) { + if (*tnp++ == 0) + *tlp = *tlp - *fcfp; /* Support clang */ + tlp++; + fcfp++; + } + break; } - break; - } - case CPL_TYPE_DOUBLE_COMPLEX: - { - double complex *fcdp = from_column->values->cd; + case CPL_TYPE_DOUBLE_COMPLEX: { + double complex *fcdp = from_column->values->cd; - while (to_length--) { - if (*tnp++ == 0) - *tlp = *tlp - *fcdp; /* Support clang */ - tlp++; - fcdp++; + while (to_length--) { + if (*tnp++ == 0) + *tlp = *tlp - *fcdp; /* Support clang */ + tlp++; + fcdp++; + } + break; } - break; + default: + break; } - default: - break; + break; } - break; - } - case CPL_TYPE_LONG_LONG: - { - long long *tlp = to_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *tlp = to_column->values->ll; - switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + switch (from_type) { + case CPL_TYPE_INT: { + int *fip = from_column->values->i; - while (to_length--) { - if (*tnp++ == 0) - *tlp -= *fip; - tlp++; - fip++; + while (to_length--) { + if (*tnp++ == 0) + *tlp -= *fip; + tlp++; + fip++; + } + break; } - break; - } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; - while (to_length--) { - if (*tnp++ == 0) - *tlp -= *flp; - tlp++; - flp++; + while (to_length--) { + if (*tnp++ == 0) + *tlp -= *flp; + tlp++; + flp++; + } + break; } - break; - } - case CPL_TYPE_LONG_LONG: - { - long long *fllp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *fllp = from_column->values->ll; - while (to_length--) { - if (*tnp++ == 0) - *tlp -= *fllp; - tlp++; - fllp++; + while (to_length--) { + if (*tnp++ == 0) + *tlp -= *fllp; + tlp++; + fllp++; + } + break; } - break; - } - case CPL_TYPE_SIZE: - { - cpl_size *fszp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *fszp = from_column->values->sz; - while (to_length--) { - if (*tnp++ == 0) - *tlp -= *fszp; - tlp++; - fszp++; + while (to_length--) { + if (*tnp++ == 0) + *tlp -= *fszp; + tlp++; + fszp++; + } + break; } - break; - } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; - while (to_length--) { - if (*tnp++ == 0) - *tlp -= *ffp; - tlp++; - ffp++; + while (to_length--) { + if (*tnp++ == 0) + *tlp -= *ffp; + tlp++; + ffp++; + } + break; } - break; - } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; - while (to_length--) { - if (*tnp++ == 0) - *tlp -= *fdp; - tlp++; - fdp++; + while (to_length--) { + if (*tnp++ == 0) + *tlp -= *fdp; + tlp++; + fdp++; + } + break; } - break; - } - case CPL_TYPE_FLOAT_COMPLEX: - { - float complex *fcfp = from_column->values->cf; + case CPL_TYPE_FLOAT_COMPLEX: { + float complex *fcfp = from_column->values->cf; - while (to_length--) { - if (*tnp++ == 0) - *tlp = *tlp - *fcfp; /* Support clang */ - tlp++; - fcfp++; + while (to_length--) { + if (*tnp++ == 0) + *tlp = *tlp - *fcfp; /* Support clang */ + tlp++; + fcfp++; + } + break; } - break; - } - case CPL_TYPE_DOUBLE_COMPLEX: - { - double complex *fcdp = from_column->values->cd; + case CPL_TYPE_DOUBLE_COMPLEX: { + double complex *fcdp = from_column->values->cd; - while (to_length--) { - if (*tnp++ == 0) - *tlp = *tlp - *fcdp; /* Support clang */ - tlp++; - fcdp++; + while (to_length--) { + if (*tnp++ == 0) + *tlp = *tlp - *fcdp; /* Support clang */ + tlp++; + fcdp++; + } + break; } - break; + default: + break; } - default: - break; + break; } - break; - } - case CPL_TYPE_SIZE: - { - cpl_size *tlp = to_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *tlp = to_column->values->sz; - switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + switch (from_type) { + case CPL_TYPE_INT: { + int *fip = from_column->values->i; - while (to_length--) { - if (*tnp++ == 0) - *tlp -= *fip; - tlp++; - fip++; + while (to_length--) { + if (*tnp++ == 0) + *tlp -= *fip; + tlp++; + fip++; + } + break; } - break; - } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; - while (to_length--) { - if (*tnp++ == 0) - *tlp -= *flp; - tlp++; - flp++; + while (to_length--) { + if (*tnp++ == 0) + *tlp -= *flp; + tlp++; + flp++; + } + break; } - break; - } - case CPL_TYPE_LONG_LONG: - { - long long *fllp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *fllp = from_column->values->ll; - while (to_length--) { - if (*tnp++ == 0) - *tlp -= *fllp; - tlp++; - fllp++; + while (to_length--) { + if (*tnp++ == 0) + *tlp -= *fllp; + tlp++; + fllp++; + } + break; } - break; - } - case CPL_TYPE_SIZE: - { - cpl_size *fszp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *fszp = from_column->values->sz; - while (to_length--) { - if (*tnp++ == 0) - *tlp -= *fszp; - tlp++; - fszp++; + while (to_length--) { + if (*tnp++ == 0) + *tlp -= *fszp; + tlp++; + fszp++; + } + break; } - break; - } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; - while (to_length--) { - if (*tnp++ == 0) - *tlp -= *ffp; - tlp++; - ffp++; + while (to_length--) { + if (*tnp++ == 0) + *tlp -= *ffp; + tlp++; + ffp++; + } + break; } - break; - } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; - while (to_length--) { - if (*tnp++ == 0) - *tlp -= *fdp; - tlp++; - fdp++; + while (to_length--) { + if (*tnp++ == 0) + *tlp -= *fdp; + tlp++; + fdp++; + } + break; } - break; - } - case CPL_TYPE_FLOAT_COMPLEX: - { - float complex *fcfp = from_column->values->cf; + case CPL_TYPE_FLOAT_COMPLEX: { + float complex *fcfp = from_column->values->cf; - while (to_length--) { - if (*tnp++ == 0) - *tlp = *tlp - *fcfp; /* Support clang */ - tlp++; - fcfp++; + while (to_length--) { + if (*tnp++ == 0) + *tlp = *tlp - *fcfp; /* Support clang */ + tlp++; + fcfp++; + } + break; } - break; - } - case CPL_TYPE_DOUBLE_COMPLEX: - { - double complex *fcdp = from_column->values->cd; + case CPL_TYPE_DOUBLE_COMPLEX: { + double complex *fcdp = from_column->values->cd; - while (to_length--) { - if (*tnp++ == 0) - *tlp = *tlp - *fcdp; /* Support clang */ - tlp++; - fcdp++; + while (to_length--) { + if (*tnp++ == 0) + *tlp = *tlp - *fcdp; /* Support clang */ + tlp++; + fcdp++; + } + break; } - break; + default: + break; } - default: - break; + break; } - break; - } - case CPL_TYPE_FLOAT: - { - float *tfp = to_column->values->f; + case CPL_TYPE_FLOAT: { + float *tfp = to_column->values->f; - switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + switch (from_type) { + case CPL_TYPE_INT: { + int *fip = from_column->values->i; - while (to_length--) { - if (*tnp++ == 0) - *tfp -= (double)*fip; - tfp++; - fip++; + while (to_length--) { + if (*tnp++ == 0) + *tfp -= (double)*fip; + tfp++; + fip++; + } + break; } - break; - } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; - while (to_length--) { - if (*tnp++ == 0) - *tfp -= *flp; - tfp++; - flp++; + while (to_length--) { + if (*tnp++ == 0) + *tfp -= *flp; + tfp++; + flp++; + } + break; } - break; - } - case CPL_TYPE_LONG_LONG: - { - long long *fllp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *fllp = from_column->values->ll; - while (to_length--) { - if (*tnp++ == 0) - *tfp -= *fllp; - tfp++; - fllp++; + while (to_length--) { + if (*tnp++ == 0) + *tfp -= *fllp; + tfp++; + fllp++; + } + break; } - break; - } - case CPL_TYPE_SIZE: - { - cpl_size *fszp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *fszp = from_column->values->sz; - while (to_length--) { - if (*tnp++ == 0) - *tfp -= *fszp; - tfp++; - fszp++; + while (to_length--) { + if (*tnp++ == 0) + *tfp -= *fszp; + tfp++; + fszp++; + } + break; } - break; - } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; - while (to_length--) { - if (*tnp++ == 0) - *tfp -= (double)*ffp; - tfp++; - ffp++; + while (to_length--) { + if (*tnp++ == 0) + *tfp -= (double)*ffp; + tfp++; + ffp++; + } + break; } - break; - } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; - while (to_length--) { - if (*tnp++ == 0) - *tfp -= *fdp; - tfp++; - fdp++; + while (to_length--) { + if (*tnp++ == 0) + *tfp -= *fdp; + tfp++; + fdp++; + } + break; } - break; - } - case CPL_TYPE_FLOAT_COMPLEX: - { - float complex *fcfp = from_column->values->cf; + case CPL_TYPE_FLOAT_COMPLEX: { + float complex *fcfp = from_column->values->cf; - while (to_length--) { - if (*tnp++ == 0) - *tfp = *tfp - *fcfp; /* Support clang */ - tfp++; - fcfp++; + while (to_length--) { + if (*tnp++ == 0) + *tfp = *tfp - *fcfp; /* Support clang */ + tfp++; + fcfp++; + } + break; } - break; - } - case CPL_TYPE_DOUBLE_COMPLEX: - { - double complex *fcdp = from_column->values->cd; + case CPL_TYPE_DOUBLE_COMPLEX: { + double complex *fcdp = from_column->values->cd; - while (to_length--) { - if (*tnp++ == 0) - *tfp = *tfp - *fcdp; /* Support clang */ - tfp++; - fcdp++; + while (to_length--) { + if (*tnp++ == 0) + *tfp = *tfp - *fcdp; /* Support clang */ + tfp++; + fcdp++; + } + break; } - break; + default: + break; } - default: - break; + break; } - break; - } - case CPL_TYPE_DOUBLE: - { + case CPL_TYPE_DOUBLE: { + double *tdp = to_column->values->d; - double *tdp = to_column->values->d; - - switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + switch (from_type) { + case CPL_TYPE_INT: { + int *fip = from_column->values->i; - while (to_length--) { - if (*tnp++ == 0) - *tdp -= *fip; - tdp++; - fip++; + while (to_length--) { + if (*tnp++ == 0) + *tdp -= *fip; + tdp++; + fip++; + } + break; } - break; - } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; - while (to_length--) { - if (*tnp++ == 0) - *tdp -= *flp; - tdp++; - flp++; + while (to_length--) { + if (*tnp++ == 0) + *tdp -= *flp; + tdp++; + flp++; + } + break; } - break; - } - case CPL_TYPE_LONG_LONG: - { - long long *fllp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *fllp = from_column->values->ll; - while (to_length--) { - if (*tnp++ == 0) - *tdp -= *fllp; - tdp++; - fllp++; + while (to_length--) { + if (*tnp++ == 0) + *tdp -= *fllp; + tdp++; + fllp++; + } + break; } - break; - } - case CPL_TYPE_SIZE: - { - cpl_size *fszp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *fszp = from_column->values->sz; - while (to_length--) { - if (*tnp++ == 0) - *tdp -= *fszp; - tdp++; - fszp++; + while (to_length--) { + if (*tnp++ == 0) + *tdp -= *fszp; + tdp++; + fszp++; + } + break; } - break; - } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; - while (to_length--) { - if (*tnp++ == 0) - *tdp -= *ffp; - tdp++; - ffp++; + while (to_length--) { + if (*tnp++ == 0) + *tdp -= *ffp; + tdp++; + ffp++; + } + break; } - break; - } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; - while (to_length--) { - if (*tnp++ == 0) - *tdp -= *fdp; - tdp++; - fdp++; + while (to_length--) { + if (*tnp++ == 0) + *tdp -= *fdp; + tdp++; + fdp++; + } + break; } - break; - } - case CPL_TYPE_FLOAT_COMPLEX: - { - float complex *fcfp = from_column->values->cf; + case CPL_TYPE_FLOAT_COMPLEX: { + float complex *fcfp = from_column->values->cf; - while (to_length--) { - if (*tnp++ == 0) - *tdp = *tdp - *fcfp; /* Support clang */ - tdp++; - fcfp++; + while (to_length--) { + if (*tnp++ == 0) + *tdp = *tdp - *fcfp; /* Support clang */ + tdp++; + fcfp++; + } + break; } - break; - } - case CPL_TYPE_DOUBLE_COMPLEX: - { - double complex *fcdp = from_column->values->cd; + case CPL_TYPE_DOUBLE_COMPLEX: { + double complex *fcdp = from_column->values->cd; - while (to_length--) { - if (*tnp++ == 0) - *tdp = *tdp - *fcdp; /* Support clang */ - tdp++; - fcdp++; + while (to_length--) { + if (*tnp++ == 0) + *tdp = *tdp - *fcdp; /* Support clang */ + tdp++; + fcdp++; + } + break; } - break; + default: + break; } - default: - break; + break; } - break; - } - case CPL_TYPE_FLOAT_COMPLEX: - { - - float complex *tcfp = to_column->values->cf; + case CPL_TYPE_FLOAT_COMPLEX: { + float complex *tcfp = to_column->values->cf; - switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + switch (from_type) { + case CPL_TYPE_INT: { + int *fip = from_column->values->i; - while (to_length--) { - if (*tnp++ == 0) - *tcfp -= *fip; - tcfp++; - fip++; + while (to_length--) { + if (*tnp++ == 0) + *tcfp -= *fip; + tcfp++; + fip++; + } + break; } - break; - } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; - while (to_length--) { - if (*tnp++ == 0) - *tcfp -= *flp; - tcfp++; - flp++; + while (to_length--) { + if (*tnp++ == 0) + *tcfp -= *flp; + tcfp++; + flp++; + } + break; } - break; - } - case CPL_TYPE_LONG_LONG: - { - long long *fllp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *fllp = from_column->values->ll; - while (to_length--) { - if (*tnp++ == 0) - *tcfp -= *fllp; - tcfp++; - fllp++; + while (to_length--) { + if (*tnp++ == 0) + *tcfp -= *fllp; + tcfp++; + fllp++; + } + break; } - break; - } - case CPL_TYPE_SIZE: - { - cpl_size *fszp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *fszp = from_column->values->sz; - while (to_length--) { - if (*tnp++ == 0) - *tcfp -= *fszp; - tcfp++; - fszp++; + while (to_length--) { + if (*tnp++ == 0) + *tcfp -= *fszp; + tcfp++; + fszp++; + } + break; } - break; - } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; - while (to_length--) { - if (*tnp++ == 0) - *tcfp -= *ffp; - tcfp++; - ffp++; + while (to_length--) { + if (*tnp++ == 0) + *tcfp -= *ffp; + tcfp++; + ffp++; + } + break; } - break; - } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; - while (to_length--) { - if (*tnp++ == 0) - *tcfp -= *fdp; - tcfp++; - fdp++; + while (to_length--) { + if (*tnp++ == 0) + *tcfp -= *fdp; + tcfp++; + fdp++; + } + break; } - break; - } - case CPL_TYPE_FLOAT_COMPLEX: - { - float complex *fcfp = from_column->values->cf; + case CPL_TYPE_FLOAT_COMPLEX: { + float complex *fcfp = from_column->values->cf; - while (to_length--) { - if (*tnp++ == 0) - *tcfp -= *fcfp; - tcfp++; - fcfp++; + while (to_length--) { + if (*tnp++ == 0) + *tcfp -= *fcfp; + tcfp++; + fcfp++; + } + break; } - break; - } - case CPL_TYPE_DOUBLE_COMPLEX: - { - double complex *fcdp = from_column->values->cd; + case CPL_TYPE_DOUBLE_COMPLEX: { + double complex *fcdp = from_column->values->cd; - while (to_length--) { - if (*tnp++ == 0) - *tcfp -= *fcdp; - tcfp++; - fcdp++; + while (to_length--) { + if (*tnp++ == 0) + *tcfp -= *fcdp; + tcfp++; + fcdp++; + } + break; } - break; + default: + break; } - default: - break; - } - break; - } - case CPL_TYPE_DOUBLE_COMPLEX: - { - - double complex *tcdp = to_column->values->cd; + break; + } + case CPL_TYPE_DOUBLE_COMPLEX: { + double complex *tcdp = to_column->values->cd; - switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + switch (from_type) { + case CPL_TYPE_INT: { + int *fip = from_column->values->i; - while (to_length--) { - if (*tnp++ == 0) - *tcdp -= *fip; - tcdp++; - fip++; + while (to_length--) { + if (*tnp++ == 0) + *tcdp -= *fip; + tcdp++; + fip++; + } + break; } - break; - } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; - while (to_length--) { - if (*tnp++ == 0) - *tcdp -= *flp; - tcdp++; - flp++; + while (to_length--) { + if (*tnp++ == 0) + *tcdp -= *flp; + tcdp++; + flp++; + } + break; } - break; - } - case CPL_TYPE_LONG_LONG: - { - long long *fllp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *fllp = from_column->values->ll; - while (to_length--) { - if (*tnp++ == 0) - *tcdp -= *fllp; - tcdp++; - fllp++; + while (to_length--) { + if (*tnp++ == 0) + *tcdp -= *fllp; + tcdp++; + fllp++; + } + break; } - break; - } - case CPL_TYPE_SIZE: - { - cpl_size *fszp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *fszp = from_column->values->sz; - while (to_length--) { - if (*tnp++ == 0) - *tcdp -= *fszp; - tcdp++; - fszp++; + while (to_length--) { + if (*tnp++ == 0) + *tcdp -= *fszp; + tcdp++; + fszp++; + } + break; } - break; - } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; - while (to_length--) { - if (*tnp++ == 0) - *tcdp -= *ffp; - tcdp++; - ffp++; + while (to_length--) { + if (*tnp++ == 0) + *tcdp -= *ffp; + tcdp++; + ffp++; + } + break; } - break; - } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; - while (to_length--) { - if (*tnp++ == 0) - *tcdp -= *fdp; - tcdp++; - fdp++; + while (to_length--) { + if (*tnp++ == 0) + *tcdp -= *fdp; + tcdp++; + fdp++; + } + break; } - break; - } - case CPL_TYPE_FLOAT_COMPLEX: - { - float complex *fcfp = from_column->values->cf; + case CPL_TYPE_FLOAT_COMPLEX: { + float complex *fcfp = from_column->values->cf; - while (to_length--) { - if (*tnp++ == 0) - *tcdp -= *fcfp; - tcdp++; - fcfp++; + while (to_length--) { + if (*tnp++ == 0) + *tcdp -= *fcfp; + tcdp++; + fcfp++; + } + break; } - break; - } - case CPL_TYPE_DOUBLE_COMPLEX: - { - double complex *fcdp = from_column->values->cd; + case CPL_TYPE_DOUBLE_COMPLEX: { + double complex *fcdp = from_column->values->cd; - while (to_length--) { - if (*tnp++ == 0) - *tcdp -= *fcdp; - tcdp++; - fcdp++; + while (to_length--) { + if (*tnp++ == 0) + *tcdp -= *fcdp; + tcdp++; + fcdp++; + } + break; } - break; + default: + break; } - default: - break; + break; } - break; - } - default: - break; + default: + break; } } return CPL_ERROR_NONE; - } @@ -15877,16 +15312,15 @@ * is not applicable to array columns. */ -cpl_error_code cpl_column_multiply(cpl_column *to_column, - cpl_column *from_column) +cpl_error_code +cpl_column_multiply(cpl_column *to_column, cpl_column *from_column) { - - cpl_size i; - cpl_size to_length = cpl_column_get_size(to_column); - cpl_size from_length = cpl_column_get_size(from_column); - cpl_type to_type = cpl_column_get_type(to_column); - cpl_type from_type = cpl_column_get_type(from_column); - int *tnp; + cpl_size i; + cpl_size to_length = cpl_column_get_size(to_column); + cpl_size from_length = cpl_column_get_size(from_column); + cpl_type to_type = cpl_column_get_type(to_column); + cpl_type from_type = cpl_column_get_type(from_column); + int *tnp; if (to_column == NULL || from_column == NULL) @@ -15910,80 +15344,74 @@ if (to_column->nullcount == 0 && from_column->nullcount == 0) { - /* * If there are no invalids in both columns, the operation can * be performed without any check: */ switch (to_type) { - case CPL_TYPE_INT: - { - int *tip = to_column->values->i; + case CPL_TYPE_INT: { + int *tip = to_column->values->i; switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) *tip++ *= *fip++; break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) *tip++ *= *flp++; break; } - case CPL_TYPE_LONG_LONG: - { - long long *flp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *flp = from_column->values->ll; while (to_length--) *tip++ *= *flp++; break; } - case CPL_TYPE_SIZE: - { - cpl_size *flp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *flp = from_column->values->sz; while (to_length--) *tip++ *= *flp++; break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; while (to_length--) *tip++ *= *ffp++; break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; while (to_length--) *tip++ *= *fdp++; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; while (to_length--) - tip[to_length] = tip[to_length] * fcfp[to_length]; /* Support clang */ + tip[to_length] = + tip[to_length] * + fcfp[to_length]; /* Support clang */ break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; while (to_length--) - tip[to_length] = tip[to_length] * fcdp[to_length]; /* Support clang */ + tip[to_length] = + tip[to_length] * + fcdp[to_length]; /* Support clang */ break; } default: @@ -15991,73 +15419,68 @@ } break; } - case CPL_TYPE_LONG: - { - long *tlp = to_column->values->l; + case CPL_TYPE_LONG: { + long *tlp = to_column->values->l; switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) *tlp++ *= *fip++; break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) *tlp++ *= *flp++; break; } - case CPL_TYPE_LONG_LONG: - { - long long *flp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *flp = from_column->values->ll; while (to_length--) *tlp++ *= *flp++; break; } - case CPL_TYPE_SIZE: - { - cpl_size *flp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *flp = from_column->values->sz; while (to_length--) *tlp++ *= *flp++; break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; while (to_length--) *tlp++ *= *ffp++; break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; while (to_length--) *tlp++ *= *fdp++; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; while (to_length--) - tlp[to_length] = tlp[to_length] * fcfp[to_length]; /* Support clang */ + tlp[to_length] = + tlp[to_length] * + fcfp[to_length]; /* Support clang */ break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; while (to_length--) - tlp[to_length] = tlp[to_length] * fcdp[to_length]; /* Support clang */ + tlp[to_length] = + tlp[to_length] * + fcdp[to_length]; /* Support clang */ break; } default: @@ -16065,73 +15488,68 @@ } break; } - case CPL_TYPE_LONG_LONG: - { - long long *tlp = to_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *tlp = to_column->values->ll; switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) *tlp++ *= *fip++; break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) *tlp++ *= *flp++; break; } - case CPL_TYPE_LONG_LONG: - { - long long *flp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *flp = from_column->values->ll; while (to_length--) *tlp++ *= *flp++; break; } - case CPL_TYPE_SIZE: - { - cpl_size *flp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *flp = from_column->values->sz; while (to_length--) *tlp++ *= *flp++; break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; while (to_length--) *tlp++ *= *ffp++; break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; while (to_length--) *tlp++ *= *fdp++; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; while (to_length--) - tlp[to_length] = tlp[to_length] * fcfp[to_length]; /* Support clang */ + tlp[to_length] = + tlp[to_length] * + fcfp[to_length]; /* Support clang */ break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; while (to_length--) - tlp[to_length] = tlp[to_length] * fcdp[to_length]; /* Support clang */ + tlp[to_length] = + tlp[to_length] * + fcdp[to_length]; /* Support clang */ break; } default: @@ -16139,73 +15557,68 @@ } break; } - case CPL_TYPE_SIZE: - { - cpl_size *tlp = to_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *tlp = to_column->values->sz; switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) *tlp++ *= *fip++; break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) *tlp++ *= *flp++; break; } - case CPL_TYPE_LONG_LONG: - { - long long *flp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *flp = from_column->values->ll; while (to_length--) *tlp++ *= *flp++; break; } - case CPL_TYPE_SIZE: - { - cpl_size *flp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *flp = from_column->values->sz; while (to_length--) *tlp++ *= *flp++; break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; while (to_length--) *tlp++ *= *ffp++; break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; while (to_length--) *tlp++ *= *fdp++; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; while (to_length--) - tlp[to_length] = tlp[to_length] * fcfp[to_length]; /* Support clang */ + tlp[to_length] = + tlp[to_length] * + fcfp[to_length]; /* Support clang */ break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; while (to_length--) - tlp[to_length] = tlp[to_length] * fcdp[to_length]; /* Support clang */ + tlp[to_length] = + tlp[to_length] * + fcdp[to_length]; /* Support clang */ break; } default: @@ -16213,73 +15626,68 @@ } break; } - case CPL_TYPE_FLOAT: - { - float *tfp = to_column->values->f; + case CPL_TYPE_FLOAT: { + float *tfp = to_column->values->f; switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) *tfp++ *= (double)*fip++; break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) *tfp++ *= *flp++; break; } - case CPL_TYPE_LONG_LONG: - { - long long *flp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *flp = from_column->values->ll; while (to_length--) *tfp++ *= *flp++; break; } - case CPL_TYPE_SIZE: - { - cpl_size *flp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *flp = from_column->values->sz; while (to_length--) *tfp++ *= *flp++; break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; while (to_length--) *tfp++ *= (double)*ffp++; break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; while (to_length--) *tfp++ *= *fdp++; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; while (to_length--) - tfp[to_length] = tfp[to_length] * fcfp[to_length]; /* Support clang */ + tfp[to_length] = + tfp[to_length] * + fcfp[to_length]; /* Support clang */ break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; while (to_length--) - tfp[to_length] = tfp[to_length] * fcdp[to_length]; /* Support clang */ + tfp[to_length] = + tfp[to_length] * + fcdp[to_length]; /* Support clang */ break; } default: @@ -16287,73 +15695,68 @@ } break; } - case CPL_TYPE_DOUBLE: - { - double *tdp = to_column->values->d; + case CPL_TYPE_DOUBLE: { + double *tdp = to_column->values->d; switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) *tdp++ *= *fip++; break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) *tdp++ *= *flp++; break; } - case CPL_TYPE_LONG_LONG: - { - long long *flp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *flp = from_column->values->ll; while (to_length--) *tdp++ *= *flp++; break; } - case CPL_TYPE_SIZE: - { - cpl_size *flp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *flp = from_column->values->sz; while (to_length--) *tdp++ *= *flp++; break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; while (to_length--) *tdp++ *= *ffp++; break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; while (to_length--) *tdp++ *= *fdp++; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; while (to_length--) - tdp[to_length] = tdp[to_length] * fcfp[to_length]; /* Support clang */ + tdp[to_length] = + tdp[to_length] * + fcfp[to_length]; /* Support clang */ break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; while (to_length--) - tdp[to_length] = tdp[to_length] * fcdp[to_length]; /* Support clang */ + tdp[to_length] = + tdp[to_length] * + fcdp[to_length]; /* Support clang */ break; } default: @@ -16361,69 +15764,60 @@ } break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *tcfp = to_column->values->cf; switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) *tcfp++ *= *fip++; break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) *tcfp++ *= *flp++; break; } - case CPL_TYPE_LONG_LONG: - { - long long *flp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *flp = from_column->values->ll; while (to_length--) *tcfp++ *= *flp++; break; } - case CPL_TYPE_SIZE: - { - cpl_size *flp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *flp = from_column->values->sz; while (to_length--) *tcfp++ *= *flp++; break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; while (to_length--) *tcfp++ *= *ffp++; break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; while (to_length--) *tcfp++ *= *fdp++; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; while (to_length--) *tcfp++ *= *fcfp++; break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; while (to_length--) @@ -16435,69 +15829,60 @@ } break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *tcdp = to_column->values->cd; switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) *tcdp++ *= *fip++; break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) *tcdp++ *= *flp++; break; } - case CPL_TYPE_LONG_LONG: - { - long long *flp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *flp = from_column->values->ll; while (to_length--) *tcdp++ *= *flp++; break; } - case CPL_TYPE_SIZE: - { - cpl_size *flp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *flp = from_column->values->sz; while (to_length--) *tcdp++ *= *flp++; break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; while (to_length--) *tcdp++ *= *ffp++; break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; while (to_length--) *tcdp++ *= *fdp++; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; while (to_length--) *tcdp++ *= *fcfp++; break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; while (to_length--) @@ -16514,7 +15899,6 @@ } } else { - /* * Here there are some invalids around, so the operation needs to be * performed with some checks. As a first thing, take care of the @@ -16522,7 +15906,6 @@ */ if (to_column->nullcount == 0 || from_column->nullcount == 0) { - /* * Here there are some invalids in just one of the two columns. * If they are just in the column to add, an identical invalid @@ -16530,8 +15913,8 @@ */ if (from_column->nullcount) { - to_column->null = cpl_calloc(to_length, - sizeof(cpl_column_flag)); + to_column->null = + cpl_calloc(to_length, sizeof(cpl_column_flag)); i = to_length; while (i--) @@ -16539,11 +15922,9 @@ to_column->null[i] = 1; to_column->nullcount = from_column->nullcount; - } } else { - /* * Here there are some invalids in both columns. */ @@ -16559,7 +15940,6 @@ } if (to_column->nullcount == to_length) { - /* * Just invalids in the result: no need to perform any further * operation, and the invalid buffer of the target column can @@ -16571,7 +15951,6 @@ to_column->null = NULL; return 0; } - } /* @@ -16582,14 +15961,12 @@ tnp = to_column->null; switch (to_type) { - case CPL_TYPE_INT: - { - int *tip = to_column->values->i; + case CPL_TYPE_INT: { + int *tip = to_column->values->i; switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) { if (*tnp++ == 0) @@ -16599,9 +15976,8 @@ } break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) { if (*tnp++ == 0) @@ -16611,9 +15987,8 @@ } break; } - case CPL_TYPE_LONG_LONG: - { - long long *flp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *flp = from_column->values->ll; while (to_length--) { if (*tnp++ == 0) @@ -16623,9 +15998,8 @@ } break; } - case CPL_TYPE_SIZE: - { - cpl_size *flp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *flp = from_column->values->sz; while (to_length--) { if (*tnp++ == 0) @@ -16635,9 +16009,8 @@ } break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; while (to_length--) { if (*tnp++ == 0) @@ -16647,9 +16020,8 @@ } break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; while (to_length--) { if (*tnp++ == 0) @@ -16659,8 +16031,7 @@ } break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; while (to_length--) { @@ -16671,8 +16042,7 @@ } break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; while (to_length--) { @@ -16688,14 +16058,12 @@ } break; } - case CPL_TYPE_LONG: - { - long *tlp = to_column->values->l; + case CPL_TYPE_LONG: { + long *tlp = to_column->values->l; switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) { if (*tnp++ == 0) @@ -16705,9 +16073,8 @@ } break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) { if (*tnp++ == 0) @@ -16717,9 +16084,8 @@ } break; } - case CPL_TYPE_LONG_LONG: - { - long long *flp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *flp = from_column->values->ll; while (to_length--) { if (*tnp++ == 0) @@ -16729,9 +16095,8 @@ } break; } - case CPL_TYPE_SIZE: - { - cpl_size *flp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *flp = from_column->values->sz; while (to_length--) { if (*tnp++ == 0) @@ -16741,9 +16106,8 @@ } break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; while (to_length--) { if (*tnp++ == 0) @@ -16753,9 +16117,8 @@ } break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; while (to_length--) { if (*tnp++ == 0) @@ -16765,8 +16128,7 @@ } break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; while (to_length--) { @@ -16777,8 +16139,7 @@ } break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; while (to_length--) { @@ -16794,14 +16155,12 @@ } break; } - case CPL_TYPE_LONG_LONG: - { - long long *tlp = to_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *tlp = to_column->values->ll; switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) { if (*tnp++ == 0) @@ -16811,9 +16170,8 @@ } break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) { if (*tnp++ == 0) @@ -16823,9 +16181,8 @@ } break; } - case CPL_TYPE_LONG_LONG: - { - long long *flp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *flp = from_column->values->ll; while (to_length--) { if (*tnp++ == 0) @@ -16835,9 +16192,8 @@ } break; } - case CPL_TYPE_SIZE: - { - cpl_size *flp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *flp = from_column->values->sz; while (to_length--) { if (*tnp++ == 0) @@ -16847,9 +16203,8 @@ } break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; while (to_length--) { if (*tnp++ == 0) @@ -16859,9 +16214,8 @@ } break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; while (to_length--) { if (*tnp++ == 0) @@ -16871,8 +16225,7 @@ } break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; while (to_length--) { @@ -16883,8 +16236,7 @@ } break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; while (to_length--) { @@ -16900,14 +16252,12 @@ } break; } - case CPL_TYPE_SIZE: - { - cpl_size *tlp = to_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *tlp = to_column->values->sz; switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) { if (*tnp++ == 0) @@ -16917,9 +16267,8 @@ } break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) { if (*tnp++ == 0) @@ -16929,9 +16278,8 @@ } break; } - case CPL_TYPE_LONG_LONG: - { - long long *flp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *flp = from_column->values->ll; while (to_length--) { if (*tnp++ == 0) @@ -16941,9 +16289,8 @@ } break; } - case CPL_TYPE_SIZE: - { - cpl_size *flp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *flp = from_column->values->sz; while (to_length--) { if (*tnp++ == 0) @@ -16953,9 +16300,8 @@ } break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; while (to_length--) { if (*tnp++ == 0) @@ -16965,9 +16311,8 @@ } break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; while (to_length--) { if (*tnp++ == 0) @@ -16977,8 +16322,7 @@ } break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; while (to_length--) { @@ -16989,8 +16333,7 @@ } break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; while (to_length--) { @@ -17006,14 +16349,12 @@ } break; } - case CPL_TYPE_FLOAT: - { - float *tfp = to_column->values->f; + case CPL_TYPE_FLOAT: { + float *tfp = to_column->values->f; switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) { if (*tnp++ == 0) @@ -17023,9 +16364,8 @@ } break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) { if (*tnp++ == 0) @@ -17035,9 +16375,8 @@ } break; } - case CPL_TYPE_LONG_LONG: - { - long long *flp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *flp = from_column->values->ll; while (to_length--) { if (*tnp++ == 0) @@ -17047,9 +16386,8 @@ } break; } - case CPL_TYPE_SIZE: - { - cpl_size *flp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *flp = from_column->values->sz; while (to_length--) { if (*tnp++ == 0) @@ -17059,9 +16397,8 @@ } break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; while (to_length--) { if (*tnp++ == 0) @@ -17071,9 +16408,8 @@ } break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; while (to_length--) { if (*tnp++ == 0) @@ -17083,8 +16419,7 @@ } break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; while (to_length--) { @@ -17095,8 +16430,7 @@ } break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; while (to_length--) { @@ -17112,14 +16446,12 @@ } break; } - case CPL_TYPE_DOUBLE: - { - double *tdp = to_column->values->d; + case CPL_TYPE_DOUBLE: { + double *tdp = to_column->values->d; switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) { if (*tnp++ == 0) @@ -17129,9 +16461,8 @@ } break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) { if (*tnp++ == 0) @@ -17141,9 +16472,8 @@ } break; } - case CPL_TYPE_LONG_LONG: - { - long long *flp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *flp = from_column->values->ll; while (to_length--) { if (*tnp++ == 0) @@ -17153,9 +16483,8 @@ } break; } - case CPL_TYPE_SIZE: - { - cpl_size *flp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *flp = from_column->values->sz; while (to_length--) { if (*tnp++ == 0) @@ -17165,9 +16494,8 @@ } break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; while (to_length--) { if (*tnp++ == 0) @@ -17177,9 +16505,8 @@ } break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; while (to_length--) { if (*tnp++ == 0) @@ -17189,8 +16516,7 @@ } break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; while (to_length--) { @@ -17201,8 +16527,7 @@ } break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; while (to_length--) { @@ -17218,14 +16543,12 @@ } break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *tcfp = to_column->values->cf; switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) { if (*tnp++ == 0) @@ -17235,9 +16558,8 @@ } break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) { if (*tnp++ == 0) @@ -17247,9 +16569,8 @@ } break; } - case CPL_TYPE_LONG_LONG: - { - long long *flp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *flp = from_column->values->ll; while (to_length--) { if (*tnp++ == 0) @@ -17259,9 +16580,8 @@ } break; } - case CPL_TYPE_SIZE: - { - cpl_size *flp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *flp = from_column->values->sz; while (to_length--) { if (*tnp++ == 0) @@ -17271,9 +16591,8 @@ } break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; while (to_length--) { if (*tnp++ == 0) @@ -17283,9 +16602,8 @@ } break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; while (to_length--) { if (*tnp++ == 0) @@ -17295,8 +16613,7 @@ } break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; while (to_length--) { @@ -17307,8 +16624,7 @@ } break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; while (to_length--) { @@ -17324,14 +16640,12 @@ } break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *tcdp = to_column->values->cd; switch (from_type) { - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) { if (*tnp++ == 0) @@ -17341,9 +16655,8 @@ } break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) { if (*tnp++ == 0) @@ -17353,9 +16666,8 @@ } break; } - case CPL_TYPE_LONG_LONG: - { - long long *flp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *flp = from_column->values->ll; while (to_length--) { if (*tnp++ == 0) @@ -17365,9 +16677,8 @@ } break; } - case CPL_TYPE_SIZE: - { - long long *flp = from_column->values->sz; + case CPL_TYPE_SIZE: { + long long *flp = from_column->values->sz; while (to_length--) { if (*tnp++ == 0) @@ -17377,9 +16688,8 @@ } break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; while (to_length--) { if (*tnp++ == 0) @@ -17389,9 +16699,8 @@ } break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; while (to_length--) { if (*tnp++ == 0) @@ -17401,8 +16710,7 @@ } break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; while (to_length--) { @@ -17413,8 +16721,7 @@ } break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; while (to_length--) { @@ -17436,7 +16743,6 @@ } return CPL_ERROR_NONE; - } @@ -17466,16 +16772,15 @@ * is not applicable to array columns. */ -cpl_error_code cpl_column_divide(cpl_column *to_column, - cpl_column *from_column) +cpl_error_code +cpl_column_divide(cpl_column *to_column, cpl_column *from_column) { - - cpl_size i; - cpl_size to_length = cpl_column_get_size(to_column); - cpl_size from_length = cpl_column_get_size(from_column); - cpl_type to_type = cpl_column_get_type(to_column); - cpl_type from_type = cpl_column_get_type(from_column); - int *tnp; + cpl_size i; + cpl_size to_length = cpl_column_get_size(to_column); + cpl_size from_length = cpl_column_get_size(from_column); + cpl_type to_type = cpl_column_get_type(to_column); + cpl_type from_type = cpl_column_get_type(from_column); + int *tnp; if (to_column == NULL || from_column == NULL) @@ -17501,11 +16806,8 @@ */ if (from_column->nullcount == 0) { - switch (from_type) { - - case CPL_TYPE_INT: - { + case CPL_TYPE_INT: { int *fip = from_column->values->i; for (i = 0; i < to_length; i++) @@ -17513,8 +16815,7 @@ cpl_column_set_invalid(to_column, i); break; } - case CPL_TYPE_LONG: - { + case CPL_TYPE_LONG: { long *flp = from_column->values->l; for (i = 0; i < to_length; i++) @@ -17522,8 +16823,7 @@ cpl_column_set_invalid(to_column, i); break; } - case CPL_TYPE_LONG_LONG: - { + case CPL_TYPE_LONG_LONG: { long long *flp = from_column->values->ll; for (i = 0; i < to_length; i++) @@ -17531,8 +16831,7 @@ cpl_column_set_invalid(to_column, i); break; } - case CPL_TYPE_SIZE: - { + case CPL_TYPE_SIZE: { cpl_size *flp = from_column->values->sz; for (i = 0; i < to_length; i++) @@ -17540,8 +16839,7 @@ cpl_column_set_invalid(to_column, i); break; } - case CPL_TYPE_FLOAT: - { + case CPL_TYPE_FLOAT: { float *ffp = from_column->values->f; for (i = 0; i < to_length; i++) @@ -17549,8 +16847,7 @@ cpl_column_set_invalid(to_column, i); break; } - case CPL_TYPE_DOUBLE: - { + case CPL_TYPE_DOUBLE: { double *fdp = from_column->values->d; for (i = 0; i < to_length; i++) @@ -17558,8 +16855,7 @@ cpl_column_set_invalid(to_column, i); break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; for (i = 0; i < to_length; i++) @@ -17567,8 +16863,7 @@ cpl_column_set_invalid(to_column, i); break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; for (i = 0; i < to_length; i++) @@ -17578,17 +16873,13 @@ } default: break; - } } else { - cpl_column_flag *fnp = from_column->null; switch (from_type) { - - case CPL_TYPE_INT: - { + case CPL_TYPE_INT: { int *fip = from_column->values->i; for (i = 0; i < to_length; i++, fip++) @@ -17597,8 +16888,7 @@ cpl_column_set_invalid(to_column, i); break; } - case CPL_TYPE_LONG: - { + case CPL_TYPE_LONG: { long *flp = from_column->values->l; for (i = 0; i < to_length; i++, flp++) @@ -17607,8 +16897,7 @@ cpl_column_set_invalid(to_column, i); break; } - case CPL_TYPE_LONG_LONG: - { + case CPL_TYPE_LONG_LONG: { long long *flp = from_column->values->ll; for (i = 0; i < to_length; i++, flp++) @@ -17617,8 +16906,7 @@ cpl_column_set_invalid(to_column, i); break; } - case CPL_TYPE_SIZE: - { + case CPL_TYPE_SIZE: { cpl_size *flp = from_column->values->sz; for (i = 0; i < to_length; i++, flp++) @@ -17627,8 +16915,7 @@ cpl_column_set_invalid(to_column, i); break; } - case CPL_TYPE_FLOAT: - { + case CPL_TYPE_FLOAT: { float *ffp = from_column->values->f; for (i = 0; i < to_length; i++, ffp++) @@ -17637,8 +16924,7 @@ cpl_column_set_invalid(to_column, i); break; } - case CPL_TYPE_DOUBLE: - { + case CPL_TYPE_DOUBLE: { double *fdp = from_column->values->d; for (i = 0; i < to_length; i++, fdp++) @@ -17647,8 +16933,7 @@ cpl_column_set_invalid(to_column, i); break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; for (i = 0; i < to_length; i++, fcfp++) @@ -17657,8 +16942,7 @@ cpl_column_set_invalid(to_column, i); break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; for (i = 0; i < to_length; i++, fcdp++) @@ -17669,13 +16953,11 @@ } default: break; - } - } - /* + /* * If there are just NULLs in the target column, no need to * perform any further operation: */ @@ -17685,534 +16967,480 @@ if (to_column->nullcount == 0 && from_column->nullcount == 0) { - /* * If there are no invalids in both columns, the operation can * be performed without any check: */ switch (to_type) { - - case CPL_TYPE_INT: - { - int *tip = to_column->values->i; + case CPL_TYPE_INT: { + int *tip = to_column->values->i; switch (from_type) { - - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) *tip++ /= *fip++; break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) *tip++ /= *flp++; break; } - case CPL_TYPE_LONG_LONG: - { - long long *flp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *flp = from_column->values->ll; while (to_length--) *tip++ /= *flp++; break; } - case CPL_TYPE_SIZE: - { - cpl_size *flp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *flp = from_column->values->sz; while (to_length--) *tip++ /= *flp++; break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; while (to_length--) *tip++ /= *ffp++; break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; while (to_length--) *tip++ /= *fdp++; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; while (to_length--) - tip[to_length] = tip[to_length] / fcfp[to_length]; /* Support clang */ + tip[to_length] = + tip[to_length] / + fcfp[to_length]; /* Support clang */ break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; while (to_length--) - tip[to_length] = tip[to_length] / fcdp[to_length]; /* Support clang */ + tip[to_length] = + tip[to_length] / + fcdp[to_length]; /* Support clang */ break; } default: break; - } break; } - case CPL_TYPE_LONG: - { - long *tlp = to_column->values->l; + case CPL_TYPE_LONG: { + long *tlp = to_column->values->l; switch (from_type) { - - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) *tlp++ /= *fip++; break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) *tlp++ /= *flp++; break; } - case CPL_TYPE_LONG_LONG: - { - long long *flp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *flp = from_column->values->ll; while (to_length--) *tlp++ /= *flp++; break; } - case CPL_TYPE_SIZE: - { - cpl_size *flp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *flp = from_column->values->sz; while (to_length--) *tlp++ /= *flp++; break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; while (to_length--) *tlp++ /= *ffp++; break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; while (to_length--) *tlp++ /= *fdp++; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; while (to_length--) - tlp[to_length] = tlp[to_length] / fcfp[to_length]; /* Support clang */ + tlp[to_length] = + tlp[to_length] / + fcfp[to_length]; /* Support clang */ break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; while (to_length--) - tlp[to_length] = tlp[to_length] / fcdp[to_length]; /* Support clang */ + tlp[to_length] = + tlp[to_length] / + fcdp[to_length]; /* Support clang */ break; } default: break; - } break; } - case CPL_TYPE_LONG_LONG: - { - long long *tlp = to_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *tlp = to_column->values->ll; switch (from_type) { - - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) *tlp++ /= *fip++; break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) *tlp++ /= *flp++; break; } - case CPL_TYPE_LONG_LONG: - { - long long *flp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *flp = from_column->values->ll; while (to_length--) *tlp++ /= *flp++; break; } - case CPL_TYPE_SIZE: - { - cpl_size *flp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *flp = from_column->values->sz; while (to_length--) *tlp++ /= *flp++; break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; while (to_length--) *tlp++ /= *ffp++; break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; while (to_length--) *tlp++ /= *fdp++; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; while (to_length--) - tlp[to_length] = tlp[to_length] / fcfp[to_length]; /* Support clang */ + tlp[to_length] = + tlp[to_length] / + fcfp[to_length]; /* Support clang */ break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; while (to_length--) - tlp[to_length] = tlp[to_length] / fcdp[to_length]; /* Support clang */ + tlp[to_length] = + tlp[to_length] / + fcdp[to_length]; /* Support clang */ break; } default: break; - } break; } - case CPL_TYPE_SIZE: - { - cpl_size *tlp = to_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *tlp = to_column->values->sz; switch (from_type) { - - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) *tlp++ /= *fip++; break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) *tlp++ /= *flp++; break; } - case CPL_TYPE_LONG_LONG: - { - long long *flp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *flp = from_column->values->ll; while (to_length--) *tlp++ /= *flp++; break; } - case CPL_TYPE_SIZE: - { - cpl_size *flp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *flp = from_column->values->sz; while (to_length--) *tlp++ /= *flp++; break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; while (to_length--) *tlp++ /= *ffp++; break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; while (to_length--) *tlp++ /= *fdp++; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; while (to_length--) - tlp[to_length] = tlp[to_length] / fcfp[to_length]; /* Support clang */ + tlp[to_length] = + tlp[to_length] / + fcfp[to_length]; /* Support clang */ break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; while (to_length--) - tlp[to_length] = tlp[to_length] / fcdp[to_length]; /* Support clang */ + tlp[to_length] = + tlp[to_length] / + fcdp[to_length]; /* Support clang */ break; } default: break; - } break; } - case CPL_TYPE_FLOAT: - { - float *tfp = to_column->values->f; + case CPL_TYPE_FLOAT: { + float *tfp = to_column->values->f; switch (from_type) { - - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) *tfp++ /= (double)*fip++; break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) *tfp++ /= (double)*flp++; break; } - case CPL_TYPE_LONG_LONG: - { - long long *flp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *flp = from_column->values->ll; while (to_length--) *tfp++ /= (double)*flp++; break; } - case CPL_TYPE_SIZE: - { - cpl_size *flp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *flp = from_column->values->sz; while (to_length--) *tfp++ /= (double)*flp++; break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; while (to_length--) *tfp++ /= (double)*ffp++; break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; while (to_length--) *tfp++ /= *fdp++; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; while (to_length--) - tfp[to_length] = tfp[to_length] / fcfp[to_length]; /* Support clang */ + tfp[to_length] = + tfp[to_length] / + fcfp[to_length]; /* Support clang */ break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; while (to_length--) - tfp[to_length] = tfp[to_length] / fcdp[to_length]; /* Support clang */ + tfp[to_length] = + tfp[to_length] / + fcdp[to_length]; /* Support clang */ break; } default: break; - } break; } - case CPL_TYPE_DOUBLE: - { - double *tdp = to_column->values->d; + case CPL_TYPE_DOUBLE: { + double *tdp = to_column->values->d; switch (from_type) { - - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) *tdp++ /= *fip++; break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) *tdp++ /= *flp++; break; } - case CPL_TYPE_LONG_LONG: - { - long long *flp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *flp = from_column->values->ll; while (to_length--) *tdp++ /= *flp++; break; } - case CPL_TYPE_SIZE: - { - cpl_size *flp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *flp = from_column->values->sz; while (to_length--) *tdp++ /= *flp++; break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; while (to_length--) *tdp++ /= *ffp++; break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; while (to_length--) *tdp++ /= *fdp++; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; while (to_length--) - tdp[to_length] = tdp[to_length] / fcfp[to_length]; /* Support clang */ + tdp[to_length] = + tdp[to_length] / + fcfp[to_length]; /* Support clang */ break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; while (to_length--) - tdp[to_length] = tdp[to_length] / fcdp[to_length]; /* Support clang */ + tdp[to_length] = + tdp[to_length] / + fcdp[to_length]; /* Support clang */ break; } default: break; - } break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *tcfp = to_column->values->cf; switch (from_type) { - - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) *tcfp++ /= *fip++; break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) *tcfp++ /= *flp++; break; } - case CPL_TYPE_LONG_LONG: - { - long long *flp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *flp = from_column->values->ll; while (to_length--) *tcfp++ /= *flp++; break; } - case CPL_TYPE_SIZE: - { - cpl_size *flp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *flp = from_column->values->sz; while (to_length--) *tcfp++ /= *flp++; break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; while (to_length--) *tcfp++ /= *ffp++; break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; while (to_length--) *tcfp++ /= *fdp++; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; while (to_length--) *tcfp++ /= *fcfp++; break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; while (to_length--) @@ -18221,74 +17449,63 @@ } default: break; - } break; - } - case CPL_TYPE_DOUBLE_COMPLEX: - { + } + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *tcdp = to_column->values->cd; switch (from_type) { - - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; while (to_length--) *tcdp++ /= *fip++; break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; while (to_length--) *tcdp++ /= *flp++; break; } - case CPL_TYPE_LONG_LONG: - { - long long *flp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *flp = from_column->values->ll; while (to_length--) *tcdp++ /= *flp++; break; } - case CPL_TYPE_SIZE: - { - cpl_size *flp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *flp = from_column->values->sz; while (to_length--) *tcdp++ /= *flp++; break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; while (to_length--) *tcdp++ /= *ffp++; break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; while (to_length--) *tcdp++ /= *fdp++; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; while (to_length--) *tcdp++ /= *fcfp++; break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; while (to_length--) @@ -18297,17 +17514,14 @@ } default: break; - } break; } default: break; - } } else { - /* * Here there are some invalids around, so the operation needs to be * performed with some checks. As a first thing, take care of the @@ -18315,7 +17529,6 @@ */ if (to_column->nullcount == 0 || from_column->nullcount == 0) { - /* * Here there are some invalids in just one of the two columns. * If they are just in the column to subtract, an identical @@ -18323,8 +17536,8 @@ */ if (from_column->nullcount) { - to_column->null = cpl_calloc(to_length, - sizeof(cpl_column_flag)); + to_column->null = + cpl_calloc(to_length, sizeof(cpl_column_flag)); i = to_length; while (i--) @@ -18332,11 +17545,9 @@ to_column->null[i] = 1; to_column->nullcount = from_column->nullcount; - } } else { - /* * Here there are some invalids in both columns. */ @@ -18352,7 +17563,6 @@ } if (to_column->nullcount == to_length) { - /* * Just invalids in the result: no need to perform any further * operation, and the invalid buffer of the target column can @@ -18364,7 +17574,6 @@ to_column->null = NULL; return 0; } - } /* @@ -18375,69 +17584,59 @@ tnp = to_column->null; switch (to_type) { - - case CPL_TYPE_INT: - { - int *tip = to_column->values->i; + case CPL_TYPE_INT: { + int *tip = to_column->values->i; switch (from_type) { - - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; for (i = 0; i < to_length; i++, tip++, fip++, tnp++) if (*tnp == 0) *tip /= *fip; break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; for (i = 0; i < to_length; i++, tip++, flp++, tnp++) if (*tnp == 0) *tip /= *flp; break; } - case CPL_TYPE_LONG_LONG: - { - long long *flp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *flp = from_column->values->ll; for (i = 0; i < to_length; i++, tip++, flp++, tnp++) if (*tnp == 0) *tip /= *flp; break; } - case CPL_TYPE_SIZE: - { - cpl_size *flp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *flp = from_column->values->sz; for (i = 0; i < to_length; i++, tip++, flp++, tnp++) if (*tnp == 0) *tip /= *flp; break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; for (i = 0; i < to_length; i++, tip++, ffp++, tnp++) if (*tnp == 0) *tip /= *ffp; break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; for (i = 0; i < to_length; i++, tip++, fdp++, tnp++) if (*tnp == 0) *tip /= *fdp; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; for (i = 0; i < to_length; i++, tip++, fcfp++, tnp++) @@ -18445,8 +17644,7 @@ *tip = *tip / *fcfp; /* Support clang */ break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; for (i = 0; i < to_length; i++, tip++, fcdp++, tnp++) @@ -18456,72 +17654,62 @@ } default: break; - } break; } - case CPL_TYPE_LONG: - { - long *tlp = to_column->values->l; + case CPL_TYPE_LONG: { + long *tlp = to_column->values->l; switch (from_type) { - - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; for (i = 0; i < to_length; i++, tlp++, fip++, tnp++) if (*tnp == 0) *tlp /= *fip; break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; for (i = 0; i < to_length; i++, tlp++, flp++, tnp++) if (*tnp == 0) *tlp /= *flp; break; } - case CPL_TYPE_LONG_LONG: - { - long long *flp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *flp = from_column->values->ll; for (i = 0; i < to_length; i++, tlp++, flp++, tnp++) if (*tnp == 0) *tlp /= *flp; break; } - case CPL_TYPE_SIZE: - { - cpl_size *flp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *flp = from_column->values->sz; for (i = 0; i < to_length; i++, tlp++, flp++, tnp++) if (*tnp == 0) *tlp /= *flp; break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; for (i = 0; i < to_length; i++, tlp++, ffp++, tnp++) if (*tnp == 0) *tlp /= *ffp; break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; for (i = 0; i < to_length; i++, tlp++, fdp++, tnp++) if (*tnp == 0) *tlp /= *fdp; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; for (i = 0; i < to_length; i++, tlp++, fcfp++, tnp++) @@ -18529,8 +17717,7 @@ *tlp = *tlp / *fcfp; /* Support clang */ break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; for (i = 0; i < to_length; i++, tlp++, fcdp++, tnp++) @@ -18540,72 +17727,62 @@ } default: break; - } break; } - case CPL_TYPE_LONG_LONG: - { - long long *tlp = to_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *tlp = to_column->values->ll; switch (from_type) { - - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; for (i = 0; i < to_length; i++, tlp++, fip++, tnp++) if (*tnp == 0) *tlp /= *fip; break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; for (i = 0; i < to_length; i++, tlp++, flp++, tnp++) if (*tnp == 0) *tlp /= *flp; break; } - case CPL_TYPE_LONG_LONG: - { - long long *flp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *flp = from_column->values->ll; for (i = 0; i < to_length; i++, tlp++, flp++, tnp++) if (*tnp == 0) *tlp /= *flp; break; } - case CPL_TYPE_SIZE: - { - cpl_size *flp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *flp = from_column->values->sz; for (i = 0; i < to_length; i++, tlp++, flp++, tnp++) if (*tnp == 0) *tlp /= *flp; break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; for (i = 0; i < to_length; i++, tlp++, ffp++, tnp++) if (*tnp == 0) *tlp /= *ffp; break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; for (i = 0; i < to_length; i++, tlp++, fdp++, tnp++) if (*tnp == 0) *tlp /= *fdp; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; for (i = 0; i < to_length; i++, tlp++, fcfp++, tnp++) @@ -18613,8 +17790,7 @@ *tlp = *tlp / *fcfp; /* Support clang */ break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; for (i = 0; i < to_length; i++, tlp++, fcdp++, tnp++) @@ -18624,72 +17800,62 @@ } default: break; - } break; } - case CPL_TYPE_SIZE: - { - cpl_size *tlp = to_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *tlp = to_column->values->sz; switch (from_type) { - - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; for (i = 0; i < to_length; i++, tlp++, fip++, tnp++) if (*tnp == 0) *tlp /= *fip; break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; for (i = 0; i < to_length; i++, tlp++, flp++, tnp++) if (*tnp == 0) *tlp /= *flp; break; } - case CPL_TYPE_LONG_LONG: - { - long long *flp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *flp = from_column->values->ll; for (i = 0; i < to_length; i++, tlp++, flp++, tnp++) if (*tnp == 0) *tlp /= *flp; break; } - case CPL_TYPE_SIZE: - { - cpl_size *flp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *flp = from_column->values->sz; for (i = 0; i < to_length; i++, tlp++, flp++, tnp++) if (*tnp == 0) *tlp /= *flp; break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; for (i = 0; i < to_length; i++, tlp++, ffp++, tnp++) if (*tnp == 0) *tlp /= *ffp; break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; for (i = 0; i < to_length; i++, tlp++, fdp++, tnp++) if (*tnp == 0) *tlp /= *fdp; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; for (i = 0; i < to_length; i++, tlp++, fcfp++, tnp++) @@ -18697,8 +17863,7 @@ *tlp = *tlp / *fcfp; /* Support clang */ break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; for (i = 0; i < to_length; i++, tlp++, fcdp++, tnp++) @@ -18708,72 +17873,62 @@ } default: break; - } break; } - case CPL_TYPE_FLOAT: - { - float *tfp = to_column->values->f; + case CPL_TYPE_FLOAT: { + float *tfp = to_column->values->f; switch (from_type) { - - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; for (i = 0; i < to_length; i++, tfp++, fip++, tnp++) if (*tnp == 0) *tfp /= (double)*fip; break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; for (i = 0; i < to_length; i++, tfp++, flp++, tnp++) if (*tnp == 0) *tfp /= *flp; break; } - case CPL_TYPE_LONG_LONG: - { - long long *flp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *flp = from_column->values->ll; for (i = 0; i < to_length; i++, tfp++, flp++, tnp++) if (*tnp == 0) *tfp /= *flp; break; } - case CPL_TYPE_SIZE: - { - cpl_size *flp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *flp = from_column->values->sz; for (i = 0; i < to_length; i++, tfp++, flp++, tnp++) if (*tnp == 0) *tfp /= *flp; break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; for (i = 0; i < to_length; i++, tfp++, ffp++, tnp++) if (*tnp == 0) *tfp /= (double)*ffp; break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; for (i = 0; i < to_length; i++, tfp++, fdp++, tnp++) if (*tnp == 0) *tfp /= *fdp; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; for (i = 0; i < to_length; i++, tfp++, fcfp++, tnp++) @@ -18781,8 +17936,7 @@ *tfp /= (double)*fcfp; break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; for (i = 0; i < to_length; i++, tfp++, fcdp++, tnp++) @@ -18792,72 +17946,62 @@ } default: break; - } break; } - case CPL_TYPE_DOUBLE: - { - double *tdp = to_column->values->d; + case CPL_TYPE_DOUBLE: { + double *tdp = to_column->values->d; switch (from_type) { - - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; for (i = 0; i < to_length; i++, tdp++, fip++, tnp++) if (*tnp == 0) *tdp /= *fip; break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; for (i = 0; i < to_length; i++, tdp++, flp++, tnp++) if (*tnp == 0) *tdp /= *flp; break; } - case CPL_TYPE_LONG_LONG: - { - long long *flp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *flp = from_column->values->ll; for (i = 0; i < to_length; i++, tdp++, flp++, tnp++) if (*tnp == 0) *tdp /= *flp; break; } - case CPL_TYPE_SIZE: - { - cpl_size *flp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *flp = from_column->values->sz; for (i = 0; i < to_length; i++, tdp++, flp++, tnp++) if (*tnp == 0) *tdp /= *flp; break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; for (i = 0; i < to_length; i++, tdp++, ffp++, tnp++) if (*tnp == 0) *tdp /= *ffp; break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; for (i = 0; i < to_length; i++, tdp++, fdp++, tnp++) if (*tnp == 0) *tdp /= *fdp; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; for (i = 0; i < to_length; i++, tdp++, fcfp++, tnp++) @@ -18865,8 +18009,7 @@ *tdp = *tdp / *fcfp; /* Support clang */ break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; for (i = 0; i < to_length; i++, tdp++, fcdp++, tnp++) @@ -18876,72 +18019,62 @@ } default: break; - } break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *tcfp = to_column->values->cf; switch (from_type) { - - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; for (i = 0; i < to_length; i++, tcfp++, fip++, tnp++) if (*tnp == 0) *tcfp /= *fip; break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; for (i = 0; i < to_length; i++, tcfp++, flp++, tnp++) if (*tnp == 0) *tcfp /= *flp; break; } - case CPL_TYPE_LONG_LONG: - { - long long *flp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *flp = from_column->values->ll; for (i = 0; i < to_length; i++, tcfp++, flp++, tnp++) if (*tnp == 0) *tcfp /= *flp; break; } - case CPL_TYPE_SIZE: - { - cpl_size *flp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *flp = from_column->values->sz; for (i = 0; i < to_length; i++, tcfp++, flp++, tnp++) if (*tnp == 0) *tcfp /= *flp; break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; for (i = 0; i < to_length; i++, tcfp++, ffp++, tnp++) if (*tnp == 0) *tcfp /= *ffp; break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; for (i = 0; i < to_length; i++, tcfp++, fdp++, tnp++) if (*tnp == 0) *tcfp /= *fdp; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; for (i = 0; i < to_length; i++, tcfp++, fcfp++, tnp++) @@ -18949,8 +18082,7 @@ *tcfp /= *fcfp; break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; for (i = 0; i < to_length; i++, tcfp++, fcdp++, tnp++) @@ -18960,72 +18092,62 @@ } default: break; - } break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *tcdp = to_column->values->cd; switch (from_type) { - - case CPL_TYPE_INT: - { - int *fip = from_column->values->i; + case CPL_TYPE_INT: { + int *fip = from_column->values->i; for (i = 0; i < to_length; i++, tcdp++, fip++, tnp++) if (*tnp == 0) *tcdp /= *fip; break; } - case CPL_TYPE_LONG: - { - long *flp = from_column->values->l; + case CPL_TYPE_LONG: { + long *flp = from_column->values->l; for (i = 0; i < to_length; i++, tcdp++, flp++, tnp++) if (*tnp == 0) *tcdp /= *flp; break; } - case CPL_TYPE_LONG_LONG: - { - long long *flp = from_column->values->ll; + case CPL_TYPE_LONG_LONG: { + long long *flp = from_column->values->ll; for (i = 0; i < to_length; i++, tcdp++, flp++, tnp++) if (*tnp == 0) *tcdp /= *flp; break; } - case CPL_TYPE_SIZE: - { - cpl_size *flp = from_column->values->sz; + case CPL_TYPE_SIZE: { + cpl_size *flp = from_column->values->sz; for (i = 0; i < to_length; i++, tcdp++, flp++, tnp++) if (*tnp == 0) *tcdp /= *flp; break; } - case CPL_TYPE_FLOAT: - { - float *ffp = from_column->values->f; + case CPL_TYPE_FLOAT: { + float *ffp = from_column->values->f; for (i = 0; i < to_length; i++, tcdp++, ffp++, tnp++) if (*tnp == 0) *tcdp /= *ffp; break; } - case CPL_TYPE_DOUBLE: - { - double *fdp = from_column->values->d; + case CPL_TYPE_DOUBLE: { + double *fdp = from_column->values->d; for (i = 0; i < to_length; i++, tcdp++, fdp++, tnp++) if (*tnp == 0) *tcdp /= *fdp; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *fcfp = from_column->values->cf; for (i = 0; i < to_length; i++, tcdp++, fcfp++, tnp++) @@ -19033,8 +18155,7 @@ *tcdp /= *fcfp; break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *fcdp = from_column->values->cd; for (i = 0; i < to_length; i++, tcdp++, fcdp++, tnp++) @@ -19044,18 +18165,15 @@ } default: break; - } break; } default: break; - } } return CPL_ERROR_NONE; - } @@ -19073,13 +18191,13 @@ * that this was done elsewhere. */ -static void cpl_column_exp_int(cpl_column *column, double base) +static void +cpl_column_exp_int(cpl_column *column, double base) { - cpl_size nullcount = cpl_column_count_invalid(column); - cpl_size length = cpl_column_get_size(column); - int *ip = cpl_column_get_data_int(column); - int *np = cpl_column_get_data_invalid(column); + cpl_size length = cpl_column_get_size(column); + int *ip = cpl_column_get_data_int(column); + int *np = cpl_column_get_data_invalid(column); cpl_size i; @@ -19095,7 +18213,6 @@ if (*np == 0) *ip = cpl_tools_ipow(base, *ip); } - } @@ -19113,14 +18230,14 @@ * that this was done elsewhere. */ -static void cpl_column_exp_long(cpl_column *column, double base) +static void +cpl_column_exp_long(cpl_column *column, double base) { - - cpl_size nullcount = cpl_column_count_invalid(column); - cpl_size length = cpl_column_get_size(column); - long *lp = cpl_column_get_data_long(column); - cpl_column_flag *np = cpl_column_get_data_invalid(column); - cpl_size i; + cpl_size nullcount = cpl_column_count_invalid(column); + cpl_size length = cpl_column_get_size(column); + long *lp = cpl_column_get_data_long(column); + cpl_column_flag *np = cpl_column_get_data_invalid(column); + cpl_size i; if (nullcount == length) @@ -19135,7 +18252,6 @@ if (*np == 0) *lp = pow(base, *lp); } - } @@ -19153,14 +18269,14 @@ * that this was done elsewhere. */ -static void cpl_column_exp_long_long(cpl_column *column, double base) +static void +cpl_column_exp_long_long(cpl_column *column, double base) { - - cpl_size nullcount = cpl_column_count_invalid(column); - cpl_size length = cpl_column_get_size(column); - long long *lp = cpl_column_get_data_long_long(column); - cpl_column_flag *np = cpl_column_get_data_invalid(column); - cpl_size i; + cpl_size nullcount = cpl_column_count_invalid(column); + cpl_size length = cpl_column_get_size(column); + long long *lp = cpl_column_get_data_long_long(column); + cpl_column_flag *np = cpl_column_get_data_invalid(column); + cpl_size i; if (nullcount == length) @@ -19175,7 +18291,6 @@ if (*np == 0) *lp = pow(base, *lp); } - } @@ -19193,14 +18308,14 @@ * that this was done elsewhere. */ -static void cpl_column_exp_cplsize(cpl_column *column, double base) +static void +cpl_column_exp_cplsize(cpl_column *column, double base) { - - cpl_size nullcount = cpl_column_count_invalid(column); - cpl_size length = cpl_column_get_size(column); - cpl_size *lp = cpl_column_get_data_cplsize(column); - cpl_column_flag *np = cpl_column_get_data_invalid(column); - cpl_size i; + cpl_size nullcount = cpl_column_count_invalid(column); + cpl_size length = cpl_column_get_size(column); + cpl_size *lp = cpl_column_get_data_cplsize(column); + cpl_column_flag *np = cpl_column_get_data_invalid(column); + cpl_size i; if (nullcount == length) @@ -19215,7 +18330,6 @@ if (*np == 0) *lp = pow(base, *lp); } - } @@ -19233,13 +18347,13 @@ * that this was done elsewhere. */ -static void cpl_column_exp_float(cpl_column *column, double base) +static void +cpl_column_exp_float(cpl_column *column, double base) { - cpl_size nullcount = cpl_column_count_invalid(column); - cpl_size length = cpl_column_get_size(column); - float *fp = cpl_column_get_data_float(column); - int *np = cpl_column_get_data_invalid(column); + cpl_size length = cpl_column_get_size(column); + float *fp = cpl_column_get_data_float(column); + int *np = cpl_column_get_data_invalid(column); cpl_size i; @@ -19255,18 +18369,17 @@ if (*np == 0) *fp = pow(base, *fp); } - } -static void cpl_column_conj_float(cpl_column *column) +static void +cpl_column_conj_float(cpl_column *column) { - - cpl_size nullcount = cpl_column_count_invalid(column); - cpl_size length = cpl_column_get_size(column); - float complex *fp = cpl_column_get_data_float_complex(column); - int *np = cpl_column_get_data_invalid(column); - cpl_size i; + cpl_size nullcount = cpl_column_count_invalid(column); + cpl_size length = cpl_column_get_size(column); + float complex *fp = cpl_column_get_data_float_complex(column); + int *np = cpl_column_get_data_invalid(column); + cpl_size i; if (nullcount == length) @@ -19281,7 +18394,6 @@ if (*np == 0) *fp = conj(*fp); } - } @@ -19299,14 +18411,14 @@ * that this was done elsewhere. */ -static void cpl_column_exp_float_complex(cpl_column *column, double base) +static void +cpl_column_exp_float_complex(cpl_column *column, double base) { - - cpl_size nullcount = cpl_column_count_invalid(column); - cpl_size length = cpl_column_get_size(column); - float complex *fp = cpl_column_get_data_float_complex(column); - int *np = cpl_column_get_data_invalid(column); - cpl_size i; + cpl_size nullcount = cpl_column_count_invalid(column); + cpl_size length = cpl_column_get_size(column); + float complex *fp = cpl_column_get_data_float_complex(column); + int *np = cpl_column_get_data_invalid(column); + cpl_size i; if (nullcount == length) @@ -19321,7 +18433,6 @@ if (*np == 0) *fp = cpowf(base, *fp); } - } @@ -19339,13 +18450,13 @@ * that this was done elsewhere. */ -static void cpl_column_exp_double(cpl_column *column, double base) +static void +cpl_column_exp_double(cpl_column *column, double base) { - cpl_size nullcount = cpl_column_count_invalid(column); - cpl_size length = cpl_column_get_size(column); - double *dp = cpl_column_get_data_double(column); - int *np = cpl_column_get_data_invalid(column); + cpl_size length = cpl_column_get_size(column); + double *dp = cpl_column_get_data_double(column); + int *np = cpl_column_get_data_invalid(column); cpl_size i; @@ -19361,18 +18472,17 @@ if (*np == 0) *dp = pow(base, *dp); } - } -static void cpl_column_conj_double(cpl_column *column) +static void +cpl_column_conj_double(cpl_column *column) { - - cpl_size nullcount = cpl_column_count_invalid(column); - cpl_size length = cpl_column_get_size(column); - double complex *fp = cpl_column_get_data_double_complex(column); - int *np = cpl_column_get_data_invalid(column); - cpl_size i; + cpl_size nullcount = cpl_column_count_invalid(column); + cpl_size length = cpl_column_get_size(column); + double complex *fp = cpl_column_get_data_double_complex(column); + int *np = cpl_column_get_data_invalid(column); + cpl_size i; if (nullcount == length) @@ -19387,7 +18497,6 @@ if (*np == 0) *fp = conj(*fp); } - } @@ -19405,14 +18514,14 @@ * that this was done elsewhere. */ -static void cpl_column_exp_double_complex(cpl_column *column, double base) +static void +cpl_column_exp_double_complex(cpl_column *column, double base) { - - cpl_size nullcount = cpl_column_count_invalid(column); - cpl_size length = cpl_column_get_size(column); - double complex *dp = cpl_column_get_data_double_complex(column); - int *np = cpl_column_get_data_invalid(column); - cpl_size i; + cpl_size nullcount = cpl_column_count_invalid(column); + cpl_size length = cpl_column_get_size(column); + double complex *dp = cpl_column_get_data_double_complex(column); + int *np = cpl_column_get_data_invalid(column); + cpl_size i; if (nullcount == length) @@ -19427,7 +18536,6 @@ if (*np == 0) *dp = cpow(base, *dp); } - } /* @@ -19444,14 +18552,15 @@ * that this was done elsewhere. */ -static void cpl_column_pow_float_complex(cpl_column *column, double exponent) +static void +cpl_column_pow_float_complex(cpl_column *column, double exponent) { - const int myerrno = errno; + const int myerrno = errno; const cpl_size nullcount = cpl_column_count_invalid(column); - const cpl_size length = cpl_column_get_size(column); - float complex *fp = cpl_column_get_data_float_complex(column); - const int *np = nullcount == 0 ? NULL - : cpl_column_get_data_invalid_const(column); + const cpl_size length = cpl_column_get_size(column); + float complex *fp = cpl_column_get_data_float_complex(column); + const int *np = + nullcount == 0 ? NULL : cpl_column_get_data_invalid_const(column); if (nullcount == length) @@ -19473,55 +18582,64 @@ float complex value; if (fp[i] != 0.0) { value = 1.0 / csqrtf(fp[i]); - } else { + } + else { errno = EDOM; /* Use errno to reuse code */ } if (errno) { errno = 0; cpl_column_set_invalid(column, i); - } else { + } + else { fp[i] = value; } } } - } else if (exponent < 0.0) { + } + else if (exponent < 0.0) { /* Column value must be non-zero */ for (size_t i = 0; i < (size_t)length; i++) { if (np == NULL || np[i] == 0) { float complex value; if (fp[i] != 0.0) { value = cpowf(fp[i], exponent); - } else { + } + else { errno = EDOM; /* Use errno to reuse code */ } if (errno) { errno = 0; cpl_column_set_invalid(column, i); - } else { + } + else { fp[i] = value; } } } - } else if (exponent == 0.5) { + } + else if (exponent == 0.5) { for (size_t i = 0; i < (size_t)length; i++) { if (np == NULL || np[i] == 0) { const float complex value = csqrtf(fp[i]); if (errno) { errno = 0; cpl_column_set_invalid(column, i); - } else { + } + else { fp[i] = value; } } } - } else if (exponent != 1.0) { + } + else if (exponent != 1.0) { for (size_t i = 0; i < (size_t)length; i++) { if (np == NULL || np[i] == 0) { const float complex value = cpowf(fp[i], exponent); if (errno) { errno = 0; cpl_column_set_invalid(column, i); - } else { + } + else { fp[i] = value; } } @@ -19530,7 +18648,7 @@ if (exponent != 1.0) { /* FIXME: Counts also bad pixels */ - cpl_tools_add_flops( length ); + cpl_tools_add_flops(length); } errno = myerrno; @@ -19551,14 +18669,15 @@ * that this was done elsewhere. */ -static void cpl_column_pow_double_complex(cpl_column *column, double exponent) +static void +cpl_column_pow_double_complex(cpl_column *column, double exponent) { - const int myerrno = errno; + const int myerrno = errno; const cpl_size nullcount = cpl_column_count_invalid(column); - const cpl_size length = cpl_column_get_size(column); - double complex *fp = cpl_column_get_data_double_complex(column); - const int *np = nullcount == 0 ? NULL - : cpl_column_get_data_invalid_const(column); + const cpl_size length = cpl_column_get_size(column); + double complex *fp = cpl_column_get_data_double_complex(column); + const int *np = + nullcount == 0 ? NULL : cpl_column_get_data_invalid_const(column); if (nullcount == length) @@ -19580,55 +18699,64 @@ double complex value = 0; /* Init avoids (false pos.) warning */ if (fp[i] != 0.0) { value = 1.0 / csqrt(fp[i]); - } else { + } + else { errno = EDOM; /* Use errno to reuse code */ } if (errno) { errno = 0; cpl_column_set_invalid(column, i); - } else { + } + else { fp[i] = value; } } } - } else if (exponent < 0.0) { + } + else if (exponent < 0.0) { /* Column value must be non-zero */ for (size_t i = 0; i < (size_t)length; i++) { if (np == NULL || np[i] == 0) { double complex value = 0; /* Init avoids (false pos.) warning */ if (fp[i] != 0.0) { value = cpow(fp[i], exponent); - } else { + } + else { errno = EDOM; /* Use errno to reuse code */ } if (errno) { errno = 0; cpl_column_set_invalid(column, i); - } else { + } + else { fp[i] = value; } } } - } else if (exponent == 0.5) { + } + else if (exponent == 0.5) { for (size_t i = 0; i < (size_t)length; i++) { if (np == NULL || np[i] == 0) { const double complex value = csqrt(fp[i]); if (errno) { errno = 0; cpl_column_set_invalid(column, i); - } else { + } + else { fp[i] = value; } } } - } else if (exponent != 1.0) { + } + else if (exponent != 1.0) { for (size_t i = 0; i < (size_t)length; i++) { if (np == NULL || np[i] == 0) { const double complex value = cpow(fp[i], exponent); if (errno) { errno = 0; cpl_column_set_invalid(column, i); - } else { + } + else { fp[i] = value; } } @@ -19637,7 +18765,7 @@ if (exponent != 1.0) { /* FIXME: Counts also bad pixels */ - cpl_tools_add_flops( length ); + cpl_tools_add_flops(length); } errno = myerrno; @@ -19658,15 +18786,15 @@ * that this was done elsewhere. */ -static void cpl_column_cpow_float_complex(cpl_column *column, - double complex exponent) +static void +cpl_column_cpow_float_complex(cpl_column *column, double complex exponent) { - const int myerrno = errno; + const int myerrno = errno; const cpl_size nullcount = cpl_column_count_invalid(column); - const cpl_size length = cpl_column_get_size(column); - float complex *fp = cpl_column_get_data_float_complex(column); - const int *np = nullcount == 0 ? NULL - : cpl_column_get_data_invalid_const(column); + const cpl_size length = cpl_column_get_size(column); + float complex *fp = cpl_column_get_data_float_complex(column); + const int *np = + nullcount == 0 ? NULL : cpl_column_get_data_invalid_const(column); if (nullcount == length) @@ -19687,7 +18815,8 @@ if (errno) { errno = 0; cpl_column_set_invalid(column, i); - } else { + } + else { fp[i] = value; } } @@ -19695,7 +18824,7 @@ if (exponent != 1.0) { /* FIXME: Counts also bad pixels */ - cpl_tools_add_flops( length ); + cpl_tools_add_flops(length); } errno = myerrno; @@ -19715,15 +18844,15 @@ * that this was done elsewhere. */ -static void cpl_column_cpow_double_complex(cpl_column *column, - double complex exponent) +static void +cpl_column_cpow_double_complex(cpl_column *column, double complex exponent) { - const int myerrno = errno; + const int myerrno = errno; const cpl_size nullcount = cpl_column_count_invalid(column); - const cpl_size length = cpl_column_get_size(column); - double complex *dp = cpl_column_get_data_double_complex(column); - const int *np = nullcount == 0 ? NULL - : cpl_column_get_data_invalid_const(column); + const cpl_size length = cpl_column_get_size(column); + double complex *dp = cpl_column_get_data_double_complex(column); + const int *np = + nullcount == 0 ? NULL : cpl_column_get_data_invalid_const(column); if (nullcount == length) @@ -19744,7 +18873,8 @@ if (errno) { errno = 0; cpl_column_set_invalid(column, i); - } else { + } + else { dp[i] = value; } } @@ -19767,15 +18897,15 @@ * that this was done elsewhere. */ -static void cpl_column_log_int(cpl_column *column, double base) +static void +cpl_column_log_int(cpl_column *column, double base) { - cpl_size nullcount = cpl_column_count_invalid(column); - cpl_size length = cpl_column_get_size(column); - int *ip = cpl_column_get_data_int(column); - int *np = cpl_column_get_data_invalid(column); + cpl_size length = cpl_column_get_size(column); + int *ip = cpl_column_get_data_int(column); + int *np = cpl_column_get_data_invalid(column); cpl_size i; - double invlog = 1 / log(base); + double invlog = 1 / log(base); if (nullcount == length) @@ -19785,7 +18915,7 @@ for (i = 0; i < length; i++, ip++) { if (*ip > 0) *ip = floor(log(*ip) * invlog + 0.5); - else + else cpl_column_set_invalid(column, i); } } @@ -19816,15 +18946,15 @@ * that this was done elsewhere. */ -static void cpl_column_log_long(cpl_column *column, double base) +static void +cpl_column_log_long(cpl_column *column, double base) { - - cpl_size nullcount = cpl_column_count_invalid(column); - cpl_size length = cpl_column_get_size(column); - long *lp = cpl_column_get_data_long(column); - cpl_column_flag *np = cpl_column_get_data_invalid(column); - cpl_size i; - double invlog = 1 / log(base); + cpl_size nullcount = cpl_column_count_invalid(column); + cpl_size length = cpl_column_get_size(column); + long *lp = cpl_column_get_data_long(column); + cpl_column_flag *np = cpl_column_get_data_invalid(column); + cpl_size i; + double invlog = 1 / log(base); if (nullcount == length) @@ -19865,15 +18995,15 @@ * that this was done elsewhere. */ -static void cpl_column_log_long_long(cpl_column *column, double base) +static void +cpl_column_log_long_long(cpl_column *column, double base) { - - cpl_size nullcount = cpl_column_count_invalid(column); - cpl_size length = cpl_column_get_size(column); - long long *lp = cpl_column_get_data_long_long(column); - cpl_column_flag *np = cpl_column_get_data_invalid(column); - cpl_size i; - double invlog = 1 / log(base); + cpl_size nullcount = cpl_column_count_invalid(column); + cpl_size length = cpl_column_get_size(column); + long long *lp = cpl_column_get_data_long_long(column); + cpl_column_flag *np = cpl_column_get_data_invalid(column); + cpl_size i; + double invlog = 1 / log(base); if (nullcount == length) @@ -19914,15 +19044,15 @@ * that this was done elsewhere. */ -static void cpl_column_log_cplsize(cpl_column *column, double base) +static void +cpl_column_log_cplsize(cpl_column *column, double base) { - - cpl_size nullcount = cpl_column_count_invalid(column); - cpl_size length = cpl_column_get_size(column); - cpl_size *lp = cpl_column_get_data_cplsize(column); - cpl_column_flag *np = cpl_column_get_data_invalid(column); - cpl_size i; - double invlog = 1 / log(base); + cpl_size nullcount = cpl_column_count_invalid(column); + cpl_size length = cpl_column_get_size(column); + cpl_size *lp = cpl_column_get_data_cplsize(column); + cpl_column_flag *np = cpl_column_get_data_invalid(column); + cpl_size i; + double invlog = 1 / log(base); if (nullcount == length) @@ -19963,15 +19093,15 @@ * that this was done elsewhere. */ -static void cpl_column_log_float(cpl_column *column, double base) +static void +cpl_column_log_float(cpl_column *column, double base) { - cpl_size nullcount = cpl_column_count_invalid(column); - cpl_size length = cpl_column_get_size(column); - float *fp = cpl_column_get_data_float(column); - int *np = cpl_column_get_data_invalid(column); + cpl_size length = cpl_column_get_size(column); + float *fp = cpl_column_get_data_float(column); + int *np = cpl_column_get_data_invalid(column); cpl_size i; - double invlog = 1 / log(base); + double invlog = 1 / log(base); if (nullcount == length) @@ -20012,15 +19142,15 @@ * that this was done elsewhere. */ -static void cpl_column_log_float_complex(cpl_column *column, double base) +static void +cpl_column_log_float_complex(cpl_column *column, double base) { - - cpl_size nullcount = cpl_column_count_invalid(column); - cpl_size length = cpl_column_get_size(column); - float complex *fp = cpl_column_get_data_float_complex(column); - int *np = cpl_column_get_data_invalid(column); - cpl_size i; - double invlog = 1 / log(base); + cpl_size nullcount = cpl_column_count_invalid(column); + cpl_size length = cpl_column_get_size(column); + float complex *fp = cpl_column_get_data_float_complex(column); + int *np = cpl_column_get_data_invalid(column); + cpl_size i; + double invlog = 1 / log(base); if (nullcount == length) @@ -20061,15 +19191,15 @@ * that this was done elsewhere. */ -static void cpl_column_log_double(cpl_column *column, double base) +static void +cpl_column_log_double(cpl_column *column, double base) { - cpl_size nullcount = cpl_column_count_invalid(column); - cpl_size length = cpl_column_get_size(column); - double *dp = cpl_column_get_data_double(column); - int *np = cpl_column_get_data_invalid(column); + cpl_size length = cpl_column_get_size(column); + double *dp = cpl_column_get_data_double(column); + int *np = cpl_column_get_data_invalid(column); cpl_size i; - double invlog = 1 / log(base); + double invlog = 1 / log(base); if (nullcount == length) @@ -20110,15 +19240,15 @@ * that this was done elsewhere. */ -static void cpl_column_log_double_complex(cpl_column *column, double base) +static void +cpl_column_log_double_complex(cpl_column *column, double base) { - - cpl_size nullcount = cpl_column_count_invalid(column); - cpl_size length = cpl_column_get_size(column); - double complex *dp = cpl_column_get_data_double_complex(column); - int *np = cpl_column_get_data_invalid(column); - cpl_size i; - double invlog = 1 / log(base); + cpl_size nullcount = cpl_column_count_invalid(column); + cpl_size length = cpl_column_get_size(column); + double complex *dp = cpl_column_get_data_double_complex(column); + int *np = cpl_column_get_data_invalid(column); + cpl_size i; + double invlog = 1 / log(base); if (nullcount == length) @@ -20159,13 +19289,13 @@ * that this was done elsewhere. */ -static void cpl_column_add_to_int(cpl_column *column, int value) +static void +cpl_column_add_to_int(cpl_column *column, int value) { - cpl_size nullcount = cpl_column_count_invalid(column); - cpl_size length = cpl_column_get_size(column); - int *ip = cpl_column_get_data_int(column); - int *np = cpl_column_get_data_invalid(column); + cpl_size length = cpl_column_get_size(column); + int *ip = cpl_column_get_data_int(column); + int *np = cpl_column_get_data_invalid(column); cpl_size i; @@ -20182,7 +19312,6 @@ for (i = 0; i < length; i++, ip++, np++) if (*np == 0) *ip += value; - } @@ -20201,14 +19330,14 @@ * that this was done elsewhere. */ -static void cpl_column_add_to_long(cpl_column *column, long value) +static void +cpl_column_add_to_long(cpl_column *column, long value) { - - cpl_size nullcount = cpl_column_count_invalid(column); - cpl_size length = cpl_column_get_size(column); - long *lp = cpl_column_get_data_long(column); - cpl_column_flag *np = cpl_column_get_data_invalid(column); - cpl_size i; + cpl_size nullcount = cpl_column_count_invalid(column); + cpl_size length = cpl_column_get_size(column); + long *lp = cpl_column_get_data_long(column); + cpl_column_flag *np = cpl_column_get_data_invalid(column); + cpl_size i; if (value == 0) @@ -20224,7 +19353,6 @@ for (i = 0; i < length; i++, lp++, np++) if (*np == 0) *lp += value; - } @@ -20243,14 +19371,14 @@ * that this was done elsewhere. */ -static void cpl_column_add_to_long_long(cpl_column *column, long long value) +static void +cpl_column_add_to_long_long(cpl_column *column, long long value) { - - cpl_size nullcount = cpl_column_count_invalid(column); - cpl_size length = cpl_column_get_size(column); - long long *lp = cpl_column_get_data_long_long(column); - cpl_column_flag *np = cpl_column_get_data_invalid(column); - cpl_size i; + cpl_size nullcount = cpl_column_count_invalid(column); + cpl_size length = cpl_column_get_size(column); + long long *lp = cpl_column_get_data_long_long(column); + cpl_column_flag *np = cpl_column_get_data_invalid(column); + cpl_size i; if (value == 0) @@ -20266,7 +19394,6 @@ for (i = 0; i < length; i++, lp++, np++) if (*np == 0) *lp += value; - } @@ -20284,14 +19411,14 @@ * that this was done elsewhere. */ -static void cpl_column_add_to_cplsize(cpl_column *column, cpl_size value) +static void +cpl_column_add_to_cplsize(cpl_column *column, cpl_size value) { - - cpl_size nullcount = cpl_column_count_invalid(column); - cpl_size length = cpl_column_get_size(column); - cpl_size *lp = cpl_column_get_data_cplsize(column); - cpl_column_flag *np = cpl_column_get_data_invalid(column); - cpl_size i; + cpl_size nullcount = cpl_column_count_invalid(column); + cpl_size length = cpl_column_get_size(column); + cpl_size *lp = cpl_column_get_data_cplsize(column); + cpl_column_flag *np = cpl_column_get_data_invalid(column); + cpl_size i; if (value == 0) @@ -20307,7 +19434,6 @@ for (i = 0; i < length; i++, lp++, np++) if (*np == 0) *lp += value; - } @@ -20323,15 +19449,15 @@ * This private function is just a way to compact the code of other * higher level functions. No check is performed on input, assuming * that this was done elsewhere. - */ + */ -static void cpl_column_add_to_float(cpl_column *column, double value) +static void +cpl_column_add_to_float(cpl_column *column, double value) { - cpl_size nullcount = cpl_column_count_invalid(column); - cpl_size length = cpl_column_get_size(column); - float *fp = cpl_column_get_data_float(column); - int *np = cpl_column_get_data_invalid(column); + cpl_size length = cpl_column_get_size(column); + float *fp = cpl_column_get_data_float(column); + int *np = cpl_column_get_data_invalid(column); cpl_size i; @@ -20341,14 +19467,13 @@ if (nullcount == length) return; - if (nullcount == 0) + if (nullcount == 0) for (i = 0; i < length; i++) *fp++ += value; else for (i = 0; i < length; i++, fp++, np++) if (*np == 0) *fp += value; - } @@ -20367,15 +19492,14 @@ * that this was done elsewhere. */ -static void cpl_column_add_to_float_complex(cpl_column *column, - double complex value) +static void +cpl_column_add_to_float_complex(cpl_column *column, double complex value) { - - cpl_size nullcount = cpl_column_count_invalid(column); - cpl_size length = cpl_column_get_size(column); - float complex *fp = cpl_column_get_data_float_complex(column); - int *np = cpl_column_get_data_invalid(column); - cpl_size i; + cpl_size nullcount = cpl_column_count_invalid(column); + cpl_size length = cpl_column_get_size(column); + float complex *fp = cpl_column_get_data_float_complex(column); + int *np = cpl_column_get_data_invalid(column); + cpl_size i; if (value == 0.0) @@ -20391,7 +19515,6 @@ for (i = 0; i < length; i++, fp++, np++) if (*np == 0) *fp += value; - } @@ -20409,13 +19532,13 @@ * that this was done elsewhere. */ -static void cpl_column_add_to_double(cpl_column *column, double value) +static void +cpl_column_add_to_double(cpl_column *column, double value) { - cpl_size nullcount = cpl_column_count_invalid(column); - cpl_size length = cpl_column_get_size(column); - double *dp = cpl_column_get_data_double(column); - int *np = cpl_column_get_data_invalid(column); + cpl_size length = cpl_column_get_size(column); + double *dp = cpl_column_get_data_double(column); + int *np = cpl_column_get_data_invalid(column); cpl_size i; @@ -20425,14 +19548,13 @@ if (nullcount == length) return; - if (nullcount == 0) + if (nullcount == 0) for (i = 0; i < length; i++) *dp++ += value; else for (i = 0; i < length; i++, dp++, np++) if (*np == 0) *dp += value; - } @@ -20451,15 +19573,14 @@ * that this was done elsewhere. */ -static void cpl_column_add_to_double_complex(cpl_column *column, - double complex value) +static void +cpl_column_add_to_double_complex(cpl_column *column, double complex value) { - - cpl_size nullcount = cpl_column_count_invalid(column); - cpl_size length = cpl_column_get_size(column); - double complex *dp = cpl_column_get_data_double_complex(column); - int *np = cpl_column_get_data_invalid(column); - cpl_size i; + cpl_size nullcount = cpl_column_count_invalid(column); + cpl_size length = cpl_column_get_size(column); + double complex *dp = cpl_column_get_data_double_complex(column); + int *np = cpl_column_get_data_invalid(column); + cpl_size i; if (value == 0.0) @@ -20475,7 +19596,6 @@ for (i = 0; i < length; i++, dp++, np++) if (*np == 0) *dp += value; - } @@ -20493,13 +19613,13 @@ * that this was done elsewhere. */ -static void cpl_column_mul_double_to_int(cpl_column *column, double value) +static void +cpl_column_mul_double_to_int(cpl_column *column, double value) { - cpl_size nullcount = cpl_column_count_invalid(column); - cpl_size length = cpl_column_get_size(column); - int *ip = cpl_column_get_data_int(column); - int *np = cpl_column_get_data_invalid(column); + cpl_size length = cpl_column_get_size(column); + int *ip = cpl_column_get_data_int(column); + int *np = cpl_column_get_data_invalid(column); cpl_size i; @@ -20516,7 +19636,6 @@ for (i = 0; i < length; i++, ip++, np++) if (*np == 0) *ip *= value; - } @@ -20535,14 +19654,14 @@ * that this was done elsewhere. */ -static void cpl_column_mul_double_to_long(cpl_column *column, double value) +static void +cpl_column_mul_double_to_long(cpl_column *column, double value) { - - cpl_size nullcount = cpl_column_count_invalid(column); - cpl_size length = cpl_column_get_size(column); - long *lp = cpl_column_get_data_long(column); - cpl_column_flag *np = cpl_column_get_data_invalid(column); - cpl_size i; + cpl_size nullcount = cpl_column_count_invalid(column); + cpl_size length = cpl_column_get_size(column); + long *lp = cpl_column_get_data_long(column); + cpl_column_flag *np = cpl_column_get_data_invalid(column); + cpl_size i; if (value == 1.0) @@ -20558,7 +19677,6 @@ for (i = 0; i < length; i++, lp++, np++) if (*np == 0) *lp *= value; - } @@ -20577,14 +19695,14 @@ * that this was done elsewhere. */ -static void cpl_column_mul_double_to_long_long(cpl_column *column, double value) +static void +cpl_column_mul_double_to_long_long(cpl_column *column, double value) { - - cpl_size nullcount = cpl_column_count_invalid(column); - cpl_size length = cpl_column_get_size(column); - long long *lp = cpl_column_get_data_long_long(column); - cpl_column_flag *np = cpl_column_get_data_invalid(column); - cpl_size i; + cpl_size nullcount = cpl_column_count_invalid(column); + cpl_size length = cpl_column_get_size(column); + long long *lp = cpl_column_get_data_long_long(column); + cpl_column_flag *np = cpl_column_get_data_invalid(column); + cpl_size i; if (value == 1.0) @@ -20600,7 +19718,6 @@ for (i = 0; i < length; i++, lp++, np++) if (*np == 0) *lp *= value; - } @@ -20619,14 +19736,14 @@ * that this was done elsewhere. */ -static void cpl_column_mul_double_to_cplsize(cpl_column *column, double value) +static void +cpl_column_mul_double_to_cplsize(cpl_column *column, double value) { - - cpl_size nullcount = cpl_column_count_invalid(column); - cpl_size length = cpl_column_get_size(column); - cpl_size *lp = cpl_column_get_data_cplsize(column); - cpl_column_flag *np = cpl_column_get_data_invalid(column); - cpl_size i; + cpl_size nullcount = cpl_column_count_invalid(column); + cpl_size length = cpl_column_get_size(column); + cpl_size *lp = cpl_column_get_data_cplsize(column); + cpl_column_flag *np = cpl_column_get_data_invalid(column); + cpl_size i; if (value == 1.0) @@ -20642,7 +19759,6 @@ for (i = 0; i < length; i++, lp++, np++) if (*np == 0) *lp *= value; - } @@ -20660,13 +19776,13 @@ * that this was done elsewhere. */ -static void cpl_column_mul_double_to_float(cpl_column *column, double value) +static void +cpl_column_mul_double_to_float(cpl_column *column, double value) { - cpl_size nullcount = cpl_column_count_invalid(column); - cpl_size length = cpl_column_get_size(column); - float *fp = cpl_column_get_data_float(column); - int *np = cpl_column_get_data_invalid(column); + cpl_size length = cpl_column_get_size(column); + float *fp = cpl_column_get_data_float(column); + int *np = cpl_column_get_data_invalid(column); cpl_size i; @@ -20683,19 +19799,17 @@ for (i = 0; i < length; i++, fp++, np++) if (*np == 0) *fp *= value; - } -static void cpl_column_mul_double_to_float_complex(cpl_column *column, - double complex value) +static void +cpl_column_mul_double_to_float_complex(cpl_column *column, double complex value) { - - cpl_size nullcount = cpl_column_count_invalid(column); - cpl_size length = cpl_column_get_size(column); - float complex *fp = cpl_column_get_data_float_complex(column); - int *np = cpl_column_get_data_invalid(column); - cpl_size i; + cpl_size nullcount = cpl_column_count_invalid(column); + cpl_size length = cpl_column_get_size(column); + float complex *fp = cpl_column_get_data_float_complex(column); + int *np = cpl_column_get_data_invalid(column); + cpl_size i; if (value == 1.0) @@ -20711,7 +19825,6 @@ for (i = 0; i < length; i++, fp++, np++) if (*np == 0) *fp *= value; - } @@ -20729,13 +19842,13 @@ * that this was done elsewhere. */ -static void cpl_column_mul_to_double(cpl_column *column, double value) +static void +cpl_column_mul_to_double(cpl_column *column, double value) { - cpl_size nullcount = cpl_column_count_invalid(column); - cpl_size length = cpl_column_get_size(column); - double *dp = cpl_column_get_data_double(column); - int *np = cpl_column_get_data_invalid(column); + cpl_size length = cpl_column_get_size(column); + double *dp = cpl_column_get_data_double(column); + int *np = cpl_column_get_data_invalid(column); cpl_size i; @@ -20752,7 +19865,6 @@ for (i = 0; i < length; i++, dp++, np++) if (*np == 0) *dp *= value; - } @@ -20771,15 +19883,14 @@ * that this was done elsewhere. */ -static void cpl_column_mul_to_double_complex(cpl_column *column, - double complex value) +static void +cpl_column_mul_to_double_complex(cpl_column *column, double complex value) { - - cpl_size nullcount = cpl_column_count_invalid(column); - cpl_size length = cpl_column_get_size(column); - double complex *dp = cpl_column_get_data_double_complex(column); - int *np = cpl_column_get_data_invalid(column); - cpl_size i; + cpl_size nullcount = cpl_column_count_invalid(column); + cpl_size length = cpl_column_get_size(column); + double complex *dp = cpl_column_get_data_double_complex(column); + int *np = cpl_column_get_data_invalid(column); + cpl_size i; if (value == 1.0) @@ -20795,7 +19906,6 @@ for (i = 0; i < length; i++, dp++, np++) if (*np == 0) *dp *= value; - } @@ -20818,10 +19928,10 @@ * not allowed. */ -cpl_error_code cpl_column_logarithm(cpl_column *column, double base) +cpl_error_code +cpl_column_logarithm(cpl_column *column, double base) { - - cpl_type type = cpl_column_get_type(column); + cpl_type type = cpl_column_get_type(column); if (column == NULL) @@ -20832,38 +19942,35 @@ switch (type) { - - case CPL_TYPE_INT: - cpl_column_log_int(column, base); - break; - case CPL_TYPE_LONG: - cpl_column_log_long(column, base); - break; - case CPL_TYPE_LONG_LONG: - cpl_column_log_long_long(column, base); - break; - case CPL_TYPE_SIZE: - cpl_column_log_cplsize(column, base); - break; - case CPL_TYPE_FLOAT: - cpl_column_log_float(column, base); - break; - case CPL_TYPE_DOUBLE: - cpl_column_log_double(column, base); - break; - case CPL_TYPE_FLOAT_COMPLEX: - cpl_column_log_float_complex(column, base); - break; - case CPL_TYPE_DOUBLE_COMPLEX: - cpl_column_log_double_complex(column, base); - break; - default: - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); - + case CPL_TYPE_INT: + cpl_column_log_int(column, base); + break; + case CPL_TYPE_LONG: + cpl_column_log_long(column, base); + break; + case CPL_TYPE_LONG_LONG: + cpl_column_log_long_long(column, base); + break; + case CPL_TYPE_SIZE: + cpl_column_log_cplsize(column, base); + break; + case CPL_TYPE_FLOAT: + cpl_column_log_float(column, base); + break; + case CPL_TYPE_DOUBLE: + cpl_column_log_double(column, base); + break; + case CPL_TYPE_FLOAT_COMPLEX: + cpl_column_log_float_complex(column, base); + break; + case CPL_TYPE_DOUBLE_COMPLEX: + cpl_column_log_double_complex(column, base); + break; + default: + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } return CPL_ERROR_NONE; - } @@ -20880,112 +19987,103 @@ * Columns of strings, or arrays, or complex, are not allowed. */ -cpl_error_code cpl_column_absolute(cpl_column *column) +cpl_error_code +cpl_column_absolute(cpl_column *column) { - - cpl_type type = cpl_column_get_type(column); - cpl_size length; - cpl_size nullcount; - cpl_size i; + cpl_type type = cpl_column_get_type(column); + cpl_size length; + cpl_size nullcount; + cpl_size i; if (column == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); switch (type) { - case CPL_TYPE_INT: - break; - case CPL_TYPE_LONG: - break; - case CPL_TYPE_LONG_LONG: - break; - case CPL_TYPE_FLOAT: - break; - case CPL_TYPE_DOUBLE: - break; - default: - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + case CPL_TYPE_INT: + break; + case CPL_TYPE_LONG: + break; + case CPL_TYPE_LONG_LONG: + break; + case CPL_TYPE_FLOAT: + break; + case CPL_TYPE_DOUBLE: + break; + default: + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } - length = cpl_column_get_size(column); + length = cpl_column_get_size(column); nullcount = cpl_column_count_invalid(column); if (nullcount == length) return CPL_ERROR_NONE; switch (type) { - - case CPL_TYPE_INT: - { - int *ip = cpl_column_get_data_int(column); - for (i = 0; i < length; i++, ip++) - *ip = abs(*ip); - break; - } - case CPL_TYPE_LONG: - { - long *lp = cpl_column_get_data_long(column); - for (i = 0; i < length; i++, lp++) - *lp = labs(*lp); - break; - } - case CPL_TYPE_LONG_LONG: - { - long long *lp = cpl_column_get_data_long_long(column); + case CPL_TYPE_INT: { + int *ip = cpl_column_get_data_int(column); + for (i = 0; i < length; i++, ip++) + *ip = abs(*ip); + break; + } + case CPL_TYPE_LONG: { + long *lp = cpl_column_get_data_long(column); + for (i = 0; i < length; i++, lp++) + *lp = labs(*lp); + break; + } + case CPL_TYPE_LONG_LONG: { + long long *lp = cpl_column_get_data_long_long(column); #if defined(HAVE_LLABS) && defined(HAVE_DECL_LLABS) - for (i = 0; i < length; i++, lp++) - *lp = llabs(*lp); + for (i = 0; i < length; i++, lp++) + *lp = llabs(*lp); #else - for (i = 0; i < length; i++, lp++) - *lp = *lp < 0LL ? -(*lp) : *lp; + for (i = 0; i < length; i++, lp++) + *lp = *lp < 0LL ? -(*lp) : *lp; #endif - break; - } - case CPL_TYPE_SIZE: - { - cpl_size *lp = cpl_column_get_data_cplsize(column); + break; + } + case CPL_TYPE_SIZE: { + cpl_size *lp = cpl_column_get_data_cplsize(column); #if defined(HAVE_LLABS) && defined(HAVE_DECL_LLABS) - for (i = 0; i < length; i++, lp++) - *lp = llabs(*lp); + for (i = 0; i < length; i++, lp++) + *lp = llabs(*lp); #else - for (i = 0; i < length; i++, lp++) - *lp = *lp < 0LL ? -(*lp) : *lp; + for (i = 0; i < length; i++, lp++) + *lp = *lp < 0LL ? -(*lp) : *lp; #endif - break; - } - case CPL_TYPE_FLOAT: - { - float *fp = cpl_column_get_data_float(column); - for (i = 0; i < length; i++, fp++) - *fp = fabsf(*fp); - break; - } - case CPL_TYPE_DOUBLE: - { - double *dp = cpl_column_get_data_double(column); - for (i = 0; i < length; i++, dp++) - *dp = fabs(*dp); - break; - } - default: - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); - + break; + } + case CPL_TYPE_FLOAT: { + float *fp = cpl_column_get_data_float(column); + for (i = 0; i < length; i++, fp++) + *fp = fabsf(*fp); + break; + } + case CPL_TYPE_DOUBLE: { + double *dp = cpl_column_get_data_double(column); + for (i = 0; i < length; i++, dp++) + *dp = fabs(*dp); + break; + } + default: + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } return CPL_ERROR_NONE; - } @@ -21001,14 +20099,14 @@ * Columns of strings, of integers, or arrays, are not allowed. */ -cpl_column *cpl_column_absolute_complex(cpl_column *column) +cpl_column * +cpl_column_absolute_complex(cpl_column *column) { - - cpl_type type = cpl_column_get_type(column); - cpl_column *new_column; - cpl_size length; - cpl_size nullcount; - cpl_size i; + cpl_type type = cpl_column_get_type(column); + cpl_column *new_column; + cpl_size length; + cpl_size nullcount; + cpl_size i; if (column == NULL) { @@ -21044,9 +20142,7 @@ } switch (type) { - - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *cfp = cpl_column_get_data_float_complex(column); float *fp = cpl_column_get_data_float(new_column); @@ -21054,8 +20150,7 @@ *fp = cabsf(*cfp); break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *cdp = cpl_column_get_data_double_complex(column); double *dp = cpl_column_get_data_double(new_column); @@ -21063,17 +20158,14 @@ *dp = cabs(*cdp); break; } - default: - { + default: { cpl_error_set_(CPL_ERROR_INVALID_TYPE); cpl_column_delete(new_column); return NULL; } - } return new_column; - } @@ -21090,14 +20182,14 @@ * Columns of strings, of integers, or arrays, are not allowed. */ -cpl_column *cpl_column_phase_complex(cpl_column *column) +cpl_column * +cpl_column_phase_complex(cpl_column *column) { - - cpl_type type = cpl_column_get_type(column); - cpl_column *new_column; - cpl_size length; - cpl_size nullcount; - cpl_size i; + cpl_type type = cpl_column_get_type(column); + cpl_column *new_column; + cpl_size length; + cpl_size nullcount; + cpl_size i; if (column == NULL) { @@ -21133,9 +20225,7 @@ } switch (type) { - - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *cfp = cpl_column_get_data_float_complex(column); float *fp = cpl_column_get_data_float(new_column); @@ -21143,8 +20233,7 @@ *fp = cargf(*cfp); break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *cdp = cpl_column_get_data_double_complex(column); double *dp = cpl_column_get_data_double(new_column); @@ -21152,17 +20241,14 @@ *dp = carg(*cdp); break; } - default: - { + default: { cpl_error_set_(CPL_ERROR_INVALID_TYPE); cpl_column_delete(new_column); return NULL; } - } return new_column; - } @@ -21178,14 +20264,14 @@ * Columns of strings, integers, or arrays, are not allowed. */ -cpl_column *cpl_column_extract_real(const cpl_column *self) +cpl_column * +cpl_column_extract_real(const cpl_column *self) { - - const cpl_type type = cpl_column_get_type(self); - cpl_column *new_column; - cpl_size length; - cpl_size nullcount; - cpl_size i; + const cpl_type type = cpl_column_get_type(self); + cpl_column *new_column; + cpl_size length; + cpl_size nullcount; + cpl_size i; if (self == NULL) { @@ -21216,43 +20302,36 @@ if (self->null) { new_column->null = cpl_malloc(length * sizeof(cpl_column_flag)); - memcpy(new_column->null, self->null, - length * sizeof(cpl_column_flag)); + memcpy(new_column->null, self->null, length * sizeof(cpl_column_flag)); } switch (type) { - - case CPL_TYPE_FLOAT_COMPLEX: - { - const float complex *cfp - = cpl_column_get_data_float_complex_const(self); + case CPL_TYPE_FLOAT_COMPLEX: { + const float complex *cfp = + cpl_column_get_data_float_complex_const(self); float *fp = cpl_column_get_data_float(new_column); for (i = 0; i < length; i++, fp++, cfp++) *fp = crealf(*cfp); break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { - const double complex *cdp - = cpl_column_get_data_double_complex_const(self); + case CPL_TYPE_DOUBLE_COMPLEX: { + const double complex *cdp = + cpl_column_get_data_double_complex_const(self); double *dp = cpl_column_get_data_double(new_column); for (i = 0; i < length; i++, dp++, cdp++) *dp = creal(*cdp); break; } - default: - { + default: { cpl_error_set_(CPL_ERROR_INVALID_TYPE); cpl_column_delete(new_column); return NULL; } - } return new_column; - } @@ -21268,14 +20347,14 @@ * Columns of strings, integers, or arrays, are not allowed. */ -cpl_column *cpl_column_extract_imag(const cpl_column *self) +cpl_column * +cpl_column_extract_imag(const cpl_column *self) { - - cpl_type type = cpl_column_get_type(self); - cpl_column *new_column; - cpl_size length; - cpl_size nullcount; - cpl_size i; + cpl_type type = cpl_column_get_type(self); + cpl_column *new_column; + cpl_size length; + cpl_size nullcount; + cpl_size i; if (self == NULL) { @@ -21306,43 +20385,36 @@ if (self->null) { new_column->null = cpl_malloc(length * sizeof(cpl_column_flag)); - memcpy(new_column->null, self->null, - length * sizeof(cpl_column_flag)); + memcpy(new_column->null, self->null, length * sizeof(cpl_column_flag)); } switch (type) { - - case CPL_TYPE_FLOAT_COMPLEX: - { - const float complex *cfp - = cpl_column_get_data_float_complex_const(self); + case CPL_TYPE_FLOAT_COMPLEX: { + const float complex *cfp = + cpl_column_get_data_float_complex_const(self); float *fp = cpl_column_get_data_float(new_column); for (i = 0; i < length; i++, fp++, cfp++) *fp = cimagf(*cfp); break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { - const double complex *cdp - = cpl_column_get_data_double_complex_const(self); + case CPL_TYPE_DOUBLE_COMPLEX: { + const double complex *cdp = + cpl_column_get_data_double_complex_const(self); double *dp = cpl_column_get_data_double(new_column); for (i = 0; i < length; i++, dp++, cdp++) *dp = cimag(*cdp); break; } - default: - { + default: { cpl_error_set_(CPL_ERROR_INVALID_TYPE); cpl_column_delete(new_column); return NULL; } - } return new_column; - } @@ -21364,10 +20436,10 @@ * arrays are not allowed. */ -cpl_error_code cpl_column_exponential(cpl_column *column, double base) +cpl_error_code +cpl_column_exponential(cpl_column *column, double base) { - - cpl_type type = cpl_column_get_type(column); + cpl_type type = cpl_column_get_type(column); if (column == NULL) @@ -21378,7 +20450,6 @@ switch (type) { - case CPL_TYPE_INT: cpl_column_exp_int(column, base); break; @@ -21405,25 +20476,22 @@ break; default: return cpl_error_set_(CPL_ERROR_INVALID_TYPE); - } return CPL_ERROR_NONE; - } -cpl_error_code cpl_column_conjugate(cpl_column *column) +cpl_error_code +cpl_column_conjugate(cpl_column *column) { - - cpl_type type = cpl_column_get_type(column); + cpl_type type = cpl_column_get_type(column); if (column == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); - - switch (type) { + switch (type) { case CPL_TYPE_FLOAT: case CPL_TYPE_DOUBLE: break; @@ -21435,11 +20503,9 @@ break; default: return cpl_error_set_(CPL_ERROR_INVALID_TYPE); - } return CPL_ERROR_NONE; - } @@ -21461,47 +20527,46 @@ * not allowed. */ -cpl_error_code cpl_column_power(cpl_column *column, double exponent) +cpl_error_code +cpl_column_power(cpl_column *column, double exponent) { if (column == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); - } else { + } + else { const cpl_type type = cpl_column_get_type(column); switch (type) { - - case CPL_TYPE_INT: - cpl_column_pow_int(column, exponent); - break; - case CPL_TYPE_LONG: - cpl_column_pow_long(column, exponent); - break; - case CPL_TYPE_LONG_LONG: - cpl_column_pow_long_long(column, exponent); - break; - case CPL_TYPE_SIZE: - cpl_column_pow_cplsize(column, exponent); - break; - case CPL_TYPE_FLOAT: - cpl_column_pow_float(column, exponent); - break; - case CPL_TYPE_DOUBLE: - cpl_column_pow_double(column, exponent); - break; - case CPL_TYPE_FLOAT_COMPLEX: - cpl_column_pow_float_complex(column, exponent); - break; - case CPL_TYPE_DOUBLE_COMPLEX: - cpl_column_pow_double_complex(column, exponent); - break; - default: - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); - + case CPL_TYPE_INT: + cpl_column_pow_int(column, exponent); + break; + case CPL_TYPE_LONG: + cpl_column_pow_long(column, exponent); + break; + case CPL_TYPE_LONG_LONG: + cpl_column_pow_long_long(column, exponent); + break; + case CPL_TYPE_SIZE: + cpl_column_pow_cplsize(column, exponent); + break; + case CPL_TYPE_FLOAT: + cpl_column_pow_float(column, exponent); + break; + case CPL_TYPE_DOUBLE: + cpl_column_pow_double(column, exponent); + break; + case CPL_TYPE_FLOAT_COMPLEX: + cpl_column_pow_float_complex(column, exponent); + break; + case CPL_TYPE_DOUBLE_COMPLEX: + cpl_column_pow_double_complex(column, exponent); + break; + default: + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } } return CPL_ERROR_NONE; - } @@ -21522,33 +20587,32 @@ * invalid. Columns of strings or arrays are not allowed. */ -cpl_error_code cpl_column_power_complex(cpl_column *column, - double complex exponent) +cpl_error_code +cpl_column_power_complex(cpl_column *column, double complex exponent) { if (column == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); - } else if (exponent != (double)exponent) { + } + else if (exponent != (double)exponent) { /* Only call complex version when needed */ const cpl_type type = cpl_column_get_type(column); switch (type) { - - case CPL_TYPE_FLOAT_COMPLEX: - cpl_column_cpow_float_complex(column, exponent); - break; - case CPL_TYPE_DOUBLE_COMPLEX: - cpl_column_cpow_double_complex(column, exponent); - break; - default: - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); - + case CPL_TYPE_FLOAT_COMPLEX: + cpl_column_cpow_float_complex(column, exponent); + break; + case CPL_TYPE_DOUBLE_COMPLEX: + cpl_column_cpow_double_complex(column, exponent); + break; + default: + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } - } else if (cpl_column_power(column, (double)exponent)) { + } + else if (cpl_column_power(column, (double)exponent)) { return cpl_error_set_where_(); } return CPL_ERROR_NONE; - } @@ -21568,10 +20632,10 @@ * modified by this operation. Columns of strings or arrays are not allowed. */ -cpl_error_code cpl_column_add_scalar(cpl_column *column, double value) +cpl_error_code +cpl_column_add_scalar(cpl_column *column, double value) { - - cpl_type type = cpl_column_get_type(column); + cpl_type type = cpl_column_get_type(column); if (column == NULL) @@ -21579,7 +20643,6 @@ switch (type) { - case CPL_TYPE_INT: cpl_column_add_to_int(column, value); break; @@ -21606,19 +20669,16 @@ break; default: return cpl_error_set_(CPL_ERROR_INVALID_TYPE); - } return CPL_ERROR_NONE; - } -cpl_error_code cpl_column_add_scalar_complex(cpl_column *column, - double complex value) +cpl_error_code +cpl_column_add_scalar_complex(cpl_column *column, double complex value) { - - cpl_type type = cpl_column_get_type(column); + cpl_type type = cpl_column_get_type(column); if (column == NULL) @@ -21626,7 +20686,6 @@ switch (type) { - case CPL_TYPE_FLOAT: cpl_column_add_to_float(column, value); break; @@ -21641,11 +20700,9 @@ break; default: return cpl_error_set_(CPL_ERROR_INVALID_TYPE); - } return CPL_ERROR_NONE; - } @@ -21665,19 +20722,16 @@ * modified by this operation. Columns of strings or arrays are not allowed. */ -cpl_error_code cpl_column_subtract_scalar(cpl_column *column, double value) +cpl_error_code +cpl_column_subtract_scalar(cpl_column *column, double value) { - return cpl_column_add_scalar(column, -value); - } -cpl_error_code cpl_column_subtract_scalar_complex(cpl_column *column, - double complex value) +cpl_error_code +cpl_column_subtract_scalar_complex(cpl_column *column, double complex value) { - return cpl_column_add_scalar_complex(column, -value); - } @@ -21697,10 +20751,10 @@ * modified by this operation. Columns of strings or arrays are not allowed. */ -cpl_error_code cpl_column_multiply_scalar(cpl_column *column, double value) +cpl_error_code +cpl_column_multiply_scalar(cpl_column *column, double value) { - - cpl_type type = cpl_column_get_type(column); + cpl_type type = cpl_column_get_type(column); if (column == NULL) @@ -21708,7 +20762,6 @@ switch (type) { - case CPL_TYPE_INT: cpl_column_mul_double_to_int(column, value); break; @@ -21735,19 +20788,16 @@ break; default: return cpl_error_set_(CPL_ERROR_INVALID_TYPE); - } return CPL_ERROR_NONE; - } -cpl_error_code cpl_column_multiply_scalar_complex(cpl_column *column, - double complex value) +cpl_error_code +cpl_column_multiply_scalar_complex(cpl_column *column, double complex value) { - - cpl_type type = cpl_column_get_type(column); + cpl_type type = cpl_column_get_type(column); if (column == NULL) @@ -21755,7 +20805,6 @@ switch (type) { - case CPL_TYPE_FLOAT: cpl_column_mul_double_to_float(column, value); break; @@ -21770,11 +20819,9 @@ break; default: return cpl_error_set_(CPL_ERROR_INVALID_TYPE); - } return CPL_ERROR_NONE; - } @@ -21795,12 +20842,12 @@ * modified by this operation. Columns of strings or arrays are not allowed. */ -cpl_error_code cpl_column_divide_scalar(cpl_column *column, double value) +cpl_error_code +cpl_column_divide_scalar(cpl_column *column, double value) { + cpl_type type = cpl_column_get_type(column); - cpl_type type = cpl_column_get_type(column); - if (column == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -21811,7 +20858,6 @@ value = 1 / value; switch (type) { - case CPL_TYPE_INT: cpl_column_mul_double_to_int(column, value); break; @@ -21838,19 +20884,16 @@ break; default: return cpl_error_set_(CPL_ERROR_INVALID_TYPE); - } return CPL_ERROR_NONE; - } -cpl_error_code cpl_column_divide_scalar_complex(cpl_column *column, - double complex value) +cpl_error_code +cpl_column_divide_scalar_complex(cpl_column *column, double complex value) { - - cpl_type type = cpl_column_get_type(column); + cpl_type type = cpl_column_get_type(column); if (column == NULL) @@ -21863,7 +20906,6 @@ value = 1 / value; switch (type) { - case CPL_TYPE_FLOAT: cpl_column_mul_double_to_float(column, value); break; @@ -21878,11 +20920,9 @@ break; default: return cpl_error_set_(CPL_ERROR_INVALID_TYPE); - } return CPL_ERROR_NONE; - } @@ -21904,18 +20944,18 @@ * arrays are not allowed. */ -double cpl_column_get_mean(const cpl_column *column) +double +cpl_column_get_mean(const cpl_column *column) { + cpl_size length = cpl_column_get_size(column); + cpl_size nullcount = cpl_column_count_invalid_const(column); + cpl_type type = cpl_column_get_type(column); + double mean = 0.0; + cpl_size count = length - nullcount; + cpl_size i; + int *np; - cpl_size length = cpl_column_get_size(column); - cpl_size nullcount = cpl_column_count_invalid_const(column); - cpl_type type = cpl_column_get_type(column); - double mean = 0.0; - cpl_size count = length - nullcount; - cpl_size i; - int *np; - if (column == NULL) { cpl_error_set_where_(); return 0.0; @@ -21930,9 +20970,7 @@ np = column->null; switch (type) { - - case CPL_TYPE_INT: - { + case CPL_TYPE_INT: { int *ip = column->values->i; if (nullcount == 0) @@ -21944,8 +20982,7 @@ mean += *ip; break; } - case CPL_TYPE_LONG: - { + case CPL_TYPE_LONG: { long *lp = column->values->l; if (nullcount == 0) @@ -21957,8 +20994,7 @@ mean += *lp; break; } - case CPL_TYPE_LONG_LONG: - { + case CPL_TYPE_LONG_LONG: { long long *lp = column->values->ll; if (nullcount == 0) @@ -21970,8 +21006,7 @@ mean += *lp; break; } - case CPL_TYPE_SIZE: - { + case CPL_TYPE_SIZE: { cpl_size *lp = column->values->sz; if (nullcount == 0) @@ -21983,8 +21018,7 @@ mean += *lp; break; } - case CPL_TYPE_FLOAT: - { + case CPL_TYPE_FLOAT: { float *fp = column->values->f; if (nullcount == 0) @@ -21996,8 +21030,7 @@ mean += *fp; break; } - case CPL_TYPE_DOUBLE: - { + case CPL_TYPE_DOUBLE: { double *dp = column->values->d; if (nullcount == 0) @@ -22012,28 +21045,26 @@ default: cpl_error_set_(CPL_ERROR_INVALID_TYPE); break; - } return (mean / count); - } /* It works with numeric types too... */ -double complex cpl_column_get_mean_complex(const cpl_column *column) +double complex +cpl_column_get_mean_complex(const cpl_column *column) { + cpl_size length = cpl_column_get_size(column); + cpl_size nullcount = cpl_column_count_invalid_const(column); + cpl_type type = cpl_column_get_type(column); + double complex mean = 0.0; + cpl_size count = length - nullcount; + cpl_size i; + int *np; - cpl_size length = cpl_column_get_size(column); - cpl_size nullcount = cpl_column_count_invalid_const(column); - cpl_type type = cpl_column_get_type(column); - double complex mean = 0.0; - cpl_size count = length - nullcount; - cpl_size i; - int *np; - if (column == NULL) { cpl_error_set_where_(); return 0.0; @@ -22048,9 +21079,7 @@ np = column->null; switch (type) { - - case CPL_TYPE_INT: - { + case CPL_TYPE_INT: { int *ip = column->values->i; if (nullcount == 0) @@ -22062,8 +21091,7 @@ mean += *ip; break; } - case CPL_TYPE_LONG: - { + case CPL_TYPE_LONG: { long *lp = column->values->l; if (nullcount == 0) @@ -22075,8 +21103,7 @@ mean += *lp; break; } - case CPL_TYPE_LONG_LONG: - { + case CPL_TYPE_LONG_LONG: { long long *lp = column->values->ll; if (nullcount == 0) @@ -22088,8 +21115,7 @@ mean += *lp; break; } - case CPL_TYPE_SIZE: - { + case CPL_TYPE_SIZE: { cpl_size *lp = column->values->sz; if (nullcount == 0) @@ -22101,8 +21127,7 @@ mean += *lp; break; } - case CPL_TYPE_FLOAT: - { + case CPL_TYPE_FLOAT: { float *fp = column->values->f; if (nullcount == 0) @@ -22114,8 +21139,7 @@ mean += *fp; break; } - case CPL_TYPE_DOUBLE: - { + case CPL_TYPE_DOUBLE: { double *dp = column->values->d; if (nullcount == 0) @@ -22127,8 +21151,7 @@ mean += *dp; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex *cfp = column->values->cf; if (nullcount == 0) @@ -22140,8 +21163,7 @@ mean += *cfp; break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex *cdp = column->values->cd; if (nullcount == 0) @@ -22156,26 +21178,24 @@ default: cpl_error_set_(CPL_ERROR_INVALID_TYPE); break; - } return (mean / count); - } -double cpl_column_get_stdev(const cpl_column *column) +double +cpl_column_get_stdev(const cpl_column *column) { - - cpl_size length = cpl_column_get_size(column); - cpl_size nullcount = cpl_column_count_invalid_const(column); - cpl_type type = cpl_column_get_type(column); - double stdev = 0.0; - double mean; - double delta; - cpl_size count = length - nullcount; - cpl_size i; - int *np; + cpl_size length = cpl_column_get_size(column); + cpl_size nullcount = cpl_column_count_invalid_const(column); + cpl_type type = cpl_column_get_type(column); + double stdev = 0.0; + double mean; + double delta; + cpl_size count = length - nullcount; + cpl_size i; + int *np; if (column == NULL) { @@ -22190,14 +21210,12 @@ } if (count == 1) - return 0.0; + return 0.0; np = column->null; switch (type) { - - case CPL_TYPE_INT: - { + case CPL_TYPE_INT: { int *ip = column->values->i; if (nullcount == 0) @@ -22215,8 +21233,7 @@ break; } - case CPL_TYPE_LONG: - { + case CPL_TYPE_LONG: { long *lp = column->values->l; if (nullcount == 0) @@ -22234,8 +21251,7 @@ break; } - case CPL_TYPE_LONG_LONG: - { + case CPL_TYPE_LONG_LONG: { long long *lp = column->values->ll; if (nullcount == 0) @@ -22253,8 +21269,7 @@ break; } - case CPL_TYPE_SIZE: - { + case CPL_TYPE_SIZE: { cpl_size *lp = column->values->sz; if (nullcount == 0) @@ -22272,8 +21287,7 @@ break; } - case CPL_TYPE_FLOAT: - { + case CPL_TYPE_FLOAT: { float *fp = column->values->f; if (nullcount == 0) @@ -22291,8 +21305,7 @@ break; } - case CPL_TYPE_DOUBLE: - { + case CPL_TYPE_DOUBLE: { double *dp = column->values->d; if (nullcount == 0) @@ -22313,11 +21326,9 @@ default: cpl_error_set_(CPL_ERROR_INVALID_TYPE); break; - } return sqrt(stdev / (count - 1)); - } @@ -22339,16 +21350,16 @@ * arrays are not allowed. */ -double cpl_column_get_max(const cpl_column *column) +double +cpl_column_get_max(const cpl_column *column) { - - cpl_size length = cpl_column_get_size(column); - cpl_size nullcount = cpl_column_count_invalid_const(column); - cpl_type type = cpl_column_get_type(column); - int first = 1; - int *np; - double maximum = 0; - cpl_size i; + cpl_size length = cpl_column_get_size(column); + cpl_size nullcount = cpl_column_count_invalid_const(column); + cpl_type type = cpl_column_get_type(column); + int first = 1; + int *np; + double maximum = 0; + cpl_size i; if (column == NULL) { @@ -22364,8 +21375,7 @@ np = column->null; switch (type) { - case CPL_TYPE_INT: - { + case CPL_TYPE_INT: { int *ip = column->values->i; if (length == 1) @@ -22383,16 +21393,14 @@ first = 0; maximum = *ip; } - else - if (maximum < *ip) - maximum = *ip; + else if (maximum < *ip) + maximum = *ip; } } } break; } - case CPL_TYPE_LONG: - { + case CPL_TYPE_LONG: { long *lp = column->values->l; if (length == 1) @@ -22410,16 +21418,14 @@ first = 0; maximum = *lp; } - else - if (maximum < *lp) - maximum = *lp; + else if (maximum < *lp) + maximum = *lp; } } } break; } - case CPL_TYPE_LONG_LONG: - { + case CPL_TYPE_LONG_LONG: { long long *lp = column->values->ll; if (length == 1) @@ -22437,16 +21443,14 @@ first = 0; maximum = *lp; } - else - if (maximum < *lp) - maximum = *lp; + else if (maximum < *lp) + maximum = *lp; } } } break; } - case CPL_TYPE_SIZE: - { + case CPL_TYPE_SIZE: { cpl_size *lp = column->values->sz; if (length == 1) @@ -22464,16 +21468,14 @@ first = 0; maximum = *lp; } - else - if (maximum < *lp) - maximum = *lp; + else if (maximum < *lp) + maximum = *lp; } } } break; } - case CPL_TYPE_FLOAT: - { + case CPL_TYPE_FLOAT: { float *fp = column->values->f; if (length == 1) @@ -22491,16 +21493,14 @@ first = 0; maximum = *fp; } - else - if (maximum < *fp) - maximum = *fp; + else if (maximum < *fp) + maximum = *fp; } } } break; } - case CPL_TYPE_DOUBLE: - { + case CPL_TYPE_DOUBLE: { double *dp = column->values->d; if (length == 1) @@ -22518,9 +21518,8 @@ first = 0; maximum = *dp; } - else - if (maximum < *dp) - maximum = *dp; + else if (maximum < *dp) + maximum = *dp; } } } @@ -22532,7 +21531,6 @@ } return maximum; - } @@ -22552,18 +21550,18 @@ * Column values marked as invalid are excluded from the search. * The column must contain at least one valid value. Columns of strings or * arrays are not allowed. - */ + */ -double cpl_column_get_min(const cpl_column *column) +double +cpl_column_get_min(const cpl_column *column) { - - cpl_size length = cpl_column_get_size(column); - cpl_size nullcount = cpl_column_count_invalid_const(column); - cpl_type type = cpl_column_get_type(column); - int first = 1; - int *np; - double minimum = 0; - cpl_size i; + cpl_size length = cpl_column_get_size(column); + cpl_size nullcount = cpl_column_count_invalid_const(column); + cpl_type type = cpl_column_get_type(column); + int first = 1; + int *np; + double minimum = 0; + cpl_size i; if (column == NULL) { @@ -22579,8 +21577,7 @@ np = column->null; switch (type) { - case CPL_TYPE_INT: - { + case CPL_TYPE_INT: { int *ip = column->values->i; if (length == 1) @@ -22598,16 +21595,14 @@ first = 0; minimum = *ip; } - else - if (minimum > *ip) - minimum = *ip; + else if (minimum > *ip) + minimum = *ip; } } } break; } - case CPL_TYPE_LONG: - { + case CPL_TYPE_LONG: { long *lp = column->values->l; if (length == 1) @@ -22625,16 +21620,14 @@ first = 0; minimum = *lp; } - else - if (minimum > *lp) - minimum = *lp; + else if (minimum > *lp) + minimum = *lp; } } } break; } - case CPL_TYPE_LONG_LONG: - { + case CPL_TYPE_LONG_LONG: { long long *lp = column->values->ll; if (length == 1) @@ -22652,16 +21645,14 @@ first = 0; minimum = *lp; } - else - if (minimum > *lp) - minimum = *lp; + else if (minimum > *lp) + minimum = *lp; } } } break; } - case CPL_TYPE_SIZE: - { + case CPL_TYPE_SIZE: { cpl_size *lp = column->values->sz; if (length == 1) @@ -22679,16 +21670,14 @@ first = 0; minimum = *lp; } - else - if (minimum > *lp) - minimum = *lp; + else if (minimum > *lp) + minimum = *lp; } } } break; } - case CPL_TYPE_FLOAT: - { + case CPL_TYPE_FLOAT: { float *fp = column->values->f; if (length == 1) @@ -22706,16 +21695,14 @@ first = 0; minimum = *fp; } - else - if (minimum > *fp) - minimum = *fp; + else if (minimum > *fp) + minimum = *fp; } } } break; } - case CPL_TYPE_DOUBLE: - { + case CPL_TYPE_DOUBLE: { double *dp = column->values->d; if (length == 1) @@ -22733,9 +21720,8 @@ first = 0; minimum = *dp; } - else - if (minimum > *dp) - minimum = *dp; + else if (minimum > *dp) + minimum = *dp; } } } @@ -22747,7 +21733,6 @@ } return minimum; - } @@ -22771,18 +21756,18 @@ * element correspond to the max value, the position with the lowest * indx is returned. In case of error, @em indx is set to zero. * Columns of strings or arrays are not allowed. - */ - -cpl_error_code cpl_column_get_maxpos(const cpl_column *column, cpl_size *indx) -{ + */ - cpl_size length = cpl_column_get_size(column); - cpl_size nullcount = cpl_column_count_invalid_const(column); - cpl_type type = cpl_column_get_type(column); - int first = 1; - int *np; - double maximum = 0; - cpl_size i; +cpl_error_code +cpl_column_get_maxpos(const cpl_column *column, cpl_size *indx) +{ + cpl_size length = cpl_column_get_size(column); + cpl_size nullcount = cpl_column_count_invalid_const(column); + cpl_type type = cpl_column_get_type(column); + int first = 1; + int *np; + double maximum = 0; + cpl_size i; if (column == NULL || indx == NULL) @@ -22799,8 +21784,7 @@ np = column->null; switch (type) { - case CPL_TYPE_INT: - { + case CPL_TYPE_INT: { int *ip = column->values->i; if (nullcount == 0) { @@ -22831,8 +21815,7 @@ } break; } - case CPL_TYPE_LONG: - { + case CPL_TYPE_LONG: { long *lp = column->values->l; if (nullcount == 0) { @@ -22863,8 +21846,7 @@ } break; } - case CPL_TYPE_LONG_LONG: - { + case CPL_TYPE_LONG_LONG: { long long *lp = column->values->ll; if (nullcount == 0) { @@ -22895,8 +21877,7 @@ } break; } - case CPL_TYPE_SIZE: - { + case CPL_TYPE_SIZE: { cpl_size *lp = column->values->sz; if (nullcount == 0) { @@ -22927,8 +21908,7 @@ } break; } - case CPL_TYPE_FLOAT: - { + case CPL_TYPE_FLOAT: { float *fp = column->values->f; if (nullcount == 0) { @@ -22959,8 +21939,7 @@ } break; } - case CPL_TYPE_DOUBLE: - { + case CPL_TYPE_DOUBLE: { double *dp = column->values->d; if (nullcount == 0) { @@ -22996,7 +21975,6 @@ } return CPL_ERROR_NONE; - } @@ -23022,16 +22000,16 @@ * Columns of strings or arrays are not allowed. */ -cpl_error_code cpl_column_get_minpos(const cpl_column *column, cpl_size *indx) +cpl_error_code +cpl_column_get_minpos(const cpl_column *column, cpl_size *indx) { - - cpl_size length = cpl_column_get_size(column); - cpl_size nullcount = cpl_column_count_invalid_const(column); - cpl_type type = cpl_column_get_type(column); - int first = 1; - int *np; - double minimum = 0; - cpl_size i; + cpl_size length = cpl_column_get_size(column); + cpl_size nullcount = cpl_column_count_invalid_const(column); + cpl_type type = cpl_column_get_type(column); + int first = 1; + int *np; + double minimum = 0; + cpl_size i; if (column == NULL || indx == NULL) @@ -23048,8 +22026,7 @@ np = column->null; switch (type) { - case CPL_TYPE_INT: - { + case CPL_TYPE_INT: { int *ip = column->values->i; if (nullcount == 0) { @@ -23080,8 +22057,7 @@ } break; } - case CPL_TYPE_LONG: - { + case CPL_TYPE_LONG: { long *lp = column->values->l; if (nullcount == 0) { @@ -23112,8 +22088,7 @@ } break; } - case CPL_TYPE_LONG_LONG: - { + case CPL_TYPE_LONG_LONG: { long long *lp = column->values->ll; if (nullcount == 0) { @@ -23144,8 +22119,7 @@ } break; } - case CPL_TYPE_SIZE: - { + case CPL_TYPE_SIZE: { cpl_size *lp = column->values->sz; if (nullcount == 0) { @@ -23176,8 +22150,7 @@ } break; } - case CPL_TYPE_FLOAT: - { + case CPL_TYPE_FLOAT: { float *fp = column->values->f; if (nullcount == 0) { @@ -23208,8 +22181,7 @@ } break; } - case CPL_TYPE_DOUBLE: - { + case CPL_TYPE_DOUBLE: { double *dp = column->values->d; if (nullcount == 0) { @@ -23245,7 +22217,6 @@ } return CPL_ERROR_NONE; - } @@ -23263,17 +22234,17 @@ * arrays are not allowed. */ -static int cpl_column_median_int(const cpl_column *column) +static int +cpl_column_median_int(const cpl_column *column) { - - cpl_size length = cpl_column_get_size(column); + cpl_size length = cpl_column_get_size(column); cpl_size nullcount = cpl_column_count_invalid_const(column); - int median = 0; + int median = 0; cpl_size i, n; - int *np; - int *ip; - int *cip; - int *copybuf; + int *np; + int *ip; + int *cip; + int *copybuf; n = length - nullcount; @@ -23296,7 +22267,6 @@ cpl_free(copybuf); return median; - } @@ -23314,17 +22284,17 @@ * arrays are not allowed. */ -static long cpl_column_median_long(const cpl_column *column) +static long +cpl_column_median_long(const cpl_column *column) { - - cpl_size length = cpl_column_get_size(column); + cpl_size length = cpl_column_get_size(column); cpl_size nullcount = cpl_column_count_invalid_const(column); - long median = 0; + long median = 0; cpl_size i, n; - int *np; - long *lp; - long *clp; - long *copybuf; + int *np; + long *lp; + long *clp; + long *copybuf; n = length - nullcount; @@ -23347,7 +22317,6 @@ cpl_free(copybuf); return median; - } @@ -23365,17 +22334,17 @@ * arrays are not allowed. */ -static long long cpl_column_median_long_long(const cpl_column *column) +static long long +cpl_column_median_long_long(const cpl_column *column) { - - cpl_size length = cpl_column_get_size(column); + cpl_size length = cpl_column_get_size(column); cpl_size nullcount = cpl_column_count_invalid_const(column); - long long median = 0; + long long median = 0; cpl_size i, n; - int *np; - long long *lp; - long long *clp; - long long *copybuf; + int *np; + long long *lp; + long long *clp; + long long *copybuf; n = length - nullcount; @@ -23398,7 +22367,6 @@ cpl_free(copybuf); return median; - } @@ -23416,17 +22384,17 @@ * arrays are not allowed. */ -static cpl_size cpl_column_median_cplsize(const cpl_column *column) +static cpl_size +cpl_column_median_cplsize(const cpl_column *column) { - - cpl_size length = cpl_column_get_size(column); + cpl_size length = cpl_column_get_size(column); cpl_size nullcount = cpl_column_count_invalid_const(column); - cpl_size median = 0; + cpl_size median = 0; cpl_size i, n; - int *np; - cpl_size *lp; - cpl_size *clp; - cpl_size *copybuf; + int *np; + cpl_size *lp; + cpl_size *clp; + cpl_size *copybuf; n = length - nullcount; @@ -23449,7 +22417,6 @@ cpl_free(copybuf); return median; - } @@ -23467,17 +22434,17 @@ * arrays are not allowed. */ -static float cpl_column_median_float(const cpl_column *column) +static float +cpl_column_median_float(const cpl_column *column) { - - cpl_size length = cpl_column_get_size(column); + cpl_size length = cpl_column_get_size(column); cpl_size nullcount = cpl_column_count_invalid_const(column); - float median = 0; + float median = 0; cpl_size i, n; - int *np; - float *fp; - float *cfp; - float *copybuf; + int *np; + float *fp; + float *cfp; + float *copybuf; n = length - nullcount; @@ -23500,7 +22467,6 @@ cpl_free(copybuf); return median; - } @@ -23517,17 +22483,17 @@ * In case of failure, zero is returned. */ -static double cpl_column_median_double(const cpl_column *column) +static double +cpl_column_median_double(const cpl_column *column) { - - cpl_size length = cpl_column_get_size(column); + cpl_size length = cpl_column_get_size(column); cpl_size nullcount = cpl_column_count_invalid_const(column); - double median = 0; + double median = 0; cpl_size i, n; - int *np; - double *dp; - double *cdp; - double *copybuf; + int *np; + double *dp; + double *cdp; + double *copybuf; n = length - nullcount; @@ -23550,7 +22516,6 @@ cpl_free(copybuf); return median; - } @@ -23570,12 +22535,12 @@ * valid elements. Columns of strings or arrays are not allowed. */ -double cpl_column_get_median(const cpl_column *column) +double +cpl_column_get_median(const cpl_column *column) { - - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); - cpl_size nullcount = cpl_column_count_invalid_const(column); + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + cpl_size nullcount = cpl_column_count_invalid_const(column); if (column == NULL) { @@ -23607,7 +22572,6 @@ } return 0.0; - } @@ -23631,12 +22595,12 @@ * arrays are not allowed. */ -cpl_error_code cpl_column_shift(cpl_column *column, cpl_size shift) +cpl_error_code +cpl_column_shift(cpl_column *column, cpl_size shift) { - - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); - int status; + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + int status; if (column == NULL) @@ -23685,9 +22649,7 @@ */ if (column->nullcount) { - if (shift > 0) { - cpl_size j = length - shift; cpl_column_flag *np1 = column->null + length; cpl_column_flag *np2 = np1 - shift; @@ -23696,19 +22658,17 @@ *--np1 = *--np2; } else { - cpl_size j = -shift; cpl_column_flag *np1 = column->null; cpl_column_flag *np2 = np1 - shift; - while(j++ < length) + while (j++ < length) *np1++ = *np2++; } - } - /* + /* * Invalidate the leftovers */ @@ -23721,61 +22681,52 @@ return status; - /* + /* * Now shift the data. */ switch (type) { - - case CPL_TYPE_INT: - { + case CPL_TYPE_INT: { if (shift > 0) { - - cpl_size j = length - shift; - int *ip1 = column->values->i + length; - int *ip2 = ip1 - shift; + cpl_size j = length - shift; + int *ip1 = column->values->i + length; + int *ip2 = ip1 - shift; while (j--) *--ip1 = *--ip2; } else { + cpl_size j = -shift; + int *ip1 = column->values->i; + int *ip2 = ip1 - shift; - cpl_size j = -shift; - int *ip1 = column->values->i; - int *ip2 = ip1 - shift; - - while(j++ < length) + while (j++ < length) *ip1++ = *ip2++; } break; } - case CPL_TYPE_LONG: - { + case CPL_TYPE_LONG: { if (shift > 0) { - - cpl_size j = length - shift; - long *lp1 = column->values->l + length; - long *lp2 = lp1 - shift; + cpl_size j = length - shift; + long *lp1 = column->values->l + length; + long *lp2 = lp1 - shift; while (j--) *--lp1 = *--lp2; } else { + cpl_size j = -shift; + long *lp1 = column->values->l; + long *lp2 = lp1 - shift; - cpl_size j = -shift; - long *lp1 = column->values->l; - long *lp2 = lp1 - shift; - - while(j++ < length) + while (j++ < length) *lp1++ = *lp2++; } break; } - case CPL_TYPE_LONG_LONG: - { + case CPL_TYPE_LONG_LONG: { if (shift > 0) { - - cpl_size j = length - shift; + cpl_size j = length - shift; long long *lp1 = column->values->ll + length; long long *lp2 = lp1 - shift; @@ -23783,21 +22734,18 @@ *--lp1 = *--lp2; } else { + cpl_size j = -shift; + long long *lp1 = column->values->ll; + long long *lp2 = lp1 - shift; - cpl_size j = -shift; - long long *lp1 = column->values->ll; - long long *lp2 = lp1 - shift; - - while(j++ < length) + while (j++ < length) *lp1++ = *lp2++; } break; } - case CPL_TYPE_SIZE: - { + case CPL_TYPE_SIZE: { if (shift > 0) { - - cpl_size j = length - shift; + cpl_size j = length - shift; cpl_size *lp1 = column->values->sz + length; cpl_size *lp2 = lp1 - shift; @@ -23805,65 +22753,56 @@ *--lp1 = *--lp2; } else { + cpl_size j = -shift; + cpl_size *lp1 = column->values->sz; + cpl_size *lp2 = lp1 - shift; - cpl_size j = -shift; - cpl_size *lp1 = column->values->sz; - cpl_size *lp2 = lp1 - shift; - - while(j++ < length) + while (j++ < length) *lp1++ = *lp2++; } break; } - case CPL_TYPE_FLOAT: - { + case CPL_TYPE_FLOAT: { if (shift > 0) { - - cpl_size j = length - shift; - float *fp1 = column->values->f + length; - float *fp2 = fp1 - shift; + cpl_size j = length - shift; + float *fp1 = column->values->f + length; + float *fp2 = fp1 - shift; while (j--) *--fp1 = *--fp2; } else { + cpl_size j = -shift; + float *fp1 = column->values->f; + float *fp2 = fp1 - shift; - cpl_size j = -shift; - float *fp1 = column->values->f; - float *fp2 = fp1 - shift; - - while(j++ < length) + while (j++ < length) *fp1++ = *fp2++; } break; } - case CPL_TYPE_DOUBLE: - { + case CPL_TYPE_DOUBLE: { if (shift > 0) { - - cpl_size j = length - shift; - double *dp1 = column->values->d + length; - double *dp2 = dp1 - shift; + cpl_size j = length - shift; + double *dp1 = column->values->d + length; + double *dp2 = dp1 - shift; while (j--) *--dp1 = *--dp2; } else { + cpl_size j = -shift; + double *dp1 = column->values->d; + double *dp2 = dp1 - shift; - cpl_size j = -shift; - double *dp1 = column->values->d; - double *dp2 = dp1 - shift; - - while(j++ < length) + while (j++ < length) *dp1++ = *dp2++; } break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { if (shift > 0) { - - cpl_size j = length - shift; + cpl_size j = length - shift; float complex *cfp1 = column->values->cf + length; float complex *cfp2 = cfp1 - shift; @@ -23871,21 +22810,18 @@ *--cfp1 = *--cfp2; } else { - - cpl_size j = -shift; + cpl_size j = -shift; float complex *cfp1 = column->values->cf; float complex *cfp2 = cfp1 - shift; - while(j++ < length) + while (j++ < length) *cfp1++ = *cfp2++; } break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { if (shift > 0) { - - cpl_size j = length - shift; + cpl_size j = length - shift; double complex *cdp1 = column->values->cd + length; double complex *cdp2 = cdp1 - shift; @@ -23893,12 +22829,11 @@ *--cdp1 = *--cdp2; } else { - - cpl_size j = -shift; + cpl_size j = -shift; double complex *cdp1 = column->values->cd; double complex *cdp2 = cdp1 - shift; - while(j++ < length) + while (j++ < length) *cdp1++ = *cdp2++; } break; @@ -23908,7 +22843,6 @@ } return CPL_ERROR_NONE; - } @@ -23942,12 +22876,12 @@ * Assigning a code to an invalid element doesn't make it valid. */ -cpl_error_code cpl_column_fill_invalid_int(cpl_column *column, int code) +cpl_error_code +cpl_column_fill_invalid_int(cpl_column *column, int code) { - - const cpl_type type = cpl_column_get_type(column); + const cpl_type type = cpl_column_get_type(column); const cpl_size length = cpl_column_get_size(column); - size_t i; + size_t i; if (column == NULL) @@ -23966,12 +22900,14 @@ acolumn = cpl_array_get_column(array[i]); cpl_column_fill_invalid_int(acolumn, code); } - } else if (column->nullcount == length) { + } + else if (column->nullcount == length) { cpl_column_fill_int(column, 0, length, code); - column->nullcount = length; /* Restore: they are still all NULL! */ - } else if (column->nullcount != 0) { + column->nullcount = length; /* Restore: they are still all NULL! */ + } + else if (column->nullcount != 0) { const int *np = cpl_column_get_data_invalid_const(column); - int *ip = cpl_column_get_data_int(column); + int *ip = cpl_column_get_data_int(column); for (i = 0; i < (size_t)length; i++) if (np[i] == 1) @@ -23979,7 +22915,6 @@ } return CPL_ERROR_NONE; - } @@ -24013,14 +22948,14 @@ * Assigning a code to an invalid element doesn't make it valid. */ -cpl_error_code cpl_column_fill_invalid_long(cpl_column *column, long code) +cpl_error_code +cpl_column_fill_invalid_long(cpl_column *column, long code) { - - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); - int *np; - long *lp; - cpl_size i; + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + int *np; + long *lp; + cpl_size i; cpl_column *acolumn; @@ -24031,7 +22966,6 @@ return cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); if (type & CPL_TYPE_POINTER) { - cpl_array **array = cpl_column_get_data_array(column); while (length--) { @@ -24048,7 +22982,7 @@ if (column->nullcount == length) { cpl_column_fill_long(column, 0, length, code); - column->nullcount = length; /* Restore: they are still all NULL! */ + column->nullcount = length; /* Restore: they are still all NULL! */ return CPL_ERROR_NONE; } @@ -24060,7 +22994,6 @@ *lp = code; return CPL_ERROR_NONE; - } @@ -24095,15 +23028,14 @@ * Assigning a code to an invalid element doesn't make it valid. */ -cpl_error_code cpl_column_fill_invalid_long_long(cpl_column *column, - long long code) +cpl_error_code +cpl_column_fill_invalid_long_long(cpl_column *column, long long code) { - - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); - int *np; - long long *lp; - cpl_size i; + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + int *np; + long long *lp; + cpl_size i; cpl_column *acolumn; @@ -24114,12 +23046,12 @@ return cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); if (type & CPL_TYPE_POINTER) { - cpl_array **array = cpl_column_get_data_array(column); while (length--) { if (array[length] == NULL) - array[length] = cpl_array_new(column->depth, CPL_TYPE_LONG_LONG); + array[length] = + cpl_array_new(column->depth, CPL_TYPE_LONG_LONG); acolumn = cpl_array_get_column(array[length]); cpl_column_fill_invalid_long_long(acolumn, code); } @@ -24131,7 +23063,7 @@ if (column->nullcount == length) { cpl_column_fill_long_long(column, 0, length, code); - column->nullcount = length; /* Restore: they are still all NULL! */ + column->nullcount = length; /* Restore: they are still all NULL! */ return CPL_ERROR_NONE; } @@ -24143,7 +23075,6 @@ *lp = code; return CPL_ERROR_NONE; - } @@ -24177,15 +23108,14 @@ * Assigning a code to an invalid element doesn't make it valid. */ -cpl_error_code cpl_column_fill_invalid_cplsize(cpl_column *column, - cpl_size code) +cpl_error_code +cpl_column_fill_invalid_cplsize(cpl_column *column, cpl_size code) { - - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); - int *np; - cpl_size *lp; - cpl_size i; + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + int *np; + cpl_size *lp; + cpl_size i; cpl_column *acolumn; @@ -24196,7 +23126,6 @@ return cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); if (type & CPL_TYPE_POINTER) { - cpl_array **array = cpl_column_get_data_array(column); while (length--) { @@ -24213,7 +23142,7 @@ if (column->nullcount == length) { cpl_column_fill_cplsize(column, 0, length, code); - column->nullcount = length; /* Restore: they are still all NULL! */ + column->nullcount = length; /* Restore: they are still all NULL! */ return CPL_ERROR_NONE; } @@ -24225,7 +23154,6 @@ *lp = code; return CPL_ERROR_NONE; - } @@ -24259,14 +23187,14 @@ * Assigning a code to an invalid element doesn't make it valid. */ -cpl_error_code cpl_column_fill_invalid_float(cpl_column *column, float code) +cpl_error_code +cpl_column_fill_invalid_float(cpl_column *column, float code) { - - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); - int *np; - float *fp; - cpl_size i; + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + int *np; + float *fp; + cpl_size i; cpl_column *acolumn; cpl_array **array; @@ -24278,7 +23206,6 @@ return cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); if (type & CPL_TYPE_POINTER) { - array = cpl_column_get_data_array(column); while (length--) { @@ -24295,7 +23222,7 @@ if (column->nullcount == length) { cpl_column_fill_float(column, 0, length, code); - column->nullcount = length; /* Restore: they are still all NULL! */ + column->nullcount = length; /* Restore: they are still all NULL! */ return CPL_ERROR_NONE; } @@ -24307,21 +23234,19 @@ *fp = code; return CPL_ERROR_NONE; - } -cpl_error_code cpl_column_fill_invalid_float_complex(cpl_column *column, - float complex code) +cpl_error_code +cpl_column_fill_invalid_float_complex(cpl_column *column, float complex code) { - - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); - int *np; + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + int *np; float complex *fp; - cpl_size i; - cpl_column *acolumn; - cpl_array **array; + cpl_size i; + cpl_column *acolumn; + cpl_array **array; if (column == NULL) @@ -24331,7 +23256,6 @@ return cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); if (type & CPL_TYPE_POINTER) { - array = cpl_column_get_data_array(column); while (length--) { @@ -24348,7 +23272,7 @@ if (column->nullcount == length) { cpl_column_fill_float_complex(column, 0, length, code); - column->nullcount = length; /* Restore: they are still all NULL! */ + column->nullcount = length; /* Restore: they are still all NULL! */ return CPL_ERROR_NONE; } @@ -24360,7 +23284,6 @@ *fp = code; return CPL_ERROR_NONE; - } @@ -24394,14 +23317,14 @@ * Assigning a code to an invalid element doesn't make it valid. */ -cpl_error_code cpl_column_fill_invalid_double(cpl_column *column, double code) +cpl_error_code +cpl_column_fill_invalid_double(cpl_column *column, double code) { - - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); - int *np; - double *dp; - cpl_size i; + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + int *np; + double *dp; + cpl_size i; cpl_column *acolumn; cpl_array **array; @@ -24413,7 +23336,6 @@ return cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); if (type & CPL_TYPE_POINTER) { - array = cpl_column_get_data_array(column); while (length--) { @@ -24430,7 +23352,7 @@ if (column->nullcount == length) { cpl_column_fill_double(column, 0, length, code); - column->nullcount = length; /* Restore: they are still all NULL! */ + column->nullcount = length; /* Restore: they are still all NULL! */ return CPL_ERROR_NONE; } @@ -24442,21 +23364,19 @@ *dp = code; return CPL_ERROR_NONE; - } -cpl_error_code cpl_column_fill_invalid_double_complex(cpl_column *column, - double complex code) +cpl_error_code +cpl_column_fill_invalid_double_complex(cpl_column *column, double complex code) { - - cpl_type type = cpl_column_get_type(column); - cpl_size length = cpl_column_get_size(column); - int *np; + cpl_type type = cpl_column_get_type(column); + cpl_size length = cpl_column_get_size(column); + int *np; double complex *dp; - cpl_size i; - cpl_column *acolumn; - cpl_array **array; + cpl_size i; + cpl_column *acolumn; + cpl_array **array; if (column == NULL) @@ -24466,7 +23386,6 @@ return cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); if (type & CPL_TYPE_POINTER) { - array = cpl_column_get_data_array(column); while (length--) { @@ -24483,7 +23402,7 @@ if (column->nullcount == length) { cpl_column_fill_double_complex(column, 0, length, code); - column->nullcount = length; /* Restore: they are still all NULL! */ + column->nullcount = length; /* Restore: they are still all NULL! */ return CPL_ERROR_NONE; } @@ -24495,7 +23414,6 @@ *dp = code; return CPL_ERROR_NONE; - } /* @@ -24505,7 +23423,8 @@ * @return Nothing. * @see cpl_column_unset_null_segment(), cpl_array_init_perm() */ -void cpl_column_unset_null_all(cpl_column *self) +void +cpl_column_unset_null_all(cpl_column *self) { const cpl_size n = (size_t)cpl_column_get_size_(self); diff -Nru cpl-7.1.4+ds/cplcore/cpl_column.h cpl-7.2.2+ds/cplcore/cpl_column.h --- cpl-7.1.4+ds/cplcore/cpl_column.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_column.h 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -21,7 +21,8 @@ #define CPL_COLUMN_H #if ((defined(__STDC_IEC_559_COMPLEX__) || (__STDC_VERSION__ >= 199901L) || \ - (__GNUC__ >= 3)) && !defined(__cplusplus)) + (__GNUC__ >= 3)) && \ + !defined(__cplusplus)) #include #endif #include @@ -47,51 +48,35 @@ * Constructors and destructors: */ -cpl_column *cpl_column_new_int(cpl_size length) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_new_long(cpl_size length) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_new_long_long(cpl_size length) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_new_cplsize(cpl_size length) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_new_float(cpl_size length) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_new_double(cpl_size length) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_new_float_complex(cpl_size length) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_new_double_complex(cpl_size length) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_new_string(cpl_size length) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_new_array(cpl_type, cpl_size, cpl_size) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_new_complex_from_arrays(const cpl_column *, - const cpl_column *) +cpl_column *cpl_column_new_int(cpl_size length) CPL_ATTR_ALLOC; +cpl_column *cpl_column_new_long(cpl_size length) CPL_ATTR_ALLOC; +cpl_column *cpl_column_new_long_long(cpl_size length) CPL_ATTR_ALLOC; +cpl_column *cpl_column_new_cplsize(cpl_size length) CPL_ATTR_ALLOC; +cpl_column *cpl_column_new_float(cpl_size length) CPL_ATTR_ALLOC; +cpl_column *cpl_column_new_double(cpl_size length) CPL_ATTR_ALLOC; +cpl_column *cpl_column_new_float_complex(cpl_size length) CPL_ATTR_ALLOC; +cpl_column *cpl_column_new_double_complex(cpl_size length) CPL_ATTR_ALLOC; +cpl_column *cpl_column_new_string(cpl_size length) CPL_ATTR_ALLOC; +cpl_column *cpl_column_new_array(cpl_type, cpl_size, cpl_size) CPL_ATTR_ALLOC; +cpl_column * +cpl_column_new_complex_from_arrays(const cpl_column *, const cpl_column *) CPL_ATTR_ALLOC CPL_INTERNAL; cpl_error_code cpl_column_set_save_type(cpl_column *, cpl_type); cpl_type cpl_column_get_save_type(const cpl_column *); -cpl_column *cpl_column_wrap_int(int *, cpl_size length) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_wrap_long(long *, cpl_size length) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_wrap_long_long(long long *, cpl_size length) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_wrap_cplsize(cpl_size *, cpl_size length) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_wrap_float(float *, cpl_size length) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_wrap_double(double *, cpl_size length) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_wrap_float_complex(_Complex float *, cpl_size length) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_wrap_double_complex(_Complex double *, cpl_size length) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_wrap_string(char **, cpl_size length) - CPL_ATTR_ALLOC; +cpl_column *cpl_column_wrap_int(int *, cpl_size length) CPL_ATTR_ALLOC; +cpl_column *cpl_column_wrap_long(long *, cpl_size length) CPL_ATTR_ALLOC; +cpl_column * +cpl_column_wrap_long_long(long long *, cpl_size length) CPL_ATTR_ALLOC; +cpl_column *cpl_column_wrap_cplsize(cpl_size *, cpl_size length) CPL_ATTR_ALLOC; +cpl_column *cpl_column_wrap_float(float *, cpl_size length) CPL_ATTR_ALLOC; +cpl_column *cpl_column_wrap_double(double *, cpl_size length) CPL_ATTR_ALLOC; +cpl_column * +cpl_column_wrap_float_complex(_Complex float *, cpl_size length) CPL_ATTR_ALLOC; +cpl_column *cpl_column_wrap_double_complex(_Complex double *, + cpl_size length) CPL_ATTR_ALLOC; +cpl_column *cpl_column_wrap_string(char **, cpl_size length) CPL_ATTR_ALLOC; void *cpl_column_unwrap(cpl_column *); void cpl_column_delete_but_strings(cpl_column *); @@ -104,12 +89,12 @@ cpl_error_code cpl_column_copy_data_cplsize(cpl_column *, const cpl_size *); cpl_error_code cpl_column_copy_data_float(cpl_column *, const float *); cpl_error_code cpl_column_copy_data_double(cpl_column *, const double *); -cpl_error_code cpl_column_copy_data_complex(cpl_column *, - const _Complex double *); -cpl_error_code cpl_column_copy_data_float_complex(cpl_column *, - const _Complex float *); -cpl_error_code cpl_column_copy_data_double_complex(cpl_column *, - const _Complex double *); +cpl_error_code +cpl_column_copy_data_complex(cpl_column *, const _Complex double *); +cpl_error_code +cpl_column_copy_data_float_complex(cpl_column *, const _Complex float *); +cpl_error_code +cpl_column_copy_data_double_complex(cpl_column *, const _Complex double *); cpl_error_code cpl_column_copy_data_string(cpl_column *, const char **); void cpl_column_delete(cpl_column *); @@ -160,75 +145,98 @@ const cpl_array **cpl_column_get_data_array_const(const cpl_column *); cpl_column_flag *cpl_column_get_data_invalid(cpl_column *); const cpl_column_flag *cpl_column_get_data_invalid_const(const cpl_column *); -cpl_error_code cpl_column_set_data_invalid(cpl_column *, - cpl_column_flag *, cpl_size); +cpl_error_code +cpl_column_set_data_invalid(cpl_column *, cpl_column_flag *, cpl_size); cpl_error_code cpl_column_set_size(cpl_column *, cpl_size); cpl_error_code cpl_column_set_depth(cpl_column *, cpl_size); double cpl_column_get(const cpl_column *, cpl_size, int *); -_Complex double cpl_column_get_complex(const cpl_column *, cpl_size , int *); -int cpl_column_get_int(const cpl_column *, cpl_size, int *); +_Complex double cpl_column_get_complex(const cpl_column *, cpl_size, int *); +int cpl_column_get_int(const cpl_column *, cpl_size, int *); long cpl_column_get_long(const cpl_column *, cpl_size, int *); long long cpl_column_get_long_long(const cpl_column *, cpl_size, int *); cpl_size cpl_column_get_cplsize(const cpl_column *, cpl_size, int *); -float cpl_column_get_float(const cpl_column *, cpl_size, int *); -double cpl_column_get_double(const cpl_column *, cpl_size, int *); -_Complex float cpl_column_get_float_complex(const cpl_column *, cpl_size, - int *); -_Complex double cpl_column_get_double_complex(const cpl_column *, cpl_size, - int *); +float cpl_column_get_float(const cpl_column *, cpl_size, int *); +double cpl_column_get_double(const cpl_column *, cpl_size, int *); +_Complex float +cpl_column_get_float_complex(const cpl_column *, cpl_size, int *); +_Complex double +cpl_column_get_double_complex(const cpl_column *, cpl_size, int *); char *cpl_column_get_string(cpl_column *, cpl_size); const char *cpl_column_get_string_const(const cpl_column *, cpl_size); cpl_array *cpl_column_get_array(cpl_column *, cpl_size); const cpl_array *cpl_column_get_array_const(const cpl_column *, cpl_size); -cpl_error_code cpl_column_set(cpl_column *, cpl_size, double); -cpl_error_code cpl_column_set_int(cpl_column *, cpl_size, int); +cpl_error_code cpl_column_set(cpl_column *, cpl_size, double); +cpl_error_code cpl_column_set_int(cpl_column *, cpl_size, int); cpl_error_code cpl_column_set_long(cpl_column *, cpl_size, long); cpl_error_code cpl_column_set_long_long(cpl_column *, cpl_size, long long); cpl_error_code cpl_column_set_cplsize(cpl_column *, cpl_size, cpl_size); -cpl_error_code cpl_column_set_float(cpl_column *, cpl_size, float); -cpl_error_code cpl_column_set_double(cpl_column *, cpl_size, double); +cpl_error_code cpl_column_set_float(cpl_column *, cpl_size, float); +cpl_error_code cpl_column_set_double(cpl_column *, cpl_size, double); cpl_error_code cpl_column_set_complex(cpl_column *, cpl_size, _Complex double); -cpl_error_code cpl_column_set_float_complex(cpl_column *, cpl_size, _Complex float); -cpl_error_code cpl_column_set_double_complex(cpl_column *, cpl_size, _Complex double); +cpl_error_code +cpl_column_set_float_complex(cpl_column *, cpl_size, _Complex float); +cpl_error_code +cpl_column_set_double_complex(cpl_column *, cpl_size, _Complex double); cpl_error_code cpl_column_set_string(cpl_column *, cpl_size, const char *); cpl_error_code cpl_column_set_array(cpl_column *, cpl_size, const cpl_array *); -cpl_error_code cpl_column_fill(cpl_column *, cpl_size, cpl_size, double); -cpl_error_code cpl_column_fill_int(cpl_column *, cpl_size, cpl_size, int); +cpl_error_code cpl_column_fill(cpl_column *, cpl_size, cpl_size, double); +cpl_error_code cpl_column_fill_int(cpl_column *, cpl_size, cpl_size, int); cpl_error_code cpl_column_fill_long(cpl_column *, cpl_size, cpl_size, long); -cpl_error_code cpl_column_fill_long_long(cpl_column *, cpl_size, cpl_size, long long); -cpl_error_code cpl_column_fill_cplsize(cpl_column *, cpl_size, cpl_size, cpl_size); -cpl_error_code cpl_column_fill_float(cpl_column *, cpl_size, cpl_size, float); +cpl_error_code +cpl_column_fill_long_long(cpl_column *, cpl_size, cpl_size, long long); +cpl_error_code +cpl_column_fill_cplsize(cpl_column *, cpl_size, cpl_size, cpl_size); +cpl_error_code cpl_column_fill_float(cpl_column *, cpl_size, cpl_size, float); cpl_error_code cpl_column_fill_double(cpl_column *, cpl_size, cpl_size, double); -cpl_error_code cpl_column_fill_complex(cpl_column *, cpl_size, cpl_size, _Complex double); -cpl_error_code cpl_column_fill_float_complex(cpl_column *, - cpl_size, cpl_size, _Complex float); -cpl_error_code cpl_column_fill_double_complex(cpl_column *, - cpl_size, cpl_size, _Complex double); -cpl_error_code cpl_column_fill_string(cpl_column *, cpl_size, cpl_size, const char *); -cpl_error_code cpl_column_fill_array(cpl_column *, cpl_size, cpl_size, const cpl_array *); - -cpl_error_code cpl_column_copy_segment(cpl_column *, cpl_size, cpl_size, double *); -cpl_error_code cpl_column_copy_segment_int(cpl_column *, cpl_size, cpl_size, int *); -cpl_error_code cpl_column_copy_segment_long(cpl_column *, cpl_size, cpl_size, long *); -cpl_error_code cpl_column_copy_segment_long_long(cpl_column *, cpl_size, - cpl_size, long long *); -cpl_error_code cpl_column_copy_segment_cplsize(cpl_column *, cpl_size, - cpl_size, cpl_size *); -cpl_error_code cpl_column_copy_segment_float(cpl_column *, cpl_size, cpl_size, float *); -cpl_error_code cpl_column_copy_segment_double(cpl_column *, cpl_size, cpl_size, double *); -cpl_error_code cpl_column_copy_segment_complex(cpl_column *, - cpl_size, cpl_size, _Complex double *); -cpl_error_code cpl_column_copy_segment_float_complex(cpl_column *, - cpl_size, cpl_size, _Complex float *); -cpl_error_code cpl_column_copy_segment_double_complex(cpl_column *, - cpl_size, cpl_size, _Complex double *); -cpl_error_code cpl_column_copy_segment_string(cpl_column *, cpl_size, cpl_size, char **); -cpl_error_code cpl_column_copy_segment_array(cpl_column *, cpl_size, cpl_size, - cpl_array **); +cpl_error_code +cpl_column_fill_complex(cpl_column *, cpl_size, cpl_size, _Complex double); +cpl_error_code +cpl_column_fill_float_complex(cpl_column *, cpl_size, cpl_size, _Complex float); +cpl_error_code cpl_column_fill_double_complex(cpl_column *, + cpl_size, + cpl_size, + _Complex double); +cpl_error_code +cpl_column_fill_string(cpl_column *, cpl_size, cpl_size, const char *); +cpl_error_code +cpl_column_fill_array(cpl_column *, cpl_size, cpl_size, const cpl_array *); + +cpl_error_code +cpl_column_copy_segment(cpl_column *, cpl_size, cpl_size, double *); +cpl_error_code +cpl_column_copy_segment_int(cpl_column *, cpl_size, cpl_size, int *); +cpl_error_code +cpl_column_copy_segment_long(cpl_column *, cpl_size, cpl_size, long *); +cpl_error_code cpl_column_copy_segment_long_long(cpl_column *, + cpl_size, + cpl_size, + long long *); +cpl_error_code +cpl_column_copy_segment_cplsize(cpl_column *, cpl_size, cpl_size, cpl_size *); +cpl_error_code +cpl_column_copy_segment_float(cpl_column *, cpl_size, cpl_size, float *); +cpl_error_code +cpl_column_copy_segment_double(cpl_column *, cpl_size, cpl_size, double *); +cpl_error_code cpl_column_copy_segment_complex(cpl_column *, + cpl_size, + cpl_size, + _Complex double *); +cpl_error_code cpl_column_copy_segment_float_complex(cpl_column *, + cpl_size, + cpl_size, + _Complex float *); +cpl_error_code cpl_column_copy_segment_double_complex(cpl_column *, + cpl_size, + cpl_size, + _Complex double *); +cpl_error_code +cpl_column_copy_segment_string(cpl_column *, cpl_size, cpl_size, char **); +cpl_error_code +cpl_column_copy_segment_array(cpl_column *, cpl_size, cpl_size, cpl_array **); cpl_error_code cpl_column_shift(cpl_column *, cpl_size); @@ -246,69 +254,50 @@ cpl_error_code cpl_column_fill_invalid_cplsize(cpl_column *, cpl_size); cpl_error_code cpl_column_fill_invalid_float(cpl_column *, float); cpl_error_code cpl_column_fill_invalid_double(cpl_column *, double); -cpl_error_code cpl_column_fill_invalid_float_complex(cpl_column *, - _Complex float); -cpl_error_code cpl_column_fill_invalid_double_complex(cpl_column *, - _Complex double); +cpl_error_code +cpl_column_fill_invalid_float_complex(cpl_column *, _Complex float); +cpl_error_code +cpl_column_fill_invalid_double_complex(cpl_column *, _Complex double); cpl_error_code cpl_column_erase_segment(cpl_column *, cpl_size, cpl_size); cpl_error_code cpl_column_erase_pattern(cpl_column *, int *); cpl_error_code cpl_column_insert_segment(cpl_column *, cpl_size, cpl_size); -cpl_column *cpl_column_duplicate(const cpl_column *) - CPL_ATTR_ALLOC; +cpl_column *cpl_column_duplicate(const cpl_column *) CPL_ATTR_ALLOC; -cpl_column *cpl_column_extract(cpl_column *, cpl_size, cpl_size) - CPL_ATTR_ALLOC; +cpl_column *cpl_column_extract(cpl_column *, cpl_size, cpl_size) CPL_ATTR_ALLOC; -cpl_column *cpl_column_cast_to_int(const cpl_column *) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_cast_to_long(const cpl_column *) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_cast_to_long_long(const cpl_column *) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_cast_to_cplsize(const cpl_column *) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_cast_to_float(const cpl_column *) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_cast_to_double(const cpl_column *) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_cast_to_float_complex(const cpl_column *) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_cast_to_double_complex(const cpl_column *) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_cast_to_int_array(const cpl_column *) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_cast_to_long_array(const cpl_column *) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_cast_to_long_long_array(const cpl_column *) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_cast_to_cplsize_array(const cpl_column *) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_cast_to_float_array(const cpl_column *) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_cast_to_double_array(const cpl_column *) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_cast_to_float_complex_array(const cpl_column *) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_cast_to_double_complex_array(const cpl_column *) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_cast_to_int_flat(const cpl_column *) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_cast_to_long_flat(const cpl_column *) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_cast_to_long_long_flat(const cpl_column *) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_cast_to_cplsize_flat(const cpl_column *) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_cast_to_float_flat(const cpl_column *) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_cast_to_double_flat(const cpl_column *) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_cast_to_float_complex_flat(const cpl_column *) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_cast_to_double_complex_flat(const cpl_column *) - CPL_ATTR_ALLOC; +cpl_column *cpl_column_cast_to_int(const cpl_column *) CPL_ATTR_ALLOC; +cpl_column *cpl_column_cast_to_long(const cpl_column *) CPL_ATTR_ALLOC; +cpl_column *cpl_column_cast_to_long_long(const cpl_column *) CPL_ATTR_ALLOC; +cpl_column *cpl_column_cast_to_cplsize(const cpl_column *) CPL_ATTR_ALLOC; +cpl_column *cpl_column_cast_to_float(const cpl_column *) CPL_ATTR_ALLOC; +cpl_column *cpl_column_cast_to_double(const cpl_column *) CPL_ATTR_ALLOC; +cpl_column *cpl_column_cast_to_float_complex(const cpl_column *) CPL_ATTR_ALLOC; +cpl_column * +cpl_column_cast_to_double_complex(const cpl_column *) CPL_ATTR_ALLOC; +cpl_column *cpl_column_cast_to_int_array(const cpl_column *) CPL_ATTR_ALLOC; +cpl_column *cpl_column_cast_to_long_array(const cpl_column *) CPL_ATTR_ALLOC; +cpl_column * +cpl_column_cast_to_long_long_array(const cpl_column *) CPL_ATTR_ALLOC; +cpl_column *cpl_column_cast_to_cplsize_array(const cpl_column *) CPL_ATTR_ALLOC; +cpl_column *cpl_column_cast_to_float_array(const cpl_column *) CPL_ATTR_ALLOC; +cpl_column *cpl_column_cast_to_double_array(const cpl_column *) CPL_ATTR_ALLOC; +cpl_column * +cpl_column_cast_to_float_complex_array(const cpl_column *) CPL_ATTR_ALLOC; +cpl_column * +cpl_column_cast_to_double_complex_array(const cpl_column *) CPL_ATTR_ALLOC; +cpl_column *cpl_column_cast_to_int_flat(const cpl_column *) CPL_ATTR_ALLOC; +cpl_column *cpl_column_cast_to_long_flat(const cpl_column *) CPL_ATTR_ALLOC; +cpl_column * +cpl_column_cast_to_long_long_flat(const cpl_column *) CPL_ATTR_ALLOC; +cpl_column *cpl_column_cast_to_cplsize_flat(const cpl_column *) CPL_ATTR_ALLOC; +cpl_column *cpl_column_cast_to_float_flat(const cpl_column *) CPL_ATTR_ALLOC; +cpl_column *cpl_column_cast_to_double_flat(const cpl_column *) CPL_ATTR_ALLOC; +cpl_column * +cpl_column_cast_to_float_complex_flat(const cpl_column *) CPL_ATTR_ALLOC; +cpl_column * +cpl_column_cast_to_double_complex_flat(const cpl_column *) CPL_ATTR_ALLOC; cpl_error_code cpl_column_merge(cpl_column *, const cpl_column *, cpl_size); @@ -320,24 +309,21 @@ cpl_error_code cpl_column_add_scalar(cpl_column *, double); cpl_error_code cpl_column_add_scalar_complex(cpl_column *, _Complex double); cpl_error_code cpl_column_subtract_scalar(cpl_column *, double); -cpl_error_code cpl_column_subtract_scalar_complex(cpl_column *, _Complex double); +cpl_error_code +cpl_column_subtract_scalar_complex(cpl_column *, _Complex double); cpl_error_code cpl_column_multiply_scalar(cpl_column *, double); -cpl_error_code cpl_column_multiply_scalar_complex(cpl_column *, _Complex double); +cpl_error_code +cpl_column_multiply_scalar_complex(cpl_column *, _Complex double); cpl_error_code cpl_column_divide_scalar(cpl_column *, double); cpl_error_code cpl_column_divide_scalar_complex(cpl_column *, _Complex double); cpl_error_code cpl_column_absolute(cpl_column *); -cpl_column *cpl_column_absolute_complex(cpl_column *) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_phase_complex(cpl_column *) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_extract_real(const cpl_column *) - CPL_ATTR_ALLOC; -cpl_column *cpl_column_extract_imag(const cpl_column *) - CPL_ATTR_ALLOC; +cpl_column *cpl_column_absolute_complex(cpl_column *) CPL_ATTR_ALLOC; +cpl_column *cpl_column_phase_complex(cpl_column *) CPL_ATTR_ALLOC; +cpl_column *cpl_column_extract_real(const cpl_column *) CPL_ATTR_ALLOC; +cpl_column *cpl_column_extract_imag(const cpl_column *) CPL_ATTR_ALLOC; cpl_error_code cpl_column_logarithm(cpl_column *, double); cpl_error_code cpl_column_power(cpl_column *, double); -cpl_error_code cpl_column_power_complex(cpl_column *, - double complex); +cpl_error_code cpl_column_power_complex(cpl_column *, double complex); cpl_error_code cpl_column_exponential(cpl_column *, double); cpl_error_code cpl_column_conjugate(cpl_column *); diff -Nru cpl-7.1.4+ds/cplcore/cpl_error.c cpl-7.2.2+ds/cplcore/cpl_error.c --- cpl-7.1.4+ds/cplcore/cpl_error.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_error.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -88,15 +88,12 @@ /**@{*/ -#ifndef CPL_LINESZ -#ifdef FITS_LINESZ -#define CPL_LINESZ FITS_LINESZ -#else -#define CPL_LINESZ 6 -#endif +#ifndef CPL_LINENOSZ +#define CPL_LINENOSZ 6 #endif -#define MAX_WHERE_LENGTH (2+(MAX_NAME_LENGTH)+(MAX_FILE_LENGTH)+(CPL_LINESZ)) +#define MAX_WHERE_LENGTH \ + (2 + (MAX_NAME_LENGTH) + (MAX_FILE_LENGTH) + (CPL_LINENOSZ)) /*----------------------------------------------------------------------------- Private variables @@ -118,12 +115,15 @@ Private functions -----------------------------------------------------------------------------*/ -static cpl_error * cpl_error_fill(const char *, cpl_error_code, const char *, - unsigned); +static cpl_error * +cpl_error_fill(const char *, cpl_error_code, const char *, unsigned); static cpl_error_code -cpl_error_set_message_macro_(const char *, cpl_error_code, - const char *, unsigned, - const char *, va_list) CPL_ATTR_PRINTF(5,0) +cpl_error_set_message_macro_(const char *, + cpl_error_code, + const char *, + unsigned, + const char *, + va_list) CPL_ATTR_PRINTF(5, 0) #ifdef CPL_HAVE_ATTR_NONNULL __attribute__((nonnull(3))) #endif @@ -142,21 +142,21 @@ * This function initialises the @em cpl_error_code to @c CPL_ERROR_NONE. */ -void cpl_error_reset(void) +void +cpl_error_reset(void) { - #ifdef HAVE_LIBPTHREAD pthread_rwlock_wrlock(&cpl_lock_error_status); pthread_rwlock_rdlock(&cpl_lock_error_read_only); #endif - if (!cpl_error_read_only) cpl_error_status = CPL_FALSE; + if (!cpl_error_read_only) + cpl_error_status = CPL_FALSE; #ifdef HAVE_LIBPTHREAD pthread_rwlock_unlock(&cpl_lock_error_status); pthread_rwlock_unlock(&cpl_lock_error_read_only); #endif - } /* @@ -176,21 +176,22 @@ * @note This function is only provided for cpl_error_set*() macros. * @see cpl_error_set_message() */ -cpl_error_code cpl_error_set_message_macro(const char * function, - cpl_error_code code, - const char * file, unsigned line, - const char * text, ...) +cpl_error_code +cpl_error_set_message_macro(const char *function, + cpl_error_code code, + const char *file, + unsigned line, + const char *text, + ...) { - - - va_list arglist; + va_list arglist; cpl_error_code lcode; va_start(arglist, text); - lcode = cpl_error_set_message_macro_(function, code, file, line, text, - arglist); + lcode = + cpl_error_set_message_macro_(function, code, file, line, text, arglist); va_end(arglist); @@ -216,27 +217,26 @@ * @see cpl_error_set_message() * @note This function should only be called from the cpl_error_set_fits() macro */ -cpl_error_code cpl_error_set_fits_macro(const char * function, - cpl_error_code code, - int fitscode, - const char * fitsfunction, - const char * file, - unsigned line, - const char * text, - ...) +cpl_error_code +cpl_error_set_fits_macro(const char *function, + cpl_error_code code, + int fitscode, + const char *fitsfunction, + const char *file, + unsigned line, + const char *text, + ...) { - - - char cfitsio_msg[FLEN_ERRMSG]; - va_list arglist; - cpl_error_code lcode; - char * newformat; + char cfitsio_msg[FLEN_ERRMSG]; + va_list arglist; + cpl_error_code lcode; + char *newformat; const cpl_boolean has_name = fitsfunction && strcmp(fitsfunction, "\"\""); fits_get_errstatus(fitscode, cfitsio_msg); - cfitsio_msg[FLEN_ERRMSG-1] = '\0' ; /* Better safe than sorry */ + cfitsio_msg[FLEN_ERRMSG - 1] = '\0'; /* Better safe than sorry */ newformat = cpl_sprintf("\"%s\" from CFITSIO " #ifdef CFITSIO_VERSION @@ -244,23 +244,20 @@ "(ver. " CPL_STRINGIFY(CFITSIO_VERSION) ") " #endif - "%s%s=%d. %s", cfitsio_msg, - has_name ? fitsfunction : "", - has_name ? "()" : "error", - fitscode, text); + "%s%s=%d. %s", + cfitsio_msg, has_name ? fitsfunction : "", + has_name ? "()" : "error", fitscode, text); va_start(arglist, text); - lcode = cpl_error_set_message_macro_(function, code, file, line, - newformat, arglist); + lcode = cpl_error_set_message_macro_(function, code, file, line, newformat, + arglist); va_end(arglist); cpl_free(newformat); return lcode; - - } /*----------------------------------------------------------------------------*/ @@ -281,27 +278,27 @@ * @see cpl_error_set_message() * @note This function should only be called from cpl_error_set_regex() */ -cpl_error_code cpl_error_set_regex_macro(const char * function, - cpl_error_code code, - int regcode, - const regex_t * preg, - const char * file, - unsigned line, - const char * text, - ...) +cpl_error_code +cpl_error_set_regex_macro(const char *function, + cpl_error_code code, + int regcode, + const regex_t *preg, + const char *file, + unsigned line, + const char *text, + ...) { - - cpl_error_code lcode; - va_list arglist; - char * newformat; + va_list arglist; + char *newformat; if (preg == NULL) { /* Passing NULL to regerror() seems to fill with the information of the previous error, which we do not want here */ newformat = cpl_sprintf("regcomp(NULL)=%d. %s", regcode, text); - } else { + } + else { char regex_msg[CPL_ERROR_MAX_MESSAGE_LENGTH]; (void)regerror(regcode, preg, regex_msg, CPL_ERROR_MAX_MESSAGE_LENGTH); @@ -312,19 +309,17 @@ va_start(arglist, text); - lcode = cpl_error_set_message_macro_(function, code, file, line, - newformat, arglist); + lcode = cpl_error_set_message_macro_(function, code, file, line, newformat, + arglist); va_end(arglist); cpl_free(newformat); return lcode; - } - /*----------------------------------------------------------------------------*/ /** * @internal @@ -345,54 +340,55 @@ * @note This function should only be called from the cpl_error_set_wcs() macro * */ -cpl_error_code cpl_error_set_wcs_macro(const char * function, - cpl_error_code code, - int wcserror, - const char * wcsfunction, - const char * wcserrmsg[], - const char * file, - unsigned line, - const char * text, - ...) +cpl_error_code +cpl_error_set_wcs_macro(const char *function, + cpl_error_code code, + int wcserror, + const char *wcsfunction, + const char *wcserrmsg[], + const char *file, + unsigned line, + const char *text, + ...) { - - cpl_error_code lcode; - va_list arglist; - char * newformat; + cpl_error_code lcode; + va_list arglist; + char *newformat; const cpl_boolean has_name = wcsfunction && strlen(wcsfunction); if (wcserror < 0) { - newformat = cpl_sprintf("%s%s=%d < 0. %s", - has_name ? wcsfunction : "", - has_name ? "()" : "error", wcserror, text); - } else if (wcserrmsg == NULL) { + newformat = cpl_sprintf("%s%s=%d < 0. %s", has_name ? wcsfunction : "", + has_name ? "()" : "error", wcserror, text); + } + else if (wcserrmsg == NULL) { newformat = cpl_sprintf("%s%s()=%d. wcs_errmsg[] == NULL. %s", has_name ? wcsfunction : "", has_name ? "()" : "error", wcserror, text); - } else if (wcserrmsg[wcserror] == NULL) { - newformat = cpl_sprintf("%s%s()=%d. wcs_errmsg[%d] == NULL. %s", - has_name ? wcsfunction : "", - has_name ? "()" : "error", - wcserror, wcserror, text); - } else { - newformat = cpl_sprintf("\"%s\" from %s%s()=%d. %s", wcserrmsg[wcserror], - has_name ? wcsfunction : "", - has_name ? "()" : "error", - wcserror, text); + } + else if (wcserrmsg[wcserror] == NULL) { + newformat = + cpl_sprintf("%s%s()=%d. wcs_errmsg[%d] == NULL. %s", + has_name ? wcsfunction : "", has_name ? "()" : "error", + wcserror, wcserror, text); + } + else { + newformat = + cpl_sprintf("\"%s\" from %s%s()=%d. %s", wcserrmsg[wcserror], + has_name ? wcsfunction : "", has_name ? "()" : "error", + wcserror, text); } va_start(arglist, text); - lcode = cpl_error_set_message_macro_(function, code, file, line, - newformat, arglist); + lcode = cpl_error_set_message_macro_(function, code, file, line, newformat, + arglist); va_end(arglist); cpl_free(newformat); return lcode; - } @@ -405,7 +401,8 @@ * Get @em cpl_error_code of last occurred error. */ -cpl_error_code cpl_error_get_code(void) +cpl_error_code +cpl_error_get_code(void) { cpl_error_code code = CPL_ERROR_NONE; @@ -414,7 +411,7 @@ #endif if (cpl_error_status) { - const cpl_error * error = cpl_errorstate_find(); + const cpl_error *error = cpl_errorstate_find(); code = error->code; } @@ -441,10 +438,10 @@ * */ -const char * cpl_error_get_message(void) +const char * +cpl_error_get_message(void) { - - const cpl_error * error; + const cpl_error *error; #ifdef HAVE_LIBPTHREAD pthread_rwlock_rdlock(&cpl_lock_error_status); @@ -467,7 +464,7 @@ /* assert(error->code != CPL_ERROR_NONE); */ return strlen(error->msg) ? error->msg - : cpl_error_get_message_default(error->code); + : cpl_error_get_message_default(error->code); } /** @@ -480,16 +477,17 @@ * Get the function name where the last CPL error occurred. */ -const char *cpl_error_get_function(void) +const char * +cpl_error_get_function(void) { - const char * function = ""; + const char *function = ""; #ifdef HAVE_LIBPTHREAD pthread_rwlock_rdlock(&cpl_lock_error_status); #endif if (cpl_error_status) { - const cpl_error * error = cpl_errorstate_find(); + const cpl_error *error = cpl_errorstate_find(); function = error->function; } @@ -514,9 +512,9 @@ * @c function_name:source_file:line_number */ -const char *cpl_error_get_where(void) +const char * +cpl_error_get_where(void) { - static char cpl_error_where_string[MAX_WHERE_LENGTH]; #ifdef _OPENMP @@ -529,7 +527,6 @@ cpl_error_get_line()); return cpl_error_where_string; - } @@ -542,16 +539,17 @@ * Get the source code file name where the last CPL error occurred. */ -const char *cpl_error_get_file(void) +const char * +cpl_error_get_file(void) { - const char * file = ""; + const char *file = ""; #ifdef HAVE_LIBPTHREAD pthread_rwlock_rdlock(&cpl_lock_error_status); #endif if (cpl_error_status) { - const cpl_error * error = cpl_errorstate_find(); + const cpl_error *error = cpl_errorstate_find(); file = error->file; } @@ -573,7 +571,8 @@ * Get the line number of the source file where the last CPL error occurred. */ -unsigned cpl_error_get_line(void) +unsigned +cpl_error_get_line(void) { unsigned line = 0; @@ -582,7 +581,7 @@ #endif if (cpl_error_status) { - const cpl_error * error = cpl_errorstate_find(); + const cpl_error *error = cpl_errorstate_find(); line = error->line; } @@ -603,85 +602,86 @@ */ /*----------------------------------------------------------------------------*/ -const char * cpl_error_get_message_default(cpl_error_code code) +const char * +cpl_error_get_message_default(cpl_error_code code) { - const char * message; + const char *message; switch (code) { - case CPL_ERROR_NONE: + case CPL_ERROR_NONE: message = ""; break; - case CPL_ERROR_UNSPECIFIED: - message = "An unspecified error"; + case CPL_ERROR_UNSPECIFIED: + message = "An unspecified error"; break; - case CPL_ERROR_HISTORY_LOST: - message = "The actual error was lost"; + case CPL_ERROR_HISTORY_LOST: + message = "The actual error was lost"; break; - case CPL_ERROR_DUPLICATING_STREAM: + case CPL_ERROR_DUPLICATING_STREAM: message = "Cannot duplicate output stream"; break; - case CPL_ERROR_ASSIGNING_STREAM: + case CPL_ERROR_ASSIGNING_STREAM: message = "Cannot associate a stream with a file descriptor"; break; - case CPL_ERROR_FILE_IO: + case CPL_ERROR_FILE_IO: message = "File read/write error"; break; - case CPL_ERROR_BAD_FILE_FORMAT: + case CPL_ERROR_BAD_FILE_FORMAT: message = "Bad file format"; break; - case CPL_ERROR_FILE_ALREADY_OPEN: + case CPL_ERROR_FILE_ALREADY_OPEN: message = "File already open"; break; - case CPL_ERROR_FILE_NOT_CREATED: + case CPL_ERROR_FILE_NOT_CREATED: message = "File cannot be created"; break; - case CPL_ERROR_FILE_NOT_FOUND: + case CPL_ERROR_FILE_NOT_FOUND: message = "File not found"; break; - case CPL_ERROR_DATA_NOT_FOUND: + case CPL_ERROR_DATA_NOT_FOUND: message = "Data not found"; break; - case CPL_ERROR_ACCESS_OUT_OF_RANGE: + case CPL_ERROR_ACCESS_OUT_OF_RANGE: message = "Access beyond boundaries"; break; - case CPL_ERROR_NULL_INPUT: + case CPL_ERROR_NULL_INPUT: message = "Null input data"; break; - case CPL_ERROR_INCOMPATIBLE_INPUT: + case CPL_ERROR_INCOMPATIBLE_INPUT: message = "Input data do not match"; break; - case CPL_ERROR_ILLEGAL_INPUT: + case CPL_ERROR_ILLEGAL_INPUT: message = "Illegal input"; break; - case CPL_ERROR_ILLEGAL_OUTPUT: + case CPL_ERROR_ILLEGAL_OUTPUT: message = "Illegal output"; break; - case CPL_ERROR_UNSUPPORTED_MODE: + case CPL_ERROR_UNSUPPORTED_MODE: message = "Unsupported mode"; break; - case CPL_ERROR_SINGULAR_MATRIX: + case CPL_ERROR_SINGULAR_MATRIX: message = "Singular matrix"; break; - case CPL_ERROR_DIVISION_BY_ZERO: + case CPL_ERROR_DIVISION_BY_ZERO: message = "Division by zero"; break; - case CPL_ERROR_TYPE_MISMATCH: + case CPL_ERROR_TYPE_MISMATCH: message = "Type mismatch"; break; - case CPL_ERROR_INVALID_TYPE: + case CPL_ERROR_INVALID_TYPE: message = "Invalid type"; break; - case CPL_ERROR_CONTINUE: + case CPL_ERROR_CONTINUE: message = "The iterative process did not converge"; break; - case CPL_ERROR_NO_WCS: + case CPL_ERROR_NO_WCS: message = "The WCS functionalities are missing"; break; - case CPL_ERROR_EOL: - message = "A user-defined error"; + case CPL_ERROR_EOL: + message = "A user-defined error"; break; - default: - message = "A user-defined error"; + default: + message = "A user-defined error"; break; } @@ -694,7 +694,8 @@ @brief Lock the RW locks of the global variables in this module */ /*----------------------------------------------------------------------------*/ -void cpl_error_init_locks(void) +void +cpl_error_init_locks(void) { pthread_rwlock_init(&cpl_lock_error_status, NULL); pthread_rwlock_init(&cpl_lock_error_read_only, NULL); @@ -717,7 +718,8 @@ */ /*----------------------------------------------------------------------------*/ -cpl_boolean cpl_error_is_set(void) +cpl_boolean +cpl_error_is_set(void) { cpl_boolean status; @@ -744,7 +746,8 @@ */ /*----------------------------------------------------------------------------*/ -cpl_boolean cpl_error_is_readonly(void) +cpl_boolean +cpl_error_is_readonly(void) { cpl_boolean read_only; @@ -769,9 +772,9 @@ */ /*----------------------------------------------------------------------------*/ -void cpl_error_set_readonly(void) +void +cpl_error_set_readonly(void) { - #ifdef HAVE_LIBPTHREAD pthread_rwlock_wrlock(&cpl_lock_error_read_only); #endif @@ -781,7 +784,6 @@ #ifdef HAVE_LIBPTHREAD pthread_rwlock_unlock(&cpl_lock_error_read_only); #endif - } @@ -793,9 +795,9 @@ */ /*----------------------------------------------------------------------------*/ -void cpl_error_reset_readonly(void) +void +cpl_error_reset_readonly(void) { - #ifdef HAVE_LIBPTHREAD pthread_rwlock_wrlock(&cpl_lock_error_read_only); #endif @@ -805,7 +807,6 @@ #ifdef HAVE_LIBPTHREAD pthread_rwlock_unlock(&cpl_lock_error_read_only); #endif - } /* @@ -818,11 +819,13 @@ * @return A pointer to the struct of the error. * @see cpl_error_set_message_macro() */ -static cpl_error * cpl_error_fill(const char * function, cpl_error_code code, - const char * file, unsigned line) +static cpl_error * +cpl_error_fill(const char *function, + cpl_error_code code, + const char *file, + unsigned line) { - - cpl_error * error = cpl_errorstate_append(); + cpl_error *error = cpl_errorstate_append(); cx_assert(error != NULL); cx_assert(code != CPL_ERROR_NONE); @@ -850,14 +853,16 @@ if (function == NULL) { error->function[0] = '\0'; - } else { + } + else { (void)strncpy(error->function, function, MAX_NAME_LENGTH); error->function[MAX_NAME_LENGTH] = '\0'; } if (file == NULL) { error->file[0] = '\0'; - } else { + } + else { (void)strncpy(error->file, file, MAX_FILE_LENGTH); error->file[MAX_FILE_LENGTH] = '\0'; } @@ -865,7 +870,6 @@ error->msg[0] = '\0'; return error; - } /* @@ -883,22 +887,24 @@ * CPL_ERROR_HISTORY_LOST. * @see cpl_error_set_message_macro() */ -static -cpl_error_code cpl_error_set_message_macro_(const char * function, - cpl_error_code code, - const char * file, unsigned line, - const char * text, va_list arglist) +static cpl_error_code +cpl_error_set_message_macro_(const char *function, + cpl_error_code code, + const char *file, + unsigned line, + const char *text, + va_list arglist) { /* Check copied from cpl_error_set_message_one_macro() */ - char * message = (text != NULL && text[0] != '\0' && - (text[0] != ' ' || text[1] != '\0')) - ? cpl_vsprintf(text, arglist) : NULL; - const char * usemsg = message ? message : text; - - const cpl_error_code lcode = cpl_error_set_message_one_macro(function, code, - file, line, - usemsg); - cpl_free((void*)message); + char *message = + (text != NULL && text[0] != '\0' && (text[0] != ' ' || text[1] != '\0')) + ? cpl_vsprintf(text, arglist) + : NULL; + const char *usemsg = message ? message : text; + + const cpl_error_code lcode = + cpl_error_set_message_one_macro(function, code, file, line, usemsg); + cpl_free((void *)message); return lcode; } @@ -918,23 +924,22 @@ * CPL_ERROR_HISTORY_LOST. * @see cpl_error_set_message_macro_() */ -cpl_error_code cpl_error_set_message_one_macro(const char * function, - cpl_error_code code, - const char * file, - unsigned line, - const char * text) +cpl_error_code +cpl_error_set_message_one_macro(const char *function, + cpl_error_code code, + const char *file, + unsigned line, + const char *text) { - - const cpl_error_code lcode = code == CPL_ERROR_HISTORY_LOST - ? CPL_ERROR_UNSPECIFIED : code; + const cpl_error_code lcode = + code == CPL_ERROR_HISTORY_LOST ? CPL_ERROR_UNSPECIFIED : code; #ifdef HAVE_LIBPTHREAD pthread_rwlock_rdlock(&cpl_lock_error_read_only); #endif if (!cpl_error_read_only && code != CPL_ERROR_NONE) { - - cpl_error * error = cpl_error_fill(function, lcode, file, line); + cpl_error *error = cpl_error_fill(function, lcode, file, line); if (text != NULL && text[0] != '\0' && (text[0] != ' ' || text[1] != '\0')) { @@ -946,12 +951,11 @@ /* Concatenate the standard message and the user supplied message */ - cx_assert( error != NULL ); + cx_assert(error != NULL); (void)cx_snprintf((cxchar *)error->msg, (cxsize)CPL_ERROR_MAX_MESSAGE_LENGTH, (const cxchar *)"%s: %s", - cpl_error_get_message_default(lcode), - text); + cpl_error_get_message_default(lcode), text); } } @@ -960,5 +964,4 @@ #endif return lcode; - } diff -Nru cpl-7.1.4+ds/cplcore/cpl_error.h cpl-7.2.2+ds/cplcore/cpl_error.h --- cpl-7.1.4+ds/cplcore/cpl_error.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_error.h 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -25,7 +25,7 @@ #include #include - + CPL_BEGIN_DECLS /* @@ -65,17 +65,17 @@ */ /*----------------------------------------------------------------------------*/ #ifndef CPL_HAVE_VA_ARGS -# if !defined __STDC_VERSION__ && defined __STRICT_ANSI__ - /* (llvm-)gcc -ansi and (llvm-)gcc -std=c89 do not define __STDC_VERSION__ +#if !defined __STDC_VERSION__ && defined __STRICT_ANSI__ +/* (llvm-)gcc -ansi and (llvm-)gcc -std=c89 do not define __STDC_VERSION__ but they do define __STRICT_ANSI__ */ -# define CPL_HAVE_VA_ARGS 0 -# else - /* (llvm-)gcc with other language standards (incl. gnu89 (equivalent to +#define CPL_HAVE_VA_ARGS 0 +#else +/* (llvm-)gcc with other language standards (incl. gnu89 (equivalent to no language specification), iso9899:199409, c99) reaches this point */ - /* Sunstudio 12.1 c99 reaches this point since it defines __STDC_VERSION__ +/* Sunstudio 12.1 c99 reaches this point since it defines __STDC_VERSION__ to 199901L as expected (it also defines __STRICT_ANSI__) */ -# define CPL_HAVE_VA_ARGS 1 -# endif +#define CPL_HAVE_VA_ARGS 1 +#endif #endif /*----------------------------------------------------------------------------*/ @@ -170,27 +170,34 @@ /*----------------------------------------------------------------------------*/ #if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS == 1 || defined DOXYGEN_SKIP -#define cpl_error_ensure(CONDITION, CODE, ACTION, ...) \ - do if (CPL_UNLIKELY(!(CONDITION))) { \ - /* Evaluate exactly once using a name-space protected variable name */ \ - const cpl_error_code cpl_ensure_error = (CODE); \ - (void)cpl_error_set_message_macro(cpl_func, cpl_ensure_error \ - ? cpl_ensure_error : \ - CPL_ERROR_UNSPECIFIED, \ - __FILE__, __LINE__, __VA_ARGS__); \ - ACTION; \ - } while (0) +#define cpl_error_ensure(CONDITION, CODE, ACTION, ...) \ + do \ + if (CPL_UNLIKELY(!(CONDITION))) { \ + /* Evaluate exactly once using a name-space protected variable name */ \ + const cpl_error_code cpl_ensure_error = (CODE); \ + (void)cpl_error_set_message_macro(cpl_func, \ + cpl_ensure_error \ + ? cpl_ensure_error \ + : CPL_ERROR_UNSPECIFIED, \ + __FILE__, __LINE__, \ + __VA_ARGS__); \ + ACTION; \ + } \ + while (0) #else -#define cpl_error_ensure(CONDITION, CODE, ACTION, MSG) \ - do if (CPL_UNLIKELY(!(CONDITION))) { \ - /* Evaluate exactly once using a name-space protected variable name */ \ - const cpl_error_code cpl_ensure_error = (CODE); \ - (void)cpl_error_set_message_one_macro(cpl_func, cpl_ensure_error \ - ? cpl_ensure_error : \ - CPL_ERROR_UNSPECIFIED, \ - __FILE__, __LINE__, MSG); \ - ACTION; \ - } while (0) +#define cpl_error_ensure(CONDITION, CODE, ACTION, MSG) \ + do \ + if (CPL_UNLIKELY(!(CONDITION))) { \ + /* Evaluate exactly once using a name-space protected variable name */ \ + const cpl_error_code cpl_ensure_error = (CODE); \ + (void)cpl_error_set_message_one_macro(cpl_func, \ + cpl_ensure_error \ + ? cpl_ensure_error \ + : CPL_ERROR_UNSPECIFIED, \ + __FILE__, __LINE__, MSG); \ + ACTION; \ + } \ + while (0) #endif @@ -211,8 +218,8 @@ */ /*----------------------------------------------------------------------------*/ -#define cpl_ensure(BOOL, ERRCODE, RETURN) \ - cpl_error_ensure(BOOL, ERRCODE, return(RETURN), " ") +#define cpl_ensure(BOOL, ERRCODE, RETURN) \ + cpl_error_ensure(BOOL, ERRCODE, return (RETURN), " ") /*----------------------------------------------------------------------------*/ /** @@ -225,8 +232,8 @@ */ /*----------------------------------------------------------------------------*/ -#define cpl_ensure_code(BOOL, ERRCODE) \ - cpl_error_ensure(BOOL, ERRCODE, return(cpl_error_get_code()), " ") +#define cpl_ensure_code(BOOL, ERRCODE) \ + cpl_error_ensure(BOOL, ERRCODE, return (cpl_error_get_code()), " ") /** @@ -248,7 +255,7 @@ */ #define cpl_error_set(function, code) \ - cpl_error_set_message_macro(function, code, __FILE__, __LINE__, " ") + cpl_error_set_message_macro(function, code, __FILE__, __LINE__, " ") /** @@ -275,9 +282,9 @@ * @hideinitializer */ -#define cpl_error_set_where(function) \ - cpl_error_set_message_macro(function, cpl_error_get_code(), \ - __FILE__, __LINE__, " ") +#define cpl_error_set_where(function) \ + cpl_error_set_message_macro(function, cpl_error_get_code(), __FILE__, \ + __LINE__, " ") /** * @ingroup cpl_error @@ -341,10 +348,10 @@ * @hideinitializer */ #if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS == 1 || defined DOXYGEN_SKIP -#define cpl_error_set_message(function, code, ...) \ +#define cpl_error_set_message(function, code, ...) \ cpl_error_set_message_macro(function, code, __FILE__, __LINE__, __VA_ARGS__) #else -#define cpl_error_set_message(function, code, text) \ +#define cpl_error_set_message(function, code, text) \ cpl_error_set_message_one_macro(function, code, __FILE__, __LINE__, text) #endif @@ -384,8 +391,9 @@ */ -enum _cpl_error_code_ { - CPL_ERROR_NONE = 0, +enum _cpl_error_code_ +{ + CPL_ERROR_NONE = 0, /**< No error condition */ CPL_ERROR_UNSPECIFIED = 1, /**< An unspecified error */ @@ -395,37 +403,37 @@ /**< Could not duplicate output stream */ CPL_ERROR_ASSIGNING_STREAM, /**< Could not associate a stream with a file descriptor */ - CPL_ERROR_FILE_IO, + CPL_ERROR_FILE_IO, /**< Permission denied */ - CPL_ERROR_BAD_FILE_FORMAT, + CPL_ERROR_BAD_FILE_FORMAT, /**< Input file had not the expected format */ CPL_ERROR_FILE_ALREADY_OPEN, /**< Attempted to open a file twice */ - CPL_ERROR_FILE_NOT_CREATED, + CPL_ERROR_FILE_NOT_CREATED, /**< Could not create a file */ - CPL_ERROR_FILE_NOT_FOUND, + CPL_ERROR_FILE_NOT_FOUND, /**< A specified file or directory was not found */ - CPL_ERROR_DATA_NOT_FOUND, + CPL_ERROR_DATA_NOT_FOUND, /**< Data searched within a valid object were not found */ - CPL_ERROR_ACCESS_OUT_OF_RANGE, + CPL_ERROR_ACCESS_OUT_OF_RANGE, /**< Data were accessed beyond boundaries */ - CPL_ERROR_NULL_INPUT, + CPL_ERROR_NULL_INPUT, /**< A @c NULL pointer was found where a valid pointer was expected */ - CPL_ERROR_INCOMPATIBLE_INPUT, + CPL_ERROR_INCOMPATIBLE_INPUT, /**< Data that had to be processed together did not match */ - CPL_ERROR_ILLEGAL_INPUT, + CPL_ERROR_ILLEGAL_INPUT, /**< Illegal values were detected */ - CPL_ERROR_ILLEGAL_OUTPUT, + CPL_ERROR_ILLEGAL_OUTPUT, /**< A given operation would have generated an illegal object */ - CPL_ERROR_UNSUPPORTED_MODE, + CPL_ERROR_UNSUPPORTED_MODE, /**< The requested functionality is not supported */ - CPL_ERROR_SINGULAR_MATRIX, + CPL_ERROR_SINGULAR_MATRIX, /**< Could not invert a matrix */ - CPL_ERROR_DIVISION_BY_ZERO, + CPL_ERROR_DIVISION_BY_ZERO, /**< Attempted to divide a number by zero */ - CPL_ERROR_TYPE_MISMATCH, + CPL_ERROR_TYPE_MISMATCH, /**< Data were not of the expected type */ - CPL_ERROR_INVALID_TYPE, + CPL_ERROR_INVALID_TYPE, /**< Data type was unsupported or invalid */ CPL_ERROR_CONTINUE, /**< An iterative process did not converge */ @@ -450,32 +458,35 @@ Function prototypes -----------------------------------------------------------------------------*/ -void cpl_error_reset(void); -cpl_error_code -cpl_error_set_message_macro(const char *, cpl_error_code, - const char *, unsigned, - const char *, ...) CPL_ATTR_PRINTF(5,6) +void cpl_error_reset(void); +cpl_error_code cpl_error_set_message_macro(const char *, + cpl_error_code, + const char *, + unsigned, + const char *, + ...) CPL_ATTR_PRINTF(5, 6) #ifdef CPL_HAVE_ATTR_NONNULL __attribute__((nonnull(3))) #endif - ; + ; -cpl_error_code -cpl_error_set_message_one_macro(const char *, cpl_error_code, - const char *, unsigned, - const char *) +cpl_error_code cpl_error_set_message_one_macro(const char *, + cpl_error_code, + const char *, + unsigned, + const char *) #ifdef CPL_HAVE_ATTR_NONNULL __attribute__((nonnull(3))) #endif ; -cpl_error_code cpl_error_get_code(void) CPL_ATTR_PURE; -const char *cpl_error_get_message(void) CPL_ATTR_PURE; -const char *cpl_error_get_message_default(cpl_error_code) CPL_ATTR_CONST; -const char *cpl_error_get_function(void) CPL_ATTR_PURE; -const char *cpl_error_get_file(void) CPL_ATTR_PURE; -unsigned cpl_error_get_line(void) CPL_ATTR_PURE; -const char *cpl_error_get_where(void) CPL_ATTR_PURE; +cpl_error_code cpl_error_get_code(void) CPL_ATTR_PURE; +const char *cpl_error_get_message(void) CPL_ATTR_PURE; +const char *cpl_error_get_message_default(cpl_error_code) CPL_ATTR_CONST; +const char *cpl_error_get_function(void) CPL_ATTR_PURE; +const char *cpl_error_get_file(void) CPL_ATTR_PURE; +unsigned cpl_error_get_line(void) CPL_ATTR_PURE; +const char *cpl_error_get_where(void) CPL_ATTR_PURE; CPL_END_DECLS diff -Nru cpl-7.1.4+ds/cplcore/cpl_error_impl.h cpl-7.2.2+ds/cplcore/cpl_error_impl.h --- cpl-7.1.4+ds/cplcore/cpl_error_impl.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_error_impl.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -79,7 +79,7 @@ * @see cpl_error_set_message() */ -#define cpl_error_set_message_(code, ...) \ +#define cpl_error_set_message_(code, ...) \ cpl_error_set_message(cpl_func, code, __VA_ARGS__) @@ -114,10 +114,10 @@ * * @hideinitializer */ -#define cpl_error_set_fits(code, fitscode, fitsfunction, ...) \ - cpl_error_set_fits_macro(cpl_func, code, fitscode, \ - CPL_STRINGIFY(fitsfunction), \ - __FILE__, __LINE__, __VA_ARGS__) +#define cpl_error_set_fits(code, fitscode, fitsfunction, ...) \ + cpl_error_set_fits_macro(cpl_func, code, fitscode, \ + CPL_STRINGIFY(fitsfunction), __FILE__, __LINE__, \ + __VA_ARGS__) /** * @ingroup cpl_error @@ -148,9 +148,9 @@ * * @hideinitializer */ -#define cpl_error_set_regex(code, regcode, preg, ...) \ - cpl_error_set_regex_macro(cpl_func, code, regcode, preg, \ - __FILE__, __LINE__, __VA_ARGS__) +#define cpl_error_set_regex(code, regcode, preg, ...) \ + cpl_error_set_regex_macro(cpl_func, code, regcode, preg, __FILE__, \ + __LINE__, __VA_ARGS__) #ifndef CPL_WCS_INSTALLED /* Make sure the WCS error macro can be invoked also when @@ -196,44 +196,58 @@ * * @hideinitializer */ -#define cpl_error_set_wcs(code, wcscode, wcsfunction, ...) \ - cpl_error_set_wcs_macro(cpl_func, code, wcscode, wcsfunction, \ - wcs_errmsg, __FILE__, __LINE__, __VA_ARGS__) - -struct _cpl_error_ { - cpl_error_code code; - unsigned line; - char function[MAX_NAME_LENGTH+1]; - char file[MAX_FILE_LENGTH+1]; - char msg[CPL_ERROR_MAX_MESSAGE_LENGTH]; +#define cpl_error_set_wcs(code, wcscode, wcsfunction, ...) \ + cpl_error_set_wcs_macro(cpl_func, code, wcscode, wcsfunction, wcs_errmsg, \ + __FILE__, __LINE__, __VA_ARGS__) + +struct _cpl_error_ +{ + cpl_error_code code; + unsigned line; + char function[MAX_NAME_LENGTH + 1]; + char file[MAX_FILE_LENGTH + 1]; + char msg[CPL_ERROR_MAX_MESSAGE_LENGTH]; }; /*----------------------------------------------------------------------------- Prototypes of private functions -----------------------------------------------------------------------------*/ -cpl_error * cpl_errorstate_append(void); -const cpl_error * cpl_errorstate_find(void) CPL_ATTR_PURE; +cpl_error *cpl_errorstate_append(void); +const cpl_error *cpl_errorstate_find(void) CPL_ATTR_PURE; cpl_boolean cpl_error_is_set(void) CPL_ATTR_PURE; cpl_boolean cpl_error_is_readonly(void) CPL_ATTR_PURE; void cpl_error_set_readonly(void); void cpl_error_reset_readonly(void); -cpl_error_code -cpl_error_set_fits_macro(const char *, cpl_error_code, int, - const char *, const char *, - unsigned, const char *, ...) CPL_ATTR_PRINTF(7,8); - -cpl_error_code -cpl_error_set_regex_macro(const char *, cpl_error_code, int, - const regex_t *, const char *, - unsigned, const char *, ...) CPL_ATTR_PRINTF(7,8); - -cpl_error_code -cpl_error_set_wcs_macro(const char *, cpl_error_code, int, - const char *, const char *[], const char *, - unsigned, const char *, ...) CPL_ATTR_PRINTF(8,9); +cpl_error_code cpl_error_set_fits_macro(const char *, + cpl_error_code, + int, + const char *, + const char *, + unsigned, + const char *, + ...) CPL_ATTR_PRINTF(7, 8); + +cpl_error_code cpl_error_set_regex_macro(const char *, + cpl_error_code, + int, + const regex_t *, + const char *, + unsigned, + const char *, + ...) CPL_ATTR_PRINTF(7, 8); + +cpl_error_code cpl_error_set_wcs_macro(const char *, + cpl_error_code, + int, + const char *, + const char *[], + const char *, + unsigned, + const char *, + ...) CPL_ATTR_PRINTF(8, 9); #ifdef HAVE_LIBPTHREAD void cpl_error_init_locks(void); diff -Nru cpl-7.1.4+ds/cplcore/cpl_errorstate.c cpl-7.2.2+ds/cplcore/cpl_errorstate.c --- cpl-7.1.4+ds/cplcore/cpl_errorstate.c 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_errorstate.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -60,18 +60,18 @@ Internal structures -----------------------------------------------------------------------------*/ -static struct { - +static struct +{ /* This struct may only be accessed when cpl_error_is_set() is true */ - size_t current; /* The number of the current CPL error in the history */ + size_t current; /* The number of the current CPL error in the history */ /* Numbering of errors start with 1. */ /* When a new CPL error is created, estate.current is incremented holding the number of that error */ - size_t highest; /* The highest number reached in the history */ + size_t highest; /* The highest number reached in the history */ /* cpl_errorstate_set() may not increase estate.current above this value, assert( estate.current <= estate.highest ); */ @@ -150,10 +150,12 @@ /*----------------------------------------------------------------------------- Private Function Declarations -----------------------------------------------------------------------------*/ -static void cpl_errorstate_dump_one_level(void (*)(const char *, - const char *, ...) - CPL_ATTR_PRINTF(2, 3), - unsigned, unsigned, unsigned); +static void +cpl_errorstate_dump_one_level(void (*)(const char *, const char *, ...) + CPL_ATTR_PRINTF(2, 3), + unsigned, + unsigned, + unsigned); /*----------------------------------------------------------------------------- Functions code @@ -186,9 +188,9 @@ */ /*----------------------------------------------------------------------------*/ -cpl_errorstate cpl_errorstate_get(void) +cpl_errorstate +cpl_errorstate_get(void) { - /* The return value is defined as the number of errors that have happened (since the most recent reset of the error state). This definition should be changable without effects to the API. @@ -220,15 +222,17 @@ */ /*----------------------------------------------------------------------------*/ -void cpl_errorstate_set(cpl_errorstate self) +void +cpl_errorstate_set(cpl_errorstate self) { - const size_t myself = (const size_t)self; if (myself == 0) { cpl_error_reset(); - } else if (myself < estate.current) { - if (!cpl_error_is_readonly()) estate.current = myself; + } + else if (myself < estate.current) { + if (!cpl_error_is_readonly()) + estate.current = myself; } } @@ -241,14 +245,15 @@ */ /*----------------------------------------------------------------------------*/ -cpl_boolean cpl_errorstate_is_equal(cpl_errorstate self) +cpl_boolean +cpl_errorstate_is_equal(cpl_errorstate self) { - const size_t myself = (const size_t)self; if (cpl_error_is_set()) { return myself == estate.current ? CPL_TRUE : CPL_FALSE; - } else { + } + else { return myself == 0 ? CPL_TRUE : CPL_FALSE; } } @@ -302,16 +307,15 @@ */ /*----------------------------------------------------------------------------*/ -void cpl_errorstate_dump(cpl_errorstate self, - cpl_boolean reverse, - void (*dump_one)(unsigned, unsigned, unsigned)) +void +cpl_errorstate_dump(cpl_errorstate self, + cpl_boolean reverse, + void (*dump_one)(unsigned, unsigned, unsigned)) { - if (!cpl_error_is_readonly()) { - cpl_boolean did_call = CPL_FALSE; - void (*mydump_one)(unsigned, unsigned, unsigned) - = dump_one ? dump_one : cpl_errorstate_dump_one; + void (*mydump_one)(unsigned, unsigned, unsigned) = + dump_one ? dump_one : cpl_errorstate_dump_one; /* Put CPL error system into read-only mode, to prevent changes by (*dump_one)() */ @@ -326,24 +330,26 @@ if (oldest <= newest) { /* There is at least one error to dump */ const size_t first = reverse ? newest : oldest; - const size_t last = reverse ? oldest : newest; - size_t ilost = 0; + const size_t last = reverse ? oldest : newest; + size_t ilost = 0; /* The iteration through the sequence of errors is done by modifying estate.current */ if (reverse) { cx_assert(estate.current == first); - } else { + } + else { estate.current = first; } - for (; ; reverse ? estate.current-- : estate.current++) { - cx_assert( estate.current > 0 ); + for (;; reverse ? estate.current-- : estate.current++) { + cx_assert(estate.current > 0); if (dump_one == NULL && cpl_error_get_code() == CPL_ERROR_HISTORY_LOST) { ilost++; - } else { + } + else { if (ilost > 0) { cpl_msg_error(cpl_func, "Lost %zu CPL error(s)", ilost); @@ -352,7 +358,8 @@ (*mydump_one)((unsigned)estate.current, (unsigned)first, (unsigned)last); } - if (estate.current == last) break; + if (estate.current == last) + break; } if (ilost > 0) { cpl_msg_error(cpl_func, "Lost %zu CPL error(s)", ilost); @@ -362,7 +369,8 @@ if (reverse) { /* Reestablish the CPL error state */ estate.current = newest; - } else { + } + else { cx_assert(estate.current == newest); } did_call = CPL_TRUE; @@ -408,9 +416,9 @@ */ /*----------------------------------------------------------------------------*/ -void cpl_errorstate_dump_one(unsigned self, unsigned first, unsigned last) +void +cpl_errorstate_dump_one(unsigned self, unsigned first, unsigned last) { - cpl_errorstate_dump_one_level(cpl_msg_error, self, first, last); } @@ -426,10 +434,9 @@ */ /*----------------------------------------------------------------------------*/ -void cpl_errorstate_dump_one_warning(unsigned self, unsigned first, - unsigned last) +void +cpl_errorstate_dump_one_warning(unsigned self, unsigned first, unsigned last) { - cpl_errorstate_dump_one_level(cpl_msg_warning, self, first, last); } @@ -444,9 +451,9 @@ */ /*----------------------------------------------------------------------------*/ -void cpl_errorstate_dump_one_info(unsigned self, unsigned first, unsigned last) +void +cpl_errorstate_dump_one_info(unsigned self, unsigned first, unsigned last) { - cpl_errorstate_dump_one_level(cpl_msg_info, self, first, last); } @@ -461,9 +468,9 @@ */ /*----------------------------------------------------------------------------*/ -void cpl_errorstate_dump_one_debug(unsigned self, unsigned first, unsigned last) +void +cpl_errorstate_dump_one_debug(unsigned self, unsigned first, unsigned last) { - cpl_errorstate_dump_one_level(cpl_msg_debug, self, first, last); } @@ -478,11 +485,10 @@ */ /*----------------------------------------------------------------------------*/ -cpl_error * cpl_errorstate_append(void) +cpl_error * +cpl_errorstate_append(void) { - if (cpl_error_is_set()) { - if (estate.lowest > estate.current) { /* The details of the current CPL error have been lost */ @@ -493,22 +499,23 @@ estate.newest = estate.oldest; /* When returning, estate.lowest == estate.current */ - estate.lowest = estate.current+1; - } else if (estate.highest == estate.current) { - + estate.lowest = estate.current + 1; + } + else if (estate.highest == estate.current) { /* The current error is the newest */ /* Advance the index of the newest entry in the CPL error history */ - if (++estate.newest == CPL_ERROR_HISTORY_SIZE) estate.newest = 0; + if (++estate.newest == CPL_ERROR_HISTORY_SIZE) + estate.newest = 0; /* If the history is full, then let the oldest be overwritten */ if (estate.newest == estate.oldest) { estate.lowest++; - if (++estate.oldest == CPL_ERROR_HISTORY_SIZE) estate.oldest = 0; + if (++estate.oldest == CPL_ERROR_HISTORY_SIZE) + estate.oldest = 0; } - - } else { - + } + else { const size_t diff = estate.highest - estate.current; cx_assert(diff < CPL_ERROR_HISTORY_SIZE); @@ -522,17 +529,18 @@ if (estate.newest < diff - 1) { estate.newest += CPL_ERROR_HISTORY_SIZE - (diff - 1); - } else { + } + else { estate.newest -= diff - 1; } } estate.current++; - - } else { + } + else { /* Initialize a new history of errors */ estate.lowest = estate.current = 1; - estate.newest = estate.oldest = 0; + estate.newest = estate.oldest = 0; /* (newest and oldest could also be set to any other value less than CPL_ERROR_HISTORY_SIZE) */ } @@ -557,41 +565,39 @@ */ /*----------------------------------------------------------------------------*/ -const cpl_error * cpl_errorstate_find(void) +const cpl_error * +cpl_errorstate_find(void) { - - const cpl_error * self; + const cpl_error *self; /* assert(cpl_error_is_set()); */ if (estate.lowest > estate.current) { /* The details of the current CPL error have been lost */ - static const cpl_error lost = {CPL_ERROR_HISTORY_LOST, 0, "", "", ""}; + static const cpl_error lost = { CPL_ERROR_HISTORY_LOST, 0, "", "", "" }; self = &lost; - - } else { - + } + else { /* The current CPL error is the newest */ /* or */ /* The current CPL error is preserved, but is not the newest */ const size_t diff = estate.highest - estate.current; - const size_t current = estate.newest < diff - ? estate.newest + (CPL_ERROR_HISTORY_SIZE - diff) - : estate.newest - diff; + const size_t current = + estate.newest < diff + ? estate.newest + (CPL_ERROR_HISTORY_SIZE - diff) + : estate.newest - diff; /* assert(diff < CPL_ERROR_HISTORY_SIZE); */ self = error_history + current; - } return self; - } @@ -607,47 +613,50 @@ */ /*----------------------------------------------------------------------------*/ -static -void cpl_errorstate_dump_one_level(void (*messenger)(const char *, - const char *, ...), - unsigned self, unsigned first, - unsigned last) +static void +cpl_errorstate_dump_one_level(void (*messenger)(const char *, + const char *, + ...), + unsigned self, + unsigned first, + unsigned last) { - - const cpl_boolean is_reverse = first > last ? CPL_TRUE : CPL_FALSE; - const unsigned newest = is_reverse ? first : last; - const unsigned oldest = is_reverse ? last : first; - const char * revmsg = is_reverse ? " in reverse order" : ""; + const unsigned newest = is_reverse ? first : last; + const unsigned oldest = is_reverse ? last : first; + const char *revmsg = is_reverse ? " in reverse order" : ""; - cx_assert( messenger != NULL ); - cx_assert( oldest <= self ); - cx_assert( newest >= self ); + cx_assert(messenger != NULL); + cx_assert(oldest <= self); + cx_assert(newest >= self); if (newest == 0) { messenger(cpl_func, "No error(s) to dump"); - cx_assert( oldest == 0); - } else { - cx_assert( oldest > 0); - cx_assert( newest >= oldest); + cx_assert(oldest == 0); + } + else { + cx_assert(oldest > 0); + cx_assert(newest >= oldest); if (self == first) { if (oldest == 1) { messenger(cpl_func, "Dumping all %u error(s)%s:", newest, revmsg); - } else { - messenger(cpl_func, "Dumping the %u most recent error(s) " - "out of a total of %u errors%s:", - newest - oldest + 1, newest, revmsg); + } + else { + messenger(cpl_func, + "Dumping the %u most recent error(s) " + "out of a total of %u errors%s:", + newest - oldest + 1, newest, revmsg); } cpl_msg_indent_more(); } messenger(cpl_func, "[%u/%u] '%s' (%u) at %s", self, newest, - cpl_error_get_message(), cpl_error_get_code(), - cpl_error_get_where()); + cpl_error_get_message(), cpl_error_get_code(), + cpl_error_get_where()); - if (self == last) cpl_msg_indent_less(); + if (self == last) + cpl_msg_indent_less(); } } - diff -Nru cpl-7.1.4+ds/cplcore/cpl_errorstate.h cpl-7.2.2+ds/cplcore/cpl_errorstate.h --- cpl-7.1.4+ds/cplcore/cpl_errorstate.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_errorstate.h 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -23,7 +23,7 @@ #include #include - + CPL_BEGIN_DECLS /*----------------------------------------------------------------------------- @@ -34,7 +34,7 @@ #define CPL_ERROR_HISTORY_SIZE 20 #endif -typedef const void * cpl_errorstate; +typedef const void *cpl_errorstate; /*----------------------------------------------------------------------------- Prototypes of functions diff -Nru cpl-7.1.4+ds/cplcore/cpl_filter.h cpl-7.2.2+ds/cplcore/cpl_filter.h --- cpl-7.1.4+ds/cplcore/cpl_filter.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_filter.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -254,7 +254,9 @@ CPL_FILTER_MORPHO, /**< - A morphological filter (for a @c cpl_image). The kernel elements are + A morphological filter (for a @c cpl_image). The kernel elements + are used as weights on the sorted values covered by the kernel. + The kernel elements are normalized with the sum of their absolute values. This implies that there must be at least one non-zero element in the kernel. The normalisation makes the kernel useful for filtering where flux @@ -311,4 +313,4 @@ CPL_END_DECLS -#endif +#endif diff -Nru cpl-7.1.4+ds/cplcore/cpl_filter_median.c cpl-7.2.2+ds/cplcore/cpl_filter_median.c --- cpl-7.1.4+ds/cplcore/cpl_filter_median.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_filter_median.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -68,7 +68,8 @@ #endif /** @cond */ -typedef struct ADDTYPE(dheap) { +typedef struct ADDTYPE(dheap) +{ unsigned *heaps; /* Double binary heap and ADDTYPE(median) element. Values are pixel buffer indices in the current filtering window. @@ -78,7 +79,8 @@ heaps[m+1] ... heaps[2m] : a minimum heap of pixels with values greater than ADDTYPE(median) */ - unsigned *B; /* Size Nx x Ny map from image positions to double heap positions. + unsigned + *B; /* Size Nx x Ny map from image positions to double heap positions. This is the inverse map of the heaps[] array, B[heaps[i]] = i. It allows constant time look-up of any pixel in the double heap @@ -89,7 +91,8 @@ size (2rx+1)(2ry+1)^2. However, in that case the overall execution time would be dominated by mapping pixels to positions in B. */ - unsigned *SCA; /* Array Nx*(2Ry+1) of sorted column arrays. Values are image pixel + unsigned * + SCA; /* Array Nx*(2Ry+1) of sorted column arrays. Values are image pixel buffer indices. Each column array is sorted according to image buffer pixel values. This buffer is laid out in column major order to allow fast iteration within each column array (i.e. @@ -97,11 +100,11 @@ {S[x*(2Ry+1)], ..., S[x*(2Ry+1) + 2Ry]}) */ const PIX_TYPE *image; - unsigned rx; //kernel radius - unsigned ry; //kernel radius - unsigned Nx; //image width - unsigned Ny; //image height - unsigned m; //kernel window half size, must be positive + unsigned rx; //kernel radius + unsigned ry; //kernel radius + unsigned Nx; //image width + unsigned Ny; //image height + unsigned m; //kernel window half size, must be positive unsigned Rx; //2rx + 1 unsigned Ry; //2ry + 1 } ADDTYPE(dheap); @@ -115,13 +118,13 @@ @param i index in SCA array @param j index in SCA array */ -#define S_SWAP(SCA, i, j) \ -do { \ - const unsigned SCAi = SCA[i]; \ - const unsigned SCAj = SCA[j]; \ - SCA[i] = SCAj; \ - SCA[j] = SCAi; \ -} while(0) +#define S_SWAP(SCA, i, j) \ + do { \ + const unsigned SCAi = SCA[i]; \ + const unsigned SCAj = SCA[j]; \ + SCA[i] = SCAj; \ + SCA[j] = SCAi; \ + } while (0) #define BITS 64 @@ -134,13 +137,11 @@ SCA is sorted in increasing order by image[SCA[i]] */ -static void -ADDTYPE(qsort_int)(unsigned *SCA, - unsigned n, const PIX_TYPE *image) +static void ADDTYPE(qsort_int)(unsigned *SCA, unsigned n, const PIX_TYPE *image) { int i, ir, j, k, l; int i_stack[BITS]; - int j_stack ; + int j_stack; int a; PIX_TYPE ia; @@ -148,64 +149,73 @@ //assure( n <= 1 << BITS ); /* generates warnings */ /* true because no-one ever wants to filter with a radius larger than 2^BITS */ - ir = n ; - l = 1 ; - j_stack = 0 ; + ir = n; + l = 1; + j_stack = 0; while (1) { - if (ir-l < 7) { - for (j=l+1 ; j<=ir ; j++) { - a = SCA[j-1]; + if (ir - l < 7) { + for (j = l + 1; j <= ir; j++) { + a = SCA[j - 1]; ia = image[a]; - for (i=j-1 ; i>=1 ; i--) { - if (image[SCA[i-1]] <= ia) break; - SCA[i] = SCA[i-1]; + for (i = j - 1; i >= 1; i--) { + if (image[SCA[i - 1]] <= ia) + break; + SCA[i] = SCA[i - 1]; } SCA[i] = a; } - if (j_stack == 0) break; - ir = i_stack[j_stack-- -1]; - l = i_stack[j_stack-- -1]; - } else { + if (j_stack == 0) + break; + ir = i_stack[j_stack-- - 1]; + l = i_stack[j_stack-- - 1]; + } + else { /* The following is buggy and has O(n^2) behaviour if the input array is sorted in reverse order. For maximum performance we should select the pivot randomly, (however this step is used only in the initialization of the sorted column arrays, so be it) */ - k = (l+ir) >> 1; - S_SWAP(SCA, k-1, l); - if (image[SCA[l]] > image[SCA[ir-1]]) { - S_SWAP(SCA, l, ir-1); + k = (l + ir) >> 1; + S_SWAP(SCA, k - 1, l); + if (image[SCA[l]] > image[SCA[ir - 1]]) { + S_SWAP(SCA, l, ir - 1); } - if (image[SCA[l-1]] > image[SCA[ir-1]]) { - S_SWAP(SCA, l-1, ir-1); + if (image[SCA[l - 1]] > image[SCA[ir - 1]]) { + S_SWAP(SCA, l - 1, ir - 1); } - if (image[SCA[l]] > image[SCA[l-1]]) { - S_SWAP(SCA, l, l-1); + if (image[SCA[l]] > image[SCA[l - 1]]) { + S_SWAP(SCA, l, l - 1); } - i = l+1; + i = l + 1; j = ir; - a = SCA[l-1]; + a = SCA[l - 1]; ia = image[a]; for (;;) { - do i++; while (image[SCA[i-1]] < ia); - do j--; while (image[SCA[j-1]] > ia); - if (j < i) break; - S_SWAP(SCA, i-1, j-1); + do + i++; + while (image[SCA[i - 1]] < ia); + do + j--; + while (image[SCA[j - 1]] > ia); + if (j < i) + break; + S_SWAP(SCA, i - 1, j - 1); } - SCA[l-1] = SCA[j-1]; - SCA[j-1] = a; + SCA[l - 1] = SCA[j - 1]; + SCA[j - 1] = a; j_stack += 2; - assert( j_stack <= BITS ); + assert(j_stack <= BITS); - if (ir-i+1 >= j-l) { - i_stack[j_stack-1] = ir; - i_stack[j_stack-2] = i; - ir = j-1; - } else { - i_stack[j_stack-1] = j-1; - i_stack[j_stack-2] = l; + if (ir - i + 1 >= j - l) { + i_stack[j_stack - 1] = ir; + i_stack[j_stack - 2] = i; + ir = j - 1; + } + else { + i_stack[j_stack - 1] = j - 1; + i_stack[j_stack - 2] = l; l = i; } } @@ -220,20 +230,17 @@ @param dh double heap @param x current column */ -static void -ADDTYPE(SCA_init)(ADDTYPE(dheap) *dh, unsigned x) +static void ADDTYPE(SCA_init)(ADDTYPE(dheap) * dh, unsigned x) { unsigned y; - unsigned *SCAx = dh->SCA + (dh->Ry)*x; + unsigned *SCAx = dh->SCA + (dh->Ry) * x; for (y = 0; y < dh->Ry; y++) { - SCAx[y] = x + y*dh->Nx; + SCAx[y] = x + y * dh->Nx; } - ADDTYPE(qsort_int)(SCAx, - dh->Ry, - dh->image); - + ADDTYPE(qsort_int)(SCAx, dh->Ry, dh->image); + return; } @@ -245,17 +252,18 @@ @param yold image row of previous element @param ynew image row of new element */ -static void -ADDTYPE(SCA_replace)(ADDTYPE(dheap) *dh, unsigned x, - unsigned yold, unsigned ynew) +static void ADDTYPE(SCA_replace)(ADDTYPE(dheap) * dh, + unsigned x, + unsigned yold, + unsigned ynew) { unsigned n = dh->Ry; - unsigned *SCAx = dh->SCA + n*x; //start of current column array + unsigned *SCAx = dh->SCA + n * x; //start of current column array const PIX_TYPE *im = dh->image; unsigned i; - unsigned aold = x + yold*dh->Nx; - unsigned anew = x + ynew*dh->Nx; + unsigned aold = x + yold * dh->Nx; + unsigned anew = x + ynew * dh->Nx; /* Do a linear search for the old pixel and replace it with the new. @@ -266,36 +274,30 @@ up to at least r = 64) */ for (i = 0; i < n; i++) { - if (SCAx[i] == aold) break; + if (SCAx[i] == aold) + break; } SCAx[i] = anew; /* The new pixel is not necessarily in it the right place. Bubble until SCAx is again sorted. */ - if (i+1 < n && - im[SCAx[i ]] > - im[SCAx[i+1]]) { - - S_SWAP(SCAx, i , i+1); + if (i + 1 < n && im[SCAx[i]] > im[SCAx[i + 1]]) { + S_SWAP(SCAx, i, i + 1); i++; - - while (i+1 < n && - im[SCAx[i ]] > - im[SCAx[i+1]]) { - S_SWAP(SCAx, i , i+1); + + while (i + 1 < n && im[SCAx[i]] > im[SCAx[i + 1]]) { + S_SWAP(SCAx, i, i + 1); i++; } } else { - while (i >= 1 && - im[SCAx[i ]] < - im[SCAx[i-1]]) { - S_SWAP(SCAx, i , i-1); + while (i >= 1 && im[SCAx[i]] < im[SCAx[i - 1]]) { + S_SWAP(SCAx, i, i - 1); i--; } } - + return; } @@ -308,11 +310,10 @@ @param B image to heap map @param heaps heaps array */ -static void -ADDTYPE(HEAP_SWAP)(unsigned i, - unsigned j, - unsigned int *B, - unsigned int *heaps) +static void ADDTYPE(HEAP_SWAP)(unsigned i, + unsigned j, + unsigned int *B, + unsigned int *heaps) { unsigned ai = heaps[i]; unsigned aj = heaps[j]; @@ -322,7 +323,7 @@ B[aj] = i; B[ai] = j; - return; + return; } /** @@ -330,14 +331,13 @@ @brief Partion double heaps array in ADDTYPE(median) and upper/lower values @param dh double heap with elements in no particular order */ -static void -ADDTYPE(median)(ADDTYPE(dheap) *dh) +static void ADDTYPE(median)(ADDTYPE(dheap) * dh) { - unsigned n = 2 * dh->m + 1; - const unsigned k = (n-1)/2; - unsigned lo = 0; - unsigned hi = n - 1; - + unsigned n = 2 * dh->m + 1; + const unsigned k = (n - 1) / 2; + unsigned lo = 0; + unsigned hi = n - 1; + while (lo < hi) { /* Buggy. We should select the pivot randomly, or there is O(n^2) behaviour for certain inputs */ @@ -346,19 +346,24 @@ unsigned j = hi; do { - while (dh->image[dh->heaps[i]] < pivot) i++; - while (dh->image[dh->heaps[j]] > pivot) j--; + while (dh->image[dh->heaps[i]] < pivot) + i++; + while (dh->image[dh->heaps[j]] > pivot) + j--; if (i <= j) { - if (i != j) ADDTYPE(HEAP_SWAP)(i, j, dh->B, dh->heaps); + if (i != j) + ADDTYPE(HEAP_SWAP)(i, j, dh->B, dh->heaps); i++; j--; } } while (i <= j); - - if (j < k) lo = i; - if (k < i) hi = j; + + if (j < k) + lo = i; + if (k < i) + hi = j; } - + return; } @@ -374,26 +379,23 @@ @param root double heap position @return final position */ -static unsigned -ADDTYPE(bubble_down_gt)(const PIX_TYPE *image, - unsigned *B, - unsigned *heaps, - unsigned m, - unsigned m1, - unsigned root) +static unsigned ADDTYPE(bubble_down_gt)(const PIX_TYPE *image, + unsigned *B, + unsigned *heaps, + unsigned m, + unsigned m1, + unsigned root) { - unsigned end = m-1; + unsigned end = m - 1; while (root * 2 + 1 <= end) { - unsigned child = root*2 + 1; + unsigned child = root * 2 + 1; - if (child < end && - image[heaps[m1 + child]] > - image[heaps[m1 + child + 1]]) { + if (child < end && + image[heaps[m1 + child]] > image[heaps[m1 + child + 1]]) { child = child + 1; } - if (image[heaps[m1 + root]] > - image[heaps[m1 + child]]) { + if (image[heaps[m1 + root]] > image[heaps[m1 + child]]) { ADDTYPE(HEAP_SWAP)(m1 + root, m1 + child, B, heaps); root = child; } @@ -414,22 +416,21 @@ @param child double heap position @return final position */ -static unsigned -ADDTYPE(bubble_up_gt)(const PIX_TYPE *image, - unsigned *B, - unsigned *heaps, - unsigned m1, - unsigned child) +static unsigned ADDTYPE(bubble_up_gt)(const PIX_TYPE *image, + unsigned *B, + unsigned *heaps, + unsigned m1, + unsigned child) { while (child > 0) { const unsigned parent = (child - 1) / 2; - if (image[heaps[m1 + parent]] > - image[heaps[m1 + child]]) { + if (image[heaps[m1 + parent]] > image[heaps[m1 + child]]) { ADDTYPE(HEAP_SWAP)(m1 + parent, m1 + child, B, heaps); child = parent; } - else return child; + else + return child; } return child; } @@ -439,17 +440,13 @@ @brief establish upper heap @param dh double heap */ -static void -ADDTYPE(heapify_gt)(ADDTYPE(dheap) *dh) +static void ADDTYPE(heapify_gt)(ADDTYPE(dheap) * dh) { - int start = dh->m/2-1; + int start = dh->m / 2 - 1; while (start >= 0) { - ADDTYPE(bubble_down_gt)(dh->image, - dh->B, - dh->heaps, - dh->m, - dh->m+1, start); + ADDTYPE(bubble_down_gt) + (dh->image, dh->B, dh->heaps, dh->m, dh->m + 1, start); start = start - 1; } return; @@ -465,22 +462,19 @@ @param root double heap position @return final position */ -static unsigned -ADDTYPE(bubble_down_lt)(const PIX_TYPE *image, - unsigned *B, - unsigned *heaps, - unsigned end, unsigned root) +static unsigned ADDTYPE(bubble_down_lt)(const PIX_TYPE *image, + unsigned *B, + unsigned *heaps, + unsigned end, + unsigned root) { while (root * 2 + 1 <= end) { - unsigned child = root*2 + 1; - - if (child < end && - image[heaps[child]] < - image[heaps[child + 1]]) { + unsigned child = root * 2 + 1; + + if (child < end && image[heaps[child]] < image[heaps[child + 1]]) { child = child + 1; } - if (image[heaps[root]] < - image[heaps[child]]) { + if (image[heaps[root]] < image[heaps[child]]) { ADDTYPE(HEAP_SWAP)(root, child, B, heaps); root = child; } @@ -500,20 +494,20 @@ @param child double heap position @return final position */ -static unsigned -ADDTYPE(bubble_up_lt)(const PIX_TYPE *image, - unsigned *B, - unsigned *heaps, unsigned child) +static unsigned ADDTYPE(bubble_up_lt)(const PIX_TYPE *image, + unsigned *B, + unsigned *heaps, + unsigned child) { while (child > 0) { const unsigned parent = (child - 1) / 2; - if (image[heaps[parent]] < - image[heaps[child]]) { + if (image[heaps[parent]] < image[heaps[child]]) { ADDTYPE(HEAP_SWAP)(parent, child, B, heaps); child = parent; } - else return child; + else + return child; } return child; } @@ -523,34 +517,29 @@ @brief establish lower heap @param dh double heap */ -static void -ADDTYPE(heapify_lt)(ADDTYPE(dheap) *dh) +static void ADDTYPE(heapify_lt)(ADDTYPE(dheap) * dh) { - int start = dh->m/2-1; + int start = dh->m / 2 - 1; while (start >= 0) { - ADDTYPE(bubble_down_lt)(dh->image, - dh->B, - dh->heaps, - dh->m-1, start); + ADDTYPE(bubble_down_lt)(dh->image, dh->B, dh->heaps, dh->m - 1, start); start = start - 1; } return; -} +} /** @internal @brief Initialize double heap @param dh double heap with elements in no particular order */ -static void -ADDTYPE(dheap_establish)(ADDTYPE(dheap) *dh) +static void ADDTYPE(dheap_establish)(ADDTYPE(dheap) * dh) { ADDTYPE(median)(dh); - + ADDTYPE(heapify_lt)(dh); ADDTYPE(heapify_gt)(dh); - + return; } @@ -567,37 +556,40 @@ The double heap, inverse map and SCA invariants are established using the first image window */ -static ADDTYPE(dheap) * -ADDTYPE(dheap_new)(const PIX_TYPE *image, unsigned Nx, unsigned Ny, unsigned rx, unsigned ry) +static ADDTYPE(dheap) * ADDTYPE(dheap_new)(const PIX_TYPE *image, + unsigned Nx, + unsigned Ny, + unsigned rx, + unsigned ry) { ADDTYPE(dheap) *dh = malloc(sizeof(*dh)); - assure( dh != NULL ); - assure( rx > 0 || ry > 0 ); + assure(dh != NULL); + assure(rx > 0 || ry > 0); + + dh->heaps = malloc((2 * rx + 1) * (2 * ry + 1) * sizeof(*dh->heaps)); + dh->B = malloc(Nx * Ny * sizeof(*dh->B)); + dh->SCA = malloc(Nx * (2 * ry + 1) * sizeof(*dh->SCA)); + assure(dh->heaps != NULL); + assure(dh->B != NULL); + assure(dh->SCA != NULL); - dh->heaps = malloc( (2*rx+1)*(2*ry+1) * sizeof(*dh->heaps)); - dh->B = malloc( Nx*Ny * sizeof(*dh->B)); - dh->SCA = malloc( Nx*(2*ry+1) * sizeof(*dh->SCA)); - assure( dh->heaps != NULL ); - assure( dh->B != NULL ); - assure( dh->SCA != NULL ); - dh->image = image; - dh->m = ((2*rx+1)*(2*ry+1))/2; - dh->Nx = Nx; - dh->Ny = Ny; - dh->rx = rx; - dh->ry = ry; - dh->Rx = 2*rx+1; - dh->Ry = 2*ry+1; + dh->m = ((2 * rx + 1) * (2 * ry + 1)) / 2; + dh->Nx = Nx; + dh->Ny = Ny; + dh->rx = rx; + dh->ry = ry; + dh->Rx = 2 * rx + 1; + dh->Ry = 2 * ry + 1; { unsigned k = 0; unsigned x, y; - + for (y = 0; y < dh->Ry; y++) { for (x = 0; x < dh->Rx; x++) { unsigned ai = x + y * dh->Nx; - dh->heaps[k] = ai; + dh->heaps[k] = ai; dh->B[ai] = k; k++; } @@ -607,8 +599,7 @@ { unsigned x; - for (x = 0; x < 2*dh->rx; x++) - { + for (x = 0; x < 2 * dh->rx; x++) { ADDTYPE(SCA_init)(dh, x); } } @@ -621,8 +612,7 @@ @brief double heap destructor @param dh double heap */ -static void -ADDTYPE(dheap_delete)(ADDTYPE(dheap) *dh) +static void ADDTYPE(dheap_delete)(ADDTYPE(dheap) * dh) { free(dh->SCA); free(dh->B); @@ -638,8 +628,7 @@ @param dh double heap @return the ADDTYPE(median) element value */ -static PIX_TYPE -ADDTYPE(dheap_median)(const ADDTYPE(dheap) *dh) +static PIX_TYPE ADDTYPE(dheap_median)(const ADDTYPE(dheap) * dh) { return dh->image[dh->heaps[dh->m]]; } @@ -672,22 +661,21 @@ the current element into place. */ -static void -ADDTYPE(dheap_replace)(const PIX_TYPE *image, - unsigned *B, - unsigned *heaps, - mybool *pprev_was_larger, - mybool *pprev_was_smaller, - unsigned m, - unsigned m1, - unsigned anew, - unsigned aold) +static void ADDTYPE(dheap_replace)(const PIX_TYPE *image, + unsigned *B, + unsigned *heaps, + mybool *pprev_was_larger, + mybool *pprev_was_smaller, + unsigned m, + unsigned m1, + unsigned anew, + unsigned aold) { unsigned pos; /* Lookup position of old pixel in heaps structure, overwrite with new pixel */ - unsigned ci = B[aold]; + unsigned ci = B[aold]; heaps[ci] = anew; B[anew] = ci; @@ -696,27 +684,26 @@ if (ci < m) { /* Lower heap */ if (*pprev_was_smaller) { - pos = ADDTYPE(bubble_down_lt)(image, B, heaps, m-1, - ci); - if (pos == ci) pos = ADDTYPE(bubble_up_lt)(image, B, heaps, ci); + pos = ADDTYPE(bubble_down_lt)(image, B, heaps, m - 1, ci); + if (pos == ci) + pos = ADDTYPE(bubble_up_lt)(image, B, heaps, ci); } - else - /* previous was larger or nothing is known */ + else + /* previous was larger or nothing is known */ { /* Optimistic guess optimization here: bubble_up requires only one comparison and is faster than bubble_down. Therefore, in the case where nothing is known about the previous element, we try to bubble_up before bubble_down. */ pos = ADDTYPE(bubble_up_lt)(image, B, heaps, ci); - if (pos == ci) pos = ADDTYPE(bubble_down_lt)(image, B, heaps, m-1, ci); + if (pos == ci) + pos = ADDTYPE(bubble_down_lt)(image, B, heaps, m - 1, ci); } - - if (pos == 0 && - image[heaps[0]] > image[heaps[m]]) { + + if (pos == 0 && image[heaps[0]] > image[heaps[m]]) { ADDTYPE(HEAP_SWAP)(0, m, B, heaps); - - if (image[heaps[m1]] < - image[heaps[m]]) { + + if (image[heaps[m1]] < image[heaps[m]]) { ADDTYPE(HEAP_SWAP)(m1, m, B, heaps); ADDTYPE(bubble_down_gt)(image, B, heaps, m, m1, 0); } @@ -728,35 +715,35 @@ one it replaced (at least not without the cost of a comparison with the previous element, which may or may not pay off). */ - *pprev_was_larger = (pos < ci); + *pprev_was_larger = (pos < ci); *pprev_was_smaller = (pos > ci); return; } else if (ci >= m1) { /* Upper heap */ if (*pprev_was_larger) { - pos = ADDTYPE(bubble_down_gt)(image, B, heaps, m, m1, ci-(m1)); - if (pos == ci-(m1)) - pos = ADDTYPE(bubble_up_gt)(image, B, heaps, m1, ci-(m1)); + pos = ADDTYPE(bubble_down_gt)(image, B, heaps, m, m1, ci - (m1)); + if (pos == ci - (m1)) + pos = ADDTYPE(bubble_up_gt)(image, B, heaps, m1, ci - (m1)); } else { - pos = ADDTYPE(bubble_up_gt)(image, B, heaps, m1, ci-(m1)); - if (pos == ci-(m1)) - pos = ADDTYPE(bubble_down_gt)(image, B, heaps, m, m1, ci-(m1)); + pos = ADDTYPE(bubble_up_gt)(image, B, heaps, m1, ci - (m1)); + if (pos == ci - (m1)) + pos = + ADDTYPE(bubble_down_gt)(image, B, heaps, m, m1, ci - (m1)); } - if (pos == 0 && - image[heaps[m1]] < image[heaps[m]]) { + if (pos == 0 && image[heaps[m1]] < image[heaps[m]]) { ADDTYPE(HEAP_SWAP)(m1, m, B, heaps); - + if (image[heaps[0]] > image[heaps[m]]) { ADDTYPE(HEAP_SWAP)(0, m, B, heaps); - ADDTYPE(bubble_down_lt)(image, B, heaps, m-1, 0); + ADDTYPE(bubble_down_lt)(image, B, heaps, m - 1, 0); } } - *pprev_was_smaller = (pos < ci-(m1)); - *pprev_was_larger = (pos > ci-(m1)); + *pprev_was_smaller = (pos < ci - (m1)); + *pprev_was_larger = (pos > ci - (m1)); return; } else { @@ -764,40 +751,42 @@ if (*pprev_was_smaller) { if (image[heaps[0]] > image[heaps[m]]) { ADDTYPE(HEAP_SWAP)(0, m, B, heaps); - ADDTYPE(bubble_down_lt)(image, B, heaps, m-1, 0); + ADDTYPE(bubble_down_lt)(image, B, heaps, m - 1, 0); *pprev_was_smaller = mytrue; *pprev_was_larger = myfalse; return; - } - else if (image[heaps[m1]] < - image[heaps[m]]) { + } + else if (image[heaps[m1]] < image[heaps[m]]) { ADDTYPE(HEAP_SWAP)(m1, m, B, heaps); ADDTYPE(bubble_down_gt)(image, B, heaps, m, m1, 0); *pprev_was_smaller = myfalse; *pprev_was_larger = mytrue; return; - } else { + } + else { *pprev_was_smaller = myfalse; - *pprev_was_larger = myfalse; + *pprev_was_larger = myfalse; return; } - } else { - if (image[heaps[m1]] < - image[heaps[m]]) { + } + else { + if (image[heaps[m1]] < image[heaps[m]]) { ADDTYPE(HEAP_SWAP)(m1, m, B, heaps); ADDTYPE(bubble_down_gt)(image, B, heaps, m, m1, 0); *pprev_was_smaller = myfalse; *pprev_was_larger = mytrue; return; - } else if (image[heaps[0]] > image[heaps[m]]) { + } + else if (image[heaps[0]] > image[heaps[m]]) { ADDTYPE(HEAP_SWAP)(0, m, B, heaps); - ADDTYPE(bubble_down_lt)(image, B, heaps, m-1, 0); + ADDTYPE(bubble_down_lt)(image, B, heaps, m - 1, 0); *pprev_was_smaller = mytrue; *pprev_was_larger = myfalse; return; - } else { + } + else { *pprev_was_smaller = myfalse; - *pprev_was_larger = myfalse; + *pprev_was_larger = myfalse; return; } } @@ -814,16 +803,9 @@ Cost: 2 comparisons */ -static inline PIX_TYPE -ADDTYPE(max3)(PIX_TYPE p0, - PIX_TYPE p1, - PIX_TYPE p2) -{ - return (p0 > p1) - ? - ((p0 > p2) ? p0 : p2) - : - ((p1 > p2) ? p1 : p2); +static inline PIX_TYPE ADDTYPE(max3)(PIX_TYPE p0, PIX_TYPE p1, PIX_TYPE p2) +{ + return (p0 > p1) ? ((p0 > p2) ? p0 : p2) : ((p1 > p2) ? p1 : p2); } /** @@ -836,16 +818,9 @@ Cost: 2 comparisons */ -static inline PIX_TYPE -ADDTYPE(min3)(PIX_TYPE p0, - PIX_TYPE p1, - PIX_TYPE p2) -{ - return (p0 < p1) - ? - ((p0 < p2) ? p0 : p2) - : - ((p1 < p2) ? p1 : p2); +static inline PIX_TYPE ADDTYPE(min3)(PIX_TYPE p0, PIX_TYPE p1, PIX_TYPE p2) +{ + return (p0 < p1) ? ((p0 < p2) ? p0 : p2) : ((p1 < p2) ? p1 : p2); } /** @@ -865,12 +840,8 @@ 2 + 2 (probability 3/7) = 20/7 = 2.86 comparisons */ -static inline PIX_TYPE -ADDTYPE(median5)(PIX_TYPE p0, - PIX_TYPE p1, - PIX_TYPE p2, - PIX_TYPE p3, - PIX_TYPE p4) +static inline PIX_TYPE ADDTYPE( + median5)(PIX_TYPE p0, PIX_TYPE p1, PIX_TYPE p2, PIX_TYPE p3, PIX_TYPE p4) { /* This would be a one-off ADDTYPE(median) filter (i.e. rank 4th, 5th @@ -878,12 +849,9 @@ return p1; */ - - return (p3 < p1) - ? - ((p4 >= p1) ? p1 : ADDTYPE(max3)(p3, p4, p0)) - : - ((p4 <= p1) ? p1 : ADDTYPE(min3)(p3, p4, p2)); + + return (p3 < p1) ? ((p4 >= p1) ? p1 : ADDTYPE(max3)(p3, p4, p0)) + : ((p4 <= p1) ? p1 : ADDTYPE(min3)(p3, p4, p2)); } /** @@ -911,23 +879,19 @@ 2 + 2.86 (probability 2/3) = 95/21 = 4.52 comparisons */ -static inline PIX_TYPE -ADDTYPE(median9_2)(PIX_TYPE p0, - PIX_TYPE p1, - PIX_TYPE p2, - PIX_TYPE p3, - PIX_TYPE p4, - PIX_TYPE p5, - PIX_TYPE p6, - PIX_TYPE p7, - PIX_TYPE p8) -{ - return (p4 <= p7) - ? - ADDTYPE(median5)(p3, p4, p5, p2, p6) - : - ((p1 < p7) ? ADDTYPE(median5)(p6, p7, p8, p2, p3) - : ADDTYPE(median5)(p0, p1, p2, p8, p3)); +static inline PIX_TYPE ADDTYPE(median9_2)(PIX_TYPE p0, + PIX_TYPE p1, + PIX_TYPE p2, + PIX_TYPE p3, + PIX_TYPE p4, + PIX_TYPE p5, + PIX_TYPE p6, + PIX_TYPE p7, + PIX_TYPE p8) +{ + return (p4 <= p7) ? ADDTYPE(median5)(p3, p4, p5, p2, p6) + : ((p1 < p7) ? ADDTYPE(median5)(p6, p7, p8, p2, p3) + : ADDTYPE(median5)(p0, p1, p2, p8, p3)); } /** @internal @@ -950,19 +914,18 @@ Cost: 1 + 4.52 = 116/21 = 5.52 comparisons */ -static inline PIX_TYPE -ADDTYPE(median9_1)(PIX_TYPE p0, - PIX_TYPE p1, - PIX_TYPE p2, - PIX_TYPE p3, - PIX_TYPE p4, - PIX_TYPE p5, - PIX_TYPE p6, - PIX_TYPE p7, - PIX_TYPE p8) +static inline PIX_TYPE ADDTYPE(median9_1)(PIX_TYPE p0, + PIX_TYPE p1, + PIX_TYPE p2, + PIX_TYPE p3, + PIX_TYPE p4, + PIX_TYPE p5, + PIX_TYPE p6, + PIX_TYPE p7, + PIX_TYPE p8) { return (p1 < p4) ? ADDTYPE(median9_2)(p0, p1, p2, p3, p4, p5, p6, p7, p8) - : ADDTYPE(median9_2)(p3, p4, p5, p0, p1, p2, p6, p7, p8); + : ADDTYPE(median9_2)(p3, p4, p5, p0, p1, p2, p6, p7, p8); } /** @@ -979,31 +942,48 @@ 2 (probability 1/3) or 3 (probability 2/3) = 8/3 = 2.66 comparisons */ -#define sort3(p0, p1, p2, i0, i1, i2) \ -do { \ - if (i0 <= i1) { \ - if (i1 <= i2) { \ - p0 = i0; p1 = i1; p2 = i2; \ - } else if (i0 <= i2) { \ - /* i0, i2, i1 */ \ - p0 = i0; p1 = i2; p2 = i1; \ - } else { \ - /* i2, i0, i1 */ \ - p0 = i2; p1 = i0; p2 = i1; \ - } \ - } else { \ - if (i0 <= i2) { \ - /* i1, i0, i2 */ \ - p0 = i1; p1 = i0; p2 = i2; \ - } else if (i1 < i2) { \ - /* i1, i2, i0 */ \ - p0 = i1; p1 = i2; p2 = i0; \ - } else { \ - /* i2, i1, i0 */ \ - p0 = i2; p1=i1; p2 = i0; \ - } \ - } \ -} while(0) +#define sort3(p0, p1, p2, i0, i1, i2) \ + do { \ + if (i0 <= i1) { \ + if (i1 <= i2) { \ + p0 = i0; \ + p1 = i1; \ + p2 = i2; \ + } \ + else if (i0 <= i2) { \ + /* i0, i2, i1 */ \ + p0 = i0; \ + p1 = i2; \ + p2 = i1; \ + } \ + else { \ + /* i2, i0, i1 */ \ + p0 = i2; \ + p1 = i0; \ + p2 = i1; \ + } \ + } \ + else { \ + if (i0 <= i2) { \ + /* i1, i0, i2 */ \ + p0 = i1; \ + p1 = i0; \ + p2 = i2; \ + } \ + else if (i1 < i2) { \ + /* i1, i2, i0 */ \ + p0 = i1; \ + p1 = i2; \ + p2 = i0; \ + } \ + else { \ + /* i2, i1, i0 */ \ + p0 = i2; \ + p1 = i1; \ + p2 = i0; \ + } \ + } \ + } while (0) /** @internal @@ -1022,22 +1002,24 @@ consistency. Here, an alternate lower and upper median is taken, which has the same effect as the +- inf chess-like pattern. */ -static void -ADDTYPE(filter_median_1)(const PIX_TYPE *in, PIX_TYPE *out, - unsigned Nx, unsigned Ny, unsigned border_mode) +static void ADDTYPE(filter_median_1)(const PIX_TYPE *in, + PIX_TYPE *out, + unsigned Nx, + unsigned Ny, + unsigned border_mode) { register PIX_TYPE p0, p1, p2, p3, p4, p5; register PIX_TYPE p6 = (PIX_TYPE)0; /* Fix (false) uninit warning */ register PIX_TYPE p7 = (PIX_TYPE)0; /* Fix (false) uninit warning */ register PIX_TYPE p8 = (PIX_TYPE)0; /* Fix (false) uninit warning */ - const PIX_TYPE * i0 = in; - const PIX_TYPE * i1 = i0 + Nx; - const PIX_TYPE * i2 = i1 + Nx; - const PIX_TYPE * istop = in + Nx*Ny; /* First pixel not to be accessed */ - unsigned m = 2; /* lower ADDTYPE(median) of 6 elements */ + const PIX_TYPE *i0 = in; + const PIX_TYPE *i1 = i0 + Nx; + const PIX_TYPE *i2 = i1 + Nx; + const PIX_TYPE *istop = in + Nx * Ny; /* First pixel not to be accessed */ + unsigned m = 2; /* lower ADDTYPE(median) of 6 elements */ - assure( Nx >= 3 ); - assure( Ny >= 3 ); + assure(Nx >= 3); + assure(Ny >= 3); switch (border_mode) { case CPL_BORDER_FILTER: { @@ -1051,38 +1033,39 @@ /* upper median */ out[j++] = ADDTYPE(cpl_tools_get_kth)(buf6, 4, 2); - for (; j < Nx-1; j++) { - memcpy(buf6, i0+j-1, 3*sizeof(*buf6)); - memcpy(buf6+3, i1+j-1, 3*sizeof(*buf6)); + for (; j < Nx - 1; j++) { + memcpy(buf6, i0 + j - 1, 3 * sizeof(*buf6)); + memcpy(buf6 + 3, i1 + j - 1, 3 * sizeof(*buf6)); out[j] = ADDTYPE(cpl_tools_get_kth)(buf6, 6, m); - m = 5-m; /* alternate between lower/upper median */ + m = 5 - m; /* alternate between lower/upper median */ } - buf6[0] = i0[Nx-2]; - buf6[1] = i0[Nx-1]; - buf6[2] = i1[Nx-2]; - buf6[3] = i1[Nx-1]; - out[j] = ADDTYPE(cpl_tools_get_kth)(buf6, 4, m-1); + buf6[0] = i0[Nx - 2]; + buf6[1] = i0[Nx - 1]; + buf6[2] = i1[Nx - 2]; + buf6[3] = i1[Nx - 1]; + out[j] = ADDTYPE(cpl_tools_get_kth)(buf6, 4, m - 1); out += Nx; break; } case CPL_BORDER_COPY: /* From the first row copy all but the last pixel */ - (void)memcpy(out, in, (Nx-1)*sizeof(*out)); - out += Nx-1; /* Could also fall through since dimensions are same */ + (void)memcpy(out, in, (Nx - 1) * sizeof(*out)); + out += + Nx - 1; /* Could also fall through since dimensions are same */ break; case CPL_BORDER_NOP: - out += Nx-1; /* Same as above, except no action taken */ + out += Nx - 1; /* Same as above, except no action taken */ break; default: case CPL_BORDER_CROP: break; } - if (border_mode == CPL_BORDER_FILTER) m = 2; /* lower ADDTYPE(median) */ - - for (;i2 < istop; i0 += Nx, i1 += Nx, i2 += Nx, out += Nx) { + if (border_mode == CPL_BORDER_FILTER) + m = 2; /* lower ADDTYPE(median) */ + for (; i2 < istop; i0 += Nx, i1 += Nx, i2 += Nx, out += Nx) { unsigned char k = 2; unsigned j = 0; @@ -1112,7 +1095,7 @@ case CPL_BORDER_COPY: { /* Copy last pixel from previous row and first pixel from current row */ - out[0] = (PIX_TYPE)i0[Nx-1]; + out[0] = (PIX_TYPE)i0[Nx - 1]; out[1] = (PIX_TYPE)i0[Nx]; break; } @@ -1122,12 +1105,11 @@ sort3(p0, p1, p2, i0[j], i1[j], i2[j]); j++; - + sort3(p3, p4, p5, i0[j], i1[j], i2[j]); j++; for (; j < Nx; j++) { - if (k == 0) { k = 1; sort3(p0, p1, p2, i0[j], i1[j], i2[j]); @@ -1140,9 +1122,9 @@ k = 0; sort3(p6, p7, p8, i0[j], i1[j], i2[j]); } - - out[j] - = (PIX_TYPE)ADDTYPE(median9_1)(p0, p1, p2, p3, p4, p5, p6, p7, p8); + + out[j] = (PIX_TYPE)ADDTYPE(median9_1)(p0, p1, p2, p3, p4, p5, p6, + p7, p8); /* The cost per pixel was determined by considering the 9! possible permutations of 9 different numbers and subsequently confirmed by @@ -1170,16 +1152,16 @@ if (border_mode == CPL_BORDER_FILTER) { PIX_TYPE buf6[6]; - buf6[0] = i0[j-2]; - buf6[1] = i1[j-2]; - buf6[2] = i2[j-2]; - buf6[3] = i0[j-1]; - buf6[4] = i1[j-1]; - buf6[5] = i2[j-1]; + buf6[0] = i0[j - 2]; + buf6[1] = i1[j - 2]; + buf6[2] = i2[j - 2]; + buf6[3] = i0[j - 1]; + buf6[4] = i1[j - 1]; + buf6[5] = i2[j - 1]; out[j] = ADDTYPE(cpl_tools_get_kth)(buf6, 6, - ((Nx & 1) == 1) ? m : 5-m); - m = 5-m; + ((Nx & 1) == 1) ? m : 5 - m); + m = 5 - m; /* out was decremented, increment it back */ out++; @@ -1195,20 +1177,20 @@ buf6[1] = i0[1]; buf6[2] = i1[0]; buf6[3] = i1[1]; - out[j++] = ADDTYPE(cpl_tools_get_kth)(buf6, 4, m-1); - m = 5-m; + out[j++] = ADDTYPE(cpl_tools_get_kth)(buf6, 4, m - 1); + m = 5 - m; - for (; j < Nx-1; j++) { - memcpy(buf6, i0+j-1, 3*sizeof(*buf6)); - memcpy(buf6+3, i1+j-1, 3*sizeof(*buf6)); + for (; j < Nx - 1; j++) { + memcpy(buf6, i0 + j - 1, 3 * sizeof(*buf6)); + memcpy(buf6 + 3, i1 + j - 1, 3 * sizeof(*buf6)); out[j] = ADDTYPE(cpl_tools_get_kth)(buf6, 6, m); - m = 5-m; + m = 5 - m; } - buf6[0] = i0[Nx-2]; - buf6[1] = i0[Nx-1]; - buf6[2] = i1[Nx-2]; - buf6[3] = i1[Nx-1]; - out[j] = ADDTYPE(cpl_tools_get_kth)(buf6, 4, m-1); + buf6[0] = i0[Nx - 2]; + buf6[1] = i0[Nx - 1]; + buf6[2] = i1[Nx - 2]; + buf6[3] = i1[Nx - 1]; + out[j] = ADDTYPE(cpl_tools_get_kth)(buf6, 4, m - 1); break; } @@ -1218,7 +1200,7 @@ case CPL_BORDER_COPY: { /* From the 2nd last row copy last pixel */ /* From the last row copy all pixels */ - (void)memcpy(out, istop-(Nx+1), (Nx+1)*sizeof(*out)); + (void)memcpy(out, istop - (Nx + 1), (Nx + 1) * sizeof(*out)); break; } } @@ -1243,19 +1225,22 @@ tests/cpl_filter_body.h. Do not forget to keep both in sync. */ -static void -ADDTYPE(fill_row)(PIX_TYPE *in, unsigned nx, unsigned y, - unsigned xmin, unsigned xmax, - PIX_TYPE val1, PIX_TYPE val2) +static void ADDTYPE(fill_row)(PIX_TYPE *in, + unsigned nx, + unsigned y, + unsigned xmin, + unsigned xmax, + PIX_TYPE val1, + PIX_TYPE val2) { unsigned x = xmin; - - while (x+1 < xmax) { - in[(x++) + y*nx] = val1; - in[(x++) + y*nx] = val2; + + while (x + 1 < xmax) { + in[(x++) + y * nx] = val1; + in[(x++) + y * nx] = val2; } if (x < xmax) { - in[(x++) + y*nx] = val1; + in[(x++) + y * nx] = val1; } return; @@ -1283,46 +1268,43 @@ filter_median_1. */ -void -ADDTYPE(cpl_image_filter_fill_chess)(PIX_TYPE *in_larger, const PIX_TYPE *in, - unsigned Nx_larger, unsigned Ny_larger, - unsigned Nx, unsigned Ny, - unsigned rx, unsigned ry) +void ADDTYPE(cpl_image_filter_fill_chess)(PIX_TYPE *in_larger, + const PIX_TYPE *in, + unsigned Nx_larger, + unsigned Ny_larger, + unsigned Nx, + unsigned Ny, + unsigned rx, + unsigned ry) { unsigned y; - + /* Fill border with PIX_MAX if x+y is even and PIX_MIN if x+y is odd. Loop over images in cache-friendly order. */ for (y = 0; y < ry; y++) { - - ADDTYPE(fill_row)(in_larger, Nx_larger, y, - 0, Nx_larger, - (y & 1) == 0 ? PIX_MAX : PIX_MIN, - (y & 1) == 0 ? PIX_MIN : PIX_MAX); - } - - for (y = ry; y < ry+Ny; y++) { - - ADDTYPE(fill_row)(in_larger, Nx_larger, y, - 0, rx, - (y & 1) == 0 ? PIX_MAX : PIX_MIN, - (y & 1) == 0 ? PIX_MIN : PIX_MAX); - - (void)memcpy(in_larger + rx + y*Nx_larger, - in + (y-ry)*Nx, Nx*sizeof(*in)); - - ADDTYPE(fill_row)(in_larger, Nx_larger, y, - rx + Nx, Nx_larger, - ((y + rx + Nx) & 1) == 0 ? PIX_MAX : PIX_MIN, - ((y + rx + Nx) & 1) == 0 ? PIX_MIN : PIX_MAX); + ADDTYPE(fill_row) + (in_larger, Nx_larger, y, 0, Nx_larger, + (y & 1) == 0 ? PIX_MAX : PIX_MIN, (y & 1) == 0 ? PIX_MIN : PIX_MAX); + } + + for (y = ry; y < ry + Ny; y++) { + ADDTYPE(fill_row) + (in_larger, Nx_larger, y, 0, rx, (y & 1) == 0 ? PIX_MAX : PIX_MIN, + (y & 1) == 0 ? PIX_MIN : PIX_MAX); + + (void)memcpy(in_larger + rx + y * Nx_larger, in + (y - ry) * Nx, + Nx * sizeof(*in)); + + ADDTYPE(fill_row) + (in_larger, Nx_larger, y, rx + Nx, Nx_larger, + ((y + rx + Nx) & 1) == 0 ? PIX_MAX : PIX_MIN, + ((y + rx + Nx) & 1) == 0 ? PIX_MIN : PIX_MAX); } for (y = ry + Ny; y < Ny_larger; y++) { - - ADDTYPE(fill_row)(in_larger, Nx_larger, y, - 0, Nx_larger, - (y & 1) == 0 ? PIX_MAX : PIX_MIN, - (y & 1) == 0 ? PIX_MIN : PIX_MAX); + ADDTYPE(fill_row) + (in_larger, Nx_larger, y, 0, Nx_larger, + (y & 1) == 0 ? PIX_MAX : PIX_MIN, (y & 1) == 0 ? PIX_MIN : PIX_MAX); } } @@ -1418,24 +1400,26 @@ Rx = Ry = 1 is handled as a separate case. */ -static void -ADDTYPE(filter_median)(const PIX_TYPE *in, PIX_TYPE *out, - unsigned Nx, unsigned Ny, - unsigned rx, unsigned ry, - unsigned border_mode) +static void ADDTYPE(filter_median)(const PIX_TYPE *in, + PIX_TYPE *out, + unsigned Nx, + unsigned Ny, + unsigned rx, + unsigned ry, + unsigned border_mode) { unsigned out_Nx; - ADDTYPE(dheap) *dh; + ADDTYPE(dheap) * dh; unsigned y; unsigned x; int dx; - mybool prev_was_larger = myfalse; + mybool prev_was_larger = myfalse; mybool prev_was_smaller = myfalse; - assure( 2*rx + 1 <= Nx ); - assure( 2*ry + 1 <= Ny ); + assure(2 * rx + 1 <= Nx); + assure(2 * ry + 1 <= Ny); if (rx == 1 && ry == 1) { ADDTYPE(filter_median_1)(in, out, Nx, Ny, border_mode); @@ -1449,15 +1433,13 @@ Works for all border modes (because there are no borders!). */ - (void)memcpy(out, in, (Nx*Ny)*sizeof(*out)); + (void)memcpy(out, in, (Nx * Ny) * sizeof(*out)); return; } - assure( border_mode == CPL_BORDER_NOP || - border_mode == CPL_BORDER_CROP || - border_mode == CPL_BORDER_COPY || - border_mode == CPL_BORDER_FILTER ); + assure(border_mode == CPL_BORDER_NOP || border_mode == CPL_BORDER_CROP || + border_mode == CPL_BORDER_COPY || border_mode == CPL_BORDER_FILTER); if (border_mode == CPL_BORDER_FILTER) { /* Add a border of (width, height) = (rx, ry) to the input image. @@ -1467,42 +1449,41 @@ and the result will come out right (because the added border region always contains the same number of +infinity and -infinity). */ - const unsigned Nx_larger = Nx + 2*rx; - const unsigned Ny_larger = Ny + 2*ry; + const unsigned Nx_larger = Nx + 2 * rx; + const unsigned Ny_larger = Ny + 2 * ry; - PIX_TYPE *in_larger = malloc(Nx_larger*Ny_larger*sizeof(*in_larger)); - assure( in_larger != NULL ); + PIX_TYPE *in_larger = + malloc(Nx_larger * Ny_larger * sizeof(*in_larger)); + assure(in_larger != NULL); - ADDTYPE(cpl_image_filter_fill_chess)(in_larger, in, Nx_larger, - Ny_larger, Nx, Ny, rx, ry); - - ADDTYPE(filter_median)(in_larger, out, - Nx_larger, Ny_larger, - rx, ry, - CPL_BORDER_CROP); + ADDTYPE(cpl_image_filter_fill_chess) + (in_larger, in, Nx_larger, Ny_larger, Nx, Ny, rx, ry); + + ADDTYPE(filter_median) + (in_larger, out, Nx_larger, Ny_larger, rx, ry, CPL_BORDER_CROP); free(in_larger); return; } - assert( border_mode == CPL_BORDER_NOP || - border_mode == CPL_BORDER_CROP || - border_mode == CPL_BORDER_COPY); + assert(border_mode == CPL_BORDER_NOP || border_mode == CPL_BORDER_CROP || + border_mode == CPL_BORDER_COPY); if (border_mode == CPL_BORDER_COPY) { - (void)memcpy(out, in, (ry*Nx+rx)*sizeof(*out)); + (void)memcpy(out, in, (ry * Nx + rx) * sizeof(*out)); } - + if (border_mode == CPL_BORDER_CROP) { /* Subtract a bit from the out pointer, so that indexing out[x + y*out_Nx] works */ - out_Nx = Nx - 2*rx; + out_Nx = Nx - 2 * rx; out -= rx + ry * out_Nx; } - else out_Nx = Nx; + else + out_Nx = Nx; dh = ADDTYPE(dheap_new)(in, Nx, Ny, rx, ry); - + /* Loop over image like this -->->->- -<-<-<-- @@ -1510,84 +1491,66 @@ etc. so that the current window always moves by 1 pixel per iteration */ - for (y = 0 + dh->ry, dx = 1; - y < dh->Ny - dh->ry; - y++, dx = -dx) { - - const unsigned xfirst = (dx == 1) ? dh->rx : dh->Nx-1 - dh->rx; - const unsigned xlast = (dx == -1) ? dh->rx : dh->Nx-1 - dh->rx; + for (y = 0 + dh->ry, dx = 1; y < dh->Ny - dh->ry; y++, dx = -dx) { + const unsigned xfirst = (dx == 1) ? dh->rx : dh->Nx - 1 - dh->rx; + const unsigned xlast = (dx == -1) ? dh->rx : dh->Nx - 1 - dh->rx; if (border_mode == CPL_BORDER_COPY && dx == -1 && y != dh->Ny - dh->ry - 1) { - - PIX_TYPE *o = out + xfirst + 1 + y*dh->Nx; - const PIX_TYPE *i = in + xfirst + 1 + y*dh->Nx; + PIX_TYPE *o = out + xfirst + 1 + y * dh->Nx; + const PIX_TYPE *i = in + xfirst + 1 + y * dh->Nx; /* in- and out-types have identical sizes */ - (void)memcpy(o, i, 2*rx*sizeof(*o)); + (void)memcpy(o, i, 2 * rx * sizeof(*o)); } for (x = xfirst; x != xlast + dx; x += dx) { - if (y == dh->ry) { ADDTYPE(SCA_init)(dh, x + dx * dh->rx); } else { /* Most frequent case. Update just 1 pixel in 1 sorted column array */ - ADDTYPE(SCA_replace)(dh, x + dx * dh->rx, - y - dh->ry - 1, - y + dh->ry); + ADDTYPE(SCA_replace) + (dh, x + dx * dh->rx, y - dh->ry - 1, y + dh->ry); } - + if (x == xfirst) { - if (y != dh->ry) { /* Window just moved to next row, update pixels at window bottom row */ unsigned i; - for (i = x - dx*dh->rx; - i != x + dx*dh->rx; i += dx) { - ADDTYPE(SCA_replace)(dh, i, - y - dh->ry - 1, - y + dh->ry); - - ADDTYPE(dheap_replace)(dh->image, - dh->B, - dh->heaps, - &prev_was_larger, - &prev_was_smaller, - dh->m, - dh->m+1, - i + ((y + dh->ry ) * dh->Nx), - i + ((y - dh->ry - 1) * dh->Nx)); + for (i = x - dx * dh->rx; i != x + dx * dh->rx; i += dx) { + ADDTYPE(SCA_replace)(dh, i, y - dh->ry - 1, y + dh->ry); + + ADDTYPE(dheap_replace) + (dh->image, dh->B, dh->heaps, &prev_was_larger, + &prev_was_smaller, dh->m, dh->m + 1, + i + ((y + dh->ry) * dh->Nx), + i + ((y - dh->ry - 1) * dh->Nx)); } - - ADDTYPE(dheap_replace)(dh->image, - dh->B, - dh->heaps, - &prev_was_larger, - &prev_was_smaller, - dh->m, - dh->m+1, - i + ((y + dh->ry ) * dh->Nx), - i + ((y - dh->ry - 1) * dh->Nx)); + + ADDTYPE(dheap_replace) + (dh->image, dh->B, dh->heaps, &prev_was_larger, + &prev_was_smaller, dh->m, dh->m + 1, + i + ((y + dh->ry) * dh->Nx), + i + ((y - dh->ry - 1) * dh->Nx)); } } else { /* Most frequent case. Replace pixels in xold column with pixels from xnew column */ const unsigned xnew = x + dx * dh->rx; - const unsigned xold = x - dx * (dh->rx+1); - const unsigned *SCAxnew = dh->SCA + dh->Ry*xnew; - const unsigned *SCAxold = dh->SCA + dh->Ry*xold; - + const unsigned xold = x - dx * (dh->rx + 1); + const unsigned *SCAxnew = dh->SCA + dh->Ry * xnew; + const unsigned *SCAxold = dh->SCA + dh->Ry * xold; + const PIX_TYPE *image = dh->image; unsigned *B = dh->B; unsigned *heaps = dh->heaps; const unsigned m = dh->m; - const unsigned m1 = m+1; + const unsigned m1 = m + 1; unsigned i; - + /* Loop through old/new sorted column arrays and replace old pixels by new pixels of the same rank (i.e. position in sorted column array). @@ -1598,58 +1561,59 @@ for (i = 0; i < dh->Ry; i++) { const unsigned anew = SCAxnew[i]; const unsigned aold = SCAxold[i]; - - ADDTYPE(dheap_replace)(image, B, heaps, - &prev_was_larger, - &prev_was_smaller, - m, m1, anew, aold); + + ADDTYPE(dheap_replace) + (image, B, heaps, &prev_was_larger, &prev_was_smaller, m, + m1, anew, aold); } } - out[x + y*out_Nx] = (PIX_TYPE)ADDTYPE(dheap_median)(dh); + out[x + y * out_Nx] = (PIX_TYPE)ADDTYPE(dheap_median)(dh); } /* for x */ - + if (border_mode == CPL_BORDER_COPY && dx == 1 && y != dh->Ny - dh->ry - 1) { - - PIX_TYPE *o = out + xlast + 1 + y*dh->Nx; - const PIX_TYPE *i = in + xlast + 1 + y*dh->Nx; + PIX_TYPE *o = out + xlast + 1 + y * dh->Nx; + const PIX_TYPE *i = in + xlast + 1 + y * dh->Nx; /* in- and out- types have identical sizes */ - (void)memcpy(o, i, 2*rx*sizeof(*o)); + (void)memcpy(o, i, 2 * rx * sizeof(*o)); } } /* for y */ if (border_mode == CPL_BORDER_COPY) { - out += (Ny-ry)*dh->Nx - rx; - in += (Ny-ry)*dh->Nx - rx; + out += (Ny - ry) * dh->Nx - rx; + in += (Ny - ry) * dh->Nx - rx; /* in- and out- types have identical sizes */ - (void)memcpy(out, in, (ry*Nx + rx)*sizeof(*out)); + (void)memcpy(out, in, (ry * Nx + rx) * sizeof(*out)); } ADDTYPE(dheap_delete)(dh); return; } -static -void ADDTYPE(cpl_filter_median_fast)(void * out, const void * in, - cpl_size Nx, cpl_size Ny, cpl_size hsizex, - cpl_size hsizey, cpl_border_mode mode) +static void ADDTYPE(cpl_filter_median_fast)(void *out, + const void *in, + cpl_size Nx, + cpl_size Ny, + cpl_size hsizex, + cpl_size hsizey, + cpl_border_mode mode) { - - const unsigned Nxu = (const unsigned)Nx; - const unsigned Nyu = (const unsigned)Ny; + const unsigned Nxu = (const unsigned)Nx; + const unsigned Nyu = (const unsigned)Ny; const unsigned hsizexu = (const unsigned)hsizex; const unsigned hsizeyu = (const unsigned)hsizey; if ((cpl_size)Nxu == Nx && (cpl_size)Nyu == Ny && (cpl_size)hsizexu == hsizex && (cpl_size)hsizeyu == hsizey) { - ADDTYPE(filter_median)(in, out, (unsigned)Nx, (unsigned)Ny, - (unsigned)hsizex, (unsigned)hsizey, - (unsigned)mode); - } else { + ADDTYPE(filter_median) + (in, out, (unsigned)Nx, (unsigned)Ny, (unsigned)hsizex, + (unsigned)hsizey, (unsigned)mode); + } + else { cpl_error_set_(CPL_ERROR_UNSUPPORTED_MODE); } diff -Nru cpl-7.1.4+ds/cplcore/cpl_fits.c cpl-7.2.2+ds/cplcore/cpl_fits.c --- cpl-7.1.4+ds/cplcore/cpl_fits.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_fits.c 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -118,30 +118,30 @@ - CPL_ERROR_BAD_FILE_FORMAT if the I/O caused by CPL_FITS_STOP_CACHING failed */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_fits_set_mode(cpl_fits_mode mode) +cpl_error_code +cpl_fits_set_mode(cpl_fits_mode mode) { - if (mode == CPL_FITS_START_CACHING) { - cpl_io_fits_init(); - - } else if (mode == CPL_FITS_STOP_CACHING) { - - if (cpl_io_fits_end()) return cpl_error_set_where_(); - - } else if ((mode & CPL_FITS_RESTART_CACHING) == CPL_FITS_RESTART_CACHING) { - + } + else if (mode == CPL_FITS_STOP_CACHING) { + if (cpl_io_fits_end()) + return cpl_error_set_where_(); + } + else if ((mode & CPL_FITS_RESTART_CACHING) == CPL_FITS_RESTART_CACHING) { if (cpl_io_fits_close_tid((mode & CPL_FITS_ONE) ? CPL_IO_FITS_ONE - : CPL_IO_FITS_ALL)) + : CPL_IO_FITS_ALL)) return cpl_error_set_where_(); - - } else if (mode == 0) { + } + else if (mode == 0) { return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); - } else if (mode == 1) { + } + else if (mode == 1) { return cpl_error_set_(CPL_ERROR_INVALID_TYPE); - } else { - return cpl_error_set_message_(CPL_ERROR_UNSUPPORTED_MODE, - "mode=%d", (int)mode); + } + else { + return cpl_error_set_message_(CPL_ERROR_UNSUPPORTED_MODE, "mode=%d", + (int)mode); } return CPL_ERROR_NONE; @@ -156,11 +156,11 @@ */ /*----------------------------------------------------------------------------*/ -cpl_fits_mode cpl_fits_get_mode(void) +cpl_fits_mode +cpl_fits_get_mode(void) { - return cpl_io_fits_is_enabled() ? CPL_FITS_START_CACHING - : CPL_FITS_STOP_CACHING; + : CPL_FITS_STOP_CACHING; } /*----------------------------------------------------------------------------*/ @@ -176,11 +176,12 @@ - CPL_ERROR_BAD_FILE_FORMAT if the input FITS file is otherwise invalid */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_fits_count_extensions(const char * filename) +cpl_size +cpl_fits_count_extensions(const char *filename) { - fitsfile * fptr; - int error = 0; - int next = 0; /* CFITSIO supports only int */ + fitsfile *fptr; + int error = 0; + int next = 0; /* CFITSIO supports only int */ cpl_ensure(filename != NULL, CPL_ERROR_NULL_INPUT, -1); @@ -218,22 +219,22 @@ - CPL_ERROR_FILE_IO if the file is not FITS */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_fits_find_extension(const char * filename, - const char * extname) +cpl_size +cpl_fits_find_extension(const char *filename, const char *extname) { - fitsfile * fptr; - int error = 0; - cpl_size ext_num = 0; - char c_extname[FLEN_VALUE] = ""; + fitsfile *fptr; + int error = 0; + cpl_size ext_num = 0; + char c_extname[FLEN_VALUE] = ""; cpl_boolean has_card; cpl_ensure(filename != NULL, CPL_ERROR_NULL_INPUT, -1); - cpl_ensure(extname != NULL, CPL_ERROR_NULL_INPUT, -1); + cpl_ensure(extname != NULL, CPL_ERROR_NULL_INPUT, -1); if (cpl_io_fits_open_diskfile(&fptr, filename, READONLY, &error)) { (void)cpl_error_set_fits(CPL_ERROR_FILE_IO, error, fits_open_diskfile, - "filename='%s', extname='%s'", - filename, extname); + "filename='%s', extname='%s'", filename, + extname); return -1; } @@ -241,7 +242,7 @@ has_card = CPL_TRUE; if (!fits_movabs_hdu(fptr, 2 + ext_num, NULL, &error) && fits_read_key_str(fptr, "EXTNAME", c_extname, NULL, &error) == - KEY_NO_EXIST) { + KEY_NO_EXIST) { /* EXTNAME card is absent, that is allowed */ has_card = CPL_FALSE; error = 0; /* Reset so subsequent calls work */ @@ -259,8 +260,8 @@ if (cpl_io_fits_close_file(fptr, &error)) { (void)cpl_error_set_fits(CPL_ERROR_FILE_IO, error, fits_close_file, - "filename='%s', extname='%s'", - filename, extname); + "filename='%s', extname='%s'", filename, + extname); ext_num = -1; } @@ -278,7 +279,8 @@ */ /*----------------------------------------------------------------------------*/ -int cpl_fits_get_nb_extensions(const char * filename) +int +cpl_fits_get_nb_extensions(const char *filename) { return (int)cpl_fits_count_extensions(filename); } @@ -295,8 +297,8 @@ */ /*----------------------------------------------------------------------------*/ -int cpl_fits_get_extension_nb(const char * filename, - const char * extname) +int +cpl_fits_get_extension_nb(const char *filename, const char *extname) { return (int)cpl_fits_find_extension(filename, extname); } diff -Nru cpl-7.1.4+ds/cplcore/cpl_fits_card.c cpl-7.2.2+ds/cplcore/cpl_fits_card.c --- cpl-7.1.4+ds/cplcore/cpl_fits_card.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_fits_card.c 2022-04-29 14:56:01.000000000 +0000 @@ -0,0 +1,2057 @@ +/* + * This file is part of the ESO Common Pipeline Library + * Copyright (C) 2001-2022 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 "cpl_fits_card.h" +#include "cpl_propertylist_impl.h" +#include "cpl_memory.h" + +/*----------------------------------------------------------------------------*/ +/** + * @defgroup cpl_fits_card FITS card related basic routines + * + * @par Synopsis: + * @code + * #include "cpl_fits_card.h" + * @endcode + */ +/*----------------------------------------------------------------------------*/ +/**@{*/ + +/*----------------------------------------------------------------------------- + Macro definitions + -----------------------------------------------------------------------------*/ + +/* Space permitting non-string values are right justified to column 30, + per ESO-044156 (DICD), Ver. 6, p. 20/73. */ +#define CPL_ALIGN_POS 30 + +/* The FITS card value indicator is initialized via (a part of) this string, + which has padding sufficient for the right justification, see CPL_ALIGN_POS. + Its length is such that when the equal sign is on position 9 it extends to + one character short of the alignment position. + It can be used in four different ways, with or without its initial blank + and with or without padding for right column alignment. */ +#define VALINDSTR (const char *)" = " + +#define BLANK80 \ + " " \ + " " + +/* The actual FITS card length does not include the null-byte */ +#define FITS_CARD_LEN (FLEN_CARD - 1) + +/*----------------------------------------------------------------------------- + Private type definitions + -----------------------------------------------------------------------------*/ + +typedef struct cpl_fits_value +{ + union + { + long long i; /* Numerical, integer */ + double f; /* Numerical, double */ + double complex x; /* Numerical, complex */ + char l; /* Boolean: 1 for true ('T') or 0 for false ('F') */ + const char *c; /* String, any escaped quotes ('') are decoded */ + } val; + int nmemb; /* For string data: number of bytes in buffer + For no-value, undefined value and error: 0 + For one of the other values: 1 + */ + char tcode; /* Type code: FITS code: 'C', 'L', 'F', 'I', 'X', or + 'U' (undefined), 'N' (none) or 0 (unparsable card) */ + /* String buffer for decoded string value with at least one internal quote + - can at most use 67 chars */ + char unquote[FLEN_VALUE]; +} cpl_fits_value; + +/*----------------------------------------------------------------------------- + Private function prototypes + -----------------------------------------------------------------------------*/ + +static const char * +cpl_fits_set_value_(char *, int *, int, const cpl_property *) CPL_ATTR_NONNULL; + +static const char * +cpl_fits_get_comment(const char *, int, int *) CPL_ATTR_NONNULL; + +static int +cpl_property_is_float(const cpl_cstr *) CPL_ATTR_NONNULL CPL_ATTR_PURE; + +static char +cpl_fits_get_value(cpl_fits_value *, const char *, int, const cpl_cstr *, int *) + CPL_ATTR_NONNULL; + +static int cpl_fits_get_number(const char *, int, long long *, double *, int *) +#ifdef CPL_HAVE_ATTR_NONNULL + __attribute__((nonnull(1, 4, 5))) +#endif + ; + +static const char * +cpl_fits_get_key(const char *, int *, int *) CPL_ATTR_NONNULL; + +static void cpl_fits_txtcpy(char *, const char *, int) CPL_ATTR_NONNULL; + +static char +cpl_fits_check_key(const char *, int) CPL_ATTR_NONNULL CPL_ATTR_PURE; + +static int cpl_fits_set_key(char *, + int *, + const cpl_cstr *, + cpl_property_sorttype) CPL_ATTR_NONNULL; + +static cpl_error_code +cpl_fits_set_value(char *, int *, const cpl_property *) CPL_ATTR_NONNULL; + +/*----------------------------------------------------------------------------- + Function codes + -----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------*/ +/* + * @internal + * @brief Convert card to a property + * @param self The propertylist to append to + * @param cardi A NULL-terminated string with a FITS card, 81 bytes + * @param names An optional list of names w. invert flag for filtering cards + * @param regexp An optional regexp w. invert flag for filtering cards + * @return CPL_ERROR_NONE, or the relevant CPL error on failure + * @see _cpl_propertylist_fill_from_fits() + * @note While a newly created property has a NULL-comment, a property + * appended here has a non-NULL (but possibly zero-length) comment + * + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code +cpl_propertylist_append_from_string(cpl_propertylist *self, + const char *cardi, + const cpl_memcmp *names, + const cpl_regexp *regexp) +{ + char keystr[FLEN_KEYWORD]; + cpl_property *myprop; + const char *commentmem = NULL; + cpl_boolean get_comment = CPL_TRUE; + cpl_fits_value parseval; + int compos = 0; + int comlen; + char type; + + int keylen = 0; /* Length excl. terminating null byte */ + int valinlen = 0; /* Length to value indicator */ + const char *keymem = cpl_fits_get_key(cardi, &keylen, &valinlen); + const cpl_cstr *keywlen = CXSTR(keymem, keylen); + + if (keylen + 1 >= FLEN_KEYWORD) { + return cpl_error_set_message_(CPL_ERROR_BAD_FILE_FORMAT, + "FITS Card " + "has bad key (len=%d)", + keylen); + } + + if (names != NULL) { + if (cpl_cstr_check_memcmp(keywlen, names) == FALSE) { + /* Card is filtered out */ + return CPL_ERROR_NONE; + } + } + else if (regexp != NULL) { + /* The regexp parser requires a null-terminated key */ + (void)memcpy(keystr, keymem, keylen); + keystr[keylen] = '\0'; + + if (cpl_cstr_check_regexp(CXSTR(keystr, keylen), regexp) == FALSE) { + /* Card is filtered out */ + return CPL_ERROR_NONE; + } + } + + type = cpl_fits_get_value(&parseval, cardi, valinlen, keywlen, &compos); + + /* + * Create the property from the parsed FITS card. + */ + + switch (type) { + case 'L': + myprop = cpl_property_new_cx(keywlen, CPL_TYPE_BOOL); + cpl_property_set_bool(myprop, parseval.val.l); + + break; + + case 'I': + + /* Certain (WCS) keywords must be floating point, even if + their FITS encoding is a valid integer. */ + + if (cpl_property_is_float(keywlen)) { + /* The different types share a union, so use temp var */ + const long long ival = parseval.val.i; + + parseval.val.f = (double)ival; + } + else if ((long long)((int)parseval.val.i) == parseval.val.i) { + /* Using an 'int' since the integer property fits */ + + myprop = cpl_property_new_cx(keywlen, CPL_TYPE_INT); + cpl_property_set_int(myprop, (int)parseval.val.i); + break; + } + else { + myprop = cpl_property_new_cx(keywlen, CPL_TYPE_LONG_LONG); + cpl_property_set_long_long(myprop, parseval.val.i); + break; + } + + CPL_ATTR_FALLTRHU; /* fall through */ + case 'F': + + myprop = cpl_property_new_cx(keywlen, CPL_TYPE_DOUBLE); + cpl_property_set_double(myprop, parseval.val.f); + + break; + + case 'U': /* Undefined value fall-through to no-value */ + case 'N': + + /* Strip any trailing blanks */ + for (comlen = FITS_CARD_LEN - compos; comlen > 0; comlen--) { + if (cardi[compos + comlen - 1] != ' ') + break; + } + + /* Skip totally empty records */ + if (keylen == 0 && comlen == 0) + return CPL_ERROR_NONE; + + /* + * FITS standard: blank keywords may be followed by + * any ASCII text as it is for COMMENT and HISTORY. + * + * In order to preserve this header record it is + * changed into COMMENT record, so that it can be + * stored in the property list. + */ + + /* For a value-less card, a string value is made from the comment + which becomes empty */ + + parseval.val.c = cardi + compos; + parseval.nmemb = comlen; + comlen = 0; + + get_comment = CPL_FALSE; + + CPL_ATTR_FALLTRHU; /* fall through */ + case 'C': + + /* For the above fall through, a blank key becomes a comment key */ + myprop = + cpl_property_new_cx(keylen == 0 ? CXSTR("COMMENT", 7) : keywlen, + CPL_TYPE_STRING); + + cpl_property_set_string_cx(myprop, + CXSTR(parseval.nmemb > 0 ? parseval.val.c + : "", + parseval.nmemb)); + + break; + + case 'X': + + myprop = cpl_property_new_cx(keywlen, CPL_TYPE_DOUBLE_COMPLEX); + cpl_property_set_double_complex(myprop, parseval.val.x); + + break; + + default: { + /* A card with an invalid value will go here */ + const char badchar[2] = { cardi[compos], '\0' }; + + (void)memcpy(keystr, keymem, keylen); + keystr[keylen] = '\0'; + return cpl_error_set_message_( + CPL_ERROR_BAD_FILE_FORMAT, + "Bad value " + "in FITS card with key='%*s', " + "bytepos(=): %d, bad-byte=0x%02x (\"%s\") " + "at pos: %d", + keylen, keystr, valinlen, (int)*badchar, badchar, compos); + } + } + + if (get_comment) { + commentmem = cpl_fits_get_comment(cardi, compos, &comlen); + } + + /* While for the cpl_property a NULL comment is the default, + here an empty comment is set as such */ + cpl_property_set_comment_cx(myprop, + CXSTR(comlen > 0 ? commentmem : "", comlen)); + + (void)cpl_propertylist_set_property(self, myprop); + + return CPL_ERROR_NONE; +} + + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief Fill a FITS card + @param card A buffer of 80 (or more) characters + @param self The property to fill from + @return CPL_ERROR_NONE, or the relevant CPL error on failure + @note (Almost) no input validation in this internal function + @see fits_make_key(), ffmkky(), fftkey() + + */ +/*----------------------------------------------------------------------------*/ +cpl_error_code +cpl_fits_fill_card(char *card, const cpl_property *self) +{ + const cpl_type type = cpl_property_get_type_(self); + const cxchar *name = cpl_property_get_name_(self); + const cxsize namelen = cpl_property_get_size_name(self); + const cpl_cstr *name_ = CXSTR(name, namelen); + const cpl_size commlen = (cpl_size)cpl_property_get_size_comment(self); + int wlen = 0; + const cpl_property_sorttype ksort = cpl_property_get_sortkey_(self); + const int keytype = cpl_fits_set_key(card, &wlen, name_, ksort); + /* Whether to write the value indicator */ + const cpl_boolean dovalin = + (keytype == 0 || type != CPL_TYPE_STRING) ? CPL_TRUE : CPL_FALSE; + + if (CPL_UNLIKELY(keytype < 0)) + return cpl_error_set_where_(); + + if (!dovalin) { + /* Commentary card (COMMENT/HISTORY/blank key) */ + const int mysz = + CX_MIN(FITS_CARD_LEN - 8, + CX_MAX(0, (int)cpl_property_get_size_(self) - 1)); + const char *strcpy = mysz == 0 ? "" : cpl_property_get_string_(self); + + cpl_fits_txtcpy(card + wlen, strcpy, mysz); + wlen += mysz; + } + else if (CPL_UNLIKELY(cpl_fits_set_value(card, &wlen, self))) + return cpl_error_set_where_(); + + if (wlen + 3 < FITS_CARD_LEN && commlen > 0) { + const cxchar *comment = cpl_property_get_comment_(self); + const int mysz = CX_MIN(FITS_CARD_LEN - (wlen + 3), commlen); + + (void)memcpy(card + wlen, " / ", 3); + wlen += 3; + + cpl_fits_txtcpy(card + wlen, comment, mysz); + wlen += mysz; + } + + if (wlen < FITS_CARD_LEN) /* Space pad remainder of card */ + (void)memset(card + wlen, ' ', FITS_CARD_LEN - wlen); + +#ifdef CPL_PROPERTYLIST_DEBUG + cpl_msg_warning(cpl_func, "FITSFILL(%d:%d:%d:%d:%s): %s", (int)namelen, + (int)cpl_property_get_size_(self), (int)commlen, wlen, name, + card); +#endif + + return CPL_ERROR_NONE; +} + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief Convert text to restricted FITS, replacing non-printables with blanks + @param dest A buffer of characters to write to + @param src A buffer of characters to read from + @param sz The number of characters to convert + @return void + @note (Almost) no input validation in this internal function + @see memcpy() + + In FITS text is restricted to the ASCII range 32 to 126, any other is replaced + by a blank. + + */ +/*----------------------------------------------------------------------------*/ +inline static void +cpl_fits_txtcpy(char *dest, const char *src, int sz) +{ +#ifdef CPL_USE_CFITSIO_STRICT + (void)memcpy(dest, src, sz); +#else + /* The lookup table of the 256 8-bit characters, mapping each + restricted character (0..31, 127..255) to a blank. + Each produced character is (naturally) printable, still to produce + a regularly formatted map each character is coded in hexadecimal. */ + + const char *lookup = + "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" + "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" + "\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f" + "\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f" + "\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f" + "\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f" + "\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f" + "\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x20" + "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" + "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" + "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" + "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" + "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" + "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" + "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" + "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20"; + + + for (int i = 0; i < sz; i++) { + dest[i] = lookup[(const unsigned char)src[i]]; + } +#endif +} + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief Check that the key is OK + @param key The key to check + @param sz The length of the key + @return Zero on OK, negative on invalid, positive on lower-case + @note (Almost) no input validation in this internal function + + The return values are: + Zero: Valid FITS key, i.e. [A-Z0-9_-] and the blank. + Positive: Lower case letter (a-z), each ASCII value binary or'ed together + Negative: Any other, each ASCII value or'ed together with most significant bit + + */ +/*----------------------------------------------------------------------------*/ +inline static char +cpl_fits_check_key(const char *key, int sz) +{ + /* The below initializer was generated with: + perl -le 'for ($n=0; $n < 256; $n+=16) {printf(" \"");' \ + -e 'grep(printf("\\x%02x", (97 <= $_ && $_ <= 122) ? $_ : ' \ + -e '($_ == 32 || $_ == 45 || 48 <= $_ && $_ <= 57 || ' \ + -e '65 <= $_ && $_ <= 90 || $_ == 95)' \ + -e ' ? 0 : ($_ | 128)), ($n)..($n+15));print "\"";};' + */ + const char *checkmap = + "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f" + "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f" + "\x00\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\x00\xae\xaf" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xba\xbb\xbc\xbd\xbe\xbf" + "\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xdb\xdc\xdd\xde\x00" + "\xe0\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f" + "\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\xfb\xfc\xfd\xfe\xff" + "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f" + "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f" + "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf" + "\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf" + "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf" + "\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf" + "\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef" + "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"; + char checksum = 0; + + while (sz) + checksum |= checkmap[(const unsigned char)key[--sz]]; + + return checksum; +} + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief Convert integer of unspecified type to its string representation + @param VALUE Integer L-value to convert, will be modified + @param CARD Character array to write to from the end, points to result + @return Nothing + @note Card must be long enough! No error checking in this internal function! + + The right alignment avoids copying/reversing the string. + +*/ +/*----------------------------------------------------------------------------*/ +#define CPL_ITOA_RIGHTALIGN(VALUE, CARD) \ + do { \ + if (VALUE < 0) { \ + while (VALUE <= -10) { \ + *--(CARD) = (char)('0' - VALUE % 10); \ + VALUE /= 10; \ + } \ + *--(CARD) = (char)('0' - VALUE); \ + *--(CARD) = '-'; \ + } \ + else { \ + while (VALUE >= 10) { \ + *--(CARD) = (char)('0' + VALUE % 10); \ + VALUE /= 10; \ + } \ + *--(CARD) = (char)('0' + VALUE); \ + } \ + } while (0) + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief Convert the value of a property to a string + @param card A buffer of FLEN_VALUE+1 (or more) characters + @param plen The number of converted characters, or undefined on error + @param maxlen The maximum number of characters allowed, at least 8 + @param self The property to fill from + @return A pointer to the converted characters, may be without null-terminator + or NULL on error + @note (Almost) no input validation in this internal function + @see cpl_fits_set_value() + + The string representation of the value is first written into a separate + buffer which is then copied into the FITS card, this is done for several + reasons: + 1) The actual position in the card where the first character of the converted + string is to be written depends on the length of the converted string... + 2) A very fast conversion of an integer value can start from the least + significant byte, but this creates a string where the position of the + first character is only known when the conversion is complete. + In this case the filling of the card buffer starts at position FLEN_VALUE. + In case of a conversion error, the card buffer needs an extra character to + NULL-terminate the string for when it goes into the CPL error message. + 3) memcpy() is very fast so writing the string representation of the + value directly to the card and then sometimes having to move it to its + right position is slower and also more complex. + + */ +/*----------------------------------------------------------------------------*/ +inline static const char * +cpl_fits_set_value_(char *strval, + int *plen, + int maxlen, + const cpl_property *self) +{ + char *retval = strval; /* Default is to fill from the start */ + const cpl_type type = cpl_property_get_type_(self); + + switch (type) { + case CPL_TYPE_BOOL: { + const int b = cpl_property_get_bool_(self); + + retval[0] = b == TRUE ? 'T' : 'F'; + *plen = 1; + } break; + + case CPL_TYPE_INT: { + int value = cpl_property_get_int_(self); + + /* Start the conversion at the end of the array, + working backwards, avoiding extra copying */ + + retval += FLEN_VALUE; + CPL_ITOA_RIGHTALIGN(value, retval); + *plen = strval + FLEN_VALUE - retval; + + } break; + + case CPL_TYPE_LONG: { + long value = cpl_property_get_long_(self); + + retval += FLEN_VALUE; + CPL_ITOA_RIGHTALIGN(value, retval); + *plen = strval + FLEN_VALUE - retval; + + } break; + + case CPL_TYPE_LONG_LONG: { + long long value = cpl_property_get_long_long_(self); + + retval += FLEN_VALUE; + CPL_ITOA_RIGHTALIGN(value, retval); + *plen = strval + FLEN_VALUE - retval; + + } break; + + case CPL_TYPE_FLOAT: { + const float value = cpl_property_get_float_(self); + + /* Default CFITSIO float precision: 7, ffr2e() */ + *plen = sprintf(retval, "%.7G", value); + + cx_assert(*plen > 0); + cx_assert(*plen < FLEN_VALUE); + + /* Check whether the number is special - or just integer */ + if (memchr(retval, '.', *plen) == NULL && + memchr(retval, 'E', *plen) == NULL) { + const int fptype = fpclassify(value); + + if (fptype == FP_NAN || fptype == FP_INFINITE) { + (void)cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, + "FITS does not allow special " + "float: %s", + retval); + return NULL; + } + else { + /* Force decimal point onto integer */ + retval[(*plen)++] = '.'; + } + } + } break; + + case CPL_TYPE_DOUBLE: { + const double value = cpl_property_get_double_(self); + + /* Default CFITSIO double precision: 15, ffd2e() */ + *plen = sprintf(retval, "%.15G", value); + + cx_assert(*plen > 0); + cx_assert(*plen < FLEN_VALUE); + + /* Check whether the number is special - or just integer */ + if (memchr(retval, '.', *plen) == NULL && + memchr(retval, 'E', *plen) == NULL) { + const int fptype = fpclassify(value); + + if (fptype == FP_NAN || fptype == FP_INFINITE) { + (void)cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, + "FITS does not allow special " + "double: %s", + retval); + return NULL; + } + else { + /* Force decimal point onto integer */ + retval[(*plen)++] = '.'; + } + } + } break; + + case CPL_TYPE_FLOAT_COMPLEX: { + const float complex value = cpl_property_get_float_complex_(self); + const float val2[2] = { crealf(value), cimagf(value) }; + const int fptype0 = fpclassify(val2[0]); + const int fptype1 = fpclassify(val2[1]); + + /* Default CFITSIO float precision: 7 */ + *plen = sprintf(retval, "(%.7G, %.7G)", val2[0], val2[1]); + + cx_assert(*plen > 0); + cx_assert(*plen < FLEN_VALUE); + + /* Check whether the number is special */ + if (fptype0 == FP_NAN || fptype0 == FP_INFINITE || + fptype1 == FP_NAN || fptype1 == FP_INFINITE) { + (void)cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, + "" + "FITS does not allow special " + "float complex: %s", + retval); + return NULL; + } + } break; + + case CPL_TYPE_DOUBLE_COMPLEX: { + const double complex value = cpl_property_get_double_complex_(self); + const double val2[2] = { creal(value), cimag(value) }; + const int fptype0 = fpclassify(val2[0]); + const int fptype1 = fpclassify(val2[1]); + + /* Default CFITSIO double precision: 15 */ + *plen = sprintf(retval, "(%.15G, %.15G)", val2[0], val2[1]); + + cx_assert(*plen > 0); + cx_assert(*plen < FLEN_VALUE); + + /* Check whether the number is special */ + if (fptype0 == FP_NAN || fptype0 == FP_INFINITE || + fptype1 == FP_NAN || fptype1 == FP_INFINITE) { + (void)cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, + "" + "FITS does not allow special " + "double complex: %s", + retval); + return NULL; + } + } break; + + case CPL_TYPE_CHAR: { + const char c = cpl_property_get_char_(self); + + /* + * Character properties are represented as a single + * character string, not as its numerical equivalent. + */ + + /* Space pad like CFITSIO */ + /* If the character is a quote, it must be escaped by a second one. + With a default quote in the string literal, only one single + character has to be written in each case */ + (void)memcpy(retval, "'' '", 10); + cpl_fits_txtcpy(retval + (c == '\'' ? 2 : 1), &c, 1); + if (CPL_UNLIKELY(maxlen < 10)) { + cx_assert(maxlen > 3); + retval[maxlen - 1] = '\''; + *plen = maxlen; + } + else { + *plen = 10; + } + } break; + + case CPL_TYPE_STRING: { + /* The size is the string length incl. the null-byte */ + const int valuesize = (int)cpl_property_get_size_(self); + int mysz = 0; + int npad; + + retval[mysz++] = '\''; + + if (CPL_LIKELY(valuesize > 1)) { + const char *value = cpl_property_get_string_(self); + /* Need space also for enclosing quotes */ + int remsize = CX_MIN(valuesize - 1, maxlen - 2); + int rpos = 0; + const char *qpos; + + while (CPL_LIKELY(remsize > 0) && + CPL_UNLIKELY((qpos = memchr(value + rpos, '\'', + remsize)) != NULL)) { + const int prelen = qpos - (value + rpos); /* Pre-quote */ + + cx_assert(qpos >= value + rpos); + + cpl_fits_txtcpy(retval + mysz, value + rpos, prelen); + + mysz += prelen; + rpos += prelen + 1; /* Includes quote to be escaped */ + /* Remaining space needs one extra quote */ + remsize = CX_MIN(valuesize - rpos - 1, maxlen - mysz - 3); + + if (remsize >= 0) { + retval[mysz++] = '\''; /* Escape the quote */ + retval[mysz++] = '\''; /* Escape the quote */ + } + else { + remsize = 0; + } + } + + cpl_fits_txtcpy(retval + mysz, value + rpos, remsize); + mysz += remsize; + } + + npad = CX_MIN(9, maxlen - 2) - mysz; + if (npad > 0) { + /* Space pad like CFITSIO */ + (void)memset(retval + mysz, ' ', npad); + mysz += npad; + } + + retval[mysz++] = '\''; + + *plen = mysz; + + break; + } + + default: + (void)cpl_error_set_message_(CPL_ERROR_UNSUPPORTED_MODE, + "type=%d ('%s')", type, + cpl_type_get_name(type)); + return NULL; + } + + if (*plen > maxlen) { + cx_assert(type != CPL_TYPE_STRING); + retval[*plen] = '\0'; /* Cannot overflow string buffer */ + (void)cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, + "Key + '%s'-" + "value too long for FITS card: %d < %d " + "(%*s)", + cpl_type_get_name(type), *plen, maxlen, + *plen, retval); + return NULL; + } + + return retval; +} +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief Set the value of a FITS card + @param card A buffer of 80 (or more) characters + @param plen The number of characters in card, or undefined on error + @param self The property to fill from + @return CPL_ERROR_NONE, or the relevant CPL error on failure + @note (Almost) no input validation in this internal function + @see cpl_fits_fill_card(), fits_make_key(), ffmkky(), fftkey() + + */ +/*----------------------------------------------------------------------------*/ +inline static cpl_error_code +cpl_fits_set_value(char *card, int *plen, const cpl_property *self) +{ + char strval[FLEN_VALUE + 1]; + const int maxlen = FLEN_VALUE - CX_MAX(1, *plen - 7); + int mysz = 0; /* The length of the value as a string */ + + /* First write the value to a temp buffer and then copy it */ + const char *myval = cpl_fits_set_value_(strval, &mysz, maxlen, self); + + if (CPL_UNLIKELY(myval == NULL)) + return cpl_error_set_where_(); + + cx_assert(mysz <= maxlen); + + if (*myval == '\'') { + if (*plen > 8 && *plen + mysz + 2 < FITS_CARD_LEN) { + (void)memcpy(card + *plen, VALINDSTR, 3); + *plen += 3; + } + else { + (void)memcpy(card + *plen, VALINDSTR + 1, 2); + *plen += 2; + } + + (void)memcpy(card + *plen, myval, mysz); + *plen += mysz; + + if (*plen < CPL_ALIGN_POS) { + (void)memset(card + *plen, ' ', CPL_ALIGN_POS - *plen); + *plen = CPL_ALIGN_POS; + } + } + else { + if (*plen + mysz + 2 < CPL_ALIGN_POS) { + (void)memcpy(card + *plen, *plen > 8 ? VALINDSTR : VALINDSTR + 1, + CPL_ALIGN_POS - *plen - mysz); + *plen = CPL_ALIGN_POS - mysz; + } + else if (*plen > 8 && *plen + mysz + 2 < FITS_CARD_LEN) { + (void)memcpy(card + *plen, VALINDSTR, 3); + *plen += 3; + } + else { + (void)memcpy(card + *plen, VALINDSTR + 1, 2); + *plen += 2; + } + (void)memcpy(card + *plen, myval, mysz); + *plen += mysz; + } + + return CPL_ERROR_NONE; +} + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief Determine whether the key is commentary + @param keywlen The name w. length of the property + @return Zero on commentary, non-zero otherwise + @note (Almost) no input validation in this internal function + @see fits_set_key() + +*/ +/*----------------------------------------------------------------------------*/ +inline int +cpl_fits_key_is_comment(const cpl_cstr *keywlen) +{ + const char *key = cx_string_get_(keywlen); + cxsize wlen = cx_string_size_(keywlen); + + + /* Leading and trailing spaces are ignored, if nothing remains the key is + blank. */ + while (!memcmp(key, BLANK80, CX_MIN(FITS_CARD_LEN, wlen))) { + if (CPL_LIKELY(wlen <= FITS_CARD_LEN)) { + return 0; /* Blank key: Commentary card */ + } + wlen -= FITS_CARD_LEN; + key += FITS_CARD_LEN; + } + + /* Key is not blank, skip (remaining) initial+trailing blanks */ + while (CPL_UNLIKELY(*key == ' ')) + key++; /* Skip initial blanks */ + while (CPL_UNLIKELY(key[wlen - 1] == ' ')) + wlen--; /* Skip trailing blanks */ + + cx_assert(*key != ' '); + cx_assert(wlen > 0); + + return wlen == 7 && + (!memcmp(key, "COMMENT", 7) || !memcmp(key, "HISTORY", 7)) + ? 0 + : 1; +} + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief Set the key + @param card A buffer of 80 (or more) characters + @param plen The number of characters in card, or undefined on error + @param type The type of the value, needed for commentary cards + @param keywlen The name w. length of the property + @param ksort The sort key of the property + @return Zero on normal card, positive on commentary, negative on error + @note (Almost) no input validation in this internal function + @see cpl_property_set_sortkey(), fits_make_key(), ffmkky(), fftkey() + + A lower case key character [a-z] does not cause an error, but is silently + changed to upper case, like CFITSIO does. + +*/ +/*----------------------------------------------------------------------------*/ +inline static int +cpl_fits_set_key(char *card, + int *plen, + const cpl_cstr *keywlen, + cpl_property_sorttype ksort) +{ + const char *key = cx_string_get_(keywlen); + cxsize wlen = cx_string_size_(keywlen); /* Default write length */ + int keytype = 0; + char checksum = 0; + + /* Determine the type of key in order of typical frequency */ + + /* Since leading and trailing blanks need to be ignored and since an + all blank card can occur (albeit not very often), we use the very + fast memcmp() to detect a blank card. After that we know that the + key has a non-blank and we will assume that leading and trailing + blanks are rare, since few use them. */ + + while (!memcmp(key, BLANK80, CX_MIN(FITS_CARD_LEN, wlen))) { + if (CPL_LIKELY(wlen <= FITS_CARD_LEN)) { + (void)memcpy(card, BLANK80, 8); + *plen = 8; + return 1; /* Blank key: Commentary card */ + } + wlen -= FITS_CARD_LEN; /* Using so many blanks is really expensive... */ + key += FITS_CARD_LEN; + } + + /* Key is not blank, skip (remaining) initial+trailing blanks */ + while (CPL_UNLIKELY(*key == ' ')) + key++; /* Skip initial blanks */ + while (CPL_UNLIKELY(key[wlen - 1] == ' ')) + wlen--; /* Skip trailing blanks */ + + cx_assert(*key != ' '); + cx_assert(wlen > 0); + + if (wlen > 8) { + keytype = 'H'; /* ESO HIERARCH key, assumed to need HIERARCH prolog */ + + if (ksort & CPL_DICB_HIERARCH_XYZ) { + /* Need to verify all but the first 7 key characters + pre-verified as "ESO XYZ" */ + checksum = cpl_fits_check_key(key + 7, wlen - 7); + } + else if (!memcmp(key, "ESO ", 4)) { + /* HIERARCH key extension came from ESO so is its most likely use */ + + checksum = cpl_fits_check_key(key + 4, wlen - 4); + } + else if (memcmp(key, "HIERARCH ", 9) != 0) { + /* HIERARCH but not ESO HIERARCH */ + + checksum = cpl_fits_check_key(key, wlen); + } + else if (CPL_LIKELY(wlen < FLEN_KEYWORD - 1)) { + /* Long w. HIERARCH, so "Standard" copy of key */ + + keytype = 'S'; + + /* Skip verification of already present "HIERARCH " */ + checksum = cpl_fits_check_key(key + 9, wlen - 9); + } + else { + (void)cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, + "FITS " + "HIERARCH key too long: %d > %d", + (int)wlen, FLEN_KEYWORD - 2); + return -1; + } + } + else if (wlen == 7 && + (!memcmp(key, "COMMENT", 7) || !memcmp(key, "HISTORY", 7))) { + keytype = 'C'; /* Commentary key */ + } + else if (CPL_DICB_UNDEF < ksort && ksort < CPL_DICB_PRIMARY) { + keytype = 'S'; /* Pre-verified Standard key */ + } + else { + keytype = CPL_LIKELY(memchr(key, ' ', wlen) == NULL) + ? 'S' /* Standard key */ + : 'H'; /* No known HIERARCH key of at most 8 characters */ + + /* Need to verify all the (up to 8) key characters */ + checksum = cpl_fits_check_key(key, wlen); + } + + if (keytype != 'H') { + (void)memcpy(card, key, wlen); + if (wlen < 8) { + (void)memset(card + wlen, ' ', 8 - wlen); + wlen = 8; + } + *plen = wlen; + } + else if (CPL_LIKELY(wlen < FLEN_KEYWORD - 10)) { + (void)memcpy(card, "HIERARCH ", 9); + (void)memcpy(card + 9, key, wlen); + *plen = 9 + wlen; + } + else { + (void)cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, + "FITS HIERARCH key too long: %d + 9 > %d", + (int)wlen, FLEN_KEYWORD - 2); + return -1; + } + + if (CPL_UNLIKELY(checksum)) { + if (checksum < 0) { + const char checkchar[2] = { checksum & 0x7f, '\0' }; + (void)cpl_error_set_message_( + CPL_ERROR_ILLEGAL_INPUT, + "Bad %d-" + "character FITS key (\"%*s\") w. mask: " + "0x%02x (\"%s\")", + (int)wlen, (int)wlen, key, (int)*checkchar, checkchar); + return -1; + } + else { + for (int i = 0; i < *plen; i++) { + card[i] = toupper(card[i]); + } + } + } + + return keytype == 'C' ? 1 : 0; +} + + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief Get the length of the key of a FITS card + @param card A FITS card (80 bytes or more) may not have null terminator + @param plen The length, zero for a key-less card, undefined on error + @param piparsed The index to the last parsed character + @return On success, points to start of key (skips "HIERARCH "), else NULL + @note (Almost) no input validation in this internal function + @see fits_get_keyname(), ffgknm() + + On success *piparsed is the index to the last parsed character, for a + ESO HIERARCH card *piparsed is the index of the value indicator ('='), for a + non ESO HIERARCH card *piparsed is 8 (whether or not that byte has a + value indicator). + + */ +/*----------------------------------------------------------------------------*/ +inline static const char * +cpl_fits_get_key(const char *card, int *plen, int *piparsed) +{ + const char *kstart = card; + + if (!memcmp(card, "HIERARCH ", 9)) { + /* A malformed card could be missing its value indicator (and could + instead have an '=' sign in its comment) or the key could be invalid. + The purpose of this library is not to process invalid FITS data, so + in such cases the card may be dropped silently or a property with an + unusual key may be created. */ + const char *eqpos = memchr(card + 9, '=', FITS_CARD_LEN - 9); + + if (CPL_LIKELY(eqpos != NULL)) { + *piparsed = (int)(eqpos - card); + + /* If available memrchr() would not help much here, unlikely + to find a whole (properly aligned) word of ' ' */ + while (*--eqpos == ' ') + ; + + if (CPL_LIKELY(eqpos > card + 7)) { + kstart += 9; + *plen = (int)(1 + eqpos - kstart); + } + else { + /* A non-standard HIERARCH card with a value indicator */ + *plen = 8; + } + } + else { + /* A non-standard HIERARCH card without a value indicator */ + *plen = 8; + *piparsed = 8; + } + } + else { + /* The standard allows for non-HIERARCH keys with up to 8 characters + and any trailing blanks are not counted as part of the key. */ + const char *spcpos = memchr(card, ' ', 8); + + *plen = spcpos ? (int)(spcpos - card) : 8; + + *piparsed = 8; + } + + return kstart; +} + + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief Get a numerical value from a FITS card + @param card A FITS card (80 bytes), must have null terminator + @param iparsed The value from cpl_fits_get_key() or just before the number + @param plval On positive return, *plval is the integer, unless NULL + @param pdval On negative return, *pdval is the double + @param pjparsed The index to the last parsed character + @return Positive for int, negative for floating point, zero for NaN (error) + @note (Almost) no input validation in this internal function! + @see cpl_fits_get_key() + + On error, *pjparsed is undefined. + + Parsing a string for a number is non-trivial, so use strtoll() + strtod(). + + If plval is non-NULL, the resulting number is either integer or float, + as indicatd by the return value. + + If the string has a decimal point or an exponent part, the resulting + number is a float even if its fractional part is zero. + + If the string has neither but the conversion to a signed long long int + causes an overflow, the resulting number is deemed float. + + */ +/*----------------------------------------------------------------------------*/ +inline static int +cpl_fits_get_number(const char *card, + int iparsed, + long long *plval, + double *pdval, + int *pjparsed) +{ + char *endptr; + + if (plval != NULL) { + /* Since strtoll() is several times faster than strtod() and since + after strtoll() it is trivial to detect a non-integer, strtoll() + is called first. + If necessary, strtod() is then called on the same address. */ + + errno = 0; /* Integer parsing can result in overflow, ERANGE */ + *plval = strtoll(card + iparsed, &endptr, 10); + + if ((*endptr == ' ' || *endptr == '\0' || + /* FITS std. 4.1.2.3: "A space between the value and + the slash is strongly recommended. */ + CPL_UNLIKELY(*endptr == '/')) && + CPL_LIKELY(errno == 0)) { + *pjparsed = (int)(endptr - card); + return 1; /* Done: It is an integer fitting a long long */ + } + /* The string value may be valid but is not an integer that fits a + long long int. */ + } + + errno = 0; /* Floating-point parsing can result in overflow, ERANGE */ + *pdval = strtod(card + iparsed, &endptr); + + /* The FITS standard (4.2.4) allows for a floating-point constant with a 'D' + starting the exponent part. This format cannot by handled by strtod(). + (Coincidentally, in FORTRAN a double precision constant uses a 'D'). + Since this format is quite rare we don't try to avoid calling strtod() + twice on e.g. 0D0. */ + + if (CPL_UNLIKELY(*endptr == 'D')) { + /* Deal with the FORTRAN-format by replacing the 'D' + with an 'E' in a copy */ + + char numparse[FLEN_VALUE]; + + (void)memcpy(numparse, card + iparsed, FITS_CARD_LEN - iparsed); + + numparse[endptr - (card + iparsed)] = 'E'; + numparse[FITS_CARD_LEN - iparsed] = '\0'; + + errno = 0; /* Floating-point parsing can result in overflow, ERANGE */ + *pdval = strtod(numparse, &endptr); + + /* Transform back to card base */ + endptr += card + iparsed - numparse; + } + + *pjparsed = (int)(endptr - card); + + /* While strtod() converts the various lower and upper case variations of + the strings 'NaN' and '+/-/Inf' (that end with a letter) these strings + are not valid FITS. */ + return CPL_UNLIKELY(errno != 0) || CPL_UNLIKELY(isalpha(*(endptr - 1))) + ? 0 + : -1; +} + + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief Get the parsed value and the comment location of a FITS card + @param pparseval On success, the parsed value and its type + @param card A FITS card (80 bytes), must have null terminator + @param iparsed The value from cpl_fits_get_key() + @param keywlen The name w. length of the property + @param pjparsed The index to the last parsed character (comment separator, /) + @return The FITS type code, or zero on error + @note (Almost) no input validation in this internal function! + @see fits_parse_value(), ffpsvc(), ffdtyp() + + The possible return values are these FITS type codes: + 'C', 'L', 'F', 'I', 'X' - as well as + 'U' (undefined), 'N' (none) or 0 (unparsable value in card) + + If the card has no value indicator, everything after its expected location + is deemed a comment, per FITS standard sections 4.1.2.2 and 4.1.2.3. + + If the value is of type string, the enclosing quotes are left out. If the + string itself contains (FITS-encoded, per 4.2.1 1) quotes, each is converted. + If the string itself contains no quotes, the pointer to its value points + to the relevant byte in the input card, so that string value is only valid + while the card itself is. + + On error, *pjparsed is undefined. + + */ +/*----------------------------------------------------------------------------*/ +inline static char +cpl_fits_get_value(cpl_fits_value *pparseval, + const char *card, + int iparsed, + const cpl_cstr *keywlen, + int *pjparsed) +{ + if (card[iparsed] != '=' || cx_string_size_(keywlen) == 0 || + (cx_string_size_(keywlen) == 7 && + (!memcmp("COMMENT", cx_string_get_(keywlen), 7) || + !memcmp("HISTORY", cx_string_get_(keywlen), 7)))) { + /* Card is commentary, i.e. it has no value indicator or + it is a COMMENT/HISTORY or blank card, see FITS std. 4.4.2.4. + Everything after the key is a comment */ + + pparseval->tcode = 'N'; + *pjparsed = cx_string_size_(keywlen) ? 8 : 0; /* Card may be blank */ + } + else { + /* Value indicator is present */ + + /* - skip it and any leading spaces */ + while (card[++iparsed] == ' ') + ; /* Rely on null terminator */ + + if (iparsed < FITS_CARD_LEN) { + /* card[iparsed] now points to the first value byte */ + + /* Assume failure */ + pparseval->nmemb = 0; + pparseval->tcode = 0; + + switch (card[iparsed]) { + case '\'': { /* character string starts with a quote */ + const char *nextquote; + int vallen = 0; /* The number of value characters */ + + /* - need to increase iparsed to point past current quote + when looking for the next one */ + iparsed++; + while ((nextquote = memchr(card + iparsed, '\'', + FITS_CARD_LEN - iparsed)) != NULL + /* We silently ignore the error where there is 1 byte + after the ending quote and before the end-of-record + and that last byte equals a quote */ + && nextquote + 1 < card + FITS_CARD_LEN && + nextquote[1] == '\'') { + /* O''HARA -> O'HARA */ + + /* The parsed string differs from the FITS-encoded, + so we need to copy it (including the found quote) */ + (void)memcpy(pparseval->unquote + vallen, + card + iparsed, + (int)(nextquote + 1 - card - iparsed)); + + vallen += (int)(nextquote + 1 - card - iparsed); + + /* iparsed must be updated to point to the 2nd quote */ + iparsed = 2 + nextquote - card; + } + + if (nextquote != NULL) { + /* Found the ending quote (none would be a format error) */ + pparseval->tcode = 'C'; + + if (vallen > 0) { + /* Wrote to decoded string buffer */ + pparseval->val.c = pparseval->unquote; + + /* Copy part of string following encoded quote */ + (void)memcpy(pparseval->unquote + vallen, + card + iparsed, + (int)(nextquote - card - iparsed)); + } + else { + /* Reference to original, quote-free string */ + pparseval->val.c = card + iparsed; + } + + vallen += (int)(nextquote - card - iparsed); + + /* FITS standard 4.2.1 1: + Given the example + "KEYWORD2= ' ' / empty string keyword" + and the statement + "the value of the KEYWORD2 is an empty string (nominally " + "a single space character because the first space in the " + " string is significant, but trailing spaces are not)." + a string consisting solely of spaces is deemed to be empty + */ + while (vallen > 0 && + pparseval->val.c[vallen - 1] == ' ') { + vallen--; + } + + /* Update iparsed to point to first byte after value */ + iparsed = 1 + (int)(nextquote - card); + } + + pparseval->nmemb = vallen; + + break; + } + case 'T': + pparseval->val.l = 1; + pparseval->nmemb = 1; + pparseval->tcode = 'L'; /* logical True ('T' character) */ + /* Update iparsed to point to first byte after value */ + iparsed++; + break; + case 'F': + pparseval->val.l = 0; + pparseval->nmemb = 1; + pparseval->tcode = 'L'; /* logical: False ('F' character) */ + /* Update iparsed to point to first byte after value */ + iparsed++; + break; + case '(': { + double dval[2]; + const char dsep[2] = { ',', ')' }; + int i; + + iparsed++; /* Skip '(' */ + for (i = 0; i < 2; i++) { + /* FITS std. 4.2.5: Integer allowed, but parse it as double + since that is all we can store */ + const int ntype = + cpl_fits_get_number(card, iparsed, NULL, dval + i, + &iparsed); + + if (ntype != -1) + break; + + /* FITS std. 4.2.5/6: Trailing blanks are allowed */ + while (card[iparsed] == + ' ') { /* Rely on null terminator */ + iparsed++; + } + if (!(iparsed < FITS_CARD_LEN) || + card[iparsed] != dsep[i]) + break; + iparsed++; + } + + if (i < 2) { + pparseval->nmemb = 0; + pparseval->tcode = 0; + *pjparsed = + iparsed; /* Invalid character - for error msg */ + } + else { + pparseval->val.x = dval[0] + dval[1] * _Complex_I; + pparseval->nmemb = 1; + pparseval->tcode = + 'X'; /* complex datatype "(1.2, -3.4)" */ + } + break; + } + case '/': /* Undefinded value - with a comment */ + pparseval->nmemb = 0; + pparseval->tcode = 'U'; + break; /* No value found, so do not advance iparsed */ + + default: { /* Numerical type */ + /* In determining whether it is int or float, we might as + well parse it. */ + double dvalue = 0.0; + long long lvalue = 0; + +#ifdef CPL_PROPERTYLIST_DEBUG + const int iiparsed = iparsed; +#endif + const int ntype = + cpl_fits_get_number(card, iparsed, &lvalue, &dvalue, + &iparsed); + +#ifdef CPL_PROPERTYLIST_DEBUG + cpl_msg_warning(cpl_func, + "FITSNUM(%d:%d<=%d): %lld %g (%c) %s", + ntype, iiparsed, iparsed, lvalue, dvalue, + card[iparsed], card + iparsed); +#endif + + if (CPL_LIKELY(ntype != 0)) { + if (ntype < 0) { + pparseval->tcode = 'F'; + pparseval->val.f = dvalue; + } + else { + pparseval->tcode = 'I'; + pparseval->val.i = lvalue; + } + pparseval->nmemb = 1; + } + } + } + + /* Now iparsed points to first byte after value */ + + if (CPL_LIKELY(pparseval->tcode != 0)) { + /* Found value. Look for comment */ + + const char *comchar; + + cx_assert(iparsed >= 0); + cx_assert(iparsed <= FITS_CARD_LEN); + + comchar = memchr(card + iparsed, '/', FITS_CARD_LEN - iparsed); + + *pjparsed = CPL_LIKELY(comchar != NULL) + ? (int)(comchar - card) /* Start of comment */ + : FITS_CARD_LEN; /* Nothing left */ + + if (CPL_LIKELY(*pjparsed > iparsed) && + CPL_UNLIKELY(card[iparsed] != ' ')) { + /* A value was found but the subsequent byte is invalid */ + /* In principle a malformed FITS card could have subsequent + non-space byte(s) before the comment/EOL. An actual FITS + verification could use memcmp() against that. */ + + pparseval->tcode = 0; + pparseval->nmemb = 0; + *pjparsed = iparsed; /* Invalid character - for error msg */ + } + } + + return pparseval->tcode; + } + /* The value and its type is undefined, + both value and comment have zero length*/ + + pparseval->tcode = 'U'; + *pjparsed = FITS_CARD_LEN; /* Nothing left */ + } + + /* No value */ + pparseval->nmemb = 0; + return pparseval->tcode; +} + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief Determine whether a given property must be floating point + @param keywlen The name w. length of the property, must be non-NULL + @return Non-zero iff the property must be floating point + @note This internal function has no error checking + + The function does not validate its input according to the FITS standard, + it merely determines whether the given key must be loaded as a floating + point type, even if its actual value can be represented as an integer. + + https://fits.gsfc.nasa.gov/standard40/fits_standard40aa-le.pdf + + Per this paper coauthored by M. R. Calabretta: + https://www.aanda.org/articles/aa/full/2002/45/aah3859/aah3859.html + + these are numerical keys of a floating point type, where the axis is 1-99 + and where the total key length cannot exceed 8: + + CRPIX[0-9]+ + CRVAL[0-9]+ + CDELT[0-9]+ + CRDER[0-9]+ + CSYER[0-9]+ + PC[0-9]+_[0-9]+ + PV[0-9]+_[0-9]+ + CD[0-9]+_[0-9]+ + EQUINOX + EPOCH + MJD-OBS + LONGPOLE + LATPOLE + + Yes - and partly for historical reasons this will also promote to float keys + such as CRPIX0, CRPIX001, CRPIX111, PC0_1, etc. + + */ +/*----------------------------------------------------------------------------*/ +inline static int +cpl_property_is_float(const cpl_cstr *keywlen) +{ + const char *key = cx_string_get_(keywlen); + const cxsize keylen = cx_string_size_(keywlen); + int isfloat = 0; /* Default is integer type */ + /* The state of multi-digit parsing: + 0: Nothing, + 1: A sequence of digits, + 2: Above, followed by a '_' + */ + int parsestate = 0; + + /* Switch on the length, i.e. the number of input characters */ + + /* First matching the length of the key to the length of the string literal + allows for a static-length memcmp() which should be inline-able. */ + + /* NB: The indentation that aligns the calls to memcmp() helps to + ensure that strings of identical length share the correct branch */ + + switch (keylen) { + case 8: + if (isdigit(key[7])) { + parsestate = 1; /* Fall through */ + } + else if (!memcmp(key, "LONGPOLE", 8)) { + isfloat = 1; + break; + } + else { + break; + } + + CPL_ATTR_FALLTRHU; /* fall through */ + + case 7: + if (parsestate) { + if (key[6] == '_') { + parsestate = 2; /* Fall through */ + } + else if (isdigit(key[6])) { + /* Fall through */ + } + else { + break; + } + } + else if (isdigit(key[6])) { + parsestate = 1; /* Fall through */ + } + else if (!memcmp(key, "MJD-OBS", 7) || !memcmp(key, "EQUINOX", 7) || + !memcmp(key, "LATPOLE", 7)) { + isfloat = 1; + break; + } + else { + break; + } + + CPL_ATTR_FALLTRHU; /* fall through */ + + case 6: + if (parsestate <= 1) { + if (isdigit(key[5])) { + if (!memcmp(key, "CRPIX", 5) || !memcmp(key, "CRVAL", 5) || + !memcmp(key, "CDELT", 5) || !memcmp(key, "CRDER", 5) || + !memcmp(key, "CSYER", 5)) { + isfloat = 1; + break; + } + else { + parsestate = 1; /* Fall through */ + } + } + else if (CPL_UNLIKELY(parsestate && key[5] == '_')) { + parsestate = 2; /* Fall through */ + } + else { + break; + } + } + else if (CPL_UNLIKELY(isdigit(key[5]))) { + /* Fall through */ + } + else { + break; + } + + CPL_ATTR_FALLTRHU; /* fall through */ + + case 5: + if (parsestate <= 1) { + if (!parsestate && !memcmp(key, "EPOCH", 5)) { + isfloat = 1; + break; + } + else if (key[3] == '_' && isdigit(key[4])) { + /* parsestate = 2; */ + } + else if (key[4] == '_' && isdigit(key[3])) { + /* parsestate = 2; */ + } + else { + break; + } + } + else if (CPL_UNLIKELY(isdigit(key[4]) && isdigit(key[3]))) { + /* parsestate = 2; */ + } + else { + break; + } + + if (isdigit(key[2]) && + (!memcmp(key, "PC", 2) || !memcmp(key, "PV", 2) || + !memcmp(key, "CD", 2))) { + isfloat = 1; + } + break; + + default: + break; + } + +#ifdef CPL_PROPERTYLIST_DEBUG + if (isfloat) { + char keystr[FLEN_KEYWORD]; /* Needed for %s */ + (void)memcpy(keystr, key, keylen); + keystr[keylen] = '\0'; + + cpl_msg_warning(cpl_func, "Floating point key(%zd): %s", keylen, + keystr); + } +#endif + + return isfloat; +} + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief Get the comment of a FITS card + @param card A FITS card (80 bytes or more) may not have null terminator + @param jparsed The value from cpl_fits_get_value() + @param plen The length when present, otherwise zero + @return Points to start of comment, or NULL if no comment present + @note (Almost) no input validation in this internal function + @see fits_get_keyname(), ffgknm() + + A value of 80 (or more) for jparsed is allowed and interpreted as no comment + available. + + */ +/*----------------------------------------------------------------------------*/ +inline static const char * +cpl_fits_get_comment(const char *card, int jparsed, int *plen) +{ + /* The comment is not a comment if it is empty */ + if (jparsed + 1 < FITS_CARD_LEN && card[jparsed++] == '/') { + /* Since for some comments it is recommended that a space follows the + comment byte (/) (FITS standard 4.3.2), such a space is not + considered part of the commentary text */ + + if (card[jparsed] == ' ') + jparsed++; + + if (jparsed < FITS_CARD_LEN) { + *plen = FITS_CARD_LEN - jparsed; + /* Drop trailing spaces */ + while (card[jparsed + *plen - 1] == ' ' && *plen > 0) { + *plen -= 1; + } + return *plen > 0 ? card + jparsed : NULL; + } + } + + *plen = 0; + return NULL; +} + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief Deallocate memory used for checkning key uniqueness + @param putkey Array of keys arrays already written, ordered after length + @return Nothing + @note (Almost) no input validation in this internal function + + */ +/*----------------------------------------------------------------------------*/ +static void +cpl_fits_key_free_unique(const char **putkey[]) +{ +#ifdef CPL_PROPERTYLIST_DEBUG + cpl_size maxpos = 0; + cpl_size maxlen = 0; + cpl_size nonull = 0; +#endif + for (cpl_size i = 0; i < FLEN_KEYWORD; i++) { + if (putkey[i]) { +#ifdef CPL_PROPERTYLIST_DEBUG + cpl_size k = 0; + + while (putkey[i][k++] != NULL) + ; + + nonull++; + if (k > maxlen) { + maxlen = k; + maxpos = i; + } + cpl_msg_info(cpl_func, "UNIQ-check(%d<%d): %d", (int)i, + FLEN_KEYWORD, (int)k); +#endif + cpl_free(putkey[i]); + } + } + +#ifdef CPL_PROPERTYLIST_DEBUG + cpl_msg_warning(cpl_func, "UNIQ-CHECK(%d:%d<%d): %d", (int)nonull, + (int)maxpos, FLEN_KEYWORD, (int)maxlen); +#endif +} + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief Uniqueness check of a key with the given length + @param KLEN The key length + @return Nothing + @note (Almost) no input validation in this internal macro + +*/ +/*----------------------------------------------------------------------------*/ +#define CPL_FITS_IS_UNIQUE_ONE(KLEN) \ + do { \ + cpl_size i = 0; \ + if (putkey[KLEN] != NULL) { \ + do { \ + if (!memcmp(putkey[KLEN][i], keyname, KLEN)) \ + return 1; \ + } while (putkey[KLEN][++i] != NULL); \ + } \ + else { \ + /* One extra for the NULL-terminator */ \ + putkey[KLEN] = cpl_malloc((ntocheck + 2) * sizeof(char *)); \ + } \ + \ + putkey[KLEN][i] = keyname; \ + putkey[KLEN][i + 1] = NULL; \ + \ + } while (0) + + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief Uniqueness check of a key with the given length, larger than 8 + @param KLEN The key length + @return Nothing + @note Longer keys tend to differ only at the end, call memcmp() differently + @see CPL_FITS_IS_UNIQUE_ONE() + +*/ +/*----------------------------------------------------------------------------*/ +#define CPL_FITS_IS_UNIQUE_TWO(KLEN) \ + do { \ + cpl_size i = 0; \ + if (putkey[KLEN] != NULL) { \ + do { \ + if (!memcmp(putkey[KLEN][i] + KLEN - 8, keyname + KLEN - 8, \ + 8) && \ + !memcmp(putkey[KLEN][i], keyname, KLEN - 8)) \ + return 1; \ + } while (putkey[KLEN][++i] != NULL); \ + } \ + else { \ + /* One extra for the NULL-terminator */ \ + putkey[KLEN] = cpl_malloc((ntocheck + 2) * sizeof(char *)); \ + } \ + \ + putkey[KLEN][i] = keyname; \ + putkey[KLEN][i + 1] = NULL; \ + \ + } while (0) + + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief Check if a FITS card has already been written + @param putkey Array of keys arrays already written, ordered after length + @param key The key to check + @param ntocheck Number of keys to check after this one + @return Zero if the card has not (yet) been written, negative if exempt + @note (Almost) no input validation in this internal function + + As a poor-man's hash this check first groups written keys according to their + length, so the actual string comparison is done only on keys with matching + lengths, reducing the number of memcmp() calls. + + An option would also be to group the already seen keys according to their + sortkey. However, with the grouping according to length, and with keys that + do not share the sorting key typically differing within their first 8 bytes, + this is not worth the added complexity and increased number of buffers. + + */ +/*----------------------------------------------------------------------------*/ +inline static int +cpl_fits_key_is_unique(const char **putkey[], + const cpl_cstr *key, + cpl_size ntocheck) +{ + cxsize keylen = cx_string_size_(key); + const char *keyname = cx_string_get_(key); + + /* Trailing blanks in the key should not occur. + Regardless (and since for a normal key it is only one check), make + sure to remove any since they would be ignored in a FITS card. */ + while (CPL_LIKELY(keylen > 0) && CPL_UNLIKELY(keyname[keylen - 1] == ' ')) { + keylen--; + } + + /* Use this cumbersome switch so each call to memcmp() can be inline'd */ + switch (keylen) { + case 0: + return -1; /* Zero length may come from all spaces */ + case 1: + CPL_FITS_IS_UNIQUE_ONE(1); + break; + case 2: + CPL_FITS_IS_UNIQUE_ONE(2); + break; + case 3: + CPL_FITS_IS_UNIQUE_ONE(3); + break; + case 4: + CPL_FITS_IS_UNIQUE_ONE(4); + break; + case 5: + CPL_FITS_IS_UNIQUE_ONE(5); + break; + case 6: + CPL_FITS_IS_UNIQUE_ONE(6); + break; + case 7: + if (!memcmp("COMMENT", keyname, 7) || + !memcmp("HISTORY", keyname, 7)) + return -1; + CPL_FITS_IS_UNIQUE_ONE(7); + break; + case 8: + CPL_FITS_IS_UNIQUE_ONE(8); + break; + case 9: + CPL_FITS_IS_UNIQUE_TWO(9); + break; + case 10: + CPL_FITS_IS_UNIQUE_TWO(10); + break; + case 11: + CPL_FITS_IS_UNIQUE_TWO(11); + break; + case 12: + CPL_FITS_IS_UNIQUE_TWO(12); + break; + case 13: + CPL_FITS_IS_UNIQUE_TWO(13); + break; + case 14: + CPL_FITS_IS_UNIQUE_TWO(14); + break; + case 15: + CPL_FITS_IS_UNIQUE_TWO(15); + break; + case 16: + CPL_FITS_IS_UNIQUE_TWO(16); + break; + case 17: + CPL_FITS_IS_UNIQUE_TWO(17); + break; + case 18: + CPL_FITS_IS_UNIQUE_TWO(18); + break; + case 19: + CPL_FITS_IS_UNIQUE_TWO(19); + break; + case 20: + CPL_FITS_IS_UNIQUE_TWO(20); + break; + case 21: + CPL_FITS_IS_UNIQUE_TWO(21); + break; + case 22: + CPL_FITS_IS_UNIQUE_TWO(22); + break; + case 23: + CPL_FITS_IS_UNIQUE_TWO(23); + break; + case 24: + CPL_FITS_IS_UNIQUE_TWO(24); + break; + case 25: + CPL_FITS_IS_UNIQUE_TWO(25); + break; + case 26: + CPL_FITS_IS_UNIQUE_TWO(26); + break; + case 27: + CPL_FITS_IS_UNIQUE_TWO(27); + break; + case 28: + CPL_FITS_IS_UNIQUE_TWO(28); + break; + case 29: + CPL_FITS_IS_UNIQUE_TWO(29); + break; + case 30: + CPL_FITS_IS_UNIQUE_TWO(30); + break; + case 31: + CPL_FITS_IS_UNIQUE_TWO(31); + break; + case 32: + CPL_FITS_IS_UNIQUE_TWO(32); + break; + case 33: + CPL_FITS_IS_UNIQUE_TWO(33); + break; + case 34: + CPL_FITS_IS_UNIQUE_TWO(34); + break; + case 35: + CPL_FITS_IS_UNIQUE_TWO(35); + break; + case 36: + CPL_FITS_IS_UNIQUE_TWO(36); + break; + case 37: + CPL_FITS_IS_UNIQUE_TWO(37); + break; + case 38: + CPL_FITS_IS_UNIQUE_TWO(38); + break; + case 39: + CPL_FITS_IS_UNIQUE_TWO(39); + break; + case 40: + CPL_FITS_IS_UNIQUE_TWO(40); + break; + case 41: + CPL_FITS_IS_UNIQUE_TWO(41); + break; + case 42: + CPL_FITS_IS_UNIQUE_TWO(42); + break; + case 43: + CPL_FITS_IS_UNIQUE_TWO(43); + break; + case 44: + CPL_FITS_IS_UNIQUE_TWO(44); + break; + case 45: + CPL_FITS_IS_UNIQUE_TWO(45); + break; + case 46: + CPL_FITS_IS_UNIQUE_TWO(46); + break; + case 47: + CPL_FITS_IS_UNIQUE_TWO(47); + break; + case 48: + CPL_FITS_IS_UNIQUE_TWO(48); + break; + case 49: + CPL_FITS_IS_UNIQUE_TWO(49); + break; + case 50: + CPL_FITS_IS_UNIQUE_TWO(50); + break; + case 51: + CPL_FITS_IS_UNIQUE_TWO(51); + break; + case 52: + CPL_FITS_IS_UNIQUE_TWO(52); + break; + case 53: + CPL_FITS_IS_UNIQUE_TWO(53); + break; + case 54: + CPL_FITS_IS_UNIQUE_TWO(54); + break; + case 55: + CPL_FITS_IS_UNIQUE_TWO(55); + break; + case 56: + CPL_FITS_IS_UNIQUE_TWO(56); + break; + case 57: + CPL_FITS_IS_UNIQUE_TWO(57); + break; + case 58: + CPL_FITS_IS_UNIQUE_TWO(58); + break; + case 59: + CPL_FITS_IS_UNIQUE_TWO(59); + break; + case 60: + CPL_FITS_IS_UNIQUE_TWO(60); + break; + default: /* Don't create extra code for exceedingly rare, long keys */ + /* No point in distinguishing among keys too long to convert to FITS */ + CPL_FITS_IS_UNIQUE_TWO(CX_MIN(keylen, FLEN_KEYWORD - 1)); + break; + } + + return 0; +} + +/**@}*/ diff -Nru cpl-7.1.4+ds/cplcore/cpl_fits_card.h cpl-7.2.2+ds/cplcore/cpl_fits_card.h --- cpl-7.1.4+ds/cplcore/cpl_fits_card.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_fits_card.h 2022-04-29 14:56:02.000000000 +0000 @@ -0,0 +1,39 @@ +/* + * This file is part of the ESO Common Pipeline Library + * Copyright (C) 2001-2022 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 CPL_FITS_CARD_H +#define CPL_FITS_CARD_H + +#include +#include "cpl_property_impl.h" + +/*----------------------------------------------------------------------------- + Function prototypes + -----------------------------------------------------------------------------*/ + +static int cpl_fits_key_is_unique(const char **[], + const cpl_cstr *, + cpl_size) CPL_ATTR_NONNULL CPL_ATTR_PURE; + +static void cpl_fits_key_free_unique(const char **[]) CPL_ATTR_NONNULL; + +static int +cpl_fits_key_is_comment(const cpl_cstr *) CPL_ATTR_NONNULL CPL_ATTR_PURE; + +#endif diff -Nru cpl-7.1.4+ds/cplcore/cpl_fits.h cpl-7.2.2+ds/cplcore/cpl_fits.h --- cpl-7.1.4+ds/cplcore/cpl_fits.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_fits.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -41,20 +41,21 @@ * The values can be combined with bitwise or. */ -enum _cpl_fits_mode_ { +enum _cpl_fits_mode_ +{ -/* No mode has the value 1, which makes the (mis)use of logical or detectable */ + /* No mode has the value 1, which makes the (mis)use of logical or detectable */ /** * Stop the caching of open FITS files * @hideinitializer */ - CPL_FITS_STOP_CACHING = 1 << 1, + CPL_FITS_STOP_CACHING = 1 << 1, /** * Start the caching of open FITS files * @hideinitializer */ - CPL_FITS_START_CACHING = 1 << 2, + CPL_FITS_START_CACHING = 1 << 2, /** * Restart the caching of open FITS files * @hideinitializer @@ -64,8 +65,8 @@ * Apply the mode change only to the current thread * @hideinitializer */ - CPL_FITS_ONE = 1 << 3 - + CPL_FITS_ONE = 1 << 3 + }; /** @@ -92,4 +93,4 @@ CPL_END_DECLS -#endif +#endif diff -Nru cpl-7.1.4+ds/cplcore/cpl_func.h.top cpl-7.2.2+ds/cplcore/cpl_func.h.top --- cpl-7.1.4+ds/cplcore/cpl_func.h.top 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_func.h.top 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 diff -Nru cpl-7.1.4+ds/cplcore/cpl_image_basic_body.h cpl-7.2.2+ds/cplcore/cpl_image_basic_body.h --- cpl-7.1.4+ds/cplcore/cpl_image_basic_body.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_image_basic_body.h 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -20,15 +20,16 @@ #if defined(CPL_OPERATION) && CPL_OPERATION == CPL_IMAGE_BASIC_HYPOT /* Declaration */ -static cpl_error_code CPL_CONCAT2X(cpl_image_hypot, CPL_CONCAT2X(CPL_TYPE1, - CPL_CONCAT2X(CPL_TYPE2, CPL_TYPE3))) - (cpl_image *, - const cpl_image *, - const cpl_image *) +static cpl_error_code + CPL_CONCAT2X(cpl_image_hypot, + CPL_CONCAT2X(CPL_TYPE1, CPL_CONCAT2X(CPL_TYPE2, CPL_TYPE3)))( + cpl_image *, + const cpl_image *, + const cpl_image *) #ifdef CPL_HAVE_ATTR_NONNULL - __attribute__((nonnull(1, 3))) + __attribute__((nonnull(1, 3))) #endif -; + ; /*----------------------------------------------------------------------------*/ /** @@ -42,17 +43,17 @@ */ /*----------------------------------------------------------------------------*/ -static cpl_error_code CPL_CONCAT2X(cpl_image_hypot, CPL_CONCAT2X(CPL_TYPE1, - CPL_CONCAT2X(CPL_TYPE2, CPL_TYPE3))) - (cpl_image * self, - const cpl_image * first, - const cpl_image * second) +static cpl_error_code + CPL_CONCAT2X(cpl_image_hypot, + CPL_CONCAT2X(CPL_TYPE1, CPL_CONCAT2X(CPL_TYPE2, CPL_TYPE3)))( + cpl_image *self, + const cpl_image *first, + const cpl_image *second) { - - CPL_TYPE1 * p1 = ( CPL_TYPE1 *)self->pixels; - const CPL_TYPE3 * p3 = (const CPL_TYPE3 *)second->pixels; - const size_t nxy = (size_t)(self->nx * self->ny); - size_t i; + CPL_TYPE1 *p1 = (CPL_TYPE1 *)self->pixels; + const CPL_TYPE3 *p3 = (const CPL_TYPE3 *)second->pixels; + const size_t nxy = (size_t)(self->nx * self->ny); + size_t i; if (first == NULL) { for (i = 0; i < nxy; i++) @@ -62,41 +63,49 @@ if (second->bpm != NULL) { if (self->bpm == NULL) { self->bpm = cpl_mask_duplicate(second->bpm); - } else { + } + else { cpl_mask_or(self->bpm, second->bpm); } } - } else { - const CPL_TYPE2 * p2 = (const CPL_TYPE2 *)first->pixels; + } + else { + const CPL_TYPE2 *p2 = (const CPL_TYPE2 *)first->pixels; for (i = 0; i < nxy; i++) p1[i] = (CPL_TYPE1)CPL_HYPOT(p2[i], p3[i]); /* Handle bad pixels map */ if (first->bpm != NULL && second->bpm != NULL) { - if (self->bpm == NULL) self->bpm = - cpl_mask_wrap(self->nx, self->ny, (cpl_binary*)cpl_malloc(nxy)); + if (self->bpm == NULL) + self->bpm = cpl_mask_wrap(self->nx, self->ny, + (cpl_binary *)cpl_malloc(nxy)); cpl_mask_or_(cpl_mask_get_data(self->bpm), cpl_mask_get_data_const(first->bpm), cpl_mask_get_data_const(second->bpm), nxy); - } else if (first->bpm != NULL) { - assert( second->bpm == NULL ); + } + else if (first->bpm != NULL) { + assert(second->bpm == NULL); if (self->bpm == NULL) { self->bpm = cpl_mask_duplicate(first->bpm); - } else { + } + else { (void)memcpy(cpl_mask_get_data(self->bpm), cpl_mask_get_data_const(first->bpm), nxy); } - } else if (second->bpm != NULL) { - assert( first-> bpm == NULL ); + } + else if (second->bpm != NULL) { + assert(first->bpm == NULL); if (self->bpm == NULL) { self->bpm = cpl_mask_duplicate(second->bpm); - } else { + } + else { (void)memcpy(cpl_mask_get_data(self->bpm), cpl_mask_get_data_const(second->bpm), nxy); } - } else if (self->bpm != NULL) { + } + else if (self->bpm != NULL) { /* The input has no bad pixel map. We already have an output bpm and we don't know where it comes from, so instead of deallocating it, we just clear it. If the caller does not @@ -111,9 +120,9 @@ #elif defined(CPL_OPERATION) && CPL_OPERATION == CPL_IMAGE_BASIC_OPERATE case CPL_TYPE_T: { - const CPL_TYPE * p2 = (const CPL_TYPE *)image2->pixels; - const size_t nxy = (size_t)(image1->nx * image1->ny); - size_t i; + const CPL_TYPE *p2 = (const CPL_TYPE *)image2->pixels; + const size_t nxy = (size_t)(image1->nx * image1->ny); + size_t i; for (i = 0; i < nxy; i++) CPL_OPERATOR(pout[i], p1[i], p2[i]); @@ -122,14 +131,15 @@ #elif defined(CPL_OPERATION) && CPL_OPERATION == CPL_IMAGE_BASIC_DIVIDE case CPL_TYPE_T: { - const CPL_TYPE * p2 = (const CPL_TYPE *)image2->pixels; - const size_t nxy = (size_t)(image1->nx * image1->ny); - size_t i; + const CPL_TYPE *p2 = (const CPL_TYPE *)image2->pixels; + const size_t nxy = (size_t)(image1->nx * image1->ny); + size_t i; for (i = 0; i < nxy; i++) { if (p2[i] != (CPL_TYPE)0) { CPL_IMAGE_DIVISION(pout[i], p1[i], p2[i]); - } else { + } + else { pout[i] = (CPL_TYPE)0; pzeros[i] = CPL_BINARY_1; nzero++; @@ -140,25 +150,26 @@ #elif defined(CPL_OPERATION) && CPL_OPERATION == CPL_IMAGE_BASIC_OPERATE_LOCAL case CPL_TYPE_T: { - const CPL_TYPE * p2 = (const CPL_TYPE *)im2->pixels; - const size_t nxy = (size_t)(im1->nx * im1->ny); - size_t i; + const CPL_TYPE *p2 = (const CPL_TYPE *)im2->pixels; + const size_t nxy = (size_t)(im1->nx * im1->ny); + size_t i; - for (i = 0; i < nxy; i++) + for (i = 0; i < nxy; i++) CPL_OPERATOR(p1[i], p2[i]); break; } #elif defined(CPL_OPERATION) && CPL_OPERATION == CPL_IMAGE_BASIC_DIVIDE_LOCAL case CPL_TYPE_T: { - const CPL_TYPE * p2 = (const CPL_TYPE * )im2->pixels; - const size_t nxy = (size_t)(im1->nx * im1->ny); - size_t i; + const CPL_TYPE *p2 = (const CPL_TYPE *)im2->pixels; + const size_t nxy = (size_t)(im1->nx * im1->ny); + size_t i; for (i = 0; i < nxy; i++) { if (p2[i] != (CPL_TYPE)0) { CPL_IMAGE_DIVISIONASSIGN(p1[i], p2[i]); - } else { + } + else { pzeros[i] = CPL_BINARY_1; nzero++; } @@ -169,37 +180,37 @@ /* Type dependent macros */ #if defined CPL_CLASS && CPL_CLASS == CPL_CLASS_DOUBLE -#define CPL_TYPE double +#define CPL_TYPE double #define CPL_TYPE_CONCAT double -#define CPL_TYPE_T CPL_TYPE_DOUBLE -#define CPL_MATH_ABS fabs +#define CPL_TYPE_T CPL_TYPE_DOUBLE +#define CPL_MATH_ABS fabs #define CPL_TYPE_IS_FPOINT #elif defined CPL_CLASS && CPL_CLASS == CPL_CLASS_FLOAT -#define CPL_TYPE float +#define CPL_TYPE float #define CPL_TYPE_CONCAT float -#define CPL_TYPE_T CPL_TYPE_FLOAT -#define CPL_MATH_ABS fabsf +#define CPL_TYPE_T CPL_TYPE_FLOAT +#define CPL_MATH_ABS fabsf #define CPL_TYPE_IS_FPOINT #elif defined CPL_CLASS && CPL_CLASS == CPL_CLASS_INT -#define CPL_TYPE int +#define CPL_TYPE int #define CPL_TYPE_CONCAT int -#define CPL_TYPE_T CPL_TYPE_INT -#define CPL_MATH_ABS abs +#define CPL_TYPE_T CPL_TYPE_INT +#define CPL_MATH_ABS abs #elif defined CPL_CLASS && CPL_CLASS == CPL_CLASS_DOUBLE_COMPLEX -#define CPL_TYPE double complex +#define CPL_TYPE double complex #define CPL_TYPE_CONCAT double_complex -#define CPL_MATH_ABS cabs -#define CPL_TYPE_T CPL_TYPE_DOUBLE_COMPLEX +#define CPL_MATH_ABS cabs +#define CPL_TYPE_T CPL_TYPE_DOUBLE_COMPLEX #define CPL_TYPE_IS_FPOINT #elif defined CPL_CLASS && CPL_CLASS == CPL_CLASS_FLOAT_COMPLEX -#define CPL_TYPE float complex +#define CPL_TYPE float complex #define CPL_TYPE_CONCAT float_complex -#define CPL_MATH_ABS cabsf -#define CPL_TYPE_T CPL_TYPE_FLOAT_COMPLEX +#define CPL_MATH_ABS cabsf +#define CPL_TYPE_T CPL_TYPE_FLOAT_COMPLEX #define CPL_TYPE_IS_FPOINT #else @@ -218,9 +229,12 @@ -----------------------------------------------------------------------------*/ static cpl_image * -CPL_TYPE_ADD(cpl_image_collapse_window_create)(const cpl_image *, cpl_size, - cpl_size, cpl_size, cpl_size, - int); + CPL_TYPE_ADD(cpl_image_collapse_window_create)(const cpl_image *, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + int); static cpl_error_code CPL_TYPE_ADD(cpl_image_power)(cpl_image *, double); @@ -239,22 +253,21 @@ */ /*----------------------------------------------------------------------------*/ -static cpl_error_code CPL_TYPE_ADD(cpl_image_logarithm)(cpl_image * self, - double base) +static cpl_error_code + CPL_TYPE_ADD(cpl_image_logarithm)(cpl_image *self, double base) { - double scale; const int myerrno = errno; - CPL_TYPE * data = cpl_image_get_data(self); + CPL_TYPE *data = cpl_image_get_data(self); const size_t n = cpl_image_get_size_x(self) * cpl_image_get_size_y(self); - const cpl_mask * mask = cpl_image_get_bpm_const(self); - const cpl_binary * cbpm = mask ? cpl_mask_get_data_const(mask) : NULL; - cpl_binary * bpm = NULL; + const cpl_mask *mask = cpl_image_get_bpm_const(self); + const cpl_binary *cbpm = mask ? cpl_mask_get_data_const(mask) : NULL; + cpl_binary *bpm = NULL; size_t i; cpl_ensure_code(data != NULL, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(base > 0.0, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(base != 1.0, CPL_ERROR_DIVISION_BY_ZERO); + cpl_ensure_code(base > 0.0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(base != 1.0, CPL_ERROR_DIVISION_BY_ZERO); /* In spite of checks log() may still set errno */ @@ -262,14 +275,15 @@ scale = 1.0 / log(base); - cpl_ensure_code(!errno, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(!errno, CPL_ERROR_ILLEGAL_INPUT); /* Pixel value must be positive */ for (i = 0; i < n; i++) { if (!cbpm || !cbpm[i]) { /* Pixel is not bad (yet) */ if ((double)data[i] > 0.0) { data[i] = (CPL_TYPE)(log((double)data[i]) * scale); - } else { + } + else { errno = EDOM; /* Use errno to reuse code */ } if (errno) { @@ -287,7 +301,7 @@ } /* FIXME: Counts also bad pixels */ - cpl_tools_add_flops( 2 * n + 2); + cpl_tools_add_flops(2 * n + 2); errno = myerrno; return CPL_ERROR_NONE; @@ -305,16 +319,15 @@ */ /*----------------------------------------------------------------------------*/ -static cpl_error_code CPL_TYPE_ADD(cpl_image_exponential)(cpl_image * self, - double base) +static cpl_error_code + CPL_TYPE_ADD(cpl_image_exponential)(cpl_image *self, double base) { - const int myerrno = errno; - CPL_TYPE * data = cpl_image_get_data(self); + CPL_TYPE *data = cpl_image_get_data(self); const size_t n = cpl_image_get_size_x(self) * cpl_image_get_size_y(self); - const cpl_mask * mask = cpl_image_get_bpm_const(self); - const cpl_binary * cbpm = mask ? cpl_mask_get_data_const(mask) : NULL; - cpl_binary * bpm = NULL; + const cpl_mask *mask = cpl_image_get_bpm_const(self); + const cpl_binary *cbpm = mask ? cpl_mask_get_data_const(mask) : NULL; + cpl_binary *bpm = NULL; size_t i; cpl_ensure_code(data != NULL, CPL_ERROR_ILLEGAL_INPUT); @@ -330,7 +343,8 @@ if (!cbpm || !cbpm[i]) { /* Pixel is not bad (yet) */ if ((double)data[i] == ceil((double)data[i])) { data[i] = (CPL_TYPE)pow(base, (double)data[i]); - } else { + } + else { errno = EDOM; /* Use errno to reuse code */ } if (errno) { @@ -346,9 +360,10 @@ } } } - } else + } + else #endif - if (base != 0.0) { + if (base != 0.0) { /* Pixel value can be anything */ for (i = 0; i < n; i++) { if (!cbpm || !cbpm[i]) { /* Pixel is not bad (yet) */ @@ -366,13 +381,15 @@ } } } - } else { + } + else { /* Base is zero, pixel value must be non-negative */ for (i = 0; i < n; i++) { if (!cbpm || !cbpm[i]) { /* Pixel is not bad (yet) */ if ((double)data[i] >= 0.0) { data[i] = (CPL_TYPE)pow(base, (double)data[i]); - } else { + } + else { errno = EDOM; /* Use errno to reuse code */ } if (errno) { @@ -391,7 +408,7 @@ } /* FIXME: Counts also bad pixels */ - cpl_tools_add_flops( n ); + cpl_tools_add_flops(n); errno = myerrno; return CPL_ERROR_NONE; @@ -409,16 +426,15 @@ */ /*----------------------------------------------------------------------------*/ -static cpl_error_code CPL_TYPE_ADD(cpl_image_power)(cpl_image * self, - double exponent) +static cpl_error_code + CPL_TYPE_ADD(cpl_image_power)(cpl_image *self, double exponent) { - const int myerrno = errno; - CPL_TYPE * data = cpl_image_get_data(self); + CPL_TYPE *data = cpl_image_get_data(self); const size_t n = cpl_image_get_size_x(self) * cpl_image_get_size_y(self); - const cpl_mask * mask = cpl_image_get_bpm_const(self); - const cpl_binary * cbpm = mask ? cpl_mask_get_data_const(mask) : NULL; - cpl_binary * bpm = NULL; + const cpl_mask *mask = cpl_image_get_bpm_const(self); + const cpl_binary *cbpm = mask ? cpl_mask_get_data_const(mask) : NULL; + cpl_binary *bpm = NULL; size_t i; cpl_ensure_code(data != NULL, CPL_ERROR_ILLEGAL_INPUT); @@ -431,8 +447,9 @@ for (i = 0; i < n; i++) { if (!cbpm || !cbpm[i]) { /* Pixel is not bad (yet) */ if ((double)data[i] > 0.0) { - data[i] = (CPL_TYPE)(1.0/sqrt((double)data[i])); - } else { + data[i] = (CPL_TYPE)(1.0 / sqrt((double)data[i])); + } + else { errno = EDOM; /* Use errno to reuse code */ } if (errno) { @@ -449,13 +466,15 @@ } } #ifdef HAVE_CBRT - } else if (exponent == -1.0 / 3.0) { + } + else if (exponent == -1.0 / 3.0) { /* Pixel value must be positive */ for (i = 0; i < n; i++) { if (!cbpm || !cbpm[i]) { /* Pixel is not bad (yet) */ if ((double)data[i] > 0.0) { - data[i] = (CPL_TYPE)(1.0/cbrt((double)data[i])); - } else { + data[i] = (CPL_TYPE)(1.0 / cbrt((double)data[i])); + } + else { errno = EDOM; /* Use errno to reuse code */ } if (errno) { @@ -472,14 +491,16 @@ } } #endif - } else if (exponent < 0.0) { + } + else if (exponent < 0.0) { if (exponent != ceil(exponent)) { /* Pixel value must be positive */ for (i = 0; i < n; i++) { if (!cbpm || !cbpm[i]) { /* Pixel is not bad (yet) */ if ((double)data[i] > 0.0) { data[i] = (CPL_TYPE)pow((double)data[i], exponent); - } else { + } + else { errno = EDOM; /* Use errno to reuse code */ } if (errno) { @@ -495,14 +516,16 @@ } } } - } else { + } + else { /* Pixel value must be non-zero */ for (i = 0; i < n; i++) { if (!cbpm || !cbpm[i]) { /* Pixel is not bad (yet) */ if ((double)data[i] != 0.0) { - data[i] = (CPL_TYPE)cpl_tools_ipow((double)data[i], - exponent); - } else { + data[i] = + (CPL_TYPE)cpl_tools_ipow((double)data[i], exponent); + } + else { errno = EDOM; /* Use errno to reuse code */ } if (errno) { @@ -519,13 +542,15 @@ } } } - } else if (exponent == 0.5) { + } + else if (exponent == 0.5) { /* Pixel value must be non-negative */ for (i = 0; i < n; i++) { if (!cbpm || !cbpm[i]) { /* Pixel is not bad (yet) */ if ((double)data[i] >= 0.0) { data[i] = (CPL_TYPE)sqrt((double)data[i]); - } else { + } + else { errno = EDOM; /* Use errno to reuse code */ } if (errno) { @@ -542,13 +567,15 @@ } } #ifdef HAVE_CBRT - } else if (exponent == 1.0 / 3.0) { + } + else if (exponent == 1.0 / 3.0) { if (cbpm == NULL) { /* No bad pixels */ for (i = 0; i < n; i++) { data[i] = (CPL_TYPE)cbrt((double)data[i]); } - } else { + } + else { for (i = 0; i < n; i++) { if (!cbpm[i]) { /* Pixel is not bad */ data[i] = (CPL_TYPE)cbrt((double)data[i]); @@ -556,13 +583,15 @@ } } #endif - } else if (exponent != ceil(exponent)) { + } + else if (exponent != ceil(exponent)) { /* Pixel value must be non-negative */ for (i = 0; i < n; i++) { if (!cbpm || !cbpm[i]) { /* Pixel is not bad (yet) */ if ((double)data[i] >= 0.0) { data[i] = (CPL_TYPE)pow((double)data[i], exponent); - } else { + } + else { errno = EDOM; /* Use errno to reuse code */ } if (errno) { @@ -578,7 +607,8 @@ } } } - } else if (exponent != 1.0) { + } + else if (exponent != 1.0) { /* Pixel value can be anything */ for (i = 0; i < n; i++) { if (!cbpm || !cbpm[i]) { /* Pixel is not bad (yet) */ @@ -599,14 +629,13 @@ } /* FIXME: Counts also bad pixels */ - cpl_tools_add_flops( n ); + cpl_tools_add_flops(n); errno = myerrno; return CPL_ERROR_NONE; } - /*----------------------------------------------------------------------------*/ /** @internal @@ -631,81 +660,84 @@ */ /*----------------------------------------------------------------------------*/ static cpl_image * -CPL_TYPE_ADD(cpl_image_collapse_window_create)(const cpl_image * self, - cpl_size llx, - cpl_size lly, - cpl_size urx, - cpl_size ury, - int direction) + CPL_TYPE_ADD(cpl_image_collapse_window_create)(const cpl_image *self, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury, + int direction) { - - cpl_image * other; - const CPL_TYPE * pi = (const CPL_TYPE*)self->pixels; - const cpl_binary * bpmi = self->bpm ? cpl_mask_get_data(self->bpm) : NULL; - CPL_TYPE * po; - cpl_binary * bpmo = NULL; - const size_t n1x = 1 + urx - llx; - const size_t n1y = 1 + ury - lly; - size_t i, j; + cpl_image *other; + const CPL_TYPE *pi = (const CPL_TYPE *)self->pixels; + const cpl_binary *bpmi = self->bpm ? cpl_mask_get_data(self->bpm) : NULL; + CPL_TYPE *po; + cpl_binary *bpmo = NULL; + const size_t n1x = 1 + urx - llx; + const size_t n1y = 1 + ury - lly; + size_t i, j; - cpl_ensure(llx >= 1, CPL_ERROR_ILLEGAL_INPUT, NULL); - cpl_ensure(lly >= 1, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(llx >= 1, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(lly >= 1, CPL_ERROR_ILLEGAL_INPUT, NULL); cpl_ensure(urx <= self->nx, CPL_ERROR_ILLEGAL_INPUT, NULL); cpl_ensure(ury <= self->ny, CPL_ERROR_ILLEGAL_INPUT, NULL); - assert( self->type == CPL_TYPE_T ); + assert(self->type == CPL_TYPE_T); /* Let pi and bpmi point to first pixel to collapse */ - pi += self->nx * (lly-1) + (llx - 1); - if (bpmi != NULL) bpmi += self->nx * (lly-1) + (llx - 1); + pi += self->nx * (lly - 1) + (llx - 1); + if (bpmi != NULL) + bpmi += self->nx * (lly - 1) + (llx - 1); if (direction == 0) { const double r1y = (double)n1y; - size_t * nok; + size_t *nok; other = cpl_image_new(n1x, 1, CPL_TYPE_T); - po = (CPL_TYPE*)other->pixels; + po = (CPL_TYPE *)other->pixels; /* To obtain a stride-1 access of pi[], some temporary storage is needed - this may be a disadvantage for very small images */ - nok = (size_t*)cpl_calloc(n1x, sizeof(*nok)); + nok = (size_t *)cpl_calloc(n1x, sizeof(*nok)); - for (j=0; j < n1y; j++) { - for (i=0; i < n1x; i++) { + for (j = 0; j < n1y; j++) { + for (i = 0; i < n1x; i++) { if (bpmi == NULL || !bpmi[i]) { po[i] += pi[i]; nok[i]++; /* Count good pixels */ } } pi += self->nx; - if (bpmi != NULL) bpmi += self->nx; + if (bpmi != NULL) + bpmi += self->nx; } if (bpmi != NULL) { - for (i=0; i < n1x; i++) { + for (i = 0; i < n1x; i++) { if (nok[i] == 0) { /* assert(po[i] == 0.0); */ if (bpmo == NULL) bpmo = cpl_mask_get_data(cpl_image_get_bpm(other)); bpmo[i] = CPL_BINARY_1; - } else if (nok[i] < n1y) { + } + else if (nok[i] < n1y) { po[i] *= r1y / (double)nok[i]; } } } cpl_free(nok); - } else if (direction == 1) { + } + else if (direction == 1) { const double r1x = (double)n1x; - double sum; - size_t nok; + double sum; + size_t nok; other = cpl_image_new(1, n1y, CPL_TYPE_T); - po = (CPL_TYPE*)other->pixels; + po = (CPL_TYPE *)other->pixels; - for (j=0; j < n1y; j++) { + for (j = 0; j < n1y; j++) { sum = 0.0; nok = 0; - for (i=0; i < n1x; i++) { + for (i = 0; i < n1x; i++) { if (bpmi == NULL || !bpmi[i]) { sum += pi[i]; nok++; @@ -716,13 +748,16 @@ if (bpmo == NULL) bpmo = cpl_mask_get_data(cpl_image_get_bpm(other)); bpmo[j] = CPL_BINARY_1; - } else { + } + else { po[j] = nok == n1x ? sum : sum * r1x / (double)nok; } pi += self->nx; - if (bpmi != NULL) bpmi += self->nx; + if (bpmi != NULL) + bpmi += self->nx; } - } else { + } + else { (void)cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); other = NULL; } @@ -741,79 +776,79 @@ #undef CPL_OPERATION #define CPL_OPERATION CPL_IMAGE_BASIC_OPERATE - cpl_image * self; +cpl_image *self; - if (image1 == NULL) { - (void)cpl_error_set_message_(CPL_ERROR_NULL_INPUT, - "First image is NULL"); - return NULL; - } else if (image2 == NULL) { - (void)cpl_error_set_message_(CPL_ERROR_NULL_INPUT, - "Second image is NULL"); - return NULL; - } else if (image1->nx != image2->nx) { - (void)cpl_error_set_message_(CPL_ERROR_INCOMPATIBLE_INPUT, - "Images are %" CPL_SIZE_FORMAT " X %" - CPL_SIZE_FORMAT " (%s) <=> %" - CPL_SIZE_FORMAT " X %" CPL_SIZE_FORMAT - " (%s)", image1->nx, image1->ny, - cpl_type_get_name(image1->type), - image2->nx, image2->ny, - cpl_type_get_name(image2->type)); - return NULL; - } else if (image1->ny != image2->ny) { - (void)cpl_error_set_message_(CPL_ERROR_INCOMPATIBLE_INPUT, - "Images are %" CPL_SIZE_FORMAT " X %" - CPL_SIZE_FORMAT " (%s) <=> %" - CPL_SIZE_FORMAT " X %" CPL_SIZE_FORMAT - " (%s)", image1->nx, image1->ny, - cpl_type_get_name(image1->type), - image2->nx, image2->ny, - cpl_type_get_name(image2->type)); - return NULL; - } +if (image1 == NULL) { + (void)cpl_error_set_message_(CPL_ERROR_NULL_INPUT, "First image is NULL"); + return NULL; +} +else if (image2 == NULL) { + (void)cpl_error_set_message_(CPL_ERROR_NULL_INPUT, "Second image is NULL"); + return NULL; +} +else if (image1->nx != image2->nx) { + (void)cpl_error_set_message_(CPL_ERROR_INCOMPATIBLE_INPUT, + "Images are %" CPL_SIZE_FORMAT + " X %" CPL_SIZE_FORMAT + " (%s) <=> %" CPL_SIZE_FORMAT + " X %" CPL_SIZE_FORMAT " (%s)", + image1->nx, image1->ny, + cpl_type_get_name(image1->type), image2->nx, + image2->ny, cpl_type_get_name(image2->type)); + return NULL; +} +else if (image1->ny != image2->ny) { + (void)cpl_error_set_message_(CPL_ERROR_INCOMPATIBLE_INPUT, + "Images are %" CPL_SIZE_FORMAT + " X %" CPL_SIZE_FORMAT + " (%s) <=> %" CPL_SIZE_FORMAT + " X %" CPL_SIZE_FORMAT " (%s)", + image1->nx, image1->ny, + cpl_type_get_name(image1->type), image2->nx, + image2->ny, cpl_type_get_name(image2->type)); + return NULL; +} - assert( image1->pixels ); - assert( image2->pixels ); +assert(image1->pixels); +assert(image2->pixels); - /* Switch on the first passed image type */ - switch (image1->type) { +/* Switch on the first passed image type */ +switch (image1->type) { #define CPL_MATH_ABS1 abs case CPL_TYPE_INT: { - const int * p1 = (const int *)image1->pixels; - int * pout = (int *)cpl_malloc(image1->nx * image1->ny * - sizeof(*pout)); + const int *p1 = (const int *)image1->pixels; + int *pout = (int *)cpl_malloc(image1->nx * image1->ny * sizeof(*pout)); /* Switch on the second passed image type */ switch (image2->type) { -#define CPL_TYPE_T CPL_TYPE_INT -#define CPL_TYPE int +#define CPL_TYPE_T CPL_TYPE_INT +#define CPL_TYPE int #define CPL_MATH_ABS2 abs #include "cpl_image_basic_body.h" #undef CPL_TYPE_T #undef CPL_TYPE #undef CPL_MATH_ABS2 -#define CPL_TYPE_T CPL_TYPE_FLOAT -#define CPL_TYPE float +#define CPL_TYPE_T CPL_TYPE_FLOAT +#define CPL_TYPE float #define CPL_MATH_ABS2 fabsf #include "cpl_image_basic_body.h" #undef CPL_TYPE_T #undef CPL_TYPE #undef CPL_MATH_ABS2 -#define CPL_TYPE_T CPL_TYPE_DOUBLE -#define CPL_TYPE double +#define CPL_TYPE_T CPL_TYPE_DOUBLE +#define CPL_TYPE double #define CPL_MATH_ABS2 fabs #include "cpl_image_basic_body.h" #undef CPL_TYPE_T #undef CPL_TYPE #undef CPL_MATH_ABS2 - default: - cpl_free(pout); - (void)cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); - pout = NULL; + default: + cpl_free(pout); + (void)cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); + pout = NULL; } self = pout ? cpl_image_wrap_int(image1->nx, image1->ny, pout) : NULL; break; @@ -821,40 +856,40 @@ #undef CPL_MATH_ABS1 #define CPL_MATH_ABS1 fabsf case CPL_TYPE_FLOAT: { - const float * p1 = (const float *)image1->pixels; - float * pout = (float *)cpl_malloc(image1->nx * image1->ny * - sizeof(*pout)); + const float *p1 = (const float *)image1->pixels; + float *pout = + (float *)cpl_malloc(image1->nx * image1->ny * sizeof(*pout)); /* Switch on the second passed image type */ switch (image2->type) { -#define CPL_TYPE_T CPL_TYPE_INT -#define CPL_TYPE int +#define CPL_TYPE_T CPL_TYPE_INT +#define CPL_TYPE int #define CPL_MATH_ABS2 abs #include "cpl_image_basic_body.h" #undef CPL_TYPE_T #undef CPL_TYPE #undef CPL_MATH_ABS2 -#define CPL_TYPE_T CPL_TYPE_FLOAT -#define CPL_TYPE float +#define CPL_TYPE_T CPL_TYPE_FLOAT +#define CPL_TYPE float #define CPL_MATH_ABS2 fabsf #include "cpl_image_basic_body.h" #undef CPL_TYPE_T #undef CPL_TYPE #undef CPL_MATH_ABS2 -#define CPL_TYPE_T CPL_TYPE_DOUBLE -#define CPL_TYPE double +#define CPL_TYPE_T CPL_TYPE_DOUBLE +#define CPL_TYPE double #define CPL_MATH_ABS2 fabs #include "cpl_image_basic_body.h" #undef CPL_TYPE_T #undef CPL_TYPE #undef CPL_MATH_ABS2 - default: - cpl_free(pout); - (void)cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); - pout = NULL; + default: + cpl_free(pout); + (void)cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); + pout = NULL; } self = pout ? cpl_image_wrap_float(image1->nx, image1->ny, pout) : NULL; break; @@ -862,233 +897,239 @@ #undef CPL_MATH_ABS1 #define CPL_MATH_ABS1 fabs case CPL_TYPE_DOUBLE: { - const double * p1 = (const double *)image1->pixels; - double * pout = (double *)cpl_malloc(image1->nx * image1->ny * - sizeof(*pout)); + const double *p1 = (const double *)image1->pixels; + double *pout = + (double *)cpl_malloc(image1->nx * image1->ny * sizeof(*pout)); /* Switch on the second passed image type */ switch (image2->type) { -#define CPL_TYPE_T CPL_TYPE_INT -#define CPL_TYPE int +#define CPL_TYPE_T CPL_TYPE_INT +#define CPL_TYPE int #define CPL_MATH_ABS2 abs #include "cpl_image_basic_body.h" #undef CPL_TYPE_T #undef CPL_TYPE #undef CPL_MATH_ABS2 -#define CPL_TYPE_T CPL_TYPE_FLOAT -#define CPL_TYPE float +#define CPL_TYPE_T CPL_TYPE_FLOAT +#define CPL_TYPE float #define CPL_MATH_ABS2 fabsf #include "cpl_image_basic_body.h" #undef CPL_TYPE_T #undef CPL_TYPE #undef CPL_MATH_ABS2 -#define CPL_TYPE_T CPL_TYPE_DOUBLE -#define CPL_TYPE double +#define CPL_TYPE_T CPL_TYPE_DOUBLE +#define CPL_TYPE double #define CPL_MATH_ABS2 fabs #include "cpl_image_basic_body.h" #undef CPL_TYPE_T #undef CPL_TYPE #undef CPL_MATH_ABS2 - default: - cpl_free(pout); - (void)cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); - pout = NULL; + default: + cpl_free(pout); + (void)cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); + pout = NULL; } - self = pout ? cpl_image_wrap_double(image1->nx, image1->ny, pout) - : NULL; + self = + pout ? cpl_image_wrap_double(image1->nx, image1->ny, pout) : NULL; break; } #undef CPL_MATH_ABS1 #define CPL_MATH_ABS1 cabsf case CPL_TYPE_FLOAT_COMPLEX: { - const float complex * p1 = (const float complex *)image1->pixels; - float complex * pout = - (float complex *)cpl_malloc(image1->nx * image1->ny * sizeof(*pout)); + const float complex *p1 = (const float complex *)image1->pixels; + float complex *pout = (float complex *)cpl_malloc( + image1->nx * image1->ny * sizeof(*pout)); /* Switch on the second passed image type */ switch (image2->type) { -#define CPL_TYPE_T CPL_TYPE_INT -#define CPL_TYPE int +#define CPL_TYPE_T CPL_TYPE_INT +#define CPL_TYPE int #define CPL_MATH_ABS2 abs #include "cpl_image_basic_body.h" #undef CPL_TYPE_T #undef CPL_TYPE #undef CPL_MATH_ABS2 -#define CPL_TYPE_T CPL_TYPE_FLOAT -#define CPL_TYPE float +#define CPL_TYPE_T CPL_TYPE_FLOAT +#define CPL_TYPE float #define CPL_MATH_ABS2 fabsf #include "cpl_image_basic_body.h" #undef CPL_TYPE_T #undef CPL_TYPE #undef CPL_MATH_ABS2 -#define CPL_TYPE_T CPL_TYPE_DOUBLE -#define CPL_TYPE double +#define CPL_TYPE_T CPL_TYPE_DOUBLE +#define CPL_TYPE double #define CPL_MATH_ABS2 fabs #include "cpl_image_basic_body.h" #undef CPL_TYPE_T #undef CPL_TYPE #undef CPL_MATH_ABS2 -#define CPL_TYPE_T CPL_TYPE_FLOAT_COMPLEX -#define CPL_TYPE float complex +#define CPL_TYPE_T CPL_TYPE_FLOAT_COMPLEX +#define CPL_TYPE float complex #define CPL_MATH_ABS2 cabsf #include "cpl_image_basic_body.h" #undef CPL_TYPE_T #undef CPL_TYPE #undef CPL_MATH_ABS2 -#define CPL_TYPE_T CPL_TYPE_DOUBLE_COMPLEX -#define CPL_TYPE double complex +#define CPL_TYPE_T CPL_TYPE_DOUBLE_COMPLEX +#define CPL_TYPE double complex #define CPL_MATH_ABS2 cabs #include "cpl_image_basic_body.h" #undef CPL_TYPE_T #undef CPL_TYPE #undef CPL_MATH_ABS2 - default: - cpl_free(pout); - (void)cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); - pout = NULL; + default: + cpl_free(pout); + (void)cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); + pout = NULL; } self = pout ? cpl_image_wrap_float_complex(image1->nx, image1->ny, pout) - : NULL; + : NULL; break; } #undef CPL_MATH_ABS1 #define CPL_MATH_ABS1 cabs case CPL_TYPE_DOUBLE_COMPLEX: { - const double complex * p1 = (const double complex *)image1->pixels; - double complex * pout = - (double complex *)cpl_malloc(image1->nx * image1->ny * sizeof(*pout)); + const double complex *p1 = (const double complex *)image1->pixels; + double complex *pout = (double complex *)cpl_malloc( + image1->nx * image1->ny * sizeof(*pout)); /* Switch on the second passed image type */ switch (image2->type) { -#define CPL_TYPE_T CPL_TYPE_INT -#define CPL_TYPE int +#define CPL_TYPE_T CPL_TYPE_INT +#define CPL_TYPE int #define CPL_MATH_ABS2 abs #include "cpl_image_basic_body.h" #undef CPL_TYPE_T #undef CPL_TYPE #undef CPL_MATH_ABS2 -#define CPL_TYPE_T CPL_TYPE_FLOAT -#define CPL_TYPE float +#define CPL_TYPE_T CPL_TYPE_FLOAT +#define CPL_TYPE float #define CPL_MATH_ABS2 fabsf #include "cpl_image_basic_body.h" #undef CPL_TYPE_T #undef CPL_TYPE #undef CPL_MATH_ABS2 -#define CPL_TYPE_T CPL_TYPE_DOUBLE -#define CPL_TYPE double +#define CPL_TYPE_T CPL_TYPE_DOUBLE +#define CPL_TYPE double #define CPL_MATH_ABS2 fabs #include "cpl_image_basic_body.h" #undef CPL_TYPE_T #undef CPL_TYPE #undef CPL_MATH_ABS2 -#define CPL_TYPE_T CPL_TYPE_FLOAT_COMPLEX -#define CPL_TYPE float complex +#define CPL_TYPE_T CPL_TYPE_FLOAT_COMPLEX +#define CPL_TYPE float complex #define CPL_MATH_ABS2 cabsf #include "cpl_image_basic_body.h" #undef CPL_TYPE_T #undef CPL_TYPE #undef CPL_MATH_ABS2 -#define CPL_TYPE_T CPL_TYPE_DOUBLE_COMPLEX -#define CPL_TYPE double complex +#define CPL_TYPE_T CPL_TYPE_DOUBLE_COMPLEX +#define CPL_TYPE double complex #define CPL_MATH_ABS2 cabs #include "cpl_image_basic_body.h" #undef CPL_TYPE_T #undef CPL_TYPE #undef CPL_MATH_ABS2 - default: - cpl_free(pout); - (void)cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); - pout = NULL; - } - self = pout ? cpl_image_wrap_double_complex(image1->nx, image1->ny, - pout) : NULL; + default: + cpl_free(pout); + (void)cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); + pout = NULL; + } + self = pout + ? cpl_image_wrap_double_complex(image1->nx, image1->ny, pout) + : NULL; break; } #undef CPL_MATH_ABS1 default: (void)cpl_error_set_(CPL_ERROR_INVALID_TYPE); self = NULL; - } - - if (self != NULL) { +} - if (image1->type != CPL_TYPE_INT && image2->type != CPL_TYPE_INT) { - cpl_tools_add_flops(image1->nx * image1->ny); - } +if (self != NULL) { + if (image1->type != CPL_TYPE_INT && image2->type != CPL_TYPE_INT) { + cpl_tools_add_flops(image1->nx * image1->ny); + } - /* Handle bad pixels map */ - if (image1->bpm == NULL && image2->bpm == NULL) { - self->bpm = NULL; - } else if (image1->bpm == NULL) { - self->bpm = cpl_mask_duplicate(image2->bpm); - } else if (image2->bpm == NULL) { - self->bpm = cpl_mask_duplicate(image1->bpm); - } else { - self->bpm = cpl_mask_duplicate(image1->bpm); - cpl_mask_or(self->bpm, image2->bpm); - } + /* Handle bad pixels map */ + if (image1->bpm == NULL && image2->bpm == NULL) { + self->bpm = NULL; } + else if (image1->bpm == NULL) { + self->bpm = cpl_mask_duplicate(image2->bpm); + } + else if (image2->bpm == NULL) { + self->bpm = cpl_mask_duplicate(image1->bpm); + } + else { + self->bpm = cpl_mask_duplicate(image1->bpm); + cpl_mask_or(self->bpm, image2->bpm); + } +} - return self; +return self; #undef CPL_OPERATION #define CPL_OPERATION CPL_IMAGE_BASIC_ASSIGN -#elif CPL_OPERATION == CPL_IMAGE_BASIC_ASSIGN_LOCAL +#elif CPL_OPERATION == CPL_IMAGE_BASIC_ASSIGN_LOCAL #undef CPL_OPERATION #define CPL_OPERATION CPL_IMAGE_BASIC_OPERATE_LOCAL - if (im1 == NULL) { - return cpl_error_set_message_(CPL_ERROR_NULL_INPUT, - "First image is NULL"); - } else if (im2 == NULL) { - return cpl_error_set_message_(CPL_ERROR_NULL_INPUT, - "Second image is NULL"); - } else if (im1->nx != im2->nx) { - return cpl_error_set_message_(CPL_ERROR_INCOMPATIBLE_INPUT, - "Images are %" CPL_SIZE_FORMAT " X %" - CPL_SIZE_FORMAT " (%s) <=> %" - CPL_SIZE_FORMAT " X %" CPL_SIZE_FORMAT - " (%s)", im1->nx, im1->ny, - cpl_type_get_name(im1->type), im2->nx, - im2->ny, cpl_type_get_name(im2->type)); - } else if (im1->ny != im2->ny) { - return cpl_error_set_message_(CPL_ERROR_INCOMPATIBLE_INPUT, - "Images are %" CPL_SIZE_FORMAT " X %" - CPL_SIZE_FORMAT " (%s) <=> %" - CPL_SIZE_FORMAT " X %" CPL_SIZE_FORMAT - " (%s)", im1->nx, im1->ny, - cpl_type_get_name(im1->type), im2->nx, - im2->ny, cpl_type_get_name(im2->type)); - } +if (im1 == NULL) { + return cpl_error_set_message_(CPL_ERROR_NULL_INPUT, "First image is NULL"); +} +else if (im2 == NULL) { + return cpl_error_set_message_(CPL_ERROR_NULL_INPUT, "Second image is NULL"); +} +else if (im1->nx != im2->nx) { + return cpl_error_set_message_(CPL_ERROR_INCOMPATIBLE_INPUT, + "Images are %" CPL_SIZE_FORMAT + " X %" CPL_SIZE_FORMAT + " (%s) <=> %" CPL_SIZE_FORMAT + " X %" CPL_SIZE_FORMAT " (%s)", + im1->nx, im1->ny, + cpl_type_get_name(im1->type), im2->nx, + im2->ny, cpl_type_get_name(im2->type)); +} +else if (im1->ny != im2->ny) { + return cpl_error_set_message_(CPL_ERROR_INCOMPATIBLE_INPUT, + "Images are %" CPL_SIZE_FORMAT + " X %" CPL_SIZE_FORMAT + " (%s) <=> %" CPL_SIZE_FORMAT + " X %" CPL_SIZE_FORMAT " (%s)", + im1->nx, im1->ny, + cpl_type_get_name(im1->type), im2->nx, + im2->ny, cpl_type_get_name(im2->type)); +} - assert( im1->pixels ); - assert( im2->pixels ); +assert(im1->pixels); +assert(im2->pixels); - /* Switch on the first passed image type */ - switch (im1->type) { +/* Switch on the first passed image type */ +switch (im1->type) { case CPL_TYPE_INT: { - int * p1 = (int *)im1->pixels; + int *p1 = (int *)im1->pixels; /* Switch on the second passed image type */ switch (im2->type) { -#define CPL_TYPE_T CPL_TYPE_INT -#define CPL_TYPE int +#define CPL_TYPE_T CPL_TYPE_INT +#define CPL_TYPE int #include "cpl_image_basic_body.h" #undef CPL_TYPE_T #undef CPL_TYPE @@ -1104,13 +1145,13 @@ #include "cpl_image_basic_body.h" #undef CPL_TYPE_T #undef CPL_TYPE - default: - return cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); + default: + return cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); } break; } case CPL_TYPE_FLOAT: { - float * p1 = (float *)im1->pixels; + float *p1 = (float *)im1->pixels; /* Switch on the second passed image type */ switch (im2->type) { @@ -1131,14 +1172,14 @@ #include "cpl_image_basic_body.h" #undef CPL_TYPE_T #undef CPL_TYPE - default: - return cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); + default: + return cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); } - cpl_tools_add_flops( im1->nx * im1->ny ); + cpl_tools_add_flops(im1->nx * im1->ny); break; } case CPL_TYPE_DOUBLE: { - double * p1 = (double *)im1->pixels; + double *p1 = (double *)im1->pixels; /* Switch on the second passed image type */ switch (im2->type) { @@ -1160,14 +1201,14 @@ #undef CPL_TYPE_T #undef CPL_TYPE - default: - return cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); + default: + return cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); } - cpl_tools_add_flops( im1->nx * im1->ny ); + cpl_tools_add_flops(im1->nx * im1->ny); break; } case CPL_TYPE_FLOAT_COMPLEX: { - float complex * p1 = (float complex *)im1->pixels; + float complex *p1 = (float complex *)im1->pixels; /* Switch on the second passed image type */ switch (im2->type) { @@ -1201,14 +1242,14 @@ #undef CPL_TYPE_T #undef CPL_TYPE - default: - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + default: + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } - cpl_tools_add_flops( im1->nx * im1->ny ); + cpl_tools_add_flops(im1->nx * im1->ny); break; } case CPL_TYPE_DOUBLE_COMPLEX: { - double complex * p1 = (double complex *)im1->pixels; + double complex *p1 = (double complex *)im1->pixels; /* Switch on the second passed image type */ switch (im2->type) { @@ -1242,440 +1283,447 @@ #undef CPL_TYPE_T #undef CPL_TYPE - default: - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + default: + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } - cpl_tools_add_flops( im1->nx * im1->ny ); + cpl_tools_add_flops(im1->nx * im1->ny); break; } default: return cpl_error_set_(CPL_ERROR_INVALID_TYPE); - } +} - /* Handle bad pixels map */ - if (im2->bpm != NULL) { - if (im1->bpm == NULL) { - im1->bpm = cpl_mask_duplicate(im2->bpm); - } else { - cpl_mask_or(im1->bpm, im2->bpm); - } +/* Handle bad pixels map */ +if (im2->bpm != NULL) { + if (im1->bpm == NULL) { + im1->bpm = cpl_mask_duplicate(im2->bpm); + } + else { + cpl_mask_or(im1->bpm, im2->bpm); } +} - return CPL_ERROR_NONE; +return CPL_ERROR_NONE; #undef CPL_OPERATION #define CPL_OPERATION CPL_IMAGE_BASIC_ASSIGN_LOCAL #elif CPL_OPERATION == CPL_IMAGE_BASIC_OP_SCALAR - - case CPL_TYPE_T: - { - CPL_TYPE * pio = (CPL_TYPE*)self->pixels; - const CPL_TYPE cscalar = (const CPL_TYPE)scalar; - const size_t nxy = (size_t)(self->nx * self->ny); - size_t i; - - assert( self->pixels ); - - for (i = 0; i < nxy; i++) { - CPL_OPERATOR(pio[i], cscalar); - } + +case CPL_TYPE_T: { + CPL_TYPE *pio = (CPL_TYPE *)self->pixels; + const CPL_TYPE cscalar = (const CPL_TYPE)scalar; + const size_t nxy = (size_t)(self->nx * self->ny); + size_t i; + + assert(self->pixels); + + for (i = 0; i < nxy; i++) { + CPL_OPERATOR(pio[i], cscalar); + } #ifdef CPL_TYPE_IS_FPOINT - cpl_tools_add_flops( nxy ); + cpl_tools_add_flops(nxy); #endif - break; - } + break; +} #elif CPL_OPERATION == CPL_IMAGE_BASIC_SQRT - - case CPL_TYPE_T: - { - CPL_TYPE * pio = (CPL_TYPE*)image->pixels; - const size_t nxy = (size_t)(image->nx * image->ny); - size_t i; - for (i=0; i < nxy; i++) - pio[i] = sqrt(pio[i]); +case CPL_TYPE_T: { + CPL_TYPE *pio = (CPL_TYPE *)image->pixels; + const size_t nxy = (size_t)(image->nx * image->ny); + size_t i; + + for (i = 0; i < nxy; i++) + pio[i] = sqrt(pio[i]); #ifdef CPL_TYPE_IS_FPOINT - cpl_tools_add_flops( image->nx * image->ny ); + cpl_tools_add_flops(image->nx * image->ny); #endif - break; - } + break; +} #elif CPL_OPERATION == CPL_IMAGE_BASIC_THRESHOLD - case CPL_TYPE_T: - { - CPL_TYPE * pi = (CPL_TYPE*)image_in->pixels; - const size_t nxy = (size_t)(image_in->nx * image_in->ny); - size_t i; - - for (i=0; i < nxy; i++) { - if (pi[i] > hi_cut) pi[i] = (CPL_TYPE)assign_hi_cut; - else if (pi[i] < lo_cut) pi[i] = (CPL_TYPE)assign_lo_cut; - } - break; - } +case CPL_TYPE_T: { + CPL_TYPE *pi = (CPL_TYPE *)image_in->pixels; + const size_t nxy = (size_t)(image_in->nx * image_in->ny); + size_t i; + + for (i = 0; i < nxy; i++) { + if (pi[i] > hi_cut) + pi[i] = (CPL_TYPE)assign_hi_cut; + else if (pi[i] < lo_cut) + pi[i] = (CPL_TYPE)assign_lo_cut; + } + break; +} #elif CPL_OPERATION == CPL_IMAGE_BASIC_ABS - case CPL_TYPE_T: - { - CPL_TYPE * pio = (CPL_TYPE*)image->pixels; - const size_t nxy = (size_t)(image->nx * image->ny); - size_t i; +case CPL_TYPE_T: { + CPL_TYPE *pio = (CPL_TYPE *)image->pixels; + const size_t nxy = (size_t)(image->nx * image->ny); + size_t i; - for (i = 0; i < nxy; i++) - pio[i] = (CPL_TYPE)CPL_MATH_ABS(pio[i]); + for (i = 0; i < nxy; i++) + pio[i] = (CPL_TYPE)CPL_MATH_ABS(pio[i]); #ifdef CPL_TYPE_IS_FPOINT - cpl_tools_add_flops( image->nx * image->ny ); + cpl_tools_add_flops(image->nx * image->ny); #endif - break; - } + break; +} #elif CPL_OPERATION == CPL_IMAGE_BASIC_AVERAGE - - case CPL_TYPE_T: - { - const size_t nxy = (size_t)(image_1->nx * image_1->ny); - const CPL_TYPE * pi1 = (const CPL_TYPE*)image_1->pixels; - CPL_TYPE * po = (CPL_TYPE *)cpl_malloc(nxy * sizeof(*po)); - size_t i; - - /* Switch on second passed image type */ - switch (image_2->type) { - case CPL_TYPE_INT: - pii2 = (int*)image_2->pixels; - for (i = 0; i < nxy; i++) - po[i] = (CPL_TYPE)(0.5 * (pi1[i] + pii2[i])); - break; - case CPL_TYPE_FLOAT: - pfi2 = (float*)image_2->pixels; - for (i = 0; i < nxy; i++) - po[i] = (CPL_TYPE)(0.5 * (pi1[i] + pfi2[i])); - break; - case CPL_TYPE_DOUBLE: - pdi2 = (double*)image_2->pixels; - for (i = 0; i < nxy; i++) - po[i] = (CPL_TYPE)(0.5 * (pi1[i] + pdi2[i])); - break; - default: - cpl_free(po); - (void)cpl_error_set_(CPL_ERROR_INVALID_TYPE); - return NULL; - } - image_out = cpl_image_wrap_(image_1->nx, image_1->ny, CPL_TYPE_T, po); + +case CPL_TYPE_T: { + const size_t nxy = (size_t)(image_1->nx * image_1->ny); + const CPL_TYPE *pi1 = (const CPL_TYPE *)image_1->pixels; + CPL_TYPE *po = (CPL_TYPE *)cpl_malloc(nxy * sizeof(*po)); + size_t i; + + /* Switch on second passed image type */ + switch (image_2->type) { + case CPL_TYPE_INT: + pii2 = (int *)image_2->pixels; + for (i = 0; i < nxy; i++) + po[i] = (CPL_TYPE)(0.5 * (pi1[i] + pii2[i])); + break; + case CPL_TYPE_FLOAT: + pfi2 = (float *)image_2->pixels; + for (i = 0; i < nxy; i++) + po[i] = (CPL_TYPE)(0.5 * (pi1[i] + pfi2[i])); + break; + case CPL_TYPE_DOUBLE: + pdi2 = (double *)image_2->pixels; + for (i = 0; i < nxy; i++) + po[i] = (CPL_TYPE)(0.5 * (pi1[i] + pdi2[i])); + break; + default: + cpl_free(po); + (void)cpl_error_set_(CPL_ERROR_INVALID_TYPE); + return NULL; + } + image_out = cpl_image_wrap_(image_1->nx, image_1->ny, CPL_TYPE_T, po); #ifdef CPL_TYPE_IS_FPOINT - cpl_tools_add_flops( 2 * image_out->nx * image_out->ny ); + cpl_tools_add_flops(2 * image_out->nx * image_out->ny); #endif - break; - } + break; +} #elif CPL_OPERATION == CPL_IMAGE_BASIC_EXTRACT - case CPL_TYPE_T: - { - const size_t outlx = urx - llx + 1; - const size_t outly = ury - lly + 1; - - /* Output pixel buffer */ - void * po = cpl_malloc(outlx * outly * sizeof(CPL_TYPE)); +case CPL_TYPE_T: { + const size_t outlx = urx - llx + 1; + const size_t outly = ury - lly + 1; - if (cpl_tools_copy_window(po, in->pixels, sizeof(CPL_TYPE), - in->nx, in->ny, llx, lly, urx, ury)) { - cpl_free(po); - (void)cpl_error_set_where_(); - } else { - self = CPL_TYPE_ADD(cpl_image_wrap)(outlx, outly, (CPL_TYPE*)po); - } + /* Output pixel buffer */ + void *po = cpl_malloc(outlx * outly * sizeof(CPL_TYPE)); - break; + if (cpl_tools_copy_window(po, in->pixels, sizeof(CPL_TYPE), in->nx, in->ny, + llx, lly, urx, ury)) { + cpl_free(po); + (void)cpl_error_set_where_(); + } + else { + self = CPL_TYPE_ADD(cpl_image_wrap)(outlx, outly, (CPL_TYPE *)po); } + break; +} + #elif CPL_OPERATION == CPL_IMAGE_BASIC_EXTRACTROW - case CPL_TYPE_T: - { - CPL_TYPE * pi = (CPL_TYPE*)image_in->pixels; - size_t i; +case CPL_TYPE_T: { + CPL_TYPE *pi = (CPL_TYPE *)image_in->pixels; + size_t i; - for (i = 0; i < (size_t)image_in->nx; i++) { - out_data[i] = (double)pi[i+(pos-1)*image_in->nx]; - } - break; + for (i = 0; i < (size_t)image_in->nx; i++) { + out_data[i] = (double)pi[i + (pos - 1) * image_in->nx]; } + break; +} #elif CPL_OPERATION == CPL_IMAGE_BASIC_EXTRACTCOL - case CPL_TYPE_T: - { - CPL_TYPE * pi = (CPL_TYPE*)image_in->pixels; - size_t i; +case CPL_TYPE_T: { + CPL_TYPE *pi = (CPL_TYPE *)image_in->pixels; + size_t i; - for (i = 0; i < (size_t)image_in->ny; i++) { - out_data[i] = (double)pi[pos-1+i*image_in->nx]; - } - break; + for (i = 0; i < (size_t)image_in->ny; i++) { + out_data[i] = (double)pi[pos - 1 + i * image_in->nx]; } + break; +} #elif CPL_OPERATION == CPL_IMAGE_BASIC_COLLAPSE_MEDIAN - case CPL_TYPE_T: - { - /* Number of output pixels */ - const size_t npix = direction ? self->ny : self->nx; - - /* Max number of input pixels in one median computation */ - const size_t nmed = (direction ? self->nx : self->ny) - ndrop; - - const CPL_TYPE * pi = (const CPL_TYPE*)self->pixels; - CPL_TYPE * po = (CPL_TYPE*)cpl_malloc(npix * sizeof(CPL_TYPE)); - CPL_TYPE * med = (CPL_TYPE*)cpl_malloc(nmed * sizeof(CPL_TYPE)); - cpl_binary * bpm = NULL; - const cpl_binary * bin = self->bpm - ? cpl_mask_get_data_const(self->bpm) : NULL; - cpl_boolean isok = bin == NULL ? CPL_TRUE : CPL_FALSE; - size_t i, j; - - if (direction == 1) { - /* Collapsing the image in the x direction */ - pi += drop_ll; - if (bin == NULL) { - for (j = 0; j < (size_t)(self->ny); j++, pi += self->nx) { - size_t k = 0; - for (i = 0; i < nmed; i++) { +case CPL_TYPE_T: { + /* Number of output pixels */ + const size_t npix = direction ? self->ny : self->nx; + + /* Max number of input pixels in one median computation */ + const size_t nmed = (direction ? self->nx : self->ny) - ndrop; + + const CPL_TYPE *pi = (const CPL_TYPE *)self->pixels; + CPL_TYPE *po = (CPL_TYPE *)cpl_malloc(npix * sizeof(CPL_TYPE)); + CPL_TYPE *med = (CPL_TYPE *)cpl_malloc(nmed * sizeof(CPL_TYPE)); + cpl_binary *bpm = NULL; + const cpl_binary *bin = + self->bpm ? cpl_mask_get_data_const(self->bpm) : NULL; + cpl_boolean isok = bin == NULL ? CPL_TRUE : CPL_FALSE; + size_t i, j; + + if (direction == 1) { + /* Collapsing the image in the x direction */ + pi += drop_ll; + if (bin == NULL) { + for (j = 0; j < (size_t)(self->ny); j++, pi += self->nx) { + size_t k = 0; + for (i = 0; i < nmed; i++) { + med[k++] = pi[i]; + } + po[j] = CPL_TYPE_ADD(cpl_tools_get_median)(med, k); + } + } + else { + bin += drop_ll; + for (j = 0; j < (size_t)(self->ny); + j++, pi += self->nx, bin += self->nx) { + size_t k = 0; + for (i = 0; i < nmed; i++) { + if (!bin[i]) med[k++] = pi[i]; - } + } + if (k == 0) { + if (bpm == NULL) + bpm = cpl_calloc((size_t)npix, sizeof(cpl_binary)); + bpm[j] = CPL_BINARY_1; + po[j] = (CPL_TYPE)0; + } + else { po[j] = CPL_TYPE_ADD(cpl_tools_get_median)(med, k); + isok = CPL_TRUE; } - } else { - bin += drop_ll; - for (j = 0; j < (size_t)(self->ny); j++, - pi += self->nx, bin += self->nx) { - size_t k = 0; - for (i = 0; i < nmed; i++) { - if (!bin[i]) med[k++] = pi[i]; - } - if (k == 0) { - if (bpm == NULL) - bpm = cpl_calloc((size_t)npix, sizeof(cpl_binary)); - bpm[j] = CPL_BINARY_1; - po[j] = (CPL_TYPE)0; - } else { - po[j] = CPL_TYPE_ADD(cpl_tools_get_median)(med, k); - isok = CPL_TRUE; - } + } + } + } + else { + /* Collapsing the image in the y direction */ + pi += drop_ll * self->nx; + if (bin == NULL) { + for (i = 0; i < (size_t)(self->nx); i++, pi++) { + size_t k = 0; + for (j = 0; j < nmed; j++) { + med[k++] = pi[j * self->nx]; } + po[i] = CPL_TYPE_ADD(cpl_tools_get_median)(med, k); } - } else { - /* Collapsing the image in the y direction */ - pi += drop_ll * self->nx; - if (bin == NULL) { - for (i = 0; i < (size_t)(self->nx); i++, pi++) { - size_t k = 0; - for (j = 0; j < nmed; j++) { + } + else { + bin += drop_ll * self->nx; + for (i = 0; i < (size_t)(self->nx); i++, pi++, bin++) { + size_t k = 0; + for (j = 0; j < nmed; j++) { + if (!bin[j * self->nx]) med[k++] = pi[j * self->nx]; - } - po[i] = CPL_TYPE_ADD(cpl_tools_get_median)(med, k); } - } else { - bin += drop_ll * self->nx; - for (i = 0; i < (size_t)(self->nx); i++, pi++, bin++) { - size_t k = 0; - for (j = 0; j < nmed; j++) { - if (!bin[j * self->nx]) med[k++] = pi[j * self->nx]; - } - if (k == 0) { - if (bpm == NULL) - bpm = cpl_calloc((size_t)npix, sizeof(cpl_binary)); - bpm[i] = CPL_BINARY_1; - po[i] = (CPL_TYPE)0; - } else { - po[i] = CPL_TYPE_ADD(cpl_tools_get_median)(med, k); - isok = CPL_TRUE; - } + if (k == 0) { + if (bpm == NULL) + bpm = cpl_calloc((size_t)npix, sizeof(cpl_binary)); + bpm[i] = CPL_BINARY_1; + po[i] = (CPL_TYPE)0; + } + else { + po[i] = CPL_TYPE_ADD(cpl_tools_get_median)(med, k); + isok = CPL_TRUE; } } } - cpl_free(med); + } + cpl_free(med); - if (isok) { - other = direction ? CPL_TYPE_ADD(cpl_image_wrap)(1, self->ny, po) - : CPL_TYPE_ADD(cpl_image_wrap)(self->nx, 1, po); - if (bpm != NULL) { - other->bpm = direction ? cpl_mask_wrap(1, self->ny, bpm) - : cpl_mask_wrap(self->nx, 1, bpm); - } - } else { - cpl_free(po); - cpl_free(bpm); - (void)cpl_error_set(cpl_func, CPL_ERROR_DATA_NOT_FOUND); + if (isok) { + other = direction ? CPL_TYPE_ADD(cpl_image_wrap)(1, self->ny, po) + : CPL_TYPE_ADD(cpl_image_wrap)(self->nx, 1, po); + if (bpm != NULL) { + other->bpm = direction ? cpl_mask_wrap(1, self->ny, bpm) + : cpl_mask_wrap(self->nx, 1, bpm); } - - break; + } + else { + cpl_free(po); + cpl_free(bpm); + (void)cpl_error_set(cpl_func, CPL_ERROR_DATA_NOT_FOUND); } + break; +} + #elif CPL_OPERATION == CPL_IMAGE_BASIC_ROTATE_INT_LOCAL - case CPL_TYPE_T: - { - /* rot is 0, 1, 2 or 3. */ - switch(rot) { - case 1: { - CPL_TYPE * pi = (CPL_TYPE *)self->pixels; - size_t i,j; +case CPL_TYPE_T: { + /* rot is 0, 1, 2 or 3. */ + switch (rot) { + case 1: { + CPL_TYPE *pi = (CPL_TYPE *)self->pixels; + size_t i, j; - if (self->nx == self->ny) { - /* If self->nx is even, + if (self->nx == self->ny) { + /* If self->nx is even, then there is a multiple of 4 pixels to move. If self->nx is odd, then there is also a multiple of 4 pixels to move, since the center pixel does not move. */ - /* The first four pixels to move are the corner ones, + /* The first four pixels to move are the corner ones, followed by their neighbors - the last four pixels to move are the center ones. */ - for (j = 0; j < (size_t)(self->ny/2); j++) { - for (i = j; i < (size_t)(self->nx-1-j); i++) { - const CPL_TYPE tmp = pi[i + j * self->nx]; + for (j = 0; j < (size_t)(self->ny / 2); j++) { + for (i = j; i < (size_t)(self->nx - 1 - j); i++) { + const CPL_TYPE tmp = pi[i + j * self->nx]; - pi[i + j * self->nx] - = pi[(self->ny-1-j) + i * self->nx]; + pi[i + j * self->nx] = + pi[(self->ny - 1 - j) + i * self->nx]; - pi[(self->ny-1-j) + i * self->nx] - = pi[(self->nx-1-i) + (self->ny-1-j) * self->nx]; + pi[(self->ny - 1 - j) + i * self->nx] = + pi[(self->nx - 1 - i) + + (self->ny - 1 - j) * self->nx]; - pi[(self->nx-1-i) + (self->ny-1-j) * self->nx] - = pi[j + (self->nx-1-i) * self->nx]; + pi[(self->nx - 1 - i) + (self->ny - 1 - j) * self->nx] = + pi[j + (self->nx - 1 - i) * self->nx]; - pi[j + (self->nx-1-i) * self->nx] = tmp; - } + pi[j + (self->nx - 1 - i) * self->nx] = tmp; } - } else if (self->nx == 1) { - /* No pixels need to move - just swap nx and ny */ - self->nx = self->ny; - self->ny = 1; - } else if (self->ny == 1) { - /* The image is a single horizontal row, + } + } + else if (self->nx == 1) { + /* No pixels need to move - just swap nx and ny */ + self->nx = self->ny; + self->ny = 1; + } + else if (self->ny == 1) { + /* The image is a single horizontal row, the order of the pixels needs to be reversed */ - - /* Flip the 1D-image and swap nx and ny */ - CPL_TYPE_ADD(cpl_tools_flip)(pi, (size_t)self->nx); - self->ny = self->nx; - self->nx = 1; - } else { - /* Duplicate the input image :-( */ - cpl_image * tmp = cpl_image_duplicate(self); - const CPL_TYPE * pt = (const CPL_TYPE *)tmp->pixels; - - self->nx = tmp->ny; - self->ny = tmp->nx; - pi += ((self->ny)-1)* (self->nx); - for (j=0; j < (size_t)(self->nx); j++) { - for (i = 0; i < (size_t)(self->ny); i++) { - *pi = *pt++; - pi -= (self->nx); - } - pi += (self->nx)*(self->ny)+1; + + /* Flip the 1D-image and swap nx and ny */ + CPL_TYPE_ADD(cpl_tools_flip)(pi, (size_t)self->nx); + self->ny = self->nx; + self->nx = 1; + } + else { + /* Duplicate the input image :-( */ + cpl_image *tmp = cpl_image_duplicate(self); + const CPL_TYPE *pt = (const CPL_TYPE *)tmp->pixels; + + self->nx = tmp->ny; + self->ny = tmp->nx; + pi += ((self->ny) - 1) * (self->nx); + for (j = 0; j < (size_t)(self->nx); j++) { + for (i = 0; i < (size_t)(self->ny); i++) { + *pi = *pt++; + pi -= (self->nx); } - cpl_image_delete(tmp); + pi += (self->nx) * (self->ny) + 1; } - break; + cpl_image_delete(tmp); } - case 2: { - /* A 180 degree rotation preserves the shape of the image, + break; + } + case 2: { + /* A 180 degree rotation preserves the shape of the image, and reverts the order of the pixels */ - CPL_TYPE_ADD(cpl_tools_flip)((CPL_TYPE *)self->pixels, - (size_t)self->nx * - (size_t)self->ny); - break; - } - case 3: { - CPL_TYPE * pi = (CPL_TYPE *)self->pixels; - size_t i,j; - if (self->nx == self->ny) { - /* See case 1. */ - for (j = 0; j < (size_t)(self->ny/2); j++) { - for (i = j; i < (size_t)(self->nx-1-j); i++) { - const CPL_TYPE tmp = pi[i + j * self->nx]; - - pi[i + j * self->nx] - = pi[j + (self->nx-1-i) * self->nx]; + CPL_TYPE_ADD(cpl_tools_flip) + ((CPL_TYPE *)self->pixels, (size_t)self->nx * (size_t)self->ny); + break; + } + case 3: { + CPL_TYPE *pi = (CPL_TYPE *)self->pixels; + size_t i, j; + if (self->nx == self->ny) { + /* See case 1. */ + for (j = 0; j < (size_t)(self->ny / 2); j++) { + for (i = j; i < (size_t)(self->nx - 1 - j); i++) { + const CPL_TYPE tmp = pi[i + j * self->nx]; - pi[j + (self->nx-1-i) * self->nx] - = pi[(self->nx-1-i) + (self->ny-1-j) * self->nx]; + pi[i + j * self->nx] = + pi[j + (self->nx - 1 - i) * self->nx]; - pi[(self->nx-1-i) + (self->ny-1-j) * self->nx] - = pi[(self->ny-1-j) + i * self->nx]; + pi[j + (self->nx - 1 - i) * self->nx] = + pi[(self->nx - 1 - i) + + (self->ny - 1 - j) * self->nx]; - pi[(self->ny-1-j) + i * self->nx] = tmp; - } + pi[(self->nx - 1 - i) + (self->ny - 1 - j) * self->nx] = + pi[(self->ny - 1 - j) + i * self->nx]; + + pi[(self->ny - 1 - j) + i * self->nx] = tmp; } - } else if (self->ny == 1) { - /* No pixels need to move - just swap nx and ny */ - self->ny = self->nx; - self->nx = 1; - } else if (self->nx == 1) { - /* The image is a single vertical solumn, + } + } + else if (self->ny == 1) { + /* No pixels need to move - just swap nx and ny */ + self->ny = self->nx; + self->nx = 1; + } + else if (self->nx == 1) { + /* The image is a single vertical solumn, the order of the pixels needs to be reversed */ - /* Flip the 1D-image and swap nx and ny */ - CPL_TYPE_ADD(cpl_tools_flip)(pi, (size_t)self->ny); - self->nx = self->ny; - self->ny = 1; - } else { - /* Duplicate the input image :-( */ - cpl_image * tmp = cpl_image_duplicate(self); - const CPL_TYPE * pt = (const CPL_TYPE *)tmp->pixels; - - self->nx = tmp->ny; - self->ny = tmp->nx; - pi += (self->nx)-1; - for (j=0; j < (size_t)(self->nx); j++) { - for (i = 0; i < (size_t)(self->ny); i++) { - *pi = *pt++; - pi += (self->nx); - } - pi -= (self->nx)*(self->ny)+1; + /* Flip the 1D-image and swap nx and ny */ + CPL_TYPE_ADD(cpl_tools_flip)(pi, (size_t)self->ny); + self->nx = self->ny; + self->ny = 1; + } + else { + /* Duplicate the input image :-( */ + cpl_image *tmp = cpl_image_duplicate(self); + const CPL_TYPE *pt = (const CPL_TYPE *)tmp->pixels; + + self->nx = tmp->ny; + self->ny = tmp->nx; + pi += (self->nx) - 1; + for (j = 0; j < (size_t)(self->nx); j++) { + for (i = 0; i < (size_t)(self->ny); i++) { + *pi = *pt++; + pi += (self->nx); } - cpl_image_delete(tmp); + pi -= (self->nx) * (self->ny) + 1; } - break; + cpl_image_delete(tmp); } - default: - break; + break; } - break; + default: + break; } + break; +} #elif CPL_OPERATION == CPL_IMAGE_BASIC_FLIP_LOCAL - case CPL_TYPE_T: - { - const size_t nx = im->nx; - const size_t ny = im->ny; - CPL_TYPE * pi = (CPL_TYPE *)im->pixels; - size_t i, j; +case CPL_TYPE_T: { + const size_t nx = im->nx; + const size_t ny = im->ny; + CPL_TYPE *pi = (CPL_TYPE *)im->pixels; + size_t i, j; - switch(angle) { + switch (angle) { case 0: { const size_t rowsize = (size_t)nx * sizeof(CPL_TYPE); - CPL_TYPE row[nx]; - CPL_TYPE * pfirst = pi; - CPL_TYPE * plast = pi + (ny-1) * nx; - - for (j = 0; j < ny/2; j++, pfirst += nx, plast -= nx) { - (void)memcpy(row, pfirst, rowsize); - (void)memcpy(pfirst, plast, rowsize); - (void)memcpy(plast, row, rowsize); + CPL_TYPE row[nx]; + CPL_TYPE *pfirst = pi; + CPL_TYPE *plast = pi + (ny - 1) * nx; + + for (j = 0; j < ny / 2; j++, pfirst += nx, plast -= nx) { + (void)memcpy(row, pfirst, rowsize); + (void)memcpy(pfirst, plast, rowsize); + (void)memcpy(plast, row, rowsize); } break; } case 2: { - for (j = 0; j < ny; j++, pi += nx) { CPL_TYPE_ADD(cpl_tools_flip)(pi, nx); } @@ -1683,7 +1731,7 @@ } case 1: { if (nx == ny) { - CPL_TYPE * pt = pi; + CPL_TYPE *pt = pi; for (j = 0; j < nx; j++, pt += nx) { for (i = 0; i < j; i++) { @@ -1692,19 +1740,20 @@ pi[j + i * nx] = tmp; } } - } else { + } + else { /* Duplicate the input image */ - cpl_image * tmp_im = cpl_image_duplicate(im); - const CPL_TYPE * pt = (const CPL_TYPE *)tmp_im->pixels; + cpl_image *tmp_im = cpl_image_duplicate(im); + const CPL_TYPE *pt = (const CPL_TYPE *)tmp_im->pixels; im->nx = ny; im->ny = nx; - for (j=0; jpixels; + cpl_image *tmp_im = cpl_image_duplicate(im); + const CPL_TYPE *pt = (const CPL_TYPE *)tmp_im->pixels; im->nx = ny; im->ny = nx; - pt += (nx*ny-1); - for (j=0; jpixels; - po = (CPL_TYPE *)im->pixels; - - /* Move the pixels */ - for (j=0; jnx*(l+j*tile_sz_y); - npos=(k+tile_x*tile_sz_x) + - im->nx*(l+tile_y*tile_sz_y); - po[npos] = pi[opos]; - } +case CPL_TYPE_T: { + /* Duplicate the input image */ + cpl_image *tmp_im = cpl_image_duplicate(im); + CPL_TYPE *po; + const CPL_TYPE *pi; + + cpl_ensure_code(tmp_im, cpl_error_get_code()); + + /* Get pointer to the data */ + pi = (const CPL_TYPE *)tmp_im->pixels; + po = (CPL_TYPE *)im->pixels; + + /* Move the pixels */ + for (j = 0; j < nb_cut; j++) { + for (i = 0; i < nb_cut; i++) { + tile_x = (new_pos[i + j * nb_cut] - 1) % nb_cut; + tile_y = (new_pos[i + j * nb_cut] - 1) / nb_cut; + for (l = 0; l < tile_sz_y; l++) { + for (k = 0; k < tile_sz_x; k++) { + opos = (k + i * tile_sz_x) + im->nx * (l + j * tile_sz_y); + npos = (k + tile_x * tile_sz_x) + + im->nx * (l + tile_y * tile_sz_y); + po[npos] = pi[opos]; } } } - cpl_image_delete(tmp_im); - break; } + cpl_image_delete(tmp_im); + break; +} #else #error "Undefined CPL Operation" diff -Nru cpl-7.1.4+ds/cplcore/cpl_image_basic.c cpl-7.2.2+ds/cplcore/cpl_image_basic.c --- cpl-7.1.4+ds/cplcore/cpl_image_basic.c 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_image_basic.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -60,39 +60,40 @@ Defines -----------------------------------------------------------------------------*/ -#define CPL_IMAGE_BASIC_ASSIGN 1 -#define CPL_IMAGE_BASIC_ASSIGN_LOCAL 2 -#define CPL_IMAGE_BASIC_THRESHOLD 3 -#define CPL_IMAGE_BASIC_ABS 4 -#define CPL_IMAGE_BASIC_AVERAGE 5 -#define CPL_IMAGE_BASIC_SUBMIN 6 -#define CPL_IMAGE_BASIC_EXTRACT 7 -#define CPL_IMAGE_BASIC_EXTRACTROW 8 -#define CPL_IMAGE_BASIC_EXTRACTCOL 9 -#define CPL_IMAGE_BASIC_COLLAPSE_MEDIAN 11 -#define CPL_IMAGE_BASIC_ROTATE_INT_LOCAL 12 -#define CPL_IMAGE_BASIC_FLIP_LOCAL 15 -#define CPL_IMAGE_BASIC_MOVE_PIXELS 16 -#define CPL_IMAGE_BASIC_OP_SCALAR 21 -#define CPL_IMAGE_BASIC_SQRT 22 -#define CPL_IMAGE_BASIC_DECLARE 23 - -#define CPL_IMAGE_BASIC_OPERATE 24 -#define CPL_IMAGE_BASIC_DIVIDE 25 -#define CPL_IMAGE_BASIC_OPERATE_LOCAL 26 -#define CPL_IMAGE_BASIC_DIVIDE_LOCAL 27 -#define CPL_IMAGE_BASIC_HYPOT 28 - -#define CPL_IMAGE_ADDITION(a,b,c) a = (b) + (c) -#define CPL_IMAGE_ADDITIONASSIGN(a,b) a += (b) -#define CPL_IMAGE_SUBTRACTION(a,b,c) a = (b) - (c) -#define CPL_IMAGE_SUBTRACTIONASSIGN(a,b) a -= (b) -#define CPL_IMAGE_MULTIPLICATION(a,b,c) a = (b) * (c) -#define CPL_IMAGE_MULTIPLICATIONASSIGN(a,b) a *= (b) -#define CPL_IMAGE_DIVISION(a,b,c) a = (b) / (c) -#define CPL_IMAGE_DIVISIONASSIGN(a,b) a /= (b) -#define CPL_IMAGE_MINABS(a,b,c) a = CPL_MATH_ABS1(b) < CPL_MATH_ABS2(c) ? (b) : (c) - +#define CPL_IMAGE_BASIC_ASSIGN 1 +#define CPL_IMAGE_BASIC_ASSIGN_LOCAL 2 +#define CPL_IMAGE_BASIC_THRESHOLD 3 +#define CPL_IMAGE_BASIC_ABS 4 +#define CPL_IMAGE_BASIC_AVERAGE 5 +#define CPL_IMAGE_BASIC_SUBMIN 6 +#define CPL_IMAGE_BASIC_EXTRACT 7 +#define CPL_IMAGE_BASIC_EXTRACTROW 8 +#define CPL_IMAGE_BASIC_EXTRACTCOL 9 +#define CPL_IMAGE_BASIC_COLLAPSE_MEDIAN 11 +#define CPL_IMAGE_BASIC_ROTATE_INT_LOCAL 12 +#define CPL_IMAGE_BASIC_FLIP_LOCAL 15 +#define CPL_IMAGE_BASIC_MOVE_PIXELS 16 +#define CPL_IMAGE_BASIC_OP_SCALAR 21 +#define CPL_IMAGE_BASIC_SQRT 22 +#define CPL_IMAGE_BASIC_DECLARE 23 + +#define CPL_IMAGE_BASIC_OPERATE 24 +#define CPL_IMAGE_BASIC_DIVIDE 25 +#define CPL_IMAGE_BASIC_OPERATE_LOCAL 26 +#define CPL_IMAGE_BASIC_DIVIDE_LOCAL 27 +#define CPL_IMAGE_BASIC_HYPOT 28 + +#define CPL_IMAGE_ADDITION(a, b, c) a = (b) + (c) +#define CPL_IMAGE_ADDITIONASSIGN(a, b) a += (b) +#define CPL_IMAGE_SUBTRACTION(a, b, c) a = (b) - (c) +#define CPL_IMAGE_SUBTRACTIONASSIGN(a, b) a -= (b) +#define CPL_IMAGE_MULTIPLICATION(a, b, c) a = (b) * (c) +#define CPL_IMAGE_MULTIPLICATIONASSIGN(a, b) a *= (b) +#define CPL_IMAGE_DIVISION(a, b, c) a = (b) / (c) +#define CPL_IMAGE_DIVISIONASSIGN(a, b) a /= (b) +#define CPL_IMAGE_MINABS(a, b, c) \ + a = CPL_MATH_ABS1(b) < CPL_MATH_ABS2(c) ? (b) : (c) + /*----------------------------------------------------------------------------- Private Function prototypes -----------------------------------------------------------------------------*/ @@ -105,13 +106,13 @@ #define CPL_OPERATION CPL_IMAGE_BASIC_HYPOT #define CPL_TYPE_T1 CPL_TYPE_FLOAT -#define CPL_TYPE1 float +#define CPL_TYPE1 float #define CPL_TYPE_T2 CPL_TYPE_FLOAT #define CPL_TYPE_T3 CPL_TYPE_FLOAT -#define CPL_TYPE2 float -#define CPL_TYPE3 float -#define CPL_HYPOT hypotf +#define CPL_TYPE2 float +#define CPL_TYPE3 float +#define CPL_HYPOT hypotf #include "cpl_image_basic_body.h" #undef CPL_TYPE_T2 @@ -123,9 +124,9 @@ #define CPL_TYPE_T2 CPL_TYPE_FLOAT #define CPL_TYPE_T3 CPL_TYPE_DOUBLE -#define CPL_TYPE2 float -#define CPL_TYPE3 double -#define CPL_HYPOT hypot +#define CPL_TYPE2 float +#define CPL_TYPE3 double +#define CPL_HYPOT hypot #include "cpl_image_basic_body.h" #undef CPL_TYPE_T2 #undef CPL_TYPE_T3 @@ -134,8 +135,8 @@ #define CPL_TYPE_T2 CPL_TYPE_DOUBLE #define CPL_TYPE_T3 CPL_TYPE_FLOAT -#define CPL_TYPE2 double -#define CPL_TYPE3 float +#define CPL_TYPE2 double +#define CPL_TYPE3 float #include "cpl_image_basic_body.h" #undef CPL_TYPE_T2 #undef CPL_TYPE_T3 @@ -144,8 +145,8 @@ #define CPL_TYPE_T2 CPL_TYPE_DOUBLE #define CPL_TYPE_T3 CPL_TYPE_DOUBLE -#define CPL_TYPE2 double -#define CPL_TYPE3 double +#define CPL_TYPE2 double +#define CPL_TYPE3 double #include "cpl_image_basic_body.h" #undef CPL_TYPE_T2 #undef CPL_TYPE_T3 @@ -155,14 +156,14 @@ #undef CPL_TYPE_T1 #undef CPL_TYPE1 #define CPL_TYPE_T1 CPL_TYPE_DOUBLE -#define CPL_TYPE1 double +#define CPL_TYPE1 double #undef CPL_HYPOT #define CPL_TYPE_T2 CPL_TYPE_FLOAT #define CPL_TYPE_T3 CPL_TYPE_FLOAT -#define CPL_TYPE2 float -#define CPL_TYPE3 float -#define CPL_HYPOT hypotf +#define CPL_TYPE2 float +#define CPL_TYPE3 float +#define CPL_HYPOT hypotf #include "cpl_image_basic_body.h" #undef CPL_TYPE_T2 @@ -173,9 +174,9 @@ #define CPL_TYPE_T2 CPL_TYPE_FLOAT #define CPL_TYPE_T3 CPL_TYPE_DOUBLE -#define CPL_TYPE2 float -#define CPL_TYPE3 double -#define CPL_HYPOT hypot +#define CPL_TYPE2 float +#define CPL_TYPE3 double +#define CPL_HYPOT hypot #include "cpl_image_basic_body.h" #undef CPL_TYPE_T2 #undef CPL_TYPE_T3 @@ -184,8 +185,8 @@ #define CPL_TYPE_T2 CPL_TYPE_DOUBLE #define CPL_TYPE_T3 CPL_TYPE_FLOAT -#define CPL_TYPE2 double -#define CPL_TYPE3 float +#define CPL_TYPE2 double +#define CPL_TYPE3 float #include "cpl_image_basic_body.h" #undef CPL_TYPE_T2 #undef CPL_TYPE_T3 @@ -194,8 +195,8 @@ #define CPL_TYPE_T2 CPL_TYPE_DOUBLE #define CPL_TYPE_T3 CPL_TYPE_DOUBLE -#define CPL_TYPE2 double -#define CPL_TYPE3 double +#define CPL_TYPE2 double +#define CPL_TYPE3 double #include "cpl_image_basic_body.h" #undef CPL_TYPE_T2 #undef CPL_TYPE_T3 @@ -232,10 +233,10 @@ #include #ifdef __clang__ -# define cpl_m_from_int64 (__m64) -# else -# define cpl_m_from_int64 _m_from_int64 -# endif +#define cpl_m_from_int64 (__m64) +#else +#define cpl_m_from_int64 _m_from_int64 +#endif #endif #if defined __SSE2__ || defined __SSE3__ @@ -244,21 +245,22 @@ #define CPL_MM_ADDSUB_PS(a, b) _mm_addsub_ps(a, b) #define CPL_MM_ADDSUB_PD(a, b) _mm_addsub_pd(a, b) #else - /* faster than multiplying with 1,-1,1,-1 */ -#define CPL_MM_ADDSUB_PS(a, b) \ - _mm_add_ps(a, _mm_xor_ps(b, (__m128)_mm_set_epi32(0x0u, 0x80000000u, \ - 0x0u, 0x80000000u))) -#define CPL_MM_ADDSUB_PD(a, b) \ - _mm_add_pd(a, _mm_xor_pd(b, (__m128d)_mm_set_epi64(cpl_m_from_int64(0x0llu), \ - cpl_m_from_int64(0x8000000000000000llu)))) +/* faster than multiplying with 1,-1,1,-1 */ +#define CPL_MM_ADDSUB_PS(a, b) \ + _mm_add_ps(a, _mm_xor_ps(b, (__m128)_mm_set_epi32(0x0u, 0x80000000u, 0x0u, \ + 0x80000000u))) +#define CPL_MM_ADDSUB_PD(a, b) \ + _mm_add_pd(a, _mm_xor_pd(b, (__m128d)_mm_set_epi64( \ + cpl_m_from_int64(0x0llu), \ + cpl_m_from_int64(0x8000000000000000llu)))) #endif -static cpl_error_code cpl_image_multiply_fcomplex_sse_(cpl_image *, - const cpl_image *) - CPL_ATTR_NONNULL; -static cpl_error_code cpl_image_multiply_dcomplex_sse_(cpl_image *, - const cpl_image *) - CPL_ATTR_NONNULL; +static cpl_error_code +cpl_image_multiply_fcomplex_sse_(cpl_image *, + const cpl_image *) CPL_ATTR_NONNULL; +static cpl_error_code +cpl_image_multiply_dcomplex_sse_(cpl_image *, + const cpl_image *) CPL_ATTR_NONNULL; #endif /*----------------------------------------------------------------------------- @@ -290,10 +292,8 @@ while the first one does not */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_add_create( - const cpl_image * image1, - const cpl_image * image2) -{ +cpl_image * +cpl_image_add_create(const cpl_image *image1, const cpl_image *image2){ #define CPL_OPERATOR CPL_IMAGE_ADDITION #include "cpl_image_basic_body.h" #undef CPL_OPERATOR @@ -309,10 +309,8 @@ @see cpl_image_add_create() */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_subtract_create( - const cpl_image * image1, - const cpl_image * image2) -{ +cpl_image *cpl_image_subtract_create(const cpl_image *image1, + const cpl_image *image2){ #define CPL_OPERATOR CPL_IMAGE_SUBTRACTION #include "cpl_image_basic_body.h" #undef CPL_OPERATOR @@ -328,10 +326,8 @@ @see cpl_image_add_create() */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_multiply_create( - const cpl_image * image1, - const cpl_image * image2) -{ +cpl_image *cpl_image_multiply_create(const cpl_image *image1, + const cpl_image *image2){ #define CPL_OPERATOR CPL_IMAGE_MULTIPLICATION #include "cpl_image_basic_body.h" #undef CPL_OPERATOR @@ -350,16 +346,15 @@ absolute minimum */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_min_create( - const cpl_image * image1, - const cpl_image * image2) +cpl_image *cpl_image_min_create(const cpl_image *image1, + const cpl_image *image2) { #define CPL_OPERATOR CPL_IMAGE_MINABS #include "cpl_image_basic_body.h" #undef CPL_OPERATOR } #undef CPL_OPERATION - + /*----------------------------------------------------------------------------*/ /** @ingroup cpl_image @@ -380,19 +375,18 @@ - CPL_ERROR_DIVISION_BY_ZERO is all pixels in the divisor are zero */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_divide_create(const cpl_image * image1, - const cpl_image * image2) +cpl_image * +cpl_image_divide_create(const cpl_image *image1, const cpl_image *image2) { - #define CPL_OPERATION CPL_IMAGE_BASIC_DIVIDE - cpl_image * self; - cpl_mask * zeros; - cpl_binary * pzeros; - cpl_size nzero = 0; + cpl_image *self; + cpl_mask *zeros; + cpl_binary *pzeros; + cpl_size nzero = 0; - cpl_ensure(image1 != NULL, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(image2 != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(image1 != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(image2 != NULL, CPL_ERROR_NULL_INPUT, NULL); cpl_ensure(image1->nx == image2->nx, CPL_ERROR_INCOMPATIBLE_INPUT, NULL); cpl_ensure(image1->ny == image2->ny, CPL_ERROR_INCOMPATIBLE_INPUT, NULL); @@ -402,13 +396,13 @@ /* Switch on the first passed image type */ switch (image1->type) { - case CPL_TYPE_INT: { - const int * p1 = (const int *)image1->pixels; - int * pout = (int *)cpl_malloc(image1->nx * image1->ny * - sizeof(*pout)); + case CPL_TYPE_INT: { + const int *p1 = (const int *)image1->pixels; + int *pout = + (int *)cpl_malloc(image1->nx * image1->ny * sizeof(*pout)); - /* Switch on the second passed image type */ - switch (image2->type) { + /* Switch on the second passed image type */ + switch (image2->type) { #define CPL_TYPE_T CPL_TYPE_INT #define CPL_TYPE int #include "cpl_image_basic_body.h" @@ -427,22 +421,23 @@ #undef CPL_TYPE_T #undef CPL_TYPE - default: - cpl_free(pout); - (void)cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); - pout = NULL; + default: + cpl_free(pout); + (void)cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); + pout = NULL; + } + self = + pout ? cpl_image_wrap_int(image1->nx, image1->ny, pout) : NULL; + break; } - self = pout ? cpl_image_wrap_int(image1->nx, image1->ny, pout) : NULL; - break; - } - case CPL_TYPE_FLOAT: { - const float * p1 = (const float *)image1->pixels; - float * pout = (float *)cpl_malloc(image1->nx * image1->ny * - sizeof(*pout)); + case CPL_TYPE_FLOAT: { + const float *p1 = (const float *)image1->pixels; + float *pout = + (float *)cpl_malloc(image1->nx * image1->ny * sizeof(*pout)); - /* Switch on the second passed image type */ - switch (image2->type) { + /* Switch on the second passed image type */ + switch (image2->type) { #define CPL_TYPE_T CPL_TYPE_INT #define CPL_TYPE int #include "cpl_image_basic_body.h" @@ -461,22 +456,23 @@ #undef CPL_TYPE_T #undef CPL_TYPE - default: - cpl_free(pout); - (void)cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); - pout = NULL; + default: + cpl_free(pout); + (void)cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); + pout = NULL; + } + self = pout ? cpl_image_wrap_float(image1->nx, image1->ny, pout) + : NULL; + break; } - self = pout ? cpl_image_wrap_float(image1->nx, image1->ny, pout) : NULL; - break; - } - case CPL_TYPE_DOUBLE: { - const double * p1 = (const double *)image1->pixels; - double * pout = (double *)cpl_malloc(image1->nx * image1->ny * - sizeof(*pout)); + case CPL_TYPE_DOUBLE: { + const double *p1 = (const double *)image1->pixels; + double *pout = + (double *)cpl_malloc(image1->nx * image1->ny * sizeof(*pout)); - /* Switch on the second passed image type */ - switch (image2->type) { + /* Switch on the second passed image type */ + switch (image2->type) { #define CPL_TYPE_T CPL_TYPE_INT #define CPL_TYPE int #include "cpl_image_basic_body.h" @@ -495,23 +491,23 @@ #undef CPL_TYPE_T #undef CPL_TYPE - default: - cpl_free(pout); - (void)cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); - pout = NULL; - } - self = pout ? cpl_image_wrap_double(image1->nx, image1->ny, pout) : NULL; - break; - } - - case CPL_TYPE_FLOAT_COMPLEX: { - const float complex * p1 = (const float complex *)image1->pixels; - float complex * pout = (float complex *)cpl_malloc(image1->nx * - image1->ny * - sizeof(*pout)); + default: + cpl_free(pout); + (void)cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); + pout = NULL; + } + self = pout ? cpl_image_wrap_double(image1->nx, image1->ny, pout) + : NULL; + break; + } + + case CPL_TYPE_FLOAT_COMPLEX: { + const float complex *p1 = (const float complex *)image1->pixels; + float complex *pout = (float complex *)cpl_malloc( + image1->nx * image1->ny * sizeof(*pout)); - /* Switch on the second passed image type */ - switch (image2->type) { + /* Switch on the second passed image type */ + switch (image2->type) { #define CPL_TYPE_T CPL_TYPE_INT #define CPL_TYPE int #include "cpl_image_basic_body.h" @@ -542,24 +538,24 @@ #undef CPL_TYPE_T #undef CPL_TYPE - default: - cpl_free(pout); - (void)cpl_error_set_(CPL_ERROR_INVALID_TYPE); - pout = NULL; + default: + cpl_free(pout); + (void)cpl_error_set_(CPL_ERROR_INVALID_TYPE); + pout = NULL; + } + self = pout ? cpl_image_wrap_float_complex(image1->nx, image1->ny, + pout) + : NULL; + break; } - self = pout ? cpl_image_wrap_float_complex(image1->nx, image1->ny, pout) - : NULL; - break; - } - case CPL_TYPE_DOUBLE_COMPLEX: { - const double complex * p1 = (const double complex *)image1->pixels; - double complex * pout = (double complex *)cpl_malloc(image1->nx * - image1->ny * - sizeof(*pout)); + case CPL_TYPE_DOUBLE_COMPLEX: { + const double complex *p1 = (const double complex *)image1->pixels; + double complex *pout = (double complex *)cpl_malloc( + image1->nx * image1->ny * sizeof(*pout)); - /* Switch on the second passed image type */ - switch (image2->type) { + /* Switch on the second passed image type */ + switch (image2->type) { #define CPL_TYPE_T CPL_TYPE_INT #define CPL_TYPE int #include "cpl_image_basic_body.h" @@ -591,18 +587,19 @@ #undef CPL_TYPE + default: + cpl_free(pout); + (void)cpl_error_set_(CPL_ERROR_INVALID_TYPE); + pout = NULL; + } + self = pout ? cpl_image_wrap_double_complex(image1->nx, image1->ny, + pout) + : NULL; + break; + } default: - cpl_free(pout); (void)cpl_error_set_(CPL_ERROR_INVALID_TYPE); - pout = NULL; - } - self = pout ? cpl_image_wrap_double_complex(image1->nx, image1->ny, - pout) : NULL; - break; - } - default: - (void)cpl_error_set_(CPL_ERROR_INVALID_TYPE); - self = NULL; + self = NULL; } if (nzero == image1->nx * image1->ny) { @@ -613,15 +610,19 @@ if (self == NULL) { cpl_mask_delete(zeros); - } else { + } + else { /* Handle bad pixels map */ if (image1->bpm == NULL && image2->bpm == NULL) { self->bpm = NULL; - } else if (image1->bpm == NULL) { + } + else if (image1->bpm == NULL) { self->bpm = cpl_mask_duplicate(image2->bpm); - } else if (image2->bpm == NULL) { + } + else if (image2->bpm == NULL) { self->bpm = cpl_mask_duplicate(image1->bpm); - } else { + } + else { self->bpm = cpl_mask_duplicate(image1->bpm); cpl_mask_or(self->bpm, image2->bpm); } @@ -630,23 +631,24 @@ if (nzero != 0) { if (self->bpm == NULL) { self->bpm = zeros; - } else { + } + else { cpl_mask_or(self->bpm, zeros); cpl_mask_delete(zeros); } - } else { + } + else { cpl_mask_delete(zeros); } if (image1->type != CPL_TYPE_INT && image2->type != CPL_TYPE_INT) { - cpl_tools_add_flops( image1->nx * image1->ny - nzero); + cpl_tools_add_flops(image1->nx * image1->ny - nzero); } } return self; #undef CPL_OPERATION - } #define CPL_OPERATION CPL_IMAGE_BASIC_ASSIGN_LOCAL @@ -670,10 +672,8 @@ while the first one does not */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_add( - cpl_image * im1, - const cpl_image * im2) -{ +cpl_error_code +cpl_image_add(cpl_image *im1, const cpl_image *im2){ #define CPL_OPERATOR CPL_IMAGE_ADDITIONASSIGN #include "cpl_image_basic_body.h" #undef CPL_OPERATOR @@ -689,10 +689,7 @@ @see cpl_image_add() */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_subtract( - cpl_image * im1, - const cpl_image * im2) -{ +cpl_error_code cpl_image_subtract(cpl_image *im1, const cpl_image *im2){ #define CPL_OPERATOR CPL_IMAGE_SUBTRACTIONASSIGN #include "cpl_image_basic_body.h" #undef CPL_OPERATOR @@ -708,15 +705,13 @@ @see cpl_image_add() */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_multiply( - cpl_image * im1, - const cpl_image * im2) +cpl_error_code cpl_image_multiply(cpl_image *im1, const cpl_image *im2) { /* Faster version of code generated with gcc -ffast-math */ /* (NaNs and other float specials are no longer IEEE compliant) */ #if (defined __SSE3__ || defined __SSE2__) - cpl_ensure_code(im1 != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(im2 != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(im1 != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(im2 != NULL, CPL_ERROR_NULL_INPUT); if (im1->type == CPL_TYPE_FLOAT_COMPLEX && im2->type == CPL_TYPE_FLOAT_COMPLEX) { @@ -725,8 +720,8 @@ cpl_image_multiply_fcomplex_sse_(im1, im2); return CPL_ERROR_NONE; } - else if (im1->type == CPL_TYPE_DOUBLE_COMPLEX && - im2->type == CPL_TYPE_DOUBLE_COMPLEX) { + else if (im1->type == CPL_TYPE_DOUBLE_COMPLEX && + im2->type == CPL_TYPE_DOUBLE_COMPLEX) { cpl_ensure_code(im1->nx == im2->nx, CPL_ERROR_INCOMPATIBLE_INPUT); cpl_ensure_code(im1->ny == im2->ny, CPL_ERROR_INCOMPATIBLE_INPUT); cpl_image_multiply_dcomplex_sse_(im1, im2); @@ -762,30 +757,32 @@ - CPL_ERROR_DIVISION_BY_ZERO is all pixels in the divisor are zero */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_divide(cpl_image * im1, - const cpl_image * im2) +cpl_error_code +cpl_image_divide(cpl_image *im1, const cpl_image *im2) { #define CPL_OPERATION CPL_IMAGE_BASIC_DIVIDE_LOCAL - cpl_mask * zeros; - cpl_binary * pzeros; - cpl_size nzero = 0; + cpl_mask *zeros; + cpl_binary *pzeros; + cpl_size nzero = 0; - cpl_ensure_code(im1 != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(im2 != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(im1 != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(im2 != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(im1->nx == im2->nx, CPL_ERROR_INCOMPATIBLE_INPUT); cpl_ensure_code(im1->ny == im2->ny, CPL_ERROR_INCOMPATIBLE_INPUT); - assert( im1->pixels ); - assert( im2->pixels ); + assert(im1->pixels); + assert(im2->pixels); /* Create the zeros map */ /* Do not modify im1->bpm now, in case of failure below */ if (im1->bpm != NULL) { zeros = im1->bpm; - } else if (im2->bpm != NULL) { + } + else if (im2->bpm != NULL) { zeros = cpl_mask_duplicate(im2->bpm); - } else { + } + else { zeros = cpl_mask_new(im1->nx, im1->ny); } @@ -793,11 +790,11 @@ /* Switch on the first passed image type */ switch (im1->type) { - case CPL_TYPE_INT: { - int * p1 = (int *)im1->pixels; + case CPL_TYPE_INT: { + int *p1 = (int *)im1->pixels; - /* Switch on the second passed image type */ - switch (im2->type) { + /* Switch on the second passed image type */ + switch (im2->type) { #define CPL_TYPE_T CPL_TYPE_INT #define CPL_TYPE int #include "cpl_image_basic_body.h" @@ -816,18 +813,19 @@ #undef CPL_TYPE_T #undef CPL_TYPE - default: - if (zeros != im1->bpm) cpl_mask_delete(zeros); - return cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); + default: + if (zeros != im1->bpm) + cpl_mask_delete(zeros); + return cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); + } + break; } - break; - } - case CPL_TYPE_FLOAT: { - float * p1 = (float *)im1->pixels; + case CPL_TYPE_FLOAT: { + float *p1 = (float *)im1->pixels; - /* Switch on the second passed image type */ - switch (im2->type) { + /* Switch on the second passed image type */ + switch (im2->type) { #define CPL_TYPE_T CPL_TYPE_INT #define CPL_TYPE int #include "cpl_image_basic_body.h" @@ -846,17 +844,18 @@ #undef CPL_TYPE_T #undef CPL_TYPE - default: - if (zeros != im1->bpm) cpl_mask_delete(zeros); - return cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); + default: + if (zeros != im1->bpm) + cpl_mask_delete(zeros); + return cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); + } + break; } - break; - } - case CPL_TYPE_DOUBLE: { - double * p1 = (double *)im1->pixels; + case CPL_TYPE_DOUBLE: { + double *p1 = (double *)im1->pixels; - /* Switch on the second passed image type */ - switch (im2->type) { + /* Switch on the second passed image type */ + switch (im2->type) { #define CPL_TYPE_T CPL_TYPE_INT #define CPL_TYPE int #include "cpl_image_basic_body.h" @@ -875,14 +874,15 @@ #undef CPL_TYPE_T #undef CPL_TYPE - default: - if (zeros != im1->bpm) cpl_mask_delete(zeros); - return cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); + default: + if (zeros != im1->bpm) + cpl_mask_delete(zeros); + return cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); + } + break; } - break; - } - case CPL_TYPE_FLOAT_COMPLEX: { - float complex * p1 = (float complex *)im1->pixels; + case CPL_TYPE_FLOAT_COMPLEX: { + float complex *p1 = (float complex *)im1->pixels; /* Switch on the second passed image type */ switch (im2->type) { @@ -916,17 +916,18 @@ #undef CPL_TYPE_T #undef CPL_TYPE - default: - if (zeros != im1->bpm) cpl_mask_delete(zeros); - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + default: + if (zeros != im1->bpm) + cpl_mask_delete(zeros); + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } break; - } - case CPL_TYPE_DOUBLE_COMPLEX: { - double complex * p1 = (double complex *)im1->pixels; + } + case CPL_TYPE_DOUBLE_COMPLEX: { + double complex *p1 = (double complex *)im1->pixels; - /* Switch on the second passed image type */ - switch (im2->type) { + /* Switch on the second passed image type */ + switch (im2->type) { #define CPL_TYPE_T CPL_TYPE_INT #define CPL_TYPE int #include "cpl_image_basic_body.h" @@ -957,35 +958,40 @@ #undef CPL_TYPE_T #undef CPL_TYPE - default: - if (zeros != im1->bpm) cpl_mask_delete(zeros); - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + default: + if (zeros != im1->bpm) + cpl_mask_delete(zeros); + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + } + break; } - break; - } - default: - if (zeros != im1->bpm) cpl_mask_delete(zeros); - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + default: + if (zeros != im1->bpm) + cpl_mask_delete(zeros); + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } if (nzero == im1->nx * im1->ny) { - if (zeros != im1->bpm) cpl_mask_delete(zeros); + if (zeros != im1->bpm) + cpl_mask_delete(zeros); return cpl_error_set_(CPL_ERROR_DIVISION_BY_ZERO); } if (im1->type != CPL_TYPE_INT && im2->type != CPL_TYPE_INT) { - cpl_tools_add_flops( im1->nx * im1->ny - nzero); + cpl_tools_add_flops(im1->nx * im1->ny - nzero); } /* Handle bad pixels map */ if (im1->bpm != NULL && im2->bpm != NULL && im1->bpm != im2->bpm) { - assert( zeros == im1->bpm ); + assert(zeros == im1->bpm); cpl_mask_or(im1->bpm, im2->bpm); - } else if (im1->bpm == NULL && (im2->bpm != NULL || nzero > 0)) { - assert( zeros != NULL ); + } + else if (im1->bpm == NULL && (im2->bpm != NULL || nzero > 0)) { + assert(zeros != NULL); im1->bpm = zeros; - } else if (im1->bpm != zeros) { + } + else if (im1->bpm != zeros) { cpl_mask_delete(zeros); } @@ -995,7 +1001,7 @@ #undef CPL_OPERATION #define CPL_OPERATION CPL_IMAGE_BASIC_OP_SCALAR -#define CPL_OPERATOR CPL_IMAGE_ADDITIONASSIGN +#define CPL_OPERATOR CPL_IMAGE_ADDITIONASSIGN /*----------------------------------------------------------------------------*/ /** @ingroup cpl_image @@ -1013,11 +1019,11 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_add_scalar(cpl_image * self, - double scalar) +cpl_error_code +cpl_image_add_scalar(cpl_image *self, double scalar) { cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); - + /* Switch on image type */ switch (cpl_image_get_type(self)) { #define CPL_CLASS CPL_CLASS_DOUBLE @@ -1035,8 +1041,8 @@ #define CPL_CLASS CPL_CLASS_FLOAT_COMPLEX #include "cpl_image_basic_body.h" #undef CPL_CLASS - default: - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + default: + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } return CPL_ERROR_NONE; } @@ -1053,11 +1059,11 @@ @see cpl_image_add_scalar() */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_subtract_scalar(cpl_image * self, - double scalar) +cpl_error_code +cpl_image_subtract_scalar(cpl_image *self, double scalar) { cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); - + /* Switch on image type */ switch (cpl_image_get_type(self)) { #define CPL_CLASS CPL_CLASS_DOUBLE @@ -1075,8 +1081,8 @@ #define CPL_CLASS CPL_CLASS_FLOAT_COMPLEX #include "cpl_image_basic_body.h" #undef CPL_CLASS - default: - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + default: + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } return CPL_ERROR_NONE; } @@ -1093,11 +1099,11 @@ @see cpl_image_add_scalar() */ /*----------------------------------------------------------------------------*/ - cpl_error_code cpl_image_multiply_scalar(cpl_image * self, - double scalar) +cpl_error_code +cpl_image_multiply_scalar(cpl_image *self, double scalar) { cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); - + /* Switch on image type */ switch (cpl_image_get_type(self)) { #define CPL_CLASS CPL_CLASS_DOUBLE @@ -1115,8 +1121,8 @@ #define CPL_CLASS CPL_CLASS_FLOAT_COMPLEX #include "cpl_image_basic_body.h" #undef CPL_CLASS - default: - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + default: + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } return CPL_ERROR_NONE; } @@ -1141,13 +1147,12 @@ - CPL_ERROR_DIVISION_BY_ZERO a division by 0 occurs */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_divide_scalar(cpl_image * self, - double scalar) +cpl_error_code +cpl_image_divide_scalar(cpl_image *self, double scalar) { + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(scalar != 0.0, CPL_ERROR_DIVISION_BY_ZERO); - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(scalar != 0.0, CPL_ERROR_DIVISION_BY_ZERO); - /* Switch on image type */ switch (cpl_image_get_type(self)) { #define CPL_CLASS CPL_CLASS_DOUBLE @@ -1165,8 +1170,8 @@ #define CPL_CLASS CPL_CLASS_FLOAT_COMPLEX #include "cpl_image_basic_body.h" #undef CPL_CLASS - default: - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + default: + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } return CPL_ERROR_NONE; } @@ -1196,28 +1201,31 @@ - CPL_ERROR_DIVISION_BY_ZERO if the base equals 1 */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_logarithm(cpl_image * self, double base) +cpl_error_code +cpl_image_logarithm(cpl_image *self, double base) { - cpl_error_code error; cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); /* Switch on image type */ switch (cpl_image_get_type(self)) { - case CPL_TYPE_INT: - error = cpl_image_logarithm_int(self, base); - break; - case CPL_TYPE_FLOAT: - error = cpl_image_logarithm_float(self, base); - break; - case CPL_TYPE_DOUBLE: - error = cpl_image_logarithm_double(self, base); - break; - default: - return cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, "type='%s'. " - "base=%g", cpl_type_get_name - (cpl_image_get_type(self)), base); + case CPL_TYPE_INT: + error = cpl_image_logarithm_int(self, base); + break; + case CPL_TYPE_FLOAT: + error = cpl_image_logarithm_float(self, base); + break; + case CPL_TYPE_DOUBLE: + error = cpl_image_logarithm_double(self, base); + break; + default: + return cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, + "type='%s'. " + "base=%g", + cpl_type_get_name( + cpl_image_get_type(self)), + base); } return error ? cpl_error_set_where_() : CPL_ERROR_NONE; @@ -1245,28 +1253,31 @@ */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_exponential(cpl_image * self, double base) +cpl_error_code +cpl_image_exponential(cpl_image *self, double base) { - cpl_error_code error; cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); /* Switch on image type */ switch (cpl_image_get_type(self)) { - case CPL_TYPE_INT: - error = cpl_image_exponential_int(self, base); - break; - case CPL_TYPE_FLOAT: - error = cpl_image_exponential_float(self, base); - break; - case CPL_TYPE_DOUBLE: - error = cpl_image_exponential_double(self, base); - break; - default: - return cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, "type='%s'. " - "base=%g", cpl_type_get_name - (cpl_image_get_type(self)), base); + case CPL_TYPE_INT: + error = cpl_image_exponential_int(self, base); + break; + case CPL_TYPE_FLOAT: + error = cpl_image_exponential_float(self, base); + break; + case CPL_TYPE_DOUBLE: + error = cpl_image_exponential_double(self, base); + break; + default: + return cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, + "type='%s'. " + "base=%g", + cpl_type_get_name( + cpl_image_get_type(self)), + base); } return error ? cpl_error_set_where_() : CPL_ERROR_NONE; @@ -1292,28 +1303,31 @@ - CPL_ERROR_INVALID_TYPE if the passed image type is not supported */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_power(cpl_image * self, double exponent) +cpl_error_code +cpl_image_power(cpl_image *self, double exponent) { - cpl_error_code error; cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); /* Switch on image type */ switch (cpl_image_get_type(self)) { - case CPL_TYPE_INT: - error = cpl_image_power_int(self, exponent); - break; - case CPL_TYPE_FLOAT: - error = cpl_image_power_float(self, exponent); - break; - case CPL_TYPE_DOUBLE: - error = cpl_image_power_double(self, exponent); - break; - default: - return cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, "type='%s'. " - "exponent=%g", cpl_type_get_name - (cpl_image_get_type(self)), exponent); + case CPL_TYPE_INT: + error = cpl_image_power_int(self, exponent); + break; + case CPL_TYPE_FLOAT: + error = cpl_image_power_float(self, exponent); + break; + case CPL_TYPE_DOUBLE: + error = cpl_image_power_double(self, exponent); + break; + default: + return cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, + "type='%s'. " + "exponent=%g", + cpl_type_get_name( + cpl_image_get_type(self)), + exponent); } return error ? cpl_error_set_where_() : CPL_ERROR_NONE; @@ -1336,11 +1350,10 @@ - CPL_ERROR_INVALID_TYPE if the passed image type is as required */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_and(cpl_image * self, - const cpl_image * first, - const cpl_image * second) +cpl_error_code +cpl_image_and(cpl_image *self, const cpl_image *first, const cpl_image *second) { - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(second != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(self->nx == second->nx, CPL_ERROR_INCOMPATIBLE_INPUT); @@ -1349,8 +1362,8 @@ if (cpl_image_get_type(self) != CPL_TYPE_INT) { return cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, "self-type='%s', not int", - cpl_type_get_name - (cpl_image_get_type(self))); + cpl_type_get_name( + cpl_image_get_type(self))); } if (first != NULL) { cpl_ensure_code(self->nx == first->nx, CPL_ERROR_INCOMPATIBLE_INPUT); @@ -1358,15 +1371,15 @@ if (cpl_image_get_type(first) != CPL_TYPE_INT) { return cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, "first-type='%s', not int", - cpl_type_get_name - (cpl_image_get_type(first))); + cpl_type_get_name( + cpl_image_get_type(first))); } } if (cpl_image_get_type(second) != CPL_TYPE_INT) { return cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, "second-type='%s', not int", - cpl_type_get_name - (cpl_image_get_type(second))); + cpl_type_get_name( + cpl_image_get_type(second))); } /* Cannot fail now */ @@ -1374,11 +1387,11 @@ /* Update the output bad pixel map */ cpl_image_or_mask(self, first, second); - cpl_mask_and_((cpl_binary*)self->pixels, - first ? (const cpl_binary*)first->pixels : NULL, - (const cpl_binary*)second->pixels, - cpl_type_get_sizeof(CPL_TYPE_INT) - *(size_t)(self->nx * self->ny)); + cpl_mask_and_((cpl_binary *)self->pixels, + first ? (const cpl_binary *)first->pixels : NULL, + (const cpl_binary *)second->pixels, + cpl_type_get_sizeof(CPL_TYPE_INT) * + (size_t)(self->nx * self->ny)); return CPL_ERROR_NONE; } @@ -1401,11 +1414,10 @@ - CPL_ERROR_INVALID_TYPE if the passed image type is as required */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_or(cpl_image * self, - const cpl_image * first, - const cpl_image * second) +cpl_error_code +cpl_image_or(cpl_image *self, const cpl_image *first, const cpl_image *second) { - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(second != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(self->nx == second->nx, CPL_ERROR_INCOMPATIBLE_INPUT); @@ -1414,8 +1426,8 @@ if (cpl_image_get_type(self) != CPL_TYPE_INT) { return cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, "self-type='%s', not int", - cpl_type_get_name - (cpl_image_get_type(self))); + cpl_type_get_name( + cpl_image_get_type(self))); } if (first != NULL) { cpl_ensure_code(self->nx == first->nx, CPL_ERROR_INCOMPATIBLE_INPUT); @@ -1423,15 +1435,15 @@ if (cpl_image_get_type(first) != CPL_TYPE_INT) { return cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, "first-type='%s', not int", - cpl_type_get_name - (cpl_image_get_type(first))); + cpl_type_get_name( + cpl_image_get_type(first))); } } if (cpl_image_get_type(second) != CPL_TYPE_INT) { return cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, "second-type='%s', not int", - cpl_type_get_name - (cpl_image_get_type(second))); + cpl_type_get_name( + cpl_image_get_type(second))); } /* Cannot fail now */ @@ -1439,11 +1451,11 @@ /* Update the output bad pixel map */ cpl_image_or_mask(self, first, second); - cpl_mask_or_((cpl_binary*)self->pixels, - first ? (const cpl_binary*)first->pixels : NULL, - (const cpl_binary*)second->pixels, - cpl_type_get_sizeof(CPL_TYPE_INT) - *(size_t)(self->nx * self->ny)); + cpl_mask_or_((cpl_binary *)self->pixels, + first ? (const cpl_binary *)first->pixels : NULL, + (const cpl_binary *)second->pixels, + cpl_type_get_sizeof(CPL_TYPE_INT) * + (size_t)(self->nx * self->ny)); return CPL_ERROR_NONE; } @@ -1465,11 +1477,10 @@ - CPL_ERROR_INVALID_TYPE if the passed image type is as required */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_xor(cpl_image * self, - const cpl_image * first, - const cpl_image * second) +cpl_error_code +cpl_image_xor(cpl_image *self, const cpl_image *first, const cpl_image *second) { - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(second != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(self->nx == second->nx, CPL_ERROR_INCOMPATIBLE_INPUT); @@ -1478,8 +1489,8 @@ if (cpl_image_get_type(self) != CPL_TYPE_INT) { return cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, "self-type='%s', not int", - cpl_type_get_name - (cpl_image_get_type(self))); + cpl_type_get_name( + cpl_image_get_type(self))); } if (first != NULL) { cpl_ensure_code(self->nx == first->nx, CPL_ERROR_INCOMPATIBLE_INPUT); @@ -1487,15 +1498,15 @@ if (cpl_image_get_type(first) != CPL_TYPE_INT) { return cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, "first-type='%s', not int", - cpl_type_get_name - (cpl_image_get_type(first))); + cpl_type_get_name( + cpl_image_get_type(first))); } } if (cpl_image_get_type(second) != CPL_TYPE_INT) { return cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, "second-type='%s', not int", - cpl_type_get_name - (cpl_image_get_type(second))); + cpl_type_get_name( + cpl_image_get_type(second))); } @@ -1504,11 +1515,11 @@ /* Update the output bad pixel map */ cpl_image_or_mask(self, first, second); - cpl_mask_xor_((cpl_binary*)self->pixels, - first ? (const cpl_binary*)first->pixels : NULL, - (const cpl_binary*)second->pixels, - cpl_type_get_sizeof(CPL_TYPE_INT) - *(size_t)(self->nx * self->ny)); + cpl_mask_xor_((cpl_binary *)self->pixels, + first ? (const cpl_binary *)first->pixels : NULL, + (const cpl_binary *)second->pixels, + cpl_type_get_sizeof(CPL_TYPE_INT) * + (size_t)(self->nx * self->ny)); return CPL_ERROR_NONE; } @@ -1529,16 +1540,16 @@ - CPL_ERROR_INVALID_TYPE if the passed image type is as required */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_not(cpl_image * self, - const cpl_image * first) +cpl_error_code +cpl_image_not(cpl_image *self, const cpl_image *first) { - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); if (cpl_image_get_type(self) != CPL_TYPE_INT) { return cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, "self-type='%s', not int", - cpl_type_get_name - (cpl_image_get_type(self))); + cpl_type_get_name( + cpl_image_get_type(self))); } if (first != NULL) { cpl_ensure_code(self->nx == first->nx, CPL_ERROR_INCOMPATIBLE_INPUT); @@ -1546,8 +1557,8 @@ if (cpl_image_get_type(first) != CPL_TYPE_INT) { return cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, "first-type='%s', not int", - cpl_type_get_name - (cpl_image_get_type(first))); + cpl_type_get_name( + cpl_image_get_type(first))); } } @@ -1556,11 +1567,11 @@ /* Update the output bad pixel map */ cpl_image_or_mask_unary(self, first); - cpl_mask_xor_scalar((cpl_binary*)self->pixels, - first ? (const cpl_binary*)first->pixels : NULL, + cpl_mask_xor_scalar((cpl_binary *)self->pixels, + first ? (const cpl_binary *)first->pixels : NULL, (cpl_bitmask)-1, - cpl_type_get_sizeof(CPL_TYPE_INT) - *(size_t)(self->nx * self->ny)); + cpl_type_get_sizeof(CPL_TYPE_INT) * + (size_t)(self->nx * self->ny)); return CPL_ERROR_NONE; } @@ -1581,17 +1592,18 @@ - CPL_ERROR_INVALID_TYPE if the passed image type is as required */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_and_scalar(cpl_image * self, - const cpl_image * first, - cpl_bitmask second) +cpl_error_code +cpl_image_and_scalar(cpl_image *self, + const cpl_image *first, + cpl_bitmask second) { cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); if (cpl_image_get_type(self) != CPL_TYPE_INT) { return cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, "self-type='%s', not int", - cpl_type_get_name - (cpl_image_get_type(self))); + cpl_type_get_name( + cpl_image_get_type(self))); } if (first != NULL) { cpl_ensure_code(self->nx == first->nx, CPL_ERROR_INCOMPATIBLE_INPUT); @@ -1599,8 +1611,8 @@ if (cpl_image_get_type(first) != CPL_TYPE_INT) { return cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, "first-type='%s', not int", - cpl_type_get_name - (cpl_image_get_type(first))); + cpl_type_get_name( + cpl_image_get_type(first))); } } @@ -1609,11 +1621,11 @@ /* Update the output bad pixel map */ cpl_image_or_mask_unary(self, first); - cpl_mask_and_scalar((cpl_binary*)self->pixels, - first ? (const cpl_binary*)first->pixels : NULL, + cpl_mask_and_scalar((cpl_binary *)self->pixels, + first ? (const cpl_binary *)first->pixels : NULL, (second & (uint32_t)-1) | (second << 32), - cpl_type_get_sizeof(CPL_TYPE_INT) - *(size_t)(self->nx * self->ny)); + cpl_type_get_sizeof(CPL_TYPE_INT) * + (size_t)(self->nx * self->ny)); return CPL_ERROR_NONE; } @@ -1634,17 +1646,16 @@ - CPL_ERROR_INVALID_TYPE if the passed image type is as required */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_or_scalar(cpl_image * self, - const cpl_image * first, - cpl_bitmask second) +cpl_error_code +cpl_image_or_scalar(cpl_image *self, const cpl_image *first, cpl_bitmask second) { cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); if (cpl_image_get_type(self) != CPL_TYPE_INT) { return cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, "self-type='%s', not int", - cpl_type_get_name - (cpl_image_get_type(self))); + cpl_type_get_name( + cpl_image_get_type(self))); } if (first != NULL) { cpl_ensure_code(self->nx == first->nx, CPL_ERROR_INCOMPATIBLE_INPUT); @@ -1652,8 +1663,8 @@ if (cpl_image_get_type(first) != CPL_TYPE_INT) { return cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, "first-type='%s', not int", - cpl_type_get_name - (cpl_image_get_type(first))); + cpl_type_get_name( + cpl_image_get_type(first))); } } @@ -1662,11 +1673,11 @@ /* Update the output bad pixel map */ cpl_image_or_mask_unary(self, first); - cpl_mask_or_scalar((cpl_binary*)self->pixels, - first ? (const cpl_binary*)first->pixels : NULL, + cpl_mask_or_scalar((cpl_binary *)self->pixels, + first ? (const cpl_binary *)first->pixels : NULL, (second & (uint32_t)-1) | (second << 32), - cpl_type_get_sizeof(CPL_TYPE_INT) - *(size_t)(self->nx * self->ny)); + cpl_type_get_sizeof(CPL_TYPE_INT) * + (size_t)(self->nx * self->ny)); return CPL_ERROR_NONE; } @@ -1688,17 +1699,18 @@ - CPL_ERROR_INVALID_TYPE if the passed image type is as required */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_xor_scalar(cpl_image * self, - const cpl_image * first, - cpl_bitmask second) +cpl_error_code +cpl_image_xor_scalar(cpl_image *self, + const cpl_image *first, + cpl_bitmask second) { cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); if (cpl_image_get_type(self) != CPL_TYPE_INT) { return cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, "self-type='%s', not int", - cpl_type_get_name - (cpl_image_get_type(self))); + cpl_type_get_name( + cpl_image_get_type(self))); } if (first != NULL) { cpl_ensure_code(self->nx == first->nx, CPL_ERROR_INCOMPATIBLE_INPUT); @@ -1706,8 +1718,8 @@ if (cpl_image_get_type(first) != CPL_TYPE_INT) { return cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, "first-type='%s', not int", - cpl_type_get_name - (cpl_image_get_type(first))); + cpl_type_get_name( + cpl_image_get_type(first))); } } @@ -1716,11 +1728,11 @@ /* Update the output bad pixel map */ cpl_image_or_mask_unary(self, first); - cpl_mask_xor_scalar((cpl_binary*)self->pixels, - first ? (const cpl_binary*)first->pixels : NULL, + cpl_mask_xor_scalar((cpl_binary *)self->pixels, + first ? (const cpl_binary *)first->pixels : NULL, (second & (uint32_t)-1) | (second << 32), - cpl_type_get_sizeof(CPL_TYPE_INT) - *(size_t)(self->nx * self->ny)); + cpl_type_get_sizeof(CPL_TYPE_INT) * + (size_t)(self->nx * self->ny)); return CPL_ERROR_NONE; } @@ -1756,35 +1768,36 @@ - CPL_ERROR_INVALID_TYPE if the passed image type is not supported */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_hypot(cpl_image * self, - const cpl_image * first, - const cpl_image * second) +cpl_error_code +cpl_image_hypot(cpl_image *self, + const cpl_image *first, + const cpl_image *second) { - cpl_error_code error; /* Only used to determine the type of the first hypot operand */ - const cpl_image * myfirst = first ? first : second; + const cpl_image *myfirst = first ? first : second; - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(second != NULL, CPL_ERROR_NULL_INPUT); if (cpl_image_get_type(self) != CPL_TYPE_DOUBLE && cpl_image_get_type(self) != CPL_TYPE_FLOAT) { - return cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, - "self-type='%s'", cpl_type_get_name - (cpl_image_get_type(self))); + return cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, "self-type='%s'", + cpl_type_get_name( + cpl_image_get_type(self))); } if (first != NULL && cpl_image_get_type(first) != CPL_TYPE_DOUBLE && cpl_image_get_type(first) != CPL_TYPE_FLOAT) { - return cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, - "first-type='%s'", cpl_type_get_name - (cpl_image_get_type(first))); + return cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, "first-type='%s'", + cpl_type_get_name( + cpl_image_get_type(first))); } if (cpl_image_get_type(second) != CPL_TYPE_DOUBLE && cpl_image_get_type(second) != CPL_TYPE_FLOAT) { return cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, - "second-type='%s'", cpl_type_get_name - (cpl_image_get_type(second))); + "second-type='%s'", + cpl_type_get_name( + cpl_image_get_type(second))); } if (first != NULL) { @@ -1796,34 +1809,33 @@ /* Switch on image type */ - switch ((cpl_image_get_type(self) == CPL_TYPE_FLOAT ? 4 : 0) + + switch ((cpl_image_get_type(self) == CPL_TYPE_FLOAT ? 4 : 0) + (cpl_image_get_type(myfirst) == CPL_TYPE_FLOAT ? 2 : 0) + - (cpl_image_get_type(second) == CPL_TYPE_FLOAT ? 1 : 0)) { - - case 7: /* float, float, float */ - error = cpl_image_hypot_float_float_float(self, first, second); - break; - case 6: /* float, float, double */ - error = cpl_image_hypot_float_float_double(self, first, second); - break; - case 5: /* float, double, float */ - error = cpl_image_hypot_float_double_float(self, first, second); - break; - case 4: /* float, double, double */ - error = cpl_image_hypot_float_double_double(self, first, second); - break; - case 3: /* double, float, float */ - error = cpl_image_hypot_double_float_float(self, first, second); - break; - case 2: /* double, float, double */ - error = cpl_image_hypot_double_float_double(self, first, second); - break; - case 1: /* double, double, float */ - error = cpl_image_hypot_double_double_float(self, first, second); - break; - default: /* double, double, double */ - error = cpl_image_hypot_double_double_double(self, first, second); - break; + (cpl_image_get_type(second) == CPL_TYPE_FLOAT ? 1 : 0)) { + case 7: /* float, float, float */ + error = cpl_image_hypot_float_float_float(self, first, second); + break; + case 6: /* float, float, double */ + error = cpl_image_hypot_float_float_double(self, first, second); + break; + case 5: /* float, double, float */ + error = cpl_image_hypot_float_double_float(self, first, second); + break; + case 4: /* float, double, double */ + error = cpl_image_hypot_float_double_double(self, first, second); + break; + case 3: /* double, float, float */ + error = cpl_image_hypot_double_float_float(self, first, second); + break; + case 2: /* double, float, double */ + error = cpl_image_hypot_double_float_double(self, first, second); + break; + case 1: /* double, double, float */ + error = cpl_image_hypot_double_double_float(self, first, second); + break; + default: /* double, double, double */ + error = cpl_image_hypot_double_double_double(self, first, second); + break; } return error ? cpl_error_set_where_() : CPL_ERROR_NONE; @@ -1849,9 +1861,8 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_normalise( - cpl_image * image, - cpl_norm mode) +cpl_error_code +cpl_image_normalise(cpl_image *image, cpl_norm mode) { double scale; @@ -1862,8 +1873,8 @@ case CPL_NORM_SCALE: { cpl_stats stats; - if (cpl_stats_fill_from_image(&stats, image, CPL_STATS_MIN - | CPL_STATS_MAX)) { + if (cpl_stats_fill_from_image(&stats, image, + CPL_STATS_MIN | CPL_STATS_MAX)) { return cpl_error_set_where_(); } scale = cpl_stats_get_max(&stats) - cpl_stats_get_min(&stats); @@ -1876,22 +1887,22 @@ case CPL_NORM_MEAN: { scale = cpl_image_get_mean(image); break; - } + } case CPL_NORM_FLUX: { scale = cpl_image_get_flux(image); break; - } + } case CPL_NORM_ABSFLUX: { scale = cpl_image_get_absflux(image); break; - } + } default: /* This case can only be reached if cpl_norm is extended in error */ return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } - cpl_ensure_code( !cpl_image_divide_scalar(image, scale), - cpl_error_get_code()); + cpl_ensure_code(!cpl_image_divide_scalar(image, scale), + cpl_error_get_code()); return CPL_ERROR_NONE; } @@ -1912,11 +1923,10 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_normalise_create( - const cpl_image * image_in, - cpl_norm mode) +cpl_image * +cpl_image_normalise_create(const cpl_image *image_in, cpl_norm mode) { - cpl_image * image_out; + cpl_image *image_out; cpl_ensure(image_in, CPL_ERROR_NULL_INPUT, NULL); @@ -1949,11 +1959,10 @@ the passed image. */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_add_scalar_create( - const cpl_image * image, - double addend) +cpl_image * +cpl_image_add_scalar_create(const cpl_image *image, double addend) { - cpl_image * result = cpl_image_duplicate(image); + cpl_image *result = cpl_image_duplicate(image); cpl_ensure(result, cpl_error_get_code(), NULL); @@ -1976,11 +1985,10 @@ @see cpl_image_add_scalar_create */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_subtract_scalar_create( - const cpl_image * image, - double subtrahend) +cpl_image * +cpl_image_subtract_scalar_create(const cpl_image *image, double subtrahend) { - cpl_image * result = cpl_image_duplicate(image); + cpl_image *result = cpl_image_duplicate(image); cpl_ensure(result, cpl_error_get_code(), NULL); @@ -2005,11 +2013,10 @@ @see cpl_image_add_scalar_create */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_multiply_scalar_create( - const cpl_image * image, - double factor) +cpl_image * +cpl_image_multiply_scalar_create(const cpl_image *image, double factor) { - cpl_image * result = cpl_image_duplicate(image); + cpl_image *result = cpl_image_duplicate(image); cpl_ensure(result, cpl_error_get_code(), NULL); @@ -2034,11 +2041,10 @@ @see cpl_image_add_scalar_create */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_divide_scalar_create( - const cpl_image * image, - double divisor) +cpl_image * +cpl_image_divide_scalar_create(const cpl_image *image, double divisor) { - cpl_image * result = cpl_image_duplicate(image); + cpl_image *result = cpl_image_duplicate(image); cpl_ensure(result, cpl_error_get_code(), NULL); @@ -2063,11 +2069,10 @@ @see cpl_image_add_scalar_create */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_logarithm_create( - const cpl_image * image, - double base) +cpl_image * +cpl_image_logarithm_create(const cpl_image *image, double base) { - cpl_image * result = cpl_image_duplicate(image); + cpl_image *result = cpl_image_duplicate(image); cpl_ensure(result, cpl_error_get_code(), NULL); @@ -2079,7 +2084,7 @@ return result; } - + /*----------------------------------------------------------------------------*/ /** @ingroup cpl_image @@ -2091,11 +2096,10 @@ @see cpl_image_add_scalar_create */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_exponential_create( - const cpl_image * image, - double base) +cpl_image * +cpl_image_exponential_create(const cpl_image *image, double base) { - cpl_image * result = cpl_image_duplicate(image); + cpl_image *result = cpl_image_duplicate(image); cpl_ensure(result, cpl_error_get_code(), NULL); @@ -2107,7 +2111,7 @@ return result; } - + /*----------------------------------------------------------------------------*/ /** @ingroup cpl_image @@ -2119,11 +2123,10 @@ @see cpl_image_add_scalar_create */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_power_create( - const cpl_image * image, - double exponent) +cpl_image * +cpl_image_power_create(const cpl_image *image, double exponent) { - cpl_image * result = cpl_image_duplicate(image); + cpl_image *result = cpl_image_duplicate(image); cpl_ensure(result, cpl_error_get_code(), NULL); @@ -2135,7 +2138,7 @@ return result; } - + #define CPL_OPERATION CPL_IMAGE_BASIC_THRESHOLD /*----------------------------------------------------------------------------*/ /** @@ -2163,14 +2166,13 @@ - CPL_ERROR_ILLEGAL_INPUT if lo_cut is greater than hi_cut */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_threshold( - cpl_image * image_in, - double lo_cut, - double hi_cut, - double assign_lo_cut, - double assign_hi_cut) +cpl_error_code +cpl_image_threshold(cpl_image *image_in, + double lo_cut, + double hi_cut, + double assign_lo_cut, + double assign_hi_cut) { - cpl_ensure_code(image_in != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(lo_cut <= hi_cut, CPL_ERROR_ILLEGAL_INPUT); @@ -2186,7 +2188,7 @@ #include "cpl_image_basic_body.h" #undef CPL_CLASS default: - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } return CPL_ERROR_NONE; } @@ -2206,7 +2208,8 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_abs(cpl_image * image) +cpl_error_code +cpl_image_abs(cpl_image *image) { /* Check entries */ cpl_ensure_code(image, CPL_ERROR_NULL_INPUT); @@ -2243,10 +2246,10 @@ cpl_image_delete(). */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_abs_create(const cpl_image * image_in) +cpl_image * +cpl_image_abs_create(const cpl_image *image_in) { - - cpl_image * result = cpl_image_duplicate(image_in); + cpl_image *result = cpl_image_duplicate(image_in); cpl_ensure(result, cpl_error_get_code(), NULL); @@ -2278,18 +2281,17 @@ - CPL_ERROR_INVALID_TYPE if the passed image type is not supported */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_average_create( - const cpl_image * image_1, - const cpl_image * image_2) -{ - cpl_image * image_out; - int * pii2; - float * pfi2; - double * pdi2; +cpl_image * +cpl_image_average_create(const cpl_image *image_1, const cpl_image *image_2) +{ + cpl_image *image_out; + int *pii2; + float *pfi2; + double *pdi2; /* Check entries */ cpl_ensure(image_1 && image_2, CPL_ERROR_NULL_INPUT, NULL); - + /* Input data images shall have the same sizes */ cpl_ensure(image_1->nx == image_2->nx && image_1->ny == image_2->ny, CPL_ERROR_ILLEGAL_INPUT, NULL); @@ -2309,15 +2311,18 @@ (void)cpl_error_set_(CPL_ERROR_INVALID_TYPE); return NULL; } - + /* Handle bad pixels map */ if (image_1->bpm == NULL && image_2->bpm == NULL) { image_out->bpm = NULL; - } else if (image_1->bpm == NULL) { + } + else if (image_1->bpm == NULL) { image_out->bpm = cpl_mask_duplicate(image_2->bpm); - } else if (image_2->bpm == NULL) { + } + else if (image_2->bpm == NULL) { image_out->bpm = cpl_mask_duplicate(image_1->bpm); - } else { + } + else { image_out->bpm = cpl_mask_duplicate(image_1->bpm); cpl_mask_or(image_out->bpm, image_2->bpm); } @@ -2348,38 +2353,40 @@ - CPL_ERROR_ILLEGAL_INPUT if the specified window is not valid */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_collapse_window_create(const cpl_image * self, - cpl_size llx, - cpl_size lly, - cpl_size urx, - cpl_size ury, - int direction) +cpl_image * +cpl_image_collapse_window_create(const cpl_image *self, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury, + int direction) { - cpl_image * other; + cpl_image *other; /* Switch on image type */ switch (cpl_image_get_type(self)) { - case CPL_TYPE_DOUBLE: - other = cpl_image_collapse_window_create_double(self, llx, lly, urx, - ury, direction); - break; - case CPL_TYPE_FLOAT: - other = cpl_image_collapse_window_create_float(self, llx, lly, urx, - ury, direction); - break; - case CPL_TYPE_INT: - other = cpl_image_collapse_window_create_int(self, llx, lly, urx, - ury, direction); - break; - default: - /* NULL input will be go here, after having set a CPL error */ - other = NULL; + case CPL_TYPE_DOUBLE: + other = cpl_image_collapse_window_create_double(self, llx, lly, urx, + ury, direction); + break; + case CPL_TYPE_FLOAT: + other = cpl_image_collapse_window_create_float(self, llx, lly, urx, + ury, direction); + break; + case CPL_TYPE_INT: + other = cpl_image_collapse_window_create_int(self, llx, lly, urx, + ury, direction); + break; + default: + /* NULL input will be go here, after having set a CPL error */ + other = NULL; } /* Propagate error, if any */ - if (other == NULL) (void)cpl_error_set_where_(); - + if (other == NULL) + (void)cpl_error_set_where_(); + return other; } /*----------------------------------------------------------------------------*/ @@ -2422,18 +2429,16 @@ - CPL_ERROR_INVALID_TYPE if the passed image type is not supported */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_collapse_create(const cpl_image * self, - int direction) +cpl_image * +cpl_image_collapse_create(const cpl_image *self, int direction) { - cpl_image * other - = cpl_image_collapse_window_create(self, 1, 1, - cpl_image_get_size_x(self), - cpl_image_get_size_y(self), - direction); + cpl_image *other = + cpl_image_collapse_window_create(self, 1, 1, cpl_image_get_size_x(self), + cpl_image_get_size_y(self), direction); /* Propagate error, if any */ cpl_ensure(other != NULL, cpl_error_get_code(), NULL); - + return other; } @@ -2469,27 +2474,30 @@ - CPL_ERROR_DATA_NOT_FOUND if the output image would have only bad pixels */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_collapse_median_create(const cpl_image * self, - int direction, - cpl_size drop_ll, - cpl_size drop_ur) +cpl_image * +cpl_image_collapse_median_create(const cpl_image *self, + int direction, + cpl_size drop_ll, + cpl_size drop_ur) { - cpl_image * other = NULL; + cpl_image *other = NULL; const cpl_size ndrop = drop_ll + drop_ur; - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); cpl_ensure(drop_ll >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL); cpl_ensure(drop_ur >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL); if (direction == 0) { cpl_ensure(ndrop < self->ny, CPL_ERROR_ILLEGAL_INPUT, NULL); - } else if (direction == 1) { + } + else if (direction == 1) { cpl_ensure(ndrop < self->nx, CPL_ERROR_ILLEGAL_INPUT, NULL); - } else { + } + else { (void)cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); return NULL; } - + /* Switch on image type */ switch (self->type) { #define CPL_CLASS CPL_CLASS_DOUBLE @@ -2504,8 +2512,8 @@ default: (void)cpl_error_set_(CPL_ERROR_INVALID_TYPE); - } - + } + return other; } #undef CPL_OPERATION @@ -2541,22 +2549,23 @@ - CPL_ERROR_INVALID_TYPE if the passed image type is not supported */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_extract(const cpl_image * in, - cpl_size llx, - cpl_size lly, - cpl_size urx, - cpl_size ury) +cpl_image * +cpl_image_extract(const cpl_image *in, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury) { - cpl_image * self = NULL; + cpl_image *self = NULL; - cpl_ensure(in != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(in != NULL, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(llx >= 1, CPL_ERROR_ILLEGAL_INPUT, NULL); - cpl_ensure(llx <= urx, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(llx >= 1, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(llx <= urx, CPL_ERROR_ILLEGAL_INPUT, NULL); cpl_ensure(urx <= in->nx, CPL_ERROR_ILLEGAL_INPUT, NULL); - cpl_ensure(lly >= 1, CPL_ERROR_ILLEGAL_INPUT, NULL); - cpl_ensure(lly <= ury, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(lly >= 1, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(lly <= ury, CPL_ERROR_ILLEGAL_INPUT, NULL); cpl_ensure(ury <= in->ny, CPL_ERROR_ILLEGAL_INPUT, NULL); /* Switch on image type */ @@ -2610,20 +2619,20 @@ - CPL_ERROR_INVALID_TYPE if the passed image type is not supported */ /*----------------------------------------------------------------------------*/ -cpl_vector * cpl_vector_new_from_image_row(const cpl_image * image_in, - cpl_size pos) +cpl_vector * +cpl_vector_new_from_image_row(const cpl_image *image_in, cpl_size pos) { - cpl_vector * out; - double * out_data; + cpl_vector *out; + double *out_data; /* Test entries */ cpl_ensure(image_in, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(pos>=1 && pos<=image_in->ny, CPL_ERROR_ILLEGAL_INPUT,NULL); - + cpl_ensure(pos >= 1 && pos <= image_in->ny, CPL_ERROR_ILLEGAL_INPUT, NULL); + /* Allocate output vector */ out = cpl_vector_new(image_in->nx); out_data = cpl_vector_get_data(out); - + /* Switch on image type */ switch (image_in->type) { #define CPL_CLASS CPL_CLASS_DOUBLE @@ -2640,7 +2649,7 @@ out = NULL; (void)cpl_error_set_(CPL_ERROR_INVALID_TYPE); } - + return out; } #undef CPL_OPERATION @@ -2665,21 +2674,21 @@ - CPL_ERROR_INVALID_TYPE if the passed image type is not supported */ /*----------------------------------------------------------------------------*/ -cpl_vector * cpl_vector_new_from_image_column(const cpl_image * image_in, - cpl_size pos) +cpl_vector * +cpl_vector_new_from_image_column(const cpl_image *image_in, cpl_size pos) { - cpl_vector * out; - double * out_data; + cpl_vector *out; + double *out_data; /* Check entries */ - cpl_ensure(image_in != NULL, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(pos >= 1, CPL_ERROR_ILLEGAL_INPUT, NULL); - cpl_ensure(pos <= image_in->nx, CPL_ERROR_ILLEGAL_INPUT, NULL); - + cpl_ensure(image_in != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(pos >= 1, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(pos <= image_in->nx, CPL_ERROR_ILLEGAL_INPUT, NULL); + /* Allocate output vector */ out = cpl_vector_new(image_in->ny); out_data = cpl_vector_get_data(out); - + /* Switch on image type */ switch (image_in->type) { #define CPL_CLASS CPL_CLASS_DOUBLE @@ -2696,7 +2705,7 @@ out = NULL; (void)cpl_error_set_(CPL_ERROR_INVALID_TYPE); } - + return out; } #undef CPL_OPERATION @@ -2734,18 +2743,20 @@ - CPL_ERROR_INVALID_TYPE if the passed image type is not supported */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_turn(cpl_image * self, int rot) +cpl_error_code +cpl_image_turn(cpl_image *self, int rot) { - cpl_ensure_code(self, CPL_ERROR_NULL_INPUT); rot %= 4; - if (rot < 0) rot += 4; + if (rot < 0) + rot += 4; /* rot is 0, 1, 2 or 3. */ /* Rotate the bad pixel map */ - if (rot != 0 && self->bpm != NULL) cpl_mask_turn(self->bpm, rot); + if (rot != 0 && self->bpm != NULL) + cpl_mask_turn(self->bpm, rot); /* Switch on the image type */ switch (self->type) { @@ -2787,23 +2798,22 @@ image size */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_shift(cpl_image * self, - cpl_size dx, - cpl_size dy) +cpl_error_code +cpl_image_shift(cpl_image *self, cpl_size dx, cpl_size dy) { - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); if (dx != 0 || dy != 0) { /* Rejected pixels are set to a zero-bit-pattern */ if (cpl_tools_shift_window(self->pixels, - cpl_type_get_sizeof(self->type), - self->nx, self->ny, 0, dx, dy)) { + cpl_type_get_sizeof(self->type), self->nx, + self->ny, 0, dx, dy)) { return cpl_error_set_where_(); } /* Shift the bad pixel map */ - if (self->bpm == NULL) self->bpm = cpl_mask_new(self->nx, self->ny); + if (self->bpm == NULL) + self->bpm = cpl_mask_new(self->nx, self->ny); /* Cannot fail now */ (void)cpl_mask_shift(self->bpm, dx, dy); } @@ -2839,32 +2849,32 @@ specified range */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_copy(cpl_image * im1, - const cpl_image * im2, - cpl_size xpos, - cpl_size ypos) +cpl_error_code +cpl_image_copy(cpl_image *im1, + const cpl_image *im2, + cpl_size xpos, + cpl_size ypos) { - /* FIXME: Support overlapping pixel buffers ? */ /* FIXME: Need to do pointer arithmetic */ - char * pim1 = (char*)cpl_image_get_data(im1); - const cpl_size nx1 = cpl_image_get_size_x(im1); - const cpl_size ny1 = cpl_image_get_size_y(im1); - const cpl_size nx2 = cpl_image_get_size_x(im2); - const cpl_size ny2 = cpl_image_get_size_y(im2); + char *pim1 = (char *)cpl_image_get_data(im1); + const cpl_size nx1 = cpl_image_get_size_x(im1); + const cpl_size ny1 = cpl_image_get_size_y(im1); + const cpl_size nx2 = cpl_image_get_size_x(im2); + const cpl_size ny2 = cpl_image_get_size_y(im2); /* Define the zone to modify in im1: xpos, ypos, urx, ury */ - const cpl_size urx = CX_MIN(nx1, nx2 + xpos - 1); - const cpl_size ury = CX_MIN(ny1, ny2 + ypos - 1); - const size_t pixsz = cpl_type_get_sizeof(cpl_image_get_type(im1)); - const size_t linesz = (size_t)(urx - (xpos-1)) * pixsz; - + const cpl_size urx = CX_MIN(nx1, nx2 + xpos - 1); + const cpl_size ury = CX_MIN(ny1, ny2 + ypos - 1); + const size_t pixsz = cpl_type_get_sizeof(cpl_image_get_type(im1)); + const size_t linesz = (size_t)(urx - (xpos - 1)) * pixsz; + /* Check entries */ - cpl_ensure_code(im1 != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(im2 != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(xpos >= 1, CPL_ERROR_ACCESS_OUT_OF_RANGE); - cpl_ensure_code(xpos <= nx1, CPL_ERROR_ACCESS_OUT_OF_RANGE); - cpl_ensure_code(ypos >= 1, CPL_ERROR_ACCESS_OUT_OF_RANGE); - cpl_ensure_code(ypos <= ny1, CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_ensure_code(im1 != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(im2 != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(xpos >= 1, CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_ensure_code(xpos <= nx1, CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_ensure_code(ypos >= 1, CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_ensure_code(ypos <= ny1, CPL_ERROR_ACCESS_OUT_OF_RANGE); cpl_ensure_code(im1->type == im2->type, CPL_ERROR_TYPE_MISMATCH); pim1 += (ypos - 1) * nx1 * pixsz; @@ -2872,12 +2882,13 @@ if (xpos == 1 && urx == nx1 && nx1 == nx2) { /* The zone consists of whole lines in both in1 and in2 */ memcpy(pim1, im2->pixels, (ury - (ypos - 1)) * linesz); - } else { + } + else { /* FIXME: Need to do pointer arithmetic */ - const char * pim2 = (const char*)im2->pixels; - const size_t sz1 = (size_t)nx1 * pixsz; - const size_t sz2 = (size_t)nx2 * pixsz; - cpl_size j; + const char *pim2 = (const char *)im2->pixels; + const size_t sz1 = (size_t)nx1 * pixsz; + const size_t sz2 = (size_t)nx2 * pixsz; + cpl_size j; pim1 += (size_t)(xpos - 1) * pixsz; @@ -2889,13 +2900,15 @@ /* Handle the bad pixels */ if (im1->bpm != NULL || im2->bpm != NULL) { - cpl_mask * bpm2; - if (im1->bpm == NULL) im1->bpm = cpl_mask_new(im1->nx, im1->ny); + cpl_mask *bpm2; + if (im1->bpm == NULL) + im1->bpm = cpl_mask_new(im1->nx, im1->ny); bpm2 = im2->bpm ? im2->bpm : cpl_mask_new(im2->nx, im2->ny); cpl_mask_copy(im1->bpm, bpm2, xpos, ypos); - if (bpm2 != im2->bpm) cpl_mask_delete(bpm2); + if (bpm2 != im2->bpm) + cpl_mask_delete(bpm2); /* FIXME: im1->bpm may be empty... */ } @@ -2927,13 +2940,12 @@ - CPL_ERROR_INVALID_TYPE if the passed image type is not supported */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_flip( - cpl_image * im, - int angle) +cpl_error_code +cpl_image_flip(cpl_image *im, int angle) { /* Check entries */ cpl_ensure_code(im != NULL, CPL_ERROR_NULL_INPUT); - + /* Switch on the image type */ switch (im->type) { #define CPL_CLASS CPL_CLASS_DOUBLE @@ -2950,7 +2962,8 @@ } /* Flip the bad pixel map */ - if (im->bpm != NULL) cpl_mask_flip(im->bpm, angle); + if (im->bpm != NULL) + cpl_mask_flip(im->bpm, angle); return CPL_ERROR_NONE; } @@ -2961,19 +2974,23 @@ /*----------------------------------------------------------------------------*/ /** @ingroup cpl_image - @brief Reorganize the pixels in an image - @param im the image to reorganize - @param nb_cut the number of cut in x and y - @param new_pos array with the nb_cut^2 new positions + @brief Permute tiles in an image + @param im The image to modify + @param nb_cut The number of cuts in x and y + @param new_pos Array with the nb_cut^2 permuted positions @return the #_cpl_error_code_ or CPL_ERROR_NONE + @note The permutation array _must_ contain nb_cut-squared elements - nb_cut^2 defines in how many tiles the images will be moved. Each tile will - then be moved to an other place defined in new_pos. 1 will leave the image - unchanged, 2 is used to move the quadrants, etc.. - new_pos contains nb_cut^2 values between 1 and nb_cut^2. - The zones positions are counted from the lower left part of the image. + nb_cut^2 defines in how many tiles the images will be permuted. Each tile will + then be moved to another place defined in new_pos. nb_cut equal 1 will leave + the image unchanged, 2 is used to permute the four image quadrants, etc.. + new_pos contains nb_cut^2 values between 1 and nb_cut^2, i.e. a permutation + of the values from 1 to nb_cut^2. + The zone positions are counted from the lower left part of the image. It is not allowed to move two tiles to the same position (the relation between th new tiles positions and the initial position is bijective !). + The array with the permuted positions must contain nb_cut^2 values, the + function is unable to verify this. The image x and y sizes have to be multiples of nb_cut. @@ -2993,30 +3010,29 @@ with new_pos = {9,8,7,6,5,4,3,2,1}; @endverbatim - The bad pixels are moved accordingly. + The bad pixels are moved in the same way. Possible #_cpl_error_code_ set in this function: - CPL_ERROR_NULL_INPUT if an input pointer is NULL - CPL_ERROR_ILLEGAL_INPUT if nb_cut is not strictly positive or cannot - divide one of the image sizes or if the new_pos array specifies to - move two tiles to the same position. + divide one of the image sizes or if the new_pos array does not contain a + permutation of the values from 1 through nb_cut squared. - CPL_ERROR_INVALID_TYPE if the passed image type is not supported */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_move(cpl_image * im, - cpl_size nb_cut, - const cpl_size * new_pos) -{ - cpl_size test_sum; - cpl_size tile_sz_x, tile_sz_y; - cpl_size tile_x, tile_y; - cpl_size npos, opos; - cpl_size i, j, k, l; +cpl_error_code +cpl_image_move(cpl_image *im, cpl_size nb_cut, const cpl_size *new_pos) +{ + cpl_size *sort_pos; + cpl_size tile_sz_x, tile_sz_y; + cpl_size tile_x, tile_y; + cpl_size npos, opos; + cpl_size i, j, k, l; /* Check entries */ - cpl_ensure_code(im, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(new_pos, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(nb_cut > 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(im, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(new_pos, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(nb_cut > 0, CPL_ERROR_ILLEGAL_INPUT); tile_sz_x = im->nx / nb_cut; tile_sz_y = im->ny / nb_cut; @@ -3025,11 +3041,15 @@ cpl_ensure_code(tile_sz_y * nb_cut == im->ny, CPL_ERROR_ILLEGAL_INPUT); /* Test that new_pos takes all values between 1 and nb_cut*nb_cut */ - /* The test here is not strict, but should be sufficient */ - test_sum = 0; - for (i=0; itype) { @@ -3048,15 +3068,15 @@ #define CPL_CLASS CPL_CLASS_FLOAT_COMPLEX #include "cpl_image_basic_body.h" #undef CPL_CLASS - default: - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + default: + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } /* Handle the bad pixels */ - if (im->bpm != NULL) cpl_mask_move(im->bpm, nb_cut, new_pos); - - return CPL_ERROR_NONE; + if (im->bpm != NULL) + cpl_mask_move(im->bpm, nb_cut, new_pos); + return CPL_ERROR_NONE; } #undef CPL_OPERATION @@ -3099,65 +3119,78 @@ This function is only acceptable for determining the position of a peak. */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_fit_gaussian( - const cpl_image * im, - cpl_size xpos, - cpl_size ypos, - cpl_size size, - double * norm, - double * xcen, - double * ycen, - double * sig_x, - double * sig_y, - double * fwhm_x, - double * fwhm_y) -{ - const cpl_image * im_use; - cpl_image * im_cast = NULL; - cpl_size llx, lly, urx, ury; - cpl_bivector * stats; - double * pstats; +cpl_error_code +cpl_image_fit_gaussian(const cpl_image *im, + cpl_size xpos, + cpl_size ypos, + cpl_size size, + double *norm, + double *xcen, + double *ycen, + double *sig_x, + double *sig_y, + double *fwhm_x, + double *fwhm_y) +{ + const cpl_image *im_use; + cpl_image *im_cast = NULL; + cpl_size llx, lly, urx, ury; + cpl_bivector *stats; + double *pstats; /* Check entries */ - cpl_ensure_code(im != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(xpos >= 1, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(ypos >= 1, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(im != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(xpos >= 1, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(ypos >= 1, CPL_ERROR_ILLEGAL_INPUT); cpl_ensure_code(xpos <= im->nx, CPL_ERROR_ILLEGAL_INPUT); cpl_ensure_code(ypos <= im->ny, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(size >= 1, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(size < im->nx, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(size < im->ny, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(size >= 1, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(size < im->nx, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(size < im->ny, CPL_ERROR_ILLEGAL_INPUT); /* Extraction zone */ llx = xpos - size / 2; lly = ypos - size / 2; urx = xpos + size / 2; ury = ypos + size / 2; - if (llx < 1) llx = 1; - if (lly < 1) lly = 1; - if (urx > im->nx) urx = im->nx; - if (ury > im->ny) ury = im->ny; - + if (llx < 1) + llx = 1; + if (lly < 1) + lly = 1; + if (urx > im->nx) + urx = im->nx; + if (ury > im->ny) + ury = im->ny; + /* Convert the image to FLOAT, if needed */ - im_use = cpl_image_get_type(im) == CPL_TYPE_FLOAT ? im : - (im_cast = cpl_image_cast(im, CPL_TYPE_FLOAT)); + im_use = cpl_image_get_type(im) == CPL_TYPE_FLOAT + ? im + : (im_cast = cpl_image_cast(im, CPL_TYPE_FLOAT)); /* Call cpl_image_iqe */ stats = cpl_image_iqe(im_use, llx, lly, urx, ury); cpl_image_delete(im_cast); - if (stats == NULL) return cpl_error_set_where_(); - + if (stats == NULL) + return cpl_error_set_where_(); + /* Write the results */ pstats = cpl_bivector_get_x_data(stats); - if (xcen) *xcen = pstats[0]; - if (ycen) *ycen = pstats[1]; - if (fwhm_x) *fwhm_x = pstats[2]; - if (fwhm_y) *fwhm_y = pstats[3]; - if (sig_x) *sig_x = pstats[2] / CPL_MATH_FWHM_SIG; - if (sig_y) *sig_y = pstats[3] / CPL_MATH_FWHM_SIG; - if (norm) *norm = pstats[5] * CPL_MATH_2PI * - (pstats[2]*pstats[3]) / (CPL_MATH_FWHM_SIG*CPL_MATH_FWHM_SIG); + if (xcen) + *xcen = pstats[0]; + if (ycen) + *ycen = pstats[1]; + if (fwhm_x) + *fwhm_x = pstats[2]; + if (fwhm_y) + *fwhm_y = pstats[3]; + if (sig_x) + *sig_x = pstats[2] / CPL_MATH_FWHM_SIG; + if (sig_y) + *sig_y = pstats[3] / CPL_MATH_FWHM_SIG; + if (norm) + *norm = pstats[5] * CPL_MATH_2PI * (pstats[2] * pstats[3]) / + (CPL_MATH_FWHM_SIG * CPL_MATH_FWHM_SIG); cpl_bivector_delete(stats); return CPL_ERROR_NONE; @@ -3193,24 +3226,25 @@ size range */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_get_fwhm( - const cpl_image * in, - cpl_size xpos, - cpl_size ypos, - double * fwhm_x, - double * fwhm_y) -{ - double half_max; - double thres; - const cpl_size minimum_size = 5; - int is_rejected; +cpl_error_code +cpl_image_get_fwhm(const cpl_image *in, + cpl_size xpos, + cpl_size ypos, + double *fwhm_x, + double *fwhm_y) +{ + double half_max; + double thres; + const cpl_size minimum_size = 5; + int is_rejected; /* Check entries - and initialize *fwhm_{x,y} */ - if (fwhm_y != NULL) *fwhm_y = -1; - cpl_ensure_code(fwhm_x, CPL_ERROR_NULL_INPUT); + if (fwhm_y != NULL) + *fwhm_y = -1; + cpl_ensure_code(fwhm_x, CPL_ERROR_NULL_INPUT); *fwhm_x = -1; - cpl_ensure_code(fwhm_y, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(fwhm_y, CPL_ERROR_NULL_INPUT); /* This call will check the validity of image, xpos and ypos */ half_max = 0.5 * cpl_image_get(in, xpos, ypos, &is_rejected); @@ -3219,13 +3253,13 @@ cpl_ensure_code(!is_rejected, CPL_ERROR_DATA_NOT_FOUND); cpl_ensure_code(half_max > 0, CPL_ERROR_DATA_NOT_FOUND); - + /* FWHM in x */ if (in->nx >= minimum_size) { cpl_errorstate pstate; /* Extract the vector centered on the maximum */ - cpl_vector * row = cpl_vector_new_from_image_row(in, ypos); + cpl_vector *row = cpl_vector_new_from_image_row(in, ypos); /* If an error happened, update its location */ cpl_ensure_code(row, cpl_error_get_code()); @@ -3234,7 +3268,7 @@ /* Find out threshold */ thres = cpl_vector_get_noise(row, xpos); - + /* Compute the FWHM */ if (cpl_errorstate_is_equal(pstate)) *fwhm_x = cpl_vector_get_fwhm(row, xpos, half_max + thres * 0.5); @@ -3243,15 +3277,14 @@ /* Propagate the error, if any */ cpl_ensure_code(cpl_errorstate_is_equal(pstate), cpl_error_get_code()); - } - + /* FWHM in y */ if (in->ny >= minimum_size) { cpl_errorstate pstate; /* Extract the vector centered on the maximum */ - cpl_vector * col = cpl_vector_new_from_image_column(in, xpos); + cpl_vector *col = cpl_vector_new_from_image_column(in, xpos); /* If an error happened, update its location */ cpl_ensure_code(col, cpl_error_get_code()); @@ -3260,7 +3293,7 @@ /* Find out threshold */ thres = cpl_vector_get_noise(col, ypos); - + /* Compute the FWHM */ if (cpl_errorstate_is_equal(pstate)) *fwhm_y = cpl_vector_get_fwhm(col, ypos, half_max + thres * 0.5); @@ -3270,7 +3303,7 @@ /* Propagate the error, if any */ cpl_ensure_code(cpl_errorstate_is_equal(pstate), cpl_error_get_code()); } - + return CPL_ERROR_NONE; } @@ -3313,29 +3346,27 @@ - CPL_ERROR_INVALID_TYPE if the passed image type is not supported */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_fft( - cpl_image * img_real, - cpl_image * img_imag, - unsigned mode) +cpl_error_code +cpl_image_fft(cpl_image *img_real, cpl_image *img_imag, unsigned mode) { - unsigned dim[2]; - double * imag_part; + unsigned dim[2]; + double *imag_part; /* Check entries */ cpl_ensure_code(img_real, CPL_ERROR_NULL_INPUT); cpl_ensure_code(mode != 1, CPL_ERROR_INVALID_TYPE); - cpl_ensure_code( - mode <= (CPL_FFT_INVERSE|CPL_FFT_UNNORMALIZED|CPL_FFT_SWAP_HALVES), - CPL_ERROR_UNSUPPORTED_MODE); - cpl_ensure_code(img_real->nx==img_real->ny, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(img_real->type==CPL_TYPE_DOUBLE,CPL_ERROR_INVALID_TYPE); - cpl_ensure_code(cpl_tools_is_power_of_2(img_real->nx)>=0, + cpl_ensure_code(mode <= (CPL_FFT_INVERSE | CPL_FFT_UNNORMALIZED | + CPL_FFT_SWAP_HALVES), + CPL_ERROR_UNSUPPORTED_MODE); + cpl_ensure_code(img_real->nx == img_real->ny, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(img_real->type == CPL_TYPE_DOUBLE, CPL_ERROR_INVALID_TYPE); + cpl_ensure_code(cpl_tools_is_power_of_2(img_real->nx) >= 0, CPL_ERROR_ILLEGAL_INPUT); if (img_imag != NULL) { - cpl_ensure_code(img_real->nx==img_imag->nx,CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(img_real->ny==img_imag->ny,CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(img_imag->type==CPL_TYPE_DOUBLE, - CPL_ERROR_INVALID_TYPE); + cpl_ensure_code(img_real->nx == img_imag->nx, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(img_real->ny == img_imag->ny, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(img_imag->type == CPL_TYPE_DOUBLE, + CPL_ERROR_INVALID_TYPE); } /* Initialize */ @@ -3345,15 +3376,17 @@ if (img_imag == NULL) { /* Create the imaginary part and set it to 0 */ - imag_part = cpl_calloc(dim[0]*dim[1], sizeof(double)); - } else { + imag_part = cpl_calloc(dim[0] * dim[1], sizeof(double)); + } + else { /* Put the input imaginary part in a local object */ imag_part = img_imag->pixels; } /* APPLY THE FFT HERE */ cpl_ensure_code(!cpl_fft(img_real->pixels, imag_part, dim, 2, - (mode & CPL_FFT_INVERSE) ? -1 : 1),cpl_error_get_code()); + (mode & CPL_FFT_INVERSE) ? -1 : 1), + cpl_error_get_code()); /* Free the imaginary part result in the input image */ if (img_imag == NULL) { @@ -3362,17 +3395,17 @@ /* Normalize on the inverse transform */ if (!(mode & CPL_FFT_UNNORMALIZED) && (mode & CPL_FFT_INVERSE)) { - cpl_ensure_code(!cpl_image_divide_scalar(img_real, dim[0]*dim[1]), + cpl_ensure_code(!cpl_image_divide_scalar(img_real, dim[0] * dim[1]), cpl_error_get_code()); if (img_imag != NULL) { - cpl_ensure_code(!cpl_image_divide_scalar(img_imag, dim[0]*dim[1]), + cpl_ensure_code(!cpl_image_divide_scalar(img_imag, dim[0] * dim[1]), cpl_error_get_code()); } } /* Swap halves in both dimensions */ if (mode & CPL_FFT_SWAP_HALVES) { - const cpl_size new_pos[] = {4, 3, 2, 1}; + const cpl_size new_pos[] = { 4, 3, 2, 1 }; cpl_ensure_code(!cpl_image_move(img_real, 2, new_pos), cpl_error_get_code()); if (img_imag != NULL) { @@ -3396,11 +3429,11 @@ @note Error checking assumed to have been performed by the caller */ /*----------------------------------------------------------------------------*/ -void cpl_image_or_mask(cpl_image * self, - const cpl_image * first, - const cpl_image * second) +void +cpl_image_or_mask(cpl_image *self, + const cpl_image *first, + const cpl_image *second) { - const size_t nxy = (size_t)self->nx * (size_t)self->ny; if (self->bpm == NULL) { @@ -3410,33 +3443,40 @@ cpl_mask_or_(cpl_mask_get_data(self->bpm), cpl_mask_get_data_const(first->bpm), cpl_mask_get_data_const(second->bpm), nxy); - } else if (second->bpm != NULL) { + } + else if (second->bpm != NULL) { self->bpm = cpl_mask_duplicate(second->bpm); - } else if (first != NULL && first->bpm != NULL) { + } + else if (first != NULL && first->bpm != NULL) { self->bpm = cpl_mask_duplicate(first->bpm); } - } else { + } + else { /* The self bpm is non-NULL. If first is NULL, then the operation is in-place, so self is an input parameter */ if (first != NULL && first->bpm != NULL && second->bpm != NULL) { cpl_mask_or_(cpl_mask_get_data(self->bpm), cpl_mask_get_data_const(first->bpm), cpl_mask_get_data_const(second->bpm), nxy); - } else if (first != NULL && first->bpm != NULL) { + } + else if (first != NULL && first->bpm != NULL) { assert(second->bpm == NULL); (void)memcpy(cpl_mask_get_data(self->bpm), cpl_mask_get_data_const(first->bpm), nxy); - } else if (second->bpm != NULL) { + } + else if (second->bpm != NULL) { if (first == NULL) { /* Self is an input parameter */ cpl_mask_or(self->bpm, second->bpm); - } else { + } + else { /* First is non-NULL, but happens to have a NULL bpm */ assert(first->bpm == NULL); (void)memcpy(cpl_mask_get_data(self->bpm), cpl_mask_get_data_const(second->bpm), nxy); } - } else if (first != NULL) { + } + else if (first != NULL) { /* First is non-NULL, but happens to have a NULL bpm, so the result is an empty bpm */ (void)memset(cpl_mask_get_data(self->bpm), 0, nxy); @@ -3457,10 +3497,9 @@ @see cpl_image_or_mask */ /*----------------------------------------------------------------------------*/ -void cpl_image_or_mask_unary(cpl_image * self, - const cpl_image * first) +void +cpl_image_or_mask_unary(cpl_image *self, const cpl_image *first) { - const size_t nxy = (size_t)self->nx * (size_t)self->ny; if (self->bpm == NULL) { @@ -3468,13 +3507,15 @@ if (first != NULL && first->bpm != NULL) { self->bpm = cpl_mask_duplicate(first->bpm); } - } else { + } + else { /* The self bpm is non-NULL. If first is NULL, then the operation is in-place, so self is an input parameter */ if (first != NULL && first->bpm != NULL) { (void)memcpy(cpl_mask_get_data(self->bpm), cpl_mask_get_data_const(first->bpm), nxy); - } else if (first != NULL) { + } + else if (first != NULL) { /* First is non-NULL, but happens to have a NULL bpm, so the result is an empty bpm */ (void)memset(cpl_mask_get_data(self->bpm), 0, nxy); @@ -3527,40 +3568,37 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -static cpl_error_code cpl_fft( - double * real, - double * imag, - const unsigned * nn, - int ndim, - int isign) -{ - int idim; - unsigned i1, i2rev, i3rev, ibit; - unsigned ip2, ifp1, ifp2, k2, n; - unsigned nprev = 1, ntot = 1; - register unsigned i2, i3; - double theta; - double w_r, w_i, wp_r, wp_i; - double wtemp; - double temp_r, temp_i, wt_r, wt_i; - double t1, t2; +static cpl_error_code +cpl_fft(double *real, double *imag, const unsigned *nn, int ndim, int isign) +{ + int idim; + unsigned i1, i2rev, i3rev, ibit; + unsigned ip2, ifp1, ifp2, k2, n; + unsigned nprev = 1, ntot = 1; + register unsigned i2, i3; + double theta; + double w_r, w_i, wp_r, wp_i; + double wtemp; + double temp_r, temp_i, wt_r, wt_i; + double t1, t2; /* Check entries */ cpl_ensure_code(real, CPL_ERROR_NULL_INPUT); cpl_ensure_code(imag, CPL_ERROR_NULL_INPUT); cpl_ensure_code(nn, CPL_ERROR_NULL_INPUT); - for (idim = 0; idim < ndim; ++idim) - cpl_ensure_code(cpl_tools_is_power_of_2(nn[idim])>=0, + for (idim = 0; idim < ndim; ++idim) + cpl_ensure_code(cpl_tools_is_power_of_2(nn[idim]) >= 0, CPL_ERROR_ILLEGAL_INPUT); /* Compute total number of complex values */ - for (idim = 0; idim < ndim; ++idim) ntot *= nn[idim]; + for (idim = 0; idim < ndim; ++idim) + ntot *= nn[idim]; for (idim = ndim - 1; idim >= 0; --idim) { n = nn[idim]; - ip2 = nprev * n; /* Unit step for next dimension */ - i2rev = 0; /* Bit reversed i2 */ + ip2 = nprev * n; /* Unit step for next dimension */ + i2rev = 0; /* Bit reversed i2 */ /* This is the bit reversal section of the routine */ /* Loop over current dimension */ @@ -3611,10 +3649,11 @@ wt_i = imag[k2]; /* Complex multiply using 3 real multiplies. */ - real[k2] = real[i2] - (temp_r = - (t1 = w_r * wt_r) - (t2 = w_i * wt_i)); - imag[k2] = imag[i2] - (temp_i = - (w_r + w_i) * (wt_r + wt_i) - t1 - t2); + real[k2] = real[i2] - (temp_r = (t1 = w_r * wt_r) - + (t2 = w_i * wt_i)); + imag[k2] = + imag[i2] - + (temp_i = (w_r + w_i) * (wt_r + wt_i) - t1 - t2); real[i2] += temp_r; imag[i2] += temp_i; } @@ -3649,23 +3688,22 @@ - CPL_ERROR_ILLEGAL_INPUT */ /*----------------------------------------------------------------------------*/ -static double cpl_vector_get_noise( - const cpl_vector * vec, - cpl_size pos) -{ - cpl_size nelem; - cpl_vector * smooth_vec; - const double * vector_data; - double noise_left, noise_right; - cpl_errorstate prestate = cpl_errorstate_get(); - cpl_size i; +static double +cpl_vector_get_noise(const cpl_vector *vec, cpl_size pos) +{ + cpl_size nelem; + cpl_vector *smooth_vec; + const double *vector_data; + double noise_left, noise_right; + cpl_errorstate prestate = cpl_errorstate_get(); + cpl_size i; /* Check entries */ - cpl_ensure(vec, CPL_ERROR_NULL_INPUT, -1.0); + cpl_ensure(vec, CPL_ERROR_NULL_INPUT, -1.0); nelem = cpl_vector_get_size(vec); - cpl_ensure(pos >= 1, CPL_ERROR_ILLEGAL_INPUT, -1.0); + cpl_ensure(pos >= 1, CPL_ERROR_ILLEGAL_INPUT, -1.0); cpl_ensure(pos <= nelem, CPL_ERROR_ILLEGAL_INPUT, -1.0); - cpl_ensure(nelem > 1, CPL_ERROR_ILLEGAL_INPUT, -1.0); + cpl_ensure(nelem > 1, CPL_ERROR_ILLEGAL_INPUT, -1.0); /* Smooth out the array to be less sensitive to noise */ smooth_vec = cpl_vector_filter_lowpass_create(vec, CPL_LOWPASS_LINEAR, 1); @@ -3679,9 +3717,10 @@ if (smooth_vec != NULL) { /* The smoothing (half-size is 1) may have moved the maximum 1 pixel */ - if (pos < nelem && vector_data[pos-1] < vector_data[pos]) { + if (pos < nelem && vector_data[pos - 1] < vector_data[pos]) { pos++; - } else if (pos > 1 && vector_data[pos-1] < vector_data[pos-2]) { + } + else if (pos > 1 && vector_data[pos - 1] < vector_data[pos - 2]) { pos--; } } @@ -3689,16 +3728,20 @@ /* Find noise level on the left side of the peak. */ i = pos - 1; while (i > 0) { - if (vector_data[i] > vector_data[i-1]) i--; - else break; + if (vector_data[i] > vector_data[i - 1]) + i--; + else + break; } noise_left = vector_data[i]; /* Find noise level on the right side of the peak */ i = pos - 1; - while (i < nelem-1) { - if (vector_data[i] > vector_data[i+1]) i++; - else break; + while (i < nelem - 1) { + if (vector_data[i] > vector_data[i + 1]) + i++; + else + break; } noise_right = vector_data[i]; @@ -3723,63 +3766,67 @@ - CPL_ERROR_ILLEGAL_INPUT if pos is less than 1 or greater than the vec-length */ /*----------------------------------------------------------------------------*/ -static double cpl_vector_get_fwhm( - const cpl_vector * vec, - cpl_size pos, - double half_max) -{ - const double * vec_data; - cpl_size nelem; - double x_left, x_right; - double y_1, y_2; - cpl_size i; +static double +cpl_vector_get_fwhm(const cpl_vector *vec, cpl_size pos, double half_max) +{ + const double *vec_data; + cpl_size nelem; + double x_left, x_right; + double y_1, y_2; + cpl_size i; /* Check entries */ - cpl_ensure(vec, CPL_ERROR_NULL_INPUT, -1.0); + cpl_ensure(vec, CPL_ERROR_NULL_INPUT, -1.0); nelem = cpl_vector_get_size(vec); - cpl_ensure(pos >= 1, CPL_ERROR_ILLEGAL_INPUT, -1.0); + cpl_ensure(pos >= 1, CPL_ERROR_ILLEGAL_INPUT, -1.0); cpl_ensure(pos <= nelem, CPL_ERROR_ILLEGAL_INPUT, -1.0); vec_data = cpl_vector_get_data_const(vec); /* Object may be too noisy - or strange in some other way */ - if (vec_data[pos - 1] <= half_max) return -1.0; + if (vec_data[pos - 1] <= half_max) + return -1.0; /* Find first pair of values, y(i) <= half_max < y(i+1) on the left of the maximum */ i = pos - 1; - while ((vec_data[i] > half_max) && (i > 0)) i--; - if (vec_data[i] > half_max) return -1.0; /* y_1 could not be found */ + while ((vec_data[i] > half_max) && (i > 0)) + i--; + if (vec_data[i] > half_max) + return -1.0; /* y_1 could not be found */ y_1 = vec_data[i]; - y_2 = vec_data[i+1]; + y_2 = vec_data[i + 1]; /* assert ( y_1 <= half_max && half_max < y_2 ); */ /* Assume linearity between y_1 and y_2 */ - x_left = (double)i + (half_max-y_1) / (y_2-y_1); + x_left = (double)i + (half_max - y_1) / (y_2 - y_1); /* assert( x_left >= i ); */ /* Find first pair of values, y(i-1) > half_max >= y(i) on the right of the maximum */ i = pos - 1; - - while ((vec_data[i] > half_max) && (i < nelem-1)) i++; - if (vec_data[i] > half_max) return -1.0; /* y_2 could not be found */ - y_1 = vec_data[i-1]; + while ((vec_data[i] > half_max) && (i < nelem - 1)) + i++; + if (vec_data[i] > half_max) + return -1.0; /* y_2 could not be found */ + + y_1 = vec_data[i - 1]; y_2 = vec_data[i]; /* assert( y_1 > half_max && half_max >= y_2 ); */ /* Assume linearity between y_1 and y_2 */ - x_right = (double)i + (half_max-y_2) / (y_2-y_1); + x_right = (double)i + (half_max - y_2) / (y_2 - y_1); /* assert( x_right < i ); */ - if (x_right < x_left || x_right - x_left > FLT_MAX) return -1; + if (x_right < x_left || x_right - x_left > FLT_MAX) + return -1; return x_right - x_left; } @@ -3807,7 +3854,7 @@ */ /*----------------------------------------------------------------------------*/ static void CPL_ATTR_NOINLINE -fcompl_mult_scalar2(float complex * a, const float complex * b, const size_t i) +fcompl_mult_scalar2(float complex *a, const float complex *b, const size_t i) { a[i] = a[i] * b[i]; a[i + 1] = a[i + 1] * b[i + 1]; @@ -3825,20 +3872,21 @@ */ /*----------------------------------------------------------------------------*/ static inline cpl_boolean -fcompl_fix_nan(__m128 res, float complex * a, - const float complex * b, +fcompl_fix_nan(__m128 res, + float complex *a, + const float complex *b, const size_t i) { #ifndef __FAST_MATH__ - /* check for NaN, redo all in libc if found */ - __m128 n = _mm_cmpneq_ps(res, res); - if (CPL_UNLIKELY(_mm_movemask_ps(n) != 0)) { - fcompl_mult_scalar2(a, b, i); - return CPL_TRUE; - } - else + /* check for NaN, redo all in libc if found */ + __m128 n = _mm_cmpneq_ps(res, res); + if (CPL_UNLIKELY(_mm_movemask_ps(n) != 0)) { + fcompl_mult_scalar2(a, b, i); + return CPL_TRUE; + } + else #endif - return CPL_FALSE; + return CPL_FALSE; } @@ -3860,9 +3908,9 @@ /* optimized to SSE3 _mm_move[hl]dup_ps by gcc */ __m128 reala = _mm_shuffle_ps(va, va, _MM_SHUFFLE(2, 2, 0, 0)); /* x x */ __m128 imaga = _mm_shuffle_ps(va, va, _MM_SHUFFLE(3, 3, 1, 1)); /* w w */ - __m128 t1 = _mm_mul_ps(reala, vb); /* x*y x*z */ + __m128 t1 = _mm_mul_ps(reala, vb); /* x*y x*z */ __m128 sb = _mm_shuffle_ps(vb, vb, _MM_SHUFFLE(2, 3, 0, 1)); /* z y */ - __m128 t2 = _mm_mul_ps(imaga, sb); /* w*z w*y */ + __m128 t2 = _mm_mul_ps(imaga, sb); /* w*z w*y */ return CPL_MM_ADDSUB_PS(t1, t2); /* x*y-w*z x*z+w*y*/ } @@ -3879,15 +3927,15 @@ */ /*----------------------------------------------------------------------------*/ static cpl_error_code -fcompl_mult_sse_aligned(float complex * a, - const float complex * b, +fcompl_mult_sse_aligned(float complex *a, + const float complex *b, const size_t Nt) { const size_t n = (Nt % 2) == 1 ? Nt - 1 : Nt; /* no overflow hint for the compiler */ - cpl_ensure_code(n < SIZE_MAX-1, CPL_ERROR_ACCESS_OUT_OF_RANGE); - for (size_t i = 0; i < n; i+=2) { + cpl_ensure_code(n < SIZE_MAX - 1, CPL_ERROR_ACCESS_OUT_OF_RANGE); + for (size_t i = 0; i < n; i += 2) { __m128 va = _mm_load_ps((const float *)&a[i]); /* x w */ __m128 vb = _mm_load_ps((const float *)&b[i]); /* y z */ __m128 res = fcompl_mult_sse_fast(va, vb); @@ -3915,15 +3963,15 @@ */ /*----------------------------------------------------------------------------*/ static cpl_error_code -fcompl_mult_sse_unaligned(float complex * a, - const float complex * b, +fcompl_mult_sse_unaligned(float complex *a, + const float complex *b, const size_t Nt) { const size_t n = (Nt % 2) == 1 ? Nt - 1 : Nt; /* no overflow hint for the compiler */ - cpl_ensure_code(n < SIZE_MAX-1, CPL_ERROR_ACCESS_OUT_OF_RANGE); - for (size_t i = 0; i < n; i+=2) { + cpl_ensure_code(n < SIZE_MAX - 1, CPL_ERROR_ACCESS_OUT_OF_RANGE); + for (size_t i = 0; i < n; i += 2) { __m128 va = _mm_loadu_ps((const float *)&a[i]); /* x w */ __m128 vb = _mm_loadu_ps((const float *)&b[i]); /* y z */ __m128 res = fcompl_mult_sse_fast(va, vb); @@ -3951,12 +3999,12 @@ @note No error checking performed in this static function */ /*----------------------------------------------------------------------------*/ -static cpl_error_code cpl_image_multiply_fcomplex_sse_(cpl_image * im1, - const cpl_image * im2) +static cpl_error_code +cpl_image_multiply_fcomplex_sse_(cpl_image *im1, const cpl_image *im2) { const size_t Nt = im1->nx * im1->ny; - float complex * a = im1->pixels; - const float complex * b = im2->pixels; + float complex *a = im1->pixels; + const float complex *b = im2->pixels; cpl_error_code err = CPL_ERROR_NONE; /* FIXME: cases for a xor b unaligned? */ @@ -3974,7 +4022,8 @@ if (im2->bpm != NULL) { if (im1->bpm == NULL) { im1->bpm = cpl_mask_duplicate(im2->bpm); - } else { + } + else { cpl_mask_or(im1->bpm, im2->bpm); } } @@ -3997,7 +4046,7 @@ */ /*----------------------------------------------------------------------------*/ static void CPL_ATTR_NOINLINE -dcompl_mult_scalar(double complex * a, const double complex * b, const size_t i) +dcompl_mult_scalar(double complex *a, const double complex *b, const size_t i) { a[i] = a[i] * b[i]; } @@ -4014,20 +4063,21 @@ */ /*----------------------------------------------------------------------------*/ static inline cpl_boolean -dcompl_fix_nan(__m128d res, double complex * a, - const double complex * b, +dcompl_fix_nan(__m128d res, + double complex *a, + const double complex *b, const size_t i) { #ifndef __FAST_MATH__ - /* check for NaN, redo all in libc if found */ - __m128d n = _mm_cmpneq_pd(res, res); - if (CPL_UNLIKELY(_mm_movemask_pd(n) != 0)) { - dcompl_mult_scalar(a, b, i); - return CPL_TRUE; - } - else + /* check for NaN, redo all in libc if found */ + __m128d n = _mm_cmpneq_pd(res, res); + if (CPL_UNLIKELY(_mm_movemask_pd(n) != 0)) { + dcompl_mult_scalar(a, b, i); + return CPL_TRUE; + } + else #endif - return CPL_FALSE; + return CPL_FALSE; } @@ -4047,10 +4097,10 @@ dcompl_mult_sse_fast(__m128d va, __m128d vb) { /* optimized to SSE3 _mm_movedup_pd by gcc */ - __m128d rb = _mm_unpacklo_pd(vb, vb); /* y, y */ - __m128d ib = _mm_unpackhi_pd(vb, vb); /* w, w*/ - __m128d t1 = _mm_mul_pd(rb, va); /* y * x, y * z */ - __m128d t2 = _mm_mul_pd(ib, va); /* w * x, w * z*/ + __m128d rb = _mm_unpacklo_pd(vb, vb); /* y, y */ + __m128d ib = _mm_unpackhi_pd(vb, vb); /* w, w*/ + __m128d t1 = _mm_mul_pd(rb, va); /* y * x, y * z */ + __m128d t2 = _mm_mul_pd(ib, va); /* w * x, w * z*/ __m128d sb = _mm_shuffle_pd(t2, t2, _MM_SHUFFLE2(0, 1)); /* w * z, w * x */ return CPL_MM_ADDSUB_PD(t1, sb); /* x * y - y * w, z*y + x * w */ } @@ -4068,8 +4118,8 @@ */ /*----------------------------------------------------------------------------*/ static cpl_error_code CPL_ATTR_NOINLINE -dcompl_mult_sse_aligned(double complex * a, - const double complex * b, +dcompl_mult_sse_aligned(double complex *a, + const double complex *b, const size_t n) { /* no overflow hint for the compiler */ @@ -4099,8 +4149,8 @@ */ /*----------------------------------------------------------------------------*/ static cpl_error_code -dcompl_mult_sse_unaligned(double complex * a, - const double complex * b, +dcompl_mult_sse_unaligned(double complex *a, + const double complex *b, const size_t n) { /* no overflow hint for the compiler */ @@ -4129,12 +4179,12 @@ @note No error checking performed in this static function */ /*----------------------------------------------------------------------------*/ -static cpl_error_code cpl_image_multiply_dcomplex_sse_(cpl_image * im1, - const cpl_image * im2) +static cpl_error_code +cpl_image_multiply_dcomplex_sse_(cpl_image *im1, const cpl_image *im2) { const size_t Nt = im1->nx * im1->ny; - double complex * a = im1->pixels; - const double complex * b = im2->pixels; + double complex *a = im1->pixels; + const double complex *b = im2->pixels; cpl_error_code err = CPL_ERROR_NONE; /* FIXME: cases for a xor b unaligned? */ @@ -4148,7 +4198,8 @@ if (im2->bpm != NULL) { if (im1->bpm == NULL) { im1->bpm = cpl_mask_duplicate(im2->bpm); - } else { + } + else { cpl_mask_or(im1->bpm, im2->bpm); } } diff -Nru cpl-7.1.4+ds/cplcore/cpl_image_basic.h cpl-7.2.2+ds/cplcore/cpl_image_basic.h --- cpl-7.1.4+ds/cplcore/cpl_image_basic.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_image_basic.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -36,15 +36,16 @@ * Each FFT mode is listed below. * The modes can be combined with bitwise or. */ -#define CPL_FFT_DEFAULT ((unsigned)0) +#define CPL_FFT_DEFAULT ((unsigned)0) /* Inverse FFT */ -#define CPL_FFT_INVERSE ((unsigned)1 << 1) +#define CPL_FFT_INVERSE ((unsigned)1 << 1) /* No normalization */ #define CPL_FFT_UNNORMALIZED ((unsigned)1 << 2) /* Swap halves of output */ -#define CPL_FFT_SWAP_HALVES ((unsigned)1 << 3) +#define CPL_FFT_SWAP_HALVES ((unsigned)1 << 3) -enum _cpl_norm_ { +enum _cpl_norm_ +{ CPL_NORM_SCALE, CPL_NORM_MEAN, CPL_NORM_FLUX, @@ -58,14 +59,14 @@ -----------------------------------------------------------------------------*/ /* Basic operations */ -cpl_image * cpl_image_add_create(const cpl_image *, const cpl_image *) - CPL_ATTR_ALLOC; -cpl_image * cpl_image_subtract_create(const cpl_image *, const cpl_image *) - CPL_ATTR_ALLOC; -cpl_image * cpl_image_multiply_create(const cpl_image *, const cpl_image *) - CPL_ATTR_ALLOC; -cpl_image * cpl_image_divide_create(const cpl_image *, const cpl_image *) - CPL_ATTR_ALLOC; +cpl_image * +cpl_image_add_create(const cpl_image *, const cpl_image *) CPL_ATTR_ALLOC; +cpl_image * +cpl_image_subtract_create(const cpl_image *, const cpl_image *) CPL_ATTR_ALLOC; +cpl_image * +cpl_image_multiply_create(const cpl_image *, const cpl_image *) CPL_ATTR_ALLOC; +cpl_image * +cpl_image_divide_create(const cpl_image *, const cpl_image *) CPL_ATTR_ALLOC; cpl_error_code cpl_image_add(cpl_image *, const cpl_image *); cpl_error_code cpl_image_subtract(cpl_image *, const cpl_image *); cpl_error_code cpl_image_multiply(cpl_image *, const cpl_image *); @@ -80,82 +81,70 @@ cpl_error_code cpl_image_logarithm(cpl_image *, double); cpl_error_code cpl_image_normalise(cpl_image *, cpl_norm); cpl_error_code cpl_image_abs(cpl_image *); -cpl_error_code cpl_image_hypot(cpl_image *, - const cpl_image *, - const cpl_image *); - -cpl_error_code cpl_image_and(cpl_image *, - const cpl_image *, - const cpl_image *); -cpl_error_code cpl_image_or(cpl_image *, - const cpl_image *, - const cpl_image *); -cpl_error_code cpl_image_xor(cpl_image *, - const cpl_image *, - const cpl_image *); - -cpl_error_code cpl_image_not(cpl_image *, - const cpl_image *); - -cpl_error_code cpl_image_and_scalar(cpl_image *, - const cpl_image *, - cpl_bitmask); -cpl_error_code cpl_image_or_scalar(cpl_image *, - const cpl_image *, - cpl_bitmask); -cpl_error_code cpl_image_xor_scalar(cpl_image *, - const cpl_image *, - cpl_bitmask); +cpl_error_code +cpl_image_hypot(cpl_image *, const cpl_image *, const cpl_image *); -cpl_image * cpl_image_add_scalar_create(const cpl_image *, double) - CPL_ATTR_ALLOC; -cpl_image * cpl_image_subtract_scalar_create(const cpl_image *, double) - CPL_ATTR_ALLOC; -cpl_image * cpl_image_multiply_scalar_create(const cpl_image *, double) - CPL_ATTR_ALLOC; -cpl_image * cpl_image_divide_scalar_create(const cpl_image *, double) - CPL_ATTR_ALLOC; -cpl_image * cpl_image_power_create(const cpl_image *, double) - CPL_ATTR_ALLOC; -cpl_image * cpl_image_exponential_create(const cpl_image *, double) - CPL_ATTR_ALLOC; -cpl_image * cpl_image_logarithm_create(const cpl_image *, double) - CPL_ATTR_ALLOC; -cpl_image * cpl_image_normalise_create(const cpl_image *, cpl_norm) - CPL_ATTR_ALLOC; -cpl_image * cpl_image_abs_create(const cpl_image *) - CPL_ATTR_ALLOC; +cpl_error_code cpl_image_and(cpl_image *, const cpl_image *, const cpl_image *); +cpl_error_code cpl_image_or(cpl_image *, const cpl_image *, const cpl_image *); +cpl_error_code cpl_image_xor(cpl_image *, const cpl_image *, const cpl_image *); + +cpl_error_code cpl_image_not(cpl_image *, const cpl_image *); + +cpl_error_code +cpl_image_and_scalar(cpl_image *, const cpl_image *, cpl_bitmask); +cpl_error_code cpl_image_or_scalar(cpl_image *, const cpl_image *, cpl_bitmask); +cpl_error_code +cpl_image_xor_scalar(cpl_image *, const cpl_image *, cpl_bitmask); + +cpl_image * +cpl_image_add_scalar_create(const cpl_image *, double) CPL_ATTR_ALLOC; +cpl_image * +cpl_image_subtract_scalar_create(const cpl_image *, double) CPL_ATTR_ALLOC; +cpl_image * +cpl_image_multiply_scalar_create(const cpl_image *, double) CPL_ATTR_ALLOC; +cpl_image * +cpl_image_divide_scalar_create(const cpl_image *, double) CPL_ATTR_ALLOC; +cpl_image *cpl_image_power_create(const cpl_image *, double) CPL_ATTR_ALLOC; +cpl_image * +cpl_image_exponential_create(const cpl_image *, double) CPL_ATTR_ALLOC; +cpl_image *cpl_image_logarithm_create(const cpl_image *, double) CPL_ATTR_ALLOC; +cpl_image * +cpl_image_normalise_create(const cpl_image *, cpl_norm) CPL_ATTR_ALLOC; +cpl_image *cpl_image_abs_create(const cpl_image *) CPL_ATTR_ALLOC; cpl_error_code cpl_image_threshold(cpl_image *, double, double, double, double); -cpl_image * cpl_image_average_create(const cpl_image *, const cpl_image *) - CPL_ATTR_ALLOC; +cpl_image * +cpl_image_average_create(const cpl_image *, const cpl_image *) CPL_ATTR_ALLOC; /* Collapse functions */ -cpl_image * cpl_image_collapse_window_create(const cpl_image *, cpl_size, - cpl_size, cpl_size, - cpl_size, int) - CPL_ATTR_ALLOC; -cpl_image * cpl_image_collapse_create(const cpl_image *, int) - CPL_ATTR_ALLOC; -cpl_image * cpl_image_collapse_median_create(const cpl_image *, int, - cpl_size, cpl_size) - CPL_ATTR_ALLOC; +cpl_image *cpl_image_collapse_window_create(const cpl_image *, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + int) CPL_ATTR_ALLOC; +cpl_image *cpl_image_collapse_create(const cpl_image *, int) CPL_ATTR_ALLOC; +cpl_image *cpl_image_collapse_median_create(const cpl_image *, + int, + cpl_size, + cpl_size) CPL_ATTR_ALLOC; /* Extraction function */ -cpl_image * cpl_image_extract(const cpl_image *, cpl_size, cpl_size, - cpl_size, cpl_size) CPL_ATTR_ALLOC; -cpl_vector * cpl_vector_new_from_image_row(const cpl_image *, cpl_size) - CPL_ATTR_ALLOC; -cpl_vector * cpl_vector_new_from_image_column(const cpl_image *, cpl_size) +cpl_image * +cpl_image_extract(const cpl_image *, cpl_size, cpl_size, cpl_size, cpl_size) CPL_ATTR_ALLOC; +cpl_vector * +cpl_vector_new_from_image_row(const cpl_image *, cpl_size) CPL_ATTR_ALLOC; +cpl_vector * +cpl_vector_new_from_image_column(const cpl_image *, cpl_size) CPL_ATTR_ALLOC; /* Rotation and Shift */ cpl_error_code cpl_image_turn(cpl_image *, int); cpl_error_code cpl_image_shift(cpl_image *, cpl_size, cpl_size); /* Insert an image in an other one */ -cpl_error_code cpl_image_copy(cpl_image *, const cpl_image *, - cpl_size, cpl_size); +cpl_error_code +cpl_image_copy(cpl_image *, const cpl_image *, cpl_size, cpl_size); /* Symmetry function */ cpl_error_code cpl_image_flip(cpl_image *, int); @@ -164,18 +153,25 @@ cpl_error_code cpl_image_move(cpl_image *, cpl_size, const cpl_size *); /* Gaussian fit of an image zone */ -cpl_error_code -cpl_image_fit_gaussian(const cpl_image *, cpl_size, cpl_size, cpl_size, - double *, double *, double *, double *, - double *, double *, double *) CPL_ATTR_DEPRECATED; +cpl_error_code cpl_image_fit_gaussian(const cpl_image *, + cpl_size, + cpl_size, + cpl_size, + double *, + double *, + double *, + double *, + double *, + double *, + double *) CPL_ATTR_DEPRECATED; /* FWHM computation on a local maximum */ -cpl_error_code cpl_image_get_fwhm(const cpl_image *, cpl_size, cpl_size, - double *, double *); +cpl_error_code +cpl_image_get_fwhm(const cpl_image *, cpl_size, cpl_size, double *, double *); /* FFT computation */ cpl_error_code cpl_image_fft(cpl_image *, cpl_image *, unsigned); CPL_END_DECLS -#endif +#endif diff -Nru cpl-7.1.4+ds/cplcore/cpl_image_basic_impl.h cpl-7.2.2+ds/cplcore/cpl_image_basic_impl.h --- cpl-7.1.4+ds/cplcore/cpl_image_basic_impl.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_image_basic_impl.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -32,19 +32,18 @@ Function prototypes -----------------------------------------------------------------------------*/ -cpl_image * cpl_image_min_create(const cpl_image *, const cpl_image *) - CPL_INTERNAL - CPL_ATTR_ALLOC; +cpl_image *cpl_image_min_create(const cpl_image *, + const cpl_image *) CPL_INTERNAL CPL_ATTR_ALLOC; -void cpl_image_or_mask(cpl_image *, const cpl_image *, const cpl_image *) - CPL_INTERNAL +void cpl_image_or_mask(cpl_image *, + const cpl_image *, + const cpl_image *) CPL_INTERNAL #ifdef CPL_HAVE_ATTR_NONNULL - __attribute__((nonnull(1,3))) + __attribute__((nonnull(1, 3))) #endif ; -void cpl_image_or_mask_unary(cpl_image *, const cpl_image *) - CPL_INTERNAL +void cpl_image_or_mask_unary(cpl_image *, const cpl_image *) CPL_INTERNAL #ifdef CPL_HAVE_ATTR_NONNULL __attribute__((nonnull(1))) #endif @@ -52,4 +51,4 @@ CPL_END_DECLS -#endif +#endif diff -Nru cpl-7.1.4+ds/cplcore/cpl_image_bpm_body.h cpl-7.2.2+ds/cplcore/cpl_image_bpm_body.h --- cpl-7.1.4+ds/cplcore/cpl_image_bpm_body.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_image_bpm_body.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -37,22 +37,21 @@ */ /*----------------------------------------------------------------------------*/ -static cpl_error_code ADDTYPE(cpl_image_reject_value)(cpl_image * self, - cpl_value mode) +static cpl_error_code + ADDTYPE(cpl_image_reject_value)(cpl_image *self, cpl_value mode) { - - CPL_TYPE * data = (CPL_TYPE*)cpl_image_get_data(self); - cpl_binary* bpm = NULL; - const size_t npix = (size_t)cpl_image_get_size_x(self) - * (size_t)cpl_image_get_size_y(self); + CPL_TYPE *data = (CPL_TYPE *)cpl_image_get_data(self); + cpl_binary *bpm = NULL; + const size_t npix = + (size_t)cpl_image_get_size_x(self) * (size_t)cpl_image_get_size_y(self); size_t i; cpl_value check = mode; - cpl_ensure_code(mode != 1, CPL_ERROR_INVALID_TYPE); - cpl_ensure_code(mode != 0, CPL_ERROR_UNSUPPORTED_MODE); + cpl_ensure_code(mode != 1, CPL_ERROR_INVALID_TYPE); + cpl_ensure_code(mode != 0, CPL_ERROR_UNSUPPORTED_MODE); - check &= ~ ( CPL_VALUE_NOTFINITE | CPL_VALUE_ZERO); - cpl_ensure_code(check == 0, CPL_ERROR_UNSUPPORTED_MODE); + check &= ~(CPL_VALUE_NOTFINITE | CPL_VALUE_ZERO); + cpl_ensure_code(check == 0, CPL_ERROR_UNSUPPORTED_MODE); #ifdef CPL_TYPE_IS_INT if (mode & CPL_VALUE_ZERO) { @@ -70,13 +69,11 @@ for (i = 0; i < npix; i++) { const int fptype = fpclassify(data[i]); if ((fptype == FP_ZERO && (mode & CPL_VALUE_ZERO)) || - (fptype == FP_NAN && (mode & CPL_VALUE_NAN)) || - (fptype == FP_INFINITE && (((mode & CPL_VALUE_PLUSINF) && - ((mode & CPL_VALUE_MINUSINF) - || data[i] > 0.0)) || - ((mode & CPL_VALUE_MINUSINF) && - data[i] < 0.0)))) { - + (fptype == FP_NAN && (mode & CPL_VALUE_NAN)) || + (fptype == FP_INFINITE && + (((mode & CPL_VALUE_PLUSINF) && + ((mode & CPL_VALUE_MINUSINF) || data[i] > 0.0)) || + ((mode & CPL_VALUE_MINUSINF) && data[i] < 0.0)))) { if (bpm == NULL) { bpm = cpl_mask_get_data(cpl_image_get_bpm(self)); } diff -Nru cpl-7.1.4+ds/cplcore/cpl_image_bpm.c cpl-7.2.2+ds/cplcore/cpl_image_bpm.c --- cpl-7.1.4+ds/cplcore/cpl_image_bpm.c 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_image_bpm.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -25,7 +25,7 @@ Includes -----------------------------------------------------------------------------*/ -#include "cpl_image_bpm.h" +#include "cpl_image_bpm_impl.h" #include "cpl_tools.h" #include "cpl_error_impl.h" @@ -41,8 +41,8 @@ /* These macros are needed for support of the different pixel types */ -#define CONCAT(a,b) a ## _ ## b -#define CONCAT2X(a,b) CONCAT(a,b) +#define CONCAT(a, b) a##_##b +#define CONCAT2X(a, b) CONCAT(a, b) #define ADDTYPE(a) CONCAT2X(a, CPL_TYPE_NAME) @@ -50,33 +50,33 @@ Static Function Prototypes -----------------------------------------------------------------------------*/ -#define CPL_TYPE double +#define CPL_TYPE double #define CPL_TYPE_NAME double #include "cpl_image_bpm_body.h" #undef CPL_TYPE #undef CPL_TYPE_NAME -#define CPL_TYPE float +#define CPL_TYPE float #define CPL_TYPE_NAME float #include "cpl_image_bpm_body.h" #undef CPL_TYPE #undef CPL_TYPE_NAME #ifdef CPL_FPCLASSIFY_COMPLEX -#define CPL_TYPE double complex +#define CPL_TYPE double complex #define CPL_TYPE_NAME double_complex #include "cpl_image_bpm_body.h" #undef CPL_TYPE #undef CPL_TYPE_NAME -#define CPL_TYPE float complex +#define CPL_TYPE float complex #define CPL_TYPE_NAME float_complex #include "cpl_image_bpm_body.h" #undef CPL_TYPE #undef CPL_TYPE_NAME #endif -#define CPL_TYPE int +#define CPL_TYPE int #define CPL_TYPE_NAME int #define CPL_TYPE_IS_INT #include "cpl_image_bpm_body.h" @@ -103,33 +103,34 @@ allowed options. */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_reject_value(cpl_image * self, cpl_value mode) +cpl_error_code +cpl_image_reject_value(cpl_image *self, cpl_value mode) { - cpl_error_code error = CPL_ERROR_NONE; switch (cpl_image_get_type(self)) { - case CPL_TYPE_DOUBLE: - error = cpl_image_reject_value_double(self, mode); - break; - case CPL_TYPE_FLOAT: - error = cpl_image_reject_value_float(self, mode); - break; + case CPL_TYPE_DOUBLE: + error = cpl_image_reject_value_double(self, mode); + break; + case CPL_TYPE_FLOAT: + error = cpl_image_reject_value_float(self, mode); + break; #ifdef CPL_FPCLASSIFY_COMPLEX - case CPL_TYPE_DOUBLE_COMPLEX: - error = cpl_image_reject_value_double_complex(self, mode); - break; - case CPL_TYPE_FLOAT_COMPLEX: - error = cpl_image_reject_value_float_complex(self, mode); - break; + case CPL_TYPE_DOUBLE_COMPLEX: + error = cpl_image_reject_value_double_complex(self, mode); + break; + case CPL_TYPE_FLOAT_COMPLEX: + error = cpl_image_reject_value_float_complex(self, mode); + break; #endif - case CPL_TYPE_INT: - error = cpl_image_reject_value_int(self, mode); - break; - default: - /* NULL input and unsupported pixel types */ - error = self != NULL ? CPL_ERROR_INVALID_TYPE : CPL_ERROR_NULL_INPUT; - break; + case CPL_TYPE_INT: + error = cpl_image_reject_value_int(self, mode); + break; + default: + /* NULL input and unsupported pixel types */ + error = + self != NULL ? CPL_ERROR_INVALID_TYPE : CPL_ERROR_NULL_INPUT; + break; } return error ? cpl_error_set_(error) : CPL_ERROR_NONE; @@ -150,15 +151,13 @@ the image */ /*----------------------------------------------------------------------------*/ -int cpl_image_is_rejected(const cpl_image * im, - cpl_size x, - cpl_size y) +int +cpl_image_is_rejected(const cpl_image *im, cpl_size x, cpl_size y) { - /* Test entries */ - cpl_ensure(im != NULL, CPL_ERROR_NULL_INPUT, -1); - cpl_ensure(x >= 1, CPL_ERROR_ACCESS_OUT_OF_RANGE, -2); - cpl_ensure(y >= 1, CPL_ERROR_ACCESS_OUT_OF_RANGE, -3); + cpl_ensure(im != NULL, CPL_ERROR_NULL_INPUT, -1); + cpl_ensure(x >= 1, CPL_ERROR_ACCESS_OUT_OF_RANGE, -2); + cpl_ensure(y >= 1, CPL_ERROR_ACCESS_OUT_OF_RANGE, -3); cpl_ensure(x <= im->nx, CPL_ERROR_ACCESS_OUT_OF_RANGE, -4); cpl_ensure(y <= im->ny, CPL_ERROR_ACCESS_OUT_OF_RANGE, -5); @@ -182,9 +181,9 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_image_count_rejected(const cpl_image * im) +cpl_size +cpl_image_count_rejected(const cpl_image *im) { - cpl_ensure(im != NULL, CPL_ERROR_NULL_INPUT, -1); return im->bpm == NULL ? 0 : cpl_mask_count(im->bpm); @@ -204,21 +203,20 @@ */ /*----------------------------------------------------------------------------*/ -void cpl_image_reject_(cpl_image * im, - cpl_size x, - cpl_size y) +void +cpl_image_reject_(cpl_image *im, cpl_size x, cpl_size y) { - cpl_binary * pbpm; + cpl_binary *pbpm; /* Create the bad pixels mask if empty */ - if (im->bpm == NULL) im->bpm = cpl_mask_new(im->nx, im->ny); + if (im->bpm == NULL) + im->bpm = cpl_mask_new(im->nx, im->ny); /* Get the access to the data */ pbpm = cpl_mask_get_data(im->bpm); /* Set the bad pixel */ - pbpm[(x-1) + (y-1) * im->nx] = CPL_BINARY_1; - + pbpm[(x - 1) + (y - 1) * im->nx] = CPL_BINARY_1; } /*----------------------------------------------------------------------------*/ @@ -236,14 +234,13 @@ the image */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_reject(cpl_image * im, - cpl_size x, - cpl_size y) +cpl_error_code +cpl_image_reject(cpl_image *im, cpl_size x, cpl_size y) { /* Test entries */ - cpl_ensure_code(im != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(x >= 1, CPL_ERROR_ACCESS_OUT_OF_RANGE); - cpl_ensure_code(y >= 1, CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_ensure_code(im != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(x >= 1, CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_ensure_code(y >= 1, CPL_ERROR_ACCESS_OUT_OF_RANGE); cpl_ensure_code(x <= im->nx, CPL_ERROR_ACCESS_OUT_OF_RANGE); cpl_ensure_code(y <= im->ny, CPL_ERROR_ACCESS_OUT_OF_RANGE); @@ -266,16 +263,15 @@ */ /*----------------------------------------------------------------------------*/ -void cpl_image_accept_(cpl_image * im, - cpl_size x, - cpl_size y) +void +cpl_image_accept_(cpl_image *im, cpl_size x, cpl_size y) { if (im->bpm != NULL) { /* Get the access to the data */ - cpl_binary * pbpm = cpl_mask_get_data(im->bpm); + cpl_binary *pbpm = cpl_mask_get_data(im->bpm); /* Set the good pixel */ - pbpm[(x-1) + (y-1) * im->nx] = CPL_BINARY_0; + pbpm[(x - 1) + (y - 1) * im->nx] = CPL_BINARY_0; } } @@ -294,14 +290,13 @@ the image */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_accept(cpl_image * im, - cpl_size x, - cpl_size y) +cpl_error_code +cpl_image_accept(cpl_image *im, cpl_size x, cpl_size y) { /* Test entries */ - cpl_ensure_code(im != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(x >= 1, CPL_ERROR_ACCESS_OUT_OF_RANGE); - cpl_ensure_code(y >= 1, CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_ensure_code(im != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(x >= 1, CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_ensure_code(y >= 1, CPL_ERROR_ACCESS_OUT_OF_RANGE); cpl_ensure_code(x <= im->nx, CPL_ERROR_ACCESS_OUT_OF_RANGE); cpl_ensure_code(y <= im->ny, CPL_ERROR_ACCESS_OUT_OF_RANGE); @@ -321,9 +316,9 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_accept_all(cpl_image * self) +cpl_error_code +cpl_image_accept_all(cpl_image *self) { - cpl_mask_delete(cpl_image_unset_bpm(self)); return self != NULL ? CPL_ERROR_NONE : cpl_error_set_where_(); @@ -345,16 +340,15 @@ - CPL_ERROR_INCOMPATIBLE_INPUT if the image and the map have different sizes */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_reject_from_mask(cpl_image * im, - const cpl_mask * map) +cpl_error_code +cpl_image_reject_from_mask(cpl_image *im, const cpl_mask *map) { - /* Test entries */ - cpl_ensure_code(im != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(im != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(map != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(im->nx==cpl_mask_get_size_x(map), + cpl_ensure_code(im->nx == cpl_mask_get_size_x(map), CPL_ERROR_INCOMPATIBLE_INPUT); - cpl_ensure_code(im->ny==cpl_mask_get_size_y(map), + cpl_ensure_code(im->ny == cpl_mask_get_size_y(map), CPL_ERROR_INCOMPATIBLE_INPUT); /* Copy the provided mask - cpl_image_get_bpm(im) @@ -365,4 +359,3 @@ return CPL_ERROR_NONE; } - diff -Nru cpl-7.1.4+ds/cplcore/cpl_image_bpm.h cpl-7.2.2+ds/cplcore/cpl_image_bpm.h --- cpl-7.1.4+ds/cplcore/cpl_image_bpm.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_image_bpm.h 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -41,40 +41,41 @@ * They are a bit-field and can be combined with bitwise or. */ -enum _cpl_value_ { +enum _cpl_value_ +{ -/* No entry has the value 1 which makes the (mis)use of logical or detectable */ + /* No entry has the value 1 which makes the (mis)use of logical or detectable */ /** * Not-a-Number (NaN) * @hideinitializer */ - CPL_VALUE_NAN = 1 << 1, + CPL_VALUE_NAN = 1 << 1, /** * Plus Infinity * @hideinitializer */ - CPL_VALUE_PLUSINF = 1 << 2, + CPL_VALUE_PLUSINF = 1 << 2, /** * Minus Infinity * @hideinitializer */ - CPL_VALUE_MINUSINF = 1 << 3, + CPL_VALUE_MINUSINF = 1 << 3, /** * Zero * @hideinitializer */ - CPL_VALUE_ZERO = 1 << 4, + CPL_VALUE_ZERO = 1 << 4, /** * Infinity with any sign * @hideinitializer */ - CPL_VALUE_INF = CPL_VALUE_PLUSINF | CPL_VALUE_MINUSINF, + CPL_VALUE_INF = CPL_VALUE_PLUSINF | CPL_VALUE_MINUSINF, /** * NaN or infinity with any sign * @hideinitializer */ - CPL_VALUE_NOTFINITE = CPL_VALUE_INF | CPL_VALUE_NAN + CPL_VALUE_NOTFINITE = CPL_VALUE_INF | CPL_VALUE_NAN }; @@ -87,7 +88,6 @@ typedef enum _cpl_value_ cpl_value; - /*----------------------------------------------------------------------------- Function prototypes -----------------------------------------------------------------------------*/ @@ -105,4 +105,4 @@ CPL_END_DECLS -#endif +#endif diff -Nru cpl-7.1.4+ds/cplcore/cpl_image_bpm_impl.h cpl-7.2.2+ds/cplcore/cpl_image_bpm_impl.h --- cpl-7.1.4+ds/cplcore/cpl_image_bpm_impl.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_image_bpm_impl.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -31,17 +31,10 @@ /*----------------------------------------------------------------------------- Function prototypes -----------------------------------------------------------------------------*/ -void cpl_image_accept_(cpl_image *, - cpl_size, - cpl_size) - CPL_ATTR_NONNULL; - -void cpl_image_reject_(cpl_image *, - cpl_size, - cpl_size) - CPL_ATTR_NONNULL; +void cpl_image_accept_(cpl_image *, cpl_size, cpl_size) CPL_ATTR_NONNULL; -CPL_END_DECLS +void cpl_image_reject_(cpl_image *, cpl_size, cpl_size) CPL_ATTR_NONNULL; -#endif +CPL_END_DECLS +#endif diff -Nru cpl-7.1.4+ds/cplcore/cpl_image_defs.h cpl-7.2.2+ds/cplcore/cpl_image_defs.h --- cpl-7.1.4+ds/cplcore/cpl_image_defs.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_image_defs.h 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -45,18 +45,18 @@ New types -----------------------------------------------------------------------------*/ -struct _cpl_image_ { +struct _cpl_image_ +{ /* Size of the image in x and y */ - cpl_size nx, ny; + cpl_size nx, ny; /* Type of the pixels used for the cpl_image */ - cpl_type type; + cpl_type type; /* Pointer to pixel buffer as a 1d buffer */ - void * pixels; + void *pixels; /* Bad Pixels mask */ - cpl_mask * bpm; + cpl_mask *bpm; }; CPL_END_DECLS #endif - diff -Nru cpl-7.1.4+ds/cplcore/cpl_image_fft.c cpl-7.2.2+ds/cplcore/cpl_image_fft.c --- cpl-7.1.4+ds/cplcore/cpl_image_fft.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_image_fft.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -50,37 +50,37 @@ -----------------------------------------------------------------------------*/ #if defined CPL_FFTWF_INSTALLED || defined CPL_FFTW_INSTALLED -static void * cpl_fft_aligned(void *, void *, size_t) CPL_ATTR_NONNULL; +static void *cpl_fft_aligned(void *, void *, size_t) CPL_ATTR_NONNULL; #endif #ifdef CPL_FFTW_INSTALLED -# define CPL_FFTW fftw +#define CPL_FFTW fftw /* Cannot concatenate the reserved macro complex :-( */ -# define CPL_FFTW_TYPE fftw_complex -# define CPL_TYPE double +#define CPL_FFTW_TYPE fftw_complex +#define CPL_TYPE double /* Cannot concatenate the reserved macro complex :-( */ -# define CPL_TYPE_C double_complex -# include "cpl_fft_body.h" -# undef CPL_FFTW -# undef CPL_TYPE -# undef CPL_TYPE_T -# undef CPL_TYPE_C -# undef CPL_FFTW_TYPE +#define CPL_TYPE_C double_complex +#include "cpl_fft_body.h" +#undef CPL_FFTW +#undef CPL_TYPE +#undef CPL_TYPE_T +#undef CPL_TYPE_C +#undef CPL_FFTW_TYPE #endif #ifdef CPL_FFTWF_INSTALLED -# define CPL_FFTW fftwf +#define CPL_FFTW fftwf /* Cannot concatenate the reserved macro complex :-( */ -# define CPL_FFTW_TYPE fftwf_complex -# define CPL_TYPE float +#define CPL_FFTW_TYPE fftwf_complex +#define CPL_TYPE float /* Cannot concatenate the reserved macro complex :-( */ -# define CPL_TYPE_C float_complex -# include "cpl_fft_body.h" -# undef CPL_FFTW -# undef CPL_TYPE -# undef CPL_TYPE_T -# undef CPL_TYPE_C -# undef CPL_FFTW_TYPE +#define CPL_TYPE_C float_complex +#include "cpl_fft_body.h" +#undef CPL_FFTW +#undef CPL_TYPE +#undef CPL_TYPE_T +#undef CPL_TYPE_C +#undef CPL_FFTW_TYPE #endif /*---------------------------------------------------------------------------*/ @@ -94,20 +94,19 @@ @see cpl_fft_image() */ /*---------------------------------------------------------------------------*/ -cpl_error_code cpl_fft_image_(cpl_image * self, const cpl_image * other, - cpl_fft_mode mode) +cpl_error_code +cpl_fft_image_(cpl_image *self, const cpl_image *other, cpl_fft_mode mode) { - /* The below pointers hold temporary storage allocated and deallocated by cpl_fft_image__(). */ - void * bufin = NULL; - void * bufout = NULL; + void *bufin = NULL; + void *bufout = NULL; return cpl_fft_image__(self, other, mode, NULL, &bufin, &bufout, CPL_TRUE) - ? cpl_error_set_where_() : CPL_ERROR_NONE; - + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } /*---------------------------------------------------------------------------*/ @@ -125,24 +124,28 @@ @see cpl_fft_image() */ /*---------------------------------------------------------------------------*/ -cpl_error_code cpl_fft_image__(cpl_image * self, const cpl_image * other, - cpl_fft_mode mode, void * pplan, - void * pbufin, void * pbufout, - cpl_boolean is_last) +cpl_error_code +cpl_fft_image__(cpl_image *self, + const cpl_image *other, + cpl_fft_mode mode, + void *pplan, + void *pbufin, + void *pbufout, + cpl_boolean is_last) { - const cpl_type typin = cpl_image_get_type(other); + const cpl_type typin = cpl_image_get_type(other); const cpl_type typout = cpl_image_get_type(self); - const cpl_size lnxin = cpl_image_get_size_x(other); - const cpl_size lnyin = cpl_image_get_size_y(other); + const cpl_size lnxin = cpl_image_get_size_x(other); + const cpl_size lnyin = cpl_image_get_size_y(other); const cpl_size lnxout = cpl_image_get_size_x(self); const cpl_size lnyout = cpl_image_get_size_y(self); - const int nxin = (int)lnxin; - const int nyin = (int)lnyin; - const int nxout = (int)lnxout; - const int nyout = (int)lnyout; - const int nxh = ((mode & CPL_FFT_FORWARD) ? nxin : nxout) / 2 + 1; + const int nxin = (int)lnxin; + const int nyin = (int)lnyin; + const int nxout = (int)lnxout; + const int nyout = (int)lnyout; + const int nxh = ((mode & CPL_FFT_FORWARD) ? nxin : nxout) / 2 + 1; cpl_error_code error; #if defined CPL_FFTWF_INSTALLED || defined CPL_FFTW_INSTALLED @@ -153,11 +156,13 @@ rigor = FFTW_EXHAUSTIVE; /* Reset bit. At the end the bitmask must be zero */ mode ^= CPL_FFT_FIND_EXHAUSTIVE; - } else if (mode & CPL_FFT_FIND_PATIENT) { + } + else if (mode & CPL_FFT_FIND_PATIENT) { rigor = FFTW_PATIENT; /* Reset bit. At the end the bitmask must be zero */ mode ^= CPL_FFT_FIND_PATIENT; - } else if (mode & CPL_FFT_FIND_MEASURE) { + } + else if (mode & CPL_FFT_FIND_MEASURE) { rigor = FFTW_MEASURE; /* Reset bit. At the end the bitmask must be zero */ mode ^= CPL_FFT_FIND_MEASURE; @@ -165,57 +170,63 @@ #endif - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(other != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(other != NULL, CPL_ERROR_NULL_INPUT); /* FFTW (only) supports dimensions that fit within an int type */ - cpl_ensure_code((cpl_size)nxin == lnxin, CPL_ERROR_UNSUPPORTED_MODE); - cpl_ensure_code((cpl_size)nyin == lnyin, CPL_ERROR_UNSUPPORTED_MODE); + cpl_ensure_code((cpl_size)nxin == lnxin, CPL_ERROR_UNSUPPORTED_MODE); + cpl_ensure_code((cpl_size)nyin == lnyin, CPL_ERROR_UNSUPPORTED_MODE); cpl_ensure_code((cpl_size)nxout == lnxout, CPL_ERROR_UNSUPPORTED_MODE); cpl_ensure_code((cpl_size)nyout == lnyout, CPL_ERROR_UNSUPPORTED_MODE); if ((mode & CPL_FFT_FORWARD) && !(typin & CPL_TYPE_COMPLEX)) { cpl_ensure_code(nxin == nxout || nxout == nxh, CPL_ERROR_INCOMPATIBLE_INPUT); - } else if ((mode & CPL_FFT_BACKWARD) && !(typout & CPL_TYPE_COMPLEX)) { + } + else if ((mode & CPL_FFT_BACKWARD) && !(typout & CPL_TYPE_COMPLEX)) { cpl_ensure_code(nxin == nxout || nxin == nxh, CPL_ERROR_INCOMPATIBLE_INPUT); - } else { - cpl_ensure_code(nxin == nxout, CPL_ERROR_INCOMPATIBLE_INPUT); } - cpl_ensure_code(lnyin == lnyout, CPL_ERROR_INCOMPATIBLE_INPUT); - - if (typin & CPL_TYPE_FLOAT) { + else { + cpl_ensure_code(nxin == nxout, CPL_ERROR_INCOMPATIBLE_INPUT); + } + cpl_ensure_code(lnyin == lnyout, CPL_ERROR_INCOMPATIBLE_INPUT); - cpl_ensure_code(typout & CPL_TYPE_FLOAT, CPL_ERROR_TYPE_MISMATCH); + if (typin & CPL_TYPE_FLOAT) { + cpl_ensure_code(typout & CPL_TYPE_FLOAT, CPL_ERROR_TYPE_MISMATCH); #ifdef CPL_FFTWF_INSTALLED - error = cpl_fft_image_float(self, other, mode, rigor, (fftwf_plan*)pplan, - (fftwf_complex**)pbufin, - (fftwf_complex**)pbufout, is_last); + error = + cpl_fft_image_float(self, other, mode, rigor, (fftwf_plan *)pplan, + (fftwf_complex **)pbufin, + (fftwf_complex **)pbufout, is_last); #else - error = CPL_ERROR_UNSUPPORTED_MODE; + error = CPL_ERROR_UNSUPPORTED_MODE; #endif - } else if (typin & CPL_TYPE_DOUBLE) { - - cpl_ensure_code(typout & CPL_TYPE_DOUBLE, CPL_ERROR_TYPE_MISMATCH); + } + else if (typin & CPL_TYPE_DOUBLE) { + cpl_ensure_code(typout & CPL_TYPE_DOUBLE, CPL_ERROR_TYPE_MISMATCH); #ifdef CPL_FFTW_INSTALLED - error = cpl_fft_image_double(self, other, mode, rigor, (fftw_plan*)pplan, - (fftw_complex**)pbufin, - (fftw_complex**)pbufout, is_last); + error = + cpl_fft_image_double(self, other, mode, rigor, (fftw_plan *)pplan, + (fftw_complex **)pbufin, + (fftw_complex **)pbufout, is_last); #else - error = CPL_ERROR_UNSUPPORTED_MODE; + error = CPL_ERROR_UNSUPPORTED_MODE; #endif - } else { - error = CPL_ERROR_TYPE_MISMATCH; - } - - /* Set or propagate error, if any */ - return cpl_error_set_message_(error, "mode=%d (%d). %d X %d (%s) => %d X" - " %d (%s)", (int)mode, (int)is_last, - nxin, nyin, cpl_type_get_name(typin), - nxout, nyout, cpl_type_get_name(typout)); + } + else { + error = CPL_ERROR_TYPE_MISMATCH; + } + + /* Set or propagate error, if any */ + return cpl_error_set_message_(error, + "mode=%d (%d). %d X %d (%s) => %d X" + " %d (%s)", + (int)mode, (int)is_last, nxin, nyin, + cpl_type_get_name(typin), nxout, nyout, + cpl_type_get_name(typout)); } /*---------------------------------------------------------------------------*/ @@ -231,36 +242,41 @@ @note Only double-type images supported... */ /*---------------------------------------------------------------------------*/ -cpl_error_code cpl_fft_image_cycle(cpl_image * self, - const cpl_image * other, - double xshift, - double yshift) +cpl_error_code +cpl_fft_image_cycle(cpl_image *self, + const cpl_image *other, + double xshift, + double yshift) { - - const cpl_size nx = cpl_image_get_size_x(self); - const cpl_size ny = cpl_image_get_size_y(self); + const cpl_size nx = cpl_image_get_size_x(self); + const cpl_size ny = cpl_image_get_size_y(self); const cpl_type type = cpl_image_get_type(self); if (nx < 1) { return cpl_error_set_where_(); - } else if (type != CPL_TYPE_DOUBLE) { + } + else if (type != CPL_TYPE_DOUBLE) { return cpl_error_set_(CPL_ERROR_UNSUPPORTED_MODE); - } else if (other != NULL && type != cpl_image_get_type(other)) { + } + else if (other != NULL && type != cpl_image_get_type(other)) { return cpl_error_set_(CPL_ERROR_INCOMPATIBLE_INPUT); - } else if (other != NULL && nx != cpl_image_get_size_x(other)) { + } + else if (other != NULL && nx != cpl_image_get_size_x(other)) { return cpl_error_set_(CPL_ERROR_INCOMPATIBLE_INPUT); - } else if (other != NULL && ny != cpl_image_get_size_y(other)) { + } + else if (other != NULL && ny != cpl_image_get_size_y(other)) { return cpl_error_set_(CPL_ERROR_INCOMPATIBLE_INPUT); - } else { + } + else { /* FIXME: Use 1D-FFT to handle special case of zero-valued x/y-shift */ /* With R2C & C2R: only half the columns */ - const cpl_size nh = nx / 2 + 1; - const double nxy = (double)(nx * ny); - double complex * pfft = - (double complex*)cpl_malloc(nh * ny * sizeof(*pfft)); - cpl_image* imgfft = cpl_image_wrap_double_complex(nh, ny, pfft); - const cpl_image* imguse = other ? other : self; + const cpl_size nh = nx / 2 + 1; + const double nxy = (double)(nx * ny); + double complex *pfft = + (double complex *)cpl_malloc(nh * ny * sizeof(*pfft)); + cpl_image *imgfft = cpl_image_wrap_double_complex(nh, ny, pfft); + const cpl_image *imguse = other ? other : self; cpl_error_code code; code = cpl_fft_image_(imgfft, imguse, CPL_FFT_FORWARD); @@ -268,14 +284,16 @@ assert(!code); for (size_t j = 0; j < (size_t)ny; j++) { - const double yscale = (j < (size_t)(ny+1)/2 ? -(double)j - : (double)(ny - j)) * yshift / (double)ny; + const double yscale = + (j < (size_t)(ny + 1) / 2 ? -(double)j : (double)(ny - j)) * + yshift / (double)ny; for (size_t i = 0; i < (size_t)nh; i++) { - const double kx = i < (size_t)nh ? -(double)i : (double)(nx - i); + const double kx = + i < (size_t)nh ? -(double)i : (double)(nx - i); const double xyshift = yscale + kx * xshift / (double)nx; - const double complex scale - = cexp((CPL_MATH_2PI * xyshift) * I) - / nxy; /* Apply also the FFT scaling */ + const double complex scale = + cexp((CPL_MATH_2PI * xyshift) * I) / + nxy; /* Apply also the FFT scaling */ pfft[i + j * nh] *= scale; } @@ -305,7 +323,8 @@ */ /*----------------------------------------------------------------------------*/ -static void * cpl_fft_aligned(void * self, void * other, size_t align) +static void * +cpl_fft_aligned(void *self, void *other, size_t align) { #ifdef HAVE_FFTW_ALIGNMENT_OF /* FIXME: Available from FFTW 3.3.4 */ @@ -314,8 +333,8 @@ #pragma omp critical(cpl_fft_fftw) #endif { - iself = fftw_alignment_of((double*)self); - iother = fftw_alignment_of((double*)other); + iself = fftw_alignment_of((double *)self); + iother = fftw_alignment_of((double *)other); } return iself == iother ? self : other; @@ -325,7 +344,7 @@ /* Find number of zero-valued LSBs */ while (!(align & lsb) && lsb < 16) { - lsb <<=1; + lsb <<= 1; lsb |= 1; } lsb >>= 1; diff -Nru cpl-7.1.4+ds/cplcore/cpl_image_fft_impl.h cpl-7.2.2+ds/cplcore/cpl_image_fft_impl.h --- cpl-7.1.4+ds/cplcore/cpl_image_fft_impl.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_image_fft_impl.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -32,20 +32,23 @@ Function prototypes -----------------------------------------------------------------------------*/ -cpl_error_code cpl_fft_image_cycle(cpl_image *, const cpl_image *, - double, double); +cpl_error_code +cpl_fft_image_cycle(cpl_image *, const cpl_image *, double, double); cpl_error_code cpl_fft_image_(cpl_image *, const cpl_image *, cpl_fft_mode); -cpl_error_code cpl_fft_image__(cpl_image *, const cpl_image *, - cpl_fft_mode, void *, void *, void *, +cpl_error_code cpl_fft_image__(cpl_image *, + const cpl_image *, + cpl_fft_mode, + void *, + void *, + void *, cpl_boolean) #ifdef CPL_HAVE_ATTR_NONNULL - __attribute__((nonnull(5,6))) + __attribute__((nonnull(5, 6))) #endif ; CPL_END_DECLS #endif /* CPL_IMAGE_FFT_H */ - diff -Nru cpl-7.1.4+ds/cplcore/cpl_image_filter_body.h cpl-7.2.2+ds/cplcore/cpl_image_filter_body.h --- cpl-7.1.4+ds/cplcore/cpl_image_filter_body.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_image_filter_body.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -17,46 +17,78 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -static void -ADDTYPE_TWO(cpl_filter_average)(void *, const void *, cpl_size, cpl_size, - cpl_size, cpl_size, cpl_border_mode); - - -static void -ADDTYPE_TWO(cpl_filter_average_bpm)(void *, cpl_binary **, - const void *, const cpl_binary *, - cpl_size, cpl_size, cpl_size, cpl_size, - cpl_border_mode); - -static cpl_error_code -ADDTYPE_TWO(cpl_filter_average_slow)(void *, cpl_binary **, - const void *, const cpl_binary *, - const cpl_binary *, cpl_size, cpl_size, - cpl_size, cpl_size, cpl_border_mode); - -static void -ADDTYPE_TWO(cpl_filter_stdev)(void *, const void *, cpl_size, cpl_size, - cpl_size, cpl_size, cpl_border_mode); - -static cpl_error_code -ADDTYPE_TWO(cpl_filter_stdev_slow)(void *, cpl_binary **, - const void *, const cpl_binary *, - const cpl_binary *, cpl_size, cpl_size, - cpl_size, cpl_size, cpl_border_mode); - -static cpl_error_code -ADDTYPE_TWO(cpl_filter_linear_slow)(void *, cpl_binary **, - const void *, const cpl_binary *, - const double *, cpl_size, cpl_size, - cpl_boolean, - cpl_size, cpl_size, cpl_border_mode); - -static cpl_error_code -ADDTYPE_TWO(cpl_filter_morpho_slow)(void *, cpl_binary **, - const void *, const cpl_binary *, - const double *, cpl_size, cpl_size, - cpl_boolean, - cpl_size, cpl_size, cpl_border_mode); +static void ADDTYPE_TWO(cpl_filter_average)(void *, + const void *, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_border_mode); + + +static void ADDTYPE_TWO(cpl_filter_average_bpm)(void *, + cpl_binary **, + const void *, + const cpl_binary *, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_border_mode); + +static cpl_error_code ADDTYPE_TWO(cpl_filter_average_slow)(void *, + cpl_binary **, + const void *, + const cpl_binary *, + const cpl_binary *, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_border_mode); + +static void ADDTYPE_TWO(cpl_filter_stdev)(void *, + const void *, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_border_mode); + +static cpl_error_code ADDTYPE_TWO(cpl_filter_stdev_slow)(void *, + cpl_binary **, + const void *, + const cpl_binary *, + const cpl_binary *, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_border_mode); + +static cpl_error_code ADDTYPE_TWO(cpl_filter_linear_slow)(void *, + cpl_binary **, + const void *, + const cpl_binary *, + const double *, + cpl_size, + cpl_size, + cpl_boolean, + cpl_size, + cpl_size, + cpl_border_mode); + +static cpl_error_code ADDTYPE_TWO(cpl_filter_morpho_slow)(void *, + cpl_binary **, + const void *, + const cpl_binary *, + const double *, + cpl_size, + cpl_size, + cpl_boolean, + cpl_size, + cpl_size, + cpl_border_mode); #ifndef CPL_FILTER_NO_RECIPROCAL #ifndef ACCU_TYPE_IS_INT @@ -65,7 +97,7 @@ #endif #ifdef ALLOW_RECIPROCAL - /* If possible, and in order to speed-up the code, the central part of +/* If possible, and in order to speed-up the code, the central part of averaged image is done with multiplication instead of division, incurring one extra round-off */ #define RUNSUM_MEAN (runsum * rnpix) @@ -85,19 +117,24 @@ /* Start of no-cast code */ -static cpl_error_code ADDTYPE(cpl_filter_median_slow)(void *, cpl_binary **, +static cpl_error_code ADDTYPE(cpl_filter_median_slow)(void *, + cpl_binary **, const void *, const cpl_binary *, const cpl_binary *, - cpl_size, cpl_size, - cpl_size, cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_size, cpl_border_mode); #ifndef CPL_MEDIAN_SAMPLE -static void -ADDTYPE(cpl_filter_median_even)(void *, const void *, - cpl_size, cpl_size, - cpl_size, cpl_size) CPL_ATTR_NONNULL; +static void ADDTYPE(cpl_filter_median_even)(void *, + const void *, + cpl_size, + cpl_size, + cpl_size, + cpl_size) CPL_ATTR_NONNULL; /*----------------------------------------------------------------------------*/ /** @@ -128,37 +165,39 @@ */ /*----------------------------------------------------------------------------*/ -static void ADDTYPE(cpl_filter_median_even)(void * vout, const void * vin, - cpl_size nx, cpl_size ny, - cpl_size rx, cpl_size ry) +static void ADDTYPE(cpl_filter_median_even)(void *vout, + const void *vin, + cpl_size nx, + cpl_size ny, + cpl_size rx, + cpl_size ry) { - - OUT_TYPE * out = (OUT_TYPE*)vout; - const IN_TYPE * in = (const IN_TYPE*)vin; + OUT_TYPE *out = (OUT_TYPE *)vout; + const IN_TYPE *in = (const IN_TYPE *)vin; IN_TYPE window[(2 * rx + 1) * (2 * ry + 1)]; - cpl_size x, y; + cpl_size x, y; /* FIXME: Create 4 shorter loops... ? */ for (y = 0; y < ny; y++) { - const size_t y_1 = CX_MAX(0, y - ry); - const size_t y2 = CX_MIN(ny-1, y + ry); + const size_t y_1 = CX_MAX(0, y - ry); + const size_t y2 = CX_MIN(ny - 1, y + ry); for (x = 0; x < nx; x++) { - const size_t x1 = CX_MAX(0, x - rx); - const size_t x2 = CX_MIN(nx-1, x + rx); + const size_t x1 = CX_MAX(0, x - rx); + const size_t x2 = CX_MIN(nx - 1, x + rx); if (((2 * ry - (y2 - y_1)) & 1) != 0 || - ((2 * rx - (x2 - x1 )) & 1) != 0) { + ((2 * rx - (x2 - x1)) & 1) != 0) { /* The pixel position has an even number of samples */ - const IN_TYPE * inj = in + y_1 * nx; + const IN_TYPE *inj = in + y_1 * nx; size_t j, k = 0; for (j = y_1; j < 1 + y2; j++, inj += nx, k += 1 + x2 - x1) { (void)memcpy(window + k, inj + x1, (1 + x2 - x1) * sizeof(IN_TYPE)); } - assert( k % 2 == 0); + assert(k % 2 == 0); out[x + y * nx] = ADDTYPE(cpl_tools_get_median)(window, k); } @@ -185,47 +224,49 @@ */ /*----------------------------------------------------------------------------*/ -static cpl_error_code -ADDTYPE(cpl_filter_median_slow)(void * vout, cpl_binary ** ppbpm, - const void * vin, - const cpl_binary * bpm, - const cpl_binary * pmask, - cpl_size nx, cpl_size ny, - cpl_size rx, cpl_size ry, - cpl_border_mode mode) +static cpl_error_code ADDTYPE(cpl_filter_median_slow)(void *vout, + cpl_binary **ppbpm, + const void *vin, + const cpl_binary *bpm, + const cpl_binary *pmask, + cpl_size nx, + cpl_size ny, + cpl_size rx, + cpl_size ry, + cpl_border_mode mode) { - if (mode == CPL_BORDER_FILTER) { - OUT_TYPE * out = (OUT_TYPE*)vout; - const IN_TYPE * in = (const IN_TYPE*)vin; + OUT_TYPE *out = (OUT_TYPE *)vout; + const IN_TYPE *in = (const IN_TYPE *)vin; IN_TYPE window[(2 * rx + 1) * (2 * ry + 1)]; - cpl_size x, y; + cpl_size x, y; for (y = 0; y < ny; y++) { - const size_t y_1 = CX_MAX(0, y - ry); - const size_t y2 = CX_MIN(ny-1, y + ry); + const size_t y_1 = CX_MAX(0, y - ry); + const size_t y2 = CX_MIN(ny - 1, y + ry); for (x = 0; x < nx; x++) { - const size_t x1 = CX_MAX(0, x - rx); - const size_t x2 = CX_MIN(nx-1, x + rx); - const IN_TYPE * inj = in + y_1 * nx; - const cpl_binary * pmaskj = pmask - + (rx - x) + ((ry - y) + y_1) * (2 * rx + 1); + const size_t x1 = CX_MAX(0, x - rx); + const size_t x2 = CX_MIN(nx - 1, x + rx); + const IN_TYPE *inj = in + y_1 * nx; + const cpl_binary *pmaskj = + pmask + (rx - x) + ((ry - y) + y_1) * (2 * rx + 1); size_t k = 0; size_t i, j; if (bpm == NULL) { - for (j = y_1; j < 1 + y2; j++, inj += nx, - pmaskj += 2 * rx + 1) { + for (j = y_1; j < 1 + y2; + j++, inj += nx, pmaskj += 2 * rx + 1) { for (i = x1; i < 1 + x2; i++) { if (pmaskj[i]) window[k++] = inj[i]; } } - } else { - const cpl_binary * bpmj = bpm + y_1 * nx; + } + else { + const cpl_binary *bpmj = bpm + y_1 * nx; - for (j = y_1; j < 1 + y2; j++, inj += nx, bpmj += nx, - pmaskj += 2 * rx + 1) { + for (j = y_1; j < 1 + y2; + j++, inj += nx, bpmj += nx, pmaskj += 2 * rx + 1) { for (i = x1; i < 1 + x2; i++) { if (!bpmj[i] && pmaskj[i]) window[k++] = inj[i]; @@ -234,7 +275,8 @@ } if (k > 0) { out[x + y * nx] = ADDTYPE(cpl_tools_get_median)(window, k); - } else { + } + else { /* Flag as bad - and set to zero */ if (*ppbpm == NULL) { *ppbpm = cpl_calloc((size_t)nx * (size_t)ny, @@ -245,14 +287,15 @@ } } } - } else if (mode == CPL_BORDER_NOP || mode == CPL_BORDER_COPY || - mode == CPL_BORDER_CROP) { - OUT_TYPE * out = (OUT_TYPE*)vout; - const IN_TYPE * in = (const IN_TYPE*)vin; + } + else if (mode == CPL_BORDER_NOP || mode == CPL_BORDER_COPY || + mode == CPL_BORDER_CROP) { + OUT_TYPE *out = (OUT_TYPE *)vout; + const IN_TYPE *in = (const IN_TYPE *)vin; IN_TYPE window[(2 * rx + 1) * (2 * ry + 1)]; - cpl_size x, y; - cpl_size nxo = mode == CPL_BORDER_CROP ? nx - 2 * rx : nx; - cpl_size nyo = mode == CPL_BORDER_CROP ? ny - 2 * ry : ny; + cpl_size x, y; + cpl_size nxo = mode == CPL_BORDER_CROP ? nx - 2 * rx : nx; + cpl_size nyo = mode == CPL_BORDER_CROP ? ny - 2 * ry : ny; if (mode == CPL_BORDER_COPY) { /* Copy the first ry row(s) and @@ -262,32 +305,33 @@ for (y = ry; y < ny - ry; y++) { const size_t y_1 = y - ry; - const size_t y2 = y + ry; + const size_t y2 = y + ry; const size_t yo = mode == CPL_BORDER_CROP ? y_1 : (size_t)y; for (x = rx; x < nx - rx; x++) { - const size_t x1 = x - rx; - const size_t x2 = x + rx; - const size_t xo = mode == CPL_BORDER_CROP ? x1 : (size_t)x; - const IN_TYPE * inj = in + y_1 * nx; - const cpl_binary * pmaskj = pmask - + (rx - x) + ((ry - y) + y_1) * (2 * rx + 1); + const size_t x1 = x - rx; + const size_t x2 = x + rx; + const size_t xo = mode == CPL_BORDER_CROP ? x1 : (size_t)x; + const IN_TYPE *inj = in + y_1 * nx; + const cpl_binary *pmaskj = + pmask + (rx - x) + ((ry - y) + y_1) * (2 * rx + 1); size_t k = 0; size_t i, j; if (bpm == NULL) { - for (j = y_1; j < 1 + y2; j++, inj += nx, - pmaskj += 2 * rx + 1) { + for (j = y_1; j < 1 + y2; + j++, inj += nx, pmaskj += 2 * rx + 1) { for (i = x1; i < 1 + x2; i++) { if (pmaskj[i]) window[k++] = inj[i]; } } - } else { - const cpl_binary * bpmj = bpm + y_1 * nx; + } + else { + const cpl_binary *bpmj = bpm + y_1 * nx; - for (j = y_1; j < 1 + y2; j++, inj += nx, bpmj += nx, - pmaskj += 2 * rx + 1) { + for (j = y_1; j < 1 + y2; + j++, inj += nx, bpmj += nx, pmaskj += 2 * rx + 1) { for (i = x1; i < 1 + x2; i++) { if (!bpmj[i] && pmaskj[i]) window[k++] = inj[i]; @@ -297,7 +341,8 @@ if (k > 0) { out[xo + yo * nxo] = ADDTYPE(cpl_tools_get_median)(window, k); - } else { + } + else { /* Flag as bad - and set to zero */ if (*ppbpm == NULL) { *ppbpm = cpl_calloc((size_t)nxo * (size_t)nyo, @@ -324,7 +369,8 @@ in + (size_t)(nx * y - rx), (size_t)(nx * ry + rx) * sizeof(*out)); } - } else { + } + else { /* FIXME: Support more modes ? */ return cpl_error_set_(CPL_ERROR_UNSUPPORTED_MODE); } @@ -356,29 +402,31 @@ */ /*----------------------------------------------------------------------------*/ static cpl_error_code -ADDTYPE_TWO(cpl_filter_average_slow)(void * vout, cpl_binary ** ppbpm, - const void * vin, - const cpl_binary * bpm, - const cpl_binary * pmask, - cpl_size nx, cpl_size ny, - cpl_size rx, cpl_size ry, - cpl_border_mode mode) + ADDTYPE_TWO(cpl_filter_average_slow)(void *vout, + cpl_binary **ppbpm, + const void *vin, + const cpl_binary *bpm, + const cpl_binary *pmask, + cpl_size nx, + cpl_size ny, + cpl_size rx, + cpl_size ry, + cpl_border_mode mode) { - if (mode == CPL_BORDER_FILTER) { - OUT_TYPE * out = (OUT_TYPE*)vout; - const IN_TYPE * in = (const IN_TYPE*)vin; - cpl_size x, y; + OUT_TYPE *out = (OUT_TYPE *)vout; + const IN_TYPE *in = (const IN_TYPE *)vin; + cpl_size x, y; for (y = 0; y < ny; y++) { - const size_t y_1 = (size_t)CX_MAX(0, y - ry); - const size_t y2 = (size_t)CX_MIN(ny-1, y + ry); + const size_t y_1 = (size_t)CX_MAX(0, y - ry); + const size_t y2 = (size_t)CX_MIN(ny - 1, y + ry); for (x = 0; x < nx; x++) { - const size_t x1 = (size_t)CX_MAX(0, x - rx); - const size_t x2 = (size_t)CX_MIN(nx-1, x + rx); - const IN_TYPE * inj = in + y_1 * nx; - const cpl_binary * pmaskj = pmask - + (rx - x) + ((ry - y) + y_1) * (2 * rx + 1); + const size_t x1 = (size_t)CX_MAX(0, x - rx); + const size_t x2 = (size_t)CX_MIN(nx - 1, x + rx); + const IN_TYPE *inj = in + y_1 * nx; + const cpl_binary *pmaskj = + pmask + (rx - x) + ((ry - y) + y_1) * (2 * rx + 1); ACCU_TYPE meansum = (ACCU_TYPE)0; /* Sum for int else mean */ size_t k = 0; @@ -386,8 +434,8 @@ if (bpm == NULL) { - for (j = y_1; j < 1 + y2; j++, inj += nx, - pmaskj += 2 * rx + 1) { + for (j = y_1; j < 1 + y2; + j++, inj += nx, pmaskj += 2 * rx + 1) { for (i = x1; i < 1 + x2; i++) { if (pmaskj[i]) { #if defined ACCU_TYPE_IS_INT || !defined CPL_FILTER_AVERAGE_SLOW @@ -403,11 +451,12 @@ } } } - } else { - const cpl_binary * bpmj = bpm + y_1 * nx; + } + else { + const cpl_binary *bpmj = bpm + y_1 * nx; - for (j = y_1; j < 1 + y2; j++, inj += nx, bpmj += nx, - pmaskj += 2 * rx + 1) { + for (j = y_1; j < 1 + y2; + j++, inj += nx, bpmj += nx, pmaskj += 2 * rx + 1) { for (i = x1; i < 1 + x2; i++) { if (!bpmj[i] && pmaskj[i]) { #if defined ACCU_TYPE_IS_INT || !defined CPL_FILTER_AVERAGE_SLOW @@ -428,7 +477,8 @@ #if defined ACCU_TYPE_IS_INT || !defined CPL_FILTER_AVERAGE_SLOW meansum /= (ACCU_TYPE)k; #endif - } else { + } + else { /* Flag as bad - and set to zero */ if (*ppbpm == NULL) { *ppbpm = cpl_calloc((size_t)nx * (size_t)ny, @@ -439,7 +489,8 @@ out[x + y * nx] = (OUT_TYPE)meansum; } } - } else { + } + else { /* FIXME: Support more modes ? */ return cpl_error_set_(CPL_ERROR_UNSUPPORTED_MODE); } @@ -468,29 +519,31 @@ */ /*----------------------------------------------------------------------------*/ static cpl_error_code -ADDTYPE_TWO(cpl_filter_stdev_slow)(void * vout, cpl_binary ** ppbpm, - const void * vin, - const cpl_binary * bpm, - const cpl_binary * pmask, - cpl_size nx, cpl_size ny, - cpl_size rx, cpl_size ry, - cpl_border_mode mode) + ADDTYPE_TWO(cpl_filter_stdev_slow)(void *vout, + cpl_binary **ppbpm, + const void *vin, + const cpl_binary *bpm, + const cpl_binary *pmask, + cpl_size nx, + cpl_size ny, + cpl_size rx, + cpl_size ry, + cpl_border_mode mode) { - if (mode == CPL_BORDER_FILTER) { - OUT_TYPE * out = (OUT_TYPE*)vout; - const IN_TYPE * in = (const IN_TYPE*)vin; - cpl_size x, y; + OUT_TYPE *out = (OUT_TYPE *)vout; + const IN_TYPE *in = (const IN_TYPE *)vin; + cpl_size x, y; for (y = 0; y < ny; y++) { - const size_t y_1 = CX_MAX(0, y - ry); - const size_t y2 = CX_MIN(ny-1, y + ry); + const size_t y_1 = CX_MAX(0, y - ry); + const size_t y2 = CX_MIN(ny - 1, y + ry); for (x = 0; x < nx; x++) { - const size_t x1 = CX_MAX(0, x - rx); - const size_t x2 = CX_MIN(nx-1, x + rx); - const IN_TYPE * inj = in + y_1 * nx; - const cpl_binary * pmaskj = pmask - + (rx - x) + ((ry - y) + y_1) * (2 * rx + 1); + const size_t x1 = CX_MAX(0, x - rx); + const size_t x2 = CX_MIN(nx - 1, x + rx); + const IN_TYPE *inj = in + y_1 * nx; + const cpl_binary *pmaskj = + pmask + (rx - x) + ((ry - y) + y_1) * (2 * rx + 1); ACCU_FLOATTYPE varsum = 0.0; ACCU_FLOATTYPE mean = 0.0; @@ -498,31 +551,32 @@ size_t i, j; if (bpm == NULL) { - for (j = y_1; j < 1 + y2; j++, inj += nx, - pmaskj += 2 * rx + 1) { + for (j = y_1; j < 1 + y2; + j++, inj += nx, pmaskj += 2 * rx + 1) { for (i = x1; i < 1 + x2; i++) { if (pmaskj[i]) { - const ACCU_FLOATTYPE delta - = (ACCU_FLOATTYPE)inj[i] - mean; + const ACCU_FLOATTYPE delta = + (ACCU_FLOATTYPE)inj[i] - mean; varsum += k * delta * delta / (k + 1.0); - mean += delta / (k + 1.0); + mean += delta / (k + 1.0); k += 1.0; } } } - } else { - const cpl_binary * bpmj = bpm + y_1 * nx; + } + else { + const cpl_binary *bpmj = bpm + y_1 * nx; - for (j = y_1; j < 1 + y2; j++, inj += nx, bpmj += nx, - pmaskj += 2 * rx + 1) { + for (j = y_1; j < 1 + y2; + j++, inj += nx, bpmj += nx, pmaskj += 2 * rx + 1) { for (i = x1; i < 1 + x2; i++) { if (!bpmj[i] && pmaskj[i]) { - const ACCU_FLOATTYPE delta - = (ACCU_FLOATTYPE)inj[i] - mean; + const ACCU_FLOATTYPE delta = + (ACCU_FLOATTYPE)inj[i] - mean; varsum += k * delta * delta / (k + 1.0); - mean += delta / (k + 1.0); + mean += delta / (k + 1.0); k += 1.0; } } @@ -530,7 +584,8 @@ } if (k > 1) { out[x + y * nx] = (OUT_TYPE)sqrt(varsum / (k - 1.0)); - } else { + } + else { /* Flag as bad - and set to zero */ if (*ppbpm == NULL) { *ppbpm = cpl_calloc((size_t)nx * (size_t)ny, @@ -541,7 +596,8 @@ } } } - } else { + } + else { /* FIXME: Support more modes ? */ return cpl_error_set_(CPL_ERROR_UNSUPPORTED_MODE); } @@ -565,19 +621,19 @@ */ /*----------------------------------------------------------------------------*/ -static void -ADDTYPE_TWO(cpl_filter_stdev)(void * vout, - const void * vin, - cpl_size nx, cpl_size ny, - cpl_size hsizex, cpl_size hsizey, - cpl_border_mode border_mode) +static void ADDTYPE_TWO(cpl_filter_stdev)(void *vout, + const void *vin, + cpl_size nx, + cpl_size ny, + cpl_size hsizex, + cpl_size hsizey, + cpl_border_mode border_mode) { + OUT_TYPE *out = (OUT_TYPE *)vout; + const IN_TYPE *in = (const IN_TYPE *)vin; - OUT_TYPE * out = (OUT_TYPE*)vout; - const IN_TYPE * in = (const IN_TYPE*)vin; - - double * colvarsum; - double * colmean; + double *colvarsum; + double *colmean; cpl_size npix, npixy; cpl_size x, y, i; @@ -586,195 +642,185 @@ assert(out != NULL); assert(in != NULL); - assert( hsizex >= 0 ); - assert( hsizey >= 0 ); - assert( 2*hsizex < nx ); /* Caller does not (need to) support this */ - assert( 2*hsizey < ny ); /* Caller does not (need to) support this */ + assert(hsizex >= 0); + assert(hsizey >= 0); + assert(2 * hsizex < nx); /* Caller does not (need to) support this */ + assert(2 * hsizey < ny); /* Caller does not (need to) support this */ - assert( hsizex > 0 || hsizey > 0); + assert(hsizex > 0 || hsizey > 0); /* FIXME: Support more modes ? */ - assert( border_mode == CPL_BORDER_FILTER ); + assert(border_mode == CPL_BORDER_FILTER); /* The number of pixels prior to the first stdev */ npixy = hsizey; - npix = (1+hsizex) * npixy; + npix = (1 + hsizex) * npixy; /* Initialize the column sums */ colvarsum = cpl_calloc((size_t)nx, sizeof(double)); - colmean = cpl_calloc((size_t)nx, sizeof(double)); + colmean = cpl_calloc((size_t)nx, sizeof(double)); npixcol = 0.0; - for (y=0; y < hsizey; y++) { - for (i=0; i < nx; i++) { + for (y = 0; y < hsizey; y++) { + for (i = 0; i < nx; i++) { const double delta = (double)in[i + y * nx] - colmean[i]; colvarsum[i] += npixcol / (npixcol + 1.0) * delta * delta; - colmean[i] += delta / (npixcol + 1.0); + colmean[i] += delta / (npixcol + 1.0); } npixcol += 1.0; } - + /* Loop over all the first rows, that cannot be covered by the kernel */ for (y = 0; y < 1 + hsizey; y++) { - double runvarsum = (double)0; - double runmean = (double)0; + double runmean = (double)0; - npixy ++; + npixy++; npix = (hsizex)*npixy; - - ncol = 0.0; - for (x = 0; x < 1; x ++) { + ncol = 0.0; + for (x = 0; x < 1; x++) { /* Update the first 1 + hsizex column sums */ - for (i = 0; i < 1 + hsizex; i ++) { - const double delta = + for (i = 0; i < 1 + hsizex; i++) { + const double delta = (double)in[i + (y + hsizey) * nx] - colmean[i]; double rundelta; - + colvarsum[i] += npixcol / (npixcol + 1.0) * delta * delta; - colmean[i] += delta / (npixcol + 1.0); + colmean[i] += delta / (npixcol + 1.0); rundelta = colmean[i] - runmean; - runvarsum += - colvarsum[i] + ncol / (ncol + 1.0) * (npixcol + 1.0) * - rundelta * rundelta; - runmean += rundelta / (ncol + 1.0); - + runvarsum += colvarsum[i] + ncol / (ncol + 1.0) * + (npixcol + 1.0) * rundelta * + rundelta; + runmean += rundelta / (ncol + 1.0); + ncol += 1.0; } npix += npixy; - out[x + y * nx] = (OUT_TYPE)sqrt(runvarsum/(double)(npix - 1)); + out[x + y * nx] = (OUT_TYPE)sqrt(runvarsum / (double)(npix - 1)); } - for (; x < 1 + hsizex; x ++) { - const double delta = - (double)in[x + hsizex + (y + hsizey) * nx] - - colmean[x + hsizex]; + for (; x < 1 + hsizex; x++) { + const double delta = (double)in[x + hsizex + (y + hsizey) * nx] - + colmean[x + hsizex]; double rundelta; - + colvarsum[x + hsizex] += npixcol / (npixcol + 1.0) * delta * delta; - colmean[x + hsizex] += delta / (npixcol + 1.0); + colmean[x + hsizex] += delta / (npixcol + 1.0); rundelta = colmean[x + hsizex] - runmean; - runvarsum += - colvarsum[x + hsizex] + ncol / (ncol + 1.0) * (npixcol + 1.0) * - rundelta * rundelta; - runmean += rundelta / (ncol + 1.0); + runvarsum += colvarsum[x + hsizex] + ncol / (ncol + 1.0) * + (npixcol + 1.0) * + rundelta * rundelta; + runmean += rundelta / (ncol + 1.0); ncol += 1.0; npix += npixy; - out[x + y * nx] = (OUT_TYPE)sqrt(runvarsum/(double)(npix - 1)); + out[x + y * nx] = (OUT_TYPE)sqrt(runvarsum / (double)(npix - 1)); } - for (; x < nx-hsizex; x ++) { - const double delta = - (double)in[x + hsizex + (y + hsizey) * nx] - - colmean[x + hsizex]; + for (; x < nx - hsizex; x++) { + const double delta = (double)in[x + hsizex + (y + hsizey) * nx] - + colmean[x + hsizex]; double rundelta; - + colvarsum[x + hsizex] += npixcol / (npixcol + 1.0) * delta * delta; - colmean[x + hsizex] += delta / (npixcol + 1.0); + colmean[x + hsizex] += delta / (npixcol + 1.0); if (ncol > 1.0) { rundelta = colmean[x - hsizex - 1] - runmean; - runvarsum -= - colvarsum[x - hsizex - 1] + - ncol / (ncol - 1.0) * (npixcol + 1.0) * - rundelta * rundelta; - runmean -= rundelta / (ncol - 1.0); + runvarsum -= + colvarsum[x - hsizex - 1] + + ncol / (ncol - 1.0) * (npixcol + 1.0) * rundelta * rundelta; + runmean -= rundelta / (ncol - 1.0); rundelta = colmean[x + hsizex] - runmean; - runvarsum += - colvarsum[x + hsizex] + - (ncol - 1.0) / ncol * (npixcol + 1.0) * - rundelta * rundelta; - runmean += rundelta / ncol; - } else { + runvarsum += colvarsum[x + hsizex] + (ncol - 1.0) / ncol * + (npixcol + 1.0) * + rundelta * rundelta; + runmean += rundelta / ncol; + } + else { runvarsum = colvarsum[x + hsizex]; } - out[x + y * nx] = (OUT_TYPE)sqrt(runvarsum/(double)(npix - 1)); + out[x + y * nx] = (OUT_TYPE)sqrt(runvarsum / (double)(npix - 1)); } for (; x < nx; x++) { const double rundelta = colmean[x - hsizex - 1] - runmean; - runvarsum -= - colvarsum[x - hsizex - 1] + - ncol / (ncol - 1.0) * (npixcol + 1.0) * - rundelta * rundelta; - runmean -= rundelta / (ncol - 1.0); + runvarsum -= colvarsum[x - hsizex - 1] + ncol / (ncol - 1.0) * + (npixcol + 1.0) * + rundelta * rundelta; + runmean -= rundelta / (ncol - 1.0); ncol -= 1.0; npix -= npixy; - out[x + y * nx] = (OUT_TYPE)sqrt(runvarsum/(double)(npix - 1)); + out[x + y * nx] = (OUT_TYPE)sqrt(runvarsum / (double)(npix - 1)); } npixcol += 1.0; } /* Loop over the central rows */ - for (;y < ny-hsizey; y++) { - + for (; y < ny - hsizey; y++) { double runvarsum = (double)0; - double runmean = (double)0; + double runmean = (double)0; npix = (hsizex)*npixy; ncol = 0.0; for (x = 0; x < 1; x++) { - /* Update the first 1 + hsizex column sums */ - for (i = 0; i < 1 + hsizex; i ++) { + for (i = 0; i < 1 + hsizex; i++) { double delta; double rundelta; if (npixcol > 1.0) { delta = (double)in[i + (y - hsizey - 1) * nx] - colmean[i]; - - colvarsum[i] -= - npixcol / (npixcol - 1.0) * delta * delta; - colmean[i] -= delta / (npixcol - 1.0); + + colvarsum[i] -= npixcol / (npixcol - 1.0) * delta * delta; + colmean[i] -= delta / (npixcol - 1.0); delta = (double)in[i + (y + hsizey) * nx] - colmean[i]; - - colvarsum[i] += - (npixcol - 1.0) / npixcol * delta * delta; - colmean[i] += delta / npixcol; - } else { + + colvarsum[i] += (npixcol - 1.0) / npixcol * delta * delta; + colmean[i] += delta / npixcol; + } + else { colvarsum[i] = 0.0; - colmean[i] = (double)in[i + (y + hsizey) * nx]; + colmean[i] = (double)in[i + (y + hsizey) * nx]; } rundelta = colmean[i] - runmean; - runvarsum += - colvarsum[i] + ncol / (ncol + 1.0) * npixcol * - rundelta * rundelta; - runmean += rundelta / (ncol + 1.0); - + runvarsum += colvarsum[i] + ncol / (ncol + 1.0) * npixcol * + rundelta * rundelta; + runmean += rundelta / (ncol + 1.0); + ncol += 1.0; } npix += npixy; - out[x + y * nx] = (OUT_TYPE)sqrt(runvarsum/(double)(npix - 1)); + out[x + y * nx] = (OUT_TYPE)sqrt(runvarsum / (double)(npix - 1)); } for (; x < 1 + hsizex; x++) { @@ -782,208 +828,201 @@ double rundelta; if (npixcol > 1.0) { - delta = - (double)in[x + hsizex + (y - hsizey - 1) * nx] - - colmean[x + hsizex]; - - colvarsum[x + hsizex] -= + delta = (double)in[x + hsizex + (y - hsizey - 1) * nx] - + colmean[x + hsizex]; + + colvarsum[x + hsizex] -= npixcol / (npixcol - 1.0) * delta * delta; - colmean[x + hsizex] -= delta / (npixcol - 1.0); + colmean[x + hsizex] -= delta / (npixcol - 1.0); + + delta = (double)in[x + hsizex + (y + hsizey) * nx] - + colmean[x + hsizex]; - delta = - (double)in[x + hsizex + (y + hsizey) * nx] - - colmean[x + hsizex]; - - colvarsum[x + hsizex] += + colvarsum[x + hsizex] += (npixcol - 1.0) / npixcol * delta * delta; - colmean[x + hsizex] += delta / npixcol; - } else { + colmean[x + hsizex] += delta / npixcol; + } + else { colvarsum[x + hsizex] = 0.0; - colmean[x + hsizex] = + colmean[x + hsizex] = (double)in[x + hsizex + (y + hsizey) * nx]; } rundelta = colmean[x + hsizex] - runmean; - runvarsum += - colvarsum[x + hsizex] + ncol / (ncol + 1.0) * npixcol * - rundelta * rundelta; - runmean += rundelta / (ncol + 1.0); + runvarsum += colvarsum[x + hsizex] + + ncol / (ncol + 1.0) * npixcol * rundelta * rundelta; + runmean += rundelta / (ncol + 1.0); ncol += 1.0; npix += npixy; - out[x + y * nx] = (OUT_TYPE)sqrt(runvarsum/(double)(npix - 1)); + out[x + y * nx] = (OUT_TYPE)sqrt(runvarsum / (double)(npix - 1)); } - - for (; x < nx-hsizex; x++) { + + for (; x < nx - hsizex; x++) { double delta; double rundelta; if (npixcol > 1.0) { - delta = - (double)in[x + hsizex + (y - hsizey - 1) * nx] - - colmean[x + hsizex]; - - colvarsum[x + hsizex] -= + delta = (double)in[x + hsizex + (y - hsizey - 1) * nx] - + colmean[x + hsizex]; + + colvarsum[x + hsizex] -= npixcol / (npixcol - 1.0) * delta * delta; - colmean[x + hsizex] -= delta / (npixcol - 1.0); + colmean[x + hsizex] -= delta / (npixcol - 1.0); + + delta = (double)in[x + hsizex + (y + hsizey) * nx] - + colmean[x + hsizex]; - delta = - (double)in[x + hsizex + (y + hsizey) * nx] - - colmean[x + hsizex]; - - colvarsum[x + hsizex] += + colvarsum[x + hsizex] += (npixcol - 1.0) / npixcol * delta * delta; - colmean[x + hsizex] += delta / npixcol; - } else { + colmean[x + hsizex] += delta / npixcol; + } + else { colvarsum[x + hsizex] = 0.0; - colmean[x + hsizex] = + colmean[x + hsizex] = (double)in[x + hsizex + (y + hsizey) * nx]; } if (ncol > 1.0) { rundelta = colmean[x - hsizex - 1] - runmean; - runvarsum -= - colvarsum[x - hsizex - 1] + + runvarsum -= + colvarsum[x - hsizex - 1] + ncol / (ncol - 1.0) * npixcol * rundelta * rundelta; - runmean -= rundelta / (ncol - 1.0); + runmean -= rundelta / (ncol - 1.0); rundelta = colmean[x + hsizex] - runmean; - runvarsum += - colvarsum[x + hsizex] + - (ncol - 1.0) / ncol * npixcol * rundelta * rundelta; - runmean += rundelta / ncol; - } else { + runvarsum += colvarsum[x + hsizex] + (ncol - 1.0) / ncol * + npixcol * rundelta * + rundelta; + runmean += rundelta / ncol; + } + else { runvarsum = colvarsum[x + hsizex]; } - out[x + y * nx] = (OUT_TYPE)sqrt(runvarsum/(double)(npix - 1)); + out[x + y * nx] = (OUT_TYPE)sqrt(runvarsum / (double)(npix - 1)); } for (; x < nx; x++) { const double rundelta = colmean[x - hsizex - 1] - runmean; - runvarsum -= - colvarsum[x - hsizex - 1] + - ncol / (ncol - 1.0) * npixcol * rundelta * rundelta; - runmean -= rundelta / (ncol - 1.0); + runvarsum -= colvarsum[x - hsizex - 1] + + ncol / (ncol - 1.0) * npixcol * rundelta * rundelta; + runmean -= rundelta / (ncol - 1.0); ncol -= 1.0; npix -= npixy; - out[x + y * nx] = (OUT_TYPE)sqrt(runvarsum/(double)(npix - 1)); + out[x + y * nx] = (OUT_TYPE)sqrt(runvarsum / (double)(npix - 1)); } } /* Loop over all the last rows, that cannot be covered by the kernel */ - for (;y < ny; y++) { - + for (; y < ny; y++) { double runvarsum = (double)0; - double runmean = (double)0; + double runmean = (double)0; - npixy --; + npixy--; npix = (hsizex)*npixy; ncol = 0.0; for (x = 0; x < 1; x++) { - /* Update the first 1 + hsizex column sums */ - for (i = 0; i < 1 + hsizex; i ++) { - const double delta = + for (i = 0; i < 1 + hsizex; i++) { + const double delta = (double)in[i + (y - hsizey - 1) * nx] - colmean[i]; double rundelta; - colvarsum[i] -= - npixcol / (npixcol - 1.0) * delta * delta; - colmean[i] -= delta / (npixcol - 1.0); + colvarsum[i] -= npixcol / (npixcol - 1.0) * delta * delta; + colmean[i] -= delta / (npixcol - 1.0); rundelta = colmean[i] - runmean; - runvarsum += - colvarsum[i] + ncol / (ncol + 1.0) * (npixcol - 1.0) * - rundelta * rundelta; - runmean += rundelta / (ncol + 1.0); + runvarsum += colvarsum[i] + ncol / (ncol + 1.0) * + (npixcol - 1.0) * rundelta * + rundelta; + runmean += rundelta / (ncol + 1.0); ncol += 1.0; } npix += npixy; - out[x + y * nx] = (OUT_TYPE)sqrt(runvarsum/(double)(npix - 1)); + out[x + y * nx] = (OUT_TYPE)sqrt(runvarsum / (double)(npix - 1)); } for (; x < 1 + hsizex; x++) { const double delta = - (double)in[x + hsizex + (y - hsizey - 1) * nx] - + (double)in[x + hsizex + (y - hsizey - 1) * nx] - colmean[x + hsizex]; double rundelta; - - colvarsum[x + hsizex] -= - npixcol / (npixcol - 1.0) * delta * delta; - colmean[x + hsizex] -= delta / (npixcol - 1.0); + + colvarsum[x + hsizex] -= npixcol / (npixcol - 1.0) * delta * delta; + colmean[x + hsizex] -= delta / (npixcol - 1.0); rundelta = colmean[x + hsizex] - runmean; - runvarsum += - colvarsum[x + hsizex] + ncol / (ncol + 1.0) * (npixcol - 1.0) * - rundelta * rundelta; - runmean += rundelta / (ncol + 1.0); + runvarsum += colvarsum[x + hsizex] + ncol / (ncol + 1.0) * + (npixcol - 1.0) * + rundelta * rundelta; + runmean += rundelta / (ncol + 1.0); npix += npixy; ncol += 1.0; - out[x + y * nx] = (OUT_TYPE)sqrt(runvarsum/(double)(npix - 1)); + out[x + y * nx] = (OUT_TYPE)sqrt(runvarsum / (double)(npix - 1)); } - - for (; x < nx-hsizex; x++) { + + for (; x < nx - hsizex; x++) { const double delta = - (double)in[x + hsizex + (y - hsizey - 1) * nx] - + (double)in[x + hsizex + (y - hsizey - 1) * nx] - colmean[x + hsizex]; double rundelta; - - colvarsum[x + hsizex] -= - npixcol / (npixcol - 1.0) * delta * delta; - colmean[x + hsizex] -= delta / (npixcol - 1.0); + + colvarsum[x + hsizex] -= npixcol / (npixcol - 1.0) * delta * delta; + colmean[x + hsizex] -= delta / (npixcol - 1.0); if (ncol > 1.0) { rundelta = colmean[x - hsizex - 1] - runmean; - runvarsum -= - colvarsum[x - hsizex - 1] + + runvarsum -= + colvarsum[x - hsizex - 1] + ncol / (ncol - 1.0) * (npixcol - 1.0) * rundelta * rundelta; - runmean -= rundelta / (ncol - 1.0); + runmean -= rundelta / (ncol - 1.0); rundelta = colmean[x + hsizex] - runmean; - runvarsum += - colvarsum[x + hsizex] + - (ncol - 1.0) / ncol * (npixcol - 1.0) * rundelta * rundelta; - runmean += rundelta / ncol; - } else { + runvarsum += colvarsum[x + hsizex] + (ncol - 1.0) / ncol * + (npixcol - 1.0) * + rundelta * rundelta; + runmean += rundelta / ncol; + } + else { runvarsum = colvarsum[x + hsizex]; } - out[x + y * nx] = (OUT_TYPE)sqrt(runvarsum/(double)(npix - 1)); + out[x + y * nx] = (OUT_TYPE)sqrt(runvarsum / (double)(npix - 1)); } for (; x < nx; x++) { const double rundelta = colmean[x - hsizex - 1] - runmean; - runvarsum -= - colvarsum[x - hsizex - 1] + - ncol / (ncol - 1.0) * (npixcol - 1.0) * rundelta * rundelta; - runmean -= rundelta / (ncol - 1.0); + runvarsum -= colvarsum[x - hsizex - 1] + ncol / (ncol - 1.0) * + (npixcol - 1.0) * + rundelta * rundelta; + runmean -= rundelta / (ncol - 1.0); ncol -= 1.0; npix -= npixy; - out[x + y * nx] = (OUT_TYPE)sqrt(runvarsum/(double)(npix - 1)); + out[x + y * nx] = (OUT_TYPE)sqrt(runvarsum / (double)(npix - 1)); } npixcol -= 1.0; @@ -993,7 +1032,6 @@ cpl_free(colmean); return; - } /*----------------------------------------------------------------------------*/ @@ -1012,70 +1050,68 @@ */ /*----------------------------------------------------------------------------*/ -static void -ADDTYPE_TWO(cpl_filter_average)(void * vout, const void * vin, - cpl_size nx, cpl_size ny, - cpl_size hsizex, cpl_size hsizey, - cpl_border_mode border_mode) +static void ADDTYPE_TWO(cpl_filter_average)(void *vout, + const void *vin, + cpl_size nx, + cpl_size ny, + cpl_size hsizex, + cpl_size hsizey, + cpl_border_mode border_mode) { + OUT_TYPE *out = (OUT_TYPE *)vout; + const IN_TYPE *in = (const IN_TYPE *)vin; - OUT_TYPE * out = (OUT_TYPE*)vout; - const IN_TYPE * in = (const IN_TYPE*)vin; - - ACCU_TYPE * colsum; + ACCU_TYPE *colsum; cpl_size npix, npixy; cpl_size x, y, i; assert(out != NULL); assert(in != NULL); - assert( hsizex >= 0 ); - assert( hsizey >= 0 ); - assert( 2*hsizex < nx ); /* Caller does not (need to) support this */ - assert( 2*hsizey < ny ); /* Caller does not (need to) support this */ + assert(hsizex >= 0); + assert(hsizey >= 0); + assert(2 * hsizex < nx); /* Caller does not (need to) support this */ + assert(2 * hsizey < ny); /* Caller does not (need to) support this */ /* FIXME: Support more modes ? */ - assert( border_mode == CPL_BORDER_FILTER ); + assert(border_mode == CPL_BORDER_FILTER); /* The number of pixels prior to the first average */ npixy = hsizey; - npix = (1+hsizex) * npixy; + npix = (1 + hsizex) * npixy; /* Initialize the column sums */ colsum = cpl_calloc((size_t)nx, sizeof(*colsum)); - for (y=0; y < hsizey; y++) { - for (i=0; i < nx; i++) { + for (y = 0; y < hsizey; y++) { + for (i = 0; i < nx; i++) { colsum[i] += in[i + y * nx]; } } /* Loop over all the first rows, that cannot be covered by the kernel */ for (y = 0; y < 1 + hsizey; y++) { - ACCU_TYPE runsum = (ACCU_TYPE)0; #ifdef ALLOW_RECIPROCAL ACCU_TYPE rnpix; #endif - npixy ++; + npixy++; npix = (hsizex)*npixy; - for (x = 0; x < 1; x ++) { - + for (x = 0; x < 1; x++) { /* Update the first 1 + hsizex column sums */ - for (i = 0; i < 1 + hsizex; i ++) { - colsum[i] += in[i + (y + hsizey) * nx]; - runsum += colsum[i]; + for (i = 0; i < 1 + hsizex; i++) { + colsum[i] += in[i + (y + hsizey) * nx]; + runsum += colsum[i]; } npix += npixy; - out[x + y * nx] = (OUT_TYPE)(runsum/(ACCU_TYPE)npix); + out[x + y * nx] = (OUT_TYPE)(runsum / (ACCU_TYPE)npix); } - for (; x < 1 + hsizex; x ++) { - + for (; x < 1 + hsizex; x++) { /* Update the new colsum */ colsum[x + hsizex] += in[x + hsizex + (y + hsizey) * nx]; @@ -1084,15 +1120,14 @@ npix += npixy; - out[x + y * nx] = (OUT_TYPE)(runsum/(ACCU_TYPE)npix); + out[x + y * nx] = (OUT_TYPE)(runsum / (ACCU_TYPE)npix); } #ifdef ALLOW_RECIPROCAL - rnpix = (ACCU_TYPE)1.0/(ACCU_TYPE)npix; + rnpix = (ACCU_TYPE)1.0 / (ACCU_TYPE)npix; #endif - for (; x < nx-hsizex; x ++) { - + for (; x < nx - hsizex; x++) { /* Update the new colsum */ colsum[x + hsizex] += in[x + hsizex + (y + hsizey) * nx]; @@ -1105,19 +1140,17 @@ } for (; x < nx; x++) { - - /* Update the running sum */ + /* Update the running sum */ runsum -= colsum[x - hsizex - 1]; npix -= npixy; - out[x + y * nx] = (OUT_TYPE)(runsum/(ACCU_TYPE)npix); + out[x + y * nx] = (OUT_TYPE)(runsum / (ACCU_TYPE)npix); } } /* Loop over the central rows */ - for (;y < ny-hsizey; y++) { - + for (; y < ny - hsizey; y++) { ACCU_TYPE runsum = (ACCU_TYPE)0; #ifdef ALLOW_RECIPROCAL @@ -1126,21 +1159,19 @@ npix = (hsizex)*npixy; for (x = 0; x < 1; x++) { - /* Update the first 1 + hsizex column sums */ - for (i = 0; i < 1 + hsizex; i ++) { - colsum[i] -= in[i + (y - hsizey - 1) * nx]; - colsum[i] += in[i + (y + hsizey) * nx]; - runsum += colsum[i]; + for (i = 0; i < 1 + hsizex; i++) { + colsum[i] -= in[i + (y - hsizey - 1) * nx]; + colsum[i] += in[i + (y + hsizey) * nx]; + runsum += colsum[i]; } npix += npixy; - out[x + y * nx] = (OUT_TYPE)(runsum/(ACCU_TYPE)npix); + out[x + y * nx] = (OUT_TYPE)(runsum / (ACCU_TYPE)npix); } for (; x < 1 + hsizex; x++) { - /* Update the new colsum */ colsum[x + hsizex] -= in[x + hsizex + (y - hsizey - 1) * nx]; colsum[x + hsizex] += in[x + hsizex + (y + hsizey) * nx]; @@ -1150,15 +1181,14 @@ npix += npixy; - out[x + y * nx] = (OUT_TYPE)(runsum/(ACCU_TYPE)npix); + out[x + y * nx] = (OUT_TYPE)(runsum / (ACCU_TYPE)npix); } #ifdef ALLOW_RECIPROCAL - rnpix = (ACCU_TYPE)1.0/(ACCU_TYPE)npix; + rnpix = (ACCU_TYPE)1.0 / (ACCU_TYPE)npix; #endif - - for (; x < nx-hsizex; x++) { + for (; x < nx - hsizex; x++) { /* Update the new colsum */ colsum[x + hsizex] -= in[x + hsizex + (y - hsizey - 1) * nx]; colsum[x + hsizex] += in[x + hsizex + (y + hsizey) * nx]; @@ -1172,43 +1202,39 @@ } for (; x < nx; x++) { - - /* Update the running sum */ + /* Update the running sum */ runsum -= colsum[x - hsizex - 1]; npix -= npixy; - out[x + y * nx] = (OUT_TYPE)(runsum/(ACCU_TYPE)npix); + out[x + y * nx] = (OUT_TYPE)(runsum / (ACCU_TYPE)npix); } } /* Loop over all the last rows, that cannot be covered by the kernel */ - for (;y < ny; y++) { - + for (; y < ny; y++) { ACCU_TYPE runsum = (ACCU_TYPE)0; #ifdef ALLOW_RECIPROCAL ACCU_TYPE rnpix; #endif - npixy --; + npixy--; npix = (hsizex)*npixy; for (x = 0; x < 1; x++) { - /* Update the first 1 + hsizex column sums */ - for (i = 0; i < 1 + hsizex; i ++) { - colsum[i] -= in[i + (y - hsizey - 1) * nx]; - runsum += colsum[i]; + for (i = 0; i < 1 + hsizex; i++) { + colsum[i] -= in[i + (y - hsizey - 1) * nx]; + runsum += colsum[i]; } npix += npixy; - out[x + y * nx] = (OUT_TYPE)(runsum/(ACCU_TYPE)npix); + out[x + y * nx] = (OUT_TYPE)(runsum / (ACCU_TYPE)npix); } for (; x < 1 + hsizex; x++) { - /* Update the new colsum */ colsum[x + hsizex] -= in[x + hsizex + (y - hsizey - 1) * nx]; @@ -1217,15 +1243,14 @@ npix += npixy; - out[x + y * nx] = (OUT_TYPE)(runsum/(ACCU_TYPE)npix); + out[x + y * nx] = (OUT_TYPE)(runsum / (ACCU_TYPE)npix); } #ifdef ALLOW_RECIPROCAL - rnpix = (ACCU_TYPE)1.0/(ACCU_TYPE)npix; + rnpix = (ACCU_TYPE)1.0 / (ACCU_TYPE)npix; #endif - - for (; x < nx-hsizex; x++) { + for (; x < nx - hsizex; x++) { /* Update the new colsum */ colsum[x + hsizex] -= in[x + hsizex + (y - hsizey - 1) * nx]; @@ -1238,20 +1263,18 @@ } for (; x < nx; x++) { - - /* Update the running sum */ + /* Update the running sum */ runsum -= colsum[x - hsizex - 1]; npix -= npixy; - out[x + y * nx] = (OUT_TYPE)(runsum/(ACCU_TYPE)npix); + out[x + y * nx] = (OUT_TYPE)(runsum / (ACCU_TYPE)npix); } } cpl_free(colsum); return; - } /*----------------------------------------------------------------------------*/ @@ -1273,18 +1296,20 @@ */ /*----------------------------------------------------------------------------*/ -static void -ADDTYPE_TWO(cpl_filter_average_bpm)(void * vout, cpl_binary ** pbpm, - const void * vin, const cpl_binary * bpm, - cpl_size nx, cpl_size ny, - cpl_size hsizex, cpl_size hsizey, - cpl_border_mode border_mode) +static void ADDTYPE_TWO(cpl_filter_average_bpm)(void *vout, + cpl_binary **pbpm, + const void *vin, + const cpl_binary *bpm, + cpl_size nx, + cpl_size ny, + cpl_size hsizex, + cpl_size hsizey, + cpl_border_mode border_mode) { - - OUT_TYPE * out = (OUT_TYPE*)vout; - const IN_TYPE * in = (const IN_TYPE*)vin; - ACCU_TYPE * colsum; - int * colpix; + OUT_TYPE *out = (OUT_TYPE *)vout; + const IN_TYPE *in = (const IN_TYPE *)vin; + ACCU_TYPE *colsum; + int *colpix; cpl_size npix; cpl_size x, y, i; @@ -1293,20 +1318,20 @@ assert(in != NULL); assert(bpm != NULL); - assert( hsizex >= 0 ); - assert( hsizey >= 0 ); - assert( 2*hsizex < nx ); /* Caller does not (need to) support this */ - assert( 2*hsizey < ny ); /* Caller does not (need to) support this */ + assert(hsizex >= 0); + assert(hsizey >= 0); + assert(2 * hsizex < nx); /* Caller does not (need to) support this */ + assert(2 * hsizey < ny); /* Caller does not (need to) support this */ /* FIXME: Support more modes ? */ - assert( border_mode == CPL_BORDER_FILTER ); + assert(border_mode == CPL_BORDER_FILTER); /* Initialize the column sums */ colsum = cpl_calloc((size_t)nx, sizeof(*colsum)); /* Initialize the counter of column elements (variable with bad pixels) */ colpix = cpl_calloc((size_t)nx, sizeof(*colsum)); - for (y=0; y < hsizey; y++) { - for (i=0; i < nx; i++) { + for (y = 0; y < hsizey; y++) { + for (i = 0; i < nx; i++) { if (!bpm[i + y * nx]) { colsum[i] += in[i + y * nx]; colpix[i]++; @@ -1316,7 +1341,6 @@ /* Loop over all the first rows, that cannot be covered by the kernel */ for (y = 0; y < 1 + hsizey; y++) { - ACCU_TYPE runsum = (ACCU_TYPE)0; #ifdef ALLOW_RECIPROCAL @@ -1325,10 +1349,9 @@ npix = 0; - for (x = 0; x < 1; x ++) { - + for (x = 0; x < 1; x++) { /* Update the first 1 + hsizex column sums */ - for (i = 0; i < 1 + hsizex; i ++) { + for (i = 0; i < 1 + hsizex; i++) { if (!bpm[i + (y + hsizey) * nx]) { colsum[i] += in[i + (y + hsizey) * nx]; runsum += colsum[i]; @@ -1338,19 +1361,19 @@ } if (npix) { - out[x + y * nx] = (OUT_TYPE)(runsum/(ACCU_TYPE)npix); - } else { + out[x + y * nx] = (OUT_TYPE)(runsum / (ACCU_TYPE)npix); + } + else { /* Flag as bad - and set to zero */ - if (*pbpm == NULL) *pbpm - = (cpl_binary*)cpl_calloc((size_t)nx * (size_t)ny, - sizeof(cpl_binary)); + if (*pbpm == NULL) + *pbpm = (cpl_binary *)cpl_calloc((size_t)nx * (size_t)ny, + sizeof(cpl_binary)); (*pbpm)[x + y * nx] = CPL_BINARY_1; out[x + y * nx] = (OUT_TYPE)0; } } - for (; x < 1 + hsizex; x ++) { - + for (; x < 1 + hsizex; x++) { if (!bpm[x + hsizex + (y + hsizey) * nx]) { /* Update the new colsum */ colsum[x + hsizex] += in[x + hsizex + (y + hsizey) * nx]; @@ -1360,26 +1383,25 @@ colpix[x + hsizex]++; npix += colpix[x + hsizex]; - } if (npix) { - out[x + y * nx] = (OUT_TYPE)(runsum/(ACCU_TYPE)npix); - } else { + out[x + y * nx] = (OUT_TYPE)(runsum / (ACCU_TYPE)npix); + } + else { /* Flag as bad - and set to zero */ - if (*pbpm == NULL) *pbpm - = (cpl_binary*)cpl_calloc((size_t)nx * (size_t)ny, - sizeof(cpl_binary)); + if (*pbpm == NULL) + *pbpm = (cpl_binary *)cpl_calloc((size_t)nx * (size_t)ny, + sizeof(cpl_binary)); (*pbpm)[x + y * nx] = CPL_BINARY_1; out[x + y * nx] = (OUT_TYPE)0; } } #ifdef ALLOW_RECIPROCAL - rnpix = (ACCU_TYPE)1.0/(ACCU_TYPE)npix; + rnpix = (ACCU_TYPE)1.0 / (ACCU_TYPE)npix; #endif - for (; x < nx-hsizex; x ++) { - + for (; x < nx - hsizex; x++) { if (!bpm[x + hsizex + (y + hsizey) * nx]) { /* Update the new colsum */ colsum[x + hsizex] += in[x + hsizex + (y + hsizey) * nx]; @@ -1388,7 +1410,8 @@ if (colsum[x + hsizex] != colpix[x - hsizex - 1]) { npix += colpix[x + hsizex] - colpix[x - hsizex - 1]; #ifdef ALLOW_RECIPROCAL - if (npix) rnpix = (ACCU_TYPE)1.0/(ACCU_TYPE)npix; + if (npix) + rnpix = (ACCU_TYPE)1.0 / (ACCU_TYPE)npix; #endif } @@ -1398,30 +1421,31 @@ if (npix) { out[x + y * nx] = (OUT_TYPE)(RUNSUM_MEAN); - } else { + } + else { /* Flag as bad - and set to zero */ - if (*pbpm == NULL) *pbpm - = (cpl_binary*)cpl_calloc((size_t)nx * (size_t)ny, - sizeof(cpl_binary)); + if (*pbpm == NULL) + *pbpm = (cpl_binary *)cpl_calloc((size_t)nx * (size_t)ny, + sizeof(cpl_binary)); (*pbpm)[x + y * nx] = CPL_BINARY_1; out[x + y * nx] = (OUT_TYPE)0; } } for (; x < nx; x++) { - - /* Update the running sum */ + /* Update the running sum */ runsum -= colsum[x - hsizex - 1]; npix -= colpix[x - hsizex - 1]; if (npix) { - out[x + y * nx] = (OUT_TYPE)(runsum/(ACCU_TYPE)npix); - } else { + out[x + y * nx] = (OUT_TYPE)(runsum / (ACCU_TYPE)npix); + } + else { /* Flag as bad - and set to zero */ - if (*pbpm == NULL) *pbpm - = (cpl_binary*)cpl_calloc((size_t)nx * (size_t)ny, - sizeof(cpl_binary)); + if (*pbpm == NULL) + *pbpm = (cpl_binary *)cpl_calloc((size_t)nx * (size_t)ny, + sizeof(cpl_binary)); (*pbpm)[x + y * nx] = CPL_BINARY_1; out[x + y * nx] = (OUT_TYPE)0; } @@ -1429,8 +1453,7 @@ } /* Loop over the central rows */ - for (;y < ny-hsizey; y++) { - + for (; y < ny - hsizey; y++) { ACCU_TYPE runsum = (ACCU_TYPE)0; #ifdef ALLOW_RECIPROCAL @@ -1439,9 +1462,8 @@ npix = 0; for (x = 0; x < 1; x++) { - /* Update the first 1 + hsizex column sums */ - for (i = 0; i < 1 + hsizex; i ++) { + for (i = 0; i < 1 + hsizex; i++) { if (!bpm[i + (y - hsizey - 1) * nx]) { colsum[i] -= in[i + (y - hsizey - 1) * nx]; colpix[i]--; @@ -1455,19 +1477,19 @@ } if (npix) { - out[x + y * nx] = (OUT_TYPE)(runsum/(ACCU_TYPE)npix); - } else { + out[x + y * nx] = (OUT_TYPE)(runsum / (ACCU_TYPE)npix); + } + else { /* Flag as bad - and set to zero */ - if (*pbpm == NULL) *pbpm - = (cpl_binary*)cpl_calloc((size_t)nx * (size_t)ny, - sizeof(cpl_binary)); + if (*pbpm == NULL) + *pbpm = (cpl_binary *)cpl_calloc((size_t)nx * (size_t)ny, + sizeof(cpl_binary)); (*pbpm)[x + y * nx] = CPL_BINARY_1; out[x + y * nx] = (OUT_TYPE)0; } } for (; x < 1 + hsizex; x++) { - /* Update the new colsum */ if (!bpm[x + hsizex + (y - hsizey - 1) * nx]) { colsum[x + hsizex] -= in[x + hsizex + (y - hsizey - 1) * nx]; @@ -1483,12 +1505,13 @@ npix += colpix[x + hsizex]; if (npix) { - out[x + y * nx] = (OUT_TYPE)(runsum/(ACCU_TYPE)npix); - } else { + out[x + y * nx] = (OUT_TYPE)(runsum / (ACCU_TYPE)npix); + } + else { /* Flag as bad - and set to zero */ - if (*pbpm == NULL) *pbpm - = (cpl_binary*)cpl_calloc((size_t)nx * (size_t)ny, - sizeof(cpl_binary)); + if (*pbpm == NULL) + *pbpm = (cpl_binary *)cpl_calloc((size_t)nx * (size_t)ny, + sizeof(cpl_binary)); (*pbpm)[x + y * nx] = CPL_BINARY_1; out[x + y * nx] = (OUT_TYPE)0; } @@ -1496,11 +1519,10 @@ #ifdef ALLOW_RECIPROCAL if (npix > (ACCU_TYPE)0.0) - rnpix = (ACCU_TYPE)1.0/(ACCU_TYPE)npix; + rnpix = (ACCU_TYPE)1.0 / (ACCU_TYPE)npix; #endif - - for (; x < nx-hsizex; x++) { + for (; x < nx - hsizex; x++) { /* Update the new colsum */ if (!bpm[x + hsizex + (y - hsizey - 1) * nx]) { colsum[x + hsizex] -= in[x + hsizex + (y - hsizey - 1) * nx]; @@ -1518,35 +1540,37 @@ if (colsum[x + hsizex] != colpix[x - hsizex - 1]) { npix += colpix[x + hsizex] - colpix[x - hsizex - 1]; #ifdef ALLOW_RECIPROCAL - if (npix) rnpix = (ACCU_TYPE)1.0/(ACCU_TYPE)npix; + if (npix) + rnpix = (ACCU_TYPE)1.0 / (ACCU_TYPE)npix; #endif } if (npix) { out[x + y * nx] = (OUT_TYPE)(RUNSUM_MEAN); - } else { + } + else { /* Flag as bad - and set to zero */ - if (*pbpm == NULL) *pbpm - = (cpl_binary*)cpl_calloc((size_t)nx * (size_t)ny, - sizeof(cpl_binary)); + if (*pbpm == NULL) + *pbpm = (cpl_binary *)cpl_calloc((size_t)nx * (size_t)ny, + sizeof(cpl_binary)); (*pbpm)[x + y * nx] = CPL_BINARY_1; out[x + y * nx] = (OUT_TYPE)0; } } for (; x < nx; x++) { - - /* Update the running sum */ + /* Update the running sum */ runsum -= colsum[x - hsizex - 1]; - npix -= colpix[x - hsizex - 1]; + npix -= colpix[x - hsizex - 1]; if (npix) { - out[x + y * nx] = (OUT_TYPE)(runsum/(ACCU_TYPE)npix); - } else { + out[x + y * nx] = (OUT_TYPE)(runsum / (ACCU_TYPE)npix); + } + else { /* Flag as bad - and set to zero */ - if (*pbpm == NULL) *pbpm - = (cpl_binary*)cpl_calloc((size_t)nx * (size_t)ny, - sizeof(cpl_binary)); + if (*pbpm == NULL) + *pbpm = (cpl_binary *)cpl_calloc((size_t)nx * (size_t)ny, + sizeof(cpl_binary)); (*pbpm)[x + y * nx] = CPL_BINARY_1; out[x + y * nx] = (OUT_TYPE)0; } @@ -1554,8 +1578,7 @@ } /* Loop over all the last rows, that cannot be covered by the kernel */ - for (;y < ny; y++) { - + for (; y < ny; y++) { ACCU_TYPE runsum = (ACCU_TYPE)0; #ifdef ALLOW_RECIPROCAL @@ -1565,59 +1588,59 @@ npix = (ACCU_TYPE)0; for (x = 0; x < 1; x++) { - /* Update the first 1 + hsizex column sums */ - for (i = 0; i < 1 + hsizex; i ++) { + for (i = 0; i < 1 + hsizex; i++) { if (!bpm[i + (y - hsizey - 1) * nx]) { colsum[i] -= in[i + (y - hsizey - 1) * nx]; colpix[i]--; } - runsum += colsum[i]; - npix += colpix[i]; + runsum += colsum[i]; + npix += colpix[i]; } if (npix) { - out[x + y * nx] = (OUT_TYPE)(runsum/(ACCU_TYPE)npix); - } else { + out[x + y * nx] = (OUT_TYPE)(runsum / (ACCU_TYPE)npix); + } + else { /* Flag as bad - and set to zero */ - if (*pbpm == NULL) *pbpm - = (cpl_binary*)cpl_calloc((size_t)nx * (size_t)ny, - sizeof(cpl_binary)); + if (*pbpm == NULL) + *pbpm = (cpl_binary *)cpl_calloc((size_t)nx * (size_t)ny, + sizeof(cpl_binary)); (*pbpm)[x + y * nx] = CPL_BINARY_1; out[x + y * nx] = (OUT_TYPE)0; } } for (; x < 1 + hsizex; x++) { - /* Update the new colsum */ - if (!bpm[x + hsizex + (y - hsizey - 1) * nx]) { - colsum[x + hsizex] -= in[x + hsizex + (y - hsizey - 1) * nx]; - colpix[x + hsizex]--; - } + if (!bpm[x + hsizex + (y - hsizey - 1) * nx]) { + colsum[x + hsizex] -= in[x + hsizex + (y - hsizey - 1) * nx]; + colpix[x + hsizex]--; + } /* Update the running sum */ runsum += colsum[x + hsizex]; - npix += colpix[x + hsizex]; + npix += colpix[x + hsizex]; if (npix) { - out[x + y * nx] = (OUT_TYPE)(runsum/(ACCU_TYPE)npix); - } else { + out[x + y * nx] = (OUT_TYPE)(runsum / (ACCU_TYPE)npix); + } + else { /* Flag as bad - and set to zero */ - if (*pbpm == NULL) *pbpm - = (cpl_binary*)cpl_calloc((size_t)nx * (size_t)ny, - sizeof(cpl_binary)); + if (*pbpm == NULL) + *pbpm = (cpl_binary *)cpl_calloc((size_t)nx * (size_t)ny, + sizeof(cpl_binary)); (*pbpm)[x + y * nx] = CPL_BINARY_1; out[x + y * nx] = (OUT_TYPE)0; } } #ifdef ALLOW_RECIPROCAL - if (npix) rnpix = (ACCU_TYPE)1.0/(ACCU_TYPE)npix; + if (npix) + rnpix = (ACCU_TYPE)1.0 / (ACCU_TYPE)npix; #endif - - for (; x < nx-hsizex; x++) { + for (; x < nx - hsizex; x++) { /* Update the new colsum */ if (!bpm[x + hsizex + (y - hsizey - 1) * nx]) { colsum[x + hsizex] -= in[x + hsizex + (y - hsizey - 1) * nx]; @@ -1632,35 +1655,37 @@ if (colsum[x + hsizex] != colpix[x - hsizex - 1]) { npix += colpix[x + hsizex] - colpix[x - hsizex - 1]; #ifdef ALLOW_RECIPROCAL - if (npix) rnpix = (ACCU_TYPE)1.0/(ACCU_TYPE)npix; + if (npix) + rnpix = (ACCU_TYPE)1.0 / (ACCU_TYPE)npix; #endif } if (npix) { out[x + y * nx] = (OUT_TYPE)(RUNSUM_MEAN); - } else { + } + else { /* Flag as bad - and set to zero */ - if (*pbpm == NULL) *pbpm - = (cpl_binary*)cpl_calloc((size_t)nx * (size_t)ny, - sizeof(cpl_binary)); + if (*pbpm == NULL) + *pbpm = (cpl_binary *)cpl_calloc((size_t)nx * (size_t)ny, + sizeof(cpl_binary)); (*pbpm)[x + y * nx] = CPL_BINARY_1; out[x + y * nx] = (OUT_TYPE)0; } } for (; x < nx; x++) { - - /* Update the running sum */ + /* Update the running sum */ runsum -= colsum[x - hsizex - 1]; - npix -= colpix[x - hsizex - 1]; + npix -= colpix[x - hsizex - 1]; if (npix) { - out[x + y * nx] = (OUT_TYPE)(runsum/(ACCU_TYPE)npix); - } else { + out[x + y * nx] = (OUT_TYPE)(runsum / (ACCU_TYPE)npix); + } + else { /* Flag as bad - and set to zero */ - if (*pbpm == NULL) *pbpm - = (cpl_binary*)cpl_calloc((size_t)nx * (size_t)ny, - sizeof(cpl_binary)); + if (*pbpm == NULL) + *pbpm = (cpl_binary *)cpl_calloc((size_t)nx * (size_t)ny, + sizeof(cpl_binary)); (*pbpm)[x + y * nx] = CPL_BINARY_1; out[x + y * nx] = (OUT_TYPE)0; } @@ -1671,7 +1696,6 @@ cpl_free(colpix); return; - } @@ -1696,29 +1720,30 @@ */ /*----------------------------------------------------------------------------*/ -static cpl_error_code -ADDTYPE_TWO(cpl_filter_linear_slow)(void * vout, cpl_binary ** ppbpm, - const void * vin, - const cpl_binary * bpm, - const double * pkernel, - cpl_size nx, cpl_size ny, - cpl_boolean dodiv, - cpl_size rx, cpl_size ry, - cpl_border_mode mode) +static cpl_error_code ADDTYPE_TWO(cpl_filter_linear_slow)(void *vout, + cpl_binary **ppbpm, + const void *vin, + const cpl_binary *bpm, + const double *pkernel, + cpl_size nx, + cpl_size ny, + cpl_boolean dodiv, + cpl_size rx, + cpl_size ry, + cpl_border_mode mode) { - if (mode == CPL_BORDER_FILTER) { - OUT_TYPE * out = (OUT_TYPE*)vout; - const IN_TYPE * in = (const IN_TYPE*)vin; - cpl_size x, y; + OUT_TYPE *out = (OUT_TYPE *)vout; + const IN_TYPE *in = (const IN_TYPE *)vin; + cpl_size x, y; for (y = 0; y < ny; y++) { - const size_t y_1 = CX_MAX(0, y - ry); - const size_t y2 = CX_MIN(ny-1, y + ry); + const size_t y_1 = CX_MAX(0, y - ry); + const size_t y2 = CX_MIN(ny - 1, y + ry); for (x = 0; x < nx; x++) { - const size_t x1 = CX_MAX(0, x - rx); - const size_t x2 = CX_MIN(nx-1, x + rx); - const IN_TYPE * inj = in + y_1 * nx; + const size_t x1 = CX_MAX(0, x - rx); + const size_t x2 = CX_MIN(nx - 1, x + rx); + const IN_TYPE *inj = in + y_1 * nx; /* Point to last (bottom) kernel row for first (bottom) image row */ /* As a difference from cpl_filter_average_slow, @@ -1726,40 +1751,46 @@ element (i, n-1-j) in a matrix buffer. Thus a matrix buffer has to be accessed in reverse row order */ - const double * pkernelj = pkernel - + (rx - x) + (ry + y - y_1) * (2 * rx + 1); - double sum = 0.0; - double weight = 0.0; + const double *pkernelj = + pkernel + (rx - x) + (ry + y - y_1) * (2 * rx + 1); + double sum = 0.0; + double weight = 0.0; /* True iff the filtered pixel has contributing input pixels (ignoring zero-valued weigths) */ cpl_boolean isok = bpm == NULL; size_t i, j; if (bpm == NULL) { - for (j = y_1; j < 1 + y2; j++, inj += nx, - pkernelj -= 2 * rx + 1) { + for (j = y_1; j < 1 + y2; + j++, inj += nx, pkernelj -= 2 * rx + 1) { for (i = x1; i < 1 + x2; i++) { sum += pkernelj[i] * (double)inj[i]; - if (dodiv) weight += fabs(pkernelj[i]); + if (dodiv) + weight += fabs(pkernelj[i]); } } - } else { - const cpl_binary * bpmj = bpm + y_1 * nx; + } + else { + const cpl_binary *bpmj = bpm + y_1 * nx; - for (j = y_1; j < 1 + y2; j++, inj += nx, bpmj += nx, - pkernelj -= 2 * rx + 1) { + for (j = y_1; j < 1 + y2; + j++, inj += nx, bpmj += nx, pkernelj -= 2 * rx + 1) { for (i = x1; i < 1 + x2; i++) { if (!bpmj[i]) { sum += pkernelj[i] * (double)inj[i]; - if (dodiv) weight += fabs(pkernelj[i]); - else isok = CPL_TRUE; + if (dodiv) + weight += fabs(pkernelj[i]); + else + isok = CPL_TRUE; } } } } if (dodiv ? weight > 0.0 : isok) { - if (dodiv) sum /= weight; - } else { + if (dodiv) + sum /= weight; + } + else { /* Flag as bad - and set to zero */ if (*ppbpm == NULL) { *ppbpm = cpl_calloc((size_t)nx * (size_t)ny, @@ -1770,7 +1801,8 @@ out[x + y * nx] = (OUT_TYPE)sum; } } - } else { + } + else { /* FIXME: Support more modes ? */ return cpl_error_set_(CPL_ERROR_UNSUPPORTED_MODE); } @@ -1800,32 +1832,33 @@ */ /*----------------------------------------------------------------------------*/ -static cpl_error_code -ADDTYPE_TWO(cpl_filter_morpho_slow)(void * vout, cpl_binary ** ppbpm, - const void * vin, - const cpl_binary * bpm, - const double * pkernel, - cpl_size nx, cpl_size ny, - cpl_boolean dodiv, - cpl_size rx, cpl_size ry, - cpl_border_mode mode) +static cpl_error_code ADDTYPE_TWO(cpl_filter_morpho_slow)(void *vout, + cpl_binary **ppbpm, + const void *vin, + const cpl_binary *bpm, + const double *pkernel, + cpl_size nx, + cpl_size ny, + cpl_boolean dodiv, + cpl_size rx, + cpl_size ry, + cpl_border_mode mode) { - if (mode == CPL_BORDER_FILTER) { - OUT_TYPE * out = (OUT_TYPE*)vout; - const IN_TYPE * in = (const IN_TYPE*)vin; + OUT_TYPE *out = (OUT_TYPE *)vout; + const IN_TYPE *in = (const IN_TYPE *)vin; IN_TYPE window[(2 * rx + 1) * (2 * ry + 1)]; - cpl_size x, y; + cpl_size x, y; for (y = 0; y < ny; y++) { - const size_t y_1 = CX_MAX(0, y - ry); - const size_t y2 = CX_MIN(ny-1, y + ry); + const size_t y_1 = CX_MAX(0, y - ry); + const size_t y2 = CX_MIN(ny - 1, y + ry); for (x = 0; x < nx; x++) { - const size_t x1 = CX_MAX(0, x - rx); - const size_t x2 = CX_MIN(nx-1, x + rx); - const IN_TYPE * inj = in + y_1 * nx; - double sum = 0.0; - double weight = 0.0; + const size_t x1 = CX_MAX(0, x - rx); + const size_t x2 = CX_MIN(nx - 1, x + rx); + const IN_TYPE *inj = in + y_1 * nx; + double sum = 0.0; + double weight = 0.0; size_t i, j; size_t k = 0; @@ -1836,18 +1869,21 @@ for (j = y_1; j < 1 + y2; j++, inj += nx) { for (i = x1; i < 1 + x2; i++) { window[k] = inj[i]; - if (dodiv) weight += fabs(pkernel[k]); + if (dodiv) + weight += fabs(pkernel[k]); k++; } } - } else { - const cpl_binary * bpmj = bpm + y_1 * nx; + } + else { + const cpl_binary *bpmj = bpm + y_1 * nx; for (j = y_1; j < 1 + y2; j++, inj += nx, bpmj += nx) { for (i = x1; i < 1 + x2; i++) { if (!bpmj[i]) { window[k] = inj[i]; - if (dodiv) weight += fabs(pkernel[k]); + if (dodiv) + weight += fabs(pkernel[k]); k++; } } @@ -1860,8 +1896,10 @@ for (; k--;) { sum += pkernel[k] * (double)window[k]; } - if (dodiv) sum /= weight; - } else { + if (dodiv) + sum /= weight; + } + else { /* Flag as bad - and set to zero */ if (*ppbpm == NULL) { *ppbpm = cpl_calloc((size_t)nx * (size_t)ny, @@ -1872,7 +1910,8 @@ out[x + y * nx] = (OUT_TYPE)sum; } } - } else { + } + else { /* FIXME: Support more modes ? */ return cpl_error_set_(CPL_ERROR_UNSUPPORTED_MODE); } @@ -1890,4 +1929,3 @@ #undef ACCU_TYPE_IS_INT #undef ALLOW_RECIPROCAL #undef RUNSUM_MEAN - diff -Nru cpl-7.1.4+ds/cplcore/cpl_image_filter.c cpl-7.2.2+ds/cplcore/cpl_image_filter.c --- cpl-7.1.4+ds/cplcore/cpl_image_filter.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_image_filter.c 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -51,10 +51,10 @@ /* These macros are needed for support of the different pixel types */ -#define CONCAT(a,b) a ## _ ## b -#define CONCAT2X(a,b) CONCAT(a,b) +#define CONCAT(a, b) a##_##b +#define CONCAT2X(a, b) CONCAT(a, b) -#define ADDTYPE(a) CONCAT2X(a, IN_TYPE) +#define ADDTYPE(a) CONCAT2X(a, IN_TYPE) #define ADDTYPE_TWO(a) CONCAT2X(a, CONCAT2X(OUT_TYPE, IN_TYPE)) /*----------------------------------------------------------------------------- @@ -64,86 +64,86 @@ /* First includes involve no casting */ #define IN_EQ_OUT -#define IN_TYPE double +#define IN_TYPE double #define PIX_TYPE double /* FIXME: Use DBL_MIN */ #define PIX_MIN (-DBL_MAX) #define PIX_MAX DBL_MAX #include "cpl_filter_median.c" -#define IN_TYPE float +#define IN_TYPE float #define PIX_TYPE float /* FIXME: Use FLT_MIN */ #define PIX_MIN (-FLT_MAX) #define PIX_MAX FLT_MAX #include "cpl_filter_median.c" -#define IN_TYPE int +#define IN_TYPE int #define PIX_TYPE int /* FIXME: Use INT_MIN */ #define PIX_MIN (-INT_MAX) #define PIX_MAX INT_MAX #include "cpl_filter_median.c" -#define IN_TYPE double -#define OUT_TYPE double -#define ACCU_TYPE double +#define IN_TYPE double +#define OUT_TYPE double +#define ACCU_TYPE double #define ACCU_FLOATTYPE double #include "cpl_image_filter_body.h" -#define IN_TYPE float -#define OUT_TYPE float -#define ACCU_TYPE float +#define IN_TYPE float +#define OUT_TYPE float +#define ACCU_TYPE float #define ACCU_FLOATTYPE float #include "cpl_image_filter_body.h" -#define IN_TYPE int -#define OUT_TYPE int -#define ACCU_TYPE int +#define IN_TYPE int +#define OUT_TYPE int +#define ACCU_TYPE int #define ACCU_TYPE_IS_INT #define ACCU_FLOATTYPE double #include "cpl_image_filter_body.h" #undef IN_EQ_OUT -#define IN_TYPE double -#define OUT_TYPE float -#define ACCU_TYPE double +#define IN_TYPE double +#define OUT_TYPE float +#define ACCU_TYPE double #define ACCU_FLOATTYPE double #include "cpl_image_filter_body.h" -#define IN_TYPE double -#define OUT_TYPE int -#define ACCU_TYPE double +#define IN_TYPE double +#define OUT_TYPE int +#define ACCU_TYPE double #define ACCU_FLOATTYPE double #include "cpl_image_filter_body.h" -#define IN_TYPE float -#define OUT_TYPE double -#define ACCU_TYPE double +#define IN_TYPE float +#define OUT_TYPE double +#define ACCU_TYPE double #define ACCU_FLOATTYPE double #include "cpl_image_filter_body.h" -#define IN_TYPE float -#define OUT_TYPE int -#define ACCU_TYPE float +#define IN_TYPE float +#define OUT_TYPE int +#define ACCU_TYPE float #define ACCU_FLOATTYPE float #include "cpl_image_filter_body.h" -#define IN_TYPE int -#define OUT_TYPE double -#define ACCU_TYPE double +#define IN_TYPE int +#define OUT_TYPE double +#define ACCU_TYPE double #define ACCU_FLOATTYPE double #include "cpl_image_filter_body.h" -#define IN_TYPE int -#define OUT_TYPE float -#define ACCU_TYPE float +#define IN_TYPE int +#define OUT_TYPE float +#define ACCU_TYPE float #define ACCU_FLOATTYPE float #include "cpl_image_filter_body.h" -static cpl_mask * cpl_mask_new_from_matrix(const cpl_matrix *, double, double); +static cpl_mask *cpl_mask_new_from_matrix(const cpl_matrix *, double, double); /*----------------------------------------------------------------------------- Function codes @@ -237,37 +237,37 @@ is unsupported. */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_filter_mask(cpl_image * self, - const cpl_image * other, - const cpl_mask * kernel, - cpl_filter_mode filter, - cpl_border_mode border) +cpl_error_code +cpl_image_filter_mask(cpl_image *self, + const cpl_image *other, + const cpl_mask *kernel, + cpl_filter_mode filter, + cpl_border_mode border) { - - const cpl_size nsx = cpl_image_get_size_x(self); - const cpl_size nsy = cpl_image_get_size_y(self); - const cpl_size nx = cpl_image_get_size_x(other); - const cpl_size ny = cpl_image_get_size_y(other); + const cpl_size nsx = cpl_image_get_size_x(self); + const cpl_size nsy = cpl_image_get_size_y(self); + const cpl_size nx = cpl_image_get_size_x(other); + const cpl_size ny = cpl_image_get_size_y(other); const cpl_size mx = cpl_mask_get_size_x(kernel); const cpl_size my = cpl_mask_get_size_y(kernel); const cpl_size hsizex = mx >> 1; const cpl_size hsizey = my >> 1; - const cpl_binary * pmask = cpl_mask_get_data_const(kernel); - const void * pother = cpl_image_get_data_const(other); - const void * pself = cpl_image_get_data_const(self); + const cpl_binary *pmask = cpl_mask_get_data_const(kernel); + const void *pother = cpl_image_get_data_const(other); + const void *pself = cpl_image_get_data_const(self); /* assert( sizeof(char) == 1 ) */ - const void * polast = (const void*)((const char*)pother - + (size_t)nx * (size_t)ny - * cpl_type_get_sizeof - (cpl_image_get_type(other))); + const void *polast = + (const void *)((const char *)pother + + (size_t)nx * (size_t)ny * + cpl_type_get_sizeof(cpl_image_get_type(other))); /* pmask may not overlap pself at all */ - const void * pmlast = (const void*)(pmask + (size_t)mx * (size_t)my); - const void * pslast = (const void*)((const char*)pself - + (size_t)nsx * (size_t)nsy - * cpl_type_get_sizeof - (cpl_image_get_type(self))); - cpl_binary * pbpmself; - const cpl_binary * badmap; + const void *pmlast = (const void *)(pmask + (size_t)mx * (size_t)my); + const void *pslast = + (const void *)((const char *)pself + + (size_t)nsx * (size_t)nsy * + cpl_type_get_sizeof(cpl_image_get_type(self))); + cpl_binary *pbpmself; + const cpl_binary *badmap; /* There are four different types of input: 1) No bpm, non-full kernel 2) No bpm, full kernel @@ -277,26 +277,24 @@ /* Input type 1: Not used (yet) */ /* Input type 2 */ - void (*filter_fast)(void *, const void *, - cpl_size, cpl_size, cpl_size, cpl_size, - cpl_border_mode); + void (*filter_fast)(void *, const void *, cpl_size, cpl_size, cpl_size, + cpl_size, cpl_border_mode); /* Input type 3 */ - cpl_error_code (*filter_bpm)(void *, cpl_binary **, - const void *, const cpl_binary *, - const cpl_binary *, cpl_size, cpl_size, - cpl_size, cpl_size, cpl_border_mode); + cpl_error_code (*filter_bpm)(void *, cpl_binary **, const void *, + const cpl_binary *, const cpl_binary *, + cpl_size, cpl_size, cpl_size, cpl_size, + cpl_border_mode); /* Input type 4 */ - void (*filter_full)(void *, cpl_binary **, - const void *, const cpl_binary *, - cpl_size, cpl_size, cpl_size, cpl_size, - cpl_border_mode); - cpl_boolean same_type = cpl_image_get_type(self) - == cpl_image_get_type(other); - cpl_boolean is_full; + void (*filter_full)(void *, cpl_binary **, const void *, const cpl_binary *, + cpl_size, cpl_size, cpl_size, cpl_size, + cpl_border_mode); + cpl_boolean same_type = + cpl_image_get_type(self) == cpl_image_get_type(other); + cpl_boolean is_full; - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(other != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(other != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(kernel != NULL, CPL_ERROR_NULL_INPUT); /* pself has to be above all of the other pixel buffer, or */ @@ -305,37 +303,37 @@ two pixel buffers may not overlap at all */ if (!(pself >= polast || pother >= pslast)) { return cpl_error_set_message_(CPL_ERROR_UNSUPPORTED_MODE, - "pself=%p, polast=%p, pother=%p, " - "pslast=%p, same_type=%d", - pself, polast, pother, pslast, - same_type); + "pself=%p, polast=%p, pother=%p, " + "pslast=%p, same_type=%d", + pself, polast, pother, pslast, same_type); } /* If this check fails, the caller is doing something really weird... */ - cpl_ensure_code((const void*)pmask >= pslast || - pself >= (const void*)pmlast, + cpl_ensure_code((const void *)pmask >= pslast || + pself >= (const void *)pmlast, CPL_ERROR_UNSUPPORTED_MODE); /* Only odd-sized masks allowed */ - cpl_ensure_code((mx&1) == 1, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code((my&1) == 1, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code((mx & 1) == 1, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code((my & 1) == 1, CPL_ERROR_ILLEGAL_INPUT); if (filter == CPL_FILTER_STDEV || filter == CPL_FILTER_STDEV_FAST) { /* Mask must have at least two non-zero elements */ - const cpl_binary * pmask1 = memchr(pmask, CPL_BINARY_1, - (size_t)mx * (size_t)my - * sizeof(*pmask)); - const cpl_binary * pmask2; + const cpl_binary *pmask1 = + memchr(pmask, CPL_BINARY_1, + (size_t)mx * (size_t)my * sizeof(*pmask)); + const cpl_binary *pmask2; cpl_ensure_code(pmask1 != NULL, CPL_ERROR_DATA_NOT_FOUND); /* Rely on memchr() to return NULL on zero-size */ pmask2 = memchr(pmask1 + sizeof(*pmask), CPL_BINARY_1, - ((size_t)mx * (size_t)my - (1 + pmask1 - pmask)) - * sizeof(*pmask)); + ((size_t)mx * (size_t)my - (1 + pmask1 - pmask)) * + sizeof(*pmask)); cpl_ensure_code(pmask2 != NULL, CPL_ERROR_DATA_NOT_FOUND); - } else { + } + else { /* Mask may not be empty */ cpl_ensure_code(!cpl_mask_is_empty(kernel), CPL_ERROR_DATA_NOT_FOUND); } @@ -347,29 +345,30 @@ cpl_ensure_code(nsx == nx - 2 * hsizex, CPL_ERROR_INCOMPATIBLE_INPUT); cpl_ensure_code(nsy == ny - 2 * hsizey, CPL_ERROR_INCOMPATIBLE_INPUT); - - } else { + } + else { cpl_ensure_code(nsx == nx, CPL_ERROR_INCOMPATIBLE_INPUT); cpl_ensure_code(nsy == ny, CPL_ERROR_INCOMPATIBLE_INPUT); - } /* Get and reset all bad pixels, if any */ pbpmself = self->bpm != NULL - ? memset(cpl_mask_get_data(self->bpm), CPL_BINARY_0, - (size_t)nsx * (size_t)nsy) - : NULL; + ? memset(cpl_mask_get_data(self->bpm), CPL_BINARY_0, + (size_t)nsx * (size_t)nsy) + : NULL; badmap = other->bpm == NULL || cpl_mask_is_empty(other->bpm) - ? NULL : cpl_mask_get_data_const(other->bpm); + ? NULL + : cpl_mask_get_data_const(other->bpm); is_full = memchr(pmask, CPL_BINARY_0, (size_t)mx * (size_t)my * sizeof(*pmask)) == NULL - ? CPL_TRUE : CPL_FALSE; + ? CPL_TRUE + : CPL_FALSE; filter_fast = NULL; - filter_bpm = NULL; + filter_bpm = NULL; filter_full = NULL; @@ -397,29 +396,32 @@ cpl_ensure_code(same_type, CPL_ERROR_TYPE_MISMATCH); switch (cpl_image_get_type(self)) { - case CPL_TYPE_DOUBLE: - if (use_all) { - filter_fast = cpl_filter_median_fast_double; - } else { - filter_bpm = cpl_filter_median_slow_double; - } - break; - case CPL_TYPE_FLOAT: - if (use_all) { - filter_fast = cpl_filter_median_fast_float; - } else { - filter_bpm = cpl_filter_median_slow_float; - } - break; - case CPL_TYPE_INT: - if (use_all) { - filter_fast = cpl_filter_median_fast_int; - } else { - filter_bpm = cpl_filter_median_slow_int; - } - break; - default: - /* + case CPL_TYPE_DOUBLE: + if (use_all) { + filter_fast = cpl_filter_median_fast_double; + } + else { + filter_bpm = cpl_filter_median_slow_double; + } + break; + case CPL_TYPE_FLOAT: + if (use_all) { + filter_fast = cpl_filter_median_fast_float; + } + else { + filter_bpm = cpl_filter_median_slow_float; + } + break; + case CPL_TYPE_INT: + if (use_all) { + filter_fast = cpl_filter_median_fast_int; + } + else { + filter_bpm = cpl_filter_median_slow_int; + } + break; + default: + /* * Currently, it is an error in CPL to reach this point, as all * possible types for images (see cpl_image_new()) are supported. * @@ -428,164 +430,96 @@ * in this function. For that case, we keep setting the appropriate * error code in this default section. */ - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } - - } else if (filter == CPL_FILTER_STDEV || - (filter == CPL_FILTER_STDEV_FAST && !is_full)) { + } + else if (filter == CPL_FILTER_STDEV || + (filter == CPL_FILTER_STDEV_FAST && !is_full)) { cpl_ensure_code(border == CPL_BORDER_FILTER, CPL_ERROR_UNSUPPORTED_MODE); switch (cpl_image_get_type(self)) { - case CPL_TYPE_DOUBLE: { - switch (cpl_image_get_type(other)) { - case CPL_TYPE_DOUBLE: - filter_bpm = cpl_filter_stdev_slow_double_double; - break; - case CPL_TYPE_FLOAT: - filter_bpm = cpl_filter_stdev_slow_double_float; - break; - case CPL_TYPE_INT: - filter_bpm = cpl_filter_stdev_slow_double_int; - break; - default: - /* See comment in previous switch() default: */ - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); - } - - break; - } - - case CPL_TYPE_FLOAT: { - switch (cpl_image_get_type(other)) { - case CPL_TYPE_DOUBLE: - filter_bpm = cpl_filter_stdev_slow_float_double; - break; - case CPL_TYPE_FLOAT: - filter_bpm = cpl_filter_stdev_slow_float_float; - break; - case CPL_TYPE_INT: - filter_bpm = cpl_filter_stdev_slow_float_int; - break; - default: - /* See comment in previous switch() default: */ - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); - } - break; - } - + case CPL_TYPE_DOUBLE: { + switch (cpl_image_get_type(other)) { + case CPL_TYPE_DOUBLE: + filter_bpm = cpl_filter_stdev_slow_double_double; + break; + case CPL_TYPE_FLOAT: + filter_bpm = cpl_filter_stdev_slow_double_float; + break; + case CPL_TYPE_INT: + filter_bpm = cpl_filter_stdev_slow_double_int; + break; + default: + /* See comment in previous switch() default: */ + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + } - case CPL_TYPE_INT: { - switch (cpl_image_get_type(other)) { - case CPL_TYPE_DOUBLE: - filter_bpm = cpl_filter_stdev_slow_int_double; break; - case CPL_TYPE_FLOAT: - filter_bpm = cpl_filter_stdev_slow_int_float; - break; - case CPL_TYPE_INT: - filter_bpm = cpl_filter_stdev_slow_int_int; - break; - default: - /* See comment in previous switch() default: */ - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } - break; - } - - default: - /* See comment in previous switch() default: */ - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); - } - } else if (filter == CPL_FILTER_AVERAGE || - (filter == CPL_FILTER_AVERAGE_FAST && !is_full)) { - cpl_ensure_code(border == CPL_BORDER_FILTER, - CPL_ERROR_UNSUPPORTED_MODE); - - switch (cpl_image_get_type(self)) { - case CPL_TYPE_DOUBLE: { - switch (cpl_image_get_type(other)) { - case CPL_TYPE_DOUBLE: - filter_bpm = cpl_filter_average_slow_double_double; - break; - case CPL_TYPE_FLOAT: - filter_bpm = cpl_filter_average_slow_double_float; - break; - case CPL_TYPE_INT: - filter_bpm = cpl_filter_average_slow_double_int; + case CPL_TYPE_FLOAT: { + switch (cpl_image_get_type(other)) { + case CPL_TYPE_DOUBLE: + filter_bpm = cpl_filter_stdev_slow_float_double; + break; + case CPL_TYPE_FLOAT: + filter_bpm = cpl_filter_stdev_slow_float_float; + break; + case CPL_TYPE_INT: + filter_bpm = cpl_filter_stdev_slow_float_int; + break; + default: + /* See comment in previous switch() default: */ + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + } break; - default: - /* See comment in previous switch() default: */ - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } - break; - } - case CPL_TYPE_FLOAT: { - switch (cpl_image_get_type(other)) { - case CPL_TYPE_DOUBLE: - filter_bpm = cpl_filter_average_slow_float_double; - break; - case CPL_TYPE_FLOAT: - filter_bpm = cpl_filter_average_slow_float_float; - break; - case CPL_TYPE_INT: - filter_bpm = cpl_filter_average_slow_float_int; + case CPL_TYPE_INT: { + switch (cpl_image_get_type(other)) { + case CPL_TYPE_DOUBLE: + filter_bpm = cpl_filter_stdev_slow_int_double; + break; + case CPL_TYPE_FLOAT: + filter_bpm = cpl_filter_stdev_slow_int_float; + break; + case CPL_TYPE_INT: + filter_bpm = cpl_filter_stdev_slow_int_int; + break; + default: + /* See comment in previous switch() default: */ + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + } break; - default: - /* See comment in previous switch() default: */ - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } - break; - } - - case CPL_TYPE_INT: { - switch (cpl_image_get_type(other)) { - case CPL_TYPE_DOUBLE: - filter_bpm = cpl_filter_average_slow_int_double; - break; - case CPL_TYPE_FLOAT: - filter_bpm = cpl_filter_average_slow_int_float; - break; - case CPL_TYPE_INT: - filter_bpm = cpl_filter_average_slow_int_int; - break; default: /* See comment in previous switch() default: */ return cpl_error_set_(CPL_ERROR_INVALID_TYPE); - } - break; } - - default: - /* See comment in previous switch() default: */ - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); - } - } else if (filter == CPL_FILTER_AVERAGE_FAST) { - + } + else if (filter == CPL_FILTER_AVERAGE || + (filter == CPL_FILTER_AVERAGE_FAST && !is_full)) { cpl_ensure_code(border == CPL_BORDER_FILTER, CPL_ERROR_UNSUPPORTED_MODE); - if (badmap != NULL) { - /* Full kernel, bad pixels */ - switch (cpl_image_get_type(self)) { + switch (cpl_image_get_type(self)) { case CPL_TYPE_DOUBLE: { switch (cpl_image_get_type(other)) { - case CPL_TYPE_DOUBLE: - filter_full = cpl_filter_average_bpm_double_double; - break; - case CPL_TYPE_FLOAT: - filter_full = cpl_filter_average_bpm_double_float; - break; - case CPL_TYPE_INT: - filter_full = cpl_filter_average_bpm_double_int; - break; - default: - /* See comment in previous switch() default: */ - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + case CPL_TYPE_DOUBLE: + filter_bpm = cpl_filter_average_slow_double_double; + break; + case CPL_TYPE_FLOAT: + filter_bpm = cpl_filter_average_slow_double_float; + break; + case CPL_TYPE_INT: + filter_bpm = cpl_filter_average_slow_double_int; + break; + default: + /* See comment in previous switch() default: */ + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } break; @@ -593,18 +527,18 @@ case CPL_TYPE_FLOAT: { switch (cpl_image_get_type(other)) { - case CPL_TYPE_DOUBLE: - filter_full = cpl_filter_average_bpm_float_double; - break; - case CPL_TYPE_FLOAT: - filter_full = cpl_filter_average_bpm_float_float; - break; - case CPL_TYPE_INT: - filter_full = cpl_filter_average_bpm_float_int; - break; - default: - /* See comment in previous switch() default: */ - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + case CPL_TYPE_DOUBLE: + filter_bpm = cpl_filter_average_slow_float_double; + break; + case CPL_TYPE_FLOAT: + filter_bpm = cpl_filter_average_slow_float_float; + break; + case CPL_TYPE_INT: + filter_bpm = cpl_filter_average_slow_float_int; + break; + default: + /* See comment in previous switch() default: */ + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } break; } @@ -612,18 +546,18 @@ case CPL_TYPE_INT: { switch (cpl_image_get_type(other)) { - case CPL_TYPE_DOUBLE: - filter_full = cpl_filter_average_bpm_int_double; - break; - case CPL_TYPE_FLOAT: - filter_full = cpl_filter_average_bpm_int_float; - break; - case CPL_TYPE_INT: - filter_full = cpl_filter_average_bpm_int_int; - break; - default: - /* See comment in previous switch() default: */ - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + case CPL_TYPE_DOUBLE: + filter_bpm = cpl_filter_average_slow_int_double; + break; + case CPL_TYPE_FLOAT: + filter_bpm = cpl_filter_average_slow_int_float; + break; + case CPL_TYPE_INT: + filter_bpm = cpl_filter_average_slow_int_int; + break; + default: + /* See comment in previous switch() default: */ + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } break; } @@ -631,214 +565,282 @@ default: /* See comment in previous switch() default: */ return cpl_error_set_(CPL_ERROR_INVALID_TYPE); - } - } else { - /* Full kernel, no bad pixels */ + } + } + else if (filter == CPL_FILTER_AVERAGE_FAST) { + cpl_ensure_code(border == CPL_BORDER_FILTER, + CPL_ERROR_UNSUPPORTED_MODE); + + if (badmap != NULL) { + /* Full kernel, bad pixels */ switch (cpl_image_get_type(self)) { - case CPL_TYPE_DOUBLE: { - switch (cpl_image_get_type(other)) { - case CPL_TYPE_DOUBLE: - filter_fast = cpl_filter_average_double_double; - break; - case CPL_TYPE_FLOAT: - filter_fast = cpl_filter_average_double_float; + case CPL_TYPE_DOUBLE: { + switch (cpl_image_get_type(other)) { + case CPL_TYPE_DOUBLE: + filter_full = cpl_filter_average_bpm_double_double; + break; + case CPL_TYPE_FLOAT: + filter_full = cpl_filter_average_bpm_double_float; + break; + case CPL_TYPE_INT: + filter_full = cpl_filter_average_bpm_double_int; + break; + default: + /* See comment in previous switch() default: */ + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + } + break; - case CPL_TYPE_INT: - filter_fast = cpl_filter_average_double_int; + } + + case CPL_TYPE_FLOAT: { + switch (cpl_image_get_type(other)) { + case CPL_TYPE_DOUBLE: + filter_full = cpl_filter_average_bpm_float_double; + break; + case CPL_TYPE_FLOAT: + filter_full = cpl_filter_average_bpm_float_float; + break; + case CPL_TYPE_INT: + filter_full = cpl_filter_average_bpm_float_int; + break; + default: + /* See comment in previous switch() default: */ + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + } break; - default: - /* See comment in previous switch() default: */ - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } - break; - } - case CPL_TYPE_FLOAT: { - switch (cpl_image_get_type(other)) { - case CPL_TYPE_DOUBLE: - filter_fast = cpl_filter_average_float_double; - break; - case CPL_TYPE_FLOAT: - filter_fast = cpl_filter_average_float_float; - break; - case CPL_TYPE_INT: - filter_fast = cpl_filter_average_float_int; + case CPL_TYPE_INT: { + switch (cpl_image_get_type(other)) { + case CPL_TYPE_DOUBLE: + filter_full = cpl_filter_average_bpm_int_double; + break; + case CPL_TYPE_FLOAT: + filter_full = cpl_filter_average_bpm_int_float; + break; + case CPL_TYPE_INT: + filter_full = cpl_filter_average_bpm_int_int; + break; + default: + /* See comment in previous switch() default: */ + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + } break; + } + default: /* See comment in previous switch() default: */ return cpl_error_set_(CPL_ERROR_INVALID_TYPE); - } - break; } + } + else { + /* Full kernel, no bad pixels */ + switch (cpl_image_get_type(self)) { + case CPL_TYPE_DOUBLE: { + switch (cpl_image_get_type(other)) { + case CPL_TYPE_DOUBLE: + filter_fast = cpl_filter_average_double_double; + break; + case CPL_TYPE_FLOAT: + filter_fast = cpl_filter_average_double_float; + break; + case CPL_TYPE_INT: + filter_fast = cpl_filter_average_double_int; + break; + default: + /* See comment in previous switch() default: */ + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + } - - case CPL_TYPE_INT: { - switch (cpl_image_get_type(other)) { - case CPL_TYPE_DOUBLE: - filter_fast = cpl_filter_average_int_double; break; - case CPL_TYPE_FLOAT: - filter_fast = cpl_filter_average_int_float; + } + + case CPL_TYPE_FLOAT: { + switch (cpl_image_get_type(other)) { + case CPL_TYPE_DOUBLE: + filter_fast = cpl_filter_average_float_double; + break; + case CPL_TYPE_FLOAT: + filter_fast = cpl_filter_average_float_float; + break; + case CPL_TYPE_INT: + filter_fast = cpl_filter_average_float_int; + break; + default: + /* See comment in previous switch() default: */ + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + } break; - case CPL_TYPE_INT: - filter_fast = cpl_filter_average_int_int; + } + + + case CPL_TYPE_INT: { + switch (cpl_image_get_type(other)) { + case CPL_TYPE_DOUBLE: + filter_fast = cpl_filter_average_int_double; + break; + case CPL_TYPE_FLOAT: + filter_fast = cpl_filter_average_int_float; + break; + case CPL_TYPE_INT: + filter_fast = cpl_filter_average_int_int; + break; + default: + /* See comment in previous switch() default: */ + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + } break; + } + default: /* See comment in previous switch() default: */ return cpl_error_set_(CPL_ERROR_INVALID_TYPE); - } - break; - } - - default: - /* See comment in previous switch() default: */ - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } } - } else if (filter == CPL_FILTER_STDEV_FAST) { - + } + else if (filter == CPL_FILTER_STDEV_FAST) { cpl_ensure_code(border == CPL_BORDER_FILTER, CPL_ERROR_UNSUPPORTED_MODE); if (badmap != NULL) { - /* FIXME : + /* FIXME : Implement cpl_filter_stdev_bpm_* similarly to cpl_filter_average_bpm_* and replace cpl_filter_stdev_slow_* with it */ /* Full kernel, bad pixels */ switch (cpl_image_get_type(self)) { - case CPL_TYPE_DOUBLE: { - switch (cpl_image_get_type(other)) { - case CPL_TYPE_DOUBLE: - filter_bpm = cpl_filter_stdev_slow_double_double; - break; - case CPL_TYPE_FLOAT: - filter_bpm = cpl_filter_stdev_slow_double_float; - break; - case CPL_TYPE_INT: - filter_bpm = cpl_filter_stdev_slow_double_int; + case CPL_TYPE_DOUBLE: { + switch (cpl_image_get_type(other)) { + case CPL_TYPE_DOUBLE: + filter_bpm = cpl_filter_stdev_slow_double_double; + break; + case CPL_TYPE_FLOAT: + filter_bpm = cpl_filter_stdev_slow_double_float; + break; + case CPL_TYPE_INT: + filter_bpm = cpl_filter_stdev_slow_double_int; + break; + default: + /* See comment in previous switch() default: */ + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + } + break; - default: - /* See comment in previous switch() default: */ - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } - break; - } - - case CPL_TYPE_FLOAT: { - switch (cpl_image_get_type(other)) { - case CPL_TYPE_DOUBLE: - filter_bpm = cpl_filter_stdev_slow_float_double; - break; - case CPL_TYPE_FLOAT: - filter_bpm = cpl_filter_stdev_slow_float_float; - break; - case CPL_TYPE_INT: - filter_bpm = cpl_filter_stdev_slow_float_int; + case CPL_TYPE_FLOAT: { + switch (cpl_image_get_type(other)) { + case CPL_TYPE_DOUBLE: + filter_bpm = cpl_filter_stdev_slow_float_double; + break; + case CPL_TYPE_FLOAT: + filter_bpm = cpl_filter_stdev_slow_float_float; + break; + case CPL_TYPE_INT: + filter_bpm = cpl_filter_stdev_slow_float_int; + break; + default: + /* See comment in previous switch() default: */ + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + } break; - default: - /* See comment in previous switch() default: */ - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } - break; - } - case CPL_TYPE_INT: { - switch (cpl_image_get_type(other)) { - case CPL_TYPE_DOUBLE: - filter_bpm = cpl_filter_stdev_slow_int_double; - break; - case CPL_TYPE_FLOAT: - filter_bpm = cpl_filter_stdev_slow_int_float; - break; - case CPL_TYPE_INT: - filter_bpm = cpl_filter_stdev_slow_int_int; + case CPL_TYPE_INT: { + switch (cpl_image_get_type(other)) { + case CPL_TYPE_DOUBLE: + filter_bpm = cpl_filter_stdev_slow_int_double; + break; + case CPL_TYPE_FLOAT: + filter_bpm = cpl_filter_stdev_slow_int_float; + break; + case CPL_TYPE_INT: + filter_bpm = cpl_filter_stdev_slow_int_int; + break; + default: + /* See comment in previous switch() default: */ + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + } break; + } + default: /* See comment in previous switch() default: */ return cpl_error_set_(CPL_ERROR_INVALID_TYPE); - } - break; - } - - default: - /* See comment in previous switch() default: */ - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } - } else { + } + else { /* Full kernel, no bad pixels */ switch (cpl_image_get_type(self)) { - case CPL_TYPE_DOUBLE: { - switch (cpl_image_get_type(other)) { - case CPL_TYPE_DOUBLE: - filter_fast = cpl_filter_stdev_double_double; - break; - case CPL_TYPE_FLOAT: - filter_fast = cpl_filter_stdev_double_float; - break; - case CPL_TYPE_INT: - filter_fast = cpl_filter_stdev_double_int; + case CPL_TYPE_DOUBLE: { + switch (cpl_image_get_type(other)) { + case CPL_TYPE_DOUBLE: + filter_fast = cpl_filter_stdev_double_double; + break; + case CPL_TYPE_FLOAT: + filter_fast = cpl_filter_stdev_double_float; + break; + case CPL_TYPE_INT: + filter_fast = cpl_filter_stdev_double_int; + break; + default: + /* See comment in previous switch() default: */ + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + } + break; - default: - /* See comment in previous switch() default: */ - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } - break; - } - - case CPL_TYPE_FLOAT: { - switch (cpl_image_get_type(other)) { - case CPL_TYPE_DOUBLE: - filter_fast = cpl_filter_stdev_float_double; - break; - case CPL_TYPE_FLOAT: - filter_fast = cpl_filter_stdev_float_float; + case CPL_TYPE_FLOAT: { + switch (cpl_image_get_type(other)) { + case CPL_TYPE_DOUBLE: + filter_fast = cpl_filter_stdev_float_double; + break; + case CPL_TYPE_FLOAT: + filter_fast = cpl_filter_stdev_float_float; + break; + case CPL_TYPE_INT: + filter_fast = cpl_filter_stdev_float_int; + break; + default: + /* See comment in previous switch() default: */ + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + } break; - case CPL_TYPE_INT: - filter_fast = cpl_filter_stdev_float_int; - break; - default: - /* See comment in previous switch() default: */ - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } - break; - } - case CPL_TYPE_INT: { - switch (cpl_image_get_type(other)) { - case CPL_TYPE_DOUBLE: - filter_fast = cpl_filter_stdev_int_double; - break; - case CPL_TYPE_FLOAT: - filter_fast = cpl_filter_stdev_int_float; - break; - case CPL_TYPE_INT: - filter_fast = cpl_filter_stdev_int_int; + case CPL_TYPE_INT: { + switch (cpl_image_get_type(other)) { + case CPL_TYPE_DOUBLE: + filter_fast = cpl_filter_stdev_int_double; + break; + case CPL_TYPE_FLOAT: + filter_fast = cpl_filter_stdev_int_float; + break; + case CPL_TYPE_INT: + filter_fast = cpl_filter_stdev_int_int; + break; + default: + /* See comment in previous switch() default: */ + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + } break; + } + default: /* See comment in previous switch() default: */ return cpl_error_set_(CPL_ERROR_INVALID_TYPE); - } - break; - } - - default: - /* See comment in previous switch() default: */ - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } } } if (filter_fast != NULL) { - filter_fast(cpl_image_get_data(self), - cpl_image_get_data_const(other), - nx, ny, hsizex, hsizey, - (unsigned)border); + filter_fast(cpl_image_get_data(self), cpl_image_get_data_const(other), + nx, ny, hsizex, hsizey, (unsigned)border); #ifndef CPL_MEDIAN_SAMPLE if (filter == CPL_FILTER_MEDIAN && border == CPL_BORDER_FILTER) { const cpl_type type = cpl_image_get_type(self); @@ -851,32 +853,34 @@ cpl_filter_median_even_double(cpl_image_get_data(self), cpl_image_get_data_const(other), nx, ny, hsizex, hsizey); - } else if (type == CPL_TYPE_FLOAT) { + } + else if (type == CPL_TYPE_FLOAT) { cpl_filter_median_even_float(cpl_image_get_data(self), cpl_image_get_data_const(other), nx, ny, hsizex, hsizey); - } else { - assert( type == CPL_TYPE_INT); + } + else { + assert(type == CPL_TYPE_INT); cpl_filter_median_even_int(cpl_image_get_data(self), - cpl_image_get_data_const(other), - nx, ny, hsizex, hsizey); + cpl_image_get_data_const(other), nx, + ny, hsizex, hsizey); } } #endif - } else if (filter_full != NULL) { + } + else if (filter_full != NULL) { filter_full(cpl_image_get_data(self), &pbpmself, - cpl_image_get_data_const(other), badmap, - nx, ny, hsizex, hsizey, - border); - } else if (filter_bpm != NULL) { - + cpl_image_get_data_const(other), badmap, nx, ny, hsizex, + hsizey, border); + } + else if (filter_bpm != NULL) { if (filter_bpm(cpl_image_get_data(self), &pbpmself, - cpl_image_get_data_const(other), badmap, - pmask, nx, ny, hsizex, hsizey, - border)) { + cpl_image_get_data_const(other), badmap, pmask, nx, ny, + hsizex, hsizey, border)) { return cpl_error_set_where_(); } - } else { + } + else { return cpl_error_set_(CPL_ERROR_UNSUPPORTED_MODE); } @@ -886,7 +890,6 @@ } return CPL_ERROR_NONE; - } /*----------------------------------------------------------------------------*/ @@ -955,71 +958,71 @@ is unsupported. */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_filter(cpl_image * self, - const cpl_image * other, - const cpl_matrix * kernel, - cpl_filter_mode filter, - cpl_border_mode border) +cpl_error_code +cpl_image_filter(cpl_image *self, + const cpl_image *other, + const cpl_matrix *kernel, + cpl_filter_mode filter, + cpl_border_mode border) { - - const cpl_size nsx = cpl_image_get_size_x(self); - const cpl_size nsy = cpl_image_get_size_y(self); - const cpl_size nx = cpl_image_get_size_x(other); - const cpl_size ny = cpl_image_get_size_y(other); + const cpl_size nsx = cpl_image_get_size_x(self); + const cpl_size nsy = cpl_image_get_size_y(self); + const cpl_size nx = cpl_image_get_size_x(other); + const cpl_size ny = cpl_image_get_size_y(other); const cpl_size mx = cpl_matrix_get_ncol(kernel); const cpl_size my = cpl_matrix_get_nrow(kernel); const cpl_size hsizex = mx >> 1; const cpl_size hsizey = my >> 1; - const double * pkernel = cpl_matrix_get_data_const(kernel); - const void * pother = cpl_image_get_data_const(other); - const void * pself = cpl_image_get_data_const(self); + const double *pkernel = cpl_matrix_get_data_const(kernel); + const void *pother = cpl_image_get_data_const(other); + const void *pself = cpl_image_get_data_const(self); /* assert( sizeof(char) == 1 ) */ - const void * polast = (const void*)((const char*)pother - + (size_t)nx * (size_t)ny - * cpl_type_get_sizeof - (cpl_image_get_type(other))); + const void *polast = + (const void *)((const char *)pother + + (size_t)nx * (size_t)ny * + cpl_type_get_sizeof(cpl_image_get_type(other))); /* pkernel may not overlap pself at all */ - const void * pmlast = (const void*)(pkernel + mx * my); - const void * pslast = (const void*)((const char*)pself - + (size_t)nsx * (size_t)nsy - * cpl_type_get_sizeof - (cpl_image_get_type(self))); - cpl_binary * pbpmself; - const cpl_binary * badmap; - cpl_error_code (*filter_func)(void *, cpl_binary **, - const void *, const cpl_binary *, - const double *, cpl_size, cpl_size, - cpl_boolean, - cpl_size, cpl_size, cpl_border_mode); + const void *pmlast = (const void *)(pkernel + mx * my); + const void *pslast = + (const void *)((const char *)pself + + (size_t)nsx * (size_t)nsy * + cpl_type_get_sizeof(cpl_image_get_type(self))); + cpl_binary *pbpmself; + const cpl_binary *badmap; + cpl_error_code (*filter_func)(void *, cpl_binary **, const void *, + const cpl_binary *, const double *, cpl_size, + cpl_size, cpl_boolean, cpl_size, cpl_size, + cpl_border_mode); cpl_boolean dodiv = CPL_FALSE; cpl_size i; - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(other != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(kernel != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(other != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(kernel != NULL, CPL_ERROR_NULL_INPUT); /* pself has to be above all of the other pixel buffer, or */ /* ...pother has to be above the first hsize+1 rows of pself */ /* ... unless they have different pixel types, in which case the two pixel buffers may not overlap at all */ cpl_ensure_code(pself >= polast || pother >= pslast, - CPL_ERROR_UNSUPPORTED_MODE); + CPL_ERROR_UNSUPPORTED_MODE); /* If this check fails, the caller is doing something really weird... */ - cpl_ensure_code((const void*)pkernel >= pslast || - pself >= (const void*)pmlast, + cpl_ensure_code((const void *)pkernel >= pslast || + pself >= (const void *)pmlast, CPL_ERROR_UNSUPPORTED_MODE); /* Only odd-sized kernels allowed */ - cpl_ensure_code((mx&1) == 1, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code((my&1) == 1, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code((mx & 1) == 1, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code((my & 1) == 1, CPL_ERROR_ILLEGAL_INPUT); cpl_ensure_code(mx <= nx, CPL_ERROR_ACCESS_OUT_OF_RANGE); cpl_ensure_code(my <= ny, CPL_ERROR_ACCESS_OUT_OF_RANGE); /* kernel may not be empty */ - for (i=0 ; i < mx * my ; i++) { - if (pkernel[i] != 0.0) break; + for (i = 0; i < mx * my; i++) { + if (pkernel[i] != 0.0) + break; } cpl_ensure_code(i < mx * my, CPL_ERROR_DIVISION_BY_ZERO); @@ -1027,46 +1030,45 @@ cpl_ensure_code(nsx == nx - 2 * hsizex, CPL_ERROR_INCOMPATIBLE_INPUT); cpl_ensure_code(nsy == ny - 2 * hsizey, CPL_ERROR_INCOMPATIBLE_INPUT); - - } else { + } + else { cpl_ensure_code(nsx == nx, CPL_ERROR_INCOMPATIBLE_INPUT); cpl_ensure_code(nsy == ny, CPL_ERROR_INCOMPATIBLE_INPUT); - } /* Get and reset all bad pixels, if any */ pbpmself = self->bpm != NULL - ? memset(cpl_mask_get_data(self->bpm), CPL_BINARY_0, - (size_t)nsx * (size_t)nsy) - : NULL; + ? memset(cpl_mask_get_data(self->bpm), CPL_BINARY_0, + (size_t)nsx * (size_t)nsy) + : NULL; badmap = other->bpm == NULL || cpl_mask_is_empty(other->bpm) - ? NULL : cpl_mask_get_data_const(other->bpm); + ? NULL + : cpl_mask_get_data_const(other->bpm); filter_func = NULL; if (filter == CPL_FILTER_LINEAR || filter == CPL_FILTER_LINEAR_SCALE) { - cpl_ensure_code(border == CPL_BORDER_FILTER, CPL_ERROR_UNSUPPORTED_MODE); dodiv = filter == CPL_FILTER_LINEAR; switch (cpl_image_get_type(self)) { - case CPL_TYPE_DOUBLE: { - switch (cpl_image_get_type(other)) { - case CPL_TYPE_DOUBLE: - filter_func = cpl_filter_linear_slow_double_double; - break; - case CPL_TYPE_FLOAT: - filter_func = cpl_filter_linear_slow_double_float; - break; - case CPL_TYPE_INT: - filter_func = cpl_filter_linear_slow_double_int; - break; - default: - /* + case CPL_TYPE_DOUBLE: { + switch (cpl_image_get_type(other)) { + case CPL_TYPE_DOUBLE: + filter_func = cpl_filter_linear_slow_double_double; + break; + case CPL_TYPE_FLOAT: + filter_func = cpl_filter_linear_slow_double_float; + break; + case CPL_TYPE_INT: + filter_func = cpl_filter_linear_slow_double_int; + break; + default: + /* * Currently, it is an error in CPL to reach this point, as all * possible types for images (see cpl_image_new()) are supported. * @@ -1075,76 +1077,74 @@ * in this function. For that case, we keep setting the appropriate * error code in this default section. */ - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); - } - - break; - } + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + } - case CPL_TYPE_FLOAT: { - switch (cpl_image_get_type(other)) { - case CPL_TYPE_DOUBLE: - filter_func = cpl_filter_linear_slow_float_double; break; - case CPL_TYPE_FLOAT: - filter_func = cpl_filter_linear_slow_float_float; - break; - case CPL_TYPE_INT: - filter_func = cpl_filter_linear_slow_float_int; + } + + case CPL_TYPE_FLOAT: { + switch (cpl_image_get_type(other)) { + case CPL_TYPE_DOUBLE: + filter_func = cpl_filter_linear_slow_float_double; + break; + case CPL_TYPE_FLOAT: + filter_func = cpl_filter_linear_slow_float_float; + break; + case CPL_TYPE_INT: + filter_func = cpl_filter_linear_slow_float_int; + break; + default: + /* See comment in previous switch() default: */ + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + } break; - default: - /* See comment in previous switch() default: */ - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } - break; - } - case CPL_TYPE_INT: { - switch (cpl_image_get_type(other)) { - case CPL_TYPE_DOUBLE: - filter_func = cpl_filter_linear_slow_int_double; - break; - case CPL_TYPE_FLOAT: - filter_func = cpl_filter_linear_slow_int_float; - break; - case CPL_TYPE_INT: - filter_func = cpl_filter_linear_slow_int_int; + case CPL_TYPE_INT: { + switch (cpl_image_get_type(other)) { + case CPL_TYPE_DOUBLE: + filter_func = cpl_filter_linear_slow_int_double; + break; + case CPL_TYPE_FLOAT: + filter_func = cpl_filter_linear_slow_int_float; + break; + case CPL_TYPE_INT: + filter_func = cpl_filter_linear_slow_int_int; + break; + default: + /* See comment in previous switch() default: */ + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + } break; + } + default: /* See comment in previous switch() default: */ return cpl_error_set_(CPL_ERROR_INVALID_TYPE); - } - break; - } - - default: - /* See comment in previous switch() default: */ - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } - - } else if (filter == CPL_FILTER_MORPHO || - filter == CPL_FILTER_MORPHO_SCALE) { - + } + else if (filter == CPL_FILTER_MORPHO || filter == CPL_FILTER_MORPHO_SCALE) { cpl_ensure_code(border == CPL_BORDER_FILTER, CPL_ERROR_UNSUPPORTED_MODE); dodiv = filter == CPL_FILTER_MORPHO; switch (cpl_image_get_type(self)) { - case CPL_TYPE_DOUBLE: { - switch (cpl_image_get_type(other)) { - case CPL_TYPE_DOUBLE: - filter_func = cpl_filter_morpho_slow_double_double; - break; - case CPL_TYPE_FLOAT: - filter_func = cpl_filter_morpho_slow_double_float; - break; - case CPL_TYPE_INT: - filter_func = cpl_filter_morpho_slow_double_int; - break; - default: - /* + case CPL_TYPE_DOUBLE: { + switch (cpl_image_get_type(other)) { + case CPL_TYPE_DOUBLE: + filter_func = cpl_filter_morpho_slow_double_double; + break; + case CPL_TYPE_FLOAT: + filter_func = cpl_filter_morpho_slow_double_float; + break; + case CPL_TYPE_INT: + filter_func = cpl_filter_morpho_slow_double_int; + break; + default: + /* * Currently, it is an error in CPL to reach this point, as all * possible types for images (see cpl_image_new()) are supported. * @@ -1153,61 +1153,60 @@ * in this function. For that case, we keep setting the appropriate * error code in this default section. */ - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); - } - - break; - } + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + } - case CPL_TYPE_FLOAT: { - switch (cpl_image_get_type(other)) { - case CPL_TYPE_DOUBLE: - filter_func = cpl_filter_morpho_slow_float_double; break; - case CPL_TYPE_FLOAT: - filter_func = cpl_filter_morpho_slow_float_float; - break; - case CPL_TYPE_INT: - filter_func = cpl_filter_morpho_slow_float_int; + } + + case CPL_TYPE_FLOAT: { + switch (cpl_image_get_type(other)) { + case CPL_TYPE_DOUBLE: + filter_func = cpl_filter_morpho_slow_float_double; + break; + case CPL_TYPE_FLOAT: + filter_func = cpl_filter_morpho_slow_float_float; + break; + case CPL_TYPE_INT: + filter_func = cpl_filter_morpho_slow_float_int; + break; + default: + /* See comment in previous switch() default: */ + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + } break; - default: - /* See comment in previous switch() default: */ - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } - break; - } - case CPL_TYPE_INT: { - switch (cpl_image_get_type(other)) { - case CPL_TYPE_DOUBLE: - filter_func = cpl_filter_morpho_slow_int_double; - break; - case CPL_TYPE_FLOAT: - filter_func = cpl_filter_morpho_slow_int_float; - break; - case CPL_TYPE_INT: - filter_func = cpl_filter_morpho_slow_int_int; + case CPL_TYPE_INT: { + switch (cpl_image_get_type(other)) { + case CPL_TYPE_DOUBLE: + filter_func = cpl_filter_morpho_slow_int_double; + break; + case CPL_TYPE_FLOAT: + filter_func = cpl_filter_morpho_slow_int_float; + break; + case CPL_TYPE_INT: + filter_func = cpl_filter_morpho_slow_int_int; + break; + default: + /* See comment in previous switch() default: */ + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + } break; + } + default: /* See comment in previous switch() default: */ return cpl_error_set_(CPL_ERROR_INVALID_TYPE); - } - break; - } - - default: - /* See comment in previous switch() default: */ - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } } cpl_ensure_code(filter_func != NULL, CPL_ERROR_UNSUPPORTED_MODE); if (filter_func(cpl_image_get_data(self), &pbpmself, - cpl_image_get_data_const(other), badmap, - pkernel, nx, ny, dodiv, - hsizex, hsizey, border)) { + cpl_image_get_data_const(other), badmap, pkernel, nx, ny, + dodiv, hsizex, hsizey, border)) { return cpl_error_set_where_(); } @@ -1217,7 +1216,6 @@ } return CPL_ERROR_NONE; - } @@ -1234,17 +1232,16 @@ */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_filter_linear(const cpl_image * in, - const cpl_matrix * ker) +cpl_image * +cpl_image_filter_linear(const cpl_image *in, const cpl_matrix *ker) { - cpl_image * self; + cpl_image *self; - cpl_ensure(in != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(in != NULL, CPL_ERROR_NULL_INPUT, NULL); self = cpl_image_new(in->nx, in->ny, in->type); - if (cpl_image_filter(self, in, ker, CPL_FILTER_LINEAR, - CPL_BORDER_FILTER)) { + if (cpl_image_filter(self, in, ker, CPL_FILTER_LINEAR, CPL_BORDER_FILTER)) { cpl_image_delete(self); self = NULL; (void)cpl_error_set_where_(); @@ -1266,17 +1263,16 @@ */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_filter_morpho(const cpl_image * in, - const cpl_matrix * ker) +cpl_image * +cpl_image_filter_morpho(const cpl_image *in, const cpl_matrix *ker) { - cpl_image * self; + cpl_image *self; - cpl_ensure(in != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(in != NULL, CPL_ERROR_NULL_INPUT, NULL); self = cpl_image_new(in->nx, in->ny, in->type); - if (cpl_image_filter(self, in, ker, CPL_FILTER_MORPHO, - CPL_BORDER_FILTER)) { + if (cpl_image_filter(self, in, ker, CPL_FILTER_MORPHO, CPL_BORDER_FILTER)) { cpl_image_delete(self); self = NULL; (void)cpl_error_set_where_(); @@ -1298,14 +1294,13 @@ */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_filter_median(const cpl_image * in, - const cpl_matrix * ker) +cpl_image * +cpl_image_filter_median(const cpl_image *in, const cpl_matrix *ker) { + cpl_image *self; + cpl_mask *mask; - cpl_image * self; - cpl_mask * mask; - - cpl_ensure(in != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(in != NULL, CPL_ERROR_NULL_INPUT, NULL); mask = cpl_mask_new_from_matrix(ker, 1.0, 1e-5); @@ -1338,14 +1333,13 @@ */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_filter_stdev(const cpl_image * in, - const cpl_matrix * ker) +cpl_image * +cpl_image_filter_stdev(const cpl_image *in, const cpl_matrix *ker) { + cpl_image *self; + cpl_mask *mask; - cpl_image * self; - cpl_mask * mask; - - cpl_ensure(in != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(in != NULL, CPL_ERROR_NULL_INPUT, NULL); mask = cpl_mask_new_from_matrix(ker, 1.0, 1e-5); @@ -1364,7 +1358,6 @@ cpl_mask_delete(mask); return self; - } /*----------------------------------------------------------------------------*/ @@ -1389,25 +1382,25 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -static cpl_mask * cpl_mask_new_from_matrix(const cpl_matrix * kernel, - double value, double tol) +static cpl_mask * +cpl_mask_new_from_matrix(const cpl_matrix *kernel, double value, double tol) { - - const cpl_size nx = cpl_matrix_get_ncol(kernel); - const cpl_size ny = cpl_matrix_get_nrow(kernel); - const cpl_size n = nx * ny; - const double * data = cpl_matrix_get_data_const(kernel); - cpl_mask * self; - cpl_binary * pself; - cpl_size i; + const cpl_size nx = cpl_matrix_get_ncol(kernel); + const cpl_size ny = cpl_matrix_get_nrow(kernel); + const cpl_size n = nx * ny; + const double *data = cpl_matrix_get_data_const(kernel); + cpl_mask *self; + cpl_binary *pself; + cpl_size i; cpl_ensure(kernel != NULL, CPL_ERROR_NULL_INPUT, NULL); - self = cpl_mask_new(nx, ny); + self = cpl_mask_new(nx, ny); pself = cpl_mask_get_data(self); - for (i=0; i < n; i++) { - if (fabs(data[i] - value) < tol) pself[i] = CPL_BINARY_1; + for (i = 0; i < n; i++) { + if (fabs(data[i] - value) < tol) + pself[i] = CPL_BINARY_1; } return self; diff -Nru cpl-7.1.4+ds/cplcore/cpl_image_filter.h cpl-7.2.2+ds/cplcore/cpl_image_filter.h --- cpl-7.1.4+ds/cplcore/cpl_image_filter.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_image_filter.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -34,23 +34,27 @@ Function prototypes -----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_filter_mask(cpl_image *, const cpl_image *, +cpl_error_code cpl_image_filter_mask(cpl_image *, + const cpl_image *, const cpl_mask *, - cpl_filter_mode, cpl_border_mode); + cpl_filter_mode, + cpl_border_mode); -cpl_error_code cpl_image_filter(cpl_image *, const cpl_image *, +cpl_error_code cpl_image_filter(cpl_image *, + const cpl_image *, const cpl_matrix *, - cpl_filter_mode, cpl_border_mode); + cpl_filter_mode, + cpl_border_mode); -cpl_image * cpl_image_filter_linear(const cpl_image *, const cpl_matrix *) - CPL_ATTR_DEPRECATED; -cpl_image * cpl_image_filter_morpho(const cpl_image *, const cpl_matrix *) - CPL_ATTR_DEPRECATED; -cpl_image * cpl_image_filter_median(const cpl_image *, const cpl_matrix *) - CPL_ATTR_DEPRECATED; -cpl_image * cpl_image_filter_stdev(const cpl_image *, const cpl_matrix *) - CPL_ATTR_DEPRECATED; +cpl_image *cpl_image_filter_linear(const cpl_image *, + const cpl_matrix *) CPL_ATTR_DEPRECATED; +cpl_image *cpl_image_filter_morpho(const cpl_image *, + const cpl_matrix *) CPL_ATTR_DEPRECATED; +cpl_image *cpl_image_filter_median(const cpl_image *, + const cpl_matrix *) CPL_ATTR_DEPRECATED; +cpl_image *cpl_image_filter_stdev(const cpl_image *, + const cpl_matrix *) CPL_ATTR_DEPRECATED; CPL_END_DECLS -#endif +#endif diff -Nru cpl-7.1.4+ds/cplcore/cpl_image_filter_impl.h cpl-7.2.2+ds/cplcore/cpl_image_filter_impl.h --- cpl-7.1.4+ds/cplcore/cpl_image_filter_impl.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_image_filter_impl.h 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -31,25 +31,33 @@ /*----------------------------------------------------------------------------- Function prototypes -----------------------------------------------------------------------------*/ -void -cpl_image_filter_fill_chess_double(double *in_larger, const double *in, - unsigned Nx_larger, unsigned Ny_larger, - unsigned Nx, unsigned Ny, - unsigned rx, unsigned ry); - -void -cpl_image_filter_fill_chess_float(float *in_larger, const float *in, - unsigned Nx_larger, unsigned Ny_larger, - unsigned Nx, unsigned Ny, - unsigned rx, unsigned ry); - -void -cpl_image_filter_fill_chess_int(int *in_larger, const int *in, - unsigned Nx_larger, unsigned Ny_larger, - unsigned Nx, unsigned Ny, - unsigned rx, unsigned ry); +void cpl_image_filter_fill_chess_double(double *in_larger, + const double *in, + unsigned Nx_larger, + unsigned Ny_larger, + unsigned Nx, + unsigned Ny, + unsigned rx, + unsigned ry); + +void cpl_image_filter_fill_chess_float(float *in_larger, + const float *in, + unsigned Nx_larger, + unsigned Ny_larger, + unsigned Nx, + unsigned Ny, + unsigned rx, + unsigned ry); + +void cpl_image_filter_fill_chess_int(int *in_larger, + const int *in, + unsigned Nx_larger, + unsigned Ny_larger, + unsigned Nx, + unsigned Ny, + unsigned rx, + unsigned ry); CPL_END_DECLS -#endif - +#endif diff -Nru cpl-7.1.4+ds/cplcore/cpl_image_gen_body.h cpl-7.2.2+ds/cplcore/cpl_image_gen_body.h --- cpl-7.1.4+ds/cplcore/cpl_image_gen_body.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_image_gen_body.h 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -19,28 +19,28 @@ /* Type dependent macros */ #if CPL_CLASS == CPL_CLASS_DOUBLE -#define CPL_TYPE double -#define CPL_TYPE_T CPL_TYPE_DOUBLE +#define CPL_TYPE double +#define CPL_TYPE_T CPL_TYPE_DOUBLE #define CPL_TYPE_IS_COMPLEX FALSE #elif CPL_CLASS == CPL_CLASS_FLOAT -#define CPL_TYPE float -#define CPL_TYPE_T CPL_TYPE_FLOAT +#define CPL_TYPE float +#define CPL_TYPE_T CPL_TYPE_FLOAT #define CPL_TYPE_IS_COMPLEX FALSE #elif CPL_CLASS == CPL_CLASS_INT -#define CPL_TYPE int -#define CPL_TYPE_T CPL_TYPE_INT +#define CPL_TYPE int +#define CPL_TYPE_T CPL_TYPE_INT #define CPL_TYPE_IS_COMPLEX FALSE #elif CPL_CLASS == CPL_CLASS_DOUBLE_COMPLEX -#define CPL_TYPE double complex -#define CPL_TYPE_T CPL_TYPE_DOUBLE_COMPLEX +#define CPL_TYPE double complex +#define CPL_TYPE_T CPL_TYPE_DOUBLE_COMPLEX #define CPL_TYPE_IS_COMPLEX TRUE #elif CPL_CLASS == CPL_CLASS_FLOAT_COMPLEX -#define CPL_TYPE float complex -#define CPL_TYPE_T CPL_TYPE_FLOAT_COMPLEX +#define CPL_TYPE float complex +#define CPL_TYPE_T CPL_TYPE_FLOAT_COMPLEX #define CPL_TYPE_IS_COMPLEX TRUE #else @@ -51,78 +51,74 @@ #if CPL_OPERATION == CPL_IMAGE_GEN_NOISE_UNIFORM && !CPL_TYPE_IS_COMPLEX - case CPL_TYPE_T: - { - CPL_TYPE * pi; - pi = (CPL_TYPE*)ima->pixels; - - /* Compute the pixels values */ - for (j=0; jny; j++) - for (i=0; inx; i++) - pi[i+j*ima->nx] = - (CPL_TYPE)(min_pix + cpl_drand()*(max_pix-min_pix)); - break; - } +case CPL_TYPE_T: { + CPL_TYPE *pi; + pi = (CPL_TYPE *)ima->pixels; + + /* Compute the pixels values */ + for (j = 0; j < ima->ny; j++) + for (i = 0; i < ima->nx; i++) + pi[i + j * ima->nx] = + (CPL_TYPE)(min_pix + cpl_drand() * (max_pix - min_pix)); + break; +} #elif CPL_OPERATION == CPL_IMAGE_GEN_NOISE_UNIFORM && CPL_TYPE_IS_COMPLEX - case CPL_TYPE_T: - { - CPL_TYPE * pi; - pi = (CPL_TYPE*)ima->pixels; - - /* Compute the pixels values */ - for (j=0; jny; j++) - for (i=0; inx; i++) - pi[i+j*ima->nx] = (CPL_TYPE) - ( +case CPL_TYPE_T: { + CPL_TYPE *pi; + pi = (CPL_TYPE *)ima->pixels; + + /* Compute the pixels values */ + for (j = 0; j < ima->ny; j++) + for (i = 0; i < ima->nx; i++) + pi[i + j * ima->nx] = (CPL_TYPE)( #ifdef CPL_I - /* The complex image will only have complex values + /* The complex image will only have complex values when those are supported */ - (min_pix + cpl_drand() * (max_pix - min_pix)) * CPL_I + + (min_pix + cpl_drand() * (max_pix - min_pix)) * CPL_I + #endif - (min_pix + cpl_drand() * (max_pix - min_pix))); - break; - } + (min_pix + cpl_drand() * (max_pix - min_pix))); + break; +} #elif CPL_OPERATION == CPL_IMAGE_GEN_GAUSSIAN - - case CPL_TYPE_T: - { - CPL_TYPE * pi; - pi = (CPL_TYPE*)ima->pixels; - - /* Compute the pixels values */ - for (j=0; jny; j++) { - for (i=0; inx; i++) { - x = (double)(i+1) - (double)xcen; - y = (double)(j+1) - (double)ycen; - pi[i+j*ima->nx]=(CPL_TYPE)cpl_gaussian_2d(x,y,norm,sig_x,sig_y); - } + +case CPL_TYPE_T: { + CPL_TYPE *pi; + pi = (CPL_TYPE *)ima->pixels; + + /* Compute the pixels values */ + for (j = 0; j < ima->ny; j++) { + for (i = 0; i < ima->nx; i++) { + x = (double)(i + 1) - (double)xcen; + y = (double)(j + 1) - (double)ycen; + pi[i + j * ima->nx] = + (CPL_TYPE)cpl_gaussian_2d(x, y, norm, sig_x, sig_y); } - break; } - + break; +} + #elif CPL_OPERATION == CPL_IMAGE_GEN_POLYNOMIAL - - case CPL_TYPE_T: - { - CPL_TYPE * pi; - pi = (CPL_TYPE*)ima->pixels; - - /* Compute the pixels values */ - x = cpl_vector_new(2); - xdata = cpl_vector_get_data(x); - for (j=0; jny; j++) { - for (i=0; inx; i++) { - xdata[0] = (double)(startx + i * stepx); - xdata[1] = (double)(starty + j * stepy); - pi[i+j*ima->nx] = (CPL_TYPE)cpl_polynomial_eval(poly, x); - } + +case CPL_TYPE_T: { + CPL_TYPE *pi; + pi = (CPL_TYPE *)ima->pixels; + + /* Compute the pixels values */ + x = cpl_vector_new(2); + xdata = cpl_vector_get_data(x); + for (j = 0; j < ima->ny; j++) { + for (i = 0; i < ima->nx; i++) { + xdata[0] = (double)(startx + i * stepx); + xdata[1] = (double)(starty + j * stepy); + pi[i + j * ima->nx] = (CPL_TYPE)cpl_polynomial_eval(poly, x); } - cpl_vector_delete(x); - break; } + cpl_vector_delete(x); + break; +} #endif diff -Nru cpl-7.1.4+ds/cplcore/cpl_image_gen.c cpl-7.2.2+ds/cplcore/cpl_image_gen.c --- cpl-7.1.4+ds/cplcore/cpl_image_gen.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_image_gen.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -44,9 +44,9 @@ Defines -----------------------------------------------------------------------------*/ -#define CPL_IMAGE_GEN_NOISE_UNIFORM 1 -#define CPL_IMAGE_GEN_GAUSSIAN 2 -#define CPL_IMAGE_GEN_POLYNOMIAL 3 +#define CPL_IMAGE_GEN_NOISE_UNIFORM 1 +#define CPL_IMAGE_GEN_GAUSSIAN 2 +#define CPL_IMAGE_GEN_POLYNOMIAL 3 #define CPL_IMAGE_GEN_NBPOINTS 10 @@ -92,17 +92,15 @@ - CPL_ERROR_INVALID_TYPE if the passed image type is not supported */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_fill_noise_uniform( - cpl_image * ima, - double min_pix, - double max_pix) +cpl_error_code +cpl_image_fill_noise_uniform(cpl_image *ima, double min_pix, double max_pix) { - int i, j; + int i, j; /* Test entries */ cpl_ensure_code(ima, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(min_pixtype) { #define CPL_CLASS CPL_CLASS_DOUBLE @@ -121,7 +119,7 @@ #include "cpl_image_gen_body.h" #undef CPL_CLASS default: - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } return CPL_ERROR_NONE; } @@ -156,17 +154,17 @@ - CPL_ERROR_INVALID_TYPE if the passed image type is not supported */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_fill_gaussian( - cpl_image * ima, - double xcen, - double ycen, - double norm, - double sig_x, - double sig_y) +cpl_error_code +cpl_image_fill_gaussian(cpl_image *ima, + double xcen, + double ycen, + double norm, + double sig_x, + double sig_y) { - double x, y; - int i, j; - + double x, y; + int i, j; + /* Test entries */ cpl_ensure_code(ima, CPL_ERROR_NULL_INPUT); @@ -179,7 +177,7 @@ #include "cpl_image_gen_body.h" #undef CPL_CLASS default: - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } return CPL_ERROR_NONE; } @@ -214,22 +212,22 @@ - CPL_ERROR_INVALID_TYPE if the passed image type is not supported */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_fill_polynomial( - cpl_image * ima, - const cpl_polynomial * poly, - double startx, - double stepx, - double starty, - double stepy) +cpl_error_code +cpl_image_fill_polynomial(cpl_image *ima, + const cpl_polynomial *poly, + double startx, + double stepx, + double starty, + double stepy) { - cpl_vector * x; - double * xdata; - int i, j; + cpl_vector *x; + double *xdata; + int i, j; /* Test entries */ cpl_ensure_code(ima && poly, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(cpl_polynomial_get_dimension(poly) == 2, - CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(cpl_polynomial_get_dimension(poly) == 2, + CPL_ERROR_ILLEGAL_INPUT); /* Switch on image type */ switch (ima->type) { @@ -240,7 +238,7 @@ #include "cpl_image_gen_body.h" #undef CPL_CLASS default: - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } return CPL_ERROR_NONE; } @@ -262,42 +260,42 @@ */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_fill_test_create(cpl_size nx, - cpl_size ny) +cpl_image * +cpl_image_fill_test_create(cpl_size nx, cpl_size ny) { + const double xposrate[] = { + 0.4, 0.5, 0.8, 0.9, 0.2, 0.5, 0.9, 0.3, 0.1, 0.7 + }; - const double xposrate[] - = {0.4, 0.5, 0.8, 0.9, 0.2, 0.5, 0.9, 0.3, 0.1, 0.7}; + const double yposrate[10] = { 0.4, 0.2, 0.3, 0.9, 0.7, + 0.8, 0.9, 0.8, 0.7, 0.7 }; - const double yposrate[10] - = {0.4, 0.2, 0.3, 0.9, 0.7, 0.8, 0.9, 0.8, 0.7, 0.7}; + double xpos[CPL_IMAGE_GEN_NBPOINTS]; + double ypos[CPL_IMAGE_GEN_NBPOINTS]; - double xpos[CPL_IMAGE_GEN_NBPOINTS]; - double ypos[CPL_IMAGE_GEN_NBPOINTS]; - - cpl_image * test_im = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE); - cpl_image * tmp_im = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE); + cpl_image *test_im = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE); + cpl_image *tmp_im = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE); const cpl_size nbpoints = CPL_IMAGE_GEN_NBPOINTS; - const double sigma = 10.0; - const double flux = 1000.0; - cpl_size i; + const double sigma = 10.0; + const double flux = 1000.0; + cpl_size i; cpl_ensure(nx > 0, CPL_ERROR_ILLEGAL_INPUT, NULL); cpl_ensure(ny > 0, CPL_ERROR_ILLEGAL_INPUT, NULL); - for (i=0; i < nbpoints; i++) { + for (i = 0; i < nbpoints; i++) { xpos[i] = (double)nx * xposrate[i]; ypos[i] = (double)ny * yposrate[i]; } - + /* Set the background */ cpl_image_fill_noise_uniform(test_im, -1, 1); - + /* Put fake stars */ for (i = 0; i < nbpoints; i++) { cpl_image_fill_gaussian(tmp_im, xpos[i], ypos[i], 10.0, sigma, sigma); - cpl_image_multiply_scalar(tmp_im, flux / (double)(i+1)); + cpl_image_multiply_scalar(tmp_im, flux / (double)(i + 1)); cpl_image_add(test_im, tmp_im); } @@ -324,14 +322,10 @@ exp(-y^2/(2*sig_y^2)) */ /*----------------------------------------------------------------------------*/ -static double cpl_gaussian_2d(double x, - double y, - double norm, - double sig_x, - double sig_y) +static double +cpl_gaussian_2d(double x, double y, double norm, double sig_x, double sig_y) { - return norm / (sig_x * sig_y * CPL_MATH_2PI * - exp(x * x / (2.0 * sig_x * sig_x) + - y * y / (2.0 * sig_y * sig_y))); + return norm / + (sig_x * sig_y * CPL_MATH_2PI * + exp(x * x / (2.0 * sig_x * sig_x) + y * y / (2.0 * sig_y * sig_y))); } - diff -Nru cpl-7.1.4+ds/cplcore/cpl_image_gen.h cpl-7.2.2+ds/cplcore/cpl_image_gen.h --- cpl-7.1.4+ds/cplcore/cpl_image_gen.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_image_gen.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -34,12 +34,16 @@ -----------------------------------------------------------------------------*/ cpl_error_code cpl_image_fill_noise_uniform(cpl_image *, double, double); -cpl_error_code cpl_image_fill_gaussian(cpl_image *, double, double, double, - double, double); -cpl_error_code cpl_image_fill_polynomial(cpl_image *, const cpl_polynomial *, - double, double, double, double); -cpl_image * cpl_image_fill_test_create(cpl_size, cpl_size) CPL_ATTR_ALLOC; +cpl_error_code +cpl_image_fill_gaussian(cpl_image *, double, double, double, double, double); +cpl_error_code cpl_image_fill_polynomial(cpl_image *, + const cpl_polynomial *, + double, + double, + double, + double); +cpl_image *cpl_image_fill_test_create(cpl_size, cpl_size) CPL_ATTR_ALLOC; CPL_END_DECLS -#endif +#endif diff -Nru cpl-7.1.4+ds/cplcore/cpl_image.h cpl-7.2.2+ds/cplcore/cpl_image.h --- cpl-7.1.4+ds/cplcore/cpl_image.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_image.h 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -63,4 +63,4 @@ */ /*----------------------------------------------------------------------------*/ -#endif +#endif diff -Nru cpl-7.1.4+ds/cplcore/cpl_image_io_body.h cpl-7.2.2+ds/cplcore/cpl_image_io_body.h --- cpl-7.1.4+ds/cplcore/cpl_image_io_body.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_image_io_body.h 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -19,124 +19,130 @@ #if defined(CPL_OPERATION) && CPL_OPERATION == CPL_IMAGE_IO_RE_IM - if (preal != NULL && pimag != NULL) { - const size_t nxy = (size_t)(self->nx * self->ny); - size_t i; - - for (i = 0; i < nxy; i++) { - preal[i] = CPL_CREAL(pself[i]); - pimag[i] = CPL_CIMAG(pself[i]); - } - } else { - error = CPL_ERROR_TYPE_MISMATCH; - } +if (preal != NULL && pimag != NULL) { + const size_t nxy = (size_t)(self->nx * self->ny); + size_t i; + + for (i = 0; i < nxy; i++) { + preal[i] = CPL_CREAL(pself[i]); + pimag[i] = CPL_CIMAG(pself[i]); + } +} +else { + error = CPL_ERROR_TYPE_MISMATCH; +} #elif defined(CPL_OPERATION) && CPL_OPERATION == CPL_IMAGE_IO_RE - if (preal != NULL) { - const size_t nxy = (size_t)(self->nx * self->ny); - size_t i; - - for (i = 0; i < nxy; i++) { - preal[i] = CPL_CREAL(pself[i]); - } - } else { - error = CPL_ERROR_TYPE_MISMATCH; - } +if (preal != NULL) { + const size_t nxy = (size_t)(self->nx * self->ny); + size_t i; + + for (i = 0; i < nxy; i++) { + preal[i] = CPL_CREAL(pself[i]); + } +} +else { + error = CPL_ERROR_TYPE_MISMATCH; +} #elif defined(CPL_OPERATION) && CPL_OPERATION == CPL_IMAGE_IO_IM - if (pimag != NULL) { - const size_t nxy = (size_t)(self->nx * self->ny); - size_t i; - - for (i = 0; i < nxy; i++) { - pimag[i] = CPL_CIMAG(pself[i]); - } - } else { - error = CPL_ERROR_TYPE_MISMATCH; - } +if (pimag != NULL) { + const size_t nxy = (size_t)(self->nx * self->ny); + size_t i; + + for (i = 0; i < nxy; i++) { + pimag[i] = CPL_CIMAG(pself[i]); + } +} +else { + error = CPL_ERROR_TYPE_MISMATCH; +} #elif defined(CPL_OPERATION) && CPL_OPERATION == CPL_IMAGE_IO_ABS_ARG - if (pabs != NULL && parg != NULL) { - const size_t nxy = (size_t)(self->nx * self->ny); - size_t i; - - for (i = 0; i < nxy; i++) { - pabs[i] = CPL_CABS(pself[i]); - parg[i] = CPL_CARG(pself[i]); - } - } else { - error = CPL_ERROR_TYPE_MISMATCH; - } +if (pabs != NULL && parg != NULL) { + const size_t nxy = (size_t)(self->nx * self->ny); + size_t i; + + for (i = 0; i < nxy; i++) { + pabs[i] = CPL_CABS(pself[i]); + parg[i] = CPL_CARG(pself[i]); + } +} +else { + error = CPL_ERROR_TYPE_MISMATCH; +} #elif defined(CPL_OPERATION) && CPL_OPERATION == CPL_IMAGE_IO_ABS - if (pabs != NULL) { - const size_t nxy = (size_t)(self->nx * self->ny); - size_t i; - - for (i = 0; i < nxy; i++) { - pabs[i] = CPL_CABS(pself[i]); - } - } else { - error = CPL_ERROR_TYPE_MISMATCH; - } +if (pabs != NULL) { + const size_t nxy = (size_t)(self->nx * self->ny); + size_t i; + + for (i = 0; i < nxy; i++) { + pabs[i] = CPL_CABS(pself[i]); + } +} +else { + error = CPL_ERROR_TYPE_MISMATCH; +} #elif defined(CPL_OPERATION) && CPL_OPERATION == CPL_IMAGE_IO_ARG - if (parg != NULL) { - const size_t nxy = (size_t)(self->nx * self->ny); - size_t i; - - for (i = 0; i < nxy; i++) { - parg[i] = CPL_CARG(pself[i]); - } - } else { - error = CPL_ERROR_TYPE_MISMATCH; - } +if (parg != NULL) { + const size_t nxy = (size_t)(self->nx * self->ny); + size_t i; + + for (i = 0; i < nxy; i++) { + parg[i] = CPL_CARG(pself[i]); + } +} +else { + error = CPL_ERROR_TYPE_MISMATCH; +} #else /* Type dependent macros */ #if defined CPL_CLASS && CPL_CLASS == CPL_CLASS_DOUBLE -#define CPL_TYPE double +#define CPL_TYPE double /* Cannot concatenate the reserved macro complex :-( */ -#define CPL_TYPE_C double_complex -#define CPL_TYPE_T CPL_TYPE_DOUBLE -#define CPL_CONJ conj -#define CPL_CREAL creal -#define CPL_CIMAG cimag -#define CPL_CABS cabs -#define CPL_CARG carg -#define CPL_CFITSIO_TYPE TDOUBLE +#define CPL_TYPE_C double_complex +#define CPL_TYPE_T CPL_TYPE_DOUBLE +#define CPL_CONJ conj +#define CPL_CREAL creal +#define CPL_CIMAG cimag +#define CPL_CABS cabs +#define CPL_CARG carg +#define CPL_CFITSIO_TYPE TDOUBLE #elif defined CPL_CLASS && CPL_CLASS == CPL_CLASS_FLOAT -#define CPL_TYPE float +#define CPL_TYPE float /* Cannot concatenate the reserved macro complex :-( */ -#define CPL_TYPE_C float_complex -#define CPL_TYPE_T CPL_TYPE_FLOAT -#define CPL_CONJ conjf -#define CPL_CREAL crealf -#define CPL_CIMAG cimagf -#define CPL_CABS cabsf -#define CPL_CARG cargf -#define CPL_CFITSIO_TYPE TFLOAT +#define CPL_TYPE_C float_complex +#define CPL_TYPE_T CPL_TYPE_FLOAT +#define CPL_CONJ conjf +#define CPL_CREAL crealf +#define CPL_CIMAG cimagf +#define CPL_CABS cabsf +#define CPL_CARG cargf +#define CPL_CFITSIO_TYPE TFLOAT #elif defined CPL_CLASS && CPL_CLASS == CPL_CLASS_INT -#define CPL_TYPE int -#define CPL_TYPE_T CPL_TYPE_INT -#define CPL_CFITSIO_TYPE TINT +#define CPL_TYPE int +#define CPL_TYPE_T CPL_TYPE_INT +#define CPL_CFITSIO_TYPE TINT #elif defined CPL_CLASS && CPL_CLASS == CPL_CLASS_DOUBLE_COMPLEX -#define CPL_TYPE double complex -#define CPL_TYPE_T CPL_TYPE_DOUBLE_COMPLEX +#define CPL_TYPE double complex +#define CPL_TYPE_T CPL_TYPE_DOUBLE_COMPLEX /* NOTE: Saving unsupported */ #elif defined CPL_CLASS && CPL_CLASS == CPL_CLASS_FLOAT_COMPLEX -#define CPL_TYPE float complex -#define CPL_TYPE_T CPL_TYPE_FLOAT_COMPLEX +#define CPL_TYPE float complex +#define CPL_TYPE_T CPL_TYPE_FLOAT_COMPLEX /* NOTE: Saving unsupported */ #else @@ -145,49 +151,50 @@ #undef CPL_CFITSIO_TYPE #endif -#define CPL_TYPE_ADD(a) CPL_CONCAT2X(a, CPL_TYPE) -#define CPL_TYPE_ADD_CONST(a) CPL_CONCAT3X(a, CPL_TYPE, const) -#define CPL_TYPE_ADD_COMPLEX(a) CPL_CONCAT2X(a, CPL_TYPE_C) +#define CPL_TYPE_ADD(a) CPL_CONCAT2X(a, CPL_TYPE) +#define CPL_TYPE_ADD_CONST(a) CPL_CONCAT3X(a, CPL_TYPE, const) +#define CPL_TYPE_ADD_COMPLEX(a) CPL_CONCAT2X(a, CPL_TYPE_C) #define CPL_TYPE_ADD_COMPLEX_CONST(a) CPL_CONCAT3X(a, CPL_TYPE_C, const) #if defined(CPL_OPERATION) && CPL_OPERATION == CPL_IMAGE_IO_GET - case CPL_TYPE_T: { - const CPL_TYPE * pi = (CPL_TYPE*)image->pixels; - value = (CPL_TYPE_RETURN)pi[pos]; - break; - } +case CPL_TYPE_T: { + const CPL_TYPE *pi = (CPL_TYPE *)image->pixels; + value = (CPL_TYPE_RETURN)pi[pos]; + break; +} #elif defined(CPL_OPERATION) && CPL_OPERATION == CPL_IMAGE_IO_SET - case CPL_TYPE_T: { - CPL_TYPE * pi = (CPL_TYPE*)image->pixels; - pi[pos] = (CPL_TYPE)value; - break; - } +case CPL_TYPE_T: { + CPL_TYPE *pi = (CPL_TYPE *)image->pixels; + pi[pos] = (CPL_TYPE)value; + break; +} #elif defined(CPL_OPERATION) && CPL_OPERATION == CPL_IMAGE_IO_GET_PIXELS - /* Test entries */ - cpl_ensure(img, CPL_ERROR_NULL_INPUT, NULL); - if (img->type != CPL_TYPE_T) { - (void)cpl_error_set_message_(CPL_ERROR_TYPE_MISMATCH, - "Expected pixel type %s, not %s", - cpl_type_get_name(CPL_TYPE_T), - cpl_type_get_name(img->type)); - return NULL; - } +/* Test entries */ +cpl_ensure(img, CPL_ERROR_NULL_INPUT, NULL); +if (img->type != CPL_TYPE_T) { + (void)cpl_error_set_message_(CPL_ERROR_TYPE_MISMATCH, + "Expected pixel type %s, not %s", + cpl_type_get_name(CPL_TYPE_T), + cpl_type_get_name(img->type)); + return NULL; +} - return (CPL_CONST CPL_TYPE*)img->pixels; +return (CPL_CONST CPL_TYPE *)img->pixels; #elif defined(CPL_OPERATION) && CPL_OPERATION == CPL_IMAGE_IO_SET_BADPIXEL - case CPL_TYPE_T: { - CPL_TYPE * pi = (CPL_TYPE*)im->pixels; - const CPL_TYPE acast = (const CPL_TYPE) a; - const size_t nxy = (size_t)(im->nx * im->ny); - size_t i; - - for (i = 0; i < nxy; i++) - if (pbpm[i] == CPL_BINARY_1) pi[i] = acast; - break; - } +case CPL_TYPE_T: { + CPL_TYPE *pi = (CPL_TYPE *)im->pixels; + const CPL_TYPE acast = (const CPL_TYPE)a; + const size_t nxy = (size_t)(im->nx * im->ny); + size_t i; + + for (i = 0; i < nxy; i++) + if (pbpm[i] == CPL_BINARY_1) + pi[i] = acast; + break; +} #elif !defined(CPL_OPERATION) @@ -195,25 +202,25 @@ cpl_image *, const cpl_image *); -static cpl_error_code CPL_TYPE_ADD(cpl_image_fill_re)(cpl_image *, - const cpl_image *); +static cpl_error_code + CPL_TYPE_ADD(cpl_image_fill_re)(cpl_image *, const cpl_image *); -static cpl_error_code CPL_TYPE_ADD(cpl_image_fill_im)(cpl_image *, - const cpl_image *); +static cpl_error_code + CPL_TYPE_ADD(cpl_image_fill_im)(cpl_image *, const cpl_image *); static cpl_error_code CPL_TYPE_ADD(cpl_image_fill_abs_arg)(cpl_image *, - cpl_image *, - const cpl_image *); + cpl_image *, + const cpl_image *); -static cpl_error_code CPL_TYPE_ADD(cpl_image_fill_abs)(cpl_image *, - const cpl_image *); +static cpl_error_code + CPL_TYPE_ADD(cpl_image_fill_abs)(cpl_image *, const cpl_image *); -static cpl_error_code CPL_TYPE_ADD(cpl_image_fill_arg)(cpl_image *, - const cpl_image *); +static cpl_error_code + CPL_TYPE_ADD(cpl_image_fill_arg)(cpl_image *, const cpl_image *); -static cpl_error_code CPL_TYPE_ADD(cpl_image_conjugate)(cpl_image *, - const cpl_image *) - CPL_ATTR_NONNULL; +static cpl_error_code + CPL_TYPE_ADD(cpl_image_conjugate)(cpl_image *, + const cpl_image *) CPL_ATTR_NONNULL; /*----------------------------------------------------------------------------*/ /** @@ -229,56 +236,54 @@ @see cpl_image_fill_re_im() */ /*----------------------------------------------------------------------------*/ -static cpl_error_code CPL_TYPE_ADD(cpl_image_fill_re_im)(cpl_image * im_real, - cpl_image * im_imag, - const cpl_image * self) +static cpl_error_code CPL_TYPE_ADD(cpl_image_fill_re_im)(cpl_image *im_real, + cpl_image *im_imag, + const cpl_image *self) { #define CPL_OPERATION CPL_IMAGE_IO_RE_IM - const CPL_TYPE complex * pself - = CPL_TYPE_ADD_COMPLEX_CONST(cpl_image_get_data)(self); + const CPL_TYPE complex *pself = + CPL_TYPE_ADD_COMPLEX_CONST(cpl_image_get_data)(self); cpl_error_code error = CPL_ERROR_NONE; cpl_ensure_code(im_real != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(im_imag != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(pself != NULL, CPL_ERROR_INVALID_TYPE); + cpl_ensure_code(pself != NULL, CPL_ERROR_INVALID_TYPE); if ((im_real->type & CPL_TYPE_COMPLEX) && (im_imag->type & CPL_TYPE_COMPLEX)) { - CPL_TYPE complex * preal - = CPL_TYPE_ADD_COMPLEX(cpl_image_get_data)(im_real); - CPL_TYPE complex * pimag - = CPL_TYPE_ADD_COMPLEX(cpl_image_get_data)(im_imag); + CPL_TYPE complex *preal = + CPL_TYPE_ADD_COMPLEX(cpl_image_get_data)(im_real); + CPL_TYPE complex *pimag = + CPL_TYPE_ADD_COMPLEX(cpl_image_get_data)(im_imag); #include "cpl_image_io_body.h" - - } else if (im_real->type & CPL_TYPE_COMPLEX) { - CPL_TYPE complex * preal - = CPL_TYPE_ADD_COMPLEX(cpl_image_get_data)(im_real); - CPL_TYPE * pimag = CPL_TYPE_ADD(cpl_image_get_data)(im_imag); + } + else if (im_real->type & CPL_TYPE_COMPLEX) { + CPL_TYPE complex *preal = + CPL_TYPE_ADD_COMPLEX(cpl_image_get_data)(im_real); + CPL_TYPE *pimag = CPL_TYPE_ADD(cpl_image_get_data)(im_imag); #include "cpl_image_io_body.h" - - } else if (im_imag->type & CPL_TYPE_COMPLEX) { - CPL_TYPE * preal = CPL_TYPE_ADD(cpl_image_get_data)(im_real); - CPL_TYPE complex * pimag - = CPL_TYPE_ADD_COMPLEX(cpl_image_get_data)(im_imag); + } + else if (im_imag->type & CPL_TYPE_COMPLEX) { + CPL_TYPE *preal = CPL_TYPE_ADD(cpl_image_get_data)(im_real); + CPL_TYPE complex *pimag = + CPL_TYPE_ADD_COMPLEX(cpl_image_get_data)(im_imag); #include "cpl_image_io_body.h" - - } else { - CPL_TYPE * preal = CPL_TYPE_ADD(cpl_image_get_data)(im_real); - CPL_TYPE * pimag = CPL_TYPE_ADD(cpl_image_get_data)(im_imag); + } + else { + CPL_TYPE *preal = CPL_TYPE_ADD(cpl_image_get_data)(im_real); + CPL_TYPE *pimag = CPL_TYPE_ADD(cpl_image_get_data)(im_imag); #include "cpl_image_io_body.h" - } return error ? cpl_error_set_(error) : CPL_ERROR_NONE; #undef CPL_OPERATION - } /*----------------------------------------------------------------------------*/ @@ -293,36 +298,34 @@ @see cpl_image_fill_re_im() */ /*----------------------------------------------------------------------------*/ -static cpl_error_code CPL_TYPE_ADD(cpl_image_fill_re)(cpl_image * im_real, - const cpl_image * self) +static cpl_error_code + CPL_TYPE_ADD(cpl_image_fill_re)(cpl_image *im_real, const cpl_image *self) { #define CPL_OPERATION CPL_IMAGE_IO_RE - const CPL_TYPE complex * pself - = CPL_TYPE_ADD_COMPLEX_CONST(cpl_image_get_data)(self); + const CPL_TYPE complex *pself = + CPL_TYPE_ADD_COMPLEX_CONST(cpl_image_get_data)(self); cpl_error_code error = CPL_ERROR_NONE; cpl_ensure_code(im_real != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(pself != NULL, CPL_ERROR_INVALID_TYPE); + cpl_ensure_code(pself != NULL, CPL_ERROR_INVALID_TYPE); if (im_real->type & CPL_TYPE_COMPLEX) { - CPL_TYPE complex * preal - = CPL_TYPE_ADD_COMPLEX(cpl_image_get_data)(im_real); + CPL_TYPE complex *preal = + CPL_TYPE_ADD_COMPLEX(cpl_image_get_data)(im_real); #include "cpl_image_io_body.h" - - } else { - CPL_TYPE * preal = CPL_TYPE_ADD(cpl_image_get_data)(im_real); + } + else { + CPL_TYPE *preal = CPL_TYPE_ADD(cpl_image_get_data)(im_real); #include "cpl_image_io_body.h" - } return error ? cpl_error_set_(error) : CPL_ERROR_NONE; #undef CPL_OPERATION - } /*----------------------------------------------------------------------------*/ @@ -337,36 +340,34 @@ @see cpl_image_fill_re_im() */ /*----------------------------------------------------------------------------*/ -static cpl_error_code CPL_TYPE_ADD(cpl_image_fill_im)(cpl_image * im_imag, - const cpl_image * self) +static cpl_error_code + CPL_TYPE_ADD(cpl_image_fill_im)(cpl_image *im_imag, const cpl_image *self) { #define CPL_OPERATION CPL_IMAGE_IO_IM - const CPL_TYPE complex * pself - = CPL_TYPE_ADD_COMPLEX_CONST(cpl_image_get_data)(self); + const CPL_TYPE complex *pself = + CPL_TYPE_ADD_COMPLEX_CONST(cpl_image_get_data)(self); cpl_error_code error = CPL_ERROR_NONE; cpl_ensure_code(im_imag != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(pself != NULL, CPL_ERROR_INVALID_TYPE); + cpl_ensure_code(pself != NULL, CPL_ERROR_INVALID_TYPE); if (im_imag->type & CPL_TYPE_COMPLEX) { - CPL_TYPE complex * pimag - = CPL_TYPE_ADD_COMPLEX(cpl_image_get_data)(im_imag); + CPL_TYPE complex *pimag = + CPL_TYPE_ADD_COMPLEX(cpl_image_get_data)(im_imag); #include "cpl_image_io_body.h" - - } else { - CPL_TYPE * pimag = CPL_TYPE_ADD(cpl_image_get_data)(im_imag); + } + else { + CPL_TYPE *pimag = CPL_TYPE_ADD(cpl_image_get_data)(im_imag); #include "cpl_image_io_body.h" - } return error ? cpl_error_set_(error) : CPL_ERROR_NONE; #undef CPL_OPERATION - } /*----------------------------------------------------------------------------*/ @@ -383,57 +384,55 @@ @see cpl_image_fill_re_im() */ /*----------------------------------------------------------------------------*/ -static -cpl_error_code CPL_TYPE_ADD(cpl_image_fill_abs_arg)(cpl_image * im_abs, - cpl_image * im_arg, - const cpl_image * self) +static cpl_error_code + CPL_TYPE_ADD(cpl_image_fill_abs_arg)(cpl_image *im_abs, + cpl_image *im_arg, + const cpl_image *self) { #define CPL_OPERATION CPL_IMAGE_IO_ABS_ARG - const CPL_TYPE complex * pself - = CPL_TYPE_ADD_COMPLEX_CONST(cpl_image_get_data)(self); + const CPL_TYPE complex *pself = + CPL_TYPE_ADD_COMPLEX_CONST(cpl_image_get_data)(self); cpl_error_code error = CPL_ERROR_NONE; cpl_ensure_code(im_abs != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(im_arg != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(pself != NULL, CPL_ERROR_INVALID_TYPE); + cpl_ensure_code(pself != NULL, CPL_ERROR_INVALID_TYPE); if ((im_abs->type & CPL_TYPE_COMPLEX) && (im_arg->type & CPL_TYPE_COMPLEX)) { - CPL_TYPE complex * pabs - = CPL_TYPE_ADD_COMPLEX(cpl_image_get_data)(im_abs); - CPL_TYPE complex * parg - = CPL_TYPE_ADD_COMPLEX(cpl_image_get_data)(im_arg); + CPL_TYPE complex *pabs = + CPL_TYPE_ADD_COMPLEX(cpl_image_get_data)(im_abs); + CPL_TYPE complex *parg = + CPL_TYPE_ADD_COMPLEX(cpl_image_get_data)(im_arg); #include "cpl_image_io_body.h" - - } else if (im_abs->type & CPL_TYPE_COMPLEX) { - CPL_TYPE complex * pabs - = CPL_TYPE_ADD_COMPLEX(cpl_image_get_data)(im_abs); - CPL_TYPE * parg = CPL_TYPE_ADD(cpl_image_get_data)(im_arg); + } + else if (im_abs->type & CPL_TYPE_COMPLEX) { + CPL_TYPE complex *pabs = + CPL_TYPE_ADD_COMPLEX(cpl_image_get_data)(im_abs); + CPL_TYPE *parg = CPL_TYPE_ADD(cpl_image_get_data)(im_arg); #include "cpl_image_io_body.h" - - } else if (im_arg->type & CPL_TYPE_COMPLEX) { - CPL_TYPE * pabs = CPL_TYPE_ADD(cpl_image_get_data)(im_abs); - CPL_TYPE complex * parg - = CPL_TYPE_ADD_COMPLEX(cpl_image_get_data)(im_arg); + } + else if (im_arg->type & CPL_TYPE_COMPLEX) { + CPL_TYPE *pabs = CPL_TYPE_ADD(cpl_image_get_data)(im_abs); + CPL_TYPE complex *parg = + CPL_TYPE_ADD_COMPLEX(cpl_image_get_data)(im_arg); #include "cpl_image_io_body.h" - - } else { - CPL_TYPE * pabs = CPL_TYPE_ADD(cpl_image_get_data)(im_abs); - CPL_TYPE * parg = CPL_TYPE_ADD(cpl_image_get_data)(im_arg); + } + else { + CPL_TYPE *pabs = CPL_TYPE_ADD(cpl_image_get_data)(im_abs); + CPL_TYPE *parg = CPL_TYPE_ADD(cpl_image_get_data)(im_arg); #include "cpl_image_io_body.h" - } return error ? cpl_error_set_(error) : CPL_ERROR_NONE; #undef CPL_OPERATION - } /*----------------------------------------------------------------------------*/ @@ -448,36 +447,34 @@ @see cpl_image_fill_abs_arg() */ /*----------------------------------------------------------------------------*/ -static cpl_error_code CPL_TYPE_ADD(cpl_image_fill_abs)(cpl_image * im_abs, - const cpl_image * self) +static cpl_error_code + CPL_TYPE_ADD(cpl_image_fill_abs)(cpl_image *im_abs, const cpl_image *self) { #define CPL_OPERATION CPL_IMAGE_IO_ABS - const CPL_TYPE complex * pself - = CPL_TYPE_ADD_COMPLEX_CONST(cpl_image_get_data)(self); + const CPL_TYPE complex *pself = + CPL_TYPE_ADD_COMPLEX_CONST(cpl_image_get_data)(self); cpl_error_code error = CPL_ERROR_NONE; cpl_ensure_code(im_abs != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(pself != NULL, CPL_ERROR_INVALID_TYPE); + cpl_ensure_code(pself != NULL, CPL_ERROR_INVALID_TYPE); if (im_abs->type & CPL_TYPE_COMPLEX) { - CPL_TYPE complex * pabs - = CPL_TYPE_ADD_COMPLEX(cpl_image_get_data)(im_abs); + CPL_TYPE complex *pabs = + CPL_TYPE_ADD_COMPLEX(cpl_image_get_data)(im_abs); #include "cpl_image_io_body.h" - - } else { - CPL_TYPE * pabs = CPL_TYPE_ADD(cpl_image_get_data)(im_abs); + } + else { + CPL_TYPE *pabs = CPL_TYPE_ADD(cpl_image_get_data)(im_abs); #include "cpl_image_io_body.h" - } return error ? cpl_error_set_(error) : CPL_ERROR_NONE; #undef CPL_OPERATION - } /*----------------------------------------------------------------------------*/ @@ -493,36 +490,34 @@ @see cpl_image_fill_re_im() */ /*----------------------------------------------------------------------------*/ -static cpl_error_code CPL_TYPE_ADD(cpl_image_fill_arg)(cpl_image * im_arg, - const cpl_image * self) +static cpl_error_code + CPL_TYPE_ADD(cpl_image_fill_arg)(cpl_image *im_arg, const cpl_image *self) { #define CPL_OPERATION CPL_IMAGE_IO_ARG - const CPL_TYPE complex * pself - = CPL_TYPE_ADD_COMPLEX_CONST(cpl_image_get_data)(self); + const CPL_TYPE complex *pself = + CPL_TYPE_ADD_COMPLEX_CONST(cpl_image_get_data)(self); cpl_error_code error = CPL_ERROR_NONE; cpl_ensure_code(im_arg != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(pself != NULL, CPL_ERROR_INVALID_TYPE); + cpl_ensure_code(pself != NULL, CPL_ERROR_INVALID_TYPE); if (im_arg->type & CPL_TYPE_COMPLEX) { - CPL_TYPE complex * parg - = CPL_TYPE_ADD_COMPLEX(cpl_image_get_data)(im_arg); + CPL_TYPE complex *parg = + CPL_TYPE_ADD_COMPLEX(cpl_image_get_data)(im_arg); #include "cpl_image_io_body.h" - - } else { - CPL_TYPE * parg = CPL_TYPE_ADD(cpl_image_get_data)(im_arg); + } + else { + CPL_TYPE *parg = CPL_TYPE_ADD(cpl_image_get_data)(im_arg); #include "cpl_image_io_body.h" - } return error ? cpl_error_set_(error) : CPL_ERROR_NONE; #undef CPL_OPERATION - } /*----------------------------------------------------------------------------*/ @@ -537,19 +532,17 @@ @see cpl_image_conjugate() */ /*----------------------------------------------------------------------------*/ -static cpl_error_code CPL_TYPE_ADD(cpl_image_conjugate)(cpl_image * self, - const cpl_image * other) +static cpl_error_code + CPL_TYPE_ADD(cpl_image_conjugate)(cpl_image *self, const cpl_image *other) { - - CPL_TYPE complex * pout = CPL_TYPE_ADD_COMPLEX - (cpl_image_get_data)(self); - const CPL_TYPE complex * pin = CPL_TYPE_ADD_COMPLEX_CONST - (cpl_image_get_data)(other); - const size_t nxy = (size_t)(self->nx * self->ny); - size_t i; + CPL_TYPE complex *pout = CPL_TYPE_ADD_COMPLEX(cpl_image_get_data)(self); + const CPL_TYPE complex *pin = + CPL_TYPE_ADD_COMPLEX_CONST(cpl_image_get_data)(other); + const size_t nxy = (size_t)(self->nx * self->ny); + size_t i; cpl_ensure_code(pout != NULL, CPL_ERROR_INVALID_TYPE); - cpl_ensure_code(pin != NULL, CPL_ERROR_INVALID_TYPE); + cpl_ensure_code(pin != NULL, CPL_ERROR_INVALID_TYPE); for (i = 0; i < nxy; i++) { pout[i] = CPL_CONJ(pin[i]); diff -Nru cpl-7.1.4+ds/cplcore/cpl_image_io.c cpl-7.2.2+ds/cplcore/cpl_image_io.c --- cpl-7.1.4+ds/cplcore/cpl_image_io.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_image_io.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -51,39 +51,45 @@ Defines -----------------------------------------------------------------------------*/ -#define CPL_IMAGE_IO_GET_PIXELS 1 -#define CPL_IMAGE_IO_SET_BADPIXEL 2 -#define CPL_IMAGE_IO_GET 3 -#define CPL_IMAGE_IO_SET 4 - -#define CPL_IMAGE_IO_RE_IM 5 -#define CPL_IMAGE_IO_RE 6 -#define CPL_IMAGE_IO_IM 7 - -#define CPL_IMAGE_IO_ABS_ARG 8 -#define CPL_IMAGE_IO_ABS 9 -#define CPL_IMAGE_IO_ARG 10 +#define CPL_IMAGE_IO_GET_PIXELS 1 +#define CPL_IMAGE_IO_SET_BADPIXEL 2 +#define CPL_IMAGE_IO_GET 3 +#define CPL_IMAGE_IO_SET 4 + +#define CPL_IMAGE_IO_RE_IM 5 +#define CPL_IMAGE_IO_RE 6 +#define CPL_IMAGE_IO_IM 7 + +#define CPL_IMAGE_IO_ABS_ARG 8 +#define CPL_IMAGE_IO_ABS 9 +#define CPL_IMAGE_IO_ARG 10 /* Needed for cpl_image_floodfill() */ -#define FFSTACK_MAXLINES 10 +#define FFSTACK_MAXLINES 10 #define FFSTACK_STACKSZ(IMAGE) (FFSTACK_MAXLINES * IMAGE->ny) #define FFSTACK_BYTES(IMAGE) \ ((size_t)FFSTACK_STACKSZ(IMAGE) * 4 * sizeof(cpl_size)) -#define CPL_MSG "Image with %" CPL_SIZE_FORMAT " X %" CPL_SIZE_FORMAT \ +#define CPL_MSG \ + "Image with %" CPL_SIZE_FORMAT " X %" CPL_SIZE_FORMAT \ " pixel(s) of type '%s' and %" CPL_SIZE_FORMAT " bad pixel(s)\n" /*----------------------------------------------------------------------------- Private function prototypes -----------------------------------------------------------------------------*/ -static -void cpl_image_floodfill(cpl_image *, void *, cpl_size, cpl_size, cpl_size); +static void +cpl_image_floodfill(cpl_image *, void *, cpl_size, cpl_size, cpl_size); -static -cpl_image * cpl_image_load_one(const char *, cpl_type, cpl_size, cpl_size, - cpl_boolean, cpl_size, cpl_size, cpl_size, - cpl_size) CPL_ATTR_ALLOC; +static cpl_image *cpl_image_load_one(const char *, + cpl_type, + cpl_size, + cpl_size, + cpl_boolean, + cpl_size, + cpl_size, + cpl_size, + cpl_size) CPL_ATTR_ALLOC; #define CPL_CLASS CPL_CLASS_DOUBLE #include "cpl_image_io_body.h" @@ -122,12 +128,13 @@ */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_new(cpl_size nx, cpl_size ny, cpl_type type) +cpl_image * +cpl_image_new(cpl_size nx, cpl_size ny, cpl_type type) { + cpl_image *self = cpl_image_wrap_(nx, ny, type, NULL); - cpl_image * self = cpl_image_wrap_(nx, ny, type, NULL); - - if (self == NULL) (void)cpl_error_set_where_(); + if (self == NULL) + (void)cpl_error_set_where_(); return self; } @@ -150,16 +157,17 @@ - CPL_ERROR_INVALID_TYPE if the passed pixel type is not supported */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_wrap(cpl_size nx, cpl_size ny, cpl_type type, - void * pixels) +cpl_image * +cpl_image_wrap(cpl_size nx, cpl_size ny, cpl_type type, void *pixels) { - cpl_image * self; + cpl_image *self; cpl_ensure(pixels != NULL, CPL_ERROR_NULL_INPUT, NULL); self = cpl_image_wrap_(nx, ny, type, pixels); - if (self == NULL) (void)cpl_error_set_where_(); + if (self == NULL) + (void)cpl_error_set_where_(); return self; } @@ -184,17 +192,17 @@ - CPL_ERROR_ILLEGAL_INPUT if nx or ny is non-positive or zero. */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_wrap_double(cpl_size nx, - cpl_size ny, - double * pixels) +cpl_image * +cpl_image_wrap_double(cpl_size nx, cpl_size ny, double *pixels) { - cpl_image * self; + cpl_image *self; cpl_ensure(pixels != NULL, CPL_ERROR_NULL_INPUT, NULL); self = cpl_image_wrap_(nx, ny, CPL_TYPE_DOUBLE, pixels); - if (self == NULL) (void)cpl_error_set_where_(); + if (self == NULL) + (void)cpl_error_set_where_(); return self; } @@ -210,17 +218,17 @@ @see cpl_image_wrap_double() */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_wrap_float(cpl_size nx, - cpl_size ny, - float * pixels) +cpl_image * +cpl_image_wrap_float(cpl_size nx, cpl_size ny, float *pixels) { - cpl_image * self; + cpl_image *self; cpl_ensure(pixels != NULL, CPL_ERROR_NULL_INPUT, NULL); self = cpl_image_wrap_(nx, ny, CPL_TYPE_FLOAT, pixels); - if (self == NULL) (void)cpl_error_set_where_(); + if (self == NULL) + (void)cpl_error_set_where_(); return self; } @@ -238,17 +246,17 @@ @note This function is available iff the application includes complex.h */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_wrap_double_complex(cpl_size nx, - cpl_size ny, - double complex * pixels) +cpl_image * +cpl_image_wrap_double_complex(cpl_size nx, cpl_size ny, double complex *pixels) { - cpl_image * self; + cpl_image *self; cpl_ensure(pixels != NULL, CPL_ERROR_NULL_INPUT, NULL); self = cpl_image_wrap_(nx, ny, CPL_TYPE_DOUBLE_COMPLEX, pixels); - if (self == NULL) (void)cpl_error_set_where_(); + if (self == NULL) + (void)cpl_error_set_where_(); return self; } @@ -264,17 +272,17 @@ @see cpl_image_wrap_double_complex() */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_wrap_float_complex(cpl_size nx, - cpl_size ny, - float complex * pixels) +cpl_image * +cpl_image_wrap_float_complex(cpl_size nx, cpl_size ny, float complex *pixels) { - cpl_image * self; + cpl_image *self; cpl_ensure(pixels != NULL, CPL_ERROR_NULL_INPUT, NULL); self = cpl_image_wrap_(nx, ny, CPL_TYPE_FLOAT_COMPLEX, pixels); - if (self == NULL) (void)cpl_error_set_where_(); + if (self == NULL) + (void)cpl_error_set_where_(); return self; } @@ -290,18 +298,17 @@ @see cpl_image_wrap_double() */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_wrap_int( - cpl_size nx, - cpl_size ny, - int * pixels) +cpl_image * +cpl_image_wrap_int(cpl_size nx, cpl_size ny, int *pixels) { - cpl_image * self; + cpl_image *self; cpl_ensure(pixels != NULL, CPL_ERROR_NULL_INPUT, NULL); self = cpl_image_wrap_(nx, ny, CPL_TYPE_INT, pixels); - if (self == NULL) (void)cpl_error_set_where_(); + if (self == NULL) + (void)cpl_error_set_where_(); return self; } @@ -369,15 +376,17 @@ - CPL_ERROR_DATA_NOT_FOUND if the specified extension has no image data */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_load(const char * filename, - cpl_type im_type, - cpl_size pnum, - cpl_size xtnum) +cpl_image * +cpl_image_load(const char *filename, + cpl_type im_type, + cpl_size pnum, + cpl_size xtnum) { - cpl_image * self = cpl_image_load_one(filename, im_type, pnum, xtnum, - CPL_FALSE, 0, 0, 0, 0); + cpl_image *self = cpl_image_load_one(filename, im_type, pnum, xtnum, + CPL_FALSE, 0, 0, 0, 0); - if (self == NULL) cpl_error_set_where_(); + if (self == NULL) + cpl_error_set_where_(); return self; } @@ -400,39 +409,40 @@ @see cpl_image_load() */ /*----------------------------------------------------------------------------*/ -static cpl_image * cpl_image_load_one(const char * filename, - cpl_type im_type, - cpl_size pnum, - cpl_size xtnum, - cpl_boolean do_window, - cpl_size llx, - cpl_size lly, - cpl_size urx, - cpl_size ury) +static cpl_image * +cpl_image_load_one(const char *filename, + cpl_type im_type, + cpl_size pnum, + cpl_size xtnum, + cpl_boolean do_window, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury) { - - int error = 0; - int naxis = 0; + int error = 0; + int naxis = 0; /* May read from Data Unit w. NAXIS=[23] */ - CPL_FITSIO_TYPE naxes[3] ={0, 0, 0}; - cpl_type pix_type = im_type; - fitsfile * fptr; - cpl_image * self; + CPL_FITSIO_TYPE naxes[3] = { 0, 0, 0 }; + cpl_type pix_type = im_type; + fitsfile *fptr; + cpl_image *self; /* FIXME: Version 3.24 of fits_open_diskfile() seg-faults on NULL. If ever fixed in CFITSIO, this check should be removed */ cpl_ensure(filename != NULL, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(xtnum >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(xtnum >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL); if (cpl_io_fits_open_diskfile(&fptr, filename, READONLY, &error)) { /* If the file did not exist: error = 104 (FILE_NOT_OPENED) */ /* If the file had permission 0: error = 104 (FILE_NOT_OPENED) */ /* If the file was empty: error = 107 (END_OF_FILE) */ /* If the file was a directory: error = 108 (READ_ERROR) */ - (void)cpl_error_set_fits(CPL_ERROR_FILE_IO, error, fits_open_diskfile, - "filename='%s', im_type=%u, pnum=%" - CPL_SIZE_FORMAT ", xtnum=%" CPL_SIZE_FORMAT, - filename, im_type, pnum, xtnum); + (void)cpl_error_set_fits( + CPL_ERROR_FILE_IO, error, fits_open_diskfile, + "filename='%s', im_type=%u, pnum=%" CPL_SIZE_FORMAT + ", xtnum=%" CPL_SIZE_FORMAT, + filename, im_type, pnum, xtnum); return NULL; } @@ -443,11 +453,13 @@ cpl_image_delete(self); self = NULL; (void)cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, error, - fits_close_file, "filename='%s', " + fits_close_file, + "filename='%s', " "im_type=%u, pnum=%" CPL_SIZE_FORMAT ", xtnum=%" CPL_SIZE_FORMAT, filename, im_type, pnum, xtnum); - } else if (self == NULL) { + } + else if (self == NULL) { cpl_error_set_where_(); } @@ -477,23 +489,23 @@ - CPL_ERROR_ILLEGAL_INPUT if the passed position is invalid */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_load_window(const char * filename, - cpl_type im_type, - cpl_size pnum, - cpl_size xtnum, - cpl_size llx, - cpl_size lly, - cpl_size urx, - cpl_size ury) +cpl_image * +cpl_image_load_window(const char *filename, + cpl_type im_type, + cpl_size pnum, + cpl_size xtnum, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury) { + cpl_image *self = cpl_image_load_one(filename, im_type, pnum, xtnum, + CPL_TRUE, llx, lly, urx, ury); - cpl_image * self = cpl_image_load_one(filename, im_type, pnum, xtnum, - CPL_TRUE, llx, lly, urx, ury); - - if (self == NULL) cpl_error_set_where_(); + if (self == NULL) + cpl_error_set_where_(); return self; - } /*----------------------------------------------------------------------------*/ @@ -509,24 +521,25 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_new_from_mask(const cpl_mask * mask) +cpl_image * +cpl_image_new_from_mask(const cpl_mask *mask) { - const size_t nx = cpl_mask_get_size_x(mask); - const size_t ny = cpl_mask_get_size_y(mask); - const cpl_binary * data = cpl_mask_get_data_const(mask); - cpl_image * out; - int * pout; - size_t i; + const size_t nx = cpl_mask_get_size_x(mask); + const size_t ny = cpl_mask_get_size_y(mask); + const cpl_binary *data = cpl_mask_get_data_const(mask); + cpl_image *out; + int *pout; + size_t i; cpl_ensure(mask, CPL_ERROR_NULL_INPUT, NULL); /* Create the INT image */ - pout = (int*)cpl_malloc(nx * ny * sizeof(*pout)); + pout = (int *)cpl_malloc(nx * ny * sizeof(*pout)); out = cpl_image_wrap_int(nx, ny, pout); /* Fill the image */ - for (i= 0; i < nx * ny; i++) { + for (i = 0; i < nx * ny; i++) { pout[i] = (data[i] == CPL_BINARY_0) ? 0 : 1; } @@ -554,17 +567,17 @@ - CPL_ERROR_NULL_INPUT if the input mask is NULL */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_labelise_mask_create(const cpl_mask * in, - cpl_size * nbobjs) +cpl_image * +cpl_image_labelise_mask_create(const cpl_mask *in, cpl_size *nbobjs) { - cpl_image * intimage; - int * pio; - cpl_size label = 1; /* The first label value */ - const size_t nx = cpl_mask_get_size_x(in); - const size_t ny = cpl_mask_get_size_y(in); - const cpl_binary * pin = cpl_mask_get_data_const(in); - size_t i, j; - cpl_boolean has_data = CPL_TRUE; + cpl_image *intimage; + int *pio; + cpl_size label = 1; /* The first label value */ + const size_t nx = cpl_mask_get_size_x(in); + const size_t ny = cpl_mask_get_size_y(in); + const cpl_binary *pin = cpl_mask_get_data_const(in); + size_t i, j; + cpl_boolean has_data = CPL_TRUE; /* Duplicated body from cpl_image_new_from_mask() :-((((((((((((((((*/ @@ -587,7 +600,7 @@ /* Now work on intimage */ /* Allocate temporary work-space for cpl_image_floodfill() */ - void * fftemp = cpl_malloc(FFSTACK_BYTES(intimage)); + void *fftemp = cpl_malloc(FFSTACK_BYTES(intimage)); for (j = 0; j < ny; j++, pio += nx) { for (i = 0; i < nx; i++) { @@ -602,7 +615,8 @@ cpl_free(fftemp); } - if (nbobjs!=NULL) *nbobjs = label-1; + if (nbobjs != NULL) + *nbobjs = label - 1; return intimage; } @@ -618,7 +632,8 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_type cpl_image_get_type(const cpl_image * img) +cpl_type +cpl_image_get_type(const cpl_image *img) { cpl_ensure(img, CPL_ERROR_NULL_INPUT, CPL_TYPE_INVALID); return img->type; @@ -635,7 +650,8 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_image_get_size_x(const cpl_image * img) +cpl_size +cpl_image_get_size_x(const cpl_image *img) { cpl_ensure(img, CPL_ERROR_NULL_INPUT, -1); return img->nx; @@ -652,13 +668,14 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_image_get_size_y(const cpl_image * img) +cpl_size +cpl_image_get_size_y(const cpl_image *img) { cpl_ensure(img, CPL_ERROR_NULL_INPUT, -1); return img->ny; } -#define CPL_OPERATION CPL_IMAGE_IO_GET +#define CPL_OPERATION CPL_IMAGE_IO_GET #define CPL_TYPE_RETURN double /*----------------------------------------------------------------------------*/ /** @@ -672,16 +689,15 @@ @see cpl_image_get() @note No input validation in this function - */ + */ /*----------------------------------------------------------------------------*/ -double cpl_image_get_(const cpl_image * image, - cpl_size xpos, - cpl_size ypos) +inline double +cpl_image_get_(const cpl_image *image, cpl_size xpos, cpl_size ypos) { const cpl_size pos = (xpos - 1) + image->nx * (ypos - 1); double value; - assert( image->pixels ); + assert(image->pixels); /* Get the value */ switch (image->type) { @@ -728,12 +744,13 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL - CPL_ERROR_ACCESS_OUT_OF_RANGE if the passed position is not in the image - CPL_ERROR_INVALID_TYPE if the image pixel type is not supported - */ + */ /*----------------------------------------------------------------------------*/ -double cpl_image_get(const cpl_image * image, - cpl_size xpos, - cpl_size ypos, - int * pis_rejected) +double +cpl_image_get(const cpl_image *image, + cpl_size xpos, + cpl_size ypos, + int *pis_rejected) { cpl_size pos; @@ -741,19 +758,19 @@ cpl_ensure(pis_rejected != NULL, CPL_ERROR_NULL_INPUT, -1.0); *pis_rejected = -1; - cpl_ensure(image != NULL, CPL_ERROR_NULL_INPUT, -2.0); + cpl_ensure(image != NULL, CPL_ERROR_NULL_INPUT, -2.0); /* Check the validity of image, xpos and ypos */ - cpl_ensure(xpos >= 1, CPL_ERROR_ACCESS_OUT_OF_RANGE, -2.0); - cpl_ensure(ypos >= 1, CPL_ERROR_ACCESS_OUT_OF_RANGE, -2.0); + cpl_ensure(xpos >= 1, CPL_ERROR_ACCESS_OUT_OF_RANGE, -2.0); + cpl_ensure(ypos >= 1, CPL_ERROR_ACCESS_OUT_OF_RANGE, -2.0); cpl_ensure(xpos <= image->nx, CPL_ERROR_ACCESS_OUT_OF_RANGE, -2.0); cpl_ensure(ypos <= image->ny, CPL_ERROR_ACCESS_OUT_OF_RANGE, -2.0); cpl_ensure(!(image->type & CPL_TYPE_COMPLEX), CPL_ERROR_INVALID_TYPE, -3.0); pos = (xpos - 1) + image->nx * (ypos - 1); - *pis_rejected = image->bpm != NULL && image->bpm->data[pos] != CPL_BINARY_0 - ? 1 : 0; + *pis_rejected = + image->bpm != NULL && image->bpm->data[pos] != CPL_BINARY_0 ? 1 : 0; return *pis_rejected ? 0.0 : cpl_image_get_(image, xpos, ypos); } @@ -779,37 +796,39 @@ 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 the passed position is not in the image - */ + */ /*----------------------------------------------------------------------------*/ -double complex cpl_image_get_complex(const cpl_image * image, - cpl_size xpos, - cpl_size ypos, - int * pis_rejected) +double complex +cpl_image_get_complex(const cpl_image *image, + cpl_size xpos, + cpl_size ypos, + int *pis_rejected) { double complex value; - cpl_size pos; + cpl_size pos; /* Check entries */ cpl_ensure(pis_rejected != NULL, CPL_ERROR_NULL_INPUT, -1.0); *pis_rejected = -1; - cpl_ensure(image != NULL, CPL_ERROR_NULL_INPUT, -1.0); + cpl_ensure(image != NULL, CPL_ERROR_NULL_INPUT, -1.0); - cpl_ensure(xpos >= 1, CPL_ERROR_ACCESS_OUT_OF_RANGE, -2.0); - cpl_ensure(ypos >= 1, CPL_ERROR_ACCESS_OUT_OF_RANGE, -2.0); + cpl_ensure(xpos >= 1, CPL_ERROR_ACCESS_OUT_OF_RANGE, -2.0); + cpl_ensure(ypos >= 1, CPL_ERROR_ACCESS_OUT_OF_RANGE, -2.0); cpl_ensure(xpos <= image->nx, CPL_ERROR_ACCESS_OUT_OF_RANGE, -2.0); cpl_ensure(ypos <= image->ny, CPL_ERROR_ACCESS_OUT_OF_RANGE, -2.0); pos = (xpos - 1) + image->nx * (ypos - 1); /* Check the validity of image, xpos and ypos */ - *pis_rejected = image->bpm != NULL && image->bpm->data[pos] != CPL_BINARY_0 - ? 1 : 0; + *pis_rejected = + image->bpm != NULL && image->bpm->data[pos] != CPL_BINARY_0 ? 1 : 0; /* The pixel is flagged as rejected */ - if (*pis_rejected) return 0.0; + if (*pis_rejected) + return 0.0; - assert( image->pixels ); + assert(image->pixels); /* Get the value */ switch (image->type) { @@ -833,9 +852,9 @@ #include "cpl_image_io_body.h" #undef CPL_CLASS - default: - (void)cpl_error_set_(CPL_ERROR_INVALID_TYPE); - value = -3.0; + default: + (void)cpl_error_set_(CPL_ERROR_INVALID_TYPE); + value = -3.0; } return value; @@ -865,12 +884,13 @@ - CPL_ERROR_TYPE_MISMATCH If the images have different precision */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_fill_re_im(cpl_image * im_real, cpl_image * im_imag, - const cpl_image * self) +cpl_error_code +cpl_image_fill_re_im(cpl_image *im_real, + cpl_image *im_imag, + const cpl_image *self) { - cpl_error_code error = CPL_ERROR_NONE; /* Set locally in this function */ - cpl_error_code code = CPL_ERROR_NONE; /* Set in call, propagate */ + cpl_error_code code = CPL_ERROR_NONE; /* Set in call, propagate */ cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(self->type & CPL_TYPE_COMPLEX, CPL_ERROR_INVALID_TYPE); @@ -882,44 +902,47 @@ cpl_ensure_code(self->ny == im_imag->ny, CPL_ERROR_INCOMPATIBLE_INPUT); switch (self->type) { - case CPL_TYPE_DOUBLE_COMPLEX: - code = cpl_image_fill_re_im_double(im_real, im_imag, self); - break; - case CPL_TYPE_FLOAT_COMPLEX: - code = cpl_image_fill_re_im_float(im_real, im_imag, self); - break; - default: - error = cpl_error_set_(CPL_ERROR_INVALID_TYPE); + case CPL_TYPE_DOUBLE_COMPLEX: + code = cpl_image_fill_re_im_double(im_real, im_imag, self); + break; + case CPL_TYPE_FLOAT_COMPLEX: + code = cpl_image_fill_re_im_float(im_real, im_imag, self); + break; + default: + error = cpl_error_set_(CPL_ERROR_INVALID_TYPE); } - } else if (im_real != NULL) { + } + else if (im_real != NULL) { cpl_ensure_code(self->nx == im_real->nx, CPL_ERROR_INCOMPATIBLE_INPUT); cpl_ensure_code(self->ny == im_real->ny, CPL_ERROR_INCOMPATIBLE_INPUT); switch (self->type) { - case CPL_TYPE_DOUBLE_COMPLEX: - code = cpl_image_fill_re_double(im_real, self); - break; - case CPL_TYPE_FLOAT_COMPLEX: - code = cpl_image_fill_re_float(im_real, self); - break; - default: - error = cpl_error_set_(CPL_ERROR_INVALID_TYPE); + case CPL_TYPE_DOUBLE_COMPLEX: + code = cpl_image_fill_re_double(im_real, self); + break; + case CPL_TYPE_FLOAT_COMPLEX: + code = cpl_image_fill_re_float(im_real, self); + break; + default: + error = cpl_error_set_(CPL_ERROR_INVALID_TYPE); } - } else if (im_imag != NULL) { + } + else if (im_imag != NULL) { cpl_ensure_code(self->nx == im_imag->nx, CPL_ERROR_INCOMPATIBLE_INPUT); cpl_ensure_code(self->ny == im_imag->ny, CPL_ERROR_INCOMPATIBLE_INPUT); switch (self->type) { - case CPL_TYPE_DOUBLE_COMPLEX: - code = cpl_image_fill_im_double(im_imag, self); - break; - case CPL_TYPE_FLOAT_COMPLEX: - code = cpl_image_fill_im_float(im_imag, self); - break; - default: - error = cpl_error_set_(CPL_ERROR_INVALID_TYPE); + case CPL_TYPE_DOUBLE_COMPLEX: + code = cpl_image_fill_im_double(im_imag, self); + break; + case CPL_TYPE_FLOAT_COMPLEX: + code = cpl_image_fill_im_float(im_imag, self); + break; + default: + error = cpl_error_set_(CPL_ERROR_INVALID_TYPE); } - } else { + } + else { error = cpl_error_set_(CPL_ERROR_NULL_INPUT); } @@ -947,10 +970,11 @@ - CPL_ERROR_TYPE_MISMATCH If the images have different precision */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_fill_abs_arg(cpl_image * im_abs, cpl_image * im_arg, - const cpl_image * self) +cpl_error_code +cpl_image_fill_abs_arg(cpl_image *im_abs, + cpl_image *im_arg, + const cpl_image *self) { - cpl_error_code error; cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); @@ -963,44 +987,47 @@ cpl_ensure_code(self->ny == im_arg->ny, CPL_ERROR_INCOMPATIBLE_INPUT); switch (self->type) { - case CPL_TYPE_DOUBLE_COMPLEX: - error = cpl_image_fill_abs_arg_double(im_abs, im_arg, self); - break; - case CPL_TYPE_FLOAT_COMPLEX: - error = cpl_image_fill_abs_arg_float(im_abs, im_arg, self); - break; - default: - error = CPL_ERROR_INVALID_TYPE; + case CPL_TYPE_DOUBLE_COMPLEX: + error = cpl_image_fill_abs_arg_double(im_abs, im_arg, self); + break; + case CPL_TYPE_FLOAT_COMPLEX: + error = cpl_image_fill_abs_arg_float(im_abs, im_arg, self); + break; + default: + error = CPL_ERROR_INVALID_TYPE; } - } else if (im_abs != NULL) { + } + else if (im_abs != NULL) { cpl_ensure_code(self->nx == im_abs->nx, CPL_ERROR_INCOMPATIBLE_INPUT); cpl_ensure_code(self->ny == im_abs->ny, CPL_ERROR_INCOMPATIBLE_INPUT); switch (self->type) { - case CPL_TYPE_DOUBLE_COMPLEX: - error = cpl_image_fill_abs_double(im_abs, self); - break; - case CPL_TYPE_FLOAT_COMPLEX: - error = cpl_image_fill_abs_float(im_abs, self); - break; - default: - error = CPL_ERROR_INVALID_TYPE; + case CPL_TYPE_DOUBLE_COMPLEX: + error = cpl_image_fill_abs_double(im_abs, self); + break; + case CPL_TYPE_FLOAT_COMPLEX: + error = cpl_image_fill_abs_float(im_abs, self); + break; + default: + error = CPL_ERROR_INVALID_TYPE; } - } else if (im_arg != NULL) { + } + else if (im_arg != NULL) { cpl_ensure_code(self->nx == im_arg->nx, CPL_ERROR_INCOMPATIBLE_INPUT); cpl_ensure_code(self->ny == im_arg->ny, CPL_ERROR_INCOMPATIBLE_INPUT); switch (self->type) { - case CPL_TYPE_DOUBLE_COMPLEX: - error = cpl_image_fill_arg_double(im_arg, self); - break; - case CPL_TYPE_FLOAT_COMPLEX: - error = cpl_image_fill_arg_float(im_arg, self); - break; - default: - error = CPL_ERROR_INVALID_TYPE; + case CPL_TYPE_DOUBLE_COMPLEX: + error = cpl_image_fill_arg_double(im_arg, self); + break; + case CPL_TYPE_FLOAT_COMPLEX: + error = cpl_image_fill_arg_float(im_arg, self); + break; + default: + error = CPL_ERROR_INVALID_TYPE; } - } else { + } + else { error = CPL_ERROR_NULL_INPUT; } @@ -1020,9 +1047,9 @@ */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_fill_real(cpl_image * self, const cpl_image * other) +cpl_error_code +cpl_image_fill_real(cpl_image *self, const cpl_image *other) { - const cpl_error_code error = cpl_image_fill_re_im(self, NULL, other); return error ? cpl_error_set_where_() : CPL_ERROR_NONE; @@ -1041,9 +1068,9 @@ */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_fill_imag(cpl_image * self, const cpl_image * other) +cpl_error_code +cpl_image_fill_imag(cpl_image *self, const cpl_image *other) { - const cpl_error_code error = cpl_image_fill_re_im(NULL, self, other); return error ? cpl_error_set_where_() : CPL_ERROR_NONE; @@ -1062,9 +1089,9 @@ */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_fill_mod(cpl_image * self, const cpl_image * other) +cpl_error_code +cpl_image_fill_mod(cpl_image *self, const cpl_image *other) { - const cpl_error_code error = cpl_image_fill_abs_arg(self, NULL, other); return error ? cpl_error_set_where_() : CPL_ERROR_NONE; @@ -1083,13 +1110,12 @@ */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_fill_phase(cpl_image * self, const cpl_image * other) +cpl_error_code +cpl_image_fill_phase(cpl_image *self, const cpl_image *other) { - const cpl_error_code error = cpl_image_fill_abs_arg(NULL, self, other); return error ? cpl_error_set_where_() : CPL_ERROR_NONE; - } /*----------------------------------------------------------------------------*/ @@ -1110,26 +1136,26 @@ - CPL_ERROR_TYPE_MISMATCH If the images have different precision */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_conjugate(cpl_image * self, const cpl_image * other) +cpl_error_code +cpl_image_conjugate(cpl_image *self, const cpl_image *other) { - cpl_error_code error; - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(other != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(self->nx == other->nx, CPL_ERROR_INCOMPATIBLE_INPUT); - cpl_ensure_code(self->ny == other->ny, CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(other != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self->nx == other->nx, CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_ensure_code(self->ny == other->ny, CPL_ERROR_INCOMPATIBLE_INPUT); cpl_ensure_code(self->type == other->type, CPL_ERROR_TYPE_MISMATCH); switch (self->type) { - case CPL_TYPE_DOUBLE_COMPLEX: - error = cpl_image_conjugate_double(self, other); - break; - case CPL_TYPE_FLOAT_COMPLEX: - error = cpl_image_conjugate_float(self, other); - break; - default: - error = CPL_ERROR_INVALID_TYPE; + case CPL_TYPE_DOUBLE_COMPLEX: + error = cpl_image_conjugate_double(self, other); + break; + case CPL_TYPE_FLOAT_COMPLEX: + error = cpl_image_conjugate_float(self, other); + break; + default: + error = CPL_ERROR_INVALID_TYPE; } return error ? cpl_error_set_(error) : CPL_ERROR_NONE; @@ -1153,18 +1179,19 @@ - CPL_ERROR_ILLEGAL_INPUT if the specified window is not valid */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_fill_window(cpl_image * self, - cpl_size llx, - cpl_size lly, - cpl_size urx, - cpl_size ury, - double value) -{ - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(llx >= 1, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(lly >= 1, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(llx <= urx, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(lly <= ury, CPL_ERROR_ILLEGAL_INPUT); +cpl_error_code +cpl_image_fill_window(cpl_image *self, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury, + double value) +{ + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(llx >= 1, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(lly >= 1, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(llx <= urx, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(lly <= ury, CPL_ERROR_ILLEGAL_INPUT); cpl_ensure_code(urx <= self->nx, CPL_ERROR_ILLEGAL_INPUT); cpl_ensure_code(ury <= self->ny, CPL_ERROR_ILLEGAL_INPUT); @@ -1198,20 +1225,21 @@ - CPL_ERROR_TYPE_MISMATCH if the image type is not int */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_fill_int(cpl_image * self, int value) +cpl_error_code +cpl_image_fill_int(cpl_image *self, int value) { - - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(self->type == CPL_TYPE_INT, CPL_ERROR_TYPE_MISMATCH); if (value == 0) { - (void)memset(self->pixels, 0, (size_t)self->nx * (size_t)self->ny - * sizeof(int)); - } else { + (void)memset(self->pixels, 0, + (size_t)self->nx * (size_t)self->ny * sizeof(int)); + } + else { size_t i = (size_t)(self->nx * self->ny); do { - ((int*)self->pixels)[--i] = value; + ((int *)self->pixels)[--i] = value; } while (i); } @@ -1234,11 +1262,12 @@ Possible #_cpl_error_code_ set in this function: - CPL_ERROR_NULL_INPUT if the input pointer is NULL - CPL_ERROR_INVALID_TYPE if the passed image type is non-complex - */ + */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_extract_real(const cpl_image * image) +cpl_image * +cpl_image_extract_real(const cpl_image *image) { - cpl_image * self; + cpl_image *self; cpl_ensure(image != NULL, CPL_ERROR_NULL_INPUT, NULL); @@ -1269,11 +1298,12 @@ Possible #_cpl_error_code_ set in this function: - CPL_ERROR_NULL_INPUT if the input pointer is NULL - CPL_ERROR_INVALID_TYPE if the passed image type is non-complex - */ + */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_extract_imag(const cpl_image * image) +cpl_image * +cpl_image_extract_imag(const cpl_image *image) { - cpl_image * self; + cpl_image *self; cpl_ensure(image != NULL, CPL_ERROR_NULL_INPUT, NULL); @@ -1304,11 +1334,12 @@ Possible #_cpl_error_code_ set in this function: - CPL_ERROR_NULL_INPUT if the input pointer is NULL - CPL_ERROR_INVALID_TYPE if the passed image type is non-complex - */ + */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_extract_mod(const cpl_image * image) +cpl_image * +cpl_image_extract_mod(const cpl_image *image) { - cpl_image * self; + cpl_image *self; cpl_ensure(image != NULL, CPL_ERROR_NULL_INPUT, NULL); @@ -1339,11 +1370,12 @@ Possible #_cpl_error_code_ set in this function: - CPL_ERROR_NULL_INPUT if the input pointer is NULL - CPL_ERROR_INVALID_TYPE if the passed image type is non-complex - */ + */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_extract_phase(const cpl_image * image) +cpl_image * +cpl_image_extract_phase(const cpl_image *image) { - cpl_image * self; + cpl_image *self; cpl_ensure(image != NULL, CPL_ERROR_NULL_INPUT, NULL); @@ -1374,16 +1406,14 @@ @see cpl_image_set() @note BPM not touched, no input validation - */ + */ /*----------------------------------------------------------------------------*/ -inline void cpl_image_set_(cpl_image * image, - cpl_size xpos, - cpl_size ypos, - double value) +inline void +cpl_image_set_(cpl_image *image, cpl_size xpos, cpl_size ypos, double value) { const cpl_size pos = (xpos - 1) + image->nx * (ypos - 1); - assert( image->pixels ); + assert(image->pixels); switch (image->type) { #define CPL_CLASS CPL_CLASS_DOUBLE @@ -1421,17 +1451,15 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL - CPL_ERROR_ACCESS_OUT_OF_RANGE if the passed position is not in the image - CPL_ERROR_INVALID_TYPE if the image pixel type is not supported - */ + */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_set(cpl_image * image, - cpl_size xpos, - cpl_size ypos, - double value) +cpl_error_code +cpl_image_set(cpl_image *image, cpl_size xpos, cpl_size ypos, double value) { /* Check entries */ - cpl_ensure_code(image != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(xpos >= 1, CPL_ERROR_ACCESS_OUT_OF_RANGE); - cpl_ensure_code(ypos >= 1, CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_ensure_code(image != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(xpos >= 1, CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_ensure_code(ypos >= 1, CPL_ERROR_ACCESS_OUT_OF_RANGE); cpl_ensure_code(xpos <= image->nx, CPL_ERROR_ACCESS_OUT_OF_RANGE); cpl_ensure_code(ypos <= image->ny, CPL_ERROR_ACCESS_OUT_OF_RANGE); cpl_ensure_code(!(image->type & CPL_TYPE_COMPLEX), CPL_ERROR_INVALID_TYPE); @@ -1462,33 +1490,35 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL - CPL_ERROR_ACCESS_OUT_OF_RANGE if the passed position is not in the image - CPL_ERROR_INVALID_TYPE if the image pixel type is not supported - */ + */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_set_complex(cpl_image * image, - cpl_size xpos, - cpl_size ypos, - double complex value) +cpl_error_code +cpl_image_set_complex(cpl_image *image, + cpl_size xpos, + cpl_size ypos, + double complex value) { cpl_size pos; /* Check entries */ - cpl_ensure_code(image != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(xpos >= 1, CPL_ERROR_ACCESS_OUT_OF_RANGE); - cpl_ensure_code(ypos >= 1, CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_ensure_code(image != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(xpos >= 1, CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_ensure_code(ypos >= 1, CPL_ERROR_ACCESS_OUT_OF_RANGE); cpl_ensure_code(xpos <= image->nx, CPL_ERROR_ACCESS_OUT_OF_RANGE); cpl_ensure_code(ypos <= image->ny, CPL_ERROR_ACCESS_OUT_OF_RANGE); -/* cpl_ensure_code(image -> type & CPL_TYPE_COMPLEX, + /* cpl_ensure_code(image -> type & CPL_TYPE_COMPLEX, CPL_ERROR_INVALID_TYPE);*/ - assert( image->pixels ); + assert(image->pixels); pos = (xpos - 1) + image->nx * (ypos - 1); - if (image-> type == CPL_TYPE_FLOAT_COMPLEX) { - float complex * pi = (float complex *)image->pixels; + if (image->type == CPL_TYPE_FLOAT_COMPLEX) { + float complex *pi = (float complex *)image->pixels; pi[pos] = (float complex)value; - } else { - double complex * pi = (double complex *)image->pixels; + } + else { + double complex *pi = (double complex *)image->pixels; pi[pos] = value; } cpl_image_accept_(image, xpos, ypos); @@ -1509,7 +1539,8 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -void * cpl_image_get_data(cpl_image * img) +void * +cpl_image_get_data(cpl_image *img) { cpl_ensure(img, CPL_ERROR_NULL_INPUT, NULL); return img->pixels; @@ -1524,7 +1555,8 @@ @see cpl_image_get_data */ /*----------------------------------------------------------------------------*/ -const void * cpl_image_get_data_const(const cpl_image * img) +const void * +cpl_image_get_data_const(const cpl_image *img) { cpl_ensure(img, CPL_ERROR_NULL_INPUT, NULL); return img->pixels; @@ -1545,20 +1577,20 @@ - CPL_ERROR_NULL_INPUT if self is NULL */ /*----------------------------------------------------------------------------*/ -cpl_mask * cpl_image_set_bpm(cpl_image * self, cpl_mask * bpm) +cpl_mask * +cpl_image_set_bpm(cpl_image *self, cpl_mask *bpm) { - cpl_mask * oldbpm; + cpl_mask *oldbpm; cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); oldbpm = self->bpm; self->bpm = bpm; - + return oldbpm; } - /*----------------------------------------------------------------------------*/ /** @ingroup cpl_image @@ -1573,7 +1605,8 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_mask * cpl_image_unset_bpm(cpl_image * self) +cpl_mask * +cpl_image_unset_bpm(cpl_image *self) { cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); @@ -1595,15 +1628,17 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_mask * cpl_image_get_bpm(cpl_image * img) +cpl_mask * +cpl_image_get_bpm(cpl_image *img) { cpl_ensure(img != NULL, CPL_ERROR_NULL_INPUT, NULL); - if (img->bpm == NULL) img->bpm = cpl_mask_new(img->nx, img->ny); + if (img->bpm == NULL) + img->bpm = cpl_mask_new(img->nx, img->ny); return img->bpm; } - + /*----------------------------------------------------------------------------*/ /** @ingroup cpl_image @@ -1617,15 +1652,16 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -const cpl_mask * cpl_image_get_bpm_const(const cpl_image * img) +const cpl_mask * +cpl_image_get_bpm_const(const cpl_image *img) { cpl_ensure(img != NULL, CPL_ERROR_NULL_INPUT, NULL); return img->bpm; } - + #define CPL_OPERATION CPL_IMAGE_IO_GET_PIXELS -#define CPL_CONST /* const */ +#define CPL_CONST /* const */ /*----------------------------------------------------------------------------*/ /** @ingroup cpl_image @@ -1649,7 +1685,8 @@ - CPL_ERROR_TYPE_MISMATCH if the passed image type is not double */ /*----------------------------------------------------------------------------*/ -double * cpl_image_get_data_double(cpl_image * img) +double * +cpl_image_get_data_double(cpl_image *img) { #define CPL_CLASS CPL_CLASS_DOUBLE #include "cpl_image_io_body.h" @@ -1666,7 +1703,8 @@ @see cpl_image_get_data_double() */ /*----------------------------------------------------------------------------*/ -float * cpl_image_get_data_float(cpl_image * img) +float * +cpl_image_get_data_float(cpl_image *img) { #define CPL_CLASS CPL_CLASS_FLOAT #include "cpl_image_io_body.h" @@ -1684,7 +1722,8 @@ */ /*----------------------------------------------------------------------------*/ -double complex * cpl_image_get_data_double_complex(cpl_image * img) +double complex * +cpl_image_get_data_double_complex(cpl_image *img) { #define CPL_CLASS CPL_CLASS_DOUBLE_COMPLEX #include "cpl_image_io_body.h" @@ -1700,7 +1739,8 @@ @see cpl_image_get_data_double_complex() */ /*----------------------------------------------------------------------------*/ -float complex * cpl_image_get_data_float_complex(cpl_image * img) +float complex * +cpl_image_get_data_float_complex(cpl_image *img) { #define CPL_CLASS CPL_CLASS_FLOAT_COMPLEX #include "cpl_image_io_body.h" @@ -1716,13 +1756,14 @@ @see cpl_image_get_data_double() */ /*----------------------------------------------------------------------------*/ -int * cpl_image_get_data_int(cpl_image * img) +int * +cpl_image_get_data_int(cpl_image *img) { #define CPL_CLASS CPL_CLASS_INT #include "cpl_image_io_body.h" #undef CPL_CLASS } - + #undef CPL_CONST #define CPL_CONST const @@ -1735,7 +1776,8 @@ @see cpl_image_get_data_double */ /*----------------------------------------------------------------------------*/ -const double * cpl_image_get_data_double_const(const cpl_image * img) +const double * +cpl_image_get_data_double_const(const cpl_image *img) { #define CPL_CLASS CPL_CLASS_DOUBLE #include "cpl_image_io_body.h" @@ -1752,7 +1794,8 @@ @see cpl_image_get_data_float() */ /*----------------------------------------------------------------------------*/ -const float * cpl_image_get_data_float_const(const cpl_image * img) +const float * +cpl_image_get_data_float_const(const cpl_image *img) { #define CPL_CLASS CPL_CLASS_FLOAT #include "cpl_image_io_body.h" @@ -1768,8 +1811,8 @@ @see cpl_image_get_data_double_complex() */ /*----------------------------------------------------------------------------*/ -const double complex * -cpl_image_get_data_double_complex_const(const cpl_image * img) +const double complex * +cpl_image_get_data_double_complex_const(const cpl_image *img) { #define CPL_CLASS CPL_CLASS_DOUBLE_COMPLEX #include "cpl_image_io_body.h" @@ -1785,8 +1828,8 @@ @see cpl_image_get_data_double_complex() */ /*----------------------------------------------------------------------------*/ -const float complex * -cpl_image_get_data_float_complex_const(const cpl_image * img) +const float complex * +cpl_image_get_data_float_complex_const(const cpl_image *img) { #define CPL_CLASS CPL_CLASS_FLOAT_COMPLEX #include "cpl_image_io_body.h" @@ -1802,14 +1845,15 @@ @see cpl_image_get_data_int() */ /*----------------------------------------------------------------------------*/ -const int * cpl_image_get_data_int_const(const cpl_image * img) +const int * +cpl_image_get_data_int_const(const cpl_image *img) { #define CPL_CLASS CPL_CLASS_INT #include "cpl_image_io_body.h" #undef CPL_CLASS } #undef CPL_OPERATION - + /*----------------------------------------------------------------------------*/ /** @@ -1823,9 +1867,11 @@ anything. */ /*----------------------------------------------------------------------------*/ -void cpl_image_delete(cpl_image * d) +void +cpl_image_delete(cpl_image *d) { - if (d == NULL) return; + if (d == NULL) + return; /* Delete pixels and bad pixel map */ cpl_free(d->pixels); @@ -1850,17 +1896,18 @@ result in a memory leak. */ /*----------------------------------------------------------------------------*/ -void * cpl_image_unwrap(cpl_image * d) +void * +cpl_image_unwrap(cpl_image *d) { + void *data; - void * data; - - if (d == NULL) return NULL; + if (d == NULL) + return NULL; /* Delete bad pixel map */ cpl_mask_delete(d->bpm); - data = (void *) d->pixels; + data = (void *)d->pixels; cpl_free(d); @@ -1882,9 +1929,10 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_duplicate(const cpl_image * src) +cpl_image * +cpl_image_duplicate(const cpl_image *src) { - cpl_image * self; + cpl_image *self; cpl_ensure(src != NULL, CPL_ERROR_NULL_INPUT, NULL); @@ -1893,13 +1941,15 @@ self = memcpy(cpl_malloc(sizeof(cpl_image)), src, sizeof(cpl_image)); /* 1: Allocate and copy the pixel buffer */ - self->pixels = cpl_malloc((size_t)src->nx * (size_t)src->ny - * cpl_type_get_sizeof(src->type)); - (void)memcpy(self->pixels, src->pixels, (size_t)src->nx * (size_t)src->ny - * cpl_type_get_sizeof(src->type)); + self->pixels = cpl_malloc((size_t)src->nx * (size_t)src->ny * + cpl_type_get_sizeof(src->type)); + (void)memcpy(self->pixels, src->pixels, + (size_t)src->nx * (size_t)src->ny * + cpl_type_get_sizeof(src->type)); /* 2: Duplicate the bad pixel map, if any */ - if (src->bpm != NULL) self->bpm = cpl_mask_duplicate(src->bpm); + if (src->bpm != NULL) + self->bpm = cpl_mask_duplicate(src->bpm); return self; } @@ -1922,198 +1972,201 @@ - CPL_ERROR_INVALID_TYPE if the passed pixel type is not supported */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_cast(const cpl_image * self, - cpl_type type) +cpl_image * +cpl_image_cast(const cpl_image *self, cpl_type type) { - cpl_image * new_im; - void * ppixels; + cpl_image *new_im; + void *ppixels; cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); - + /* The source image has the destination type */ - if (self->type == type) return cpl_image_duplicate(self); + if (self->type == type) + return cpl_image_duplicate(self); cpl_ensure(type != CPL_TYPE_INVALID, CPL_ERROR_ILLEGAL_INPUT, NULL); - ppixels = cpl_malloc((size_t)(self->nx * self->ny) - * cpl_type_get_sizeof(type)); + ppixels = + cpl_malloc((size_t)(self->nx * self->ny) * cpl_type_get_sizeof(type)); /* Switch on the destination type */ switch (type) { - case CPL_TYPE_FLOAT: { - float * pfo = (float*)ppixels; - - /* Switch on the source type */ - switch(self->type) { - case CPL_TYPE_DOUBLE: { - const double * pdi = (const double*)self->pixels; - for (cpl_size i = 0; i < self->nx * self->ny; i++) - pfo[i] = (float)pdi[i]; - break; - } - case CPL_TYPE_INT: { - const int * pii = (const int*)self->pixels; - for (cpl_size i = 0; i < self->nx * self->ny; i++) - pfo[i] = (float)pii[i]; - break; - } - case CPL_TYPE_FLOAT_COMPLEX: - case CPL_TYPE_DOUBLE_COMPLEX: - cpl_free(ppixels); - (void)cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); - return NULL; - default: - cpl_free(ppixels); - (void)cpl_error_set_(CPL_ERROR_INVALID_TYPE); - return NULL; - } - break; - } - case CPL_TYPE_DOUBLE: { - double * pdo = (double*)ppixels; - - /* Switch on the source type */ - switch(self->type) { case CPL_TYPE_FLOAT: { - const float * pfi = (const float*)self->pixels; - for (cpl_size i = 0; i < self->nx * self->ny; i++) - pdo[i] = (double)pfi[i]; - break; - } - case CPL_TYPE_INT: { - const int * pii = (const int*)self->pixels; - for (cpl_size i = 0; i < self->nx * self->ny; i++) - pdo[i] = (double)pii[i]; - break; - } - case CPL_TYPE_FLOAT_COMPLEX: - case CPL_TYPE_DOUBLE_COMPLEX: - cpl_free(ppixels); - (void)cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); - return NULL; - default: - cpl_free(ppixels); - (void)cpl_error_set_(CPL_ERROR_INVALID_TYPE); - return NULL; - } - break; - } - case CPL_TYPE_INT: { - int * pio = (int*)ppixels; + float *pfo = (float *)ppixels; - /* Switch on the source type */ - switch(self->type) { - case CPL_TYPE_FLOAT: { - const float * pfi = (const float*)self->pixels; - for (cpl_size i = 0; i < self->nx * self->ny; i++) - pio[i] = (int)pfi[i]; + /* Switch on the source type */ + switch (self->type) { + case CPL_TYPE_DOUBLE: { + const double *pdi = (const double *)self->pixels; + for (cpl_size i = 0; i < self->nx * self->ny; i++) + pfo[i] = (float)pdi[i]; + break; + } + case CPL_TYPE_INT: { + const int *pii = (const int *)self->pixels; + for (cpl_size i = 0; i < self->nx * self->ny; i++) + pfo[i] = (float)pii[i]; + break; + } + case CPL_TYPE_FLOAT_COMPLEX: + case CPL_TYPE_DOUBLE_COMPLEX: + cpl_free(ppixels); + (void)cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); + return NULL; + default: + cpl_free(ppixels); + (void)cpl_error_set_(CPL_ERROR_INVALID_TYPE); + return NULL; + } break; } case CPL_TYPE_DOUBLE: { - const double * pdi = (const double*)self->pixels; - for (cpl_size i = 0; i < self->nx * self->ny; i++) - pio[i] = (int)pdi[i]; - break; - } - case CPL_TYPE_FLOAT_COMPLEX: - case CPL_TYPE_DOUBLE_COMPLEX: - cpl_free(ppixels); - (void)cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); - return NULL; - default: - cpl_free(ppixels); - (void)cpl_error_set_(CPL_ERROR_INVALID_TYPE); - return NULL; - } - break; - } - case CPL_TYPE_FLOAT_COMPLEX: { - float complex * pfco = (float complex*)ppixels; + double *pdo = (double *)ppixels; - /* Switch on the source type */ - switch(self->type) { - case CPL_TYPE_DOUBLE_COMPLEX: { - const double complex * pdci = - (const double complex *)self->pixels; - for (cpl_size i = 0; i < self->nx * self->ny; i++) - pfco[i] = (float complex)pdci[i]; + /* Switch on the source type */ + switch (self->type) { + case CPL_TYPE_FLOAT: { + const float *pfi = (const float *)self->pixels; + for (cpl_size i = 0; i < self->nx * self->ny; i++) + pdo[i] = (double)pfi[i]; + break; + } + case CPL_TYPE_INT: { + const int *pii = (const int *)self->pixels; + for (cpl_size i = 0; i < self->nx * self->ny; i++) + pdo[i] = (double)pii[i]; + break; + } + case CPL_TYPE_FLOAT_COMPLEX: + case CPL_TYPE_DOUBLE_COMPLEX: + cpl_free(ppixels); + (void)cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); + return NULL; + default: + cpl_free(ppixels); + (void)cpl_error_set_(CPL_ERROR_INVALID_TYPE); + return NULL; + } break; } case CPL_TYPE_INT: { - const int * pii = (const int *)self->pixels; - for (cpl_size i = 0; i < self->nx * self->ny; i++) - pfco[i] = (float complex)pii[i]; - break; - } - case CPL_TYPE_FLOAT: { - const float * pfi = (const float*)self->pixels; - for (cpl_size i = 0; i < self->nx * self->ny; i++) - pfco[i] = (float complex)pfi[i]; - break; - } - case CPL_TYPE_DOUBLE: { - const double * pdi = (const double*)self->pixels; - for (cpl_size i = 0; i < self->nx * self->ny; i++) - pfco[i] = (float complex)pdi[i]; - break; - } - default: - cpl_free(ppixels); - (void)cpl_error_set_(CPL_ERROR_INVALID_TYPE); - return NULL; - } - break; - } - case CPL_TYPE_DOUBLE_COMPLEX: { - double complex * pdco = (double complex*)ppixels; + int *pio = (int *)ppixels; - /* Switch on the source type */ - switch(self->type) { - case CPL_TYPE_FLOAT_COMPLEX: { - const float complex * pfci = (const float complex*)self->pixels; - for (cpl_size i = 0; i < self->nx * self->ny; i++) - pdco[i] = (double complex)pfci[i]; - break; - } - case CPL_TYPE_INT: { - const int * pii = (const int *)self->pixels; - for (cpl_size i = 0; i < self->nx * self->ny; i++) - pdco[i] = (double complex)pii[i]; + /* Switch on the source type */ + switch (self->type) { + case CPL_TYPE_FLOAT: { + const float *pfi = (const float *)self->pixels; + for (cpl_size i = 0; i < self->nx * self->ny; i++) + pio[i] = (int)pfi[i]; + break; + } + case CPL_TYPE_DOUBLE: { + const double *pdi = (const double *)self->pixels; + for (cpl_size i = 0; i < self->nx * self->ny; i++) + pio[i] = (int)pdi[i]; + break; + } + case CPL_TYPE_FLOAT_COMPLEX: + case CPL_TYPE_DOUBLE_COMPLEX: + cpl_free(ppixels); + (void)cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); + return NULL; + default: + cpl_free(ppixels); + (void)cpl_error_set_(CPL_ERROR_INVALID_TYPE); + return NULL; + } break; } - case CPL_TYPE_FLOAT: { - const float * pfi = (const float*)self->pixels; - for (cpl_size i = 0; i < self->nx * self->ny; i++) - pdco[i] = (double complex)pfi[i]; + case CPL_TYPE_FLOAT_COMPLEX: { + float complex *pfco = (float complex *)ppixels; + + /* Switch on the source type */ + switch (self->type) { + case CPL_TYPE_DOUBLE_COMPLEX: { + const double complex *pdci = + (const double complex *)self->pixels; + for (cpl_size i = 0; i < self->nx * self->ny; i++) + pfco[i] = (float complex)pdci[i]; + break; + } + case CPL_TYPE_INT: { + const int *pii = (const int *)self->pixels; + for (cpl_size i = 0; i < self->nx * self->ny; i++) + pfco[i] = (float complex)pii[i]; + break; + } + case CPL_TYPE_FLOAT: { + const float *pfi = (const float *)self->pixels; + for (cpl_size i = 0; i < self->nx * self->ny; i++) + pfco[i] = (float complex)pfi[i]; + break; + } + case CPL_TYPE_DOUBLE: { + const double *pdi = (const double *)self->pixels; + for (cpl_size i = 0; i < self->nx * self->ny; i++) + pfco[i] = (float complex)pdi[i]; + break; + } + default: + cpl_free(ppixels); + (void)cpl_error_set_(CPL_ERROR_INVALID_TYPE); + return NULL; + } break; } - case CPL_TYPE_DOUBLE: { - const double * pdi = (const double*)self->pixels; - for (cpl_size i = 0; i < self->nx * self->ny; i++) - pdco[i] = (double complex)pdi[i]; + case CPL_TYPE_DOUBLE_COMPLEX: { + double complex *pdco = (double complex *)ppixels; + + /* Switch on the source type */ + switch (self->type) { + case CPL_TYPE_FLOAT_COMPLEX: { + const float complex *pfci = + (const float complex *)self->pixels; + for (cpl_size i = 0; i < self->nx * self->ny; i++) + pdco[i] = (double complex)pfci[i]; + break; + } + case CPL_TYPE_INT: { + const int *pii = (const int *)self->pixels; + for (cpl_size i = 0; i < self->nx * self->ny; i++) + pdco[i] = (double complex)pii[i]; + break; + } + case CPL_TYPE_FLOAT: { + const float *pfi = (const float *)self->pixels; + for (cpl_size i = 0; i < self->nx * self->ny; i++) + pdco[i] = (double complex)pfi[i]; + break; + } + case CPL_TYPE_DOUBLE: { + const double *pdi = (const double *)self->pixels; + for (cpl_size i = 0; i < self->nx * self->ny; i++) + pdco[i] = (double complex)pdi[i]; + break; + } + default: + cpl_free(ppixels); + (void)cpl_error_set_(CPL_ERROR_INVALID_TYPE); + return NULL; + } break; } default: cpl_free(ppixels); - (void)cpl_error_set_(CPL_ERROR_INVALID_TYPE); + (void)cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, + "source: %s <=> %s-destination", + cpl_type_get_name(self->type), + cpl_type_get_name(type)); return NULL; - } - break; - } - default: - cpl_free(ppixels); - (void)cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, - "source: %s <=> %s-destination", - cpl_type_get_name(self->type), - cpl_type_get_name(type)); - return NULL; } new_im = cpl_image_wrap_(self->nx, self->ny, type, ppixels); /* Bad pixel map */ - if (self->bpm != NULL) new_im->bpm = cpl_mask_duplicate(self->bpm); - + if (self->bpm != NULL) + new_im->bpm = cpl_mask_duplicate(self->bpm); + return new_im; } @@ -2134,23 +2187,24 @@ - CPL_ERROR_INVALID_TYPE if the image pixel type is not supported */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_fill_rejected( - cpl_image * im, - double a) +cpl_error_code +cpl_image_fill_rejected(cpl_image *im, double a) { - cpl_binary * pbpm; + cpl_binary *pbpm; /* Check entries and Initialise */ cpl_ensure_code(im, CPL_ERROR_NULL_INPUT); - + /* If no bad pixel */ - if (im->bpm == NULL) return CPL_ERROR_NONE; - + if (im->bpm == NULL) + return CPL_ERROR_NONE; + /* Return if no bad pixel map to update */ - if (cpl_mask_is_empty(im->bpm)) return CPL_ERROR_NONE; + if (cpl_mask_is_empty(im->bpm)) + return CPL_ERROR_NONE; pbpm = cpl_mask_get_data(im->bpm); - + switch (im->type) { #define CPL_CLASS CPL_CLASS_DOUBLE #include "cpl_image_io_body.h" @@ -2172,8 +2226,8 @@ #include "cpl_image_io_body.h" #undef CPL_CLASS - default: - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + default: + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } return CPL_ERROR_NONE; @@ -2190,75 +2244,79 @@ @param is_cube CPL_TRUE: use NAXIS3, otherwise NAXIS2 (ignored: nz > 1) @param filename Name of the file to write to @param type The type used to represent the data in the file - @param pl Property list for the output header or NULL + @param plist Property list for the output header or NULL @param mode The desired output options @return CPL_ERROR_NONE or the relevant #_cpl_error_code_ on error @see cpl_image_save() */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_save_(const cpl_image * const* self, - cpl_size nz, - cpl_boolean is_cube, - const char * filename, - cpl_type type, - const cpl_propertylist * pl, - unsigned mode) +cpl_error_code +cpl_image_save_(const cpl_image *const *self, + cpl_size nz, + cpl_boolean is_cube, + const char *filename, + cpl_type type, + const cpl_propertylist *plist, + unsigned mode) { - - int status = 0; /* CFITSIO status, must be set to zero */ + int status = 0; /* CFITSIO status, must be set to zero */ /* Count number of compression flags */ const unsigned ncompress = ((mode & CPL_IO_COMPRESS_GZIP) != 0) + - ((mode & CPL_IO_COMPRESS_HCOMPRESS) != 0) + - ((mode & CPL_IO_COMPRESS_PLIO) != 0) + - ((mode & CPL_IO_COMPRESS_RICE) != 0); - fitsfile * fptr; - cpl_size i; - const char * badkeys = mode & CPL_IO_EXTEND ? - CPL_FITS_BADKEYS_EXT "|" CPL_FITS_COMPRKEYS : - CPL_FITS_BADKEYS_PRIM "|" CPL_FITS_COMPRKEYS; - const cpl_image * first = self ? self[0] : NULL; - const cpl_size nx = cpl_image_get_size_x(first); - const cpl_size ny = cpl_image_get_size_y(first); - const cpl_type ftype = cpl_image_get_type(first); - const int cfitsiotype = ftype == CPL_TYPE_DOUBLE ? TDOUBLE - : (ftype == CPL_TYPE_FLOAT ? TFLOAT : TINT); - const CPL_FITSIO_TYPE naxes[3] = {nx, ny, nz}; - long plane1 = 0; /* First plane to write */ - const int ibpp = cpl_tools_get_bpp(type == CPL_TYPE_UNSPECIFIED ? - ftype : type); + ((mode & CPL_IO_COMPRESS_HCOMPRESS) != 0) + + ((mode & CPL_IO_COMPRESS_PLIO) != 0) + + ((mode & CPL_IO_COMPRESS_RICE) != 0); + fitsfile *fptr; + cpl_size i; + const cpl_boolean hupdate = (mode & CPL_IO_APPEND) ? CPL_TRUE : CPL_FALSE; + const cpl_image *first = self ? self[0] : NULL; + const cpl_size nx = cpl_image_get_size_x(first); + const cpl_size ny = cpl_image_get_size_y(first); + const cpl_type ftype = cpl_image_get_type(first); + const int cfitsiotype = ftype == CPL_TYPE_DOUBLE + ? TDOUBLE + : (ftype == CPL_TYPE_FLOAT ? TFLOAT : TINT); + const CPL_FITSIO_TYPE naxes[3] = { nx, ny, nz }; + long plane1 = 0; /* First plane to write */ + const int ibpp = + cpl_tools_get_bpp(type == CPL_TYPE_UNSPECIFIED ? ftype : type); const int naxis23 = (nz > 1 || is_cube) ? 3 : 2; /* Test entries */ cpl_ensure_code(filename != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(ibpp != 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(ibpp != 0, CPL_ERROR_ILLEGAL_INPUT); if (is_cube) { cpl_ensure_code(((mode & CPL_IO_CREATE) != 0) + - ((mode & CPL_IO_EXTEND) != 0) + - ((mode & CPL_IO_APPEND) != 0) == 1, CPL_ERROR_ILLEGAL_INPUT); - } else { + ((mode & CPL_IO_EXTEND) != 0) + + ((mode & CPL_IO_APPEND) != 0) == + 1, + CPL_ERROR_ILLEGAL_INPUT); + } + else { cpl_ensure_code(((mode & CPL_IO_CREATE) != 0) + - ((mode & CPL_IO_EXTEND) != 0) == 1, CPL_ERROR_ILLEGAL_INPUT); + ((mode & CPL_IO_EXTEND) != 0) == + 1, + CPL_ERROR_ILLEGAL_INPUT); } cpl_ensure_code(mode < CPL_IO_MAX, CPL_ERROR_ILLEGAL_INPUT); cpl_ensure_code(ftype == CPL_TYPE_DOUBLE || ftype == CPL_TYPE_FLOAT || - ftype == CPL_TYPE_INT, CPL_ERROR_INVALID_TYPE); + ftype == CPL_TYPE_INT, + CPL_ERROR_INVALID_TYPE); if (mode & (CPL_IO_EXTEND | CPL_IO_APPEND)) { - if (ncompress > 0) { if (ncompress > 1) { /* Only one type of compression is allowed */ return cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, "Specify one compression method, " - "not %d (mode=0x%x)", ncompress, - mode); + "not %d (mode=0x%x)", + ncompress, mode); } if (mode & CPL_IO_APPEND) { - /* A compression flag is not allowed in append mode - it would + /* A compression flag is not allowed in append mode - it would at best be redundant or else in conflict with the existing compression method (which includes no compression) */ return cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, @@ -2270,15 +2328,16 @@ "Compression not supported " "with implicit conversion to " "BITPIX=%d (type='%s'), use e.g. " - "type='CPL_TYPE_INT'", ibpp, - cpl_type_get_name(type)); + "type='CPL_TYPE_INT'", + ibpp, cpl_type_get_name(type)); } #ifndef CPL_IO_COMPRESSION_LOSSY if (ibpp < 0) { /* No compression of floating-point data - yet */ return cpl_error_set_message_(CPL_ERROR_UNSUPPORTED_MODE, "Lossy compression not supported " - "(BITPIX=%d < 0)", ibpp); + "(BITPIX=%d < 0)", + ibpp); } #endif } @@ -2286,17 +2345,19 @@ /* Open the file */ if (cpl_io_fits_open_diskfile(&fptr, filename, READWRITE, &status)) { return cpl_error_set_fits(CPL_ERROR_FILE_IO, status, - fits_open_diskfile, "filename='%s', " - "type=%d, mode=%d", filename, type, mode); + fits_open_diskfile, + "filename='%s', " + "type=%d, mode=%d", + filename, type, mode); } - if (mode & CPL_IO_COMPRESS_GZIP) + if (mode & CPL_IO_COMPRESS_GZIP) fits_set_compression_type(fptr, GZIP_1, &status); - else if (mode & CPL_IO_COMPRESS_HCOMPRESS) + else if (mode & CPL_IO_COMPRESS_HCOMPRESS) fits_set_compression_type(fptr, HCOMPRESS_1, &status); - else if (mode & CPL_IO_COMPRESS_PLIO) + else if (mode & CPL_IO_COMPRESS_PLIO) fits_set_compression_type(fptr, PLIO_1, &status); - else if (mode & CPL_IO_COMPRESS_RICE) + else if (mode & CPL_IO_COMPRESS_RICE) fits_set_compression_type(fptr, RICE_1, &status); if (status != 0) { @@ -2308,19 +2369,22 @@ "filename='%s', type=%d, mode=%d", filename, type, mode); } - - } else if (ncompress > 0) { + } + else if (ncompress > 0) { /* Compression is only allowed in extensions */ return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); - } else { + } + else { /* Create the file */ - char * sval = cpl_sprintf("!%s", filename); + char *sval = cpl_sprintf("!%s", filename); cpl_io_fits_create_file(&fptr, sval, &status); cpl_free(sval); if (status != 0) { return cpl_error_set_fits(CPL_ERROR_FILE_IO, status, - fits_create_file, "filename='%s', " - "type=%d, mode=%d", filename, type, mode); + fits_create_file, + "filename='%s', " + "type=%d, mode=%d", + filename, type, mode); } } @@ -2336,97 +2400,132 @@ int error2 = 0; cpl_io_fits_close_file(fptr, &error2); return cpl_error_set_fits(CPL_ERROR_FILE_IO, status, - fits_get_num_hdus, "filename='%s', " - "type=%d, mode=%d", filename, type, mode); - } else if (fits_movabs_hdu(fptr, next, &exttype, &status)) { + fits_get_num_hdus, + "filename='%s', " + "type=%d, mode=%d", + filename, type, mode); + } + else if (fits_movabs_hdu(fptr, next, &exttype, &status)) { int error2 = 0; cpl_io_fits_close_file(fptr, &error2); - return cpl_error_set_fits(CPL_ERROR_FILE_IO, status, fits_movabs_hdu, + return cpl_error_set_fits(CPL_ERROR_FILE_IO, status, + fits_movabs_hdu, "filename='%s', type=%d, mode=%d", filename, type, mode); - } else if (exttype != IMAGE_HDU) { + } + else if (exttype != IMAGE_HDU) { int error2 = 0; return cpl_io_fits_close_file(fptr, &error2) - ? cpl_error_set_fits(CPL_ERROR_FILE_IO, error2, - fits_close_file, "filename='%s', " - "type=%d, mode=%d", filename, type, mode) - : cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, "Data-unit " - "%d in file %s is not image-type (%d " - "!= %d. type=%d, mode=%d)", next, - filename, exttype, IMAGE_HDU, type, - mode); - } else if (fits_get_img_dim(fptr, &naxis, &status)) { + ? cpl_error_set_fits(CPL_ERROR_FILE_IO, error2, + fits_close_file, + "filename='%s', " + "type=%d, mode=%d", + filename, type, mode) + : cpl_error_set_message_( + CPL_ERROR_ILLEGAL_INPUT, + "Data-unit " + "%d in file %s is not image-type (%d " + "!= %d. type=%d, mode=%d)", + next, filename, exttype, IMAGE_HDU, type, mode); + } + else if (fits_get_img_dim(fptr, &naxis, &status)) { int error2 = 0; cpl_io_fits_close_file(fptr, &error2); return cpl_error_set_fits(CPL_ERROR_FILE_IO, status, - fits_get_img_dim, "filename='%s', " - "type=%d, mode=%d", filename, type, mode); - } else if (naxis < 2 || naxis > 3) { + fits_get_img_dim, + "filename='%s', " + "type=%d, mode=%d", + filename, type, mode); + } + else if (naxis < 2 || naxis > 3) { int error2 = 0; return cpl_io_fits_close_file(fptr, &error2) - ? cpl_error_set_fits(CPL_ERROR_FILE_IO, error2, - fits_close_file, "filename='%s', " - "type=%d, mode=%d", filename, type, mode) - : cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, "Data-unit " - "%d in file %s has wrong NAXIS (%d !=" - " 2/3). type=%d, mode=%d)", next, - filename, naxis, type, mode); - } else if (fits_get_img_type(fptr, &bitpix, &status)) { + ? cpl_error_set_fits(CPL_ERROR_FILE_IO, error2, + fits_close_file, + "filename='%s', " + "type=%d, mode=%d", + filename, type, mode) + : cpl_error_set_message_( + CPL_ERROR_ILLEGAL_INPUT, + "Data-unit " + "%d in file %s has wrong NAXIS (%d !=" + " 2/3). type=%d, mode=%d)", + next, filename, naxis, type, mode); + } + else if (fits_get_img_type(fptr, &bitpix, &status)) { int error2 = 0; cpl_io_fits_close_file(fptr, &error2); return cpl_error_set_fits(CPL_ERROR_FILE_IO, status, - fits_get_img_type, "filename='%s', type=" - "%d, mode=%d", filename, type, mode); - } else if (bitpix != ibpp) { + fits_get_img_type, + "filename='%s', type=" + "%d, mode=%d", + filename, type, mode); + } + else if (bitpix != ibpp) { int error2 = 0; return cpl_io_fits_close_file(fptr, &error2) - ? cpl_error_set_fits(CPL_ERROR_FILE_IO, error2, - fits_close_file, "filename='%s', " - "type=%d, mode=%d", filename, type, mode) - : cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, "Data-unit " - "%d in file %s has wrong BITPIX (%d " - "!= %d). type=%d, mode=%d)", next, - filename, bitpix, ibpp, type, mode); - } else if (CPL_FITSIO_GET_SIZE(fptr, naxis, fnaxes, &status)) { + ? cpl_error_set_fits(CPL_ERROR_FILE_IO, error2, + fits_close_file, + "filename='%s', " + "type=%d, mode=%d", + filename, type, mode) + : cpl_error_set_message_( + CPL_ERROR_ILLEGAL_INPUT, + "Data-unit " + "%d in file %s has wrong BITPIX (%d " + "!= %d). type=%d, mode=%d)", + next, filename, bitpix, ibpp, type, mode); + } + else if (CPL_FITSIO_GET_SIZE(fptr, naxis, fnaxes, &status)) { int error2 = 0; cpl_io_fits_close_file(fptr, &error2); return cpl_error_set_fits(CPL_ERROR_FILE_IO, status, CPL_FITSIO_GET_SIZE, "filename='%s', type=%d, mode=%d", filename, type, mode); - } else if (naxes[0] != fnaxes[0] || naxes[1] != fnaxes[1]) { + } + else if (naxes[0] != fnaxes[0] || naxes[1] != fnaxes[1]) { int error2 = 0; return cpl_io_fits_close_file(fptr, &error2) - ? cpl_error_set_fits(CPL_ERROR_FILE_IO, error2, - fits_close_file, "filename='%s', " - "type=%d, mode=%d", filename, type, mode) - : cpl_error_set_message_ - (CPL_ERROR_ILLEGAL_INPUT, "Data-unit %d in file %s has " - "wrong NAXIS1/2 (%ldX%ld != %ldX%ld). type=%d, mode=%d)", - next, filename, (long)fnaxes[0], (long)fnaxes[1], - (long)naxes[0], (long)naxes[1], type, mode); - - } else if (fits_is_compressed_image(fptr, &status) && !status) { + ? cpl_error_set_fits(CPL_ERROR_FILE_IO, error2, + fits_close_file, + "filename='%s', " + "type=%d, mode=%d", + filename, type, mode) + : cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, + "Data-unit %d in file %s has " + "wrong NAXIS1/2 (%ldX%ld != " + "%ldX%ld). type=%d, mode=%d)", + next, filename, (long)fnaxes[0], + (long)fnaxes[1], (long)naxes[0], + (long)naxes[1], type, mode); + } + else if (fits_is_compressed_image(fptr, &status) && !status) { return cpl_io_fits_close_file(fptr, &status) - ? cpl_error_set_fits(CPL_ERROR_FILE_IO, status, - fits_close_file, "filename='%s', " - "type=%d, mode=%d", filename, type, mode) - : cpl_error_set_message_(CPL_ERROR_UNSUPPORTED_MODE, "Data-" - "unit %d in file %s is compressed. " - "type=%d, mode=%d)", next, filename, - type, mode); - } else if (status) { + ? cpl_error_set_fits(CPL_ERROR_FILE_IO, status, + fits_close_file, + "filename='%s', " + "type=%d, mode=%d", + filename, type, mode) + : cpl_error_set_message_( + CPL_ERROR_UNSUPPORTED_MODE, + "Data-" + "unit %d in file %s is compressed. " + "type=%d, mode=%d)", + next, filename, type, mode); + } + else if (status) { int error2 = 0; cpl_io_fits_close_file(fptr, &error2); return cpl_error_set_fits(CPL_ERROR_FILE_IO, status, fits_is_compressed_image, "filename='%s', type=%d, mode=%d", filename, type, mode); - } else { + } + else { plane1 = fnaxes[2]; fnaxes[2] += naxes[2]; - if (CPL_FITSIO_RESIZE_IMG(fptr, bitpix, naxis, fnaxes, - &status)) { + if (CPL_FITSIO_RESIZE_IMG(fptr, bitpix, naxis, fnaxes, &status)) { int error2 = 0; cpl_io_fits_close_file(fptr, &error2); return cpl_error_set_fits(CPL_ERROR_FILE_IO, status, @@ -2435,43 +2534,48 @@ filename, type, mode); } } - } else if - /* Create the imagelist in a new HDU appended to the file */ - (CPL_FITSIO_CREATE_IMG(fptr, ibpp, naxis23, naxes, &status)) { + } + else if + /* Create the imagelist in a new HDU appended to the file */ + (CPL_FITSIO_CREATE_IMG(fptr, ibpp, naxis23, naxes, &status)) { int error2 = 0; cpl_io_fits_close_file(fptr, &error2); return cpl_error_set_fits(CPL_ERROR_FILE_IO, status, CPL_FITSIO_CREATE_IMG_E, - "filename='%s', type=%d, mode=%d", - filename, type, mode); - } else if - /* Add Date, if creating */ - ((mode & CPL_IO_CREATE) && fits_write_date(fptr, &status)) { + "filename='%s', type=%d, mode=%d", filename, + type, mode); + } + else if + /* Add Date, if creating */ + ((mode & CPL_IO_CREATE) && fits_write_date(fptr, &status)) { int error2 = 0; cpl_io_fits_close_file(fptr, &error2); return cpl_error_set_fits(CPL_ERROR_FILE_IO, status, fits_write_date, - "filename='%s', type=%d, mode=%d", - filename, type, mode); + "filename='%s', type=%d, mode=%d", filename, + type, mode); } /* Add the property list */ - if (cpl_fits_add_properties(fptr, pl, badkeys)) { + if (cpl_fits_add_properties(fptr, plist, mode, hupdate)) { return cpl_io_fits_close_file(fptr, &status) - ? cpl_error_set_fits(CPL_ERROR_FILE_IO, status, - fits_close_file, "filename='%s', " - "type=%d, mode=%d", filename, type, mode) - : cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); + ? cpl_error_set_fits(CPL_ERROR_FILE_IO, status, + fits_close_file, + "filename='%s', " + "type=%d, mode=%d", + filename, type, mode) + : cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); } /* Loop on the images */ for (i = 0; i < nz; i++) { - const CPL_FITSIO_TYPE fpixel[3] = {1, 1, plane1 + i + 1}; - const cpl_image * image = self[i]; - const void * data = cpl_image_get_data_const(image); + const CPL_FITSIO_TYPE fpixel[3] = { 1, 1, plane1 + i + 1 }; + const cpl_image *image = self[i]; + const void *data = cpl_image_get_data_const(image); /* Write the pixels */ - if (CPL_FITSIO_WRITE_PIX(fptr, cfitsiotype, fpixel, - (LONGLONG)(nx*ny), data, &status)) break; + if (CPL_FITSIO_WRITE_PIX(fptr, cfitsiotype, fpixel, (LONGLONG)(nx * ny), + data, &status)) + break; } /* Check */ @@ -2479,18 +2583,19 @@ int error2 = 0; cpl_io_fits_close_file(fptr, &error2); return cpl_error_set_fits(CPL_ERROR_FILE_IO, status, - CPL_FITSIO_WRITE_PIX_E, "filename='%s', " - "type=%d, mode=%d, plane=%u", filename, type, - mode, (unsigned)i); + CPL_FITSIO_WRITE_PIX_E, + "filename='%s', " + "type=%d, mode=%d, plane=%u", + filename, type, mode, (unsigned)i); } /* Close (and write to disk) */ return cpl_io_fits_close_file(fptr, &status) - ? cpl_error_set_fits(CPL_ERROR_FILE_IO, status, - fits_close_file, "filename='%s', " - "type=%d, mode=%d", filename, type, mode) - : CPL_ERROR_NONE; - + ? cpl_error_set_fits(CPL_ERROR_FILE_IO, status, fits_close_file, + "filename='%s', " + "type=%d, mode=%d", + filename, type, mode) + : CPL_ERROR_NONE; } @@ -2501,7 +2606,7 @@ @param self Image to write to disk or NULL @param filename Name of the file to write to @param type The type used to represent the data in the file - @param pl Property list for the output header or NULL + @param plist Property list for the output header or NULL @param mode The desired output options @return CPL_ERROR_NONE or the relevant #_cpl_error_code_ on error @see cpl_propertylist_save() @@ -2550,15 +2655,17 @@ - CPL_ERROR_FILE_IO if the data cannot be written to the file */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_save(const cpl_image * self, - const char * filename, - cpl_type type, - const cpl_propertylist * pl, - unsigned mode) -{ - const cpl_error_code error = self == NULL ? - cpl_propertylist_save(pl, filename, mode) : - cpl_image_save_(&self, 1, CPL_FALSE, filename, type, pl, mode); +cpl_error_code +cpl_image_save(const cpl_image *self, + const char *filename, + cpl_type type, + const cpl_propertylist *plist, + unsigned mode) +{ + const cpl_error_code error = + self == NULL + ? cpl_propertylist_save(plist, filename, mode) + : cpl_image_save_(&self, 1, CPL_FALSE, filename, type, plist, mode); return error ? cpl_error_set_where_() : CPL_ERROR_NONE; } @@ -2576,25 +2683,23 @@ - CPL_ERROR_FILE_IO if a write operation fails */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_dump_structure(const cpl_image * self, FILE * stream) +cpl_error_code +cpl_image_dump_structure(const cpl_image *self, FILE *stream) { - const int msgmin = (int)(strlen(CPL_MSG) - 2 - 3 * strlen(CPL_SIZE_FORMAT)); - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(stream != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code( fprintf(stream, CPL_MSG, - self->nx, - self->ny, - cpl_type_get_name(self->type), - self->bpm ? cpl_mask_count(self->bpm) : 0) - >= msgmin, CPL_ERROR_FILE_IO); + cpl_ensure_code(fprintf(stream, CPL_MSG, self->nx, self->ny, + cpl_type_get_name(self->type), + self->bpm ? cpl_mask_count(self->bpm) : 0) >= + msgmin, + CPL_ERROR_FILE_IO); return CPL_ERROR_NONE; - } - + /*----------------------------------------------------------------------------*/ /** @ingroup cpl_image @@ -2614,71 +2719,95 @@ - CPL_ERROR_ILLEGAL_INPUT if the window definition is wrong (e.g llx > urx) */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_dump_window(const cpl_image * self, cpl_size llx, - cpl_size lly, - cpl_size urx, cpl_size ury, FILE * stream) +cpl_error_code +cpl_image_dump_window(const cpl_image *self, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury, + FILE *stream) { const cpl_error_code err = CPL_ERROR_FILE_IO; - cpl_size i, j; - cpl_boolean has_bad; + cpl_size i, j; + cpl_boolean has_bad; - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(stream != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(llx > 0 && llx <= self->nx && urx > 0 && urx <= self->nx, - CPL_ERROR_ACCESS_OUT_OF_RANGE); + CPL_ERROR_ACCESS_OUT_OF_RANGE); cpl_ensure_code(lly > 0 && lly <= self->ny && ury > 0 && ury <= self->ny, - CPL_ERROR_ACCESS_OUT_OF_RANGE); + CPL_ERROR_ACCESS_OUT_OF_RANGE); cpl_ensure_code(urx >= llx && ury >= lly, CPL_ERROR_ILLEGAL_INPUT); has_bad = self->bpm != NULL && !cpl_mask_is_empty(self->bpm); - cpl_ensure_code( fprintf(stream, "#----- image: %" CPL_SIZE_FORMAT - " <= x <= %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT - " <= y <= %" CPL_SIZE_FORMAT " -----\n", - llx, urx, lly, ury) > 0, err); + cpl_ensure_code(fprintf(stream, + "#----- image: %" CPL_SIZE_FORMAT + " <= x <= %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT + " <= y <= %" CPL_SIZE_FORMAT " -----\n", + llx, urx, lly, ury) > 0, + err); - cpl_ensure_code( fprintf(stream, "\tX\tY\tvalue\n") > 0, err); + cpl_ensure_code(fprintf(stream, "\tX\tY\tvalue\n") > 0, err); for (j = lly; j <= ury; j++) { for (i = llx; i <= urx; i++) { - const char * badtxt = has_bad && cpl_mask_get(self->bpm, i, j) - ? " (rejected)" : ""; + const char *badtxt = + has_bad && cpl_mask_get(self->bpm, i, j) ? " (rejected)" : ""; if (self->type == CPL_TYPE_INT) { - const int * pint = (const int*)self->pixels; - const int value = pint[(i-1) + (j-1) * self->nx]; - cpl_ensure_code( fprintf(stream, "\t%" CPL_SIZE_FORMAT "\t%" - CPL_SIZE_FORMAT "\t%d%s\n", i, j, - value, badtxt) > 0, err); - } else if (self->type == CPL_TYPE_FLOAT_COMPLEX || - self->type == CPL_TYPE_DOUBLE_COMPLEX ) { + const int *pint = (const int *)self->pixels; + const int value = pint[(i - 1) + (j - 1) * self->nx]; + cpl_ensure_code(fprintf(stream, + "\t%" CPL_SIZE_FORMAT + "\t%" CPL_SIZE_FORMAT "\t%d%s\n", + i, j, value, badtxt) > 0, + err); + } + else if (self->type == CPL_TYPE_FLOAT_COMPLEX || + self->type == CPL_TYPE_DOUBLE_COMPLEX) { int dummy; - const double complex value = - cpl_image_get_complex(self, i, j, &dummy); - cpl_ensure_code( fprintf(stream, "\t%" CPL_SIZE_FORMAT "\t%" - CPL_SIZE_FORMAT "\t%g + %g I %s\n", - i, j, creal(value), cimag(value), - badtxt) > 0, err); - } else { + const double complex value = + cpl_image_get_complex(self, i, j, &dummy); + cpl_ensure_code(fprintf(stream, + "\t%" CPL_SIZE_FORMAT + "\t%" CPL_SIZE_FORMAT + "\t%g + %g I %s\n", + i, j, creal(value), cimag(value), + badtxt) > 0, + err); + } + else { int dummy; const double value = cpl_image_get(self, i, j, &dummy); - cpl_ensure_code( fprintf(stream, "\t%" CPL_SIZE_FORMAT "\t%" - CPL_SIZE_FORMAT "\t%g%s\n", i, j, - value, badtxt) > 0, err); + cpl_ensure_code(fprintf(stream, + "\t%" CPL_SIZE_FORMAT + "\t%" CPL_SIZE_FORMAT "\t%g%s\n", + i, j, value, badtxt) > 0, + err); } } } return CPL_ERROR_NONE; - } - -#define FFSTACK_PUSH(Y, XL, XR, DY) \ - if (sp=wy1 && Y+(DY)<=wy2) \ - {sp->y = Y; sp->xl = XL; sp->xr = XR; sp->dy = DY; sp++;} + +#define FFSTACK_PUSH(Y, XL, XR, DY) \ + if (sp < stack + stacksz && Y + (DY) >= wy1 && Y + (DY) <= wy2) { \ + sp->y = Y; \ + sp->xl = XL; \ + sp->xr = XR; \ + sp->dy = DY; \ + sp++; \ + } #define FFSTACK_POP(Y, XL, XR, DY) \ - {sp--; Y = sp->y+(DY = sp->dy); XL = sp->xl; XR = sp->xr;} + { \ + sp--; \ + Y = sp->y + (DY = sp->dy); \ + XL = sp->xl; \ + XR = sp->xr; \ + } /*----------------------------------------------------------------------------*/ /* @@ -2697,54 +2826,64 @@ programming practices, but works fine and fast. */ /*----------------------------------------------------------------------------*/ -static void cpl_image_floodfill(cpl_image * lab, - void * fftemp, - cpl_size x, - cpl_size y, - cpl_size label) -{ - struct { cpl_size y, xl, xr, dy; } * stack, * sp; - cpl_size wx1, wx2, wy1, wy2; - cpl_size l, x1, x2, dy; - cpl_size ov; - const cpl_size stacksz = FFSTACK_STACKSZ(lab); - int * pii; +static void +cpl_image_floodfill(cpl_image *lab, + void *fftemp, + cpl_size x, + cpl_size y, + cpl_size label) +{ + struct + { + cpl_size y, xl, xr, dy; + } * stack, *sp; + cpl_size wx1, wx2, wy1, wy2; + cpl_size l, x1, x2, dy; + cpl_size ov; + const cpl_size stacksz = FFSTACK_STACKSZ(lab); + int *pii; stack = fftemp; sp = stack; wx1 = 0; - wx2 = lab->nx-1; + wx2 = lab->nx - 1; wy1 = 0; - wy2 = lab->ny-1; + wy2 = lab->ny - 1; pii = cpl_image_get_data_int(lab); - ov = pii[x+y*lab->nx]; - if (ov==label || xwx2 || ywy2) return; - FFSTACK_PUSH(y, x, x, 1); /* needed in some cases */ - FFSTACK_PUSH(y+1, x, x, -1); /* seed segment (popped 1st) */ + ov = pii[x + y * lab->nx]; + if (ov == label || x < wx1 || x > wx2 || y < wy1 || y > wy2) + return; + FFSTACK_PUSH(y, x, x, 1); /* needed in some cases */ + FFSTACK_PUSH(y + 1, x, x, -1); /* seed segment (popped 1st) */ - while (sp>stack) { + while (sp > stack) { /* pop segment off stack and fill a neighboring scan line */ FFSTACK_POP(y, x1, x2, dy); /* * segment of scan line y-dy for x1<=x<=x2 was previously filled, * now explore adjacent pixels in scan line y */ - for (x=x1; x>=wx1 && pii[x+y*lab->nx]==ov; x--) - pii[x+y*lab->nx] = (int)label; /* FIXME: Need cpl_size pixel */ - if (x>=x1) goto skip; - l = x+1; - if (l= wx1 && pii[x + y * lab->nx] == ov; x--) + pii[x + y * lab->nx] = (int)label; /* FIXME: Need cpl_size pixel */ + if (x >= x1) + goto skip; + l = x + 1; + if (l < x1) + FFSTACK_PUSH(y, l, x1 - 1, -dy); /* leak on left? */ + x = x1 + 1; do { - for (; x<=wx2 && pii[x+y*lab->nx]==ov; x++) - pii[x+y*lab->nx] = (int)label; /* FIXME: Need cpl_size pixel */ - FFSTACK_PUSH(y, l, x-1, dy); - if (x>x2+1) FFSTACK_PUSH(y, x2+1, x-1, -dy); /* leak on right? */ -skip: for (x++; x<=x2 && pii[x+y*lab->nx]!=ov; x++) { + for (; x <= wx2 && pii[x + y * lab->nx] == ov; x++) + pii[x + y * lab->nx] = + (int)label; /* FIXME: Need cpl_size pixel */ + FFSTACK_PUSH(y, l, x - 1, dy); + if (x > x2 + 1) + FFSTACK_PUSH(y, x2 + 1, x - 1, -dy); /* leak on right? */ + skip: + for (x++; x <= x2 && pii[x + y * lab->nx] != ov; x++) { ; } l = x; - } while (x<=x2); + } while (x <= x2); } } @@ -2791,46 +2930,47 @@ */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_load_(fitsfile * fptr, - int * pnaxis, - CPL_FITSIO_TYPE naxes[], - cpl_type * ppix_type, - const char * filename, - cpl_size pnum, - cpl_size lhdumov, - cpl_boolean do_window, - cpl_size llx, - cpl_size lly, - cpl_size urx, - cpl_size ury) -{ - - const int hdumov = (int)lhdumov; - int error = 0; - cpl_image * self; - void * pixels; - const long int inc[3] = {1, 1, 1}; - long int fpixel[3]; - long int lpixel[3]; - int loadtype; - cpl_size nx, ny; - - cpl_ensure(fptr != NULL, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(pnaxis != NULL, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(naxes != NULL, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(ppix_type != NULL, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(filename != NULL, CPL_ERROR_NULL_INPUT, NULL); +cpl_image * +cpl_image_load_(fitsfile *fptr, + int *pnaxis, + CPL_FITSIO_TYPE naxes[], + cpl_type *ppix_type, + const char *filename, + cpl_size pnum, + cpl_size lhdumov, + cpl_boolean do_window, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury) +{ + const int hdumov = (int)lhdumov; + int error = 0; + cpl_image *self; + void *pixels; + const long int inc[3] = { 1, 1, 1 }; + long int fpixel[3]; + long int lpixel[3]; + int loadtype; + cpl_size nx, ny; + + cpl_ensure(fptr != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(pnaxis != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(naxes != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(ppix_type != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(filename != NULL, CPL_ERROR_NULL_INPUT, NULL); /* CFITSIO only supports int */ - cpl_ensure((cpl_size)(1+hdumov) == 1+lhdumov, CPL_ERROR_ILLEGAL_INPUT, + cpl_ensure((cpl_size)(1 + hdumov) == 1 + lhdumov, CPL_ERROR_ILLEGAL_INPUT, NULL); /* The open call may be reusing file handle opened for previous I/O, so the file pointer needs to be moved also for hdumov = 0 */ - if (hdumov >= 0 && fits_movabs_hdu(fptr, 1+hdumov, NULL, &error)) { + if (hdumov >= 0 && fits_movabs_hdu(fptr, 1 + hdumov, NULL, &error)) { (void)cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, error, - fits_movabs_hdu, "filename='%s', pnum=%" - CPL_SIZE_FORMAT ", hdumov=%d", + fits_movabs_hdu, + "filename='%s', pnum=%" CPL_SIZE_FORMAT + ", hdumov=%d", filename, pnum, hdumov); return NULL; } @@ -2838,15 +2978,16 @@ /* Get NAXIS, if needed */ if (*pnaxis == 0 && fits_get_img_dim(fptr, pnaxis, &error)) { (void)cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, error, - fits_get_img_dim, "filename='%s', pnum=%" - CPL_SIZE_FORMAT ", hdumov=%d", + fits_get_img_dim, + "filename='%s', pnum=%" CPL_SIZE_FORMAT + ", hdumov=%d", filename, pnum, hdumov); return NULL; } /* Verify NAXIS before trying anything else */ if (*pnaxis != 2 && *pnaxis != 3) { (void)cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, - "filename='%s', pnum=%" CPL_SIZE_FORMAT + "filename='%s', pnum=%" CPL_SIZE_FORMAT ", hdumov=%d, NAXIS=%d", filename, pnum, hdumov, *pnaxis); return NULL; @@ -2855,9 +2996,11 @@ /* Get NAXIS[12[3]], if needed */ if (naxes[0] == 0 && CPL_FITSIO_GET_SIZE(fptr, *pnaxis, naxes, &error)) { (void)cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, error, - CPL_FITSIO_GET_SIZE, "filename='%s', " + CPL_FITSIO_GET_SIZE, + "filename='%s', " "pnum=%" CPL_SIZE_FORMAT ", hdumov=%d, " - "NAXIS=%d", filename, pnum, hdumov, *pnaxis); + "NAXIS=%d", + filename, pnum, hdumov, *pnaxis); return NULL; } @@ -2865,20 +3008,21 @@ if (naxes[0] == 0 || naxes[1] == 0) { /* FIXME: Is this actually possible with a non-zero NAXIS ? */ (void)cpl_error_set_message_(CPL_ERROR_INCOMPATIBLE_INPUT, - "filename='%s', pnum=%" CPL_SIZE_FORMAT + "filename='%s', pnum=%" CPL_SIZE_FORMAT ", hdumov=%d, NAXIS=%d, NAXIS1=%ld, " - "NAXIS2=%ld", filename, pnum, hdumov, - *pnaxis, (long)naxes[0], (long)naxes[1]); + "NAXIS2=%ld", + filename, pnum, hdumov, *pnaxis, + (long)naxes[0], (long)naxes[1]); return NULL; } if (*pnaxis == 3 && naxes[2] == 0) { /* FIXME: Is this actually possible with a non-zero NAXIS ? */ (void)cpl_error_set_message_(CPL_ERROR_INCOMPATIBLE_INPUT, - "filename='%s', pnum=%" CPL_SIZE_FORMAT + "filename='%s', pnum=%" CPL_SIZE_FORMAT ", hdumov=%d, NAXIS=%d, NAXIS1=%ld, " - "NAXIS2=%ld NAXIS3=0", filename, pnum, - hdumov, *pnaxis, (long)naxes[0], - (long)naxes[1]); + "NAXIS2=%ld NAXIS3=0", + filename, pnum, hdumov, *pnaxis, + (long)naxes[0], (long)naxes[1]); return NULL; } @@ -2886,22 +3030,24 @@ /* Verify the window size */ /* If the naxes[] passed is from a previous succesful call here, then this check is redundant. Don't rely on that. */ - if (llx < 1 || lly < 1 || urx > naxes[0] || ury > naxes[1] - || urx < llx || ury < lly) { + if (llx < 1 || lly < 1 || urx > naxes[0] || ury > naxes[1] || + urx < llx || ury < lly) { (void)cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, - "filename='%s', pnum=%" - CPL_SIZE_FORMAT ", hdumov=%d, " - "llx=%" CPL_SIZE_FORMAT ", lly=%" - CPL_SIZE_FORMAT ", urx=%" - CPL_SIZE_FORMAT ", ury=%" - CPL_SIZE_FORMAT ", NAXIS=%d, " + "filename='%s', pnum=%" CPL_SIZE_FORMAT + ", hdumov=%d, " + "llx=%" CPL_SIZE_FORMAT + ", lly=%" CPL_SIZE_FORMAT + ", urx=%" CPL_SIZE_FORMAT + ", ury=%" CPL_SIZE_FORMAT + ", NAXIS=%d, " "NAXIS1=%ld, NAXIS2=%ld", - filename, pnum, hdumov, llx, lly, - urx, ury, *pnaxis, (long)naxes[0], + filename, pnum, hdumov, llx, lly, urx, + ury, *pnaxis, (long)naxes[0], (long)naxes[1]); return NULL; } - } else { + } + else { llx = lly = 1; urx = naxes[0]; ury = naxes[1]; @@ -2913,32 +3059,31 @@ lpixel[0] = urx; lpixel[1] = ury; if (*pnaxis == 3) { - /* Verify plane number */ if (pnum + 1 > naxes[2]) { (void)cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, - "filename='%s', pnum=%" CPL_SIZE_FORMAT + "filename='%s', pnum=%" CPL_SIZE_FORMAT ", hdumov=%d, NAXIS=3, NAXIS1=%ld, " - "NAXIS2=%ld, NAXIS3=%ld", - filename, pnum, hdumov, - (long)naxes[0], (long)naxes[1], - (long)naxes[2]); + "NAXIS2=%ld, NAXIS3=%ld", + filename, pnum, hdumov, (long)naxes[0], + (long)naxes[1], (long)naxes[2]); return NULL; } fpixel[2] = lpixel[2] = pnum + 1; - } else if (pnum != 0) { + } + else if (pnum != 0) { /* May not ask for any plane but the first when NAXIS == 2 */ (void)cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, - "filename='%s', pnum=%" CPL_SIZE_FORMAT + "filename='%s', pnum=%" CPL_SIZE_FORMAT ", hdumov=%d, NAXIS=%d, NAXIS1=%ld, " - "NAXIS2=%ld", filename, pnum, hdumov, - *pnaxis, (long)naxes[0], (long)naxes[1]); + "NAXIS2=%ld", + filename, pnum, hdumov, *pnaxis, + (long)naxes[0], (long)naxes[1]); return NULL; } if (*ppix_type == CPL_TYPE_UNSPECIFIED) { - /* The pixel type of the created image is determined by the pixel type of the loaded FITS image */ @@ -2946,85 +3091,94 @@ if (fits_get_img_type(fptr, &imgtype, &error)) { (void)cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, error, - fits_get_img_type, "filename='%s', " + fits_get_img_type, + "filename='%s', " "pnum=%" CPL_SIZE_FORMAT ", hdumov=%d, " "NAXIS=%d, NAXIS1=%ld, NAXIS2=%ld", filename, pnum, hdumov, *pnaxis, (long)naxes[0], (long)naxes[1]); return NULL; } - + switch (imgtype) { - case BYTE_IMG : - case SHORT_IMG : - case LONG_IMG : - case LONGLONG_IMG: - *ppix_type = CPL_TYPE_INT; - break; - case FLOAT_IMG : - *ppix_type = CPL_TYPE_FLOAT; - break; - case DOUBLE_IMG : - *ppix_type = CPL_TYPE_DOUBLE; - break; - default: - break; + case BYTE_IMG: + case SHORT_IMG: + case LONG_IMG: + case LONGLONG_IMG: + *ppix_type = CPL_TYPE_INT; + break; + case FLOAT_IMG: + *ppix_type = CPL_TYPE_FLOAT; + break; + case DOUBLE_IMG: + *ppix_type = CPL_TYPE_DOUBLE; + break; + default: + break; } if (*ppix_type == CPL_TYPE_UNSPECIFIED) { (void)cpl_error_set_message_(CPL_ERROR_BAD_FILE_FORMAT, - "filename='%s', pnum=%" CPL_SIZE_FORMAT + "filename='%s', pnum=%" CPL_SIZE_FORMAT ", hdumov=%d, NAXIS=%d, NAXIS1=%ld, " - "NAXIS2=%ld, imgtype=%d", filename, - pnum, hdumov, *pnaxis, (long)naxes[0], - (long)naxes[1], imgtype); + "NAXIS2=%ld, imgtype=%d", + filename, pnum, hdumov, *pnaxis, + (long)naxes[0], (long)naxes[1], + imgtype); return NULL; } } if (*ppix_type == CPL_TYPE_DOUBLE) { loadtype = TDOUBLE; - } else if (*ppix_type == CPL_TYPE_FLOAT) { + } + else if (*ppix_type == CPL_TYPE_FLOAT) { loadtype = TFLOAT; - } else if (*ppix_type == CPL_TYPE_INT) { + } + else if (*ppix_type == CPL_TYPE_INT) { loadtype = TINT; - } else { + } + else { (void)cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, - "filename='%s', pnum=%" CPL_SIZE_FORMAT + "filename='%s', pnum=%" CPL_SIZE_FORMAT ", hdumov=%d, NAXIS=%d, NAXIS1=%ld, " - "NAXIS2=%ld, im_type=%d", filename, pnum, - hdumov,*pnaxis, (long)naxes[0], - (long)naxes[1], *ppix_type); + "NAXIS2=%ld, im_type=%d", + filename, pnum, hdumov, *pnaxis, + (long)naxes[0], (long)naxes[1], + *ppix_type); return NULL; } nx = urx - llx + 1; ny = ury - lly + 1; - pixels = cpl_malloc((size_t)nx * (size_t)ny - * cpl_type_get_sizeof(*ppix_type)); + pixels = + cpl_malloc((size_t)nx * (size_t)ny * cpl_type_get_sizeof(*ppix_type)); if (nx == (cpl_size)naxes[0]) { - const LONGLONG nelem = naxes[0] * (LONGLONG)ny; - const LONGLONG firstelem = 1 + naxes[0] * (LONGLONG)(lly - 1) - + naxes[0] * naxes[1] * (LONGLONG)pnum; + const LONGLONG nelem = naxes[0] * (LONGLONG)ny; + const LONGLONG firstelem = 1 + naxes[0] * (LONGLONG)(lly - 1) + + naxes[0] * naxes[1] * (LONGLONG)pnum; - if (fits_read_img(fptr, loadtype, firstelem, nelem, - NULL, pixels, NULL, &error)) { + if (fits_read_img(fptr, loadtype, firstelem, nelem, NULL, pixels, NULL, + &error)) { cpl_free(pixels); (void)cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, error, - fits_read_img, "filename='%s', " + fits_read_img, + "filename='%s', " "pnum=%" CPL_SIZE_FORMAT ", hdumov=%d, " "NAXIS=%d, NAXIS1=%ld, NAXIS2=%ld", filename, pnum, hdumov, *pnaxis, (long)naxes[0], (long)naxes[1]); return NULL; } - } else if (cpl_fits_read_subset(fptr, loadtype, fpixel, lpixel, inc, - NULL, pixels, NULL, &error)) { + } + else if (cpl_fits_read_subset(fptr, loadtype, fpixel, lpixel, inc, NULL, + pixels, NULL, &error)) { cpl_free(pixels); (void)cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, error, - fits_read_subset, "filename='%s', " + fits_read_subset, + "filename='%s', " "pnum=%" CPL_SIZE_FORMAT ", hdumov=%d, " "NAXIS=%d, NAXIS1=%ld, NAXIS2=%ld", filename, pnum, hdumov, *pnaxis, @@ -3060,30 +3214,31 @@ - CPL_ERROR_INVALID_TYPE if the passed pixel type is not supported */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_wrap_(cpl_size nx, cpl_size ny, cpl_type type, - void * pixels) +cpl_image * +cpl_image_wrap_(cpl_size nx, cpl_size ny, cpl_type type, void *pixels) { - cpl_image * self; + cpl_image *self; const cpl_size npix = nx * ny; - const size_t upix = (size_t)nx * (size_t)ny; + const size_t upix = (size_t)nx * (size_t)ny; - cpl_ensure( nx > 0, CPL_ERROR_ILLEGAL_INPUT, NULL); - cpl_ensure( ny > 0, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(nx > 0, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(ny > 0, CPL_ERROR_ILLEGAL_INPUT, NULL); /* Check for overflow */ - cpl_ensure( npix > 0, CPL_ERROR_ILLEGAL_INPUT, NULL); - cpl_ensure( (size_t)npix == upix, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(npix > 0, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure((size_t)npix == upix, CPL_ERROR_ILLEGAL_INPUT, NULL); - cpl_ensure( type == CPL_TYPE_INT || type == CPL_TYPE_FLOAT || - type == CPL_TYPE_DOUBLE || type == CPL_TYPE_FLOAT_COMPLEX || - type == CPL_TYPE_DOUBLE_COMPLEX, CPL_ERROR_INVALID_TYPE, NULL); - - self = cpl_malloc(sizeof(cpl_image)); - self->nx = nx; - self->ny = ny; - self->type = type; - self->bpm = NULL; - self->pixels = pixels != NULL ? pixels - : cpl_calloc(upix, cpl_type_get_sizeof(type)); + cpl_ensure(type == CPL_TYPE_INT || type == CPL_TYPE_FLOAT || + type == CPL_TYPE_DOUBLE || type == CPL_TYPE_FLOAT_COMPLEX || + type == CPL_TYPE_DOUBLE_COMPLEX, + CPL_ERROR_INVALID_TYPE, NULL); + + self = cpl_malloc(sizeof(cpl_image)); + self->nx = nx; + self->ny = ny; + self->type = type; + self->bpm = NULL; + self->pixels = + pixels != NULL ? pixels : cpl_calloc(upix, cpl_type_get_sizeof(type)); return self; } diff -Nru cpl-7.1.4+ds/cplcore/cpl_image_io.h cpl-7.2.2+ds/cplcore/cpl_image_io.h --- cpl-7.1.4+ds/cplcore/cpl_image_io.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_image_io.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -43,25 +43,32 @@ -----------------------------------------------------------------------------*/ /* Image constructors */ -cpl_image * cpl_image_new(cpl_size, cpl_size, cpl_type) CPL_ATTR_ALLOC; -cpl_image * cpl_image_wrap(cpl_size, cpl_size, cpl_type, void *) CPL_ATTR_ALLOC; -cpl_image * cpl_image_wrap_double(cpl_size, cpl_size, double *) CPL_ATTR_ALLOC; -cpl_image * cpl_image_wrap_float(cpl_size, cpl_size, float *) CPL_ATTR_ALLOC; -cpl_image * cpl_image_wrap_int(cpl_size, cpl_size, int *) CPL_ATTR_ALLOC; - -cpl_image * cpl_image_wrap_double_complex(cpl_size, cpl_size, - _Complex double *) CPL_ATTR_ALLOC; -cpl_image * cpl_image_wrap_float_complex(cpl_size, cpl_size, - _Complex float *) CPL_ATTR_ALLOC; - -cpl_image * cpl_image_load(const char *, cpl_type, cpl_size, cpl_size) - CPL_ATTR_ALLOC; -cpl_image * cpl_image_load_window(const char *, cpl_type, cpl_size, cpl_size, - cpl_size, cpl_size, cpl_size, cpl_size) - CPL_ATTR_ALLOC; -cpl_image * cpl_image_new_from_mask(const cpl_mask *) CPL_ATTR_ALLOC; -cpl_image * cpl_image_labelise_mask_create(const cpl_mask *, - cpl_size *) CPL_ATTR_ALLOC; +cpl_image *cpl_image_new(cpl_size, cpl_size, cpl_type) CPL_ATTR_ALLOC; +cpl_image *cpl_image_wrap(cpl_size, cpl_size, cpl_type, void *) CPL_ATTR_ALLOC; +cpl_image *cpl_image_wrap_double(cpl_size, cpl_size, double *) CPL_ATTR_ALLOC; +cpl_image *cpl_image_wrap_float(cpl_size, cpl_size, float *) CPL_ATTR_ALLOC; +cpl_image *cpl_image_wrap_int(cpl_size, cpl_size, int *) CPL_ATTR_ALLOC; + +cpl_image *cpl_image_wrap_double_complex(cpl_size, + cpl_size, + _Complex double *) CPL_ATTR_ALLOC; +cpl_image *cpl_image_wrap_float_complex(cpl_size, + cpl_size, + _Complex float *) CPL_ATTR_ALLOC; + +cpl_image * +cpl_image_load(const char *, cpl_type, cpl_size, cpl_size) CPL_ATTR_ALLOC; +cpl_image *cpl_image_load_window(const char *, + cpl_type, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_size) CPL_ATTR_ALLOC; +cpl_image *cpl_image_new_from_mask(const cpl_mask *) CPL_ATTR_ALLOC; +cpl_image * +cpl_image_labelise_mask_create(const cpl_mask *, cpl_size *) CPL_ATTR_ALLOC; /* Get functions */ cpl_type cpl_image_get_type(const cpl_image *); @@ -69,57 +76,69 @@ cpl_size cpl_image_get_size_y(const cpl_image *); double cpl_image_get(const cpl_image *, cpl_size, cpl_size, int *); -_Complex double cpl_image_get_complex(const cpl_image *, cpl_size, cpl_size, - int *); -cpl_error_code cpl_image_set_complex(cpl_image *, cpl_size, cpl_size, - _Complex double); - -cpl_mask * cpl_image_set_bpm(cpl_image *, cpl_mask *); -cpl_mask * cpl_image_unset_bpm(cpl_image *); -cpl_mask * cpl_image_get_bpm(cpl_image *); -const cpl_mask * cpl_image_get_bpm_const(const cpl_image *); - void * cpl_image_get_data(cpl_image *); -const void * cpl_image_get_data_const(const cpl_image *); - double * cpl_image_get_data_double(cpl_image *); -const double * cpl_image_get_data_double_const(const cpl_image *); - float * cpl_image_get_data_float(cpl_image *); -const float * cpl_image_get_data_float_const(const cpl_image *); - int * cpl_image_get_data_int(cpl_image *); -const int * cpl_image_get_data_int_const(const cpl_image *); - _Complex double * cpl_image_get_data_double_complex(cpl_image *); -const _Complex double * cpl_image_get_data_double_complex_const(const cpl_image *); - _Complex float * cpl_image_get_data_float_complex(cpl_image *); -const _Complex float * cpl_image_get_data_float_complex_const(const cpl_image *); +_Complex double +cpl_image_get_complex(const cpl_image *, cpl_size, cpl_size, int *); +cpl_error_code +cpl_image_set_complex(cpl_image *, cpl_size, cpl_size, _Complex double); + +cpl_mask *cpl_image_set_bpm(cpl_image *, cpl_mask *); +cpl_mask *cpl_image_unset_bpm(cpl_image *); +cpl_mask *cpl_image_get_bpm(cpl_image *); +const cpl_mask *cpl_image_get_bpm_const(const cpl_image *); +void *cpl_image_get_data(cpl_image *); +const void *cpl_image_get_data_const(const cpl_image *); +double *cpl_image_get_data_double(cpl_image *); +const double *cpl_image_get_data_double_const(const cpl_image *); +float *cpl_image_get_data_float(cpl_image *); +const float *cpl_image_get_data_float_const(const cpl_image *); +int *cpl_image_get_data_int(cpl_image *); +const int *cpl_image_get_data_int_const(const cpl_image *); +_Complex double *cpl_image_get_data_double_complex(cpl_image *); +const _Complex double * +cpl_image_get_data_double_complex_const(const cpl_image *); +_Complex float *cpl_image_get_data_float_complex(cpl_image *); +const _Complex float *cpl_image_get_data_float_complex_const(const cpl_image *); cpl_error_code cpl_image_conjugate(cpl_image *, const cpl_image *); -cpl_error_code cpl_image_fill_re_im(cpl_image *, cpl_image *, - const cpl_image *); -cpl_error_code cpl_image_fill_abs_arg(cpl_image *, cpl_image *, - const cpl_image *); +cpl_error_code +cpl_image_fill_re_im(cpl_image *, cpl_image *, const cpl_image *); +cpl_error_code +cpl_image_fill_abs_arg(cpl_image *, cpl_image *, const cpl_image *); /* Set functions */ cpl_error_code cpl_image_set(cpl_image *, cpl_size, cpl_size, double); cpl_error_code cpl_image_fill_rejected(cpl_image *, double); -cpl_error_code cpl_image_fill_window(cpl_image *, cpl_size, cpl_size, - cpl_size, cpl_size, double); +cpl_error_code cpl_image_fill_window(cpl_image *, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + double); /* Image destructor */ void cpl_image_delete(cpl_image *); -void * cpl_image_unwrap(cpl_image *); +void *cpl_image_unwrap(cpl_image *); /* Debugging functions */ cpl_error_code cpl_image_dump_structure(const cpl_image *, FILE *); -cpl_error_code cpl_image_dump_window(const cpl_image *, cpl_size, cpl_size, - cpl_size, cpl_size, FILE *); +cpl_error_code cpl_image_dump_window(const cpl_image *, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + FILE *); /* Others */ -cpl_image * cpl_image_duplicate(const cpl_image *) CPL_ATTR_ALLOC; -cpl_image * cpl_image_cast(const cpl_image *, cpl_type) CPL_ATTR_ALLOC; +cpl_image *cpl_image_duplicate(const cpl_image *) CPL_ATTR_ALLOC; +cpl_image *cpl_image_cast(const cpl_image *, cpl_type) CPL_ATTR_ALLOC; /* Saving function */ -cpl_error_code cpl_image_save(const cpl_image *, const char *, cpl_type, - const cpl_propertylist *, unsigned); +cpl_error_code cpl_image_save(const cpl_image *, + const char *, + cpl_type, + const cpl_propertylist *, + unsigned); CPL_END_DECLS -#endif +#endif diff -Nru cpl-7.1.4+ds/cplcore/cpl_image_io_impl.h cpl-7.2.2+ds/cplcore/cpl_image_io_impl.h --- cpl-7.1.4+ds/cplcore/cpl_image_io_impl.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_image_io_impl.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -37,40 +37,47 @@ Function prototypes -----------------------------------------------------------------------------*/ -cpl_image * cpl_image_wrap_(cpl_size, cpl_size, cpl_type, void *) - CPL_ATTR_ALLOC; +cpl_image *cpl_image_wrap_(cpl_size, cpl_size, cpl_type, void *) CPL_ATTR_ALLOC; /* Special extractor functions for complex images */ -cpl_image * cpl_image_extract_real(const cpl_image *) CPL_ATTR_ALLOC; -cpl_image * cpl_image_extract_imag(const cpl_image *) CPL_ATTR_ALLOC; +cpl_image *cpl_image_extract_real(const cpl_image *) CPL_ATTR_ALLOC; +cpl_image *cpl_image_extract_imag(const cpl_image *) CPL_ATTR_ALLOC; -cpl_image * cpl_image_extract_mod (const cpl_image *) CPL_ATTR_ALLOC; -cpl_image * cpl_image_extract_phase(const cpl_image *) CPL_ATTR_ALLOC; +cpl_image *cpl_image_extract_mod(const cpl_image *) CPL_ATTR_ALLOC; +cpl_image *cpl_image_extract_phase(const cpl_image *) CPL_ATTR_ALLOC; -cpl_error_code cpl_image_fill_real (cpl_image *, const cpl_image *); -cpl_error_code cpl_image_fill_imag (cpl_image *, const cpl_image *); -cpl_error_code cpl_image_fill_mod (cpl_image *, const cpl_image *); +cpl_error_code cpl_image_fill_real(cpl_image *, const cpl_image *); +cpl_error_code cpl_image_fill_imag(cpl_image *, const cpl_image *); +cpl_error_code cpl_image_fill_mod(cpl_image *, const cpl_image *); cpl_error_code cpl_image_fill_phase(cpl_image *, const cpl_image *); /* FIXME: Export ? - add other types ? */ cpl_error_code cpl_image_fill_int(cpl_image *, int); -cpl_image * cpl_image_load_(fitsfile *, int *, CPL_FITSIO_TYPE[], cpl_type *, - const char *, cpl_size, cpl_size, - cpl_boolean, cpl_size, cpl_size, cpl_size, cpl_size) - CPL_ATTR_ALLOC; - -cpl_error_code cpl_image_save_(const cpl_image * const*, cpl_size, cpl_boolean, - const char *, cpl_type, - const cpl_propertylist *, unsigned) - CPL_INTERNAL; +cpl_image *cpl_image_load_(fitsfile *, + int *, + CPL_FITSIO_TYPE[], + cpl_type *, + const char *, + cpl_size, + cpl_size, + cpl_boolean, + cpl_size, + cpl_size, + cpl_size, + cpl_size) CPL_ATTR_ALLOC; + +cpl_error_code cpl_image_save_(const cpl_image *const *, + cpl_size, + cpl_boolean, + const char *, + cpl_type, + const cpl_propertylist *, + unsigned) CPL_INTERNAL; -void cpl_image_set_(cpl_image *, cpl_size, cpl_size, double) - CPL_ATTR_NONNULL; +void cpl_image_set_(cpl_image *, cpl_size, cpl_size, double) CPL_ATTR_NONNULL; -double cpl_image_get_(const cpl_image *, - cpl_size, - cpl_size) +double cpl_image_get_(const cpl_image *, cpl_size, cpl_size) #ifdef NDEBUG CPL_ATTR_PURE #endif @@ -78,5 +85,4 @@ CPL_END_DECLS -#endif - +#endif diff -Nru cpl-7.1.4+ds/cplcore/cpl_image_iqe.c cpl-7.2.2+ds/cplcore/cpl_image_iqe.c --- cpl-7.1.4+ds/cplcore/cpl_image_iqe.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_image_iqe.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -98,28 +98,28 @@ case of noiseless data with a box 7 times the sigma). */ /*----------------------------------------------------------------------------*/ -cpl_bivector * cpl_image_iqe(const cpl_image * in, - cpl_size llx, - cpl_size lly, - cpl_size urx, - cpl_size ury) -{ - cpl_image * extracted; - float parm[8], - sdev[8]; - float * pextracted; - cpl_bivector * res; - double * res_x; - double * res_y; - int iqe_error; - cpl_size nx, ny; - int inx, iny; +cpl_bivector * +cpl_image_iqe(const cpl_image *in, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury) +{ + cpl_image *extracted; + float parm[8], sdev[8]; + float *pextracted; + cpl_bivector *res; + double *res_x; + double *res_y; + int iqe_error; + cpl_size nx, ny; + int inx, iny; /* Check entries */ - cpl_ensure(in, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(in->type == CPL_TYPE_FLOAT, CPL_ERROR_INVALID_TYPE, NULL); - cpl_ensure(urx >= llx + 3, CPL_ERROR_ILLEGAL_INPUT, NULL); - cpl_ensure(ury >= lly + 3, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(in, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(in->type == CPL_TYPE_FLOAT, CPL_ERROR_INVALID_TYPE, NULL); + cpl_ensure(urx >= llx + 3, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(ury >= lly + 3, CPL_ERROR_ILLEGAL_INPUT, NULL); /* Extract the image */ extracted = cpl_image_extract(in, llx, lly, urx, ury); @@ -173,7 +173,7 @@ static int iqemnt(float *, int, int, float, float, float *, int); static int iqesec(float *, int, int, float, float *, float *, int); static int iqefit(float *, int, int, float, float *, float *, float *, int); -static int g2efit(float *, float *, int, int, float [], float [], double *); +static int g2efit(float *, float *, int, int, float[6], float[6], double *); static int g2einit(float *, float *, int, int); static int g2efunc(int, float *, float *, float *, float *, float *); @@ -186,30 +186,36 @@ /* define constants */ -#define hsq2 CPL_MATH_SQRT1_2 /* constant 0.5*sqrt(2) */ +#define hsq2 CPL_MATH_SQRT1_2 /* constant 0.5*sqrt(2) */ -#define MA 6 /* No. of variables */ -#define MITER 64 /* Max. no. of iterations */ -#define MMA 16 /* Max. size of matrix */ -#define SWAP(a,b) {double temp=(a);(a)=(b);(b)=temp;} +#define MA 6 /* No. of variables */ +#define MITER 64 /* Max. no. of iterations */ +#define MMA 16 /* Max. size of matrix */ +#define SWAP(a, b) \ + { \ + double temp = (a); \ + (a) = (b); \ + (b) = temp; \ + } /* end define */ -static float *pval; -static float *pwght; -static int mxx, mp; -static double w[9]; -static double xi[9]; -static double yi[9]; +static float *pval; +static float *pwght; +static int mxx, mp; +static double w[9]; +static double xi[9]; +static double yi[9]; #ifdef _OPENMP -#pragma omp threadprivate(pval,pwght,mxx,mp,w,xi,yi) +#pragma omp threadprivate(pval, pwght, mxx, mp, w, xi, yi) #endif -static int cpl_iqe( -/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +static int +cpl_iqe( + /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ .PURPOSE Estimate parameters for the Image Quality using a small frame around the object. The following parameters are estimated and given in the array 'parm': @@ -225,155 +231,180 @@ to 'iqebgv', 'iqemnt', 'iqesec' and 'iqefit'. .RETURN status, 0: OK, <0: estimate failed, ------------------------------------------------------------------------*/ -float *pfm, -int mx, -int my, -float *parm, -float *sdev -) -{ -int n, err, nbg; -int winsize; - -float bgv, bgs; -float ap[6], cv[6], est[6], sec[6]; - -for (n=0; n<7; n++) parm[n] = sdev[n] = 0.0; - -winsize = (mx * my) - 1; /* size of sub window */ - -if ((err=iqebgv(pfm, mx, my, &bgv, &bgs, &nbg))) return -1; -parm[6] = bgv; -sdev[6] = bgs; - -if ((err=iqemnt(pfm, mx, my, bgv, bgs, est, winsize))) return -2; -parm[0] = est[1]; -parm[1] = CPL_MATH_FWHM_SIG*est[2]; /* Sigma to FWHM */ -parm[2] = est[3]; -parm[3] = CPL_MATH_FWHM_SIG*est[4]; /* Sigma to FWHM */ -parm[5] = est[0]; - -if ((err=iqesec(pfm, mx, my, bgv, est, sec, winsize))) return -3; -parm[4] = CPL_MATH_DEG_RAD*sec[5]; /* Radian to Degrees */ - -if ((err=iqefit(pfm, mx, my, bgv, sec, ap, cv, winsize))<0) return -4; -parm[0] = ap[1]; -sdev[0] = cv[1]; -parm[1] = CPL_MATH_FWHM_SIG*ap[2]; /* Sigma to FWHM */ -sdev[1] = CPL_MATH_FWHM_SIG*cv[2]; /* Sigma to FWHM */ -parm[2] = ap[3]; -sdev[2] = cv[3]; -parm[3] = CPL_MATH_FWHM_SIG*ap[4]; /* Sigma to FWHM */ -sdev[3] = CPL_MATH_FWHM_SIG*cv[4]; /* Sigma to FWHM */ -parm[4] = fmod(CPL_MATH_DEG_RAD*ap[5]+180.0, 180.0); -sdev[4] = CPL_MATH_DEG_RAD*cv[5]; /* Radian to Degrees */ -if (sdev[4] > 180.) sdev[4] = 180.0; /* max is: Pi */ -parm[5] = ap[0]; -sdev[5] = cv[0]; + float *pfm, + int mx, + int my, + float *parm, + float *sdev) +{ + int n, err, nbg; + int winsize; + + float bgv, bgs; + float ap[6], cv[6], est[6], sec[6]; + + for (n = 0; n < 7; n++) + parm[n] = sdev[n] = 0.0; + + winsize = (mx * my) - 1; /* size of sub window */ + + if ((err = iqebgv(pfm, mx, my, &bgv, &bgs, &nbg))) + return -1; + parm[6] = bgv; + sdev[6] = bgs; + + if ((err = iqemnt(pfm, mx, my, bgv, bgs, est, winsize))) + return -2; + parm[0] = est[1]; + parm[1] = CPL_MATH_FWHM_SIG * est[2]; /* Sigma to FWHM */ + parm[2] = est[3]; + parm[3] = CPL_MATH_FWHM_SIG * est[4]; /* Sigma to FWHM */ + parm[5] = est[0]; + + if ((err = iqesec(pfm, mx, my, bgv, est, sec, winsize))) + return -3; + parm[4] = CPL_MATH_DEG_RAD * sec[5]; /* Radian to Degrees */ + + if ((err = iqefit(pfm, mx, my, bgv, sec, ap, cv, winsize)) < 0) + return -4; + parm[0] = ap[1]; + sdev[0] = cv[1]; + parm[1] = CPL_MATH_FWHM_SIG * ap[2]; /* Sigma to FWHM */ + sdev[1] = CPL_MATH_FWHM_SIG * cv[2]; /* Sigma to FWHM */ + parm[2] = ap[3]; + sdev[2] = cv[3]; + parm[3] = CPL_MATH_FWHM_SIG * ap[4]; /* Sigma to FWHM */ + sdev[3] = CPL_MATH_FWHM_SIG * cv[4]; /* Sigma to FWHM */ + parm[4] = fmod(CPL_MATH_DEG_RAD * ap[5] + 180.0, 180.0); + sdev[4] = CPL_MATH_DEG_RAD * cv[5]; /* Radian to Degrees */ + if (sdev[4] > 180.) + sdev[4] = 180.0; /* max is: Pi */ + parm[5] = ap[0]; + sdev[5] = cv[0]; -return 0; + return 0; } -static int iqebgv( -/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +static int +iqebgv( + /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ .PURPOSE Estimate background level for subimage .RETURN status, 0: OK, -1:no buffer space, -2: no points left ------------------------------------------------------------------------*/ -float *pfm, -int mx, -int my, -float *bgm, -float *bgs, -int *nbg -) -{ - int n, m, ns, ms, nt, mt; - float *pfb, *pwb, *pf, *pw; - float *pf0, *pf1, *pf2, *pf3, *pfs0, *pfs1, *pfs2, *pfs3; - double val, fks, ba, bm, bs; - - *bgm = 0.0; - *bgs = 0.0; - *nbg = 0; - - pfs0 = pfm; - pfs1 = pfm + mx - 1; - pfs2 = pfm + mx*(my-1); - pfs3 = pfm + mx*my - 1; - - ns = (mx winsize)) return -99; - - val = *pf - bgv; - am = val; - ax = val*x; - ay = val*y; - axx = val*x*x; - ayy = val*y*y; - axy = val*x*y; - nt++; - -ki = ks = kn = 1; -while (n--) - { - k = kn; - if (!ki && ks==-1) - { - if (nx) - nx = 0; - else - break; - } - ioff = (ki) ? ks : ks*mx; - while (k--) - { - if (ki) x += ks; else y += ks; - if (x<0.0 || y<0.0 || xm winsize)) break; - - val = *pf - bgv; - if (dv winsize)) + return -99; + + val = *pf - bgv; + am = val; + ax = val * x; + ay = val * y; + axx = val * x * x; + ayy = val * y * y; + axy = val * x * y; + nt++; + + ki = ks = kn = 1; + while (n--) { + k = kn; + if (!ki && ks == -1) { + if (nx) + nx = 0; + else + break; + } + ioff = (ki) ? ks : ks * mx; + while (k--) { + if (ki) + x += ks; + else + y += ks; + if (x < 0.0 || y < 0.0 || xm < x || ym < y) + break; + + pf += ioff; + psize = pf - pfm; + if ((psize < 0) || (psize > winsize)) + break; + + val = *pf - bgv; + if (dv < val) { + am += val; + ax += val * x; + ay += val * y; + axx += val * x * x; + ayy += val * y * y; + axy += val * x * y; + nt++; + nx++; + } + } + if ((ki = (!ki))) { + ks = -ks; + kn++; + } + } + if (am <= 0.0) + return -1; + + /* normalize the moments and put them in to the output array */ -return 0; + amm[1] = ax / am; + amm[3] = ay / am; + axx = axx / am - amm[1] * amm[1]; + amm[2] = (0.0 < axx) ? sqrt(axx) : 0.0; + ayy = ayy / am - amm[3] * amm[3]; + amm[4] = (0.0 < ayy) ? sqrt(ayy) : 0.0; + axy = (axy / am - amm[1] * amm[3]) / axx; + amm[5] = fmod(atan(axy) + CPL_MATH_PI, CPL_MATH_PI); + nx = amm[1]; + ny = amm[3]; + amm[0] = pfm[nx + ny * mx] - bgv; + + return 0; } -static int estm9p( -/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +static int +estm9p( + /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ .PURPOSE Estimate parameters for 3x3 pixel region .RETURN status, 0:OK, -1:out of range, ------------------------------------------------------------------------*/ -float *pfm, -int mx, -int my, -int nx, -int ny, -float *rm, -float *dx, -float *dy -) -{ -int n, nt, ix, iy; -float a, am; -float *pfb, *pwb, fb[9], _fb[9], wb[9]; - -cpl_size idx[9]; - -/* check if 3x3 region is fully within frame */ - -if (nx<1 || mx winsize)) break; - - dx = x - xc; dy = y - yc; - r = sqrt(dx*dx + dy*dy); - if (rl winsize)) + break; + + dx = x - xc; + dy = y - yc; + r = sqrt(dx * dx + dy * dy); + if (rl < r && r < rh) { + f = *pf - bgv; + idx = ((int)(CPL_MATH_4_PI * atan2(y - yc, x - xc) + 8.5)) % 8; + sb[idx] += (0.0 < f) ? f : 0.0; + ns[idx]++; + } + } + if ((ki = (!ki))) { + ks = -ks; + kn++; + } + } + + /* normalize the sector array and do explicit FFT for k=1,2 */ - return 0; + for (n = 0; n < 8; n++) { + if (ns[n] < 1) + ns[n] = 1; + sb[n] /= ns[n]; + } + + a2r = sb[0] - sb[2] + sb[4] - sb[6]; + a2i = sb[1] - sb[3] + sb[5] - sb[7]; + + for (n = 0; n < 6; n++) + sec[n] = est[n]; /* copy estimates over */ + if (a2r == 0.0 && a2i == 0.0) + return -2; + sec[5] = fmod(0.5 * atan2(a2i, a2r), CPL_MATH_PI); + + return 0; } -static int iqefit( -/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +static int +iqefit( + /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ .PURPOSE Fit 2D Gaussian function to PSF .COMMEMTS The parameter arrays 'est' and 'ap' are as follows ap[0] = amplitude over background @@ -702,192 +781,232 @@ ap[5] = angle of major axis .RETURN no. of iterations, <0: error, -10: no buffer ------------------------------------------------------------------------*/ -float *pfm, -int mx, -int my, -float bgv, -float *est, -float *ap, -float *cm, -int winsize -) + float *pfm, + int mx, + int my, + float bgv, + float *est, + float *ap, + float *cm, + int winsize) { -int n, ix, iy, nx, ny, nxs, nys, psize; -float *pfb, *pwb, *pf, *pw, *pfmo; -double chi; + int n, ix, iy, nx, ny, nxs, nys, psize; + float *pfb, *pwb, *pf, *pw, *pfmo; + double chi; -/* initialize basic variables */ + /* initialize basic variables */ -for (n=0; n<6; n++) ap[n] = cm[n] = 0.0; + for (n = 0; n < 6; n++) + ap[n] = cm[n] = 0.0; -/* allocate buffer for a 4 sigma region around the object */ + /* allocate buffer for a 4 sigma region around the object */ -pfmo = pfm; /* keep original start of array */ + pfmo = pfm; /* keep original start of array */ -nxs = floor(est[1] - 4.0*est[2]); -if (nxs<0) nxs = 0; -nys = floor(est[3] - 4.0*est[4]); -if (nys<0) nys = 0; -nx = ceil(8.0*est[2]); -if (mx winsize)) { cpl_free (pfb); return -99; } + pfm += nxs + mx * nys; + psize = pfm - pfmo; + if ((psize < 0) || (psize > winsize)) { + cpl_free(pfb); + return -99; + } -pf = pfb; pw = pwb; -iy = ny; - while (iy--) - { - ix = nx; - while (ix--) - { - *pf++ = *pfm++ - bgv; - psize = pfm - pfmo; - if (psize > winsize) { cpl_free (pfb); return -99; } + pf = pfb; + pw = pwb; + iy = ny; + while (iy--) { + ix = nx; + while (ix--) { + *pf++ = *pfm++ - bgv; + psize = pfm - pfmo; + if (psize > winsize) { + cpl_free(pfb); + return -99; + } - *pw++ = 1.0; - } - pfm += mx - nx; - psize = pfm - pfmo; - if ((psize < 0) || (psize > winsize)) { cpl_free (pfb); return -99; } - } + *pw++ = 1.0; + } + pfm += mx - nx; + psize = pfm - pfmo; + if ((psize < 0) || (psize > winsize)) { + cpl_free(pfb); + return -99; + } + } -/* initialize parameters for fitting */ + /* initialize parameters for fitting */ -ap[0] = est[0]; -ap[1] = est[1] - nxs; -ap[2] = est[2]; -ap[3] = est[3] - nys; -ap[4] = est[4]; -ap[5] = est[5]; + ap[0] = est[0]; + ap[1] = est[1] - nxs; + ap[2] = est[2]; + ap[3] = est[3] - nys; + ap[4] = est[4]; + ap[5] = est[5]; -/* perform actual 2D Gauss fit on small subimage */ + /* perform actual 2D Gauss fit on small subimage */ -n = g2efit(pfb, pwb, nx, ny, ap, cm, &chi); + n = g2efit(pfb, pwb, nx, ny, ap, cm, &chi); -/* normalize parameters and uncertainties, and exit */ + /* normalize parameters and uncertainties, and exit */ -ap[1] += nxs; -ap[3] += nys; + ap[1] += nxs; + ap[3] += nys; -cpl_free(pfb); -return n; + cpl_free(pfb); + return n; } -static int g2einit( -/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +static int +g2einit( + /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ .PURPOSE Initiate gauss fit function, set pointers to data and weights .RETURN status, 0: OK, -1: error - bad pixel no. ------------------------------------------------------------------------*/ -float *val, -float *wght, -int nx, -int ny -) -{ -double fh, w1, w2, w3; - - if (nx<1) { /* if NO x-pixel set to NULL */ - pval = (float *) 0; - pwght = (float *) 0; - mxx = mp = 0; - return -1; - } - - pval = val; /* otherwise initiate static varables */ - pwght = wght; - mxx = nx; - mp = (0 MITER) return -4; + + if (status <= 0) + return -2; + if (ap[1] < 0.0 || nx < ap[1] || ap[3] < 0.0 || ny < ap[3]) + return -3; + if (result.niter > MITER) + return -4; return result.niter; } diff -Nru cpl-7.1.4+ds/cplcore/cpl_image_iqe.h cpl-7.2.2+ds/cplcore/cpl_image_iqe.h --- cpl-7.1.4+ds/cplcore/cpl_image_iqe.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_image_iqe.h 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -33,9 +33,10 @@ Function prototypes -----------------------------------------------------------------------------*/ -cpl_bivector * cpl_image_iqe(const cpl_image *, cpl_size, cpl_size, cpl_size, - cpl_size) CPL_ATTR_ALLOC; +cpl_bivector * +cpl_image_iqe(const cpl_image *, cpl_size, cpl_size, cpl_size, cpl_size) + CPL_ATTR_ALLOC; CPL_END_DECLS -#endif +#endif diff -Nru cpl-7.1.4+ds/cplcore/cpl_imagelist_basic_body.h cpl-7.2.2+ds/cplcore/cpl_imagelist_basic_body.h --- cpl-7.1.4+ds/cplcore/cpl_imagelist_basic_body.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_imagelist_basic_body.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -19,31 +19,31 @@ /* Type dependent macros */ #if defined CPL_CLASS && CPL_CLASS == CPL_CLASS_DOUBLE -#define CPL_TYPE double -#define CPL_TYPE_T CPL_TYPE_DOUBLE -#define CPL_IMAGE_GET_DATA cpl_image_get_data_double +#define CPL_TYPE double +#define CPL_TYPE_T CPL_TYPE_DOUBLE +#define CPL_IMAGE_GET_DATA cpl_image_get_data_double #define CPL_IMAGE_GET_DATA_CONST cpl_image_get_data_double_const -#define CPL_IMAGE_WRAP cpl_image_wrap_double -#define CPL_IMAGE_GET_MEDIAN cpl_tools_get_median_double -#define CPL_TOOLS_GET_KTH cpl_tools_get_kth_double +#define CPL_IMAGE_WRAP cpl_image_wrap_double +#define CPL_IMAGE_GET_MEDIAN cpl_tools_get_median_double +#define CPL_TOOLS_GET_KTH cpl_tools_get_kth_double #elif defined CPL_CLASS && CPL_CLASS == CPL_CLASS_FLOAT -#define CPL_TYPE float -#define CPL_TYPE_T CPL_TYPE_FLOAT -#define CPL_IMAGE_GET_DATA cpl_image_get_data_float +#define CPL_TYPE float +#define CPL_TYPE_T CPL_TYPE_FLOAT +#define CPL_IMAGE_GET_DATA cpl_image_get_data_float #define CPL_IMAGE_GET_DATA_CONST cpl_image_get_data_float_const -#define CPL_IMAGE_WRAP cpl_image_wrap_float -#define CPL_IMAGE_GET_MEDIAN cpl_tools_get_median_float -#define CPL_TOOLS_GET_KTH cpl_tools_get_kth_float +#define CPL_IMAGE_WRAP cpl_image_wrap_float +#define CPL_IMAGE_GET_MEDIAN cpl_tools_get_median_float +#define CPL_TOOLS_GET_KTH cpl_tools_get_kth_float #elif defined CPL_CLASS && CPL_CLASS == CPL_CLASS_INT -#define CPL_TYPE int -#define CPL_TYPE_T CPL_TYPE_INT -#define CPL_IMAGE_GET_DATA cpl_image_get_data_int +#define CPL_TYPE int +#define CPL_TYPE_T CPL_TYPE_INT +#define CPL_IMAGE_GET_DATA cpl_image_get_data_int #define CPL_IMAGE_GET_DATA_CONST cpl_image_get_data_int_const -#define CPL_IMAGE_WRAP cpl_image_wrap_int -#define CPL_IMAGE_GET_MEDIAN cpl_tools_get_median_int -#define CPL_TOOLS_GET_KTH cpl_tools_get_kth_int +#define CPL_IMAGE_WRAP cpl_image_wrap_int +#define CPL_IMAGE_GET_MEDIAN cpl_tools_get_median_int +#define CPL_TOOLS_GET_KTH cpl_tools_get_kth_int #else #undef CPL_TYPE @@ -57,392 +57,390 @@ #if CPL_OPERATION == CPL_IMLIST_BASIC_OPER - cpl_size i; +cpl_size i; - /* Check input image sets */ - cpl_ensure_code(in1, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(in2, CPL_ERROR_NULL_INPUT); - - /* Check image sets compatibility */ - cpl_ensure_code( in1->ni == in2->ni, CPL_ERROR_ILLEGAL_INPUT); - - /* Loop on the planes and apply the operation */ - for (i=0; ini; i++) { - const cpl_error_code error = - CPL_OPERATOR(in1->images[i], in2->images[i]); - cpl_ensure_code(!error, error); - } +/* Check input image sets */ +cpl_ensure_code(in1, CPL_ERROR_NULL_INPUT); +cpl_ensure_code(in2, CPL_ERROR_NULL_INPUT); + +/* Check image sets compatibility */ +cpl_ensure_code(in1->ni == in2->ni, CPL_ERROR_ILLEGAL_INPUT); + +/* Loop on the planes and apply the operation */ +for (i = 0; i < in1->ni; i++) { + const cpl_error_code error = CPL_OPERATOR(in1->images[i], in2->images[i]); + cpl_ensure_code(!error, error); +} - return CPL_ERROR_NONE; +return CPL_ERROR_NONE; #elif CPL_OPERATION == CPL_IMLIST_BASIC_IMAGE_LOCAL - cpl_size i; +cpl_size i; - /* Check input image sets */ - cpl_ensure_code(imlist, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(img, CPL_ERROR_NULL_INPUT); - - /* Loop on the planes and apply the operation */ - for (i=0; ini; i++) { - const cpl_error_code error = CPL_OPERATOR(imlist->images[i], img); - cpl_ensure_code(!error, error); - } +/* Check input image sets */ +cpl_ensure_code(imlist, CPL_ERROR_NULL_INPUT); +cpl_ensure_code(img, CPL_ERROR_NULL_INPUT); + +/* Loop on the planes and apply the operation */ +for (i = 0; i < imlist->ni; i++) { + const cpl_error_code error = CPL_OPERATOR(imlist->images[i], img); + cpl_ensure_code(!error, error); +} - return CPL_ERROR_NONE; +return CPL_ERROR_NONE; #elif CPL_OPERATION == CPL_IMLIST_BASIC_TIME_MEDIAN - case CPL_TYPE_T: - { - const size_t nz = self->ni; - CPL_TYPE ** pi = cpl_malloc((size_t)nz * sizeof(CPL_TYPE*)); - CPL_TYPE * po = (CPL_TYPE*)cpl_malloc(nx * ny * sizeof(*po)); - CPL_TYPE * timeline = NULL; - const cpl_binary ** pbpm = NULL; - size_t i, j, k; +case CPL_TYPE_T: { + const size_t nz = self->ni; + CPL_TYPE **pi = cpl_malloc((size_t)nz * sizeof(CPL_TYPE *)); + CPL_TYPE *po = (CPL_TYPE *)cpl_malloc(nx * ny * sizeof(*po)); + CPL_TYPE *timeline = NULL; + const cpl_binary **pbpm = NULL; + size_t i, j, k; + + /* Create the output image */ + median = cpl_image_wrap(nx, ny, type, po); + + /* Find planes with a non-empty bad pixel map - if any */ + for (k = 0; k < nz; k++) { + const cpl_mask *bpm = cpl_image_get_bpm_const(self->images[k]); - /* Create the output image */ - median = cpl_image_wrap(nx, ny, type, po); + pi[k] = CPL_IMAGE_GET_DATA(self->images[k]); - /* Find planes with a non-empty bad pixel map - if any */ - for (k = 0; k < nz; k++) { - const cpl_mask * bpm - = cpl_image_get_bpm_const(self->images[k]); - - pi[k] = CPL_IMAGE_GET_DATA(self->images[k]); - - if (bpm != NULL && !cpl_mask_is_empty(bpm)) { - /* Found one */ - if (pbpm == NULL) { - pbpm = cpl_calloc((size_t)nz, sizeof(*pbpm)); - /* Assume that cpl_calloc() fills with NULL */ - } - pbpm[k] = cpl_mask_get_data_const(bpm); + if (bpm != NULL && !cpl_mask_is_empty(bpm)) { + /* Found one */ + if (pbpm == NULL) { + pbpm = cpl_calloc((size_t)nz, sizeof(*pbpm)); + /* Assume that cpl_calloc() fills with NULL */ } + pbpm[k] = cpl_mask_get_data_const(bpm); } + } - { - const size_t cacheline = 64 / sizeof(CPL_TYPE); - timeline = cpl_malloc((size_t)nz * sizeof(CPL_TYPE) * cacheline); - if (pbpm == NULL) { - /* For each time line */ - for (i=0; i < nx * ny - ((nx * ny) % cacheline); i+=cacheline) { - /* Get the pixels on the current time line */ - for (k=0; k < nz; k++) { - for (j = 0; j < cacheline; j++) { - CPL_TYPE * pik = pi[k]; - timeline[k + j * nz] = pik[i + j]; - } - } - - /* Compute the median */ + { + const size_t cacheline = 64 / sizeof(CPL_TYPE); + timeline = cpl_malloc((size_t)nz * sizeof(CPL_TYPE) * cacheline); + if (pbpm == NULL) { + /* For each time line */ + for (i = 0; i < nx * ny - ((nx * ny) % cacheline); i += cacheline) { + /* Get the pixels on the current time line */ + for (k = 0; k < nz; k++) { for (j = 0; j < cacheline; j++) { - po[i + j] = CPL_IMAGE_GET_MEDIAN(timeline + j * nz, nz); + CPL_TYPE *pik = pi[k]; + timeline[k + j * nz] = pik[i + j]; } } - for (; i < nx * ny; i++) { - /* Get the pixels on the current time line */ - for (k=0; k < nz; k++) { - timeline[k] = pi[k][i]; - } - /* Compute the median */ - po[i] = CPL_IMAGE_GET_MEDIAN(timeline, nz); + /* Compute the median */ + for (j = 0; j < cacheline; j++) { + po[i + j] = CPL_IMAGE_GET_MEDIAN(timeline + j * nz, nz); + } + } + for (; i < nx * ny; i++) { + /* Get the pixels on the current time line */ + for (k = 0; k < nz; k++) { + timeline[k] = pi[k][i]; } - } else { - /* For each time line */ - for (i=0; i < nx * ny - ((nx * ny) % cacheline); i+=cacheline) { - /* Get the pixels on the current time line */ - size_t igood[cacheline]; - memset(igood, 0, sizeof(igood)); - for (k=0; k < nz; k++) { - for (j = 0; j < cacheline; j++) { - if (pbpm[k] == NULL || !pbpm[k][i + j]) { - timeline[j * nz + igood[j]++] = pi[k][i + j]; - } - } - } + /* Compute the median */ + po[i] = CPL_IMAGE_GET_MEDIAN(timeline, nz); + } + } + else { + /* For each time line */ + for (i = 0; i < nx * ny - ((nx * ny) % cacheline); i += cacheline) { + /* Get the pixels on the current time line */ + size_t igood[cacheline]; + memset(igood, 0, sizeof(igood)); + for (k = 0; k < nz; k++) { for (j = 0; j < cacheline; j++) { - if (igood[j] > 0) { - /* Compute the median */ - po[i + j] = CPL_IMAGE_GET_MEDIAN(timeline + j * nz, igood[j]); - } else { - po[i + j] = (CPL_TYPE)0; - cpl_image_reject(median, (i + j)%nx + 1, (i + j)/nx + 1); + if (pbpm[k] == NULL || !pbpm[k][i + j]) { + timeline[j * nz + igood[j]++] = pi[k][i + j]; } } } - for (; i < nx * ny; i++) { - /* Get the pixels on the current time line */ - size_t igood = 0; - for (k=0; k < nz; k++) { - if (pbpm[k] == NULL || !pbpm[k][i]) { - timeline[igood++] = pi[k][i]; - } - } - if (igood > 0) { + for (j = 0; j < cacheline; j++) { + if (igood[j] > 0) { /* Compute the median */ - po[i] = CPL_IMAGE_GET_MEDIAN(timeline, igood); - } else { - po[i] = (CPL_TYPE)0; - cpl_image_reject(median, i%nx + 1, i/nx + 1); + po[i + j] = + CPL_IMAGE_GET_MEDIAN(timeline + j * nz, igood[j]); + } + else { + po[i + j] = (CPL_TYPE)0; + cpl_image_reject(median, (i + j) % nx + 1, + (i + j) / nx + 1); } } } - } + for (; i < nx * ny; i++) { + /* Get the pixels on the current time line */ + size_t igood = 0; + for (k = 0; k < nz; k++) { + if (pbpm[k] == NULL || !pbpm[k][i]) { + timeline[igood++] = pi[k][i]; + } + } - cpl_free(pi); - cpl_free(timeline); - cpl_free(pbpm); - break; + if (igood > 0) { + /* Compute the median */ + po[i] = CPL_IMAGE_GET_MEDIAN(timeline, igood); + } + else { + po[i] = (CPL_TYPE)0; + cpl_image_reject(median, i % nx + 1, i / nx + 1); + } + } + } } -#elif CPL_OPERATION == CPL_IMLIST_BASIC_TIME_MINMAX + cpl_free(pi); + cpl_free(timeline); + cpl_free(pbpm); + break; +} - case CPL_TYPE_T: - { - /* Pointers to the ni pixel buffers */ - const CPL_TYPE ** pin = cpl_malloc(ni * sizeof(CPL_TYPE *)); - const cpl_binary ** pbpm = NULL; +#elif CPL_OPERATION == CPL_IMLIST_BASIC_TIME_MINMAX - /* Output pixel buffer */ - CPL_TYPE * pavg - = cpl_malloc(nx * ny * sizeof(*pavg)); +case CPL_TYPE_T: { + /* Pointers to the ni pixel buffers */ + const CPL_TYPE **pin = cpl_malloc(ni * sizeof(CPL_TYPE *)); + const cpl_binary **pbpm = NULL; - /* A single timeline */ - CPL_TYPE * ptime = cpl_malloc(ni * sizeof(*ptime)); - size_t i, k; + /* Output pixel buffer */ + CPL_TYPE *pavg = cpl_malloc(nx * ny * sizeof(*pavg)); - avg = CPL_IMAGE_WRAP(nx, ny, pavg); + /* A single timeline */ + CPL_TYPE *ptime = cpl_malloc(ni * sizeof(*ptime)); + size_t i, k; - /* Find planes with a non-empty bad pixel map - if any */ - for (k = 0; k < ni; k++) { + avg = CPL_IMAGE_WRAP(nx, ny, pavg); - const cpl_mask * bpm - = cpl_image_get_bpm_const(self->images[k]); + /* Find planes with a non-empty bad pixel map - if any */ + for (k = 0; k < ni; k++) { + const cpl_mask *bpm = cpl_image_get_bpm_const(self->images[k]); - pin[k] = CPL_IMAGE_GET_DATA_CONST(cpl_imagelist_get_const(self, k)); + pin[k] = CPL_IMAGE_GET_DATA_CONST(cpl_imagelist_get_const(self, k)); - if (bpm != NULL && !cpl_mask_is_empty(bpm)) { - /* Found one */ - if (pbpm == NULL) { - pbpm = cpl_calloc(ni, sizeof(*pbpm)); - /* Assume that cpl_calloc() fills with NULL */ - } - pbpm[k] = cpl_mask_get_data_const(bpm); + if (bpm != NULL && !cpl_mask_is_empty(bpm)) { + /* Found one */ + if (pbpm == NULL) { + pbpm = cpl_calloc(ni, sizeof(*pbpm)); + /* Assume that cpl_calloc() fills with NULL */ } - + pbpm[k] = cpl_mask_get_data_const(bpm); } + } - /* Loop on the pixels */ - for (i = 0; i < nx * ny; i++) { - size_t igood = 0; - size_t ilow, ihigh; - size_t ihbad; + /* Loop on the pixels */ + for (i = 0; i < nx * ny; i++) { + size_t igood = 0; + size_t ilow, ihigh; + size_t ihbad; - /* Fill the timeline */ - for (k = 0; k < ni; k++) { - if (pbpm == NULL || pbpm[k] == NULL || !pbpm[k][i]) { - ptime[igood++] = pin[k][i]; - } + /* Fill the timeline */ + for (k = 0; k < ni; k++) { + if (pbpm == NULL || pbpm[k] == NULL || !pbpm[k][i]) { + ptime[igood++] = pin[k][i]; } + } - ihbad = (ni - igood) / 2; - - ilow = (size_t)nlow > ihbad ? (size_t)nlow - ihbad : 0; - ihigh = (size_t)nhigh > ihbad ? (size_t)nhigh - ihbad : 0; + ihbad = (ni - igood) / 2; - if (igood > ilow + ihigh) { - double mean = 0.0; - const size_t iuse = igood - ilow - ihigh; + ilow = (size_t)nlow > ihbad ? (size_t)nlow - ihbad : 0; + ihigh = (size_t)nhigh > ihbad ? (size_t)nhigh - ihbad : 0; - /* Place ilow and ihigh samples at the ends */ - if (ilow > 0) (void)CPL_TOOLS_GET_KTH(ptime, igood, ilow-1); - if (ihigh > 0) (void)CPL_TOOLS_GET_KTH(ptime + ilow, - iuse + ihigh, iuse); + if (igood > ilow + ihigh) { + double mean = 0.0; + const size_t iuse = igood - ilow - ihigh; + + /* Place ilow and ihigh samples at the ends */ + if (ilow > 0) + (void)CPL_TOOLS_GET_KTH(ptime, igood, ilow - 1); + if (ihigh > 0) + (void)CPL_TOOLS_GET_KTH(ptime + ilow, iuse + ihigh, iuse); - /* Compute the average - using the recurrence relation from + /* Compute the average - using the recurrence relation from cpl_tools_get_mean_double() */ - for (k = 0; k < iuse; k++) - mean += ((double)ptime[ilow + k] - mean) / (double)(k + 1); + for (k = 0; k < iuse; k++) + mean += ((double)ptime[ilow + k] - mean) / (double)(k + 1); - pavg[i] = (CPL_TYPE)mean; + pavg[i] = (CPL_TYPE)mean; - cpl_tools_add_flops(3 * iuse); - } else { - pavg[i] = (CPL_TYPE)0; - cpl_image_reject(avg, i%nx + 1, i/nx + 1); - } + cpl_tools_add_flops(3 * iuse); + } + else { + pavg[i] = (CPL_TYPE)0; + cpl_image_reject(avg, i % nx + 1, i / nx + 1); } + } - cpl_free(pin); - cpl_free(ptime); - cpl_free(pbpm); + cpl_free(pin); + cpl_free(ptime); + cpl_free(pbpm); - break; - } + break; +} #elif CPL_OPERATION == CPL_IMLIST_BASIC_TIME_SIGCLIP - case CPL_TYPE_T: - { - /* Need at least two values for the standard deviation */ - const cpl_size notok = CX_MAX(1, (cpl_size)(keepfrac * (double)ni)); - /* The pixel buffer of the output image */ - CPL_TYPE * pclipped = (CPL_TYPE*)cpl_malloc((size_t)nx * (size_t)ny * - sizeof(*pclipped)); - /* Temporary array for the non-clipped values */ - double * pvals = (double*)cpl_malloc((size_t)ni * sizeof(double)); - cpl_size i; - - clipped = cpl_image_wrap(nx, ny, CPL_TYPE_T, (void*)pclipped); - - /* Loop on the pixels */ - for (i = 0; i < nx * ny; i++) { - double mean = 0.0; /* Value to use when all pixels are bad */ - cpl_size nok = 0; /* Number of values used in this timeline */ - /* Need a 2nd counter, for convergence check and for contribution */ - cpl_size prevok = ni + 1; /* No convergence before 1st iteration */ - cpl_size k; - - /* Extract and count the non-bad values for this pixel */ - for (k = 0; k < ni; k++) { - const cpl_image * imgk = cpl_imagelist_get_const(self, k); - const cpl_mask * bpm = cpl_image_get_bpm_const(imgk); - const cpl_binary * bbpm = bpm ? cpl_mask_get_data_const(bpm) - : NULL; - - if (bbpm == NULL || !bbpm[i]) { - const CPL_TYPE * pimg = CPL_IMAGE_GET_DATA_CONST(imgk); - pvals[nok++] = (double)pimg[i]; - } +case CPL_TYPE_T: { + /* Need at least two values for the standard deviation */ + const cpl_size notok = CX_MAX(1, (cpl_size)(keepfrac * (double)ni)); + /* The pixel buffer of the output image */ + CPL_TYPE *pclipped = + (CPL_TYPE *)cpl_malloc((size_t)nx * (size_t)ny * sizeof(*pclipped)); + /* Temporary array for the non-clipped values */ + double *pvals = (double *)cpl_malloc((size_t)ni * sizeof(double)); + cpl_size i; + + clipped = cpl_image_wrap(nx, ny, CPL_TYPE_T, (void *)pclipped); + + /* Loop on the pixels */ + for (i = 0; i < nx * ny; i++) { + double mean = 0.0; /* Value to use when all pixels are bad */ + cpl_size nok = 0; /* Number of values used in this timeline */ + /* Need a 2nd counter, for convergence check and for contribution */ + cpl_size prevok = ni + 1; /* No convergence before 1st iteration */ + cpl_size k; + + /* Extract and count the non-bad values for this pixel */ + for (k = 0; k < ni; k++) { + const cpl_image *imgk = cpl_imagelist_get_const(self, k); + const cpl_mask *bpm = cpl_image_get_bpm_const(imgk); + const cpl_binary *bbpm = bpm ? cpl_mask_get_data_const(bpm) : NULL; + + if (bbpm == NULL || !bbpm[i]) { + const CPL_TYPE *pimg = CPL_IMAGE_GET_DATA_CONST(imgk); + pvals[nok++] = (double)pimg[i]; } + } - /* Will not actually enter when there are too many bad pixels */ - while (notok < nok && nok < prevok) { - /* cpl_tools_get_variancesum_double() is trusted to return + /* Will not actually enter when there are too many bad pixels */ + while (notok < nok && nok < prevok) { + /* cpl_tools_get_variancesum_double() is trusted to return a non-negative result even with rounding errors, so we assume it is safe to take the sqrt() below. Compute also the mean. Since it is computed prior to the clipping, it is the mean-value sought once the iteration has stopped. */ - const double varsum = cpl_tools_get_variancesum_double - (pvals, nok, &mean); + const double varsum = + cpl_tools_get_variancesum_double(pvals, nok, &mean); - /* When computed, the median permutes the (non-clipped) + /* When computed, the median permutes the (non-clipped) values, but this has no effect on the result. */ - const double center = mode == CPL_COLLAPSE_MEAN || - (mode == CPL_COLLAPSE_MEDIAN_MEAN && prevok < ni + 1) - ? mean : cpl_tools_get_median_double(pvals, nok); - - /* Compute the clipping thresholds */ - const double stdev = sqrt(varsum / (double) (nok-1)); - const double low_thresh = center - kappalow * stdev; - const double high_thresh = center + kappahigh * stdev; - - prevok = nok; - /* Count the initial all-ok values */ - for (nok = 0; nok < prevok; nok++) { - /* Use exact same clipping criterion as next loop */ - if (!(low_thresh < pvals[nok] && - pvals[nok] < high_thresh)) { - break; - } + const double center = + mode == CPL_COLLAPSE_MEAN || + (mode == CPL_COLLAPSE_MEDIAN_MEAN && prevok < ni + 1) + ? mean + : cpl_tools_get_median_double(pvals, nok); + + /* Compute the clipping thresholds */ + const double stdev = sqrt(varsum / (double)(nok - 1)); + const double low_thresh = center - kappalow * stdev; + const double high_thresh = center + kappahigh * stdev; + + prevok = nok; + /* Count the initial all-ok values */ + for (nok = 0; nok < prevok; nok++) { + /* Use exact same clipping criterion as next loop */ + if (!(low_thresh < pvals[nok] && pvals[nok] < high_thresh)) { + break; } + } - /* All values may have been checked above, but if not + /* All values may have been checked above, but if not skip the one that cause the above loop to stop and check the rest and repack+count as necessary */ - for (k = nok+1; k < prevok; k++) { - if (low_thresh < pvals[k] && - pvals[k] < high_thresh) { - pvals[nok++] = pvals[k]; - } + for (k = nok + 1; k < prevok; k++) { + if (low_thresh < pvals[k] && pvals[k] < high_thresh) { + pvals[nok++] = pvals[k]; } } + } - if (prevok == ni+1) { - /* The clipping loop was not entered at all */ + if (prevok == ni + 1) { + /* The clipping loop was not entered at all */ - prevok = nok; /* Needed for the contribution map */ + prevok = nok; /* Needed for the contribution map */ - /* The mean must be computed (without clipping) */ - if (nok == 0) { /* All pixels are bad, so result pixel is bad */ - /* The call for the 1st bad pixel will create the bpm */ - cpl_mask * bpm = cpl_image_get_bpm(clipped); - cpl_binary * bbpm = cpl_mask_get_data(bpm); + /* The mean must be computed (without clipping) */ + if (nok == 0) { /* All pixels are bad, so result pixel is bad */ + /* The call for the 1st bad pixel will create the bpm */ + cpl_mask *bpm = cpl_image_get_bpm(clipped); + cpl_binary *bbpm = cpl_mask_get_data(bpm); - bbpm[i] = CPL_BINARY_1; - } else { - mean = cpl_tools_get_mean_double(pvals, nok); - } + bbpm[i] = CPL_BINARY_1; } - - /* Set the output image pixel value */ - pclipped[i] = (CPL_TYPE)mean; - - if (pcontrib) { - /* The contributing number of values */ - pcontrib[i] = (int)prevok; - if((cpl_size)pcontrib[i] != prevok) break; + else { + mean = cpl_tools_get_mean_double(pvals, nok); } + } - cpl_tools_add_flops(6 + prevok); + /* Set the output image pixel value */ + pclipped[i] = (CPL_TYPE)mean; + if (pcontrib) { + /* The contributing number of values */ + pcontrib[i] = (int)prevok; + if ((cpl_size)pcontrib[i] != prevok) + break; } - cpl_free(pvals); + cpl_tools_add_flops(6 + prevok); + } - if (i < nx * ny) { - cpl_image_delete(clipped); - clipped = NULL; - (void)cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); - } + cpl_free(pvals); - break; + if (i < nx * ny) { + cpl_image_delete(clipped); + clipped = NULL; + (void)cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); } -#elif CPL_OPERATION == CPL_IMLIST_BASIC_SWAP_AXIS + break; +} - case CPL_TYPE_T: - { - CPL_TYPE * pcur_ima; - const CPL_TYPE * pold_ima; +#elif CPL_OPERATION == CPL_IMLIST_BASIC_SWAP_AXIS - /* SWAP X <-> Z */ - if (mode == CPL_SWAP_AXIS_XZ) { - for (i=0; i Z */ + if (mode == CPL_SWAP_AXIS_XZ) { + for (i = 0; i < nx; i++) { + cur_ima = cpl_image_new(ni, ny, CPL_TYPE_T); + pcur_ima = CPL_IMAGE_GET_DATA(cur_ima); + for (j = 0; j < ni; j++) { + old_ima = cpl_imagelist_get_const(ilist, j); + pold_ima = CPL_IMAGE_GET_DATA_CONST(old_ima); + for (k = 0; k < ny; k++) { + pcur_ima[j + k * ni] = pold_ima[i + k * nx]; } - cpl_imagelist_set(swapped, cur_ima, i); } - } else { + cpl_imagelist_set(swapped, cur_ima, i); + } + } + else { /* SWAP Y <-> Z */ - for (i=0; ini; i++) - cpl_ensure_code( !cpl_image_add_scalar(imlist->images[i], addend), - cpl_error_get_code()); + + for (i = 0; i < imlist->ni; i++) + cpl_ensure_code(!cpl_image_add_scalar(imlist->images[i], addend), + cpl_error_get_code()); return CPL_ERROR_NONE; } @@ -281,18 +266,18 @@ @see cpl_imagelist_add_scalar() */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_imagelist_subtract_scalar( - cpl_imagelist * imlist, - double subtrahend) +cpl_error_code +cpl_imagelist_subtract_scalar(cpl_imagelist *imlist, double subtrahend) { - cpl_size i; + cpl_size i; /* Check inputs */ cpl_ensure_code(imlist != NULL, CPL_ERROR_NULL_INPUT); - - for (i=0; i < imlist->ni; i++) - cpl_ensure_code(!cpl_image_subtract_scalar(imlist->images[i],subtrahend), - cpl_error_get_code()); + + for (i = 0; i < imlist->ni; i++) + cpl_ensure_code(!cpl_image_subtract_scalar(imlist->images[i], + subtrahend), + cpl_error_get_code()); return CPL_ERROR_NONE; } @@ -307,18 +292,17 @@ @see cpl_imagelist_add_scalar() */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_imagelist_multiply_scalar( - cpl_imagelist * imlist, - double factor) +cpl_error_code +cpl_imagelist_multiply_scalar(cpl_imagelist *imlist, double factor) { - cpl_size i; + cpl_size i; /* Check inputs */ cpl_ensure_code(imlist != NULL, CPL_ERROR_NULL_INPUT); - - for (i=0; i < imlist->ni; i++) - cpl_ensure_code( !cpl_image_multiply_scalar(imlist->images[i], factor), - cpl_error_get_code()); + + for (i = 0; i < imlist->ni; i++) + cpl_ensure_code(!cpl_image_multiply_scalar(imlist->images[i], factor), + cpl_error_get_code()); return CPL_ERROR_NONE; } @@ -336,18 +320,17 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_imagelist_divide_scalar( - cpl_imagelist * imlist, - double divisor) +cpl_error_code +cpl_imagelist_divide_scalar(cpl_imagelist *imlist, double divisor) { - cpl_size i; + cpl_size i; /* Check inputs */ cpl_ensure_code(imlist != NULL, CPL_ERROR_NULL_INPUT); - - for (i=0; i < imlist->ni; i++) - cpl_ensure_code( !cpl_image_divide_scalar(imlist->images[i], divisor), - cpl_error_get_code()); + + for (i = 0; i < imlist->ni; i++) + cpl_ensure_code(!cpl_image_divide_scalar(imlist->images[i], divisor), + cpl_error_get_code()); return CPL_ERROR_NONE; } @@ -365,18 +348,17 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_imagelist_logarithm( - cpl_imagelist * imlist, - double base) +cpl_error_code +cpl_imagelist_logarithm(cpl_imagelist *imlist, double base) { - cpl_size i; + cpl_size i; /* Check inputs */ cpl_ensure_code(imlist != NULL, CPL_ERROR_NULL_INPUT); - - for (i=0; i < imlist->ni; i++) - cpl_ensure_code( !cpl_image_logarithm(imlist->images[i], base), - cpl_error_get_code()); + + for (i = 0; i < imlist->ni; i++) + cpl_ensure_code(!cpl_image_logarithm(imlist->images[i], base), + cpl_error_get_code()); return CPL_ERROR_NONE; } @@ -394,18 +376,17 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_imagelist_exponential( - cpl_imagelist * imlist, - double base) +cpl_error_code +cpl_imagelist_exponential(cpl_imagelist *imlist, double base) { - cpl_size i; + cpl_size i; /* Check inputs */ cpl_ensure_code(imlist != NULL, CPL_ERROR_NULL_INPUT); - - for (i=0; i < imlist->ni; i++) - cpl_ensure_code( !cpl_image_exponential(imlist->images[i], base), - cpl_error_get_code()); + + for (i = 0; i < imlist->ni; i++) + cpl_ensure_code(!cpl_image_exponential(imlist->images[i], base), + cpl_error_get_code()); return CPL_ERROR_NONE; } @@ -423,18 +404,17 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_imagelist_power( - cpl_imagelist * imlist, - double exponent) +cpl_error_code +cpl_imagelist_power(cpl_imagelist *imlist, double exponent) { - cpl_size i; + cpl_size i; /* Check inputs */ cpl_ensure_code(imlist != NULL, CPL_ERROR_NULL_INPUT); - - for (i=0; i < imlist->ni; i++) - cpl_ensure_code( !cpl_image_power(imlist->images[i], exponent), - cpl_error_get_code()); + + for (i = 0; i < imlist->ni; i++) + cpl_ensure_code(!cpl_image_power(imlist->images[i], exponent), + cpl_error_get_code()); return CPL_ERROR_NONE; } @@ -454,17 +434,16 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_imagelist_normalise( - cpl_imagelist * imlist, - cpl_norm mode) +cpl_error_code +cpl_imagelist_normalise(cpl_imagelist *imlist, cpl_norm mode) { - cpl_size i; + cpl_size i; /* Check inputs */ cpl_ensure_code(imlist != NULL, CPL_ERROR_NULL_INPUT); - - for (i=0; ini; i++) - cpl_ensure_code(!cpl_image_normalise(imlist->images[i], mode), + + for (i = 0; i < imlist->ni; i++) + cpl_ensure_code(!cpl_image_normalise(imlist->images[i], mode), cpl_error_get_code()); return CPL_ERROR_NONE; @@ -490,20 +469,20 @@ - CPL_ERROR_INCOMPATIBLE_INPUT if lo_cut is bigger than hi_cut */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_imagelist_threshold( - cpl_imagelist * imlist, - double lo_cut, - double hi_cut, - double assign_lo_cut, - double assign_hi_cut) +cpl_error_code +cpl_imagelist_threshold(cpl_imagelist *imlist, + double lo_cut, + double hi_cut, + double assign_lo_cut, + double assign_hi_cut) { - cpl_size i; + cpl_size i; /* Check inputs */ cpl_ensure_code(imlist != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(lo_cut < hi_cut, CPL_ERROR_INCOMPATIBLE_INPUT); - - for (i=0; ini; i++) + + for (i = 0; i < imlist->ni; i++) cpl_ensure_code(!cpl_image_threshold(imlist->images[i], lo_cut, hi_cut, assign_lo_cut, assign_hi_cut), cpl_error_get_code()); @@ -520,11 +499,12 @@ @param mask input mask */ /*----------------------------------------------------------------------------*/ -static void mask_sub(cpl_image * img, const cpl_mask * mask) +static void +mask_sub(cpl_image *img, const cpl_mask *mask) { size_t npix = cpl_image_get_size_x(img) * cpl_image_get_size_y(img); - int * imgd = cpl_image_get_data_int(img); - const cpl_binary * maskd = cpl_mask_get_data_const(mask); + int *imgd = cpl_image_get_data_int(img); + const cpl_binary *maskd = cpl_mask_get_data_const(mask); for (size_t i = 0; i < npix; i++) { imgd[i] -= maskd[i] != CPL_BINARY_0; } @@ -546,18 +526,19 @@ - CPL_ERROR_ILLEGAL_INPUT if the input image list is not valid */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_image_new_from_accepted(const cpl_imagelist * imlist) +cpl_image * +cpl_image_new_from_accepted(const cpl_imagelist *imlist) { - const cpl_image * first = cpl_imagelist_get_const(imlist, 0); - const cpl_size nx = cpl_image_get_size_x(first); - const cpl_size ny = cpl_image_get_size_y(first); - const size_t nz = cpl_imagelist_get_size(imlist); - cpl_image * goodsum; - size_t i; - + const cpl_image *first = cpl_imagelist_get_const(imlist, 0); + const cpl_size nx = cpl_image_get_size_x(first); + const cpl_size ny = cpl_image_get_size_y(first); + const size_t nz = cpl_imagelist_get_size(imlist); + cpl_image *goodsum; + size_t i; + cpl_ensure(imlist != NULL, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(cpl_imagelist_is_uniform(imlist)==0, CPL_ERROR_ILLEGAL_INPUT, + cpl_ensure(cpl_imagelist_is_uniform(imlist) == 0, CPL_ERROR_ILLEGAL_INPUT, NULL); goodsum = cpl_image_new(nx, ny, CPL_TYPE_INT); @@ -566,8 +547,8 @@ /* Loop on the images */ for (i = 0; i < nz; i++) { - const cpl_mask * bpmap - = cpl_image_get_bpm_const(cpl_imagelist_get_const(imlist, i)); + const cpl_mask *bpmap = + cpl_image_get_bpm_const(cpl_imagelist_get_const(imlist, i)); if (bpmap != NULL) { mask_sub(goodsum, bpmap); @@ -598,37 +579,40 @@ - CPL_ERROR_ILLEGAL_INPUT if the input image list is not valid */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_imagelist_collapse_create(const cpl_imagelist * imlist) +cpl_image * +cpl_imagelist_collapse_create(const cpl_imagelist *imlist) { - cpl_image * avg; - cpl_image * contrib; - cpl_size i; - + cpl_image *avg; + cpl_image *contrib; + cpl_size i; + /* Check inputs */ cpl_ensure(imlist != NULL, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(cpl_imagelist_is_uniform(imlist)==0, CPL_ERROR_ILLEGAL_INPUT, + cpl_ensure(cpl_imagelist_is_uniform(imlist) == 0, CPL_ERROR_ILLEGAL_INPUT, NULL); /* Should not be able to fail now */ - + /* Create avg with the first image */ avg = cpl_image_duplicate(imlist->images[0]); cpl_image_fill_rejected(avg, 0.0); cpl_image_accept_all(avg); - + /* Add all images together */ - for (i=1; ini; i++) { - cpl_image * tmp_im; + for (i = 1; i < imlist->ni; i++) { + cpl_image *tmp_im; if (cpl_image_get_bpm_const(imlist->images[i])) { tmp_im = cpl_image_duplicate(imlist->images[i]); cpl_image_fill_rejected(tmp_im, 0.0); cpl_image_accept_all(tmp_im); - } else { + } + else { tmp_im = imlist->images[i]; } cpl_image_add(avg, tmp_im); - if (tmp_im != imlist->images[i]) cpl_image_delete(tmp_im); + if (tmp_im != imlist->images[i]) + cpl_image_delete(tmp_im); } /* Compute the contribution map */ @@ -647,7 +631,7 @@ cpl_image_delete(contrib); - return avg; + return avg; } #define CPL_OPERATION CPL_IMLIST_BASIC_TIME_MINMAX @@ -689,26 +673,27 @@ - CPL_ERROR_INVALID_TYPE if the passed image list type is not supported */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_imagelist_collapse_minmax_create(const cpl_imagelist * self, - cpl_size nlow, - cpl_size nhigh) -{ - const cpl_image * imgself = cpl_imagelist_get_const(self, 0); - const cpl_type type = cpl_image_get_type(imgself); - const size_t ni = cpl_imagelist_get_size(self); - const size_t nx = cpl_image_get_size_x(imgself); - const size_t ny = cpl_image_get_size_y(imgself); - const size_t nrej = (size_t)(nlow + nhigh); - cpl_image * avg = NULL; - - - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(cpl_imagelist_is_uniform(self)==0, CPL_ERROR_ILLEGAL_INPUT, +cpl_image * +cpl_imagelist_collapse_minmax_create(const cpl_imagelist *self, + cpl_size nlow, + cpl_size nhigh) +{ + const cpl_image *imgself = cpl_imagelist_get_const(self, 0); + const cpl_type type = cpl_image_get_type(imgself); + const size_t ni = cpl_imagelist_get_size(self); + const size_t nx = cpl_image_get_size_x(imgself); + const size_t ny = cpl_image_get_size_y(imgself); + const size_t nrej = (size_t)(nlow + nhigh); + cpl_image *avg = NULL; + + + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(cpl_imagelist_is_uniform(self) == 0, CPL_ERROR_ILLEGAL_INPUT, NULL); - cpl_ensure(nlow >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL); - cpl_ensure(nhigh >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL); - cpl_ensure(ni > nrej, CPL_ERROR_ILLEGAL_INPUT, NULL); - + cpl_ensure(nlow >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(nhigh >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(ni > nrej, CPL_ERROR_ILLEGAL_INPUT, NULL); + /* Switch on the data type */ switch (type) { #define CPL_CLASS CPL_CLASS_DOUBLE @@ -815,40 +800,40 @@ */ /*----------------------------------------------------------------------------*/ cpl_image * -cpl_imagelist_collapse_sigclip_create(const cpl_imagelist * self, - double kappalow, - double kappahigh, - double keepfrac, - cpl_collapse_mode mode, - cpl_image * contrib) -{ - const cpl_size ni = cpl_imagelist_get_size(self); - const cpl_image * img = cpl_imagelist_get_const(self, 0); - const cpl_size nx = cpl_image_get_size_x(img); - const cpl_size ny = cpl_image_get_size_y(img); - cpl_image * clipped = NULL; - int * pcontrib = NULL; +cpl_imagelist_collapse_sigclip_create(const cpl_imagelist *self, + double kappalow, + double kappahigh, + double keepfrac, + cpl_collapse_mode mode, + cpl_image *contrib) +{ + const cpl_size ni = cpl_imagelist_get_size(self); + const cpl_image *img = cpl_imagelist_get_const(self, 0); + const cpl_size nx = cpl_image_get_size_x(img); + const cpl_size ny = cpl_image_get_size_y(img); + cpl_image *clipped = NULL; + int *pcontrib = NULL; /* Check inputs */ - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(kappalow + kappahigh > 0.0, CPL_ERROR_ILLEGAL_INPUT, NULL); - cpl_ensure(keepfrac > 0.0, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL); - cpl_ensure(keepfrac <= 1.0, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL); - cpl_ensure(ni > 1, CPL_ERROR_DATA_NOT_FOUND, NULL); + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(kappalow + kappahigh > 0.0, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(keepfrac > 0.0, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL); + cpl_ensure(keepfrac <= 1.0, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL); + cpl_ensure(ni > 1, CPL_ERROR_DATA_NOT_FOUND, NULL); cpl_ensure(cpl_imagelist_is_uniform(self) == 0, CPL_ERROR_ILLEGAL_INPUT, NULL); - cpl_ensure(mode == CPL_COLLAPSE_MEDIAN_MEAN || mode == CPL_COLLAPSE_MEDIAN - || mode == CPL_COLLAPSE_MEAN, + cpl_ensure(mode == CPL_COLLAPSE_MEDIAN_MEAN || + mode == CPL_COLLAPSE_MEDIAN || mode == CPL_COLLAPSE_MEAN, CPL_ERROR_UNSUPPORTED_MODE, NULL); if (contrib) { - cpl_ensure(cpl_image_get_size_x(contrib) == nx, - CPL_ERROR_ILLEGAL_INPUT, NULL); - cpl_ensure(cpl_image_get_size_y(contrib) == ny, - CPL_ERROR_ILLEGAL_INPUT, NULL); - cpl_ensure(cpl_image_get_type(contrib) == CPL_TYPE_INT, + cpl_ensure(cpl_image_get_size_x(contrib) == nx, CPL_ERROR_ILLEGAL_INPUT, + NULL); + cpl_ensure(cpl_image_get_size_y(contrib) == ny, CPL_ERROR_ILLEGAL_INPUT, + NULL); + cpl_ensure(cpl_image_get_type(contrib) == CPL_TYPE_INT, CPL_ERROR_ILLEGAL_INPUT, NULL); pcontrib = cpl_image_get_data_int(contrib); @@ -867,8 +852,8 @@ #define CPL_CLASS CPL_CLASS_INT #include "cpl_imagelist_basic_body.h" #undef CPL_CLASS - default: - (void)cpl_error_set_(CPL_ERROR_INVALID_TYPE); + default: + (void)cpl_error_set_(CPL_ERROR_INVALID_TYPE); } return clipped; @@ -907,18 +892,19 @@ - CPL_ERROR_INVALID_TYPE if the passed image list pixel type is not supported */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_imagelist_collapse_median_create(const cpl_imagelist * self) +cpl_image * +cpl_imagelist_collapse_median_create(const cpl_imagelist *self) { - cpl_image * median = NULL; - const cpl_image * imself = cpl_imagelist_get_const(self, 0); - const size_t nx = (size_t)cpl_image_get_size_x(imself); - const size_t ny = (size_t)cpl_image_get_size_y(imself); - const cpl_type type = cpl_image_get_type(imself); - + cpl_image *median = NULL; + const cpl_image *imself = cpl_imagelist_get_const(self, 0); + const size_t nx = (size_t)cpl_image_get_size_x(imself); + const size_t ny = (size_t)cpl_image_get_size_y(imself); + const cpl_type type = cpl_image_get_type(imself); + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); cpl_ensure(cpl_imagelist_is_uniform(self) == 0, CPL_ERROR_ILLEGAL_INPUT, NULL); - + /* Switch on the data type */ switch (type) { #define CPL_CLASS CPL_CLASS_DOUBLE @@ -936,7 +922,7 @@ (void)cpl_error_set_(CPL_ERROR_INVALID_TYPE); } - return median; + return median; } #undef CPL_OPERATION @@ -965,28 +951,27 @@ - CPL_ERROR_INVALID_TYPE if the passed image list type is not supported */ /*----------------------------------------------------------------------------*/ -cpl_imagelist * cpl_imagelist_swap_axis_create( - const cpl_imagelist * ilist, - cpl_swap_axis mode) +cpl_imagelist * +cpl_imagelist_swap_axis_create(const cpl_imagelist *ilist, cpl_swap_axis mode) { - cpl_imagelist * swapped; - const cpl_image * image; - cpl_image * cur_ima; - const cpl_image * old_ima; - cpl_size ni, nx, ny; - cpl_type type; - int recompute_bpm, nbpm; - cpl_mask * cur_mask; - cpl_binary * pcur_mask; - cpl_binary * pold_mask; - cpl_size i, j, k; + cpl_imagelist *swapped; + const cpl_image *image; + cpl_image *cur_ima; + const cpl_image *old_ima; + cpl_size ni, nx, ny; + cpl_type type; + int recompute_bpm, nbpm; + cpl_mask *cur_mask; + cpl_binary *pcur_mask; + cpl_binary *pold_mask; + cpl_size i, j, k; /* Check entries */ cpl_ensure(ilist != NULL, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(cpl_imagelist_is_uniform(ilist)==0, CPL_ERROR_ILLEGAL_INPUT, + cpl_ensure(cpl_imagelist_is_uniform(ilist) == 0, CPL_ERROR_ILLEGAL_INPUT, NULL); - cpl_ensure(mode==CPL_SWAP_AXIS_XZ || mode==CPL_SWAP_AXIS_YZ, - CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(mode == CPL_SWAP_AXIS_XZ || mode == CPL_SWAP_AXIS_YZ, + CPL_ERROR_ILLEGAL_INPUT, NULL); /* Initialise */ recompute_bpm = 0; @@ -1017,7 +1002,7 @@ /* HANDLE THE BAD PIXELS MASKS */ /* Check if there are bad pixels in the input image list */ - for (i=0; ibpm != NULL) { recompute_bpm = 1; @@ -1029,17 +1014,17 @@ if (recompute_bpm == 1) { /* SWAP X <-> Z */ if (mode == CPL_SWAP_AXIS_XZ) { - for (i=0; ibpm != NULL) { pold_mask = cpl_mask_get_data(image->bpm); - for (k=0; k 0) { - cpl_image * swap = cpl_imagelist_get(swapped, i); + cpl_image *swap = cpl_imagelist_get(swapped, i); cpl_image_reject_from_mask(swap, cur_mask); } cpl_mask_delete(cur_mask); } - } else { - /* SWAP Y <-> Z */ - for (i=0; i Z */ + for (i = 0; i < ny; i++) { cur_mask = cpl_mask_new(nx, ni); pcur_mask = cpl_mask_get_data(cur_mask); nbpm = 0; - for (j=0; jbpm != NULL) { pold_mask = cpl_mask_get_data(image->bpm); - for (k=0; k 0) { - cpl_image * swap = cpl_imagelist_get(swapped, i); + cpl_image *swap = cpl_imagelist_get(swapped, i); cpl_image_reject_from_mask(swap, cur_mask); } cpl_mask_delete(cur_mask); diff -Nru cpl-7.1.4+ds/cplcore/cpl_imagelist_basic.h cpl-7.2.2+ds/cplcore/cpl_imagelist_basic.h --- cpl-7.1.4+ds/cplcore/cpl_imagelist_basic.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_imagelist_basic.h 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -32,14 +32,16 @@ Defines -----------------------------------------------------------------------------*/ -enum _cpl_swap_axis_ { +enum _cpl_swap_axis_ +{ CPL_SWAP_AXIS_XZ, CPL_SWAP_AXIS_YZ }; typedef enum _cpl_swap_axis_ cpl_swap_axis; -typedef enum { +typedef enum +{ CPL_COLLAPSE_MEAN, CPL_COLLAPSE_MEDIAN, CPL_COLLAPSE_MEDIAN_MEAN @@ -69,24 +71,26 @@ cpl_error_code cpl_imagelist_logarithm(cpl_imagelist *, double); cpl_error_code cpl_imagelist_normalise(cpl_imagelist *, cpl_norm); -cpl_error_code cpl_imagelist_threshold(cpl_imagelist *, double, double, - double, double); -cpl_imagelist * cpl_imagelist_swap_axis_create(const cpl_imagelist *, - cpl_swap_axis) CPL_ATTR_ALLOC; +cpl_error_code +cpl_imagelist_threshold(cpl_imagelist *, double, double, double, double); +cpl_imagelist *cpl_imagelist_swap_axis_create(const cpl_imagelist *, + cpl_swap_axis) CPL_ATTR_ALLOC; /* Imagelist to image functions */ -cpl_image * cpl_image_new_from_accepted(const cpl_imagelist *) CPL_ATTR_ALLOC; -cpl_image * cpl_imagelist_collapse_create(const cpl_imagelist *) CPL_ATTR_ALLOC; -cpl_image * cpl_imagelist_collapse_median_create(const cpl_imagelist *) - CPL_ATTR_ALLOC; -cpl_image * cpl_imagelist_collapse_minmax_create(const cpl_imagelist *, - cpl_size, cpl_size) - CPL_ATTR_ALLOC; -cpl_image * cpl_imagelist_collapse_sigclip_create(const cpl_imagelist *, - double, double, double, - cpl_collapse_mode, - cpl_image *) CPL_ATTR_ALLOC; +cpl_image *cpl_image_new_from_accepted(const cpl_imagelist *) CPL_ATTR_ALLOC; +cpl_image *cpl_imagelist_collapse_create(const cpl_imagelist *) CPL_ATTR_ALLOC; +cpl_image * +cpl_imagelist_collapse_median_create(const cpl_imagelist *) CPL_ATTR_ALLOC; +cpl_image *cpl_imagelist_collapse_minmax_create(const cpl_imagelist *, + cpl_size, + cpl_size) CPL_ATTR_ALLOC; +cpl_image *cpl_imagelist_collapse_sigclip_create(const cpl_imagelist *, + double, + double, + double, + cpl_collapse_mode, + cpl_image *) CPL_ATTR_ALLOC; CPL_END_DECLS -#endif +#endif diff -Nru cpl-7.1.4+ds/cplcore/cpl_imagelist_defs.h cpl-7.2.2+ds/cplcore/cpl_imagelist_defs.h --- cpl-7.1.4+ds/cplcore/cpl_imagelist_defs.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_imagelist_defs.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -24,10 +24,10 @@ Define -----------------------------------------------------------------------------*/ -#define CPL_CLASS_NONE 0 -#define CPL_CLASS_DOUBLE 1 -#define CPL_CLASS_FLOAT 2 -#define CPL_CLASS_INT 3 +#define CPL_CLASS_NONE 0 +#define CPL_CLASS_DOUBLE 1 +#define CPL_CLASS_FLOAT 2 +#define CPL_CLASS_INT 3 /*----------------------------------------------------------------------------- Includes @@ -41,11 +41,12 @@ New types -----------------------------------------------------------------------------*/ -struct _cpl_imagelist_ { - cpl_size ni; - cpl_image ** images; +struct _cpl_imagelist_ +{ + cpl_size ni; + cpl_image **images; }; CPL_END_DECLS -#endif +#endif diff -Nru cpl-7.1.4+ds/cplcore/cpl_imagelist.h cpl-7.2.2+ds/cplcore/cpl_imagelist.h --- cpl-7.1.4+ds/cplcore/cpl_imagelist.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_imagelist.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -51,4 +51,4 @@ */ /*----------------------------------------------------------------------------*/ -#endif +#endif diff -Nru cpl-7.1.4+ds/cplcore/cpl_imagelist_io.c cpl-7.2.2+ds/cplcore/cpl_imagelist_io.c --- cpl-7.1.4+ds/cplcore/cpl_imagelist_io.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_imagelist_io.c 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -52,10 +52,14 @@ #define CPL_MSG "Imagelist with %d image(s)\n" #define CPL_IMSG "Image nb %d of %d in imagelist\n" -static -cpl_imagelist * cpl_imagelist_load_one(const char *, cpl_type, cpl_size, - cpl_boolean, cpl_size, cpl_size, - cpl_size, cpl_size) CPL_ATTR_ALLOC; +static cpl_imagelist *cpl_imagelist_load_one(const char *, + cpl_type, + cpl_size, + cpl_boolean, + cpl_size, + cpl_size, + cpl_size, + cpl_size) CPL_ATTR_ALLOC; /**@{*/ @@ -74,9 +78,10 @@ */ /*----------------------------------------------------------------------------*/ -cpl_imagelist * cpl_imagelist_new(void) +cpl_imagelist * +cpl_imagelist_new(void) { - return (cpl_imagelist *) cpl_calloc(1, sizeof(cpl_imagelist)); + return (cpl_imagelist *)cpl_calloc(1, sizeof(cpl_imagelist)); } /*----------------------------------------------------------------------------*/ @@ -107,14 +112,14 @@ - CPL_ERROR_DATA_NOT_FOUND if the data cannot be read from the file */ /*----------------------------------------------------------------------------*/ -cpl_imagelist * cpl_imagelist_load(const char * filename, - cpl_type im_type, - cpl_size xtnum) +cpl_imagelist * +cpl_imagelist_load(const char *filename, cpl_type im_type, cpl_size xtnum) { - cpl_imagelist * self = cpl_imagelist_load_one(filename, im_type, xtnum, - CPL_FALSE, 0, 0, 0, 0); + cpl_imagelist *self = + cpl_imagelist_load_one(filename, im_type, xtnum, CPL_FALSE, 0, 0, 0, 0); - if (self == NULL) cpl_error_set_where_(); + if (self == NULL) + cpl_error_set_where_(); return self; } @@ -150,19 +155,21 @@ - CPL_ERROR_DATA_NOT_FOUND if the data cannot be read from the file */ /*----------------------------------------------------------------------------*/ -cpl_imagelist * cpl_imagelist_load_window(const char * filename, - cpl_type im_type, - cpl_size xtnum, - cpl_size llx, - cpl_size lly, - cpl_size urx, - cpl_size ury) +cpl_imagelist * +cpl_imagelist_load_window(const char *filename, + cpl_type im_type, + cpl_size xtnum, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury) { - cpl_imagelist * self = cpl_imagelist_load_one(filename, im_type, xtnum, - CPL_TRUE, llx, lly, urx, ury); + cpl_imagelist *self = cpl_imagelist_load_one(filename, im_type, xtnum, + CPL_TRUE, llx, lly, urx, ury); - if (self == NULL) cpl_error_set_where_(); + if (self == NULL) + cpl_error_set_where_(); return self; } @@ -178,12 +185,12 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_imagelist_get_size(const cpl_imagelist * imlist) +cpl_size +cpl_imagelist_get_size(const cpl_imagelist *imlist) { - cpl_ensure(imlist != NULL, CPL_ERROR_NULL_INPUT, - -1); + cpl_ensure(imlist != NULL, CPL_ERROR_NULL_INPUT, -1); - assert( imlist->ni >= 0 ); + assert(imlist->ni >= 0); return imlist->ni; } @@ -204,12 +211,11 @@ - CPL_ERROR_ILLEGAL_INPUT if inum is negative */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_imagelist_get(cpl_imagelist * imlist, - cpl_size inum) +cpl_image * +cpl_imagelist_get(cpl_imagelist *imlist, cpl_size inum) { - - cpl_ensure(imlist != NULL, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(inum >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(imlist != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(inum >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL); cpl_ensure(inum < imlist->ni, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL); return imlist->images[inum]; @@ -225,11 +231,11 @@ @see cpl_imagelist_get */ /*----------------------------------------------------------------------------*/ -const cpl_image * cpl_imagelist_get_const(const cpl_imagelist * imlist, - cpl_size inum) +const cpl_image * +cpl_imagelist_get_const(const cpl_imagelist *imlist, cpl_size inum) { - cpl_ensure(imlist != NULL, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(inum >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(imlist != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(inum >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL); cpl_ensure(inum < imlist->ni, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL); return imlist->images[inum]; @@ -271,50 +277,51 @@ images in self */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_imagelist_set(cpl_imagelist * self, - cpl_image * im, - cpl_size pos) +cpl_error_code +cpl_imagelist_set(cpl_imagelist *self, cpl_image *im, cpl_size pos) { - - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(im != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(pos >= 0, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(pos <= self->ni, CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(im != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(pos >= 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(pos <= self->ni, CPL_ERROR_ACCESS_OUT_OF_RANGE); /* Do nothing if the image is already there */ - if (pos < self->ni && im == self->images[pos]) return CPL_ERROR_NONE; + if (pos < self->ni && im == self->images[pos]) + return CPL_ERROR_NONE; if (pos > 0 || self->ni > 1) { /* Require images to have the same size and type */ cpl_ensure_code(cpl_image_get_size_x(im) == - cpl_image_get_size_x(self->images[0]), + cpl_image_get_size_x(self->images[0]), CPL_ERROR_INCOMPATIBLE_INPUT); cpl_ensure_code(cpl_image_get_size_y(im) == - cpl_image_get_size_y(self->images[0]), + cpl_image_get_size_y(self->images[0]), CPL_ERROR_INCOMPATIBLE_INPUT); cpl_ensure_code(cpl_image_get_type(im) == - cpl_image_get_type(self->images[0]), + cpl_image_get_type(self->images[0]), CPL_ERROR_TYPE_MISMATCH); } if (pos == self->ni) { self->ni++; - self->images = cpl_realloc(self->images, - (size_t)self->ni * sizeof(cpl_image*)); - } else { + self->images = + cpl_realloc(self->images, (size_t)self->ni * sizeof(cpl_image *)); + } + else { /* Check if the image at the position to be overwritten is present in only one position */ int i; for (i = 0; i < self->ni; i++) { - if (i != pos && self->images[i] == self->images[pos]) break; + if (i != pos && self->images[i] == self->images[pos]) + break; } if (i == self->ni) { /* The image at the position to be overwritten is present in only one position, so delete it */ /* But first we must check whether its bpm is shared with others */ - const cpl_mask * bpm = cpl_image_get_bpm_const(self->images[pos]); + const cpl_mask *bpm = cpl_image_get_bpm_const(self->images[pos]); if (bpm != NULL) { for (i = 0; i < self->ni; i++) { @@ -357,14 +364,14 @@ images in self */ /*----------------------------------------------------------------------------*/ -cpl_image * cpl_imagelist_unset(cpl_imagelist * self, - cpl_size pos) +cpl_image * +cpl_imagelist_unset(cpl_imagelist *self, cpl_size pos) { - cpl_image * out; + cpl_image *out; - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(pos >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL); - cpl_ensure(pos < self->ni, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL); + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(pos >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(pos < self->ni, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL); /* Get pointer to image to be removed */ out = self->images[pos]; @@ -376,7 +383,7 @@ /* Move the following images one position towards zero */ (void)memmove(self->images + (size_t)pos, self->images + (size_t)pos + 1, - sizeof(cpl_image*) * (size_t)(self->ni - pos)); + sizeof(cpl_image *) * (size_t)(self->ni - pos)); } return out; @@ -396,15 +403,14 @@ */ /*----------------------------------------------------------------------------*/ -void cpl_imagelist_empty(cpl_imagelist * self) +void +cpl_imagelist_empty(cpl_imagelist *self) { - if (self != NULL) { - while (self->ni > 0) { /* An iteration may unset more than 1 image */ cpl_size i = self->ni - 1; - cpl_image * del = cpl_imagelist_unset(self, i); - const cpl_mask * bpm = cpl_image_get_bpm_const(del); + cpl_image *del = cpl_imagelist_unset(self, i); + const cpl_mask *bpm = cpl_image_get_bpm_const(del); cpl_image_delete(del); @@ -414,14 +420,14 @@ if (bpm != NULL && bpm == cpl_image_get_bpm_const(self->images[i])) { /* The same bad pixel map is used also by this image */ - const cpl_mask * samebpm - = cpl_image_unset_bpm(self->images[i]); + const cpl_mask *samebpm = + cpl_image_unset_bpm(self->images[i]); assert(samebpm == bpm); } - if (self->images[i] == del) { + if (self->images[i] == del) { /* This image was inserted more than once in the list */ - const cpl_image * sameimg = cpl_imagelist_unset(self, i); - assert(sameimg == del); + const cpl_image *sameimg = cpl_imagelist_unset(self, i); + assert(sameimg == del); } } } @@ -442,11 +448,10 @@ done and no error is set. */ /*----------------------------------------------------------------------------*/ -void cpl_imagelist_unwrap(cpl_imagelist * self) +void +cpl_imagelist_unwrap(cpl_imagelist *self) { - if (self != NULL) { - cpl_free(self->images); cpl_free(self); } @@ -464,7 +469,8 @@ */ /*----------------------------------------------------------------------------*/ -void cpl_imagelist_delete(cpl_imagelist * self) +void +cpl_imagelist_delete(cpl_imagelist *self) { cpl_imagelist_empty(self); cpl_imagelist_unwrap(self); @@ -492,40 +498,45 @@ - CPL_ERROR_INVALID_TYPE if the passed pixel type is not supported */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_imagelist_cast(cpl_imagelist * self, - const cpl_imagelist * other, - cpl_type type) +cpl_error_code +cpl_imagelist_cast(cpl_imagelist *self, + const cpl_imagelist *other, + cpl_type type) { - if (self == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); - } else if (self == other) { + } + else if (self == other) { return cpl_error_set_(CPL_ERROR_INCOMPATIBLE_INPUT); - } else { - const cpl_boolean inplace = other == NULL ? CPL_TRUE : CPL_FALSE; - const cpl_imagelist * src = inplace ? self : other; - cpl_imagelist * dest = inplace ? cpl_imagelist_new() : self; - const size_t n = (size_t)cpl_imagelist_get_size(src); - const size_t m = (size_t)cpl_imagelist_get_size(dest); - const cpl_type ctype = inplace || m == 0 ? type - : cpl_image_get_type(cpl_imagelist_get_const(dest, 0)); - cpl_error_code code = CPL_ERROR_NONE; - size_t i, j; + } + else { + const cpl_boolean inplace = other == NULL ? CPL_TRUE : CPL_FALSE; + const cpl_imagelist *src = inplace ? self : other; + cpl_imagelist *dest = inplace ? cpl_imagelist_new() : self; + const size_t n = (size_t)cpl_imagelist_get_size(src); + const size_t m = (size_t)cpl_imagelist_get_size(dest); + const cpl_type ctype = + inplace || m == 0 + ? type + : cpl_image_get_type(cpl_imagelist_get_const(dest, 0)); + cpl_error_code code = CPL_ERROR_NONE; + size_t i, j; for (i = j = 0; i < n; i++) { - /* For in-place, empty src along the way */ - const cpl_image * srcimg = cpl_imagelist_get_const(src,(cpl_size)j); - cpl_image * tmpimg = cpl_image_cast(srcimg, ctype); + const cpl_image *srcimg = cpl_imagelist_get_const(src, (cpl_size)j); + cpl_image *tmpimg = cpl_image_cast(srcimg, ctype); - if (tmpimg == NULL) break; + if (tmpimg == NULL) + break; - if (cpl_imagelist_set(dest, tmpimg, m + (cpl_size)i)) break; + if (cpl_imagelist_set(dest, tmpimg, m + (cpl_size)i)) + break; if (inplace) { cpl_size k; - cpl_image* del = cpl_imagelist_unset(self, 0); - const cpl_mask * bpm = cpl_image_get_bpm_const(del); + cpl_image *del = cpl_imagelist_unset(self, 0); + const cpl_mask *bpm = cpl_image_get_bpm_const(del); /* If this image was inserted more than once into the list, it will be deleted in a subsequent iteration */ @@ -542,7 +553,8 @@ } if (k == self->ni) cpl_image_delete(del); - } else { + } + else { j++; } } @@ -553,11 +565,12 @@ if (inplace) { cpl_imagelist_delete(dest); } - } else if (inplace) { + } + else if (inplace) { /* Need to move dest to self (which is empty) */ - cpl_imagelist * tmp = (cpl_imagelist*)cpl_malloc(sizeof(*tmp)); + cpl_imagelist *tmp = (cpl_imagelist *)cpl_malloc(sizeof(*tmp)); - (void)memcpy(tmp, self, sizeof(*tmp)); + (void)memcpy(tmp, self, sizeof(*tmp)); (void)memcpy(self, dest, sizeof(*tmp)); cpl_free(dest); @@ -583,10 +596,11 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_imagelist * cpl_imagelist_duplicate(const cpl_imagelist * imlist) +cpl_imagelist * +cpl_imagelist_duplicate(const cpl_imagelist *imlist) { - cpl_imagelist * out; - cpl_size i; + cpl_imagelist *out; + cpl_size i; cpl_ensure(imlist != NULL, CPL_ERROR_NULL_INPUT, NULL); @@ -594,7 +608,7 @@ out = cpl_imagelist_new(); /* Duplicate the images */ - for (i=0; ini; i++) { + for (i = 0; i < imlist->ni; i++) { cpl_imagelist_set(out, cpl_image_duplicate(imlist->images[i]), i); } @@ -622,28 +636,28 @@ size are different */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_imagelist_erase( - cpl_imagelist * imlist, - const cpl_vector * valid) +cpl_error_code +cpl_imagelist_erase(cpl_imagelist *imlist, const cpl_vector *valid) { - cpl_size nkeep = 0; - cpl_size i; + cpl_size nkeep = 0; + cpl_size i; /* Check entries */ cpl_ensure_code(imlist, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(valid, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(valid, CPL_ERROR_NULL_INPUT); cpl_ensure_code(cpl_vector_get_size(valid) == imlist->ni, CPL_ERROR_INCOMPATIBLE_INPUT); - for (i=0; i < imlist->ni; i++) { + for (i = 0; i < imlist->ni; i++) { if (cpl_vector_get(valid, i) >= -0.5) { /* image is to be kept, place it in the 1st free position */ imlist->images[nkeep] = imlist->images[i]; nkeep++; - } else { + } + else { /* image is to be erased, delete it */ cpl_size k; - const cpl_mask * bpm = cpl_image_get_bpm_const(imlist->images[i]); + const cpl_mask *bpm = cpl_image_get_bpm_const(imlist->images[i]); /* If this image was inserted more than once into the list, it will be deleted in a subsequent iteration */ @@ -678,7 +692,7 @@ @param self Imagelist to save @param filename Name of the FITS file to write @param type The type used to represent the data in the file - @param pl Property list for the output header or NULL + @param plist Property list for the output header or NULL @param mode The desired output options (combined with bitwise or) @return the #_cpl_error_code_ or CPL_ERROR_NONE @see cpl_image_save() @@ -729,21 +743,22 @@ - CPL_ERROR_INVALID_TYPE if the passed image list type is not supported */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_imagelist_save(const cpl_imagelist * self, - const char * filename, - cpl_type type, - const cpl_propertylist * pl, - unsigned mode) +cpl_error_code +cpl_imagelist_save(const cpl_imagelist *self, + const char *filename, + cpl_type type, + const cpl_propertylist *plist, + unsigned mode) { - - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(filename != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(cpl_imagelist_is_uniform(self)==0, + cpl_ensure_code(cpl_imagelist_is_uniform(self) == 0, CPL_ERROR_ILLEGAL_INPUT); - return cpl_image_save_((const cpl_image* const*)self->images, self->ni, - CPL_TRUE, filename, type, pl, mode) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + return cpl_image_save_((const cpl_image *const *)self->images, self->ni, + CPL_TRUE, filename, type, plist, mode) + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } /*----------------------------------------------------------------------------*/ @@ -759,24 +774,29 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -int cpl_imagelist_is_uniform(const cpl_imagelist * imlist) +int +cpl_imagelist_is_uniform(const cpl_imagelist *imlist) { - cpl_type type; - cpl_size nx, ny; - cpl_size i; + cpl_type type; + cpl_size nx, ny; + cpl_size i; cpl_ensure(imlist != NULL, CPL_ERROR_NULL_INPUT, -1); - if (imlist->ni == 0) return 1; + if (imlist->ni == 0) + return 1; /* Check the images */ - nx = cpl_image_get_size_x(imlist->images[0]); - ny = cpl_image_get_size_y(imlist->images[0]); - type = cpl_image_get_type (imlist->images[0]); - - for (i=1; i < imlist->ni; i++) { - if (cpl_image_get_size_x(imlist->images[i]) != nx) return (int)i+1; - if (cpl_image_get_size_y(imlist->images[i]) != ny) return (int)i+1; - if (cpl_image_get_type (imlist->images[i]) != type) return (int)i+1; + nx = cpl_image_get_size_x(imlist->images[0]); + ny = cpl_image_get_size_y(imlist->images[0]); + type = cpl_image_get_type(imlist->images[0]); + + for (i = 1; i < imlist->ni; i++) { + if (cpl_image_get_size_x(imlist->images[i]) != nx) + return (int)i + 1; + if (cpl_image_get_size_y(imlist->images[i]) != ny) + return (int)i + 1; + if (cpl_image_get_type(imlist->images[i]) != type) + return (int)i + 1; } return 0; } @@ -794,28 +814,28 @@ - CPL_ERROR_FILE_IO if a write operation fails */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_imagelist_dump_structure(const cpl_imagelist * self, - FILE * stream) +cpl_error_code +cpl_imagelist_dump_structure(const cpl_imagelist *self, FILE *stream) { - const int msgmin = (int)strlen(CPL_MSG) - 5; + const int msgmin = (int)strlen(CPL_MSG) - 5; int i; - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(stream != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code( fprintf(stream, CPL_MSG, (int)self->ni) >= msgmin, - CPL_ERROR_FILE_IO ); + cpl_ensure_code(fprintf(stream, CPL_MSG, (int)self->ni) >= msgmin, + CPL_ERROR_FILE_IO); - for (i = 0; i < self -> ni; i++) { - const cpl_image * image = cpl_imagelist_get_const(self, i); - const int imsgmin = (int)strlen(CPL_IMSG) - 5; + for (i = 0; i < self->ni; i++) { + const cpl_image *image = cpl_imagelist_get_const(self, i); + const int imsgmin = (int)strlen(CPL_IMSG) - 5; - cpl_ensure_code( fprintf(stream, CPL_IMSG, i, (int)self->ni) >= imsgmin, - CPL_ERROR_FILE_IO ); + cpl_ensure_code(fprintf(stream, CPL_IMSG, i, (int)self->ni) >= imsgmin, + CPL_ERROR_FILE_IO); - cpl_ensure_code( !cpl_image_dump_structure(image, stream), - cpl_error_get_code() ); + cpl_ensure_code(!cpl_image_dump_structure(image, stream), + cpl_error_get_code()); } return CPL_ERROR_NONE; @@ -840,26 +860,30 @@ - CPL_ERROR_ILLEGAL_INPUT if the window definition is wrong (e.g llx > urx) */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_imagelist_dump_window(const cpl_imagelist * self, - cpl_size llx, cpl_size lly, - cpl_size urx, cpl_size ury, - FILE * stream) +cpl_error_code +cpl_imagelist_dump_window(const cpl_imagelist *self, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury, + FILE *stream) { cpl_size i; - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(stream != NULL, CPL_ERROR_NULL_INPUT); - for (i = 0; i < self -> ni; i++) { - const cpl_image * image = cpl_imagelist_get_const(self, i); - const int imsgmin = (int)strlen(CPL_IMSG) - 5; - - cpl_ensure_code( fprintf(stream, CPL_IMSG, (int)i, - (int)self->ni) >= imsgmin, CPL_ERROR_FILE_IO ); - - cpl_ensure_code( !cpl_image_dump_window(image, llx, lly, urx, ury, - stream), - cpl_error_get_code() ); + for (i = 0; i < self->ni; i++) { + const cpl_image *image = cpl_imagelist_get_const(self, i); + const int imsgmin = (int)strlen(CPL_IMSG) - 5; + + cpl_ensure_code(fprintf(stream, CPL_IMSG, (int)i, (int)self->ni) >= + imsgmin, + CPL_ERROR_FILE_IO); + + cpl_ensure_code(!cpl_image_dump_window(image, llx, lly, urx, ury, + stream), + cpl_error_get_code()); } return CPL_ERROR_NONE; @@ -884,36 +908,37 @@ @see cpl_imagelist_load() */ /*----------------------------------------------------------------------------*/ -static cpl_imagelist * cpl_imagelist_load_one(const char * filename, - cpl_type im_type, - cpl_size xtnum, - cpl_boolean do_window, - cpl_size llx, - cpl_size lly, - cpl_size urx, - cpl_size ury) +static cpl_imagelist * +cpl_imagelist_load_one(const char *filename, + cpl_type im_type, + cpl_size xtnum, + cpl_boolean do_window, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury) { - /* Count number of images read - use also to indicate failure */ - cpl_size selfsize; - cpl_imagelist * self; - cpl_image * image; - fitsfile * fptr; - int status = 0; /* CFITSIO status, must be set to zero */ + cpl_size selfsize; + cpl_imagelist *self; + cpl_image *image; + fitsfile *fptr; + int status = 0; /* CFITSIO status, must be set to zero */ /* Initialize to indicate that they need to be read from the file */ - int naxis = 0; - CPL_FITSIO_TYPE naxes[3] ={0, 0, 0}; - cpl_type pix_type = im_type; + int naxis = 0; + CPL_FITSIO_TYPE naxes[3] = { 0, 0, 0 }; + cpl_type pix_type = im_type; /* FIXME: Version 3.2 of fits_open_diskfile() seg-faults on NULL. If fixed in CFITSIO, this check should be removed */ - cpl_ensure(filename != NULL, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(xtnum >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(filename != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(xtnum >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL); if (cpl_io_fits_open_diskfile(&fptr, filename, READONLY, &status)) { - (void)cpl_error_set_fits(CPL_ERROR_FILE_IO, status, fits_open_diskfile, - "filename='%s', im_type=%u, xtnum=%" - CPL_SIZE_FORMAT, filename, im_type, xtnum); + (void)cpl_error_set_fits( + CPL_ERROR_FILE_IO, status, fits_open_diskfile, + "filename='%s', im_type=%u, xtnum=%" CPL_SIZE_FORMAT, filename, + im_type, xtnum); return NULL; } @@ -927,7 +952,8 @@ if (image == NULL || cpl_imagelist_set(self, image, selfsize)) { cpl_image_delete(image); - } else { + } + else { selfsize++; } @@ -936,10 +962,11 @@ int iplane; for (iplane = 1; iplane < naxes[2]; iplane++) { - image = cpl_image_load_(fptr, &naxis, naxes, &pix_type, - filename, iplane, xtnum, - do_window, llx, lly, urx, ury); - if (image == NULL) break; + image = + cpl_image_load_(fptr, &naxis, naxes, &pix_type, filename, + iplane, xtnum, do_window, llx, lly, urx, ury); + if (image == NULL) + break; if (cpl_imagelist_set(self, image, selfsize)) { cpl_image_delete(image); @@ -955,11 +982,13 @@ if (cpl_io_fits_close_file(fptr, &status)) { (void)cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, status, - fits_close_file, "filename='%s', " + fits_close_file, + "filename='%s', " "im_type=%u, xtnum=%" CPL_SIZE_FORMAT, filename, (unsigned)im_type, xtnum); selfsize = 0; /* Indicate failure */ - } else if (selfsize == 0) { + } + else if (selfsize == 0) { (void)cpl_error_set_where_(); } diff -Nru cpl-7.1.4+ds/cplcore/cpl_imagelist_io.h cpl-7.2.2+ds/cplcore/cpl_imagelist_io.h --- cpl-7.1.4+ds/cplcore/cpl_imagelist_io.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_imagelist_io.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -35,19 +35,23 @@ -----------------------------------------------------------------------------*/ /* Imagelist constructors */ -cpl_imagelist * cpl_imagelist_new(void) CPL_ATTR_ALLOC; -cpl_imagelist * cpl_imagelist_load(const char *, cpl_type, cpl_size) - CPL_ATTR_ALLOC; -cpl_imagelist * cpl_imagelist_load_window(const char *, cpl_type, cpl_size, - cpl_size, cpl_size, cpl_size, - cpl_size) CPL_ATTR_ALLOC; +cpl_imagelist *cpl_imagelist_new(void) CPL_ATTR_ALLOC; +cpl_imagelist * +cpl_imagelist_load(const char *, cpl_type, cpl_size) CPL_ATTR_ALLOC; +cpl_imagelist *cpl_imagelist_load_window(const char *, + cpl_type, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_size) CPL_ATTR_ALLOC; /* Imagelist accessors */ cpl_size cpl_imagelist_get_size(const cpl_imagelist *); - cpl_image * cpl_imagelist_get(cpl_imagelist *, cpl_size); -const cpl_image * cpl_imagelist_get_const(const cpl_imagelist *, cpl_size); +cpl_image *cpl_imagelist_get(cpl_imagelist *, cpl_size); +const cpl_image *cpl_imagelist_get_const(const cpl_imagelist *, cpl_size); cpl_error_code cpl_imagelist_set(cpl_imagelist *, cpl_image *, cpl_size); -cpl_image * cpl_imagelist_unset(cpl_imagelist *, cpl_size); +cpl_image *cpl_imagelist_unset(cpl_imagelist *, cpl_size); /* Imagelist destructor */ void cpl_imagelist_delete(cpl_imagelist *); @@ -55,21 +59,27 @@ void cpl_imagelist_empty(cpl_imagelist *); /* Others */ -cpl_imagelist * cpl_imagelist_duplicate(const cpl_imagelist *) CPL_ATTR_ALLOC; +cpl_imagelist *cpl_imagelist_duplicate(const cpl_imagelist *) CPL_ATTR_ALLOC; cpl_error_code cpl_imagelist_erase(cpl_imagelist *, const cpl_vector *); int cpl_imagelist_is_uniform(const cpl_imagelist *); -cpl_error_code cpl_imagelist_cast(cpl_imagelist *, const cpl_imagelist *, - cpl_type); +cpl_error_code +cpl_imagelist_cast(cpl_imagelist *, const cpl_imagelist *, cpl_type); cpl_error_code cpl_imagelist_dump_structure(const cpl_imagelist *, FILE *); cpl_error_code cpl_imagelist_dump_window(const cpl_imagelist *, - cpl_size, cpl_size, cpl_size, cpl_size, FILE *); + cpl_size, + cpl_size, + cpl_size, + cpl_size, + FILE *); /* Saving function */ -cpl_error_code cpl_imagelist_save(const cpl_imagelist *, const char *, - cpl_type, const cpl_propertylist *, +cpl_error_code cpl_imagelist_save(const cpl_imagelist *, + const char *, + cpl_type, + const cpl_propertylist *, unsigned); CPL_END_DECLS -#endif +#endif diff -Nru cpl-7.1.4+ds/cplcore/cpl_image_resample_body.h cpl-7.2.2+ds/cplcore/cpl_image_resample_body.h --- cpl-7.1.4+ds/cplcore/cpl_image_resample_body.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_image_resample_body.h 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -19,18 +19,18 @@ /* Type dependent macros */ #if CPL_CLASS == CPL_CLASS_DOUBLE -#define CPL_TYPE double -#define CPL_TYPE_T CPL_TYPE_DOUBLE +#define CPL_TYPE double +#define CPL_TYPE_T CPL_TYPE_DOUBLE #define CPL_TYPE_INTERPOLATE cpl_image_get_interpolated_double #elif CPL_CLASS == CPL_CLASS_FLOAT -#define CPL_TYPE float -#define CPL_TYPE_T CPL_TYPE_FLOAT +#define CPL_TYPE float +#define CPL_TYPE_T CPL_TYPE_FLOAT #define CPL_TYPE_INTERPOLATE cpl_image_get_interpolated_float #elif CPL_CLASS == CPL_CLASS_INT -#define CPL_TYPE int -#define CPL_TYPE_T CPL_TYPE_INT +#define CPL_TYPE int +#define CPL_TYPE_T CPL_TYPE_INT #define CPL_TYPE_INTERPOLATE cpl_image_get_interpolated_int #else @@ -41,42 +41,38 @@ #if defined CPL_OPERATION && CPL_OPERATION == CPL_IMAGE_RESAMPLE_SUBSAMPLE -case CPL_TYPE_T: -{ +case CPL_TYPE_T: { const CPL_TYPE *pi; - CPL_TYPE *po; + CPL_TYPE *po; out_im = cpl_image_new(new_nx, new_ny, CPL_TYPE_T); - pi = (CPL_TYPE*)image->pixels; - po = (CPL_TYPE*)out_im->pixels; + pi = (CPL_TYPE *)image->pixels; + po = (CPL_TYPE *)out_im->pixels; - for (j = 0; j < image->ny; j += ystep, pi += ystep*image->nx) + for (j = 0; j < image->ny; j += ystep, pi += ystep * image->nx) for (i = 0; i < image->nx; i += xstep) *po++ = pi[i]; -} -break; +} break; #elif defined CPL_OPERATION && CPL_OPERATION == CPL_IMAGE_REBIN -case CPL_TYPE_T: -{ +case CPL_TYPE_T: { const CPL_TYPE *pi; - CPL_TYPE *po; + CPL_TYPE *po; out_im = cpl_image_new(new_nx, new_ny, CPL_TYPE_T); - pi = (CPL_TYPE*)image->pixels; - po = (CPL_TYPE*)out_im->pixels; + pi = (CPL_TYPE *)image->pixels; + po = (CPL_TYPE *)out_im->pixels; for (j = ystart - 1; j < ny; j++) { for (i = xstart - 1; i < nx; i++) { - po[(i-xstart+1)/xstep + ((j-ystart+1)/ystep)*new_nx] - += pi[i + j*old_nx]; + po[(i - xstart + 1) / xstep + + ((j - ystart + 1) / ystep) * new_nx] += pi[i + j * old_nx]; } } -} -break; +} break; #elif defined CPL_OPERATION && CPL_OPERATION == CPL_IMAGE_WARP @@ -85,82 +81,71 @@ /* Double loop on the output image */ for (cpl_size j = 0; j < out->ny; j++) { for (cpl_size i = 0; i < out->nx; i++) { - /* Compute the original source for this pixel */ const cpl_size pos = i + j * out->nx; - const double x = (double)(i+1) - pdeltax[pos]; - const double y = (double)(j+1) - pdeltay[pos]; - double confidence; + const double x = (double)(i + 1) - pdeltax[pos]; + const double y = (double)(j + 1) - pdeltay[pos]; + double confidence; /* Compute the new value */ - const double value = CPL_TYPE_INTERPOLATE - ((const CPL_TYPE*)in->pixels, inbpm, - in->nx, in->ny, - xtabsperpix, ytabsperpix, x, y, - yweight, pxprof, xradius, pyprof, - yradius, sqyradius, sqyxratio, &confidence); + const double value = + CPL_TYPE_INTERPOLATE((const CPL_TYPE *)in->pixels, inbpm, + in->nx, in->ny, xtabsperpix, ytabsperpix, + x, y, yweight, pxprof, xradius, pyprof, + yradius, sqyradius, sqyxratio, + &confidence); if (confidence > 0.0) - cpl_image_set_(out, i+1, j+1, value); + cpl_image_set_(out, i + 1, j + 1, value); else { pbad[i + j * out->nx] = CPL_BINARY_1; hasbad = 1; } } } -break; + break; #elif defined CPL_OPERATION && CPL_OPERATION == CPL_IMAGE_WARP_POLYNOMIAL case CPL_TYPE_T: -/* Double loop on the output image */ -for (j=0; j < out->ny; j++) { - pval[1] = (double)(j+1); - for (i=0; i < out->nx; i++) { - pval[0] = (double)(i+1); - - /* The CPL-calls here cannot fail */ - - /* Compute the original source for this pixel */ - - x = cpl_polynomial_eval(poly_x, val); - y = cpl_polynomial_eval(poly_y, val); - - - value = CPL_TYPE_INTERPOLATE - ((const CPL_TYPE*)in->pixels, - inbpm, - in->nx, in->ny, - xtabsperpix, - ytabsperpix, - x, y, - yweight, - pxprof, - xradius, - pyprof, - yradius, - sqyradius, - sqyxratio, - &confidence); - - - if (confidence > 0) - cpl_image_set_(out, i+1, j+1, value); - else { - pbad[i + j * out->nx] = CPL_BINARY_1; - hasbad = 1; + /* Double loop on the output image */ + for (j = 0; j < out->ny; j++) { + pval[1] = (double)(j + 1); + for (i = 0; i < out->nx; i++) { + pval[0] = (double)(i + 1); + + /* The CPL-calls here cannot fail */ + + /* Compute the original source for this pixel */ + + x = cpl_polynomial_eval(poly_x, val); + y = cpl_polynomial_eval(poly_y, val); + + + value = CPL_TYPE_INTERPOLATE((const CPL_TYPE *)in->pixels, inbpm, + in->nx, in->ny, xtabsperpix, + ytabsperpix, x, y, yweight, pxprof, + xradius, pyprof, yradius, sqyradius, + sqyxratio, &confidence); + + + if (confidence > 0) + cpl_image_set_(out, i + 1, j + 1, value); + else { + pbad[i + j * out->nx] = CPL_BINARY_1; + hasbad = 1; + } } } -} -break; + break; #else #ifdef ADDTYPE #undef ADDTYPE #endif -#define ADDTYPE(a) CONCAT2X(a,CPL_TYPE) +#define ADDTYPE(a) CONCAT2X(a, CPL_TYPE) /*----------------------------------------------------------------------------*/ /** @@ -173,33 +158,33 @@ */ /*----------------------------------------------------------------------------*/ -inline static double -ADDTYPE(cpl_image_get_interpolated)(const CPL_TYPE * pixel, - const cpl_binary * bpm, - cpl_size nx, - cpl_size ny, - double xtabsperpix, - double ytabsperpix, - double xpos, double ypos, - double * yweight, - const double * pxprof, - double xradius, - const double * pyprof, - double yradius, - double sqyradius, - double sqyxratio, - double * pconfid) +inline static double ADDTYPE(cpl_image_get_interpolated)(const CPL_TYPE *pixel, + const cpl_binary *bpm, + cpl_size nx, + cpl_size ny, + double xtabsperpix, + double ytabsperpix, + double xpos, + double ypos, + double *yweight, + const double *pxprof, + double xradius, + const double *pyprof, + double yradius, + double sqyradius, + double sqyxratio, + double *pconfid) { - double sum = 0.0; - double wsum = 0.0; + double sum = 0.0; + double wsum = 0.0; double wconf = 0.0; - double wabs = 0.0; + double wabs = 0.0; /* These image positions can become negative */ - const intptr_t xfirst = (intptr_t)ceil (xpos - xradius); - const intptr_t xlast = (intptr_t)floor(xpos + xradius); - const intptr_t yfirst = (intptr_t)ceil (ypos - yradius); - const intptr_t ylast = (intptr_t)floor(ypos + yradius); + const intptr_t xfirst = (intptr_t)ceil(xpos - xradius); + const intptr_t xlast = (intptr_t)floor(xpos + xradius); + const intptr_t yfirst = (intptr_t)ceil(ypos - yradius); + const intptr_t ylast = (intptr_t)floor(ypos + yradius); #ifdef CPL_ADD_FLOPS cpl_flops skipped = 0; #endif @@ -219,21 +204,21 @@ /* Generate weights for all points in the Y-direction */ for (intptr_t y = yfirst; y <= ylast; y++) - yweight[(size_t)(y-yfirst)] = pyprof[(size_t)(fabs((double)y - ypos) - * ytabsperpix+0.5)]; + yweight[(size_t)(y - yfirst)] = + pyprof[(size_t)(fabs((double)y - ypos) * ytabsperpix + 0.5)]; /* Iterate through all the points in the X-direction */ for (intptr_t x = xfirst; x <= xlast; x++) { const double xdel = (double)x - xpos; - const double sqrest = sqyradius - xdel*xdel*sqyxratio; - const double xweight = pxprof[(size_t)(fabs(xdel) * xtabsperpix+0.5)]; + const double sqrest = sqyradius - xdel * xdel * sqyxratio; + const double xweight = pxprof[(size_t)(fabs(xdel) * xtabsperpix + 0.5)]; /* Iterate through all the points in the Y-direction */ for (intptr_t y = yfirst; y <= ylast; y++) { const double ydel = (double)y - ypos; double value, weight; - if (ydel*ydel > sqrest) { + if (ydel * ydel > sqrest) { #ifdef CPL_ADD_FLOPS skipped += 8; #endif @@ -243,7 +228,7 @@ (xradius, yradius) at (xpos, ypos) */ /* The pixel weight is the product of the two 1D-profiles */ - weight = xweight * yweight[(size_t)(y-yfirst)]; + weight = xweight * yweight[(size_t)(y - yfirst)]; /* Sum of all absolute weights in the inclusion area */ wconf += fabs(weight); @@ -256,14 +241,14 @@ } if (bpm != NULL && - bpm[(size_t)((x-1) + (y-1) * nx)] != CPL_BINARY_0) { + bpm[(size_t)((x - 1) + (y - 1) * nx)] != CPL_BINARY_0) { #ifdef CPL_ADD_FLOPS skipped += 5; #endif continue; } - value = pixel[(size_t)((x-1) + (y-1) * nx)]; + value = pixel[(size_t)((x - 1) + (y - 1) * nx)]; /* Sum of weigths actually used */ wsum += weight; @@ -271,7 +256,6 @@ wabs += fabs(weight); /* Weighted pixel sum */ sum += value * weight; - } } @@ -280,10 +264,9 @@ *pconfid = wconf > 0 ? wabs / wconf : 0; #ifdef CPL_ADD_FLOPS - cpl_tools_add_flops( 3 * ( ylast - yfirst + 1) - + 6 * ( xlast - xfirst + 1) - + 11* ( ylast - yfirst + 1) - * ( xlast - xfirst + 1) - skipped ); + cpl_tools_add_flops(3 * (ylast - yfirst + 1) + 6 * (xlast - xfirst + 1) + + 11 * (ylast - yfirst + 1) * (xlast - xfirst + 1) - + skipped); #endif return wsum > 0.0 ? sum / wsum : 0.0; diff -Nru cpl-7.1.4+ds/cplcore/cpl_image_resample.c cpl-7.2.2+ds/cplcore/cpl_image_resample.c --- cpl-7.1.4+ds/cplcore/cpl_image_resample.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_image_resample.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -44,13 +44,13 @@ Defines -----------------------------------------------------------------------------*/ -#define CPL_IMAGE_RESAMPLE_SUBSAMPLE 1 -#define CPL_IMAGE_WARP 2 -#define CPL_IMAGE_WARP_POLYNOMIAL 3 -#define CPL_IMAGE_REBIN 4 +#define CPL_IMAGE_RESAMPLE_SUBSAMPLE 1 +#define CPL_IMAGE_WARP 2 +#define CPL_IMAGE_WARP_POLYNOMIAL 3 +#define CPL_IMAGE_REBIN 4 -#define CONCAT(a,b) a ## _ ## b -#define CONCAT2X(a,b) CONCAT(a,b) +#define CONCAT(a, b) a##_##b +#define CONCAT2X(a, b) CONCAT(a, b) /*----------------------------------------------------------------------------- @@ -59,46 +59,64 @@ inline static double cpl_image_get_interpolated_double(const double *, const cpl_binary *, - cpl_size, cpl_size, - double, double, - double, double, + cpl_size, + cpl_size, + double, + double, + double, + double, double *, - const double *, double, - const double *, double, - double, double, + const double *, + double, + const double *, + double, + double, + double, double *) #ifdef CPL_HAVE_ATTR_NONNULL - __attribute__((nonnull(1,9,10,12,16))) + __attribute__((nonnull(1, 9, 10, 12, 16))) #endif ; inline static double cpl_image_get_interpolated_float(const float *, const cpl_binary *, - cpl_size, cpl_size, - double, double, - double, double, + cpl_size, + cpl_size, + double, + double, + double, + double, double *, - const double *, double, - const double *, double, - double, double, + const double *, + double, + const double *, + double, + double, + double, double *) #ifdef CPL_HAVE_ATTR_NONNULL - __attribute__((nonnull(1,9,10,12,16))) + __attribute__((nonnull(1, 9, 10, 12, 16))) #endif ; inline static double cpl_image_get_interpolated_int(const int *, const cpl_binary *, - cpl_size, cpl_size, - double, double, - double, double, + cpl_size, + cpl_size, + double, + double, + double, + double, double *, - const double *, double, - const double *, double, - double, double, + const double *, + double, + const double *, + double, + double, + double, double *) #ifdef CPL_HAVE_ATTR_NONNULL - __attribute__((nonnull(1,9,10,12,16))) + __attribute__((nonnull(1, 9, 10, 12, 16))) #endif ; @@ -112,7 +130,7 @@ /*----------------------------------------------------------------------------- Function codes -----------------------------------------------------------------------------*/ - + #define CPL_OPERATION CPL_IMAGE_WARP /*----------------------------------------------------------------------------*/ /** @@ -169,51 +187,51 @@ - CPL_ERROR_INVALID_TYPE if the passed image type is not supported */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_warp( - cpl_image * out, - const cpl_image * in, - const cpl_image * deltax, - const cpl_image * deltay, - const cpl_vector * xprofile, - double xradius, - const cpl_vector * yprofile, - double yradius) +cpl_error_code +cpl_image_warp(cpl_image *out, + const cpl_image *in, + const cpl_image *deltax, + const cpl_image *deltay, + const cpl_vector *xprofile, + double xradius, + const cpl_vector *yprofile, + double yradius) { - cpl_mask * bad; - cpl_binary * pbad; - int hasbad; - const double sqxradius = xradius * xradius; - const double sqyradius = yradius * yradius; - double sqyxratio; - double xtabsperpix; - double ytabsperpix; - const double * pxprof; - const double * pyprof; - cpl_ifalloc yweightbuf; - double * yweight; - cpl_size ixprolen; - cpl_size iyprolen; - const double * pdeltax; - const double * pdeltay; - const cpl_binary* inbpm; + cpl_mask *bad; + cpl_binary *pbad; + int hasbad; + const double sqxradius = xradius * xradius; + const double sqyradius = yradius * yradius; + double sqyxratio; + double xtabsperpix; + double ytabsperpix; + const double *pxprof; + const double *pyprof; + cpl_ifalloc yweightbuf; + double *yweight; + cpl_size ixprolen; + cpl_size iyprolen; + const double *pdeltax; + const double *pdeltay; + const cpl_binary *inbpm; /* Check entries */ - cpl_ensure_code(out, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(in, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(deltax, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(deltay, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(cpl_image_get_size_x(deltax) == cpl_image_get_size_x(out), - CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(cpl_image_get_size_y(deltax) == cpl_image_get_size_y(out), - CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(cpl_image_get_size_x(deltay) == cpl_image_get_size_x(out), - CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(cpl_image_get_size_y(deltay) == cpl_image_get_size_y(out), - CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(cpl_image_get_type(deltax) == CPL_TYPE_DOUBLE, - CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(cpl_image_get_type(deltay) == CPL_TYPE_DOUBLE, - CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(out, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(in, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(deltax, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(deltay, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(cpl_image_get_size_x(deltax) == cpl_image_get_size_x(out), + CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(cpl_image_get_size_y(deltax) == cpl_image_get_size_y(out), + CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(cpl_image_get_size_x(deltay) == cpl_image_get_size_x(out), + CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(cpl_image_get_size_y(deltay) == cpl_image_get_size_y(out), + CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(cpl_image_get_type(deltax) == CPL_TYPE_DOUBLE, + CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(cpl_image_get_type(deltay) == CPL_TYPE_DOUBLE, + CPL_ERROR_ILLEGAL_INPUT); ixprolen = cpl_vector_get_size(xprofile); cpl_ensure_code(ixprolen > 0, CPL_ERROR_ILLEGAL_INPUT); @@ -226,14 +244,14 @@ /* Initialise */ bad = NULL; hasbad = 0; - pxprof = cpl_vector_get_data_const(xprofile); - pyprof = cpl_vector_get_data_const(yprofile); + pxprof = cpl_vector_get_data_const(xprofile); + pyprof = cpl_vector_get_data_const(yprofile); sqyxratio = sqyradius / sqxradius; - xtabsperpix = (double)(ixprolen-1)/xradius; - ytabsperpix = (double)(iyprolen-1)/yradius; + xtabsperpix = (double)(ixprolen - 1) / xradius; + ytabsperpix = (double)(iyprolen - 1) / yradius; cpl_ifalloc_set(&yweightbuf, (1 + (size_t)(2.0 * yradius)) * sizeof(*yweight)); - yweight = (double*)cpl_ifalloc_get(&yweightbuf); + yweight = (double *)cpl_ifalloc_get(&yweightbuf); /* Access the offsets */ pdeltax = cpl_image_get_data_double_const(deltax); @@ -255,14 +273,14 @@ #define CPL_CLASS CPL_CLASS_INT #include "cpl_image_resample_body.h" #undef CPL_CLASS - default: - cpl_error_set_(CPL_ERROR_INVALID_TYPE); - + default: + cpl_error_set_(CPL_ERROR_INVALID_TYPE); } cpl_ifalloc_free(&yweightbuf); /* Handle bad pixels */ - if (hasbad) cpl_image_reject_from_mask(out, bad); + if (hasbad) + cpl_image_reject_from_mask(out, bad); cpl_mask_delete(bad); return CPL_ERROR_NONE; @@ -316,74 +334,74 @@ - CPL_ERROR_INVALID_TYPE if the passed image type is not supported */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_warp_polynomial( - cpl_image * out, - const cpl_image * in, - const cpl_polynomial * poly_x, - const cpl_polynomial * poly_y, - const cpl_vector * xprofile, - double xradius, - const cpl_vector * yprofile, - double yradius) +cpl_error_code +cpl_image_warp_polynomial(cpl_image *out, + const cpl_image *in, + const cpl_polynomial *poly_x, + const cpl_polynomial *poly_y, + const cpl_vector *xprofile, + double xradius, + const cpl_vector *yprofile, + double yradius) { - double x, y; - cpl_vector * val = NULL; - double * pval; - cpl_mask * bad = NULL; - cpl_binary * pbad; + double x, y; + cpl_vector *val = NULL; + double *pval; + cpl_mask *bad = NULL; + cpl_binary *pbad; double value, confidence; - cpl_size i, j; + cpl_size i, j; int hasbad = 0; const double sqxradius = xradius * xradius; const double sqyradius = yradius * yradius; double sqyxratio; - double xtabsperpix; - double ytabsperpix; - const double * pxprof; - const double * pyprof; + double xtabsperpix; + double ytabsperpix; + const double *pxprof; + const double *pyprof; - cpl_ifalloc yweightbuf; - double * yweight; + cpl_ifalloc yweightbuf; + double *yweight; cpl_size ixprolen; cpl_size iyprolen; - const cpl_binary* inbpm; + const cpl_binary *inbpm; /* Check entries */ - cpl_ensure_code(out, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(in, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(poly_x, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(poly_y, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(cpl_polynomial_get_dimension(poly_x) == 2, - CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(cpl_polynomial_get_dimension(poly_y) == 2, - CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(out, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(in, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(poly_x, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(poly_y, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(cpl_polynomial_get_dimension(poly_x) == 2, + CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(cpl_polynomial_get_dimension(poly_y) == 2, + CPL_ERROR_ILLEGAL_INPUT); ixprolen = cpl_vector_get_size(xprofile); - cpl_ensure(ixprolen > 0, cpl_error_get_code(), -3); + cpl_ensure(ixprolen > 0, cpl_error_get_code(), -3); iyprolen = cpl_vector_get_size(yprofile); - cpl_ensure(iyprolen > 0, cpl_error_get_code(), -4); + cpl_ensure(iyprolen > 0, cpl_error_get_code(), -4); - cpl_ensure(xradius > 0, CPL_ERROR_ILLEGAL_INPUT, -5); - cpl_ensure(yradius > 0, CPL_ERROR_ILLEGAL_INPUT, -6); + cpl_ensure(xradius > 0, CPL_ERROR_ILLEGAL_INPUT, -5); + cpl_ensure(yradius > 0, CPL_ERROR_ILLEGAL_INPUT, -6); - pxprof = cpl_vector_get_data_const(xprofile); - pyprof = cpl_vector_get_data_const(yprofile); + pxprof = cpl_vector_get_data_const(xprofile); + pyprof = cpl_vector_get_data_const(yprofile); - sqyxratio = sqyradius/sqxradius; + sqyxratio = sqyradius / sqxradius; - xtabsperpix = (double)(ixprolen-1) / xradius; - ytabsperpix = (double)(iyprolen-1) / yradius; + xtabsperpix = (double)(ixprolen - 1) / xradius; + ytabsperpix = (double)(iyprolen - 1) / yradius; cpl_ifalloc_set(&yweightbuf, (1 + (size_t)(2.0 * yradius)) * sizeof(*yweight)); - yweight = (double*)cpl_ifalloc_get(&yweightbuf); + yweight = (double *)cpl_ifalloc_get(&yweightbuf); val = cpl_vector_new(2); pval = cpl_vector_get_data(val); @@ -403,15 +421,15 @@ #define CPL_CLASS CPL_CLASS_INT #include "cpl_image_resample_body.h" #undef CPL_CLASS - default: - cpl_error_set_(CPL_ERROR_INVALID_TYPE); - + default: + cpl_error_set_(CPL_ERROR_INVALID_TYPE); } cpl_vector_delete(val); cpl_ifalloc_free(&yweightbuf); - if (hasbad) cpl_image_reject_from_mask(out, bad); + if (hasbad) + cpl_image_reject_from_mask(out, bad); cpl_mask_delete(bad); @@ -448,21 +466,22 @@ - CPL_ERROR_INVALID_TYPE if the passed image type is not supported */ /*----------------------------------------------------------------------------*/ -cpl_image *cpl_image_extract_subsample(const cpl_image *image, - cpl_size xstep, - cpl_size ystep) +cpl_image * +cpl_image_extract_subsample(const cpl_image *image, + cpl_size xstep, + cpl_size ystep) { cpl_image *out_im; - cpl_size new_nx, new_ny; - cpl_size i, j; + cpl_size new_nx, new_ny; + cpl_size i, j; cpl_ensure(image != NULL, CPL_ERROR_NULL_INPUT, NULL); cpl_ensure(xstep > 0, CPL_ERROR_ILLEGAL_INPUT, NULL); cpl_ensure(ystep > 0, CPL_ERROR_ILLEGAL_INPUT, NULL); - new_nx = (image->nx - 1)/xstep + 1; - new_ny = (image->ny - 1)/ystep + 1; + new_nx = (image->nx - 1) / xstep + 1; + new_ny = (image->ny - 1) / ystep + 1; switch (image->type) { #define CPL_CLASS CPL_CLASS_DOUBLE @@ -481,7 +500,7 @@ /* Sub sample the bad pixel map too */ - if (image->bpm != NULL) + if (image->bpm != NULL) out_im->bpm = cpl_mask_extract_subsample(image->bpm, xstep, ystep); return out_im; @@ -526,27 +545,28 @@ - CPL_ERROR_INVALID_TYPE if the passed image type is not supported */ /*----------------------------------------------------------------------------*/ -cpl_image *cpl_image_rebin(const cpl_image *image, - cpl_size xstart, - cpl_size ystart, - cpl_size xstep, - cpl_size ystep) +cpl_image * +cpl_image_rebin(const cpl_image *image, + cpl_size xstart, + cpl_size ystart, + cpl_size xstep, + cpl_size ystep) { - cpl_image *out_im; - cpl_size nx, ny; - cpl_size new_nx, new_ny; + cpl_image *out_im; + cpl_size nx, ny; + cpl_size new_nx, new_ny; const cpl_size old_nx = cpl_image_get_size_x(image); - cpl_size i, j; + cpl_size i, j; cpl_ensure(image != NULL, CPL_ERROR_NULL_INPUT, NULL); cpl_ensure(xstart > 0, CPL_ERROR_ILLEGAL_INPUT, NULL); cpl_ensure(ystart > 0, CPL_ERROR_ILLEGAL_INPUT, NULL); - cpl_ensure(xstep > 0, CPL_ERROR_ILLEGAL_INPUT, NULL); - cpl_ensure(ystep > 0, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(xstep > 0, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(ystep > 0, CPL_ERROR_ILLEGAL_INPUT, NULL); - new_nx = (image->nx - xstart + 1)/xstep; - new_ny = (image->ny - ystart + 1)/ystep; + new_nx = (image->nx - xstart + 1) / xstep; + new_ny = (image->ny - ystart + 1) / ystep; cpl_ensure(new_nx > 0, CPL_ERROR_ILLEGAL_INPUT, NULL); cpl_ensure(new_ny > 0, CPL_ERROR_ILLEGAL_INPUT, NULL); @@ -574,8 +594,8 @@ if (image->bpm != NULL) { const cpl_binary *pin; - cpl_binary *pout; - cpl_size pos; + cpl_binary *pout; + cpl_size pos; out_im->bpm = cpl_mask_new(new_nx, new_ny); pin = cpl_mask_get_data_const(image->bpm); @@ -583,9 +603,10 @@ for (j = ystart - 1; j < ny; j++) { for (i = xstart - 1; i < nx; i++) { - pos = (i-xstart+1)/xstep + ((j-ystart+1)/ystep)*new_nx; + pos = (i - xstart + 1) / xstep + + ((j - ystart + 1) / ystep) * new_nx; if (pout[pos] == CPL_BINARY_0) - pout[pos] = pin[i + j*nx]; + pout[pos] = pin[i + j * nx]; } } } @@ -673,19 +694,19 @@ - CPL_ERROR_INVALID_TYPE if the passed image type is not supported */ /*----------------------------------------------------------------------------*/ -double cpl_image_get_interpolated(const cpl_image * source, - double xpos, - double ypos, - const cpl_vector * xprofile, - double xradius, - const cpl_vector * yprofile, - double yradius, - double * pconfid) +double +cpl_image_get_interpolated(const cpl_image *source, + double xpos, + double ypos, + const cpl_vector *xprofile, + double xradius, + const cpl_vector *yprofile, + double yradius, + double *pconfid) { - - const double * pxprof = cpl_vector_get_data_const(xprofile); - const double * pyprof = cpl_vector_get_data_const(yprofile); + const double *pxprof = cpl_vector_get_data_const(xprofile); + const double *pyprof = cpl_vector_get_data_const(yprofile); const double sqxradius = xradius * xradius; const double sqyradius = yradius * yradius; @@ -693,85 +714,68 @@ double xtabsperpix, ytabsperpix; - const cpl_size nx = cpl_image_get_size_x(source); - const cpl_size ny = cpl_image_get_size_y(source); + const cpl_size nx = cpl_image_get_size_x(source); + const cpl_size ny = cpl_image_get_size_y(source); const cpl_size ixprolen = cpl_vector_get_size(xprofile); const cpl_size iyprolen = cpl_vector_get_size(yprofile); /* Use the stack except for ridiculously large radii that would use too much. A negative Y radius is cast to a very large number */ - const size_t ywsize = 1 + (size_t)(2.0 * yradius); - cpl_ifalloc yweightbuf; - double * yweight; + const size_t ywsize = 1 + (size_t)(2.0 * yradius); + cpl_ifalloc yweightbuf; + double *yweight; double value; - cpl_ensure(pconfid !=NULL, CPL_ERROR_NULL_INPUT, -1); + cpl_ensure(pconfid != NULL, CPL_ERROR_NULL_INPUT, -1); *pconfid = -1; - cpl_ensure(nx > 0, cpl_error_get_code(), -2); - cpl_ensure(ixprolen > 0, cpl_error_get_code(), -3); - cpl_ensure(iyprolen > 0, cpl_error_get_code(), -4); + cpl_ensure(nx > 0, cpl_error_get_code(), -2); + cpl_ensure(ixprolen > 0, cpl_error_get_code(), -3); + cpl_ensure(iyprolen > 0, cpl_error_get_code(), -4); - cpl_ensure(xradius > 0, CPL_ERROR_ILLEGAL_INPUT, -5); - cpl_ensure(yradius > 0, CPL_ERROR_ILLEGAL_INPUT, -6); + cpl_ensure(xradius > 0, CPL_ERROR_ILLEGAL_INPUT, -5); + cpl_ensure(yradius > 0, CPL_ERROR_ILLEGAL_INPUT, -6); - xtabsperpix = (double)(ixprolen-1) / xradius; - ytabsperpix = (double)(iyprolen-1) / yradius; + xtabsperpix = (double)(ixprolen - 1) / xradius; + ytabsperpix = (double)(iyprolen - 1) / yradius; - sqyxratio = sqyradius/sqxradius; + sqyxratio = sqyradius / sqxradius; cpl_ifalloc_set(&yweightbuf, ywsize * sizeof(*yweight)); - yweight = (double*)cpl_ifalloc_get(&yweightbuf); + yweight = (double *)cpl_ifalloc_get(&yweightbuf); switch (source->type) { - case CPL_TYPE_DOUBLE: - value = cpl_image_get_interpolated_double - ((const double*)source->pixels, - source->bpm ? cpl_mask_get_data_const(source->bpm) : NULL, - nx, ny, - xtabsperpix, ytabsperpix, - xpos, ypos, yweight, - pxprof, xradius, - pyprof, yradius, - sqyradius, sqyxratio, - pconfid); - break; - case CPL_TYPE_FLOAT: - - value = cpl_image_get_interpolated_float - ((const float*)source->pixels, - source->bpm ? cpl_mask_get_data_const(source->bpm) : NULL, - nx, ny, - xtabsperpix, ytabsperpix, - xpos, ypos, yweight, - pxprof, xradius, - pyprof, yradius, - sqyradius, sqyxratio, - pconfid); - break; - case CPL_TYPE_INT: - - value = cpl_image_get_interpolated_int - ((const int*)source->pixels, - source->bpm ? cpl_mask_get_data_const(source->bpm) : NULL, - nx, ny, - xtabsperpix, ytabsperpix, - xpos, ypos, yweight, - pxprof, xradius, - pyprof, yradius, - sqyradius, sqyxratio, - pconfid); - break; - - default: - value = 0; - cpl_error_set_(CPL_ERROR_INVALID_TYPE); + case CPL_TYPE_DOUBLE: + value = cpl_image_get_interpolated_double( + (const double *)source->pixels, + source->bpm ? cpl_mask_get_data_const(source->bpm) : NULL, nx, + ny, xtabsperpix, ytabsperpix, xpos, ypos, yweight, pxprof, + xradius, pyprof, yradius, sqyradius, sqyxratio, pconfid); + break; + case CPL_TYPE_FLOAT: + + value = cpl_image_get_interpolated_float( + (const float *)source->pixels, + source->bpm ? cpl_mask_get_data_const(source->bpm) : NULL, nx, + ny, xtabsperpix, ytabsperpix, xpos, ypos, yweight, pxprof, + xradius, pyprof, yradius, sqyradius, sqyxratio, pconfid); + break; + case CPL_TYPE_INT: + + value = cpl_image_get_interpolated_int( + (const int *)source->pixels, + source->bpm ? cpl_mask_get_data_const(source->bpm) : NULL, nx, + ny, xtabsperpix, ytabsperpix, xpos, ypos, yweight, pxprof, + xradius, pyprof, yradius, sqyradius, sqyxratio, pconfid); + break; + default: + value = 0; + cpl_error_set_(CPL_ERROR_INVALID_TYPE); } cpl_ifalloc_free(&yweightbuf); return value; - } @@ -826,23 +830,24 @@ * - CPL_ERROR_INVALID_TYPE if the passed image type is not supported */ -cpl_error_code cpl_image_fill_jacobian_polynomial(cpl_image *out, - const cpl_polynomial *poly_x, - const cpl_polynomial *poly_y) +cpl_error_code +cpl_image_fill_jacobian_polynomial(cpl_image *out, + const cpl_polynomial *poly_x, + const cpl_polynomial *poly_y) { cpl_polynomial *dxdu; cpl_polynomial *dxdv; cpl_polynomial *dydu; cpl_polynomial *dydv; - cpl_vector *val; - double *pval; + cpl_vector *val; + double *pval; - double *ddata; - float *fdata; + double *ddata; + float *fdata; - cpl_size nx, ny; - cpl_size i, j; + cpl_size nx, ny; + cpl_size i, j; cpl_error_code error = CPL_ERROR_NONE; @@ -885,36 +890,36 @@ pval = cpl_vector_get_data(val); switch (cpl_image_get_type(out)) { - case CPL_TYPE_FLOAT: - fdata = cpl_image_get_data_float(out); - for (j=0; j < ny; j++) { - pval[1] = (double)(j + 1); - for (i=0; i < nx; i++) { - pval[0] = (double)(i + 1); - *fdata++ = (float)(cpl_polynomial_eval(dxdu, val) - * cpl_polynomial_eval(dydv, val) - - cpl_polynomial_eval(dxdv, val) - * cpl_polynomial_eval(dydu, val)); + case CPL_TYPE_FLOAT: + fdata = cpl_image_get_data_float(out); + for (j = 0; j < ny; j++) { + pval[1] = (double)(j + 1); + for (i = 0; i < nx; i++) { + pval[0] = (double)(i + 1); + *fdata++ = (float)(cpl_polynomial_eval(dxdu, val) * + cpl_polynomial_eval(dydv, val) - + cpl_polynomial_eval(dxdv, val) * + cpl_polynomial_eval(dydu, val)); + } } - } - break; - case CPL_TYPE_DOUBLE: - ddata = cpl_image_get_data_double(out); - for (j=0; j < ny; j++) { - pval[1] = (double)(j + 1); - for (i=0; i < nx; i++) { - pval[0] = (double)(i + 1); - *ddata++ = cpl_polynomial_eval(dxdu, val) - * cpl_polynomial_eval(dydv, val) - - cpl_polynomial_eval(dxdv, val) - * cpl_polynomial_eval(dydu, val); + break; + case CPL_TYPE_DOUBLE: + ddata = cpl_image_get_data_double(out); + for (j = 0; j < ny; j++) { + pval[1] = (double)(j + 1); + for (i = 0; i < nx; i++) { + pval[0] = (double)(i + 1); + *ddata++ = cpl_polynomial_eval(dxdu, val) * + cpl_polynomial_eval(dydv, val) - + cpl_polynomial_eval(dxdv, val) * + cpl_polynomial_eval(dydu, val); + } } - } - break; - default: - /* It is an error in CPL to reach this point */ - error = CPL_ERROR_UNSPECIFIED; - break; + break; + default: + /* It is an error in CPL to reach this point */ + error = CPL_ERROR_UNSPECIFIED; + break; } cpl_vector_delete(val); @@ -928,7 +933,8 @@ * Ensure the scale factor is positive... */ - if (!error) error = cpl_image_abs(out); + if (!error) + error = cpl_image_abs(out); /* Propagate error, if any */ return cpl_error_set_(error); @@ -1002,27 +1008,28 @@ * - CPL_ERROR_INVALID_TYPE if the passed image type is not supported */ -cpl_error_code cpl_image_fill_jacobian(cpl_image *out, - const cpl_image *deltax, - const cpl_image *deltay) +cpl_error_code +cpl_image_fill_jacobian(cpl_image *out, + const cpl_image *deltax, + const cpl_image *deltay) { - cpl_image *dxdu; - cpl_image *dxdv; - cpl_image *dydu; - cpl_image *dydv; - - double *d_dxdu; - double *d_dxdv; - double *d_dydu; - double *d_dydv; + cpl_image *dxdu; + cpl_image *dxdv; + cpl_image *dydu; + cpl_image *dydv; + + double *d_dxdu; + double *d_dxdv; + double *d_dydu; + double *d_dydv; const double *ddeltax; const double *ddeltay; - double *ddata; - float *fdata; + double *ddata; + float *fdata; - cpl_size nx, ny, npix; - cpl_size i, j, pos; + cpl_size nx, ny, npix; + cpl_size i, j, pos; cpl_error_code error = CPL_ERROR_NONE; @@ -1039,7 +1046,7 @@ nx = cpl_image_get_size_x(out); ny = cpl_image_get_size_y(out); - + if (nx != cpl_image_get_size_x(deltax) || nx != cpl_image_get_size_x(deltay) || ny != cpl_image_get_size_y(deltax) || @@ -1057,10 +1064,10 @@ dydu = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE); dydv = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE); - d_dxdu = cpl_image_get_data_double(dxdu); - d_dxdv = cpl_image_get_data_double(dxdv); - d_dydu = cpl_image_get_data_double(dydu); - d_dydv = cpl_image_get_data_double(dydv); + d_dxdu = cpl_image_get_data_double(dxdu); + d_dxdv = cpl_image_get_data_double(dxdv); + d_dydu = cpl_image_get_data_double(dydu); + d_dydv = cpl_image_get_data_double(dydv); ddeltax = cpl_image_get_data_double_const(deltax); ddeltay = cpl_image_get_data_double_const(deltay); @@ -1073,10 +1080,10 @@ pos = j * nx; for (i = 1; i < nx - 1; i++) { pos++; - d_dxdu[pos] = (ddeltax[pos-1] - ddeltax[pos+1]) / 2 + 1; - d_dxdv[pos] = (ddeltax[pos-nx] - ddeltax[pos+nx]) / 2; - d_dydu[pos] = (ddeltay[pos-1] - ddeltay[pos+1]) / 2; - d_dydv[pos] = (ddeltay[pos-nx] - ddeltay[pos+nx]) / 2 + 1; + d_dxdu[pos] = (ddeltax[pos - 1] - ddeltax[pos + 1]) / 2 + 1; + d_dxdv[pos] = (ddeltax[pos - nx] - ddeltax[pos + nx]) / 2; + d_dydu[pos] = (ddeltay[pos - 1] - ddeltay[pos + 1]) / 2; + d_dydv[pos] = (ddeltay[pos - nx] - ddeltay[pos + nx]) / 2 + 1; } } @@ -1089,24 +1096,25 @@ npix = nx * ny; switch (cpl_image_get_type(out)) { - case CPL_TYPE_FLOAT: - fdata = cpl_image_get_data_float(out); - for (i = 0; i < npix; i++) { - *fdata++ = (float)((*d_dxdu++) * (*d_dydv++) - - (*d_dxdv++) * (*d_dydu++)); - } - break; - case CPL_TYPE_DOUBLE: - ddata = cpl_image_get_data_double(out); - for (i = 0; i < npix; i++) { - *ddata++ = (*d_dxdu++) * (*d_dydv++) - (*d_dxdv++) * (*d_dydu++); - } - break; - default: + case CPL_TYPE_FLOAT: + fdata = cpl_image_get_data_float(out); + for (i = 0; i < npix; i++) { + *fdata++ = (float)((*d_dxdu++) * (*d_dydv++) - + (*d_dxdv++) * (*d_dydu++)); + } + break; + case CPL_TYPE_DOUBLE: + ddata = cpl_image_get_data_double(out); + for (i = 0; i < npix; i++) { + *ddata++ = + (*d_dxdu++) * (*d_dydv++) - (*d_dxdv++) * (*d_dydu++); + } + break; + default: - /* It is an error in CPL to reach this point */ - error = CPL_ERROR_UNSPECIFIED; - break; + /* It is an error in CPL to reach this point */ + error = CPL_ERROR_UNSPECIFIED; + break; } cpl_image_delete(dxdu); @@ -1119,11 +1127,11 @@ * Ensure the scale factor is positive... */ - if (!error) error = cpl_image_abs(out); + if (!error) + error = cpl_image_abs(out); /* Propagate error, if any */ return cpl_error_set_(error); - } /**@}*/ @@ -1142,5 +1150,3 @@ #undef CPL_OPERATION #include "cpl_image_resample_body.h" #undef CPL_CLASS - - diff -Nru cpl-7.1.4+ds/cplcore/cpl_image_resample.h cpl-7.2.2+ds/cplcore/cpl_image_resample.h --- cpl-7.1.4+ds/cplcore/cpl_image_resample.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_image_resample.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -39,17 +39,23 @@ CPL_BEGIN_DECLS -cpl_error_code cpl_image_warp_polynomial(cpl_image *, const cpl_image *, +cpl_error_code cpl_image_warp_polynomial(cpl_image *, + const cpl_image *, const cpl_polynomial *, const cpl_polynomial *, - const cpl_vector *, double, - const cpl_vector *, double); + const cpl_vector *, + double, + const cpl_vector *, + double); -cpl_error_code cpl_image_warp(cpl_image *, const cpl_image *, +cpl_error_code cpl_image_warp(cpl_image *, const cpl_image *, const cpl_image *, - const cpl_vector *, double, - const cpl_vector *, double); + const cpl_image *, + const cpl_vector *, + double, + const cpl_vector *, + double); cpl_error_code cpl_image_fill_jacobian_polynomial(cpl_image *, const cpl_polynomial *poly_x, @@ -60,16 +66,22 @@ const cpl_image *deltay); cpl_image *cpl_image_extract_subsample(const cpl_image *, - cpl_size, cpl_size) CPL_ATTR_ALLOC; - -cpl_image *cpl_image_rebin(const cpl_image *, cpl_size, cpl_size, - cpl_size, cpl_size) CPL_ATTR_ALLOC; + cpl_size, + cpl_size) CPL_ATTR_ALLOC; -double cpl_image_get_interpolated(const cpl_image *, double, double, - const cpl_vector *, double, - const cpl_vector *, double, double *); +cpl_image * +cpl_image_rebin(const cpl_image *, cpl_size, cpl_size, cpl_size, cpl_size) + CPL_ATTR_ALLOC; + +double cpl_image_get_interpolated(const cpl_image *, + double, + double, + const cpl_vector *, + double, + const cpl_vector *, + double, + double *); CPL_END_DECLS -#endif - +#endif diff -Nru cpl-7.1.4+ds/cplcore/cpl_image_stats_body.h cpl-7.2.2+ds/cplcore/cpl_image_stats_body.h --- cpl-7.1.4+ds/cplcore/cpl_image_stats_body.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_image_stats_body.h 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -19,15 +19,15 @@ /* Type dependent macros */ #if CPL_CLASS == CPL_CLASS_DOUBLE -#define CPL_TYPE double +#define CPL_TYPE double #define CPL_TYPE_T CPL_TYPE_DOUBLE #elif CPL_CLASS == CPL_CLASS_FLOAT -#define CPL_TYPE float +#define CPL_TYPE float #define CPL_TYPE_T CPL_TYPE_FLOAT #elif CPL_CLASS == CPL_CLASS_INT -#define CPL_TYPE int +#define CPL_TYPE int #define CPL_TYPE_T CPL_TYPE_INT #else @@ -39,48 +39,48 @@ #if CPL_OPERATION == CPL_IMAGE_STATS_MEDIAN_STAT - case CPL_TYPE_T: - { - const CPL_TYPE * pi = (const CPL_TYPE*)image->pixels; - int npix = image->nx * image->ny; - int i; +case CPL_TYPE_T: { + const CPL_TYPE *pi = (const CPL_TYPE *)image->pixels; + int npix = image->nx * image->ny; + int i; - *sigma = 0.0; + *sigma = 0.0; - /* Could be done in two FLOPs instead of three + /* Could be done in two FLOPs instead of three * - but this would lead to more complicated code... */ - if (image->bpm != NULL) { - /* Need to check bad pixel buffer */ - const cpl_binary * badmap = cpl_mask_get_data_const(image->bpm); - int nbad = 0; - - for (i = 0; i < npix; i++) { - if (badmap[i]) { - nbad++; - } else { - *sigma += fabs((double)pi[i]-median_val); - } - } - - /* Subtract the number of bad pixels */ - npix -= nbad; - - /* assert( npix > 0 ); */ - - } else { - for (i = 0; i < npix; i++) { - *sigma += fabs((double)pi[i]-median_val); - } - } + if (image->bpm != NULL) { + /* Need to check bad pixel buffer */ + const cpl_binary *badmap = cpl_mask_get_data_const(image->bpm); + int nbad = 0; + + for (i = 0; i < npix; i++) { + if (badmap[i]) { + nbad++; + } + else { + *sigma += fabs((double)pi[i] - median_val); + } + } + + /* Subtract the number of bad pixels */ + npix -= nbad; + + /* assert( npix > 0 ); */ + } + else { + for (i = 0; i < npix; i++) { + *sigma += fabs((double)pi[i] - median_val); + } + } - *sigma /= (double) npix; + *sigma /= (double)npix; - cpl_tools_add_flops( 3 * npix + 1 ); + cpl_tools_add_flops(3 * npix + 1); - break; - } + break; +} #endif diff -Nru cpl-7.1.4+ds/cplcore/cpl_image_stats.c cpl-7.2.2+ds/cplcore/cpl_image_stats.c --- cpl-7.1.4+ds/cplcore/cpl_image_stats.c 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_image_stats.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -49,25 +49,26 @@ @brief Define the body of a stats window function @param op Operation in lower case @param OP Operation in upper case - */ + */ /*----------------------------------------------------------------------------*/ -#define CPL_IMAGE_GET_STATS_WINDOW_DOUBLE_BODY(op, OP) \ - \ - cpl_stats stats; \ - const cpl_error_code icode = \ - cpl_stats_fill_from_image_window(&stats, image, \ - CPL_CONCAT2X(CPL_STATS, OP), \ - llx, lly, urx, ury); \ - double res = 0.0; \ - \ - if (icode) { \ - (void)cpl_error_set_where_(); \ - } else { \ - /* Should not be able to fail now */ \ - res = CPL_CONCAT2X(cpl_stats_get, op)((const cpl_stats *)&stats); \ - } \ - \ - return res +#define CPL_IMAGE_GET_STATS_WINDOW_DOUBLE_BODY(op, OP) \ + \ + cpl_stats stats; \ + const cpl_error_code icode = \ + cpl_stats_fill_from_image_window(&stats, image, \ + CPL_CONCAT2X(CPL_STATS, OP), llx, \ + lly, urx, ury); \ + double res = 0.0; \ + \ + if (icode) { \ + (void)cpl_error_set_where_(); \ + } \ + else { \ + /* Should not be able to fail now */ \ + res = CPL_CONCAT2X(cpl_stats_get, op)((const cpl_stats *)&stats); \ + } \ + \ + return res /*----------------------------------------------------------------------------*/ /** @@ -76,25 +77,26 @@ @brief Define the body of a stats function @param op Operation in lower case @param OP Operation in upper case -*/ +*/ /*----------------------------------------------------------------------------*/ -#define CPL_IMAGE_GET_STATS_DOUBLE_BODY(op, OP) \ - \ - cpl_stats stats; \ - const cpl_error_code icode = \ +#define CPL_IMAGE_GET_STATS_DOUBLE_BODY(op, OP) \ + \ + cpl_stats stats; \ + const cpl_error_code icode = \ cpl_stats_fill_from_image(&stats, image, CPL_CONCAT2X(CPL_STATS, OP)); \ - double res = 0.0; \ - \ - \ - if (icode) { \ - (void)cpl_error_set_where_(); \ - } else { \ - /* Should not be able to fail now */ \ - res = CPL_CONCAT2X(cpl_stats_get, op)((const cpl_stats *)&stats); \ - } \ - \ - \ - return res + double res = 0.0; \ + \ + \ + if (icode) { \ + (void)cpl_error_set_where_(); \ + } \ + else { \ + /* Should not be able to fail now */ \ + res = CPL_CONCAT2X(cpl_stats_get, op)((const cpl_stats *)&stats); \ + } \ + \ + \ + return res /*----------------------------------------------------------------------------- Function codes @@ -119,13 +121,14 @@ Possible #_cpl_error_code_ set in this function: - CPL_ERROR_NULL_INPUT if an input pointer is NULL - */ + */ /*----------------------------------------------------------------------------*/ -double cpl_image_get_min_window(const cpl_image * image, - cpl_size llx, - cpl_size lly, - cpl_size urx, - cpl_size ury) +double +cpl_image_get_min_window(const cpl_image *image, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury) { CPL_IMAGE_GET_STATS_WINDOW_DOUBLE_BODY(min, MIN); } @@ -144,9 +147,10 @@ Possible #_cpl_error_code_ set in this function: - CPL_ERROR_NULL_INPUT if an input pointer is NULL - */ + */ /*----------------------------------------------------------------------------*/ -double cpl_image_get_min(const cpl_image * image) +double +cpl_image_get_min(const cpl_image *image) { CPL_IMAGE_GET_STATS_DOUBLE_BODY(min, MIN); } @@ -162,13 +166,14 @@ @param ury Upper right y position (FITS convention) @return the maximum value @see cpl_image_get_min_window() - */ + */ /*----------------------------------------------------------------------------*/ -double cpl_image_get_max_window(const cpl_image * image, - cpl_size llx, - cpl_size lly, - cpl_size urx, - cpl_size ury) +double +cpl_image_get_max_window(const cpl_image *image, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury) { CPL_IMAGE_GET_STATS_WINDOW_DOUBLE_BODY(max, MAX); } @@ -180,9 +185,10 @@ @param image input image. @return the maximum value @see cpl_image_get_min() - */ + */ /*----------------------------------------------------------------------------*/ -double cpl_image_get_max(const cpl_image * image) +double +cpl_image_get_max(const cpl_image *image) { CPL_IMAGE_GET_STATS_DOUBLE_BODY(max, MAX); } @@ -198,14 +204,14 @@ @param ury Upper right y position (FITS convention) @return the mean value @see cpl_image_get_min_window() - */ + */ /*----------------------------------------------------------------------------*/ -double cpl_image_get_mean_window( - const cpl_image * image, - cpl_size llx, - cpl_size lly, - cpl_size urx, - cpl_size ury) +double +cpl_image_get_mean_window(const cpl_image *image, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury) { CPL_IMAGE_GET_STATS_WINDOW_DOUBLE_BODY(mean, MEAN); } @@ -217,9 +223,10 @@ @param image input image. @return the mean value @see cpl_image_get_min() - */ + */ /*----------------------------------------------------------------------------*/ -double cpl_image_get_mean(const cpl_image * image) +double +cpl_image_get_mean(const cpl_image *image) { CPL_IMAGE_GET_STATS_DOUBLE_BODY(mean, MEAN); } @@ -253,13 +260,14 @@ - CPL_ERROR_ILLEGAL_INPUT if the window is outside the image or if there are only bad pixels in the window - CPL_ERROR_INVALID_TYPE if the passed image type is not supported - */ + */ /*----------------------------------------------------------------------------*/ -double cpl_image_get_median_window(const cpl_image * image, - cpl_size llx, - cpl_size lly, - cpl_size urx, - cpl_size ury) +double +cpl_image_get_median_window(const cpl_image *image, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury) { CPL_IMAGE_GET_STATS_WINDOW_DOUBLE_BODY(median, MEDIAN); } @@ -278,9 +286,10 @@ Possible #_cpl_error_code_ set in this function: - CPL_ERROR_NULL_INPUT if an input pointer is NULL - */ + */ /*----------------------------------------------------------------------------*/ -double cpl_image_get_median(const cpl_image * image) +double +cpl_image_get_median(const cpl_image *image) { CPL_IMAGE_GET_STATS_DOUBLE_BODY(median, MEDIAN); } @@ -296,13 +305,14 @@ @param ury Upper right y position (FITS convention) @return the standard deviation value @see cpl_image_get_min_window() - */ + */ /*----------------------------------------------------------------------------*/ -double cpl_image_get_stdev_window(const cpl_image * image, - cpl_size llx, - cpl_size lly, - cpl_size urx, - cpl_size ury) +double +cpl_image_get_stdev_window(const cpl_image *image, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury) { CPL_IMAGE_GET_STATS_WINDOW_DOUBLE_BODY(stdev, STDEV); } @@ -314,9 +324,10 @@ @param image input image. @return the standard deviation value @see cpl_image_get_min() - */ + */ /*----------------------------------------------------------------------------*/ -double cpl_image_get_stdev(const cpl_image * image) +double +cpl_image_get_stdev(const cpl_image *image) { CPL_IMAGE_GET_STATS_DOUBLE_BODY(stdev, STDEV); } @@ -332,13 +343,14 @@ @param ury Upper right y position (FITS convention) @return the flux value @see cpl_image_get_min_window() - */ + */ /*----------------------------------------------------------------------------*/ -double cpl_image_get_flux_window(const cpl_image * image, - cpl_size llx, - cpl_size lly, - cpl_size urx, - cpl_size ury) +double +cpl_image_get_flux_window(const cpl_image *image, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury) { CPL_IMAGE_GET_STATS_WINDOW_DOUBLE_BODY(flux, FLUX); } @@ -350,9 +362,10 @@ @param image input image. @return the flux value @see cpl_image_get_min() - */ + */ /*----------------------------------------------------------------------------*/ -double cpl_image_get_flux(const cpl_image * image) +double +cpl_image_get_flux(const cpl_image *image) { cpl_ensure(image, CPL_ERROR_NULL_INPUT, 0.0); return cpl_image_get_flux_window(image, 1, 1, image->nx, image->ny); @@ -369,13 +382,14 @@ @param ury Upper right y position (FITS convention) @return the absolute flux (sum of |pixels|) value @see cpl_image_get_min_window() - */ + */ /*----------------------------------------------------------------------------*/ -double cpl_image_get_absflux_window(const cpl_image * image, - cpl_size llx, - cpl_size lly, - cpl_size urx, - cpl_size ury) +double +cpl_image_get_absflux_window(const cpl_image *image, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury) { CPL_IMAGE_GET_STATS_WINDOW_DOUBLE_BODY(absflux, ABSFLUX); } @@ -391,14 +405,14 @@ @param ury Upper right y position (FITS convention) @return the square flux @see cpl_image_get_min_window() - */ + */ /*----------------------------------------------------------------------------*/ -double cpl_image_get_sqflux_window( - const cpl_image * image, - cpl_size llx, - cpl_size lly, - cpl_size urx, - cpl_size ury) +double +cpl_image_get_sqflux_window(const cpl_image *image, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury) { CPL_IMAGE_GET_STATS_WINDOW_DOUBLE_BODY(sqflux, SQFLUX); } @@ -410,9 +424,10 @@ @param image input image. @return the absolute flux (sum of |pixels|) value @see cpl_image_get_min() - */ + */ /*----------------------------------------------------------------------------*/ -double cpl_image_get_absflux(const cpl_image * image) +double +cpl_image_get_absflux(const cpl_image *image) { CPL_IMAGE_GET_STATS_DOUBLE_BODY(absflux, ABSFLUX); } @@ -424,9 +439,10 @@ @param image input image. @return the sqaure flux @see cpl_image_get_min() - */ + */ /*----------------------------------------------------------------------------*/ -double cpl_image_get_sqflux(const cpl_image * image) +double +cpl_image_get_sqflux(const cpl_image *image) { CPL_IMAGE_GET_STATS_DOUBLE_BODY(sqflux, SQFLUX); } @@ -438,9 +454,10 @@ @param image input image. @return the x centroid value @see cpl_image_get_min_window() - */ + */ /*----------------------------------------------------------------------------*/ -double cpl_image_get_centroid_x(const cpl_image * image) +double +cpl_image_get_centroid_x(const cpl_image *image) { CPL_IMAGE_GET_STATS_DOUBLE_BODY(centroid_x, CENTROID); } @@ -456,13 +473,14 @@ @param ury Upper right y position (FITS convention) @return the x centroid value @see cpl_image_get_min_window() - */ + */ /*----------------------------------------------------------------------------*/ -double cpl_image_get_centroid_x_window(const cpl_image * image, - cpl_size llx, - cpl_size lly, - cpl_size urx, - cpl_size ury) +double +cpl_image_get_centroid_x_window(const cpl_image *image, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury) { CPL_IMAGE_GET_STATS_WINDOW_DOUBLE_BODY(centroid_x, CENTROID); } @@ -474,9 +492,10 @@ @param image input image. @return the y centroid value @see cpl_image_get_min_window() - */ + */ /*----------------------------------------------------------------------------*/ -double cpl_image_get_centroid_y(const cpl_image * image) +double +cpl_image_get_centroid_y(const cpl_image *image) { CPL_IMAGE_GET_STATS_DOUBLE_BODY(centroid_y, CENTROID); } @@ -492,13 +511,14 @@ @param ury Upper right y position (FITS convention) @return the y centroid value @see cpl_image_get_min_window() - */ + */ /*----------------------------------------------------------------------------*/ -double cpl_image_get_centroid_y_window(const cpl_image * image, - cpl_size llx, - cpl_size lly, - cpl_size urx, - cpl_size ury) +double +cpl_image_get_centroid_y_window(const cpl_image *image, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury) { CPL_IMAGE_GET_STATS_WINDOW_DOUBLE_BODY(centroid_y, CENTROID); } @@ -525,24 +545,25 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_get_minpos_window(const cpl_image * image, - cpl_size llx, - cpl_size lly, - cpl_size urx, - cpl_size ury, - cpl_size * px, - cpl_size * py) +cpl_error_code +cpl_image_get_minpos_window(const cpl_image *image, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury, + cpl_size *px, + cpl_size *py) { cpl_stats stats; cpl_ensure_code(px != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(py != NULL, CPL_ERROR_NULL_INPUT); - if (cpl_stats_fill_from_image_window(&stats, image, CPL_STATS_MINPOS, - llx, lly, urx, ury)) { + if (cpl_stats_fill_from_image_window(&stats, image, CPL_STATS_MINPOS, llx, + lly, urx, ury)) { return cpl_error_set_where_(); } - + /* Should not be able to fail now */ *px = cpl_stats_get_min_x(&stats); @@ -567,11 +588,9 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_get_minpos(const cpl_image * image, - cpl_size * px, - cpl_size * py) +cpl_error_code +cpl_image_get_minpos(const cpl_image *image, cpl_size *px, cpl_size *py) { - cpl_stats stats; cpl_ensure_code(px != NULL, CPL_ERROR_NULL_INPUT); @@ -580,14 +599,13 @@ if (cpl_stats_fill_from_image(&stats, image, CPL_STATS_MINPOS)) { return cpl_error_set_where_(); } - + /* Should not be able to fail now */ *px = cpl_stats_get_min_x(&stats); *py = cpl_stats_get_min_y(&stats); return CPL_ERROR_NONE; - } /*----------------------------------------------------------------------------*/ @@ -605,24 +623,25 @@ @see cpl_image_get_minpos_window() */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_get_maxpos_window(const cpl_image * image, - cpl_size llx, - cpl_size lly, - cpl_size urx, - cpl_size ury, - cpl_size * px, - cpl_size * py) +cpl_error_code +cpl_image_get_maxpos_window(const cpl_image *image, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury, + cpl_size *px, + cpl_size *py) { cpl_stats stats; cpl_ensure_code(px != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(py != NULL, CPL_ERROR_NULL_INPUT); - if (cpl_stats_fill_from_image_window(&stats, image, CPL_STATS_MAXPOS, - llx, lly, urx, ury)) { + if (cpl_stats_fill_from_image_window(&stats, image, CPL_STATS_MAXPOS, llx, + lly, urx, ury)) { return cpl_error_set_where_(); } - + /* Should not be able to fail now */ *px = cpl_stats_get_max_x(&stats); @@ -642,9 +661,8 @@ @see cpl_image_get_minpos() */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_image_get_maxpos(const cpl_image * image, - cpl_size * px, - cpl_size * py) +cpl_error_code +cpl_image_get_maxpos(const cpl_image *image, cpl_size *px, cpl_size *py) { cpl_stats stats; @@ -654,7 +672,7 @@ if (cpl_stats_fill_from_image(&stats, image, CPL_STATS_MAXPOS)) { return cpl_error_set_where_(); } - + /* Should not be able to fail now */ *px = cpl_stats_get_max_x(&stats); @@ -694,12 +712,13 @@ - CPL_ERROR_DATA_NOT_FOUND if all the pixels are bad in the image window */ /*----------------------------------------------------------------------------*/ -double cpl_image_get_median_dev_window(const cpl_image * image, - cpl_size llx, - cpl_size lly, - cpl_size urx, - cpl_size ury, - double * sigma) +double +cpl_image_get_median_dev_window(const cpl_image *image, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury, + double *sigma) { cpl_stats stats; double median; @@ -708,10 +727,10 @@ cpl_ensure_code(sigma != NULL, CPL_ERROR_NULL_INPUT); if (cpl_stats_fill_from_image_window(&stats, image, CPL_STATS_MEDIAN_DEV, - llx, lly, urx, ury)) { + llx, lly, urx, ury)) { return cpl_error_set_where_(); } - + /* Should not be able to fail now */ median = cpl_stats_get_median(&stats); @@ -735,8 +754,8 @@ - CPL_ERROR_DATA_NOT_FOUND if all the pixels are bad in the image */ /*----------------------------------------------------------------------------*/ -double cpl_image_get_median_dev(const cpl_image * image, - double * sigma) +double +cpl_image_get_median_dev(const cpl_image *image, double *sigma) { cpl_stats stats; double median; @@ -747,7 +766,7 @@ if (cpl_stats_fill_from_image(&stats, image, CPL_STATS_MEDIAN_DEV)) { return cpl_error_set_where_(); } - + /* Should not be able to fail now */ median = cpl_stats_get_median(&stats); @@ -789,12 +808,13 @@ - CPL_ERROR_DATA_NOT_FOUND if all the pixels are bad in the image window */ /*----------------------------------------------------------------------------*/ -double cpl_image_get_mad_window(const cpl_image * image, - cpl_size llx, - cpl_size lly, - cpl_size urx, - cpl_size ury, - double * sigma) +double +cpl_image_get_mad_window(const cpl_image *image, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury, + double *sigma) { cpl_stats stats; double median; @@ -802,11 +822,11 @@ cpl_ensure_code(sigma != NULL, CPL_ERROR_NULL_INPUT); - if (cpl_stats_fill_from_image_window(&stats, image, CPL_STATS_MAD, - llx, lly, urx, ury)) { + if (cpl_stats_fill_from_image_window(&stats, image, CPL_STATS_MAD, llx, lly, + urx, ury)) { return cpl_error_set_where_(); } - + /* Should not be able to fail now */ median = cpl_stats_get_median(&stats); @@ -830,8 +850,8 @@ - CPL_ERROR_DATA_NOT_FOUND if all the pixels are bad in the image */ /*----------------------------------------------------------------------------*/ -double cpl_image_get_mad(const cpl_image * image, - double * sigma) +double +cpl_image_get_mad(const cpl_image *image, double *sigma) { cpl_stats stats; double median; @@ -842,7 +862,7 @@ if (cpl_stats_fill_from_image(&stats, image, CPL_STATS_MAD)) { return cpl_error_set_where_(); } - + /* Should not be able to fail now */ median = cpl_stats_get_median(&stats); @@ -850,4 +870,3 @@ return median; } - diff -Nru cpl-7.1.4+ds/cplcore/cpl_image_stats.h cpl-7.2.2+ds/cplcore/cpl_image_stats.h --- cpl-7.1.4+ds/cplcore/cpl_image_stats.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_image_stats.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -33,62 +33,108 @@ -----------------------------------------------------------------------------*/ double cpl_image_get_min(const cpl_image *); -double cpl_image_get_min_window(const cpl_image *, cpl_size, cpl_size, - cpl_size, cpl_size); +double cpl_image_get_min_window(const cpl_image *, + cpl_size, + cpl_size, + cpl_size, + cpl_size); double cpl_image_get_max(const cpl_image *); -double cpl_image_get_max_window(const cpl_image *, cpl_size, cpl_size, - cpl_size, cpl_size); +double cpl_image_get_max_window(const cpl_image *, + cpl_size, + cpl_size, + cpl_size, + cpl_size); double cpl_image_get_mean(const cpl_image *); -double cpl_image_get_mean_window(const cpl_image *, cpl_size, cpl_size, - cpl_size, cpl_size); +double cpl_image_get_mean_window(const cpl_image *, + cpl_size, + cpl_size, + cpl_size, + cpl_size); double cpl_image_get_median(const cpl_image *); -double cpl_image_get_median_window(const cpl_image *, cpl_size, cpl_size, - cpl_size, cpl_size); +double cpl_image_get_median_window(const cpl_image *, + cpl_size, + cpl_size, + cpl_size, + cpl_size); double cpl_image_get_stdev(const cpl_image *); -double cpl_image_get_stdev_window(const cpl_image *, cpl_size, cpl_size, - cpl_size, cpl_size); +double cpl_image_get_stdev_window(const cpl_image *, + cpl_size, + cpl_size, + cpl_size, + cpl_size); double cpl_image_get_flux(const cpl_image *); -double cpl_image_get_flux_window(const cpl_image *, cpl_size, cpl_size, - cpl_size, cpl_size); +double cpl_image_get_flux_window(const cpl_image *, + cpl_size, + cpl_size, + cpl_size, + cpl_size); double cpl_image_get_absflux(const cpl_image *); -double cpl_image_get_absflux_window(const cpl_image *, cpl_size, cpl_size, - cpl_size, cpl_size); +double cpl_image_get_absflux_window(const cpl_image *, + cpl_size, + cpl_size, + cpl_size, + cpl_size); double cpl_image_get_sqflux(const cpl_image *); -double cpl_image_get_sqflux_window(const cpl_image *, cpl_size, cpl_size, - cpl_size, cpl_size); +double cpl_image_get_sqflux_window(const cpl_image *, + cpl_size, + cpl_size, + cpl_size, + cpl_size); double cpl_image_get_centroid_x(const cpl_image *); -double cpl_image_get_centroid_x_window(const cpl_image *, cpl_size, cpl_size, - cpl_size, cpl_size); +double cpl_image_get_centroid_x_window(const cpl_image *, + cpl_size, + cpl_size, + cpl_size, + cpl_size); double cpl_image_get_centroid_y(const cpl_image *); -double cpl_image_get_centroid_y_window(const cpl_image *, cpl_size, cpl_size, - cpl_size, cpl_size); +double cpl_image_get_centroid_y_window(const cpl_image *, + cpl_size, + cpl_size, + cpl_size, + cpl_size); cpl_error_code cpl_image_get_minpos(const cpl_image *, cpl_size *, cpl_size *); -cpl_error_code cpl_image_get_minpos_window(const cpl_image *, cpl_size, - cpl_size, cpl_size, cpl_size, - cpl_size *, cpl_size *); +cpl_error_code cpl_image_get_minpos_window(const cpl_image *, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_size *, + cpl_size *); cpl_error_code cpl_image_get_maxpos(const cpl_image *, cpl_size *, cpl_size *); -cpl_error_code cpl_image_get_maxpos_window(const cpl_image *, cpl_size, - cpl_size, cpl_size, cpl_size, - cpl_size *, cpl_size *); +cpl_error_code cpl_image_get_maxpos_window(const cpl_image *, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_size *, + cpl_size *); double cpl_image_get_median_dev(const cpl_image *, double *); -double cpl_image_get_median_dev_window(const cpl_image *, cpl_size, cpl_size, - cpl_size, cpl_size, double *); +double cpl_image_get_median_dev_window(const cpl_image *, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + double *); double cpl_image_get_mad(const cpl_image *, double *); -double cpl_image_get_mad_window(const cpl_image *, cpl_size, cpl_size, - cpl_size, cpl_size, double *); +double cpl_image_get_mad_window(const cpl_image *, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + double *); CPL_END_DECLS -#endif +#endif diff -Nru cpl-7.1.4+ds/cplcore/cpl_init.c cpl-7.2.2+ds/cplcore/cpl_init.c --- cpl-7.1.4+ds/cplcore/cpl_init.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_init.c 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -39,21 +39,21 @@ /* strcmp() */ #include -#ifdef CPL_WCS_INSTALLED /* If WCS is installed */ +#ifdef CPL_WCS_INSTALLED /* If WCS is installed */ /* Get WCSLIB version number */ #include -#endif /* End If WCS is installed */ +#endif /* End If WCS is installed */ #if defined CPL_FFTWF_INSTALLED || defined CPL_FFTW_INSTALLED #include #endif #if !defined(CFITSIO_MAJOR) || !defined(CFITSIO_MINOR) -# error "CFITSIO major and/or minor version are not set!" +#error "CFITSIO major and/or minor version are not set!" #else -# if (CFITSIO_MAJOR < 3) || ((CFITSIO_MAJOR == 3) && (CFITSIO_MINOR < 35)) -# error "CFITSIO version is not supported (too old)!" -# endif +#if (CFITSIO_MAJOR < 3) || ((CFITSIO_MAJOR == 3) && (CFITSIO_MINOR < 35)) +#error "CFITSIO version is not supported (too old)!" +#endif #endif @@ -114,20 +114,21 @@ void cpl_init(unsigned self) { - int memory_mode = CPL_XMEMORY_MODE; /* Default from configure */ - const char * memory_mode_string = getenv("CPL_MEMORY_MODE"); - const char * io_fits_mode_string = getenv("CPL_IO_MODE"); - const cpl_boolean use_io_fits = io_fits_mode_string != NULL && - strcmp("1", io_fits_mode_string) == 0; + const char *memory_mode_string = getenv("CPL_MEMORY_MODE"); + const char *io_fits_mode_string = getenv("CPL_IO_MODE"); + const cpl_boolean use_io_fits = + io_fits_mode_string != NULL && strcmp("1", io_fits_mode_string) == 0; if (memory_mode_string != NULL) { if (strcmp("0", memory_mode_string) == 0) { memory_mode = 0; - } else if (strcmp("1", memory_mode_string) == 0) { + } + else if (strcmp("1", memory_mode_string) == 0) { memory_mode = 1; - } else if (strcmp("2", memory_mode_string) == 0) { + } + else if (strcmp("2", memory_mode_string) == 0) { memory_mode = 2; } /* else: Ignore the environment variable */ } @@ -141,16 +142,17 @@ } float _cfitsio_version; - const int cfitsio_version_min = (int)(1000. * CPL_CFITSIO_VERSION + 0.5); - const int cfitsio_version = (int)(1000. * - fits_get_version(&_cfitsio_version) + 0.5); + const int cfitsio_version_min = + (int)(100. * CPL_CFITSIO_MAJOR + CPL_CFITSIO_MINOR); + const int cfitsio_version = + (int)(100. * fits_get_version(&_cfitsio_version)); if (cfitsio_version < cfitsio_version_min) { (void)cpl_error_set_message_(CPL_ERROR_INCOMPATIBLE_INPUT, "Run-time version %.3f of CFITSIO " "is not supported. Minimum required " - "version is %.3f", _cfitsio_version, - CPL_CFITSIO_VERSION); + "version is %.3f", + _cfitsio_version, CPL_CFITSIO_VERSION); } #ifdef HAVE_LIBPTHREAD @@ -165,8 +167,6 @@ } - - /*----------------------------------------------------------------------------*/ /** @brief Create a string of version numbers of CPL and its libraries @@ -174,9 +174,9 @@ @return A pointer to a constant character array */ /*----------------------------------------------------------------------------*/ -const char * cpl_get_description(unsigned self) +const char * +cpl_get_description(unsigned self) { - /* At a later stage decription_mode may be used to select what version information to return, e.g. CPL only, 3rd party libraries only, or both */ @@ -193,8 +193,9 @@ #if defined CPL_FFTW_INSTALLED && defined CPL_FFTWF_INSTALLED #if defined CPL_FFTW_VERSION && defined CPL_FFTWF_VERSION -#define CPL_FFTW_APPEND ", FFTW (normal precision) = " CPL_FFTW_VERSION \ - ", FFTW (single precision) = " CPL_FFTWF_VERSION +#define CPL_FFTW_APPEND \ + ", FFTW (normal precision) = " CPL_FFTW_VERSION \ + ", FFTW (single precision) = " CPL_FFTWF_VERSION #else #define CPL_FFTW_APPEND ", FFTW (normal and single precision)" #endif @@ -215,10 +216,9 @@ #endif #ifdef CPL_ADD_FLOPS -#define CPL_FLOPS_APPEND \ - ", CPL FLOP counting is available" +#define CPL_FLOPS_APPEND ", CPL FLOP counting is available" #else -#define CPL_FLOPS_APPEND \ +#define CPL_FLOPS_APPEND \ ", CPL FLOP counting is unavailable, enable with -DCPL_ADD_FLOPS" #endif @@ -229,8 +229,8 @@ #endif #ifdef CPL_IO_FITS_MAX_OPEN -#define CPL_IO_FITS_APPEND ", CPL_IO_FITS_OPEN = " \ - CPL_STRINGIFY(CPL_IO_FITS_MAX_OPEN) +#define CPL_IO_FITS_APPEND \ + ", CPL_IO_FITS_OPEN = " CPL_STRINGIFY(CPL_IO_FITS_MAX_OPEN) #else #define CPL_IO_FITS_APPEND "" #endif @@ -243,16 +243,14 @@ #ifdef CFITSIO_VERSION return "CPL = " VERSION ", CFITSIO = " CPL_STRINGIFY(CFITSIO_VERSION) - CPL_WCS_APPEND CPL_FFTW_APPEND CPL_FLOPS_APPEND CPL_OPENMP_APPEND - CPL_IO_FITS_APPEND; + CPL_WCS_APPEND CPL_FFTW_APPEND CPL_OPENMP_APPEND; #else /* FIXME: Verify that 3.03 introduced CFITSIO_VERSION */ - return "CPL = " VERSION ", CFITSIO less than 3.03" - CPL_WCS_APPEND CPL_FFTW_APPEND CPL_FLOPS_APPEND CPL_OPENMP_APPEND - CPL_IO_FITS_APPEND; + return "CPL = " VERSION + ", CFITSIO less than 3.03" CPL_WCS_APPEND CPL_FFTW_APPEND + CPL_OPENMP_APPEND; #endif - } @@ -272,7 +270,6 @@ void cpl_end(void) { - (void)cpl_fits_set_mode(CPL_FITS_STOP_CACHING); #ifdef CPL_FFTWF_INSTALLED @@ -285,7 +282,6 @@ cpl_msg_stop(); return; - } diff -Nru cpl-7.1.4+ds/cplcore/cpl_init.h cpl-7.2.2+ds/cplcore/cpl_init.h --- cpl-7.1.4+ds/cplcore/cpl_init.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_init.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -25,11 +25,11 @@ CPL_BEGIN_DECLS -#define CPL_INIT_DEFAULT 0 +#define CPL_INIT_DEFAULT 0 #define CPL_DESCRIPTION_DEFAULT 0 void cpl_init(unsigned); -const char * cpl_get_description(unsigned); +const char *cpl_get_description(unsigned); void cpl_end(void); CPL_END_DECLS diff -Nru cpl-7.1.4+ds/cplcore/cpl_io_fits.c cpl-7.2.2+ds/cplcore/cpl_io_fits.c --- cpl-7.1.4+ds/cplcore/cpl_io_fits.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_io_fits.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -79,17 +79,19 @@ Private types -----------------------------------------------------------------------------*/ -typedef struct cpl_fitsfile_t { - char * name; - fitsfile * fptr; - int iomode; /* CFITSIO currently defines: READONLY, READWRITE */ +typedef struct cpl_fitsfile_t +{ + char *name; + size_t namelen; + fitsfile *fptr; + int iomode; /* CFITSIO currently defines: READONLY, READWRITE */ cpl_boolean has_stat; /* Set to true iff stat() can be & was called OK. */ /* When false, the below members are undefined */ #ifdef CPL_HAVE_STAT - dev_t st_dev; /* ID of device containing file */ - ino_t st_ino; /* inode number */ + dev_t st_dev; /* ID of device containing file */ + ino_t st_ino; /* inode number */ #endif - int tid; /* Thread id. It must be matched for read-reuse. + int tid; /* Thread id. It must be matched for read-reuse. If must also be matched if a file must be closed prematurely because there are too many open files. If matched for write-reuse the thread id is therefore @@ -108,34 +110,42 @@ /* The maximum number of open FITS-files */ static cpl_size cpl_io_max_open = (CPL_IO_FITS_MAX_OPEN); -static cpl_size cpl_nfitsfiles = 0; /* The number of open FITS-files */ -static cx_list * cpl_fitslist = NULL; /* The list of open, cached FITS-files */ +static cpl_size cpl_nfitsfiles = 0; /* The number of open FITS-files */ +static cx_list *cpl_fitslist = NULL; /* The list of open, cached FITS-files */ /*----------------------------------------------------------------------------- Private functions -----------------------------------------------------------------------------*/ #ifdef CPL_IO_FITS -static cpl_boolean cpl_io_fits_find_fptr(cx_list_iterator *, const char *, - const int *, const struct stat *) +static cpl_boolean cpl_io_fits_find_fptr(cx_list_iterator *, + const char *, + const int *, + const struct stat *) #ifdef CPL_HAVE_ATTR_NONNULL __attribute__((nonnull(1))) #endif ; + +inline static cpl_boolean cpl_io_fits_is_equal(const char *, + size_t, + const char *, + size_t *, + cpl_boolean *) CPL_ATTR_NONNULL; #endif -static fitsfile * cpl_io_fits_unset_fptr(const char *, const int *); -static fitsfile * cpl_io_fits_reuse_fptr(const char *, int, cpl_boolean) +static fitsfile *cpl_io_fits_unset_fptr(const char *, const int *); +static fitsfile *cpl_io_fits_reuse_fptr(const char *, int, cpl_boolean) #ifdef CPL_HAVE_ATTR_NONNULL __attribute__((nonnull(1))) #endif ; -static const char * cpl_io_fits_find_name(const fitsfile *, int *) - CPL_ATTR_NONNULL; -static void cpl_io_fits_set(fitsfile *, const char *, int, cpl_boolean) - CPL_ATTR_NONNULL; +static const char * +cpl_io_fits_find_name(const fitsfile *, int *) CPL_ATTR_NONNULL; +static void +cpl_io_fits_set(fitsfile *, const char *, int, cpl_boolean) CPL_ATTR_NONNULL; -static cpl_fitsfile_t * cpl_io_fits_unset_tid(int); +static cpl_fitsfile_t *cpl_io_fits_unset_tid(int); static int cpl_io_fits_free(cpl_fitsfile_t *, cpl_boolean, int *) #ifdef CPL_HAVE_ATTR_NONNULL __attribute__((nonnull(3))) @@ -153,22 +163,23 @@ * @see cpl_io_fits_end() * @note If the caching is already active, nothing happens */ -void cpl_io_fits_init(void) +void +cpl_io_fits_init(void) { #if defined HAVE_SYSCONF && defined _SC_OPEN_MAX const long open_max = sysconf(_SC_OPEN_MAX); - if (0 <= open_max && open_max/2 < (CPL_IO_FITS_MAX_OPEN)) - cpl_io_max_open = (cpl_size)(open_max/2); + if (0 <= open_max && open_max / 2 < (CPL_IO_FITS_MAX_OPEN)) + cpl_io_max_open = (cpl_size)(open_max / 2); #endif #ifdef CPL_IO_FITS_DEBUG cpl_msg_debug(cpl_func, cpl_fitslist == NULL - ? "Initializing, max file pointers: %" CPL_SIZE_FORMAT " <= " - CPL_STRINGIFY(CPL_IO_FITS_MAX_OPEN) - : "Already initialized, max file pointers: %" - CPL_SIZE_FORMAT " <= " - CPL_STRINGIFY(CPL_IO_FITS_MAX_OPEN), cpl_io_max_open); + ? "Initializing, max file pointers: %" CPL_SIZE_FORMAT + " <= " CPL_STRINGIFY(CPL_IO_FITS_MAX_OPEN) + : "Already initialized, max file pointers: %" CPL_SIZE_FORMAT + " <= " CPL_STRINGIFY(CPL_IO_FITS_MAX_OPEN), + cpl_io_max_open); #endif #ifdef CPL_IO_FITS @@ -192,7 +203,8 @@ * no other functions from this module may be called * */ -cpl_error_code cpl_io_fits_end(void) +cpl_error_code +cpl_io_fits_end(void) { const cpl_error_code error = cpl_io_fits_close_tid(CPL_IO_FITS_ALL); @@ -208,7 +220,7 @@ { if (cpl_fitslist != NULL) { cx_list_delete(cpl_fitslist); - cpl_fitslist = NULL; + cpl_fitslist = NULL; } } #endif @@ -219,21 +231,37 @@ /*----------------------------------------------------------------------------*/ /** @internal + @brief Get the maximum number of files cached + @return The maximum number of files cached + @note Will return non-zero also if caching is disabled and no files are cached + @see cpl_io_fits_is_enabled() + +*/ +/*----------------------------------------------------------------------------*/ +cpl_size +cpl_io_get_max_open(void) +{ + return cpl_io_max_open; +} + +/*----------------------------------------------------------------------------*/ +/** + @internal @brief Close all files in use by the specified thread(s) (current or all) @param mode CPL_IO_FITS_ALL (all threads) or CPL_IO_FITS_ONE (current thread) @return Zero on success or else the CFITSIO status */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_io_fits_close_tid(cpl_boolean mode) +cpl_error_code +cpl_io_fits_close_tid(cpl_boolean mode) { int status = 0; if (cpl_fitslist != NULL) { const int tid = mode == CPL_IO_FITS_ONE ? omp_get_thread_num() : -1; - cpl_fitsfile_t * oldest; + cpl_fitsfile_t *oldest; do { - #ifdef _OPENMP #pragma omp critical(cpl_io_fits) #endif @@ -255,7 +283,8 @@ * @see cpl_io_fits_init() * */ -cpl_boolean cpl_io_fits_is_enabled(void) +cpl_boolean +cpl_io_fits_is_enabled(void) { return cpl_fitslist != NULL ? CPL_TRUE : CPL_FALSE; } @@ -273,7 +302,8 @@ * currently open files are closed prior to opening this one. * */ -int cpl_io_fits_create_file(fitsfile **pfptr, const char *filename, int *status) +int +cpl_io_fits_create_file(fitsfile **pfptr, const char *filename, int *status) { if (*status == 0) { /* Duplicate CFITSIO behaviour */ @@ -290,14 +320,14 @@ cpl_nfitsfiles--; #ifdef CPL_IO_FITS_DEBUG cpl_msg_debug(cpl_func, "Closed file: %s (%p) (%d)", filename, - (const void*)*pfptr, (int)cpl_nfitsfiles); + (const void *)*pfptr, (int)cpl_nfitsfiles); #endif } if (*pfptr == NULL) { if (cpl_fitslist != NULL) { const int tid = omp_get_thread_num(); - cpl_fitsfile_t * oldest = NULL; + cpl_fitsfile_t *oldest = NULL; #ifdef _OPENMP /* Comparison critical with cpl_nfitsfiles increment */ #pragma omp critical(cpl_io_fits) @@ -333,12 +363,11 @@ #pragma omp atomic #endif cpl_nfitsfiles--; /* The open failed */ - } else { - + } + else { #ifdef CPL_IO_FITS_DEBUG cpl_msg_debug(cpl_func, "Opened file for writing: %s (%p) (%d)", - filename, (const void*)*pfptr, - (int)cpl_nfitsfiles); + filename, (const void *)*pfptr, (int)cpl_nfitsfiles); #endif /* FIXME: Assume READWRITE */ @@ -362,10 +391,12 @@ * use fits_movabs_hdu() and not fits_movrel_hdu(). * */ -int cpl_io_fits_open_diskfile(fitsfile **pfptr, const char * filename, - int iomode, int *status) +int +cpl_io_fits_open_diskfile(fitsfile **pfptr, + const char *filename, + int iomode, + int *status) { - if (*status == 0) { /* Duplicate CFITSIO behaviour */ const int rmiomode = iomode == READONLY ? READWRITE : READONLY; @@ -382,32 +413,38 @@ /* assert( cpl_io_fits_unset_fptr(filename, &rmiomode) == NULL); */ } - } else { + } + else { /* If the caller comes from a cpl_*_save() then we are free to assume that no other thread is inside a CPL I/O function concerning the same file. We can therefore unset and close all reader file pointers open for that filename. A write file pointer if present is not unset, since it can be reused. */ - while ((*pfptr = cpl_io_fits_unset_fptr(filename, &rmiomode)) - != NULL && !fits_close_file(*pfptr, status)) { + while ((*pfptr = cpl_io_fits_unset_fptr(filename, &rmiomode)) != + NULL && + !fits_close_file(*pfptr, status)) { #ifdef _OPENMP #pragma omp atomic #endif cpl_nfitsfiles--; #ifdef CPL_IO_FITS_DEBUG - cpl_msg_debug(cpl_func, "Closed file: %s (%p) (I/O-mode: %d != " - "%d) (%d)", filename, (const void*)*pfptr, - rmiomode, iomode, (int)cpl_nfitsfiles); + cpl_msg_debug(cpl_func, + "Closed file: %s (%p) (I/O-mode: %d != " + "%d) (%d)", + filename, (const void *)*pfptr, rmiomode, iomode, + (int)cpl_nfitsfiles); #endif } if (*status) { #ifdef CPL_IO_FITS_DEBUG - cpl_msg_debug(cpl_func, "Could not close file: %s (%p) (I/O-" - "mode: %d) (%d)", filename, (const void*)*pfptr, - rmiomode, (int)cpl_nfitsfiles); + cpl_msg_debug(cpl_func, + "Could not close file: %s (%p) (I/O-" + "mode: %d) (%d)", + filename, (const void *)*pfptr, rmiomode, + (int)cpl_nfitsfiles); #endif return *status; } @@ -417,39 +454,43 @@ /* Determine if an already open file can be reused */ /* If iomode is READONLY, then the tid must match */ /* If iomode is READWRITE, its tid will be set to the current one */ - *pfptr = cpl_io_fits_reuse_fptr(filename, iomode, - iomode == READWRITE); + *pfptr = + cpl_io_fits_reuse_fptr(filename, iomode, iomode == READWRITE); } if (*pfptr != NULL) { - #ifdef CPL_IO_FITS_DEBUG - cpl_msg_debug(cpl_func, "Reusing handle (%p) for: %s (I/O-mode" - ": %d%s) (%d)", (const void*)*pfptr, filename, - iomode, iomode == rmiomode ? " for reading" : "", + cpl_msg_debug(cpl_func, + "Reusing handle (%p) for: %s (I/O-mode" + ": %d%s) (%d)", + (const void *)*pfptr, filename, iomode, + iomode == rmiomode ? " for reading" : "", (int)cpl_nfitsfiles); #endif #ifdef CPL_IO_FITS_REWIND - /* A newly opened file points to the 1st HDU so do the same here */ - if (fits_movabs_hdu(*pfptr, 1, NULL, status)) { + /* A newly opened file points to the 1st HDU so do the same here */ + if (fits_movabs_hdu(*pfptr, 1, NULL, status)) { (void)cpl_error_fits(iomode == READWRITE - ? CPL_ERROR_FILE_NOT_CREATED - : CPL_ERROR_FILE_NOT_FOUND, status, - fits_movabs_hdu, "filename='%s', mode=%d", - filename, iomode); -#ifdef CPL_IO_FITS_DEBUG - cpl_msg_debug(cpl_func, "Could not move to primary HDU: %s (%p) (I/O-" - "mode: %d) (%d)", filename, (const void*)*pfptr, - rmiomode, (int)cpl_nfitsfiles); + ? CPL_ERROR_FILE_NOT_CREATED + : CPL_ERROR_FILE_NOT_FOUND, + status, fits_movabs_hdu, + "filename='%s', mode=%d", filename, + iomode); +#ifdef CPL_IO_FITS_DEBUG + cpl_msg_debug(cpl_func, + "Could not move to primary HDU: %s (%p) (I/O-" + "mode: %d) (%d)", + filename, (const void *)*pfptr, rmiomode, + (int)cpl_nfitsfiles); #endif - } + } #endif return *status; } if (cpl_fitslist != NULL) { const int tid = omp_get_thread_num(); - cpl_fitsfile_t * oldest = NULL; + cpl_fitsfile_t *oldest = NULL; #ifdef _OPENMP /* Comparison critical with cpl_nfitsfiles increment */ @@ -482,20 +523,21 @@ #endif if (fits_open_diskfile(pfptr, filename, iomode, status)) { (void)cpl_error_set_fits(iomode == READWRITE - ? CPL_ERROR_FILE_NOT_CREATED - : CPL_ERROR_FILE_NOT_FOUND, *status, - fits_open_diskfile, + ? CPL_ERROR_FILE_NOT_CREATED + : CPL_ERROR_FILE_NOT_FOUND, + *status, fits_open_diskfile, "filename='%s', mode=%d", filename, iomode); #ifdef _OPENMP #pragma omp atomic #endif cpl_nfitsfiles--; /* The open failed */ - } else { + } + else { cpl_io_fits_set(*pfptr, filename, iomode, iomode == READWRITE); #ifdef CPL_IO_FITS_DEBUG cpl_msg_debug(cpl_func, "Set file: %s (%p) (I/O-mode: %d) (%d)", - filename, (const void*)*pfptr, iomode, + filename, (const void *)*pfptr, iomode, (int)cpl_nfitsfiles); #endif } @@ -517,12 +559,12 @@ the program subsequently dies, the disk FITS file will be closed correctly. */ -int cpl_io_fits_close_file(fitsfile *fptr, int *status) +int +cpl_io_fits_close_file(fitsfile *fptr, int *status) { - if (*status == 0 && fptr != NULL) { /* Duplicate CFITSIO behaviour */ - int iomode; - const char * name = cpl_io_fits_find_name(fptr, &iomode); + int iomode; + const char *name = cpl_io_fits_find_name(fptr, &iomode); if (name == NULL) { /* This branch is used when CPL_IO_MODE is inactive */ @@ -530,15 +572,19 @@ (void)cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, *status, fits_close_file, "."); } - } else if (iomode != READONLY) { + } + else if (iomode != READONLY) { #ifdef CPL_IO_FITS_DEBUG cpl_msg_debug(cpl_func, "Flushing handle (%p) for: %s (%d) (%d)", - (const void*)fptr, name, iomode, (int)cpl_nfitsfiles); + (const void *)fptr, name, iomode, + (int)cpl_nfitsfiles); #endif if (fits_flush_file(fptr, status)) { (void)cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, *status, - fits_flush_file, "filename='%s', " - "mode=%d", name, iomode); + fits_flush_file, + "filename='%s', " + "mode=%d", + name, iomode); } } } @@ -556,19 +602,19 @@ * @note This wrapper is needed when CPL_IO_MODE is active */ -int cpl_io_fits_delete_file(fitsfile *fptr, int *status) +int +cpl_io_fits_delete_file(fitsfile *fptr, int *status) { - if (fptr != NULL) { /* Duplicate CFITSIO behaviour (*status ignored) */ - int iomode = 0; /* Initialize, in case the find fails */ - const char * name = cpl_io_fits_find_name(fptr, &iomode); + int iomode = 0; /* Initialize, in case the find fails */ + const char *name = cpl_io_fits_find_name(fptr, &iomode); - cpl_fitsfile_t * cpl_fitsfile = NULL; - const char * filename = name != NULL && *name == '!' ? name+1 : name; + cpl_fitsfile_t *cpl_fitsfile = NULL; + const char *filename = name != NULL && *name == '!' ? name + 1 : name; cx_list_iterator pos; struct stat statbuf; - const cpl_boolean has_stat = filename ? !stat(filename, &statbuf) - : CPL_FALSE; + const cpl_boolean has_stat = + filename ? !stat(filename, &statbuf) : CPL_FALSE; if (name != NULL) { /* CPL_IO_MODE is active */ @@ -581,8 +627,8 @@ has_stat ? &statbuf : NULL)) { /* Found it */ - cpl_fitsfile = (cpl_fitsfile_t *)cx_list_extract(cpl_fitslist, - pos); + cpl_fitsfile = + (cpl_fitsfile_t *)cx_list_extract(cpl_fitslist, pos); } } } @@ -591,11 +637,13 @@ int status_ = 0; cpl_io_fits_free(cpl_fitsfile, CPL_TRUE, &status_); *status = status_; - } else { + } + else { int status_ = 0; if (fits_delete_file(fptr, &status_)) { (void)cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, status_, - fits_delete_file, "filename='%s', " + fits_delete_file, + "filename='%s', " "I/O-mode: %d <=> %d/%d", name, iomode, READONLY, READWRITE); } @@ -614,29 +662,28 @@ @note May not be called when fitslist is empty */ -static cpl_fitsfile_t * cpl_io_fits_unset_tid(int tid) +static cpl_fitsfile_t * +cpl_io_fits_unset_tid(int tid) { - #ifdef CPL_IO_FITS cx_list_iterator pos = cx_list_begin(cpl_fitslist); while (pos != cx_list_end(cpl_fitslist)) { - - const cpl_fitsfile_t * cpl_fitsfile = + const cpl_fitsfile_t *cpl_fitsfile = (const cpl_fitsfile_t *)cx_list_get(cpl_fitslist, pos); - if (tid < 0 || cpl_fitsfile->tid == tid) break; + if (tid < 0 || cpl_fitsfile->tid == tid) + break; pos = cx_list_next(cpl_fitslist, pos); } - return pos != cx_list_end(cpl_fitslist) - ? cx_list_extract(cpl_fitslist, pos) : NULL; + return pos != cx_list_end(cpl_fitslist) ? cx_list_extract(cpl_fitslist, pos) + : NULL; #else return NULL; #endif - } /** @@ -647,26 +694,27 @@ @param status The CFITSIO status @return Zero on success or else the CFITSIO status */ -static -int cpl_io_fits_free(cpl_fitsfile_t * self, cpl_boolean dodel, int * status) +static int +cpl_io_fits_free(cpl_fitsfile_t *self, cpl_boolean dodel, int *status) { - if (self != NULL) { if (*status == 0) { if (dodel) { if (fits_delete_file(self->fptr, status)) { (void)cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, *status, - fits_delete_file, "filename='%s', " + fits_delete_file, + "filename='%s', " "I/O-mode: %d, Thread-ID: %d", self->name, self->iomode, self->tid); } - } else if (fits_close_file(self->fptr, status)) { + } + else if (fits_close_file(self->fptr, status)) { (void)cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, *status, - fits_close_file, "filename='%s', " + fits_close_file, + "filename='%s', " "I/O-mode: %d, Thread-ID: %d", - self->name, self->iomode, - self->tid); + self->name, self->iomode, self->tid); } if (*status == 0) { @@ -676,15 +724,15 @@ cpl_nfitsfiles--; #ifdef CPL_IO_FITS_DEBUG - cpl_msg_debug(cpl_func, "Closed oldest file of thread %d: %s " - "(I/O-mode: %d. %p) (%d)", self->tid, self->name, - self->iomode, (const void*)self->fptr, *status); + cpl_msg_debug(cpl_func, + "Closed oldest file of thread %d: %s " + "(I/O-mode: %d. %p) (%d)", + self->tid, self->name, self->iomode, + (const void *)self->fptr, *status); #endif } - } - cpl_free(self->name); cpl_free(self); } @@ -701,20 +749,21 @@ @note If no file handle exists for the file, nothing is done */ /*----------------------------------------------------------------------------*/ -int cpl_io_fits_close(const char * filename, int * status) +int +cpl_io_fits_close(const char *filename, int *status) { if (*status == 0) { /* Duplicate CFITSIO behaviour */ - fitsfile * fptr; + fitsfile *fptr; - while ((fptr = cpl_io_fits_unset_fptr(filename, NULL)) - != NULL && !fits_close_file(fptr, status)) { + while ((fptr = cpl_io_fits_unset_fptr(filename, NULL)) != NULL && + !fits_close_file(fptr, status)) { #ifdef _OPENMP #pragma omp atomic #endif cpl_nfitsfiles--; #ifdef CPL_IO_FITS_DEBUG cpl_msg_debug(cpl_func, "Closed CFITSIO-file: %p (%s) (%d)", - (const void*)fptr, filename, (int)cpl_nfitsfiles); + (const void *)fptr, filename, (int)cpl_nfitsfiles); #endif } } @@ -722,6 +771,35 @@ return *status; } +/** + * @internal + * @brief Return true iff the named file is open as FITS + * @return CPL_TRUE iff the named file is open as FITS + * @see cpl_io_fits_is_enabled() + * + */ +cpl_boolean +cpl_io_fits_is_open(const char *filename) +{ + cpl_boolean is_open = CPL_FALSE; +#ifdef CPL_IO_FITS + if (cpl_fitslist != NULL) { + cx_list_iterator pos; + +#ifdef _OPENMP +#pragma omp critical(cpl_io_fits) +#endif + { + if (cpl_io_fits_find_fptr(&pos, filename, NULL, NULL)) { + /* Found it */ + is_open = CPL_TRUE; + } + } + } +#endif + return is_open; +} + /**@}*/ /*----------------------------------------------------------------------------*/ @@ -737,31 +815,38 @@ name (and fptr) can safely be assumed to be non-NULL. */ /*----------------------------------------------------------------------------*/ -static void cpl_io_fits_set(fitsfile * fptr, const char * name, int iomode, - cpl_boolean writing) +static void +cpl_io_fits_set(fitsfile *fptr, + const char *name, + int iomode, + cpl_boolean writing) { #ifdef CPL_IO_FITS if (cpl_fitslist != NULL) { - - char * filename = cpl_strdup(*name == '!' ? name+1 : name); + const char *filename = *name == '!' ? name + 1 : name; + const size_t namelen = strlen(filename); struct stat statbuf; const cpl_boolean has_stat = !stat(filename, &statbuf); - cpl_fitsfile_t * cpl_fitsfile = cpl_malloc(sizeof(*cpl_fitsfile)); + /* Store copy of name w. null terminator right after struct */ + cpl_fitsfile_t *cpl_fitsfile = + cpl_malloc(sizeof(*cpl_fitsfile) + namelen + 1); /* assert(iomode != READONLY || !writing); */ - cpl_fitsfile->fptr = fptr; - cpl_fitsfile->name = filename; + cpl_fitsfile->fptr = fptr; + cpl_fitsfile->name = + (char *)memcpy(cpl_fitsfile + 1, filename, namelen + 1); + cpl_fitsfile->namelen = namelen; cpl_fitsfile->iomode = iomode; - cpl_fitsfile->tid = omp_get_thread_num(); + cpl_fitsfile->tid = omp_get_thread_num(); cpl_fitsfile->writing = writing; cpl_fitsfile->has_stat = has_stat; if (has_stat) { cpl_fitsfile->st_dev = statbuf.st_dev; - cpl_fitsfile->st_ino = statbuf.st_ino; + cpl_fitsfile->st_ino = statbuf.st_ino; } #ifdef _OPENMP @@ -778,6 +863,35 @@ /*----------------------------------------------------------------------------*/ /** @internal + @brief Determine if the two filenames are equal + @param refname The 1st filename + @param reflen The length of the 1st filename (not counting null terminator) + @param filename The second filename + @param pnamelen The length of the 2nd filename, to be determined on 1st call + @param pfirst True on 1st call, then set to false + @return CPL_TRUE, iff equal + @note Pointers may not be NULL! +*/ +/*----------------------------------------------------------------------------*/ +inline static cpl_boolean +cpl_io_fits_is_equal(const char *refname, + size_t reflen, + const char *filename, + size_t *pnamelen, + cpl_boolean *pfirst) +{ + if (*pfirst) { + *pnamelen = strlen(filename); + *pfirst = CPL_FALSE; + } + return *pnamelen == reflen && !memcmp(refname, filename, reflen) + ? CPL_TRUE + : CPL_FALSE; +} + +/*----------------------------------------------------------------------------*/ +/** + @internal @brief Search by name for an already opened FITS file @param pkey Iff found, *pkey is the location of the entry @param filename The filename to look for, NULL will return first available @@ -787,31 +901,37 @@ @note Pointer pkey may not be NULL! */ /*----------------------------------------------------------------------------*/ -static cpl_boolean cpl_io_fits_find_fptr(cx_list_iterator * pkey, - const char * filename, - const int * piomode, - const struct stat * filestat) +static cpl_boolean +cpl_io_fits_find_fptr(cx_list_iterator *pkey, + const char *filename, + const int *piomode, + const struct stat *filestat) { - const int tid = omp_get_thread_num(); - const cpl_fitsfile_t * cpl_fitsfile = NULL; + const cpl_fitsfile_t *cpl_fitsfile = NULL; + size_t namelen = 0; + cpl_boolean is_first = CPL_TRUE; cpl_size i = 0; cx_list_iterator pos = cx_list_begin(cpl_fitslist); cpl_boolean found; - while ((found = pos != cx_list_end(cpl_fitslist))) { - + while ((found = (pos != cx_list_end(cpl_fitslist)))) { cpl_fitsfile = (const cpl_fitsfile_t *)cx_list_get(cpl_fitslist, pos); - if (filename == NULL) break;/* Matches any entry */ + if (filename == NULL) + break; /* Matches any entry */ if ((piomode == NULL || *piomode == cpl_fitsfile->iomode) && - (((piomode == NULL || *piomode != READONLY) - && cpl_fitsfile->writing) || cpl_fitsfile->tid == tid) && + (((piomode == NULL || *piomode != READONLY) && + cpl_fitsfile->writing) || + cpl_fitsfile->tid == tid) && (filestat != NULL && cpl_fitsfile->has_stat - ? cpl_fitsfile->st_dev == filestat->st_dev && - cpl_fitsfile->st_ino == filestat->st_ino - : !strcmp(cpl_fitsfile->name, filename))) break; + ? cpl_fitsfile->st_dev == filestat->st_dev && + cpl_fitsfile->st_ino == filestat->st_ino + : cpl_io_fits_is_equal(cpl_fitsfile->name, + cpl_fitsfile->namelen, filename, + &namelen, &is_first))) + break; pos = cx_list_next(cpl_fitslist, pos); i++; @@ -820,14 +940,20 @@ if (found) { *pkey = pos; #ifdef CPL_IO_FITS_DEBUG - cpl_msg_debug(cpl_func, "File %s found (%d < %d): %p (I/O-mode: " - "%d) (tid: %d <=> %d)", filename, (int)i, - (int)cpl_nfitsfiles, (const void*)cpl_fitsfile->fptr, - cpl_fitsfile->iomode, tid, cpl_fitsfile->tid); - } else if (piomode != NULL) { - cpl_msg_debug(cpl_func, "File %s not found (%d) (I/O-mode: %d, " - "tid=%d)", filename, (int)cpl_nfitsfiles, *piomode, tid); - } else { + cpl_msg_debug(cpl_func, + "File %s found (%d < %d): %p (I/O-mode: " + "%d) (tid: %d <=> %d)", + filename, (int)i, (int)cpl_nfitsfiles, + (const void *)cpl_fitsfile->fptr, cpl_fitsfile->iomode, + tid, cpl_fitsfile->tid); + } + else if (piomode != NULL) { + cpl_msg_debug(cpl_func, + "File %s not found (%d) (I/O-mode: %d, " + "tid=%d)", + filename, (int)cpl_nfitsfiles, *piomode, tid); + } + else { cpl_msg_debug(cpl_func, "File %s not found (%d) (tid=%d)", filename, (int)cpl_nfitsfiles, tid); #endif @@ -857,20 +983,19 @@ */ /*----------------------------------------------------------------------------*/ -static fitsfile * cpl_io_fits_unset_fptr(const char * name, const int * piomode) +static fitsfile * +cpl_io_fits_unset_fptr(const char *name, const int *piomode) { - - fitsfile * fptr = NULL; + fitsfile *fptr = NULL; #ifdef CPL_IO_FITS if (cpl_fitslist != NULL) { - cpl_fitsfile_t * cpl_fitsfile = NULL; - const char * filename = name != NULL && *name == '!' ? name+1 : name; + cpl_fitsfile_t *cpl_fitsfile = NULL; + const char *filename = name != NULL && *name == '!' ? name + 1 : name; cx_list_iterator pos; struct stat statbuf; - const cpl_boolean has_stat = filename ? !stat(filename, &statbuf) - : CPL_FALSE; - + const cpl_boolean has_stat = + filename ? !stat(filename, &statbuf) : CPL_FALSE; #ifdef _OPENMP @@ -881,14 +1006,13 @@ has_stat ? &statbuf : NULL)) { /* Found it */ - cpl_fitsfile = (cpl_fitsfile_t *)cx_list_extract(cpl_fitslist, - pos); + cpl_fitsfile = + (cpl_fitsfile_t *)cx_list_extract(cpl_fitslist, pos); } } if (cpl_fitsfile != NULL) { fptr = cpl_fitsfile->fptr; - cpl_free(cpl_fitsfile->name); cpl_free(cpl_fitsfile); } } @@ -914,16 +1038,15 @@ flag is cleared. */ /*----------------------------------------------------------------------------*/ -static fitsfile * cpl_io_fits_reuse_fptr(const char * name, int iomode, - cpl_boolean writing) +static fitsfile * +cpl_io_fits_reuse_fptr(const char *name, int iomode, cpl_boolean writing) { - - fitsfile * fptr = NULL; + fitsfile *fptr = NULL; #ifdef CPL_IO_FITS if (cpl_fitslist != NULL) { - cpl_fitsfile_t * cpl_fitsfile = NULL; - const char * filename = *name == '!' ? name+1 : name; + cpl_fitsfile_t *cpl_fitsfile = NULL; + const char *filename = *name == '!' ? name + 1 : name; cx_list_iterator pos; struct stat statbuf; const cpl_boolean has_stat = !stat(filename, &statbuf); @@ -967,15 +1090,14 @@ @return When found, the name otherwise NULL */ /*----------------------------------------------------------------------------*/ -static const char * cpl_io_fits_find_name(const fitsfile * fptr, int * piomode) +static const char * +cpl_io_fits_find_name(const fitsfile *fptr, int *piomode) { - - const char * name = NULL; + const char *name = NULL; #ifdef CPL_IO_FITS if (cpl_fitslist != NULL) { - #ifdef _OPENMP #pragma omp critical(cpl_io_fits) #endif @@ -983,13 +1105,12 @@ cx_list_const_iterator pos = cx_list_begin(cpl_fitslist); while (pos != cx_list_end(cpl_fitslist)) { - - const cpl_fitsfile_t * cpl_fitsfile = (const cpl_fitsfile_t *) - cx_list_get(cpl_fitslist, pos); + const cpl_fitsfile_t *cpl_fitsfile = + (const cpl_fitsfile_t *)cx_list_get(cpl_fitslist, pos); if (fptr == cpl_fitsfile->fptr) { /* Found it */ - name = cpl_fitsfile->name; + name = cpl_fitsfile->name; *piomode = cpl_fitsfile->iomode; break; } diff -Nru cpl-7.1.4+ds/cplcore/cpl_io_fits.h cpl-7.2.2+ds/cplcore/cpl_io_fits.h --- cpl-7.1.4+ds/cplcore/cpl_io_fits.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_io_fits.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -60,25 +60,25 @@ #undef CPL_IO_FITS #ifndef CPL_HAVE_STAT /* Without stat() the caching is disabled */ -#elif defined CPL_IO_FITS_MAX_OPEN && CPL_IO_FITS_MAX_OPEN == 0 +#elif defined CPL_IO_FITS_MAX_OPEN && CPL_IO_FITS_MAX_OPEN == 0 /* May be defined to zero to disable the caching of file handles */ #else -# define CPL_IO_FITS +#define CPL_IO_FITS #endif #ifndef CPL_IO_FITS -# undef CPL_IO_FITS_MAX_OPEN -# define CPL_IO_FITS_MAX_OPEN 0 +#undef CPL_IO_FITS_MAX_OPEN +#define CPL_IO_FITS_MAX_OPEN 0 #elif !defined CPL_IO_FITS_MAX_OPEN || CPL_IO_FITS_MAX_OPEN > NMAXFILES -# undef CPL_IO_FITS_MAX_OPEN +#undef CPL_IO_FITS_MAX_OPEN /* May be defined to zero to disable the caching of file handles */ /* Default value is the maximum allowed by CFITSIO, but can be defined (to less) if needed due to a limit imposed by e.g. setrlimit() */ -# define CPL_IO_FITS_MAX_OPEN NMAXFILES +#define CPL_IO_FITS_MAX_OPEN NMAXFILES #elif CPL_IO_FITS_MAX_OPEN < 0 /* Prevent trouble from a manually set value */ -# error "CPL_IO_FITS_MAX_OPEN has am illegal, negative value" +#error "CPL_IO_FITS_MAX_OPEN has an illegal, negative value" #endif #define CPL_IO_FITS_ALL CPL_TRUE @@ -91,8 +91,12 @@ void cpl_io_fits_init(void); cpl_error_code cpl_io_fits_end(void); +cpl_size cpl_io_get_max_open(void); + cpl_boolean cpl_io_fits_is_enabled(void); +cpl_boolean cpl_io_fits_is_open(const char *) CPL_ATTR_NONNULL; + int cpl_io_fits_create_file(fitsfile **, const char *, int *) CPL_ATTR_NONNULL; int cpl_io_fits_open_diskfile(fitsfile **, const char *, int, int *) @@ -104,8 +108,7 @@ #endif ; -int cpl_io_fits_delete_file(fitsfile *, int *) - CPL_INTERNAL +int cpl_io_fits_delete_file(fitsfile *, int *) CPL_INTERNAL #ifdef CPL_HAVE_ATTR_NONNULL __attribute__((nonnull(2))) #endif @@ -121,4 +124,4 @@ CPL_END_DECLS -#endif +#endif diff -Nru cpl-7.1.4+ds/cplcore/cpl_io.h cpl-7.2.2+ds/cplcore/cpl_io.h --- cpl-7.1.4+ds/cplcore/cpl_io.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_io.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -59,7 +59,8 @@ */ /*----------------------------------------------------------------------------*/ -enum _cpl_io_type_ { +enum _cpl_io_type_ +{ /* * More modes may be added in the future. To support future combination of @@ -100,7 +101,7 @@ /**< Reserved for internal CPL usage. */ /** @hideinitializer */ - CPL_IO_DEFAULT = ((unsigned)CPL_IO_CREATE) + CPL_IO_DEFAULT = ((unsigned)CPL_IO_CREATE) /**< Deprecated, kept only for backwards compatibility */ }; @@ -113,16 +114,15 @@ typedef enum _cpl_io_type_ cpl_io_type; - /** @deprecated Use CPL_TYPE_UCHAR */ -#define CPL_BPP_8_UNSIGNED CPL_TYPE_UCHAR +#define CPL_BPP_8_UNSIGNED CPL_TYPE_UCHAR /** @deprecated Use CPL_TYPE_SHORT */ -#define CPL_BPP_16_SIGNED CPL_TYPE_SHORT +#define CPL_BPP_16_SIGNED CPL_TYPE_SHORT /** @deprecated Use CPL_TYPE_USHORT @@ -132,12 +132,12 @@ /** @deprecated Use CPL_TYPE_INT */ -#define CPL_BPP_32_SIGNED CPL_TYPE_INT +#define CPL_BPP_32_SIGNED CPL_TYPE_INT /** @deprecated Use CPL_TYPE_FLOAT */ -#define CPL_BPP_IEEE_FLOAT CPL_TYPE_FLOAT +#define CPL_BPP_IEEE_FLOAT CPL_TYPE_FLOAT /** @deprecated Use CPL_TYPE_DOUBLE @@ -146,7 +146,7 @@ /** @deprecated Use cpl_type */ -#define cpl_type_bpp cpl_type +#define cpl_type_bpp cpl_type /**@}*/ diff -Nru cpl-7.1.4+ds/cplcore/cpl_macros.h cpl-7.2.2+ds/cplcore/cpl_macros.h --- cpl-7.1.4+ds/cplcore/cpl_macros.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_macros.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -33,8 +33,8 @@ #undef CPL_BEGIN_DECLS #undef CPL_END_DECLS -#define CPL_BEGIN_DECLS CX_BEGIN_DECLS -#define CPL_END_DECLS CX_END_DECLS +#define CPL_BEGIN_DECLS CX_BEGIN_DECLS +#define CPL_END_DECLS CX_END_DECLS /* @@ -44,19 +44,19 @@ */ #ifdef CPL_UNUSED_WARNINGS -# define CPL_UNUSED(arg) +#define CPL_UNUSED(arg) #else -# define CPL_UNUSED(arg) (void)(arg) +#define CPL_UNUSED(arg) (void)(arg) #endif /* Needed to concatenate two and three macro arguments */ -#define CPL_CONCAT(a,b) a ## _ ## b -#define CPL_CONCAT2X(a,b) CPL_CONCAT(a,b) -#define CPL_CONCAT3X(a,b,c) CPL_CONCAT2X(CPL_CONCAT2X(a,b),c) +#define CPL_CONCAT(a, b) a##_##b +#define CPL_CONCAT2X(a, b) CPL_CONCAT(a, b) +#define CPL_CONCAT3X(a, b, c) CPL_CONCAT2X(CPL_CONCAT2X(a, b), c) #define CPL_XSTRINGIFY(TOSTRING) #TOSTRING -#define CPL_STRINGIFY(TOSTRING) CPL_XSTRINGIFY(TOSTRING) +#define CPL_STRINGIFY(TOSTRING) CPL_XSTRINGIFY(TOSTRING) /* @@ -76,125 +76,129 @@ */ #if defined __GNUC__ && __GNUC__ > 2 - /* gcc 3 or higher */ +/* gcc 3 or higher */ -# define CPL_ATTR_CONST __attribute__((const)) -# define CPL_ATTR_PRINTF(A,B) __attribute__((format (printf, A, B))) -# define CPL_ATTR_PURE __attribute__((pure)) - -# if __GNUC__ > 3 || defined __GNUC_MINOR__ && __GNUC_MINOR__ > 0 - /* gcc 3.1 or higher */ -# define CPL_ATTR_DEPRECATED __attribute__((deprecated)) -# endif - -# if __GNUC__ > 3 || defined __GNUC_MINOR__ && __GNUC_MINOR__ > 2 - /* gcc 3.3 or higher */ -# define CPL_ATTR_NONNULL __attribute__((nonnull)) -# define CPL_HAVE_ATTR_NONNULL -# define CPL_UNLIKELY(x) __builtin_expect((x), 0) -# define CPL_LIKELY(x) __builtin_expect((x), 1) -# define CPL_ATTR_NOINLINE __attribute__((noinline)) -# endif - -# if __GNUC__ > 3 || defined __GNUC_MINOR__ && __GNUC_MINOR__ > 3 - /* gcc 3.4 or higher */ -# define CPL_ATTR_ALLOC __attribute__((malloc, warn_unused_result)) - -# if __GNUC__ > 4 || __GNUC__ == 4 && defined __GNUC_MINOR__ && __GNUC_MINOR__ > 2 - /* gcc 4.3 or higher */ - -# define CPL_ATTR_MALLOC \ - __attribute__((malloc, warn_unused_result, alloc_size(1))) -# define CPL_ATTR_CALLOC \ - __attribute__((malloc, warn_unused_result, alloc_size(1,2))) -# define CPL_ATTR_REALLOC \ - __attribute__((warn_unused_result, alloc_size(2))) -# else - /* gcc 3.4 to 4.2 */ -# define CPL_ATTR_MALLOC __attribute__((malloc, warn_unused_result)) -# define CPL_ATTR_CALLOC __attribute__((malloc, warn_unused_result)) -# define CPL_ATTR_REALLOC __attribute__((warn_unused_result)) -# endif - -# else - /* gcc 3.0 to 3.3 */ - -# define CPL_ATTR_ALLOC __attribute__((malloc)) -# define CPL_ATTR_MALLOC __attribute__((malloc)) -# define CPL_ATTR_CALLOC __attribute__((malloc)) -# define CPL_ATTR_REALLOC /* __attribute__ */ -# endif - -# if __GNUC__ >= 4 -# define CPL_INTERNAL __attribute__((visibility("hidden"))) -# define CPL_EXPORT __attribute__((visibility("default"))) -# endif +#define CPL_ATTR_CONST __attribute__((const)) +#define CPL_ATTR_PRINTF(A, B) __attribute__((format(printf, A, B))) +#define CPL_ATTR_PURE __attribute__((pure)) + +#if __GNUC__ > 3 || defined __GNUC_MINOR__ && __GNUC_MINOR__ > 0 +/* gcc 3.1 or higher */ +#define CPL_ATTR_DEPRECATED __attribute__((deprecated)) +#endif + +#if __GNUC__ > 3 || defined __GNUC_MINOR__ && __GNUC_MINOR__ > 2 +/* gcc 3.3 or higher */ +#define CPL_ATTR_NONNULL __attribute__((nonnull)) +#define CPL_HAVE_ATTR_NONNULL +#define CPL_UNLIKELY(x) __builtin_expect((x), 0) +#define CPL_LIKELY(x) __builtin_expect((x), 1) +#define CPL_ATTR_NOINLINE __attribute__((noinline)) +#endif + +#if __GNUC__ > 3 || defined __GNUC_MINOR__ && __GNUC_MINOR__ > 3 +/* gcc 3.4 or higher */ +#define CPL_ATTR_ALLOC __attribute__((malloc, warn_unused_result)) + +#if __GNUC__ > 4 || \ + __GNUC__ == 4 && defined __GNUC_MINOR__ && __GNUC_MINOR__ > 2 +/* gcc 4.3 or higher */ + +#define CPL_ATTR_MALLOC \ + __attribute__((malloc, warn_unused_result, alloc_size(1))) +#define CPL_ATTR_CALLOC \ + __attribute__((malloc, warn_unused_result, alloc_size(1, 2))) +#define CPL_ATTR_REALLOC __attribute__((warn_unused_result, alloc_size(2))) +#else +/* gcc 3.4 to 4.2 */ +#define CPL_ATTR_MALLOC __attribute__((malloc, warn_unused_result)) +#define CPL_ATTR_CALLOC __attribute__((malloc, warn_unused_result)) +#define CPL_ATTR_REALLOC __attribute__((warn_unused_result)) +#endif + +#else +/* gcc 3.0 to 3.3 */ + +#define CPL_ATTR_ALLOC __attribute__((malloc)) +#define CPL_ATTR_MALLOC __attribute__((malloc)) +#define CPL_ATTR_CALLOC __attribute__((malloc)) +#define CPL_ATTR_REALLOC /* __attribute__ */ +#endif + +#if __GNUC__ >= 4 +#define CPL_INTERNAL __attribute__((visibility("hidden"))) +#define CPL_EXPORT __attribute__((visibility("default"))) +#endif #endif #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) -#define CPL_DIAG_PRAGMA_PUSH_IGN(x) \ - _Pragma("GCC diagnostic push") \ - _Pragma(CPL_STRINGIFY(GCC diagnostic ignored #x)) -#define CPL_DIAG_PRAGMA_PUSH_ERR(x) \ - _Pragma("GCC diagnostic push") \ - _Pragma(CPL_STRINGIFY(GCC diagnostic error #x)) -#define CPL_DIAG_PRAGMA_POP \ - _Pragma("GCC diagnostic pop") +#define CPL_DIAG_PRAGMA_PUSH_IGN(x) \ + _Pragma("GCC diagnostic push") \ + _Pragma(CPL_STRINGIFY(GCC diagnostic ignored #x)) +#define CPL_DIAG_PRAGMA_PUSH_ERR(x) \ + _Pragma("GCC diagnostic push") \ + _Pragma(CPL_STRINGIFY(GCC diagnostic error #x)) +#define CPL_DIAG_PRAGMA_POP _Pragma("GCC diagnostic pop") #else #define CPL_DIAG_PRAGMA_PUSH_IGN(x) /* pragma GCC diagnostic ignored */ #define CPL_DIAG_PRAGMA_PUSH_ERR(x) /* pragma GCC diagnostic error */ #define CPL_DIAG_PRAGMA_POP /* pragma GCC diagnostic pop */ #endif +#if __GNUC__ >= 7 +#define CPL_ATTR_FALLTRHU __attribute__((fallthrough)) +#else +#define CPL_ATTR_FALLTRHU /* fall through */ +#endif #ifndef CPL_ATTR_ALLOC -# define CPL_ATTR_ALLOC /* __attribute__ */ +#define CPL_ATTR_ALLOC /* __attribute__ */ #endif #ifndef CPL_ATTR_CALLOC -# define CPL_ATTR_CALLOC /*__attribute__ */ +#define CPL_ATTR_CALLOC /*__attribute__ */ #endif #ifndef CPL_ATTR_CONST -# define CPL_ATTR_CONST /* __attribute__ */ +#define CPL_ATTR_CONST /* __attribute__ */ #endif #ifndef CPL_ATTR_DEPRECATED -# define CPL_ATTR_DEPRECATED /* __attribute__ */ +#define CPL_ATTR_DEPRECATED /* __attribute__ */ #endif #ifndef CPL_ATTR_PURE -# define CPL_ATTR_PURE /* __attribute__ */ +#define CPL_ATTR_PURE /* __attribute__ */ #endif #ifndef CPL_ATTR_MALLOC -# define CPL_ATTR_MALLOC /* __attribute__ */ +#define CPL_ATTR_MALLOC /* __attribute__ */ #endif #ifndef CPL_ATTR_NONNULL -# define CPL_ATTR_NONNULL /* __attribute__ */ +#define CPL_ATTR_NONNULL /* __attribute__ */ #endif #ifndef CPL_ATTR_PRINTF -# define CPL_ATTR_PRINTF(A,B) /* __attribute__ */ +#define CPL_ATTR_PRINTF(A, B) /* __attribute__ */ #endif #ifndef CPL_ATTR_REALLOC -# define CPL_ATTR_REALLOC /* __attribute__ */ +#define CPL_ATTR_REALLOC /* __attribute__ */ #endif #ifndef CPL_UNLIKELY -# define CPL_UNLIKELY(x) (x) -# define CPL_LIKELY(x) (x) +#define CPL_UNLIKELY(x) (x) +#define CPL_LIKELY(x) (x) #endif #ifndef CPL_ATTR_NOINLINE -# define CPL_ATTR_NOINLINE /* __attribute__ */ +#define CPL_ATTR_NOINLINE /* __attribute__ */ #endif #ifndef CPL_INTERNAL -# define CPL_INTERNAL /* __attribute__ */ -# define CPL_EXPORT /* __attribute__ */ +#define CPL_INTERNAL /* __attribute__ */ +#define CPL_EXPORT /* __attribute__ */ #endif #endif /* CPL_MACROS_H */ diff -Nru cpl-7.1.4+ds/cplcore/cpl_mask_binary.h cpl-7.2.2+ds/cplcore/cpl_mask_binary.h --- cpl-7.1.4+ds/cplcore/cpl_mask_binary.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_mask_binary.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -30,20 +30,20 @@ */ /*----------------------------------------------------------------------------*/ -void APPENDOPER(CPL_MASK_BINARY_WOPER)(cpl_binary * self, - const cpl_binary * first, - const cpl_binary * second, +void APPENDOPER(CPL_MASK_BINARY_WOPER)(cpl_binary *self, + const cpl_binary *first, + const cpl_binary *second, size_t nxy) { - - CPL_MASK_REGISTER_TYPE * word0 = (CPL_MASK_REGISTER_TYPE*)self; - const CPL_MASK_REGISTER_TYPE* word1 = first - ? (const CPL_MASK_REGISTER_TYPE*)first - : (const CPL_MASK_REGISTER_TYPE*)self; - const CPL_MASK_REGISTER_TYPE* word2 = (const CPL_MASK_REGISTER_TYPE*)second; - const size_t nword = nxy / CPL_MASK_REGISTER_SIZE; - size_t i; + CPL_MASK_REGISTER_TYPE *word0 = (CPL_MASK_REGISTER_TYPE *)self; + const CPL_MASK_REGISTER_TYPE *word1 = + first ? (const CPL_MASK_REGISTER_TYPE *)first + : (const CPL_MASK_REGISTER_TYPE *)self; + const CPL_MASK_REGISTER_TYPE *word2 = + (const CPL_MASK_REGISTER_TYPE *)second; + const size_t nword = nxy / CPL_MASK_REGISTER_SIZE; + size_t i; for (i = 0; i < nword; i++) { @@ -68,7 +68,8 @@ for (; i < nxy; i++) { self[i] = self[i] CPL_MASK_BINARY_OPER second[i]; } - } else { + } + else { for (; i < nxy; i++) { self[i] = first[i] CPL_MASK_BINARY_OPER second[i]; } @@ -88,19 +89,18 @@ */ /*----------------------------------------------------------------------------*/ -void APPENDOPERS(CPL_MASK_BINARY_WOPER)(cpl_binary * self, - const cpl_binary * first, +void APPENDOPERS(CPL_MASK_BINARY_WOPER)(cpl_binary *self, + const cpl_binary *first, cpl_bitmask second, size_t nxy) { - - CPL_MASK_REGISTER_TYPE * word0 = (CPL_MASK_REGISTER_TYPE*)self; - const CPL_MASK_REGISTER_TYPE* word1 = first - ? (const CPL_MASK_REGISTER_TYPE*)first - : (const CPL_MASK_REGISTER_TYPE*)self; - const size_t nword = nxy / CPL_MASK_REGISTER_SIZE; - size_t i; + CPL_MASK_REGISTER_TYPE *word0 = (CPL_MASK_REGISTER_TYPE *)self; + const CPL_MASK_REGISTER_TYPE *word1 = + first ? (const CPL_MASK_REGISTER_TYPE *)first + : (const CPL_MASK_REGISTER_TYPE *)self; + const size_t nword = nxy / CPL_MASK_REGISTER_SIZE; + size_t i; for (i = 0; i < nword; i++) { @@ -116,7 +116,7 @@ const __m128i v0 = OPER2MM(CPL_MASK_BINARY_WOPER)(v1, v2); _mm_storeu_si128(word0 + i, v0); #else - word0[i] = word1[i] CPL_MASK_BINARY_OPER (CPL_MASK_REGISTER_TYPE)second; + word0[i] = word1[i] CPL_MASK_BINARY_OPER(CPL_MASK_REGISTER_TYPE) second; #endif } @@ -126,30 +126,31 @@ #if CPL_MASK_REGISTER_SIZE > 8 if (i + 8 <= nxy) { /* Handle the remaining uint64_t */ - uint64_t * self8 = (uint64_t *)self; - const uint64_t * first8 = (const uint64_t *)(first ? first : self); + uint64_t *self8 = (uint64_t *)self; + const uint64_t *first8 = (const uint64_t *)(first ? first : self); - self8[i/8] = first8[i/8] CPL_MASK_BINARY_OPER (uint64_t)second; + self8[i / 8] = first8[i / 8] CPL_MASK_BINARY_OPER(uint64_t) second; i += 8; } #endif if (i + 4 <= nxy) { /* Handle the remaining uint32_t */ - uint32_t * self4 = (uint32_t *)self; - const uint32_t * first4 = (const uint32_t *)(first ? first : self); + uint32_t *self4 = (uint32_t *)self; + const uint32_t *first4 = (const uint32_t *)(first ? first : self); - self4[i/4] = first4[i/4] CPL_MASK_BINARY_OPER (uint32_t)second; + self4[i / 4] = first4[i / 4] CPL_MASK_BINARY_OPER(uint32_t) second; i += 4; } #endif if (first == NULL) { for (; i < nxy; i++) { - self[i] = self[i] CPL_MASK_BINARY_OPER (cpl_binary)second; + self[i] = self[i] CPL_MASK_BINARY_OPER(cpl_binary) second; } - } else { + } + else { for (; i < nxy; i++) { - self[i] = first[i] CPL_MASK_BINARY_OPER (cpl_binary)second; + self[i] = first[i] CPL_MASK_BINARY_OPER(cpl_binary) second; } } } diff -Nru cpl-7.1.4+ds/cplcore/cpl_mask_body.h cpl-7.2.2+ds/cplcore/cpl_mask_body.h --- cpl-7.1.4+ds/cplcore/cpl_mask_body.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_mask_body.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -34,11 +34,14 @@ */ /*----------------------------------------------------------------------------*/ -static void -APPENDSIZE(OPERATION, HX, HY)(cpl_binary * self, const cpl_binary * other, - const cpl_binary * kernel, cpl_size nx, - cpl_size ny, size_t hx, size_t hy, - cpl_border_mode border) +static void APPENDSIZE(OPERATION, HX, HY)(cpl_binary *self, + const cpl_binary *other, + const cpl_binary *kernel, + cpl_size nx, + cpl_size ny, + size_t hx, + size_t hy, + cpl_border_mode border) { if (border == CPL_BORDER_NOP || border == CPL_BORDER_ZERO || border == CPL_BORDER_COPY) { @@ -47,33 +50,33 @@ instruction can process four bytes. This will lead to either a 1 or 3 bytes out of bounds access. So process the last element(s) of the last row(s) one byte at a time. */ - const size_t mxe = 1 + (mx | CPL_MASK_PAD); - const size_t mxout = mxe - mx; /* 1 or 3 out-of-bounds elements */ + const size_t mxe = 1 + (mx | CPL_MASK_PAD); + const size_t mxout = mxe - mx; /* 1 or 3 out-of-bounds elements */ /* Number of out-of-bounds rows */ - const cpl_size myout = 1 + (cpl_size)(mxout-1)/nx; + const cpl_size myout = 1 + (cpl_size)(mxout - 1) / nx; /* Last row w/o out-of-bounds rows */ const cpl_size jstop = ny - (cpl_size)hy - myout; cpl_size i, j; #ifdef GENERAL_CASE - const cpl_size mxew = mxe/CPL_MASK_WORD; + const cpl_size mxew = mxe / CPL_MASK_WORD; #else - const size_t * kernelw = (const size_t *)kernel; + const size_t *kernelw = (const size_t *)kernel; hy = HY; /* Help compiler to optimize */ -#if HX == 2 -#if CPL_MASK_WORD == 4 - assert( hx <= 3); - assert( hx >= 2 ); +#if HX == 2 +#if CPL_MASK_WORD == 4 + assert(hx <= 3); + assert(hx >= 2); #else - assert( hx <= 7); - assert( hx >= 4 ); + assert(hx <= 7); + assert(hx >= 4); #endif #else -#if HX == 1 -#if CPL_MASK_WORD == 4 - assert( hx <= 1); +#if HX == 1 +#if CPL_MASK_WORD == 4 + assert(hx <= 1); #else - assert( hx <= 3); + assert(hx <= 3); #endif #endif #endif @@ -82,26 +85,28 @@ /* Handle border for first hy rows and first hx elements of next row */ if (border == CPL_BORDER_ZERO) { (void)memset(self, CPL_BINARY_0, hx + hy * (size_t)nx); - } else if (border == CPL_BORDER_COPY) { + } + else if (border == CPL_BORDER_COPY) { (void)memcpy(self, other, hx + hy * (size_t)nx); } - self += hy * nx; /* self-col now indexed from -hy to hy */ - other -= hx; /* other-row now indexed from hx */ + self += hy * nx; /* self-col now indexed from -hy to hy */ + other -= hx; /* other-row now indexed from hx */ - for (j = (cpl_size)hy; j < ny-(cpl_size)hy; + for (j = (cpl_size)hy; j < ny - (cpl_size)hy; j++, self += nx, other += nx) { /* The last row(s) can only do a multiple of 4 elements */ - const cpl_size istop = j < jstop ? nx - (cpl_size)hx - : nx - (cpl_size)mxe - (cpl_size)hx; + const cpl_size istop = j < jstop + ? nx - (cpl_size)hx + : nx - (cpl_size)mxe - (cpl_size)hx; if (j > (cpl_size)hy) { /* Do also last hx border elements of previous row */ if (border == CPL_BORDER_ZERO) { (void)memset(self - hx, CPL_BINARY_0, 2 * hx); - } else if (border == CPL_BORDER_COPY) { - (void)memcpy(self - hx, other + hy * (size_t)nx, - 2 * hx); + } + else if (border == CPL_BORDER_COPY) { + (void)memcpy(self - hx, other + hy * (size_t)nx, 2 * hx); } } @@ -111,15 +116,17 @@ /* The last elements one byte at a time :-( */ for (; i < nx - (cpl_size)hx; i++) { - const cpl_binary * otheri = other + i; - const cpl_binary * kernelk = kernel; + const cpl_binary *otheri = other + i; + const cpl_binary *kernelk = kernel; size_t k, l; for (k = 0; k < 1 + 2 * hy; k++, otheri += nx, kernelk += mxe) { for (l = 0; l < 1 + 2 * hx; l++) { - if (OPERATE_PIXEL(otheri[l]) && kernelk[l]) break; + if (OPERATE_PIXEL(otheri[l]) && kernelk[l]) + break; } - if (l < 1 + 2 * hx) break; + if (l < 1 + 2 * hx) + break; } self[i] = k < 1 + 2 * hy ? VALUE_TRUE : VALUE_FALSE; } @@ -128,7 +135,8 @@ /* Do also last hx border elements of previous row */ if (border == CPL_BORDER_ZERO) { (void)memset(self - hx, CPL_BINARY_0, hx + hy * (size_t)nx); - } else if (border == CPL_BORDER_COPY) { + } + else if (border == CPL_BORDER_COPY) { (void)memcpy(self - hx, other + hy * (size_t)nx, hx + hy * (size_t)nx); } diff -Nru cpl-7.1.4+ds/cplcore/cpl_mask.c cpl-7.2.2+ds/cplcore/cpl_mask.c --- cpl-7.1.4+ds/cplcore/cpl_mask.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_mask.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -33,6 +33,7 @@ #include "cpl_io_fits.h" #include "cpl_cfitsio.h" #include "cpl_propertylist_impl.h" +#include "cpl_matrix_impl.h" #include "cpl_math_const.h" /* Verify self-sufficiency of CPL header files by including system files last */ @@ -49,10 +50,10 @@ #include #ifdef __clang__ -# define cpl_m_from_int64 (__m64) -# else -# define cpl_m_from_int64 _m_from_int64 -# endif +#define cpl_m_from_int64 (__m64) +#else +#define cpl_m_from_int64 _m_from_int64 +#endif #endif /*----------------------------------------------------------------------------- @@ -61,9 +62,9 @@ #if defined SIZEOF_SIZE_T && SIZEOF_SIZE_T == 4 /* Maximum half-size that fits in one word */ -#define CPL_MASK_HXW 1 +#define CPL_MASK_HXW 1 /* Maximum half-size that fits in two words */ -#define CPL_MASK_HX2W 3 +#define CPL_MASK_HX2W 3 /* Word-size */ #define CPL_MASK_WORD 4 /* Maximum zero-padding */ @@ -71,20 +72,49 @@ /* Used for computing number of words to span 2hx + 1 */ #define CPL_MASK_DIV 2 /* Used to not a word and via multiplication for population count in one word */ -#define CPL_MASK_NOT (((((((size_t)CPL_BINARY_1<<8) | (size_t)CPL_BINARY_1) <<8) | (size_t)CPL_BINARY_1)<<8) | (size_t)CPL_BINARY_1) +#define CPL_MASK_NOT \ + (((((((size_t)CPL_BINARY_1 << 8) | (size_t)CPL_BINARY_1) << 8) | \ + (size_t)CPL_BINARY_1) \ + << 8) | \ + (size_t)CPL_BINARY_1) #elif defined SIZEOF_SIZE_T && SIZEOF_SIZE_T == 8 #define CPL_MASK_HXW 3 #define CPL_MASK_HX2W 7 #define CPL_MASK_WORD 8 -#define CPL_MASK_PAD 7 -#define CPL_MASK_DIV 4 -#define CPL_MASK_NOT (((((((((((((((size_t)CPL_BINARY_1<<8) | (size_t)CPL_BINARY_1) <<8) | (size_t)CPL_BINARY_1)<<8) | (size_t)CPL_BINARY_1 )<<8)|(size_t)CPL_BINARY_1)<<8) | (size_t)CPL_BINARY_1) <<8) | (size_t)CPL_BINARY_1)<<8) | (size_t)CPL_BINARY_1) +#define CPL_MASK_PAD 7 +#define CPL_MASK_DIV 4 +#define CPL_MASK_NOT \ + (((((((((((((((size_t)CPL_BINARY_1 << 8) | (size_t)CPL_BINARY_1) << 8) | \ + (size_t)CPL_BINARY_1) \ + << 8) | \ + (size_t)CPL_BINARY_1) \ + << 8) | \ + (size_t)CPL_BINARY_1) \ + << 8) | \ + (size_t)CPL_BINARY_1) \ + << 8) | \ + (size_t)CPL_BINARY_1) \ + << 8) | \ + (size_t)CPL_BINARY_1) #endif -#define CPL_MASK_PAD2 ((CPL_MASK_PAD<<1)|1) -#define CPL_MASK_WORD2 (CPL_MASK_WORD<<1) +#define CPL_MASK_PAD2 ((CPL_MASK_PAD << 1) | 1) +#define CPL_MASK_WORD2 (CPL_MASK_WORD << 1) -#define CPL_MASK_NOT8 (((((((((((((((cpl_bitmask)CPL_BINARY_1<<8) | (cpl_bitmask)CPL_BINARY_1) <<8) | (cpl_bitmask)CPL_BINARY_1)<<8) | (cpl_bitmask)CPL_BINARY_1 )<<8)|(cpl_bitmask)CPL_BINARY_1)<<8) | (cpl_bitmask)CPL_BINARY_1) <<8) | (cpl_bitmask)CPL_BINARY_1)<<8) | (cpl_bitmask)CPL_BINARY_1) +#define CPL_MASK_NOT8 \ + (((((((((((((((cpl_bitmask)CPL_BINARY_1 << 8) | (cpl_bitmask)CPL_BINARY_1) \ + << 8) | \ + (cpl_bitmask)CPL_BINARY_1) \ + << 8) | \ + (cpl_bitmask)CPL_BINARY_1) \ + << 8) | \ + (cpl_bitmask)CPL_BINARY_1) \ + << 8) | \ + (cpl_bitmask)CPL_BINARY_1) \ + << 8) | \ + (cpl_bitmask)CPL_BINARY_1) \ + << 8) | \ + (cpl_bitmask)CPL_BINARY_1) #ifdef __SSE2__ #define CPL_MASK_REGISTER_SIZE 16 @@ -101,15 +131,15 @@ /* These macros are needed for support of the different pixel types */ -#define CONCAT(a,b) a ## _ ## b -#define CONCAT2X(a,b) CONCAT(a,b) +#define CONCAT(a, b) a##_##b +#define CONCAT2X(a, b) CONCAT(a, b) /* Multiple concatenation should append the terms starting from the left, */ /* to avoid forming intermediate identifiers that are reserved (e.g. _0_1) */ #define APPENDSIZE(a, b, c) CONCAT2X(CONCAT2X(CONCAT2X(cpl_mask, a), b), c) -#define APPENDOPER(a) CONCAT2X(CONCAT2X(cpl_mask, a), _) -#define APPENDOPERS(a) CONCAT2X(CONCAT2X(cpl_mask, a), scalar) -#define OPER2MM(a) CONCAT2X(CONCAT2X(_mm, a), si128) +#define APPENDOPER(a) CONCAT2X(CONCAT2X(cpl_mask, a), _) +#define APPENDOPERS(a) CONCAT2X(CONCAT2X(cpl_mask, a), scalar) +#define OPER2MM(a) CONCAT2X(CONCAT2X(_mm, a), si128) /*----------------------------------------------------------------------------*/ /** @@ -137,62 +167,83 @@ /*----------------------------------------------------------------------------- Private functions -----------------------------------------------------------------------------*/ -static void cpl_mask_and__(cpl_binary *, - const cpl_binary *, - const cpl_binary *, - size_t) +static void +cpl_mask_and__(cpl_binary *, const cpl_binary *, const cpl_binary *, size_t) #ifdef CPL_HAVE_ATTR_NONNULL -__attribute__((nonnull(1,3))) + __attribute__((nonnull(1, 3))) #endif ; -static void cpl_mask_or__(cpl_binary *, - const cpl_binary *, - const cpl_binary *, - size_t) +static void +cpl_mask_or__(cpl_binary *, const cpl_binary *, const cpl_binary *, size_t) #ifdef CPL_HAVE_ATTR_NONNULL -__attribute__((nonnull(1,3))) + __attribute__((nonnull(1, 3))) #endif ; -static void cpl_mask_xor__(cpl_binary *, - const cpl_binary *, - const cpl_binary *, - size_t) +static void +cpl_mask_xor__(cpl_binary *, const cpl_binary *, const cpl_binary *, size_t) #ifdef CPL_HAVE_ATTR_NONNULL -__attribute__((nonnull(1,3))) + __attribute__((nonnull(1, 3))) #endif ; -static -cpl_mask * cpl_mask_load_one(const char *, cpl_size, cpl_size, cpl_boolean, - cpl_size, cpl_size, cpl_size, cpl_size) - CPL_ATTR_ALLOC; - -static -cpl_mask * cpl_mask_load_(fitsfile*, int*, CPL_FITSIO_TYPE[], const char*, - cpl_size, cpl_size, cpl_boolean, cpl_size, cpl_size, - cpl_size, cpl_size) CPL_ATTR_ALLOC; - -static -void cpl_mask_erosion_(cpl_binary *, const cpl_binary *, const cpl_binary *, - cpl_size, cpl_size, cpl_size, cpl_size, cpl_border_mode) - CPL_ATTR_NONNULL; -static -void cpl_mask_dilation_(cpl_binary *, const cpl_binary *, const cpl_binary *, - cpl_size, cpl_size, cpl_size, cpl_size, cpl_border_mode) - CPL_ATTR_NONNULL; -static -void cpl_mask_opening_(cpl_binary *, const cpl_binary *, const cpl_binary *, - cpl_size, cpl_size, cpl_size, cpl_size, cpl_border_mode) - CPL_ATTR_NONNULL; -static -void cpl_mask_closing_(cpl_binary *, const cpl_binary *, const cpl_binary *, - cpl_size, cpl_size, cpl_size, cpl_size, cpl_border_mode) - CPL_ATTR_NONNULL; +static cpl_mask *cpl_mask_load_one(const char *, + cpl_size, + cpl_size, + cpl_boolean, + cpl_size, + cpl_size, + cpl_size, + cpl_size) CPL_ATTR_ALLOC; + +static cpl_mask *cpl_mask_load_(fitsfile *, + int *, + CPL_FITSIO_TYPE[], + const char *, + cpl_size, + cpl_size, + cpl_boolean, + cpl_size, + cpl_size, + cpl_size, + cpl_size) CPL_ATTR_ALLOC; + +static void cpl_mask_erosion_(cpl_binary *, + const cpl_binary *, + const cpl_binary *, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_border_mode) CPL_ATTR_NONNULL; +static void cpl_mask_dilation_(cpl_binary *, + const cpl_binary *, + const cpl_binary *, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_border_mode) CPL_ATTR_NONNULL; +static void cpl_mask_opening_(cpl_binary *, + const cpl_binary *, + const cpl_binary *, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_border_mode) CPL_ATTR_NONNULL; +static void cpl_mask_closing_(cpl_binary *, + const cpl_binary *, + const cpl_binary *, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_border_mode) CPL_ATTR_NONNULL; -static cpl_mask * cpl_mask_new_from_matrix(const cpl_matrix *, - double) CPL_ATTR_ALLOC; +static cpl_mask * +cpl_mask_new_from_matrix(const cpl_matrix *, double) CPL_ATTR_ALLOC; #define CPL_MASK_BINARY_WOPER and #define CPL_MASK_BINARY_OPER & @@ -225,33 +276,32 @@ #define GENERAL_CASE -#define OPERATION erosion -#define OPERATE_WORD(A) ((A) ^ CPL_MASK_NOT) +#define OPERATION erosion +#define OPERATE_WORD(A) ((A) ^ CPL_MASK_NOT) #define OPERATE_PIXEL(A) (!(A)) -#define VALUE_TRUE CPL_BINARY_0 -#define VALUE_FALSE CPL_BINARY_1 +#define VALUE_TRUE CPL_BINARY_0 +#define VALUE_FALSE CPL_BINARY_1 #define HX n #define HY n -#define CPL_MASK_FILTER_WORD \ - const cpl_binary * otheri = other + i; \ - const size_t * kernelkw = (const size_t *)kernel; \ - size_t k, l; \ - \ - for (k = 0; k < 1 + 2 * hy; k++, otheri += nx, \ - kernelkw += mxew) { \ - /* Points to first element to read */ \ - const size_t * otheriw = (const size_t *)otheri; \ - \ - for (l = 0; l < (hx+CPL_MASK_DIV)/CPL_MASK_DIV; l++) { \ - if (OPERATE_WORD(otheriw[l]) & kernelkw[l]) \ - break; \ - } \ - if (l < (hx+CPL_MASK_DIV)/CPL_MASK_DIV) break; \ - \ - } \ - self[i] = k < 1+ 2 * hy ? VALUE_TRUE : VALUE_FALSE +#define CPL_MASK_FILTER_WORD \ + const cpl_binary *otheri = other + i; \ + const size_t *kernelkw = (const size_t *)kernel; \ + size_t k, l; \ + \ + for (k = 0; k < 1 + 2 * hy; k++, otheri += nx, kernelkw += mxew) { \ + /* Points to first element to read */ \ + const size_t *otheriw = (const size_t *)otheri; \ + \ + for (l = 0; l < (hx + CPL_MASK_DIV) / CPL_MASK_DIV; l++) { \ + if (OPERATE_WORD(otheriw[l]) & kernelkw[l]) \ + break; \ + } \ + if (l < (hx + CPL_MASK_DIV) / CPL_MASK_DIV) \ + break; \ + } \ + self[i] = k < 1 + 2 * hy ? VALUE_TRUE : VALUE_FALSE #include "cpl_mask_body.h" @@ -261,11 +311,11 @@ #undef VALUE_TRUE #undef VALUE_FALSE -#define OPERATION dilation -#define OPERATE_WORD(A) (A) +#define OPERATION dilation +#define OPERATE_WORD(A) (A) #define OPERATE_PIXEL(A) (A) -#define VALUE_TRUE CPL_BINARY_1 -#define VALUE_FALSE CPL_BINARY_0 +#define VALUE_TRUE CPL_BINARY_1 +#define VALUE_FALSE CPL_BINARY_0 #include "cpl_mask_body.h" @@ -283,19 +333,19 @@ #undef HX #undef HY -#define OPERATION erosion -#define OPERATE_WORD(A) ((A) ^ CPL_MASK_NOT) +#define OPERATION erosion +#define OPERATE_WORD(A) ((A) ^ CPL_MASK_NOT) #define OPERATE_PIXEL(A) (!(A)) -#define VALUE_TRUE CPL_BINARY_0 -#define VALUE_FALSE CPL_BINARY_1 +#define VALUE_TRUE CPL_BINARY_0 +#define VALUE_FALSE CPL_BINARY_1 #define HX 1 #define HY 0 #define CPL_MASK_FILTER_WORD \ - self[i] = \ - (OPERATE_WORD(*(const size_t*)(other + i )) & kernelw[0]) \ - ? VALUE_TRUE : VALUE_FALSE + self[i] = (OPERATE_WORD(*(const size_t *)(other + i)) & kernelw[0]) \ + ? VALUE_TRUE \ + : VALUE_FALSE #include "cpl_mask_body.h" @@ -306,11 +356,11 @@ #undef VALUE_FALSE -#define OPERATION dilation -#define OPERATE_WORD(A) (A) +#define OPERATION dilation +#define OPERATE_WORD(A) (A) #define OPERATE_PIXEL(A) (A) -#define VALUE_TRUE CPL_BINARY_1 -#define VALUE_FALSE CPL_BINARY_0 +#define VALUE_TRUE CPL_BINARY_1 +#define VALUE_FALSE CPL_BINARY_0 #include "cpl_mask_body.h" @@ -326,21 +376,23 @@ #undef HX #undef HY -#define OPERATION erosion -#define OPERATE_WORD(A) ((A) ^ CPL_MASK_NOT) +#define OPERATION erosion +#define OPERATE_WORD(A) ((A) ^ CPL_MASK_NOT) #define OPERATE_PIXEL(A) (!(A)) -#define VALUE_TRUE CPL_BINARY_0 -#define VALUE_FALSE CPL_BINARY_1 +#define VALUE_TRUE CPL_BINARY_0 +#define VALUE_FALSE CPL_BINARY_1 #define HX 1 #define HY 1 -#define CPL_MASK_FILTER_WORD \ - self[i] = \ - (OPERATE_WORD(*(const size_t*)(other + i )) & kernelw[0]) || \ - (OPERATE_WORD(*(const size_t*)(other + i + nx )) & kernelw[1]) || \ - (OPERATE_WORD(*(const size_t*)(other + i + nx*2)) & kernelw[2]) \ - ? VALUE_TRUE : VALUE_FALSE +#define CPL_MASK_FILTER_WORD \ + self[i] = (OPERATE_WORD(*(const size_t *)(other + i)) & kernelw[0]) || \ + (OPERATE_WORD(*(const size_t *)(other + i + nx)) & \ + kernelw[1]) || \ + (OPERATE_WORD(*(const size_t *)(other + i + nx * 2)) & \ + kernelw[2]) \ + ? VALUE_TRUE \ + : VALUE_FALSE #include "cpl_mask_body.h" @@ -351,11 +403,11 @@ #undef VALUE_FALSE -#define OPERATION dilation -#define OPERATE_WORD(A) (A) +#define OPERATION dilation +#define OPERATE_WORD(A) (A) #define OPERATE_PIXEL(A) (A) -#define VALUE_TRUE CPL_BINARY_1 -#define VALUE_FALSE CPL_BINARY_0 +#define VALUE_TRUE CPL_BINARY_1 +#define VALUE_FALSE CPL_BINARY_0 #include "cpl_mask_body.h" @@ -371,23 +423,27 @@ #undef HX #undef HY -#define OPERATION erosion -#define OPERATE_WORD(A) ((A) ^ CPL_MASK_NOT) +#define OPERATION erosion +#define OPERATE_WORD(A) ((A) ^ CPL_MASK_NOT) #define OPERATE_PIXEL(A) (!(A)) -#define VALUE_TRUE CPL_BINARY_0 -#define VALUE_FALSE CPL_BINARY_1 +#define VALUE_TRUE CPL_BINARY_0 +#define VALUE_FALSE CPL_BINARY_1 #define HX 1 #define HY 2 -#define CPL_MASK_FILTER_WORD \ - self[i] = \ - (OPERATE_WORD(*(const size_t*)(other + i )) & kernelw[0]) || \ - (OPERATE_WORD(*(const size_t*)(other + i + nx )) & kernelw[1]) || \ - (OPERATE_WORD(*(const size_t*)(other + i + nx*2)) & kernelw[2]) || \ - (OPERATE_WORD(*(const size_t*)(other + i + nx*3)) & kernelw[3]) || \ - (OPERATE_WORD(*(const size_t*)(other + i + nx*4)) & kernelw[4]) \ - ? VALUE_TRUE : VALUE_FALSE +#define CPL_MASK_FILTER_WORD \ + self[i] = (OPERATE_WORD(*(const size_t *)(other + i)) & kernelw[0]) || \ + (OPERATE_WORD(*(const size_t *)(other + i + nx)) & \ + kernelw[1]) || \ + (OPERATE_WORD(*(const size_t *)(other + i + nx * 2)) & \ + kernelw[2]) || \ + (OPERATE_WORD(*(const size_t *)(other + i + nx * 3)) & \ + kernelw[3]) || \ + (OPERATE_WORD(*(const size_t *)(other + i + nx * 4)) & \ + kernelw[4]) \ + ? VALUE_TRUE \ + : VALUE_FALSE #include "cpl_mask_body.h" @@ -398,11 +454,11 @@ #undef VALUE_FALSE -#define OPERATION dilation -#define OPERATE_WORD(A) (A) +#define OPERATION dilation +#define OPERATE_WORD(A) (A) #define OPERATE_PIXEL(A) (A) -#define VALUE_TRUE CPL_BINARY_1 -#define VALUE_FALSE CPL_BINARY_0 +#define VALUE_TRUE CPL_BINARY_1 +#define VALUE_FALSE CPL_BINARY_0 #include "cpl_mask_body.h" @@ -418,25 +474,31 @@ #undef HX #undef HY -#define OPERATION erosion -#define OPERATE_WORD(A) ((A) ^ CPL_MASK_NOT) +#define OPERATION erosion +#define OPERATE_WORD(A) ((A) ^ CPL_MASK_NOT) #define OPERATE_PIXEL(A) (!(A)) -#define VALUE_TRUE CPL_BINARY_0 -#define VALUE_FALSE CPL_BINARY_1 +#define VALUE_TRUE CPL_BINARY_0 +#define VALUE_FALSE CPL_BINARY_1 #define HX 1 #define HY 3 -#define CPL_MASK_FILTER_WORD \ - self[i] = \ - (OPERATE_WORD(*(const size_t*)(other + i )) & kernelw[0]) || \ - (OPERATE_WORD(*(const size_t*)(other + i + nx )) & kernelw[1]) || \ - (OPERATE_WORD(*(const size_t*)(other + i + nx*2)) & kernelw[2]) || \ - (OPERATE_WORD(*(const size_t*)(other + i + nx*3)) & kernelw[3]) || \ - (OPERATE_WORD(*(const size_t*)(other + i + nx*4)) & kernelw[4]) || \ - (OPERATE_WORD(*(const size_t*)(other + i + nx*5)) & kernelw[5]) || \ - (OPERATE_WORD(*(const size_t*)(other + i + nx*6)) & kernelw[6]) \ - ? VALUE_TRUE : VALUE_FALSE +#define CPL_MASK_FILTER_WORD \ + self[i] = (OPERATE_WORD(*(const size_t *)(other + i)) & kernelw[0]) || \ + (OPERATE_WORD(*(const size_t *)(other + i + nx)) & \ + kernelw[1]) || \ + (OPERATE_WORD(*(const size_t *)(other + i + nx * 2)) & \ + kernelw[2]) || \ + (OPERATE_WORD(*(const size_t *)(other + i + nx * 3)) & \ + kernelw[3]) || \ + (OPERATE_WORD(*(const size_t *)(other + i + nx * 4)) & \ + kernelw[4]) || \ + (OPERATE_WORD(*(const size_t *)(other + i + nx * 5)) & \ + kernelw[5]) || \ + (OPERATE_WORD(*(const size_t *)(other + i + nx * 6)) & \ + kernelw[6]) \ + ? VALUE_TRUE \ + : VALUE_FALSE #include "cpl_mask_body.h" @@ -447,11 +509,11 @@ #undef VALUE_FALSE -#define OPERATION dilation -#define OPERATE_WORD(A) (A) +#define OPERATION dilation +#define OPERATE_WORD(A) (A) #define OPERATE_PIXEL(A) (A) -#define VALUE_TRUE CPL_BINARY_1 -#define VALUE_FALSE CPL_BINARY_0 +#define VALUE_TRUE CPL_BINARY_1 +#define VALUE_FALSE CPL_BINARY_0 #include "cpl_mask_body.h" @@ -467,21 +529,22 @@ #undef HX #undef HY -#define OPERATION erosion -#define OPERATE_WORD(A) ((A) ^ CPL_MASK_NOT) +#define OPERATION erosion +#define OPERATE_WORD(A) ((A) ^ CPL_MASK_NOT) #define OPERATE_PIXEL(A) (!(A)) -#define VALUE_TRUE CPL_BINARY_0 -#define VALUE_FALSE CPL_BINARY_1 +#define VALUE_TRUE CPL_BINARY_0 +#define VALUE_FALSE CPL_BINARY_1 #define HX 2 #define HY 0 -#define CPL_MASK_FILTER_WORD \ - self[i] = \ - (OPERATE_WORD(*(const size_t*)(other + i )) & kernelw[0]) || \ - (OPERATE_WORD(*(const size_t*)(other + i + CPL_MASK_WORD)) \ - & kernelw[1]) \ - ? VALUE_TRUE : VALUE_FALSE +#define CPL_MASK_FILTER_WORD \ + self[i] = \ + (OPERATE_WORD(*(const size_t *)(other + i)) & kernelw[0]) || \ + (OPERATE_WORD(*(const size_t *)(other + i + CPL_MASK_WORD)) & \ + kernelw[1]) \ + ? VALUE_TRUE \ + : VALUE_FALSE #include "cpl_mask_body.h" @@ -492,11 +555,11 @@ #undef VALUE_FALSE -#define OPERATION dilation -#define OPERATE_WORD(A) (A) +#define OPERATION dilation +#define OPERATE_WORD(A) (A) #define OPERATE_PIXEL(A) (A) -#define VALUE_TRUE CPL_BINARY_1 -#define VALUE_FALSE CPL_BINARY_0 +#define VALUE_TRUE CPL_BINARY_1 +#define VALUE_FALSE CPL_BINARY_0 #include "cpl_mask_body.h" @@ -512,27 +575,32 @@ #undef HX #undef HY -#define OPERATION erosion -#define OPERATE_WORD(A) ((A) ^ CPL_MASK_NOT) +#define OPERATION erosion +#define OPERATE_WORD(A) ((A) ^ CPL_MASK_NOT) #define OPERATE_PIXEL(A) (!(A)) -#define VALUE_TRUE CPL_BINARY_0 -#define VALUE_FALSE CPL_BINARY_1 +#define VALUE_TRUE CPL_BINARY_0 +#define VALUE_FALSE CPL_BINARY_1 #define HX 2 #define HY 1 -#define CPL_MASK_FILTER_WORD \ - self[i] = \ - (OPERATE_WORD(*(const size_t*)(other + i )) & kernelw[0]) || \ - (OPERATE_WORD(*(const size_t*)(other + i + CPL_MASK_WORD)) \ - & kernelw[1]) || \ - (OPERATE_WORD(*(const size_t*)(other + i + nx )) & kernelw[2]) || \ - (OPERATE_WORD(*(const size_t*)(other + i + nx + CPL_MASK_WORD)) \ - & kernelw[3]) || \ - (OPERATE_WORD(*(const size_t*)(other + i + nx*2)) & kernelw[4]) || \ - (OPERATE_WORD(*(const size_t*)(other + i + nx*2 + CPL_MASK_WORD)) \ - & kernelw[5]) \ - ? VALUE_TRUE : VALUE_FALSE +#define CPL_MASK_FILTER_WORD \ + self[i] = \ + (OPERATE_WORD(*(const size_t *)(other + i)) & kernelw[0]) || \ + (OPERATE_WORD(*(const size_t *)(other + i + CPL_MASK_WORD)) & \ + kernelw[1]) || \ + (OPERATE_WORD(*(const size_t *)(other + i + nx)) & \ + kernelw[2]) || \ + (OPERATE_WORD( \ + *(const size_t *)(other + i + nx + CPL_MASK_WORD)) & \ + kernelw[3]) || \ + (OPERATE_WORD(*(const size_t *)(other + i + nx * 2)) & \ + kernelw[4]) || \ + (OPERATE_WORD( \ + *(const size_t *)(other + i + nx * 2 + CPL_MASK_WORD)) & \ + kernelw[5]) \ + ? VALUE_TRUE \ + : VALUE_FALSE #include "cpl_mask_body.h" @@ -543,11 +611,11 @@ #undef VALUE_FALSE -#define OPERATION dilation -#define OPERATE_WORD(A) (A) +#define OPERATION dilation +#define OPERATE_WORD(A) (A) #define OPERATE_PIXEL(A) (A) -#define VALUE_TRUE CPL_BINARY_1 -#define VALUE_FALSE CPL_BINARY_0 +#define VALUE_TRUE CPL_BINARY_1 +#define VALUE_FALSE CPL_BINARY_0 #include "cpl_mask_body.h" @@ -563,33 +631,42 @@ #undef HX #undef HY -#define OPERATION erosion -#define OPERATE_WORD(A) ((A) ^ CPL_MASK_NOT) +#define OPERATION erosion +#define OPERATE_WORD(A) ((A) ^ CPL_MASK_NOT) #define OPERATE_PIXEL(A) (!(A)) -#define VALUE_TRUE CPL_BINARY_0 -#define VALUE_FALSE CPL_BINARY_1 +#define VALUE_TRUE CPL_BINARY_0 +#define VALUE_FALSE CPL_BINARY_1 #define HX 2 #define HY 2 -#define CPL_MASK_FILTER_WORD \ - self[i] = \ - (OPERATE_WORD(*(const size_t*)(other + i )) & kernelw[0]) || \ - (OPERATE_WORD(*(const size_t*)(other + i + CPL_MASK_WORD)) \ - & kernelw[1]) || \ - (OPERATE_WORD(*(const size_t*)(other + i + nx )) & kernelw[2]) || \ - (OPERATE_WORD(*(const size_t*)(other + i + nx + CPL_MASK_WORD)) \ - & kernelw[3]) || \ - (OPERATE_WORD(*(const size_t*)(other + i + nx*2)) & kernelw[4]) || \ - (OPERATE_WORD(*(const size_t*)(other + i + nx*2 + CPL_MASK_WORD)) \ - & kernelw[5]) || \ - (OPERATE_WORD(*(const size_t*)(other + i + nx*3)) & kernelw[6]) || \ - (OPERATE_WORD(*(const size_t*)(other + i + nx*3 + CPL_MASK_WORD)) \ - & kernelw[7]) || \ - (OPERATE_WORD(*(const size_t*)(other + i + nx*4)) & kernelw[8]) || \ - (OPERATE_WORD(*(const size_t*)(other + i + nx*4 + CPL_MASK_WORD)) \ - & kernelw[9]) \ - ? VALUE_TRUE : VALUE_FALSE +#define CPL_MASK_FILTER_WORD \ + self[i] = \ + (OPERATE_WORD(*(const size_t *)(other + i)) & kernelw[0]) || \ + (OPERATE_WORD(*(const size_t *)(other + i + CPL_MASK_WORD)) & \ + kernelw[1]) || \ + (OPERATE_WORD(*(const size_t *)(other + i + nx)) & \ + kernelw[2]) || \ + (OPERATE_WORD( \ + *(const size_t *)(other + i + nx + CPL_MASK_WORD)) & \ + kernelw[3]) || \ + (OPERATE_WORD(*(const size_t *)(other + i + nx * 2)) & \ + kernelw[4]) || \ + (OPERATE_WORD( \ + *(const size_t *)(other + i + nx * 2 + CPL_MASK_WORD)) & \ + kernelw[5]) || \ + (OPERATE_WORD(*(const size_t *)(other + i + nx * 3)) & \ + kernelw[6]) || \ + (OPERATE_WORD( \ + *(const size_t *)(other + i + nx * 3 + CPL_MASK_WORD)) & \ + kernelw[7]) || \ + (OPERATE_WORD(*(const size_t *)(other + i + nx * 4)) & \ + kernelw[8]) || \ + (OPERATE_WORD( \ + *(const size_t *)(other + i + nx * 4 + CPL_MASK_WORD)) & \ + kernelw[9]) \ + ? VALUE_TRUE \ + : VALUE_FALSE #include "cpl_mask_body.h" @@ -600,11 +677,11 @@ #undef VALUE_FALSE -#define OPERATION dilation -#define OPERATE_WORD(A) (A) +#define OPERATION dilation +#define OPERATE_WORD(A) (A) #define OPERATE_PIXEL(A) (A) -#define VALUE_TRUE CPL_BINARY_1 -#define VALUE_FALSE CPL_BINARY_0 +#define VALUE_TRUE CPL_BINARY_1 +#define VALUE_FALSE CPL_BINARY_0 #include "cpl_mask_body.h" @@ -621,39 +698,52 @@ #undef HX #undef HY -#define OPERATION erosion -#define OPERATE_WORD(A) ((A) ^ CPL_MASK_NOT) +#define OPERATION erosion +#define OPERATE_WORD(A) ((A) ^ CPL_MASK_NOT) #define OPERATE_PIXEL(A) (!(A)) -#define VALUE_TRUE CPL_BINARY_0 -#define VALUE_FALSE CPL_BINARY_1 +#define VALUE_TRUE CPL_BINARY_0 +#define VALUE_FALSE CPL_BINARY_1 #define HX 2 #define HY 3 -#define CPL_MASK_FILTER_WORD \ - self[i] = \ - (OPERATE_WORD(*(const size_t*)(other + i )) & kernelw[0]) || \ - (OPERATE_WORD(*(const size_t*)(other + i + CPL_MASK_WORD)) \ - & kernelw[1]) || \ - (OPERATE_WORD(*(const size_t*)(other + i + nx )) & kernelw[2]) || \ - (OPERATE_WORD(*(const size_t*)(other + i + nx + CPL_MASK_WORD)) \ - & kernelw[3]) || \ - (OPERATE_WORD(*(const size_t*)(other + i + nx*2)) & kernelw[4]) || \ - (OPERATE_WORD(*(const size_t*)(other + i + nx*2 + CPL_MASK_WORD)) \ - & kernelw[5]) || \ - (OPERATE_WORD(*(const size_t*)(other + i + nx*3)) & kernelw[6]) || \ - (OPERATE_WORD(*(const size_t*)(other + i + nx*3 + CPL_MASK_WORD)) \ - & kernelw[7]) || \ - (OPERATE_WORD(*(const size_t*)(other + i + nx*4)) & kernelw[8]) || \ - (OPERATE_WORD(*(const size_t*)(other + i + nx*4 + CPL_MASK_WORD)) \ - & kernelw[9]) || \ - (OPERATE_WORD(*(const size_t*)(other + i + nx*5)) & kernelw[10]) || \ - (OPERATE_WORD(*(const size_t*)(other + i + nx*5 + CPL_MASK_WORD)) \ - & kernelw[11]) || \ - (OPERATE_WORD(*(const size_t*)(other + i + nx*6)) & kernelw[12]) || \ - (OPERATE_WORD(*(const size_t*)(other + i + nx*6 + CPL_MASK_WORD)) \ - & kernelw[13]) \ - ? VALUE_TRUE : VALUE_FALSE +#define CPL_MASK_FILTER_WORD \ + self[i] = \ + (OPERATE_WORD(*(const size_t *)(other + i)) & kernelw[0]) || \ + (OPERATE_WORD(*(const size_t *)(other + i + CPL_MASK_WORD)) & \ + kernelw[1]) || \ + (OPERATE_WORD(*(const size_t *)(other + i + nx)) & \ + kernelw[2]) || \ + (OPERATE_WORD( \ + *(const size_t *)(other + i + nx + CPL_MASK_WORD)) & \ + kernelw[3]) || \ + (OPERATE_WORD(*(const size_t *)(other + i + nx * 2)) & \ + kernelw[4]) || \ + (OPERATE_WORD( \ + *(const size_t *)(other + i + nx * 2 + CPL_MASK_WORD)) & \ + kernelw[5]) || \ + (OPERATE_WORD(*(const size_t *)(other + i + nx * 3)) & \ + kernelw[6]) || \ + (OPERATE_WORD( \ + *(const size_t *)(other + i + nx * 3 + CPL_MASK_WORD)) & \ + kernelw[7]) || \ + (OPERATE_WORD(*(const size_t *)(other + i + nx * 4)) & \ + kernelw[8]) || \ + (OPERATE_WORD( \ + *(const size_t *)(other + i + nx * 4 + CPL_MASK_WORD)) & \ + kernelw[9]) || \ + (OPERATE_WORD(*(const size_t *)(other + i + nx * 5)) & \ + kernelw[10]) || \ + (OPERATE_WORD( \ + *(const size_t *)(other + i + nx * 5 + CPL_MASK_WORD)) & \ + kernelw[11]) || \ + (OPERATE_WORD(*(const size_t *)(other + i + nx * 6)) & \ + kernelw[12]) || \ + (OPERATE_WORD( \ + *(const size_t *)(other + i + nx * 6 + CPL_MASK_WORD)) & \ + kernelw[13]) \ + ? VALUE_TRUE \ + : VALUE_FALSE #include "cpl_mask_body.h" @@ -664,12 +754,12 @@ #undef VALUE_FALSE -#define OPERATION dilation -#define OPERATE_WORD(A) (A) -#define OPERATE_PIXEL(A) (A) -#define OPERATE_AND(A,B) ((A) & (B)) -#define VALUE_TRUE CPL_BINARY_1 -#define VALUE_FALSE CPL_BINARY_0 +#define OPERATION dilation +#define OPERATE_WORD(A) (A) +#define OPERATE_PIXEL(A) (A) +#define OPERATE_AND(A, B) ((A) & (B)) +#define VALUE_TRUE CPL_BINARY_1 +#define VALUE_FALSE CPL_BINARY_0 #include "cpl_mask_body.h" @@ -700,16 +790,17 @@ - CPL_ERROR_ILLEGAL_INPUT if nx or ny is negative */ /*----------------------------------------------------------------------------*/ -cpl_mask * cpl_mask_new(cpl_size nx, cpl_size ny) +cpl_mask * +cpl_mask_new(cpl_size nx, cpl_size ny) { /* Need to validate input for cpl_calloc() */ cpl_ensure(nx > 0, CPL_ERROR_ILLEGAL_INPUT, NULL); cpl_ensure(ny > 0, CPL_ERROR_ILLEGAL_INPUT, NULL); /* Cannot fail now */ - return cpl_mask_wrap(nx, ny, (cpl_binary*)cpl_calloc((size_t)nx - * (size_t)ny, - sizeof(cpl_binary))); + return cpl_mask_wrap(nx, ny, + (cpl_binary *)cpl_calloc((size_t)nx * (size_t)ny, + sizeof(cpl_binary))); } /*----------------------------------------------------------------------------*/ @@ -726,14 +817,15 @@ - CPL_ERROR_ILLEGAL_INPUT if nx or ny is negative or zero */ /*----------------------------------------------------------------------------*/ -cpl_mask * cpl_mask_wrap(cpl_size nx, cpl_size ny, cpl_binary * data) +cpl_mask * +cpl_mask_wrap(cpl_size nx, cpl_size ny, cpl_binary *data) { - cpl_mask * m; + cpl_mask *m; /* Test input */ - cpl_ensure(data != NULL, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(nx > 0, CPL_ERROR_ILLEGAL_INPUT, NULL); - cpl_ensure(ny > 0, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(data != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(nx > 0, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(ny > 0, CPL_ERROR_ILLEGAL_INPUT, NULL); /* Allocate memory */ m = cpl_malloc(sizeof(cpl_mask)); @@ -756,7 +848,8 @@ - CPL_ERROR_NULL_INPUT if in is NULL */ /*----------------------------------------------------------------------------*/ -cpl_mask * cpl_mask_duplicate(const cpl_mask * in) +cpl_mask * +cpl_mask_duplicate(const cpl_mask *in) { if (in != NULL) { /* Create the output mask, cannot fail now */ @@ -781,7 +874,8 @@ */ /*----------------------------------------------------------------------------*/ -void cpl_mask_delete(cpl_mask * m) +void +cpl_mask_delete(cpl_mask *m) { if (m != NULL) { cpl_free(m->data); @@ -799,12 +893,13 @@ */ /*----------------------------------------------------------------------------*/ -void * cpl_mask_unwrap(cpl_mask * m) +void * +cpl_mask_unwrap(cpl_mask *m) { - void * data = NULL; + void *data = NULL; if (m != NULL) { - data = (void *) m->data; + data = (void *)m->data; cpl_free(m); } @@ -823,7 +918,8 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_binary * cpl_mask_get_data(cpl_mask * in) +cpl_binary * +cpl_mask_get_data(cpl_mask *in) { cpl_ensure(in, CPL_ERROR_NULL_INPUT, NULL); return in->data; @@ -837,7 +933,8 @@ @see cpl_mask_get_data */ /*----------------------------------------------------------------------------*/ -const cpl_binary * cpl_mask_get_data_const(const cpl_mask * in) +const cpl_binary * +cpl_mask_get_data_const(const cpl_mask *in) { cpl_ensure(in, CPL_ERROR_NULL_INPUT, NULL); @@ -859,18 +956,17 @@ - CPL_ERROR_ILLEGAL_INPUT if xpos or ypos is out of bounds */ /*----------------------------------------------------------------------------*/ -cpl_binary cpl_mask_get(const cpl_mask * self, - cpl_size xpos, - cpl_size ypos) +cpl_binary +cpl_mask_get(const cpl_mask *self, cpl_size xpos, cpl_size ypos) { /* Test entries */ - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, CPL_BINARY_0); - cpl_ensure(xpos > 0, CPL_ERROR_ILLEGAL_INPUT, CPL_BINARY_0); - cpl_ensure(ypos > 0, CPL_ERROR_ILLEGAL_INPUT, CPL_BINARY_0); + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, CPL_BINARY_0); + cpl_ensure(xpos > 0, CPL_ERROR_ILLEGAL_INPUT, CPL_BINARY_0); + cpl_ensure(ypos > 0, CPL_ERROR_ILLEGAL_INPUT, CPL_BINARY_0); cpl_ensure(xpos <= self->nx, CPL_ERROR_ILLEGAL_INPUT, CPL_BINARY_0); cpl_ensure(ypos <= self->ny, CPL_ERROR_ILLEGAL_INPUT, CPL_BINARY_0); - return self->data[(xpos-1) + (ypos-1) * self->nx]; + return self->data[(xpos - 1) + (ypos - 1) * self->nx]; } /*----------------------------------------------------------------------------*/ @@ -890,21 +986,18 @@ is different from CPL_BINARY_0 and CPL_BINARY_1 */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_mask_set(cpl_mask * self, - cpl_size xpos, - cpl_size ypos, - cpl_binary value) +cpl_error_code +cpl_mask_set(cpl_mask *self, cpl_size xpos, cpl_size ypos, cpl_binary value) { - - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(xpos > 0, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(ypos > 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(xpos > 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(ypos > 0, CPL_ERROR_ILLEGAL_INPUT); cpl_ensure_code(xpos <= self->nx, CPL_ERROR_ILLEGAL_INPUT); cpl_ensure_code(ypos <= self->ny, CPL_ERROR_ILLEGAL_INPUT); cpl_ensure_code(value == CPL_BINARY_0 || value == CPL_BINARY_1, CPL_ERROR_ILLEGAL_INPUT); - self->data[(xpos-1) + (ypos-1) * self->nx] = value; + self->data[(xpos - 1) + (ypos - 1) * self->nx] = value; return CPL_ERROR_NONE; } @@ -919,7 +1012,8 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_mask_get_size_x(const cpl_mask * in) +cpl_size +cpl_mask_get_size_x(const cpl_mask *in) { /* Test entries */ cpl_ensure(in, CPL_ERROR_NULL_INPUT, -1); @@ -936,7 +1030,8 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_mask_get_size_y(const cpl_mask * in) +cpl_size +cpl_mask_get_size_y(const cpl_mask *in) { /* Test entries */ cpl_ensure(in, CPL_ERROR_NULL_INPUT, -1); @@ -962,37 +1057,45 @@ - CPL_ERROR_ILLEGAL_INPUT if the window definition is wrong (e.g llx > urx) */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_mask_dump_window(const cpl_mask * self, cpl_size llx, - cpl_size lly, cpl_size urx, - cpl_size ury, FILE * stream) +cpl_error_code +cpl_mask_dump_window(const cpl_mask *self, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury, + FILE *stream) { const cpl_error_code err = CPL_ERROR_FILE_IO; cpl_size i, j; - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(stream != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(stream != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(llx > 0, CPL_ERROR_ACCESS_OUT_OF_RANGE); - cpl_ensure_code(llx <= urx, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(llx > 0, CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_ensure_code(llx <= urx, CPL_ERROR_ILLEGAL_INPUT); cpl_ensure_code(urx <= self->nx, CPL_ERROR_ACCESS_OUT_OF_RANGE); - cpl_ensure_code(lly > 0, CPL_ERROR_ACCESS_OUT_OF_RANGE); - cpl_ensure_code(lly <= ury, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(lly > 0, CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_ensure_code(lly <= ury, CPL_ERROR_ILLEGAL_INPUT); cpl_ensure_code(ury <= self->ny, CPL_ERROR_ACCESS_OUT_OF_RANGE); - cpl_ensure_code( fprintf(stream, "#----- mask: %" CPL_SIZE_FORMAT - " <= x <= %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT - " <= y <= %" CPL_SIZE_FORMAT " -----\n", - llx, urx, lly, ury) > 0, err); + cpl_ensure_code(fprintf(stream, + "#----- mask: %" CPL_SIZE_FORMAT + " <= x <= %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT + " <= y <= %" CPL_SIZE_FORMAT " -----\n", + llx, urx, lly, ury) > 0, + err); - cpl_ensure_code( fprintf(stream, "\tX\tY\tvalue\n") > 0, err); + cpl_ensure_code(fprintf(stream, "\tX\tY\tvalue\n") > 0, err); for (i = llx; i <= urx; i++) { for (j = lly; j <= ury; j++) { - const cpl_binary value = self->data[(i-1) + (j-1) * self->nx]; - cpl_ensure_code( fprintf(stream, "\t%" CPL_SIZE_FORMAT "\t%" - CPL_SIZE_FORMAT "\t%d\n", i, j, (int)value) - > 0, err); + const cpl_binary value = self->data[(i - 1) + (j - 1) * self->nx]; + cpl_ensure_code(fprintf(stream, + "\t%" CPL_SIZE_FORMAT "\t%" CPL_SIZE_FORMAT + "\t%d\n", + i, j, (int)value) > 0, + err); } } @@ -1011,19 +1114,20 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_boolean cpl_mask_is_empty(const cpl_mask * self) +cpl_boolean +cpl_mask_is_empty(const cpl_mask *self) { - if (self == NULL) { (void)cpl_error_set_(CPL_ERROR_NULL_INPUT); return CPL_FALSE; - } else { - const cpl_size idx = cpl_mask_get_first_window(self, 1, 1, - self->nx, self->ny, - CPL_BINARY_1); + } + else { + const cpl_size idx = cpl_mask_get_first_window(self, 1, 1, self->nx, + self->ny, CPL_BINARY_1); /* Propagate the error, if any */ - if (idx < -1) (void)cpl_error_set_where_(); + if (idx < -1) + (void)cpl_error_set_where_(); return idx == -1 ? CPL_TRUE : CPL_FALSE; } @@ -1044,17 +1148,19 @@ - CPL_ERROR_ILLEGAL_INPUT if the window coordinates are not valid */ /*----------------------------------------------------------------------------*/ -cpl_boolean cpl_mask_is_empty_window(const cpl_mask * self, - cpl_size llx, - cpl_size lly, - cpl_size urx, - cpl_size ury) +cpl_boolean +cpl_mask_is_empty_window(const cpl_mask *self, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury) { - const cpl_size idx = cpl_mask_get_first_window(self, llx, lly, urx, ury, - CPL_BINARY_1); + const cpl_size idx = + cpl_mask_get_first_window(self, llx, lly, urx, ury, CPL_BINARY_1); /* Propagate the error, if any */ - if (idx < -1) (void)cpl_error_set_where_(); + if (idx < -1) + (void)cpl_error_set_where_(); return idx == -1 ? CPL_TRUE : CPL_FALSE; } @@ -1071,14 +1177,13 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_mask_count(const cpl_mask * in) +cpl_size +cpl_mask_count(const cpl_mask *in) { - /* Test inputs */ cpl_ensure(in, CPL_ERROR_NULL_INPUT, -1); return cpl_mask_count_window(in, 1, 1, in->nx, in->ny); - } /*----------------------------------------------------------------------------*/ @@ -1096,26 +1201,27 @@ - CPL_ERROR_ILLEGAL_INPUT if the window coordinates are invalid */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_mask_count_window(const cpl_mask * self, - cpl_size llx, - cpl_size lly, - cpl_size urx, - cpl_size ury) +cpl_size +cpl_mask_count_window(const cpl_mask *self, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury) { /* Point to first row with element(s) to check */ - const cpl_binary * pi - = self ? self->data + (size_t)self->nx * (size_t)(lly-1) : NULL; - cpl_size count = 0; + const cpl_binary *pi = + self ? self->data + (size_t)self->nx * (size_t)(lly - 1) : NULL; + cpl_size count = 0; - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1); - cpl_ensure(llx > 0, CPL_ERROR_ILLEGAL_INPUT, -1); - cpl_ensure(llx <= urx, CPL_ERROR_ILLEGAL_INPUT, -1); - cpl_ensure(urx <= self->nx, CPL_ERROR_ILLEGAL_INPUT, -1); - - cpl_ensure(lly > 0, CPL_ERROR_ILLEGAL_INPUT, -1); - cpl_ensure(lly <= ury, CPL_ERROR_ILLEGAL_INPUT, -1); - cpl_ensure(ury <= self->ny, CPL_ERROR_ILLEGAL_INPUT, -1); + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1); + cpl_ensure(llx > 0, CPL_ERROR_ILLEGAL_INPUT, -1); + cpl_ensure(llx <= urx, CPL_ERROR_ILLEGAL_INPUT, -1); + cpl_ensure(urx <= self->nx, CPL_ERROR_ILLEGAL_INPUT, -1); + + cpl_ensure(lly > 0, CPL_ERROR_ILLEGAL_INPUT, -1); + cpl_ensure(lly <= ury, CPL_ERROR_ILLEGAL_INPUT, -1); + cpl_ensure(ury <= self->ny, CPL_ERROR_ILLEGAL_INPUT, -1); for (cpl_size j = lly - 1; j < ury; j++, pi += self->nx) { @@ -1123,15 +1229,16 @@ #ifdef CPL_MASK_WORD /* FIXME: Should really ensure byte-wise iteration to word-boundary */ for (; i < CPL_MIN(llx - 1 + CPL_MASK_PAD2WORD2(llx - 1), urx); i++) { - if (pi[i] != CPL_BINARY_0) count++; + if (pi[i] != CPL_BINARY_0) + count++; } /* Use multiplication to sum up all one-bytes in one word into the single (most significant byte) using an idea of Julian Taylor. */ - for (; i < (urx & ~CPL_MASK_PAD2); i+= CPL_MASK_WORD2) { - const size_t countz = *(const size_t*)(pi + i) - + *(const size_t*)(pi + i + CPL_MASK_WORD); + for (; i < (urx & ~CPL_MASK_PAD2); i += CPL_MASK_WORD2) { + const size_t countz = *(const size_t *)(pi + i) + + *(const size_t *)(pi + i + CPL_MASK_WORD); - /* Instead of shifting one could also accumulate from an + /* Instead of shifting one could also accumulate from an unsigned character pointing to the MSB of the product, but on one tested 64-bit platform this is not faster. */ count += (countz * CPL_MASK_NOT) >> (CPL_MASK_PAD * 8); @@ -1139,7 +1246,8 @@ /* Count remainder */ #endif for (; i < urx; i++) { - if (pi[i] != CPL_BINARY_0) count++; + if (pi[i] != CPL_BINARY_0) + count++; } } @@ -1159,11 +1267,11 @@ - CPL_ERROR_ILLEGAL_INPUT if the two masks have different sizes */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_mask_and(cpl_mask * in1, - const cpl_mask * in2) +cpl_error_code +cpl_mask_and(cpl_mask *in1, const cpl_mask *in2) { - cpl_ensure_code(in1 != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(in2 != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(in1 != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(in2 != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(in1->nx == in2->nx, CPL_ERROR_INCOMPATIBLE_INPUT); cpl_ensure_code(in1->ny == in2->ny, CPL_ERROR_INCOMPATIBLE_INPUT); @@ -1188,17 +1296,19 @@ - CPL_ERROR_ILLEGAL_INPUT if the two masks have different sizes */ /*----------------------------------------------------------------------------*/ -void cpl_mask_and_(cpl_binary * self, - const cpl_binary * first, - const cpl_binary * second, - size_t nxy) +void +cpl_mask_and_(cpl_binary *self, + const cpl_binary *first, + const cpl_binary *second, + size_t nxy) { - const cpl_binary * myfirst = first ? first : self; + const cpl_binary *myfirst = first ? first : self; if (myfirst != second) { cpl_mask_and__(self, first ? first : NULL, second, nxy); - } else if (first != NULL) { - assert( first == second ); + } + else if (first != NULL) { + assert(first == second); (void)memcpy(self, first, nxy); } } @@ -1216,11 +1326,11 @@ - CPL_ERROR_ILLEGAL_INPUT if the two masks have different sizes */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_mask_or(cpl_mask * in1, - const cpl_mask * in2) +cpl_error_code +cpl_mask_or(cpl_mask *in1, const cpl_mask *in2) { - cpl_ensure_code(in1 != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(in2 != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(in1 != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(in2 != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(in1->nx == in2->nx, CPL_ERROR_INCOMPATIBLE_INPUT); cpl_ensure_code(in1->ny == in2->ny, CPL_ERROR_INCOMPATIBLE_INPUT); @@ -1245,17 +1355,19 @@ - CPL_ERROR_ILLEGAL_INPUT if the two masks have different sizes */ /*----------------------------------------------------------------------------*/ -void cpl_mask_or_(cpl_binary * self, - const cpl_binary * first, - const cpl_binary * second, - size_t nxy) +void +cpl_mask_or_(cpl_binary *self, + const cpl_binary *first, + const cpl_binary *second, + size_t nxy) { - const cpl_binary * myfirst = first ? first : self; + const cpl_binary *myfirst = first ? first : self; if (myfirst != second) { cpl_mask_or__(self, first ? first : NULL, second, nxy); - } else if (first != NULL) { - assert( first == second ); + } + else if (first != NULL) { + assert(first == second); (void)memcpy(self, first, nxy); } } @@ -1274,12 +1386,11 @@ - CPL_ERROR_ILLEGAL_INPUT if the two masks have different sizes */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_mask_xor(cpl_mask * in1, - const cpl_mask * in2) +cpl_error_code +cpl_mask_xor(cpl_mask *in1, const cpl_mask *in2) { - - cpl_ensure_code(in1 != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(in2 != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(in1 != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(in2 != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(in1->nx == in2->nx, CPL_ERROR_INCOMPATIBLE_INPUT); cpl_ensure_code(in1->ny == in2->ny, CPL_ERROR_INCOMPATIBLE_INPUT); @@ -1304,16 +1415,18 @@ - CPL_ERROR_ILLEGAL_INPUT if the two masks have different sizes */ /*----------------------------------------------------------------------------*/ -void cpl_mask_xor_(cpl_binary * self, - const cpl_binary * first, - const cpl_binary * second, - size_t nxy) +void +cpl_mask_xor_(cpl_binary *self, + const cpl_binary *first, + const cpl_binary *second, + size_t nxy) { - const cpl_binary * myfirst = first ? first : self; + const cpl_binary *myfirst = first ? first : self; if (myfirst != second) { cpl_mask_xor__(self, first ? first : NULL, second, nxy); - } else { + } + else { (void)memset(self, 0, nxy); } } @@ -1329,9 +1442,10 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_mask_not(cpl_mask * in) +cpl_error_code +cpl_mask_not(cpl_mask *in) { - cpl_ensure_code(in != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(in != NULL, CPL_ERROR_NULL_INPUT); cpl_mask_xor_scalar(in->data, NULL, CPL_MASK_NOT8, (size_t)(in->nx * in->ny)); @@ -1369,12 +1483,12 @@ - CPL_ERROR_ILLEGAL_INPUT */ /*----------------------------------------------------------------------------*/ -cpl_mask * cpl_mask_collapse_create(const cpl_mask * in, - int dir) +cpl_mask * +cpl_mask_collapse_create(const cpl_mask *in, int dir) { - cpl_mask * out; - const cpl_binary * pin; - cpl_size j; + cpl_mask *out; + const cpl_binary *pin; + cpl_size j; /* Check entries */ cpl_ensure(in != NULL, CPL_ERROR_NULL_INPUT, NULL); @@ -1384,8 +1498,8 @@ /* Check the collapsing direction */ if (dir == 0) { - cpl_binary * pout = (cpl_binary*)cpl_malloc((size_t)in->nx - * sizeof(cpl_binary)); + cpl_binary *pout = + (cpl_binary *)cpl_malloc((size_t)in->nx * sizeof(cpl_binary)); /* Process whole words */ const cpl_size nword = in->nx / (cpl_size)sizeof(size_t); @@ -1393,14 +1507,14 @@ /* This overhead is accepted because in the typical case out will have many CPL_BINARY_0;s, leading to a significant reduction in iterations */ - cpl_size ifirst = 0; - cpl_size ilast = nword-1; /* Can't use unsigned: nword may be zero */ + cpl_size ifirst = 0; + cpl_size ilast = nword - 1; /* Can't use unsigned: nword may be zero */ /* Unlike in perl, in C ?: cannot be used to choose the assignee */ - cpl_size * pfirst = &ifirst; - cpl_size * plast = &ilast; + cpl_size *pfirst = &ifirst; + cpl_size *plast = &ilast; /* Initialize out with 1st row of in */ - size_t * word1 = (size_t*)memcpy(pout, pin, (size_t)in->nx); + size_t *word1 = (size_t *)memcpy(pout, pin, (size_t)in->nx); pin += in->nx; /* To achieve stride-1 access remaining rows of pin are and'ed onto @@ -1408,41 +1522,42 @@ No more iterations are needed if pout is all CPL_BINARY_0. */ for (j = 1; j < in->ny; j++, pin += in->nx) { - const size_t * word2 = (const size_t*)pin; - unsigned donext = 0; /* Done iff out is all _0 */ + const size_t *word2 = (const size_t *)pin; + unsigned donext = 0; /* Done iff out is all _0 */ const cpl_size klast = ilast; /* ilast is updated via plast */ - cpl_size i; + cpl_size i; for (i = ifirst; i < 1 + klast; i++) { /* donext is also used to ensure an update of ifirst the first time a CPL_BINARY_1 is set, and to update ilast for other occurences (including the last one) of CPL_BINARY_1 */ - if ((word1[i] &= word2[i])) *(donext++ ? plast : pfirst) = i; + if ((word1[i] &= word2[i])) + *(donext++ ? plast : pfirst) = i; } /* Typical masks will fall through here */ for (i = nword * (cpl_size)sizeof(size_t); i < in->nx; i++) { - if ((pout[i] &= pin[i])) donext = 1; + if ((pout[i] &= pin[i])) + donext = 1; } - if (!donext) break; + if (!donext) + break; } out = cpl_mask_wrap(in->nx, 1, pout); - - } else if (dir == 1) { - + } + else if (dir == 1) { /* Using memchr() this direction is about three times faster for some 4k by 4k masks on a 32 bit Intel Xeon */ - cpl_binary * pout = (cpl_binary*)cpl_malloc((size_t)in->ny - * sizeof(cpl_binary)); + cpl_binary *pout = + (cpl_binary *)cpl_malloc((size_t)in->ny * sizeof(cpl_binary)); /* Each iteration may do multiple rows. Therefore, if the last computed value is CPL_BINARY_1, j will be 1 + in->ny after the loop */ for (j = 0; j < in->ny; j++) { - /* pfind points to 1st element in the j'th row */ - const cpl_binary * pfind = pin + (size_t)in->nx * (size_t)j; + const cpl_binary *pfind = pin + (size_t)in->nx * (size_t)j; /* szfind is the remaining number of elements to search */ const size_t szfind = (size_t)in->nx * (size_t)(in->ny - j); @@ -1450,28 +1565,30 @@ /* In the worst case the last column is all CPL_BINARY_0, the rest is CPL_BINARY_1, then ny memchr() calls have to be made, each scanning nx elements */ - const cpl_binary * pnext = memchr(pfind, CPL_BINARY_0, szfind); + const cpl_binary *pnext = memchr(pfind, CPL_BINARY_0, szfind); /* Row numbers less than this one are set to CPL_BINARY_1 */ - const cpl_size row0 = pnext != NULL - ? (cpl_size)((size_t)pnext-(size_t)pin) / in->nx : in->ny; + const cpl_size row0 = + pnext != NULL ? (cpl_size)((size_t)pnext - (size_t)pin) / in->nx + : in->ny; for (; j < row0; j++) { pout[j] = CPL_BINARY_1; } /* Unless we are done, collapse the j'th row to CPL_BINARY_0 */ - if (pnext != NULL) pout[j] = CPL_BINARY_0; + if (pnext != NULL) + pout[j] = CPL_BINARY_0; } out = cpl_mask_wrap(1, in->ny, pout); - - } else { + } + else { out = NULL; (void)cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); } - /* out is NULL if dir is illegal */ + /* out is NULL if dir is illegal */ return out; } @@ -1491,20 +1608,21 @@ - CPL_ERROR_NULL_INPUT if the input mask is NULL */ /*----------------------------------------------------------------------------*/ -cpl_mask * cpl_mask_extract(const cpl_mask * in, - cpl_size llx, - cpl_size lly, - cpl_size urx, - cpl_size ury) +cpl_mask * +cpl_mask_extract(const cpl_mask *in, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury) { - cpl_errorstate prestate = cpl_errorstate_get(); - cpl_mask * self = cpl_mask_extract_(in, llx, lly, urx, ury); + cpl_mask *self = cpl_mask_extract_(in, llx, lly, urx, ury); if (self == NULL) { if (cpl_errorstate_is_equal(prestate)) { self = cpl_mask_new(urx - llx + 1, ury - lly + 1); - } else { + } + else { (void)cpl_error_set_where_(); } } @@ -1537,18 +1655,20 @@ - CPL_ERROR_NULL_INPUT if self is NULL */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_mask_turn(cpl_mask * self, int rot) +cpl_error_code +cpl_mask_turn(cpl_mask *self, int rot) { - cpl_mask * loc; - const cpl_binary * ploc; - cpl_binary * pself; - cpl_size i, j; + cpl_mask *loc; + const cpl_binary *ploc; + cpl_binary *pself; + cpl_size i, j; /* Check entries */ cpl_ensure_code(self, CPL_ERROR_NULL_INPUT); rot %= 4; - if (rot < 0) rot += 4; + if (rot < 0) + rot += 4; /* Create the local mask */ @@ -1563,29 +1683,29 @@ case 1: self->nx = loc->ny; self->ny = loc->nx; - pself += ((self->ny)-1)* (self->nx); - for (j=0; j<(self->nx); j++) { - for (i=0; i<(self->ny); i++) { + pself += ((self->ny) - 1) * (self->nx); + for (j = 0; j < (self->nx); j++) { + for (i = 0; i < (self->ny); i++) { *pself = *ploc++; pself -= (self->nx); } - pself += (self->nx)*(self->ny)+1; + pself += (self->nx) * (self->ny) + 1; } break; case 2: - for (i=0; i<(self->nx)*(self->ny); i++) - pself[i] = ploc[(self->ny)*(self->nx)-1-i]; + for (i = 0; i < (self->nx) * (self->ny); i++) + pself[i] = ploc[(self->ny) * (self->nx) - 1 - i]; break; case 3: self->nx = loc->ny; self->ny = loc->nx; - pself += (self->nx)-1; - for (j=0; j<(self->nx); j++) { - for (i=0; i<(self->ny); i++) { + pself += (self->nx) - 1; + for (j = 0; j < (self->nx); j++) { + for (i = 0; i < (self->ny); i++) { *pself = *ploc++; pself += (self->nx); } - pself -= (self->nx)*(self->ny)+1; + pself -= (self->nx) * (self->ny) + 1; } break; default: @@ -1614,15 +1734,15 @@ - CPL_ERROR_ILLEGAL_INPUT if the offsets are too big */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_mask_shift(cpl_mask * self, - cpl_size dx, - cpl_size dy) +cpl_error_code +cpl_mask_shift(cpl_mask *self, cpl_size dx, cpl_size dy) { cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); - return cpl_tools_shift_window(self->data, sizeof(*(self->data)), - self->nx, self->ny, CPL_BINARY_1, dx, dy) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + return cpl_tools_shift_window(self->data, sizeof(*(self->data)), self->nx, + self->ny, CPL_BINARY_1, dx, dy) + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } /*----------------------------------------------------------------------------*/ @@ -1641,22 +1761,23 @@ - CPL_ERROR_ILLEGAL_INPUT if x_pos, y_pos is outside in1 */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_mask_copy(cpl_mask * in1, - const cpl_mask * in2, - cpl_size x_pos, - cpl_size y_pos) -{ - cpl_binary * pin1; - const cpl_binary * pin2; - cpl_size urx, ury; - size_t linesz; +cpl_error_code +cpl_mask_copy(cpl_mask *in1, + const cpl_mask *in2, + cpl_size x_pos, + cpl_size y_pos) +{ + cpl_binary *pin1; + const cpl_binary *pin2; + cpl_size urx, ury; + size_t linesz; /* Test entries */ - cpl_ensure_code(in1 != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(in2 != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(x_pos >= 1, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(in1 != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(in2 != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(x_pos >= 1, CPL_ERROR_ILLEGAL_INPUT); cpl_ensure_code(x_pos <= in1->nx, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(y_pos >= 1, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(y_pos >= 1, CPL_ERROR_ILLEGAL_INPUT); cpl_ensure_code(y_pos <= in1->ny, CPL_ERROR_ILLEGAL_INPUT); /* Define the zone to modify in in1: x_pos, y_pos, urx, ury */ @@ -1666,12 +1787,13 @@ /* Get access to the data */ pin1 = cpl_mask_get_data(in1) + (y_pos - 1) * in1->nx; pin2 = cpl_mask_get_data_const(in2); - linesz = (size_t)(urx - (x_pos-1)) * sizeof(cpl_binary); + linesz = (size_t)(urx - (x_pos - 1)) * sizeof(cpl_binary); if (x_pos == 1 && urx == in1->nx && in1->nx == in2->nx) { /* The zone consists of whole lines in both in1 and in2 */ (void)memcpy(pin1, pin2, (size_t)(ury - (y_pos - 1)) * linesz); - } else { + } + else { cpl_size j; pin1 += (x_pos - 1); @@ -1702,9 +1824,10 @@ - CPL_ERROR_ILLEGAL_INPUT if angle is not as specified */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_mask_flip(cpl_mask * in, int angle) +cpl_error_code +cpl_mask_flip(cpl_mask *in, int angle) { - cpl_binary * pin; + cpl_binary *pin; cpl_size nx, ny; cpl_size i, j; @@ -1719,91 +1842,92 @@ /* Compute the new positions */ /* Switch on the kind of flipping */ switch (angle) { - case 0: { - const size_t rowsize = (size_t)nx * sizeof(cpl_binary); - cpl_binary row[nx]; - cpl_binary * pfirst = pin; - cpl_binary * plast = pin + (ny-1) * nx; - - for (j = 0; j < ny/2; j++, pfirst += nx, plast -= nx) { - (void)memcpy(row, pfirst, rowsize); - (void)memcpy(pfirst, plast, rowsize); - (void)memcpy(plast, row, rowsize); - } - break; - } - case 2: { - - for (j = 0; j < ny; j++, pin += nx) { - for (i = 0; i < nx/2; i++) { - const cpl_binary tmp = pin[i]; - pin[i] = pin[nx-1-i]; - pin[nx-1-i] = tmp; + case 0: { + const size_t rowsize = (size_t)nx * sizeof(cpl_binary); + cpl_binary row[nx]; + cpl_binary *pfirst = pin; + cpl_binary *plast = pin + (ny - 1) * nx; + + for (j = 0; j < ny / 2; j++, pfirst += nx, plast -= nx) { + (void)memcpy(row, pfirst, rowsize); + (void)memcpy(pfirst, plast, rowsize); + (void)memcpy(plast, row, rowsize); } + break; } - break; - } - case 1: { - if (nx == ny) { - cpl_binary * pt = pin; - - for (j = 0; j < nx; j++, pt += nx) { - for (i = 0; i < j; i++) { - const cpl_binary tmp = pt[i]; - pt[i] = pin[j + i * nx]; - pin[j + i * nx] = tmp; + case 2: { + for (j = 0; j < ny; j++, pin += nx) { + for (i = 0; i < nx / 2; i++) { + const cpl_binary tmp = pin[i]; + pin[i] = pin[nx - 1 - i]; + pin[nx - 1 - i] = tmp; + } + } + break; + } + case 1: { + if (nx == ny) { + cpl_binary *pt = pin; + + for (j = 0; j < nx; j++, pt += nx) { + for (i = 0; i < j; i++) { + const cpl_binary tmp = pt[i]; + pt[i] = pin[j + i * nx]; + pin[j + i * nx] = tmp; + } } } - } else { - /* Duplicate the input mask */ - cpl_mask * loc = cpl_mask_duplicate(in); - const cpl_binary * ploc = cpl_mask_get_data_const(loc); - - in->nx = ny; - in->ny = nx; - for (j=0; jnx = ny; + in->ny = nx; + for (j = 0; j < nx; j++) { + for (i = 0; i < ny; i++) { + *pin++ = *ploc; + ploc += nx; + } + ploc -= (nx * ny - 1); } - ploc -= (nx*ny-1); + cpl_mask_delete(loc); } - cpl_mask_delete(loc); + break; } - break; - } - case 3: { - if (nx == ny) { - cpl_binary * pt = pin; - - for (j = 0; j < nx; j++, pt += nx) { - for (i = 0; i < nx - j; i++) { - const cpl_binary tmp = pt[i]; - pt[i] = pin[(nx - 1 - j) + (nx - 1 - i) * nx]; - pin[(nx - 1 - j) + (nx - 1 - i) * nx] = tmp; + case 3: { + if (nx == ny) { + cpl_binary *pt = pin; + + for (j = 0; j < nx; j++, pt += nx) { + for (i = 0; i < nx - j; i++) { + const cpl_binary tmp = pt[i]; + pt[i] = pin[(nx - 1 - j) + (nx - 1 - i) * nx]; + pin[(nx - 1 - j) + (nx - 1 - i) * nx] = tmp; + } } } - } else { - /* Duplicate the input mask */ - cpl_mask * loc = cpl_mask_duplicate(in); - const cpl_binary * ploc = cpl_mask_get_data_const(loc); - - in->nx = ny; - in->ny = nx; - ploc += (nx*ny-1); - for (j=0; jnx = ny; + in->ny = nx; + ploc += (nx * ny - 1); + for (j = 0; j < nx; j++) { + for (i = 0; i < ny; i++) { + *pin++ = *ploc; + ploc -= nx; + } + ploc += (nx * ny - 1); } - ploc += (nx*ny-1); + cpl_mask_delete(loc); } - cpl_mask_delete(loc); + break; } - break; - } - default: - return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); + default: + return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); } return CPL_ERROR_NONE; @@ -1811,35 +1935,36 @@ /*----------------------------------------------------------------------------*/ /** - @brief Reorganize the pixels in a mask - @param in mask to collapse - @param nb_cut the number of cut in x and y - @param new_pos array with the nb_cut^2 new positions + @brief Permute tiles in a mask + @param in Mask to modify + @param nb_cut The number of cuts in x and y + @param new_pos Array with the nb_cut^2 permuted positions @return the #_cpl_error_code_ or CPL_ERROR_NONE @see cpl_image_move() - - nb_cut must be positive and divide the size of the input mask in x and y. + @note The permutation array _must_ contain nb_cut-squared elements Possible #_cpl_error_code_ set in this function: - - CPL_ERROR_NULL_INPUT if in or new_pos is NULL - - CPL_ERROR_ILLEGAL_INPUT if nb_cut is not as requested. + - CPL_ERROR_NULL_INPUT if an input pointer is NULL + - CPL_ERROR_ILLEGAL_INPUT if nb_cut is not strictly positive or cannot + divide one of the image sizes or if the new_pos array does not contain a + permutation of the values from 1 through nb_cut squared. */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_mask_move(cpl_mask * in, - cpl_size nb_cut, - const cpl_size * new_pos) +cpl_error_code +cpl_mask_move(cpl_mask *in, cpl_size nb_cut, const cpl_size *new_pos) { - cpl_size tile_sz_x, tile_sz_y, tile_x, tile_y; - cpl_size npos, opos; - cpl_mask * loc; - const cpl_binary* ploc; - cpl_binary * pin; - cpl_size i, j, k, l; + cpl_size tile_sz_x, tile_sz_y, tile_x, tile_y; + cpl_size npos, opos; + cpl_size *sort_pos; + cpl_mask *loc; + const cpl_binary *ploc; + cpl_binary *pin; + cpl_size i, j, k, l; /* Check entries */ - cpl_ensure_code(in != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(new_pos != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(nb_cut > 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(in != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(new_pos != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(nb_cut > 0, CPL_ERROR_ILLEGAL_INPUT); tile_sz_x = in->nx / nb_cut; tile_sz_y = in->ny / nb_cut; @@ -1847,20 +1972,32 @@ cpl_ensure_code(tile_sz_x * nb_cut == in->nx, CPL_ERROR_ILLEGAL_INPUT); cpl_ensure_code(tile_sz_y * nb_cut == in->ny, CPL_ERROR_ILLEGAL_INPUT); + /* Test that new_pos takes all values between 1 and nb_cut*nb_cut */ + sort_pos = (cpl_size *)cpl_malloc(nb_cut * nb_cut * sizeof(*sort_pos)); + (void)memcpy(sort_pos, new_pos, nb_cut * nb_cut * sizeof(*sort_pos)); + cpl_tools_sort_cplsize(sort_pos, nb_cut * nb_cut); + for (i = 0; i < nb_cut * nb_cut; i++) { + if (sort_pos[i] != i + 1) + break; + } + cpl_free(sort_pos); + cpl_ensure_code(i == nb_cut * nb_cut, CPL_ERROR_ILLEGAL_INPUT); + /* Create local mask */ loc = cpl_mask_duplicate(in); ploc = cpl_mask_get_data_const(loc); pin = cpl_mask_get_data(in); /* Loop to move the pixels */ - for (j=0; jnx * (l+j*tile_sz_y); - npos=(k+tile_x*tile_sz_x) + in->nx * (l+tile_y*tile_sz_y); + for (j = 0; j < nb_cut; j++) { + for (i = 0; i < nb_cut; i++) { + tile_x = (new_pos[i + j * nb_cut] - 1) % nb_cut; + tile_y = (new_pos[i + j * nb_cut] - 1) / nb_cut; + for (l = 0; l < tile_sz_y; l++) { + for (k = 0; k < tile_sz_x; k++) { + opos = (k + i * tile_sz_x) + in->nx * (l + j * tile_sz_y); + npos = (k + tile_x * tile_sz_x) + + in->nx * (l + tile_y * tile_sz_y); pin[npos] = ploc[opos]; } } @@ -1887,29 +2024,28 @@ - CPL_ERROR_ILLEGAL_INPUT if xstep and ystep are not greater than zero */ /*----------------------------------------------------------------------------*/ -cpl_mask *cpl_mask_extract_subsample(const cpl_mask *in, - cpl_size xstep, - cpl_size ystep) -{ - cpl_size new_nx, new_ny; - cpl_mask *out; - cpl_binary *pout; +cpl_mask * +cpl_mask_extract_subsample(const cpl_mask *in, cpl_size xstep, cpl_size ystep) +{ + cpl_size new_nx, new_ny; + cpl_mask *out; + cpl_binary *pout; const cpl_binary *pin; - cpl_size i, j; + cpl_size i, j; - cpl_ensure(in != NULL, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(xstep > 0, CPL_ERROR_ILLEGAL_INPUT, NULL); - cpl_ensure(ystep > 0, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(in != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(xstep > 0, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(ystep > 0, CPL_ERROR_ILLEGAL_INPUT, NULL); - new_nx = (in->nx - 1)/xstep + 1; - new_ny = (in->ny - 1)/ystep + 1; + new_nx = (in->nx - 1) / xstep + 1; + new_ny = (in->ny - 1) / ystep + 1; out = cpl_mask_new(new_nx, new_ny); pin = cpl_mask_get_data_const(in); pout = cpl_mask_get_data(out); - for (j = 0; j < in->ny; j += ystep, pin += ystep*in->nx) + for (j = 0; j < in->ny; j += ystep, pin += ystep * in->nx) for (i = 0; i < in->nx; i += xstep) *pout++ = pin[i]; @@ -1917,7 +2053,6 @@ } - /*----------------------------------------------------------------------------*/ /** @brief Filter a mask using a binary kernel @@ -1993,57 +2128,59 @@ */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_mask_filter(cpl_mask * self, const cpl_mask * other, - const cpl_mask * kernel, - cpl_filter_mode filter, - cpl_border_mode border) +cpl_error_code +cpl_mask_filter(cpl_mask *self, + const cpl_mask *other, + const cpl_mask *kernel, + cpl_filter_mode filter, + cpl_border_mode border) { - /* Modified from cpl_image_filter_mask() :-((((( */ - const cpl_size nsx = cpl_mask_get_size_x(self); - const cpl_size nsy = cpl_mask_get_size_y(self); - const cpl_size nx = cpl_mask_get_size_x(other); - const cpl_size ny = cpl_mask_get_size_y(other); - const cpl_size mx = cpl_mask_get_size_x(kernel); - const cpl_size my = cpl_mask_get_size_y(kernel); + const cpl_size nsx = cpl_mask_get_size_x(self); + const cpl_size nsy = cpl_mask_get_size_y(self); + const cpl_size nx = cpl_mask_get_size_x(other); + const cpl_size ny = cpl_mask_get_size_y(other); + const cpl_size mx = cpl_mask_get_size_x(kernel); + const cpl_size my = cpl_mask_get_size_y(kernel); const cpl_size hsizex = mx >> 1; const cpl_size hsizey = my >> 1; - const cpl_binary * pmask = cpl_mask_get_data_const(kernel); - const cpl_binary * pother = cpl_mask_get_data_const(other); - cpl_binary * pself = cpl_mask_get_data(self); + const cpl_binary *pmask = cpl_mask_get_data_const(kernel); + const cpl_binary *pother = cpl_mask_get_data_const(other); + cpl_binary *pself = cpl_mask_get_data(self); /* assert( sizeof(cpl_binary) == 1 ) */ - const cpl_binary * polast = pother + nx * ny; - const cpl_binary * psrows = pself + nsx * (1 + hsizey); + const cpl_binary *polast = pother + nx * ny; + const cpl_binary *psrows = pself + nsx * (1 + hsizey); /* pmask may not overlap pself at all */ - const cpl_binary * pmlast = pmask + mx * my; - const cpl_binary * pslast = pself + nsx * nsy; + const cpl_binary *pmlast = pmask + mx * my; + const cpl_binary *pslast = pself + nsx * nsy; /* In filtering it is generally faster with a special case for the full kernel. Some tests indicate that this is not the case for mask filtering. This may be due to the typically small kernels - and the simple operations involved. */ void (*filter_func)(cpl_binary *, const cpl_binary *, const cpl_binary *, - cpl_size, cpl_size, cpl_size, cpl_size, - cpl_border_mode) CPL_ATTR_NONNULL; + cpl_size, cpl_size, cpl_size, cpl_size, cpl_border_mode) + CPL_ATTR_NONNULL; - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(other != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(other != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(kernel != NULL, CPL_ERROR_NULL_INPUT); if (filter == CPL_FILTER_OPENING || filter == CPL_FILTER_CLOSING) { - cpl_ensure_code(border == CPL_BORDER_NOP || - border == CPL_BORDER_ZERO || - border == CPL_BORDER_COPY, + cpl_ensure_code(border == CPL_BORDER_NOP || border == CPL_BORDER_ZERO || + border == CPL_BORDER_COPY, CPL_ERROR_UNSUPPORTED_MODE); - } else { + } + else { /* pself has to be above all of the other buffer, or */ /* ...pother has to be above the first hsize+1 rows of pself */ cpl_ensure_code(pself >= polast || pother >= psrows, CPL_ERROR_UNSUPPORTED_MODE); cpl_ensure_code(border == CPL_BORDER_NOP || border == CPL_BORDER_ZERO || - border == CPL_BORDER_COPY, CPL_ERROR_UNSUPPORTED_MODE); + border == CPL_BORDER_COPY, + CPL_ERROR_UNSUPPORTED_MODE); } /* If this check fails, the caller is doing something really weird... */ @@ -2051,8 +2188,8 @@ CPL_ERROR_UNSUPPORTED_MODE); /* Only odd-sized masks allowed */ - cpl_ensure_code((mx&1) == 1, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code((my&1) == 1, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code((mx & 1) == 1, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code((my & 1) == 1, CPL_ERROR_ILLEGAL_INPUT); cpl_ensure_code(mx <= nx, CPL_ERROR_ACCESS_OUT_OF_RANGE); cpl_ensure_code(my <= ny, CPL_ERROR_ACCESS_OUT_OF_RANGE); @@ -2062,14 +2199,13 @@ cpl_ensure_code(nsx == nx - 2 * hsizex, CPL_ERROR_INCOMPATIBLE_INPUT); cpl_ensure_code(nsy == ny - 2 * hsizey, CPL_ERROR_INCOMPATIBLE_INPUT); - - } else + } + else #endif - { + { cpl_ensure_code(nsx == nx, CPL_ERROR_INCOMPATIBLE_INPUT); cpl_ensure_code(nsy == ny, CPL_ERROR_INCOMPATIBLE_INPUT); - } cpl_ensure_code(!cpl_mask_is_empty(kernel), CPL_ERROR_DATA_NOT_FOUND); @@ -2079,31 +2215,33 @@ #ifdef CPL_MASK_NOT if (filter == CPL_FILTER_EROSION) { filter_func = cpl_mask_erosion_; - } else if (filter == CPL_FILTER_DILATION) { + } + else if (filter == CPL_FILTER_DILATION) { filter_func = cpl_mask_dilation_; - } else if (filter == CPL_FILTER_OPENING) { + } + else if (filter == CPL_FILTER_OPENING) { filter_func = cpl_mask_opening_; - } else if (filter == CPL_FILTER_CLOSING) { + } + else if (filter == CPL_FILTER_CLOSING) { filter_func = cpl_mask_closing_; } #endif if (filter_func != NULL) { - /* Pad kernel rows to a multiple of four/eight bytes so each instruction can process four/eight bytes. */ - const cpl_size mxe = 1 + (mx | CPL_MASK_PAD); - cpl_mask * meven = cpl_mask_new(mxe, my); - cpl_binary * even = cpl_mask_get_data(meven); + const cpl_size mxe = 1 + (mx | CPL_MASK_PAD); + cpl_mask *meven = cpl_mask_new(mxe, my); + cpl_binary *even = cpl_mask_get_data(meven); cpl_mask_copy(meven, kernel, 1, 1); filter_func(pself, pother, even, nx, ny, hsizex, hsizey, border); cpl_mask_delete(meven); - - } else { + } + else { return cpl_error_set_message_(CPL_ERROR_UNSUPPORTED_MODE, - "filter=%u. border=%u", - (unsigned)filter, (unsigned)border); + "filter=%u. border=%u", (unsigned)filter, + (unsigned)border); } return CPL_ERROR_NONE; @@ -2122,12 +2260,10 @@ */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_mask_opening( - cpl_mask * in, - const cpl_matrix * ker) +cpl_error_code +cpl_mask_opening(cpl_mask *in, const cpl_matrix *ker) { - - cpl_mask * mask = cpl_mask_new_from_matrix(ker, FLT_MIN); + cpl_mask *mask = cpl_mask_new_from_matrix(ker, FLT_MIN); const cpl_error_code error = cpl_mask_filter(in, in, mask, CPL_FILTER_OPENING, CPL_BORDER_ZERO); @@ -2150,12 +2286,10 @@ */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_mask_closing( - cpl_mask * in, - const cpl_matrix * ker) +cpl_error_code +cpl_mask_closing(cpl_mask *in, const cpl_matrix *ker) { - - cpl_mask * mask = cpl_mask_new_from_matrix(ker, FLT_MIN); + cpl_mask *mask = cpl_mask_new_from_matrix(ker, FLT_MIN); const cpl_error_code error = cpl_mask_filter(in, in, mask, CPL_FILTER_CLOSING, CPL_BORDER_ZERO); @@ -2177,13 +2311,11 @@ */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_mask_erosion( - cpl_mask * in, - const cpl_matrix * ker) +cpl_error_code +cpl_mask_erosion(cpl_mask *in, const cpl_matrix *ker) { - - cpl_mask * mask = cpl_mask_new_from_matrix(ker, FLT_MIN); - cpl_mask * self = cpl_mask_duplicate(in); + cpl_mask *mask = cpl_mask_new_from_matrix(ker, FLT_MIN); + cpl_mask *self = cpl_mask_duplicate(in); const cpl_error_code error = cpl_mask_filter(in, self, mask, CPL_FILTER_EROSION, CPL_BORDER_ZERO); @@ -2206,13 +2338,11 @@ */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_mask_dilation( - cpl_mask * in, - const cpl_matrix * ker) +cpl_error_code +cpl_mask_dilation(cpl_mask *in, const cpl_matrix *ker) { - - cpl_mask * mask = cpl_mask_new_from_matrix(ker, FLT_MIN); - cpl_mask * self = cpl_mask_duplicate(in); + cpl_mask *mask = cpl_mask_new_from_matrix(ker, FLT_MIN); + cpl_mask *self = cpl_mask_duplicate(in); const cpl_error_code error = cpl_mask_filter(in, self, mask, CPL_FILTER_DILATION, CPL_BORDER_ZERO); @@ -2247,24 +2377,25 @@ - CPL_ERROR_ILLEGAL_INPUT if inval is not one of CPL_BINARY_1 or CPL_BINARY_0 */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_mask_threshold_image(cpl_mask * self, - const cpl_image * image, - double lo_cut, double hi_cut, - cpl_binary inval) -{ - - const cpl_size nx = cpl_mask_get_size_x(self); - const cpl_size ny = cpl_mask_get_size_y(self); - const cpl_size npix = nx * ny; - const void * pixels = cpl_image_get_data_const(image); - cpl_binary * bpm = cpl_mask_get_data(self); - const cpl_mask * bmask = cpl_image_get_bpm_const(image); - const cpl_binary * pmask = bmask ? cpl_mask_get_data_const(bmask) : NULL; - const cpl_binary outval = inval == CPL_BINARY_1 ? CPL_BINARY_0 - : CPL_BINARY_1; +cpl_error_code +cpl_mask_threshold_image(cpl_mask *self, + const cpl_image *image, + double lo_cut, + double hi_cut, + cpl_binary inval) +{ + const cpl_size nx = cpl_mask_get_size_x(self); + const cpl_size ny = cpl_mask_get_size_y(self); + const cpl_size npix = nx * ny; + const void *pixels = cpl_image_get_data_const(image); + cpl_binary *bpm = cpl_mask_get_data(self); + const cpl_mask *bmask = cpl_image_get_bpm_const(image); + const cpl_binary *pmask = bmask ? cpl_mask_get_data_const(bmask) : NULL; + const cpl_binary outval = + inval == CPL_BINARY_1 ? CPL_BINARY_0 : CPL_BINARY_1; int i; - cpl_ensure_code(bpm != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(bpm != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(pixels != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(nx == cpl_image_get_size_x(image), @@ -2276,32 +2407,38 @@ /* Switch on the input data type */ switch (cpl_image_get_type(image)) { - case CPL_TYPE_DOUBLE: { - const double * pi = (const double*)pixels; - for (i=0; i < npix; i++) { - bpm[i] = (pmask == NULL || !pmask[i]) && - lo_cut < pi[i] && pi[i] < hi_cut ? inval : outval; - } - break; - } - case CPL_TYPE_FLOAT: { - const float * pi = (const float*)pixels; - for (i=0; i < npix; i++) { - bpm[i] = (pmask == NULL || !pmask[i]) && - lo_cut < pi[i] && pi[i] < hi_cut ? inval : outval; - } - break; - } - case CPL_TYPE_INT: { - const int * pi = (const int*)pixels; - for (i=0; i < npix; i++) { - bpm[i] = (pmask == NULL || !pmask[i]) && - lo_cut < pi[i] && pi[i] < hi_cut ? inval : outval; + case CPL_TYPE_DOUBLE: { + const double *pi = (const double *)pixels; + for (i = 0; i < npix; i++) { + bpm[i] = (pmask == NULL || !pmask[i]) && lo_cut < pi[i] && + pi[i] < hi_cut + ? inval + : outval; + } + break; } - break; - } - default: - return cpl_error_set_(CPL_ERROR_UNSUPPORTED_MODE); + case CPL_TYPE_FLOAT: { + const float *pi = (const float *)pixels; + for (i = 0; i < npix; i++) { + bpm[i] = (pmask == NULL || !pmask[i]) && lo_cut < pi[i] && + pi[i] < hi_cut + ? inval + : outval; + } + break; + } + case CPL_TYPE_INT: { + const int *pi = (const int *)pixels; + for (i = 0; i < npix; i++) { + bpm[i] = (pmask == NULL || !pmask[i]) && lo_cut < pi[i] && + pi[i] < hi_cut + ? inval + : outval; + } + break; + } + default: + return cpl_error_set_(CPL_ERROR_UNSUPPORTED_MODE); } return CPL_ERROR_NONE; @@ -2318,12 +2455,13 @@ */ /*----------------------------------------------------------------------------*/ -cpl_mask * cpl_mask_threshold_image_create(const cpl_image * in, - double lo_cut, - double hi_cut) +cpl_mask * +cpl_mask_threshold_image_create(const cpl_image *in, + double lo_cut, + double hi_cut) { - cpl_mask * self = cpl_mask_new(cpl_image_get_size_x(in), - cpl_image_get_size_y(in)); + cpl_mask *self = + cpl_mask_new(cpl_image_get_size_x(in), cpl_image_get_size_y(in)); if (cpl_mask_threshold_image(self, in, lo_cut, hi_cut, CPL_BINARY_1)) { cpl_error_set_where_(); @@ -2340,7 +2478,7 @@ @brief Save a mask to a FITS file @param self mask to write to disk @param filename Name of the file to write - @param pl Property list for the output header or NULL + @param plist Property list for the output header or NULL @param mode The desired output options @return CPL_ERROR_NONE or the relevant #_cpl_error_code_ on error @see cpl_propertylist_save() @@ -2371,34 +2509,31 @@ - CPL_ERROR_FILE_IO if the data cannot be written to the file */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_mask_save(const cpl_mask * self, - const char * filename, - const cpl_propertylist * pl, - unsigned mode) +cpl_error_code +cpl_mask_save(const cpl_mask *self, + const char *filename, + const cpl_propertylist *plist, + unsigned mode) { - /* FIXME: This code is a simplification of cpl_image_save() */ cpl_error_code error = CPL_ERROR_NONE; - fitsfile * fptr; - int fio_status=0; - const char * badkeys = mode & CPL_IO_EXTEND - ? CPL_FITS_BADKEYS_EXT "|" CPL_FITS_COMPRKEYS - : CPL_FITS_BADKEYS_PRIM "|" CPL_FITS_COMPRKEYS; - CPL_FITSIO_TYPE naxes[2]; + fitsfile *fptr; + int fio_status = 0; + CPL_FITSIO_TYPE naxes[2]; /* Count number of compression flags */ const unsigned ncompress = ((mode & CPL_IO_COMPRESS_GZIP) != 0) + - ((mode & CPL_IO_COMPRESS_HCOMPRESS) != 0) + - ((mode & CPL_IO_COMPRESS_PLIO) != 0) + - ((mode & CPL_IO_COMPRESS_RICE) != 0); + ((mode & CPL_IO_COMPRESS_HCOMPRESS) != 0) + + ((mode & CPL_IO_COMPRESS_PLIO) != 0) + + ((mode & CPL_IO_COMPRESS_RICE) != 0); - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(filename != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(((mode & CPL_IO_CREATE) != 0) ^ - ((mode & CPL_IO_EXTEND) != 0), + cpl_ensure_code(((mode & CPL_IO_CREATE) != 0) ^ + ((mode & CPL_IO_EXTEND) != 0), CPL_ERROR_ILLEGAL_INPUT); cpl_ensure_code(mode < CPL_IO_MAX, CPL_ERROR_ILLEGAL_INPUT); @@ -2407,7 +2542,6 @@ naxes[1] = self->ny; if (mode & CPL_IO_EXTEND) { - /* Only one type of compression is allowed */ cpl_ensure_code(ncompress <= 1, CPL_ERROR_ILLEGAL_INPUT); @@ -2416,17 +2550,16 @@ if (fio_status != 0) { return cpl_error_set_fits(CPL_ERROR_FILE_IO, fio_status, fits_open_diskfile, - "filename='%s', mode=%d", - filename, mode); + "filename='%s', mode=%d", filename, mode); } - if (mode & CPL_IO_COMPRESS_GZIP) + if (mode & CPL_IO_COMPRESS_GZIP) fits_set_compression_type(fptr, GZIP_1, &fio_status); - else if (mode & CPL_IO_COMPRESS_HCOMPRESS) + else if (mode & CPL_IO_COMPRESS_HCOMPRESS) fits_set_compression_type(fptr, HCOMPRESS_1, &fio_status); - else if (mode & CPL_IO_COMPRESS_PLIO) + else if (mode & CPL_IO_COMPRESS_PLIO) fits_set_compression_type(fptr, PLIO_1, &fio_status); - else if (mode & CPL_IO_COMPRESS_RICE) + else if (mode & CPL_IO_COMPRESS_RICE) fits_set_compression_type(fptr, RICE_1, &fio_status); if (fio_status != 0) { @@ -2435,15 +2568,16 @@ return cpl_error_set_fits(CPL_ERROR_FILE_IO, fio_status, fits_set_compression_type, - "filename='%s', mode=%d", - filename, mode); + "filename='%s', mode=%d", filename, mode); } - } else if (ncompress > 0) { + } + else if (ncompress > 0) { /* Compression is only allowed in extensions */ return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); - } else { + } + else { /* Create the file */ - char * sval = cpl_sprintf("!%s", filename); + char *sval = cpl_sprintf("!%s", filename); cpl_io_fits_create_file(&fptr, sval, &fio_status); cpl_free(sval); @@ -2451,22 +2585,26 @@ int fio_status2 = 0; cpl_io_fits_close_file(fptr, &fio_status2); return cpl_error_set_fits(CPL_ERROR_FILE_IO, fio_status, - fits_create_file, "filename='%s', " - "mode=%d", filename, mode); + fits_create_file, + "filename='%s', " + "mode=%d", + filename, mode); } } /* Save the data in a new HDU appended to the file */ CPL_FITSIO_CREATE_IMG(fptr, BYTE_IMG, 2, naxes, &fio_status); - + if (fio_status != 0) { int fio_status2 = 0; cpl_io_fits_close_file(fptr, &fio_status2); return cpl_error_set_fits(CPL_ERROR_FILE_IO, fio_status, - CPL_FITSIO_CREATE_IMG_E, "filename='%s', " - "mode=%d", filename, mode); + CPL_FITSIO_CREATE_IMG_E, + "filename='%s', " + "mode=%d", + filename, mode); } - + if (mode & CPL_IO_CREATE) { /* Add DATE */ fits_write_date(fptr, &fio_status); @@ -2474,25 +2612,29 @@ int fio_status2 = 0; cpl_io_fits_close_file(fptr, &fio_status2); return cpl_error_set_fits(CPL_ERROR_FILE_IO, fio_status, - fits_write_date, "filename='%s', " - "mode=%d", filename, mode); + fits_write_date, + "filename='%s', " + "mode=%d", + filename, mode); } } /* Add the property list */ - if (cpl_fits_add_properties(fptr, pl, badkeys) != CPL_ERROR_NONE) { + if (cpl_fits_add_properties(fptr, plist, mode, CPL_FALSE)) { cpl_io_fits_close_file(fptr, &fio_status); return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); } /* Write the pixels */ fits_write_img(fptr, TBYTE, 1, (LONGLONG)self->nx * (LONGLONG)self->ny, - (void*)self->data, &fio_status); + (void *)self->data, &fio_status); if (fio_status != 0) { - error = cpl_error_set_fits(CPL_ERROR_FILE_IO, fio_status, - fits_write_img, "filename='%s', " - "mode=%d", filename, mode); + error = + cpl_error_set_fits(CPL_ERROR_FILE_IO, fio_status, fits_write_img, + "filename='%s', " + "mode=%d", + filename, mode); fio_status = 0; } @@ -2501,11 +2643,13 @@ /* Check */ if (fio_status != 0) { - error = cpl_error_set_fits(CPL_ERROR_FILE_IO, fio_status, - fits_close_file, "filename='%s', " - "mode=%d", filename, mode); + error = + cpl_error_set_fits(CPL_ERROR_FILE_IO, fio_status, fits_close_file, + "filename='%s', " + "mode=%d", + filename, mode); } - + return error; } @@ -2538,14 +2682,14 @@ - CPL_ERROR_DATA_NOT_FOUND if the specified extension has no mask data */ /*----------------------------------------------------------------------------*/ -cpl_mask * cpl_mask_load(const char * filename, - cpl_size pnum, - cpl_size xtnum) +cpl_mask * +cpl_mask_load(const char *filename, cpl_size pnum, cpl_size xtnum) { - cpl_mask * self = cpl_mask_load_one(filename, pnum, xtnum, - CPL_FALSE, 0, 0, 0, 0); + cpl_mask *self = + cpl_mask_load_one(filename, pnum, xtnum, CPL_FALSE, 0, 0, 0, 0); - if (self == NULL) (void)cpl_error_set_where_(); + if (self == NULL) + (void)cpl_error_set_where_(); return self; } @@ -2570,22 +2714,22 @@ - CPL_ERROR_ILLEGAL_INPUT if the passed position is invalid */ /*----------------------------------------------------------------------------*/ -cpl_mask * cpl_mask_load_window(const char * filename, - cpl_size pnum, - cpl_size xtnum, - cpl_size llx, - cpl_size lly, - cpl_size urx, - cpl_size ury) +cpl_mask * +cpl_mask_load_window(const char *filename, + cpl_size pnum, + cpl_size xtnum, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury) { + cpl_mask *self = + cpl_mask_load_one(filename, pnum, xtnum, CPL_TRUE, llx, lly, urx, ury); - cpl_mask * self = cpl_mask_load_one(filename, pnum, xtnum, - CPL_TRUE, llx, lly, urx, ury); - - if (self == NULL) (void)cpl_error_set_where_(); + if (self == NULL) + (void)cpl_error_set_where_(); return self; - } @@ -2607,21 +2751,22 @@ */ /*----------------------------------------------------------------------------*/ -void cpl_mask_fill_window(cpl_mask * self, - cpl_size llx, - cpl_size lly, - cpl_size urx, - cpl_size ury, - cpl_binary value) +void +cpl_mask_fill_window(cpl_mask *self, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury, + cpl_binary value) { if (llx == 1 && urx == self->nx) { (void)memset(self->data + (size_t)self->nx * (size_t)(lly - 1), value, (size_t)(self->nx * (1 + ury - lly)) * sizeof(cpl_binary)); - - } else { + } + else { for (cpl_size j = lly; j <= ury; j++) { (void)memset(self->data + (size_t)(self->nx * (j - 1) + llx - 1), - value, (size_t)(1 + urx -llx) * sizeof(cpl_binary)); + value, (size_t)(1 + urx - llx) * sizeof(cpl_binary)); } } } @@ -2641,22 +2786,23 @@ */ /*----------------------------------------------------------------------------*/ -cpl_mask * cpl_mask_extract_(const cpl_mask * in, - cpl_size llx, - cpl_size lly, - cpl_size urx, - cpl_size ury) +cpl_mask * +cpl_mask_extract_(const cpl_mask *in, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury) { - const cpl_size first = cpl_mask_get_first_window(in, llx, lly, urx, ury, - CPL_BINARY_1); + const cpl_size first = + cpl_mask_get_first_window(in, llx, lly, urx, ury, CPL_BINARY_1); if (first >= 0) { /* first is the number of good (zero) elements before the first bad */ const cpl_size nx = urx - llx + 1; const cpl_size ny = ury - lly + 1; /* Create the buffer of the extracted mask */ - cpl_binary *pout = (cpl_binary*)cpl_malloc((size_t)(nx * ny) - * sizeof(*pout)); + cpl_binary *pout = + (cpl_binary *)cpl_malloc((size_t)(nx * ny) * sizeof(*pout)); if (first > 0) { (void)memset(pout, 0, first * sizeof(cpl_binary)); @@ -2667,13 +2813,14 @@ (void)memcpy(pout + first, in->data + first + (size_t)in->nx * (size_t)(lly - 1), (size_t)(nx * ny - first) * sizeof(cpl_binary)); - } else { - const cpl_size my = first / nx; /* Whole zero-rows copied */ + } + else { + const cpl_size my = first / nx; /* Whole zero-rows copied */ const cpl_size part = first - nx * my; /* Partially copied row */ - const cpl_binary * pin = in->data + (llx - 1) - + (size_t)in->nx * (size_t)(lly - 1 + my); - cpl_binary * pj = pout + nx * my; - cpl_size j = my; + const cpl_binary *pin = + in->data + (llx - 1) + (size_t)in->nx * (size_t)(lly - 1 + my); + cpl_binary *pj = pout + nx * my; + cpl_size j = my; if (part > 0) { /* Complete partial row */ @@ -2681,7 +2828,7 @@ (size_t)(nx - part) * sizeof(cpl_binary)); j++; pin += in->nx; - pj += nx; + pj += nx; } /* Loop over the rows to extract */ @@ -2691,7 +2838,8 @@ } return cpl_mask_wrap(nx, ny, pout); - } else if (first < -1) { + } + else if (first < -1) { (void)cpl_error_set_where_(); } @@ -2714,29 +2862,29 @@ @see cpl_mask_load() */ /*----------------------------------------------------------------------------*/ -static cpl_mask * cpl_mask_load_one(const char * filename, - cpl_size pnum, - cpl_size xtnum, - cpl_boolean do_window, - cpl_size llx, - cpl_size lly, - cpl_size urx, - cpl_size ury) +static cpl_mask * +cpl_mask_load_one(const char *filename, + cpl_size pnum, + cpl_size xtnum, + cpl_boolean do_window, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury) { - /* FIXME: This code is a simplification of cpl_image_load_one() */ - int error = 0; - int naxis = 0; + int error = 0; + int naxis = 0; /* May read from Data Unit w. NAXIS=[23] */ - CPL_FITSIO_TYPE naxes[3] ={0, 0, 0}; - fitsfile * fptr; - cpl_mask * self; + CPL_FITSIO_TYPE naxes[3] = { 0, 0, 0 }; + fitsfile *fptr; + cpl_mask *self; /* FIXME: Version 3.24 of fits_open_diskfile() seg-faults on NULL. If ever fixed in CFITSIO, this check should be removed */ cpl_ensure(filename != NULL, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(xtnum >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(xtnum >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL); if (cpl_io_fits_open_diskfile(&fptr, filename, READONLY, &error)) { /* If the file did not exist: error = 104 (FILE_NOT_OPENED) */ @@ -2750,17 +2898,19 @@ return NULL; } - self = cpl_mask_load_(fptr, &naxis, naxes, filename, pnum, - xtnum, do_window, llx, lly, urx, ury); + self = cpl_mask_load_(fptr, &naxis, naxes, filename, pnum, xtnum, do_window, + llx, lly, urx, ury); if (cpl_io_fits_close_file(fptr, &error)) { cpl_mask_delete(self); self = NULL; (void)cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, error, - fits_close_file, "filename='%s', pnum=%" - CPL_SIZE_FORMAT ", xtnum=%" CPL_SIZE_FORMAT, + fits_close_file, + "filename='%s', pnum=%" CPL_SIZE_FORMAT + ", xtnum=%" CPL_SIZE_FORMAT, filename, pnum, xtnum); - } else if (self == NULL) { + } + else if (self == NULL) { cpl_error_set_where_(); } @@ -2806,43 +2956,44 @@ */ /*----------------------------------------------------------------------------*/ -cpl_mask * cpl_mask_load_(fitsfile * fptr, - int * pnaxis, - CPL_FITSIO_TYPE naxes[], - const char * filename, - cpl_size pnum, - cpl_size lhdumov, - cpl_boolean do_window, - cpl_size llx, - cpl_size lly, - cpl_size urx, - cpl_size ury) +cpl_mask * +cpl_mask_load_(fitsfile *fptr, + int *pnaxis, + CPL_FITSIO_TYPE naxes[], + const char *filename, + cpl_size pnum, + cpl_size lhdumov, + cpl_boolean do_window, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury) { - /* FIXME: This code is a simplification of cpl_image_load_() */ - const int hdumov = (int)lhdumov; - int error = 0; - cpl_mask * self; - cpl_binary * pixels; - const long int inc[3] = {1, 1, 1}; - long int fpixel[3]; - long int lpixel[3]; - cpl_size nx, ny; - size_t i; - - cpl_ensure(fptr != NULL, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(pnaxis != NULL, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(naxes != NULL, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(filename != NULL, CPL_ERROR_NULL_INPUT, NULL); + const int hdumov = (int)lhdumov; + int error = 0; + cpl_mask *self; + cpl_binary *pixels; + const long int inc[3] = { 1, 1, 1 }; + long int fpixel[3]; + long int lpixel[3]; + cpl_size nx, ny; + size_t i; + + cpl_ensure(fptr != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(pnaxis != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(naxes != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(filename != NULL, CPL_ERROR_NULL_INPUT, NULL); /* CFITSIO only supports int */ - cpl_ensure((cpl_size)(1+hdumov) == 1+lhdumov, CPL_ERROR_ILLEGAL_INPUT, + cpl_ensure((cpl_size)(1 + hdumov) == 1 + lhdumov, CPL_ERROR_ILLEGAL_INPUT, NULL); - if (hdumov >= 0 && fits_movabs_hdu(fptr, 1+hdumov, NULL, &error)) { + if (hdumov >= 0 && fits_movabs_hdu(fptr, 1 + hdumov, NULL, &error)) { (void)cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, error, - fits_movabs_hdu, "filename='%s', pnum=%" - CPL_SIZE_FORMAT ", " "hdumov=%d", + fits_movabs_hdu, + "filename='%s', pnum=%" CPL_SIZE_FORMAT ", " + "hdumov=%d", filename, pnum, hdumov); return NULL; } @@ -2850,16 +3001,17 @@ /* Get NAXIS, if needed */ if (*pnaxis == 0 && fits_get_img_dim(fptr, pnaxis, &error)) { (void)cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, error, - fits_get_img_dim, "filename='%s', pnum=%" - CPL_SIZE_FORMAT ", hdumov=%d", + fits_get_img_dim, + "filename='%s', pnum=%" CPL_SIZE_FORMAT + ", hdumov=%d", filename, pnum, hdumov); return NULL; } /* Verify NAXIS before trying anything else */ if (*pnaxis != 2 && *pnaxis != 3) { (void)cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, - "filename='%s', pnum=%" CPL_SIZE_FORMAT - ", hdumov=%d, NAXIS=%d", + "filename='%s', pnum=%" CPL_SIZE_FORMAT + ", hdumov=%d, NAXIS=%d", filename, pnum, hdumov, *pnaxis); return NULL; } @@ -2867,9 +3019,11 @@ /* Get NAXIS[12[3]], if needed */ if (naxes[0] == 0 && CPL_FITSIO_GET_SIZE(fptr, *pnaxis, naxes, &error)) { (void)cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, error, - CPL_FITSIO_GET_SIZE, "filename='%s', " + CPL_FITSIO_GET_SIZE, + "filename='%s', " "pnum=%" CPL_SIZE_FORMAT ", hdumov=%d, " - "NAXIS=%d", filename, pnum, hdumov, *pnaxis); + "NAXIS=%d", + filename, pnum, hdumov, *pnaxis); return NULL; } @@ -2877,16 +3031,17 @@ if (naxes[0] == 0 || naxes[1] == 0) { /* FIXME: Is this actually possible with a non-zero NAXIS ? */ (void)cpl_error_set_message_(CPL_ERROR_INCOMPATIBLE_INPUT, - "filename='%s', pnum=%" CPL_SIZE_FORMAT + "filename='%s', pnum=%" CPL_SIZE_FORMAT ", hdumov=%d, NAXIS=%d, NAXIS1=%ld, " - "NAXIS2=%ld", filename, pnum, hdumov, - *pnaxis, (long)naxes[0], (long)naxes[1]); + "NAXIS2=%ld", + filename, pnum, hdumov, *pnaxis, + (long)naxes[0], (long)naxes[1]); return NULL; } if (*pnaxis == 3 && naxes[2] == 0) { /* FIXME: Is this actually possible with a non-zero NAXIS ? */ (void)cpl_error_set_message_(CPL_ERROR_INCOMPATIBLE_INPUT, - "filename='%s', pnum=%" CPL_SIZE_FORMAT + "filename='%s', pnum=%" CPL_SIZE_FORMAT ", hdumov=%d, NAXIS=%d, NAXIS1=%ld, " "NAXIS2=%ld NAXIS3=0", filename, pnum, hdumov, *pnaxis, @@ -2898,22 +3053,23 @@ /* Verify the window size */ /* If the naxes[] passed is from a previous succesful call here, then this check is redundant. Don't rely on that. */ - if (llx < 1 || lly < 1 || urx > naxes[0] || ury > naxes[1] - || urx < llx || ury < lly) { + if (llx < 1 || lly < 1 || urx > naxes[0] || ury > naxes[1] || + urx < llx || ury < lly) { (void)cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, - "filename='%s', pnum=%" - CPL_SIZE_FORMAT ", hdumov=%d, " + "filename='%s', pnum=%" CPL_SIZE_FORMAT + ", hdumov=%d, " "llx=%" CPL_SIZE_FORMAT ", " "lly=%" CPL_SIZE_FORMAT ", " "urx=%" CPL_SIZE_FORMAT ", " "ury=%" CPL_SIZE_FORMAT ", " "NAXIS=%d, NAXIS1=%ld, NAXIS2=%ld", - filename, pnum, hdumov, llx, lly, - urx, ury, *pnaxis, (long)naxes[0], + filename, pnum, hdumov, llx, lly, urx, + ury, *pnaxis, (long)naxes[0], (long)naxes[1]); return NULL; } - } else { + } + else { llx = lly = 1; urx = naxes[0]; ury = naxes[1]; @@ -2925,39 +3081,42 @@ lpixel[0] = urx; lpixel[1] = ury; if (*pnaxis == 3) { - /* Verify plane number */ if (pnum + 1 > naxes[2]) { (void)cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, "filename='%s', pnum=%" CPL_SIZE_FORMAT ", hdumov=%d, NAXIS=3, NAXIS1=%ld, " - "NAXIS2=%ld, NAXIS3=%ld", filename, - pnum, hdumov, (long)naxes[0], + "NAXIS2=%ld, NAXIS3=%ld", + filename, pnum, hdumov, (long)naxes[0], (long)naxes[1], (long)naxes[2]); return NULL; } fpixel[2] = lpixel[2] = pnum + 1; - } else if (pnum != 0) { + } + else if (pnum != 0) { /* May not ask for any plane but the first when NAXIS == 2 */ (void)cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, - "filename='%s', pnum=%" CPL_SIZE_FORMAT + "filename='%s', pnum=%" CPL_SIZE_FORMAT ", hdumov=%d, NAXIS=%d, NAXIS1=%ld, " - "NAXIS2=%ld", filename, pnum, hdumov, - *pnaxis, (long)naxes[0], (long)naxes[1]); + "NAXIS2=%ld", + filename, pnum, hdumov, *pnaxis, + (long)naxes[0], (long)naxes[1]); return NULL; } nx = urx - llx + 1; ny = ury - lly + 1; - pixels = (cpl_binary*)cpl_malloc((size_t)nx * (size_t)ny * sizeof(*pixels)); + pixels = + (cpl_binary *)cpl_malloc((size_t)nx * (size_t)ny * sizeof(*pixels)); - if (cpl_fits_read_subset(fptr, TBYTE, fpixel, lpixel, inc, - NULL, pixels, NULL, &error)) { + if (cpl_fits_read_subset(fptr, TBYTE, fpixel, lpixel, inc, NULL, pixels, + NULL, &error)) { cpl_free(pixels); (void)cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, error, - fits_read_subset, "filename='%s', " + fits_read_subset, + "filename='%s', " "pnum=%" CPL_SIZE_FORMAT ", hdumov=%d, " "NAXIS=%d, NAXIS1=%ld, NAXIS2=%ld", filename, pnum, hdumov, *pnaxis, @@ -2997,42 +3156,45 @@ - CPL_ERROR_ILLEGAL_INPUT if the window coordinates are not valid */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_mask_get_first_window(const cpl_mask * self, - cpl_size llx, - cpl_size lly, - cpl_size urx, - cpl_size ury, - cpl_binary value) +cpl_size +cpl_mask_get_first_window(const cpl_mask *self, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury, + cpl_binary value) { + const cpl_binary *pi; + const cpl_binary *found; - const cpl_binary * pi; - const cpl_binary * found; - - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -2); + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -2); - cpl_ensure(llx <= urx, CPL_ERROR_ILLEGAL_INPUT, -3); - cpl_ensure(llx > 0, CPL_ERROR_ILLEGAL_INPUT, -4); + cpl_ensure(llx <= urx, CPL_ERROR_ILLEGAL_INPUT, -3); + cpl_ensure(llx > 0, CPL_ERROR_ILLEGAL_INPUT, -4); cpl_ensure(urx <= self->nx, CPL_ERROR_ILLEGAL_INPUT, -5); - cpl_ensure(lly <= ury, CPL_ERROR_ILLEGAL_INPUT, -6); - cpl_ensure(lly > 0, CPL_ERROR_ILLEGAL_INPUT, -7); + cpl_ensure(lly <= ury, CPL_ERROR_ILLEGAL_INPUT, -6); + cpl_ensure(lly > 0, CPL_ERROR_ILLEGAL_INPUT, -7); cpl_ensure(ury <= self->ny, CPL_ERROR_ILLEGAL_INPUT, -8); /* Point to 1st element in first row to read */ - pi = self->data + (lly-1)*self->nx + llx - 1; + pi = self->data + (lly - 1) * self->nx + llx - 1; if (llx == 1 && urx == self->nx) { /* Special case: Window extends to left and right mask border */ - found = memchr(pi, value, - (size_t)self->nx * (size_t)(ury-lly+1) * sizeof(*pi)); - } else { - const cpl_binary * pii = pi; - const cpl_size nx = urx - llx + 1; + found = + memchr(pi, value, + (size_t)self->nx * (size_t)(ury - lly + 1) * sizeof(*pi)); + } + else { + const cpl_binary *pii = pi; + const cpl_size nx = urx - llx + 1; - for (cpl_size j = lly - 1; j < ury; j++, pii += self->nx, - pi += self->nx - nx) { + for (cpl_size j = lly - 1; j < ury; + j++, pii += self->nx, pi += self->nx - nx) { found = memchr(pii, value, nx * sizeof(*pii)); - if (found) break; + if (found) + break; } } @@ -3059,30 +3221,42 @@ */ /*----------------------------------------------------------------------------*/ -static -void cpl_mask_erosion_(cpl_binary * self, const cpl_binary * other, - const cpl_binary * kernel, cpl_size nx, cpl_size ny, - cpl_size hx, cpl_size hy, cpl_border_mode border) +static void +cpl_mask_erosion_(cpl_binary *self, + const cpl_binary *other, + const cpl_binary *kernel, + cpl_size nx, + cpl_size ny, + cpl_size hx, + cpl_size hy, + cpl_border_mode border) { - #ifdef CPL_MASK_NOT if (hx <= CPL_MASK_HXW && hy == 0) { cpl_mask_erosion_1_0(self, other, kernel, nx, ny, hx, hy, border); - } else if (hx <= CPL_MASK_HXW && hy == 1) { + } + else if (hx <= CPL_MASK_HXW && hy == 1) { cpl_mask_erosion_1_1(self, other, kernel, nx, ny, hx, hy, border); - } else if (hx <= CPL_MASK_HXW && hy == 2) { + } + else if (hx <= CPL_MASK_HXW && hy == 2) { cpl_mask_erosion_1_2(self, other, kernel, nx, ny, hx, hy, border); - } else if (hx <= CPL_MASK_HXW && hy == 3) { + } + else if (hx <= CPL_MASK_HXW && hy == 3) { cpl_mask_erosion_1_3(self, other, kernel, nx, ny, hx, hy, border); - } else if (hx <= CPL_MASK_HX2W && hy == 0) { + } + else if (hx <= CPL_MASK_HX2W && hy == 0) { cpl_mask_erosion_2_0(self, other, kernel, nx, ny, hx, hy, border); - } else if (hx <= CPL_MASK_HX2W && hy == 1) { + } + else if (hx <= CPL_MASK_HX2W && hy == 1) { cpl_mask_erosion_2_1(self, other, kernel, nx, ny, hx, hy, border); - } else if (hx <= CPL_MASK_HX2W && hy == 2) { + } + else if (hx <= CPL_MASK_HX2W && hy == 2) { cpl_mask_erosion_2_2(self, other, kernel, nx, ny, hx, hy, border); - } else if (hx <= CPL_MASK_HX2W && hy == 3) { + } + else if (hx <= CPL_MASK_HX2W && hy == 3) { cpl_mask_erosion_2_3(self, other, kernel, nx, ny, hx, hy, border); - } else { + } + else { cpl_mask_erosion_n_n(self, other, kernel, nx, ny, hx, hy, border); } #endif @@ -3111,29 +3285,42 @@ */ /*----------------------------------------------------------------------------*/ -static -void cpl_mask_dilation_(cpl_binary * self, const cpl_binary * other, - const cpl_binary * kernel, cpl_size nx, cpl_size ny, - cpl_size hx, cpl_size hy, cpl_border_mode border) +static void +cpl_mask_dilation_(cpl_binary *self, + const cpl_binary *other, + const cpl_binary *kernel, + cpl_size nx, + cpl_size ny, + cpl_size hx, + cpl_size hy, + cpl_border_mode border) { #ifdef CPL_MASK_NOT if (hx <= CPL_MASK_HXW && hy == 0) { cpl_mask_dilation_1_0(self, other, kernel, nx, ny, hx, hy, border); - } else if (hx <= CPL_MASK_HXW && hy == 1) { + } + else if (hx <= CPL_MASK_HXW && hy == 1) { cpl_mask_dilation_1_1(self, other, kernel, nx, ny, hx, hy, border); - } else if (hx <= CPL_MASK_HXW && hy == 2) { + } + else if (hx <= CPL_MASK_HXW && hy == 2) { cpl_mask_dilation_1_2(self, other, kernel, nx, ny, hx, hy, border); - } else if (hx <= CPL_MASK_HXW && hy == 3) { + } + else if (hx <= CPL_MASK_HXW && hy == 3) { cpl_mask_dilation_1_3(self, other, kernel, nx, ny, hx, hy, border); - } else if (hx <= CPL_MASK_HX2W && hy == 0) { + } + else if (hx <= CPL_MASK_HX2W && hy == 0) { cpl_mask_dilation_2_0(self, other, kernel, nx, ny, hx, hy, border); - } else if (hx <= CPL_MASK_HX2W && hy == 1) { + } + else if (hx <= CPL_MASK_HX2W && hy == 1) { cpl_mask_dilation_2_1(self, other, kernel, nx, ny, hx, hy, border); - } else if (hx <= CPL_MASK_HX2W && hy == 2) { + } + else if (hx <= CPL_MASK_HX2W && hy == 2) { cpl_mask_dilation_2_2(self, other, kernel, nx, ny, hx, hy, border); - } else if (hx <= CPL_MASK_HX2W && hy == 3) { + } + else if (hx <= CPL_MASK_HX2W && hy == 3) { cpl_mask_dilation_2_3(self, other, kernel, nx, ny, hx, hy, border); - } else { + } + else { cpl_mask_dilation_n_n(self, other, kernel, nx, ny, hx, hy, border); } #endif @@ -3158,16 +3345,21 @@ */ /*----------------------------------------------------------------------------*/ -static -void cpl_mask_opening_(cpl_binary * self, const cpl_binary * other, - const cpl_binary * kernel, cpl_size nx, cpl_size ny, - cpl_size hx, cpl_size hy, cpl_border_mode border) +static void +cpl_mask_opening_(cpl_binary *self, + const cpl_binary *other, + const cpl_binary *kernel, + cpl_size nx, + cpl_size ny, + cpl_size hx, + cpl_size hy, + cpl_border_mode border) { /* Border of temporary buffer needs initialization from first filtering */ - const cpl_border_mode border1 = border == CPL_BORDER_NOP - ? CPL_BORDER_COPY : border; - cpl_binary * middle = cpl_malloc((size_t)nx * (size_t)ny - * sizeof(cpl_binary)); + const cpl_border_mode border1 = + border == CPL_BORDER_NOP ? CPL_BORDER_COPY : border; + cpl_binary *middle = + cpl_malloc((size_t)nx * (size_t)ny * sizeof(cpl_binary)); cpl_mask_erosion_(middle, other, kernel, nx, ny, hx, hy, border1); cpl_mask_dilation_(self, middle, kernel, nx, ny, hx, hy, border); @@ -3193,16 +3385,21 @@ */ /*----------------------------------------------------------------------------*/ -static -void cpl_mask_closing_(cpl_binary * self, const cpl_binary * other, - const cpl_binary * kernel, cpl_size nx, cpl_size ny, - cpl_size hx, cpl_size hy, cpl_border_mode border) +static void +cpl_mask_closing_(cpl_binary *self, + const cpl_binary *other, + const cpl_binary *kernel, + cpl_size nx, + cpl_size ny, + cpl_size hx, + cpl_size hy, + cpl_border_mode border) { /* Border of temporary buffer needs initialization from first filtering */ - const cpl_border_mode border1 = border == CPL_BORDER_NOP - ? CPL_BORDER_COPY : border; - cpl_binary * middle = cpl_malloc((size_t)nx * (size_t)ny - * sizeof(cpl_binary)); + const cpl_border_mode border1 = + border == CPL_BORDER_NOP ? CPL_BORDER_COPY : border; + cpl_binary *middle = + cpl_malloc((size_t)nx * (size_t)ny * sizeof(cpl_binary)); cpl_mask_dilation_(middle, other, kernel, nx, ny, hx, hy, border1); cpl_mask_erosion_(self, middle, kernel, nx, ny, hx, hy, border); @@ -3230,13 +3427,12 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -static -cpl_mask * cpl_mask_new_from_matrix(const cpl_matrix * kernel, double tol) +static cpl_mask * +cpl_mask_new_from_matrix(const cpl_matrix *kernel, double tol) { - - const cpl_size mx = cpl_matrix_get_ncol(kernel); - const cpl_size my = cpl_matrix_get_nrow(kernel); - cpl_mask * self; + const cpl_size mx = cpl_matrix_get_ncol(kernel); + const cpl_size my = cpl_matrix_get_nrow(kernel); + cpl_mask *self; cpl_ensure(kernel != NULL, CPL_ERROR_NULL_INPUT, NULL); @@ -3245,7 +3441,7 @@ for (cpl_size j = 0; j < my; j++) { for (cpl_size i = 0; i < mx; i++) { - const double value = cpl_matrix_get(kernel, my - j - 1, i); + const double value = cpl_matrix_get_(kernel, my - j - 1, i); if (fabs(value) > tol) cpl_mask_set(self, i + 1, j + 1, CPL_BINARY_1); diff -Nru cpl-7.1.4+ds/cplcore/cpl_mask_defs.h cpl-7.2.2+ds/cplcore/cpl_mask_defs.h --- cpl-7.1.4+ds/cplcore/cpl_mask_defs.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_mask_defs.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -34,13 +34,13 @@ Type definition -----------------------------------------------------------------------------*/ -struct _cpl_mask_ { - cpl_size nx; - cpl_size ny; - cpl_binary * data; +struct _cpl_mask_ +{ + cpl_size nx; + cpl_size ny; + cpl_binary *data; }; CPL_END_DECLS #endif - diff -Nru cpl-7.1.4+ds/cplcore/cpl_mask.h cpl-7.2.2+ds/cplcore/cpl_mask.h --- cpl-7.1.4+ds/cplcore/cpl_mask.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_mask.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -41,37 +41,48 @@ cpl_binary type definition -----------------------------------------------------------------------------*/ -typedef unsigned char cpl_binary; +typedef unsigned char cpl_binary; /*----------------------------------------------------------------------------- Define -----------------------------------------------------------------------------*/ -#define CPL_BINARY_1 (cpl_binary)1 -#define CPL_BINARY_0 (cpl_binary)0 +#define CPL_BINARY_1 (cpl_binary)1 +#define CPL_BINARY_0 (cpl_binary)0 /*----------------------------------------------------------------------------- Function prototypes -----------------------------------------------------------------------------*/ /* IO operations */ -cpl_mask * cpl_mask_new(cpl_size, cpl_size) CPL_ATTR_ALLOC; -cpl_mask * cpl_mask_wrap(cpl_size, cpl_size, cpl_binary *) CPL_ATTR_ALLOC; -cpl_mask * cpl_mask_duplicate(const cpl_mask *) CPL_ATTR_ALLOC; +cpl_mask *cpl_mask_new(cpl_size, cpl_size) CPL_ATTR_ALLOC; +cpl_mask *cpl_mask_wrap(cpl_size, cpl_size, cpl_binary *) CPL_ATTR_ALLOC; +cpl_mask *cpl_mask_duplicate(const cpl_mask *) CPL_ATTR_ALLOC; void cpl_mask_delete(cpl_mask *); -void * cpl_mask_unwrap(cpl_mask *); -cpl_error_code cpl_mask_dump_window(const cpl_mask *, cpl_size, cpl_size, - cpl_size, cpl_size, FILE *); - -cpl_mask * cpl_mask_load(const char *, cpl_size, cpl_size) CPL_ATTR_ALLOC; -cpl_mask * cpl_mask_load_window(const char *, cpl_size, cpl_size, cpl_size, - cpl_size, cpl_size, cpl_size) CPL_ATTR_ALLOC; -cpl_error_code cpl_mask_save(const cpl_mask *, const char *, - const cpl_propertylist *, unsigned); +void *cpl_mask_unwrap(cpl_mask *); +cpl_error_code cpl_mask_dump_window(const cpl_mask *, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + FILE *); + +cpl_mask *cpl_mask_load(const char *, cpl_size, cpl_size) CPL_ATTR_ALLOC; +cpl_mask *cpl_mask_load_window(const char *, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_size) CPL_ATTR_ALLOC; +cpl_error_code cpl_mask_save(const cpl_mask *, + const char *, + const cpl_propertylist *, + unsigned); /* Accessor functions */ -cpl_binary * cpl_mask_get_data(cpl_mask *); -const cpl_binary * cpl_mask_get_data_const(const cpl_mask *); +cpl_binary *cpl_mask_get_data(cpl_mask *); +const cpl_binary *cpl_mask_get_data_const(const cpl_mask *); cpl_binary cpl_mask_get(const cpl_mask *, cpl_size, cpl_size); cpl_error_code cpl_mask_set(cpl_mask *, cpl_size, cpl_size, cpl_binary); cpl_size cpl_mask_get_size_x(const cpl_mask *); @@ -79,44 +90,55 @@ /* Basic operations */ cpl_boolean cpl_mask_is_empty(const cpl_mask *); -cpl_boolean cpl_mask_is_empty_window(const cpl_mask *, cpl_size, cpl_size, - cpl_size, cpl_size); +cpl_boolean cpl_mask_is_empty_window(const cpl_mask *, + cpl_size, + cpl_size, + cpl_size, + cpl_size); cpl_size cpl_mask_count(const cpl_mask *); -cpl_size cpl_mask_count_window(const cpl_mask *, cpl_size, cpl_size, - cpl_size, cpl_size); +cpl_size +cpl_mask_count_window(const cpl_mask *, cpl_size, cpl_size, cpl_size, cpl_size); cpl_error_code cpl_mask_and(cpl_mask *, const cpl_mask *); cpl_error_code cpl_mask_or(cpl_mask *, const cpl_mask *); cpl_error_code cpl_mask_xor(cpl_mask *, const cpl_mask *); cpl_error_code cpl_mask_not(cpl_mask *); -cpl_mask * cpl_mask_collapse_create(const cpl_mask *, int) CPL_ATTR_ALLOC; -cpl_mask * cpl_mask_extract(const cpl_mask *, cpl_size, cpl_size, - cpl_size, cpl_size) CPL_ATTR_ALLOC; +cpl_mask *cpl_mask_collapse_create(const cpl_mask *, int) CPL_ATTR_ALLOC; +cpl_mask * +cpl_mask_extract(const cpl_mask *, cpl_size, cpl_size, cpl_size, cpl_size) + CPL_ATTR_ALLOC; cpl_error_code cpl_mask_turn(cpl_mask *, int); cpl_error_code cpl_mask_shift(cpl_mask *, cpl_size, cpl_size); cpl_error_code cpl_mask_copy(cpl_mask *, const cpl_mask *, cpl_size, cpl_size); cpl_error_code cpl_mask_flip(cpl_mask *, int); cpl_error_code cpl_mask_move(cpl_mask *, cpl_size, const cpl_size *); -cpl_mask * cpl_mask_extract_subsample(const cpl_mask *, - cpl_size, cpl_size) CPL_ATTR_ALLOC; +cpl_mask * +cpl_mask_extract_subsample(const cpl_mask *, cpl_size, cpl_size) CPL_ATTR_ALLOC; /* Morphological operations */ -cpl_error_code cpl_mask_filter(cpl_mask *, const cpl_mask *, const cpl_mask *, - cpl_filter_mode, cpl_border_mode); -cpl_error_code cpl_mask_closing(cpl_mask *, - const cpl_matrix *) CPL_ATTR_DEPRECATED; -cpl_error_code cpl_mask_opening(cpl_mask *, - const cpl_matrix *) CPL_ATTR_DEPRECATED; -cpl_error_code cpl_mask_erosion(cpl_mask *, - const cpl_matrix *) CPL_ATTR_DEPRECATED; -cpl_error_code cpl_mask_dilation(cpl_mask *, - const cpl_matrix *) CPL_ATTR_DEPRECATED; +cpl_error_code cpl_mask_filter(cpl_mask *, + const cpl_mask *, + const cpl_mask *, + cpl_filter_mode, + cpl_border_mode); +cpl_error_code +cpl_mask_closing(cpl_mask *, const cpl_matrix *) CPL_ATTR_DEPRECATED; +cpl_error_code +cpl_mask_opening(cpl_mask *, const cpl_matrix *) CPL_ATTR_DEPRECATED; +cpl_error_code +cpl_mask_erosion(cpl_mask *, const cpl_matrix *) CPL_ATTR_DEPRECATED; +cpl_error_code +cpl_mask_dilation(cpl_mask *, const cpl_matrix *) CPL_ATTR_DEPRECATED; /* Zones selection */ -cpl_error_code cpl_mask_threshold_image(cpl_mask *, const cpl_image *, - double, double, cpl_binary); -cpl_mask * cpl_mask_threshold_image_create(const cpl_image *, - double, double) CPL_ATTR_ALLOC; +cpl_error_code cpl_mask_threshold_image(cpl_mask *, + const cpl_image *, + double, + double, + cpl_binary); +cpl_mask *cpl_mask_threshold_image_create(const cpl_image *, + double, + double) CPL_ATTR_ALLOC; CPL_END_DECLS -#endif +#endif diff -Nru cpl-7.1.4+ds/cplcore/cpl_mask_impl.h cpl-7.2.2+ds/cplcore/cpl_mask_impl.h --- cpl-7.1.4+ds/cplcore/cpl_mask_impl.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_mask_impl.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -24,74 +24,57 @@ CPL_BEGIN_DECLS -cpl_size cpl_mask_get_first_window(const cpl_mask *, cpl_size, cpl_size, - cpl_size, cpl_size, cpl_binary); +cpl_size cpl_mask_get_first_window(const cpl_mask *, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_binary); -void cpl_mask_and_(cpl_binary *, - const cpl_binary *, - const cpl_binary *, - size_t) +void cpl_mask_and_(cpl_binary *, const cpl_binary *, const cpl_binary *, size_t) CPL_INTERNAL #ifdef CPL_HAVE_ATTR_NONNULL - __attribute__((nonnull(1,3))) + __attribute__((nonnull(1, 3))) #endif ; -void cpl_mask_or_(cpl_binary *, - const cpl_binary *, - const cpl_binary *, - size_t) +void cpl_mask_or_(cpl_binary *, const cpl_binary *, const cpl_binary *, size_t) CPL_INTERNAL #ifdef CPL_HAVE_ATTR_NONNULL - __attribute__((nonnull(1,3))) + __attribute__((nonnull(1, 3))) #endif ; -void cpl_mask_xor_(cpl_binary *, - const cpl_binary *, - const cpl_binary *, - size_t) +void cpl_mask_xor_(cpl_binary *, const cpl_binary *, const cpl_binary *, size_t) CPL_INTERNAL #ifdef CPL_HAVE_ATTR_NONNULL - __attribute__((nonnull(1,3))) + __attribute__((nonnull(1, 3))) #endif ; -void cpl_mask_and_scalar(cpl_binary *, - const cpl_binary *, - cpl_bitmask, - size_t) +void cpl_mask_and_scalar(cpl_binary *, const cpl_binary *, cpl_bitmask, size_t) CPL_INTERNAL #ifdef CPL_HAVE_ATTR_NONNULL __attribute__((nonnull(1))) #endif ; -void cpl_mask_or_scalar(cpl_binary *, - const cpl_binary *, - cpl_bitmask, - size_t) +void cpl_mask_or_scalar(cpl_binary *, const cpl_binary *, cpl_bitmask, size_t) CPL_INTERNAL #ifdef CPL_HAVE_ATTR_NONNULL __attribute__((nonnull(1))) #endif ; -void cpl_mask_xor_scalar(cpl_binary *, - const cpl_binary *, - cpl_bitmask, - size_t) +void cpl_mask_xor_scalar(cpl_binary *, const cpl_binary *, cpl_bitmask, size_t) CPL_INTERNAL #ifdef CPL_HAVE_ATTR_NONNULL __attribute__((nonnull(1))) #endif ; -cpl_mask * cpl_mask_extract_(const cpl_mask *, - cpl_size, - cpl_size, - cpl_size, - cpl_size) +cpl_mask * +cpl_mask_extract_(const cpl_mask *, cpl_size, cpl_size, cpl_size, cpl_size) CPL_ATTR_ALLOC; void cpl_mask_fill_window(cpl_mask *, @@ -99,8 +82,7 @@ cpl_size, cpl_size, cpl_size, - cpl_binary) - CPL_INTERNAL CPL_ATTR_NONNULL; + cpl_binary) CPL_INTERNAL CPL_ATTR_NONNULL; CPL_END_DECLS diff -Nru cpl-7.1.4+ds/cplcore/cpl_math_const.h cpl-7.2.2+ds/cplcore/cpl_math_const.h --- cpl-7.1.4+ds/cplcore/cpl_math_const.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_math_const.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -67,7 +67,7 @@ * http://www.research.att.com/~njas/sequences/A001113 */ /*----------------------------------------------------------------------------*/ -#define CPL_MATH_E 2.7182818284590452353602874713526624977572470936999595 +#define CPL_MATH_E 2.7182818284590452353602874713526624977572470936999595 /*----------------------------------------------------------------------------*/ /** @@ -76,7 +76,7 @@ * http://www.research.att.com/~njas/sequences/A000796 */ /*----------------------------------------------------------------------------*/ -#define CPL_MATH_PI 3.1415926535897932384626433832795028841971693993751058 +#define CPL_MATH_PI 3.1415926535897932384626433832795028841971693993751058 /*----------------------------------------------------------------------------*/ /** @@ -85,7 +85,7 @@ * http://www.research.att.com/~njas/sequences/A002162 */ /*----------------------------------------------------------------------------*/ -#define CPL_MATH_LN2 0.6931471805599453094172321214581765680755001343602553 +#define CPL_MATH_LN2 0.6931471805599453094172321214581765680755001343602553 /*----------------------------------------------------------------------------*/ /** @@ -94,7 +94,7 @@ * http://www.research.att.com/~njas/sequences/A002392 */ /*----------------------------------------------------------------------------*/ -#define CPL_MATH_LN10 2.3025850929940456840179914546843642076011014886287730 +#define CPL_MATH_LN10 2.3025850929940456840179914546843642076011014886287730 /*----------------------------------------------------------------------------*/ /** @@ -103,7 +103,7 @@ @note Derived from a fundamental constant */ /*----------------------------------------------------------------------------*/ -#define CPL_MATH_2PI 6.2831853071795864769252867665590057683943387987502116 +#define CPL_MATH_2PI 6.2831853071795864769252867665590057683943387987502116 /*----------------------------------------------------------------------------*/ /** @@ -112,7 +112,7 @@ @note Derived from a fundamental constant */ /*----------------------------------------------------------------------------*/ -#define CPL_MATH_PI_2 1.5707963267948966192313216916397514420985846996875529 +#define CPL_MATH_PI_2 1.5707963267948966192313216916397514420985846996875529 /*----------------------------------------------------------------------------*/ /** @@ -121,7 +121,7 @@ @note Derived from a fundamental constant */ /*----------------------------------------------------------------------------*/ -#define CPL_MATH_PI_4 0.7853981633974483096156608458198757210492923498437765 +#define CPL_MATH_PI_4 0.7853981633974483096156608458198757210492923498437765 /*----------------------------------------------------------------------------*/ /** @@ -130,7 +130,7 @@ @note Derived from a fundamental constant */ /*----------------------------------------------------------------------------*/ -#define CPL_MATH_1_PI 0.3183098861837906715377675267450287240689192914809129 +#define CPL_MATH_1_PI 0.3183098861837906715377675267450287240689192914809129 /*----------------------------------------------------------------------------*/ /** @@ -139,7 +139,7 @@ @note Derived from a fundamental constant */ /*----------------------------------------------------------------------------*/ -#define CPL_MATH_2_PI 0.6366197723675813430755350534900574481378385829618258 +#define CPL_MATH_2_PI 0.6366197723675813430755350534900574481378385829618258 /*----------------------------------------------------------------------------*/ /** @@ -148,7 +148,7 @@ @note Derived from a fundamental constant */ /*----------------------------------------------------------------------------*/ -#define CPL_MATH_4_PI 1.2732395447351626861510701069801148962756771659236516 +#define CPL_MATH_4_PI 1.2732395447351626861510701069801148962756771659236516 /*----------------------------------------------------------------------------*/ /** @@ -157,7 +157,7 @@ @note Derived from a fundamental constant */ /*----------------------------------------------------------------------------*/ -#define CPL_MATH_SQRT2PI 2.5066282746310005024157652848110452530069867406099383 +#define CPL_MATH_SQRT2PI 2.5066282746310005024157652848110452530069867406099383 /*----------------------------------------------------------------------------*/ /** @@ -175,7 +175,7 @@ * http://www.research.att.com/~njas/sequences/A002193 */ /*----------------------------------------------------------------------------*/ -#define CPL_MATH_SQRT2 1.4142135623730950488016887242096980785696718753769481 +#define CPL_MATH_SQRT2 1.4142135623730950488016887242096980785696718753769481 /*----------------------------------------------------------------------------*/ /** @@ -184,7 +184,7 @@ * http://www.research.att.com/~njas/sequences/A002194 */ /*----------------------------------------------------------------------------*/ -#define CPL_MATH_SQRT3 1.7320508075688772935274463415058723669428052538103806 +#define CPL_MATH_SQRT3 1.7320508075688772935274463415058723669428052538103806 /*----------------------------------------------------------------------------*/ /** @@ -193,7 +193,7 @@ @note Derived from a fundamental constant */ /*----------------------------------------------------------------------------*/ -#define CPL_MATH_SQRT1_2 0.7071067811865475244008443621048490392848359376884740 +#define CPL_MATH_SQRT1_2 0.7071067811865475244008443621048490392848359376884740 /*----------------------------------------------------------------------------*/ /** @@ -202,7 +202,7 @@ @note Derived from a fundamental constant */ /*----------------------------------------------------------------------------*/ -#define CPL_MATH_LOG2E 1.4426950408889634073599246810018921374266459541529859 +#define CPL_MATH_LOG2E 1.4426950408889634073599246810018921374266459541529859 /*----------------------------------------------------------------------------*/ /** @@ -211,7 +211,7 @@ @note Derived from a fundamental constant */ /*----------------------------------------------------------------------------*/ -#define CPL_MATH_LOG10E 0.4342944819032518276511289189166050822943970058036666 +#define CPL_MATH_LOG10E 0.4342944819032518276511289189166050822943970058036666 /*----------------------------------------------------------------------------*/ /** @@ -220,7 +220,7 @@ @note Derived from a fundamental constant */ /*----------------------------------------------------------------------------*/ -#define CPL_MATH_DEG_RAD 57.295779513082320876798154814105170332405472466564322 +#define CPL_MATH_DEG_RAD 57.295779513082320876798154814105170332405472466564322 /*----------------------------------------------------------------------------*/ /** @@ -229,7 +229,7 @@ @note Derived from a fundamental constant */ /*----------------------------------------------------------------------------*/ -#define CPL_MATH_RAD_DEG 0.0174532925199432957692369076848861271344287188854173 +#define CPL_MATH_RAD_DEG 0.0174532925199432957692369076848861271344287188854173 /*----------------------------------------------------------------------------*/ /** @@ -276,8 +276,8 @@ */ /*----------------------------------------------------------------------------*/ -#define CPL_MIN(first, second) \ - (((first) < (second)) ? (first) : (second)) /* Two evaluations of minimum */ +#define CPL_MIN(first, second) \ + (((first) < (second)) ? (first) : (second)) /* Two evaluations of minimum */ /*----------------------------------------------------------------------------*/ /** @@ -290,12 +290,11 @@ */ /*----------------------------------------------------------------------------*/ -#define CPL_MAX(first, second) \ - (((first) > (second)) ? (first) : (second)) /* Two evaluations of maximum */ +#define CPL_MAX(first, second) \ + (((first) > (second)) ? (first) : (second)) /* Two evaluations of maximum */ /**@}*/ CPL_END_DECLS #endif - diff -Nru cpl-7.1.4+ds/cplcore/cpl_matrix.c cpl-7.2.2+ds/cplcore/cpl_matrix.c --- cpl-7.1.4+ds/cplcore/cpl_matrix.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_matrix.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -61,31 +61,30 @@ * The cpl_matrix type: */ -struct _cpl_matrix_ { +struct _cpl_matrix_ +{ cpl_size nc; cpl_size nr; - double *m; -}; + double *m; +}; /*----------------------------------------------------------------------------- Private function prototypes -----------------------------------------------------------------------------*/ -inline -static void swap_rows(cpl_matrix *, cpl_size, cpl_size) CPL_ATTR_NONNULL; +inline static void swap_rows(cpl_matrix *, cpl_size, cpl_size) CPL_ATTR_NONNULL; static void read_row(const cpl_matrix *, double *, cpl_size) CPL_ATTR_NONNULL; static void write_row(cpl_matrix *, const double *, cpl_size) CPL_ATTR_NONNULL; static void write_read_row(cpl_matrix *, double *, cpl_size) CPL_ATTR_NONNULL; -static -void read_column(const cpl_matrix *, double *, cpl_size) CPL_ATTR_NONNULL; -static -void write_column(cpl_matrix *, const double *, cpl_size) CPL_ATTR_NONNULL; -static -void write_read_column(cpl_matrix *, double *, cpl_size) CPL_ATTR_NONNULL; +static void +read_column(const cpl_matrix *, double *, cpl_size) CPL_ATTR_NONNULL; +static void +write_column(cpl_matrix *, const double *, cpl_size) CPL_ATTR_NONNULL; +static void +write_read_column(cpl_matrix *, double *, cpl_size) CPL_ATTR_NONNULL; static cpl_error_code cpl_matrix_set_size_(cpl_matrix *, cpl_size, cpl_size); -static cpl_error_code _cpl_matrix_decomp_sv_jacobi(cpl_matrix *U, - cpl_vector *S, - cpl_matrix *V); +static cpl_error_code +cpl_matrix_decomp_sv_jacobi_(cpl_matrix *U, cpl_vector *S, cpl_matrix *V); /*----------------------------------------------------------------------------- Function codes -----------------------------------------------------------------------------*/ @@ -105,23 +104,21 @@ */ /*----------------------------------------------------------------------------*/ -static -cpl_error_code cpl_matrix_set_size_(cpl_matrix * self, cpl_size nr, cpl_size nc) +static cpl_error_code +cpl_matrix_set_size_(cpl_matrix *self, cpl_size nr, cpl_size nc) { - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); if (self->nr != nr || self->nc != nc) { - cpl_ensure_code(nr > 0, CPL_ERROR_ILLEGAL_INPUT); cpl_ensure_code(nc > 0, CPL_ERROR_ILLEGAL_INPUT); /* Need to resize the matrix */ - if (self->nr * self->nc != nr * nc) { + if (self->nr * self->nc != nr * nc) { cpl_free(self->m); - self->m = (double*)cpl_malloc((size_t)nr * (size_t)nc - * sizeof(double)); + self->m = + (double *)cpl_malloc((size_t)nr * (size_t)nc * sizeof(double)); } self->nr = nr; self->nc = nc; @@ -151,20 +148,20 @@ */ /*----------------------------------------------------------------------------*/ -inline -static void swap_rows(cpl_matrix * self, cpl_size row1, cpl_size row2) -{ +inline static void +swap_rows(cpl_matrix *self, cpl_size row1, cpl_size row2) +{ #define NBLOCK 128 - double swap[NBLOCK]; + double swap[NBLOCK]; cpl_size ncol = self->nc; - double * pos1 = self->m + ncol * row1; - double * pos2 = self->m + ncol * row2; + double *pos1 = self->m + ncol * row1; + double *pos2 = self->m + ncol * row2; while (ncol >= NBLOCK) { ncol -= NBLOCK; - (void)memcpy(swap, pos1 + ncol, NBLOCK * sizeof(double)); + (void)memcpy(swap, pos1 + ncol, NBLOCK * sizeof(double)); (void)memcpy(pos1 + ncol, pos2 + ncol, NBLOCK * sizeof(double)); - (void)memcpy(pos2 + ncol, swap, NBLOCK * sizeof(double)); + (void)memcpy(pos2 + ncol, swap, NBLOCK * sizeof(double)); } if (ncol > 0) { @@ -189,14 +186,13 @@ * This private function reads the content of a matrix row into an allocated * buffer. No checks are performed. */ -static void read_row(const cpl_matrix *matrix, double *row, cpl_size pos) +static void +read_row(const cpl_matrix *matrix, double *row, cpl_size pos) { - cpl_size i; for (i = 0, pos *= matrix->nc; i < matrix->nc; i++, pos++) row[i] = matrix->m[pos]; - } /* @@ -213,14 +209,13 @@ * This private function writes the content of a buffer into a matrix row. * No checks are performed. */ -static void write_row(cpl_matrix *matrix, const double *row, cpl_size pos) +static void +write_row(cpl_matrix *matrix, const double *row, cpl_size pos) { - cpl_size i; for (i = 0, pos *= matrix->nc; i < matrix->nc; i++, pos++) matrix->m[pos] = *row++; - } /* @@ -237,10 +232,10 @@ * This private function exchanges the values in buffer with the values in * a chosen matrix row. No checks are performed. */ -static void write_read_row(cpl_matrix *matrix, double *row, cpl_size pos) +static void +write_read_row(cpl_matrix *matrix, double *row, cpl_size pos) { - - cpl_size i; + cpl_size i; double swap; for (i = 0, pos *= matrix->nc; i < matrix->nc; i++, pos++) { @@ -248,7 +243,6 @@ matrix->m[pos] = row[i]; row[i] = swap; } - } /* @@ -265,14 +259,13 @@ * This private function reads the content of a matrix column into an * allocated buffer. No checks are performed. */ -static void read_column(const cpl_matrix *matrix, double *column, cpl_size pos) +static void +read_column(const cpl_matrix *matrix, double *column, cpl_size pos) { - cpl_size i; for (i = 0; i < matrix->nr; i++, pos += matrix->nc) column[i] = matrix->m[pos]; - } /* @@ -289,16 +282,15 @@ * This private function writes the content of a buffer into a matrix column. * No checks are performed. */ -static void write_column(cpl_matrix *matrix, const double *column, cpl_size pos) +static void +write_column(cpl_matrix *matrix, const double *column, cpl_size pos) { - cpl_size i; cpl_size size = matrix->nr * matrix->nc; for (i = pos; i < size; i += matrix->nc) matrix->m[i] = *column++; - } /* @@ -315,10 +307,10 @@ * This private function exchanges the values in buffer with the values in * a chosen matrix column. No checks are performed. */ -static void write_read_column(cpl_matrix *matrix, double *column, cpl_size pos) +static void +write_read_column(cpl_matrix *matrix, double *column, cpl_size pos) { - - cpl_size i; + cpl_size i; double swap; for (i = 0; i < matrix->nr; i++, pos += matrix->nc) { @@ -326,7 +318,6 @@ matrix->m[pos] = column[i]; column[i] = swap; } - } /* @@ -349,7 +340,8 @@ * @c fprintf(). */ -void cpl_matrix_dump(const cpl_matrix *matrix, FILE *stream) +void +cpl_matrix_dump(const cpl_matrix *matrix, FILE *stream) { cpl_size i, j, k; @@ -404,11 +396,10 @@ * To destroy this matrix the function @c cpl_matrix_delete() should be used. */ -cpl_matrix *cpl_matrix_new(cpl_size rows, cpl_size columns) +cpl_matrix * +cpl_matrix_new(cpl_size rows, cpl_size columns) { - - - cpl_matrix *matrix; + cpl_matrix *matrix; if (rows < 1) { @@ -423,13 +414,12 @@ matrix = (cpl_matrix *)cpl_malloc(sizeof(cpl_matrix)); - matrix->m = (double *)cpl_calloc((size_t)rows * (size_t)columns, - sizeof(double)); + matrix->m = + (double *)cpl_calloc((size_t)rows * (size_t)columns, sizeof(double)); matrix->nr = rows; matrix->nc = columns; return matrix; - } @@ -488,11 +478,10 @@ * be used. */ -cpl_matrix *cpl_matrix_wrap(cpl_size rows, cpl_size columns, double *data) +cpl_matrix * +cpl_matrix_wrap(cpl_size rows, cpl_size columns, double *data) { - - - cpl_matrix *matrix; + cpl_matrix *matrix; if (rows < 1 || columns < 1) { @@ -512,7 +501,6 @@ matrix->nc = columns; return matrix; - } @@ -528,14 +516,13 @@ * If @em matrix is @c NULL, nothing is done. */ -void cpl_matrix_delete(cpl_matrix *matrix) +void +cpl_matrix_delete(cpl_matrix *matrix) { - if (matrix) { cpl_free(matrix->m); cpl_free(matrix); } - } @@ -557,9 +544,9 @@ * nothing is done, and a @c NULL pointer is returned. */ -void *cpl_matrix_unwrap(cpl_matrix *matrix) +void * +cpl_matrix_unwrap(cpl_matrix *matrix) { - void *data = NULL; if (matrix) { @@ -568,7 +555,6 @@ } return data; - } @@ -594,18 +580,36 @@ * Determine the number of rows in a matrix. */ -inline -cpl_size cpl_matrix_get_nrow(const cpl_matrix *matrix) +inline cpl_size +cpl_matrix_get_nrow(const cpl_matrix *matrix) { - if (matrix == NULL) { /* inline precludes using cpl_error_set_() due to its use of __func__ */ - (void) cpl_error_set("cpl_matrix_get_nrow", CPL_ERROR_NULL_INPUT); + (void)cpl_error_set_(CPL_ERROR_NULL_INPUT); return 0; } - return matrix->nr; + return cpl_matrix_get_nrow_(matrix); +} + +/** + * @internal + * @brief + * Get the number of rows of a matrix. + * + * @param matrix Pointer to the matrix to examine. + * + * @return Number of matrix rows, or zero in case of failure. + * + * @note No error checking in this internal function! + * @see cpl_matrix_get_nrow + * + */ +inline cpl_size +cpl_matrix_get_nrow_(const cpl_matrix *matrix) +{ + return matrix->nr; } @@ -631,18 +635,36 @@ * Determine the number of columns in a matrix. */ -inline -cpl_size cpl_matrix_get_ncol(const cpl_matrix *matrix) +inline cpl_size +cpl_matrix_get_ncol(const cpl_matrix *matrix) { - if (matrix == NULL) { /* inline precludes using cpl_error_set_() due to its use of __func__ */ - (void) cpl_error_set("cpl_matrix_get_ncol", CPL_ERROR_NULL_INPUT); + (void)cpl_error_set_(CPL_ERROR_NULL_INPUT); return 0; } - return matrix->nc; + return cpl_matrix_get_ncol_(matrix); +} + + +/** + * @brief + * Get the number of columns of a matrix. + * + * @param matrix Pointer to the matrix to examine. + * + * @return Number of matrix columns, or zero in case of failure. + * + * @note No error checking in this internal function! + * @see cpl_matrix_get_ncol + * + */ +inline cpl_size +cpl_matrix_get_ncol_(const cpl_matrix *matrix) +{ + return matrix->nc; } @@ -687,18 +709,37 @@ * the actual matrix data and structure. */ -inline -double *cpl_matrix_get_data(cpl_matrix *matrix) +inline double * +cpl_matrix_get_data(cpl_matrix *matrix) { - if (matrix == NULL) { /* inline precludes using cpl_error_set_() due to its use of __func__ */ - (void) cpl_error_set("cpl_matrix_get_data", CPL_ERROR_NULL_INPUT); + (void)cpl_error_set_(CPL_ERROR_NULL_INPUT); return NULL; } - return matrix->m; + return cpl_matrix_get_data_(matrix); +} + + +/** + * @internal + * @brief + * Get the pointer to a matrix data buffer, or @c NULL in case of error. + * + * @param matrix Input matrix. + * + * @return Pointer to the matrix data buffer. + * + * @note No error checking in this internal function! + * @see cpl_matrix_get_data + * + */ +inline double * +cpl_matrix_get_data_(cpl_matrix *matrix) +{ + return matrix->m; } @@ -713,15 +754,35 @@ * @see cpl_matrix_get_data */ -inline -const double *cpl_matrix_get_data_const(const cpl_matrix *matrix) +inline const double * +cpl_matrix_get_data_const(const cpl_matrix *matrix) { if (matrix == NULL) { /* inline precludes using cpl_error_set_() due to its use of __func__ */ - (void) cpl_error_set("cpl_matrix_get_data_const", CPL_ERROR_NULL_INPUT); + (void)cpl_error_set_(CPL_ERROR_NULL_INPUT); return NULL; } + return cpl_matrix_get_data_const_(matrix); +} + + +/** + * @internal + * @brief + * Get the pointer to a matrix data buffer, or @c NULL in case of error. + * + * @param matrix Input matrix. + * + * @return Pointer to the matrix data buffer. + * + * @note No error checking in this internal function! + * @see cpl_matrix_get_data_const + */ + +inline const double * +cpl_matrix_get_data_const_(const cpl_matrix *matrix) +{ return matrix->m; } @@ -757,28 +818,46 @@ * counted from 0,0. */ -double cpl_matrix_get(const cpl_matrix *matrix, cpl_size row, cpl_size column) +double +cpl_matrix_get(const cpl_matrix *matrix, cpl_size row, cpl_size column) { - - - - if (matrix == NULL) { (void)cpl_error_set_(CPL_ERROR_NULL_INPUT); return 0.0; - } + } if (row < 0 || row >= matrix->nr || column < 0 || column >= matrix->nc) { (void)cpl_error_set_(CPL_ERROR_ACCESS_OUT_OF_RANGE); return 0.0; } - return matrix->m[column + row * matrix->nc]; + return cpl_matrix_get_(matrix, row, column); +} + + +/** + * @internal + * @brief + * Get the value of a matrix element. + * + * @param matrix Pointer to a matrix. + * @param row Matrix element row. + * @param column Matrix element column. + * + * @return Value of the specified matrix element, or 0.0 in case of error. + * @note No error checking in this internal function! + * @see cpl_matrix_get + */ +inline double +cpl_matrix_get_(const cpl_matrix *matrix, cpl_size row, cpl_size column) +{ + return matrix->m[column + row * matrix->nc]; } /** + * @internal * @brief * Write a value to a matrix element. * @@ -810,24 +889,40 @@ * counted from 0,0. */ -inline -cpl_error_code cpl_matrix_set(cpl_matrix *matrix, - cpl_size row, cpl_size column, double value) +inline cpl_error_code +cpl_matrix_set(cpl_matrix *matrix, cpl_size row, cpl_size column, double value) { - - - - if (matrix == NULL) - return cpl_error_set("cpl_matrix_set", CPL_ERROR_NULL_INPUT); + return cpl_error_set_(CPL_ERROR_NULL_INPUT); if (row < 0 || row >= matrix->nr || column < 0 || column >= matrix->nc) - return cpl_error_set("cpl_matrix_set", CPL_ERROR_ACCESS_OUT_OF_RANGE); + return cpl_error_set_(CPL_ERROR_ACCESS_OUT_OF_RANGE); - matrix->m[column + row * matrix->nc] = value; + cpl_matrix_set_(matrix, row, column, value); return CPL_ERROR_NONE; +} + + +/** + * @brief + * Write a value to a matrix element. + * + * @param matrix Input matrix. + * @param row Matrix element row. + * @param column Matrix element column. + * @param value Value to write. + * + * @return void + * @note No error checking in this internal function! + * @see cpl_matrix_set + * + */ +inline void +cpl_matrix_set_(cpl_matrix *matrix, cpl_size row, cpl_size column, double value) +{ + matrix->m[column + row * matrix->nc] = value; } @@ -854,11 +949,10 @@ * the function @c cpl_matrix_delete() should be used. */ -cpl_matrix *cpl_matrix_duplicate(const cpl_matrix *matrix) +cpl_matrix * +cpl_matrix_duplicate(const cpl_matrix *matrix) { - - - cpl_matrix *new_matrix = NULL; + cpl_matrix *new_matrix = NULL; if (matrix) { const cpl_size size = matrix->nr * matrix->nc; @@ -874,7 +968,6 @@ (void)cpl_error_set_(CPL_ERROR_NULL_INPUT); return new_matrix; - } @@ -925,17 +1018,19 @@ * @c cpl_matrix_delete() should be used. */ -cpl_matrix *cpl_matrix_extract(const cpl_matrix *matrix, - cpl_size start_row, cpl_size start_column, - cpl_size step_row, cpl_size step_column, - cpl_size nrows, cpl_size ncolumns) +cpl_matrix * +cpl_matrix_extract(const cpl_matrix *matrix, + cpl_size start_row, + cpl_size start_column, + cpl_size step_row, + cpl_size step_column, + cpl_size nrows, + cpl_size ncolumns) { - - - cpl_matrix *new_matrix = NULL; - cpl_size i, r, c; - cpl_size size; - cpl_size row, col; + cpl_matrix *new_matrix = NULL; + cpl_size i, r, c; + cpl_size size; + cpl_size row, col; if (matrix == NULL) { @@ -943,17 +1038,16 @@ return NULL; } - if (start_row < 0 || start_row >= matrix->nr || - start_column < 0 || start_column >= matrix->nc || - nrows < 1 || ncolumns < 1) { + if (start_row < 0 || start_row >= matrix->nr || start_column < 0 || + start_column >= matrix->nc || nrows < 1 || ncolumns < 1) { cpl_error_set_(CPL_ERROR_ACCESS_OUT_OF_RANGE); return NULL; } - if (nrows == 1) /* Step irrelevant... */ + if (nrows == 1) /* Step irrelevant... */ step_row = 1; - if (ncolumns == 1) /* Step irrelevant... */ + if (ncolumns == 1) /* Step irrelevant... */ step_column = 1; if (step_row < 1 || step_column < 1) { @@ -969,18 +1063,17 @@ size = nrows * ncolumns; - new_matrix = (cpl_matrix *)cpl_malloc(sizeof(cpl_matrix)); - new_matrix->m = (double *)cpl_malloc((size_t)size * sizeof(double)); + new_matrix = (cpl_matrix *)cpl_malloc(sizeof(cpl_matrix)); + new_matrix->m = (double *)cpl_malloc((size_t)size * sizeof(double)); new_matrix->nr = nrows; new_matrix->nc = ncolumns; for (i = 0, r = start_row, row = nrows; row--; r += step_row) - for (c = r * matrix->nc + start_column, col = ncolumns; col--; - c += step_column, i++) + for (c = r * matrix->nc + start_column, col = ncolumns; col--; + c += step_column, i++) new_matrix->m[i] = matrix->m[c]; return new_matrix; - } @@ -1015,9 +1108,9 @@ * @c cpl_matrix_delete() should be used. */ -cpl_matrix *cpl_matrix_extract_row(const cpl_matrix *matrix, cpl_size row) +cpl_matrix * +cpl_matrix_extract_row(const cpl_matrix *matrix, cpl_size row) { - cpl_matrix *vector; if (matrix == NULL) { @@ -1028,10 +1121,9 @@ vector = cpl_matrix_extract(matrix, row, 0, 1, 1, 1, matrix->nc); if (vector == NULL) - cpl_error_set_where("cpl_matrix_extract_row"); + cpl_error_set_where_(); return vector; - } @@ -1066,9 +1158,9 @@ * function @c cpl_matrix_delete() should be used. */ -cpl_matrix *cpl_matrix_extract_column(const cpl_matrix *matrix, cpl_size column) +cpl_matrix * +cpl_matrix_extract_column(const cpl_matrix *matrix, cpl_size column) { - cpl_matrix *vector; if (matrix == NULL) { @@ -1078,11 +1170,10 @@ vector = cpl_matrix_extract(matrix, 0, column, 1, 1, matrix->nr, 1); - if (vector == NULL) - cpl_error_set_where("cpl_matrix_extract_column"); + if (vector == NULL) + cpl_error_set_where_(); return vector; - } @@ -1123,16 +1214,15 @@ * the new matrix the function @c cpl_matrix_delete() should be used. */ -cpl_matrix *cpl_matrix_extract_diagonal(const cpl_matrix *matrix, cpl_size diagonal) +cpl_matrix * +cpl_matrix_extract_diagonal(const cpl_matrix *matrix, cpl_size diagonal) { - - - cpl_matrix *output; - cpl_size diagonal_count; - cpl_size diagonal_length; - cpl_size i, r, c; - double *m; - double *om; + cpl_matrix *output; + cpl_size diagonal_count; + cpl_size diagonal_length; + cpl_size i, r, c; + double *m; + double *om; if (matrix == NULL) { @@ -1140,7 +1230,7 @@ return NULL; } - diagonal_count = labs(matrix->nr - matrix->nc) + 1; + diagonal_count = llabs(matrix->nr - matrix->nc) + 1; if (diagonal < 0 || diagonal >= diagonal_count) { cpl_error_set_(CPL_ERROR_ACCESS_OUT_OF_RANGE); @@ -1150,8 +1240,8 @@ diagonal_length = matrix->nr < matrix->nc ? matrix->nr : matrix->nc; output = (cpl_matrix *)cpl_malloc(sizeof(cpl_matrix)); - om = output->m = (double *)cpl_malloc((size_t)diagonal_length - * sizeof(*om)); + om = output->m = + (double *)cpl_malloc((size_t)diagonal_length * sizeof(*om)); if (matrix->nc < matrix->nr) { r = diagonal; @@ -1171,7 +1261,6 @@ *om++ = *m; return output; - } @@ -1198,18 +1287,20 @@ * Write the same value to all matrix elements. */ -cpl_error_code cpl_matrix_fill(cpl_matrix *matrix, double value) +cpl_error_code +cpl_matrix_fill(cpl_matrix *matrix, double value) { if (matrix == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); - } else if (value != 0.0) { - cpl_size size = matrix->nr * matrix->nc; - double *m = matrix->m; + } + else if (value != 0.0) { + cpl_size size = matrix->nr * matrix->nc; + double *m = matrix->m; while (size--) *m++ = value; - - } else { + } + else { (void)memset(matrix->m, 0, (size_t)(matrix->nr * matrix->nc) * sizeof(*matrix->m)); } @@ -1248,13 +1339,11 @@ * Write the same value to a matrix row. Rows are counted starting from 0. */ -cpl_error_code cpl_matrix_fill_row(cpl_matrix *matrix, double value, - cpl_size row) +cpl_error_code +cpl_matrix_fill_row(cpl_matrix *matrix, double value, cpl_size row) { - - - double *m; - cpl_size count; + double *m; + cpl_size count; if (matrix == NULL) @@ -1270,7 +1359,6 @@ *m++ = value; return CPL_ERROR_NONE; - } @@ -1305,13 +1393,11 @@ * from 0. */ -cpl_error_code cpl_matrix_fill_column(cpl_matrix *matrix, - double value, cpl_size column) +cpl_error_code +cpl_matrix_fill_column(cpl_matrix *matrix, double value, cpl_size column) { - - - cpl_size count; - double *m; + cpl_size count; + double *m; if (matrix == NULL) @@ -1329,7 +1415,6 @@ } return CPL_ERROR_NONE; - } @@ -1365,8 +1450,8 @@ * */ -cpl_error_code cpl_matrix_fill_diagonal(cpl_matrix *matrix, - double value, cpl_size diagonal) +cpl_error_code +cpl_matrix_fill_diagonal(cpl_matrix *matrix, double value, cpl_size diagonal) { cpl_size ij, nm; @@ -1375,25 +1460,26 @@ return cpl_error_set_(CPL_ERROR_NULL_INPUT); if (diagonal > matrix->nc) - return cpl_error_set_message_(CPL_ERROR_ACCESS_OUT_OF_RANGE, "d=%" - CPL_SIZE_FORMAT " > c=%" CPL_SIZE_FORMAT, + return cpl_error_set_message_(CPL_ERROR_ACCESS_OUT_OF_RANGE, + "d=%" CPL_SIZE_FORMAT + " > c=%" CPL_SIZE_FORMAT, diagonal, matrix->nc); if (-diagonal > matrix->nr) - return cpl_error_set_message_(CPL_ERROR_ACCESS_OUT_OF_RANGE, "-d=%" - CPL_SIZE_FORMAT " > c=%" CPL_SIZE_FORMAT, + return cpl_error_set_message_(CPL_ERROR_ACCESS_OUT_OF_RANGE, + "-d=%" CPL_SIZE_FORMAT + " > c=%" CPL_SIZE_FORMAT, -diagonal, matrix->nc); nm = diagonal >= 0 ? (matrix->nr - diagonal) * matrix->nc - : matrix->nr * matrix->nc; + : matrix->nr * matrix->nc; - for (ij = diagonal >= 0 ? diagonal : -diagonal * matrix->nc; - ij < nm; ij += matrix->nc + 1) { + for (ij = diagonal >= 0 ? diagonal : -diagonal * matrix->nc; ij < nm; + ij += matrix->nc + 1) { matrix->m[ij] = value; } return CPL_ERROR_NONE; - } @@ -1426,16 +1512,20 @@ * */ -cpl_error_code cpl_matrix_fill_identity(cpl_matrix *self) +cpl_error_code +cpl_matrix_fill_identity(cpl_matrix *self) { if (self == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); - } else if (self->nr != self->nc) { - return cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, "Number of rows " + } + else if (self->nr != self->nc) { + return cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, + "Number of rows " "%d != %d number of columns", (int)self->nr, (int)self->nc); - } else { - double * p = self->m; + } + else { + double *p = self->m; *p = 1.0; for (cpl_size i = 0; i < self->nc - 1; i++) { @@ -1488,18 +1578,19 @@ * is done, but an error condition is set. */ -cpl_error_code cpl_matrix_copy(cpl_matrix *matrix, const cpl_matrix *submatrix, - cpl_size row, cpl_size col) -{ - - - cpl_size endrow; - cpl_size endcol; - cpl_size subrow; - cpl_size subcol; - cpl_size r, c, sr, sc; - double *m; - double *sm; +cpl_error_code +cpl_matrix_copy(cpl_matrix *matrix, + const cpl_matrix *submatrix, + cpl_size row, + cpl_size col) +{ + cpl_size endrow; + cpl_size endcol; + cpl_size subrow; + cpl_size subcol; + cpl_size r, c, sr, sc; + double *m; + double *sm; if (matrix == NULL) @@ -1507,22 +1598,21 @@ if (submatrix == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); - if (row == 0 && col == 0 && - submatrix->nr == matrix->nr && + if (row == 0 && col == 0 && submatrix->nr == matrix->nr && submatrix->nc == matrix->nc) { /* FIXME: Use in more cases */ - return - cpl_tools_copy_window(matrix->m, submatrix->m, sizeof(*matrix->m), - matrix->nc, matrix->nr, 1, 1, - matrix->nc, matrix->nr) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + return cpl_tools_copy_window(matrix->m, submatrix->m, + sizeof(*matrix->m), matrix->nc, matrix->nr, + 1, 1, matrix->nc, matrix->nr) + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } endrow = row + submatrix->nr; endcol = col + submatrix->nc; - /* + /* * Check whether matrices overlap. */ @@ -1530,7 +1620,7 @@ return cpl_error_set_(CPL_ERROR_ACCESS_OUT_OF_RANGE); - /* + /* * Define the overlap region on both matrices reference system: */ @@ -1562,7 +1652,6 @@ } return CPL_ERROR_NONE; - } @@ -1609,16 +1698,18 @@ * case. */ -cpl_error_code cpl_matrix_fill_window(cpl_matrix *matrix, double value, - cpl_size row, cpl_size col, - cpl_size nrow, cpl_size ncol) -{ - - - cpl_size endrow; - cpl_size endcol; - cpl_size r, c; - double *m; +cpl_error_code +cpl_matrix_fill_window(cpl_matrix *matrix, + double value, + cpl_size row, + cpl_size col, + cpl_size nrow, + cpl_size ncol) +{ + cpl_size endrow; + cpl_size endcol; + cpl_size r, c; + double *m; if (matrix == NULL) @@ -1647,7 +1738,6 @@ } return CPL_ERROR_NONE; - } @@ -1680,7 +1770,8 @@ * */ -cpl_error_code cpl_matrix_shift(cpl_matrix *matrix, cpl_size rshift, cpl_size cshift) +cpl_error_code +cpl_matrix_shift(cpl_matrix *matrix, cpl_size rshift, cpl_size cshift) { if (matrix == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -1720,52 +1811,52 @@ if ((rshift > 0 && cshift == 0) || (rshift == 0 && cshift > 0)) { const cpl_size szcp = cshift + rshift * matrix->nc; - void * copy = cpl_malloc((size_t)szcp * sizeof(double)); - double * drow = matrix->m; + void *copy = cpl_malloc((size_t)szcp * sizeof(double)); + double *drow = matrix->m; memcpy(copy, matrix->m + (size_t)(matrix->nr * matrix->nc - szcp), (size_t)szcp * sizeof(double)); memmove(matrix->m + (size_t)szcp, matrix->m, - (size_t)(matrix->nr * matrix->nc - szcp) - * sizeof(double)); + (size_t)(matrix->nr * matrix->nc - szcp) * sizeof(double)); if (cshift > 0) { cpl_size i; for (i = 0; i < matrix->nr - 1; i++, drow += matrix->nc) { - memcpy(drow, drow + (size_t)matrix->nc, (size_t)szcp * sizeof(double)); + memcpy(drow, drow + (size_t)matrix->nc, + (size_t)szcp * sizeof(double)); } } memcpy(drow, copy, (size_t)szcp * sizeof(double)); cpl_free(copy); - - } else if ((rshift < 0 && cshift == 0) || (rshift == 0 && cshift < 0)) { + } + else if ((rshift < 0 && cshift == 0) || (rshift == 0 && cshift < 0)) { const cpl_size szcp = -cshift - rshift * matrix->nc; - void * copy = cpl_malloc((size_t)szcp * sizeof(double)); - double * drow = matrix->m + (size_t)(matrix->nr * matrix->nc - szcp); + void *copy = cpl_malloc((size_t)szcp * sizeof(double)); + double *drow = matrix->m + (size_t)(matrix->nr * matrix->nc - szcp); memcpy(copy, matrix->m, (size_t)szcp * sizeof(double)); memmove(matrix->m, matrix->m + (size_t)szcp, - (size_t)(matrix->nr * matrix->nc - szcp) - * sizeof(double)); + (size_t)(matrix->nr * matrix->nc - szcp) * sizeof(double)); if (cshift < 0) { cpl_size i; for (i = matrix->nr - 1; i > 0; i--, drow -= matrix->nc) { - memcpy(drow, drow - (size_t)matrix->nc, (size_t)szcp * sizeof(double)); + memcpy(drow, drow - (size_t)matrix->nc, + (size_t)szcp * sizeof(double)); } } memcpy(drow, copy, (size_t)szcp * sizeof(double)); cpl_free(copy); - } else if (rshift > 0 && cshift > 0) { + } + else if (rshift > 0 && cshift > 0) { const cpl_size szcp = rshift * matrix->nc + cshift; - double * copy = cpl_malloc((size_t)szcp * sizeof(double)); - double * drow = matrix->m; - const double * crow = copy; + double *copy = cpl_malloc((size_t)szcp * sizeof(double)); + double *drow = matrix->m; + const double *crow = copy; cpl_size i; memcpy(copy, matrix->m + (size_t)(matrix->nr * matrix->nc - szcp), (size_t)szcp * sizeof(double)); memmove(matrix->m + (size_t)szcp, matrix->m, - (size_t)(matrix->nr * matrix->nc - szcp) - * sizeof(double)); + (size_t)(matrix->nr * matrix->nc - szcp) * sizeof(double)); for (i = 0; i < rshift; i++, drow += matrix->nc, crow += matrix->nc) { memcpy(drow, crow + (size_t)matrix->nc, (size_t)cshift * sizeof(double)); @@ -1778,20 +1869,20 @@ } memcpy(drow, copy, (size_t)cshift * sizeof(double)); cpl_free(copy); - } else if (rshift < 0 && cshift < 0) { + } + else if (rshift < 0 && cshift < 0) { const cpl_size szcp = -rshift * matrix->nc - cshift; - double * copy = cpl_malloc((size_t)szcp * sizeof(double)); - double * drow = matrix->m + (size_t)(matrix->nr * matrix->nc + cshift); - const double * crow = copy + szcp - matrix->nc + cshift; + double *copy = cpl_malloc((size_t)szcp * sizeof(double)); + double *drow = matrix->m + (size_t)(matrix->nr * matrix->nc + cshift); + const double *crow = copy + szcp - matrix->nc + cshift; cpl_size i; memcpy(copy, matrix->m, (size_t)szcp * sizeof(double)); memmove(matrix->m, matrix->m + (size_t)szcp, - (size_t)(matrix->nr * matrix->nc - szcp) - * sizeof(double)); + (size_t)(matrix->nr * matrix->nc - szcp) * sizeof(double)); - for (i = matrix->nr; i > matrix->nr + rshift; i--, drow -= matrix->nc, - crow -= matrix->nc) { + for (i = matrix->nr; i > matrix->nr + rshift; + i--, drow -= matrix->nc, crow -= matrix->nc) { memcpy(drow - (size_t)(matrix->nc + cshift), crow - (size_t)cshift, (size_t)(matrix->nc + cshift) * sizeof(double)); memcpy(drow, crow, (size_t)-cshift * sizeof(double)); @@ -1803,18 +1894,18 @@ memcpy(drow, copy + (size_t)(szcp + cshift), (size_t)-cshift * sizeof(double)); cpl_free(copy); - } else if (rshift > 0 && cshift < 0) { + } + else if (rshift > 0 && cshift < 0) { const cpl_size szcp = rshift * matrix->nc; - double * copy = cpl_malloc((size_t)szcp * sizeof(double)); - double * drow = matrix->m + (size_t)(matrix->nr * matrix->nc + cshift); - const double * crow = copy + szcp - matrix->nc; + double *copy = cpl_malloc((size_t)szcp * sizeof(double)); + double *drow = matrix->m + (size_t)(matrix->nr * matrix->nc + cshift); + const double *crow = copy + szcp - matrix->nc; cpl_size i; memcpy(copy, matrix->m + (size_t)(matrix->nr * matrix->nc - szcp), (size_t)szcp * sizeof(double)); memmove(matrix->m + (size_t)szcp + (size_t)cshift, matrix->m, - (size_t)(matrix->nr * matrix->nc - szcp) - * sizeof(double)); + (size_t)(matrix->nr * matrix->nc - szcp) * sizeof(double)); for (i = matrix->nr; i > rshift; i--, drow -= matrix->nc) { memcpy(drow, drow - (size_t)matrix->nc, @@ -1828,11 +1919,12 @@ (size_t)(matrix->nc + cshift) * sizeof(double)); } cpl_free(copy); - } else if (rshift < 0 && cshift > 0) { + } + else if (rshift < 0 && cshift > 0) { const cpl_size szcp = -rshift * matrix->nc; - double * copy = cpl_malloc((size_t)szcp * sizeof(double)); - double * drow = matrix->m; - const double * crow = copy; + double *copy = cpl_malloc((size_t)szcp * sizeof(double)); + double *drow = matrix->m; + const double *crow = copy; cpl_size i; memcpy(copy, matrix->m, (size_t)szcp * sizeof(double)); @@ -1886,12 +1978,11 @@ * a default threshold of @c DBL_EPSILON is used. */ -cpl_error_code cpl_matrix_threshold_small(cpl_matrix *matrix, double tolerance) +cpl_error_code +cpl_matrix_threshold_small(cpl_matrix *matrix, double tolerance) { - - - cpl_size size; - double *m; + cpl_size size; + double *m; if (matrix == NULL) @@ -1911,7 +2002,6 @@ } return CPL_ERROR_NONE; - } @@ -1948,12 +2038,11 @@ */ -int cpl_matrix_is_zero(const cpl_matrix *matrix, double tolerance) +int +cpl_matrix_is_zero(const cpl_matrix *matrix, double tolerance) { - - - cpl_size size; - double *m; + cpl_size size; + double *m; if (matrix == NULL) { @@ -1975,7 +2064,6 @@ } return 1; - } @@ -2007,12 +2095,11 @@ * not square. */ -int cpl_matrix_is_diagonal(const cpl_matrix *matrix, double tolerance) +int +cpl_matrix_is_diagonal(const cpl_matrix *matrix, double tolerance) { - - - cpl_size size; - cpl_size dist; + cpl_size size; + cpl_size dist; if (matrix == NULL) { @@ -2036,7 +2123,6 @@ return 0; return 1; - } @@ -2068,13 +2154,12 @@ * input matrix is not square. */ -int cpl_matrix_is_identity(const cpl_matrix *matrix, double tolerance) +int +cpl_matrix_is_identity(const cpl_matrix *matrix, double tolerance) { - - - double tiny; - cpl_size i; - cpl_size skip; + double tiny; + cpl_size i; + cpl_size skip; if (matrix == NULL) { @@ -2101,7 +2186,6 @@ } return 1; - } @@ -2137,19 +2221,19 @@ * done and no error is set. */ -cpl_error_code cpl_matrix_swap_rows(cpl_matrix *matrix, cpl_size row1, cpl_size row2) +cpl_error_code +cpl_matrix_swap_rows(cpl_matrix *matrix, cpl_size row1, cpl_size row2) { - - cpl_ensure_code(matrix != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(row1 >= 0, CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_ensure_code(matrix != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(row1 >= 0, CPL_ERROR_ACCESS_OUT_OF_RANGE); cpl_ensure_code(row1 < matrix->nr, CPL_ERROR_ACCESS_OUT_OF_RANGE); - cpl_ensure_code(row2 >= 0, CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_ensure_code(row2 >= 0, CPL_ERROR_ACCESS_OUT_OF_RANGE); cpl_ensure_code(row2 < matrix->nr, CPL_ERROR_ACCESS_OUT_OF_RANGE); - if (row1 != row2) swap_rows(matrix, row1, row2); + if (row1 != row2) + swap_rows(matrix, row1, row2); return CPL_ERROR_NONE; - } @@ -2186,26 +2270,24 @@ * nothing is done and no error is set. */ -cpl_error_code cpl_matrix_swap_columns(cpl_matrix *matrix, - cpl_size column1, cpl_size column2) +cpl_error_code +cpl_matrix_swap_columns(cpl_matrix *matrix, cpl_size column1, cpl_size column2) { - - - double swap; - cpl_size nrow; + double swap; + cpl_size nrow; if (matrix == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); - if (column1 < 0 || column1 >= matrix->nc || - column2 < 0 || column2 >= matrix->nc) + if (column1 < 0 || column1 >= matrix->nc || column2 < 0 || + column2 >= matrix->nc) return cpl_error_set_(CPL_ERROR_ACCESS_OUT_OF_RANGE); if (column1 == column2) return CPL_ERROR_NONE; - + nrow = matrix->nr; while (nrow--) { @@ -2217,7 +2299,6 @@ } return CPL_ERROR_NONE; - } @@ -2257,13 +2338,12 @@ * the same sequence number. Rows and columns are counted starting from 0. */ -cpl_error_code cpl_matrix_swap_rowcolumn(cpl_matrix *matrix, cpl_size row) +cpl_error_code +cpl_matrix_swap_rowcolumn(cpl_matrix *matrix, cpl_size row) { - - - double swap; - cpl_size i; - cpl_size posr, posc; + double swap; + cpl_size i; + cpl_size posr, posc; if (matrix == NULL) @@ -2288,7 +2368,6 @@ } return CPL_ERROR_NONE; - } @@ -2314,13 +2393,12 @@ * The order of the rows in the matrix is reversed in place. */ -cpl_error_code cpl_matrix_flip_rows(cpl_matrix *matrix) +cpl_error_code +cpl_matrix_flip_rows(cpl_matrix *matrix) { + cpl_size i, j; - cpl_size i, j; - - if (matrix == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -2329,7 +2407,6 @@ swap_rows(matrix, i, j); return CPL_ERROR_NONE; - } @@ -2355,22 +2432,20 @@ * The order of the columns in the matrix is reversed in place. */ -cpl_error_code cpl_matrix_flip_columns(cpl_matrix *matrix) +cpl_error_code +cpl_matrix_flip_columns(cpl_matrix *matrix) { - - - cpl_size i, j; + cpl_size i, j; if (matrix == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); - for (i = 0, j = matrix->nc - 1; i < j; i++, j--) + for (i = 0, j = matrix->nc - 1; i < j; i++, j--) cpl_matrix_swap_columns(matrix, i, j); return CPL_ERROR_NONE; - } @@ -2398,14 +2473,13 @@ * the function @c cpl_matrix_delete() should be used. */ -cpl_matrix *cpl_matrix_transpose_create(const cpl_matrix *matrix) +cpl_matrix * +cpl_matrix_transpose_create(const cpl_matrix *matrix) { - - - cpl_matrix *transposed = NULL; - cpl_size i, j; - double *m; - double *tm; + cpl_matrix *transposed = NULL; + cpl_size i, j; + double *m; + double *tm; if (matrix == NULL) { @@ -2414,18 +2488,17 @@ } - tm = (double *)cpl_malloc((size_t)matrix->nc * (size_t)matrix->nr - * sizeof(*tm)); + tm = (double *)cpl_malloc((size_t)matrix->nc * (size_t)matrix->nr * + sizeof(*tm)); transposed = cpl_matrix_wrap(matrix->nc, matrix->nr, tm); m = matrix->m; for (i = 0; i < matrix->nr; i++) - for (j = 0, tm = transposed->m + i; - j < matrix->nc; j++, tm += matrix->nr) + for (j = 0, tm = transposed->m + i; j < matrix->nc; + j++, tm += matrix->nr) *tm = *m++; return transposed; - } @@ -2456,20 +2529,19 @@ * absolute values (zeroes at bottom). */ -cpl_error_code cpl_matrix_sort_rows(cpl_matrix *matrix, int mode) +cpl_error_code +cpl_matrix_sort_rows(cpl_matrix *matrix, int mode) { + double *row; + double value1, value2; - - double *row; - double value1, value2; - - int *done; + int *done; cpl_size *sort_pattern; cpl_size *p; cpl_size i, j; cpl_size keep; cpl_size reach; - int start; + int start; cpl_size count; cpl_size pos; @@ -2478,7 +2550,7 @@ return cpl_error_set_(CPL_ERROR_NULL_INPUT); if (matrix->nr == 1) - return CPL_ERROR_NONE; + return CPL_ERROR_NONE; /* * Allocate the arrays for computing the sort pattern (i.e., the @@ -2502,9 +2574,8 @@ reach = 1; while (i < matrix->nr) { - value1 = matrix->m[p[i] * matrix->nc + j]; - value2 = matrix->m[p[i-1] * matrix->nc + j]; + value2 = matrix->m[p[i - 1] * matrix->nc + j]; if (mode == 0) { value1 = fabs(value1); @@ -2517,8 +2588,8 @@ reach = i; } else if (value1 > value2) { - keep = p[i-1]; - p[i-1] = p[i]; + keep = p[i - 1]; + p[i - 1] = p[i]; p[i] = keep; if (i > 1) i--; @@ -2544,7 +2615,6 @@ j = 0; continue; } - } @@ -2555,14 +2625,14 @@ reach = 1; i = 1; while (i < matrix->nr) { - if (p[sort_pattern[i]] > p[sort_pattern[i-1]]) { + if (p[sort_pattern[i]] > p[sort_pattern[i - 1]]) { i++; if (i > reach) reach = i; } else { - keep = sort_pattern[i-1]; - sort_pattern[i-1] = sort_pattern[i]; + keep = sort_pattern[i - 1]; + sort_pattern[i - 1] = sort_pattern[i]; sort_pattern[i] = keep; if (i > 1) i--; @@ -2590,22 +2660,19 @@ pos = 0; start = 1; count = matrix->nr; - - while (count--) { + while (count--) { done[pos] = 1; if (pos == sort_pattern[pos]) { - if (count) for (pos = 0; pos < matrix->nr; pos++) - if (!done[pos]) { - start = 1; - break; - } + if (!done[pos]) { + start = 1; + break; + } continue; - } if (start) { @@ -2616,22 +2683,19 @@ pos = sort_pattern[pos]; if (done[pos]) { - write_row(matrix, row, pos); if (count) { for (pos = 0; pos < matrix->nr; pos++) { - if (!done[pos]) { - start = 1; - break; - } + if (!done[pos]) { + start = 1; + break; + } } } - } else write_read_row(matrix, row, pos); - } cpl_free(sort_pattern); @@ -2639,7 +2703,6 @@ cpl_free(row); return CPL_ERROR_NONE; - } @@ -2670,20 +2733,19 @@ * to their absolute values (zeroes at left). */ -cpl_error_code cpl_matrix_sort_columns(cpl_matrix *matrix, int mode) +cpl_error_code +cpl_matrix_sort_columns(cpl_matrix *matrix, int mode) { + double *column; + double value1, value2; - - double *column; - double value1, value2; - - int *done; - int *sort_pattern; - int *p; - int i, j; - int keep; - int reach; - int start; + int *done; + int *sort_pattern; + int *p; + int i, j; + int keep; + int reach; + int start; cpl_size count; cpl_size pos; @@ -2692,7 +2754,7 @@ return cpl_error_set_(CPL_ERROR_NULL_INPUT); if (matrix->nc == 1) - return CPL_ERROR_NONE; + return CPL_ERROR_NONE; /* * Allocate the arrays for computing the sort pattern (i.e., the @@ -2716,9 +2778,8 @@ reach = 1; while (i < matrix->nc) { - value1 = matrix->m[j * matrix->nc + p[i]]; - value2 = matrix->m[j * matrix->nc + p[i-1]]; + value2 = matrix->m[j * matrix->nc + p[i - 1]]; if (mode == 0) { value1 = fabs(value1); @@ -2731,8 +2792,8 @@ reach = i; } else if (value1 < value2) { - keep = p[i-1]; - p[i-1] = p[i]; + keep = p[i - 1]; + p[i - 1] = p[i]; p[i] = keep; if (i > 1) i--; @@ -2758,7 +2819,6 @@ j = 0; continue; } - } @@ -2769,14 +2829,14 @@ reach = 1; i = 1; while (i < matrix->nc) { - if (p[sort_pattern[i]] > p[sort_pattern[i-1]]) { + if (p[sort_pattern[i]] > p[sort_pattern[i - 1]]) { i++; if (i > reach) reach = i; } else { - keep = sort_pattern[i-1]; - sort_pattern[i-1] = sort_pattern[i]; + keep = sort_pattern[i - 1]; + sort_pattern[i - 1] = sort_pattern[i]; sort_pattern[i] = keep; if (i > 1) i--; @@ -2804,22 +2864,19 @@ pos = 0; start = 1; count = matrix->nc; - - while (count--) { + while (count--) { done[pos] = 1; if (pos == sort_pattern[pos]) { - if (count) for (pos = 0; pos < matrix->nc; pos++) - if (!done[pos]) { - start = 1; - break; - } + if (!done[pos]) { + start = 1; + break; + } continue; - } if (start) { @@ -2830,22 +2887,19 @@ pos = sort_pattern[pos]; if (done[pos]) { - write_column(matrix, column, pos); if (count) { for (pos = 0; pos < matrix->nc; pos++) { - if (!done[pos]) { - start = 1; - break; - } + if (!done[pos]) { + start = 1; + break; + } } } - } else write_read_column(matrix, column, pos); - } cpl_free(sort_pattern); @@ -2853,7 +2907,6 @@ cpl_free(column); return CPL_ERROR_NONE; - } @@ -2904,17 +2957,15 @@ * matrices are illegal. Rows are counted starting from 0. */ -cpl_error_code cpl_matrix_erase_rows(cpl_matrix *matrix, cpl_size start, - cpl_size count) +cpl_error_code +cpl_matrix_erase_rows(cpl_matrix *matrix, cpl_size start, cpl_size count) { + double *m1; + double *m2; + cpl_size size; + cpl_size i; - double *m1; - double *m2; - cpl_size size; - cpl_size i; - - if (matrix == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -2933,7 +2984,7 @@ size = matrix->nr * matrix->nc; m1 = matrix->m + start * matrix->nc; m2 = m1 + count * matrix->nc; - + for (i = (start + count) * matrix->nc; i < size; i++) *m1++ = *m2++; @@ -2944,7 +2995,6 @@ matrix->nr -= count; return CPL_ERROR_NONE; - } @@ -2995,16 +3045,14 @@ * matrices are illegal. Columns are counted starting from 0. */ -cpl_error_code cpl_matrix_erase_columns(cpl_matrix *matrix, - cpl_size start, cpl_size count) +cpl_error_code +cpl_matrix_erase_columns(cpl_matrix *matrix, cpl_size start, cpl_size count) { - - - double *m1; - double *m2; - cpl_size size; - cpl_size new_nc; - cpl_size i, j; + double *m1; + double *m2; + cpl_size size; + cpl_size new_nc; + cpl_size i, j; if (matrix == NULL) @@ -3025,7 +3073,6 @@ new_nc = matrix->nc - count; for (j = 0; j < matrix->nr; j++) { - m1 = matrix->m + j * new_nc; m2 = matrix->m + j * matrix->nc; @@ -3036,7 +3083,6 @@ for (i += count; i < matrix->nc; i++) *m1++ = *m2++; - } size = (matrix->nc - count) * matrix->nr; @@ -3046,7 +3092,6 @@ matrix->nc -= count; return CPL_ERROR_NONE; - } @@ -3095,14 +3140,15 @@ * should be discarded. */ -cpl_error_code cpl_matrix_resize(cpl_matrix *matrix, - cpl_size top, cpl_size bottom, - cpl_size left, cpl_size right) +cpl_error_code +cpl_matrix_resize(cpl_matrix *matrix, + cpl_size top, + cpl_size bottom, + cpl_size left, + cpl_size right) { - - - cpl_matrix *resized; - cpl_size nr, nc; + cpl_matrix *resized; + cpl_size nr, nc; if (matrix == NULL) @@ -3128,7 +3174,6 @@ matrix->nc = nc; return CPL_ERROR_NONE; - } @@ -3170,14 +3215,13 @@ * should be discarded. */ -cpl_error_code cpl_matrix_set_size(cpl_matrix *matrix, cpl_size rows, - cpl_size columns) +cpl_error_code +cpl_matrix_set_size(cpl_matrix *matrix, cpl_size rows, cpl_size columns) { - - return cpl_matrix_resize(matrix, 0, rows - matrix->nr, - 0, columns - matrix->nc) - ? cpl_error_set_where_() : CPL_ERROR_NONE; - + return cpl_matrix_resize(matrix, 0, rows - matrix->nr, 0, + columns - matrix->nc) + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -3228,19 +3272,19 @@ * should be discarded. */ -cpl_error_code cpl_matrix_append(cpl_matrix *matrix1, - const cpl_matrix *matrix2, int mode) +cpl_error_code +cpl_matrix_append(cpl_matrix *matrix1, const cpl_matrix *matrix2, int mode) { - - cpl_size old_size; if (matrix1 == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); - } else if (matrix2 == NULL) { + } + else if (matrix2 == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); - } else if (mode == 0) { + } + else if (mode == 0) { if (matrix1->nr != matrix2->nr) return cpl_error_set_(CPL_ERROR_INCOMPATIBLE_INPUT); @@ -3248,7 +3292,8 @@ cpl_matrix_resize(matrix1, 0, 0, 0, matrix2->nc); cpl_matrix_copy(matrix1, matrix2, 0, old_size); - } else if (mode == 1) { + } + else if (mode == 1) { if (matrix1->nc != matrix2->nc) return cpl_error_set_(CPL_ERROR_INCOMPATIBLE_INPUT); @@ -3256,12 +3301,12 @@ cpl_matrix_resize(matrix1, 0, matrix2->nr, 0, 0); cpl_matrix_copy(matrix1, matrix2, old_size, 0); - } else { + } + else { return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); } return CPL_ERROR_NONE; - } @@ -3295,13 +3340,12 @@ * identical sizes. The result is written to the first matrix. */ -cpl_error_code cpl_matrix_add(cpl_matrix *matrix1, const cpl_matrix *matrix2) +cpl_error_code +cpl_matrix_add(cpl_matrix *matrix1, const cpl_matrix *matrix2) { - - - cpl_size size; - double *m1; - double *m2; + cpl_size size; + double *m1; + double *m2; if (matrix1 == NULL || matrix2 == NULL) @@ -3310,17 +3354,16 @@ if (matrix1->nr != matrix2->nr || matrix1->nc != matrix2->nc) return cpl_error_set_(CPL_ERROR_INCOMPATIBLE_INPUT); - + size = matrix1->nr * matrix1->nc; m1 = matrix1->m; m2 = matrix2->m; - cpl_tools_add_flops( (cpl_flops)size ); + cpl_tools_add_flops((cpl_flops)size); while (size--) *m1++ += *m2++; return CPL_ERROR_NONE; - } @@ -3355,14 +3398,12 @@ * to the first matrix. */ -cpl_error_code cpl_matrix_subtract(cpl_matrix *matrix1, - const cpl_matrix *matrix2) +cpl_error_code +cpl_matrix_subtract(cpl_matrix *matrix1, const cpl_matrix *matrix2) { - - - cpl_size size; - double *m1; - double *m2; + cpl_size size; + double *m1; + double *m2; if (matrix1 == NULL || matrix2 == NULL) @@ -3370,17 +3411,16 @@ if (matrix1->nr != matrix2->nr || matrix1->nc != matrix2->nc) return cpl_error_set_(CPL_ERROR_INCOMPATIBLE_INPUT); - + size = matrix1->nr * matrix1->nc; m1 = matrix1->m; m2 = matrix2->m; - cpl_tools_add_flops( (cpl_flops)size ); + cpl_tools_add_flops((cpl_flops)size); while (size--) *m1++ -= *m2++; return CPL_ERROR_NONE; - } @@ -3418,14 +3458,12 @@ * @c cpl_matrix_product_create() should be used instead. */ -cpl_error_code cpl_matrix_multiply(cpl_matrix *matrix1, - const cpl_matrix *matrix2) +cpl_error_code +cpl_matrix_multiply(cpl_matrix *matrix1, const cpl_matrix *matrix2) { - - - cpl_size size; - double *m1; - double *m2; + cpl_size size; + double *m1; + double *m2; if (matrix1 == NULL || matrix2 == NULL) @@ -3438,12 +3476,11 @@ m1 = matrix1->m; m2 = matrix2->m; - cpl_tools_add_flops( (cpl_flops)size ); + cpl_tools_add_flops((cpl_flops)size); while (size--) *m1++ *= *m2++; return CPL_ERROR_NONE; - } @@ -3479,14 +3516,12 @@ * matrix. No check is made against a division by zero. */ -cpl_error_code cpl_matrix_divide(cpl_matrix *matrix1, - const cpl_matrix *matrix2) +cpl_error_code +cpl_matrix_divide(cpl_matrix *matrix1, const cpl_matrix *matrix2) { - - - cpl_size size; - double *m1; - double *m2; + cpl_size size; + double *m1; + double *m2; if (matrix1 == NULL || matrix2 == NULL) @@ -3499,12 +3534,11 @@ m1 = matrix1->m; m2 = matrix2->m; - cpl_tools_add_flops( (cpl_flops)size ); + cpl_tools_add_flops((cpl_flops)size); while (size--) *m1++ /= *m2++; return CPL_ERROR_NONE; - } @@ -3531,12 +3565,11 @@ * Add the same value to each matrix element. */ -cpl_error_code cpl_matrix_add_scalar(cpl_matrix *matrix, double value) +cpl_error_code +cpl_matrix_add_scalar(cpl_matrix *matrix, double value) { - - - cpl_size size; - double *m; + cpl_size size; + double *m; if (matrix == NULL) @@ -3545,12 +3578,11 @@ size = matrix->nr * matrix->nc; m = matrix->m; - cpl_tools_add_flops( (cpl_flops)size ); + cpl_tools_add_flops((cpl_flops)size); while (size--) *m++ += value; return CPL_ERROR_NONE; - } @@ -3577,12 +3609,11 @@ * Subtract the same value to each matrix element. */ -cpl_error_code cpl_matrix_subtract_scalar(cpl_matrix *matrix, double value) +cpl_error_code +cpl_matrix_subtract_scalar(cpl_matrix *matrix, double value) { - - - cpl_size size; - double *m; + cpl_size size; + double *m; if (matrix == NULL) @@ -3591,12 +3622,11 @@ size = matrix->nr * matrix->nc; m = matrix->m; - cpl_tools_add_flops( (cpl_flops)size ); + cpl_tools_add_flops((cpl_flops)size); while (size--) *m++ -= value; - - return CPL_ERROR_NONE; + return CPL_ERROR_NONE; } @@ -3623,12 +3653,11 @@ * Multiply each matrix element by the same factor. */ -cpl_error_code cpl_matrix_multiply_scalar(cpl_matrix *matrix, double value) +cpl_error_code +cpl_matrix_multiply_scalar(cpl_matrix *matrix, double value) { - - - cpl_size size; - double *m; + cpl_size size; + double *m; if (matrix == NULL) @@ -3637,12 +3666,11 @@ size = matrix->nr * matrix->nc; m = matrix->m; - cpl_tools_add_flops( (cpl_flops)size ); + cpl_tools_add_flops((cpl_flops)size); while (size--) *m++ *= value; return CPL_ERROR_NONE; - } @@ -3674,13 +3702,12 @@ * * Divide each matrix element by the same value. */ - -cpl_error_code cpl_matrix_divide_scalar(cpl_matrix *matrix, double value) -{ - +cpl_error_code +cpl_matrix_divide_scalar(cpl_matrix *matrix, double value) +{ cpl_size size; - double *m; + double *m; if (matrix == NULL) @@ -3692,12 +3719,11 @@ size = matrix->nr * matrix->nc; m = matrix->m; - cpl_tools_add_flops( (cpl_flops)size ); + cpl_tools_add_flops((cpl_flops)size); while (size--) *m++ /= value; return CPL_ERROR_NONE; - } @@ -3733,13 +3759,12 @@ * case, the matrix would not be modified. */ -cpl_error_code cpl_matrix_logarithm(cpl_matrix *matrix, double base) +cpl_error_code +cpl_matrix_logarithm(cpl_matrix *matrix, double base) { - - - cpl_size size; - double *m; - double logbase; + cpl_size size; + double *m; + double logbase; if (matrix == NULL) @@ -3763,14 +3788,13 @@ size = matrix->nr * matrix->nc; m = matrix->m; - cpl_tools_add_flops( 1 + 2 * (cpl_flops)size ); + cpl_tools_add_flops(1 + 2 * (cpl_flops)size); while (size--) { *m = log(*m) / logbase; m++; } return CPL_ERROR_NONE; - } @@ -3804,12 +3828,11 @@ * The base must be positive. */ -cpl_error_code cpl_matrix_exponential(cpl_matrix *matrix, double base) +cpl_error_code +cpl_matrix_exponential(cpl_matrix *matrix, double base) { - - - cpl_size size; - double *m; + cpl_size size; + double *m; if (matrix == NULL) @@ -3821,14 +3844,13 @@ size = matrix->nr * matrix->nc; m = matrix->m; - cpl_tools_add_flops( (cpl_flops)size ); + cpl_tools_add_flops((cpl_flops)size); while (size--) { *m = pow(base, *m); m++; } return CPL_ERROR_NONE; - } @@ -3869,13 +3891,12 @@ * (non negative) matrix element would be assigned the value 1.0. */ -cpl_error_code cpl_matrix_power(cpl_matrix *matrix, double exponent) +cpl_error_code +cpl_matrix_power(cpl_matrix *matrix, double exponent) { - - - cpl_size size; - double *m; - int negative = exponent < 0.0; + cpl_size size; + double *m; + int negative = exponent < 0.0; if (matrix == NULL) @@ -3905,7 +3926,7 @@ size = matrix->nr * matrix->nc; m = matrix->m; - cpl_tools_add_flops( (cpl_flops)size ); + cpl_tools_add_flops((cpl_flops)size); if (negative) { while (size--) { *m = 1 / pow(*m, exponent); @@ -3928,7 +3949,6 @@ } return CPL_ERROR_NONE; - } @@ -3965,25 +3985,23 @@ * be used. */ -cpl_matrix *cpl_matrix_product_create(const cpl_matrix *matrix1, - const cpl_matrix *matrix2) +cpl_matrix * +cpl_matrix_product_create(const cpl_matrix *matrix1, const cpl_matrix *matrix2) { + cpl_matrix *self; - cpl_matrix *self; - - cpl_ensure(matrix1 != NULL, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(matrix2 != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(matrix1 != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(matrix2 != NULL, CPL_ERROR_NULL_INPUT, NULL); cpl_ensure(matrix1->nc == matrix2->nr, CPL_ERROR_INCOMPATIBLE_INPUT, NULL); /* Create data-buffer without overhead of initializing */ self = cpl_matrix_wrap(matrix1->nr, matrix2->nc, - cpl_malloc((size_t)matrix1->nr * (size_t)matrix2->nc - * sizeof(*self))); + cpl_malloc((size_t)matrix1->nr * + (size_t)matrix2->nc * sizeof(*self))); - (void) cpl_matrix_product(self, matrix1, matrix2); + (void)cpl_matrix_product(self, matrix1, matrix2); return self; - } @@ -4033,23 +4051,22 @@ * @enderror * */ -cpl_error_code cpl_matrix_decomp_lu(cpl_matrix * self, cpl_array * perm, - int * psig) +cpl_error_code +cpl_matrix_decomp_lu(cpl_matrix *self, cpl_array *perm, int *psig) { - - const cpl_size n = cpl_array_get_size(perm); - int * iperm = cpl_array_get_data_int(perm); - int nn; - cpl_size i, j; - const double * aread; - double * awrite; + const cpl_size n = cpl_array_get_size(perm); + int *iperm = cpl_array_get_data_int(perm); + int nn; + cpl_size i, j; + const double *aread; + double *awrite; cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(perm != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(psig != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(self->nc == self->nr, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(self->nc == n, CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_ensure_code(self->nc == n, CPL_ERROR_INCOMPATIBLE_INPUT); cpl_ensure_code(cpl_array_get_type(perm) == CPL_TYPE_INT, CPL_ERROR_TYPE_MISMATCH); @@ -4070,19 +4087,21 @@ cpl_size ipivot = j; for (i = j + 1; i < n; i++) { - const double aij = fabs(aread[j + i * n]); + const double aij = fabs(aread[j + i * n]); - if (aij > pivot) { - pivot = aij; - ipivot = i; - } + if (aij > pivot) { + pivot = aij; + ipivot = i; + } } if (pivot <= 0.0) { - return cpl_error_set_message_(CPL_ERROR_SINGULAR_MATRIX, "Pivot %" - CPL_SIZE_FORMAT " of %" - CPL_SIZE_FORMAT " is non-positive: " - "%g", j, n, pivot); + return cpl_error_set_message_(CPL_ERROR_SINGULAR_MATRIX, + "Pivot %" CPL_SIZE_FORMAT + " of %" CPL_SIZE_FORMAT + " is non-positive: " + "%g", + j, n, pivot); } if (ipivot > j) { @@ -4092,7 +4111,7 @@ iperm[j] = iperm[ipivot]; iperm[ipivot] = iswap; - *psig = - (*psig); + *psig = -(*psig); swap_rows(self, j, ipivot); } @@ -4112,13 +4131,15 @@ } } } - cpl_tools_add_flops( (cpl_flops)(2 * n * n * n) / 3); + cpl_tools_add_flops((cpl_flops)(2 * n * n * n) / 3); /* Check if A(n,n) is non-zero */ - return fabs(aread[n * (n-1) + (n-1)]) > 0.0 ? CPL_ERROR_NONE - : cpl_error_set_message_(CPL_ERROR_SINGULAR_MATRIX, "The last of %" - CPL_SIZE_FORMAT " pivot(s) is zero", n); - + return fabs(aread[n * (n - 1) + (n - 1)]) > 0.0 + ? CPL_ERROR_NONE + : cpl_error_set_message_(CPL_ERROR_SINGULAR_MATRIX, + "The last of %" CPL_SIZE_FORMAT + " pivot(s) is zero", + n); } /* @@ -4167,23 +4188,24 @@ * @enderror * */ -cpl_error_code cpl_matrix_solve_lu(const cpl_matrix * self, - cpl_matrix * rhs, const cpl_array * perm) +cpl_error_code +cpl_matrix_solve_lu(const cpl_matrix *self, + cpl_matrix *rhs, + const cpl_array *perm) { - - const int * iperm = NULL; + const int *iperm = NULL; cpl_size n, i, j, k; - double * x = NULL; /* Avoid false uninit warning */ - const double * aread; - const double * bread; - double * bwrite; - cpl_ifalloc mybuf; + double *x = NULL; /* Avoid false uninit warning */ + const double *aread; + const double *bread; + double *bwrite; + cpl_ifalloc mybuf; cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(rhs != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(rhs != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(self->nc == self->nr, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(rhs->nr == self->nr, CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_ensure_code(rhs->nr == self->nr, CPL_ERROR_INCOMPATIBLE_INPUT); n = self->nc; @@ -4191,7 +4213,6 @@ bread = bwrite = rhs->m; if (perm != NULL) { - cpl_ensure_code(cpl_array_get_size(perm) == n, CPL_ERROR_INCOMPATIBLE_INPUT); cpl_ensure_code(cpl_array_get_type(perm) == CPL_TYPE_INT, @@ -4200,10 +4221,10 @@ iperm = cpl_array_get_data_int_const(perm); cpl_ifalloc_set(&mybuf, (size_t)n * sizeof(*x)); - x = (double*)cpl_ifalloc_get(&mybuf); + x = (double *)cpl_ifalloc_get(&mybuf); } - for (k=0; k < rhs->nc; k++) { + for (k = 0; k < rhs->nc; k++) { if (perm != NULL) { /* Un-permute the rows in column k */ for (i = 0; i < n; i++) { @@ -4235,23 +4256,24 @@ } /* Check for a bug in the calling function */ - if (aread[n * i + i] == 0.0) break; - - bwrite[rhs->nc * i + k] = tmp/aread[n * i + i]; + if (aread[n * i + i] == 0.0) + break; + bwrite[rhs->nc * i + k] = tmp / aread[n * i + i]; } - if (i >= 0) break; + if (i >= 0) + break; } - if (perm != NULL) cpl_ifalloc_free(&mybuf); + if (perm != NULL) + cpl_ifalloc_free(&mybuf); /* Flop count may be a bit too high if the below check fails */ - cpl_tools_add_flops( (cpl_flops)(k * 2 * n * n) ); + cpl_tools_add_flops((cpl_flops)(k * 2 * n * n)); return k == rhs->nc ? CPL_ERROR_NONE - : cpl_error_set_(CPL_ERROR_DIVISION_BY_ZERO); - + : cpl_error_set_(CPL_ERROR_DIVISION_BY_ZERO); } @@ -4290,50 +4312,59 @@ @enderror */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_matrix_decomp_chol(cpl_matrix * self) +cpl_error_code +cpl_matrix_decomp_chol(cpl_matrix *self) { - - const cpl_size n = cpl_matrix_get_ncol(self); - double * awrite = cpl_matrix_get_data(self); - const double * aread = awrite; - double sub = 0.0; /* Fix (false) uninit warning */ + cpl_size n; + double *awrite; + const double *aread; + double sub = 0.0; /* Fix (false) uninit warning */ cpl_size i, j = 0; /* Fix (false) uninit warning */ cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(cpl_matrix_get_nrow(self) == n, CPL_ERROR_ILLEGAL_INPUT); + + n = cpl_matrix_get_ncol_(self); + cpl_ensure_code(cpl_matrix_get_nrow_(self) == n, CPL_ERROR_ILLEGAL_INPUT); + + aread = awrite = cpl_matrix_get_data_(self); for (i = 0; i < n; i++) { for (j = i; j < n; j++) { cpl_size k; sub = aread[n * i + j]; - for (k = i-1; k >= 0; k--) { + for (k = i - 1; k >= 0; k--) { sub -= aread[n * i + k] * aread[n * j + k]; } if (j > i) { - awrite[n * j + i] = sub/aread[n * i + i]; - } else if (sub > 0.0) { + awrite[n * j + i] = sub / aread[n * i + i]; + } + else if (sub > 0.0) { awrite[n * i + i] = sqrt(sub); - } else { + } + else { break; } } - if (j < n) break; + if (j < n) + break; } /* Dominant term: N^3 / 3 */ /* FIXME: Probably inexact on error */ - cpl_tools_add_flops((cpl_flops)( i * ( 1 + j * ( 3 + 2 * n))) / 6); + cpl_tools_add_flops((cpl_flops)(i * (1 + j * (3 + 2 * n))) / 6); return i == n ? CPL_ERROR_NONE - : cpl_error_set_message_(CPL_ERROR_SINGULAR_MATRIX, "Pivot " - "%" CPL_SIZE_FORMAT " of %" CPL_SIZE_FORMAT - " is non-positive: %g", i+1, n, sub); + : cpl_error_set_message_(CPL_ERROR_SINGULAR_MATRIX, + "Pivot " + "%" CPL_SIZE_FORMAT + " of %" CPL_SIZE_FORMAT + " is non-positive: %g", + i + 1, n, sub); } - /*----------------------------------------------------------------------------*/ /** @brief Solve a L*transpose(L)-system @@ -4375,59 +4406,57 @@ @enderror */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_matrix_solve_chol(const cpl_matrix * self, - cpl_matrix * rhs) +cpl_error_code +cpl_matrix_solve_chol(const cpl_matrix *self, cpl_matrix *rhs) { - - const cpl_size n = cpl_matrix_get_ncol(self); - const cpl_size nrhs = cpl_matrix_get_ncol(rhs); + cpl_size n, nrhs; cpl_size i, j, k; - const double * aread; - const double * bread; - double * bwrite; + const double *aread; + const double *bread; + double *bwrite; cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(rhs != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(rhs != NULL, CPL_ERROR_NULL_INPUT); + + n = cpl_matrix_get_ncol_(self); + nrhs = cpl_matrix_get_ncol_(rhs); - cpl_ensure_code(cpl_matrix_get_nrow(self) == n, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(cpl_matrix_get_nrow(rhs) == n, CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_ensure_code(cpl_matrix_get_nrow_(self) == n, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(cpl_matrix_get_nrow_(rhs) == n, + CPL_ERROR_INCOMPATIBLE_INPUT); - aread = cpl_matrix_get_data_const(self); - bread = bwrite = cpl_matrix_get_data(rhs); + aread = cpl_matrix_get_data_const_(self); + bread = bwrite = cpl_matrix_get_data_(rhs); - for (k=0; k < nrhs; k++) { + for (k = 0; k < nrhs; k++) { /* Forward substitution in column k */ for (i = 0; i < n; i++) { double sub = bread[nrhs * i + k]; - for (j = i-1; j >= 0; j--) { + for (j = i - 1; j >= 0; j--) { sub -= aread[n * i + j] * bread[nrhs * j + k]; } cpl_ensure_code(aread[n * i + i] != 0.0, CPL_ERROR_DIVISION_BY_ZERO); - bwrite[nrhs * i + k] = sub/aread[n * i + i]; + bwrite[nrhs * i + k] = sub / aread[n * i + i]; } /* Back substitution in column k */ - for (i = n-1; i >= 0; i--) { + for (i = n - 1; i >= 0; i--) { double sub = bread[nrhs * i + k]; - for (j = i+1; j < n; j++) { + for (j = i + 1; j < n; j++) { sub -= aread[n * j + i] * bread[nrhs * j + k]; } - bwrite[nrhs * i + k] = sub/aread[n * i + i]; + bwrite[nrhs * i + k] = sub / aread[n * i + i]; } } - cpl_tools_add_flops( 2 * (cpl_flops)(n * n * nrhs)); + cpl_tools_add_flops(2 * (cpl_flops)(n * n * nrhs)); return CPL_ERROR_NONE; - } - - - /** * @brief * Compute the determinant of a matrix. @@ -4464,22 +4493,22 @@ * the matrix single element value is returned. */ -double cpl_matrix_get_determinant(const cpl_matrix *matrix) +double +cpl_matrix_get_determinant(const cpl_matrix *matrix) { - - cpl_matrix * self; - cpl_array * perm; - int * iperm; - double determinant; - int sig; + cpl_matrix *self; + cpl_array *perm; + int *iperm; + double determinant; + int sig; cpl_errorstate prevstate = cpl_errorstate_get(); cpl_error_code error; - cpl_ensure(matrix != NULL, CPL_ERROR_NULL_INPUT, 0.0); + cpl_ensure(matrix != NULL, CPL_ERROR_NULL_INPUT, 0.0); cpl_ensure(matrix->nr == matrix->nc, CPL_ERROR_ILLEGAL_INPUT, 0.0); - iperm = (int*) cpl_malloc((size_t)matrix->nr * sizeof(*iperm)); + iperm = (int *)cpl_malloc((size_t)matrix->nr * sizeof(*iperm)); perm = cpl_array_wrap_int(iperm, matrix->nr); @@ -4494,12 +4523,12 @@ /* Use long double because the intermediate products may vary greatly */ cpl_long_double ldet = (cpl_long_double)sig; for (i = 0; i < matrix->nr; i++) { - const double aii = cpl_matrix_get(self, i, i); + const double aii = cpl_matrix_get_(self, i, i); ldet *= (cpl_long_double)aii; - if (ldet == 0.0) break; - + if (ldet == 0.0) + break; } determinant = (double)ldet; @@ -4508,19 +4537,20 @@ (void)cpl_error_set_message_(CPL_ERROR_UNSPECIFIED, "Underflow at pivot %" CPL_SIZE_FORMAT " of %" CPL_SIZE_FORMAT, - 1+i, matrix->nr); - } else if (determinant == 0.0) { + 1 + i, matrix->nr); + } + else if (determinant == 0.0) { (void)cpl_error_set_message_(CPL_ERROR_UNSPECIFIED, "Underflow at %Lg", ldet); } - - } else { - + } + else { determinant = 0.0; if (error == CPL_ERROR_SINGULAR_MATRIX) { cpl_errorstate_set(prevstate); - } else { + } + else { /* Should not be able to enter here */ (void)cpl_error_set_where_(); } @@ -4529,7 +4559,6 @@ cpl_matrix_delete(self); return determinant; - } @@ -4586,29 +4615,29 @@ * */ -cpl_matrix *cpl_matrix_solve(const cpl_matrix *coeff, const cpl_matrix *rhs) +cpl_matrix * +cpl_matrix_solve(const cpl_matrix *coeff, const cpl_matrix *rhs) { - - cpl_matrix * lu; - cpl_matrix * x; - cpl_array * perm; - int * iperm; - cpl_size n; + cpl_matrix *lu; + cpl_matrix *x; + cpl_array *perm; + int *iperm; + cpl_size n; cpl_error_code code; cpl_ensure(coeff != NULL, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(rhs != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(rhs != NULL, CPL_ERROR_NULL_INPUT, NULL); n = coeff->nc; cpl_ensure(coeff->nr == n, CPL_ERROR_ILLEGAL_INPUT, NULL); - cpl_ensure(rhs->nr == n, CPL_ERROR_INCOMPATIBLE_INPUT, NULL); + cpl_ensure(rhs->nr == n, CPL_ERROR_INCOMPATIBLE_INPUT, NULL); lu = cpl_matrix_duplicate(coeff); - x = cpl_matrix_duplicate(rhs); + x = cpl_matrix_duplicate(rhs); - iperm = (int*) cpl_malloc((size_t)n * sizeof(*iperm)); + iperm = (int *)cpl_malloc((size_t)n * sizeof(*iperm)); perm = cpl_array_wrap_int(iperm, n); code = cpl_matrix_solve_(lu, x, perm); @@ -4666,15 +4695,15 @@ * any error code being set. */ -cpl_matrix *cpl_matrix_invert_create(const cpl_matrix *matrix) +cpl_matrix * +cpl_matrix_invert_create(const cpl_matrix *matrix) { - - cpl_matrix * lu; - cpl_matrix * inverse; - cpl_array * perm; - int * iperm; - cpl_size n, i; - int sig, nn; + cpl_matrix *lu; + cpl_matrix *inverse; + cpl_array *perm; + int *iperm; + cpl_size n, i; + int sig, nn; cpl_error_code error; @@ -4690,7 +4719,7 @@ lu = cpl_matrix_duplicate(matrix); - iperm = (int*) cpl_malloc((size_t)n * sizeof(*iperm)); + iperm = (int *)cpl_malloc((size_t)n * sizeof(*iperm)); perm = cpl_array_wrap_int(iperm, n); @@ -4705,7 +4734,7 @@ inverse = cpl_matrix_new(n, n); /* Create an identity matrix with the rows permuted */ for (i = 0; i < n; i++) { - (void)cpl_matrix_set(inverse, i, iperm[i], 1.0); + cpl_matrix_set_(inverse, i, iperm[i], 1.0); } cpl_array_delete(perm); @@ -4721,7 +4750,6 @@ } return inverse; - } @@ -4783,19 +4811,18 @@ * @c cpl_matrix_delete(). */ -cpl_matrix *cpl_matrix_solve_normal(const cpl_matrix *coeff, - const cpl_matrix *rhs) +cpl_matrix * +cpl_matrix_solve_normal(const cpl_matrix *coeff, const cpl_matrix *rhs) { - - cpl_matrix * solution; - cpl_matrix * At; - cpl_matrix * AtA; + cpl_matrix *solution; + cpl_matrix *At; + cpl_matrix *AtA; cpl_ensure(coeff != NULL, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(rhs != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(rhs != NULL, CPL_ERROR_NULL_INPUT, NULL); cpl_ensure(rhs->nr == coeff->nr, CPL_ERROR_INCOMPATIBLE_INPUT, NULL); - At = cpl_matrix_transpose_create(coeff); + At = cpl_matrix_transpose_create(coeff); solution = cpl_matrix_product_create(At, rhs); AtA = cpl_matrix_product_normal_create(At); @@ -4811,7 +4838,6 @@ cpl_matrix_delete(AtA); return solution; - } @@ -4841,13 +4867,14 @@ * the input matrix do not contain garbage (such as @c NaN or infinity). */ -double cpl_matrix_get_mean(const cpl_matrix *matrix) +double +cpl_matrix_get_mean(const cpl_matrix *matrix) { - if (matrix == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return 0.0; - } else { + } + else { return cpl_tools_get_mean_double(matrix->m, matrix->nr * matrix->nc); } } @@ -4880,22 +4907,22 @@ * the input matrix do not contain garbage (such as @c NaN or infinity). */ -double cpl_matrix_get_stdev(const cpl_matrix *matrix) +double +cpl_matrix_get_stdev(const cpl_matrix *matrix) { - - if (matrix == NULL) { (void)cpl_error_set_(CPL_ERROR_NULL_INPUT); return 0.0; - } else if (matrix->nr == 1 && matrix->nc == 1) { + } + else if (matrix->nr == 1 && matrix->nc == 1) { return 0.0; - } else { - + } + else { const cpl_size size = matrix->nr * matrix->nc; - const double varsum = cpl_tools_get_variancesum_double(matrix->m, - size, NULL); + const double varsum = + cpl_tools_get_variancesum_double(matrix->m, size, NULL); - return sqrt( varsum / (double)(size - 1)); + return sqrt(varsum / (double)(size - 1)); } } @@ -4922,16 +4949,18 @@ * The median value of all matrix elements is calculated. */ -double cpl_matrix_get_median(const cpl_matrix *matrix) +double +cpl_matrix_get_median(const cpl_matrix *matrix) { - double median = 0.0; + double median = 0.0; if (matrix == NULL) { (void)cpl_error_set_(CPL_ERROR_NULL_INPUT); - } else { + } + else { const cpl_size size = matrix->nr * matrix->nc; - double *copybuf = (double*)cpl_malloc((size_t)size * sizeof(*copybuf)); + double *copybuf = (double *)cpl_malloc((size_t)size * sizeof(*copybuf)); (void)memcpy(copybuf, matrix->m, (size_t)size * sizeof(double)); median = cpl_tools_get_median_double(copybuf, size); @@ -4964,17 +4993,17 @@ * The minimum value of all matrix elements is found. */ -double cpl_matrix_get_min(const cpl_matrix *matrix) +double +cpl_matrix_get_min(const cpl_matrix *matrix) { - - cpl_size i, j; if (cpl_matrix_get_minpos(matrix, &i, &j)) { (void)cpl_error_set_where_(); return 0.0; - } else { - return cpl_matrix_get(matrix, i, j); + } + else { + return cpl_matrix_get_(matrix, i, j); } } @@ -5000,17 +5029,18 @@ * * The maximum value of all matrix elements is found. */ - -double cpl_matrix_get_max(const cpl_matrix *matrix) -{ +double +cpl_matrix_get_max(const cpl_matrix *matrix) +{ cpl_size i, j; if (cpl_matrix_get_maxpos(matrix, &i, &j)) { (void)cpl_error_set_where_(); return 0.0; - } else { - return cpl_matrix_get(matrix, i, j); + } + else { + return cpl_matrix_get_(matrix, i, j); } } @@ -5043,20 +5073,21 @@ * the lowest element column number is returned in @em column. */ -cpl_error_code cpl_matrix_get_minpos(const cpl_matrix *matrix, - cpl_size *row, cpl_size *column) +cpl_error_code +cpl_matrix_get_minpos(const cpl_matrix *matrix, cpl_size *row, cpl_size *column) { - if (matrix == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); - } else if (row == NULL) { + } + else if (row == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); - } else if (column == NULL) { + } + else if (column == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); - } else { - + } + else { const cpl_size size = matrix->nr * matrix->nc; - cpl_size i, pos = 0; + cpl_size i, pos = 0; for (i = 1; i < size; i++) { @@ -5065,12 +5096,11 @@ } } - *row = pos / matrix->nc; + *row = pos / matrix->nc; *column = pos % matrix->nc; } return CPL_ERROR_NONE; - } @@ -5102,20 +5132,21 @@ * the lowest element column number is returned in @em column. */ -cpl_error_code cpl_matrix_get_maxpos(const cpl_matrix *matrix, - cpl_size *row, cpl_size *column) +cpl_error_code +cpl_matrix_get_maxpos(const cpl_matrix *matrix, cpl_size *row, cpl_size *column) { - if (matrix == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); - } else if (row == NULL) { + } + else if (row == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); - } else if (column == NULL) { + } + else if (column == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); - } else { - + } + else { const cpl_size size = matrix->nr * matrix->nc; - cpl_size i, pos = 0; + cpl_size i, pos = 0; for (i = 1; i < size; i++) { @@ -5124,12 +5155,11 @@ } } - *row = pos / matrix->nc; + *row = pos / matrix->nc; *column = pos % matrix->nc; } return CPL_ERROR_NONE; - } @@ -5178,16 +5208,14 @@ */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_matrix_solve_spd(cpl_matrix *self, - cpl_matrix *rhs) +cpl_error_code +cpl_matrix_solve_spd(cpl_matrix *self, cpl_matrix *rhs) { - cpl_ensure_code(!cpl_matrix_decomp_chol(self), cpl_error_get_code()); cpl_ensure_code(!cpl_matrix_solve_chol(self, rhs), cpl_error_get_code()); return CPL_ERROR_NONE; - } @@ -5229,25 +5257,30 @@ * */ -cpl_error_code cpl_matrix_product_normal(cpl_matrix * self, - const cpl_matrix * other) +cpl_error_code +cpl_matrix_product_normal(cpl_matrix *self, const cpl_matrix *other) { - - double sum; - const double * ai = cpl_matrix_get_data_const(other); - const double * aj; - double * bwrite = cpl_matrix_get_data(self); - const size_t m = (size_t)cpl_matrix_get_nrow(self); - const size_t n = (size_t)cpl_matrix_get_ncol(other); + double sum; + const double *ai; + const double *aj; + double *bwrite; + size_t m, n; - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(other != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(cpl_matrix_get_ncol(self) == (cpl_size)m, + + m = (size_t)cpl_matrix_get_nrow_(self); + n = (size_t)cpl_matrix_get_ncol_(other); + + cpl_ensure_code(cpl_matrix_get_ncol_(self) == (cpl_size)m, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(cpl_matrix_get_nrow(other) == (cpl_size)m, + cpl_ensure_code(cpl_matrix_get_nrow_(other) == (cpl_size)m, CPL_ERROR_INCOMPATIBLE_INPUT); + ai = cpl_matrix_get_data_const_(other); + bwrite = cpl_matrix_get_data_(self); + #ifdef CPL_MATRIX_PRODUCT_NORMAL_RESET /* Initialize all values to zero. This is done to avoid access of uninitilized memory in case @@ -5298,17 +5331,25 @@ * be used. */ -cpl_matrix * cpl_matrix_product_normal_create(const cpl_matrix * self) +cpl_matrix * +cpl_matrix_product_normal_create(const cpl_matrix *self) { + cpl_matrix *product = NULL; - 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 (self == NULL) { + (void)cpl_error_set_(CPL_ERROR_NULL_INPUT); + } + else { + const size_t m = cpl_matrix_get_nrow_(self); - if (cpl_matrix_product_normal(product, self)) { - cpl_matrix_delete(product); - product = NULL; - (void)cpl_error_set_where_(); + 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; + (void)cpl_error_set_where_(); + } } return product; @@ -5330,26 +5371,30 @@ */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_matrix_product(cpl_matrix * self, - const cpl_matrix * ma, - const cpl_matrix * mb) -{ - const size_t bs = 48; - double * ds; - const double * d1 = cpl_matrix_get_data_const(ma); - const double * d2 = cpl_matrix_get_data_const(mb); - - const size_t nr = cpl_matrix_get_nrow(ma); - const size_t nc = cpl_matrix_get_ncol(mb); - const size_t nk = cpl_matrix_get_nrow(mb); +cpl_error_code +cpl_matrix_product(cpl_matrix *self, const cpl_matrix *ma, const cpl_matrix *mb) +{ + const size_t bs = 48; + double *ds; + const double *d1; + const double *d2; + size_t nr, nc, nk; + + cpl_ensure_code(ma != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(mb != NULL, CPL_ERROR_NULL_INPUT); + + nr = cpl_matrix_get_nrow_(ma); + nc = cpl_matrix_get_ncol_(mb); + nk = cpl_matrix_get_nrow_(mb); - cpl_ensure_code(ma != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(mb != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code((size_t)ma->nc == nk, CPL_ERROR_INCOMPATIBLE_INPUT); - if (cpl_matrix_set_size_(self, nr, nc)) return cpl_error_set_where_(); + if (cpl_matrix_set_size_(self, nr, nc)) + return cpl_error_set_where_(); - ds = cpl_matrix_get_data(self); + ds = cpl_matrix_get_data_(self); + d1 = cpl_matrix_get_data_const_(ma); + d2 = cpl_matrix_get_data_const_(mb); (void)memset(ds, 0, nr * nc * sizeof(*ds)); @@ -5371,10 +5416,9 @@ } - cpl_tools_add_flops( 2 * (cpl_flops)(ma->nr * mb->nr * mb->nc) ); + cpl_tools_add_flops(2 * (cpl_flops)(ma->nr * mb->nr * mb->nc)); return CPL_ERROR_NONE; - } /*----------------------------------------------------------------------------*/ @@ -5391,31 +5435,36 @@ */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_matrix_product_transpose(cpl_matrix * self, - const cpl_matrix * ma, - const cpl_matrix * mb) -{ - - double sum; +cpl_error_code +cpl_matrix_product_transpose(cpl_matrix *self, + const cpl_matrix *ma, + const cpl_matrix *mb) +{ + double sum; + + double *ds; + const double *d1; + const double *d2; + const double *di; + cpl_size nr, nc, nk; + cpl_size i, j, k; - double * ds; - const double * d1 = cpl_matrix_get_data_const(ma); - const double * d2 = cpl_matrix_get_data_const(mb); - const double * di; - const cpl_size nr = cpl_matrix_get_nrow(ma); - const cpl_size nc = cpl_matrix_get_nrow(mb); - const cpl_size nk = cpl_matrix_get_ncol(mb); - cpl_size i, j, k; + cpl_ensure_code(ma != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(mb != NULL, CPL_ERROR_NULL_INPUT); + nr = cpl_matrix_get_nrow_(ma); + nc = cpl_matrix_get_nrow_(mb); + nk = cpl_matrix_get_ncol_(mb); - cpl_ensure_code(ma != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(mb != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(ma->nc == nk, CPL_ERROR_INCOMPATIBLE_INPUT); - if (cpl_matrix_set_size_(self, nr, nc)) return cpl_error_set_where_(); + if (cpl_matrix_set_size_(self, nr, nc)) + return cpl_error_set_where_(); - ds = cpl_matrix_get_data(self); + ds = cpl_matrix_get_data_(self); + d1 = cpl_matrix_get_data_const_(ma); + d2 = cpl_matrix_get_data_const_(mb); for (i = 0; i < nr; i++, d1 += nk) { /* Since ma and mb are addressed in the same manner, @@ -5431,10 +5480,9 @@ } } - cpl_tools_add_flops( 2 * (cpl_flops)(ma->nr * mb->nr * mb->nc) ); + cpl_tools_add_flops(2 * (cpl_flops)(ma->nr * mb->nr * mb->nc)); return CPL_ERROR_NONE; - } /*----------------------------------------------------------------------------*/ @@ -5463,33 +5511,38 @@ */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_matrix_product_bilinear(cpl_matrix * self, - const cpl_matrix * ma, - const cpl_matrix * mb) -{ +cpl_error_code +cpl_matrix_product_bilinear(cpl_matrix *self, + const cpl_matrix *ma, + const cpl_matrix *mb) +{ + double *ds; + double *cj; /* Holds one column of A * B' */ + const double *d1; + const double *d2; - double * ds; - double * cj; /* Holds one column of A * B' */ - const double * d1 = cpl_matrix_get_data_const(ma); - const double * d2 = cpl_matrix_get_data_const(mb); + cpl_size nr, nc; + cpl_size i, j, k; - const cpl_size nr = cpl_matrix_get_nrow(mb); - const cpl_size nc = cpl_matrix_get_ncol(mb); - cpl_size i, j, k; + cpl_ensure_code(ma != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(mb != NULL, CPL_ERROR_NULL_INPUT); + + nr = cpl_matrix_get_nrow_(mb); + nc = cpl_matrix_get_ncol_(mb); - cpl_ensure_code(ma != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(mb != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(ma->nr == nc, CPL_ERROR_INCOMPATIBLE_INPUT); cpl_ensure_code(ma->nc == nc, CPL_ERROR_INCOMPATIBLE_INPUT); - if (cpl_matrix_set_size_(self, nr, nr)) return cpl_error_set_where_(); + if (cpl_matrix_set_size_(self, nr, nr)) + return cpl_error_set_where_(); - ds = cpl_matrix_get_data(self); + ds = cpl_matrix_get_data_(self); + d1 = cpl_matrix_get_data_const_(ma); + d2 = cpl_matrix_get_data_const_(mb); cj = cpl_malloc((size_t)nc * sizeof(*cj)); for (j = 0; j < nr; j++) { - /* First compute the jth column of C = A * B', whose kth element is the dot-product of kth row of A and the jth row of B, both of which are read with unit stride. */ @@ -5516,10 +5569,9 @@ cpl_free(cj); - cpl_tools_add_flops( 2 * (cpl_flops)(nr * nc * (nc + nr)) ); + cpl_tools_add_flops(2 * (cpl_flops)(nr * nc * (nc + nr))); return CPL_ERROR_NONE; - } /*----------------------------------------------------------------------------*/ @@ -5566,31 +5618,31 @@ */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_matrix_solve_chol_transpose(const cpl_matrix * self, - cpl_matrix * rhs) +cpl_error_code +cpl_matrix_solve_chol_transpose(const cpl_matrix *self, cpl_matrix *rhs) { - - const cpl_size n = cpl_matrix_get_ncol(self); - const cpl_size nrhs = cpl_matrix_get_nrow(rhs); + cpl_size n, nrhs; cpl_size i, j, k; - const double * aread; - const double * ai; - double * bk; + const double *aread; + const double *ai; + double *bk; double sub; cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(rhs != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(rhs != NULL, CPL_ERROR_NULL_INPUT); + + n = cpl_matrix_get_ncol_(self); + nrhs = cpl_matrix_get_nrow_(rhs); cpl_ensure_code(self->nr == n, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(rhs->nc == n, CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_ensure_code(rhs->nc == n, CPL_ERROR_INCOMPATIBLE_INPUT); aread = self->m; /* bk points to first entry in k'th right hand side */ bk = rhs->m; - for (k=0; k < nrhs; k++, bk += n) { - + for (k = 0; k < nrhs; k++, bk += n) { /* Forward substitution in column k */ /* Since self and rhs are addressed in the same manner, @@ -5607,25 +5659,26 @@ /* Back substitution in column k */ - for (i = n-1; i >= 0; i--) { + for (i = n - 1; i >= 0; i--) { sub = bk[i]; - for (j = i+1; j < n; j++) { + for (j = i + 1; j < n; j++) { sub -= aread[n * j + i] * bk[j]; } - bk[i] = sub/aread[n * i + i]; + bk[i] = sub / aread[n * i + i]; } } - cpl_tools_add_flops( 2 * (cpl_flops)(n * n * nrhs)); + cpl_tools_add_flops(2 * (cpl_flops)(n * n * nrhs)); return CPL_ERROR_NONE; - } /* - * The following implementation of one-sided Jacobi orthogonalization - * to compute the SVD of a MxN matrix, with M >= N is based on the - * implementation found in the GNU Scientific Library (GSL). + * The following implementation of the one-sided Jacobi orthogonalization + * to compute the SVD of a MxN matrix, with M >= N, is based on the + * implementation found in the GNU Scientific Library (GSL). It uses the + * rotations as given in Nash, J.C., "Compact Numerical Methods for Computers: + * Linear Algebra and Function Minimisation", 2nd ed., 1990. */ /** @@ -5668,11 +5721,16 @@ * * @enderror * - * The function computes singular value decomposition (SVD) of a real M x N - * matrix @em U, where M >= N. It uses a one-sided Jacobi orthogonalization - * as described in James Demmel, Kresimir Veselic, "Jacobi's Method is more - * accurate than QR", Lapack Working Note 15 (LAWN15), October 1989, - * Algorithm 4.1 which is available at @em netlib.org. + * The function computes the singular value decomposition (SVD) of a real + * M x N matrix @em U, where M >= N. If M < N the SVD of U can be computed by + * computing the SVD of the transpose of the matrix U, Ut, since Ut = V S Ut. + * + * It uses a one-sided Jacobi orthogonalization as described in James Demmel, + * Kresimir Veselic, "Jacobi's Method is more accurate than QR", Lapack Working + * Note 15 (LAWN15), October 1989, Algorithm 4.1 which is available at + * @em netlib.org. It follows the implementation of Nash, J.C., "Compact + Numerical Methods for Computers: Linear Algebra and Function Minimisation", + 2nd ed., 1990, and the implementation in the GNU Scientific Library. * * The input matrix @em U is overwritten during the process and contains * in the end the left singular vectors of @em U. The matrix @em V will be @@ -5683,9 +5741,8 @@ */ static cpl_error_code -_cpl_matrix_decomp_sv_jacobi(cpl_matrix *U, cpl_vector *S, cpl_matrix *V) +cpl_matrix_decomp_sv_jacobi_(cpl_matrix *U, cpl_vector *S, cpl_matrix *V) { - cpl_ensure_code((U != NULL) && (V != NULL) && (S != NULL), CPL_ERROR_NULL_INPUT); cpl_ensure_code(U->nr >= U->nc, CPL_ERROR_ILLEGAL_INPUT); @@ -5728,7 +5785,7 @@ for (j = 0; j < n; ++j) { for (i = 0; i < m; ++i) { - _cv1[i] = cpl_matrix_get(U, i, j); + _cv1[i] = cpl_matrix_get_(U, i, j); } double s = sqrt(cpl_vector_product(cv1, cv1)); @@ -5744,7 +5801,6 @@ double *const _cv2 = cpl_vector_get_data(cv2); while ((count > 0) && (sweep <= sweepmax)) { - /* * Initialize the rotation counter. */ @@ -5752,17 +5808,15 @@ count = n * (n - 1) / 2; for (j = 0; j < n - 1; ++j) { - cpl_size k; for (k = j + 1; k < n; ++k) { - for (i = 0; i < m; ++i) { - _cv1[i] = cpl_matrix_get(U, i, j); + _cv1[i] = cpl_matrix_get_(U, i, j); } for (i = 0; i < m; ++i) { - _cv2[i] = cpl_matrix_get(U, i, k); + _cv2[i] = cpl_matrix_get_(U, i, k); } /* @@ -5775,16 +5829,17 @@ double c = 2. * cpl_vector_product(cv1, cv2); /* - * Test for columns j, k orthogonal, or dominant errors. + * Test whether the columns j, k are orthogonal, or for + * dominant errors. */ double abserr_a = cpl_vector_get(S, j); double abserr_b = cpl_vector_get(S, k); cpl_boolean orthogonal = (fabs(c) <= tolerance * a * b); - cpl_boolean sorted = (a >= b); - cpl_boolean noisy_a = (a < abserr_a); - cpl_boolean noisy_b = (b < abserr_b); + cpl_boolean sorted = (a >= b); + cpl_boolean noisy_a = (a < abserr_a); + cpl_boolean noisy_b = (b < abserr_b); if (sorted && (orthogonal || noisy_a || noisy_b)) { --count; @@ -5799,9 +5854,10 @@ double q = a * a - b * b; double v = sqrt(c * c + q * q); - double cs; /* cos(theta) */ - double sn; /* sin(theta) */ + double cs; /* cos(theta) */ + double sn; /* sin(theta) */ +#ifdef USE_NASH79 if (v == 0. || !sorted) { cs = 0.; sn = 1.; @@ -5810,41 +5866,50 @@ cs = sqrt((v + q) / (2. * v)); sn = c / (2. * v * cs); } +#else + if (v == 0.) { + cs = 0.; + sn = 1.; + } + else { + if (sorted) { + cs = sqrt(0.5 * (1. + q / v)); + sn = 0.5 * c / (v * cs); + } + else { + double sign = (c >= 0.) ? 1. : -1.; + sn = sign * sqrt(0.5 * (1. - q / v)); + cs = 0.5 * c / (v * sn); + } + } +#endif /* * Update the columns j and k of U and V */ for (i = 0; i < m; ++i) { + const double u_ij = cpl_matrix_get_(U, i, j); + const double u_ik = cpl_matrix_get_(U, i, k); - const double u_ij = cpl_matrix_get(U, i, j); - const double u_ik = cpl_matrix_get(U, i, k); - - cpl_matrix_set(U, i, j, u_ij * cs + u_ik * sn); - cpl_matrix_set(U, i, k, -u_ij * sn + u_ik * cs); - + cpl_matrix_set_(U, i, j, u_ij * cs + u_ik * sn); + cpl_matrix_set_(U, i, k, -u_ij * sn + u_ik * cs); } for (i = 0; i < n; ++i) { + const double v_ij = cpl_matrix_get_(V, i, j); + const double v_ik = cpl_matrix_get_(V, i, k); - const double v_ij = cpl_matrix_get(V, i, j); - const double v_ik = cpl_matrix_get(V, i, k); - - cpl_matrix_set(V, i, j, v_ij * cs + v_ik * sn); - cpl_matrix_set(V, i, k, -v_ij * sn + v_ik * cs); + cpl_matrix_set_(V, i, j, v_ij * cs + v_ik * sn); + cpl_matrix_set_(V, i, k, -v_ij * sn + v_ik * cs); } - cpl_vector_set(S, j, fabs(cs) * abserr_a + - fabs(sn) * abserr_b); - cpl_vector_set(S, k, fabs(sn) * abserr_a + - fabs(cs) * abserr_b); - + cpl_vector_set(S, j, fabs(cs) * abserr_a + fabs(sn) * abserr_b); + cpl_vector_set(S, k, fabs(sn) * abserr_a + fabs(cs) * abserr_b); } - } ++sweep; - } cpl_vector_delete(cv2); @@ -5857,9 +5922,8 @@ double prev_norm = -1.; for (j = 0; j < n; ++j) { - for (i = 0; i < m; ++i) { - _cv1[i] = cpl_matrix_get(U, i, j); + _cv1[i] = cpl_matrix_get_(U, i, j); } double norm = sqrt(cpl_vector_product(cv1, cv1)); @@ -5871,30 +5935,25 @@ */ if ((norm == 0.) || (prev_norm == 0.) || - ((j > 0) && (norm <= tolerance * prev_norm))) { - - cpl_vector_set(S, j, 0.); /* singular */ - cpl_matrix_fill_column(U, 0., j); /* annihilate column */ + ((j > 0) && (norm <= tolerance * prev_norm))) { + cpl_vector_set(S, j, 0.); /* singular */ + cpl_matrix_fill_column(U, 0., j); /* annihilate column */ prev_norm = 0.; - } else { - - cpl_vector_set(S, j, norm); /* non-singular */ + cpl_vector_set(S, j, norm); /* non-singular */ /* * Normalize the column vector of U */ for (i = 0; i < m; ++i) { - cpl_matrix_set(U, i, j, _cv1[i] / norm); + cpl_matrix_set_(U, i, j, _cv1[i] / norm); } prev_norm = norm; - } - } cpl_vector_delete(cv1); @@ -5904,7 +5963,147 @@ } return CPL_ERROR_NONE; +} + +/** + * @brief + * Solve a linear system in a least square sense using an SVD factorization + * discarding singular values below a given threshold. + * + * @param coeff An N by M matrix of linear system coefficients, where N >= M + * @param rhs An N by 1 matrix with the right hand side of the system + * @param mode Cutoff mode selector for small singular values. + * @param tolerance Factor used to compute the cutoff value if mode is + * set to @c 2. + * + * @return + * A newly allocated M by 1 matrix containing the solution vector or + * @c NULL on error. + * + * @error + * + * + * + * + * + * + * + * + * + * + * + * + * + *
CPL_ERROR_NULL_INPUT + * coeff or rhs is a NULL pointer. + *
CPL_ERROR_INCOMPATIBLE_INPUT + * coeff and rhs do not have the same number of rows. + *
CPL_ILLEGAL_INPUT + * The matrix rhs has more than one column, or an illegal + * mode or tolerance was given. + *
+ * @enderror + * + * The function solves a linear system of the form Ax = b for the solution + * vector x, where @c A is represented by the argument @em coeff and @c b + * by the argument @em rhs. The linear system is solved using the singular + * value decomposition (SVD) of the coefficient matrix, based on a one-sided + * Jacobi orthogonalization. When solving the linear system singular values + * which are less or equal than a given cutoff value are treated as zero. + * + * The argument @em mode is used to select the computation of the cutoff value + * for small singular values. If @em mode is set to @c 0 the machine precision + * (@c DBL_EPSILON) is used as the cutoff factor. If @em mode is @c 1, the + * cutoff factor is computed as + * @f$10 \times\text{\texttt{DBL\_EPSILON}} \times \max(N, M)@f$, and if + * @em mode is @c 2 the argument @em tolerance, a value in the range + * @f$[0,1]@f$. is used as the cutoff factor. The actual cutoff value, is then + * given by the cutoff factor times the biggest singular value obtained from + * the SVD of the input matrix @em coeff. + * + * The returned solution matrix should be deallocated using + * @b cpl_matrix_delete(). + * + * @see cpl_matrix_solve_svd() + */ + +cpl_matrix * +cpl_matrix_solve_svd_threshold(const cpl_matrix *coeff, + const cpl_matrix *rhs, + int mode, + double tolerance) +{ + cpl_ensure((coeff != NULL) && (rhs != NULL), CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(coeff->nr == rhs->nr, CPL_ERROR_INCOMPATIBLE_INPUT, NULL); + cpl_ensure(rhs->nc == 1, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure((mode == 0) || (mode == 1) || + ((mode == 2) && ((tolerance >= 0.) && (tolerance <= 1.))), + CPL_ERROR_ILLEGAL_INPUT, NULL); + + + /* + * Compute the SVD factorization of the coefficient matrix + */ + + cpl_matrix *U = cpl_matrix_duplicate(coeff); + const cpl_size nc = U->nc; + + cpl_matrix *V = cpl_matrix_new(U->nc, U->nc); + cpl_vector *S = cpl_vector_new(U->nc); + + cpl_error_code status = cpl_matrix_decomp_sv_jacobi_(U, S, V); + + if (status != CPL_ERROR_NONE) { + cpl_vector_delete(S); + cpl_matrix_delete(V); + cpl_matrix_delete(U); + + cpl_error_set_where(cpl_func); + + return NULL; + } + + + /* + * Solve the linear system + */ + + cpl_matrix *Ut = cpl_matrix_transpose_create(U); + cpl_matrix *w = cpl_matrix_product_create(Ut, rhs); + + cpl_matrix_delete(Ut); + + if (mode == 0) { + tolerance = DBL_EPSILON; + } + else if (mode == 1) { + cpl_size nr = cpl_matrix_get_nrow(U); + tolerance = 10. * CPL_MAX(nr, nc) * DBL_EPSILON; + } + + const double rcond = tolerance * cpl_vector_get_max(S); + const double *_s = cpl_vector_get_data_const(S); + double *_w = cpl_matrix_get_data(w); + + cpl_size ic; + for (ic = 0; ic < nc; ++ic) { + double s = _s[ic]; + if (s > rcond) { + s = 1. / s; + } + else { + s = 0.; + } + _w[ic] *= s; + } + + cpl_matrix *solution = cpl_matrix_product_create(V, w); + cpl_matrix_delete(w); + cpl_vector_delete(S); + cpl_matrix_delete(V); + cpl_matrix_delete(U); + return solution; } @@ -5946,16 +6145,20 @@ * vector x, where @c A is represented by the argument @em coeff and @c b * by the argument @em rhs. The linear system is solved using the singular * value decomposition (SVD) of the coefficient matrix, based on a one-sided - * Jacobi orthogonalization. + * Jacobi orthogonalization. When solving the linear system all singular + * values are taken into account, regardless of their magnitude. This is + * equivalent to calling cpl_matrix_solve_svd_threshold() with mode set + * to @c 2 and a threshold value of @c 0. * * The returned solution matrix should be deallocated using * @b cpl_matrix_delete(). + * + * @see cpl_matrix_solve_svd_threshold() */ cpl_matrix * cpl_matrix_solve_svd(const cpl_matrix *coeff, const cpl_matrix *rhs) { - cpl_ensure((coeff != NULL) && (rhs != NULL), CPL_ERROR_NULL_INPUT, NULL); cpl_ensure(coeff->nr == rhs->nr, CPL_ERROR_INCOMPATIBLE_INPUT, NULL); cpl_ensure(rhs->nc == 1, CPL_ERROR_ILLEGAL_INPUT, NULL); @@ -5969,7 +6172,7 @@ cpl_matrix *V = cpl_matrix_new(U->nc, U->nc); cpl_vector *S = cpl_vector_new(U->nc); - cpl_error_code status = _cpl_matrix_decomp_sv_jacobi(U, S, V); + cpl_error_code status = cpl_matrix_decomp_sv_jacobi_(U, S, V); if (status != CPL_ERROR_NONE) { cpl_vector_delete(S); @@ -5987,23 +6190,21 @@ */ cpl_matrix *Ut = cpl_matrix_transpose_create(U); - cpl_matrix *w = cpl_matrix_product_create(Ut, rhs); + cpl_matrix *w = cpl_matrix_product_create(Ut, rhs); cpl_matrix_delete(Ut); const double *_s = cpl_vector_get_data_const(S); - double *_w = cpl_matrix_get_data(w); + double *_w = cpl_matrix_get_data_(w); cpl_size ic; for (ic = 0; ic < U->nc; ++ic) { - double s = _s[ic]; if (s != 0.) { s = 1. / s; } _w[ic] *= s; - } cpl_matrix *solution = cpl_matrix_product_create(V, w); @@ -6014,7 +6215,6 @@ cpl_matrix_delete(U); return solution; - } /** @@ -6029,12 +6229,11 @@ * @see cpl_matrix_solve() * */ -cpl_error_code cpl_matrix_solve_(cpl_matrix * a, - cpl_matrix * x, - cpl_array * p) +cpl_error_code +cpl_matrix_solve_(cpl_matrix *a, cpl_matrix *x, cpl_array *p) { const cpl_size n = cpl_array_get_size(p); - int sig; + int sig; assert(a->nc == n); assert(a->nr == n); diff -Nru cpl-7.1.4+ds/cplcore/cpl_matrix.h cpl-7.2.2+ds/cplcore/cpl_matrix.h --- cpl-7.1.4+ds/cplcore/cpl_matrix.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_matrix.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -59,7 +59,7 @@ cpl_size cpl_matrix_get_nrow(const cpl_matrix *); cpl_size cpl_matrix_get_ncol(const cpl_matrix *); - double *cpl_matrix_get_data(cpl_matrix *); +double *cpl_matrix_get_data(cpl_matrix *); const double *cpl_matrix_get_data_const(const cpl_matrix *); double cpl_matrix_get(const cpl_matrix *, cpl_size, cpl_size); cpl_error_code cpl_matrix_set(cpl_matrix *, cpl_size, cpl_size, double); @@ -69,27 +69,35 @@ */ cpl_matrix *cpl_matrix_duplicate(const cpl_matrix *) CPL_ATTR_ALLOC; -cpl_matrix *cpl_matrix_extract(const cpl_matrix *, - cpl_size, cpl_size, cpl_size, cpl_size, - cpl_size, cpl_size) CPL_ATTR_ALLOC; +cpl_matrix *cpl_matrix_extract(const cpl_matrix *, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_size) CPL_ATTR_ALLOC; cpl_matrix *cpl_matrix_extract_row(const cpl_matrix *, cpl_size) CPL_ATTR_ALLOC; -cpl_matrix *cpl_matrix_extract_column(const cpl_matrix *, cpl_size) - CPL_ATTR_ALLOC; -cpl_matrix *cpl_matrix_extract_diagonal(const cpl_matrix *, cpl_size) - CPL_ATTR_ALLOC; +cpl_matrix * +cpl_matrix_extract_column(const cpl_matrix *, cpl_size) CPL_ATTR_ALLOC; +cpl_matrix * +cpl_matrix_extract_diagonal(const cpl_matrix *, cpl_size) CPL_ATTR_ALLOC; /* * Writing methods */ -cpl_error_code cpl_matrix_copy(cpl_matrix *, const cpl_matrix *, - cpl_size, cpl_size); +cpl_error_code +cpl_matrix_copy(cpl_matrix *, const cpl_matrix *, cpl_size, cpl_size); cpl_error_code cpl_matrix_fill(cpl_matrix *, double); cpl_error_code cpl_matrix_fill_row(cpl_matrix *, double, cpl_size); cpl_error_code cpl_matrix_fill_column(cpl_matrix *, double, cpl_size); cpl_error_code cpl_matrix_fill_diagonal(cpl_matrix *, double, cpl_size); -cpl_error_code cpl_matrix_fill_window(cpl_matrix *, double, - cpl_size, cpl_size, cpl_size, cpl_size); +cpl_error_code cpl_matrix_fill_window(cpl_matrix *, + double, + cpl_size, + cpl_size, + cpl_size, + cpl_size); /* * Test methods @@ -119,9 +127,9 @@ cpl_error_code cpl_matrix_erase_rows(cpl_matrix *, cpl_size, cpl_size); cpl_error_code cpl_matrix_erase_columns(cpl_matrix *, cpl_size, cpl_size); cpl_error_code cpl_matrix_set_size(cpl_matrix *, cpl_size, cpl_size); -cpl_error_code cpl_matrix_resize(cpl_matrix *, cpl_size, cpl_size, - cpl_size, cpl_size); -cpl_error_code cpl_matrix_append(cpl_matrix *, const cpl_matrix *, int); +cpl_error_code +cpl_matrix_resize(cpl_matrix *, cpl_size, cpl_size, cpl_size, cpl_size); +cpl_error_code cpl_matrix_append(cpl_matrix *, const cpl_matrix *, int); /* * Basic operations @@ -143,8 +151,7 @@ cpl_matrix *cpl_matrix_product_create(const cpl_matrix *, const cpl_matrix *) CPL_ATTR_ALLOC; cpl_matrix *cpl_matrix_transpose_create(const cpl_matrix *) CPL_ATTR_ALLOC; -cpl_error_code cpl_matrix_product_normal(cpl_matrix *, - const cpl_matrix *); +cpl_error_code cpl_matrix_product_normal(cpl_matrix *, const cpl_matrix *); cpl_error_code cpl_matrix_product_transpose(cpl_matrix *, const cpl_matrix *, @@ -155,17 +162,21 @@ */ double cpl_matrix_get_determinant(const cpl_matrix *); -cpl_matrix *cpl_matrix_solve(const cpl_matrix *, - const cpl_matrix *) CPL_ATTR_ALLOC; -cpl_matrix *cpl_matrix_solve_normal(const cpl_matrix *, - const cpl_matrix *) CPL_ATTR_ALLOC; -cpl_matrix *cpl_matrix_solve_svd(const cpl_matrix *, - const cpl_matrix *) CPL_ATTR_ALLOC; +cpl_matrix * +cpl_matrix_solve(const cpl_matrix *, const cpl_matrix *) CPL_ATTR_ALLOC; +cpl_matrix * +cpl_matrix_solve_normal(const cpl_matrix *, const cpl_matrix *) CPL_ATTR_ALLOC; +cpl_matrix * +cpl_matrix_solve_svd(const cpl_matrix *, const cpl_matrix *) CPL_ATTR_ALLOC; +cpl_matrix *cpl_matrix_solve_svd_threshold(const cpl_matrix *, + const cpl_matrix *, + int, + double) CPL_ATTR_ALLOC; cpl_matrix *cpl_matrix_invert_create(const cpl_matrix *) CPL_ATTR_ALLOC; cpl_error_code cpl_matrix_decomp_lu(cpl_matrix *, cpl_array *, int *); -cpl_error_code cpl_matrix_solve_lu(const cpl_matrix *, cpl_matrix *, - const cpl_array *); +cpl_error_code +cpl_matrix_solve_lu(const cpl_matrix *, cpl_matrix *, const cpl_array *); cpl_error_code cpl_matrix_decomp_chol(cpl_matrix *); cpl_error_code cpl_matrix_solve_chol(const cpl_matrix *, cpl_matrix *); @@ -178,13 +189,12 @@ double cpl_matrix_get_stdev(const cpl_matrix *); double cpl_matrix_get_min(const cpl_matrix *); double cpl_matrix_get_max(const cpl_matrix *); -cpl_error_code cpl_matrix_get_minpos(const cpl_matrix *, cpl_size *, - cpl_size *); -cpl_error_code cpl_matrix_get_maxpos(const cpl_matrix *, cpl_size *, - cpl_size *); +cpl_error_code +cpl_matrix_get_minpos(const cpl_matrix *, cpl_size *, cpl_size *); +cpl_error_code +cpl_matrix_get_maxpos(const cpl_matrix *, cpl_size *, cpl_size *); CPL_END_DECLS #endif /* end of cpl_matrix.h */ - diff -Nru cpl-7.1.4+ds/cplcore/cpl_matrix_impl.h cpl-7.2.2+ds/cplcore/cpl_matrix_impl.h --- cpl-7.1.4+ds/cplcore/cpl_matrix_impl.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_matrix_impl.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -21,29 +21,45 @@ #define CPL_MATRIX_IMPL_H #include "cpl_matrix.h" - + CPL_BEGIN_DECLS -cpl_matrix * cpl_matrix_product_normal_create(const cpl_matrix *) - CPL_ATTR_ALLOC; +cpl_matrix *cpl_matrix_product_normal_create(const cpl_matrix *) CPL_ATTR_ALLOC; cpl_error_code cpl_matrix_solve_spd(cpl_matrix *, cpl_matrix *); -cpl_error_code cpl_matrix_product(cpl_matrix *, const cpl_matrix *, - const cpl_matrix *); +cpl_error_code +cpl_matrix_product(cpl_matrix *, const cpl_matrix *, const cpl_matrix *); cpl_error_code cpl_matrix_product_bilinear(cpl_matrix *, const cpl_matrix *, const cpl_matrix *); -cpl_error_code cpl_matrix_solve_chol_transpose(const cpl_matrix *, - cpl_matrix *); +cpl_error_code +cpl_matrix_solve_chol_transpose(const cpl_matrix *, cpl_matrix *); -cpl_error_code cpl_matrix_solve_(cpl_matrix *, cpl_matrix *, cpl_array *) - CPL_ATTR_NONNULL; +cpl_error_code +cpl_matrix_solve_(cpl_matrix *, cpl_matrix *, cpl_array *) CPL_ATTR_NONNULL; cpl_error_code cpl_matrix_fill_identity(cpl_matrix *); +void cpl_matrix_set_(cpl_matrix *, cpl_size, cpl_size, double) CPL_ATTR_NONNULL; + +double cpl_matrix_get_(const cpl_matrix *, + cpl_size, + cpl_size) CPL_ATTR_PURE CPL_ATTR_NONNULL; + +double *cpl_matrix_get_data_(cpl_matrix *) CPL_ATTR_PURE CPL_ATTR_NONNULL; + +const double * +cpl_matrix_get_data_const_(const cpl_matrix *) CPL_ATTR_PURE CPL_ATTR_NONNULL; + +cpl_size +cpl_matrix_get_nrow_(const cpl_matrix *) CPL_ATTR_PURE CPL_ATTR_NONNULL; + +cpl_size +cpl_matrix_get_ncol_(const cpl_matrix *) CPL_ATTR_PURE CPL_ATTR_NONNULL; + CPL_END_DECLS #endif diff -Nru cpl-7.1.4+ds/cplcore/cpl_memory.c cpl-7.2.2+ds/cplcore/cpl_memory.c --- cpl-7.1.4+ds/cplcore/cpl_memory.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_memory.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -18,7 +18,7 @@ */ #ifdef HAVE_CONFIG_H -# include +#include #endif #include @@ -67,31 +67,31 @@ if (cpl_memory_mode < 0) { if (mode == 0) { static const cx_memory_vtable cpl_memory_services_system = { - (cxptr(*)(cxsize))malloc, - (cxptr (*)(cxsize, cxsize))calloc, - (cxptr (*) (cxptr, cxsize))realloc, - (void (*) (cxptr))free + (cxptr(*)(cxsize))malloc, (cxptr(*)(cxsize, cxsize))calloc, + (cxptr(*)(cxptr, cxsize))realloc, (void (*)(cxptr))free }; cx_memory_vtable_set(&cpl_memory_services_system); cpl_memory_mode = 0; #ifndef _OPENMP /* Mode 2 is not supported with OpenMP - will default to 1 */ - } else if (mode == 2) { + } + else if (mode == 2) { static const cx_memory_vtable cpl_memory_services_xmemory = { (cxptr(*)(cxsize))cpl_xmemory_malloc, - (cxptr (*)(cxsize, cxsize))cpl_xmemory_calloc, - (cxptr (*) (cxptr, cxsize))cpl_xmemory_realloc, - (void (*) (cxptr))cpl_xmemory_free + (cxptr(*)(cxsize, cxsize))cpl_xmemory_calloc, + (cxptr(*)(cxptr, cxsize))cpl_xmemory_realloc, + (void (*)(cxptr))cpl_xmemory_free }; cx_memory_vtable_set(&cpl_memory_services_xmemory); cpl_memory_mode = 2; #endif - } else { + } + else { static const cx_memory_vtable cpl_memory_services_count = { (cxptr(*)(cxsize))cpl_xmemory_malloc_count, - (cxptr (*)(cxsize, cxsize))cpl_xmemory_calloc_count, - (cxptr (*) (cxptr, cxsize))cpl_xmemory_realloc_count, - (void (*) (cxptr))cpl_xmemory_free_count + (cxptr(*)(cxsize, cxsize))cpl_xmemory_calloc_count, + (cxptr(*)(cxptr, cxsize))cpl_xmemory_realloc_count, + (void (*)(cxptr))cpl_xmemory_free_count }; cx_memory_vtable_set(&cpl_memory_services_count); cpl_memory_mode = 1; @@ -123,17 +123,17 @@ void * cpl_malloc(size_t nbytes) { - if (cpl_memory_mode < 0) { - cx_log(CX_LOG_DOMAIN, CX_LOG_LEVEL_ERROR, "%s: CPL " PACKAGE_VERSION - " memory management subsystem is not initialized!", CX_CODE_POS); + cx_log(CX_LOG_DOMAIN, CX_LOG_LEVEL_ERROR, + "%s: CPL " PACKAGE_VERSION + " memory management subsystem is not initialized!", + CX_CODE_POS); } return cx_malloc((cxsize)nbytes); - } - + /** * @brief * Allocate memory for @em natoms elements of size @em size. @@ -156,14 +156,14 @@ void * cpl_calloc(size_t natoms, size_t nbytes) { - if (cpl_memory_mode < 0) { - cx_log(CX_LOG_DOMAIN, CX_LOG_LEVEL_ERROR, "%s: CPL " PACKAGE_VERSION - " memory management subsystem is not initialized!", CX_CODE_POS); + cx_log(CX_LOG_DOMAIN, CX_LOG_LEVEL_ERROR, + "%s: CPL " PACKAGE_VERSION + " memory management subsystem is not initialized!", + CX_CODE_POS); } return cx_calloc((cxsize)natoms, (cxsize)nbytes); - } @@ -200,14 +200,14 @@ void * cpl_realloc(void *memblk, size_t nbytes) { - if (cpl_memory_mode < 0) { - cx_log(CX_LOG_DOMAIN, CX_LOG_LEVEL_ERROR, "%s: CPL " PACKAGE_VERSION - " memory management subsystem is not initialized!", CX_CODE_POS); + cx_log(CX_LOG_DOMAIN, CX_LOG_LEVEL_ERROR, + "%s: CPL " PACKAGE_VERSION + " memory management subsystem is not initialized!", + CX_CODE_POS); } return cx_realloc(memblk, (cxsize)nbytes); - } @@ -226,15 +226,15 @@ void cpl_free(void *memblk) { - if (cpl_memory_mode < 0) { - cx_log(CX_LOG_DOMAIN, CX_LOG_LEVEL_ERROR, "%s: CPL " PACKAGE_VERSION - " memory management subsystem is not initialized!", CX_CODE_POS); + cx_log(CX_LOG_DOMAIN, CX_LOG_LEVEL_ERROR, + "%s: CPL " PACKAGE_VERSION + " memory management subsystem is not initialized!", + CX_CODE_POS); } cx_free(memblk); return; - } /** @@ -251,16 +251,17 @@ * @see cpl_free() */ -char *cpl_strdup(const char *string) +char * +cpl_strdup(const char *string) { - if (cpl_memory_mode < 0) { - cx_log(CX_LOG_DOMAIN, CX_LOG_LEVEL_ERROR, "%s: CPL " PACKAGE_VERSION - " memory management subsystem is not initialized!", CX_CODE_POS); + cx_log(CX_LOG_DOMAIN, CX_LOG_LEVEL_ERROR, + "%s: CPL " PACKAGE_VERSION + " memory management subsystem is not initialized!", + CX_CODE_POS); } return cx_strdup(string); - } @@ -294,16 +295,18 @@ * */ /*----------------------------------------------------------------------------*/ -char * cpl_vsprintf(const char * format, va_list arglist) +char * +cpl_vsprintf(const char *format, va_list arglist) { - - char * self = NULL; - int nlen; + char *self = NULL; + int nlen; if (cpl_memory_mode < 0) { - cx_log(CX_LOG_DOMAIN, CX_LOG_LEVEL_ERROR, "%s: CPL " PACKAGE_VERSION - " memory management subsystem is not initialized!", CX_CODE_POS); + cx_log(CX_LOG_DOMAIN, CX_LOG_LEVEL_ERROR, + "%s: CPL " PACKAGE_VERSION + " memory management subsystem is not initialized!", + CX_CODE_POS); } cpl_ensure(format != NULL, CPL_ERROR_NULL_INPUT, NULL); @@ -314,17 +317,20 @@ if (nlen < 0) { cx_free(self); self = NULL; - (void)cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, "cx_vasprintf() " - "returned %d < 0 on format=%s", nlen, - format); - } else if (self == NULL) { - (void)cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, "cx_vasprintf() " + (void)cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, + "cx_vasprintf() " + "returned %d < 0 on format=%s", + nlen, format); + } + else if (self == NULL) { + (void)cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, + "cx_vasprintf() " "returned %d but set self=NULL on " - "format=%s", nlen, format); + "format=%s", + nlen, format); } return self; - } /*----------------------------------------------------------------------------*/ @@ -379,11 +385,11 @@ * */ /*----------------------------------------------------------------------------*/ -char * cpl_sprintf(const char * format, ...) +char * +cpl_sprintf(const char *format, ...) { - - char * self; - va_list arglist; + char *self; + va_list arglist; cpl_ensure(format != NULL, CPL_ERROR_NULL_INPUT, NULL); @@ -395,7 +401,6 @@ cpl_ensure(self != NULL, cpl_error_get_code(), NULL); return self; - } @@ -403,7 +408,8 @@ * @brief Tell if there is some memory allocated * @return -1 if the model is off, 1 if it is empty, 0 otherwise */ -int cpl_memory_is_empty(void) +int +cpl_memory_is_empty(void) { return cpl_xmemory_is_empty(cpl_memory_mode); } @@ -411,8 +417,9 @@ /** * @brief Display the memory status */ -void cpl_memory_dump(void) -{ +void +cpl_memory_dump(void) +{ cpl_xmemory_status(cpl_memory_mode); return; diff -Nru cpl-7.1.4+ds/cplcore/cpl_memory.h cpl-7.2.2+ds/cplcore/cpl_memory.h --- cpl-7.1.4+ds/cplcore/cpl_memory.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_memory.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -40,7 +40,7 @@ char *cpl_strdup(const char *) CPL_ATTR_ALLOC; char *cpl_vsprintf(const char *, va_list) CPL_ATTR_ALLOC CPL_ATTR_PRINTF(1, 0); -char *cpl_sprintf (const char *, ...) CPL_ATTR_ALLOC CPL_ATTR_PRINTF(1, 2); +char *cpl_sprintf(const char *, ...) CPL_ATTR_ALLOC CPL_ATTR_PRINTF(1, 2); int cpl_memory_is_empty(void) CPL_ATTR_PURE; diff -Nru cpl-7.1.4+ds/cplcore/cpl_memory_impl.h cpl-7.2.2+ds/cplcore/cpl_memory_impl.h --- cpl-7.1.4+ds/cplcore/cpl_memory_impl.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_memory_impl.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 diff -Nru cpl-7.1.4+ds/cplcore/cpl_mpfit.c cpl-7.2.2+ds/cplcore/cpl_mpfit.c --- cpl-7.1.4+ds/cplcore/cpl_mpfit.c 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_mpfit.c 2022-04-29 14:56:02.000000000 +0000 @@ -34,28 +34,68 @@ /* Forward declarations of functions in this module */ static int _cpl_mp_fdjac2(mp_func funct, - int m, int n, int *ifree, int npar, double *x, double *fvec, - double *fjac, int ldfjac, double epsfcn, - double *wa, void *priv, int *nfev, - double *step, double *dstep, int *dside, - int *qulimited, double *ulimit, - int *ddebug, double *ddrtol, double *ddatol); -static void _cpl_mp_qrfac(int m, int n, double *a, int lda, - int pivot, int *ipvt, int lipvt, - double *rdiag, double *acnorm, double *wa); -static void _cpl_mp_qrsolv(int n, double *r, int ldr, int *ipvt, double *diag, - double *qtb, double *x, double *sdiag, double *wa); -static void _cpl_mp_lmpar(int n, double *r, int ldr, int *ipvt, int *ifree, double *diag, - double *qtb, double delta, double *par, double *x, - double *sdiag, double *wa1, double *wa2); + int m, + int n, + int *ifree, + int npar, + double *x, + double *fvec, + double *fjac, + int ldfjac, + double epsfcn, + double *wa, + void *priv, + int *nfev, + double *step, + double *dstep, + int *dside, + int *qulimited, + double *ulimit, + int *ddebug, + double *ddrtol, + double *ddatol); +static void _cpl_mp_qrfac(int m, + int n, + double *a, + int lda, + int pivot, + int *ipvt, + int lipvt, + double *rdiag, + double *acnorm, + double *wa); +static void _cpl_mp_qrsolv(int n, + double *r, + int ldr, + int *ipvt, + double *diag, + double *qtb, + double *x, + double *sdiag, + double *wa); +static void _cpl_mp_lmpar(int n, + double *r, + int ldr, + int *ipvt, + int *ifree, + double *diag, + double *qtb, + double delta, + double *par, + double *x, + double *sdiag, + double *wa1, + double *wa2); static double _cpl_mp_enorm(int n, double *x); static double _cpl_mp_dmax1(double a, double b); static double _cpl_mp_dmin1(double a, double b); static int _cpl_mp_min0(int a, int b); -static int _cpl_mp_covar(int n, double *r, int ldr, int *ipvt, double tol, double *wa); +static int +_cpl_mp_covar(int n, double *r, int ldr, int *ipvt, double tol, double *wa); /* Macro to call user function */ -#define mp_call(funct, m, n, x, fvec, dvec, priv) (*(funct))(m,n,x,fvec,dvec,priv) +#define mp_call(funct, m, n, x, fvec, dvec, priv) \ + (*(funct))(m, n, x, fvec, dvec, priv) /* * Macro to safely allocate memory @@ -64,12 +104,12 @@ * and the call to malloc has been replaced with a call to calloc, * which makes the initialization loop unnecessary. */ -#define mp_malloc(dest,type,size) \ - dest = (type *) cpl_calloc( size, sizeof(type) ); \ - if (dest == 0) { \ - info = MP_ERR_MEMORY; \ - goto CLEANUP; \ - } +#define mp_malloc(dest, type, size) \ + dest = (type *)cpl_calloc(size, sizeof(type)); \ + if (dest == 0) { \ + info = MP_ERR_MEMORY; \ + goto CLEANUP; \ + } /* * ********** @@ -281,719 +321,794 @@ * ********** */ -int cpl_mpfit(mp_func funct, int m, int npar, double *xall, mp_par *pars, - mp_config *config, void *private_data, mp_result *result) +int +cpl_mpfit(mp_func funct, + int m, + int npar, + double *xall, + mp_par *pars, + mp_config *config, + void *private_data, + mp_result *result) { - mp_config conf; - int i, j, info, iflag, nfree, npegged, iter; - int qanylim = 0; - - int ij,jj,l; - double actred,delta,dirder,fnorm,fnorm1,gnorm, orignorm; - double par,pnorm,prered,ratio; - double sum,temp,temp1,temp2,temp3,xnorm, alpha; - static double one = 1.0; - static double p1 = 0.1; - static double p5 = 0.5; - static double p25 = 0.25; - static double p75 = 0.75; - static double p0001 = 1.0e-4; - static double zero = 0.0; - int nfev = 0; - - double *step = 0, *dstep = 0, *llim = 0, *ulim = 0; - int *pfixed = 0, *mpside = 0, *ifree = 0, *qllim = 0, *qulim = 0; - int *ddebug = 0; - double *ddrtol = 0, *ddatol = 0; - - double *fvec = 0, *qtf = 0; - double *x = 0, *xnew = 0, *fjac = 0, *diag = 0; - double *wa1 = 0, *wa2 = 0, *wa3 = 0, *wa4 = 0; - int *ipvt = 0; - - int ldfjac; - - /* Default configuration */ - conf.ftol = 1e-10; - conf.xtol = 1e-10; - conf.gtol = 1e-10; - conf.stepfactor = 100.0; - conf.nprint = 1; - conf.epsfcn = MP_MACHEP0; - conf.maxiter = 200; - conf.douserscale = 0; - conf.maxfev = 0; - conf.covtol = 1e-14; - conf.nofinitecheck = 0; - - if (config) { - /* Transfer any user-specified configurations */ - if (config->ftol > 0) conf.ftol = config->ftol; - if (config->xtol > 0) conf.xtol = config->xtol; - if (config->gtol > 0) conf.gtol = config->gtol; - if (config->stepfactor > 0) conf.stepfactor = config->stepfactor; - if (config->nprint >= 0) conf.nprint = config->nprint; - if (config->epsfcn > 0) conf.epsfcn = config->epsfcn; - if (config->maxiter > 0) conf.maxiter = config->maxiter; - if (config->douserscale != 0) conf.douserscale = config->douserscale; - if (config->covtol > 0) conf.covtol = config->covtol; - if (config->nofinitecheck > 0) conf.nofinitecheck = config->nofinitecheck; - conf.maxfev = config->maxfev; - } - - info = 0; - iflag = 0; - nfree = 0; - npegged = 0; - - if (funct == 0) { - return MP_ERR_FUNC; - } - - if ((m <= 0) || (xall == 0)) { - return MP_ERR_NPOINTS; - } - - if (npar <= 0) { - return MP_ERR_NFREE; - } + mp_config conf; + int i, j, info, iflag, nfree, npegged, iter; + int qanylim = 0; + + int ij, jj, l; + double actred, delta, dirder, fnorm, fnorm1, gnorm, orignorm; + double par, pnorm, prered, ratio; + double sum, temp, temp1, temp2, temp3, xnorm, alpha; + static double one = 1.0; + static double p1 = 0.1; + static double p5 = 0.5; + static double p25 = 0.25; + static double p75 = 0.75; + static double p0001 = 1.0e-4; + static double zero = 0.0; + int nfev = 0; + + double *step = 0, *dstep = 0, *llim = 0, *ulim = 0; + int *pfixed = 0, *mpside = 0, *ifree = 0, *qllim = 0, *qulim = 0; + int *ddebug = 0; + double *ddrtol = 0, *ddatol = 0; + + double *fvec = 0, *qtf = 0; + double *x = 0, *xnew = 0, *fjac = 0, *diag = 0; + double *wa1 = 0, *wa2 = 0, *wa3 = 0, *wa4 = 0; + int *ipvt = 0; + + int ldfjac; + + /* Default configuration */ + conf.ftol = 1e-10; + conf.xtol = 1e-10; + conf.gtol = 1e-10; + conf.stepfactor = 100.0; + conf.nprint = 1; + conf.epsfcn = MP_MACHEP0; + conf.maxiter = 200; + conf.douserscale = 0; + conf.maxfev = 0; + conf.covtol = 1e-14; + conf.nofinitecheck = 0; + + if (config) { + /* Transfer any user-specified configurations */ + if (config->ftol > 0) + conf.ftol = config->ftol; + if (config->xtol > 0) + conf.xtol = config->xtol; + if (config->gtol > 0) + conf.gtol = config->gtol; + if (config->stepfactor > 0) + conf.stepfactor = config->stepfactor; + if (config->nprint >= 0) + conf.nprint = config->nprint; + if (config->epsfcn > 0) + conf.epsfcn = config->epsfcn; + if (config->maxiter > 0) + conf.maxiter = config->maxiter; + if (config->douserscale != 0) + conf.douserscale = config->douserscale; + if (config->covtol > 0) + conf.covtol = config->covtol; + if (config->nofinitecheck > 0) + conf.nofinitecheck = config->nofinitecheck; + conf.maxfev = config->maxfev; + } + + info = 0; + iflag = 0; + nfree = 0; + npegged = 0; + + if (funct == 0) { + return MP_ERR_FUNC; + } + + if ((m <= 0) || (xall == 0)) { + return MP_ERR_NPOINTS; + } + + if (npar <= 0) { + return MP_ERR_NFREE; + } + + fnorm = -1.0; + fnorm1 = -1.0; + xnorm = -1.0; + delta = 0.0; + + /* FIXED parameters? */ + mp_malloc(pfixed, int, npar); + if (pars) + for (i = 0; i < npar; i++) { + pfixed[i] = (pars[i].fixed) ? 1 : 0; + } - fnorm = -1.0; - fnorm1 = -1.0; - xnorm = -1.0; - delta = 0.0; - - /* FIXED parameters? */ - mp_malloc(pfixed, int, npar); - if (pars) for (i=0; i pars[i].limits[1])) ) { - info = MP_ERR_INITBOUNDS; - goto CLEANUP; - } - if ( (pars[i].fixed == 0) && pars[i].limited[0] && pars[i].limited[1] && - (pars[i].limits[0] >= pars[i].limits[1])) { - info = MP_ERR_BOUNDS; - goto CLEANUP; - } - } - - mp_malloc(qulim, int, nfree); - mp_malloc(qllim, int, nfree); - mp_malloc(ulim, double, nfree); - mp_malloc(llim, double, nfree); - - for (i=0; i pars[i].limits[1]))) { + info = MP_ERR_INITBOUNDS; + goto CLEANUP; + } + if ((pars[i].fixed == 0) && pars[i].limited[0] && + pars[i].limited[1] && + (pars[i].limits[0] >= pars[i].limits[1])) { + info = MP_ERR_BOUNDS; + goto CLEANUP; + } + } - /* Initialize Levelberg-Marquardt parameter and iteration counter */ + mp_malloc(qulim, int, nfree); + mp_malloc(qllim, int, nfree); + mp_malloc(ulim, double, nfree); + mp_malloc(llim, double, nfree); + + for (i = 0; i < nfree; i++) { + qllim[i] = pars[ifree[i]].limited[0]; + qulim[i] = pars[ifree[i]].limited[1]; + llim[i] = pars[ifree[i]].limits[0]; + ulim[i] = pars[ifree[i]].limits[1]; + if (qllim[i] || qulim[i]) + qanylim = 1; + } + } - par = 0.0; - iter = 1; - for (i=0; i 0)) { - ij = j*ldfjac; - for (i=0; i 0)) { + ij = j * ldfjac; + for (i = 0; i < m; i++, ij++) + fjac[ij] = 0; + } + if (upegged && (sum < 0)) { + ij = j * ldfjac; + for (i = 0; i < m; i++, ij++) + fjac[ij] = 0; + } + } } - } - /* Compute the QR factorization of the jacobian */ - _cpl_mp_qrfac(m,nfree,fjac,ldfjac,1,ipvt,nfree,wa1,wa2,wa3); + /* Compute the QR factorization of the jacobian */ + _cpl_mp_qrfac(m, nfree, fjac, ldfjac, 1, ipvt, nfree, wa1, wa2, wa3); - /* + /* * on the first iteration and if mode is 1, scale according * to the norms of the columns of the initial jacobian. */ - if (iter == 1) { - if (conf.douserscale == 0) { - for (j=0; j= ulim[j])); - int dwa1 = fabs(wa1[j]) > MP_MACHEP0; - - if (lpegged && (wa1[j] < 0)) wa1[j] = 0; - if (upegged && (wa1[j] > 0)) wa1[j] = 0; - - if (dwa1 && qllim[j] && ((x[j] + wa1[j]) < llim[j])) { - alpha = _cpl_mp_dmin1(alpha, (llim[j]-x[j])/wa1[j]); - } - if (dwa1 && qulim[j] && ((x[j] + wa1[j]) > ulim[j])) { - alpha = _cpl_mp_dmin1(alpha, (ulim[j]-x[j])/wa1[j]); - } - } - - /* Scale the resulting vector, advance to the next position */ - for (j=0; j= ulim[j])); + int dwa1 = fabs(wa1[j]) > MP_MACHEP0; + + if (lpegged && (wa1[j] < 0)) + wa1[j] = 0; + if (upegged && (wa1[j] > 0)) + wa1[j] = 0; + + if (dwa1 && qllim[j] && ((x[j] + wa1[j]) < llim[j])) { + alpha = _cpl_mp_dmin1(alpha, (llim[j] - x[j]) / wa1[j]); + } + if (dwa1 && qulim[j] && ((x[j] + wa1[j]) > ulim[j])) { + alpha = _cpl_mp_dmin1(alpha, (ulim[j] - x[j]) / wa1[j]); + } + } + + /* Scale the resulting vector, advance to the next position */ + for (j = 0; j < nfree; j++) { + double sgnu, sgnl; + double ulim1, llim1; - wa1[j] = wa1[j] * alpha; - wa2[j] = x[j] + wa1[j]; + wa1[j] = wa1[j] * alpha; + wa2[j] = x[j] + wa1[j]; - /* Adjust the output values. If the step put us exactly + /* Adjust the output values. If the step put us exactly * on a boundary, make sure it is exact. */ - sgnu = (ulim[j] >= 0) ? (+1) : (-1); - sgnl = (llim[j] >= 0) ? (+1) : (-1); - ulim1 = ulim[j]*(1-sgnu*MP_MACHEP0) - ((ulim[j] == 0)?(MP_MACHEP0):0); - llim1 = llim[j]*(1+sgnl*MP_MACHEP0) + ((llim[j] == 0)?(MP_MACHEP0):0); - - if (qulim[j] && (wa2[j] >= ulim1)) { - wa2[j] = ulim[j]; - } - if (qllim[j] && (wa2[j] <= llim1)) { - wa2[j] = llim[j]; - } + sgnu = (ulim[j] >= 0) ? (+1) : (-1); + sgnl = (llim[j] >= 0) ? (+1) : (-1); + ulim1 = ulim[j] * (1 - sgnu * MP_MACHEP0) - + ((ulim[j] == 0) ? (MP_MACHEP0) : 0); + llim1 = llim[j] * (1 + sgnl * MP_MACHEP0) + + ((llim[j] == 0) ? (MP_MACHEP0) : 0); + + if (qulim[j] && (wa2[j] >= ulim1)) { + wa2[j] = ulim[j]; + } + if (qllim[j] && (wa2[j] <= llim1)) { + wa2[j] = llim[j]; + } + } } - } + for (j = 0; j < nfree; j++) { + wa3[j] = diag[ifree[j]] * wa1[j]; + } - for (j=0; j= zero) { - temp = p5; - } else { - temp = p5*dirder/(dirder + p5*actred); - } - if (((p1*fnorm1) >= fnorm) - || (temp < p1) ) { - temp = p1; - } - delta = temp*_cpl_mp_dmin1(delta,pnorm/p1); - par = par/temp; - } else { - if ((par == zero) || (ratio >= p75) ) { - delta = pnorm/p5; - par = p5*par; + + if (ratio <= p25) { + if (actred >= zero) { + temp = p5; + } + else { + temp = p5 * dirder / (dirder + p5 * actred); + } + if (((p1 * fnorm1) >= fnorm) || (temp < p1)) { + temp = p1; + } + delta = temp * _cpl_mp_dmin1(delta, pnorm / p1); + par = par / temp; + } + else { + if ((par == zero) || (ratio >= p75)) { + delta = pnorm / p5; + par = p5 * par; + } } - } - /* + /* * test for successful iteration. */ - if (ratio >= p0001) { - - /* + if (ratio >= p0001) { + /* * successful iteration. update x, fvec, and their norms. */ - for (j=0; j 0) && (nfev >= conf.maxfev)) { - /* Too many function evaluations */ - info = MP_MAXITER; - } - if (iter >= conf.maxiter) { - /* Too many iterations */ - info = MP_MAXITER; - } - if ((fabs(actred) <= MP_MACHEP0) && (prered <= MP_MACHEP0) && (p5*ratio <= one) ) { - info = MP_FTOL; - } - if (delta <= MP_MACHEP0*xnorm) { - info = MP_XTOL; - } - if (gnorm <= MP_MACHEP0) { - info = MP_GTOL; - } - if (info != 0) { - goto L300; - } - - /* + if ((conf.maxfev > 0) && (nfev >= conf.maxfev)) { + /* Too many function evaluations */ + info = MP_MAXITER; + } + if (iter >= conf.maxiter) { + /* Too many iterations */ + info = MP_MAXITER; + } + if ((fabs(actred) <= MP_MACHEP0) && (prered <= MP_MACHEP0) && + (p5 * ratio <= one)) { + info = MP_FTOL; + } + if (delta <= MP_MACHEP0 * xnorm) { + info = MP_XTOL; + } + if (gnorm <= MP_MACHEP0) { + info = MP_GTOL; + } + if (info != 0) { + goto L300; + } + + /* * end of the inner loop. repeat if iteration unsuccessful. */ - if (ratio < p0001) goto L200; - /* + if (ratio < p0001) + goto L200; + /* * end of the outer loop. */ - goto OUTER_LOOP; + goto OUTER_LOOP; - L300: - /* +L300: + /* * termination, either normal or user imposed. */ - if (iflag < 0) { - info = iflag; - } - iflag = 0; + if (iflag < 0) { + info = iflag; + } + iflag = 0; - for (i=0; i 0) && (info > 0)) { - iflag = mp_call(funct, m, npar, xall, fvec, 0, private_data); - nfev += 1; - } + for (i = 0; i < nfree; i++) { + xall[ifree[i]] = x[i]; + } - /* Compute number of pegged parameters */ - npegged = 0; - if (pars) for (i=0; i 0) && (info > 0)) { + iflag = mp_call(funct, m, npar, xall, fvec, 0, private_data); + nfev += 1; } - } - /* Compute and return the covariance matrix and/or parameter errors */ - if (result && (result->covar || result->xerror)) { - _cpl_mp_covar(nfree, fjac, ldfjac, ipvt, conf.covtol, wa2); - - if (result->covar) { - /* Zero the destination covariance array */ - for (j=0; j<(npar*npar); j++) result->covar[j] = 0; - - /* Transfer the covariance array */ - for (j=0; jcovar[ifree[j]*npar+ifree[i]] = fjac[j*ldfjac+i]; - } - } - } - - if (result->xerror) { - for (j=0; jxerror[j] = 0; - - for (j=0; j 0) result->xerror[ifree[j]] = sqrt(cc); - } - } - } - - if (result) { - strcpy(result->version, MPFIT_VERSION); - result->bestnorm = _cpl_mp_dmax1(fnorm,fnorm1); - result->bestnorm *= result->bestnorm; - result->orignorm = orignorm; - result->status = info; - result->niter = iter; - result->nfev = nfev; - result->npar = npar; - result->nfree = nfree; - result->npegged = npegged; - result->nfunc = m; - - /* Copy residuals if requested */ - if (result->resid) { - for (j=0; jresid[j] = fvec[j]; + /* Compute number of pegged parameters */ + npegged = 0; + if (pars) + for (i = 0; i < npar; i++) { + if ((pars[i].limited[0] && (pars[i].limits[0] == xall[i])) || + (pars[i].limited[1] && (pars[i].limits[1] == xall[i]))) { + npegged++; + } + } + + /* Compute and return the covariance matrix and/or parameter errors */ + if (result && (result->covar || result->xerror)) { + _cpl_mp_covar(nfree, fjac, ldfjac, ipvt, conf.covtol, wa2); + + if (result->covar) { + /* Zero the destination covariance array */ + for (j = 0; j < (npar * npar); j++) + result->covar[j] = 0; + + /* Transfer the covariance array */ + for (j = 0; j < nfree; j++) { + for (i = 0; i < nfree; i++) { + result->covar[ifree[j] * npar + ifree[i]] = + fjac[j * ldfjac + i]; + } + } + } + + if (result->xerror) { + for (j = 0; j < npar; j++) + result->xerror[j] = 0; + + for (j = 0; j < nfree; j++) { + double cc = fjac[j * ldfjac + j]; + if (cc > 0) + result->xerror[ifree[j]] = sqrt(cc); + } + } + } + + if (result) { + strcpy(result->version, MPFIT_VERSION); + result->bestnorm = _cpl_mp_dmax1(fnorm, fnorm1); + result->bestnorm *= result->bestnorm; + result->orignorm = orignorm; + result->status = info; + result->niter = iter; + result->nfev = nfev; + result->npar = npar; + result->nfree = nfree; + result->npegged = npegged; + result->nfunc = m; + + /* Copy residuals if requested */ + if (result->resid) { + for (j = 0; j < m; j++) + result->resid[j] = fvec[j]; + } } - } - CLEANUP: - if (fvec) cpl_free(fvec); - if (qtf) cpl_free(qtf); - if (x) cpl_free(x); - if (xnew) cpl_free(xnew); - if (fjac) cpl_free(fjac); - if (diag) cpl_free(diag); - if (wa1) cpl_free(wa1); - if (wa2) cpl_free(wa2); - if (wa3) cpl_free(wa3); - if (wa4) cpl_free(wa4); - if (ipvt) cpl_free(ipvt); - if (pfixed) cpl_free(pfixed); - if (step) cpl_free(step); - if (dstep) cpl_free(dstep); - if (mpside) cpl_free(mpside); - if (ddebug) cpl_free(ddebug); - if (ddrtol) cpl_free(ddrtol); - if (ddatol) cpl_free(ddatol); - if (ifree) cpl_free(ifree); - if (qllim) cpl_free(qllim); - if (qulim) cpl_free(qulim); - if (llim) cpl_free(llim); - if (ulim) cpl_free(ulim); +CLEANUP: + if (fvec) + cpl_free(fvec); + if (qtf) + cpl_free(qtf); + if (x) + cpl_free(x); + if (xnew) + cpl_free(xnew); + if (fjac) + cpl_free(fjac); + if (diag) + cpl_free(diag); + if (wa1) + cpl_free(wa1); + if (wa2) + cpl_free(wa2); + if (wa3) + cpl_free(wa3); + if (wa4) + cpl_free(wa4); + if (ipvt) + cpl_free(ipvt); + if (pfixed) + cpl_free(pfixed); + if (step) + cpl_free(step); + if (dstep) + cpl_free(dstep); + if (mpside) + cpl_free(mpside); + if (ddebug) + cpl_free(ddebug); + if (ddrtol) + cpl_free(ddrtol); + if (ddatol) + cpl_free(ddatol); + if (ifree) + cpl_free(ifree); + if (qllim) + cpl_free(qllim); + if (qulim) + cpl_free(qulim); + if (llim) + cpl_free(llim); + if (ulim) + cpl_free(ulim); - return info; + return info; } /************************fdjac2.c*************************/ -static -int _cpl_mp_fdjac2(mp_func funct, - int m, int n, int *ifree, int npar, double *x, double *fvec, - double *fjac, int ldfjac, double epsfcn, - double *wa, void *priv, int *nfev, - double *step, double *dstep, int *dside, - int *qulimited, double *ulimit, - int *ddebug, double *ddrtol, double *ddatol) +static int +_cpl_mp_fdjac2(mp_func funct, + int m, + int n, + int *ifree, + int npar, + double *x, + double *fvec, + double *fjac, + int ldfjac, + double epsfcn, + double *wa, + void *priv, + int *nfev, + double *step, + double *dstep, + int *dside, + int *qulimited, + double *ulimit, + int *ddebug, + double *ddrtol, + double *ddatol) { -/* + /* * ********** * * subroutine fdjac2 @@ -1070,169 +1185,203 @@ * ********** */ - int i,j,ij; - int iflag = 0; - double eps,h,temp; - static double zero = 0.0; - double **dvec = 0; - int has_analytical_deriv = 0, has_numerical_deriv = 0; - int has_debug_deriv = 0; - - temp = _cpl_mp_dmax1(epsfcn,MP_MACHEP0); - eps = sqrt(temp); - ij = 0; - CPL_UNUSED(ldfjac); - - dvec = (double **) cpl_calloc(npar, sizeof(double *)); - if (dvec == 0) return MP_ERR_MEMORY; + int i, j, ij; + int iflag = 0; + double eps, h, temp; + static double zero = 0.0; + double **dvec = 0; + int has_analytical_deriv = 0, has_numerical_deriv = 0; + int has_debug_deriv = 0; + + temp = _cpl_mp_dmax1(epsfcn, MP_MACHEP0); + eps = sqrt(temp); + ij = 0; + CPL_UNUSED(ldfjac); + + dvec = (double **)cpl_calloc(npar, sizeof(double *)); + if (dvec == 0) + return MP_ERR_MEMORY; + + /* Initialize the Jacobian derivative matrix */ + for (j = 0; j < (n * m); j++) + fjac[j] = 0; - /* Initialize the Jacobian derivative matrix */ - for (j=0; j<(n*m); j++) fjac[j] = 0; - - /* Check for which parameters need analytical derivatives and which + /* Check for which parameters need analytical derivatives and which need numerical ones */ - for (j=0; j 0) + h = step[ifree[j]]; + if (dstep && dstep[ifree[j]] > 0) + h = fabs(dstep[ifree[j]] * temp); + if (h == zero) + h = eps; + + /* If negative step requested, or we are against the upper limit */ + if ((dside && dsidei == -1) || + (dside && dsidei == 0 && qulimited && ulimit && qulimited[j] && + (temp > (ulimit[j] - h)))) { + h = -h; + } + + x[ifree[j]] = temp + h; + iflag = mp_call(funct, m, npar, x, wa, 0, priv); + if (nfev) + *nfev = *nfev + 1; + if (iflag < 0) + goto DONE; + x[ifree[j]] = temp; + + if (dsidei <= 1) { + /* COMPUTE THE ONE-SIDED DERIVATIVE */ + if (!debug) { + /* Non-debug path for speed */ + for (i = 0; i < m; i++, ij++) { + fjac[ij] = (wa[i] - fvec[i]) / h; /* fjac[i+m*j] */ + } + } + else { + /* Debug path for correctness */ + for (i = 0; i < m; i++, ij++) { + double fjold = fjac[ij]; + fjac[ij] = (wa[i] - fvec[i]) / h; /* fjac[i+m*j] */ + if ((da == 0 && dr == 0 && + (fjold != 0 || fjac[ij] != 0)) || + ((da != 0 || dr != 0) && (fabs(fjold - fjac[ij]) > + da + fabs(fjold) * dr))) { + printf( + " %10d %10.4g %10.4g %10.4g %10.4g %10.4g\n", + i, fvec[i], fjold, fjac[ij], fjold - fjac[ij], + (fjold == 0) ? (0) + : ((fjold - fjac[ij]) / fjold)); + } + } + } + } + else { + /* COMPUTE THE TWO-SIDED DERIVATIVE */ + for (i = 0; i < m; i++, ij++) { + fjac[ij] = wa[i]; /* Store temp data: fjac[i+m*j] */ + } + + /* Evaluate at x - h */ + x[ifree[j]] = temp - h; + iflag = mp_call(funct, m, npar, x, wa, 0, priv); + if (nfev) + *nfev = *nfev + 1; + if (iflag < 0) + goto DONE; + x[ifree[j]] = temp; + + /* Now compute derivative as (f(x+h) - f(x-h))/(2h) */ + ij -= m; + if (!debug) { + for (i = 0; i < m; i++, ij++) { + fjac[ij] = + (fjac[ij] - wa[i]) / (2 * h); /* fjac[i+m*j] */ + } + } + else { + for (i = 0; i < m; i++, ij++) { + double fjold = fjac[ij]; + fjac[ij] = + (fjac[ij] - wa[i]) / (2 * h); /* fjac[i+m*j] */ + if ((da == 0 && dr == 0 && + (fjold != 0 || fjac[ij] != 0)) || + ((da != 0 || dr != 0) && (fabs(fjold - fjac[ij]) > + da + fabs(fjold) * dr))) { + printf( + " %10d %10.4g %10.4g %10.4g %10.4g %10.4g\n", + i, fvec[i], fjold, fjac[ij], fjold - fjac[ij], + (fjold == 0) ? (0) + : ((fjold - fjac[ij]) / fjold)); + } + } + } + } + } - /* Any parameters requiring numerical derivatives */ - if (has_numerical_deriv) for (j=0; j 0) h = step[ifree[j]]; - if (dstep && dstep[ifree[j]] > 0) h = fabs(dstep[ifree[j]]*temp); - if (h == zero) h = eps; - - /* If negative step requested, or we are against the upper limit */ - if ((dside && dsidei == -1) || - (dside && dsidei == 0 && - qulimited && ulimit && qulimited[j] && - (temp > (ulimit[j]-h)))) { - h = -h; - } - - x[ifree[j]] = temp + h; - iflag = mp_call(funct, m, npar, x, wa, 0, priv); - if (nfev) *nfev = *nfev + 1; - if (iflag < 0 ) goto DONE; - x[ifree[j]] = temp; - - if (dsidei <= 1) { - /* COMPUTE THE ONE-SIDED DERIVATIVE */ - if (! debug) { - /* Non-debug path for speed */ - for (i=0; i da + fabs(fjold)*dr))) { - printf(" %10d %10.4g %10.4g %10.4g %10.4g %10.4g\n", - i, fvec[i], fjold, fjac[ij], fjold-fjac[ij], - (fjold == 0)?(0):((fjold-fjac[ij])/fjold)); - } - } - } - - } else { - /* COMPUTE THE TWO-SIDED DERIVATIVE */ - for (i=0; i da + fabs(fjold)*dr))) { - printf(" %10d %10.4g %10.4g %10.4g %10.4g %10.4g\n", - i, fvec[i], fjold, fjac[ij], fjold-fjac[ij], - (fjold == 0)?(0):((fjold-fjac[ij])/fjold)); - } - } - } - + if (has_debug_deriv) { + printf("FJAC DEBUG END\n"); } - } - if (has_debug_deriv) { - printf("FJAC DEBUG END\n"); - } - - DONE: - if (dvec) cpl_free(dvec); - if (iflag < 0) return iflag; - return 0; - /* +DONE: + if (dvec) + cpl_free(dvec); + if (iflag < 0) + return iflag; + return 0; + /* * last card of subroutine fdjac2. */ } /************************qrfac.c*************************/ - -static -void _cpl_mp_qrfac(int m, int n, double *a, int lda, - int pivot, int *ipvt, int lipvt, - double *rdiag, double *acnorm, double *wa) + +static void +_cpl_mp_qrfac(int m, + int n, + double *a, + int lda, + int pivot, + int *ipvt, + int lipvt, + double *rdiag, + double *acnorm, + double *wa) { -/* + /* * ********** * * subroutine qrfac @@ -1309,137 +1458,135 @@ * * ********** */ - int i,ij,jj,j,jp1,k,kmax,minmn; - double ajnorm,sum,temp; - static double zero = 0.0; - static double one = 1.0; - static double p05 = 0.05; + int i, ij, jj, j, jp1, k, kmax, minmn; + double ajnorm, sum, temp; + static double zero = 0.0; + static double one = 1.0; + static double p05 = 0.05; - CPL_UNUSED(lda); - CPL_UNUSED(lipvt); + CPL_UNUSED(lda); + CPL_UNUSED(lipvt); - /* + /* * compute the initial column norms and initialize several arrays. */ - ij = 0; - for (j=0; j rdiag[kmax]) - kmax = k; - } - if (kmax == j) - goto L40; - - ij = m * j; - jj = m * kmax; - for (i=0; i rdiag[kmax]) + kmax = k; + } + if (kmax == j) + goto L40; + + ij = m * j; + jj = m * kmax; + for (i = 0; i < m; i++) { + temp = a[ij]; /* [i+m*j] */ + a[ij] = a[jj]; /* [i+m*kmax] */ + a[jj] = temp; + ij += 1; + jj += 1; + } + rdiag[kmax] = rdiag[j]; + wa[kmax] = wa[j]; + k = ipvt[j]; + ipvt[j] = ipvt[kmax]; + ipvt[kmax] = k; + + L40: + /* * compute the householder transformation to reduce the * j-th column of a to a multiple of the j-th unit vector. */ - jj = j + m*j; - ajnorm = _cpl_mp_enorm(m-j,&a[jj]); - if (ajnorm == zero) - goto L100; - if (a[jj] < zero) - ajnorm = -ajnorm; - ij = jj; - for (i=j; i kp1) - { - ik = kk + 1; - for (i=kp1; i kp1) { + ik = kk + 1; + for (i = kp1; i < n; i++) { + temp = cosx * r[ik] + sinx * sdiag[i]; + sdiag[i] = -sinx * r[ik] + cosx * sdiag[i]; + r[ik] = temp; + ik += 1; /* [i+ldr*k] */ + } + } + } + L90: + /* * store the diagonal element of s and restore * the corresponding diagonal element of r. */ - kk = j + ldr*j; - sdiag[j] = r[kk]; - r[kk] = x[j]; - } - /* + kk = j + ldr * j; + sdiag[j] = r[kk]; + r[kk] = x[j]; + } + /* * solve the triangular system for z. if the system is * singular, then obtain a least squares solution. */ - nsing = n; - for (j=0; j jp1) - { - ij = jp1 + ldr * j; - for (i=jp1; i jp1) { + ij = jp1 + ldr * j; + for (i = jp1; i < nsing; i++) { + sum += r[ij] * wa[i]; + ij += 1; /* [i+ldr*j] */ + } + } + wa[j] = (wa[j] - sum) / sdiag[j]; + } +L150: + /* * permute the components of z back to components of x. */ - for (j=0; j= 1) { + for (k = 0; k < nsing; k++) { + j = nsing - k - 1; + wa1[j] = wa1[j] / r[j + ldr * j]; + temp = wa1[j]; + jm1 = j - 1; + if (jm1 >= 0) { + ij = ldr * j; + for (i = 0; i <= jm1; i++) { + wa1[i] -= r[ij] * temp; + ij += 1; + } + } + } + } - if (nsing >= 1) { - for (k=0; k= 0) - { - ij = ldr * j; - for (i=0; i<=jm1; i++) - { - wa1[i] -= r[ij]*temp; - ij += 1; - } - } - } - } - - for (j=0; j= n) { - for (j=0; j= 0) - { - ij = jj; - for (i=0; i<=jm1; i++) - { - sum += r[ij]*wa1[i]; - ij += 1; - } - } - wa1[j] = (wa1[j] - sum)/r[j+ldr*j]; - jj += ldr; /* [i+ldr*j] */ - } - temp = _cpl_mp_enorm(n,wa1); - parl = ((fp/delta)/temp)/temp; - } - /* + parl = zero; + if (nsing >= n) { + for (j = 0; j < n; j++) { + l = ipvt[j]; + wa1[j] = diag[ifree[l]] * (wa2[l] / dxnorm); + } + jj = 0; + for (j = 0; j < n; j++) { + sum = zero; + jm1 = j - 1; + if (jm1 >= 0) { + ij = jj; + for (i = 0; i <= jm1; i++) { + sum += r[ij] * wa1[i]; + ij += 1; + } + } + wa1[j] = (wa1[j] - sum) / r[j + ldr * j]; + jj += ldr; /* [i+ldr*j] */ + } + temp = _cpl_mp_enorm(n, wa1); + parl = ((fp / delta) / temp) / temp; + } + /* * calculate an upper bound, paru, for the zero of the function. */ - jj = 0; - for (j=0; j zero) - parl = _cpl_mp_dmax1(parl, *par); - if (fp < zero) - paru = _cpl_mp_dmin1(paru, *par); - /* + if (fp > zero) + parl = _cpl_mp_dmax1(parl, *par); + if (fp < zero) + paru = _cpl_mp_dmin1(paru, *par); + /* * compute an improved estimate for par. */ - *par = _cpl_mp_dmax1(parl, *par + parc); - /* + *par = _cpl_mp_dmax1(parl, *par + parc); + /* * end of an iteration. */ - goto L150; - - L220: - /* + goto L150; + +L220: + /* * termination. */ - if (iter == 0) - *par = zero; - /* + if (iter == 0) + *par = zero; + /* * last card of subroutine lmpar. */ } /************************enorm.c*************************/ - -static -double _cpl_mp_enorm(int n, double *x) + +static double +_cpl_mp_enorm(int n, double *x) { - /* + /* * ********** * * function enorm @@ -2006,121 +2144,113 @@ * * ********** */ - int i; - double agiant,floatn,s1,s2,s3,xabs,x1max,x3max; - double ans, temp; - double rdwarf = MP_RDWARF; - double rgiant = MP_RGIANT; - static double zero = 0.0; - static double one = 1.0; - - s1 = zero; - s2 = zero; - s3 = zero; - x1max = zero; - x3max = zero; - floatn = n; - agiant = rgiant/floatn; - - for (i=0; i rdwarf) && (xabs < agiant)) - { - /* + int i; + double agiant, floatn, s1, s2, s3, xabs, x1max, x3max; + double ans, temp; + double rdwarf = MP_RDWARF; + double rgiant = MP_RGIANT; + static double zero = 0.0; + static double one = 1.0; + + s1 = zero; + s2 = zero; + s3 = zero; + x1max = zero; + x3max = zero; + floatn = n; + agiant = rgiant / floatn; + + for (i = 0; i < n; i++) { + xabs = fabs(x[i]); + if ((xabs > rdwarf) && (xabs < agiant)) { + /* * sum for intermediate components. */ - s2 += xabs*xabs; - continue; - } - - if (xabs > rdwarf) - { - /* + s2 += xabs * xabs; + continue; + } + + if (xabs > rdwarf) { + /* * sum for large components. */ - if (xabs > x1max) - { - temp = x1max/xabs; - s1 = one + s1*temp*temp; - x1max = xabs; - } - else - { - temp = xabs/x1max; - s1 += temp*temp; - } - continue; - } - /* + if (xabs > x1max) { + temp = x1max / xabs; + s1 = one + s1 * temp * temp; + x1max = xabs; + } + else { + temp = xabs / x1max; + s1 += temp * temp; + } + continue; + } + /* * sum for small components. */ - if (xabs > x3max) - { - temp = x3max/xabs; - s3 = one + s3*temp*temp; - x3max = xabs; - } - else - { - if (xabs != zero) - { - temp = xabs/x3max; - s3 += temp*temp; - } - } - } - /* + if (xabs > x3max) { + temp = x3max / xabs; + s3 = one + s3 * temp * temp; + x3max = xabs; + } + else { + if (xabs != zero) { + temp = xabs / x3max; + s3 += temp * temp; + } + } + } + /* * calculation of norm. */ - if (s1 != zero) { - temp = s1 + (s2/x1max)/x1max; - ans = x1max*sqrt(temp); - return(ans); - } - if (s2 != zero) { - if (s2 >= x3max) - temp = s2*(one+(x3max/s2)*(x3max*s3)); - else - temp = x3max*((s2/x3max)+(x3max*s3)); - ans = sqrt(temp); - } - else - { - ans = x3max*sqrt(s3); + if (s1 != zero) { + temp = s1 + (s2 / x1max) / x1max; + ans = x1max * sqrt(temp); + return (ans); + } + if (s2 != zero) { + if (s2 >= x3max) + temp = s2 * (one + (x3max / s2) * (x3max * s3)); + else + temp = x3max * ((s2 / x3max) + (x3max * s3)); + ans = sqrt(temp); } - return(ans); - /* + else { + ans = x3max * sqrt(s3); + } + return (ans); + /* * last card of function enorm. */ } /************************lmmisc.c*************************/ -static -double _cpl_mp_dmax1(double a, double b) +static double +_cpl_mp_dmax1(double a, double b) { - if (a >= b) - return(a); - else - return(b); + if (a >= b) + return (a); + else + return (b); } -static -double _cpl_mp_dmin1(double a, double b) +static double +_cpl_mp_dmin1(double a, double b) { - if (a <= b) - return(a); - else - return(b); + if (a <= b) + return (a); + else + return (b); } -static -int _cpl_mp_min0(int a, int b) +static int +_cpl_mp_min0(int a, int b) { - if (a <= b) - return(a); - else - return(b); + if (a <= b) + return (a); + else + return (b); } /************************covar.c*************************/ @@ -2192,15 +2322,15 @@ c ********** */ -static -int _cpl_mp_covar(int n, double *r, int ldr, int *ipvt, double tol, double *wa) +static int +_cpl_mp_covar(int n, double *r, int ldr, int *ipvt, double tol, double *wa) { - int i, ii, j, jj, k, l; - int kk, kj, ji, j0, k0, jj0; - int sing; - double one = 1.0, temp, tolr, zero = 0.0; + int i, ii, j, jj, k, l; + int kk, kj, ji, j0, k0, jj0; + int sing; + double one = 1.0, temp, tolr, zero = 0.0; - /* + /* * form the inverse of r in the full upper triangle of r. */ @@ -2213,81 +2343,86 @@ } #endif - tolr = tol*fabs(r[0]); - l = -1; - for (k=0; k= 0) { - for (k=0; k <= l; k++) { - k0 = k*ldr; - - for (j=0; j= 0) { + for (k = 0; k <= l; k++) { + k0 = k * ldr; + + for (j = 0; j < k; j++) { + temp = r[k * ldr + j]; + + j0 = j * ldr; + for (i = 0; i <= j; i++) { + r[j0 + i] += temp * r[k0 + i]; + } + } + + temp = r[k0 + k]; + for (i = 0; i <= k; i++) { + r[k0 + i] *= temp; + } + } } - } - /* + /* * For the full lower triangle of the covariance matrix * in the strict lower triangle or and in wa */ - for (j=0; j l); - j0 = j*ldr; - jj0 = jj*ldr; - for (i=0; i<=j; i++) { - ji = j0+i; - - if (sing) r[ji] = zero; - ii = ipvt[i]; - if (ii > jj) r[jj0+ii] = r[ji]; - if (ii < jj) r[ii*ldr+jj] = r[ji]; + for (j = 0; j < n; j++) { + jj = ipvt[j]; + sing = (j > l); + j0 = j * ldr; + jj0 = jj * ldr; + for (i = 0; i <= j; i++) { + ji = j0 + i; + + if (sing) + r[ji] = zero; + ii = ipvt[i]; + if (ii > jj) + r[jj0 + ii] = r[ji]; + if (ii < jj) + r[ii * ldr + jj] = r[ji]; + } + wa[jj] = r[j0 + j]; } - wa[jj] = r[j0+j]; - } - /* + /* * Symmetrize the covariance matrix in r */ - for (j=0; j +#include #endif #include @@ -29,30 +29,30 @@ #include #ifdef HAVE_UNISTD_H -# include +#include #endif #ifdef HAVE_TERMIOS_H -# include +#include #else -# ifdef HAVE_TERMIO_H -# include -# else -# error Neither termios.h nor termio.h found! -# endif +#ifdef HAVE_TERMIO_H +#include +#else +#error Neither termios.h nor termio.h found! +#endif #endif #ifdef HAVE_STROPTS_H -# include +#include #endif #if !defined(HAVE_STROPTS_H) || defined(HAVE_TERMIOS_H) || \ defined(GWINSZ_IN_SYS_IOCTL) -# ifdef HAVE_SYS_IOCTL_H -# include -# else -# error Cannot find header file for ioctl()! -# endif +#ifdef HAVE_SYS_IOCTL_H +#include +#else +#error Cannot find header file for ioctl()! +#endif #endif @@ -60,9 +60,10 @@ #undef CPL_HAVE_WINDOW_RESIZING #ifndef __STRICT_ANSI__ - /* gcc -ansi and gcc -std=... enters here */ +/* gcc -ansi and gcc -std=... enters here */ #if defined HAVE_FILENO && defined HAVE_FDOPEN && defined HAVE_DUP -#if defined HAVE_DECL_FILENO && defined HAVE_DECL_FDOPEN && defined HAVE_DECL_DUP +#if defined HAVE_DECL_FILENO && defined HAVE_DECL_FDOPEN && \ + defined HAVE_DECL_DUP #define CPL_HAVE_STREAM_DUPLICATION #if defined HAVE_SIGACTION && defined HAVE_SIGEMPTYSET #define CPL_HAVE_WINDOW_RESIZING @@ -72,7 +73,7 @@ #endif #ifdef _OPENMP -# include +#include #endif #include @@ -164,7 +165,7 @@ * If this number is zero or negative, then lines are not splitted. */ -#define DEFAULT_WIDTH (-1) +#define DEFAULT_WIDTH (-1) /* @@ -176,47 +177,47 @@ #define INFO_STRING "[ INFO ] " #define DEBUG_STRING "[ DEBUG ] " -inline static -void cpl_msg_out(cpl_msg_severity, const char *, int, - const char *, va_list) CPL_ATTR_PRINTF(4,0); - -static const char default_component[] = ""; -static const char default_format[] = ""; - -static cpl_msg_severity log_min_level = CPL_MSG_OFF; -static cpl_msg_severity term_min_level = CPL_MSG_INFO; -static int time_tag = 0; -static int threadid_tag = 0; -static int domain_tag = 0; -static int component_tag = 0; -static int msg_init = 0; - -static char domain[CPL_MAX_DOMAIN_NAME] = "Undefined domain"; -static char logfile_name[CPL_MAX_LOGFILE_NAME] = ".logfile"; -static FILE *logfile = NULL; - -static int page_width = DEFAULT_WIDTH; -static const int log_width = DEFAULT_WIDTH; -static int indent_step = 2; -static int indent_value = 0; -static int overwrite = 0; +inline static void +cpl_msg_out(cpl_msg_severity, const char *, int, const char *, va_list) + CPL_ATTR_PRINTF(4, 0); + +static const char default_component[] = ""; +static const char default_format[] = ""; + +static cpl_msg_severity log_min_level = CPL_MSG_OFF; +static cpl_msg_severity term_min_level = CPL_MSG_INFO; +static int time_tag = 0; +static int threadid_tag = 0; +static int domain_tag = 0; +static int component_tag = 0; +static int msg_init = 0; + +static char domain[CPL_MAX_DOMAIN_NAME] = "Undefined domain"; +static char logfile_name[CPL_MAX_LOGFILE_NAME] = ".logfile"; +static FILE *logfile = NULL; + +static int page_width = DEFAULT_WIDTH; +static const int log_width = DEFAULT_WIDTH; +static int indent_step = 2; +static int indent_value = 0; +static int overwrite = 0; #ifdef _OPENMP #pragma omp threadprivate(indent_value, overwrite) #endif -static FILE *msg_stdout; -static FILE *msg_stderr; +static FILE *msg_stdout; +static FILE *msg_stderr; #ifdef CPL_HAVE_STREAM_DUPLICATION -static int out_stream; +static int out_stream; #ifdef CPL_HAVE_WINDOW_RESIZING static struct sigaction act, oact; #endif #endif -static cx_print_func default_printer; -static cx_print_func default_error; +static cx_print_func default_printer; +static cx_print_func default_error; /* @@ -229,21 +230,26 @@ * called by the user. */ -inline static void _cpl_msg_init(const char *component) +inline static void +_cpl_msg_init(const char *component) { if (msg_init == 0) { if (cpl_msg_init() == CPL_ERROR_NONE) { - cpl_msg_warning("CPL messaging", - "The CPL messaging function %s() was called before the system " - "had been initialised. Please call the function cpl_init() " - "before attempting to use any CPL function.", component); + cpl_msg_warning( + "CPL messaging", + "The CPL messaging function %s() was called before the system " + "had been initialised. Please call the function cpl_init() " + "before attempting to use any CPL function.", + component); } else { fprintf(stderr, "%s\n", cpl_error_get_message()); - fprintf(stderr, "SEVERE ERROR: The CPL messaging system has " - "not been initialised, and this may cause undefined program " - "behaviour: please call the function cpl_init() before " - "attempting to use any CPL function."); + fprintf( + stderr, + "SEVERE ERROR: The CPL messaging system has " + "not been initialised, and this may cause undefined program " + "behaviour: please call the function cpl_init() before " + "attempting to use any CPL function."); } msg_init = 1; } @@ -260,20 +266,18 @@ * This private function just returns the current time in ISO8601 format. */ -static void _cpl_timestamp_iso8601(char *timestamp) +static void +_cpl_timestamp_iso8601(char *timestamp) { - char _timestamp[TIME_ISO8601_LENGTH]; const time_t seconds = time(NULL); strncpy(_timestamp, "0000-00-00T00:00:00", TIME_ISO8601_LENGTH); if (seconds != ((time_t)-1)) { - struct tm time_of_day; if (localtime_r(&seconds, &time_of_day) != NULL) { - int _errno = errno; strftime(_timestamp, TIME_ISO8601_LENGTH, "%Y-%m-%dT%H:%M:%S", &time_of_day); @@ -284,14 +288,11 @@ */ errno = _errno; - } - } strncpy(timestamp, _timestamp, TIME_ISO8601_LENGTH); return; - } #ifdef CPL_HAVE_STREAM_DUPLICATION @@ -308,9 +309,9 @@ * subsystem to the new window size on arrival of the signal @c SIGWINCH. */ -static void _cpl_change_width(int i) +static void +_cpl_change_width(int i) { - struct winsize win; CPL_UNUSED(i); @@ -319,7 +320,6 @@ page_width = DEFAULT_WIDTH; else page_width = win.ws_col; - } #endif @@ -336,12 +336,11 @@ * to standard output. */ -static void _cpl_print_out(const cxchar *message) +static void +_cpl_print_out(const cxchar *message) { - fputs(message, msg_stdout); fflush(msg_stdout); - } @@ -357,12 +356,11 @@ * to standard output. */ -static void _cpl_print_err(const cxchar *message) +static void +_cpl_print_err(const cxchar *message) { - fputs(message, msg_stderr); fflush(msg_stderr); - } @@ -391,12 +389,12 @@ * not exceed the maximum allowed width. */ -static const char *strsplit(char * split, const char *s, int blanks, int width) +static const char * +strsplit(char *split, const char *s, int blanks, int width) { - int i, j, k; - int cuti = 0; - int cutj = 0; + int cuti = 0; + int cutj = 0; int limit = width; @@ -404,18 +402,15 @@ return s; if (blanks >= width) - blanks = width - 1; /* Give up indentation */ - - for (i = 0, j = 0; - i < CPL_MAX_MSG_LENGTH && j < CPL_MAX_MSG_LENGTH; i++, j++) { + blanks = width - 1; /* Give up indentation */ + for (i = 0, j = 0; i < CPL_MAX_MSG_LENGTH && j < CPL_MAX_MSG_LENGTH; + i++, j++) { split[j] = s[i]; if (s[i] == ' ' || s[i] == '\0' || s[i] == '\n') { - if (i >= limit) { - - /* + /* * Go back to the previous cuttable position, if possible */ @@ -428,14 +423,13 @@ break; } - /* + /* * Split here, and insert blanks */ split[j] = '\n'; - for (k = 0, j++; - k < blanks && j < CPL_MAX_MSG_LENGTH; k++, j++) + for (k = 0, j++; k < blanks && j < CPL_MAX_MSG_LENGTH; k++, j++) split[j] = ' '; j--; @@ -443,48 +437,45 @@ } else { if (s[i] == '\0') - break; + break; if (s[i] == '\n') { - - /* + /* * Split point already present in input string: just add * the specified number of blanks */ - if (s[i+1] == '\0') { + if (s[i + 1] == '\0') { split[j] = '\0'; break; } - for (k = 0, j++; - k < blanks && j < CPL_MAX_MSG_LENGTH; k++, j++) + for (k = 0, j++; k < blanks && j < CPL_MAX_MSG_LENGTH; + k++, j++) split[j] = ' '; j--; limit = width - blanks + i; } - /* + /* * Keep track of the last cuttable position */ cutj = j; cuti = i; - } } } - /* + /* * Safety belt! */ split[CPL_MAX_MSG_LENGTH - 1] = '\0'; return split; - } @@ -512,23 +503,26 @@ * @see cpl_msg_set_level(), cpl_msg_set_log_level() */ -inline static void cpl_msg_out(cpl_msg_severity severity, - const char *component, int caller, - const char *format, va_list al) +inline static void +cpl_msg_out(cpl_msg_severity severity, + const char *component, + int caller, + const char *format, + va_list al) { struct tm time_of_day; time_t seconds; - char msg_text[CPL_MAX_MSG_LENGTH] = ""; - char msg_log[CPL_MAX_MSG_LENGTH] = ""; - char msg_term[CPL_MAX_MSG_LENGTH] = ""; - char split[CPL_MAX_MSG_LENGTH]; + char msg_text[CPL_MAX_MSG_LENGTH] = ""; + char msg_log[CPL_MAX_MSG_LENGTH] = ""; + char msg_term[CPL_MAX_MSG_LENGTH] = ""; + char split[CPL_MAX_MSG_LENGTH]; #ifdef _OPENMP - char *tid; + char *tid; #endif - int start_log_line, start_term_line; - int copy_only; - int i; + int start_log_line, start_term_line; + int copy_only; + int i; if (severity < term_min_level && severity < log_min_level) @@ -542,18 +536,17 @@ cx_vsnprintf(msg_text, CPL_MAX_MSG_LENGTH, format, al); - /* + /* * Date and time. Note that time tag and severity field are not * affected by indentation. Date and time are always present in * the log file, optional in the terminal output. */ if (localtime_r(&seconds, &time_of_day) == NULL) { - msg_log[0] = '\0'; + msg_log[0] = '\0'; msg_term[0] = '\0'; } else { - /* three 2-digit integers + 2 colons + 1 space + terminating 0 */ char msg_timestamp[10]; @@ -567,11 +560,10 @@ else { msg_term[0] = '\0'; } - } - /* + /* * Severity label */ @@ -579,29 +571,28 @@ strncat(msg_log, ERROR_STRING, CPL_MAX_MSG_LENGTH - strlen(msg_log) - 1); strncat(msg_term, ERROR_STRING, - CPL_MAX_MSG_LENGTH - strlen(msg_term) - 1); + CPL_MAX_MSG_LENGTH - strlen(msg_term) - 1); } else if (severity == CPL_MSG_WARNING) { strncat(msg_log, WARNING_STRING, - CPL_MAX_MSG_LENGTH - strlen(msg_log) - 1); + CPL_MAX_MSG_LENGTH - strlen(msg_log) - 1); strncat(msg_term, WARNING_STRING, - CPL_MAX_MSG_LENGTH - strlen(msg_term) - 1); + CPL_MAX_MSG_LENGTH - strlen(msg_term) - 1); } else if (severity == CPL_MSG_INFO) { - strncat(msg_log, INFO_STRING, - CPL_MAX_MSG_LENGTH - strlen(msg_log) - 1); + strncat(msg_log, INFO_STRING, CPL_MAX_MSG_LENGTH - strlen(msg_log) - 1); strncat(msg_term, INFO_STRING, - CPL_MAX_MSG_LENGTH - strlen(msg_term) - 1); + CPL_MAX_MSG_LENGTH - strlen(msg_term) - 1); } else if (severity == CPL_MSG_DEBUG) { strncat(msg_log, DEBUG_STRING, - CPL_MAX_MSG_LENGTH - strlen(msg_log) - 1); + CPL_MAX_MSG_LENGTH - strlen(msg_log) - 1); strncat(msg_term, DEBUG_STRING, - CPL_MAX_MSG_LENGTH - strlen(msg_term) - 1); + CPL_MAX_MSG_LENGTH - strlen(msg_term) - 1); } - /* + /* * Domain, component name, and message appended: */ @@ -621,19 +612,19 @@ #ifdef _OPENMP - /* + /* * Thread ID */ - tid = cpl_sprintf("[tid=%03d] ", omp_get_thread_num()); - strncat(msg_log, tid, CPL_MAX_MSG_LENGTH - strlen(msg_log) - 1); - if (threadid_tag) - strncat(msg_term, tid, CPL_MAX_MSG_LENGTH - strlen(msg_term) - 1); - cpl_free(tid); + tid = cpl_sprintf("[tid=%03d] ", omp_get_thread_num()); + strncat(msg_log, tid, CPL_MAX_MSG_LENGTH - strlen(msg_log) - 1); + if (threadid_tag) + strncat(msg_term, tid, CPL_MAX_MSG_LENGTH - strlen(msg_term) - 1); + cpl_free(tid); #endif - /* + /* * Message indentation */ @@ -647,7 +638,7 @@ start_term_line = strlen(msg_term); - /* + /* * Finally add the message text. If message is too long * it is truncated. */ @@ -664,29 +655,28 @@ if (severity >= term_min_level) { if (severity > CPL_MSG_WARNING) { if (overwrite) { - cx_printerr("\n%s\n", strsplit(split, msg_term, - start_term_line, page_width)); + cx_printerr("\n%s\n", strsplit(split, msg_term, start_term_line, + page_width)); overwrite = 0; } else - cx_printerr("%s\n", strsplit(split, msg_term, - start_term_line, page_width)); + cx_printerr("%s\n", strsplit(split, msg_term, start_term_line, + page_width)); + } + else if (caller) { + char *c = strrchr(msg_term, '\n'); + if (c >= msg_term) + *c = '\0'; + cx_print("\r%s", msg_term); + } + else if (overwrite) { + cx_print("\n%s\n", + strsplit(split, msg_term, start_term_line, page_width)); + overwrite = 0; } else - if (caller) { - char *c = strrchr(msg_term, '\n'); - if (c >= msg_term) *c = '\0'; - cx_print("\r%s", msg_term); - } - else - if (overwrite) { - cx_print("\n%s\n", strsplit(split, msg_term, - start_term_line, page_width)); - overwrite = 0; - } - else - cx_print("%s\n", strsplit(split, msg_term, - start_term_line, page_width)); + cx_print("%s\n", + strsplit(split, msg_term, start_term_line, page_width)); } } @@ -740,9 +730,9 @@ * a non positive width. */ -cpl_error_code cpl_msg_init(void) +cpl_error_code +cpl_msg_init(void) { - #ifdef CPL_HAVE_STREAM_DUPLICATION struct winsize win; static int err_stream; @@ -783,7 +773,7 @@ #ifdef CPL_HAVE_STREAM_DUPLICATION #ifdef CPL_HAVE_WINDOW_RESIZING - /* + /* * Get the terminal window size, and if successful deploy the handler * for any image resizing at runtime. */ @@ -795,7 +785,7 @@ act.sa_handler = _cpl_change_width; sigemptyset(&act.sa_mask); - act.sa_flags = 0; /* Probably more appropriate flags * + act.sa_flags = 0; /* Probably more appropriate flags * * initialisation should be inserted here. */ act.sa_flags &= ~SA_SIGINFO; /* Eliminates SA_SIGINFO from any setting * @@ -832,7 +822,8 @@ * nothing is done, and no error is set. */ -void cpl_msg_stop(void) +void +cpl_msg_stop(void) { if (msg_init == 0) return; @@ -903,31 +894,28 @@ * be called in threads. */ -cpl_error_code cpl_msg_set_log_level(cpl_msg_severity verbosity) +cpl_error_code +cpl_msg_set_log_level(cpl_msg_severity verbosity) { - _cpl_msg_init(cpl_func); if (logfile) { - /* * If a log file was already open, nothing is done, but a status * is returned. */ return cpl_error_set_(CPL_ERROR_FILE_ALREADY_OPEN); - } if (verbosity != CPL_MSG_OFF) { - char timeLabel[TIME_ISO8601_LENGTH]; if ((logfile = fopen(logfile_name, "w")) == NULL) return cpl_error_set_message_(CPL_ERROR_FILE_NOT_CREATED, "%s", logfile_name); - (void)setvbuf(logfile, (char *) NULL, _IOLBF, 0); + (void)setvbuf(logfile, (char *)NULL, _IOLBF, 0); log_min_level = verbosity; @@ -942,12 +930,21 @@ fprintf(logfile, "Program name : %s\n", domain); fprintf(logfile, "Severity level : "); - switch(verbosity) { - case CPL_MSG_DEBUG : fprintf(logfile, DEBUG_STRING); break; - case CPL_MSG_INFO : fprintf(logfile, INFO_STRING); break; - case CPL_MSG_WARNING : fprintf(logfile, WARNING_STRING); break; - case CPL_MSG_ERROR : fprintf(logfile, ERROR_STRING); break; - default : break; + switch (verbosity) { + case CPL_MSG_DEBUG: + fprintf(logfile, DEBUG_STRING); + break; + case CPL_MSG_INFO: + fprintf(logfile, INFO_STRING); + break; + case CPL_MSG_WARNING: + fprintf(logfile, WARNING_STRING); + break; + case CPL_MSG_ERROR: + fprintf(logfile, ERROR_STRING); + break; + default: + break; } fprintf(logfile, "\n\n"); @@ -972,21 +969,18 @@ * at the end of the program. */ -cpl_error_code cpl_msg_stop_log(void) +cpl_error_code +cpl_msg_stop_log(void) { - _cpl_msg_init(cpl_func); if (log_min_level != CPL_MSG_OFF) { - log_min_level = CPL_MSG_OFF; fclose(logfile); logfile = NULL; - } return CPL_ERROR_NONE; - } @@ -999,7 +993,8 @@ * The name of the log file is returned. */ -const char *cpl_msg_get_log_name(void) +const char * +cpl_msg_get_log_name(void) { _cpl_msg_init(cpl_func); @@ -1052,9 +1047,9 @@ * be called in threads. */ -cpl_error_code cpl_msg_set_log_name(const char *name) +cpl_error_code +cpl_msg_set_log_name(const char *name) { - _cpl_msg_init(cpl_func); if (name == NULL) @@ -1062,13 +1057,13 @@ if (logfile) return cpl_error_set_message_(CPL_ERROR_FILE_ALREADY_OPEN, "%s: %p", - name, (const void*)logfile); + name, (const void *)logfile); if (strlen(name) > CPL_MAX_LOGFILE_NAME - 1) - return cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, "%s: %u + 1 > " - CPL_STRINGIFY(CPL_MAX_LOGFILE_NAME) " = " - CPL_XSTRINGIFY(CPL_MAX_LOGFILE_NAME), - name, (unsigned)strlen(name)); + return cpl_error_set_message_( + CPL_ERROR_ILLEGAL_INPUT, + "%s: %u + 1 > " CPL_STRINGIFY(CPL_MAX_LOGFILE_NAME) " = " CPL_XSTRINGIFY(CPL_MAX_LOGFILE_NAME), + name, (unsigned)strlen(name)); strcpy(logfile_name, name); @@ -1092,13 +1087,12 @@ * This function is not supposed to be called in threads. */ -void cpl_msg_set_level(cpl_msg_severity verbosity) +void +cpl_msg_set_level(cpl_msg_severity verbosity) { - _cpl_msg_init(cpl_func); term_min_level = verbosity; - } @@ -1122,12 +1116,13 @@ */ /*----------------------------------------------------------------------------*/ -void cpl_msg_set_level_from_env(void) +void +cpl_msg_set_level_from_env(void) { + const char *level = getenv("CPL_MSG_LEVEL"); - const char * level = getenv("CPL_MSG_LEVEL"); - - if (level == NULL) return; + if (level == NULL) + return; if (!strcmp(level, "debug")) cpl_msg_set_level(CPL_MSG_DEBUG); @@ -1152,7 +1147,8 @@ * Get current verbosity level set for the output to the log file. */ -cpl_msg_severity cpl_msg_get_log_level(void) +cpl_msg_severity +cpl_msg_get_log_level(void) { _cpl_msg_init(cpl_func); @@ -1169,7 +1165,8 @@ * Get current verbosity level set for the output to terminal. */ -cpl_msg_severity cpl_msg_get_level(void) +cpl_msg_severity +cpl_msg_get_level(void) { _cpl_msg_init(cpl_func); @@ -1194,7 +1191,8 @@ * be called in threads. */ -void cpl_msg_set_time_on(void) +void +cpl_msg_set_time_on(void) { _cpl_msg_init(cpl_func); @@ -1218,7 +1216,8 @@ * be called in threads. */ -void cpl_msg_set_time_off(void) +void +cpl_msg_set_time_off(void) { _cpl_msg_init(cpl_func); @@ -1242,7 +1241,8 @@ * be called in threads. */ -void cpl_msg_set_threadid_on(void) +void +cpl_msg_set_threadid_on(void) { _cpl_msg_init(cpl_func); @@ -1266,7 +1266,8 @@ * be called in threads. */ -void cpl_msg_set_threadid_off(void) +void +cpl_msg_set_threadid_off(void) { _cpl_msg_init(cpl_func); @@ -1294,7 +1295,8 @@ * be called in threads. */ -void cpl_msg_set_domain_on(void) +void +cpl_msg_set_domain_on(void) { _cpl_msg_init(cpl_func); @@ -1316,7 +1318,8 @@ * be called in threads. */ -void cpl_msg_set_domain_off(void) +void +cpl_msg_set_domain_off(void) { _cpl_msg_init(cpl_func); @@ -1343,7 +1346,8 @@ * be called in threads. */ -void cpl_msg_set_component_on(void) +void +cpl_msg_set_component_on(void) { _cpl_msg_init(cpl_func); @@ -1367,7 +1371,8 @@ * be called in threads. */ -void cpl_msg_set_component_off(void) +void +cpl_msg_set_component_off(void) { _cpl_msg_init(cpl_func); @@ -1400,7 +1405,8 @@ * be called in threads. */ -void cpl_msg_set_domain(const char *name) +void +cpl_msg_set_domain(const char *name) { _cpl_msg_init(cpl_func); @@ -1409,7 +1415,7 @@ if (strlen(name) >= CPL_MAX_DOMAIN_NAME) { strncpy(domain, name, CPL_MAX_DOMAIN_NAME); - domain[CPL_MAX_DOMAIN_NAME-1] = '\0'; + domain[CPL_MAX_DOMAIN_NAME - 1] = '\0'; } else { strcpy(domain, name); @@ -1427,7 +1433,8 @@ * allocated buffer containing the "domain" string. */ -const char *cpl_msg_get_domain(void) +const char * +cpl_msg_get_domain(void) { _cpl_msg_init(cpl_func); @@ -1453,7 +1460,8 @@ * never broken in log files. */ -void cpl_msg_set_width(int width) +void +cpl_msg_set_width(int width) { _cpl_msg_init(cpl_func); @@ -1486,7 +1494,8 @@ * be called in threads. */ -void cpl_msg_set_indentation(int step) +void +cpl_msg_set_indentation(int step) { _cpl_msg_init(cpl_func); @@ -1512,7 +1521,8 @@ * level to zero. */ -void cpl_msg_indent(int level) +void +cpl_msg_indent(int level) { _cpl_msg_init(cpl_func); @@ -1533,7 +1543,8 @@ * level by 1. See function @c cpl_msg_indent(). */ -void cpl_msg_indent_more(void) +void +cpl_msg_indent_more(void) { _cpl_msg_init(cpl_func); @@ -1551,7 +1562,8 @@ * by 1. If the indentation level is already 0, it is not decreased. */ -void cpl_msg_indent_less(void) +void +cpl_msg_indent_less(void) { _cpl_msg_init(cpl_func); @@ -1581,17 +1593,18 @@ * pointer, the message "" would be printed. */ -void cpl_msg_error(const char *component, const char *format, ...) +void +cpl_msg_error(const char *component, const char *format, ...) { - const char *c = component != NULL ? component : default_component; _cpl_msg_init(cpl_func); if (format == NULL) { cpl_msg_error(c, default_format); - } else { - va_list al; + } + else { + va_list al; va_start(al, format); cpl_msg_out(CPL_MSG_ERROR, c, 0, format, al); va_end(al); @@ -1612,7 +1625,8 @@ * See the description of the function @c cpl_msg_error(). */ -void cpl_msg_warning(const char *component, const char *format, ...) +void +cpl_msg_warning(const char *component, const char *format, ...) { const char *c = component != NULL ? component : default_component; @@ -1620,8 +1634,9 @@ if (format == NULL) { cpl_msg_warning(c, default_format); - } else { - va_list al; + } + else { + va_list al; va_start(al, format); cpl_msg_out(CPL_MSG_WARNING, c, 0, format, al); va_end(al); @@ -1642,7 +1657,8 @@ * See the description of the function @c cpl_msg_error(). */ -void cpl_msg_info(const char *component, const char *format, ...) +void +cpl_msg_info(const char *component, const char *format, ...) { const char *c = component != NULL ? component : default_component; @@ -1650,8 +1666,9 @@ if (format == NULL) { cpl_msg_info(c, default_format); - } else { - va_list al; + } + else { + va_list al; va_start(al, format); cpl_msg_out(CPL_MSG_INFO, c, 0, format, al); va_end(al); @@ -1692,7 +1709,8 @@ * (contrary to what @c cpl_msg_info() does). */ -void cpl_msg_info_overwritable(const char *component, const char *format, ...) +void +cpl_msg_info_overwritable(const char *component, const char *format, ...) { const char *c = component != NULL ? component : default_component; @@ -1702,8 +1720,9 @@ if (format == NULL) { cpl_msg_info(c, default_format); - } else { - va_list al; + } + else { + va_list al; va_start(al, format); cpl_msg_out(CPL_MSG_INFO, c, 1, format, al); va_end(al); @@ -1724,7 +1743,8 @@ * See the description of the function @c cpl_msg_error(). */ -void cpl_msg_debug(const char *component, const char *format, ...) +void +cpl_msg_debug(const char *component, const char *format, ...) { const char *c = component != NULL ? component : default_component; @@ -1732,8 +1752,9 @@ if (format == NULL) { cpl_msg_debug(c, default_format); - } else { - va_list al; + } + else { + va_list al; va_start(al, format); cpl_msg_out(CPL_MSG_DEBUG, c, 0, format, al); va_end(al); @@ -1757,18 +1778,21 @@ * */ -void cpl_msg_progress(const char *component, int i, int iter, - const char *format, ...) +void +cpl_msg_progress(const char *component, + int i, + int iter, + const char *format, + ...) { - const char *c = component != NULL ? component : default_component; - const double tquiet = 10.0; /* Accept silence for this many seconds */ - static double tstart = 0.0; /* Initialize to avoid false warnings */ - static double tend = 0.0; /* Initialize to avoid false warnings */ + const double tquiet = 10.0; /* Accept silence for this many seconds */ + static double tstart = 0.0; /* Initialize to avoid false warnings */ + static double tend = 0.0; /* Initialize to avoid false warnings */ double tspent; - static int iprev = 0; /* Used to detect some illegal calls */ - static int nprev = 0; /* Used to detect some illegal calls */ + static int iprev = 0; /* Used to detect some illegal calls */ + static int nprev = 0; /* Used to detect some illegal calls */ static int didmsg = 0; int percent; @@ -1776,13 +1800,15 @@ _cpl_msg_init(cpl_func); - if (format == NULL) format = default_format; + if (format == NULL) + format = default_format; if (i >= iter || i < 0 || iter < 1) return; if (i == 0) { - if (iter == 1) return; /* A meaningful message is not possible */ + if (iter == 1) + return; /* A meaningful message is not possible */ /* Reset check variables */ nprev = iter; iprev = 0; @@ -1795,11 +1821,13 @@ } /* More input errors: i must increase during loop */ - if (i <= iprev) return; /* cpl_ensure() ? */ + if (i <= iprev) + return; /* cpl_ensure() ? */ iprev = i; /* More input errors: iter may not change during loop */ - if (iter != nprev) return; /* cpl_ensure() ? */ + if (iter != nprev) + return; /* cpl_ensure() ? */ /* Compute the time spent in the loop so far */ tspent = cpl_test_get_cputime() - tstart; @@ -1807,13 +1835,16 @@ /* This fraction (rounded down) of iterations has been completed */ percent = (i * 100) / iter; - if (i == iter-1 && didmsg) - cpl_msg_debug(c, "Loop time prediction offset (%d%% done) [s]: " - "%.2g", percent, tend - tspent); + if (i == iter - 1 && didmsg) + cpl_msg_debug(c, + "Loop time prediction offset (%d%% done) [s]: " + "%.2g", + percent, tend - tspent); /* Return if the time spent is within the allowed time of silence + the predicted time if any */ - if (tspent < tquiet + tend) return; + if (tspent < tquiet + tend) + return; /* A prediction has not (yet) been made, or the prediction was too optismistic. @@ -1822,19 +1853,19 @@ so far required per iteration is unchanged for the remaining iteration(s). */ - tend = tspent * (iter - i) / (double) i; + tend = tspent * (iter - i) / (double)i; /* Update the starting point for the prediction */ tstart += tspent; - if (tend >= 0.5) { /* Do not predict less than 1 second */ + if (tend >= 0.5) { /* Do not predict less than 1 second */ const int itend = 0.5 + tend; /* Roundoff to integer */ /* %% is expanded twice */ - char * extformat = cpl_sprintf("%s. %d%%%% done, about %d seconds left", - format, percent, itend); - va_list al; + char *extformat = cpl_sprintf("%s. %d%%%% done, about %d seconds left", + format, percent, itend); + va_list al; va_start(al, format); cpl_msg_out(CPL_MSG_INFO, c, 0, extformat, al); @@ -1843,7 +1874,6 @@ cpl_free(extformat); } - } /**@}*/ diff -Nru cpl-7.1.4+ds/cplcore/cpl_msg.h cpl-7.2.2+ds/cplcore/cpl_msg.h --- cpl-7.1.4+ds/cplcore/cpl_msg.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_msg.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -45,20 +45,21 @@ */ #ifndef CPL_MAX_MSG_LENGTH -#define CPL_MAX_MSG_LENGTH 1024 +#define CPL_MAX_MSG_LENGTH 1024 #endif #ifndef CPL_MAX_FUNCTION_NAME -#define CPL_MAX_FUNCTION_NAME 50 +#define CPL_MAX_FUNCTION_NAME 50 #endif #ifndef CPL_MAX_DOMAIN_NAME -#define CPL_MAX_DOMAIN_NAME 40 +#define CPL_MAX_DOMAIN_NAME 40 #endif #ifndef CPL_MAX_LOGFILE_NAME -#define CPL_MAX_LOGFILE_NAME 72 +#define CPL_MAX_LOGFILE_NAME 72 #endif -enum _cpl_msg_severity_ { - CPL_MSG_DEBUG = 0, +enum _cpl_msg_severity_ +{ + CPL_MSG_DEBUG = 0, CPL_MSG_INFO, CPL_MSG_WARNING, CPL_MSG_ERROR, @@ -97,14 +98,15 @@ void cpl_msg_indent_less(void); void cpl_msg_indent(int); -void cpl_msg_error(const char *, const char *, ...) CPL_ATTR_PRINTF(2,3); -void cpl_msg_warning(const char *, const char *, ...) CPL_ATTR_PRINTF(2,3); -void cpl_msg_info(const char *, const char *, ...) CPL_ATTR_PRINTF(2,3); -void cpl_msg_debug(const char *, const char *, ...) CPL_ATTR_PRINTF(2,3); -void cpl_msg_info_overwritable(const char *, - const char *, ...) CPL_ATTR_PRINTF(2,3); -void cpl_msg_progress(const char *, int, int, const char *, - ...) CPL_ATTR_DEPRECATED CPL_ATTR_PRINTF(4,5); +void cpl_msg_error(const char *, const char *, ...) CPL_ATTR_PRINTF(2, 3); +void cpl_msg_warning(const char *, const char *, ...) CPL_ATTR_PRINTF(2, 3); +void cpl_msg_info(const char *, const char *, ...) CPL_ATTR_PRINTF(2, 3); +void cpl_msg_debug(const char *, const char *, ...) CPL_ATTR_PRINTF(2, 3); +void cpl_msg_info_overwritable(const char *, const char *, ...) + CPL_ATTR_PRINTF(2, 3); +void +cpl_msg_progress(const char *, int, int, const char *, ...) CPL_ATTR_DEPRECATED + CPL_ATTR_PRINTF(4, 5); CPL_END_DECLS diff -Nru cpl-7.1.4+ds/cplcore/cpl_plot.c cpl-7.2.2+ds/cplcore/cpl_plot.c --- cpl-7.1.4+ds/cplcore/cpl_plot.c 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_plot.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -90,13 +90,14 @@ typedef struct _cpl_plot_ cpl_plot; -struct _cpl_plot_ { +struct _cpl_plot_ +{ /* File with data to be sent to plotting command's stdin */ - FILE * data; + FILE *data; /* Name of command capable of reading the plot on stdin */ - const char * exe; + const char *exe; /* Name of temporary file for storing the plot commands */ - const char * tmp; + const char *tmp; }; /*----------------------------------------------------------------------------- @@ -105,11 +106,11 @@ static cpl_error_code cpl_mplot_puts(cpl_plot *, const char *); static cpl_error_code cpl_mplot_write(cpl_plot *, const char *, size_t); -static cpl_plot * cpl_mplot_open(const char *); -static cpl_plot * cpl_image_open(const char *); +static cpl_plot *cpl_mplot_open(const char *); +static cpl_plot *cpl_image_open(const char *); static cpl_error_code cpl_mplot_close(cpl_plot *, const char *); -static const char * cpl_mplot_plotter(void); -static const char * cpl_mplot_imager(void); +static const char *cpl_mplot_plotter(void); +static const char *cpl_mplot_imager(void); /*----------------------------------------------------------------------------- Functions code @@ -134,31 +135,35 @@ run-time system. */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_plot_vector(const char * pre, - const char * options, - const char * post, - const cpl_vector * vector) +cpl_error_code +cpl_plot_vector(const char *pre, + const char *options, + const char *post, + const cpl_vector *vector) { - const double * pvec = cpl_vector_get_data_const(vector); - const cpl_size n = cpl_vector_get_size(vector); + const double *pvec = cpl_vector_get_data_const(vector); + const cpl_size n = cpl_vector_get_size(vector); cpl_error_code error = CPL_ERROR_NONE; - cpl_size i; - cpl_plot * plot; + cpl_size i; + cpl_plot *plot; - if (n <= 0) return cpl_error_set_where_(); + if (n <= 0) + return cpl_error_set_where_(); plot = cpl_mplot_open(pre); - if (plot == NULL) return cpl_error_set_where_(); + if (plot == NULL) + return cpl_error_set_where_(); error |= cpl_mplot_puts(plot, "plot '-' "); if (options != NULL) { error |= cpl_mplot_puts(plot, options); - } else { - char * myoptions = cpl_sprintf("t '%" CPL_SIZE_FORMAT"-vector (%p)", n, - (const void*)vector); + } + else { + char *myoptions = cpl_sprintf("t '%" CPL_SIZE_FORMAT "-vector (%p)", n, + (const void *)vector); assert(myoptions != NULL); error |= cpl_mplot_puts(plot, myoptions); cpl_free(myoptions); @@ -167,11 +172,12 @@ error |= cpl_mplot_puts(plot, ";\n"); for (i = 0; i < n; i++) { - char * snumber = cpl_sprintf("%g\n", pvec[i]); + char *snumber = cpl_sprintf("%g\n", pvec[i]); error |= cpl_mplot_puts(plot, snumber); cpl_free(snumber); - if (error) break; + if (error) + break; } error |= cpl_mplot_puts(plot, "e\n"); @@ -201,32 +207,36 @@ run-time system. */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_plot_bivector(const char * pre, - const char * options, - const char * post, - const cpl_bivector * bivector) +cpl_error_code +cpl_plot_bivector(const char *pre, + const char *options, + const char *post, + const cpl_bivector *bivector) { - const cpl_size n = cpl_bivector_get_size(bivector); - const double * pvecx = cpl_bivector_get_x_data_const(bivector); - const double * pvecy = cpl_bivector_get_y_data_const(bivector); - cpl_error_code error = CPL_ERROR_NONE; - cpl_plot * plot; - cpl_size i; + const cpl_size n = cpl_bivector_get_size(bivector); + const double *pvecx = cpl_bivector_get_x_data_const(bivector); + const double *pvecy = cpl_bivector_get_y_data_const(bivector); + cpl_error_code error = CPL_ERROR_NONE; + cpl_plot *plot; + cpl_size i; - if (n <= 0) return cpl_error_set_where_(); + if (n <= 0) + return cpl_error_set_where_(); plot = cpl_mplot_open(pre); - if (plot == NULL) return cpl_error_set_where_(); + if (plot == NULL) + return cpl_error_set_where_(); error |= cpl_mplot_puts(plot, "plot '-' "); if (options != NULL) { error |= cpl_mplot_puts(plot, options); - } else { - char * myoptions = cpl_sprintf("t '%" CPL_SIZE_FORMAT "-bivector (%p)", - n, (const void*)bivector); + } + else { + char *myoptions = cpl_sprintf("t '%" CPL_SIZE_FORMAT "-bivector (%p)", + n, (const void *)bivector); assert(myoptions != NULL); error |= cpl_mplot_puts(plot, myoptions); cpl_free(myoptions); @@ -235,11 +245,12 @@ error |= cpl_mplot_puts(plot, ";\n"); for (i = 0; i < n; i++) { - char * snumber = cpl_sprintf("%g %g\n", pvecx[i], pvecy[i]); + char *snumber = cpl_sprintf("%g %g\n", pvecx[i], pvecy[i]); error |= cpl_mplot_puts(plot, snumber); cpl_free(snumber); - if (error) break; + if (error) + break; } error |= cpl_mplot_puts(plot, "e\n"); @@ -274,96 +285,107 @@ run-time system. */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_plot_vectors(const char * pre, - const char * options, - const char * post, - const cpl_vector ** vectors, - cpl_size nvec) +cpl_error_code +cpl_plot_vectors(const char *pre, + const char *options, + const char *post, + const cpl_vector **vectors, + cpl_size nvec) { cpl_errorstate prestate = cpl_errorstate_get(); - const double * pvecx; - const double * pvecy; - cpl_size vec_size = 0; /* Avoid uninit warning */ - char ** names; - char * sval; - FILE * tmpfd; - cpl_plot * plot; - cpl_size i, j; - + const double *pvecx; + const double *pvecy; + cpl_size vec_size = 0; /* Avoid uninit warning */ + char **names; + char *sval; + FILE *tmpfd; + cpl_plot *plot; + cpl_size i, j; + /* Check entries */ cpl_ensure_code(vectors != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(nvec>=3, CPL_ERROR_ILLEGAL_INPUT); - for (i=1; i= 3, CPL_ERROR_ILLEGAL_INPUT); + for (i = 1; i < nvec; i++) { cpl_ensure_code(vectors[i] != NULL, CPL_ERROR_NULL_INPUT); - if (i==1) vec_size = cpl_vector_get_size(vectors[i]); - else cpl_ensure_code(vec_size==cpl_vector_get_size(vectors[i]), - CPL_ERROR_ILLEGAL_INPUT); + if (i == 1) + vec_size = cpl_vector_get_size(vectors[i]); + else + cpl_ensure_code(vec_size == cpl_vector_get_size(vectors[i]), + CPL_ERROR_ILLEGAL_INPUT); } if (vectors[0] != NULL) { - cpl_ensure_code(vec_size==cpl_vector_get_size(vectors[0]), - CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(vec_size == cpl_vector_get_size(vectors[0]), + CPL_ERROR_ILLEGAL_INPUT); } /* Get the X axis if passed */ pvecx = vectors[0] ? cpl_vector_get_data_const(vectors[0]) : NULL; - + /* Hold the files names */ - names = cpl_malloc((size_t)(nvec-1)*sizeof(char*)); - for (i=1; i= 1, CPL_ERROR_DATA_NOT_FOUND); - for (i=0; i= 1, CPL_ERROR_DATA_NOT_FOUND); + for (i = 0; i < nbvec; i++) { cpl_ensure_code(bivectors[i] != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code( options[i] != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(options[i] != NULL, CPL_ERROR_NULL_INPUT); } /* Hold the files names */ - names = cpl_malloc((size_t)nbvec * sizeof(char*)); - for (i=0; iexe != NULL); if (strstr(plot->exe, "gnuplot")) { - error |= cpl_mplot_puts(plot, "splot '-' matrix "); if (myoptions == NULL || strlen(myoptions) < 1) { - myoptions = cpl_sprintf("t '%s';", dvi_options); - assert( myoptions != NULL); + assert(myoptions != NULL); } error |= cpl_mplot_puts(plot, myoptions); error |= cpl_mplot_puts(plot, ";\n"); for (j = 0; j < ny; j++) { for (i = 0; i < nx; i++) { - char * snumber = cpl_sprintf("%d ", pmask[i + j * nx]); + char *snumber = cpl_sprintf("%d ", pmask[i + j * nx]); error |= cpl_mplot_puts(plot, snumber); cpl_free(snumber); - if (error) break; + if (error) + break; } error |= cpl_mplot_puts(plot, "\n"); - if (error) break; + if (error) + break; } error |= cpl_mplot_puts(plot, "e\n"); - - } else { + } + else { const size_t bsize = (size_t)(ny * nx); /* Octets in raster */ - unsigned char * raster = (unsigned char *)cpl_malloc(bsize); + unsigned char *raster = (unsigned char *)cpl_malloc(bsize); /* Create a PGM P5 header - with a maxval of 1 */ - myoptions = cpl_sprintf("P5\n%" CPL_SIZE_FORMAT " %" CPL_SIZE_FORMAT - "\n", nx, ny); + myoptions = + cpl_sprintf("P5\n%" CPL_SIZE_FORMAT " %" CPL_SIZE_FORMAT "\n", nx, + ny); error |= cpl_mplot_puts(plot, myoptions); cpl_free(myoptions); @@ -568,17 +603,21 @@ error |= cpl_mplot_puts(plot, myoptions); - for (j = 0; j < ny; j++) for (i = 0; i < nx; i++) - raster[i + (ny-j-1) * nx] = (unsigned char) pmask[i + j * nx]; + for (j = 0; j < ny; j++) + for (i = 0; i < nx; i++) + raster[i + (ny - j - 1) * nx] = + (unsigned char)pmask[i + j * nx]; - error |= cpl_mplot_write(plot, (const void *) raster, bsize); + error |= cpl_mplot_write(plot, (const void *)raster, bsize); cpl_free(raster); } - if (dvi_options != options) cpl_free(dvi_options); - if (myoptions != options) cpl_free(myoptions); + if (dvi_options != options) + cpl_free(dvi_options); + if (myoptions != options) + cpl_free(myoptions); error |= cpl_mplot_close(plot, post); @@ -616,44 +655,47 @@ run-time system. */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_plot_image(const char * pre, - const char * options, - const char * post, - const cpl_image * image) +cpl_error_code +cpl_plot_image(const char *pre, + const char *options, + const char *post, + const cpl_image *image) { - const cpl_size nx = cpl_image_get_size_x(image); - const cpl_size ny = cpl_image_get_size_y(image); - cpl_plot * plot; - cpl_image * temp; - const double * pimage; - unsigned char * raster = NULL; - char * dvi_options = (char *)options; - char * myoptions = (char *)options; - cpl_error_code error = CPL_ERROR_NONE; - cpl_size i, j; + const cpl_size nx = cpl_image_get_size_x(image); + const cpl_size ny = cpl_image_get_size_y(image); + cpl_plot *plot; + cpl_image *temp; + const double *pimage; + unsigned char *raster = NULL; + char *dvi_options = (char *)options; + char *myoptions = (char *)options; + cpl_error_code error = CPL_ERROR_NONE; + cpl_size i, j; - if (nx <= 0) return cpl_error_set_where_(); + if (nx <= 0) + return cpl_error_set_where_(); plot = cpl_image_open(pre); - if (plot == NULL) return cpl_error_set_where_(); + if (plot == NULL) + return cpl_error_set_where_(); if (options == NULL || strlen(options) < 1) { dvi_options = cpl_sprintf("%" CPL_SIZE_FORMAT "X%" CPL_SIZE_FORMAT - "-image-(%d) (%p)", nx, ny, - (int)cpl_image_get_type(image), - (const void*)image); - assert( dvi_options != NULL); + "-image-(%d) (%p)", + nx, ny, (int)cpl_image_get_type(image), + (const void *)image); + assert(dvi_options != NULL); } assert(plot->exe != NULL); if (strstr(plot->exe, "gnuplot")) { - if (cpl_image_get_type(image) == CPL_TYPE_DOUBLE) { temp = NULL; pimage = cpl_image_get_data_double_const(image); - } else { + } + else { temp = cpl_image_cast(image, CPL_TYPE_DOUBLE); pimage = cpl_image_get_data_double(temp); } @@ -661,37 +703,38 @@ error |= cpl_mplot_puts(plot, "splot '-' matrix "); if (myoptions == NULL || strlen(myoptions) < 1) { - - myoptions = cpl_sprintf("t '%s';", - dvi_options); - assert( myoptions != NULL); + myoptions = cpl_sprintf("t '%s';", dvi_options); + assert(myoptions != NULL); } error |= cpl_mplot_puts(plot, myoptions); error |= cpl_mplot_puts(plot, ";\n"); for (j = 0; j < ny; j++) { for (i = 0; i < nx; i++) { - char * snumber = cpl_sprintf("%g ", pimage[j*nx + i]); + char *snumber = cpl_sprintf("%g ", pimage[j * nx + i]); error |= cpl_mplot_puts(plot, snumber); cpl_free(snumber); - if (error) break; + if (error) + break; } error |= cpl_mplot_puts(plot, "\n"); - if (error) break; + if (error) + break; } error |= cpl_mplot_puts(plot, "e\n"); - - } else { + } + else { const size_t bsize = (size_t)(ny * nx); /* Octets in raster */ const double tmin = cpl_image_get_min(image); - double tmax; + double tmax; /* Convert the image to one in the range [0; 256[ */ - if (cpl_image_get_type(image) == CPL_TYPE_DOUBLE) { + if (cpl_image_get_type(image) == CPL_TYPE_DOUBLE) { temp = cpl_image_subtract_scalar_create(image, tmin); - } else { + } + else { temp = cpl_image_cast(image, CPL_TYPE_DOUBLE); error |= cpl_image_subtract_scalar(temp, tmin); } @@ -699,21 +742,23 @@ tmax = cpl_image_get_max(temp); if (tmax > 0.0) - error |= cpl_image_multiply_scalar(temp, 256.0*(1.0-DBL_EPSILON) - /tmax); + error |= + cpl_image_multiply_scalar(temp, + 256.0 * (1.0 - DBL_EPSILON) / tmax); pimage = cpl_image_get_data_double(temp); assert(pimage != NULL); /* Create a PGM P5 header - with a maxval of 255 */ - myoptions = cpl_sprintf("P5\n%" CPL_SIZE_FORMAT " %" CPL_SIZE_FORMAT - "\n", nx, ny); + myoptions = + cpl_sprintf("P5\n%" CPL_SIZE_FORMAT " %" CPL_SIZE_FORMAT "\n", nx, + ny); error |= cpl_mplot_puts(plot, myoptions); cpl_free(myoptions); - myoptions = cpl_sprintf("# True Value Range: [%g;%g]\n", - tmin, tmin+tmax); - assert( myoptions != NULL); + myoptions = + cpl_sprintf("# True Value Range: [%g;%g]\n", tmin, tmin + tmax); + assert(myoptions != NULL); error |= cpl_mplot_puts(plot, myoptions); cpl_free(myoptions); @@ -723,16 +768,19 @@ error |= cpl_mplot_puts(plot, myoptions); raster = (unsigned char *)cpl_malloc(bsize); - for (j = 0; j < ny; j++) for (i = 0; i < nx; i++) - raster[(ny-j-1)*nx + i] = (unsigned char) pimage[j*nx + i]; - - error |= cpl_mplot_write(plot, (const char *) raster, bsize); + for (j = 0; j < ny; j++) + for (i = 0; i < nx; i++) + raster[(ny - j - 1) * nx + i] = + (unsigned char)pimage[j * nx + i]; + error |= cpl_mplot_write(plot, (const char *)raster, bsize); } - if (dvi_options != options) cpl_free(dvi_options); - if (myoptions != options) cpl_free(myoptions); + if (dvi_options != options) + cpl_free(dvi_options); + if (myoptions != options) + cpl_free(myoptions); cpl_free(raster); cpl_image_delete(temp); @@ -768,13 +816,14 @@ run-time system. */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_plot_image_row(const char * pre, - const char * options, - const char * post, - const cpl_image * image, - cpl_size firstrow, - cpl_size lastrow, - cpl_size rowstep) +cpl_error_code +cpl_plot_image_row(const char *pre, + const char *options, + const char *post, + const cpl_image *image, + cpl_size firstrow, + cpl_size lastrow, + cpl_size rowstep) { cpl_errorstate prestate = cpl_errorstate_get(); cpl_size nx, ny; @@ -784,73 +833,86 @@ nx = cpl_image_get_size_x(image); ny = cpl_image_get_size_y(image); - cpl_ensure_code( nx > 0, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code( ny > 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(nx > 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(ny > 0, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code( rowstep > 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(rowstep > 0, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code( firstrow > 0, CPL_ERROR_ACCESS_OUT_OF_RANGE); - cpl_ensure_code( firstrow <= lastrow, CPL_ERROR_ACCESS_OUT_OF_RANGE); - cpl_ensure_code( lastrow <= ny, CPL_ERROR_ACCESS_OUT_OF_RANGE); - - do { + cpl_ensure_code(firstrow > 0, CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_ensure_code(firstrow <= lastrow, CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_ensure_code(lastrow <= ny, CPL_ERROR_ACCESS_OUT_OF_RANGE); - const double * pimage; - cpl_image * temp = NULL; - char * myoptions = NULL; + do { + const double *pimage; + cpl_image *temp = NULL; + char *myoptions = NULL; cpl_size i, j; - cpl_plot * plot = cpl_mplot_open(pre); + cpl_plot *plot = cpl_mplot_open(pre); do { - if (plot == NULL) break; + if (plot == NULL) + break; - if (cpl_mplot_puts(plot, "plot")) break; - for (j = firstrow-1; j < lastrow; j += rowstep) { - const char * useoptions = options; - if (j > firstrow-1 && cpl_mplot_puts(plot, ",")) break; - if (cpl_mplot_puts(plot, " '-' ")) break; + if (cpl_mplot_puts(plot, "plot")) + break; + for (j = firstrow - 1; j < lastrow; j += rowstep) { + const char *useoptions = options; + if (j > firstrow - 1 && cpl_mplot_puts(plot, ",")) + break; + if (cpl_mplot_puts(plot, " '-' ")) + break; if (useoptions == NULL || strlen(useoptions) < 1) { - cpl_free(myoptions); - myoptions = (j == firstrow-1) - ? cpl_sprintf("t 'Row %" CPL_SIZE_FORMAT " %" - CPL_SIZE_FORMAT "X%" CPL_SIZE_FORMAT - "-image-(%d) (%p)'", j, nx, ny, - (int)cpl_image_get_type(image), - (const void*)image) - : cpl_sprintf("t 'Row %" CPL_SIZE_FORMAT - " of the same image'", j); + myoptions = + (j == firstrow - 1) + ? cpl_sprintf("t 'Row %" CPL_SIZE_FORMAT + " %" CPL_SIZE_FORMAT + "X%" CPL_SIZE_FORMAT + "-image-(%d) (%p)'", + j, nx, ny, + (int)cpl_image_get_type(image), + (const void *)image) + : cpl_sprintf("t 'Row %" CPL_SIZE_FORMAT + " of the same image'", + j); - assert( myoptions != NULL); - useoptions = myoptions; + assert(myoptions != NULL); + useoptions = myoptions; } - if (cpl_mplot_puts(plot, useoptions)) break; + if (cpl_mplot_puts(plot, useoptions)) + break; } - if (cpl_mplot_puts(plot, ";\n ")) break; + if (cpl_mplot_puts(plot, ";\n ")) + break; if (cpl_image_get_type(image) == CPL_TYPE_DOUBLE) { pimage = cpl_image_get_data_double_const(image); - } else { + } + else { temp = cpl_image_cast(image, CPL_TYPE_DOUBLE); pimage = cpl_image_get_data_double_const(temp); } assert(pimage != NULL); - for (j = firstrow-1; j < lastrow; j += rowstep) { + for (j = firstrow - 1; j < lastrow; j += rowstep) { for (i = 0; i < nx; i++) { - char * snumber = cpl_sprintf("%g\n", pimage[j * nx + i]); + char *snumber = cpl_sprintf("%g\n", pimage[j * nx + i]); const int nstat = cpl_mplot_puts(plot, snumber); cpl_free(snumber); - if (nstat) break; + if (nstat) + break; } - if (i != nx) break; - if (cpl_mplot_puts(plot, "e\n")) break; + if (i != nx) + break; + if (cpl_mplot_puts(plot, "e\n")) + break; } - if (j != lastrow) break; + if (j != lastrow) + break; } while (0); @@ -862,7 +924,7 @@ } while (0); return cpl_errorstate_is_equal(prestate) ? CPL_ERROR_NONE - : cpl_error_set_where_(); + : cpl_error_set_where_(); } /*----------------------------------------------------------------------------*/ @@ -892,13 +954,14 @@ run-time system. */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_plot_image_col(const char * pre, - const char * options, - const char * post, - const cpl_image * image, - cpl_size firstcol, - cpl_size lastcol, - cpl_size colstep) +cpl_error_code +cpl_plot_image_col(const char *pre, + const char *options, + const char *post, + const cpl_image *image, + cpl_size firstcol, + cpl_size lastcol, + cpl_size colstep) { cpl_errorstate prestate = cpl_errorstate_get(); cpl_size nx, ny; @@ -908,70 +971,83 @@ nx = cpl_image_get_size_x(image); ny = cpl_image_get_size_y(image); - cpl_ensure_code( nx > 0, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code( ny > 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(nx > 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(ny > 0, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code( colstep > 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(colstep > 0, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code( firstcol > 0, CPL_ERROR_ACCESS_OUT_OF_RANGE); - cpl_ensure_code( firstcol <= lastcol, CPL_ERROR_ACCESS_OUT_OF_RANGE); - cpl_ensure_code( lastcol <= nx, CPL_ERROR_ACCESS_OUT_OF_RANGE); - - do { + cpl_ensure_code(firstcol > 0, CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_ensure_code(firstcol <= lastcol, CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_ensure_code(lastcol <= nx, CPL_ERROR_ACCESS_OUT_OF_RANGE); - const double * pimage; - cpl_image * temp = NULL; - char * myoptions = NULL; + do { + const double *pimage; + cpl_image *temp = NULL; + char *myoptions = NULL; cpl_size i, j; - cpl_plot * plot = cpl_mplot_open(pre); + cpl_plot *plot = cpl_mplot_open(pre); do { - if (cpl_error_get_code()) break; + if (cpl_error_get_code()) + break; - if (cpl_mplot_puts(plot, "plot")) break; - for (i = firstcol-1; i < lastcol; i += colstep) { - const char * useoptions = options; - if (i > firstcol-1 && cpl_mplot_puts(plot, ",")) break; - if (cpl_mplot_puts(plot, " '-' ")) break; + if (cpl_mplot_puts(plot, "plot")) + break; + for (i = firstcol - 1; i < lastcol; i += colstep) { + const char *useoptions = options; + if (i > firstcol - 1 && cpl_mplot_puts(plot, ",")) + break; + if (cpl_mplot_puts(plot, " '-' ")) + break; if (useoptions == NULL || strlen(useoptions) < 1) { - cpl_free(myoptions); - myoptions = (i == firstcol-1) - ? cpl_sprintf("t 'Column %" CPL_SIZE_FORMAT " of a " - "%" CPL_SIZE_FORMAT "X%" CPL_SIZE_FORMAT - "-image-(%d) (%p) ", i, nx, ny, - (int)cpl_image_get_type(image), - (const void*)image) - : cpl_sprintf("t 'Column %" CPL_SIZE_FORMAT " of the " - "same image'", i); - assert( myoptions != NULL); + myoptions = + (i == firstcol - 1) + ? cpl_sprintf("t 'Column %" CPL_SIZE_FORMAT " of a " + "%" CPL_SIZE_FORMAT + "X%" CPL_SIZE_FORMAT + "-image-(%d) (%p) ", + i, nx, ny, + (int)cpl_image_get_type(image), + (const void *)image) + : cpl_sprintf("t 'Column %" CPL_SIZE_FORMAT + " of the " + "same image'", + i); + assert(myoptions != NULL); useoptions = myoptions; - } - if (cpl_mplot_puts(plot, useoptions )) break; + if (cpl_mplot_puts(plot, useoptions)) + break; } - if (cpl_mplot_puts(plot, ";\n ")) break; + if (cpl_mplot_puts(plot, ";\n ")) + break; if (cpl_image_get_type(image) == CPL_TYPE_DOUBLE) { pimage = cpl_image_get_data_double_const(image); - } else { + } + else { temp = cpl_image_cast(image, CPL_TYPE_DOUBLE); pimage = cpl_image_get_data_double_const(temp); } - for (i = firstcol-1; i < lastcol; i += colstep) { + for (i = firstcol - 1; i < lastcol; i += colstep) { for (j = 0; j < ny; j++) { - char * snumber = cpl_sprintf("%g\n", pimage[j * nx + i]); + char *snumber = cpl_sprintf("%g\n", pimage[j * nx + i]); const int nstat = cpl_mplot_puts(plot, snumber); cpl_free(snumber); - if (nstat) break; + if (nstat) + break; } - if (j != ny) break; - if (cpl_mplot_puts(plot, "e\n")) break; + if (j != ny) + break; + if (cpl_mplot_puts(plot, "e\n")) + break; } - if (i != lastcol) break; + if (i != lastcol) + break; } while (0); @@ -984,7 +1060,7 @@ } while (0); return cpl_errorstate_is_equal(prestate) ? CPL_ERROR_NONE - : cpl_error_set_where_(); + : cpl_error_set_where_(); } /*----------------------------------------------------------------------------*/ @@ -1012,127 +1088,130 @@ run-time system. */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_plot_column( - const char * pre, - const char * options, - const char * post, - const cpl_table * tab, - const char * xlab, - const char * ylab) +cpl_error_code +cpl_plot_column(const char *pre, + const char *options, + const char *post, + const cpl_table *tab, + const char *xlab, + const char *ylab) { cpl_errorstate prestate = cpl_errorstate_get(); - cpl_size n; - cpl_table * tempx; - cpl_table * tempy; - cpl_bivector * bivect; - cpl_vector * xvec; - cpl_vector * yvec; - cpl_type type_x; - cpl_type type_y; - cpl_size invalid_x; - cpl_size invalid_y; + cpl_size n; + cpl_table *tempx; + cpl_table *tempy; + cpl_bivector *bivect; + cpl_vector *xvec; + cpl_vector *yvec; + cpl_type type_x; + cpl_type type_y; + cpl_size invalid_x; + cpl_size invalid_y; /* Check input */ cpl_ensure_code(tab, CPL_ERROR_NULL_INPUT); cpl_ensure_code(ylab, CPL_ERROR_NULL_INPUT); n = cpl_table_get_nrow(tab); - cpl_ensure_code(n>0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(n > 0, CPL_ERROR_ILLEGAL_INPUT); if (xlab) - cpl_ensure_code(cpl_table_has_column(tab, xlab), - CPL_ERROR_DATA_NOT_FOUND); + cpl_ensure_code(cpl_table_has_column(tab, xlab), + CPL_ERROR_DATA_NOT_FOUND); cpl_ensure_code(cpl_table_has_column(tab, ylab), CPL_ERROR_DATA_NOT_FOUND); if (xlab != NULL) { invalid_x = cpl_table_count_invalid(tab, xlab); type_x = cpl_table_get_column_type(tab, xlab); - } else { + } + else { invalid_x = 0; type_x = CPL_TYPE_DOUBLE; } invalid_y = cpl_table_count_invalid(tab, ylab); type_y = cpl_table_get_column_type(tab, ylab); - cpl_ensure_code(type_x == CPL_TYPE_INT || - type_x == CPL_TYPE_FLOAT || - type_x == CPL_TYPE_DOUBLE, CPL_ERROR_INVALID_TYPE); - cpl_ensure_code(type_y == CPL_TYPE_INT || - type_y == CPL_TYPE_FLOAT || - type_y == CPL_TYPE_DOUBLE, CPL_ERROR_INVALID_TYPE); + cpl_ensure_code(type_x == CPL_TYPE_INT || type_x == CPL_TYPE_FLOAT || + type_x == CPL_TYPE_DOUBLE, + CPL_ERROR_INVALID_TYPE); + cpl_ensure_code(type_y == CPL_TYPE_INT || type_y == CPL_TYPE_FLOAT || + type_y == CPL_TYPE_DOUBLE, + CPL_ERROR_INVALID_TYPE); cpl_ensure_code(invalid_x < n && invalid_y < n, CPL_ERROR_DATA_NOT_FOUND); - + /* Cast columns to CPL_TYPE_DOUBLE and remove invalid entries */ if (type_y != CPL_TYPE_DOUBLE || invalid_y > 0) { tempy = cpl_table_new(n); - + cpl_table_duplicate_column(tempy, "Y", tab, ylab); cpl_table_cast_column(tempy, "Y", "Ydouble", CPL_TYPE_DOUBLE); - + /* Remove rows with one or more invalid elements. No columns will be removed because each column contains at least one valid element. */ cpl_table_erase_invalid(tempy); - + yvec = cpl_vector_wrap(cpl_table_get_nrow(tempy), - cpl_table_get_data_double(tempy, "Ydouble")); + cpl_table_get_data_double(tempy, "Ydouble")); } - else - { + else { tempy = NULL; -CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); - yvec = cpl_vector_wrap(n, - (double*)cpl_table_get_data_double_const(tab, - ylab)); -CPL_DIAG_PRAGMA_POP; - + CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); + yvec = + cpl_vector_wrap(n, (double *)cpl_table_get_data_double_const(tab, + ylab)); + CPL_DIAG_PRAGMA_POP; } - /* Cast columns to CPL_TYPE_DOUBLE and remove invalid entries */ + /* Cast columns to CPL_TYPE_DOUBLE and remove invalid entries */ if (type_x != CPL_TYPE_DOUBLE || invalid_x > 0) { tempx = cpl_table_new(n); - + cpl_table_duplicate_column(tempx, "X", tab, xlab); cpl_table_cast_column(tempx, "X", "Xdouble", CPL_TYPE_DOUBLE); - + /* Remove rows with one or more invalid elements. No columns will be removed because each column contains at least one valid element. */ cpl_table_erase_invalid(tempx); - + xvec = cpl_vector_wrap(cpl_table_get_nrow(tempx), - cpl_table_get_data_double(tempx, "Xdouble")); + cpl_table_get_data_double(tempx, "Xdouble")); } - else - { + else { tempx = NULL; - + if (xlab == NULL) { cpl_size i; xvec = cpl_vector_duplicate(yvec); - for (i=0; i= 3, CPL_ERROR_DATA_NOT_FOUND); + cpl_ensure_code(tab != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(labels != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(nlabels >= 3, CPL_ERROR_DATA_NOT_FOUND); for (i = 1; i < nlabels; i++) { cpl_ensure_code(labels[i] != NULL, CPL_ERROR_NULL_INPUT); } @@ -1196,49 +1276,53 @@ tempy = cpl_table_new(n); /* Get the X axis if passed */ - if (labels[0] == NULL) px = NULL; + if (labels[0] == NULL) + px = NULL; else { - cpl_ensure_code(cpl_table_has_column(tab, labels[0]), - CPL_ERROR_DATA_NOT_FOUND); + cpl_ensure_code(cpl_table_has_column(tab, labels[0]), + CPL_ERROR_DATA_NOT_FOUND); type_x = cpl_table_get_column_type(tab, labels[0]); cpl_ensure_code(type_x == CPL_TYPE_INT || type_x == CPL_TYPE_FLOAT || - type_x == CPL_TYPE_DOUBLE, CPL_ERROR_INVALID_TYPE); - + type_x == CPL_TYPE_DOUBLE, + CPL_ERROR_INVALID_TYPE); + if (type_x != CPL_TYPE_DOUBLE) { cpl_table_duplicate_column(tempx, "X", tab, labels[0]); cpl_table_cast_column(tempx, "X", "Xdouble", CPL_TYPE_DOUBLE); px = cpl_table_get_data_double_const(tempx, "Xdouble"); - } else { + } + else { px = cpl_table_get_data_double_const(tab, labels[0]); } } /* Hold the files names */ - names = cpl_malloc((size_t)(nlabels-1) * sizeof(char*)); - for (i=1; i < nlabels; i++) - names[i-1] = cpl_sprintf("cpl_plot-%" CPL_SIZE_FORMAT, i); + names = cpl_malloc((size_t)(nlabels - 1) * sizeof(char *)); + for (i = 1; i < nlabels; i++) + names[i - 1] = cpl_sprintf("cpl_plot-%" CPL_SIZE_FORMAT, i); /* Open the plot */ plot = cpl_mplot_open(pre); /* Loop on the signals to plot */ - for (i=1; iexe = exe; - plot->tmp = tmp; + plot->exe = exe; + plot->tmp = tmp; plot->data = data; if (cpl_mplot_puts(plot, options)) { @@ -1437,25 +1531,25 @@ - CPL_ERROR_FILE_IO */ /*----------------------------------------------------------------------------*/ -static cpl_plot * cpl_image_open(const char * options) +static cpl_plot * +cpl_image_open(const char *options) { - cpl_plot * plot; - const char * exe = cpl_mplot_imager(); - const char * tmp = CPL_PLOT_TMPFILE; - FILE * data; + cpl_plot *plot; + const char *exe = cpl_mplot_imager(); + const char *tmp = CPL_PLOT_TMPFILE; + FILE *data; cpl_ensure(exe != NULL, CPL_ERROR_NULL_INPUT, NULL); data = fopen(tmp, "w"); - cpl_error_ensure(data != NULL, CPL_ERROR_FILE_IO, return NULL, - "%s", tmp); + cpl_error_ensure(data != NULL, CPL_ERROR_FILE_IO, return NULL, "%s", tmp); plot = cpl_malloc(sizeof(cpl_plot)); - plot->exe = exe; - plot->tmp = tmp; + plot->exe = exe; + plot->tmp = tmp; plot->data = data; if (cpl_mplot_puts(plot, options)) { @@ -1479,8 +1573,8 @@ - CPL_ERROR_FILE_IO */ /*----------------------------------------------------------------------------*/ -static cpl_error_code cpl_mplot_close(cpl_plot * plot, - const char * options) +static cpl_error_code +cpl_mplot_close(cpl_plot *plot, const char *options) { cpl_error_code error; @@ -1494,22 +1588,25 @@ assert(plot->tmp != NULL); assert(plot->exe != NULL); - if (fclose(plot->data) != 0) error = cpl_error_set_(CPL_ERROR_FILE_IO); + if (fclose(plot->data) != 0) + error = cpl_error_set_(CPL_ERROR_FILE_IO); if (!error) { /* Note: The portability of this plotting module is limited by the portability of the following command (which is likely to be valid on any kind of UNIX platform). We use 'exec' to reduce the number of child processes created. */ - char * command = cpl_sprintf("exec <%s %s", plot->tmp, plot->exe); + char *command = cpl_sprintf("exec <%s %s", plot->tmp, plot->exe); const int nstat = system(command); - if (nstat != 0) error = - cpl_error_set_message_(CPL_ERROR_FILE_IO, "system('%s') returned " - "%d", command ? command : "", nstat); + if (nstat != 0) + error = cpl_error_set_message_(CPL_ERROR_FILE_IO, + "system('%s') returned " + "%d", + command ? command : "", nstat); cpl_free(command); } - (void) remove(plot->tmp); + (void)remove(plot->tmp); cpl_free(plot); @@ -1529,10 +1626,11 @@ */ /*----------------------------------------------------------------------------*/ -static cpl_error_code cpl_mplot_puts(cpl_plot * plot, const char * cmd) +static cpl_error_code +cpl_mplot_puts(cpl_plot *plot, const char *cmd) { - - if (cmd == NULL || strlen(cmd) == 0) return CPL_ERROR_NONE; + if (cmd == NULL || strlen(cmd) == 0) + return CPL_ERROR_NONE; cpl_ensure_code(plot != NULL, CPL_ERROR_NULL_INPUT); @@ -1557,13 +1655,12 @@ - CPL_ERROR_ILLEGAL_INPUT */ /*----------------------------------------------------------------------------*/ -static cpl_error_code cpl_mplot_write(cpl_plot * plot, - const char * buffer, - size_t length) +static cpl_error_code +cpl_mplot_write(cpl_plot *plot, const char *buffer, size_t length) { - cpl_ensure_code(plot != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(plot != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(buffer != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(length > 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(length > 0, CPL_ERROR_ILLEGAL_INPUT); assert(plot->data != NULL); diff -Nru cpl-7.1.4+ds/cplcore/cpl_plot.h cpl-7.2.2+ds/cplcore/cpl_plot.h --- cpl-7.1.4+ds/cplcore/cpl_plot.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_plot.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -37,37 +37,61 @@ Function prototypes -----------------------------------------------------------------------------*/ -cpl_error_code cpl_plot_vector(const char *, const char *, const char *, - const cpl_vector *); +cpl_error_code +cpl_plot_vector(const char *, const char *, const char *, const cpl_vector *); -cpl_error_code cpl_plot_vectors(const char *, const char *, const char *, - const cpl_vector **, cpl_size); - -cpl_error_code cpl_plot_bivector(const char *, const char *, const char *, +cpl_error_code cpl_plot_vectors(const char *, + const char *, + const char *, + const cpl_vector **, + cpl_size); + +cpl_error_code cpl_plot_bivector(const char *, + const char *, + const char *, const cpl_bivector *); -cpl_error_code cpl_plot_bivectors(const char *, const char **, const char *, - const cpl_bivector **, cpl_size); +cpl_error_code cpl_plot_bivectors(const char *, + const char **, + const char *, + const cpl_bivector **, + cpl_size); -cpl_error_code cpl_plot_mask(const char *, const char *, const char *, - const cpl_mask *); +cpl_error_code +cpl_plot_mask(const char *, const char *, const char *, const cpl_mask *); -cpl_error_code cpl_plot_image(const char *, const char *, const char *, - const cpl_image *); +cpl_error_code +cpl_plot_image(const char *, const char *, const char *, const cpl_image *); -cpl_error_code cpl_plot_image_row(const char *, const char *, const char *, - const cpl_image *, cpl_size, cpl_size, +cpl_error_code cpl_plot_image_row(const char *, + const char *, + const char *, + const cpl_image *, + cpl_size, + cpl_size, cpl_size); -cpl_error_code cpl_plot_image_col(const char *, const char *, const char *, - const cpl_image *, cpl_size, cpl_size, +cpl_error_code cpl_plot_image_col(const char *, + const char *, + const char *, + const cpl_image *, + cpl_size, + cpl_size, cpl_size); -cpl_error_code cpl_plot_column(const char *, const char *, const char *, - const cpl_table *, const char *, const char *); - -cpl_error_code cpl_plot_columns(const char *, const char *, const char *, - const cpl_table *, const char **, cpl_size); +cpl_error_code cpl_plot_column(const char *, + const char *, + const char *, + const cpl_table *, + const char *, + const char *); + +cpl_error_code cpl_plot_columns(const char *, + const char *, + const char *, + const cpl_table *, + const char **, + cpl_size); CPL_END_DECLS diff -Nru cpl-7.1.4+ds/cplcore/cpl_polynomial.c cpl-7.2.2+ds/cplcore/cpl_polynomial.c --- cpl-7.1.4+ds/cplcore/cpl_polynomial.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_polynomial.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -73,12 +73,58 @@ /**@{*/ /*----------------------------------------------------------------------------- - Type definition + Macro definitions -----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/ -/* - Polynomial object. +/** + @internal + @def CPL_POLYNOMIAL_DEFAULT_COEFFS + @brief The default allocation for a 1D-polynomial + @hideinitializer + + */ +/*----------------------------------------------------------------------------*/ + +#ifndef CPL_POLYNOMIAL_DEFAULT_COEFFS +#define CPL_POLYNOMIAL_DEFAULT_COEFFS 5 +#endif + +/*----------------------------------------------------------------------------*/ +/** + @internal + @def CPL_POLYNOMIAL_SOLVE_MAXITE + @brief Maximum number of Newton-Raphson iterations + @hideinitializer + + */ +/*----------------------------------------------------------------------------*/ + +#ifndef CPL_POLYNOMIAL_SOLVE_MAXITE +#define CPL_POLYNOMIAL_SOLVE_MAXITE 100 +#endif + +/*----------------------------------------------------------------------------*/ +/** + @internal + @def CPL_POLYNOMIAL_COEFF_IS_MALLOC + @brief Boolean expression, true iff the coefficients are malloc()'ed + @param SELF The 1D-polynomial + @hideinitializer + + */ +/*----------------------------------------------------------------------------*/ +#define CPL_POLYNOMIAL_COEFF_IS_MALLOC(SELF) \ + ((SELF)->coef != (void *)((SELF) + 1)) + +/*----------------------------------------------------------------------------- + New types + -----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief Definition of the polynomial object The zero-polynomial (i.e. a zero-degree polynomial with a zero-valued coefficient) is regardless of its dimension stored internally as a @@ -210,77 +256,29 @@ */ /*----------------------------------------------------------------------------*/ - -/*----------------------------------------------------------------------------- - Macro definitions - -----------------------------------------------------------------------------*/ - -/*----------------------------------------------------------------------------*/ -/** - @internal - @def CPL_POLYNOMIAL_DEFAULT_COEFFS - @brief The default allocation for a 1D-polynomial - @hideinitializer - - */ -/*----------------------------------------------------------------------------*/ - -#ifndef CPL_POLYNOMIAL_DEFAULT_COEFFS -#define CPL_POLYNOMIAL_DEFAULT_COEFFS 5 -#endif - -/*----------------------------------------------------------------------------*/ -/** - @internal - @def CPL_POLYNOMIAL_SOLVE_MAXITE - @brief Maximum number of Newton-Raphson iterations - @hideinitializer - - */ -/*----------------------------------------------------------------------------*/ - -#ifndef CPL_POLYNOMIAL_SOLVE_MAXITE -#define CPL_POLYNOMIAL_SOLVE_MAXITE 100 -#endif - -/*----------------------------------------------------------------------------*/ -/** - @internal - @def CPL_POLYNOMIAL_COEFF_IS_MALLOC - @brief Boolean expression, true iff the coefficients are malloc()'ed - @param SELF The 1D-polynomial - @hideinitializer - - */ -/*----------------------------------------------------------------------------*/ -#define CPL_POLYNOMIAL_COEFF_IS_MALLOC(SELF) \ - ((SELF)->coef != (void*)((SELF) + 1)) - -/*----------------------------------------------------------------------------- - New types - -----------------------------------------------------------------------------*/ - -typedef struct cpl_polynomial_1d_ { - union { - double val; /* Final, lowest dimension, coefficient */ - struct cpl_polynomial_1d_ * next; /* Next, lower dimension */ +typedef struct cpl_polynomial_1d_ +{ + union + { + double val; /* Final, lowest dimension, coefficient */ + struct cpl_polynomial_1d_ *next; /* Next, lower dimension */ } * coef; cpl_size nc; /* The non-zero number of coefficients, one plus the degree */ cpl_size nz; /* The allocated number of coefficients, at least nc */ } cpl_polynomial_1d; -typedef struct _cpl_polynomial_ { - cpl_polynomial_1d * tree; /* NULL for the zero-polynomial */ - cpl_size dim; /* 1 for univariate */ - cpl_size degree; /* Kept updated at every coefficient change */ +typedef struct _cpl_polynomial_ +{ + cpl_polynomial_1d *tree; /* NULL for the zero-polynomial */ + cpl_size dim; /* 1 for univariate */ + cpl_size degree; /* Kept updated at every coefficient change */ } _cpl_polynomial_; /*----------------------------------------------------------------------------- Private function prototypes -----------------------------------------------------------------------------*/ -inline static cpl_polynomial_1d * cpl_polynomial_new_1d(cpl_size) - CPL_ATTR_ALLOC; +inline static cpl_polynomial_1d *cpl_polynomial_new_1d(cpl_size) CPL_ATTR_ALLOC; inline static void cpl_polynomial_delete_(cpl_polynomial_1d *, cpl_size); @@ -288,45 +286,38 @@ inline static void cpl_polynomial_grow_1d(cpl_polynomial_1d *, cpl_size); -inline static void cpl_polynomial_grow_1d_reset(cpl_polynomial_1d *, - cpl_size, - cpl_size); +inline static void +cpl_polynomial_grow_1d_reset(cpl_polynomial_1d *, cpl_size, cpl_size); inline static void cpl_polynomial_set_coeff_(cpl_polynomial_1d *, const cpl_size *, cpl_size, - double) - CPL_ATTR_NONNULL; + double) CPL_ATTR_NONNULL; -inline static cpl_boolean cpl_polynomial_prune_(cpl_polynomial_1d *, - cpl_size, - cpl_size); +static cpl_boolean +cpl_polynomial_prune_(cpl_polynomial_1d *, cpl_size, cpl_size); inline static void cpl_polynomial_transpose_(cpl_polynomial_1d *, - cpl_size *, cpl_size, - const cpl_size *, + cpl_size *, cpl_size, const cpl_polynomial_1d *, - cpl_size) - CPL_ATTR_NONNULL; + cpl_size) CPL_ATTR_NONNULL; static void cpl_polynomial_copy_(cpl_polynomial_1d *, cpl_size, const cpl_polynomial_1d *, - cpl_size) - CPL_ATTR_NONNULL; + cpl_size) CPL_ATTR_NONNULL; static cpl_size cpl_polynomial_find_degree_(const cpl_polynomial_1d *, - cpl_size) - CPL_ATTR_NONNULL; + cpl_size) CPL_ATTR_NONNULL; static int cpl_polynomial_compare_(const cpl_polynomial_1d *, const cpl_polynomial_1d *, cpl_size, double); -static cpl_boolean cpl_polynomial_add_(cpl_polynomial_1d *, +static cpl_boolean cpl_polynomial_add_(cpl_polynomial_1d *, const cpl_polynomial_1d *, const cpl_polynomial_1d *, cpl_size) @@ -335,16 +326,17 @@ #endif ; -static cpl_boolean cpl_polynomial_scale_add_(cpl_polynomial_1d *, +static cpl_boolean cpl_polynomial_scale_add_(cpl_polynomial_1d *, const cpl_polynomial_1d *, - cpl_size, double, - const cpl_size *) + cpl_size, + double, + const cpl_size *) #ifdef CPL_HAVE_ATTR_NONNULL - __attribute__((nonnull(1,5))) + __attribute__((nonnull(1, 5))) #endif ; -static cpl_boolean cpl_polynomial_subtract_(cpl_polynomial_1d *, +static cpl_boolean cpl_polynomial_subtract_(cpl_polynomial_1d *, const cpl_polynomial_1d *, const cpl_polynomial_1d *, cpl_size) @@ -353,92 +345,80 @@ #endif ; -static void cpl_polynomial_multiply_(cpl_polynomial_1d *, +static void cpl_polynomial_multiply_(cpl_polynomial_1d *, const cpl_polynomial_1d *, const cpl_polynomial_1d *, - cpl_size *, cpl_size, - const cpl_size *, - cpl_size) - CPL_ATTR_NONNULL; + cpl_size *, + cpl_size) CPL_ATTR_NONNULL; static cpl_error_code cpl_polynomial_dump_(const cpl_polynomial_1d *, - cpl_size *, cpl_size, - const cpl_size *, + cpl_size *, cpl_size, cpl_size *, - FILE *) - CPL_ATTR_NONNULL; + FILE *) CPL_ATTR_NONNULL; static void cpl_polynomial_multiply_scalar_(cpl_polynomial_1d *, const cpl_polynomial_1d *, cpl_size, - double) - CPL_ATTR_NONNULL; + double) CPL_ATTR_NONNULL; -static void cpl_polynomial_multiply_scalar_self(cpl_polynomial_1d *, - cpl_size, - double); +static void +cpl_polynomial_multiply_scalar_self(cpl_polynomial_1d *, cpl_size, double); -static cpl_error_code cpl_polynomial_dump_coeff(const cpl_size *, - cpl_size , - FILE *, - double ) +static cpl_error_code +cpl_polynomial_dump_coeff(const cpl_size *, cpl_size, FILE *, double) #ifdef CPL_HAVE_ATTR_NONNULL __attribute__((nonnull(3))); #endif -inline static double cpl_polynomial_get_coeff_(const cpl_polynomial_1d *, - const cpl_size *, - cpl_size) +inline static double +cpl_polynomial_get_coeff_(const cpl_polynomial_1d *, const cpl_size *, cpl_size) #ifdef CPL_HAVE_ATTR_NONNULL __attribute__((nonnull(2))); #endif -inline static cpl_long_double cpl_polynomial_eval_(const cpl_polynomial_1d *, - cpl_size, - const double *) +inline static cpl_long_double +cpl_polynomial_eval_(const cpl_polynomial_1d *, cpl_size, const double *) #ifdef CPL_HAVE_ATTR_NONNULL __attribute__((nonnull(3))); #endif static cpl_error_code cpl_polynomial_solve_1d__(const cpl_polynomial_1d *, - double, double *, + double, + double *, cpl_size, - cpl_boolean) - CPL_ATTR_NONNULL; + cpl_boolean) CPL_ATTR_NONNULL; -inline static cpl_long_double cpl_polynomial_eval_1d_(const cpl_polynomial_1d *, - double, double *) +inline static cpl_long_double +cpl_polynomial_eval_1d_(const cpl_polynomial_1d *, double, double *) #ifdef CPL_HAVE_ATTR_NONNULL __attribute__((nonnull(1))) #endif ; static void cpl_polynomial_eval_monomial_(const cpl_polynomial_1d *, - cpl_size *, - cpl_size , - const cpl_size *, - cpl_size , - const double *, - cpl_long_double *) + cpl_size, + cpl_size *, + cpl_size, + const double *, + cpl_long_double *) #ifdef CPL_HAVE_ATTR_NONNULL - __attribute__((nonnull(2,4,6,7))) + __attribute__((nonnull(3, 5, 6))) #endif ; -inline static -cpl_long_double cpl_polynomial_nested_horner(const cpl_polynomial_1d *, - double, double, - cpl_long_double *) - CPL_ATTR_NONNULL; +inline static cpl_long_double +cpl_polynomial_nested_horner(const cpl_polynomial_1d *, + double, + double, + cpl_long_double *) CPL_ATTR_NONNULL; static cpl_boolean cpl_polynomial_derivative_(cpl_polynomial_1d *, cpl_size, - cpl_size) - CPL_ATTR_NONNULL; + cpl_size) CPL_ATTR_NONNULL; static cpl_boolean cpl_polynomial_extract_(cpl_polynomial_1d *, const cpl_polynomial_1d *, @@ -448,32 +428,51 @@ inline static void cpl_polynomial_shift_1d_(cpl_polynomial_1d *, cpl_size, - double) - CPL_ATTR_NONNULL; + double) CPL_ATTR_NONNULL; -inline static cpl_boolean cpl_polynomial_delete_coeff_(cpl_polynomial_1d *, - const cpl_size *, - cpl_size) - CPL_ATTR_NONNULL; +static cpl_boolean cpl_polynomial_delete_coeff_(cpl_polynomial_1d *, + const cpl_size *, + cpl_size) CPL_ATTR_NONNULL; static void cpl_polynomial_delete_coeff(cpl_polynomial *, const cpl_size *, - cpl_size) - CPL_ATTR_NONNULL; + cpl_size) CPL_ATTR_NONNULL; + +static void cpl_matrix_fill_normal_vandermonde(cpl_matrix *, + cpl_matrix *, + const cpl_vector *, + cpl_boolean, + cpl_size, + const cpl_vector *, + const cpl_vector *) +#ifdef CPL_HAVE_ATTR_NONNULL + __attribute__((nonnull(1, 2, 3, 6))) +#endif + ; -static -void cpl_matrix_fill_normal_vandermonde(cpl_matrix *, cpl_matrix *, - const cpl_vector *, cpl_boolean, - cpl_size, const cpl_vector *) - CPL_ATTR_NONNULL; - -static -cpl_error_code cpl_polynomial_fit_2d(cpl_polynomial *, const cpl_bivector *, - const cpl_vector *, cpl_boolean, - const cpl_size *, - const cpl_size *) +static cpl_error_code cpl_polynomial_fit_2d(cpl_polynomial *, + const cpl_bivector *, + const cpl_vector *, + const cpl_vector *, + cpl_boolean, + const cpl_size *, + const cpl_size *) #ifdef CPL_HAVE_ATTR_NONNULL - __attribute__((nonnull(5))) + __attribute__((nonnull(6))) +#endif + ; + +static cpl_error_code cpl_polynomial_fit_3d(cpl_polynomial *, + const cpl_vector *, + const cpl_vector *, + const cpl_vector *, + const cpl_vector *, + const cpl_vector *, + cpl_boolean, + const cpl_size *, + const cpl_size *) +#ifdef CPL_HAVE_ATTR_NONNULL + __attribute__((nonnull(8))) #endif ; @@ -497,9 +496,10 @@ - CPL_ERROR_ILLEGAL_INPUT if dim is negative or zero */ /*----------------------------------------------------------------------------*/ -cpl_polynomial * cpl_polynomial_new(cpl_size dim) +cpl_polynomial * +cpl_polynomial_new(cpl_size dim) { - cpl_polynomial * self; + cpl_polynomial *self; cpl_ensure(dim > 0, CPL_ERROR_ILLEGAL_INPUT, NULL); @@ -518,12 +518,13 @@ @brief Reset (delete all coefficients of) a cpl_polynomial @param self Polynomial to modify @return void - @see cpl_polynomial_free() + @see cpl_polynomial_delete() @note The dimension is unchanged, the degree is zero */ /*----------------------------------------------------------------------------*/ -void cpl_polynomial_empty(cpl_polynomial * self) +void +cpl_polynomial_empty(cpl_polynomial *self) { if (self != NULL) { assert(self->dim > 0); @@ -545,22 +546,21 @@ */ /*----------------------------------------------------------------------------*/ -void cpl_polynomial_delete(cpl_polynomial * self) +void +cpl_polynomial_delete(cpl_polynomial *self) { if (self != NULL) { cpl_polynomial_empty(self); - cpl_free((void*)self); + cpl_free((void *)self); } } /*----------------------------------------------------------------------------*/ /** - @brief Dump a polynomial as ASCII to a stream, fail on zero-polynomial(s) + @brief Dump a polynomial as ASCII to a stream @param self The polynomial to process @param stream Output stream eq. @c stdout or @c stderr @return CPL_ERROR_NONE or the relevant #_cpl_error_code_ - @note Since this function is mostly for testing during development, it checks - for illegal sub-zero-polynomials and sets a CPL error if one is found Each coefficient is preceded by its integer power(s) and written on a single line. @@ -577,24 +577,24 @@ - CPL_ERROR_FILE_IO if the write operation fails */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_polynomial_dump(const cpl_polynomial * self, - FILE * stream) +cpl_error_code +cpl_polynomial_dump(const cpl_polynomial *self, FILE *stream) { - cpl_size* pows; cpl_error_code code; int retval; cpl_size icoeff = 0; - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(stream != NULL, CPL_ERROR_NULL_INPUT); - retval = fprintf(stream, "#----- %" CPL_SIZE_FORMAT " dimensional " + retval = fprintf(stream, + "#----- %" CPL_SIZE_FORMAT " dimensional " "polynomial of degree %" CPL_SIZE_FORMAT " -----\n", self->dim, self->degree); cpl_ensure_code(retval > 0, CPL_ERROR_FILE_IO); for (cpl_size i = 0; i < self->dim; i++) { - retval = fprintf(stream, "%d.dim.power ", (int)i+1); + retval = fprintf(stream, "%d.dim.power ", (int)i + 1); cpl_ensure_code(retval > 0, CPL_ERROR_FILE_IO); } retval = fprintf(stream, "coefficient\n"); @@ -602,19 +602,22 @@ if (self->tree == NULL) { code = cpl_polynomial_dump_coeff(NULL, self->dim, stream, 0.0); - } else { - pows = cpl_malloc((size_t)self->dim * sizeof(*pows)); + } + else { + cpl_size *pows = cpl_malloc((size_t)self->dim * sizeof(*pows)); - code = cpl_polynomial_dump_(self->tree, - pows + self->dim - 1, self->dim - 1, - pows, self->dim, &icoeff, stream); + code = cpl_polynomial_dump_(self->tree, self->dim - 1, pows, self->dim, + &icoeff, stream); cpl_free(pows); } - if (code) return cpl_error_set_where_(); + if (code) + return cpl_error_set_where_(); - retval = fprintf(stream, "#----- %" CPL_SIZE_FORMAT " coefficient(s) " - "-----\n", icoeff); + retval = fprintf(stream, + "#----- %" CPL_SIZE_FORMAT " coefficient(s) " + "-----\n", + icoeff); cpl_ensure_code(retval > 0, CPL_ERROR_FILE_IO); retval = fprintf(stream, "#------------------------------------\n"); @@ -634,20 +637,21 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_polynomial * cpl_polynomial_duplicate(const cpl_polynomial * self) +cpl_polynomial * +cpl_polynomial_duplicate(const cpl_polynomial *self) { - cpl_polynomial * other; + cpl_polynomial *other; cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); other = cpl_polynomial_new(self->dim); - if (self->tree == NULL) return other; + if (self->tree == NULL) + return other; other->tree = cpl_polynomial_new_1d(self->tree->nc); - cpl_polynomial_copy_(other->tree, self->dim - 1, - self->tree, self->dim - 1); + cpl_polynomial_copy_(other->tree, self->dim - 1, self->tree, self->dim - 1); other->degree = self->degree; return other; @@ -668,23 +672,24 @@ Possible #_cpl_error_code_ set in this function: - CPL_ERROR_NULL_INPUT if an input pointer is NULL - - CPL_ERROR_INCOMPATIBLE_INPUT if in and out point to the same polynomial + - CPL_ERROR_INCOMPATIBLE_INPUT if self and out point to the same polynomial */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_polynomial_copy(cpl_polynomial * self, - const cpl_polynomial * other) +cpl_error_code +cpl_polynomial_copy(cpl_polynomial *self, const cpl_polynomial *other) { - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(other != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(other != self, CPL_ERROR_INCOMPATIBLE_INPUT); if (other->tree == NULL) { cpl_polynomial_empty(self); /* Deallocate any pre-existing buffers */ - } else { - if (self->tree == NULL) + } + else { + if (self->tree == NULL) self->tree = cpl_polynomial_new_1d(other->tree->nc); - cpl_polynomial_copy_(self->tree, self->dim - 1, - other->tree, other->dim - 1); + cpl_polynomial_copy_(self->tree, self->dim - 1, other->tree, + other->dim - 1); self->degree = other->degree; } self->dim = other->dim; @@ -726,28 +731,27 @@ - CPL_ERROR_ILLEGAL_INPUT if tol is negative */ /*----------------------------------------------------------------------------*/ -int cpl_polynomial_compare(const cpl_polynomial * self, - const cpl_polynomial * other, - double tol) +int +cpl_polynomial_compare(const cpl_polynomial *self, + const cpl_polynomial *other, + double tol) { - - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1); + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1); cpl_ensure(other != NULL, CPL_ERROR_NULL_INPUT, -2); - cpl_ensure(tol >= 0.0, CPL_ERROR_ILLEGAL_INPUT, -5); + cpl_ensure(tol >= 0.0, CPL_ERROR_ILLEGAL_INPUT, -5); - if (self == other) return 0; + if (self == other) + return 0; if (self->dim > other->dim) { return self->dim - other->dim; - } else if (other->dim > self->dim) { + } + else if (other->dim > self->dim) { return other->dim - self->dim; } /* The two polynomials have equal dimension */ - return cpl_polynomial_compare_(self->tree, - other->tree, - self->dim - 1, - tol); + return cpl_polynomial_compare_(self->tree, other->tree, self->dim - 1, tol); } /*----------------------------------------------------------------------------*/ @@ -764,7 +768,8 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_polynomial_get_degree(const cpl_polynomial * self) +cpl_size +cpl_polynomial_get_degree(const cpl_polynomial *self) { cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1); @@ -781,7 +786,8 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_polynomial_get_dimension(const cpl_polynomial * self) +cpl_size +cpl_polynomial_get_dimension(const cpl_polynomial *self) { cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1); @@ -813,18 +819,19 @@ - CPL_ERROR_ILLEGAL_INPUT if pows contains negative values */ /*----------------------------------------------------------------------------*/ -double cpl_polynomial_get_coeff(const cpl_polynomial * self, - const cpl_size * pows) +double +cpl_polynomial_get_coeff(const cpl_polynomial *self, const cpl_size *pows) { cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, 0.0); cpl_ensure(pows != NULL, CPL_ERROR_NULL_INPUT, 0.0); for (cpl_size mydim = 0; mydim < self->dim; mydim++) { if (pows[mydim] < 0) { - (void)cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, "Dimension %" - CPL_SIZE_FORMAT " of %"CPL_SIZE_FORMAT - " has negative power %"CPL_SIZE_FORMAT, - mydim+1, self->dim, pows[mydim]); + (void)cpl_error_set_message_( + CPL_ERROR_ILLEGAL_INPUT, + "Dimension %" CPL_SIZE_FORMAT " of %" CPL_SIZE_FORMAT + " has negative power %" CPL_SIZE_FORMAT, + mydim + 1, self->dim, pows[mydim]); return 0.0; } } @@ -868,17 +875,18 @@ @endcode - For efficiency reasons, multiple coefficients are best inserted with the - of the highest powers first. + When setting multiple coefficients there is a small efficiency gain when + setting the highest powers first. Possible #_cpl_error_code_ set in this function: - CPL_ERROR_NULL_INPUT if an input pointer is NULL - CPL_ERROR_ILLEGAL_INPUT if pows contains negative values */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_polynomial_set_coeff(cpl_polynomial * self, - const cpl_size * pows, - double value) +cpl_error_code +cpl_polynomial_set_coeff(cpl_polynomial *self, + const cpl_size *pows, + double value) { cpl_size powdegree = 0; @@ -886,23 +894,25 @@ cpl_ensure_code(pows != NULL, CPL_ERROR_NULL_INPUT); for (cpl_size mydim = 0; mydim < self->dim; mydim++) { - if (pows[mydim] < 0) return - cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, "Dimension %" - CPL_SIZE_FORMAT " of %" CPL_SIZE_FORMAT - " has negative power %" CPL_SIZE_FORMAT, - mydim+1, self->dim, pows[mydim]); + if (pows[mydim] < 0) + return cpl_error_set_message_( + CPL_ERROR_ILLEGAL_INPUT, + "Dimension %" CPL_SIZE_FORMAT " of %" CPL_SIZE_FORMAT + " has negative power %" CPL_SIZE_FORMAT, + mydim + 1, self->dim, pows[mydim]); powdegree += pows[mydim]; } if (value != 0.0) { - - if (self->tree == NULL) + if (self->tree == NULL) self->tree = cpl_polynomial_new_1d(1 + pows[self->dim - 1]); cpl_polynomial_set_coeff_(self->tree, pows, self->dim - 1, value); - if (powdegree > self->degree) self->degree = powdegree; - } else { + if (powdegree > self->degree) + self->degree = powdegree; + } + else { cpl_polynomial_delete_coeff(self, pows, powdegree); } @@ -911,7 +921,7 @@ /*----------------------------------------------------------------------------*/ /** - @brief Evaluate the polynomial at the given point using Horners rule. + @brief Evaluate the polynomial at the given point using Horner's rule. @param self The polynomial to access @param x Point of evaluation @note The length of x must match the polynomial dimension. @@ -921,16 +931,35 @@ With n coefficients the complexity is about 2n FLOPs. + @par For multiple evaluations the input vector can be updated like this: + @code + double xy[2]; + cpl_vector * xyvec = cpl_vector_wrap(2, xy); + + for (cpl_size i = 0; i < nmany; i++) { + double value; + + xy[0] = my_x(i); + xy[1] = my_y(i); + + value = cpl_polynomial_eval(poly2d, xyvec); + + my_func(value); + } + (void)cpl_vector_unwrap(xyvec); + @endcode + Possible #_cpl_error_code_ set in this function: - CPL_ERROR_NULL_INPUT if an input pointer is NULL - CPL_ERROR_INCOMPATIBLE_INPUT if the length of x differs from the dimension of the polynomial */ /*----------------------------------------------------------------------------*/ -double cpl_polynomial_eval(const cpl_polynomial * self, const cpl_vector * x) +double +cpl_polynomial_eval(const cpl_polynomial *self, const cpl_vector *x) { cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1.0); - cpl_ensure(x != NULL, CPL_ERROR_NULL_INPUT, -2.0); + cpl_ensure(x != NULL, CPL_ERROR_NULL_INPUT, -2.0); cpl_ensure(self->dim == cpl_vector_get_size_(x), CPL_ERROR_INCOMPATIBLE_INPUT, -3.0); @@ -978,20 +1007,20 @@ */ /*----------------------------------------------------------------------------*/ -cpl_polynomial * cpl_polynomial_extract(const cpl_polynomial * self, - cpl_size dim, - const cpl_polynomial * other) +cpl_polynomial * +cpl_polynomial_extract(const cpl_polynomial *self, + cpl_size dim, + const cpl_polynomial *other) { - - cpl_polynomial * collapsed; - cpl_size newdim; + cpl_polynomial *collapsed; + cpl_size newdim; - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(other != NULL, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(self->dim > 1, CPL_ERROR_INVALID_TYPE, NULL); - cpl_ensure(dim >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL); - cpl_ensure(dim < self->dim, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL); + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(other != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(self->dim > 1, CPL_ERROR_INVALID_TYPE, NULL); + cpl_ensure(dim >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(dim < self->dim, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL); newdim = self->dim - 1; @@ -1004,23 +1033,23 @@ collapsed = cpl_polynomial_new(newdim); if (self->tree != NULL) { - cpl_size * pows = cpl_calloc(newdim, sizeof(*pows)); + cpl_size *pows = cpl_calloc(newdim, sizeof(*pows)); const double value = cpl_polynomial_get_coeff(other, pows); cpl_free(pows); collapsed->tree = cpl_polynomial_new_1d(self->tree->nc); - if (cpl_polynomial_extract_(collapsed->tree, self->tree, - self->dim - 1, dim, value)) { + if (cpl_polynomial_extract_(collapsed->tree, self->tree, self->dim - 1, + dim, value)) { cpl_polynomial_empty(collapsed); - } else { + } + else { collapsed->degree = cpl_polynomial_find_degree_(collapsed->tree, collapsed->dim - 1); } } return collapsed; - } /*----------------------------------------------------------------------------*/ @@ -1031,7 +1060,7 @@ @return CPL_ERROR_NONE or the relevant #_cpl_error_code_ The dimension of the polynomial is preserved, even if the operation may cause - the polynomial to become independent of the dimension dim of the variable. + the polynomial to become independent of the dimension dim variable. The call requires n FLOPs, where n is the number of (non-zero) polynomial coefficients whose power in dimension dim is at least 1. @@ -1042,18 +1071,20 @@ - CPL_ERROR_ACCESS_OUT_OF_RANGE if dim exceeds the dimension of self. */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_polynomial_derivative(cpl_polynomial * self, cpl_size dim) +cpl_error_code +cpl_polynomial_derivative(cpl_polynomial *self, cpl_size dim) { - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(dim >= 0, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(dim < self->dim, CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(dim >= 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(dim < self->dim, CPL_ERROR_ACCESS_OUT_OF_RANGE); if (self->tree != NULL) { if (cpl_polynomial_derivative_(self->tree, self->dim - 1, dim)) { cpl_polynomial_empty(self); - } else { - self->degree = cpl_polynomial_find_degree_(self->tree, - self->dim - 1); + } + else { + self->degree = + cpl_polynomial_find_degree_(self->tree, self->dim - 1); } } @@ -1062,7 +1093,7 @@ /*----------------------------------------------------------------------------*/ /** - @brief Evaluate a univariate (1D) polynomial using Horners rule. + @brief Evaluate a univariate (1D) polynomial using Horner's rule. @param self The 1D-polynomial @param x The point of evaluation @param pd Iff pd is non-NULL, the derivative evaluated at x @@ -1083,14 +1114,15 @@ - CPL_ERROR_INVALID_TYPE if the polynomial is not (1D) univariate */ /*----------------------------------------------------------------------------*/ -double cpl_polynomial_eval_1d(const cpl_polynomial * self, double x, - double * pd) +double +cpl_polynomial_eval_1d(const cpl_polynomial *self, double x, double *pd) { - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1.0); - cpl_ensure(self->dim == 1, CPL_ERROR_INVALID_TYPE, -3.0); + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1.0); + cpl_ensure(self->dim == 1, CPL_ERROR_INVALID_TYPE, -3.0); if (self->tree == NULL) { - if (pd != NULL) *pd = 0.0; + if (pd != NULL) + *pd = 0.0; return 0.0; } @@ -1099,12 +1131,13 @@ /*----------------------------------------------------------------------------*/ /** - @brief Evaluate p(a) - p(b) using Horners rule. + @brief Evaluate p(a) - p(b) using Horner's rule. @param self The 1D-polynomial @param a The evaluation point of the minuend @param b The evaluation point of the subtrahend @param ppa Iff ppa is not NULL, p(a) @return The difference or undefined on error + @see cpl_polynomial_eval_1d() The call requires about 4n FLOPs where n is the number of coefficients in self, which is the same as that required for two separate polynomial @@ -1121,22 +1154,28 @@ - CPL_ERROR_INVALID_TYPE if the polynomial has the wrong dimension */ /*----------------------------------------------------------------------------*/ -double cpl_polynomial_eval_1d_diff(const cpl_polynomial * self, double a, - double b, double * ppa) +double +cpl_polynomial_eval_1d_diff(const cpl_polynomial *self, + double a, + double b, + double *ppa) { double result; - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1.0); - cpl_ensure(self->dim == 1, CPL_ERROR_INVALID_TYPE, -3.0); + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1.0); + cpl_ensure(self->dim == 1, CPL_ERROR_INVALID_TYPE, -3.0); if (self->tree == NULL) { - if (ppa != NULL) *ppa = 0.0; + if (ppa != NULL) + *ppa = 0.0; result = 0.0; - } else { + } + else { cpl_long_double pa; result = cpl_polynomial_nested_horner(self->tree, a, b, &pa) * (a - b); - if (ppa != NULL) *ppa = (double)pa; + if (ppa != NULL) + *ppa = (double)pa; } return result; @@ -1144,7 +1183,7 @@ /*----------------------------------------------------------------------------*/ /** - @brief Evaluate a 1D-polynomial on equidistant points using Horners rule + @brief Evaluate a 1D-polynomial on equidistant points using Horner's rule @param v Preallocated vector to contain the result @param p The 1D-polynomial @param x0 The first point of evaluation @@ -1166,21 +1205,23 @@ - CPL_ERROR_INVALID_TYPE if the polynomial has the wrong dimension */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_vector_fill_polynomial(cpl_vector * v, - const cpl_polynomial * p, - double x0, double d) +cpl_error_code +cpl_vector_fill_polynomial(cpl_vector *v, + const cpl_polynomial *p, + double x0, + double d) { cpl_size i; - double * dv; + double *dv; - cpl_ensure_code(v != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(p != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(v != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(p != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(p->dim == 1, CPL_ERROR_INVALID_TYPE); - i = cpl_vector_get_size_(v); + i = cpl_vector_get_size_(v); dv = cpl_vector_get_data_(v); - cpl_tools_add_flops( 2 * i ); + cpl_tools_add_flops(2 * i); do { i--; @@ -1201,13 +1242,16 @@ Even if a real solution exists, it may not be found if the first guess is too far from the solution. But a solution is guaranteed to be found if all - roots of p are real. If the constant term is zero, the solution 0 will be + roots of p are real (except in the case where the derivative at the first + guess happens to be zero, see below - for an n-degree polynomial there are up + to n-1 such guesses). If the constant term is zero, the solution 0 will be returned regardless of the first guess. No solution is found when the iterative process stops because: 1) It can not proceed because p`(x) = 0 (CPL_ERROR_DIVISION_BY_ZERO). 2) Only a finite number of iterations are allowed (CPL_ERROR_CONTINUE). - Both cases may be due to lack of a real solution or a bad first guess. + Either can happen due to an an actual lack of a real solution or due to an + insufficiently good first guess. In these two cases *px is set to the value where the error occurred. In case of other errors *px is unmodified. @@ -1228,11 +1272,15 @@ - CPL_ERROR_CONTINUE if the algorithm does not converge */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_polynomial_solve_1d(const cpl_polynomial * p, - double x0, double * px, cpl_size mul) +cpl_error_code +cpl_polynomial_solve_1d(const cpl_polynomial *p, + double x0, + double *px, + cpl_size mul) { return cpl_polynomial_solve_1d_(p, x0, px, mul, CPL_FALSE) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } /*----------------------------------------------------------------------------*/ @@ -1247,9 +1295,9 @@ @param mindeg Pointer to 1 or d minimum fitting degree(s), or NULL @param maxdeg Pointer to 1 or d maximum fitting degree(s), at least mindeg @return CPL_ERROR_NONE on success, else the relevant #_cpl_error_code_ - @note Currently only uni- and bi-variate polynomials are supported, - fitsigm must be NULL. For all but uni-variate polynomials mindeg must - be zero. + @note Currently only 1D (uni-variate), 2D (bi-variate) and 3D (tri-variate) + polynomials are supported. For all but uni-variate + polynomials mindeg must be zero. @see cpl_vector_fill_polynomial_fit_residual() Any pre-set non-zero coefficients in self are overwritten or reset by the fit. @@ -1261,9 +1309,10 @@ If dimdeg is false, an n-degree coefficient is fitted iff mindeg <= n <= maxdeg. For a 2D-polynomial this means that - N * (N + 1) / 2 coefficients are fitted. + N * (N + 1) / 2 coefficients are fitted. For a 3D-polynomial, + it is N * (N + 1) * (N + 2) / 6. - If dimdeg is true, nci = 1 + maxdeg[i] + mindeg[i] coefficients are fitted + If dimdeg is true, nci = 1 + maxdeg[i] - mindeg[i] coefficients are fitted for dimension i, i.e. for a 2D-polynomial N = nc1 * nc2 coefficients are fitted. @@ -1275,7 +1324,9 @@ samples. If the relative uncertainties of the sampled values are known, they may be - passed via fitsigm. NULL means that all uncertainties equals one. + passed via fitsigm. NULL means that all uncertainties equals one. This + uncertainties can be applied to the least squares method by converting them + to weights (w = 1.0 / sigma^2). sampsym is ignored if mindeg is nonzero, otherwise the caller may use sampsym to indicate an a priori knowledge that the sampling @@ -1309,11 +1360,13 @@ happens with an increase of the polynomial degree from 8 to 9. The fit is done in the following steps: - 1) If mindeg is zero, the sampling positions are first transformed into + 1) If fitsigm is non-NULL. The factors are applied to the values. + 2) If mindeg is zero, the sampling positions are first transformed into Xhat_i = X_i - mean(X_i), i=1, .., dimension. - 2) The Vandermonde matrix is formed from Xhat. - 3) The normal equations of the Vandermonde matrix is solved. - 4) If mindeg is zero, the resulting polynomial in Xhat is transformed + 3) The Vandermonde matrix is formed from Xhat. If fitsigm is non-NULL, + the weights are also taken into account. + 4) The normal equations of the Vandermonde matrix is solved. + 5) If mindeg is zero, the resulting polynomial in Xhat is transformed back to X. For a univariate (1D) fit the call requires 6MN + N^3/3 + 7/2N^2 + O(M) FLOPs @@ -1350,6 +1403,18 @@ @endcode + @code + + cpl_polynomial * fit3d = cpl_polynomial_new(3); + cpl_matrix * samppos3d = my_sampling_points_3d(); // 3-row matrix + cpl_vector * fitvals = my_sampling_values(); + const cpl_size maxdeg3d[] = {2, 1, 2}; // Fit 18 coefficients + cpl_error_code error3d + = cpl_polynomial_fit(fit3d, samppos3d, NULL, fitvals, NULL, CPL_FALSE, + NULL, maxdeg3d); + + @endcode + Possible #_cpl_error_code_ set in this function: - CPL_ERROR_NULL_INPUT if an input pointer is NULL - CPL_ERROR_ILLEGAL_INPUT if a mindeg value is negative, or if a maxdeg value @@ -1360,86 +1425,118 @@ incompatible sizes, or if samppos, self or sampsym have incompatible sizes. - CPL_ERROR_SINGULAR_MATRIX if samppos contains too few distinct values - CPL_ERROR_DIVISION_BY_ZERO if an element in fitsigm is zero - - CPL_ERROR_UNSUPPORTED_MODE if the polynomial dimension exceeds two + - CPL_ERROR_UNSUPPORTED_MODE if the polynomial dimension exceeds three */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_polynomial_fit(cpl_polynomial * self, - const cpl_matrix * samppos, - const cpl_boolean * sampsym, - const cpl_vector * fitvals, - const cpl_vector * fitsigm, - cpl_boolean dimdeg, - const cpl_size * mindeg, - const cpl_size * maxdeg) +cpl_error_code +cpl_polynomial_fit(cpl_polynomial *self, + const cpl_matrix *samppos, + const cpl_boolean *sampsym, + const cpl_vector *fitvals, + const cpl_vector *fitsigm, + cpl_boolean dimdeg, + const cpl_size *mindeg, + const cpl_size *maxdeg) { - const cpl_size mdim = cpl_polynomial_get_dimension(self); - const cpl_size np = cpl_vector_get_size(fitvals); + const cpl_size np = cpl_vector_get_size(fitvals); - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(samppos != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(fitvals != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(maxdeg != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(maxdeg != NULL, CPL_ERROR_NULL_INPUT); - if (cpl_matrix_get_ncol(samppos) != np) - return cpl_error_set_message_(CPL_ERROR_INCOMPATIBLE_INPUT, "Number of " + if (cpl_matrix_get_ncol_(samppos) != np) + return cpl_error_set_message_(CPL_ERROR_INCOMPATIBLE_INPUT, + "Number of " "fitting values = %" CPL_SIZE_FORMAT " <=> % " CPL_SIZE_FORMAT " = samppos col" - "umns", np, cpl_matrix_get_ncol(samppos)); + "umns", + np, cpl_matrix_get_ncol_(samppos)); - if (cpl_matrix_get_nrow(samppos) != mdim) - return cpl_error_set_message_(CPL_ERROR_INCOMPATIBLE_INPUT, "Fitting " - "dimension = %" CPL_SIZE_FORMAT " <=> %" - CPL_SIZE_FORMAT " = samppos rows", mdim, - cpl_matrix_get_nrow(samppos)); + if (cpl_matrix_get_nrow_(samppos) != mdim) + return cpl_error_set_message_(CPL_ERROR_INCOMPATIBLE_INPUT, + "Fitting " + "dimension = %" CPL_SIZE_FORMAT + " <=> %" CPL_SIZE_FORMAT + " = samppos rows", + mdim, cpl_matrix_get_nrow(samppos)); if (fitsigm != NULL && cpl_vector_get_size_(fitsigm) != np) - return cpl_error_set_message_(CPL_ERROR_INCOMPATIBLE_INPUT, "Number of " + return cpl_error_set_message_(CPL_ERROR_INCOMPATIBLE_INPUT, + "Number of " "fitting values = %" CPL_SIZE_FORMAT " <=" "> % " CPL_SIZE_FORMAT " = number of er" - "rors", np, cpl_vector_get_size(fitsigm)); - - if (fitsigm != NULL) - return cpl_error_set_message_(CPL_ERROR_UNSUPPORTED_MODE, "fitsigm = " - "%p != NULL is not supported (yet)", - (const void*)fitsigm); + "rors", + np, cpl_vector_get_size(fitsigm)); -CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); + CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); if (mdim == 1) { - cpl_vector * x_pos - = cpl_vector_wrap(np, cpl_matrix_get_data((cpl_matrix*)samppos)); + cpl_vector *x_pos = + cpl_vector_wrap(np, cpl_matrix_get_data_((cpl_matrix *)samppos)); const cpl_boolean isampsym = sampsym ? sampsym[0] : CPL_FALSE; - const int mindeg0 = mindeg ? mindeg[0] : 0; - const cpl_error_code error = cpl_polynomial_fit_1d(self, x_pos, fitvals, - mindeg0, maxdeg[0], - isampsym, NULL); -CPL_DIAG_PRAGMA_POP; + const int mindeg0 = mindeg ? mindeg[0] : 0; + const cpl_error_code error = + cpl_polynomial_fit_1d(self, x_pos, fitvals, fitsigm, mindeg0, + maxdeg[0], isampsym, NULL); + CPL_DIAG_PRAGMA_POP; (void)cpl_vector_unwrap(x_pos); - if (error) return cpl_error_set_where_(); -CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); - } else if (mdim == 2) { - cpl_vector * x_pos - = cpl_vector_wrap(np, cpl_matrix_get_data((cpl_matrix *)samppos)); - cpl_vector * y_pos = cpl_vector_wrap(np, np - + cpl_matrix_get_data((cpl_matrix *)samppos)); - cpl_bivector * xy_pos = cpl_bivector_wrap_vectors(x_pos, y_pos); - const cpl_size mindeg0[2] = {mindeg ? mindeg[0] : 0, - mindeg ? mindeg[1] : 0}; - const cpl_error_code error = cpl_polynomial_fit_2d(self, xy_pos, - fitvals, dimdeg, - mindeg0, - maxdeg); -CPL_DIAG_PRAGMA_POP; + if (error) + return cpl_error_set_where_(); + CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); + } + else if (mdim == 2) { + cpl_vector *x_pos = + cpl_vector_wrap(np, cpl_matrix_get_data_((cpl_matrix *)samppos)); + cpl_vector *y_pos = + cpl_vector_wrap(np, + np + cpl_matrix_get_data_((cpl_matrix *)samppos)); + cpl_bivector *xy_pos = cpl_bivector_wrap_vectors(x_pos, y_pos); + const cpl_size mindeg0[2] = { mindeg ? mindeg[0] : 0, + mindeg ? mindeg[1] : 0 }; + const cpl_error_code error = + cpl_polynomial_fit_2d(self, xy_pos, fitvals, fitsigm, dimdeg, + mindeg0, maxdeg); + CPL_DIAG_PRAGMA_POP; (void)cpl_vector_unwrap(x_pos); (void)cpl_vector_unwrap(y_pos); cpl_bivector_unwrap_vectors(xy_pos); - if (error) return cpl_error_set_where_(); - } else { - assert( mdim > 2 ); - return cpl_error_set_message_(CPL_ERROR_UNSUPPORTED_MODE, "The fitting " - "dimension %d > 2 is not supported", + if (error) + return cpl_error_set_where_(); + CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); + } + else if (mdim == 3) { + cpl_vector *x_pos = + cpl_vector_wrap(np, cpl_matrix_get_data_((cpl_matrix *)samppos)); + cpl_vector *y_pos = + cpl_vector_wrap(np, + np + cpl_matrix_get_data_((cpl_matrix *)samppos)); + cpl_vector *z_pos = + cpl_vector_wrap(np, np * 2 + cpl_matrix_get_data_( + (cpl_matrix *)samppos)); + const cpl_size mindeg0[3] = { mindeg ? mindeg[0] : 0, + mindeg ? mindeg[1] : 0, + mindeg ? mindeg[2] : 0 }; + + const cpl_error_code error = + cpl_polynomial_fit_3d(self, x_pos, y_pos, z_pos, fitvals, fitsigm, + dimdeg, mindeg0, maxdeg); + + CPL_DIAG_PRAGMA_POP; + (void)cpl_vector_unwrap(x_pos); + (void)cpl_vector_unwrap(y_pos); + (void)cpl_vector_unwrap(z_pos); + + if (error) + return cpl_error_set_where_(); + } + else { + assert(mdim > 3); + return cpl_error_set_message_(CPL_ERROR_UNSUPPORTED_MODE, + "The fitting " + "dimension %d > 3 is not supported", (int)mdim); } @@ -1490,49 +1587,53 @@ */ /*----------------------------------------------------------------------------*/ cpl_error_code -cpl_vector_fill_polynomial_fit_residual(cpl_vector * self, - const cpl_vector * fitvals, - const cpl_vector * fitsigm, - const cpl_polynomial * fit, - const cpl_matrix * samppos, - double * rechisq) +cpl_vector_fill_polynomial_fit_residual(cpl_vector *self, + const cpl_vector *fitvals, + const cpl_vector *fitsigm, + const cpl_polynomial *fit, + const cpl_matrix *samppos, + double *rechisq) { const cpl_size mdim = cpl_polynomial_get_dimension(fit); const cpl_size np = cpl_vector_get_size(fitvals); const cpl_size nc = fit && fit->tree ? fit->tree->nc : 0; - const double * dsamppos = cpl_matrix_get_data_const(samppos); - const double * dfitvals = cpl_vector_get_data_const(fitvals); - double * dself; - cpl_size i, j; - - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(dfitvals != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(fit != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(dsamppos != NULL, CPL_ERROR_NULL_INPUT); + const double *dsamppos; + const double *dfitvals; + double *dself; + cpl_size i; + + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(fitvals != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(fit != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(samppos != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(cpl_matrix_get_ncol(samppos) == np, + cpl_ensure_code(cpl_matrix_get_ncol_(samppos) == np, CPL_ERROR_INCOMPATIBLE_INPUT); - cpl_ensure_code(cpl_matrix_get_nrow(samppos) == mdim, + cpl_ensure_code(cpl_matrix_get_nrow_(samppos) == mdim, CPL_ERROR_INCOMPATIBLE_INPUT); /* May not be under-determined */ cpl_ensure_code(np >= nc, CPL_ERROR_DATA_NOT_FOUND); + dsamppos = cpl_matrix_get_data_const_(samppos); + dfitvals = cpl_vector_get_data_const_(fitvals); + cpl_vector_set_size(self, np); dself = cpl_vector_get_data_(self); if (mdim == 1) { for (i = 0; i < np; i++) { - dself[i] = dfitvals[i] - cpl_polynomial_eval_1d(fit, dsamppos[i], - NULL); + dself[i] = + dfitvals[i] - cpl_polynomial_eval_1d(fit, dsamppos[i], NULL); } - } else { - double * dsampoint = cpl_malloc((size_t)mdim * sizeof(*dsampoint)); - cpl_vector * sampoint = cpl_vector_wrap(mdim, dsampoint); + } + else { + double *dsampoint = cpl_malloc((size_t)mdim * sizeof(*dsampoint)); + cpl_vector *sampoint = cpl_vector_wrap(mdim, dsampoint); for (i = 0; i < np; i++) { - for (j = 0; j < mdim; j++) { + for (cpl_size j = 0; j < mdim; j++) { dsampoint[j] = dsamppos[i + j * np]; } dself[i] = dfitvals[i] - cpl_polynomial_eval(fit, sampoint); @@ -1541,7 +1642,7 @@ cpl_vector_delete(sampoint); } - cpl_tools_add_flops( np ); + cpl_tools_add_flops(np); if (rechisq != NULL) { /* Assuming that the np sampling points are distinct! */ @@ -1551,8 +1652,9 @@ if (fitsigm == NULL) { *rechisq = cpl_vector_product(self, self) / (double)nfree; - } else { - const double * dsigm = cpl_vector_get_data_const_(fitsigm); + } + else { + const double *dsigm = cpl_vector_get_data_const_(fitsigm); double dot = 0.0; cpl_ensure_code(cpl_vector_get_size_(fitsigm) == np, @@ -1566,7 +1668,7 @@ dot += delta * delta; } *rechisq = dot / (double)nfree; - cpl_tools_add_flops( 3 * np ); + cpl_tools_add_flops(3 * np); } } @@ -1597,37 +1699,38 @@ - CPL_ERROR_ACCESS_OUT_OF_RANGE if i exceeds the dimension of p */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_polynomial_shift_1d(cpl_polynomial * p, cpl_size i, double u) +cpl_error_code +cpl_polynomial_shift_1d(cpl_polynomial *p, cpl_size i, double u) { - const cpl_size ndim = cpl_polynomial_get_dimension(p); cpl_ensure_code(p != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(i >= 0, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(i < ndim, CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_ensure_code(i >= 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(i < ndim, CPL_ERROR_ACCESS_OUT_OF_RANGE); if (p->tree != NULL) { - cpl_ifalloc mybuf; - cpl_size * pows = NULL; - cpl_polynomial_1d * self = p->tree; - cpl_polynomial_1d * transtree = NULL; + cpl_ifalloc mybuf; + cpl_size *pows = NULL; + cpl_polynomial_1d *self = p->tree; + cpl_polynomial_1d *transtree = NULL; if (i > 0) { /* Need to transpose the dimension to shift into lowest dimension */ cpl_ifalloc_set(&mybuf, (size_t)p->dim * sizeof(*pows)); - pows = (cpl_size*)cpl_ifalloc_get(&mybuf); + pows = (cpl_size *)cpl_ifalloc_get(&mybuf); transtree = cpl_polynomial_new_1d(p->tree->nc); /* Guess for size */ - cpl_polynomial_transpose_(transtree, pows + p->dim - 1, p->dim - 1, - pows, p->dim, p->tree, i); + cpl_polynomial_transpose_(transtree, p->dim - 1, pows, p->dim, + p->tree, i); self = transtree; } #ifdef CPL_POLYNOMIAL_UNION_IS_DOUBLE_SZ /* Assume no padding in a union of same sized primitive elements */ - assert((char*)&(self->coef[0].val) + (size_t)self->nc * sizeof(double) == - (char*)&(self->coef[self->nc].val)); + assert((char *)&(self->coef[0].val) + + (size_t)self->nc * sizeof(double) == + (char *)&(self->coef[self->nc].val)); #endif cpl_polynomial_shift_1d_(self, p->dim - 1, u); @@ -1641,8 +1744,8 @@ - and the reset will set all X-coefficient counters to zero, so if any remains zero, they must be pruned */ - cpl_polynomial_transpose_(p->tree, pows + p->dim - 1, p->dim - 1, - pows, p->dim, transtree, i); + cpl_polynomial_transpose_(p->tree, p->dim - 1, pows, p->dim, + transtree, i); (void)cpl_polynomial_prune_(p->tree, p->dim - 1, p->tree->nc); @@ -1668,16 +1771,17 @@ */ /*----------------------------------------------------------------------------*/ -cpl_polynomial * cpl_polynomial_fit_1d_create(const cpl_vector * x_pos, - const cpl_vector * values, - cpl_size degree, - double * pmse) +cpl_polynomial * +cpl_polynomial_fit_1d_create(const cpl_vector *x_pos, + const cpl_vector *values, + cpl_size degree, + double *pmse) { - - cpl_polynomial * self = cpl_polynomial_new(1); + cpl_polynomial *self = cpl_polynomial_new(1); const cpl_boolean is_eqdist = cpl_vector_is_eqdist(x_pos) == 1; - const cpl_error_code error = cpl_polynomial_fit_1d(self, x_pos, values, 0, - degree, is_eqdist, pmse); + const cpl_error_code error = + cpl_polynomial_fit_1d(self, x_pos, values, NULL, 0, degree, is_eqdist, + pmse); if (error != CPL_ERROR_NONE) { cpl_polynomial_delete(self); @@ -1702,46 +1806,48 @@ */ /*----------------------------------------------------------------------------*/ -cpl_polynomial * cpl_polynomial_fit_2d_create(const cpl_bivector * xy_pos, - const cpl_vector * values, - cpl_size degree, - double * pmse) -{ - cpl_polynomial * self = cpl_polynomial_new(2); - const cpl_size mindeg0 = 0; - const cpl_error_code error = cpl_polynomial_fit_2d(self, xy_pos, values, - CPL_FALSE, &mindeg0, - °ree); +cpl_polynomial * +cpl_polynomial_fit_2d_create(const cpl_bivector *xy_pos, + const cpl_vector *values, + cpl_size degree, + double *pmse) +{ + cpl_polynomial *self = cpl_polynomial_new(2); + const cpl_size mindeg0 = 0; + const cpl_error_code error = + cpl_polynomial_fit_2d(self, xy_pos, values, NULL, CPL_FALSE, &mindeg0, + °ree); if (error != CPL_ERROR_NONE) { cpl_polynomial_delete(self); self = NULL; cpl_error_set_(error); - } else if (pmse != NULL) { + } + else if (pmse != NULL) { /* Compute mean squared error */ - const cpl_size np = cpl_vector_get_size(values); - const cpl_vector * x_pos = cpl_bivector_get_x_const(xy_pos); - const cpl_vector * y_pos = cpl_bivector_get_y_const(xy_pos); - const double * dx_pos = cpl_vector_get_data_const(x_pos); - const double * dy_pos = cpl_vector_get_data_const(y_pos); - const double * dvalues = cpl_vector_get_data_const(values); - double xyval[2]; - cpl_vector * x_val = cpl_vector_wrap(2, xyval); + const cpl_size np = cpl_vector_get_size(values); + const cpl_vector *x_pos = cpl_bivector_get_x_const(xy_pos); + const cpl_vector *y_pos = cpl_bivector_get_y_const(xy_pos); + const double *dx_pos = cpl_vector_get_data_const(x_pos); + const double *dy_pos = cpl_vector_get_data_const(y_pos); + const double *dvalues = cpl_vector_get_data_const(values); + double xyval[2]; + cpl_vector *x_val = cpl_vector_wrap(2, xyval); *pmse = 0.0; for (cpl_size i = 0; i < np; i++) { - double residue; + double residual; xyval[0] = dx_pos[i]; xyval[1] = dy_pos[i]; /* Subtract from the true value, square, accumulate */ - residue = dvalues[i] - cpl_polynomial_eval(self, x_val); - *pmse += residue * residue; + residual = dvalues[i] - cpl_polynomial_eval(self, x_val); + *pmse += residual * residual; } (void)cpl_vector_unwrap(x_val); /* Average the error term */ *pmse /= (double)np; - cpl_tools_add_flops( 3 * np + 1 ); + cpl_tools_add_flops(3 * np + 1); } return self; @@ -1749,6 +1855,191 @@ /*----------------------------------------------------------------------------*/ /** + @brief Evaluate a bivariate (2D) polynomial using Horner's rule and compute + the derivatives if needed. + @param self The 2D-polynomial + @param x The x component of the evaluation point + @param y The y component of the evaluation point + @param gradient Iff gradient is non-NULL, the 2D gradient array containing + the X and Y components of the gradient vector at the evaluated point + @return The result or undefined on error. + @see cpl_polynomial_eval() + + The result is computed as p_0 + x * ( p_1 + x * ( p_2 + ... x * p_n )) + + Possible #_cpl_error_code_ set in this function: + - CPL_ERROR_NULL_INPUT if an input pointer is NULL + - CPL_ERROR_INVALID_TYPE if the polynomial is not 2D + */ +/*----------------------------------------------------------------------------*/ +double +cpl_polynomial_eval_2d(const cpl_polynomial *self, + double x, + double y, + double *gradient) +{ + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1.0); + cpl_ensure(self->dim == 2, CPL_ERROR_INVALID_TYPE, -3.0); + + double result; + cpl_size j, i; + + if (gradient != NULL) { + gradient[0] = gradient[1] = 0.0; + } + + if (self->tree == NULL || self->tree[0].nc == 0) { /* zero polynomial */ + return 0.0; + } + + result = 0.0; + if (gradient != NULL) { + j = self->tree[0].nc; + while (j--) { + double sumj = 0.0; + double sumpdj = 0.0; + const cpl_polynomial_1d *itree = self->tree[0].coef[j].next; + if (itree) { + i = itree->nc; + while (i--) { + sumj = sumj * x + itree->coef[i].val; + if (i > 0) { + sumpdj = sumpdj * x + i * itree->coef[i].val; + } + } + } + result = result * y + sumj; + gradient[0] = gradient[0] * y + sumpdj; + if (j > 0) { + gradient[1] = gradient[1] * y + j * sumj; + } + } + } + else { + j = self->tree[0].nc; + while (j--) { + double sumj = 0.0; + const cpl_polynomial_1d *itree = self->tree[0].coef[j].next; + if (itree) { + i = itree->nc; + while (i--) { + sumj = sumj * x + itree->coef[i].val; + } + } + result = result * y + sumj; + } + } + + return result; +} + +/*----------------------------------------------------------------------------*/ +/** + @brief Evaluate a 3D polynomial using Horner's rule and compute the + the derivatives if needed. + @param self The 3D-polynomial + @param x The x component of the evaluation point + @param y The y component of the evaluation point + @param z The z component of the evaluation point + @param gradient Iff gradient is non-NULL, the 3D gradient array containing + the X, Y and Z components of the gradient vector at the evaluated point + @return The result or undefined on error. + @see cpl_polynomial_eval() + + The result is computed as p_0 + x * ( p_1 + x * ( p_2 + ... x * p_n )) + + Possible #_cpl_error_code_ set in this function: + - CPL_ERROR_NULL_INPUT if an input pointer is NULL + - CPL_ERROR_INVALID_TYPE if the polynomial is not 3D + */ +/*----------------------------------------------------------------------------*/ +double +cpl_polynomial_eval_3d(const cpl_polynomial *self, + double x, + double y, + double z, + double *gradient) +{ + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1.0); + cpl_ensure(self->dim == 3, CPL_ERROR_INVALID_TYPE, -3.0); + + double result; + cpl_size k, j, i; + + if (gradient != NULL) { + gradient[0] = gradient[1] = gradient[2] = 0.0; + } + + if (self->tree == NULL || self->tree[0].nc == 0) { /* zero polynomial */ + return 0.0; + } + + result = 0.0; + if (gradient != NULL) { + k = self->tree[0].nc; + while (k--) { + double sumk = 0.0; + double sumpdkx = 0.0; + double sumpdky = 0.0; + const cpl_polynomial_1d *jtree = self->tree[0].coef[k].next; + if (jtree) { + j = jtree->nc; + while (j--) { + double sumpdjx = 0.0; + double sumj = 0.0; + const cpl_polynomial_1d *itree = jtree->coef[j].next; + if (itree) { + i = itree->nc; + while (i--) { + sumj = sumj * x + itree->coef[i].val; + if (i > 0) { + sumpdjx = sumpdjx * x + i * itree->coef[i].val; + } + } + } + sumk = sumk * y + sumj; + sumpdkx = sumpdkx * y + sumpdjx; + if (j > 0) { + sumpdky = sumpdky * y + j * sumj; + } + } + } + result = result * z + sumk; + gradient[0] = gradient[0] * z + sumpdkx; + gradient[1] = gradient[1] * z + sumpdky; + if (k > 0) { + gradient[2] = gradient[2] * z + k * sumk; + } + } + } + else { + k = self->tree[0].nc; + while (k--) { + double sumk = 0.0; + const cpl_polynomial_1d *jtree = self->tree[0].coef[k].next; + if (jtree) { + j = jtree->nc; + while (j--) { + double sumj = 0.0; + const cpl_polynomial_1d *itree = jtree->coef[j].next; + if (itree) { + i = itree->nc; + while (i--) { + sumj = sumj * x + itree->coef[i].val; + } + } + sumk = sumk * y + sumj; + } + } + result = result * z + sumk; + } + } + + return result; +} + +/*----------------------------------------------------------------------------*/ +/** @brief Add two polynomials of the same dimension @param self The polynomial to hold the result @param first The 1st polynomial to add @@ -1762,26 +2053,28 @@ dimensions */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_polynomial_add(cpl_polynomial * self, - const cpl_polynomial * first, - const cpl_polynomial * second) +cpl_error_code +cpl_polynomial_add(cpl_polynomial *self, + const cpl_polynomial *first, + const cpl_polynomial *second) { - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(first != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(first != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(second != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(cpl_polynomial_get_dimension(self) == - cpl_polynomial_get_dimension(first), + cpl_polynomial_get_dimension(first), CPL_ERROR_INCOMPATIBLE_INPUT); cpl_ensure_code(cpl_polynomial_get_dimension(self) == - cpl_polynomial_get_dimension(second), + cpl_polynomial_get_dimension(second), CPL_ERROR_INCOMPATIBLE_INPUT); if (first->tree == NULL && second->tree == NULL) { cpl_polynomial_empty(self); - } else { + } + else { if (self->tree == NULL) { - const cpl_size nfirst = first->tree ? first->tree->nc : 0; + const cpl_size nfirst = first->tree ? first->tree->nc : 0; const cpl_size nsecond = second->tree ? second->tree->nc : 0; self->tree = cpl_polynomial_new_1d(CPL_MAX(nfirst, nsecond)); @@ -1790,9 +2083,10 @@ if (cpl_polynomial_add_(self->tree, first->tree, second->tree, self->dim - 1)) { cpl_polynomial_empty(self); - } else { - self->degree = cpl_polynomial_find_degree_(self->tree, - self->dim - 1); + } + else { + self->degree = + cpl_polynomial_find_degree_(self->tree, self->dim - 1); } } @@ -1807,6 +2101,7 @@ @param second The polynomial to subtract, or NULL @return CPL_ERROR_NONE or the relevant CPL error code @note self may be passed also as first and/or second + @see cpl_polynomial_add() Possible CPL error code set in this function: - CPL_ERROR_NULL_INPUT if an input pointer is NULL @@ -1814,37 +2109,40 @@ dimensions */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_polynomial_subtract(cpl_polynomial * self, - const cpl_polynomial * first, - const cpl_polynomial * second) +cpl_error_code +cpl_polynomial_subtract(cpl_polynomial *self, + const cpl_polynomial *first, + const cpl_polynomial *second) { - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(first != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(first != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(second != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(cpl_polynomial_get_dimension(self) == - cpl_polynomial_get_dimension(first), + cpl_polynomial_get_dimension(first), CPL_ERROR_INCOMPATIBLE_INPUT); cpl_ensure_code(cpl_polynomial_get_dimension(self) == - cpl_polynomial_get_dimension(second), + cpl_polynomial_get_dimension(second), CPL_ERROR_INCOMPATIBLE_INPUT); if (first->tree == NULL && second->tree == NULL) { cpl_polynomial_empty(self); - } else { + } + else { if (self->tree == NULL) { - const cpl_size nfirst = first->tree ? first->tree->nc : 0; + const cpl_size nfirst = first->tree ? first->tree->nc : 0; const cpl_size nsecond = second->tree ? second->tree->nc : 0; self->tree = cpl_polynomial_new_1d(CPL_MAX(nfirst, nsecond)); } - if (cpl_polynomial_subtract_(self->tree, first->tree, - second->tree, self->dim - 1)) { + if (cpl_polynomial_subtract_(self->tree, first->tree, second->tree, + self->dim - 1)) { cpl_polynomial_empty(self); - } else { - self->degree = cpl_polynomial_find_degree_(self->tree, - self->dim - 1); + } + else { + self->degree = + cpl_polynomial_find_degree_(self->tree, self->dim - 1); } } @@ -1867,28 +2165,30 @@ dimensions */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_polynomial_multiply(cpl_polynomial * self, - const cpl_polynomial * first, - const cpl_polynomial * second) +cpl_error_code +cpl_polynomial_multiply(cpl_polynomial *self, + const cpl_polynomial *first, + const cpl_polynomial *second) { - cpl_polynomial * original = self; - cpl_polynomial * result = NULL; + cpl_polynomial *original = self; + cpl_polynomial *result = NULL; - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(first != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(first != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(second != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(cpl_polynomial_get_dimension(self) == - cpl_polynomial_get_dimension(first), + cpl_polynomial_get_dimension(first), CPL_ERROR_INCOMPATIBLE_INPUT); cpl_ensure_code(cpl_polynomial_get_dimension(self) == - cpl_polynomial_get_dimension(second), + cpl_polynomial_get_dimension(second), CPL_ERROR_INCOMPATIBLE_INPUT); if (self == first || self == second) { /* For an inplace multiplication, we need some temporary storage */ self = result = cpl_polynomial_new(cpl_polynomial_get_dimension(self)); - } else { + } + else { cpl_polynomial_empty(self); } @@ -1896,29 +2196,28 @@ Both first and second must be non-empty for that to change */ if (first->tree != NULL && second->tree != NULL) { - cpl_size* pows = cpl_malloc((size_t)self->dim * sizeof(*pows)); + cpl_size *pows = cpl_malloc((size_t)self->dim * sizeof(*pows)); if (self->tree == NULL) { assert(first->tree->nc + second->tree->nc > 0); - self->tree = cpl_polynomial_new_1d(first->tree->nc + - second->tree->nc); + self->tree = + cpl_polynomial_new_1d(first->tree->nc + second->tree->nc); } cpl_polynomial_multiply_(self->tree, first->tree, second->tree, - pows + self->dim - 1, self->dim - 1, - pows, self->dim); + self->dim - 1, pows, self->dim); cpl_free(pows); self->degree = cpl_polynomial_find_degree_(self->tree, self->dim - 1); } if (result != NULL) { - void * swap = cpl_malloc(sizeof(cpl_polynomial)); + void *swap = cpl_malloc(sizeof(cpl_polynomial)); assert(original != self); - memcpy(swap, self, sizeof(cpl_polynomial)); + memcpy(swap, self, sizeof(cpl_polynomial)); memcpy(self, original, sizeof(cpl_polynomial)); memcpy(original, swap, sizeof(cpl_polynomial)); @@ -1944,23 +2243,24 @@ - CPL_ERROR_INCOMPATIBLE_INPUT if the two dimensions do not match */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_polynomial_multiply_scalar(cpl_polynomial * self, - const cpl_polynomial * other, - double factor) +cpl_error_code +cpl_polynomial_multiply_scalar(cpl_polynomial *self, + const cpl_polynomial *other, + double factor) { - - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(other != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(cpl_polynomial_get_dimension(self) == - cpl_polynomial_get_dimension(other), + cpl_polynomial_get_dimension(other), CPL_ERROR_INCOMPATIBLE_INPUT); if (factor != 0.0 && other->tree != NULL) { if (self == other) { - cpl_polynomial_multiply_scalar_self(self->tree, - self->dim - 1, factor); - } else { + cpl_polynomial_multiply_scalar_self(self->tree, self->dim - 1, + factor); + } + else { if (self->tree == NULL) self->tree = cpl_polynomial_new_1d(other->tree->nc); @@ -1968,15 +2268,14 @@ self->dim - 1, factor); self->degree = other->degree; } - } else { + } + else { cpl_polynomial_empty(self); } return CPL_ERROR_NONE; } -/**@}*/ - /*----------------------------------------------------------------------------*/ /** @internal @@ -1988,13 +2287,254 @@ */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_polynomial_get_1d_size(const cpl_polynomial * self) +cpl_size +cpl_polynomial_get_1d_size(const cpl_polynomial *self) { - return - (char*)&(self->tree->coef[self->tree->nc].val) - - (char*)&(self->tree->coef[0 ].val); + return (char *)&(self->tree->coef[self->tree->nc].val) - + (char *)&(self->tree->coef[0].val); } +// /*----------------------------------------------------------------------------*/ +// /** +// @internal +// @brief Fit a 1D-polynomial to a 1D-signal in a least squares sense +// @param self 1D-polynomial to hold the fit +// @param x_pos Vector of positions of the signal to fit. +// @param values Vector of values of the signal to fit. +// @param mindeg The non-negative minimum fitting degree +// @param degree The polynomial fitting degree, at least mindeg +// @param symsamp True iff the x_pos values are symmetric around their mean +// @param pmse Iff pmse is not null, the mean squared error on success +// @return The fitted polynomial or NULL on error +// @see cpl_polynomial_fit() + +// symsamp is ignored if mindeg is nonzero, otherwise +// symsamp may to be set to CPL_TRUE if and only if the values in x_pos are +// known a-priori to be symmetric around their mean, e.g. (1, 2, 4, 6, 10, +// 14, 16, 18, 19), but not (1, 2, 4, 6, 10, 14, 16). Setting symsamp to +// CPL_TRUE while mindeg is zero eliminates certain round-off errors. +// For higher order fitting the fitting problem known as "Runge's phenomenon" +// is minimized using the socalled "Chebyshev nodes" as sampling points. +// For Chebyshev nodes symsamp can be set to CPL_TRUE. + +// */ +// /*----------------------------------------------------------------------------*/ +// cpl_error_code cpl_polynomial_fit_1d(cpl_polynomial * self, +// const cpl_vector * x_pos, +// const cpl_vector * values, +// cpl_size mindeg, cpl_size degree, +// cpl_boolean symsamp, double * pmse) +// { + +// /* Number of unknowns to determine */ +// const cpl_size nc = 1 + degree - mindeg; +// const cpl_size np = cpl_vector_get_size(x_pos); +// double mean; +// double delta, xval; +// cpl_vector * xhat; +// const cpl_vector * xuse; +// cpl_matrix * mh; /* Hankel matrix */ +// cpl_matrix * mx; +// double * dx; +// cpl_size i, j; +// cpl_error_code error; + + +// cpl_ensure_code(np > 0, cpl_error_get_code()); +// cpl_ensure_code(values, CPL_ERROR_NULL_INPUT); + +// cpl_ensure_code(cpl_vector_get_size_(values) == np, +// CPL_ERROR_INCOMPATIBLE_INPUT); + +// cpl_ensure_code(mindeg >= 0, CPL_ERROR_ILLEGAL_INPUT); +// cpl_ensure_code(degree >= mindeg, CPL_ERROR_ILLEGAL_INPUT); + +// cpl_ensure_code(cpl_polynomial_get_dimension(self) == 1, +// CPL_ERROR_INCOMPATIBLE_INPUT); + +// symsamp = symsamp && (mindeg == 0); /* symsamp not usable with mindeg > 0 */ + +// if (self->tree != NULL) { +// /* Reset coefficients */ +// cpl_polynomial_reset_(self->tree, self->dim - 1); +// self->degree = 0; + +// /* When a coefficient is set with cpl_polynomial_set_coeff(), +// the tree is set properly, or deallocated */ +// } + +// if (degree == mindeg) { +// /* Handle this one-coefficient polynomial as a special case */ + +// if (degree == 0) { +// /* Handle this zero-degree polynomial as a special case */ + +// /* If requested, compute mean squared error */ +// if (pmse != NULL) *pmse = +// cpl_tools_get_variance_double(cpl_vector_get_data_const_(values), +// np, &mean); +// else +// mean = cpl_vector_get_mean(values); + +// } else { +// /* A polynomial with just one coefficient and a positive degree +// is requested. The coefficient must therefore be non-zero. */ + +// /* Raise values to the power of mindeg */ +// const double * xpos = cpl_vector_get_data_const_(x_pos); +// const double * dval = cpl_vector_get_data_const_(values); +// double h = 0.0; /* Hankel = Transpose(Vandermonde) * Vandermonde */ +// double vtv = 0.0; /* Transpose(Vandermonde) * values */ + +// for (i=0; i < np; i++) { +// const double xn = cpl_tools_ipow(xpos[i], (int)mindeg); + +// vtv += xn * dval[i]; +// h += xn * xn; +// } + +// if (h > 0.0) { +// mean = vtv / h; +// } else { +// cpl_polynomial_empty(self); +// return cpl_error_set_message_(CPL_ERROR_DIVISION_BY_ZERO, +// "mindeg=%" CPL_SIZE_FORMAT ". " +// "degree=%" CPL_SIZE_FORMAT ". " +// "nc=%" CPL_SIZE_FORMAT ". " +// "np=%" CPL_SIZE_FORMAT ". " +// "Coeff = %g / %g", +// mindeg, degree, +// nc, np, vtv, h); +// } +// } +// /* Should not be able to fail now, nevertheless propagate */ +// return cpl_error_set_(cpl_polynomial_set_coeff(self, °ree, mean)); +// } +// cpl_ensure_code(np >= nc, CPL_ERROR_DATA_NOT_FOUND); + +// /* The Hankel matrix may be singular in such a fashion, that the pivot +// points in its Cholesky decomposition are positive due to rounding errors. +// To ensure that such singular systems are robustly detected, the number of +// distinct sampling points is counted. +// */ + +// cpl_ensure_code(!cpl_vector_ensure_distinct(x_pos, nc), +// CPL_ERROR_SINGULAR_MATRIX); + +// /* Try to detect if the x-points are equidistant +// - in which every other skew diagonal of the Hankel matrix is zero */ +// xval = cpl_vector_get(x_pos, 1); +// delta = xval - cpl_vector_get(x_pos, 0); +// for (i=1; i < np-1; i++) { +// const double dprev = delta; +// const double xprev = xval; + +// xval = cpl_vector_get_(x_pos, i+1); +// delta = xval - xprev; +// if (delta != dprev) break; +// } + +// if (mindeg == 0) { +// /* Transform: xhat = x - mean(x) */ +// xhat = cpl_vector_transform_mean(x_pos, &mean); +// xuse = xhat; +// } else { +// mean = 0.0; +// xhat = NULL; +// xuse = x_pos; +// } + +// assert( xuse != NULL ); + +// /* Generate Hankel matrix, H = V' * V, where V is the Vandermonde matrix */ +// /* FIXME: It is faster and likely more accurate to compute the QR +// factorization of the Vandermonde matrix, QR = V, see +// C.J. Demeure: Fast QR Factorization of Vandermonde Matrices */ + +// /* mh is initialized only if xuse is not equidistant */ +// mh = symsamp ? cpl_matrix_new(nc, nc) : +// cpl_matrix_wrap(nc, nc, cpl_malloc((size_t)(nc * nc) * sizeof(double))); +// dx = (double*)cpl_malloc((size_t)(nc * 1) * sizeof(*dx)); +// mx = cpl_matrix_wrap(nc, 1, dx); + +// cpl_matrix_fill_normal_vandermonde(mh, mx, xuse, symsamp, mindeg, values, NULL); +// #ifdef CPL_POLYNOMIAL_FIT_DEBUG +// cpl_msg_warning(cpl_func, "MINDEG=%" CPL_SIZE_FORMAT ". degree=%" +// CPL_SIZE_FORMAT ". nc=%" CPL_SIZE_FORMAT ". np=%" +// CPL_SIZE_FORMAT ". mean=%g", mindeg, degree, nc, np, mean); +// cpl_matrix_dump(mh, stdout); +// cpl_matrix_dump(mx, stdout); +// #endif + +// cpl_vector_delete(xhat); + +// error = cpl_matrix_solve_spd(mh, mx); + +// cpl_matrix_delete(mh); + +// if (error) { +// cpl_matrix_delete(mx); +// cpl_polynomial_empty(self); +// return cpl_error_set_message_(error, "mindeg=%" CPL_SIZE_FORMAT +// ". degree=%" CPL_SIZE_FORMAT ". nc=%" +// CPL_SIZE_FORMAT ". np=%" CPL_SIZE_FORMAT +// ". mean=%g", mindeg, degree, nc, np, +// mean); +// } + + +// /* Scale back - and store coefficients - with leading coefficient first, +// see doxygen of cpl_polynomial_set_coeff() */ +// /* - make sure there is enough space, then fill up from below */ +// if (self->tree == NULL) { +// self->tree = cpl_polynomial_new_1d(mindeg + nc); +// } else { +// cpl_polynomial_grow_1d(self->tree, mindeg + nc); +// } +// for (j = 0; j < nc; j++) { +// if (dx[j] != 0.0) { +// /* Since the tree may be a zero-polynomial, +// deleting a coefficient (and determining the new +// degree) can cause an assert() to fail */ + +// const cpl_size k = j + mindeg; + +// cpl_polynomial_set_coeff(self, &k, dx[j]); +// } +// } + +// if (self->tree->nc == 0) { +// /* All fitted coefficients are zero */ +// cpl_polynomial_empty(self); +// } + +// cpl_matrix_delete(mx); + +// if (mindeg == 0) { +// /* Shift back */ +// cpl_polynomial_shift_1d(self, 0, -mean); +// } + +// /* If requested, compute mean squared error */ +// if (pmse != NULL) { +// const double * xpos = cpl_vector_get_data_const_(x_pos); +// const double * dval = cpl_vector_get_data_const_(values); +// *pmse = 0.0; +// for (i = 0; i < np; i++) { +// /* Subtract from the true value, square, accumulate */ +// const double residue = dval[i] +// - cpl_polynomial_eval_1d(self, xpos[i], NULL); +// *pmse += residue * residue; +// } +// /* Average the error term */ +// *pmse /= (double)np; + +// cpl_tools_add_flops( 3 * np + 1 ); +// } + +// return CPL_ERROR_NONE; +// } + /*----------------------------------------------------------------------------*/ /** @internal @@ -2002,6 +2542,7 @@ @param self 1D-polynomial to hold the fit @param x_pos Vector of positions of the signal to fit. @param values Vector of values of the signal to fit. + @param sigmas Vector of uncertainties of the sampled values, or NULL for all ones. @param mindeg The non-negative minimum fitting degree @param degree The polynomial fitting degree, at least mindeg @param symsamp True iff the x_pos values are symmetric around their mean @@ -2020,39 +2561,49 @@ */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_polynomial_fit_1d(cpl_polynomial * self, - const cpl_vector * x_pos, - const cpl_vector * values, - cpl_size mindeg, cpl_size degree, - cpl_boolean symsamp, double * pmse) +cpl_error_code +cpl_polynomial_fit_1d(cpl_polynomial *self, + const cpl_vector *x_pos, + const cpl_vector *values, + const cpl_vector *sigmas, + cpl_size mindeg, + cpl_size degree, + cpl_boolean symsamp, + double *pmse) { - /* Number of unknowns to determine */ - const cpl_size nc = 1 + degree - mindeg; - const cpl_size np = cpl_vector_get_size(x_pos); - double mean; - double delta, xval; - cpl_vector * xhat; - const cpl_vector * xuse; - cpl_matrix * mh; /* Hankel matrix */ - cpl_matrix * mx; - double * dx; - cpl_size i, j; - cpl_error_code error; + const cpl_size nc = 1 + degree - mindeg; + const cpl_size np = cpl_vector_get_size(x_pos); + double mean; + double delta, xval; + cpl_vector *xhat; + const cpl_vector *xuse; + cpl_matrix *mh; /* Hankel matrix */ + cpl_matrix *mx; + double *dx; + cpl_size i, j; + cpl_error_code error; - cpl_ensure_code(np > 0, cpl_error_get_code()); - cpl_ensure_code(values, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(np > 0, cpl_error_get_code()); + cpl_ensure_code(values, CPL_ERROR_NULL_INPUT); cpl_ensure_code(cpl_vector_get_size_(values) == np, CPL_ERROR_INCOMPATIBLE_INPUT); - cpl_ensure_code(mindeg >= 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(mindeg >= 0, CPL_ERROR_ILLEGAL_INPUT); cpl_ensure_code(degree >= mindeg, CPL_ERROR_ILLEGAL_INPUT); cpl_ensure_code(cpl_polynomial_get_dimension(self) == 1, CPL_ERROR_INCOMPATIBLE_INPUT); + if (sigmas != NULL) { /* Check sigma errors */ + const double *sval = cpl_vector_get_data_const_(sigmas); + for (i = 0; i < np; ++i) { + cpl_ensure_code(sval[i] != 0.0, CPL_ERROR_DIVISION_BY_ZERO); + } + } + symsamp = symsamp && (mindeg == 0); /* symsamp not usable with mindeg > 0 */ if (self->tree != NULL) { @@ -2070,48 +2621,91 @@ if (degree == 0) { /* Handle this zero-degree polynomial as a special case */ - /* If requested, compute mean squared error */ - if (pmse != NULL) *pmse = - cpl_tools_get_variance_double(cpl_vector_get_data_const_(values), - np, &mean); - else - mean = cpl_vector_get_mean(values); + if (sigmas != NULL) { + const double *dval = cpl_vector_get_data_const_(values); + const double *sval = cpl_vector_get_data_const_(sigmas); + double sum = 0.0; /* sum of squared weighted values */ + double wsum = 0.0; /* sum of the squared weights */ + + /* Compute the squared weighted mean */ + for (i = 0; i < np; ++i) { + const double w = 1.0 / (sval[i] * sval[i]); + wsum += w * w; + sum += dval[i] * w * w; + } + mean = sum / wsum; - } else { + /* If requested, compute mean squared error */ + /* In the case of a weighted fit, the default definition + of the MSE still applied. + MSE=sum((x - p(x))^2)/N => MSE=sum((x - wmean)^2)/N */ + if (pmse != NULL) { + *pmse = 0.0; + for (i = 0; i < np; i++) { + /* Subtract from the true value, square, accumulate */ + double residual = dval[i] - mean; + *pmse += residual * residual; + } + /* Average the error term */ + *pmse /= (double)np; + } + } + else { + /* If requested, compute mean squared error */ + if (pmse != NULL) + *pmse = cpl_tools_get_variance_double( + cpl_vector_get_data_const_(values), np, &mean); + else + mean = cpl_vector_get_mean(values); + } + } + else { /* A polynomial with just one coefficient and a positive degree is requested. The coefficient must therefore be non-zero. */ /* Raise values to the power of mindeg */ - const double * xpos = cpl_vector_get_data_const_(x_pos); - const double * dval = cpl_vector_get_data_const_(values); - double h = 0.0; /* Hankel = Transpose(Vandermonde) * Vandermonde */ - double vtv = 0.0; /* Transpose(Vandermonde) * values */ - - for (i=0; i < np; i++) { - const double xn = cpl_tools_ipow(xpos[i], (int)mindeg); - - vtv += xn * dval[i]; - h += xn * xn; + const double *xpos = cpl_vector_get_data_const_(x_pos); + const double *dval = cpl_vector_get_data_const_(values); + double h = + 0.0; /* Hankel = Transpose(W * Vandermonde) * (W * Vandermonde) */ + double vtv = 0.0; /* Transpose(W * Vandermonde) * (W * values) */ + + if (sigmas != NULL) { + const double *sval = cpl_vector_get_data_const_(sigmas); + for (i = 0; i < np; i++) { + const double xn = cpl_tools_ipow(xpos[i], (int)mindeg); + const double w = 1.0 / (sval[i] * sval[i]); + vtv += xn * dval[i] * w * w; + h += xn * xn * w * w; + } + } + else { + /* Sigma vector is filled with one (no need to apply weights) */ + for (i = 0; i < np; i++) { + const double xn = cpl_tools_ipow(xpos[i], (int)mindeg); + vtv += xn * dval[i]; + h += xn * xn; + } } if (h > 0.0) { mean = vtv / h; - } else { + } + else { cpl_polynomial_empty(self); return cpl_error_set_message_(CPL_ERROR_DIVISION_BY_ZERO, - "mindeg=%" CPL_SIZE_FORMAT ". " + "mindeg=%" CPL_SIZE_FORMAT ". " "degree=%" CPL_SIZE_FORMAT ". " "nc=%" CPL_SIZE_FORMAT ". " "np=%" CPL_SIZE_FORMAT ". " "Coeff = %g / %g", - mindeg, degree, - nc, np, vtv, h); + mindeg, degree, nc, np, vtv, h); } } /* Should not be able to fail now, nevertheless propagate */ return cpl_error_set_(cpl_polynomial_set_coeff(self, °ree, mean)); } - cpl_ensure_code(np >= nc, CPL_ERROR_DATA_NOT_FOUND); + cpl_ensure_code(np >= nc, CPL_ERROR_DATA_NOT_FOUND); /* The Hankel matrix may be singular in such a fashion, that the pivot points in its Cholesky decomposition are positive due to rounding errors. @@ -2120,55 +2714,432 @@ */ cpl_ensure_code(!cpl_vector_ensure_distinct(x_pos, nc), - CPL_ERROR_SINGULAR_MATRIX); + CPL_ERROR_SINGULAR_MATRIX); /* Try to detect if the x-points are equidistant - in which every other skew diagonal of the Hankel matrix is zero */ xval = cpl_vector_get(x_pos, 1); delta = xval - cpl_vector_get(x_pos, 0); - for (i=1; i < np-1; i++) { + for (i = 1; i < np - 1; i++) { const double dprev = delta; const double xprev = xval; - xval = cpl_vector_get_(x_pos, i+1); + xval = cpl_vector_get_(x_pos, i + 1); delta = xval - xprev; - if (delta != dprev) break; + if (delta != dprev) + break; } if (mindeg == 0) { - /* Transform: xhat = x - mean(x) */ - xhat = cpl_vector_transform_mean(x_pos, &mean); - xuse = xhat; - } else { + if (sigmas != NULL) { + /* Weights must be taken in account */ + /* Transform: xhat = x - wmean(x) */ + xhat = cpl_vector_duplicate(x_pos); + const double *dval = cpl_vector_get_data_const_(xhat); + const double *sval = cpl_vector_get_data_const_(sigmas); + double sum = 0.0; + double wsum = 0.0; + for (i = 0; i < np; i++) { + double w = 1.0 / (sval[i] * sval[i]); + sum += dval[i] * w * w; + wsum += w * w; + } + mean = sum / wsum; + cpl_vector_subtract_scalar(xhat, mean); + xuse = xhat; + } + else { + /* Transform: xhat = x - mean(x) */ + xhat = cpl_vector_transform_mean(x_pos, &mean); + xuse = xhat; + } + } + else { mean = 0.0; xhat = NULL; xuse = x_pos; } - assert( xuse != NULL ); + assert(xuse != NULL); /* Generate Hankel matrix, H = V' * V, where V is the Vandermonde matrix */ + /* If we apply the weights we have H = (W * V') * (W * V) */ /* FIXME: It is faster and likely more accurate to compute the QR factorization of the Vandermonde matrix, QR = V, see C.J. Demeure: Fast QR Factorization of Vandermonde Matrices */ /* mh is initialized only if xuse is not equidistant */ - mh = symsamp ? cpl_matrix_new(nc, nc) : - cpl_matrix_wrap(nc, nc, cpl_malloc((size_t)(nc * nc) * sizeof(double))); - dx = (double*)cpl_malloc((size_t)(nc * 1) * sizeof(*dx)); + mh = symsamp + ? cpl_matrix_new(nc, nc) + : cpl_matrix_wrap(nc, nc, + cpl_malloc((size_t)(nc * nc) * sizeof(double))); + dx = (double *)cpl_malloc((size_t)(nc * 1) * sizeof(*dx)); mx = cpl_matrix_wrap(nc, 1, dx); - cpl_matrix_fill_normal_vandermonde(mh, mx, xuse, symsamp, mindeg, values); -#ifdef CPL_POLYNOMIAL_FIT_DEBUG - cpl_msg_warning(cpl_func, "MINDEG=%" CPL_SIZE_FORMAT ". degree=%" - CPL_SIZE_FORMAT ". nc=%" CPL_SIZE_FORMAT ". np=%" - CPL_SIZE_FORMAT ". mean=%g", mindeg, degree, nc, np, mean); - cpl_matrix_dump(mh, stdout); - cpl_matrix_dump(mx, stdout); -#endif + cpl_matrix_fill_normal_vandermonde(mh, mx, xuse, symsamp, mindeg, values, + sigmas); + +#ifdef CPL_POLYNOMIAL_FIT_DEBUG + cpl_msg_warning(cpl_func, + "MINDEG=%" CPL_SIZE_FORMAT ". degree=%" CPL_SIZE_FORMAT + ". nc=%" CPL_SIZE_FORMAT ". np=%" CPL_SIZE_FORMAT + ". mean=%g", + mindeg, degree, nc, np, mean); + cpl_matrix_dump(mh, stdout); + cpl_matrix_dump(mx, stdout); +#endif + + cpl_vector_delete(xhat); + + error = cpl_matrix_solve_spd(mh, mx); + + cpl_matrix_delete(mh); + + if (error) { + cpl_matrix_delete(mx); + cpl_polynomial_empty(self); + return cpl_error_set_message_(error, + "mindeg=%" CPL_SIZE_FORMAT + ". degree=%" CPL_SIZE_FORMAT + ". nc=%" CPL_SIZE_FORMAT + ". np=%" CPL_SIZE_FORMAT ". mean=%g", + mindeg, degree, nc, np, mean); + } + + + /* Scale back - and store coefficients - with leading coefficient first, + see doxygen of cpl_polynomial_set_coeff() */ + /* - make sure there is enough space, then fill up from below */ + if (self->tree == NULL) { + self->tree = cpl_polynomial_new_1d(mindeg + nc); + } + else { + cpl_polynomial_grow_1d(self->tree, mindeg + nc); + } + for (j = 0; j < nc; j++) { + if (dx[j] != 0.0) { + /* Since the tree may be a zero-polynomial, + deleting a coefficient (and determining the new + degree) can cause an assert() to fail */ + + const cpl_size k = j + mindeg; + + cpl_polynomial_set_coeff(self, &k, dx[j]); + } + } + + if (self->tree->nc == 0) { + /* All fitted coefficients are zero */ + cpl_polynomial_empty(self); + } + + cpl_matrix_delete(mx); + + if (mindeg == 0) { + /* Shift back */ + cpl_polynomial_shift_1d(self, 0, -mean); + } + + /* If requested, compute mean squared error */ + /* In the case of a weighted fit, the default definition + of the MSE still applied. + MSE=sum((x - p(x))^2)/N => MSE=sum((x - wmean)^2)/N */ + if (pmse != NULL) { + const double *xpos = cpl_vector_get_data_const_(x_pos); + const double *dval = cpl_vector_get_data_const_(values); + *pmse = 0.0; + for (i = 0; i < np; i++) { + /* Subtract from the true value, square, accumulate */ + const double residual = + dval[i] - cpl_polynomial_eval_1d(self, xpos[i], NULL); + *pmse += residual * residual; + } + /* Average the error term */ + *pmse /= (double)np; + + cpl_tools_add_flops(3 * np + 1); + } + + return CPL_ERROR_NONE; +} + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief Fit a 2D-polynomial to a 2D-surface in a least squares sense + @param xy_pos Bivector positions of the surface to fit. + @param values Vector of values of the surface to fit. + @param sigmas Vector of uncertainties of the sampled values, or NULL for all ones. + @param dimdeg True iff there is a fitting degree per dimension + @param mindeg Pointer to 1 or d minimum fitting degree(s), at least 0 + @param maxdeg Pointer to 1 or d maximum fitting degree(s), at least mindeg + @return The fitted polynomial or NULL on error + @see cpl_polynomial_fit() + */ +/*----------------------------------------------------------------------------*/ +static cpl_error_code +cpl_polynomial_fit_2d(cpl_polynomial *self, + const cpl_bivector *xy_pos, + const cpl_vector *values, + const cpl_vector *sigmas, + cpl_boolean dimdeg, + const cpl_size *mindeg, + const cpl_size *maxdeg) +{ + const cpl_size np = cpl_bivector_get_size(xy_pos); + cpl_size degree; /* The degree of the fitted polynomial */ + cpl_boolean is_mindeg = CPL_FALSE; /* Whether mindeg is non-zero */ + cpl_size nc; /* Number of unknowns to determine */ + cpl_size ncy; /* Number of Y-coefficients (incl. mindeg ones) */ + cpl_matrix *mv; /* The transpose of the Vandermonde matrix */ + cpl_matrix *mh; /* Block-Hankel matrix, (W * V') * (W * V) */ + cpl_matrix *mb; + cpl_matrix *mx; + const double *coeffs1d; + double *dmv; + cpl_vector *xhat; + cpl_vector *yhat; + cpl_vector *wvalues; + const cpl_vector *xuse; + const cpl_vector *yuse; + const double *dxuse; + const double *dyuse; + const double *sval; + double xmean; + double ymean; + double wsum; + cpl_size powers[2]; + cpl_size degx, degy; + cpl_size i, j; + cpl_boolean do_prune = CPL_FALSE; + cpl_error_code error; + + + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(cpl_polynomial_get_dimension(self) == 2, + CPL_ERROR_INVALID_TYPE); + cpl_ensure_code(np > 0, cpl_error_get_code()); + cpl_ensure_code(values != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(maxdeg != NULL, CPL_ERROR_NULL_INPUT); + + cpl_ensure_code(cpl_vector_get_size_(values) == np, + CPL_ERROR_INCOMPATIBLE_INPUT); + + if (sigmas != NULL) { /* Check sigma errors */ + sval = cpl_vector_get_data_const_(sigmas); + for (i = 0; i < np; ++i) { + cpl_ensure_code(sval[i] != 0.0, CPL_ERROR_DIVISION_BY_ZERO); + } + } + else { + sval = NULL; + } + + cpl_ensure_code(mindeg[0] >= 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(maxdeg[0] >= mindeg[0], CPL_ERROR_ILLEGAL_INPUT); + + if (dimdeg) { + cpl_ensure_code(mindeg[1] >= 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(maxdeg[1] >= mindeg[1], CPL_ERROR_ILLEGAL_INPUT); + + if (mindeg[0] > 0 || mindeg[1] > 0) + is_mindeg = CPL_TRUE; + + degree = maxdeg[0] + maxdeg[1]; + ncy = maxdeg[1] + 1; + nc = (maxdeg[0] + 1 - mindeg[0]) * (ncy - mindeg[1]); + } + else { + const cpl_size nc0 = mindeg[0] * (mindeg[0] + 1) / 2; + + degree = maxdeg[0]; + ncy = degree + 1; + nc = ncy * (maxdeg[0] + 2) / 2 - nc0; + + if (mindeg[0] > 0) + is_mindeg = CPL_TRUE; + } + + if (np < nc) { + return cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, + "Too few data " + "points %d < %d for %d-degree 2D-fit " + "(dimdeg=%d, mindeg=%d)", + (int)np, (int)nc, (int)degree, + (int)dimdeg, (int)mindeg[0]); + } + + if (self->tree != NULL) { + /* Reset coefficients, keeping allocations. + Pruning or emptying needed before return! */ + cpl_polynomial_reset_(self->tree, self->dim - 1); + self->degree = 0; + do_prune = CPL_TRUE; + } + + /* If the fit use sigmas, the solved matrix equation is + (W*V)t*(W*V)*x = (W*V)t*(W*y) where W is the diagonal weighted matrix. We can see + that the (W*V)t is common in both member. The weights can therefore be multiplied + direclty in the construction of the transposed Vandermonde matrix. We also must + multiply the values (y) by the weights. + https://www.cs.auckland.ac.nz/courses/compsci369s1c/lectures/GG-notes/CS369-LeastSquares.pdf (slide 36) + https://en.wikipedia.org/wiki/Weighted_least_squares */ + + /* Apply the weights to the values (W*y) */ + if (sigmas != NULL) { + wvalues = cpl_vector_duplicate(values); + double *dval = cpl_vector_get_data_(wvalues); + for (i = 0; i < np; i++) { + const double w = 1.0 / (sval[i] * sval[i]); + dval[i] *= w; + } + } + else { + wvalues = (cpl_vector *)values; + } + + if (degree == 0) { + /* Handle this as a special case */ + + assert(nc == 1); + + if (sigmas != NULL) { + /* Compute the squared weighted mean */ + const double *dval = cpl_vector_get_data_const_(values); + wsum = 0.0; + double sum = 0.0; + for (i = 0; i < np; ++i) { + const double w = 1.0 / (sval[i] * sval[i]); + wsum += w * w; + sum += dval[i] * w * w; + } + xmean = sum / wsum; + } + else { + xmean = cpl_vector_get_mean(values); + } + + if (xmean != 0.0) { + powers[0] = powers[1] = 0; + + (void)cpl_polynomial_set_coeff(self, powers, xmean); + + assert(self->tree != NULL); + + if (do_prune) + cpl_polynomial_prune_(self->tree, self->dim - 1, nc); + + assert(self->tree->nc == 1); + } + else { + cpl_polynomial_empty(self); + } + + if (sigmas != NULL) { + cpl_vector_delete(wvalues); + } + + return CPL_ERROR_NONE; + } + + if (is_mindeg) { + xmean = ymean = 0.0; + xhat = yhat = NULL; + xuse = cpl_bivector_get_x_const(xy_pos); + yuse = cpl_bivector_get_y_const(xy_pos); + } + else { + if (sigmas != NULL) { + /* Weights must be taken in account */ + /* Transform: xhat = x - wmean(x) */ + /* Transform: yhat = y - wmean(y) */ + double xsum, ysum; + xhat = cpl_vector_duplicate(cpl_bivector_get_x_const(xy_pos)); + yhat = cpl_vector_duplicate(cpl_bivector_get_y_const(xy_pos)); + const double *xdval = cpl_vector_get_data_const(xhat); + const double *ydval = cpl_vector_get_data_const(yhat); + xsum = ysum = wsum = 0.0; + for (i = 0; i < np; i++) { + double w = 1.0 / (sval[i] * sval[i]); + xsum += xdval[i] * w * w; + ysum += ydval[i] * w * w; + wsum += w * w; + } + xmean = xsum / wsum; + ymean = ysum / wsum; + cpl_vector_subtract_scalar(xhat, xmean); + cpl_vector_subtract_scalar(yhat, ymean); + xuse = xhat; + yuse = yhat; + } + else { + /* Transform: xhat = x - mean(x) */ + xhat = cpl_vector_transform_mean(cpl_bivector_get_x_const(xy_pos), + &xmean); + assert(xhat != NULL); + xuse = xhat; + + /* Transform: yhat = y - mean(y) */ + yhat = cpl_vector_transform_mean(cpl_bivector_get_y_const(xy_pos), + &ymean); + assert(yhat != NULL); + yuse = yhat; + } + } + + dxuse = cpl_vector_get_data_const_(xuse); + dyuse = cpl_vector_get_data_const_(yuse); + + /* Initialize matrices */ + /* mv contains the polynomial terms in the order described */ + /* above in each row, for each input point. */ + dmv = (double *)cpl_malloc((size_t)(nc * np) * sizeof(*dmv)); + mv = cpl_matrix_wrap(nc, np, dmv); + + /* Has redundant FLOPs, appears to improve accuracy. */ + /* If weights are used, the factors are applied to the values */ + for (i = 0; i < np; i++) { + const double x = dxuse[i]; + const double y = dyuse[i]; + double yvalue = 1.0; + j = 0; + for (degy = 0; degy < ncy; degy++) { + const cpl_size ncx = 1 + (dimdeg ? maxdeg[0] : degree - degy); + double xvalue = 1.0; + for (degx = 0; degx < ncx; degx++) { + if (dimdeg ? (degx >= mindeg[0] && degy >= mindeg[1]) + : degx + degy >= mindeg[0]) { + /* multiplied weights if needed */ + dmv[np * j++ + i] = + sval ? (xvalue * yvalue) / (sval[i] * sval[i]) + : xvalue * yvalue; + } + xvalue *= x; + } + yvalue *= y; + } + assert(j == nc); + } + cpl_tools_add_flops(np * (nc * 2 + ncy)); + + cpl_vector_delete(xhat); + cpl_vector_delete(yhat); + + /* mb contains the values, it is weighted */ + CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); + mb = cpl_matrix_wrap(np, 1, cpl_vector_get_data_(wvalues)); + CPL_DIAG_PRAGMA_POP; + + /* Form the right hand side of the normal equations */ + mx = cpl_matrix_product_create(mv, mb); + + (void)cpl_matrix_unwrap(mb); - cpl_vector_delete(xhat); + /* Form the matrix of the normal equations */ + mh = cpl_matrix_product_normal_create(mv); + cpl_matrix_delete(mv); + /* Solve XA=B by a least-square solution (aka pseudo-inverse). */ error = cpl_matrix_solve_spd(mh, mx); cpl_matrix_delete(mh); @@ -2176,61 +3147,69 @@ if (error) { cpl_matrix_delete(mx); cpl_polynomial_empty(self); - return cpl_error_set_message_(error, "mindeg=%" CPL_SIZE_FORMAT - ". degree=%" CPL_SIZE_FORMAT ". nc=%" - CPL_SIZE_FORMAT ". np=%" CPL_SIZE_FORMAT - ". mean=%g", mindeg, degree, nc, np, - mean); + return cpl_error_set_message_(error, "degree=%d, nc=%d <= np=%d", + (int)degree, (int)nc, (int)np); } + coeffs1d = cpl_matrix_get_data_const_(mx); - /* Scale back - and store coefficients - with leading coefficient first, - see doxygen of cpl_polynomial_set_coeff() */ - /* - make sure there is enough space, then fill up from below */ - if (self->tree == NULL) { - self->tree = cpl_polynomial_new_1d(mindeg + nc); - } else { - cpl_polynomial_grow_1d(self->tree, mindeg + nc); - } + /* Check coefficients for anomalies */ for (j = 0; j < nc; j++) { - if (dx[j] != 0.0) { - /* Since the tree may be a zero-polynomial, - deleting a coefficient (and determining the new - degree) can cause an assert() to fail */ - - const cpl_size k = j + mindeg; - - cpl_polynomial_set_coeff(self, &k, dx[j]); + if (isnan(coeffs1d[j])) { + cpl_matrix_delete(mx); + cpl_polynomial_empty(self); + return cpl_error_set_(CPL_ERROR_DIVISION_BY_ZERO); } } - if (self->tree->nc == 0) { - /* All fitted coefficients are zero */ - cpl_polynomial_empty(self); + /* Store coefficients for output */ + /* - make sure there is enough upper dim space, then fill up from below */ + if (self->tree == NULL) { + self->tree = cpl_polynomial_new_1d(ncy); + } + else { + cpl_polynomial_grow_1d(self->tree, ncy); } + j = 0; + for (degy = 0; degy < ncy; degy++) { + const cpl_size ncx = 1 + (dimdeg ? maxdeg[0] : degree - degy); + powers[1] = degy; + for (degx = 0; degx < ncx; degx++) { + if (dimdeg ? (degx >= mindeg[0] && degy >= mindeg[1]) + : degx + degy >= mindeg[0]) { + const double coeff = cpl_matrix_get_(mx, j, 0); + if (coeff != 0.0) { + /* Since the tree may contain zero-polynomials, + deleting a coefficient (and determining the new + degree) can cause an assert() to fail */ + powers[0] = degx; + if (coeffs1d[j] != coeff) + break; + if (cpl_polynomial_set_coeff(self, powers, coeff)) + break; + } + j++; + } + } + if (degx < ncx) + break; + } cpl_matrix_delete(mx); - if (mindeg == 0) { - /* Shift back */ - cpl_polynomial_shift_1d(self, 0, -mean); + assert(j == nc); + + if (sigmas != NULL) { + cpl_vector_delete(wvalues); } - /* If requested, compute mean squared error */ - if (pmse != NULL) { - const double * xpos = cpl_vector_get_data_const_(x_pos); - const double * dval = cpl_vector_get_data_const_(values); - *pmse = 0.0; - for (i = 0; i < np; i++) { - /* Subtract from the true value, square, accumulate */ - const double residue = dval[i] - - cpl_polynomial_eval_1d(self, xpos[i], NULL); - *pmse += residue * residue; - } - /* Average the error term */ - *pmse /= (double)np; + if (do_prune && cpl_polynomial_prune_(self->tree, self->dim - 1, ncy)) + cpl_polynomial_empty(self); - cpl_tools_add_flops( 3 * np + 1 ); + if (!is_mindeg) { + /* Transform the polynomial back */ + cpl_polynomial_shift_1d(self, 0, -xmean); + cpl_polynomial_shift_1d(self, 1, -ymean); } return CPL_ERROR_NONE; @@ -2239,90 +3218,141 @@ /*----------------------------------------------------------------------------*/ /** @internal - @brief Fit a 2D-polynomial to a 2D-surface in a least squares sense - @param xy_pos Bivector positions of the surface to fit. - @param values Vector of values of the surface to fit. + @brief Fit a 3D-polynomial to a 3D-volume in a least squares sense + @param x_pos X positions of the points volume to fit. + @param y_pos Y positions of the points volume to fit. + @param z_pos Z positions of the points volume to fit. + @param values Vector of values of the volume to fit. + @param sigmas Vector of uncertainties of the sampled values, or NULL for all ones. @param dimdeg True iff there is a fitting degree per dimension - @param mindeg Pointer to 1 or d maximum fitting degree(s), at least 0 + @param mindeg Pointer to 1 or d minimum fitting degree(s), at least 0 @param maxdeg Pointer to 1 or d maximum fitting degree(s), at least mindeg @return The fitted polynomial or NULL on error @see cpl_polynomial_fit() */ /*----------------------------------------------------------------------------*/ -static cpl_error_code cpl_polynomial_fit_2d(cpl_polynomial * self, - const cpl_bivector * xy_pos, - const cpl_vector * values, - cpl_boolean dimdeg, - const cpl_size * mindeg, - const cpl_size * maxdeg) -{ - - const cpl_size np = cpl_bivector_get_size(xy_pos); - cpl_size degree; /* The degree of the fitted polynomial */ - cpl_boolean is_mindeg = CPL_FALSE; /* Whether mindeg is non-zero */ - cpl_size nc; /* Number of unknowns to determine */ - cpl_size ncy; /* Number of Y-coefficients (incl. mindeg ones) */ - cpl_matrix * mv; /* The transpose of the Vandermonde matrix */ - cpl_matrix * mh; /* Block-Hankel matrix, V'*V */ - cpl_matrix * mb; - cpl_matrix * mx; - const double * coeffs1d; - double * dmv; - cpl_vector * xhat; - cpl_vector * yhat; - const cpl_vector* xuse; - const cpl_vector* yuse; - const double * dxuse; - const double * dyuse; - double xmean; - double ymean; - cpl_size powers[2]; - cpl_size degx, degy; - cpl_size i, j; - cpl_boolean do_prune = CPL_FALSE; - cpl_error_code error; +static cpl_error_code +cpl_polynomial_fit_3d(cpl_polynomial *self, + const cpl_vector *x_pos, + const cpl_vector *y_pos, + const cpl_vector *z_pos, + const cpl_vector *values, + const cpl_vector *sigmas, + cpl_boolean dimdeg, + const cpl_size *mindeg, + const cpl_size *maxdeg) +{ + const cpl_size np = cpl_vector_get_size_(values); + cpl_size degree; /* The degree of the fitted polynomial */ + cpl_boolean is_mindeg = CPL_FALSE; /* Whether mindeg is non-zero */ + cpl_size nc; /* Number of unknowns to determine */ + cpl_size ncz; /* Number of Z-coefficients (incl. mindeg ones) */ + cpl_matrix *mv; /* The transpose of the Vandermonde matrix */ + cpl_matrix *mh; /* Block-Hankel matrix, (W*V)'*(W*V) */ + cpl_matrix *mb; + cpl_matrix *mx; + const double *coeffs1d; + double *dmv; + cpl_vector *xhat; + cpl_vector *yhat; + cpl_vector *zhat; + cpl_vector *wvalues; + const cpl_vector *xuse; + const cpl_vector *yuse; + const cpl_vector *zuse; + const double *dxuse; + const double *dyuse; + const double *dzuse; + const double *sval; + double xmean; + double ymean; + double zmean; + double wsum; + cpl_size powers[3]; + cpl_size degx, degy, degz; + cpl_size i, j; + cpl_boolean do_prune = CPL_FALSE; + cpl_error_code error; - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(cpl_polynomial_get_dimension(self) == 2, + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(cpl_polynomial_get_dimension(self) == 3, CPL_ERROR_INVALID_TYPE); - cpl_ensure_code(np > 0, cpl_error_get_code()); + cpl_ensure_code(np > 0, cpl_error_get_code()); cpl_ensure_code(values != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(maxdeg != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(cpl_vector_get_size_(values) == np, + cpl_ensure_code(cpl_vector_get_size_(x_pos) == np && + cpl_vector_get_size_(y_pos) == np && + cpl_vector_get_size_(z_pos) == np, CPL_ERROR_INCOMPATIBLE_INPUT); - cpl_ensure_code(mindeg[0] >= 0, CPL_ERROR_ILLEGAL_INPUT); + if (sigmas != NULL) { /* Check sigmas errors */ + sval = cpl_vector_get_data_const_(sigmas); + for (i = 0; i < np; ++i) { + cpl_ensure_code(sval[i] != 0.0, CPL_ERROR_DIVISION_BY_ZERO); + } + } + else { + sval = NULL; + } + + cpl_ensure_code(mindeg[0] >= 0, CPL_ERROR_ILLEGAL_INPUT); cpl_ensure_code(maxdeg[0] >= mindeg[0], CPL_ERROR_ILLEGAL_INPUT); if (dimdeg) { - - cpl_ensure_code(mindeg[1] >= 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(mindeg[1] >= 0, CPL_ERROR_ILLEGAL_INPUT); cpl_ensure_code(maxdeg[1] >= mindeg[1], CPL_ERROR_ILLEGAL_INPUT); - if (mindeg[0] > 0 || mindeg[1] > 0) is_mindeg = CPL_TRUE; + cpl_ensure_code(mindeg[2] >= 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(maxdeg[2] >= mindeg[2], CPL_ERROR_ILLEGAL_INPUT); - degree = maxdeg[0] + maxdeg[1]; - ncy = maxdeg[1] + 1; - nc = (maxdeg[0] + 1 - mindeg[0]) * (ncy - mindeg[1]); + if (mindeg[0] > 0 || mindeg[1] > 0 || mindeg[2] > 0) + is_mindeg = CPL_TRUE; - } else { - const cpl_size nc0 = mindeg[0] * (mindeg[0] + 1) / 2; + degree = maxdeg[0] + maxdeg[1] + maxdeg[2]; + ncz = maxdeg[2] + 1; + nc = (maxdeg[0] + 1 - mindeg[0]) * (maxdeg[1] + 1 - mindeg[1]) * + (ncz - mindeg[2]); + } + else { + /* + In this case, we want to calculate the number of entries in the + Vandermonde matrix which is the number of combination for + x^i * y^j * z^k where i + j + k <= degree. + This number can be calculated with the following formula for 3D case: + nc(n) = n * (n + 1) * (n + 2) / 6 + Proof: + nc(n) = sum(j=1->n, sum(k=1->j, k)) + nc(n) = sum(j=1->n, j * (j + 1) / 2) + nc(n) = 1/2 * (sum(j=1->n, j * j) + sum(j=1->n, j)) + nc(n) = 1/2 * n * (n + 1) * (2 * n + 1) / 6 + n * (n + 1) / 2 + nc(n) = n * (n + 1) * (n + 2) / 6 + This proof can be generalized for a polynomial of dimension n and degree d: + nc(d, n) = (d + n - 1)! / (d! * (n - 1)!) + */ + + /* Compute the number of 0 coefficients using the previous formula */ + const cpl_size nc0 = + (mindeg[0] * (mindeg[0] + 1) * (mindeg[0] + 2)) / 6; degree = maxdeg[0]; - ncy = degree + 1; - nc = ncy * (maxdeg[0] + 2) / 2 - nc0; + ncz = degree + 1; - if (mindeg[0] > 0) is_mindeg = CPL_TRUE; + /* Compute the number of entries which is nc(degree + 1) - nc0 */ + nc = (((degree + 1) * (degree + 2) * (degree + 3)) / 6) - nc0; + + if (mindeg[0] > 0) + is_mindeg = CPL_TRUE; } if (np < nc) { - return cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, "Too few data " - "points %d < %d for %d-degree 2D-fit " + return cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, + "Too few data " + "points %d < %d for %d-degree 3D-fit " "(dimdeg=%d, mindeg=%d)", - (int)np, (int)nc, (int)degree, (int)dimdeg, - (int)mindeg[0]); + (int)np, (int)nc, (int)degree, + (int)dimdeg, (int)mindeg[0]); } if (self->tree != NULL) { @@ -2333,16 +3363,50 @@ do_prune = CPL_TRUE; } + /* If the fit use sigmas, the solved matrix equation is + (W*V)t*(W*V)*x = (W*V)t*(W*y) where W is the diagonal weighted matrix. We can see + that the (W*V)t is common in both member. The weights can therefore be multiplied + direclty in the construction of the transposed Vandermonde matrix. We also must + multiply the values (y) by the weights. + https://www.cs.auckland.ac.nz/courses/compsci369s1c/lectures/GG-notes/CS369-LeastSquares.pdf (slide 36) + https://en.wikipedia.org/wiki/Weighted_least_squares */ + + /* Apply the weights to the values */ + if (sigmas != NULL) { + wvalues = cpl_vector_duplicate(values); + double *dval = cpl_vector_get_data_(wvalues); + for (i = 0; i < np; i++) { + const double w = 1.0 / (sval[i] * sval[i]); + dval[i] *= w; + } + } + else { + wvalues = (cpl_vector *)values; + } + if (degree == 0) { /* Handle this as a special case */ assert(nc == 1); - xmean = cpl_vector_get_mean(values); + if (sigmas != NULL) { + /* Compute the squared weighted mean */ + const double *dval = cpl_vector_get_data_const_(values); + wsum = 0.0; + double sum = 0.0; + for (i = 0; i < np; ++i) { + const double w = 1.0 / (sval[i] * sval[i]); + wsum += w * w; + sum += dval[i] * w * w; + } + xmean = sum / wsum; + } + else { + xmean = cpl_vector_get_mean(values); + } if (xmean != 0.0) { - - powers[0] = powers[1] = 0; + powers[0] = powers[1] = powers[2] = 0; (void)cpl_polynomial_set_coeff(self, powers, xmean); @@ -2352,69 +3416,128 @@ cpl_polynomial_prune_(self->tree, self->dim - 1, nc); assert(self->tree->nc == 1); - - } else { + } + else { cpl_polynomial_empty(self); } + if (sigmas != NULL) { + cpl_vector_delete(wvalues); + } + return CPL_ERROR_NONE; } if (is_mindeg) { - xmean = ymean = 0.0; - xhat = yhat = NULL; - xuse = cpl_bivector_get_x_const(xy_pos); - yuse = cpl_bivector_get_y_const(xy_pos); - } else { - /* Transform: xhat = x - mean(x) */ - xhat = cpl_vector_transform_mean(cpl_bivector_get_x_const(xy_pos), - &xmean); - assert( xhat != NULL ); - xuse = xhat; - - /* Transform: yhat = y - mean(y) */ - yhat = cpl_vector_transform_mean(cpl_bivector_get_y_const(xy_pos), - &ymean); - assert( yhat != NULL ); - yuse = yhat; + xmean = ymean = zmean = 0.0; + xhat = yhat = zhat = NULL; + xuse = x_pos; + yuse = y_pos; + zuse = z_pos; + } + else { + if (sigmas != NULL) { + /* Weights must be taken in account */ + /* Transform: xhat = x - weightedmean(x) */ + /* Transform: yhat = y - weightedmean(y) */ + /* Transform: zhat = z - weightedmean(z) */ + double xsum, ysum, zsum; + xhat = cpl_vector_duplicate(x_pos); + yhat = cpl_vector_duplicate(y_pos); + zhat = cpl_vector_duplicate(z_pos); + const double *xdval = cpl_vector_get_data_const(xhat); + const double *ydval = cpl_vector_get_data_const(yhat); + const double *zdval = cpl_vector_get_data_const(zhat); + xsum = ysum = zsum = wsum = 0.0; + for (i = 0; i < np; i++) { + double w = 1.0 / (sval[i] * sval[i]); + xsum += xdval[i] * w * w; + ysum += ydval[i] * w * w; + zsum += zdval[i] * w * w; + wsum += w * w; + } + xmean = xsum / wsum; + ymean = ysum / wsum; + zmean = zsum / wsum; + cpl_vector_subtract_scalar(xhat, xmean); + cpl_vector_subtract_scalar(yhat, ymean); + cpl_vector_subtract_scalar(zhat, zmean); + xuse = xhat; + yuse = yhat; + zuse = zhat; + } + else { + /* Transform: xhat = x - mean(x) */ + xhat = cpl_vector_transform_mean(x_pos, &xmean); + assert(xhat != NULL); + xuse = xhat; + + /* Transform: yhat = y - mean(y) */ + yhat = cpl_vector_transform_mean(y_pos, &ymean); + assert(yhat != NULL); + yuse = yhat; + + /* Transform: zhat = z - mean(z) */ + zhat = cpl_vector_transform_mean(z_pos, &zmean); + assert(zhat != NULL); + zuse = zhat; + } } dxuse = cpl_vector_get_data_const_(xuse); dyuse = cpl_vector_get_data_const_(yuse); + dzuse = cpl_vector_get_data_const_(zuse); /* Initialize matrices */ /* mv contains the polynomial terms in the order described */ /* above in each row, for each input point. */ - dmv = (double*)cpl_malloc((size_t)(nc * np) * sizeof(*dmv)); + dmv = (double *)cpl_malloc((size_t)(nc * np) * sizeof(*dmv)); mv = cpl_matrix_wrap(nc, np, dmv); /* Has redundant FLOPs, appears to improve accuracy */ - for (i=0; i < np; i++) { + /* If weights are used, the factors are applied to the values */ + for (i = 0; i < np; i++) { const double x = dxuse[i]; const double y = dyuse[i]; - double yvalue = 1.0; + const double z = dzuse[i]; j = 0; - for (degy = 0; degy < ncy; degy++) { - const cpl_size ncx = 1 + (dimdeg ? maxdeg[0] : degree - degy); - double xvalue = 1.0; - for (degx = 0; degx < ncx; degx++) { - if (dimdeg ? (degx >= mindeg[0] && degy >= mindeg[1]) - : degx + degy >= mindeg[0]) - dmv[np * j++ + i] = xvalue * yvalue; - xvalue *= x; + double zvalue = 1.0; + for (degz = 0; degz < ncz; ++degz) { + const cpl_size ny = 1 + (dimdeg ? maxdeg[1] : degree - degz); + double yvalue = 1.0; + for (degy = 0; degy < ny; ++degy) { + const cpl_size nx = + 1 + (dimdeg ? maxdeg[0] : degree - degz - degy); + double xvalue = 1.0; + for (degx = 0; degx < nx; ++degx) { + if (dimdeg ? (degx >= mindeg[0] && degy >= mindeg[1] && + degz >= mindeg[2]) + : degx + degy + degz >= mindeg[0]) { + dmv[np * j++ + i] = + sval + ? (xvalue * yvalue * zvalue) / + (sval[i] * sval[i]) + : xvalue * yvalue * + zvalue; /* multiplied weights if needed */ + } + xvalue *= x; + } + yvalue *= y; } - yvalue *= y; + zvalue *= z; } - assert( j == nc ); + assert(j == nc); } - cpl_tools_add_flops( np * (nc * 2 + ncy)); + cpl_tools_add_flops(np * + (nc * 3)); /* TODO: find the good flops estimation */ cpl_vector_delete(xhat); cpl_vector_delete(yhat); + cpl_vector_delete(zhat); - /* mb contains the values, it is _not_ modified */ + /* mb contains the values, it is weighted */ CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); - mb = cpl_matrix_wrap(np, 1, cpl_vector_get_data_((cpl_vector*)values)); + mb = cpl_matrix_wrap(np, 1, cpl_vector_get_data_(wvalues)); CPL_DIAG_PRAGMA_POP; /* Form the right hand side of the normal equations */ @@ -2438,10 +3561,12 @@ (int)degree, (int)nc, (int)np); } - coeffs1d = cpl_matrix_get_data_const(mx); + coeffs1d = cpl_matrix_get_data_const_(mx); /* Check coefficients for anomalies */ - for (j = 0; j < nc; j++) { + /* This check was added due to its presence in the 2D case */ + /* FIXME: Add a unit test */ + for (j = 0; j < nc; ++j) { if (isnan(coeffs1d[j])) { cpl_matrix_delete(mx); cpl_polynomial_empty(self); @@ -2452,43 +3577,59 @@ /* Store coefficients for output */ /* - make sure there is enough upper dim space, then fill up from below */ if (self->tree == NULL) { - self->tree = cpl_polynomial_new_1d(ncy); - } else { - cpl_polynomial_grow_1d(self->tree, ncy); + self->tree = cpl_polynomial_new_1d(ncz); + } + else { + cpl_polynomial_grow_1d(self->tree, ncz); } j = 0; - for (degy = 0; degy < ncy; degy++) { - const cpl_size ncx = 1 + (dimdeg ? maxdeg[0] : degree - degy); - powers[1] = degy; - for (degx = 0; degx < ncx; degx++) { - if (dimdeg ? (degx >= mindeg[0] && degy >= mindeg[1]) - : degx + degy >= mindeg[0]) { - const double coeff = cpl_matrix_get(mx, j, 0); - if (coeff != 0.0) { - /* Since the tree may contain zero-polynomials, - deleting a coefficient (and determining the new - degree) can cause an assert() to fail */ - powers[0] = degx; - if (coeffs1d[j] != coeff) break; - if (cpl_polynomial_set_coeff(self, powers, coeff)) break; + for (degz = 0; degz < ncz; ++degz) { + const cpl_size ny = 1 + (dimdeg ? maxdeg[1] : degree - degz); + powers[2] = degz; + for (degy = 0; degy < ny; ++degy) { + const cpl_size nx = 1 + (dimdeg ? maxdeg[0] : degree - degz - degy); + powers[1] = degy; + for (degx = 0; degx < nx; ++degx) { + if (dimdeg ? (degx >= mindeg[0] && degy >= mindeg[1] && + degz >= mindeg[2]) + : degx + degy + degz >= mindeg[0]) { + const double coeff = cpl_matrix_get_(mx, j, 0); + if (coeff != 0.0) { + /* Since the tree may contain zero-polynomials, + deleting a coefficient (and determining the new + degree) can cause an assert() to fail */ + powers[0] = degx; + if (coeffs1d[j] != coeff) + break; + if (cpl_polynomial_set_coeff(self, powers, coeff)) + break; + } + j++; } - j++; } + if (degx < nx) + break; } - if (degx < ncx) break; + if (degy < ny) + break; } cpl_matrix_delete(mx); assert(j == nc); - if (do_prune && cpl_polynomial_prune_(self->tree, self->dim -1, ncy)) + if (sigmas != NULL) { + cpl_vector_delete(wvalues); + } + + if (do_prune && cpl_polynomial_prune_(self->tree, self->dim - 1, ncz)) cpl_polynomial_empty(self); if (!is_mindeg) { /* Transform the polynomial back */ cpl_polynomial_shift_1d(self, 0, -xmean); cpl_polynomial_shift_1d(self, 1, -ymean); + cpl_polynomial_shift_1d(self, 2, -zmean); } return CPL_ERROR_NONE; @@ -2502,21 +3643,24 @@ @param pows The non-negative power(s) of the variable(s) @param deldeg The degree of the coefficient to be deleted, sum of pows @return void - @note @see cpl_polynomial_set_coeff() + @see cpl_polynomial_set_coeff() */ /*----------------------------------------------------------------------------*/ -static void cpl_polynomial_delete_coeff(cpl_polynomial * self, - const cpl_size * pows, - cpl_size deldeg) +static void +cpl_polynomial_delete_coeff(cpl_polynomial *self, + const cpl_size *pows, + cpl_size deldeg) { - if (self->tree == NULL) return; + if (self->tree == NULL) + return; if (cpl_polynomial_delete_coeff_(self->tree, pows, self->dim - 1)) { cpl_polynomial_delete_(self->tree, self->dim - 1); self->tree = NULL; self->degree = 0; - } else if (deldeg == self->degree) { + } + else if (deldeg == self->degree) { self->degree = cpl_polynomial_find_degree_(self->tree, self->dim - 1); assert(self->degree <= deldeg); } @@ -2526,43 +3670,57 @@ /** @internal @brief Fill the Hankel Matrix H=V'*V, where V is a 1D-Vandermonde matrix + and apply the weights (1.0 / sigma^2) if needed (H = (W*V)'*(W*V)). @param self The matrix H - @param mx A right multiplication with V', mx = V' * values + @param mx A right multiplication with V', mx = V' * values + or mx = (W*V)'*W*values with weights. @param xhat The mean-transformed x-values @param is_eqdist True iff xhat contains equidistant points @param mindeg The non-negative minimum fitting degree @param values The values to be interpolated + @param sigmas The uncertainties of the sampled values @return void @note self must have its elements initialized to zero iff is_eqdist is true. @see cpl_polynomial_fit_1d() */ /*----------------------------------------------------------------------------*/ -static void cpl_matrix_fill_normal_vandermonde(cpl_matrix * self, - cpl_matrix * mx, - const cpl_vector * xhat, - cpl_boolean is_eqdist, - cpl_size mindeg, - const cpl_vector * values) -{ - - - const double * dval = cpl_vector_get_data_const_(values); - const double * xval = cpl_vector_get_data_const_(xhat); - cpl_vector * phat = cpl_vector_duplicate(xhat); /* Powers of xhat */ - cpl_vector * qhat = NULL; /* mindeg Power of xhat */ - double * dhat = cpl_vector_get_data_(phat); - double * ehat = NULL; - const cpl_size nc = cpl_matrix_get_ncol(self); - const cpl_size np = cpl_vector_get_size_(xhat); - cpl_size i,j; - - - assert( nc == cpl_matrix_get_nrow(self) ); - assert( nc == cpl_matrix_get_nrow(mx) ); - assert( 1 == cpl_matrix_get_ncol(mx) ); - assert( np == cpl_vector_get_size_(values) ); - +inline static void +cpl_matrix_fill_normal_vandermonde(cpl_matrix *self, + cpl_matrix *mx, + const cpl_vector *xhat, + cpl_boolean is_eqdist, + cpl_size mindeg, + const cpl_vector *values, + const cpl_vector *sigmas) +{ + const double *dval = cpl_vector_get_data_const_(values); + const double *xval = cpl_vector_get_data_const_(xhat); + cpl_vector *phat = cpl_vector_duplicate(xhat); /* Powers of xhat */ + cpl_vector *qhat = NULL; /* mindeg Power of xhat */ + double *dhat = cpl_vector_get_data_(phat); + double *ehat = NULL; + const cpl_size nc = cpl_matrix_get_ncol_(self); + const cpl_size np = cpl_vector_get_size_(xhat); + cpl_size i, j; + const double *sval; + cpl_vector *shat; + + if (sigmas != NULL) { + assert(np == cpl_vector_get_size_(sigmas)); + shat = (cpl_vector *)sigmas; /* required to compute the sum */ + } + else { + shat = cpl_vector_new(np); + cpl_vector_fill(shat, 1.0); + } + + sval = cpl_vector_get_data_const_(shat); + + assert(nc == cpl_matrix_get_nrow_(self)); + assert(nc == cpl_matrix_get_nrow_(mx)); + assert(1 == cpl_matrix_get_ncol_(mx)); + assert(np == cpl_vector_get_size_(values)); /* Fill Hankel matrix from top-left to main skew diagonal - on and above (non-skew) main diagonal */ @@ -2576,90 +3734,109 @@ ehat = cpl_vector_get_data_(qhat); /* Raise xhat to the power of mindeg */ - for (k=0; k < np; k++) { + for (k = 0; k < np; k++) { const double x = xval[k]; + const double w = 1.0 / (sval[k] * sval[k]); - if (mindeg > 1) ehat[k] = cpl_tools_ipow(x, (int)mindeg); + if (mindeg > 1) + ehat[k] = cpl_tools_ipow(x, (int)mindeg); dhat[k] *= ehat[k]; - hsum += ehat[k] * ehat[k]; + hsum += ehat[k] * ehat[k] * w * w; + } + cpl_matrix_set_(self, 0, 0, hsum); + } + else { + /* First coefficient is the sum of weights */ + /* NULL sigms means sum(wi)=np */ + double sum = 0.0; + for (i = 0; i < np; ++i) { + const double w = 1.0 / (sval[i] * sval[i]); + sum += w * w; } - cpl_matrix_set(self, 0, 0, hsum); - } else { - cpl_matrix_set(self, 0, 0, (double)np); + cpl_matrix_set_(self, 0, 0, sum); } /* qhat is xhat to the power of mindeg, iff mindeg > 0 */ /* dhat is xhat to the power of 1+mindeg, iff mindeg > 0 */ - for (j=1; j < 2; j++) { + for (j = 1; j < 2; j++) { double vsum0 = 0.0; double hsum = 0.0; double vsum = 0.0; cpl_size k; - for (k=0; k < np; k++) { + for (k = 0; k < np; k++) { const double y = dval[k]; + const double w = 1.0 / (sval[k] * sval[k]); - hsum += mindeg > 0 ? ehat[k] * dhat[k] : dhat[k]; - vsum += y * dhat[k]; - vsum0 += mindeg > 0 ? ehat[k] * y : y; - } - cpl_matrix_set(mx, 0, 0, vsum0); - cpl_matrix_set(mx, j, 0, vsum); - if (is_eqdist) continue; + hsum += mindeg > 0 ? ehat[k] * dhat[k] * w * w : dhat[k] * w * w; + vsum += y * dhat[k] * w * w; + vsum0 += mindeg > 0 ? ehat[k] * y * w * w : y * w * w; + } + cpl_matrix_set_(mx, 0, 0, vsum0); + cpl_matrix_set_(mx, j, 0, vsum); + if (is_eqdist) + continue; k = j; - for (i=0; i <= k; i++, k--) { - cpl_matrix_set(self, i, k, hsum); + for (i = 0; i <= k; i++, k--) { + cpl_matrix_set_(self, i, k, hsum); } } for (; j < nc; j++) { - double hsum = 0.0; - double vsum = 0.0; + double hsum = 0.0; + double vsum = 0.0; cpl_size k; - for (k=0; k < np; k++) { + for (k = 0; k < np; k++) { const double x = xval[k]; const double y = dval[k]; + const double w = 1.0 / (sval[k] * sval[k]); dhat[k] *= x; - hsum += mindeg > 0 ? ehat[k] * dhat[k] : dhat[k]; - vsum += y * dhat[k]; + hsum += mindeg > 0 ? ehat[k] * dhat[k] * w * w : dhat[k] * w * w; + vsum += y * dhat[k] * w * w; } - cpl_matrix_set(mx, j, 0, vsum); - if (is_eqdist && (j&1)) continue; + cpl_matrix_set_(mx, j, 0, vsum); + if (is_eqdist && (j & 1)) + continue; k = j; - for (i=0; i <= k; i++, k--) { - cpl_matrix_set(self, i, k, hsum); + for (i = 0; i <= k; i++, k--) { + cpl_matrix_set_(self, i, k, hsum); } } /* Fill remaining Hankel matrix - on and above (non-skew) main diagonal */ - if (mindeg > 0) cpl_vector_multiply(phat, qhat); + if (mindeg > 0) + cpl_vector_multiply(phat, qhat); cpl_vector_delete(qhat); for (i = 1; i < nc; i++) { cpl_size k; - double hsum = 0.0; + double hsum = 0.0; - if (is_eqdist && ((i+nc)&1)==0) { + if (is_eqdist && ((i + nc) & 1) == 0) { cpl_vector_multiply(phat, xhat); continue; } - for (k=0; k < np; k++) { + for (k = 0; k < np; k++) { const double x = xval[k]; + const double w = 1.0 / (sval[k] * sval[k]); dhat[k] *= x; - hsum += dhat[k]; + hsum += dhat[k] * w * w; } k = i; - for (j = nc-1; k <= j; k++, j--) { - cpl_matrix_set(self, k, j, hsum); + for (j = nc - 1; k <= j; k++, j--) { + cpl_matrix_set_(self, k, j, hsum); } } - cpl_tools_add_flops( 6 * np * ( nc - 1) ); + cpl_tools_add_flops(6 * np * (nc - 1)); cpl_vector_delete(phat); + if (sigmas == NULL) { + cpl_vector_delete(shat); + } } /*----------------------------------------------------------------------------*/ @@ -2675,30 +3852,31 @@ */ /*----------------------------------------------------------------------------*/ -static int cpl_vector_is_eqdist(const cpl_vector * self) +static int +cpl_vector_is_eqdist(const cpl_vector *self) { - double xval, delta; const cpl_size np = cpl_vector_get_size(self); cpl_size i; cpl_ensure(self, CPL_ERROR_NULL_INPUT, -1); - if (cpl_vector_get_size_(self) == 1) return 1; + if (cpl_vector_get_size_(self) == 1) + return 1; xval = cpl_vector_get(self, 1); delta = xval - cpl_vector_get(self, 0); - for (i=1; i < np-1; i++) { + for (i = 1; i < np - 1; i++) { const double dprev = delta; const double xprev = xval; - xval = cpl_vector_get(self, i+1); + xval = cpl_vector_get(self, i + 1); delta = xval - xprev; - if (delta != dprev) break; + if (delta != dprev) + break; } - return i == np-1 ? 1 : 0; - + return i == np - 1 ? 1 : 0; } /*----------------------------------------------------------------------------*/ @@ -2714,13 +3892,14 @@ */ /*----------------------------------------------------------------------------*/ -inline void cpl_polynomial_shift_double(double * coeffs, cpl_size n, double u) +inline void +cpl_polynomial_shift_double(double *coeffs, cpl_size n, double u) { - for (cpl_size j = 0; j < n-1; j++) - for (cpl_size i = 1; i < n - j; i++ ) - coeffs[n-1-i] += coeffs[n-i] * u; + for (cpl_size j = 0; j < n - 1; j++) + for (cpl_size i = 1; i < n - j; i++) + coeffs[n - 1 - i] += coeffs[n - i] * u; - cpl_tools_add_flops( n * ( n - 1) ); + cpl_tools_add_flops(n * (n - 1)); } /*----------------------------------------------------------------------------*/ @@ -2737,24 +3916,29 @@ */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_polynomial_solve_1d_(const cpl_polynomial * self, - double x0, double * px, cpl_size mul, - cpl_boolean bpos) +cpl_error_code +cpl_polynomial_solve_1d_(const cpl_polynomial *self, + double x0, + double *px, + cpl_size mul, + cpl_boolean bpos) { cpl_error_code code = CPL_ERROR_NONE; - cpl_ensure_code(px != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(self->dim == 1, CPL_ERROR_INVALID_TYPE); - cpl_ensure_code(mul > 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(px != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self->dim == 1, CPL_ERROR_INVALID_TYPE); + cpl_ensure_code(mul > 0, CPL_ERROR_ILLEGAL_INPUT); /* Iterating towards zero is not as simple as it sounds, so don't */ if (self->tree == NULL) { - *px = 0.0; - } else if (self->tree->coef[0].val != 0.0) { + *px = 0.0; + } + else if (self->tree->coef[0].val != 0.0) { code = cpl_polynomial_solve_1d__(self->tree, x0, px, mul, bpos); - } else { - *px = 0.0; + } + else { + *px = 0.0; } return code ? cpl_error_set_where_() : CPL_ERROR_NONE; @@ -2778,19 +3962,20 @@ */ /*----------------------------------------------------------------------------*/ -static cpl_error_code cpl_polynomial_solve_1d__(const cpl_polynomial_1d * p, - double x0, double * px, - cpl_size mul, - cpl_boolean bpos) +static cpl_error_code +cpl_polynomial_solve_1d__(const cpl_polynomial_1d *p, + double x0, + double *px, + cpl_size mul, + cpl_boolean bpos) { - - double x = x0; + double x = x0; /* Initialize to ensure at least one iteration */ - double r = 1.0; - double d = 0.0; - const double dmul = (double)mul; /* Root multiplicity */ + double r = 1.0; + double d = 0.0; + const double dmul = (double)mul; /* Root multiplicity */ const cpl_size mite = p->nc * (CPL_POLYNOMIAL_SOLVE_MAXITE); - cpl_size i; + cpl_size i; for (i = 0; i < mite; i++) { @@ -2806,8 +3991,10 @@ 1) Correction did not decrease - unless p`(x) changed sign 2) p`(x) == 0. It is insufficient to implement this as d == 0, because some non-zero divisors can still result in inf. */ - if (bpos && d <= 0.0) break; - if (d * dprev >= 0.0 && fabs(r * dprev) >= fabs(rprev * d)) break; + if (bpos && d <= 0.0) + break; + if (d * dprev >= 0.0 && fabs(r * dprev) >= fabs(rprev * d)) + break; /* Compute and apply the accelerated Newton-Raphson correction */ x -= dmul * r / d; @@ -2820,23 +4007,25 @@ /* Stop also if: 3) The correction did not change the solution - will typically save at most one Horner-evaluation */ - if (fabs(x - xprev) < fabs(x) * DBL_EPSILON) break; + if (fabs(x - xprev) < fabs(x) * DBL_EPSILON) + break; /* if x_i == x_j for i > j > 0 the iteration cannot converge. This can only happen with at least two sign-changes for p`(x_k) i >= k >= j. This is not checked for. */ - } *px = x; - cpl_tools_add_flops( i * 12 ); + cpl_tools_add_flops(i * 12); - if (i == mite) return - cpl_error_set_message_(CPL_ERROR_CONTINUE, "x0=%g, mul=%d, degree=%d, " - "i=%d, p(x=%g)=%g", x0, (int)mul, (int)p->nc-1, - (int)i, x, - (double)cpl_polynomial_eval_1d_(p, x, NULL)); + if (i == mite) + return cpl_error_set_message_(CPL_ERROR_CONTINUE, + "x0=%g, mul=%d, degree=%d, " + "i=%d, p(x=%g)=%g", + x0, (int)mul, (int)p->nc - 1, (int)i, x, + (double)cpl_polynomial_eval_1d_(p, x, + NULL)); /* At this point: In absence of rounding r or d is zero. @@ -2847,10 +4036,12 @@ - in this case |r| cannot be bigger than |d| because p is one degree higher than p'. */ - if (bpos && d <= 0.0) return - cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, "x0=%g, mul=%d, " - "degree=%d, i=%d, p(x=%g)=%g, p'(x)=%g <= 0.0", - x0, (int)mul, (int)p->nc-1, (int)i, x, r, d); + if (bpos && d <= 0.0) + return cpl_error_set_message_( + CPL_ERROR_ILLEGAL_INPUT, + "x0=%g, mul=%d, " + "degree=%d, i=%d, p(x=%g)=%g, p'(x)=%g <= 0.0", + x0, (int)mul, (int)p->nc - 1, (int)i, x, r, d); if (fabs(r) > fabs(d)) { /* When d is computed in long double precision at a multiple root, @@ -2862,12 +4053,16 @@ /* Since r is non-zero, at least one coefficient must be non-zero */ cpl_size n = p->nc; double max = 0.0; - while (n) if (fabs(p->coef[--n].val) > max) max = fabs(p->coef[n].val); - - if (fabs(r) > max * DBL_EPSILON) return - cpl_error_set_message_(CPL_ERROR_DIVISION_BY_ZERO, "x0=%g, mul=%d, " - "degree=%d, i=%d, p(x=%g)=%g, p'(x)=%g", x0, - (int)mul, (int)p->nc-1, (int)i, x, r, d); + while (n) + if (fabs(p->coef[--n].val) > max) + max = fabs(p->coef[n].val); + + if (fabs(r) > max * DBL_EPSILON) + return cpl_error_set_message_( + CPL_ERROR_DIVISION_BY_ZERO, + "x0=%g, mul=%d, " + "degree=%d, i=%d, p(x=%g)=%g, p'(x)=%g", + x0, (int)mul, (int)p->nc - 1, (int)i, x, r, d); } return CPL_ERROR_NONE; @@ -2879,24 +4074,23 @@ @brief Create a new, zero-valued polynomial with memory for coefficients @param nc The positive number of coefficients @return 1 newly allocated polynomial + @see cpl_polynomial_new() @note No error checking in this internal function - Possible #_cpl_error_code_ set in this function: - - CPL_ERROR_ILLEGAL_INPUT if dim is negative or zero */ /*----------------------------------------------------------------------------*/ -inline static cpl_polynomial_1d * cpl_polynomial_new_1d(cpl_size nc) +inline static cpl_polynomial_1d * +cpl_polynomial_new_1d(cpl_size nc) { - const cpl_size nz = nc > CPL_POLYNOMIAL_DEFAULT_COEFFS ? nc : - CPL_POLYNOMIAL_DEFAULT_COEFFS; + const cpl_size nz = + nc > CPL_POLYNOMIAL_DEFAULT_COEFFS ? nc : CPL_POLYNOMIAL_DEFAULT_COEFFS; - cpl_polynomial_1d * self; + cpl_polynomial_1d *self; /* Allocate struct - and within the same allocation also space for the requested number of coefficients (and at least the default number) */ - self = cpl_malloc(sizeof(*self) - + (size_t)nz * sizeof(*(self->coef))); - self->coef = (void*)(self + 1); + self = cpl_malloc(sizeof(*self) + (size_t)nz * sizeof(*(self->coef))); + self->coef = (void *)(self + 1); assert(!CPL_POLYNOMIAL_COEFF_IS_MALLOC(self)); assert(nc > 0); @@ -2919,8 +4113,8 @@ */ /*----------------------------------------------------------------------------*/ -inline static -void cpl_polynomial_grow_1d(cpl_polynomial_1d * self, cpl_size newsize) +inline static void +cpl_polynomial_grow_1d(cpl_polynomial_1d *self, cpl_size newsize) { if (newsize == 0 || newsize > self->nz) { /* No shrinking, only growing */ @@ -2931,25 +4125,27 @@ if (self->nc == 0) { /* No memcpy(), no overhead */ if (CPL_POLYNOMIAL_COEFF_IS_MALLOC(self)) - cpl_free((void*)self->coef); + cpl_free((void *)self->coef); self->coef = cpl_malloc((size_t)self->nz * sizeof(*(self->coef))); - } else if (!CPL_POLYNOMIAL_COEFF_IS_MALLOC(self)) { + } + else if (!CPL_POLYNOMIAL_COEFF_IS_MALLOC(self)) { /* Copy (possibly full), but no deallocation */ - self->coef = memcpy(cpl_malloc((size_t)self->nz - * sizeof(*(self->coef))), - self->coef, - (size_t)self->nc * sizeof(*(self->coef))); - } else if (self->nc < oldsize) { + self->coef = + memcpy(cpl_malloc((size_t)self->nz * sizeof(*(self->coef))), + self->coef, (size_t)self->nc * sizeof(*(self->coef))); + } + else if (self->nc < oldsize) { /* Partial memcpy(), allocation overhead */ - void * oldbuf = self->coef; + void *oldbuf = self->coef; self->coef = cpl_malloc((size_t)self->nz * sizeof(*(self->coef))); (void)memcpy(self->coef, oldbuf, (size_t)self->nc * sizeof(*(self->coef))); cpl_free(oldbuf); - } else { + } + else { /* Full memcpy(), allocation overhead handled by realloc() */ - self->coef = cpl_realloc(self->coef, (size_t)self->nz - * sizeof(*(self->coef))); + self->coef = cpl_realloc(self->coef, + (size_t)self->nz * sizeof(*(self->coef))); } } } @@ -2966,18 +4162,19 @@ */ /*----------------------------------------------------------------------------*/ -inline static void cpl_polynomial_grow_1d_reset(cpl_polynomial_1d * self, - cpl_size newsize, - cpl_size zeroto) +inline static void +cpl_polynomial_grow_1d_reset(cpl_polynomial_1d *self, + cpl_size newsize, + cpl_size zeroto) { - cpl_polynomial_grow_1d(self, newsize); - if (zeroto == 0) zeroto = self->nz; + if (zeroto == 0) + zeroto = self->nz; - assert(self->nz > self->nc); + assert(self->nz > self->nc); assert(self->nz >= zeroto); - assert(zeroto >= self->nc); + assert(zeroto >= self->nc); (void)memset(self->coef + (size_t)self->nc, 0, (size_t)(zeroto - self->nc) * sizeof(*self->coef)); @@ -2988,14 +4185,14 @@ @internal @brief Delete and deallocate all memory of a polynomial @param self Polynomial to delete - @param mydim This dimension, zero for deepest + @param mydim This dimension, zero for lowest @return void - @see cpl_polynomial_delete_() + @see cpl_polynomial_delete() */ /*----------------------------------------------------------------------------*/ -inline static -void cpl_polynomial_delete_(cpl_polynomial_1d * self, cpl_size mydim) +inline static void +cpl_polynomial_delete_(cpl_polynomial_1d *self, cpl_size mydim) { if (self != NULL) { if (mydim > 0) { @@ -3003,14 +4200,15 @@ assert(self->coef != NULL); do { self->nc--; - cpl_polynomial_delete_(self->coef[self->nc].next, mydim - 1); + cpl_polynomial_delete_(self->coef[self->nc].next, + mydim - 1); } while (self->nc); } assert(self->nc == 0); } if (CPL_POLYNOMIAL_COEFF_IS_MALLOC(self)) - cpl_free((void*)self->coef); - cpl_free((void*)self); + cpl_free((void *)self->coef); + cpl_free((void *)self); } } @@ -3019,7 +4217,7 @@ @internal @brief Set to zero all coefficients, keeping all nodes allocated @param self Polynomial to modify - @param mydim This dimension, zero for deepest + @param mydim This dimension, zero for lowest @return void @note Tree of arrays is not deallocated, just emptied @see cpl_polynomial_reset_() @@ -3034,14 +4232,16 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_polynomial_reset_(cpl_polynomial_1d * self, cpl_size mydim) +static void +cpl_polynomial_reset_(cpl_polynomial_1d *self, cpl_size mydim) { if (self != NULL) { if (mydim > 0) { for (cpl_size i = 0; i < self->nc; i++) { cpl_polynomial_reset_(self->coef[i].next, mydim - 1); } - } else { + } + else { self->nc = 0; } } @@ -3052,16 +4252,15 @@ @internal @brief Ensure leading coefficient(s) are non-zero recursively, set size @param self Polynomial to modify - @param mydim This dimension, zero for deepest + @param mydim This dimension, zero for lowest @parma newsize New size, zero to empty completely @return CPL_TRUE iff there is an underlying dimension to be deallocated @note The new size may not exceed the allocated size! */ /*----------------------------------------------------------------------------*/ -inline static cpl_boolean cpl_polynomial_prune_(cpl_polynomial_1d * self, - cpl_size mydim, - cpl_size newsize) +static cpl_boolean +cpl_polynomial_prune_(cpl_polynomial_1d *self, cpl_size mydim, cpl_size newsize) { cpl_boolean do_del = CPL_FALSE; @@ -3072,7 +4271,7 @@ /* If new size exceeds old size: */ /* Delete zero-valued coefficients */ for (i = self->nc; i > newsize; i--) { - cpl_polynomial_delete_(self->coef[i-1].next, mydim - 1); + cpl_polynomial_delete_(self->coef[i - 1].next, mydim - 1); } } @@ -3081,19 +4280,20 @@ /* Delete zero-valued leading coefficients */ if (mydim == 0) { for (; i > 0; i--) { - if (self->coef[i-1].val != 0.0) break; + if (self->coef[i - 1].val != 0.0) + break; } - } else { + } + else { for (; i > 0; i--) { + if (self->coef[i - 1].next == NULL) + continue; - if (self->coef[i-1].next == NULL) continue; - - if (self->coef[i-1].next->nc == 0 || - cpl_polynomial_prune_(self->coef[i-1].next, - mydim - 1, - self->coef[i-1].next->nc)) { - cpl_polynomial_delete_(self->coef[i-1].next, mydim - 1); - self->coef[i-1].next = NULL; + if (self->coef[i - 1].next->nc == 0 || + cpl_polynomial_prune_(self->coef[i - 1].next, mydim - 1, + self->coef[i - 1].next->nc)) { + cpl_polynomial_delete_(self->coef[i - 1].next, mydim - 1); + self->coef[i - 1].next = NULL; continue; } @@ -3106,17 +4306,16 @@ if (mydim > 0) { /* Deallocate remaining, empty nodes */ for (; i > 0; i--) { - if (self->coef[i-1].next == NULL) continue; + if (self->coef[i - 1].next == NULL) + continue; - if (self->coef[i-1].next->nc == 0 || - cpl_polynomial_prune_(self->coef[i-1].next, - mydim - 1, - self->coef[i-1].next->nc)) { - cpl_polynomial_delete_(self->coef[i-1].next, mydim - 1); - self->coef[i-1].next = NULL; + if (self->coef[i - 1].next->nc == 0 || + cpl_polynomial_prune_(self->coef[i - 1].next, mydim - 1, + self->coef[i - 1].next->nc)) { + cpl_polynomial_delete_(self->coef[i - 1].next, mydim - 1); + self->coef[i - 1].next = NULL; } } - } do_del = self->nc == 0 ? CPL_TRUE : CPL_FALSE; } @@ -3129,35 +4328,35 @@ @brief Delete (set to zero) a coefficient of a polynomial @param self The polynomial to modify @param pows The non-negative power(s) of the variable(s) - @param mydim This dimension, zero for deepest + @param mydim This dimension, zero for lowest @return CPL_TRUE iff there is an underlying dimension to be deallocated @see cpl_polynomial_delete_coeff() */ /*----------------------------------------------------------------------------*/ -inline static cpl_boolean cpl_polynomial_delete_coeff_(cpl_polynomial_1d * self, - const cpl_size * pows, - cpl_size mydim) +static cpl_boolean +cpl_polynomial_delete_coeff_(cpl_polynomial_1d *self, + const cpl_size *pows, + cpl_size mydim) { cpl_boolean do_del = CPL_FALSE; - assert(mydim >= 0); + assert(mydim >= 0); assert(pows[mydim] >= 0); if (pows[mydim] < self->nc) { - if (mydim == 0) { self->coef[pows[mydim]].val = 0.0; - } else if (self->coef[pows[mydim]].next != NULL && - cpl_polynomial_delete_coeff_(self->coef[pows[mydim]].next, - pows, - mydim - 1)) { + } + else if (self->coef[pows[mydim]].next != NULL && + cpl_polynomial_delete_coeff_(self->coef[pows[mydim]].next, + pows, mydim - 1)) { cpl_polynomial_delete_(self->coef[pows[mydim]].next, mydim - 1); self->coef[pows[mydim]].next = NULL; } - if (pows[mydim] == self->nc-1) { + if (pows[mydim] == self->nc - 1) { /* Leading coefficient is zero - find the new leading */ if (cpl_polynomial_prune_(self, mydim, self->nc)) { @@ -3175,18 +4374,19 @@ @brief Set a non-zero coefficient of the polynomial @param self The polynomial to modify @param pows The non-negative power(s) of the variable(s) - @param mydim This dimension, zero for deepest + @param mydim This dimension, zero for lowest @param value The new, non-zero coefficient @return void @see cpl_polynomial_set_coeff() */ /*----------------------------------------------------------------------------*/ -inline static void cpl_polynomial_set_coeff_(cpl_polynomial_1d * self, - const cpl_size * pows, - cpl_size mydim, - double value) +inline static void +cpl_polynomial_set_coeff_(cpl_polynomial_1d *self, + const cpl_size *pows, + cpl_size mydim, + double value) { - assert(mydim >= 0); + assert(mydim >= 0); assert(pows[mydim] >= 0); assert(value != 0.0); @@ -3199,22 +4399,23 @@ /* ... setting the last one to zero is redundant when mydim == 0 */ (void)memset(self->coef + (size_t)self->nc, 0, (size_t)(1 + pows[mydim] - self->nc) * - sizeof(*self->coef)); + sizeof(*self->coef)); self->nc = 1 + pows[mydim]; } if (mydim == 0) { self->coef[pows[mydim]].val = value; - } else { + } + else { assert(mydim > 0); if (self->coef[pows[mydim]].next == NULL) self->coef[pows[mydim]].next = cpl_polynomial_new_1d(1 + pows[mydim - 1]); - cpl_polynomial_set_coeff_(self->coef[pows[mydim]].next, - pows, mydim - 1, value); + cpl_polynomial_set_coeff_(self->coef[pows[mydim]].next, pows, mydim - 1, + value); } } @@ -3224,13 +4425,13 @@ @internal @brief The degree of the polynomial @param self The polynomial to access - @param mydim This dimension, zero for deepest + @param mydim This dimension, zero for lowest @return The degree, possibly zero @see cpl_polynomial_get_degree() */ /*----------------------------------------------------------------------------*/ -static cpl_size cpl_polynomial_find_degree_(const cpl_polynomial_1d * self, - cpl_size mydim) +static cpl_size +cpl_polynomial_find_degree_(const cpl_polynomial_1d *self, cpl_size mydim) { cpl_size mydegree = self->nc - 1; @@ -3239,9 +4440,11 @@ if (mydim > 0) { for (cpl_size i = 0; i < self->nc; i++) { if (self->coef[i].next != NULL) { - const cpl_size idegree = i + + const cpl_size idegree = + i + cpl_polynomial_find_degree_(self->coef[i].next, mydim - 1); - if (idegree > mydegree) mydegree = idegree; + if (idegree > mydegree) + mydegree = idegree; } } } @@ -3262,12 +4465,12 @@ @see cpl_polynomial_copy() */ /*----------------------------------------------------------------------------*/ -static void cpl_polynomial_copy_(cpl_polynomial_1d * self, - cpl_size selfdim, - const cpl_polynomial_1d * other, - cpl_size otherdim) +static void +cpl_polynomial_copy_(cpl_polynomial_1d *self, + cpl_size selfdim, + const cpl_polynomial_1d *other, + cpl_size otherdim) { - if (otherdim == 0) { if (selfdim > 0) { while (self->nc) { @@ -3276,13 +4479,15 @@ }; } cpl_polynomial_grow_1d(self, other->nc); - (void)memcpy((void*)self->coef, (const void*)other->coef, + (void)memcpy((void *)self->coef, (const void *)other->coef, (size_t)other->nc * sizeof(*self->coef)); - } else { + } + else { /* Nothing to keep */ if (selfdim == 0) { self->nc = 0; - } else { + } + else { /* - except reusable lower dimension storage structure */ while (self->nc > other->nc) { self->nc--; @@ -3292,9 +4497,7 @@ cpl_polynomial_grow_1d(self, other->nc); - selfdim > 0 - ? assert(self->nc <= other->nc) - : assert(self->nc == 0); + selfdim > 0 ? assert(self->nc <= other->nc) : assert(self->nc == 0); for (cpl_size i = 0; i < other->nc; i++) { if (other->coef[i].next != NULL) { @@ -3303,7 +4506,8 @@ cpl_polynomial_new_1d(other->coef[i].next->nc); cpl_polynomial_copy_(self->coef[i].next, selfdim - 1, other->coef[i].next, otherdim - 1); - } else { + } + else { if (selfdim > 0 && i < self->nc) cpl_polynomial_delete_(self->coef[i].next, selfdim - 1); self->coef[i].next = NULL; @@ -3325,48 +4529,53 @@ @see cpl_polynomial_compare() */ /*----------------------------------------------------------------------------*/ -static int cpl_polynomial_compare_(const cpl_polynomial_1d * self, - const cpl_polynomial_1d * other, - cpl_size mydim, - double tol) +static int +cpl_polynomial_compare_(const cpl_polynomial_1d *self, + const cpl_polynomial_1d *other, + cpl_size mydim, + double tol) { - if (self != NULL || other != NULL) { - const cpl_size nself = self == NULL ? 0 : self->nc; + const cpl_size nself = self == NULL ? 0 : self->nc; const cpl_size nother = other == NULL ? 0 : other->nc; - const cpl_size nmin = CPL_MIN(nself, nother); + const cpl_size nmin = CPL_MIN(nself, nother); cpl_size i = 0; if (mydim == 0) { for (; i < nmin; i++) - if (fabs(self->coef[i].val - other->coef[i].val) > tol) return i+1; + if (fabs(self->coef[i].val - other->coef[i].val) > tol) + return i + 1; for (; i < nother; i++) - if (fabs(other->coef[i].val) > tol) return i + 1; + if (fabs(other->coef[i].val) > tol) + return i + 1; for (; i < nself; i++) - if (fabs(self->coef[i].val ) > tol) return i + 1; - } else { + if (fabs(self->coef[i].val) > tol) + return i + 1; + } + else { int cmp = 0; for (; i < nmin; i++) { cmp = cpl_polynomial_compare_(self->coef[i].next, - other->coef[i].next, - mydim - 1, tol); - if (cmp) return i + cmp; + other->coef[i].next, mydim - 1, + tol); + if (cmp) + return i + cmp; } for (; i < nother; i++) { - cmp = cpl_polynomial_compare_(NULL, - other->coef[i].next, + cmp = cpl_polynomial_compare_(NULL, other->coef[i].next, mydim - 1, tol); - if (cmp) return i + cmp; + if (cmp) + return i + cmp; } for (; i < nself; i++) { - cmp = cpl_polynomial_compare_(self->coef[i].next, - NULL, + cmp = cpl_polynomial_compare_(self->coef[i].next, NULL, mydim - 1, tol); - if (cmp) return i + cmp; + if (cmp) + return i + cmp; } } } @@ -3379,15 +4588,16 @@ @internal @brief Compute a first order partial derivative @param self The polynomial to be modified in place - @param mydim This dimension, zero for deepest + @param mydim This dimension, zero for lowest @param dodim The dimension to differentiate, zero for first dimension @return CPL_TRUE iff the operation collapsed the dimension to zero @see cpl_polynomial_derivative() */ /*----------------------------------------------------------------------------*/ -static cpl_boolean cpl_polynomial_derivative_(cpl_polynomial_1d * self, - cpl_size mydim, - cpl_size dodim) +static cpl_boolean +cpl_polynomial_derivative_(cpl_polynomial_1d *self, + cpl_size mydim, + cpl_size dodim) { if (mydim > dodim) { cpl_size nc = 0; @@ -3399,7 +4609,8 @@ /* Underlying dimension(s) collapsed */ cpl_polynomial_delete_(self->coef[i].next, mydim - 1); self->coef[i].next = NULL; - } else { + } + else { nc = i + 1; /* Remember highest non-zero, i.e. new lead */ } } @@ -3407,10 +4618,10 @@ /* Zero-valued leading coefficients have already been deleted */ self->nc = nc; - } else if (dodim > 0) { - - assert(dodim == mydim); - assert(self->nc > 0); + } + else if (dodim > 0) { + assert(dodim == mydim); + assert(self->nc > 0); /* Constant term goes away */ cpl_polynomial_delete_(self->coef[0].next, mydim - 1); @@ -3420,22 +4631,23 @@ for (cpl_size i = 0; i < self->nc; i++) { self->coef[i].next = self->coef[i + 1].next; /* Decrement power */ - cpl_polynomial_multiply_scalar_self(self->coef[i].next, - mydim - 1, (double)(i+1)); + cpl_polynomial_multiply_scalar_self(self->coef[i].next, mydim - 1, + (double)(i + 1)); } - } else { - assert(dodim == 0); - assert(mydim == 0); - assert(self->nc > 0); + } + else { + assert(dodim == 0); + assert(mydim == 0); + assert(self->nc > 0); /* Constant term goes away */ self->nc--; for (cpl_size i = 0; i < self->nc; i++) { - self->coef[i].val = (double)(i+1) * self->coef[i + 1].val; + self->coef[i].val = (double)(i + 1) * self->coef[i + 1].val; } - cpl_tools_add_flops( self->nc ); + cpl_tools_add_flops(self->nc); } return self->nc == 0 ? CPL_TRUE : CPL_FALSE; @@ -3451,15 +4663,15 @@ @param stream Output stream eq. @c stdout or @c stderr @param value The coefficient @return CPL_ERROR_NONE or the relevant #_cpl_error_code_ - @note pows not accessed (and zeros used instead) on zero valued coefficient @see cpl_polynomial_dump() */ /*----------------------------------------------------------------------------*/ -static cpl_error_code cpl_polynomial_dump_coeff(const cpl_size * pows, - cpl_size dim, - FILE * stream, - double value) +static cpl_error_code +cpl_polynomial_dump_coeff(const cpl_size *pows, + cpl_size dim, + FILE *stream, + double value) { int retval; @@ -3480,8 +4692,7 @@ @internal @brief Swap the given dimension with the lowest one @param self The (empty) polynomial to hold the result - @param mypow The power of this dimension, aliased with pows + mydim - @param mydim This dimension, zero for deepest + @param mydim This dimension, zero for lowest @param pows The non-negative power(s) of the variable(s) @param dim The positive polynomial dimension (number of variables) @param other The polynomial to read from @@ -3490,31 +4701,34 @@ */ /*----------------------------------------------------------------------------*/ -inline static void cpl_polynomial_transpose_(cpl_polynomial_1d * self, - cpl_size * mypow, - cpl_size mydim, - const cpl_size * pows, - cpl_size dim, - const cpl_polynomial_1d * other, - cpl_size dodim) +inline static void +cpl_polynomial_transpose_(cpl_polynomial_1d *self, + cpl_size mydim, + cpl_size *pows, + cpl_size dim, + const cpl_polynomial_1d *other, + cpl_size dodim) { - if (mydim == 0) { for (cpl_size i = 0; i < other->nc; i++) { const double value = other->coef[i].val; if (value != 0.0) { - mypow[dodim] = i; + /* Write the zero'th dimension into the dimension to swap */ + pows[dodim] = i; + (void)cpl_polynomial_set_coeff_(self, pows, dim - 1, value); } } - } else { + } + else { for (cpl_size i = 0; i < other->nc; i++) { - if (other->coef[i].next == NULL) continue; + if (other->coef[i].next == NULL) + continue; /* Write the dimension to swap into zero'th place */ - *(mydim == dodim ? mypow - mydim : mypow) = i; + pows[mydim == dodim ? 0 : mydim] = i; - cpl_polynomial_transpose_(self, mypow - 1, mydim - 1, pows, - dim, other->coef[i].next, dodim); + cpl_polynomial_transpose_(self, mydim - 1, pows, dim, + other->coef[i].next, dodim); } } } @@ -3522,93 +4736,50 @@ /*----------------------------------------------------------------------------*/ /** @internal - @brief Dump a polynomial as ASCII to a stream, fail on zero-polynomial(s) + @brief Dump a polynomial as ASCII to a stream @param self The polynomial to process - @param mypow The power of this dimension, aliased with pows + mydim - @param mydim This dimension, zero for deepest + @param mydim This dimension, zero for lowest @param pows The non-negative power(s) of the variable(s) @param dim The positive polynomial dimension (number of variables) @param ncoeff Counter of non-zero coefficients @param stream Output stream eq. @c stdout or @c stderr @return CPL_ERROR_NONE or the relevant #_cpl_error_code_ - @note Since this function is mostly for testing, it checks for illegal - sub-zero-polynomials and sets a CPL error if one is found @see cpl_polynomial_dump() */ /*----------------------------------------------------------------------------*/ -static cpl_error_code cpl_polynomial_dump_(const cpl_polynomial_1d * self, - cpl_size * mypow, - cpl_size mydim, - const cpl_size * pows, - cpl_size dim, - cpl_size * ncoeff, - FILE * stream) -{ - - if (self->nc == 0) { - const cpl_size edim = dim - mydim - 1; - if (mydim < dim) { - *mypow = 0; - if (cpl_polynomial_dump_coeff(pows + mydim, dim - mydim, stream, 0.0)) - return cpl_error_set_where_(); - } - return cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, "Polynomial of " - "dimension %d contains a zero-valued %d-" - "dimensional polynomial in dimension %d", - (int)dim, (int)edim, (int)mydim+ 1); - } else if (mydim == 0) { +static cpl_error_code +cpl_polynomial_dump_(const cpl_polynomial_1d *self, + cpl_size mydim, + cpl_size *pows, + cpl_size dim, + cpl_size *ncoeff, + FILE *stream) +{ + if (mydim == 0) { for (cpl_size i = 0; i < self->nc; i++) { - const double value = self->coef[i].val; - cpl_boolean doit = CPL_FALSE; - cpl_error_code code = CPL_ERROR_NONE; - - *mypow = i; - assert(pows[mydim] == i); + const double value = self->coef[i].val; if (value != 0.0) { + pows[mydim] = i; + ++*ncoeff; - doit = CPL_TRUE; - } else if (i + 1 == self->nc) { - /* Leading must be non-zero */ - doit = CPL_TRUE; - code = cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, - "Polynomial of dimension %d " - "contains a zero-valued leading " - "coefficient at power %d in the " - "lowest dimension", (int)dim, - (int)i); - } - if (doit && cpl_polynomial_dump_coeff(pows, dim, stream, value)) - return cpl_error_set_where_(); - if (code) return code; + + if (cpl_polynomial_dump_coeff(pows, dim, stream, value)) { + return cpl_error_set_where_(); + } + } } - } else { + } + else { for (cpl_size i = 0; i < self->nc; i++) { + if (self->coef[i].next != NULL) { + pows[mydim] = i; - *mypow = i; - assert(pows[mydim] == i); - - if (self->coef[i].next == NULL) { - /* Leading must be non-zero */ - if (i + 1 == self->nc) { - const cpl_error_code code = - cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, - "Polynomial of dimension %d " - "contains a zero-valued leading " - "coefficient at power %d in " - "dimension %d", (int)dim, - (int)i, (int)mydim + 1); - - if (cpl_polynomial_dump_coeff(pows + mydim, dim - mydim, - stream, 0.0)) - return cpl_error_set_where_(); - return code; + if (cpl_polynomial_dump_(self->coef[i].next, mydim - 1, pows, + dim, ncoeff, stream)) { + return cpl_error_set_where_(); } - } else if (cpl_polynomial_dump_(self->coef[i].next, - mypow - 1, mydim - 1, - pows, dim, ncoeff, stream)) { - return cpl_error_set_where_(); } } } @@ -3623,28 +4794,28 @@ @brief Get a coefficient of the polynomial @param self The polynomial to modify @param pows The non-negative power(s) of the variable(s) - @param mydim This dimension, zero for deepest + @param mydim This dimension, zero for lowest @return The coefficient, or zero for not found @note Input with NULL/member nc == 0 means zero-polynomial @see cpl_polynomial_get_coeff */ /*----------------------------------------------------------------------------*/ -inline static double cpl_polynomial_get_coeff_(const cpl_polynomial_1d * self, - const cpl_size * pows, - cpl_size mydim) +inline static double +cpl_polynomial_get_coeff_(const cpl_polynomial_1d *self, + const cpl_size *pows, + cpl_size mydim) { double value = 0.0; - assert(mydim >= 0); + assert(mydim >= 0); assert(pows[mydim] >= 0); if (self != NULL && pows[mydim] < self->nc) { - value = mydim == 0 - ? self->coef[pows[mydim]].val - : cpl_polynomial_get_coeff_(self->coef[pows[mydim]].next, - pows, mydim - 1); + ? self->coef[pows[mydim]].val + : cpl_polynomial_get_coeff_(self->coef[pows[mydim]].next, + pows, mydim - 1); } return value; @@ -3663,17 +4834,17 @@ */ /*----------------------------------------------------------------------------*/ -inline static -cpl_long_double cpl_polynomial_nested_horner(const cpl_polynomial_1d * self, - double a, - double b, - cpl_long_double * ppa) +inline static cpl_long_double +cpl_polynomial_nested_horner(const cpl_polynomial_1d *self, + double a, + double b, + cpl_long_double *ppa) { - cpl_size i = self->nc - 1; + cpl_size i = self->nc - 1; cpl_long_double pa = self->coef[i].val; cpl_long_double pb = pa; - cpl_tools_add_flops( 4 * i ); + cpl_tools_add_flops(4 * i); while (i > 1) { pa = pa * a + self->coef[--i].val; @@ -3688,7 +4859,7 @@ /*----------------------------------------------------------------------------*/ /** @internal - @brief Evaluate a univariate (1D) polynomial using Horners rule. + @brief Evaluate a univariate (1D) polynomial using Horner's rule. @param self The 1D-polynomial @param x The point of evaluation @param pd Iff pd is non-NULL, the derivative evaluated at x @@ -3697,10 +4868,8 @@ */ /*----------------------------------------------------------------------------*/ -inline static -cpl_long_double cpl_polynomial_eval_1d_(const cpl_polynomial_1d * self, - double x, - double * pd) +inline static cpl_long_double +cpl_polynomial_eval_1d_(const cpl_polynomial_1d *self, double x, double *pd) { cpl_long_double result; @@ -3711,13 +4880,15 @@ result = self->coef[i].val; - cpl_tools_add_flops( 2 * i ); - - while (i) result = x * result + self->coef[--i].val; + cpl_tools_add_flops(2 * i); - } else if (self->nc > 1) { + while (i) + result = x * result + self->coef[--i].val; + } + else if (self->nc > 1) { *pd = (double)cpl_polynomial_nested_horner(self, x, x, &result); - } else { + } + else { result = self->coef[0].val; *pd = 0.0; } @@ -3730,7 +4901,7 @@ @internal @brief Evaluate the polynomial at the given point, using Horner's rule @param self The polynomial to access - @param mydim This dimension, zero for deepest + @param mydim This dimension, zero for lowest @param px Point of evaluation, lowest dimension variable is at px[0] @return The computed value or undefined on error. @see cpl_polynomial_eval() @@ -3738,18 +4909,18 @@ */ /*----------------------------------------------------------------------------*/ -inline static -cpl_long_double cpl_polynomial_eval_(const cpl_polynomial_1d * self, - cpl_size mydim, - const double * px) +inline static cpl_long_double +cpl_polynomial_eval_(const cpl_polynomial_1d *self, + cpl_size mydim, + const double *px) { cpl_long_double result = 0.0; if (self != NULL && self->nc > 0) { - if (mydim == 0) { result = cpl_polynomial_eval_1d_(self, *px, NULL); - } else { + } + else { cpl_size i = self->nc - 1; assert(self->coef[i].next != NULL); @@ -3759,7 +4930,8 @@ cpl_tools_add_flops(2 * i); while (i) { - result = px[mydim] * result + + result = + px[mydim] * result + cpl_polynomial_eval_(self->coef[--i].next, mydim - 1, px); } } @@ -3782,22 +4954,22 @@ */ /*----------------------------------------------------------------------------*/ -double cpl_polynomial_eval_monomial(const cpl_polynomial * self, - const cpl_vector * x) +double +cpl_polynomial_eval_monomial(const cpl_polynomial *self, const cpl_vector *x) { cpl_long_double result = 0.0; cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1.0); - cpl_ensure(x != NULL, CPL_ERROR_NULL_INPUT, -2.0); + cpl_ensure(x != NULL, CPL_ERROR_NULL_INPUT, -2.0); cpl_ensure(self->dim == cpl_vector_get_size_(x), CPL_ERROR_INCOMPATIBLE_INPUT, -3.0); if (self->tree != NULL) { - cpl_size * pows = cpl_malloc((size_t)self->dim * sizeof(*pows)); + cpl_size *pows = cpl_malloc((size_t)self->dim * sizeof(*pows)); - cpl_polynomial_eval_monomial_(self->tree, pows + self->dim - 1, - self->dim - 1, pows, self->dim, - cpl_vector_get_data_const_(x), &result); + cpl_polynomial_eval_monomial_(self->tree, self->dim - 1, pows, + self->dim, cpl_vector_get_data_const_(x), + &result); cpl_free(pows); } @@ -3809,8 +4981,7 @@ @internal @brief Evaluate the polynomial at the given point one monomial at a time @param self The polynomial to access - @param mypow The power of this dimension, aliased with pows + mydim - @param mydim This dimension, zero for deepest + @param mydim This dimension, zero for lowest @param pows The non-negative power(s) of the variable(s) @param dim The positive polynomial dimension (number of variables) @param px Point of evaluation @@ -3821,21 +4992,20 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_polynomial_eval_monomial_(const cpl_polynomial_1d * self, - cpl_size * mypow, - cpl_size mydim, - const cpl_size * pows, - cpl_size dim, - const double * px, - cpl_long_double * presult) +static void +cpl_polynomial_eval_monomial_(const cpl_polynomial_1d *self, + cpl_size mydim, + cpl_size *pows, + cpl_size dim, + const double *px, + cpl_long_double *presult) { if (self != NULL && self->nc > 0) { if (mydim == 0) { for (cpl_size i = 0; i < self->nc; i++) { cpl_long_double monomial = self->coef[i].val; if (monomial != 0.0) { - *mypow = i; - assert(pows[mydim] == i); + pows[mydim] = i; for (cpl_size j = 0; j < dim; j++) { monomial *= cpl_tools_ipow(px[j], pows[j]); @@ -3844,14 +5014,12 @@ } } cpl_tools_add_flops(self->nc * (1 + dim)); /* Approximate */ - } else { + } + else { for (cpl_size i = 0; i < self->nc; i++) { + pows[mydim] = i; - *mypow = i; - assert(pows[mydim] == i); - - cpl_polynomial_eval_monomial_(self->coef[i].next, - mypow - 1, mydim - 1, + cpl_polynomial_eval_monomial_(self->coef[i].next, mydim - 1, pows, dim, px, presult); } } @@ -3864,29 +5032,29 @@ @param self The polynomial to hold the result @param first The 1st polynomial to add, or NULL @param second The 2nd polynomial to add, or NULL - @param mydim This dimension, zero for deepest + @param mydim This dimension, zero for lowest @return CPL_TRUE iff the operation collapsed the dimension to zero @note self may be passed also as first and/or second @see cpl_polynomial_add() @note Input with NULL/member nc == 0 means zero-polynomial */ /*----------------------------------------------------------------------------*/ -static cpl_boolean cpl_polynomial_add_(cpl_polynomial_1d * self, - const cpl_polynomial_1d * first, - const cpl_polynomial_1d * second, - cpl_size mydim) +static cpl_boolean +cpl_polynomial_add_(cpl_polynomial_1d *self, + const cpl_polynomial_1d *first, + const cpl_polynomial_1d *second, + cpl_size mydim) { cpl_boolean do_del = CPL_FALSE; if (first != NULL || second != NULL) { - const cpl_size nfirst = first == NULL ? 0 : first->nc; + const cpl_size nfirst = first == NULL ? 0 : first->nc; const cpl_size nsecond = second == NULL ? 0 : second->nc; - const cpl_size nmin = CPL_MIN(nfirst, nsecond); - const cpl_size nmax = CPL_MAX(nfirst, nsecond); + const cpl_size nmin = CPL_MIN(nfirst, nsecond); + const cpl_size nmax = CPL_MAX(nfirst, nsecond); cpl_size i = 0; if (mydim == 0) { - if (self->nc < nmax) { cpl_polynomial_grow_1d(self, nmax); } @@ -3898,10 +5066,11 @@ if (i < nsecond) { if (self->coef != second->coef) (void)memcpy(self->coef + i, second->coef + i, - (size_t)(nsecond - i) * sizeof(*self->coef)); + (size_t)(nsecond - i) * sizeof(*self->coef)); i = nsecond; assert(i == second->nc); - } else if (i < nfirst) { + } + else if (i < nfirst) { if (self->coef != first->coef) (void)memcpy(self->coef + i, first->coef + i, (size_t)(nfirst - i) * sizeof(*self->coef)); @@ -3909,9 +5078,9 @@ assert(i == first->nc); } - cpl_tools_add_flops( nmin ); - } else { - + cpl_tools_add_flops(nmin); + } + else { if (self->nc < nmax) { /* Need to reset new elements to NULL */ cpl_polynomial_grow_1d_reset(self, nmax, 0); @@ -3919,14 +5088,12 @@ for (; i < nmin; i++) { if (self->coef[i].next == NULL) - self->coef[i].next = - cpl_polynomial_new_1d(CPL_MAX(first->coef[i].next->nc, - second->coef[i].next->nc)); + self->coef[i].next = cpl_polynomial_new_1d( + CPL_MAX(first->coef[i].next->nc, + second->coef[i].next->nc)); - if (cpl_polynomial_add_(self->coef[i].next, - first->coef[i].next, - second->coef[i].next, - mydim - 1)) { + if (cpl_polynomial_add_(self->coef[i].next, first->coef[i].next, + second->coef[i].next, mydim - 1)) { cpl_polynomial_delete_(self->coef[i].next, mydim - 1); self->coef[i].next = NULL; } @@ -3938,27 +5105,24 @@ self->coef[i].next = cpl_polynomial_new_1d(second->coef[i].next->nc); - cpl_polynomial_copy_(self->coef[i].next, - mydim - 1, - second->coef[i].next, - mydim - 1); + cpl_polynomial_copy_(self->coef[i].next, mydim - 1, + second->coef[i].next, mydim - 1); } for (; i < nfirst; i++) { if (self->coef[i].next == NULL) self->coef[i].next = cpl_polynomial_new_1d(first->coef[i].next->nc); - cpl_polynomial_copy_(self->coef[i].next, - mydim - 1, - first->coef[i].next, - mydim - 1); + cpl_polynomial_copy_(self->coef[i].next, mydim - 1, + first->coef[i].next, mydim - 1); } } /* Adjust degree of self and */ /* Delete zero-valued leading coefficients */ if (cpl_polynomial_prune_(self, mydim, i)) do_del = CPL_TRUE; - } else { + } + else { do_del = CPL_TRUE; } return do_del; @@ -3971,28 +5135,28 @@ @param self The polynomial to hold the result @param first The polynomial to subtract from, or NULL @param second The polynomial to subtract, or NULL - @param mydim This dimension, zero for deepest + @param mydim This dimension, zero for lowest @return CPL_TRUE iff the operation collapsed the dimension to zero @note self may be passed also as first and/or second @see cpl_polynomial_add_() @note Input with NULL/member nc == 0 means zero-polynomial */ /*----------------------------------------------------------------------------*/ -static cpl_boolean cpl_polynomial_subtract_(cpl_polynomial_1d * self, - const cpl_polynomial_1d * first, - const cpl_polynomial_1d * second, - cpl_size mydim) +static cpl_boolean +cpl_polynomial_subtract_(cpl_polynomial_1d *self, + const cpl_polynomial_1d *first, + const cpl_polynomial_1d *second, + cpl_size mydim) { cpl_boolean do_del = CPL_FALSE; if (first != NULL || second != NULL) { - const cpl_size nfirst = first == NULL ? 0 : first->nc; + const cpl_size nfirst = first == NULL ? 0 : first->nc; const cpl_size nsecond = second == NULL ? 0 : second->nc; - const cpl_size nmin = CPL_MIN(nfirst, nsecond); + const cpl_size nmin = CPL_MIN(nfirst, nsecond); cpl_size i = 0; if (mydim == 0) { - if (self->nc < CPL_MAX(nfirst, nsecond)) cpl_polynomial_grow_1d(self, CPL_MAX(nfirst, nsecond)); @@ -4002,23 +5166,24 @@ if (i < nsecond) { /* First operand is zero, so just negate the other */ for (; i < nsecond; i++) - self->coef[i].val = - second->coef[i].val; + self->coef[i].val = -second->coef[i].val; assert(i == second->nc); self->nc = i; /* Adjust degree of self */ - } else if (i < nfirst) { + } + else if (i < nfirst) { /* Second operand is zero, so just copy the first */ if (self->coef != first->coef) (void)memcpy(self->coef + i, first->coef + i, - (size_t)(nfirst - i) * sizeof(*self->coef)); + (size_t)(nfirst - i) * sizeof(*self->coef)); i = nfirst; assert(i == first->nc); self->nc = i; /* Adjust degree of self */ } - cpl_tools_add_flops( nmin ); - } else { - + cpl_tools_add_flops(nmin); + } + else { if (self->nc < CPL_MAX(nfirst, nsecond)) { /* Need to reset new elements to NULL */ cpl_polynomial_grow_1d_reset(self, CPL_MAX(nfirst, nsecond), 0); @@ -4026,14 +5191,13 @@ for (; i < nmin; i++) { if (self->coef[i].next == NULL) - self->coef[i].next = - cpl_polynomial_new_1d(CPL_MAX(first->coef[i].next->nc, - second->coef[i].next->nc)); + self->coef[i].next = cpl_polynomial_new_1d( + CPL_MAX(first->coef[i].next->nc, + second->coef[i].next->nc)); if (cpl_polynomial_subtract_(self->coef[i].next, - first->coef[i].next, - second->coef[i].next, - mydim - 1)) { + first->coef[i].next, + second->coef[i].next, mydim - 1)) { cpl_polynomial_delete_(self->coef[i].next, mydim - 1); self->coef[i].next = NULL; } @@ -4045,10 +5209,8 @@ self->coef[i].next = cpl_polynomial_new_1d(second->coef[i].next->nc); - if (cpl_polynomial_subtract_(self->coef[i].next, - NULL, - second->coef[i].next, - mydim - 1)) { + if (cpl_polynomial_subtract_(self->coef[i].next, NULL, + second->coef[i].next, mydim - 1)) { cpl_polynomial_delete_(self->coef[i].next, mydim - 1); self->coef[i].next = NULL; } @@ -4059,17 +5221,16 @@ self->coef[i].next = cpl_polynomial_new_1d(first->coef[i].next->nc); - cpl_polynomial_copy_(self->coef[i].next, - mydim - 1, - first->coef[i].next, - mydim - 1); + cpl_polynomial_copy_(self->coef[i].next, mydim - 1, + first->coef[i].next, mydim - 1); } } /* Adjust degree of self and */ /* Delete zero-valued leading coefficients */ if (cpl_polynomial_prune_(self, mydim, i)) do_del = CPL_TRUE; - } else { + } + else { do_del = CPL_TRUE; } return do_del; @@ -4082,7 +5243,7 @@ @brief Multiply a polynomial with a scalar @param self The polynomial to hold the result @param other The polynomial to scale of same dimension, may equal self - @param mydim This dimension, zero for deepest + @param mydim This dimension, zero for lowest @param factor The non-zero factor to multiply with @return void @note self and other may be aliased, must be non-NULL. member nc == 0 is OK. @@ -4090,10 +5251,11 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_polynomial_multiply_scalar_(cpl_polynomial_1d * self, - const cpl_polynomial_1d * other, - cpl_size mydim, - double factor) +static void +cpl_polynomial_multiply_scalar_(cpl_polynomial_1d *self, + const cpl_polynomial_1d *other, + cpl_size mydim, + double factor) { if (mydim == 0) { if (self->nc < other->nc) { @@ -4105,13 +5267,15 @@ for (cpl_size i = 0; i < self->nc; i++) { self->coef[i].val = factor * other->coef[i].val; } - cpl_tools_add_flops( self->nc ); - } else { + cpl_tools_add_flops(self->nc); + } + else { if (self->nc < other->nc) { /* Self is too short, grow */ cpl_polynomial_grow_1d_reset(self, other->nc, 0); self->nc = other->nc; - } else { + } + else { while (self->nc > other->nc) { /* Self is too long, shrink */ self->nc--; @@ -4126,12 +5290,13 @@ continue; } - if (self->coef[i].next == NULL) self->coef[i].next = - cpl_polynomial_new_1d(other->coef[i].next->nc); + if (self->coef[i].next == NULL) + self->coef[i].next = + cpl_polynomial_new_1d(other->coef[i].next->nc); cpl_polynomial_multiply_scalar_(self->coef[i].next, - other->coef[i].next, - mydim - 1, factor); + other->coef[i].next, mydim - 1, + factor); } } assert(self->nc == other->nc); @@ -4142,7 +5307,7 @@ @internal @brief Multiply a polynomial with a scalar @param self The polynomial to scale, or NULL - @param mydim This dimension, zero for deepest + @param mydim This dimension, zero for lowest @param factor The non-zero factor to multiply with @return void @note member nc == 0 is OK. @@ -4150,17 +5315,19 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_polynomial_multiply_scalar_self(cpl_polynomial_1d * self, - cpl_size mydim, - double factor) +static void +cpl_polynomial_multiply_scalar_self(cpl_polynomial_1d *self, + cpl_size mydim, + double factor) { if (self != NULL) { if (mydim == 0) { for (cpl_size i = 0; i < self->nc; i++) { self->coef[i].val *= factor; } - cpl_tools_add_flops( self->nc ); - } else { + cpl_tools_add_flops(self->nc); + } + else { for (cpl_size i = 0; i < self->nc; i++) { cpl_polynomial_multiply_scalar_self(self->coef[i].next, mydim - 1, factor); @@ -4175,7 +5342,7 @@ @brief Scale a polynomial and add it to another of the same dimension @param self The polynomial to add to @param second The polynomial to scale and add, or NULL - @param mydim This dimension, zero for deepest + @param mydim This dimension, zero for lowest @param factor The monomial scaling factor @param pows The non-negative power(s) of the monomial @return CPL_TRUE iff the operation collapsed the dimension to zero @@ -4183,11 +5350,12 @@ @see cpl_polynomial_add() */ /*----------------------------------------------------------------------------*/ -static cpl_boolean cpl_polynomial_scale_add_(cpl_polynomial_1d * self, - const cpl_polynomial_1d * second, - cpl_size mydim, - double factor, - const cpl_size * pows) +static cpl_boolean +cpl_polynomial_scale_add_(cpl_polynomial_1d *self, + const cpl_polynomial_1d *second, + cpl_size mydim, + double factor, + const cpl_size *pows) { cpl_boolean do_del = CPL_FALSE; @@ -4206,16 +5374,18 @@ cpl_polynomial_grow_1d_reset(self, second->nc + pows[mydim], 0); for (; i < second->nc; i++) - self->coef[i + pows[mydim]].val - = factor * second->coef[i].val; + self->coef[i + pows[mydim]].val = + factor * second->coef[i].val; cpl_tools_add_flops(second->nc + self->nc); assert(i == second->nc); self->nc = second->nc + pows[mydim]; /* Adjust degree of self */ - } else { + } + else { cpl_tools_add_flops(2 * self->nc); } - } else { + } + else { cpl_size i; assert(mydim > 0); @@ -4230,13 +5400,12 @@ for (i = 0; i < second->nc; i++) { if (self->coef[i + pows[mydim]].next == NULL) - self->coef[i + pows[mydim]].next = - cpl_polynomial_new_1d(second->coef[i].next->nc - + pows[mydim - 1]); + self->coef[i + pows[mydim]].next = cpl_polynomial_new_1d( + second->coef[i].next->nc + pows[mydim - 1]); if (cpl_polynomial_scale_add_(self->coef[i + pows[mydim]].next, - second->coef[i].next, - mydim - 1, factor, pows)) { + second->coef[i].next, mydim - 1, + factor, pows)) { cpl_polynomial_delete_(self->coef[i + pows[mydim]].next, mydim - 1); self->coef[i + pows[mydim]].next = NULL; @@ -4246,8 +5415,9 @@ /* Delete zero-valued leading coefficients */ if (cpl_polynomial_prune_(self, mydim, self->nc)) do_del = CPL_TRUE; - } else { - do_del = CPL_TRUE; + } + else { + do_del = CPL_TRUE; } return do_del; } @@ -4260,8 +5430,7 @@ @param self The polynomial to hold the result, at top-level @param first The 1st polynomial to multiply, at top-level @param second The 2nd polynomial to multiply - @param mypow The power of this dimension, aliased with pows + mydim - @param mydim This dimension, zero for deepest + @param mydim This dimension, zero for lowest @param pows The non-negative power(s) of the variable(s) of second @param dim The positive polynomial dimension (number of variables) @return void @@ -4273,25 +5442,25 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_polynomial_multiply_(cpl_polynomial_1d * self, - const cpl_polynomial_1d * first, - const cpl_polynomial_1d * second, - cpl_size * mypow, - cpl_size mydim, - const cpl_size * pows, - cpl_size dim) +static void +cpl_polynomial_multiply_(cpl_polynomial_1d *self, + const cpl_polynomial_1d *first, + const cpl_polynomial_1d *second, + cpl_size mydim, + cpl_size *pows, + cpl_size dim) { if (mydim == 0) { for (cpl_size i = 0; i < second->nc; i++) { const double value = second->coef[i].val; if (value != 0.0) { - *mypow = i; + pows[mydim] = i; /* Multiply the monomial element of the second polynomial onto the first and add the result to self */ - if (cpl_polynomial_scale_add_(self, first, dim - 1, - value, pows)) { + if (cpl_polynomial_scale_add_(self, first, dim - 1, value, + pows)) { /* FIXME: This branch is untested. Can this point actually be reached ?! */ @@ -4299,14 +5468,15 @@ } } } - } else { + } + else { for (cpl_size i = 0; i < second->nc; i++) { - if (second->coef[i].next == NULL) continue; - *mypow = i; + if (second->coef[i].next == NULL) + continue; + pows[mydim] = i; cpl_polynomial_multiply_(self, first, second->coef[i].next, - mypow - 1, mydim - 1, - pows, dim); + mydim - 1, pows, dim); } } } @@ -4316,7 +5486,7 @@ @internal @brief Modify self, self(x0, x1, ..., xn) := (x0+u, x1, ..., xn) @param self The polynomial to be modified in place - @param mydim This dimension, zero for deepest + @param mydim This dimension, zero for lowest @param u The shift @return void @see cpl_polynomial_shift_1d() @@ -4324,26 +5494,27 @@ */ /*----------------------------------------------------------------------------*/ -inline static void cpl_polynomial_shift_1d_(cpl_polynomial_1d * self, - cpl_size mydim, - double u) +inline static void +cpl_polynomial_shift_1d_(cpl_polynomial_1d *self, cpl_size mydim, double u) { if (mydim > 0) { for (cpl_size i = 0; i < self->nc; i++) { - if (self->coef[i].next == NULL) continue; + if (self->coef[i].next == NULL) + continue; cpl_polynomial_shift_1d_(self->coef[i].next, mydim - 1, u); } - } else { + } + else { #ifdef CPL_POLYNOMIAL_UNION_IS_DOUBLE_SZ cpl_polynomial_shift_double(&(self->coef[0].val), self->nc, u); #else for (cpl_size j = 0; j < self->nc - 1; j++) for (cpl_size i = 1; i < self->nc - j; i++) - self->coef[self->nc - 1 - i].val += + self->coef[self->nc - 1 - i].val += self->coef[self->nc - i].val * u; - cpl_tools_add_flops( n * ( n - 1) ); + cpl_tools_add_flops(n * (n - 1)); #endif } } @@ -4361,11 +5532,12 @@ @see cpl_polynomial_extract() */ /*----------------------------------------------------------------------------*/ -static cpl_boolean cpl_polynomial_extract_(cpl_polynomial_1d * self, - const cpl_polynomial_1d * other, - cpl_size mydim, - cpl_size dodim, - double value) +static cpl_boolean +cpl_polynomial_extract_(cpl_polynomial_1d *self, + const cpl_polynomial_1d *other, + cpl_size mydim, + cpl_size dodim, + double value) { cpl_boolean do_del = CPL_FALSE; @@ -4375,16 +5547,16 @@ /* When value is zero, only the constant term survives */ const cpl_size icopy = value != 0.0 ? other->nc - 1 : 0; - cpl_polynomial_copy_(self, mydim - 1, - other->coef[icopy].next, mydim - 1); + cpl_polynomial_copy_(self, mydim - 1, other->coef[icopy].next, + mydim - 1); for (cpl_size i = icopy; i > 0; i--) { cpl_polynomial_multiply_scalar_self(self, mydim - 1, value); - if (other->coef[i-1].next == NULL) continue; + if (other->coef[i - 1].next == NULL) + continue; - cpl_polynomial_add_(self, self, other->coef[i-1].next, - mydim - 1); + cpl_polynomial_add_(self, self, other->coef[i - 1].next, mydim - 1); } if (icopy > 0) { @@ -4394,7 +5566,8 @@ if (cpl_polynomial_prune_(self, mydim - 1, self->nc)) do_del = CPL_TRUE; } - } else if (mydim == 1) { + } + else if (mydim == 1) { /* Collapse the lowest dimension into the current one, ignoring all leading coefficients that evaluate to zero */ @@ -4405,7 +5578,7 @@ assert(self->nz >= other->nc); for (; i > 0; i--) { - const double leading = cpl_polynomial_eval_(other->coef[i-1].next, + const double leading = cpl_polynomial_eval_(other->coef[i - 1].next, mydim - 1, &value); if (leading != 0.0) { self->nc = i; @@ -4416,23 +5589,25 @@ } for (; i > 0; i--) { - self->coef[i-1].val = cpl_polynomial_eval_(other->coef[i-1].next, - mydim - 1, &value); + self->coef[i - 1].val = + cpl_polynomial_eval_(other->coef[i - 1].next, mydim - 1, + &value); } do_del = self->nc == 0; - } else { + } + else { assert(mydim > 1); /* Copy this dimension */ for (cpl_size i = 0; i < other->nc; i++) { if (other->coef[i].next == NULL) { self->coef[i].next = NULL; - } else { + } + else { self->coef[i].next = cpl_polynomial_new_1d(other->coef[i].next->nc); if (cpl_polynomial_extract_(self->coef[i].next, - other->coef[i].next, - mydim - 1, + other->coef[i].next, mydim - 1, dodim, value)) { assert(self->coef[i].next->nc == 0); cpl_polynomial_delete_(self->coef[i].next, mydim - 1); @@ -4447,3 +5622,5 @@ } return do_del; } + +/**@}*/ diff -Nru cpl-7.1.4+ds/cplcore/cpl_polynomial.h cpl-7.2.2+ds/cplcore/cpl_polynomial.h --- cpl-7.1.4+ds/cplcore/cpl_polynomial.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_polynomial.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -43,27 +43,28 @@ -----------------------------------------------------------------------------*/ /* cpl_polynomial handling */ -cpl_polynomial * cpl_polynomial_new(cpl_size) CPL_ATTR_ALLOC; +cpl_polynomial *cpl_polynomial_new(cpl_size) CPL_ATTR_ALLOC; void cpl_polynomial_delete(cpl_polynomial *); cpl_error_code cpl_polynomial_dump(const cpl_polynomial *, FILE *); -cpl_polynomial * cpl_polynomial_duplicate(const cpl_polynomial *) - CPL_ATTR_ALLOC; +cpl_polynomial *cpl_polynomial_duplicate(const cpl_polynomial *) CPL_ATTR_ALLOC; cpl_error_code cpl_polynomial_copy(cpl_polynomial *, const cpl_polynomial *); /* Accessor functions */ double cpl_polynomial_get_coeff(const cpl_polynomial *, const cpl_size *); -cpl_error_code cpl_polynomial_set_coeff(cpl_polynomial *, const cpl_size *, - double); +cpl_error_code +cpl_polynomial_set_coeff(cpl_polynomial *, const cpl_size *, double); /* Basic operations */ -int cpl_polynomial_compare(const cpl_polynomial *, const cpl_polynomial *, +int cpl_polynomial_compare(const cpl_polynomial *, + const cpl_polynomial *, double tol); cpl_size cpl_polynomial_get_dimension(const cpl_polynomial *); cpl_size cpl_polynomial_get_degree(const cpl_polynomial *); double cpl_polynomial_eval(const cpl_polynomial *, const cpl_vector *); -cpl_polynomial * cpl_polynomial_extract(const cpl_polynomial *, cpl_size, - const cpl_polynomial *) CPL_ATTR_ALLOC; +cpl_polynomial *cpl_polynomial_extract(const cpl_polynomial *, + cpl_size, + const cpl_polynomial *) CPL_ATTR_ALLOC; cpl_error_code cpl_polynomial_add(cpl_polynomial *, const cpl_polynomial *, @@ -78,47 +79,58 @@ const cpl_polynomial *); cpl_error_code cpl_polynomial_multiply_scalar(cpl_polynomial *, - const cpl_polynomial *, double); + const cpl_polynomial *, + double); cpl_error_code cpl_polynomial_derivative(cpl_polynomial *, cpl_size); -cpl_error_code cpl_polynomial_fit(cpl_polynomial *, - const cpl_matrix *, +cpl_error_code cpl_polynomial_fit(cpl_polynomial *, + const cpl_matrix *, const cpl_boolean *, - const cpl_vector *, - const cpl_vector *, - cpl_boolean , - const cpl_size *, - const cpl_size *); - -cpl_error_code cpl_vector_fill_polynomial_fit_residual(cpl_vector *, - const cpl_vector *, - const cpl_vector *, + const cpl_vector *, + const cpl_vector *, + cpl_boolean, + const cpl_size *, + const cpl_size *); + +cpl_error_code cpl_vector_fill_polynomial_fit_residual(cpl_vector *, + const cpl_vector *, + const cpl_vector *, const cpl_polynomial *, - const cpl_matrix *, + const cpl_matrix *, double *); /* Basic operations on 1d-polynomials */ double cpl_polynomial_eval_1d(const cpl_polynomial *, double, double *); -double cpl_polynomial_eval_1d_diff(const cpl_polynomial *, double, double, - double *); -cpl_error_code cpl_vector_fill_polynomial(cpl_vector *, const cpl_polynomial *, - double, double); -cpl_error_code cpl_polynomial_solve_1d(const cpl_polynomial *, double, double *, - cpl_size); +double +cpl_polynomial_eval_1d_diff(const cpl_polynomial *, double, double, double *); +cpl_error_code cpl_vector_fill_polynomial(cpl_vector *, + const cpl_polynomial *, + double, + double); +cpl_error_code +cpl_polynomial_solve_1d(const cpl_polynomial *, double, double *, cpl_size); cpl_error_code cpl_polynomial_shift_1d(cpl_polynomial *, cpl_size, double); -cpl_polynomial * cpl_polynomial_fit_1d_create(const cpl_vector *, - const cpl_vector *, cpl_size, - double *) CPL_ATTR_DEPRECATED; +cpl_polynomial *cpl_polynomial_fit_1d_create(const cpl_vector *, + const cpl_vector *, + cpl_size, + double *) CPL_ATTR_DEPRECATED; /* Basic operations on 2d-polynomials */ -cpl_polynomial * cpl_polynomial_fit_2d_create(const cpl_bivector *, - const cpl_vector *, - cpl_size, double *) - CPL_ATTR_DEPRECATED; +cpl_polynomial *cpl_polynomial_fit_2d_create(const cpl_bivector *, + const cpl_vector *, + cpl_size, + double *) CPL_ATTR_DEPRECATED; +double cpl_polynomial_eval_2d(const cpl_polynomial *, double, double, double *); + +/* Basic operations on 3d-polynomials */ +double cpl_polynomial_eval_3d(const cpl_polynomial *, + double, + double, + double, + double *); CPL_END_DECLS #endif - diff -Nru cpl-7.1.4+ds/cplcore/cpl_polynomial_impl.h cpl-7.2.2+ds/cplcore/cpl_polynomial_impl.h --- cpl-7.1.4+ds/cplcore/cpl_polynomial_impl.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_polynomial_impl.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -34,9 +34,9 @@ #undef CPL_POLYNOMIAL_UNION_IS_DOUBLE_SZ #if defined(SIZEOF_VOID_P) && defined(SIZEOF_DOUBLE) -# if SIZEOF_VOID_P <= SIZEOF_DOUBLE -# define CPL_POLYNOMIAL_UNION_IS_DOUBLE_SZ -# endif +#if SIZEOF_VOID_P <= SIZEOF_DOUBLE +#define CPL_POLYNOMIAL_UNION_IS_DOUBLE_SZ +#endif #endif /*----------------------------------------------------------------------------- @@ -45,23 +45,28 @@ void cpl_polynomial_empty(cpl_polynomial *); -cpl_error_code cpl_polynomial_fit_1d(cpl_polynomial *, const cpl_vector *, - const cpl_vector *, cpl_size, cpl_size, - cpl_boolean, double *); - -void cpl_polynomial_shift_double(double *, cpl_size, double) - CPL_ATTR_NONNULL; - -cpl_error_code cpl_polynomial_solve_1d_(const cpl_polynomial *, double, - double *, cpl_size, cpl_boolean); +cpl_error_code cpl_polynomial_fit_1d(cpl_polynomial *, + const cpl_vector *, + const cpl_vector *, + const cpl_vector *, + cpl_size, + cpl_size, + cpl_boolean, + double *); + +void cpl_polynomial_shift_double(double *, cpl_size, double) CPL_ATTR_NONNULL; + +cpl_error_code cpl_polynomial_solve_1d_(const cpl_polynomial *, + double, + double *, + cpl_size, + cpl_boolean); cpl_size cpl_polynomial_get_1d_size(const cpl_polynomial *) CPL_ATTR_PURE CPL_ATTR_NONNULL; -double cpl_polynomial_eval_monomial(const cpl_polynomial *, - const cpl_vector *); +double cpl_polynomial_eval_monomial(const cpl_polynomial *, const cpl_vector *); CPL_END_DECLS -#endif - +#endif diff -Nru cpl-7.1.4+ds/cplcore/cpl_property.c cpl-7.2.2+ds/cplcore/cpl_property.c --- cpl-7.1.4+ds/cplcore/cpl_property.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_property.c 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -18,7 +18,7 @@ */ #ifdef HAVE_CONFIG_H -# include +#include #endif /*----------------------------------------------------------------------------- @@ -90,12 +90,10 @@ @note Intended for use with cx_assert() @hideinitializer */ -#define CPL_PROPERTY_MEMBER_IS_OUTSIDE(SELF, MEMBER) \ - ((SELF)->MEMBER != NULL && \ - ((const char*)(SELF)->MEMBER < (const char*)(SELF) || \ - (const char*)(SELF)->MEMBER >= (const char*)(SELF) + sizeof(*self))) \ - -#define CPL_PROPERTY_SORT_UNDEF 0 +#define CPL_PROPERTY_MEMBER_IS_OUTSIDE(SELF, MEMBER) \ + ((SELF)->MEMBER != NULL && \ + ((const char *)(SELF)->MEMBER < (const char *)(SELF) || \ + (const char *)(SELF)->MEMBER >= (const char *)(SELF) + sizeof(*self))) /*----------------------------------------------------------------------------- New types @@ -120,9 +118,10 @@ stored right after the value. The memory layout of the struct can thus be visualized like this: - PPPPPVVCCCUUNNNN + PPPMMVVCCCUUNNNN - where each letter symbolizes (on 64-bit, 8 bytes for each capital letter): - P: Property triplet of pointers and meta-data, 40 bytes + P: Property triplet of pointers, 24 bytes + M: Property meta-data, 16 bytes V: Value (16 bytes, in this example) C: Comment string (24 bytes, in this example) U: Unused, undefined memory (16 bytes, in this example) @@ -136,107 +135,45 @@ One member of the struct is for supporting effective sorting of a list of n properties according to this key, which is then set prior to the sorting at complexity O(n), as opposed to O(n*log(n)) of the sorting itself. - This sorting key is just 1 byte, stored at the end where it does not - change the alignment of the value member. */ -typedef struct _cpl_property_ { - char * name; /* A property is always created with the name set */ - char * comment; /* NULL when not set */ - void * value; /* Null/all zero(s) before it is explicitly set */ - cpl_size size; /* Number of elements, 1 for non-array */ - uint32_t type; /* Property CPL-type (least significant 32 bits) */ - unsigned char vsize; /* Container storage used for value, or 0 [byte] */ - unsigned char nsize; /* Container storage used for name, or 0 [byte] */ - unsigned char csize; /* Container storage used for comment, or 0 [byte] */ - unsigned char ksort; /* The sorting key for efficient sorting */ - char data[CPL_PROPERTY_SIZE]; /* Container for a normal property */ +typedef struct _cpl_property_ +{ + /* The 3 pointer members must come first, also due to the update method */ + char *name; /* A property is always created with the name set */ + char *comment; /* NULL when not set */ + void *value; /* Null/all zero(s) before it is explicitly set */ + cpl_size size; /* Number of elements, 1 for non-array */ + uint32_t type; /* Property CPL-type (least significant 32 bits) */ + unsigned char vsize; /* Container storage used for value, or 0 [byte] */ + unsigned char nsize; /* Container storage used for name, or 0 [byte] */ + unsigned char csize; /* Container storage used for comment, or 0 [byte] */ + unsigned char ksort; /* The sorting key for efficient sorting [byte] */ + union + { /* Container for a normal property */ + char data[CPL_PROPERTY_SIZE]; + cpl_boolean bool; + int i; + long l; + long long ll; + float fp; + double dp; + float complex fc; + double complex dc; + } storage; } _cpl_property_; - -/*----------------------------------------------------------------------------*/ -/** - @enum cpl_property_dicbtype - @internal - @brief The FITS key types according to DICB - @note This enum may have no more than 256 entries, among which the value zero - is reserved to mean undefined. - - This enum stores all possible types for a FITS keyword. These determine - the order of appearance in a header, they are a crucial point for - DICB (ESO) compatibility. This classification is internal to this - module. - - */ -/*----------------------------------------------------------------------------*/ -typedef enum cpl_property_dicbtype { - CPL_DICB_UNDEF = CPL_PROPERTY_SORT_UNDEF, - - CPL_DICB_TOP, - - /* Mandatory keywords */ - /* All FITS files */ - CPL_DICB_BITPIX, - - /* Per the FITS standard, NAXISn can go from 1 to 999. */ - CPL_DICB_NAXIS, - CPL_DICB_NAXISn, - - /* Random groups only */ - CPL_DICB_GROUP, - /* Extensions */ - CPL_DICB_PCOUNT, - CPL_DICB_GCOUNT, - /* Main header */ - CPL_DICB_EXTEND, - /* Images */ - CPL_DICB_BSCALE, - CPL_DICB_BZERO, - /* Tables */ - CPL_DICB_TFIELDS, - - /* Per the FITS standard, TBCOLn is indexed and starts with 1 */ - CPL_DICB_TBCOLn, - - /* Per the FITS standard, TBCOLn is indexed and starts with 1 */ - CPL_DICB_TFORMn, - - /* Other primary keywords */ - CPL_DICB_PRIMARY, - - /* HIERARCH ESO keywords ordered according to DICB */ - /* Only the two first (3-letter) words count in the orderting */ - CPL_DICB_HIERARCH_DPR, - CPL_DICB_HIERARCH_OBS, - CPL_DICB_HIERARCH_TPL, - CPL_DICB_HIERARCH_GEN, - CPL_DICB_HIERARCH_TEL, - CPL_DICB_HIERARCH_INS, - CPL_DICB_HIERARCH_DET, - CPL_DICB_HIERARCH_LOG, - CPL_DICB_HIERARCH_PRO, - /* Other HIERARCH keywords */ - /* Only the first (3-letter "ESO") word count in the orderting */ - CPL_DICB_HIERARCH_ESO, - /* Except, in principle, there could be non-ESO cards */ - CPL_DICB_HIERARCH, - - /* HISTORY and COMMENT */ - CPL_DICB_HISTORY, - CPL_DICB_COMMENT, - /* END */ - CPL_DICB_END -} cpl_property_dicbtype; - /*----------------------------------------------------------------------------- Private function prototypes -----------------------------------------------------------------------------*/ -static cpl_property * -cpl_property_new_(const char *, cpl_type, cpl_size, size_t) +static cpl_property *cpl_property_new_(const char *, cpl_type, cpl_size, size_t) CPL_ATTR_ALLOC CPL_ATTR_NONNULL; +inline static void +cpl_property_update_(cpl_property *, const cpl_property *) CPL_ATTR_NONNULL; + /* * Private methods */ @@ -250,6 +187,7 @@ * @param type Property type flag. * @param size Property size, 1 for non-array type, string length for string * @param namelen Property name length (excl. terminating null), zero when NULL + * @note The comment memmber is NULL in a newly created property * * @return * The newly created property, or @c NULL if it could not be created. In the @@ -259,12 +197,14 @@ */ static cpl_property * -cpl_property_new_(const char *name, cpl_type type, cpl_size size, +cpl_property_new_(const char *name, + cpl_type type, + cpl_size size, size_t namelen) { cpl_property *self; - const size_t allocsz = 1 + namelen; /* Include terminating null-byte */ - size_t elemsz; + const size_t allocsz = 1 + namelen; /* Include terminating null-byte */ + size_t elemsz; /* Type size is 0 for invalid types */ @@ -281,7 +221,7 @@ } /* Allocate space for property and for typically sized name/value/comment */ - self = (cpl_property*)cx_malloc(sizeof(*self)); + self = (cpl_property *)cx_malloc(sizeof(*self)); self->type = (uint32_t)type; /* Ensure no data loss in truncated representation */ @@ -300,11 +240,11 @@ self->vsize = 0; self->size = size; /* Number of array elements */ - - } else { + } + else { /* Value is not an array - store inside struct */ - self->value = self->data; + self->value = self->storage.data; self->vsize = (unsigned char)elemsz; /* Ensure no data loss in truncated representation */ @@ -313,16 +253,17 @@ self->size = 1; /* Disregard caller supplied size, if any */ /* Clear memory of value */ - (void)memset(self->data, 0, self->vsize); + (void)memset(self->storage.data, 0, self->vsize); } - if (self->vsize + allocsz <= CPL_PROPERTY_SIZE) { - self->name = self->data + CPL_PROPERTY_SIZE - allocsz; + if (CPL_LIKELY(self->vsize + allocsz <= CPL_PROPERTY_SIZE)) { + self->name = self->storage.data + CPL_PROPERTY_SIZE - allocsz; self->nsize = allocsz; cx_assert((size_t)self->nsize == allocsz); /* Ensure no data loss */ - } else { + } + else { /* Name is too long... */ - self->name = (char*)cx_malloc(allocsz); + self->name = (char *)cx_malloc(allocsz); self->nsize = 0; } @@ -333,11 +274,9 @@ cx_assert(self->vsize + self->nsize + self->csize <= CPL_PROPERTY_SIZE); return self; - } - /** * @internal * @brief @@ -359,10 +298,10 @@ inline cpl_property * cpl_property_new_cx(const cpl_cstr *key, cpl_type type) { - cpl_property *self = cpl_property_new_(cx_string_get_(key), type, 1, - cx_string_size_(key)); + cpl_property *self = + cpl_property_new_(cx_string_get_(key), type, 1, cx_string_size_(key)); - if (self == NULL) { + if (CPL_UNLIKELY(self == NULL)) { (void)cpl_error_set_where_(); } @@ -422,7 +361,7 @@ self = cpl_property_new_(name, type, 1, strlen(name)); - if (self == NULL) { + if (CPL_UNLIKELY(self == NULL)) { (void)cpl_error_set_where_(); } @@ -488,7 +427,7 @@ self = cpl_property_new_(name, type, size, strlen(name)); - if (self == NULL) { + if (CPL_UNLIKELY(self == NULL)) { (void)cpl_error_set_where_(); } @@ -532,51 +471,87 @@ } /* Allocate and copy everything up to any value + comment, after which the - container may hold unused (and undefined) storage. If the name is stored - inside the container then it too will be copied, see below */ - self = memcpy(cx_malloc(sizeof(*self)), other, - sizeof(*self) - CPL_PROPERTY_SIZE - + other->vsize + other->csize); + container may hold unused (and undefined) storage. The name size is + copied here, the name itself is copied separately, see below */ + self = cx_malloc(sizeof(*self)); - /* Each of the three pointer members now need to be updated. */ + cpl_property_update_(self, other); - if (self->vsize > 0) { - /* Member is stored inside the container, data already copied */ - self->value = self->data; - } else if (other->value != NULL) { - /* Member is stored outside the container: + if (CPL_LIKELY(self->nsize > 0)) { + /* Member is stored inside the container, copy it and update pointer */ + self->name = + memcpy(self->storage.data + CPL_PROPERTY_SIZE - self->nsize, + other->storage.data + CPL_PROPERTY_SIZE - self->nsize, + self->nsize); + } + else { + /* Member is stored outside the container: Need to allocate, copy and update pointer */ + const size_t size = 1 + strlen(other->name); - const size_t mysize = cpl_type_get_sizeof((cpl_type)self->type); + cx_assert(CPL_PROPERTY_MEMBER_IS_OUTSIDE(other, name)); - const size_t size = self->size * mysize; + self->name = memcpy(cx_malloc(size), other->name, size); + } - cx_assert(CPL_PROPERTY_MEMBER_IS_OUTSIDE(other, value)); + return self; +} - self->value = memcpy(cx_malloc(size), other->value, size); - } else { - cx_assert(self->value == NULL); - } - if (self->nsize > 0) { - /* Member is stored inside the container, copy it and update pointer */ - self->name = memcpy(self->data + CPL_PROPERTY_SIZE - self->nsize, - other->data + CPL_PROPERTY_SIZE - self->nsize, - self->nsize); - } else { - /* Member is stored outside the container: +/** + * @internal + * @brief + * Update of a property, i.e. copy everything but the name + * + * @param self The property to be filled with everything but its name + * @param other The property to copy + * + * @return + * Nothing + * + * @note The property to be filled shall have no allocation for value + comment, + * the name pointer of the destination property is not overwritten. + * @see cpl_property_update + * + */ + +inline static void +cpl_property_update_(cpl_property *self, const cpl_property *other) +{ + /* Copy everything up to and including any value + comment, after which + the container may hold unused (and undefined) storage. The three + pointer members are _not_ copied, they are only valid for the source + property. So the name size is copied, but not the name itself! */ + (void)memcpy(2 * sizeof(char *) + sizeof(void *) + (char *)self, + 2 * sizeof(char *) + sizeof(void *) + (const char *)other, + sizeof(*self) - 2 * sizeof(char *) - sizeof(void *) + + other->vsize + other->csize - CPL_PROPERTY_SIZE); + + /* The 3 pointer members now need to be updated, do all but the name now */ + + if (CPL_LIKELY(self->vsize > 0)) { + /* Member is stored inside the container, data already copied */ + self->value = self->storage.data; + } + else if (other->value != NULL) { + /* Member is stored outside the container: Need to allocate, copy and update pointer */ - const size_t size = 1 + strlen(other->name); - cx_assert(CPL_PROPERTY_MEMBER_IS_OUTSIDE(other, name)); + const size_t size = self->size * cpl_type_get_sizeof(self->type); - self->name = memcpy(cx_malloc(size), other->name, size); + cx_assert(CPL_PROPERTY_MEMBER_IS_OUTSIDE(other, value)); + + self->value = memcpy(cx_malloc(size), other->value, size); + } + else { + self->value = NULL; } - if (self->csize > 0) { + if (CPL_LIKELY(self->csize > 0)) { /* Member is stored inside the container, on top of value */ - self->comment = self->data + self->vsize; - } else if (self->comment != NULL) { + self->comment = self->storage.data + self->vsize; + } + else if (other->comment != NULL) { /* Member is stored outside the container: Need to allocate, copy and update pointer */ const size_t size = 1 + strlen(other->comment); @@ -584,13 +559,63 @@ cx_assert(CPL_PROPERTY_MEMBER_IS_OUTSIDE(other, comment)); self->comment = memcpy(cx_malloc(size), other->comment, size); - } else { - cx_assert(self->comment == NULL); } + else { + self->comment = NULL; + } +} - cx_assert(self->vsize + self->nsize + self->csize <= CPL_PROPERTY_SIZE); - return self; +/** + * @internal + * @brief + * Update a property, i.e. copy everything but the name + * + * @param self The property to update + * @param other The property to copy from + * + * @return + * Nothing. + * + * @note No error checking in this internal function + * + * The name is preserved but a pointer to the name will become stale, + * iff the destination name is longer than the source name, to the point + * that the destination name has to be moved outside the container. + */ + +void +cpl_property_update(cpl_property *self, const cpl_property *other) +{ + /* Deallocate old member allocations, except the name */ + if (CPL_UNLIKELY(self->vsize == 0 && self->value != NULL)) + cx_free(self->value); + if (CPL_UNLIKELY(self->csize == 0 && self->comment != NULL)) + cx_free(self->comment); + + /* Even if the old and new names are identical, the new one + may have to have its name moved outside the container */ + if (CPL_UNLIKELY(self->nsize + other->vsize + other->csize > + CPL_PROPERTY_SIZE)) { + /* Move name outside */ + + cx_assert(self->nsize > 0); + + self->name = memcpy(cx_malloc(self->nsize), self->name, self->nsize); + + cpl_property_update_(self, other); /* Does not touch name pointer */ + + self->nsize = 0; + + cx_assert(CPL_PROPERTY_MEMBER_IS_OUTSIDE(self, name)); + } + else { + const unsigned char nsize = self->nsize; + + cpl_property_update_(self, other); /* Does not touch name pointer */ + + self->nsize = nsize; /* Redundant when names are of equal length */ + } } /** @@ -609,52 +634,50 @@ void cpl_property_delete(cpl_property *self) { - if (self) { #ifdef CPL_PROPERTY_DEBUG - cpl_msg_warning(cpl_func, "FREE(%d+%d+%d<=>%d<=>%zu:%zu) %s-property " + cpl_msg_warning(cpl_func, + "FREE(%d+%d+%d<=>%d<=>%zu:%zu) %s-property " "%s (sort=%d)", (int)self->nsize, (int)self->vsize, (int)self->csize, CPL_PROPERTY_SIZE - (int)self->nsize - (int)self->vsize, sizeof(*self), (size_t)self->size * cpl_type_get_sizeof(self->type), - cpl_type_get_name(self->type), - self->name, self->ksort); + cpl_type_get_name(self->type), self->name, self->ksort); #endif - if (self->csize == 0 && self->comment != NULL) { + if (CPL_UNLIKELY(self->csize == 0 && self->comment != NULL)) { cx_assert(CPL_PROPERTY_MEMBER_IS_OUTSIDE(self, comment)); #ifdef CPL_PROPERTY_DEBUG cpl_msg_warning(cpl_func, "OUTSIZED(%zu) comment in %s-type %s", 1 + strlen(self->comment), - cpl_type_get_name(self->type), - self->name); + cpl_type_get_name(self->type), self->name); #endif - cx_free((void*)self->comment); + cx_free((void *)self->comment); } - if (self->vsize == 0 && self->value != NULL) { + if (CPL_UNLIKELY(self->vsize == 0 && self->value != NULL)) { cx_assert(CPL_PROPERTY_MEMBER_IS_OUTSIDE(self, value)); #ifdef CPL_PROPERTY_DEBUG cpl_msg_warning(cpl_func, "OUTSIZED(%zu) value in %s-type %s", - (size_t)self->size * cpl_type_get_sizeof(self->type), - cpl_type_get_name(self->type), - self->name); + (size_t)self->size * + cpl_type_get_sizeof(self->type), + cpl_type_get_name(self->type), self->name); #endif cx_free(self->value); } - if (self->nsize == 0) { + if (CPL_UNLIKELY(self->nsize == 0)) { cx_assert(CPL_PROPERTY_MEMBER_IS_OUTSIDE(self, name)); #ifdef CPL_PROPERTY_DEBUG cpl_msg_warning(cpl_func, "OUTSIZED(%zu) name %s of %s-type", 1 + strlen(self->name), self->name, cpl_type_get_name(self->type)); #endif - cx_free((void*)self->name); + cx_free((void *)self->name); } - cx_free((void*)self); + cx_free((void *)self); } return; @@ -674,6 +697,7 @@ * * @see cpl_property_get_size() * + * @note No error checking in this internal function */ inline cpl_size @@ -742,6 +766,48 @@ } /** + * @internal + * @brief + * Get the type of a property. + * + * @param self The property. + * + * @return + * The type code of this property. + * + * @see cpl_property_get_type() + * + * @note No error checking in this internal function + */ + +inline cpl_type +cpl_property_get_type_(const cpl_property *self) +{ + return (cpl_type)self->type; +} + + +/** + * @internal + * @brief + * Get the sort key of a property. + * + * @param self The property. + * + * @return + * The sort key of this property. + * + * @note No error checking in this internal function + */ + +inline cpl_property_sorttype +cpl_property_get_sortkey_(const cpl_property *self) +{ + return self->ksort; +} + + +/** * @brief * Get the type of a property. * @@ -770,13 +836,12 @@ cpl_type cpl_property_get_type(const cpl_property *self) { - if (self == NULL) { (void)cpl_error_set_(CPL_ERROR_NULL_INPUT); return CPL_TYPE_INVALID; } - return (cpl_type)self->type; + return cpl_property_get_type_(self); } @@ -799,7 +864,7 @@ const size_t allocsz = cx_string_size_(name) + 1; - if (self->nsize == 0) { + if (CPL_UNLIKELY(self->nsize == 0)) { /* Outside space already allocated, keep it like that */ /* Include terminating null-byte */ @@ -808,20 +873,22 @@ cx_assert(CPL_PROPERTY_MEMBER_IS_OUTSIDE(self, name)); if (allocsz > oldsize) { - cx_free((void*)self->name); - self->name = (char*)cx_malloc(allocsz); + cx_free((void *)self->name); + self->name = (char *)cx_malloc(allocsz); } - } else if (self->vsize + self->csize + allocsz > CPL_PROPERTY_SIZE) { + } + else if (CPL_UNLIKELY(self->vsize + self->csize + allocsz > + CPL_PROPERTY_SIZE)) { /* Inside storage exhausted, move member outside */ self->nsize = 0; - self->name = (char*)cx_malloc(allocsz); - - } else if (allocsz != self->nsize) { + self->name = (char *)cx_malloc(allocsz); + } + else if (allocsz != self->nsize) { /* Name stays inside, but size and thus location changes */ self->nsize = allocsz; - self->name = self->data + CPL_PROPERTY_SIZE - self->nsize; + self->name = self->storage.data + CPL_PROPERTY_SIZE - self->nsize; } /* Copy member into place - it may be without null-terminator */ @@ -864,12 +931,12 @@ cpl_error_code cpl_property_set_name(cpl_property *self, const char *name) { - const cpl_cstr * cxstr; + const cpl_cstr *cxstr; if (self == NULL) { - return name != NULL - ? cpl_error_set_message_(CPL_ERROR_NULL_INPUT, "name=%s", name) - : cpl_error_set_(CPL_ERROR_NULL_INPUT); + return name != NULL ? cpl_error_set_message_(CPL_ERROR_NULL_INPUT, + "name=%s", name) + : cpl_error_set_(CPL_ERROR_NULL_INPUT); } if (name == NULL) { @@ -914,28 +981,29 @@ * case the function effectively deletes the current comment. */ -inline void +inline void cpl_property_set_comment_cx(cpl_property *self, const cpl_cstr *comment) { size_t allocsz; if (cx_string_get_(comment) == NULL) { - if (self->csize > 0) { + if (CPL_LIKELY(self->csize > 0)) { /* Reset old, inside stored comment */ cx_assert(!CPL_PROPERTY_MEMBER_IS_OUTSIDE(self, comment)); self->csize = 0; self->comment = NULL; - } else if (self->comment != NULL) { + } + else if (self->comment != NULL) { /* Free old, outside stored comment */ cx_assert(CPL_PROPERTY_MEMBER_IS_OUTSIDE(self, comment)); - cx_free((void*)self->comment); + cx_free((void *)self->comment); self->comment = NULL; } } allocsz = 1 + cx_string_size_(comment); /* Include terminating null-byte */ - if (self->csize == 0 && self->comment != NULL) { + if (CPL_UNLIKELY(self->csize == 0 && self->comment != NULL)) { /* Outside space already allocated, keep it like that */ /* Include terminating null-byte */ @@ -944,22 +1012,26 @@ cx_assert(CPL_PROPERTY_MEMBER_IS_OUTSIDE(self, comment)); if (allocsz > oldsize) { - cx_free((void*)self->comment); - self->comment = (char*)cx_malloc(allocsz); + cx_free((void *)self->comment); + self->comment = (char *)cx_malloc(allocsz); } - } else if (self->vsize + self->nsize + allocsz > CPL_PROPERTY_SIZE) { + } + else if (CPL_UNLIKELY(self->vsize + self->nsize + allocsz > + CPL_PROPERTY_SIZE)) { /* Inside storage exhausted, move member outside */ self->csize = 0; - self->comment = (char*)cx_malloc(allocsz); - } else if (allocsz != self->csize) { + self->comment = (char *)cx_malloc(allocsz); + } + else if (allocsz != self->csize) { /* Inside storage OK, need to adjust comment location */ - self->comment = self->data + self->vsize; + self->comment = self->storage.data + self->vsize; self->csize = allocsz; - } else { + } + else { /* Inside storage OK, with size and location unchanged */ cx_assert(self->csize > 0); - cx_assert(self->comment == self->data + self->vsize); + cx_assert(self->comment == self->storage.data + self->vsize); } /* Copy member into place - it may be without null-terminator */ @@ -1001,13 +1073,12 @@ cpl_error_code cpl_property_set_comment(cpl_property *self, const char *comment) { - const cpl_cstr * cxstr; + const cpl_cstr *cxstr; if (self == NULL) { - return comment == NULL - ? cpl_error_set_(CPL_ERROR_NULL_INPUT) - : cpl_error_set_message_(CPL_ERROR_NULL_INPUT, "comment=%s", - comment); + return comment == NULL ? cpl_error_set_(CPL_ERROR_NULL_INPUT) + : cpl_error_set_message_(CPL_ERROR_NULL_INPUT, + "comment=%s", comment); } cxstr = CXSTR(comment, comment ? strlen(comment) : 0); @@ -1059,14 +1130,13 @@ if (self->type != CPL_TYPE_CHAR) { return cpl_error_set_message_(CPL_ERROR_TYPE_MISMATCH, - "name=%s, type=%s", - self->name, + "name=%s, type=%s", self->name, cpl_type_get_name(self->type)); } cx_assert(sizeof(value) == cpl_type_get_sizeof((cpl_type)self->type)); - (void)memcpy(self->data, &value, sizeof(value)); /* Inlined */ + (void)memcpy(self->storage.data, &value, sizeof(value)); /* Inlined */ return CPL_ERROR_NONE; } @@ -1116,14 +1186,13 @@ if (self->type != CPL_TYPE_BOOL) { return cpl_error_set_message_(CPL_ERROR_TYPE_MISMATCH, - "name=%s, type=%s", - self->name, + "name=%s, type=%s", self->name, cpl_type_get_name(self->type)); } cx_assert(sizeof(value) == cpl_type_get_sizeof((cpl_type)self->type)); - (void)memcpy(self->data, &myvalue, sizeof(myvalue)); /* Inlined */ + self->storage.bool = myvalue; return CPL_ERROR_NONE; } @@ -1170,14 +1239,13 @@ if (self->type != CPL_TYPE_INT) { return cpl_error_set_message_(CPL_ERROR_TYPE_MISMATCH, - "name=%s, type=%s", - self->name, + "name=%s, type=%s", self->name, cpl_type_get_name(self->type)); } cx_assert(sizeof(value) == cpl_type_get_sizeof((cpl_type)self->type)); - (void)memcpy(self->data, &value, sizeof(value)); /* Inlined */ + self->storage.i = value; return CPL_ERROR_NONE; } @@ -1224,14 +1292,13 @@ if (self->type != CPL_TYPE_LONG) { return cpl_error_set_message_(CPL_ERROR_TYPE_MISMATCH, - "name=%s, type=%s", - self->name, + "name=%s, type=%s", self->name, cpl_type_get_name(self->type)); } cx_assert(sizeof(value) == cpl_type_get_sizeof((cpl_type)self->type)); - (void)memcpy(self->data, &value, sizeof(value)); /* Inlined */ + self->storage.l = value; return CPL_ERROR_NONE; } @@ -1278,14 +1345,13 @@ if (self->type != CPL_TYPE_LONG_LONG) { return cpl_error_set_message_(CPL_ERROR_TYPE_MISMATCH, - "name=%s, type=%s", - self->name, + "name=%s, type=%s", self->name, cpl_type_get_name(self->type)); } cx_assert(sizeof(value) == cpl_type_get_sizeof((cpl_type)self->type)); - (void)memcpy(self->data, &value, sizeof(value)); /* Inlined */ + self->storage.ll = value; return CPL_ERROR_NONE; } @@ -1332,14 +1398,13 @@ if (self->type != CPL_TYPE_FLOAT) { return cpl_error_set_message_(CPL_ERROR_TYPE_MISMATCH, - "name=%s, type=%s", - self->name, + "name=%s, type=%s", self->name, cpl_type_get_name(self->type)); } cx_assert(sizeof(value) == cpl_type_get_sizeof((cpl_type)self->type)); - (void)memcpy(self->data, &value, sizeof(value)); /* Inlined */ + self->storage.fp = value; return CPL_ERROR_NONE; } @@ -1386,14 +1451,13 @@ if (self->type != CPL_TYPE_DOUBLE) { return cpl_error_set_message_(CPL_ERROR_TYPE_MISMATCH, - "name=%s, type=%s", - self->name, + "name=%s, type=%s", self->name, cpl_type_get_name(self->type)); } cx_assert(sizeof(value) == cpl_type_get_sizeof((cpl_type)self->type)); - (void)memcpy(self->data, &value, sizeof(value)); /* Inlined */ + self->storage.dp = value; return CPL_ERROR_NONE; } @@ -1423,35 +1487,36 @@ cx_assert(CPL_PROPERTY_MEMBER_IS_OUTSIDE(self, value)); if ((cpl_size)allocsz > self->size) { - cx_free((void*)self->value); - self->value = (char*)cx_malloc(allocsz); + cx_free((void *)self->value); + self->value = (char *)cx_malloc(allocsz); } - } else if (self->nsize + self->csize + allocsz > CPL_PROPERTY_SIZE) { + } + else if (self->nsize + self->csize + allocsz > CPL_PROPERTY_SIZE) { /* Inside storage exhausted, move member outside */ /* May need to move non-empty comment down to where old string was */ move_comment = self->csize > 0 && self->vsize > 0; self->vsize = 0; - self->value = (char*)cx_malloc(allocsz); - - } else if (self->vsize != allocsz) { + self->value = (char *)cx_malloc(allocsz); + } + else if (self->vsize != allocsz) { /* Inside storage OK, update location and size */ /* Move non-empty comment based on new value size */ move_comment = self->csize > 0; self->vsize = allocsz; - self->value = self->data; /* Redundant all but the first time */ + self->value = self->storage.data; /* Redundant all but the first time */ } if (move_comment) - self->comment = memmove(self->data + self->vsize, - self->comment, self->csize); + self->comment = memmove(self->storage.data + self->vsize, self->comment, + self->csize); /* Copy member into place */ (void)memcpy(self->value, cx_string_get_(value), allocsz - 1); - ((char*)self->value)[allocsz - 1] = '\0'; + ((char *)self->value)[allocsz - 1] = '\0'; self->size = allocsz; @@ -1495,7 +1560,7 @@ cpl_error_code cpl_property_set_string(cpl_property *self, const char *value) { - const cpl_cstr * cxstr; + const cpl_cstr *cxstr; if (self == NULL) { @@ -1504,13 +1569,12 @@ if (self->type != CPL_TYPE_STRING) { return cpl_error_set_message_(CPL_ERROR_TYPE_MISMATCH, - "name=%s, type=%s", - self->name, + "name=%s, type=%s", self->name, cpl_type_get_name(self->type)); } if (value == NULL) { - return cpl_error_set_message_(CPL_ERROR_NULL_INPUT, "self->name=%s", + return cpl_error_set_message_(CPL_ERROR_NULL_INPUT, "name=%s", self->name); } @@ -1564,14 +1628,13 @@ if (self->type != CPL_TYPE_FLOAT_COMPLEX) { return cpl_error_set_message_(CPL_ERROR_TYPE_MISMATCH, - "name=%s, type=%s", - self->name, + "name=%s, type=%s", self->name, cpl_type_get_name(self->type)); } cx_assert(sizeof(value) == cpl_type_get_sizeof((cpl_type)self->type)); - (void)memcpy(self->data, &value, sizeof(value)); /* Inlined */ + self->storage.fc = value; return CPL_ERROR_NONE; } @@ -1619,14 +1682,13 @@ if (self->type != CPL_TYPE_DOUBLE_COMPLEX) { return cpl_error_set_message_(CPL_ERROR_TYPE_MISMATCH, - "name=%s, type=%s", - self->name, + "name=%s, type=%s", self->name, cpl_type_get_name(self->type)); } cx_assert(sizeof(value) == cpl_type_get_sizeof((cpl_type)self->type)); - (void)memcpy(self->data, &value, sizeof(value)); /* Inlined */ + self->storage.dc = value; return CPL_ERROR_NONE; } @@ -1721,7 +1783,6 @@ const char * cpl_property_get_name(const cpl_property *self) { - if (self == NULL) { (void)cpl_error_set_(CPL_ERROR_NULL_INPUT); return NULL; @@ -1738,7 +1799,7 @@ * * @return * The comment of the property if it is present or @c NULL. If an error - * occurrs the function returns @c NULL and sets an appropriate error code. + * occurs the function returns @c NULL and sets an appropriate error code. * * @error * @@ -1757,7 +1818,6 @@ const char * cpl_property_get_comment(const cpl_property *self) { - if (self == NULL) { (void)cpl_error_set_(CPL_ERROR_NULL_INPUT); return NULL; @@ -1807,13 +1867,35 @@ if (self->type != CPL_TYPE_CHAR) { (void)cpl_error_set_message_(CPL_ERROR_TYPE_MISMATCH, - "name=%s, type=%s", - self->name, + "name=%s, type=%s", self->name, cpl_type_get_name(self->type)); return '\0'; } - return *((const char*)self->data); + return cpl_property_get_char_(self); +} + +/** + * @internal + * @brief + * Get the value of a character property. + * + * @param self The property. + * + * @return + * The current property value. If an error occurs the function returns + * '\\0' and an appropriate error code is set. + * + * @note This internal function has no error checking. + * + * @see cpl_property_get_char + * + */ + +inline char +cpl_property_get_char_(const cpl_property *self) +{ + return *(self->storage.data); } /** @@ -1857,13 +1939,34 @@ if (self->type != CPL_TYPE_BOOL) { (void)cpl_error_set_message_(CPL_ERROR_TYPE_MISMATCH, - "name=%s, type=%s", - self->name, + "name=%s, type=%s", self->name, cpl_type_get_name(self->type)); return 0; } - return *((const cpl_boolean*)self->data); + return cpl_property_get_bool_(self); +} + +/** + * @internal + * @brief + * Get the value of a boolean property. + * + * @param self The property. + * + * @return + * The current property value. If an error occurs the function returns + * 0 and an appropriate error code is set. + * + * @note This internal function has no error checking. + * + * @see cpl_property_get_bool + */ + +inline int +cpl_property_get_bool_(const cpl_property *self) +{ + return self->storage.bool; } /** @@ -1907,13 +2010,34 @@ if (self->type != CPL_TYPE_INT) { (void)cpl_error_set_message_(CPL_ERROR_TYPE_MISMATCH, - "name=%s, type=%s", - self->name, + "name=%s, type=%s", self->name, cpl_type_get_name(self->type)); return 0; } - return *((const int*)self->data); + return cpl_property_get_int_(self); +} + +/** + * @internal + * @brief + * Get the value of an integer property. + * + * @param self The property. + * + * @return + * The current property value. If an error occurs the function returns + * 0 and an appropriate error code is set. + * + * @note This internal function has no error checking. + * + * @see cpl_property_get_int + */ + +inline int +cpl_property_get_int_(const cpl_property *self) +{ + return self->storage.i; } /** @@ -1952,43 +2076,52 @@ long cpl_property_get_long(const cpl_property *self) { - long value = 0; - - if (self == NULL) { (void)cpl_error_set_(CPL_ERROR_NULL_INPUT); - return value; + return 0; } - /* - * If the property self is of the same kind, but of a smaller rank, - * promote the property's value to the target type. - */ - switch (self->type) { case CPL_TYPE_INT: - { - value = *((const int*)self->data); - break; - } - case CPL_TYPE_LONG: - { - value = *((const long*)self->data); break; - } - default: - { + default: { (void)cpl_error_set_message_(CPL_ERROR_TYPE_MISMATCH, - "name=%s, type=%s", - self->name, + "name=%s, type=%s", self->name, cpl_type_get_name(self->type)); - break; + return 0; } } - return value; + return cpl_property_get_long_(self); +} + +/** + * @internal + * @brief + * Get the value of a long property. + * + * @param self The property, of type int or long. + * + * @return + * The current property value. If an error occurs the function returns + * 0 and an appropriate error code is set. + * + * @note This internal function has no error checking. + * + * @see cpl_property_get_long + */ + +inline long +cpl_property_get_long_(const cpl_property *self) +{ + /* + * If the property self is of the same kind, but of a smaller rank, + * promote the property's value to the target type. + */ + + return self->type == CPL_TYPE_INT ? self->storage.i : self->storage.l; } /** @@ -2027,12 +2160,9 @@ long long cpl_property_get_long_long(const cpl_property *self) { - long long value = 0; - - if (self == NULL) { (void)cpl_error_set_(CPL_ERROR_NULL_INPUT); - return value; + return 0; } /* @@ -2042,29 +2172,60 @@ switch (self->type) { case CPL_TYPE_INT: - { - value = *((const int*)self->data); + case CPL_TYPE_LONG: + case CPL_TYPE_LONG_LONG: break; + + default: { + (void)cpl_error_set_message_(CPL_ERROR_TYPE_MISMATCH, + "name=%s, type=%s", self->name, + cpl_type_get_name(self->type)); + return 0; } + } - case CPL_TYPE_LONG: - { - value = *((const long*)self->data); + return cpl_property_get_long_long_(self); +} + +/** + * @internal + * @brief + * Get the value of a long long property. + * + * @param self The property, of type int, long or long long. + * + * @return + * The current property value. If an error occurs the function returns + * 0 and an appropriate error code is set. + * + * @note This internal function has no error checking. + * + * @see cpl_property_get_long_long + */ + +inline long long +cpl_property_get_long_long_(const cpl_property *self) +{ + long long value; + + /* + * If the property self is of the same kind, but of a smaller rank, + * promote the property's value to the target type. + */ + + switch (self->type) { + case CPL_TYPE_INT: { + value = self->storage.i; break; } - case CPL_TYPE_LONG_LONG: - { - value = *((const long long*)self->data); + case CPL_TYPE_LONG: { + value = self->storage.l; break; } - default: - { - (void)cpl_error_set_message_(CPL_ERROR_TYPE_MISMATCH, - "name=%s, type=%s", - self->name, - cpl_type_get_name(self->type)); + default: { + value = self->storage.ll; break; } } @@ -2112,12 +2273,9 @@ float cpl_property_get_float(const cpl_property *self) { - float value = 0.0; - - if (self == NULL) { (void)cpl_error_set_(CPL_ERROR_NULL_INPUT); - return value; + return 0.0; } /* @@ -2127,32 +2285,44 @@ switch (self->type) { case CPL_TYPE_FLOAT: - { - cx_assert(sizeof(value) == cpl_type_get_sizeof(self->type)); - (void)memcpy(&value, self->data, sizeof(value)); + cx_assert(sizeof(float) == cpl_type_get_sizeof(self->type)); break; - } case CPL_TYPE_DOUBLE: - { - double pvalue; - cx_assert(sizeof(pvalue) == cpl_type_get_sizeof(self->type)); - (void)memcpy(&pvalue, self->data, sizeof(pvalue)); - value = pvalue; + cx_assert(sizeof(double) == cpl_type_get_sizeof(self->type)); break; - } - default: - { + default: { (void)cpl_error_set_message_(CPL_ERROR_TYPE_MISMATCH, - "name=%s, type=%s", - self->name, + "name=%s, type=%s", self->name, cpl_type_get_name(self->type)); - break; + return 0.0; } } - return value; + return cpl_property_get_float_(self); +} + +/** + * @internal + * @brief + * Get the value of a float property. + * + * @param self The property, of type float or double + * + * @return + * The current property value. If an error occurs the function returns + * 0. and an appropriate error code is set. + * + * @note This internal function has no error checking. + * + * @see cpl_property_get_float + */ + +inline float +cpl_property_get_float_(const cpl_property *self) +{ + return self->type == CPL_TYPE_FLOAT ? self->storage.fp : self->storage.dp; } /** @@ -2191,12 +2361,9 @@ double cpl_property_get_double(const cpl_property *self) { - double value = 0.0; - - if (self == NULL) { (void)cpl_error_set_(CPL_ERROR_NULL_INPUT); - return value; + return 0.0; } /* @@ -2206,32 +2373,44 @@ switch (self->type) { case CPL_TYPE_FLOAT: - { - float pvalue; - cx_assert(sizeof(pvalue) == cpl_type_get_sizeof(self->type)); - (void)memcpy(&pvalue, self->data, sizeof(pvalue)); - value = pvalue; + cx_assert(sizeof(float) == cpl_type_get_sizeof(self->type)); break; - } case CPL_TYPE_DOUBLE: - { - cx_assert(sizeof(value) == cpl_type_get_sizeof(self->type)); - (void)memcpy(&value, self->data, sizeof(value)); + cx_assert(sizeof(double) == cpl_type_get_sizeof(self->type)); break; - } - default: - { + default: { (void)cpl_error_set_message_(CPL_ERROR_TYPE_MISMATCH, - "name=%s, type=%s", - self->name, + "name=%s, type=%s", self->name, cpl_type_get_name(self->type)); - break; + return 0.0; } } - return value; + return cpl_property_get_double_(self); +} + +/** + * @internal + * @brief + * Get the value of a double property. + * + * @param self The property, of type float or double. + * + * @return + * The current property value. If an error occurs the function returns + * 0. and an appropriate error code is set. + * + * @note This internal function has no error checking. + * + * @see cpl_property_get_double + */ + +inline double +cpl_property_get_double_(const cpl_property *self) +{ + return self->type == CPL_TYPE_DOUBLE ? self->storage.dp : self->storage.fp; } /** @@ -2277,8 +2456,7 @@ if (self->type != CPL_TYPE_STRING) { (void)cpl_error_set_message_(CPL_ERROR_TYPE_MISMATCH, - "name=%s, type=%s", - self->name, + "name=%s, type=%s", self->name, cpl_type_get_name(self->type)); return NULL; } @@ -2327,47 +2505,59 @@ float complex cpl_property_get_float_complex(const cpl_property *self) { - float complex value = 0.0; - - if (self == NULL) { (void)cpl_error_set_(CPL_ERROR_NULL_INPUT); - return value; + return 0.0; } - /* - * If the property self is of type double complex cast it to float complex. - * This may lead to truncation errors! - */ - switch (self->type) { case CPL_TYPE_FLOAT_COMPLEX: - { - cx_assert(sizeof(value) == cpl_type_get_sizeof(self->type)); - (void)memcpy(&value, self->data, sizeof(value)); + cx_assert(sizeof(float complex) == cpl_type_get_sizeof(self->type)); break; - } case CPL_TYPE_DOUBLE_COMPLEX: - { - double complex pvalue; - cx_assert(sizeof(pvalue) == cpl_type_get_sizeof(self->type)); - (void)memcpy(&pvalue, self->data, sizeof(pvalue)); - value = pvalue; + cx_assert(sizeof(double complex) == + cpl_type_get_sizeof(self->type)); break; - } - default: - { + default: { (void)cpl_error_set_message_(CPL_ERROR_TYPE_MISMATCH, - "name=%s, type=%s", - self->name, + "name=%s, type=%s", self->name, cpl_type_get_name(self->type)); - break; + return 0.0; } } - return value; + return cpl_property_get_float_complex_(self); +} + + +/** + * @internal + * @brief + * Get the value of a float complex property. + * + * @param self The property, of type float complex or double complex. + * + * @return + * The current property value. If an error occurs the function returns + * 0. and an appropriate error code is set. + * + * @note This internal function has no error checking. + * + * @see cpl_property_get_float_complex + */ + +inline float complex +cpl_property_get_float_complex_(const cpl_property *self) +{ + /* + * If the property self is of type double complex cast it to float complex. + * This may lead to truncation errors! + */ + + return self->type == CPL_TYPE_FLOAT_COMPLEX ? self->storage.fc + : self->storage.dc; } @@ -2408,47 +2598,58 @@ double complex cpl_property_get_double_complex(const cpl_property *self) { - double complex value = 0.0; - - if (self == NULL) { (void)cpl_error_set_(CPL_ERROR_NULL_INPUT); - return value; + return 0.0; } - /* - * If the property self is of the same kind, but of a smaller rank, - * promote the property's value to the target type. - */ - switch (self->type) { case CPL_TYPE_FLOAT_COMPLEX: - { - float complex pvalue; - cx_assert(sizeof(pvalue) == cpl_type_get_sizeof(self->type)); - (void)memcpy(&pvalue, self->data, sizeof(pvalue)); - value = pvalue; + cx_assert(sizeof(float complex) == cpl_type_get_sizeof(self->type)); break; - } case CPL_TYPE_DOUBLE_COMPLEX: - { - cx_assert(sizeof(value) == cpl_type_get_sizeof(self->type)); - (void)memcpy(&value, self->data, sizeof(value)); + cx_assert(sizeof(double complex) == + cpl_type_get_sizeof(self->type)); break; - } - default: - { + default: { (void)cpl_error_set_message_(CPL_ERROR_TYPE_MISMATCH, - "name=%s, type=%s", - self->name, + "name=%s, type=%s", self->name, cpl_type_get_name(self->type)); - break; + return 0.0; } } - return value; + return cpl_property_get_double_complex_(self); +} + +/** + * @internal + * @brief + * Get the value of a double complex property. + * + * @param self The property, of type float complex or double complex. + * + * @return + * The current property value. If an error occurs the function returns + * 0. and an appropriate error code is set. + * + * @note This internal function has no error checking. + * + * @see cpl_property_get_double_complex + */ + +inline double complex +cpl_property_get_double_complex_(const cpl_property *self) +{ + /* + * If the property self is of the same kind, but of a smaller rank, + * promote the property's value to the target type. + */ + + return self->type == CPL_TYPE_DOUBLE_COMPLEX ? self->storage.dc + : self->storage.fc; } /** @@ -2459,166 +2660,41 @@ * @param p2 the second property, non-NULL * @return -1 if p1 < p2, 0 if p1 == p2, +1 if p1 > p2 * @note This internal function has no error checking. - * @see cpl_property_set_sort_dicb(), cpl_propertylist_sort() + * @see cpl_property_set_sortkey_(), cpl_propertylist_sort() + * + * Properties with an undefined sorting order cannot be ordered, + * so zero will be returned if a property has an undefined sorting + * key even if the other key has a different value. * */ -int cpl_property_compare_sortkey(const cpl_property * p1, - const cpl_property * p2) +int +cpl_property_compare_sortkey(const cpl_property *p1, const cpl_property *p2) { - /* Cannot order properties with an undefined sorting order */ - if (p1->ksort == CPL_PROPERTY_SORT_UNDEF || - p2->ksort == CPL_PROPERTY_SORT_UNDEF) return 0; - - if (p1->ksort > p2->ksort) return 1; - else if (p1->ksort < p2->ksort) return -1; - else return 0; + if (p1->ksort > p2->ksort) + return p2->ksort == CPL_PROPERTY_SORT_UNDEF ? 0 : 1; + else if (p1->ksort < p2->ksort) + return p1->ksort == CPL_PROPERTY_SORT_UNDEF ? 0 : -1; + else + return 0; } -/*----------------------------------------------------------------------------*/ /** - @internal - @brief Set the DICB type of the name - @param self The property, must be non-NULL - @return nothing - @note This internal function has no error checking - @see cpl_property_compare_sortkey(), cpl_propertylist_sort() - - The function does not validate its input according to the FITS standard, - it merely provides the type specified for DICB in order to sort the FITS - keys. - - The correctness of the ordering in this function is difficult to verify - because CFITSIO itself orders several cards in accordance with the FITS - standard. For the same reason, any incorrectness regarding such keys will - have no effect on any written FITS header. - - */ -/*----------------------------------------------------------------------------*/ -void cpl_property_set_sort_dicb(cpl_property * self) -{ - const size_t size = self->nsize > 0 ? self->nsize : 1 + strlen(self->name); - const char * key = self->name; - cpl_property_dicbtype kt; - - /* The sort key must fit in a single char */ - cx_assert(CPL_DICB_END == (unsigned char)CPL_DICB_END); - - /* First matching the length of the key to the length of the string literal - allows for a static-length memcmp() which should be inline-able. */ - - /* NB: The indentation that aligns the calls to memcmp() helps to - ensure that strings of identical length share the correct branch */ - - if (size > 3 && !memcmp(key, "ESO", 3)) { - kt = CPL_DICB_HIERARCH_ESO; /* Default HIERARCH ESO type */ - - if (size > 7) { - /* Specific HIERARCH ESO types take precedence */ - if (!memcmp(key, "ESO DPR", 7)) kt = CPL_DICB_HIERARCH_DPR; - else if (!memcmp(key, "ESO OBS", 7)) kt = CPL_DICB_HIERARCH_OBS; - else if (!memcmp(key, "ESO TPL", 7)) kt = CPL_DICB_HIERARCH_TPL; - else if (!memcmp(key, "ESO GEN", 7)) kt = CPL_DICB_HIERARCH_GEN; - else if (!memcmp(key, "ESO TEL", 7)) kt = CPL_DICB_HIERARCH_TEL; - else if (!memcmp(key, "ESO INS", 7)) kt = CPL_DICB_HIERARCH_INS; - else if (!memcmp(key, "ESO DET", 7)) kt = CPL_DICB_HIERARCH_DET; - else if (!memcmp(key, "ESO LOG", 7)) kt = CPL_DICB_HIERARCH_LOG; - else if (!memcmp(key, "ESO PRO", 7)) kt = CPL_DICB_HIERARCH_PRO; - } - - self->ksort = kt; - - return; - } - - /* The default value for a FITS key of length less than 9 */ - kt = CPL_DICB_PRIMARY; - - /* Switch on the size. The number of characters is one less */ - switch (size) { - case 4: - if (!memcmp(key, "END", 3)) kt = CPL_DICB_END; - break; - - case 6: - if (!memcmp(key, "BZERO", 5)) kt = CPL_DICB_BZERO; - else if (!memcmp(key, "NAXIS", 5)) kt = CPL_DICB_NAXIS; - else if (!memcmp(key, "GROUP", 5)) kt = CPL_DICB_GROUP; - - break; - - case 7: - if (!memcmp(key, "BITPIX", 6)) kt = CPL_DICB_BITPIX; - else if (!memcmp(key, "BSCALE", 6)) kt = CPL_DICB_BSCALE; - else if (!memcmp(key, "EXTEND", 6)) kt = CPL_DICB_EXTEND; - else if (!memcmp(key, "PCOUNT", 6)) kt = CPL_DICB_PCOUNT; - else if (!memcmp(key, "GCOUNT", 6)) kt = CPL_DICB_GCOUNT; - else if (!memcmp(key, "SIMPLE", 6)) kt = CPL_DICB_TOP; - else { - cpl_property_dicbtype mykt = kt; - - /* NAXISn/TFORMn/TBCOLn, n = 1..9 */ - - if (!memcmp(key, "NAXIS", 5)) mykt = CPL_DICB_NAXISn; - else if (!memcmp(key, "TFORM", 5)) mykt = CPL_DICB_TFORMn; - else if (!memcmp(key, "TBCOL", 5)) mykt = CPL_DICB_TBCOLn; - - if (mykt != kt && - '1' <= key[5] && key[5] <= '9') { - kt = mykt; - } - } - break; - case 8: - if (!memcmp(key, "HISTORY", 7)) kt = CPL_DICB_HISTORY; - else if (!memcmp(key, "COMMENT", 7)) kt = CPL_DICB_COMMENT; - else if (!memcmp(key, "TFIELDS", 7)) kt = CPL_DICB_TFIELDS; - else { - cpl_property_dicbtype mykt = kt; - - /* NAXISn/TFORMn/TBCOLn, n = 10..99 */ - - if (!memcmp(key, "NAXIS", 5)) mykt = CPL_DICB_NAXISn; - else if (!memcmp(key, "TFORM", 5)) mykt = CPL_DICB_TFORMn; - else if (!memcmp(key, "TBCOL", 5)) mykt = CPL_DICB_TBCOLn; - - if (mykt != kt && - '1' <= key[5] && key[5] <= '9' && - '0' <= key[6] && key[6] <= '9') { - kt = mykt; - } - } - break; - - case 9: - if (!memcmp(key, "XTENSION", 8)) kt = CPL_DICB_TOP; - else { - cpl_property_dicbtype mykt = kt; - - /* NAXISn/TFORMn/TBCOLn, n = 100..999 */ - - if (!memcmp(key, "NAXIS", 5)) mykt = CPL_DICB_NAXISn; - else if (!memcmp(key, "TFORM", 5)) mykt = CPL_DICB_TFORMn; - else if (!memcmp(key, "TBCOL", 5)) mykt = CPL_DICB_TBCOLn; - - if (mykt != kt && - '1' <= key[5] && key[5] <= '9' && - '0' <= key[6] && key[6] <= '9' && - '0' <= key[7] && key[7] <= '9') { - kt = mykt; - } - } - break; - - default: - if (size > 9) { - /* With a length of 9 or more, this is not a standard key... */ - - kt = CPL_DICB_HIERARCH; - } - break; - } + * @internal + * @brief + * Get the sort key of a property. + * + * @param self The property. + * + * @return + * The sort code of this property. + * + * @note No error checking in this internal function + */ - self->ksort = kt; +inline void +cpl_property_set_sortkey_(cpl_property *self, cpl_property_sorttype sortkey) +{ + self->ksort = sortkey; } @@ -2631,10 +2707,12 @@ * @note This internal function has no error checking. * */ -inline size_t cpl_property_get_size_name(const cpl_property * self) +inline size_t +cpl_property_get_size_name(const cpl_property *self) { - return self->nsize > 0 ? (size_t)self->nsize - 1 - : strlen(self->name); /* Name not in container. :-( */ + return CPL_LIKELY(self->nsize > 0) + ? (size_t)self->nsize - 1 + : strlen(self->name); /* Name not in container. :-( */ } /** @@ -2646,10 +2724,13 @@ * @note This internal function has no error checking. * */ -inline size_t cpl_property_get_size_comment(const cpl_property * self) +inline size_t +cpl_property_get_size_comment(const cpl_property *self) { - return self->csize > 0 ? (size_t)self->csize - 1 - : strlen(self->comment); /* Comment not in container. :-( */ + return CPL_LIKELY(self->csize > 0) + ? (size_t)self->csize - 1 + /* Comment not in container. :-( */ + : (self->comment ? strlen(self->comment) : 0); } /**@}*/ @@ -2668,9 +2749,9 @@ * The function used for printing is the standard C @c fprintf(). */ -void cpl_property_dump(const cpl_property *property, FILE * stream) +void +cpl_property_dump(const cpl_property *property, FILE *stream) { - const char *name = cpl_property_get_name(property); const char *comment = cpl_property_get_comment(property); @@ -2681,7 +2762,7 @@ cpl_type type = cpl_property_get_type(property); - fprintf(stream, "Property at address %p\n", (const void*)property); + fprintf(stream, "Property at address %p\n", (const void *)property); fprintf(stream, "\tname : %p '%s'\n", name, name); fprintf(stream, "\tcomment: %p '%s'\n", comment, comment); fprintf(stream, "\ttype : %#09x\n", type); @@ -2729,13 +2810,11 @@ default: fprintf(stream, "unknown."); break; - } fprintf(stream, "\n"); return; - } #ifdef CPL_CXSTR_DEBUG @@ -2747,13 +2826,13 @@ * @param length The length of the string to test * @note Only for testing, will abort()! */ -const cpl_cstr * cxstr_abort(const char* string, cxsize length) +const cpl_cstr * +cxstr_abort(const char *string, cxsize length) { const size_t allocsz = string ? strlen(string) : 0; cpl_msg_error(cpl_func, "CXSTR(\"%s\", %d) <=> %zd", - string ? string : "", - (int)length, allocsz); + string ? string : "", (int)length, allocsz); cx_assert(allocsz == length); abort(); diff -Nru cpl-7.1.4+ds/cplcore/cpl_property_dicb.c cpl-7.2.2+ds/cplcore/cpl_property_dicb.c --- cpl-7.1.4+ds/cplcore/cpl_property_dicb.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_property_dicb.c 2022-04-29 14:56:02.000000000 +0000 @@ -0,0 +1,397 @@ +/* + * This file is part of the ESO Common Pipeline Library + * Copyright (C) 2001-2022 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 "cpl_property_dicb.h" + +/*----------------------------------------------------------------------------*/ +/** + * @defgroup cpl_property_dicb DICB specific property functionality + * + * @par Synopsis: + * @code + * #include "cpl_property_dicb.h" + * @endcode + */ +/*----------------------------------------------------------------------------*/ +/**@{*/ + +/*----------------------------------------------------------------------------- + Function codes + -----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief Set the DICB type of the name + @param self The property, must be non-NULL + @return nothing + @note This internal function has no error checking + @see cpl_property_compare_sortkey(), cpl_propertylist_sort(), cpl_fits_set_key + + The function does not validate its input according to the FITS standard, + it merely provides the type specified for DICB in order to sort the FITS + keys. + + The correctness of the ordering in this function is difficult to verify + because CFITSIO itself orders several cards in accordance with the FITS + standard. For the same reason, any incorrectness regarding such keys will + have no effect on any written FITS header. + + */ +/*----------------------------------------------------------------------------*/ +void +cpl_property_set_sortkey_dicb(cpl_property *self) +{ + const size_t size = cpl_property_get_size_name(self) + 1; + const char *key = cpl_property_get_name_(self); + + /* The default value for a FITS key of length less than 9 */ + cpl_property_sorttype_dicb kt = CPL_DICB_PRIMARY; + + + /* The sort key must fit in a single char */ + cx_assert(CPL_DICB_END == (unsigned char)CPL_DICB_END); + + /* First matching the length of the key to the length of the string literal + allows for a static-length memcmp() which should be inline-able. */ + + /* NB: The indentation that aligns the calls to memcmp() helps to + ensure that strings of identical length share the correct branch */ + + switch (size) { /* The number of characters includes the null-byte */ + case 1: + case 2: + break; + + case 3: + if (!memcmp(key, "RA", 2)) + kt = CPL_DICB_DESCRIBE; + break; + + case 4: + if (!memcmp(key, "DEC", 3)) + kt = CPL_DICB_DESCRIBE; + else if (!memcmp(key, "LST", 3)) + kt = CPL_DICB_DESCRIBE; + else if (!memcmp(key, "UTC", 3)) + kt = CPL_DICB_DESCRIBE; + else if (!memcmp(key, "END", 3)) + kt = CPL_DICB_END; + break; + + case 5: + if (!memcmp(key, "DATE", 4)) + kt = CPL_DICB_DESCRIBE; + break; + + case 6: + if (!memcmp(key, "BZERO", 5)) + kt = CPL_DICB_BZERO; + else if (!memcmp(key, "NAXIS", 5)) + kt = CPL_DICB_NAXIS; + else if (!memcmp(key, "GROUP", 5)) + kt = CPL_DICB_GROUP; + else if (!memcmp(key, "BLANK", 5)) + kt = CPL_DICB_DESCRIBE; + /* With NAXIS 1-9, these are WCS keys */ + else if (key[3] == '_' && + (!memcmp(key, "PC", 2) || !memcmp(key, "PV", 2) || + !memcmp(key, "PS", 2) || !memcmp(key, "CD", 2)) && + '1' <= key[2] && key[2] <= '9' && '1' <= key[4] && + key[4] <= '9') + kt = CPL_DICB_WCS; + else if (!memcmp(key, "ESO ", 4)) + kt = CPL_DICB_HIERARCH_ESO; + + break; + + case 7: + if (!memcmp(key, "BITPIX", 6)) + kt = CPL_DICB_BITPIX; + else if (!memcmp(key, "BSCALE", 6)) + kt = CPL_DICB_BSCALE; + else if (!memcmp(key, "EXTEND", 6)) + kt = CPL_DICB_EXTEND; + else if (!memcmp(key, "PCOUNT", 6)) + kt = CPL_DICB_PCOUNT; + else if (!memcmp(key, "GCOUNT", 6)) + kt = CPL_DICB_GCOUNT; + else if (!memcmp(key, "SIMPLE", 6)) + kt = CPL_DICB_TOP; + else if (!memcmp(key, "ORIGIN", 6)) + kt = CPL_DICB_DESCRIBE; + else if (!memcmp(key, "OBJECT", 6)) + kt = CPL_DICB_DESCRIBE; + else if (!memcmp(key, "PI-COI", 6)) + kt = CPL_DICB_DESCRIBE; + /* With NAXIS 10-99, these are WCS keys */ + else if (CPL_UNLIKELY(key[3] == '_' && (!memcmp(key, "PC", 2) || + !memcmp(key, "PV", 2) || + !memcmp(key, "PS", 2) || + !memcmp(key, "CD", 2))) && + '1' <= key[2] && key[2] <= '9' && '1' <= key[4] && + key[4] <= '9' && '0' <= key[5] && key[5] <= '9') + kt = CPL_DICB_WCS; + else if (CPL_UNLIKELY(key[4] == '_' && (!memcmp(key, "PC", 2) || + !memcmp(key, "PV", 2) || + !memcmp(key, "PS", 2) || + !memcmp(key, "CD", 2))) && + '1' <= key[2] && key[2] <= '9' && '0' <= key[3] && + key[3] <= '9' && '1' <= key[5] && key[5] <= '9') + kt = CPL_DICB_WCS; + else if (CPL_UNLIKELY(!memcmp(key, "ESO ", 4))) + kt = CPL_DICB_HIERARCH_ESO; + else { + cpl_property_sorttype_dicb mykt = kt; + + /* NAXISn/TFORMn/TBCOLn, n = 1..9 */ + + if (!memcmp(key, "NAXIS", 5)) + mykt = CPL_DICB_NAXISn; + else if (!memcmp(key, "TFORM", 5)) + mykt = CPL_DICB_TFORMn; + else if (!memcmp(key, "TBCOL", 5)) + mykt = CPL_DICB_TBCOLn; + else if (!memcmp(key, "CRVAL", 5)) + mykt = CPL_DICB_WCS; + else if (!memcmp(key, "CRPIX", 5)) + mykt = CPL_DICB_WCS; + else if (!memcmp(key, "CDELT", 5)) + mykt = CPL_DICB_WCS; + else if (!memcmp(key, "CTYPE", 5)) + mykt = CPL_DICB_WCS; + else if (!memcmp(key, "CUNIT", 5)) + mykt = CPL_DICB_WCS; + else if (!memcmp(key, "CRDER", 5)) + mykt = CPL_DICB_WCS; + else if (!memcmp(key, "CSYER", 5)) + mykt = CPL_DICB_WCS; + + if (mykt != kt && '1' <= key[5] && key[5] <= '9') { + kt = mykt; + } + } + break; + case 8: + if (!memcmp(key, "HISTORY", 7)) + kt = CPL_DICB_HISTORY; + else if (!memcmp(key, "COMMENT", 7)) + kt = CPL_DICB_COMMENT; + else if (!memcmp(key, "TFIELDS", 7)) + kt = CPL_DICB_TFIELDS; + else if (!memcmp(key, "EXPTIME", 7)) + kt = CPL_DICB_DESCRIBE; + else if (!memcmp(key, "MJD-OBS", 7)) + kt = CPL_DICB_DESCRIBE; + else if (!memcmp(key, "MJD-END", 7)) + kt = CPL_DICB_DESCRIBE; + else if (!memcmp(key, "EQUINOX", 7)) + kt = CPL_DICB_DESCRIBE; + else if (!memcmp(key, "TIMESYS", 7)) + kt = CPL_DICB_DESCRIBE; + else if (!memcmp(key, "WCSAXES", 7)) + kt = CPL_DICB_WCS; + else if (!memcmp(key, "WCSNAME", 7)) + kt = CPL_DICB_WCS; + else if (CPL_UNLIKELY(!memcmp(key, "ESO ", 4))) + kt = CPL_DICB_HIERARCH_ESO; + else { + cpl_property_sorttype_dicb mykt = kt; + + /* NAXISn/TFORMn/TBCOLn, n = 10..99 */ + + if (!memcmp(key, "TFORM", 5)) + mykt = CPL_DICB_TFORMn; + else if (!memcmp(key, "TBCOL", 5)) + mykt = CPL_DICB_TBCOLn; + else if (CPL_UNLIKELY(!memcmp(key, "NAXIS", 5))) + mykt = CPL_DICB_NAXISn; + else if (CPL_UNLIKELY(!memcmp(key, "CRVAL", 5))) + mykt = CPL_DICB_WCS; + else if (CPL_UNLIKELY(!memcmp(key, "CRPIX", 5))) + mykt = CPL_DICB_WCS; + else if (CPL_UNLIKELY(!memcmp(key, "CDELT", 5))) + mykt = CPL_DICB_WCS; + else if (CPL_UNLIKELY(!memcmp(key, "CTYPE", 5))) + mykt = CPL_DICB_WCS; + else if (CPL_UNLIKELY(!memcmp(key, "CUNIT", 5))) + mykt = CPL_DICB_WCS; + else if (CPL_UNLIKELY(!memcmp(key, "CRDER", 5))) + mykt = CPL_DICB_WCS; + else if (CPL_UNLIKELY(!memcmp(key, "CSYER", 5))) + mykt = CPL_DICB_WCS; + + if (mykt != kt && '1' <= key[5] && key[5] <= '9' && + '0' <= key[6] && key[6] <= '9') { + kt = mykt; + } /* With NAXIS 10-99, these are WCS keys */ + else if (CPL_UNLIKELY(key[3] == '_' && + (!memcmp(key, "PC", 2) || + !memcmp(key, "PV", 2) || + !memcmp(key, "PS", 2) || + !memcmp(key, "CD", 2))) && + '1' <= key[2] && key[2] <= '9' && '1' <= key[4] && + key[4] <= '9' && '0' <= key[5] && key[5] <= '9' && + '0' <= key[6] && key[6] <= '9') + kt = CPL_DICB_WCS; + else if (CPL_UNLIKELY(key[4] == '_' && + (!memcmp(key, "PC", 2) || + !memcmp(key, "PV", 2) || + !memcmp(key, "PS", 2) || + !memcmp(key, "CD", 2))) && + '1' <= key[2] && key[2] <= '9' && '0' <= key[3] && + key[3] <= '9' && '1' <= key[5] && key[5] <= '9' && + '0' <= key[6] && key[6] <= '9') + kt = CPL_DICB_WCS; + else if (CPL_UNLIKELY(key[5] == '_' && + (!memcmp(key, "PC", 2) || + !memcmp(key, "PV", 2) || + !memcmp(key, "PS", 2) || + !memcmp(key, "CD", 2))) && + '1' <= key[2] && key[2] <= '9' && '0' <= key[3] && + key[3] <= '9' && '0' <= key[4] && key[4] <= '9' && + '1' <= key[6] && key[6] <= '9') + kt = CPL_DICB_WCS; + } + break; + + case 9: + if (!memcmp(key, "XTENSION", 8)) + kt = CPL_DICB_TOP; + else if (!memcmp(key, "TELESCOP", 8)) + kt = CPL_DICB_DESCRIBE; + else if (!memcmp(key, "INSTRUME", 8)) + kt = CPL_DICB_DESCRIBE; + else if (!memcmp(key, "DATE-OBS", 8)) + kt = CPL_DICB_DESCRIBE; + else if (!memcmp(key, "DATE-END", 8)) + kt = CPL_DICB_DESCRIBE; + else if (!memcmp(key, "OBSERVER", 8)) + kt = CPL_DICB_DESCRIBE; + else if (!memcmp(key, "RADECSYS", 8)) + kt = CPL_DICB_DESCRIBE; + else if (CPL_UNLIKELY(!memcmp(key, "ESO ", 4))) + kt = CPL_DICB_HIERARCH_ESO; + else { + cpl_property_sorttype_dicb mykt = kt; + + /* NAXISn/TFORMn/TBCOLn, n = 100..999 */ + + if (!memcmp(key, "TFORM", 5)) + mykt = CPL_DICB_TFORMn; + else if (!memcmp(key, "TBCOL", 5)) + mykt = CPL_DICB_TBCOLn; + else if (CPL_UNLIKELY(!memcmp(key, "NAXIS", 5))) + mykt = CPL_DICB_NAXISn; + else if (CPL_UNLIKELY(!memcmp(key, "CRVAL", 5))) + mykt = CPL_DICB_WCS; + else if (CPL_UNLIKELY(!memcmp(key, "CRPIX", 5))) + mykt = CPL_DICB_WCS; + else if (CPL_UNLIKELY(!memcmp(key, "CDELT", 5))) + mykt = CPL_DICB_WCS; + else if (CPL_UNLIKELY(!memcmp(key, "CTYPE", 5))) + mykt = CPL_DICB_WCS; + else if (CPL_UNLIKELY(!memcmp(key, "CUNIT", 5))) + mykt = CPL_DICB_WCS; + else if (CPL_UNLIKELY(!memcmp(key, "CRDER", 5))) + mykt = CPL_DICB_WCS; + else if (CPL_UNLIKELY(!memcmp(key, "CSYER", 5))) + mykt = CPL_DICB_WCS; + + if (mykt != kt && '1' <= key[5] && key[5] <= '9' && + '0' <= key[6] && key[6] <= '9' && '0' <= key[7] && + key[7] <= '9') { + kt = mykt; + } /* With NAXIS 100-999, these are WCS keys */ + else if (CPL_UNLIKELY(key[4] == '_' && + (!memcmp(key, "PC", 2) || + !memcmp(key, "PV", 2) || + !memcmp(key, "PS", 2) || + !memcmp(key, "CD", 2))) && + '1' <= key[2] && key[2] <= '9' && '0' <= key[3] && + key[3] <= '9' && '1' <= key[5] && key[5] <= '9' && + '0' <= key[6] && key[6] <= '9' && '0' <= key[7] && + key[7] <= '9') + kt = CPL_DICB_WCS; + else if (CPL_UNLIKELY(key[5] == '_' && + (!memcmp(key, "PC", 2) || + !memcmp(key, "PV", 2) || + !memcmp(key, "PS", 2) || + !memcmp(key, "CD", 2))) && + '1' <= key[2] && key[2] <= '9' && '0' <= key[3] && + key[3] <= '9' && '0' <= key[4] && key[4] <= '9' && + '1' <= key[6] && key[6] <= '9' && '0' <= key[7] && + key[7] <= '9') + kt = CPL_DICB_WCS; + } + break; + + default: + /* With a length of 9 or more, this is not a standard key... */ + + if (CPL_LIKELY(!memcmp(key, "ESO ", 4))) { + /* NB: The FITS key cannot end with a space, so these checks + are only needed here in the default branch */ + + /* Specific HIERARCH ESO types take precedence + - most frequent ones first */ + + /* Each type can have an additional character appended to it, e.g. + "ESO INS1 DID" so only the first three characters are compared */ + + if (!memcmp(key + 4, "DET", 3)) + kt = CPL_DICB_HIERARCH_DET; + else if (!memcmp(key + 4, "INS", 3)) + kt = CPL_DICB_HIERARCH_INS; + else if (!memcmp(key + 4, "OBS", 3)) + kt = CPL_DICB_HIERARCH_OBS; + else if (!memcmp(key + 4, "TEL", 3)) + kt = CPL_DICB_HIERARCH_TEL; + else if (!memcmp(key + 4, "TPL", 3)) + kt = CPL_DICB_HIERARCH_TPL; + else if (!memcmp(key + 4, "DPR", 3)) + kt = CPL_DICB_HIERARCH_DPR; + else if (!memcmp(key + 4, "GEN", 3)) + kt = CPL_DICB_HIERARCH_GEN; + else if (!memcmp(key + 4, "LOG", 3)) + kt = CPL_DICB_HIERARCH_LOG; + else if (!memcmp(key + 4, "PRO", 3)) + kt = CPL_DICB_HIERARCH_PRO; + else + kt = CPL_DICB_HIERARCH_ESO; + } + else { + kt = CPL_DICB_HIERARCH; + } + + break; + } + + cpl_property_set_sortkey_(self, (cpl_property_sorttype)kt); +} + +/**@}*/ diff -Nru cpl-7.1.4+ds/cplcore/cpl_property_dicb.h cpl-7.2.2+ds/cplcore/cpl_property_dicb.h --- cpl-7.1.4+ds/cplcore/cpl_property_dicb.h 1970-01-01 00:00:00.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_property_dicb.h 2022-04-29 14:56:02.000000000 +0000 @@ -0,0 +1,117 @@ +/* + * This file is part of the ESO Common Pipeline Library + * Copyright (C) 2001-2022 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 CPL_PROPERTY_DICB_H +#define CPL_PROPERTY_DICB_H + +#include "cpl_property_impl.h" + +/*----------------------------------------------------------------------------- + Type definitions + -----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------*/ +/** + @enum cpl_property_sorttype_dicb + @internal + @brief The FITS key types according to DICB + @note This enum may have no more than 256 entries, among which the value zero + is reserved to mean undefined. + + This enum stores all possible DICB types for a FITS keyword. These determine + the order of appearance in a header, they are a crucial point for DICB (ESO) + compliance. This classification is internal to CPL. + + */ +/*----------------------------------------------------------------------------*/ +typedef enum cpl_property_sorttype_dicb +{ + CPL_DICB_UNDEF = CPL_PROPERTY_SORT_UNDEF, + + CPL_DICB_TOP, + + /* Mandatory keywords */ + /* All FITS files */ + CPL_DICB_BITPIX, + + /* Per the FITS standard, NAXISn can go from 1 to 999. */ + CPL_DICB_NAXIS, + CPL_DICB_NAXISn, + + /* Random groups only */ + CPL_DICB_GROUP, + /* Extensions */ + CPL_DICB_PCOUNT, + CPL_DICB_GCOUNT, + /* Main header */ + CPL_DICB_EXTEND, + /* Images */ + CPL_DICB_BSCALE, + CPL_DICB_BZERO, + /* Tables */ + CPL_DICB_TFIELDS, + + /* Per the FITS standard, TBCOLn is indexed and starts with 1 */ + CPL_DICB_TBCOLn, + + /* Per the FITS standard, TBCOLn is indexed and starts with 1 */ + CPL_DICB_TFORMn, + + /* Descriptive keywords defined by DICD */ + CPL_DICB_DESCRIBE, + + /* WCS keywords - may involve dimension digit(s) */ + CPL_DICB_WCS, + + /* Other primary keywords */ + CPL_DICB_PRIMARY, + + /* HIERARCH ESO keywords ordered according to DICB */ + /* Only the two first (3-letter) words count in the ordering */ + CPL_DICB_HIERARCH_XYZ = 1 << 5, /* This bit is shared by these ESO keys */ + CPL_DICB_HIERARCH_DPR = CPL_DICB_HIERARCH_XYZ, + CPL_DICB_HIERARCH_OBS, + CPL_DICB_HIERARCH_TPL, + CPL_DICB_HIERARCH_GEN, + CPL_DICB_HIERARCH_TEL, + CPL_DICB_HIERARCH_INS, + CPL_DICB_HIERARCH_DET, + CPL_DICB_HIERARCH_LOG, + CPL_DICB_HIERARCH_PRO, + /* Other HIERARCH keywords */ + /* Only the first (3-letter "ESO") word count in the ordering */ + CPL_DICB_HIERARCH_ESO = CPL_DICB_HIERARCH_XYZ << 1, + /* Except, in principle, there could be non-ESO cards */ + CPL_DICB_HIERARCH, + + /* HISTORY and COMMENT */ + CPL_DICB_HISTORY, + CPL_DICB_COMMENT, + /* END */ + CPL_DICB_END +} cpl_property_sorttype_dicb; + +/*----------------------------------------------------------------------------- + Function prototypes + -----------------------------------------------------------------------------*/ + +void +cpl_property_set_sortkey_dicb(cpl_property *self) CPL_INTERNAL CPL_ATTR_NONNULL; + +#endif diff -Nru cpl-7.1.4+ds/cplcore/cpl_property.h cpl-7.2.2+ds/cplcore/cpl_property.h --- cpl-7.1.4+ds/cplcore/cpl_property.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_property.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -40,9 +40,9 @@ * Create, copy and destroy operations. */ -cpl_property *cpl_property_new(const char *name, - cpl_type type) CPL_ATTR_ALLOC; -cpl_property *cpl_property_new_array(const char *name, cpl_type type, +cpl_property *cpl_property_new(const char *name, cpl_type type) CPL_ATTR_ALLOC; +cpl_property *cpl_property_new_array(const char *name, + cpl_type type, cpl_size size) CPL_ATTR_ALLOC; cpl_property *cpl_property_duplicate(const cpl_property *other) CPL_ATTR_ALLOC; void cpl_property_delete(cpl_property *self); @@ -59,8 +59,8 @@ */ cpl_error_code cpl_property_set_name(cpl_property *self, const char *name); -cpl_error_code cpl_property_set_comment(cpl_property *self, - const char *comment); +cpl_error_code +cpl_property_set_comment(cpl_property *self, const char *comment); cpl_error_code cpl_property_set_char(cpl_property *self, char value); cpl_error_code cpl_property_set_bool(cpl_property *self, int value); cpl_error_code cpl_property_set_int(cpl_property *self, int value); @@ -69,10 +69,10 @@ cpl_error_code cpl_property_set_float(cpl_property *self, float value); cpl_error_code cpl_property_set_double(cpl_property *self, double value); cpl_error_code cpl_property_set_string(cpl_property *self, const char *value); -cpl_error_code cpl_property_set_double_complex(cpl_property *self, - _Complex double value); -cpl_error_code cpl_property_set_float_complex(cpl_property *self, - _Complex float value); +cpl_error_code +cpl_property_set_double_complex(cpl_property *self, _Complex double value); +cpl_error_code +cpl_property_set_float_complex(cpl_property *self, _Complex float value); /* * Element access diff -Nru cpl-7.1.4+ds/cplcore/cpl_property_impl.h cpl-7.2.2+ds/cplcore/cpl_property_impl.h --- cpl-7.1.4+ds/cplcore/cpl_property_impl.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_property_impl.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -26,7 +26,8 @@ #include /* This internal struct is for creating a constant cx_string */ -struct cpl_cstr { +struct cpl_cstr +{ const cxchar *data; cxsize sz; }; @@ -36,21 +37,29 @@ /* CXSTR() allocates stack memory, so any pointer to it must have same scope */ #ifdef CPL_CXSTR_DEBUG -const cpl_cstr * cxstr_abort(const char*, cxsize); -#define CXSTR(STRING, SIZE) ((size_t)(SIZE) == ((STRING) ? strlen(STRING) : 0) \ - ? &(const cpl_cstr){STRING, SIZE} \ - : cxstr_abort(STRING, SIZE)) +const cpl_cstr *cxstr_abort(const char *, cxsize); +#define CXSTR(STRING, SIZE) \ + ((size_t)(SIZE) == ((STRING) ? strlen(STRING) : 0) \ + ? &(const cpl_cstr){ STRING, SIZE } \ + : cxstr_abort(STRING, SIZE)) #else -#define CXSTR(STRING, SIZE) (&(const cpl_cstr){STRING, SIZE}) +#define CXSTR(STRING, SIZE) (&(const cpl_cstr){ STRING, SIZE }) #endif /* Inline'd accessors not available here ... */ -#define cx_string_get_(SELF) (SELF)->data +#define cx_string_get_(SELF) (SELF)->data #define cx_string_size_(SELF) (SELF)->sz -#define cx_string_equal_(SELF, OTHER) \ - (cx_string_size_(SELF) == cx_string_size_(OTHER) && \ - !memcmp(cx_string_get_(SELF), cx_string_get_(OTHER), \ - cx_string_size_(SELF))) \ +#define cx_string_equal_(SELF, OTHER) \ + (cx_string_size_(SELF) == cx_string_size_(OTHER) && \ + !memcmp(cx_string_get_(SELF), cx_string_get_(OTHER), \ + cx_string_size_(SELF))) + +/* The sort key type and its default value */ +typedef unsigned char cpl_property_sorttype; + +/* cpl_property_compare_sortkey(): sortkey must be unsigned, undef value zero */ +#define CPL_PROPERTY_SORT_UNDEF ((cpl_property_sorttype)0) +#define CPL_PROPERTY_SORT_MAX ((cpl_property_sorttype)-1) CPL_BEGIN_DECLS @@ -62,51 +71,73 @@ * Private methods */ -void -cpl_property_dump(const cpl_property *, FILE *) - CPL_ATTR_NONNULL; +void cpl_property_dump(const cpl_property *, FILE *) CPL_ATTR_NONNULL; -int cpl_property_compare_sortkey(const cpl_property *, - const cpl_property *) +int cpl_property_compare_sortkey(const cpl_property *, const cpl_property *) CPL_INTERNAL CPL_ATTR_PURE CPL_ATTR_NONNULL; -void cpl_property_set_sort_dicb(cpl_property * self) - CPL_INTERNAL CPL_ATTR_NONNULL; - size_t cpl_property_get_size_name(const cpl_property *) - CPL_INTERNAL CPL_ATTR_PURE CPL_ATTR_NONNULL; + CPL_INTERNAL CPL_ATTR_PURE CPL_ATTR_NONNULL; size_t cpl_property_get_size_comment(const cpl_property *) - CPL_INTERNAL CPL_ATTR_PURE CPL_ATTR_NONNULL; + CPL_INTERNAL CPL_ATTR_PURE CPL_ATTR_NONNULL; + +const char *cpl_property_get_name_(const cpl_property *) + CPL_INTERNAL CPL_ATTR_PURE CPL_ATTR_NONNULL; -const char * -cpl_property_get_name_(const cpl_property *) +cpl_size cpl_property_get_size_(const cpl_property *) CPL_INTERNAL CPL_ATTR_PURE CPL_ATTR_NONNULL; -cpl_size -cpl_property_get_size_(const cpl_property *) +cpl_type cpl_property_get_type_(const cpl_property *self) CPL_INTERNAL CPL_ATTR_PURE CPL_ATTR_NONNULL; -const char * -cpl_property_get_string_(const cpl_property *) +cpl_property_sorttype cpl_property_get_sortkey_(const cpl_property *self) CPL_INTERNAL CPL_ATTR_PURE CPL_ATTR_NONNULL; -const char * -cpl_property_get_comment_(const cpl_property *) +const char *cpl_property_get_string_(const cpl_property *) + CPL_INTERNAL CPL_ATTR_PURE CPL_ATTR_NONNULL; + +const char *cpl_property_get_comment_(const cpl_property *) CPL_INTERNAL CPL_ATTR_PURE CPL_ATTR_NONNULL; cpl_property * -cpl_property_new_cx(const cpl_cstr *, cpl_type) - CPL_ATTR_NONNULL CPL_ATTR_ALLOC; +cpl_property_new_cx(const cpl_cstr *, cpl_type) CPL_ATTR_NONNULL CPL_ATTR_ALLOC; + +void +cpl_property_set_name_cx(cpl_property *, const cpl_cstr *) CPL_ATTR_NONNULL; + +void +cpl_property_set_string_cx(cpl_property *, const cpl_cstr *) CPL_ATTR_NONNULL; -void cpl_property_set_name_cx(cpl_property *, const cpl_cstr *) - CPL_ATTR_NONNULL; +void +cpl_property_set_comment_cx(cpl_property *, const cpl_cstr *) CPL_ATTR_NONNULL; + +void cpl_property_set_sortkey_(cpl_property *, + cpl_property_sorttype) CPL_ATTR_NONNULL; -void cpl_property_set_string_cx(cpl_property *, const cpl_cstr *) - CPL_ATTR_NONNULL; +void cpl_property_update(cpl_property *, + const cpl_property *) CPL_INTERNAL CPL_ATTR_NONNULL; -void cpl_property_set_comment_cx(cpl_property *, const cpl_cstr *) - CPL_ATTR_NONNULL; +char cpl_property_get_char_(const cpl_property *self) + CPL_INTERNAL CPL_ATTR_PURE CPL_ATTR_NONNULL; +int cpl_property_get_bool_(const cpl_property *self) + CPL_INTERNAL CPL_ATTR_PURE CPL_ATTR_NONNULL; +int cpl_property_get_int_(const cpl_property *self) + CPL_INTERNAL CPL_ATTR_PURE CPL_ATTR_NONNULL; +long cpl_property_get_long_(const cpl_property *self) + CPL_INTERNAL CPL_ATTR_PURE CPL_ATTR_NONNULL; +long long cpl_property_get_long_long_(const cpl_property *self) + CPL_INTERNAL CPL_ATTR_PURE CPL_ATTR_NONNULL; +float cpl_property_get_float_(const cpl_property *self) + CPL_INTERNAL CPL_ATTR_PURE CPL_ATTR_NONNULL; +double cpl_property_get_double_(const cpl_property *self) + CPL_INTERNAL CPL_ATTR_PURE CPL_ATTR_NONNULL; +#ifdef _Complex_I +_Complex float cpl_property_get_float_complex_(const cpl_property *self) + CPL_INTERNAL CPL_ATTR_PURE CPL_ATTR_NONNULL; +_Complex double cpl_property_get_double_complex_(const cpl_property *self) + CPL_INTERNAL CPL_ATTR_PURE CPL_ATTR_NONNULL; +#endif CPL_END_DECLS diff -Nru cpl-7.1.4+ds/cplcore/cpl_propertylist.c cpl-7.2.2+ds/cplcore/cpl_propertylist.c --- cpl-7.1.4+ds/cplcore/cpl_propertylist.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_propertylist.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -18,13 +18,12 @@ */ #ifdef HAVE_CONFIG_H -# include +#include #endif #include #include #include -#include #include #include @@ -44,7 +43,8 @@ #include "cpl_memory.h" #include "cpl_io.h" #include "cpl_propertylist_impl.h" -#include "cpl_property_impl.h" +#include "cpl_property_dicb.h" +#include "cpl_fits_card.h" #include #include @@ -78,450 +78,136 @@ /**@{*/ -enum { - FITS_STDKEY_MAX = 8, - FITS_SVALUE_MAX = 68, - FITS_CARD_LEN = 80 -}; - - /* * The property list type. */ -struct _cpl_propertylist_ { +struct _cpl_propertylist_ +{ cx_deque *properties; }; /* - * Regular expresion filter type - */ - -struct _cpl_regexp_ { - regex_t re; - cxbool invert; -}; - -typedef struct _cpl_regexp_ cpl_regexp; - -/* - * memcmp() filter type - */ - -typedef struct cpl_memcmp_ { - cpl_size nstart; - const cpl_cstr ** startkey; - cpl_size nexact; - const cpl_cstr ** exactkey; - cxbool invert; -} cpl_memcmp_; - -/* - * FITS keyword type mapping for floating point WCS keywords. + * Private methods */ -struct _cpl_wcskeys_ { - const cxchar *key; - cxint sz; - cxchar type; -}; - -typedef struct _cpl_wcskeys_ cpl_wcskeys; - -/* FITS standard 4.1.2.1: - "For indexed keyword names that have a single - positive integer index counter appended to the root name, - the counter shall not have leading zeros (e.g., NAXIS1, not - NAXIS001)." - - https://fits.gsfc.nasa.gov/standard40/fits_standard40aa-le.pdf - -*/ - -static cpl_wcskeys FITS_KEYMAP_WCS[] = { - {"^CRPIX[0-9]+", -1, 'F'}, - {"^CRVAL[0-9]+", -1, 'F'}, - {"^CDELT[0-9]+", -1, 'F'}, - {"^CRDER[0-9]+", -1, 'F'}, - {"^CSYER[0-9]+", -1, 'F'}, - {"^PC[0-9]+_[0-9]+", -1, 'F'}, - {"^PV[0-9]+_[0-9]+", -1, 'F'}, - {"^CD[0-9]+_[0-9]+", -1, 'F'}, - {"EQUINOX", 7, 'F'}, - {"EPOCH", 5, 'F'}, - {"MJD-OBS", 7, 'F'}, - {"LONGPOLE", 8, 'F'}, - {"LATPOLE", 7, 'F'} -}; - +inline static cxbool +cpl_property_check_regexp(const cpl_property *, + cxcptr) CPL_ATTR_PURE CPL_ATTR_NONNULL; -typedef struct cpl_fits_value { - union { - long long i; /* Numerical, integer */ - double f; /* Numerical, double */ - double complex x; /* Numerical, complex */ - char l; /* Boolean: 1 for true ('T') or 0 for false ('F') */ - const char * c; /* String, any escaped quotes ('') are decoded */ - } val; - int nmemb; /* For string data: number of bytes in buffer - For no-value, undefined value and error: 0 - For one of the other values: 1 - */ - char tcode; /* Type code: FITS code: 'C', 'L', 'F', 'I', 'X', or - 'U' (undefined), 'N' (none) or 0 (unparsable card) */ - char unquote[FLEN_COMMENT]; /* String buffer for decoded string */ -} cpl_fits_value; +inline static cxbool +cpl_property_check_memcmp(const cpl_property *, + cxcptr) CPL_ATTR_PURE CPL_ATTR_NONNULL; -/* - * Private methods - */ +inline static cxbool +cpl_cstr_check_regexp(const cpl_cstr *, cxcptr) CPL_ATTR_PURE CPL_ATTR_NONNULL; -inline static cxint -cpl_fits_key_is_unique(const char **[], const cpl_cstr *, cpl_size) - CPL_ATTR_NONNULL; +inline static cxbool +cpl_cstr_check_memcmp(const cpl_cstr *, cxcptr) CPL_ATTR_PURE CPL_ATTR_NONNULL; +inline static cpl_size cpl_propertylist_erase_filter(cpl_propertylist *self, + const cpl_memcmp *, + const cpl_regexp *) +#ifdef CPL_HAVE_ATTR_NONNULL + __attribute__((nonnull(1))) +#endif + ; -inline static void -cpl_fits_key_free_unique(const char **[]) - CPL_ATTR_NONNULL; +inline static cxbool +cpl_property_compare_name(const cpl_property *, + const cpl_cstr *) CPL_ATTR_PURE CPL_ATTR_NONNULL; -inline static cxint -_cpl_propertylist_filter_regexp(cxcptr, cxcptr) +inline static cx_deque_iterator +cpl_propertylist_find_pos(const cpl_propertylist *, const cpl_cstr *) +#ifdef CX_DISABLE_ASSERT + CPL_ATTR_PURE +#endif CPL_ATTR_NONNULL; -inline static cxint -_cpl_propertylist_filter_memcmp(cxcptr, cxcptr) +inline static cx_deque_iterator +cpl_propertylist_find_pos_(const cpl_propertylist *, const char *) +#ifdef CX_DISABLE_ASSERT + CPL_ATTR_PURE +#endif CPL_ATTR_NONNULL; -inline static -const char * cpl_fits_get_key(const char *, int *, int *) +inline static cpl_property * +cpl_propertylist_find(const cpl_propertylist *, const cpl_cstr *) +#ifdef CX_DISABLE_ASSERT + CPL_ATTR_PURE +#endif CPL_ATTR_NONNULL; -inline static -char cpl_fits_get_value(cpl_fits_value *, const char *, int, int, - const cpl_cstr *, int *) +inline static cpl_property * +cpl_propertylist_find_(const cpl_propertylist *, const char *) +#ifdef CX_DISABLE_ASSERT + CPL_ATTR_PURE +#endif CPL_ATTR_NONNULL; -inline static -int cpl_fits_get_number(const char *, int, long long *, double *, int *) +static cpl_error_code cpl_propertylist_copy_filter_(cpl_propertylist *, + const cpl_propertylist *, + const cpl_memcmp *, + const cpl_regexp *) #ifdef CPL_HAVE_ATTR_NONNULL - __attribute__((nonnull(1,4,5))) + __attribute__((nonnull(1, 2))) #endif ; -inline static -const char * cpl_fits_get_comment(const char *, int, int *) - CPL_ATTR_NONNULL; - -inline static char cpl_property_find_type(const cpl_cstr*, int) - CPL_ATTR_NONNULL CPL_ATTR_PURE; - -inline static cxbool -cpl_property_compare_name(const cpl_property *, - const cpl_cstr *) CPL_ATTR_NONNULL; - inline static cpl_error_code -_cpl_propertylist_to_fitsfile(fitsfile *, const cpl_propertylist *, - cx_compare_func, cxptr) +_cpl_propertylist_to_fitsfile(fitsfile *, + const cpl_propertylist *, + const cpl_regexp *, + cpl_boolean) #ifdef CPL_HAVE_ATTR_NONNULL - __attribute__((nonnull(1,2))) + __attribute__((nonnull(1, 2))) #endif ; -static cpl_error_code -cpl_propertylist_to_fitsfile_locale(fitsfile *, const cpl_propertylist *, - cx_compare_func, cxptr) +inline static cpl_error_code +cpl_propertylist_to_fitsfile_locale(fitsfile *, + const cpl_propertylist *, + const cpl_regexp *, + cpl_boolean) #ifdef CPL_HAVE_ATTR_NONNULL - __attribute__((nonnull(1,2))) + __attribute__((nonnull(1, 2))) #endif ; -static cpl_error_code -cpl_propertylist_fill_from_fits_locale(cpl_propertylist *, fitsfile *, - int, - cx_compare_func, cxptr) +static cpl_error_code cpl_propertylist_fill_from_fits_locale(cpl_propertylist *, + fitsfile *, + int, + const cpl_memcmp *, + const cpl_regexp *) #ifdef CPL_HAVE_ATTR_NONNULL - __attribute__((nonnull(1,2))) + __attribute__((nonnull(1, 2))) #endif ; inline static cpl_error_code -_cpl_propertylist_fill_from_fits(cpl_propertylist *, fitsfile *, +_cpl_propertylist_fill_from_fits(cpl_propertylist *, + fitsfile *, int, - cx_compare_func, cxptr) + const cpl_memcmp *, + const cpl_regexp *) #ifdef CPL_HAVE_ATTR_NONNULL - __attribute__((nonnull(1,2))) + __attribute__((nonnull(1, 2))) #endif ; - -inline static cxint -_cpl_wcskeys_find(const cxchar *key, const cpl_wcskeys *keymap, - cxint mapsize) -{ - - cxint i = 0; - cxint pos = mapsize; - - for (i = 0; i < mapsize; ++i) { - - if (keymap[i].sz < 0) { - - cpl_regexp pattern; - cxint status = regcomp(&pattern.re, keymap[i].key, - REG_EXTENDED | REG_NOSUB); - if (status) { - return -1; - } - - if (regexec(&pattern.re, key, (size_t)0, NULL, 0) == 0) { - pos = i; - regfree(&pattern.re); - break; - } - regfree(&pattern.re); - - } - else { - - if (strncmp(key, keymap[i].key, keymap[i].sz) == 0) { - pos = i; - break; - } - - } - - } - - return pos; - -} - -/*----------------------------------------------------------------------------*/ -/** - @internal - @brief Determine whether a given property must be floating point - @param key The name w. length of the property, must be non-NULL - @param naxis The value of NAXIS of the given header (may be zero) - @return The property type: 'I', 'F' - @note This internal function has no error checking - - The function does not validate its input according to the FITS standard, - it merely determines whether the given key must be loaded as a floating - point type, even if its actual value can be represented as an integer - - Per this paper coauthored by M. R. Calabretta: - https://www.aanda.org/articles/aa/full/2002/45/aah3859/aah3859.html - - these are numerical keys of a floating point type (where the axis is 1-99): - - CRPIX[0-9]+ - CRVAL[0-9]+ - CDELT[0-9]+ - CRDER[0-9]+ - CSYER[0-9]+ - PC[0-9]+_[0-9]+ - PV[0-9]+_[0-9]+ - CD[0-9]+_[0-9]+ - EQUINOX - EPOCH - MJD-OBS - LONGPOLE - LATPOLE - - */ -/*----------------------------------------------------------------------------*/ -inline static char cpl_property_find_type(const cpl_cstr* key, - int naxis) -{ - char type = 'I'; /* Default type */ - const cxsize keylen = cx_string_size_(key); - const char * keyname = cx_string_get_(key); - - /* Switch on the length, i.e. the number of characters */ - - /* First matching the length of the key to the length of the string literal - allows for a static-length memcmp() which should be inline-able. */ - - /* NB: The indentation that aligns the calls to memcmp() helps to - ensure that strings of identical length share the correct branch */ - - switch (keylen) { - case 5: - if (!memcmp(keyname, "EPOCH", 5)) type = 'F'; - else if (keyname[3] == '_' && 0 < naxis && naxis < 10) { - char mytype = type; - - if (!memcmp(keyname, "PC", 2)) mytype = 'F'; - else if (!memcmp(keyname, "PV", 2)) mytype = 'F'; - else if (!memcmp(keyname, "CD", 2)) mytype = 'F'; - - if (mytype != type && - '0' < keyname[2] && keyname[2] <= '9' && - '0' < keyname[4] && keyname[4] <= '9' ) - type = mytype; - } - - break; - - case 6: - if (0 < naxis && naxis < 10) { - char mytype = type; - - if (!memcmp(keyname, "CRPIX", 5)) mytype = 'F'; - else if (!memcmp(keyname, "CRVAL", 5)) mytype = 'F'; - else if (!memcmp(keyname, "CDELT", 5)) mytype = 'F'; - else if (!memcmp(keyname, "CRDER", 5)) mytype = 'F'; - else if (!memcmp(keyname, "CSYER", 5)) mytype = 'F'; - - if (mytype != type && - '0' < keyname[5] && keyname[5] <= '9') - type = mytype; - } - - break; - - case 7: - if (!memcmp(keyname, "EQUINOX", 7)) type = 'F'; - else if (!memcmp(keyname, "MJD-OBS", 7)) type = 'F'; - else if (!memcmp(keyname, "LATPOLE", 7)) type = 'F'; - - break; - - case 8: - if (!memcmp(keyname, "LONGPOLE", 8)) type = 'F'; - - break; - - default: - break; - } - - if (type == 'I' && naxis > 0 && keylen > 5) { - char mytype = type; - - if (!memcmp(keyname, "CRPIX", 5)) mytype = 'F'; - else if (!memcmp(keyname, "CRVAL", 5)) mytype = 'F'; - else if (!memcmp(keyname, "CDELT", 5)) mytype = 'F'; - else if (!memcmp(keyname, "CRDER", 5)) mytype = 'F'; - else if (!memcmp(keyname, "CSYER", 5)) mytype = 'F'; - else if (!memcmp(keyname, "PC", 2)) mytype = 'F'; - else if (!memcmp(keyname, "PV", 2)) mytype = 'F'; - else if (!memcmp(keyname, "CD", 2)) mytype = 'F'; - - if (mytype != type) { - /* Cover the many multi-digit cases with regular expressions */ - const cxuint nwcs = CX_N_ELEMENTS(FITS_KEYMAP_WCS); - cxuint j; - - j = _cpl_wcskeys_find(keyname, FITS_KEYMAP_WCS, nwcs); - - if ((j < nwcs) && (type != FITS_KEYMAP_WCS[j].type)) { - type = FITS_KEYMAP_WCS[j].type; - } -#ifdef CPL_PROPERTYLIST_DEBUG - if (type != 'I') - cpl_msg_warning(cpl_func, "Floating point key(%zd:naxis=%d): " - "%s (regexp check)", keylen, naxis, - keyname); -#endif - } - } - -#ifdef CPL_PROPERTYLIST_DEBUG - if (type != 'I') { - char keystr[FLEN_KEYWORD]; /* Needed for %s */ - (void)memcpy(keystr, keyname, keylen); - keystr[keylen] = '\0'; - - cpl_msg_warning(cpl_func, "Floating point key(%zd:naxis=%d): %s", - keylen, naxis, keystr); - } -#endif - - return type; -} - - -inline static cxint -_cpl_propertylist_filter_regexp(cxcptr key, cxcptr filter) -{ - - const cxchar *_key = cx_string_get_((const cpl_cstr *)key); - const cpl_regexp *_filter = (const cpl_regexp *)filter; - - if (regexec(&_filter->re, _key, (size_t)0, NULL, 0) == REG_NOMATCH) - return _filter->invert == TRUE ? TRUE : FALSE; - - return _filter->invert == TRUE ? FALSE : TRUE; - -} - -inline static cxint -_cpl_propertylist_filter_memcmp(cxcptr key, cxcptr filter) -{ - - const cpl_cstr *_key = (const cpl_cstr *)key; - const cpl_memcmp_ *_filter = (const cpl_memcmp_ *)filter; - - cpl_size i; - - /* Does the key match the beginning of the provided start-keys ? */ - for (i = 0; i < _filter->nstart; i++) { - if (cx_string_size_(_key) >= cx_string_size_(_filter->startkey[i]) && - !memcmp(cx_string_get_(_key), cx_string_get_(_filter->startkey[i]), - cx_string_size_(_filter->startkey[i]))) break; /* Match */ - } - - if (i < _filter->nstart) return _filter->invert ? FALSE : TRUE; - - /* Does the key exactly match the provided exact-keys ? */ - for (i = 0; i < _filter->nexact; i++) { - if (cx_string_size_(_key) == cx_string_size_(_filter->exactkey[i]) && - !memcmp(cx_string_get_(_key), cx_string_get_(_filter->exactkey[i]), - cx_string_size_(_filter->exactkey[i]))) break; /* Match */ - } - - if (i < _filter->nexact) return _filter->invert ? FALSE : TRUE; - - /* No match */ - - return _filter->invert ? TRUE : FALSE; - -} - - inline static cxbool _cpl_propertylist_compare_start(const cpl_property *property, const char *part_name) { - const cxchar *key = cpl_property_get_name(property); if (strstr(key, part_name) == key) return TRUE; return FALSE; - -} - - -inline static cxbool -_cpl_propertylist_compare_regexp(const cpl_property *property, cpl_regexp *re) -{ - - const cxchar *key = cpl_property_get_name(property); - const cxsize keysz = cpl_property_get_size_name(property); - const cpl_cstr *key_; - - key_ = CXSTR(key, keysz); - - return _cpl_propertylist_filter_regexp(key_, re); - } - /** * @internal * @brief @@ -534,83 +220,77 @@ * */ inline static cxbool -cpl_property_compare_name(const cpl_property *self, - const cpl_cstr *key) +cpl_property_compare_name(const cpl_property *self, const cpl_cstr *key) { const size_t namelen = cpl_property_get_size_name(self); return (namelen != cx_string_size_(key) || memcmp(cpl_property_get_name_(self), cx_string_get_(key), namelen)) - ? FALSE : TRUE; + ? FALSE + : TRUE; } -inline static cx_deque_iterator -_cpl_propertylist_find_(const cpl_propertylist *self, const cpl_cstr *name) +inline static cpl_property * +cpl_propertylist_find(const cpl_propertylist *self, const cpl_cstr *name) { - - cx_deque_iterator first, last; - - first = cx_deque_begin(self->properties); - last = cx_deque_end(self->properties); + cx_deque_iterator first = cx_deque_begin(self->properties); + cx_deque_iterator last = cx_deque_end(self->properties); while (first != last) { cpl_property *p = cx_deque_get(self->properties, first); if (cpl_property_compare_name(p, name)) - break; + return p; first = cx_deque_next(self->properties, first); } - return first; - + return NULL; } inline static cx_deque_iterator -_cpl_propertylist_find(const cpl_propertylist *self, const char *name) +cpl_propertylist_find_pos(const cpl_propertylist *self, const cpl_cstr *name) { - const cpl_cstr * cxstr; + cx_deque_iterator first = cx_deque_begin(self->properties); + cx_deque_iterator last = cx_deque_end(self->properties); - cxstr = CXSTR(name, name ? strlen(name) : 0); - - return _cpl_propertylist_find_(self, cxstr); -} + while (first != last) { + cpl_property *p = cx_deque_get(self->properties, first); -inline static cpl_property * -_cpl_propertylist_get_cx(const cpl_propertylist *self, - const cpl_cstr *name) -{ + if (cpl_property_compare_name(p, name)) + break; - cx_deque_iterator pos = _cpl_propertylist_find_(self, name); + first = cx_deque_next(self->properties, first); + } - if (pos == cx_deque_end(self->properties)) - return NULL; + return first; +} - return cx_deque_get(self->properties, pos); +inline static cx_deque_iterator +cpl_propertylist_find_pos_(const cpl_propertylist *self, const char *name) +{ + const cpl_cstr *cxstr = CXSTR(name, strlen(name)); + return cpl_propertylist_find_pos(self, cxstr); } - inline static cpl_property * -_cpl_propertylist_get(const cpl_propertylist *self, const char *name) +cpl_propertylist_find_(const cpl_propertylist *self, const char *name) { + const cpl_cstr *name_ = CXSTR(name, strlen(name)); - cx_deque_iterator pos = _cpl_propertylist_find(self, name); - - if (pos == cx_deque_end(self->properties)) - return NULL; - - return cx_deque_get(self->properties, pos); - + return cpl_propertylist_find(self, name_); } -inline static int -_cpl_propertylist_insert(cpl_propertylist *self, const cxchar *where, - cxbool after, const cxchar *name, cpl_type type, +static int +_cpl_propertylist_insert(cpl_propertylist *self, + const cxchar *where, + cxbool after, + const cxchar *name, + cpl_type type, cxcptr value) { - cx_deque_iterator pos; cpl_property *property; @@ -619,7 +299,7 @@ * Find the position where value should be inserted. */ - pos = _cpl_propertylist_find(self, where); + pos = cpl_propertylist_find_pos_(self, where); if (pos == cx_deque_end(self->properties)) { return 1; @@ -700,7 +380,6 @@ cx_deque_insert(self->properties, pos, property); return 0; - } @@ -710,8 +389,48 @@ * @param self The propertylist to insert * @param file The CFITSIO file object * @param hdumov Absolute extension number to move to first (0 for primary) - * @param filter An optional compare function for filtering the properties - * @param data An optional regexp w. invert flag for filtering the properties + * @param names An optional list of names w. invert flag for filtering cards + * @param regexp An optional regexp w. invert flag for filtering cards + * @return CPL_ERROR_NONE, or the relevant CPL error on failure + * @see _cpl_propertylist_fill_from_fits + */ +static cpl_error_code +cpl_propertylist_fill_from_fits_locale(cpl_propertylist *self, + fitsfile *file, + int hdumov, + const cpl_memcmp *names, + const cpl_regexp *regexp) +{ +#ifdef CPL_HAVE_LOCALE + /* Need the POSIX locale for parsing FITS via C-functions */ + locale_t posix_locale = newlocale(LC_NUMERIC_MASK, "POSIX", (locale_t)0); + /* Set the POSIX locale and keep the old one for subsequent reinstating + - should not be able to fail, but check nevertheless */ + locale_t old_locale = + posix_locale != (locale_t)0 ? uselocale(posix_locale) : (locale_t)0; +#endif + + const cpl_error_code code = + _cpl_propertylist_fill_from_fits(self, file, hdumov, names, regexp); + +#ifdef CPL_HAVE_LOCALE + if (posix_locale != (locale_t)0) { + (void)uselocale(old_locale); /* Restore the previous locale */ + freelocale(posix_locale); + } +#endif + + return code ? cpl_error_set_where_() : CPL_ERROR_NONE; +} + +/* + * @internal + * @brief Insert cards from a FITS CHU into a propertylist + * @param self The propertylist to insert + * @param file The CFITSIO file object + * @param hdumov Absolute extension number to move to first (0 for primary) + * @param names An optional list of names w. invert flag for filtering cards + * @param regexp An optional regexp w. invert flag for filtering cards * @return CPL_ERROR_NONE, or the relevant CPL error on failure * @see cpl_propertylist_to_fitsfile * @@ -724,253 +443,79 @@ */ inline static cpl_error_code -_cpl_propertylist_fill_from_fits(cpl_propertylist *self, fitsfile *file, +_cpl_propertylist_fill_from_fits(cpl_propertylist *self, + fitsfile *file, int hdumov, - cx_compare_func filter, cxptr data) + const cpl_memcmp *names, + const cpl_regexp *regexp) { - - char buffer[FLEN_CARD]; - char keystr[FLEN_KEYWORD]; /* Needed for regexp filter */ - int status = 0; - int ncards = 0; - int naxis = 0; - - - if (hdumov >= 0 && fits_movabs_hdu(file, 1+hdumov, NULL, &status)) { + char cardi[FLEN_CARD]; + LONGLONG headstart = 0; + int status = 0; + int ncards = 0; + + /* Move to the requested header */ + if (hdumov >= 0 && + fits_movabs_hdu(file, 1 + hdumov, NULL, &status)) { /* ffmahd() */ return cpl_error_set_fits(CPL_ERROR_DATA_NOT_FOUND, status, - fits_movabs_hdu, "HDU#=%d", hdumov); - } - - if (fits_get_hdrspace(file, &ncards, NULL, &status)) { /* ffghsp() */ - return cpl_error_set_fits(CPL_ERROR_FILE_IO, status, - fits_get_hdrspace, "HDU#=%d", hdumov); - } - - if (ncards <= 0) { - return cpl_error_set_message_(CPL_ERROR_BAD_FILE_FORMAT, - "HDU#=%d: ncards=%d", - hdumov, ncards); + fits_movabs_hdu, "HDU#=%d", hdumov); } - /* Seek to beginning of Header */ - if (fits_movabs_key(file, 1, &status)) { /* ffmaky() */ + /* Find and seek to beginning of the header, ffghadll() */ + if (fits_get_hduaddrll(file, &headstart, NULL, NULL, &status)) { return cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, status, - fits_movabs_key, "HDU#=%d", hdumov); + fits_get_hduaddrll, "HDU#=%d", hdumov); } - - /* Need null-terminator for parsing a card with a numerical value */ - buffer[FLEN_CARD - 1] = '\0'; - - for (int i = 1; i <= ncards; i++) { - const char * cardi = buffer; - const cpl_cstr * keywlen; - cpl_property * property; - const char * keymem; - const char * commentmem = NULL; - cpl_boolean get_comment = CPL_TRUE; - cpl_fits_value parseval; - int keylen = 0; /* Length excl. terminating null byte */ - int valinlen = 0; /* Length to value indicator */ - int compos = 0; - int comlen; - char type; - - if (ffgnky(file, buffer, &status)) { - return cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, status, ffgnky, - "HDU#=%d: Bad card %d/%d", - hdumov, i, ncards); - - } - - keymem = cpl_fits_get_key(cardi, &keylen, &valinlen); - - if (keylen+1 >= FLEN_KEYWORD) { - return cpl_error_set_message_(CPL_ERROR_BAD_FILE_FORMAT, "HDU#=%d: " - "Card %d/%d has bad key (len=%d)", - hdumov, i, ncards, keylen); - } - - if (filter != NULL) { - /* The filter may require a null-terminated string */ - (void)memcpy(keystr, keymem, keylen); - keystr[keylen] = '\0'; - - if (filter(CXSTR(keystr, keylen), data) == FALSE) { - /* Card is filtered out */ - continue; - } - } - - keywlen = CXSTR(keymem, keylen); - - type = cpl_fits_get_value(&parseval, cardi, valinlen, naxis, keywlen, - &compos); - - /* - * Create the property from the parsed FITS card. - */ - - switch (type) { - case 'L': - property = cpl_property_new_cx(keywlen, CPL_TYPE_BOOL); - cpl_property_set_bool(property, parseval.val.l); - - break; - - case 'I': - - if ((long long)((int)parseval.val.i) == parseval.val.i) { - - /* Using an 'int' since the integer property fits */ - - property = cpl_property_new_cx(keywlen, CPL_TYPE_INT); - cpl_property_set_int(property, (int)parseval.val.i); - - /* Get a limit on digits in floating point keys */ - if (cx_string_equal_(keywlen, CXSTR("NAXIS", 5))) - naxis = (int)parseval.val.i; - - } else { - property = cpl_property_new_cx(keywlen, CPL_TYPE_LONG_LONG); - cpl_property_set_long_long(property, parseval.val.i); - - } - - break; - - case 'F': - - property = cpl_property_new_cx(keywlen, CPL_TYPE_DOUBLE); - cpl_property_set_double(property, parseval.val.f); - - break; - - case 'U': /* Undefined value fall-through to no-value */ - case 'N': - - comlen = FITS_CARD_LEN - compos; - - /* Skip totally empty records */ - if (keylen == 0 && comlen == 0) continue; - - /* - * FITS standard: blank keywords may be followed by - * any ASCII text as it is for COMMENT and HISTORY. - * - * In order to preserve this header record it is - * changed into COMMENT record, so that it can be - * stored in the property list. - */ - - /* For a value-less card, a string value is made from the comment - which becomes empty */ - - parseval.val.c = cardi + compos; - parseval.nmemb = comlen; - comlen = 0; - - get_comment = CPL_FALSE; - - CPL_ATTR_FALLTRHU; /* fall through */ - case 'C': - - /* For the above fall through, a blank key becomes a comment key */ - property = cpl_property_new_cx(keylen == 0 ? CXSTR("COMMENT", 7) - : keywlen, CPL_TYPE_STRING); - - cpl_property_set_string_cx(property, - CXSTR(parseval.nmemb > 0 - ? parseval.val.c : "", - parseval.nmemb)); - - break; - - case 'X': - - property = cpl_property_new_cx(keywlen, CPL_TYPE_DOUBLE_COMPLEX); - cpl_property_set_double_complex(property, parseval.val.x); - - break; - - default: { - /* A card with an invalid value will go here */ - const char badchar[2] = {cardi[compos], '\0'}; - return cpl_error_set_message_(CPL_ERROR_BAD_FILE_FORMAT, "HDU#=%d: " - "Bad value in card %d/%d, key-len=%d " - "(valinlen=%d, compos=%d, bad-char=" - "0x%02x (\"%s\")", hdumov, i, ncards, - keylen, valinlen, compos, - (int)*badchar, badchar); - } - } - - if (get_comment) { - commentmem = cpl_fits_get_comment(cardi, compos, &comlen); - } - - /* While for the cpl_property a NULL comment is the default, - here an empty comment is set as such */ - cpl_property_set_comment_cx(property, - CXSTR(comlen > 0 ? commentmem : "", - comlen)); - - cx_deque_push_back(self->properties, property); + if (ffmbyt(file, headstart, REPORT_EOF, &status)) { + return cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, status, ffmbyt, + "HDU#=%d", hdumov); } - return CPL_ERROR_NONE; -} - - -/* - * @internal - * @brief Insert cards from a FITS CHU into a propertylist, setting the locale - * @param self The propertylist to insert - * @param file The CFITSIO file object - * @param hdumov Absolute extension number to move to first (0 for primary) - * @param filter An optional compare function for filtering the properties - * @param data An optional regexp w. invert flag for filtering the properties - * @return CPL_ERROR_NONE, or the relevant CPL error on failure - * @see _cpl_propertylist_fill_from_fits - * - */ + /* Determine number of header cards */ + if (fits_get_hdrspace(file, &ncards, NULL, &status)) { /* ffghsp() */ + return cpl_error_set_fits(CPL_ERROR_FILE_IO, status, fits_get_hdrspace, + "HDU#=%d", hdumov); + } -static cpl_error_code -cpl_propertylist_fill_from_fits_locale(cpl_propertylist *self, fitsfile *file, - int hdumov, - cx_compare_func filter, cxptr data) -{ -#ifdef CPL_HAVE_LOCALE - /* Need the POSIX locale for parsing FITS via C-functions */ - locale_t posix_locale = newlocale(LC_NUMERIC_MASK, "POSIX", (locale_t) 0); - /* Set the POSIX locale and keep the old one for subsequent reinstating - - should not be able to fail, but check nevertheless */ - locale_t old_locale = posix_locale != (locale_t)0 - ? uselocale(posix_locale) : (locale_t)0; -#endif + if (ncards <= 0) { + return cpl_error_set_message_(CPL_ERROR_BAD_FILE_FORMAT, + "HDU#=%d: ncards=%d", hdumov, ncards); + } - const cpl_error_code code = - _cpl_propertylist_fill_from_fits(self, file, hdumov, filter, data); + /* Need null-terminator for parsing a card with a numerical value */ + cardi[FLEN_CARD - 1] = '\0'; -#ifdef CPL_HAVE_LOCALE - if (posix_locale != (locale_t)0) { - (void)uselocale(old_locale); /* Restore the previous locale */ - freelocale(posix_locale); + for (int i = 1; i <= ncards; i++) { + /* Read one card and advance file pointer. + NB: Avoid ffgnky() which strips trailing blanks */ + if (ffgbyt(file, FLEN_CARD - 1, cardi, &status)) { + return cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, status, ffgbyt, + "HDU#=%d: Bad card %d/%d", hdumov, i, + ncards); + } + + /* Parse one card */ + if (cpl_propertylist_append_from_string(self, cardi, names, regexp)) { + return cpl_error_set_message_(cpl_error_get_code(), + "HDU#=%d: " + "Bad FITS Card %d/%d", + hdumov, i, ncards); + } } -#endif - return code ? cpl_error_set_where_() : CPL_ERROR_NONE; + return CPL_ERROR_NONE; } /* * @internal * @brief - * Save the current property list to FITS via cfitsio, setting the locale + * Save the current property list to a FITS file using cfitsio. * - * @param file The CFITSIO file object - * @param self The propertylist to be saved - * @param filter An optional compare function for filtering the properties - * @param data An optional regexp w. invert flag for filtering the properties + * @param file The CFITSIO file object + * @param self The propertylist to be saved + * @param regexp An optional regexp w. invert flag for filtering cards + * @param update Whether to update or overwrite an existing extension * * @return * CPL_ERROR_NONE, or the relevant CPL error on failure @@ -978,23 +523,23 @@ * @see _cpl_propertylist_to_fitsfile */ -static cpl_error_code +inline static cpl_error_code cpl_propertylist_to_fitsfile_locale(fitsfile *file, const cpl_propertylist *self, - cx_compare_func filter, - cxptr data) + const cpl_regexp *regexp, + cpl_boolean update) { #ifdef CPL_HAVE_LOCALE /* Need the POSIX locale for parsing FITS via C-functions */ - locale_t posix_locale = newlocale(LC_NUMERIC_MASK, "POSIX", (locale_t) 0); + locale_t posix_locale = newlocale(LC_NUMERIC_MASK, "POSIX", (locale_t)0); /* Set the POSIX locale and keep the old one for subsequent reinstating - should not be able to fail, but check nevertheless */ - locale_t old_locale = posix_locale != (locale_t)0 - ? uselocale(posix_locale) : (locale_t)0; + locale_t old_locale = + posix_locale != (locale_t)0 ? uselocale(posix_locale) : (locale_t)0; #endif const cpl_error_code code = - _cpl_propertylist_to_fitsfile(file, self, filter, data); + _cpl_propertylist_to_fitsfile(file, self, regexp, update); #ifdef CPL_HAVE_LOCALE if (posix_locale != (locale_t)0) { @@ -1006,15 +551,16 @@ return code ? cpl_error_set_where_() : CPL_ERROR_NONE; } + /* * @internal * @brief * Save the current property list to a FITS file using cfitsio. * - * @param file The CFITSIO file object - * @param self The propertylist to be saved - * @param filter An optional compare function for filtering the properties - * @param data An optional regexp w. invert flag for filtering the properties + * @param file The CFITSIO file object + * @param self The propertylist to be saved + * @param regexp An optional regexp w. invert flag for filtering cards + * @param update Whether to update or overwrite an existing extension * * @return * CPL_ERROR_NONE, or the relevant CPL error on failure @@ -1036,300 +582,245 @@ */ inline static cpl_error_code -_cpl_propertylist_to_fitsfile(fitsfile *file, const cpl_propertylist *self, - cx_compare_func filter, cxptr data) -{ - const char **putkey[FLEN_KEYWORD] = - {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; +_cpl_propertylist_to_fitsfile(fitsfile *file, + const cpl_propertylist *self, + const cpl_regexp *regexp, + cpl_boolean update) +{ + const char **putkey[FLEN_KEYWORD] = { + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL + }; - cx_deque_iterator first, last; - const cpl_boolean do_filter = filter != NULL && data != NULL; + char cardi[FLEN_CARD]; - const cpl_size nsize = cx_deque_size(self->properties); - cpl_size ntocheck = nsize; + cx_deque_iterator first, last; + + const cpl_size nsize = cx_deque_size(self->properties); + cpl_size ntocheck = nsize; -#ifdef CPL_USE_LONGSTRN - /* - Used for the OGIP Long String Keyword Convention: - http://heasarc.gsfc.nasa.gov/docs/heasarc/ofwg/docs/ofwg_recomm/r13.html - */ - cpl_boolean has_longstr = CPL_FALSE; -#endif first = cx_deque_begin(self->properties); - last = cx_deque_end(self->properties); + last = cx_deque_end(self->properties); + + cardi[FLEN_CARD - 1] = '\0'; while (first != last) { - const cpl_property *p = cx_deque_get(self->properties, first); - const cxchar *name = cpl_property_get_name_(p); - const cxchar *comment = cpl_property_get_comment_(p); + const cpl_property *p = cx_deque_get(self->properties, first); + const cxchar *name = cpl_property_get_name_(p); + const cxchar *comment = cpl_property_get_comment_(p); + const cpl_type type = cpl_property_get_type_(p); const cpl_cstr *name_; - const cxsize namelen = cpl_property_get_size_name(p); - const cpl_type type = cpl_property_get_type(p); - cpl_boolean is_unique; + cxsize namelen; cxint error = 0; + int is_unique; - name_ = CXSTR(name, namelen); - ntocheck--; - if (do_filter && filter(name_, data) == TRUE) { - first = cx_deque_next(self->properties, first); - continue; + if (regexp != NULL) { + const cpl_cstr *name0 = +#ifdef CPL_CXSTR_DEBUG + CXSTR(name, cpl_property_get_size_name(p)) +#else + /* The regexp parser cannot use the size */ + CXSTR(name, 0) +#endif + ; + if (cpl_cstr_check_regexp(name0, regexp) == TRUE) { + first = cx_deque_next(self->properties, first); + continue; + } } - /* For N properties fits_update_key() has complexity O(N^2) in - FITS card parsing calls (ffgcrd() w. ffgknm() + ffgnky()) so - try something less inefficient. */ - is_unique = cpl_fits_key_is_unique(putkey, name_, ntocheck) > 0 - ? CPL_FALSE : CPL_TRUE; + namelen = cpl_property_get_size_name(p); + name_ = CXSTR(name, namelen); -#ifndef CX_DISABLE_ASSERT - if (!is_unique) { - cpl_msg_warning(cpl_func, "Non-unique FITS key(len=%d): %s (%d/%d)", - (int)namelen, name, (int)(nsize - ntocheck), - (int)nsize); + if (update) { + /* Unless the card is commentary, it must be assumed that it has + already been written, and that it must thus be updated. */ + + is_unique = + (type == CPL_TYPE_STRING && !cpl_fits_key_is_comment(name_)) + ? -1 + : 1; } + else { + /* For N properties fits_update_key() has complexity O(N^2) in + FITS card parsing calls (ffgcrd() w. ffgknm() + ffgnky()) so + try something less inefficient. */ + is_unique = cpl_fits_key_is_unique(putkey, name_, ntocheck); + +#ifndef CX_DISABLE_ASSERT + if (is_unique > 0) { + /* FIXME: The CFITSIO function ffflnm() is unsafe, so to + provide the filename of the open FITS file, the filename + needs to be passed down from the CPL-caller. :-( */ + cpl_msg_warning(cpl_func, + "Non-unique FITS key(len=%d): %s " + "(%d/%d)", + (int)namelen, name, (int)(nsize - ntocheck), + (int)nsize); + } #endif + } - switch (type) { + if (is_unique < 1) { + if (cpl_fits_fill_card(cardi, p)) { + cpl_fits_key_free_unique(putkey); + return cpl_error_set_message_(cpl_error_get_code(), + "Bad FITS Card %d/%d", + (int)(nsize - ntocheck), + (int)nsize); + } + else if (cpl_fits_write_record(file, cardi, &error)) { + cpl_fits_key_free_unique(putkey); /* ffprec() */ + return cpl_error_set_fits(CPL_ERROR_ILLEGAL_INPUT, error, + fits_write_record, + "name='%s', " + "type=%d ('%s'), comment='%s'", + name, type, cpl_type_get_name(type), + comment); + } + first = cx_deque_next(self->properties, first); + continue; + } - /* For each type call the relevant CFITSIO key writing function. */ + switch (type) { + /* For each type call the relevant CFITSIO key writing function. */ - case CPL_TYPE_CHAR: - { - const cxchar c = cpl_property_get_char(p); + case CPL_TYPE_CHAR: { + const cxchar c = cpl_property_get_char_(p); /* * Character properties should be represented as a single * character string, not as its numerical equivalent. */ - const cxchar value[2] = {c, '\0'}; - /* ffpkys() / ffukys() */ - (void)(is_unique ? fits_write_key_str : fits_update_key_str) - (file, name, value, comment, &error); - } - break; + const cxchar value[2] = { c, '\0' }; + /* ffukys() */ + (void)fits_update_key_str(file, name, value, comment, &error); + } break; - case CPL_TYPE_BOOL: - { - const cxint b = cpl_property_get_bool(p); + case CPL_TYPE_BOOL: { + const cxint b = cpl_property_get_bool_(p); const cxint value = b == TRUE ? 1 : 0; - /* ffpkyl()/ ffukyl() */ - (void)(is_unique ? fits_write_key_log : fits_update_key_log) - (file, name, value, comment, &error); - } - break; + /* ffukyl() */ + (void)fits_update_key_log(file, name, value, comment, &error); + } break; - case CPL_TYPE_INT: - { - const cxint value = cpl_property_get_int(p); + case CPL_TYPE_INT: { + const cxint value = cpl_property_get_int_(p); - /* ffpkyj() / ffukyj() */ - (void)(is_unique ? fits_write_key_lng : fits_update_key_lng) - (file, name, value, comment, &error); - } - break; + /* ffukyj() */ + (void)fits_update_key_lng(file, name, value, comment, &error); + } break; - case CPL_TYPE_LONG: - { - const cxlong value = cpl_property_get_long(p); + case CPL_TYPE_LONG: { + const cxlong value = cpl_property_get_long_(p); - /* ffpkyj() / ffukyj() */ - (void)(is_unique ? fits_write_key_lng : fits_update_key_lng) - (file, name, value, comment, &error); - } - break; + /* ffukyj() */ + (void)fits_update_key_lng(file, name, value, comment, &error); + } break; - case CPL_TYPE_LONG_LONG: - { - const long long value = cpl_property_get_long_long(p); + case CPL_TYPE_LONG_LONG: { + const long long value = cpl_property_get_long_long_(p); - /* ffpkyj() / ffukyj() */ - (void)(is_unique ? fits_write_key_lng : fits_update_key_lng) - (file, name, value, comment, &error); - } - break; + /* ffukyj() */ + (void)fits_update_key_lng(file, name, value, comment, &error); + } break; - case CPL_TYPE_FLOAT: - { - const cxfloat value = cpl_property_get_float(p); + case CPL_TYPE_FLOAT: { + const cxfloat value = cpl_property_get_float_(p); const int ff_fp = -7; /* Default CFITSIO float precision */ - /* ffpkye() / ffukye() */ - (void)(is_unique ? fits_write_key_flt : fits_update_key_flt) - (file, name, value, ff_fp, comment, &error); - } - break; + /* ffukye() */ + (void)fits_update_key_flt(file, name, value, ff_fp, comment, + &error); + } break; - case CPL_TYPE_DOUBLE: - { - const cxdouble value = cpl_property_get_double(p); + case CPL_TYPE_DOUBLE: { + const cxdouble value = cpl_property_get_double_(p); const int ff_dp = -15; /* Default CFITSIO double precision */ - /* ffpkyd() / ffukyd() */ - (void)(is_unique ? fits_write_key_dbl : fits_update_key_dbl) - (file, name, value, ff_dp, comment, &error); - } - break; - - case CPL_TYPE_STRING: - if (cx_string_equal_(CXSTR("COMMENT", 7), name_)) { - /* The size is the string length incl. the null-byte */ - const cxsize valuesize = cpl_property_get_size_(p); - const cxchar * value = valuesize <= 1 ? " " : - cpl_property_get_string_(p); - - if (fits_write_comment(file, value, &error)) { /* ffpcom() */ - cpl_fits_key_free_unique(putkey); - return cpl_error_set_fits(CPL_ERROR_ILLEGAL_INPUT, - error, fits_write_comment, - "name='%s', type=%d ('%s'), " - "comment='%s'", name, - type, cpl_type_get_name(type), - comment); - } - - } - else if (cx_string_equal_(CXSTR("HISTORY", 7), name_)) { - /* The size is the string length incl. the null-byte */ - const cxsize valuesize = cpl_property_get_size_(p); - const cxchar * value = valuesize <= 1 ? " " : - cpl_property_get_string_(p); - - if (fits_write_history(file, value, &error)) { /* ffphis() */ - cpl_fits_key_free_unique(putkey); - return cpl_error_set_fits(CPL_ERROR_ILLEGAL_INPUT, - error, fits_write_history, - "name='%s', type=%d ('%s'), " - "comment='%s'", name, - type, cpl_type_get_name(type), - comment); - } - - } - else { - const cxchar * value = cpl_property_get_string_(p); - -#ifdef CPL_USE_LONGSTRN - /* In v. 3.24 fits_update_key_longstr() has a buffer - overflow triggered by a long comment. :-(((((((((((( */ - /* Try to work around this by using a truncated comment. */ - cxchar shortcomment[FLEN_COMMENT]; - - if (comment != NULL) { - (void)strncpy(shortcomment, comment, FLEN_COMMENT-1); - shortcomment[FLEN_COMMENT-1] = '\0'; - } - - if (!has_longstr) { - - has_longstr = CPL_TRUE; - - if (fits_write_key_longwarn(file, &error)) { - cpl_fits_key_free_unique(putkey); - return cpl_error_set_fits(CPL_ERROR_FILE_IO, error, - fits_write_key_longwarn, - " "); - } - - } - - if (fits_update_key_longstr(file, name, value, - comment != NULL ? - shortcomment : NULL, - &error)) { - cpl_fits_key_free_unique(putkey); - return cpl_error_set_fits(CPL_ERROR_ILLEGAL_INPUT, - error,fits_update_key_longstr, - "name='%s', value='%s', " - "comment='%s'", - name, value, comment); - } + /* ffukyd() */ + (void)fits_update_key_dbl(file, name, value, ff_dp, comment, + &error); + } break; -#else + case CPL_TYPE_STRING: { + const cxchar *value = cpl_property_get_string_(p); - /* ffpkys() / ffukys() */ - if ((is_unique ? fits_write_key_str : fits_update_key_str) - (file, name, value, comment, &error)) { + /* ffukys() */ + if (fits_update_key_str(file, name, value, comment, &error)) { cpl_fits_key_free_unique(putkey); - return cpl_error_set_fits(CPL_ERROR_ILLEGAL_INPUT, - error, fits_update_key_str, + return cpl_error_set_fits(CPL_ERROR_ILLEGAL_INPUT, error, + fits_update_key_str, "name='%s', value='%s', " "comment='%s'", name, value, comment); } -#endif - - } - break; + } break; - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { /* After v. 3.31 const correctness is incomplete only for the value pointer, which is taken as void *, but which ideally should be const void *. */ - const float complex value = cpl_property_get_float_complex(p); - float value_[2] = {crealf(value), cimagf(value)}; + const float complex value = cpl_property_get_float_complex_(p); + float value_[2] = { crealf(value), cimagf(value) }; const int ff_fp = -7; /* Default CFITSIO float precision */ - /* ffpkyc() / ffukyc() */ - (void)(is_unique ? fits_write_key_cmp : fits_update_key_cmp) - (file, name, value_, ff_fp, comment, &error); - } - break; + /* ffukyc() */ + (void)fits_update_key_cmp(file, name, value_, ff_fp, comment, + &error); + } break; - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { /* After v. 3.31 const correctness is incomplete only for the value pointer, which is taken as void *, but which ideally should be const void *. */ - const double complex value = cpl_property_get_double_complex(p); - double value_[2] = {creal(value), cimag(value)}; + const double complex value = + cpl_property_get_double_complex_(p); + double value_[2] = { creal(value), cimag(value) }; const int ff_fp = -15; /* Default CFITSIO float precision */ - /* ffpkym() / ffukym() */ - (void) - (is_unique ? fits_write_key_dblcmp : fits_update_key_dblcmp) - (file, name, value_, ff_fp, comment, &error); - } - break; + /* ffukym() */ + (void)fits_update_key_dblcmp(file, name, value_, ff_fp, comment, + &error); + } break; - default: - cpl_fits_key_free_unique(putkey); - return cpl_error_set_message_(CPL_ERROR_UNSUPPORTED_MODE, - "name='%s', type=%d ('%s'), " - "comment='%s'", name, type, - cpl_type_get_name(type), comment); + default: + cpl_fits_key_free_unique(putkey); + return cpl_error_set_message_(CPL_ERROR_UNSUPPORTED_MODE, + "name='%s', type=%d ('%s'), " + "comment='%s'", + name, type, + cpl_type_get_name(type), comment); } if (error) { cpl_fits_key_free_unique(putkey); return cpl_error_set_fits(CPL_ERROR_ILLEGAL_INPUT, error, - fits_update_key, "name='%s', " - "type=%d ('%s'), comment='%s'", name, - type, cpl_type_get_name(type), comment); + fits_update_key, + "name='%s', " + "type=%d ('%s'), comment='%s'", + name, type, cpl_type_get_name(type), + comment); } first = cx_deque_next(self->properties, first); - } cpl_fits_key_free_unique(putkey); @@ -1358,13 +849,11 @@ cpl_propertylist * cpl_propertylist_new(void) { - cpl_propertylist *self = cx_malloc(sizeof *self); self->properties = cx_deque_new(); return self; - } @@ -1396,8 +885,6 @@ cpl_propertylist * cpl_propertylist_duplicate(const cpl_propertylist *self) { - - cx_deque_iterator first, last; cpl_propertylist *copy = NULL; @@ -1424,7 +911,6 @@ } return copy; - } @@ -1444,14 +930,12 @@ void cpl_propertylist_delete(cpl_propertylist *self) { - if (self) { cx_deque_destroy(self->properties, (cx_free_func)cpl_property_delete); cx_free(self); } return; - } @@ -1484,16 +968,12 @@ cpl_size cpl_propertylist_get_size(const cpl_propertylist *self) { - - - if (self == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return 0L; } - return (cpl_size) cx_deque_size(self->properties); - + return (cpl_size)cx_deque_size(self->properties); } @@ -1525,16 +1005,12 @@ int cpl_propertylist_is_empty(const cpl_propertylist *self) { - - - if (self == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return -1; } return cx_deque_empty(self->properties); - } @@ -1575,18 +1051,16 @@ */ inline cpl_type -cpl_propertylist_get_type_cx(const cpl_propertylist *self, - const cpl_cstr *name) +cpl_propertylist_get_type_cx(const cpl_propertylist *self, const cpl_cstr *name) { - cpl_property *property = _cpl_propertylist_get_cx(self, name); + const cpl_property *property = cpl_propertylist_find(self, name); if (property == NULL) { cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, "%s", name->data); return CPL_TYPE_INVALID; } - return cpl_property_get_type(property); - + return cpl_property_get_type_(property); } @@ -1628,9 +1102,7 @@ cpl_type cpl_propertylist_get_type(const cpl_propertylist *self, const char *name) { - - - cpl_property *property; + const cpl_property *property; if (self == NULL || name == NULL) { @@ -1638,21 +1110,42 @@ return CPL_TYPE_INVALID; } - property = _cpl_propertylist_get(self, name); + property = cpl_propertylist_find_(self, name); if (property == NULL) { cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, "%s", name); return CPL_TYPE_INVALID; } - return cpl_property_get_type(property); - + return cpl_property_get_type_(property); } /** * @internal * @brief + * Get a property from a property list. + * + * @param self A property list. + * @param name The property name to look up. + * + * @return + * The named property or NULL if not present. + * + * The function searches the property list @em self for a property with + * the name @em name and returns it if found, otherwise NULL. + */ + +const cpl_property * +cpl_propertylist_get_const_cx(const cpl_propertylist *self, + const cpl_cstr *name) +{ + return cpl_propertylist_find(self, name); +} + +/** + * @internal + * @brief * Check whether a property is present in a property list. * * @param self A property list. @@ -1682,7 +1175,7 @@ inline int cpl_propertylist_has_cx(const cpl_propertylist *self, const cpl_cstr *name) { - return _cpl_propertylist_get_cx(self, name) != NULL ? 1 : 0; + return cpl_propertylist_find(self, name) != NULL ? 1 : 0; } /** @@ -1716,16 +1209,12 @@ int cpl_propertylist_has(const cpl_propertylist *self, const char *name) { - - - if (self == NULL || name == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return 0; } - return _cpl_propertylist_get(self, name) != NULL ? 1 : 0; - + return cpl_propertylist_find_(self, name) != NULL ? 1 : 0; } @@ -1769,11 +1258,10 @@ */ cpl_error_code -cpl_propertylist_set_comment(cpl_propertylist *self, const char *name, +cpl_propertylist_set_comment(cpl_propertylist *self, + const char *name, const char *comment) { - - cpl_property *property; @@ -1781,7 +1269,7 @@ return cpl_error_set_(CPL_ERROR_NULL_INPUT); } - property = _cpl_propertylist_get(self, name); + property = cpl_propertylist_find_(self, name); if (property == NULL) { return cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, "%s", name); @@ -1790,7 +1278,6 @@ cpl_property_set_comment(property, comment); return CPL_ERROR_NONE; - } /** @@ -1812,12 +1299,11 @@ */ inline cpl_error_code -cpl_propertylist_set_comment_cx(cpl_propertylist *self, const cpl_cstr *name, +cpl_propertylist_set_comment_cx(cpl_propertylist *self, + const cpl_cstr *name, const cpl_cstr *comment) { - - - cpl_property *property = _cpl_propertylist_get_cx(self, name); + cpl_property *property = cpl_propertylist_find(self, name); if (property == NULL) { return cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, "%s", @@ -1827,7 +1313,6 @@ cpl_property_set_comment_cx(property, comment); return CPL_ERROR_NONE; - } @@ -1869,11 +1354,8 @@ */ cpl_error_code -cpl_propertylist_set_char(cpl_propertylist *self, const char *name, - char value) +cpl_propertylist_set_char(cpl_propertylist *self, const char *name, char value) { - - cpl_property *property; @@ -1881,14 +1363,13 @@ return cpl_error_set_(CPL_ERROR_NULL_INPUT); } - property = _cpl_propertylist_get(self, name); + property = cpl_propertylist_find_(self, name); if (property == NULL) { return cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, "%s", name); } return cpl_property_set_char(property, value); - } @@ -1932,8 +1413,6 @@ cpl_error_code cpl_propertylist_set_bool(cpl_propertylist *self, const char *name, int value) { - - cpl_property *property; @@ -1941,14 +1420,13 @@ return cpl_error_set_(CPL_ERROR_NULL_INPUT); } - property = _cpl_propertylist_get(self, name); + property = cpl_propertylist_find_(self, name); if (property == NULL) { return cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, "%s", name); } return cpl_property_set_bool(property, value); - } @@ -1992,8 +1470,6 @@ cpl_error_code cpl_propertylist_set_int(cpl_propertylist *self, const char *name, int value) { - - cpl_property *property; @@ -2001,14 +1477,13 @@ return cpl_error_set_(CPL_ERROR_NULL_INPUT); } - property = _cpl_propertylist_get(self, name); + property = cpl_propertylist_find_(self, name); if (property == NULL) { return cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, "%s", name); } return cpl_property_set_int(property, value); - } @@ -2050,11 +1525,8 @@ */ cpl_error_code -cpl_propertylist_set_long(cpl_propertylist *self, const char *name, - long value) +cpl_propertylist_set_long(cpl_propertylist *self, const char *name, long value) { - - cpl_property *property; @@ -2062,14 +1534,13 @@ return cpl_error_set_(CPL_ERROR_NULL_INPUT); } - property = _cpl_propertylist_get(self, name); + property = cpl_propertylist_find_(self, name); if (property == NULL) { return cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, "%s", name); } return cpl_property_set_long(property, value); - } @@ -2111,11 +1582,10 @@ */ cpl_error_code -cpl_propertylist_set_long_long(cpl_propertylist *self, const char *name, +cpl_propertylist_set_long_long(cpl_propertylist *self, + const char *name, long long value) { - - cpl_property *property; @@ -2123,14 +1593,13 @@ return cpl_error_set_(CPL_ERROR_NULL_INPUT); } - property = _cpl_propertylist_get(self, name); + property = cpl_propertylist_find_(self, name); if (property == NULL) { return cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, "%s", name); } return cpl_property_set_long_long(property, value); - } @@ -2172,11 +1641,10 @@ */ cpl_error_code -cpl_propertylist_set_float(cpl_propertylist *self, const char *name, +cpl_propertylist_set_float(cpl_propertylist *self, + const char *name, float value) { - - cpl_property *property; @@ -2184,14 +1652,13 @@ return cpl_error_set_(CPL_ERROR_NULL_INPUT); } - property = _cpl_propertylist_get(self, name); + property = cpl_propertylist_find_(self, name); if (property == NULL) { return cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, "%s", name); } return cpl_property_set_float(property, value); - } @@ -2233,11 +1700,10 @@ */ cpl_error_code -cpl_propertylist_set_double(cpl_propertylist *self, const char *name, +cpl_propertylist_set_double(cpl_propertylist *self, + const char *name, double value) { - - cpl_property *property; @@ -2245,14 +1711,13 @@ return cpl_error_set_(CPL_ERROR_NULL_INPUT); } - property = _cpl_propertylist_get(self, name); + property = cpl_propertylist_find_(self, name); if (property == NULL) { return cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, "%s", name); } return cpl_property_set_double(property, value); - } @@ -2294,11 +1759,10 @@ */ cpl_error_code -cpl_propertylist_set_string(cpl_propertylist *self, const char *name, +cpl_propertylist_set_string(cpl_propertylist *self, + const char *name, const char *value) { - - cpl_property *property; @@ -2306,14 +1770,13 @@ return cpl_error_set_(CPL_ERROR_NULL_INPUT); } - property = _cpl_propertylist_get(self, name); + property = cpl_propertylist_find_(self, name); if (property == NULL) { return cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, "%s", name); } return cpl_property_set_string(property, value); - } @@ -2355,7 +1818,8 @@ */ cpl_error_code -cpl_propertylist_set_float_complex(cpl_propertylist *self, const char *name, +cpl_propertylist_set_float_complex(cpl_propertylist *self, + const char *name, float complex value) { cpl_property *property; @@ -2365,15 +1829,15 @@ return cpl_error_set_(CPL_ERROR_NULL_INPUT); } - property = _cpl_propertylist_get(self, name); + property = cpl_propertylist_find_(self, name); if (property == NULL) { return cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, "%s", name); } return cpl_property_set_float_complex(property, value) - ? cpl_error_set_where_() : CPL_ERROR_NONE; - + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -2415,10 +1879,10 @@ */ cpl_error_code -cpl_propertylist_set_double_complex(cpl_propertylist *self, const char *name, +cpl_propertylist_set_double_complex(cpl_propertylist *self, + const char *name, double complex value) { - cpl_property *property; @@ -2426,15 +1890,15 @@ return cpl_error_set_(CPL_ERROR_NULL_INPUT); } - property = _cpl_propertylist_get(self, name); + property = cpl_propertylist_find_(self, name); if (property == NULL) { return cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, "%s", name); } return cpl_property_set_double_complex(property, value) - ? cpl_error_set_where_() : CPL_ERROR_NONE; - + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -2467,11 +1931,9 @@ * @c NULL. */ -const cpl_property * +inline const cpl_property * cpl_propertylist_get_const(const cpl_propertylist *self, long position) { - - #ifdef CPL_PROPERTYLIST_ENABLE_LOOP_CHECK cxsize i = 0; #endif @@ -2508,7 +1970,6 @@ } return cx_deque_get(self->properties, (cx_deque_const_iterator)position); - } /** @@ -2543,7 +2004,6 @@ cpl_property * cpl_propertylist_get(cpl_propertylist *self, long position) { - cpl_errorstate prestate = cpl_errorstate_get(); cpl_property *property; @@ -2555,7 +2015,6 @@ (void)cpl_error_set_where_(); return property; - } /** * @brief @@ -2596,9 +2055,7 @@ const char * cpl_propertylist_get_comment(const cpl_propertylist *self, const char *name) { - - - cpl_property *property; + const cpl_property *property; if (self == NULL || name == NULL) { @@ -2606,7 +2063,7 @@ return NULL; } - property = _cpl_propertylist_get(self, name); + property = cpl_propertylist_find_(self, name); if (!property) { cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, "%s", name); @@ -2614,7 +2071,6 @@ } return cpl_property_get_comment(property); - } @@ -2664,11 +2120,9 @@ char cpl_propertylist_get_char(const cpl_propertylist *self, const char *name) { - - cxchar result; - cpl_property *property; + const cpl_property *property; cpl_errorstate prevstate; @@ -2677,7 +2131,7 @@ return '\0'; } - property = _cpl_propertylist_get(self, name); + property = cpl_propertylist_find_(self, name); if (!property) { cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, "%s", name); @@ -2695,12 +2149,10 @@ if (!cpl_errorstate_is_equal(prevstate)) { cpl_error_set_where_(); - return '\0'; } return result; - } @@ -2752,11 +2204,9 @@ int cpl_propertylist_get_bool(const cpl_propertylist *self, const char *name) { - - cxbool result; - cpl_property *property; + const cpl_property *property; cpl_errorstate prevstate; @@ -2765,7 +2215,7 @@ return 0; } - property = _cpl_propertylist_get(self, name); + property = cpl_propertylist_find_(self, name); if (!property) { cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, "%s", name); @@ -2783,12 +2233,10 @@ if (!cpl_errorstate_is_equal(prevstate)) { cpl_error_set_where_(); - return 0; } return result == TRUE ? 1 : 0; - } @@ -2838,11 +2286,9 @@ int cpl_propertylist_get_int(const cpl_propertylist *self, const char *name) { - - cxint result; - cpl_property *property; + const cpl_property *property; cpl_errorstate prevstate; @@ -2851,7 +2297,7 @@ return 0; } - property = _cpl_propertylist_get(self, name); + property = cpl_propertylist_find_(self, name); if (!property) { cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, "%s", name); @@ -2869,11 +2315,9 @@ if (!cpl_errorstate_is_equal(prevstate)) { cpl_error_set_where_(); - return 0; } return result; - } @@ -2928,11 +2372,9 @@ long cpl_propertylist_get_long(const cpl_propertylist *self, const char *name) { - - cxlong result; - cpl_property *property; + const cpl_property *property; cpl_errorstate prevstate; @@ -2942,7 +2384,7 @@ return 0; } - property = _cpl_propertylist_get(self, name); + property = cpl_propertylist_find_(self, name); if (!property) { cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, "%s", name); @@ -2960,12 +2402,10 @@ if (!cpl_errorstate_is_equal(prevstate)) { cpl_error_set_where_(); - return 0; } return result; - } @@ -3021,11 +2461,9 @@ long long cpl_propertylist_get_long_long(const cpl_propertylist *self, const char *name) { - - cxllong result; - cpl_property *property; + const cpl_property *property; cpl_errorstate prevstate; @@ -3035,7 +2473,7 @@ return 0; } - property = _cpl_propertylist_get(self, name); + property = cpl_propertylist_find_(self, name); if (!property) { cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, "%s", name); @@ -3054,12 +2492,10 @@ if (!cpl_errorstate_is_equal(prevstate)) { cpl_error_set_where_(); - return 0; } return result; - } @@ -3110,11 +2546,9 @@ float cpl_propertylist_get_float(const cpl_propertylist *self, const char *name) { - - cxfloat result; - cpl_property *property; + const cpl_property *property; cpl_errorstate prevstate; @@ -3123,7 +2557,7 @@ return 0; } - property = _cpl_propertylist_get(self, name); + property = cpl_propertylist_find_(self, name); if (!property) { cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, "%s", name); @@ -3141,11 +2575,9 @@ if (!cpl_errorstate_is_equal(prevstate)) { cpl_error_set_where_(); - return 0; } return result; - } @@ -3201,11 +2633,9 @@ double cpl_propertylist_get_double(const cpl_propertylist *self, const char *name) { - - cxdouble result; - cpl_property *property; + const cpl_property *property; cpl_errorstate prevstate; @@ -3215,7 +2645,7 @@ return 0; } - property = _cpl_propertylist_get(self, name); + property = cpl_propertylist_find_(self, name); if (!property) { cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, "%s", name); @@ -3233,12 +2663,10 @@ if (!cpl_errorstate_is_equal(prevstate)) { cpl_error_set_where_(); - return 0; } return result; - } @@ -3289,11 +2717,9 @@ const char * cpl_propertylist_get_string(const cpl_propertylist *self, const char *name) { - - const cxchar *result; - cpl_property *property; + const cpl_property *property; cpl_errorstate prevstate; @@ -3302,7 +2728,7 @@ return NULL; } - property = _cpl_propertylist_get(self, name); + property = cpl_propertylist_find_(self, name); if (!property) { cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, "%s", name); @@ -3320,11 +2746,9 @@ if (!cpl_errorstate_is_equal(prevstate)) { cpl_error_set_where_(); - return NULL; } return result; - } @@ -3376,10 +2800,9 @@ cpl_propertylist_get_float_complex(const cpl_propertylist *self, const char *name) { - float complex result; - cpl_property *property; + const cpl_property *property; cpl_errorstate prevstate; @@ -3388,7 +2811,7 @@ return 0.0; } - property = _cpl_propertylist_get(self, name); + property = cpl_propertylist_find_(self, name); if (!property) { (void)cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, "%s", name); @@ -3406,11 +2829,9 @@ if (!cpl_errorstate_is_equal(prevstate)) { (void)cpl_error_set_where_(); - return 0.0; } return result; - } @@ -3467,10 +2888,9 @@ cpl_propertylist_get_double_complex(const cpl_propertylist *self, const char *name) { - double complex result; - cpl_property *property; + const cpl_property *property; cpl_errorstate prevstate; @@ -3480,7 +2900,7 @@ return 0.0; } - property = _cpl_propertylist_get(self, name); + property = cpl_propertylist_find_(self, name); if (!property) { (void)cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, "%s", name); @@ -3498,12 +2918,10 @@ if (!cpl_errorstate_is_equal(prevstate)) { (void)cpl_error_set_where_(); - return 0.0; } return result; - } /** @@ -3544,11 +2962,11 @@ */ cpl_error_code -cpl_propertylist_insert_char(cpl_propertylist *self, const char *here, - const char *name, char value) +cpl_propertylist_insert_char(cpl_propertylist *self, + const char *here, + const char *name, + char value) { - - cxint status = 0; @@ -3556,15 +2974,14 @@ return cpl_error_set_(CPL_ERROR_NULL_INPUT); } - status = _cpl_propertylist_insert(self, here, FALSE, name, - CPL_TYPE_CHAR, (cxcptr)&value); + status = _cpl_propertylist_insert(self, here, FALSE, name, CPL_TYPE_CHAR, + (cxcptr)&value); if (status) { return cpl_error_set_(CPL_ERROR_UNSPECIFIED); } return CPL_ERROR_NONE; - } @@ -3606,11 +3023,11 @@ */ cpl_error_code -cpl_propertylist_insert_bool(cpl_propertylist *self, const char *here, - const char *name, int value) -{ - - +cpl_propertylist_insert_bool(cpl_propertylist *self, + const char *here, + const char *name, + int value) +{ cxint status = 0; @@ -3618,15 +3035,14 @@ return cpl_error_set_(CPL_ERROR_NULL_INPUT); } - status = _cpl_propertylist_insert(self, here, FALSE, name, - CPL_TYPE_BOOL, (cxcptr)&value); + status = _cpl_propertylist_insert(self, here, FALSE, name, CPL_TYPE_BOOL, + (cxcptr)&value); if (status) { return cpl_error_set_(CPL_ERROR_UNSPECIFIED); } return CPL_ERROR_NONE; - } @@ -3668,11 +3084,11 @@ */ cpl_error_code -cpl_propertylist_insert_int(cpl_propertylist *self, const char *here, - const char *name, int value) +cpl_propertylist_insert_int(cpl_propertylist *self, + const char *here, + const char *name, + int value) { - - cxint status = 0; @@ -3680,15 +3096,14 @@ return cpl_error_set_(CPL_ERROR_NULL_INPUT); } - status = _cpl_propertylist_insert(self, here, FALSE, name, - CPL_TYPE_INT, (cxcptr)&value); + status = _cpl_propertylist_insert(self, here, FALSE, name, CPL_TYPE_INT, + (cxcptr)&value); if (status) { return cpl_error_set_(CPL_ERROR_UNSPECIFIED); } return CPL_ERROR_NONE; - } @@ -3730,11 +3145,11 @@ */ cpl_error_code -cpl_propertylist_insert_long(cpl_propertylist *self, const char *here, - const char *name, long value) +cpl_propertylist_insert_long(cpl_propertylist *self, + const char *here, + const char *name, + long value) { - - cxint status = 0; @@ -3742,15 +3157,14 @@ return cpl_error_set_(CPL_ERROR_NULL_INPUT); } - status = _cpl_propertylist_insert(self, here, FALSE, name, - CPL_TYPE_LONG, (cxcptr)&value); + status = _cpl_propertylist_insert(self, here, FALSE, name, CPL_TYPE_LONG, + (cxcptr)&value); if (status) { return cpl_error_set_(CPL_ERROR_UNSPECIFIED); } return CPL_ERROR_NONE; - } @@ -3792,11 +3206,11 @@ */ cpl_error_code -cpl_propertylist_insert_long_long(cpl_propertylist *self, const char *here, - const char *name, long long value) +cpl_propertylist_insert_long_long(cpl_propertylist *self, + const char *here, + const char *name, + long long value) { - - cxint status = 0; @@ -3812,7 +3226,6 @@ } return CPL_ERROR_NONE; - } @@ -3854,11 +3267,11 @@ */ cpl_error_code -cpl_propertylist_insert_float(cpl_propertylist *self, const char *here, - const char *name, float value) +cpl_propertylist_insert_float(cpl_propertylist *self, + const char *here, + const char *name, + float value) { - - cxint status = 0; @@ -3866,15 +3279,14 @@ return cpl_error_set_(CPL_ERROR_NULL_INPUT); } - status = _cpl_propertylist_insert(self, here, FALSE, name, - CPL_TYPE_FLOAT, (cxcptr)&value); + status = _cpl_propertylist_insert(self, here, FALSE, name, CPL_TYPE_FLOAT, + (cxcptr)&value); if (status) { return cpl_error_set_(CPL_ERROR_UNSPECIFIED); } return CPL_ERROR_NONE; - } @@ -3916,11 +3328,11 @@ */ cpl_error_code -cpl_propertylist_insert_double(cpl_propertylist *self, const char *here, - const char *name, double value) +cpl_propertylist_insert_double(cpl_propertylist *self, + const char *here, + const char *name, + double value) { - - cxint status = 0; @@ -3928,15 +3340,14 @@ return cpl_error_set_(CPL_ERROR_NULL_INPUT); } - status = _cpl_propertylist_insert(self, here, FALSE, name, - CPL_TYPE_DOUBLE, (cxcptr)&value); + status = _cpl_propertylist_insert(self, here, FALSE, name, CPL_TYPE_DOUBLE, + (cxcptr)&value); if (status) { return cpl_error_set_(CPL_ERROR_UNSPECIFIED); } return CPL_ERROR_NONE; - } @@ -3978,11 +3389,11 @@ */ cpl_error_code -cpl_propertylist_insert_string(cpl_propertylist *self, const char *here, - const char *name, const char *value) +cpl_propertylist_insert_string(cpl_propertylist *self, + const char *here, + const char *name, + const char *value) { - - cxint status = 0; @@ -3990,15 +3401,14 @@ return cpl_error_set_(CPL_ERROR_NULL_INPUT); } - status = _cpl_propertylist_insert(self, here, FALSE, name, - CPL_TYPE_STRING, (cxcptr)value); + status = _cpl_propertylist_insert(self, here, FALSE, name, CPL_TYPE_STRING, + (cxcptr)value); if (status) { return cpl_error_set_(CPL_ERROR_UNSPECIFIED); } return CPL_ERROR_NONE; - } @@ -4040,18 +3450,19 @@ */ cpl_error_code -cpl_propertylist_insert_float_complex(cpl_propertylist *self, const char *here, - const char *name, float complex value) +cpl_propertylist_insert_float_complex(cpl_propertylist *self, + const char *here, + const char *name, + float complex value) { - if (self == NULL || here == NULL || name == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } return _cpl_propertylist_insert(self, here, FALSE, name, - CPL_TYPE_FLOAT_COMPLEX, - (cxcptr)&value) - ? cpl_error_set_(CPL_ERROR_UNSPECIFIED) : CPL_ERROR_NONE; + CPL_TYPE_FLOAT_COMPLEX, (cxcptr)&value) + ? cpl_error_set_(CPL_ERROR_UNSPECIFIED) + : CPL_ERROR_NONE; } @@ -4093,18 +3504,19 @@ */ cpl_error_code -cpl_propertylist_insert_double_complex(cpl_propertylist *self, const char *here, - const char *name, double complex value) +cpl_propertylist_insert_double_complex(cpl_propertylist *self, + const char *here, + const char *name, + double complex value) { - if (self == NULL || here == NULL || name == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } return _cpl_propertylist_insert(self, here, FALSE, name, - CPL_TYPE_DOUBLE_COMPLEX, - (cxcptr)&value) - ? cpl_error_set_(CPL_ERROR_UNSPECIFIED) : CPL_ERROR_NONE; + CPL_TYPE_DOUBLE_COMPLEX, (cxcptr)&value) + ? cpl_error_set_(CPL_ERROR_UNSPECIFIED) + : CPL_ERROR_NONE; } /** @@ -4145,11 +3557,11 @@ */ cpl_error_code -cpl_propertylist_insert_after_char(cpl_propertylist *self, const char *after, - const char *name, char value) +cpl_propertylist_insert_after_char(cpl_propertylist *self, + const char *after, + const char *name, + char value) { - - cxint status = 0; @@ -4157,15 +3569,14 @@ return cpl_error_set_(CPL_ERROR_NULL_INPUT); } - status = _cpl_propertylist_insert(self, after, TRUE, name, - CPL_TYPE_CHAR, (cxcptr)&value); + status = _cpl_propertylist_insert(self, after, TRUE, name, CPL_TYPE_CHAR, + (cxcptr)&value); if (status) { return cpl_error_set_(CPL_ERROR_UNSPECIFIED); } return CPL_ERROR_NONE; - } @@ -4207,11 +3618,11 @@ */ cpl_error_code -cpl_propertylist_insert_after_bool(cpl_propertylist *self, const char *after, - const char *name, int value) +cpl_propertylist_insert_after_bool(cpl_propertylist *self, + const char *after, + const char *name, + int value) { - - cxint status = 0; @@ -4219,15 +3630,14 @@ return cpl_error_set_(CPL_ERROR_NULL_INPUT); } - status = _cpl_propertylist_insert(self, after, TRUE, name, - CPL_TYPE_BOOL, (cxcptr)&value); + status = _cpl_propertylist_insert(self, after, TRUE, name, CPL_TYPE_BOOL, + (cxcptr)&value); if (status) { return cpl_error_set_(CPL_ERROR_UNSPECIFIED); } return CPL_ERROR_NONE; - } @@ -4269,11 +3679,11 @@ */ cpl_error_code -cpl_propertylist_insert_after_int(cpl_propertylist *self, const char *after, - const char *name, int value) +cpl_propertylist_insert_after_int(cpl_propertylist *self, + const char *after, + const char *name, + int value) { - - cxint status = 0; @@ -4281,15 +3691,14 @@ return cpl_error_set_(CPL_ERROR_NULL_INPUT); } - status = _cpl_propertylist_insert(self, after, TRUE, name, - CPL_TYPE_INT, (cxcptr)&value); + status = _cpl_propertylist_insert(self, after, TRUE, name, CPL_TYPE_INT, + (cxcptr)&value); if (status) { return cpl_error_set_(CPL_ERROR_UNSPECIFIED); } return CPL_ERROR_NONE; - } @@ -4331,11 +3740,11 @@ */ cpl_error_code -cpl_propertylist_insert_after_long(cpl_propertylist *self, const char *after, - const char *name, long value) +cpl_propertylist_insert_after_long(cpl_propertylist *self, + const char *after, + const char *name, + long value) { - - cxint status = 0; @@ -4343,15 +3752,14 @@ return cpl_error_set_(CPL_ERROR_NULL_INPUT); } - status = _cpl_propertylist_insert(self, after, TRUE, name, - CPL_TYPE_LONG, (cxcptr)&value); + status = _cpl_propertylist_insert(self, after, TRUE, name, CPL_TYPE_LONG, + (cxcptr)&value); if (status) { return cpl_error_set_(CPL_ERROR_UNSPECIFIED); } return CPL_ERROR_NONE; - } @@ -4394,11 +3802,10 @@ cpl_error_code cpl_propertylist_insert_after_long_long(cpl_propertylist *self, - const char *after, const char *name, + const char *after, + const char *name, long long value) { - - cxint status = 0; @@ -4414,7 +3821,6 @@ } return CPL_ERROR_NONE; - } @@ -4456,11 +3862,11 @@ */ cpl_error_code -cpl_propertylist_insert_after_float(cpl_propertylist *self, const char *after, - const char *name, float value) +cpl_propertylist_insert_after_float(cpl_propertylist *self, + const char *after, + const char *name, + float value) { - - cxint status = 0; @@ -4468,15 +3874,14 @@ return cpl_error_set_(CPL_ERROR_NULL_INPUT); } - status = _cpl_propertylist_insert(self, after, TRUE, name, - CPL_TYPE_FLOAT, (cxcptr)&value); + status = _cpl_propertylist_insert(self, after, TRUE, name, CPL_TYPE_FLOAT, + (cxcptr)&value); if (status) { return cpl_error_set_(CPL_ERROR_UNSPECIFIED); } return CPL_ERROR_NONE; - } @@ -4519,11 +3924,10 @@ cpl_error_code cpl_propertylist_insert_after_double(cpl_propertylist *self, - const char *after, const char *name, + const char *after, + const char *name, double value) { - - cxint status = 0; @@ -4531,15 +3935,14 @@ return cpl_error_set_(CPL_ERROR_NULL_INPUT); } - status = _cpl_propertylist_insert(self, after, TRUE, name, - CPL_TYPE_DOUBLE, (cxcptr)&value); + status = _cpl_propertylist_insert(self, after, TRUE, name, CPL_TYPE_DOUBLE, + (cxcptr)&value); if (status) { return cpl_error_set_(CPL_ERROR_UNSPECIFIED); } return CPL_ERROR_NONE; - } @@ -4582,11 +3985,10 @@ cpl_error_code cpl_propertylist_insert_after_string(cpl_propertylist *self, - const char *after, const char *name, + const char *after, + const char *name, const char *value) { - - cxint status = 0; @@ -4594,15 +3996,14 @@ return cpl_error_set_(CPL_ERROR_NULL_INPUT); } - status = _cpl_propertylist_insert(self, after, TRUE, name, - CPL_TYPE_STRING, (cxcptr)value); + status = _cpl_propertylist_insert(self, after, TRUE, name, CPL_TYPE_STRING, + (cxcptr)value); if (status) { return cpl_error_set_(CPL_ERROR_UNSPECIFIED); } return CPL_ERROR_NONE; - } /** @@ -4644,17 +4045,18 @@ cpl_error_code cpl_propertylist_insert_after_float_complex(cpl_propertylist *self, - const char *after, const char *name, + const char *after, + const char *name, float complex value) { - if (self == NULL || after == NULL || name == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } return _cpl_propertylist_insert(self, after, TRUE, name, CPL_TYPE_FLOAT_COMPLEX, (cxcptr)&value) - ? cpl_error_set_(CPL_ERROR_UNSPECIFIED) : CPL_ERROR_NONE; + ? cpl_error_set_(CPL_ERROR_UNSPECIFIED) + : CPL_ERROR_NONE; } @@ -4701,16 +4103,14 @@ const char *name, double complex value) { - if (self == NULL || after == NULL || name == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } return _cpl_propertylist_insert(self, after, TRUE, name, - CPL_TYPE_DOUBLE_COMPLEX, - (cxcptr)&value) - ? cpl_error_set_(CPL_ERROR_UNSPECIFIED) : CPL_ERROR_NONE; - + CPL_TYPE_DOUBLE_COMPLEX, (cxcptr)&value) + ? cpl_error_set_(CPL_ERROR_UNSPECIFIED) + : CPL_ERROR_NONE; } @@ -4743,11 +4143,10 @@ */ cpl_error_code -cpl_propertylist_prepend_char(cpl_propertylist *self, const char *name, +cpl_propertylist_prepend_char(cpl_propertylist *self, + const char *name, char value) { - - cpl_property *property = NULL; @@ -4762,7 +4161,6 @@ cx_deque_push_front(self->properties, property); return CPL_ERROR_NONE; - } @@ -4795,11 +4193,10 @@ */ cpl_error_code -cpl_propertylist_prepend_bool(cpl_propertylist *self, const char *name, +cpl_propertylist_prepend_bool(cpl_propertylist *self, + const char *name, int value) { - - cpl_property *property = NULL; @@ -4814,7 +4211,6 @@ cx_deque_push_front(self->properties, property); return CPL_ERROR_NONE; - } @@ -4847,11 +4243,10 @@ */ cpl_error_code -cpl_propertylist_prepend_int(cpl_propertylist *self, const char *name, +cpl_propertylist_prepend_int(cpl_propertylist *self, + const char *name, int value) { - - cpl_property *property = NULL; @@ -4866,7 +4261,6 @@ cx_deque_push_front(self->properties, property); return CPL_ERROR_NONE; - } @@ -4899,11 +4293,10 @@ */ cpl_error_code -cpl_propertylist_prepend_long(cpl_propertylist *self, const char *name, +cpl_propertylist_prepend_long(cpl_propertylist *self, + const char *name, long value) { - - cpl_property *property = NULL; @@ -4918,7 +4311,6 @@ cx_deque_push_front(self->properties, property); return CPL_ERROR_NONE; - } @@ -4951,11 +4343,10 @@ */ cpl_error_code -cpl_propertylist_prepend_long_long(cpl_propertylist *self, const char *name, +cpl_propertylist_prepend_long_long(cpl_propertylist *self, + const char *name, long long value) { - - cpl_property *property = NULL; @@ -4970,7 +4361,6 @@ cx_deque_push_front(self->properties, property); return CPL_ERROR_NONE; - } @@ -5003,11 +4393,10 @@ */ cpl_error_code -cpl_propertylist_prepend_float(cpl_propertylist *self, const char *name, +cpl_propertylist_prepend_float(cpl_propertylist *self, + const char *name, float value) { - - cpl_property *property = NULL; @@ -5022,7 +4411,6 @@ cx_deque_push_front(self->properties, property); return CPL_ERROR_NONE; - } @@ -5055,11 +4443,10 @@ */ cpl_error_code -cpl_propertylist_prepend_double(cpl_propertylist *self, const char *name, +cpl_propertylist_prepend_double(cpl_propertylist *self, + const char *name, double value) { - - cpl_property *property = NULL; @@ -5074,7 +4461,6 @@ cx_deque_push_front(self->properties, property); return CPL_ERROR_NONE; - } @@ -5107,11 +4493,10 @@ */ cpl_error_code -cpl_propertylist_prepend_string(cpl_propertylist *self, const char *name, +cpl_propertylist_prepend_string(cpl_propertylist *self, + const char *name, const char *value) { - - cpl_property *property = NULL; @@ -5126,7 +4511,6 @@ cx_deque_push_front(self->properties, property); return CPL_ERROR_NONE; - } @@ -5159,10 +4543,10 @@ */ cpl_error_code -cpl_propertylist_prepend_float_complex(cpl_propertylist *self, const char *name, +cpl_propertylist_prepend_float_complex(cpl_propertylist *self, + const char *name, float complex value) { - cpl_property *property = NULL; @@ -5177,7 +4561,6 @@ cx_deque_push_front(self->properties, property); return CPL_ERROR_NONE; - } @@ -5210,10 +4593,10 @@ */ cpl_error_code -cpl_propertylist_prepend_double_complex(cpl_propertylist *self, const char *name, +cpl_propertylist_prepend_double_complex(cpl_propertylist *self, + const char *name, double complex value) { - cpl_property *property = NULL; @@ -5228,7 +4611,6 @@ cx_deque_push_front(self->properties, property); return CPL_ERROR_NONE; - } /** @@ -5260,11 +4642,10 @@ */ cpl_error_code -cpl_propertylist_append_char(cpl_propertylist *self, const char *name, +cpl_propertylist_append_char(cpl_propertylist *self, + const char *name, char value) { - - cpl_property *property = NULL; @@ -5279,7 +4660,6 @@ cx_deque_push_back(self->properties, property); return CPL_ERROR_NONE; - } @@ -5312,11 +4692,10 @@ */ cpl_error_code -cpl_propertylist_append_bool(cpl_propertylist *self, const char *name, +cpl_propertylist_append_bool(cpl_propertylist *self, + const char *name, int value) { - - cpl_property *property = NULL; @@ -5331,7 +4710,6 @@ cx_deque_push_back(self->properties, property); return CPL_ERROR_NONE; - } @@ -5364,11 +4742,8 @@ */ cpl_error_code -cpl_propertylist_append_int(cpl_propertylist *self, const char *name, - int value) +cpl_propertylist_append_int(cpl_propertylist *self, const char *name, int value) { - - cpl_property *property = NULL; @@ -5383,7 +4758,6 @@ cx_deque_push_back(self->properties, property); return CPL_ERROR_NONE; - } @@ -5416,11 +4790,10 @@ */ cpl_error_code -cpl_propertylist_append_long(cpl_propertylist *self, const char *name, +cpl_propertylist_append_long(cpl_propertylist *self, + const char *name, long value) { - - cpl_property *property = NULL; @@ -5435,7 +4808,6 @@ cx_deque_push_back(self->properties, property); return CPL_ERROR_NONE; - } @@ -5468,11 +4840,10 @@ */ cpl_error_code -cpl_propertylist_append_long_long(cpl_propertylist *self, const char *name, +cpl_propertylist_append_long_long(cpl_propertylist *self, + const char *name, long long value) { - - cpl_property *property = NULL; @@ -5487,7 +4858,6 @@ cx_deque_push_back(self->properties, property); return CPL_ERROR_NONE; - } @@ -5520,11 +4890,10 @@ */ cpl_error_code -cpl_propertylist_append_float(cpl_propertylist *self, const char *name, +cpl_propertylist_append_float(cpl_propertylist *self, + const char *name, float value) { - - cpl_property *property = NULL; @@ -5539,7 +4908,6 @@ cx_deque_push_back(self->properties, property); return CPL_ERROR_NONE; - } @@ -5572,11 +4940,10 @@ */ cpl_error_code -cpl_propertylist_append_double(cpl_propertylist *self, const char *name, +cpl_propertylist_append_double(cpl_propertylist *self, + const char *name, double value) { - - cpl_property *property = NULL; @@ -5591,7 +4958,6 @@ cx_deque_push_back(self->properties, property); return CPL_ERROR_NONE; - } @@ -5624,11 +4990,10 @@ */ cpl_error_code -cpl_propertylist_append_string(cpl_propertylist *self, const char *name, +cpl_propertylist_append_string(cpl_propertylist *self, + const char *name, const char *value) { - - cpl_property *property = NULL; @@ -5643,7 +5008,6 @@ cx_deque_push_back(self->properties, property); return CPL_ERROR_NONE; - } @@ -5676,10 +5040,10 @@ */ cpl_error_code -cpl_propertylist_append_float_complex(cpl_propertylist *self, const char *name, +cpl_propertylist_append_float_complex(cpl_propertylist *self, + const char *name, float complex value) { - cpl_property *property = NULL; @@ -5694,7 +5058,6 @@ cx_deque_push_back(self->properties, property); return CPL_ERROR_NONE; - } @@ -5727,10 +5090,10 @@ */ cpl_error_code -cpl_propertylist_append_double_complex(cpl_propertylist *self, const char *name, +cpl_propertylist_append_double_complex(cpl_propertylist *self, + const char *name, double complex value) { - cpl_property *property = NULL; @@ -5745,7 +5108,6 @@ cx_deque_push_back(self->properties, property); return CPL_ERROR_NONE; - } /** @@ -5775,32 +5137,24 @@ */ cpl_error_code -cpl_propertylist_append(cpl_propertylist *self, - const cpl_propertylist *other) +cpl_propertylist_append(cpl_propertylist *self, const cpl_propertylist *other) { - - if (self == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } if (other != NULL) { - cx_deque_const_iterator pos = cx_deque_begin(other->properties); while (pos != cx_deque_end(other->properties)) { - const cpl_property *p = cx_deque_get(other->properties, pos); cx_deque_push_back(self->properties, cpl_property_duplicate(p)); pos = cx_deque_next(other->properties, pos); - } - } return CPL_ERROR_NONE; - } @@ -5838,7 +5192,7 @@ inline int cpl_propertylist_erase_cx(cpl_propertylist *self, const cpl_cstr *name) { - cx_deque_iterator pos = _cpl_propertylist_find_(self, name); + cx_deque_iterator pos = cpl_propertylist_find_pos(self, name); if (pos == cx_deque_end(self->properties)) { @@ -5848,7 +5202,6 @@ cx_deque_erase(self->properties, pos, (cx_free_func)cpl_property_delete); return 1; - } /** @@ -5884,8 +5237,6 @@ int cpl_propertylist_erase(cpl_propertylist *self, const char *name) { - - cx_deque_iterator pos; @@ -5894,7 +5245,7 @@ return 0; } - pos = _cpl_propertylist_find(self, name); + pos = cpl_propertylist_find_pos_(self, name); if (pos == cx_deque_end(self->properties)) { return 0; } @@ -5902,7 +5253,6 @@ cx_deque_erase(self->properties, pos, (cx_free_func)cpl_property_delete); return 1; - } /** @@ -5948,16 +5298,13 @@ */ int -cpl_propertylist_erase_regexp(cpl_propertylist *self, const char *regexp, +cpl_propertylist_erase_regexp(cpl_propertylist *self, + const char *regexp, int invert) { - - cxint status = 0; cxint count = 0; - cx_deque_iterator first; - cpl_regexp filter; @@ -5973,37 +5320,72 @@ status = regcomp(&filter.re, regexp, REG_EXTENDED | REG_NOSUB); if (status) { - (void)cpl_error_set_regex(CPL_ERROR_ILLEGAL_INPUT, status, - &filter.re, "regexp='%s', invert=%d", - regexp, invert); + (void)cpl_error_set_regex(CPL_ERROR_ILLEGAL_INPUT, status, &filter.re, + "regexp='%s', invert=%d", regexp, invert); return -1; } filter.invert = invert == 0 ? FALSE : TRUE; - first = cx_deque_begin(self->properties); + count = cpl_propertylist_erase_filter(self, NULL, &filter); - while (first < cx_deque_end(self->properties)) { - cx_deque_iterator pos = first; - cpl_property *p = cx_deque_get(self->properties, pos); + if (count < 0) { + (void)cpl_error_set_where_(); + } + + regfree(&filter.re); + + return count; +} + + +/** + * @internal + * @brief + * Erase all properties with name matching the provided filter. + * + * @param self The property list to erase properties from + * @param names An optional list of names w. invert flag for filtering cards + * @param regexp An optional regexp w. invert flag for filtering cards + * + * @return + * On success the function returns the number of erased entries, + * or 0 if no entries are erased. If an error occurs the function returns -1 + * and an appropriate error code is set. + * + * @note No input validation in this internal function + * + */ + +inline static cpl_size +cpl_propertylist_erase_filter(cpl_propertylist *self, + const cpl_memcmp *names, + const cpl_regexp *regexp) +{ + cx_deque_iterator first = cx_deque_begin(self->properties); + cpl_size nerase = 0; + + + while (first != cx_deque_end(self->properties)) { + cpl_property *p = cx_deque_get(self->properties, first); + + if ((names != NULL && cpl_property_check_memcmp(p, names) == TRUE) || + (regexp != NULL && cpl_property_check_regexp(p, regexp) == TRUE)) { + /* Card is to be deleted */ - if (_cpl_propertylist_compare_regexp(p, &filter) == TRUE) { - cx_deque_erase(self->properties, pos, - (cx_free_func)cpl_property_delete); - count++; + nerase++; + + cx_deque_erase(self->properties, first, + (cx_free_func)cpl_property_delete); } else { first = cx_deque_next(self->properties, first); } } - regfree(&filter.re); - - return count; - + return nerase; } - /** * @brief * Remove all properties from a property list. @@ -6031,8 +5413,6 @@ void cpl_propertylist_empty(cpl_propertylist *self) { - - cx_deque_iterator first; @@ -6052,12 +5432,10 @@ cx_deque_iterator pos = first; cx_deque_erase(self->properties, pos, - (cx_free_func)cpl_property_delete); - + (cx_free_func)cpl_property_delete); } return; - } @@ -6100,47 +5478,31 @@ */ cpl_error_code -cpl_propertylist_update_char(cpl_propertylist *self, const char *name, +cpl_propertylist_update_char(cpl_propertylist *self, + const char *name, char value) { - - - cx_deque_iterator pos; - - if (self == NULL || name == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } - - pos = _cpl_propertylist_find(self, name); - - if (pos == cx_deque_end(self->properties)) { - - cpl_property *property = cpl_property_new(name, CPL_TYPE_CHAR); - - - cx_assert(property != NULL); - - cpl_property_set_char(property, value); - cx_deque_push_back(self->properties, property); - } else { + const cpl_cstr *name_ = CXSTR(name, strlen(name)); + cpl_property *property = cpl_propertylist_find(self, name_); - cpl_property *property = cx_deque_get(self->properties, pos); - + if (property == NULL) { + property = cpl_property_new_cx(name_, CPL_TYPE_CHAR); - cx_assert(property != NULL); + cx_assert(property != NULL); - if (cpl_property_get_type(property) != CPL_TYPE_CHAR) { - return cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); + cpl_property_set_char(property, value); + cx_deque_push_back(self->properties, property); + } + else if (cpl_property_set_char(property, value)) { + return cpl_error_set_where_(); } - - cpl_property_set_char(property, value); - } return CPL_ERROR_NONE; - } @@ -6183,47 +5545,31 @@ */ cpl_error_code -cpl_propertylist_update_bool(cpl_propertylist *self, const char *name, +cpl_propertylist_update_bool(cpl_propertylist *self, + const char *name, int value) { - - - cx_deque_iterator pos; - - if (self == NULL || name == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } - - pos = _cpl_propertylist_find(self, name); - - if (pos == cx_deque_end(self->properties)) { - - cpl_property *property = cpl_property_new(name, CPL_TYPE_BOOL); - - - cx_assert(property != NULL); - - cpl_property_set_bool(property, value); - cx_deque_push_back(self->properties, property); - } else { + const cpl_cstr *name_ = CXSTR(name, strlen(name)); + cpl_property *property = cpl_propertylist_find(self, name_); - cpl_property *property = cx_deque_get(self->properties, pos); - + if (property == NULL) { + property = cpl_property_new_cx(name_, CPL_TYPE_BOOL); - cx_assert(property != NULL); + cx_assert(property != NULL); - if (cpl_property_get_type(property) != CPL_TYPE_BOOL) { - return cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); + cpl_property_set_bool(property, value); + cx_deque_push_back(self->properties, property); + } + else if (cpl_property_set_bool(property, value)) { + return cpl_error_set_where_(); } - - cpl_property_set_bool(property, value); - } return CPL_ERROR_NONE; - } @@ -6266,47 +5612,29 @@ */ cpl_error_code -cpl_propertylist_update_int(cpl_propertylist *self, const char *name, - int value) +cpl_propertylist_update_int(cpl_propertylist *self, const char *name, int value) { - - - cx_deque_iterator pos; - - if (self == NULL || name == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } - - pos = _cpl_propertylist_find(self, name); - - if (pos == cx_deque_end(self->properties)) { - - cpl_property *property = cpl_property_new(name, CPL_TYPE_INT); - - - cx_assert(property != NULL); - - cpl_property_set_int(property, value); - cx_deque_push_back(self->properties, property); - } else { + const cpl_cstr *name_ = CXSTR(name, strlen(name)); + cpl_property *property = cpl_propertylist_find(self, name_); - cpl_property *property = cx_deque_get(self->properties, pos); + if (property == NULL) { + property = cpl_property_new_cx(name_, CPL_TYPE_INT); + cx_assert(property != NULL); - cx_assert(property != NULL); - - if (cpl_property_get_type(property) != CPL_TYPE_INT) { - return cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); + cpl_property_set_int(property, value); + cx_deque_push_back(self->properties, property); + } + else if (cpl_property_set_int(property, value)) { + return cpl_error_set_where_(); } - - cpl_property_set_int(property, value); - } return CPL_ERROR_NONE; - } @@ -6346,50 +5674,34 @@ * its value is updated, otherwise a property with the name @em name is * created and added to @em self. The update will fail if a property with * the name @em name exists already which is not of type @c CPL_TYPE_LONG. - */ - -cpl_error_code -cpl_propertylist_update_long(cpl_propertylist *self, const char *name, - long value) -{ - - - cx_deque_iterator pos; - + */ +cpl_error_code +cpl_propertylist_update_long(cpl_propertylist *self, + const char *name, + long value) +{ if (self == NULL || name == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } - - pos = _cpl_propertylist_find(self, name); - - if (pos == cx_deque_end(self->properties)) { - - cpl_property *property = cpl_property_new(name, CPL_TYPE_LONG); - - - cx_assert(property != NULL); - - cpl_property_set_long(property, value); - cx_deque_push_back(self->properties, property); - } else { + const cpl_cstr *name_ = CXSTR(name, strlen(name)); + cpl_property *property = cpl_propertylist_find(self, name_); - cpl_property *property = cx_deque_get(self->properties, pos); + if (property == NULL) { + property = cpl_property_new_cx(name_, CPL_TYPE_LONG); + cx_assert(property != NULL); - cx_assert(property != NULL); - - if (cpl_property_get_type(property) != CPL_TYPE_LONG) { - return cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); + cpl_property_set_long(property, value); + cx_deque_push_back(self->properties, property); + } + else if (cpl_property_set_long(property, value)) { + return cpl_error_set_where_(); } - - cpl_property_set_long(property, value); - } return CPL_ERROR_NONE; - } @@ -6432,47 +5744,31 @@ */ cpl_error_code -cpl_propertylist_update_long_long(cpl_propertylist *self, const char *name, +cpl_propertylist_update_long_long(cpl_propertylist *self, + const char *name, long long value) { - - - cx_deque_iterator pos; - - if (self == NULL || name == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } - - pos = _cpl_propertylist_find(self, name); - - if (pos == cx_deque_end(self->properties)) { - - cpl_property *property = cpl_property_new(name, CPL_TYPE_LONG_LONG); - - - cx_assert(property != NULL); - - cpl_property_set_long_long(property, value); - cx_deque_push_back(self->properties, property); - } else { + const cpl_cstr *name_ = CXSTR(name, strlen(name)); + cpl_property *property = cpl_propertylist_find(self, name_); - cpl_property *property = cx_deque_get(self->properties, pos); + if (property == NULL) { + property = cpl_property_new_cx(name_, CPL_TYPE_LONG_LONG); + cx_assert(property != NULL); - cx_assert(property != NULL); - - if (cpl_property_get_type(property) != CPL_TYPE_LONG_LONG) { - return cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); + cpl_property_set_long_long(property, value); + cx_deque_push_back(self->properties, property); + } + else if (cpl_property_set_long_long(property, value)) { + return cpl_error_set_where_(); } - - cpl_property_set_long_long(property, value); - } return CPL_ERROR_NONE; - } @@ -6515,47 +5811,31 @@ */ cpl_error_code -cpl_propertylist_update_float(cpl_propertylist *self, const char *name, +cpl_propertylist_update_float(cpl_propertylist *self, + const char *name, float value) { - - - cx_deque_iterator pos; - - if (self == NULL || name == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } - - pos = _cpl_propertylist_find(self, name); - - if (pos == cx_deque_end(self->properties)) { - - cpl_property *property = cpl_property_new(name, CPL_TYPE_FLOAT); - - - cx_assert(property != NULL); - - cpl_property_set_float(property, value); - cx_deque_push_back(self->properties, property); - } else { + const cpl_cstr *name_ = CXSTR(name, strlen(name)); + cpl_property *property = cpl_propertylist_find(self, name_); - cpl_property *property = cx_deque_get(self->properties, pos); + if (property == NULL) { + property = cpl_property_new_cx(name_, CPL_TYPE_FLOAT); + cx_assert(property != NULL); - cx_assert(property != NULL); - - if (cpl_property_get_type(property) != CPL_TYPE_FLOAT) { - return cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); + cpl_property_set_float(property, value); + cx_deque_push_back(self->properties, property); + } + else if (cpl_property_set_float(property, value)) { + return cpl_error_set_where_(); } - - cpl_property_set_float(property, value); - } return CPL_ERROR_NONE; - } @@ -6598,50 +5878,95 @@ */ cpl_error_code -cpl_propertylist_update_double(cpl_propertylist *self, const char *name, +cpl_propertylist_update_double(cpl_propertylist *self, + const char *name, double value) { - - - cx_deque_iterator pos; - - if (self == NULL || name == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } + else { + const cpl_cstr *name_ = CXSTR(name, strlen(name)); + cpl_property *property = cpl_propertylist_find(self, name_); - pos = _cpl_propertylist_find(self, name); + if (property == NULL) { + property = cpl_property_new_cx(name_, CPL_TYPE_DOUBLE); - if (pos == cx_deque_end(self->properties)) { + cx_assert(property != NULL); - cpl_property *property = cpl_property_new(name, CPL_TYPE_DOUBLE); + cpl_property_set_double(property, value); + cx_deque_push_back(self->properties, property); + } + else if (cpl_property_set_double(property, value)) { + return cpl_error_set_where_(); + } + } + return CPL_ERROR_NONE; +} - cx_assert(property != NULL); - cpl_property_set_double(property, value); - cx_deque_push_back(self->properties, property); - } - else { +/** + * @internal + * @brief + * Update a property list with a string value. + * + * @param self A property list. + * @param name The property name to be assigned to the value. + * @param value The string value to store. + * + * @note No pointer validation by this internal function + * + * @see cpl_propertylist_update_string() + * + * @return + * The function returns the property assigned to or NULL on error + * + * @error + *
+ * + * + * + * + *
CPL_ERROR_TYPE_MISMATCH + * The property list self contains a property with the + * name name which is not of type CPL_TYPE_STRING. + *
+ * @enderror + * + * The function updates the property list @em self with the string value + * @em value. This means, if a property with the name @em name exists already + * its value is updated, otherwise a property with the name @em name is + * created and added to @em self. The update will fail if a property with + * the name @em name exists already which is not of type @c CPL_TYPE_STRING. + */ - cpl_property *property = cx_deque_get(self->properties, pos); +cpl_property * +cpl_propertylist_update_string_(cpl_propertylist *self, + const cpl_cstr *name, + const cpl_cstr *value) +{ + cpl_property *property = cpl_propertylist_find(self, name); + if (property == NULL) { + property = cpl_property_new_cx(name, CPL_TYPE_STRING); cx_assert(property != NULL); - if (cpl_property_get_type(property) != CPL_TYPE_DOUBLE) { - return cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); - } - - cpl_property_set_double(property, value); - + cpl_property_set_string_cx(property, value); + cx_deque_push_back(self->properties, property); + } + else if (cpl_property_get_type_(property) != CPL_TYPE_STRING) { + (void)cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); + return NULL; + } + else { + cpl_property_set_string_cx(property, value); } - return CPL_ERROR_NONE; - + return property; } - /** * @brief * Update a property list with a string value. @@ -6681,47 +6006,18 @@ */ cpl_error_code -cpl_propertylist_update_string(cpl_propertylist *self, const char *name, +cpl_propertylist_update_string(cpl_propertylist *self, + const char *name, const char *value) { - - - cx_deque_iterator pos; - - if (self == NULL || name == NULL || value == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } - pos = _cpl_propertylist_find(self, name); - - if (pos == cx_deque_end(self->properties)) { - - cpl_property *property = cpl_property_new(name, CPL_TYPE_STRING); - - - cx_assert(property != NULL); - - cpl_property_set_string(property, value); - cx_deque_push_back(self->properties, property); - } - else { - - cpl_property *property = cx_deque_get(self->properties, pos); - - - cx_assert(property != NULL); - - if (cpl_property_get_type(property) != CPL_TYPE_STRING) { - return cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); - } - - cpl_property_set_string(property, value); - - } - - return CPL_ERROR_NONE; - + return cpl_propertylist_update_string_(self, CXSTR(name, strlen(name)), + CXSTR(value, strlen(value))) == NULL + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -6766,44 +6062,31 @@ */ cpl_error_code -cpl_propertylist_update_float_complex(cpl_propertylist *self, const char *name, +cpl_propertylist_update_float_complex(cpl_propertylist *self, + const char *name, float complex value) { - - cx_deque_iterator pos; - - if (self == NULL || name == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } - - pos = _cpl_propertylist_find(self, name); - - if (pos == cx_deque_end(self->properties)) { - - cpl_property *property = cpl_property_new(name, CPL_TYPE_FLOAT_COMPLEX); - - - cx_assert(property != NULL); - - cpl_property_set_float_complex(property, value); - cx_deque_push_back(self->properties, property); - } else { + const cpl_cstr *name_ = CXSTR(name, strlen(name)); + cpl_property *property = cpl_propertylist_find(self, name_); - cpl_property *property = cx_deque_get(self->properties, pos); - + if (property == NULL) { + property = cpl_property_new_cx(name_, CPL_TYPE_FLOAT_COMPLEX); - cx_assert(property != NULL); + cx_assert(property != NULL); - if (cpl_property_set_float_complex(property, value)) { + cpl_property_set_float_complex(property, value); + cx_deque_push_back(self->properties, property); + } + else if (cpl_property_set_float_complex(property, value)) { return cpl_error_set_where_(); } - } return CPL_ERROR_NONE; - } @@ -6848,45 +6131,31 @@ */ cpl_error_code -cpl_propertylist_update_double_complex(cpl_propertylist *self, const char *name, +cpl_propertylist_update_double_complex(cpl_propertylist *self, + const char *name, double complex value) { - - cx_deque_iterator pos; - - if (self == NULL || name == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } - - pos = _cpl_propertylist_find(self, name); - - if (pos == cx_deque_end(self->properties)) { - - cpl_property *property = cpl_property_new(name, - CPL_TYPE_DOUBLE_COMPLEX); - - - cx_assert(property != NULL); - - cpl_property_set_double_complex(property, value); - cx_deque_push_back(self->properties, property); - } else { + const cpl_cstr *name_ = CXSTR(name, strlen(name)); + cpl_property *property = cpl_propertylist_find(self, name_); - cpl_property *property = cx_deque_get(self->properties, pos); + if (property == NULL) { + property = cpl_property_new_cx(name_, CPL_TYPE_DOUBLE_COMPLEX); + cx_assert(property != NULL); - cx_assert(property != NULL); - - if (cpl_property_set_double_complex(property, value)) { + cpl_property_set_double_complex(property, value); + cx_deque_push_back(self->properties, property); + } + else if (cpl_property_set_double_complex(property, value)) { cpl_error_set_where_(); } - } return CPL_ERROR_NONE; - } @@ -6942,93 +6211,33 @@ const cpl_propertylist *other, const char *name) { - - - cx_deque_iterator spos; - cx_deque_iterator tpos; - - if (self == NULL || other == NULL || name == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } - - spos = _cpl_propertylist_find(other, name); - - if (spos == cx_deque_end(other->properties)) { - return cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, "%s", name); - } - - tpos = _cpl_propertylist_find(self, name); - - if (tpos == cx_deque_end(self->properties)) { - - cpl_property *p = cpl_property_duplicate(cx_deque_get(other->properties, - spos)); - cx_deque_push_back(self->properties, p); - - } else { + const cpl_cstr *name_ = CXSTR(name, strlen(name)); + const cpl_property *psrc = cpl_propertylist_find(other, name_); + cpl_property *pdest = cpl_propertylist_find(self, name_); - cpl_property *p = cx_deque_get(self->properties, tpos); - cpl_property *_p = cx_deque_get(other->properties, spos); - - - if (cpl_property_get_type(p) != cpl_property_get_type(_p)) { - return cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); + if (psrc == NULL) { + return cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, "%s", name); } - switch (cpl_property_get_type(_p)) { - - case CPL_TYPE_CHAR: - cpl_property_set_char(p, cpl_property_get_char(_p)); - break; - - case CPL_TYPE_BOOL: - cpl_property_set_bool(p, cpl_property_get_bool(_p)); - break; - - case CPL_TYPE_INT: - cpl_property_set_int(p, cpl_property_get_int(_p)); - break; - - case CPL_TYPE_LONG: - cpl_property_set_long(p, cpl_property_get_long(_p)); - break; - - case CPL_TYPE_FLOAT: - cpl_property_set_float(p, cpl_property_get_float(_p)); - break; - - case CPL_TYPE_DOUBLE: - cpl_property_set_double(p, cpl_property_get_double(_p)); - break; - - case CPL_TYPE_STRING: - cpl_property_set_string(p, cpl_property_get_string(_p)); - break; - - case CPL_TYPE_FLOAT_COMPLEX: - cpl_property_set_float_complex(p, - cpl_property_get_float_complex(_p)); - break; + if (pdest == NULL) { + pdest = cpl_property_duplicate(psrc); - case CPL_TYPE_DOUBLE_COMPLEX: - cpl_property_set_double_complex(p, - cpl_property_get_double_complex(_p)); - break; - - default: - /* This point should never be reached */ - return cpl_error_set_(CPL_ERROR_UNSUPPORTED_MODE); - break; + cx_deque_push_back(self->properties, pdest); + } + else if (cpl_property_get_type_(psrc) == + cpl_property_get_type_(pdest)) { + cpl_property_update(pdest, psrc); + } + else { + return cpl_error_set_message_(CPL_ERROR_TYPE_MISMATCH, "%s", name); } - - cpl_property_set_comment(p, cpl_property_get_comment(_p)); - } return CPL_ERROR_NONE; - } @@ -7093,28 +6302,12 @@ */ cpl_error_code -cpl_propertylist_copy_property_regexp(cpl_propertylist *self, - const cpl_propertylist *other, - const char *regexp, - int invert) -{ - - - cxint status; - - cxsize i; - cxsize count = 0; - - cx_deque_const_iterator first, last; - - typedef struct _property_pair_ { - cpl_property *s; - cpl_property *t; - } property_pair; - - property_pair *pairs = NULL; - - cpl_regexp filter; +cpl_propertylist_copy_property_regexp(cpl_propertylist *self, + const cpl_propertylist *other, + const char *regexp, + int invert) +{ + cxsize count; if (self == NULL || other == NULL || regexp == NULL) { @@ -7125,155 +6318,31 @@ return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); } - status = regcomp(&filter.re, regexp, REG_EXTENDED | REG_NOSUB); - if (status) { - (void)cpl_error_set_regex(CPL_ERROR_ILLEGAL_INPUT, status, - &filter.re, "regexp='%s', invert=%d", - regexp, invert); - return CPL_ERROR_ILLEGAL_INPUT; - } - - filter.invert = invert == 0 ? FALSE : TRUE; - - count = cx_deque_size(other->properties); - if (count == 0) { - regfree(&filter.re); - return CPL_ERROR_NONE; - } - - pairs = cx_malloc(count * sizeof(property_pair)); - cx_assert(pairs != NULL); - - count = 0; - - - first = cx_deque_begin(other->properties); - last = cx_deque_end(other->properties); - - while (first != last) { - - cpl_property *p = cx_deque_get(other->properties, first); - - - if (_cpl_propertylist_compare_regexp(p, &filter) == TRUE) { - - const cxchar *name = cpl_property_get_name(p); - /* name size, i.e. including terminating null byte */ - const size_t namelen= cpl_property_get_size_name(p); - cpl_property *_p = NULL; - cx_deque_const_iterator pos; - const cpl_cstr * cxstr; - - cxstr = CXSTR(name, namelen); - - pos = _cpl_propertylist_find_(self, cxstr); - - if (pos != cx_deque_end(self->properties)) { - - _p = cx_deque_get(self->properties, pos); - - if (cpl_property_get_type(p) != cpl_property_get_type(_p)) { - - regfree(&filter.re); - - cx_free(pairs); - pairs = NULL; - - return cpl_error_set_(CPL_ERROR_TYPE_MISMATCH); - - } - - } - - pairs[count].s = p; - pairs[count].t = _p; - ++count; - - } - - first = cx_deque_next(other->properties, first); - - } - - regfree(&filter.re); - - - for (i = 0; i < count; i++) { - - if (pairs[i].t == NULL) { + if (count > 0) { + cpl_regexp filter; - cpl_property *p = cpl_property_duplicate(pairs[i].s); - cx_deque_push_back(self->properties, p); + cpl_error_code code; + const int status = + regcomp(&filter.re, regexp, REG_EXTENDED | REG_NOSUB); + if (status) { + return cpl_error_set_regex(CPL_ERROR_ILLEGAL_INPUT, status, + &filter.re, "regexp='%s', invert=%d", + regexp, invert); } - else { - - switch (cpl_property_get_type(pairs[i].s)) { - - case CPL_TYPE_CHAR: - cpl_property_set_char(pairs[i].t, - cpl_property_get_char(pairs[i].s)); - break; - - case CPL_TYPE_BOOL: - cpl_property_set_bool(pairs[i].t, - cpl_property_get_bool(pairs[i].s)); - break; - - case CPL_TYPE_INT: - cpl_property_set_int(pairs[i].t, - cpl_property_get_int(pairs[i].s)); - break; - - case CPL_TYPE_LONG: - cpl_property_set_long(pairs[i].t, - cpl_property_get_long(pairs[i].s)); - break; - - case CPL_TYPE_FLOAT: - cpl_property_set_float(pairs[i].t, - cpl_property_get_float(pairs[i].s)); - break; - - case CPL_TYPE_DOUBLE: - cpl_property_set_double(pairs[i].t, - cpl_property_get_double(pairs[i].s)); - break; - - case CPL_TYPE_STRING: - cpl_property_set_string(pairs[i].t, - cpl_property_get_string(pairs[i].s)); - break; - - case CPL_TYPE_FLOAT_COMPLEX: - cpl_property_set_float_complex(pairs[i].t, - cpl_property_get_float_complex(pairs[i].s)); - break; - - case CPL_TYPE_DOUBLE_COMPLEX: - cpl_property_set_double_complex(pairs[i].t, - cpl_property_get_double_complex(pairs[i].s)); - break; - default: - /* This point should never be reached */ - cx_free(pairs); - return cpl_error_set_(CPL_ERROR_UNSUPPORTED_MODE); - break; - } + filter.invert = invert == 0 ? FALSE : TRUE; - cpl_property_set_comment(pairs[i].t, - cpl_property_get_comment(pairs[i].s)); - } + code = cpl_propertylist_copy_filter_(self, other, NULL, &filter); + regfree(&filter.re); + if (code) + return cpl_error_set_where_(); } - cx_free(pairs); - return CPL_ERROR_NONE; - } @@ -7313,12 +6382,9 @@ cpl_propertylist_sort(cpl_propertylist* self, int (*compare)(const void*, const void*))*/ cpl_error_code -cpl_propertylist_sort(cpl_propertylist* self, +cpl_propertylist_sort(cpl_propertylist *self, cpl_propertylist_compare_func compare) { - - - cx_compare_func _compare = (cx_compare_func)compare; @@ -7329,7 +6395,6 @@ cx_deque_sort(self->properties, _compare); return CPL_ERROR_NONE; - } @@ -7398,7 +6463,6 @@ cpl_propertylist * cpl_propertylist_load(const char *name, cpl_size position) { - cxint status = 0; cpl_propertylist *self; @@ -7408,7 +6472,6 @@ fitsfile *file = NULL; - if (name == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return NULL; @@ -7420,35 +6483,35 @@ } if (cpl_io_fits_open_diskfile(&file, name, READONLY, &status)) { - - (void)cpl_error_set_fits(status == FILE_NOT_OPENED ? - CPL_ERROR_FILE_IO : CPL_ERROR_BAD_FILE_FORMAT, - status, fits_open_diskfile, "filename='%s', " - "position=%d", name, (cxint)position); + (void)cpl_error_set_fits(status == FILE_NOT_OPENED + ? CPL_ERROR_FILE_IO + : CPL_ERROR_BAD_FILE_FORMAT, + status, fits_open_diskfile, + "filename='%s', " + "position=%d", + name, (cxint)position); return NULL; - } self = cpl_propertylist_new(); code = cpl_propertylist_fill_from_fits_locale(self, file, (cxint)position, - NULL, NULL); + NULL, NULL); if (cpl_io_fits_close_file(file, &status)) { - code = cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, status, - fits_close_file, "filename='%s', " - "position=%d", name, (cxint)position); - - } else if (code) { - + fits_close_file, + "filename='%s', " + "position=%d", + name, (cxint)position); + } + else if (code) { /* * Propagate error */ - cpl_error_set_message_(code, "Position %d in file: %s", - (int)position, name); - + cpl_error_set_message_(code, "Position %d in file: %s", (int)position, + name); } if (code) { @@ -7457,7 +6520,6 @@ } return self; - } @@ -7537,10 +6599,11 @@ */ cpl_propertylist * -cpl_propertylist_load_regexp(const char *name, cpl_size position, - const char *regexp, int invert) +cpl_propertylist_load_regexp(const char *name, + cpl_size position, + const char *regexp, + int invert) { - cxint status = 0; cpl_propertylist *self; @@ -7581,21 +6644,19 @@ status = regcomp(&filter.re, regexp, REG_EXTENDED | REG_NOSUB); if (status) { - - (void)cpl_error_set_regex(CPL_ERROR_ILLEGAL_INPUT, status, - &filter.re, "regexp='%s', invert=%d", - regexp, invert); + (void)cpl_error_set_regex(CPL_ERROR_ILLEGAL_INPUT, status, &filter.re, + "regexp='%s', invert=%d", regexp, invert); return NULL; - } filter.invert = invert == 0 ? FALSE : TRUE; if (cpl_io_fits_open_diskfile(&file, name, READONLY, &status)) { - - (void)cpl_error_set_fits(status == FILE_NOT_OPENED ? - CPL_ERROR_FILE_IO : CPL_ERROR_BAD_FILE_FORMAT, - status, fits_open_diskfile, "filename='%s', " + (void)cpl_error_set_fits(status == FILE_NOT_OPENED + ? CPL_ERROR_FILE_IO + : CPL_ERROR_BAD_FILE_FORMAT, + status, fits_open_diskfile, + "filename='%s', " "position=%d, regexp='%s'", name, (cxint)position, regexp); @@ -7604,32 +6665,28 @@ regfree(&filter.re); return NULL; - } self = cpl_propertylist_new(); code = cpl_propertylist_fill_from_fits_locale(self, file, (cxint)position, - _cpl_propertylist_filter_regexp, - &filter); + NULL, &filter); regfree(&filter.re); if (cpl_io_fits_close_file(file, &status)) { - code = cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, status, - fits_close_file, "filename='%s', position=" - "%d, regexp='%s'", name, (cxint)position, - regexp); - - } else if (code) { - + fits_close_file, + "filename='%s', position=" + "%d, regexp='%s'", + name, (cxint)position, regexp); + } + else if (code) { /* * Propagate error */ cpl_error_set_message_(code, "Position %d in file: %s. Invert=%d of %s", (int)position, name, invert, regexp); - } if (code) { @@ -7638,10 +6695,213 @@ } return self; +} + + +/** + * @internal + * @brief + * Copy the named properties from one list to another + * + * @param self The destination propertylist, to append to + * @param other The source propertylist, to copy from + * @param nstart Number of start keys to select against + * @param startkey Keys starting with this name are loaded + * @param nexact Number of exact keys to select against + * @param exactkey Keys with this exact name are loaded + * @param invert Flag inverting the sense of matching property names. + * + * @return CPL_ERROR_NONE, or the relevant CPL error on failure + * + * @see cpl_propertylist_copy_property_regexp(() + * + * @note No input validation in this internal function + * + * If a property is to be copied is already present in the destination, + * then its type there must match that of the source. If this is not + * the case, an error is set and no modifications are made to the input. + * + */ +cpl_error_code +cpl_propertylist_copy_name_(cpl_propertylist *self, + const cpl_propertylist *other, + cpl_size nstart, + const cpl_cstr *startkey[], + cpl_size nexact, + const cpl_cstr *exactkey[], + int invert) +{ + cpl_size nsize = cx_deque_size(other->properties); + + if (nsize > 0 && (nstart > 0 || nexact > 0 || invert)) { + /* + * Set up the filter + */ + + cpl_memcmp filter; + + filter.nstart = nstart; + filter.startkey = startkey; + filter.nexact = nexact; + filter.exactkey = exactkey; + filter.invert = invert; + + if (cpl_propertylist_copy_filter_(self, other, &filter, NULL)) { + return cpl_error_set_where_(); + } + } + + return CPL_ERROR_NONE; +} + +/** + * @internal + * @brief + * Erase the named properties from the list + * + * @param self The propertylist, to erase from + * @param nstart Number of start keys to select against + * @param startkey Keys starting with this name are loaded + * @param nexact Number of exact keys to select against + * @param exactkey Keys with this exact name are loaded + * @param invert Flag inverting the sense of matching property names. + * + * @return CPL_ERROR_NONE, or the relevant CPL error on failure + * + * @see cpl_propertylist_erase_regexp(() + * + * @note No input validation in this internal function + * + */ + +cpl_error_code +cpl_propertylist_erase_name_(cpl_propertylist *self, + cpl_size nstart, + const cpl_cstr *startkey[], + cpl_size nexact, + const cpl_cstr *exactkey[], + int invert) +{ + if (nstart > 0 || nexact > 0 || invert) { + /* + * Set up the filter + */ + + cpl_memcmp filter; + + filter.nstart = nstart; + filter.startkey = startkey; + filter.nexact = nexact; + filter.exactkey = exactkey; + filter.invert = invert; + + if (cpl_propertylist_erase_filter(self, &filter, NULL)) { + return cpl_error_set_where_(); + } + } + + return CPL_ERROR_NONE; } +/** + * @internal + * @brief + * Copy the named properties from one list to another + * + * @param self The destination propertylist, to append to + * @param other The source propertylist, to copy from + * @param names An optional list of names w. invert flag for filtering cards + * @param regexp An optional regexp w. invert flag for filtering cards + * + * @return CPL_ERROR_NONE, or the relevant CPL error on failure + * + * @see cpl_propertylist_copy_property_regexp(() + * + * @note No input validation in this internal function + * + * If a property is to be copied is already present in the destination, + * then its type there must match that of the source. If this is not + * the case, an error is set and no modifications are made to the input. + * + */ + +static cpl_error_code +cpl_propertylist_copy_filter_(cpl_propertylist *self, + const cpl_propertylist *other, + const cpl_memcmp *names, + const cpl_regexp *regexp) +{ + const cpl_size nsize = cx_deque_size(other->properties); + + if (nsize > 0) { + cpl_size ncopy = 0; + + typedef struct _property_pair_ + { + cpl_property *s; + const cpl_property *o; + } property_pair; + + property_pair *pairs = cx_malloc(nsize * sizeof(property_pair)); + + cx_deque_iterator first = cx_deque_begin(other->properties); + cx_deque_iterator last = cx_deque_end(other->properties); + + while (first != last) { + const cpl_property *p = cx_deque_get(other->properties, first); + + if ((names != NULL && + cpl_property_check_memcmp(p, names) == TRUE) || + (regexp != NULL && + cpl_property_check_regexp(p, regexp) == TRUE)) { + /* Property is to be copied */ + const cxchar *name = cpl_property_get_name_(p); + const cxsize namelen = cpl_property_get_size_name(p); + const cpl_cstr *name_ = CXSTR(name, namelen); + + cpl_property *_p = cpl_propertylist_find(self, name_); + + cx_assert(ncopy < nsize); + + if (_p == NULL) { + /* Property is new, not an update to self */ + pairs[ncopy].s = NULL; + } + else if (cpl_property_get_type_(p) == + cpl_property_get_type_(_p)) { + pairs[ncopy].s = _p; + } + else { + cx_free(pairs); + + return cpl_error_set_message_(CPL_ERROR_TYPE_MISMATCH, + "name: %s", name); + } + pairs[ncopy].o = p; + ++ncopy; + } + + first = cx_deque_next(other->properties, first); + } + + for (cpl_size icopy = 0; icopy < ncopy; icopy++) { + if (pairs[icopy].s != NULL) + + cpl_property_update(pairs[icopy].s, pairs[icopy].o); + + else + + cx_deque_push_back(self->properties, + cpl_property_duplicate(pairs[icopy].o)); + } + + cx_free(pairs); + } + + return CPL_ERROR_NONE; +} /** @@ -7671,38 +6931,38 @@ */ cpl_propertylist * -cpl_propertylist_load_name_(const char * name, - cpl_size position, - cpl_size nstart, - const cpl_cstr * startkey[], - cpl_size nexact, - const cpl_cstr * exactkey[], - int invert) +cpl_propertylist_load_name_(const char *name, + cpl_size position, + cpl_size nstart, + const cpl_cstr *startkey[], + cpl_size nexact, + const cpl_cstr *exactkey[], + int invert) { - cxint status = 0; cpl_propertylist *self; - cpl_memcmp_ filter; + cpl_memcmp filter; cpl_error_code code; fitsfile *file = NULL; if (cpl_io_fits_open_diskfile(&file, name, READONLY, &status)) { - - (void)cpl_error_set_fits(status == FILE_NOT_OPENED ? - CPL_ERROR_FILE_IO : CPL_ERROR_BAD_FILE_FORMAT, - status, fits_open_diskfile, "filename='%s', " + (void)cpl_error_set_fits(status == FILE_NOT_OPENED + ? CPL_ERROR_FILE_IO + : CPL_ERROR_BAD_FILE_FORMAT, + status, fits_open_diskfile, + "filename='%s', " "position=%d, nstartkey=%d, nexactkey=%d", - name, (cxint)position, (int)nstart, (int)nexact); + name, (cxint)position, (int)nstart, + (int)nexact); status = 0; cpl_io_fits_close_file(file, &status); return NULL; - } self = cpl_propertylist_new(); @@ -7711,32 +6971,30 @@ * Set up the filter */ - filter.nstart = nstart; + filter.nstart = nstart; filter.startkey = startkey; - filter.nexact = nexact; + filter.nexact = nexact; filter.exactkey = exactkey; - filter.invert = invert; + filter.invert = invert; code = cpl_propertylist_fill_from_fits_locale(self, file, (cxint)position, - _cpl_propertylist_filter_memcmp, - &filter); + &filter, NULL); if (cpl_io_fits_close_file(file, &status)) { - - code = cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, status, - fits_close_file, "filename='%s', position=" - "%d, nstartkey=%d, nexactkey=%d", name, - (cxint)position, (int)nstart, (int)nexact); - - } else if (code) { - + code = + cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, status, + fits_close_file, + "filename='%s', position=" + "%d, nstartkey=%d, nexactkey=%d", + name, (cxint)position, (int)nstart, (int)nexact); + } + else if (code) { /* * Propagate error */ cpl_error_set_message_(code, "Position %d in file: %s. Invert=%d", (int)position, name, invert); - } if (code) { @@ -7745,7 +7003,6 @@ } return self; - } /** @@ -7756,6 +7013,7 @@ * @param file The FITS file to write to. * @param properties The property list to write to the file. * @param to_rm The regular expression used to filter properties + * @param update Whether to update or overwrite an existing extension * * @return * The function returns @c CPL_ERROR_NONE on success, or an appropriate @@ -7770,9 +7028,9 @@ cpl_error_code cpl_propertylist_to_fitsfile(fitsfile *file, const cpl_propertylist *self, - const char *to_rm) + const char *to_rm, + cpl_boolean update) { - cpl_regexp filter; cpl_error_code error; @@ -7786,11 +7044,10 @@ } if (to_rm != NULL) { - /* A regular expression must be applied */ - const cxint rstatus = regcomp(&filter.re, to_rm, - REG_EXTENDED | REG_NOSUB); + const cxint rstatus = + regcomp(&filter.re, to_rm, REG_EXTENDED | REG_NOSUB); if (rstatus) { return cpl_error_set_regex(CPL_ERROR_ILLEGAL_INPUT, rstatus, @@ -7798,18 +7055,15 @@ } filter.invert = 0; - } error = cpl_propertylist_to_fitsfile_locale(file, self, - _cpl_propertylist_filter_regexp, - to_rm ? &filter : NULL); + to_rm ? &filter : NULL, update); if (to_rm != NULL) { regfree(&filter.re); } return error ? cpl_error_set_where_() : CPL_ERROR_NONE; - } @@ -7838,7 +7092,6 @@ cpl_propertylist * cpl_propertylist_from_fitsfile(fitsfile *file) { - cpl_propertylist *self; cpl_ensure(file != NULL, CPL_ERROR_NULL_INPUT, NULL); @@ -7852,7 +7105,6 @@ } return self; - } @@ -7883,11 +7135,10 @@ * @em name, then the first one found will be returned. */ -const cpl_property * -cpl_propertylist_get_property_const(const cpl_propertylist *self, const char *name) +inline const cpl_property * +cpl_propertylist_get_property_const(const cpl_propertylist *self, + const char *name) { - cx_deque_iterator pos; - if (self == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return NULL; @@ -7898,13 +7149,7 @@ return NULL; } - pos = _cpl_propertylist_find(self, name); - - if (pos == cx_deque_end(self->properties)) - return NULL; - - return cx_deque_get(self->properties, pos); - + return cpl_propertylist_find_(self, name); } @@ -7938,19 +7183,17 @@ cpl_property * cpl_propertylist_get_property(cpl_propertylist *self, const char *name) { + if (self == NULL) { + cpl_error_set_(CPL_ERROR_NULL_INPUT); + return NULL; + } - cpl_errorstate prestate = cpl_errorstate_get(); - cpl_property *property; - - CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); - property = (cpl_property *)cpl_propertylist_get_property_const(self, name); - CPL_DIAG_PRAGMA_POP; - - if (!cpl_errorstate_is_equal(prestate)) - (void)cpl_error_set_where_(); - - return property; + if (name == NULL) { + cpl_error_set_(CPL_ERROR_NULL_INPUT); + return NULL; + } + return cpl_propertylist_find_(self, name); } @@ -7996,14 +7239,10 @@ */ cpl_error_code -cpl_propertylist_save(const cpl_propertylist *self, const char *filename, +cpl_propertylist_save(const cpl_propertylist *self, + const char *filename, unsigned mode) { - - const cxchar *badkeys = (mode & CPL_IO_EXTEND) ? - CPL_FITS_BADKEYS_EXT "|" CPL_FITS_COMPRKEYS : - CPL_FITS_BADKEYS_PRIM "|" CPL_FITS_COMPRKEYS; - cxint error = 0; cpl_error_code code = CPL_ERROR_NONE; @@ -8011,13 +7250,12 @@ fitsfile *fptr; - /* * Check entries */ cpl_ensure_code(filename, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(mode == CPL_IO_CREATE || mode == CPL_IO_EXTEND, + cpl_ensure_code(mode == CPL_IO_CREATE || mode == CPL_IO_EXTEND, CPL_ERROR_ILLEGAL_INPUT); @@ -8028,10 +7266,11 @@ /* Open the file */ if (cpl_io_fits_open_diskfile(&fptr, filename, READWRITE, &error)) { return cpl_error_set_fits(CPL_ERROR_FILE_IO, error, - fits_open_diskfile, "filename='%s', " - "mode=%u", filename, mode); + fits_open_diskfile, + "filename='%s', " + "mode=%u", + filename, mode); } - } else { /* Main HDU */ @@ -8044,41 +7283,38 @@ if (error != 0) { return cpl_error_set_fits(CPL_ERROR_FILE_IO, error, - fits_create_file, "filename='%s', " - "mode=%u", filename, mode); + fits_create_file, + "filename='%s', " + "mode=%u", + filename, mode); } - } /* Create empty header */ if (fits_create_img(fptr, BYTE_IMG, 0, NULL, &error)) { - cxint error2 = 0; cpl_io_fits_close_file(fptr, &error2); return cpl_error_set_fits(CPL_ERROR_FILE_IO, error, fits_create_img, "filename='%s', mode=%u", filename, mode); - } /* Add DATE */ if (mode != CPL_IO_EXTEND && fits_write_date(fptr, &error)) { - cxint error2 = 0; cpl_io_fits_close_file(fptr, &error2); return cpl_error_set_fits(CPL_ERROR_FILE_IO, error, fits_write_date, "filename='%s', mode=%u", filename, mode); - } /* Add the property list */ - if (cpl_fits_add_properties(fptr, self, badkeys)) { + if (cpl_fits_add_properties(fptr, self, mode, CPL_FALSE)) { code = cpl_error_set_where_(); } @@ -8090,7 +7326,6 @@ } return code; - } @@ -8108,9 +7343,9 @@ * The function used for printing is the standard C @c fprintf(). */ -void cpl_propertylist_dump(const cpl_propertylist *self, FILE *stream) +void +cpl_propertylist_dump(const cpl_propertylist *self, FILE *stream) { - cxchar c = '\0'; cpl_size i = 0; @@ -8133,7 +7368,7 @@ const cxchar *name = cpl_property_get_name(p); const cxchar *comment = cpl_property_get_comment(p); cpl_size size = cpl_property_get_size(p); - cpl_type type = cpl_property_get_type(p); + cpl_type type = cpl_property_get_type_(p); const cxchar *typestr = cpl_type_get_name(type); fprintf(stream, "Property at address %p\n", (cxcptr)p); @@ -8145,75 +7380,72 @@ switch (type) { - case CPL_TYPE_CHAR: - c = cpl_property_get_char(p); - if (!c) - fprintf(stream, "''"); - else - fprintf(stream, "'%c'", c); - break; - - case CPL_TYPE_BOOL: - fprintf(stream, "%d", cpl_property_get_bool(p)); - break; + case CPL_TYPE_CHAR: + c = cpl_property_get_char(p); + if (!c) + fprintf(stream, "''"); + else + fprintf(stream, "'%c'", c); + break; - case CPL_TYPE_INT: - fprintf(stream, "%d", cpl_property_get_int(p)); - break; + case CPL_TYPE_BOOL: + fprintf(stream, "%d", cpl_property_get_bool(p)); + break; - case CPL_TYPE_LONG: - fprintf(stream, "%ld", cpl_property_get_long(p)); - break; + case CPL_TYPE_INT: + fprintf(stream, "%d", cpl_property_get_int(p)); + break; - case CPL_TYPE_LONG_LONG: - fprintf(stream, "%lld", cpl_property_get_long_long(p)); - break; + case CPL_TYPE_LONG: + fprintf(stream, "%ld", cpl_property_get_long(p)); + break; - case CPL_TYPE_FLOAT: - fprintf(stream, "%.7g", cpl_property_get_float(p)); - break; + case CPL_TYPE_LONG_LONG: + fprintf(stream, "%lld", cpl_property_get_long_long(p)); + break; - case CPL_TYPE_DOUBLE: - fprintf(stream, "%.15g", cpl_property_get_double(p)); - break; + case CPL_TYPE_FLOAT: + fprintf(stream, "%.7g", cpl_property_get_float(p)); + break; - case CPL_TYPE_STRING: - fprintf(stream, "'%s'", cpl_property_get_string(p)); - break; + case CPL_TYPE_DOUBLE: + fprintf(stream, "%.15g", cpl_property_get_double(p)); + break; - case CPL_TYPE_FLOAT_COMPLEX: { - /* Print with FITS header format */ - const float complex z = cpl_property_get_float_complex(p); - fprintf(stream, "(%.7g,%.7g)", crealf(z), cimagf(z)); - break; - } - case CPL_TYPE_DOUBLE_COMPLEX: { - /* Print with FITS header format */ - const double complex z = cpl_property_get_double_complex(p); - fprintf(stream, "(%.15g,%.15g)", creal(z), cimag(z)); - break; - } - default: - fprintf(stream, "unknown."); - break; + case CPL_TYPE_STRING: + fprintf(stream, "'%s'", cpl_property_get_string(p)); + break; + case CPL_TYPE_FLOAT_COMPLEX: { + /* Print with FITS header format */ + const float complex z = cpl_property_get_float_complex(p); + fprintf(stream, "(%.7g,%.7g)", crealf(z), cimagf(z)); + break; + } + case CPL_TYPE_DOUBLE_COMPLEX: { + /* Print with FITS header format */ + const double complex z = cpl_property_get_double_complex(p); + fprintf(stream, "(%.15g,%.15g)", creal(z), cimag(z)); + break; + } + default: + fprintf(stream, "unknown."); + break; } fprintf(stream, "\n"); - } return; - } /** * @brief - * Append a property to a property list + * Append a duplicate of a property to a property list * * @param self Property list to append to - * @param property The property to append + * @param property The property to duplicate and append * * @return * The function returns @c CPL_ERROR_NONE on success or a CPL error @@ -8239,8 +7471,7 @@ cpl_propertylist_append_property(cpl_propertylist *self, const cpl_property *property) { - - if((self == NULL) || (property == NULL)){ + if ((self == NULL) || (property == NULL)) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } @@ -8251,6 +7482,35 @@ /** + * @internal + * @brief + * Append a property to a property list + * + * @param self Property list to append to + * @param property The property to append + * + * @note This internal function has no error checking + * + * @return + * The function returns @c CPL_ERROR_NONE on success or a CPL error + * code otherwise. + * + * @see cpl_propertylist_append_property() + * + * This function appends a property to the end of a property list. + * It will not check if the property already exists. + */ + +inline cpl_error_code +cpl_propertylist_set_property(cpl_propertylist *self, cpl_property *property) +{ + cx_deque_push_back(self->properties, property); + + return CPL_ERROR_NONE; +} + + +/** * @brief * Prepend a property to a property list * @@ -8281,8 +7541,7 @@ cpl_propertylist_prepend_property(cpl_propertylist *self, const cpl_property *property) { - - if((self == NULL) || (property == NULL)){ + if ((self == NULL) || (property == NULL)) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } @@ -8326,7 +7585,6 @@ const char *here, const cpl_property *property) { - cx_deque_iterator pos; if (self == NULL || here == NULL || property == NULL) { @@ -8337,7 +7595,7 @@ * Find the position where property should be inserted. */ - pos = _cpl_propertylist_find(self, here); + pos = cpl_propertylist_find_pos_(self, here); if (pos == cx_deque_end(self->properties)) { return cpl_error_set_(CPL_ERROR_UNSPECIFIED); @@ -8352,7 +7610,6 @@ return CPL_ERROR_NONE; - } @@ -8386,10 +7643,9 @@ cpl_error_code cpl_propertylist_insert_after_property(cpl_propertylist *self, - const char *after, - const cpl_property *property) + const char *after, + const cpl_property *property) { - cx_deque_iterator pos; if (self == NULL || after == NULL || property == NULL) { @@ -8399,7 +7655,7 @@ /* * Find the position where property should be inserted. */ - pos = _cpl_propertylist_find(self, after); + pos = cpl_propertylist_find_pos_(self, after); if (pos == cx_deque_end(self->properties)) { return cpl_error_set_(CPL_ERROR_UNSPECIFIED); @@ -8417,65 +7673,92 @@ return CPL_ERROR_NONE; - } + /*----------------------------------------------------------------------------*/ /** @internal @brief Generate a valid FITS header for saving functions @param self The fitsfile to modify @param to_add The set of keywords to add to the minimal header - @param to_rm The set of keys to remove + @param mode The desired output options + @param update Whether to update or overwrite an existing extension @return 1 newly allocated valid header The passed file should contain a minimal header. - The propertylist is sorted (DICB) and added after the miniaml header. + The propertylist is sorted (DICB) and added after the minimal header. + + If the mode has the internal CPL_IO_WCS bit set, no WCS keys are added Possible #_cpl_error_code_ set in this function: - CPL_ERROR_NULL_INPUT if self is NULL - CPL_ERROR_ILLEGAL_INPUT if the propertylist cannot be written */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_fits_add_properties(fitsfile * self, - const cpl_propertylist * to_add, - const char * to_rm) +cpl_error_code +cpl_fits_add_properties(fitsfile *self, + const cpl_propertylist *to_add, + unsigned mode, + cpl_boolean update) { cpl_error_code error = CPL_ERROR_NONE; if (to_add != NULL) { - cpl_propertylist * out; - - /* Failure here would indicate a bug in CPL */ - cpl_ensure_code(self, CPL_ERROR_NULL_INPUT); - - if (to_rm != NULL) { - /* Copy all but the black-listed properties */ - out = cpl_propertylist_new(); - if (cpl_propertylist_copy_property_regexp(out, to_add, to_rm, 1)) { - error = cpl_error_set_where_(); - } - } else { - out = cpl_propertylist_duplicate(to_add); - } - - if (!error) { - const cpl_size ncards = cpl_propertylist_get_size(out); + cpl_propertylist *out; + const cpl_cstr *exactkeysp[] = { CPL_FITS_EXACT_PRIM }; + const cpl_cstr *exactkeyse[] = { CPL_FITS_EXACT_EXT }; + const cpl_cstr **exactkeys = + (mode & CPL_IO_EXTEND) ? exactkeyse : exactkeysp; + + const int nexactkeysp = (int)CX_N_ELEMENTS(exactkeysp); + const int nexactkeyse = (int)CX_N_ELEMENTS(exactkeyse); + const int nexactkeys = + (mode & CPL_IO_EXTEND) ? nexactkeyse : nexactkeysp; + + const cpl_cstr *startkeysp[] = { CPL_FITS_START_PRIM }; + const cpl_cstr *startkeyse[] = { CPL_FITS_START_EXT }; + const cpl_cstr **startkeys = + (mode & CPL_IO_EXTEND) ? startkeyse : startkeysp; + + const int nstartkeysp = (int)CX_N_ELEMENTS(startkeysp); + const int nstartkeyse = (int)CX_N_ELEMENTS(startkeyse); + const int nstartkeys = + (mode & CPL_IO_EXTEND) ? nstartkeyse : nstartkeysp; + + /* Copy all but the black-listed properties */ + out = cpl_propertylist_new(); + if (cpl_propertylist_copy_name_(out, to_add, nstartkeys, startkeys, + nexactkeys, exactkeys, 1)) { + error = cpl_error_set_where_(); + } + else { /* Before sorting, set the DICB type sort key, reducing the complexity of that to O(n) */ - for (cpl_size i = 0; i < ncards; i++) { - cpl_property* myprop = cpl_propertylist_get(out, i); - cpl_property_set_sort_dicb(myprop); + + cx_deque_iterator first = cx_deque_begin(out->properties); + + while (first != cx_deque_end(out->properties)) { + cpl_property *p = cx_deque_get(out->properties, first); + + cpl_property_set_sortkey_dicb(p); + + if ((mode & CPL_IO_WCS) && /* Remove all WCS related keys */ + cpl_property_get_sortkey_(p) == CPL_DICB_WCS) { + cx_deque_erase(out->properties, first, + (cx_free_func)cpl_property_delete); + } + else { + first = cx_deque_next(out->properties, first); + } } + /* Sort and write the propertylist to the file */ if (cpl_propertylist_sort(out, cpl_property_compare_sortkey) || - cpl_propertylist_to_fitsfile(self, out, NULL)) { - + cpl_propertylist_to_fitsfile(self, out, NULL, update)) { error = cpl_error_set_where_(); - } - } cpl_propertylist_delete(out); } @@ -8485,862 +7768,130 @@ /**@}*/ -/*----------------------------------------------------------------------------*/ -/** - @internal - @brief Get the length of the key of a FITS card - @param card A FITS card (80 bytes or more) may not have null terminator - @param plen The length, zero for a key-less card, undefined on error - @param piparsed The index to the last parsed character - @return On succes, points to start of key (skips "HIERARCH "), else NULL - @note (Almost) no input validation in this internal function - @see fits_get_keyname(), ffgknm() - - On success *piparsed is the index to the last parsed character, for a - ESO HIERARCH card *piparsed is the index of the value indicator ('='), for a - non ESO HIERARCH card *piparsed is 8 (whether or not that byte has a - value indicator). - - */ -/*----------------------------------------------------------------------------*/ -inline static -const char * cpl_fits_get_key(const char * card, - int * plen, - int * piparsed) -{ - const char * kstart; - - if (!memcmp(card, "HIERARCH ", 9)) { - /* A malformed card could be missing its value indicator (and could - instead have an '=' sign in its comment) or the key could be invalid. - The purpose of this library is not to process invalid FITS data, so - in such cases the card may be dropped silently or a property with an - unusual key may be created. */ - const char * eqpos = memchr(card + 9, '=', FITS_CARD_LEN - 9); - - if (eqpos) { - - kstart = card + 9; - - *piparsed = (int)(eqpos - card); - - /* If available memrchr() would not help much here, unlikely - to find a whole (properly aligned) word of ' ' */ - do { - eqpos--; - } while (*eqpos == ' '); - - if (eqpos >= kstart) { - *plen = (int)(1 + eqpos - kstart); - } else { - /* This is not a valid ESO HIERARCH card */ - kstart = NULL; - } - } else { - /* This is not a valid ESO HIERARCH card */ - kstart = NULL; - } - } else { - /* Did CFITSIO nuke the trailing blanks ? */ - const char * nullbyte = memchr(card, '\0', 8); - - if (nullbyte != NULL) { - const char * spcpos = memchr(card, ' ', nullbyte - card); - *plen = (int)((spcpos ? spcpos : nullbyte) - card); - *piparsed = FITS_CARD_LEN; - - } else { - const char * spcpos = memchr(card, ' ', 8); - - *plen = spcpos ? (int)(spcpos - card) : 8; - *piparsed = 8; - } - - kstart = card; - } - - return kstart; -} - - -/*----------------------------------------------------------------------------*/ /** - @internal - @brief Get a numerical value from a FITS card - @param card A FITS card (80 bytes), must have null terminator - @param iparsed The value from cpl_fits_get_key() or just before the number - @param plval On positive return, *plval is the integer, unless NULL - @param pdval On negative return, *pdval is the double - @param pjparsed The index to the last parsed character - @return Positive for int, negative for floating point, zero for NaN (error) - @note (Almost) no input validation in this internal function! - @see cpl_fits_get_key() - - On error, *pjparsed is undefined. - - Parsing a string for a number is non-trivial, so use sscanf(). - - If plval is non-NULL, the resulting number is either integer or float, - as indicatd by the return value. - - If the string has a decimal point or an exponent part, the resulting - number is a float even if its fractional part is zero. - - If the string has neither but the conversion to a signed long long int - causes an overflow, the resulting number is deemed float. - + * @internal + * @brief + * Check whether the card name matches the regular expression + * + * @param key The card name to check + * @param data The regular expression with invert flag + * @return TRUE iff the name matches else false (inverted if the flag is set) + * @see cpl_cstr_key_memcmp, cpl_property_check_regexp + * @note This function is an order of magnitude slower than the memcmp version + * */ -/*----------------------------------------------------------------------------*/ -inline static -int cpl_fits_get_number(const char * card, - int iparsed, - long long * plval, - double * pdval, - int * pjparsed) -{ - /* The FITS standard (4.2.4) allows for a floating-point constant with a 'D' - starting the exponent part. This format cannot by handled by sscanf(). - (Coincidentally, in FORTRAN a double precision constant uses a 'D') */ - - cpl_boolean is_dexp = CPL_FALSE; - - cx_assert(FITS_CARD_LEN < FLEN_VALUE + iparsed); - cx_assert(iparsed < FITS_CARD_LEN); - - if (plval != NULL) { - errno = 0; /* Integer parsing can result in overflow, ERANGE */ - - if (sscanf(card + iparsed, "%lld%n", plval, pjparsed) > 0 && - errno == 0 && *pjparsed > 0 && - card[iparsed + *pjparsed] != '.' && - card[iparsed + *pjparsed] != 'E') { - - if (card[iparsed + *pjparsed] != 'D') { - *pjparsed += iparsed; - return 1; /* Done: It is an integer fitting a long long */ - } - - is_dexp = CPL_TRUE; - } - } - - if (!is_dexp && (sscanf(card + iparsed, "%lf%n", pdval, pjparsed) < 1 || - *pjparsed < 1)) return 0; /* NaN */ - - /* The card has a number and it is a floating point - (or too large to fit a long long, so we use a double) */ - -#ifdef CPL_PROPERTYLIST_DEBUG - cpl_msg_warning(cpl_func, "FITSSSCAN(%d:%d): %g (%c) %s", iparsed, - *pjparsed, *pdval, card[iparsed], card + iparsed); -#endif - - if (card[iparsed + *pjparsed] == 'D') { - /* Deal with the FORTRAN-format by replacing the 'D' - with an 'E' in a copy */ - - char numparse[FLEN_VALUE]; - - (void)memcpy(numparse, card + iparsed, FITS_CARD_LEN - iparsed); - - numparse[*pjparsed] = 'E'; - numparse[FITS_CARD_LEN - iparsed] = '\0'; - - if (sscanf(numparse, "%lf%n", pdval, pjparsed) < 1 || - *pjparsed < 3) return 0; /* Malformed exponent, 0D0 shortest OK */ - -#ifdef CPL_PROPERTYLIST_DEBUG - cpl_msg_warning(cpl_func, "FITSFTRAN(%d:%d): %g (%c) %s", iparsed, - *pjparsed, *pdval, card[iparsed], card + iparsed); - } else { - - cpl_msg_warning(cpl_func, "FITSFP(%d:%d): %g", iparsed, - *pjparsed, *pdval); -#endif +inline static cxbool +cpl_cstr_check_regexp(const cpl_cstr *key, cxcptr data) +{ + const char *key_ = cx_string_get_(key); + const cpl_regexp *data_ = (const cpl_regexp *)data; - } + if (regexec(&data_->re, key_, 0, NULL, 0) != REG_NOMATCH) /* Match */ + return data_->invert == TRUE ? FALSE : TRUE; - *pjparsed += iparsed; + /* No match */ - return -1; + return data_->invert == TRUE ? TRUE : FALSE; } -/*----------------------------------------------------------------------------*/ /** - @internal - @brief Get the parsed value and the comment location of a FITS card - @param pparseval On succes, the parsed value and its type - @param card A FITS card (80 bytes), must have null terminator - @param iparsed The value from cpl_fits_get_key() - @param naxis Used to more efficiently find cards that must be float - @param keywlen The name w. length of the property, used w. naxis - @param pjparsed The index to the last parsed character (comment separator, /) - @return The FITS type code, or zero on error - @note (Almost) no input validation in this internal function! - @see fits_parse_value(), ffpsvc(), ffdtyp() - - The possible return values are thes FITS type codes: - 'C', 'L', 'F', 'I', 'X' - as well as - 'U' (undefined), 'N' (none) or 0 (unparsable value in card) - - If the card has no value indicator, everything after its expected location - is deemed a comment, per FITS standard sections 4.1.2.2 and 4.1.2.3. - - If the value is of type string, the enclosing quotes are left out. If the - string itself contains (FITS-encoded, per 4.2.1 1) quotes, each is converted. - If the string itself contains no quotes, the pointer to its value points - to the relevant byte in the input card, so that string value is only valid - while the card itself it. - - On error, *pjparsed is undefined. - + * @internal + * @brief + * Check whether the card name matches the provided names + * + * @param key The card name to check + * @param data The lists of name beginnings and exact names with invert flag + * @return TRUE iff the name matches else false (inverted if the flag is set) + * @see cpl_cstr_key_regexp, cpl_property_check_memcmp + * @note This function is an order of magnitude faster then the regexp version + * */ -/*----------------------------------------------------------------------------*/ -inline static -char cpl_fits_get_value(cpl_fits_value * pparseval, - const char * card, - int iparsed, - int naxis, - const cpl_cstr * keywlen, - int * pjparsed) -{ - if (card[iparsed] != '=' || cx_string_size_(keywlen) == 0 || - (cx_string_size_(keywlen) == 7 && - (!memcmp("COMMENT", cx_string_get_(keywlen), 7) || - !memcmp("HISTORY", cx_string_get_(keywlen), 7)))) { - /* Card is commentary, i.e. it has no value indicator or - it is a COMMENT/HISTORY or blank card, see FITS std. 4.4.2.4. - Everything after the key is a comment */ - - /* Did CFITSIO nuke the trailing blanks ? */ - const char * nullbyte = memchr(card, '\0', 8); - - pparseval->tcode = 'N'; - *pjparsed = nullbyte ? FITS_CARD_LEN : 8; - } else { - /* Value indicator is present */ - - /* - skip it and any leading spaces */ - do { - iparsed++; - } while (iparsed < FITS_CARD_LEN && card[iparsed] == ' '); - - if (iparsed < FITS_CARD_LEN && - card[iparsed] != 0) { /* Did CFITSIO nuke the trailing blanks ? */ - - /* card[iparsed] now points to the first value byte */ - - /* Assume failure */ - pparseval->nmemb = 0; - pparseval->tcode = 0; - - switch (card[iparsed]) { - case '\'': { /* character string starts with a quote */ - const char * nextquote; - int vallen = 0; /* The number of value characters */ - - /* - need to increase iparsed to point past current quote - when looking for the next one */ - iparsed++; - while ((nextquote = memchr(card + iparsed, '\'', - FITS_CARD_LEN - iparsed)) != NULL - /* We silently ignore the error where there is 1 byte - after the ending quote and before the end-of-record - and that last byte equals a quote */ - && nextquote + 1 < card + FITS_CARD_LEN - && nextquote[1] == '\'') { - - /* O''HARA -> O'HARA */ - - /* The parsed string differs from the FITS-encoded, - so we need to copy it (including the found quote) */ - (void)memcpy(pparseval->unquote + vallen, card + iparsed, - (int)(nextquote + 1 - card - iparsed)); - - vallen += (int)(nextquote + 1 - card - iparsed); - - /* iparsed must be updated to point to the 2nd quote */ - iparsed = 2 + nextquote - card; - } - - if (nextquote != NULL) { - /* Found the ending quote (none would be a format error) */ - pparseval->tcode = 'C'; - - if (vallen > 0) { - /* Wrote to decoded string buffer */ - pparseval->val.c = pparseval->unquote; - - /* Copy part of string following encoded quote */ - (void)memcpy(pparseval->unquote + vallen, card + iparsed, - (int)(nextquote - card - iparsed)); - } else { - /* Reference to original, quote-free string */ - pparseval->val.c = card + iparsed; - } - - vallen += (int)(nextquote - card - iparsed); - - /* FITS standard 4.2.1 1: - Given the example - "KEYWORD2= ' ' / empty string keyword" - and the statement - "the value of the KEYWORD2 is an empty string (nominally " - "a single space character because the first space in the " - " string is significant, but trailing spaces are not)." - a string consisting solely of spaces is deemed to be empty - */ - while (vallen > 0 && pparseval->val.c[vallen - 1] == ' ') { - vallen--; - } - - /* Update iparsed to point to first byte after value */ - iparsed = 1 + (int)(nextquote - card); - } - - pparseval->nmemb = vallen; - - break; - } - case 'T': - pparseval->val.l = 1; - pparseval->nmemb = 1; - pparseval->tcode = 'L'; /* logical True ('T' character) */ - /* Update iparsed to point to first byte after value */ - iparsed++; - break; - case 'F': - pparseval->val.l = 0; - pparseval->nmemb = 1; - pparseval->tcode = 'L'; /* logical: False ('F' character) */ - /* Update iparsed to point to first byte after value */ - iparsed++; - break; - case '(': { - double dval[2]; - const char dsep[2] = {',', ')'}; - int i; - - iparsed++; /* Skip '(' */ - for (i = 0; i < 2; i++) { - /* FITS std. 4.2.5: Integer allowed, but parse it as double - since that is all we can store */ - const int ntype = cpl_fits_get_number(card, iparsed, NULL, - dval + i, &iparsed); - - if (ntype != -1) break; - - /* FITS std. 4.2.5/6: Trailing blanks are allowed */ - while (iparsed < FITS_CARD_LEN && card[iparsed] == ' ') { - iparsed++; - } - if (!(iparsed < FITS_CARD_LEN) || - card[iparsed] != dsep[i]) break; - iparsed++; - } - - if (i < 2) { - pparseval->nmemb = 0; - pparseval->tcode = 0; - } else { - - pparseval->val.x = dval[0] + dval[1] * _Complex_I; - pparseval->nmemb = 1; - pparseval->tcode = 'X'; /* complex datatype "(1.2, -3.4)" */ - } - break; - } - case '/': /* Undefinded value - with a comment */ - pparseval->nmemb = 0; - pparseval->tcode = 'U'; - break; /* No value found, so do not advance iparsed */ - - default: { /* Numerical type */ - /* In determining whether it is int or float, we might as - well parse it. */ - double dvalue = 0.0; - long long lvalue = 0; - - /* Certain (WCS) keywords must be floating point, even if - their FITS encoding is a valid integer. - Use the value of NAXIS to simplify the check. */ - - long long * plvalue = - cpl_property_find_type(keywlen, naxis) == 'F' - ? NULL : &lvalue; - -#ifdef CPL_PROPERTYLIST_DEBUG - const int iiparsed = iparsed; -#endif - const int ntype = cpl_fits_get_number(card, iparsed, plvalue, - &dvalue, &iparsed); - -#ifdef CPL_PROPERTYLIST_DEBUG - cpl_msg_warning(cpl_func, "FITSNUM(%d:%d<=%d): %lld %g (%c) %s", - ntype, iiparsed, iparsed, lvalue, dvalue, - card[iparsed], card + iparsed); -#endif - - if (ntype != 0) { - if (ntype < 0) { - pparseval->tcode = 'F'; - pparseval->val.f = dvalue; - } else { - pparseval->tcode = 'I'; - pparseval->val.i = lvalue; - } - pparseval->nmemb = 1; - } - } - } - - /* Now iparsed points to first byte after value */ - - if (pparseval->tcode != 0) { - /* Found value. Card OK ? */ - if (CPL_LIKELY(card[iparsed] == ' ' || - card[iparsed] == '/' || - card[iparsed] == '\0')) { - - const char * comchar = memchr(card + iparsed, '/', - FITS_CARD_LEN - iparsed); - - if (comchar == NULL) { - *pjparsed = FITS_CARD_LEN; /* Nothing left */ - } else { - *pjparsed = (int)(comchar - card); - } - } else { - /* A value was found, but a subsequent byte is invalid */ - pparseval->tcode = 0; - pparseval->nmemb = 0; - *pjparsed = iparsed; /* Invalid character - for error msg */ - } - } +inline static cxbool +cpl_cstr_check_memcmp(const cpl_cstr *key, cxcptr data) +{ + const char *key_ = cx_string_get_(key); + const cxsize keysz = cx_string_size_(key); + const cpl_memcmp *data_ = (const cpl_memcmp *)data; - return pparseval->tcode; - } - /* The value and its type is undefined, - both value and comment have zero length*/ + cpl_size i; - pparseval->tcode = 'U'; - *pjparsed = FITS_CARD_LEN; /* Nothing left */ + /* Does the key match the beginning of the provided start-keys ? */ + for (i = 0; i < data_->nstart; i++) { + if (keysz >= cx_string_size_(data_->startkey[i]) && + !memcmp(key_, cx_string_get_(data_->startkey[i]), + cx_string_size_(data_->startkey[i]))) + break; /* Match */ } - /* No value */ - pparseval->nmemb = 0; - return pparseval->tcode; -} - -/*----------------------------------------------------------------------------*/ -/** - @internal - @brief Get the comment of a FITS card - @param card A FITS card (80 bytes or more) may not have null terminator - @param jparsed The value from cpl_fits_get_value() - @param plen The length when present, otherwise zero - @return Points to start of comment, or NULL if no comment present - @note (Almost) no input validation in this internal function - @see fits_get_keyname(), ffgknm() - - A value of 80 (or more) for jparsed is allowed and interpreted as no comment - available. - - */ -/*----------------------------------------------------------------------------*/ -inline static -const char * cpl_fits_get_comment(const char * card, int jparsed, int * plen) -{ - /* The comment is not a comment if it is empty */ - if (jparsed + 1 < FITS_CARD_LEN && card[jparsed++] == '/') { - - /* CFITSIO insists on turning the 80 byte FITS record into a string */ - const char * nullchr = memchr(card + jparsed, 0, - FITS_CARD_LEN - jparsed); - const int cardlen = nullchr ? (nullchr - card) : FITS_CARD_LEN; + if (i < data_->nstart) + return data_->invert ? FALSE : TRUE; - /* Since for some comments it is recommended that a space follows the - comment byte (/) (FITS standard 4.3.2), such a space is not - considered part of the commentary text */ - - if (card[jparsed] == ' ') jparsed++; + /* Does the key exactly match the provided exact-keys ? */ + for (i = 0; i < data_->nexact; i++) { + if (keysz == cx_string_size_(data_->exactkey[i]) && + !memcmp(key_, cx_string_get_(data_->exactkey[i]), keysz)) + break; /* Match */ + } - if (jparsed < cardlen) { + if (i < data_->nexact) + return data_->invert ? FALSE : TRUE; - *plen = cardlen - jparsed; - /* Drop trailing spaces */ - while (card[jparsed + *plen - 1] == ' ' && *plen > 0) { - *plen -= 1; - } - return *plen > 0 ? card + jparsed : NULL; - } - } + /* No match */ - *plen = 0; - return NULL; + return data_->invert ? TRUE : FALSE; } -/*----------------------------------------------------------------------------*/ -/** - @internal - @brief Deallocate memory used for checkning key uniqueness - @param putkey Array of keys arrays already written, ordered after length - @return Nothing - @note (Almost) no input validation in this internal function +/** + * @internal + * @brief + * Check whether the property name matches the regular expression + * + * @param self The property name to compare + * @param data The regular expression with invert flag + * @return TRUE iff the name matches else false (inverted if the flag is set) + * @see cpl_property_check_memcmp, cpl_cstr_key_regexp + * @note This function is an order of magnitude slower than the memcmp version + * */ -/*----------------------------------------------------------------------------*/ -inline static void -cpl_fits_key_free_unique(const char ** putkey[]) +inline static cxbool +cpl_property_check_regexp(const cpl_property *self, cxcptr data) { -#ifdef CPL_PROPERTYLIST_DEBUG - cpl_size maxpos = 0; - cpl_size maxlen = 0; - cpl_size nonull = 0; -#endif - for (cpl_size i = 0; i < FLEN_KEYWORD; i++) { - if (putkey[i]) { -#ifdef CPL_PROPERTYLIST_DEBUG - cpl_size k = 0; - - while (putkey[i][k++] != NULL); - - nonull++; - if (k > maxlen) { - maxlen = k; - maxpos = i; - } - cpl_msg_info(cpl_func, "UNIQ-check(%d<%d): %d", - (int)i, FLEN_KEYWORD, (int)k); -#endif - cpl_free(putkey[i]); - } - } - -#ifdef CPL_PROPERTYLIST_DEBUG - cpl_msg_warning(cpl_func, "UNIQ-CHECK(%d:%d<%d): %d", (int)nonull, - (int)maxpos, FLEN_KEYWORD, (int)maxlen); + const cpl_cstr *key = +#ifdef CPL_CXSTR_DEBUG + CXSTR(cpl_property_get_name_(self), cpl_property_get_size_name(self)) +#else + /* The regexp parser cannot use the size */ + CXSTR(cpl_property_get_name_(self), 0) #endif + ; + return cpl_cstr_check_regexp(key, data); } -/*----------------------------------------------------------------------------*/ -/** - @internal - @brief Uniqueness check of a key with the given length - @param KLEN The key length - @return Nothing - @note (Almost) no input validation in this internal macro - -*/ -/*----------------------------------------------------------------------------*/ -#define CPL_FITS_IS_UNIQUE_ONE(KLEN) \ - do { \ - cpl_size i = 0; \ - if (putkey[KLEN] != NULL) { \ - do { \ - if (!memcmp(putkey[KLEN][i], keyname, KLEN)) return 1; \ - } while (putkey[KLEN][++i] != NULL); \ - } else { \ - /* One extra for the NULL-terminator */ \ - putkey[KLEN] = cpl_malloc((ntocheck + 2) * sizeof(char *)); \ - } \ - \ - putkey[KLEN][i ] = keyname; \ - putkey[KLEN][i + 1] = NULL; \ - \ - } while (0) - - -/*----------------------------------------------------------------------------*/ -/** - @internal - @brief Uniqueness check of a key with the given length, larger than 8 - @param KLEN The key length - @return Nothing - @note Longer keys tend to differ only at the end, call memcmp() differently - @see CPL_FITS_IS_UNIQUE_ONE() - -*/ -/*----------------------------------------------------------------------------*/ -#define CPL_FITS_IS_UNIQUE_TWO(KLEN) \ - do { \ - cpl_size i = 0; \ - if (putkey[KLEN] != NULL) { \ - do { \ - if (!memcmp(putkey[KLEN][i] + KLEN - 8, keyname + KLEN - 8, 8) && \ - !memcmp(putkey[KLEN][i], keyname, KLEN - 8)) return 1; \ - } while (putkey[KLEN][++i] != NULL); \ - } else { \ - /* One extra for the NULL-terminator */ \ - putkey[KLEN] = cpl_malloc((ntocheck + 2) * sizeof(char *)); \ - } \ - \ - putkey[KLEN][i ] = keyname; \ - putkey[KLEN][i + 1] = NULL; \ - \ - } while (0) - -/*----------------------------------------------------------------------------*/ /** - @internal - @brief Check if a FITS card has already been written - @param putkey Array of keys arrays already written, ordered after length - @param key The key to check - @param ntocheck Number of keys to check after this one - @return Zero if the card has not (yet) been written, negative if exempt - @note (Almost) no input validation in this internal function - - As a poor-man's hash this check first groups written keys according to their - length, so the actual string comparison is done only on keys with matching - lengths, reducing the number of memcmp() calls. - - An option would also be to group the already seen keys according to their - sortkey. However, with the grouping according to length, and with keys that - do not share the sorting key typically differing within their first 8 bytes, - this is not worth the added complexity and increased number of buffers. - + * @internal + * @brief + * Check whether the property name matches the provided names + * + * @param self The property name to compare + * @param data The lists of name beginnings and exact names with invert flag + * @return TRUE iff the name matches else false (inverted if the flag is set) + * @see cpl_property_check_regexp, cpl_cstr_key_memcmp + * @note This function is an order of magnitude faster than the regexp version + * */ -/*----------------------------------------------------------------------------*/ -inline static cxint -cpl_fits_key_is_unique(const char **putkey[], - const cpl_cstr * key, - cpl_size ntocheck) -{ - cxsize keylen = cx_string_size_(key); - const char * keyname = cx_string_get_(key); - - /* Trailing blanks in the key should not occur. - Regardless (and since for a normal key it is only one check), make - sure to remove any since they would be ignored in a FITS card. */ - while (CPL_LIKELY(keylen > 0) && CPL_UNLIKELY(keyname[keylen - 1] == ' ')) { - keylen--; - } - - /* Use this cumbersome switch so each call to memcmp() can be inline'd */ - /* No point in distinguishing among keys too long to convert to FITS */ - switch (CX_MIN(keylen, FLEN_KEYWORD - 1)) { - case 0: - return -1; /* Zero length may come from all spaces */ - case 1: - CPL_FITS_IS_UNIQUE_ONE(1); - break; - case 2: - CPL_FITS_IS_UNIQUE_ONE(2); - break; - case 3: - CPL_FITS_IS_UNIQUE_ONE(3); - break; - case 4: - CPL_FITS_IS_UNIQUE_ONE(4); - break; - case 5: - CPL_FITS_IS_UNIQUE_ONE(5); - break; - case 6: - CPL_FITS_IS_UNIQUE_ONE(6); - break; - case 7: - if (!memcmp("COMMENT", keyname, 7) || - !memcmp("HISTORY", keyname, 7)) return -1; - CPL_FITS_IS_UNIQUE_ONE(7); - break; - case 8: - CPL_FITS_IS_UNIQUE_ONE(8); - break; - case 9: - CPL_FITS_IS_UNIQUE_TWO(9); - break; - case 10: - CPL_FITS_IS_UNIQUE_TWO(10); - break; - case 11: - CPL_FITS_IS_UNIQUE_TWO(11); - break; - case 12: - CPL_FITS_IS_UNIQUE_TWO(12); - break; - case 13: - CPL_FITS_IS_UNIQUE_TWO(13); - break; - case 14: - CPL_FITS_IS_UNIQUE_TWO(14); - break; - case 15: - CPL_FITS_IS_UNIQUE_TWO(15); - break; - case 16: - CPL_FITS_IS_UNIQUE_TWO(16); - break; - case 17: - CPL_FITS_IS_UNIQUE_TWO(17); - break; - case 18: - CPL_FITS_IS_UNIQUE_TWO(18); - break; - case 19: - CPL_FITS_IS_UNIQUE_TWO(19); - break; - case 20: - CPL_FITS_IS_UNIQUE_TWO(20); - break; - case 21: - CPL_FITS_IS_UNIQUE_TWO(21); - break; - case 22: - CPL_FITS_IS_UNIQUE_TWO(22); - break; - case 23: - CPL_FITS_IS_UNIQUE_TWO(23); - break; - case 24: - CPL_FITS_IS_UNIQUE_TWO(24); - break; - case 25: - CPL_FITS_IS_UNIQUE_TWO(25); - break; - case 26: - CPL_FITS_IS_UNIQUE_TWO(26); - break; - case 27: - CPL_FITS_IS_UNIQUE_TWO(27); - break; - case 28: - CPL_FITS_IS_UNIQUE_TWO(28); - break; - case 29: - CPL_FITS_IS_UNIQUE_TWO(29); - break; - case 30: - CPL_FITS_IS_UNIQUE_TWO(30); - break; - case 31: - CPL_FITS_IS_UNIQUE_TWO(31); - break; - case 32: - CPL_FITS_IS_UNIQUE_TWO(32); - break; - case 33: - CPL_FITS_IS_UNIQUE_TWO(33); - break; - case 34: - CPL_FITS_IS_UNIQUE_TWO(34); - break; - case 35: - CPL_FITS_IS_UNIQUE_TWO(35); - break; - case 36: - CPL_FITS_IS_UNIQUE_TWO(36); - break; - case 37: - CPL_FITS_IS_UNIQUE_TWO(37); - break; - case 38: - CPL_FITS_IS_UNIQUE_TWO(38); - break; - case 39: - CPL_FITS_IS_UNIQUE_TWO(39); - break; - case 40: - CPL_FITS_IS_UNIQUE_TWO(40); - break; - case 41: - CPL_FITS_IS_UNIQUE_TWO(41); - break; - case 42: - CPL_FITS_IS_UNIQUE_TWO(42); - break; - case 43: - CPL_FITS_IS_UNIQUE_TWO(43); - break; - case 44: - CPL_FITS_IS_UNIQUE_TWO(44); - break; - case 45: - CPL_FITS_IS_UNIQUE_TWO(45); - break; - case 46: - CPL_FITS_IS_UNIQUE_TWO(46); - break; - case 47: - CPL_FITS_IS_UNIQUE_TWO(47); - break; - case 48: - CPL_FITS_IS_UNIQUE_TWO(48); - break; - case 49: - CPL_FITS_IS_UNIQUE_TWO(49); - break; - case 50: - CPL_FITS_IS_UNIQUE_TWO(50); - break; - case 51: - CPL_FITS_IS_UNIQUE_TWO(51); - break; - case 52: - CPL_FITS_IS_UNIQUE_TWO(52); - break; - case 53: - CPL_FITS_IS_UNIQUE_TWO(53); - break; - case 54: - CPL_FITS_IS_UNIQUE_TWO(54); - break; - case 55: - CPL_FITS_IS_UNIQUE_TWO(55); - break; - case 56: - CPL_FITS_IS_UNIQUE_TWO(56); - break; - case 57: - CPL_FITS_IS_UNIQUE_TWO(57); - break; - case 58: - CPL_FITS_IS_UNIQUE_TWO(58); - break; - case 59: - CPL_FITS_IS_UNIQUE_TWO(59); - break; - case 60: - CPL_FITS_IS_UNIQUE_TWO(60); - break; - case 61: - CPL_FITS_IS_UNIQUE_TWO(61); - break; - case 62: - CPL_FITS_IS_UNIQUE_TWO(62); - break; - case 63: - CPL_FITS_IS_UNIQUE_TWO(63); - break; - case 64: - CPL_FITS_IS_UNIQUE_TWO(64); - break; - case 65: - CPL_FITS_IS_UNIQUE_TWO(65); - break; - case 66: - CPL_FITS_IS_UNIQUE_TWO(66); - break; - case 67: - CPL_FITS_IS_UNIQUE_TWO(67); - break; - case 68: - CPL_FITS_IS_UNIQUE_TWO(68); - break; - case 69: - CPL_FITS_IS_UNIQUE_TWO(69); - break; - case 70: - CPL_FITS_IS_UNIQUE_TWO(70); - break; - case 71: - CPL_FITS_IS_UNIQUE_TWO(71); - break; - } +inline static cxbool +cpl_property_check_memcmp(const cpl_property *self, cxcptr data) +{ + const cpl_cstr *key = + CXSTR(cpl_property_get_name_(self), cpl_property_get_size_name(self)); - return 0; + return cpl_cstr_check_memcmp(key, data); } + +#include "cpl_fits_card.c" +#include "cpl_property_dicb.c" diff -Nru cpl-7.1.4+ds/cplcore/cpl_propertylist.h cpl-7.2.2+ds/cplcore/cpl_propertylist.h --- cpl-7.1.4+ds/cplcore/cpl_propertylist.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_propertylist.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -54,70 +54,61 @@ * Create, copy and destroy operations. */ -cpl_propertylist * -cpl_propertylist_new(void) CPL_ATTR_ALLOC; +cpl_propertylist *cpl_propertylist_new(void) CPL_ATTR_ALLOC; cpl_propertylist * cpl_propertylist_duplicate(const cpl_propertylist *other) CPL_ATTR_ALLOC; -void -cpl_propertylist_delete(cpl_propertylist *self); +void cpl_propertylist_delete(cpl_propertylist *self); /* * Non modifying operations */ -cpl_size -cpl_propertylist_get_size(const cpl_propertylist *self); +cpl_size cpl_propertylist_get_size(const cpl_propertylist *self); -int -cpl_propertylist_is_empty(const cpl_propertylist *self); +int cpl_propertylist_is_empty(const cpl_propertylist *self); cpl_type cpl_propertylist_get_type(const cpl_propertylist *self, const char *name); -int -cpl_propertylist_has(const cpl_propertylist *self, const char *name); +int cpl_propertylist_has(const cpl_propertylist *self, const char *name); /* * Assignment operations */ -cpl_error_code -cpl_propertylist_set_comment(cpl_propertylist *self, const char *name, - const char *comment); -cpl_error_code -cpl_propertylist_set_char(cpl_propertylist *self, const char *name, - char value); -cpl_error_code -cpl_propertylist_set_bool(cpl_propertylist *self, const char *name , - int value); -cpl_error_code -cpl_propertylist_set_int(cpl_propertylist *self, const char *name, - int value); -cpl_error_code -cpl_propertylist_set_long(cpl_propertylist *self, const char *name, - long value); -cpl_error_code -cpl_propertylist_set_long_long(cpl_propertylist *self, const char *name, - long long value); -cpl_error_code -cpl_propertylist_set_float(cpl_propertylist *self, const char *name, - float value); -cpl_error_code -cpl_propertylist_set_double(cpl_propertylist *self, const char *name, - double value); -cpl_error_code -cpl_propertylist_set_string(cpl_propertylist *self, const char *name, - const char *value); -cpl_error_code -cpl_propertylist_set_float_complex(cpl_propertylist *self, const char *name, - _Complex float value); -cpl_error_code -cpl_propertylist_set_double_complex(cpl_propertylist *self, const char *name, - _Complex double value); +cpl_error_code cpl_propertylist_set_comment(cpl_propertylist *self, + const char *name, + const char *comment); +cpl_error_code +cpl_propertylist_set_char(cpl_propertylist *self, const char *name, char value); +cpl_error_code +cpl_propertylist_set_bool(cpl_propertylist *self, const char *name, int value); +cpl_error_code +cpl_propertylist_set_int(cpl_propertylist *self, const char *name, int value); +cpl_error_code +cpl_propertylist_set_long(cpl_propertylist *self, const char *name, long value); +cpl_error_code cpl_propertylist_set_long_long(cpl_propertylist *self, + const char *name, + long long value); +cpl_error_code cpl_propertylist_set_float(cpl_propertylist *self, + const char *name, + float value); +cpl_error_code cpl_propertylist_set_double(cpl_propertylist *self, + const char *name, + double value); +cpl_error_code cpl_propertylist_set_string(cpl_propertylist *self, + const char *name, + const char *value); +cpl_error_code cpl_propertylist_set_float_complex(cpl_propertylist *self, + const char *name, + _Complex float value); +cpl_error_code cpl_propertylist_set_double_complex(cpl_propertylist *self, + const char *name, + _Complex double value); /* @@ -127,11 +118,11 @@ const cpl_property * cpl_propertylist_get_const(const cpl_propertylist *self, long position); -cpl_property * -cpl_propertylist_get(cpl_propertylist *self, long position); +cpl_property *cpl_propertylist_get(cpl_propertylist *self, long position); const cpl_property * -cpl_propertylist_get_property_const(const cpl_propertylist *self, const char *name); +cpl_propertylist_get_property_const(const cpl_propertylist *self, + const char *name); cpl_property * cpl_propertylist_get_property(cpl_propertylist *self, const char *name); @@ -139,17 +130,13 @@ const char * cpl_propertylist_get_comment(const cpl_propertylist *self, const char *name); -char -cpl_propertylist_get_char(const cpl_propertylist *self, const char *name); +char cpl_propertylist_get_char(const cpl_propertylist *self, const char *name); -int -cpl_propertylist_get_bool(const cpl_propertylist *self, const char *name); +int cpl_propertylist_get_bool(const cpl_propertylist *self, const char *name); -int -cpl_propertylist_get_int(const cpl_propertylist *self, const char *name); +int cpl_propertylist_get_int(const cpl_propertylist *self, const char *name); -long -cpl_propertylist_get_long(const cpl_propertylist *self, const char *name); +long cpl_propertylist_get_long(const cpl_propertylist *self, const char *name); long long cpl_propertylist_get_long_long(const cpl_propertylist *self, const char *name); @@ -163,9 +150,8 @@ const char * cpl_propertylist_get_string(const cpl_propertylist *self, const char *name); -_Complex float -cpl_propertylist_get_float_complex(const cpl_propertylist *self, - const char *name); +_Complex float cpl_propertylist_get_float_complex(const cpl_propertylist *self, + const char *name); _Complex double cpl_propertylist_get_double_complex(const cpl_propertylist *self, @@ -176,82 +162,100 @@ * Inserting and removing elements */ -cpl_error_code -cpl_propertylist_insert_char(cpl_propertylist *self, const char *here, - const char *name, char value); - -cpl_error_code -cpl_propertylist_insert_bool(cpl_propertylist *self, const char *here, - const char *name, int value); - -cpl_error_code -cpl_propertylist_insert_int(cpl_propertylist *self, const char *here, - const char *name, int value); - -cpl_error_code -cpl_propertylist_insert_long(cpl_propertylist *self, const char *here, - const char *name, long value); - -cpl_error_code -cpl_propertylist_insert_long_long(cpl_propertylist *self, const char *here, - const char *name, long long value); - -cpl_error_code -cpl_propertylist_insert_float(cpl_propertylist *self, const char *here, - const char *name, float value); - -cpl_error_code -cpl_propertylist_insert_double(cpl_propertylist *self, const char *here, - const char *name, double value); - -cpl_error_code -cpl_propertylist_insert_string(cpl_propertylist *self, const char *here, - const char *name, const char *value); - -cpl_error_code -cpl_propertylist_insert_float_complex(cpl_propertylist *self, const char *here, - const char *name, _Complex float value); - -cpl_error_code -cpl_propertylist_insert_double_complex(cpl_propertylist *self, const char *here, - const char *name, _Complex double value); - -cpl_error_code -cpl_propertylist_insert_after_char(cpl_propertylist *self, const char *after, - const char *name, char value); - -cpl_error_code -cpl_propertylist_insert_after_bool(cpl_propertylist *self, const char *after, - const char *name, int value); - -cpl_error_code -cpl_propertylist_insert_after_int(cpl_propertylist *self, const char *after, - const char *name, int value); - -cpl_error_code -cpl_propertylist_insert_after_long(cpl_propertylist *self, const char *after, - const char *name, long value); - -cpl_error_code -cpl_propertylist_insert_after_long_long(cpl_propertylist *self, - const char *after, const char *name, - long long value); - -cpl_error_code -cpl_propertylist_insert_after_float(cpl_propertylist *self, const char *after, - const char *name, float value); +cpl_error_code cpl_propertylist_insert_char(cpl_propertylist *self, + const char *here, + const char *name, + char value); + +cpl_error_code cpl_propertylist_insert_bool(cpl_propertylist *self, + const char *here, + const char *name, + int value); + +cpl_error_code cpl_propertylist_insert_int(cpl_propertylist *self, + const char *here, + const char *name, + int value); + +cpl_error_code cpl_propertylist_insert_long(cpl_propertylist *self, + const char *here, + const char *name, + long value); + +cpl_error_code cpl_propertylist_insert_long_long(cpl_propertylist *self, + const char *here, + const char *name, + long long value); -cpl_error_code -cpl_propertylist_insert_after_double(cpl_propertylist *self, const char *after, - const char *name, double value); +cpl_error_code cpl_propertylist_insert_float(cpl_propertylist *self, + const char *here, + const char *name, + float value); -cpl_error_code -cpl_propertylist_insert_after_string(cpl_propertylist *self, const char *after, - const char *name, const char *value); +cpl_error_code cpl_propertylist_insert_double(cpl_propertylist *self, + const char *here, + const char *name, + double value); + +cpl_error_code cpl_propertylist_insert_string(cpl_propertylist *self, + const char *here, + const char *name, + const char *value); + +cpl_error_code cpl_propertylist_insert_float_complex(cpl_propertylist *self, + const char *here, + const char *name, + _Complex float value); + +cpl_error_code cpl_propertylist_insert_double_complex(cpl_propertylist *self, + const char *here, + const char *name, + _Complex double value); + +cpl_error_code cpl_propertylist_insert_after_char(cpl_propertylist *self, + const char *after, + const char *name, + char value); + +cpl_error_code cpl_propertylist_insert_after_bool(cpl_propertylist *self, + const char *after, + const char *name, + int value); + +cpl_error_code cpl_propertylist_insert_after_int(cpl_propertylist *self, + const char *after, + const char *name, + int value); + +cpl_error_code cpl_propertylist_insert_after_long(cpl_propertylist *self, + const char *after, + const char *name, + long value); + +cpl_error_code cpl_propertylist_insert_after_long_long(cpl_propertylist *self, + const char *after, + const char *name, + long long value); + +cpl_error_code cpl_propertylist_insert_after_float(cpl_propertylist *self, + const char *after, + const char *name, + float value); + +cpl_error_code cpl_propertylist_insert_after_double(cpl_propertylist *self, + const char *after, + const char *name, + double value); + +cpl_error_code cpl_propertylist_insert_after_string(cpl_propertylist *self, + const char *after, + const char *name, + const char *value); cpl_error_code cpl_propertylist_insert_after_float_complex(cpl_propertylist *self, - const char *after, const char *name, + const char *after, + const char *name, _Complex float value); cpl_error_code @@ -260,164 +264,155 @@ const char *name, _Complex double value); -cpl_error_code -cpl_propertylist_prepend_char(cpl_propertylist *self, const char *name, - char value); +cpl_error_code cpl_propertylist_prepend_char(cpl_propertylist *self, + const char *name, + char value); -cpl_error_code -cpl_propertylist_prepend_bool(cpl_propertylist *self, const char *name, - int value); -cpl_error_code -cpl_propertylist_prepend_int(cpl_propertylist *self, const char *name, - int value); +cpl_error_code cpl_propertylist_prepend_bool(cpl_propertylist *self, + const char *name, + int value); +cpl_error_code cpl_propertylist_prepend_int(cpl_propertylist *self, + const char *name, + int value); -cpl_error_code -cpl_propertylist_prepend_long(cpl_propertylist *self, const char *name, - long value); +cpl_error_code cpl_propertylist_prepend_long(cpl_propertylist *self, + const char *name, + long value); -cpl_error_code -cpl_propertylist_prepend_long_long(cpl_propertylist *self, const char *name, - long long value); +cpl_error_code cpl_propertylist_prepend_long_long(cpl_propertylist *self, + const char *name, + long long value); -cpl_error_code -cpl_propertylist_prepend_float(cpl_propertylist *self, const char *name, - float value); +cpl_error_code cpl_propertylist_prepend_float(cpl_propertylist *self, + const char *name, + float value); -cpl_error_code -cpl_propertylist_prepend_double(cpl_propertylist *self, const char *name, - double value); +cpl_error_code cpl_propertylist_prepend_double(cpl_propertylist *self, + const char *name, + double value); -cpl_error_code -cpl_propertylist_prepend_string(cpl_propertylist *self, const char *name, - const char *value); +cpl_error_code cpl_propertylist_prepend_string(cpl_propertylist *self, + const char *name, + const char *value); -cpl_error_code -cpl_propertylist_prepend_float_complex(cpl_propertylist *self, - const char *name, - _Complex float value); +cpl_error_code cpl_propertylist_prepend_float_complex(cpl_propertylist *self, + const char *name, + _Complex float value); -cpl_error_code -cpl_propertylist_prepend_double_complex(cpl_propertylist *self, - const char *name, - _Complex double value); +cpl_error_code cpl_propertylist_prepend_double_complex(cpl_propertylist *self, + const char *name, + _Complex double value); -cpl_error_code -cpl_propertylist_append_char(cpl_propertylist *self, const char *name, - char value); +cpl_error_code cpl_propertylist_append_char(cpl_propertylist *self, + const char *name, + char value); -cpl_error_code -cpl_propertylist_append_bool(cpl_propertylist *self, const char *name, - int value); +cpl_error_code cpl_propertylist_append_bool(cpl_propertylist *self, + const char *name, + int value); -cpl_error_code -cpl_propertylist_append_int(cpl_propertylist *self, const char *name, - int value); +cpl_error_code cpl_propertylist_append_int(cpl_propertylist *self, + const char *name, + int value); -cpl_error_code -cpl_propertylist_append_long(cpl_propertylist *self, const char *name, - long value); +cpl_error_code cpl_propertylist_append_long(cpl_propertylist *self, + const char *name, + long value); -cpl_error_code -cpl_propertylist_append_long_long(cpl_propertylist *self, const char *name, - long long value); +cpl_error_code cpl_propertylist_append_long_long(cpl_propertylist *self, + const char *name, + long long value); -cpl_error_code -cpl_propertylist_append_float(cpl_propertylist *self, const char *name, - float value); +cpl_error_code cpl_propertylist_append_float(cpl_propertylist *self, + const char *name, + float value); -cpl_error_code -cpl_propertylist_append_double(cpl_propertylist *self, const char *name, - double value); +cpl_error_code cpl_propertylist_append_double(cpl_propertylist *self, + const char *name, + double value); -cpl_error_code -cpl_propertylist_append_string(cpl_propertylist *self, const char *name, - const char *value); +cpl_error_code cpl_propertylist_append_string(cpl_propertylist *self, + const char *name, + const char *value); -cpl_error_code -cpl_propertylist_append_float_complex(cpl_propertylist *self, const char *name, - _Complex float value); +cpl_error_code cpl_propertylist_append_float_complex(cpl_propertylist *self, + const char *name, + _Complex float value); -cpl_error_code -cpl_propertylist_append_double_complex(cpl_propertylist *self, const char *name, - _Complex double value); +cpl_error_code cpl_propertylist_append_double_complex(cpl_propertylist *self, + const char *name, + _Complex double value); cpl_error_code -cpl_propertylist_append(cpl_propertylist *self, - const cpl_propertylist *other); +cpl_propertylist_append(cpl_propertylist *self, const cpl_propertylist *other); -int -cpl_propertylist_erase(cpl_propertylist *self, const char *name); +int cpl_propertylist_erase(cpl_propertylist *self, const char *name); -int -cpl_propertylist_erase_regexp(cpl_propertylist *self, const char *regexp, - int invert); +int cpl_propertylist_erase_regexp(cpl_propertylist *self, + const char *regexp, + int invert); -void -cpl_propertylist_empty(cpl_propertylist *self); +void cpl_propertylist_empty(cpl_propertylist *self); /* * Convenience functions */ -cpl_error_code -cpl_propertylist_update_char(cpl_propertylist *self, const char *name, - char value); -cpl_error_code -cpl_propertylist_update_bool(cpl_propertylist *self, const char *name, - int value); -cpl_error_code -cpl_propertylist_update_int(cpl_propertylist *self, const char *name, - int value); -cpl_error_code -cpl_propertylist_update_long(cpl_propertylist *self, const char *name, - long value); -cpl_error_code -cpl_propertylist_update_long_long(cpl_propertylist *self, const char *name, - long long value); -cpl_error_code -cpl_propertylist_update_float(cpl_propertylist *self, const char *name, - float value); -cpl_error_code -cpl_propertylist_update_double(cpl_propertylist *self, const char *name, - double value); -cpl_error_code -cpl_propertylist_update_string(cpl_propertylist *self, const char *name, - const char *value); -cpl_error_code -cpl_propertylist_update_float_complex(cpl_propertylist *self, const char *name, - _Complex float value); -cpl_error_code -cpl_propertylist_update_double_complex(cpl_propertylist *self, const char *name, - _Complex double value); +cpl_error_code cpl_propertylist_update_char(cpl_propertylist *self, + const char *name, + char value); +cpl_error_code cpl_propertylist_update_bool(cpl_propertylist *self, + const char *name, + int value); +cpl_error_code cpl_propertylist_update_int(cpl_propertylist *self, + const char *name, + int value); +cpl_error_code cpl_propertylist_update_long(cpl_propertylist *self, + const char *name, + long value); +cpl_error_code cpl_propertylist_update_long_long(cpl_propertylist *self, + const char *name, + long long value); +cpl_error_code cpl_propertylist_update_float(cpl_propertylist *self, + const char *name, + float value); +cpl_error_code cpl_propertylist_update_double(cpl_propertylist *self, + const char *name, + double value); +cpl_error_code cpl_propertylist_update_string(cpl_propertylist *self, + const char *name, + const char *value); +cpl_error_code cpl_propertylist_update_float_complex(cpl_propertylist *self, + const char *name, + _Complex float value); +cpl_error_code cpl_propertylist_update_double_complex(cpl_propertylist *self, + const char *name, + _Complex double value); /* * Working on properties */ -cpl_error_code -cpl_propertylist_copy_property(cpl_propertylist *self, - const cpl_propertylist *other, - const char *name); +cpl_error_code cpl_propertylist_copy_property(cpl_propertylist *self, + const cpl_propertylist *other, + const char *name); cpl_error_code cpl_propertylist_copy_property_regexp(cpl_propertylist *self, const cpl_propertylist *other, const char *regexp, int invert); -cpl_error_code -cpl_propertylist_append_property(cpl_propertylist *self, - const cpl_property *property); +cpl_error_code cpl_propertylist_append_property(cpl_propertylist *self, + const cpl_property *property); -cpl_error_code -cpl_propertylist_prepend_property(cpl_propertylist *self, - const cpl_property *property); -cpl_error_code -cpl_propertylist_insert_property(cpl_propertylist *self, - const char *here, - const cpl_property *property); +cpl_error_code cpl_propertylist_prepend_property(cpl_propertylist *self, + const cpl_property *property); +cpl_error_code cpl_propertylist_insert_property(cpl_propertylist *self, + const char *here, + const cpl_property *property); cpl_error_code cpl_propertylist_insert_after_property(cpl_propertylist *self, const char *after, @@ -427,9 +422,8 @@ * Sorting */ -cpl_error_code -cpl_propertylist_sort(cpl_propertylist *self, - cpl_propertylist_compare_func compare); +cpl_error_code cpl_propertylist_sort(cpl_propertylist *self, + cpl_propertylist_compare_func compare); /* * Loading, saving and conversion operations. @@ -438,12 +432,13 @@ cpl_propertylist * cpl_propertylist_load(const char *name, cpl_size position) CPL_ATTR_ALLOC; -cpl_propertylist * -cpl_propertylist_load_regexp(const char *name, cpl_size position, - const char *regexp, int invert) CPL_ATTR_ALLOC; -cpl_error_code -cpl_propertylist_save(const cpl_propertylist *self, const char *filename, - unsigned int mode); +cpl_propertylist *cpl_propertylist_load_regexp(const char *name, + cpl_size position, + const char *regexp, + int invert) CPL_ATTR_ALLOC; +cpl_error_code cpl_propertylist_save(const cpl_propertylist *self, + const char *filename, + unsigned int mode); void cpl_propertylist_dump(const cpl_propertylist *self, FILE *stream); diff -Nru cpl-7.1.4+ds/cplcore/cpl_propertylist_impl.h cpl-7.2.2+ds/cplcore/cpl_propertylist_impl.h --- cpl-7.1.4+ds/cplcore/cpl_propertylist_impl.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_propertylist_impl.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -20,54 +20,127 @@ #ifndef CPL_PROPERTYLIST_IMPL_H #define CPL_PROPERTYLIST_IMPL_H -#include - #include "cpl_propertylist.h" #include "cpl_property_impl.h" -CPL_BEGIN_DECLS +#include + +#include +#include + +/* + * Regular expression filter type + */ + +typedef struct cpl_regexp +{ + regex_t re; + cxbool invert; +} cpl_regexp; -cpl_error_code cpl_propertylist_to_fitsfile(fitsfile *file, - const cpl_propertylist *self, - const char *to_rm); - -cpl_propertylist *cpl_propertylist_from_fitsfile(fitsfile *file); - -cpl_propertylist * -cpl_propertylist_load_name_(const char*, - cpl_size, - cpl_size, - const cpl_cstr *[], - cpl_size, - const cpl_cstr *[], - int) +/* + * memcmp() filter type + */ + +typedef struct cpl_memcmp +{ + cpl_size nstart; + const cpl_cstr **startkey; + cpl_size nexact; + const cpl_cstr **exactkey; + cxbool invert; +} cpl_memcmp; + +CPL_BEGIN_DECLS +cpl_error_code cpl_propertylist_to_fitsfile(fitsfile *, + const cpl_propertylist *, + const char *, + cpl_boolean); + +cpl_propertylist *cpl_propertylist_from_fitsfile(fitsfile *); + +cpl_propertylist *cpl_propertylist_load_name_(const char *, + cpl_size, + cpl_size, + const cpl_cstr *[], + cpl_size, + const cpl_cstr *[], + int) #ifdef CPL_HAVE_ATTR_NONNULL __attribute__((nonnull(1))) #endif - CPL_ATTR_ALLOC; +cpl_error_code cpl_propertylist_copy_name_(cpl_propertylist *, + const cpl_propertylist *, + cpl_size, + const cpl_cstr *[], + cpl_size, + const cpl_cstr *[], + int) +#ifdef CPL_HAVE_ATTR_NONNULL + __attribute__((nonnull(1, 2))) +#endif + ; + +cpl_error_code cpl_propertylist_erase_name_(cpl_propertylist *, + cpl_size, + const cpl_cstr *[], + cpl_size, + const cpl_cstr *[], + int) +#ifdef CPL_HAVE_ATTR_NONNULL + __attribute__((nonnull(1))) +#endif + ; + cpl_error_code cpl_fits_add_properties(fitsfile *, - const cpl_propertylist *, - const char *); + const cpl_propertylist *, + unsigned, + cpl_boolean) +#ifdef CPL_HAVE_ATTR_NONNULL + __attribute__((nonnull(1))) +#endif + ; + +cpl_error_code +cpl_propertylist_set_comment_cx(cpl_propertylist *, + const cpl_cstr *, + const cpl_cstr *) CPL_ATTR_NONNULL; + +const cpl_property * +cpl_propertylist_get_const_cx(const cpl_propertylist *, + const cpl_cstr *) CPL_ATTR_NONNULL; + +int cpl_propertylist_has_cx(const cpl_propertylist *, + const cpl_cstr *) CPL_ATTR_NONNULL; + +cpl_type cpl_propertylist_get_type_cx(const cpl_propertylist *, + const cpl_cstr *) CPL_ATTR_NONNULL; + +int cpl_propertylist_erase_cx(cpl_propertylist *, + const cpl_cstr *) CPL_ATTR_NONNULL; + +cpl_error_code cpl_propertylist_set_property(cpl_propertylist *, + cpl_property *) CPL_ATTR_NONNULL; + +cpl_property * +cpl_propertylist_update_string_(cpl_propertylist *, + const cpl_cstr *, + const cpl_cstr *) CPL_ATTR_NONNULL; + +cpl_error_code cpl_propertylist_append_from_string(cpl_propertylist *, + const char *, + const cpl_memcmp *, + const cpl_regexp *) +#ifdef CPL_HAVE_ATTR_NONNULL + __attribute__((nonnull(1, 2))) +#endif + ; cpl_error_code -cpl_propertylist_set_comment_cx(cpl_propertylist *, const cpl_cstr *, - const cpl_cstr *) - CPL_ATTR_NONNULL; - -int -cpl_propertylist_has_cx(const cpl_propertylist *, const cpl_cstr *) - CPL_ATTR_NONNULL; - -cpl_type -cpl_propertylist_get_type_cx(const cpl_propertylist *, const cpl_cstr *) - CPL_ATTR_NONNULL; - -int -cpl_propertylist_erase_cx(cpl_propertylist *, const cpl_cstr *) - CPL_ATTR_NONNULL; +cpl_fits_fill_card(char *, const cpl_property *) CPL_ATTR_NONNULL; CPL_END_DECLS diff -Nru cpl-7.1.4+ds/cplcore/cpl_stats_body.h cpl-7.2.2+ds/cplcore/cpl_stats_body.h --- cpl-7.1.4+ds/cplcore/cpl_stats_body.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_stats_body.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -19,18 +19,18 @@ /* Type dependent macros */ #if CPL_CLASS == CPL_CLASS_DOUBLE -#define CPL_TYPE double -#define CPL_TYPE_T CPL_TYPE_DOUBLE +#define CPL_TYPE double +#define CPL_TYPE_T CPL_TYPE_DOUBLE #define CPL_ADD_FLOPS_ADD cpl_tools_add_flops #elif CPL_CLASS == CPL_CLASS_FLOAT -#define CPL_TYPE float -#define CPL_TYPE_T CPL_TYPE_FLOAT +#define CPL_TYPE float +#define CPL_TYPE_T CPL_TYPE_FLOAT #define CPL_ADD_FLOPS_ADD cpl_tools_add_flops #elif CPL_CLASS == CPL_CLASS_INT -#define CPL_TYPE int -#define CPL_TYPE_T CPL_TYPE_INT +#define CPL_TYPE int +#define CPL_TYPE_T CPL_TYPE_INT #define CPL_ADD_FLOPS_ADD(N) /* N integer ops */ #else @@ -42,276 +42,274 @@ #if CPL_OPERATION == CPL_IMAGE_STATS_ALL - case CPL_TYPE_T: - { - const CPL_TYPE * pi = (const CPL_TYPE*)image->pixels; - - min_pos = max_pos = firstgoodpos; - min_pix = (double)pi[firstgoodpos]; - max_pix = (double)pi[firstgoodpos]; - - for (j=llysz-1; jnx; - - for (i=llxsz-1; i max_pix) max_pix = (double)pi[max_pos = pos]; - - pix_sum += (double)pi[pos]; - abs_sum += fabs((double)pi[pos]); - dev_sum += fabs((double)pi[pos]-self->med); - sqr_sum += (double)pi[pos] * (double)pi[pos]; - - } - pos++; - } - } - CPL_ADD_FLOPS_ADD(17 * npix); - break; - } +case CPL_TYPE_T: { + const CPL_TYPE *pi = (const CPL_TYPE *)image->pixels; + + min_pos = max_pos = firstgoodpos; + min_pix = (double)pi[firstgoodpos]; + max_pix = (double)pi[firstgoodpos]; + + for (j = llysz - 1; j < urysz; j++) { + pos = (llxsz - 1) + j * image->nx; + + for (i = llxsz - 1; i < urxsz; i++) { + if (nbadpix == 0 || !badmap[pos]) { + const double delta = (double)pi[pos] - pix_mean; + + pix_var += ipix * delta * (delta / (ipix + 1.0)); + pix_mean += delta / (ipix + 1.0); + ipix += 1.0; + + if (pi[pos] < min_pix) + min_pix = (double)pi[min_pos = pos]; + if (pi[pos] > max_pix) + max_pix = (double)pi[max_pos = pos]; + + pix_sum += (double)pi[pos]; + abs_sum += fabs((double)pi[pos]); + dev_sum += fabs((double)pi[pos] - self->med); + sqr_sum += (double)pi[pos] * (double)pi[pos]; + } + pos++; + } + } + CPL_ADD_FLOPS_ADD(17 * npix); + break; +} #elif CPL_OPERATION == CPL_IMAGE_STATS_VARIANCE - case CPL_TYPE_T: - { - const CPL_TYPE * pi = (const CPL_TYPE*)image->pixels; - - for (j=llysz-1; jnx; - for (i=llxsz-1; ipixels; + + for (j = llysz - 1; j < urysz; j++) { + pos = (llxsz - 1) + j * image->nx; + for (i = llxsz - 1; i < urxsz; i++) { + if (nbadpix == 0 || !badmap[pos]) { + const double delta = (double)pi[pos] - pix_mean; - /* The round-off on pix_mean may be different here + /* The round-off on pix_mean may be different here and in the all-stats block :-( */ - pix_var += ipix * delta * (delta / (ipix + 1.0)); - pix_mean += delta / (ipix + 1.0); - ipix += 1.0; - - } - pos++; - } - } - CPL_ADD_FLOPS_ADD(7 * npix); - break; - } + pix_var += ipix * delta * (delta / (ipix + 1.0)); + pix_mean += delta / (ipix + 1.0); + ipix += 1.0; + } + pos++; + } + } + CPL_ADD_FLOPS_ADD(7 * npix); + break; +} #elif CPL_OPERATION == CPL_IMAGE_STATS_CENTROID - case CPL_TYPE_T: - { - const CPL_TYPE * pi = (const CPL_TYPE*)image->pixels; - const double min_pix_tmp = min_pix < 0.0 ? min_pix : 0.0; - - for (j=llysz-1; jnx; - for (i=llxsz-1; ipixels; + const double min_pix_tmp = min_pix < 0.0 ? min_pix : 0.0; + + for (j = llysz - 1; j < urysz; j++) { + pos = (llxsz - 1) + j * image->nx; + for (i = llxsz - 1; i < urxsz; i++) { + if (nbadpix == 0 || !badmap[pos]) { + sum_xz += ((double)pi[pos] - min_pix_tmp) * (double)(i + 1); + sum_yz += ((double)pi[pos] - min_pix_tmp) * (double)(j + 1); + sum_z += (double)pi[pos] - min_pix_tmp; + sum_x += (double)(i + 1); + sum_y += (double)(j + 1); + } + pos++; + } + } + if (sum_z < 0) + sum_z = 0; /* Can only become negative due to rounding */ + if (sum_xz < 0) + sum_xz = 0; /* Can only become negative due to rounding */ + if (sum_yz < 0) + sum_yz = 0; /* Can only become negative due to rounding */ + CPL_ADD_FLOPS_ADD(8 * npix); + break; +} #elif CPL_OPERATION == CPL_IMAGE_STATS_MINMAX - case CPL_TYPE_T: - { - const CPL_TYPE * pi = (const CPL_TYPE*)image->pixels; - /* Avoid in-loop casting */ - CPL_TYPE min_tmp = pi[firstgoodpos]; - CPL_TYPE max_tmp = pi[firstgoodpos]; - - min_pos = max_pos = firstgoodpos; - for (j=llysz-1; jnx; - - for (i=llxsz-1; i max_tmp) max_tmp = pi[max_pos = pos]; - } - pos++; - } - } - min_pix = (double)min_tmp; - max_pix = (double)max_tmp; - CPL_ADD_FLOPS_ADD(2 * npix); - break; - } +case CPL_TYPE_T: { + const CPL_TYPE *pi = (const CPL_TYPE *)image->pixels; + /* Avoid in-loop casting */ + CPL_TYPE min_tmp = pi[firstgoodpos]; + CPL_TYPE max_tmp = pi[firstgoodpos]; + + min_pos = max_pos = firstgoodpos; + for (j = llysz - 1; j < urysz; j++) { + pos = (llxsz - 1) + j * image->nx; + + for (i = llxsz - 1; i < urxsz; i++) { + if (nbadpix == 0 || !badmap[pos]) { + if (pi[pos] < min_tmp) + min_tmp = pi[min_pos = pos]; + if (pi[pos] > max_tmp) + max_tmp = pi[max_pos = pos]; + } + pos++; + } + } + min_pix = (double)min_tmp; + max_pix = (double)max_tmp; + CPL_ADD_FLOPS_ADD(2 * npix); + break; +} #elif CPL_OPERATION == CPL_IMAGE_STATS_FLUX - case CPL_TYPE_T: - { - const CPL_TYPE * pi = (const CPL_TYPE*)image->pixels; - - for (j=llysz-1; jnx; - - for (i=llxsz-1; ipixels; + + for (j = llysz - 1; j < urysz; j++) { + pos = (llxsz - 1) + j * image->nx; + + for (i = llxsz - 1; i < urxsz; i++) { + if (nbadpix == 0 || !badmap[pos]) { + pix_sum += (double)pi[pos]; + abs_sum += fabs((double)pi[pos]); + sqr_sum += (double)pi[pos] * (double)pi[pos]; + } + pos++; + } + } + + CPL_ADD_FLOPS_ADD(5 * npix); + break; +} #elif CPL_OPERATION == CPL_IMAGE_STATS_MEDIAN - case CPL_TYPE_T: - { - CPL_TYPE * copybuft = (CPL_TYPE *)cpl_ifalloc_get(©buf); - if (nbadpix == 0) { - - /* All pixels are good */ - - /* Cannot fail here */ - (void)cpl_tools_copy_window((void*)copybuft, - image->pixels, - sizeof(CPL_TYPE), - image->nx, image->ny, - llxsz, llysz, urxsz, urysz); - - } else { - /* Point to first pixel in first row to read */ - const CPL_TYPE * pi = (const CPL_TYPE*)image->pixels - + (llysz-1)*image->nx; - - /* - ditto for bad pixel map */ - const cpl_binary * pbpm = badmap + (llysz-1)*image->nx; - cpl_size ngood = 0; - - for (j = llysz - 1; j < urysz; j++, pi += image->nx, pbpm += image->nx) { - for (i = llxsz - 1; i < urxsz; i++) { - /* Take only good pixels */ - if (pbpm[i] == CPL_BINARY_0) { - copybuft[ngood++] = pi[i]; - } +case CPL_TYPE_T: { + CPL_TYPE *copybuft = (CPL_TYPE *)cpl_ifalloc_get(©buf); + if (nbadpix == 0) { + /* All pixels are good */ + + /* Cannot fail here */ + (void)cpl_tools_copy_window((void *)copybuft, image->pixels, + sizeof(CPL_TYPE), image->nx, image->ny, + llxsz, llysz, urxsz, urysz); + } + else { + /* Point to first pixel in first row to read */ + const CPL_TYPE *pi = + (const CPL_TYPE *)image->pixels + (llysz - 1) * image->nx; + + /* - ditto for bad pixel map */ + const cpl_binary *pbpm = badmap + (llysz - 1) * image->nx; + cpl_size ngood = 0; + + for (j = llysz - 1; j < urysz; + j++, pi += image->nx, pbpm += image->nx) { + for (i = llxsz - 1; i < urxsz; i++) { + /* Take only good pixels */ + if (pbpm[i] == CPL_BINARY_0) { + copybuft[ngood++] = pi[i]; } } - /* assert( ngood == npix ) */ } + /* assert( ngood == npix ) */ + } - /* Compute the median */ - self->med = CPL_TYPE_ADD(cpl_tools_get_median)(copybuft, npix); + /* Compute the median */ + self->med = CPL_TYPE_ADD(cpl_tools_get_median)(copybuft, npix); - break; - } + break; +} #elif CPL_OPERATION == CPL_IMAGE_STATS_MEDIAN_DEV - case CPL_TYPE_T: - { - - /* Could be done in two FLOPs instead of three +case CPL_TYPE_T: { + /* Could be done in two FLOPs instead of three * - but this would lead to more complicated code... */ - if (nbadpix != 0) { - /* Need to check bad pixel buffer */ + if (nbadpix != 0) { + /* Need to check bad pixel buffer */ - /* Point to first pixel in first row to read */ - const CPL_TYPE * pi = (const CPL_TYPE*)image->pixels - + (llysz-1)*image->nx; - - /* - ditto for bad pixel map */ - const cpl_binary * pbpm = badmap + (llysz-1)*image->nx; - - for (j = llysz - 1; j < urysz; j++, pi += image->nx, pbpm += image->nx) { - for (i = llxsz - 1; i < urxsz; i++) { - /* Take only good pixels */ - if (pbpm[i] == CPL_BINARY_0) { - dev_sum += fabs((double)pi[i]-self->med); - } + /* Point to first pixel in first row to read */ + const CPL_TYPE *pi = + (const CPL_TYPE *)image->pixels + (llysz - 1) * image->nx; + + /* - ditto for bad pixel map */ + const cpl_binary *pbpm = badmap + (llysz - 1) * image->nx; + + for (j = llysz - 1; j < urysz; + j++, pi += image->nx, pbpm += image->nx) { + for (i = llxsz - 1; i < urxsz; i++) { + /* Take only good pixels */ + if (pbpm[i] == CPL_BINARY_0) { + dev_sum += fabs((double)pi[i] - self->med); } } - } else { - /* Point to first pixel in first row to read */ - const CPL_TYPE * pi = (const CPL_TYPE*)image->pixels - + (llysz-1)*image->nx; - - for (j = llysz - 1; j < urysz; j++, pi += image->nx) { - for (i = llxsz - 1; i < urxsz; i++) { - dev_sum += fabs((double)pi[i]-self->med); - } + } + } + else { + /* Point to first pixel in first row to read */ + const CPL_TYPE *pi = + (const CPL_TYPE *)image->pixels + (llysz - 1) * image->nx; + + for (j = llysz - 1; j < urysz; j++, pi += image->nx) { + for (i = llxsz - 1; i < urxsz; i++) { + dev_sum += fabs((double)pi[i] - self->med); } - } + } + } - cpl_tools_add_flops( 3 * npix + 1 ); + cpl_tools_add_flops(3 * npix + 1); - break; - } + break; +} #elif CPL_OPERATION == CPL_IMAGE_STATS_MAD - case CPL_TYPE_T: - { - CPL_TYPE * copybuft = (CPL_TYPE *)cpl_ifalloc_get(©buf); - cpl_size ngood = 0; - - - if (nbadpix != 0) { - /* Need to check bad pixel buffer */ - - /* Point to first pixel in first row to read */ - const CPL_TYPE * pi = (const CPL_TYPE*)image->pixels - + (llysz-1)*image->nx; - - /* - ditto for bad pixel map */ - const cpl_binary * pbpm = badmap + (llysz-1)*image->nx; - - for (j = llysz - 1; j < urysz; j++, pi += image->nx, pbpm += image->nx) { - for (i = llxsz - 1; i < urxsz; i++) { - /* Take only good pixels */ - if (pbpm[i] == CPL_BINARY_0) { - copybuft[ngood++] = fabs((double)pi[i]-self->med); - } +case CPL_TYPE_T: { + CPL_TYPE *copybuft = (CPL_TYPE *)cpl_ifalloc_get(©buf); + cpl_size ngood = 0; + + + if (nbadpix != 0) { + /* Need to check bad pixel buffer */ + + /* Point to first pixel in first row to read */ + const CPL_TYPE *pi = + (const CPL_TYPE *)image->pixels + (llysz - 1) * image->nx; + + /* - ditto for bad pixel map */ + const cpl_binary *pbpm = badmap + (llysz - 1) * image->nx; + + for (j = llysz - 1; j < urysz; + j++, pi += image->nx, pbpm += image->nx) { + for (i = llxsz - 1; i < urxsz; i++) { + /* Take only good pixels */ + if (pbpm[i] == CPL_BINARY_0) { + copybuft[ngood++] = fabs((double)pi[i] - self->med); } } - } else { - /* Point to first pixel in first row to read */ - const CPL_TYPE * pi = (const CPL_TYPE*)image->pixels - + (llysz-1)*image->nx; - - for (j = llysz - 1; j < urysz; j++, pi += image->nx) { - for (i = llxsz - 1; i < urxsz; i++) { - copybuft[ngood++] = fabs((double)pi[i]-self->med); - } + } + } + else { + /* Point to first pixel in first row to read */ + const CPL_TYPE *pi = + (const CPL_TYPE *)image->pixels + (llysz - 1) * image->nx; + + for (j = llysz - 1; j < urysz; j++, pi += image->nx) { + for (i = llxsz - 1; i < urxsz; i++) { + copybuft[ngood++] = fabs((double)pi[i] - self->med); } - } - /* assert( ngood == npix ) */ + } + } + /* assert( ngood == npix ) */ - cpl_tools_add_flops( 2 * npix ); + cpl_tools_add_flops(2 * npix); - /* Compute the median */ - self->mad = CPL_TYPE_ADD(cpl_tools_get_median)(copybuft, npix); + /* Compute the median */ + self->mad = CPL_TYPE_ADD(cpl_tools_get_median)(copybuft, npix); - break; - } + break; +} #endif diff -Nru cpl-7.1.4+ds/cplcore/cpl_stats.c cpl-7.2.2+ds/cplcore/cpl_stats.c --- cpl-7.1.4+ds/cplcore/cpl_stats.c 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_stats.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -47,34 +47,37 @@ Defines -----------------------------------------------------------------------------*/ -#define CPL_IMAGE_STATS_ALL 1 -#define CPL_IMAGE_STATS_MINMAX 2 -#define CPL_IMAGE_STATS_FLUX 3 -#define CPL_IMAGE_STATS_VARIANCE 4 -#define CPL_IMAGE_STATS_CENTROID 5 -#define CPL_IMAGE_STATS_MEDIAN 6 -#define CPL_IMAGE_STATS_MEDIAN_DEV 7 -#define CPL_IMAGE_STATS_MAD 8 +#define CPL_IMAGE_STATS_ALL 1 +#define CPL_IMAGE_STATS_MINMAX 2 +#define CPL_IMAGE_STATS_FLUX 3 +#define CPL_IMAGE_STATS_VARIANCE 4 +#define CPL_IMAGE_STATS_CENTROID 5 +#define CPL_IMAGE_STATS_MEDIAN 6 +#define CPL_IMAGE_STATS_MEDIAN_DEV 7 +#define CPL_IMAGE_STATS_MAD 8 -#define CONCAT(a,b) a ## _ ## b -#define CONCAT2X(a,b) CONCAT(a,b) +#define CONCAT(a, b) a##_##b +#define CONCAT2X(a, b) CONCAT(a, b) #define CPL_STATS_DUMP_ONE(OPERATOR, MEMBER, LABEL, CONVERTER) \ - if (mode & OPERATOR) { \ + if (mode & OPERATOR) { \ mode ^= OPERATOR; /* Reset bit. At the end mode must be zero */ \ - cpl_ensure_code(fprintf(stream, "\t\t%-13s%" CONVERTER "\n", LABEL ":", \ - self->MEMBER) > 0, CPL_ERROR_FILE_IO); \ + cpl_ensure_code(fprintf(stream, "\t\t%-13s%" CONVERTER "\n", \ + LABEL ":", self->MEMBER) > 0, \ + CPL_ERROR_FILE_IO); \ } #define CPL_STATS_DUMP_TWO(OPERATOR, MEMBER, LABEL, CONVERTER) \ - if (mode & OPERATOR) { \ + if (mode & OPERATOR) { \ mode ^= OPERATOR; /* Reset bit. At the end mode must be zero */ \ cpl_ensure_code(fprintf(stream, "\t\t%-13s%" CONVERTER "\n", \ - "X " LABEL ":", self->CONCAT2X(MEMBER, x)) \ - > 0, CPL_ERROR_FILE_IO); \ + "X " LABEL ":", \ + self->CONCAT2X(MEMBER, x)) > 0, \ + CPL_ERROR_FILE_IO); \ cpl_ensure_code(fprintf(stream, "\t\t%-13s%" CONVERTER "\n", \ - "Y " LABEL ":", self->CONCAT2X(MEMBER, y)) \ - > 0, CPL_ERROR_FILE_IO); \ + "Y " LABEL ":", \ + self->CONCAT2X(MEMBER, y)) > 0, \ + CPL_ERROR_FILE_IO); \ } /*----------------------------------------------------------------------------*/ @@ -115,9 +118,10 @@ - CPL_ERROR_ILLEGAL_INPUT if the requested stat has not been computed in in */ /*----------------------------------------------------------------------------*/ -double cpl_stats_get_min(const cpl_stats * in) +double +cpl_stats_get_min(const cpl_stats *in) { - cpl_ensure(in!=NULL, CPL_ERROR_NULL_INPUT, 0.0); + cpl_ensure(in != NULL, CPL_ERROR_NULL_INPUT, 0.0); cpl_ensure(in->mode & (CPL_STATS_MIN | CPL_STATS_MINPOS), CPL_ERROR_ILLEGAL_INPUT, 0); return in->min; @@ -131,9 +135,10 @@ @see cpl_stats_get_min() */ /*----------------------------------------------------------------------------*/ -double cpl_stats_get_max(const cpl_stats * in) +double +cpl_stats_get_max(const cpl_stats *in) { - cpl_ensure(in!=NULL, CPL_ERROR_NULL_INPUT, 0.0); + cpl_ensure(in != NULL, CPL_ERROR_NULL_INPUT, 0.0); cpl_ensure(in->mode & (CPL_STATS_MAX | CPL_STATS_MAXPOS), CPL_ERROR_ILLEGAL_INPUT, 0); return in->max; @@ -147,9 +152,10 @@ @see cpl_stats_get_min() */ /*----------------------------------------------------------------------------*/ -double cpl_stats_get_mean(const cpl_stats * in) +double +cpl_stats_get_mean(const cpl_stats *in) { - cpl_ensure(in!=NULL, CPL_ERROR_NULL_INPUT, 0.0); + cpl_ensure(in != NULL, CPL_ERROR_NULL_INPUT, 0.0); cpl_ensure(in->mode & CPL_STATS_MEAN, CPL_ERROR_ILLEGAL_INPUT, 0); return in->mean; } @@ -162,9 +168,10 @@ @see cpl_stats_get_min() */ /*----------------------------------------------------------------------------*/ -double cpl_stats_get_median(const cpl_stats * in) +double +cpl_stats_get_median(const cpl_stats *in) { - cpl_ensure(in!=NULL, CPL_ERROR_NULL_INPUT, 0.0); + cpl_ensure(in != NULL, CPL_ERROR_NULL_INPUT, 0.0); cpl_ensure(in->mode & CPL_STATS_MEDIAN, CPL_ERROR_ILLEGAL_INPUT, 0); return in->med; } @@ -177,9 +184,10 @@ @see cpl_stats_get_min() */ /*----------------------------------------------------------------------------*/ -double cpl_stats_get_median_dev(const cpl_stats * in) +double +cpl_stats_get_median_dev(const cpl_stats *in) { - cpl_ensure(in!=NULL, CPL_ERROR_NULL_INPUT, 0.0); + cpl_ensure(in != NULL, CPL_ERROR_NULL_INPUT, 0.0); cpl_ensure(in->mode & CPL_STATS_MEDIAN_DEV, CPL_ERROR_ILLEGAL_INPUT, 0.0); return in->med_dev; } @@ -192,9 +200,10 @@ @see cpl_stats_get_min() */ /*----------------------------------------------------------------------------*/ -double cpl_stats_get_mad(const cpl_stats * in) +double +cpl_stats_get_mad(const cpl_stats *in) { - cpl_ensure(in!=NULL, CPL_ERROR_NULL_INPUT, 0.0); + cpl_ensure(in != NULL, CPL_ERROR_NULL_INPUT, 0.0); cpl_ensure(in->mode & CPL_STATS_MAD, CPL_ERROR_ILLEGAL_INPUT, 0.0); return in->mad; } @@ -207,9 +216,10 @@ @see cpl_stats_get_min() */ /*----------------------------------------------------------------------------*/ -double cpl_stats_get_stdev(const cpl_stats * in) +double +cpl_stats_get_stdev(const cpl_stats *in) { - cpl_ensure(in!=NULL, CPL_ERROR_NULL_INPUT, -1); + cpl_ensure(in != NULL, CPL_ERROR_NULL_INPUT, -1); cpl_ensure(in->mode & CPL_STATS_STDEV, CPL_ERROR_ILLEGAL_INPUT, 0); return in->stdev; } @@ -222,9 +232,10 @@ @see cpl_stats_get_min() */ /*----------------------------------------------------------------------------*/ -double cpl_stats_get_flux(const cpl_stats * in) +double +cpl_stats_get_flux(const cpl_stats *in) { - cpl_ensure(in!=NULL, CPL_ERROR_NULL_INPUT, 0.0); + cpl_ensure(in != NULL, CPL_ERROR_NULL_INPUT, 0.0); cpl_ensure(in->mode & CPL_STATS_FLUX, CPL_ERROR_ILLEGAL_INPUT, 0); return in->flux; } @@ -237,9 +248,10 @@ @see cpl_stats_get_min() */ /*----------------------------------------------------------------------------*/ -double cpl_stats_get_absflux(const cpl_stats * in) +double +cpl_stats_get_absflux(const cpl_stats *in) { - cpl_ensure(in!=NULL, CPL_ERROR_NULL_INPUT, -1); + cpl_ensure(in != NULL, CPL_ERROR_NULL_INPUT, -1); cpl_ensure(in->mode & CPL_STATS_ABSFLUX, CPL_ERROR_ILLEGAL_INPUT, -2); return in->absflux; } @@ -252,9 +264,10 @@ @see cpl_stats_get_min() */ /*----------------------------------------------------------------------------*/ -double cpl_stats_get_sqflux(const cpl_stats * in) +double +cpl_stats_get_sqflux(const cpl_stats *in) { - cpl_ensure(in!=NULL, CPL_ERROR_NULL_INPUT, -1); + cpl_ensure(in != NULL, CPL_ERROR_NULL_INPUT, -1); cpl_ensure(in->mode & CPL_STATS_SQFLUX, CPL_ERROR_ILLEGAL_INPUT, -2); return in->sqflux; } @@ -267,11 +280,11 @@ @see cpl_stats_get_min() */ /*----------------------------------------------------------------------------*/ -double cpl_stats_get_centroid_x(const cpl_stats * in) +double +cpl_stats_get_centroid_x(const cpl_stats *in) { - cpl_ensure(in!=NULL, CPL_ERROR_NULL_INPUT, 0.0); - cpl_ensure(in->mode & CPL_STATS_CENTROID, CPL_ERROR_ILLEGAL_INPUT, - 0); + cpl_ensure(in != NULL, CPL_ERROR_NULL_INPUT, 0.0); + cpl_ensure(in->mode & CPL_STATS_CENTROID, CPL_ERROR_ILLEGAL_INPUT, 0); return in->centroid_x; } @@ -283,11 +296,11 @@ @see cpl_stats_get_min() */ /*----------------------------------------------------------------------------*/ -double cpl_stats_get_centroid_y(const cpl_stats * in) +double +cpl_stats_get_centroid_y(const cpl_stats *in) { - cpl_ensure(in!=NULL, CPL_ERROR_NULL_INPUT, 0.0); - cpl_ensure(in->mode & CPL_STATS_CENTROID, CPL_ERROR_ILLEGAL_INPUT, - 0); + cpl_ensure(in != NULL, CPL_ERROR_NULL_INPUT, 0.0); + cpl_ensure(in->mode & CPL_STATS_CENTROID, CPL_ERROR_ILLEGAL_INPUT, 0); return in->centroid_y; } @@ -301,9 +314,10 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_stats_get_min_x(const cpl_stats * in) +cpl_size +cpl_stats_get_min_x(const cpl_stats *in) { - cpl_ensure(in!=NULL, CPL_ERROR_NULL_INPUT, -1); + cpl_ensure(in != NULL, CPL_ERROR_NULL_INPUT, -1); cpl_ensure(in->mode & (CPL_STATS_MIN | CPL_STATS_MINPOS), CPL_ERROR_ILLEGAL_INPUT, 0); return in->min_x; @@ -319,9 +333,10 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_stats_get_min_y(const cpl_stats * in) +cpl_size +cpl_stats_get_min_y(const cpl_stats *in) { - cpl_ensure(in!=NULL, CPL_ERROR_NULL_INPUT, -1); + cpl_ensure(in != NULL, CPL_ERROR_NULL_INPUT, -1); cpl_ensure(in->mode & (CPL_STATS_MIN | CPL_STATS_MINPOS), CPL_ERROR_ILLEGAL_INPUT, 0); return in->min_y; @@ -337,9 +352,10 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_stats_get_max_x(const cpl_stats * in) +cpl_size +cpl_stats_get_max_x(const cpl_stats *in) { - cpl_ensure(in!=NULL, CPL_ERROR_NULL_INPUT, -1); + cpl_ensure(in != NULL, CPL_ERROR_NULL_INPUT, -1); cpl_ensure(in->mode & (CPL_STATS_MAX | CPL_STATS_MAXPOS), CPL_ERROR_ILLEGAL_INPUT, 0); return in->max_x; @@ -355,9 +371,10 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_stats_get_max_y(const cpl_stats * in) +cpl_size +cpl_stats_get_max_y(const cpl_stats *in) { - cpl_ensure(in!=NULL, CPL_ERROR_NULL_INPUT, -1); + cpl_ensure(in != NULL, CPL_ERROR_NULL_INPUT, -1); cpl_ensure(in->mode & (CPL_STATS_MAX | CPL_STATS_MAXPOS), CPL_ERROR_ILLEGAL_INPUT, 0); return in->max_y; @@ -376,9 +393,10 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_stats_get_npix(const cpl_stats * in) +cpl_size +cpl_stats_get_npix(const cpl_stats *in) { - cpl_ensure(in!=NULL, CPL_ERROR_NULL_INPUT, -1); + cpl_ensure(in != NULL, CPL_ERROR_NULL_INPUT, -1); return in->npix; } @@ -392,9 +410,11 @@ is @c NULL, nothing is done and no error is set. */ /*----------------------------------------------------------------------------*/ -void cpl_stats_delete(cpl_stats * stats) +void +cpl_stats_delete(cpl_stats *stats) { - if (stats == NULL) return; + if (stats == NULL) + return; cpl_free(stats); } @@ -464,16 +484,16 @@ allowed options. */ /*----------------------------------------------------------------------------*/ -cpl_stats * cpl_stats_new_from_image_window( - const cpl_image * image, - cpl_stats_mode mode, - cpl_size llx, - cpl_size lly, - cpl_size urx, - cpl_size ury) +cpl_stats * +cpl_stats_new_from_image_window(const cpl_image *image, + cpl_stats_mode mode, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury) { /* Allocate stat object */ - cpl_stats * self = cpl_malloc(sizeof(cpl_stats)); + cpl_stats *self = cpl_malloc(sizeof(cpl_stats)); const cpl_error_code code = cpl_stats_fill_from_image_window(self, image, mode, llx, lly, urx, ury); @@ -497,9 +517,10 @@ @see cpl_stats_new_from_image_window() */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_stats_fill_from_image(cpl_stats * self, - const cpl_image * image, - cpl_stats_mode mode) +cpl_error_code +cpl_stats_fill_from_image(cpl_stats *self, + const cpl_image *image, + cpl_stats_mode mode) { const cpl_error_code code = cpl_stats_fill_from_image_window(self, image, mode, 1, 1, @@ -524,59 +545,60 @@ @see cpl_stats_new_from_image_window() */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_stats_fill_from_image_window(cpl_stats * self, - const cpl_image * image, - cpl_stats_mode mode, - cpl_size llx, - cpl_size lly, - cpl_size urx, - cpl_size ury) +cpl_error_code +cpl_stats_fill_from_image_window(cpl_stats *self, + const cpl_image *image, + cpl_stats_mode mode, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury) { const size_t llxsz = (size_t)llx; const size_t llysz = (size_t)lly; const size_t urxsz = (size_t)urx; const size_t urysz = (size_t)ury; - double pix_sum = 0.0; - double sqr_sum = 0.0; - double abs_sum = 0.0; - double dev_sum = 0.0; - double pix_mean = 0.0; - double pix_var = 0.0; /* The accumulated variance sum */ - double max_pix = DBL_MAX; /* Avoid (false) uninit warning */ - double min_pix = DBL_MAX; /* Avoid (false) uninit warning */ - cpl_size max_pos = -1; /* Avoid (false) uninit warning */ - cpl_size min_pos = -1; /* Avoid (false) uninit warning */ - double ipix = 0.0; /* Counter of pixels used */ - cpl_size npix; - const cpl_size mpix = (urx-llx+1) * (ury-lly+1); - cpl_size pos; - cpl_ifalloc copybuf; + double pix_sum = 0.0; + double sqr_sum = 0.0; + double abs_sum = 0.0; + double dev_sum = 0.0; + double pix_mean = 0.0; + double pix_var = 0.0; /* The accumulated variance sum */ + double max_pix = DBL_MAX; /* Avoid (false) uninit warning */ + double min_pix = DBL_MAX; /* Avoid (false) uninit warning */ + cpl_size max_pos = -1; /* Avoid (false) uninit warning */ + cpl_size min_pos = -1; /* Avoid (false) uninit warning */ + double ipix = 0.0; /* Counter of pixels used */ + cpl_size npix; + const cpl_size mpix = (urx - llx + 1) * (ury - lly + 1); + cpl_size pos; + cpl_ifalloc copybuf; /* Two statistics computation categories defined here */ - const cpl_stats_mode minmax_cat = mode & - (CPL_STATS_MIN|CPL_STATS_MAX|CPL_STATS_MINPOS| - CPL_STATS_MAXPOS|CPL_STATS_CENTROID); - const cpl_stats_mode flux_cat = mode & - (CPL_STATS_FLUX | CPL_STATS_ABSFLUX | CPL_STATS_SQFLUX); - const cpl_stats_mode variance_cat = mode & - (CPL_STATS_MEAN | CPL_STATS_STDEV); + const cpl_stats_mode minmax_cat = + mode & (CPL_STATS_MIN | CPL_STATS_MAX | CPL_STATS_MINPOS | + CPL_STATS_MAXPOS | CPL_STATS_CENTROID); + const cpl_stats_mode flux_cat = + mode & (CPL_STATS_FLUX | CPL_STATS_ABSFLUX | CPL_STATS_SQFLUX); + const cpl_stats_mode variance_cat = + mode & (CPL_STATS_MEAN | CPL_STATS_STDEV); /* Index of 1st good pixel - used for initialization */ - cpl_size firstgoodpos; + cpl_size firstgoodpos; /* The number of bad pixels inside the subwindow */ - cpl_size nbadpix; + cpl_size nbadpix; /* A map of the the bad pixels in the input */ - const cpl_binary * badmap; - size_t i, j; + const cpl_binary *badmap; + size_t i, j; /* Test inputs */ - cpl_ensure_code(image != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(image != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(llx > 0, CPL_ERROR_ACCESS_OUT_OF_RANGE); - cpl_ensure_code(lly > 0, CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_ensure_code(llx > 0, CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_ensure_code(lly > 0, CPL_ERROR_ACCESS_OUT_OF_RANGE); cpl_ensure_code(urx <= image->nx, CPL_ERROR_ACCESS_OUT_OF_RANGE); cpl_ensure_code(ury <= image->ny, CPL_ERROR_ACCESS_OUT_OF_RANGE); - cpl_ensure_code(llx <= urx, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(lly <= ury, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(llx <= urx, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(lly <= ury, CPL_ERROR_ILLEGAL_INPUT); cpl_ensure_code(mode != 1, CPL_ERROR_INVALID_TYPE); cpl_ensure_code(mode != 0, CPL_ERROR_UNSUPPORTED_MODE); @@ -592,14 +614,15 @@ /* Get the first good pixel and the number of bad pixels */ nbadpix = 0; if (badmap != NULL) { - const cpl_binary * bpmj1 = badmap + (lly-1) * image->nx - 1; + const cpl_binary *bpmj1 = badmap + (lly - 1) * image->nx - 1; firstgoodpos = -1; for (j = llysz; j < 1 + urysz; j++, bpmj1 += image->nx) { for (i = llxsz; i < 1 + urxsz; i++) { if (bpmj1[i] == CPL_BINARY_1) { nbadpix++; - } else if (firstgoodpos < 0) { + } + else if (firstgoodpos < 0) { firstgoodpos = (i - 1) + (j - 1) * image->nx; } } @@ -607,9 +630,9 @@ /* Verify that there are good pixels */ cpl_ensure_code(firstgoodpos >= 0, CPL_ERROR_DATA_NOT_FOUND); - - } else { - firstgoodpos = (llx-1)+(lly-1)*image->nx; + } + else { + firstgoodpos = (llx - 1) + (lly - 1) * image->nx; } npix = mpix - nbadpix; @@ -627,7 +650,7 @@ (size_t)npix * cpl_type_get_sizeof(image->type)); switch (image->type) { #define CPL_OPERATION CPL_IMAGE_STATS_MEDIAN -#define CPL_CLASS CPL_CLASS_DOUBLE +#define CPL_CLASS CPL_CLASS_DOUBLE #include "cpl_stats_body.h" #undef CPL_CLASS #define CPL_CLASS CPL_CLASS_FLOAT @@ -637,12 +660,13 @@ #include "cpl_stats_body.h" #undef CPL_CLASS #undef CPL_OPERATION - default: - /* See comment in previous switch() default: */ - cpl_ifalloc_free(©buf); - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + default: + /* See comment in previous switch() default: */ + cpl_ifalloc_free(©buf); + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } - } else { + } + else { cpl_ifalloc_set(©buf, 0); /* Initialize for deallocation */ } @@ -650,7 +674,7 @@ /* Switch on image type */ switch (image->type) { #define CPL_OPERATION CPL_IMAGE_STATS_ALL -#define CPL_CLASS CPL_CLASS_DOUBLE +#define CPL_CLASS CPL_CLASS_DOUBLE #include "cpl_stats_body.h" #undef CPL_CLASS #define CPL_CLASS CPL_CLASS_FLOAT @@ -660,8 +684,8 @@ #include "cpl_stats_body.h" #undef CPL_CLASS #undef CPL_OPERATION - default: - /* + default: + /* * Currently, it is an error in CPL to reach this point, as all * possible types for images (see cpl_image_new()) are supported. * @@ -670,16 +694,16 @@ * in this function. For that case, we keep setting the appropriate * error code in this default section. */ - cpl_ifalloc_free(©buf); - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + cpl_ifalloc_free(©buf); + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } - - } else { + } + else { if (minmax_cat) { /* Switch on image type */ switch (image->type) { #define CPL_OPERATION CPL_IMAGE_STATS_MINMAX -#define CPL_CLASS CPL_CLASS_DOUBLE +#define CPL_CLASS CPL_CLASS_DOUBLE #include "cpl_stats_body.h" #undef CPL_CLASS #define CPL_CLASS CPL_CLASS_FLOAT @@ -689,18 +713,17 @@ #include "cpl_stats_body.h" #undef CPL_CLASS #undef CPL_OPERATION - default: - /* See comment in previous switch() default: */ - cpl_ifalloc_free(©buf); - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + default: + /* See comment in previous switch() default: */ + cpl_ifalloc_free(©buf); + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } - } if (flux_cat) { /* Switch on image type */ switch (image->type) { #define CPL_OPERATION CPL_IMAGE_STATS_FLUX -#define CPL_CLASS CPL_CLASS_DOUBLE +#define CPL_CLASS CPL_CLASS_DOUBLE #include "cpl_stats_body.h" #undef CPL_CLASS #define CPL_CLASS CPL_CLASS_FLOAT @@ -710,17 +733,17 @@ #include "cpl_stats_body.h" #undef CPL_CLASS #undef CPL_OPERATION - default: - /* See comment in previous switch() default: */ - cpl_ifalloc_free(©buf); - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + default: + /* See comment in previous switch() default: */ + cpl_ifalloc_free(©buf); + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } } if (variance_cat) { /* Switch on image type */ switch (image->type) { #define CPL_OPERATION CPL_IMAGE_STATS_VARIANCE -#define CPL_CLASS CPL_CLASS_DOUBLE +#define CPL_CLASS CPL_CLASS_DOUBLE #include "cpl_stats_body.h" #undef CPL_CLASS #define CPL_CLASS CPL_CLASS_FLOAT @@ -730,17 +753,17 @@ #include "cpl_stats_body.h" #undef CPL_CLASS #undef CPL_OPERATION - default: - /* See comment in previous switch() default: */ - cpl_ifalloc_free(©buf); - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + default: + /* See comment in previous switch() default: */ + cpl_ifalloc_free(©buf); + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } } if (mode & CPL_STATS_MEDIAN_DEV) { switch (image->type) { #define CPL_OPERATION CPL_IMAGE_STATS_MEDIAN_DEV -#define CPL_CLASS CPL_CLASS_DOUBLE +#define CPL_CLASS CPL_CLASS_DOUBLE #include "cpl_stats_body.h" #undef CPL_CLASS #define CPL_CLASS CPL_CLASS_FLOAT @@ -750,17 +773,17 @@ #include "cpl_stats_body.h" #undef CPL_CLASS #undef CPL_OPERATION - default: - /* See comment in previous switch() default: */ - cpl_ifalloc_free(©buf); - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + default: + /* See comment in previous switch() default: */ + cpl_ifalloc_free(©buf); + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } } } if (mode & CPL_STATS_MAD) { switch (image->type) { #define CPL_OPERATION CPL_IMAGE_STATS_MAD -#define CPL_CLASS CPL_CLASS_DOUBLE +#define CPL_CLASS CPL_CLASS_DOUBLE #include "cpl_stats_body.h" #undef CPL_CLASS #define CPL_CLASS CPL_CLASS_FLOAT @@ -770,33 +793,35 @@ #include "cpl_stats_body.h" #undef CPL_CLASS #undef CPL_OPERATION - default: - /* See comment in previous switch() default: */ - cpl_ifalloc_free(©buf); - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + default: + /* See comment in previous switch() default: */ + cpl_ifalloc_free(©buf); + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } } - if (mode & CPL_STATS_MIN) self->min = min_pix; - if (mode & CPL_STATS_MAX) self->max = max_pix; - if (mode & CPL_STATS_MEAN) self->mean = pix_mean; - - if (mode &CPL_STATS_STDEV) { + if (mode & CPL_STATS_MIN) + self->min = min_pix; + if (mode & CPL_STATS_MAX) + self->max = max_pix; + if (mode & CPL_STATS_MEAN) + self->mean = pix_mean; + if (mode & CPL_STATS_STDEV) { /* Compute the bias-corrected standard deviation. */ - self->stdev = npix < 2 ? 0.0 : sqrt(pix_var/(double)(npix-1)); + self->stdev = npix < 2 ? 0.0 : sqrt(pix_var / (double)(npix - 1)); } - if (mode &CPL_STATS_CENTROID) { - double sum_xz = 0.0; - double sum_yz = 0.0; - double sum_z = 0.0; - double sum_x = 0.0; - double sum_y = 0.0; + if (mode & CPL_STATS_CENTROID) { + double sum_xz = 0.0; + double sum_yz = 0.0; + double sum_z = 0.0; + double sum_x = 0.0; + double sum_y = 0.0; switch (image->type) { #define CPL_OPERATION CPL_IMAGE_STATS_CENTROID -#define CPL_CLASS CPL_CLASS_DOUBLE +#define CPL_CLASS CPL_CLASS_DOUBLE #include "cpl_stats_body.h" #undef CPL_CLASS #define CPL_CLASS CPL_CLASS_FLOAT @@ -806,15 +831,16 @@ #include "cpl_stats_body.h" #undef CPL_CLASS #undef CPL_OPERATION - default: - /* See comment in previous switch() default: */ - cpl_ifalloc_free(©buf); - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + default: + /* See comment in previous switch() default: */ + cpl_ifalloc_free(©buf); + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } if (sum_z > 0.0) { - self->centroid_x = sum_xz / sum_z; - self->centroid_y = sum_yz / sum_z; - } else { + self->centroid_x = sum_xz / sum_z; + self->centroid_y = sum_yz / sum_z; + } + else { self->centroid_x = sum_x / (double)npix; self->centroid_y = sum_y / (double)npix; } @@ -826,33 +852,39 @@ e.g. when lly == ury */ if (self->centroid_x < (double)llx) { - assert( (double)llx - self->centroid_x < FLT_EPSILON ); + assert((double)llx - self->centroid_x < FLT_EPSILON); self->centroid_x = (double)llx; - } else if (self->centroid_x > (double)urx) { - assert( self->centroid_x - (double)urx < FLT_EPSILON ); + } + else if (self->centroid_x > (double)urx) { + assert(self->centroid_x - (double)urx < FLT_EPSILON); self->centroid_x = (double)urx; } if (self->centroid_y < (double)lly) { - assert( (double)lly - self->centroid_y < FLT_EPSILON ); + assert((double)lly - self->centroid_y < FLT_EPSILON); self->centroid_y = (double)lly; - } else if (self->centroid_y > (double)ury) { - assert( self->centroid_y - (double)ury < FLT_EPSILON ); + } + else if (self->centroid_y > (double)ury) { + assert(self->centroid_y - (double)ury < FLT_EPSILON); self->centroid_y = (double)ury; } } - if (mode &CPL_STATS_FLUX) self->flux = pix_sum; - if (mode &CPL_STATS_ABSFLUX) self->absflux = abs_sum; - if (mode &CPL_STATS_SQFLUX) self->sqflux = sqr_sum; - if (mode &CPL_STATS_MINPOS) { + if (mode & CPL_STATS_FLUX) + self->flux = pix_sum; + if (mode & CPL_STATS_ABSFLUX) + self->absflux = abs_sum; + if (mode & CPL_STATS_SQFLUX) + self->sqflux = sqr_sum; + if (mode & CPL_STATS_MINPOS) { self->min_x = 1 + min_pos % image->nx; self->min_y = 1 + min_pos / image->nx; } - if (mode &CPL_STATS_MAXPOS) { + if (mode & CPL_STATS_MAXPOS) { self->max_x = 1 + max_pos % image->nx; self->max_y = 1 + max_pos / image->nx; } - if (mode & CPL_STATS_MEDIAN_DEV) self->med_dev = dev_sum / (double) npix; + if (mode & CPL_STATS_MEDIAN_DEV) + self->med_dev = dev_sum / (double)npix; cpl_ifalloc_free(©buf); return CPL_ERROR_NONE; @@ -867,17 +899,18 @@ @see cpl_stats_new_from_image_window() */ /*----------------------------------------------------------------------------*/ -cpl_stats * cpl_stats_new_from_image(const cpl_image * image, - cpl_stats_mode mode) +cpl_stats * +cpl_stats_new_from_image(const cpl_image *image, cpl_stats_mode mode) { - cpl_stats * self; + cpl_stats *self; cpl_ensure(image != NULL, CPL_ERROR_NULL_INPUT, NULL); self = cpl_stats_new_from_image_window(image, mode, 1, 1, image->nx, image->ny); /* Propagate error, if any */ - if (self == NULL) (void)cpl_error_set_where_(); + if (self == NULL) + (void)cpl_error_set_where_(); return self; } @@ -900,39 +933,35 @@ - CPL_ERROR_FILE_IO if the write fails */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_stats_dump(const cpl_stats * self, - cpl_stats_mode mode, - FILE * stream) +cpl_error_code +cpl_stats_dump(const cpl_stats *self, cpl_stats_mode mode, FILE *stream) { - - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(stream != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code((mode & ~self->mode) == 0, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code( fprintf(stream, "\t\tPixel count: %" CPL_SIZE_FORMAT "\n", - self->npix) >0, CPL_ERROR_FILE_IO); - - CPL_STATS_DUMP_ONE(CPL_STATS_MIN, min, "Min", ".8g"); - CPL_STATS_DUMP_ONE(CPL_STATS_MAX, max, "Max", ".8g"); - CPL_STATS_DUMP_ONE(CPL_STATS_MEAN, mean, "Mean", ".8g"); - CPL_STATS_DUMP_ONE(CPL_STATS_MEDIAN, med, "Median", ".8g"); - CPL_STATS_DUMP_ONE(CPL_STATS_MEDIAN_DEV, med_dev, "Median dev", ".8g"); - CPL_STATS_DUMP_ONE(CPL_STATS_MAD, mad, "MAD", ".8g"); - CPL_STATS_DUMP_ONE(CPL_STATS_STDEV, stdev, "Std. dev", ".8g"); - CPL_STATS_DUMP_ONE(CPL_STATS_FLUX, flux, "Flux", ".8g"); - CPL_STATS_DUMP_ONE(CPL_STATS_ABSFLUX, absflux, "Abs flux", ".8g"); - CPL_STATS_DUMP_ONE(CPL_STATS_SQFLUX, sqflux, "Sq. flux", ".8g"); - - CPL_STATS_DUMP_TWO(CPL_STATS_CENTROID, centroid, "centroid", ".8g"); - CPL_STATS_DUMP_TWO(CPL_STATS_MINPOS, min, "min. pos.", - CPL_SIZE_FORMAT); - CPL_STATS_DUMP_TWO(CPL_STATS_MAXPOS, max, "max. pos.", - CPL_SIZE_FORMAT); + cpl_ensure_code(fprintf(stream, "\t\tPixel count: %" CPL_SIZE_FORMAT "\n", + self->npix) > 0, + CPL_ERROR_FILE_IO); + + CPL_STATS_DUMP_ONE(CPL_STATS_MIN, min, "Min", ".8g"); + CPL_STATS_DUMP_ONE(CPL_STATS_MAX, max, "Max", ".8g"); + CPL_STATS_DUMP_ONE(CPL_STATS_MEAN, mean, "Mean", ".8g"); + CPL_STATS_DUMP_ONE(CPL_STATS_MEDIAN, med, "Median", ".8g"); + CPL_STATS_DUMP_ONE(CPL_STATS_MEDIAN_DEV, med_dev, "Median dev", ".8g"); + CPL_STATS_DUMP_ONE(CPL_STATS_MAD, mad, "MAD", ".8g"); + CPL_STATS_DUMP_ONE(CPL_STATS_STDEV, stdev, "Std. dev", ".8g"); + CPL_STATS_DUMP_ONE(CPL_STATS_FLUX, flux, "Flux", ".8g"); + CPL_STATS_DUMP_ONE(CPL_STATS_ABSFLUX, absflux, "Abs flux", ".8g"); + CPL_STATS_DUMP_ONE(CPL_STATS_SQFLUX, sqflux, "Sq. flux", ".8g"); + + CPL_STATS_DUMP_TWO(CPL_STATS_CENTROID, centroid, "centroid", ".8g"); + CPL_STATS_DUMP_TWO(CPL_STATS_MINPOS, min, "min. pos.", CPL_SIZE_FORMAT); + CPL_STATS_DUMP_TWO(CPL_STATS_MAXPOS, max, "max. pos.", CPL_SIZE_FORMAT); /* Failure here means a new member has been added, without dump support */ return mode ? cpl_error_set_(CPL_ERROR_UNSUPPORTED_MODE) : CPL_ERROR_NONE; } /**@}*/ - diff -Nru cpl-7.1.4+ds/cplcore/cpl_stats_defs.h cpl-7.2.2+ds/cplcore/cpl_stats_defs.h --- cpl-7.1.4+ds/cplcore/cpl_stats_defs.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_stats_defs.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -35,23 +35,23 @@ -----------------------------------------------------------------------------*/ struct _cpl_stats_ { - double min; - double max; - double mean; - double med; - double med_dev; - double mad; - double stdev; - double flux; - double absflux; - double sqflux; - double centroid_x; - double centroid_y; - cpl_size min_x; - cpl_size min_y; - cpl_size max_x; - cpl_size max_y; - cpl_size npix; + double min; + double max; + double mean; + double med; + double med_dev; + double mad; + double stdev; + double flux; + double absflux; + double sqflux; + double centroid_x; + double centroid_y; + cpl_size min_x; + cpl_size min_y; + cpl_size max_x; + cpl_size max_y; + cpl_size npix; cpl_stats_mode mode; }; diff -Nru cpl-7.1.4+ds/cplcore/cpl_stats.h cpl-7.2.2+ds/cplcore/cpl_stats.h --- cpl-7.1.4+ds/cplcore/cpl_stats.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_stats.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -46,80 +46,81 @@ * The values can be combined with bitwise or. */ -enum _cpl_stats_mode_ { +enum _cpl_stats_mode_ +{ -/* No mode has the value 1, which makes the (mis)use of logical or detectable */ + /* No mode has the value 1, which makes the (mis)use of logical or detectable */ /** * The minimum * @hideinitializer */ - CPL_STATS_MIN = 1 << 1, + CPL_STATS_MIN = 1 << 1, /** * The maximum * @hideinitializer */ - CPL_STATS_MAX = 1 << 2, + CPL_STATS_MAX = 1 << 2, /** * The mean * @hideinitializer */ - CPL_STATS_MEAN = 1 << 3, + CPL_STATS_MEAN = 1 << 3, /** * The median * @hideinitializer */ - CPL_STATS_MEDIAN = 1 << 4, + CPL_STATS_MEDIAN = 1 << 4, /** * The standard deviation * @hideinitializer */ - CPL_STATS_STDEV = 1 << 5, + CPL_STATS_STDEV = 1 << 5, /** * The flux * @hideinitializer */ - CPL_STATS_FLUX = 1 << 6, + CPL_STATS_FLUX = 1 << 6, /** * The absolute flux * @hideinitializer */ - CPL_STATS_ABSFLUX = 1 << 7, + CPL_STATS_ABSFLUX = 1 << 7, /** * The square flux * @hideinitializer */ - CPL_STATS_SQFLUX = 1 << 8, + CPL_STATS_SQFLUX = 1 << 8, /** * The position of the minimum * @hideinitializer */ - CPL_STATS_MINPOS = 1 << 9, + CPL_STATS_MINPOS = 1 << 9, /** * The position of the maximum * @hideinitializer */ - CPL_STATS_MAXPOS = 1 << 10, + CPL_STATS_MAXPOS = 1 << 10, /** * The centroid position * @hideinitializer */ - CPL_STATS_CENTROID = 1 << 11, + CPL_STATS_CENTROID = 1 << 11, /** * The mean of the absolute median deviation * @hideinitializer */ - CPL_STATS_MEDIAN_DEV = 1 << 12, + CPL_STATS_MEDIAN_DEV = 1 << 12, /** * The median of the absolute median deviation * @hideinitializer */ - CPL_STATS_MAD = 1 << 13, + CPL_STATS_MAD = 1 << 13, /** * All of the above * @hideinitializer */ - CPL_STATS_ALL = (1 << 14)-2 + CPL_STATS_ALL = (1 << 14) - 2 }; @@ -163,13 +164,16 @@ void cpl_stats_delete(cpl_stats *); /* Statistics computations */ -cpl_stats * cpl_stats_new_from_image(const cpl_image *, - cpl_stats_mode) CPL_ATTR_ALLOC; -cpl_stats * cpl_stats_new_from_image_window(const cpl_image *, cpl_stats_mode, - cpl_size, cpl_size, cpl_size, - cpl_size) CPL_ATTR_ALLOC; +cpl_stats * +cpl_stats_new_from_image(const cpl_image *, cpl_stats_mode) CPL_ATTR_ALLOC; +cpl_stats *cpl_stats_new_from_image_window(const cpl_image *, + cpl_stats_mode, + cpl_size, + cpl_size, + cpl_size, + cpl_size) CPL_ATTR_ALLOC; cpl_error_code cpl_stats_dump(const cpl_stats *, cpl_stats_mode, FILE *); CPL_END_DECLS -#endif +#endif diff -Nru cpl-7.1.4+ds/cplcore/cpl_stats_impl.h cpl-7.2.2+ds/cplcore/cpl_stats_impl.h --- cpl-7.1.4+ds/cplcore/cpl_stats_impl.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_stats_impl.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -24,15 +24,16 @@ CPL_BEGIN_DECLS -cpl_error_code cpl_stats_fill_from_image(cpl_stats *, const cpl_image *, - cpl_stats_mode) - CPL_INTERNAL -; -cpl_error_code cpl_stats_fill_from_image_window(cpl_stats *, const cpl_image *, - cpl_stats_mode, cpl_size, - cpl_size, cpl_size, cpl_size) - CPL_INTERNAL -; +cpl_error_code cpl_stats_fill_from_image(cpl_stats *, + const cpl_image *, + cpl_stats_mode) CPL_INTERNAL; +cpl_error_code cpl_stats_fill_from_image_window(cpl_stats *, + const cpl_image *, + cpl_stats_mode, + cpl_size, + cpl_size, + cpl_size, + cpl_size) CPL_INTERNAL; CPL_END_DECLS diff -Nru cpl-7.1.4+ds/cplcore/cpl_table.c cpl-7.2.2+ds/cplcore/cpl_table.c --- cpl-7.1.4+ds/cplcore/cpl_table.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_table.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -18,11 +18,12 @@ */ #ifdef HAVE_CONFIG_H -# include +#include #endif -#define ERASE_WCS_REGEXP "WCSAXES|WCSNAME|(PC|CD|PV|PS)[0-9]+_[0-9]+|" \ - "C(RVAL|RPIX|DELT|TYPE|UNIT|RDER|SYER)[0-9]+" +#define ERASE_WCS_REGEXP \ + "WCSAXES|WCSNAME|(PC|CD|PV|PS)[0-9]+_[0-9]+|" \ + "C(RVAL|RPIX|DELT|TYPE|UNIT|RDER|SYER)[0-9]+" #include #include @@ -103,16 +104,17 @@ * The table type; */ -struct _cpl_table_ { - cpl_size nc; - cpl_size nr; - cpl_column **columns; +struct _cpl_table_ +{ + cpl_size nc; + cpl_size nr; + cpl_column **columns; cpl_column_flag *select; - cpl_size selectcount; + cpl_size selectcount; }; - /* +/* * Prototypes for CPL_TYPE_LONG columns. Support for this type is implemented, * but disabled, since the FITS standard has no counterpart for this type. * This means that on saving a column of this type it needs to be converted @@ -127,23 +129,27 @@ cpl_error_code cpl_table_wrap_long(cpl_table *, long *, const char *) CPL_INTERNAL; long *cpl_table_get_data_long(cpl_table *, const char *name) CPL_INTERNAL; -const long *cpl_table_get_data_long_const(const cpl_table *, - const char *name) CPL_INTERNAL; -long cpl_table_get_long(const cpl_table *, const char *, cpl_size, - int *null) CPL_INTERNAL; -cpl_error_code cpl_table_set_long(cpl_table *, const char *, - cpl_size, long) CPL_INTERNAL; -cpl_error_code cpl_table_fill_column_window_long(cpl_table *, const char *, - cpl_size, cpl_size, +const long * +cpl_table_get_data_long_const(const cpl_table *, const char *name) CPL_INTERNAL; +long cpl_table_get_long(const cpl_table *, const char *, cpl_size, int *null) + CPL_INTERNAL; +cpl_error_code +cpl_table_set_long(cpl_table *, const char *, cpl_size, long) CPL_INTERNAL; +cpl_error_code cpl_table_fill_column_window_long(cpl_table *, + const char *, + cpl_size, + cpl_size, long) CPL_INTERNAL; -cpl_error_code cpl_table_copy_data_long(cpl_table *, const char *, - const long *) CPL_INTERNAL; -cpl_error_code cpl_table_fill_invalid_long(cpl_table *, const char *, - long) CPL_INTERNAL; -cpl_size cpl_table_and_selected_long(cpl_table *, const char *, +cpl_error_code +cpl_table_copy_data_long(cpl_table *, const char *, const long *) CPL_INTERNAL; +cpl_error_code +cpl_table_fill_invalid_long(cpl_table *, const char *, long) CPL_INTERNAL; +cpl_size cpl_table_and_selected_long(cpl_table *, + const char *, cpl_table_select_operator, long) CPL_INTERNAL; -cpl_size cpl_table_or_selected_long(cpl_table *, const char *, +cpl_size cpl_table_or_selected_long(cpl_table *, + const char *, cpl_table_select_operator, long) CPL_INTERNAL; @@ -153,23 +159,19 @@ static cpl_column *cpl_table_find_column_(cpl_table *, const char *); -static const cpl_column *cpl_table_find_column_const_(const cpl_table *, - const char *); +static const cpl_column * +cpl_table_find_column_const_(const cpl_table *, const char *); + +static cpl_column * +cpl_table_find_column(cpl_table *, const char *) CPL_ATTR_NONNULL; -static cpl_column *cpl_table_find_column(cpl_table *, - const char *) - CPL_ATTR_NONNULL; - -static const cpl_column *cpl_table_find_column_const(const cpl_table *, - const char *) - CPL_ATTR_NONNULL; - -static cpl_error_code cpl_table_append_column(cpl_table *, - cpl_column *) - CPL_ATTR_NONNULL; +static const cpl_column * +cpl_table_find_column_const(const cpl_table *, const char *) CPL_ATTR_NONNULL; + +static cpl_error_code +cpl_table_append_column(cpl_table *, cpl_column *) CPL_ATTR_NONNULL; -static int strmatch(regex_t *, const char *) - CPL_ATTR_NONNULL; +static int strmatch(regex_t *, const char *) CPL_ATTR_NONNULL; /* @@ -184,20 +186,16 @@ inline static size_t _cpl_strvlen_max(const char **s, cpl_size n) { - register size_t i; register size_t sz = 0; for (i = 0; i < (size_t)n; ++i) { - if (s[i] != NULL) { sz = CPL_MAX(sz, strlen(s[i])); } - } return sz; - } @@ -225,8 +223,8 @@ */ inline static int -_cpl_columntype_get_nativetype(cpl_type type, char *fmtcode) { - +_cpl_columntype_get_nativetype(cpl_type type, char *fmtcode) +{ char fmt = '\0'; int native_type = -1; @@ -235,7 +233,6 @@ type = _cpl_columntype_get_valuetype(type); switch (type) { - case CPL_TYPE_BOOL: fmt = 'L'; native_type = TLOGICAL; @@ -293,7 +290,6 @@ default: break; - } if ((native_type != -1) && (fmtcode != NULL)) { @@ -301,13 +297,15 @@ } return native_type; - } inline static int -_cpl_column_find_null(const cpl_column *column, cpl_type type, cpl_size nrows, - unsigned int *null_flag, LONGLONG *null_value) +_cpl_column_find_null(const cpl_column *column, + cpl_type type, + cpl_size nrows, + unsigned int *null_flag, + LONGLONG *null_value) { const cpl_column_flag *is_invalid; @@ -317,11 +315,9 @@ */ if (!cpl_column_has_invalid(column)) { - - *null_flag = 0; + *null_flag = 0; *null_value = 0; return 0; - } @@ -340,11 +336,8 @@ */ if (!is_invalid) { - switch (type) { - - case CPL_TYPE_INT: - { + case CPL_TYPE_INT: { register int _null_flag = 1; register cpl_size irow; @@ -360,22 +353,20 @@ } if (_null_flag) { - *null_flag = 1; + *null_flag = 1; *null_value = data[0]; } break; } - case CPL_TYPE_LONG_LONG: - { - + case CPL_TYPE_LONG_LONG: { register int _null_flag = 1; register cpl_size irow; const long long *data = - cpl_column_get_data_long_long_const(column); + cpl_column_get_data_long_long_const(column); for (irow = 1; irow < nrows; ++irow) { @@ -386,7 +377,7 @@ } if (_null_flag) { - *null_flag = 1; + *null_flag = 1; *null_value = data[0]; } @@ -396,12 +387,9 @@ default: return 2; break; - } - } else { - register cpl_size first = 0; @@ -414,9 +402,7 @@ } switch (type) { - case CPL_TYPE_INT: - { - + case CPL_TYPE_INT: { register int _null_flag = 1; register cpl_size irow; @@ -432,21 +418,20 @@ } if (_null_flag) { - *null_flag = 1; + *null_flag = 1; *null_value = data[first]; } break; } - case CPL_TYPE_LONG_LONG: - { + case CPL_TYPE_LONG_LONG: { register int _null_flag = 1; register cpl_size irow; const long long *data = - cpl_column_get_data_long_long_const(column); + cpl_column_get_data_long_long_const(column); for (irow = first + 1; irow < nrows; ++irow) { if (is_invalid[irow] && (data[irow] != data[first])) { @@ -456,7 +441,7 @@ } if (_null_flag) { - *null_flag = 1; + *null_flag = 1; *null_value = data[first]; } @@ -467,11 +452,9 @@ return 2; break; } - } return 0; - } @@ -504,20 +487,22 @@ * @enderror */ -static const cpl_column *cpl_table_find_column_const_(const cpl_table *table, - const char *name) +static const cpl_column * +cpl_table_find_column_const_(const cpl_table *table, const char *name) { - const cpl_column *column = NULL; if (name == NULL) { (void)cpl_error_set_message_(CPL_ERROR_NULL_INPUT, "name is NULL"); - } else if (table == NULL) { - (void)cpl_error_set_message_(CPL_ERROR_NULL_INPUT, "table is NULL, " - "name='%s'", name); - } else { - + } + else if (table == NULL) { + (void)cpl_error_set_message_(CPL_ERROR_NULL_INPUT, + "table is NULL, " + "name='%s'", + name); + } + else { column = cpl_table_find_column_const(table, name); if (!column) { @@ -530,20 +515,22 @@ } -static cpl_column *cpl_table_find_column_(cpl_table *table, - const char *name) +static cpl_column * +cpl_table_find_column_(cpl_table *table, const char *name) { - cpl_column *column = NULL; if (name == NULL) { (void)cpl_error_set_message_(CPL_ERROR_NULL_INPUT, "name is NULL"); - } else if (table == NULL) { - (void)cpl_error_set_message_(CPL_ERROR_NULL_INPUT, "table is NULL, " - "name='%s'", name); - } else { - + } + else if (table == NULL) { + (void)cpl_error_set_message_(CPL_ERROR_NULL_INPUT, + "table is NULL, " + "name='%s'", + name); + } + else { column = cpl_table_find_column(table, name); if (!column) { @@ -593,25 +580,24 @@ * @enderror */ -static cpl_column *cpl_table_find_column_type(cpl_table *table, - const char *name, - cpl_type exptype) +static cpl_column * +cpl_table_find_column_type(cpl_table *table, const char *name, cpl_type exptype) { - cpl_column *column = cpl_table_find_column_(table, name); if (!column) { (void)cpl_error_set_where_(); - } else { - + } + else { const cpl_type type = cpl_column_get_type(column); if (type != exptype && (exptype != CPL_TYPE_POINTER || !(type & CPL_TYPE_POINTER))) { column = NULL; - (void)cpl_error_set_message_(CPL_ERROR_TYPE_MISMATCH, "name='%s', " - "type=%s != %s", name, - cpl_type_get_name(type), + (void)cpl_error_set_message_(CPL_ERROR_TYPE_MISMATCH, + "name='%s', " + "type=%s != %s", + name, cpl_type_get_name(type), cpl_type_get_name(exptype)); } } @@ -657,26 +643,26 @@ * @enderror */ -static -const cpl_column *cpl_table_find_column_type_const(const cpl_table *table, - const char *name, - cpl_type exptype) +static const cpl_column * +cpl_table_find_column_type_const(const cpl_table *table, + const char *name, + cpl_type exptype) { - const cpl_column *column = cpl_table_find_column_const_(table, name); if (!column) { (void)cpl_error_set_where_(); - } else { - + } + else { const cpl_type type = cpl_column_get_type(column); if (type != exptype && (exptype != CPL_TYPE_POINTER || !(type & CPL_TYPE_POINTER))) { column = NULL; - (void)cpl_error_set_message_(CPL_ERROR_TYPE_MISMATCH, "name='%s', " - "type=%s != %s", name, - cpl_type_get_name(type), + (void)cpl_error_set_message_(CPL_ERROR_TYPE_MISMATCH, + "name='%s', " + "type=%s != %s", + name, cpl_type_get_name(type), cpl_type_get_name(exptype)); } } @@ -700,12 +686,10 @@ * not to be @c NULL. */ -static const cpl_column *cpl_table_find_column_const(const cpl_table *table, - const char *name) +static const cpl_column * +cpl_table_find_column_const(const cpl_table *table, const char *name) { - - const cpl_column * const *column = - (const cpl_column * const *)table->columns; + const cpl_column *const *column = (const cpl_column *const *)table->columns; for (cpl_size i = 0; i < table->nc; i++, column++) { const char *column_name = cpl_column_get_name(*column); @@ -715,7 +699,6 @@ } return NULL; - } /* @@ -733,10 +716,9 @@ * not to be @c NULL. */ -static cpl_column *cpl_table_find_column(cpl_table *table, - const char *name) +static cpl_column * +cpl_table_find_column(cpl_table *table, const char *name) { - cpl_column **column = table->columns; for (cpl_size i = 0; i < table->nc; i++, column++) { @@ -747,7 +729,6 @@ } return NULL; - } @@ -768,42 +749,39 @@ * are expected not to be @c NULL. */ -static cpl_column *cpl_table_extract_column(cpl_table *table, const char *name) +static cpl_column * +cpl_table_extract_column(cpl_table *table, const char *name) { - - cpl_column *column = cpl_table_find_column(table, name); + cpl_column *column = cpl_table_find_column(table, name); if (column) { - - const cpl_size width = cpl_table_get_ncol(table); - cpl_size i, j; + const cpl_size width = cpl_table_get_ncol(table); + cpl_size i, j; for (i = 0; i < width; i++) if (column == table->columns[i]) break; j = i + 1; - while(j < width) + while (j < width) table->columns[i++] = table->columns[j++]; table->nc--; if (table->nc) { - table->columns = cpl_realloc(table->columns, - table->nc * sizeof(column)); + table->columns = + cpl_realloc(table->columns, table->nc * sizeof(column)); } else { cpl_free(table->columns); table->columns = NULL; } - if (table->nc == 0) /* Last column deleted */ + if (table->nc == 0) /* Last column deleted */ cpl_table_select_all(table); - } return column; - } @@ -824,13 +802,12 @@ * columns in the table. */ -static cpl_error_code cpl_table_append_column(cpl_table *table, - cpl_column *column) +static cpl_error_code +cpl_table_append_column(cpl_table *table, cpl_column *column) { - if (table->columns) { - table->columns = cpl_realloc(table->columns, - (table->nc + 1) * sizeof(column)); + table->columns = + cpl_realloc(table->columns, (table->nc + 1) * sizeof(column)); } else table->columns = cpl_malloc(sizeof(column)); @@ -840,7 +817,6 @@ table->nc++; return CPL_ERROR_NONE; - } @@ -858,14 +834,13 @@ * check on the availability of regexec() are done elsewhere. */ -static int strmatch(regex_t *pattern, const char *string) +static int +strmatch(regex_t *pattern, const char *string) { - if (regexec(pattern, string, (size_t)0, NULL, 0) == REG_NOMATCH) return 0; return 1; - } @@ -887,8 +862,11 @@ */ static cpl_error_code -table_sort(cpl_table *table, const cpl_propertylist *reflist, unsigned n, - cpl_size *sort_pattern, cpl_size *sort_null_pattern) +table_sort(cpl_table *table, + const cpl_propertylist *reflist, + unsigned n, + cpl_size *sort_pattern, + cpl_size *sort_null_pattern) { const cpl_property *info; const char *name; @@ -900,24 +878,24 @@ cpl_size i, j; cpl_size nullcount; - int *idata; - int *work_idata; - long *ldata; - long *work_ldata; - long long *lldata; - long long *work_lldata; - float *fdata; - float *work_fdata; - double *ddata; - double *work_ddata; - float complex *cfdata; - float complex *work_cfdata; - double complex *cddata; - double complex *work_cddata; - char **sdata; - char **work_sdata; - cpl_array **adata; - cpl_array **work_adata; + int *idata; + int *work_idata; + long *ldata; + long *work_ldata; + long long *lldata; + long long *work_lldata; + float *fdata; + float *work_fdata; + double *ddata; + double *work_ddata; + float complex *cfdata; + float complex *work_cfdata; + double complex *cddata; + double complex *work_cddata; + char **sdata; + char **work_sdata; + cpl_array **adata; + cpl_array **work_adata; cpl_column_flag *ndata; cpl_column_flag *work_ndata; @@ -948,7 +926,7 @@ } type = cpl_column_get_type(column); - if (type & CPL_TYPE_POINTER) { /* Arrays not as reference */ + if (type & CPL_TYPE_POINTER) { /* Arrays not as reference */ return cpl_error_set_(CPL_ERROR_UNSUPPORTED_MODE); } @@ -960,29 +938,25 @@ nullcount = cpl_column_count_invalid(column); ndata = cpl_column_get_data_invalid(column); - + j = 0; for (i = 0; i < table->nr; i++) { - if (nullcount == table->nr || - (ndata != NULL && ndata[i])) { + if (nullcount == table->nr || (ndata != NULL && ndata[i])) { sort_null_pattern[j++] = i; } } -/* + /* assert( j == nullcount ); */ for (i = 0; i < table->nr; i++) { - if (! - (nullcount == table->nr || - (ndata != NULL && ndata[i])) - ) { + if (!(nullcount == table->nr || (ndata != NULL && ndata[i]))) { sort_null_pattern[j++] = i; } } -/* + /* assert( j == table->nr ); */ @@ -999,43 +973,48 @@ int isnull; switch (type) { - case CPL_TYPE_INT: - cpl_column_set_int( - column_sorted_null, i, - cpl_column_get_int(column, sort_null_pattern[i], &isnull)); - break; - case CPL_TYPE_LONG: - cpl_column_set_long( - column_sorted_null, i, - cpl_column_get_long(column, sort_null_pattern[i], &isnull)); - break; - case CPL_TYPE_LONG_LONG: - cpl_column_set_long_long( - column_sorted_null, i, - cpl_column_get_long_long(column, sort_null_pattern[i], &isnull)); - break; - case CPL_TYPE_FLOAT: - cpl_column_set_float( - column_sorted_null, i, - cpl_column_get_float(column, sort_null_pattern[i], &isnull)); - break; - case CPL_TYPE_DOUBLE: - cpl_column_set_double( - column_sorted_null, i, - cpl_column_get_double(column, sort_null_pattern[i], &isnull)); - break; - case CPL_TYPE_STRING: - cpl_column_set_string( - column_sorted_null, i, - cpl_column_get_string(column, sort_null_pattern[i])); - break; - default: + case CPL_TYPE_INT: + cpl_column_set_int(column_sorted_null, i, + cpl_column_get_int(column, + sort_null_pattern[i], + &isnull)); + break; + case CPL_TYPE_LONG: + cpl_column_set_long(column_sorted_null, i, + cpl_column_get_long(column, + sort_null_pattern[i], + &isnull)); + break; + case CPL_TYPE_LONG_LONG: + cpl_column_set_long_long( + column_sorted_null, i, + cpl_column_get_long_long(column, sort_null_pattern[i], + &isnull)); + break; + case CPL_TYPE_FLOAT: + cpl_column_set_float(column_sorted_null, i, + cpl_column_get_float(column, + sort_null_pattern[i], + &isnull)); + break; + case CPL_TYPE_DOUBLE: + cpl_column_set_double( + column_sorted_null, i, + cpl_column_get_double(column, sort_null_pattern[i], + &isnull)); + break; + case CPL_TYPE_STRING: + cpl_column_set_string( + column_sorted_null, i, + cpl_column_get_string(column, sort_null_pattern[i])); + break; + default: - /* You should never get here */ -/* + /* You should never get here */ + /* assert( 0 ); */ - break; + break; } } @@ -1047,61 +1026,50 @@ sort_pattern[i] = i; } switch (type) { - case CPL_TYPE_INT: - cpl_tools_sort_stable_pattern_int( - cpl_column_get_data_int(column_sorted_null) + nullcount, - table->nr - nullcount, - reverse, - stable, - sort_pattern + nullcount); - break; - case CPL_TYPE_LONG: - cpl_tools_sort_stable_pattern_long( - cpl_column_get_data_long(column_sorted_null) + nullcount, - table->nr - nullcount, - reverse, - stable, - sort_pattern + nullcount); - break; - case CPL_TYPE_LONG_LONG: - cpl_tools_sort_stable_pattern_long_long( - cpl_column_get_data_long_long(column_sorted_null) + nullcount, - table->nr - nullcount, - reverse, - stable, - sort_pattern + nullcount); - break; - case CPL_TYPE_FLOAT: - cpl_tools_sort_stable_pattern_float( - cpl_column_get_data_float(column_sorted_null) + nullcount, - table->nr - nullcount, - reverse, - stable, - sort_pattern + nullcount); - break; - case CPL_TYPE_DOUBLE: - cpl_tools_sort_stable_pattern_double( - cpl_column_get_data_double(column_sorted_null) + nullcount, - table->nr - nullcount, - reverse, - stable, - sort_pattern + nullcount); - break; - case CPL_TYPE_STRING: - cpl_tools_sort_stable_pattern_string( - cpl_column_get_data_string(column_sorted_null) + nullcount, - table->nr - nullcount, - reverse, - stable, - sort_pattern + nullcount); - break; - default: + case CPL_TYPE_INT: + cpl_tools_sort_stable_pattern_int(cpl_column_get_data_int( + column_sorted_null) + + nullcount, + table->nr - nullcount, reverse, + stable, sort_pattern + nullcount); + break; + case CPL_TYPE_LONG: + cpl_tools_sort_stable_pattern_long( + cpl_column_get_data_long(column_sorted_null) + nullcount, + table->nr - nullcount, reverse, stable, + sort_pattern + nullcount); + break; + case CPL_TYPE_LONG_LONG: + cpl_tools_sort_stable_pattern_long_long( + cpl_column_get_data_long_long(column_sorted_null) + nullcount, + table->nr - nullcount, reverse, stable, + sort_pattern + nullcount); + break; + case CPL_TYPE_FLOAT: + cpl_tools_sort_stable_pattern_float( + cpl_column_get_data_float(column_sorted_null) + nullcount, + table->nr - nullcount, reverse, stable, + sort_pattern + nullcount); + break; + case CPL_TYPE_DOUBLE: + cpl_tools_sort_stable_pattern_double( + cpl_column_get_data_double(column_sorted_null) + nullcount, + table->nr - nullcount, reverse, stable, + sort_pattern + nullcount); + break; + case CPL_TYPE_STRING: + cpl_tools_sort_stable_pattern_string( + cpl_column_get_data_string(column_sorted_null) + nullcount, + table->nr - nullcount, reverse, stable, + sort_pattern + nullcount); + break; + default: - /* You should never get here */ -/* + /* You should never get here */ + /* assert( 0 ); */ - break; + break; } cpl_column_delete(column_sorted_null); @@ -1122,34 +1090,30 @@ j = 0; while (j < table->nc) { - cpl_type type_id = cpl_column_get_type(table->columns[j]); if (_cpl_columntype_is_pointer(type_id)) { - switch (_cpl_columntype_get_valuetype(type_id)) { - case CPL_TYPE_INT: case CPL_TYPE_LONG: case CPL_TYPE_LONG_LONG: case CPL_TYPE_FLOAT: case CPL_TYPE_DOUBLE: - case CPL_TYPE_STRING: - { - cpl_column *work_column = - cpl_column_new_array(cpl_column_get_type(table->columns[j]), - table->nr, - cpl_column_get_depth(table->columns[j])); + case CPL_TYPE_STRING: { + cpl_column *work_column = cpl_column_new_array( + cpl_column_get_type(table->columns[j]), table->nr, + cpl_column_get_depth(table->columns[j])); work_adata = cpl_column_get_data_array(work_column); adata = cpl_column_get_data_array(table->columns[j]); - + for (i = 0; i < table->nr; i++) work_adata[i] = adata[i]; for (i = 0; i < table->nr; i++) - adata[i] = work_adata[sort_null_pattern[sort_pattern[i]]]; + adata[i] = + work_adata[sort_null_pattern[sort_pattern[i]]]; cpl_column_delete_but_arrays(work_column); break; @@ -1157,260 +1121,249 @@ default: - break; /* Should never get here */ - + break; /* Should never get here */ } - } else { - switch (_cpl_columntype_get_valuetype(type_id)) { - - case CPL_TYPE_INT: - { - cpl_column *work_column = + case CPL_TYPE_INT: { + cpl_column *work_column = cpl_column_duplicate(table->columns[j]); - nullcount = cpl_column_count_invalid(table->columns[j]); - - if (nullcount != table->nr) { + nullcount = cpl_column_count_invalid(table->columns[j]); - ndata = cpl_column_get_data_invalid(table->columns[j]); + if (nullcount != table->nr) { + ndata = cpl_column_get_data_invalid(table->columns[j]); - if (ndata) { - work_ndata = cpl_column_get_data_invalid(work_column); - - for (i = 0; i < table->nr; i++) - ndata[i] = - work_ndata[sort_null_pattern[sort_pattern[i]]]; + if (ndata) { + work_ndata = + cpl_column_get_data_invalid(work_column); + for (i = 0; i < table->nr; i++) + ndata[i] = work_ndata + [sort_null_pattern[sort_pattern[i]]]; + } } - } - - work_idata = cpl_column_get_data_int(work_column); - idata = cpl_column_get_data_int(table->columns[j]); - - for (i = 0; i < table->nr; i++) - idata[i] = work_idata[sort_null_pattern[sort_pattern[i]]]; - - cpl_column_delete(work_column); - break; - } + work_idata = cpl_column_get_data_int(work_column); + idata = cpl_column_get_data_int(table->columns[j]); - case CPL_TYPE_LONG: - { - cpl_column *work_column = cpl_column_duplicate(table->columns[j]); + for (i = 0; i < table->nr; i++) + idata[i] = + work_idata[sort_null_pattern[sort_pattern[i]]]; - nullcount = cpl_column_count_invalid(table->columns[j]); + cpl_column_delete(work_column); + break; + } - if (nullcount != table->nr) { + case CPL_TYPE_LONG: { + cpl_column *work_column = + cpl_column_duplicate(table->columns[j]); - ndata = cpl_column_get_data_invalid(table->columns[j]); + nullcount = cpl_column_count_invalid(table->columns[j]); - if (ndata) { - work_ndata = cpl_column_get_data_invalid(work_column); + if (nullcount != table->nr) { + ndata = cpl_column_get_data_invalid(table->columns[j]); - for (i = 0; i < table->nr; i++) - ndata[i] = - work_ndata[sort_null_pattern[sort_pattern[i]]]; + if (ndata) { + work_ndata = + cpl_column_get_data_invalid(work_column); + for (i = 0; i < table->nr; i++) + ndata[i] = work_ndata + [sort_null_pattern[sort_pattern[i]]]; + } } - } - - work_ldata = cpl_column_get_data_long(work_column); - ldata = cpl_column_get_data_long(table->columns[j]); + work_ldata = cpl_column_get_data_long(work_column); + ldata = cpl_column_get_data_long(table->columns[j]); - for (i = 0; i < table->nr; i++) - ldata[i] = work_ldata[sort_null_pattern[sort_pattern[i]]]; - - cpl_column_delete(work_column); - break; - } - - case CPL_TYPE_LONG_LONG: - { - cpl_column *work_column = cpl_column_duplicate(table->columns[j]); + for (i = 0; i < table->nr; i++) + ldata[i] = + work_ldata[sort_null_pattern[sort_pattern[i]]]; - nullcount = cpl_column_count_invalid(table->columns[j]); + cpl_column_delete(work_column); + break; + } - if (nullcount != table->nr) { + case CPL_TYPE_LONG_LONG: { + cpl_column *work_column = + cpl_column_duplicate(table->columns[j]); - ndata = cpl_column_get_data_invalid(table->columns[j]); + nullcount = cpl_column_count_invalid(table->columns[j]); - if (ndata) { - work_ndata = cpl_column_get_data_invalid(work_column); + if (nullcount != table->nr) { + ndata = cpl_column_get_data_invalid(table->columns[j]); - for (i = 0; i < table->nr; i++) - ndata[i] = - work_ndata[sort_null_pattern[sort_pattern[i]]]; + if (ndata) { + work_ndata = + cpl_column_get_data_invalid(work_column); + for (i = 0; i < table->nr; i++) + ndata[i] = work_ndata + [sort_null_pattern[sort_pattern[i]]]; + } } - } - - work_lldata = cpl_column_get_data_long_long(work_column); - lldata = cpl_column_get_data_long_long(table->columns[j]); - - for (i = 0; i < table->nr; i++) - lldata[i] = work_lldata[sort_null_pattern[sort_pattern[i]]]; - - cpl_column_delete(work_column); - break; - } + work_lldata = cpl_column_get_data_long_long(work_column); + lldata = cpl_column_get_data_long_long(table->columns[j]); - case CPL_TYPE_FLOAT: - { - cpl_column *work_column = cpl_column_duplicate(table->columns[j]); + for (i = 0; i < table->nr; i++) + lldata[i] = + work_lldata[sort_null_pattern[sort_pattern[i]]]; - nullcount = cpl_column_count_invalid(table->columns[j]); + cpl_column_delete(work_column); + break; + } - if (nullcount != table->nr) { + case CPL_TYPE_FLOAT: { + cpl_column *work_column = + cpl_column_duplicate(table->columns[j]); - ndata = cpl_column_get_data_invalid(table->columns[j]); + nullcount = cpl_column_count_invalid(table->columns[j]); - if (ndata) { - work_ndata = cpl_column_get_data_invalid(work_column); + if (nullcount != table->nr) { + ndata = cpl_column_get_data_invalid(table->columns[j]); - for (i = 0; i < table->nr; i++) - ndata[i] = - work_ndata[sort_null_pattern[sort_pattern[i]]]; + if (ndata) { + work_ndata = + cpl_column_get_data_invalid(work_column); + for (i = 0; i < table->nr; i++) + ndata[i] = work_ndata + [sort_null_pattern[sort_pattern[i]]]; + } } - } - - work_fdata = cpl_column_get_data_float(work_column); - fdata = cpl_column_get_data_float(table->columns[j]); - - for (i = 0; i < table->nr; i++) - fdata[i] = work_fdata[sort_null_pattern[sort_pattern[i]]]; - - cpl_column_delete(work_column); - break; - } + work_fdata = cpl_column_get_data_float(work_column); + fdata = cpl_column_get_data_float(table->columns[j]); - case CPL_TYPE_DOUBLE: - { - cpl_column *work_column = cpl_column_duplicate(table->columns[j]); + for (i = 0; i < table->nr; i++) + fdata[i] = + work_fdata[sort_null_pattern[sort_pattern[i]]]; - nullcount = cpl_column_count_invalid(table->columns[j]); + cpl_column_delete(work_column); + break; + } - if (nullcount != table->nr) { + case CPL_TYPE_DOUBLE: { + cpl_column *work_column = + cpl_column_duplicate(table->columns[j]); - ndata = cpl_column_get_data_invalid(table->columns[j]); + nullcount = cpl_column_count_invalid(table->columns[j]); - if (ndata) { - work_ndata = cpl_column_get_data_invalid(work_column); + if (nullcount != table->nr) { + ndata = cpl_column_get_data_invalid(table->columns[j]); - for (i = 0; i < table->nr; i++) - ndata[i] = - work_ndata[sort_null_pattern[sort_pattern[i]]]; + if (ndata) { + work_ndata = + cpl_column_get_data_invalid(work_column); + for (i = 0; i < table->nr; i++) + ndata[i] = work_ndata + [sort_null_pattern[sort_pattern[i]]]; + } } - } - - work_ddata = cpl_column_get_data_double(work_column); - ddata = cpl_column_get_data_double(table->columns[j]); - - for (i = 0; i < table->nr; i++) - ddata[i] = work_ddata[sort_null_pattern[sort_pattern[i]]]; - - cpl_column_delete(work_column); - break; - } + work_ddata = cpl_column_get_data_double(work_column); + ddata = cpl_column_get_data_double(table->columns[j]); - case CPL_TYPE_FLOAT_COMPLEX: - { - cpl_column *work_column = cpl_column_duplicate(table->columns[j]); + for (i = 0; i < table->nr; i++) + ddata[i] = + work_ddata[sort_null_pattern[sort_pattern[i]]]; - nullcount = cpl_column_count_invalid(table->columns[j]); + cpl_column_delete(work_column); + break; + } - if (nullcount != table->nr) { + case CPL_TYPE_FLOAT_COMPLEX: { + cpl_column *work_column = + cpl_column_duplicate(table->columns[j]); - ndata = cpl_column_get_data_invalid(table->columns[j]); + nullcount = cpl_column_count_invalid(table->columns[j]); - if (ndata) { - work_ndata = cpl_column_get_data_invalid(work_column); + if (nullcount != table->nr) { + ndata = cpl_column_get_data_invalid(table->columns[j]); - for (i = 0; i < table->nr; i++) - ndata[i] = - work_ndata[sort_null_pattern[sort_pattern[i]]]; + if (ndata) { + work_ndata = + cpl_column_get_data_invalid(work_column); + for (i = 0; i < table->nr; i++) + ndata[i] = work_ndata + [sort_null_pattern[sort_pattern[i]]]; + } } - } - - work_cfdata = cpl_column_get_data_float_complex(work_column); - cfdata = cpl_column_get_data_float_complex(table->columns[j]); + work_cfdata = + cpl_column_get_data_float_complex(work_column); + cfdata = + cpl_column_get_data_float_complex(table->columns[j]); - for (i = 0; i < table->nr; i++) - cfdata[i] = work_cfdata[sort_null_pattern[sort_pattern[i]]]; - - cpl_column_delete(work_column); - break; - } - - case CPL_TYPE_DOUBLE_COMPLEX: - { - cpl_column *work_column = cpl_column_duplicate(table->columns[j]); + for (i = 0; i < table->nr; i++) + cfdata[i] = + work_cfdata[sort_null_pattern[sort_pattern[i]]]; - nullcount = cpl_column_count_invalid(table->columns[j]); + cpl_column_delete(work_column); + break; + } - if (nullcount != table->nr) { + case CPL_TYPE_DOUBLE_COMPLEX: { + cpl_column *work_column = + cpl_column_duplicate(table->columns[j]); - ndata = cpl_column_get_data_invalid(table->columns[j]); + nullcount = cpl_column_count_invalid(table->columns[j]); - if (ndata) { - work_ndata = cpl_column_get_data_invalid(work_column); + if (nullcount != table->nr) { + ndata = cpl_column_get_data_invalid(table->columns[j]); - for (i = 0; i < table->nr; i++) - ndata[i] = - work_ndata[sort_null_pattern[sort_pattern[i]]]; + if (ndata) { + work_ndata = + cpl_column_get_data_invalid(work_column); + for (i = 0; i < table->nr; i++) + ndata[i] = work_ndata + [sort_null_pattern[sort_pattern[i]]]; + } } - } - - work_cddata = cpl_column_get_data_double_complex(work_column); - cddata = cpl_column_get_data_double_complex(table->columns[j]); + work_cddata = + cpl_column_get_data_double_complex(work_column); + cddata = + cpl_column_get_data_double_complex(table->columns[j]); - for (i = 0; i < table->nr; i++) - cddata[i] = work_cddata[sort_null_pattern[sort_pattern[i]]]; - - cpl_column_delete(work_column); - break; - } + for (i = 0; i < table->nr; i++) + cddata[i] = + work_cddata[sort_null_pattern[sort_pattern[i]]]; - case CPL_TYPE_STRING: - { - cpl_column *work_column = cpl_column_new_string(table->nr); + cpl_column_delete(work_column); + break; + } - work_sdata = cpl_column_get_data_string(work_column); - sdata = cpl_column_get_data_string(table->columns[j]); + case CPL_TYPE_STRING: { + cpl_column *work_column = cpl_column_new_string(table->nr); - for (i = 0; i < table->nr; i++) - work_sdata[i] = sdata[i]; + work_sdata = cpl_column_get_data_string(work_column); + sdata = cpl_column_get_data_string(table->columns[j]); - for (i = 0; i < table->nr; i++) - sdata[i] = work_sdata[sort_null_pattern[sort_pattern[i]]]; + for (i = 0; i < table->nr; i++) + work_sdata[i] = sdata[i]; - cpl_column_delete_but_strings(work_column); - break; - } + for (i = 0; i < table->nr; i++) + sdata[i] = + work_sdata[sort_null_pattern[sort_pattern[i]]]; - default: + cpl_column_delete_but_strings(work_column); + break; + } - break; /* Should never get here */ + default: + break; /* Should never get here */ } - } j++; - } @@ -1455,9 +1408,9 @@ * long as no row selection has been applied to it. */ -cpl_table *cpl_table_new(cpl_size length) +cpl_table * +cpl_table_new(cpl_size length) { - cpl_table *table; @@ -1474,7 +1427,6 @@ table->selectcount = length; return table; - } @@ -1510,16 +1462,15 @@ * invalid elements. */ -cpl_error_code cpl_table_copy_structure(cpl_table *table, - const cpl_table *mtable) +cpl_error_code +cpl_table_copy_structure(cpl_table *table, const cpl_table *mtable) { - - const char *unit = NULL; - const char *form = NULL; + const char *unit = NULL; + const char *form = NULL; cpl_column **column; - cpl_type type; - cpl_size width = cpl_table_get_ncol(mtable); - cpl_size i = 0; + cpl_type type; + cpl_size width = cpl_table_get_ncol(mtable); + cpl_size i = 0; if (table == NULL || mtable == NULL) @@ -1546,7 +1497,6 @@ } return CPL_ERROR_NONE; - } @@ -1591,11 +1541,10 @@ * are marked as invalid. */ -cpl_error_code cpl_table_new_column(cpl_table *table, - const char *name, cpl_type type) +cpl_error_code +cpl_table_new_column(cpl_table *table, const char *name, cpl_type type) { - - cpl_column *column; + cpl_column *column; if (table == NULL || name == NULL) @@ -1604,42 +1553,41 @@ if (cpl_table_find_column(table, name)) return cpl_error_set_(CPL_ERROR_ILLEGAL_OUTPUT); - switch(type) { - case CPL_TYPE_INT: - column = cpl_column_new_int(table->nr); - break; + switch (type) { + case CPL_TYPE_INT: + column = cpl_column_new_int(table->nr); + break; #if defined(USE_COLUMN_TYPE_LONG) - case CPL_TYPE_LONG: - column = cpl_column_new_long(table->nr); - break; + case CPL_TYPE_LONG: + column = cpl_column_new_long(table->nr); + break; #endif - case CPL_TYPE_LONG_LONG: - column = cpl_column_new_long_long(table->nr); - break; - case CPL_TYPE_FLOAT: - column = cpl_column_new_float(table->nr); - break; - case CPL_TYPE_DOUBLE: - column = cpl_column_new_double(table->nr); - break; - case CPL_TYPE_FLOAT_COMPLEX: - column = cpl_column_new_float_complex(table->nr); - break; - case CPL_TYPE_DOUBLE_COMPLEX: - column = cpl_column_new_double_complex(table->nr); - break; - case CPL_TYPE_STRING: - column = cpl_column_new_string(table->nr); - break; - default: - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + case CPL_TYPE_LONG_LONG: + column = cpl_column_new_long_long(table->nr); + break; + case CPL_TYPE_FLOAT: + column = cpl_column_new_float(table->nr); + break; + case CPL_TYPE_DOUBLE: + column = cpl_column_new_double(table->nr); + break; + case CPL_TYPE_FLOAT_COMPLEX: + column = cpl_column_new_float_complex(table->nr); + break; + case CPL_TYPE_DOUBLE_COMPLEX: + column = cpl_column_new_double_complex(table->nr); + break; + case CPL_TYPE_STRING: + column = cpl_column_new_string(table->nr); + break; + default: + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } cpl_column_set_name(column, name); cpl_table_append_column(table, column); return CPL_ERROR_NONE; - } @@ -1694,11 +1642,13 @@ * table. All the elements of the new column are marked as invalid. */ -cpl_error_code cpl_table_new_column_array(cpl_table *table, const char *name, - cpl_type type, cpl_size depth) +cpl_error_code +cpl_table_new_column_array(cpl_table *table, + const char *name, + cpl_type type, + cpl_size depth) { - - cpl_column *column; + cpl_column *column; if (table == NULL || name == NULL) @@ -1721,7 +1671,6 @@ cpl_table_append_column(table, column); return CPL_ERROR_NONE; - } @@ -1800,13 +1749,14 @@ * would not overflow such types. */ -cpl_error_code cpl_table_set_column_savetype(cpl_table *table, - const char *name, cpl_type type) +cpl_error_code +cpl_table_set_column_savetype(cpl_table *table, const char *name, cpl_type type) { cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_set_save_type(column, type) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -1910,11 +1860,10 @@ * that column before destroying the table that contains it. */ -cpl_error_code cpl_table_wrap_int(cpl_table *table, - int *data, const char *name) +cpl_error_code +cpl_table_wrap_int(cpl_table *table, int *data, const char *name) { - - cpl_column *column; + cpl_column *column; if (table == NULL || data == NULL || name == NULL) @@ -1928,7 +1877,6 @@ cpl_table_append_column(table, column); return CPL_ERROR_NONE; - } @@ -1964,11 +1912,10 @@ * @c cpl_table_wrap_int() for further details. */ -cpl_error_code cpl_table_wrap_long(cpl_table *table, - long *data, const char *name) +cpl_error_code +cpl_table_wrap_long(cpl_table *table, long *data, const char *name) { - - cpl_column *column; + cpl_column *column; if (table == NULL || data == NULL || name == NULL) @@ -1982,7 +1929,6 @@ cpl_table_append_column(table, column); return CPL_ERROR_NONE; - } @@ -2018,11 +1964,10 @@ * @c cpl_table_wrap_int() for further details. */ -cpl_error_code cpl_table_wrap_long_long(cpl_table *table, - long long *data, const char *name) +cpl_error_code +cpl_table_wrap_long_long(cpl_table *table, long long *data, const char *name) { - - cpl_column *column; + cpl_column *column; if (table == NULL || data == NULL || name == NULL) @@ -2036,7 +1981,6 @@ cpl_table_append_column(table, column); return CPL_ERROR_NONE; - } @@ -2072,11 +2016,10 @@ * @c cpl_table_wrap_int() for further details. */ -cpl_error_code cpl_table_wrap_float(cpl_table *table, - float *data, const char *name) +cpl_error_code +cpl_table_wrap_float(cpl_table *table, float *data, const char *name) { - - cpl_column *column; + cpl_column *column; if (table == NULL || data == NULL || name == NULL) @@ -2090,7 +2033,6 @@ cpl_table_append_column(table, column); return CPL_ERROR_NONE; - } @@ -2126,11 +2068,11 @@ * @c cpl_table_wrap_int() for further details. */ -cpl_error_code cpl_table_wrap_float_complex(cpl_table *table, - float complex *data, - const char *name) +cpl_error_code +cpl_table_wrap_float_complex(cpl_table *table, + float complex *data, + const char *name) { - cpl_column *column; @@ -2145,7 +2087,6 @@ cpl_table_append_column(table, column); return CPL_ERROR_NONE; - } @@ -2181,11 +2122,10 @@ * @c cpl_table_wrap_int() for further details. */ -cpl_error_code cpl_table_wrap_double(cpl_table *table, - double *data, const char *name) +cpl_error_code +cpl_table_wrap_double(cpl_table *table, double *data, const char *name) { - - cpl_column *column; + cpl_column *column; if (table == NULL || data == NULL || name == NULL) @@ -2199,7 +2139,6 @@ cpl_table_append_column(table, column); return CPL_ERROR_NONE; - } @@ -2235,11 +2174,11 @@ * @c cpl_table_wrap_int() for further details. */ -cpl_error_code cpl_table_wrap_double_complex(cpl_table *table, - double complex *data, - const char *name) +cpl_error_code +cpl_table_wrap_double_complex(cpl_table *table, + double complex *data, + const char *name) { - cpl_column *column; @@ -2254,7 +2193,6 @@ cpl_table_append_column(table, column); return CPL_ERROR_NONE; - } @@ -2294,11 +2232,10 @@ * @c cpl_table_set_column_invalid() should be used. */ -cpl_error_code cpl_table_wrap_string(cpl_table *table, - char **data, const char *name) +cpl_error_code +cpl_table_wrap_string(cpl_table *table, char **data, const char *name) { - - cpl_column *column; + cpl_column *column; if (table == NULL || data == NULL || name == NULL) @@ -2312,7 +2249,6 @@ cpl_table_append_column(table, column); return CPL_ERROR_NONE; - } @@ -2362,7 +2298,8 @@ * data buffer. */ -void *cpl_table_unwrap(cpl_table *table, const char *name) +void * +cpl_table_unwrap(cpl_table *table, const char *name) { cpl_column *column; @@ -2385,7 +2322,6 @@ } return cpl_column_unwrap(column); - } @@ -2429,18 +2365,16 @@ * @c cpl_table_set_invalid() and @c cpl_table_set_column_invalid(). */ -cpl_error_code cpl_table_copy_data_int(cpl_table *table, - const char *name, const int *data) +cpl_error_code +cpl_table_copy_data_int(cpl_table *table, const char *name, const int *data) { - - cpl_column *column = cpl_table_find_column_(table, name); + cpl_column *column = cpl_table_find_column_(table, name); if (data == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); - return cpl_column_copy_data_int(column, data) - ? cpl_error_set_where_() : CPL_ERROR_NONE; - + return cpl_column_copy_data_int(column, data) ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -2480,19 +2414,17 @@ * See the description of @c cpl_table_copy_data_int() for details. */ -cpl_error_code cpl_table_copy_data_long(cpl_table *table, - const char *name, const long *data) +cpl_error_code +cpl_table_copy_data_long(cpl_table *table, const char *name, const long *data) { - - cpl_column *column = cpl_table_find_column_(table, name); + cpl_column *column = cpl_table_find_column_(table, name); if (data == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); - return cpl_column_copy_data_long(column, data) - ? cpl_error_set_where_() : CPL_ERROR_NONE; - + return cpl_column_copy_data_long(column, data) ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -2532,19 +2464,19 @@ * See the description of @c cpl_table_copy_data_int() for details. */ -cpl_error_code cpl_table_copy_data_long_long(cpl_table *table, - const char *name, - const long long *data) +cpl_error_code +cpl_table_copy_data_long_long(cpl_table *table, + const char *name, + const long long *data) { - - cpl_column *column = cpl_table_find_column_(table, name); + cpl_column *column = cpl_table_find_column_(table, name); if (data == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); - return cpl_column_copy_data_long_long(column, data) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + return cpl_column_copy_data_long_long(column, data) ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -2584,18 +2516,17 @@ * See the description of @c cpl_table_copy_data_int() for details. */ -cpl_error_code cpl_table_copy_data_float(cpl_table *table, - const char *name, const float *data) +cpl_error_code +cpl_table_copy_data_float(cpl_table *table, const char *name, const float *data) { - - cpl_column *column = cpl_table_find_column_(table, name); + cpl_column *column = cpl_table_find_column_(table, name); if (data == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); - return cpl_column_copy_data_float(column, data) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + return cpl_column_copy_data_float(column, data) ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -2635,18 +2566,19 @@ * See the description of @c cpl_table_copy_data_int() for details. */ -cpl_error_code cpl_table_copy_data_float_complex(cpl_table *table, - const char *name, - const float complex *data) +cpl_error_code +cpl_table_copy_data_float_complex(cpl_table *table, + const char *name, + const float complex *data) { - - cpl_column *column = cpl_table_find_column_(table, name); + cpl_column *column = cpl_table_find_column_(table, name); if (data == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); return cpl_column_copy_data_float_complex(column, data) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -2686,16 +2618,18 @@ * See the description of @c cpl_table_copy_data_int() for details. */ -cpl_error_code cpl_table_copy_data_double(cpl_table *table, - const char *name, const double *data) +cpl_error_code +cpl_table_copy_data_double(cpl_table *table, + const char *name, + const double *data) { - cpl_column *column = cpl_table_find_column_(table, name); + cpl_column *column = cpl_table_find_column_(table, name); if (data == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); - return cpl_column_copy_data_double(column, data) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + return cpl_column_copy_data_double(column, data) ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -2735,18 +2669,19 @@ * See the description of @c cpl_table_copy_data_int() for details. */ -cpl_error_code cpl_table_copy_data_double_complex(cpl_table *table, - const char *name, - const double complex *data) +cpl_error_code +cpl_table_copy_data_double_complex(cpl_table *table, + const char *name, + const double complex *data) { - - cpl_column *column = cpl_table_find_column_(table, name); + cpl_column *column = cpl_table_find_column_(table, name); if (data == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); return cpl_column_copy_data_double_complex(column, data) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -2790,16 +2725,18 @@ * deallocated before being replaced by the new ones. */ -cpl_error_code cpl_table_copy_data_string(cpl_table *table, const char *name, - const char **data) +cpl_error_code +cpl_table_copy_data_string(cpl_table *table, + const char *name, + const char **data) { - cpl_column *column = cpl_table_find_column_(table, name); + cpl_column *column = cpl_table_find_column_(table, name); if (data == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); - return cpl_column_copy_data_string(column, data) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + return cpl_column_copy_data_string(column, data) ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -2816,10 +2753,10 @@ * nothing is done, and no error is set. */ -void cpl_table_delete(cpl_table *table) +void +cpl_table_delete(cpl_table *table) { - - int width; + int width; cpl_column **column; @@ -2834,7 +2771,6 @@ cpl_free(table->select); cpl_free(table); } - } @@ -2861,16 +2797,15 @@ * Get the number of rows in a table. */ -cpl_size cpl_table_get_nrow(const cpl_table *table) +cpl_size +cpl_table_get_nrow(const cpl_table *table) { - if (table) return table->nr; cpl_error_set("cpl_table_get_nrow", CPL_ERROR_NULL_INPUT); return -1; - } @@ -2897,16 +2832,15 @@ * Get the number of columns in a table. */ -cpl_size cpl_table_get_ncol(const cpl_table *table) +cpl_size +cpl_table_get_ncol(const cpl_table *table) { - if (table) return table->nc; cpl_error_set("cpl_table_get_ncol", CPL_ERROR_NULL_INPUT); return -1; - } @@ -2939,7 +2873,8 @@ * Get the type of a column. */ -cpl_type cpl_table_get_column_type(const cpl_table *table, const char *name) +cpl_type +cpl_table_get_column_type(const cpl_table *table, const char *name) { const cpl_column *column = cpl_table_find_column_const_(table, name); @@ -2949,7 +2884,6 @@ } return cpl_column_get_type(column); - } @@ -2983,10 +2917,10 @@ * depth, while columns listing numbers or character strings have depth 0. */ -cpl_size cpl_table_get_column_depth(const cpl_table *table, const char *name) +cpl_size +cpl_table_get_column_depth(const cpl_table *table, const char *name) { - - const cpl_column *column = cpl_table_find_column_const_(table, name); + const cpl_column *column = cpl_table_find_column_const_(table, name); if (!column) { (void)cpl_error_set_where_(); @@ -2994,7 +2928,6 @@ } return cpl_column_get_depth(column); - } @@ -3028,12 +2961,11 @@ * column, or if it has no dimensions, 1 is returned. */ -cpl_size cpl_table_get_column_dimensions(const cpl_table *table, - const char *name) +cpl_size +cpl_table_get_column_dimensions(const cpl_table *table, const char *name) { - cpl_size dim; - const cpl_column *column = cpl_table_find_column_const_(table, name); + const cpl_column *column = cpl_table_find_column_const_(table, name); if (!column) { (void)cpl_error_set_where_(); @@ -3101,17 +3033,18 @@ * has size less than 2, nothing is done and no error is returned. */ -cpl_error_code cpl_table_set_column_dimensions(cpl_table *table, - const char *name, - const cpl_array *dimensions) +cpl_error_code +cpl_table_set_column_dimensions(cpl_table *table, + const char *name, + const cpl_array *dimensions) { - cpl_column *column = cpl_table_find_column_(table, name); + cpl_column *column = cpl_table_find_column_(table, name); if (dimensions == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); return column ? cpl_column_set_dimensions(column, dimensions) - : cpl_error_set_where_(); + : cpl_error_set_where_(); } @@ -3166,11 +3099,13 @@ * column, or if it has no dimensions, 1 is returned. */ -cpl_size cpl_table_get_column_dimension(const cpl_table *table, - const char *name, cpl_size indx) +cpl_size +cpl_table_get_column_dimension(const cpl_table *table, + const char *name, + cpl_size indx) { cpl_size dim; - const cpl_column *column = cpl_table_find_column_const_(table, name); + const cpl_column *column = cpl_table_find_column_const_(table, name); if (!column) { (void)cpl_error_set_where_(); @@ -3222,14 +3157,13 @@ * cpl_table_save(). */ -cpl_error_code cpl_table_set_column_unit(cpl_table *table, const char *name, - const char *unit) +cpl_error_code +cpl_table_set_column_unit(cpl_table *table, const char *name, const char *unit) { + cpl_column *column = cpl_table_find_column_(table, name); - cpl_column *column = cpl_table_find_column_(table, name); - - return !column || cpl_column_set_unit(column, unit) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + return !column || cpl_column_set_unit(column, unit) ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -3268,10 +3202,10 @@ * be called as an argument of the function @c strdup(). */ -const char *cpl_table_get_column_unit(const cpl_table *table, const char *name) +const char * +cpl_table_get_column_unit(const cpl_table *table, const char *name) { - - const cpl_column *column = cpl_table_find_column_const_(table, name); + const cpl_column *column = cpl_table_find_column_const_(table, name); if (!column) { (void)cpl_error_set_where_(); @@ -3321,14 +3255,16 @@ * the table in FITS format using @c cpl_table_save(). */ -cpl_error_code cpl_table_set_column_format(cpl_table *table, - const char *name, const char *format) +cpl_error_code +cpl_table_set_column_format(cpl_table *table, + const char *name, + const char *format) { - - cpl_column *column = cpl_table_find_column_(table, name); + cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_set_format(column, format) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -3367,12 +3303,11 @@ * argument of the function @c strdup(). */ -const char *cpl_table_get_column_format(const cpl_table *table, - const char *name) +const char * +cpl_table_get_column_format(const cpl_table *table, const char *name) { - - const char * format; - const cpl_column *column = cpl_table_find_column_const_(table, name); + const char *format; + const cpl_column *column = cpl_table_find_column_const_(table, name); if (!column) { (void)cpl_error_set_where_(); @@ -3437,11 +3372,11 @@ * the actual column data and structure. */ -int *cpl_table_get_data_int(cpl_table *table, const char *name) +int * +cpl_table_get_data_int(cpl_table *table, const char *name) { /* Modified from the corresponding const accessor */ - cpl_column *column = - cpl_table_find_column_type(table, name, CPL_TYPE_INT); + cpl_column *column = cpl_table_find_column_type(table, name, CPL_TYPE_INT); if (!column) { (void)cpl_error_set_where_(); @@ -3494,11 +3429,11 @@ * of function @c cpl_table_fill_invalid_int() for further details. */ -const int *cpl_table_get_data_int_const(const cpl_table *table, - const char *name) +const int * +cpl_table_get_data_int_const(const cpl_table *table, const char *name) { - const cpl_column *column = cpl_table_find_column_type_const(table, name, - CPL_TYPE_INT); + const cpl_column *column = + cpl_table_find_column_type_const(table, name, CPL_TYPE_INT); if (!column) { (void)cpl_error_set_where_(); @@ -3557,11 +3492,11 @@ * the actual column data and structure. */ -long *cpl_table_get_data_long(cpl_table *table, const char *name) +long * +cpl_table_get_data_long(cpl_table *table, const char *name) { /* Modified from the corresponding const accessor */ - cpl_column *column = - cpl_table_find_column_type(table, name, CPL_TYPE_LONG); + cpl_column *column = cpl_table_find_column_type(table, name, CPL_TYPE_LONG); if (!column) { (void)cpl_error_set_where_(); @@ -3614,11 +3549,11 @@ * of function @c cpl_table_fill_invalid_long() for further details. */ -const long *cpl_table_get_data_long_const(const cpl_table *table, - const char *name) +const long * +cpl_table_get_data_long_const(const cpl_table *table, const char *name) { - const cpl_column *column = cpl_table_find_column_type_const(table, name, - CPL_TYPE_LONG); + const cpl_column *column = + cpl_table_find_column_type_const(table, name, CPL_TYPE_LONG); if (!column) { (void)cpl_error_set_where_(); @@ -3626,7 +3561,6 @@ } return cpl_column_get_data_long_const(column); - } @@ -3679,7 +3613,8 @@ * the actual column data and structure. */ -long long *cpl_table_get_data_long_long(cpl_table *table, const char *name) +long long * +cpl_table_get_data_long_long(cpl_table *table, const char *name) { /* Modified from the corresponding const accessor */ cpl_column *column = @@ -3737,8 +3672,8 @@ * @c cpl_table_fill_invalid_long_long() for further details. */ -const long long *cpl_table_get_data_long_long_const(const cpl_table *table, - const char *name) +const long long * +cpl_table_get_data_long_long_const(const cpl_table *table, const char *name) { const cpl_column *column = cpl_table_find_column_type_const(table, name, CPL_TYPE_LONG_LONG); @@ -3749,7 +3684,6 @@ } return cpl_column_get_data_long_long_const(column); - } @@ -3801,7 +3735,8 @@ * the actual column data and structure. */ -float *cpl_table_get_data_float(cpl_table *table, const char *name) +float * +cpl_table_get_data_float(cpl_table *table, const char *name) { /* Modified from the corresponding const accessor */ cpl_column *column = @@ -3858,12 +3793,11 @@ * of function @c cpl_table_fill_invalid_float() for further details. */ -const float *cpl_table_get_data_float_const(const cpl_table *table, - const char *name) +const float * +cpl_table_get_data_float_const(const cpl_table *table, const char *name) { - - const cpl_column *column = cpl_table_find_column_type_const(table, name, - CPL_TYPE_FLOAT); + const cpl_column *column = + cpl_table_find_column_type_const(table, name, CPL_TYPE_FLOAT); if (!column) { (void)cpl_error_set_where_(); @@ -3871,7 +3805,6 @@ } return cpl_column_get_data_float_const(column); - } @@ -3925,8 +3858,8 @@ * the actual column data and structure. */ -float complex *cpl_table_get_data_float_complex(cpl_table *table, - const char *name) +float complex * +cpl_table_get_data_float_complex(cpl_table *table, const char *name) { /* Modified from the corresponding const accessor */ @@ -3984,13 +3917,11 @@ * should be called just before this function, assigning to all the invalid * column elements an @em ad @em hoc numerical value. See the description * of function @c cpl_table_fill_invalid_float_complex() for further details. - */ + */ const float complex * -cpl_table_get_data_float_complex_const(const cpl_table *table, - const char *name) +cpl_table_get_data_float_complex_const(const cpl_table *table, const char *name) { - const cpl_column *column = cpl_table_find_column_type_const(table, name, CPL_TYPE_FLOAT_COMPLEX); @@ -4000,7 +3931,6 @@ } return cpl_column_get_data_float_complex_const(column); - } @@ -4052,7 +3982,8 @@ * the actual column data and structure. */ -double *cpl_table_get_data_double(cpl_table *table, const char *name) +double * +cpl_table_get_data_double(cpl_table *table, const char *name) { /* Modified from the corresponding const accessor */ cpl_column *column = @@ -4109,8 +4040,8 @@ * of function @c cpl_table_fill_invalid_double() for further details. */ -const double *cpl_table_get_data_double_const(const cpl_table *table, - const char *name) +const double * +cpl_table_get_data_double_const(const cpl_table *table, const char *name) { const cpl_column *column = cpl_table_find_column_type_const(table, name, CPL_TYPE_DOUBLE); @@ -4121,7 +4052,6 @@ } return cpl_column_get_data_double_const(column); - } @@ -4175,8 +4105,8 @@ * the actual column data and structure. */ -double complex *cpl_table_get_data_double_complex(cpl_table *table, - const char *name) +double complex * +cpl_table_get_data_double_complex(cpl_table *table, const char *name) { /* Modified from the corresponding const accessor */ @@ -4189,7 +4119,6 @@ } return cpl_column_get_data_double_complex(column); - } @@ -4235,13 +4164,12 @@ * should be called just before this function, assigning to all the invalid * column elements an @em ad @em hoc numerical value. See the description * of function @c cpl_table_fill_invalid_double_complex() for further details. - */ + */ const double complex * cpl_table_get_data_double_complex_const(const cpl_table *table, const char *name) { - const cpl_column *column = cpl_table_find_column_type_const(table, name, CPL_TYPE_DOUBLE_COMPLEX); @@ -4251,7 +4179,6 @@ } return cpl_column_get_data_double_complex_const(column); - } @@ -4298,7 +4225,8 @@ * the actual column data and structure. */ -char **cpl_table_get_data_string(cpl_table *table, const char *name) +char ** +cpl_table_get_data_string(cpl_table *table, const char *name) { /* Modified from the corresponding const acessor */ cpl_column *column = @@ -4350,8 +4278,8 @@ * of type @em char*. This function returns a pointer to this array. */ -const char **cpl_table_get_data_string_const(const cpl_table *table, - const char *name) +const char ** +cpl_table_get_data_string_const(const cpl_table *table, const char *name) { const cpl_column *column = cpl_table_find_column_type_const(table, name, CPL_TYPE_STRING); @@ -4362,7 +4290,6 @@ } return cpl_column_get_data_string_const(column); - } @@ -4409,10 +4336,11 @@ * the actual column data and structure. */ -cpl_array **cpl_table_get_data_array(cpl_table *table, const char *name) +cpl_array ** +cpl_table_get_data_array(cpl_table *table, const char *name) { /* Modified from the corresponding const acessor */ - cpl_column *column = + cpl_column *column = cpl_table_find_column_type(table, name, CPL_TYPE_POINTER); if (!column) { @@ -4461,10 +4389,10 @@ * of type @em cpl_array*. This function returns a pointer to this array. */ -const cpl_array **cpl_table_get_data_array_const(const cpl_table *table, - const char *name) +const cpl_array ** +cpl_table_get_data_array_const(const cpl_table *table, const char *name) { - const cpl_column *column = + const cpl_column *column = cpl_table_find_column_type_const(table, name, CPL_TYPE_POINTER); if (!column) { @@ -4473,7 +4401,6 @@ } return cpl_column_get_data_array_const(column); - } @@ -4507,10 +4434,10 @@ * also the selection flags are lost. */ -cpl_error_code cpl_table_erase_column(cpl_table *table, const char *name) +cpl_error_code +cpl_table_erase_column(cpl_table *table, const char *name) { - - cpl_column *column; + cpl_column *column; if (table == NULL || name == NULL) @@ -4524,7 +4451,6 @@ cpl_column_delete(column); return CPL_ERROR_NONE; - } @@ -4571,11 +4497,10 @@ * the table. */ -cpl_error_code cpl_table_erase_window(cpl_table *table, - cpl_size start, cpl_size count) +cpl_error_code +cpl_table_erase_window(cpl_table *table, cpl_size start, cpl_size count) { - - cpl_size width = cpl_table_get_ncol(table); + cpl_size width = cpl_table_get_ncol(table); cpl_column **column; @@ -4601,7 +4526,6 @@ table->nr -= count; return cpl_table_select_all(table); - } @@ -4631,11 +4555,11 @@ * "all selected". */ -cpl_error_code cpl_table_erase_selected(cpl_table *table) +cpl_error_code +cpl_table_erase_selected(cpl_table *table) { - - cpl_size length = cpl_table_get_nrow(table); - cpl_size i, width; + cpl_size length = cpl_table_get_nrow(table); + cpl_size i, width; if (table == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -4703,11 +4627,10 @@ * "all selected". */ -cpl_error_code cpl_table_insert_window(cpl_table *table, - cpl_size start, cpl_size count) +cpl_error_code +cpl_table_insert_window(cpl_table *table, cpl_size start, cpl_size count) { - - cpl_size width = cpl_table_get_ncol(table); + cpl_size width = cpl_table_get_ncol(table); cpl_column **column; @@ -4731,7 +4654,6 @@ table->nr += count; return cpl_table_select_all(table); - } @@ -4761,13 +4683,12 @@ * The order of the columns is not relevant. */ -int cpl_table_compare_structure(const cpl_table *table1, - const cpl_table *table2) +int +cpl_table_compare_structure(const cpl_table *table1, const cpl_table *table2) { - - cpl_size width1 = cpl_table_get_ncol(table1); - cpl_size width2 = cpl_table_get_ncol(table2); - const char *name = NULL; + cpl_size width1 = cpl_table_get_ncol(table1); + cpl_size width2 = cpl_table_get_ncol(table2); + const char *name = NULL; if (table1 == NULL || table2 == NULL) { @@ -4777,9 +4698,8 @@ if (width1 == width2) { - cpl_array *names = cpl_table_get_column_names(table1); - cpl_size i; + cpl_size i; int result = 0; for (i = 0; i < width1; i++) { @@ -4827,11 +4747,9 @@ cpl_array_delete(names); return result; - } return 1; - } @@ -4879,11 +4797,12 @@ * @c cpl_table_get_data_string(), etc., should be discarded. */ -cpl_error_code cpl_table_insert(cpl_table *target_table, - const cpl_table *insert_table, cpl_size row) +cpl_error_code +cpl_table_insert(cpl_table *target_table, + const cpl_table *insert_table, + cpl_size row) { - - cpl_size width = cpl_table_get_ncol(target_table); + cpl_size width = cpl_table_get_ncol(target_table); cpl_column **column; @@ -4893,18 +4812,17 @@ column = target_table->columns; while (width--) { - - if (cpl_column_merge(*column, cpl_table_find_column_const(insert_table, - cpl_column_get_name(*column)), row)) { + if (cpl_column_merge(*column, + cpl_table_find_column_const( + insert_table, cpl_column_get_name(*column)), + row)) { return cpl_error_set_where_(); } column++; - } target_table->nr += insert_table->nr; return cpl_table_select_all(target_table); - } @@ -4956,12 +4874,11 @@ * The @em null argument can be left to @c NULL. */ -double cpl_table_get(const cpl_table *table, - const char *name, cpl_size row, int *null) +double +cpl_table_get(const cpl_table *table, const char *name, cpl_size row, int *null) { - - cpl_type type; - const cpl_column *column = cpl_table_find_column_const_(table, name); + cpl_type type; + const cpl_column *column = cpl_table_find_column_const_(table, name); if (null) *null = -1; /* Ensure initialization in case of an error */ @@ -4973,17 +4890,16 @@ type = cpl_column_get_type(column); - if ((type == CPL_TYPE_STRING) - || (type & CPL_TYPE_POINTER) - || (type & CPL_TYPE_COMPLEX)) { - (void)cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, "name='%s', row=%" - CPL_SIZE_FORMAT ", type='%s'", name, row, - cpl_type_get_name(type)); + if ((type == CPL_TYPE_STRING) || (type & CPL_TYPE_POINTER) || + (type & CPL_TYPE_COMPLEX)) { + (void)cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, + "name='%s', row=%" CPL_SIZE_FORMAT + ", type='%s'", + name, row, cpl_type_get_name(type)); return 0.0; } return cpl_column_get(column, row, null); - } @@ -5035,12 +4951,14 @@ * The @em null argument can be left to @c NULL. */ -double complex cpl_table_get_complex(const cpl_table *table, - const char *name, cpl_size row, int *null) +double complex +cpl_table_get_complex(const cpl_table *table, + const char *name, + cpl_size row, + int *null) { - - cpl_type type; - const cpl_column *column = cpl_table_find_column_const_(table, name); + cpl_type type; + const cpl_column *column = cpl_table_find_column_const_(table, name); if (null) *null = -1; /* Ensure initialization in case of an error */ @@ -5053,14 +4971,14 @@ type = cpl_column_get_type(column); if (!(type & CPL_TYPE_COMPLEX) || (type & CPL_TYPE_POINTER)) { - (void)cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, "name='%s', row=%" - CPL_SIZE_FORMAT ", type='%s'", name, row, - cpl_type_get_name(type)); + (void)cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, + "name='%s', row=%" CPL_SIZE_FORMAT + ", type='%s'", + name, row, cpl_type_get_name(type)); return 0.0; } return cpl_column_get_complex(column, row, null); - } @@ -5118,12 +5036,14 @@ * @c cpl_table_get(). */ -int cpl_table_get_int(const cpl_table *table, - const char *name, cpl_size row, int *null) +int +cpl_table_get_int(const cpl_table *table, + const char *name, + cpl_size row, + int *null) { - - const cpl_column *column; - cpl_type type; + const cpl_column *column; + cpl_type type; if (null) @@ -5142,22 +5062,24 @@ column = cpl_table_find_column_const(table, name); if (!column) { - (void)cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, "name='%s', " - "row=%" CPL_SIZE_FORMAT, name, row); + (void)cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, + "name='%s', " + "row=%" CPL_SIZE_FORMAT, + name, row); return 0; } type = cpl_column_get_type(column); if (type != CPL_TYPE_INT) { - (void)cpl_error_set_message_(CPL_ERROR_TYPE_MISMATCH, "name='%s', row=%" - CPL_SIZE_FORMAT ", Non-int type='%s'", + (void)cpl_error_set_message_(CPL_ERROR_TYPE_MISMATCH, + "name='%s', row=%" CPL_SIZE_FORMAT + ", Non-int type='%s'", name, row, cpl_type_get_name(type)); return 0; } return cpl_column_get_int(column, row, null); - } @@ -5207,11 +5129,13 @@ * of function cpl_table_get_int(). */ -long cpl_table_get_long(const cpl_table *table, const char *name, - cpl_size row, int *null) +long +cpl_table_get_long(const cpl_table *table, + const char *name, + cpl_size row, + int *null) { - - const cpl_column *column = + const cpl_column *column = cpl_table_find_column_type_const(table, name, CPL_TYPE_LONG); if (null) @@ -5223,7 +5147,6 @@ } return cpl_column_get_long(column, row, null); - } @@ -5273,10 +5196,12 @@ * documentation of function cpl_table_get_int(). */ -long long cpl_table_get_long_long(const cpl_table *table, const char *name, - cpl_size row, int *null) +long long +cpl_table_get_long_long(const cpl_table *table, + const char *name, + cpl_size row, + int *null) { - const cpl_column *column = cpl_table_find_column_type_const(table, name, CPL_TYPE_LONG_LONG); @@ -5289,7 +5214,6 @@ } return cpl_column_get_long_long(column, row, null); - } @@ -5339,11 +5263,13 @@ * of function cpl_table_get_int(). */ -float cpl_table_get_float(const cpl_table *table, const char *name, - cpl_size row, int *null) +float +cpl_table_get_float(const cpl_table *table, + const char *name, + cpl_size row, + int *null) { - - const cpl_column *column = + const cpl_column *column = cpl_table_find_column_type_const(table, name, CPL_TYPE_FLOAT); if (null) @@ -5355,7 +5281,6 @@ } return cpl_column_get_float(column, row, null); - } @@ -5405,11 +5330,12 @@ * See the documentation of function cpl_table_get_int(). */ -float complex cpl_table_get_float_complex(const cpl_table *table, - const char *name, cpl_size row, - int *null) +float complex +cpl_table_get_float_complex(const cpl_table *table, + const char *name, + cpl_size row, + int *null) { - const cpl_column *column = cpl_table_find_column_type_const(table, name, CPL_TYPE_FLOAT_COMPLEX); @@ -5422,7 +5348,6 @@ } return cpl_column_get_float_complex(column, row, null); - } @@ -5472,10 +5397,12 @@ * documentation of function cpl_table_get_int(). */ -double cpl_table_get_double(const cpl_table *table, const char *name, - cpl_size row, int *null) +double +cpl_table_get_double(const cpl_table *table, + const char *name, + cpl_size row, + int *null) { - const cpl_column *column = cpl_table_find_column_type_const(table, name, CPL_TYPE_DOUBLE); @@ -5488,7 +5415,6 @@ } return cpl_column_get_double(column, row, null); - } @@ -5538,11 +5464,12 @@ * documentation of function cpl_table_get_int(). */ -double complex cpl_table_get_double_complex(const cpl_table *table, - const char *name, - cpl_size row, int *null) +double complex +cpl_table_get_double_complex(const cpl_table *table, + const char *name, + cpl_size row, + int *null) { - const cpl_column *column = cpl_table_find_column_type_const(table, name, CPL_TYPE_DOUBLE_COMPLEX); @@ -5555,7 +5482,6 @@ } return cpl_column_get_double_complex(column, row, null); - } @@ -5611,10 +5537,9 @@ * function should be called as an argument of the function @c strdup(). */ -const char *cpl_table_get_string(const cpl_table *table, - const char *name, cpl_size row) +const char * +cpl_table_get_string(const cpl_table *table, const char *name, cpl_size row) { - const cpl_column *column = cpl_table_find_column_type_const(table, name, CPL_TYPE_STRING); @@ -5624,7 +5549,6 @@ } return cpl_column_get_string_const(column, row); - } @@ -5681,10 +5605,9 @@ * @c cpl_array_duplicate(). */ -const cpl_array *cpl_table_get_array(const cpl_table *table, - const char *name, cpl_size row) +const cpl_array * +cpl_table_get_array(const cpl_table *table, const char *name, cpl_size row) { - const cpl_column *column = cpl_table_find_column_type_const(table, name, CPL_TYPE_POINTER); @@ -5694,7 +5617,6 @@ } return cpl_column_get_array_const(column, row); - } @@ -5746,14 +5668,14 @@ * @c cpl_table_set_invalid(). Table rows are counted starting from 0. */ -cpl_error_code cpl_table_set(cpl_table *table, - const char *name, cpl_size row, double value) +cpl_error_code +cpl_table_set(cpl_table *table, const char *name, cpl_size row, double value) { - cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_set(column, row, value) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -5805,15 +5727,17 @@ * @c cpl_table_set_invalid(). Table rows are counted starting from 0. */ -cpl_error_code cpl_table_set_complex(cpl_table *table, - const char *name, - cpl_size row, double complex value) +cpl_error_code +cpl_table_set_complex(cpl_table *table, + const char *name, + cpl_size row, + double complex value) { - cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_set_complex(column, row, value) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -5867,15 +5791,14 @@ * @c cpl_table_set(). */ -cpl_error_code cpl_table_set_int(cpl_table *table, - const char *name, cpl_size row, int value) +cpl_error_code +cpl_table_set_int(cpl_table *table, const char *name, cpl_size row, int value) { - cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_set_int(column, row, value) - ? cpl_error_set_where_() : CPL_ERROR_NONE; - + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -5929,14 +5852,14 @@ * @c cpl_table_set(). */ -cpl_error_code cpl_table_set_long(cpl_table *table, - const char *name, cpl_size row, long value) +cpl_error_code +cpl_table_set_long(cpl_table *table, const char *name, cpl_size row, long value) { - cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_set_long(column, row, value) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -5990,15 +5913,17 @@ * @c cpl_table_set(). */ -cpl_error_code cpl_table_set_long_long(cpl_table *table, - const char *name, cpl_size row, - long long value) +cpl_error_code +cpl_table_set_long_long(cpl_table *table, + const char *name, + cpl_size row, + long long value) { - cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_set_long_long(column, row, value) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -6052,15 +5977,17 @@ * @c cpl_table_set(). */ -cpl_error_code cpl_table_set_float(cpl_table *table, const char *name, - cpl_size row, float value) +cpl_error_code +cpl_table_set_float(cpl_table *table, + const char *name, + cpl_size row, + float value) { - cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_set_float(column, row, value) - ? cpl_error_set_where_() : CPL_ERROR_NONE; - + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -6115,15 +6042,17 @@ * @c cpl_table_set_complex(). */ -cpl_error_code cpl_table_set_float_complex(cpl_table *table, const char *name, - cpl_size row, float complex value) +cpl_error_code +cpl_table_set_float_complex(cpl_table *table, + const char *name, + cpl_size row, + float complex value) { - cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_set_float_complex(column, row, value) - ? cpl_error_set_where_() : CPL_ERROR_NONE; - + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -6177,15 +6106,17 @@ * @c cpl_table_set(). */ -cpl_error_code cpl_table_set_double(cpl_table *table, const char *name, - cpl_size row, double value) +cpl_error_code +cpl_table_set_double(cpl_table *table, + const char *name, + cpl_size row, + double value) { - cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_set_double(column, row, value) - ? cpl_error_set_where_() : CPL_ERROR_NONE; - + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -6240,14 +6171,17 @@ * @c cpl_table_set_complex(). */ -cpl_error_code cpl_table_set_double_complex(cpl_table *table, const char *name, - cpl_size row, double complex value) +cpl_error_code +cpl_table_set_double_complex(cpl_table *table, + const char *name, + cpl_size row, + double complex value) { - cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_set_double_complex(column, row, value) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -6300,14 +6234,17 @@ * use the function @c cpl_table_get_data_string(). */ -cpl_error_code cpl_table_set_string(cpl_table *table, const char *name, - cpl_size row, const char *value) +cpl_error_code +cpl_table_set_string(cpl_table *table, + const char *name, + cpl_size row, + const char *value) { - cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_set_string(column, row, value) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -6369,14 +6306,17 @@ * the column. */ -cpl_error_code cpl_table_set_array(cpl_table *table, const char *name, - cpl_size row, const cpl_array *array) +cpl_error_code +cpl_table_set_array(cpl_table *table, + const char *name, + cpl_size row, + const cpl_array *array) { - cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_set_array(column, row, array) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -6420,14 +6360,14 @@ * is flagged internally as invalid. */ -cpl_error_code cpl_table_set_invalid(cpl_table *table, const char *name, - cpl_size row) +cpl_error_code +cpl_table_set_invalid(cpl_table *table, const char *name, cpl_size row) { - cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_set_invalid(column, row) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -6487,15 +6427,18 @@ * rows, the column is filled up to its end. */ -cpl_error_code cpl_table_fill_column_window(cpl_table *table, const char *name, - cpl_size start, cpl_size count, - double value) +cpl_error_code +cpl_table_fill_column_window(cpl_table *table, + const char *name, + cpl_size start, + cpl_size count, + double value) { - cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_fill(column, start, count, value) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -6555,17 +6498,18 @@ * rows, the column is filled up to its end. */ -cpl_error_code cpl_table_fill_column_window_complex(cpl_table *table, - const char *name, - cpl_size start, - cpl_size count, - double complex value) +cpl_error_code +cpl_table_fill_column_window_complex(cpl_table *table, + const char *name, + cpl_size start, + cpl_size count, + double complex value) { - cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_fill_complex(column, start, count, value) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -6628,16 +6572,18 @@ * @c cpl_table_fill_column_window(). */ -cpl_error_code cpl_table_fill_column_window_int(cpl_table *table, - const char *name, - cpl_size start, - cpl_size count, int value) +cpl_error_code +cpl_table_fill_column_window_int(cpl_table *table, + const char *name, + cpl_size start, + cpl_size count, + int value) { - cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_fill_int(column, start, count, value) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -6700,16 +6646,18 @@ * @c cpl_table_fill_column_window(). */ -cpl_error_code cpl_table_fill_column_window_long(cpl_table *table, - const char *name, - cpl_size start, - cpl_size count, long value) +cpl_error_code +cpl_table_fill_column_window_long(cpl_table *table, + const char *name, + cpl_size start, + cpl_size count, + long value) { - cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_fill_long(column, start, count, value) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -6772,17 +6720,18 @@ * @c cpl_table_fill_column_window(). */ -cpl_error_code cpl_table_fill_column_window_long_long(cpl_table *table, - const char *name, - cpl_size start, - cpl_size count, - long long value) +cpl_error_code +cpl_table_fill_column_window_long_long(cpl_table *table, + const char *name, + cpl_size start, + cpl_size count, + long long value) { - cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_fill_long_long(column, start, count, value) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -6841,16 +6790,18 @@ * column is filled up to its end. */ -cpl_error_code cpl_table_fill_column_window_float(cpl_table *table, - const char *name, - cpl_size start, - cpl_size count, float value) +cpl_error_code +cpl_table_fill_column_window_float(cpl_table *table, + const char *name, + cpl_size start, + cpl_size count, + float value) { - cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_fill_float(column, start, count, value) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -6909,17 +6860,18 @@ * column is filled up to its end. */ -cpl_error_code cpl_table_fill_column_window_float_complex(cpl_table *table, - const char *name, - cpl_size start, - cpl_size count, - float complex value) +cpl_error_code +cpl_table_fill_column_window_float_complex(cpl_table *table, + const char *name, + cpl_size start, + cpl_size count, + float complex value) { - cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_fill_float_complex(column, start, count, value) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -6978,17 +6930,18 @@ * column is filled up to its end. */ -cpl_error_code cpl_table_fill_column_window_double(cpl_table *table, - const char *name, - cpl_size start, - cpl_size count, - double value) +cpl_error_code +cpl_table_fill_column_window_double(cpl_table *table, + const char *name, + cpl_size start, + cpl_size count, + double value) { - cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_fill_double(column, start, count, value) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -7047,17 +7000,19 @@ * column is filled up to its end. */ -cpl_error_code cpl_table_fill_column_window_double_complex(cpl_table *table, - const char *name, - cpl_size start, - cpl_size count, - double complex value) +cpl_error_code +cpl_table_fill_column_window_double_complex(cpl_table *table, + const char *name, + cpl_size start, + cpl_size count, + double complex value) { - cpl_column *column = cpl_table_find_column_(table, name); - return !column || cpl_column_fill_double_complex(column, start, count, value) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + return !column || + cpl_column_fill_double_complex(column, start, count, value) + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -7117,17 +7072,18 @@ * filled up to its end. */ -cpl_error_code cpl_table_fill_column_window_string(cpl_table *table, - const char *name, - cpl_size start, - cpl_size count, - const char *value) +cpl_error_code +cpl_table_fill_column_window_string(cpl_table *table, + const char *name, + cpl_size start, + cpl_size count, + const char *value) { - cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_fill_string(column, start, count, value) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -7195,17 +7151,18 @@ * filled up to its end. */ -cpl_error_code cpl_table_fill_column_window_array(cpl_table *table, - const char *name, - cpl_size start, - cpl_size count, - const cpl_array *array) +cpl_error_code +cpl_table_fill_column_window_array(cpl_table *table, + const char *name, + cpl_size start, + cpl_size count, + const cpl_array *array) { - cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_fill_array(column, start, count, array) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -7257,14 +7214,17 @@ * invalidated up to its end. */ -cpl_error_code cpl_table_set_column_invalid(cpl_table *table, const char *name, - cpl_size start, cpl_size count) +cpl_error_code +cpl_table_set_column_invalid(cpl_table *table, + const char *name, + cpl_size start, + cpl_size count) { - cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_fill_invalid(column, start, count) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -7300,10 +7260,10 @@ * Check if a column element is valid. */ -int cpl_table_is_valid(const cpl_table *table, const char *name, cpl_size row) +int +cpl_table_is_valid(const cpl_table *table, const char *name, cpl_size row) { - - int validity; + int validity; cpl_errorstate prevstate = cpl_errorstate_get(); const cpl_column *column = cpl_table_find_column_const_(table, name); @@ -7320,7 +7280,6 @@ } return validity; - } @@ -7360,10 +7319,10 @@ * @c cpl_array_has_invalid(). */ -int cpl_table_has_invalid(const cpl_table *table, const char *name) +int +cpl_table_has_invalid(const cpl_table *table, const char *name) { - - int answer; + int answer; cpl_errorstate prevstate = cpl_errorstate_get(); const cpl_column *column = cpl_table_find_column_const_(table, name); @@ -7378,7 +7337,6 @@ cpl_error_set_where_(); return answer; - } @@ -7418,10 +7376,10 @@ * @c cpl_array_has_valid(). */ -int cpl_table_has_valid(const cpl_table *table, const char *name) +int +cpl_table_has_valid(const cpl_table *table, const char *name) { - - int answer; + int answer; cpl_errorstate prevstate = cpl_errorstate_get(); const cpl_column *column = cpl_table_find_column_const_(table, name); @@ -7436,7 +7394,6 @@ cpl_error_set_where_(); return answer; - } @@ -7470,9 +7427,9 @@ * Count number of invalid elements in a table column. */ -cpl_size cpl_table_count_invalid(const cpl_table *table, const char *name) +cpl_size +cpl_table_count_invalid(const cpl_table *table, const char *name) { - const cpl_column *column = cpl_table_find_column_const_(table, name); if (!column) { @@ -7481,7 +7438,6 @@ } return cpl_column_count_invalid_const(column); - } @@ -7535,11 +7491,12 @@ * Move a column from a table to another. */ -cpl_error_code cpl_table_move_column(cpl_table *to_table, - const char *name, cpl_table *from_table) +cpl_error_code +cpl_table_move_column(cpl_table *to_table, + const char *name, + cpl_table *from_table) { - - cpl_column *column; + cpl_column *column; if (to_table == NULL || from_table == NULL || name == NULL) @@ -7562,7 +7519,6 @@ cpl_table_append_column(to_table, column); return CPL_ERROR_NONE; - } @@ -7612,18 +7568,18 @@ * may be duplicated also within the same table. */ -cpl_error_code cpl_table_duplicate_column(cpl_table *to_table, - const char *to_name, - const cpl_table *from_table, - const char *from_name) +cpl_error_code +cpl_table_duplicate_column(cpl_table *to_table, + const char *to_name, + const cpl_table *from_table, + const char *from_name) { + const cpl_column *column_from; + cpl_column *column_to; - const cpl_column *column_from; - cpl_column *column_to; - - if (to_table == NULL || from_table == NULL || - to_name == NULL || from_name == NULL) + if (to_table == NULL || from_table == NULL || to_name == NULL || + from_name == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); if (to_table->nr != from_table->nr) @@ -7644,7 +7600,6 @@ cpl_table_append_column(to_table, column_to); return CPL_ERROR_NONE; - } @@ -7686,11 +7641,12 @@ * This function is used to change the name of a column. */ -cpl_error_code cpl_table_name_column(cpl_table *table, const char *from_name, - const char *to_name) +cpl_error_code +cpl_table_name_column(cpl_table *table, + const char *from_name, + const char *to_name) { - - cpl_column *column; + cpl_column *column; if (from_name == NULL || to_name == NULL || table == NULL) @@ -7705,7 +7661,6 @@ return cpl_error_set_(CPL_ERROR_DATA_NOT_FOUND); return cpl_column_set_name(column, to_name); - } @@ -7732,16 +7687,15 @@ * Check if a column with a given name exists in the specified table. */ -int cpl_table_has_column(const cpl_table *table, const char *name) +int +cpl_table_has_column(const cpl_table *table, const char *name) { - if (table == NULL || name == NULL) { cpl_error_set("cpl_table_has_column", CPL_ERROR_NULL_INPUT); return -1; } return (cpl_table_find_column_const(table, name) != NULL ? 1 : 0); - } @@ -7782,12 +7736,12 @@ * instead. */ -const char *cpl_table_get_column_name(const cpl_table *table) +const char * +cpl_table_get_column_name(const cpl_table *table) { - static const cpl_table *looking = NULL; - static cpl_size width = 0; - static cpl_size i = 0; + static cpl_size width = 0; + static cpl_size i = 0; if (table) { @@ -7806,7 +7760,6 @@ return cpl_column_get_name(looking->columns[i]); return NULL; - } @@ -7821,11 +7774,12 @@ * The returned CPL array of strings should be finally destroyed * using cpl_array_delete(). */ - -cpl_array *cpl_table_get_column_names(const cpl_table *table) + +cpl_array * +cpl_table_get_column_names(const cpl_table *table) { - cpl_array *names; - cpl_size i; + cpl_array *names; + cpl_size i; if (table == NULL) { @@ -7835,10 +7789,9 @@ names = cpl_array_new(table->nc, CPL_TYPE_STRING); for (i = 0; i < table->nc; i++) - cpl_array_set_string(names, i, cpl_column_get_name(table->columns[i])); + cpl_array_set_string(names, i, cpl_column_get_name(table->columns[i])); return names; - } @@ -7876,10 +7829,10 @@ * @c cpl_table_get_data_string(), etc. should be discarded. */ -cpl_error_code cpl_table_set_size(cpl_table *table, cpl_size new_length) +cpl_error_code +cpl_table_set_size(cpl_table *table, cpl_size new_length) { - - cpl_size width = cpl_table_get_ncol(table); + cpl_size width = cpl_table_get_ncol(table); cpl_column **column; @@ -7906,7 +7859,6 @@ table->nr = new_length; return cpl_table_select_all(table); - } @@ -7960,11 +7912,10 @@ * etc. should be discarded. */ -cpl_error_code cpl_table_set_column_depth(cpl_table *table, const char *name, - cpl_size depth) +cpl_error_code +cpl_table_set_column_depth(cpl_table *table, const char *name, cpl_size depth) { - - cpl_size length; + cpl_size length; cpl_column *column = cpl_table_find_column_type(table, name, CPL_TYPE_POINTER); @@ -7989,7 +7940,6 @@ } return CPL_ERROR_NONE; - } @@ -8007,13 +7957,13 @@ * table are transferred to the new table. */ -cpl_table *cpl_table_duplicate(const cpl_table *table) +cpl_table * +cpl_table_duplicate(const cpl_table *table) { - - cpl_size length = cpl_table_get_nrow(table); - cpl_size width = cpl_table_get_ncol(table); - cpl_size i; - cpl_table *new_table = NULL; + cpl_size length = cpl_table_get_nrow(table); + cpl_size width = cpl_table_get_ncol(table); + cpl_size i; + cpl_table *new_table = NULL; cpl_column *column; @@ -8023,11 +7973,9 @@ return NULL; if (table->select) { - new_table->select = cpl_malloc(length * sizeof(cpl_column_flag)); memcpy(new_table->select, table->select, length * sizeof(cpl_column_flag)); - } new_table->selectcount = table->selectcount; @@ -8038,7 +7986,6 @@ } return new_table; - } @@ -8085,15 +8032,14 @@ * transferred from the old table to the new one. */ -cpl_table *cpl_table_extract(const cpl_table *table, - cpl_size start, cpl_size count) +cpl_table * +cpl_table_extract(const cpl_table *table, cpl_size start, cpl_size count) { - - cpl_size width = cpl_table_get_ncol(table); - cpl_size length = cpl_table_get_nrow(table); - cpl_size i; - cpl_table *new_table = NULL; - cpl_column *column = NULL; + cpl_size width = cpl_table_get_ncol(table); + cpl_size length = cpl_table_get_nrow(table); + cpl_size i; + cpl_table *new_table = NULL; + cpl_column *column = NULL; if (table == NULL) { @@ -8109,8 +8055,7 @@ for (i = 0; i < width; i++) { column = cpl_column_extract(table->columns[i], start, count); if (column) { - cpl_column_set_name(column, - cpl_column_get_name(table->columns[i])); + cpl_column_set_name(column, cpl_column_get_name(table->columns[i])); cpl_table_append_column(new_table, column); } else { @@ -8121,7 +8066,6 @@ } return new_table; - } @@ -8237,14 +8181,16 @@ * should be discarded. */ -cpl_error_code cpl_table_cast_column(cpl_table *table, const char *from_name, - const char *to_name, cpl_type type) -{ - - int in_place = 0; - cpl_size depth = 0; - int array = 0; - cpl_column *column = cpl_table_find_column_(table, from_name); +cpl_error_code +cpl_table_cast_column(cpl_table *table, + const char *from_name, + const char *to_name, + cpl_type type) +{ + int in_place = 0; + cpl_size depth = 0; + int array = 0; + cpl_column *column = cpl_table_find_column_(table, from_name); if (!column) { return cpl_error_set_where_(); @@ -8305,8 +8251,8 @@ if (in_place) if (depth > 1) - if (cpl_table_get_column_type(table, from_name) == - (type | CPL_TYPE_POINTER)) + if (cpl_table_get_column_type(table, from_name) == + (type | CPL_TYPE_POINTER)) return CPL_ERROR_NONE; /* @@ -8345,7 +8291,7 @@ column = cpl_column_cast_to_double_complex_array(column); break; default: - return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); + return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); } } else if (depth == 1 && array == 0) { @@ -8374,7 +8320,7 @@ column = cpl_column_cast_to_double_complex_flat(column); break; default: - return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); + return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); } } else { @@ -8403,7 +8349,7 @@ column = cpl_column_cast_to_double_complex(column); break; default: - return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); + return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); } } @@ -8468,16 +8414,18 @@ * overflows are ignored. */ -cpl_error_code cpl_table_add_columns(cpl_table *table, const char *to_name, - const char *from_name) +cpl_error_code +cpl_table_add_columns(cpl_table *table, + const char *to_name, + const char *from_name) { - cpl_column *to_column = cpl_table_find_column_(table, to_name); /* FIXME: Should be const */ cpl_column *from_column = cpl_table_find_column_(table, from_name); return !to_column || !from_column || cpl_column_add(to_column, from_column) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -8520,18 +8468,19 @@ * the function @c cpl_table_add_columns() for further details. */ -cpl_error_code cpl_table_subtract_columns(cpl_table *table, - const char *to_name, - const char *from_name) +cpl_error_code +cpl_table_subtract_columns(cpl_table *table, + const char *to_name, + const char *from_name) { - cpl_column *to_column = cpl_table_find_column_(table, to_name); /* FIXME: Should be const */ cpl_column *from_column = cpl_table_find_column_(table, from_name); return !to_column || !from_column || - cpl_column_subtract(to_column, from_column) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + cpl_column_subtract(to_column, from_column) + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -8574,18 +8523,19 @@ * the function @c cpl_table_add_columns() for further details. */ -cpl_error_code cpl_table_multiply_columns(cpl_table *table, - const char *to_name, - const char *from_name) +cpl_error_code +cpl_table_multiply_columns(cpl_table *table, + const char *to_name, + const char *from_name) { - cpl_column *to_column = cpl_table_find_column_(table, to_name); /* FIXME: Should be const */ cpl_column *from_column = cpl_table_find_column_(table, from_name); return !to_column || !from_column || - cpl_column_multiply(to_column, from_column) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + cpl_column_multiply(to_column, from_column) + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -8633,17 +8583,19 @@ * division by exactly zero will set an invalid column element. */ -cpl_error_code cpl_table_divide_columns(cpl_table *table, const char *to_name, - const char *from_name) +cpl_error_code +cpl_table_divide_columns(cpl_table *table, + const char *to_name, + const char *from_name) { - cpl_column *to_column = cpl_table_find_column_(table, to_name); /* FIXME: Should be const */ cpl_column *from_column = cpl_table_find_column_(table, from_name); return !to_column || !from_column || - cpl_column_divide(to_column, from_column) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + cpl_column_divide(to_column, from_column) + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -8686,14 +8638,14 @@ * are not modified by this operation. */ -cpl_error_code cpl_table_add_scalar(cpl_table *table, const char *name, - double value) +cpl_error_code +cpl_table_add_scalar(cpl_table *table, const char *name, double value) { - cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_add_scalar(column, value) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -8736,14 +8688,16 @@ * are not modified by this operation. */ -cpl_error_code cpl_table_add_scalar_complex(cpl_table *table, const char *name, - double complex value) +cpl_error_code +cpl_table_add_scalar_complex(cpl_table *table, + const char *name, + double complex value) { - cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_add_scalar_complex(column, value) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -8784,14 +8738,14 @@ * See the description of the function @c cpl_table_add_scalar(). */ -cpl_error_code cpl_table_subtract_scalar(cpl_table *table, const char *name, - double value) +cpl_error_code +cpl_table_subtract_scalar(cpl_table *table, const char *name, double value) { - cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_subtract_scalar(column, value) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -8832,16 +8786,16 @@ * See the description of the function @c cpl_table_add_scalar_complex(). */ -cpl_error_code cpl_table_subtract_scalar_complex(cpl_table *table, - const char *name, - double complex value) +cpl_error_code +cpl_table_subtract_scalar_complex(cpl_table *table, + const char *name, + double complex value) { - cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_subtract_scalar_complex(column, value) - ? cpl_error_set_where_() : CPL_ERROR_NONE; - + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -8882,14 +8836,14 @@ * See the description of the function @c cpl_table_add_scalar(). */ -cpl_error_code cpl_table_multiply_scalar(cpl_table *table, const char *name, - double value) +cpl_error_code +cpl_table_multiply_scalar(cpl_table *table, const char *name, double value) { - cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_multiply_scalar(column, value) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -8930,16 +8884,16 @@ * See the description of the function @c cpl_table_add_scalar_complex(). */ -cpl_error_code cpl_table_multiply_scalar_complex(cpl_table *table, - const char *name, - double complex value) +cpl_error_code +cpl_table_multiply_scalar_complex(cpl_table *table, + const char *name, + double complex value) { - cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_multiply_scalar_complex(column, value) - ? cpl_error_set_where_() : CPL_ERROR_NONE; - + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -8988,14 +8942,14 @@ * not modified by this operation. */ -cpl_error_code cpl_table_divide_scalar(cpl_table *table, const char *name, - double value) +cpl_error_code +cpl_table_divide_scalar(cpl_table *table, const char *name, double value) { - cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_divide_scalar(column, value) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -9045,15 +8999,16 @@ */ -cpl_error_code cpl_table_divide_scalar_complex(cpl_table *table, - const char *name, - double complex value) +cpl_error_code +cpl_table_divide_scalar_complex(cpl_table *table, + const char *name, + double complex value) { - cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_divide_scalar_complex(column, value) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -9098,10 +9053,10 @@ * and @c cpl_array_get_data_double_complex() should be discarded. */ -cpl_error_code cpl_table_abs_column(cpl_table *table, const char *name) +cpl_error_code +cpl_table_abs_column(cpl_table *table, const char *name) { - - cpl_type type; + cpl_type type; cpl_column *column = cpl_table_find_column_(table, name); if (!column) { @@ -9127,7 +9082,6 @@ } return CPL_ERROR_NONE; - } @@ -9185,14 +9139,14 @@ * be expressed as (5.00, -4.06). */ -cpl_error_code cpl_table_logarithm_column(cpl_table *table, const char *name, - double base) +cpl_error_code +cpl_table_logarithm_column(cpl_table *table, const char *name, double base) { - cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_logarithm(column, base) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -9242,14 +9196,14 @@ * not modified by this operation. */ -cpl_error_code cpl_table_exponential_column(cpl_table *table, - const char *name, double base) +cpl_error_code +cpl_table_exponential_column(cpl_table *table, const char *name, double base) { - cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_exponential(column, base) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -9298,13 +9252,13 @@ * not modified by this operation. */ -cpl_error_code cpl_table_conjugate_column(cpl_table *table, const char *name) +cpl_error_code +cpl_table_conjugate_column(cpl_table *table, const char *name) { - cpl_column *column = cpl_table_find_column_(table, name); - return !column || cpl_column_conjugate(column) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + return !column || cpl_column_conjugate(column) ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -9349,14 +9303,14 @@ * overflow are marked as invalid. */ -cpl_error_code cpl_table_power_column(cpl_table *table, const char *name, - double exponent) +cpl_error_code +cpl_table_power_column(cpl_table *table, const char *name, double exponent) { - cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_power(column, exponent) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -9402,10 +9356,10 @@ * @c cpl_table_get_data_double_complex(), etc., should be discarded. */ -cpl_error_code cpl_table_arg_column(cpl_table *table, const char *name) +cpl_error_code +cpl_table_arg_column(cpl_table *table, const char *name) { - - cpl_type type; + cpl_type type; cpl_column *column = cpl_table_find_column_(table, name); if (!column) { @@ -9426,30 +9380,29 @@ return cpl_error_set_where_(); } else { - float *fdata; + float *fdata; double *ddata; - int length = cpl_table_get_nrow(table); + int length = cpl_table_get_nrow(table); switch (type) { - case CPL_TYPE_FLOAT: - if (length) { - fdata = cpl_table_get_data_float(table, name); - memset(fdata, 0.0, length * sizeof(float)); // keep NULLs - } - break; - case CPL_TYPE_DOUBLE: - if (length) { - ddata = cpl_table_get_data_double(table, name); - memset(ddata, 0.0, length * sizeof(double)); - } - break; - default: - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + case CPL_TYPE_FLOAT: + if (length) { + fdata = cpl_table_get_data_float(table, name); + memset(fdata, 0.0, length * sizeof(float)); // keep NULLs + } + break; + case CPL_TYPE_DOUBLE: + if (length) { + ddata = cpl_table_get_data_double(table, name); + memset(ddata, 0.0, length * sizeof(double)); + } + break; + default: + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } } return CPL_ERROR_NONE; - } @@ -9494,10 +9447,10 @@ * @c cpl_table_get_data_double_complex(), etc., should be discarded. */ -cpl_error_code cpl_table_real_column(cpl_table *table, const char *name) +cpl_error_code +cpl_table_real_column(cpl_table *table, const char *name) { - - cpl_type type; + cpl_type type; cpl_column *column = cpl_table_find_column_(table, name); if (!column) { @@ -9519,16 +9472,15 @@ } else { switch (type) { - case CPL_TYPE_FLOAT: - case CPL_TYPE_DOUBLE: - break; - default: - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + case CPL_TYPE_FLOAT: + case CPL_TYPE_DOUBLE: + break; + default: + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } } return CPL_ERROR_NONE; - } @@ -9573,10 +9525,10 @@ * @c cpl_table_get_data_double_complex(), etc., should be discarded. */ -cpl_error_code cpl_table_imag_column(cpl_table *table, const char *name) +cpl_error_code +cpl_table_imag_column(cpl_table *table, const char *name) { - - cpl_type type; + cpl_type type; cpl_column *column = cpl_table_find_column_(table, name); if (!column) { @@ -9597,30 +9549,29 @@ return cpl_error_set_where_(); } else { - float *fdata; + float *fdata; double *ddata; - int length = cpl_table_get_nrow(table); + int length = cpl_table_get_nrow(table); switch (type) { - case CPL_TYPE_FLOAT: - if (length) { - fdata = cpl_table_get_data_float(table, name); - memset(fdata, 0.0, length * sizeof(float)); // keep NULLs - } - break; - case CPL_TYPE_DOUBLE: - if (length) { - ddata = cpl_table_get_data_double(table, name); - memset(ddata, 0.0, length * sizeof(double)); - } - break; - default: - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + case CPL_TYPE_FLOAT: + if (length) { + fdata = cpl_table_get_data_float(table, name); + memset(fdata, 0.0, length * sizeof(float)); // keep NULLs + } + break; + case CPL_TYPE_DOUBLE: + if (length) { + ddata = cpl_table_get_data_double(table, name); + memset(ddata, 0.0, length * sizeof(double)); + } + break; + default: + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } } return CPL_ERROR_NONE; - } @@ -9662,10 +9613,10 @@ * selection flags have no influence on the result. */ -double cpl_table_get_column_mean(const cpl_table *table, const char *name) +double +cpl_table_get_column_mean(const cpl_table *table, const char *name) { - - double mean; + double mean; cpl_errorstate prevstate = cpl_errorstate_get(); const cpl_column *column = cpl_table_find_column_const_(table, name); @@ -9680,7 +9631,6 @@ cpl_error_set_where_(); return mean; - } @@ -9722,10 +9672,9 @@ * selection flags have no influence on the result. */ -double complex cpl_table_get_column_mean_complex(const cpl_table *table, - const char *name) +double complex +cpl_table_get_column_mean_complex(const cpl_table *table, const char *name) { - double complex mean; cpl_errorstate prevstate = cpl_errorstate_get(); const cpl_column *column = cpl_table_find_column_const_(table, name); @@ -9741,7 +9690,6 @@ cpl_error_set_where_(); return mean; - } @@ -9757,10 +9705,10 @@ * See the description of the function @c cpl_table_get_column_mean(). */ -double cpl_table_get_column_median(const cpl_table *table, const char *name) +double +cpl_table_get_column_median(const cpl_table *table, const char *name) { - - double median; + double median; cpl_errorstate prevstate = cpl_errorstate_get(); const cpl_column *column = cpl_table_find_column_const_(table, name); @@ -9775,7 +9723,6 @@ cpl_error_set_where_(); return median; - } @@ -9820,10 +9767,10 @@ * influence on the result. */ -double cpl_table_get_column_stdev(const cpl_table *table, const char *name) +double +cpl_table_get_column_stdev(const cpl_table *table, const char *name) { - - double stdev; + double stdev; cpl_errorstate prevstate = cpl_errorstate_get(); const cpl_column *column = cpl_table_find_column_const_(table, name); @@ -9838,7 +9785,6 @@ cpl_error_set_where_(); return stdev; - } @@ -9854,10 +9800,10 @@ * See the description of the function @c cpl_table_get_column_mean(). */ -double cpl_table_get_column_max(const cpl_table *table, const char *name) +double +cpl_table_get_column_max(const cpl_table *table, const char *name) { - - double max; + double max; cpl_errorstate prevstate = cpl_errorstate_get(); const cpl_column *column = cpl_table_find_column_const_(table, name); @@ -9872,7 +9818,6 @@ cpl_error_set_where_(); return max; - } @@ -9888,10 +9833,10 @@ * See the description of the function @c cpl_table_get_column_mean(). */ -double cpl_table_get_column_min(const cpl_table *table, const char *name) +double +cpl_table_get_column_min(const cpl_table *table, const char *name) { - - double min; + double min; cpl_errorstate prevstate = cpl_errorstate_get(); const cpl_column *column = cpl_table_find_column_const_(table, name); @@ -9906,7 +9851,6 @@ cpl_error_set_where_(); return min; - } @@ -9953,14 +9897,16 @@ * influence on the result. */ -cpl_error_code cpl_table_get_column_maxpos(const cpl_table *table, - const char *name, cpl_size *row) +cpl_error_code +cpl_table_get_column_maxpos(const cpl_table *table, + const char *name, + cpl_size *row) { - const cpl_column *column = cpl_table_find_column_const_(table, name); return !column || cpl_column_get_maxpos(column, row) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -9977,14 +9923,16 @@ * See the description of the function @c cpl_table_get_column_maxpos(). */ -cpl_error_code cpl_table_get_column_minpos(const cpl_table *table, - const char *name, cpl_size *row) +cpl_error_code +cpl_table_get_column_minpos(const cpl_table *table, + const char *name, + cpl_size *row) { - const cpl_column *column = cpl_table_find_column_const_(table, name); return !column || cpl_column_get_minpos(column, row) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -10019,29 +9967,27 @@ * deleted. */ -cpl_error_code cpl_table_erase_invalid_rows(cpl_table *table) +cpl_error_code +cpl_table_erase_invalid_rows(cpl_table *table) { - - cpl_size length = cpl_table_get_nrow(table); - cpl_size width = cpl_table_get_ncol(table); - cpl_size new_width; - cpl_size count = 0; - int any_valid; - int all_valid = 0; + cpl_size length = cpl_table_get_nrow(table); + cpl_size width = cpl_table_get_ncol(table); + cpl_size new_width; + cpl_size count = 0; + int any_valid; + int all_valid = 0; if (table == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); while (width--) { - if (!cpl_column_has_valid(table->columns[width])) cpl_table_erase_column(table, - cpl_column_get_name(table->columns[width])); + cpl_column_get_name(table->columns[width])); else if (!cpl_column_has_invalid(table->columns[width])) all_valid = 1; - } if (all_valid) @@ -10053,7 +9999,6 @@ return CPL_ERROR_NONE; while (length--) { - width = new_width; any_valid = 0; @@ -10064,22 +10009,20 @@ } } - if (any_valid) { /* Current row does not contain just invalids */ - if (count) { /* End of segment of just invalids */ + if (any_valid) { /* Current row does not contain just invalids */ + if (count) { /* End of segment of just invalids */ cpl_table_erase_window(table, length + 1, count); count = 0; } } - else /* Current row just contains invalids */ + else /* Current row just contains invalids */ count++; - } - if (count) /* The first table row is invalid */ + if (count) /* The first table row is invalid */ cpl_table_erase_window(table, 0, count); return cpl_table_select_all(table); - } @@ -10125,26 +10068,26 @@ * cpl_table_erase_invalid_rows() */ -cpl_error_code cpl_table_erase_invalid(cpl_table *table) +cpl_error_code +cpl_table_erase_invalid(cpl_table *table) { - - cpl_size length = 0; - cpl_size width = 0; - cpl_size new_width; - cpl_size count = 0; - int any_null; + cpl_size length = 0; + cpl_size width = 0; + cpl_size new_width; + cpl_size count = 0; + int any_null; if (table == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); length = cpl_table_get_nrow(table); - width = cpl_table_get_ncol(table); + width = cpl_table_get_ncol(table); while (width--) if (!cpl_column_has_valid(table->columns[width])) cpl_table_erase_column(table, - cpl_column_get_name(table->columns[width])); + cpl_column_get_name(table->columns[width])); new_width = cpl_table_get_ncol(table); @@ -10152,7 +10095,6 @@ return CPL_ERROR_NONE; while (length--) { - width = new_width; any_null = 0; @@ -10163,23 +10105,21 @@ } } - if (any_null) { /* Current row contains at least an invalid */ + if (any_null) { /* Current row contains at least an invalid */ count++; } - else { /* Current row contains no invalids */ - if (count) { /* End of segment of rows with some invalids */ + else { /* Current row contains no invalids */ + if (count) { /* End of segment of rows with some invalids */ cpl_table_erase_window(table, length + 1, count); count = 0; } } - } - if (count) /* The first table row has at least a NULL */ + if (count) /* The first table row has at least a NULL */ cpl_table_erase_window(table, 0, count); return cpl_table_select_all(table); - } @@ -10213,11 +10153,9 @@ * Flag a table row as selected. Any previous selection is kept. */ -cpl_error_code cpl_table_select_row(cpl_table *table, cpl_size row) +cpl_error_code +cpl_table_select_row(cpl_table *table, cpl_size row) { - - - if (table == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -10241,7 +10179,6 @@ } return CPL_ERROR_NONE; - } @@ -10269,11 +10206,9 @@ * table. */ -cpl_error_code cpl_table_select_all(cpl_table *table) +cpl_error_code +cpl_table_select_all(cpl_table *table) { - - - if (table == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -10283,7 +10218,6 @@ table->selectcount = table->nr; return CPL_ERROR_NONE; - } @@ -10317,10 +10251,10 @@ * Flag a table row as unselected. Any previous selection is kept. */ -cpl_error_code cpl_table_unselect_row(cpl_table *table, cpl_size row) +cpl_error_code +cpl_table_unselect_row(cpl_table *table, cpl_size row) { - - int length; + int length; if (table == NULL) @@ -10353,7 +10287,6 @@ } return CPL_ERROR_NONE; - } @@ -10380,9 +10313,9 @@ * rows are selected. */ -cpl_error_code cpl_table_unselect_all(cpl_table *table) +cpl_error_code +cpl_table_unselect_all(cpl_table *table) { - if (table == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -10392,7 +10325,6 @@ table->selectcount = 0; return CPL_ERROR_NONE; - } @@ -10416,11 +10348,11 @@ * used for printing is the standard C @c fprintf(). */ -void cpl_table_dump_structure(const cpl_table *table, FILE *stream) +void +cpl_table_dump_structure(const cpl_table *table, FILE *stream) { - cpl_size width = cpl_table_get_ncol(table); - cpl_size i = 0; + cpl_size i = 0; if (stream == NULL) @@ -10432,9 +10364,9 @@ } if (width > 0) - fprintf(stream, "Table with %" CPL_SIZE_FORMAT - "/%" CPL_SIZE_FORMAT " selected rows and %" - CPL_SIZE_FORMAT " columns:\n\n", + fprintf(stream, + "Table with %" CPL_SIZE_FORMAT "/%" CPL_SIZE_FORMAT + " selected rows and %" CPL_SIZE_FORMAT " columns:\n\n", table->selectcount, table->nr, table->nc); while (i < width) { @@ -10456,46 +10388,46 @@ switch (_cpl_columntype_get_valuetype(type_id)) { - case CPL_TYPE_INT: - type_name = "integer"; - break; - case CPL_TYPE_LONG: - type_name = "long integer"; - break; - case CPL_TYPE_LONG_LONG: - type_name = "long long integer"; - break; - case CPL_TYPE_FLOAT: - type_name = "float"; - break; - case CPL_TYPE_DOUBLE: - type_name = "double"; - break; - case CPL_TYPE_STRING: - type_name = "string"; - break; - case CPL_TYPE_FLOAT_COMPLEX: - type_name = "float complex"; - break; - case CPL_TYPE_DOUBLE_COMPLEX: - type_name = "double complex"; - break; - default: - break; + case CPL_TYPE_INT: + type_name = "integer"; + break; + case CPL_TYPE_LONG: + type_name = "long integer"; + break; + case CPL_TYPE_LONG_LONG: + type_name = "long long integer"; + break; + case CPL_TYPE_FLOAT: + type_name = "float"; + break; + case CPL_TYPE_DOUBLE: + type_name = "double"; + break; + case CPL_TYPE_STRING: + type_name = "string"; + break; + case CPL_TYPE_FLOAT_COMPLEX: + type_name = "float complex"; + break; + case CPL_TYPE_DOUBLE_COMPLEX: + type_name = "double complex"; + break; + default: + break; } if (_cpl_columntype_is_pointer(type_id)) { fprintf(stream, "arrays of "); } - fprintf(stream, "%s elements, of which %" CPL_SIZE_FORMAT " are " - "flagged invalid.\n", type_name, - cpl_column_count_invalid(table->columns[i])); + fprintf(stream, + "%s elements, of which %" CPL_SIZE_FORMAT " are " + "flagged invalid.\n", + type_name, cpl_column_count_invalid(table->columns[i])); i++; } return; - } @@ -10529,22 +10461,24 @@ * The function used for printing is the standard C @c fprintf(). */ -void cpl_table_dump(const cpl_table *table, - cpl_size start, cpl_size count, FILE *stream) -{ - - cpl_size size; - cpl_size nc = cpl_table_get_ncol(table); - cpl_size offset; - cpl_size i, j, k; - cpl_size end; - int *field_size; - int *label_len; - int row; - char **fields; - char *row_field; - int null; - int found; +void +cpl_table_dump(const cpl_table *table, + cpl_size start, + cpl_size count, + FILE *stream) +{ + cpl_size size; + cpl_size nc = cpl_table_get_ncol(table); + cpl_size offset; + cpl_size i, j, k; + cpl_size end; + int *field_size; + int *label_len; + int row; + char **fields; + char *row_field; + int null; + int found; if (stream == NULL) @@ -10583,156 +10517,170 @@ const cpl_type type_id = cpl_column_get_type(table->columns[j]); label_len[j] = field_size[j] = - strlen(cpl_column_get_name(table->columns[j])); + strlen(cpl_column_get_name(table->columns[j])); if (!_cpl_columntype_is_pointer(type_id)) { - switch (_cpl_columntype_get_valuetype(type_id)) { + case CPL_TYPE_INT: + for (i = start; i < end; i++) { + int inum = + cpl_column_get_int(table->columns[j], i, &null); - case CPL_TYPE_INT: - for (i = start; i < end; i++) { - int inum = cpl_column_get_int(table->columns[j], i, &null); - - if (null) - size = 4; - else - size = cx_snprintf(NULL, 0, - cpl_column_get_format(table->columns[j]), - inum); + if (null) + size = 4; + else + size = cx_snprintf(NULL, 0, + cpl_column_get_format( + table->columns[j]), + inum); - if (size > field_size[j]) - field_size[j] = size; - } - break; + if (size > field_size[j]) + field_size[j] = size; + } + break; - case CPL_TYPE_LONG: - for (i = start; i < end; i++) { - long lnum = cpl_column_get_long(table->columns[j], i, &null); + case CPL_TYPE_LONG: + for (i = start; i < end; i++) { + long lnum = + cpl_column_get_long(table->columns[j], i, &null); - if (null) - size = 4; - else - size = cx_snprintf(NULL, 0, - cpl_column_get_format(table->columns[j]), - lnum); + if (null) + size = 4; + else + size = cx_snprintf(NULL, 0, + cpl_column_get_format( + table->columns[j]), + lnum); - if (size > field_size[j]) - field_size[j] = size; - } - break; + if (size > field_size[j]) + field_size[j] = size; + } + break; - case CPL_TYPE_LONG_LONG: - for (i = start; i < end; i++) { - long long llnum = cpl_column_get_long_long(table->columns[j], i, - &null); - - if (null) - size = 4; - else - size = cx_snprintf(NULL, 0, - cpl_column_get_format(table->columns[j]), - llnum); + case CPL_TYPE_LONG_LONG: + for (i = start; i < end; i++) { + long long llnum = + cpl_column_get_long_long(table->columns[j], i, + &null); - if (size > field_size[j]) - field_size[j] = size; - } - break; + if (null) + size = 4; + else + size = cx_snprintf(NULL, 0, + cpl_column_get_format( + table->columns[j]), + llnum); - case CPL_TYPE_FLOAT: - for (i = start; i < end; i++) { - float fnum = cpl_column_get_float(table->columns[j], i, &null); + if (size > field_size[j]) + field_size[j] = size; + } + break; - if (null) - size = 4; - else - size = cx_snprintf(NULL, 0, - cpl_column_get_format(table->columns[j]), - fnum); + case CPL_TYPE_FLOAT: + for (i = start; i < end; i++) { + float fnum = + cpl_column_get_float(table->columns[j], i, &null); - if (size > field_size[j]) - field_size[j] = size; - } - break; + if (null) + size = 4; + else + size = cx_snprintf(NULL, 0, + cpl_column_get_format( + table->columns[j]), + fnum); - case CPL_TYPE_DOUBLE: - for (i = start; i < end; i++) { - double dnum = cpl_column_get_double(table->columns[j], i, - &null); - - if (null) - size = 4; - else - size = cx_snprintf(NULL, 0, - cpl_column_get_format(table->columns[j]), - dnum); + if (size > field_size[j]) + field_size[j] = size; + } + break; - if (size > field_size[j]) - field_size[j] = size; - } - break; + case CPL_TYPE_DOUBLE: + for (i = start; i < end; i++) { + double dnum = + cpl_column_get_double(table->columns[j], i, &null); - case CPL_TYPE_FLOAT_COMPLEX: - for (i = start; i < end; i++) { - float complex cfnum = - cpl_column_get_float_complex(table->columns[j], i, - &null); + if (null) + size = 4; + else + size = cx_snprintf(NULL, 0, + cpl_column_get_format( + table->columns[j]), + dnum); - if (null) - size = 4; - else - size = 3 + cx_snprintf(NULL, 0, - cpl_column_get_format(table->columns[j]), - crealf(cfnum)) - + cx_snprintf(NULL, 0, - cpl_column_get_format(table->columns[j]), - cimagf(cfnum)); + if (size > field_size[j]) + field_size[j] = size; + } + break; - if (size > field_size[j]) - field_size[j] = size; - } - break; + case CPL_TYPE_FLOAT_COMPLEX: + for (i = start; i < end; i++) { + float complex cfnum = + cpl_column_get_float_complex(table->columns[j], i, + &null); - case CPL_TYPE_DOUBLE_COMPLEX: - for (i = start; i < end; i++) { - double complex cdnum = + if (null) + size = 4; + else + size = 3 + + cx_snprintf(NULL, 0, + cpl_column_get_format( + table->columns[j]), + crealf(cfnum)) + + cx_snprintf(NULL, 0, + cpl_column_get_format( + table->columns[j]), + cimagf(cfnum)); + + if (size > field_size[j]) + field_size[j] = size; + } + break; + + case CPL_TYPE_DOUBLE_COMPLEX: + for (i = start; i < end; i++) { + double complex cdnum = cpl_column_get_double_complex(table->columns[j], i, &null); - if (null) - size = 4; - else - size = 3 + cx_snprintf(NULL, 0, - cpl_column_get_format(table->columns[j]), - creal(cdnum)) - + cx_snprintf(NULL, 0, - cpl_column_get_format(table->columns[j]), - cimag(cdnum)); + if (null) + size = 4; + else + size = 3 + + cx_snprintf(NULL, 0, + cpl_column_get_format( + table->columns[j]), + creal(cdnum)) + + cx_snprintf(NULL, 0, + cpl_column_get_format( + table->columns[j]), + cimag(cdnum)); - if (size > field_size[j]) - field_size[j] = size; - } - break; + if (size > field_size[j]) + field_size[j] = size; + } + break; - case CPL_TYPE_STRING: - for (i = start; i < end; i++) { - char *string = (char *)cpl_column_get_string(table->columns[j], - i); - - if (string == NULL) - size = 4; - else - size = cx_snprintf(NULL, 0, - cpl_column_get_format(table->columns[j]), - string); + case CPL_TYPE_STRING: + for (i = start; i < end; i++) { + char *string = + (char *)cpl_column_get_string(table->columns[j], i); - if (size > field_size[j]) - field_size[j] = size; - } - break; + if (string == NULL) + size = 4; + else + size = cx_snprintf(NULL, 0, + cpl_column_get_format( + table->columns[j]), + string); - default: - field_size[j] = 4; - break; + if (size > field_size[j]) + field_size[j] = size; + } + break; + + default: + field_size[j] = 4; + break; } } @@ -10740,7 +10688,6 @@ label_len[j]++; fields[j] = cpl_malloc(field_size[j] * sizeof(char)); - } fprintf(stream, "%s ", row_field); @@ -10750,7 +10697,7 @@ for (i = 0; i < offset; i++) fields[j][i] = ' '; cx_snprintf(fields[j] + offset, label_len[j], "%s", - cpl_column_get_name(table->columns[j])); + cpl_column_get_name(table->columns[j])); for (i = label_len[j] + offset - 1; i < field_size[j]; i++) fields[j][i] = ' '; fields[j][field_size[j] - 1] = '\0'; @@ -10761,15 +10708,12 @@ for (i = start; i < end; i++) { - fprintf(stream, "%*" CPL_SIZE_FORMAT " ", row, i); for (j = 0; j < nc; j++) { - cpl_type type_id = cpl_column_get_type(table->columns[j]); if (_cpl_columntype_is_pointer(type_id)) { - cpl_array *array = cpl_column_get_array(table->columns[j], i); if (!array) { @@ -10780,15 +10724,12 @@ } fields[j][field_size[j] - 1] = '\0'; - } else { - switch (_cpl_columntype_get_valuetype(type_id)) { - - case CPL_TYPE_INT: - { - int inum = cpl_column_get_int(table->columns[j], i, &null); + case CPL_TYPE_INT: { + int inum = + cpl_column_get_int(table->columns[j], i, &null); if (null) { memset(fields[j], '-', field_size[j]); @@ -10796,13 +10737,15 @@ } else cx_snprintf(fields[j], field_size[j], - cpl_column_get_format(table->columns[j]), inum); + cpl_column_get_format( + table->columns[j]), + inum); break; } - case CPL_TYPE_LONG: - { - long lnum = cpl_column_get_long(table->columns[j], i, &null); + case CPL_TYPE_LONG: { + long lnum = + cpl_column_get_long(table->columns[j], i, &null); if (null) { memset(fields[j], '-', field_size[j]); @@ -10810,14 +10753,16 @@ } else cx_snprintf(fields[j], field_size[j], - cpl_column_get_format(table->columns[j]), lnum); + cpl_column_get_format( + table->columns[j]), + lnum); break; } - case CPL_TYPE_LONG_LONG: - { - long long llnum = cpl_column_get_long_long(table->columns[j], i, - &null); + case CPL_TYPE_LONG_LONG: { + long long llnum = + cpl_column_get_long_long(table->columns[j], i, + &null); if (null) { memset(fields[j], '-', field_size[j]); @@ -10825,13 +10770,15 @@ } else cx_snprintf(fields[j], field_size[j], - cpl_column_get_format(table->columns[j]), llnum); + cpl_column_get_format( + table->columns[j]), + llnum); break; } - case CPL_TYPE_FLOAT: - { - float fnum = cpl_column_get_float(table->columns[j], i, &null); + case CPL_TYPE_FLOAT: { + float fnum = + cpl_column_get_float(table->columns[j], i, &null); if (null) { memset(fields[j], '-', field_size[j]); @@ -10839,14 +10786,15 @@ } else cx_snprintf(fields[j], field_size[j], - cpl_column_get_format(table->columns[j]), fnum); + cpl_column_get_format( + table->columns[j]), + fnum); break; } - case CPL_TYPE_DOUBLE: - { - double dnum = cpl_column_get_double(table->columns[j], i, - &null); + case CPL_TYPE_DOUBLE: { + double dnum = + cpl_column_get_double(table->columns[j], i, &null); if (null) { memset(fields[j], '-', field_size[j]); @@ -10854,24 +10802,26 @@ } else cx_snprintf(fields[j], field_size[j], - cpl_column_get_format(table->columns[j]), dnum); + cpl_column_get_format( + table->columns[j]), + dnum); break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { float complex cfnum = - cpl_column_get_float_complex(table->columns[j], i, - &null); + cpl_column_get_float_complex(table->columns[j], i, + &null); if (null) { memset(fields[j], '-', field_size[j]); fields[j][field_size[j] - 1] = '\0'; } else { - char *s = cpl_sprintf("(%s,%s)", - cpl_column_get_format(table->columns[j]), - cpl_column_get_format(table->columns[j])); + char *s = cpl_sprintf( + "(%s,%s)", + cpl_column_get_format(table->columns[j]), + cpl_column_get_format(table->columns[j])); cx_snprintf(fields[j], field_size[j], s, crealf(cfnum), cimagf(cfnum)); @@ -10880,20 +10830,20 @@ break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { double complex cdnum = - cpl_column_get_double_complex(table->columns[j], i, - &null); + cpl_column_get_double_complex(table->columns[j], i, + &null); if (null) { memset(fields[j], '-', field_size[j]); fields[j][field_size[j] - 1] = '\0'; } else { - char *s = cpl_sprintf("(%s,%s)", - cpl_column_get_format(table->columns[j]), - cpl_column_get_format(table->columns[j])); + char *s = cpl_sprintf( + "(%s,%s)", + cpl_column_get_format(table->columns[j]), + cpl_column_get_format(table->columns[j])); cx_snprintf(fields[j], field_size[j], s, creal(cdnum), cimag(cdnum)); @@ -10902,10 +10852,9 @@ break; } - case CPL_TYPE_STRING: - { + case CPL_TYPE_STRING: { char *string = - (char *)cpl_column_get_string(table->columns[j], i); + (char *)cpl_column_get_string(table->columns[j], i); if (!string) { memset(fields[j], '-', field_size[j]); @@ -10913,13 +10862,15 @@ } else cx_snprintf(fields[j], field_size[j], - cpl_column_get_format(table->columns[j]), string); + cpl_column_get_format( + table->columns[j]), + string); break; } - default: - { - cpl_array *array = cpl_column_get_array(table->columns[j], i); + default: { + cpl_array *array = + cpl_column_get_array(table->columns[j], i); if (!array) { memset(fields[j], '-', field_size[j]); @@ -10934,10 +10885,10 @@ found = 0; for (k = 0; k < field_size[j]; k++) { - if (fields[j][k] == '\0') - found = 1; - if (found) - fields[j][k] = ' '; + if (fields[j][k] == '\0') + found = 1; + if (found) + fields[j][k] = ' '; } fields[j][field_size[j] - 1] = '\0'; fprintf(stream, "%-*s ", field_size[j], fields[j]); @@ -10946,14 +10897,13 @@ } for (j = 0; j < nc; j++) - cpl_free(fields[j]); + cpl_free(fields[j]); cpl_free(fields); cpl_free(row_field); cpl_free(label_len); cpl_free(field_size); return; - } @@ -11008,16 +10958,15 @@ * to "all selected" after this operation. */ -cpl_error_code cpl_table_shift_column(cpl_table *table, const char *name, - cpl_size shift) +cpl_error_code +cpl_table_shift_column(cpl_table *table, const char *name, cpl_size shift) { - - cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_shift(column, shift) || - cpl_table_select_all(table) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + cpl_table_select_all(table) + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -11078,14 +11027,14 @@ * will make the array element valid. */ -cpl_error_code cpl_table_fill_invalid_int(cpl_table *table, - const char *name, int code) +cpl_error_code +cpl_table_fill_invalid_int(cpl_table *table, const char *name, int code) { - cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_fill_invalid_int(column, code) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -11131,14 +11080,14 @@ * will make the array element valid. */ -cpl_error_code cpl_table_fill_invalid_long(cpl_table *table, - const char *name, long code) +cpl_error_code +cpl_table_fill_invalid_long(cpl_table *table, const char *name, long code) { - cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_fill_invalid_long(column, code) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -11184,15 +11133,16 @@ * will make the array element valid. */ -cpl_error_code cpl_table_fill_invalid_long_long(cpl_table *table, - const char *name, - long long code) +cpl_error_code +cpl_table_fill_invalid_long_long(cpl_table *table, + const char *name, + long long code) { - cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_fill_invalid_long_long(column, code) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -11238,14 +11188,14 @@ * will make the array element valid. */ -cpl_error_code cpl_table_fill_invalid_float(cpl_table *table, - const char *name, float code) +cpl_error_code +cpl_table_fill_invalid_float(cpl_table *table, const char *name, float code) { - cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_fill_invalid_float(column, code) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -11291,15 +11241,16 @@ * will make the array element valid. */ -cpl_error_code cpl_table_fill_invalid_float_complex(cpl_table *table, - const char *name, - float complex code) +cpl_error_code +cpl_table_fill_invalid_float_complex(cpl_table *table, + const char *name, + float complex code) { - cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_fill_invalid_float_complex(column, code) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -11345,14 +11296,14 @@ * will make the array element valid. */ -cpl_error_code cpl_table_fill_invalid_double(cpl_table *table, - const char *name, double code) +cpl_error_code +cpl_table_fill_invalid_double(cpl_table *table, const char *name, double code) { - cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_fill_invalid_double(column, code) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -11398,15 +11349,16 @@ * will make the array element valid. */ -cpl_error_code cpl_table_fill_invalid_double_complex(cpl_table *table, - const char *name, - double complex code) +cpl_error_code +cpl_table_fill_invalid_double_complex(cpl_table *table, + const char *name, + double complex code) { - cpl_column *column = cpl_table_find_column_(table, name); return !column || cpl_column_fill_invalid_double_complex(column, code) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -11456,26 +11408,27 @@ * also the function @c cpl_table_or_selected_int(). */ -cpl_size cpl_table_and_selected_int(cpl_table *table, const char *name, - cpl_table_select_operator operator, - int value) +cpl_size +cpl_table_and_selected_int(cpl_table *table, + const char *name, + cpl_table_select_operator + operator, + int value) { - cpl_column_flag *nulldata; - int *data; - cpl_size length; - cpl_size nullcount; - cpl_column *column = cpl_table_find_column_type(table, name, - CPL_TYPE_INT); + int *data; + cpl_size length; + cpl_size nullcount; + cpl_column *column = cpl_table_find_column_type(table, name, CPL_TYPE_INT); if (!column) { (void)cpl_error_set_where_(); return -1; } - nulldata = cpl_column_get_data_invalid(column); - data = cpl_column_get_data_int(column); - length = cpl_column_get_size(column); + nulldata = cpl_column_get_data_invalid(column); + data = cpl_column_get_data_int(column); + length = cpl_column_get_size(column); nullcount = cpl_column_count_invalid(column); @@ -11489,7 +11442,7 @@ if (table->selectcount == 0) return 0; - if (nulldata) /* Some (not all!) invalid elements */ + if (nulldata) /* Some (not all!) invalid elements */ while (length--) if (nulldata[length]) cpl_table_unselect_row(table, length); @@ -11502,15 +11455,14 @@ * Moreover unselect anything that does not fulfill the comparison: */ - length = cpl_table_get_nrow(table); /* Restore */ + length = cpl_table_get_nrow(table); /* Restore */ switch (operator) { - case CPL_EQUAL_TO: if (nulldata) { while (length--) - if (nulldata[length] == 0) + if (nulldata[length] == 0) if (data[length] != value) cpl_table_unselect_row(table, length); } @@ -11525,7 +11477,7 @@ if (nulldata) { while (length--) - if (nulldata[length] == 0) + if (nulldata[length] == 0) if (data[length] == value) cpl_table_unselect_row(table, length); } @@ -11540,7 +11492,7 @@ if (nulldata) { while (length--) - if (nulldata[length] == 0) + if (nulldata[length] == 0) if (data[length] <= value) cpl_table_unselect_row(table, length); } @@ -11555,7 +11507,7 @@ if (nulldata) { while (length--) - if (nulldata[length] == 0) + if (nulldata[length] == 0) if (data[length] > value) cpl_table_unselect_row(table, length); } @@ -11570,7 +11522,7 @@ if (nulldata) { while (length--) - if (nulldata[length] == 0) + if (nulldata[length] == 0) if (data[length] >= value) cpl_table_unselect_row(table, length); } @@ -11585,7 +11537,7 @@ if (nulldata) { while (length--) - if (nulldata[length] == 0) + if (nulldata[length] == 0) if (data[length] < value) cpl_table_unselect_row(table, length); } @@ -11595,11 +11547,9 @@ cpl_table_unselect_row(table, length); } break; - } return table->selectcount; - } @@ -11649,33 +11599,34 @@ * also the description of the function @c cpl_table_and_selected_int(). */ -cpl_size cpl_table_or_selected_int(cpl_table *table, const char *name, - cpl_table_select_operator operator, - int value) +cpl_size +cpl_table_or_selected_int(cpl_table *table, + const char *name, + cpl_table_select_operator + operator, + int value) { - cpl_column_flag *nulldata; - int *data; - int length; - int nullcount; - cpl_column *column = cpl_table_find_column_type(table, name, - CPL_TYPE_INT); + int *data; + int length; + int nullcount; + cpl_column *column = cpl_table_find_column_type(table, name, CPL_TYPE_INT); if (!column) { (void)cpl_error_set_where_(); return -1; } - nulldata = cpl_column_get_data_invalid(column); - data = cpl_column_get_data_int(column); - length = cpl_column_get_size(column); + nulldata = cpl_column_get_data_invalid(column); + data = cpl_column_get_data_int(column); + length = cpl_column_get_size(column); nullcount = cpl_column_count_invalid(column); - if (table->selectcount == length) /* It's already all selected */ + if (table->selectcount == length) /* It's already all selected */ return length; - if (nullcount == length) /* Just invalids, no need to check values */ + if (nullcount == length) /* Just invalids, no need to check values */ return table->selectcount; /* @@ -11683,7 +11634,6 @@ */ switch (operator) { - case CPL_EQUAL_TO: if (nulldata) { @@ -11779,11 +11729,9 @@ } break; - } return table->selectcount; - } @@ -11833,26 +11781,27 @@ * also the function @c cpl_table_or_selected_long(). */ -cpl_size cpl_table_and_selected_long(cpl_table *table, const char *name, - cpl_table_select_operator operator, - long value) +cpl_size +cpl_table_and_selected_long(cpl_table *table, + const char *name, + cpl_table_select_operator + operator, + long value) { - cpl_column_flag *nulldata; - long *data; - cpl_size length; - cpl_size nullcount; - cpl_column *column = cpl_table_find_column_type(table, name, - CPL_TYPE_LONG); + long *data; + cpl_size length; + cpl_size nullcount; + cpl_column *column = cpl_table_find_column_type(table, name, CPL_TYPE_LONG); if (!column) { (void)cpl_error_set_where_(); return -1; } - nulldata = cpl_column_get_data_invalid(column); - data = cpl_column_get_data_long(column); - length = cpl_column_get_size(column); + nulldata = cpl_column_get_data_invalid(column); + data = cpl_column_get_data_long(column); + length = cpl_column_get_size(column); nullcount = cpl_column_count_invalid(column); @@ -11866,7 +11815,7 @@ if (table->selectcount == 0) return 0; - if (nulldata) /* Some (not all!) invalid elements */ + if (nulldata) /* Some (not all!) invalid elements */ while (length--) if (nulldata[length]) cpl_table_unselect_row(table, length); @@ -11879,10 +11828,9 @@ * Moreover unselect anything that does not fulfill the comparison: */ - length = cpl_table_get_nrow(table); /* Restore */ + length = cpl_table_get_nrow(table); /* Restore */ switch (operator) { - case CPL_EQUAL_TO: if (nulldata) { @@ -11972,11 +11920,9 @@ cpl_table_unselect_row(table, length); } break; - } return table->selectcount; - } @@ -12026,33 +11972,34 @@ * also the description of the function @c cpl_table_and_selected_long(). */ -cpl_size cpl_table_or_selected_long(cpl_table *table, const char *name, - cpl_table_select_operator operator, - long value) +cpl_size +cpl_table_or_selected_long(cpl_table *table, + const char *name, + cpl_table_select_operator + operator, + long value) { - cpl_column_flag *nulldata; - long *data; - int length; - int nullcount; - cpl_column *column = cpl_table_find_column_type(table, name, - CPL_TYPE_LONG); + long *data; + int length; + int nullcount; + cpl_column *column = cpl_table_find_column_type(table, name, CPL_TYPE_LONG); if (!column) { (void)cpl_error_set_where_(); return -1; } - nulldata = cpl_column_get_data_invalid(column); - data = cpl_column_get_data_long(column); - length = cpl_column_get_size(column); + nulldata = cpl_column_get_data_invalid(column); + data = cpl_column_get_data_long(column); + length = cpl_column_get_size(column); nullcount = cpl_column_count_invalid(column); - if (table->selectcount == length) /* It's already all selected */ + if (table->selectcount == length) /* It's already all selected */ return length; - if (nullcount == length) /* Just invalids, no need to check values */ + if (nullcount == length) /* Just invalids, no need to check values */ return table->selectcount; /* @@ -12060,7 +12007,6 @@ */ switch (operator) { - case CPL_EQUAL_TO: if (nulldata) { @@ -12156,11 +12102,9 @@ } break; - } return table->selectcount; - } @@ -12210,26 +12154,28 @@ * also the function @c cpl_table_or_selected_long_long(). */ -cpl_size cpl_table_and_selected_long_long(cpl_table *table, const char *name, - cpl_table_select_operator operator, - long long value) +cpl_size +cpl_table_and_selected_long_long(cpl_table *table, + const char *name, + cpl_table_select_operator + operator, + long long value) { - cpl_column_flag *nulldata; - long long *data; - cpl_size length; - cpl_size nullcount; - cpl_column *column = cpl_table_find_column_type(table, name, - CPL_TYPE_LONG_LONG); + long long *data; + cpl_size length; + cpl_size nullcount; + cpl_column *column = + cpl_table_find_column_type(table, name, CPL_TYPE_LONG_LONG); if (!column) { (void)cpl_error_set_where_(); return -1; } - nulldata = cpl_column_get_data_invalid(column); - data = cpl_column_get_data_long_long(column); - length = cpl_column_get_size(column); + nulldata = cpl_column_get_data_invalid(column); + data = cpl_column_get_data_long_long(column); + length = cpl_column_get_size(column); nullcount = cpl_column_count_invalid(column); @@ -12243,7 +12189,7 @@ if (table->selectcount == 0) return 0; - if (nulldata) /* Some (not all!) invalid elements */ + if (nulldata) /* Some (not all!) invalid elements */ while (length--) if (nulldata[length]) cpl_table_unselect_row(table, length); @@ -12256,10 +12202,9 @@ * Moreover unselect anything that does not fulfill the comparison: */ - length = cpl_table_get_nrow(table); /* Restore */ + length = cpl_table_get_nrow(table); /* Restore */ switch (operator) { - case CPL_EQUAL_TO: if (nulldata) { @@ -12349,11 +12294,9 @@ cpl_table_unselect_row(table, length); } break; - } return table->selectcount; - } @@ -12403,33 +12346,35 @@ * also the description of the function @c cpl_table_and_selected_long_long(). */ -cpl_size cpl_table_or_selected_long_long(cpl_table *table, const char *name, - cpl_table_select_operator operator, - long long value) +cpl_size +cpl_table_or_selected_long_long(cpl_table *table, + const char *name, + cpl_table_select_operator + operator, + long long value) { - cpl_column_flag *nulldata; - long long *data; - int length; - int nullcount; - cpl_column *column = cpl_table_find_column_type(table, name, - CPL_TYPE_LONG_LONG); + long long *data; + int length; + int nullcount; + cpl_column *column = + cpl_table_find_column_type(table, name, CPL_TYPE_LONG_LONG); if (!column) { (void)cpl_error_set_where_(); return -1; } - nulldata = cpl_column_get_data_invalid(column); - data = cpl_column_get_data_long_long(column); - length = cpl_column_get_size(column); + nulldata = cpl_column_get_data_invalid(column); + data = cpl_column_get_data_long_long(column); + length = cpl_column_get_size(column); nullcount = cpl_column_count_invalid(column); - if (table->selectcount == length) /* It's already all selected */ + if (table->selectcount == length) /* It's already all selected */ return length; - if (nullcount == length) /* Just invalids, no need to check values */ + if (nullcount == length) /* Just invalids, no need to check values */ return table->selectcount; /* @@ -12437,7 +12382,6 @@ */ switch (operator) { - case CPL_EQUAL_TO: if (nulldata) { @@ -12533,11 +12477,9 @@ } break; - } return table->selectcount; - } @@ -12587,17 +12529,19 @@ * also the function @c cpl_table_or_selected_float(). */ -cpl_size cpl_table_and_selected_float(cpl_table *table, const char *name, - cpl_table_select_operator operator, - float value) +cpl_size +cpl_table_and_selected_float(cpl_table *table, + const char *name, + cpl_table_select_operator + operator, + float value) { - cpl_column_flag *nulldata; - float *data; - cpl_size length; - cpl_size nullcount; - cpl_column *column = cpl_table_find_column_type(table, name, - CPL_TYPE_FLOAT); + float *data; + cpl_size length; + cpl_size nullcount; + cpl_column *column = + cpl_table_find_column_type(table, name, CPL_TYPE_FLOAT); if (!column) { (void)cpl_error_set_where_(); @@ -12605,9 +12549,9 @@ } - nulldata = cpl_column_get_data_invalid(column); - data = cpl_column_get_data_float(column); - length = cpl_column_get_size(column); + nulldata = cpl_column_get_data_invalid(column); + data = cpl_column_get_data_float(column); + length = cpl_column_get_size(column); nullcount = cpl_column_count_invalid(column); @@ -12621,7 +12565,7 @@ if (table->selectcount == 0) return 0; - if (nulldata) /* Some (not all!) invalids */ + if (nulldata) /* Some (not all!) invalids */ while (length--) if (nulldata[length]) cpl_table_unselect_row(table, length); @@ -12634,10 +12578,9 @@ * Moreover unselect anything that does not fulfill the comparison: */ - length = cpl_table_get_nrow(table); /* Restore */ + length = cpl_table_get_nrow(table); /* Restore */ switch (operator) { - case CPL_EQUAL_TO: if (nulldata) { @@ -12727,7 +12670,6 @@ cpl_table_unselect_row(table, length); } break; - } return table->selectcount; @@ -12786,27 +12728,28 @@ * also the function @c cpl_table_or_selected_float_complex(). */ -cpl_size cpl_table_and_selected_float_complex(cpl_table *table, - const char *name, - cpl_table_select_operator operator, - float complex value) +cpl_size +cpl_table_and_selected_float_complex(cpl_table *table, + const char *name, + cpl_table_select_operator + operator, + float complex value) { - cpl_column_flag *nulldata; - float complex *data; - cpl_size length; - cpl_size nullcount; - cpl_column *column = cpl_table_find_column_type(table, name, - CPL_TYPE_FLOAT_COMPLEX); + float complex *data; + cpl_size length; + cpl_size nullcount; + cpl_column *column = + cpl_table_find_column_type(table, name, CPL_TYPE_FLOAT_COMPLEX); if (!column) { (void)cpl_error_set_where_(); return -1; } - nulldata = cpl_column_get_data_invalid(column); - data = cpl_column_get_data_float_complex(column); - length = cpl_column_get_size(column); + nulldata = cpl_column_get_data_invalid(column); + data = cpl_column_get_data_float_complex(column); + length = cpl_column_get_size(column); nullcount = cpl_column_count_invalid(column); @@ -12820,7 +12763,7 @@ if (table->selectcount == 0) return 0; - if (nulldata) /* Some (not all!) invalids */ + if (nulldata) /* Some (not all!) invalids */ while (length--) if (nulldata[length]) cpl_table_unselect_row(table, length); @@ -12833,48 +12776,46 @@ * Moreover unselect anything that does not fulfill the comparison: */ - length = cpl_table_get_nrow(table); /* Restore */ + length = cpl_table_get_nrow(table); /* Restore */ switch (operator) { + case CPL_EQUAL_TO: - case CPL_EQUAL_TO: - - if (nulldata) { - while (length--) - if (nulldata[length] == 0) + if (nulldata) { + while (length--) + if (nulldata[length] == 0) + if (data[length] != value) + cpl_table_unselect_row(table, length); + } + else { + while (length--) if (data[length] != value) cpl_table_unselect_row(table, length); - } - else { - while (length--) - if (data[length] != value) - cpl_table_unselect_row(table, length); - } - break; + } + break; - case CPL_NOT_EQUAL_TO: + case CPL_NOT_EQUAL_TO: - if (nulldata) { - while (length--) - if (nulldata[length] == 0) + if (nulldata) { + while (length--) + if (nulldata[length] == 0) + if (data[length] == value) + cpl_table_unselect_row(table, length); + } + else { + while (length--) if (data[length] == value) cpl_table_unselect_row(table, length); - } - else { - while (length--) - if (data[length] == value) - cpl_table_unselect_row(table, length); - } - break; - - case CPL_GREATER_THAN: - case CPL_NOT_GREATER_THAN: - case CPL_LESS_THAN: - case CPL_NOT_LESS_THAN: + } + break; - cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); - return -1; + case CPL_GREATER_THAN: + case CPL_NOT_GREATER_THAN: + case CPL_LESS_THAN: + case CPL_NOT_LESS_THAN: + cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); + return -1; } return table->selectcount; @@ -12927,26 +12868,28 @@ * also the description of the function @c cpl_table_and_selected_float(). */ -cpl_size cpl_table_or_selected_float(cpl_table *table, const char *name, - cpl_table_select_operator operator, - float value) +cpl_size +cpl_table_or_selected_float(cpl_table *table, + const char *name, + cpl_table_select_operator + operator, + float value) { - cpl_column_flag *nulldata; - float *data; - cpl_size length; - cpl_size nullcount; - cpl_column *column = cpl_table_find_column_type(table, name, - CPL_TYPE_FLOAT); + float *data; + cpl_size length; + cpl_size nullcount; + cpl_column *column = + cpl_table_find_column_type(table, name, CPL_TYPE_FLOAT); if (!column) { (void)cpl_error_set_where_(); return -1; } - nulldata = cpl_column_get_data_invalid(column); - data = cpl_column_get_data_float(column); - length = cpl_column_get_size(column); + nulldata = cpl_column_get_data_invalid(column); + data = cpl_column_get_data_float(column); + length = cpl_column_get_size(column); nullcount = cpl_column_count_invalid(column); if (table->selectcount == length) @@ -12960,7 +12903,6 @@ */ switch (operator) { - case CPL_EQUAL_TO: if (nulldata) { @@ -13056,11 +12998,9 @@ } break; - } return table->selectcount; - } @@ -13116,26 +13056,28 @@ * of the function @c cpl_table_and_selected_float_complex(). */ -cpl_size cpl_table_or_selected_float_complex(cpl_table *table, const char *name, - cpl_table_select_operator operator, - float complex value) +cpl_size +cpl_table_or_selected_float_complex(cpl_table *table, + const char *name, + cpl_table_select_operator + operator, + float complex value) { - cpl_column_flag *nulldata; - float complex *data; - cpl_size length; - cpl_size nullcount; - cpl_column *column = cpl_table_find_column_type(table, name, - CPL_TYPE_FLOAT_COMPLEX); + float complex *data; + cpl_size length; + cpl_size nullcount; + cpl_column *column = + cpl_table_find_column_type(table, name, CPL_TYPE_FLOAT_COMPLEX); if (!column) { (void)cpl_error_set_where_(); return -1; } - nulldata = cpl_column_get_data_invalid(column); - data = cpl_column_get_data_float_complex(column); - length = cpl_column_get_size(column); + nulldata = cpl_column_get_data_invalid(column); + data = cpl_column_get_data_float_complex(column); + length = cpl_column_get_size(column); nullcount = cpl_column_count_invalid(column); if (table->selectcount == length) @@ -13149,51 +13091,48 @@ */ switch (operator) { + case CPL_EQUAL_TO: - case CPL_EQUAL_TO: - - if (nulldata) { - while (length--) - if (nulldata[length] == 0) + if (nulldata) { + while (length--) + if (nulldata[length] == 0) + if (data[length] == value) + cpl_table_select_row(table, length); + } + else { + while (length--) if (data[length] == value) cpl_table_select_row(table, length); - } - else { - while (length--) - if (data[length] == value) - cpl_table_select_row(table, length); - } + } - break; + break; - case CPL_NOT_EQUAL_TO: + case CPL_NOT_EQUAL_TO: - if (nulldata) { - while (length--) - if (nulldata[length] == 0) + if (nulldata) { + while (length--) + if (nulldata[length] == 0) + if (data[length] != value) + cpl_table_select_row(table, length); + } + else { + while (length--) if (data[length] != value) cpl_table_select_row(table, length); - } - else { - while (length--) - if (data[length] != value) - cpl_table_select_row(table, length); - } - - break; + } - case CPL_GREATER_THAN: - case CPL_NOT_GREATER_THAN: - case CPL_LESS_THAN: - case CPL_NOT_LESS_THAN: + break; - cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); - return -1; + case CPL_GREATER_THAN: + case CPL_NOT_GREATER_THAN: + case CPL_LESS_THAN: + case CPL_NOT_LESS_THAN: + cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); + return -1; } return table->selectcount; - } @@ -13243,17 +13182,19 @@ * also the function @c cpl_table_or_selected_double(). */ -cpl_size cpl_table_and_selected_double(cpl_table *table, const char *name, - cpl_table_select_operator operator, - double value) +cpl_size +cpl_table_and_selected_double(cpl_table *table, + const char *name, + cpl_table_select_operator + operator, + double value) { - cpl_column_flag *nulldata; - double *data; - cpl_size length; - cpl_size nullcount; - cpl_column *column = cpl_table_find_column_type(table, name, - CPL_TYPE_DOUBLE); + double *data; + cpl_size length; + cpl_size nullcount; + cpl_column *column = + cpl_table_find_column_type(table, name, CPL_TYPE_DOUBLE); if (!column) { (void)cpl_error_set_where_(); @@ -13261,9 +13202,9 @@ } - nulldata = cpl_column_get_data_invalid(column); - data = cpl_column_get_data_double(column); - length = cpl_column_get_size(column); + nulldata = cpl_column_get_data_invalid(column); + data = cpl_column_get_data_double(column); + length = cpl_column_get_size(column); nullcount = cpl_column_count_invalid(column); @@ -13277,7 +13218,7 @@ if (table->selectcount == 0) return 0; - if (nulldata) /* Some (not all!) invalids */ + if (nulldata) /* Some (not all!) invalids */ while (length--) if (nulldata[length]) cpl_table_unselect_row(table, length); @@ -13290,10 +13231,9 @@ * Moreover unselect anything that does not fulfill the comparison: */ - length = cpl_table_get_nrow(table); /* Restore */ + length = cpl_table_get_nrow(table); /* Restore */ switch (operator) { - case CPL_EQUAL_TO: if (nulldata) { @@ -13383,11 +13323,9 @@ cpl_table_unselect_row(table, length); } break; - } return table->selectcount; - } @@ -13443,27 +13381,28 @@ * also the function @c cpl_table_or_selected_double_complex(). */ -cpl_size cpl_table_and_selected_double_complex(cpl_table *table, - const char *name, - cpl_table_select_operator operator, - double complex value) +cpl_size +cpl_table_and_selected_double_complex(cpl_table *table, + const char *name, + cpl_table_select_operator + operator, + double complex value) { - cpl_column_flag *nulldata; - double complex *data; - cpl_size length; - cpl_size nullcount; - cpl_column *column = cpl_table_find_column_type(table, name, - CPL_TYPE_DOUBLE_COMPLEX); + double complex *data; + cpl_size length; + cpl_size nullcount; + cpl_column *column = + cpl_table_find_column_type(table, name, CPL_TYPE_DOUBLE_COMPLEX); if (!column) { (void)cpl_error_set_where_(); return -1; } - nulldata = cpl_column_get_data_invalid(column); - data = cpl_column_get_data_double_complex(column); - length = cpl_column_get_size(column); + nulldata = cpl_column_get_data_invalid(column); + data = cpl_column_get_data_double_complex(column); + length = cpl_column_get_size(column); nullcount = cpl_column_count_invalid(column); @@ -13477,7 +13416,7 @@ if (table->selectcount == 0) return 0; - if (nulldata) /* Some (not all!) invalids */ + if (nulldata) /* Some (not all!) invalids */ while (length--) if (nulldata[length]) cpl_table_unselect_row(table, length); @@ -13490,52 +13429,49 @@ * Moreover unselect anything that does not fulfill the comparison: */ - length = cpl_table_get_nrow(table); /* Restore */ + length = cpl_table_get_nrow(table); /* Restore */ switch (operator) { + case CPL_EQUAL_TO: - case CPL_EQUAL_TO: - - if (nulldata) { - while (length--) - if (nulldata[length] == 0) + if (nulldata) { + while (length--) + if (nulldata[length] == 0) + if (data[length] != value) + cpl_table_unselect_row(table, length); + } + else { + while (length--) if (data[length] != value) cpl_table_unselect_row(table, length); - } - else { - while (length--) - if (data[length] != value) - cpl_table_unselect_row(table, length); - } - break; + } + break; - case CPL_NOT_EQUAL_TO: + case CPL_NOT_EQUAL_TO: - if (nulldata) { - while (length--) - if (nulldata[length] == 0) - if (data[length] == value) - cpl_table_unselect_row(table, length); - } - else { - while (length--) - if (data[length] == value) - cpl_table_unselect_row(table, length); - } - break; - - case CPL_GREATER_THAN: - case CPL_NOT_GREATER_THAN: - case CPL_LESS_THAN: - case CPL_NOT_LESS_THAN: + if (nulldata) { + while (length--) + if (nulldata[length] == 0) + if (data[length] == value) + cpl_table_unselect_row(table, length); + } + else { + while (length--) + if (data[length] == value) + cpl_table_unselect_row(table, length); + } + break; - cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); - return -1; + case CPL_GREATER_THAN: + case CPL_NOT_GREATER_THAN: + case CPL_LESS_THAN: + case CPL_NOT_LESS_THAN: + cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); + return -1; } return table->selectcount; - } @@ -13585,26 +13521,28 @@ * also the description of the function @c cpl_table_and_selected_double(). */ -cpl_size cpl_table_or_selected_double(cpl_table *table, const char *name, - cpl_table_select_operator operator, - double value) +cpl_size +cpl_table_or_selected_double(cpl_table *table, + const char *name, + cpl_table_select_operator + operator, + double value) { - cpl_column_flag *nulldata; - double *data; - cpl_size length; - cpl_size nullcount; - cpl_column *column = cpl_table_find_column_type(table, name, - CPL_TYPE_DOUBLE); + double *data; + cpl_size length; + cpl_size nullcount; + cpl_column *column = + cpl_table_find_column_type(table, name, CPL_TYPE_DOUBLE); if (!column) { (void)cpl_error_set_where_(); return -1; } - nulldata = cpl_column_get_data_invalid(column); - data = cpl_column_get_data_double(column); - length = cpl_column_get_size(column); + nulldata = cpl_column_get_data_invalid(column); + data = cpl_column_get_data_double(column); + length = cpl_column_get_size(column); nullcount = cpl_column_count_invalid(column); if (table->selectcount == length) @@ -13618,7 +13556,6 @@ */ switch (operator) { - case CPL_EQUAL_TO: if (nulldata) { @@ -13714,11 +13651,9 @@ } break; - } return table->selectcount; - } @@ -13774,27 +13709,28 @@ * of the function @c cpl_table_and_selected_double_complex(). */ -cpl_size cpl_table_or_selected_double_complex(cpl_table *table, - const char *name, - cpl_table_select_operator operator, - double complex value) +cpl_size +cpl_table_or_selected_double_complex(cpl_table *table, + const char *name, + cpl_table_select_operator + operator, + double complex value) { - cpl_column_flag *nulldata; - double complex *data; - cpl_size length; - cpl_size nullcount; - cpl_column *column = cpl_table_find_column_type(table, name, - CPL_TYPE_DOUBLE_COMPLEX); + double complex *data; + cpl_size length; + cpl_size nullcount; + cpl_column *column = + cpl_table_find_column_type(table, name, CPL_TYPE_DOUBLE_COMPLEX); if (!column) { (void)cpl_error_set_where_(); return -1; } - nulldata = cpl_column_get_data_invalid(column); - data = cpl_column_get_data_double_complex(column); - length = cpl_column_get_size(column); + nulldata = cpl_column_get_data_invalid(column); + data = cpl_column_get_data_double_complex(column); + length = cpl_column_get_size(column); nullcount = cpl_column_count_invalid(column); if (table->selectcount == length) @@ -13808,51 +13744,48 @@ */ switch (operator) { + case CPL_EQUAL_TO: - case CPL_EQUAL_TO: - - if (nulldata) { - while (length--) - if (nulldata[length] == 0) + if (nulldata) { + while (length--) + if (nulldata[length] == 0) + if (data[length] == value) + cpl_table_select_row(table, length); + } + else { + while (length--) if (data[length] == value) cpl_table_select_row(table, length); - } - else { - while (length--) - if (data[length] == value) - cpl_table_select_row(table, length); - } + } - break; + break; - case CPL_NOT_EQUAL_TO: + case CPL_NOT_EQUAL_TO: - if (nulldata) { - while (length--) - if (nulldata[length] == 0) + if (nulldata) { + while (length--) + if (nulldata[length] == 0) + if (data[length] != value) + cpl_table_select_row(table, length); + } + else { + while (length--) if (data[length] != value) cpl_table_select_row(table, length); - } - else { - while (length--) - if (data[length] != value) - cpl_table_select_row(table, length); - } - - break; + } - case CPL_GREATER_THAN: - case CPL_NOT_GREATER_THAN: - case CPL_LESS_THAN: - case CPL_NOT_LESS_THAN: + break; - cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); - return -1; + case CPL_GREATER_THAN: + case CPL_NOT_GREATER_THAN: + case CPL_LESS_THAN: + case CPL_NOT_LESS_THAN: + cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); + return -1; } return table->selectcount; - } @@ -13911,25 +13844,27 @@ * the function @c cpl_table_or_selected_string(). */ -cpl_size cpl_table_and_selected_string(cpl_table *table, const char *name, - cpl_table_select_operator operator, - const char *string) +cpl_size +cpl_table_and_selected_string(cpl_table *table, + const char *name, + cpl_table_select_operator + operator, + const char * string) { - - char **data; - cpl_size length; - cpl_size nullcount; - int status; - cpl_column *column = cpl_table_find_column_type(table, name, - CPL_TYPE_STRING); + char **data; + cpl_size length; + cpl_size nullcount; + int status; + cpl_column *column = + cpl_table_find_column_type(table, name, CPL_TYPE_STRING); if (!column) { (void)cpl_error_set_where_(); return -1; } - data = cpl_column_get_data_string(column); - length = cpl_column_get_size(column); + data = cpl_column_get_data_string(column); + length = cpl_column_get_size(column); nullcount = cpl_column_count_invalid(column); if (length == 0) @@ -13946,7 +13881,7 @@ if (table->selectcount == 0) return 0; - if (nullcount) /* Some (not all!) invalids */ + if (nullcount) /* Some (not all!) invalids */ while (length--) if (data[length] == NULL) cpl_table_unselect_row(table, length); @@ -13959,15 +13894,13 @@ * Moreover unselect anything that does not fulfill the comparison: */ - length = cpl_table_get_nrow(table); /* Restore */ + length = cpl_table_get_nrow(table); /* Restore */ switch (operator) { - - case CPL_EQUAL_TO: - { + case CPL_EQUAL_TO: { regex_t re; - status = regcomp(&re, string, REG_EXTENDED|REG_NOSUB); + status = regcomp(&re, string, REG_EXTENDED | REG_NOSUB); if (status) { cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); @@ -13986,11 +13919,10 @@ break; } - case CPL_NOT_EQUAL_TO: - { + case CPL_NOT_EQUAL_TO: { regex_t re; - status = regcomp(&re, string, REG_EXTENDED|REG_NOSUB); + status = regcomp(&re, string, REG_EXTENDED | REG_NOSUB); if (status) { cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); @@ -14040,11 +13972,9 @@ if (strcmp(data[length], string) < 0) cpl_table_unselect_row(table, length); break; - } return table->selectcount; - } @@ -14103,25 +14033,27 @@ * function @c cpl_table_and_selected_string(). */ -cpl_size cpl_table_or_selected_string(cpl_table *table, const char *name, - cpl_table_select_operator operator, - const char *string) +cpl_size +cpl_table_or_selected_string(cpl_table *table, + const char *name, + cpl_table_select_operator + operator, + const char * string) { - - char **data; - cpl_size length; - cpl_size nullcount; - int status; - cpl_column *column = cpl_table_find_column_type(table, name, - CPL_TYPE_STRING); + char **data; + cpl_size length; + cpl_size nullcount; + int status; + cpl_column *column = + cpl_table_find_column_type(table, name, CPL_TYPE_STRING); if (!column) { (void)cpl_error_set_where_(); return -1; } - data = cpl_column_get_data_string(column); - length = cpl_column_get_size(column); + data = cpl_column_get_data_string(column); + length = cpl_column_get_size(column); nullcount = cpl_column_count_invalid(column); @@ -14139,12 +14071,10 @@ */ switch (operator) { - - case CPL_EQUAL_TO: - { + case CPL_EQUAL_TO: { regex_t re; - status = regcomp(&re, string, REG_EXTENDED|REG_NOSUB); + status = regcomp(&re, string, REG_EXTENDED | REG_NOSUB); if (status) { cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); @@ -14163,11 +14093,10 @@ break; } - case CPL_NOT_EQUAL_TO: - { + case CPL_NOT_EQUAL_TO: { regex_t re; - status = regcomp(&re, string, REG_EXTENDED|REG_NOSUB); + status = regcomp(&re, string, REG_EXTENDED | REG_NOSUB); if (status) { cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); @@ -14217,11 +14146,9 @@ if (strcmp(data[length], string) >= 0) cpl_table_select_row(table, length); break; - } return table->selectcount; - } @@ -14258,16 +14185,16 @@ * @c cpl_table_or_selected_invalid(). */ -cpl_size cpl_table_and_selected_invalid(cpl_table *table, const char *name) +cpl_size +cpl_table_and_selected_invalid(cpl_table *table, const char *name) { - - cpl_type type; + cpl_type type; cpl_column_flag *nulldata = NULL; - cpl_array **adata = NULL; - char **cdata = NULL; - cpl_size length; - cpl_size nullcount; - cpl_column *column = cpl_table_find_column_(table, name); + cpl_array **adata = NULL; + char **cdata = NULL; + cpl_size length; + cpl_size nullcount; + cpl_column *column = cpl_table_find_column_(table, name); if (!column) { (void)cpl_error_set_where_(); @@ -14283,7 +14210,7 @@ else nulldata = cpl_column_get_data_invalid(column); - length = cpl_column_get_size(column); + length = cpl_column_get_size(column); nullcount = cpl_column_count_invalid(column); if (nullcount == length) @@ -14299,12 +14226,12 @@ * If this point is reached, there are some (not all!) invalid elements. */ - if (cdata) { /* String column */ + if (cdata) { /* String column */ while (length--) if (cdata[length]) cpl_table_unselect_row(table, length); } - else if (adata) { /* Array column */ + else if (adata) { /* Array column */ while (length--) if (adata[length]) cpl_table_unselect_row(table, length); @@ -14316,7 +14243,6 @@ } return table->selectcount; - } @@ -14353,16 +14279,16 @@ * @c cpl_table_and_selected_invalid(). */ -cpl_size cpl_table_or_selected_invalid(cpl_table *table, const char *name) +cpl_size +cpl_table_or_selected_invalid(cpl_table *table, const char *name) { - - cpl_type type; + cpl_type type; cpl_column_flag *nulldata = NULL; - cpl_array **adata = NULL; - char **cdata = NULL; - cpl_size length; - cpl_size nullcount; - cpl_column *column = cpl_table_find_column_(table, name); + cpl_array **adata = NULL; + char **cdata = NULL; + cpl_size length; + cpl_size nullcount; + cpl_column *column = cpl_table_find_column_(table, name); if (!column) { (void)cpl_error_set_where_(); @@ -14378,7 +14304,7 @@ else nulldata = cpl_column_get_data_invalid(column); - length = cpl_column_get_size(column); + length = cpl_column_get_size(column); nullcount = cpl_column_count_invalid(column); if (nullcount == 0) @@ -14394,12 +14320,12 @@ * If this point is reached, there are some (not all!) invalid elements. */ - if (cdata) { /* String column */ + if (cdata) { /* String column */ while (length--) if (!cdata[length]) cpl_table_select_row(table, length); } - else if (adata) { /* Array column */ + else if (adata) { /* Array column */ while (length--) if (!adata[length]) cpl_table_select_row(table, length); @@ -14411,7 +14337,6 @@ } return table->selectcount; - } @@ -14456,11 +14381,10 @@ * also the function @c cpl_table_or_selected_window(). */ -cpl_size cpl_table_and_selected_window(cpl_table *table, - cpl_size start, cpl_size count) +cpl_size +cpl_table_and_selected_window(cpl_table *table, cpl_size start, cpl_size count) { - - cpl_size i; + cpl_size i; if (table == NULL) { @@ -14479,17 +14403,16 @@ } - if (table->selectcount == 0) /* Nothing was selected, nothing to "and" */ + if (table->selectcount == 0) /* Nothing was selected, nothing to "and" */ return 0; if (count > table->nr - start) count = table->nr - start; - if (count == table->nr) /* "Anding" the whole table, no change */ + if (count == table->nr) /* "Anding" the whole table, no change */ return table->selectcount; if (table->selectcount == table->nr) { - table->select = cpl_calloc(table->nr, sizeof(cpl_column_flag)); i = start; @@ -14498,10 +14421,8 @@ table->select[i] = 1; i++; } - } else { - i = 0; while (i < start) { if (table->select[i] == 1) { @@ -14525,11 +14446,9 @@ cpl_free(table->select); table->select = NULL; } - } return table->selectcount; - } @@ -14574,11 +14493,10 @@ * the function @c cpl_table_and_selected_window(). */ -cpl_size cpl_table_or_selected_window(cpl_table *table, - cpl_size start, cpl_size count) +cpl_size +cpl_table_or_selected_window(cpl_table *table, cpl_size start, cpl_size count) { - - cpl_size i = start; + cpl_size i = start; if (table == NULL) { @@ -14599,14 +14517,13 @@ if (count > table->nr - start) count = table->nr - start; - if (count == table->nr) /* "Oring" the whole table */ + if (count == table->nr) /* "Oring" the whole table */ cpl_table_select_all(table); if (table->selectcount == table->nr) /* All was selected, no "or" is due */ return table->selectcount; if (table->selectcount == 0) { - table->select = cpl_calloc(table->nr, sizeof(cpl_column_flag)); table->selectcount = count; @@ -14614,10 +14531,8 @@ table->select[i] = 1; i++; } - } else { - while (count--) { if (table->select[i] == 0) { table->select[i] = 1; @@ -14631,11 +14546,9 @@ cpl_free(table->select); table->select = NULL; } - } return table->selectcount; - } @@ -14662,10 +14575,10 @@ * Select unselected table rows, and unselect selected ones. */ -cpl_size cpl_table_not_selected(cpl_table *table) +cpl_size +cpl_table_not_selected(cpl_table *table) { - - cpl_size length; + cpl_size length; if (table == NULL) { @@ -14689,7 +14602,6 @@ } return table->selectcount = table->nr - table->selectcount; - } @@ -14743,22 +14655,24 @@ * See also the function @c cpl_table_or_selected(). */ -cpl_size cpl_table_and_selected(cpl_table *table, const char *name1, - cpl_table_select_operator operator, - const char *name2) +cpl_size +cpl_table_and_selected(cpl_table *table, + const char *name1, + cpl_table_select_operator + operator, + const char * name2) { - - cpl_type type1; - cpl_type type2; + cpl_type type1; + cpl_type type2; cpl_column_flag *nulldata1; cpl_column_flag *nulldata2; - char **sdata1; - char **sdata2; - cpl_size nullcount1; - cpl_size nullcount2; - cpl_size length; - cpl_column *column1 = cpl_table_find_column_(table, name1); - cpl_column *column2 = cpl_table_find_column_(table, name2); + char **sdata1; + char **sdata2; + cpl_size nullcount1; + cpl_size nullcount2; + cpl_size length; + cpl_column *column1 = cpl_table_find_column_(table, name1); + cpl_column *column2 = cpl_table_find_column_(table, name2); if (!column1 || !column2) { (void)cpl_error_set_where_(); @@ -14783,11 +14697,11 @@ } } - nulldata1 = cpl_column_get_data_invalid(column1); - nulldata2 = cpl_column_get_data_invalid(column2); + nulldata1 = cpl_column_get_data_invalid(column1); + nulldata2 = cpl_column_get_data_invalid(column2); nullcount1 = cpl_column_count_invalid(column1); nullcount2 = cpl_column_count_invalid(column2); - length = cpl_column_get_size(column1); + length = cpl_column_get_size(column1); if (length == 0) return 0; @@ -14803,12 +14717,12 @@ if (table->selectcount == 0) return 0; - if (nulldata1) /* Some (not all!) NULLs */ + if (nulldata1) /* Some (not all!) NULLs */ while (length--) if (nulldata1[length]) cpl_table_unselect_row(table, length); - if (type1 == CPL_TYPE_STRING) { /* In case of string comparison */ + if (type1 == CPL_TYPE_STRING) { /* In case of string comparison */ sdata1 = cpl_column_get_data_string(column1); while (length--) { if (sdata1[length] == NULL) { @@ -14820,14 +14734,14 @@ if (table->selectcount == 0) return 0; - length = cpl_table_get_nrow(table); /* Restore */ + length = cpl_table_get_nrow(table); /* Restore */ - if (nulldata2) /* Some (not all!) NULLs */ + if (nulldata2) /* Some (not all!) NULLs */ while (length--) if (nulldata2[length]) cpl_table_unselect_row(table, length); - if (type2 == CPL_TYPE_STRING) { /* In case of string comparison */ + if (type2 == CPL_TYPE_STRING) { /* In case of string comparison */ sdata2 = cpl_column_get_data_string(column2); while (length--) { if (sdata2[length] == NULL) { @@ -14844,1453 +14758,1405 @@ * Moreover unselect anything that does not fulfill the comparison: */ - length = cpl_table_get_nrow(table); /* Restore */ + length = cpl_table_get_nrow(table); /* Restore */ switch (type1) { + case CPL_TYPE_INT: { + int *idata1 = cpl_column_get_data_int(column1); - case CPL_TYPE_INT: - { - int *idata1 = cpl_column_get_data_int(column1); + switch (type2) { + case CPL_TYPE_INT: { + int *idata2 = cpl_column_get_data_int(column2); + + switch (operator) { + case CPL_EQUAL_TO: + + while (length--) + if (idata1[length] != idata2[length]) + cpl_table_unselect_row(table, length); + break; - switch (type2) { + case CPL_NOT_EQUAL_TO: - case CPL_TYPE_INT: - { - int *idata2 = cpl_column_get_data_int(column2); + while (length--) + if (idata1[length] == idata2[length]) + cpl_table_unselect_row(table, length); + break; - switch (operator) { + case CPL_GREATER_THAN: - case CPL_EQUAL_TO: + while (length--) + if (idata1[length] <= idata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if (idata1[length] != idata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_NOT_GREATER_THAN: - case CPL_NOT_EQUAL_TO: + while (length--) + if (idata1[length] > idata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if (idata1[length] == idata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_LESS_THAN: - case CPL_GREATER_THAN: + while (length--) + if (idata1[length] >= idata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if (idata1[length] <= idata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_NOT_LESS_THAN: - case CPL_NOT_GREATER_THAN: + while (length--) + if (idata1[length] < idata2[length]) + cpl_table_unselect_row(table, length); + break; + } - while (length--) - if (idata1[length] > idata2[length]) - cpl_table_unselect_row(table, length); - break; + break; + } - case CPL_LESS_THAN: + case CPL_TYPE_LONG: { + long *ldata2 = cpl_column_get_data_long(column2); - while (length--) - if (idata1[length] >= idata2[length]) - cpl_table_unselect_row(table, length); - break; + switch (operator) { + case CPL_EQUAL_TO: - case CPL_NOT_LESS_THAN: + while (length--) + if ((long)idata1[length] != ldata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if (idata1[length] < idata2[length]) - cpl_table_unselect_row(table, length); - break; - } + case CPL_NOT_EQUAL_TO: - break; - } + while (length--) + if ((long)idata1[length] == ldata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_TYPE_LONG: - { - long *ldata2 = cpl_column_get_data_long(column2); + case CPL_GREATER_THAN: - switch (operator) { + while (length--) + if ((long)idata1[length] <= ldata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_EQUAL_TO: + case CPL_NOT_GREATER_THAN: - while (length--) - if ((long)idata1[length] != ldata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if ((long)idata1[length] > ldata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_NOT_EQUAL_TO: + case CPL_LESS_THAN: - while (length--) - if ((long)idata1[length] == ldata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if ((long)idata1[length] >= ldata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_GREATER_THAN: + case CPL_NOT_LESS_THAN: - while (length--) - if ((long)idata1[length] <= ldata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if ((long)idata1[length] < ldata2[length]) + cpl_table_unselect_row(table, length); + break; + } - case CPL_NOT_GREATER_THAN: + break; + } - while (length--) - if ((long)idata1[length] > ldata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_TYPE_LONG_LONG: { + long long *lldata2 = cpl_column_get_data_long_long(column2); - case CPL_LESS_THAN: + switch (operator) { + case CPL_EQUAL_TO: - while (length--) - if ((long)idata1[length] >= ldata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if ((long long)idata1[length] != + lldata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_NOT_LESS_THAN: + case CPL_NOT_EQUAL_TO: - while (length--) - if ((long)idata1[length] < ldata2[length]) - cpl_table_unselect_row(table, length); - break; - } + while (length--) + if ((long long)idata1[length] == + lldata2[length]) + cpl_table_unselect_row(table, length); + break; - break; - } + case CPL_GREATER_THAN: - case CPL_TYPE_LONG_LONG: - { - long long *lldata2 = cpl_column_get_data_long_long(column2); + while (length--) + if ((long long)idata1[length] <= + lldata2[length]) + cpl_table_unselect_row(table, length); + break; - switch (operator) { + case CPL_NOT_GREATER_THAN: - case CPL_EQUAL_TO: + while (length--) + if ((long long)idata1[length] > lldata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if ((long long)idata1[length] != lldata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_LESS_THAN: - case CPL_NOT_EQUAL_TO: + while (length--) + if ((long long)idata1[length] >= + lldata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if ((long long)idata1[length] == lldata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_NOT_LESS_THAN: - case CPL_GREATER_THAN: + while (length--) + if ((long long)idata1[length] < lldata2[length]) + cpl_table_unselect_row(table, length); + break; + } - while (length--) - if ((long long)idata1[length] <= lldata2[length]) - cpl_table_unselect_row(table, length); - break; + break; + } - case CPL_NOT_GREATER_THAN: + case CPL_TYPE_FLOAT: { + float *fdata2 = cpl_column_get_data_float(column2); - while (length--) - if ((long long)idata1[length] > lldata2[length]) - cpl_table_unselect_row(table, length); - break; + switch (operator) { + case CPL_EQUAL_TO: - case CPL_LESS_THAN: + while (length--) + if ((float)idata1[length] != fdata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if ((long long)idata1[length] >= lldata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_NOT_EQUAL_TO: - case CPL_NOT_LESS_THAN: + while (length--) + if ((float)idata1[length] == fdata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if ((long long)idata1[length] < lldata2[length]) - cpl_table_unselect_row(table, length); - break; - } + case CPL_GREATER_THAN: - break; - } + while (length--) + if ((float)idata1[length] <= fdata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_TYPE_FLOAT: - { - float *fdata2 = cpl_column_get_data_float(column2); + case CPL_NOT_GREATER_THAN: - switch (operator) { + while (length--) + if ((float)idata1[length] > fdata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_EQUAL_TO: + case CPL_LESS_THAN: - while (length--) - if ((float)idata1[length] != fdata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if ((float)idata1[length] >= fdata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_NOT_EQUAL_TO: + case CPL_NOT_LESS_THAN: - while (length--) - if ((float)idata1[length] == fdata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if ((float)idata1[length] < fdata2[length]) + cpl_table_unselect_row(table, length); + break; + } - case CPL_GREATER_THAN: + break; + } - while (length--) - if ((float)idata1[length] <= fdata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_TYPE_DOUBLE: { + double *ddata2 = cpl_column_get_data_double(column2); - case CPL_NOT_GREATER_THAN: + switch (operator) { + case CPL_EQUAL_TO: - while (length--) - if ((float)idata1[length] > fdata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if ((double)idata1[length] != ddata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_LESS_THAN: + case CPL_NOT_EQUAL_TO: - while (length--) - if ((float)idata1[length] >= fdata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if ((double)idata1[length] == ddata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_NOT_LESS_THAN: + case CPL_GREATER_THAN: - while (length--) - if ((float)idata1[length] < fdata2[length]) - cpl_table_unselect_row(table, length); - break; - } + while (length--) + if ((double)idata1[length] <= ddata2[length]) + cpl_table_unselect_row(table, length); + break; - break; - } + case CPL_NOT_GREATER_THAN: - case CPL_TYPE_DOUBLE: - { - double *ddata2 = cpl_column_get_data_double(column2); + while (length--) + if ((double)idata1[length] > ddata2[length]) + cpl_table_unselect_row(table, length); + break; - switch (operator) { + case CPL_LESS_THAN: - case CPL_EQUAL_TO: + while (length--) + if ((double)idata1[length] >= ddata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if ((double)idata1[length] != ddata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_NOT_LESS_THAN: - case CPL_NOT_EQUAL_TO: + while (length--) + if ((double)idata1[length] < ddata2[length]) + cpl_table_unselect_row(table, length); + break; + } - while (length--) - if ((double)idata1[length] == ddata2[length]) - cpl_table_unselect_row(table, length); - break; + break; + } - case CPL_GREATER_THAN: + default: - while (length--) - if ((double)idata1[length] <= ddata2[length]) - cpl_table_unselect_row(table, length); - break; + break; - case CPL_NOT_GREATER_THAN: + } // switch(type2) - while (length--) - if ((double)idata1[length] > ddata2[length]) - cpl_table_unselect_row(table, length); - break; + break; - case CPL_LESS_THAN: + } // case CPL_TYPE_INT - while (length--) - if ((double)idata1[length] >= ddata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_TYPE_LONG: { + long *ldata1 = cpl_column_get_data_long(column1); - case CPL_NOT_LESS_THAN: + switch (type2) { + case CPL_TYPE_INT: { + int *idata2 = cpl_column_get_data_int(column2); - while (length--) - if ((double)idata1[length] < ddata2[length]) - cpl_table_unselect_row(table, length); - break; - } + switch (operator) { + case CPL_EQUAL_TO: - break; - } + while (length--) + if (ldata1[length] != (long)idata2[length]) + cpl_table_unselect_row(table, length); + break; - default: + case CPL_NOT_EQUAL_TO: - break; + while (length--) + if (ldata1[length] == (long)idata2[length]) + cpl_table_unselect_row(table, length); + break; - } // switch(type2) + case CPL_GREATER_THAN: - break; + while (length--) + if (ldata1[length] <= (long)idata2[length]) + cpl_table_unselect_row(table, length); + break; - } // case CPL_TYPE_INT + case CPL_NOT_GREATER_THAN: - case CPL_TYPE_LONG: - { - long *ldata1 = cpl_column_get_data_long(column1); + while (length--) + if (ldata1[length] > (long)idata2[length]) + cpl_table_unselect_row(table, length); + break; - switch (type2) { + case CPL_LESS_THAN: - case CPL_TYPE_INT: - { - int *idata2 = cpl_column_get_data_int(column2); + while (length--) + if (ldata1[length] >= (long)idata2[length]) + cpl_table_unselect_row(table, length); + break; - switch (operator) { + case CPL_NOT_LESS_THAN: - case CPL_EQUAL_TO: + while (length--) + if (ldata1[length] < (long)idata2[length]) + cpl_table_unselect_row(table, length); + break; + } - while (length--) - if (ldata1[length] != (long)idata2[length]) - cpl_table_unselect_row(table, length); - break; + break; + } - case CPL_NOT_EQUAL_TO: + case CPL_TYPE_LONG: { + long *ldata2 = cpl_column_get_data_long(column2); - while (length--) - if (ldata1[length] == (long)idata2[length]) - cpl_table_unselect_row(table, length); - break; + switch (operator) { + case CPL_EQUAL_TO: - case CPL_GREATER_THAN: + while (length--) + if (ldata1[length] != ldata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if (ldata1[length] <= (long)idata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_NOT_EQUAL_TO: - case CPL_NOT_GREATER_THAN: + while (length--) + if (ldata1[length] == ldata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if (ldata1[length] > (long)idata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_GREATER_THAN: - case CPL_LESS_THAN: + while (length--) + if (ldata1[length] <= ldata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if (ldata1[length] >= (long)idata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_NOT_GREATER_THAN: - case CPL_NOT_LESS_THAN: + while (length--) + if (ldata1[length] > ldata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if (ldata1[length] < (long)idata2[length]) - cpl_table_unselect_row(table, length); - break; - } + case CPL_LESS_THAN: - break; - } + while (length--) + if (ldata1[length] >= ldata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_TYPE_LONG: - { - long *ldata2 = cpl_column_get_data_long(column2); + case CPL_NOT_LESS_THAN: - switch (operator) { + while (length--) + if (ldata1[length] < ldata2[length]) + cpl_table_unselect_row(table, length); + break; + } - case CPL_EQUAL_TO: + break; + } - while (length--) - if (ldata1[length] != ldata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_TYPE_LONG_LONG: { + long long *lldata2 = cpl_column_get_data_long_long(column2); - case CPL_NOT_EQUAL_TO: + switch (operator) { + case CPL_EQUAL_TO: - while (length--) - if (ldata1[length] == ldata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if ((long long)ldata1[length] != + lldata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_GREATER_THAN: + case CPL_NOT_EQUAL_TO: - while (length--) - if (ldata1[length] <= ldata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if ((long long)ldata1[length] == + lldata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_NOT_GREATER_THAN: + case CPL_GREATER_THAN: - while (length--) - if (ldata1[length] > ldata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if ((long long)ldata1[length] <= + lldata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_LESS_THAN: + case CPL_NOT_GREATER_THAN: - while (length--) - if (ldata1[length] >= ldata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if ((long long)ldata1[length] > lldata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_NOT_LESS_THAN: + case CPL_LESS_THAN: - while (length--) - if (ldata1[length] < ldata2[length]) - cpl_table_unselect_row(table, length); - break; - } + while (length--) + if ((long long)ldata1[length] >= + lldata2[length]) + cpl_table_unselect_row(table, length); + break; - break; - } + case CPL_NOT_LESS_THAN: - case CPL_TYPE_LONG_LONG: - { - long long *lldata2 = cpl_column_get_data_long_long(column2); + while (length--) + if ((long long)ldata1[length] < lldata2[length]) + cpl_table_unselect_row(table, length); + break; + } - switch (operator) { + break; + } - case CPL_EQUAL_TO: + case CPL_TYPE_FLOAT: { + float *fdata2 = cpl_column_get_data_float(column2); - while (length--) - if ((long long)ldata1[length] != lldata2[length]) - cpl_table_unselect_row(table, length); - break; + switch (operator) { + case CPL_EQUAL_TO: - case CPL_NOT_EQUAL_TO: + while (length--) + if ((float)ldata1[length] != fdata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if ((long long)ldata1[length] == lldata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_NOT_EQUAL_TO: - case CPL_GREATER_THAN: + while (length--) + if ((float)ldata1[length] == fdata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if ((long long)ldata1[length] <= lldata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_GREATER_THAN: - case CPL_NOT_GREATER_THAN: + while (length--) + if ((float)ldata1[length] <= fdata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if ((long long)ldata1[length] > lldata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_NOT_GREATER_THAN: - case CPL_LESS_THAN: + while (length--) + if ((float)ldata1[length] > fdata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if ((long long)ldata1[length] >= lldata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_LESS_THAN: - case CPL_NOT_LESS_THAN: + while (length--) + if ((float)ldata1[length] >= fdata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if ((long long)ldata1[length] < lldata2[length]) - cpl_table_unselect_row(table, length); - break; - } + case CPL_NOT_LESS_THAN: - break; - } + while (length--) + if ((float)ldata1[length] < fdata2[length]) + cpl_table_unselect_row(table, length); + break; + } - case CPL_TYPE_FLOAT: - { - float *fdata2 = cpl_column_get_data_float(column2); + break; + } - switch (operator) { + case CPL_TYPE_DOUBLE: { + double *ddata2 = cpl_column_get_data_double(column2); - case CPL_EQUAL_TO: + switch (operator) { + case CPL_EQUAL_TO: - while (length--) - if ((float)ldata1[length] != fdata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if ((double)ldata1[length] != ddata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_NOT_EQUAL_TO: + case CPL_NOT_EQUAL_TO: - while (length--) - if ((float)ldata1[length] == fdata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if ((double)ldata1[length] == ddata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_GREATER_THAN: + case CPL_GREATER_THAN: - while (length--) - if ((float)ldata1[length] <= fdata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if ((double)ldata1[length] <= ddata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_NOT_GREATER_THAN: + case CPL_NOT_GREATER_THAN: - while (length--) - if ((float)ldata1[length] > fdata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if ((double)ldata1[length] > ddata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_LESS_THAN: + case CPL_LESS_THAN: - while (length--) - if ((float)ldata1[length] >= fdata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if ((double)ldata1[length] >= ddata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_NOT_LESS_THAN: + case CPL_NOT_LESS_THAN: - while (length--) - if ((float)ldata1[length] < fdata2[length]) - cpl_table_unselect_row(table, length); - break; - } + while (length--) + if ((double)ldata1[length] < ddata2[length]) + cpl_table_unselect_row(table, length); + break; + } - break; - } + break; + } - case CPL_TYPE_DOUBLE: - { - double *ddata2 = cpl_column_get_data_double(column2); + default: - switch (operator) { + break; - case CPL_EQUAL_TO: + } // switch (type2) - while (length--) - if ((double)ldata1[length] != ddata2[length]) - cpl_table_unselect_row(table, length); - break; + break; - case CPL_NOT_EQUAL_TO: + } // case CPL_TYPE_LONG - while (length--) - if ((double)ldata1[length] == ddata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_TYPE_LONG_LONG: { + long long *lldata1 = cpl_column_get_data_long_long(column1); - case CPL_GREATER_THAN: + switch (type2) { + case CPL_TYPE_INT: { + int *idata2 = cpl_column_get_data_int(column2); - while (length--) - if ((double)ldata1[length] <= ddata2[length]) - cpl_table_unselect_row(table, length); - break; + switch (operator) { + case CPL_EQUAL_TO: - case CPL_NOT_GREATER_THAN: + while (length--) + if (lldata1[length] != + (long long)idata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if ((double)ldata1[length] > ddata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_NOT_EQUAL_TO: - case CPL_LESS_THAN: + while (length--) + if (lldata1[length] == + (long long)idata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if ((double)ldata1[length] >= ddata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_GREATER_THAN: - case CPL_NOT_LESS_THAN: + while (length--) + if (lldata1[length] <= + (long long)idata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if ((double)ldata1[length] < ddata2[length]) - cpl_table_unselect_row(table, length); - break; - } + case CPL_NOT_GREATER_THAN: - break; - } + while (length--) + if (lldata1[length] > (long long)idata2[length]) + cpl_table_unselect_row(table, length); + break; - default: + case CPL_LESS_THAN: - break; + while (length--) + if (lldata1[length] >= + (long long)idata2[length]) + cpl_table_unselect_row(table, length); + break; - } // switch (type2) + case CPL_NOT_LESS_THAN: - break; + while (length--) + if (lldata1[length] < (long long)idata2[length]) + cpl_table_unselect_row(table, length); + break; + } - } // case CPL_TYPE_LONG + break; + } - case CPL_TYPE_LONG_LONG: - { - long long *lldata1 = cpl_column_get_data_long_long(column1); + case CPL_TYPE_LONG: { + long *ldata2 = cpl_column_get_data_long(column2); - switch (type2) { + switch (operator) { + case CPL_EQUAL_TO: - case CPL_TYPE_INT: - { - int *idata2 = cpl_column_get_data_int(column2); + while (length--) + if (lldata1[length] != + (long long)ldata2[length]) + cpl_table_unselect_row(table, length); + break; - switch (operator) { + case CPL_NOT_EQUAL_TO: - case CPL_EQUAL_TO: + while (length--) + if (lldata1[length] == + (long long)ldata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if (lldata1[length] != (long long)idata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_GREATER_THAN: - case CPL_NOT_EQUAL_TO: + while (length--) + if (lldata1[length] <= + (long long)ldata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if (lldata1[length] == (long long)idata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_NOT_GREATER_THAN: - case CPL_GREATER_THAN: + while (length--) + if (lldata1[length] > (long long)ldata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if (lldata1[length] <= (long long)idata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_LESS_THAN: - case CPL_NOT_GREATER_THAN: + while (length--) + if (lldata1[length] >= + (long long)ldata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if (lldata1[length] > (long long)idata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_NOT_LESS_THAN: - case CPL_LESS_THAN: + while (length--) + if (lldata1[length] < (long long)ldata2[length]) + cpl_table_unselect_row(table, length); + break; + } - while (length--) - if (lldata1[length] >= (long long)idata2[length]) - cpl_table_unselect_row(table, length); - break; + break; + } - case CPL_NOT_LESS_THAN: + case CPL_TYPE_LONG_LONG: { + long long *lldata2 = cpl_column_get_data_long_long(column2); - while (length--) - if (lldata1[length] < (long long)idata2[length]) - cpl_table_unselect_row(table, length); - break; - } + switch (operator) { + case CPL_EQUAL_TO: - break; - } + while (length--) + if (lldata1[length] != lldata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_TYPE_LONG: - { - long *ldata2 = cpl_column_get_data_long(column2); - - switch (operator) { + case CPL_NOT_EQUAL_TO: - case CPL_EQUAL_TO: - - while (length--) - if (lldata1[length] != (long long)ldata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if (lldata1[length] == lldata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_NOT_EQUAL_TO: + case CPL_GREATER_THAN: - while (length--) - if (lldata1[length] == (long long)ldata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if (lldata1[length] <= lldata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_GREATER_THAN: + case CPL_NOT_GREATER_THAN: - while (length--) - if (lldata1[length] <= (long long)ldata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if (lldata1[length] > lldata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_NOT_GREATER_THAN: + case CPL_LESS_THAN: - while (length--) - if (lldata1[length] > (long long)ldata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if (lldata1[length] >= lldata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_LESS_THAN: + case CPL_NOT_LESS_THAN: - while (length--) - if (lldata1[length] >= (long long)ldata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if (lldata1[length] < lldata2[length]) + cpl_table_unselect_row(table, length); + break; + } - case CPL_NOT_LESS_THAN: + break; + } - while (length--) - if (lldata1[length] < (long long)ldata2[length]) - cpl_table_unselect_row(table, length); - break; - } + case CPL_TYPE_FLOAT: { + float *fdata2 = cpl_column_get_data_float(column2); - break; - } + switch (operator) { + case CPL_EQUAL_TO: - case CPL_TYPE_LONG_LONG: - { - long long *lldata2 = cpl_column_get_data_long_long(column2); + while (length--) + if ((float)lldata1[length] != fdata2[length]) + cpl_table_unselect_row(table, length); + break; - switch (operator) { + case CPL_NOT_EQUAL_TO: - case CPL_EQUAL_TO: + while (length--) + if ((float)lldata1[length] == fdata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if (lldata1[length] != lldata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_GREATER_THAN: - case CPL_NOT_EQUAL_TO: + while (length--) + if ((float)lldata1[length] <= fdata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if (lldata1[length] == lldata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_NOT_GREATER_THAN: - case CPL_GREATER_THAN: + while (length--) + if ((float)lldata1[length] > fdata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if (lldata1[length] <= lldata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_LESS_THAN: - case CPL_NOT_GREATER_THAN: + while (length--) + if ((float)lldata1[length] >= fdata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if (lldata1[length] > lldata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_NOT_LESS_THAN: - case CPL_LESS_THAN: + while (length--) + if ((float)lldata1[length] < fdata2[length]) + cpl_table_unselect_row(table, length); + break; + } - while (length--) - if (lldata1[length] >= lldata2[length]) - cpl_table_unselect_row(table, length); - break; + break; + } - case CPL_NOT_LESS_THAN: + case CPL_TYPE_DOUBLE: { + double *ddata2 = cpl_column_get_data_double(column2); - while (length--) - if (lldata1[length] < lldata2[length]) - cpl_table_unselect_row(table, length); - break; - } + switch (operator) { + case CPL_EQUAL_TO: - break; - } + while (length--) + if ((double)lldata1[length] != ddata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_TYPE_FLOAT: - { - float *fdata2 = cpl_column_get_data_float(column2); + case CPL_NOT_EQUAL_TO: - switch (operator) { + while (length--) + if ((double)lldata1[length] == ddata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_EQUAL_TO: + case CPL_GREATER_THAN: - while (length--) - if ((float)lldata1[length] != fdata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if ((double)lldata1[length] <= ddata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_NOT_EQUAL_TO: + case CPL_NOT_GREATER_THAN: - while (length--) - if ((float)lldata1[length] == fdata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if ((double)lldata1[length] > ddata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_GREATER_THAN: + case CPL_LESS_THAN: - while (length--) - if ((float)lldata1[length] <= fdata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if ((double)lldata1[length] >= ddata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_NOT_GREATER_THAN: + case CPL_NOT_LESS_THAN: - while (length--) - if ((float)lldata1[length] > fdata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if ((double)lldata1[length] < ddata2[length]) + cpl_table_unselect_row(table, length); + break; + } - case CPL_LESS_THAN: + break; + } - while (length--) - if ((float)lldata1[length] >= fdata2[length]) - cpl_table_unselect_row(table, length); - break; + default: - case CPL_NOT_LESS_THAN: + break; - while (length--) - if ((float)lldata1[length] < fdata2[length]) - cpl_table_unselect_row(table, length); - break; - } + } // switch (type2) break; - } - case CPL_TYPE_DOUBLE: - { - double *ddata2 = cpl_column_get_data_double(column2); + } // case CPL_TYPE_LONG_LONG - switch (operator) { + case CPL_TYPE_FLOAT: { + float *fdata1 = cpl_column_get_data_float(column1); - case CPL_EQUAL_TO: + switch (type2) { + case CPL_TYPE_INT: { + int *idata2 = cpl_column_get_data_int(column2); - while (length--) - if ((double)lldata1[length] != ddata2[length]) - cpl_table_unselect_row(table, length); - break; + switch (operator) { + case CPL_EQUAL_TO: - case CPL_NOT_EQUAL_TO: + while (length--) + if (fdata1[length] != (float)idata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if ((double)lldata1[length] == ddata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_NOT_EQUAL_TO: - case CPL_GREATER_THAN: + while (length--) + if (fdata1[length] == (float)idata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if ((double)lldata1[length] <= ddata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_GREATER_THAN: - case CPL_NOT_GREATER_THAN: + while (length--) + if (fdata1[length] <= (float)idata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if ((double)lldata1[length] > ddata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_NOT_GREATER_THAN: - case CPL_LESS_THAN: + while (length--) + if (fdata1[length] > (float)idata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if ((double)lldata1[length] >= ddata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_LESS_THAN: - case CPL_NOT_LESS_THAN: + while (length--) + if (fdata1[length] >= (float)idata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if ((double)lldata1[length] < ddata2[length]) - cpl_table_unselect_row(table, length); - break; - } + case CPL_NOT_LESS_THAN: - break; - } + while (length--) + if (fdata1[length] < (float)idata2[length]) + cpl_table_unselect_row(table, length); + break; + } - default: + break; + } - break; + case CPL_TYPE_LONG: { + long *ldata2 = cpl_column_get_data_long(column2); - } // switch (type2) + switch (operator) { + case CPL_EQUAL_TO: - break; + while (length--) + if (fdata1[length] != (float)ldata2[length]) + cpl_table_unselect_row(table, length); + break; - } // case CPL_TYPE_LONG_LONG + case CPL_NOT_EQUAL_TO: - case CPL_TYPE_FLOAT: - { - float *fdata1 = cpl_column_get_data_float(column1); + while (length--) + if (fdata1[length] == (float)ldata2[length]) + cpl_table_unselect_row(table, length); + break; - switch (type2) { + case CPL_GREATER_THAN: - case CPL_TYPE_INT: - { - int *idata2 = cpl_column_get_data_int(column2); + while (length--) + if (fdata1[length] <= (float)ldata2[length]) + cpl_table_unselect_row(table, length); + break; - switch (operator) { + case CPL_NOT_GREATER_THAN: - case CPL_EQUAL_TO: + while (length--) + if (fdata1[length] > (float)ldata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if (fdata1[length] != (float)idata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_LESS_THAN: - case CPL_NOT_EQUAL_TO: + while (length--) + if (fdata1[length] >= (float)ldata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if (fdata1[length] == (float)idata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_NOT_LESS_THAN: - case CPL_GREATER_THAN: + while (length--) + if (fdata1[length] < (float)ldata2[length]) + cpl_table_unselect_row(table, length); + break; + } - while (length--) - if (fdata1[length] <= (float)idata2[length]) - cpl_table_unselect_row(table, length); - break; + break; + } - case CPL_NOT_GREATER_THAN: + case CPL_TYPE_LONG_LONG: { + long long *lldata2 = cpl_column_get_data_long_long(column2); - while (length--) - if (fdata1[length] > (float)idata2[length]) - cpl_table_unselect_row(table, length); - break; + switch (operator) { + case CPL_EQUAL_TO: - case CPL_LESS_THAN: + while (length--) + if (fdata1[length] != (float)lldata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if (fdata1[length] >= (float)idata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_NOT_EQUAL_TO: - case CPL_NOT_LESS_THAN: + while (length--) + if (fdata1[length] == (float)lldata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if (fdata1[length] < (float)idata2[length]) - cpl_table_unselect_row(table, length); - break; - } + case CPL_GREATER_THAN: - break; - } + while (length--) + if (fdata1[length] <= (float)lldata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_TYPE_LONG: - { - long *ldata2 = cpl_column_get_data_long(column2); + case CPL_NOT_GREATER_THAN: - switch (operator) { + while (length--) + if (fdata1[length] > (float)lldata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_EQUAL_TO: + case CPL_LESS_THAN: - while (length--) - if (fdata1[length] != (float)ldata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if (fdata1[length] >= (float)lldata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_NOT_EQUAL_TO: + case CPL_NOT_LESS_THAN: - while (length--) - if (fdata1[length] == (float)ldata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if (fdata1[length] < (float)lldata2[length]) + cpl_table_unselect_row(table, length); + break; + } - case CPL_GREATER_THAN: + break; + } - while (length--) - if (fdata1[length] <= (float)ldata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_TYPE_FLOAT: { + float *fdata2 = cpl_column_get_data_float(column2); - case CPL_NOT_GREATER_THAN: + switch (operator) { + case CPL_EQUAL_TO: - while (length--) - if (fdata1[length] > (float)ldata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if (fdata1[length] != fdata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_LESS_THAN: + case CPL_NOT_EQUAL_TO: - while (length--) - if (fdata1[length] >= (float)ldata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if (fdata1[length] == fdata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_NOT_LESS_THAN: + case CPL_GREATER_THAN: - while (length--) - if (fdata1[length] < (float)ldata2[length]) - cpl_table_unselect_row(table, length); - break; - } + while (length--) + if (fdata1[length] <= fdata2[length]) + cpl_table_unselect_row(table, length); + break; - break; - } + case CPL_NOT_GREATER_THAN: - case CPL_TYPE_LONG_LONG: - { - long long *lldata2 = cpl_column_get_data_long_long(column2); + while (length--) + if (fdata1[length] > fdata2[length]) + cpl_table_unselect_row(table, length); + break; - switch (operator) { + case CPL_LESS_THAN: - case CPL_EQUAL_TO: + while (length--) + if (fdata1[length] >= fdata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if (fdata1[length] != (float)lldata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_NOT_LESS_THAN: - case CPL_NOT_EQUAL_TO: + while (length--) + if (fdata1[length] < fdata2[length]) + cpl_table_unselect_row(table, length); + break; + } - while (length--) - if (fdata1[length] == (float)lldata2[length]) - cpl_table_unselect_row(table, length); - break; + break; + } - case CPL_GREATER_THAN: + case CPL_TYPE_DOUBLE: { + double *ddata2 = cpl_column_get_data_double(column2); - while (length--) - if (fdata1[length] <= (float)lldata2[length]) - cpl_table_unselect_row(table, length); - break; + switch (operator) { + case CPL_EQUAL_TO: - case CPL_NOT_GREATER_THAN: + while (length--) + if ((double)fdata1[length] != ddata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if (fdata1[length] > (float)lldata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_NOT_EQUAL_TO: - case CPL_LESS_THAN: + while (length--) + if ((double)fdata1[length] == ddata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if (fdata1[length] >= (float)lldata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_GREATER_THAN: - case CPL_NOT_LESS_THAN: + while (length--) + if ((double)fdata1[length] <= ddata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if (fdata1[length] < (float)lldata2[length]) - cpl_table_unselect_row(table, length); - break; - } + case CPL_NOT_GREATER_THAN: - break; - } + while (length--) + if ((double)fdata1[length] > ddata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_TYPE_FLOAT: - { - float *fdata2 = cpl_column_get_data_float(column2); + case CPL_LESS_THAN: - switch (operator) { + while (length--) + if ((double)fdata1[length] >= ddata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_EQUAL_TO: + case CPL_NOT_LESS_THAN: - while (length--) - if (fdata1[length] != fdata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if ((double)fdata1[length] < ddata2[length]) + cpl_table_unselect_row(table, length); + break; + } - case CPL_NOT_EQUAL_TO: + break; + } - while (length--) - if (fdata1[length] == fdata2[length]) - cpl_table_unselect_row(table, length); - break; + default: - case CPL_GREATER_THAN: + break; - while (length--) - if (fdata1[length] <= fdata2[length]) - cpl_table_unselect_row(table, length); - break; - - case CPL_NOT_GREATER_THAN: - - while (length--) - if (fdata1[length] > fdata2[length]) - cpl_table_unselect_row(table, length); - break; - - case CPL_LESS_THAN: - - while (length--) - if (fdata1[length] >= fdata2[length]) - cpl_table_unselect_row(table, length); - break; - - case CPL_NOT_LESS_THAN: - - while (length--) - if (fdata1[length] < fdata2[length]) - cpl_table_unselect_row(table, length); - break; - } + } // switch (type2) break; - } - - case CPL_TYPE_DOUBLE: - { - double *ddata2 = cpl_column_get_data_double(column2); - - switch (operator) { - - case CPL_EQUAL_TO: - - while (length--) - if ((double)fdata1[length] != ddata2[length]) - cpl_table_unselect_row(table, length); - break; - - case CPL_NOT_EQUAL_TO: - - while (length--) - if ((double)fdata1[length] == ddata2[length]) - cpl_table_unselect_row(table, length); - break; - case CPL_GREATER_THAN: + } //case CPL_TYPE_FLOAT - while (length--) - if ((double)fdata1[length] <= ddata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_TYPE_DOUBLE: { + double *ddata1 = cpl_column_get_data_double(column1); - case CPL_NOT_GREATER_THAN: + switch (type2) { + case CPL_TYPE_INT: { + int *idata2 = cpl_column_get_data_int(column2); - while (length--) - if ((double)fdata1[length] > ddata2[length]) - cpl_table_unselect_row(table, length); - break; + switch (operator) { + case CPL_EQUAL_TO: - case CPL_LESS_THAN: + while (length--) + if (ddata1[length] != (double)idata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if ((double)fdata1[length] >= ddata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_NOT_EQUAL_TO: - case CPL_NOT_LESS_THAN: + while (length--) + if (ddata1[length] == (double)idata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if ((double)fdata1[length] < ddata2[length]) - cpl_table_unselect_row(table, length); - break; - } + case CPL_GREATER_THAN: - break; - } + while (length--) + if (ddata1[length] <= (double)idata2[length]) + cpl_table_unselect_row(table, length); + break; - default: + case CPL_NOT_GREATER_THAN: - break; + while (length--) + if (ddata1[length] > (double)idata2[length]) + cpl_table_unselect_row(table, length); + break; - } // switch (type2) + case CPL_LESS_THAN: - break; + while (length--) + if (ddata1[length] >= (double)idata2[length]) + cpl_table_unselect_row(table, length); + break; - } //case CPL_TYPE_FLOAT + case CPL_NOT_LESS_THAN: - case CPL_TYPE_DOUBLE: - { - double *ddata1 = cpl_column_get_data_double(column1); + while (length--) + if (ddata1[length] < (double)idata2[length]) + cpl_table_unselect_row(table, length); + break; + } - switch (type2) { + break; + } - case CPL_TYPE_INT: - { - int *idata2 = cpl_column_get_data_int(column2); + case CPL_TYPE_LONG: { + long *ldata2 = cpl_column_get_data_long(column2); - switch (operator) { + switch (operator) { + case CPL_EQUAL_TO: - case CPL_EQUAL_TO: + while (length--) + if (ddata1[length] != (double)ldata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if (ddata1[length] != (double)idata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_NOT_EQUAL_TO: - case CPL_NOT_EQUAL_TO: + while (length--) + if (ddata1[length] == (double)ldata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if (ddata1[length] == (double)idata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_GREATER_THAN: - case CPL_GREATER_THAN: + while (length--) + if (ddata1[length] <= (double)ldata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if (ddata1[length] <= (double)idata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_NOT_GREATER_THAN: - case CPL_NOT_GREATER_THAN: + while (length--) + if (ddata1[length] > (double)ldata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if (ddata1[length] > (double)idata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_LESS_THAN: - case CPL_LESS_THAN: + while (length--) + if (ddata1[length] >= (double)ldata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if (ddata1[length] >= (double)idata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_NOT_LESS_THAN: - case CPL_NOT_LESS_THAN: + while (length--) + if (ddata1[length] < (double)ldata2[length]) + cpl_table_unselect_row(table, length); + break; + } - while (length--) - if (ddata1[length] < (double)idata2[length]) - cpl_table_unselect_row(table, length); - break; - } + break; + } - break; - } + case CPL_TYPE_LONG_LONG: { + long long *lldata2 = cpl_column_get_data_long_long(column2); - case CPL_TYPE_LONG: - { - long *ldata2 = cpl_column_get_data_long(column2); + switch (operator) { + case CPL_EQUAL_TO: - switch (operator) { + while (length--) + if (ddata1[length] != (double)lldata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_EQUAL_TO: + case CPL_NOT_EQUAL_TO: - while (length--) - if (ddata1[length] != (double)ldata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if (ddata1[length] == (double)lldata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_NOT_EQUAL_TO: + case CPL_GREATER_THAN: - while (length--) - if (ddata1[length] == (double)ldata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if (ddata1[length] <= (double)lldata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_GREATER_THAN: + case CPL_NOT_GREATER_THAN: - while (length--) - if (ddata1[length] <= (double)ldata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if (ddata1[length] > (double)lldata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_NOT_GREATER_THAN: + case CPL_LESS_THAN: - while (length--) - if (ddata1[length] > (double)ldata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if (ddata1[length] >= (double)lldata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_LESS_THAN: + case CPL_NOT_LESS_THAN: - while (length--) - if (ddata1[length] >= (double)ldata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if (ddata1[length] < (double)lldata2[length]) + cpl_table_unselect_row(table, length); + break; + } - case CPL_NOT_LESS_THAN: + break; + } - while (length--) - if (ddata1[length] < (double)ldata2[length]) - cpl_table_unselect_row(table, length); - break; - } + case CPL_TYPE_FLOAT: { + float *fdata2 = cpl_column_get_data_float(column2); - break; - } + switch (operator) { + case CPL_EQUAL_TO: - case CPL_TYPE_LONG_LONG: - { - long long *lldata2 = cpl_column_get_data_long_long(column2); + while (length--) + if (ddata1[length] != (double)fdata2[length]) + cpl_table_unselect_row(table, length); + break; - switch (operator) { + case CPL_NOT_EQUAL_TO: - case CPL_EQUAL_TO: + while (length--) + if (ddata1[length] == (double)fdata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if (ddata1[length] != (double)lldata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_GREATER_THAN: - case CPL_NOT_EQUAL_TO: + while (length--) + if (ddata1[length] <= (double)fdata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if (ddata1[length] == (double)lldata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_NOT_GREATER_THAN: - case CPL_GREATER_THAN: + while (length--) + if (ddata1[length] > (double)fdata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if (ddata1[length] <= (double)lldata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_LESS_THAN: - case CPL_NOT_GREATER_THAN: + while (length--) + if (ddata1[length] >= (double)fdata2[length]) + cpl_table_unselect_row(table, length); + break; - while (length--) - if (ddata1[length] > (double)lldata2[length]) - cpl_table_unselect_row(table, length); - break; + case CPL_NOT_LESS_THAN: - case CPL_LESS_THAN: + while (length--) + if (ddata1[length] < (double)fdata2[length]) + cpl_table_unselect_row(table, length); + break; + } - while (length--) - if (ddata1[length] >= (double)lldata2[length]) - cpl_table_unselect_row(table, length); - break; + break; + } - case CPL_NOT_LESS_THAN: + case CPL_TYPE_DOUBLE: { + double *ddata2 = cpl_column_get_data_double(column2); - while (length--) - if (ddata1[length] < (double)lldata2[length]) - cpl_table_unselect_row(table, length); - break; - } + switch (operator) { + case CPL_EQUAL_TO: - break; - } + while (length--) + if (ddata1[length] != ddata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_TYPE_FLOAT: - { - float *fdata2 = cpl_column_get_data_float(column2); + case CPL_NOT_EQUAL_TO: - switch (operator) { + while (length--) + if (ddata1[length] == ddata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_EQUAL_TO: + case CPL_GREATER_THAN: - while (length--) - if (ddata1[length] != (double)fdata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if (ddata1[length] <= ddata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_NOT_EQUAL_TO: + case CPL_NOT_GREATER_THAN: - while (length--) - if (ddata1[length] == (double)fdata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if (ddata1[length] > ddata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_GREATER_THAN: + case CPL_LESS_THAN: - while (length--) - if (ddata1[length] <= (double)fdata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if (ddata1[length] >= ddata2[length]) + cpl_table_unselect_row(table, length); + break; - case CPL_NOT_GREATER_THAN: + case CPL_NOT_LESS_THAN: - while (length--) - if (ddata1[length] > (double)fdata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if (ddata1[length] < ddata2[length]) + cpl_table_unselect_row(table, length); + break; + } - case CPL_LESS_THAN: + break; + } - while (length--) - if (ddata1[length] >= (double)fdata2[length]) - cpl_table_unselect_row(table, length); - break; + default: - case CPL_NOT_LESS_THAN: + break; - while (length--) - if (ddata1[length] < (double)fdata2[length]) - cpl_table_unselect_row(table, length); - break; - } + } // end switch (type2) break; - } - case CPL_TYPE_DOUBLE: - { - double *ddata2 = cpl_column_get_data_double(column2); + } // end CPL_TYPE_DOUBLE - switch (operator) { + case CPL_TYPE_STRING: { + sdata1 = cpl_column_get_data_string(column1); + sdata2 = cpl_column_get_data_string(column2); - case CPL_EQUAL_TO: + switch (operator) { + case CPL_EQUAL_TO: - while (length--) - if (ddata1[length] != ddata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if (strcmp(sdata1[length], sdata2[length])) + cpl_table_unselect_row(table, length); + break; - case CPL_NOT_EQUAL_TO: + case CPL_NOT_EQUAL_TO: - while (length--) - if (ddata1[length] == ddata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if (!strcmp(sdata1[length], sdata2[length])) + cpl_table_unselect_row(table, length); + break; - case CPL_GREATER_THAN: + case CPL_GREATER_THAN: - while (length--) - if (ddata1[length] <= ddata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if (strcmp(sdata1[length], sdata2[length]) <= 0) + cpl_table_unselect_row(table, length); + break; - case CPL_NOT_GREATER_THAN: + case CPL_NOT_GREATER_THAN: - while (length--) - if (ddata1[length] > ddata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if (strcmp(sdata1[length], sdata2[length]) > 0) + cpl_table_unselect_row(table, length); + break; - case CPL_LESS_THAN: + case CPL_LESS_THAN: - while (length--) - if (ddata1[length] >= ddata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if (strcmp(sdata1[length], sdata2[length]) >= 0) + cpl_table_unselect_row(table, length); + break; - case CPL_NOT_LESS_THAN: + case CPL_NOT_LESS_THAN: - while (length--) - if (ddata1[length] < ddata2[length]) - cpl_table_unselect_row(table, length); - break; + while (length--) + if (strcmp(sdata1[length], sdata2[length]) < 0) + cpl_table_unselect_row(table, length); + break; } break; - } - - default: - - break; - } // end switch (type2) + } // end CASE_TYPE_STRING - break; - - } // end CPL_TYPE_DOUBLE - - case CPL_TYPE_STRING: - { - sdata1 = cpl_column_get_data_string(column1); - sdata2 = cpl_column_get_data_string(column2); - - switch (operator) { - - case CPL_EQUAL_TO: + default: - while (length--) - if (strcmp(sdata1[length], sdata2[length])) - cpl_table_unselect_row(table, length); break; - case CPL_NOT_EQUAL_TO: + } // end switch (type1) - while (length--) - if (!strcmp(sdata1[length], sdata2[length])) - cpl_table_unselect_row(table, length); - break; - - case CPL_GREATER_THAN: - - while (length--) - if (strcmp(sdata1[length], sdata2[length]) <= 0) - cpl_table_unselect_row(table, length); - break; - - case CPL_NOT_GREATER_THAN: - - while (length--) - if (strcmp(sdata1[length], sdata2[length]) > 0) - cpl_table_unselect_row(table, length); - break; - - case CPL_LESS_THAN: - - while (length--) - if (strcmp(sdata1[length], sdata2[length]) >= 0) - cpl_table_unselect_row(table, length); - break; - - case CPL_NOT_LESS_THAN: - - while (length--) - if (strcmp(sdata1[length], sdata2[length]) < 0) - cpl_table_unselect_row(table, length); - break; - } - - break; - - } // end CASE_TYPE_STRING - - default: - - break; - - } // end switch (type1) - - return table->selectcount; - -} + return table->selectcount; +} /** @@ -16343,22 +16209,24 @@ * See also the function @c cpl_table_and_selected(). */ -cpl_size cpl_table_or_selected(cpl_table *table, const char *name1, - cpl_table_select_operator operator, - const char *name2) +cpl_size +cpl_table_or_selected(cpl_table *table, + const char *name1, + cpl_table_select_operator + operator, + const char * name2) { - - cpl_type type1; - cpl_type type2; + cpl_type type1; + cpl_type type2; cpl_column_flag *nulldata1; cpl_column_flag *nulldata2; - char **sdata1; - char **sdata2; - cpl_size nullcount1; - cpl_size nullcount2; - cpl_size length; - cpl_column *column1 = cpl_table_find_column_(table, name1); - cpl_column *column2 = cpl_table_find_column_(table, name2); + char **sdata1; + char **sdata2; + cpl_size nullcount1; + cpl_size nullcount2; + cpl_size length; + cpl_column *column1 = cpl_table_find_column_(table, name1); + cpl_column *column2 = cpl_table_find_column_(table, name2); if (!column1 || !column2) { (void)cpl_error_set_where_(); @@ -16383,16 +16251,16 @@ } } - nulldata1 = cpl_column_get_data_invalid(column1); - nulldata2 = cpl_column_get_data_invalid(column2); + nulldata1 = cpl_column_get_data_invalid(column1); + nulldata2 = cpl_column_get_data_invalid(column2); nullcount1 = cpl_column_count_invalid(column1); nullcount2 = cpl_column_count_invalid(column2); - length = cpl_column_get_size(column1); + length = cpl_column_get_size(column1); if (length == 0) return 0; - if (table->selectcount == length) /* It's already all selected */ + if (table->selectcount == length) /* It's already all selected */ return length; if (nullcount1 == length || nullcount2 == length) @@ -16403,4633 +16271,5119 @@ */ switch (type1) { + case CPL_TYPE_INT: { + int *idata1 = cpl_column_get_data_int(column1); - case CPL_TYPE_INT: - { - int *idata1 = cpl_column_get_data_int(column1); + switch (type2) { + case CPL_TYPE_INT: { + int *idata2 = cpl_column_get_data_int(column2); + + switch (operator) { + case CPL_EQUAL_TO: + + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (idata1[length] == idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (idata1[length] == idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (idata1[length] == idata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (idata1[length] == idata2[length]) + cpl_table_select_row(table, length); + } - switch (type2) { + break; - case CPL_TYPE_INT: - { - int *idata2 = cpl_column_get_data_int(column2); + case CPL_NOT_EQUAL_TO: - switch (operator) { + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (idata1[length] != idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (idata1[length] != idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (idata1[length] != idata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (idata1[length] != idata2[length]) + cpl_table_select_row(table, length); + } - case CPL_EQUAL_TO: + break; - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (idata1[length] == idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (idata1[length] == idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (idata1[length] == idata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (idata1[length] == idata2[length]) - cpl_table_select_row(table, length); - } + case CPL_GREATER_THAN: - break; + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (idata1[length] > idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (idata1[length] > idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (idata1[length] > idata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (idata1[length] > idata2[length]) + cpl_table_select_row(table, length); + } - case CPL_NOT_EQUAL_TO: + break; - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (idata1[length] != idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (idata1[length] != idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (idata1[length] != idata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (idata1[length] != idata2[length]) - cpl_table_select_row(table, length); - } + case CPL_NOT_GREATER_THAN: - break; + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (idata1[length] <= idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (idata1[length] <= idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (idata1[length] <= idata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (idata1[length] <= idata2[length]) + cpl_table_select_row(table, length); + } - case CPL_GREATER_THAN: + break; - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (idata1[length] > idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (idata1[length] > idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (idata1[length] > idata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (idata1[length] > idata2[length]) - cpl_table_select_row(table, length); - } + case CPL_LESS_THAN: - break; + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (idata1[length] < idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (idata1[length] < idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (idata1[length] < idata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (idata1[length] < idata2[length]) + cpl_table_select_row(table, length); + } - case CPL_NOT_GREATER_THAN: + break; - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (idata1[length] <= idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (idata1[length] <= idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (idata1[length] <= idata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (idata1[length] <= idata2[length]) - cpl_table_select_row(table, length); - } + case CPL_NOT_LESS_THAN: - break; + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (idata1[length] >= idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (idata1[length] >= idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (idata1[length] >= idata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (idata1[length] >= idata2[length]) + cpl_table_select_row(table, length); + } - case CPL_LESS_THAN: + break; + } - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (idata1[length] < idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (idata1[length] < idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (idata1[length] < idata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (idata1[length] < idata2[length]) - cpl_table_select_row(table, length); + break; } - break; + case CPL_TYPE_LONG: { + long *ldata2 = cpl_column_get_data_long(column2); - case CPL_NOT_LESS_THAN: + switch (operator) { + case CPL_EQUAL_TO: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (idata1[length] >= idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (idata1[length] >= idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (idata1[length] >= idata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (idata1[length] >= idata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((long)idata1[length] == + ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((long)idata1[length] == + ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((long)idata1[length] == + ldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((long)idata1[length] == ldata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - } + case CPL_NOT_EQUAL_TO: - break; - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((long)idata1[length] != + ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((long)idata1[length] != + ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((long)idata1[length] != + ldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((long)idata1[length] != ldata2[length]) + cpl_table_select_row(table, length); + } - case CPL_TYPE_LONG: - { - long *ldata2 = cpl_column_get_data_long(column2); + break; - switch (operator) { + case CPL_GREATER_THAN: - case CPL_EQUAL_TO: + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((long)idata1[length] > + ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((long)idata1[length] > + ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((long)idata1[length] > + ldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((long)idata1[length] > ldata2[length]) + cpl_table_select_row(table, length); + } - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((long)idata1[length] == ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((long)idata1[length] == ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((long)idata1[length] == ldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((long)idata1[length] == ldata2[length]) - cpl_table_select_row(table, length); - } + break; - break; + case CPL_NOT_GREATER_THAN: - case CPL_NOT_EQUAL_TO: + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((long)idata1[length] <= + ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((long)idata1[length] <= + ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((long)idata1[length] <= + ldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((long)idata1[length] <= ldata2[length]) + cpl_table_select_row(table, length); + } - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((long)idata1[length] != ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((long)idata1[length] != ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((long)idata1[length] != ldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((long)idata1[length] != ldata2[length]) - cpl_table_select_row(table, length); - } + break; - break; + case CPL_LESS_THAN: - case CPL_GREATER_THAN: + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((long)idata1[length] < + ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((long)idata1[length] < + ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((long)idata1[length] < + ldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((long)idata1[length] < ldata2[length]) + cpl_table_select_row(table, length); + } - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((long)idata1[length] > ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((long)idata1[length] > ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((long)idata1[length] > ldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((long)idata1[length] > ldata2[length]) - cpl_table_select_row(table, length); - } + break; - break; + case CPL_NOT_LESS_THAN: - case CPL_NOT_GREATER_THAN: + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((long)idata1[length] >= + ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((long)idata1[length] >= + ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((long)idata1[length] >= + ldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((long)idata1[length] >= ldata2[length]) + cpl_table_select_row(table, length); + } - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((long)idata1[length] <= ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((long)idata1[length] <= ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((long)idata1[length] <= ldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((long)idata1[length] <= ldata2[length]) - cpl_table_select_row(table, length); + break; + } + + break; } - break; + case CPL_TYPE_LONG_LONG: { + long long *lldata2 = cpl_column_get_data_long_long(column2); - case CPL_LESS_THAN: + switch (operator) { + case CPL_EQUAL_TO: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((long)idata1[length] < ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((long)idata1[length] < ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((long)idata1[length] < ldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((long)idata1[length] < ldata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((long long)idata1[length] == + lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((long long)idata1[length] == + lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((long long)idata1[length] == + lldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((long long)idata1[length] == + lldata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_NOT_LESS_THAN: + case CPL_NOT_EQUAL_TO: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((long)idata1[length] >= ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((long)idata1[length] >= ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((long)idata1[length] >= ldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((long)idata1[length] >= ldata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((long long)idata1[length] != + lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((long long)idata1[length] != + lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((long long)idata1[length] != + lldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((long long)idata1[length] != + lldata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - } + case CPL_GREATER_THAN: - break; - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((long long)idata1[length] > + lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((long long)idata1[length] > + lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((long long)idata1[length] > + lldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((long long)idata1[length] > + lldata2[length]) + cpl_table_select_row(table, length); + } - case CPL_TYPE_LONG_LONG: - { - long long *lldata2 = cpl_column_get_data_long_long(column2); + break; - switch (operator) { + case CPL_NOT_GREATER_THAN: - case CPL_EQUAL_TO: + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((long long)idata1[length] <= + lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((long long)idata1[length] <= + lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((long long)idata1[length] <= + lldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((long long)idata1[length] <= + lldata2[length]) + cpl_table_select_row(table, length); + } - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((long long)idata1[length] == lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((long long)idata1[length] == lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((long long)idata1[length] == lldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((long long)idata1[length] == lldata2[length]) - cpl_table_select_row(table, length); - } + break; - break; + case CPL_LESS_THAN: - case CPL_NOT_EQUAL_TO: + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((long long)idata1[length] < + lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((long long)idata1[length] < + lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((long long)idata1[length] < + lldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((long long)idata1[length] < + lldata2[length]) + cpl_table_select_row(table, length); + } - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((long long)idata1[length] != lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((long long)idata1[length] != lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((long long)idata1[length] != lldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((long long)idata1[length] != lldata2[length]) - cpl_table_select_row(table, length); - } + break; - break; + case CPL_NOT_LESS_THAN: - case CPL_GREATER_THAN: + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((long long)idata1[length] >= + lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((long long)idata1[length] >= + lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((long long)idata1[length] >= + lldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((long long)idata1[length] >= + lldata2[length]) + cpl_table_select_row(table, length); + } - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((long long)idata1[length] > lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((long long)idata1[length] > lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((long long)idata1[length] > lldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((long long)idata1[length] > lldata2[length]) - cpl_table_select_row(table, length); + break; + } + + break; } - break; + case CPL_TYPE_FLOAT: { + float *fdata2 = cpl_column_get_data_float(column2); - case CPL_NOT_GREATER_THAN: + switch (operator) { + case CPL_EQUAL_TO: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((long long)idata1[length] <= lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((long long)idata1[length] <= lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((long long)idata1[length] <= lldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((long long)idata1[length] <= lldata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((float)idata1[length] == + fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((float)idata1[length] == + fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((float)idata1[length] == + fdata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((float)idata1[length] == fdata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_LESS_THAN: + case CPL_NOT_EQUAL_TO: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((long long)idata1[length] < lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((long long)idata1[length] < lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((long long)idata1[length] < lldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((long long)idata1[length] < lldata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((float)idata1[length] != + fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((float)idata1[length] != + fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((float)idata1[length] != + fdata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((float)idata1[length] != fdata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_NOT_LESS_THAN: + case CPL_GREATER_THAN: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((long long)idata1[length] >= lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((long long)idata1[length] >= lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((long long)idata1[length] >= lldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((long long)idata1[length] >= lldata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((float)idata1[length] > + fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((float)idata1[length] > + fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((float)idata1[length] > + fdata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((float)idata1[length] > fdata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - } + case CPL_NOT_GREATER_THAN: - break; - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((float)idata1[length] <= + fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((float)idata1[length] <= + fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((float)idata1[length] <= + fdata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((float)idata1[length] <= fdata2[length]) + cpl_table_select_row(table, length); + } - case CPL_TYPE_FLOAT: - { - float *fdata2 = cpl_column_get_data_float(column2); + break; - switch (operator) { + case CPL_LESS_THAN: + + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((float)idata1[length] < + fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((float)idata1[length] < + fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((float)idata1[length] < + fdata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((float)idata1[length] < fdata2[length]) + cpl_table_select_row(table, length); + } - case CPL_EQUAL_TO: + break; - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((float)idata1[length] == fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((float)idata1[length] == fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((float)idata1[length] == fdata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((float)idata1[length] == fdata2[length]) - cpl_table_select_row(table, length); - } + case CPL_NOT_LESS_THAN: - break; + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((float)idata1[length] >= + fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((float)idata1[length] >= + fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((float)idata1[length] >= + fdata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((float)idata1[length] >= fdata2[length]) + cpl_table_select_row(table, length); + } - case CPL_NOT_EQUAL_TO: + break; + } - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((float)idata1[length] != fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((float)idata1[length] != fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((float)idata1[length] != fdata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((float)idata1[length] != fdata2[length]) - cpl_table_select_row(table, length); + break; } - break; - - case CPL_GREATER_THAN: + case CPL_TYPE_DOUBLE: { + double *ddata2 = cpl_column_get_data_double(column2); - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((float)idata1[length] > fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((float)idata1[length] > fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((float)idata1[length] > fdata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((float)idata1[length] > fdata2[length]) - cpl_table_select_row(table, length); - } + switch (operator) { + case CPL_EQUAL_TO: - break; + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((double)idata1[length] == + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((double)idata1[length] == + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((double)idata1[length] == + ddata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((double)idata1[length] == + ddata2[length]) + cpl_table_select_row(table, length); + } - case CPL_NOT_GREATER_THAN: + break; - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((float)idata1[length] <= fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((float)idata1[length] <= fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((float)idata1[length] <= fdata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((float)idata1[length] <= fdata2[length]) - cpl_table_select_row(table, length); - } + case CPL_NOT_EQUAL_TO: - break; + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((double)idata1[length] != + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((double)idata1[length] != + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((double)idata1[length] != + ddata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((double)idata1[length] != + ddata2[length]) + cpl_table_select_row(table, length); + } - case CPL_LESS_THAN: + break; - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((float)idata1[length] < fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((float)idata1[length] < fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((float)idata1[length] < fdata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((float)idata1[length] < fdata2[length]) - cpl_table_select_row(table, length); - } + case CPL_GREATER_THAN: - break; + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((double)idata1[length] > + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((double)idata1[length] > + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((double)idata1[length] > + ddata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((double)idata1[length] > ddata2[length]) + cpl_table_select_row(table, length); + } - case CPL_NOT_LESS_THAN: + break; - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((float)idata1[length] >= fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((float)idata1[length] >= fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((float)idata1[length] >= fdata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((float)idata1[length] >= fdata2[length]) - cpl_table_select_row(table, length); - } + case CPL_NOT_GREATER_THAN: - break; + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((double)idata1[length] <= + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((double)idata1[length] <= + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((double)idata1[length] <= + ddata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((double)idata1[length] <= + ddata2[length]) + cpl_table_select_row(table, length); + } - } + break; - break; - } + case CPL_LESS_THAN: - case CPL_TYPE_DOUBLE: - { - double *ddata2 = cpl_column_get_data_double(column2); - - switch (operator) { - - case CPL_EQUAL_TO: - - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((double)idata1[length] == ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((double)idata1[length] == ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((double)idata1[length] == ddata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((double)idata1[length] == ddata2[length]) - cpl_table_select_row(table, length); - } - - break; - - case CPL_NOT_EQUAL_TO: - - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((double)idata1[length] != ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((double)idata1[length] != ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((double)idata1[length] != ddata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((double)idata1[length] != ddata2[length]) - cpl_table_select_row(table, length); - } - - break; - - case CPL_GREATER_THAN: - - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((double)idata1[length] > ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((double)idata1[length] > ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((double)idata1[length] > ddata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((double)idata1[length] > ddata2[length]) - cpl_table_select_row(table, length); - } - - break; - - case CPL_NOT_GREATER_THAN: - - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((double)idata1[length] <= ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((double)idata1[length] <= ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((double)idata1[length] <= ddata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((double)idata1[length] <= ddata2[length]) - cpl_table_select_row(table, length); - } - - break; - - case CPL_LESS_THAN: - - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((double)idata1[length] < ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((double)idata1[length] < ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((double)idata1[length] < ddata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((double)idata1[length] < ddata2[length]) - cpl_table_select_row(table, length); - } - - break; - - case CPL_NOT_LESS_THAN: - - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((double)idata1[length] >= ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((double)idata1[length] >= ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((double)idata1[length] >= ddata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((double)idata1[length] >= ddata2[length]) - cpl_table_select_row(table, length); - } - - break; - - } - - break; - } - - default: - - break; - - } // end switch (type2) - - break; - - } // end case CPL_TYPE_INT - - case CPL_TYPE_LONG: - { - long *ldata1 = cpl_column_get_data_long(column1); - - switch (type2) { - - case CPL_TYPE_INT: - { - int *idata2 = cpl_column_get_data_int(column2); - - switch (operator) { - - case CPL_EQUAL_TO: - - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (ldata1[length] == (long)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (ldata1[length] == (long)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (ldata1[length] == (long)idata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (ldata1[length] == (long)idata2[length]) - cpl_table_select_row(table, length); - } - - break; - - case CPL_NOT_EQUAL_TO: - - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (ldata1[length] != (long)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (ldata1[length] != (long)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (ldata1[length] != (long)idata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (ldata1[length] != (long)idata2[length]) - cpl_table_select_row(table, length); - } - - break; - - case CPL_GREATER_THAN: - - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (ldata1[length] > (long)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (ldata1[length] > (long)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (ldata1[length] > (long)idata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (ldata1[length] > (long)idata2[length]) - cpl_table_select_row(table, length); - } - - break; - - case CPL_NOT_GREATER_THAN: - - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (ldata1[length] <= (long)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (ldata1[length] <= (long)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (ldata1[length] <= (long)idata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (ldata1[length] <= (long)idata2[length]) - cpl_table_select_row(table, length); - } - - break; - - case CPL_LESS_THAN: - - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (ldata1[length] < (long)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (ldata1[length] < (long)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (ldata1[length] < (long)idata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (ldata1[length] < (long)idata2[length]) - cpl_table_select_row(table, length); - } - - break; - - case CPL_NOT_LESS_THAN: - - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (ldata1[length] >= (long)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (ldata1[length] >= (long)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (ldata1[length] >= (long)idata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (ldata1[length] >= (long)idata2[length]) - cpl_table_select_row(table, length); - } - - break; - - } - - break; - } - - case CPL_TYPE_LONG: - { - long *ldata2 = cpl_column_get_data_long(column2); - - switch (operator) { - - case CPL_EQUAL_TO: - - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (ldata1[length] == ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (ldata1[length] == ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (ldata1[length] == ldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (ldata1[length] == ldata2[length]) - cpl_table_select_row(table, length); - } - - break; - - case CPL_NOT_EQUAL_TO: - - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (ldata1[length] != ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (ldata1[length] != ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (ldata1[length] != ldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (ldata1[length] != ldata2[length]) - cpl_table_select_row(table, length); - } - - break; - - case CPL_GREATER_THAN: - - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (ldata1[length] > ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (ldata1[length] > ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (ldata1[length] > ldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (ldata1[length] > ldata2[length]) - cpl_table_select_row(table, length); - } - - break; - - case CPL_NOT_GREATER_THAN: - - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (ldata1[length] <= ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (ldata1[length] <= ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (ldata1[length] <= ldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (ldata1[length] <= ldata2[length]) - cpl_table_select_row(table, length); - } - - break; - - case CPL_LESS_THAN: - - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (ldata1[length] < ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (ldata1[length] < ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (ldata1[length] < ldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (ldata1[length] < ldata2[length]) - cpl_table_select_row(table, length); - } - - break; - - case CPL_NOT_LESS_THAN: - - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (ldata1[length] >= ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (ldata1[length] >= ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (ldata1[length] >= ldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (ldata1[length] >= ldata2[length]) - cpl_table_select_row(table, length); - } - - break; - - } - - break; - } - - case CPL_TYPE_LONG_LONG: - { - long long *lldata2 = cpl_column_get_data_long_long(column2); - - switch (operator) { - - case CPL_EQUAL_TO: - - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((long long)ldata1[length] == lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((long long)ldata1[length] == lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((long long)ldata1[length] == lldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((long long)ldata1[length] == lldata2[length]) - cpl_table_select_row(table, length); - } - - break; - - case CPL_NOT_EQUAL_TO: - - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((long long)ldata1[length] != lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((long long)ldata1[length] != lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((long long)ldata1[length] != lldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((long long)ldata1[length] != lldata2[length]) - cpl_table_select_row(table, length); - } - - break; - - case CPL_GREATER_THAN: - - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((long long)ldata1[length] > lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((long long)ldata1[length] > lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((long long)ldata1[length] > lldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((long long)ldata1[length] > lldata2[length]) - cpl_table_select_row(table, length); - } - - break; - - case CPL_NOT_GREATER_THAN: - - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((long long)ldata1[length] <= lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((long long)ldata1[length] <= lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((long long)ldata1[length] <= lldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((long long)ldata1[length] <= lldata2[length]) - cpl_table_select_row(table, length); - } - - break; + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((double)idata1[length] < + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((double)idata1[length] < + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((double)idata1[length] < + ddata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((double)idata1[length] < ddata2[length]) + cpl_table_select_row(table, length); + } - case CPL_LESS_THAN: + break; - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((long long)ldata1[length] < lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((long long)ldata1[length] < lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((long long)ldata1[length] < lldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((long long)ldata1[length] < lldata2[length]) - cpl_table_select_row(table, length); - } + case CPL_NOT_LESS_THAN: - break; + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((double)idata1[length] >= + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((double)idata1[length] >= + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((double)idata1[length] >= + ddata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((double)idata1[length] >= + ddata2[length]) + cpl_table_select_row(table, length); + } - case CPL_NOT_LESS_THAN: + break; + } - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((long long)ldata1[length] >= lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((long long)ldata1[length] >= lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((long long)ldata1[length] >= lldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((long long)ldata1[length] >= lldata2[length]) - cpl_table_select_row(table, length); + break; } - break; - - } - - break; - } - - case CPL_TYPE_FLOAT: - { - float *fdata2 = cpl_column_get_data_float(column2); - - switch (operator) { - - case CPL_EQUAL_TO: - - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((float)ldata1[length] == fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((float)ldata1[length] == fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((float)ldata1[length] == fdata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((float)ldata1[length] == fdata2[length]) - cpl_table_select_row(table, length); - } + default: - break; + break; - case CPL_NOT_EQUAL_TO: + } // end switch (type2) - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((float)ldata1[length] != fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((float)ldata1[length] != fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((float)ldata1[length] != fdata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((float)ldata1[length] != fdata2[length]) - cpl_table_select_row(table, length); - } + break; - break; + } // end case CPL_TYPE_INT - case CPL_GREATER_THAN: + case CPL_TYPE_LONG: { + long *ldata1 = cpl_column_get_data_long(column1); - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((float)ldata1[length] > fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((float)ldata1[length] > fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((float)ldata1[length] > fdata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((float)ldata1[length] > fdata2[length]) - cpl_table_select_row(table, length); - } + switch (type2) { + case CPL_TYPE_INT: { + int *idata2 = cpl_column_get_data_int(column2); + + switch (operator) { + case CPL_EQUAL_TO: + + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (ldata1[length] == + (long)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (ldata1[length] == + (long)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (ldata1[length] == + (long)idata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (ldata1[length] == (long)idata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_NOT_GREATER_THAN: + case CPL_NOT_EQUAL_TO: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((float)ldata1[length] <= fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((float)ldata1[length] <= fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((float)ldata1[length] <= fdata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((float)ldata1[length] <= fdata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (ldata1[length] != + (long)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (ldata1[length] != + (long)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (ldata1[length] != + (long)idata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (ldata1[length] != (long)idata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_LESS_THAN: + case CPL_GREATER_THAN: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((float)ldata1[length] < fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((float)ldata1[length] < fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((float)ldata1[length] < fdata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((float)ldata1[length] < fdata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (ldata1[length] > + (long)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (ldata1[length] > + (long)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (ldata1[length] > + (long)idata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (ldata1[length] > (long)idata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_NOT_LESS_THAN: + case CPL_NOT_GREATER_THAN: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((float)ldata1[length] >= fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((float)ldata1[length] >= fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((float)ldata1[length] >= fdata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((float)ldata1[length] >= fdata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (ldata1[length] <= + (long)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (ldata1[length] <= + (long)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (ldata1[length] <= + (long)idata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (ldata1[length] <= (long)idata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - } + case CPL_LESS_THAN: - break; - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (ldata1[length] < + (long)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (ldata1[length] < + (long)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (ldata1[length] < + (long)idata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (ldata1[length] < (long)idata2[length]) + cpl_table_select_row(table, length); + } - case CPL_TYPE_DOUBLE: - { - double *ddata2 = cpl_column_get_data_double(column2); + break; - switch (operator) { + case CPL_NOT_LESS_THAN: - case CPL_EQUAL_TO: + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (ldata1[length] >= + (long)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (ldata1[length] >= + (long)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (ldata1[length] >= + (long)idata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (ldata1[length] >= (long)idata2[length]) + cpl_table_select_row(table, length); + } - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((double)ldata1[length] == ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((double)ldata1[length] == ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((double)ldata1[length] == ddata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((double)ldata1[length] == ddata2[length]) - cpl_table_select_row(table, length); + break; + } + + break; } - break; + case CPL_TYPE_LONG: { + long *ldata2 = cpl_column_get_data_long(column2); - case CPL_NOT_EQUAL_TO: + switch (operator) { + case CPL_EQUAL_TO: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((double)ldata1[length] != ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((double)ldata1[length] != ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((double)ldata1[length] != ddata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((double)ldata1[length] != ddata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (ldata1[length] == ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (ldata1[length] == ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (ldata1[length] == ldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (ldata1[length] == ldata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_GREATER_THAN: + case CPL_NOT_EQUAL_TO: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((double)ldata1[length] > ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((double)ldata1[length] > ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((double)ldata1[length] > ddata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((double)ldata1[length] > ddata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (ldata1[length] != ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (ldata1[length] != ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (ldata1[length] != ldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (ldata1[length] != ldata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_NOT_GREATER_THAN: + case CPL_GREATER_THAN: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((double)ldata1[length] <= ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((double)ldata1[length] <= ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((double)ldata1[length] <= ddata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((double)ldata1[length] <= ddata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (ldata1[length] > ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (ldata1[length] > ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (ldata1[length] > ldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (ldata1[length] > ldata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_LESS_THAN: + case CPL_NOT_GREATER_THAN: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((double)ldata1[length] < ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((double)ldata1[length] < ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((double)ldata1[length] < ddata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((double)ldata1[length] < ddata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (ldata1[length] <= ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (ldata1[length] <= ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (ldata1[length] <= ldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (ldata1[length] <= ldata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_NOT_LESS_THAN: + case CPL_LESS_THAN: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((double)ldata1[length] >= ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((double)ldata1[length] >= ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((double)ldata1[length] >= ddata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((double)ldata1[length] >= ddata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (ldata1[length] < ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (ldata1[length] < ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (ldata1[length] < ldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (ldata1[length] < ldata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - } + case CPL_NOT_LESS_THAN: - break; - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (ldata1[length] >= ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (ldata1[length] >= ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (ldata1[length] >= ldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (ldata1[length] >= ldata2[length]) + cpl_table_select_row(table, length); + } - default: + break; + } - break; + break; + } + + case CPL_TYPE_LONG_LONG: { + long long *lldata2 = cpl_column_get_data_long_long(column2); - } // end switch (type2) + switch (operator) { + case CPL_EQUAL_TO: + + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((long long)ldata1[length] == + lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((long long)ldata1[length] == + lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((long long)ldata1[length] == + lldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((long long)ldata1[length] == + lldata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - } // end case CPL_TYPE_LONG + case CPL_NOT_EQUAL_TO: - case CPL_TYPE_LONG_LONG: - { - long long *lldata1 = cpl_column_get_data_long_long(column1); + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((long long)ldata1[length] != + lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((long long)ldata1[length] != + lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((long long)ldata1[length] != + lldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((long long)ldata1[length] != + lldata2[length]) + cpl_table_select_row(table, length); + } - switch (type2) { + break; - case CPL_TYPE_INT: - { - int *idata2 = cpl_column_get_data_int(column2); + case CPL_GREATER_THAN: - switch (operator) { + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((long long)ldata1[length] > + lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((long long)ldata1[length] > + lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((long long)ldata1[length] > + lldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((long long)ldata1[length] > + lldata2[length]) + cpl_table_select_row(table, length); + } - case CPL_EQUAL_TO: + break; - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (lldata1[length] == (long long)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (lldata1[length] == (long long)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (lldata1[length] == (long long)idata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (lldata1[length] == (long long)idata2[length]) - cpl_table_select_row(table, length); - } + case CPL_NOT_GREATER_THAN: - break; + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((long long)ldata1[length] <= + lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((long long)ldata1[length] <= + lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((long long)ldata1[length] <= + lldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((long long)ldata1[length] <= + lldata2[length]) + cpl_table_select_row(table, length); + } - case CPL_NOT_EQUAL_TO: + break; - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (lldata1[length] != (long long)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (lldata1[length] != (long long)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (lldata1[length] != (long long)idata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (lldata1[length] != (long long)idata2[length]) - cpl_table_select_row(table, length); - } + case CPL_LESS_THAN: - break; + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((long long)ldata1[length] < + lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((long long)ldata1[length] < + lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((long long)ldata1[length] < + lldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((long long)ldata1[length] < + lldata2[length]) + cpl_table_select_row(table, length); + } - case CPL_GREATER_THAN: + break; - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (lldata1[length] > (long long)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (lldata1[length] > (long long)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (lldata1[length] > (long long)idata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (lldata1[length] > (long long)idata2[length]) - cpl_table_select_row(table, length); - } + case CPL_NOT_LESS_THAN: - break; + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((long long)ldata1[length] >= + lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((long long)ldata1[length] >= + lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((long long)ldata1[length] >= + lldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((long long)ldata1[length] >= + lldata2[length]) + cpl_table_select_row(table, length); + } - case CPL_NOT_GREATER_THAN: + break; + } - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (lldata1[length] <= (long long)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (lldata1[length] <= (long long)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (lldata1[length] <= (long long)idata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (lldata1[length] <= (long long)idata2[length]) - cpl_table_select_row(table, length); + break; } - break; + case CPL_TYPE_FLOAT: { + float *fdata2 = cpl_column_get_data_float(column2); - case CPL_LESS_THAN: + switch (operator) { + case CPL_EQUAL_TO: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (lldata1[length] < (long long)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (lldata1[length] < (long long)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (lldata1[length] < (long long)idata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (lldata1[length] < (long long)idata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((float)ldata1[length] == + fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((float)ldata1[length] == + fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((float)ldata1[length] == + fdata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((float)ldata1[length] == fdata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_NOT_LESS_THAN: + case CPL_NOT_EQUAL_TO: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (lldata1[length] >= (long long)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (lldata1[length] >= (long long)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (lldata1[length] >= (long long)idata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (lldata1[length] >= (long long)idata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((float)ldata1[length] != + fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((float)ldata1[length] != + fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((float)ldata1[length] != + fdata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((float)ldata1[length] != fdata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - } + case CPL_GREATER_THAN: - break; - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((float)ldata1[length] > + fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((float)ldata1[length] > + fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((float)ldata1[length] > + fdata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((float)ldata1[length] > fdata2[length]) + cpl_table_select_row(table, length); + } - case CPL_TYPE_LONG: - { - long *ldata2 = cpl_column_get_data_long(column2); + break; - switch (operator) { + case CPL_NOT_GREATER_THAN: - case CPL_EQUAL_TO: + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((float)ldata1[length] <= + fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((float)ldata1[length] <= + fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((float)ldata1[length] <= + fdata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((float)ldata1[length] <= fdata2[length]) + cpl_table_select_row(table, length); + } - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (lldata1[length] == (long long)ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (lldata1[length] == (long long)ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (lldata1[length] == (long long)ldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (lldata1[length] == (long long)ldata2[length]) - cpl_table_select_row(table, length); - } + break; - break; + case CPL_LESS_THAN: - case CPL_NOT_EQUAL_TO: + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((float)ldata1[length] < + fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((float)ldata1[length] < + fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((float)ldata1[length] < + fdata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((float)ldata1[length] < fdata2[length]) + cpl_table_select_row(table, length); + } - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (lldata1[length] != (long long)ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (lldata1[length] != (long long)ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (lldata1[length] != (long long)ldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (lldata1[length] != (long long)ldata2[length]) - cpl_table_select_row(table, length); - } + break; - break; + case CPL_NOT_LESS_THAN: - case CPL_GREATER_THAN: + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((float)ldata1[length] >= + fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((float)ldata1[length] >= + fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((float)ldata1[length] >= + fdata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((float)ldata1[length] >= fdata2[length]) + cpl_table_select_row(table, length); + } - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (lldata1[length] > (long long)ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (lldata1[length] > (long long)ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (lldata1[length] > (long long)ldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (lldata1[length] > (long long)ldata2[length]) - cpl_table_select_row(table, length); + break; + } + + break; } - break; + case CPL_TYPE_DOUBLE: { + double *ddata2 = cpl_column_get_data_double(column2); - case CPL_NOT_GREATER_THAN: + switch (operator) { + case CPL_EQUAL_TO: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (lldata1[length] <= (long long)ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (lldata1[length] <= (long long)ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (lldata1[length] <= (long long)ldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (lldata1[length] <= (long long)ldata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((double)ldata1[length] == + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((double)ldata1[length] == + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((double)ldata1[length] == + ddata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((double)ldata1[length] == + ddata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_LESS_THAN: + case CPL_NOT_EQUAL_TO: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (lldata1[length] < (long long)ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (lldata1[length] < (long long)ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (lldata1[length] < (long long)ldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (lldata1[length] < (long long)ldata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((double)ldata1[length] != + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((double)ldata1[length] != + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((double)ldata1[length] != + ddata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((double)ldata1[length] != + ddata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_NOT_LESS_THAN: + case CPL_GREATER_THAN: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (lldata1[length] >= (long long)ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (lldata1[length] >= (long long)ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (lldata1[length] >= (long long)ldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (lldata1[length] >= (long long)ldata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((double)ldata1[length] > + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((double)ldata1[length] > + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((double)ldata1[length] > + ddata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((double)ldata1[length] > ddata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - } + case CPL_NOT_GREATER_THAN: - break; - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((double)ldata1[length] <= + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((double)ldata1[length] <= + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((double)ldata1[length] <= + ddata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((double)ldata1[length] <= + ddata2[length]) + cpl_table_select_row(table, length); + } - case CPL_TYPE_LONG_LONG: - { - long long *lldata2 = cpl_column_get_data_long_long(column2); + break; - switch (operator) { + case CPL_LESS_THAN: - case CPL_EQUAL_TO: + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((double)ldata1[length] < + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((double)ldata1[length] < + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((double)ldata1[length] < + ddata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((double)ldata1[length] < ddata2[length]) + cpl_table_select_row(table, length); + } - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (lldata1[length] == lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (lldata1[length] == lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (lldata1[length] == lldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (lldata1[length] == lldata2[length]) - cpl_table_select_row(table, length); - } + break; - break; + case CPL_NOT_LESS_THAN: - case CPL_NOT_EQUAL_TO: + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((double)ldata1[length] >= + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((double)ldata1[length] >= + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((double)ldata1[length] >= + ddata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((double)ldata1[length] >= + ddata2[length]) + cpl_table_select_row(table, length); + } - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (lldata1[length] != lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (lldata1[length] != lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (lldata1[length] != lldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (lldata1[length] != lldata2[length]) - cpl_table_select_row(table, length); + break; + } + + break; } - break; + default: + + break; - case CPL_GREATER_THAN: + } // end switch (type2) - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (lldata1[length] > lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (lldata1[length] > lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (lldata1[length] > lldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (lldata1[length] > lldata2[length]) - cpl_table_select_row(table, length); - } + break; - break; + } // end case CPL_TYPE_LONG - case CPL_NOT_GREATER_THAN: + case CPL_TYPE_LONG_LONG: { + long long *lldata1 = cpl_column_get_data_long_long(column1); - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (lldata1[length] <= lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (lldata1[length] <= lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (lldata1[length] <= lldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (lldata1[length] <= lldata2[length]) - cpl_table_select_row(table, length); - } + switch (type2) { + case CPL_TYPE_INT: { + int *idata2 = cpl_column_get_data_int(column2); + + switch (operator) { + case CPL_EQUAL_TO: + + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (lldata1[length] == + (long long)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (lldata1[length] == + (long long)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (lldata1[length] == + (long long)idata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (lldata1[length] == + (long long)idata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_LESS_THAN: + case CPL_NOT_EQUAL_TO: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (lldata1[length] < lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (lldata1[length] < lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (lldata1[length] < lldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (lldata1[length] < lldata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (lldata1[length] != + (long long)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (lldata1[length] != + (long long)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (lldata1[length] != + (long long)idata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (lldata1[length] != + (long long)idata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_NOT_LESS_THAN: + case CPL_GREATER_THAN: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (lldata1[length] >= lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (lldata1[length] >= lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (lldata1[length] >= lldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (lldata1[length] >= lldata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (lldata1[length] > + (long long)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (lldata1[length] > + (long long)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (lldata1[length] > + (long long)idata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (lldata1[length] > + (long long)idata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - } + case CPL_NOT_GREATER_THAN: - break; - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (lldata1[length] <= + (long long)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (lldata1[length] <= + (long long)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (lldata1[length] <= + (long long)idata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (lldata1[length] <= + (long long)idata2[length]) + cpl_table_select_row(table, length); + } - case CPL_TYPE_FLOAT: - { - float *fdata2 = cpl_column_get_data_float(column2); + break; - switch (operator) { + case CPL_LESS_THAN: - case CPL_EQUAL_TO: + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (lldata1[length] < + (long long)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (lldata1[length] < + (long long)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (lldata1[length] < + (long long)idata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (lldata1[length] < + (long long)idata2[length]) + cpl_table_select_row(table, length); + } - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((float)lldata1[length] == fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((float)lldata1[length] == fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((float)lldata1[length] == fdata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((float)lldata1[length] == fdata2[length]) - cpl_table_select_row(table, length); - } + break; - break; + case CPL_NOT_LESS_THAN: - case CPL_NOT_EQUAL_TO: + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (lldata1[length] >= + (long long)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (lldata1[length] >= + (long long)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (lldata1[length] >= + (long long)idata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (lldata1[length] >= + (long long)idata2[length]) + cpl_table_select_row(table, length); + } - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((float)lldata1[length] != fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((float)lldata1[length] != fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((float)lldata1[length] != fdata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((float)lldata1[length] != fdata2[length]) - cpl_table_select_row(table, length); + break; + } + + break; } - break; + case CPL_TYPE_LONG: { + long *ldata2 = cpl_column_get_data_long(column2); - case CPL_GREATER_THAN: + switch (operator) { + case CPL_EQUAL_TO: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((float)lldata1[length] > fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((float)lldata1[length] > fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((float)lldata1[length] > fdata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((float)lldata1[length] > fdata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (lldata1[length] == + (long long)ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (lldata1[length] == + (long long)ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (lldata1[length] == + (long long)ldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (lldata1[length] == + (long long)ldata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_NOT_GREATER_THAN: + case CPL_NOT_EQUAL_TO: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((float)lldata1[length] <= fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((float)lldata1[length] <= fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((float)lldata1[length] <= fdata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((float)lldata1[length] <= fdata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (lldata1[length] != + (long long)ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (lldata1[length] != + (long long)ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (lldata1[length] != + (long long)ldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (lldata1[length] != + (long long)ldata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_LESS_THAN: + case CPL_GREATER_THAN: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((float)lldata1[length] < fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((float)lldata1[length] < fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((float)lldata1[length] < fdata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((float)lldata1[length] < fdata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (lldata1[length] > + (long long)ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (lldata1[length] > + (long long)ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (lldata1[length] > + (long long)ldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (lldata1[length] > + (long long)ldata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_NOT_LESS_THAN: + case CPL_NOT_GREATER_THAN: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((float)lldata1[length] >= fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((float)lldata1[length] >= fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((float)lldata1[length] >= fdata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((float)lldata1[length] >= fdata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (lldata1[length] <= + (long long)ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (lldata1[length] <= + (long long)ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (lldata1[length] <= + (long long)ldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (lldata1[length] <= + (long long)ldata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - } + case CPL_LESS_THAN: - break; - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (lldata1[length] < + (long long)ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (lldata1[length] < + (long long)ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (lldata1[length] < + (long long)ldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (lldata1[length] < + (long long)ldata2[length]) + cpl_table_select_row(table, length); + } - case CPL_TYPE_DOUBLE: - { - double *ddata2 = cpl_column_get_data_double(column2); + break; - switch (operator) { + case CPL_NOT_LESS_THAN: - case CPL_EQUAL_TO: + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (lldata1[length] >= + (long long)ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (lldata1[length] >= + (long long)ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (lldata1[length] >= + (long long)ldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (lldata1[length] >= + (long long)ldata2[length]) + cpl_table_select_row(table, length); + } - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((double)lldata1[length] == ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((double)lldata1[length] == ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((double)lldata1[length] == ddata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((double)lldata1[length] == ddata2[length]) - cpl_table_select_row(table, length); + break; + } + + break; } - break; + case CPL_TYPE_LONG_LONG: { + long long *lldata2 = cpl_column_get_data_long_long(column2); - case CPL_NOT_EQUAL_TO: + switch (operator) { + case CPL_EQUAL_TO: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((double)lldata1[length] != ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((double)lldata1[length] != ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((double)lldata1[length] != ddata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((double)lldata1[length] != ddata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (lldata1[length] == lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (lldata1[length] == lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (lldata1[length] == lldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (lldata1[length] == lldata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_GREATER_THAN: + case CPL_NOT_EQUAL_TO: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((double)lldata1[length] > ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((double)lldata1[length] > ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((double)lldata1[length] > ddata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((double)lldata1[length] > ddata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (lldata1[length] != lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (lldata1[length] != lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (lldata1[length] != lldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (lldata1[length] != lldata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_NOT_GREATER_THAN: + case CPL_GREATER_THAN: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((double)lldata1[length] <= ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((double)lldata1[length] <= ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((double)lldata1[length] <= ddata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((double)lldata1[length] <= ddata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (lldata1[length] > lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (lldata1[length] > lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (lldata1[length] > lldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (lldata1[length] > lldata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_LESS_THAN: + case CPL_NOT_GREATER_THAN: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((double)lldata1[length] < ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((double)lldata1[length] < ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((double)lldata1[length] < ddata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((double)lldata1[length] < ddata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (lldata1[length] <= lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (lldata1[length] <= lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (lldata1[length] <= lldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (lldata1[length] <= lldata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_NOT_LESS_THAN: + case CPL_LESS_THAN: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((double)lldata1[length] >= ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((double)lldata1[length] >= ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((double)lldata1[length] >= ddata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((double)lldata1[length] >= ddata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (lldata1[length] < lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (lldata1[length] < lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (lldata1[length] < lldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (lldata1[length] < lldata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - } + case CPL_NOT_LESS_THAN: - break; - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (lldata1[length] >= lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (lldata1[length] >= lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (lldata1[length] >= lldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (lldata1[length] >= lldata2[length]) + cpl_table_select_row(table, length); + } - default: + break; + } - break; + break; + } - } // end switch (type2) + case CPL_TYPE_FLOAT: { + float *fdata2 = cpl_column_get_data_float(column2); - break; + switch (operator) { + case CPL_EQUAL_TO: - } // end case CPL_TYPE_LONG_LONG + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((float)lldata1[length] == + fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((float)lldata1[length] == + fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((float)lldata1[length] == + fdata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((float)lldata1[length] == + fdata2[length]) + cpl_table_select_row(table, length); + } - case CPL_TYPE_FLOAT: - { - float *fdata1 = cpl_column_get_data_float(column1); + break; - switch (type2) { + case CPL_NOT_EQUAL_TO: - case CPL_TYPE_INT: - { - int *idata2 = cpl_column_get_data_int(column2); + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((float)lldata1[length] != + fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((float)lldata1[length] != + fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((float)lldata1[length] != + fdata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((float)lldata1[length] != + fdata2[length]) + cpl_table_select_row(table, length); + } - switch (operator) { + break; - case CPL_EQUAL_TO: + case CPL_GREATER_THAN: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (fdata1[length] == (float)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (fdata1[length] == (float)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (fdata1[length] == (float)idata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (fdata1[length] == (float)idata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((float)lldata1[length] > + fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((float)lldata1[length] > + fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((float)lldata1[length] > + fdata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((float)lldata1[length] > fdata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_NOT_EQUAL_TO: + case CPL_NOT_GREATER_THAN: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (fdata1[length] != (float)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (fdata1[length] != (float)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (fdata1[length] != (float)idata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (fdata1[length] != (float)idata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((float)lldata1[length] <= + fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((float)lldata1[length] <= + fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((float)lldata1[length] <= + fdata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((float)lldata1[length] <= + fdata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_GREATER_THAN: + case CPL_LESS_THAN: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (fdata1[length] > (float)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (fdata1[length] > (float)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (fdata1[length] > (float)idata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (fdata1[length] > (float)idata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((float)lldata1[length] < + fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((float)lldata1[length] < + fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((float)lldata1[length] < + fdata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((float)lldata1[length] < fdata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_NOT_GREATER_THAN: + case CPL_NOT_LESS_THAN: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (fdata1[length] <= (float)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (fdata1[length] <= (float)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (fdata1[length] <= (float)idata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (fdata1[length] <= (float)idata2[length]) - cpl_table_select_row(table, length); + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((float)lldata1[length] >= + fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((float)lldata1[length] >= + fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((float)lldata1[length] >= + fdata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((float)lldata1[length] >= + fdata2[length]) + cpl_table_select_row(table, length); + } + + break; + } + + break; } - break; + case CPL_TYPE_DOUBLE: { + double *ddata2 = cpl_column_get_data_double(column2); - case CPL_LESS_THAN: + switch (operator) { + case CPL_EQUAL_TO: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (fdata1[length] < (float)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (fdata1[length] < (float)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (fdata1[length] < (float)idata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (fdata1[length] < (float)idata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((double)lldata1[length] == + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((double)lldata1[length] == + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((double)lldata1[length] == + ddata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((double)lldata1[length] == + ddata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_NOT_LESS_THAN: + case CPL_NOT_EQUAL_TO: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (fdata1[length] >= (float)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (fdata1[length] >= (float)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (fdata1[length] >= (float)idata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (fdata1[length] >= (float)idata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((double)lldata1[length] != + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((double)lldata1[length] != + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((double)lldata1[length] != + ddata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((double)lldata1[length] != + ddata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - } + case CPL_GREATER_THAN: - break; + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((double)lldata1[length] > + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((double)lldata1[length] > + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((double)lldata1[length] > + ddata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((double)lldata1[length] > + ddata2[length]) + cpl_table_select_row(table, length); + } - } + break; - case CPL_TYPE_LONG: - { - long *ldata2 = cpl_column_get_data_long(column2); + case CPL_NOT_GREATER_THAN: - switch (operator) { + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((double)lldata1[length] <= + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((double)lldata1[length] <= + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((double)lldata1[length] <= + ddata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((double)lldata1[length] <= + ddata2[length]) + cpl_table_select_row(table, length); + } - case CPL_EQUAL_TO: + break; - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (fdata1[length] == (float)ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (fdata1[length] == (float)ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (fdata1[length] == (float)ldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (fdata1[length] == (float)ldata2[length]) - cpl_table_select_row(table, length); - } + case CPL_LESS_THAN: - break; + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((double)lldata1[length] < + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((double)lldata1[length] < + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((double)lldata1[length] < + ddata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((double)lldata1[length] < + ddata2[length]) + cpl_table_select_row(table, length); + } - case CPL_NOT_EQUAL_TO: + break; - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (fdata1[length] != (float)ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (fdata1[length] != (float)ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (fdata1[length] != (float)ldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (fdata1[length] != (float)ldata2[length]) - cpl_table_select_row(table, length); - } + case CPL_NOT_LESS_THAN: - break; + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((double)lldata1[length] >= + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((double)lldata1[length] >= + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((double)lldata1[length] >= + ddata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((double)lldata1[length] >= + ddata2[length]) + cpl_table_select_row(table, length); + } - case CPL_GREATER_THAN: + break; + } - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (fdata1[length] > (float)ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (fdata1[length] > (float)ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (fdata1[length] > (float)ldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (fdata1[length] > (float)ldata2[length]) - cpl_table_select_row(table, length); + break; } - break; + default: + + break; - case CPL_NOT_GREATER_THAN: + } // end switch (type2) - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (fdata1[length] <= (float)ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (fdata1[length] <= (float)ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (fdata1[length] <= (float)ldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (fdata1[length] <= (float)ldata2[length]) - cpl_table_select_row(table, length); - } + break; - break; + } // end case CPL_TYPE_LONG_LONG - case CPL_LESS_THAN: + case CPL_TYPE_FLOAT: { + float *fdata1 = cpl_column_get_data_float(column1); - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (fdata1[length] < (float)ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (fdata1[length] < (float)ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (fdata1[length] < (float)ldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (fdata1[length] < (float)ldata2[length]) - cpl_table_select_row(table, length); - } + switch (type2) { + case CPL_TYPE_INT: { + int *idata2 = cpl_column_get_data_int(column2); + + switch (operator) { + case CPL_EQUAL_TO: + + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (fdata1[length] == + (float)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (fdata1[length] == + (float)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (fdata1[length] == + (float)idata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (fdata1[length] == (float)idata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_NOT_LESS_THAN: + case CPL_NOT_EQUAL_TO: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (fdata1[length] >= (float)ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (fdata1[length] >= (float)ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (fdata1[length] >= (float)ldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (fdata1[length] >= (float)ldata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (fdata1[length] != + (float)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (fdata1[length] != + (float)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (fdata1[length] != + (float)idata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (fdata1[length] != (float)idata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - } + case CPL_GREATER_THAN: - break; - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (fdata1[length] > + (float)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (fdata1[length] > + (float)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (fdata1[length] > + (float)idata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (fdata1[length] > (float)idata2[length]) + cpl_table_select_row(table, length); + } - case CPL_TYPE_LONG_LONG: - { - long long *lldata2 = cpl_column_get_data_long_long(column2); + break; - switch (operator) { + case CPL_NOT_GREATER_THAN: - case CPL_EQUAL_TO: + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (fdata1[length] <= + (float)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (fdata1[length] <= + (float)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (fdata1[length] <= + (float)idata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (fdata1[length] <= (float)idata2[length]) + cpl_table_select_row(table, length); + } - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (fdata1[length] == (float)lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (fdata1[length] == (float)lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (fdata1[length] == (float)lldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (fdata1[length] == (float)lldata2[length]) - cpl_table_select_row(table, length); - } + break; - break; + case CPL_LESS_THAN: - case CPL_NOT_EQUAL_TO: + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (fdata1[length] < + (float)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (fdata1[length] < + (float)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (fdata1[length] < + (float)idata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (fdata1[length] < (float)idata2[length]) + cpl_table_select_row(table, length); + } - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (fdata1[length] != (float)lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (fdata1[length] != (float)lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (fdata1[length] != (float)lldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (fdata1[length] != (float)lldata2[length]) - cpl_table_select_row(table, length); - } + break; - break; + case CPL_NOT_LESS_THAN: - case CPL_GREATER_THAN: + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (fdata1[length] >= + (float)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (fdata1[length] >= + (float)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (fdata1[length] >= + (float)idata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (fdata1[length] >= (float)idata2[length]) + cpl_table_select_row(table, length); + } - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (fdata1[length] > (float)lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (fdata1[length] > (float)lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (fdata1[length] > (float)lldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (fdata1[length] > (float)lldata2[length]) - cpl_table_select_row(table, length); + break; + } + + break; } - break; + case CPL_TYPE_LONG: { + long *ldata2 = cpl_column_get_data_long(column2); - case CPL_NOT_GREATER_THAN: + switch (operator) { + case CPL_EQUAL_TO: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (fdata1[length] <= (float)lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (fdata1[length] <= (float)lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (fdata1[length] <= (float)lldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (fdata1[length] <= (float)lldata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (fdata1[length] == + (float)ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (fdata1[length] == + (float)ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (fdata1[length] == + (float)ldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (fdata1[length] == (float)ldata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_LESS_THAN: + case CPL_NOT_EQUAL_TO: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (fdata1[length] < (float)lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (fdata1[length] < (float)lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (fdata1[length] < (float)lldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (fdata1[length] < (float)lldata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (fdata1[length] != + (float)ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (fdata1[length] != + (float)ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (fdata1[length] != + (float)ldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (fdata1[length] != (float)ldata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_NOT_LESS_THAN: + case CPL_GREATER_THAN: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (fdata1[length] >= (float)lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (fdata1[length] >= (float)lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (fdata1[length] >= (float)lldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (fdata1[length] >= (float)lldata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (fdata1[length] > + (float)ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (fdata1[length] > + (float)ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (fdata1[length] > + (float)ldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (fdata1[length] > (float)ldata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - } + case CPL_NOT_GREATER_THAN: - break; - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (fdata1[length] <= + (float)ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (fdata1[length] <= + (float)ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (fdata1[length] <= + (float)ldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (fdata1[length] <= (float)ldata2[length]) + cpl_table_select_row(table, length); + } - case CPL_TYPE_FLOAT: - { - float *fdata2 = cpl_column_get_data_float(column2); + break; - switch (operator) { + case CPL_LESS_THAN: - case CPL_EQUAL_TO: + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (fdata1[length] < + (float)ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (fdata1[length] < + (float)ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (fdata1[length] < + (float)ldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (fdata1[length] < (float)ldata2[length]) + cpl_table_select_row(table, length); + } - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (fdata1[length] == fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (fdata1[length] == fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (fdata1[length] == fdata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (fdata1[length] == fdata2[length]) - cpl_table_select_row(table, length); - } + break; - break; + case CPL_NOT_LESS_THAN: - case CPL_NOT_EQUAL_TO: + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (fdata1[length] >= + (float)ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (fdata1[length] >= + (float)ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (fdata1[length] >= + (float)ldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (fdata1[length] >= (float)ldata2[length]) + cpl_table_select_row(table, length); + } - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (fdata1[length] != fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (fdata1[length] != fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (fdata1[length] != fdata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (fdata1[length] != fdata2[length]) - cpl_table_select_row(table, length); + break; + } + + break; } - break; + case CPL_TYPE_LONG_LONG: { + long long *lldata2 = cpl_column_get_data_long_long(column2); - case CPL_GREATER_THAN: + switch (operator) { + case CPL_EQUAL_TO: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (fdata1[length] > fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (fdata1[length] > fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (fdata1[length] > fdata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (fdata1[length] > fdata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (fdata1[length] == + (float)lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (fdata1[length] == + (float)lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (fdata1[length] == + (float)lldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (fdata1[length] == + (float)lldata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_NOT_GREATER_THAN: + case CPL_NOT_EQUAL_TO: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (fdata1[length] <= fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (fdata1[length] <= fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (fdata1[length] <= fdata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (fdata1[length] <= fdata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (fdata1[length] != + (float)lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (fdata1[length] != + (float)lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (fdata1[length] != + (float)lldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (fdata1[length] != + (float)lldata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_LESS_THAN: + case CPL_GREATER_THAN: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (fdata1[length] < fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (fdata1[length] < fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (fdata1[length] < fdata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (fdata1[length] < fdata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (fdata1[length] > + (float)lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (fdata1[length] > + (float)lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (fdata1[length] > + (float)lldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (fdata1[length] > (float)lldata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_NOT_LESS_THAN: + case CPL_NOT_GREATER_THAN: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (fdata1[length] >= fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (fdata1[length] >= fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (fdata1[length] >= fdata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (fdata1[length] >= fdata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (fdata1[length] <= + (float)lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (fdata1[length] <= + (float)lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (fdata1[length] <= + (float)lldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (fdata1[length] <= + (float)lldata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - } + case CPL_LESS_THAN: - break; + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (fdata1[length] < + (float)lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (fdata1[length] < + (float)lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (fdata1[length] < + (float)lldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (fdata1[length] < (float)lldata2[length]) + cpl_table_select_row(table, length); + } - } + break; - case CPL_TYPE_DOUBLE: - { - double *ddata2 = cpl_column_get_data_double(column2); + case CPL_NOT_LESS_THAN: - switch (operator) { + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (fdata1[length] >= + (float)lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (fdata1[length] >= + (float)lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (fdata1[length] >= + (float)lldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (fdata1[length] >= + (float)lldata2[length]) + cpl_table_select_row(table, length); + } - case CPL_EQUAL_TO: + break; + } - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((double)fdata1[length] == ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((double)fdata1[length] == ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((double)fdata1[length] == ddata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((double)fdata1[length] == ddata2[length]) - cpl_table_select_row(table, length); + break; } - break; + case CPL_TYPE_FLOAT: { + float *fdata2 = cpl_column_get_data_float(column2); - case CPL_NOT_EQUAL_TO: + switch (operator) { + case CPL_EQUAL_TO: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((double)fdata1[length] != ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((double)fdata1[length] != ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((double)fdata1[length] != ddata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((double)fdata1[length] != ddata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (fdata1[length] == fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (fdata1[length] == fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (fdata1[length] == fdata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (fdata1[length] == fdata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_GREATER_THAN: + case CPL_NOT_EQUAL_TO: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((double)fdata1[length] > ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((double)fdata1[length] > ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((double)fdata1[length] > ddata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((double)fdata1[length] > ddata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (fdata1[length] != fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (fdata1[length] != fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (fdata1[length] != fdata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (fdata1[length] != fdata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_NOT_GREATER_THAN: + case CPL_GREATER_THAN: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((double)fdata1[length] <= ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((double)fdata1[length] <= ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((double)fdata1[length] <= ddata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((double)fdata1[length] <= ddata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (fdata1[length] > fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (fdata1[length] > fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (fdata1[length] > fdata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (fdata1[length] > fdata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_LESS_THAN: + case CPL_NOT_GREATER_THAN: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((double)fdata1[length] < ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((double)fdata1[length] < ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((double)fdata1[length] < ddata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((double)fdata1[length] < ddata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (fdata1[length] <= fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (fdata1[length] <= fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (fdata1[length] <= fdata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (fdata1[length] <= fdata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_NOT_LESS_THAN: + case CPL_LESS_THAN: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if ((double)fdata1[length] >= ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if ((double)fdata1[length] >= ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if ((double)fdata1[length] >= ddata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if ((double)fdata1[length] >= ddata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (fdata1[length] < fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (fdata1[length] < fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (fdata1[length] < fdata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (fdata1[length] < fdata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - } + case CPL_NOT_LESS_THAN: - break; + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (fdata1[length] >= fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (fdata1[length] >= fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (fdata1[length] >= fdata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (fdata1[length] >= fdata2[length]) + cpl_table_select_row(table, length); + } - } + break; + } - default: + break; + } - break; + case CPL_TYPE_DOUBLE: { + double *ddata2 = cpl_column_get_data_double(column2); - } // end switch (type2) + switch (operator) { + case CPL_EQUAL_TO: - break; + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((double)fdata1[length] == + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((double)fdata1[length] == + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((double)fdata1[length] == + ddata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((double)fdata1[length] == + ddata2[length]) + cpl_table_select_row(table, length); + } - } // end case CPL_TYPE_FLOAT + break; - case CPL_TYPE_DOUBLE: - { - double *ddata1 = cpl_column_get_data_double(column1); + case CPL_NOT_EQUAL_TO: - switch (type2) { + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((double)fdata1[length] != + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((double)fdata1[length] != + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((double)fdata1[length] != + ddata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((double)fdata1[length] != + ddata2[length]) + cpl_table_select_row(table, length); + } - case CPL_TYPE_INT: - { - int *idata2 = cpl_column_get_data_int(column2); + break; - switch (operator) { + case CPL_GREATER_THAN: - case CPL_EQUAL_TO: + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((double)fdata1[length] > + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((double)fdata1[length] > + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((double)fdata1[length] > + ddata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((double)fdata1[length] > ddata2[length]) + cpl_table_select_row(table, length); + } - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (ddata1[length] == (double)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (ddata1[length] == (double)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (ddata1[length] == (double)idata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (ddata1[length] == (double)idata2[length]) - cpl_table_select_row(table, length); - } + break; - break; + case CPL_NOT_GREATER_THAN: - case CPL_NOT_EQUAL_TO: + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((double)fdata1[length] <= + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((double)fdata1[length] <= + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((double)fdata1[length] <= + ddata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((double)fdata1[length] <= + ddata2[length]) + cpl_table_select_row(table, length); + } - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (ddata1[length] != (double)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (ddata1[length] != (double)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (ddata1[length] != (double)idata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (ddata1[length] != (double)idata2[length]) - cpl_table_select_row(table, length); - } + break; - break; + case CPL_LESS_THAN: - case CPL_GREATER_THAN: + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((double)fdata1[length] < + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((double)fdata1[length] < + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((double)fdata1[length] < + ddata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((double)fdata1[length] < ddata2[length]) + cpl_table_select_row(table, length); + } - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (ddata1[length] > (double)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (ddata1[length] > (double)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (ddata1[length] > (double)idata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (ddata1[length] > (double)idata2[length]) - cpl_table_select_row(table, length); - } + break; - break; + case CPL_NOT_LESS_THAN: - case CPL_NOT_GREATER_THAN: + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if ((double)fdata1[length] >= + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if ((double)fdata1[length] >= + ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if ((double)fdata1[length] >= + ddata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if ((double)fdata1[length] >= + ddata2[length]) + cpl_table_select_row(table, length); + } - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (ddata1[length] <= (double)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (ddata1[length] <= (double)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (ddata1[length] <= (double)idata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (ddata1[length] <= (double)idata2[length]) - cpl_table_select_row(table, length); + break; + } + + break; } - break; + default: + + break; - case CPL_LESS_THAN: + } // end switch (type2) - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (ddata1[length] < (double)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (ddata1[length] < (double)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (ddata1[length] < (double)idata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (ddata1[length] < (double)idata2[length]) - cpl_table_select_row(table, length); - } + break; - break; + } // end case CPL_TYPE_FLOAT - case CPL_NOT_LESS_THAN: + case CPL_TYPE_DOUBLE: { + double *ddata1 = cpl_column_get_data_double(column1); - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (ddata1[length] >= (double)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (ddata1[length] >= (double)idata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (ddata1[length] >= (double)idata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (ddata1[length] >= (double)idata2[length]) - cpl_table_select_row(table, length); - } + switch (type2) { + case CPL_TYPE_INT: { + int *idata2 = cpl_column_get_data_int(column2); + + switch (operator) { + case CPL_EQUAL_TO: + + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (ddata1[length] == + (double)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (ddata1[length] == + (double)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (ddata1[length] == + (double)idata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (ddata1[length] == + (double)idata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - } + case CPL_NOT_EQUAL_TO: - break; - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (ddata1[length] != + (double)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (ddata1[length] != + (double)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (ddata1[length] != + (double)idata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (ddata1[length] != + (double)idata2[length]) + cpl_table_select_row(table, length); + } - case CPL_TYPE_LONG: - { - long *ldata2 = cpl_column_get_data_long(column2); + break; - switch (operator) { + case CPL_GREATER_THAN: + + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (ddata1[length] > + (double)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (ddata1[length] > + (double)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (ddata1[length] > + (double)idata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (ddata1[length] > (double)idata2[length]) + cpl_table_select_row(table, length); + } - case CPL_EQUAL_TO: + break; - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (ddata1[length] == (double)ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (ddata1[length] == (double)ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (ddata1[length] == (double)ldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (ddata1[length] == (double)ldata2[length]) - cpl_table_select_row(table, length); - } + case CPL_NOT_GREATER_THAN: - break; + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (ddata1[length] <= + (double)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (ddata1[length] <= + (double)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (ddata1[length] <= + (double)idata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (ddata1[length] <= + (double)idata2[length]) + cpl_table_select_row(table, length); + } - case CPL_NOT_EQUAL_TO: + break; - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (ddata1[length] != (double)ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (ddata1[length] != (double)ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (ddata1[length] != (double)ldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (ddata1[length] != (double)ldata2[length]) - cpl_table_select_row(table, length); - } + case CPL_LESS_THAN: - break; + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (ddata1[length] < + (double)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (ddata1[length] < + (double)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (ddata1[length] < + (double)idata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (ddata1[length] < (double)idata2[length]) + cpl_table_select_row(table, length); + } - case CPL_GREATER_THAN: + break; - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (ddata1[length] > (double)ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (ddata1[length] > (double)ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (ddata1[length] > (double)ldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (ddata1[length] > (double)ldata2[length]) - cpl_table_select_row(table, length); - } + case CPL_NOT_LESS_THAN: - break; + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (ddata1[length] >= + (double)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (ddata1[length] >= + (double)idata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (ddata1[length] >= + (double)idata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (ddata1[length] >= + (double)idata2[length]) + cpl_table_select_row(table, length); + } - case CPL_NOT_GREATER_THAN: + break; + } - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (ddata1[length] <= (double)ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (ddata1[length] <= (double)ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (ddata1[length] <= (double)ldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (ddata1[length] <= (double)ldata2[length]) - cpl_table_select_row(table, length); + break; } - break; + case CPL_TYPE_LONG: { + long *ldata2 = cpl_column_get_data_long(column2); - case CPL_LESS_THAN: + switch (operator) { + case CPL_EQUAL_TO: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (ddata1[length] < (double)ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (ddata1[length] < (double)ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (ddata1[length] < (double)ldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (ddata1[length] < (double)ldata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (ddata1[length] == + (double)ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (ddata1[length] == + (double)ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (ddata1[length] == + (double)ldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (ddata1[length] == + (double)ldata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_NOT_LESS_THAN: + case CPL_NOT_EQUAL_TO: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (ddata1[length] >= (double)ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (ddata1[length] >= (double)ldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (ddata1[length] >= (double)ldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (ddata1[length] >= (double)ldata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (ddata1[length] != + (double)ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (ddata1[length] != + (double)ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (ddata1[length] != + (double)ldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (ddata1[length] != + (double)ldata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - } + case CPL_GREATER_THAN: - break; - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (ddata1[length] > + (double)ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (ddata1[length] > + (double)ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (ddata1[length] > + (double)ldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (ddata1[length] > (double)ldata2[length]) + cpl_table_select_row(table, length); + } - case CPL_TYPE_LONG_LONG: - { - long long *lldata2 = cpl_column_get_data_long_long(column2); + break; - switch (operator) { + case CPL_NOT_GREATER_THAN: - case CPL_EQUAL_TO: + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (ddata1[length] <= + (double)ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (ddata1[length] <= + (double)ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (ddata1[length] <= + (double)ldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (ddata1[length] <= + (double)ldata2[length]) + cpl_table_select_row(table, length); + } - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (ddata1[length] == (double)lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (ddata1[length] == (double)lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (ddata1[length] == (double)lldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (ddata1[length] == (double)lldata2[length]) - cpl_table_select_row(table, length); - } + break; - break; + case CPL_LESS_THAN: - case CPL_NOT_EQUAL_TO: + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (ddata1[length] < + (double)ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (ddata1[length] < + (double)ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (ddata1[length] < + (double)ldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (ddata1[length] < (double)ldata2[length]) + cpl_table_select_row(table, length); + } - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (ddata1[length] != (double)lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (ddata1[length] != (double)lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (ddata1[length] != (double)lldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (ddata1[length] != (double)lldata2[length]) - cpl_table_select_row(table, length); - } + break; - break; + case CPL_NOT_LESS_THAN: - case CPL_GREATER_THAN: + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (ddata1[length] >= + (double)ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (ddata1[length] >= + (double)ldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (ddata1[length] >= + (double)ldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (ddata1[length] >= + (double)ldata2[length]) + cpl_table_select_row(table, length); + } - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (ddata1[length] > (double)lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (ddata1[length] > (double)lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (ddata1[length] > (double)lldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (ddata1[length] > (double)lldata2[length]) - cpl_table_select_row(table, length); + break; + } + + break; } - break; + case CPL_TYPE_LONG_LONG: { + long long *lldata2 = cpl_column_get_data_long_long(column2); - case CPL_NOT_GREATER_THAN: + switch (operator) { + case CPL_EQUAL_TO: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (ddata1[length] <= (double)lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (ddata1[length] <= (double)lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (ddata1[length] <= (double)lldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (ddata1[length] <= (double)lldata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (ddata1[length] == + (double)lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (ddata1[length] == + (double)lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (ddata1[length] == + (double)lldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (ddata1[length] == + (double)lldata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_LESS_THAN: + case CPL_NOT_EQUAL_TO: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (ddata1[length] < (double)lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (ddata1[length] < (double)lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (ddata1[length] < (double)lldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (ddata1[length] < (double)lldata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (ddata1[length] != + (double)lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (ddata1[length] != + (double)lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (ddata1[length] != + (double)lldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (ddata1[length] != + (double)lldata2[length]) + cpl_table_select_row(table, length); + } + + break; - break; + case CPL_GREATER_THAN: - case CPL_NOT_LESS_THAN: + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (ddata1[length] > + (double)lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (ddata1[length] > + (double)lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (ddata1[length] > + (double)lldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (ddata1[length] > + (double)lldata2[length]) + cpl_table_select_row(table, length); + } - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (ddata1[length] >= (double)lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (ddata1[length] >= (double)lldata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (ddata1[length] >= (double)lldata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (ddata1[length] >= (double)lldata2[length]) - cpl_table_select_row(table, length); - } + break; - break; + case CPL_NOT_GREATER_THAN: - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (ddata1[length] <= + (double)lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (ddata1[length] <= + (double)lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (ddata1[length] <= + (double)lldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (ddata1[length] <= + (double)lldata2[length]) + cpl_table_select_row(table, length); + } - break; - } + break; - case CPL_TYPE_FLOAT: - { - float *fdata2 = cpl_column_get_data_float(column2); + case CPL_LESS_THAN: - switch (operator) { + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (ddata1[length] < + (double)lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (ddata1[length] < + (double)lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (ddata1[length] < + (double)lldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (ddata1[length] < + (double)lldata2[length]) + cpl_table_select_row(table, length); + } - case CPL_EQUAL_TO: + break; - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (ddata1[length] == (double)fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (ddata1[length] == (double)fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (ddata1[length] == (double)fdata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (ddata1[length] == (double)fdata2[length]) - cpl_table_select_row(table, length); - } + case CPL_NOT_LESS_THAN: - break; + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (ddata1[length] >= + (double)lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (ddata1[length] >= + (double)lldata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (ddata1[length] >= + (double)lldata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (ddata1[length] >= + (double)lldata2[length]) + cpl_table_select_row(table, length); + } - case CPL_NOT_EQUAL_TO: + break; + } - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (ddata1[length] != (double)fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (ddata1[length] != (double)fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (ddata1[length] != (double)fdata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (ddata1[length] != (double)fdata2[length]) - cpl_table_select_row(table, length); + break; } - break; + case CPL_TYPE_FLOAT: { + float *fdata2 = cpl_column_get_data_float(column2); - case CPL_GREATER_THAN: + switch (operator) { + case CPL_EQUAL_TO: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (ddata1[length] > (double)fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (ddata1[length] > (double)fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (ddata1[length] > (double)fdata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (ddata1[length] > (double)fdata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (ddata1[length] == + (double)fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (ddata1[length] == + (double)fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (ddata1[length] == + (double)fdata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (ddata1[length] == + (double)fdata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_NOT_GREATER_THAN: + case CPL_NOT_EQUAL_TO: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (ddata1[length] <= (double)fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (ddata1[length] <= (double)fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (ddata1[length] <= (double)fdata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (ddata1[length] <= (double)fdata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (ddata1[length] != + (double)fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (ddata1[length] != + (double)fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (ddata1[length] != + (double)fdata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (ddata1[length] != + (double)fdata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_LESS_THAN: + case CPL_GREATER_THAN: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (ddata1[length] < (double)fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (ddata1[length] < (double)fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (ddata1[length] < (double)fdata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (ddata1[length] < (double)fdata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (ddata1[length] > + (double)fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (ddata1[length] > + (double)fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (ddata1[length] > + (double)fdata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (ddata1[length] > (double)fdata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_NOT_LESS_THAN: + case CPL_NOT_GREATER_THAN: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (ddata1[length] >= (double)fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (ddata1[length] >= (double)fdata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (ddata1[length] >= (double)fdata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (ddata1[length] >= (double)fdata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (ddata1[length] <= + (double)fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (ddata1[length] <= + (double)fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (ddata1[length] <= + (double)fdata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (ddata1[length] <= + (double)fdata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - } + case CPL_LESS_THAN: - break; - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (ddata1[length] < + (double)fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (ddata1[length] < + (double)fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (ddata1[length] < + (double)fdata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (ddata1[length] < (double)fdata2[length]) + cpl_table_select_row(table, length); + } - case CPL_TYPE_DOUBLE: - { - double *ddata2 = cpl_column_get_data_double(column2); + break; - switch (operator) { + case CPL_NOT_LESS_THAN: - case CPL_EQUAL_TO: + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (ddata1[length] >= + (double)fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (ddata1[length] >= + (double)fdata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (ddata1[length] >= + (double)fdata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (ddata1[length] >= + (double)fdata2[length]) + cpl_table_select_row(table, length); + } - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (ddata1[length] == ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (ddata1[length] == ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (ddata1[length] == ddata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (ddata1[length] == ddata2[length]) - cpl_table_select_row(table, length); + break; + } + + break; } - break; + case CPL_TYPE_DOUBLE: { + double *ddata2 = cpl_column_get_data_double(column2); - case CPL_NOT_EQUAL_TO: + switch (operator) { + case CPL_EQUAL_TO: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (ddata1[length] != ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (ddata1[length] != ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (ddata1[length] != ddata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (ddata1[length] != ddata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (ddata1[length] == ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (ddata1[length] == ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (ddata1[length] == ddata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (ddata1[length] == ddata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_GREATER_THAN: + case CPL_NOT_EQUAL_TO: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (ddata1[length] > ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (ddata1[length] > ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (ddata1[length] > ddata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (ddata1[length] > ddata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (ddata1[length] != ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (ddata1[length] != ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (ddata1[length] != ddata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (ddata1[length] != ddata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_NOT_GREATER_THAN: + case CPL_GREATER_THAN: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (ddata1[length] <= ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (ddata1[length] <= ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (ddata1[length] <= ddata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (ddata1[length] <= ddata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (ddata1[length] > ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (ddata1[length] > ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (ddata1[length] > ddata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (ddata1[length] > ddata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_LESS_THAN: + case CPL_NOT_GREATER_THAN: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (ddata1[length] < ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (ddata1[length] < ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (ddata1[length] < ddata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (ddata1[length] < ddata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (ddata1[length] <= ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (ddata1[length] <= ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (ddata1[length] <= ddata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (ddata1[length] <= ddata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - case CPL_NOT_LESS_THAN: + case CPL_LESS_THAN: - if (nulldata1 && nulldata2) { - while (length--) - if (nulldata1[length] == 0 && nulldata2[length] == 0) - if (ddata1[length] >= ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata1) { - while (length--) - if (nulldata1[length] == 0) - if (ddata1[length] >= ddata2[length]) - cpl_table_select_row(table, length); - } - else if (nulldata2) { - while (length--) - if (nulldata2[length] == 0) - if (ddata1[length] >= ddata2[length]) - cpl_table_select_row(table, length); - } - else { - while (length--) - if (ddata1[length] >= ddata2[length]) - cpl_table_select_row(table, length); - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (ddata1[length] < ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (ddata1[length] < ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (ddata1[length] < ddata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (ddata1[length] < ddata2[length]) + cpl_table_select_row(table, length); + } - break; + break; - } + case CPL_NOT_LESS_THAN: - break; - } + if (nulldata1 && nulldata2) { + while (length--) + if (nulldata1[length] == 0 && + nulldata2[length] == 0) + if (ddata1[length] >= ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata1) { + while (length--) + if (nulldata1[length] == 0) + if (ddata1[length] >= ddata2[length]) + cpl_table_select_row(table, length); + } + else if (nulldata2) { + while (length--) + if (nulldata2[length] == 0) + if (ddata1[length] >= ddata2[length]) + cpl_table_select_row(table, length); + } + else { + while (length--) + if (ddata1[length] >= ddata2[length]) + cpl_table_select_row(table, length); + } - default: + break; + } - break; + break; + } - } // end switch (type2) + default: - break; + break; - } // end case CPL_TYPE_DOUBLE + } // end switch (type2) - case CPL_TYPE_STRING: - { - sdata1 = cpl_column_get_data_string(column1); - sdata2 = cpl_column_get_data_string(column2); + break; - switch (operator) { + } // end case CPL_TYPE_DOUBLE - case CPL_EQUAL_TO: + case CPL_TYPE_STRING: { + sdata1 = cpl_column_get_data_string(column1); + sdata2 = cpl_column_get_data_string(column2); - while (length--) - if (sdata1[length] && sdata2[length]) - if (!strcmp(sdata1[length], sdata2[length])) - cpl_table_select_row(table, length); - break; + switch (operator) { + case CPL_EQUAL_TO: - case CPL_NOT_EQUAL_TO: + while (length--) + if (sdata1[length] && sdata2[length]) + if (!strcmp(sdata1[length], sdata2[length])) + cpl_table_select_row(table, length); + break; - while (length--) - if (sdata1[length] && sdata2[length]) - if (strcmp(sdata1[length], sdata2[length])) - cpl_table_select_row(table, length); - break; + case CPL_NOT_EQUAL_TO: - case CPL_GREATER_THAN: + while (length--) + if (sdata1[length] && sdata2[length]) + if (strcmp(sdata1[length], sdata2[length])) + cpl_table_select_row(table, length); + break; - while (length--) - if (sdata1[length] && sdata2[length]) - if (strcmp(sdata1[length], sdata2[length]) > 0) - cpl_table_select_row(table, length); - break; + case CPL_GREATER_THAN: - case CPL_NOT_GREATER_THAN: + while (length--) + if (sdata1[length] && sdata2[length]) + if (strcmp(sdata1[length], sdata2[length]) > 0) + cpl_table_select_row(table, length); + break; - while (length--) - if (sdata1[length] && sdata2[length]) - if (strcmp(sdata1[length], sdata2[length]) <= 0) - cpl_table_select_row(table, length); - break; + case CPL_NOT_GREATER_THAN: - case CPL_LESS_THAN: + while (length--) + if (sdata1[length] && sdata2[length]) + if (strcmp(sdata1[length], sdata2[length]) <= 0) + cpl_table_select_row(table, length); + break; - while (length--) - if (sdata1[length] && sdata2[length]) - if (strcmp(sdata1[length], sdata2[length]) < 0) - cpl_table_select_row(table, length); - break; + case CPL_LESS_THAN: - case CPL_NOT_LESS_THAN: + while (length--) + if (sdata1[length] && sdata2[length]) + if (strcmp(sdata1[length], sdata2[length]) < 0) + cpl_table_select_row(table, length); + break; - while (length--) - if (sdata1[length] && sdata2[length]) - if (strcmp(sdata1[length], sdata2[length]) >= 0) - cpl_table_select_row(table, length); - break; - } + case CPL_NOT_LESS_THAN: + + while (length--) + if (sdata1[length] && sdata2[length]) + if (strcmp(sdata1[length], sdata2[length]) >= 0) + cpl_table_select_row(table, length); + break; + } - break; + break; - } // end case CPL_TYPE_STRING + } // end case CPL_TYPE_STRING - default: + default: - break; + break; - } // end switch (type1) + } // end switch (type1) return table->selectcount; - } @@ -21063,11 +21417,9 @@ * Check if a table row is selected. */ -int cpl_table_is_selected(const cpl_table *table, cpl_size row) +int +cpl_table_is_selected(const cpl_table *table, cpl_size row) { - - - if (table == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return -1; @@ -21085,7 +21437,6 @@ return 1; return table->select[row]; - } @@ -21111,18 +21462,15 @@ * Get number of selected rows in given table. */ -cpl_size cpl_table_count_selected(const cpl_table *table) +cpl_size +cpl_table_count_selected(const cpl_table *table) { - - - if (table == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return -1; } return table->selectcount; - } @@ -21150,12 +21498,12 @@ * using @c cpl_array_delete(). */ -cpl_array *cpl_table_where_selected(const cpl_table *table) +cpl_array * +cpl_table_where_selected(const cpl_table *table) { - cpl_array *array; - cpl_size *flags; - cpl_size i; + cpl_size *flags; + cpl_size i; if (table == NULL) { @@ -21177,7 +21525,6 @@ *flags++ = i; return array; - } @@ -21204,20 +21551,20 @@ * rows of the input table. In the output table all rows are selected. */ -cpl_table *cpl_table_extract_selected(const cpl_table *table) +cpl_table * +cpl_table_extract_selected(const cpl_table *table) { - - cpl_table *new_table; - int ivalue; - float fvalue; - double dvalue; - char *svalue; - cpl_array *avalue; - cpl_size from_row; - cpl_size to_row; - cpl_size count; - cpl_size i, j, l, m, n; - int isnull; + cpl_table *new_table; + int ivalue; + float fvalue; + double dvalue; + char *svalue; + cpl_array *avalue; + cpl_size from_row; + cpl_size to_row; + cpl_size count; + cpl_size i, j, l, m, n; + int isnull; if (table == NULL) { @@ -21239,7 +21586,6 @@ count = 0; i = 0; while (i < table->nr) { - if (table->select[i]) { if (count == 0) from_row = i; @@ -21251,11 +21597,9 @@ } if (count) { - j = 0; while (j < table->nc) { - cpl_type type_id = cpl_column_get_type(table->columns[j]); l = 0; @@ -21263,20 +21607,19 @@ n = to_row; if (_cpl_columntype_is_pointer(type_id)) { - switch (_cpl_columntype_get_valuetype(type_id)) { - case CPL_TYPE_INT: case CPL_TYPE_LONG_LONG: case CPL_TYPE_FLOAT: case CPL_TYPE_DOUBLE: case CPL_TYPE_FLOAT_COMPLEX: case CPL_TYPE_DOUBLE_COMPLEX: - case CPL_TYPE_STRING: - { + case CPL_TYPE_STRING: { while (l < count) { - avalue = cpl_column_get_array(table->columns[j], m); - cpl_column_set_array(new_table->columns[j], n, avalue); + avalue = + cpl_column_get_array(table->columns[j], m); + cpl_column_set_array(new_table->columns[j], n, + avalue); l++; m++; @@ -21288,10 +21631,8 @@ default: break; } - } else { - /* * This is slow, but acceptable for the moment. * It should be replaced by a call to a function @@ -21301,7 +21642,6 @@ */ switch (_cpl_columntype_get_valuetype(type_id)) { - case CPL_TYPE_INT: while (l < count) { @@ -21309,10 +21649,11 @@ m, &isnull); if (isnull) - cpl_column_set_invalid(new_table->columns[j], n); + cpl_column_set_invalid( + new_table->columns[j], n); else - cpl_column_set_int(new_table->columns[j], - n, ivalue); + cpl_column_set_int(new_table->columns[j], n, + ivalue); l++; m++; @@ -21324,14 +21665,15 @@ while (l < count) { long long value = - cpl_column_get_long_long(table->columns[j], - m, &isnull); + cpl_column_get_long_long(table->columns[j], + m, &isnull); if (isnull) - cpl_column_set_invalid(new_table->columns[j], n); + cpl_column_set_invalid( + new_table->columns[j], n); else - cpl_column_set_long_long(new_table->columns[j], - n, value); + cpl_column_set_long_long( + new_table->columns[j], n, value); l++; m++; @@ -21342,14 +21684,14 @@ case CPL_TYPE_FLOAT: while (l < count) { - fvalue = - cpl_column_get_float(table->columns[j], - m, &isnull); + fvalue = cpl_column_get_float(table->columns[j], + m, &isnull); if (isnull) - cpl_column_set_invalid(new_table->columns[j], n); + cpl_column_set_invalid( + new_table->columns[j], n); else - cpl_column_set_float( - new_table->columns[j], n, fvalue); + cpl_column_set_float(new_table->columns[j], + n, fvalue); l++; m++; @@ -21360,14 +21702,16 @@ case CPL_TYPE_DOUBLE: while (l < count) { - dvalue = cpl_column_get_double(table->columns[j], - m, &isnull); + dvalue = + cpl_column_get_double(table->columns[j], m, + &isnull); if (isnull) - cpl_column_set_invalid(new_table->columns[j], n); + cpl_column_set_invalid( + new_table->columns[j], n); else - cpl_column_set_double( - new_table->columns[j], n, dvalue); + cpl_column_set_double(new_table->columns[j], + n, dvalue); l++; m++; @@ -21379,13 +21723,14 @@ while (l < count) { float complex value = - cpl_column_get_float_complex(table->columns[j], - m, &isnull); + cpl_column_get_float_complex( + table->columns[j], m, &isnull); if (isnull) - cpl_column_set_invalid(new_table->columns[j], n); + cpl_column_set_invalid( + new_table->columns[j], n); else cpl_column_set_float_complex( - new_table->columns[j], n, value); + new_table->columns[j], n, value); l++; m++; @@ -21397,13 +21742,14 @@ while (l < count) { double complex value = - cpl_column_get_double_complex(table->columns[j], - m, &isnull); + cpl_column_get_double_complex( + table->columns[j], m, &isnull); if (isnull) - cpl_column_set_invalid(new_table->columns[j], n); + cpl_column_set_invalid( + new_table->columns[j], n); else cpl_column_set_double_complex( - new_table->columns[j], n, value); + new_table->columns[j], n, value); l++; m++; @@ -21414,9 +21760,10 @@ case CPL_TYPE_STRING: while (l < count) { - svalue = - (char *)cpl_column_get_string(table->columns[j], m); - cpl_column_set_string(new_table->columns[j], n, svalue); + svalue = (char *) + cpl_column_get_string(table->columns[j], m); + cpl_column_set_string(new_table->columns[j], n, + svalue); l++; m++; @@ -21427,7 +21774,6 @@ default: break; } - } j++; @@ -21441,11 +21787,9 @@ } i++; - } return new_table; - } @@ -21515,9 +21859,10 @@ * remain valid. */ -cpl_error_code cpl_table_sort(cpl_table *table, const cpl_propertylist *reflist) +cpl_error_code +cpl_table_sort(cpl_table *table, const cpl_propertylist *reflist) { - cpl_size *sort_pattern, *sort_null_pattern; + cpl_size *sort_pattern, *sort_null_pattern; cpl_error_code ec; if (table == NULL || reflist == NULL) @@ -21529,7 +21874,7 @@ if (table->nr < 2) return CPL_ERROR_NONE; - sort_pattern = cpl_malloc(table->nr * sizeof(cpl_size)); + sort_pattern = cpl_malloc(table->nr * sizeof(cpl_size)); sort_null_pattern = cpl_malloc(table->nr * sizeof(cpl_size)); ec = table_sort(table, reflist, cpl_propertylist_get_size(reflist), @@ -21542,47 +21887,48 @@ } -static cpl_table *cpl_table_overload_window(const char *filename, int xtnum, - int check_nulls, - const cpl_array *selcol, - cpl_size firstrow, cpl_size nrow) +static cpl_table * +cpl_table_overload_window(const char *filename, + int xtnum, + int check_nulls, + const cpl_array *selcol, + cpl_size firstrow, + cpl_size nrow) { + fitsfile *fptr; + + cpl_table *table; + char colname[FLEN_VALUE]; + char colunit[FLEN_VALUE]; + char comment[FLEN_COMMENT]; + char keyname[FLEN_KEYWORD]; - fitsfile *fptr; - - cpl_table *table; - - char colname[FLEN_VALUE]; - char colunit[FLEN_VALUE]; - char comment[FLEN_COMMENT]; - char keyname[FLEN_KEYWORD]; - - cpl_size nullcount; - - int extension_count; - cpl_size field_size; - int ncol; - cpl_size nrows; - int naxis; - cpl_size *naxes; - int i, k; - cpl_size j; - cpl_size depth; - cpl_size z, zz; - cpl_array *adim; - cpl_array **array; - cpl_column *acolumn; - cpl_column_flag *nulldata; - char err_text[FLEN_STATUS]; - const char **extcol = NULL; - char *barray; - int xcol = 0; - int extract; - int colnum; - int status = 0; - int hdutype; - int typecode; + cpl_size nullcount; + + int extension_count; + cpl_size field_size; + int ncol; + cpl_size nrows; + int naxis; + cpl_size *naxes; + int i, k; + cpl_size j; + cpl_size depth; + cpl_size z, zz; + cpl_array *adim; + cpl_array **array; + cpl_column *acolumn; + cpl_column_flag *nulldata; + char err_text[FLEN_STATUS]; + const char **extcol = NULL; + char *barray; + int xcol = 0; + int extract; + int colnum; + int status = 0; + int hdutype; + int typecode; err_text[0] = '\0'; @@ -21598,19 +21944,21 @@ } if (cpl_io_fits_open_diskfile(&fptr, filename, READONLY, &status)) { - - (void)cpl_error_set_fits(status == FILE_NOT_OPENED ? - CPL_ERROR_FILE_IO : CPL_ERROR_BAD_FILE_FORMAT, - status, fits_open_diskfile, "filename='%s', " - "position=%d", filename, xtnum); + (void)cpl_error_set_fits(status == FILE_NOT_OPENED + ? CPL_ERROR_FILE_IO + : CPL_ERROR_BAD_FILE_FORMAT, + status, fits_open_diskfile, + "filename='%s', " + "position=%d", + filename, xtnum); } fits_get_num_hdus(fptr, &extension_count, &status); if (status) { (void)cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, status, - fits_get_num_hdus, "filename='%s', position=%d", - filename, xtnum); + fits_get_num_hdus, + "filename='%s', position=%d", filename, xtnum); status = 0; cpl_io_fits_close_file(fptr, &status); return NULL; @@ -21647,8 +21995,8 @@ if (status) { (void)cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, status, - fits_get_hdu_type, "filename='%s', position=%d", - filename, xtnum); + fits_get_hdu_type, + "filename='%s', position=%d", filename, xtnum); status = 0; cpl_io_fits_close_file(fptr, &status); return NULL; @@ -21679,8 +22027,8 @@ if (status) { (void)cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, status, - fits_get_num_rowsll, "filename='%s', position=%d", - filename, xtnum); + fits_get_num_rowsll, + "filename='%s', position=%d", filename, xtnum); status = 0; cpl_io_fits_close_file(fptr, &status); return NULL; @@ -21753,8 +22101,7 @@ cpl_table_delete(table); return NULL; } - cpl_fits_get_colnum(fptr, CASEINSEN, extcol[i], &colnum, - &status); + cpl_fits_get_colnum(fptr, CASEINSEN, extcol[i], &colnum, &status); if (status) { cpl_table_delete(table); cpl_error_set_(CPL_ERROR_DATA_NOT_FOUND); @@ -21770,28 +22117,31 @@ */ for (i = 0, k = 0; i < ncol; i++) { + cpl_size repeat; + cpl_size width; + int anynul; + char *nullarray; + + /* + * Only need to keep column numbers up to 9999, but space for the + * maximum possible number of digits is needed for the buffer. + */ + char scolnum[6]; + snprintf(scolnum, 6, "%hd", (short int)(i + 1)); - cpl_size repeat; - cpl_size width; - int anynul; - char *nullarray; - char scolnum[5]; /* Keeping column numbers up to 9999 */ - - - snprintf(scolnum, 5, "%d", i + 1); fits_get_colname(fptr, CASEINSEN, scolnum, colname, &colnum, &status); if (status) { (void)cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, status, - fits_get_colname, "filename='%s', position=%d", - filename, xtnum); + fits_get_colname, + "filename='%s', position=%d", filename, + xtnum); status = 0; cpl_io_fits_close_file(fptr, &status); return NULL; } if (colnum != i + 1) { - /* * This has the sense of an assertion */ @@ -21799,12 +22149,12 @@ cpl_io_fits_close_file(fptr, &status); cpl_error_set_message_(CPL_ERROR_UNSPECIFIED, "Unexpected column number " - "(%d instead of %d)", colnum, i + 1); + "(%d instead of %d)", + colnum, i + 1); return NULL; } if (extcol) { - /* * Check if this column should be extracted */ @@ -21827,16 +22177,17 @@ */ LONGLONG longrepeat, longwidth; - fits_get_eqcoltypell(fptr, i + 1, &typecode, - &longrepeat, &longwidth, &status); + fits_get_eqcoltypell(fptr, i + 1, &typecode, &longrepeat, + &longwidth, &status); repeat = (cpl_size)longrepeat; width = (cpl_size)longwidth; } if (status) { (void)cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, status, - fits_get_eqcoltypell, "filename='%s', position=%d", - filename, xtnum); + fits_get_eqcoltypell, + "filename='%s', position=%d", filename, + xtnum); status = 0; cpl_io_fits_close_file(fptr, &status); return NULL; @@ -21855,768 +22206,775 @@ } switch (typecode) { - case TSTRING: - if (hdutype == ASCII_TBL) { - - /* + case TSTRING: + if (hdutype == ASCII_TBL) { + /* * No arrays of strings in ASCII tables (i.e., repeat = 1 * always, it's the width that rules). */ - repeat = width; - } - - field_size = width + 1; - depth = repeat / width; - - if (depth > 1) { - cpl_table_new_column_array(table, colname, - CPL_TYPE_STRING, depth); - array = cpl_table_get_data_array(table, colname); - nullarray = cpl_malloc(depth * sizeof(char)); + repeat = width; + } - for (j = 0; j < nrow; j++) { + field_size = width + 1; + depth = repeat / width; + if (depth > 1) { + cpl_table_new_column_array(table, colname, CPL_TYPE_STRING, + depth); + array = cpl_table_get_data_array(table, colname); + nullarray = cpl_malloc(depth * sizeof(char)); + + for (j = 0; j < nrow; j++) { + char **scolumn = NULL; + + array[j] = cpl_array_new(depth, CPL_TYPE_STRING); + scolumn = cpl_array_get_data_string(array[j]); + + for (z = 0; z < depth; z++) + scolumn[z] = cpl_calloc(field_size, sizeof(char)); + + if (check_nulls) { + fits_read_colnull(fptr, TSTRING, i + 1, + firstrow + j + 1, 1, depth, + scolumn, nullarray, &anynul, + &status); + nullcount = 0; + if (anynul) { + for (z = 0; z < depth; z++) { + if (nullarray[z]) { + nullcount++; + cpl_free(scolumn[z]); + scolumn[z] = NULL; + } + } + } + if (nullcount == depth) { + cpl_free(array[j]); + array[j] = NULL; + } + } + else { + fits_read_col(fptr, TSTRING, i + 1, + firstrow + j + 1, 1, depth, 0, + scolumn, &anynul, &status); + } + } + cpl_free(nullarray); + } + else { char **scolumn = NULL; - array[j] = cpl_array_new(depth, CPL_TYPE_STRING); - scolumn = cpl_array_get_data_string(array[j]); - - for (z = 0; z < depth; z++) - scolumn[z] = cpl_calloc(field_size, sizeof(char)); + cpl_table_new_column(table, colname, CPL_TYPE_STRING); + scolumn = cpl_table_get_data_string(table, colname); + for (j = 0; j < nrow; j++) + scolumn[j] = cpl_calloc(field_size, sizeof(char)); if (check_nulls) { - fits_read_colnull(fptr, TSTRING, i + 1, - firstrow + j + 1, 1, depth, scolumn, - nullarray, &anynul, &status); - nullcount = 0; + nullarray = cpl_calloc(nrow, sizeof(char)); + fits_read_colnull(fptr, TSTRING, i + 1, firstrow + 1, 1, + nrow, scolumn, nullarray, &anynul, + &status); if (anynul) { - for (z = 0; z < depth; z++) { - if (nullarray[z]) { - nullcount++; - cpl_free(scolumn[z]); - scolumn[z] = NULL; + for (j = 0; j < nrow; j++) { + if (nullarray[j]) { + cpl_free(scolumn[j]); + scolumn[j] = NULL; } } } - if (nullcount == depth) { - cpl_free(array[j]); - array[j] = NULL; - } + cpl_free(nullarray); } else { - fits_read_col(fptr, TSTRING, i + 1, firstrow + j + 1, - 1, depth, 0, scolumn, &anynul, &status); + fits_read_col(fptr, TSTRING, i + 1, firstrow + 1, 1, + nrow, 0, scolumn, &anynul, &status); } } - cpl_free(nullarray); - } - else { - char **scolumn = NULL; + break; + + case TLOGICAL: + if (depth > 1) { + barray = cpl_malloc(depth * sizeof(char)); + cpl_table_new_column_array(table, colname, CPL_TYPE_INT, + depth); + array = cpl_table_get_data_array(table, colname); + nullarray = cpl_malloc(depth * sizeof(char)); - cpl_table_new_column(table, colname, CPL_TYPE_STRING); - scolumn = cpl_table_get_data_string(table, colname); - for (j = 0; j < nrow; j++) - scolumn[j] = cpl_calloc(field_size, sizeof(char)); - - if (check_nulls) { - nullarray = cpl_calloc(nrow, sizeof(char)); - fits_read_colnull(fptr, TSTRING, i + 1, firstrow + 1, 1, - nrow, scolumn, nullarray, &anynul, - &status); - if (anynul) { - for (j = 0; j < nrow; j++) { - if (nullarray[j]) { - cpl_free(scolumn[j]); - scolumn[j] = NULL; + for (j = 0; j < nrow; j++) { + int *icolumn = NULL; + + array[j] = cpl_array_new(depth, CPL_TYPE_INT); + acolumn = cpl_array_get_column(array[j]); + + icolumn = cpl_column_get_data_int(acolumn); + if (check_nulls) { + fits_read_colnull(fptr, TLOGICAL, i + 1, + firstrow + j + 1, 1, depth, + barray, nullarray, &anynul, + &status); + nullcount = 0; + if (anynul) { + for (z = 0; z < depth; z++) + if (nullarray[z]) + nullcount++; + + if (nullcount == depth) { + cpl_array_delete(array[j]); + array[j] = NULL; + } + else { + nulldata = cpl_malloc( + depth * sizeof(cpl_column_flag)); + for (z = 0; z < depth; z++) + nulldata[z] = nullarray[z]; + cpl_column_set_data_invalid(acolumn, + nulldata, + nullcount); + } + } + else { + cpl_column_set_data_invalid(acolumn, NULL, 0); } } + else { + fits_read_col(fptr, TLOGICAL, i + 1, + firstrow + j + 1, 1, depth, 0, barray, + &anynul, &status); + cpl_column_set_data_invalid(acolumn, NULL, 0); + } + for (z = 0; z < depth; z++) + icolumn[z] = barray[z]; } + cpl_free(barray); cpl_free(nullarray); } else { - fits_read_col(fptr, TSTRING, i + 1, firstrow + 1, 1, - nrow, 0, scolumn, &anynul, &status); - } - } - - break; - - case TLOGICAL: - if (depth > 1) { - barray = cpl_malloc(depth * sizeof(char)); - cpl_table_new_column_array(table, colname, - CPL_TYPE_INT, depth); - array = cpl_table_get_data_array(table, colname); - nullarray = cpl_malloc(depth * sizeof(char)); - - for (j = 0; j < nrow; j++) { - int *icolumn = NULL; - array[j] = cpl_array_new(depth, CPL_TYPE_INT); - acolumn = cpl_array_get_column(array[j]); - - icolumn = cpl_column_get_data_int(acolumn); + barray = cpl_malloc(nrow * sizeof(char)); + cpl_table_new_column(table, colname, CPL_TYPE_INT); + icolumn = cpl_table_get_data_int(table, colname); if (check_nulls) { - fits_read_colnull(fptr, TLOGICAL, i + 1, - firstrow + j + 1, - 1, depth, barray, nullarray, - &anynul, &status); + nullarray = cpl_malloc(nrow * sizeof(char)); + fits_read_colnull(fptr, TLOGICAL, i + 1, firstrow + 1, + 1, nrow, barray, nullarray, &anynul, + &status); nullcount = 0; + nulldata = NULL; if (anynul) { - for (z = 0; z < depth; z++) - if (nullarray[z]) + for (j = 0; j < nrow; j++) + if (nullarray[j]) nullcount++; - if (nullcount == depth) { - cpl_array_delete(array[j]); - array[j] = NULL; - } - else { + if (nullcount < nrow) { nulldata = - cpl_malloc(depth * sizeof(cpl_column_flag)); - for (z = 0; z < depth; z++) - nulldata[z] = nullarray[z]; - cpl_column_set_data_invalid(acolumn, nulldata, - nullcount); + cpl_malloc(nrow * sizeof(cpl_column_flag)); + for (j = 0; j < nrow; j++) + nulldata[j] = nullarray[j]; } } - else { - cpl_column_set_data_invalid(acolumn, NULL, 0); - } + cpl_free(nullarray); + cpl_column_set_data_invalid(table->columns[k], nulldata, + nullcount); } else { - fits_read_col(fptr, TLOGICAL, i + 1, firstrow + j + 1, - 1, depth, 0, barray, &anynul, &status); - cpl_column_set_data_invalid(acolumn, NULL, 0); - } - for (z = 0; z < depth; z++) - icolumn[z] = barray[z]; - } - cpl_free(barray); - cpl_free(nullarray); - } - else { - - int *icolumn = NULL; + fits_read_col(fptr, TLOGICAL, i + 1, firstrow + 1, 1, + nrow, 0, barray, &anynul, &status); + cpl_column_set_data_invalid(table->columns[k], NULL, 0); + } + for (j = 0; j < nrow; j++) + icolumn[j] = barray[j]; + cpl_free(barray); + } + break; + case TBYTE: + case TSBYTE: + case TSHORT: + case TUSHORT: + case TINT: + case TLONG: + if (depth > 1) { + cpl_table_new_column_array(table, colname, CPL_TYPE_INT, + depth); + array = cpl_table_get_data_array(table, colname); + nullarray = cpl_malloc(depth * sizeof(char)); + + for (j = 0; j < nrow; j++) { + int *icolumn = NULL; + + array[j] = cpl_array_new(depth, CPL_TYPE_INT); + acolumn = cpl_array_get_column(array[j]); + + icolumn = cpl_column_get_data_int(acolumn); + if (check_nulls) { + fits_read_colnull(fptr, TINT, i + 1, + firstrow + j + 1, 1, depth, + icolumn, nullarray, &anynul, + &status); + nullcount = 0; + if (anynul) { + for (z = 0; z < depth; z++) + if (nullarray[z]) + nullcount++; - barray = cpl_malloc(nrow * sizeof(char)); - cpl_table_new_column(table, colname, CPL_TYPE_INT); - icolumn = cpl_table_get_data_int(table, colname); - if (check_nulls) { - nullarray = cpl_malloc(nrow * sizeof(char)); - fits_read_colnull(fptr, TLOGICAL, i + 1, firstrow + 1, 1, - nrow, barray, nullarray, &anynul, - &status); - nullcount = 0; - nulldata = NULL; - if (anynul) { - for (j = 0; j < nrow; j++) - if (nullarray[j]) - nullcount++; - - if (nullcount < nrow) { - nulldata = cpl_malloc(nrow * - sizeof(cpl_column_flag)); - for (j = 0; j < nrow; j++) - nulldata[j] = nullarray[j]; + if (nullcount == depth) { + cpl_array_delete(array[j]); + array[j] = NULL; + } + else { + nulldata = cpl_malloc( + depth * sizeof(cpl_column_flag)); + for (z = 0; z < depth; z++) + nulldata[z] = nullarray[z]; + cpl_column_set_data_invalid(acolumn, + nulldata, + nullcount); + } + } + else { + cpl_column_set_data_invalid(acolumn, NULL, 0); + } + } + else { + fits_read_col(fptr, TINT, i + 1, firstrow + j + 1, + 1, depth, 0, icolumn, &anynul, + &status); + cpl_column_set_data_invalid(acolumn, NULL, 0); } } cpl_free(nullarray); - cpl_column_set_data_invalid(table->columns[k], - nulldata, nullcount); } else { - fits_read_col(fptr, TLOGICAL, i + 1, firstrow + 1, 1, - nrow, 0, barray, &anynul, &status); - cpl_column_set_data_invalid(table->columns[k], NULL, 0); - } - for (j = 0; j < nrow; j++) - icolumn[j] = barray[j]; - cpl_free(barray); - } - break; - case TBYTE: - case TSBYTE: - case TSHORT: - case TUSHORT: - case TINT: - case TLONG: - if (depth > 1) { - cpl_table_new_column_array(table, colname, - CPL_TYPE_INT, depth); - array = cpl_table_get_data_array(table, colname); - nullarray = cpl_malloc(depth * sizeof(char)); - - for (j = 0; j < nrow; j++) { - int *icolumn = NULL; - array[j] = cpl_array_new(depth, CPL_TYPE_INT); - acolumn = cpl_array_get_column(array[j]); - - icolumn = cpl_column_get_data_int(acolumn); + cpl_table_new_column(table, colname, CPL_TYPE_INT); + icolumn = cpl_table_get_data_int(table, colname); if (check_nulls) { - fits_read_colnull(fptr, TINT, i + 1, firstrow + j + 1, - 1, depth, icolumn, nullarray, - &anynul, &status); + nullarray = cpl_malloc(nrow * sizeof(char)); + fits_read_colnull(fptr, TINT, i + 1, firstrow + 1, 1, + nrow, icolumn, nullarray, &anynul, + &status); nullcount = 0; + nulldata = NULL; if (anynul) { - for (z = 0; z < depth; z++) - if (nullarray[z]) + for (j = 0; j < nrow; j++) + if (nullarray[j]) nullcount++; - - if (nullcount == depth) { - cpl_array_delete(array[j]); - array[j] = NULL; - } - else { - nulldata = - cpl_malloc(depth * sizeof(cpl_column_flag)); - for (z = 0; z < depth; z++) - nulldata[z] = nullarray[z]; - cpl_column_set_data_invalid(acolumn, nulldata, - nullcount); + + if (nullcount < nrow) { + nulldata = + cpl_malloc(nrow * sizeof(cpl_column_flag)); + for (j = 0; j < nrow; j++) + nulldata[j] = nullarray[j]; } } - else { - cpl_column_set_data_invalid(acolumn, NULL, 0); - } + cpl_free(nullarray); + cpl_column_set_data_invalid(table->columns[k], nulldata, + nullcount); } else { - fits_read_col(fptr, TINT, i + 1, firstrow + j + 1, 1, - depth, 0, icolumn, &anynul, &status); - cpl_column_set_data_invalid(acolumn, NULL, 0); + fits_read_col(fptr, TINT, i + 1, firstrow + 1, 1, nrow, + 0, icolumn, &anynul, &status); + cpl_column_set_data_invalid(table->columns[k], NULL, 0); } } - cpl_free(nullarray); - } - else { - - int *icolumn = NULL; + break; + case TLONGLONG: + if (depth > 1) { + cpl_table_new_column_array(table, colname, + CPL_TYPE_LONG_LONG, depth); + array = cpl_table_get_data_array(table, colname); + nullarray = cpl_malloc(depth * sizeof(char)); + + for (j = 0; j < nrow; j++) { + long long *llcolumn = NULL; + + array[j] = cpl_array_new(depth, CPL_TYPE_LONG_LONG); + acolumn = cpl_array_get_column(array[j]); + + llcolumn = cpl_column_get_data_long_long(acolumn); + if (check_nulls) { + fits_read_colnull(fptr, TLONGLONG, i + 1, + firstrow + j + 1, 1, depth, + llcolumn, nullarray, &anynul, + &status); + nullcount = 0; + if (anynul) { + for (z = 0; z < depth; z++) + if (nullarray[z]) + nullcount++; - cpl_table_new_column(table, colname, CPL_TYPE_INT); - icolumn = cpl_table_get_data_int(table, colname); - if (check_nulls) { - nullarray = cpl_malloc(nrow * sizeof(char)); - fits_read_colnull(fptr, TINT, i + 1, firstrow + 1, 1, - nrow, icolumn, nullarray, &anynul, - &status); - nullcount = 0; - nulldata = NULL; - if (anynul) { - for (j = 0; j < nrow; j++) - if (nullarray[j]) - nullcount++; - - if (nullcount < nrow) { - nulldata = cpl_malloc(nrow * - sizeof(cpl_column_flag)); - for (j = 0; j < nrow; j++) - nulldata[j] = nullarray[j]; + if (nullcount == depth) { + cpl_array_delete(array[j]); + array[j] = NULL; + } + else { + nulldata = cpl_malloc( + depth * sizeof(cpl_column_flag)); + for (z = 0; z < depth; z++) + nulldata[z] = nullarray[z]; + cpl_column_set_data_invalid(acolumn, + nulldata, + nullcount); + } + } + else { + cpl_column_set_data_invalid(acolumn, NULL, 0); + } + } + else { + fits_read_col(fptr, TLONGLONG, i + 1, + firstrow + j + 1, 1, depth, 0, + llcolumn, &anynul, &status); + cpl_column_set_data_invalid(acolumn, NULL, 0); } } cpl_free(nullarray); - cpl_column_set_data_invalid(table->columns[k], - nulldata, nullcount); } else { - fits_read_col(fptr, TINT, i + 1, firstrow + 1, 1, - nrow, 0, icolumn, &anynul, &status); - cpl_column_set_data_invalid(table->columns[k], NULL, 0); - } - } - break; - case TLONGLONG: - if (depth > 1) { - cpl_table_new_column_array(table, colname, - CPL_TYPE_LONG_LONG, depth); - array = cpl_table_get_data_array(table, colname); - nullarray = cpl_malloc(depth * sizeof(char)); - - for (j = 0; j < nrow; j++) { - long long *llcolumn = NULL; - array[j] = cpl_array_new(depth, CPL_TYPE_LONG_LONG); - acolumn = cpl_array_get_column(array[j]); - - llcolumn = cpl_column_get_data_long_long(acolumn); + cpl_table_new_column(table, colname, CPL_TYPE_LONG_LONG); + llcolumn = cpl_table_get_data_long_long(table, colname); if (check_nulls) { - fits_read_colnull(fptr, TLONGLONG, i + 1, - firstrow + j + 1, 1, depth, - llcolumn, nullarray, - &anynul, &status); + nullarray = cpl_malloc(nrow * sizeof(char)); + fits_read_colnull(fptr, TLONGLONG, i + 1, firstrow + 1, + 1, nrow, llcolumn, nullarray, &anynul, + &status); nullcount = 0; + nulldata = NULL; if (anynul) { - for (z = 0; z < depth; z++) - if (nullarray[z]) + for (j = 0; j < nrow; j++) + if (nullarray[j]) nullcount++; - if (nullcount == depth) { - cpl_array_delete(array[j]); - array[j] = NULL; - } - else { + if (nullcount < nrow) { nulldata = - cpl_malloc(depth * sizeof(cpl_column_flag)); - for (z = 0; z < depth; z++) - nulldata[z] = nullarray[z]; - cpl_column_set_data_invalid(acolumn, nulldata, - nullcount); + cpl_malloc(nrow * sizeof(cpl_column_flag)); + for (j = 0; j < nrow; j++) + nulldata[j] = nullarray[j]; } } - else { - cpl_column_set_data_invalid(acolumn, NULL, 0); - } + cpl_free(nullarray); + cpl_column_set_data_invalid(table->columns[k], nulldata, + nullcount); } else { - fits_read_col(fptr, TLONGLONG, i + 1, firstrow + j + 1, - 1, depth, 0, llcolumn, &anynul, &status); - cpl_column_set_data_invalid(acolumn, NULL, 0); + fits_read_col(fptr, TLONGLONG, i + 1, firstrow + 1, 1, + nrow, 0, llcolumn, &anynul, &status); + cpl_column_set_data_invalid(table->columns[k], NULL, 0); } } - cpl_free(nullarray); - } - else { - - long long *llcolumn = NULL; + break; + case TFLOAT: + if (depth > 1) { + cpl_table_new_column_array(table, colname, CPL_TYPE_FLOAT, + depth); + array = cpl_table_get_data_array(table, colname); + nullarray = cpl_malloc(depth * sizeof(char)); + + for (j = 0; j < nrow; j++) { + float *fcolumn = NULL; + + array[j] = cpl_array_new(depth, CPL_TYPE_FLOAT); + acolumn = cpl_array_get_column(array[j]); + + fcolumn = cpl_column_get_data_float(acolumn); + if (check_nulls) { + fits_read_colnull(fptr, TFLOAT, i + 1, + firstrow + j + 1, 1, depth, + fcolumn, nullarray, &anynul, + &status); + nullcount = 0; + if (anynul) { + for (z = 0; z < depth; z++) + if (nullarray[z]) + nullcount++; - cpl_table_new_column(table, colname, CPL_TYPE_LONG_LONG); - llcolumn = cpl_table_get_data_long_long(table, colname); - if (check_nulls) { - nullarray = cpl_malloc(nrow * sizeof(char)); - fits_read_colnull(fptr, TLONGLONG, i + 1, firstrow + 1, 1, - nrow, llcolumn, nullarray, &anynul, - &status); - nullcount = 0; - nulldata = NULL; - if (anynul) { - for (j = 0; j < nrow; j++) - if (nullarray[j]) - nullcount++; - - if (nullcount < nrow) { - nulldata = cpl_malloc(nrow * - sizeof(cpl_column_flag)); - for (j = 0; j < nrow; j++) - nulldata[j] = nullarray[j]; + if (nullcount == depth) { + cpl_array_delete(array[j]); + array[j] = NULL; + } + else { + nulldata = cpl_malloc( + depth * sizeof(cpl_column_flag)); + for (z = 0; z < depth; z++) + nulldata[z] = nullarray[z]; + cpl_column_set_data_invalid(acolumn, + nulldata, + nullcount); + } + } + else { + cpl_column_set_data_invalid(acolumn, NULL, 0); + } + } + else { + fits_read_col(fptr, TFLOAT, i + 1, firstrow + j + 1, + 1, depth, 0, fcolumn, &anynul, + &status); + cpl_column_set_data_invalid(acolumn, NULL, 0); } } cpl_free(nullarray); - cpl_column_set_data_invalid(table->columns[k], - nulldata, nullcount); } else { - fits_read_col(fptr, TLONGLONG, i + 1, firstrow + 1, 1, - nrow, 0, llcolumn, &anynul, &status); - cpl_column_set_data_invalid(table->columns[k], NULL, 0); - } - } - break; - case TFLOAT: - if (depth > 1) { - cpl_table_new_column_array(table, colname, - CPL_TYPE_FLOAT, depth); - array = cpl_table_get_data_array(table, colname); - nullarray = cpl_malloc(depth * sizeof(char)); - - for (j = 0; j < nrow; j++) { - float *fcolumn = NULL; - array[j] = cpl_array_new(depth, CPL_TYPE_FLOAT); - acolumn = cpl_array_get_column(array[j]); - - fcolumn = cpl_column_get_data_float(acolumn); + cpl_table_new_column(table, colname, CPL_TYPE_FLOAT); + fcolumn = cpl_table_get_data_float(table, colname); if (check_nulls) { - fits_read_colnull(fptr, TFLOAT, i + 1, - firstrow + j + 1, 1, depth, fcolumn, - nullarray, &anynul, &status); + nullarray = cpl_malloc(nrow * sizeof(char)); + fits_read_colnull(fptr, TFLOAT, i + 1, firstrow + 1, 1, + nrow, fcolumn, nullarray, &anynul, + &status); nullcount = 0; + nulldata = NULL; if (anynul) { - for (z = 0; z < depth; z++) - if (nullarray[z]) + for (j = 0; j < nrow; j++) + if (nullarray[j]) nullcount++; - if (nullcount == depth) { - cpl_array_delete(array[j]); - array[j] = NULL; - } - else { - nulldata = - cpl_malloc(depth * sizeof(cpl_column_flag)); - for (z = 0; z < depth; z++) - nulldata[z] = nullarray[z]; - cpl_column_set_data_invalid(acolumn, nulldata, - nullcount); + if (nullcount < nrow) { + nulldata = + cpl_malloc(nrow * sizeof(cpl_column_flag)); + for (j = 0; j < nrow; j++) + nulldata[j] = nullarray[j]; } } - else { - cpl_column_set_data_invalid(acolumn, NULL, 0); - } + cpl_free(nullarray); + cpl_column_set_data_invalid(table->columns[k], nulldata, + nullcount); } else { - fits_read_col(fptr, TFLOAT, i + 1, firstrow + j + 1, - 1, depth, 0, fcolumn, &anynul, &status); - cpl_column_set_data_invalid(acolumn, NULL, 0); + fits_read_col(fptr, TFLOAT, i + 1, firstrow + 1, 1, + nrow, 0, fcolumn, &anynul, &status); + cpl_column_set_data_invalid(table->columns[k], NULL, 0); } } - cpl_free(nullarray); - } - else { - - float *fcolumn = NULL; + break; + case TDOUBLE: + if (depth > 1) { + cpl_table_new_column_array(table, colname, CPL_TYPE_DOUBLE, + depth); + array = cpl_table_get_data_array(table, colname); + nullarray = cpl_malloc(depth * sizeof(char)); + + for (j = 0; j < nrow; j++) { + double *dcolumn = NULL; + + array[j] = cpl_array_new(depth, CPL_TYPE_DOUBLE); + acolumn = cpl_array_get_column(array[j]); + + dcolumn = cpl_column_get_data_double(acolumn); + if (check_nulls) { + fits_read_colnull(fptr, TDOUBLE, i + 1, + firstrow + j + 1, 1, depth, + dcolumn, nullarray, &anynul, + &status); + nullcount = 0; + if (anynul) { + for (z = 0; z < depth; z++) + if (nullarray[z]) + nullcount++; - cpl_table_new_column(table, colname, CPL_TYPE_FLOAT); - fcolumn = cpl_table_get_data_float(table, colname); - if (check_nulls) { - nullarray = cpl_malloc(nrow * sizeof(char)); - fits_read_colnull(fptr, TFLOAT, i + 1, firstrow + 1, 1, - nrow, fcolumn, nullarray, &anynul, - &status); - nullcount = 0; - nulldata = NULL; - if (anynul) { - for (j = 0; j < nrow; j++) - if (nullarray[j]) - nullcount++; - - if (nullcount < nrow) { - nulldata = cpl_malloc(nrow * - sizeof(cpl_column_flag)); - for (j = 0; j < nrow; j++) - nulldata[j] = nullarray[j]; + if (nullcount == depth) { + cpl_array_delete(array[j]); + array[j] = NULL; + } + else { + nulldata = cpl_malloc( + depth * sizeof(cpl_column_flag)); + for (z = 0; z < depth; z++) + nulldata[z] = nullarray[z]; + cpl_column_set_data_invalid(acolumn, + nulldata, + nullcount); + } + } + else { + cpl_column_set_data_invalid(acolumn, NULL, 0); + } + } + else { + fits_read_col(fptr, TDOUBLE, i + 1, + firstrow + j + 1, 1, depth, 0, + dcolumn, &anynul, &status); + cpl_column_set_data_invalid(acolumn, NULL, 0); } } cpl_free(nullarray); - cpl_column_set_data_invalid(table->columns[k], - nulldata, nullcount); } else { - fits_read_col(fptr, TFLOAT, i + 1, firstrow + 1, 1, - nrow, 0, fcolumn, &anynul, &status); - cpl_column_set_data_invalid(table->columns[k], NULL, 0); - } - } - break; - case TDOUBLE: - if (depth > 1) { - cpl_table_new_column_array(table, colname, - CPL_TYPE_DOUBLE, depth); - array = cpl_table_get_data_array(table, colname); - nullarray = cpl_malloc(depth * sizeof(char)); - - for (j = 0; j < nrow; j++) { - double *dcolumn = NULL; - array[j] = cpl_array_new(depth, CPL_TYPE_DOUBLE); - acolumn = cpl_array_get_column(array[j]); - - dcolumn = cpl_column_get_data_double(acolumn); + cpl_table_new_column(table, colname, CPL_TYPE_DOUBLE); + dcolumn = cpl_table_get_data_double(table, colname); if (check_nulls) { - fits_read_colnull(fptr, TDOUBLE, i + 1, - firstrow + j + 1, 1, depth, dcolumn, - nullarray, &anynul, &status); + nullarray = cpl_malloc(nrow * sizeof(char)); + fits_read_colnull(fptr, TDOUBLE, i + 1, firstrow + 1, 1, + nrow, dcolumn, nullarray, &anynul, + &status); nullcount = 0; - if (anynul) { - for (z = 0; z < depth; z++) - if (nullarray[z]) + nulldata = NULL; + if (anynul) { + for (j = 0; j < nrow; j++) + if (nullarray[j]) nullcount++; - if (nullcount == depth) { - cpl_array_delete(array[j]); - array[j] = NULL; - } - else { - nulldata = - cpl_malloc(depth * sizeof(cpl_column_flag)); - for (z = 0; z < depth; z++) - nulldata[z] = nullarray[z]; - cpl_column_set_data_invalid(acolumn, nulldata, - nullcount); + if (nullcount < nrow) { + nulldata = + cpl_malloc(nrow * sizeof(cpl_column_flag)); + for (j = 0; j < nrow; j++) + nulldata[j] = nullarray[j]; } } - else { - cpl_column_set_data_invalid(acolumn, NULL, 0); - } + cpl_free(nullarray); + cpl_column_set_data_invalid(table->columns[k], nulldata, + nullcount); } else { - fits_read_col(fptr, TDOUBLE, i + 1, firstrow + j + 1, - 1, depth, 0, dcolumn, &anynul, &status); - cpl_column_set_data_invalid(acolumn, NULL, 0); + fits_read_col(fptr, TDOUBLE, i + 1, firstrow + 1, 1, + nrow, 0, dcolumn, &anynul, &status); + cpl_column_set_data_invalid(table->columns[k], NULL, 0); } } - cpl_free(nullarray); - } - else { + break; + case TCOMPLEX: + if (depth > 1) { + float *fcolumn = NULL; - double *dcolumn = NULL; + cpl_table_new_column_array(table, colname, + CPL_TYPE_FLOAT_COMPLEX, depth); + array = cpl_table_get_data_array(table, colname); + nullarray = cpl_malloc(depth * sizeof(char)); + fcolumn = cpl_malloc(2 * depth * sizeof(float)); + + for (j = 0; j < nrow; j++) { + float complex *cfcolumn = NULL; + + array[j] = cpl_array_new(depth, CPL_TYPE_FLOAT_COMPLEX); + acolumn = cpl_array_get_column(array[j]); + + cfcolumn = cpl_column_get_data_float_complex(acolumn); + if (check_nulls) { + fits_read_colnull(fptr, TCOMPLEX, i + 1, + firstrow + j + 1, 1, depth, + fcolumn, nullarray, &anynul, + &status); - cpl_table_new_column(table, colname, CPL_TYPE_DOUBLE); - dcolumn = cpl_table_get_data_double(table, colname); - if (check_nulls) { - nullarray = cpl_malloc(nrow * sizeof(char)); - fits_read_colnull(fptr, TDOUBLE, i + 1, firstrow + 1, - 1, nrow, dcolumn, nullarray, &anynul, - &status); - nullcount = 0; - nulldata = NULL; - if (anynul) { - for (j = 0; j < nrow; j++) - if (nullarray[j]) - nullcount++; - - if (nullcount < nrow) { - nulldata = cpl_malloc(nrow * - sizeof(cpl_column_flag)); - for (j = 0; j < nrow; j++) - nulldata[j] = nullarray[j]; + for (zz = z = 0; z < depth; z++, zz += 2) + cfcolumn[z] = fcolumn[zz] + I * fcolumn[zz + 1]; + + nullcount = 0; + if (anynul) { + for (z = 0; z < depth; z++) + if (nullarray[z]) + nullcount++; + + if (nullcount == depth) { + cpl_array_delete(array[j]); + array[j] = NULL; + } + else { + nulldata = cpl_malloc( + depth * sizeof(cpl_column_flag)); + for (z = 0; z < depth; z++) + nulldata[z] = nullarray[z]; + cpl_column_set_data_invalid(acolumn, + nulldata, + nullcount); + } + } + else { + cpl_column_set_data_invalid(acolumn, NULL, 0); + } + } + else { + fits_read_col(fptr, TCOMPLEX, i + 1, + firstrow + j + 1, 1, depth, 0, + fcolumn, &anynul, &status); + + for (zz = z = 0; z < depth; z++, zz += 2) + cfcolumn[z] = fcolumn[zz] + I * fcolumn[zz + 1]; + + cpl_column_set_data_invalid(acolumn, NULL, 0); } } + cpl_free(fcolumn); cpl_free(nullarray); - cpl_column_set_data_invalid(table->columns[k], - nulldata, nullcount); } else { - fits_read_col(fptr, TDOUBLE, i + 1, firstrow + 1, 1, - nrow, 0, dcolumn, &anynul, &status); - cpl_column_set_data_invalid(table->columns[k], NULL, 0); - } - } - break; - case TCOMPLEX: - if (depth > 1) { - - float *fcolumn = NULL; - - cpl_table_new_column_array(table, colname, - CPL_TYPE_FLOAT_COMPLEX, depth); - array = cpl_table_get_data_array(table, colname); - nullarray = cpl_malloc(depth * sizeof(char)); - fcolumn = cpl_malloc(2 * depth * sizeof(float)); - - for (j = 0; j < nrow; j++) { - + float *fcolumn = NULL; float complex *cfcolumn = NULL; - array[j] = cpl_array_new(depth, CPL_TYPE_FLOAT_COMPLEX); - acolumn = cpl_array_get_column(array[j]); - - cfcolumn = cpl_column_get_data_float_complex(acolumn); + cpl_table_new_column(table, colname, + CPL_TYPE_FLOAT_COMPLEX); + cfcolumn = cpl_table_get_data_float_complex(table, colname); + fcolumn = cpl_malloc(2 * nrow * sizeof(float)); if (check_nulls) { - fits_read_colnull(fptr, TCOMPLEX, i + 1, - firstrow + j + 1, 1, depth, fcolumn, - nullarray, &anynul, &status); - - for (zz = z = 0; z < depth; z++, zz += 2) - cfcolumn[z] = fcolumn[zz] + I*fcolumn[zz+1]; + nullarray = cpl_malloc(nrow * sizeof(char)); + fits_read_colnull(fptr, TCOMPLEX, i + 1, firstrow + 1, + 1, nrow, fcolumn, nullarray, &anynul, + &status); nullcount = 0; + nulldata = NULL; if (anynul) { - for (z = 0; z < depth; z++) - if (nullarray[z]) + for (j = 0; j < nrow; j++) + if (nullarray[j]) nullcount++; - if (nullcount == depth) { - cpl_array_delete(array[j]); - array[j] = NULL; - } - else { - nulldata = - cpl_malloc(depth * sizeof(cpl_column_flag)); - for (z = 0; z < depth; z++) - nulldata[z] = nullarray[z]; - cpl_column_set_data_invalid(acolumn, nulldata, - nullcount); + if (nullcount < nrow) { + nulldata = + cpl_malloc(nrow * sizeof(cpl_column_flag)); + for (j = 0; j < nrow; j++) + nulldata[j] = nullarray[j]; } } - else { - cpl_column_set_data_invalid(acolumn, NULL, 0); - } + cpl_free(nullarray); + cpl_column_set_data_invalid(table->columns[k], nulldata, + nullcount); } else { - fits_read_col(fptr, TCOMPLEX, i + 1, firstrow + j + 1, - 1, depth, 0, fcolumn, &anynul, &status); - - for (zz = z = 0; z < depth; z++, zz += 2) - cfcolumn[z] = fcolumn[zz] + I*fcolumn[zz+1]; - - cpl_column_set_data_invalid(acolumn, NULL, 0); + fits_read_col(fptr, TCOMPLEX, i + 1, firstrow + 1, 1, + nrow, 0, fcolumn, &anynul, &status); + cpl_column_set_data_invalid(table->columns[k], NULL, 0); } - } - cpl_free(fcolumn); - cpl_free(nullarray); - } - else { - float *fcolumn = NULL; - float complex *cfcolumn = NULL; + for (z = zz = 0; z < nrow; z++, zz += 2) + cfcolumn[z] = fcolumn[zz] + I * fcolumn[zz + 1]; - cpl_table_new_column(table, colname, CPL_TYPE_FLOAT_COMPLEX); - cfcolumn = cpl_table_get_data_float_complex(table, colname); - fcolumn = cpl_malloc(2 * nrow * sizeof(float)); - if (check_nulls) { - nullarray = cpl_malloc(nrow * sizeof(char)); - fits_read_colnull(fptr, TCOMPLEX, i + 1, firstrow + 1, 1, - nrow, fcolumn, nullarray, &anynul, - &status); - - nullcount = 0; - nulldata = NULL; - if (anynul) { - for (j = 0; j < nrow; j++) - if (nullarray[j]) - nullcount++; - - if (nullcount < nrow) { - nulldata = cpl_malloc(nrow * - sizeof(cpl_column_flag)); - for (j = 0; j < nrow; j++) - nulldata[j] = nullarray[j]; - } - } - cpl_free(nullarray); - cpl_column_set_data_invalid(table->columns[k], - nulldata, nullcount); - } - else { - fits_read_col(fptr, TCOMPLEX, i + 1, firstrow + 1, 1, - nrow, 0, fcolumn, &anynul, &status); - cpl_column_set_data_invalid(table->columns[k], NULL, 0); + cpl_free(fcolumn); } + break; + case TDBLCOMPLEX: + if (depth > 1) { + double *dcolumn = NULL; - for (z = zz = 0; z < nrow; z++, zz += 2) - cfcolumn[z] = fcolumn[zz] + I*fcolumn[zz+1]; + cpl_table_new_column_array(table, colname, + CPL_TYPE_DOUBLE_COMPLEX, depth); + array = cpl_table_get_data_array(table, colname); + nullarray = cpl_malloc(depth * sizeof(char)); + dcolumn = cpl_malloc(2 * depth * sizeof(double)); + + for (j = 0; j < nrow; j++) { + double complex *cdcolumn = NULL; + + array[j] = + cpl_array_new(depth, CPL_TYPE_DOUBLE_COMPLEX); + acolumn = cpl_array_get_column(array[j]); + + cdcolumn = cpl_column_get_data_double_complex(acolumn); + if (check_nulls) { + fits_read_colnull(fptr, TDBLCOMPLEX, i + 1, + firstrow + j + 1, 1, depth, + dcolumn, nullarray, &anynul, + &status); - cpl_free(fcolumn); - } - break; - case TDBLCOMPLEX: - if (depth > 1) { + for (zz = z = 0; z < depth; z++, zz += 2) + cdcolumn[z] = dcolumn[zz] + I * dcolumn[zz + 1]; - double *dcolumn = NULL; + nullcount = 0; + if (anynul) { + for (z = 0; z < depth; z++) + if (nullarray[z]) + nullcount++; - cpl_table_new_column_array(table, colname, - CPL_TYPE_DOUBLE_COMPLEX, depth); - array = cpl_table_get_data_array(table, colname); - nullarray = cpl_malloc(depth * sizeof(char)); - dcolumn = cpl_malloc(2 * depth * sizeof(double)); + if (nullcount == depth) { + cpl_array_delete(array[j]); + array[j] = NULL; + } + else { + nulldata = cpl_malloc( + depth * sizeof(cpl_column_flag)); + for (z = 0; z < depth; z++) + nulldata[z] = nullarray[z]; + cpl_column_set_data_invalid(acolumn, + nulldata, + nullcount); + } + } + else { + cpl_column_set_data_invalid(acolumn, NULL, 0); + } + } + else { + fits_read_col(fptr, TDBLCOMPLEX, i + 1, + firstrow + j + 1, 1, depth, 0, + dcolumn, &anynul, &status); - for (j = 0; j < nrow; j++) { + for (zz = z = 0; z < depth; z++, zz += 2) + cdcolumn[z] = dcolumn[zz] + I * dcolumn[zz + 1]; + cpl_column_set_data_invalid(acolumn, NULL, 0); + } + } + cpl_free(dcolumn); + cpl_free(nullarray); + } + else { + double *dcolumn = NULL; double complex *cdcolumn = NULL; - array[j] = cpl_array_new(depth, CPL_TYPE_DOUBLE_COMPLEX); - acolumn = cpl_array_get_column(array[j]); + cpl_table_new_column(table, colname, + CPL_TYPE_DOUBLE_COMPLEX); + cdcolumn = + cpl_table_get_data_double_complex(table, colname); + dcolumn = cpl_malloc(2 * nrow * sizeof(double)); - cdcolumn = cpl_column_get_data_double_complex(acolumn); if (check_nulls) { - fits_read_colnull(fptr, TDBLCOMPLEX, i + 1, - firstrow + j + 1, 1, depth, dcolumn, + nullarray = cpl_malloc(nrow * sizeof(char)); + fits_read_colnull(fptr, TDBLCOMPLEX, i + 1, + firstrow + 1, 1, nrow, dcolumn, nullarray, &anynul, &status); - - for (zz = z = 0; z < depth; z++, zz += 2) - cdcolumn[z] = dcolumn[zz] + I*dcolumn[zz+1]; - nullcount = 0; - if (anynul) { - for (z = 0; z < depth; z++) - if (nullarray[z]) + nulldata = NULL; + if (anynul) { + for (j = 0; j < nrow; j++) + if (nullarray[j]) nullcount++; - if (nullcount == depth) { - cpl_array_delete(array[j]); - array[j] = NULL; - } - else { - nulldata = - cpl_malloc(depth * sizeof(cpl_column_flag)); - for (z = 0; z < depth; z++) - nulldata[z] = nullarray[z]; - cpl_column_set_data_invalid(acolumn, nulldata, - nullcount); + if (nullcount < nrow) { + nulldata = + cpl_malloc(nrow * sizeof(cpl_column_flag)); + for (j = 0; j < nrow; j++) + nulldata[j] = nullarray[j]; } } - else { - cpl_column_set_data_invalid(acolumn, NULL, 0); - } + cpl_free(nullarray); + cpl_column_set_data_invalid(table->columns[k], nulldata, + nullcount); } else { - fits_read_col(fptr, TDBLCOMPLEX, i + 1, - firstrow + j + 1, 1, depth, 0, - dcolumn, &anynul, &status); - - for (zz = z = 0; z < depth; z++, zz += 2) - cdcolumn[z] = dcolumn[zz] + I*dcolumn[zz+1]; - - cpl_column_set_data_invalid(acolumn, NULL, 0); + fits_read_col(fptr, TDBLCOMPLEX, i + 1, firstrow + 1, 1, + nrow, 0, dcolumn, &anynul, &status); + cpl_column_set_data_invalid(table->columns[k], NULL, 0); } - } - cpl_free(dcolumn); - cpl_free(nullarray); - } - else { - double *dcolumn = NULL; - double complex *cdcolumn = NULL; + for (z = zz = 0; z < nrow; z++, zz += 2) + cdcolumn[z] = dcolumn[zz] + I * dcolumn[zz + 1]; - cpl_table_new_column(table, colname, CPL_TYPE_DOUBLE_COMPLEX); - cdcolumn = cpl_table_get_data_double_complex(table, colname); - dcolumn = cpl_malloc(2 * nrow * sizeof(double)); - - if (check_nulls) { - nullarray = cpl_malloc(nrow * sizeof(char)); - fits_read_colnull(fptr, TDBLCOMPLEX, i + 1, firstrow + 1, - 1, nrow, dcolumn, nullarray, &anynul, - &status); - nullcount = 0; - nulldata = NULL; - if (anynul) { - for (j = 0; j < nrow; j++) - if (nullarray[j]) - nullcount++; - - if (nullcount < nrow) { - nulldata = cpl_malloc(nrow * - sizeof(cpl_column_flag)); - for (j = 0; j < nrow; j++) - nulldata[j] = nullarray[j]; - } - } - cpl_free(nullarray); - cpl_column_set_data_invalid(table->columns[k], - nulldata, nullcount); - } - else { - fits_read_col(fptr, TDBLCOMPLEX, i + 1, firstrow + 1, 1, - nrow, 0, dcolumn, &anynul, &status); - cpl_column_set_data_invalid(table->columns[k], NULL, 0); + cpl_free(dcolumn); } + break; - for (z = zz = 0; z < nrow; z++, zz += 2) - cdcolumn[z] = dcolumn[zz] + I*dcolumn[zz+1]; - - cpl_free(dcolumn); - } - break; - - default: - cpl_msg_debug(cpl_func, "Found unsupported type (%s)\n", colname); -/* + default: + cpl_msg_debug(cpl_func, "Found unsupported type (%s)\n", + colname); + /* cx_print("cpl_table_load(): found unsupported type (%s)\n", colname); */ - continue; + continue; } if (status) { (void)cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, status, - fits_read_col, "filename='%s', position=%d", - filename, xtnum); + fits_read_col, + "filename='%s', position=%d", filename, + xtnum); status = 0; cpl_io_fits_close_file(fptr, &status); return NULL; @@ -22637,7 +22995,6 @@ } if (depth > 1 && typecode != TSTRING) { - /* * Read TDIM keyword. The first call is just to get the * number of dimensions. @@ -22652,9 +23009,9 @@ */ LONGLONG *longnaxes = cpl_malloc(naxis * sizeof(LONGLONG)); - int t; + int t; - fits_read_tdimll(fptr, i + 1, naxis, &naxis, longnaxes, + fits_read_tdimll(fptr, i + 1, naxis, &naxis, longnaxes, &status); for (t = 0; t < naxis; t++) { @@ -22662,13 +23019,13 @@ } cpl_free(longnaxes); - } if (status) { (void)cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, status, - fits_read_tdimll, "filename='%s', position=%d", - filename, xtnum); + fits_read_tdimll, + "filename='%s', position=%d", filename, + xtnum); status = 0; cpl_io_fits_close_file(fptr, &status); return NULL; @@ -22680,21 +23037,20 @@ */ adim = cpl_array_new(naxis, CPL_TYPE_INT); - for (j = 0; j < naxis; j++) - cpl_array_set_int(adim, j, (int) naxes[j]); + for (j = 0; j < naxis; j++) + cpl_array_set_int(adim, j, (int)naxes[j]); cpl_free(naxes); cpl_column_set_dimensions(table->columns[k], adim); cpl_array_delete(adim); } - k++; /* A valid column was successfully processed */ - + k++; /* A valid column was successfully processed */ } cpl_io_fits_close_file(fptr, &status); if (status) { - cpl_error_set_message_(CPL_ERROR_BAD_FILE_FORMAT, "CFITSIO: %s", + cpl_error_set_message_(CPL_ERROR_BAD_FILE_FORMAT, "CFITSIO: %s", err_text); return NULL; } @@ -22767,11 +23123,11 @@ * the @em cpl_table conventions. */ -cpl_table *cpl_table_load(const char *filename, int xtnum, int check_nulls) +cpl_table * +cpl_table_load(const char *filename, int xtnum, int check_nulls) { - - cpl_table *table = cpl_table_overload_window(filename, xtnum, check_nulls, - NULL, -1, -1); + cpl_table *table = + cpl_table_overload_window(filename, xtnum, check_nulls, NULL, -1, -1); return table; } @@ -22849,12 +23205,14 @@ * conventions. If @em selcol is NULL, all columns are selected. */ -cpl_table *cpl_table_load_window(const char *filename, int xtnum, - int check_nulls, const cpl_array *selcol, - cpl_size firstrow, cpl_size nrow) +cpl_table * +cpl_table_load_window(const char *filename, + int xtnum, + int check_nulls, + const cpl_array *selcol, + cpl_size firstrow, + cpl_size nrow) { - - cpl_table *table; @@ -22868,19 +23226,19 @@ return NULL; } - table = cpl_table_overload_window(filename, xtnum, check_nulls, - selcol, firstrow, nrow); + table = cpl_table_overload_window(filename, xtnum, check_nulls, selcol, + firstrow, nrow); return table; - } -enum { - CPL_NULL_FLAG_NONE = 0, +enum +{ + CPL_NULL_FLAG_NONE = 0, CPL_NULL_FLAG_IVALUE = 1 << 0, CPL_NULL_FLAG_FVALUE = 1 << 1, - CPL_NULL_FLAG_ARRAY = 1 << 2 + CPL_NULL_FLAG_ARRAY = 1 << 2 }; @@ -22888,47 +23246,43 @@ struct cpl_table_layout { - int columns; - LONGLONG rows; - LONGLONG *depth; - - cpl_type *value_type; - cpl_type *saved_type; - int *native_type; - - int *naxes; - LONGLONG **naxis; - - char **ttype; - char **tform; - char **tunit; - - struct - { - unsigned int flag; - LONGLONG value; - const cpl_column_flag *mask; - } *tnull; + int columns; + LONGLONG rows; + LONGLONG *depth; + + cpl_type *value_type; + cpl_type *saved_type; + int *native_type; + + int *naxes; + LONGLONG **naxis; + + char **ttype; + char **tform; + char **tunit; + struct + { + unsigned int flag; + LONGLONG value; + const cpl_column_flag *mask; + } * tnull; }; inline static void _cpl_table_layout_clear(cpl_table_layout *self) { - register int icol; cpl_free(self->tnull); for (icol = 0; icol < self->columns; ++icol) { - cpl_free(self->tform[icol]); cpl_free(self->tunit[icol]); cpl_free(self->ttype[icol]); cpl_free(self->naxis[icol]); - } cpl_free(self->tform); @@ -22944,20 +23298,18 @@ cpl_free(self->depth); return; - } inline static int _cpl_table_layout_init(cpl_table_layout *self, int ncolumns) { - self->columns = ncolumns; - self->rows = 0; - self->depth = cpl_calloc(self->columns, sizeof *self->depth); + self->rows = 0; + self->depth = cpl_calloc(self->columns, sizeof *self->depth); - self->value_type = cpl_calloc(self->columns, sizeof *self->value_type); - self->saved_type = cpl_calloc(self->columns, sizeof *self->saved_type); + self->value_type = cpl_calloc(self->columns, sizeof *self->value_type); + self->saved_type = cpl_calloc(self->columns, sizeof *self->saved_type); self->native_type = cpl_calloc(self->columns, sizeof *self->native_type); self->naxes = cpl_calloc(self->columns, sizeof *self->naxes); @@ -22970,7 +23322,6 @@ self->tnull = cpl_calloc(self->columns, sizeof *self->tnull); return 0; - } @@ -22984,7 +23335,6 @@ _cpl_table_layout_compare(const cpl_table_layout *self, const cpl_table_layout *other) { - cpl_size icol; @@ -22993,15 +23343,13 @@ } for (icol = 0; icol < self->columns; ++icol) { - if ((strcmp(self->tform[icol], other->tform[icol])) || - (strcmp(self->ttype[icol], other->ttype[icol])) || - (strcmp(self->tunit[icol], other->tunit[icol]))) { + (strcmp(self->ttype[icol], other->ttype[icol])) || + (strcmp(self->tunit[icol], other->tunit[icol]))) { return 1; } if (self->tnull[icol].flag & CPL_NULL_FLAG_IVALUE) { - if (!(other->tnull[icol].flag & CPL_NULL_FLAG_IVALUE)) { return 2; } @@ -23009,40 +23357,32 @@ if (self->tnull[icol].value != other->tnull[icol].value) { return 3; } - } if (self->naxes[icol] != other->naxes[icol]) { return 4; } else if (self->naxes[icol] > 0) { - register cpl_size iaxes; for (iaxes = 0; iaxes < self->naxes[icol]; ++iaxes) { - - LONGLONG *dimensions = self->naxis[icol]; + LONGLONG *dimensions = self->naxis[icol]; LONGLONG *_dimensions = other->naxis[icol]; if (dimensions[iaxes] != _dimensions[iaxes]) { return 5; } - } - } - } return 0; - } inline static cpl_error_code _cpl_table_layout_create(cpl_table_layout *self, const cpl_table *table) { - register int icol; @@ -23052,7 +23392,6 @@ self->rows = cpl_table_get_nrow(table); for (icol = 0; icol < self->columns; ++icol) { - char fmtcode = '\0'; cpl_size rcount = 1; @@ -23065,7 +23404,6 @@ const char *unit = cpl_column_get_unit(column); - self->value_type[icol] = _cpl_columntype_get_valuetype(column_type); self->saved_type[icol] = cpl_column_get_save_type(column); @@ -23074,7 +23412,6 @@ if (_cpl_columntype_is_pointer(column_type)) { - /* * Determine repeat count for the FITS column format description. * This is simply the array length, with the exception of @@ -23098,7 +23435,6 @@ */ if (self->value_type[icol] == CPL_TYPE_STRING) { - register size_t sz = 1; register cpl_size irow; @@ -23107,29 +23443,25 @@ unsigned int bad_rows = 0; const cpl_array **cdata = - cpl_column_get_data_array_const(column); + cpl_column_get_data_array_const(column); for (irow = 0; irow < nrow; ++irow) { - if (cdata[irow] != NULL) { - cpl_size n = cpl_array_get_size(cdata[irow]); const char **s = - cpl_array_get_data_string_const(cdata[irow]); + cpl_array_get_data_string_const(cdata[irow]); sz = CPL_MAX(sz, _cpl_strvlen_max(s, n)); - } else { bad_rows = 1; } - } if (bad_rows) { - self->tnull[icol].flag |= CPL_NULL_FLAG_ARRAY; + self->tnull[icol].flag |= CPL_NULL_FLAG_ARRAY; } self->naxes[icol] = 2; @@ -23138,22 +23470,18 @@ self->naxis[icol][0] = sz; self->naxis[icol][1] = self->depth[icol]; - rcount *= sz; - + rcount *= sz; } else { - int iaxes; self->naxes[icol] = cpl_column_get_dimensions(column); self->naxis[icol] = - cpl_malloc(self->naxes[icol] * sizeof(LONGLONG)); + cpl_malloc(self->naxes[icol] * sizeof(LONGLONG)); for (iaxes = 0; iaxes < self->naxes[icol]; ++iaxes) { - cpl_size sz = cpl_column_get_dimension(column, iaxes); self->naxis[icol][iaxes] = (LONGLONG)sz; - } @@ -23170,7 +23498,6 @@ if ((self->value_type[icol] == CPL_TYPE_INT) || (self->value_type[icol] == CPL_TYPE_LONG_LONG)) { - register int irow; unsigned int flag = 0; unsigned int bad_rows = 0; @@ -23178,7 +23505,7 @@ LONGLONG value = 0; const cpl_array **arrays = - cpl_column_get_data_array_const(column); + cpl_column_get_data_array_const(column); /* @@ -23192,41 +23519,33 @@ */ for (irow = 0; irow < self->rows; ++irow) { - if (arrays[irow]) { - unsigned int _flag = 0; LONGLONG _value = 0; const cpl_column *cdata = - cpl_array_get_column_const(arrays[irow]); + cpl_array_get_column_const(arrays[irow]); _cpl_column_find_null(cdata, self->value_type[icol], self->rows, &_flag, &_value); if (_flag) { - if (!flag) { flag = 1; value = _value; } else { - if (value != _value) { flag = 0; break; } - } - } - } else { bad_rows = 1; } - } @@ -23237,19 +23556,15 @@ */ if (flag) { - - self->tnull[icol].flag = 1; + self->tnull[icol].flag = 1; self->tnull[icol].value = value; if (bad_rows) { - self->tnull[icol].flag |= CPL_NULL_FLAG_ARRAY; + self->tnull[icol].flag |= CPL_NULL_FLAG_ARRAY; } - } - } else { - /* * For floating point data columns, just mark if there * are invalid rows. @@ -23258,15 +23573,10 @@ if (cpl_column_has_invalid(column)) { self->tnull[icol].flag = CPL_NULL_FLAG_ARRAY; } - } - } - } else { - - /* * Dummy values for non-array type columns */ @@ -23283,11 +23593,9 @@ */ if (self->value_type[icol] == CPL_TYPE_STRING) { - const char **s = cpl_column_get_data_string_const(column); rcount = CPL_MAX(1, _cpl_strvlen_max(s, self->rows)); - } @@ -23302,10 +23610,8 @@ */ switch (self->value_type[icol]) { - case CPL_TYPE_INT: - case CPL_TYPE_LONG_LONG: - { + case CPL_TYPE_LONG_LONG: { _cpl_column_find_null(column, self->value_type[icol], self->rows, &self->tnull[icol].flag, &self->tnull[icol].value); @@ -23315,12 +23621,11 @@ case CPL_TYPE_FLOAT: case CPL_TYPE_DOUBLE: case CPL_TYPE_FLOAT_COMPLEX: - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { if (cpl_column_has_invalid(column)) { self->tnull[icol].flag = CPL_NULL_FLAG_FVALUE; self->tnull[icol].mask = - cpl_column_get_data_invalid_const(column); + cpl_column_get_data_invalid_const(column); } break; } @@ -23328,7 +23633,6 @@ default: break; } - } @@ -23338,7 +23642,7 @@ */ self->native_type[icol] = - _cpl_columntype_get_nativetype(self->value_type[icol], NULL); + _cpl_columntype_get_nativetype(self->value_type[icol], NULL); if (self->native_type[icol] == -1) { return cpl_error_set_(CPL_ERROR_UNSPECIFIED); @@ -23347,17 +23651,15 @@ _cpl_columntype_get_nativetype(self->saved_type[icol], &fmtcode); - if(fmtcode == '\0') { + if (fmtcode == '\0') { return cpl_error_set_(CPL_ERROR_UNSPECIFIED); } - self->tform[icol] = cpl_sprintf("%" CPL_SIZE_FORMAT "%c", - rcount, fmtcode); - + self->tform[icol] = + cpl_sprintf("%" CPL_SIZE_FORMAT "%c", rcount, fmtcode); } return CPL_ERROR_NONE; - } @@ -23368,17 +23670,16 @@ inline static cpl_error_code _cpl_table_layout_read(cpl_table_layout *self, fitsfile *ifile) { - - int ic = 0; - int ncol = 0; + int ic = 0; + int ncol = 0; int status = 0; fits_get_num_cols(ifile, &ncol, &status); if (status) { - return cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_get_num_cols, "."); + return cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, status, + fits_get_num_cols, "."); } @@ -23392,11 +23693,10 @@ } - fits_read_btblhdrll(ifile, -1, &self->rows, NULL, self->ttype, - self->tform, self->tunit, NULL, NULL, &status); + fits_read_btblhdrll(ifile, -1, &self->rows, NULL, self->ttype, self->tform, + self->tunit, NULL, NULL, &status); for (ic = 0; ic < ncol; ++ic) { - int _status = 0; char keyname[FLEN_KEYWORD]; @@ -23406,8 +23706,8 @@ LONGLONG width; - fits_get_coltypell(ifile, ic + 1, &self->native_type[ic], - &rcount, &width, &_status); + fits_get_coltypell(ifile, ic + 1, &self->native_type[ic], &rcount, + &width, &_status); if (_status) { status = _status; @@ -23428,8 +23728,8 @@ snprintf(keyname, FLEN_KEYWORD, "TNULL%d", ic); - fits_read_key(ifile, TLONGLONG, keyname, &self->tnull[ic].value, - NULL, &_status); + fits_read_key(ifile, TLONGLONG, keyname, &self->tnull[ic].value, NULL, + &_status); if (_status == 0) { self->tnull[ic].flag = CPL_NULL_FLAG_IVALUE; @@ -23447,7 +23747,6 @@ fits_read_key(ifile, TSTRING, keyname, keyvalue, NULL, &_status); if (_status == 0) { - cpl_size ndim = 0; char *c = keyvalue; @@ -23469,10 +23768,8 @@ status = _status; break; } - } else if (_status == KEY_NO_EXIST) { - if (rcount > 1) { self->naxes[ic] = 1; self->naxis[ic] = cpl_calloc(1, sizeof *self->naxis[ic]); @@ -23482,18 +23779,16 @@ self->naxes[ic] = 0; self->naxis[ic] = NULL; } - } else { status = _status; break; } - } if (status) { - return cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_read_tdimll, "."); + return cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, status, + fits_read_tdimll, "."); } return CPL_ERROR_NONE; @@ -23508,7 +23803,6 @@ inline static cpl_error_code _cpl_table_layout_write(const cpl_table_layout *self, fitsfile *outfile) { - int status = 0; @@ -23516,13 +23810,13 @@ * Create an empty binary FITS table at the end of the output stream */ - fits_create_tbl(outfile, BINARY_TBL, self->rows, self->columns, - self->ttype, self->tform, self->tunit, NULL, &status); + fits_create_tbl(outfile, BINARY_TBL, self->rows, self->columns, self->ttype, + self->tform, self->tunit, NULL, &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_create_tbl, "."); + cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, status, + fits_create_tbl, "."); status = 0; cpl_io_fits_delete_file(outfile, &status); return code; @@ -23535,26 +23829,22 @@ */ for (int icol = 0; icol < self->columns; ++icol) { - if (self->tnull[icol].flag & CPL_NULL_FLAG_IVALUE) { - char keyname[FLEN_KEYWORD]; snprintf(keyname, FLEN_KEYWORD, "TNULL%d", icol + 1); switch (self->value_type[icol]) { - - case CPL_TYPE_INT: - { + case CPL_TYPE_INT: { int ival = self->tnull[icol].value; - fits_write_key(outfile, TINT, keyname, &ival, NULL, &status); + fits_write_key(outfile, TINT, keyname, &ival, NULL, + &status); break; } - case CPL_TYPE_LONG_LONG: - { + case CPL_TYPE_LONG_LONG: { fits_write_key(outfile, TLONGLONG, keyname, &self->tnull[icol].value, NULL, &status); break; @@ -23568,18 +23858,16 @@ */ break; - } if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_key, "."); + cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, status, + fits_write_key, "."); status = 0; cpl_io_fits_delete_file(outfile, &status); return code; } - } @@ -23590,22 +23878,18 @@ */ if (self->naxes[icol] > 1) { - fits_write_tdimll(outfile, icol + 1, self->naxes[icol], self->naxis[icol], &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_tdimll, "."); + cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, status, + fits_write_tdimll, "."); status = 0; cpl_io_fits_delete_file(outfile, &status); return code; } - - } - } @@ -23630,15 +23914,14 @@ if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_flush_file, "."); + cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, status, + fits_flush_file, "."); status = 0; cpl_io_fits_delete_file(outfile, &status); return code; } return CPL_ERROR_NONE; - } @@ -23650,8 +23933,7 @@ inline static cpl_size _cpl_table_save_get_chunksize(fitsfile *outfile, cpl_size nrows) { - - int status = 0; + int status = 0; long _nrows = 0; @@ -23663,16 +23945,18 @@ } return _nrows; - } inline static cpl_error_code -_cpl_table_write_column(fitsfile *outfile, cpl_size trow, - const cpl_column *column, int icol, cpl_size srow, - cpl_size nrows, const cpl_table_layout *layout) +_cpl_table_write_column(fitsfile *outfile, + cpl_size trow, + const cpl_column *column, + int icol, + cpl_size srow, + cpl_size nrows, + const cpl_table_layout *layout) { - int status = 0; @@ -23683,44 +23967,39 @@ */ if ((layout->tnull[icol].flag & CPL_NULL_FLAG_FVALUE) && - !layout->tnull[icol].mask) { - + !layout->tnull[icol].mask) { fits_write_col_null(outfile, icol + 1, trow + 1, 1, nrows, &status); - } else { - - - void *sdata = NULL; + void *sdata = NULL; const void *tdata = NULL; const void *tnull = NULL; const char *null_string = ""; - union { - int ival; - LONGLONG lval; + union + { + int ival; + LONGLONG lval; } null_value; const cpl_column_flag *null_mask = NULL; - - switch (layout->value_type[icol]) { - - case CPL_TYPE_STRING: - { - + + switch (layout->value_type[icol]) { + case CPL_TYPE_STRING: { register cpl_size irow; const char **cdata = - &cpl_column_get_data_string_const(column)[srow]; + &cpl_column_get_data_string_const(column)[srow]; const char **val = cpl_malloc(nrows * sizeof *cdata); sdata = val; for (irow = 0; irow < nrows; ++irow) { - val[irow] = (cdata[irow] == NULL) ? null_string : cdata[irow]; + val[irow] = + (cdata[irow] == NULL) ? null_string : cdata[irow]; } tdata = sdata; @@ -23729,8 +24008,7 @@ break; } - case CPL_TYPE_INT: - { + case CPL_TYPE_INT: { tdata = &cpl_column_get_data_int_const(column)[srow]; if (layout->tnull[icol].flag & CPL_NULL_FLAG_IVALUE) { @@ -23741,10 +24019,8 @@ break; } - case CPL_TYPE_LONG_LONG: - { - tdata = - &cpl_column_get_data_long_long_const(column)[srow]; + case CPL_TYPE_LONG_LONG: { + tdata = &cpl_column_get_data_long_long_const(column)[srow]; if (layout->tnull[icol].flag & CPL_NULL_FLAG_IVALUE) { null_value.lval = layout->tnull[icol].value; @@ -23754,8 +24030,7 @@ break; } - case CPL_TYPE_FLOAT: - { + case CPL_TYPE_FLOAT: { tdata = &cpl_column_get_data_float_const(column)[srow]; if (layout->tnull[icol].flag & CPL_NULL_FLAG_FVALUE) { @@ -23765,8 +24040,7 @@ break; } - case CPL_TYPE_DOUBLE: - { + case CPL_TYPE_DOUBLE: { tdata = &cpl_column_get_data_double_const(column)[srow]; if (layout->tnull[icol].flag & CPL_NULL_FLAG_FVALUE) { @@ -23776,25 +24050,21 @@ break; } - case CPL_TYPE_FLOAT_COMPLEX: - { - + case CPL_TYPE_FLOAT_COMPLEX: { register cpl_size irow; const float complex *cdata = - &cpl_column_get_data_float_complex_const(column)[srow]; + &cpl_column_get_data_float_complex_const(column)[srow]; float *val = cpl_malloc(2 * nrows * sizeof(float)); sdata = val; for (irow = 0; irow < nrows; ++irow) { - register cpl_size i = 2 * irow; - val[i] = crealf(cdata[irow]); + val[i] = crealf(cdata[irow]); val[i + 1] = cimagf(cdata[irow]); - } tdata = sdata; @@ -23806,25 +24076,21 @@ break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { - + case CPL_TYPE_DOUBLE_COMPLEX: { register cpl_size irow; const double complex *cdata = - &cpl_column_get_data_double_complex_const(column)[srow]; + &cpl_column_get_data_double_complex_const(column)[srow]; double *val = cpl_malloc(2 * nrows * sizeof(double)); sdata = val; for (irow = 0; irow < nrows; ++irow) { - register cpl_size i = 2 * irow; - val[i] = creal(cdata[irow]); + val[i] = creal(cdata[irow]); val[i + 1] = cimag(cdata[irow]); - } tdata = sdata; @@ -23836,13 +24102,11 @@ break; } - default: - { + default: { /* This should never be reached! */ return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); break; } - } cpl_fits_write_colnull(outfile, layout->native_type[icol], icol + 1, @@ -23860,24 +24124,19 @@ */ if ((status == 0) && null_mask) { - register cpl_size irow; register cpl_size first = 0; register cpl_size count = 0; for (irow = 0; irow < nrows; ++irow) { - if (null_mask[irow]) { - if (count == 0) { first = irow; } ++count; - } else { - if (count) { fits_write_col_null(outfile, icol + 1, trow + first + 1, 1, count, &status); @@ -23885,42 +24144,39 @@ if (status) { break; } - } count = 0; - } - } if ((status == 0) && count) { - fits_write_col_null(outfile, icol + 1, trow + first + 1, - 1, count, &status); + fits_write_col_null(outfile, icol + 1, trow + first + 1, 1, + count, &status); } - } - } if (status) { - return cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col_null, + return cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, status, + fits_write_col_null, "column=%s, icol=%d, srow=%d, nrows=%d", - cpl_column_get_name(column), - (int)icol, (int)srow, (int)nrows); + cpl_column_get_name(column), (int)icol, + (int)srow, (int)nrows); } return CPL_ERROR_NONE; - } inline static cpl_error_code -_cpl_table_write_column_array(fitsfile *outfile, cpl_size trow, - const cpl_column *column, int icol, cpl_size srow, - cpl_size nrows, const cpl_table_layout *layout) +_cpl_table_write_column_array(fitsfile *outfile, + cpl_size trow, + const cpl_column *column, + int icol, + cpl_size srow, + cpl_size nrows, + const cpl_table_layout *layout) { - int status = 0; cpl_size irow; @@ -23930,25 +24186,24 @@ * Prepare data buffer suitable for CFITSIO calls. */ - void *sdata = NULL; + void *sdata = NULL; const void **tdata = cpl_malloc(nrows * sizeof *tdata); - const void *tnull = NULL; + const void *tnull = NULL; - const cpl_array **arrays = - &cpl_column_get_data_array_const(column)[srow]; + const cpl_array **arrays = &cpl_column_get_data_array_const(column)[srow]; cpl_array *null_array = NULL; const char *null_string = ""; - union { - int ival; - LONGLONG lval; + union + { + int ival; + LONGLONG lval; } null_value; const cpl_column_flag **null_mask = NULL; - const cpl_column_flag array_null = 1; /* Only its address is used! */ - + const cpl_column_flag array_null = 1; /* Only its address is used! */ /* @@ -23964,21 +24219,18 @@ */ if (layout->tnull[icol].flag & CPL_NULL_FLAG_ARRAY) { - null_array = cpl_array_new(layout->depth[icol], - layout->value_type[icol]); + null_array = + cpl_array_new(layout->depth[icol], layout->value_type[icol]); } switch (layout->value_type[icol]) { - - case CPL_TYPE_STRING: - { - + case CPL_TYPE_STRING: { register cpl_size _irow; cpl_size depth = layout->depth[icol]; - const char **values = cpl_malloc(nrows * depth * - sizeof(const char *)); + const char **values = + cpl_malloc(nrows * depth * sizeof(const char *)); void *_null_array = NULL; @@ -23986,16 +24238,12 @@ tnull = null_string; if (null_array) { - - cpl_array_fill_window_string(null_array, 0, depth, - null_string); + cpl_array_fill_window_string(null_array, 0, depth, null_string); _null_array = cpl_array_get_data_string(null_array); - } for (_irow = 0; _irow < nrows; ++_irow) { - register cpl_size ival; register cpl_size stride = _irow * depth; @@ -24010,29 +24258,23 @@ } if ((cdata == _null_array) || - !cpl_array_has_invalid(arrays[_irow])) { + !cpl_array_has_invalid(arrays[_irow])) { memcpy(&values[stride], cdata, depth * sizeof *cdata); } else { - for (ival = 0; ival < depth; ++ival) { values[stride + ival] = - cdata[ival] == NULL ? null_string : cdata[ival]; + cdata[ival] == NULL ? null_string : cdata[ival]; } - } tdata[_irow] = &values[stride]; - } break; - } - case CPL_TYPE_INT: - { - + case CPL_TYPE_INT: { if (layout->tnull[icol].flag & CPL_NULL_FLAG_IVALUE) { null_value.ival = layout->tnull[icol].value; tnull = &null_value.ival; @@ -24040,7 +24282,6 @@ if (null_array) { - register cpl_size _irow; void *_null_array = cpl_array_get_data_int(null_array); @@ -24053,35 +24294,26 @@ } for (_irow = 0; _irow < nrows; ++_irow) { - if (arrays[_irow]) { tdata[_irow] = - cpl_array_get_data_int_const(arrays[_irow]); + cpl_array_get_data_int_const(arrays[_irow]); } else { tdata[_irow] = _null_array; } - } - } else { - register cpl_size _irow; for (_irow = 0; _irow < nrows; ++_irow) { - tdata[_irow] = - cpl_array_get_data_int_const(arrays[_irow]); + tdata[_irow] = cpl_array_get_data_int_const(arrays[_irow]); } - } break; - } - case CPL_TYPE_LONG_LONG: - { - + case CPL_TYPE_LONG_LONG: { if (layout->tnull[icol].flag & CPL_NULL_FLAG_IVALUE) { null_value.lval = layout->tnull[icol].value; tnull = &null_value.lval; @@ -24089,7 +24321,6 @@ if (null_array) { - register cpl_size _irow; void *_null_array = cpl_array_get_data_long_long(null_array); @@ -24102,35 +24333,27 @@ } for (_irow = 0; _irow < nrows; ++_irow) { - if (arrays[_irow]) { tdata[_irow] = - cpl_array_get_data_long_long_const(arrays[_irow]); + cpl_array_get_data_long_long_const(arrays[_irow]); } else { tdata[_irow] = _null_array; } - } - } else { - register cpl_size _irow; for (_irow = 0; _irow < nrows; ++_irow) { tdata[_irow] = - cpl_array_get_data_long_long_const(arrays[_irow]); + cpl_array_get_data_long_long_const(arrays[_irow]); } - } break; - } - case CPL_TYPE_FLOAT: - { - + case CPL_TYPE_FLOAT: { register cpl_size _irow; void *_null_array = NULL; @@ -24143,32 +24366,23 @@ } for (_irow = 0; _irow < nrows; ++_irow) { - if (arrays[_irow]) { - const cpl_column *cdata = - cpl_array_get_column_const(arrays[_irow]); + cpl_array_get_column_const(arrays[_irow]); - tdata[_irow] = - cpl_column_get_data_float_const(cdata); + tdata[_irow] = cpl_column_get_data_float_const(cdata); - null_mask[_irow] = - cpl_column_get_data_invalid_const(cdata); + null_mask[_irow] = cpl_column_get_data_invalid_const(cdata); } else { - tdata[_irow] = _null_array; + tdata[_irow] = _null_array; null_mask[_irow] = &array_null; - } - } break; - } - case CPL_TYPE_DOUBLE: - { - + case CPL_TYPE_DOUBLE: { register cpl_size _irow; void *_null_array = NULL; @@ -24181,33 +24395,23 @@ } for (_irow = 0; _irow < nrows; ++_irow) { - if (arrays[_irow]) { - const cpl_column *cdata = - cpl_array_get_column_const(arrays[_irow]); + cpl_array_get_column_const(arrays[_irow]); - tdata[_irow] = - cpl_column_get_data_double_const(cdata); + tdata[_irow] = cpl_column_get_data_double_const(cdata); - null_mask[_irow] = - cpl_column_get_data_invalid_const(cdata); + null_mask[_irow] = cpl_column_get_data_invalid_const(cdata); } else { - - tdata[_irow] = _null_array; + tdata[_irow] = _null_array; null_mask[_irow] = &array_null; - } - } break; - } - case CPL_TYPE_FLOAT_COMPLEX: - { - + case CPL_TYPE_FLOAT_COMPLEX: { register cpl_size _irow; register cpl_size depth = layout->depth[icol]; @@ -24225,48 +24429,39 @@ } for (_irow = 0; _irow < nrows; ++_irow) { - register cpl_size ival; register cpl_size stride = 2 * _irow * depth; const float complex *cdata = NULL; if (arrays[_irow]) { - const cpl_column *_cdata = - cpl_array_get_column_const(arrays[_irow]); + cpl_array_get_column_const(arrays[_irow]); cdata = cpl_column_get_data_float_complex_const(_cdata); null_mask[_irow] = - cpl_column_get_data_invalid_const(_cdata); - + cpl_column_get_data_invalid_const(_cdata); } else { - cdata = _null_array; + cdata = _null_array; null_mask[_irow] = &array_null; } for (ival = 0; ival < depth; ++ival) { - register cpl_size i = 2 * ival + stride; - values[i] = crealf(cdata[ival]); + values[i] = crealf(cdata[ival]); values[i + 1] = cimagf(cdata[ival]); - } tdata[_irow] = &values[stride]; - } break; - } - case CPL_TYPE_DOUBLE_COMPLEX: - { - + case CPL_TYPE_DOUBLE_COMPLEX: { register cpl_size _irow; register cpl_size depth = layout->depth[icol]; @@ -24284,7 +24479,6 @@ } for (_irow = 0; _irow < nrows; ++_irow) { - register cpl_size ival; register cpl_size stride = 2 * _irow * depth; @@ -24292,40 +24486,33 @@ if (arrays[_irow]) { - const cpl_column *_cdata = - cpl_array_get_column_const(arrays[_irow]); + cpl_array_get_column_const(arrays[_irow]); cdata = cpl_column_get_data_double_complex_const(_cdata); null_mask[_irow] = - cpl_column_get_data_invalid_const(_cdata); - + cpl_column_get_data_invalid_const(_cdata); } else { - cdata = _null_array; + cdata = _null_array; null_mask[_irow] = &array_null; } for (ival = 0; ival < depth; ++ival) { - register cpl_size i = 2 * ival + stride; - values[i] = creal(cdata[ival]); + values[i] = creal(cdata[ival]); values[i + 1] = cimag(cdata[ival]); - } tdata[_irow] = &values[stride]; - } break; - } - default: - { + default: { /* This should never be reached! */ if (null_array) { @@ -24336,16 +24523,13 @@ return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); break; } - } for (irow = 0; irow < nrows; ++irow) { - cpl_fits_write_colnull(outfile, layout->native_type[icol], icol + 1, trow + irow + 1, 1, layout->depth[icol], tdata[irow], tnull, &status); - } @@ -24360,12 +24544,10 @@ */ if ((status == 0) && null_mask) { - register cpl_size _irow; register cpl_size depth = layout->depth[icol]; for (_irow = 0; _irow < nrows; ++_irow) { - const cpl_column_flag *_null_mask = null_mask[_irow]; if (_null_mask == &array_null) { @@ -24373,24 +24555,19 @@ depth, &status); } else if (_null_mask != NULL) { - register cpl_size ival; register cpl_size first = 0; register cpl_size count = 0; for (ival = 0; ival < depth; ++ival) { - if (_null_mask[ival]) { - if (count == 0) { first = ival; } ++count; - } else { - if (count) { fits_write_col_null(outfile, icol + 1, trow + _irow + 1, first + 1, @@ -24399,24 +24576,18 @@ if (status) { break; } - } count = 0; - } - } if ((status == 0) && count) { fits_write_col_null(outfile, icol + 1, trow + _irow + 1, first + 1, count, &status); } - } - } - } @@ -24440,23 +24611,22 @@ if (status) { - return cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col_null, + return cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, status, + fits_write_col_null, "column=%s, icol=%d, srow=%d, nrows=%d", - cpl_column_get_name(column), - (int)icol, (int)srow, (int)nrows); + cpl_column_get_name(column), (int)icol, + (int)srow, (int)nrows); } return CPL_ERROR_NONE; - } inline static cpl_error_code -_cpl_table_save_extend(const cpl_table *table, fitsfile *outfile, +_cpl_table_save_extend(const cpl_table *table, + fitsfile *outfile, const cpl_propertylist *header) { - cpl_table_layout layout; cpl_size cstart, csize; @@ -24467,10 +24637,8 @@ _cpl_table_layout_create(&layout, table); if (!cpl_errorstate_is_equal(error_state)) { - _cpl_table_layout_clear(&layout); return cpl_error_set_where_(); - } @@ -24485,10 +24653,8 @@ _cpl_table_layout_write(&layout, outfile); if (!cpl_errorstate_is_equal(error_state)) { - _cpl_table_layout_clear(&layout); return cpl_error_set_where_(); - } @@ -24497,11 +24663,8 @@ */ if (header) { - - const char *ignore_keys = "^(" ERASE_WCS_REGEXP ")$|" - CPL_FITS_BADKEYS_EXT "|" CPL_FITS_COMPRKEYS; - - if (cpl_fits_add_properties(outfile, header, ignore_keys)) { + if (cpl_fits_add_properties(outfile, header, CPL_IO_WCS | CPL_IO_EXTEND, + CPL_FALSE)) { int status = 0; (void)cpl_io_fits_delete_file(outfile, &status); return cpl_error_set_message_(CPL_ERROR_FILE_NOT_CREATED, @@ -24522,7 +24685,6 @@ error_state = cpl_errorstate_get(); for (cstart = 0; cstart < layout.rows; cstart += csize) { - cpl_size icol; @@ -24536,7 +24698,6 @@ } for (icol = 0; icol < layout.columns; ++icol) { - const cpl_column *column = table->columns[icol]; @@ -24545,32 +24706,26 @@ cstart, csize, &layout); } else { - _cpl_table_write_column(outfile, cstart, column, icol, - cstart, csize, &layout); + _cpl_table_write_column(outfile, cstart, column, icol, cstart, + csize, &layout); } - } - } if (!cpl_errorstate_is_equal(error_state)) { - _cpl_table_layout_clear(&layout); return cpl_error_set_where_(); - } _cpl_table_layout_clear(&layout); return CPL_ERROR_NONE; - } inline static cpl_error_code _cpl_table_save_append(const cpl_table *table, fitsfile *outfile) { - cpl_table_layout layout; cpl_table_layout _layout; cpl_size cstart, csize; @@ -24581,11 +24736,9 @@ _cpl_table_layout_create(&layout, table); if (!cpl_errorstate_is_equal(error_state)) { - _cpl_table_layout_clear(&layout); return cpl_error_set_where_(); - } @@ -24597,21 +24750,17 @@ _cpl_table_layout_read(&_layout, outfile); if (!cpl_errorstate_is_equal(error_state)) { - _cpl_table_layout_clear(&_layout); _cpl_table_layout_clear(&layout); return cpl_error_set_where_(); - } if (_cpl_table_layout_compare(&layout, &_layout) != 0) { - _cpl_table_layout_clear(&_layout); _cpl_table_layout_clear(&layout); return cpl_error_set_(CPL_ERROR_INCOMPATIBLE_INPUT); - } /* @@ -24626,7 +24775,6 @@ error_state = cpl_errorstate_get(); for (cstart = 0; cstart < layout.rows; cstart += csize) { - cpl_size icol; @@ -24640,7 +24788,6 @@ } for (icol = 0; icol < layout.columns; ++icol) { - const cpl_column *column = table->columns[icol]; @@ -24650,29 +24797,23 @@ &layout); } else { - _cpl_table_write_column(outfile, _layout.rows + cstart, - column, icol, cstart, csize, - &layout); + _cpl_table_write_column(outfile, _layout.rows + cstart, column, + icol, cstart, csize, &layout); } - } - } if (!cpl_errorstate_is_equal(error_state)) { - _cpl_table_layout_clear(&_layout); _cpl_table_layout_clear(&layout); return cpl_error_set_where_(); - } _cpl_table_layout_clear(&_layout); _cpl_table_layout_clear(&layout); return CPL_ERROR_NONE; - } @@ -24806,11 +24947,12 @@ */ static cpl_error_code -_cpl_table_save(const cpl_table *table, const cpl_propertylist *pheader, - const cpl_propertylist *header, const char *filename, +_cpl_table_save(const cpl_table *table, + const cpl_propertylist *pheader, + const cpl_propertylist *header, + const char *filename, unsigned int mode) { - fitsfile *outfile = NULL; int extend = TRUE; @@ -24819,7 +24961,6 @@ cpl_errorstate error_state; - if (table == NULL || filename == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } @@ -24833,11 +24974,9 @@ */ if (access(filename, F_OK) == 0) { - if (access(filename, W_OK) != 0) { return cpl_error_set_(CPL_ERROR_FILE_NOT_CREATED); } - } @@ -24853,8 +24992,8 @@ if (status) { return cpl_error_set_message_(CPL_ERROR_FILE_NOT_CREATED, - "filename='%s', mode=%d", - filename, mode); + "filename='%s', mode=%d", filename, + mode); } @@ -24866,31 +25005,25 @@ */ if (pheader) { - if (fits_create_img(outfile, SHORT_IMG, 0, NULL, &status)) { - return cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_create_img, - "filename='%s', mode=%d", - filename, mode); + return cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, status, + fits_create_img, + "filename='%s', mode=%d", filename, + mode); } fits_write_date(outfile, &status); - if (cpl_fits_add_properties(outfile, pheader, "^(" - ERASE_WCS_REGEXP ")$|" - CPL_FITS_BADKEYS_PRIM "|" - CPL_FITS_COMPRKEYS)) { + if (cpl_fits_add_properties(outfile, pheader, mode | CPL_IO_WCS, + CPL_FALSE)) { (void)cpl_io_fits_delete_file(outfile, &status); return cpl_error_set_message_(CPL_ERROR_FILE_NOT_CREATED, "filename='%s', mode=%d", filename, mode); } - } - } else if (mode & CPL_IO_EXTEND) { - /* * The file must exist, and must be writable. */ @@ -24904,15 +25037,12 @@ } if (cpl_io_fits_open_diskfile(&outfile, filename, READWRITE, &status)) { - return cpl_error_set_message_(CPL_ERROR_FILE_NOT_CREATED, - "filename='%s', mode=%d", - filename, mode); + "filename='%s', mode=%d", filename, + mode); } - } else if (mode & CPL_IO_APPEND) { - int nhdu = 0; int hdu_type; @@ -24931,10 +25061,9 @@ } if (cpl_io_fits_open_diskfile(&outfile, filename, READWRITE, &status)) { - return cpl_error_set_message_(CPL_ERROR_FILE_NOT_CREATED, - "filename='%s', mode=%d", - filename, mode); + "filename='%s', mode=%d", filename, + mode); } fits_get_num_hdus(outfile, &nhdu, &status); @@ -24942,9 +25071,8 @@ if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, - status, fits_movabs_hdu, - "filename='%s', mode=%d", + cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, status, + fits_movabs_hdu, "filename='%s', mode=%d", filename, mode); status = 0; cpl_io_fits_delete_file(outfile, &status); @@ -24952,12 +25080,9 @@ } extend = FALSE; - } else { - return cpl_error_set_(CPL_ERROR_UNSUPPORTED_MODE); - } @@ -24995,9 +25120,8 @@ if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_date, - "filename='%s', mode=%d", + cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, status, + fits_write_date, "filename='%s', mode=%d", filename, mode); status = 0; cpl_io_fits_delete_file(outfile, &status); @@ -25009,18 +25133,16 @@ * Cleanup */ - cpl_io_fits_close_file(outfile, &status); - - if (status) { - status = 0; - (void)cpl_io_fits_delete_file(outfile, &status); - return cpl_error_set_message_(CPL_ERROR_FILE_NOT_CREATED, - "filename='%s', mode=%d", - filename, mode); - } + cpl_io_fits_close_file(outfile, &status); - return CPL_ERROR_NONE; + if (status) { + status = 0; + (void)cpl_io_fits_delete_file(outfile, &status); + return cpl_error_set_message_(CPL_ERROR_FILE_NOT_CREATED, + "filename='%s', mode=%d", filename, mode); + } + return CPL_ERROR_NONE; } @@ -25031,60 +25153,57 @@ const char *filename, unsigned mode) { + cpl_errorstate prestate = cpl_errorstate_get(); + cpl_size depth; + cpl_size dimensions; + cpl_array **arrays; + cpl_column *acolumn; + + cpl_column **column; + fitsfile *outfile; - cpl_errorstate prestate = cpl_errorstate_get(); - cpl_size depth; - cpl_size dimensions; - - cpl_array **arrays; - cpl_column *acolumn; - - cpl_column **column; - fitsfile *outfile; - - cpl_size nc = cpl_table_get_ncol(table); - cpl_size nr = cpl_table_get_nrow(table); - cpl_size bwidth; - cpl_size field_size = 1; - cpl_size j, k, z; - int i; - int *found; - cpl_size *nb; - cpl_size count; - cpl_size chunk, spell; - long optimal_nrows; - cpl_size fcount = 0; - - long long *nval; - - int *idata; - short int *sidata; - long long *lldata; - float *fdata; - double *ddata; - float complex *cfdata; - double complex *cddata; - const char **sdata; - cpl_column_flag *ndata; - const char *nstring; - char *sval; - char *bdata; - unsigned char *ubdata; - - const char **tunit; - const char **ttype; - const char **tform; - char tnull[FLEN_KEYWORD]; + cpl_size nc = cpl_table_get_ncol(table); + cpl_size nr = cpl_table_get_nrow(table); + cpl_size bwidth; + cpl_size field_size = 1; + cpl_size j, k, z; + int i; + int *found; + cpl_size *nb; + cpl_size count; + cpl_size chunk, spell; + long optimal_nrows; + cpl_size fcount = 0; + + long long *nval; + + int *idata; + short int *sidata; + long long *lldata; + float *fdata; + double *ddata; + float complex *cfdata; + double complex *cddata; + const char **sdata; + cpl_column_flag *ndata; + const char *nstring; + char *sval; + char *bdata; + unsigned char *ubdata; + + const char **tunit; + const char **ttype; + const char **tform; + char tnull[FLEN_KEYWORD]; - int status = 0; + int status = 0; if (table == NULL || filename == NULL) return cpl_error_set_(CPL_ERROR_NULL_INPUT); if (mode & CPL_IO_EXTEND) { - /* * The file must exist, and must be writable. */ @@ -25097,13 +25216,11 @@ if (cpl_io_fits_open_diskfile(&outfile, filename, READWRITE, &status)) { return cpl_error_set_message_(CPL_ERROR_FILE_NOT_CREATED, - "filename='%s', mode=%d", - filename, mode); + "filename='%s', mode=%d", filename, + mode); } - } else if (mode & CPL_IO_CREATE) { - /* * If the file exists, it must be (over)writable. */ @@ -25114,13 +25231,14 @@ } #ifdef CPL_TABLE_DFS04866 else { - cpl_io_fits_open_diskfile(&outfile, filename, READWRITE, &status); + cpl_io_fits_open_diskfile(&outfile, filename, READWRITE, + &status); if (status == 0) { cpl_io_fits_delete_file(outfile, &status); if (status) { - return cpl_error_set_message_(CPL_ERROR_FILE_NOT_CREATED, - "filename='%s', mode=%d", - filename, mode); + return cpl_error_set_message_( + CPL_ERROR_FILE_NOT_CREATED, + "filename='%s', mode=%d", filename, mode); } } status = 0; @@ -25133,29 +25251,26 @@ cpl_free(sval); if (status) { return cpl_error_set_message_(CPL_ERROR_FILE_NOT_CREATED, - "filename='%s', mode=%d", - filename, mode); + "filename='%s', mode=%d", filename, + mode); } if (pheader) { - /* * Write property list to primary FITS header */ if (fits_create_img(outfile, SHORT_IMG, 0, NULL, &status)) { - return cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_create_img, - "filename='%s', mode=%d", - filename, mode); + return cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, status, + fits_create_img, + "filename='%s', mode=%d", filename, + mode); } fits_write_date(outfile, &status); - if (cpl_fits_add_properties(outfile, pheader, "^(" - ERASE_WCS_REGEXP ")$|" - CPL_FITS_BADKEYS_PRIM "|" - CPL_FITS_COMPRKEYS)) { + if (cpl_fits_add_properties(outfile, pheader, mode | CPL_IO_WCS, + CPL_FALSE)) { (void)cpl_io_fits_delete_file(outfile, &status); return cpl_error_set_message_(CPL_ERROR_FILE_NOT_CREATED, "filename='%s', mode=%d", @@ -25184,7 +25299,6 @@ tunit = cpl_calloc(nc, sizeof(char *)); for (i = 0; i < nc; i++, column++) { - cpl_type column_type = cpl_column_get_type(*column); depth = cpl_table_get_column_depth(table, cpl_column_get_name(*column)); @@ -25204,11 +25318,8 @@ } if (_cpl_columntype_is_pointer(column_type)) { - switch (_cpl_columntype_get_valuetype(column_type)) { - - case CPL_TYPE_STRING: - { + case CPL_TYPE_STRING: { /* * A new kind of "depth" needs to be defined. * If an element of a table is an array of strings, @@ -25255,31 +25366,28 @@ break; } - case CPL_TYPE_INT: - { + case CPL_TYPE_INT: { if (depth > 0) { - switch (cpl_column_get_save_type(*column)) { - case CPL_TYPE_BOOL: - tform[i] = cpl_sprintf("%" CPL_SIZE_FORMAT "L", - depth); + tform[i] = + cpl_sprintf("%" CPL_SIZE_FORMAT "L", depth); break; case CPL_TYPE_CHAR: - tform[i] = cpl_sprintf("%" CPL_SIZE_FORMAT "S", - depth); + tform[i] = + cpl_sprintf("%" CPL_SIZE_FORMAT "S", depth); break; case CPL_TYPE_UCHAR: - tform[i] = cpl_sprintf("%" CPL_SIZE_FORMAT "B", - depth); + tform[i] = + cpl_sprintf("%" CPL_SIZE_FORMAT "B", depth); break; case CPL_TYPE_SHORT: - tform[i] = cpl_sprintf("%" CPL_SIZE_FORMAT "I", - depth); + tform[i] = + cpl_sprintf("%" CPL_SIZE_FORMAT "I", depth); break; default: - tform[i] = cpl_sprintf("%" CPL_SIZE_FORMAT "J", - depth); + tform[i] = + cpl_sprintf("%" CPL_SIZE_FORMAT "J", depth); } nb[i] = depth; @@ -25294,39 +25402,35 @@ break; } - case CPL_TYPE_LONG_LONG: - { + case CPL_TYPE_LONG_LONG: { if (depth > 0) { - switch (cpl_column_get_save_type(*column)) { - case CPL_TYPE_BOOL: - tform[i] = cpl_sprintf("%" CPL_SIZE_FORMAT "L", - depth); + tform[i] = + cpl_sprintf("%" CPL_SIZE_FORMAT "L", depth); break; case CPL_TYPE_CHAR: - tform[i] = cpl_sprintf("%" CPL_SIZE_FORMAT "S", - depth); + tform[i] = + cpl_sprintf("%" CPL_SIZE_FORMAT "S", depth); break; case CPL_TYPE_UCHAR: - tform[i] = cpl_sprintf("%" CPL_SIZE_FORMAT "B", - depth); + tform[i] = + cpl_sprintf("%" CPL_SIZE_FORMAT "B", depth); break; case CPL_TYPE_SHORT: - tform[i] = cpl_sprintf("%" CPL_SIZE_FORMAT "I", - depth); + tform[i] = + cpl_sprintf("%" CPL_SIZE_FORMAT "I", depth); break; case CPL_TYPE_INT: - tform[i] = cpl_sprintf("%" CPL_SIZE_FORMAT "J", - depth); + tform[i] = + cpl_sprintf("%" CPL_SIZE_FORMAT "J", depth); break; default: - tform[i] = cpl_sprintf("%" CPL_SIZE_FORMAT "K", - depth); + tform[i] = + cpl_sprintf("%" CPL_SIZE_FORMAT "K", depth); break; } nb[i] = depth; - } else { cpl_error_set_(CPL_ERROR_ILLEGAL_OUTPUT); @@ -25334,10 +25438,8 @@ break; } - case CPL_TYPE_FLOAT: - { + case CPL_TYPE_FLOAT: { if (depth > 0) { - tform[i] = cpl_sprintf("%" CPL_SIZE_FORMAT "E", depth); nb[i] = depth; } @@ -25347,8 +25449,7 @@ break; } - case CPL_TYPE_DOUBLE: - { + case CPL_TYPE_DOUBLE: { if (depth > 0) { tform[i] = cpl_sprintf("%" CPL_SIZE_FORMAT "D", depth); nb[i] = depth; @@ -25359,10 +25460,8 @@ break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { if (depth > 0) { - tform[i] = cpl_sprintf("%" CPL_SIZE_FORMAT "C", depth); nb[i] = 2 * depth; } @@ -25372,8 +25471,7 @@ break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { if (depth > 0) { tform[i] = cpl_sprintf("%" CPL_SIZE_FORMAT "M", depth); nb[i] = 2 * depth; @@ -25384,20 +25482,18 @@ break; } - default: - { - + default: { /* FIXME: No unit test coverage here... */ cpl_free(nb); for (i = 0; i < nc; i++) { CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); - cpl_free((void*)tform[i]); + cpl_free((void *)tform[i]); CPL_DIAG_PRAGMA_POP; } - cpl_free((void*)tform); + cpl_free((void *)tform); (void)cpl_io_fits_delete_file(outfile, &status); return cpl_error_set_message_(CPL_ERROR_UNSPECIFIED, @@ -25405,18 +25501,12 @@ filename, mode); break; } - } - } else { - switch (_cpl_columntype_get_valuetype(column_type)) { - - case CPL_TYPE_INT: - { + case CPL_TYPE_INT: { switch (cpl_column_get_save_type(*column)) { - case CPL_TYPE_BOOL: tform[i] = cpl_strdup("1L"); break; @@ -25447,10 +25537,8 @@ break; } - case CPL_TYPE_LONG_LONG: - { + case CPL_TYPE_LONG_LONG: { switch (cpl_column_get_save_type(*column)) { - case CPL_TYPE_BOOL: tform[i] = cpl_strdup("1L"); break; @@ -25475,36 +25563,31 @@ break; } - case CPL_TYPE_FLOAT: - { + case CPL_TYPE_FLOAT: { tform[i] = cpl_strdup("1E"); nb[i] = 1; break; } - case CPL_TYPE_DOUBLE: - { + case CPL_TYPE_DOUBLE: { tform[i] = cpl_strdup("1D"); nb[i] = 1; break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { tform[i] = cpl_strdup("1C"); nb[i] = 2; break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { tform[i] = cpl_strdup("1M"); nb[i] = 2; break; } - case CPL_TYPE_STRING: - { + case CPL_TYPE_STRING: { /* * Determine the longest string in column. */ @@ -25527,18 +25610,17 @@ break; } - default: - { + default: { /* FIXME: No unit test coverage here... */ cpl_free(nb); for (i = 0; i < nc; i++) { CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); - cpl_free((void*)tform[i]); + cpl_free((void *)tform[i]); CPL_DIAG_PRAGMA_POP; } - cpl_free((void*)tform); + cpl_free((void *)tform); (void)cpl_io_fits_delete_file(outfile, &status); return cpl_error_set_message_(CPL_ERROR_UNSPECIFIED, @@ -25546,37 +25628,33 @@ filename, mode); break; } - } - } bwidth += nb[i]; - } if (cpl_errorstate_is_equal(prestate)) { - cpl_fits_create_tbl(outfile, BINARY_TBL, nr, nc, - ttype, tform, tunit, NULL, &status); + cpl_fits_create_tbl(outfile, BINARY_TBL, nr, nc, ttype, tform, tunit, + NULL, &status); } for (i = 0; i < nc; i++) { CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); - cpl_free((void*)tform[i]); + cpl_free((void *)tform[i]); CPL_DIAG_PRAGMA_POP; } - cpl_free((void*)tform); - cpl_free((void*)ttype); - cpl_free((void*)tunit); + cpl_free((void *)tform); + cpl_free((void *)ttype); + cpl_free((void *)tunit); if (!cpl_errorstate_is_equal(prestate)) return cpl_error_set_where_(); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_create_tbl, - "filename='%s', mode=%d", + cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, status, + fits_create_tbl, "filename='%s', mode=%d", filename, mode); status = 0; cpl_io_fits_delete_file(outfile, &status); @@ -25598,7 +25676,6 @@ column = table->columns; for (i = 0; i < nc; i++, column++) { - cpl_type column_type = cpl_column_get_type(*column); depth = cpl_table_get_column_depth(table, cpl_column_get_name(*column)); @@ -25613,11 +25690,8 @@ */ if (_cpl_columntype_is_pointer(column_type)) { - switch (_cpl_columntype_get_valuetype(column_type)) { - - case CPL_TYPE_INT: - { + case CPL_TYPE_INT: { arrays = cpl_column_get_data_array(*column); for (j = 0; j < nr; j++) { @@ -25668,11 +25742,11 @@ */ if (found[i]) { - int inval = (int)nval[i]; sprintf(tnull, "TNULL%d", i + 1); - fits_write_key(outfile, TINT, tnull, &inval, NULL, &status); + fits_write_key(outfile, TINT, tnull, &inval, NULL, + &status); if (status) { const cpl_error_code code = @@ -25692,13 +25766,13 @@ break; } - case CPL_TYPE_LONG_LONG: - { + case CPL_TYPE_LONG_LONG: { arrays = cpl_column_get_data_array(*column); for (j = 0; j < nr; j++) { if (arrays[j] == NULL) { - arrays[j] = cpl_array_new(depth, CPL_TYPE_LONG_LONG); + arrays[j] = + cpl_array_new(depth, CPL_TYPE_LONG_LONG); } acolumn = cpl_array_get_column(arrays[j]); @@ -25744,8 +25818,7 @@ */ if (found[i]) { - - long long llnval = nval[i]; /* for consistency only! */ + long long llnval = nval[i]; /* for consistency only! */ sprintf(tnull, "TNULL%d", i + 1); fits_write_key(outfile, TLONGLONG, tnull, &llnval, NULL, @@ -25771,18 +25844,12 @@ default: break; - } - } else { - switch (_cpl_columntype_get_valuetype(column_type)) { - - case CPL_TYPE_INT: - { + case CPL_TYPE_INT: { if (cpl_column_has_invalid(*column)) { - idata = cpl_column_get_data_int(*column); ndata = cpl_column_get_data_invalid(*column); @@ -25823,11 +25890,11 @@ */ if (found[i]) { - int inval = (int)nval[i]; sprintf(tnull, "TNULL%d", i + 1); - fits_write_key(outfile, TINT, tnull, &inval, NULL, &status); + fits_write_key(outfile, TINT, tnull, &inval, NULL, + &status); if (status) { const cpl_error_code code = @@ -25847,10 +25914,8 @@ break; } - case CPL_TYPE_LONG_LONG: - { + case CPL_TYPE_LONG_LONG: { if (cpl_column_has_invalid(*column)) { - lldata = cpl_column_get_data_long_long(*column); ndata = cpl_column_get_data_invalid(*column); @@ -25892,8 +25957,7 @@ */ if (found[i]) { - - long long llnval = nval[i]; /* for consistency only! */ + long long llnval = nval[i]; /* for consistency only! */ sprintf(tnull, "TNULL%d", i + 1); fits_write_key(outfile, TLONGLONG, tnull, &llnval, NULL, @@ -25919,9 +25983,7 @@ default: break; - } - } @@ -25930,131 +25992,126 @@ */ if (_cpl_columntype_is_pointer(column_type)) { - switch (_cpl_columntype_get_valuetype(column_type)) { + case CPL_TYPE_INT: + case CPL_TYPE_LONG_LONG: + case CPL_TYPE_FLOAT: + case CPL_TYPE_DOUBLE: + case CPL_TYPE_FLOAT_COMPLEX: + case CPL_TYPE_DOUBLE_COMPLEX: - case CPL_TYPE_INT: - case CPL_TYPE_LONG_LONG: - case CPL_TYPE_FLOAT: - case CPL_TYPE_DOUBLE: - case CPL_TYPE_FLOAT_COMPLEX: - case CPL_TYPE_DOUBLE_COMPLEX: - - dimensions = cpl_column_get_dimensions(*column); + dimensions = cpl_column_get_dimensions(*column); - if (dimensions > 1) { - cpl_size *naxes = cpl_malloc(dimensions * sizeof(cpl_size)); + if (dimensions > 1) { + cpl_size *naxes = + cpl_malloc(dimensions * sizeof(cpl_size)); - for (z = 0; z < dimensions; z++) - naxes[z] = cpl_column_get_dimension(*column, z); + for (z = 0; z < dimensions; z++) + naxes[z] = cpl_column_get_dimension(*column, z); - /* + /* * Note the cast to int, to prevent compiler warnings. * Naturally "dimensions" is a size, so it should be * of type cpl_size. However in cfitsio is int. */ - { - /*FIXME: debug purpose only. + { + /*FIXME: debug purpose only. * Compatibility with cpl_size = int. */ - LONGLONG *longnaxes = cpl_malloc(dimensions * - sizeof(LONGLONG)); - int t; + LONGLONG *longnaxes = + cpl_malloc(dimensions * sizeof(LONGLONG)); + int t; - for (t = 0; t < dimensions; t++) { - longnaxes[t] = (LONGLONG)naxes[t]; - } + for (t = 0; t < dimensions; t++) { + longnaxes[t] = (LONGLONG)naxes[t]; + } - fits_write_tdimll(outfile, i + 1, (int)dimensions, - longnaxes, &status); + fits_write_tdimll(outfile, i + 1, (int)dimensions, + longnaxes, &status); - cpl_free(longnaxes); + cpl_free(longnaxes); + } - } + if (status) { + const cpl_error_code code = + cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, + status, fits_write_tdimll, + "filename='%s', mode=%d", + filename, mode); + status = 0; + cpl_io_fits_delete_file(outfile, &status); + cpl_free(found); + cpl_free(nval); + cpl_free(nb); + return code; + } - if (status) { - const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_tdimll, - "filename='%s', mode=%d", - filename, mode); - status = 0; - cpl_io_fits_delete_file(outfile, &status); - cpl_free(found); - cpl_free(nval); - cpl_free(nb); - return code; + cpl_free(naxes); } - cpl_free(naxes); - } - - break; + break; - case CPL_TYPE_STRING: + case CPL_TYPE_STRING: - /* + /* * In the TDIM keyword will have to be written the total number * of characters for each string field, field_size, and the * number of fields for one table element, depth. */ - { - cpl_size *naxes = cpl_malloc(2 * sizeof(cpl_size)); + { + cpl_size *naxes = cpl_malloc(2 * sizeof(cpl_size)); - naxes[0] = field_size; - naxes[1] = depth; + naxes[0] = field_size; + naxes[1] = depth; - { - /*FIXME: debug purpose only. + { + /*FIXME: debug purpose only. * Compatibility with cpl_size = int. */ - LONGLONG *longnaxes = cpl_malloc(2 * sizeof(LONGLONG)); - int t; + LONGLONG *longnaxes = + cpl_malloc(2 * sizeof(LONGLONG)); + int t; - for (t = 0; t < 2; t++) { - longnaxes[t] = (LONGLONG)naxes[t]; - } + for (t = 0; t < 2; t++) { + longnaxes[t] = (LONGLONG)naxes[t]; + } - fits_write_tdimll(outfile, i + 1, 2, longnaxes, &status); + fits_write_tdimll(outfile, i + 1, 2, longnaxes, + &status); - cpl_free(longnaxes); + cpl_free(longnaxes); + } + cpl_free(naxes); } - cpl_free(naxes); - } - - break; + break; - default: - break; /* Nothing to do for other types... */ + default: + break; /* Nothing to do for other types... */ } - } - } if (header) { - /* * Complete secondary header with property list information */ - if (cpl_fits_add_properties(outfile, header, "^(" - ERASE_WCS_REGEXP ")$|" - CPL_FITS_BADKEYS_EXT "|" - CPL_FITS_COMPRKEYS)) { + if (cpl_fits_add_properties(outfile, header, + mode | CPL_IO_WCS | CPL_IO_EXTEND, + CPL_FALSE)) { cpl_free(found); cpl_free(nval); cpl_free(nb); (void)cpl_io_fits_delete_file(outfile, &status); return cpl_error_set_message_(CPL_ERROR_FILE_NOT_CREATED, - "filename='%s', mode=%d", - filename, mode); + "filename='%s', mode=%d", filename, + mode); } } @@ -26081,9 +26138,8 @@ if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_flush_file, - "filename='%s', mode=%d", + cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, status, + fits_flush_file, "filename='%s', mode=%d", filename, mode); status = 0; cpl_io_fits_delete_file(outfile, &status); @@ -26117,28 +26173,24 @@ spell = chunk; for (k = 0; k < nr; k += chunk) { - if (chunk > nr - k) { spell = nr - k; } column = table->columns; for (i = 0; i < nc; i++, column++) { - cpl_type column_type = cpl_column_get_type(*column); - depth = cpl_table_get_column_depth(table, - cpl_column_get_name(*column)); - - if (_cpl_columntype_is_pointer(column_type)) { + depth = + cpl_table_get_column_depth(table, cpl_column_get_name(*column)); + if (_cpl_columntype_is_pointer(column_type)) { switch (_cpl_columntype_get_valuetype(column_type)) { - - case CPL_TYPE_STRING: - { + case CPL_TYPE_STRING: { int eccolo; int m, n; - char *long_string = cpl_malloc(depth * field_size * sizeof(char)); + char *long_string = + cpl_malloc(depth * field_size * sizeof(char)); arrays = cpl_column_get_data_array(*column); arrays += k; @@ -26146,8 +26198,8 @@ for (z = 0; z < spell; z++) { if (arrays[z]) { - - sdata = cpl_array_get_data_string_const(arrays[z]); + sdata = + cpl_array_get_data_string_const(arrays[z]); for (j = 0; j < depth; j++) { if (sdata[j] == NULL) { sdata[j] = nstring; @@ -26177,7 +26229,7 @@ // sdata[j], field_size); } - long_string[depth*field_size - 1] = '\0'; + long_string[depth * field_size - 1] = '\0'; // "Correct one" // fits_write_colnull(outfile, TSTRING, i + 1, @@ -26186,8 +26238,8 @@ cpl_fits_write_colnull(outfile, TSTRING, i + 1, k + z + 1, 1, 1, - &long_string, - nstring, &status); + &long_string, nstring, + &status); if (arrays[z]) { for (j = 0; j < depth; j++) { @@ -26204,18 +26256,17 @@ break; } - case CPL_TYPE_INT: - { - if(depth == 0) + case CPL_TYPE_INT: { + if (depth == 0) break; arrays = cpl_column_get_data_array(*column); arrays += k; - if (cpl_column_get_save_type(*column) == CPL_TYPE_BOOL) { + if (cpl_column_get_save_type(*column) == + CPL_TYPE_BOOL) { bdata = cpl_malloc(depth * sizeof(char)); if (found[i]) { - char bnval = (char)nval[i]; for (j = 0; j < spell; j++) { @@ -26224,19 +26275,20 @@ for (z = 0; z < depth; z++) { bdata[z] = idata[z]; } - fits_write_colnull(outfile, TLOGICAL, - i + 1, k + j + 1, 1, - depth, bdata, &bnval, - &status); + fits_write_colnull(outfile, TLOGICAL, i + 1, + k + j + 1, 1, depth, + bdata, &bnval, &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_colnull, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, fits_write_colnull, + "filename='%s', mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file(outfile, + &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -26252,16 +26304,19 @@ bdata[z] = idata[z]; } fits_write_col(outfile, TLOGICAL, i + 1, - k + j + 1, 1, depth, bdata, &status); + k + j + 1, 1, depth, bdata, + &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, fits_write_col, + "filename='%s', mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file(outfile, + &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -26271,10 +26326,10 @@ } cpl_free(bdata); } - else if (cpl_column_get_save_type(*column) == CPL_TYPE_CHAR) { + else if (cpl_column_get_save_type(*column) == + CPL_TYPE_CHAR) { bdata = cpl_malloc(depth * sizeof(char)); if (found[i]) { - char bnval = (char)nval[i]; for (j = 0; j < spell; j++) { @@ -26284,17 +26339,19 @@ bdata[z] = idata[z]; } fits_write_colnull(outfile, TSBYTE, i + 1, - k + j + 1, 1, depth, bdata, - &bnval, &status); + k + j + 1, 1, depth, + bdata, &bnval, &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_colnull, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, fits_write_colnull, + "filename='%s', mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file(outfile, + &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -26310,16 +26367,19 @@ bdata[z] = idata[z]; } fits_write_col(outfile, TSBYTE, i + 1, - k + j + 1, 1, depth, bdata, &status); + k + j + 1, 1, depth, bdata, + &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, fits_write_col, + "filename='%s', mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file(outfile, + &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -26329,10 +26389,10 @@ } cpl_free(bdata); } - else if (cpl_column_get_save_type(*column) == CPL_TYPE_UCHAR) { + else if (cpl_column_get_save_type(*column) == + CPL_TYPE_UCHAR) { ubdata = cpl_malloc(depth * sizeof(unsigned char)); if (found[i]) { - unsigned char ubnval = (unsigned char)nval[i]; for (j = 0; j < spell; j++) { @@ -26342,18 +26402,20 @@ ubdata[z] = idata[z]; } fits_write_colnull(outfile, TBYTE, i + 1, - k + j + 1, 1, - depth, ubdata, &ubnval, + k + j + 1, 1, depth, + ubdata, &ubnval, &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_colnull, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, fits_write_colnull, + "filename='%s', mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file(outfile, + &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -26369,17 +26431,19 @@ ubdata[z] = idata[z]; } fits_write_col(outfile, TBYTE, i + 1, - k + j + 1, 1, - depth, ubdata, &status); + k + j + 1, 1, depth, ubdata, + &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, fits_write_col, + "filename='%s', mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file(outfile, + &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -26389,10 +26453,10 @@ } cpl_free(ubdata); } - else if (cpl_column_get_save_type(*column) == CPL_TYPE_SHORT) { + else if (cpl_column_get_save_type(*column) == + CPL_TYPE_SHORT) { sidata = cpl_malloc(depth * sizeof(short)); if (found[i]) { - short sinval = (short)nval[i]; for (j = 0; j < spell; j++) { @@ -26402,18 +26466,20 @@ sidata[z] = idata[z]; } fits_write_colnull(outfile, TSHORT, i + 1, - k + j + 1, 1, - depth, sidata, &sinval, + k + j + 1, 1, depth, + sidata, &sinval, &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_colnull, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, fits_write_colnull, + "filename='%s', mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file(outfile, + &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -26429,17 +26495,19 @@ sidata[z] = idata[z]; } fits_write_col(outfile, TSHORT, i + 1, - k + j + 1, 1, - depth, sidata, &status); + k + j + 1, 1, depth, sidata, + &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, fits_write_col, + "filename='%s', mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file(outfile, + &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -26451,24 +26519,26 @@ } else { if (found[i]) { - int inval = (int)nval[i]; for (j = 0; j < spell; j++) { acolumn = cpl_array_get_column(arrays[j]); fits_write_colnull(outfile, TINT, i + 1, k + j + 1, 1, depth, - cpl_column_get_data_int(acolumn), + cpl_column_get_data_int( + acolumn), &inval, &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_colnull, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, fits_write_colnull, + "filename='%s', mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file(outfile, + &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -26479,19 +26549,22 @@ else { for (j = 0; j < spell; j++) { acolumn = cpl_array_get_column(arrays[j]); - fits_write_col(outfile, TINT, - i + 1, k + j + 1, 1, depth, - cpl_column_get_data_int(acolumn), + fits_write_col(outfile, TINT, i + 1, + k + j + 1, 1, depth, + cpl_column_get_data_int( + acolumn), &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, fits_write_col, + "filename='%s', mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file(outfile, + &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -26503,39 +26576,40 @@ break; } - case CPL_TYPE_LONG_LONG: - { - if(depth == 0) + case CPL_TYPE_LONG_LONG: { + if (depth == 0) break; arrays = cpl_column_get_data_array(*column); arrays += k; - if (cpl_column_get_save_type(*column) == CPL_TYPE_BOOL) { + if (cpl_column_get_save_type(*column) == + CPL_TYPE_BOOL) { bdata = cpl_malloc(depth * sizeof(char)); if (found[i]) { - char bnval = (char)nval[i]; for (j = 0; j < spell; j++) { acolumn = cpl_array_get_column(arrays[j]); - lldata = cpl_column_get_data_long_long(acolumn); + lldata = + cpl_column_get_data_long_long(acolumn); for (z = 0; z < depth; z++) { bdata[z] = lldata[z]; } - fits_write_colnull(outfile, TLOGICAL, - i + 1, k + j + 1, 1, - depth, bdata, &bnval, - &status); + fits_write_colnull(outfile, TLOGICAL, i + 1, + k + j + 1, 1, depth, + bdata, &bnval, &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_colnull, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, fits_write_colnull, + "filename='%s', mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file(outfile, + &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -26546,21 +26620,25 @@ else { for (j = 0; j < spell; j++) { acolumn = cpl_array_get_column(arrays[j]); - lldata = cpl_column_get_data_long_long(acolumn); + lldata = + cpl_column_get_data_long_long(acolumn); for (z = 0; z < depth; z++) { bdata[z] = lldata[z]; } fits_write_col(outfile, TLOGICAL, i + 1, - k + j + 1, 1, depth, bdata, &status); + k + j + 1, 1, depth, bdata, + &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, fits_write_col, + "filename='%s', mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file(outfile, + &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -26570,30 +26648,33 @@ } cpl_free(bdata); } - else if (cpl_column_get_save_type(*column) == CPL_TYPE_CHAR) { + else if (cpl_column_get_save_type(*column) == + CPL_TYPE_CHAR) { bdata = cpl_malloc(depth * sizeof(char)); if (found[i]) { - char bnval = (char)nval[i]; for (j = 0; j < spell; j++) { acolumn = cpl_array_get_column(arrays[j]); - lldata = cpl_column_get_data_long_long(acolumn); + lldata = + cpl_column_get_data_long_long(acolumn); for (z = 0; z < depth; z++) { bdata[z] = lldata[z]; } fits_write_colnull(outfile, TSBYTE, i + 1, - k + j + 1, 1, depth, bdata, - &bnval, &status); + k + j + 1, 1, depth, + bdata, &bnval, &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_colnull, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, fits_write_colnull, + "filename='%s', mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file(outfile, + &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -26604,21 +26685,25 @@ else { for (j = 0; j < spell; j++) { acolumn = cpl_array_get_column(arrays[j]); - lldata = cpl_column_get_data_long_long(acolumn); + lldata = + cpl_column_get_data_long_long(acolumn); for (z = 0; z < depth; z++) { bdata[z] = lldata[z]; } fits_write_col(outfile, TSBYTE, i + 1, - k + j + 1, 1, depth, bdata, &status); + k + j + 1, 1, depth, bdata, + &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, fits_write_col, + "filename='%s', mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file(outfile, + &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -26628,31 +26713,34 @@ } cpl_free(bdata); } - else if (cpl_column_get_save_type(*column) == CPL_TYPE_UCHAR) { + else if (cpl_column_get_save_type(*column) == + CPL_TYPE_UCHAR) { ubdata = cpl_malloc(depth * sizeof(unsigned char)); if (found[i]) { - unsigned char ubnval = (unsigned char)nval[i]; for (j = 0; j < spell; j++) { acolumn = cpl_array_get_column(arrays[j]); - lldata = cpl_column_get_data_long_long(acolumn); + lldata = + cpl_column_get_data_long_long(acolumn); for (z = 0; z < depth; z++) { ubdata[z] = lldata[z]; } fits_write_colnull(outfile, TBYTE, i + 1, - k + j + 1, 1, - depth, ubdata, &ubnval, + k + j + 1, 1, depth, + ubdata, &ubnval, &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_colnull, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, fits_write_colnull, + "filename='%s', mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file(outfile, + &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -26663,22 +26751,25 @@ else { for (j = 0; j < spell; j++) { acolumn = cpl_array_get_column(arrays[j]); - lldata = cpl_column_get_data_long_long(acolumn); + lldata = + cpl_column_get_data_long_long(acolumn); for (z = 0; z < depth; z++) { ubdata[z] = lldata[z]; } fits_write_col(outfile, TBYTE, i + 1, - k + j + 1, 1, - depth, ubdata, &status); + k + j + 1, 1, depth, ubdata, + &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, fits_write_col, + "filename='%s', mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file(outfile, + &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -26688,31 +26779,34 @@ } cpl_free(ubdata); } - else if (cpl_column_get_save_type(*column) == CPL_TYPE_SHORT) { + else if (cpl_column_get_save_type(*column) == + CPL_TYPE_SHORT) { sidata = cpl_malloc(depth * sizeof(short)); if (found[i]) { - short sinval = (short)nval[i]; for (j = 0; j < spell; j++) { acolumn = cpl_array_get_column(arrays[j]); - lldata = cpl_column_get_data_long_long(acolumn); + lldata = + cpl_column_get_data_long_long(acolumn); for (z = 0; z < depth; z++) { sidata[z] = lldata[z]; } fits_write_colnull(outfile, TSHORT, i + 1, - k + j + 1, 1, - depth, sidata, &sinval, + k + j + 1, 1, depth, + sidata, &sinval, &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_colnull, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, fits_write_colnull, + "filename='%s', mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file(outfile, + &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -26723,22 +26817,25 @@ else { for (j = 0; j < spell; j++) { acolumn = cpl_array_get_column(arrays[j]); - lldata = cpl_column_get_data_long_long(acolumn); + lldata = + cpl_column_get_data_long_long(acolumn); for (z = 0; z < depth; z++) { sidata[z] = lldata[z]; } fits_write_col(outfile, TSHORT, i + 1, - k + j + 1, 1, - depth, sidata, &status); + k + j + 1, 1, depth, sidata, + &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, fits_write_col, + "filename='%s', mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file(outfile, + &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -26748,31 +26845,33 @@ } cpl_free(sidata); } - else if (cpl_column_get_save_type(*column) == CPL_TYPE_INT) { + else if (cpl_column_get_save_type(*column) == + CPL_TYPE_INT) { idata = cpl_malloc(depth * sizeof(int)); if (found[i]) { - int inval = (int)nval[i]; for (j = 0; j < spell; j++) { acolumn = cpl_array_get_column(arrays[j]); - lldata = cpl_column_get_data_long_long(acolumn); + lldata = + cpl_column_get_data_long_long(acolumn); for (z = 0; z < depth; z++) { idata[z] = lldata[z]; } fits_write_colnull(outfile, TINT, i + 1, - k + j + 1, 1, - depth, idata, &inval, - &status); + k + j + 1, 1, depth, + idata, &inval, &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_colnull, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, fits_write_colnull, + "filename='%s', mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file(outfile, + &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -26783,22 +26882,25 @@ else { for (j = 0; j < spell; j++) { acolumn = cpl_array_get_column(arrays[j]); - lldata = cpl_column_get_data_long_long(acolumn); + lldata = + cpl_column_get_data_long_long(acolumn); for (z = 0; z < depth; z++) { idata[z] = lldata[z]; } fits_write_col(outfile, TINT, i + 1, - k + j + 1, 1, - depth, idata, &status); + k + j + 1, 1, depth, idata, + &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, fits_write_col, + "filename='%s', mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file(outfile, + &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -26810,24 +26912,27 @@ } else { if (found[i]) { - - long long llnval = nval[i]; /* for consistency only! */ + long long llnval = + nval[i]; /* for consistency only! */ for (j = 0; j < spell; j++) { acolumn = cpl_array_get_column(arrays[j]); - fits_write_colnull(outfile, TLONGLONG, i + 1, - k + j + 1, 1, depth, - cpl_column_get_data_long_long(acolumn), - &llnval, &status); + fits_write_colnull( + outfile, TLONGLONG, i + 1, k + j + 1, 1, + depth, + cpl_column_get_data_long_long(acolumn), + &llnval, &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_colnull, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, fits_write_colnull, + "filename='%s', mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file(outfile, + &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -26838,19 +26943,22 @@ else { for (j = 0; j < spell; j++) { acolumn = cpl_array_get_column(arrays[j]); - fits_write_col(outfile, TLONGLONG, - i + 1, k + j + 1, 1, depth, - cpl_column_get_data_long_long(acolumn), - &status); + fits_write_col( + outfile, TLONGLONG, i + 1, k + j + 1, 1, + depth, + cpl_column_get_data_long_long(acolumn), + &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, fits_write_col, + "filename='%s', mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file(outfile, + &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -26862,8 +26970,7 @@ break; } - case CPL_TYPE_FLOAT: - { + case CPL_TYPE_FLOAT: { if (depth == 0) break; @@ -26871,9 +26978,7 @@ arrays += k; for (j = 0; j < spell; j++) { - if (arrays[j]) { - /* * Get the data buffer of the current array. */ @@ -26882,15 +26987,14 @@ fdata = cpl_column_get_data_float(acolumn); if (cpl_column_has_invalid(acolumn)) { - /* * If some invalid values are present, * get also the array with invalid flags. */ - ndata = cpl_column_get_data_invalid(acolumn); + ndata = + cpl_column_get_data_invalid(acolumn); if (ndata) { - /* * Preliminarily fill this data section * including also the garbage (i.e., the @@ -26898,17 +27002,19 @@ */ fits_write_col(outfile, TFLOAT, i + 1, - k + j + 1, 1, depth, fdata, - &status); + k + j + 1, 1, depth, + fdata, &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, fits_write_col, + "filename='%s', mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file(outfile, + &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -26931,7 +27037,6 @@ count = 0; for (z = 0; z < depth; z++) { if (ndata[z]) { - /* * Invalid flag found. If the first of * a sequence mark its position, and @@ -26944,7 +27049,6 @@ count++; } else { - /* * Valid element found. If it's closing * a sequence of invalid elements, dump @@ -26953,19 +27057,23 @@ */ if (count) { - fits_write_col_null(outfile, i + 1, - k + j + 1, - fcount, count, - &status); + fits_write_col_null( + outfile, i + 1, + k + j + 1, fcount, + count, &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col_null, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, + fits_write_col_null, + "filename='%s'," + " mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file( + outfile, &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -26983,12 +27091,16 @@ if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col_null, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, + fits_write_col_null, + "filename='%s', " + "mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file( + outfile, &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -26997,23 +27109,25 @@ } } else { - /* * All elements are invalid: just pad with NaN * the current data section. */ - fits_write_col_null(outfile, i + 1, k + j + 1, - 1, depth, &status); + fits_write_col_null(outfile, i + 1, + k + j + 1, 1, depth, + &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col_null, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, fits_write_col_null, + "filename='%s', mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file(outfile, + &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -27022,24 +27136,25 @@ } } else { - /* * No invalid values are present, simply copy * the whole array buffer to this data section. */ fits_write_col(outfile, TFLOAT, i + 1, - k + j + 1, 1, - depth, fdata, &status); + k + j + 1, 1, depth, fdata, + &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, fits_write_col, + "filename='%s', mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file(outfile, + &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -27048,7 +27163,6 @@ } } else { - /* * All elements are invalid: just pad with NaN * the current data section. @@ -27059,10 +27173,11 @@ if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col_null, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, status, + fits_write_col_null, + "filename='%s', mode=%d", filename, + mode); status = 0; cpl_io_fits_delete_file(outfile, &status); cpl_free(found); @@ -27075,8 +27190,7 @@ break; } - case CPL_TYPE_DOUBLE: - { + case CPL_TYPE_DOUBLE: { if (depth == 0) break; @@ -27084,9 +27198,7 @@ arrays += k; for (j = 0; j < spell; j++) { - if (arrays[j]) { - /* * Get the data buffer of the current array. */ @@ -27095,15 +27207,14 @@ ddata = cpl_column_get_data_double(acolumn); if (cpl_column_has_invalid(acolumn)) { - /* * If some invalid values are present, * get also the array with invalid flags. */ - ndata = cpl_column_get_data_invalid(acolumn); + ndata = + cpl_column_get_data_invalid(acolumn); if (ndata) { - /* * Preliminarily fill this data section * including also the garbage (i.e., the @@ -27111,17 +27222,19 @@ */ fits_write_col(outfile, TDOUBLE, i + 1, - k + j + 1, 1, depth, ddata, - &status); + k + j + 1, 1, depth, + ddata, &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, fits_write_col, + "filename='%s', mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file(outfile, + &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -27144,7 +27257,6 @@ count = 0; for (z = 0; z < depth; z++) { if (ndata[z]) { - /* * Invalid flag found. If the first of * a sequence mark its position, and @@ -27157,7 +27269,6 @@ count++; } else { - /* * Valid element found. If it's closing * a sequence of invalid elements, dump @@ -27166,19 +27277,23 @@ */ if (count) { - fits_write_col_null(outfile, i + 1, - k + j + 1, - fcount, count, - &status); + fits_write_col_null( + outfile, i + 1, + k + j + 1, fcount, + count, &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col_null, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, + fits_write_col_null, + "filename='%s'," + " mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file( + outfile, &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -27190,17 +27305,22 @@ } if (count) { fits_write_col_null(outfile, i + 1, - k + j + 1, fcount, - count, &status); + k + j + 1, + fcount, count, + &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col_null, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, + fits_write_col_null, + "filename='%s', " + "mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file( + outfile, &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -27209,23 +27329,25 @@ } } else { - /* * All elements are invalid: just pad with NaN * the current data section. */ - fits_write_col_null(outfile, i + 1, k + j + 1, - 1, depth, &status); + fits_write_col_null(outfile, i + 1, + k + j + 1, 1, depth, + &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col_null, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, fits_write_col_null, + "filename='%s', mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file(outfile, + &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -27234,23 +27356,25 @@ } } else { - /* * No invalid values are present, simply copy * the whole array buffer to this data section. */ - fits_write_col(outfile, TDOUBLE, i + 1, k + j + 1, - 1, depth, ddata, &status); + fits_write_col(outfile, TDOUBLE, i + 1, + k + j + 1, 1, depth, ddata, + &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, fits_write_col, + "filename='%s', mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file(outfile, + &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -27259,7 +27383,6 @@ } } else { - /* * All elements are invalid: just pad with NaN * the current data section. @@ -27270,10 +27393,11 @@ if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col_null, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, status, + fits_write_col_null, + "filename='%s', mode=%d", filename, + mode); status = 0; cpl_io_fits_delete_file(outfile, &status); cpl_free(found); @@ -27286,8 +27410,7 @@ break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { if (depth == 0) break; @@ -27296,31 +27419,29 @@ arrays += k; for (j = 0; j < spell; j++) { - if (arrays[j]) { - /* * Get the data buffer of the current array. */ acolumn = cpl_array_get_column(arrays[j]); - cfdata = cpl_column_get_data_float_complex(acolumn); + cfdata = + cpl_column_get_data_float_complex(acolumn); for (z = 0; z < depth; z++) { - fdata[2*z] = crealf(cfdata[z]); - fdata[2*z + 1] = cimagf(cfdata[z]); + fdata[2 * z] = crealf(cfdata[z]); + fdata[2 * z + 1] = cimagf(cfdata[z]); } if (cpl_column_has_invalid(acolumn)) { - /* * If some invalid values are present, * get also the array with invalid flags. */ - ndata = cpl_column_get_data_invalid(acolumn); + ndata = + cpl_column_get_data_invalid(acolumn); if (ndata) { - /* * Preliminarily fill this data section * including also the garbage (i.e., the @@ -27328,17 +27449,19 @@ */ fits_write_col(outfile, TCOMPLEX, i + 1, - k + j + 1, 1, depth, fdata, - &status); + k + j + 1, 1, depth, + fdata, &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, fits_write_col, + "filename='%s', mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file(outfile, + &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -27361,7 +27484,6 @@ count = 0; for (z = 0; z < depth; z++) { if (ndata[z]) { - /* * Invalid flag found. If the first of * a sequence mark its position, and @@ -27374,7 +27496,6 @@ count++; } else { - /* * Valid element found. If it's closing * a sequence of invalid elements, dump @@ -27383,19 +27504,23 @@ */ if (count) { - fits_write_col_null(outfile, i + 1, - k + j + 1, - fcount, count, - &status); + fits_write_col_null( + outfile, i + 1, + k + j + 1, fcount, + count, &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col_null, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, + fits_write_col_null, + "filename='%s'," + " mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file( + outfile, &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -27413,12 +27538,16 @@ if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col_null, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, + fits_write_col_null, + "filename='%s', " + "mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file( + outfile, &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -27427,23 +27556,25 @@ } } else { - /* * All elements are invalid: just pad with NaN * the current data section. */ - fits_write_col_null(outfile, i + 1, k + j + 1, - 1, depth, &status); + fits_write_col_null(outfile, i + 1, + k + j + 1, 1, depth, + &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col_null, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, fits_write_col_null, + "filename='%s', mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file(outfile, + &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -27452,24 +27583,25 @@ } } else { - /* * No invalid values are present, simply copy * the whole array buffer to this data section. */ fits_write_col(outfile, TCOMPLEX, i + 1, - k + j + 1, 1, - depth, fdata, &status); + k + j + 1, 1, depth, fdata, + &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, fits_write_col, + "filename='%s', mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file(outfile, + &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -27478,7 +27610,6 @@ } } else { - /* * All elements are invalid: just pad with NaN * the current data section. @@ -27489,10 +27620,11 @@ if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col_null, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, status, + fits_write_col_null, + "filename='%s', mode=%d", filename, + mode); status = 0; cpl_io_fits_delete_file(outfile, &status); cpl_free(found); @@ -27506,8 +27638,7 @@ break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { if (depth == 0) break; @@ -27516,49 +27647,49 @@ arrays += k; for (j = 0; j < spell; j++) { - if (arrays[j]) { - /* * Get the data buffer of the current array. */ acolumn = cpl_array_get_column(arrays[j]); - cddata = cpl_column_get_data_double_complex(acolumn); + cddata = + cpl_column_get_data_double_complex(acolumn); for (z = 0; z < depth; z++) { - ddata[2*z] = creal(cddata[z]); - ddata[2*z + 1] = cimag(cddata[z]); + ddata[2 * z] = creal(cddata[z]); + ddata[2 * z + 1] = cimag(cddata[z]); } if (cpl_column_has_invalid(acolumn)) { - /* * If some invalid values are present, * get also the array with invalid flags. */ - ndata = cpl_column_get_data_invalid(acolumn); + ndata = + cpl_column_get_data_invalid(acolumn); if (ndata) { - /* * Preliminarily fill this data section * including also the garbage (i.e., the * invalid values). */ - fits_write_col(outfile, TDBLCOMPLEX, i + 1, - k + j + 1, 1, depth, ddata, - &status); + fits_write_col(outfile, TDBLCOMPLEX, + i + 1, k + j + 1, 1, + depth, ddata, &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, fits_write_col, + "filename='%s', mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file(outfile, + &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -27581,7 +27712,6 @@ count = 0; for (z = 0; z < depth; z++) { if (ndata[z]) { - /* * Invalid flag found. If the first of * a sequence mark its position, and @@ -27594,7 +27724,6 @@ count++; } else { - /* * Valid element found. If it's closing * a sequence of invalid elements, dump @@ -27603,19 +27732,23 @@ */ if (count) { - fits_write_col_null(outfile, i + 1, - k + j + 1, - fcount, count, - &status); + fits_write_col_null( + outfile, i + 1, + k + j + 1, fcount, + count, &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col_null, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, + fits_write_col_null, + "filename='%s'," + " mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file( + outfile, &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -27627,17 +27760,22 @@ } if (count) { fits_write_col_null(outfile, i + 1, - k + j + 1, fcount, - count, &status); + k + j + 1, + fcount, count, + &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col_null, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, + fits_write_col_null, + "filename='%s', " + "mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file( + outfile, &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -27646,23 +27784,25 @@ } } else { - /* * All elements are invalid: just pad with NaN * the current data section. */ - fits_write_col_null(outfile, i + 1, k + j + 1, - 1, depth, &status); + fits_write_col_null(outfile, i + 1, + k + j + 1, 1, depth, + &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col_null, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, fits_write_col_null, + "filename='%s', mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file(outfile, + &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -27671,23 +27811,25 @@ } } else { - /* * No invalid values are present, simply copy * the whole array buffer to this data section. */ fits_write_col(outfile, TDBLCOMPLEX, i + 1, - k + j + 1, 1, depth, ddata, &status); + k + j + 1, 1, depth, ddata, + &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, fits_write_col, + "filename='%s', mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file(outfile, + &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -27696,7 +27838,6 @@ } } else { - /* * All elements are invalid: just pad with NaN * the current data section. @@ -27707,10 +27848,11 @@ if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col_null, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, status, + fits_write_col_null, + "filename='%s', mode=%d", filename, + mode); status = 0; cpl_io_fits_delete_file(outfile, &status); cpl_free(found); @@ -27725,17 +27867,12 @@ } default: - break; /* Should never get here... */ - + break; /* Should never get here... */ } - } else { - switch (_cpl_columntype_get_valuetype(column_type)) { - - case CPL_TYPE_STRING: - { + case CPL_TYPE_STRING: { sdata = cpl_column_get_data_string_const(*column); sdata += k; @@ -27752,8 +27889,8 @@ sdata[j] = nstring; cpl_fits_write_colnull(outfile, TSTRING, i + 1, k + 1, - 1, spell, sdata, - nstring, &status); + 1, spell, sdata, nstring, + &status); if (status) { const cpl_error_code code = cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, @@ -27783,8 +27920,7 @@ break; } - case CPL_TYPE_INT: - { + case CPL_TYPE_INT: { /* * Get the data buffer of the current column. */ @@ -27792,7 +27928,8 @@ idata = cpl_column_get_data_int(*column); idata += k; - if (cpl_column_get_save_type(*column) == CPL_TYPE_BOOL) { + if (cpl_column_get_save_type(*column) == + CPL_TYPE_BOOL) { bdata = cpl_malloc(spell * sizeof(char)); for (j = 0; j < spell; j++) { bdata[j] = idata[j]; @@ -27800,16 +27937,18 @@ if (found[i]) { char bnval = (char)nval[i]; - fits_write_colnull(outfile, TLOGICAL, i + 1, k + 1, 1, - spell, bdata, &bnval, &status); + fits_write_colnull(outfile, TLOGICAL, i + 1, + k + 1, 1, spell, bdata, + &bnval, &status); } else { - fits_write_col(outfile, TLOGICAL, i + 1, k + 1, 1, - spell, bdata, &status); + fits_write_col(outfile, TLOGICAL, i + 1, k + 1, + 1, spell, bdata, &status); } cpl_free(bdata); } - else if (cpl_column_get_save_type(*column) == CPL_TYPE_CHAR) { + else if (cpl_column_get_save_type(*column) == + CPL_TYPE_CHAR) { bdata = cpl_malloc(spell * sizeof(char)); for (j = 0; j < spell; j++) { bdata[j] = idata[j]; @@ -27817,8 +27956,9 @@ if (found[i]) { char bnval = (char)nval[i]; - fits_write_colnull(outfile, TSBYTE, i + 1, k + 1, 1, - spell, bdata, &bnval, &status); + fits_write_colnull(outfile, TSBYTE, i + 1, + k + 1, 1, spell, bdata, + &bnval, &status); } else { fits_write_col(outfile, TSBYTE, i + 1, k + 1, 1, @@ -27826,7 +27966,8 @@ } cpl_free(bdata); } - else if (cpl_column_get_save_type(*column) == CPL_TYPE_UCHAR) { + else if (cpl_column_get_save_type(*column) == + CPL_TYPE_UCHAR) { ubdata = cpl_malloc(spell * sizeof(unsigned char)); for (j = 0; j < spell; j++) { ubdata[j] = idata[j]; @@ -27834,8 +27975,9 @@ if (found[i]) { unsigned char ubnval = (unsigned char)nval[i]; - fits_write_colnull(outfile, TBYTE, i + 1, k + 1, 1, - spell, ubdata, &ubnval, &status); + fits_write_colnull(outfile, TBYTE, i + 1, k + 1, + 1, spell, ubdata, &ubnval, + &status); } else { fits_write_col(outfile, TBYTE, i + 1, k + 1, 1, @@ -27843,7 +27985,8 @@ } cpl_free(ubdata); } - else if (cpl_column_get_save_type(*column) == CPL_TYPE_SHORT) { + else if (cpl_column_get_save_type(*column) == + CPL_TYPE_SHORT) { sidata = cpl_malloc(spell * sizeof(short)); for (j = 0; j < spell; j++) { sidata[j] = idata[j]; @@ -27851,8 +27994,9 @@ if (found[i]) { short sinval = (short)nval[i]; - fits_write_colnull(outfile, TSHORT, i + 1, k + 1, 1, - spell, sidata, &sinval, &status); + fits_write_colnull(outfile, TSHORT, i + 1, + k + 1, 1, spell, sidata, + &sinval, &status); } else { fits_write_col(outfile, TSHORT, i + 1, k + 1, 1, @@ -27863,12 +28007,13 @@ else { if (found[i]) { int inval = (int)nval[i]; - fits_write_colnull(outfile, TINT, i + 1, k + 1, 1, - spell, idata, &inval, &status); + fits_write_colnull(outfile, TINT, i + 1, k + 1, + 1, spell, idata, &inval, + &status); } else { - fits_write_col(outfile, TINT, i + 1, k + 1, 1, spell, - idata, &status); + fits_write_col(outfile, TINT, i + 1, k + 1, 1, + spell, idata, &status); } } @@ -27888,8 +28033,7 @@ break; } - case CPL_TYPE_LONG_LONG: - { + case CPL_TYPE_LONG_LONG: { /* * Get the data buffer of the current column. */ @@ -27897,7 +28041,8 @@ lldata = cpl_column_get_data_long_long(*column); lldata += k; - if (cpl_column_get_save_type(*column) == CPL_TYPE_BOOL) { + if (cpl_column_get_save_type(*column) == + CPL_TYPE_BOOL) { bdata = cpl_malloc(spell * sizeof(char)); for (j = 0; j < spell; j++) { bdata[j] = lldata[j]; @@ -27905,16 +28050,18 @@ if (found[i]) { char bnval = (char)nval[i]; - fits_write_colnull(outfile, TLOGICAL, i + 1, k + 1, 1, - spell, bdata, &bnval, &status); + fits_write_colnull(outfile, TLOGICAL, i + 1, + k + 1, 1, spell, bdata, + &bnval, &status); } else { - fits_write_col(outfile, TLOGICAL, i + 1, k + 1, 1, - spell, bdata, &status); + fits_write_col(outfile, TLOGICAL, i + 1, k + 1, + 1, spell, bdata, &status); } cpl_free(bdata); } - else if (cpl_column_get_save_type(*column) == CPL_TYPE_CHAR) { + else if (cpl_column_get_save_type(*column) == + CPL_TYPE_CHAR) { bdata = cpl_malloc(spell * sizeof(char)); for (j = 0; j < spell; j++) { bdata[j] = lldata[j]; @@ -27922,8 +28069,9 @@ if (found[i]) { char bnval = (char)nval[i]; - fits_write_colnull(outfile, TSBYTE, i + 1, k + 1, 1, - spell, bdata, &bnval, &status); + fits_write_colnull(outfile, TSBYTE, i + 1, + k + 1, 1, spell, bdata, + &bnval, &status); } else { fits_write_col(outfile, TSBYTE, i + 1, k + 1, 1, @@ -27931,7 +28079,8 @@ } cpl_free(bdata); } - else if (cpl_column_get_save_type(*column) == CPL_TYPE_UCHAR) { + else if (cpl_column_get_save_type(*column) == + CPL_TYPE_UCHAR) { ubdata = cpl_malloc(spell * sizeof(unsigned char)); for (j = 0; j < spell; j++) { ubdata[j] = lldata[j]; @@ -27939,8 +28088,9 @@ if (found[i]) { unsigned char ubnval = (unsigned char)nval[i]; - fits_write_colnull(outfile, TBYTE, i + 1, k + 1, 1, - spell, ubdata, &ubnval, &status); + fits_write_colnull(outfile, TBYTE, i + 1, k + 1, + 1, spell, ubdata, &ubnval, + &status); } else { fits_write_col(outfile, TBYTE, i + 1, k + 1, 1, @@ -27948,7 +28098,8 @@ } cpl_free(ubdata); } - else if (cpl_column_get_save_type(*column) == CPL_TYPE_SHORT) { + else if (cpl_column_get_save_type(*column) == + CPL_TYPE_SHORT) { sidata = cpl_malloc(spell * sizeof(short)); for (j = 0; j < spell; j++) { sidata[j] = lldata[j]; @@ -27956,8 +28107,9 @@ if (found[i]) { short sinval = (short)nval[i]; - fits_write_colnull(outfile, TSHORT, i + 1, k + 1, 1, - spell, sidata, &sinval, &status); + fits_write_colnull(outfile, TSHORT, i + 1, + k + 1, 1, spell, sidata, + &sinval, &status); } else { fits_write_col(outfile, TSHORT, i + 1, k + 1, 1, @@ -27965,7 +28117,8 @@ } cpl_free(sidata); } - else if (cpl_column_get_save_type(*column) == CPL_TYPE_INT) { + else if (cpl_column_get_save_type(*column) == + CPL_TYPE_INT) { idata = cpl_malloc(spell * sizeof(int)); for (j = 0; j < spell; j++) { idata[j] = lldata[j]; @@ -27973,8 +28126,9 @@ if (found[i]) { int inval = (int)nval[i]; - fits_write_colnull(outfile, TINT, i + 1, k + 1, 1, - spell, idata, &inval, &status); + fits_write_colnull(outfile, TINT, i + 1, k + 1, + 1, spell, idata, &inval, + &status); } else { fits_write_col(outfile, TINT, i + 1, k + 1, 1, @@ -27984,15 +28138,16 @@ } else { if (found[i]) { + long long llnval = + nval[i]; /* for consistency only! */ - long long llnval = nval[i]; /* for consistency only! */ - - fits_write_colnull(outfile, TLONGLONG, i + 1, k + 1, 1, - spell, lldata, &llnval, &status); + fits_write_colnull(outfile, TLONGLONG, i + 1, + k + 1, 1, spell, lldata, + &llnval, &status); } else { - fits_write_col(outfile, TLONGLONG, i + 1, k + 1, 1, - spell, lldata, &status); + fits_write_col(outfile, TLONGLONG, i + 1, k + 1, + 1, spell, lldata, &status); } } @@ -28012,8 +28167,7 @@ break; } - case CPL_TYPE_FLOAT: - { + case CPL_TYPE_FLOAT: { /* * Get the data buffer of the current column. */ @@ -28022,7 +28176,6 @@ fdata += k; if (cpl_column_has_invalid(*column)) { - /* * If some invalid values are present, * get also the array with invalid flags. @@ -28030,7 +28183,6 @@ ndata = cpl_column_get_data_invalid(*column); if (ndata) { - ndata += k; /* @@ -28039,15 +28191,16 @@ * invalid values). */ - fits_write_col(outfile, TFLOAT, i + 1, k + 1, 1, spell, - fdata, &status); + fits_write_col(outfile, TFLOAT, i + 1, k + 1, 1, + spell, fdata, &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, status, + fits_write_col, + "filename='%s', mode=%d", filename, + mode); status = 0; cpl_io_fits_delete_file(outfile, &status); cpl_free(found); @@ -28072,7 +28225,6 @@ count = 0; for (j = 0; j < spell; j++) { if (ndata[j]) { - /* * Invalid flag found. If the first of * a sequence mark its position, and @@ -28085,7 +28237,6 @@ count++; } else { - /* * Valid element found. If it's closing * a sequence of invalid elements, dump @@ -28094,17 +28245,22 @@ */ if (count) { - fits_write_col_null(outfile, i + 1, fcount, - 1, count, &status); + fits_write_col_null(outfile, i + 1, + fcount, 1, + count, &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col_null, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, + fits_write_col_null, + "filename='%s', " + "mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file( + outfile, &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -28120,12 +28276,14 @@ if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col_null, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, fits_write_col_null, + "filename='%s', mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file(outfile, + &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -28134,7 +28292,6 @@ } } else { - /* * All elements are invalid: just pad with NaN * the current data section. @@ -28145,10 +28302,11 @@ if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col_null, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, status, + fits_write_col_null, + "filename='%s', mode=%d", filename, + mode); status = 0; cpl_io_fits_delete_file(outfile, &status); cpl_free(found); @@ -28159,21 +28317,19 @@ } } else { - /* * No invalid values are present, simply copy * the whole array buffer to this data section. */ - fits_write_col(outfile, TFLOAT, i + 1, k + 1, 1, spell, - fdata, &status); + fits_write_col(outfile, TFLOAT, i + 1, k + 1, 1, + spell, fdata, &status); if (status) { - const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col, - "filename='%s', mode=%d", - filename, mode); + const cpl_error_code code = cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, status, + fits_write_col, "filename='%s', mode=%d", + filename, mode); status = 0; cpl_io_fits_delete_file(outfile, &status); cpl_free(found); @@ -28185,8 +28341,7 @@ break; } - case CPL_TYPE_DOUBLE: - { + case CPL_TYPE_DOUBLE: { /* * Get the data buffer of the current column. */ @@ -28195,7 +28350,6 @@ ddata += k; if (cpl_column_has_invalid(*column)) { - /* * If some invalid values are present, * get also the array with invalid flags. @@ -28203,7 +28357,6 @@ ndata = cpl_column_get_data_invalid(*column); if (ndata) { - ndata += k; /* @@ -28212,15 +28365,16 @@ * invalid values). */ - fits_write_col(outfile, TDOUBLE, i + 1, k + 1, 1, - spell, ddata, &status); + fits_write_col(outfile, TDOUBLE, i + 1, k + 1, + 1, spell, ddata, &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, status, + fits_write_col, + "filename='%s', mode=%d", filename, + mode); status = 0; cpl_io_fits_delete_file(outfile, &status); cpl_free(found); @@ -28245,7 +28399,6 @@ count = 0; for (j = 0; j < spell; j++) { if (ndata[j]) { - /* * Invalid flag found. If the first of * a sequence mark its position, and @@ -28258,7 +28411,6 @@ count++; } else { - /* * Valid element found. If it's closing * a sequence of invalid elements, dump @@ -28267,17 +28419,22 @@ */ if (count) { - fits_write_col_null(outfile, i + 1, fcount, - 1, count, &status); + fits_write_col_null(outfile, i + 1, + fcount, 1, + count, &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col_null, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, + fits_write_col_null, + "filename='%s', " + "mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file( + outfile, &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -28293,12 +28450,14 @@ if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col_null, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, fits_write_col_null, + "filename='%s', mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file(outfile, + &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -28307,7 +28466,6 @@ } } else { - /* * All elements are invalid: just pad with NaN * the current data section. @@ -28318,10 +28476,11 @@ if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col_null, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, status, + fits_write_col_null, + "filename='%s', mode=%d", filename, + mode); status = 0; cpl_io_fits_delete_file(outfile, &status); cpl_free(found); @@ -28332,7 +28491,6 @@ } } else { - /* * No invalid values are present, simply copy * the whole array buffer to this data section. @@ -28342,11 +28500,10 @@ spell, ddata, &status); if (status) { - const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col, - "filename='%s', mode=%d", - filename, mode); + const cpl_error_code code = cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, status, + fits_write_col, "filename='%s', mode=%d", + filename, mode); status = 0; cpl_io_fits_delete_file(outfile, &status); cpl_free(found); @@ -28358,8 +28515,7 @@ break; } - case CPL_TYPE_FLOAT_COMPLEX: - { + case CPL_TYPE_FLOAT_COMPLEX: { /* * Get the data buffer of the current column. */ @@ -28368,12 +28524,11 @@ cfdata = cpl_column_get_data_float_complex(*column); cfdata += k; for (j = 0; j < spell; j++) { - fdata[2*j] = crealf(cfdata[j]); - fdata[2*j + 1] = cimagf(cfdata[j]); + fdata[2 * j] = crealf(cfdata[j]); + fdata[2 * j + 1] = cimagf(cfdata[j]); } if (cpl_column_has_invalid(*column)) { - /* * If some invalid values are present, * get also the array with invalid flags. @@ -28381,7 +28536,6 @@ ndata = cpl_column_get_data_invalid(*column); if (ndata) { - ndata += k; /* @@ -28390,15 +28544,16 @@ * invalid values). */ - fits_write_col(outfile, TCOMPLEX, i + 1, k + 1, 1, - spell, fdata, &status); + fits_write_col(outfile, TCOMPLEX, i + 1, k + 1, + 1, spell, fdata, &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, status, + fits_write_col, + "filename='%s', mode=%d", filename, + mode); status = 0; cpl_io_fits_delete_file(outfile, &status); cpl_free(found); @@ -28423,7 +28578,6 @@ count = 0; for (j = 0; j < spell; j++) { if (ndata[j]) { - /* * Invalid flag found. If the first of * a sequence, mark its position and @@ -28436,7 +28590,6 @@ count++; } else { - /* * Valid element found. If it's closing * a sequence of invalid elements, dump @@ -28445,17 +28598,22 @@ */ if (count) { - fits_write_col_null(outfile, i + 1, fcount, - 1, count, &status); + fits_write_col_null(outfile, i + 1, + fcount, 1, + count, &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col_null, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, + fits_write_col_null, + "filename='%s', " + "mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file( + outfile, &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -28471,12 +28629,14 @@ if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col_null, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, fits_write_col_null, + "filename='%s', mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file(outfile, + &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -28485,7 +28645,6 @@ } } else { - /* * All elements are invalid: just pad with NaN * the current data section. @@ -28496,10 +28655,11 @@ if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col_null, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, status, + fits_write_col_null, + "filename='%s', mode=%d", filename, + mode); status = 0; cpl_io_fits_delete_file(outfile, &status); cpl_free(found); @@ -28510,21 +28670,19 @@ } } else { - /* * No invalid values are present, simply copy * the whole array buffer to this data section. */ - fits_write_col(outfile, TCOMPLEX, - i + 1, k + 1, 1, spell, fdata, &status); + fits_write_col(outfile, TCOMPLEX, i + 1, k + 1, 1, + spell, fdata, &status); if (status) { - const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col, - "filename='%s', mode=%d", - filename, mode); + const cpl_error_code code = cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, status, + fits_write_col, "filename='%s', mode=%d", + filename, mode); status = 0; cpl_io_fits_delete_file(outfile, &status); cpl_free(found); @@ -28537,8 +28695,7 @@ break; } - case CPL_TYPE_DOUBLE_COMPLEX: - { + case CPL_TYPE_DOUBLE_COMPLEX: { /* * Get the data buffer of the current column. */ @@ -28549,12 +28706,11 @@ cddata += k; for (j = 0; j < spell; j++) { - ddata[2*j] = creal(cddata[j]); - ddata[2*j + 1] = cimag(cddata[j]); + ddata[2 * j] = creal(cddata[j]); + ddata[2 * j + 1] = cimag(cddata[j]); } if (cpl_column_has_invalid(*column)) { - /* * If some invalid values are present, * get also the array with invalid flags. @@ -28562,7 +28718,6 @@ ndata = cpl_column_get_data_invalid(*column); if (ndata) { - ndata += k; /* @@ -28571,15 +28726,16 @@ * invalid values). */ - fits_write_col(outfile, TDBLCOMPLEX, i + 1, k + 1, 1, - spell, ddata, &status); + fits_write_col(outfile, TDBLCOMPLEX, i + 1, + k + 1, 1, spell, ddata, &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, status, + fits_write_col, + "filename='%s', mode=%d", filename, + mode); status = 0; cpl_io_fits_delete_file(outfile, &status); cpl_free(found); @@ -28604,7 +28760,6 @@ count = 0; for (j = 0; j < spell; j++) { if (ndata[j]) { - /* * Invalid flag found. If the first of * a sequence mark its position, and @@ -28617,7 +28772,6 @@ count++; } else { - /* * Valid element found. If it's closing * a sequence of invalid elements, dump @@ -28626,17 +28780,22 @@ */ if (count) { - fits_write_col_null(outfile, i + 1, fcount, - 1, count, &status); + fits_write_col_null(outfile, i + 1, + fcount, 1, + count, &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col_null, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, + fits_write_col_null, + "filename='%s', " + "mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file( + outfile, &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -28652,12 +28811,14 @@ if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col_null, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, + status, fits_write_col_null, + "filename='%s', mode=%d", + filename, mode); status = 0; - cpl_io_fits_delete_file(outfile, &status); + cpl_io_fits_delete_file(outfile, + &status); cpl_free(found); cpl_free(nval); cpl_free(nb); @@ -28666,7 +28827,6 @@ } } else { - /* * All elements are invalid: just pad with NaN * the current data section. @@ -28677,10 +28837,11 @@ if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col_null, - "filename='%s', mode=%d", - filename, mode); + cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, status, + fits_write_col_null, + "filename='%s', mode=%d", filename, + mode); status = 0; cpl_io_fits_delete_file(outfile, &status); cpl_free(found); @@ -28691,21 +28852,19 @@ } } else { - /* * No invalid values are present, simply copy * the whole array buffer to this data section. */ - fits_write_col(outfile, TDBLCOMPLEX, i + 1, k + 1, 1, - spell, ddata, &status); + fits_write_col(outfile, TDBLCOMPLEX, i + 1, k + 1, + 1, spell, ddata, &status); if (status) { - const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_col, - "filename='%s', mode=%d", - filename, mode); + const cpl_error_code code = cpl_error_set_fits( + CPL_ERROR_FILE_NOT_CREATED, status, + fits_write_col, "filename='%s', mode=%d", + filename, mode); status = 0; cpl_io_fits_delete_file(outfile, &status); cpl_free(found); @@ -28719,14 +28878,10 @@ } default: - break; /* Should never get here... */ - + break; /* Should never get here... */ } - } - } - } cpl_free(nval); @@ -28745,9 +28900,8 @@ fits_write_date(outfile, &status); if (status) { const cpl_error_code code = - cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, - status, fits_write_date, - "filename='%s', mode=%d", + cpl_error_set_fits(CPL_ERROR_FILE_NOT_CREATED, status, + fits_write_date, "filename='%s', mode=%d", filename, mode); status = 0; cpl_io_fits_delete_file(outfile, &status); @@ -28759,13 +28913,11 @@ if (status) { status = 0; cpl_io_fits_delete_file(outfile, &status); - return cpl_error_set_message_(CPL_ERROR_FILE_NOT_CREATED, - "filename='%s', mode=%d", - filename, mode); + return cpl_error_set_message_(CPL_ERROR_FILE_NOT_CREATED, + "filename='%s', mode=%d", filename, mode); } return CPL_ERROR_NONE; - } @@ -28909,13 +29061,16 @@ */ cpl_error_code -cpl_table_save(const cpl_table *table, const cpl_propertylist *pheader, - const cpl_propertylist *header, const char *filename, +cpl_table_save(const cpl_table *table, + const cpl_propertylist *pheader, + const cpl_propertylist *header, + const char *filename, unsigned mode) { - const cpl_error_code code = mode & CPL_IO_APPEND - ? _cpl_table_save(table, pheader, header, filename, mode) - : _cpl_table_save_legacy(table, pheader, header, filename, mode); + const cpl_error_code code = + mode & CPL_IO_APPEND + ? _cpl_table_save(table, pheader, header, filename, mode) + : _cpl_table_save_legacy(table, pheader, header, filename, mode); return code ? cpl_error_set_where_() : CPL_ERROR_NONE; } diff -Nru cpl-7.1.4+ds/cplcore/cpl_table.h cpl-7.2.2+ds/cplcore/cpl_table.h --- cpl-7.1.4+ds/cplcore/cpl_table.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_table.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -50,24 +50,23 @@ * Constructors and destructors: */ -cpl_table *cpl_table_new(cpl_size) - CPL_ATTR_ALLOC; +cpl_table *cpl_table_new(cpl_size) CPL_ATTR_ALLOC; cpl_error_code cpl_table_new_column(cpl_table *, const char *, cpl_type); -cpl_error_code cpl_table_new_column_array(cpl_table *, const char *, - cpl_type, cpl_size); +cpl_error_code +cpl_table_new_column_array(cpl_table *, const char *, cpl_type, cpl_size); -cpl_error_code cpl_table_set_column_savetype(cpl_table *, - const char *name, cpl_type); +cpl_error_code +cpl_table_set_column_savetype(cpl_table *, const char *name, cpl_type); cpl_error_code cpl_table_wrap_int(cpl_table *, int *, const char *); cpl_error_code cpl_table_wrap_long_long(cpl_table *, long long *, const char *); cpl_error_code cpl_table_wrap_float(cpl_table *, float *, const char *); cpl_error_code cpl_table_wrap_double(cpl_table *, double *, const char *); -cpl_error_code cpl_table_wrap_float_complex(cpl_table *, - _Complex float *, const char *); -cpl_error_code cpl_table_wrap_double_complex(cpl_table *, - _Complex double *, const char *); +cpl_error_code +cpl_table_wrap_float_complex(cpl_table *, _Complex float *, const char *); +cpl_error_code +cpl_table_wrap_double_complex(cpl_table *, _Complex double *, const char *); cpl_error_code cpl_table_wrap_string(cpl_table *, char **, const char *); void *cpl_table_unwrap(cpl_table *, const char *); @@ -86,146 +85,184 @@ cpl_type cpl_table_get_column_type(const cpl_table *, const char *name); -cpl_error_code cpl_table_set_column_unit(cpl_table *, const char *name, - const char *unit); +cpl_error_code +cpl_table_set_column_unit(cpl_table *, const char *name, const char *unit); const char *cpl_table_get_column_unit(const cpl_table *, const char *name); -cpl_error_code cpl_table_set_column_format(cpl_table *, const char *name, - const char *format); +cpl_error_code +cpl_table_set_column_format(cpl_table *, const char *name, const char *format); const char *cpl_table_get_column_format(const cpl_table *, const char *name); cpl_error_code cpl_table_set_column_depth(cpl_table *, const char *, cpl_size); cpl_size cpl_table_get_column_depth(const cpl_table *, const char *); cpl_size cpl_table_get_column_dimensions(const cpl_table *, const char *); -cpl_error_code cpl_table_set_column_dimensions(cpl_table *, const char *, - const cpl_array *); -cpl_size cpl_table_get_column_dimension(const cpl_table *, - const char *, cpl_size); +cpl_error_code +cpl_table_set_column_dimensions(cpl_table *, const char *, const cpl_array *); +cpl_size +cpl_table_get_column_dimension(const cpl_table *, const char *, cpl_size); int *cpl_table_get_data_int(cpl_table *, const char *name); -const int *cpl_table_get_data_int_const(const cpl_table *, - const char *name); +const int *cpl_table_get_data_int_const(const cpl_table *, const char *name); long long *cpl_table_get_data_long_long(cpl_table *, const char *name); -const long long *cpl_table_get_data_long_long_const(const cpl_table *, - const char *name); +const long long * +cpl_table_get_data_long_long_const(const cpl_table *, const char *name); float *cpl_table_get_data_float(cpl_table *, const char *name); -const float *cpl_table_get_data_float_const(const cpl_table *, - const char *name); +const float * +cpl_table_get_data_float_const(const cpl_table *, const char *name); double *cpl_table_get_data_double(cpl_table *, const char *name); -const double *cpl_table_get_data_double_const(const cpl_table *, - const char *name); +const double * +cpl_table_get_data_double_const(const cpl_table *, const char *name); _Complex float *cpl_table_get_data_float_complex(cpl_table *, const char *name); -const _Complex float *cpl_table_get_data_float_complex_const(const cpl_table *, - const char *name); +const _Complex float * +cpl_table_get_data_float_complex_const(const cpl_table *, const char *name); _Complex double *cpl_table_get_data_double_complex(cpl_table *, const char *); -const _Complex double *cpl_table_get_data_double_complex_const(const cpl_table *, - const char *); +const _Complex double * +cpl_table_get_data_double_complex_const(const cpl_table *, const char *); char **cpl_table_get_data_string(cpl_table *, const char *name); -const char **cpl_table_get_data_string_const(const cpl_table *, - const char *name); +const char ** +cpl_table_get_data_string_const(const cpl_table *, const char *name); cpl_array **cpl_table_get_data_array(cpl_table *, const char *); -const cpl_array **cpl_table_get_data_array_const(const cpl_table *, - const char *); +const cpl_array ** +cpl_table_get_data_array_const(const cpl_table *, const char *); double cpl_table_get(const cpl_table *, const char *, cpl_size, int *null); int cpl_table_get_int(const cpl_table *, const char *, cpl_size, int *null); -long long cpl_table_get_long_long(const cpl_table *, const char *, cpl_size, - int *null); +long long +cpl_table_get_long_long(const cpl_table *, const char *, cpl_size, int *null); float cpl_table_get_float(const cpl_table *, const char *, cpl_size, int *null); -double cpl_table_get_double(const cpl_table *, const char *, cpl_size, - int *null); -_Complex double cpl_table_get_complex(const cpl_table *, - const char *, cpl_size, int *); -_Complex float cpl_table_get_float_complex(const cpl_table *, - const char *, cpl_size, int *null); -_Complex double cpl_table_get_double_complex(const cpl_table *, - const char *, cpl_size, int *null); +double +cpl_table_get_double(const cpl_table *, const char *, cpl_size, int *null); +_Complex double +cpl_table_get_complex(const cpl_table *, const char *, cpl_size, int *); +_Complex float cpl_table_get_float_complex(const cpl_table *, + const char *, + cpl_size, + int *null); +_Complex double cpl_table_get_double_complex(const cpl_table *, + const char *, + cpl_size, + int *null); const char *cpl_table_get_string(const cpl_table *, const char *, cpl_size); const cpl_array *cpl_table_get_array(const cpl_table *, const char *, cpl_size); cpl_error_code cpl_table_set(cpl_table *, const char *, cpl_size, double); cpl_error_code cpl_table_set_int(cpl_table *, const char *, cpl_size, int); -cpl_error_code cpl_table_set_long_long(cpl_table *, const char *, cpl_size, - long long); +cpl_error_code +cpl_table_set_long_long(cpl_table *, const char *, cpl_size, long long); cpl_error_code cpl_table_set_float(cpl_table *, const char *, cpl_size, float); -cpl_error_code cpl_table_set_double(cpl_table *, const char *, cpl_size, - double); -cpl_error_code cpl_table_set_complex(cpl_table *, - const char *, cpl_size, _Complex double); -cpl_error_code cpl_table_set_float_complex(cpl_table *, - const char *, cpl_size, _Complex float); -cpl_error_code cpl_table_set_double_complex(cpl_table *, - const char *, cpl_size, _Complex double); -cpl_error_code cpl_table_set_string(cpl_table *, const char *, cpl_size, - const char *); -cpl_error_code cpl_table_set_array(cpl_table *, const char *, cpl_size, - const cpl_array *); - -cpl_error_code cpl_table_fill_column_window(cpl_table *, const char *, - cpl_size, cpl_size, double); -cpl_error_code cpl_table_fill_column_window_int(cpl_table *, const char *, - cpl_size, cpl_size, int); -cpl_error_code cpl_table_fill_column_window_long_long(cpl_table *, const char *, - cpl_size, cpl_size, +cpl_error_code +cpl_table_set_double(cpl_table *, const char *, cpl_size, double); +cpl_error_code +cpl_table_set_complex(cpl_table *, const char *, cpl_size, _Complex double); +cpl_error_code cpl_table_set_float_complex(cpl_table *, + const char *, + cpl_size, + _Complex float); +cpl_error_code cpl_table_set_double_complex(cpl_table *, + const char *, + cpl_size, + _Complex double); +cpl_error_code +cpl_table_set_string(cpl_table *, const char *, cpl_size, const char *); +cpl_error_code +cpl_table_set_array(cpl_table *, const char *, cpl_size, const cpl_array *); + +cpl_error_code cpl_table_fill_column_window(cpl_table *, + const char *, + cpl_size, + cpl_size, + double); +cpl_error_code cpl_table_fill_column_window_int(cpl_table *, + const char *, + cpl_size, + cpl_size, + int); +cpl_error_code cpl_table_fill_column_window_long_long(cpl_table *, + const char *, + cpl_size, + cpl_size, long long); -cpl_error_code cpl_table_fill_column_window_float(cpl_table *, const char *, - cpl_size, cpl_size, float); -cpl_error_code cpl_table_fill_column_window_double(cpl_table *, const char *, - cpl_size, cpl_size, double); -cpl_error_code cpl_table_fill_column_window_complex(cpl_table *, const char *, - cpl_size, cpl_size, _Complex double); -cpl_error_code cpl_table_fill_column_window_float_complex(cpl_table *, - const char *, cpl_size, cpl_size, _Complex float); -cpl_error_code cpl_table_fill_column_window_double_complex(cpl_table *, - const char *, cpl_size, cpl_size, _Complex double); -cpl_error_code cpl_table_fill_column_window_string(cpl_table *, const char *, - cpl_size, cpl_size, const char *); -cpl_error_code cpl_table_fill_column_window_array(cpl_table *, const char *, - cpl_size, cpl_size, const cpl_array *); +cpl_error_code cpl_table_fill_column_window_float(cpl_table *, + const char *, + cpl_size, + cpl_size, + float); +cpl_error_code cpl_table_fill_column_window_double(cpl_table *, + const char *, + cpl_size, + cpl_size, + double); +cpl_error_code cpl_table_fill_column_window_complex(cpl_table *, + const char *, + cpl_size, + cpl_size, + _Complex double); +cpl_error_code cpl_table_fill_column_window_float_complex(cpl_table *, + const char *, + cpl_size, + cpl_size, + _Complex float); +cpl_error_code cpl_table_fill_column_window_double_complex(cpl_table *, + const char *, + cpl_size, + cpl_size, + _Complex double); +cpl_error_code cpl_table_fill_column_window_string(cpl_table *, + const char *, + cpl_size, + cpl_size, + const char *); +cpl_error_code cpl_table_fill_column_window_array(cpl_table *, + const char *, + cpl_size, + cpl_size, + const cpl_array *); cpl_error_code cpl_table_copy_data_int(cpl_table *, const char *, const int *); -cpl_error_code cpl_table_copy_data_long_long(cpl_table *, const char *, - const long long *); -cpl_error_code cpl_table_copy_data_float(cpl_table *, const char *, - const float *); -cpl_error_code cpl_table_copy_data_double(cpl_table *, const char *, - const double *); -cpl_error_code cpl_table_copy_data_float_complex(cpl_table *, const char *, +cpl_error_code +cpl_table_copy_data_long_long(cpl_table *, const char *, const long long *); +cpl_error_code +cpl_table_copy_data_float(cpl_table *, const char *, const float *); +cpl_error_code +cpl_table_copy_data_double(cpl_table *, const char *, const double *); +cpl_error_code cpl_table_copy_data_float_complex(cpl_table *, + const char *, const _Complex float *); -cpl_error_code cpl_table_copy_data_double_complex(cpl_table *, const char *, +cpl_error_code cpl_table_copy_data_double_complex(cpl_table *, + const char *, const _Complex double *); -cpl_error_code cpl_table_copy_data_string(cpl_table *, const char *, - const char **); +cpl_error_code +cpl_table_copy_data_string(cpl_table *, const char *, const char **); cpl_error_code cpl_table_shift_column(cpl_table *, const char *, cpl_size); cpl_error_code cpl_table_set_invalid(cpl_table *, const char *, cpl_size); -cpl_error_code cpl_table_set_column_invalid(cpl_table *, - const char *, cpl_size, cpl_size); +cpl_error_code +cpl_table_set_column_invalid(cpl_table *, const char *, cpl_size, cpl_size); int cpl_table_is_valid(const cpl_table *, const char *, cpl_size); cpl_size cpl_table_count_invalid(const cpl_table *, const char *); int cpl_table_has_invalid(const cpl_table *table, const char *name); int cpl_table_has_valid(const cpl_table *table, const char *name); -cpl_error_code cpl_table_fill_invalid_int(cpl_table *, const char *, - int); -cpl_error_code cpl_table_fill_invalid_long_long(cpl_table *, const char *, - long long); -cpl_error_code cpl_table_fill_invalid_float(cpl_table *, const char *, - float); -cpl_error_code cpl_table_fill_invalid_double(cpl_table *, const char *, - double); -cpl_error_code cpl_table_fill_invalid_float_complex(cpl_table *, const char *, - _Complex float); -cpl_error_code cpl_table_fill_invalid_double_complex(cpl_table *, const char *, - _Complex double); +cpl_error_code cpl_table_fill_invalid_int(cpl_table *, const char *, int); +cpl_error_code +cpl_table_fill_invalid_long_long(cpl_table *, const char *, long long); +cpl_error_code cpl_table_fill_invalid_float(cpl_table *, const char *, float); +cpl_error_code cpl_table_fill_invalid_double(cpl_table *, const char *, double); +cpl_error_code +cpl_table_fill_invalid_float_complex(cpl_table *, const char *, _Complex float); +cpl_error_code cpl_table_fill_invalid_double_complex(cpl_table *, + const char *, + _Complex double); cpl_error_code cpl_table_erase_column(cpl_table *, const char *); cpl_error_code cpl_table_move_column(cpl_table *, const char *, cpl_table *); -cpl_error_code cpl_table_duplicate_column(cpl_table *, const char *, - const cpl_table *, const char *); +cpl_error_code cpl_table_duplicate_column(cpl_table *, + const char *, + const cpl_table *, + const char *); cpl_error_code cpl_table_name_column(cpl_table *, const char *, const char *); int cpl_table_has_column(const cpl_table *, const char *); @@ -235,15 +272,12 @@ cpl_error_code cpl_table_set_size(cpl_table *, cpl_size); -cpl_table *cpl_table_duplicate(const cpl_table *) - CPL_ATTR_ALLOC; +cpl_table *cpl_table_duplicate(const cpl_table *) CPL_ATTR_ALLOC; -cpl_table *cpl_table_extract(const cpl_table *, cpl_size, cpl_size) - CPL_ATTR_ALLOC; -cpl_table *cpl_table_extract_selected(const cpl_table *) - CPL_ATTR_ALLOC; -cpl_array *cpl_table_where_selected(const cpl_table *) - CPL_ATTR_ALLOC; +cpl_table * +cpl_table_extract(const cpl_table *, cpl_size, cpl_size) CPL_ATTR_ALLOC; +cpl_table *cpl_table_extract_selected(const cpl_table *) CPL_ATTR_ALLOC; +cpl_array *cpl_table_where_selected(const cpl_table *) CPL_ATTR_ALLOC; cpl_error_code cpl_table_erase_selected(cpl_table *); cpl_error_code cpl_table_erase_window(cpl_table *, cpl_size, cpl_size); @@ -253,30 +287,29 @@ cpl_error_code cpl_table_insert(cpl_table *, const cpl_table *, cpl_size); -cpl_error_code cpl_table_cast_column(cpl_table *, - const char *, const char *, cpl_type); +cpl_error_code +cpl_table_cast_column(cpl_table *, const char *, const char *, cpl_type); -cpl_error_code cpl_table_add_columns(cpl_table *, - const char *, const char *); -cpl_error_code cpl_table_subtract_columns(cpl_table *, - const char *, const char *); -cpl_error_code cpl_table_multiply_columns(cpl_table *, - const char *, const char *); -cpl_error_code cpl_table_divide_columns(cpl_table *, - const char *, const char *); +cpl_error_code cpl_table_add_columns(cpl_table *, const char *, const char *); +cpl_error_code +cpl_table_subtract_columns(cpl_table *, const char *, const char *); +cpl_error_code +cpl_table_multiply_columns(cpl_table *, const char *, const char *); +cpl_error_code +cpl_table_divide_columns(cpl_table *, const char *, const char *); cpl_error_code cpl_table_add_scalar(cpl_table *, const char *, double); cpl_error_code cpl_table_subtract_scalar(cpl_table *, const char *, double); cpl_error_code cpl_table_multiply_scalar(cpl_table *, const char *, double); cpl_error_code cpl_table_divide_scalar(cpl_table *, const char *, double); -cpl_error_code cpl_table_add_scalar_complex(cpl_table *, - const char *, _Complex double); -cpl_error_code cpl_table_subtract_scalar_complex(cpl_table *, - const char *, _Complex double); -cpl_error_code cpl_table_multiply_scalar_complex(cpl_table *, - const char *, _Complex double); -cpl_error_code cpl_table_divide_scalar_complex(cpl_table *, - const char *, _Complex double); +cpl_error_code +cpl_table_add_scalar_complex(cpl_table *, const char *, _Complex double); +cpl_error_code +cpl_table_subtract_scalar_complex(cpl_table *, const char *, _Complex double); +cpl_error_code +cpl_table_multiply_scalar_complex(cpl_table *, const char *, _Complex double); +cpl_error_code +cpl_table_divide_scalar_complex(cpl_table *, const char *, _Complex double); cpl_error_code cpl_table_abs_column(cpl_table *, const char *); cpl_error_code cpl_table_logarithm_column(cpl_table *, const char *, double); cpl_error_code cpl_table_power_column(cpl_table *, const char *, double); @@ -291,13 +324,13 @@ double cpl_table_get_column_max(const cpl_table *, const char *); double cpl_table_get_column_min(const cpl_table *, const char *); -cpl_error_code cpl_table_get_column_maxpos(const cpl_table *, - const char *, cpl_size *); -cpl_error_code cpl_table_get_column_minpos(const cpl_table *, - const char *, cpl_size *); +cpl_error_code +cpl_table_get_column_maxpos(const cpl_table *, const char *, cpl_size *); +cpl_error_code +cpl_table_get_column_minpos(const cpl_table *, const char *, cpl_size *); -_Complex double cpl_table_get_column_mean_complex(const cpl_table *, - const char *); +_Complex double +cpl_table_get_column_mean_complex(const cpl_table *, const char *); double cpl_table_get_column_mean(const cpl_table *, const char *); double cpl_table_get_column_median(const cpl_table *, const char *); double cpl_table_get_column_stdev(const cpl_table *, const char *); @@ -317,40 +350,72 @@ cpl_size cpl_table_and_selected_invalid(cpl_table *, const char *); cpl_size cpl_table_or_selected_invalid(cpl_table *, const char *); -cpl_size cpl_table_and_selected_int(cpl_table *, const char *, - cpl_table_select_operator, int); -cpl_size cpl_table_or_selected_int(cpl_table *, const char *, - cpl_table_select_operator, int); -cpl_size cpl_table_and_selected_long_long(cpl_table *, const char *, - cpl_table_select_operator, long long); -cpl_size cpl_table_or_selected_long_long(cpl_table *, const char *, - cpl_table_select_operator, long long); -cpl_size cpl_table_and_selected_float(cpl_table *, const char *, - cpl_table_select_operator, float); -cpl_size cpl_table_or_selected_float(cpl_table *, const char *, - cpl_table_select_operator, float); -cpl_size cpl_table_and_selected_double(cpl_table *, const char *, - cpl_table_select_operator, double); -cpl_size cpl_table_or_selected_double(cpl_table *, const char *, - cpl_table_select_operator, double); -cpl_size cpl_table_and_selected_float_complex(cpl_table *, const char *, - cpl_table_select_operator, _Complex float); -cpl_size cpl_table_or_selected_float_complex(cpl_table *, const char *, - cpl_table_select_operator, _Complex float); -cpl_size cpl_table_and_selected_double_complex(cpl_table *, const char *, - cpl_table_select_operator, _Complex double); -cpl_size cpl_table_or_selected_double_complex(cpl_table *, const char *, - cpl_table_select_operator, _Complex double); - -cpl_size cpl_table_and_selected_string(cpl_table *, const char *, - cpl_table_select_operator, const char *); -cpl_size cpl_table_or_selected_string(cpl_table *, const char *, - cpl_table_select_operator, const char *); - -cpl_size cpl_table_and_selected(cpl_table *, const char *, - cpl_table_select_operator, const char *); -cpl_size cpl_table_or_selected(cpl_table *, const char *, - cpl_table_select_operator, const char *); +cpl_size cpl_table_and_selected_int(cpl_table *, + const char *, + cpl_table_select_operator, + int); +cpl_size cpl_table_or_selected_int(cpl_table *, + const char *, + cpl_table_select_operator, + int); +cpl_size cpl_table_and_selected_long_long(cpl_table *, + const char *, + cpl_table_select_operator, + long long); +cpl_size cpl_table_or_selected_long_long(cpl_table *, + const char *, + cpl_table_select_operator, + long long); +cpl_size cpl_table_and_selected_float(cpl_table *, + const char *, + cpl_table_select_operator, + float); +cpl_size cpl_table_or_selected_float(cpl_table *, + const char *, + cpl_table_select_operator, + float); +cpl_size cpl_table_and_selected_double(cpl_table *, + const char *, + cpl_table_select_operator, + double); +cpl_size cpl_table_or_selected_double(cpl_table *, + const char *, + cpl_table_select_operator, + double); +cpl_size cpl_table_and_selected_float_complex(cpl_table *, + const char *, + cpl_table_select_operator, + _Complex float); +cpl_size cpl_table_or_selected_float_complex(cpl_table *, + const char *, + cpl_table_select_operator, + _Complex float); +cpl_size cpl_table_and_selected_double_complex(cpl_table *, + const char *, + cpl_table_select_operator, + _Complex double); +cpl_size cpl_table_or_selected_double_complex(cpl_table *, + const char *, + cpl_table_select_operator, + _Complex double); + +cpl_size cpl_table_and_selected_string(cpl_table *, + const char *, + cpl_table_select_operator, + const char *); +cpl_size cpl_table_or_selected_string(cpl_table *, + const char *, + cpl_table_select_operator, + const char *); + +cpl_size cpl_table_and_selected(cpl_table *, + const char *, + cpl_table_select_operator, + const char *); +cpl_size cpl_table_or_selected(cpl_table *, + const char *, + cpl_table_select_operator, + const char *); int cpl_table_is_selected(const cpl_table *, cpl_size); cpl_size cpl_table_count_selected(const cpl_table *); @@ -358,17 +423,20 @@ void cpl_table_dump_structure(const cpl_table *, FILE *); void cpl_table_dump(const cpl_table *, cpl_size, cpl_size, FILE *); -cpl_table *cpl_table_load(const char *, int, int) - CPL_ATTR_ALLOC; -cpl_table *cpl_table_load_window(const char *, int, int, const cpl_array *, - cpl_size, cpl_size) - CPL_ATTR_ALLOC; -cpl_error_code cpl_table_save(const cpl_table *, const cpl_propertylist *, - const cpl_propertylist *, const char *filename, +cpl_table *cpl_table_load(const char *, int, int) CPL_ATTR_ALLOC; +cpl_table *cpl_table_load_window(const char *, + int, + int, + const cpl_array *, + cpl_size, + cpl_size) CPL_ATTR_ALLOC; +cpl_error_code cpl_table_save(const cpl_table *, + const cpl_propertylist *, + const cpl_propertylist *, + const char *filename, unsigned mode); CPL_END_DECLS #endif /* end of cpl_table.h */ - diff -Nru cpl-7.1.4+ds/cplcore/cpl_test.c cpl-7.2.2+ds/cplcore/cpl_test.c --- cpl-7.1.4+ds/cplcore/cpl_test.c 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_test.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -129,14 +129,14 @@ -----------------------------------------------------------------------------*/ static cpl_errorstate cleanstate; -static cpl_size cpl_test_count = 0; -static cpl_size cpl_test_failures = 0; -static const char * cpl_test_report = NULL; -static double cpl_test_time_start; -static double cpl_test_time_one; -static cpl_flops cpl_test_flops_one = 0; +static cpl_size cpl_test_count = 0; +static cpl_size cpl_test_failures = 0; +static const char *cpl_test_report = NULL; +static double cpl_test_time_start; +static double cpl_test_time_one; +static cpl_flops cpl_test_flops_one = 0; /* O: Uninitialized, 1: Initialized, 2: Deinitialized */ -static int cpl_test_state_ = 0; +static int cpl_test_state_ = 0; /*----------------------------------------------------------------------------- Private function prototypes @@ -145,20 +145,26 @@ static void cpl_test_reset(cpl_errorstate); static void cpl_errorstate_dump_debug(unsigned, unsigned, unsigned); static void cpl_errorstate_dump_info(unsigned, unsigned, unsigned); -static const char * cpl_test_get_description(void) CPL_ATTR_CONST; -static void cpl_test_one(int, double, cpl_flops, cpl_errorstate, cpl_boolean, - const char *, cpl_boolean, const char *, - const char *, unsigned) CPL_ATTR_NONNULL; +static const char *cpl_test_get_description(void) CPL_ATTR_CONST; +static void cpl_test_one(int, + double, + cpl_flops, + cpl_errorstate, + cpl_boolean, + const char *, + cpl_boolean, + const char *, + const char *, + unsigned) CPL_ATTR_NONNULL; static void cpl_test_dump_status(void); -static char * cpl_test_fits_file(const char *, const char *) CPL_ATTR_NONNULL; +static char *cpl_test_fits_file(const char *, const char *) CPL_ATTR_NONNULL; /*----------------------------------------------------------------------------- Function codes -----------------------------------------------------------------------------*/ - /*----------------------------------------------------------------------------*/ /** @brief Get the process CPU time, when available (from times()) @@ -188,8 +194,9 @@ */ /*----------------------------------------------------------------------------*/ -double cpl_test_get_cputime(void) { - +double +cpl_test_get_cputime(void) +{ #if defined HAVE_SYS_TIMES_H && defined HAVE_SYSCONF && defined _SC_CLK_TCK struct tms buf; @@ -203,7 +210,6 @@ return 0.0; #endif - } /*----------------------------------------------------------------------------*/ @@ -238,27 +244,29 @@ */ /*----------------------------------------------------------------------------*/ -double cpl_test_get_walltime(void) { - +double +cpl_test_get_walltime(void) +{ #ifdef CPL_HAVE_CLOCK_GETTIME struct timespec buf; - return clock_gettime(CLOCK_REALTIME, &buf) ? 0.0 - : (double)buf.tv_sec + 1.0e-9* (double)buf.tv_nsec; + return clock_gettime(CLOCK_REALTIME, &buf) + ? 0.0 + : (double)buf.tv_sec + 1.0e-9 * (double)buf.tv_nsec; #elif defined CPL_HAVE_GETTIMEOFDAY struct timeval buf; - return gettimeofday(&buf, 0) ? 0.0 - : (double)buf.tv_sec + 1.0e-6 * (double)buf.tv_usec; + return gettimeofday(&buf, 0) + ? 0.0 + : (double)buf.tv_sec + 1.0e-6 * (double)buf.tv_usec; #else return 0.0; #endif - } /*----------------------------------------------------------------------------*/ @@ -270,7 +278,8 @@ */ /*----------------------------------------------------------------------------*/ -inline cpl_flops cpl_test_get_flops(void) +inline cpl_flops +cpl_test_get_flops(void) { return cpl_tools_get_flops(); } @@ -283,7 +292,8 @@ */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_test_get_tested(void) +cpl_size +cpl_test_get_tested(void) { return cpl_test_count; } @@ -312,7 +322,8 @@ */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_test_get_failed(void) +cpl_size +cpl_test_get_failed(void) { return cpl_test_failures; } @@ -350,10 +361,11 @@ */ /*----------------------------------------------------------------------------*/ -size_t cpl_test_get_bytes_vector(const cpl_vector * self) +size_t +cpl_test_get_bytes_vector(const cpl_vector *self) { return self == NULL ? 0 - : (size_t)cpl_vector_get_size(self) * sizeof(double); + : (size_t)cpl_vector_get_size(self) * sizeof(double); } /*----------------------------------------------------------------------------*/ @@ -366,11 +378,13 @@ */ /*----------------------------------------------------------------------------*/ -size_t cpl_test_get_bytes_matrix(const cpl_matrix * self) +size_t +cpl_test_get_bytes_matrix(const cpl_matrix *self) { - return self == NULL ? 0 - : (size_t)cpl_matrix_get_nrow(self) - * (size_t)cpl_matrix_get_ncol(self) * sizeof(double); + return self == NULL + ? 0 + : (size_t)cpl_matrix_get_nrow(self) * + (size_t)cpl_matrix_get_ncol(self) * sizeof(double); } /*----------------------------------------------------------------------------*/ @@ -383,12 +397,13 @@ */ /*----------------------------------------------------------------------------*/ -size_t cpl_test_get_bytes_image(const cpl_image * self) +size_t +cpl_test_get_bytes_image(const cpl_image *self) { return self == NULL ? 0 - : (size_t)cpl_image_get_size_x(self) - * (size_t)cpl_image_get_size_y(self) - * cpl_type_get_sizeof(cpl_image_get_type(self)); + : (size_t)cpl_image_get_size_x(self) * + (size_t)cpl_image_get_size_y(self) * + cpl_type_get_sizeof(cpl_image_get_type(self)); } /*----------------------------------------------------------------------------*/ @@ -401,11 +416,13 @@ */ /*----------------------------------------------------------------------------*/ -size_t cpl_test_get_bytes_imagelist(const cpl_imagelist * self) +size_t +cpl_test_get_bytes_imagelist(const cpl_imagelist *self) { return self == NULL ? 0 - : (size_t)cpl_imagelist_get_size(self) - * (size_t)cpl_test_get_bytes_image(cpl_imagelist_get_const(self, 0)); + : (size_t)cpl_imagelist_get_size(self) * + (size_t)cpl_test_get_bytes_image( + cpl_imagelist_get_const(self, 0)); } /*----------------------------------------------------------------------------*/ @@ -421,30 +438,31 @@ */ /*----------------------------------------------------------------------------*/ -void cpl_test_init_macro(const char * filename, const char * report, - cpl_msg_severity default_level) +void +cpl_test_init_macro(const char *filename, + const char *report, + cpl_msg_severity default_level) { - /* ISO/IEC 9899:1999 (E) 7.5 3: + /* ISO/IEC 9899:1999 (E) 7.5 3: The value of errno is zero at program startup, but is never set to zero by any library function. The value of errno may be set to nonzero by a library function call whether or not there is an error, provided the use of errno is not documented in the description of the function in this International Standard. */ - /* As such it is safe to read errno at this stage, + /* As such it is safe to read errno at this stage, but a non-zero value has no significance. */ const int errnopre = errno; int errnoini; - assert(report != NULL); + assert(report != NULL); assert(filename != NULL); #ifdef _OPENMP #pragma omp master #endif { - cpl_test_report = report; errno = 0; @@ -456,7 +474,7 @@ cpl_init(CPL_INIT_DEFAULT); cpl_test_time_start = cpl_test_get_walltime(); - cpl_test_time_one = cpl_test_time_start; + cpl_test_time_one = cpl_test_time_start; errnoini = errno; errno = 0; @@ -464,18 +482,17 @@ /* Needed on alphaev56 */ if (signal(SIGFPE, SIG_IGN) == SIG_ERR) { cpl_msg_warning(cpl_func, "Could not install new signal handler " - "(SIG_IGN) for SIGFPE"); + "(SIG_IGN) for SIGFPE"); } cleanstate = cpl_errorstate_get(); - + cpl_msg_set_level(default_level); cpl_msg_set_level_from_env(); if (filename != NULL) { - - const char * dotpos = NULL; - char * logfile = NULL; + const char *dotpos = NULL; + char *logfile = NULL; /* Create a new string, where the extension is replaced with .log */ /* First trim away any directory names before the filename. Check @@ -483,16 +500,19 @@ means no files can have these characters in their name, which is a reasonable requirement for portable software anyway. */ - const char * fslashpos = strrchr(filename, '\\'); - const char * bslashpos = strrchr(filename, '/'); - const char * slashpos = bslashpos > fslashpos ? bslashpos : fslashpos; - if (slashpos != NULL) filename = slashpos+1; + const char *fslashpos = strrchr(filename, '\\'); + const char *bslashpos = strrchr(filename, '/'); + const char *slashpos = + bslashpos > fslashpos ? bslashpos : fslashpos; + if (slashpos != NULL) + filename = slashpos + 1; /* Check the special case of having filename = "..". In that case set filename to use "." instead, so that we end up with having ".log" as the log file name. */ - if (strcmp(filename, "..") == 0) filename = "."; - + if (strcmp(filename, "..") == 0) + filename = "."; + /* Append .log in case there is no extension. In case there is an extension shorter than three characters, the new string will also be (more than) long enough for the .log extension. @@ -511,7 +531,7 @@ if (cpl_error_get_code()) { /* The log-file name could not be set */ cpl_msg_warning(cpl_func, "Ignoring failed setting of " - "log-file:"); + "log-file:"); cpl_errorstate_dump(cleanstate, CPL_FALSE, cpl_errorstate_dump_one_warning); @@ -519,12 +539,11 @@ } /* Drop .log */ - logfile[strlen(logfile)-strlen(".log")] = '\0'; + logfile[strlen(logfile) - strlen(".log")] = '\0'; cpl_msg_set_domain(logfile); cpl_free(logfile); - } cpl_msg_set_log_level(CPL_MSG_DEBUG); @@ -532,7 +551,8 @@ if (errnopre != 0) { /* May be useful for debugging - but see the above errno comment */ /* See also DFS04285 */ - cpl_msg_debug(cpl_func, "%s() was called with errno=%d: %s (Unless " + cpl_msg_debug(cpl_func, + "%s() was called with errno=%d: %s (Unless " "you are debugging code prior to the cpl_init() call " "you can ignore this message)", cpl_func, errnopre, strerror(errnopre)); @@ -540,11 +560,12 @@ if (errnoini != 0) { /* May be useful for debugging - but see the above errno comment */ - cpl_msg_debug(cpl_func, "cpl_init() set errno=%d: %s (Unless " + cpl_msg_debug(cpl_func, + "cpl_init() set errno=%d: %s (Unless " "you are debugging cpl_init() you can ignore " - "this message)", errnoini, strerror(errnoini)); + "this message)", + errnoini, strerror(errnoini)); } - } #ifdef _OPENMP @@ -595,18 +616,24 @@ */ /*----------------------------------------------------------------------------*/ -void cpl_test_macro(int errnopre, double twallpre, cpl_flops flopspre, - cpl_errorstate statepre, cpl_size expression, - cpl_boolean fail_on_zero, const char * expr_txt, - const char * function, const char * file, unsigned line) -{ - - char * message = cpl_sprintf(fail_on_zero ? "(%s) = %" CPL_SIZE_FORMAT : - "(%s) = %" CPL_SIZE_FORMAT " <=> 0", - expr_txt, expression); - const cpl_boolean bool = fail_on_zero - ? (expression ? CPL_TRUE : CPL_FALSE) - : (expression ? CPL_FALSE : CPL_TRUE); +void +cpl_test_macro(int errnopre, + double twallpre, + cpl_flops flopspre, + cpl_errorstate statepre, + cpl_size expression, + cpl_boolean fail_on_zero, + const char *expr_txt, + const char *function, + const char *file, + unsigned line) +{ + char *message = + cpl_sprintf(fail_on_zero ? "(%s) = %" CPL_SIZE_FORMAT + : "(%s) = %" CPL_SIZE_FORMAT " <=> 0", + expr_txt, expression); + const cpl_boolean bool = fail_on_zero ? (expression ? CPL_TRUE : CPL_FALSE) + : (expression ? CPL_FALSE : CPL_TRUE); cpl_test_one(errnopre, twallpre, flopspre, statepre, bool, message, CPL_FALSE, function, file, line); @@ -634,19 +661,22 @@ */ /*----------------------------------------------------------------------------*/ -void cpl_test_null_macro(int errnopre, double twallpre, cpl_flops flopspre, - cpl_errorstate statepre, - const void * pointer, const char * pointer_string, - const char * function, const char * file, - unsigned line) +void +cpl_test_null_macro(int errnopre, + double twallpre, + cpl_flops flopspre, + cpl_errorstate statepre, + const void *pointer, + const char *pointer_string, + const char *function, + const char *file, + unsigned line) { - - char * message = cpl_sprintf("(%s) = %p == NULL", pointer_string, - pointer); + char *message = cpl_sprintf("(%s) = %p == NULL", pointer_string, pointer); cpl_test_one(errnopre, twallpre, flopspre, statepre, - pointer == NULL ? CPL_TRUE : CPL_FALSE, - message, CPL_FALSE, function, file, line); + pointer == NULL ? CPL_TRUE : CPL_FALSE, message, CPL_FALSE, + function, file, line); cpl_free(message); @@ -671,19 +701,22 @@ */ /*----------------------------------------------------------------------------*/ -void cpl_test_nonnull_macro(int errnopre, double twallpre, cpl_flops flopspre, - cpl_errorstate statepre, - const void * pointer, const char * pointer_string, - const char * function, const char * file, - unsigned line) +void +cpl_test_nonnull_macro(int errnopre, + double twallpre, + cpl_flops flopspre, + cpl_errorstate statepre, + const void *pointer, + const char *pointer_string, + const char *function, + const char *file, + unsigned line) { - - char * message = cpl_sprintf("(%s) = %p != NULL", pointer_string, - pointer); + char *message = cpl_sprintf("(%s) = %p != NULL", pointer_string, pointer); cpl_test_one(errnopre, twallpre, flopspre, statepre, - pointer != NULL ? CPL_TRUE : CPL_FALSE, - message, CPL_FALSE, function, file, line); + pointer != NULL ? CPL_TRUE : CPL_FALSE, message, CPL_FALSE, + function, file, line); cpl_free(message); @@ -710,20 +743,26 @@ */ /*----------------------------------------------------------------------------*/ -void cpl_test_eq_macro(int errnopre, double twallpre, cpl_flops flopspre, - cpl_errorstate statepre, - cpl_size first, const char * first_string, - cpl_size second, const char * second_string, - const char * function, const char * file, unsigned line) -{ - - char * message = cpl_sprintf("(%s) = %" CPL_SIZE_FORMAT "; (%s) = %" - CPL_SIZE_FORMAT, first_string, first, - second_string, second); +void +cpl_test_eq_macro(int errnopre, + double twallpre, + cpl_flops flopspre, + cpl_errorstate statepre, + cpl_size first, + const char *first_string, + cpl_size second, + const char *second_string, + const char *function, + const char *file, + unsigned line) +{ + char *message = + cpl_sprintf("(%s) = %" CPL_SIZE_FORMAT "; (%s) = %" CPL_SIZE_FORMAT, + first_string, first, second_string, second); cpl_test_one(errnopre, twallpre, flopspre, statepre, - first == second ? CPL_TRUE : CPL_FALSE, - message, CPL_FALSE, function, file, line); + first == second ? CPL_TRUE : CPL_FALSE, message, CPL_FALSE, + function, file, line); cpl_free(message); @@ -750,22 +789,26 @@ */ /*----------------------------------------------------------------------------*/ -void cpl_test_noneq_macro(int errnopre, double twallpre, cpl_flops flopspre, - cpl_errorstate statepre, - cpl_size first, const char * first_string, - cpl_size second, const char * second_string, - const char * function, const char * file, - unsigned line) -{ - - char * message = cpl_sprintf("(%s) = %" CPL_SIZE_FORMAT "; (%s) = %" - CPL_SIZE_FORMAT, - first_string, first, - second_string, second); +void +cpl_test_noneq_macro(int errnopre, + double twallpre, + cpl_flops flopspre, + cpl_errorstate statepre, + cpl_size first, + const char *first_string, + cpl_size second, + const char *second_string, + const char *function, + const char *file, + unsigned line) +{ + char *message = + cpl_sprintf("(%s) = %" CPL_SIZE_FORMAT "; (%s) = %" CPL_SIZE_FORMAT, + first_string, first, second_string, second); cpl_test_one(errnopre, twallpre, flopspre, statepre, - first != second ? CPL_TRUE : CPL_FALSE, - message, CPL_FALSE, function, file, line); + first != second ? CPL_TRUE : CPL_FALSE, message, CPL_FALSE, + function, file, line); cpl_free(message); @@ -793,21 +836,25 @@ */ /*----------------------------------------------------------------------------*/ -void cpl_test_eq_ptr_macro(int errnopre, double twallpre, cpl_flops flopspre, - cpl_errorstate statepre, - const void * first, const char * first_string, - const void * second, const char * second_string, - const char * function, const char * file, - unsigned line) +void +cpl_test_eq_ptr_macro(int errnopre, + double twallpre, + cpl_flops flopspre, + cpl_errorstate statepre, + const void *first, + const char *first_string, + const void *second, + const char *second_string, + const char *function, + const char *file, + unsigned line) { - - char * message = cpl_sprintf("(%s) = %p; (%s) = %p", - first_string, first, - second_string, second); + char *message = cpl_sprintf("(%s) = %p; (%s) = %p", first_string, first, + second_string, second); cpl_test_one(errnopre, twallpre, flopspre, statepre, - first == second ? CPL_TRUE : CPL_FALSE, - message, CPL_FALSE, function, file, line); + first == second ? CPL_TRUE : CPL_FALSE, message, CPL_FALSE, + function, file, line); cpl_free(message); @@ -834,21 +881,25 @@ */ /*----------------------------------------------------------------------------*/ -void cpl_test_noneq_ptr_macro(int errnopre, double twallpre, cpl_flops flopspre, - cpl_errorstate statepre, - const void * first, const char * first_string, - const void * second, const char * second_string, - const char * function, const char * file, - unsigned line) +void +cpl_test_noneq_ptr_macro(int errnopre, + double twallpre, + cpl_flops flopspre, + cpl_errorstate statepre, + const void *first, + const char *first_string, + const void *second, + const char *second_string, + const char *function, + const char *file, + unsigned line) { - - char * message = cpl_sprintf("(%s) = %p; (%s) = %p", - first_string, first, - second_string, second); + char *message = cpl_sprintf("(%s) = %p; (%s) = %p", first_string, first, + second_string, second); cpl_test_one(errnopre, twallpre, flopspre, statepre, - first != second ? CPL_TRUE : CPL_FALSE, - message, CPL_FALSE, function, file, line); + first != second ? CPL_TRUE : CPL_FALSE, message, CPL_FALSE, + function, file, line); cpl_free(message); @@ -874,25 +925,31 @@ @note This function should only be called from cpl_test_eq_string() */ /*----------------------------------------------------------------------------*/ -void cpl_test_eq_string_macro(int errnopre, double twallpre, cpl_flops flopspre, - cpl_errorstate statepre, - const char * first, const char * first_string, - const char * second, const char * second_string, - const char * function, - const char * file, unsigned line) -{ - char * fsquote = first == NULL ? NULL : cpl_sprintf("'%s'", first); - char * ssquote = second == NULL ? NULL : cpl_sprintf("'%s'", second); - const char * fquote = fsquote == NULL ? "NULL" : fsquote; - const char * squote = ssquote == NULL ? "NULL" : ssquote; - char * message = cpl_sprintf("%s = %s; %s = %s", first_string, fquote, - second_string, squote); +void +cpl_test_eq_string_macro(int errnopre, + double twallpre, + cpl_flops flopspre, + cpl_errorstate statepre, + const char *first, + const char *first_string, + const char *second, + const char *second_string, + const char *function, + const char *file, + unsigned line) +{ + char *fsquote = first == NULL ? NULL : cpl_sprintf("'%s'", first); + char *ssquote = second == NULL ? NULL : cpl_sprintf("'%s'", second); + const char *fquote = fsquote == NULL ? "NULL" : fsquote; + const char *squote = ssquote == NULL ? "NULL" : ssquote; + char *message = cpl_sprintf("%s = %s; %s = %s", first_string, fquote, + second_string, squote); cpl_free(fsquote); cpl_free(ssquote); cpl_test_one(errnopre, twallpre, flopspre, statepre, - first != NULL && second != NULL && strcmp(first, second) == 0, + first != NULL && second != NULL && strcmp(first, second) == 0, message, CPL_FALSE, function, file, line); cpl_free(message); @@ -920,26 +977,31 @@ @note This function should only be called from cpl_test_noneq_string() */ /*----------------------------------------------------------------------------*/ -void cpl_test_noneq_string_macro(int errnopre, double twallpre, - cpl_flops flopspre, cpl_errorstate statepre, - const char * first, const char * first_string, - const char * second, - const char * second_string, - const char * function, - const char * file, unsigned line) -{ - char * fsquote = first == NULL ? NULL : cpl_sprintf("'%s'", first); - char * ssquote = second == NULL ? NULL : cpl_sprintf("'%s'", second); - const char * fquote = fsquote == NULL ? "NULL" : fsquote; - const char * squote = ssquote == NULL ? "NULL" : ssquote; - char * message = cpl_sprintf("%s = %s; %s = %s", first_string, fquote, - second_string, squote); +void +cpl_test_noneq_string_macro(int errnopre, + double twallpre, + cpl_flops flopspre, + cpl_errorstate statepre, + const char *first, + const char *first_string, + const char *second, + const char *second_string, + const char *function, + const char *file, + unsigned line) +{ + char *fsquote = first == NULL ? NULL : cpl_sprintf("'%s'", first); + char *ssquote = second == NULL ? NULL : cpl_sprintf("'%s'", second); + const char *fquote = fsquote == NULL ? "NULL" : fsquote; + const char *squote = ssquote == NULL ? "NULL" : ssquote; + char *message = cpl_sprintf("%s = %s; %s = %s", first_string, fquote, + second_string, squote); cpl_free(fsquote); cpl_free(ssquote); cpl_test_one(errnopre, twallpre, flopspre, statepre, - first != NULL && second != NULL && strcmp(first, second) != 0, + first != NULL && second != NULL && strcmp(first, second) != 0, message, CPL_FALSE, function, file, line); cpl_free(message); @@ -966,46 +1028,56 @@ */ /*----------------------------------------------------------------------------*/ -void cpl_test_fits_macro(int errnopre, double twallpre, cpl_flops flopspre, - cpl_errorstate statepre, - const char * filename, const char * filename_string, - const char * function, const char * file, - unsigned line) +void +cpl_test_fits_macro(int errnopre, + double twallpre, + cpl_flops flopspre, + cpl_errorstate statepre, + const char *filename, + const char *filename_string, + const char *function, + const char *file, + unsigned line) { - const char * checker = getenv(CPL_TEST_FITS); - char * message; + const char *checker = getenv(CPL_TEST_FITS); + char *message; cpl_boolean expression; if (filename == NULL) { message = cpl_sprintf(CPL_TEST_FITS " unusable on NULL-file " - "%s", filename_string); + "%s", + filename_string); expression = CPL_FALSE; /* Unable to do an actual test */ - } else if (checker == NULL) { - + } + else if (checker == NULL) { message = cpl_test_fits_file(filename, filename_string); if (message != NULL) { expression = CPL_FALSE; /* File cannot be FITS */ - } else { + } + else { /* The previous FITS validation is so primitive that its success is not reported */ message = cpl_sprintf(CPL_TEST_FITS " undefined for file %s='%s', " - "try: export " CPL_TEST_FITS "=fitsverify", + "try: export " CPL_TEST_FITS + "=fitsverify", filename_string, filename); expression = CPL_TRUE; /* Unable to do an actual test */ } - } else { - const char * redir = cpl_msg_get_level() < CPL_MSG_WARNING ? "" - : (cpl_msg_get_level() < CPL_MSG_ERROR ? " > /dev/null" - : " > /dev/null 2>&1"); - char * cmd = cpl_sprintf("%s %s %s", checker, filename, redir); + } + else { + const char *redir = + cpl_msg_get_level() < CPL_MSG_WARNING + ? "" + : (cpl_msg_get_level() < CPL_MSG_ERROR ? " > /dev/null" + : " > /dev/null 2>&1"); + char *cmd = cpl_sprintf("%s %s %s", checker, filename, redir); - message = cpl_sprintf(CPL_TEST_FITS " on file %s: %s", - filename_string, cmd); + message = + cpl_sprintf(CPL_TEST_FITS " on file %s: %s", filename_string, cmd); expression = system(cmd) == 0 ? CPL_TRUE : CPL_FALSE; cpl_free(cmd); - } cpl_test_one(errnopre, twallpre, flopspre, statepre, expression, message, @@ -1035,42 +1107,50 @@ @note This function should only be called from cpl_test_eq_mask() */ /*----------------------------------------------------------------------------*/ -void cpl_test_eq_mask_macro(int errnopre, double twallpre, cpl_flops flopspre, - cpl_errorstate statepre, - const cpl_mask * first, const char * first_string, - const cpl_mask * second, const char * second_string, - const char * function, const char * file, - unsigned line) +void +cpl_test_eq_mask_macro(int errnopre, + double twallpre, + cpl_flops flopspre, + cpl_errorstate statepre, + const cpl_mask *first, + const char *first_string, + const cpl_mask *second, + const char *second_string, + const char *function, + const char *file, + unsigned line) { cpl_errorstate mystate = cpl_errorstate_get(); const cpl_size nx1 = cpl_mask_get_size_x(first); const cpl_size ny1 = cpl_mask_get_size_y(first); const cpl_size nx2 = cpl_mask_get_size_x(second); const cpl_size ny2 = cpl_mask_get_size_y(second); - cpl_boolean expression; - char * message; + cpl_boolean expression; + char *message; if (!cpl_errorstate_is_equal(mystate)) { cpl_error_set(cpl_func, cpl_error_get_code()); expression = CPL_FALSE; - message = cpl_sprintf("%s <=> %s input error", - first_string, second_string); - } else if (nx1 != nx2 || ny1 != ny2) { + message = + cpl_sprintf("%s <=> %s input error", first_string, second_string); + } + else if (nx1 != nx2 || ny1 != ny2) { expression = CPL_FALSE; - message = cpl_sprintf("%s <=> %s incompatible input, nx: %" - CPL_SIZE_FORMAT " <=> %" CPL_SIZE_FORMAT ", ny: %" - CPL_SIZE_FORMAT " <=> %" CPL_SIZE_FORMAT, - first_string, second_string, - nx1, nx2, ny1, ny2); - } else if (memcmp(cpl_mask_get_data_const(first), - cpl_mask_get_data_const(second), (size_t)(nx1 * ny1))) { + message = + cpl_sprintf("%s <=> %s incompatible input, nx: %" CPL_SIZE_FORMAT + " <=> %" CPL_SIZE_FORMAT ", ny: %" CPL_SIZE_FORMAT + " <=> %" CPL_SIZE_FORMAT, + first_string, second_string, nx1, nx2, ny1, ny2); + } + else if (memcmp(cpl_mask_get_data_const(first), + cpl_mask_get_data_const(second), (size_t)(nx1 * ny1))) { /* The test has failed, now spend extra time to report why */ cpl_size i; cpl_size k = 0; cpl_size n = 0; - const cpl_binary * pbpm1 = cpl_mask_get_data_const(first); - const cpl_binary * pbpm2 = cpl_mask_get_data_const(second); + const cpl_binary *pbpm1 = cpl_mask_get_data_const(first); + const cpl_binary *pbpm2 = cpl_mask_get_data_const(second); for (i = 0; i < nx1 * ny1; i++) { if (pbpm1[i] != pbpm2[i]) { @@ -1078,19 +1158,20 @@ n++; } } - assert( n != 0 ); + assert(n != 0); expression = CPL_FALSE; - message - = cpl_sprintf("%s(%" CPL_SIZE_FORMAT ",%" CPL_SIZE_FORMAT - ") = %u <=> %u = %s(%" CPL_SIZE_FORMAT ",%" - CPL_SIZE_FORMAT ") (%" CPL_SIZE_FORMAT " of %" - CPL_SIZE_FORMAT " x %" CPL_SIZE_FORMAT " " - "differ(s))", first_string, 1+k%nx1, 1+k/nx1, - (unsigned)pbpm1[k], (unsigned)pbpm2[k], second_string, - 1+k%nx2, 1+k/nx2, n, nx1, ny1); - - } else { + message = + cpl_sprintf("%s(%" CPL_SIZE_FORMAT ",%" CPL_SIZE_FORMAT + ") = %u <=> %u = %s(%" CPL_SIZE_FORMAT + ",%" CPL_SIZE_FORMAT ") (%" CPL_SIZE_FORMAT + " of %" CPL_SIZE_FORMAT " x %" CPL_SIZE_FORMAT " " + "differ(s))", + first_string, 1 + k % nx1, 1 + k / nx1, + (unsigned)pbpm1[k], (unsigned)pbpm2[k], second_string, + 1 + k % nx2, 1 + k / nx2, n, nx1, ny1); + } + else { expression = CPL_TRUE; message = cpl_sprintf("%s == %s", first_string, second_string); } @@ -1123,16 +1204,22 @@ */ /*----------------------------------------------------------------------------*/ -void cpl_test_leq_macro(int errnopre, double twallpre, cpl_flops flopspre, - cpl_errorstate statepre, - double value, const char * value_string, - double tolerance, const char * tolerance_string, - const char * function, const char * file, unsigned line) -{ - const cpl_boolean expression - = (value <= tolerance) ? CPL_TRUE : CPL_FALSE; - char * message = cpl_sprintf("%s = %g <= %g = %s", value_string, - value, tolerance, tolerance_string); +void +cpl_test_leq_macro(int errnopre, + double twallpre, + cpl_flops flopspre, + cpl_errorstate statepre, + double value, + const char *value_string, + double tolerance, + const char *tolerance_string, + const char *function, + const char *file, + unsigned line) +{ + const cpl_boolean expression = (value <= tolerance) ? CPL_TRUE : CPL_FALSE; + char *message = cpl_sprintf("%s = %g <= %g = %s", value_string, value, + tolerance, tolerance_string); cpl_test_one(errnopre, twallpre, flopspre, statepre, expression, message, CPL_FALSE, function, file, line); @@ -1161,16 +1248,22 @@ */ /*----------------------------------------------------------------------------*/ -void cpl_test_lt_macro(int errnopre, double twallpre, cpl_flops flopspre, - cpl_errorstate statepre, - double value, const char * value_string, - double tolerance, const char * tolerance_string, - const char * function, const char * file, unsigned line) -{ - const cpl_boolean expression - = (value < tolerance) ? CPL_TRUE : CPL_FALSE; - char * message = cpl_sprintf("%s = %g < %g = %s", value_string, - value, tolerance, tolerance_string); +void +cpl_test_lt_macro(int errnopre, + double twallpre, + cpl_flops flopspre, + cpl_errorstate statepre, + double value, + const char *value_string, + double tolerance, + const char *tolerance_string, + const char *function, + const char *file, + unsigned line) +{ + const cpl_boolean expression = (value < tolerance) ? CPL_TRUE : CPL_FALSE; + char *message = cpl_sprintf("%s = %g < %g = %s", value_string, value, + tolerance, tolerance_string); cpl_test_one(errnopre, twallpre, flopspre, statepre, expression, message, CPL_FALSE, function, file, line); @@ -1203,19 +1296,26 @@ @note This function should only be called from the macro cpl_test_abs() */ /*----------------------------------------------------------------------------*/ -void cpl_test_abs_macro(int errnopre, double twallpre, cpl_flops flopspre, - cpl_errorstate statepre, - double first, const char *first_string, - double second, const char *second_string, - double tolerance, const char *tolerance_string, - const char *function, const char *file, unsigned line) +void +cpl_test_abs_macro(int errnopre, + double twallpre, + cpl_flops flopspre, + cpl_errorstate statepre, + double first, + const char *first_string, + double second, + const char *second_string, + double tolerance, + const char *tolerance_string, + const char *function, + const char *file, + unsigned line) { - const cpl_boolean expression - = (fabs(first - second) <= tolerance) ? CPL_TRUE : CPL_FALSE; + const cpl_boolean expression = + (fabs(first - second) <= tolerance) ? CPL_TRUE : CPL_FALSE; char *message = cpl_sprintf("|%s - %s| = |%g - %g| = |%g| <= %g = %s", - first_string, second_string, first, - second, first - second, tolerance, - tolerance_string); + first_string, second_string, first, second, + first - second, tolerance, tolerance_string); cpl_test_one(errnopre, twallpre, flopspre, statepre, expression, message, CPL_FALSE, function, file, line); @@ -1249,27 +1349,30 @@ cpl_test_abs_complex() */ /*----------------------------------------------------------------------------*/ -void cpl_test_abs_complex_macro(int errnopre, double twallpre, - cpl_flops flopspre, cpl_errorstate statepre, - double complex first, - const char *first_string, - double complex second, - const char *second_string, - double tolerance, - const char *tolerance_string, - const char *function, const char *file, - unsigned line) -{ - const cpl_boolean expression - = (cabs(first - second) <= tolerance) ? CPL_TRUE : CPL_FALSE; - char *message = - cpl_sprintf("|%s - %s| = |(%g%+gi) - (%g%+gi)| = " - "|%g%+gi| = %g <= %g = %s", - first_string, second_string, creal(first), - cimag(first), creal(second), cimag(second), - creal(first - second), cimag(first - second), - cabs(first - second), - tolerance, tolerance_string); +void +cpl_test_abs_complex_macro(int errnopre, + double twallpre, + cpl_flops flopspre, + cpl_errorstate statepre, + double complex first, + const char *first_string, + double complex second, + const char *second_string, + double tolerance, + const char *tolerance_string, + const char *function, + const char *file, + unsigned line) +{ + const cpl_boolean expression = + (cabs(first - second) <= tolerance) ? CPL_TRUE : CPL_FALSE; + char *message = + cpl_sprintf("|%s - %s| = |(%g%+gi) - (%g%+gi)| = " + "|%g%+gi| = %g <= %g = %s", + first_string, second_string, creal(first), cimag(first), + creal(second), cimag(second), creal(first - second), + cimag(first - second), cabs(first - second), tolerance, + tolerance_string); cpl_test_one(errnopre, twallpre, flopspre, statepre, expression, message, CPL_FALSE, function, file, line); @@ -1302,62 +1405,75 @@ @note This function should only be called from the macro cpl_test_rel() */ /*----------------------------------------------------------------------------*/ -void cpl_test_rel_macro(int errnopre, double twallpre, cpl_flops flopspre, - cpl_errorstate statepre, - double first, const char *first_string, - double second, const char *second_string, - double tolerance, const char *tolerance_string, - const char *function, const char *file, unsigned line) +void +cpl_test_rel_macro(int errnopre, + double twallpre, + cpl_flops flopspre, + cpl_errorstate statepre, + double first, + const char *first_string, + double second, + const char *second_string, + double tolerance, + const char *tolerance_string, + const char *function, + const char *file, + unsigned line) { - char * message = NULL; /* Avoid (false) uninit warnings */ + char *message = NULL; /* Avoid (false) uninit warnings */ cpl_boolean expression; if (tolerance < 0.0) { expression = CPL_FALSE; message = cpl_sprintf("%s = %g; %s = %g. Negative tolerance %s = %g", - first_string, first, - second_string, second, + first_string, first, second_string, second, tolerance_string, tolerance); - } else if (first == second) { + } + else if (first == second) { /* Not needed. Used only for prettier messaging */ expression = CPL_TRUE; - message = cpl_sprintf("%s = %g = %s. (Tolerance %s = %g)", - first_string, first, second_string, - tolerance_string, tolerance); - - } else if (first == 0.0) { + message = + cpl_sprintf("%s = %g = %s. (Tolerance %s = %g)", first_string, + first, second_string, tolerance_string, tolerance); + } + else if (first == 0.0) { /* Not needed. Used only for prettier messaging */ expression = CPL_FALSE; message = cpl_sprintf("%s = zero; %s = non-zero (%g). (Tolerance " - "%s = %g)", first_string, second_string, - second, tolerance_string, tolerance); - } else if (second == 0.0) { + "%s = %g)", + first_string, second_string, second, + tolerance_string, tolerance); + } + else if (second == 0.0) { /* Not needed. Used only for prettier messaging */ expression = CPL_FALSE; message = cpl_sprintf("%s = non-zero (%g); %s = zero. (Tolerance " - "%s = %g)", first_string, first, second_string, + "%s = %g)", + first_string, first, second_string, tolerance_string, tolerance); - } else if (fabs(first) < fabs(second)) { + } + else if (fabs(first) < fabs(second)) { expression = fabs(first - second) <= tolerance * fabs(first) - ? CPL_TRUE : CPL_FALSE; + ? CPL_TRUE + : CPL_FALSE; message = cpl_sprintf("|%s - %s|/|%s| = |%g - %g|/|%g| = |%g|/|%g|" - " <= %g = %s", first_string, second_string, - first_string, first, second, first, - first - second, first, tolerance, - tolerance_string); - - } else { + " <= %g = %s", + first_string, second_string, first_string, first, + second, first, first - second, first, tolerance, + tolerance_string); + } + else { /* assert(fabs(second) < fabs(first)) */ expression = fabs(first - second) <= tolerance * fabs(second) - ? CPL_TRUE : CPL_FALSE; + ? CPL_TRUE + : CPL_FALSE; message = cpl_sprintf("|%s - %s|/|%s| = |%g - %g|/|%g| = |%g|/|%g|" - " <= %g = %s", first_string, second_string, - second_string, first, second, second, - first - second, second, tolerance, - tolerance_string); - + " <= %g = %s", + first_string, second_string, second_string, first, + second, second, first - second, second, tolerance, + tolerance_string); } cpl_test_one(errnopre, twallpre, flopspre, statepre, expression, message, @@ -1391,20 +1507,25 @@ @note This function should only be called from the macro cpl_test_vector_abs() */ /*----------------------------------------------------------------------------*/ -void cpl_test_vector_abs_macro(int errnopre, double twallpre, - cpl_flops flopspre, cpl_errorstate statepre, - const cpl_vector * first, - const char *first_string, - const cpl_vector * second, - const char *second_string, - double tolerance, const char *tolerance_string, - const char *function, const char *file, - unsigned line) +void +cpl_test_vector_abs_macro(int errnopre, + double twallpre, + cpl_flops flopspre, + cpl_errorstate statepre, + const cpl_vector *first, + const char *first_string, + const cpl_vector *second, + const char *second_string, + double tolerance, + const char *tolerance_string, + const char *function, + const char *file, + unsigned line) { cpl_errorstate mystate = cpl_errorstate_get(); - cpl_vector * diff = cpl_vector_duplicate(first); - cpl_boolean expression; - char * message; + cpl_vector *diff = cpl_vector_duplicate(first); + cpl_boolean expression; + char *message; (void)cpl_vector_subtract(diff, second); @@ -1412,12 +1533,11 @@ cpl_error_set(cpl_func, cpl_error_get_code()); expression = CPL_FALSE; - message = cpl_sprintf("%s <=> %s (tol=%s) input error:", - first_string, second_string, - tolerance_string); - } else { - - const double * pdiff = cpl_vector_get_data_const(diff); + message = cpl_sprintf("%s <=> %s (tol=%s) input error:", first_string, + second_string, tolerance_string); + } + else { + const double *pdiff = cpl_vector_get_data_const(diff); double difval = pdiff[0]; const cpl_size n = cpl_vector_get_size(diff); cpl_size pos = 0; @@ -1431,27 +1551,25 @@ } if (cpl_errorstate_is_equal(mystate)) { - const double val1 = cpl_vector_get(first, pos); + const double val1 = cpl_vector_get(first, pos); const double val2 = cpl_vector_get(second, pos); expression = (fabs(difval) <= tolerance) ? CPL_TRUE : CPL_FALSE; - message = cpl_sprintf("|%s(%" CPL_SIZE_FORMAT ") - %s(%" - CPL_SIZE_FORMAT ")| = " + message = cpl_sprintf("|%s(%" CPL_SIZE_FORMAT + ") - %s(%" CPL_SIZE_FORMAT ")| = " "|%g - %g| = |%g| <= %g = %s", - first_string, pos, - second_string, pos, - val1, val2, difval, tolerance, - tolerance_string); - - } else { + first_string, pos, second_string, pos, val1, + val2, difval, tolerance, tolerance_string); + } + else { cpl_error_set(cpl_func, cpl_error_get_code()); expression = CPL_FALSE; - message = cpl_sprintf("%s <=> %s (tol=%s) input error:", - first_string, second_string, - tolerance_string); + message = + cpl_sprintf("%s <=> %s (tol=%s) input error:", first_string, + second_string, tolerance_string); } } @@ -1489,20 +1607,25 @@ @note This function should only be called from the macro cpl_test_matrix_abs() */ /*----------------------------------------------------------------------------*/ -void cpl_test_matrix_abs_macro(int errnopre, double twallpre, - cpl_flops flopspre, cpl_errorstate statepre, - const cpl_matrix * first, - const char *first_string, - const cpl_matrix * second, - const char *second_string, - double tolerance, const char *tolerance_string, - const char *function, const char *file, - unsigned line) +void +cpl_test_matrix_abs_macro(int errnopre, + double twallpre, + cpl_flops flopspre, + cpl_errorstate statepre, + const cpl_matrix *first, + const char *first_string, + const cpl_matrix *second, + const char *second_string, + double tolerance, + const char *tolerance_string, + const char *function, + const char *file, + unsigned line) { cpl_errorstate mystate = cpl_errorstate_get(); - cpl_matrix * diff = cpl_matrix_duplicate(first); - cpl_boolean expression; - char * message; + cpl_matrix *diff = cpl_matrix_duplicate(first); + cpl_boolean expression; + char *message; (void)cpl_matrix_subtract(diff, second); @@ -1510,15 +1633,14 @@ cpl_error_set(cpl_func, cpl_error_get_code()); expression = CPL_FALSE; - message = cpl_sprintf("%s <=> %s (tol=%s) input error:", - first_string, second_string, - tolerance_string); - } else { - - const double * pdiff = cpl_matrix_get_data_const(diff); + message = cpl_sprintf("%s <=> %s (tol=%s) input error:", first_string, + second_string, tolerance_string); + } + else { + const double *pdiff = cpl_matrix_get_data_const(diff); double difval = pdiff[0]; const cpl_size ncol = cpl_matrix_get_ncol(diff); - const cpl_size n = cpl_matrix_get_nrow(diff) * ncol; + const cpl_size n = cpl_matrix_get_nrow(diff) * ncol; cpl_size pos = 0; cpl_size i; @@ -1537,23 +1659,22 @@ expression = (fabs(difval) <= tolerance) ? CPL_TRUE : CPL_FALSE; - message = cpl_sprintf("|%s(%" CPL_SIZE_FORMAT ",%" CPL_SIZE_FORMAT - ") - %s(%" CPL_SIZE_FORMAT ",%" - CPL_SIZE_FORMAT ")| = |%g - %g| = " - "|%g| <= %g = %s", - first_string, irow, icol, - second_string, irow, icol, - val1, val2, difval, tolerance, - tolerance_string); - - } else { + message = + cpl_sprintf("|%s(%" CPL_SIZE_FORMAT ",%" CPL_SIZE_FORMAT + ") - %s(%" CPL_SIZE_FORMAT ",%" CPL_SIZE_FORMAT + ")| = |%g - %g| = " + "|%g| <= %g = %s", + first_string, irow, icol, second_string, irow, icol, + val1, val2, difval, tolerance, tolerance_string); + } + else { cpl_error_set(cpl_func, cpl_error_get_code()); expression = CPL_FALSE; - message = cpl_sprintf("%s <=> %s (tol=%s) input error:", - first_string, second_string, - tolerance_string); + message = + cpl_sprintf("%s <=> %s (tol=%s) input error:", first_string, + second_string, tolerance_string); } } @@ -1591,17 +1712,21 @@ @note This function should only be called from the macro cpl_test_array_abs() */ /*----------------------------------------------------------------------------*/ -void cpl_test_array_abs_macro(int errnopre, double twallpre, cpl_flops flopspre, - cpl_errorstate statepre, - const cpl_array * first, - const char *first_string, - const cpl_array * second, - const char *second_string, - double tolerance, const char *tolerance_string, - const char *function, const char *file, - unsigned line) +void +cpl_test_array_abs_macro(int errnopre, + double twallpre, + cpl_flops flopspre, + cpl_errorstate statepre, + const cpl_array *first, + const char *first_string, + const cpl_array *second, + const char *second_string, + double tolerance, + const char *tolerance_string, + const char *function, + const char *file, + unsigned line) { - /* Modified from cpl_test_image_abs_macro() */ cpl_errorstate mystate = cpl_errorstate_get(); @@ -1617,70 +1742,77 @@ const int nx = cpl_array_get_size(first); #endif - cpl_array * diff = cpl_array_duplicate(first); - cpl_boolean expression; - char * message; + cpl_array *diff = cpl_array_duplicate(first); + cpl_boolean expression; + char *message; (void)cpl_array_subtract(diff, second); if (tolerance < 0.0) { expression = CPL_FALSE; message = cpl_sprintf("array1=%s; array2=%s. Negative tolerance %s = " - "%g", first_string, second_string, - tolerance_string, tolerance); - } else if (!cpl_errorstate_is_equal(mystate)) { + "%g", + first_string, second_string, tolerance_string, + tolerance); + } + else if (!cpl_errorstate_is_equal(mystate)) { cpl_error_set(cpl_func, cpl_error_get_code()); expression = CPL_FALSE; #ifdef CPL_SIZE_FORMAT - message = cpl_sprintf("%s(%" CPL_SIZE_FORMAT ", %s) <=> %s(%" - CPL_SIZE_FORMAT ", %s) (tol=%s) input error:", - first_string, nx, cpl_type_get_name(type1), - second_string, cpl_array_get_size(second), - cpl_type_get_name(type2), tolerance_string); + message = + cpl_sprintf("%s(%" CPL_SIZE_FORMAT ", %s) <=> %s(%" CPL_SIZE_FORMAT + ", %s) (tol=%s) input error:", + first_string, nx, cpl_type_get_name(type1), + second_string, cpl_array_get_size(second), + cpl_type_get_name(type2), tolerance_string); #else message = cpl_sprintf("%s(%d, %s) <=> %s(%d, %s) (tol=%s) input error:", first_string, nx, cpl_type_get_name(type1), second_string, cpl_array_get_size(second), cpl_type_get_name(type2), tolerance_string); #endif - } else if (nbad1 == nbad2 && nbad1 == nx) { + } + else if (nbad1 == nbad2 && nbad1 == nx) { expression = CPL_TRUE; #ifdef CPL_SIZE_FORMAT - message = cpl_sprintf("%s(%" CPL_SIZE_FORMAT ", %s) <=> %s(%" - CPL_SIZE_FORMAT ", %s) (tol=%s) All elements " - "are bad", - first_string, nx, cpl_type_get_name(type1), - second_string, cpl_array_get_size(second), - cpl_type_get_name(type2), tolerance_string); + message = + cpl_sprintf("%s(%" CPL_SIZE_FORMAT ", %s) <=> %s(%" CPL_SIZE_FORMAT + ", %s) (tol=%s) All elements " + "are bad", + first_string, nx, cpl_type_get_name(type1), + second_string, cpl_array_get_size(second), + cpl_type_get_name(type2), tolerance_string); #else message = cpl_sprintf("%s(%d, %s) <=> %s(%d, %s) (tol=%s) " - "All elements are bad", first_string, - nx, cpl_type_get_name(type1), + "All elements are bad", + first_string, nx, cpl_type_get_name(type1), second_string, cpl_array_get_size(second), cpl_type_get_name(type2), tolerance_string); #endif - } else if (cpl_array_count_invalid(diff) == nx) { + } + else if (cpl_array_count_invalid(diff) == nx) { expression = CPL_FALSE; #ifdef CPL_SIZE_FORMAT - message = cpl_sprintf("%s(%" CPL_SIZE_FORMAT ", %s) <=> %s(%" - CPL_SIZE_FORMAT ", %s) (tol=%s) All elements " - "are bad in the first (%" CPL_SIZE_FORMAT - ") or second (%" CPL_SIZE_FORMAT "d) array", - first_string, nx, cpl_type_get_name(type1), - second_string, cpl_array_get_size(second), - cpl_type_get_name(type2), tolerance_string, - nbad1, nbad2); + message = + cpl_sprintf("%s(%" CPL_SIZE_FORMAT ", %s) <=> %s(%" CPL_SIZE_FORMAT + ", %s) (tol=%s) All elements " + "are bad in the first (%" CPL_SIZE_FORMAT + ") or second (%" CPL_SIZE_FORMAT "d) array", + first_string, nx, cpl_type_get_name(type1), + second_string, cpl_array_get_size(second), + cpl_type_get_name(type2), tolerance_string, nbad1, + nbad2); #else message = cpl_sprintf("%s(%d, %s) <=> %s(%d, %s) (tol=%s) All elements " "are bad in the first (%d) or second (%d) array", first_string, nx, cpl_type_get_name(type1), second_string, cpl_array_get_size(second), - cpl_type_get_name(type2), tolerance_string, - nbad1, nbad2); + cpl_type_get_name(type2), tolerance_string, nbad1, + nbad2); #endif - } else { - + } + else { const double maxdif = cpl_array_get_max(diff); const double mindif = cpl_array_get_min(diff); @@ -1690,53 +1822,51 @@ #ifdef CPL_SIZE_FORMAT cpl_size posx; #else - int posx; + int posx; #endif - const cpl_error_code error = (is_pos ? cpl_array_get_maxpos - : cpl_array_get_minpos) (diff, &posx); + const cpl_error_code error = + (is_pos ? cpl_array_get_maxpos : cpl_array_get_minpos)(diff, &posx); - int is_bad1; - int is_bad2; + int is_bad1; + int is_bad2; - const double val1 - = (type1 == CPL_TYPE_INT ? (double)cpl_array_get_int(first, posx, - &is_bad1) - : (type1 == CPL_TYPE_FLOAT - ? (double)cpl_array_get_float(first, posx, &is_bad1) - : cpl_array_get_double(first, posx, &is_bad1))); - - const double val2 - = (type2 == CPL_TYPE_INT - ? (double)cpl_array_get_int(second, posx, &is_bad2) - : (type2 == CPL_TYPE_FLOAT - ? (double)cpl_array_get_float(second, posx, &is_bad2) - : cpl_array_get_double(second, posx, &is_bad2))); + const double val1 = + (type1 == CPL_TYPE_INT + ? (double)cpl_array_get_int(first, posx, &is_bad1) + : (type1 == CPL_TYPE_FLOAT + ? (double)cpl_array_get_float(first, posx, &is_bad1) + : cpl_array_get_double(first, posx, &is_bad1))); + + const double val2 = + (type2 == CPL_TYPE_INT + ? (double)cpl_array_get_int(second, posx, &is_bad2) + : (type2 == CPL_TYPE_FLOAT + ? (double)cpl_array_get_float(second, posx, &is_bad2) + : cpl_array_get_double(second, posx, &is_bad2))); if (!error && cpl_errorstate_is_equal(mystate)) { - - - const char * rejstr1 = is_bad1 ? " invalid" : " valid"; - const char * rejstr2 = is_bad2 ? " invalid" : " valid"; + const char *rejstr1 = is_bad1 ? " invalid" : " valid"; + const char *rejstr2 = is_bad2 ? " invalid" : " valid"; expression = (fabs(difval) <= tolerance) ? CPL_TRUE : CPL_FALSE; - message = cpl_sprintf("|%s(%" CPL_SIZE_FORMAT ",%s, %s) - %s(%" - CPL_SIZE_FORMAT ",%s, %s)| = " - "|%g - %g| = |%g| <= %g = %s", - first_string, posx, rejstr1, - cpl_type_get_name(type1), second_string, - posx, rejstr2, cpl_type_get_name(type2), - val1, val2, difval, tolerance, - tolerance_string); - - } else { + message = + cpl_sprintf("|%s(%" CPL_SIZE_FORMAT + ",%s, %s) - %s(%" CPL_SIZE_FORMAT ",%s, %s)| = " + "|%g - %g| = |%g| <= %g = %s", + first_string, posx, rejstr1, + cpl_type_get_name(type1), second_string, posx, + rejstr2, cpl_type_get_name(type2), val1, val2, + difval, tolerance, tolerance_string); + } + else { cpl_error_set(cpl_func, cpl_error_get_code()); expression = CPL_FALSE; - message = cpl_sprintf("%s <=> %s (tol=%s) input error:", - first_string, second_string, - tolerance_string); + message = + cpl_sprintf("%s <=> %s (tol=%s) input error:", first_string, + second_string, tolerance_string); } } @@ -1780,76 +1910,85 @@ @note This function should only be called from the macro cpl_test_image_abs() */ /*----------------------------------------------------------------------------*/ -void cpl_test_image_abs_macro(int errnopre, double twallpre, cpl_flops flopspre, - cpl_errorstate statepre, - const cpl_image * first, - const char *first_string, - const cpl_image * second, - const char *second_string, - double tolerance, const char *tolerance_string, - const char *function, const char *file, - unsigned line) +void +cpl_test_image_abs_macro(int errnopre, + double twallpre, + cpl_flops flopspre, + cpl_errorstate statepre, + const cpl_image *first, + const char *first_string, + const cpl_image *second, + const char *second_string, + double tolerance, + const char *tolerance_string, + const char *function, + const char *file, + unsigned line) { cpl_errorstate mystate = cpl_errorstate_get(); - const char * stype1 = cpl_type_get_name(cpl_image_get_type(first)); - const char * stype2 = cpl_type_get_name(cpl_image_get_type(second)); + const char *stype1 = cpl_type_get_name(cpl_image_get_type(first)); + const char *stype2 = cpl_type_get_name(cpl_image_get_type(second)); const cpl_size nbad1 = cpl_image_count_rejected(first); const cpl_size nbad2 = cpl_image_count_rejected(second); const cpl_size nx = cpl_image_get_size_x(first); const cpl_size ny = cpl_image_get_size_y(first); - cpl_image * cdiff = cpl_image_subtract_create(first, second); - cpl_image * diff = (cpl_image_get_type(cdiff) & CPL_TYPE_COMPLEX) ? - cpl_image_extract_mod(cdiff) : cdiff; - cpl_boolean expression; - char * message; + cpl_image *cdiff = cpl_image_subtract_create(first, second); + cpl_image *diff = (cpl_image_get_type(cdiff) & CPL_TYPE_COMPLEX) + ? cpl_image_extract_mod(cdiff) + : cdiff; + cpl_boolean expression; + char *message; if (tolerance < 0.0) { expression = CPL_FALSE; message = cpl_sprintf("image1=%s; image2=%s. Negative tolerance %s = " - "%g", first_string, second_string, - tolerance_string, tolerance); - } else if (!cpl_errorstate_is_equal(mystate)) { + "%g", + first_string, second_string, tolerance_string, + tolerance); + } + else if (!cpl_errorstate_is_equal(mystate)) { cpl_error_set(cpl_func, cpl_error_get_code()); expression = CPL_FALSE; - message = cpl_sprintf("%s(%" CPL_SIZE_FORMAT ",%" CPL_SIZE_FORMAT - ", %s) <=> %s(%" CPL_SIZE_FORMAT ",%" - CPL_SIZE_FORMAT ", %s) (tol=%s) input error:", - first_string, nx, ny, stype1, second_string, - cpl_image_get_size_x(second), - cpl_image_get_size_y(second), stype2, - tolerance_string); - } else if (nbad1 == nbad2 && nbad1 == nx * ny) { + message = + cpl_sprintf("%s(%" CPL_SIZE_FORMAT ",%" CPL_SIZE_FORMAT + ", %s) <=> %s(%" CPL_SIZE_FORMAT ",%" CPL_SIZE_FORMAT + ", %s) (tol=%s) input error:", + first_string, nx, ny, stype1, second_string, + cpl_image_get_size_x(second), + cpl_image_get_size_y(second), stype2, tolerance_string); + } + else if (nbad1 == nbad2 && nbad1 == nx * ny) { expression = CPL_TRUE; - message = cpl_sprintf("%s(%" CPL_SIZE_FORMAT ",%" CPL_SIZE_FORMAT - ", %s) <=> %s(%" CPL_SIZE_FORMAT ",%" - CPL_SIZE_FORMAT ", %s) (tol=%s) All pixels " - "are bad", - first_string, nx, ny, stype1, second_string, - cpl_image_get_size_x(second), - cpl_image_get_size_y(second), stype2, - tolerance_string); - } else if (cpl_image_count_rejected(diff) == nx * ny) { + message = + cpl_sprintf("%s(%" CPL_SIZE_FORMAT ",%" CPL_SIZE_FORMAT + ", %s) <=> %s(%" CPL_SIZE_FORMAT ",%" CPL_SIZE_FORMAT + ", %s) (tol=%s) All pixels " + "are bad", + first_string, nx, ny, stype1, second_string, + cpl_image_get_size_x(second), + cpl_image_get_size_y(second), stype2, tolerance_string); + } + else if (cpl_image_count_rejected(diff) == nx * ny) { expression = CPL_FALSE; message = cpl_sprintf("%s(%" CPL_SIZE_FORMAT ",%" CPL_SIZE_FORMAT - ", %s) <=> %s(%" CPL_SIZE_FORMAT ",%" - CPL_SIZE_FORMAT ", %s) (tol=%s) All pixels " + ", %s) <=> %s(%" CPL_SIZE_FORMAT + ",%" CPL_SIZE_FORMAT ", %s) (tol=%s) All pixels " "are bad in the first (%" CPL_SIZE_FORMAT ") or second (%" CPL_SIZE_FORMAT ") image", - first_string, nx, ny, stype1, - second_string, cpl_image_get_size_x(second), + first_string, nx, ny, stype1, second_string, + cpl_image_get_size_x(second), cpl_image_get_size_y(second), stype2, tolerance_string, nbad1, nbad2); - } else { - + } + else { cpl_stats istats; const cpl_error_code icode = - cpl_stats_fill_from_image(&istats, diff, CPL_STATS_MIN - | CPL_STATS_MAX - | CPL_STATS_MINPOS - | CPL_STATS_MAXPOS); - const cpl_stats * stats = icode ? NULL : &istats; + cpl_stats_fill_from_image(&istats, diff, + CPL_STATS_MIN | CPL_STATS_MAX | + CPL_STATS_MINPOS | CPL_STATS_MAXPOS); + const cpl_stats *stats = icode ? NULL : &istats; const double maxdif = cpl_stats_get_max(stats); const double mindif = cpl_stats_get_min(stats); @@ -1857,76 +1996,77 @@ const cpl_boolean is_pos = (maxdif >= -mindif) ? CPL_TRUE : CPL_FALSE; const double difval = is_pos ? maxdif : mindif; - const cpl_size posx - = is_pos ? cpl_stats_get_max_x(stats) : cpl_stats_get_min_x(stats); - const cpl_size posy - = is_pos ? cpl_stats_get_max_y(stats) : cpl_stats_get_min_y(stats); + const cpl_size posx = + is_pos ? cpl_stats_get_max_x(stats) : cpl_stats_get_min_x(stats); + const cpl_size posy = + is_pos ? cpl_stats_get_max_y(stats) : cpl_stats_get_min_y(stats); - int is_bad1; - int is_bad2; + int is_bad1; + int is_bad2; if (cpl_errorstate_is_equal(mystate)) { - expression = (fabs(difval) <= tolerance) ? CPL_TRUE : CPL_FALSE; if (cpl_image_get_type(cdiff) & CPL_TYPE_COMPLEX) { const double complex val1 = - cpl_image_get_complex(first, posx, posy, &is_bad1); - const double complex val2 = + cpl_image_get_complex(first, posx, posy, &is_bad1); + const double complex val2 = (cpl_image_get_type(second) & CPL_TYPE_COMPLEX) - ? cpl_image_get_complex(second, posx, posy, &is_bad2) - : cpl_image_get(second, posx, posy, &is_bad2); + ? cpl_image_get_complex(second, posx, posy, &is_bad2) + : cpl_image_get(second, posx, posy, &is_bad2); - const char * rejstr1 = is_bad1 ? " bad" : " not bad"; - const char * rejstr2 = is_bad2 ? " bad" : " not bad"; + const char *rejstr1 = is_bad1 ? " bad" : " not bad"; + const char *rejstr2 = is_bad2 ? " bad" : " not bad"; - message = cpl_sprintf("|%s(%" CPL_SIZE_FORMAT ",%" - CPL_SIZE_FORMAT - ",%s, %s) - %s(%" CPL_SIZE_FORMAT ",%" - CPL_SIZE_FORMAT ",%s, %s)| = " - "|%g - %g + I (%g - %g) | = |%g| " - "<= %g = %s", - first_string, posx, posy, rejstr1, stype1, - second_string, posx, posy, rejstr2, - stype2, creal(val1), creal(val2), - cimag(val1), cimag(val2), difval, - tolerance, tolerance_string); - } else { - const double val1 = cpl_image_get(first, posx, posy, &is_bad1); + message = + cpl_sprintf("|%s(%" CPL_SIZE_FORMAT ",%" CPL_SIZE_FORMAT + ",%s, %s) - %s(%" CPL_SIZE_FORMAT + ",%" CPL_SIZE_FORMAT ",%s, %s)| = " + "|%g - %g + I (%g - %g) | = |%g| " + "<= %g = %s", + first_string, posx, posy, rejstr1, stype1, + second_string, posx, posy, rejstr2, stype2, + creal(val1), creal(val2), cimag(val1), + cimag(val2), difval, tolerance, + tolerance_string); + } + else { + const double val1 = cpl_image_get(first, posx, posy, &is_bad1); const double val2 = cpl_image_get(second, posx, posy, &is_bad2); - const char * rejstr1 = is_bad1 ? " bad" : " not bad"; - const char * rejstr2 = is_bad2 ? " bad" : " not bad"; + const char *rejstr1 = is_bad1 ? " bad" : " not bad"; + const char *rejstr2 = is_bad2 ? " bad" : " not bad"; - message = cpl_sprintf("|%s(%" CPL_SIZE_FORMAT ",%" - CPL_SIZE_FORMAT - ",%s, %s) - %s(%" CPL_SIZE_FORMAT ",%" - CPL_SIZE_FORMAT ",%s, %s)| = " - "|%g - %g| = |%g| <= %g = %s", - first_string, posx, posy, rejstr1, stype1, - second_string, posx, posy, rejstr2, - stype2, val1, val2, difval, tolerance, - tolerance_string); + message = + cpl_sprintf("|%s(%" CPL_SIZE_FORMAT ",%" CPL_SIZE_FORMAT + ",%s, %s) - %s(%" CPL_SIZE_FORMAT + ",%" CPL_SIZE_FORMAT ",%s, %s)| = " + "|%g - %g| = |%g| <= %g = %s", + first_string, posx, posy, rejstr1, stype1, + second_string, posx, posy, rejstr2, stype2, + val1, val2, difval, tolerance, + tolerance_string); } if (!expression && cpl_msg_get_level() <= CPL_MSG_ERROR) - cpl_stats_dump(stats, CPL_STATS_MIN - | CPL_STATS_MAX - | CPL_STATS_MINPOS - | CPL_STATS_MAXPOS, stderr); - - } else { + cpl_stats_dump(stats, + CPL_STATS_MIN | CPL_STATS_MAX | + CPL_STATS_MINPOS | CPL_STATS_MAXPOS, + stderr); + } + else { cpl_error_set(cpl_func, cpl_error_get_code()); expression = CPL_FALSE; - message = cpl_sprintf("%s(%" CPL_SIZE_FORMAT ",%" CPL_SIZE_FORMAT - ", %s) <=> %s(%" CPL_SIZE_FORMAT ",%" - CPL_SIZE_FORMAT ", %s) (tol=%s) input error:", - first_string, nx, ny, stype1, - second_string, cpl_image_get_size_x(second), - cpl_image_get_size_y(second), stype2, - tolerance_string); + message = + cpl_sprintf("%s(%" CPL_SIZE_FORMAT ",%" CPL_SIZE_FORMAT + ", %s) <=> %s(%" CPL_SIZE_FORMAT + ",%" CPL_SIZE_FORMAT ", %s) (tol=%s) input error:", + first_string, nx, ny, stype1, second_string, + cpl_image_get_size_x(second), + cpl_image_get_size_y(second), stype2, + tolerance_string); } } @@ -1942,7 +2082,8 @@ cpl_errorstate_set(mystate); cpl_image_delete(cdiff); - if (diff != cdiff) cpl_image_delete(diff); + if (diff != cdiff) + cpl_image_delete(diff); cpl_free(message); return; @@ -1970,93 +2111,106 @@ @note This function should only be called from the macro cpl_test_image_rel() */ /*----------------------------------------------------------------------------*/ -void cpl_test_image_rel_macro(int errnopre, double twallpre, cpl_flops flopspre, - cpl_errorstate statepre, - const cpl_image * first, - const char *first_string, - const cpl_image * second, - const char *second_string, - double tolerance, const char *tolerance_string, - const char *function, const char *file, - unsigned line) +void +cpl_test_image_rel_macro(int errnopre, + double twallpre, + cpl_flops flopspre, + cpl_errorstate statepre, + const cpl_image *first, + const char *first_string, + const cpl_image *second, + const char *second_string, + double tolerance, + const char *tolerance_string, + const char *function, + const char *file, + unsigned line) { cpl_errorstate mystate = cpl_errorstate_get(); - const char * stype1 = cpl_type_get_name(cpl_image_get_type(first)); - const char * stype2 = cpl_type_get_name(cpl_image_get_type(second)); + const char *stype1 = cpl_type_get_name(cpl_image_get_type(first)); + const char *stype2 = cpl_type_get_name(cpl_image_get_type(second)); const cpl_size nbad1 = cpl_image_count_rejected(first); const cpl_size nbad2 = cpl_image_count_rejected(second); const cpl_size nx = cpl_image_get_size_x(first); const cpl_size ny = cpl_image_get_size_y(first); - cpl_image * cdiff = cpl_image_subtract_create(first, second); - cpl_image * diff = (cpl_image_get_type(cdiff) & CPL_TYPE_COMPLEX) ? - cpl_image_extract_mod(cdiff) : cdiff; - cpl_boolean expression; - char * message; + cpl_image *cdiff = cpl_image_subtract_create(first, second); + cpl_image *diff = (cpl_image_get_type(cdiff) & CPL_TYPE_COMPLEX) + ? cpl_image_extract_mod(cdiff) + : cdiff; + cpl_boolean expression; + char *message; if (tolerance < 0.0) { expression = CPL_FALSE; message = cpl_sprintf("image1=%s; image2=%s. Negative tolerance %s = " - "%g", first_string, second_string, - tolerance_string, tolerance); - } else if (!cpl_errorstate_is_equal(mystate)) { + "%g", + first_string, second_string, tolerance_string, + tolerance); + } + else if (!cpl_errorstate_is_equal(mystate)) { cpl_error_set(cpl_func, cpl_error_get_code()); expression = CPL_FALSE; - message = cpl_sprintf("%s(%" CPL_SIZE_FORMAT ",%" CPL_SIZE_FORMAT - ", %s) <=> %s(%" CPL_SIZE_FORMAT ",%" - CPL_SIZE_FORMAT ", %s) (tol=%s) input error:", - first_string, nx, ny, stype1, second_string, - cpl_image_get_size_x(second), - cpl_image_get_size_y(second), stype2, - tolerance_string); - } else if (nbad1 == nbad2 && nbad1 == nx * ny) { + message = + cpl_sprintf("%s(%" CPL_SIZE_FORMAT ",%" CPL_SIZE_FORMAT + ", %s) <=> %s(%" CPL_SIZE_FORMAT ",%" CPL_SIZE_FORMAT + ", %s) (tol=%s) input error:", + first_string, nx, ny, stype1, second_string, + cpl_image_get_size_x(second), + cpl_image_get_size_y(second), stype2, tolerance_string); + } + else if (nbad1 == nbad2 && nbad1 == nx * ny) { expression = CPL_TRUE; - message = cpl_sprintf("%s(%" CPL_SIZE_FORMAT ",%" CPL_SIZE_FORMAT - ", %s) <=> %s(%" CPL_SIZE_FORMAT ",%" - CPL_SIZE_FORMAT ", %s) (tol=%s) All pixels " - "are bad", - first_string, nx, ny, stype1, second_string, - cpl_image_get_size_x(second), - cpl_image_get_size_y(second), stype2, - tolerance_string); - } else if (cpl_image_count_rejected(diff) == nx * ny) { + message = + cpl_sprintf("%s(%" CPL_SIZE_FORMAT ",%" CPL_SIZE_FORMAT + ", %s) <=> %s(%" CPL_SIZE_FORMAT ",%" CPL_SIZE_FORMAT + ", %s) (tol=%s) All pixels " + "are bad", + first_string, nx, ny, stype1, second_string, + cpl_image_get_size_x(second), + cpl_image_get_size_y(second), stype2, tolerance_string); + } + else if (cpl_image_count_rejected(diff) == nx * ny) { expression = CPL_FALSE; message = cpl_sprintf("%s(%" CPL_SIZE_FORMAT ",%" CPL_SIZE_FORMAT - ", %s) <=> %s(%" CPL_SIZE_FORMAT ",%" - CPL_SIZE_FORMAT ", %s) (tol=%s) All pixels " + ", %s) <=> %s(%" CPL_SIZE_FORMAT + ",%" CPL_SIZE_FORMAT ", %s) (tol=%s) All pixels " "are bad in the first (%" CPL_SIZE_FORMAT ") or second (%" CPL_SIZE_FORMAT ") image", - first_string, nx, ny, stype1, - second_string, cpl_image_get_size_x(second), + first_string, nx, ny, stype1, second_string, + cpl_image_get_size_x(second), cpl_image_get_size_y(second), stype2, tolerance_string, nbad1, nbad2); - } else { + } + else { /* Create real-valued images with the absolute values */ - cpl_image * imabs1 = (cpl_image_get_type(first) & CPL_TYPE_COMPLEX) ? - cpl_image_extract_mod(first) : cpl_image_abs_create(first); - cpl_image * imabs2 = (cpl_image_get_type(second) & CPL_TYPE_COMPLEX) ? - cpl_image_extract_mod(second) : cpl_image_abs_create(second); + cpl_image *imabs1 = (cpl_image_get_type(first) & CPL_TYPE_COMPLEX) + ? cpl_image_extract_mod(first) + : cpl_image_abs_create(first); + cpl_image *imabs2 = (cpl_image_get_type(second) & CPL_TYPE_COMPLEX) + ? cpl_image_extract_mod(second) + : cpl_image_abs_create(second); - cpl_image * immin = cpl_image_min_create(imabs1, imabs2); + cpl_image *immin = cpl_image_min_create(imabs1, imabs2); cpl_error_code error = cpl_image_multiply_scalar(immin, tolerance); - cpl_image * posit = cpl_image_subtract_create(immin, diff); + cpl_image *posit = cpl_image_subtract_create(immin, diff); cpl_stats istats; const cpl_error_code icode = - cpl_stats_fill_from_image(&istats, posit, CPL_STATS_MIN - | CPL_STATS_MINPOS); - const cpl_stats * stats = icode ? NULL : &istats; + cpl_stats_fill_from_image(&istats, posit, + CPL_STATS_MIN | CPL_STATS_MINPOS); + const cpl_stats *stats = icode ? NULL : &istats; const double difval = cpl_stats_get_min(stats); - const cpl_size posx = cpl_stats_get_min_x(stats); - const cpl_size posy = cpl_stats_get_min_y(stats); + const cpl_size posx = cpl_stats_get_min_x(stats); + const cpl_size posy = cpl_stats_get_min_y(stats); - int is_bad1; - int is_bad2; + int is_bad1; + int is_bad2; if (!error && cpl_errorstate_is_equal(mystate)) { const double mval = cpl_image_get(immin, posx, posy, &is_bad2); @@ -2065,66 +2219,65 @@ if (cpl_image_get_type(cdiff) & CPL_TYPE_COMPLEX) { const double complex val1 = - cpl_image_get_complex(first, posx, posy, &is_bad1); - const double complex val2 = + cpl_image_get_complex(first, posx, posy, &is_bad1); + const double complex val2 = (cpl_image_get_type(second) & CPL_TYPE_COMPLEX) - ? cpl_image_get_complex(second, posx, posy, &is_bad2) - : cpl_image_get(second, posx, posy, &is_bad2); + ? cpl_image_get_complex(second, posx, posy, &is_bad2) + : cpl_image_get(second, posx, posy, &is_bad2); - const char * rejstr1 = is_bad1 ? " bad" : " not bad"; - const char * rejstr2 = is_bad2 ? " bad" : " not bad"; + const char *rejstr1 = is_bad1 ? " bad" : " not bad"; + const char *rejstr2 = is_bad2 ? " bad" : " not bad"; - message = cpl_sprintf("|%s(%" CPL_SIZE_FORMAT ",%" - CPL_SIZE_FORMAT - ",%s, %s) - %s(%" CPL_SIZE_FORMAT ",%" - CPL_SIZE_FORMAT ",%s, %s)| = " - "|%g - %g + I (%g - %g) | = |%g + I %g| " - "<= %g", - first_string, posx, posy, rejstr1, stype1, - second_string, posx, posy, rejstr2, - stype2, creal(val1), creal(val2), - cimag(val1), cimag(val2), - creal(val1) - creal(val2), - cimag(val1) - cimag(val2), mval); - } else { - const double val1 = cpl_image_get(first, posx, posy, &is_bad1); + message = + cpl_sprintf("|%s(%" CPL_SIZE_FORMAT ",%" CPL_SIZE_FORMAT + ",%s, %s) - %s(%" CPL_SIZE_FORMAT + ",%" CPL_SIZE_FORMAT ",%s, %s)| = " + "|%g - %g + I (%g - %g) | = |%g + I %g| " + "<= %g", + first_string, posx, posy, rejstr1, stype1, + second_string, posx, posy, rejstr2, stype2, + creal(val1), creal(val2), cimag(val1), + cimag(val2), creal(val1) - creal(val2), + cimag(val1) - cimag(val2), mval); + } + else { + const double val1 = cpl_image_get(first, posx, posy, &is_bad1); const double val2 = cpl_image_get(second, posx, posy, &is_bad2); - const char * rejstr1 = is_bad1 ? " bad" : " not bad"; - const char * rejstr2 = is_bad2 ? " bad" : " not bad"; + const char *rejstr1 = is_bad1 ? " bad" : " not bad"; + const char *rejstr2 = is_bad2 ? " bad" : " not bad"; - message = cpl_sprintf("|%s(%" CPL_SIZE_FORMAT ",%" - CPL_SIZE_FORMAT - ",%s, %s) - %s(%" CPL_SIZE_FORMAT ",%" - CPL_SIZE_FORMAT ",%s, %s)| = " - "|%g - %g| = |%g| <= %g", - first_string, posx, posy, rejstr1, stype1, - second_string, posx, posy, rejstr2, - stype2, val1, val2, val1 - val2, mval); + message = + cpl_sprintf("|%s(%" CPL_SIZE_FORMAT ",%" CPL_SIZE_FORMAT + ",%s, %s) - %s(%" CPL_SIZE_FORMAT + ",%" CPL_SIZE_FORMAT ",%s, %s)| = " + "|%g - %g| = |%g| <= %g", + first_string, posx, posy, rejstr1, stype1, + second_string, posx, posy, rejstr2, stype2, + val1, val2, val1 - val2, mval); } if (!expression && cpl_msg_get_level() <= CPL_MSG_ERROR) - cpl_stats_dump(stats, CPL_STATS_MIN - | CPL_STATS_MINPOS, stderr); - - } else { + cpl_stats_dump(stats, CPL_STATS_MIN | CPL_STATS_MINPOS, stderr); + } + else { cpl_error_set(cpl_func, cpl_error_get_code()); expression = CPL_FALSE; - message = cpl_sprintf("%s(%" CPL_SIZE_FORMAT ",%" CPL_SIZE_FORMAT - ", %s) <=> %s(%" CPL_SIZE_FORMAT ",%" - CPL_SIZE_FORMAT ", %s) (tol=%s) input error:", - first_string, nx, ny, stype1, - second_string, cpl_image_get_size_x(second), - cpl_image_get_size_y(second), stype2, - tolerance_string); + message = + cpl_sprintf("%s(%" CPL_SIZE_FORMAT ",%" CPL_SIZE_FORMAT + ", %s) <=> %s(%" CPL_SIZE_FORMAT + ",%" CPL_SIZE_FORMAT ", %s) (tol=%s) input error:", + first_string, nx, ny, stype1, second_string, + cpl_image_get_size_x(second), + cpl_image_get_size_y(second), stype2, + tolerance_string); } cpl_image_delete(imabs1); cpl_image_delete(imabs2); cpl_image_delete(immin); cpl_image_delete(posit); - } cpl_test_one(errnopre, twallpre, flopspre, statepre, expression, message, @@ -2140,7 +2293,8 @@ cpl_errorstate_set(mystate); cpl_image_delete(cdiff); - if (diff != cdiff) cpl_image_delete(diff); + if (diff != cdiff) + cpl_image_delete(diff); cpl_free(message); return; @@ -2169,54 +2323,59 @@ @note This function should only be called from cpl_test_imagelist_abs() */ /*----------------------------------------------------------------------------*/ -void cpl_test_imagelist_abs_macro(int errnopre, double twallpre, - cpl_flops flopspre, cpl_errorstate statepre, - const cpl_imagelist * first, - const char *first_string, - const cpl_imagelist * second, - const char *second_string, - double tolerance, - const char *tolerance_string, - const char *function, const char *file, - unsigned line) +void +cpl_test_imagelist_abs_macro(int errnopre, + double twallpre, + cpl_flops flopspre, + cpl_errorstate statepre, + const cpl_imagelist *first, + const char *first_string, + const cpl_imagelist *second, + const char *second_string, + double tolerance, + const char *tolerance_string, + const char *function, + const char *file, + unsigned line) { cpl_errorstate mystate = cpl_errorstate_get(); const cpl_size sz1 = cpl_imagelist_get_size(first); const cpl_size sz2 = cpl_imagelist_get_size(second); - cpl_boolean expression; - char * message = NULL; + cpl_boolean expression; + char *message = NULL; if (!cpl_errorstate_is_equal(mystate)) { cpl_error_set(cpl_func, cpl_error_get_code()); expression = CPL_FALSE; - message = cpl_sprintf("%s <=> %s (tol=%s) input error:", - first_string, second_string, - tolerance_string); - } else if (sz1 != sz2) { + message = cpl_sprintf("%s <=> %s (tol=%s) input error:", first_string, + second_string, tolerance_string); + } + else if (sz1 != sz2) { expression = CPL_FALSE; message = cpl_sprintf("%s <=> %s (tol=%s) imagelist list sizes differ: " "%" CPL_SIZE_FORMAT " <=> %" CPL_SIZE_FORMAT, - first_string, second_string, - tolerance_string, sz1, sz2); - } else { + first_string, second_string, tolerance_string, + sz1, sz2); + } + else { const cpl_size failures = cpl_test_failures; cpl_size i; message = cpl_sprintf("|%s(%" CPL_SIZE_FORMAT ") - %s(%" CPL_SIZE_FORMAT - ")| <= %g = %s", first_string, sz1, - second_string, sz2, - tolerance, tolerance_string); + ")| <= %g = %s", + first_string, sz1, second_string, sz2, tolerance, + tolerance_string); for (i = 0; i < sz1; i++) { - const cpl_image * img1 = cpl_imagelist_get_const(first, i); - const cpl_image * img2 = cpl_imagelist_get_const(second, i); + const cpl_image *img1 = cpl_imagelist_get_const(first, i); + const cpl_image *img2 = cpl_imagelist_get_const(second, i); - char * img1string = cpl_sprintf("image %" CPL_SIZE_FORMAT - " in first list", 1+i); - char * img2string = cpl_sprintf("image %" CPL_SIZE_FORMAT - " in second list", 1+i); + char *img1string = + cpl_sprintf("image %" CPL_SIZE_FORMAT " in first list", 1 + i); + char *img2string = + cpl_sprintf("image %" CPL_SIZE_FORMAT " in second list", 1 + i); cpl_test_image_abs_macro(errnopre, twallpre, flopspre, statepre, img1, img1string, img2, img2string, @@ -2228,7 +2387,6 @@ expression = failures == cpl_test_failures ? CPL_TRUE : CPL_FALSE; cpl_test_failures = failures; /* Count as only one test ! */ - } cpl_test_one(errnopre, twallpre, flopspre, statepre, expression, message, @@ -2271,46 +2429,50 @@ cpl_test_polynomial_abs() */ /*----------------------------------------------------------------------------*/ -void cpl_test_polynomial_abs_macro(int errnopre, double twallpre, - cpl_flops flopspre, cpl_errorstate statepre, - const cpl_polynomial * first, - const char *first_string, - const cpl_polynomial * second, - const char *second_string, - double tolerance, - const char *tolerance_string, - const char *function, const char *file, - unsigned line) +void +cpl_test_polynomial_abs_macro(int errnopre, + double twallpre, + cpl_flops flopspre, + cpl_errorstate statepre, + const cpl_polynomial *first, + const char *first_string, + const cpl_polynomial *second, + const char *second_string, + double tolerance, + const char *tolerance_string, + const char *function, + const char *file, + unsigned line) { cpl_errorstate mystate = cpl_errorstate_get(); const int retval = cpl_polynomial_compare(first, second, tolerance); - cpl_boolean expression = retval ? CPL_FALSE : CPL_TRUE; - char * message; + cpl_boolean expression = retval ? CPL_FALSE : CPL_TRUE; + char *message; if (cpl_errorstate_is_equal(mystate)) { const cpl_size dim1 = cpl_polynomial_get_dimension(first); const cpl_size dim2 = cpl_polynomial_get_dimension(second); cpl_error_set(cpl_func, cpl_error_get_code()); - message = cpl_sprintf("(dimension %d <=> %d. intol degree=%d) |%s - %s| " - "<= %g = %s", (int)dim1, (int)dim2, - retval ? retval - 1 : 0, - first_string, second_string, - tolerance, tolerance_string); - - } else { + message = + cpl_sprintf("(dimension %d <=> %d. intol degree=%d) |%s - %s| " + "<= %g = %s", + (int)dim1, (int)dim2, retval ? retval - 1 : 0, + first_string, second_string, tolerance, + tolerance_string); + } + else { expression = CPL_FALSE; - message = cpl_sprintf("%s <=> %s (tol=%s) input error:", - first_string, second_string, - tolerance_string); + message = cpl_sprintf("%s <=> %s (tol=%s) input error:", first_string, + second_string, tolerance_string); } cpl_test_one(errnopre, twallpre, flopspre, statepre, expression, message, CPL_FALSE, function, file, line); if (retval > 0) { - cpl_polynomial_dump(first, stderr); + cpl_polynomial_dump(first, stderr); cpl_polynomial_dump(second, stderr); } @@ -2340,19 +2502,20 @@ cpl_test_errorstate() */ /*----------------------------------------------------------------------------*/ -void cpl_test_errorstate_macro(int errnopre, double twallpre, - cpl_flops flopspre, cpl_errorstate statepre, - cpl_errorstate errorstate, - const char * errorstate_string, - const char * function, const char * file, - unsigned line) +void +cpl_test_errorstate_macro(int errnopre, + double twallpre, + cpl_flops flopspre, + cpl_errorstate statepre, + cpl_errorstate errorstate, + const char *errorstate_string, + const char *function, + const char *file, + unsigned line) { - /* FIXME: Improve message */ - char * message = cpl_sprintf("%s <=> %d (%s)", - errorstate_string, - cpl_error_get_code(), - cpl_error_get_message()); + char *message = cpl_sprintf("%s <=> %d (%s)", errorstate_string, + cpl_error_get_code(), cpl_error_get_message()); cpl_test_one(errnopre, twallpre, flopspre, statepre, cpl_errorstate_is_equal(errorstate) ? CPL_TRUE : CPL_FALSE, @@ -2366,7 +2529,6 @@ } - /*----------------------------------------------------------------------------*/ /** @internal @@ -2385,22 +2547,24 @@ */ /*----------------------------------------------------------------------------*/ -void cpl_test_error_macro(int errnopre, double twallpre, cpl_flops flopspre, - cpl_errorstate statepre, - cpl_error_code error, const char * error_string, - const char * function, const char * file, - unsigned line) -{ - - char * message = cpl_sprintf("(%s) = %d (%s) <=> %d (%s)", - error_string, error, - cpl_error_get_message_default(error), - cpl_error_get_code(), - cpl_error_get_message()); +void +cpl_test_error_macro(int errnopre, + double twallpre, + cpl_flops flopspre, + cpl_errorstate statepre, + cpl_error_code error, + const char *error_string, + const char *function, + const char *file, + unsigned line) +{ + char *message = cpl_sprintf("(%s) = %d (%s) <=> %d (%s)", error_string, + error, cpl_error_get_message_default(error), + cpl_error_get_code(), cpl_error_get_message()); cpl_test_one(errnopre, twallpre, flopspre, statepre, - cpl_error_get_code() == error ? CPL_TRUE : CPL_FALSE, - message, CPL_TRUE, function, file, line); + cpl_error_get_code() == error ? CPL_TRUE : CPL_FALSE, message, + CPL_TRUE, function, file, line); cpl_free(message); @@ -2429,28 +2593,32 @@ */ /*----------------------------------------------------------------------------*/ -void cpl_test_eq_error_macro(int errnopre, double twallpre, cpl_flops flopspre, - cpl_errorstate statepre, - cpl_error_code first, const char * first_string, - cpl_error_code second, const char * second_string, - const char * function, const char * file, - unsigned line) +void +cpl_test_eq_error_macro(int errnopre, + double twallpre, + cpl_flops flopspre, + cpl_errorstate statepre, + cpl_error_code first, + const char *first_string, + cpl_error_code second, + const char *second_string, + const char *function, + const char *file, + unsigned line) { - - char * message = cpl_sprintf("(%s) = %d (%s) <=> (%s) = %d (%s) " - "<=> %d (%s)", first_string, first, - cpl_error_get_message_default(first), - second_string, second, - cpl_error_get_message_default(second), - cpl_error_get_code(), - cpl_error_get_message_default - (cpl_error_get_code())); + char *message = + cpl_sprintf("(%s) = %d (%s) <=> (%s) = %d (%s) " + "<=> %d (%s)", + first_string, first, cpl_error_get_message_default(first), + second_string, second, + cpl_error_get_message_default(second), cpl_error_get_code(), + cpl_error_get_message_default(cpl_error_get_code())); cpl_test_one(errnopre, twallpre, flopspre, statepre, - (first == second && cpl_error_get_code() == first) - ? CPL_TRUE : CPL_FALSE, + (first == second && cpl_error_get_code() == first) ? CPL_TRUE + : CPL_FALSE, message, CPL_TRUE, function, file, line); cpl_free(message); @@ -2477,18 +2645,23 @@ */ /*----------------------------------------------------------------------------*/ -void cpl_test_memory_is_empty_macro(int errnopre, double twallpre, - cpl_flops flopspre, cpl_errorstate statepre, - const char * function, const char * file, - unsigned line) +void +cpl_test_memory_is_empty_macro(int errnopre, + double twallpre, + cpl_flops flopspre, + cpl_errorstate statepre, + const char *function, + const char *file, + unsigned line) { - const char * message; + const char *message; cpl_boolean ok; if (cpl_memory_is_empty() == -1) { message = "CPL memory system is empty (not testable)"; ok = CPL_TRUE; - } else { + } + else { message = "CPL memory system is empty"; ok = cpl_memory_is_empty() == 0 ? CPL_FALSE : CPL_TRUE; } @@ -2536,36 +2709,34 @@ */ /*----------------------------------------------------------------------------*/ -int cpl_test_end(cpl_size nfail) +int +cpl_test_end(cpl_size nfail) { - - const int errnopre = errno; - const cpl_flops nflops = cpl_tools_get_flops(); - cpl_boolean ok = CPL_TRUE; - const cpl_size mfail = nfail + (cpl_size)cpl_test_failures; + const int errnopre = errno; + const cpl_flops nflops = cpl_tools_get_flops(); + cpl_boolean ok = CPL_TRUE; + const cpl_size mfail = nfail + (cpl_size)cpl_test_failures; const double cpl_test_elap = cpl_test_get_walltime() - cpl_test_time_start; #if defined HAVE_SYS_TIMES_H && defined _SC_CLK_TCK && defined HAVE_SYSCONF - struct tms buf; + struct tms buf; const clock_t clocks = times(&buf); - const double cputime =(double)buf.tms_utime - / (double)sysconf(_SC_CLK_TCK); - const double systime =(double)buf.tms_stime - / (double)sysconf(_SC_CLK_TCK); - const double chcputime =(double)buf.tms_cutime - / (double)sysconf(_SC_CLK_TCK); - const double chsystime =(double)buf.tms_cstime - / (double)sysconf(_SC_CLK_TCK); + const double cputime = (double)buf.tms_utime / (double)sysconf(_SC_CLK_TCK); + const double systime = (double)buf.tms_stime / (double)sysconf(_SC_CLK_TCK); + const double chcputime = + (double)buf.tms_cutime / (double)sysconf(_SC_CLK_TCK); + const double chsystime = + (double)buf.tms_cstime / (double)sysconf(_SC_CLK_TCK); errno = 0; cpl_msg_debug(cpl_func, "Sizeof(clock_t): %u", (unsigned)sizeof(clocks)); cpl_msg_debug(cpl_func, "sysconf(_SC_CLK_TCK): %u", (unsigned)sysconf(_SC_CLK_TCK)); - cpl_msg_info(cpl_func, "User time to test [s]: %g", cputime); - cpl_msg_info(cpl_func, "System time to test [s]: %g", systime); + cpl_msg_info(cpl_func, "User time to test [s]: %g", cputime); + cpl_msg_info(cpl_func, "System time to test [s]: %g", systime); cpl_msg_debug(cpl_func, "Child user time to test [s]: %g", chcputime); cpl_msg_debug(cpl_func, "Child system time to test [s]: %g", chsystime); @@ -2576,7 +2747,8 @@ if (cpl_test_state_ == 0) { cpl_msg_error(cpl_func, "Missing a previous call to cpl_test_init()"); ok = CPL_FALSE; - } else if (cpl_test_state_ == 2) { + } + else if (cpl_test_state_ == 2) { cpl_msg_error(cpl_func, "Repeated call to cpl_test_end()"); ok = CPL_FALSE; } @@ -2585,27 +2757,30 @@ cpl_test_zero(cpl_io_fits_end()); if (cpl_test_elap > 0.0) { - cpl_msg_info(cpl_func, "Actual time to test [s]: %g", - cpl_test_elap); - cpl_msg_info(cpl_func, "The computational speed during this test " - "[MFLOP/s]: %g", 1e-6*(double)nflops/cpl_test_elap); - } else { + cpl_msg_info(cpl_func, "Actual time to test [s]: %g", cpl_test_elap); + cpl_msg_info(cpl_func, + "The computational speed during this test " + "[MFLOP/s]: %g", + 1e-6 * (double)nflops / cpl_test_elap); + } + else { cpl_msg_info(cpl_func, "Number of MFLOPs in this test: %g", - 1e-6*(double)nflops); + 1e-6 * (double)nflops); } if (errnopre != 0) { - cpl_msg_warning(cpl_func, "%s() was called with errno=%d: %s", - cpl_func, errnopre, strerror(errnopre)); + cpl_msg_warning(cpl_func, "%s() was called with errno=%d: %s", cpl_func, + errnopre, strerror(errnopre)); } /* Make sure that the failure is written */ - if (cpl_msg_get_level() == CPL_MSG_OFF) cpl_msg_set_level(CPL_MSG_ERROR); + if (cpl_msg_get_level() == CPL_MSG_OFF) + cpl_msg_set_level(CPL_MSG_ERROR); if (cpl_error_get_code() != CPL_ERROR_NONE) { ok = CPL_FALSE; cpl_msg_error(cpl_func, "The CPL errorstate was set by the unit " - "test(s)"); + "test(s)"); cpl_msg_indent_more(); cpl_errorstate_dump(cleanstate, CPL_FALSE, NULL); cpl_msg_indent_less(); @@ -2613,17 +2788,22 @@ if (mfail > 0) { ok = CPL_FALSE; - cpl_msg_error(cpl_func, "%" CPL_SIZE_FORMAT " of %" CPL_SIZE_FORMAT - " test(s) failed", mfail, cpl_test_count); - } else if (mfail < 0) { + cpl_msg_error(cpl_func, + "%" CPL_SIZE_FORMAT " of %" CPL_SIZE_FORMAT + " test(s) failed", + mfail, cpl_test_count); + } + else if (mfail < 0) { ok = CPL_FALSE; /* This special case is only foreseen to be reached by the unit test of the CPL unit test module */ - cpl_msg_error(cpl_func, "%" CPL_SIZE_FORMAT " of %" CPL_SIZE_FORMAT + cpl_msg_error(cpl_func, + "%" CPL_SIZE_FORMAT " of %" CPL_SIZE_FORMAT " test(s) failed, %" CPL_SIZE_FORMAT " less than the " "expected %" CPL_SIZE_FORMAT " failure(s)", cpl_test_failures, cpl_test_count, -mfail, -nfail); - } else { + } + else { cpl_msg_info(cpl_func, "All %" CPL_SIZE_FORMAT " test(s) succeeded", cpl_test_count); } @@ -2634,16 +2814,19 @@ cpl_msg_indent_more(); cpl_memory_dump(); cpl_msg_indent_less(); - } else if (cpl_msg_get_level() <= CPL_MSG_DEBUG) { + } + else if (cpl_msg_get_level() <= CPL_MSG_DEBUG) { cpl_memory_dump(); } if (!ok) { cpl_msg_error(cpl_func, "This failure may indicate a bug in the tested " - "code"); - cpl_msg_error(cpl_func, "You can contribute to the improvement of the " + "code"); + cpl_msg_error(cpl_func, + "You can contribute to the improvement of the " "software by emailing the logfile '%s' and the configure " - "logfile 'config.log' to %s", cpl_msg_get_log_name(), + "logfile 'config.log' to %s", + cpl_msg_get_log_name(), cpl_test_report ? cpl_test_report : PACKAGE_BUGREPORT); cpl_msg_error(cpl_func, "System specifics:\n%s", cpl_test_get_description()); @@ -2676,7 +2859,8 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_test_reset(cpl_errorstate self) +static void +cpl_test_reset(cpl_errorstate self) { if (!cpl_errorstate_is_equal(self)) { cpl_errorstate_dump(self, CPL_FALSE, cpl_errorstate_dump_debug); @@ -2710,42 +2894,55 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_test_one(int errnopre, double twallpre, cpl_flops flopspre, - cpl_errorstate statepre, cpl_boolean expression, - const char *message, cpl_boolean expect_error, - const char *function, const char *file, unsigned line) +static void +cpl_test_one(int errnopre, + double twallpre, + cpl_flops flopspre, + cpl_errorstate statepre, + cpl_boolean expression, + const char *message, + cpl_boolean expect_error, + const char *function, + const char *file, + unsigned line) { - const int myerrno = errno; /* Local copy, in case errno changes in here */ - char * errnopre_txt = errnopre == 0 ? NULL : - cpl_sprintf(" Prior to this test errno=%d: %s.", errnopre, - strerror(errnopre)); - char * myerrno_txt = myerrno == errnopre ? NULL : - cpl_sprintf(" This test set errno=%d: %s.", myerrno, - strerror(myerrno)); - const char * errnopre_msg = errnopre_txt == NULL ? "" : errnopre_txt; - const char * myerrno_msg = myerrno_txt == NULL ? "" : myerrno_txt; - const char * error_msg = cpl_errorstate_is_equal(cleanstate) ? "" : - (expect_error ? - (cpl_errorstate_is_equal(statepre) ? "" - : "CPL error(s) set during this test.") : - (cpl_errorstate_is_equal(statepre) ? - " CPL error(s) set prior to this test." : - (statepre == cleanstate ? " CPL error(s) set during this test." : - " CPL error(s) set prior to and during this test."))); - char * flopprev_txt = NULL; - char * floptest_txt = NULL; + char *errnopre_txt = errnopre == 0 + ? NULL + : cpl_sprintf(" Prior to this test errno=%d: %s.", + errnopre, strerror(errnopre)); + char *myerrno_txt = myerrno == errnopre + ? NULL + : cpl_sprintf(" This test set errno=%d: %s.", + myerrno, strerror(myerrno)); + const char *errnopre_msg = errnopre_txt == NULL ? "" : errnopre_txt; + const char *myerrno_msg = myerrno_txt == NULL ? "" : myerrno_txt; + const char *error_msg = + cpl_errorstate_is_equal(cleanstate) + ? "" + : (expect_error + ? (cpl_errorstate_is_equal(statepre) + ? "" + : "CPL error(s) set during this test.") + : (cpl_errorstate_is_equal(statepre) + ? " CPL error(s) set prior to this test." + : (statepre == cleanstate + ? " CPL error(s) set during this test." + : " CPL error(s) set prior to and during this " + "test."))); + char *flopprev_txt = NULL; + char *floptest_txt = NULL; - assert(message != NULL); + assert(message != NULL); assert(function != NULL); - assert(file != NULL); - + assert(file != NULL); + errno = 0; #ifdef _OPENMP #pragma omp atomic #endif - cpl_test_count++; + cpl_test_count++; #ifdef _OPENMP #pragma omp master @@ -2754,7 +2951,7 @@ /* If two cpl_tests would be permitted to enter concurrently here, then the reported FLOP rate would be meaningless */ - const double cpl_test_time_now = cpl_test_get_walltime(); + const double cpl_test_time_now = cpl_test_get_walltime(); const double cpl_test_time_prev = cpl_test_time_one; const cpl_flops cpl_test_flops_now = cpl_tools_get_flops(); const cpl_flops cpl_test_flops_prev = cpl_test_flops_one; @@ -2764,17 +2961,19 @@ if (flopspre > cpl_test_flops_prev) { const double cpl_test_time_between = twallpre - cpl_test_time_prev; - const cpl_flops cpl_test_flops_between = flopspre - - cpl_test_flops_prev; + const cpl_flops cpl_test_flops_between = + flopspre - cpl_test_flops_prev; if (cpl_test_time_between > 0.0) { - flopprev_txt = cpl_sprintf(" (%g FLOPs after the previous " - "test and prior to this one at " - "[MFLOP/s]: %g).", - (double)cpl_test_flops_between, - 1e-6*(double)cpl_test_flops_between - /cpl_test_time_between); - } else { + flopprev_txt = + cpl_sprintf(" (%g FLOPs after the previous " + "test and prior to this one at " + "[MFLOP/s]: %g).", + (double)cpl_test_flops_between, + 1e-6 * (double)cpl_test_flops_between / + cpl_test_time_between); + } + else { flopprev_txt = cpl_sprintf(" (%g FLOPs after the previous test " "and prior to this one).", (double)cpl_test_flops_between); @@ -2783,54 +2982,61 @@ if (cpl_test_flops_now > flopspre) { const double cpl_test_time_during = cpl_test_time_now - twallpre; - const cpl_flops cpl_test_flops_during = cpl_test_flops_now - - flopspre; + const cpl_flops cpl_test_flops_during = + cpl_test_flops_now - flopspre; if (cpl_test_time_during > 0.0) { - floptest_txt = cpl_sprintf(" (%g FLOPs during this test at " - "[MFLOP/s]: %g).", - (double)cpl_test_flops_during, - 1e-6*(double)cpl_test_flops_during - /cpl_test_time_during); - - } else { + floptest_txt = + cpl_sprintf(" (%g FLOPs during this test at " + "[MFLOP/s]: %g).", + (double)cpl_test_flops_during, + 1e-6 * (double)cpl_test_flops_during / + cpl_test_time_during); + } + else { floptest_txt = cpl_sprintf(" (%g FLOPs during this test).", (double)cpl_test_flops_during); } } } - if (flopprev_txt == NULL) flopprev_txt = cpl_strdup(""); - if (floptest_txt == NULL) floptest_txt = cpl_strdup(""); + if (flopprev_txt == NULL) + flopprev_txt = cpl_strdup(""); + if (floptest_txt == NULL) + floptest_txt = cpl_strdup(""); if (cpl_test_state_ == 0) { cpl_msg_error(cpl_func, "Missing a previous call to cpl_test_init(): " - "Failure regardless of test"); + "Failure regardless of test"); #ifdef _OPENMP #pragma omp atomic #endif cpl_test_failures++; - } else if (cpl_test_state_ == 2) { + } + else if (cpl_test_state_ == 2) { cpl_msg_error(cpl_func, "Test after call to cpl_test_end(): " - "Failure regardless of test"); + "Failure regardless of test"); #ifdef _OPENMP #pragma omp atomic #endif cpl_test_failures++; - } else if (expression) { + } + else if (expression) { cpl_boolean has_error = error_msg[0] ? CPL_TRUE : CPL_FALSE; - (has_error ? cpl_msg_info : cpl_msg_debug) - (function, "Test %" CPL_SIZE_FORMAT " OK at %s:%u: %s.%s%s%s%s%s", - cpl_test_count, file, line, message, - error_msg, errnopre_msg, myerrno_msg, flopprev_txt, floptest_txt); - cpl_errorstate_dump(cleanstate, CPL_FALSE, has_error - ? cpl_errorstate_dump_info - : cpl_errorstate_dump_debug); - } else { - cpl_msg_error(function, "Test %" CPL_SIZE_FORMAT " failed at %s:%u: " - "%s.%s%s%s%s%s", cpl_test_count, file, line, message, - error_msg, errnopre_msg, myerrno_msg, flopprev_txt, - floptest_txt); + (has_error ? cpl_msg_info : cpl_msg_debug)( + function, "Test %" CPL_SIZE_FORMAT " OK at %s:%u: %s.%s%s%s%s%s", + cpl_test_count, file, line, message, error_msg, errnopre_msg, + myerrno_msg, flopprev_txt, floptest_txt); + cpl_errorstate_dump(cleanstate, CPL_FALSE, + has_error ? cpl_errorstate_dump_info + : cpl_errorstate_dump_debug); + } + else { + cpl_msg_error(function, + "Test %" CPL_SIZE_FORMAT " failed at %s:%u: " + "%s.%s%s%s%s%s", + cpl_test_count, file, line, message, error_msg, + errnopre_msg, myerrno_msg, flopprev_txt, floptest_txt); cpl_errorstate_dump(cleanstate, CPL_FALSE, NULL); #ifdef _OPENMP #pragma omp atomic @@ -2865,31 +3071,33 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_errorstate_dump_debug(unsigned self, unsigned first, - unsigned last) +static void +cpl_errorstate_dump_debug(unsigned self, unsigned first, unsigned last) { - const cpl_boolean is_reverse = first > last ? CPL_TRUE : CPL_FALSE; - const unsigned newest = is_reverse ? first : last; - const unsigned oldest = is_reverse ? last : first; - const char * revmsg = is_reverse ? " in reverse order" : ""; + const unsigned newest = is_reverse ? first : last; + const unsigned oldest = is_reverse ? last : first; + const char *revmsg = is_reverse ? " in reverse order" : ""; - assert( oldest <= self ); - assert( newest >= self ); + assert(oldest <= self); + assert(newest >= self); if (newest == 0) { cpl_msg_debug(cpl_func, "No error(s) to dump"); - assert( oldest == 0); - } else { - assert( oldest > 0); - assert( newest >= oldest); + assert(oldest == 0); + } + else { + assert(oldest > 0); + assert(newest >= oldest); if (self == first) { if (oldest == 1) { cpl_msg_debug(cpl_func, "Dumping all %u error(s)%s:", newest, revmsg); - } else { - cpl_msg_debug(cpl_func, "Dumping the %u most recent error(s) " + } + else { + cpl_msg_debug(cpl_func, + "Dumping the %u most recent error(s) " "out of a total of %u errors%s:", newest - oldest + 1, newest, revmsg); } @@ -2900,7 +3108,8 @@ cpl_error_get_message(), cpl_error_get_code(), cpl_error_get_where()); - if (self == last) cpl_msg_indent_less(); + if (self == last) + cpl_msg_indent_less(); } } @@ -2917,31 +3126,33 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_errorstate_dump_info(unsigned self, unsigned first, - unsigned last) +static void +cpl_errorstate_dump_info(unsigned self, unsigned first, unsigned last) { - const cpl_boolean is_reverse = first > last ? CPL_TRUE : CPL_FALSE; - const unsigned newest = is_reverse ? first : last; - const unsigned oldest = is_reverse ? last : first; - const char * revmsg = is_reverse ? " in reverse order" : ""; + const unsigned newest = is_reverse ? first : last; + const unsigned oldest = is_reverse ? last : first; + const char *revmsg = is_reverse ? " in reverse order" : ""; - assert( oldest <= self ); - assert( newest >= self ); + assert(oldest <= self); + assert(newest >= self); if (newest == 0) { cpl_msg_info(cpl_func, "No error(s) to dump"); - assert( oldest == 0); - } else { - assert( oldest > 0); - assert( newest >= oldest); + assert(oldest == 0); + } + else { + assert(oldest > 0); + assert(newest >= oldest); if (self == first) { if (oldest == 1) { cpl_msg_info(cpl_func, "Dumping all %u error(s)%s:", newest, revmsg); - } else { - cpl_msg_info(cpl_func, "Dumping the %u most recent error(s) " + } + else { + cpl_msg_info(cpl_func, + "Dumping the %u most recent error(s) " "out of a total of %u errors%s:", newest - oldest + 1, newest, revmsg); } @@ -2952,7 +3163,8 @@ cpl_error_get_message(), cpl_error_get_code(), cpl_error_get_where()); - if (self == last) cpl_msg_indent_less(); + if (self == last) + cpl_msg_indent_less(); } } @@ -2964,59 +3176,66 @@ */ /*----------------------------------------------------------------------------*/ -static const char * cpl_test_get_description(void) +static const char * +cpl_test_get_description(void) { return "CPL version: " PACKAGE_VERSION #if defined CPL_SIZE_BITS && CPL_SIZE_BITS == 32 - " (32-bit cpl_size)" + " (32-bit cpl_size)" #else - " (64-bit cpl_size)" + " (64-bit cpl_size)" #endif - "\n" + "\n" #ifdef CFITSIO_VERSION - "CFITSIO version: " CPL_STRINGIFY(CFITSIO_VERSION) "\n" + "CFITSIO version: " CPL_STRINGIFY(CFITSIO_VERSION) "\n" #elif defined _FITSIO_H - "CFITSIO version is less than 3.0\n" + "CFITSIO version is less than 3.0\n" #endif #if defined WCSLIB_VERSION - "WCSLIB version: " CPL_STRINGIFY(WCSLIB_VERSION) "\n" + "WCSLIB version: " CPL_STRINGIFY(WCSLIB_VERSION) "\n" #elif defined CPL_WCS_INSTALLED && CPL_WCS_INSTALLED == 1 - "WCSLIB available\n" + "WCSLIB available\n" #else - "WCSLIB unavailable\n" + "WCSLIB unavailable\n" #endif #if defined CPL_FFTW_INSTALLED && defined CPL_FFTWF_INSTALLED #if defined CPL_FFTW_VERSION && defined CPL_FFTWF_VERSION - "FFTW (normal precision) version: " CPL_FFTW_VERSION "\n" - "FFTW (single precision) version: " CPL_FFTWF_VERSION "\n" + "FFTW (normal precision) " + "version: " CPL_FFTW_VERSION + "\n" + "FFTW (single precision) " + "version:" + " " CPL_FFTWF_VERSION "\n" #else - "FFTW (normal and single precision) available\n" + "FFTW (normal and single " + "precision) available\n" #endif #elif defined CPL_FFTW_INSTALLED #if defined CPL_FFTW_VERSION - "FFTW (normal precision) version: " CPL_FFTW_VERSION "\n" - "FFTW (single precision) unavailable\n" + "FFTW (normal precision) version: " CPL_FFTW_VERSION "\n" + "FFTW (single precision) unavailable\n" #else - "FFTW (normal precision) available\n" - "FFTW (single precision) unavailable\n" + "FFTW (normal precision) available\n" + "FFTW (single precision) unavailable\n" #endif #elif defined CPL_FFTWF_INSTALLED #if defined CPL_FFTWF_VERSION - "FFTW (normal precision) unavailable\n" - "FFTW (single precision) version: " CPL_FFTWF_VERSION "\n" + "FFTW (normal precision) unavailable\n" + "FFTW (single precision) version: " CPL_FFTWF_VERSION "\n" #else - "FFTW (normal precision) unavailable\n" - "FFTW (single precision) available\n" + "FFTW (normal precision) unavailable\n" + "FFTW (single precision) available\n" #endif #else - "FFTW unavailable\n" + "FFTW unavailable\n" #endif #ifdef CPL_ADD_FLOPS - "CPL FLOP counting is available\n" + "CPL FLOP counting is " + "available\n" #else - "CPL FLOP counting is unavailable, enable with -DCPL_ADD_FLOPS\n" + "CPL FLOP counting is unavailable, enable with -DCPL_ADD_FLOPS\n" #endif #ifdef _OPENMP @@ -3024,61 +3243,66 @@ #endif #ifdef SIZEOF_SIZE_T - "SIZEOF_SIZE_T is defined as " CPL_STRINGIFY(SIZEOF_SIZE_T) "\n" + "SIZEOF_SIZE_T is defined as " CPL_STRINGIFY(SIZEOF_SIZE_T) "\n" #else - "SIZEOF_SIZE_T is not defined\n" + "SIZEOF_SIZE_T is not defined\n" #endif #ifdef OFF_T - "OFF_T is defined as " CPL_STRINGIFY(OFF_T) "\n" + "OFF_T is defined as " CPL_STRINGIFY(OFF_T) "\n" #else - "OFF_T is not defined\n" + "OFF_T is not defined\n" #endif #if defined WORDS_BIGENDIAN && WORDS_BIGENDIAN == 1 - "This platform is big-endian\n" + "This platform is " + "big-endian\n" #else - "This platform is not big-endian\n" + "This platform is not big-endian\n" #endif #ifdef __DATE__ - "Compile date: " __DATE__ "\n" + "Compile date: " __DATE__ + "\n" #endif #ifdef __TIME__ - "Compile time: " __TIME__ "\n" + "Compile time: " __TIME__ + "\n" #endif #ifdef __STDC__ CPL_XSTRINGIFY(__STDC__) ": " CPL_STRINGIFY(__STDC__) "\n" #endif #ifdef __STDC_VERSION__ - CPL_XSTRINGIFY(__STDC_VERSION__) ": " - CPL_STRINGIFY(__STDC_VERSION__) "\n" + CPL_XSTRINGIFY(__STDC_VERSION__) ": " CPL_STRINGIFY(__STDC_VERSION__) "\n" #endif #ifdef __STDC_HOSTED__ CPL_XSTRINGIFY(__STDC_HOSTED__) ": " CPL_STRINGIFY(__STDC_HOSTED__) "\n" #endif #ifdef __STDC_IEC_559__ - CPL_XSTRINGIFY(__STDC_IEC_559__) ": " - CPL_STRINGIFY(__STDC_IEC_559__) "\n" + CPL_XSTRINGIFY(__STDC_IEC_559__) ": " CPL_STRINGIFY(__STDC_IEC_559__) "\n" #endif #ifdef __STDC_IEC_559_COMPLEX__ - CPL_XSTRINGIFY(__STDC_IEC_559_COMPLEX__) ": " - CPL_STRINGIFY(__STDC_IEC_559_COMPLEX__) "\n" + CPL_XSTRINGIFY(__STDC_IEC_559_COMPLEX__) ": " CPL_STRINGIFY(__STDC_IEC_559_COMPLEX__) "\n" #endif #ifdef __STRICT_ANSI__ /* gcc and Sun Studio 12.1 supports this */ CPL_XSTRINGIFY(__STRICT_ANSI__) ": " CPL_STRINGIFY(__STRICT_ANSI__) "\n" #endif #ifdef __GNUC__ - "gcc version (major number): " CPL_STRINGIFY(__GNUC__) "\n" + "gcc version (major number): " CPL_STRINGIFY(__GNUC__) "\n" #ifdef __GNUC_MINOR__ - "gcc version (minor number): " CPL_STRINGIFY(__GNUC_MINOR__) "\n" + "gcc version (minor " + "number): " CPL_STRINGIFY(__GNUC_MINOR__) "\n" #endif #ifdef __GNUC_PATCHLEVEL__ - "gcc version (patch level): " CPL_STRINGIFY(__GNUC_PATCHLEVEL__) "\n" + "gcc version " + "(patch " + "level):" + " " CPL_STRINGIFY(__GNUC_PATCHLEVEL__) "\n" #endif #ifdef __VERSION__ - "Compiler version: " __VERSION__ "\n" + "Compiler version: " __VERSION__ + "\n" #endif #ifdef __LP64__ CPL_XSTRINGIFY(__LP64__) ": " CPL_STRINGIFY(__LP64__) "\n" @@ -3090,7 +3314,8 @@ CPL_XSTRINGIFY(__OPTIMIZE__) ": " CPL_STRINGIFY(__OPTIMIZE__) "\n" #endif #ifdef __TIMESTAMP__ - "Last modification of " __FILE__ ": " __TIMESTAMP__ "\n" + "Last modification of " __FILE__ ": " __TIMESTAMP__ + "\n" #endif #endif ; @@ -3103,22 +3328,23 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_test_dump_status(void) +static void +cpl_test_dump_status(void) { - #if defined HAVE_GETPID && defined CPL_TEST_DUMP_STATUS - const pid_t pid = getpid(); - char * file = cpl_sprintf("/proc/%u/status", (const unsigned)pid); - FILE * stream = fopen(file, "r"); + const pid_t pid = getpid(); + char *file = cpl_sprintf("/proc/%u/status", (const unsigned)pid); + FILE *stream = fopen(file, "r"); if (stream != NULL) { - char line[CPL_MAX_MSG_LENGTH]; + char line[CPL_MAX_MSG_LENGTH]; while (fgets(line, CPL_MAX_MSG_LENGTH, stream) != NULL) { /* Ignore newline */ - char * retpos = memchr(line, '\n', CPL_MAX_MSG_LENGTH); - if (retpos != NULL) *retpos = 0; + char *retpos = memchr(line, '\n', CPL_MAX_MSG_LENGTH); + if (retpos != NULL) + *retpos = 0; cpl_msg_debug(cpl_func, "%s", line); } @@ -3131,11 +3357,9 @@ #endif return; - } - /*----------------------------------------------------------------------------*/ /** @internal @@ -3146,25 +3370,26 @@ */ /*----------------------------------------------------------------------------*/ -static char * cpl_test_fits_file(const char * filename, - const char * filename_string) +static char * +cpl_test_fits_file(const char *filename, const char *filename_string) { - - char * self = NULL; + char *self = NULL; #ifdef HAVE_SYS_STAT_H struct stat buf; const int error = stat(filename, &buf); if (error) { - self = cpl_sprintf("%s => %s stat() returned %d: %s", - filename_string, filename, error, strerror(errno)); - } else { + self = cpl_sprintf("%s => %s stat() returned %d: %s", filename_string, + filename, error, strerror(errno)); + } + else { const off_t size = buf.st_size; if (size == 0) { self = cpl_sprintf("%s => %s has zero size", filename_string, filename); - } else { + } + else { const off_t rem = size % 2880; if (rem != 0) { self = cpl_sprintf("%s => %s has illegal size=%luB with %uB " @@ -3177,5 +3402,4 @@ #endif return self; - } diff -Nru cpl-7.1.4+ds/cplcore/cpl_test.h cpl-7.2.2+ds/cplcore/cpl_test.h --- cpl-7.1.4+ds/cplcore/cpl_test.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_test.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -63,7 +64,7 @@ */ /*----------------------------------------------------------------------------*/ #define cpl_test_init(REPORT, LEVEL) \ - cpl_test_init_macro(__FILE__, REPORT, LEVEL) + cpl_test_init_macro(__FILE__, REPORT, LEVEL) /*----------------------------------------------------------------------------*/ /** @@ -85,7 +86,8 @@ */ /*----------------------------------------------------------------------------*/ -#define cpl_test(bool) do { \ +#define cpl_test(bool) \ + do { \ const int cpl_test_errno = errno; \ const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ const double cpl_test_time = cpl_test_get_walltime(); \ @@ -115,14 +117,15 @@ */ /*----------------------------------------------------------------------------*/ -#define cpl_test_zero(zero) do { \ - const int cpl_test_errno = errno; \ - const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ - const double cpl_test_time = cpl_test_get_walltime(); \ - cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ - cpl_test_macro(cpl_test_errno, cpl_test_time, cpl_test_flops, \ - cpl_test_state, (zero), CPL_FALSE, \ - #zero, cpl_func, __FILE__, __LINE__); \ +#define cpl_test_zero(zero) \ + do { \ + const int cpl_test_errno = errno; \ + const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ + const double cpl_test_time = cpl_test_get_walltime(); \ + cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ + cpl_test_macro(cpl_test_errno, cpl_test_time, cpl_test_flops, \ + cpl_test_state, (zero), CPL_FALSE, #zero, cpl_func, \ + __FILE__, __LINE__); \ } while (0) /*----------------------------------------------------------------------------*/ @@ -144,14 +147,15 @@ */ /*----------------------------------------------------------------------------*/ -#define cpl_test_null(pointer) do { \ - const int cpl_test_errno = errno; \ - const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ - const double cpl_test_time = cpl_test_get_walltime(); \ - cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ - cpl_test_null_macro(cpl_test_errno, cpl_test_time, \ - cpl_test_flops, cpl_test_state, pointer, \ - #pointer, cpl_func, __FILE__, __LINE__); \ +#define cpl_test_null(pointer) \ + do { \ + const int cpl_test_errno = errno; \ + const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ + const double cpl_test_time = cpl_test_get_walltime(); \ + cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ + cpl_test_null_macro(cpl_test_errno, cpl_test_time, cpl_test_flops, \ + cpl_test_state, pointer, #pointer, cpl_func, \ + __FILE__, __LINE__); \ } while (0) /*----------------------------------------------------------------------------*/ @@ -173,15 +177,15 @@ */ /*----------------------------------------------------------------------------*/ -#define cpl_test_nonnull(pointer) do { \ - const int cpl_test_errno = errno; \ - const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ - const double cpl_test_time = cpl_test_get_walltime(); \ - cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ - cpl_test_nonnull_macro(cpl_test_errno, cpl_test_time, \ - cpl_test_flops, cpl_test_state, \ - pointer, #pointer, cpl_func, \ - __FILE__, __LINE__); \ +#define cpl_test_nonnull(pointer) \ + do { \ + const int cpl_test_errno = errno; \ + const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ + const double cpl_test_time = cpl_test_get_walltime(); \ + cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ + cpl_test_nonnull_macro(cpl_test_errno, cpl_test_time, cpl_test_flops, \ + cpl_test_state, pointer, #pointer, cpl_func, \ + __FILE__, __LINE__); \ } while (0) @@ -214,15 +218,15 @@ */ /*----------------------------------------------------------------------------*/ -#define cpl_test_errorstate(errorstate) do { \ - const int cpl_test_errno = errno; \ - const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ - const double cpl_test_time = cpl_test_get_walltime(); \ - cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ - cpl_test_errorstate_macro(cpl_test_errno, cpl_test_time, \ - cpl_test_flops, cpl_test_state, \ - errorstate, #errorstate, cpl_func, \ - __FILE__, __LINE__); \ +#define cpl_test_errorstate(errorstate) \ + do { \ + const int cpl_test_errno = errno; \ + const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ + const double cpl_test_time = cpl_test_get_walltime(); \ + cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ + cpl_test_errorstate_macro(cpl_test_errno, cpl_test_time, \ + cpl_test_flops, cpl_test_state, errorstate, \ + #errorstate, cpl_func, __FILE__, __LINE__); \ } while (0) /*----------------------------------------------------------------------------*/ @@ -251,14 +255,15 @@ */ /*----------------------------------------------------------------------------*/ -#define cpl_test_error(error) do { \ - const int cpl_test_errno = errno; \ - const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ - const double cpl_test_time = cpl_test_get_walltime(); \ - cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ - cpl_test_error_macro(cpl_test_errno, cpl_test_time, \ - cpl_test_flops, cpl_test_state, error, \ - #error, cpl_func, __FILE__, __LINE__); \ +#define cpl_test_error(error) \ + do { \ + const int cpl_test_errno = errno; \ + const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ + const double cpl_test_time = cpl_test_get_walltime(); \ + cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ + cpl_test_error_macro(cpl_test_errno, cpl_test_time, cpl_test_flops, \ + cpl_test_state, error, #error, cpl_func, \ + __FILE__, __LINE__); \ } while (0) /*----------------------------------------------------------------------------*/ @@ -291,15 +296,15 @@ */ /*----------------------------------------------------------------------------*/ -#define cpl_test_eq_error(first, second) do { \ - const int cpl_test_errno = errno; \ - const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ - const double cpl_test_time = cpl_test_get_walltime(); \ - cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ - cpl_test_eq_error_macro(cpl_test_errno, cpl_test_time, \ - cpl_test_flops, cpl_test_state, first, \ - #first, second, #second, cpl_func, \ - __FILE__, __LINE__); \ +#define cpl_test_eq_error(first, second) \ + do { \ + const int cpl_test_errno = errno; \ + const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ + const double cpl_test_time = cpl_test_get_walltime(); \ + cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ + cpl_test_eq_error_macro(cpl_test_errno, cpl_test_time, cpl_test_flops, \ + cpl_test_state, first, #first, second, \ + #second, cpl_func, __FILE__, __LINE__); \ } while (0) /*----------------------------------------------------------------------------*/ @@ -325,14 +330,15 @@ */ /*----------------------------------------------------------------------------*/ -#define cpl_test_eq(first, second) do { \ - const int cpl_test_errno = errno; \ - const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ - const double cpl_test_time = cpl_test_get_walltime(); \ - cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ - cpl_test_eq_macro(cpl_test_errno, cpl_test_time, cpl_test_flops, \ - cpl_test_state, first, #first, \ - second, #second, cpl_func, __FILE__, __LINE__); \ +#define cpl_test_eq(first, second) \ + do { \ + const int cpl_test_errno = errno; \ + const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ + const double cpl_test_time = cpl_test_get_walltime(); \ + cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ + cpl_test_eq_macro(cpl_test_errno, cpl_test_time, cpl_test_flops, \ + cpl_test_state, first, #first, second, #second, \ + cpl_func, __FILE__, __LINE__); \ } while (0) /*----------------------------------------------------------------------------*/ @@ -355,15 +361,15 @@ */ /*----------------------------------------------------------------------------*/ -#define cpl_test_noneq(first, second) do { \ - const int cpl_test_errno = errno; \ - const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ - const double cpl_test_time = cpl_test_get_walltime(); \ - cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ - cpl_test_noneq_macro(cpl_test_errno, cpl_test_time, \ - cpl_test_flops, cpl_test_state, first, \ - #first, second, #second, cpl_func, \ - __FILE__, __LINE__); \ +#define cpl_test_noneq(first, second) \ + do { \ + const int cpl_test_errno = errno; \ + const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ + const double cpl_test_time = cpl_test_get_walltime(); \ + cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ + cpl_test_noneq_macro(cpl_test_errno, cpl_test_time, cpl_test_flops, \ + cpl_test_state, first, #first, second, #second, \ + cpl_func, __FILE__, __LINE__); \ } while (0) @@ -386,15 +392,15 @@ */ /*----------------------------------------------------------------------------*/ -#define cpl_test_eq_ptr(first, second) do { \ - const int cpl_test_errno = errno; \ - const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ - const double cpl_test_time = cpl_test_get_walltime(); \ - cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ - cpl_test_eq_ptr_macro(cpl_test_errno, cpl_test_time, \ - cpl_test_flops, cpl_test_state, first, \ - #first, second, #second, cpl_func, \ - __FILE__, __LINE__); \ +#define cpl_test_eq_ptr(first, second) \ + do { \ + const int cpl_test_errno = errno; \ + const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ + const double cpl_test_time = cpl_test_get_walltime(); \ + cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ + cpl_test_eq_ptr_macro(cpl_test_errno, cpl_test_time, cpl_test_flops, \ + cpl_test_state, first, #first, second, #second, \ + cpl_func, __FILE__, __LINE__); \ } while (0) /*----------------------------------------------------------------------------*/ @@ -416,15 +422,16 @@ */ /*----------------------------------------------------------------------------*/ -#define cpl_test_noneq_ptr(first, second) do { \ - const int cpl_test_errno = errno; \ - const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ - const double cpl_test_time = cpl_test_get_walltime(); \ - cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ - cpl_test_noneq_ptr_macro(cpl_test_errno, cpl_test_time, \ - cpl_test_flops, cpl_test_state, first, \ - #first, second, #second, cpl_func, \ - __FILE__, __LINE__); \ +#define cpl_test_noneq_ptr(first, second) \ + do { \ + const int cpl_test_errno = errno; \ + const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ + const double cpl_test_time = cpl_test_get_walltime(); \ + cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ + cpl_test_noneq_ptr_macro(cpl_test_errno, cpl_test_time, \ + cpl_test_flops, cpl_test_state, first, \ + #first, second, #second, cpl_func, __FILE__, \ + __LINE__); \ } while (0) @@ -446,15 +453,16 @@ */ /*----------------------------------------------------------------------------*/ -#define cpl_test_eq_string(first, second) do { \ - const int cpl_test_errno = errno; \ - const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ - const double cpl_test_time = cpl_test_get_walltime(); \ - cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ - cpl_test_eq_string_macro(cpl_test_errno, cpl_test_time, \ - cpl_test_flops, cpl_test_state, first, \ - #first, second, #second, cpl_func, \ - __FILE__, __LINE__); \ +#define cpl_test_eq_string(first, second) \ + do { \ + const int cpl_test_errno = errno; \ + const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ + const double cpl_test_time = cpl_test_get_walltime(); \ + cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ + cpl_test_eq_string_macro(cpl_test_errno, cpl_test_time, \ + cpl_test_flops, cpl_test_state, first, \ + #first, second, #second, cpl_func, __FILE__, \ + __LINE__); \ } while (0) @@ -476,15 +484,16 @@ */ /*----------------------------------------------------------------------------*/ -#define cpl_test_noneq_string(first, second) do { \ - const int cpl_test_errno = errno; \ - const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ - const double cpl_test_time = cpl_test_get_walltime(); \ - cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ - cpl_test_noneq_string_macro(cpl_test_errno, cpl_test_time, \ - cpl_test_flops, cpl_test_state, \ - first, #first, second, #second, \ - cpl_func, __FILE__, __LINE__); \ +#define cpl_test_noneq_string(first, second) \ + do { \ + const int cpl_test_errno = errno; \ + const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ + const double cpl_test_time = cpl_test_get_walltime(); \ + cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ + cpl_test_noneq_string_macro(cpl_test_errno, cpl_test_time, \ + cpl_test_flops, cpl_test_state, first, \ + #first, second, #second, cpl_func, \ + __FILE__, __LINE__); \ } while (0) @@ -513,14 +522,15 @@ */ /*----------------------------------------------------------------------------*/ -#define cpl_test_fits(fitsfile) do { \ - const int cpl_test_errno = errno; \ - const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ - const double cpl_test_time = cpl_test_get_walltime(); \ - cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ - cpl_test_fits_macro(cpl_test_errno, cpl_test_time, \ - cpl_test_flops, cpl_test_state, fitsfile, \ - #fitsfile, cpl_func, __FILE__, __LINE__); \ +#define cpl_test_fits(fitsfile) \ + do { \ + const int cpl_test_errno = errno; \ + const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ + const double cpl_test_time = cpl_test_get_walltime(); \ + cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ + cpl_test_fits_macro(cpl_test_errno, cpl_test_time, cpl_test_flops, \ + cpl_test_state, fitsfile, #fitsfile, cpl_func, \ + __FILE__, __LINE__); \ } while (0) /*----------------------------------------------------------------------------*/ @@ -541,15 +551,15 @@ */ /*----------------------------------------------------------------------------*/ -#define cpl_test_eq_mask(first, second) do { \ - const int cpl_test_errno = errno; \ - const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ - const double cpl_test_time = cpl_test_get_walltime(); \ - cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ - cpl_test_eq_mask_macro(cpl_test_errno, cpl_test_time, \ - cpl_test_flops, cpl_test_state, first, \ - #first, second, #second, cpl_func, \ - __FILE__, __LINE__); \ +#define cpl_test_eq_mask(first, second) \ + do { \ + const int cpl_test_errno = errno; \ + const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ + const double cpl_test_time = cpl_test_get_walltime(); \ + cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ + cpl_test_eq_mask_macro(cpl_test_errno, cpl_test_time, cpl_test_flops, \ + cpl_test_state, first, #first, second, #second, \ + cpl_func, __FILE__, __LINE__); \ } while (0) /*----------------------------------------------------------------------------*/ @@ -573,15 +583,15 @@ */ /*----------------------------------------------------------------------------*/ -#define cpl_test_leq(value, tolerance) do { \ - const int cpl_test_errno = errno; \ - const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ - const double cpl_test_time = cpl_test_get_walltime(); \ - cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ - cpl_test_leq_macro(cpl_test_errno, cpl_test_time, \ - cpl_test_flops, cpl_test_state, value, \ - #value, tolerance, #tolerance, cpl_func, \ - __FILE__, __LINE__); \ +#define cpl_test_leq(value, tolerance) \ + do { \ + const int cpl_test_errno = errno; \ + const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ + const double cpl_test_time = cpl_test_get_walltime(); \ + cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ + cpl_test_leq_macro(cpl_test_errno, cpl_test_time, cpl_test_flops, \ + cpl_test_state, value, #value, tolerance, \ + #tolerance, cpl_func, __FILE__, __LINE__); \ } while (0) /*----------------------------------------------------------------------------*/ @@ -604,15 +614,15 @@ */ /*----------------------------------------------------------------------------*/ -#define cpl_test_lt(value, tolerance) do { \ - const int cpl_test_errno = errno; \ - const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ - const double cpl_test_time = cpl_test_get_walltime(); \ - cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ - cpl_test_lt_macro(cpl_test_errno, cpl_test_time, \ - cpl_test_flops, cpl_test_state, value, \ - #value, tolerance, #tolerance, cpl_func, \ - __FILE__, __LINE__); \ +#define cpl_test_lt(value, tolerance) \ + do { \ + const int cpl_test_errno = errno; \ + const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ + const double cpl_test_time = cpl_test_get_walltime(); \ + cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ + cpl_test_lt_macro(cpl_test_errno, cpl_test_time, cpl_test_flops, \ + cpl_test_state, value, #value, tolerance, \ + #tolerance, cpl_func, __FILE__, __LINE__); \ } while (0) /*----------------------------------------------------------------------------*/ @@ -635,15 +645,16 @@ */ /*----------------------------------------------------------------------------*/ -#define cpl_test_abs(first, second, tolerance) do { \ - const int cpl_test_errno = errno; \ - const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ - const double cpl_test_time = cpl_test_get_walltime(); \ - cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ - cpl_test_abs_macro(cpl_test_errno, cpl_test_time, \ - cpl_test_flops, cpl_test_state, first, \ - #first, second, #second, tolerance, \ - #tolerance, cpl_func, __FILE__, __LINE__); \ +#define cpl_test_abs(first, second, tolerance) \ + do { \ + const int cpl_test_errno = errno; \ + const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ + const double cpl_test_time = cpl_test_get_walltime(); \ + cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ + cpl_test_abs_macro(cpl_test_errno, cpl_test_time, cpl_test_flops, \ + cpl_test_state, first, #first, second, #second, \ + tolerance, #tolerance, cpl_func, __FILE__, \ + __LINE__); \ } while (0) /*----------------------------------------------------------------------------*/ @@ -666,15 +677,16 @@ */ /*----------------------------------------------------------------------------*/ -#define cpl_test_abs_complex(first, second, tolerance) do { \ - const int cpl_test_errno = errno; \ - const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ - const double cpl_test_time = cpl_test_get_walltime(); \ - cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ - cpl_test_abs_complex_macro(cpl_test_errno, cpl_test_time, \ - cpl_test_flops, cpl_test_state, first, \ - #first, second, #second, tolerance, \ - #tolerance, cpl_func, __FILE__, __LINE__); \ +#define cpl_test_abs_complex(first, second, tolerance) \ + do { \ + const int cpl_test_errno = errno; \ + const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ + const double cpl_test_time = cpl_test_get_walltime(); \ + cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ + cpl_test_abs_complex_macro(cpl_test_errno, cpl_test_time, \ + cpl_test_flops, cpl_test_state, first, \ + #first, second, #second, tolerance, \ + #tolerance, cpl_func, __FILE__, __LINE__); \ } while (0) /*----------------------------------------------------------------------------*/ @@ -691,16 +703,16 @@ */ /*----------------------------------------------------------------------------*/ -#define cpl_test_vector_abs(first, second, tolerance) do { \ - const int cpl_test_errno = errno; \ - const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ - const double cpl_test_time = cpl_test_get_walltime(); \ - cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ - cpl_test_vector_abs_macro(cpl_test_errno, cpl_test_time, \ - cpl_test_flops, cpl_test_state, \ - first, #first, second, #second, \ - tolerance, #tolerance, cpl_func, \ - __FILE__, __LINE__); \ +#define cpl_test_vector_abs(first, second, tolerance) \ + do { \ + const int cpl_test_errno = errno; \ + const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ + const double cpl_test_time = cpl_test_get_walltime(); \ + cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ + cpl_test_vector_abs_macro(cpl_test_errno, cpl_test_time, \ + cpl_test_flops, cpl_test_state, first, \ + #first, second, #second, tolerance, \ + #tolerance, cpl_func, __FILE__, __LINE__); \ } while (0) /*----------------------------------------------------------------------------*/ @@ -717,16 +729,16 @@ */ /*----------------------------------------------------------------------------*/ -#define cpl_test_matrix_abs(first, second, tolerance) do { \ - const int cpl_test_errno = errno; \ - const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ - const double cpl_test_time = cpl_test_get_walltime(); \ - cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ - cpl_test_matrix_abs_macro(cpl_test_errno, cpl_test_time, \ - cpl_test_flops, cpl_test_state, \ - first, #first, second, #second, \ - tolerance, #tolerance, cpl_func, \ - __FILE__, __LINE__); \ +#define cpl_test_matrix_abs(first, second, tolerance) \ + do { \ + const int cpl_test_errno = errno; \ + const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ + const double cpl_test_time = cpl_test_get_walltime(); \ + cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ + cpl_test_matrix_abs_macro(cpl_test_errno, cpl_test_time, \ + cpl_test_flops, cpl_test_state, first, \ + #first, second, #second, tolerance, \ + #tolerance, cpl_func, __FILE__, __LINE__); \ } while (0) /*----------------------------------------------------------------------------*/ @@ -745,15 +757,16 @@ */ /*----------------------------------------------------------------------------*/ -#define cpl_test_array_abs(first, second, tolerance) do { \ - const int cpl_test_errno = errno; \ - const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ - const double cpl_test_time = cpl_test_get_walltime(); \ - cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ - cpl_test_array_abs_macro(cpl_test_errno, cpl_test_time, \ - cpl_test_flops, cpl_test_state, first, \ - #first, second, #second, tolerance, \ - #tolerance, cpl_func, __FILE__, __LINE__); \ +#define cpl_test_array_abs(first, second, tolerance) \ + do { \ + const int cpl_test_errno = errno; \ + const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ + const double cpl_test_time = cpl_test_get_walltime(); \ + cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ + cpl_test_array_abs_macro(cpl_test_errno, cpl_test_time, \ + cpl_test_flops, cpl_test_state, first, \ + #first, second, #second, tolerance, \ + #tolerance, cpl_func, __FILE__, __LINE__); \ } while (0) @@ -771,15 +784,16 @@ */ /*----------------------------------------------------------------------------*/ -#define cpl_test_image_abs(first, second, tolerance) do { \ - const int cpl_test_errno = errno; \ - const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ - const double cpl_test_time = cpl_test_get_walltime(); \ - cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ - cpl_test_image_abs_macro(cpl_test_errno, cpl_test_time, \ - cpl_test_flops, cpl_test_state, first, \ - #first, second, #second, tolerance, \ - #tolerance, cpl_func, __FILE__, __LINE__); \ +#define cpl_test_image_abs(first, second, tolerance) \ + do { \ + const int cpl_test_errno = errno; \ + const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ + const double cpl_test_time = cpl_test_get_walltime(); \ + cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ + cpl_test_image_abs_macro(cpl_test_errno, cpl_test_time, \ + cpl_test_flops, cpl_test_state, first, \ + #first, second, #second, tolerance, \ + #tolerance, cpl_func, __FILE__, __LINE__); \ } while (0) @@ -802,15 +816,16 @@ */ /*----------------------------------------------------------------------------*/ -#define cpl_test_image_rel(first, second, tolerance) do { \ - const int cpl_test_errno = errno; \ - const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ - const double cpl_test_time = cpl_test_get_walltime(); \ - cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ - cpl_test_image_rel_macro(cpl_test_errno, cpl_test_time, \ - cpl_test_flops, cpl_test_state, first, \ - #first, second, #second, tolerance, \ - #tolerance, cpl_func, __FILE__, __LINE__); \ +#define cpl_test_image_rel(first, second, tolerance) \ + do { \ + const int cpl_test_errno = errno; \ + const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ + const double cpl_test_time = cpl_test_get_walltime(); \ + cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ + cpl_test_image_rel_macro(cpl_test_errno, cpl_test_time, \ + cpl_test_flops, cpl_test_state, first, \ + #first, second, #second, tolerance, \ + #tolerance, cpl_func, __FILE__, __LINE__); \ } while (0) @@ -829,16 +844,17 @@ */ /*----------------------------------------------------------------------------*/ -#define cpl_test_imagelist_abs(first, second, tolerance) do { \ - const int cpl_test_errno = errno; \ - const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ - const double cpl_test_time = cpl_test_get_walltime(); \ - cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ - cpl_test_imagelist_abs_macro(cpl_test_errno, cpl_test_time, \ - cpl_test_flops, cpl_test_state, \ - first, #first, second, #second, \ - tolerance, #tolerance, cpl_func, \ - __FILE__, __LINE__); \ +#define cpl_test_imagelist_abs(first, second, tolerance) \ + do { \ + const int cpl_test_errno = errno; \ + const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ + const double cpl_test_time = cpl_test_get_walltime(); \ + cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ + cpl_test_imagelist_abs_macro(cpl_test_errno, cpl_test_time, \ + cpl_test_flops, cpl_test_state, first, \ + #first, second, #second, tolerance, \ + #tolerance, cpl_func, __FILE__, \ + __LINE__); \ } while (0) @@ -857,16 +873,17 @@ */ /*----------------------------------------------------------------------------*/ -#define cpl_test_polynomial_abs(first, second, tolerance) do { \ - const int cpl_test_errno = errno; \ - const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ - const double cpl_test_time = cpl_test_get_walltime(); \ - cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ - cpl_test_polynomial_abs_macro(cpl_test_errno, cpl_test_time, \ - cpl_test_flops, cpl_test_state, \ - first, #first, second, #second, \ - tolerance, #tolerance, cpl_func, \ - __FILE__, __LINE__); \ +#define cpl_test_polynomial_abs(first, second, tolerance) \ + do { \ + const int cpl_test_errno = errno; \ + const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ + const double cpl_test_time = cpl_test_get_walltime(); \ + cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ + cpl_test_polynomial_abs_macro(cpl_test_errno, cpl_test_time, \ + cpl_test_flops, cpl_test_state, first, \ + #first, second, #second, tolerance, \ + #tolerance, cpl_func, __FILE__, \ + __LINE__); \ } while (0) @@ -901,15 +918,16 @@ */ /*----------------------------------------------------------------------------*/ -#define cpl_test_rel(first, second, tolerance) do { \ - const int cpl_test_errno = errno; \ - const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ - const double cpl_test_time = cpl_test_get_walltime(); \ - cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ - cpl_test_rel_macro(cpl_test_errno, cpl_test_time, \ - cpl_test_flops, cpl_test_state, first, \ - #first, second, #second, tolerance, \ - #tolerance, cpl_func, __FILE__, __LINE__); \ +#define cpl_test_rel(first, second, tolerance) \ + do { \ + const int cpl_test_errno = errno; \ + const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ + const double cpl_test_time = cpl_test_get_walltime(); \ + cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ + cpl_test_rel_macro(cpl_test_errno, cpl_test_time, cpl_test_flops, \ + cpl_test_state, first, #first, second, #second, \ + tolerance, #tolerance, cpl_func, __FILE__, \ + __LINE__); \ } while (0) @@ -922,14 +940,15 @@ @deprecated Called by cpl_test_end() */ /*----------------------------------------------------------------------------*/ -#define cpl_test_memory_is_empty() do { \ - const int cpl_test_errno = errno; \ - const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ - const double cpl_test_time = cpl_test_get_walltime(); \ - cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ - cpl_test_memory_is_empty_macro(cpl_test_errno, cpl_test_time, \ - cpl_test_flops, cpl_test_state, \ - cpl_func, __FILE__, __LINE__); \ +#define cpl_test_memory_is_empty() \ + do { \ + const int cpl_test_errno = errno; \ + const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ + const double cpl_test_time = cpl_test_get_walltime(); \ + cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ + cpl_test_memory_is_empty_macro(cpl_test_errno, cpl_test_time, \ + cpl_test_flops, cpl_test_state, \ + cpl_func, __FILE__, __LINE__); \ } while (0) /*----------------------------------------------------------------------------*/ @@ -962,17 +981,19 @@ @endcode */ /*----------------------------------------------------------------------------*/ -#define cpl_test_assert(bool) do { \ - const int cpl_test_errno = errno; \ - const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ - const double cpl_test_time = cpl_test_get_walltime(); \ - cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ - /* Evaluate bool just once */ \ - const cpl_boolean cpl_test_ok = (bool) ? CPL_TRUE : CPL_FALSE; \ - cpl_test_macro(cpl_test_errno, cpl_test_time, cpl_test_flops, \ - cpl_test_state, cpl_test_ok, CPL_TRUE, #bool, \ - cpl_func, __FILE__, __LINE__); \ - if (cpl_test_ok == CPL_FALSE) exit(cpl_test_end(0)); \ +#define cpl_test_assert(bool) \ + do { \ + const int cpl_test_errno = errno; \ + const cpl_flops cpl_test_flops = cpl_test_get_flops(); \ + const double cpl_test_time = cpl_test_get_walltime(); \ + cpl_errorstate cpl_test_state = cpl_errorstate_get(); \ + /* Evaluate bool just once */ \ + const cpl_boolean cpl_test_ok = (bool) ? CPL_TRUE : CPL_FALSE; \ + cpl_test_macro(cpl_test_errno, cpl_test_time, cpl_test_flops, \ + cpl_test_state, cpl_test_ok, CPL_TRUE, #bool, cpl_func, \ + __FILE__, __LINE__); \ + if (cpl_test_ok == CPL_FALSE) \ + exit(cpl_test_end(0)); \ } while (0) @@ -990,197 +1011,394 @@ Function prototypes -----------------------------------------------------------------------------*/ -void cpl_test_init_macro(const char *, const char *, - cpl_msg_severity); +void cpl_test_init_macro(const char *, const char *, cpl_msg_severity); int cpl_test_end(cpl_size); -void cpl_test_macro(int, double, cpl_flops, cpl_errorstate, cpl_size, - cpl_boolean, const char *, const char *, - const char *, unsigned) CPL_ATTR_NONNULL; - -void cpl_test_errorstate_macro(int, double, cpl_flops, cpl_errorstate, - cpl_errorstate, const char *, const char *, - const char *, unsigned) CPL_ATTR_NONNULL; - -void cpl_test_error_macro(int, double, cpl_flops, cpl_errorstate, - cpl_error_code, const char *, const char *, - const char *, unsigned) CPL_ATTR_NONNULL; - -void cpl_test_eq_error_macro(int, double, cpl_flops, cpl_errorstate, - cpl_error_code, const char *, cpl_error_code, - const char *, const char *, - const char *, unsigned) CPL_ATTR_NONNULL; - -void cpl_test_null_macro(int, double, cpl_flops, cpl_errorstate, const void *, - const char *, const char *, const char *, unsigned) +void cpl_test_macro(int, + double, + cpl_flops, + cpl_errorstate, + cpl_size, + cpl_boolean, + const char *, + const char *, + const char *, + unsigned) CPL_ATTR_NONNULL; + +void cpl_test_errorstate_macro(int, + double, + cpl_flops, + cpl_errorstate, + cpl_errorstate, + const char *, + const char *, + const char *, + unsigned) CPL_ATTR_NONNULL; + +void cpl_test_error_macro(int, + double, + cpl_flops, + cpl_errorstate, + cpl_error_code, + const char *, + const char *, + const char *, + unsigned) CPL_ATTR_NONNULL; + +void cpl_test_eq_error_macro(int, + double, + cpl_flops, + cpl_errorstate, + cpl_error_code, + const char *, + cpl_error_code, + const char *, + const char *, + const char *, + unsigned) CPL_ATTR_NONNULL; + +void cpl_test_null_macro(int, + double, + cpl_flops, + cpl_errorstate, + const void *, + const char *, + const char *, + const char *, + unsigned) #ifdef CPL_HAVE_ATTR_NONNULL __attribute__((nonnull(6, 7, 8))) #endif ; -void cpl_test_nonnull_macro(int, double, cpl_flops, cpl_errorstate, - const void *, const char *, const char *, - const char *, unsigned) +void cpl_test_nonnull_macro(int, + double, + cpl_flops, + cpl_errorstate, + const void *, + const char *, + const char *, + const char *, + unsigned) #ifdef CPL_HAVE_ATTR_NONNULL __attribute__((nonnull(6, 7, 8))) #endif ; -void cpl_test_eq_macro(int, double, cpl_flops, cpl_errorstate, cpl_size, - const char *, cpl_size, const char *, const char *, - const char *, unsigned) CPL_ATTR_NONNULL; - -void cpl_test_noneq_macro(int, double, cpl_flops, cpl_errorstate, cpl_size, - const char *, cpl_size, const char *, const char *, - const char *, unsigned) CPL_ATTR_NONNULL; - -void cpl_test_eq_ptr_macro(int, double, cpl_flops, cpl_errorstate, const void *, - const char *, const void *, const char *, - const char *, const char *, unsigned) +void cpl_test_eq_macro(int, + double, + cpl_flops, + cpl_errorstate, + cpl_size, + const char *, + cpl_size, + const char *, + const char *, + const char *, + unsigned) CPL_ATTR_NONNULL; + +void cpl_test_noneq_macro(int, + double, + cpl_flops, + cpl_errorstate, + cpl_size, + const char *, + cpl_size, + const char *, + const char *, + const char *, + unsigned) CPL_ATTR_NONNULL; + +void cpl_test_eq_ptr_macro(int, + double, + cpl_flops, + cpl_errorstate, + const void *, + const char *, + const void *, + const char *, + const char *, + const char *, + unsigned) #ifdef CPL_HAVE_ATTR_NONNULL __attribute__((nonnull(6, 8, 9, 10))) #endif ; -void cpl_test_noneq_ptr_macro(int, double, cpl_flops, cpl_errorstate, - const void *, const char *, const void *, - const char *, const char *, const char *, +void cpl_test_noneq_ptr_macro(int, + double, + cpl_flops, + cpl_errorstate, + const void *, + const char *, + const void *, + const char *, + const char *, + const char *, unsigned) #ifdef CPL_HAVE_ATTR_NONNULL __attribute__((nonnull(6, 8, 9, 10))) #endif ; -void cpl_test_eq_string_macro(int, double, cpl_flops, cpl_errorstate, - const char *, const char *, const char *, - const char *, const char *, const char *, +void cpl_test_eq_string_macro(int, + double, + cpl_flops, + cpl_errorstate, + const char *, + const char *, + const char *, + const char *, + const char *, + const char *, unsigned) #ifdef CPL_HAVE_ATTR_NONNULL __attribute__((nonnull(6, 8, 9, 10))) #endif ; -void cpl_test_noneq_string_macro(int, double, cpl_flops, cpl_errorstate, - const char *, const char *, const char *, - const char *, const char *, const char *, +void cpl_test_noneq_string_macro(int, + double, + cpl_flops, + cpl_errorstate, + const char *, + const char *, + const char *, + const char *, + const char *, + const char *, unsigned) #ifdef CPL_HAVE_ATTR_NONNULL __attribute__((nonnull(6, 8, 9, 10))) #endif ; -void cpl_test_fits_macro(int, double, cpl_flops, cpl_errorstate, const char *, - const char *, const char *, const char *, unsigned) +void cpl_test_fits_macro(int, + double, + cpl_flops, + cpl_errorstate, + const char *, + const char *, + const char *, + const char *, + unsigned) #ifdef CPL_HAVE_ATTR_NONNULL __attribute__((nonnull(6, 7, 8))) #endif ; -void cpl_test_eq_mask_macro(int, double, cpl_flops, cpl_errorstate, - const cpl_mask *, const char *, const cpl_mask *, - const char *, const char *, const char *, unsigned) +void cpl_test_eq_mask_macro(int, + double, + cpl_flops, + cpl_errorstate, + const cpl_mask *, + const char *, + const cpl_mask *, + const char *, + const char *, + const char *, + unsigned) #ifdef CPL_HAVE_ATTR_NONNULL __attribute__((nonnull(6, 8, 9, 10))) #endif ; -void cpl_test_leq_macro(int, double, cpl_flops, cpl_errorstate, double, - const char *, double, const char *, const char *, - const char *, unsigned) CPL_ATTR_NONNULL; - -void cpl_test_lt_macro(int, double, cpl_flops, cpl_errorstate, double, - const char *, double, const char *, const char *, - const char *, unsigned) CPL_ATTR_NONNULL; - -void cpl_test_abs_macro(int, double, cpl_flops, cpl_errorstate, double, - const char *, double, const char *, double, - const char *, const char *, const char *, +void cpl_test_leq_macro(int, + double, + cpl_flops, + cpl_errorstate, + double, + const char *, + double, + const char *, + const char *, + const char *, + unsigned) CPL_ATTR_NONNULL; + +void cpl_test_lt_macro(int, + double, + cpl_flops, + cpl_errorstate, + double, + const char *, + double, + const char *, + const char *, + const char *, + unsigned) CPL_ATTR_NONNULL; + +void cpl_test_abs_macro(int, + double, + cpl_flops, + cpl_errorstate, + double, + const char *, + double, + const char *, + double, + const char *, + const char *, + const char *, unsigned) CPL_ATTR_NONNULL; -void cpl_test_abs_complex_macro(int, double, cpl_flops, cpl_errorstate, - _Complex double, const char *, - _Complex double, const char *, double, - const char *, const char *, const char *, +void cpl_test_abs_complex_macro(int, + double, + cpl_flops, + cpl_errorstate, + _Complex double, + const char *, + _Complex double, + const char *, + double, + const char *, + const char *, + const char *, unsigned) CPL_ATTR_NONNULL; -void cpl_test_rel_macro(int, double, cpl_flops, cpl_errorstate, double, - const char *, double, const char *, double, - const char *, const char *, const char *, +void cpl_test_rel_macro(int, + double, + cpl_flops, + cpl_errorstate, + double, + const char *, + double, + const char *, + double, + const char *, + const char *, + const char *, unsigned) CPL_ATTR_NONNULL; -void cpl_test_vector_abs_macro(int, double, cpl_flops, cpl_errorstate, - const cpl_vector *, const char *, - const cpl_vector *, const char *, - double, const char *, const char *, - const char *, unsigned) +void cpl_test_vector_abs_macro(int, + double, + cpl_flops, + cpl_errorstate, + const cpl_vector *, + const char *, + const cpl_vector *, + const char *, + double, + const char *, + const char *, + const char *, + unsigned) #ifdef CPL_HAVE_ATTR_NONNULL __attribute__((nonnull(6, 8, 10, 11, 12))) #endif ; -void cpl_test_matrix_abs_macro(int, double, cpl_flops, cpl_errorstate, - const cpl_matrix *, const char *, - const cpl_matrix *, const char *, - double, const char *, const char *, - const char *, unsigned) +void cpl_test_matrix_abs_macro(int, + double, + cpl_flops, + cpl_errorstate, + const cpl_matrix *, + const char *, + const cpl_matrix *, + const char *, + double, + const char *, + const char *, + const char *, + unsigned) #ifdef CPL_HAVE_ATTR_NONNULL __attribute__((nonnull(6, 8, 10, 11, 12))) #endif ; -void cpl_test_array_abs_macro(int, double, cpl_flops, cpl_errorstate, - const cpl_array *, const char *, - const cpl_array *, const char *, double, - const char *, const char *, const char *, +void cpl_test_array_abs_macro(int, + double, + cpl_flops, + cpl_errorstate, + const cpl_array *, + const char *, + const cpl_array *, + const char *, + double, + const char *, + const char *, + const char *, unsigned) #ifdef CPL_HAVE_ATTR_NONNULL __attribute__((nonnull(6, 8, 10, 11, 12))) #endif ; -void cpl_test_image_abs_macro(int, double, cpl_flops, cpl_errorstate, - const cpl_image *, const char *, - const cpl_image *, const char *, double, - const char *, const char *, const char *, +void cpl_test_image_abs_macro(int, + double, + cpl_flops, + cpl_errorstate, + const cpl_image *, + const char *, + const cpl_image *, + const char *, + double, + const char *, + const char *, + const char *, unsigned) #ifdef CPL_HAVE_ATTR_NONNULL __attribute__((nonnull(6, 8, 10, 11, 12))) #endif ; -void cpl_test_image_rel_macro(int, double, cpl_flops, cpl_errorstate, - const cpl_image *, const char *, - const cpl_image *, const char *, double, - const char *, const char *, const char *, +void cpl_test_image_rel_macro(int, + double, + cpl_flops, + cpl_errorstate, + const cpl_image *, + const char *, + const cpl_image *, + const char *, + double, + const char *, + const char *, + const char *, unsigned) #ifdef CPL_HAVE_ATTR_NONNULL __attribute__((nonnull(6, 8, 10, 11, 12))) #endif ; -void cpl_test_imagelist_abs_macro(int, double, cpl_flops, cpl_errorstate, +void cpl_test_imagelist_abs_macro(int, + double, + cpl_flops, + cpl_errorstate, const cpl_imagelist *, const char *, const cpl_imagelist *, const char *, - double, const char *, - const char *, const char *, - unsigned ) + double, + const char *, + const char *, + const char *, + unsigned) #ifdef CPL_HAVE_ATTR_NONNULL __attribute__((nonnull(6, 8, 10, 11, 12))) #endif ; -void cpl_test_polynomial_abs_macro(int, double, cpl_flops, cpl_errorstate, +void cpl_test_polynomial_abs_macro(int, + double, + cpl_flops, + cpl_errorstate, + const cpl_polynomial *, + const char *, const cpl_polynomial *, - const char *, const cpl_polynomial *, - const char *, double, const char *, - const char *, const char *, unsigned) + const char *, + double, + const char *, + const char *, + const char *, + unsigned) #ifdef CPL_HAVE_ATTR_NONNULL __attribute__((nonnull(6, 8, 10, 11, 12))) #endif ; -void cpl_test_memory_is_empty_macro(int, double, cpl_flops, cpl_errorstate, - const char *, const char *, unsigned) - CPL_ATTR_NONNULL; +void cpl_test_memory_is_empty_macro(int, + double, + cpl_flops, + cpl_errorstate, + const char *, + const char *, + unsigned) CPL_ATTR_NONNULL; double cpl_test_get_cputime(void); double cpl_test_get_walltime(void); diff -Nru cpl-7.1.4+ds/cplcore/cpl_tools_body.h cpl-7.2.2+ds/cplcore/cpl_tools_body.h --- cpl-7.1.4+ds/cplcore/cpl_tools_body.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_tools_body.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -42,11 +42,20 @@ /* Swap macro */ -#define CPL_TYPE_SWAP(a, b) { register const CPL_TYPE t=(a); (a)=(b); (b)=t; } +#define CPL_TYPE_SWAP(a, b) \ + { \ + register const CPL_TYPE t = (a); \ + (a) = (b); \ + (b) = t; \ + } /* Guarded swap macro */ -#define CPL_TYPE_SORT(a, b) { if ((a) > (b)) CPL_TYPE_SWAP((a), (b)); } +#define CPL_TYPE_SORT(a, b) \ + { \ + if ((a) > (b)) \ + CPL_TYPE_SWAP((a), (b)); \ + } /*----------------------------------------------------------------------------*/ @@ -63,7 +72,7 @@ */ /*----------------------------------------------------------------------------*/ -static void ADDTYPE(cpl_tools_get_0th)(CPL_TYPE * self, size_t n) +static void ADDTYPE(cpl_tools_get_0th)(CPL_TYPE *self, size_t n) { CPL_TYPE min = self[0]; size_t amin = 0; @@ -92,10 +101,10 @@ */ /*----------------------------------------------------------------------------*/ -void ADDTYPE(cpl_tools_flip)(CPL_TYPE * self, size_t n) +void ADDTYPE(cpl_tools_flip)(CPL_TYPE *self, size_t n) { - for (size_t i = 0; i < n/2; i++) { - CPL_TYPE_SWAP(self[i], self[n-1-i]); + for (size_t i = 0; i < n / 2; i++) { + CPL_TYPE_SWAP(self[i], self[n - 1 - i]); } } #endif @@ -128,48 +137,48 @@ The median of the integers (1 2 3 4) is 2 (due to the integer arithmetic). */ /*----------------------------------------------------------------------------*/ -CPL_TYPE ADDTYPE(cpl_tools_get_median)(CPL_TYPE * self, cpl_size n) +CPL_TYPE ADDTYPE(cpl_tools_get_median)(CPL_TYPE *self, cpl_size n) { - switch (n) { - case 3: - ADDTYPE(cpl_tools_get_median_3)(self); - break; - - case 5: - ADDTYPE(cpl_tools_get_median_5)(self); - break; - - case 6: - ADDTYPE(cpl_tools_get_median_6)(self); - break; - - case 7: - ADDTYPE(cpl_tools_get_median_7)(self); - break; - - case 9: - ADDTYPE(cpl_tools_get_median_9)(self); - break; - - case 25: - ADDTYPE(cpl_tools_get_median_25)(self); - break; - - default: - if (n & 1) { - /* Odd number */ - (void)ADDTYPE(cpl_tools_quickselection)(self, n, (n-1)/2); - } else { - /* Even number */ - (void)ADDTYPE(cpl_tools_quickselection)(self, n, n/2-1); - ADDTYPE(cpl_tools_get_0th)(self + n / 2, n / 2); - } + case 3: + ADDTYPE(cpl_tools_get_median_3)(self); + break; + + case 5: + ADDTYPE(cpl_tools_get_median_5)(self); + break; + + case 6: + ADDTYPE(cpl_tools_get_median_6)(self); + break; + + case 7: + ADDTYPE(cpl_tools_get_median_7)(self); + break; + + case 9: + ADDTYPE(cpl_tools_get_median_9)(self); + break; + + case 25: + ADDTYPE(cpl_tools_get_median_25)(self); + break; + + default: + if (n & 1) { + /* Odd number */ + (void)ADDTYPE(cpl_tools_quickselection)(self, n, (n - 1) / 2); + } + else { + /* Even number */ + (void)ADDTYPE(cpl_tools_quickselection)(self, n, n / 2 - 1); + ADDTYPE(cpl_tools_get_0th)(self + n / 2, n / 2); + } } - return (n & 1) - ? self[(n-1)/2] /* Odd number */ - : self[n/2-1] + (self[n/2]-self[n/2-1])/((CPL_TYPE)2); /* Even number */ + return (n & 1) ? self[(n - 1) / 2] /* Odd number */ + : self[n / 2 - 1] + (self[n / 2] - self[n / 2 - 1]) / + ((CPL_TYPE)2); /* Even number */ } @@ -187,7 +196,7 @@ */ /*----------------------------------------------------------------------------*/ -static void ADDTYPE(cpl_tools_get_median_3)(CPL_TYPE * self) +static void ADDTYPE(cpl_tools_get_median_3)(CPL_TYPE *self) { #ifdef CPL_TOOLS_STRICT_ERROR_CHECKING cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, (CPL_TYPE)0); @@ -196,7 +205,6 @@ CPL_TYPE_SORT(self[0], self[1]); CPL_TYPE_SORT(self[1], self[2]); CPL_TYPE_SORT(self[0], self[1]); - } @@ -216,21 +224,22 @@ */ /*----------------------------------------------------------------------------*/ -static void ADDTYPE(cpl_tools_get_median_5)(CPL_TYPE * self) +static void ADDTYPE(cpl_tools_get_median_5)(CPL_TYPE *self) { #ifdef CPL_TOOLS_STRICT_ERROR_CHECKING cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, (CPL_TYPE)0); #endif - CPL_TYPE_SORT(self[0],self[1]); CPL_TYPE_SORT(self[3],self[4]); - CPL_TYPE_SORT(self[0],self[3]); CPL_TYPE_SORT(self[1],self[4]); - CPL_TYPE_SORT(self[1],self[2]); CPL_TYPE_SORT(self[2],self[3]); - CPL_TYPE_SORT(self[1],self[2]); - + CPL_TYPE_SORT(self[0], self[1]); + CPL_TYPE_SORT(self[3], self[4]); + CPL_TYPE_SORT(self[0], self[3]); + CPL_TYPE_SORT(self[1], self[4]); + CPL_TYPE_SORT(self[1], self[2]); + CPL_TYPE_SORT(self[2], self[3]); + CPL_TYPE_SORT(self[1], self[2]); } - /*----------------------------------------------------------------------------*/ /** @internal @@ -251,20 +260,25 @@ */ /*----------------------------------------------------------------------------*/ -static void ADDTYPE(cpl_tools_get_median_6)(CPL_TYPE * self) +static void ADDTYPE(cpl_tools_get_median_6)(CPL_TYPE *self) { #ifdef CPL_TOOLS_STRICT_ERROR_CHECKING cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, (CPL_TYPE)0); #endif - CPL_TYPE_SORT(self[1], self[2]); CPL_TYPE_SORT(self[3],self[4]); - CPL_TYPE_SORT(self[0], self[1]); CPL_TYPE_SORT(self[2],self[3]); - CPL_TYPE_SORT(self[4],self[5]); CPL_TYPE_SORT(self[1], self[2]); - CPL_TYPE_SORT(self[3],self[4]); CPL_TYPE_SORT(self[0], self[1]); - CPL_TYPE_SORT(self[2],self[3]); CPL_TYPE_SORT(self[4],self[5]); - CPL_TYPE_SORT(self[1], self[2]); CPL_TYPE_SORT(self[3],self[4]); + CPL_TYPE_SORT(self[1], self[2]); + CPL_TYPE_SORT(self[3], self[4]); + CPL_TYPE_SORT(self[0], self[1]); + CPL_TYPE_SORT(self[2], self[3]); + CPL_TYPE_SORT(self[4], self[5]); + CPL_TYPE_SORT(self[1], self[2]); + CPL_TYPE_SORT(self[3], self[4]); + CPL_TYPE_SORT(self[0], self[1]); + CPL_TYPE_SORT(self[2], self[3]); + CPL_TYPE_SORT(self[4], self[5]); + CPL_TYPE_SORT(self[1], self[2]); + CPL_TYPE_SORT(self[3], self[4]); CPL_TYPE_SORT(self[2], self[3]); - } @@ -285,24 +299,28 @@ */ /*----------------------------------------------------------------------------*/ -static void ADDTYPE(cpl_tools_get_median_7)(CPL_TYPE * self) +static void ADDTYPE(cpl_tools_get_median_7)(CPL_TYPE *self) { #ifdef CPL_TOOLS_STRICT_ERROR_CHECKING cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, (CPL_TYPE)0); #endif - CPL_TYPE_SORT(self[0], self[5]); CPL_TYPE_SORT(self[0], self[3]); - CPL_TYPE_SORT(self[1], self[6]); CPL_TYPE_SORT(self[2], self[4]); - CPL_TYPE_SORT(self[0], self[1]); CPL_TYPE_SORT(self[3], self[5]); - CPL_TYPE_SORT(self[2], self[6]); CPL_TYPE_SORT(self[2], self[3]); - CPL_TYPE_SORT(self[3], self[6]); CPL_TYPE_SORT(self[4], self[5]); - CPL_TYPE_SORT(self[1], self[4]); CPL_TYPE_SORT(self[1], self[3]); + CPL_TYPE_SORT(self[0], self[5]); + CPL_TYPE_SORT(self[0], self[3]); + CPL_TYPE_SORT(self[1], self[6]); + CPL_TYPE_SORT(self[2], self[4]); + CPL_TYPE_SORT(self[0], self[1]); + CPL_TYPE_SORT(self[3], self[5]); + CPL_TYPE_SORT(self[2], self[6]); + CPL_TYPE_SORT(self[2], self[3]); + CPL_TYPE_SORT(self[3], self[6]); + CPL_TYPE_SORT(self[4], self[5]); + CPL_TYPE_SORT(self[1], self[4]); + CPL_TYPE_SORT(self[1], self[3]); CPL_TYPE_SORT(self[3], self[4]); - } - /*----------------------------------------------------------------------------*/ /** @internal @@ -317,27 +335,34 @@ */ /*----------------------------------------------------------------------------*/ -static void ADDTYPE(cpl_tools_get_median_9)(CPL_TYPE * self) +static void ADDTYPE(cpl_tools_get_median_9)(CPL_TYPE *self) { #ifdef CPL_TOOLS_STRICT_ERROR_CHECKING cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, (CPL_TYPE)0); #endif - CPL_TYPE_SORT(self[1], self[2]); CPL_TYPE_SORT(self[4], self[5]); - CPL_TYPE_SORT(self[7], self[8]); CPL_TYPE_SORT(self[0], self[1]); - CPL_TYPE_SORT(self[3], self[4]); CPL_TYPE_SORT(self[6], self[7]); - CPL_TYPE_SORT(self[1], self[2]); CPL_TYPE_SORT(self[4], self[5]); - CPL_TYPE_SORT(self[7], self[8]); CPL_TYPE_SORT(self[0], self[3]); - CPL_TYPE_SORT(self[5], self[8]); CPL_TYPE_SORT(self[4], self[7]); - CPL_TYPE_SORT(self[3], self[6]); CPL_TYPE_SORT(self[1], self[4]); - CPL_TYPE_SORT(self[2], self[5]); CPL_TYPE_SORT(self[4], self[7]); - CPL_TYPE_SORT(self[4], self[2]); CPL_TYPE_SORT(self[6], self[4]); + CPL_TYPE_SORT(self[1], self[2]); + CPL_TYPE_SORT(self[4], self[5]); + CPL_TYPE_SORT(self[7], self[8]); + CPL_TYPE_SORT(self[0], self[1]); + CPL_TYPE_SORT(self[3], self[4]); + CPL_TYPE_SORT(self[6], self[7]); + CPL_TYPE_SORT(self[1], self[2]); + CPL_TYPE_SORT(self[4], self[5]); + CPL_TYPE_SORT(self[7], self[8]); + CPL_TYPE_SORT(self[0], self[3]); + CPL_TYPE_SORT(self[5], self[8]); + CPL_TYPE_SORT(self[4], self[7]); + CPL_TYPE_SORT(self[3], self[6]); + CPL_TYPE_SORT(self[1], self[4]); + CPL_TYPE_SORT(self[2], self[5]); + CPL_TYPE_SORT(self[4], self[7]); + CPL_TYPE_SORT(self[4], self[2]); + CPL_TYPE_SORT(self[6], self[4]); CPL_TYPE_SORT(self[4], self[2]); - } - /*----------------------------------------------------------------------------*/ /** @internal @@ -355,61 +380,110 @@ */ /*----------------------------------------------------------------------------*/ -static void ADDTYPE(cpl_tools_get_median_25)(CPL_TYPE * self) +static void ADDTYPE(cpl_tools_get_median_25)(CPL_TYPE *self) { #ifdef CPL_TOOLS_STRICT_ERROR_CHECKING cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, (CPL_TYPE)0); #endif - CPL_TYPE_SORT(self[0], self[1]); CPL_TYPE_SORT(self[3], self[4]); - CPL_TYPE_SORT(self[2], self[4]); CPL_TYPE_SORT(self[2], self[3]); - CPL_TYPE_SORT(self[6], self[7]); CPL_TYPE_SORT(self[5], self[7]); - CPL_TYPE_SORT(self[5], self[6]); CPL_TYPE_SORT(self[9], self[10]); - CPL_TYPE_SORT(self[8], self[10]); CPL_TYPE_SORT(self[8], self[9]); - CPL_TYPE_SORT(self[12], self[13]); CPL_TYPE_SORT(self[11], self[13]); - CPL_TYPE_SORT(self[11], self[12]); CPL_TYPE_SORT(self[15], self[16]); - CPL_TYPE_SORT(self[14], self[16]); CPL_TYPE_SORT(self[14], self[15]); - CPL_TYPE_SORT(self[18], self[19]); CPL_TYPE_SORT(self[17], self[19]); - CPL_TYPE_SORT(self[17], self[18]); CPL_TYPE_SORT(self[21], self[22]); - CPL_TYPE_SORT(self[20], self[22]); CPL_TYPE_SORT(self[20], self[21]); - CPL_TYPE_SORT(self[23], self[24]); CPL_TYPE_SORT(self[2], self[5]); - CPL_TYPE_SORT(self[3], self[6]); CPL_TYPE_SORT(self[0], self[6]); - CPL_TYPE_SORT(self[0], self[3]); CPL_TYPE_SORT(self[4], self[7]); - CPL_TYPE_SORT(self[1], self[7]); CPL_TYPE_SORT(self[1], self[4]); - CPL_TYPE_SORT(self[11], self[14]); CPL_TYPE_SORT(self[8], self[14]); - CPL_TYPE_SORT(self[8], self[11]); CPL_TYPE_SORT(self[12], self[15]); - CPL_TYPE_SORT(self[9], self[15]); CPL_TYPE_SORT(self[9], self[12]); - CPL_TYPE_SORT(self[13], self[16]); CPL_TYPE_SORT(self[10], self[16]); - CPL_TYPE_SORT(self[10], self[13]); CPL_TYPE_SORT(self[20], self[23]); - CPL_TYPE_SORT(self[17], self[23]); CPL_TYPE_SORT(self[17], self[20]); - CPL_TYPE_SORT(self[21], self[24]); CPL_TYPE_SORT(self[18], self[24]); - CPL_TYPE_SORT(self[18], self[21]); CPL_TYPE_SORT(self[19], self[22]); - CPL_TYPE_SORT(self[8], self[17]); CPL_TYPE_SORT(self[9], self[18]); - CPL_TYPE_SORT(self[0], self[18]); CPL_TYPE_SORT(self[0], self[9]); - CPL_TYPE_SORT(self[10], self[19]); CPL_TYPE_SORT(self[1], self[19]); - CPL_TYPE_SORT(self[1], self[10]); CPL_TYPE_SORT(self[11], self[20]); - CPL_TYPE_SORT(self[2], self[20]); CPL_TYPE_SORT(self[2], self[11]); - CPL_TYPE_SORT(self[12], self[21]); CPL_TYPE_SORT(self[3], self[21]); - CPL_TYPE_SORT(self[3], self[12]); CPL_TYPE_SORT(self[13], self[22]); - CPL_TYPE_SORT(self[4], self[22]); CPL_TYPE_SORT(self[4], self[13]); - CPL_TYPE_SORT(self[14], self[23]); CPL_TYPE_SORT(self[5], self[23]); - CPL_TYPE_SORT(self[5], self[14]); CPL_TYPE_SORT(self[15], self[24]); - CPL_TYPE_SORT(self[6], self[24]); CPL_TYPE_SORT(self[6], self[15]); - CPL_TYPE_SORT(self[7], self[16]); CPL_TYPE_SORT(self[7], self[19]); - CPL_TYPE_SORT(self[13], self[21]); CPL_TYPE_SORT(self[15], self[23]); - CPL_TYPE_SORT(self[7], self[13]); CPL_TYPE_SORT(self[7], self[15]); - CPL_TYPE_SORT(self[1], self[9]); CPL_TYPE_SORT(self[3], self[11]); - CPL_TYPE_SORT(self[5], self[17]); CPL_TYPE_SORT(self[11], self[17]); - CPL_TYPE_SORT(self[9], self[17]); CPL_TYPE_SORT(self[4], self[10]); - CPL_TYPE_SORT(self[6], self[12]); CPL_TYPE_SORT(self[7], self[14]); - CPL_TYPE_SORT(self[4], self[6]); CPL_TYPE_SORT(self[4], self[7]); - CPL_TYPE_SORT(self[12], self[14]); CPL_TYPE_SORT(self[10], self[14]); - CPL_TYPE_SORT(self[6], self[7]); CPL_TYPE_SORT(self[10], self[12]); - CPL_TYPE_SORT(self[6], self[10]); CPL_TYPE_SORT(self[6], self[17]); - CPL_TYPE_SORT(self[12], self[17]); CPL_TYPE_SORT(self[7], self[17]); - CPL_TYPE_SORT(self[7], self[10]); CPL_TYPE_SORT(self[12], self[18]); - CPL_TYPE_SORT(self[7], self[12]); CPL_TYPE_SORT(self[10], self[18]); - CPL_TYPE_SORT(self[12], self[20]); CPL_TYPE_SORT(self[10], self[20]); + CPL_TYPE_SORT(self[0], self[1]); + CPL_TYPE_SORT(self[3], self[4]); + CPL_TYPE_SORT(self[2], self[4]); + CPL_TYPE_SORT(self[2], self[3]); + CPL_TYPE_SORT(self[6], self[7]); + CPL_TYPE_SORT(self[5], self[7]); + CPL_TYPE_SORT(self[5], self[6]); + CPL_TYPE_SORT(self[9], self[10]); + CPL_TYPE_SORT(self[8], self[10]); + CPL_TYPE_SORT(self[8], self[9]); + CPL_TYPE_SORT(self[12], self[13]); + CPL_TYPE_SORT(self[11], self[13]); + CPL_TYPE_SORT(self[11], self[12]); + CPL_TYPE_SORT(self[15], self[16]); + CPL_TYPE_SORT(self[14], self[16]); + CPL_TYPE_SORT(self[14], self[15]); + CPL_TYPE_SORT(self[18], self[19]); + CPL_TYPE_SORT(self[17], self[19]); + CPL_TYPE_SORT(self[17], self[18]); + CPL_TYPE_SORT(self[21], self[22]); + CPL_TYPE_SORT(self[20], self[22]); + CPL_TYPE_SORT(self[20], self[21]); + CPL_TYPE_SORT(self[23], self[24]); + CPL_TYPE_SORT(self[2], self[5]); + CPL_TYPE_SORT(self[3], self[6]); + CPL_TYPE_SORT(self[0], self[6]); + CPL_TYPE_SORT(self[0], self[3]); + CPL_TYPE_SORT(self[4], self[7]); + CPL_TYPE_SORT(self[1], self[7]); + CPL_TYPE_SORT(self[1], self[4]); + CPL_TYPE_SORT(self[11], self[14]); + CPL_TYPE_SORT(self[8], self[14]); + CPL_TYPE_SORT(self[8], self[11]); + CPL_TYPE_SORT(self[12], self[15]); + CPL_TYPE_SORT(self[9], self[15]); + CPL_TYPE_SORT(self[9], self[12]); + CPL_TYPE_SORT(self[13], self[16]); + CPL_TYPE_SORT(self[10], self[16]); + CPL_TYPE_SORT(self[10], self[13]); + CPL_TYPE_SORT(self[20], self[23]); + CPL_TYPE_SORT(self[17], self[23]); + CPL_TYPE_SORT(self[17], self[20]); + CPL_TYPE_SORT(self[21], self[24]); + CPL_TYPE_SORT(self[18], self[24]); + CPL_TYPE_SORT(self[18], self[21]); + CPL_TYPE_SORT(self[19], self[22]); + CPL_TYPE_SORT(self[8], self[17]); + CPL_TYPE_SORT(self[9], self[18]); + CPL_TYPE_SORT(self[0], self[18]); + CPL_TYPE_SORT(self[0], self[9]); + CPL_TYPE_SORT(self[10], self[19]); + CPL_TYPE_SORT(self[1], self[19]); + CPL_TYPE_SORT(self[1], self[10]); + CPL_TYPE_SORT(self[11], self[20]); + CPL_TYPE_SORT(self[2], self[20]); + CPL_TYPE_SORT(self[2], self[11]); + CPL_TYPE_SORT(self[12], self[21]); + CPL_TYPE_SORT(self[3], self[21]); + CPL_TYPE_SORT(self[3], self[12]); + CPL_TYPE_SORT(self[13], self[22]); + CPL_TYPE_SORT(self[4], self[22]); + CPL_TYPE_SORT(self[4], self[13]); + CPL_TYPE_SORT(self[14], self[23]); + CPL_TYPE_SORT(self[5], self[23]); + CPL_TYPE_SORT(self[5], self[14]); + CPL_TYPE_SORT(self[15], self[24]); + CPL_TYPE_SORT(self[6], self[24]); + CPL_TYPE_SORT(self[6], self[15]); + CPL_TYPE_SORT(self[7], self[16]); + CPL_TYPE_SORT(self[7], self[19]); + CPL_TYPE_SORT(self[13], self[21]); + CPL_TYPE_SORT(self[15], self[23]); + CPL_TYPE_SORT(self[7], self[13]); + CPL_TYPE_SORT(self[7], self[15]); + CPL_TYPE_SORT(self[1], self[9]); + CPL_TYPE_SORT(self[3], self[11]); + CPL_TYPE_SORT(self[5], self[17]); + CPL_TYPE_SORT(self[11], self[17]); + CPL_TYPE_SORT(self[9], self[17]); + CPL_TYPE_SORT(self[4], self[10]); + CPL_TYPE_SORT(self[6], self[12]); + CPL_TYPE_SORT(self[7], self[14]); + CPL_TYPE_SORT(self[4], self[6]); + CPL_TYPE_SORT(self[4], self[7]); + CPL_TYPE_SORT(self[12], self[14]); + CPL_TYPE_SORT(self[10], self[14]); + CPL_TYPE_SORT(self[6], self[7]); + CPL_TYPE_SORT(self[10], self[12]); + CPL_TYPE_SORT(self[6], self[10]); + CPL_TYPE_SORT(self[6], self[17]); + CPL_TYPE_SORT(self[12], self[17]); + CPL_TYPE_SORT(self[7], self[17]); + CPL_TYPE_SORT(self[7], self[10]); + CPL_TYPE_SORT(self[12], self[18]); + CPL_TYPE_SORT(self[7], self[12]); + CPL_TYPE_SORT(self[10], self[18]); + CPL_TYPE_SORT(self[12], self[20]); + CPL_TYPE_SORT(self[10], self[20]); CPL_TYPE_SORT(self[10], self[12]); } @@ -429,15 +503,15 @@ */ /*----------------------------------------------------------------------------*/ -double ADDTYPE(cpl_tools_get_mean)(const CPL_TYPE * a, cpl_size nn) +double ADDTYPE(cpl_tools_get_mean)(const CPL_TYPE *a, cpl_size nn) { - double mean = 0.0; + double mean = 0.0; const size_t n = (size_t)nn; size_t i; - cpl_ensure(a != NULL, CPL_ERROR_NULL_INPUT, 0.0); - cpl_ensure(nn > 0, CPL_ERROR_ILLEGAL_INPUT, 0.0); + cpl_ensure(a != NULL, CPL_ERROR_NULL_INPUT, 0.0); + cpl_ensure(nn > 0, CPL_ERROR_ILLEGAL_INPUT, 0.0); /* Ensure that the cast was OK */ cpl_ensure((cpl_size)n == nn, CPL_ERROR_UNSUPPORTED_MODE, 0.0); @@ -535,29 +609,31 @@ */ /*----------------------------------------------------------------------------*/ -double ADDTYPE(cpl_tools_get_variancesum)(const CPL_TYPE * a, - cpl_size nn, double * pmean) +double ADDTYPE(cpl_tools_get_variancesum)(const CPL_TYPE *a, + cpl_size nn, + double *pmean) { - double varsum = 0.0; - double mean = 0.0; + double varsum = 0.0; + double mean = 0.0; const size_t n = (size_t)nn; size_t i; cpl_ensure(a != NULL, CPL_ERROR_NULL_INPUT, 0.0); - cpl_ensure(nn >= 0, CPL_ERROR_ILLEGAL_INPUT, 0.0); + cpl_ensure(nn >= 0, CPL_ERROR_ILLEGAL_INPUT, 0.0); /* Ensure that the cast was OK */ cpl_ensure((cpl_size)n == nn, CPL_ERROR_UNSUPPORTED_MODE, 0.0); - for (i=0; i < n; i++) { + for (i = 0; i < n; i++) { const double delta = (double)a[i] - mean; varsum += (double)i * delta * (delta / (double)(i + 1)); - mean += delta / (double)(i + 1); + mean += delta / (double)(i + 1); } - cpl_tools_add_flops( 1 + 6 * n ); /* Assume expression reuse */ + cpl_tools_add_flops(1 + 6 * n); /* Assume expression reuse */ - if (pmean != NULL) *pmean = mean; + if (pmean != NULL) + *pmean = mean; return varsum; } @@ -573,12 +649,11 @@ @see cpl_tools_get_variancesum_double() */ /*----------------------------------------------------------------------------*/ -double ADDTYPE(cpl_tools_get_variance)(const CPL_TYPE * a, - cpl_size n, double * pmean) +double ADDTYPE(cpl_tools_get_variance)(const CPL_TYPE *a, + cpl_size n, + double *pmean) { - - const double varsum - = ADDTYPE(cpl_tools_get_variancesum)(a, n, pmean); + const double varsum = ADDTYPE(cpl_tools_get_variancesum)(a, n, pmean); cpl_ensure(n > 0, CPL_ERROR_ILLEGAL_INPUT, 0.0); @@ -599,14 +674,12 @@ */ /*----------------------------------------------------------------------------*/ -static int ADDTYPE(compar_ascn)(const void * p1, const void * p2) +static int ADDTYPE(compar_ascn)(const void *p1, const void *p2) { - const CPL_TYPE a1 = *(const CPL_TYPE *)p1; const CPL_TYPE a2 = *(const CPL_TYPE *)p2; return a1 < a2 ? -1 : (a1 > a2 ? 1 : 0); - } /*----------------------------------------------------------------------------*/ @@ -622,14 +695,12 @@ */ /*----------------------------------------------------------------------------*/ -static int ADDTYPE(compar_desc)(const void * p1, const void * p2) +static int ADDTYPE(compar_desc)(const void *p1, const void *p2) { - const CPL_TYPE a1 = *(const CPL_TYPE *)p1; const CPL_TYPE a2 = *(const CPL_TYPE *)p2; return a1 < a2 ? 1 : (a1 > a2 ? -1 : 0); - } /*----------------------------------------------------------------------------*/ @@ -656,20 +727,18 @@ */ /*----------------------------------------------------------------------------*/ -CPL_TYPE ADDTYPE(cpl_tools_quickselection)(CPL_TYPE * self, - cpl_size nn, - cpl_size kk) +CPL_TYPE + ADDTYPE(cpl_tools_quickselection)(CPL_TYPE *self, cpl_size nn, cpl_size kk) { - const size_t n = (size_t)nn; const size_t k = (size_t)kk; - size_t low = 0; - size_t high = n-1; + size_t low = 0; + size_t high = n - 1; #ifdef CPL_TOOLS_STRICT_ERROR_CHECKING - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, (CPL_TYPE)0); - cpl_ensure(nn > 0, CPL_ERROR_ILLEGAL_INPUT, (CPL_TYPE)0); - cpl_ensure(nn > kk -1, CPL_ERROR_ILLEGAL_INPUT, (CPL_TYPE)0); + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, (CPL_TYPE)0); + cpl_ensure(nn > 0, CPL_ERROR_ILLEGAL_INPUT, (CPL_TYPE)0); + cpl_ensure(nn > kk - 1, CPL_ERROR_ILLEGAL_INPUT, (CPL_TYPE)0); #endif /* Ensure that the cast was OK */ cpl_ensure((cpl_size)n == nn, CPL_ERROR_UNSUPPORTED_MODE, 0.0); @@ -677,23 +746,27 @@ /* Control flow has been changed to a single return at the end */ - for (;low + 1 < high;) { + for (; low + 1 < high;) { /* Find median of low, middle and high items; swap into position low */ const size_t middle = low + (high - low) / 2; - size_t ll = low + 1; - size_t hh = high; + size_t ll = low + 1; + size_t hh = high; CPL_TYPE_SORT(self[middle], self[high]); - CPL_TYPE_SORT(self[low], self[high]); + CPL_TYPE_SORT(self[low], self[high]); CPL_TYPE_SORT(self[middle], self[low]); /* Swap low item (now in position middle) into position (low+1) */ - CPL_TYPE_SWAP(self[middle], self[low+1]); + CPL_TYPE_SWAP(self[middle], self[low + 1]); /* Nibble from each end towards middle, swapping items when stuck */ for (;;) { - do ll++; while (self[low] > self[ll]); - do hh--; while (self[hh] > self[low]); + do + ll++; + while (self[low] > self[ll]); + do + hh--; + while (self[hh] > self[low]); if (hh < ll) break; @@ -711,7 +784,7 @@ high = hh - 1; } - if (high == low + 1) { /* Two elements only */ + if (high == low + 1) { /* Two elements only */ CPL_TYPE_SORT(self[low], self[high]); } @@ -744,9 +817,7 @@ */ /*----------------------------------------------------------------------------*/ -CPL_TYPE ADDTYPE(cpl_tools_get_kth)(CPL_TYPE * self, - cpl_size n, - cpl_size k) +CPL_TYPE ADDTYPE(cpl_tools_get_kth)(CPL_TYPE *self, cpl_size n, cpl_size k) { register cpl_size l = 0; register cpl_size m = n - 1; @@ -754,20 +825,23 @@ register cpl_size j = m; #ifdef CPL_TOOLS_STRICT_ERROR_CHECKING - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, (CPL_TYPE)0); - cpl_ensure(k >= 0, CPL_ERROR_ILLEGAL_INPUT, (CPL_TYPE)0); - cpl_ensure(k < n, CPL_ERROR_ACCESS_OUT_OF_RANGE, (CPL_TYPE)0); + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, (CPL_TYPE)0); + cpl_ensure(k >= 0, CPL_ERROR_ILLEGAL_INPUT, (CPL_TYPE)0); + cpl_ensure(k < n, CPL_ERROR_ACCESS_OUT_OF_RANGE, (CPL_TYPE)0); #endif while (l < m) { register const CPL_TYPE x = self[k]; do { - while (self[i] < x) i++; - while (x < self[j]) j--; + while (self[i] < x) + i++; + while (x < self[j]) + j--; if (i <= j) { CPL_TYPE_SWAP(self[i], self[j]); - i++; j--; + i++; + j--; } } while (i <= j); @@ -782,10 +856,12 @@ /* assert( k < i ); */ m = j; i = l; - } else { + } + else { if (k < i) { m = j; - } else { + } + else { j = m; } l = i; @@ -807,11 +883,9 @@ - CPL_ERROR_ILLEGAL_INPUT */ /*----------------------------------------------------------------------------*/ -void ADDTYPE(cpl_tools_sort_ascn)(CPL_TYPE * self, int n) +void ADDTYPE(cpl_tools_sort_ascn)(CPL_TYPE *self, int n) { - qsort(self, n, sizeof(*self), ADDTYPE(compar_ascn)); - } /*----------------------------------------------------------------------------*/ @@ -827,7 +901,7 @@ - CPL_ERROR_ILLEGAL_INPUT */ /*----------------------------------------------------------------------------*/ -void ADDTYPE(cpl_tools_sort_desc)(CPL_TYPE * self, int n) +void ADDTYPE(cpl_tools_sort_desc)(CPL_TYPE *self, int n) { qsort(self, (size_t)n, sizeof(*self), ADDTYPE(compar_desc)); } @@ -848,14 +922,13 @@ - CPL_ERROR_ILLEGAL_INPUT */ /*----------------------------------------------------------------------------*/ -cpl_error_code -ADDTYPE(cpl_tools_sort)(CPL_TYPE * self, cpl_size nn) +cpl_error_code ADDTYPE(cpl_tools_sort)(CPL_TYPE *self, cpl_size nn) { const size_t n = (size_t)nn; - size_t i, ir, j, k, l; - size_t i_stack[CPL_PIX_STACK_SIZE]; - size_t j_stack; - CPL_TYPE a; + size_t i, ir, j, k, l; + size_t i_stack[CPL_PIX_STACK_SIZE]; + size_t j_stack; + CPL_TYPE a; /* Ensure that the cast was OK */ cpl_ensure_code((cpl_size)n == nn, CPL_ERROR_UNSUPPORTED_MODE); @@ -864,46 +937,55 @@ l = 1; j_stack = 0; for (;;) { - if (ir-l < 7) { - for (j=l+1; j<=ir; j++) { - a = self[j-1]; - for (i=j-1; i>=1; i--) { - if (self[i-1] <= a) break; - self[i] = self[i-1]; + if (ir - l < 7) { + for (j = l + 1; j <= ir; j++) { + a = self[j - 1]; + for (i = j - 1; i >= 1; i--) { + if (self[i - 1] <= a) + break; + self[i] = self[i - 1]; } self[i] = a; } - if (j_stack == 0) break; - ir = i_stack[j_stack-- -1]; - l = i_stack[j_stack-- -1]; - } else { - k = (l+ir) >> 1; - CPL_TYPE_SWAP(self[k-1], self[l]); - CPL_TYPE_SORT(self[l], self[ir-1]); - CPL_TYPE_SORT(self[l-1], self[ir-1]); - CPL_TYPE_SORT(self[l], self[l-1]); - i = l+1; + if (j_stack == 0) + break; + ir = i_stack[j_stack-- - 1]; + l = i_stack[j_stack-- - 1]; + } + else { + k = (l + ir) >> 1; + CPL_TYPE_SWAP(self[k - 1], self[l]); + CPL_TYPE_SORT(self[l], self[ir - 1]); + CPL_TYPE_SORT(self[l - 1], self[ir - 1]); + CPL_TYPE_SORT(self[l], self[l - 1]); + i = l + 1; j = ir; - a = self[l-1]; + a = self[l - 1]; for (;;) { - do i++; while (self[i-1] < a); - do j--; while (self[j-1] > a); - if (j < i) break; - CPL_TYPE_SWAP(self[i-1], self[j-1]); + do + i++; + while (self[i - 1] < a); + do + j--; + while (self[j - 1] > a); + if (j < i) + break; + CPL_TYPE_SWAP(self[i - 1], self[j - 1]); } - self[l-1] = self[j-1]; - self[j-1] = a; + self[l - 1] = self[j - 1]; + self[j - 1] = a; j_stack += 2; cpl_ensure_code(j_stack <= CPL_PIX_STACK_SIZE, CPL_ERROR_ILLEGAL_INPUT); - if (ir-i+1 >= j-l) { - i_stack[j_stack-1] = ir; - i_stack[j_stack-2] = i; - ir = j-1; - } else { - i_stack[j_stack-1] = j-1; - i_stack[j_stack-2] = l; + if (ir - i + 1 >= j - l) { + i_stack[j_stack - 1] = ir; + i_stack[j_stack - 2] = i; + ir = j - 1; + } + else { + i_stack[j_stack - 1] = j - 1; + i_stack[j_stack - 2] = l; l = i; } } @@ -945,21 +1027,21 @@ - CPL_ERROR_ILLEGAL_INPUT */ /*----------------------------------------------------------------------------*/ -cpl_error_code -ADDTYPE(cpl_tools_sort_stable_pattern)(CPL_TYPE const * self, - cpl_size n, - int reverse, - int stable, - cpl_size *sort_pattern) +cpl_error_code ADDTYPE(cpl_tools_sort_stable_pattern)(CPL_TYPE const *self, + cpl_size n, + int reverse, + int stable, + cpl_size *sort_pattern) { - cpl_size i; - + cpl_size i; + /* Check entries */ cpl_ensure_code(self, CPL_ERROR_NULL_INPUT); - + cpl_ensure_code(sort_pattern, CPL_ERROR_NULL_INPUT); - if (n == 0) return CPL_ERROR_NONE; + if (n == 0) + return CPL_ERROR_NONE; for (i = 0; i < n; i++) { sort_pattern[i] = i; @@ -969,34 +1051,27 @@ * Heap sort */ for (i = n / 2 - 1; i >= 0; i--) { - int done = 0; + int done = 0; cpl_size root = i; cpl_size bottom = n - 1; - - while ((root*2 + 1 <= bottom) && (!done)) { - cpl_size child = root*2 + 1; - - if (child+1 <= bottom) { - if ((!reverse && CPL_TOOLS_SORT_LT( - self[sort_pattern[child]], - self[sort_pattern[child + 1]])) - || - (reverse && CPL_TOOLS_SORT_LT( - self[sort_pattern[child + 1]], - self[sort_pattern[child]])) - ) { + + while ((root * 2 + 1 <= bottom) && (!done)) { + cpl_size child = root * 2 + 1; + + if (child + 1 <= bottom) { + if ((!reverse && + CPL_TOOLS_SORT_LT(self[sort_pattern[child]], + self[sort_pattern[child + 1]])) || + (reverse && CPL_TOOLS_SORT_LT(self[sort_pattern[child + 1]], + self[sort_pattern[child]]))) { child += 1; } } - if ((!reverse && CPL_TOOLS_SORT_LT( - self[sort_pattern[root]], - self[sort_pattern[child]])) - || - (reverse && CPL_TOOLS_SORT_LT( - self[sort_pattern[child]], - self[sort_pattern[root]])) - ) { + if ((!reverse && CPL_TOOLS_SORT_LT(self[sort_pattern[root]], + self[sort_pattern[child]])) || + (reverse && CPL_TOOLS_SORT_LT(self[sort_pattern[child]], + self[sort_pattern[root]]))) { CPL_INT_SWAP(sort_pattern[root], sort_pattern[child]); root = child; } @@ -1005,36 +1080,29 @@ } } } - + for (i = n - 1; i >= 1; i--) { - int done = 0; + int done = 0; cpl_size root = 0; cpl_size bottom = i - 1; CPL_INT_SWAP(sort_pattern[0], sort_pattern[i]); - - while ((root*2 + 1 <= bottom) && (!done)) { - cpl_size child = root*2 + 1; - - if (child+1 <= bottom) { - if ((!reverse && CPL_TOOLS_SORT_LT( - self[sort_pattern[child]], - self[sort_pattern[child + 1]])) - || - (reverse && CPL_TOOLS_SORT_LT( - self[sort_pattern[child + 1]], - self[sort_pattern[child]])) - ) { + + while ((root * 2 + 1 <= bottom) && (!done)) { + cpl_size child = root * 2 + 1; + + if (child + 1 <= bottom) { + if ((!reverse && + CPL_TOOLS_SORT_LT(self[sort_pattern[child]], + self[sort_pattern[child + 1]])) || + (reverse && CPL_TOOLS_SORT_LT(self[sort_pattern[child + 1]], + self[sort_pattern[child]]))) { child += 1; } } - if ((!reverse && CPL_TOOLS_SORT_LT( - self[sort_pattern[root]], - self[sort_pattern[child]])) - || - (reverse && CPL_TOOLS_SORT_LT( - self[sort_pattern[child]], - self[sort_pattern[root]])) - ) { + if ((!reverse && CPL_TOOLS_SORT_LT(self[sort_pattern[root]], + self[sort_pattern[child]])) || + (reverse && CPL_TOOLS_SORT_LT(self[sort_pattern[child]], + self[sort_pattern[root]]))) { CPL_INT_SWAP(sort_pattern[root], sort_pattern[child]); root = child; } @@ -1051,19 +1119,19 @@ for (i = 0; i < n; i++) { cpl_size j; j = i + 1; - while(j < n && - !CPL_TOOLS_SORT_LT(self[sort_pattern[i]], - self[sort_pattern[j]]) && - !CPL_TOOLS_SORT_LT(self[sort_pattern[j]], - self[sort_pattern[i]])) { + while (j < n && + !CPL_TOOLS_SORT_LT(self[sort_pattern[i]], + self[sort_pattern[j]]) && + !CPL_TOOLS_SORT_LT(self[sort_pattern[j]], + self[sort_pattern[i]])) { j++; } if (j - i > 1) { cpl_tools_sort_cplsize(sort_pattern + i, j - i); } - i = j - 1; + i = j - 1; } - } + } return CPL_ERROR_NONE; } @@ -1097,23 +1165,25 @@ - CPL_ERROR_INCOMPATIBLE_INPUT only one of bread/bwrite is NULL */ /*----------------------------------------------------------------------------*/ -cpl_error_code -ADDTYPE(cpl_tools_permute)(cpl_size * self, cpl_size n, - CPL_TYPE * awrite, CPL_TYPE const * aread, - CPL_TYPE * bwrite, CPL_TYPE const * bread) +cpl_error_code ADDTYPE(cpl_tools_permute)(cpl_size *self, + cpl_size n, + CPL_TYPE *awrite, + CPL_TYPE const *aread, + CPL_TYPE *bwrite, + CPL_TYPE const *bread) { - cpl_size ido = 0; /* First element in cycle to process */ const cpl_boolean dob = bwrite != NULL; - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(n > 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(n > 0, CPL_ERROR_ILLEGAL_INPUT); cpl_ensure_code(awrite != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(aread != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(aread != NULL, CPL_ERROR_NULL_INPUT); if (dob) { cpl_ensure_code(bread != NULL, CPL_ERROR_INCOMPATIBLE_INPUT); - } else { + } + else { cpl_ensure_code(bread == NULL, CPL_ERROR_INCOMPATIBLE_INPUT); } @@ -1131,20 +1201,22 @@ ifrom = self[ifrom]; /* Point to next in cycle */ - assert( ifrom != -1 ); /* Can fail only on non-perm array */ + assert(ifrom != -1); /* Can fail only on non-perm array */ awrite[j] = areadj; - if (dob) bwrite[j] = breadj; - self [j] = -1; /* This position now has the right value */ - + if (dob) + bwrite[j] = breadj; + self[j] = -1; /* This position now has the right value */ } /* Cycle is finished, copy and flag last pair */ awrite[ifrom] = aread0; - if (dob) bwrite[ifrom] = bread0; + if (dob) + bwrite[ifrom] = bread0; self[ifrom] = -1; /* Find start of next cycle */ - while (++ido < n && self[ido] < 0); + while (++ido < n && self[ido] < 0) + ; } while (ido < n); return CPL_ERROR_NONE; diff -Nru cpl-7.1.4+ds/cplcore/cpl_tools.c cpl-7.2.2+ds/cplcore/cpl_tools.c --- cpl-7.1.4+ds/cplcore/cpl_tools.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_tools.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -56,10 +56,15 @@ #endif /* Swap macros */ -#define CPL_INT_SWAP(a,b) { register const cpl_size t=(a); (a)=(b); (b)=t; } +#define CPL_INT_SWAP(a, b) \ + { \ + register const cpl_size t = (a); \ + (a) = (b); \ + (b) = t; \ + } -#define CONCAT(a,b) a ## _ ## b -#define CONCAT2X(a,b) CONCAT(a,b) +#define CONCAT(a, b) a##_##b +#define CONCAT2X(a, b) CONCAT(a, b) /*----------------------------------------------------------------------------- Private variables @@ -88,9 +93,9 @@ #define CPL_TYPE_IS_TYPE_PIXEL #define CPL_TYPE_IS_NUM -#define CPL_TYPE int -#define CPL_TYPE_NAME int -#define CPL_TOOLS_SORT_LT(x,y) ((x) < (y)) +#define CPL_TYPE int +#define CPL_TYPE_NAME int +#define CPL_TOOLS_SORT_LT(x, y) ((x) < (y)) #include "cpl_tools_body.h" #undef CPL_TYPE #undef CPL_TYPE_NAME @@ -98,43 +103,43 @@ #undef CPL_TYPE_IS_TYPE_PIXEL #define CPL_TYPE_IS_NUM -#define CPL_TYPE long -#define CPL_TYPE_NAME long -#define CPL_TOOLS_SORT_LT(x,y) ((x) < (y)) +#define CPL_TYPE long +#define CPL_TYPE_NAME long +#define CPL_TOOLS_SORT_LT(x, y) ((x) < (y)) #include "cpl_tools_body.h" #undef CPL_TYPE #undef CPL_TYPE_NAME #undef CPL_TOOLS_SORT_LT #define CPL_TYPE_IS_NUM -#define CPL_TYPE long long -#define CPL_TYPE_NAME long_long -#define CPL_TOOLS_SORT_LT(x,y) ((x) < (y)) +#define CPL_TYPE long long +#define CPL_TYPE_NAME long_long +#define CPL_TOOLS_SORT_LT(x, y) ((x) < (y)) #include "cpl_tools_body.h" #undef CPL_TYPE #undef CPL_TYPE_NAME #undef CPL_TOOLS_SORT_LT -#define CPL_TYPE cpl_size -#define CPL_TYPE_NAME cplsize -#define CPL_TOOLS_SORT_LT(x,y) ((x) < (y)) +#define CPL_TYPE cpl_size +#define CPL_TYPE_NAME cplsize +#define CPL_TOOLS_SORT_LT(x, y) ((x) < (y)) #include "cpl_tools_body.h" #undef CPL_TYPE #undef CPL_TYPE_NAME #undef CPL_TOOLS_SORT_LT #define CPL_TYPE_IS_TYPE_PIXEL -#define CPL_TYPE float -#define CPL_TYPE_NAME float -#define CPL_TOOLS_SORT_LT(x,y) ((x) < (y)) +#define CPL_TYPE float +#define CPL_TYPE_NAME float +#define CPL_TOOLS_SORT_LT(x, y) ((x) < (y)) #include "cpl_tools_body.h" #undef CPL_TYPE #undef CPL_TYPE_NAME #undef CPL_TOOLS_SORT_LT -#define CPL_TYPE double -#define CPL_TYPE_NAME double -#define CPL_TOOLS_SORT_LT(x,y) ((x) < (y)) +#define CPL_TYPE double +#define CPL_TYPE_NAME double +#define CPL_TOOLS_SORT_LT(x, y) ((x) < (y)) #include "cpl_tools_body.h" #undef CPL_TYPE #undef CPL_TYPE_NAME @@ -142,11 +147,11 @@ #undef CPL_TYPE_IS_NUM #undef CPL_TYPE_IS_TYPE_PIXEL -#define CPL_TYPE char * +#define CPL_TYPE char * #define CPL_TYPE_NAME string -#define CPL_TOOLS_SORT_LT(x,y) (((x) == NULL && (y) != NULL) || \ - ((x) != NULL && (y) != NULL && \ - strcmp((x), (y)) < 0)) +#define CPL_TOOLS_SORT_LT(x, y) \ + (((x) == NULL && (y) != NULL) || \ + ((x) != NULL && (y) != NULL && strcmp((x), (y)) < 0)) #include "cpl_tools_body.h" #undef CPL_TYPE #undef CPL_TYPE_NAME @@ -183,12 +188,14 @@ */ /*----------------------------------------------------------------------------*/ -inline void cpl_ifalloc_set(cpl_ifalloc * self, size_t size) +inline void +cpl_ifalloc_set(cpl_ifalloc *self, size_t size) { if (size > (size_t)CPL_IFALLOC_SZ) { self->data = self->heap = cpl_malloc(size); - } else { - self->data = (void*)(self->stack); + } + else { + self->data = (void *)(self->stack); self->heap = NULL; } } @@ -203,7 +210,8 @@ */ /*----------------------------------------------------------------------------*/ -inline void * cpl_ifalloc_get(cpl_ifalloc * self) +inline void * +cpl_ifalloc_get(cpl_ifalloc *self) { return self->data; } @@ -216,9 +224,11 @@ @see cpl_ifalloc_set */ /*----------------------------------------------------------------------------*/ -inline void cpl_ifalloc_free(cpl_ifalloc * self) +inline void +cpl_ifalloc_free(cpl_ifalloc *self) { - if (self->heap != NULL) cpl_free(self->heap); /* Typically NULL */ + if (self->heap != NULL) + cpl_free(self->heap); /* Typically NULL */ } /*----------------------------------------------------------------------------*/ @@ -242,41 +252,41 @@ */ /*----------------------------------------------------------------------------*/ -int cpl_tools_get_bpp(cpl_type type) +int +cpl_tools_get_bpp(cpl_type type) { int bpp; /* switch on type without POINTER and ARRAY bits */ switch (type & ~CPL_TYPE_POINTER & ~CPL_TYPE_FLAG_ARRAY) { - - case CPL_TYPE_UCHAR: - bpp = BYTE_IMG; /* 8 */ - break; - - case CPL_TYPE_SHORT: - bpp = SHORT_IMG; /* 16 */ - break; - - case CPL_TYPE_USHORT: - bpp = USHORT_IMG; /* 20 */ - break; - - case CPL_TYPE_INT: - bpp = LONG_IMG; /* 32 */ - break; - - case CPL_TYPE_FLOAT: - bpp = FLOAT_IMG; /* -32 */ - break; - - case CPL_TYPE_DOUBLE: - bpp = DOUBLE_IMG; /* -64 */ - break; - - default: - bpp = 0; - (void)cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, - "type=0x%x", (int)type); + case CPL_TYPE_UCHAR: + bpp = BYTE_IMG; /* 8 */ + break; + + case CPL_TYPE_SHORT: + bpp = SHORT_IMG; /* 16 */ + break; + + case CPL_TYPE_USHORT: + bpp = USHORT_IMG; /* 20 */ + break; + + case CPL_TYPE_INT: + bpp = LONG_IMG; /* 32 */ + break; + + case CPL_TYPE_FLOAT: + bpp = FLOAT_IMG; /* -32 */ + break; + + case CPL_TYPE_DOUBLE: + bpp = DOUBLE_IMG; /* -64 */ + break; + + default: + bpp = 0; + (void)cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, "type=0x%x", + (int)type); } return bpp; @@ -291,12 +301,14 @@ @return The corresponding power of 2 or -1 if p is not a power of 2 */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_tools_is_power_of_2(cpl_size p) +cpl_size +cpl_tools_is_power_of_2(cpl_size p) { cpl_size ipow = 0; cpl_size done; - if (p <= 0) return -1; + if (p <= 0) + return -1; /* Count until 1st non-zero bit is found */ do { @@ -306,8 +318,7 @@ } while (!done); /* The number is a power iff p is now zero */ - return p == 0 ? ipow-1 : -1; - + return p == 0 ? ipow - 1 : -1; } /*----------------------------------------------------------------------------*/ @@ -323,9 +334,9 @@ */ /*----------------------------------------------------------------------------*/ -double cpl_tools_ipow(double x, int y) +double +cpl_tools_ipow(double x, int y) { - double result; double pow2 = x; int p = abs(y); @@ -341,11 +352,12 @@ while (p >>= 1) { pow2 *= pow2; /* Process least significant bit in p */ - if (p & 1) result *= pow2; + if (p & 1) + result *= pow2; } /* It is left to the caller to ensure that no division by zero occurs */ - return y < 0 ? 1.0/result : result; + return y < 0 ? 1.0 / result : result; } /*----------------------------------------------------------------------------*/ @@ -359,7 +371,8 @@ */ /*----------------------------------------------------------------------------*/ -inline void cpl_tools_add_flops_(cpl_flops flops) +inline void +cpl_tools_add_flops_(cpl_flops flops) { #ifdef _OPENMP #pragma omp atomic @@ -377,9 +390,10 @@ */ /*----------------------------------------------------------------------------*/ -cpl_flops cpl_tools_get_flops(void) +cpl_flops +cpl_tools_get_flops(void) { - return flop_count; + return flop_count; } /*----------------------------------------------------------------------------*/ @@ -393,16 +407,15 @@ */ /*----------------------------------------------------------------------------*/ -cpl_vector * cpl_vector_transform_mean(const cpl_vector * x, double * pm) +cpl_vector * +cpl_vector_transform_mean(const cpl_vector *x, double *pm) { - - cpl_vector * xhat = cpl_vector_duplicate(x); + cpl_vector *xhat = cpl_vector_duplicate(x); *pm = cpl_vector_get_mean(xhat); cpl_vector_subtract_scalar(xhat, *pm); return xhat; - } @@ -416,20 +429,20 @@ */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_vector_count_distinct(cpl_vector * self, - cpl_size * pndistinct) +cpl_error_code +cpl_vector_count_distinct(cpl_vector *self, cpl_size *pndistinct) { - if (pndistinct == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); - } else if (cpl_vector_sort(self, CPL_SORT_ASCENDING)) { + } + else if (cpl_vector_sort(self, CPL_SORT_ASCENDING)) { return cpl_error_set_where_(); - } else { - - const double * dx = cpl_vector_get_data_const(self); - double xmin = dx[0]; + } + else { + const double *dx = cpl_vector_get_data_const(self); + double xmin = dx[0]; const cpl_size n = cpl_vector_get_size(self); - cpl_size i, j; + cpl_size i, j; for (j = i = 1; i < n; i++) { if (dx[i] > xmin) { @@ -456,40 +469,43 @@ */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_vector_ensure_distinct(const cpl_vector * self, - cpl_size ndistinct) +cpl_error_code +cpl_vector_ensure_distinct(const cpl_vector *self, cpl_size ndistinct) { - if (ndistinct > 1) { const cpl_size n = cpl_vector_get_size(self); if (n < 1) { return cpl_error_set_where_(); - } else if (ndistinct > n) { - return cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, - "A %" CPL_SIZE_FORMAT "-element " - "vector cannot have at least %" - CPL_SIZE_FORMAT " distinct values", - n, ndistinct); - } else { - cpl_vector * tmp = cpl_vector_duplicate(self); - cpl_size idistinct = 0; + } + else if (ndistinct > n) { + return cpl_error_set_message_( + CPL_ERROR_DATA_NOT_FOUND, + "A %" CPL_SIZE_FORMAT "-element " + "vector cannot have at least %" CPL_SIZE_FORMAT + " distinct values", + n, ndistinct); + } + else { + cpl_vector *tmp = cpl_vector_duplicate(self); + cpl_size idistinct = 0; (void)cpl_vector_count_distinct(tmp, &idistinct); cpl_vector_delete(tmp); if (idistinct < ndistinct) { - return cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, "%" - CPL_SIZE_FORMAT "-element vector " - "must have at least %" - CPL_SIZE_FORMAT " (not %" - CPL_SIZE_FORMAT ") distinct " - " values", n, ndistinct, - idistinct); + return cpl_error_set_message_( + CPL_ERROR_DATA_NOT_FOUND, + "%" CPL_SIZE_FORMAT "-element vector " + "must have at least %" CPL_SIZE_FORMAT + " (not %" CPL_SIZE_FORMAT ") distinct " + " values", + n, ndistinct, idistinct); } } - } else if (ndistinct < 1) { + } + else if (ndistinct < 1) { return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); } @@ -519,22 +535,27 @@ - CPL_ERROR_ILLEGAL_INPUT if the window coordinates are not valid */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_tools_copy_window(void *self, const void *src, size_t size, - cpl_size nx, cpl_size ny, - cpl_size llx, cpl_size lly, - cpl_size urx, cpl_size ury) +cpl_error_code +cpl_tools_copy_window(void *self, + const void *src, + size_t size, + cpl_size nx, + cpl_size ny, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury) { - /* FIXME: Need to do pointer arithmetic */ - const char * csrc = (const char*)src; + const char *csrc = (const char *)src; - cpl_ensure_code(size != 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(size != 0, CPL_ERROR_ILLEGAL_INPUT); cpl_ensure_code(llx <= urx, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(lly > 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(lly > 0, CPL_ERROR_ILLEGAL_INPUT); cpl_ensure_code(lly <= ury, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(ury <= ny, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(ury <= ny, CPL_ERROR_ILLEGAL_INPUT); /* assert(sizeof(char) == 1); */ @@ -544,22 +565,23 @@ /* Number of bytes in one row of self */ const size_t rowsize = size * (size_t)nx; - (void)memcpy(self, csrc + rowsize * (size_t)(lly-1), - rowsize * (size_t)(ury-lly+1)); - } else { + (void)memcpy(self, csrc + rowsize * (size_t)(lly - 1), + rowsize * (size_t)(ury - lly + 1)); + } + else { /* FIXME: Need to do pointer arithmetic */ - char * cself = (char*)self; + char *cself = (char *)self; /* Number of bytes in one row of self */ - const size_t rowsize = size * (size_t)(urx-llx+1); + const size_t rowsize = size * (size_t)(urx - llx + 1); /* Byte just after last byte to write to self */ - const char * cstop = cself + rowsize * (size_t)(ury-lly+1); + const char *cstop = cself + rowsize * (size_t)(ury - lly + 1); - cpl_ensure_code(llx > 0, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(urx <= nx, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(llx > 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(urx <= nx, CPL_ERROR_ILLEGAL_INPUT); /* Point to first byte to read */ - csrc += size * (size_t)((llx - 1) + (lly-1) * nx); + csrc += size * (size_t)((llx - 1) + (lly - 1) * nx); for (; cself < cstop; cself += rowsize, csrc += size * (size_t)nx) { (void)memcpy(cself, csrc, rowsize); @@ -567,7 +589,7 @@ } return CPL_ERROR_NONE; -} +} /*----------------------------------------------------------------------------*/ /** @@ -594,28 +616,32 @@ nx or ny non-positive */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_tools_shift_window(void * self, size_t size, - cpl_size nx, cpl_size ny, int null, - cpl_size dx, cpl_size dy) +cpl_error_code +cpl_tools_shift_window(void *self, + size_t size, + cpl_size nx, + cpl_size ny, + int null, + cpl_size dx, + cpl_size dy) { - /* Need to do pointer arithmetic */ - char * myself = (char*)self; + char *myself = (char *)self; /* Number of elements to be set to null */ - const size_t sset = (size_t)(labs((long int)dy) * nx) * size; + const size_t sset = (size_t)(labs((long int)dy) * nx) * size; /* Remainder of buffer will be moved */ const size_t smove = (size_t)(ny * nx) * size - sset; - char * pdest = dy < 0 ? myself : myself + sset; - char * psrc = dy > 0 ? myself : myself + sset; /* const */ - char * pset = dy > 0 ? myself : myself + smove; - - cpl_ensure_code(size > 0, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(nx > 0, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(ny > 0, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code( dx < nx, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(-dx < nx, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code( dy < ny, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(-dy < ny, CPL_ERROR_ILLEGAL_INPUT); + char *pdest = dy < 0 ? myself : myself + sset; + char *psrc = dy > 0 ? myself : myself + sset; /* const */ + char *pset = dy > 0 ? myself : myself + smove; + + cpl_ensure_code(size > 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(nx > 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(ny > 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(dx < nx, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(-dx < nx, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(dy < ny, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(-dy < ny, CPL_ERROR_ILLEGAL_INPUT); if (dx != 0) { @@ -628,39 +654,42 @@ /* Remainder of buffer will be moved */ const size_t srmove = rsize - srset; - char * prdest = dx < 0 ? pdest : pdest + srset; - char * prsrc = dx > 0 ? psrc : psrc + srset; - char * prset = dx > 0 ? pdest : pdest + srmove; + char *prdest = dx < 0 ? pdest : pdest + srset; + char *prsrc = dx > 0 ? psrc : psrc + srset; + char *prset = dx > 0 ? pdest : pdest + srmove; /* source and dest overlap when dy is zero */ - void * (*myshift)(void *, const void *, size_t) = dy ? memcpy : memmove; + void *(*myshift)(void *, const void *, size_t) = dy ? memcpy : memmove; cpl_size j; if (dy <= 0) { - for (j = -dy; j < ny; j++, - prdest += rsize, prsrc += rsize, prset += rsize) { + for (j = -dy; j < ny; + j++, prdest += rsize, prsrc += rsize, prset += rsize) { (void)myshift(prdest, prsrc, srmove); (void)memset(prset, null, srset); } - } else { + } + else { /* With a positive dy the rows must be shifted in reverse order */ prdest += smove - rsize; - prsrc += smove - rsize; - prset += smove - rsize; + prsrc += smove - rsize; + prset += smove - rsize; - for (j = dy; j < ny; j++, - prdest -= rsize, prsrc -= rsize, prset -= rsize) { + for (j = dy; j < ny; + j++, prdest -= rsize, prsrc -= rsize, prset -= rsize) { (void)memcpy(prdest, prsrc, srmove); (void)memset(prset, null, srset); } } - } else if (dy != 0) { + } + else if (dy != 0) { /* Shift all rows at once */ (void)memmove(pdest, psrc, smove); } /* Set all of the 'empty' rows */ - if (dy != 0) (void)memset(pset, null, sset); + if (dy != 0) + (void)memset(pset, null, sset); return CPL_ERROR_NONE; } diff -Nru cpl-7.1.4+ds/cplcore/cpl_tools.h cpl-7.2.2+ds/cplcore/cpl_tools.h --- cpl-7.1.4+ds/cplcore/cpl_tools.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_tools.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -59,23 +59,64 @@ @return A pseudo-random number in the range 0 to 1 @see rand() */ -#define cpl_drand() ((double)rand()/(double)RAND_MAX) +#define cpl_drand() ((double)rand() / (double)RAND_MAX) -#define CPL_FITS_BADKEYS "SIMPLE|BSCALE|BZERO|EXTEND" \ - "|XTENSION|BITPIX|NAXIS[0-9]*|PCOUNT|GCOUNT|DATE" "" \ - "|TFIELDS|TFORM[0-9]*|TTYPE[0-9]*|TUNIT[0-9]*|TZERO[0-9]*" \ - "|TSCAL[0-9]*|TDIM[0-9]*|TNULL[0-9]*" - -#define CPL_FITS_BADKEYS_PRIM "^(" CPL_FITS_BADKEYS \ - "|BLOCKED" ")$" - -#define CPL_FITS_BADKEYS_EXT "^(" CPL_FITS_BADKEYS \ - "|ORIGIN[0-9]*)$" - -#define CPL_FITS_COMPRKEYS "^(" "ZIMAGE|ZCMPTYPE|ZNAXIS" \ - "|ZTENSION|ZPCOUNT|ZGCOUNT|ZNAME[0-9]|ZVAL[0-9]" \ - "|ZTILE[0-9]|ZBITPIX|ZNAXIS[0-9]|ZSCALE|ZZERO" \ - "|ZBLANK|ZHECKSUM|ZDATASUM" ")$" +/* Flag to specify WCS key removal */ +#define CPL_IO_WCS ((CPL_IO_MAX) << 1) + +#define CPL_FITS_EXACT \ + CXSTR("SIMPLE", 6), CXSTR("BSCALE", 6), CXSTR("BZERO", 5), \ + CXSTR("EXTEND", 6), CXSTR("XTENSION", 8), CXSTR("BITPIX", 6), \ + CXSTR("PCOUNT", 6), CXSTR("GCOUNT", 6), CXSTR("DATE", 4), \ + CXSTR("TFIELDS", 7) + +#define CPL_FITS_EXACT_TILE \ + CXSTR("ZIMAGE", 6), CXSTR("ZCMPTYPE", 8), CXSTR("ZNAXIS", 6), \ + CXSTR("ZTENSION", 8), CXSTR("ZPCOUNT", 7), CXSTR("ZGCOUNT", 7), \ + CXSTR("ZBITPIX", 7), CXSTR("ZSCALE", 6), CXSTR("ZZERO", 5), \ + CXSTR("ZBLANK", 6), CXSTR("ZHECKSUM", 8), CXSTR("ZDATASUM", 8) + +#define CPL_FITS_EXACT_EXT CPL_FITS_EXACT, CPL_FITS_EXACT_TILE + +#define CPL_FITS_EXACT_PRIM CXSTR("BLOCKED", 7), CPL_FITS_EXACT_EXT + +#define CPL_FITS_START \ + CXSTR("NAXIS", 5), CXSTR("TFORM", 5), CXSTR("TTYPE", 5), \ + CXSTR("TUNIT", 5), CXSTR("TZERO", 5), CXSTR("TSCAL", 5), \ + CXSTR("TDIM", 4), CXSTR("TNULL", 5) + +#define CPL_FITS_START \ + CXSTR("NAXIS", 5), CXSTR("TFORM", 5), CXSTR("TTYPE", 5), \ + CXSTR("TUNIT", 5), CXSTR("TZERO", 5), CXSTR("TSCAL", 5), \ + CXSTR("TDIM", 4), CXSTR("TNULL", 5) + +#define CPL_FITS_START_TILE \ + CXSTR("ZNAME", 5), CXSTR("ZVAL", 4), CXSTR("ZTILE", 5), CXSTR("ZNAXIS", 6) + +#define CPL_FITS_START_PRIM CPL_FITS_START, CPL_FITS_START_TILE + +#define CPL_FITS_START_EXT CXSTR("ORIGIN", 6), CPL_FITS_START_PRIM + +#define CPL_FITS_BADKEYS \ + "SIMPLE|BSCALE|BZERO|EXTEND" \ + "|XTENSION|BITPIX|NAXIS[0-9]*|PCOUNT|GCOUNT|DATE" \ + "" \ + "|TFIELDS|TFORM[0-9]*|TTYPE[0-9]*|TUNIT[0-9]*|TZERO[0-9]*" \ + "|TSCAL[0-9]*|TDIM[0-9]*|TNULL[0-9]*" + +#define CPL_FITS_BADKEYS_PRIM \ + "^(" CPL_FITS_BADKEYS "|BLOCKED" \ + ")$" + +#define CPL_FITS_BADKEYS_EXT "^(" CPL_FITS_BADKEYS "|ORIGIN[0-9]*)$" + +#define CPL_FITS_COMPRKEYS \ + "^(" \ + "ZIMAGE|ZCMPTYPE|ZNAXIS" \ + "|ZTENSION|ZPCOUNT|ZGCOUNT|ZNAME[0-9]|ZVAL[0-9]" \ + "|ZTILE[0-9]|ZBITPIX|ZNAXIS[0-9]|ZSCALE|ZZERO" \ + "|ZBLANK|ZHECKSUM|ZDATASUM" \ + ")$" /** @internal @@ -83,9 +124,9 @@ @see fits_get_colnum @note Missing one const modifier in CFITSIO 3.42 */ -#define cpl_fits_get_colnum(A, B, C, D, E) \ - CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); \ - fits_get_colnum(A, B, (char*)C, D, E); \ +#define cpl_fits_get_colnum(A, B, C, D, E) \ + CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); \ + fits_get_colnum(A, B, (char *)C, D, E); \ CPL_DIAG_PRAGMA_POP /** @@ -94,9 +135,9 @@ @see fits_write_colnull @note Missing two const modifiers in CFITSIO 3.42 */ -#define cpl_fits_write_colnull(A, B, C, D, E, F, G, H, I) \ - CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); \ - fits_write_colnull(A, B, C, D, E, F, (void*)G, (void*)H, I); \ +#define cpl_fits_write_colnull(A, B, C, D, E, F, G, H, I) \ + CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); \ + fits_write_colnull(A, B, C, D, E, F, (void *)G, (void *)H, I); \ CPL_DIAG_PRAGMA_POP /** @@ -105,34 +146,35 @@ @see fits_create_tbl @note Missing three const modifiers in CFITSIO 3.42 */ -#define cpl_fits_create_tbl(A, B, C, D, E, F, G, H, I) \ - CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); \ - fits_create_tbl(A, B, C, D, (char**)E, (char**)F, (char**)G, H, I); \ +#define cpl_fits_create_tbl(A, B, C, D, E, F, G, H, I) \ + CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); \ + fits_create_tbl(A, B, C, D, (char **)E, (char **)F, (char **)G, H, I); \ CPL_DIAG_PRAGMA_POP /* CFITSIO support for I/O of largest possible buffers. */ /* FIXME: Add CPL_FITSIO_FORMAT w. "ld" for long int, but need a format string for LONGLONG */ -#if defined fits_get_img_sizell && defined fits_read_pixll && defined fits_create_imgll -#define CPL_FITSIO_GET_SIZE fits_get_img_sizell -#define CPL_FITSIO_READ_PIX cpl_fits_read_pixll +#if defined fits_get_img_sizell && defined fits_read_pixll && \ + defined fits_create_imgll +#define CPL_FITSIO_GET_SIZE fits_get_img_sizell +#define CPL_FITSIO_READ_PIX cpl_fits_read_pixll #define CPL_FITSIO_READ_PIX_E fits_read_pixll -#define CPL_FITSIO_RESIZE_IMG fits_resize_imgll -#define CPL_FITSIO_CREATE_IMG cpl_fits_create_imgll -#define CPL_FITSIO_CREATE_IMG_E fits_create_imgll -#define CPL_FITSIO_WRITE_PIX cpl_fits_write_pixll -#define CPL_FITSIO_WRITE_PIX_E fits_write_pixll -#define CPL_FITSIO_TYPE LONGLONG +#define CPL_FITSIO_RESIZE_IMG fits_resize_imgll +#define CPL_FITSIO_CREATE_IMG cpl_fits_create_imgll +#define CPL_FITSIO_CREATE_IMG_E fits_create_imgll +#define CPL_FITSIO_WRITE_PIX cpl_fits_write_pixll +#define CPL_FITSIO_WRITE_PIX_E fits_write_pixll +#define CPL_FITSIO_TYPE LONGLONG #else -#define CPL_FITSIO_GET_SIZE fits_get_img_size -#define CPL_FITSIO_READ_PIX cpl_fits_read_pix +#define CPL_FITSIO_GET_SIZE fits_get_img_size +#define CPL_FITSIO_READ_PIX cpl_fits_read_pix #define CPL_FITSIO_READ_PIX_E fits_read_pix -#define CPL_FITSIO_RESIZE_IMG fits_resize_img -#define CPL_FITSIO_CREATE_IMG cpl_fits_create_img -#define CPL_FITSIO_CREATE_IMG_E fits_create_img -#define CPL_FITSIO_WRITE_PIX cpl_fits_write_pix -#define CPL_FITSIO_WRITE_PIX_E fits_write_pix -#define CPL_FITSIO_TYPE long int +#define CPL_FITSIO_RESIZE_IMG fits_resize_img +#define CPL_FITSIO_CREATE_IMG cpl_fits_create_img +#define CPL_FITSIO_CREATE_IMG_E fits_create_img +#define CPL_FITSIO_WRITE_PIX cpl_fits_write_pix +#define CPL_FITSIO_WRITE_PIX_E fits_write_pix +#define CPL_FITSIO_TYPE long int #endif #ifdef CPL_ADD_FLOPS @@ -143,9 +185,9 @@ /* FIXME: Move to cpl_macros.h */ #if __GNUC__ >= 7 -# define CPL_ATTR_FALLTRHU __attribute__ ((fallthrough)) +#define CPL_ATTR_FALLTRHU __attribute__((fallthrough)) #else -# define CPL_ATTR_FALLTRHU /* fall through */ +#define CPL_ATTR_FALLTRHU /* fall through */ #endif @@ -160,31 +202,35 @@ useful in tracing a process that terminates unexpectedly. */ /*----------------------------------------------------------------------------*/ -#define cpl_tools_trace(LEVEL) \ - do { \ - const cpl_msg_severity cpl_tools_trace_level = LEVEL; \ - if (cpl_tools_trace_level == CPL_MSG_ERROR || \ - cpl_tools_trace_level == CPL_MSG_WARNING || \ - cpl_tools_trace_level == CPL_MSG_INFO || \ - cpl_tools_trace_level == CPL_MSG_DEBUG) { \ - (cpl_tools_trace_level == CPL_MSG_ERROR ? cpl_msg_error : \ - (cpl_tools_trace_level == CPL_MSG_WARNING ? cpl_msg_warning : \ - (cpl_tools_trace_level == CPL_MSG_INFO ? cpl_msg_info : \ - cpl_msg_debug))) (cpl_func, "TRACE: " __FILE__ \ - " at line " CPL_STRINGIFY(__LINE__)); \ - (void)fflush(stdout); \ - (void)fflush(stderr); \ - } \ +#define cpl_tools_trace(LEVEL) \ + do { \ + const cpl_msg_severity cpl_tools_trace_level = LEVEL; \ + if (cpl_tools_trace_level == CPL_MSG_ERROR || \ + cpl_tools_trace_level == CPL_MSG_WARNING || \ + cpl_tools_trace_level == CPL_MSG_INFO || \ + cpl_tools_trace_level == CPL_MSG_DEBUG) { \ + (cpl_tools_trace_level == CPL_MSG_ERROR \ + ? cpl_msg_error \ + : (cpl_tools_trace_level == CPL_MSG_WARNING \ + ? cpl_msg_warning \ + : (cpl_tools_trace_level == CPL_MSG_INFO \ + ? cpl_msg_info \ + : cpl_msg_debug)))(cpl_func, \ + "TRACE: " __FILE__ \ + " at line " CPL_STRINGIFY(__LINE__)); \ + (void)fflush(stdout); \ + (void)fflush(stderr); \ + } \ } while (0) #if defined HAVE_LONG_DOUBLE && HAVE_LONG_DOUBLE == 1 typedef long double cpl_long_double; -#define CPL_LDBL_EPSILON LDBL_EPSILON +#define CPL_LDBL_EPSILON LDBL_EPSILON #define CPL_LDBL_EPSILON_STR "LDBL_EPSILON" #else typedef double cpl_long_double; -#define CPL_LDBL_EPSILON DBL_EPSILON +#define CPL_LDBL_EPSILON DBL_EPSILON #define CPL_LDBL_EPSILON_STR "DBL_EPSILON" #endif @@ -209,9 +255,10 @@ @see cpl_ifalloc_set */ /*----------------------------------------------------------------------------*/ -typedef struct { - void * data; - void * heap; +typedef struct +{ + void *data; + void *heap; char stack[CPL_IFALLOC_SZ]; } cpl_ifalloc; @@ -219,7 +266,7 @@ Function prototypes -----------------------------------------------------------------------------*/ void cpl_ifalloc_set(cpl_ifalloc *, size_t) CPL_ATTR_NONNULL; -void * cpl_ifalloc_get(cpl_ifalloc *) CPL_ATTR_NONNULL; +void *cpl_ifalloc_get(cpl_ifalloc *) CPL_ATTR_NONNULL; void cpl_ifalloc_free(cpl_ifalloc *) CPL_ATTR_NONNULL; /* Operations on arrays */ @@ -227,15 +274,23 @@ float cpl_tools_get_kth_float(float *, cpl_size, cpl_size) CPL_ATTR_NONNULL; int cpl_tools_get_kth_int(int *, cpl_size, cpl_size) CPL_ATTR_NONNULL; long cpl_tools_get_kth_long(long *, cpl_size, cpl_size) CPL_ATTR_NONNULL; -long long cpl_tools_get_kth_long_long(long long *, cpl_size, cpl_size) CPL_ATTR_NONNULL; -cpl_size cpl_tools_get_kth_cplsize(cpl_size *, cpl_size, cpl_size) CPL_ATTR_NONNULL; - -double cpl_tools_quickselection_double(double *, cpl_size, cpl_size) CPL_ATTR_NONNULL; -float cpl_tools_quickselection_float(float *, cpl_size, cpl_size) CPL_ATTR_NONNULL; +long long +cpl_tools_get_kth_long_long(long long *, cpl_size, cpl_size) CPL_ATTR_NONNULL; +cpl_size +cpl_tools_get_kth_cplsize(cpl_size *, cpl_size, cpl_size) CPL_ATTR_NONNULL; + +double +cpl_tools_quickselection_double(double *, cpl_size, cpl_size) CPL_ATTR_NONNULL; +float +cpl_tools_quickselection_float(float *, cpl_size, cpl_size) CPL_ATTR_NONNULL; int cpl_tools_quickselection_int(int *, cpl_size, cpl_size) CPL_ATTR_NONNULL; long cpl_tools_quickselection_long(long *, cpl_size, cpl_size) CPL_ATTR_NONNULL; -long long cpl_tools_quickselection_long_long(long long *, cpl_size, cpl_size) CPL_ATTR_NONNULL; -cpl_size cpl_tools_quickselection_cplsize(cpl_size *, cpl_size, cpl_size) CPL_ATTR_NONNULL; +long long cpl_tools_quickselection_long_long(long long *, + cpl_size, + cpl_size) CPL_ATTR_NONNULL; +cpl_size cpl_tools_quickselection_cplsize(cpl_size *, + cpl_size, + cpl_size) CPL_ATTR_NONNULL; double cpl_tools_get_mean_double(const double *, cpl_size); double cpl_tools_get_mean_float(const float *, cpl_size); @@ -248,76 +303,128 @@ double cpl_tools_get_variancesum_float(const float *, cpl_size, double *); double cpl_tools_get_variancesum_int(const int *, cpl_size, double *); double cpl_tools_get_variancesum_long(const long *, cpl_size, double *); -double cpl_tools_get_variancesum_long_long(const long long *, cpl_size, double *); +double +cpl_tools_get_variancesum_long_long(const long long *, cpl_size, double *); double cpl_tools_get_variancesum_cplsize(const cpl_size *, cpl_size, double *); -double cpl_tools_get_variance_double(const double *, cpl_size, +double cpl_tools_get_variance_double(const double *, + cpl_size, double *) CPL_ATTR_NONNULL; -double cpl_tools_get_variance_float(const float *, cpl_size, +double cpl_tools_get_variance_float(const float *, + cpl_size, double *) CPL_ATTR_NONNULL; -double cpl_tools_get_variance_int(const int *, cpl_size, - double *) CPL_ATTR_NONNULL; -double cpl_tools_get_variance_long(const long *, cpl_size, - double *) CPL_ATTR_NONNULL; -double cpl_tools_get_variance_long_long(const long long *, cpl_size, +double +cpl_tools_get_variance_int(const int *, cpl_size, double *) CPL_ATTR_NONNULL; +double +cpl_tools_get_variance_long(const long *, cpl_size, double *) CPL_ATTR_NONNULL; +double cpl_tools_get_variance_long_long(const long long *, + cpl_size, double *) CPL_ATTR_NONNULL; -double cpl_tools_get_variance_cplsize(const cpl_size *, cpl_size, - double *) CPL_ATTR_NONNULL; +double cpl_tools_get_variance_cplsize(const cpl_size *, + cpl_size, + double *) CPL_ATTR_NONNULL; double cpl_tools_get_median_double(double *, cpl_size) CPL_ATTR_NONNULL; float cpl_tools_get_median_float(float *, cpl_size) CPL_ATTR_NONNULL; int cpl_tools_get_median_int(int *, cpl_size) CPL_ATTR_NONNULL; long cpl_tools_get_median_long(long *, cpl_size) CPL_ATTR_NONNULL; -long long cpl_tools_get_median_long_long(long long *, cpl_size) CPL_ATTR_NONNULL; +long long +cpl_tools_get_median_long_long(long long *, cpl_size) CPL_ATTR_NONNULL; cpl_size cpl_tools_get_median_cplsize(cpl_size *, cpl_size) CPL_ATTR_NONNULL; -cpl_error_code cpl_tools_copy_window(void *, const void *, size_t, - cpl_size, cpl_size, cpl_size, cpl_size, - cpl_size, cpl_size) CPL_ATTR_NONNULL; - -cpl_error_code cpl_tools_shift_window(void *, size_t, cpl_size, cpl_size, int, - cpl_size, cpl_size) CPL_ATTR_NONNULL; +cpl_error_code cpl_tools_copy_window(void *, + const void *, + size_t, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_size) CPL_ATTR_NONNULL; + +cpl_error_code cpl_tools_shift_window(void *, + size_t, + cpl_size, + cpl_size, + int, + cpl_size, + cpl_size) CPL_ATTR_NONNULL; /* Sorting */ -cpl_error_code cpl_tools_sort_stable_pattern_cplsize(cpl_size const *, - cpl_size, int, int, - cpl_size *); -cpl_error_code cpl_tools_sort_stable_pattern_int(int const *, - cpl_size, int, int, - cpl_size *); +cpl_error_code cpl_tools_sort_stable_pattern_cplsize(cpl_size const *, + cpl_size, + int, + int, + cpl_size *); +cpl_error_code +cpl_tools_sort_stable_pattern_int(int const *, cpl_size, int, int, cpl_size *); cpl_error_code cpl_tools_sort_stable_pattern_long(long const *, - cpl_size, int, int, + cpl_size, + int, + int, cpl_size *); cpl_error_code cpl_tools_sort_stable_pattern_long_long(long long const *, - cpl_size, int, int, + cpl_size, + int, + int, cpl_size *); -cpl_error_code cpl_tools_sort_stable_pattern_float(float const *, - cpl_size, int, int, +cpl_error_code cpl_tools_sort_stable_pattern_float(float const *, + cpl_size, + int, + int, cpl_size *); -cpl_error_code cpl_tools_sort_stable_pattern_double(double const *, - cpl_size, int, int, +cpl_error_code cpl_tools_sort_stable_pattern_double(double const *, + cpl_size, + int, + int, cpl_size *); -cpl_error_code cpl_tools_sort_stable_pattern_string(char * const *, - cpl_size, int, int, +cpl_error_code cpl_tools_sort_stable_pattern_string(char *const *, + cpl_size, + int, + int, cpl_size *); -cpl_error_code cpl_tools_permute_cplsize(cpl_size *, cpl_size, cpl_size *, - cpl_size const *, - cpl_size *, cpl_size const *); -cpl_error_code cpl_tools_permute_int(cpl_size *, cpl_size, int *, int const *, - int *, int const *); -cpl_error_code cpl_tools_permute_long(cpl_size *, cpl_size, long *, long const *, - long *, long const *); -cpl_error_code cpl_tools_permute_long_long(cpl_size *, cpl_size, - long long *, long long const *, - long long *, long long const *); -cpl_error_code cpl_tools_permute_float(cpl_size *, cpl_size, float *, float const *, - float *, float const *); -cpl_error_code cpl_tools_permute_double(cpl_size *, cpl_size, double *, +cpl_error_code cpl_tools_permute_cplsize(cpl_size *, + cpl_size, + cpl_size *, + cpl_size const *, + cpl_size *, + cpl_size const *); +cpl_error_code cpl_tools_permute_int(cpl_size *, + cpl_size, + int *, + int const *, + int *, + int const *); +cpl_error_code cpl_tools_permute_long(cpl_size *, + cpl_size, + long *, + long const *, + long *, + long const *); +cpl_error_code cpl_tools_permute_long_long(cpl_size *, + cpl_size, + long long *, + long long const *, + long long *, + long long const *); +cpl_error_code cpl_tools_permute_float(cpl_size *, + cpl_size, + float *, + float const *, + float *, + float const *); +cpl_error_code cpl_tools_permute_double(cpl_size *, + cpl_size, + double *, double const *, - double *, double const *); -cpl_error_code cpl_tools_permute_string(cpl_size *, cpl_size, char **, - char * const *, - char **, char * const *); + double *, + double const *); +cpl_error_code cpl_tools_permute_string(cpl_size *, + cpl_size, + char **, + char *const *, + char **, + char *const *); cpl_error_code cpl_tools_sort_double(double *, cpl_size) CPL_ATTR_NONNULL; cpl_error_code cpl_tools_sort_float(float *, cpl_size) CPL_ATTR_NONNULL; @@ -344,23 +451,23 @@ void cpl_tools_flip_float(float *, size_t) CPL_ATTR_NONNULL CPL_INTERNAL; void cpl_tools_flip_int(int *, size_t) CPL_ATTR_NONNULL CPL_INTERNAL; -cpl_vector * cpl_vector_transform_mean(const cpl_vector *, double *) - CPL_ATTR_NONNULL CPL_ATTR_ALLOC; +cpl_vector *cpl_vector_transform_mean(const cpl_vector *, + double *) CPL_ATTR_NONNULL CPL_ATTR_ALLOC; void cpl_tools_add_flops_(cpl_flops); cpl_flops cpl_tools_get_flops(void) #ifdef CPL_ADD_FLOPS - CPL_ATTR_PURE + CPL_ATTR_PURE #else - CPL_ATTR_CONST + CPL_ATTR_CONST #endif - ; + ; /* Others */ cpl_size cpl_tools_is_power_of_2(cpl_size) CPL_ATTR_CONST; double cpl_tools_ipow(double, int) CPL_ATTR_CONST; -double * cpl_tools_fill_kernel_profile(cpl_kernel, int *); +double *cpl_tools_fill_kernel_profile(cpl_kernel, int *); int cpl_tools_get_bpp(cpl_type); @@ -369,5 +476,4 @@ CPL_END_DECLS -#endif - +#endif diff -Nru cpl-7.1.4+ds/cplcore/cpl_type.c cpl-7.2.2+ds/cplcore/cpl_type.c --- cpl-7.1.4+ds/cplcore/cpl_type.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_type.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -69,10 +69,9 @@ * @c CPL_TYPE_CHAR! */ -size_t +size_t cpl_type_get_sizeof(cpl_type type) { - size_t sz; @@ -141,7 +140,7 @@ break; case CPL_TYPE_POINTER: - sz = sizeof(void*); + sz = sizeof(void *); break; case CPL_TYPE_FLOAT_COMPLEX: @@ -158,7 +157,6 @@ } return sz; - } /** @@ -174,181 +172,178 @@ const char * cpl_type_get_name(cpl_type type) { - - const char * self = ""; + const char *self = ""; if ((type & CPL_TYPE_POINTER) || (type & CPL_TYPE_FLAG_ARRAY)) { - /* switch on type without POINTER and ARRAY bits */ switch (type & ~CPL_TYPE_POINTER & ~CPL_TYPE_FLAG_ARRAY) { - /* Here follows all "usable" types as arrays */ - - case CPL_TYPE_CHAR: - /* string: case CPL_TYPE_STRING | CPL_TYPE_FLAG_ARRAY: */ - self = "char array"; - break; - - case CPL_TYPE_UCHAR: - self = "unsigned char array"; - break; - - case CPL_TYPE_BOOL: - self = "boolean array"; - break; - - case CPL_TYPE_SHORT: - self = "short array"; - break; - - case CPL_TYPE_USHORT: - self = "unsigned short array"; - break; - - case CPL_TYPE_INT: - self = "int array"; - break; - - case CPL_TYPE_UINT: - self = "unsigned int array"; - break; - - case CPL_TYPE_LONG: - self = "long int array"; - break; - - case CPL_TYPE_ULONG: - self = "unsigned long int array"; - break; - - case CPL_TYPE_LONG_LONG: - self = "long long int array"; - break; - - case CPL_TYPE_SIZE: - self = "cpl size array"; - break; + /* Here follows all "usable" types as arrays */ - case CPL_TYPE_FLOAT: - self = "float array"; - break; - - case CPL_TYPE_DOUBLE: - self = "double array"; - break; - - case CPL_TYPE_FLOAT_COMPLEX: - self = "float complex array"; - break; - - case CPL_TYPE_DOUBLE_COMPLEX: - self = "double complex array"; - break; - - case CPL_TYPE_STRING: - /* char: case CPL_TYPE_STRING | CPL_TYPE_FLAG_ARRAY: */ - self = "string array"; - break; - - default: - (void)cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, - "array/pointer type=0x%x", (int)type); - break; + case CPL_TYPE_CHAR: + /* string: case CPL_TYPE_STRING | CPL_TYPE_FLAG_ARRAY: */ + self = "char array"; + break; + + case CPL_TYPE_UCHAR: + self = "unsigned char array"; + break; + + case CPL_TYPE_BOOL: + self = "boolean array"; + break; + + case CPL_TYPE_SHORT: + self = "short array"; + break; + + case CPL_TYPE_USHORT: + self = "unsigned short array"; + break; + + case CPL_TYPE_INT: + self = "int array"; + break; + + case CPL_TYPE_UINT: + self = "unsigned int array"; + break; + + case CPL_TYPE_LONG: + self = "long int array"; + break; + + case CPL_TYPE_ULONG: + self = "unsigned long int array"; + break; + + case CPL_TYPE_LONG_LONG: + self = "long long int array"; + break; + + case CPL_TYPE_SIZE: + self = "cpl size array"; + break; + + case CPL_TYPE_FLOAT: + self = "float array"; + break; + + case CPL_TYPE_DOUBLE: + self = "double array"; + break; + + case CPL_TYPE_FLOAT_COMPLEX: + self = "float complex array"; + break; + + case CPL_TYPE_DOUBLE_COMPLEX: + self = "double complex array"; + break; + + case CPL_TYPE_STRING: + /* char: case CPL_TYPE_STRING | CPL_TYPE_FLAG_ARRAY: */ + self = "string array"; + break; + + default: + (void)cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, + "array/pointer type=0x%x", + (int)type); + break; } - - } else { - + } + else { switch (type) { - /* FIXME: This is a valid value for the enum... */ - case CPL_TYPE_FLAG_ARRAY: - self = "array"; - break; - - /* FIXME: This is a valid value for the enum... */ - case CPL_TYPE_INVALID: - self = "invalid"; - break; - - case CPL_TYPE_CHAR: - self = "char"; - break; - - case CPL_TYPE_UCHAR: - self = "unsigned char"; - break; - - case CPL_TYPE_BOOL: - self = "boolean"; - break; - - case CPL_TYPE_SHORT: - self = "short"; - break; - - case CPL_TYPE_USHORT: - self = "unsigned short"; - break; - - case CPL_TYPE_INT: - self = "int"; - break; - - case CPL_TYPE_UINT: - self = "unsigned int"; - break; - - case CPL_TYPE_LONG: - self = "long int"; - break; - - case CPL_TYPE_ULONG: - self = "unsigned long int"; - break; - - case CPL_TYPE_LONG_LONG: - self = "long long int"; - break; - - case CPL_TYPE_SIZE: - self = "cpl size"; - break; - - case CPL_TYPE_FLOAT: - self = "float"; - break; - - case CPL_TYPE_DOUBLE: - self = "double"; - break; - - case CPL_TYPE_POINTER: - self = "pointer"; - break; - - case CPL_TYPE_FLOAT_COMPLEX: - self = "float complex"; - break; - - case CPL_TYPE_DOUBLE_COMPLEX: - self = "double complex"; - break; - - case CPL_TYPE_UNSPECIFIED: - self = "unspecified"; - break; - - case CPL_TYPE_STRING: - self = "string"; - break; - - default: - (void)cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, - "type=0x%x", (int)type); - break; + /* FIXME: This is a valid value for the enum... */ + case CPL_TYPE_FLAG_ARRAY: + self = "array"; + break; + + /* FIXME: This is a valid value for the enum... */ + case CPL_TYPE_INVALID: + self = "invalid"; + break; + + case CPL_TYPE_CHAR: + self = "char"; + break; + + case CPL_TYPE_UCHAR: + self = "unsigned char"; + break; + + case CPL_TYPE_BOOL: + self = "boolean"; + break; + + case CPL_TYPE_SHORT: + self = "short"; + break; + + case CPL_TYPE_USHORT: + self = "unsigned short"; + break; + + case CPL_TYPE_INT: + self = "int"; + break; + + case CPL_TYPE_UINT: + self = "unsigned int"; + break; + + case CPL_TYPE_LONG: + self = "long int"; + break; + + case CPL_TYPE_ULONG: + self = "unsigned long int"; + break; + + case CPL_TYPE_LONG_LONG: + self = "long long int"; + break; + + case CPL_TYPE_SIZE: + self = "cpl size"; + break; + + case CPL_TYPE_FLOAT: + self = "float"; + break; + + case CPL_TYPE_DOUBLE: + self = "double"; + break; + + case CPL_TYPE_POINTER: + self = "pointer"; + break; + + case CPL_TYPE_FLOAT_COMPLEX: + self = "float complex"; + break; + + case CPL_TYPE_DOUBLE_COMPLEX: + self = "double complex"; + break; + + case CPL_TYPE_UNSPECIFIED: + self = "unspecified"; + break; + + case CPL_TYPE_STRING: + self = "string"; + break; + + default: + (void)cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, + "type=0x%x", (int)type); + break; } } return self; - } /**@}*/ diff -Nru cpl-7.1.4+ds/cplcore/cpl_type.h cpl-7.2.2+ds/cplcore/cpl_type.h --- cpl-7.1.4+ds/cplcore/cpl_type.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_type.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -34,7 +34,8 @@ * The CPL type codes and flags. */ -enum _cpl_type_ { +enum _cpl_type_ +{ /* flags */ @@ -42,7 +43,7 @@ * Flag indicating whether a type is an array or a basic type. * @hideinitializer */ - CPL_TYPE_FLAG_ARRAY = 1 << 0, + CPL_TYPE_FLAG_ARRAY = 1 << 0, /* Padded for future extensions */ @@ -52,97 +53,97 @@ * Invalid or undetermined type. * @hideinitializer */ - CPL_TYPE_INVALID = 1 << 4, + CPL_TYPE_INVALID = 1 << 4, /** * Type code corresponding to type @c char. * @hideinitializer */ - CPL_TYPE_CHAR = 1 << 5, + CPL_TYPE_CHAR = 1 << 5, /** * Type code corresponding to type @c unsigned char. * @hideinitializer */ - CPL_TYPE_UCHAR = 1 << 6, + CPL_TYPE_UCHAR = 1 << 6, /** * Type code corresponding to the boolean type. * @hideinitializer */ - CPL_TYPE_BOOL = 1 << 7, + CPL_TYPE_BOOL = 1 << 7, /** * Type code corresponding to type @c short. * @hideinitializer */ - CPL_TYPE_SHORT = 1 << 8, + CPL_TYPE_SHORT = 1 << 8, /** * Type code corresponding to type @c unsigned short. * @hideinitializer */ - CPL_TYPE_USHORT = 1 << 9, + CPL_TYPE_USHORT = 1 << 9, /** * Type code corresponding to type @c int. * @hideinitializer */ - CPL_TYPE_INT = 1 << 10, + CPL_TYPE_INT = 1 << 10, /** * Type code corresponding to type @c unsigned int. * @hideinitializer */ - CPL_TYPE_UINT = 1 << 11, + CPL_TYPE_UINT = 1 << 11, /** * Type code corresponding to type @c long. * @hideinitializer */ - CPL_TYPE_LONG = 1 << 12, + CPL_TYPE_LONG = 1 << 12, /** * Type code corresponding to type @c unsigned long. * @hideinitializer */ - CPL_TYPE_ULONG = 1 << 13, + CPL_TYPE_ULONG = 1 << 13, /** * Type code corresponding to type @c long @c long. * @hideinitializer */ - CPL_TYPE_LONG_LONG = 1 << 14, + CPL_TYPE_LONG_LONG = 1 << 14, /** * Type code corresponding to type @c cpl_size * @hideinitializer */ - CPL_TYPE_SIZE = 1 << 15, + CPL_TYPE_SIZE = 1 << 15, /** * Type code corresponding to type @c float. * @hideinitializer */ - CPL_TYPE_FLOAT = 1 << 16, + CPL_TYPE_FLOAT = 1 << 16, /** * Type code corresponding to type @c double. * @hideinitializer */ - CPL_TYPE_DOUBLE = 1 << 17, + CPL_TYPE_DOUBLE = 1 << 17, /** * Type code corresponding to a pointer type. * @hideinitializer */ - CPL_TYPE_POINTER = 1 << 18, + CPL_TYPE_POINTER = 1 << 18, /** * Type code corresponding to a complex type. * @hideinitializer */ - CPL_TYPE_COMPLEX = 1 << 19, + CPL_TYPE_COMPLEX = 1 << 19, /** * Type code to be used for inheritance of original FITS type. @@ -154,13 +155,13 @@ * Type code corresponding to type @c cpl_bitmask * @hideinitializer */ - CPL_TYPE_BITMASK = 1 << 21, + CPL_TYPE_BITMASK = 1 << 21, /** * Type code corresponding to a character array. * @hideinitializer */ - CPL_TYPE_STRING = (CPL_TYPE_CHAR | CPL_TYPE_FLAG_ARRAY), + CPL_TYPE_STRING = (CPL_TYPE_CHAR | CPL_TYPE_FLAG_ARRAY), /** * Type code corresponding to type @c float complex. @@ -186,7 +187,8 @@ typedef enum _cpl_type_ cpl_type; -enum _cpl_boolean_ { +enum _cpl_boolean_ +{ CPL_FALSE = 0, CPL_TRUE = !CPL_FALSE }; @@ -282,7 +284,7 @@ size_t cpl_type_get_sizeof(cpl_type type) CPL_ATTR_CONST; -const char * cpl_type_get_name(cpl_type type); +const char *cpl_type_get_name(cpl_type type); CPL_END_DECLS diff -Nru cpl-7.1.4+ds/cplcore/cpl_type_impl.h cpl-7.2.2+ds/cplcore/cpl_type_impl.h --- cpl-7.1.4+ds/cplcore/cpl_type_impl.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_type_impl.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 diff -Nru cpl-7.1.4+ds/cplcore/cpl_vector.c cpl-7.2.2+ds/cplcore/cpl_vector.c --- cpl-7.1.4+ds/cplcore/cpl_vector.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_vector.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -73,9 +73,10 @@ Type definition -----------------------------------------------------------------------------*/ -struct _cpl_vector_ { - cpl_size size; - double * data; +struct _cpl_vector_ +{ + cpl_size size; + double *data; }; @@ -83,31 +84,32 @@ Private function prototypes -----------------------------------------------------------------------------*/ -static cpl_vector * cpl_vector_gen_lowpass_kernel(cpl_lowpass, - cpl_size) CPL_ATTR_ALLOC; +static cpl_vector * + cpl_vector_gen_lowpass_kernel(cpl_lowpass, cpl_size) CPL_ATTR_ALLOC; static double cpl_tools_sinc(double) CPL_ATTR_CONST; static cpl_error_code cpl_vector_fill_tanh_kernel(cpl_vector *, double); -static void cpl_vector_fill_alpha_kernel(cpl_vector *, double, - double) CPL_ATTR_NONNULL; +static void +cpl_vector_fill_alpha_kernel(cpl_vector *, double, double) CPL_ATTR_NONNULL; static void cpl_vector_reverse_tanh_kernel(double *, cpl_size) CPL_ATTR_NONNULL; -static int cpl_fit_gaussian_1d_compare(const void *left, const void *right) - CPL_ATTR_PURE CPL_ATTR_NONNULL; -static int gauss(const double x[], const double a[], - double *result) CPL_ATTR_NONNULL; -static int gauss_derivative(const double x[], const double a[], +static int +cpl_fit_gaussian_1d_compare(const void *left, + const void *right) CPL_ATTR_PURE CPL_ATTR_NONNULL; +static int +gauss(const double x[], const double a[], double *result) CPL_ATTR_NONNULL; +static int gauss_derivative(const double x[], + const double a[], double result[]) CPL_ATTR_NONNULL; -inline -static double cpl_erf_antideriv(double, double) CPL_ATTR_CONST; +inline static double cpl_erf_antideriv(double, double) CPL_ATTR_CONST; -static cpl_error_code cpl_vector_fill_lss_profile_symmetric(cpl_vector *, - double, - double); +static cpl_error_code +cpl_vector_fill_lss_profile_symmetric(cpl_vector *, double, double); /*----------------------------------------------------------------------------- Private types -----------------------------------------------------------------------------*/ -typedef struct { +typedef struct +{ double x; double y; } cpl_vector_fit_gaussian_input; @@ -131,18 +133,20 @@ - CPL_ERROR_ILLEGAL_INPUT if n is negative or zero */ /*----------------------------------------------------------------------------*/ -cpl_vector * cpl_vector_new(cpl_size n) +cpl_vector * +cpl_vector_new(cpl_size n) { - cpl_vector * self = NULL; + cpl_vector *self = NULL; if (n <= 0) { (void)cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, "n=%" CPL_SIZE_FORMAT " < 1", n); - } else { + } + else { /* Allocate memory */ - self = (cpl_vector*)cpl_malloc(sizeof(cpl_vector)); + self = (cpl_vector *)cpl_malloc(sizeof(cpl_vector)); self->size = n; - self->data = (double*)cpl_malloc((size_t)n * sizeof(double)); + self->data = (double *)cpl_malloc((size_t)n * sizeof(double)); } return self; @@ -161,16 +165,19 @@ - CPL_ERROR_ILLEGAL_INPUT if n is negative or zero */ /*----------------------------------------------------------------------------*/ -cpl_vector * cpl_vector_wrap(cpl_size n, double * data) +cpl_vector * +cpl_vector_wrap(cpl_size n, double *data) { - cpl_vector * self = NULL; + cpl_vector *self = NULL; if (n <= 0) { (void)cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, "n=%" CPL_SIZE_FORMAT " < 1", n); - } else if (data == NULL) { + } + else if (data == NULL) { (void)cpl_error_set_message_(CPL_ERROR_NULL_INPUT, "data"); - } else { + } + else { self = cpl_malloc(sizeof(cpl_vector)); self->size = n; self->data = data; @@ -195,18 +202,22 @@ - CPL_ERROR_ILLEGAL_INPUT if n is negative or zero */ /*----------------------------------------------------------------------------*/ -double * cpl_vector_rewrap(cpl_vector * self, cpl_size n, double * data) +double * +cpl_vector_rewrap(cpl_vector *self, cpl_size n, double *data) { - double * old = NULL; + double *old = NULL; if (self == NULL) { (void)cpl_error_set_message_(CPL_ERROR_NULL_INPUT, "self"); - } else if (n <= 0) { + } + else if (n <= 0) { (void)cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, "n=%" CPL_SIZE_FORMAT " < 1", n); - } else if (data == NULL) { + } + else if (data == NULL) { (void)cpl_error_set_message_(CPL_ERROR_NULL_INPUT, "data"); - } else { + } + else { old = self->data; /* Return old buffer */ self->size = n; self->data = data; @@ -225,10 +236,13 @@ */ /*----------------------------------------------------------------------------*/ -void cpl_vector_delete(cpl_vector * v) +void +cpl_vector_delete(cpl_vector *v) { - if (v == NULL) return; - if (v->data != NULL) cpl_free(v->data); + if (v == NULL) + return; + if (v->data != NULL) + cpl_free(v->data); cpl_free(v); return; } @@ -245,13 +259,15 @@ */ /*----------------------------------------------------------------------------*/ -void * cpl_vector_unwrap(cpl_vector * v) +void * +cpl_vector_unwrap(cpl_vector *v) { - void * data; + void *data; - if (v == NULL) return NULL; + if (v == NULL) + return NULL; - data = (void *) v->data; + data = (void *)v->data; cpl_free(v); return data; @@ -278,10 +294,11 @@ - CPL_ERROR_BAD_FILE_FORMAT if the file contains no valid lines */ /*----------------------------------------------------------------------------*/ -cpl_vector * cpl_vector_read(const char * filename) +cpl_vector * +cpl_vector_read(const char *filename) { - FILE * in; - cpl_vector * v = NULL; + FILE *in; + cpl_vector *v = NULL; cpl_ensure(filename != NULL, CPL_ERROR_NULL_INPUT, NULL); @@ -290,12 +307,11 @@ in = fopen(filename, "r"); if (in != NULL) { - - cpl_size np = 0; - cpl_size size = 1000; /* Default size */ - char line[1024]; - double x; - int error; + cpl_size np = 0; + cpl_size size = 1000; /* Default size */ + char line[1024]; + double x; + int error; /* Create and fill the vector */ v = cpl_vector_new(size); @@ -306,7 +322,8 @@ - increase vector size if necessary, - insert element at end and - increment size counter */ - if (np == size) cpl_vector_set_size(v, size *= 2); + if (np == size) + cpl_vector_set_size(v, size *= 2); cpl_vector_set(v, np++, x); } } @@ -319,20 +336,23 @@ cpl_vector_delete(v); v = NULL; (void)cpl_error_set_(CPL_ERROR_FILE_IO); - } else if (np == 0) { + } + else if (np == 0) { cpl_vector_delete(v); v = NULL; (void)cpl_error_set_(CPL_ERROR_BAD_FILE_FORMAT); - } else if (cpl_vector_set_size(v, np)) { + } + else if (cpl_vector_set_size(v, np)) { cpl_vector_delete(v); v = NULL; (void)cpl_error_set_where_(); } - - } else if (errno != 0) { + } + else if (errno != 0) { (void)cpl_error_set_message_(CPL_ERROR_FILE_IO, "File=%s. Error: %s", filename, strerror(errno)); - } else { + } + else { (void)cpl_error_set_message_(CPL_ERROR_FILE_IO, "File=%s", filename); } @@ -360,14 +380,14 @@ */ /*----------------------------------------------------------------------------*/ -void cpl_vector_dump( - const cpl_vector * v, - FILE * stream) +void +cpl_vector_dump(const cpl_vector *v, FILE *stream) { cpl_size i; - if (stream == NULL) stream = stdout; + if (stream == NULL) + stream = stdout; fprintf(stream, "#----- vector -----\n"); @@ -377,8 +397,8 @@ } fprintf(stream, "#Index\t\tX\n"); - for (i = 0; isize; i++) - fprintf(stream, "%" CPL_SIZE_FORMAT "\t\t%g\n", i+1, v->data[i]); + for (i = 0; i < v->size; i++) + fprintf(stream, "%" CPL_SIZE_FORMAT "\t\t%g\n", i + 1, v->data[i]); fprintf(stream, "#------------------\n"); @@ -407,19 +427,20 @@ - CPL_ERROR_UNSUPPORTOED_MODE if the file is too large to be read */ /*----------------------------------------------------------------------------*/ -cpl_vector * cpl_vector_load(const char * filename, cpl_size xtnum) +cpl_vector * +cpl_vector_load(const char *filename, cpl_size xtnum) { - const int ixtnum = (int)xtnum; - fitsfile * fptr; - int error = 0; - void * data; - CPL_FITSIO_TYPE nx; - const CPL_FITSIO_TYPE fpixel[1] = {1}; - int naxis; + const int ixtnum = (int)xtnum; + fitsfile *fptr; + int error = 0; + void *data; + CPL_FITSIO_TYPE nx; + const CPL_FITSIO_TYPE fpixel[1] = { 1 }; + int naxis; /* Test entries */ - cpl_ensure(filename != NULL, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(xtnum >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(filename != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(xtnum >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL); cpl_ensure((cpl_size)ixtnum == xtnum, CPL_ERROR_ILLEGAL_INPUT, NULL); /* Open the file */ @@ -454,7 +475,8 @@ cpl_io_fits_close_file(fptr, &error); (void)cpl_error_set_message_(CPL_ERROR_BAD_FILE_FORMAT, "filename='%s', xtnum=%" CPL_SIZE_FORMAT - ", naxis=%d", filename, xtnum, naxis); + ", naxis=%d", + filename, xtnum, naxis); return NULL; } if (CPL_FITSIO_GET_SIZE(fptr, 1, &nx, &error)) { @@ -467,18 +489,22 @@ } if (nx < 1) { cpl_io_fits_close_file(fptr, &error); - (void)cpl_error_set_message_(CPL_ERROR_BAD_FILE_FORMAT, "file" - "name='%s', xtnum=%" CPL_SIZE_FORMAT ", " - "nx=%lld", filename, xtnum, (long long)nx); + (void)cpl_error_set_message_(CPL_ERROR_BAD_FILE_FORMAT, + "file" + "name='%s', xtnum=%" CPL_SIZE_FORMAT ", " + "nx=%lld", + filename, xtnum, (long long)nx); return NULL; } /* FIXME: Change 1st (unlikely) if-clause to ifdef */ if (sizeof(nx) > sizeof(cpl_size) && nx != (cpl_size)nx) { cpl_io_fits_close_file(fptr, &error); - (void)cpl_error_set_message_(CPL_ERROR_UNSUPPORTED_MODE, "file" + (void)cpl_error_set_message_(CPL_ERROR_UNSUPPORTED_MODE, + "file" "name='%s', xtnum=%" CPL_SIZE_FORMAT ", " - "nx=%lld", filename, xtnum, (long long)nx); + "nx=%lld", + filename, xtnum, (long long)nx); return NULL; } @@ -491,9 +517,11 @@ int error2 = 0; cpl_io_fits_close_file(fptr, &error2); cpl_free(data); - (void)cpl_error_set_fits(CPL_ERROR_FILE_IO, error, CPL_FITSIO_READ_PIX_E, + (void)cpl_error_set_fits(CPL_ERROR_FILE_IO, error, + CPL_FITSIO_READ_PIX_E, "filename='%s', xtnum=%" CPL_SIZE_FORMAT - ", nx=%lld", filename, xtnum, (long long)nx); + ", nx=%lld", + filename, xtnum, (long long)nx); return NULL; } @@ -501,11 +529,12 @@ cpl_free(data); (void)cpl_error_set_fits(CPL_ERROR_FILE_IO, error, fits_close_file, "filename='%s', xtnum=%" CPL_SIZE_FORMAT - ", nx=%lld", filename, xtnum, (long long)nx); + ", nx=%lld", + filename, xtnum, (long long)nx); return NULL; } - return cpl_vector_wrap(nx, (double*)data); + return cpl_vector_wrap(nx, (double *)data); } /*----------------------------------------------------------------------------*/ @@ -514,7 +543,7 @@ @param self Vector to write to disk or NULL @param filename Name of the file to write @param type The type used to represent the data in the file - @param pl Property list for the output header or NULL + @param plist Property list for the output header or NULL @param mode The desired output options (combined with bitwise or) @return CPL_ERROR_NONE or the relevant #_cpl_error_code_ on error @@ -550,26 +579,25 @@ - CPL_ERROR_UNSUPPORTOED_MODE if the file is too large to be saved */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_vector_save(const cpl_vector * self, - const char * filename, - cpl_type type, - const cpl_propertylist * pl, - unsigned mode) +cpl_error_code +cpl_vector_save(const cpl_vector *self, + const char *filename, + cpl_type type, + const cpl_propertylist *plist, + unsigned mode) { - if (self == NULL) { - return cpl_propertylist_save(pl, filename, mode) - ? cpl_error_set_where_() : CPL_ERROR_NONE; - } else { - fitsfile * fptr; - int error = 0; - const char * badkeys = mode & CPL_IO_EXTEND - ? CPL_FITS_BADKEYS_EXT "|" CPL_FITS_COMPRKEYS - : CPL_FITS_BADKEYS_PRIM "|" CPL_FITS_COMPRKEYS; + return cpl_propertylist_save(plist, filename, mode) + ? cpl_error_set_where_() + : CPL_ERROR_NONE; + } + else { + fitsfile *fptr; + int error = 0; /* Create the vector in the primary unit */ - const CPL_FITSIO_TYPE naxes[1] = {self->size}; - const int bpp = cpl_tools_get_bpp(type); + const CPL_FITSIO_TYPE naxes[1] = { self->size }; + const int bpp = cpl_tools_get_bpp(type); cpl_ensure_code(filename != NULL, CPL_ERROR_NULL_INPUT); @@ -580,27 +608,30 @@ CPL_ERROR_ILLEGAL_INPUT); cpl_ensure_code(sizeof(CPL_FITSIO_TYPE) >= sizeof(cpl_size) || - (cpl_size)naxes[0] == self->size, + (cpl_size)naxes[0] == self->size, CPL_ERROR_UNSUPPORTED_MODE); if (mode & CPL_IO_EXTEND) { /* Open the file */ if (cpl_io_fits_open_diskfile(&fptr, filename, READWRITE, &error)) { return cpl_error_set_fits(CPL_ERROR_FILE_IO, error, - fits_open_diskfile, "filename='%s', " - "type=%d, mode=%u", filename, type, - mode); + fits_open_diskfile, + "filename='%s', " + "type=%d, mode=%u", + filename, type, mode); } - } else { + } + else { /* Create the file */ - char * sval = cpl_sprintf("!%s", filename); + char *sval = cpl_sprintf("!%s", filename); cpl_io_fits_create_file(&fptr, sval, &error); cpl_free(sval); if (error) { return cpl_error_set_fits(CPL_ERROR_FILE_IO, error, - fits_create_file, "filename='%s', " - "type=%d, mode=%u", filename, type, - mode); + fits_create_file, + "filename='%s', " + "type=%d, mode=%u", + filename, type, mode); } } @@ -608,45 +639,53 @@ int error2 = 0; cpl_io_fits_close_file(fptr, &error2); return cpl_error_set_fits(CPL_ERROR_FILE_IO, error, - CPL_FITSIO_CREATE_IMG_E, "filename='%s', " - "type=%d, mode=%u", filename, type, mode); + CPL_FITSIO_CREATE_IMG_E, + "filename='%s', " + "type=%d, mode=%u", + filename, type, mode); } /* Add DATE */ if ((mode & CPL_IO_CREATE) && fits_write_date(fptr, &error)) { int error2 = 0; cpl_io_fits_close_file(fptr, &error2); - return cpl_error_set_fits(CPL_ERROR_FILE_IO, error, - fits_write_date, "filename='%s', " - "type=%d, mode=%u", filename, type, mode); + return cpl_error_set_fits(CPL_ERROR_FILE_IO, error, fits_write_date, + "filename='%s', " + "type=%d, mode=%u", + filename, type, mode); } /* Add the property list */ - if (cpl_fits_add_properties(fptr, pl, badkeys)) { + if (cpl_fits_add_properties(fptr, plist, mode, CPL_FALSE)) { return cpl_io_fits_close_file(fptr, &error) - ? cpl_error_set_fits(CPL_ERROR_FILE_IO, error, - fits_close_file, "filename='%s', " - "type=%d, mode=%u", filename, type, mode) + ? cpl_error_set_fits(CPL_ERROR_FILE_IO, error, + fits_close_file, + "filename='%s', " + "type=%d, mode=%u", + filename, type, mode) - : cpl_error_set_where_(); + : cpl_error_set_where_(); } if (fits_write_img(fptr, TDOUBLE, 1, (LONGLONG)self->size, - (void*)self->data, &error)) { + (void *)self->data, &error)) { int error2 = 0; cpl_io_fits_close_file(fptr, &error2); - return cpl_error_set_fits(CPL_ERROR_FILE_IO, error, - fits_write_img, "filename='%s', " - "type=%d, mode=%u", filename, type, mode); + return cpl_error_set_fits(CPL_ERROR_FILE_IO, error, fits_write_img, + "filename='%s', " + "type=%d, mode=%u", + filename, type, mode); } /* Close (and write to disk) */ return cpl_io_fits_close_file(fptr, &error) - ? cpl_error_set_fits(CPL_ERROR_FILE_IO, error, - fits_close_file, "filename='%s', " - "type=%d, mode=%u", filename, type, mode) - : CPL_ERROR_NONE; + ? cpl_error_set_fits(CPL_ERROR_FILE_IO, error, + fits_close_file, + "filename='%s', " + "type=%d, mode=%u", + filename, type, mode) + : CPL_ERROR_NONE; } } @@ -662,12 +701,13 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_vector * cpl_vector_duplicate(const cpl_vector * v) +cpl_vector * +cpl_vector_duplicate(const cpl_vector *v) { - cpl_vector * out; + cpl_vector *out; /* Test inputs */ - cpl_ensure(v != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(v != NULL, CPL_ERROR_NULL_INPUT, NULL); /* Create a new cpl_vector */ out = cpl_vector_new(v->size); @@ -690,12 +730,10 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_vector_copy( - cpl_vector * destination, - const cpl_vector * source) +cpl_error_code +cpl_vector_copy(cpl_vector *destination, const cpl_vector *source) { - - cpl_ensure_code(source != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(source != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(!cpl_vector_set_size(destination, source->size), cpl_error_get_code()); @@ -715,10 +753,11 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_vector_get_size(const cpl_vector * in) +cpl_size +cpl_vector_get_size(const cpl_vector *in) { /* Test entries */ - cpl_ensure(in!=NULL, CPL_ERROR_NULL_INPUT, -1); + cpl_ensure(in != NULL, CPL_ERROR_NULL_INPUT, -1); return cpl_vector_get_size_(in); } @@ -733,7 +772,8 @@ */ /*----------------------------------------------------------------------------*/ -inline cpl_size cpl_vector_get_size_(const cpl_vector * self) +inline cpl_size +cpl_vector_get_size_(const cpl_vector *self) { return self->size; } @@ -760,22 +800,21 @@ - CPL_ERROR_ILLEGAL_INPUT if newsize is negative or zero */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_vector_set_size(cpl_vector * in, cpl_size newsize) +cpl_error_code +cpl_vector_set_size(cpl_vector *in, cpl_size newsize) { - - cpl_ensure_code(in != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(in != NULL, CPL_ERROR_NULL_INPUT); if (in->size != newsize) { cpl_ensure_code(newsize > 0, CPL_ERROR_ILLEGAL_INPUT); - in->data = (double*)cpl_realloc(in->data, - (size_t)newsize * sizeof(double)); + in->data = + (double *)cpl_realloc(in->data, (size_t)newsize * sizeof(double)); in->size = newsize; } return CPL_ERROR_NONE; - } /*----------------------------------------------------------------------------*/ @@ -796,7 +835,8 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -double * cpl_vector_get_data(cpl_vector * in) +double * +cpl_vector_get_data(cpl_vector *in) { /* Test entries */ cpl_ensure(in != NULL, CPL_ERROR_NULL_INPUT, NULL); @@ -815,9 +855,10 @@ */ /*----------------------------------------------------------------------------*/ -inline double * cpl_vector_get_data_(cpl_vector * self) +inline double * +cpl_vector_get_data_(cpl_vector *self) { - assert( self->data != NULL); + assert(self->data != NULL); return self->data; } @@ -831,7 +872,8 @@ */ /*----------------------------------------------------------------------------*/ -const double * cpl_vector_get_data_const(const cpl_vector * in) +const double * +cpl_vector_get_data_const(const cpl_vector *in) { /* Test entries */ cpl_ensure(in != NULL, CPL_ERROR_NULL_INPUT, NULL); @@ -850,9 +892,10 @@ */ /*----------------------------------------------------------------------------*/ -inline const double * cpl_vector_get_data_const_(const cpl_vector * self) +inline const double * +cpl_vector_get_data_const_(const cpl_vector *self) { - assert( self->data != NULL); + assert(self->data != NULL); return self->data; } @@ -873,12 +916,12 @@ - CPL_ERROR_ACCESS_OUT_OF_RANGE if idx is out of the vector bounds */ /*----------------------------------------------------------------------------*/ -double cpl_vector_get(const cpl_vector * in, cpl_size idx) +double +cpl_vector_get(const cpl_vector *in, cpl_size idx) { - /* Test entries */ - cpl_ensure(in, CPL_ERROR_NULL_INPUT, -1.0); - cpl_ensure(idx >= 0, CPL_ERROR_ILLEGAL_INPUT, -2.0); + cpl_ensure(in, CPL_ERROR_NULL_INPUT, -1.0); + cpl_ensure(idx >= 0, CPL_ERROR_ILLEGAL_INPUT, -2.0); cpl_ensure(idx < in->size, CPL_ERROR_ACCESS_OUT_OF_RANGE, -3.0); return cpl_vector_get_(in, idx); @@ -895,9 +938,10 @@ @note No error checking in this internal function */ /*----------------------------------------------------------------------------*/ -inline double cpl_vector_get_(const cpl_vector * in, cpl_size idx) +inline double +cpl_vector_get_(const cpl_vector *in, cpl_size idx) { - assert( in->data ); + assert(in->data); return in->data[idx]; } @@ -916,15 +960,12 @@ - CPL_ERROR_ACCESS_OUT_OF_RANGE if idx is out of the vector bounds */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_vector_set( - cpl_vector * in, - cpl_size idx, - double value) +cpl_error_code +cpl_vector_set(cpl_vector *in, cpl_size idx, double value) { - /* Test entries */ - cpl_ensure_code(in != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(idx >= 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(in != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(idx >= 0, CPL_ERROR_ILLEGAL_INPUT); cpl_ensure_code(idx < in->size, CPL_ERROR_ACCESS_OUT_OF_RANGE); /* Assign the value */ @@ -945,11 +986,10 @@ @note No error checking in this internal function */ /*----------------------------------------------------------------------------*/ -inline void cpl_vector_set_(cpl_vector * in, - cpl_size idx, - double value) +inline void +cpl_vector_set_(cpl_vector *in, cpl_size idx, double value) { - assert( in->data ); + assert(in->data); /* Assign the value */ in->data[idx] = value; @@ -972,19 +1012,19 @@ - CPL_ERROR_INCOMPATIBLE_INPUT if v1 and v2 have different sizes */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_vector_add( - cpl_vector * v1, - const cpl_vector * v2) +cpl_error_code +cpl_vector_add(cpl_vector *v1, const cpl_vector *v2) { - cpl_size i; + cpl_size i; /* Test inputs */ - cpl_ensure_code(v1 != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(v2 != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(v1 != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(v2 != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(v1->size == v2->size, CPL_ERROR_INCOMPATIBLE_INPUT); /* Add v2 to v1 */ - for (i = 0; i < v1->size; i++) v1->data[i] += v2->data[i]; + for (i = 0; i < v1->size; i++) + v1->data[i] += v2->data[i]; cpl_tools_add_flops(v1->size); @@ -1000,19 +1040,19 @@ @see cpl_vector_add() */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_vector_subtract( - cpl_vector * v1, - const cpl_vector * v2) +cpl_error_code +cpl_vector_subtract(cpl_vector *v1, const cpl_vector *v2) { - cpl_size i; + cpl_size i; /* Test inputs */ - cpl_ensure_code(v1 != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(v2 != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(v1 != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(v2 != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(v1->size == v2->size, CPL_ERROR_INCOMPATIBLE_INPUT); /* subtract v2 from v1 */ - for (i = 0; i < v1->size; i++) v1->data[i] -= v2->data[i]; + for (i = 0; i < v1->size; i++) + v1->data[i] -= v2->data[i]; cpl_tools_add_flops(v1->size); @@ -1028,19 +1068,19 @@ @see cpl_vector_add() */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_vector_multiply( - cpl_vector * v1, - const cpl_vector * v2) +cpl_error_code +cpl_vector_multiply(cpl_vector *v1, const cpl_vector *v2) { - cpl_size i; + cpl_size i; /* Test inputs */ - cpl_ensure_code(v1 != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(v2 != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(v1 != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(v2 != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(v1->size == v2->size, CPL_ERROR_INCOMPATIBLE_INPUT); /* Multiply the cpl_vector fields */ - for (i = 0; i < v1->size; i++) v1->data[i] *= v2->data[i]; + for (i = 0; i < v1->size; i++) + v1->data[i] *= v2->data[i]; cpl_tools_add_flops(v1->size); @@ -1064,22 +1104,22 @@ - CPL_ERROR_DIVISION_BY_ZERO if a division by 0 would occur */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_vector_divide( - cpl_vector * v1, - const cpl_vector * v2) +cpl_error_code +cpl_vector_divide(cpl_vector *v1, const cpl_vector *v2) { - cpl_size i; + cpl_size i; /* Test inputs */ - cpl_ensure_code(v1 != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(v2 != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(v1 != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(v2 != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(v1->size == v2->size, CPL_ERROR_INCOMPATIBLE_INPUT); for (i = 0; i < v2->size; i++) cpl_ensure_code(v2->data[i] != 0, CPL_ERROR_DIVISION_BY_ZERO); /* Divide the cpl_vector fields */ - for (i = 0; i < v1->size; i++) v1->data[i] /= v2->data[i]; + for (i = 0; i < v1->size; i++) + v1->data[i] /= v2->data[i]; cpl_tools_add_flops(v1->size); @@ -1113,11 +1153,10 @@ unavailable */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_vector_cycle(cpl_vector * self, - const cpl_vector * other, - double shift) +cpl_error_code +cpl_vector_cycle(cpl_vector *self, const cpl_vector *other, double shift) { - const cpl_size n = cpl_vector_get_size(self); + const cpl_size n = cpl_vector_get_size(self); const cpl_size nshift = (cpl_size)shift % (cpl_size)n; const cpl_size ishift = nshift < 0 ? n + nshift : nshift; @@ -1127,28 +1166,32 @@ if (other != NULL && cpl_vector_get_size(other) != n) { return cpl_error_set_(CPL_ERROR_INCOMPATIBLE_INPUT); - } else if (shift != floor(shift)) { - cpl_image* imgself = cpl_image_wrap_double(n, 1, - cpl_vector_get_data(self)); - cpl_image* imgother; + } + else if (shift != floor(shift)) { + cpl_image *imgself = + cpl_image_wrap_double(n, 1, cpl_vector_get_data(self)); + cpl_image *imgother; cpl_error_code code; CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); - imgother = other ? cpl_image_wrap_double(n, 1, cpl_vector_get_data - ((cpl_vector*)other)) - : imgself; + imgother = other ? cpl_image_wrap_double(n, 1, + cpl_vector_get_data( + (cpl_vector *)other)) + : imgself; CPL_DIAG_PRAGMA_POP; code = cpl_fft_image_cycle(imgself, imgother, shift, 0.0); assert(!code); - if (imgother != imgself) (void)cpl_image_unwrap(imgother); + if (imgother != imgself) + (void)cpl_image_unwrap(imgother); (void)cpl_image_unwrap(imgself); - } else if (other == NULL || self == other) { + } + else if (other == NULL || self == other) { /* Perform integer in-place shift of self */ const cpl_size irem = n - ishift; - double* copy = NULL; + double *copy = NULL; assert(irem > 0); @@ -1156,23 +1199,23 @@ is just there to reduce the lengths of the memcpy() calls */ if (ishift > irem) { /* A large shift, copy the first (smaller) part of the buffer */ - copy = (double*)cpl_malloc((size_t)irem * sizeof(*copy)); + copy = (double *)cpl_malloc((size_t)irem * sizeof(*copy)); memcpy(copy, self->data, irem * sizeof(*copy)); memmove(self->data, self->data + irem, ishift * sizeof(double)); memcpy(self->data + ishift, copy, irem * sizeof(double)); - - } else if (ishift > 0) { + } + else if (ishift > 0) { /* A small shift, copy the last (smaller) part of the buffer */ - copy = (double*)cpl_malloc((size_t)ishift * sizeof(*copy)); + copy = (double *)cpl_malloc((size_t)ishift * sizeof(*copy)); memcpy(copy, self->data + irem, ishift * sizeof(*copy)); memmove(self->data + ishift, self->data, irem * sizeof(double)); memcpy(self->data, copy, ishift * sizeof(double)); - } cpl_free(copy); - } else if (ishift > 0) { + } + else if (ishift > 0) { /* Perform integer shift of self to other */ const cpl_size irem = n - ishift; @@ -1180,7 +1223,8 @@ (void)memcpy(self->data + ishift, other->data, irem * sizeof(double)); (void)memcpy(self->data, other->data + irem, ishift * sizeof(double)); - } else { + } + else { /* This is just a copy */ (void)memcpy(self->data, other->data, (size_t)n * sizeof(double)); } @@ -1203,23 +1247,24 @@ - CPL_ERROR_INCOMPATIBLE_INPUT if v1 and v2 have different sizes */ /*----------------------------------------------------------------------------*/ -double cpl_vector_product(const cpl_vector * v1, const cpl_vector * v2) +double +cpl_vector_product(const cpl_vector *v1, const cpl_vector *v2) { - const double * x = cpl_vector_get_data_const(v1); - const double * y = cpl_vector_get_data_const(v2); - const cpl_size n = cpl_vector_get_size(v1); + const double *x = cpl_vector_get_data_const(v1); + const double *y = cpl_vector_get_data_const(v2); + const cpl_size n = cpl_vector_get_size(v1); double sum = 0; cpl_size i; cpl_ensure(x, CPL_ERROR_NULL_INPUT, -1); cpl_ensure(y, CPL_ERROR_NULL_INPUT, -2); - cpl_ensure(cpl_vector_get_size(v2) == n, CPL_ERROR_INCOMPATIBLE_INPUT, - -3); + cpl_ensure(cpl_vector_get_size(v2) == n, CPL_ERROR_INCOMPATIBLE_INPUT, -3); - for (i = 0; i < n; i++) sum += x[i] * y[i]; + for (i = 0; i < n; i++) + sum += x[i] * y[i]; - cpl_tools_add_flops(2*n); + cpl_tools_add_flops(2 * n); return sum; } @@ -1240,24 +1285,22 @@ CPL_SORT_ASCENDING */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_vector_sort(cpl_vector * self, - cpl_sort_direction dir) +cpl_error_code +cpl_vector_sort(cpl_vector *self, cpl_sort_direction dir) { cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); if (dir == CPL_SORT_ASCENDING) { - /* Sort by increasing data */ if (cpl_tools_sort_double(self->data, self->size)) { return cpl_error_set_where_(); } - - } else if (dir == CPL_SORT_DESCENDING) { - + } + else if (dir == CPL_SORT_DESCENDING) { /* Sort by decreasing data */ cpl_tools_sort_desc_double(self->data, self->size); - - } else { + } + else { return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); } @@ -1277,14 +1320,16 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_vector_fill(cpl_vector * v, double val) +cpl_error_code +cpl_vector_fill(cpl_vector *v, double val) { - cpl_ensure_code(v, CPL_ERROR_NULL_INPUT); if (val != 0.0) { - for (size_t i = 0; i < (size_t)v->size; i++) v->data[i] = val; - } else { + for (size_t i = 0; i < (size_t)v->size; i++) + v->data[i] = val; + } + else { (void)memset(v->data, 0, (size_t)v->size * sizeof(*v->data)); } @@ -1307,18 +1352,20 @@ - CPL_ERROR_ILLEGAL_INPUT if one of the vector values is negative */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_vector_sqrt(cpl_vector * v) +cpl_error_code +cpl_vector_sqrt(cpl_vector *v) { - cpl_size i; + cpl_size i; /* Test inputs */ - cpl_ensure_code(v!=NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(v != NULL, CPL_ERROR_NULL_INPUT); - for (i = 0; isize; i++) + for (i = 0; i < v->size; i++) cpl_ensure_code(v->data[i] >= 0, CPL_ERROR_ILLEGAL_INPUT); /* Compute the sqrt */ - for (i = 0; i < v->size; i++) v->data[i] = sqrt(v->data[i]); + for (i = 0; i < v->size; i++) + v->data[i] = sqrt(v->data[i]); cpl_tools_add_flops(v->size); @@ -1348,8 +1395,8 @@ - CPL_ERROR_ILLEGAL_INPUT if two elements are found to not be sorted */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_vector_find(const cpl_vector * sorted, - double key) +cpl_size +cpl_vector_find(const cpl_vector *sorted, double key) { cpl_size low, high; @@ -1357,19 +1404,21 @@ cpl_ensure(sorted != NULL, CPL_ERROR_NULL_INPUT, -1); /* Initialize */ - low = 0; + low = 0; high = sorted->size - 1; cpl_ensure(sorted->data[low] <= sorted->data[high], CPL_ERROR_ILLEGAL_INPUT, -2); - if (key <= sorted->data[ low]) return low; - if (key >= sorted->data[high]) return high; + if (key <= sorted->data[low]) + return low; + if (key >= sorted->data[high]) + return high; /* key is in the range of the vector values */ while (high - low > 1) { - const cpl_size middle = low + (high - low) / 2; + const cpl_size middle = low + (high - low) / 2; /* Three or four comparisons are done per iteration, however with the non-localized access pattern data reads @@ -1380,9 +1429,12 @@ cpl_ensure(sorted->data[middle] <= sorted->data[high], CPL_ERROR_ILLEGAL_INPUT, -4); - if (sorted->data[middle] > key) high = middle; - else if (sorted->data[middle] < key) low = middle; - else low = high = middle; + if (sorted->data[middle] > key) + high = middle; + else if (sorted->data[middle] < key) + low = middle; + else + low = high = middle; } /* assert( low == high || low == high - 1); */ @@ -1409,25 +1461,25 @@ - CPL_ERROR_ILLEGAL_INPUT if istart, istop, istep are not as requested */ /*----------------------------------------------------------------------------*/ -cpl_vector * cpl_vector_extract( - const cpl_vector * v, - cpl_size istart, - cpl_size istop, - cpl_size istep) +cpl_vector * +cpl_vector_extract(const cpl_vector *v, + cpl_size istart, + cpl_size istop, + cpl_size istep) { - cpl_vector * out; + cpl_vector *out; /* Test inputs */ - cpl_ensure(v, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(istart >= 0, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL); - cpl_ensure(istart <= istop, CPL_ERROR_ILLEGAL_INPUT, NULL); - cpl_ensure(istep == 1, CPL_ERROR_ILLEGAL_INPUT, NULL); - cpl_ensure(istop < v->size, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL); + cpl_ensure(v, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(istart >= 0, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL); + cpl_ensure(istart <= istop, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(istep == 1, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(istop < v->size, CPL_ERROR_ACCESS_OUT_OF_RANGE, NULL); /* Allocate and fill the output vector */ out = cpl_vector_new(istop - istart + 1); - assert( out ); + assert(out); memcpy(out->data, &(v->data[istart]), (size_t)out->size * sizeof(double)); @@ -1444,7 +1496,8 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_vector_get_minpos(const cpl_vector * self) +cpl_size +cpl_vector_get_minpos(const cpl_vector *self) { size_t minpos = 0; @@ -1469,7 +1522,8 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_vector_get_maxpos(const cpl_vector * self) +cpl_size +cpl_vector_get_maxpos(const cpl_vector *self) { size_t maxpos = 0; @@ -1497,7 +1551,8 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -double cpl_vector_get_min(const cpl_vector * v) +double +cpl_vector_get_min(const cpl_vector *v) { const cpl_size minpos = cpl_vector_get_minpos(v); @@ -1517,7 +1572,8 @@ @see cpl_vector_get_min() */ /*----------------------------------------------------------------------------*/ -double cpl_vector_get_max(const cpl_vector * v) +double +cpl_vector_get_max(const cpl_vector *v) { const cpl_size maxpos = cpl_vector_get_maxpos(v); @@ -1537,15 +1593,17 @@ @see cpl_vector_get_min() */ /*----------------------------------------------------------------------------*/ -double cpl_vector_get_sum(const cpl_vector * v) +double +cpl_vector_get_sum(const cpl_vector *v) { - double sum = 0.0; - cpl_size i; + double sum = 0.0; + cpl_size i; /* Test entries */ - cpl_ensure(v != NULL, CPL_ERROR_NULL_INPUT, -1.0); + cpl_ensure(v != NULL, CPL_ERROR_NULL_INPUT, -1.0); - for (i=0; i < v->size; i++) sum += v->data[i]; + for (i = 0; i < v->size; i++) + sum += v->data[i]; return sum; } @@ -1558,7 +1616,8 @@ @see cpl_vector_get_min() */ /*----------------------------------------------------------------------------*/ -double cpl_vector_get_mean(const cpl_vector * v) +double +cpl_vector_get_mean(const cpl_vector *v) { cpl_ensure(v != NULL, CPL_ERROR_NULL_INPUT, -1.0); @@ -1576,7 +1635,8 @@ */ /*----------------------------------------------------------------------------*/ -double cpl_vector_get_median(cpl_vector * v) +double +cpl_vector_get_median(cpl_vector *v) { cpl_ensure(v != NULL, CPL_ERROR_NULL_INPUT, 0.0); @@ -1601,16 +1661,17 @@ */ /*----------------------------------------------------------------------------*/ -double cpl_vector_get_median_const(const cpl_vector * v) +double +cpl_vector_get_median_const(const cpl_vector *v) { - double * darr; - double med; + double *darr; + double med; cpl_ensure(v != NULL, CPL_ERROR_NULL_INPUT, 0.0); /* Create a separate data buffer because */ /* cpl_tools_get_median_double() modifies its input */ - darr = (double*)cpl_malloc((size_t)v->size * sizeof(*darr)); + darr = (double *)cpl_malloc((size_t)v->size * sizeof(*darr)); memcpy(darr, v->data, (size_t)v->size * sizeof(double)); @@ -1633,20 +1694,21 @@ The length of v must be at least 2. */ /*----------------------------------------------------------------------------*/ -double cpl_vector_get_stdev(const cpl_vector * v) +double +cpl_vector_get_stdev(const cpl_vector *v) { double varsum; - cpl_ensure(v != NULL, CPL_ERROR_NULL_INPUT,-1); - cpl_ensure(v->size > 1, CPL_ERROR_ILLEGAL_INPUT,-2); + cpl_ensure(v != NULL, CPL_ERROR_NULL_INPUT, -1); + cpl_ensure(v->size > 1, CPL_ERROR_ILLEGAL_INPUT, -2); varsum = cpl_tools_get_variancesum_double(v->data, v->size, NULL); /* Compute the bias-corrected standard deviation. - With the recurrence relation rounding can likely not cause the variance to become negative, but check just to be safe */ - return sqrt(varsum / (double) (v->size-1)); + return sqrt(varsum / (double)(v->size - 1)); } /*----------------------------------------------------------------------------*/ @@ -1718,10 +1780,11 @@ is not as requested */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_vector_correlate(cpl_vector * vxc, const cpl_vector * v1, - const cpl_vector * v2) +cpl_size +cpl_vector_correlate(cpl_vector *vxc, + const cpl_vector *v1, + const cpl_vector *v2) { - /* FIXME: The API should be extended with a boolean @param is_cyclic Use a cyclic boundary => v1 and v2 must have equal size @@ -1755,11 +1818,11 @@ i.e. either the first or the last 1 + 2 * hsearch elements of vxc. */ - double xc = 0.0; - double mean1 = 0.0; - double mean2 = 0.0; - double var1 = 0.0; - double var2 = 0.0; + double xc = 0.0; + double mean1 = 0.0; + double mean2 = 0.0; + double var1 = 0.0; + double var2 = 0.0; cpl_size half_search; cpl_size delta; @@ -1768,22 +1831,22 @@ cpl_size i1; cpl_size size; - cpl_ensure(vxc != NULL, CPL_ERROR_NULL_INPUT, -10); - cpl_ensure(v1 != NULL, CPL_ERROR_NULL_INPUT, -20); - cpl_ensure(v2 != NULL, CPL_ERROR_NULL_INPUT, -30); + cpl_ensure(vxc != NULL, CPL_ERROR_NULL_INPUT, -10); + cpl_ensure(v1 != NULL, CPL_ERROR_NULL_INPUT, -20); + cpl_ensure(v2 != NULL, CPL_ERROR_NULL_INPUT, -30); cpl_ensure(v1->size >= v2->size, CPL_ERROR_ILLEGAL_INPUT, -50); - half_search = cpl_vector_get_size(vxc)-1; - cpl_ensure(!(half_search & 1), CPL_ERROR_ILLEGAL_INPUT, -60); - half_search >>=1; + half_search = cpl_vector_get_size(vxc) - 1; + cpl_ensure(!(half_search & 1), CPL_ERROR_ILLEGAL_INPUT, -60); + half_search >>= 1; size = v2->size; /* Number of elements used in cross-correlation */ /* 1st v1 index used - non-zero iff v1 is longer than v2 */ - i1 = (v1->size - v2->size)/2; + i1 = (v1->size - v2->size) / 2; - cpl_ensure(half_search <= i1 || 2*i1 == v1->size - v2->size, - CPL_ERROR_ILLEGAL_INPUT, -70); + cpl_ensure(half_search <= i1 || 2 * i1 == v1->size - v2->size, + CPL_ERROR_ILLEGAL_INPUT, -70); /* The current implementation requires O(size * half_search) FLOPs. If size and half_search are large enough it should be preferable @@ -1815,12 +1878,12 @@ /* This approach requires only 8n FLOPS. It is only faster if v1 and v2 are already in cache - or if they do not fit in the cache. The round-off can be 10 times bigger */ - for (i = 0; idata[i+i1]; - mean2 += v2->data[i ]; - var1 += v1->data[i+i1] * v1->data[i+i1]; - var2 += v2->data[i ] * v2->data[i ]; - xc += v1->data[i+i1] * v2->data[i ]; + for (i = 0; i < size; i++) { + mean1 += v1->data[i + i1]; + mean2 += v2->data[i]; + var1 += v1->data[i + i1] * v1->data[i + i1]; + var2 += v2->data[i] * v2->data[i]; + xc += v1->data[i + i1] * v2->data[i]; } mean1 /= (double)size; @@ -1828,7 +1891,7 @@ var1 -= mean1 * mean1 * (double)size; var2 -= mean2 * mean2 * (double)size; - xc -= mean1 * mean2 * (double)size; + xc -= mean1 * mean2 * (double)size; cpl_tools_add_flops(8 * size + 11); @@ -1836,7 +1899,7 @@ /* var can only be zero with a constant vector - in which case xc is zero */ - if ( var1 > 0.0 && var2 > 0.0) { + if (var1 > 0.0 && var2 > 0.0) { xc /= sqrt(var1 * var2); /* xc can only be outside [-1;1] due to rounding errors */ @@ -1844,24 +1907,27 @@ #ifndef NDEBUG const double m1 = fabs(mean1) > 1.0 ? fabs(mean1) : 1.0; const double m2 = fabs(mean2) > 1.0 ? fabs(mean2) : 1.0; - assert( -1.0 - xc < (double)size * DBL_EPSILON * sqrt(m1 * m2)); + assert(-1.0 - xc < (double)size * DBL_EPSILON * sqrt(m1 * m2)); #endif xc = -1.0; - } else if (xc > 1.0) { + } + else if (xc > 1.0) { #ifndef NDEBUG const double m1 = fabs(mean1) > 1.0 ? fabs(mean1) : 1.0; const double m2 = fabs(mean2) > 1.0 ? fabs(mean2) : 1.0; - assert( xc-1.0 < (double)size * DBL_EPSILON * sqrt(m1 * m2)); + assert(xc - 1.0 < (double)size * DBL_EPSILON * sqrt(m1 * m2)); #endif - xc = 1.0; + xc = 1.0; } - - } else { + } + else { /* Remove some rounding errors */ - if (var1 < 0) var1 = 0.0; - if (var2 < 0) var2 = 0.0; + if (var1 < 0) + var1 = 0.0; + if (var2 < 0) + var2 = 0.0; xc = 0.0; } @@ -1869,7 +1935,6 @@ (void)cpl_vector_set(vxc, half_search, xc); if (half_search > 0) { - /* less than maximal precision OK here */ const double rsize = 1.0 / (double)size; const double dsize = 1.0 + rsize; @@ -1890,8 +1955,8 @@ /* No use to search further than i1 + size - 1 */ const cpl_size max_hs = i1 + size - 2; - const cpl_size hs = half_search > max_hs ? max_hs : half_search; - const cpl_size hs1 = hs > i1 ? i1 : hs; + const cpl_size hs = half_search > max_hs ? max_hs : half_search; + const cpl_size hs1 = hs > i1 ? i1 : hs; /* Skip non-drop part if var2 == 0 */ cpl_size step = var2 > 0 ? 1 : hs1 + 1; @@ -1899,8 +1964,7 @@ /* Number of elements in shortened cross-correlation */ cpl_size istop = i1 + size - step; - for (; step<=hs1; step++, istop--) { - + for (; step <= hs1; step++, istop--) { /* Can cross-correlate over all of v2 - mean2 and var2 are unchanged */ @@ -1908,30 +1972,30 @@ double xc_n = 0.0; /* Subtract term from normalization factors */ - var1_p -= (v1->data[i1+step-1] * dsize - 2 * mean1_p) - * v1->data[i1+step-1]; + var1_p -= (v1->data[i1 + step - 1] * dsize - 2 * mean1_p) * + v1->data[i1 + step - 1]; - var1_n -= (v1->data[istop ] * dsize - 2 * mean1_n) - * v1->data[istop ]; + var1_n -= (v1->data[istop] * dsize - 2 * mean1_n) * v1->data[istop]; /* Update mean1 */ - mean1_p += (v1->data[i1+size+step-1] - v1->data[i1+step-1 ]) - * rsize; - mean1_n += (v1->data[i1-step ] - v1->data[i1+size-step]) - * rsize; + mean1_p += + (v1->data[i1 + size + step - 1] - v1->data[i1 + step - 1]) * + rsize; + mean1_n += + (v1->data[i1 - step] - v1->data[i1 + size - step]) * rsize; /* Add term to normalization factors */ - var1_n += (v1->data[i1-step ] * dsize - 2 * mean1_n) - * v1->data[i1-step ]; + var1_n += (v1->data[i1 - step] * dsize - 2 * mean1_n) * + v1->data[i1 - step]; - var1_p += (v1->data[i1+size+step-1] * dsize - 2 * mean1_p) - * v1->data[i1+size+step-1]; + var1_p += (v1->data[i1 + size + step - 1] * dsize - 2 * mean1_p) * + v1->data[i1 + size + step - 1]; /* Compute xc - exploiting that the dot-product is distributive over subtraction */ - for (i = 0; idata[i] * v1->data[i+i1-step]; - xc_p += v2->data[i] * v1->data[i+i1+step]; + for (i = 0; i < size; i++) { + xc_n += v2->data[i] * v1->data[i + i1 - step]; + xc_p += v2->data[i] * v1->data[i + i1 + step]; } if (var1_n > 0.0) { @@ -1944,24 +2008,25 @@ if (xc_n < -1.0) { #ifndef NDEBUG const double m1 = fabs(mean1_n) > 1.0 ? fabs(mean1_n) : 1.0; - const double m2 = fabs(mean2) > 1.0 ? fabs(mean2) : 1.0; - assert( -1.0 - xc_n < 4.0 * (double)size * DBL_EPSILON - * sqrt(m1 * m2)); + const double m2 = fabs(mean2) > 1.0 ? fabs(mean2) : 1.0; + assert(-1.0 - xc_n < + 4.0 * (double)size * DBL_EPSILON * sqrt(m1 * m2)); #endif xc_n = -1.0; - } else if (xc_n > 1.0) { + } + else if (xc_n > 1.0) { #ifndef NDEBUG const double m1 = fabs(mean1_n) > 1.0 ? fabs(mean1_n) : 1.0; - const double m2 = fabs(mean2) > 1.0 ? fabs(mean2) : 1.0; - assert( xc_n - 1.0 < 4.0 * (double)size * DBL_EPSILON - * sqrt(m1 * m2)); + const double m2 = fabs(mean2) > 1.0 ? fabs(mean2) : 1.0; + assert(xc_n - 1.0 < + 4.0 * (double)size * DBL_EPSILON * sqrt(m1 * m2)); #endif - xc_n = 1.0; + xc_n = 1.0; } - - } else + } + else xc_n = 0.0; if (xc_n > xc) { @@ -1980,24 +2045,25 @@ if (xc_p < -1.0) { #ifndef NDEBUG const double m1 = fabs(mean1_p) > 1.0 ? fabs(mean1_p) : 1.0; - const double m2 = fabs(mean2) > 1.0 ? fabs(mean2) : 1.0; - assert( -1.0 - xc_p < 4.0 * (double)size * DBL_EPSILON - * sqrt(m1 * m2)); + const double m2 = fabs(mean2) > 1.0 ? fabs(mean2) : 1.0; + assert(-1.0 - xc_p < + 4.0 * (double)size * DBL_EPSILON * sqrt(m1 * m2)); #endif xc_p = -1.0; - } else if (xc_p > 1.0) { + } + else if (xc_p > 1.0) { #ifndef NDEBUG const double m1 = fabs(mean1_p) > 1.0 ? fabs(mean1_p) : 1.0; - const double m2 = fabs(mean2) > 1.0 ? fabs(mean2) : 1.0; - assert( xc_p - 1.0 < 4.0 * (double)size * DBL_EPSILON - * sqrt(m1 * m2)); + const double m2 = fabs(mean2) > 1.0 ? fabs(mean2) : 1.0; + assert(xc_p - 1.0 < + 4.0 * (double)size * DBL_EPSILON * sqrt(m1 * m2)); #endif - xc_p = 1.0; + xc_p = 1.0; } - - } else + } + else xc_p = 0.0; if (xc_p > xc) { @@ -2006,16 +2072,14 @@ } (void)cpl_vector_set(vxc, half_search + step, xc_p); - } - assert( step == hs1 + 1 ); + assert(step == hs1 + 1); if (var2 > 0) { - cpl_tools_add_flops( hs1 * (4*size + 26) ); + cpl_tools_add_flops(hs1 * (4 * size + 26)); } for (; step < 1 + hs; step++, istop--) { - /* v1 is too short - Cross-correlate on reduced number of elements - elements out of range are defined to be zero */ @@ -2024,34 +2088,32 @@ double xc_n = 0.0; /* Subtract dropped term from normalization factors */ - var1_p -= (v1->data[step+i1-1] * dsize - 2 * mean1_p) - * v1->data[step+i1-1]; + var1_p -= (v1->data[step + i1 - 1] * dsize - 2 * mean1_p) * + v1->data[step + i1 - 1]; - var1_n -= (v1->data[istop ] * dsize - 2 * mean1_n) - * v1->data[istop ]; + var1_n -= (v1->data[istop] * dsize - 2 * mean1_n) * v1->data[istop]; - var2_p -= (v2->data[istop ] * dsize - 2 * mean2_p) - * v2->data[istop ]; + var2_p -= (v2->data[istop] * dsize - 2 * mean2_p) * v2->data[istop]; - var2_n -= (v2->data[step-i1-1] * dsize - 2 * mean2_n) - * v2->data[step-i1-1]; + var2_n -= (v2->data[step - i1 - 1] * dsize - 2 * mean2_n) * + v2->data[step - i1 - 1]; /* Subtract dropped elements from mean */ - mean1_p -= v1->data[step+i1-1] * rsize; - mean1_n -= v1->data[istop ] * rsize; + mean1_p -= v1->data[step + i1 - 1] * rsize; + mean1_n -= v1->data[istop] * rsize; - mean2_p -= v2->data[istop ] * rsize; - mean2_n -= v2->data[step-i1-1] * rsize; + mean2_p -= v2->data[istop] * rsize; + mean2_n -= v2->data[step - i1 - 1] * rsize; /* Compute xc */ - for (i = 0; idata[i] * v2->data[i-i1+step]; - xc_p += v2->data[i] * v1->data[i+i1+step]; + for (i = 0; i < istop; i++) { + xc_n += v1->data[i] * v2->data[i - i1 + step]; + xc_p += v2->data[i] * v1->data[i + i1 + step]; } if (var1_n * var2_n > 0) { /* Subtract the mean-term */ - xc_n -= mean1_n * mean2_n * (double)(2*size - istop); + xc_n -= mean1_n * mean2_n * (double)(2 * size - istop); /* - and divide by the norm of the mean-corrected vectors */ xc_n /= sqrt(var1_n * var2_n); @@ -2059,24 +2121,25 @@ if (xc_n < -1.0) { #ifndef NDEBUG const double m1 = fabs(mean1_n) > 1.0 ? fabs(mean1_n) : 1.0; - const double m2 = fabs(mean2) > 1.0 ? fabs(mean2) : 1.0; - assert( -1.0 - xc_n < 4.0 * (double)size * DBL_EPSILON - * sqrt(m1 * m2)); + const double m2 = fabs(mean2) > 1.0 ? fabs(mean2) : 1.0; + assert(-1.0 - xc_n < + 4.0 * (double)size * DBL_EPSILON * sqrt(m1 * m2)); #endif xc_n = -1.0; - } else if (xc_n > 1.0) { + } + else if (xc_n > 1.0) { #ifndef NDEBUG const double m1 = fabs(mean1_n) > 1.0 ? fabs(mean1_n) : 1.0; - const double m2 = fabs(mean2) > 1.0 ? fabs(mean2) : 1.0; - assert( xc_n - 1.0 < 4.0 * (double)size * DBL_EPSILON - * sqrt(m1 * m2)); + const double m2 = fabs(mean2) > 1.0 ? fabs(mean2) : 1.0; + assert(xc_n - 1.0 < + 4.0 * (double)size * DBL_EPSILON * sqrt(m1 * m2)); #endif - xc_n = 1.0; + xc_n = 1.0; } - - } else + } + else xc_n = 0.0; if (xc_n > xc) { @@ -2088,7 +2151,7 @@ if (var1_p * var2_p > 0) { /* Subtract the mean-term */ - xc_p -= mean1_p * mean2_p * (double)(2*size - istop); + xc_p -= mean1_p * mean2_p * (double)(2 * size - istop); /* - and divide by the norm of the mean-corrected vectors */ xc_p /= sqrt(var1_p * var2_p); @@ -2096,24 +2159,25 @@ if (xc_p < -1.0) { #ifndef NDEBUG const double m1 = fabs(mean1_p) > 1.0 ? fabs(mean1_p) : 1.0; - const double m2 = fabs(mean2) > 1.0 ? fabs(mean2) : 1.0; - assert( -1.0 - xc_p < 4.0 * (double)size * DBL_EPSILON - * sqrt(m1 * m2)); + const double m2 = fabs(mean2) > 1.0 ? fabs(mean2) : 1.0; + assert(-1.0 - xc_p < + 4.0 * (double)size * DBL_EPSILON * sqrt(m1 * m2)); #endif xc_p = -1.0; - } else if (xc_p > 1.0) { + } + else if (xc_p > 1.0) { #ifndef NDEBUG const double m1 = fabs(mean1_p) > 1.0 ? fabs(mean1_p) : 1.0; - const double m2 = fabs(mean2) > 1.0 ? fabs(mean2) : 1.0; - assert( xc_p-1.0 < 4.0 * (double)size * DBL_EPSILON - * sqrt(m1 * m2)); + const double m2 = fabs(mean2) > 1.0 ? fabs(mean2) : 1.0; + assert(xc_p - 1.0 < + 4.0 * (double)size * DBL_EPSILON * sqrt(m1 * m2)); #endif - xc_p = 1.0; + xc_p = 1.0; } - - } else + } + else xc_p = 0.0; if (xc_p > xc) { @@ -2121,15 +2185,13 @@ delta = step; } (void)cpl_vector_set(vxc, half_search + step, xc_p); - } if (hs > hs1) { - cpl_tools_add_flops( (hs-hs1) * ( 4*istop + 28 ) ); + cpl_tools_add_flops((hs - hs1) * (4 * istop + 28)); } } return half_search + delta; - } /*----------------------------------------------------------------------------*/ @@ -2158,20 +2220,20 @@ negative or bigger than half the vector v size */ /*----------------------------------------------------------------------------*/ -cpl_vector * cpl_vector_filter_lowpass_create( - const cpl_vector * v, - cpl_lowpass filter_type, - cpl_size hw) -{ - cpl_vector * filtered; - cpl_vector * kernel; - double replace; - cpl_size i, j; +cpl_vector * +cpl_vector_filter_lowpass_create(const cpl_vector *v, + cpl_lowpass filter_type, + cpl_size hw) +{ + cpl_vector *filtered; + cpl_vector *kernel; + double replace; + cpl_size i, j; - cpl_ensure(v != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(v != NULL, CPL_ERROR_NULL_INPUT, NULL); cpl_ensure(hw >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL); - cpl_ensure(2*hw <= v->size, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(2 * hw <= v->size, CPL_ERROR_ILLEGAL_INPUT, NULL); /* generate low-pass filter kernel */ kernel = cpl_vector_gen_lowpass_kernel(filter_type, hw); @@ -2183,41 +2245,43 @@ filtered = cpl_vector_new(v->size); /* compute edge effects for the first hw elements */ - for (i = 0; idata[hw+j] * v->data[0]; - } else { - replace += kernel->data[hw+j] * v->data[i+j]; + for (j = -hw; j <= hw; j++) { + if (i + j < 0) { + replace += kernel->data[hw + j] * v->data[0]; + } + else { + replace += kernel->data[hw + j] * v->data[i + j]; } } filtered->data[i] = replace; } /* compute edge effects for the last hw elements */ - for (i=v->size-hw; isize; i++) { + for (i = v->size - hw; i < v->size; i++) { replace = 0.0; - for (j=-hw; j<=hw; j++) { - if (i+j>v->size-1) { - replace += kernel->data[hw+j] * v->data[v->size-1]; - } else { - replace += kernel->data[hw+j] * v->data[i+j]; + for (j = -hw; j <= hw; j++) { + if (i + j > v->size - 1) { + replace += kernel->data[hw + j] * v->data[v->size - 1]; + } + else { + replace += kernel->data[hw + j] * v->data[i + j]; } } filtered->data[i] = replace; } /* compute all other elements */ - for (i=hw; isize-hw; i++) { + for (i = hw; i < v->size - hw; i++) { replace = 0.0; - for (j=-hw; j<=hw; j++) { - replace += kernel->data[hw+j] * v->data[i+j]; + for (j = -hw; j <= hw; j++) { + replace += kernel->data[hw + j] * v->data[i + j]; } filtered->data[i] = replace; } cpl_vector_delete(kernel); - cpl_tools_add_flops(4*hw*v->size); + cpl_tools_add_flops(4 * hw * v->size); return filtered; } @@ -2251,30 +2315,30 @@ size */ /*----------------------------------------------------------------------------*/ -cpl_vector * cpl_vector_filter_median_create(const cpl_vector * self, - cpl_size hw) +cpl_vector * +cpl_vector_filter_median_create(const cpl_vector *self, cpl_size hw) { + cpl_vector *other; - cpl_vector * other; - - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(hw >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL); - cpl_ensure(2*hw <= self->size, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(hw >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(2 * hw <= self->size, CPL_ERROR_ILLEGAL_INPUT, NULL); if (2 * hw == self->size) { other = cpl_vector_duplicate(self); - } else { + } + else { /* Cannot fail now */ - cpl_image * imgself; - cpl_image * imgother; - cpl_mask * kernel; - double * data; + cpl_image *imgself; + cpl_image *imgother; + cpl_mask *kernel; + double *data; cpl_error_code code; /* Create (non-modified) 1D-image from self */ CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); - data = (double*)self->data; + data = (double *)self->data; CPL_DIAG_PRAGMA_POP; imgself = cpl_image_wrap_double(self->size, 1, data); @@ -2311,17 +2375,17 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_vector_add_scalar( - cpl_vector * v, - double addend) +cpl_error_code +cpl_vector_add_scalar(cpl_vector *v, double addend) { - cpl_size i; + cpl_size i; /* Test inputs */ - cpl_ensure_code(v != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(v != NULL, CPL_ERROR_NULL_INPUT); /* Perform the addition */ - for (i = 0; isize; i++) v->data[i] += addend; + for (i = 0; i < v->size; i++) + v->data[i] += addend; cpl_tools_add_flops(v->size); @@ -2342,17 +2406,17 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_vector_subtract_scalar( - cpl_vector * v, - double subtrahend) +cpl_error_code +cpl_vector_subtract_scalar(cpl_vector *v, double subtrahend) { - cpl_size i; + cpl_size i; /* Test inputs */ - cpl_ensure_code(v != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(v != NULL, CPL_ERROR_NULL_INPUT); /* Perform the subtraction */ - for (i = 0; isize; i++) v->data[i] -= subtrahend; + for (i = 0; i < v->size; i++) + v->data[i] -= subtrahend; cpl_tools_add_flops(v->size); @@ -2373,17 +2437,17 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_vector_multiply_scalar( - cpl_vector * v, - double factor) +cpl_error_code +cpl_vector_multiply_scalar(cpl_vector *v, double factor) { - cpl_size i; + cpl_size i; /* Test inputs */ - cpl_ensure_code(v != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(v != NULL, CPL_ERROR_NULL_INPUT); /* Perform the subtraction */ - for (i = 0; isize; i++) v->data[i] *= factor; + for (i = 0; i < v->size; i++) + v->data[i] *= factor; cpl_tools_add_flops(v->size); @@ -2391,7 +2455,6 @@ } - /*----------------------------------------------------------------------------*/ /** @brief Elementwise division of a vector with a scalar @@ -2406,18 +2469,18 @@ - CPL_ERROR_DIVISION_BY_ZERO if divisor is 0.0 */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_vector_divide_scalar( - cpl_vector * v, - double divisor) +cpl_error_code +cpl_vector_divide_scalar(cpl_vector *v, double divisor) { - cpl_size i; + cpl_size i; /* Test inputs */ - cpl_ensure_code(v != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(v != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(divisor != 0, CPL_ERROR_DIVISION_BY_ZERO); /* Perform the subtraction */ - for (i = 0; isize; i++) v->data[i] /= divisor; + for (i = 0; i < v->size; i++) + v->data[i] /= divisor; cpl_tools_add_flops(v->size); @@ -2442,22 +2505,22 @@ - CPL_ERROR_DIVISION_BY_ZERO if a division by zero occurs */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_vector_logarithm( - cpl_vector * v, - double base) -{ - cpl_size i; - - cpl_ensure_code(v != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(base > 0, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(base != 1, CPL_ERROR_DIVISION_BY_ZERO); +cpl_error_code +cpl_vector_logarithm(cpl_vector *v, double base) +{ + cpl_size i; + + cpl_ensure_code(v != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(base > 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(base != 1, CPL_ERROR_DIVISION_BY_ZERO); for (i = 0; i < v->size; i++) cpl_ensure_code(v->data[i] > 0, CPL_ERROR_ILLEGAL_INPUT); - for (i = 0; i < v->size; i++) v->data[i] = log(v->data[i]) / log(base); + for (i = 0; i < v->size; i++) + v->data[i] = log(v->data[i]) / log(base); - cpl_tools_add_flops(2*v->size); + cpl_tools_add_flops(2 * v->size); return CPL_ERROR_NONE; } @@ -2479,25 +2542,26 @@ - CPL_ERROR_DIVISION_BY_ZERO if one of the v values is negative or 0 */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_vector_exponential( - cpl_vector * v, - double base) +cpl_error_code +cpl_vector_exponential(cpl_vector *v, double base) { - cpl_size i; + cpl_size i; - cpl_ensure_code(v != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(v != NULL, CPL_ERROR_NULL_INPUT); if (base == 0.0) { for (i = 0; i < v->size; i++) cpl_ensure_code(v->data[i] > 0.0, CPL_ERROR_DIVISION_BY_ZERO); - } else if (base < 0.0) { + } + else if (base < 0.0) { for (i = 0; i < v->size; i++) cpl_ensure_code(v->data[i] == ceil(v->data[i]), CPL_ERROR_ILLEGAL_INPUT); } - for (i = 0; i < v->size; i++) v->data[i] = pow(base, v->data[i]); + for (i = 0; i < v->size; i++) + v->data[i] = pow(base, v->data[i]); cpl_tools_add_flops(v->size); @@ -2523,23 +2587,24 @@ - CPL_ERROR_DIVISION_BY_ZERO if one of the v values is 0 */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_vector_power( - cpl_vector * v, - double exponent) +cpl_error_code +cpl_vector_power(cpl_vector *v, double exponent) { - cpl_size i; + cpl_size i; cpl_ensure_code(v != NULL, CPL_ERROR_NULL_INPUT); if (exponent < 0) { for (i = 0; i < v->size; i++) cpl_ensure_code(v->data[i] != 0, CPL_ERROR_DIVISION_BY_ZERO); - } else if (exponent != ceil(exponent)) { + } + else if (exponent != ceil(exponent)) { for (i = 0; i < v->size; i++) cpl_ensure_code(v->data[i] >= 0, CPL_ERROR_ILLEGAL_INPUT); } - for (i = 0; i < v->size; i++) v->data[i] = pow(v->data[i], exponent); + for (i = 0; i < v->size; i++) + v->data[i] = pow(v->data[i], exponent); cpl_tools_add_flops(v->size); @@ -2573,18 +2638,19 @@ */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_vector_fill_kernel_profile(cpl_vector * profile, - cpl_kernel type, - double radius) +cpl_error_code +cpl_vector_fill_kernel_profile(cpl_vector *profile, + cpl_kernel type, + double radius) { const cpl_size size = cpl_vector_get_size(profile); /* TABS per pixel == 1 / dx */ /* If size is 1, the profile is flat (and hardly useful) */ - const double dx = size > 1 ? radius / (double)(size-1) : 1.0; + const double dx = size > 1 ? radius / (double)(size - 1) : 1.0; cpl_size i; - cpl_ensure_code(size > 0, cpl_error_get_code()); + cpl_ensure_code(size > 0, cpl_error_get_code()); cpl_ensure_code(radius > 0.0, CPL_ERROR_ILLEGAL_INPUT); /* Switch on the requested kernel type */ @@ -2599,7 +2665,7 @@ const double x = (double)i * dx; profile->data[i] = cpl_tools_sinc(x); } - cpl_tools_add_flops( 4 * size ); + cpl_tools_add_flops(4 * size); break; case CPL_KERNEL_SINC2: for (i = 0; i < size; i++) { @@ -2607,17 +2673,19 @@ profile->data[i] = cpl_tools_sinc(x); profile->data[i] *= profile->data[i]; } - cpl_tools_add_flops( 5 * size ); + cpl_tools_add_flops(5 * size); break; case CPL_KERNEL_LANCZOS: for (i = 0; i < size; i++) { const double x = (double)i * dx; - if (x >= 2) break; - profile->data[i] = cpl_tools_sinc(x) * cpl_tools_sinc(x/2); - } - for (; i < size; i++) profile->data[i] = 0; - cpl_tools_add_flops( 8 * i ); + if (x >= 2) + break; + profile->data[i] = cpl_tools_sinc(x) * cpl_tools_sinc(x / 2); + } + for (; i < size; i++) + profile->data[i] = 0; + cpl_tools_add_flops(8 * i); break; case CPL_KERNEL_HAMMING: cpl_vector_fill_alpha_kernel(profile, dx, 0.54); @@ -2630,7 +2698,7 @@ const double x = (double)i * dx; profile->data[i] = x < 0.5 ? 1.0 : 0.0; } - cpl_tools_add_flops( size ); + cpl_tools_add_flops(size); break; default: /* Only reached if cpl_kernel is extended in error */ @@ -2641,7 +2709,6 @@ } - /*----------------------------------------------------------------------------*/ /** @brief Apply a 1d gaussian fit @@ -2745,99 +2812,96 @@ /*----------------------------------------------------------------------------*/ cpl_error_code -cpl_vector_fit_gaussian(const cpl_vector *x, const cpl_vector *sigma_x, - const cpl_vector *y, const cpl_vector *sigma_y, - cpl_fit_mode fit_pars, - double *x0, double *sigma, double *area, double *offset, - double *mse, double *red_chisq, - cpl_matrix **covariance) +cpl_vector_fit_gaussian(const cpl_vector *x, + const cpl_vector *sigma_x, + const cpl_vector *y, + const cpl_vector *sigma_y, + cpl_fit_mode fit_pars, + double *x0, + double *sigma, + double *area, + double *offset, + double *mse, + double *red_chisq, + cpl_matrix **covariance) { - cpl_matrix *x_matrix = NULL; /* LM algorithm needs a matrix, + cpl_matrix *x_matrix = NULL; /* LM algorithm needs a matrix, not a vector */ - cpl_size N; /* Number of data points */ - double xlo, xhi; /* Min/max x */ + cpl_size N; /* Number of data points */ + double xlo, xhi; /* Min/max x */ /* Initial parameter values */ - double x0_guess = 0; /* Avoid warnings about uninitialized variables */ + double x0_guess = 0; /* Avoid warnings about uninitialized variables */ double sigma_guess = 0; double area_guess; double offset_guess; /* Validate input */ - cpl_ensure_code( x != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code( sigma_x == NULL, CPL_ERROR_UNSUPPORTED_MODE); - cpl_ensure_code( y != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(x != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(sigma_x == NULL, CPL_ERROR_UNSUPPORTED_MODE); + cpl_ensure_code(y != NULL, CPL_ERROR_NULL_INPUT); /* sigma_y may be NULL or non-NULL */ /* Bits in 'fit_pars' must be non-empty subset of bits in 'CPL_FIT_ALL' */ - cpl_ensure_code( fit_pars != 0 && - (CPL_FIT_ALL | fit_pars) == CPL_FIT_ALL, - CPL_ERROR_INVALID_TYPE); + cpl_ensure_code(fit_pars != 0 && (CPL_FIT_ALL | fit_pars) == CPL_FIT_ALL, + CPL_ERROR_INVALID_TYPE); N = cpl_vector_get_size(x); - cpl_ensure_code( N == cpl_vector_get_size(y), - CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_ensure_code(N == cpl_vector_get_size(y), CPL_ERROR_INCOMPATIBLE_INPUT); - if (sigma_x != NULL) - { - cpl_ensure_code( N == cpl_vector_get_size(sigma_x), - CPL_ERROR_INCOMPATIBLE_INPUT); + if (sigma_x != NULL) { + cpl_ensure_code(N == cpl_vector_get_size(sigma_x), + CPL_ERROR_INCOMPATIBLE_INPUT); } - if (sigma_y != NULL) - { - cpl_ensure_code( N == cpl_vector_get_size(sigma_y), - CPL_ERROR_INCOMPATIBLE_INPUT); + if (sigma_y != NULL) { + cpl_ensure_code(N == cpl_vector_get_size(sigma_y), + CPL_ERROR_INCOMPATIBLE_INPUT); } - cpl_ensure_code( x0 != NULL && - sigma != NULL && - area != NULL && - offset != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(x0 != NULL && sigma != NULL && area != NULL && + offset != NULL, + CPL_ERROR_NULL_INPUT); - if (! (fit_pars & CPL_FIT_STDEV)) - { - cpl_ensure_code( *sigma > 0, CPL_ERROR_ILLEGAL_INPUT); + if (!(fit_pars & CPL_FIT_STDEV)) { + cpl_ensure_code(*sigma > 0, CPL_ERROR_ILLEGAL_INPUT); } - if (! (fit_pars & CPL_FIT_AREA)) - { - cpl_ensure_code( *area > 0, CPL_ERROR_ILLEGAL_INPUT); + if (!(fit_pars & CPL_FIT_AREA)) { + cpl_ensure_code(*area > 0, CPL_ERROR_ILLEGAL_INPUT); } /* mse, red_chisq may be NULL */ /* Need more than number_of_parameters points to calculate chi^2. * There are less than 5 parameters. */ - cpl_ensure_code( red_chisq == NULL || N >= 5, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(red_chisq == NULL || N >= 5, CPL_ERROR_ILLEGAL_INPUT); - if (covariance != NULL) *covariance = NULL; + if (covariance != NULL) + *covariance = NULL; /* If covariance computation is requested, then * return either the covariance matrix or NULL * (don't return undefined pointer). */ /* Cannot compute chi square & covariance without sigma_y */ - cpl_ensure_code( (red_chisq == NULL && covariance == NULL) || - sigma_y != NULL, - CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_ensure_code((red_chisq == NULL && covariance == NULL) || + sigma_y != NULL, + CPL_ERROR_INCOMPATIBLE_INPUT); /* Create (non-modified) matrix from x-data */ -CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); - x_matrix = cpl_matrix_wrap(N, 1, (double*)cpl_vector_get_data_const(x)); -CPL_DIAG_PRAGMA_POP; - if (x_matrix == NULL) - { + CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); + x_matrix = cpl_matrix_wrap(N, 1, (double *)cpl_vector_get_data_const(x)); + CPL_DIAG_PRAGMA_POP; + if (x_matrix == NULL) { return cpl_error_set_(CPL_ERROR_ILLEGAL_OUTPUT); } /* Check that any provided sigmas are positive. */ - if (sigma_x != NULL && cpl_vector_get_min(sigma_x) <= 0) - { + if (sigma_x != NULL && cpl_vector_get_min(sigma_x) <= 0) { cpl_matrix_unwrap(x_matrix); return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); } - if (sigma_y != NULL && cpl_vector_get_min(sigma_y) <= 0) - { + if (sigma_y != NULL && cpl_vector_get_min(sigma_y) <= 0) { cpl_matrix_unwrap(x_matrix); return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); } @@ -2847,90 +2911,80 @@ * but for simplicity do not) */ { - double sum = 0.0; - double quartile[3]; - double fraction[3] = {0.25 , 0.50 , 0.75}; - const double *y_data = cpl_vector_get_data_const(y); - - if (fit_pars & CPL_FIT_OFFSET) - { - /* Estimate offset as 25% percentile of y-values. + double sum = 0.0; + double quartile[3]; + double fraction[3] = { 0.25, 0.50, 0.75 }; + const double *y_data = cpl_vector_get_data_const(y); + + if (fit_pars & CPL_FIT_OFFSET) { + /* Estimate offset as 25% percentile of y-values. (The minimum value may be too low for noisy input, the median is too high if there is not much background in the supplied data, so use something inbetween). */ - cpl_vector *y_dup = cpl_vector_duplicate(y); + cpl_vector *y_dup = cpl_vector_duplicate(y); - if (y_dup == NULL) - { - cpl_matrix_unwrap(x_matrix); - return cpl_error_set_(CPL_ERROR_ILLEGAL_OUTPUT); + if (y_dup == NULL) { + cpl_matrix_unwrap(x_matrix); + return cpl_error_set_(CPL_ERROR_ILLEGAL_OUTPUT); } - offset_guess = cpl_tools_get_kth_double( - cpl_vector_get_data(y_dup), N, N/4); + offset_guess = + cpl_tools_get_kth_double(cpl_vector_get_data(y_dup), N, N / 4); - cpl_vector_delete(y_dup); + cpl_vector_delete(y_dup); } - else - { - offset_guess = *offset; + else { + offset_guess = *offset; } - /* Get quartiles of distribution + /* Get quartiles of distribution (only bother if it's needed for estimation of x0 or sigma) */ - if ( (fit_pars & CPL_FIT_CENTROID) || - (fit_pars & CPL_FIT_STDEV ) - ) - { - /* The algorithm requires the input to be sorted + if ((fit_pars & CPL_FIT_CENTROID) || (fit_pars & CPL_FIT_STDEV)) { + /* The algorithm requires the input to be sorted as function of x, so do that (using qsort), and work on the sorted copy. Of course, the y-vector must be re-ordered along with x. sigma_x and sigma_y are not used, so don't copy those. */ - cpl_vector_fit_gaussian_input - *sorted_input = cpl_malloc((size_t)N * sizeof(*sorted_input)); - double *x_data = cpl_matrix_get_data(x_matrix); - cpl_boolean is_sorted = CPL_TRUE; - cpl_size i; + cpl_vector_fit_gaussian_input *sorted_input = + cpl_malloc((size_t)N * sizeof(*sorted_input)); + double *x_data = cpl_matrix_get_data_(x_matrix); + cpl_boolean is_sorted = CPL_TRUE; + cpl_size i; - if (sorted_input == NULL) - { - cpl_matrix_unwrap(x_matrix); - return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); + if (sorted_input == NULL) { + cpl_matrix_unwrap(x_matrix); + return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); } - for (i = 0; i < N; i++) - { - sorted_input[i].x = x_data[i]; - sorted_input[i].y = y_data[i]; + for (i = 0; i < N; i++) { + sorted_input[i].x = x_data[i]; + sorted_input[i].y = y_data[i]; - is_sorted = is_sorted && - (i==0 || (x_data[i-1] < x_data[i])); + is_sorted = + is_sorted && (i == 0 || (x_data[i - 1] < x_data[i])); } - /* For efficiency, sort only if necessary. This is to + /* For efficiency, sort only if necessary. This is to * keep the asymptotic time complexity at O(n) if the * input was already sorted. (Otherwise the time * complexity is dominated by the following qsort call.) */ - if (!is_sorted) - { - qsort(sorted_input, (size_t)N, sizeof(*sorted_input), - &cpl_fit_gaussian_1d_compare); + if (!is_sorted) { + qsort(sorted_input, (size_t)N, sizeof(*sorted_input), + &cpl_fit_gaussian_1d_compare); } - for(i = 0; i < N; i++) - { - double flux = sorted_input[i].y; + for (i = 0; i < N; i++) { + double flux = sorted_input[i].y; - sum += (flux - offset_guess); + sum += (flux - offset_guess); } - /* Note that 'sum' must be calculated the same way as + /* Note that 'sum' must be calculated the same way as 'running_sum' below, Otherwise (due to round-off error) 'running_sum' might end up being different from 'sum'(!). Specifically, it will not work to calculate 'sum' as @@ -2938,203 +2992,185 @@ (flux1 + ... + fluxN) - N*offset_guess */ - if (sum > 0.0) - { - double flux, x1, x2; - double running_sum = 0.0; - cpl_size j; - - i = 0; - flux = sorted_input[i].y - offset_guess; - - for (j = 0; j < 3; j++) - { - double limit = fraction[j] * sum; - double k; - - while (running_sum + flux < limit && i < N-1) - { - running_sum += flux; - i++; - flux = sorted_input[i].y - offset_guess; + if (sum > 0.0) { + double flux, x1, x2; + double running_sum = 0.0; + cpl_size j; + + i = 0; + flux = sorted_input[i].y - offset_guess; + + for (j = 0; j < 3; j++) { + double limit = fraction[j] * sum; + double k; + + while (running_sum + flux < limit && i < N - 1) { + running_sum += flux; + i++; + flux = sorted_input[i].y - offset_guess; } - /* Fraction [0;1] of current flux needed + /* Fraction [0;1] of current flux needed to reach the quartile */ - k = (limit - running_sum)/flux; + k = (limit - running_sum) / flux; - if (k <= 0.5) - { - /* Interpolate linearly between + if (k <= 0.5) { + /* Interpolate linearly between current and previous position */ - if (0 < i) - { - x1 = sorted_input[i-1].x; - x2 = sorted_input[i].x; - - quartile[j] = - x1*(0.5-k) + - x2*(0.5+k); - /* + if (0 < i) { + x1 = sorted_input[i - 1].x; + x2 = sorted_input[i].x; + + quartile[j] = x1 * (0.5 - k) + x2 * (0.5 + k); + /* k=0 => quartile = midpoint, k=0.5 => quartile = x2 */ } - else - { - quartile[j] = sorted_input[i].x; + else { + quartile[j] = sorted_input[i].x; } } - else - { - /* Interpolate linearly between + else { + /* Interpolate linearly between current and next position */ - if (i < N-1) - { - x1 = sorted_input[i].x; - x2 = sorted_input[i+1].x; - - quartile[j] = - x1*( 1.5-k) + - x2*(-0.5+k); - /* + if (i < N - 1) { + x1 = sorted_input[i].x; + x2 = sorted_input[i + 1].x; + + quartile[j] = x1 * (1.5 - k) + x2 * (-0.5 + k); + /* k=0.5 => quartile = x1, k=1.0 => quartile = midpoint */ } - else - { - quartile[j] = sorted_input[i].x; + else { + quartile[j] = sorted_input[i].x; } } } } - else - { - /* If there's no flux (sum = 0) then + else { + /* If there's no flux (sum = 0) then set quartiles to something that's not completely insensible. */ - quartile[1] = cpl_matrix_get_mean(x_matrix); + quartile[1] = cpl_matrix_get_mean(x_matrix); - quartile[2] = quartile[1]; - quartile[0] = quartile[2] - 1.0; - /* Then sigma_guess = 1.0 */ + quartile[2] = quartile[1]; + quartile[0] = quartile[2] - 1.0; + /* Then sigma_guess = 1.0 */ } - cpl_free(sorted_input); + cpl_free(sorted_input); } /* x0_guess = median of distribution */ - x0_guess = (fit_pars & CPL_FIT_CENTROID) ? quartile[1] : *x0; + x0_guess = (fit_pars & CPL_FIT_CENTROID) ? quartile[1] : *x0; - /* sigma_guess = median of absolute residuals + /* sigma_guess = median of absolute residuals * * (68% is within 1 sigma, and 50% is within 0.6744 * sigma, => quartile3-quartile1 = 2*0.6744 sigma) */ - sigma_guess = (fit_pars & CPL_FIT_STDEV) ? - (quartile[2] - quartile[0]) / (2*0.6744) : *sigma; - - area_guess = (fit_pars & CPL_FIT_AREA) ? - (cpl_vector_get_max(y) - offset_guess) * CPL_MATH_SQRT2PI * sigma_guess - : *area; - - /* Make sure that the area/sigma are positive number */ - if (area_guess <= 0) area_guess = 1.0; - if (sigma_guess <= 0) sigma_guess = 1.0; + sigma_guess = (fit_pars & CPL_FIT_STDEV) + ? (quartile[2] - quartile[0]) / (2 * 0.6744) + : *sigma; + + area_guess = (fit_pars & CPL_FIT_AREA) + ? (cpl_vector_get_max(y) - offset_guess) * + CPL_MATH_SQRT2PI * sigma_guess + : *area; + + /* Make sure that the area/sigma are positive number */ + if (area_guess <= 0) + area_guess = 1.0; + if (sigma_guess <= 0) + sigma_guess = 1.0; } /* Wrap parameters, fit, unwrap */ { - cpl_vector *a = cpl_vector_new(4); /* There are four parameters */ - int ia[4]; - cpl_error_code ec; + cpl_vector *a = cpl_vector_new(4); /* There are four parameters */ + int ia[4]; + cpl_error_code ec; - if (a == NULL) - { - cpl_matrix_unwrap(x_matrix); - return cpl_error_set_(CPL_ERROR_ILLEGAL_OUTPUT); + if (a == NULL) { + cpl_matrix_unwrap(x_matrix); + return cpl_error_set_(CPL_ERROR_ILLEGAL_OUTPUT); } - cpl_vector_set(a, 0, x0_guess); - cpl_vector_set(a, 1, sigma_guess); - cpl_vector_set(a, 2, area_guess); - cpl_vector_set(a, 3, offset_guess); - - ia[0] = fit_pars & CPL_FIT_CENTROID; - ia[1] = fit_pars & CPL_FIT_STDEV; - ia[2] = fit_pars & CPL_FIT_AREA; - ia[3] = fit_pars & CPL_FIT_OFFSET; - - ec = cpl_fit_lvmq_(x_matrix, NULL, - y, sigma_y, - a, ia, NULL, NULL, gauss, gauss_derivative, - CPL_FIT_LVMQ_TOLERANCE, - CPL_FIT_LVMQ_COUNT, - CPL_FIT_LVMQ_MAXITER, - mse, red_chisq, - covariance); - - cpl_matrix_unwrap(x_matrix); - - /* Check return status of fitting routine */ - if (ec == CPL_ERROR_NONE || - ec == CPL_ERROR_SINGULAR_MATRIX) - { - /* The LM algorithm converged. The computation + cpl_vector_set(a, 0, x0_guess); + cpl_vector_set(a, 1, sigma_guess); + cpl_vector_set(a, 2, area_guess); + cpl_vector_set(a, 3, offset_guess); + + ia[0] = fit_pars & CPL_FIT_CENTROID; + ia[1] = fit_pars & CPL_FIT_STDEV; + ia[2] = fit_pars & CPL_FIT_AREA; + ia[3] = fit_pars & CPL_FIT_OFFSET; + + ec = cpl_fit_lvmq_(x_matrix, NULL, y, sigma_y, a, ia, NULL, NULL, gauss, + gauss_derivative, CPL_FIT_LVMQ_TOLERANCE, + CPL_FIT_LVMQ_COUNT, CPL_FIT_LVMQ_MAXITER, mse, + red_chisq, covariance); + + cpl_matrix_unwrap(x_matrix); + + /* Check return status of fitting routine */ + if (ec == CPL_ERROR_NONE || ec == CPL_ERROR_SINGULAR_MATRIX) { + /* The LM algorithm converged. The computation * of the covariance matrix might have failed. */ - /* In principle, the LM algorithm might have converged + /* In principle, the LM algorithm might have converged * to a negative sigma (even if the guess value was * positive). Make sure that the returned sigma is positive * (by convention). */ - if (ia[0]) *x0 = cpl_vector_get(a, 0); - if (ia[1]) *sigma = fabs(cpl_vector_get(a, 1)); - if (ia[2]) *area = cpl_vector_get(a, 2); - if (ia[3]) *offset = cpl_vector_get(a, 3); - } - - cpl_vector_delete(a); - - xlo = cpl_vector_get_min(x); - xhi = cpl_vector_get_max(x); - - if (ec == CPL_ERROR_CONTINUE || - !( - xlo <= *x0 && *x0 <= xhi && - 0 < *sigma && *sigma < (xhi - xlo + 1) && - 0 < *area - /* This extra check on the background level makes sense + if (ia[0]) + *x0 = cpl_vector_get(a, 0); + if (ia[1]) + *sigma = fabs(cpl_vector_get(a, 1)); + if (ia[2]) + *area = cpl_vector_get(a, 2); + if (ia[3]) + *offset = cpl_vector_get(a, 3); + } + + cpl_vector_delete(a); + + xlo = cpl_vector_get_min(x); + xhi = cpl_vector_get_max(x); + + if (ec == CPL_ERROR_CONTINUE || + !(xlo <= *x0 && *x0 <= xhi && 0 < *sigma && + *sigma < (xhi - xlo + 1) && 0 < *area + /* This extra check on the background level makes sense iff the input flux is assumed to be positive && *offset > - *area */ - ) - ) - { - /* The LM algorithm did not converge, or it converged to + )) { + /* The LM algorithm did not converge, or it converged to * a non-sensical result. Return the guess parameter values * in order to enable the caller to recover. */ - *x0 = x0_guess; - *sigma = sigma_guess; - *area = area_guess; - *offset = offset_guess; + *x0 = x0_guess; + *sigma = sigma_guess; + *area = area_guess; + *offset = offset_guess; - /* In this case the covariance matrix will not make sense + /* In this case the covariance matrix will not make sense (because the LM algorithm failed), so delete it */ - if (covariance != NULL && *covariance != NULL) - { - cpl_matrix_delete(*covariance); - *covariance = NULL; + if (covariance != NULL && *covariance != NULL) { + cpl_matrix_delete(*covariance); + *covariance = NULL; } - /* Return CPL_ERROR_CONTINUE if the fitting routine failed */ - return cpl_error_set_(CPL_ERROR_CONTINUE); + /* Return CPL_ERROR_CONTINUE if the fitting routine failed */ + return cpl_error_set_(CPL_ERROR_CONTINUE); } } @@ -3151,12 +3187,12 @@ */ /*----------------------------------------------------------------------------*/ -cpl_vector * cpl_vector_new_lss_kernel(double slitw, - double fwhm) +cpl_vector * +cpl_vector_new_lss_kernel(double slitw, double fwhm) { - const double sigma = fwhm * CPL_MATH_SIG_FWHM; - const cpl_size size = 1 + (cpl_size)(5.0 * sigma + 0.5*slitw); - cpl_vector * kernel = cpl_vector_new(size); + const double sigma = fwhm * CPL_MATH_SIG_FWHM; + const cpl_size size = 1 + (cpl_size)(5.0 * sigma + 0.5 * slitw); + cpl_vector *kernel = cpl_vector_new(size); if (cpl_vector_fill_lss_profile_symmetric(kernel, slitw, fwhm)) { @@ -3178,16 +3214,17 @@ */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_vector_convolve_symmetric(cpl_vector * smoothed, - const cpl_vector * conv_kernel) +cpl_error_code +cpl_vector_convolve_symmetric(cpl_vector *smoothed, + const cpl_vector *conv_kernel) { - cpl_size nsamples; - cpl_size ihwidth; - cpl_vector * raw; - double * psmoothe; - double * praw; - const double* psymm; - cpl_size i, j; + cpl_size nsamples; + cpl_size ihwidth; + cpl_vector *raw; + double *psmoothe; + double *praw; + const double *psymm; + cpl_size i, j; /* Test entries */ cpl_ensure_code(smoothed, CPL_ERROR_NULL_INPUT); @@ -3196,7 +3233,7 @@ /* Initialise */ nsamples = cpl_vector_get_size(smoothed); ihwidth = cpl_vector_get_size(conv_kernel) - 1; - cpl_ensure_code(ihwidth nsamples-1 ? nsamples - 1 : i+j; - psmoothe[i] += (praw[k]+praw[i-j]) * psymm[j]; + for (j = 1; j <= ihwidth; j++) { + const cpl_size k = i + j > nsamples - 1 ? nsamples - 1 : i + j; + psmoothe[i] += (praw[k] + praw[i - j]) * psymm[j]; } } cpl_vector_delete(raw); @@ -3243,11 +3280,11 @@ */ /*----------------------------------------------------------------------------*/ -inline -static double cpl_erf_antideriv(double x, double sigma) +inline static double +cpl_erf_antideriv(double x, double sigma) { - return x * erf( x / (sigma * CPL_MATH_SQRT2)) - + 2.0 * sigma/CPL_MATH_SQRT2PI * exp(-0.5 * x * x / (sigma * sigma)); + return x * erf(x / (sigma * CPL_MATH_SQRT2)) + + 2.0 * sigma / CPL_MATH_SQRT2PI * exp(-0.5 * x * x / (sigma * sigma)); } /*----------------------------------------------------------------------------*/ @@ -3272,40 +3309,42 @@ - CPL_ERROR_ILLEGAL_INPUT if the slit width or fwhm is non-positive */ /*----------------------------------------------------------------------------*/ -static cpl_error_code cpl_vector_fill_lss_profile_symmetric(cpl_vector * self, - double slitw, - double fwhm) +static cpl_error_code +cpl_vector_fill_lss_profile_symmetric(cpl_vector *self, + double slitw, + double fwhm) { - - const double sigma = fwhm * CPL_MATH_SIG_FWHM; - const cpl_size n = cpl_vector_get_size(self); - cpl_size i; + const double sigma = fwhm * CPL_MATH_SIG_FWHM; + const cpl_size n = cpl_vector_get_size(self); + cpl_size i; cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(slitw > 0.0, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(fwhm > 0.0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(slitw > 0.0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(fwhm > 0.0, CPL_ERROR_ILLEGAL_INPUT); /* Cannot fail now */ /* Special case for i = 0 */ (void)cpl_vector_set(self, 0, - (cpl_erf_antideriv(0.5*slitw + 0.5, sigma) - - cpl_erf_antideriv(0.5*slitw - 0.5, sigma)) / slitw); + (cpl_erf_antideriv(0.5 * slitw + 0.5, sigma) - + cpl_erf_antideriv(0.5 * slitw - 0.5, sigma)) / + slitw); for (i = 1; i < n; i++) { /* FIXME: Reuse two cpl_erf_antideriv() calls from previous value */ - 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 * + 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 * (cpl_erf_antideriv(x1p, sigma) - cpl_erf_antideriv(x1n, sigma) - cpl_erf_antideriv(x0p, sigma) + cpl_erf_antideriv(x0n, sigma)); (void)cpl_vector_set(self, i, val); } - cpl_tools_add_flops( 24 * n ); + cpl_tools_add_flops(24 * n); return CPL_ERROR_NONE; } @@ -3320,14 +3359,16 @@ qsort(). */ /*----------------------------------------------------------------------------*/ -static int cpl_fit_gaussian_1d_compare(const void *left, - const void *right) +static int +cpl_fit_gaussian_1d_compare(const void *left, const void *right) { - return - (((const cpl_vector_fit_gaussian_input *)left )->x < - ((const cpl_vector_fit_gaussian_input *)right)->x) ? -1 : - (((const cpl_vector_fit_gaussian_input *)left )->x == - ((const cpl_vector_fit_gaussian_input *)right)->x) ? 0 : 1; + return (((const cpl_vector_fit_gaussian_input *)left)->x < + ((const cpl_vector_fit_gaussian_input *)right)->x) + ? -1 + : (((const cpl_vector_fit_gaussian_input *)left)->x == + ((const cpl_vector_fit_gaussian_input *)right)->x) + ? 0 + : 1; } /*----------------------------------------------------------------------------*/ @@ -3346,33 +3387,34 @@ - CPL_ERROR_ILLEGAL_INPUT if hw is negative */ /*----------------------------------------------------------------------------*/ -static cpl_vector * cpl_vector_gen_lowpass_kernel( - cpl_lowpass filt_type, - cpl_size hw) -{ - cpl_vector * kernel; - double norm; - cpl_size i; +static cpl_vector * +cpl_vector_gen_lowpass_kernel(cpl_lowpass filt_type, cpl_size hw) +{ + cpl_vector *kernel; + double norm; + cpl_size i; cpl_ensure(hw >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL); /* Create the kernel */ - kernel = cpl_vector_new(2*hw+1); - switch(filt_type) { + kernel = cpl_vector_new(2 * hw + 1); + switch (filt_type) { case CPL_LOWPASS_LINEAR: /* flat kernel */ - for (i=-hw; i<=hw; i++) kernel->data[hw+i] = 1.0/(double)(2*hw+1); + for (i = -hw; i <= hw; i++) + kernel->data[hw + i] = 1.0 / (double)(2 * hw + 1); break; case CPL_LOWPASS_GAUSSIAN: norm = 0.00; - for (i=-hw; i < 1 + hw; i++) { + for (i = -hw; i < 1 + hw; i++) { /* gaussian kernel */ - kernel->data[hw+i] = exp(-(double)(i*i)); - norm += kernel->data[hw+i]; + kernel->data[hw + i] = exp(-(double)(i * i)); + norm += kernel->data[hw + i]; } - for (i = 0; i<2*hw+1; i++) kernel->data[i] /= norm; - cpl_tools_add_flops(2*hw*4); + for (i = 0; i < 2 * hw + 1; i++) + kernel->data[i] /= norm; + cpl_tools_add_flops(2 * hw * 4); break; default: /* Only reached if cpl_lowpass is extended in error */ @@ -3392,7 +3434,8 @@ */ /*----------------------------------------------------------------------------*/ -static double cpl_tools_sinc(double x) +static double +cpl_tools_sinc(double x) { const double xpi = x * CPL_MATH_PI; @@ -3413,23 +3456,24 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_vector_fill_alpha_kernel(cpl_vector * profile, double dx, - double alpha) +static void +cpl_vector_fill_alpha_kernel(cpl_vector *profile, double dx, double alpha) { - cpl_size i; - assert( profile ); + assert(profile); for (i = 0; i < profile->size; i++) { const double x = (double)i * dx; - if (x >= 1) break; - profile->data[i] = (alpha + (1.0 - alpha) * cos (x * CPL_MATH_PI)) - * cpl_tools_sinc(x); + if (x >= 1) + break; + profile->data[i] = + (alpha + (1.0 - alpha) * cos(x * CPL_MATH_PI)) * cpl_tools_sinc(x); } - cpl_tools_add_flops( 5 * i ); - for (; i < profile->size; i++) profile->data[i] = 0; + cpl_tools_add_flops(5 * i); + for (; i < profile->size; i++) + profile->data[i] = 0; return; } @@ -3460,17 +3504,18 @@ #ifndef CPL_KERNEL_TANH_STEEPNESS #define CPL_KERNEL_TANH_STEEPNESS 5 #endif -#define CPL_hk_gen(x,s) (((tanh(s*(x+0.5))+1)/2)*((tanh(s*(-x+0.5))+1)/2)) -static cpl_error_code cpl_vector_fill_tanh_kernel(cpl_vector * profile, - double width) +#define CPL_hk_gen(x, s) \ + (((tanh(s * (x + 0.5)) + 1) / 2) * ((tanh(s * (-x + 0.5)) + 1) / 2)) +static cpl_error_code +cpl_vector_fill_tanh_kernel(cpl_vector *profile, double width) { - double * x; + double *x; const cpl_size np = 32768; /* Hardcoded: should never be changed */ - const double inv_np = 2.0 / (double)np; - const double steep = CPL_KERNEL_TANH_STEEPNESS; - double ind; + const double inv_np = 2.0 / (double)np; + const double steep = CPL_KERNEL_TANH_STEEPNESS; + double ind; const cpl_size samples = cpl_vector_get_size(profile); - cpl_size i; + cpl_size i; cpl_ensure_code(profile != NULL, CPL_ERROR_NULL_INPUT); @@ -3485,16 +3530,16 @@ * with a correct frequency ordering to allow standard FT */ - x = cpl_malloc((2*np+1)*sizeof(double)); - for (i = 0; i < np/2; i++) { - ind = (double)i * width * inv_np; - x[2*i] = CPL_hk_gen(ind, steep); - x[2*i+1] = 0; - } - for (i=np/2; idata[i] = width * x[2*i] * inv_np; + profile->data[i] = width * x[2 * i] * inv_np; } cpl_free(x); - cpl_tools_add_flops( (13 * np + samples * 4)/2 ); + cpl_tools_add_flops((13 * np + samples * 4) / 2); return CPL_ERROR_NONE; } @@ -3522,22 +3567,26 @@ not try to understand the implementation and DO NOT MODIFY THIS FUNCTION. */ /*----------------------------------------------------------------------------*/ -#define CPL_KERNEL_SW(a,b) tempr=(a);(a)=(b);(b)=tempr -static void cpl_vector_reverse_tanh_kernel(double * data, cpl_size nn) -{ - unsigned long n, mmax, m, i, j, istep; - double wtemp, wr, wpr, wpi, wi, theta; - double tempr, tempi; +#define CPL_KERNEL_SW(a, b) \ + tempr = (a); \ + (a) = (b); \ + (b) = tempr +static void +cpl_vector_reverse_tanh_kernel(double *data, cpl_size nn) +{ + unsigned long n, mmax, m, i, j, istep; + double wtemp, wr, wpr, wpi, wi, theta; + double tempr, tempi; n = (unsigned long)nn << 1; j = 1; - for (i=1; i i) { - CPL_KERNEL_SW(data[j-1],data[i-1]); - CPL_KERNEL_SW(data[j],data[i]); + CPL_KERNEL_SW(data[j - 1], data[i - 1]); + CPL_KERNEL_SW(data[j], data[i]); } m = n >> 1; - while (m>=2 && j>m) { + while (m >= 2 && j > m) { j -= m; m >>= 1; } @@ -3550,17 +3599,17 @@ wtemp = sin(0.5 * theta); wpr = -2.0 * wtemp * wtemp; wpi = sin(theta); - wr = 1.0; - wi = 0.0; - for (m=1; mpart; - cpl_matrix *alpha = pwork->alpha; - cpl_matrix *beta = pwork->beta; - double *alpha_data = pwork->dalpha; - double *beta_data = pwork->dbeta; + double *partials = pwork->part; + cpl_matrix *alpha = pwork->alpha; + cpl_matrix *beta = pwork->beta; + double *alpha_data = pwork->dalpha; + double *beta_data = pwork->dbeta; /* Number of non-constant fit parameters */ - const cpl_size Mfit = pwork->Mfit; - const cpl_size Mallfree = pwork->Mallfree; + const cpl_size Mfit = pwork->Mfit; + const cpl_size Mallfree = pwork->Mallfree; cpl_size i, imfit; /* For efficiency, don't check input in this static function */ @@ -202,24 +209,27 @@ for (cpl_size k = 0; k < N; k++) { double fx_k; /* f(x_k), y_k - f(x_k) */ const double sm2 = sigma == NULL /* (sigma_k)^-2 */ - ? 1.0 : 1.0 / (sigma[k] * sigma[k]); + ? 1.0 + : 1.0 / (sigma[k] * sigma[k]); int retval; /* Evaluate f(x_k) */ retval = f(x + k * D, a, &fx_k); if (retval) { - (void)cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, "f(%g) = %d," - " k=%d/%d", x[k * D], retval, 1+(int)k, - (int)N); + (void)cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, + "f(%g) = %d," + " k=%d/%d", + x[k * D], retval, 1 + (int)k, (int)N); return -1; } /* Evaluate (all) df/da (x_k) */ retval = dfda(x + k * D, a, partials); if (retval) { - (void)cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, "f'(%g) = %d," - " k=%d/%d", x[k * D], retval, 1+(int)k, - (int)N); + (void)cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, + "f'(%g) = %d," + " k=%d/%d", + x[k * D], retval, 1 + (int)k, (int)N); return -1; } @@ -237,13 +247,13 @@ for (j = 0, jmfit = 0; j < CPL_MIN(i, Mallfree); j++) { if (ia[j] != 0) { - alpha_data[Mfit * imfit + jmfit++] - += sm2 * partials[i] * partials[j]; + alpha_data[Mfit * imfit + jmfit++] += + sm2 * partials[i] * partials[j]; } } for (; j < i; j++) { - alpha_data[Mfit * imfit + jmfit++] - += sm2 * partials[i] * partials[j]; + alpha_data[Mfit * imfit + jmfit++] += + sm2 * partials[i] * partials[j]; } /* Alpha, diagonal terms */ @@ -260,13 +270,13 @@ for (j = 0, jmfit = 0; j < CPL_MIN(i, Mallfree); j++) { if (ia[j] != 0) { - alpha_data[Mfit * imfit + jmfit++] - += sm2 * partials[i] * partials[j]; + alpha_data[Mfit * imfit + jmfit++] += + sm2 * partials[i] * partials[j]; } } for (; j < i; j++) { - alpha_data[Mfit * imfit + jmfit++] - += sm2 * partials[i] * partials[j]; + alpha_data[Mfit * imfit + jmfit++] += + sm2 * partials[i] * partials[j]; } /* Alpha, diagonal terms */ @@ -275,7 +285,7 @@ imfit++; } - assert( imfit == Mfit ); + assert(imfit == Mfit); } /* Because alpha is the product of J^T * J (where J is assumed to have full @@ -286,7 +296,7 @@ imfit = 0; for (i = 0; i < Mallfree; i++) { if (ia[i] != 0) { - cpl_size j, jmfit = imfit+1; + cpl_size j, jmfit = imfit + 1; for (j = i + 1; j < Mallfree; j++) { if (ia[j] != 0) { @@ -302,25 +312,24 @@ jmfit++; } - assert( jmfit == Mfit ); + assert(jmfit == Mfit); imfit++; } } for (; i < M; i++) { - cpl_size j, jmfit = imfit+1; + cpl_size j, jmfit = imfit + 1; for (j = i + 1; j < M; j++) { - alpha_data[Mfit * imfit + jmfit] = - alpha_data[Mfit * jmfit + imfit]; + alpha_data[Mfit * imfit + jmfit] = alpha_data[Mfit * jmfit + imfit]; jmfit++; } - assert( jmfit == Mfit ); + assert(jmfit == Mfit); imfit++; } - assert( imfit == Mfit ); + assert(imfit == Mfit); /* Solution of alpha * da = beta */ /* This will overwrite alpha with its Cholesky factorization */ @@ -339,7 +348,8 @@ if (ia[i] != 0) { *pbsq2n += beta_data[imfit] * beta_data[imfit]; a_da[i] = a[i] + beta_data[imfit++]; - } else { + } + else { a_da[i] = a[i]; } *pasq2n += a_da[i] * a_da[i]; @@ -349,42 +359,47 @@ a_da[i] = a[i] + beta_data[imfit++]; *pasq2n += a_da[i] * a_da[i]; } - assert( imfit == Mfit ); + assert(imfit == Mfit); #if defined CPL_VECTOR_LVMQ_DIAG && CPL_VECTOR_LVMQ_DIAG > 2 switch (Mfit) { - case 1: - cpl_msg_info(cpl_func, "LVMQ-BETA(%d<%d:lambda=%g): %g", - (int)Mfit, (int)M, lambda, beta_data[0]); - break; - case 2: - cpl_msg_info(cpl_func, "LVMQ-BETA(%d<%d:lambda=%g): %g %g", - (int)Mfit, (int)M, lambda, beta_data[0], beta_data[1]); - break; - case 3: - cpl_msg_info(cpl_func, "LVMQ-BETA(%d<%d:lambda=%g): %g %g %g", - (int)Mfit, (int)M, lambda, beta_data[0], beta_data[1], beta_data[2]); - break; - case 4: - cpl_msg_info(cpl_func, "LVMQ-BETA(%d<%d:lambda=%g): %g %g %g %g", - (int)Mfit, (int)M, lambda, beta_data[0], beta_data[1], beta_data[2], - beta_data[3]); - break; - case 5: - cpl_msg_info(cpl_func, "LVMQ-BETA(%d<%d:lambda=%g): %g %g %g %g %g", - (int)Mfit, (int)M, lambda, beta_data[0], beta_data[1], beta_data[2], - beta_data[3], beta_data[4]); - break; - case 6: - cpl_msg_info(cpl_func, "LVMQ-BETA(%d<%d:lambda=%g): %g %g %g %g %g %g", - (int)Mfit, (int)M, lambda, beta_data[0], beta_data[1], beta_data[2], - beta_data[3], beta_data[4], beta_data[5]); - break; - default: - cpl_msg_info(cpl_func, "LVMQ-BETA(%d<%d:lambda=%g): %g %g %g %g %g %g %g", - (int)Mfit, (int)M, lambda, beta_data[0], beta_data[1], beta_data[2], - beta_data[3], beta_data[4], beta_data[5], beta_data[6]); - break; + case 1: + cpl_msg_info(cpl_func, "LVMQ-BETA(%d<%d:lambda=%g): %g", (int)Mfit, + (int)M, lambda, beta_data[0]); + break; + case 2: + cpl_msg_info(cpl_func, "LVMQ-BETA(%d<%d:lambda=%g): %g %g", + (int)Mfit, (int)M, lambda, beta_data[0], beta_data[1]); + break; + case 3: + cpl_msg_info(cpl_func, "LVMQ-BETA(%d<%d:lambda=%g): %g %g %g", + (int)Mfit, (int)M, lambda, beta_data[0], beta_data[1], + beta_data[2]); + break; + case 4: + cpl_msg_info(cpl_func, "LVMQ-BETA(%d<%d:lambda=%g): %g %g %g %g", + (int)Mfit, (int)M, lambda, beta_data[0], beta_data[1], + beta_data[2], beta_data[3]); + break; + case 5: + cpl_msg_info(cpl_func, "LVMQ-BETA(%d<%d:lambda=%g): %g %g %g %g %g", + (int)Mfit, (int)M, lambda, beta_data[0], beta_data[1], + beta_data[2], beta_data[3], beta_data[4]); + break; + case 6: + cpl_msg_info(cpl_func, + "LVMQ-BETA(%d<%d:lambda=%g): %g %g %g %g %g %g", + (int)Mfit, (int)M, lambda, beta_data[0], beta_data[1], + beta_data[2], beta_data[3], beta_data[4], + beta_data[5]); + break; + default: + cpl_msg_info(cpl_func, + "LVMQ-BETA(%d<%d:lambda=%g): %g %g %g %g %g %g %g", + (int)Mfit, (int)M, lambda, beta_data[0], beta_data[1], + beta_data[2], beta_data[3], beta_data[4], beta_data[5], + beta_data[6]); + break; } #endif @@ -415,14 +430,15 @@ /*----------------------------------------------------------------------------*/ inline static double -get_chisq(cpl_size N, cpl_size D, - int (*f)(const double x[], const double a[], double *result), - const double *a, - const double *x, - const double *y, - const double *sigma) +get_chisq(cpl_size N, + cpl_size D, + int (*f)(const double x[], const double a[], double *result), + const double *a, + const double *x, + const double *y, + const double *sigma) { - double chi_sq = 0.0; /* Result */ + double chi_sq = 0.0; /* Result */ /* For efficiency, don't check input in this static function */ @@ -432,15 +448,17 @@ const int retval = f(x + i * D, a, &fx_i); if (retval != 0) { - (void)cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, "f(%g) = %d, " - "i=%d/%d X %d", x[i * D], retval, - 1+(int)i, (int)N, (int)D); + (void)cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, + "f(%g) = %d, " + "i=%d/%d X %d", + x[i * D], retval, 1 + (int)i, (int)N, + (int)D); return -1.0; - } else { + } + else { /* Residual in units of uncertainty */ - const double residual = sigma != NULL - ? (fx_i - y[i]) / sigma[i] - : (fx_i - y[i]); + const double residual = + sigma != NULL ? (fx_i - y[i]) / sigma[i] : (fx_i - y[i]); /* Accumulate */ chi_sq += residual * residual; @@ -541,51 +559,55 @@ */ /*----------------------------------------------------------------------------*/ inline static cpl_error_code -cpl_fit_lvmq_(const cpl_matrix *x, const cpl_matrix *sigma_x, - const cpl_vector *y, const cpl_vector *sigma_y, - cpl_vector *a, const int ia[], - const cpl_array *lowersan, const cpl_array *uppersan, - int (*f)(const double x[], const double a[], double *result), - int (*dfda)(const double x[], const double a[], double result[]), - double relative_tolerance, - int tolerance_count, - int max_iterations, - double *mse, - double *red_chisq, - cpl_matrix **covariance) +cpl_fit_lvmq_(const cpl_matrix *x, + const cpl_matrix *sigma_x, + const cpl_vector *y, + const cpl_vector *sigma_y, + cpl_vector *a, + const int ia[], + const cpl_array *lowersan, + const cpl_array *uppersan, + int (*f)(const double x[], const double a[], double *result), + int (*dfda)(const double x[], const double a[], double result[]), + double relative_tolerance, + int tolerance_count, + int max_iterations, + double *mse, + double *red_chisq, + cpl_matrix **covariance) { - const double *x_data = NULL; /* Pointer to input data */ - const double *y_data = NULL; /* Pointer to input data */ + const double *x_data = NULL; /* Pointer to input data */ + const double *y_data = NULL; /* Pointer to input data */ const double *sigma_data = NULL; /* Pointer to input data */ - cpl_size N = 0; /* Number of data points */ - cpl_size D = 0; /* Dimension of x-points */ + cpl_size N = 0; /* Number of data points */ + cpl_size D = 0; /* Dimension of x-points */ cpl_size M = 0; /* Number of fit parameters */ cpl_size Mfit = 0; /* Number of non-constant fit parameters */ - double lambda = 0.0; /* Lambda in L-M algorithm */ - double MAXLAMBDA = 10e40; /* Parameter to control the graceful exit + double lambda = 0.0; /* Lambda in L-M algorithm */ + double MAXLAMBDA = 10e40; /* Parameter to control the graceful exit if steepest descent unexpectedly fails */ - double chi_sq = 0.0; /* Current chi^2 */ - int count = 0; /* Number of successive small improvements + double chi_sq = 0.0; /* Current chi^2 */ + int count = 0; /* Number of successive small improvements in chi^2 */ - int iterations = 0; + int iterations = 0; - cpl_matrix *alpha = NULL; /* The MxM ~curvature matrix used in L-M */ - cpl_ifalloc mybuf; /* Buffer for work space */ + cpl_matrix *alpha = NULL; /* The MxM ~curvature matrix used in L-M */ + cpl_ifalloc mybuf; /* Buffer for work space */ cpl_fit_work work; /* Mx1 matrix = -.5 grad(chi^2) */ - double *a_data = NULL; /* Parameters, a */ - double *a_da = NULL; /* Candidate position a+da */ - double *a_keep = NULL; /* Points to the a_da to keep */ - double *part = NULL; /* The partial derivatives df/da */ + double *a_data = NULL; /* Parameters, a */ + double *a_da = NULL; /* Candidate position a+da */ + double *a_keep = NULL; /* Points to the a_da to keep */ + double *part = NULL; /* The partial derivatives df/da */ cpl_boolean fit_all = CPL_FALSE; /* True iff all parameters are fitted */ const int *ia_local = ia; /* non-NULL version of ia */ const cpl_boolean check_sanity = lowersan != NULL ? CPL_TRUE : CPL_FALSE; - double asq2n = 0.0; - double bsq2n = 0.0; + double asq2n = 0.0; + double bsq2n = 0.0; #ifdef CPL_VECTOR_LVMQ_DIAG - double chi_sq_diff = 0.0; - double betamax = 0.0; + double chi_sq_diff = 0.0; + double betamax = 0.0; #endif cpl_boolean didconverge = CPL_FALSE; @@ -593,27 +615,28 @@ /* If covariance computation is requested, then either * return the covariance matrix or return NULL. */ - if (covariance != NULL) *covariance = NULL; + if (covariance != NULL) + *covariance = NULL; /* Validate input */ - cpl_ensure_code(x != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(x != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(sigma_x == NULL, CPL_ERROR_UNSUPPORTED_MODE); - cpl_ensure_code(y != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(a != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(y != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(a != NULL, CPL_ERROR_NULL_INPUT); /* ia may be NULL */ - cpl_ensure_code(f != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(dfda != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(f != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(dfda != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(relative_tolerance > 0, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(tolerance_count > 0, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(max_iterations > 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(tolerance_count > 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(max_iterations > 0, CPL_ERROR_ILLEGAL_INPUT); /* Chi^2 and covariance computations require sigmas to be known */ - cpl_ensure_code( sigma_y != NULL || - (red_chisq == NULL && covariance == NULL), - CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_ensure_code(sigma_y != NULL || + (red_chisq == NULL && covariance == NULL), + CPL_ERROR_INCOMPATIBLE_INPUT); - D = cpl_matrix_get_ncol(x); - N = cpl_matrix_get_nrow(x); + D = cpl_matrix_get_ncol_(x); + N = cpl_matrix_get_nrow_(x); M = cpl_vector_get_size_(a); cpl_ensure_code(N > 0, CPL_ERROR_ILLEGAL_INPUT); cpl_ensure_code(D > 0, CPL_ERROR_ILLEGAL_INPUT); @@ -629,14 +652,14 @@ CPL_ERROR_ILLEGAL_INPUT); cpl_ensure_code(cpl_array_get_type(uppersan) == CPL_TYPE_DOUBLE, CPL_ERROR_ILLEGAL_INPUT); - } else { + } + else { cpl_ensure_code(uppersan == NULL, CPL_ERROR_NULL_INPUT); } - cpl_ensure_code( cpl_vector_get_size_(y) == N, - CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_ensure_code(cpl_vector_get_size_(y) == N, CPL_ERROR_INCOMPATIBLE_INPUT); - x_data = cpl_matrix_get_data_const(x); + x_data = cpl_matrix_get_data_const_(x); y_data = cpl_vector_get_data_const_(y); a_data = cpl_vector_get_data_(a); @@ -646,12 +669,14 @@ "Y-sigma length = %d <=> %d", (int)cpl_vector_get_size(sigma_y), (int)N); - } else if (cpl_vector_get_min(sigma_y) <= 0.0) { + } + else if (cpl_vector_get_min(sigma_y) <= 0.0) { const cpl_size minpos = cpl_vector_get_minpos(sigma_y); - return cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, "Y-sigma " + return cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, + "Y-sigma " "minimum = %g <= 0.0 at %d/%d", cpl_vector_get(sigma_y, minpos), - 1+(int)cpl_vector_get_size(sigma_y), + 1 + (int)cpl_vector_get_size(sigma_y), (int)N); } sigma_data = cpl_vector_get_data_const_(sigma_y); @@ -676,11 +701,12 @@ fit_all = Mfit == M ? CPL_TRUE : CPL_FALSE; - if (fit_all) assert(Mallfree == 0); + if (fit_all) + assert(Mallfree == 0); work.Mallfree = Mallfree; - - } else { + } + else { /* All parameters participate */ const size_t sz = (size_t)M * sizeof(*ia_local); @@ -697,8 +723,8 @@ } /* To compute reduced chi^2, we need N > Mfit */ - if (! ( red_chisq == NULL || N > Mfit ) ) - { + if (!(red_chisq == NULL || N > Mfit)) { + cpl_fit_work_delete(&work); return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); } @@ -720,8 +746,7 @@ lambda = 0.001; count = 0; iterations = 0; - if( (chi_sq = get_chisq(N, D, f, a_data, x_data, y_data, sigma_data)) < 0) - { + if ((chi_sq = get_chisq(N, D, f, a_data, x_data, y_data, sigma_data)) < 0) { cpl_fit_work_delete(&work); return cpl_error_set_where_(); } @@ -735,13 +760,12 @@ Each iteration moves towards Newton's algorithm. The iterations counter is a protection against an infinte loop */ for (; iterations < max_iterations; iterations++, lambda /= 10.0) { - /* In each iteration lambda increases, or chi^2 decreases or count increases. Because chi^2 is bounded from below (and lambda and count from above), the loop will terminate */ cpl_errorstate prevstate = cpl_errorstate_get(); - double * a_swap; + double *a_swap; double chi_sq_candidate = 0.0; #if defined CPL_VECTOR_LVMQ_DIAG && CPL_VECTOR_LVMQ_DIAG > 1 const double chi_sq_diff_prev = chi_sq_diff; @@ -764,40 +788,38 @@ /* Try to get a valid candidate a limited number of times - each retry after failure moves towards steepest descent */ - for (; retries < ntries && lambda < MAXLAMBDA; lambda *= 9.0, retries++) { + for (; retries < ntries && lambda < MAXLAMBDA; + lambda *= 9.0, retries++) { /* Reset only error before (re)trying, so also on exhausting the tries errors are propagated */ cpl_errorstate_set(prevstate); - canderror = get_candidate(a_keep, ia_local, - M, N, D, - lambda, f, dfda, - x_data, y_data, sigma_data, - a_da, &asq2n_cand, &bsq2n_cand, &work); + canderror = get_candidate(a_keep, ia_local, M, N, D, lambda, f, + dfda, x_data, y_data, sigma_data, a_da, + &asq2n_cand, &bsq2n_cand, &work); if (!canderror && cpl_errorstate_is_equal(prevstate)) { - - if (check_sanity && cpl_fit_is_sane(a_da, M, lowersan, uppersan)) { #if defined CPL_VECTOR_LVMQ_DIAG && CPL_VECTOR_LVMQ_DIAG > 2 - cpl_msg_warning(cpl_func, "LVMQ-ILLC(N=%d:%d<%d:%d<%d): " - "lambda=%g, ||a||^2 = %g + %g = ||beta||^2 < " - "||beta_prev||^2 = %g/%g (BetaMax=%g), " - "chi_sq(%g) delta: %g (retries=%d)", (int)N, - iterations, max_iterations, count, - tolerance_count, lambda, - asq2n, bsq2n, bsq2n_prev, - relative_tolerance, - didconverge ? 1.0 : (iterations ? - bsq2n / bsq2n_prev : 1.0), - chi_sq, chi_sq_diff, (int)retries); + cpl_msg_warning( + cpl_func, + "LVMQ-ILLC(N=%d:%d<%d:%d<%d): " + "lambda=%g, ||a||^2 = %g + %g = ||beta||^2 < " + "||beta_prev||^2 = %g/%g (BetaMax=%g), " + "chi_sq(%g) delta: %g (retries=%d)", + (int)N, iterations, max_iterations, count, + tolerance_count, lambda, asq2n, bsq2n, bsq2n_prev, + relative_tolerance, + didconverge ? 1.0 + : (iterations ? bsq2n / bsq2n_prev : 1.0), + chi_sq, chi_sq_diff, (int)retries); #endif continue; } /* Get chi^2(a+da) */ - chi_sq_candidate = get_chisq(N, D, f, a_da, x_data, y_data, - sigma_data); + chi_sq_candidate = + get_chisq(N, D, f, a_da, x_data, y_data, sigma_data); /* Check for invalid candidate, including NaN */ if (cpl_errorstate_is_equal(prevstate)) { if (chi_sq_candidate < 0.0 || @@ -830,7 +852,7 @@ /* chi^2 improved, update a and chi^2 */ a_swap = a_keep; a_keep = a_da; - a_da = a_swap; + a_da = a_swap; asq2n = asq2n_cand; bsq2n = bsq2n_cand; @@ -846,12 +868,13 @@ the convergence, i.e. count is 0) */ if ((chi_sq < sqrt(DBL_EPSILON) || -chi_sq_cand_diff < chi_sq * relative_tolerance) && - (count == 0 || (retries < 3 && - (bsq2n < 2.0 * bsq2n_prev || - bsq2n < asq2n * (double)(2< 1 if (count > 0 && - !(bsq2n < asq2n * (double)(2< 0.0 && bsq2n > bsq2n_prev * betamax) betamax = bsq2n / bsq2n_prev; #endif @@ -859,7 +882,8 @@ if (count >= tolerance_count) { didconverge = CPL_TRUE; } - } else { + } + else { /* Chi^2 improved, by a significant amount or in some non-converging manner, so reset counter */ @@ -872,27 +896,30 @@ chi_sq = chi_sq_candidate; #if defined CPL_VECTOR_LVMQ_DIAG && CPL_VECTOR_LVMQ_DIAG > 1 - cpl_msg_info(cpl_func, "LVMQ(%d<%d:%d<%d:%c): lambda=%g, ||a||^2 = %g +" - " %g = ||beta||^2 < ||beta_prev||^2 = %g/%g (BetaMax=%g), " - "chi_sq(%g) delta: %g, conv: %g < %g, ratio: %g (retries=%d)", - iterations, max_iterations, count, tolerance_count, - didconverge ? 'T' : 'F', lambda, - asq2n, bsq2n, bsq2n_prev, - relative_tolerance, - didconverge ? 1.0 : (iterations ? bsq2n / bsq2n_prev : 1.0), - chi_sq, chi_sq_diff, - -chi_sq_cand_diff, chi_sq * relative_tolerance, - chi_sq_diff/chi_sq_diff_prev, retries); + cpl_msg_info( + cpl_func, + "LVMQ(%d<%d:%d<%d:%c): lambda=%g, ||a||^2 = %g +" + " %g = ||beta||^2 < ||beta_prev||^2 = %g/%g (BetaMax=%g), " + "chi_sq(%g) delta: %g, conv: %g < %g, ratio: %g (retries=%d)", + iterations, max_iterations, count, tolerance_count, + didconverge ? 'T' : 'F', lambda, asq2n, bsq2n, bsq2n_prev, + relative_tolerance, + didconverge ? 1.0 : (iterations ? bsq2n / bsq2n_prev : 1.0), chi_sq, + chi_sq_diff, -chi_sq_cand_diff, chi_sq * relative_tolerance, + chi_sq_diff / chi_sq_diff_prev, retries); #endif - if (!didconverge) continue; + if (!didconverge) + continue; /* Convergence ensured */ /* Stop when the step length is at 1 bit/parameter on average + 1/2 machine precision */ - if (bsq2n < asq2n * (double)(2<= bsq2n_prev) break; + if (bsq2n >= bsq2n_prev) + break; } if (a_keep != a_data) { @@ -910,21 +937,24 @@ /* Divergence or get_candidate()/get_chisq() failed in some way */ const cpl_error_code code = cpl_error_get_code() == CPL_ERROR_SINGULAR_MATRIX - ? CPL_ERROR_CONTINUE : cpl_error_get_code(); + ? CPL_ERROR_CONTINUE + : cpl_error_get_code(); cpl_fit_work_delete(&work); return cpl_error_set_message_(code ? code : CPL_ERROR_CONTINUE, "Iteration %d. lambda = %g. ||beta||^2 = " - "%g", (int)iterations, lambda, bsq2n); + "%g", + (int)iterations, lambda, bsq2n); } #ifdef CPL_VECTOR_LVMQ_DIAG - cpl_msg_info(cpl_func, "LVMQ-OK(%d<%d:%d<%d): lambda=%g, ||a||^2 = %g +" - " %g = ||beta||^2 (tol=%g) (BETAMAX=%g), " - "chi_sq(%g) delta: %g, conv: %g", - iterations, max_iterations, count, tolerance_count, lambda, - asq2n, bsq2n, relative_tolerance, betamax, - chi_sq, chi_sq_diff, chi_sq * relative_tolerance); + cpl_msg_info(cpl_func, + "LVMQ-OK(%d<%d:%d<%d): lambda=%g, ||a||^2 = %g +" + " %g = ||beta||^2 (tol=%g) (BETAMAX=%g), " + "chi_sq(%g) delta: %g, conv: %g", + iterations, max_iterations, count, tolerance_count, lambda, + asq2n, bsq2n, relative_tolerance, betamax, chi_sq, chi_sq_diff, + chi_sq * relative_tolerance); #endif /* Compute mse if requested */ @@ -939,9 +969,10 @@ if (retval) { cpl_fit_work_delete(&work); - return cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, "f(%g) " - "= %d, k=%d/%d", x_data[i * D], - retval, 1+(int)i, + return cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, + "f(%g) " + "= %d, k=%d/%d", + x_data[i * D], retval, 1 + (int)i, (int)N); } @@ -954,24 +985,23 @@ /* Compute reduced chi^2 if requested */ if (red_chisq != NULL) { /* We already know the optimal chi^2 (and that N > Mfit)*/ - *red_chisq = chi_sq / (double)(N-Mfit); + *red_chisq = chi_sq / (double)(N - Mfit); } /* Compute covariance matrix if requested * cov = alpha(lambda=0)^-1 */ if (covariance != NULL) { - cpl_matrix *cov = fit_all - ? cpl_matrix_wrap(M, M, cpl_malloc(M * M * sizeof(double))) - : cpl_matrix_wrap(Mfit, Mfit, cpl_malloc(Mfit * Mfit - * sizeof(double))); + cpl_matrix *cov = + fit_all ? cpl_matrix_wrap(M, M, cpl_malloc(M * M * sizeof(double))) + : cpl_matrix_wrap(Mfit, Mfit, + cpl_malloc(Mfit * Mfit * sizeof(double))); *covariance = NULL; - if (get_candidate(a_data, ia_local, - M, N, D, 0.0, f, dfda, - x_data, y_data, sigma_data, - a_da, &asq2n, &bsq2n, &work) != 0) { + if (get_candidate(a_data, ia_local, M, N, D, 0.0, f, dfda, x_data, + y_data, sigma_data, a_da, &asq2n, &bsq2n, + &work) != 0) { cpl_fit_work_delete(&work); cpl_matrix_delete(cov); return cpl_error_set_where_(); @@ -989,7 +1019,7 @@ /* Make sure that variances are positive */ for (cpl_size i = 0; i < Mfit; i++) { - if ( !(cpl_matrix_get(cov, i, i) > 0.0) ) { + if (!(cpl_matrix_get_(cov, i, i) > 0.0)) { cpl_fit_work_delete(&work); cpl_matrix_delete(cov); return cpl_error_set_(CPL_ERROR_SINGULAR_MATRIX); @@ -998,7 +1028,8 @@ if (fit_all) { *covariance = cov; - } else { + } + else { /* Expand covariance matrix from Mfit x Mfit to M x M. Set rows/columns corresponding to fixed parameters to zero */ @@ -1013,17 +1044,17 @@ for (cpl_size i = 0; i < M; i++) if (ia_local[i] != 0) { - cpl_matrix_set(*covariance, i, j, - cpl_matrix_get(cov, imfit, jmfit)); + cpl_matrix_set_(*covariance, i, j, + cpl_matrix_get_(cov, imfit, jmfit)); imfit++; } - assert( imfit == Mfit ); + assert(imfit == Mfit); jmfit++; } } - assert( jmfit == Mfit ); + assert(jmfit == Mfit); cpl_matrix_delete(cov); } } @@ -1045,58 +1076,59 @@ @see cpl_fit_lvmq_(), get_candidate() */ /*----------------------------------------------------------------------------*/ -inline static void cpl_fit_work_set(cpl_fit_work * self, - cpl_ifalloc * pmybuf, - size_t mfit, - size_t mtot, - size_t iasz) +inline static void +cpl_fit_work_set(cpl_fit_work *self, + cpl_ifalloc *pmybuf, + size_t mfit, + size_t mtot, + size_t iasz) { - const size_t size = mfit * (sizeof(double) * (1 + mfit) + sizeof(int)) - + 2 * mtot * sizeof(double) + mtot * sizeof(int) + iasz; + const size_t size = mfit * (sizeof(double) * (1 + mfit) + sizeof(int)) + + 2 * mtot * sizeof(double) + mtot * sizeof(int) + iasz; - double * start; + double *start; #if defined CPL_VECTOR_LVMQ_DIAG && CPL_VECTOR_LVMQ_DIAG > 1 cpl_msg_warning(cpl_func, "LVMQ(%zu<=%zu): %zu <=> %u (%zu)", mfit, mtot, size, CPL_IFALLOC_SZ, iasz); #endif - self->pmybuf = pmybuf; + self->pmybuf = pmybuf; - self->Mfit = mfit; + self->Mfit = mfit; cpl_ifalloc_set(self->pmybuf, size); start = cpl_ifalloc_get(self->pmybuf); - self->a_da = start; + self->a_da = start; - start += mtot; + start += mtot; - self->part = start; + self->part = start; - start += mtot; + start += mtot; /* Alpha and Beta contiguous so single memset() can reset them */ self->dalphabeta = start; - self->dbeta = self->dalphabeta; + self->dbeta = self->dalphabeta; - self->beta = cpl_matrix_wrap(mfit, 1, self->dbeta); + self->beta = cpl_matrix_wrap(mfit, 1, self->dbeta); - start += mfit; + start += mfit; - self->dalpha = start; + self->dalpha = start; - self->alpha = cpl_matrix_wrap(mfit, mfit, self->dalpha); + self->alpha = cpl_matrix_wrap(mfit, mfit, self->dalpha); self->salphabeta = (mfit * mfit + mfit) * sizeof(double); - self->alphabeta = cpl_matrix_wrap(mfit, mfit + 1, self->dalphabeta); + self->alphabeta = cpl_matrix_wrap(mfit, mfit + 1, self->dalphabeta); - start += mfit * mfit; + start += mfit * mfit; - self->ia = iasz != 0 ? (void*)start : NULL; + self->ia = iasz != 0 ? (void *)start : NULL; } /*----------------------------------------------------------------------------*/ @@ -1107,7 +1139,8 @@ @see cpl_fit_work_set() */ /*----------------------------------------------------------------------------*/ -static void cpl_fit_work_delete(cpl_fit_work * self) +static void +cpl_fit_work_delete(cpl_fit_work *self) { cpl_ifalloc_free(self->pmybuf); (void)cpl_matrix_unwrap(self->beta); @@ -1124,14 +1157,15 @@ @return Zero if check is passed */ /*----------------------------------------------------------------------------*/ -static int cpl_fit_is_sane(const double self[], - cpl_size M, - const cpl_array * lowersan, - const cpl_array * uppersan) +static int +cpl_fit_is_sane(const double self[], + cpl_size M, + const cpl_array *lowersan, + const cpl_array *uppersan) { int inv[2]; cpl_boolean is_sane = CPL_TRUE; - + for (cpl_size i = 0; i < M; i++) { const double lower = cpl_array_get_double(lowersan, i, inv); const double upper = cpl_array_get_double(uppersan, i, inv + 1); @@ -1139,12 +1173,14 @@ if (!inv[0] && self[i] < lower) { is_sane = CPL_FALSE; #if defined CPL_VECTOR_LVMQ_DIAG && CPL_VECTOR_LVMQ_DIAG > 2 - cpl_msg_warning(cpl_func, "LVMQ-Lower sanity check failed (%d<%d): " - "%g < %g < %g (%c)", (int)i, (int)M, lower, self[i], - upper, inv[1] ? 'I' : 'V'); + cpl_msg_warning(cpl_func, + "LVMQ-Lower sanity check failed (%d<%d): " + "%g < %g < %g (%c)", + (int)i, (int)M, lower, self[i], upper, + inv[1] ? 'I' : 'V'); #if CPL_VECTOR_LVMQ_DIAG > 3 - cpl_array_dump(lowersan,0, M, stderr); - cpl_array_dump(uppersan,0, M, stderr); + cpl_array_dump(lowersan, 0, M, stderr); + cpl_array_dump(uppersan, 0, M, stderr); #endif #else break; @@ -1153,12 +1189,14 @@ if (!inv[1] && self[i] > upper) { is_sane = CPL_FALSE; #if defined CPL_VECTOR_LVMQ_DIAG && CPL_VECTOR_LVMQ_DIAG > 2 - cpl_msg_warning(cpl_func, "LVMQ-Upper sanity check failed (%d<%d): " - "%g (%c) < %g < %g", (int)i, (int)M, lower, - inv[0] ? 'I' : 'V', self[i], upper); + cpl_msg_warning(cpl_func, + "LVMQ-Upper sanity check failed (%d<%d): " + "%g (%c) < %g < %g", + (int)i, (int)M, lower, inv[0] ? 'I' : 'V', self[i], + upper); #if CPL_VECTOR_LVMQ_DIAG > 3 - cpl_array_dump(lowersan,0, M, stderr); - cpl_array_dump(uppersan,0, M, stderr); + cpl_array_dump(lowersan, 0, M, stderr); + cpl_array_dump(uppersan, 0, M, stderr); #endif #else break; diff -Nru cpl-7.1.4+ds/cplcore/cpl_vector.h cpl-7.2.2+ds/cplcore/cpl_vector.h --- cpl-7.1.4+ds/cplcore/cpl_vector.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_vector.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -44,36 +44,36 @@ /* Suggested resolution of interpolation profile */ #ifndef CPL_KERNEL_TABSPERPIX -#define CPL_KERNEL_TABSPERPIX 1000 +#define CPL_KERNEL_TABSPERPIX 1000 #endif /* Suggested radius of pixel interpolation */ #ifndef CPL_KERNEL_DEF_WIDTH -#define CPL_KERNEL_DEF_WIDTH 2.0 +#define CPL_KERNEL_DEF_WIDTH 2.0 #endif /* Suggested length of interpolation profile */ #define CPL_KERNEL_DEF_SAMPLES \ - (1+(cpl_size)((CPL_KERNEL_TABSPERPIX) * (CPL_KERNEL_DEF_WIDTH))) + (1 + (cpl_size)((CPL_KERNEL_TABSPERPIX) * (CPL_KERNEL_DEF_WIDTH))) /* FIXME: Will disappear. Do not use in new code! */ -#define cpl_wlcalib_xc_convolve_create_kernel \ - cpl_vector_new_lss_kernel -#define cpl_wlcalib_xc_convolve \ - cpl_vector_convolve_symmetric +#define cpl_wlcalib_xc_convolve_create_kernel cpl_vector_new_lss_kernel +#define cpl_wlcalib_xc_convolve cpl_vector_convolve_symmetric /*----------------------------------------------------------------------------- New types -----------------------------------------------------------------------------*/ -typedef enum { +typedef enum +{ CPL_LOWPASS_LINEAR, CPL_LOWPASS_GAUSSIAN } cpl_lowpass; -typedef enum { +typedef enum +{ CPL_KERNEL_TANH, CPL_KERNEL_SINC, CPL_KERNEL_SINC2, @@ -83,18 +83,17 @@ CPL_KERNEL_NEAREST } cpl_kernel; -typedef enum { +typedef enum +{ CPL_FIT_CENTROID = 1 << 1, - CPL_FIT_STDEV = 1 << 2, - CPL_FIT_AREA = 1 << 3, - CPL_FIT_OFFSET = 1 << 4, - CPL_FIT_ALL = (1 << 1) | - (1 << 2) | - (1 << 3) | - (1 << 4) + CPL_FIT_STDEV = 1 << 2, + CPL_FIT_AREA = 1 << 3, + CPL_FIT_OFFSET = 1 << 4, + CPL_FIT_ALL = (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) } cpl_fit_mode; -typedef enum { +typedef enum +{ /* Must use these values for backwards compatability of cpl_vector_sort() */ CPL_SORT_DESCENDING = -1, CPL_SORT_ASCENDING = 1 @@ -107,22 +106,25 @@ -----------------------------------------------------------------------------*/ /* Constructors and destructors */ -cpl_vector * cpl_vector_new(cpl_size) CPL_ATTR_ALLOC; -cpl_vector * cpl_vector_wrap(cpl_size, double *) CPL_ATTR_ALLOC; +cpl_vector *cpl_vector_new(cpl_size) CPL_ATTR_ALLOC; +cpl_vector *cpl_vector_wrap(cpl_size, double *) CPL_ATTR_ALLOC; void cpl_vector_delete(cpl_vector *); -void * cpl_vector_unwrap(cpl_vector *); -cpl_vector * cpl_vector_read(const char *) CPL_ATTR_ALLOC; +void *cpl_vector_unwrap(cpl_vector *); +cpl_vector *cpl_vector_read(const char *) CPL_ATTR_ALLOC; void cpl_vector_dump(const cpl_vector *, FILE *); -cpl_vector * cpl_vector_load(const char *, cpl_size) CPL_ATTR_ALLOC; -cpl_error_code cpl_vector_save(const cpl_vector *, const char *, cpl_type, - const cpl_propertylist *, unsigned); -cpl_vector * cpl_vector_duplicate(const cpl_vector *) CPL_ATTR_ALLOC; +cpl_vector *cpl_vector_load(const char *, cpl_size) CPL_ATTR_ALLOC; +cpl_error_code cpl_vector_save(const cpl_vector *, + const char *, + cpl_type, + const cpl_propertylist *, + unsigned); +cpl_vector *cpl_vector_duplicate(const cpl_vector *) CPL_ATTR_ALLOC; cpl_error_code cpl_vector_copy(cpl_vector *, const cpl_vector *); /* Accessor functions */ cpl_size cpl_vector_get_size(const cpl_vector *); - double * cpl_vector_get_data(cpl_vector *); -const double * cpl_vector_get_data_const(const cpl_vector *); +double *cpl_vector_get_data(cpl_vector *); +const double *cpl_vector_get_data_const(const cpl_vector *); double cpl_vector_get(const cpl_vector *, cpl_size); cpl_error_code cpl_vector_set_size(cpl_vector *, cpl_size); cpl_error_code cpl_vector_set(cpl_vector *, cpl_size, double); @@ -146,8 +148,8 @@ cpl_error_code cpl_vector_fill(cpl_vector *, double); cpl_error_code cpl_vector_sqrt(cpl_vector *); cpl_size cpl_vector_find(const cpl_vector *, double); -cpl_vector * cpl_vector_extract(const cpl_vector *, cpl_size, - cpl_size, cpl_size) CPL_ATTR_ALLOC; +cpl_vector *cpl_vector_extract(const cpl_vector *, cpl_size, cpl_size, cpl_size) + CPL_ATTR_ALLOC; /* Statistics on cpl_vector */ cpl_size cpl_vector_get_minpos(const cpl_vector *); @@ -159,28 +161,36 @@ double cpl_vector_get_median(cpl_vector *); double cpl_vector_get_median_const(const cpl_vector *); double cpl_vector_get_stdev(const cpl_vector *); -cpl_size cpl_vector_correlate(cpl_vector *, const cpl_vector *, const cpl_vector *); +cpl_size +cpl_vector_correlate(cpl_vector *, const cpl_vector *, const cpl_vector *); /* Filtering */ -cpl_vector * cpl_vector_filter_lowpass_create(const cpl_vector *, cpl_lowpass, - cpl_size) CPL_ATTR_ALLOC; -cpl_vector * cpl_vector_filter_median_create(const cpl_vector *, +cpl_vector *cpl_vector_filter_lowpass_create(const cpl_vector *, + cpl_lowpass, cpl_size) CPL_ATTR_ALLOC; +cpl_vector * +cpl_vector_filter_median_create(const cpl_vector *, cpl_size) CPL_ATTR_ALLOC; cpl_error_code cpl_vector_fill_kernel_profile(cpl_vector *, cpl_kernel, double); /* Fitting */ -cpl_error_code cpl_vector_fit_gaussian(const cpl_vector *, const cpl_vector *, - const cpl_vector *, const cpl_vector *, - cpl_fit_mode, - double *, double *, - double *, double *, - double *, double *, - cpl_matrix **); - -cpl_vector * cpl_vector_new_lss_kernel(double, double) CPL_ATTR_DEPRECATED; -cpl_error_code cpl_vector_convolve_symmetric(cpl_vector *, const cpl_vector *) - CPL_ATTR_DEPRECATED; +cpl_error_code cpl_vector_fit_gaussian(const cpl_vector *, + const cpl_vector *, + const cpl_vector *, + const cpl_vector *, + cpl_fit_mode, + double *, + double *, + double *, + double *, + double *, + double *, + cpl_matrix **); + +cpl_vector *cpl_vector_new_lss_kernel(double, double) CPL_ATTR_DEPRECATED; +cpl_error_code +cpl_vector_convolve_symmetric(cpl_vector *, + const cpl_vector *) CPL_ATTR_DEPRECATED; CPL_END_DECLS diff -Nru cpl-7.1.4+ds/cplcore/cpl_vector_impl.h cpl-7.2.2+ds/cplcore/cpl_vector_impl.h --- cpl-7.1.4+ds/cplcore/cpl_vector_impl.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_vector_impl.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -24,18 +24,18 @@ CPL_BEGIN_DECLS -double * cpl_vector_rewrap(cpl_vector *, cpl_size, double *); +double *cpl_vector_rewrap(cpl_vector *, cpl_size, double *); -cpl_size cpl_vector_get_size_(const cpl_vector *) - CPL_ATTR_PURE CPL_ATTR_NONNULL; +cpl_size +cpl_vector_get_size_(const cpl_vector *) CPL_ATTR_PURE CPL_ATTR_NONNULL; -double * cpl_vector_get_data_(cpl_vector *) +double *cpl_vector_get_data_(cpl_vector *) #ifdef NDEBUG CPL_ATTR_PURE #endif CPL_ATTR_NONNULL; -const double * cpl_vector_get_data_const_(const cpl_vector *) +const double *cpl_vector_get_data_const_(const cpl_vector *) #ifdef NDEBUG CPL_ATTR_PURE #endif @@ -47,10 +47,7 @@ #endif CPL_ATTR_NONNULL; -void cpl_vector_set_(cpl_vector *, - cpl_size, - double) - CPL_ATTR_NONNULL; +void cpl_vector_set_(cpl_vector *, cpl_size, double) CPL_ATTR_NONNULL; #endif /* end of cpl_vector_impl.h */ diff -Nru cpl-7.1.4+ds/cplcore/cpl_version.c cpl-7.2.2+ds/cplcore/cpl_version.c --- cpl-7.1.4+ds/cplcore/cpl_version.c 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_version.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -18,7 +18,7 @@ */ #ifdef HAVE_CONFIG_H -# include +#include #endif #include "cpl_version.h" diff -Nru cpl-7.1.4+ds/cplcore/cpl_version.h.top cpl-7.2.2+ds/cplcore/cpl_version.h.top --- cpl-7.1.4+ds/cplcore/cpl_version.h.top 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_version.h.top 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 diff -Nru cpl-7.1.4+ds/cplcore/cpl_xmemory.c cpl-7.2.2+ds/cplcore/cpl_xmemory.c --- cpl-7.1.4+ds/cplcore/cpl_xmemory.c 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_xmemory.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -66,7 +66,7 @@ #endif #define CPL_XSTRINGIFY(TOSTRING) #TOSTRING -#define CPL_STRINGIFY(TOSTRING) CPL_XSTRINGIFY(TOSTRING) +#define CPL_STRINGIFY(TOSTRING) CPL_XSTRINGIFY(TOSTRING) /* This symbol defines the level of usage of the memory module. @@ -109,42 +109,42 @@ Private variables -----------------------------------------------------------------------------*/ -static const char * cpl_xmemory_type[] - = {"free", "malloc", "calloc", "realloc"}; +static const char *cpl_xmemory_type[] = { "free", "malloc", "calloc", + "realloc" }; /* Number of active cells */ -static size_t cpl_xmemory_ncells = 0; +static size_t cpl_xmemory_ncells = 0; /* Peak number of pointers ever seen for diagnostics */ -static size_t cpl_xmemory_max_cells = 0; +static size_t cpl_xmemory_max_cells = 0; /* Total number of allocations for diagnostics - via free()/realloc()*/ -static size_t cpl_xmemory_sum_cells = 0; +static size_t cpl_xmemory_sum_cells = 0; /* Total allocated RAM in bytes */ -static size_t cpl_xmemory_alloc_ram = 0; +static size_t cpl_xmemory_alloc_ram = 0; /* Peak allocation ever seen for diagnostics */ -static size_t cpl_xmemory_alloc_max = 0; +static size_t cpl_xmemory_alloc_max = 0; /* The current size of the xmemory table */ -static size_t cpl_xmemory_table_size = 0; +static size_t cpl_xmemory_table_size = 0; /* The default size of the xmemory table, when it is non-empty */ -static size_t cpl_xmemory_table_size_max = 0; +static size_t cpl_xmemory_table_size_max = 0; static int cpl_xmemory_fatal = 0; /* Various infos about the pointers */ /* List of pointers */ -static const void ** cpl_xmemory_p_val; +static const void **cpl_xmemory_p_val; /* Type of allocation */ /* - CPL_XMEMORY_TYPE_FREE means no allocation */ -static unsigned char * cpl_xmemory_p_type; +static unsigned char *cpl_xmemory_p_type; /* Size of allocated memory [bytes] */ -static size_t * cpl_xmemory_p_size; +static size_t *cpl_xmemory_p_size; /*----------------------------------------------------------------------------- Private function prototypes @@ -173,27 +173,24 @@ */ /*----------------------------------------------------------------------------*/ -inline -void * cpl_xmemory_malloc_count(size_t size) +inline void * +cpl_xmemory_malloc_count(size_t size) { - - void * ptr = malloc(size); + void *ptr = malloc(size); if (ptr != NULL) { - -# ifdef _OPENMP -# pragma omp atomic -# endif +#ifdef _OPENMP +#pragma omp atomic +#endif cpl_xmemory_ncells++; /* Remember peak allocation */ /* FIXME: This non-thread-safe check is incorrect, but might still produce a useful estimate */ if (cpl_xmemory_ncells > cpl_xmemory_max_cells) cpl_xmemory_max_cells = cpl_xmemory_ncells; - - } else if (size != 0) { - + } + else if (size != 0) { fprintf(stderr, "cpl_xmemory fatal error: malloc(%zu) returned NULL:\n", size); perror(NULL); @@ -201,11 +198,9 @@ cpl_xmemory_status(cpl_xmemory_table_size ? 2 : 1); assert(ptr != NULL); /* More informative, if enabled */ abort(); - } return ptr; - } /*----------------------------------------------------------------------------*/ @@ -219,39 +214,36 @@ */ /*----------------------------------------------------------------------------*/ -inline -void * cpl_xmemory_calloc_count(size_t nmemb, size_t size) +inline void * +cpl_xmemory_calloc_count(size_t nmemb, size_t size) { - - void * ptr = calloc(nmemb, size); + void *ptr = calloc(nmemb, size); if (ptr != NULL) { - -# ifdef _OPENMP -# pragma omp atomic -# endif +#ifdef _OPENMP +#pragma omp atomic +#endif cpl_xmemory_ncells++; /* Remember peak allocation */ /* FIXME: This non-thread-safe check is incorrect, but might still produce a useful estimate */ if (cpl_xmemory_ncells > cpl_xmemory_max_cells) cpl_xmemory_max_cells = cpl_xmemory_ncells; - - } else if (size != 0 && nmemb != 0) { - - fprintf(stderr, "cpl_xmemory fatal error: calloc(%zu, %zu) returned " - "NULL:\n", nmemb, size); + } + else if (size != 0 && nmemb != 0) { + fprintf(stderr, + "cpl_xmemory fatal error: calloc(%zu, %zu) returned " + "NULL:\n", + nmemb, size); perror(NULL); cpl_xmemory_fatal = 1; cpl_xmemory_status(cpl_xmemory_table_size ? 2 : 1); assert(ptr != NULL); /* More informative, if enabled */ abort(); - } return ptr; - } @@ -266,11 +258,10 @@ */ /*----------------------------------------------------------------------------*/ -inline -void * cpl_xmemory_realloc_count(void * oldptr, size_t size) +inline void * +cpl_xmemory_realloc_count(void *oldptr, size_t size) { - - void * ptr; + void *ptr; if (oldptr == NULL) { /* This is just another way to do a malloc() */ @@ -279,13 +270,16 @@ #ifndef _OPENMP /* Need to disable this non-threadsafe check with thread-support */ - } else if (cpl_xmemory_ncells == 0) { - fprintf(stderr, "cpl_xmemory error: Ignoring realloc() to %zu bytes on " - "unallocated pointer (%p)\n", size, oldptr); + } + else if (cpl_xmemory_ncells == 0) { + fprintf(stderr, + "cpl_xmemory error: Ignoring realloc() to %zu bytes on " + "unallocated pointer (%p)\n", + size, oldptr); ptr = NULL; #endif - } else { - + } + else { /* assert( oldptr != NULL ); */ ptr = realloc(oldptr, size); @@ -293,10 +287,11 @@ cpl_xmemory_sum_cells++; /* Approximate during multi-threading */ if (ptr == NULL) { - if (size != 0) { - fprintf(stderr, "cpl_xmemory fatal error: realloc(%p, %zu) " - "returned NULL:\n", oldptr, size); + fprintf(stderr, + "cpl_xmemory fatal error: realloc(%p, %zu) " + "returned NULL:\n", + oldptr, size); perror(NULL); cpl_xmemory_fatal = 1; cpl_xmemory_status(cpl_xmemory_table_size ? 2 : 1); @@ -305,9 +300,9 @@ } /* This is just another way to do a free() */ -# ifdef _OPENMP -# pragma omp atomic -# endif +#ifdef _OPENMP +#pragma omp atomic +#endif cpl_xmemory_ncells--; } } @@ -325,23 +320,25 @@ */ /*----------------------------------------------------------------------------*/ -void cpl_xmemory_free_count(void * ptr) +void +cpl_xmemory_free_count(void *ptr) { - if (ptr != NULL) { #ifndef _OPENMP /* Need to disable this non-threadsafe check with thread-support */ if (cpl_xmemory_ncells == 0) { - fprintf(stderr, "cpl_xmemory error: Ignoring free() on " - "unallocated pointer (%p)\n", ptr); + fprintf(stderr, + "cpl_xmemory error: Ignoring free() on " + "unallocated pointer (%p)\n", + ptr); return; } #endif free(ptr); -# ifdef _OPENMP -# pragma omp atomic -# endif +#ifdef _OPENMP +#pragma omp atomic +#endif cpl_xmemory_ncells--; cpl_xmemory_sum_cells++; /* Approximate during multi-threading */ @@ -359,9 +356,10 @@ */ /*----------------------------------------------------------------------------*/ -void * cpl_xmemory_malloc(size_t size) +void * +cpl_xmemory_malloc(size_t size) { - void * ptr; + void *ptr; size_t pos; if (size == 0) { @@ -372,9 +370,8 @@ ptr = cpl_xmemory_malloc_count(size); - if (cpl_xmemory_ncells - >= cpl_xmemory_table_size * CPL_XMEMORY_RESIZE_THRESHOLD) { - + if (cpl_xmemory_ncells >= + cpl_xmemory_table_size * CPL_XMEMORY_RESIZE_THRESHOLD) { /* Initialize table if needed */ if (cpl_xmemory_table_size == 0) { cpl_xmemory_init(); @@ -401,9 +398,10 @@ */ /*----------------------------------------------------------------------------*/ -void * cpl_xmemory_calloc(size_t nmemb, size_t size) +void * +cpl_xmemory_calloc(size_t nmemb, size_t size) { - void * ptr; + void *ptr; size_t pos; @@ -415,9 +413,8 @@ ptr = cpl_xmemory_calloc_count(nmemb, size); - if (cpl_xmemory_ncells - >= cpl_xmemory_table_size * CPL_XMEMORY_RESIZE_THRESHOLD) { - + if (cpl_xmemory_ncells >= + cpl_xmemory_table_size * CPL_XMEMORY_RESIZE_THRESHOLD) { /* Initialize table if needed */ if (cpl_xmemory_table_size == 0) { cpl_xmemory_init(); @@ -443,9 +440,10 @@ @return 1 newly allocated pointer. */ /*----------------------------------------------------------------------------*/ -void * cpl_xmemory_realloc(void * oldptr, size_t size) +void * +cpl_xmemory_realloc(void *oldptr, size_t size) { - void * ptr; + void *ptr; size_t pos = cpl_xmemory_table_size; /* Avoid (false) uninit warning */ if (size == 0) { @@ -456,18 +454,21 @@ } if (oldptr != NULL) { - if (cpl_xmemory_table_size == 0) { - fprintf(stderr, "cpl_xmemory error: Ignoring realloc() of %zu bytes" - " requested on unallocated pointer (%p)\n", size, oldptr); + fprintf(stderr, + "cpl_xmemory error: Ignoring realloc() of %zu bytes" + " requested on unallocated pointer (%p)\n", + size, oldptr); return NULL; } pos = cpl_xmemory_findcell(oldptr); if (pos == cpl_xmemory_table_size) { - fprintf(stderr, "cpl_xmemory error: Ignoring realloc() of %zu bytes" - " requested on unallocated pointer (%p)\n", size, oldptr); + fprintf(stderr, + "cpl_xmemory error: Ignoring realloc() of %zu bytes" + " requested on unallocated pointer (%p)\n", + size, oldptr); return NULL; } @@ -481,7 +482,6 @@ /* Remove cell from main table */ cpl_xmemory_remcell(pos); - } ptr = cpl_xmemory_realloc_count(oldptr, size); @@ -489,10 +489,8 @@ /* assert( ptr != NULL ); */ if (ptr != oldptr) { - - if (cpl_xmemory_ncells >= cpl_xmemory_table_size - * CPL_XMEMORY_RESIZE_THRESHOLD) { - + if (cpl_xmemory_ncells >= + cpl_xmemory_table_size * CPL_XMEMORY_RESIZE_THRESHOLD) { /* Initialize table if needed */ if (cpl_xmemory_table_size == 0) { cpl_xmemory_init(); @@ -503,7 +501,6 @@ } pos = cpl_xmemory_findfree(ptr); - } /* Add cell into general table */ @@ -527,17 +524,20 @@ */ /*----------------------------------------------------------------------------*/ -void cpl_xmemory_free(void * ptr) +void +cpl_xmemory_free(void *ptr) { - size_t pos; /* Do nothing for a NULL pointer */ - if (ptr == NULL) return; + if (ptr == NULL) + return; if (cpl_xmemory_ncells == 0) { - fprintf(stderr, "cpl_xmemory error: Ignoring free() on unallocated " - "pointer (%p)\n", ptr); + fprintf(stderr, + "cpl_xmemory error: Ignoring free() on unallocated " + "pointer (%p)\n", + ptr); return; } @@ -546,25 +546,27 @@ pos = cpl_xmemory_findcell(ptr); if (pos == cpl_xmemory_table_size) { - fprintf(stderr, "cpl_xmemory error: Ignoring free() on unallocated " - "pointer (%p)\n", ptr); + fprintf(stderr, + "cpl_xmemory error: Ignoring free() on unallocated " + "pointer (%p)\n", + ptr); return; - } /* free + below decrement copied from cpl_xmemory_free_count() */ free(ptr); /* Decrement number of allocated pointers */ -# ifdef _OPENMP -# pragma omp atomic -# endif +#ifdef _OPENMP +#pragma omp atomic +#endif cpl_xmemory_ncells--; if (cpl_xmemory_ncells > 0) { /* Remove cell from main table */ cpl_xmemory_remcell(pos); - } else { + } + else { /* There are no more active pointers, deallocate internal memory */ cpl_xmemory_end(); } @@ -584,85 +586,85 @@ features. */ /*----------------------------------------------------------------------------*/ -void cpl_xmemory_status(int mode) +void +cpl_xmemory_status(int mode) { + if (mode > 0) { + const size_t rowsize = + sizeof(void *) + sizeof(size_t) + sizeof(unsigned char); - if (mode > 0) - { - const size_t rowsize = - sizeof(void*) + - sizeof(size_t)+ - sizeof(unsigned char); - - fprintf(stderr, "#----- Memory Diagnostics -----\n"); + fprintf(stderr, "#----- Memory Diagnostics -----\n"); - if (mode == 2) { - fprintf(stderr, - "Total allocations [pointer]: %zu\n" - "Peak pointer usage [pointer]: %zu\n" - "Peak memory allocation [B]: %zu\n" - "Peak table size [pointer]: %zu\n" - "Peak table size [B]: %zu\n", - cpl_xmemory_sum_cells, - cpl_xmemory_max_cells, - cpl_xmemory_alloc_max, - cpl_xmemory_table_size_max, - cpl_xmemory_table_size_max * rowsize); - } else { - fprintf(stderr, "Total number of allocations" -# ifdef _OPENMP - /* cpl_xmemory_sum_cells is not updated thread-safely */ - " (approximate)" -# endif - ": %zu\n", cpl_xmemory_sum_cells); - fprintf(stderr, "Maximum number of pointers" -# ifdef _OPENMP - /* cpl_xmemory_max_cells is not updated thread-safely */ - " (approximate)" -# endif - ": %zu\n", cpl_xmemory_max_cells); - } + if (mode == 2) { + fprintf(stderr, + "Total allocations [pointer]: %zu\n" + "Peak pointer usage [pointer]: %zu\n" + "Peak memory allocation [B]: %zu\n" + "Peak table size [pointer]: %zu\n" + "Peak table size [B]: %zu\n", + cpl_xmemory_sum_cells, cpl_xmemory_max_cells, + cpl_xmemory_alloc_max, cpl_xmemory_table_size_max, + cpl_xmemory_table_size_max * rowsize); + } + else { + fprintf(stderr, + "Total number of allocations" +#ifdef _OPENMP + /* cpl_xmemory_sum_cells is not updated thread-safely */ + " (approximate)" +#endif + ": %zu\n", + cpl_xmemory_sum_cells); + fprintf(stderr, + "Maximum number of pointers" +#ifdef _OPENMP + /* cpl_xmemory_max_cells is not updated thread-safely */ + " (approximate)" +#endif + ": %zu\n", + cpl_xmemory_max_cells); + } - fprintf(stderr, "#----- Memory Currently Allocated -----\n"); + fprintf(stderr, "#----- Memory Currently Allocated -----\n"); - fprintf(stderr, "Number of active pointers: %zu\n", - cpl_xmemory_ncells); + fprintf(stderr, "Number of active pointers: %zu\n", + cpl_xmemory_ncells); - if (mode == 2 && cpl_xmemory_ncells > 0) { - size_t ii; - size_t ntype[4] = {0, 0, 0, 0}; + if (mode == 2 && cpl_xmemory_ncells > 0) { + size_t ii; + size_t ntype[4] = { 0, 0, 0, 0 }; - /* assert( cpl_xmemory_table_size != 0 ); */ + /* assert( cpl_xmemory_table_size != 0 ); */ - fprintf(stderr, - "Memory allocation [B]: %zu\n" - "Current table size [pointer]: %zu\n" - "Current table size [B]: %zu\n", - cpl_xmemory_alloc_ram, - cpl_xmemory_table_size, - cpl_xmemory_table_size * rowsize); + fprintf(stderr, + "Memory allocation [B]: %zu\n" + "Current table size [pointer]: %zu\n" + "Current table size [B]: %zu\n", + cpl_xmemory_alloc_ram, cpl_xmemory_table_size, + cpl_xmemory_table_size * rowsize); - /* Do not print entire table on fatal error + /* Do not print entire table on fatal error - it is likely huge */ - if (cpl_xmemory_fatal == 0) - fprintf(stderr, "#- Active pointer details\n"); - for (ii=0; ii < cpl_xmemory_table_size; ii++) { - if (cpl_xmemory_p_type[ii] != CPL_XMEMORY_TYPE_FREE) { - ntype[cpl_xmemory_p_type[ii]]++; - if (cpl_xmemory_fatal == 0) - fprintf(stderr, "(%p) - %s() of %zu bytes\n", - cpl_xmemory_p_val[ii], - cpl_xmemory_type[cpl_xmemory_p_type[ii]], - cpl_xmemory_p_size[ii]); - } + if (cpl_xmemory_fatal == 0) + fprintf(stderr, "#- Active pointer details\n"); + for (ii = 0; ii < cpl_xmemory_table_size; ii++) { + if (cpl_xmemory_p_type[ii] != CPL_XMEMORY_TYPE_FREE) { + ntype[cpl_xmemory_p_type[ii]]++; + if (cpl_xmemory_fatal == 0) + fprintf(stderr, "(%p) - %s() of %zu bytes\n", + cpl_xmemory_p_val[ii], + cpl_xmemory_type[cpl_xmemory_p_type[ii]], + cpl_xmemory_p_size[ii]); } - fprintf(stderr, "#- Types of active pointers\n"); - fprintf(stderr, "%7s(): %zu\n", cpl_xmemory_type[1], ntype[1]); - fprintf(stderr, "%7s(): %zu\n", cpl_xmemory_type[2], ntype[2]); - fprintf(stderr, "%7s(): %zu\n", cpl_xmemory_type[3], ntype[3]); } - if (cpl_xmemory_fatal != 0) (void)fflush(stderr); + fprintf(stderr, "#- Types of active pointers\n"); + fprintf(stderr, "%7s(): %zu\n", cpl_xmemory_type[1], ntype[1]); + fprintf(stderr, "%7s(): %zu\n", cpl_xmemory_type[2], ntype[2]); + fprintf(stderr, "%7s(): %zu\n", cpl_xmemory_type[3], ntype[3]); } + if (cpl_xmemory_fatal != 0) + (void)fflush(stderr); + } return; } @@ -676,7 +678,8 @@ -1 if the memory model is off */ /*----------------------------------------------------------------------------*/ -int cpl_xmemory_is_empty(int mode) +int +cpl_xmemory_is_empty(int mode) { if (mode > 0) { /* @@ -685,7 +688,8 @@ assert(cpl_xmemory_ncells == 0 || cpl_xmemory_alloc_ram > 0); */ return cpl_xmemory_ncells == 0 ? 1 : 0; - } else { + } + else { return -1; } } @@ -704,31 +708,40 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_xmemory_init(void) +static void +cpl_xmemory_init(void) { - if (CPL_XMEMORY_RESIZE_THRESHOLD > 1.0) { - fprintf(stderr, "cpl_xmemory fatal error: Memory table resize threshold " - CPL_XSTRINGIFY(CPL_XMEMORY_RESIZE_THRESHOLD) " must be less " - "than or equal to 1, not " - CPL_STRINGIFY(CPL_XMEMORY_RESIZE_THRESHOLD) "\n"); + fprintf( + stderr, + "cpl_xmemory fatal error: Memory table resize " + "threshold " CPL_XSTRINGIFY( + CPL_XMEMORY_RESIZE_THRESHOLD) " must be less " + "than or equal to 1, " + "not " CPL_STRINGIFY(CPL_XMEMORY_RESIZE_THRESHOLD) "\n"); assert(CPL_XMEMORY_RESIZE_THRESHOLD <= 1.0); /* More informative */ abort(); } if (CPL_XMEMORY_RESIZE_THRESHOLD <= 0.0) { - fprintf(stderr, "cpl_xmemory fatal error: Memory table resize threshold " - CPL_XSTRINGIFY(CPL_XMEMORY_RESIZE_THRESHOLD) " must be positive" - ", not " CPL_STRINGIFY(CPL_XMEMORY_RESIZE_THRESHOLD) "\n"); + fprintf( + stderr, + "cpl_xmemory fatal error: Memory table resize " + "threshold " CPL_XSTRINGIFY( + CPL_XMEMORY_RESIZE_THRESHOLD) " must be positive" + ", not " CPL_STRINGIFY(CPL_XMEMORY_RESIZE_THRESHOLD) "\n"); assert(CPL_XMEMORY_RESIZE_THRESHOLD > 0.0); /* More informative */ abort(); } if (CPL_XMEMORY_RESIZE_FACTOR <= 1.0) { - fprintf(stderr, "cpl_xmemory fatal error: Memory table resize factor " - CPL_XSTRINGIFY(CPL_XMEMORY_RESIZE_FACTOR) " must be greater " - "than 1, not " CPL_STRINGIFY(CPL_XMEMORY_RESIZE_FACTOR) "\n"); + fprintf( + stderr, + "cpl_xmemory fatal error: Memory table resize " + "factor " CPL_XSTRINGIFY( + CPL_XMEMORY_RESIZE_FACTOR) " must be greater " + "than 1, not " CPL_STRINGIFY(CPL_XMEMORY_RESIZE_FACTOR) "\n"); assert(CPL_XMEMORY_RESIZE_FACTOR > 1.0); /* More informative */ abort(); } @@ -749,31 +762,32 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_xmemory_init_alloc(void) +static void +cpl_xmemory_init_alloc(void) { - { - cpl_xmemory_p_val = calloc(cpl_xmemory_table_size, sizeof(void*)); - cpl_xmemory_p_type = calloc(cpl_xmemory_table_size, - sizeof(unsigned char)); + cpl_xmemory_p_val = calloc(cpl_xmemory_table_size, sizeof(void *)); + cpl_xmemory_p_type = + calloc(cpl_xmemory_table_size, sizeof(unsigned char)); cpl_xmemory_p_size = malloc(cpl_xmemory_table_size * sizeof(size_t)); /* FIXME: pragma omp atomic */ if (cpl_xmemory_table_size > cpl_xmemory_table_size_max) { cpl_xmemory_table_size_max = cpl_xmemory_table_size; } - } if (cpl_xmemory_p_val == NULL || cpl_xmemory_p_size == NULL || cpl_xmemory_p_type == NULL) { /* The table could not be allocated */ - fprintf(stderr, "cpl_xmemory fatal error: calloc() of memory table " - "failed with size %zu:\n", cpl_xmemory_table_size); + fprintf(stderr, + "cpl_xmemory fatal error: calloc() of memory table " + "failed with size %zu:\n", + cpl_xmemory_table_size); perror(NULL); cpl_xmemory_fatal = 1; - cpl_xmemory_status(1); /* Mode-2 data is invalid! */ - assert(cpl_xmemory_p_val != NULL); /* More informative, if enabled */ + cpl_xmemory_status(1); /* Mode-2 data is invalid! */ + assert(cpl_xmemory_p_val != NULL); /* More informative, if enabled */ assert(cpl_xmemory_p_size != NULL); assert(cpl_xmemory_p_type != NULL); abort(); @@ -790,18 +804,18 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_xmemory_resize(void) +static void +cpl_xmemory_resize(void) { + const void **p_val = cpl_xmemory_p_val; + size_t *p_size = cpl_xmemory_p_size; + unsigned char *p_type = cpl_xmemory_p_type; + const size_t old_size = cpl_xmemory_table_size; + size_t ii; - const void ** p_val = cpl_xmemory_p_val; - size_t * p_size = cpl_xmemory_p_size; - unsigned char * p_type = cpl_xmemory_p_type; - const size_t old_size = cpl_xmemory_table_size; - size_t ii; - - assert( cpl_xmemory_table_size > 0 ); + assert(cpl_xmemory_table_size > 0); - assert( cpl_xmemory_ncells > 0 ); + assert(cpl_xmemory_ncells > 0); cpl_xmemory_table_size = cpl_xmemory_table_size * CPL_XMEMORY_RESIZE_FACTOR; @@ -810,12 +824,14 @@ if (cpl_xmemory_table_size <= old_size) { /* The table could not be resized */ - fprintf(stderr, "cpl_xmemory fatal error: Memory table could not be " - "resized, %zu < %zu:\n", cpl_xmemory_table_size, old_size); + fprintf(stderr, + "cpl_xmemory fatal error: Memory table could not be " + "resized, %zu < %zu:\n", + cpl_xmemory_table_size, old_size); perror(NULL); cpl_xmemory_fatal = 1; - cpl_xmemory_status(1); /* Mode-2 data is invalid! */ - assert(cpl_xmemory_table_size > old_size); /* More informative */ + cpl_xmemory_status(1); /* Mode-2 data is invalid! */ + assert(cpl_xmemory_table_size > old_size); /* More informative */ abort(); } @@ -836,7 +852,7 @@ } } - free((void*)p_val); + free((void *)p_val); free(p_size); free(p_type); @@ -851,11 +867,10 @@ */ /*----------------------------------------------------------------------------*/ -inline -static void cpl_xmemory_end(void) +inline static void +cpl_xmemory_end(void) { - - assert( cpl_xmemory_ncells == 0 ); + assert(cpl_xmemory_ncells == 0); cpl_xmemory_table_size = 0; @@ -884,13 +899,12 @@ the passed values are correct! */ /*----------------------------------------------------------------------------*/ -inline -static void cpl_xmemory_addcell(size_t pos, - const void * pointer, - size_t size, - unsigned char type) +inline static void +cpl_xmemory_addcell(size_t pos, + const void *pointer, + size_t size, + unsigned char type) { - /* Store information */ cpl_xmemory_p_val[pos] = pointer; cpl_xmemory_p_size[pos] = size; @@ -917,16 +931,18 @@ */ /*----------------------------------------------------------------------------*/ -inline -static size_t cpl_xmemory_findcell(const void * ptr) +inline static size_t +cpl_xmemory_findcell(const void *ptr) { const size_t pos = PTR_HASH(ptr); - size_t ii = pos; + size_t ii = pos; /* Locate pointer in main table */ do { - if (cpl_xmemory_p_val[ii] == ptr) return ii; /* Found */ - if (++ii == cpl_xmemory_table_size) ii = 0; /* Wrap around */ + if (cpl_xmemory_p_val[ii] == ptr) + return ii; /* Found */ + if (++ii == cpl_xmemory_table_size) + ii = 0; /* Wrap around */ } while (ii != pos); /* Not found */ @@ -944,17 +960,16 @@ */ /*----------------------------------------------------------------------------*/ -inline -static size_t cpl_xmemory_findfree(const void * ptr) +inline static size_t +cpl_xmemory_findfree(const void *ptr) { - /* Find an available slot */ const size_t pos = PTR_HASH(ptr); /* In comparison with the method of cpl_xmemory_findcell() this is faster when the table starts to be full */ - const void * ppos = memchr(cpl_xmemory_p_type+pos, CPL_XMEMORY_TYPE_FREE, - cpl_xmemory_table_size - pos); + const void *ppos = memchr(cpl_xmemory_p_type + pos, CPL_XMEMORY_TYPE_FREE, + cpl_xmemory_table_size - pos); if (ppos == NULL) { ppos = memchr(cpl_xmemory_p_type, CPL_XMEMORY_TYPE_FREE, pos); @@ -962,7 +977,7 @@ if (ppos == NULL) { /* No available slot */ fprintf(stderr, "cpl_xmemory internal, fatal error: " - "Could not find place for new pointer\n"); + "Could not find place for new pointer\n"); cpl_xmemory_fatal = 1; cpl_xmemory_status(2); assert(ppos != NULL); /* More informative, if enabled */ @@ -984,8 +999,8 @@ */ /*----------------------------------------------------------------------------*/ -inline -static void cpl_xmemory_remcell(size_t pos) +inline static void +cpl_xmemory_remcell(size_t pos) { /* Set pointer to NULL */ cpl_xmemory_p_val[pos] = NULL; diff -Nru cpl-7.1.4+ds/cplcore/cpl_xmemory.h cpl-7.2.2+ds/cplcore/cpl_xmemory.h --- cpl-7.1.4+ds/cplcore/cpl_xmemory.h 2021-05-07 12:09:09.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/cpl_xmemory.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -34,17 +34,17 @@ Function prototypes -----------------------------------------------------------------------------*/ -void * cpl_xmemory_malloc_count(size_t) CPL_ATTR_MALLOC; -void * cpl_xmemory_calloc_count(size_t, size_t) CPL_ATTR_CALLOC; -void * cpl_xmemory_realloc_count(void *, size_t) CPL_ATTR_REALLOC; -void cpl_xmemory_free_count(void *); - -void * cpl_xmemory_malloc(size_t) CPL_ATTR_MALLOC; -void * cpl_xmemory_calloc(size_t, size_t) CPL_ATTR_CALLOC; -void * cpl_xmemory_realloc(void *, size_t) CPL_ATTR_REALLOC; -void cpl_xmemory_free(void *); +void *cpl_xmemory_malloc_count(size_t) CPL_ATTR_MALLOC; +void *cpl_xmemory_calloc_count(size_t, size_t) CPL_ATTR_CALLOC; +void *cpl_xmemory_realloc_count(void *, size_t) CPL_ATTR_REALLOC; +void cpl_xmemory_free_count(void *); + +void *cpl_xmemory_malloc(size_t) CPL_ATTR_MALLOC; +void *cpl_xmemory_calloc(size_t, size_t) CPL_ATTR_CALLOC; +void *cpl_xmemory_realloc(void *, size_t) CPL_ATTR_REALLOC; +void cpl_xmemory_free(void *); void cpl_xmemory_status(int); -int cpl_xmemory_is_empty(int) CPL_ATTR_PURE; +int cpl_xmemory_is_empty(int) CPL_ATTR_PURE; #endif diff -Nru cpl-7.1.4+ds/cplcore/Makefile.am cpl-7.2.2+ds/cplcore/Makefile.am --- cpl-7.1.4+ds/cplcore/Makefile.am 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/Makefile.am 2022-04-29 14:56:02.000000000 +0000 @@ -1,7 +1,7 @@ ## Process this file with automake to produce Makefile.in ## This file is part of the ESO Common Pipeline Library -## Copyright (C) 2001-2017 European Southern Observatory +## Copyright (C) 2001-2022 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 @@ -41,7 +41,7 @@ $(CPL_CFLAGS) EXTRA_DIST = cpl_version.h.top cpl_version.h.bot cpl_func.h.top cpl_func.h.bot \ - cpl_filter_median.c + cpl_filter_median.c cpl_fits_card.c cpl_property_dicb.c BUILT_SOURCES = cpl_version.h cpl_func.h @@ -90,7 +90,7 @@ cpl_image_stats_body.h cpl_imagelist_basic_body.h cpl_imagelist_defs.h \ cpl_mask_defs.h cpl_mask_impl.h cpl_memory_impl.h cpl_propertylist_impl.h \ cpl_stats_body.h cpl_tools.h cpl_tools_body.h cpl_type_impl.h \ - cpl_image_bpm_impl.h \ + cpl_image_bpm_impl.h cpl_fits_card.h cpl_property_dicb.h \ cpl_xmemory.h cpl_image_filter_impl.h cpl_mask_body.h cpl_mask_binary.h \ cpl_image_bpm_body.h cpl_io_fits.h cpl_cfitsio.h cpl_polynomial_impl.h \ cpl_vector_impl.h cpl_vector_fit_impl.h cpl_matrix_impl.h \ @@ -155,3 +155,8 @@ cpl_func.h: $(srcdir)/cpl_func.h.top cpl_func.h.in $(srcdir)/cpl_func.h.bot cat $(srcdir)/cpl_func.h.top cpl_func.h.in \ $(srcdir)/cpl_func.h.bot > cpl_func.h; + + +cpl_image_filter.c: $(srcdir)/cpl_filter_median.c +cpl_propertylist.c: $(srcdir)/cpl_fits_card.h $(srcdir)/cpl_fits_card.c \ + $(srcdir)/cpl_property_dicb.h $(srcdir)/cpl_property_dicb.c diff -Nru cpl-7.1.4+ds/cplcore/Makefile.in cpl-7.2.2+ds/cplcore/Makefile.in --- cpl-7.1.4+ds/cplcore/Makefile.in 2021-05-07 12:10:10.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/Makefile.in 2022-04-29 14:56:28.000000000 +0000 @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.15.1 from Makefile.am. +# Makefile.in generated by automake 1.16.3 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2017 Free Software Foundation, Inc. +# Copyright (C) 1994-2020 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -169,7 +169,28 @@ am__v_at_1 = DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) depcomp = $(SHELL) $(top_srcdir)/admin/depcomp -am__depfiles_maybe = depfiles +am__maybe_remake_depfiles = depfiles +am__depfiles_remade = ./$(DEPDIR)/cpl_array.Plo \ + ./$(DEPDIR)/cpl_bivector.Plo ./$(DEPDIR)/cpl_cfitsio.Plo \ + ./$(DEPDIR)/cpl_column.Plo ./$(DEPDIR)/cpl_error.Plo \ + ./$(DEPDIR)/cpl_errorstate.Plo ./$(DEPDIR)/cpl_fits.Plo \ + ./$(DEPDIR)/cpl_image_basic.Plo ./$(DEPDIR)/cpl_image_bpm.Plo \ + ./$(DEPDIR)/cpl_image_fft.Plo ./$(DEPDIR)/cpl_image_filter.Plo \ + ./$(DEPDIR)/cpl_image_gen.Plo ./$(DEPDIR)/cpl_image_io.Plo \ + ./$(DEPDIR)/cpl_image_iqe.Plo \ + ./$(DEPDIR)/cpl_image_resample.Plo \ + ./$(DEPDIR)/cpl_image_stats.Plo \ + ./$(DEPDIR)/cpl_imagelist_basic.Plo \ + ./$(DEPDIR)/cpl_imagelist_io.Plo ./$(DEPDIR)/cpl_init.Plo \ + ./$(DEPDIR)/cpl_io_fits.Plo ./$(DEPDIR)/cpl_mask.Plo \ + ./$(DEPDIR)/cpl_matrix.Plo ./$(DEPDIR)/cpl_memory.Plo \ + ./$(DEPDIR)/cpl_mpfit.Plo ./$(DEPDIR)/cpl_msg.Plo \ + ./$(DEPDIR)/cpl_plot.Plo ./$(DEPDIR)/cpl_polynomial.Plo \ + ./$(DEPDIR)/cpl_property.Plo ./$(DEPDIR)/cpl_propertylist.Plo \ + ./$(DEPDIR)/cpl_stats.Plo ./$(DEPDIR)/cpl_table.Plo \ + ./$(DEPDIR)/cpl_test.Plo ./$(DEPDIR)/cpl_tools.Plo \ + ./$(DEPDIR)/cpl_type.Plo ./$(DEPDIR)/cpl_vector.Plo \ + ./$(DEPDIR)/cpl_version.Plo ./$(DEPDIR)/cpl_xmemory.Plo am__mv = mv -f COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) @@ -213,7 +234,7 @@ $(RECURSIVE_CLEAN_TARGETS) \ $(am__extra_recursive_targets) AM_RECURSIVE_TARGETS = $(am__recursive_targets:-recursive=) TAGS CTAGS \ - distdir + distdir distdir-am 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 @@ -279,6 +300,7 @@ CPLCORE_INCLUDES = @CPLCORE_INCLUDES@ CPLDFS_INCLUDES = @CPLDFS_INCLUDES@ CPLDRS_INCLUDES = @CPLDRS_INCLUDES@ +CPLJAVA_INCLUDES = @CPLJAVA_INCLUDES@ CPLUI_INCLUDES = @CPLUI_INCLUDES@ CPL_BINARY_AGE = @CPL_BINARY_AGE@ CPL_BINARY_VERSION = @CPL_BINARY_VERSION@ @@ -339,6 +361,7 @@ LIBCPLCORE = @LIBCPLCORE@ LIBCPLDFS = @LIBCPLDFS@ LIBCPLDRS = @LIBCPLDRS@ +LIBCPLGASGANO = @LIBCPLGASGANO@ LIBCPLUI = @LIBCPLUI@ LIBFFTW = @LIBFFTW@ LIBFFTWF = @LIBFFTWF@ @@ -445,6 +468,7 @@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ @@ -468,7 +492,7 @@ $(CPL_CFLAGS) EXTRA_DIST = cpl_version.h.top cpl_version.h.bot cpl_func.h.top cpl_func.h.bot \ - cpl_filter_median.c + cpl_filter_median.c cpl_fits_card.c cpl_property_dicb.c BUILT_SOURCES = cpl_version.h cpl_func.h include_HEADERS = cpl_bivector.h \ @@ -514,7 +538,7 @@ cpl_image_stats_body.h cpl_imagelist_basic_body.h cpl_imagelist_defs.h \ cpl_mask_defs.h cpl_mask_impl.h cpl_memory_impl.h cpl_propertylist_impl.h \ cpl_stats_body.h cpl_tools.h cpl_tools_body.h cpl_type_impl.h \ - cpl_image_bpm_impl.h \ + cpl_image_bpm_impl.h cpl_fits_card.h cpl_property_dicb.h \ cpl_xmemory.h cpl_image_filter_impl.h cpl_mask_body.h cpl_mask_binary.h \ cpl_image_bpm_body.h cpl_io_fits.h cpl_cfitsio.h cpl_polynomial_impl.h \ cpl_vector_impl.h cpl_vector_fit_impl.h cpl_matrix_impl.h \ @@ -588,8 +612,8 @@ *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);; \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ esac; $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) @@ -645,43 +669,49 @@ distclean-compile: -rm -f *.tab.c -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_array.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_bivector.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_cfitsio.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_column.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_error.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_errorstate.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_fits.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_image_basic.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_image_bpm.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_image_fft.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_image_filter.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_image_gen.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_image_io.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_image_iqe.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_image_resample.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_image_stats.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_imagelist_basic.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_imagelist_io.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_init.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_io_fits.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_mask.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_matrix.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_memory.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_mpfit.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_msg.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_plot.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_polynomial.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_property.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_propertylist.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_stats.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_table.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_test.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_tools.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_type.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_vector.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_version.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_xmemory.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_array.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_bivector.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_cfitsio.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_column.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_error.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_errorstate.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_fits.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_image_basic.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_image_bpm.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_image_fft.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_image_filter.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_image_gen.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_image_io.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_image_iqe.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_image_resample.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_image_stats.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_imagelist_basic.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_imagelist_io.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_init.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_io_fits.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_mask.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_matrix.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_memory.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_mpfit.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_msg.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_plot.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_polynomial.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_property.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_propertylist.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_stats.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_table.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_test.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_tools.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_type.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_vector.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_version.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_xmemory.Plo@am__quote@ # am--include-marker + +$(am__depfiles_remade): + @$(MKDIR_P) $(@D) + @echo '# dummy' >$@-t && $(am__mv) $@-t $@ + +am--depfiles: $(am__depfiles_remade) .c.o: @am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @@ -851,7 +881,10 @@ distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags -distdir: $(DISTFILES) +distdir: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) distdir-am + +distdir-am: $(DISTFILES) @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ list='$(DISTFILES)'; \ @@ -917,7 +950,8 @@ done install: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) install-recursive -install-exec: install-exec-recursive +install-exec: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) install-exec-recursive install-data: install-data-recursive uninstall: uninstall-recursive @@ -955,7 +989,43 @@ mostlyclean-am distclean: distclean-recursive - -rm -rf ./$(DEPDIR) + -rm -f ./$(DEPDIR)/cpl_array.Plo + -rm -f ./$(DEPDIR)/cpl_bivector.Plo + -rm -f ./$(DEPDIR)/cpl_cfitsio.Plo + -rm -f ./$(DEPDIR)/cpl_column.Plo + -rm -f ./$(DEPDIR)/cpl_error.Plo + -rm -f ./$(DEPDIR)/cpl_errorstate.Plo + -rm -f ./$(DEPDIR)/cpl_fits.Plo + -rm -f ./$(DEPDIR)/cpl_image_basic.Plo + -rm -f ./$(DEPDIR)/cpl_image_bpm.Plo + -rm -f ./$(DEPDIR)/cpl_image_fft.Plo + -rm -f ./$(DEPDIR)/cpl_image_filter.Plo + -rm -f ./$(DEPDIR)/cpl_image_gen.Plo + -rm -f ./$(DEPDIR)/cpl_image_io.Plo + -rm -f ./$(DEPDIR)/cpl_image_iqe.Plo + -rm -f ./$(DEPDIR)/cpl_image_resample.Plo + -rm -f ./$(DEPDIR)/cpl_image_stats.Plo + -rm -f ./$(DEPDIR)/cpl_imagelist_basic.Plo + -rm -f ./$(DEPDIR)/cpl_imagelist_io.Plo + -rm -f ./$(DEPDIR)/cpl_init.Plo + -rm -f ./$(DEPDIR)/cpl_io_fits.Plo + -rm -f ./$(DEPDIR)/cpl_mask.Plo + -rm -f ./$(DEPDIR)/cpl_matrix.Plo + -rm -f ./$(DEPDIR)/cpl_memory.Plo + -rm -f ./$(DEPDIR)/cpl_mpfit.Plo + -rm -f ./$(DEPDIR)/cpl_msg.Plo + -rm -f ./$(DEPDIR)/cpl_plot.Plo + -rm -f ./$(DEPDIR)/cpl_polynomial.Plo + -rm -f ./$(DEPDIR)/cpl_property.Plo + -rm -f ./$(DEPDIR)/cpl_propertylist.Plo + -rm -f ./$(DEPDIR)/cpl_stats.Plo + -rm -f ./$(DEPDIR)/cpl_table.Plo + -rm -f ./$(DEPDIR)/cpl_test.Plo + -rm -f ./$(DEPDIR)/cpl_tools.Plo + -rm -f ./$(DEPDIR)/cpl_type.Plo + -rm -f ./$(DEPDIR)/cpl_vector.Plo + -rm -f ./$(DEPDIR)/cpl_version.Plo + -rm -f ./$(DEPDIR)/cpl_xmemory.Plo -rm -f Makefile distclean-am: clean-am distclean-compile distclean-generic \ distclean-tags @@ -1001,7 +1071,43 @@ installcheck-am: maintainer-clean: maintainer-clean-recursive - -rm -rf ./$(DEPDIR) + -rm -f ./$(DEPDIR)/cpl_array.Plo + -rm -f ./$(DEPDIR)/cpl_bivector.Plo + -rm -f ./$(DEPDIR)/cpl_cfitsio.Plo + -rm -f ./$(DEPDIR)/cpl_column.Plo + -rm -f ./$(DEPDIR)/cpl_error.Plo + -rm -f ./$(DEPDIR)/cpl_errorstate.Plo + -rm -f ./$(DEPDIR)/cpl_fits.Plo + -rm -f ./$(DEPDIR)/cpl_image_basic.Plo + -rm -f ./$(DEPDIR)/cpl_image_bpm.Plo + -rm -f ./$(DEPDIR)/cpl_image_fft.Plo + -rm -f ./$(DEPDIR)/cpl_image_filter.Plo + -rm -f ./$(DEPDIR)/cpl_image_gen.Plo + -rm -f ./$(DEPDIR)/cpl_image_io.Plo + -rm -f ./$(DEPDIR)/cpl_image_iqe.Plo + -rm -f ./$(DEPDIR)/cpl_image_resample.Plo + -rm -f ./$(DEPDIR)/cpl_image_stats.Plo + -rm -f ./$(DEPDIR)/cpl_imagelist_basic.Plo + -rm -f ./$(DEPDIR)/cpl_imagelist_io.Plo + -rm -f ./$(DEPDIR)/cpl_init.Plo + -rm -f ./$(DEPDIR)/cpl_io_fits.Plo + -rm -f ./$(DEPDIR)/cpl_mask.Plo + -rm -f ./$(DEPDIR)/cpl_matrix.Plo + -rm -f ./$(DEPDIR)/cpl_memory.Plo + -rm -f ./$(DEPDIR)/cpl_mpfit.Plo + -rm -f ./$(DEPDIR)/cpl_msg.Plo + -rm -f ./$(DEPDIR)/cpl_plot.Plo + -rm -f ./$(DEPDIR)/cpl_polynomial.Plo + -rm -f ./$(DEPDIR)/cpl_property.Plo + -rm -f ./$(DEPDIR)/cpl_propertylist.Plo + -rm -f ./$(DEPDIR)/cpl_stats.Plo + -rm -f ./$(DEPDIR)/cpl_table.Plo + -rm -f ./$(DEPDIR)/cpl_test.Plo + -rm -f ./$(DEPDIR)/cpl_tools.Plo + -rm -f ./$(DEPDIR)/cpl_type.Plo + -rm -f ./$(DEPDIR)/cpl_vector.Plo + -rm -f ./$(DEPDIR)/cpl_version.Plo + -rm -f ./$(DEPDIR)/cpl_xmemory.Plo -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic @@ -1022,17 +1128,18 @@ uninstall-nodist_includeHEADERS .MAKE: $(am__recursive_targets) all check install install-am \ - install-strip + install-exec install-strip -.PHONY: $(am__recursive_targets) CTAGS GTAGS TAGS all all-am check \ - check-am clean clean-generic clean-libLTLIBRARIES \ - clean-libtool 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-includeHEADERS install-info \ - install-info-am install-libLTLIBRARIES install-man \ +.PHONY: $(am__recursive_targets) CTAGS GTAGS TAGS all all-am \ + am--depfiles check check-am clean clean-generic \ + clean-libLTLIBRARIES clean-libtool 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-includeHEADERS install-info install-info-am \ + install-libLTLIBRARIES install-man \ install-nodist_includeHEADERS install-pdf install-pdf-am \ install-ps install-ps-am install-strip installcheck \ installcheck-am installdirs installdirs-am maintainer-clean \ @@ -1052,6 +1159,10 @@ cat $(srcdir)/cpl_func.h.top cpl_func.h.in \ $(srcdir)/cpl_func.h.bot > cpl_func.h; +cpl_image_filter.c: $(srcdir)/cpl_filter_median.c +cpl_propertylist.c: $(srcdir)/cpl_fits_card.h $(srcdir)/cpl_fits_card.c \ + $(srcdir)/cpl_property_dicb.h $(srcdir)/cpl_property_dicb.c + # 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-7.1.4+ds/cplcore/tests/cpl_array-test.c cpl-7.2.2+ds/cplcore/tests/cpl_array-test.c --- cpl-7.1.4+ds/cplcore/tests/cpl_array-test.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/tests/cpl_array-test.c 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -41,11 +41,12 @@ static void cpl_array_test_power_complex(void); static void cpl_array_test_power_valid(cpl_array *, double, double, double) CPL_ATTR_NONNULL; -static void cpl_array_test_power_complex_one(cpl_array *, double, - double complex, - double complex) CPL_ATTR_NONNULL; -static void cpl_array_test_power_invalid(cpl_array *, double, double) - CPL_ATTR_NONNULL; +static void cpl_array_test_power_complex_one(cpl_array *, + double, + double complex, + double complex) CPL_ATTR_NONNULL; +static void +cpl_array_test_power_invalid(cpl_array *, double, double) CPL_ATTR_NONNULL; static void cpl_array_test_new_complex(void); @@ -53,20 +54,20 @@ Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { - - FILE * stream; + FILE *stream; cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); - stream = cpl_msg_get_level() > CPL_MSG_INFO - ? fopen("/dev/null", "a") : stdout; + stream = + cpl_msg_get_level() > CPL_MSG_INFO ? fopen("/dev/null", "a") : stdout; /* Testing begins here */ - cpl_test_nonnull( stream ); + cpl_test_nonnull(stream); cpl_array_dump_structure(NULL, stream); cpl_array_dump(NULL, 1, 1, stream); @@ -78,7 +79,8 @@ cpl_array_test_new_complex(); - if (stream != stdout) cpl_test_zero( fclose(stream) ); + if (stream != stdout) + cpl_test_zero(fclose(stream)); /* End of tests */ return cpl_test_end(0); @@ -93,12 +95,12 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_array_test_power_complex(void) +static void +cpl_array_test_power_complex(void) { - - const cpl_type num_type[] = {CPL_TYPE_FLOAT_COMPLEX, - CPL_TYPE_DOUBLE_COMPLEX}; - const size_t ntype = sizeof(num_type)/sizeof(num_type[0]); + const cpl_type num_type[] = { CPL_TYPE_FLOAT_COMPLEX, + CPL_TYPE_DOUBLE_COMPLEX }; + const size_t ntype = sizeof(num_type) / sizeof(num_type[0]); cpl_array *myarray; @@ -128,11 +130,11 @@ cpl_test_nonnull(myarray); /* e^(i * pi) is -1, see man cpow() */ - cpl_array_test_power_complex_one(myarray, CPL_MATH_E, - CPL_MATH_PI * I, -1.0); + cpl_array_test_power_complex_one(myarray, CPL_MATH_E, CPL_MATH_PI * I, + -1.0); /* e^(i * pi/2) is i, see man cpow() */ - cpl_array_test_power_complex_one(myarray, CPL_MATH_E, - CPL_MATH_PI_2 * I, I); + cpl_array_test_power_complex_one(myarray, CPL_MATH_E, CPL_MATH_PI_2 * I, + I); cpl_array_delete(myarray); } @@ -148,18 +150,14 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_array_test_power(void) +static void +cpl_array_test_power(void) { - - const cpl_type num_type[] = {CPL_TYPE_INT, - CPL_TYPE_LONG, - CPL_TYPE_LONG_LONG, - CPL_TYPE_SIZE, - CPL_TYPE_FLOAT, - CPL_TYPE_FLOAT_COMPLEX, - CPL_TYPE_DOUBLE, - CPL_TYPE_DOUBLE_COMPLEX}; - const size_t ntype = sizeof(num_type)/sizeof(num_type[0]); + const cpl_type num_type[] = { CPL_TYPE_INT, CPL_TYPE_LONG, + CPL_TYPE_LONG_LONG, CPL_TYPE_SIZE, + CPL_TYPE_FLOAT, CPL_TYPE_FLOAT_COMPLEX, + CPL_TYPE_DOUBLE, CPL_TYPE_DOUBLE_COMPLEX }; + const size_t ntype = sizeof(num_type) / sizeof(num_type[0]); cpl_array *myarray; @@ -198,7 +196,7 @@ cpl_array_test_power_valid(myarray, 0.5, 2.0, 0.0); /* 8^(1/3) is 2, see man pow() */ - cpl_array_test_power_valid(myarray, 8.0, 1.0/3.0, 2.0); + cpl_array_test_power_valid(myarray, 8.0, 1.0 / 3.0, 2.0); /* 16^(1/4) is 2, see man pow() */ cpl_array_test_power_valid(myarray, 16.0, 0.25, 2.0); @@ -237,7 +235,8 @@ - (rounded to 1 for int types) */ if (mytype & (CPL_TYPE_FLOAT | CPL_TYPE_DOUBLE)) { cpl_array_test_power_valid(myarray, 256.0, -0.25, 0.25); - } else { + } + else { cpl_array_test_power_valid(myarray, 256.0, -0.25, 0.0); } @@ -290,7 +289,6 @@ } return; - } @@ -306,12 +304,11 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_array_test_power_valid(cpl_array *self, double x, double y, - double result) +static void +cpl_array_test_power_valid(cpl_array *self, double x, double y, double result) { - const cpl_type mytype = cpl_array_get_type(self); - int isvalid; + int isvalid; cpl_error_code code; code = cpl_array_set(self, 0, x); @@ -332,18 +329,18 @@ cpl_test_zero(isnull); cpl_test_abs(value, result, 0.0); } - } /*----------------------------------------------------------------------------*/ -static void cpl_array_test_power_complex_one(cpl_array *self, double x, - double complex y, - double complex result) +static void +cpl_array_test_power_complex_one(cpl_array *self, + double x, + double complex y, + double complex result) { - const cpl_type mytype = cpl_array_get_type(self); - int isvalid; - cpl_array* acopy; + int isvalid; + cpl_array *acopy; cpl_error_code code; code = cpl_array_set(self, 0, x); @@ -376,14 +373,15 @@ cpl_test_eq(isnull, 1); cpl_test_abs(value, 0.0, 0.0); if (mytype == CPL_TYPE_FLOAT) { - const float * fptr = cpl_array_get_data_float_const(self); + const float *fptr = cpl_array_get_data_float_const(self); cpl_test_abs(fptr[0], x, 0.0); } cpl_test_array_abs(self, acopy, 0.0); - } else { + } + else { int isnull, isnull2; - const double complex value = cpl_array_get_complex(self, 0, &isnull); + const double complex value = cpl_array_get_complex(self, 0, &isnull); const double complex value2 = cpl_array_get_complex(acopy, 0, &isnull2); cpl_test_eq(isvalid, 1); @@ -392,10 +390,12 @@ cpl_test_zero(isnull); cpl_test_zero(isnull2); if (!(y != (double)y)) - cpl_test_abs_complex(value, result, mytype & CPL_TYPE_FLOAT - ? FLT_EPSILON : DBL_EPSILON); - cpl_test_abs_complex(value2, result, mytype & CPL_TYPE_FLOAT - ? 2.0 * FLT_EPSILON : DBL_EPSILON); + cpl_test_abs_complex(value, result, + mytype & CPL_TYPE_FLOAT ? FLT_EPSILON + : DBL_EPSILON); + cpl_test_abs_complex(value2, result, + mytype & CPL_TYPE_FLOAT ? 2.0 * FLT_EPSILON + : DBL_EPSILON); } cpl_array_delete(acopy); } @@ -411,10 +411,11 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_array_test_power_invalid(cpl_array *self, double x, double y) +static void +cpl_array_test_power_invalid(cpl_array *self, double x, double y) { const cpl_type mytype = cpl_array_get_type(self); - int isvalid; + int isvalid; cpl_error_code code; code = cpl_array_set(self, 0, x); @@ -445,7 +446,7 @@ cpl_test_eq(isnull, 1); cpl_test_abs(value, 0.0, 0.0); if (mytype == CPL_TYPE_FLOAT) { - const float * fptr = cpl_array_get_data_float_const(self); + const float *fptr = cpl_array_get_data_float_const(self); cpl_test_abs(fptr[0], x, 0.0); } } @@ -462,9 +463,10 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_array_test_set_string(void) +static void +cpl_array_test_set_string(void) { - cpl_array * self = cpl_array_new(1, CPL_TYPE_STRING); + cpl_array *self = cpl_array_new(1, CPL_TYPE_STRING); cpl_error_code code; cpl_test_nonnull(self); @@ -476,7 +478,6 @@ cpl_test_eq_error(code, CPL_ERROR_ACCESS_OUT_OF_RANGE); cpl_array_delete(self); - } @@ -488,15 +489,15 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_array_test_new_complex(void) +static void +cpl_array_test_new_complex(void) { - - double darray[] = {1.0, 2.0}; - float farray[] = {1.0, 2.0}; + double darray[] = { 1.0, 2.0 }; + float farray[] = { 1.0, 2.0 }; cpl_array *null; - cpl_array *aint = cpl_array_new(1, CPL_TYPE_INT); + cpl_array *aint = cpl_array_new(1, CPL_TYPE_INT); cpl_array *adouble = cpl_array_new(1, CPL_TYPE_DOUBLE); - cpl_array *afloat = cpl_array_new(2, CPL_TYPE_FLOAT); + cpl_array *afloat = cpl_array_new(2, CPL_TYPE_FLOAT); cpl_array *acomp; cpl_test_nonnull(aint); @@ -552,7 +553,7 @@ cpl_array_delete(aint); adouble = cpl_array_wrap_double(darray, 2); - afloat = cpl_array_wrap_float(farray, 2); + afloat = cpl_array_wrap_float(farray, 2); acomp = cpl_array_new_complex_from_arrays(adouble, adouble); cpl_test_error(CPL_ERROR_NONE); diff -Nru cpl-7.1.4+ds/cplcore/tests/cpl_bivector-test.c cpl-7.2.2+ds/cplcore/tests/cpl_bivector-test.c --- cpl-7.1.4+ds/cplcore/tests/cpl_bivector-test.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/tests/cpl_bivector-test.c 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -30,7 +30,7 @@ #include "cpl_math_const.h" #ifndef FUNCTION_SIZE -#define FUNCTION_SIZE 1024 +#define FUNCTION_SIZE 1024 #endif #define LIN_SIZE 3 @@ -42,33 +42,34 @@ static cpl_error_code cpl_bivector_sort_ok(cpl_bivector *, const cpl_bivector *, cpl_sort_direction, - cpl_sort_mode, int); + cpl_sort_mode, + int); /*----------------------------------------------------------------------------- Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { - cpl_bivector * sinus; - cpl_bivector * cosinus; - cpl_bivector * tmp_fun; - cpl_bivector * source; - double * data_x, - * data_y; - const double * dnull; - const cpl_vector* vnull; - cpl_vector * vec1; - cpl_vector * vec2; - cpl_vector * vec3; - const double scale = CPL_MATH_2PI / FUNCTION_SIZE; - FILE * f_out; - const char * filename = "cpl_bivector_dump.txt"; - cpl_error_code error; - const double linear[LIN_SIZE] = {2.0, 3.0, 4.0}; - const double interpol[POL_SIZE] = {CPL_MATH_LN10, CPL_MATH_E, - CPL_MATH_PI}; - int i; - + cpl_bivector *sinus; + cpl_bivector *cosinus; + cpl_bivector *tmp_fun; + cpl_bivector *source; + double *data_x, *data_y; + const double *dnull; + const cpl_vector *vnull; + cpl_vector *vec1; + cpl_vector *vec2; + cpl_vector *vec3; + const double scale = CPL_MATH_2PI / FUNCTION_SIZE; + FILE *f_out; + const char *filename = "cpl_bivector_dump.txt"; + cpl_error_code error; + const double linear[LIN_SIZE] = { 2.0, 3.0, 4.0 }; + const double interpol[POL_SIZE] = { CPL_MATH_LN10, CPL_MATH_E, + CPL_MATH_PI }; + int i; + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); @@ -113,7 +114,7 @@ cpl_test_null(vnull); /* Create the first 1d function : sinus function */ - cpl_test_nonnull( sinus = cpl_bivector_new(FUNCTION_SIZE) ); + cpl_test_nonnull(sinus = cpl_bivector_new(FUNCTION_SIZE)); /* Fill the sinus function */ data_x = cpl_bivector_get_x_data(sinus); @@ -125,9 +126,9 @@ data_x[i] = i * scale; data_y[i] = sin(data_x[i]); } - + /* Create the second 1d function : cosinus function */ - cpl_test_nonnull (cosinus = cpl_bivector_new(FUNCTION_SIZE)); + cpl_test_nonnull(cosinus = cpl_bivector_new(FUNCTION_SIZE)); /* Fill the cosinus function */ data_x = cpl_bivector_get_x_data(cosinus); @@ -136,51 +137,51 @@ data_x[i] = i * scale - CPL_MATH_PI; data_y[i] = cos(data_x[i]); } - + /* Test cpl_bivector_get_y() */ - cpl_test_nonnull( cpl_bivector_get_y(sinus) ); - cpl_test_nonnull( cpl_bivector_get_x(sinus) ); - cpl_test_noneq_ptr( cpl_bivector_get_x(sinus), cpl_bivector_get_y(sinus) ); + cpl_test_nonnull(cpl_bivector_get_y(sinus)); + cpl_test_nonnull(cpl_bivector_get_x(sinus)); + cpl_test_noneq_ptr(cpl_bivector_get_x(sinus), cpl_bivector_get_y(sinus)); /* Test cpl_bivector_get_size() */ - cpl_test_eq( cpl_bivector_get_size(sinus), FUNCTION_SIZE ); - + cpl_test_eq(cpl_bivector_get_size(sinus), FUNCTION_SIZE); + /* Test cpl_bivector_dump() */ f_out = fopen(filename, "w"); - cpl_test_nonnull( f_out ); + cpl_test_nonnull(f_out); /* Will not print any values */ cpl_bivector_dump(NULL, f_out); cpl_bivector_dump(sinus, f_out); - cpl_test_zero( fclose(f_out) ); + cpl_test_zero(fclose(f_out)); /* Test cpl_bivector_read() */ tmp_fun = cpl_bivector_read(NULL); - cpl_test_error( CPL_ERROR_NULL_INPUT ); - cpl_test_null( tmp_fun ); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(tmp_fun); tmp_fun = cpl_bivector_read("/dev/null"); cpl_test_error(CPL_ERROR_BAD_FILE_FORMAT); - cpl_test_null( tmp_fun ); + cpl_test_null(tmp_fun); - cpl_test_nonnull( tmp_fun = cpl_bivector_duplicate(sinus) ); + cpl_test_nonnull(tmp_fun = cpl_bivector_duplicate(sinus)); cpl_bivector_delete(sinus); - cpl_test_nonnull( sinus = cpl_bivector_read(filename) ); + cpl_test_nonnull(sinus = cpl_bivector_read(filename)); cpl_test_zero(remove(filename)); /* Measure the error incurred through the dump/read */ - cpl_test_vector_abs(cpl_bivector_get_x(tmp_fun), - cpl_bivector_get_x(sinus), 48.0 * FLT_EPSILON); + cpl_test_vector_abs(cpl_bivector_get_x(tmp_fun), cpl_bivector_get_x(sinus), + 48.0 * FLT_EPSILON); - cpl_test_vector_abs(cpl_bivector_get_y(tmp_fun), - cpl_bivector_get_y(sinus), 6.0 * FLT_EPSILON); + cpl_test_vector_abs(cpl_bivector_get_y(tmp_fun), cpl_bivector_get_y(sinus), + 6.0 * FLT_EPSILON); cpl_bivector_delete(tmp_fun); - + /* Test cpl_bivector_interpolate_linear */ tmp_fun = cpl_bivector_new(FUNCTION_SIZE); vec1 = cpl_bivector_get_x(tmp_fun); @@ -223,20 +224,21 @@ cpl_bivector_delete(sinus); cpl_bivector_delete(cosinus); - sinus = cpl_bivector_new(FUNCTION_SIZE+1); + sinus = cpl_bivector_new(FUNCTION_SIZE + 1); /* Create a function with sine values, with abscissa offset by 0.5 */ data_x = cpl_bivector_get_x_data(sinus); data_y = cpl_bivector_get_y_data(sinus); for (i = 0; i < FUNCTION_SIZE + 1; i++) { - data_x[i] = (i-0.5) * scale; + data_x[i] = (i - 0.5) * scale; data_y[i] = sin(data_x[i]); } - + tmp_fun = cpl_bivector_new(FUNCTION_SIZE); vec1 = cpl_bivector_get_x(tmp_fun); data_x = cpl_vector_get_data(vec1); - for (i = 0; i < FUNCTION_SIZE; i++) data_x[i] = i * scale; + for (i = 0; i < FUNCTION_SIZE; i++) + data_x[i] = i * scale; error = cpl_bivector_interpolate_linear(tmp_fun, sinus); cpl_test_eq_error(error, CPL_ERROR_NONE); @@ -245,18 +247,19 @@ cpl_test_nonnull(data_y); /* Check interpolation error at 0, pi/2, pi, 3*pi/2 */ - cpl_test_abs( data_y[0], 0.0, FLT_EPSILON); + cpl_test_abs(data_y[0], 0.0, FLT_EPSILON); - cpl_test_abs( data_y[FUNCTION_SIZE/2], 0.0, 10 * DBL_EPSILON); + cpl_test_abs(data_y[FUNCTION_SIZE / 2], 0.0, 10 * DBL_EPSILON); - cpl_test_abs( 1.0, data_y[FUNCTION_SIZE/4], 1.0 / FUNCTION_SIZE ); - cpl_test_abs( -1.0, data_y[3*FUNCTION_SIZE/4], 1.0 / FUNCTION_SIZE ); + cpl_test_abs(1.0, data_y[FUNCTION_SIZE / 4], 1.0 / FUNCTION_SIZE); + cpl_test_abs(-1.0, data_y[3 * FUNCTION_SIZE / 4], 1.0 / FUNCTION_SIZE); cpl_bivector_delete(tmp_fun); tmp_fun = cpl_bivector_duplicate(sinus); - error = cpl_vector_copy(cpl_bivector_get_x(tmp_fun), cpl_bivector_get_x(sinus)); + error = + cpl_vector_copy(cpl_bivector_get_x(tmp_fun), cpl_bivector_get_x(sinus)); cpl_test_eq_error(error, CPL_ERROR_NONE); error = cpl_vector_fill(cpl_bivector_get_y(tmp_fun), 0.0); @@ -271,10 +274,10 @@ cpl_bivector_delete(tmp_fun); cpl_bivector_delete(sinus); - vec1 = cpl_vector_wrap(LIN_SIZE, (double*)linear); + vec1 = cpl_vector_wrap(LIN_SIZE, (double *)linear); source = cpl_bivector_wrap_vectors(vec1, vec1); - vec2 = cpl_vector_wrap(POL_SIZE, (double*)interpol); + vec2 = cpl_vector_wrap(POL_SIZE, (double *)interpol); vec3 = cpl_vector_new(POL_SIZE); tmp_fun = cpl_bivector_wrap_vectors(vec2, vec3); @@ -307,25 +310,27 @@ @see cpl_bivector_sort */ /*----------------------------------------------------------------------------*/ -static cpl_error_code cpl_bivector_sort_ok(cpl_bivector * self, - const cpl_bivector * other, - cpl_sort_direction dir, - cpl_sort_mode mode, int line) +static cpl_error_code +cpl_bivector_sort_ok(cpl_bivector *self, + const cpl_bivector *other, + cpl_sort_direction dir, + cpl_sort_mode mode, + int line) { const cpl_error_code error = cpl_bivector_sort(self, other, dir, mode); if (error != CPL_ERROR_NONE) { cpl_msg_error(cpl_func, "Failure from line %u", line); - } else { - cpl_vector * tosort = - cpl_vector_duplicate((mode == CPL_SORT_BY_X - ? cpl_bivector_get_x_const - : cpl_bivector_get_y_const)(other)); - const cpl_vector * sorted = (mode == CPL_SORT_BY_X - ? cpl_bivector_get_x_const - : cpl_bivector_get_y_const)(self); - const double * data = cpl_vector_get_data_const(sorted); - const int n = cpl_bivector_get_size(self); + } + else { + cpl_vector *tosort = cpl_vector_duplicate( + (mode == CPL_SORT_BY_X ? cpl_bivector_get_x_const + : cpl_bivector_get_y_const)(other)); + const cpl_vector *sorted = + (mode == CPL_SORT_BY_X ? cpl_bivector_get_x_const + : cpl_bivector_get_y_const)(self); + const double *data = cpl_vector_get_data_const(sorted); + const int n = cpl_bivector_get_size(self); const int ia = dir == CPL_SORT_ASCENDING ? 1 : 0; const int ib = dir == CPL_SORT_ASCENDING ? 0 : 1; int i; @@ -350,19 +355,19 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_bivector_sort_test(void) +static void +cpl_bivector_sort_test(void) { - /* In an ascending stable sort, both arrays will have same permutations */ - const double xval[] = {8.0, 1.0, 2.0, 3.0, 4.0, 4.0, 6.0, 7.0, 0.0}; - const double yval[] = {8.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 0.0}; - const int nvals = (int)(sizeof(xval)/sizeof(double)); - cpl_vector * tosortx = cpl_vector_wrap(nvals, (double*)xval); - cpl_vector * tosorty = cpl_vector_wrap(nvals, (double*)yval); - cpl_bivector * tosort = cpl_bivector_wrap_vectors(tosortx, tosorty); - cpl_bivector * sorted = cpl_bivector_new(nvals); - cpl_bivector * sorted2 = cpl_bivector_new(nvals); - cpl_bivector * toolong = cpl_bivector_new(nvals + 1); + const double xval[] = { 8.0, 1.0, 2.0, 3.0, 4.0, 4.0, 6.0, 7.0, 0.0 }; + const double yval[] = { 8.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 0.0 }; + const int nvals = (int)(sizeof(xval) / sizeof(double)); + cpl_vector *tosortx = cpl_vector_wrap(nvals, (double *)xval); + cpl_vector *tosorty = cpl_vector_wrap(nvals, (double *)yval); + cpl_bivector *tosort = cpl_bivector_wrap_vectors(tosortx, tosorty); + cpl_bivector *sorted = cpl_bivector_new(nvals); + cpl_bivector *sorted2 = cpl_bivector_new(nvals); + cpl_bivector *toolong = cpl_bivector_new(nvals + 1); cpl_error_code error; /* 1: Check error handling */ @@ -378,7 +383,8 @@ error = cpl_bivector_sort(sorted, tosort, 2, CPL_SORT_BY_X); cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); - error = cpl_bivector_sort(toolong, tosort, CPL_SORT_ASCENDING, CPL_SORT_BY_X); + error = + cpl_bivector_sort(toolong, tosort, CPL_SORT_ASCENDING, CPL_SORT_BY_X); cpl_test_eq_error(error, CPL_ERROR_INCOMPATIBLE_INPUT); /* 2: Sorting by X or Y doesn't matter with this data */ @@ -484,22 +490,23 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_bivector_sort_random(int size) { - - cpl_bivector * source = cpl_bivector_new(size); - cpl_bivector * destination = cpl_bivector_new(size); - double * xdata = cpl_bivector_get_x_data(source); - cpl_image * ximage = cpl_image_wrap_double(size, 1, xdata); - double * ydata = cpl_bivector_get_x_data(source); - cpl_image * yimage = cpl_image_wrap_double(size, 1, ydata); +static void +cpl_bivector_sort_random(int size) +{ + cpl_bivector *source = cpl_bivector_new(size); + cpl_bivector *destination = cpl_bivector_new(size); + double *xdata = cpl_bivector_get_x_data(source); + cpl_image *ximage = cpl_image_wrap_double(size, 1, xdata); + double *ydata = cpl_bivector_get_x_data(source); + cpl_image *yimage = cpl_image_wrap_double(size, 1, ydata); cpl_error_code error; int inplace; cpl_test_leq(1, size); for (inplace = 0; inplace < 2; inplace++) { - cpl_bivector * tosort = source; - cpl_bivector * sorted = destination; + cpl_bivector *tosort = source; + cpl_bivector *sorted = destination; error = cpl_image_fill_noise_uniform(ximage, -1.0, 1.0); cpl_test_eq_error(error, CPL_ERROR_NONE); diff -Nru cpl-7.1.4+ds/cplcore/tests/cpl_errorstate-test.c cpl-7.2.2+ds/cplcore/tests/cpl_errorstate-test.c --- cpl-7.1.4+ds/cplcore/tests/cpl_errorstate-test.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/tests/cpl_errorstate-test.c 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -46,15 +46,16 @@ /*----------------------------------------------------------------------------- Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { - cpl_error_code ierror; - cpl_errorstate state_none; - cpl_errorstate state, state1; + cpl_error_code ierror; + cpl_errorstate state_none; + cpl_errorstate state, state1; /* In order to produce a sequence of unique CPL errors, each call to cpl_error_set() is done with its own error code which is guatanteed not to originate from within CPL itself. */ - unsigned icode, ncode = (unsigned)CPL_ERROR_EOL; + unsigned icode, ncode = (unsigned)CPL_ERROR_EOL; unsigned i; @@ -66,7 +67,7 @@ /* This is a test for DFS05408 */ /* Set some errors */ - for (i=0; i < CPL_ERROR_HISTORY_SIZE/2; i++) { + for (i = 0; i < CPL_ERROR_HISTORY_SIZE / 2; i++) { cpl_error_set(cpl_func, i + ncode); } @@ -74,7 +75,7 @@ state1 = cpl_errorstate_get(); /* Overflow the error history */ - for (i=0; i < 2 * CPL_ERROR_HISTORY_SIZE; i++) { + for (i = 0; i < 2 * CPL_ERROR_HISTORY_SIZE; i++) { cpl_error_set(cpl_func, CPL_ERROR_ILLEGAL_INPUT); } @@ -103,43 +104,46 @@ cpl_errorstate_set(state_none); /* Test 1: Verify that the error state is empty on start-up */ - cpl_test( cpl_errorstate_is_equal(state_none) ); + cpl_test(cpl_errorstate_is_equal(state_none)); /* Test 1a: Verify that the current error cannot be used to modify the error state*/ cpl_errorstate_set(state_none); - cpl_test( cpl_errorstate_is_equal(state_none) ); + cpl_test(cpl_errorstate_is_equal(state_none)); cpl_errorstate_dump(state_none, CPL_FALSE, NULL); - nerrors = 0; did_dump = CPL_FALSE; + nerrors = 0; + did_dump = CPL_FALSE; cpl_errorstate_dump(state_none, CPL_FALSE, my_error_counter); - cpl_test_eq( nerrors, 1 ); - cpl_test_eq( did_dump, CPL_FALSE ); + cpl_test_eq(nerrors, 1); + cpl_test_eq(did_dump, CPL_FALSE); /* Test 2a: Detect a change in error state */ cpl_error_set_message(cpl_func, ++ncode, "Hello, world"); - cpl_test_zero( cpl_errorstate_is_equal(state_none) ); + cpl_test_zero(cpl_errorstate_is_equal(state_none)); cpl_errorstate_dump(state_none, CPL_FALSE, NULL); - nerrors = 0; did_dump = CPL_FALSE; + nerrors = 0; + did_dump = CPL_FALSE; cpl_errorstate_dump(state_none, CPL_FALSE, my_error_counter); - cpl_test_eq( nerrors, 1 ); - cpl_test_eq( did_dump, CPL_TRUE ); + cpl_test_eq(nerrors, 1); + cpl_test_eq(did_dump, CPL_TRUE); /* Test 2b: Try to dump zero errors with an existing errorstate */ cpl_errorstate_dump(cpl_errorstate_get(), CPL_FALSE, NULL); - nerrors = 0; did_dump = CPL_FALSE; + nerrors = 0; + did_dump = CPL_FALSE; cpl_errorstate_dump(cpl_errorstate_get(), CPL_FALSE, my_error_counter); - cpl_test_eq( nerrors, 1 ); - cpl_test_eq( did_dump, CPL_FALSE ); + cpl_test_eq(nerrors, 1); + cpl_test_eq(did_dump, CPL_FALSE); /* Add some errors without filling up the error history */ - for (ierror=1; ierror < CPL_ERROR_HISTORY_SIZE/2; ierror++) { + for (ierror = 1; ierror < CPL_ERROR_HISTORY_SIZE / 2; ierror++) { ++ncode; cpl_error_set_message(cpl_func, ncode, "Error-code=%u", (unsigned)ncode); - cpl_test_eq( ncode, cpl_error_get_code() ); + cpl_test_eq(ncode, cpl_error_get_code()); } /* Preserve that error for later tests */ @@ -147,55 +151,59 @@ icode = ncode; cpl_errorstate_dump(state_none, CPL_FALSE, NULL); - nerrors = 0; did_dump = CPL_FALSE; + nerrors = 0; + did_dump = CPL_FALSE; cpl_errorstate_dump(state_none, CPL_FALSE, my_error_counter); - cpl_test_eq( nerrors, CPL_ERROR_HISTORY_SIZE/2 ); - cpl_test_eq( did_dump, CPL_TRUE ); + cpl_test_eq(nerrors, CPL_ERROR_HISTORY_SIZE / 2); + cpl_test_eq(did_dump, CPL_TRUE); /* Test 3: Fill up the error history and check the 1st error */ - for (ierror=1; ierror < CPL_ERROR_HISTORY_SIZE; ierror++) { + for (ierror = 1; ierror < CPL_ERROR_HISTORY_SIZE; ierror++) { ++ncode; cpl_error_set_message(cpl_func, ncode, "Error-code=%u", (unsigned)ncode); - cpl_test_eq( ncode, cpl_error_get_code() ); + cpl_test_eq(ncode, cpl_error_get_code()); } - cpl_test_eq( ncode + 1, icode + CPL_ERROR_HISTORY_SIZE ); + cpl_test_eq(ncode + 1, icode + CPL_ERROR_HISTORY_SIZE); /* - error state is still non-empty */ - cpl_test_zero( cpl_errorstate_is_equal(state_none) ); + cpl_test_zero(cpl_errorstate_is_equal(state_none)); cpl_errorstate_dump(state_none, CPL_FALSE, NULL); - nerrors = 0; did_dump = CPL_FALSE; + nerrors = 0; + did_dump = CPL_FALSE; cpl_errorstate_dump(state_none, CPL_FALSE, my_error_counter); - cpl_test_eq( nerrors, CPL_ERROR_HISTORY_SIZE/2 - + CPL_ERROR_HISTORY_SIZE - 1); - cpl_test_eq( did_dump, CPL_TRUE ); + cpl_test_eq(nerrors, + CPL_ERROR_HISTORY_SIZE / 2 + CPL_ERROR_HISTORY_SIZE - 1); + cpl_test_eq(did_dump, CPL_TRUE); /* - different from the 1st error */ - cpl_test_zero( cpl_errorstate_is_equal(state) ); + cpl_test_zero(cpl_errorstate_is_equal(state)); cpl_errorstate_dump(state, CPL_FALSE, NULL); - nerrors = 0; did_dump = CPL_FALSE; + nerrors = 0; + did_dump = CPL_FALSE; cpl_errorstate_dump(state, CPL_FALSE, my_error_counter); - cpl_test_eq( nerrors, CPL_ERROR_HISTORY_SIZE - 1); - cpl_test_eq( did_dump, CPL_TRUE ); + cpl_test_eq(nerrors, CPL_ERROR_HISTORY_SIZE - 1); + cpl_test_eq(did_dump, CPL_TRUE); cpl_errorstate_set(state); cpl_errorstate_dump(state, CPL_FALSE, NULL); - nerrors = 0; did_dump = CPL_FALSE; + nerrors = 0; + did_dump = CPL_FALSE; cpl_errorstate_dump(state, CPL_FALSE, my_error_counter); - cpl_test_eq( nerrors, 1); - cpl_test_eq( did_dump, CPL_FALSE ); + cpl_test_eq(nerrors, 1); + cpl_test_eq(did_dump, CPL_FALSE); /* - the details of that 1st error are preserved */ - cpl_test_eq( cpl_error_get_code(), icode ); - cpl_test( cpl_error_get_line() != 0 ); - cpl_test_zero( strcmp(cpl_error_get_file(), __FILE__) ); - cpl_test_zero( strcmp(cpl_error_get_function(), cpl_func) ); + cpl_test_eq(cpl_error_get_code(), icode); + cpl_test(cpl_error_get_line() != 0); + cpl_test_zero(strcmp(cpl_error_get_file(), __FILE__)); + cpl_test_zero(strcmp(cpl_error_get_function(), cpl_func)); /* Set two new, 2nd and 3rd errors, discarding all errors set after 'state'. */ @@ -206,10 +214,11 @@ ++ncode; cpl_error_set_message(cpl_func, ncode, "Error-code=%u", (unsigned)ncode); - nerrors = 0; did_dump = CPL_FALSE; + nerrors = 0; + did_dump = CPL_FALSE; cpl_errorstate_dump(state, CPL_FALSE, my_error_counter); - cpl_test_eq( nerrors, 2); - cpl_test_eq( did_dump, CPL_TRUE ); + cpl_test_eq(nerrors, 2); + cpl_test_eq(did_dump, CPL_TRUE); /* Preserve that error for later tests */ state = cpl_errorstate_get(); @@ -217,79 +226,82 @@ cpl_errorstate_dump(state_none, CPL_FALSE, NULL); - nerrors = 0; did_dump = CPL_FALSE; + nerrors = 0; + did_dump = CPL_FALSE; cpl_errorstate_dump(state_none, CPL_FALSE, my_error_counter); - cpl_test_eq( nerrors, CPL_ERROR_HISTORY_SIZE/2 + 2); - cpl_test_eq( did_dump, CPL_TRUE ); + cpl_test_eq(nerrors, CPL_ERROR_HISTORY_SIZE / 2 + 2); + cpl_test_eq(did_dump, CPL_TRUE); /* Test 4: Fill up the error history and check that error */ - for (ierror=1; ierror < CPL_ERROR_HISTORY_SIZE; ierror++) { + for (ierror = 1; ierror < CPL_ERROR_HISTORY_SIZE; ierror++) { ++ncode; cpl_error_set_message(cpl_func, ncode, "Error-code=%u", (unsigned)ncode); - cpl_test_eq( ncode, cpl_error_get_code() ); + cpl_test_eq(ncode, cpl_error_get_code()); } - cpl_test_eq( ncode + 1, icode + CPL_ERROR_HISTORY_SIZE ); + cpl_test_eq(ncode + 1, icode + CPL_ERROR_HISTORY_SIZE); /* - error state is still non-empty */ - cpl_test_zero( cpl_errorstate_is_equal(state_none) ); + cpl_test_zero(cpl_errorstate_is_equal(state_none)); /* - different from the 3rd error */ - cpl_test_zero( cpl_errorstate_is_equal(state) ); + cpl_test_zero(cpl_errorstate_is_equal(state)); cpl_errorstate_dump(state_none, CPL_FALSE, NULL); - nerrors = 0; did_dump = CPL_FALSE; + nerrors = 0; + did_dump = CPL_FALSE; cpl_errorstate_dump(state_none, CPL_FALSE, my_error_counter); - cpl_test_eq( nerrors, CPL_ERROR_HISTORY_SIZE/2 - + CPL_ERROR_HISTORY_SIZE + 1); - cpl_test_eq( did_dump, CPL_TRUE ); + cpl_test_eq(nerrors, + CPL_ERROR_HISTORY_SIZE / 2 + CPL_ERROR_HISTORY_SIZE + 1); + cpl_test_eq(did_dump, CPL_TRUE); cpl_errorstate_set(state); /* - the details of that 3rd error are preserved */ - cpl_test_eq( cpl_error_get_code(), icode ); - cpl_test( cpl_error_get_line() != 0 ); - cpl_test_zero( strcmp(cpl_error_get_file(), __FILE__) ); - cpl_test_zero( strcmp(cpl_error_get_function(), cpl_func) ); + cpl_test_eq(cpl_error_get_code(), icode); + cpl_test(cpl_error_get_line() != 0); + cpl_test_zero(strcmp(cpl_error_get_file(), __FILE__)); + cpl_test_zero(strcmp(cpl_error_get_function(), cpl_func)); /* Test 5: Fill the error history and check the 3rd error */ - for (ierror=1; ierror < CPL_ERROR_HISTORY_SIZE; ierror++) { + for (ierror = 1; ierror < CPL_ERROR_HISTORY_SIZE; ierror++) { ++ncode; cpl_error_set_message(cpl_func, ncode, "Error-code=%u", (unsigned)ncode); - cpl_test_eq( ncode, cpl_error_get_code() ); + cpl_test_eq(ncode, cpl_error_get_code()); } - cpl_test_eq( ncode + 2, icode + 2 * CPL_ERROR_HISTORY_SIZE ); + cpl_test_eq(ncode + 2, icode + 2 * CPL_ERROR_HISTORY_SIZE); /* - and error state is still non-empty */ - cpl_test_zero( cpl_errorstate_is_equal(state_none) ); + cpl_test_zero(cpl_errorstate_is_equal(state_none)); /* - and different from the 3rd error */ - cpl_test_zero( cpl_errorstate_is_equal(state) ); + cpl_test_zero(cpl_errorstate_is_equal(state)); cpl_errorstate_dump(state_none, CPL_TRUE, NULL); - nerrors = 0; did_dump = CPL_FALSE; + nerrors = 0; + did_dump = CPL_FALSE; cpl_errorstate_dump(state_none, CPL_TRUE, my_error_counter); - cpl_test_eq( nerrors, CPL_ERROR_HISTORY_SIZE/2 - + CPL_ERROR_HISTORY_SIZE + 1); - cpl_test_eq( did_dump, CPL_TRUE ); + cpl_test_eq(nerrors, + CPL_ERROR_HISTORY_SIZE / 2 + CPL_ERROR_HISTORY_SIZE + 1); + cpl_test_eq(did_dump, CPL_TRUE); /* Test 6: Set the error state back to that 3rd error */ cpl_errorstate_set(state); /* - error state is still non-empty */ - cpl_test_zero( cpl_errorstate_is_equal(state_none) ); + cpl_test_zero(cpl_errorstate_is_equal(state_none)); /* - and distinguiable from the 2nd error */ - cpl_test_zero( cpl_errorstate_is_equal(state1) ); + cpl_test_zero(cpl_errorstate_is_equal(state1)); /* - and the details of that 3rd error are preserved */ - cpl_test_eq( cpl_error_get_code(), icode ); - cpl_test( cpl_error_get_line() != 0); - cpl_test_zero( strcmp(cpl_error_get_file(), __FILE__) ); - cpl_test_zero( strcmp(cpl_error_get_function(), cpl_func) ); + cpl_test_eq(cpl_error_get_code(), icode); + cpl_test(cpl_error_get_line() != 0); + cpl_test_zero(strcmp(cpl_error_get_file(), __FILE__)); + cpl_test_zero(strcmp(cpl_error_get_function(), cpl_func)); /* Test 7: Verify that the details of the previous, 2nd error have been lost */ @@ -297,24 +309,24 @@ cpl_errorstate_set(state1); /* - error state is still non-empty */ - cpl_test_zero( cpl_errorstate_is_equal(state_none) ); + cpl_test_zero(cpl_errorstate_is_equal(state_none)); /* - and distinguiable from the 3rd error */ - cpl_test_zero( cpl_errorstate_is_equal(state) ); + cpl_test_zero(cpl_errorstate_is_equal(state)); /* - but the details of that 2nd error has been lost */ - cpl_test_eq( cpl_error_get_code(), CPL_ERROR_HISTORY_LOST ); - cpl_test_zero( cpl_error_get_line()); - cpl_test_zero( strlen(cpl_error_get_file()) ); - cpl_test_zero( strlen(cpl_error_get_function()) ); + cpl_test_eq(cpl_error_get_code(), CPL_ERROR_HISTORY_LOST); + cpl_test_zero(cpl_error_get_line()); + cpl_test_zero(strlen(cpl_error_get_file())); + cpl_test_zero(strlen(cpl_error_get_function())); /* Test 8: Verify that error state cannot be advanced */ cpl_errorstate_set(state); - cpl_test( cpl_errorstate_is_equal(state1) ); + cpl_test(cpl_errorstate_is_equal(state1)); /* Test 8: Verify that error state can be cleared regardless */ cpl_errorstate_set(state_none); - cpl_test( cpl_errorstate_is_equal(state_none) ); + cpl_test(cpl_errorstate_is_equal(state_none)); /* All tests are finished */ return cpl_test_end(0); @@ -334,8 +346,9 @@ */ /*----------------------------------------------------------------------------*/ -static void my_error_counter(unsigned self, unsigned first, unsigned last) { - +static void +my_error_counter(unsigned self, unsigned first, unsigned last) +{ static cpl_errorstate prevstate; /* Don't try this at home */ static unsigned preverror; @@ -343,9 +356,10 @@ if (self != first) { /* Error dump must be in steps of 1 */ if (first < last) { - cpl_test_eq( self, preverror + 1 ); - } else { - cpl_test_eq( self, preverror - 1 ); + cpl_test_eq(self, preverror + 1); + } + else { + cpl_test_eq(self, preverror - 1); } /* Verify that the CPL error state cannot be modified from here */ cpl_errorstate_set(prevstate); @@ -362,6 +376,6 @@ nerrors++; - if (first != 0 || last != 0) did_dump = CPL_TRUE; - + if (first != 0 || last != 0) + did_dump = CPL_TRUE; } diff -Nru cpl-7.1.4+ds/cplcore/tests/cpl_error-test.c cpl-7.2.2+ds/cplcore/tests/cpl_error-test.c --- cpl-7.1.4+ds/cplcore/tests/cpl_error-test.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/tests/cpl_error-test.c 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -50,11 +50,12 @@ /*----------------------------------------------------------------------------- Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { - const cpl_boolean has_func - = strcmp(cpl_func, "main") ? CPL_FALSE : CPL_TRUE; - cpl_error_code ierror; + const cpl_boolean has_func = + strcmp(cpl_func, "main") ? CPL_FALSE : CPL_TRUE; + cpl_error_code ierror; cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); @@ -63,70 +64,70 @@ /* Test 1: Verify that the error state is empty on start-up */ - cpl_test_zero( CPL_ERROR_NONE ); - cpl_test_eq( cpl_error_get_code(), CPL_ERROR_NONE ); - cpl_test_zero( cpl_error_get_line() ); - cpl_test_zero( strlen(cpl_error_get_function()) ); - cpl_test_zero( strlen(cpl_error_get_file()) ); + cpl_test_zero(CPL_ERROR_NONE); + cpl_test_eq(cpl_error_get_code(), CPL_ERROR_NONE); + cpl_test_zero(cpl_error_get_line()); + cpl_test_zero(strlen(cpl_error_get_function())); + cpl_test_zero(strlen(cpl_error_get_file())); /* Test 1b: Verify that cpl_error_set() will not change that */ - cpl_test_eq( cpl_error_test_set(CPL_ERROR_NONE), CPL_ERROR_NONE ); - cpl_test_eq( cpl_error_get_code(), CPL_ERROR_NONE ); - cpl_test_zero( cpl_error_get_line() ); - cpl_test_zero( strlen(cpl_error_get_function()) ); - cpl_test_zero( strlen(cpl_error_get_file()) ); + cpl_test_eq(cpl_error_test_set(CPL_ERROR_NONE), CPL_ERROR_NONE); + cpl_test_eq(cpl_error_get_code(), CPL_ERROR_NONE); + cpl_test_zero(cpl_error_get_line()); + cpl_test_zero(strlen(cpl_error_get_function())); + cpl_test_zero(strlen(cpl_error_get_file())); /* Test 1c: Verify that cpl_error_set_where() will not change that */ - cpl_test_eq( cpl_error_test_set_where(), CPL_ERROR_NONE ); - cpl_test_eq( cpl_error_get_code(), CPL_ERROR_NONE ); - cpl_test_zero( cpl_error_get_line() ); - cpl_test_zero( strlen(cpl_error_get_function()) ); - cpl_test_zero( strlen(cpl_error_get_file()) ); + cpl_test_eq(cpl_error_test_set_where(), CPL_ERROR_NONE); + cpl_test_eq(cpl_error_get_code(), CPL_ERROR_NONE); + cpl_test_zero(cpl_error_get_line()); + cpl_test_zero(strlen(cpl_error_get_function())); + cpl_test_zero(strlen(cpl_error_get_file())); /* Test 1d: Verify that cpl_error_set_message() will not change that */ - cpl_test_eq( cpl_error_test_set_message(CPL_ERROR_NONE), CPL_ERROR_NONE); - cpl_test_eq( cpl_error_get_code(), CPL_ERROR_NONE ); - cpl_test_zero( cpl_error_get_line() ); - cpl_test_zero( strlen(cpl_error_get_function()) ); - cpl_test_zero( strlen(cpl_error_get_file()) ); + cpl_test_eq(cpl_error_test_set_message(CPL_ERROR_NONE), CPL_ERROR_NONE); + cpl_test_eq(cpl_error_get_code(), CPL_ERROR_NONE); + cpl_test_zero(cpl_error_get_line()); + cpl_test_zero(strlen(cpl_error_get_function())); + cpl_test_zero(strlen(cpl_error_get_file())); /* Test 1e: Verify that cpl_error_set_fits() will not change that */ - cpl_test_eq( cpl_error_test_set_fits(CPL_ERROR_NONE), CPL_ERROR_NONE); - cpl_test_eq( cpl_error_get_code(), CPL_ERROR_NONE ); - cpl_test_zero( cpl_error_get_line() ); - cpl_test_zero( strlen(cpl_error_get_function()) ); - cpl_test_zero( strlen(cpl_error_get_file()) ); + cpl_test_eq(cpl_error_test_set_fits(CPL_ERROR_NONE), CPL_ERROR_NONE); + cpl_test_eq(cpl_error_get_code(), CPL_ERROR_NONE); + cpl_test_zero(cpl_error_get_line()); + cpl_test_zero(strlen(cpl_error_get_function())); + cpl_test_zero(strlen(cpl_error_get_file())); /* Test 1f: Verify that cpl_error_set_regex() will not change that */ - cpl_test_eq( cpl_error_test_set_regex(CPL_ERROR_NONE), CPL_ERROR_NONE); - cpl_test_eq( cpl_error_get_code(), CPL_ERROR_NONE ); - cpl_test_zero( cpl_error_get_line() ); - cpl_test_zero( strlen(cpl_error_get_function()) ); - cpl_test_zero( strlen(cpl_error_get_file()) ); + cpl_test_eq(cpl_error_test_set_regex(CPL_ERROR_NONE), CPL_ERROR_NONE); + cpl_test_eq(cpl_error_get_code(), CPL_ERROR_NONE); + cpl_test_zero(cpl_error_get_line()); + cpl_test_zero(strlen(cpl_error_get_function())); + cpl_test_zero(strlen(cpl_error_get_file())); /* Do a number of tests on all (other) error codes */ - for (ierror = CPL_ERROR_NONE; ierror <= CPL_ERROR_EOL+1; ierror++) { - + for (ierror = CPL_ERROR_NONE; ierror <= CPL_ERROR_EOL + 1; ierror++) { char msg[CPL_ERROR_MAX_MESSAGE_LENGTH]; unsigned line; /* The expected error code */ - const cpl_error_code eerror = ierror == CPL_ERROR_HISTORY_LOST - ? CPL_ERROR_UNSPECIFIED : ierror; + const cpl_error_code eerror = + ierror == CPL_ERROR_HISTORY_LOST ? CPL_ERROR_UNSPECIFIED : ierror; /* Test 2: Verify that cpl_error_set_message() correctly sets the error */ - cpl_test_eq( cpl_error_test_set_message(ierror), eerror ); - cpl_test_eq( cpl_error_get_code(), eerror ); + cpl_test_eq(cpl_error_test_set_message(ierror), eerror); + cpl_test_eq(cpl_error_get_code(), eerror); /* - Except if the CPL error code is CPL_ERROR_NONE */ - if (ierror == CPL_ERROR_NONE) continue; + if (ierror == CPL_ERROR_NONE) + continue; - cpl_test( cpl_error_get_line() > __LINE__ ); + cpl_test(cpl_error_get_line() > __LINE__); cpl_test_eq_string(cpl_error_get_file(), __FILE__); cpl_test_eq_string(cpl_error_get_function(), "hardcoded"); @@ -138,28 +139,28 @@ cpl_error_get_message()); strncpy(msg, cpl_error_get_message(), CPL_ERROR_MAX_MESSAGE_LENGTH); - msg[CPL_ERROR_MAX_MESSAGE_LENGTH-1] = '\0'; + msg[CPL_ERROR_MAX_MESSAGE_LENGTH - 1] = '\0'; - cpl_test( strlen(msg) > 0 ); + cpl_test(strlen(msg) > 0); /* Test 3: Verify that cpl_error_set_message() correctly sets the error */ - cpl_test_eq( cpl_error_test_set_message_empty(ierror), eerror ); - cpl_test_eq( cpl_error_get_code(), eerror ); - cpl_test( cpl_error_get_line() > __LINE__ ); + cpl_test_eq(cpl_error_test_set_message_empty(ierror), eerror); + cpl_test_eq(cpl_error_get_code(), eerror); + cpl_test(cpl_error_get_line() > __LINE__); cpl_test_eq_string(cpl_error_get_file(), __FILE__); cpl_test_eq_string(cpl_error_get_function(), "hardcoded"); - cpl_test_eq_string( cpl_error_get_message(), - cpl_error_get_message_default(eerror) ); + cpl_test_eq_string(cpl_error_get_message(), + cpl_error_get_message_default(eerror)); /* Test 4: Verify that cpl_error_set_fits() correctly sets the error */ - cpl_test_eq( cpl_error_test_set_fits(ierror), eerror ); - cpl_test_eq( cpl_error_get_code(), eerror ); - cpl_test( cpl_error_get_line() > __LINE__ ); + cpl_test_eq(cpl_error_test_set_fits(ierror), eerror); + cpl_test_eq(cpl_error_get_code(), eerror); + cpl_test(cpl_error_get_line() > __LINE__); cpl_test_eq_string(cpl_error_get_file(), __FILE__); cpl_test_eq_string(cpl_error_get_function(), "cpl_error_test_set_fits"); @@ -173,19 +174,20 @@ /* Test 5: Verify that cpl_error_reset() correctly resets the error */ cpl_error_reset(); - cpl_test_eq( cpl_error_get_code(), CPL_ERROR_NONE ); - cpl_test_zero( cpl_error_get_line() ); - cpl_test_zero( strlen(cpl_error_get_function()) ); - cpl_test_zero( strlen(cpl_error_get_file()) ); + cpl_test_eq(cpl_error_get_code(), CPL_ERROR_NONE); + cpl_test_zero(cpl_error_get_line()); + cpl_test_zero(strlen(cpl_error_get_function())); + cpl_test_zero(strlen(cpl_error_get_file())); /* Test 4a: Verify that cpl_error_set_regex() correctly sets the error */ - cpl_test_eq( cpl_error_test_set_regex(ierror), eerror ); - cpl_test_eq( cpl_error_get_code(), eerror ); - cpl_test( cpl_error_get_line() > __LINE__ ); + cpl_test_eq(cpl_error_test_set_regex(ierror), eerror); + cpl_test_eq(cpl_error_get_code(), eerror); + cpl_test(cpl_error_get_line() > __LINE__); cpl_test_eq_string(cpl_error_get_file(), __FILE__); - cpl_test_eq_string(cpl_error_get_function(), "cpl_error_test_set_regex"); + cpl_test_eq_string(cpl_error_get_function(), + "cpl_error_test_set_regex"); cpl_test_noneq_string(cpl_error_get_message(), cpl_error_get_message_default(eerror)); @@ -197,64 +199,63 @@ /* Test 5a: Verify that cpl_error_reset() correctly resets the error */ cpl_error_reset(); - cpl_test_eq( cpl_error_get_code(), CPL_ERROR_NONE ); - cpl_test_zero( cpl_error_get_line() ); - cpl_test_zero( strlen(cpl_error_get_function()) ); - cpl_test_zero( strlen(cpl_error_get_file()) ); + cpl_test_eq(cpl_error_get_code(), CPL_ERROR_NONE); + cpl_test_zero(cpl_error_get_line()); + cpl_test_zero(strlen(cpl_error_get_function())); + cpl_test_zero(strlen(cpl_error_get_file())); /* Test 6: Verify that cpl_ensure() correctly sets the error */ - cpl_test_eq( cpl_error_test_ensure(ierror), eerror ); - cpl_test_eq( cpl_error_get_code(), eerror ); - cpl_test( cpl_error_get_line() > __LINE__ ); + cpl_test_eq(cpl_error_test_ensure(ierror), eerror); + cpl_test_eq(cpl_error_get_code(), eerror); + cpl_test(cpl_error_get_line() > __LINE__); cpl_test_eq_string(cpl_error_get_file(), __FILE__); - cpl_test_eq_ptr( strstr(msg, cpl_error_get_message()), msg ); - cpl_test( strlen(msg) > strlen(cpl_error_get_message()) ); + cpl_test_eq_ptr(strstr(msg, cpl_error_get_message()), msg); + cpl_test(strlen(msg) > strlen(cpl_error_get_message())); if (has_func) - cpl_test_eq_string( cpl_error_get_function(), - "cpl_error_test_ensure" ); + cpl_test_eq_string(cpl_error_get_function(), + "cpl_error_test_ensure"); line = cpl_error_get_line(); /* Test 7: Verify that cpl_error_set_where() propagates correctly */ - cpl_test_eq( cpl_error_test_set_where(), eerror ); - cpl_test_eq( cpl_error_get_code(), eerror ); - cpl_test( cpl_error_get_line() > __LINE__ ); - cpl_test_noneq( cpl_error_get_line(), line ); + cpl_test_eq(cpl_error_test_set_where(), eerror); + cpl_test_eq(cpl_error_get_code(), eerror); + cpl_test(cpl_error_get_line() > __LINE__); + cpl_test_noneq(cpl_error_get_line(), line); cpl_test_eq_string(cpl_error_get_file(), __FILE__); - cpl_test( strstr(msg, cpl_error_get_message()) == msg ); - cpl_test( strlen(msg) > strlen(cpl_error_get_message()) ); + cpl_test(strstr(msg, cpl_error_get_message()) == msg); + cpl_test(strlen(msg) > strlen(cpl_error_get_message())); if (has_func) - cpl_test_eq_string( cpl_error_get_function(), "where" ); + cpl_test_eq_string(cpl_error_get_function(), "where"); /* Test 8: Verify that cpl_error_set() correctly sets the error */ - cpl_test_eq( cpl_error_test_set(ierror), eerror ); - cpl_test_eq( cpl_error_get_code(), eerror ); - cpl_test( cpl_error_get_line() > __LINE__ ); + cpl_test_eq(cpl_error_test_set(ierror), eerror); + cpl_test_eq(cpl_error_get_code(), eerror); + cpl_test(cpl_error_get_line() > __LINE__); cpl_test_eq_string(cpl_error_get_file(), __FILE__); - cpl_test( strstr(msg, cpl_error_get_message()) == msg ); - cpl_test( strlen(msg) > strlen(cpl_error_get_message()) ); + cpl_test(strstr(msg, cpl_error_get_message()) == msg); + cpl_test(strlen(msg) > strlen(cpl_error_get_message())); if (has_func) - cpl_test_eq_string( cpl_error_get_function(), "set" ); + cpl_test_eq_string(cpl_error_get_function(), "set"); /* Test 9: Verify that cpl_error_reset() correctly resets the error */ cpl_error_reset(); - cpl_test_eq( cpl_error_get_code(), CPL_ERROR_NONE ); - cpl_test_zero( cpl_error_get_line() ); - cpl_test_zero( strlen(cpl_error_get_function()) ); - cpl_test_zero( strlen(cpl_error_get_file()) ); - + cpl_test_eq(cpl_error_get_code(), CPL_ERROR_NONE); + cpl_test_zero(cpl_error_get_line()); + cpl_test_zero(strlen(cpl_error_get_function())); + cpl_test_zero(strlen(cpl_error_get_file())); } /* End of actual test code */ @@ -270,7 +271,8 @@ */ /*----------------------------------------------------------------------------*/ -static cpl_error_code cpl_error_test_set(cpl_error_code code) +static cpl_error_code +cpl_error_test_set(cpl_error_code code) { return cpl_error_set("set", code); } @@ -284,16 +286,17 @@ */ /*----------------------------------------------------------------------------*/ -static cpl_error_code cpl_error_test_set_where(void) +static cpl_error_code +cpl_error_test_set_where(void) { - const cpl_error_code error = cpl_error_set_where("where"); - const char * where = cpl_error_get_where(); + const char *where = cpl_error_get_where(); if (error) { cpl_test_eq_ptr(where, strstr(where, "where")); cpl_test_nonnull(strstr(where, __FILE__)); - } else { + } + else { cpl_test_null(strstr(where, "where")); cpl_test_null(strstr(where, __FILE__)); } @@ -311,9 +314,9 @@ */ /*----------------------------------------------------------------------------*/ -static cpl_error_code cpl_error_test_set_message(cpl_error_code code) +static cpl_error_code +cpl_error_test_set_message(cpl_error_code code) { - return cpl_error_set_message("hardcoded", code, "Error-code=%u", (unsigned)code); } @@ -328,9 +331,9 @@ */ /*----------------------------------------------------------------------------*/ -static cpl_error_code cpl_error_test_set_fits(cpl_error_code code) +static cpl_error_code +cpl_error_test_set_fits(cpl_error_code code) { - return cpl_error_set_fits(code, 0, "cfitsio_dummy", "Error-code=%u", (unsigned)code); } @@ -345,15 +348,15 @@ */ /*----------------------------------------------------------------------------*/ -static cpl_error_code cpl_error_test_set_regex(cpl_error_code code) +static cpl_error_code +cpl_error_test_set_regex(cpl_error_code code) { - regex_t re; const int errcode = regcomp(&re, ")|(", REG_EXTENDED | REG_NOSUB); - const cpl_error_code rcode - = cpl_error_set_regex(code, errcode, - code == CPL_ERROR_NULL_INPUT ? NULL : &re, - "Error-code=%u", (unsigned)code); + const cpl_error_code rcode = + cpl_error_set_regex(code, errcode, + code == CPL_ERROR_NULL_INPUT ? NULL : &re, + "Error-code=%u", (unsigned)code); regfree(&re); return rcode; @@ -369,7 +372,8 @@ */ /*----------------------------------------------------------------------------*/ -static cpl_error_code cpl_error_test_set_message_empty(cpl_error_code code) +static cpl_error_code +cpl_error_test_set_message_empty(cpl_error_code code) { return cpl_error_set_message("hardcoded", code, " "); } @@ -384,9 +388,8 @@ */ /*----------------------------------------------------------------------------*/ -static cpl_error_code cpl_error_test_ensure(cpl_error_code code) +static cpl_error_code +cpl_error_test_ensure(cpl_error_code code) { - cpl_ensure_code(0, code); - } diff -Nru cpl-7.1.4+ds/cplcore/tests/cpl_filter_body.h cpl-7.2.2+ds/cplcore/tests/cpl_filter_body.h --- cpl-7.1.4+ds/cplcore/tests/cpl_filter_body.h 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/tests/cpl_filter_body.h 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -20,43 +20,44 @@ #define TYPE_ADD(a) CONCAT2X(a, PIXEL_TYPE) -static void -TYPE_ADD(filter_median_bf)(const PIXEL_TYPE *in, PIXEL_TYPE *out, - unsigned Nx, unsigned Ny, unsigned Rx, unsigned Ry, - unsigned mode) +static void TYPE_ADD(filter_median_bf)(const PIXEL_TYPE *in, + PIXEL_TYPE *out, + unsigned Nx, + unsigned Ny, + unsigned Rx, + unsigned Ry, + unsigned mode) { - PIXEL_TYPE *data = cpl_malloc((size_t)(2*Rx+1) * (size_t)(2*Ry+1) - * sizeof(*data)); + PIXEL_TYPE *data = + cpl_malloc((size_t)(2 * Rx + 1) * (size_t)(2 * Ry + 1) * sizeof(*data)); if (mode == CPL_BORDER_FILTER) { #ifdef CPL_MEDIAN_SAMPLE - const unsigned Nx_larger = Nx + 2*Rx; - const unsigned Ny_larger = Ny + 2*Ry; + const unsigned Nx_larger = Nx + 2 * Rx; + const unsigned Ny_larger = Ny + 2 * Ry; - PIXEL_TYPE *in_larger = cpl_malloc((size_t)Nx_larger * (size_t)Ny_larger - * sizeof(*in_larger)); - assure( in_larger != NULL ); - - TYPE_ADD(cpl_image_filter_fill_chess)(in_larger, in, Nx_larger, - Ny_larger, Nx, Ny, Rx, Ry); - - TYPE_ADD(filter_median_bf)(in_larger, out, - Nx_larger, Ny_larger, - Rx, Ry, - CPL_BORDER_CROP); + PIXEL_TYPE *in_larger = cpl_malloc( + (size_t)Nx_larger * (size_t)Ny_larger * sizeof(*in_larger)); + assure(in_larger != NULL); + + TYPE_ADD(cpl_image_filter_fill_chess) + (in_larger, in, Nx_larger, Ny_larger, Nx, Ny, Rx, Ry); + + TYPE_ADD(filter_median_bf) + (in_larger, out, Nx_larger, Ny_larger, Rx, Ry, CPL_BORDER_CROP); cpl_free(in_larger); #else cpl_size y; for (y = 0; y < Ny; y++) { - const size_t y_1 = CX_MAX(0, y - Ry); - const size_t y2 = CX_MIN(Ny-1, y + Ry); + const size_t y_1 = CX_MAX(0, y - Ry); + const size_t y2 = CX_MIN(Ny - 1, y + Ry); cpl_size x; for (x = 0; x < Nx; x++) { - const size_t x1 = CX_MAX(0, x - Rx); - const size_t x2 = CX_MIN(Nx-1, x + Rx); + const size_t x1 = CX_MAX(0, x - Rx); + const size_t x2 = CX_MIN(Nx - 1, x + Rx); - const PIXEL_TYPE * inj = in + y_1 * Nx; + const PIXEL_TYPE *inj = in + y_1 * Nx; size_t k = 0; size_t i, j; @@ -66,54 +67,57 @@ data[k++] = inj[i]; } } - assert( k <= (size_t)(2*Rx+1) * (size_t)(2*Ry+1)); + assert(k <= (size_t)(2 * Rx + 1) * (size_t)(2 * Ry + 1)); out[x + y * Nx] = TYPE_ADD(cpl_tools_get_median)(data, k); } } #endif - } else { + } + else { unsigned y; if (mode == CPL_BORDER_CROP) { out += Rx; - } else { - if (mode == CPL_BORDER_COPY) - (void)memcpy(out, in, (Ry*Nx+Rx)*sizeof(*out)); + } + else { + if (mode == CPL_BORDER_COPY) + (void)memcpy(out, in, (Ry * Nx + Rx) * sizeof(*out)); out += Ry * Nx; } - for (y = 0 + Ry; y < Ny-Ry; y++, out += Nx) { + for (y = 0 + Ry; y < Ny - Ry; y++, out += Nx) { unsigned x = Rx; if (mode == CPL_BORDER_CROP) { - out -= 2*Rx; /* Nx - 2 Rx medians in each row */ - } else if (mode == CPL_BORDER_COPY) { + out -= 2 * Rx; /* Nx - 2 Rx medians in each row */ + } + else if (mode == CPL_BORDER_COPY) { if (y != Ry) { - (void)memcpy(out-Rx, in + y * Nx - Rx, 2*Rx*sizeof(*out)); + (void)memcpy(out - Rx, in + y * Nx - Rx, + 2 * Rx * sizeof(*out)); } } for (; x < Nx - Rx; x++) { unsigned k = 0; unsigned i, j; - for (j = y-Ry; j <= y+Ry; j++) - for (i = x-Rx; i <= x+Rx; i++) - data[k++] = in[i + j*Nx]; - + for (j = y - Ry; j <= y + Ry; j++) + for (i = x - Rx; i <= x + Rx; i++) + data[k++] = in[i + j * Nx]; + out[x] = TYPE_ADD(cpl_tools_get_median)(data, k); } if (mode == CPL_BORDER_COPY) { if (y == Ny - Ry - 1) { - (void)memcpy(out + Nx-Rx, - in + Nx-Rx + y * Nx, - Rx*sizeof(*out)); + (void)memcpy(out + Nx - Rx, in + Nx - Rx + y * Nx, + Rx * sizeof(*out)); } } } if (mode == CPL_BORDER_COPY) { - (void)memcpy(out, in + y * Nx, Ry*Nx*sizeof(*out)); + (void)memcpy(out, in + y * Nx, Ry * Nx * sizeof(*out)); } } @@ -122,37 +126,39 @@ } -static void -TYPE_ADD(test_cpl_image_filter)(unsigned Nx, unsigned Ny, - unsigned Rx, unsigned Ry, - unsigned filter, - unsigned border_mode, - unsigned Nreps1, - unsigned Nreps2) +static void TYPE_ADD(test_cpl_image_filter)(unsigned Nx, + unsigned Ny, + unsigned Rx, + unsigned Ry, + unsigned filter, + unsigned border_mode, + unsigned Nreps1, + unsigned Nreps2) { - - PIXEL_TYPE *in = cpl_malloc((size_t)Nx * (size_t)Ny * sizeof(*in)); + PIXEL_TYPE *in = cpl_malloc((size_t)Nx * (size_t)Ny * sizeof(*in)); /* Too large in crop mode */ PIXEL_TYPE *out = cpl_malloc((size_t)Nx * (size_t)Ny * sizeof(*out)); /* Too large in crop mode */ PIXEL_TYPE *ref = cpl_malloc((size_t)Nx * (size_t)Ny * sizeof(*ref)); - cpl_mask * mask = cpl_mask_new(1 + 2 * Rx, 1 + 2 * Ry); + cpl_mask *mask = cpl_mask_new(1 + 2 * Rx, 1 + 2 * Ry); const double myeps #ifdef PIXEL_TYPE_IS_INT = 0.0; #else - = filter == CPL_FILTER_MEDIAN ? 0.0 - : 1e1 * Nx * Ny * (sizeof(PIXEL_TYPE) == 4 ? FLT_EPSILON : DBL_EPSILON); + = filter == CPL_FILTER_MEDIAN + ? 0.0 + : 1e1 * Nx * Ny * + (sizeof(PIXEL_TYPE) == 4 ? FLT_EPSILON : DBL_EPSILON); #endif cpl_error_code error; - assure( Nx > 0 ); - assure( Ny > 0 ); + assure(Nx > 0); + assure(Ny > 0); - assure( in != NULL ); - assure( out != NULL ); - assure( ref != NULL ); - assure( mask != NULL ); + assure(in != NULL); + assure(out != NULL); + assure(ref != NULL); + assure(mask != NULL); error = cpl_mask_not(mask); cpl_test_eq_error(error, CPL_ERROR_NONE); @@ -161,7 +167,7 @@ unsigned i, j; for (j = 0; j < Ny; j++) { for (i = 0; i < Nx; i++) { - in[i + j*Nx] = (PIXEL_TYPE)(10.0 + rand_gauss()*3.0); + in[i + j * Nx] = (PIXEL_TYPE)(10.0 + rand_gauss() * 3.0); /* fprintf(stderr, "(%d, %d): %f", i, j, in[i+j*Nx]); */ } /* fprintf(stderr, "\n"); */ @@ -169,24 +175,22 @@ } { - const unsigned Nxc = border_mode == CPL_BORDER_CROP - ? Nx - 2 * Rx : Nx; - const unsigned Nyc = border_mode == CPL_BORDER_CROP - ? Ny - 2 * Ry : Ny; - cpl_image *imgin = TYPE_ADD(cpl_image_wrap)(Nx, Ny, in); - cpl_image *imgout = TYPE_ADD(cpl_image_wrap)(Nxc, Nyc, out); - cpl_image *imgref = TYPE_ADD(cpl_image_wrap)(Nxc, Nyc, ref); - + const unsigned Nxc = border_mode == CPL_BORDER_CROP ? Nx - 2 * Rx : Nx; + const unsigned Nyc = border_mode == CPL_BORDER_CROP ? Ny - 2 * Ry : Ny; + cpl_image *imgin = TYPE_ADD(cpl_image_wrap)(Nx, Ny, in); + cpl_image *imgout = TYPE_ADD(cpl_image_wrap)(Nxc, Nyc, out); + cpl_image *imgref = TYPE_ADD(cpl_image_wrap)(Nxc, Nyc, ref); + unsigned i; for (i = 0; i < Nreps2; i++) { double t, tbf; unsigned j; - + if (border_mode == CPL_BORDER_NOP) { /* The border will not be set by the filtering, so preset it (to zero) */ - memset(out, 0, Nxc*Nyc * sizeof(PIXEL_TYPE)); - memset(ref, 0, Nxc*Nyc * sizeof(PIXEL_TYPE)); + memset(out, 0, Nxc * Nyc * sizeof(PIXEL_TYPE)); + memset(ref, 0, Nxc * Nyc * sizeof(PIXEL_TYPE)); } /* binary heap + column arrays */ @@ -195,26 +199,27 @@ for (j = 0; j < Nreps1; j++) { error |= cpl_image_filter_mask(imgout, imgin, mask, filter, border_mode); - } cpl_test_eq_error(error, CPL_ERROR_NONE); - t = cpl_test_get_cputime()-t; + t = cpl_test_get_cputime() - t; if (1) { tbf = cpl_test_get_cputime(); for (j = 0; j < Nreps1; j++) { if (filter == CPL_FILTER_MEDIAN) { - TYPE_ADD(filter_median_bf)(in, ref, Nx, Ny, Rx, Ry, - border_mode); - } else if (filter == CPL_FILTER_STDEV) { + TYPE_ADD(filter_median_bf) + (in, ref, Nx, Ny, Rx, Ry, border_mode); + } + else if (filter == CPL_FILTER_STDEV) { cpl_test(0); /* FIXME: Unsupported */ - } else { + } + else { #ifdef CPL_FILTER_TEST_AVERAGE_FAST - TYPE_ADD(image_filter_average_ref)(ref, in, Nx, Ny, - Rx, Ry, border_mode); + TYPE_ADD(image_filter_average_ref) + (ref, in, Nx, Ny, Rx, Ry, border_mode); #elif 1 - TYPE_ADD(image_filter_average_bf)(ref, in, Nx, Ny, - Rx, Ry, border_mode); + TYPE_ADD(image_filter_average_bf) + (ref, in, Nx, Ny, Rx, Ry, border_mode); #else error = filter_average_bf(imgref, imgin, Rx, Ry, border_mode); @@ -222,15 +227,15 @@ #endif } } - tbf = cpl_test_get_cputime()-tbf; - cpl_msg_info(cpl_func, "Time to %u-filter %u X %u " - CPL_STRINGIFY(PIXEL_TYPE) " with %u X %u [s]: %f %f", - border_mode, Nx, Ny, Rx, Ry, t, tbf); + tbf = cpl_test_get_cputime() - tbf; + cpl_msg_info(cpl_func, + "Time to %u-filter %u X %u " CPL_STRINGIFY(PIXEL_TYPE) " with %u X %u [s]: %f %f", + border_mode, Nx, Ny, Rx, Ry, t, tbf); cpl_test_image_abs(imgout, imgref, myeps); } } - cpl_test_eq_ptr(cpl_image_unwrap(imgin), in); + cpl_test_eq_ptr(cpl_image_unwrap(imgin), in); cpl_test_eq_ptr(cpl_image_unwrap(imgout), out); cpl_test_eq_ptr(cpl_image_unwrap(imgref), ref); } @@ -239,7 +244,6 @@ cpl_free(out); cpl_free(ref); cpl_mask_delete(mask); - } #ifdef CPL_FILTER_TEST_AVERAGE_FAST @@ -258,14 +262,16 @@ @see uves_filter_image_average() */ /*----------------------------------------------------------------------------*/ -static void -TYPE_ADD(image_filter_average_ref)(PIXEL_TYPE * out, const PIXEL_TYPE * in, - int nx, int ny, int hsizex, int hsizey, - unsigned border_mode) +static void TYPE_ADD(image_filter_average_ref)(PIXEL_TYPE *out, + const PIXEL_TYPE *in, + int nx, + int ny, + int hsizex, + int hsizey, + unsigned border_mode) { - - PIXEL_TYPE * aux = calloc((nx+1)*(ny+1), sizeof(PIXEL_TYPE)); - int i; + PIXEL_TYPE *aux = calloc((nx + 1) * (ny + 1), sizeof(PIXEL_TYPE)); + int i; assert(border_mode == CPL_BORDER_FILTER); @@ -280,17 +286,15 @@ /* Column x=0 and row y=0 are already zero and need not be calculated, * start from 1. */ - for (i = 0; i < (nx+1)*(ny+1); i++) - { - int x = i % (nx+1); - int y = i / (nx+1); - - if ( x >= 1 && y >= 1) - { - aux[x + y*(nx+1)] = (PIXEL_TYPE)in[x-1 + (y-1) * nx] - + aux [x-1 + y * (nx+1)] - + aux [x + (y-1)* (nx+1)] - - aux [x-1 + (y-1)* (nx+1)]; + for (i = 0; i < (nx + 1) * (ny + 1); i++) { + int x = i % (nx + 1); + int y = i / (nx + 1); + + if (x >= 1 && y >= 1) { + aux[x + y * (nx + 1)] = (PIXEL_TYPE)in[x - 1 + (y - 1) * nx] + + aux[x - 1 + y * (nx + 1)] + + aux[x + (y - 1) * (nx + 1)] - + aux[x - 1 + (y - 1) * (nx + 1)]; } /* Proof of induction step @@ -314,29 +318,32 @@ } /* Then calculate average = (flux in window) / (image size) */ - for (i = 0; i < nx*ny; i++) - { + for (i = 0; i < nx * ny; i++) { int x = (i % nx); int y = (i / nx); int lower, upper; int left, right; - lower = y - hsizey; if (lower < 0) lower = 0; - upper = y + hsizey; if (upper >= ny) upper = ny - 1; - - left = x - hsizex; if (left < 0) left = 0; - right = x + hsizex; if (right >= nx) right = nx - 1; - - out[x + y*nx] = (PIXEL_TYPE)(( - ( - aux[(right+1) + (upper+1)*(nx+1)] + - aux[ left + lower *(nx+1)] - - aux[ left + (upper+1)*(nx+1)] - - aux[(right+1) + lower *(nx+1)] - ) - / - (PIXEL_TYPE) ( (upper-lower+1) * (right-left+1) ))); + lower = y - hsizey; + if (lower < 0) + lower = 0; + upper = y + hsizey; + if (upper >= ny) + upper = ny - 1; + + left = x - hsizex; + if (left < 0) + left = 0; + right = x + hsizex; + if (right >= nx) + right = nx - 1; + + out[x + y * nx] = (PIXEL_TYPE)(( + (aux[(right + 1) + (upper + 1) * (nx + 1)] + + aux[left + lower * (nx + 1)] - aux[left + (upper + 1) * (nx + 1)] - + aux[(right + 1) + lower * (nx + 1)]) / + (PIXEL_TYPE)((upper - lower + 1) * (right - left + 1)))); } free(aux); @@ -360,12 +367,14 @@ @see uves_filter_image_average() */ /*----------------------------------------------------------------------------*/ -static void -TYPE_ADD(image_filter_average_bf)(PIXEL_TYPE * out, const PIXEL_TYPE * in, - int Nx, int Ny, int hsizex, int hsizey, - unsigned border_mode) +static void TYPE_ADD(image_filter_average_bf)(PIXEL_TYPE *out, + const PIXEL_TYPE *in, + int Nx, + int Ny, + int hsizex, + int hsizey, + unsigned border_mode) { - int y; assert(border_mode == CPL_BORDER_FILTER); @@ -379,16 +388,16 @@ int i, j; PIXEL_TYPE sum = (PIXEL_TYPE)0; - for (j = y < hsizey ? 0 : y-hsizey; - j <= (y+hsizey >= Ny ? Ny - 1 : y+hsizey); j++) { - for (i = x < hsizex ? 0 : x-hsizex; - i <= (x+hsizex >= Nx ? Nx-1 : x+hsizex); i++) { - sum += in[i + j*Nx]; + for (j = y < hsizey ? 0 : y - hsizey; + j <= (y + hsizey >= Ny ? Ny - 1 : y + hsizey); j++) { + for (i = x < hsizex ? 0 : x - hsizex; + i <= (x + hsizex >= Nx ? Nx - 1 : x + hsizex); i++) { + sum += in[i + j * Nx]; k++; } } - - out[x] = sum/(PIXEL_TYPE)k; + + out[x] = sum / (PIXEL_TYPE)k; } } diff -Nru cpl-7.1.4+ds/cplcore/tests/cpl_filter-test.c cpl-7.2.2+ds/cplcore/tests/cpl_filter-test.c --- cpl-7.1.4+ds/cplcore/tests/cpl_filter-test.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/tests/cpl_filter-test.c 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -18,7 +18,7 @@ */ #ifdef HAVE_CONFIG_H -# include +#include #endif /*----------------------------------------------------------------------------- @@ -72,63 +72,84 @@ static void test_filter(void); -static void benchmark(cpl_filter_mode filter, - cpl_border_mode border_mode, unsigned); +static void +benchmark(cpl_filter_mode filter, cpl_border_mode border_mode, unsigned); static double rand_gauss(void); -static void test_cpl_image_filter_double(unsigned, unsigned, unsigned, - unsigned, unsigned, unsigned, - unsigned, unsigned); -static void test_cpl_image_filter_float(unsigned, unsigned, unsigned, - unsigned, unsigned, unsigned, - unsigned, unsigned); -static void test_cpl_image_filter_int(unsigned, unsigned, unsigned, - unsigned, unsigned, unsigned, - unsigned, unsigned); - -static void test_cpl_image_filter(int, int, - int, int, - cpl_filter_mode, - cpl_border_mode); - -#ifdef CPL_FILTER_TEST_AVERAGE_FAST +static void test_cpl_image_filter_double(unsigned, + unsigned, + unsigned, + unsigned, + unsigned, + unsigned, + unsigned, + unsigned); +static void test_cpl_image_filter_float(unsigned, + unsigned, + unsigned, + unsigned, + unsigned, + unsigned, + unsigned, + unsigned); +static void test_cpl_image_filter_int(unsigned, + unsigned, + unsigned, + unsigned, + unsigned, + unsigned, + unsigned, + unsigned); static void -image_filter_average_ref_double(double *, const double *, - int, int, int, - int, unsigned); +test_cpl_image_filter(int, int, int, int, cpl_filter_mode, cpl_border_mode); +#ifdef CPL_FILTER_TEST_AVERAGE_FAST -static void -image_filter_average_ref_float(float *, const float *, - int, int, int, - int, unsigned); +static void image_filter_average_ref_double(double *, + const double *, + int, + int, + int, + int, + unsigned); + + +static void image_filter_average_ref_float(float *, + const float *, + int, + int, + int, + int, + unsigned); static void -image_filter_average_ref_int(int *, const int *, - int, int, int, - int, unsigned); +image_filter_average_ref_int(int *, const int *, int, int, int, int, unsigned); #elif 1 -static void -image_filter_average_bf_double(double *, const double *, - int, int, int, - int, unsigned); - -static void -image_filter_average_bf_float(float *, const float *, - int, int, int, - int, unsigned); +static void image_filter_average_bf_double(double *, + const double *, + int, + int, + int, + int, + unsigned); + +static void image_filter_average_bf_float(float *, + const float *, + int, + int, + int, + int, + unsigned); static void -image_filter_average_bf_int(int *, const int *, - int, int, int, - int, unsigned); +image_filter_average_bf_int(int *, const int *, int, int, int, int, unsigned); #else -static cpl_error_code filter_average_bf(cpl_image *, const cpl_image *, - unsigned, unsigned, unsigned); +static cpl_error_code +filter_average_bf(cpl_image *, const cpl_image *, unsigned, unsigned, unsigned); #endif @@ -149,7 +170,8 @@ @brief Unit tests of filter module **/ /*----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); @@ -164,60 +186,56 @@ @brief Unit tests of filter module **/ /*----------------------------------------------------------------------------*/ -static void test_filter(void) +static void +test_filter(void) { - const cpl_filter_mode filter_mode[] = {CPL_FILTER_AVERAGE, - CPL_FILTER_AVERAGE_FAST, - CPL_FILTER_MEDIAN}; - - const cpl_border_mode border_mode[] = {CPL_BORDER_NOP, - CPL_BORDER_FILTER, - CPL_BORDER_CROP, - CPL_BORDER_COPY}; - const int dopix[] = {1, 2, 3, 4, 7, 8}; - const int dor[] = {0, 1, 2, 3, 7}; + const cpl_filter_mode filter_mode[] = { CPL_FILTER_AVERAGE, + CPL_FILTER_AVERAGE_FAST, + CPL_FILTER_MEDIAN }; + + const cpl_border_mode border_mode[] = { CPL_BORDER_NOP, CPL_BORDER_FILTER, + CPL_BORDER_CROP, CPL_BORDER_COPY }; + const int dopix[] = { 1, 2, 3, 4, 7, 8 }; + const int dor[] = { 0, 1, 2, 3, 7 }; unsigned ifilt; - - for (ifilt = 0; - ifilt < sizeof(filter_mode)/sizeof(filter_mode[0]); - ifilt++) { + for (ifilt = 0; ifilt < sizeof(filter_mode) / sizeof(filter_mode[0]); + ifilt++) { unsigned ibord; - - for (ibord = 0; - ibord < sizeof(border_mode)/sizeof(border_mode[0]); - ibord++) { + for (ibord = 0; ibord < sizeof(border_mode) / sizeof(border_mode[0]); + ibord++) { unsigned ix; if ((filter_mode[ifilt] == CPL_FILTER_STDEV || filter_mode[ifilt] == CPL_FILTER_AVERAGE || filter_mode[ifilt] == CPL_FILTER_AVERAGE_FAST) && - border_mode[ibord] != CPL_BORDER_FILTER) continue; - - for (ix = 0; ix < sizeof(dopix)/sizeof(dopix[0]); ix++) { + border_mode[ibord] != CPL_BORDER_FILTER) + continue; + + for (ix = 0; ix < sizeof(dopix) / sizeof(dopix[0]); ix++) { const int nx = dopix[ix]; - unsigned iy; - - for (iy = 0; iy < sizeof(dopix)/sizeof(dopix[0]); iy++) { + unsigned iy; + + for (iy = 0; iy < sizeof(dopix) / sizeof(dopix[0]); iy++) { const int ny = dopix[iy]; unsigned irx; - for (irx = 0; irx < sizeof(dor)/sizeof(dor[0]); irx++) { - const int rx = - 2*dor[irx] + 1 >= nx ? (nx-1)/2 : dor[irx]; + for (irx = 0; irx < sizeof(dor) / sizeof(dor[0]); irx++) { + const int rx = + 2 * dor[irx] + 1 >= nx ? (nx - 1) / 2 : dor[irx]; unsigned iry; - - for (iry = 0; iry < sizeof(dor)/sizeof(dor[0]); iry++) { - const int ry = - 2*dor[iry] + 1 >= ny ? (ny-1)/2 : dor[iry]; - - if (2*rx + 1 <= nx && - 2*ry + 1 <= ny) { + + for (iry = 0; iry < sizeof(dor) / sizeof(dor[0]); + iry++) { + const int ry = 2 * dor[iry] + 1 >= ny ? (ny - 1) / 2 + : dor[iry]; + + if (2 * rx + 1 <= nx && 2 * ry + 1 <= ny) { test_cpl_image_filter(nx, ny, rx, ry, - filter_mode[ifilt], - border_mode[ibord]); + filter_mode[ifilt], + border_mode[ibord]); } } } @@ -228,28 +246,30 @@ } } -static void test_cpl_image_filter(int nx, int ny, - int rx, int ry, - cpl_filter_mode filter, - cpl_border_mode border_mode) +static void +test_cpl_image_filter(int nx, + int ny, + int rx, + int ry, + cpl_filter_mode filter, + cpl_border_mode border_mode) { cpl_msg_debug(cpl_func, "Testing %dx%d image, " "%dx%d kernel, filter = %d, border = %d", - nx, ny, rx, ry, - filter, border_mode); - + nx, ny, rx, ry, filter, border_mode); + /* Failure runs */ { - cpl_image * in = cpl_image_new(nx, ny, CPL_TYPE_FLOAT); - cpl_image * out = cpl_image_new(nx, ny, CPL_TYPE_FLOAT); - cpl_mask * mask = cpl_mask_new(1 + 2 * rx, 1 + 2 * ry); + cpl_image *in = cpl_image_new(nx, ny, CPL_TYPE_FLOAT); + cpl_image *out = cpl_image_new(nx, ny, CPL_TYPE_FLOAT); + cpl_mask *mask = cpl_mask_new(1 + 2 * rx, 1 + 2 * ry); cpl_error_code error; - + cpl_test_nonnull(in); cpl_test_nonnull(out); cpl_test_nonnull(mask); - + error = cpl_image_filter_mask(NULL, in, mask, filter, border_mode); cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT); @@ -259,12 +279,12 @@ error = cpl_image_filter_mask(in, out, NULL, filter, border_mode); cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT); - + cpl_image_delete(in); cpl_image_delete(out); cpl_mask_delete(mask); } - + /* Successful runs */ test_cpl_image_filter_double(nx, ny, rx, ry, filter, border_mode, 1, 1); test_cpl_image_filter_float(nx, ny, rx, ry, filter, border_mode, 1, 1); @@ -273,57 +293,59 @@ return; } -static -void benchmark(cpl_filter_mode filter, - cpl_border_mode border_mode, unsigned benchsize) +static void +benchmark(cpl_filter_mode filter, + cpl_border_mode border_mode, + unsigned benchsize) { - test_cpl_image_filter_float(benchsize, benchsize, 1, 1, - filter, border_mode, 100, 3); - test_cpl_image_filter_double(benchsize, benchsize, 1, 1, - filter, border_mode, 100, 3); - test_cpl_image_filter_int(benchsize, benchsize, 1, 1, - filter, border_mode, 100, 3); - - test_cpl_image_filter_float(benchsize, benchsize, 2, 2, - filter, border_mode, 20, 3); - test_cpl_image_filter_double(benchsize, benchsize, 2, 2, - filter, border_mode, 20, 3); - test_cpl_image_filter_int(benchsize, benchsize, 2, 2, - filter, border_mode, 20, 3); - - test_cpl_image_filter_float(benchsize, benchsize, 14, 14, - filter, border_mode, 20, 3); - test_cpl_image_filter_double(benchsize, benchsize, 14, 14, - filter, border_mode, 20, 3); - test_cpl_image_filter_int(benchsize, benchsize, 14, 14, - filter, border_mode, 20, 3); + test_cpl_image_filter_float(benchsize, benchsize, 1, 1, filter, border_mode, + 100, 3); + test_cpl_image_filter_double(benchsize, benchsize, 1, 1, filter, + border_mode, 100, 3); + test_cpl_image_filter_int(benchsize, benchsize, 1, 1, filter, border_mode, + 100, 3); + + test_cpl_image_filter_float(benchsize, benchsize, 2, 2, filter, border_mode, + 20, 3); + test_cpl_image_filter_double(benchsize, benchsize, 2, 2, filter, + border_mode, 20, 3); + test_cpl_image_filter_int(benchsize, benchsize, 2, 2, filter, border_mode, + 20, 3); + + test_cpl_image_filter_float(benchsize, benchsize, 14, 14, filter, + border_mode, 20, 3); + test_cpl_image_filter_double(benchsize, benchsize, 14, 14, filter, + border_mode, 20, 3); + test_cpl_image_filter_int(benchsize, benchsize, 14, 14, filter, border_mode, + 20, 3); return; -} +} -static -double rand_gauss(void) +static double +rand_gauss(void) { static double V1, V2, S; static int phase = 0; double X; - - if(phase == 0) { - do { - double U1 = (double)rand() / RAND_MAX; - double U2 = (double)rand() / RAND_MAX; - - V1 = 2 * U1 - 1; - V2 = 2 * U2 - 1; - S = V1 * V1 + V2 * V2; - } while(S >= 1 || S == 0); - - X = V1 * sqrt(-2 * log(S) / S); - } else - X = V2 * sqrt(-2 * log(S) / S); - + + if (phase == 0) { + do { + double U1 = (double)rand() / RAND_MAX; + double U2 = (double)rand() / RAND_MAX; + + V1 = 2 * U1 - 1; + V2 = 2 * U2 - 1; + S = V1 * V1 + V2 * V2; + } while (S >= 1 || S == 0); + + X = V1 * sqrt(-2 * log(S) / S); + } + else + X = V2 * sqrt(-2 * log(S) / S); + phase = 1 - phase; - + return X; } @@ -398,29 +420,29 @@ /* These macros are needed for support of the different pixel types */ -#define CONCAT(a,b) a ## _ ## b -#define CONCAT2X(a,b) CONCAT(a,b) +#define CONCAT(a, b) a##_##b +#define CONCAT2X(a, b) CONCAT(a, b) #define PIXEL_TYPE double -#define PIXEL_MIN (-DBL_MAX) -#define PIXEL_MAX DBL_MAX +#define PIXEL_MIN (-DBL_MAX) +#define PIXEL_MAX DBL_MAX #include "cpl_filter_body.h" #undef PIXEL_TYPE #undef PIXEL_MIN #undef PIXEL_MAX #define PIXEL_TYPE float -#define PIXEL_MIN (-FLT_MAX) -#define PIXEL_MAX FLT_MAX +#define PIXEL_MIN (-FLT_MAX) +#define PIXEL_MAX FLT_MAX #include "cpl_filter_body.h" #undef PIXEL_TYPE #undef PIXEL_MIN #undef PIXEL_MAX #define PIXEL_TYPE_IS_INT 1 -#define PIXEL_TYPE int -#define PIXEL_MIN (-INT_MAX) -#define PIXEL_MAX INT_MAX +#define PIXEL_TYPE int +#define PIXEL_MIN (-INT_MAX) +#define PIXEL_MAX INT_MAX #include "cpl_filter_body.h" #undef PIXEL_TYPE #undef PIXEL_TYPE_IS_INT diff -Nru cpl-7.1.4+ds/cplcore/tests/cpl_fits-test.c cpl-7.2.2+ds/cplcore/tests/cpl_fits-test.c --- cpl-7.1.4+ds/cplcore/tests/cpl_fits-test.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/tests/cpl_fits-test.c 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -50,12 +50,13 @@ /*----------------------------------------------------------------------------- Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { - cpl_propertylist * pl; - cpl_size ivalue; - cpl_error_code error; - cpl_size iext; + cpl_propertylist *pl; + cpl_size ivalue; + cpl_error_code error; + cpl_size iext; cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); @@ -110,7 +111,7 @@ cpl_test_eq(ivalue, 1); for (iext = 2; iext <= CPL_FITS_NEXT; iext++) { - const char * extname = cpl_sprintf("EXT%" CPL_SIZE_FORMAT, iext); + const char *extname = cpl_sprintf("EXT%" CPL_SIZE_FORMAT, iext); cpl_size jext; error = cpl_propertylist_update_string(pl, "EXTNAME", extname); @@ -125,7 +126,7 @@ cpl_test_eq(ivalue, iext); CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); - cpl_free((void*)extname); + cpl_free((void *)extname); CPL_DIAG_PRAGMA_POP; for (jext = 0; jext <= iext; jext++) { @@ -135,12 +136,13 @@ cpl_test_error(CPL_ERROR_NONE); CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); - cpl_free((void*)extname); + cpl_free((void *)extname); CPL_DIAG_PRAGMA_POP; if (jext > 1) { cpl_test_eq(ivalue, jext); - } else { + } + else { /* EXT0/1 not found */ cpl_test_zero(ivalue); } @@ -161,7 +163,8 @@ @return void */ /*----------------------------------------------------------------------------*/ -static void cpl_fits_mode_test(void) +static void +cpl_fits_mode_test(void) { cpl_error_code code; cpl_fits_mode mode, modec; @@ -170,9 +173,9 @@ cpl_fits_mode modeo; /* Copied from cpl_init() */ - const char * io_fits_mode_string = getenv("CPL_IO_MODE"); - const cpl_boolean use_io_fits = io_fits_mode_string != NULL && - strcmp("1", io_fits_mode_string) == 0; + const char *io_fits_mode_string = getenv("CPL_IO_MODE"); + const cpl_boolean use_io_fits = + io_fits_mode_string != NULL && strcmp("1", io_fits_mode_string) == 0; #else const cpl_boolean use_io_fits = CPL_FALSE; #endif @@ -180,8 +183,8 @@ /* Get the mode */ mode = cpl_fits_get_mode(); cpl_test_error(CPL_ERROR_NONE); - cpl_test_eq(mode, use_io_fits ? CPL_FITS_START_CACHING - : CPL_FITS_STOP_CACHING); + cpl_test_eq(mode, + use_io_fits ? CPL_FITS_START_CACHING : CPL_FITS_STOP_CACHING); /* Set the mode to what it already is */ code = cpl_fits_set_mode(mode); @@ -219,5 +222,4 @@ code = cpl_fits_set_mode(1); /* Result of logical and/or */ cpl_test_eq_error(code, CPL_ERROR_INVALID_TYPE); - } diff -Nru cpl-7.1.4+ds/cplcore/tests/cpl_image_basic-test.c cpl-7.2.2+ds/cplcore/tests/cpl_image_basic-test.c --- cpl-7.1.4+ds/cplcore/tests/cpl_image_basic-test.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/tests/cpl_image_basic-test.c 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -46,9 +46,9 @@ -----------------------------------------------------------------------------*/ #ifndef IMAGESZ -#define IMAGESZ 512 +#define IMAGESZ 512 #endif -#define MAGIC_PIXEL 42 +#define MAGIC_PIXEL 42 #define POLY_SIZE 24 @@ -72,42 +72,44 @@ /*----------------------------------------------------------------------------- Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { - cpl_image * imf1; - cpl_image * imf2; - cpl_image * imd1; - cpl_image * imd2; - cpl_image * imi1; - cpl_image * imi2; - cpl_image * imf; - cpl_image * imd; - cpl_image * imi; - cpl_image * imtmp; - cpl_image * imfc1; - cpl_image * imfc2; - cpl_image * imfc3; - float complex * dataf1; - float complex * dataf2; - float complex * dataf3; - cpl_image * imdc1; - cpl_image * imdc2; - cpl_image * imdc3; - double complex * data1; - double complex * data2; - double complex * data3; - cpl_vector * taylor; - double * ddata; - int nb_cut; - const cpl_size new_pos[9] = {9, 8, 7, 6, 5, 4, 3, 2, 1}; - double err; - double value; - int is_rejected; - cpl_mask * mask; - int is_bad; - int i, j, k; - cpl_error_code error; - cpl_boolean do_bench; + cpl_image *imf1; + cpl_image *imf2; + cpl_image *imd1; + cpl_image *imd2; + cpl_image *imi1; + cpl_image *imi2; + cpl_image *imf; + cpl_image *imd; + cpl_image *imi; + cpl_image *imtmp; + cpl_image *imfc1; + cpl_image *imfc2; + cpl_image *imfc3; + float complex *dataf1; + float complex *dataf2; + float complex *dataf3; + cpl_image *imdc1; + cpl_image *imdc2; + cpl_image *imdc3; + double complex *data1; + double complex *data2; + double complex *data3; + cpl_vector *taylor; + double *ddata; + cpl_size nb_cut; + /* Cyclic "shift" */ + const cpl_size new_pos[9] = { 9, 1, 2, 3, 4, 5, 6, 7, 8 }; + double err; + double value; + int is_rejected; + cpl_mask *mask; + int is_bad; + int i, j, k; + cpl_error_code error; + cpl_boolean do_bench; /* * FIXME: Ideally, we should simply use the macro I @@ -123,8 +125,8 @@ * This is a bug in gcc (seems to be related to Bugzilla #7263) and, as a * workaround in order to avoid that warning, we compute ourselves the * value of the macro. - */ - double complex cpl_i = csqrt(-1.0); + */ + double complex cpl_i = csqrt(-1.0); cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); @@ -139,10 +141,10 @@ if (do_bench) { double secs = cpl_test_get_walltime(); for (i = 0; i < 2; i++) { - cpl_image_bitwise_test(IMAGESZ/2, IMAGESZ/2); - cpl_image_bitwise_test(IMAGESZ, IMAGESZ); - cpl_image_bitwise_test(IMAGESZ*2, IMAGESZ*2); - cpl_image_bitwise_test(IMAGESZ*4, IMAGESZ*4); + cpl_image_bitwise_test(IMAGESZ / 2, IMAGESZ / 2); + cpl_image_bitwise_test(IMAGESZ, IMAGESZ); + cpl_image_bitwise_test(IMAGESZ * 2, IMAGESZ * 2); + cpl_image_bitwise_test(IMAGESZ * 4, IMAGESZ * 4); } secs = cpl_test_get_walltime() - secs; cpl_msg_info(cpl_func, "Time to test bit-wise calls [s]: %g", secs); @@ -162,79 +164,79 @@ /* Tests of cpl_image_collapse_create() */ imtmp = cpl_image_collapse_create(NULL, 1); - cpl_test_error( CPL_ERROR_NULL_INPUT ); - cpl_test_null( imtmp ); - + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(imtmp); + imtmp = cpl_image_collapse_window_create(NULL, 1, 1, 1, 1, 1); - cpl_test_error( CPL_ERROR_NULL_INPUT ); - cpl_test_null( imtmp ); - + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(imtmp); + imd = cpl_image_new(IMAGESZ, IMAGESZ, CPL_TYPE_DOUBLE); imtmp = cpl_image_collapse_create(imd, -1); - cpl_test_error( CPL_ERROR_ILLEGAL_INPUT ); - cpl_test_null( imtmp ); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(imtmp); /* Set two pixels in the last columns to 1 */ - cpl_test_zero(cpl_image_set(imd, IMAGESZ-1, IMAGESZ, 1.0)); - cpl_test_zero(cpl_image_set(imd, IMAGESZ, IMAGESZ, 1.0)); + cpl_test_zero(cpl_image_set(imd, IMAGESZ - 1, IMAGESZ, 1.0)); + cpl_test_zero(cpl_image_set(imd, IMAGESZ, IMAGESZ, 1.0)); /* No BPM */ /* Collapse the x-direction to an image with 1 row */ imtmp = cpl_image_collapse_create(imd, 1); - cpl_test_eq( cpl_image_get_type(imtmp), cpl_image_get_type(imd)); + cpl_test_eq(cpl_image_get_type(imtmp), cpl_image_get_type(imd)); - cpl_test_eq( cpl_image_get_size_x(imtmp), 1); - cpl_test_eq( cpl_image_get_size_y(imtmp), IMAGESZ); + cpl_test_eq(cpl_image_get_size_x(imtmp), 1); + cpl_test_eq(cpl_image_get_size_y(imtmp), IMAGESZ); - cpl_test_zero( cpl_image_get(imtmp, 1, IMAGESZ-1, &is_bad)); - cpl_test_zero( is_bad ); - cpl_test_eq( cpl_image_get(imtmp, 1, IMAGESZ, &is_bad), 2); - cpl_test_zero( is_bad ); + cpl_test_zero(cpl_image_get(imtmp, 1, IMAGESZ - 1, &is_bad)); + cpl_test_zero(is_bad); + cpl_test_eq(cpl_image_get(imtmp, 1, IMAGESZ, &is_bad), 2); + cpl_test_zero(is_bad); cpl_image_delete(imtmp); - imtmp = cpl_image_collapse_window_create(imd, IMAGESZ-1, IMAGESZ-1, + imtmp = cpl_image_collapse_window_create(imd, IMAGESZ - 1, IMAGESZ - 1, IMAGESZ, IMAGESZ, 1); - cpl_test_eq( cpl_image_get_type(imtmp), cpl_image_get_type(imd)); + cpl_test_eq(cpl_image_get_type(imtmp), cpl_image_get_type(imd)); - cpl_test_eq( cpl_image_get_size_x(imtmp), 1); - cpl_test_eq( cpl_image_get_size_y(imtmp), 2); + cpl_test_eq(cpl_image_get_size_x(imtmp), 1); + cpl_test_eq(cpl_image_get_size_y(imtmp), 2); - cpl_test_zero( cpl_image_get(imtmp, 1, 1, &is_bad)); - cpl_test_zero( is_bad ); - cpl_test_eq( cpl_image_get(imtmp, 1, 2, &is_bad), 2); - cpl_test_zero( is_bad ); + cpl_test_zero(cpl_image_get(imtmp, 1, 1, &is_bad)); + cpl_test_zero(is_bad); + cpl_test_eq(cpl_image_get(imtmp, 1, 2, &is_bad), 2); + cpl_test_zero(is_bad); cpl_image_delete(imtmp); /* Collapse the y-direction to an image with 1 column */ imtmp = cpl_image_collapse_create(imd, 0); - cpl_test_eq( cpl_image_get_type(imtmp), cpl_image_get_type(imd)); + cpl_test_eq(cpl_image_get_type(imtmp), cpl_image_get_type(imd)); - cpl_test_eq( cpl_image_get_size_x(imtmp), IMAGESZ); - cpl_test_eq( cpl_image_get_size_y(imtmp), 1); + cpl_test_eq(cpl_image_get_size_x(imtmp), IMAGESZ); + cpl_test_eq(cpl_image_get_size_y(imtmp), 1); - cpl_test_eq( cpl_image_get(imtmp, IMAGESZ - 1, 1, &is_bad), 1); - cpl_test_zero( is_bad ); - cpl_test_eq( cpl_image_get(imtmp, IMAGESZ, 1, &is_bad), 1); - cpl_test_zero( is_bad ); + cpl_test_eq(cpl_image_get(imtmp, IMAGESZ - 1, 1, &is_bad), 1); + cpl_test_zero(is_bad); + cpl_test_eq(cpl_image_get(imtmp, IMAGESZ, 1, &is_bad), 1); + cpl_test_zero(is_bad); cpl_image_delete(imtmp); - imtmp = cpl_image_collapse_window_create(imd, IMAGESZ-1, IMAGESZ-1, + imtmp = cpl_image_collapse_window_create(imd, IMAGESZ - 1, IMAGESZ - 1, IMAGESZ, IMAGESZ, 0); - cpl_test_eq( cpl_image_get_type(imtmp), cpl_image_get_type(imd)); + cpl_test_eq(cpl_image_get_type(imtmp), cpl_image_get_type(imd)); - cpl_test_eq( cpl_image_get_size_x(imtmp), 2); - cpl_test_eq( cpl_image_get_size_y(imtmp), 1); + cpl_test_eq(cpl_image_get_size_x(imtmp), 2); + cpl_test_eq(cpl_image_get_size_y(imtmp), 1); - cpl_test_eq( cpl_image_get(imtmp, 1, 1, &is_bad), 1); - cpl_test_zero( is_bad ); - cpl_test_eq( cpl_image_get(imtmp, 2, 1, &is_bad), 1); - cpl_test_zero( is_bad ); + cpl_test_eq(cpl_image_get(imtmp, 1, 1, &is_bad), 1); + cpl_test_zero(is_bad); + cpl_test_eq(cpl_image_get(imtmp, 2, 1, &is_bad), 1); + cpl_test_zero(is_bad); cpl_image_delete(imtmp); @@ -244,73 +246,73 @@ /* Collapse the x-direction to an image with 1 row */ - imtmp = cpl_image_collapse_window_create(imd, IMAGESZ-1, IMAGESZ-1, + imtmp = cpl_image_collapse_window_create(imd, IMAGESZ - 1, IMAGESZ - 1, IMAGESZ, IMAGESZ, 1); - cpl_test_eq( cpl_image_get_type(imtmp), cpl_image_get_type(imd)); + cpl_test_eq(cpl_image_get_type(imtmp), cpl_image_get_type(imd)); - cpl_test_eq( cpl_image_get_size_x(imtmp), 1); - cpl_test_eq( cpl_image_get_size_y(imtmp), 2); + cpl_test_eq(cpl_image_get_size_x(imtmp), 1); + cpl_test_eq(cpl_image_get_size_y(imtmp), 2); - cpl_test_zero( cpl_image_get(imtmp, 1, 1, &is_bad)); - cpl_test_zero( is_bad ); - cpl_test_eq( cpl_image_get(imtmp, 1, 2, &is_bad), 2); - cpl_test_zero( is_bad ); + cpl_test_zero(cpl_image_get(imtmp, 1, 1, &is_bad)); + cpl_test_zero(is_bad); + cpl_test_eq(cpl_image_get(imtmp, 1, 2, &is_bad), 2); + cpl_test_zero(is_bad); cpl_image_delete(imtmp); /* Collapse the y-direction to an image with 1 column */ - imtmp = cpl_image_collapse_window_create(imd, IMAGESZ-1, IMAGESZ-1, + imtmp = cpl_image_collapse_window_create(imd, IMAGESZ - 1, IMAGESZ - 1, IMAGESZ, IMAGESZ, 0); - cpl_test_eq( cpl_image_get_type(imtmp), cpl_image_get_type(imd)); + cpl_test_eq(cpl_image_get_type(imtmp), cpl_image_get_type(imd)); - cpl_test_eq( cpl_image_get_size_x(imtmp), 2); - cpl_test_eq( cpl_image_get_size_y(imtmp), 1); + cpl_test_eq(cpl_image_get_size_x(imtmp), 2); + cpl_test_eq(cpl_image_get_size_y(imtmp), 1); - cpl_test_eq( cpl_image_get(imtmp, 1, 1, &is_bad), 1); - cpl_test_zero( is_bad ); - cpl_test_eq( cpl_image_get(imtmp, 2, 1, &is_bad), 1); - cpl_test_zero( is_bad ); + cpl_test_eq(cpl_image_get(imtmp, 1, 1, &is_bad), 1); + cpl_test_zero(is_bad); + cpl_test_eq(cpl_image_get(imtmp, 2, 1, &is_bad), 1); + cpl_test_zero(is_bad); cpl_image_delete(imtmp); /* Flag the two zero pixels in the last row as bad */ - cpl_test_zero( cpl_mask_set(mask, IMAGESZ-1, IMAGESZ-1, CPL_BINARY_1)); - cpl_test_zero( cpl_mask_set(mask, IMAGESZ, IMAGESZ-1, CPL_BINARY_1)); + cpl_test_zero(cpl_mask_set(mask, IMAGESZ - 1, IMAGESZ - 1, CPL_BINARY_1)); + cpl_test_zero(cpl_mask_set(mask, IMAGESZ, IMAGESZ - 1, CPL_BINARY_1)); /* Collapse the x-direction to an image with 1 row */ - imtmp = cpl_image_collapse_window_create(imd, IMAGESZ-1, IMAGESZ-1, + imtmp = cpl_image_collapse_window_create(imd, IMAGESZ - 1, IMAGESZ - 1, IMAGESZ, IMAGESZ, 1); - cpl_test_eq( cpl_image_get_type(imtmp), cpl_image_get_type(imd)); + cpl_test_eq(cpl_image_get_type(imtmp), cpl_image_get_type(imd)); - cpl_test_eq( cpl_image_get_size_x(imtmp), 1); - cpl_test_eq( cpl_image_get_size_y(imtmp), 2); + cpl_test_eq(cpl_image_get_size_x(imtmp), 1); + cpl_test_eq(cpl_image_get_size_y(imtmp), 2); value = cpl_image_get(imtmp, 1, 1, &is_bad); - cpl_test( is_bad ); - cpl_test_eq( cpl_image_get(imtmp, 1, 2, &is_bad), 2); - cpl_test_zero( is_bad ); + cpl_test(is_bad); + cpl_test_eq(cpl_image_get(imtmp, 1, 2, &is_bad), 2); + cpl_test_zero(is_bad); cpl_image_delete(imtmp); /* Collapse the y-direction to an image with 1 column */ - imtmp = cpl_image_collapse_window_create(imd, IMAGESZ-1, IMAGESZ-1, + imtmp = cpl_image_collapse_window_create(imd, IMAGESZ - 1, IMAGESZ - 1, IMAGESZ, IMAGESZ, 0); - cpl_test_eq( cpl_image_get_type(imtmp), cpl_image_get_type(imd)); + cpl_test_eq(cpl_image_get_type(imtmp), cpl_image_get_type(imd)); - cpl_test_eq( cpl_image_get_size_x(imtmp), 2); - cpl_test_eq( cpl_image_get_size_y(imtmp), 1); + cpl_test_eq(cpl_image_get_size_x(imtmp), 2); + cpl_test_eq(cpl_image_get_size_y(imtmp), 1); - cpl_test_eq( cpl_image_get(imtmp, 1, 1, &is_bad), 2); - cpl_test_zero( is_bad ); - cpl_test_eq( cpl_image_get(imtmp, 2, 1, &is_bad), 2); - cpl_test_zero( is_bad ); + cpl_test_eq(cpl_image_get(imtmp, 1, 1, &is_bad), 2); + cpl_test_zero(is_bad); + cpl_test_eq(cpl_image_get(imtmp, 2, 1, &is_bad), 2); + cpl_test_zero(is_bad); cpl_image_delete(imtmp); - + /* Finished testing cpl_image_collapse_window_create() */ /* Finished testing cpl_image_collapse_create() */ @@ -324,29 +326,31 @@ /* Fill images with values 0, 1, 2, 3 */ value = 0.0; - for (i=1; i <= 2; i++) { - for (j=1; j <= 2; j++) { - cpl_test_zero( cpl_image_set(imd1, i, j, value)); - cpl_test_zero( cpl_image_set(imd2, i, j, value)); - cpl_test_zero( cpl_image_set(imi1, i, j, value)); - cpl_test_zero( cpl_image_set(imi2, i, j, value)); + for (i = 1; i <= 2; i++) { + for (j = 1; j <= 2; j++) { + cpl_test_zero(cpl_image_set(imd1, i, j, value)); + cpl_test_zero(cpl_image_set(imd2, i, j, value)); + cpl_test_zero(cpl_image_set(imi1, i, j, value)); + cpl_test_zero(cpl_image_set(imi2, i, j, value)); value++; } } /* Test cpl_image_divide_create() on integer and double */ imd = cpl_image_divide_create(imd1, imd2); - cpl_test_nonnull( imd); + cpl_test_nonnull(imd); imi = cpl_image_divide_create(imi1, imi2); - cpl_test_nonnull( imi); + cpl_test_nonnull(imi); value = 0.0; - for (i=1; i <= 2; i++) { - for (j=1; j <= 2; j++, value++) { - const double vald = cpl_image_get(imd, i, j, &is_bad); - const double vali = cpl_image_get(imi, i, j, &is_bad); - - if (value != 0.0) cpl_test_abs(vald, 1.0, 0.0); - if (value != 0.0) cpl_test_abs(vali, 1.0, 0.0); + for (i = 1; i <= 2; i++) { + for (j = 1; j <= 2; j++, value++) { + const double vald = cpl_image_get(imd, i, j, &is_bad); + const double vali = cpl_image_get(imi, i, j, &is_bad); + + if (value != 0.0) + cpl_test_abs(vald, 1.0, 0.0); + if (value != 0.0) + cpl_test_abs(vali, 1.0, 0.0); } } @@ -354,8 +358,8 @@ error = cpl_image_threshold(imd1, (double)MAGIC_PIXEL, (double)MAGIC_PIXEL, (double)MAGIC_PIXEL, (double)MAGIC_PIXEL); cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_leq( cpl_image_get_max(imd1), (double)MAGIC_PIXEL); - cpl_test_leq( (double)MAGIC_PIXEL, cpl_image_get_min(imd1)); + cpl_test_leq(cpl_image_get_max(imd1), (double)MAGIC_PIXEL); + cpl_test_leq((double)MAGIC_PIXEL, cpl_image_get_min(imd1)); cpl_image_delete(imd1); cpl_image_delete(imd2); @@ -375,108 +379,116 @@ value = cpl_image_get(imi1, 1, 1, &is_bad); cpl_test_abs(value, 20.0, 0.0); cpl_image_delete(imi1); - + imd = cpl_image_new(IMAGESZ, IMAGESZ, CPL_TYPE_DOUBLE); /* Fill the image with a sinus */ ddata = cpl_image_get_data(imd); - cpl_test_nonnull( ddata ); - for (i=0; i < IMAGESZ; i++) { - for (j=0; j < IMAGESZ; j++) { - value = sin(i*CPL_MATH_2PI/IMAGESZ) * sin(j*CPL_MATH_2PI/IMAGESZ); - if (cpl_image_set(imd, i+1, j+1, value)) break; - if ( ddata[i + j * IMAGESZ] != value ) break; - if (cpl_image_get(imd, i+1, j+1, &is_rejected) != value) break; - if (is_rejected) break; /* Not really useful */ + cpl_test_nonnull(ddata); + for (i = 0; i < IMAGESZ; i++) { + for (j = 0; j < IMAGESZ; j++) { + value = sin(i * CPL_MATH_2PI / IMAGESZ) * + sin(j * CPL_MATH_2PI / IMAGESZ); + if (cpl_image_set(imd, i + 1, j + 1, value)) + break; + if (ddata[i + j * IMAGESZ] != value) + break; + if (cpl_image_get(imd, i + 1, j + 1, &is_rejected) != value) + break; + if (is_rejected) + break; /* Not really useful */ } - cpl_test_eq( j, IMAGESZ); + cpl_test_eq(j, IMAGESZ); } imd1 = cpl_image_duplicate(imd); - cpl_test_nonnull( imd1 ); + cpl_test_nonnull(imd1); - cpl_test_zero( cpl_image_fft(imd1, NULL, CPL_FFT_DEFAULT) ); + cpl_test_zero(cpl_image_fft(imd1, NULL, CPL_FFT_DEFAULT)); - cpl_test_zero( cpl_image_abs(imd1) ); + cpl_test_zero(cpl_image_abs(imd1)); /* 4 FFT-components are non-zero */ - value = IMAGESZ*IMAGESZ/4; + value = IMAGESZ * IMAGESZ / 4; err = fabs(cpl_image_get(imd1, 2, 2, &is_rejected) - value); - cpl_test_zero( cpl_image_set(imd1, 2, 2, err) ); + cpl_test_zero(cpl_image_set(imd1, 2, 2, err)); err = fabs(cpl_image_get(imd1, 2, IMAGESZ, &is_rejected) - value); - cpl_test_zero( cpl_image_set(imd1, 2, IMAGESZ, err) ); + cpl_test_zero(cpl_image_set(imd1, 2, IMAGESZ, err)); err = fabs(cpl_image_get(imd1, IMAGESZ, 2, &is_rejected) - value); - cpl_test_zero( cpl_image_set(imd1, IMAGESZ, 2, err) ); + cpl_test_zero(cpl_image_set(imd1, IMAGESZ, 2, err)); err = fabs(cpl_image_get(imd1, IMAGESZ, IMAGESZ, &is_rejected) - value); - cpl_test_zero( cpl_image_set(imd1, IMAGESZ, IMAGESZ, err) ); + cpl_test_zero(cpl_image_set(imd1, IMAGESZ, IMAGESZ, err)); err = cpl_image_get_max(imd1); cpl_msg_info("", "FFT(%g) round-off [DBL_EPSILON]: %g < %d", value, - err/DBL_EPSILON, IMAGESZ*IMAGESZ); + err / DBL_EPSILON, IMAGESZ * IMAGESZ); - cpl_test_leq( fabs(err), IMAGESZ*IMAGESZ * DBL_EPSILON); + cpl_test_leq(fabs(err), IMAGESZ * IMAGESZ * DBL_EPSILON); cpl_image_delete(imd1); /* Create a Taylor-expansion of exp() */ - cpl_test_nonnull( taylor = cpl_vector_new(POLY_SIZE) ); + cpl_test_nonnull(taylor = cpl_vector_new(POLY_SIZE)); i = 0; cpl_vector_set(taylor, i, 1); - for (i=1; i 0; k--) { - cpl_test_zero( cpl_image_multiply(imd2, imd) ); - if (k&1) { - cpl_test_zero( cpl_image_add_scalar(imd2, - cpl_vector_get(taylor, k-1)) ); - } else { - cpl_test_zero( cpl_image_subtract_scalar(imd2, - -cpl_vector_get(taylor, k-1)) ); + cpl_test_nonnull(imd2); + cpl_test_zero( + cpl_image_add_scalar(imd2, cpl_vector_get(taylor, POLY_SIZE - 1))); + + for (k = POLY_SIZE - 1; k > 0; k--) { + cpl_test_zero(cpl_image_multiply(imd2, imd)); + if (k & 1) { + cpl_test_zero( + cpl_image_add_scalar(imd2, cpl_vector_get(taylor, k - 1))); + } + else { + cpl_test_zero( + cpl_image_subtract_scalar(imd2, + -cpl_vector_get(taylor, k - 1))); } - } + } /* Verify the result (against cpl_image_exponential() ) */ imd1 = cpl_image_duplicate(imd); - cpl_test_nonnull( imd1 ); + cpl_test_nonnull(imd1); - cpl_test_zero( cpl_image_exponential(imd1, CPL_MATH_E) ); + cpl_test_zero(cpl_image_exponential(imd1, CPL_MATH_E)); - cpl_test_zero( cpl_image_subtract(imd2, imd1) ); - cpl_test_zero( cpl_image_divide(imd2, imd1) ); - cpl_test_zero( cpl_image_divide_scalar(imd2, DBL_EPSILON) ); + cpl_test_zero(cpl_image_subtract(imd2, imd1)); + cpl_test_zero(cpl_image_divide(imd2, imd1)); + cpl_test_zero(cpl_image_divide_scalar(imd2, DBL_EPSILON)); - cpl_test_leq( fabs(cpl_image_get_max(imd2)), 2.64494 ); - cpl_test_leq( fabs(cpl_image_get_min(imd2)), 2.03626 ); + cpl_test_leq(fabs(cpl_image_get_max(imd2)), 2.64494); + cpl_test_leq(fabs(cpl_image_get_min(imd2)), 2.03626); cpl_image_delete(imd2); /* Evaluate exp() using cpl_image_pow() on the Taylor expansion */ imd2 = cpl_image_new(IMAGESZ, IMAGESZ, CPL_TYPE_DOUBLE); - cpl_test_nonnull( imd2 ); - cpl_test_zero( cpl_image_add_scalar(imd2, cpl_vector_get(taylor, 0)) ); - + cpl_test_nonnull(imd2); + cpl_test_zero(cpl_image_add_scalar(imd2, cpl_vector_get(taylor, 0))); + /* POLY_SIZE > 10 on alphaev56: Program received signal SIGFPE, Arithmetic exception. 0x200000a3ff0 in cpl_vector_multiply_scalar () */ - for (k=1; k < POLY_SIZE; k++) { + for (k = 1; k < POLY_SIZE; k++) { imtmp = cpl_image_duplicate(imd); - cpl_test_zero( cpl_image_power(imtmp, k) ); - cpl_test_zero( cpl_image_multiply_scalar(imtmp, cpl_vector_get(taylor, k)) ); - cpl_test_zero( cpl_image_add(imd2, imtmp) ); + cpl_test_zero(cpl_image_power(imtmp, k)); + cpl_test_zero( + cpl_image_multiply_scalar(imtmp, cpl_vector_get(taylor, k))); + cpl_test_zero(cpl_image_add(imd2, imtmp)); cpl_image_delete(imtmp); - } + } cpl_vector_delete(taylor); @@ -484,50 +496,50 @@ cpl_test_image_abs(imd2, imd1, 16 * DBL_EPSILON); /* Verify cpl_image_logarithm() ) */ - cpl_test_zero( cpl_image_logarithm(imd1, 10) ); - cpl_test_zero( cpl_image_multiply_scalar(imd1, CPL_MATH_LN10) ); + cpl_test_zero(cpl_image_logarithm(imd1, 10)); + cpl_test_zero(cpl_image_multiply_scalar(imd1, CPL_MATH_LN10)); cpl_test_image_abs(imd, imd1, 3 * DBL_EPSILON); - cpl_test_zero( cpl_image_exponential(imd, CPL_MATH_E) ); + cpl_test_zero(cpl_image_exponential(imd, CPL_MATH_E)); - cpl_test_zero( cpl_image_copy(imd1, imd,1,1) ); + cpl_test_zero(cpl_image_copy(imd1, imd, 1, 1)); - cpl_test_zero( cpl_image_fft(imd1, NULL, CPL_FFT_DEFAULT) ); + cpl_test_zero(cpl_image_fft(imd1, NULL, CPL_FFT_DEFAULT)); cpl_image_delete(imd2); imd2 = cpl_image_duplicate(imd1); - cpl_test_nonnull( imd2 ); + cpl_test_nonnull(imd2); imtmp = cpl_image_duplicate(imd1); - cpl_test_nonnull( imtmp ); - cpl_test_zero( cpl_image_copy(imd1, imd2, 1, 1) ); + cpl_test_nonnull(imtmp); + cpl_test_zero(cpl_image_copy(imd1, imd2, 1, 1)); - cpl_test_zero( cpl_image_add(imd1, imd2) ); - cpl_test_zero( cpl_image_add(imd1, imd2) ); - cpl_test_zero( cpl_image_add(imd1, imd2) ); - cpl_test_zero( cpl_image_subtract(imd1, imd2) ); - cpl_test_zero( cpl_image_multiply_scalar(imtmp, 3) ); + cpl_test_zero(cpl_image_add(imd1, imd2)); + cpl_test_zero(cpl_image_add(imd1, imd2)); + cpl_test_zero(cpl_image_add(imd1, imd2)); + cpl_test_zero(cpl_image_subtract(imd1, imd2)); + cpl_test_zero(cpl_image_multiply_scalar(imtmp, 3)); cpl_test_eq(cpl_image_count_rejected(imtmp), 0); - cpl_test_zero( cpl_image_divide(imtmp, imd1) ); + cpl_test_zero(cpl_image_divide(imtmp, imd1)); - cpl_test_zero( cpl_image_abs(imtmp) ); + cpl_test_zero(cpl_image_abs(imtmp)); - cpl_test_abs( modf(IMAGESZ*IMAGESZ - cpl_image_get_flux(imtmp), - &err), 0.0, DBL_EPSILON); + cpl_test_abs(modf(IMAGESZ * IMAGESZ - cpl_image_get_flux(imtmp), &err), 0.0, + DBL_EPSILON); cpl_test_eq(cpl_image_count_rejected(imtmp), err); - cpl_test_zero( cpl_image_fft(imd1, NULL, CPL_FFT_INVERSE) ); + cpl_test_zero(cpl_image_fft(imd1, NULL, CPL_FFT_INVERSE)); - cpl_test_zero( cpl_image_divide_scalar(imd1, 3) ); + cpl_test_zero(cpl_image_divide_scalar(imd1, 3)); cpl_test_image_abs(imd, imd1, 32 * DBL_EPSILON); - cpl_test_zero( cpl_image_copy(imd1, imd, 1, 1) ); + cpl_test_zero(cpl_image_copy(imd1, imd, 1, 1)); - cpl_test_zero( cpl_image_fft(imd1, NULL, CPL_FFT_INVERSE) ); - cpl_test_zero( cpl_image_fft(imd1, NULL, CPL_FFT_DEFAULT) ); + cpl_test_zero(cpl_image_fft(imd1, NULL, CPL_FFT_INVERSE)); + cpl_test_zero(cpl_image_fft(imd1, NULL, CPL_FFT_DEFAULT)); cpl_test_image_abs(imd, imd1, 32 * DBL_EPSILON); @@ -547,69 +559,68 @@ cpl_image_flip_turn_test(imi1); imd2 = cpl_image_fill_test_create(IMAGESZ, IMAGESZ); - cpl_image_save(imd2, "test.fits", CPL_TYPE_FLOAT, NULL, - CPL_IO_CREATE); + cpl_image_save(imd2, "test.fits", CPL_TYPE_FLOAT, NULL, CPL_IO_CREATE); remove("test.fits"); imf2 = cpl_image_cast(imd2, CPL_TYPE_FLOAT); imi2 = cpl_image_cast(imd2, CPL_TYPE_INT); - cpl_test_nonnull( imd1 ); - cpl_test_nonnull( imd2 ); + cpl_test_nonnull(imd1); + cpl_test_nonnull(imd2); - cpl_test_nonnull( imf1 ); - cpl_test_nonnull( imf2 ); + cpl_test_nonnull(imf1); + cpl_test_nonnull(imf2); + + cpl_test_nonnull(imi1); + cpl_test_nonnull(imi2); - cpl_test_nonnull( imi1 ); - cpl_test_nonnull( imi2 ); - /* COMPUTE imi =(imi1-imi2)*imi1/(imi1+imi2) with local functions */ - cpl_msg_info("","Compute imi = (imi1-imi2)*imi1/(imi1+imi2) in INTEGER"); + cpl_msg_info("", "Compute imi = (imi1-imi2)*imi1/(imi1+imi2) in INTEGER"); imi = cpl_image_duplicate(imi1); - cpl_test_zero( cpl_image_subtract(imi, imi2) ); - cpl_test_zero( cpl_image_multiply(imi, imi1) ); + cpl_test_zero(cpl_image_subtract(imi, imi2)); + cpl_test_zero(cpl_image_multiply(imi, imi1)); imtmp = cpl_image_duplicate(imi1); - cpl_test_zero( cpl_image_add(imtmp, imi2) ); - cpl_test_zero( cpl_image_divide(imi, imtmp) ); + cpl_test_zero(cpl_image_add(imtmp, imi2)); + cpl_test_zero(cpl_image_divide(imi, imtmp)); cpl_image_delete(imtmp); - + /* Delete imi1 and imi2 */ - cpl_image_delete(imi1); - cpl_image_delete(imi2); + cpl_image_delete(imi1); + cpl_image_delete(imi2); /* COMPUTE imf =(imf1-imf2)*imf1/(imf1+imf2) with local functions */ - cpl_msg_info("","Compute imf = (imf1-imf2)*imf1/(imf1+imf2) in FLOAT"); + cpl_msg_info("", "Compute imf = (imf1-imf2)*imf1/(imf1+imf2) in FLOAT"); imf = cpl_image_duplicate(imf1); - cpl_test_zero( cpl_image_subtract(imf, imf2) ); - cpl_test_zero( cpl_image_multiply(imf, imf1) ); + cpl_test_zero(cpl_image_subtract(imf, imf2)); + cpl_test_zero(cpl_image_multiply(imf, imf1)); imtmp = cpl_image_duplicate(imf1); - cpl_test_zero( cpl_image_add(imtmp, imf2) ); - cpl_test_zero( cpl_image_divide(imf, imtmp) ); + cpl_test_zero(cpl_image_add(imtmp, imf2)); + cpl_test_zero(cpl_image_divide(imf, imtmp)); cpl_image_delete(imtmp); - + /* Delete imf1 and imf2 */ - cpl_image_delete(imf1); - cpl_image_delete(imf2); + cpl_image_delete(imf1); + cpl_image_delete(imf2); /* COMPUTE imd =(imd1-imd2)*imd1/(imd1+imd2) with local functions */ - cpl_msg_info("","Compute imd = (imd1-imd2)*imd1/(imd1+imd2) in DOUBLE"); + cpl_msg_info("", "Compute imd = (imd1-imd2)*imd1/(imd1+imd2) in DOUBLE"); imd = cpl_image_duplicate(imd1); - cpl_test_zero( cpl_image_subtract(imd, imd2) ); - cpl_test_zero( cpl_image_multiply(imd, imd1) ); + cpl_test_zero(cpl_image_subtract(imd, imd2)); + cpl_test_zero(cpl_image_multiply(imd, imd1)); imtmp = cpl_image_duplicate(imd1); - cpl_test_zero( cpl_image_add(imtmp, imd2) ); - cpl_test_zero( cpl_image_divide(imd, imtmp) ); + cpl_test_zero(cpl_image_add(imtmp, imd2)); + cpl_test_zero(cpl_image_divide(imd, imtmp)); cpl_image_delete(imtmp); - + /* Delete imd1 and imd2 */ - cpl_image_delete(imd1); - cpl_image_delete(imd2); + cpl_image_delete(imd1); + cpl_image_delete(imd2); /* At this point imi, imf and imd are int, resp float and double type */ /* images with the same values - apart from differences in rounding. */ /* Test cpl_image_average_create() */ - cpl_image_delete( cpl_image_average_create(imf, imd) ); - + cpl_image_delete(cpl_image_average_create(imf, imd)); + /* Test collapse functions */ /* Set all pixels as bad */ mask = cpl_mask_new(IMAGESZ, IMAGESZ); @@ -618,66 +629,88 @@ cpl_mask_delete(mask); /* Collapse with bad pixels */ imtmp = cpl_image_collapse_create(imd, 0); - cpl_test_eq( cpl_mask_count(cpl_image_get_bpm(imtmp)), IMAGESZ); - + cpl_test_eq(cpl_mask_count(cpl_image_get_bpm(imtmp)), IMAGESZ); + cpl_image_delete(imtmp); /* Reset the bad pixlels in imd */ cpl_image_accept_all(imd); /* Collapse */ imtmp = cpl_image_collapse_create(imd, 0); - cpl_test_zero( cpl_mask_count(cpl_image_get_bpm(imtmp))); + cpl_test_zero(cpl_mask_count(cpl_image_get_bpm(imtmp))); cpl_image_delete(imtmp); /* Median collapse */ imtmp = cpl_image_collapse_median_create(imf, 0, 10, 10); cpl_image_delete(imtmp); - + /* imf=((((imf+MAGIC_PIXEL)*MAGIC_PIXEL)-MAGIC_PIXEL)/-MAGIC_PIXEL)*/ /* with non local functions */ - cpl_msg_info("","Compute imf = ((((imf+42)*42)-42)/-42)"); - cpl_test_zero( cpl_image_add_scalar(imf, (double)MAGIC_PIXEL) ); - cpl_test_zero( cpl_image_multiply_scalar(imf, (double)MAGIC_PIXEL) ); - cpl_test_zero( cpl_image_subtract_scalar(imf, (double)MAGIC_PIXEL) ); - cpl_test_zero( cpl_image_divide_scalar(imf, -(double)MAGIC_PIXEL) ); + cpl_msg_info("", "Compute imf = ((((imf+42)*42)-42)/-42)"); + cpl_test_zero(cpl_image_add_scalar(imf, (double)MAGIC_PIXEL)); + cpl_test_zero(cpl_image_multiply_scalar(imf, (double)MAGIC_PIXEL)); + cpl_test_zero(cpl_image_subtract_scalar(imf, (double)MAGIC_PIXEL)); + cpl_test_zero(cpl_image_divide_scalar(imf, -(double)MAGIC_PIXEL)); /* imd=((((imd+MAGIC_PIXEL)*MAGIC_PIXEL)-MAGIC_PIXEL)/-MAGIC_PIXEL)*/ /* with local functions */ - cpl_msg_info("","Compute imd = ((((imd+42)*42)-42)/-42)"); - cpl_test_zero( cpl_image_add_scalar(imd, (double)MAGIC_PIXEL) ); - cpl_test_zero( cpl_image_multiply_scalar(imd, (double)MAGIC_PIXEL) ); - cpl_test_zero( cpl_image_subtract_scalar(imd, (double)MAGIC_PIXEL) ); - cpl_test_zero( cpl_image_divide_scalar(imd, -(double)MAGIC_PIXEL) ); + cpl_msg_info("", "Compute imd = ((((imd+42)*42)-42)/-42)"); + cpl_test_zero(cpl_image_add_scalar(imd, (double)MAGIC_PIXEL)); + cpl_test_zero(cpl_image_multiply_scalar(imd, (double)MAGIC_PIXEL)); + cpl_test_zero(cpl_image_subtract_scalar(imd, (double)MAGIC_PIXEL)); + cpl_test_zero(cpl_image_divide_scalar(imd, -(double)MAGIC_PIXEL)); /* imi=((((imi+MAGIC_PIXEL)*MAGIC_PIXEL)-MAGIC_PIXEL)/-MAGIC_PIXEL)*/ /* with local functions */ - cpl_msg_info("","Compute imi = ((((imi+42)*42)-42)/-42)"); - cpl_test_zero( cpl_image_add_scalar(imi, (double)MAGIC_PIXEL) ); - cpl_test_zero( cpl_image_multiply_scalar(imi, (double)MAGIC_PIXEL) ); - cpl_test_zero( cpl_image_subtract_scalar(imi, (double)MAGIC_PIXEL) ); - cpl_test_zero( cpl_image_divide_scalar(imi, -(double)MAGIC_PIXEL) ); - + cpl_msg_info("", "Compute imi = ((((imi+42)*42)-42)/-42)"); + cpl_test_zero(cpl_image_add_scalar(imi, (double)MAGIC_PIXEL)); + cpl_test_zero(cpl_image_multiply_scalar(imi, (double)MAGIC_PIXEL)); + cpl_test_zero(cpl_image_subtract_scalar(imi, (double)MAGIC_PIXEL)); + cpl_test_zero(cpl_image_divide_scalar(imi, -(double)MAGIC_PIXEL)); + /* Compute imi = |imi|, imf = |imf| and imd = |imd| */ - cpl_msg_info("","Take the absolute value of imi, imf and imd"); + cpl_msg_info("", "Take the absolute value of imi, imf and imd"); imtmp = cpl_image_abs_create(imi); - cpl_image_delete(imi); + cpl_image_delete(imi); imi = imtmp; imtmp = NULL; imtmp = cpl_image_abs_create(imf); - cpl_image_delete(imf); + cpl_image_delete(imf); imf = imtmp; imtmp = NULL; imtmp = cpl_image_abs_create(imd); - cpl_image_delete(imd); + cpl_image_delete(imd); imd = imtmp; imtmp = NULL; - + /* Test cpl_image_move() */ - cpl_msg_info("","Test the pixels moving function on imd"); + cpl_msg_info("", "Test the pixels moving function on imd"); imd1 = cpl_image_extract(imd, 11, 11, 13, 16); - nb_cut = 3; + nb_cut = 1; + + error = cpl_image_move(NULL, nb_cut, new_pos); + cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT); + error = cpl_image_move(imd1, nb_cut, NULL); + cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT); + error = cpl_image_move(imd1, 0, new_pos); + cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); + error = cpl_image_move(imd1, IMAGESZ + 1, new_pos); + cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); + + imtmp = cpl_image_duplicate(imd1); - error = cpl_image_move(imd1, nb_cut, new_pos); + error = cpl_image_move(imd1, nb_cut, &nb_cut); cpl_test_eq_error(error, CPL_ERROR_NONE); + + nb_cut = 3; + error = cpl_image_move(imd1, nb_cut - 1, new_pos); + cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); + + for (k = 0; k < nb_cut * nb_cut; k++) { + error = cpl_image_move(imd1, nb_cut, new_pos); + cpl_test_eq_error(error, CPL_ERROR_NONE); + } + cpl_test_image_abs(imd1, imtmp, 0.0); cpl_image_delete(imd1); + cpl_image_delete(imtmp); /* Test extraction w. a bad pixel */ cpl_test_zero(cpl_image_reject(imd, 12, 14)); @@ -689,114 +722,117 @@ cpl_image_delete(imd1); /* Threshold imi, imf and imd */ - cpl_msg_info("","Threshold imi, imf and imd"); - cpl_image_threshold(imi, -DBL_MAX, (double)MAGIC_PIXEL, - 0.0, (double)MAGIC_PIXEL); - cpl_image_threshold(imf, -DBL_MAX, (double)MAGIC_PIXEL, - 0.0, (double)MAGIC_PIXEL); - cpl_image_threshold(imd, -DBL_MAX, (double)MAGIC_PIXEL, - 0.0, (double)MAGIC_PIXEL); + cpl_msg_info("", "Threshold imi, imf and imd"); + cpl_image_threshold(imi, -DBL_MAX, (double)MAGIC_PIXEL, 0.0, + (double)MAGIC_PIXEL); + cpl_image_threshold(imf, -DBL_MAX, (double)MAGIC_PIXEL, 0.0, + (double)MAGIC_PIXEL); + cpl_image_threshold(imd, -DBL_MAX, (double)MAGIC_PIXEL, 0.0, + (double)MAGIC_PIXEL); /* Subtract the min of the image from the image -> imi, imf and imd */ - cpl_msg_info("","Subtract the minimum for imi, imf and imd"); - cpl_test_zero( cpl_image_subtract_scalar(imi, cpl_image_get_min(imi)) ); - cpl_test_zero( cpl_image_subtract_scalar(imf, cpl_image_get_min(imf)) ); - cpl_test_zero( cpl_image_subtract_scalar(imd, cpl_image_get_min(imd)) ); + cpl_msg_info("", "Subtract the minimum for imi, imf and imd"); + cpl_test_zero(cpl_image_subtract_scalar(imi, cpl_image_get_min(imi))); + cpl_test_zero(cpl_image_subtract_scalar(imf, cpl_image_get_min(imf))); + cpl_test_zero(cpl_image_subtract_scalar(imd, cpl_image_get_min(imd))); /* Extract sub windows from imf and imd */ - cpl_msg_info("","Extract the central part of imi, imf and imd"); - imtmp = cpl_image_extract(imi, IMAGESZ/4, IMAGESZ/4, IMAGESZ/2, IMAGESZ/2); - cpl_test_nonnull( imtmp ); - cpl_image_delete(imi); + cpl_msg_info("", "Extract the central part of imi, imf and imd"); + imtmp = cpl_image_extract(imi, IMAGESZ / 4, IMAGESZ / 4, IMAGESZ / 2, + IMAGESZ / 2); + cpl_test_nonnull(imtmp); + cpl_image_delete(imi); imi = imtmp; imtmp = NULL; - imtmp = cpl_image_extract(imf, IMAGESZ/4, IMAGESZ/4, IMAGESZ/2, IMAGESZ/2); - cpl_test_nonnull( imtmp ); - cpl_image_delete(imf); + imtmp = cpl_image_extract(imf, IMAGESZ / 4, IMAGESZ / 4, IMAGESZ / 2, + IMAGESZ / 2); + cpl_test_nonnull(imtmp); + cpl_image_delete(imf); imf = imtmp; imtmp = NULL; - imtmp = cpl_image_extract(imd, IMAGESZ/4, IMAGESZ/4, IMAGESZ/2, IMAGESZ/2); - cpl_test_nonnull( imtmp ); - cpl_image_delete(imd); + imtmp = cpl_image_extract(imd, IMAGESZ / 4, IMAGESZ / 4, IMAGESZ / 2, + IMAGESZ / 2); + cpl_test_nonnull(imtmp); + cpl_image_delete(imd); imd = imtmp; imtmp = NULL; /* Test exp operation */ - cpl_msg_info("","Compute exp(imi), exp(imf) and exp(imd)"); - cpl_test_zero( cpl_image_exponential(imi, CPL_MATH_E) ); - cpl_test_zero( cpl_image_exponential(imf, CPL_MATH_E) ); - cpl_test_zero( cpl_image_exponential(imd, CPL_MATH_E) ); - + cpl_msg_info("", "Compute exp(imi), exp(imf) and exp(imd)"); + cpl_test_zero(cpl_image_exponential(imi, CPL_MATH_E)); + cpl_test_zero(cpl_image_exponential(imf, CPL_MATH_E)); + cpl_test_zero(cpl_image_exponential(imd, CPL_MATH_E)); + /* Test log operation */ - cpl_msg_info("","Compute log(imi), log(imf) and log(imd)"); - cpl_test_zero( cpl_image_logarithm(imi, CPL_MATH_E) ); - cpl_test_zero( cpl_image_logarithm(imf, CPL_MATH_E) ); - cpl_test_zero( cpl_image_logarithm(imd, CPL_MATH_E) ); - + cpl_msg_info("", "Compute log(imi), log(imf) and log(imd)"); + cpl_test_zero(cpl_image_logarithm(imi, CPL_MATH_E)); + cpl_test_zero(cpl_image_logarithm(imf, CPL_MATH_E)); + cpl_test_zero(cpl_image_logarithm(imd, CPL_MATH_E)); + /* Test ^ operation */ - cpl_msg_info("","Compute imi^2, imf^2 and imd^2"); - cpl_test_zero( cpl_image_power(imi, 2.0) ); - cpl_test_zero( cpl_image_power(imf, 2.0) ); - cpl_test_zero( cpl_image_power(imd, 2.0) ); - + cpl_msg_info("", "Compute imi^2, imf^2 and imd^2"); + cpl_test_zero(cpl_image_power(imi, 2.0)); + cpl_test_zero(cpl_image_power(imf, 2.0)); + cpl_test_zero(cpl_image_power(imd, 2.0)); + /* Test sqrt operation */ - cpl_msg_info("","Compute imf^0.5 and imd^0.5"); - cpl_test_zero( cpl_image_power(imf, 0.5) ); - cpl_test_zero( cpl_image_power(imd, 0.5) ); + cpl_msg_info("", "Compute imf^0.5 and imd^0.5"); + cpl_test_zero(cpl_image_power(imf, 0.5)); + cpl_test_zero(cpl_image_power(imd, 0.5)); /* TEST CROSS-TYPES OPERATIONS */ - cpl_msg_info("","Test cross types operations"); + cpl_msg_info("", "Test cross types operations"); imtmp = cpl_image_add_create(imf, imd); - cpl_msg_info("","Get mean of imf + imd : %g", cpl_image_get_mean(imtmp)); + cpl_msg_info("", "Get mean of imf + imd : %g", cpl_image_get_mean(imtmp)); cpl_image_delete(imtmp); imtmp = cpl_image_add_create(imd, imf); - cpl_msg_info("","Get mean of imd + imf : %g", cpl_image_get_mean(imtmp)); + cpl_msg_info("", "Get mean of imd + imf : %g", cpl_image_get_mean(imtmp)); cpl_image_delete(imtmp); imtmp = cpl_image_subtract_create(imf, imd); - cpl_msg_info("","Get mean of imf - imd : %g", cpl_image_get_mean(imtmp)); + cpl_msg_info("", "Get mean of imf - imd : %g", cpl_image_get_mean(imtmp)); cpl_image_delete(imtmp); imtmp = cpl_image_subtract_create(imd, imf); - cpl_msg_info("","Get mean of imd - imf : %g", cpl_image_get_mean(imtmp)); + cpl_msg_info("", "Get mean of imd - imf : %g", cpl_image_get_mean(imtmp)); cpl_image_delete(imtmp); imtmp = cpl_image_multiply_create(imf, imd); - cpl_msg_info("","Get mean of imf * imd : %g", cpl_image_get_mean(imtmp)); + cpl_msg_info("", "Get mean of imf * imd : %g", cpl_image_get_mean(imtmp)); cpl_image_delete(imtmp); imtmp = cpl_image_multiply_create(imd, imf); - cpl_msg_info("","Get mean of imd * imf : %g", cpl_image_get_mean(imtmp)); + cpl_msg_info("", "Get mean of imd * imf : %g", cpl_image_get_mean(imtmp)); cpl_image_delete(imtmp); imtmp = cpl_image_divide_create(imf, imd); - cpl_msg_info("","Get mean of imf / imd : %g", cpl_image_get_mean(imtmp)); + cpl_msg_info("", "Get mean of imf / imd : %g", cpl_image_get_mean(imtmp)); cpl_image_delete(imtmp); imtmp = cpl_image_divide_create(imd, imf); - cpl_msg_info("","Get mean of imd / imf : %g", cpl_image_get_mean(imtmp)); + cpl_msg_info("", "Get mean of imd / imf : %g", cpl_image_get_mean(imtmp)); cpl_image_delete(imtmp); - + /* Normalize imf and imd */ - cpl_msg_info("","Normalize imf and imd"); + cpl_msg_info("", "Normalize imf and imd"); imtmp = cpl_image_normalise_create(imf, CPL_NORM_MEAN); - cpl_test_nonnull( imtmp ); - cpl_image_delete(imf); + cpl_test_nonnull(imtmp); + cpl_image_delete(imf); imf = imtmp; imtmp = NULL; imtmp = cpl_image_normalise_create(imd, CPL_NORM_MEAN); - cpl_test_nonnull( imtmp ); - cpl_image_delete(imd); + cpl_test_nonnull(imtmp); + cpl_image_delete(imd); imd = imtmp; imtmp = NULL; - + /* Test the insertion function */ - cpl_msg_info("","Insert an image in an other one"); + cpl_msg_info("", "Insert an image in an other one"); imtmp = cpl_image_duplicate(imd); cpl_image_reject(imtmp, 1, 1); - cpl_test_zero( cpl_image_copy(imd, imtmp, 100, 100) ); + cpl_test_zero(cpl_image_copy(imd, imtmp, 100, 100)); cpl_test(cpl_image_is_rejected(imd, 100, 100)); cpl_image_delete(imtmp); - + /* Test the shift function */ - cpl_msg_info("","Compute various shifts on imi, imf and imda"); - cpl_test_zero( cpl_image_shift(imd, 1, 1) ); - cpl_test_zero( cpl_image_shift(imf, 1, 1) ); - cpl_test_zero( cpl_image_shift(imi, 1, 1) ); + cpl_msg_info("", "Compute various shifts on imi, imf and imda"); + cpl_test_zero(cpl_image_shift(imd, 1, 1)); + cpl_test_zero(cpl_image_shift(imf, 1, 1)); + cpl_test_zero(cpl_image_shift(imi, 1, 1)); cpl_image_delete(imi); cpl_image_delete(imf); @@ -804,41 +840,42 @@ /* Test for DFS02049 : Handle the division by ZERO */ /* Divide 3 | 4 by 2 | 0 --> 1.5 | X */ - /* - - - - - - */ - /* 2 | 3 2 | 0 1 | X */ + /* - - - - - - */ + /* 2 | 3 2 | 0 1 | X */ imtmp = cpl_image_new(2, 2, CPL_TYPE_DOUBLE); imd = cpl_image_new(2, 2, CPL_TYPE_DOUBLE); imf = cpl_image_new(2, 2, CPL_TYPE_FLOAT); imi = cpl_image_new(2, 2, CPL_TYPE_INT); - for (i=0; i<2; i++) { - for (j=0; j<2; j++) { - if (i==0) cpl_image_set(imtmp, i+1, j+1, 2.0); - cpl_image_set(imi, i+1, j+1, (double)(i+j+2)); - cpl_image_set(imf, i+1, j+1, (double)(i+j+2)); - cpl_image_set(imd, i+1, j+1, (double)(i+j+2)); + for (i = 0; i < 2; i++) { + for (j = 0; j < 2; j++) { + if (i == 0) + cpl_image_set(imtmp, i + 1, j + 1, 2.0); + cpl_image_set(imi, i + 1, j + 1, (double)(i + j + 2)); + cpl_image_set(imf, i + 1, j + 1, (double)(i + j + 2)); + cpl_image_set(imd, i + 1, j + 1, (double)(i + j + 2)); } - } + } imd1 = cpl_image_divide_create(imd, imtmp); imf1 = cpl_image_divide_create(imf, imtmp); imi1 = cpl_image_divide_create(imi, imtmp); - cpl_test_nonnull( imd1 ); - cpl_test_nonnull( imf1 ); - cpl_test_nonnull( imi1 ); - - cpl_test_abs( cpl_image_get_flux(imd1), 2.5, 0.0 ); - cpl_test_abs( cpl_image_get_flux(imf1), 2.5, 0.0 ); - cpl_test_abs( cpl_image_get_flux(imi1), 2.0, 0.0 ); + cpl_test_nonnull(imd1); + cpl_test_nonnull(imf1); + cpl_test_nonnull(imi1); + + cpl_test_abs(cpl_image_get_flux(imd1), 2.5, 0.0); + cpl_test_abs(cpl_image_get_flux(imf1), 2.5, 0.0); + cpl_test_abs(cpl_image_get_flux(imi1), 2.0, 0.0); cpl_image_delete(imd1); cpl_image_delete(imf1); cpl_image_delete(imi1); - cpl_test_zero( cpl_image_divide(imd, imtmp) ); - cpl_test_zero( cpl_image_divide(imf, imtmp) ); - cpl_test_zero( cpl_image_divide(imi, imtmp) ); - - cpl_test_abs( cpl_image_get_flux(imd), 2.5, 0.0 ); - cpl_test_abs( cpl_image_get_flux(imf), 2.5, 0.0 ); - cpl_test_abs( cpl_image_get_flux(imi), 2.0, 0.0 ); + cpl_test_zero(cpl_image_divide(imd, imtmp)); + cpl_test_zero(cpl_image_divide(imf, imtmp)); + cpl_test_zero(cpl_image_divide(imi, imtmp)); + + cpl_test_abs(cpl_image_get_flux(imd), 2.5, 0.0); + cpl_test_abs(cpl_image_get_flux(imf), 2.5, 0.0); + cpl_test_abs(cpl_image_get_flux(imi), 2.0, 0.0); cpl_image_delete(imtmp); cpl_image_delete(imd); @@ -852,11 +889,11 @@ imf1 = cpl_image_new(IMAGESZ, IMAGESZ, CPL_TYPE_FLOAT); imd1 = cpl_image_new(IMAGESZ, IMAGESZ, CPL_TYPE_DOUBLE); - cpl_msg_info("","Compute imf(0.0)^0.0"); - cpl_test_zero( cpl_image_power(imf, 0.0) ); - cpl_test_zero( cpl_image_power(imd, 0.0) ); - cpl_test_zero( cpl_image_subtract_scalar(imf, 1.0) ); - cpl_test_zero( cpl_image_subtract_scalar(imd, 1.0) ); + cpl_msg_info("", "Compute imf(0.0)^0.0"); + cpl_test_zero(cpl_image_power(imf, 0.0)); + cpl_test_zero(cpl_image_power(imd, 0.0)); + cpl_test_zero(cpl_image_subtract_scalar(imf, 1.0)); + cpl_test_zero(cpl_image_subtract_scalar(imd, 1.0)); cpl_test_image_abs(imf, imf1, 0.0); cpl_test_image_abs(imd, imd1, 0.0); @@ -877,8 +914,8 @@ data2 = cpl_image_get_data_double_complex(imdc2); for (i = 0; i < IMAGESZ * IMAGESZ; i++) { - data1[i] = i + i * cpl_i; - data2[i] = 2 * i + 2 * i * cpl_i; + data1[i] = i + i * cpl_i; + data2[i] = 2 * i + 2 * i * cpl_i; } imdc3 = cpl_image_add_create(imdc1, imdc2); @@ -886,7 +923,7 @@ data3 = cpl_image_get_data_double_complex(imdc3); for (i = 0; i < IMAGESZ * IMAGESZ; i++) { - cpl_test_abs( data3[i], 3 * i + 3 * i * cpl_i, 0.0 ); + cpl_test_abs(data3[i], 3 * i + 3 * i * cpl_i, 0.0); } cpl_image_delete(imdc1); @@ -902,8 +939,8 @@ dataf2 = cpl_image_get_data_float_complex(imfc2); for (i = 0; i < IMAGESZ * IMAGESZ; i++) { - dataf1[i] = i + i * cpl_i; - dataf2[i] = 2 * i + 2 * i * cpl_i; + dataf1[i] = i + i * cpl_i; + dataf2[i] = 2 * i + 2 * i * cpl_i; } imfc3 = cpl_image_add_create(imfc1, imfc2); @@ -911,7 +948,7 @@ dataf3 = cpl_image_get_data_float_complex(imfc3); for (i = 0; i < IMAGESZ * IMAGESZ; i++) { - cpl_test_abs( dataf3[i], 3 * i + 3 * i * cpl_i, 0.0 ); + cpl_test_abs(dataf3[i], 3 * i + 3 * i * cpl_i, 0.0); } cpl_image_delete(imfc1); @@ -953,25 +990,28 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_image_complex_mult(size_t o1, size_t o2, size_t n) +static void +cpl_image_complex_mult(size_t o1, size_t o2, size_t n) { /* test multiplication, compares vector version with scalar version */ const size_t nl = n + 2; const float complex cpl_i = csqrtf(-1.0); - float complex * dataf1_ = cpl_malloc(nl * nl * sizeof(float complex)); - float complex * dataf2_ = cpl_malloc(nl * nl * sizeof(float complex)); - float complex * dataf3; - float complex * dataf4 = cpl_malloc(n * n * sizeof(float complex)); - float complex * dataf1 = dataf1_; - float complex * dataf2 = dataf2_; + float complex *dataf1_ = cpl_malloc(nl * nl * sizeof(float complex)); + float complex *dataf2_ = cpl_malloc(nl * nl * sizeof(float complex)); + float complex *dataf3; + float complex *dataf4 = cpl_malloc(n * n * sizeof(float complex)); + float complex *dataf1 = dataf1_; + float complex *dataf2 = dataf2_; size_t do1 = ((intptr_t)dataf1) % 16; size_t do2 = ((intptr_t)dataf2) % 16; - cpl_image * imfc1; - cpl_image * imfc2; + cpl_image *imfc1; + cpl_image *imfc2; - cpl_msg_info(cpl_func, "Float complex vector multiply, " - "size: %zu, offsets: %zu %zu", n * n, o1, o2); + cpl_msg_info(cpl_func, + "Float complex vector multiply, " + "size: %zu, offsets: %zu %zu", + n * n, o1, o2); do1 = (do1 ? (16u - do1) / sizeof(float complex) : 0u) + o1; do2 = (do2 ? (16u - do2) / sizeof(float complex) : 0u) + o2; @@ -1048,25 +1088,28 @@ } -static void cpl_image_complex_mult_d(size_t o1, size_t o2, size_t n) +static void +cpl_image_complex_mult_d(size_t o1, size_t o2, size_t n) { /* test multiplication, compares vector version with scalar version */ const size_t nl = n + 2; const double complex cpl_i = csqrt(-1.0); - double complex * dataf1_ = cpl_malloc(nl * nl * sizeof(double complex)); - double complex * dataf2_ = cpl_malloc(nl * nl * sizeof(double complex)); - double complex * dataf3; - double complex * dataf4 = cpl_malloc(n * n * sizeof(double complex)); - double complex * dataf1 = dataf1_; - double complex * dataf2 = dataf2_; + double complex *dataf1_ = cpl_malloc(nl * nl * sizeof(double complex)); + double complex *dataf2_ = cpl_malloc(nl * nl * sizeof(double complex)); + double complex *dataf3; + double complex *dataf4 = cpl_malloc(n * n * sizeof(double complex)); + double complex *dataf1 = dataf1_; + double complex *dataf2 = dataf2_; size_t do1 = ((intptr_t)dataf1) % 16; size_t do2 = ((intptr_t)dataf2) % 16; - cpl_image * imfc1; - cpl_image * imfc2; + cpl_image *imfc1; + cpl_image *imfc2; - cpl_msg_info(cpl_func, "Double complex vector multiply, " - "size: %zu, offsets: %zu %zu", n * n, o1, o2); + cpl_msg_info(cpl_func, + "Double complex vector multiply, " + "size: %zu, offsets: %zu %zu", + n * n, o1, o2); /* i386 aligns complex double 8 bytes */ do1 = (do1 ? (16u - do1) / sizeof(double) : 0u) + o1; @@ -1152,11 +1195,11 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_image_copy_test(void) +static void +cpl_image_copy_test(void) { - - cpl_image * im1 = cpl_image_new(IMAGESZ, IMAGESZ, CPL_TYPE_DOUBLE); - cpl_image * im2 = cpl_image_new(IMAGESZ, IMAGESZ, CPL_TYPE_INT); + cpl_image *im1 = cpl_image_new(IMAGESZ, IMAGESZ, CPL_TYPE_DOUBLE); + cpl_image *im2 = cpl_image_new(IMAGESZ, IMAGESZ, CPL_TYPE_INT); cpl_error_code error; error = cpl_image_copy(NULL, im1, 1, 1); @@ -1177,10 +1220,10 @@ error = cpl_image_copy(im1, im2, 1, 0); cpl_test_eq_error(error, CPL_ERROR_ACCESS_OUT_OF_RANGE); - error = cpl_image_copy(im1, im2, IMAGESZ+1, 1); + error = cpl_image_copy(im1, im2, IMAGESZ + 1, 1); cpl_test_eq_error(error, CPL_ERROR_ACCESS_OUT_OF_RANGE); - error = cpl_image_copy(im1, im2, 1, IMAGESZ+1); + error = cpl_image_copy(im1, im2, 1, IMAGESZ + 1); cpl_test_eq_error(error, CPL_ERROR_ACCESS_OUT_OF_RANGE); /* Test copy of whole image */ @@ -1196,9 +1239,12 @@ cpl_test_zero(cpl_image_copy(im1, im2, 3, 1)); cpl_test_abs(cpl_image_get_flux(im1), 2.0 * IMAGESZ, 0.0); - cpl_test_abs(cpl_image_get_flux_window(im1, 1, 1, 1, IMAGESZ), IMAGESZ, 0.0); - cpl_test_abs(cpl_image_get_flux_window(im1, 2, 1, 2, IMAGESZ), IMAGESZ, 0.0); - cpl_test_abs(cpl_image_get_flux_window(im1, 3, 1, IMAGESZ, IMAGESZ), 0.0, 0.0); + cpl_test_abs(cpl_image_get_flux_window(im1, 1, 1, 1, IMAGESZ), IMAGESZ, + 0.0); + cpl_test_abs(cpl_image_get_flux_window(im1, 2, 1, 2, IMAGESZ), IMAGESZ, + 0.0); + cpl_test_abs(cpl_image_get_flux_window(im1, 3, 1, IMAGESZ, IMAGESZ), 0.0, + 0.0); /* Test copy of whole number of rows (all but two) */ cpl_test_zero(cpl_image_copy(im1, im2, 1, 1)); @@ -1208,9 +1254,12 @@ cpl_test_zero(cpl_image_copy(im1, im2, 1, 3)); cpl_test_abs(cpl_image_get_flux(im1), 2.0 * IMAGESZ, 0.0); - cpl_test_abs(cpl_image_get_flux_window(im1, 1, 1, IMAGESZ, 1), IMAGESZ, 0.0); - cpl_test_abs(cpl_image_get_flux_window(im1, 1, 2, IMAGESZ, 2), IMAGESZ, 0.0); - cpl_test_abs(cpl_image_get_flux_window(im1, 1, 3, IMAGESZ, IMAGESZ), 0.0, 0.0); + cpl_test_abs(cpl_image_get_flux_window(im1, 1, 1, IMAGESZ, 1), IMAGESZ, + 0.0); + cpl_test_abs(cpl_image_get_flux_window(im1, 1, 2, IMAGESZ, 2), IMAGESZ, + 0.0); + cpl_test_abs(cpl_image_get_flux_window(im1, 1, 3, IMAGESZ, IMAGESZ), 0.0, + 0.0); cpl_image_delete(im1); cpl_image_delete(im2); @@ -1226,28 +1275,28 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_image_turn_flip_test(void) +static void +cpl_image_turn_flip_test(void) { - - const cpl_type ttype[] = {CPL_TYPE_INT, CPL_TYPE_FLOAT, CPL_TYPE_DOUBLE}; + const cpl_type ttype[] = { CPL_TYPE_INT, CPL_TYPE_FLOAT, CPL_TYPE_DOUBLE }; size_t itype; - const int npix[] = {1, 2, 3, 5, 10, 11}; + const int npix[] = { 1, 2, 3, 5, 10, 11 }; - const int buf9[] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; + const int buf9[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; /* Rotate this 90 degrees clockwise to get buf9 */ - const int rot9[] = {7, 4, 1, 8, 5, 2, 9, 6, 3}; + const int rot9[] = { 7, 4, 1, 8, 5, 2, 9, 6, 3 }; /* This image is not modified while wrapping around this buffer */ - cpl_image * ref = cpl_image_new(3, 3, CPL_TYPE_INT); - cpl_image * raw = cpl_image_new(3, 3, CPL_TYPE_INT); + cpl_image *ref = cpl_image_new(3, 3, CPL_TYPE_INT); + cpl_image *raw = cpl_image_new(3, 3, CPL_TYPE_INT); cpl_error_code error; - cpl_test_eq_ptr(memcpy(cpl_image_get_data_int(ref), buf9, 9*sizeof(int)), + cpl_test_eq_ptr(memcpy(cpl_image_get_data_int(ref), buf9, 9 * sizeof(int)), cpl_image_get_data_int_const(ref)); /* Test 1: Verify direction of 90 degree rotation */ - cpl_test_eq_ptr(memcpy(cpl_image_get_data_int(raw), rot9, 9*sizeof(int)), + cpl_test_eq_ptr(memcpy(cpl_image_get_data_int(raw), rot9, 9 * sizeof(int)), cpl_image_get_data_int_const(raw)); error = cpl_image_turn(raw, 1); @@ -1267,24 +1316,25 @@ cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT); /* Test 3: Verify consistency of rotations across types */ - for (itype = 0; itype < sizeof(ttype)/sizeof(ttype[0]); itype++) { + for (itype = 0; itype < sizeof(ttype) / sizeof(ttype[0]); itype++) { const cpl_type imtype = ttype[itype]; size_t ipix; - for (ipix = 0; ipix < sizeof(npix)/sizeof(npix[0]); ipix++) { + for (ipix = 0; ipix < sizeof(npix) / sizeof(npix[0]); ipix++) { const int nx = npix[ipix]; size_t jpix; - for (jpix = 0; jpix < sizeof(npix)/sizeof(npix[0]); jpix++) { + for (jpix = 0; jpix < sizeof(npix) / sizeof(npix[0]); jpix++) { const int ny = npix[jpix]; - cpl_mask * bpm; + cpl_mask *bpm; raw = cpl_image_new(nx, ny, imtype); - error = cpl_image_fill_noise_uniform(raw, (double)-ny, - (double)nx); + error = + cpl_image_fill_noise_uniform(raw, (double)-ny, (double)nx); cpl_test_eq_error(error, CPL_ERROR_NONE); /* About 1/4 of the pixels are flagged */ - bpm = cpl_mask_threshold_image_create(raw, -0.25*ny, 0.25*nx); + bpm = + cpl_mask_threshold_image_create(raw, -0.25 * ny, 0.25 * nx); if (cpl_mask_count(bpm) < nx * ny) { /* Will not test with no good pixels */ error = cpl_image_reject_from_mask(raw, bpm); @@ -1303,11 +1353,11 @@ cpl_test_eq_error(error, CPL_ERROR_NONE); error = cpl_image_turn(raw, 4); cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_image_turn(raw,-1); + error = cpl_image_turn(raw, -1); cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_image_turn(raw,-2); + error = cpl_image_turn(raw, -2); cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_image_turn(raw,-3); + error = cpl_image_turn(raw, -3); cpl_test_eq_error(error, CPL_ERROR_NONE); error = cpl_image_turn(raw, 0); cpl_test_eq_error(error, CPL_ERROR_NONE); @@ -1351,17 +1401,17 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_image_collapse_median_test(void) +static void +cpl_image_collapse_median_test(void) { - const int mx = IMAGESZ | 1; - const int my = IMAGESZ/2 | 1; - const cpl_type types[] = {CPL_TYPE_DOUBLE_COMPLEX, - CPL_TYPE_FLOAT_COMPLEX}; - const cpl_type imtypes[] = {CPL_TYPE_DOUBLE, CPL_TYPE_FLOAT, - CPL_TYPE_INT}; - cpl_image * null; - int ityp; + const int my = IMAGESZ / 2 | 1; + const cpl_type types[] = { CPL_TYPE_DOUBLE_COMPLEX, + CPL_TYPE_FLOAT_COMPLEX }; + const cpl_type imtypes[] = { CPL_TYPE_DOUBLE, CPL_TYPE_FLOAT, + CPL_TYPE_INT }; + cpl_image *null; + int ityp; null = cpl_image_collapse_median_create(NULL, 0, 0, 0); @@ -1369,9 +1419,9 @@ cpl_test_null(null); /* Iterate through all non-supported pixel types */ - for (ityp = 0; ityp < (int)(sizeof(types)/sizeof(types[0])); ityp++) { + for (ityp = 0; ityp < (int)(sizeof(types) / sizeof(types[0])); ityp++) { const cpl_type imtype = types[ityp]; - cpl_image * img = cpl_image_new(mx, my, imtype); + cpl_image *img = cpl_image_new(mx, my, imtype); cpl_test_nonnull(img); @@ -1384,9 +1434,9 @@ /* Iterate through all supported pixel types */ - for (ityp = 0; ityp < (int)(sizeof(imtypes)/sizeof(imtypes[0])); ityp++) { + for (ityp = 0; ityp < (int)(sizeof(imtypes) / sizeof(imtypes[0])); ityp++) { const cpl_type imtype = imtypes[ityp]; - cpl_image * img = cpl_image_new(mx, my, imtype); + cpl_image *img = cpl_image_new(mx, my, imtype); int idrop; cpl_test_nonnull(img); @@ -1414,25 +1464,24 @@ cpl_test_null(null); /* Iterate through various drop combinations for dir == 0 */ - for (idrop = 0; idrop * 2 < 5; idrop ++) { - - cpl_image * filt = cpl_image_new(mx, 1 + 2 * idrop, imtype); - cpl_mask * mask = cpl_mask_new(1, my - 2 * idrop); + for (idrop = 0; idrop * 2 < 5; idrop++) { + cpl_image *filt = cpl_image_new(mx, 1 + 2 * idrop, imtype); + cpl_mask *mask = cpl_mask_new(1, my - 2 * idrop); int jdrop; cpl_error_code error; cpl_mask_not(mask); - error = cpl_image_filter_mask(filt, img, mask, - CPL_FILTER_MEDIAN, CPL_BORDER_CROP); + error = cpl_image_filter_mask(filt, img, mask, CPL_FILTER_MEDIAN, + CPL_BORDER_CROP); cpl_test_eq_error(error, CPL_ERROR_NONE); for (jdrop = 0; jdrop <= 2 * idrop; jdrop++) { - cpl_image * med - = cpl_image_collapse_median_create(img, 0, jdrop, - 2 * idrop - jdrop); - cpl_image * img1d = cpl_image_extract(filt, 1, 1 + jdrop, mx, - 1 + jdrop); + cpl_image *med = + cpl_image_collapse_median_create(img, 0, jdrop, + 2 * idrop - jdrop); + cpl_image *img1d = + cpl_image_extract(filt, 1, 1 + jdrop, mx, 1 + jdrop); int k, is_bad, is_bad2; cpl_test_nonnull(med); @@ -1457,7 +1506,7 @@ /* Accept all pixels in one column */ for (k = 1; k <= my; k++) { - cpl_image_accept(img, mx/2, k); + cpl_image_accept(img, mx / 2, k); } cpl_test_eq(cpl_image_count_rejected(img), mx * my - my); @@ -1467,8 +1516,8 @@ cpl_test_nonnull(med); cpl_test_eq(cpl_image_count_rejected(med), mx - 1); - cpl_test_abs(cpl_image_get(med, mx/2, 1, &is_bad), - cpl_image_get(img1d, mx/2, 1, &is_bad2), 0.0); + cpl_test_abs(cpl_image_get(med, mx / 2, 1, &is_bad), + cpl_image_get(img1d, mx / 2, 1, &is_bad2), 0.0); cpl_test_zero(is_bad); cpl_test_zero(is_bad2); @@ -1482,7 +1531,7 @@ /* Accept all pixels in one row */ cpl_mask_not(cpl_image_get_bpm(img)); for (k = 1; k <= mx; k++) { - cpl_image_accept(img, k, my/2); + cpl_image_accept(img, k, my / 2); } med = cpl_image_collapse_median_create(img, 0, jdrop, @@ -1491,7 +1540,7 @@ cpl_test_zero(cpl_image_count_rejected(med)); - img1d = cpl_image_extract(img, 1, my/2, mx, my/2); + img1d = cpl_image_extract(img, 1, my / 2, mx, my / 2); cpl_test_image_abs(med, img1d, 0.0); @@ -1504,25 +1553,24 @@ } /* Iterate through various drop combinations for dir == 1 */ - for (idrop = 0; idrop * 2 < 5; idrop ++) { - - cpl_image * filt = cpl_image_new(1 + 2 * idrop, my, imtype); - cpl_mask * mask = cpl_mask_new(mx - 2 * idrop, 1); + for (idrop = 0; idrop * 2 < 5; idrop++) { + cpl_image *filt = cpl_image_new(1 + 2 * idrop, my, imtype); + cpl_mask *mask = cpl_mask_new(mx - 2 * idrop, 1); int jdrop; cpl_error_code error; cpl_mask_not(mask); - error = cpl_image_filter_mask(filt, img, mask, - CPL_FILTER_MEDIAN, CPL_BORDER_CROP); + error = cpl_image_filter_mask(filt, img, mask, CPL_FILTER_MEDIAN, + CPL_BORDER_CROP); cpl_test_eq_error(error, CPL_ERROR_NONE); for (jdrop = 0; jdrop <= 2 * idrop; jdrop++) { - cpl_image * med - = cpl_image_collapse_median_create(img, 1, jdrop, - 2 * idrop - jdrop); - cpl_image * img1d = cpl_image_extract(filt, 1 + jdrop, 1, - 1 + jdrop, my); + cpl_image *med = + cpl_image_collapse_median_create(img, 1, jdrop, + 2 * idrop - jdrop); + cpl_image *img1d = + cpl_image_extract(filt, 1 + jdrop, 1, 1 + jdrop, my); int k, is_bad, is_bad2; cpl_test_nonnull(med); @@ -1547,7 +1595,7 @@ /* Accept all pixels in one row */ for (k = 1; k <= mx; k++) { - cpl_image_accept(img, k, my/2); + cpl_image_accept(img, k, my / 2); } cpl_test_eq(cpl_image_count_rejected(img), mx * my - mx); @@ -1557,8 +1605,8 @@ cpl_test_nonnull(med); cpl_test_eq(cpl_image_count_rejected(med), my - 1); - cpl_test_abs(cpl_image_get(med, 1, my/2, &is_bad), - cpl_image_get(img1d, 1, my/2, &is_bad2), 0.0); + cpl_test_abs(cpl_image_get(med, 1, my / 2, &is_bad), + cpl_image_get(img1d, 1, my / 2, &is_bad2), 0.0); cpl_test_zero(is_bad); cpl_test_zero(is_bad2); @@ -1575,7 +1623,7 @@ /* Accept all pixels in one column */ cpl_mask_not(cpl_image_get_bpm(img)); for (k = 1; k <= my; k++) { - cpl_image_accept(img, mx/2, k); + cpl_image_accept(img, mx / 2, k); } med = cpl_image_collapse_median_create(img, 1, jdrop, @@ -1584,14 +1632,13 @@ cpl_test_zero(cpl_image_count_rejected(med)); - img1d = cpl_image_extract(img, mx/2, 1, mx/2, my); + img1d = cpl_image_extract(img, mx / 2, 1, mx / 2, my); cpl_test_image_abs(med, img1d, 0.0); cpl_image_delete(img1d); cpl_image_delete(med); cpl_image_accept_all(img); - } cpl_image_delete(filt); cpl_mask_delete(mask); @@ -1601,7 +1648,6 @@ } return; - } @@ -1629,11 +1675,11 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_image_flip_turn_test(const cpl_image * self) +static void +cpl_image_flip_turn_test(const cpl_image *self) { - cpl_error_code error; - cpl_image * tmp = cpl_image_duplicate(self); + cpl_image *tmp = cpl_image_duplicate(self); error = cpl_image_turn(tmp, -1); cpl_test_eq_error(error, CPL_ERROR_NONE); @@ -1669,39 +1715,21 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_image_get_fwhm_test(void) +static void +cpl_image_get_fwhm_test(void) { - /* Test case for DFS12346 */ - const double x[] = { - -13.9055, - -2.24811, - -4.60207, - 12.0745, - -9.29113, - 19.4861, - 17.6999, - 32.2417, - 68.0725, - 120.824, - 172.361, - 242.671, - 302.048, - 355.937, - 348.458, - 309.819, - 240.489, - 179.107, - 117.223, - 66.3061, - 32.7849, - 22.9367, + const double x[] = { + -13.9055, -2.24811, -4.60207, 12.0745, -9.29113, 19.4861, + 17.6999, 32.2417, 68.0725, 120.824, 172.361, 242.671, + 302.048, 355.937, 348.458, 309.819, 240.489, 179.107, + 117.223, 66.3061, 32.7849, 22.9367, }; - const cpl_size sz = (cpl_size)(sizeof(x)/sizeof(x[0])); + const cpl_size sz = (cpl_size)(sizeof(x) / sizeof(x[0])); /* x will _not_ be modified */ - cpl_image * im1d = cpl_image_wrap_double(sz, 1, (double*)x); + cpl_image *im1d = cpl_image_wrap_double(sz, 1, (double *)x); cpl_size xmaxpos, ymaxpos; @@ -1736,7 +1764,7 @@ code = cpl_image_get_fwhm(im1d, 0, ymaxpos, &xfwhm, &yfwhm); cpl_test_eq_error(code, CPL_ERROR_ACCESS_OUT_OF_RANGE); - code = cpl_image_get_fwhm(im1d, sz+1, ymaxpos, &xfwhm, &yfwhm); + code = cpl_image_get_fwhm(im1d, sz + 1, ymaxpos, &xfwhm, &yfwhm); cpl_test_eq_error(code, CPL_ERROR_ACCESS_OUT_OF_RANGE); code = cpl_image_get_fwhm(im1d, xmaxpos, 2, &xfwhm, &yfwhm); @@ -1765,8 +1793,7 @@ cpl_test_abs(xfwhm, xref, 0.0); cpl_test_abs(yfwhm, -1.0, 0.0); - cpl_test_eq_ptr((const void*)x, cpl_image_unwrap(im1d)); - + cpl_test_eq_ptr((const void *)x, cpl_image_unwrap(im1d)); } /*----------------------------------------------------------------------------*/ @@ -1778,10 +1805,11 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_image_divide_test_one(void) { - - cpl_image * img1 = cpl_image_new(1, 2, CPL_TYPE_DOUBLE); - cpl_image * img2 = cpl_image_new(1, 2, CPL_TYPE_DOUBLE); +static void +cpl_image_divide_test_one(void) +{ + cpl_image *img1 = cpl_image_new(1, 2, CPL_TYPE_DOUBLE); + cpl_image *img2 = cpl_image_new(1, 2, CPL_TYPE_DOUBLE); cpl_error_code code; code = cpl_image_add_scalar(img1, 5.0); @@ -1812,7 +1840,6 @@ cpl_image_delete(img1); cpl_image_delete(img2); - } /*----------------------------------------------------------------------------*/ @@ -1824,25 +1851,28 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_image_hypot_test(void) { - - const cpl_type htype[2] = {CPL_TYPE_FLOAT, CPL_TYPE_DOUBLE}; +static void +cpl_image_hypot_test(void) +{ + const cpl_type htype[2] = { CPL_TYPE_FLOAT, CPL_TYPE_DOUBLE }; for (int i1type = 0; i1type < 2; i1type++) { for (int i2type = 0; i2type < 2; i2type++) { for (int i3type = 0; i3type < 2; i3type++) { - const double tol = - htype[i1type] == CPL_TYPE_FLOAT || - htype[i2type] == CPL_TYPE_FLOAT || - htype[i3type] == CPL_TYPE_FLOAT - ? 40.0 * FLT_EPSILON - : 40.0 * DBL_EPSILON; - - cpl_image * img1 = cpl_image_new(IMAGESZ, IMAGESZ, htype[i1type]); - cpl_image * img2 = cpl_image_new(IMAGESZ, IMAGESZ, htype[i2type]); - cpl_image * img3 = cpl_image_new(IMAGESZ, IMAGESZ, htype[i3type]); - cpl_image * img1copy; - cpl_image * img2copy; + const double tol = htype[i1type] == CPL_TYPE_FLOAT || + htype[i2type] == CPL_TYPE_FLOAT || + htype[i3type] == CPL_TYPE_FLOAT + ? 40.0 * FLT_EPSILON + : 40.0 * DBL_EPSILON; + + cpl_image *img1 = + cpl_image_new(IMAGESZ, IMAGESZ, htype[i1type]); + cpl_image *img2 = + cpl_image_new(IMAGESZ, IMAGESZ, htype[i2type]); + cpl_image *img3 = + cpl_image_new(IMAGESZ, IMAGESZ, htype[i3type]); + cpl_image *img1copy; + cpl_image *img2copy; cpl_error_code code; code = cpl_image_fill_noise_uniform(img1, 1.0, MAGIC_PIXEL); @@ -1881,7 +1911,7 @@ cpl_image_delete(img3); /* Verify handling of incompatible size */ - img3 = cpl_image_new(IMAGESZ+1, IMAGESZ, htype[i1type]); + img3 = cpl_image_new(IMAGESZ + 1, IMAGESZ, htype[i1type]); code = cpl_image_hypot(img3, img1copy, img2copy); cpl_test_eq_error(code, CPL_ERROR_INCOMPATIBLE_INPUT); @@ -1902,8 +1932,8 @@ cpl_image_delete(img3); /* Verify handling of unsupported type */ - img3 = cpl_image_new(IMAGESZ+1, IMAGESZ, htype[i1type] - | CPL_TYPE_COMPLEX); + img3 = cpl_image_new(IMAGESZ + 1, IMAGESZ, + htype[i1type] | CPL_TYPE_COMPLEX); code = cpl_image_hypot(img3, img1copy, img2copy); cpl_test_eq_error(code, CPL_ERROR_INVALID_TYPE); @@ -1946,10 +1976,11 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_image_power_test(void) { - - cpl_image * img1 = cpl_image_new(IMAGESZ, IMAGESZ, CPL_TYPE_DOUBLE); - cpl_image * img2; +static void +cpl_image_power_test(void) +{ + cpl_image *img1 = cpl_image_new(IMAGESZ, IMAGESZ, CPL_TYPE_DOUBLE); + cpl_image *img2; cpl_error_code code; /* Avoid division by zero for now */ @@ -1976,7 +2007,7 @@ code = cpl_image_power(img1, -3.0); cpl_test_eq_error(code, CPL_ERROR_NONE); - code = cpl_image_power(img1, -1.0/3.0); + code = cpl_image_power(img1, -1.0 / 3.0); cpl_test_eq_error(code, CPL_ERROR_NONE); cpl_test_image_abs(img1, img2, 100.0 * DBL_EPSILON); @@ -1995,31 +2026,33 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_image_bitwise_test(cpl_size nx, cpl_size ny) +static void +cpl_image_bitwise_test(cpl_size nx, cpl_size ny) { - cpl_error_code (*fimage[3])(cpl_image *, const cpl_image *, - const cpl_image *) - = {cpl_image_and, cpl_image_or, cpl_image_xor}; + const cpl_image *) = { cpl_image_and, + cpl_image_or, + cpl_image_xor }; cpl_error_code (*fscalar[3])(cpl_image *, const cpl_image *, - cpl_bitmask) - = {cpl_image_and_scalar, cpl_image_or_scalar, cpl_image_xor_scalar}; - const size_t nfunc = sizeof(fimage)/sizeof(*fimage); - - cpl_image * imf = cpl_image_new(nx, ny, CPL_TYPE_FLOAT); - cpl_image * im01 = cpl_image_new(nx, ny + 1, CPL_TYPE_INT); - cpl_image * im10 = cpl_image_new(nx + 1, ny, CPL_TYPE_INT); - cpl_image * im0 = cpl_image_new(nx, ny, CPL_TYPE_INT); - cpl_image * im1 = cpl_image_new(nx, ny, CPL_TYPE_INT); - cpl_image * im2 = cpl_image_new(nx, ny, CPL_TYPE_INT); - cpl_mask * mask0 = cpl_mask_new(nx, ny); + cpl_bitmask) = { cpl_image_and_scalar, + cpl_image_or_scalar, + cpl_image_xor_scalar }; + const size_t nfunc = sizeof(fimage) / sizeof(*fimage); + + cpl_image *imf = cpl_image_new(nx, ny, CPL_TYPE_FLOAT); + cpl_image *im01 = cpl_image_new(nx, ny + 1, CPL_TYPE_INT); + cpl_image *im10 = cpl_image_new(nx + 1, ny, CPL_TYPE_INT); + cpl_image *im0 = cpl_image_new(nx, ny, CPL_TYPE_INT); + cpl_image *im1 = cpl_image_new(nx, ny, CPL_TYPE_INT); + cpl_image *im2 = cpl_image_new(nx, ny, CPL_TYPE_INT); + cpl_mask *mask0 = cpl_mask_new(nx, ny); cpl_error_code code; - cpl_test_eq( sizeof(fimage), sizeof(fscalar)); + cpl_test_eq(sizeof(fimage), sizeof(fscalar)); /* Test the handling of the 3 possible error types for all 7 functions */ for (size_t i = 0; i < nfunc; i++) { - const cpl_image * im3 = im1; + const cpl_image *im3 = im1; for (size_t i2 = 0; i2 < 2; i2++, im3 = NULL) { code = fimage[i](NULL, im3, im2); cpl_test_eq_error(code, CPL_ERROR_NULL_INPUT); @@ -2076,8 +2109,7 @@ code = cpl_image_not(im1, im10); cpl_test_eq_error(code, CPL_ERROR_INCOMPATIBLE_INPUT); - code = cpl_image_fill_noise_uniform(im1, - -cpl_tools_ipow(2.0, 31), + code = cpl_image_fill_noise_uniform(im1, -cpl_tools_ipow(2.0, 31), cpl_tools_ipow(2.0, 31) - 1.0); cpl_test_eq_error(code, CPL_ERROR_NONE); code = cpl_image_not(im2, im1); @@ -2184,14 +2216,15 @@ various cases of division by zeros and bad pixel masks. */ /*----------------------------------------------------------------------------*/ -static void cpl_image_divide_create_test(void) +static void +cpl_image_divide_create_test(void) { - cpl_image * a = cpl_image_new(3, 3, CPL_TYPE_FLOAT); - cpl_image * b = cpl_image_new(3, 3, CPL_TYPE_FLOAT); - cpl_image * c = NULL; - const cpl_mask * m = NULL; - float * data_a = cpl_image_get_data_float(a); - float * data_b = cpl_image_get_data_float(b); + cpl_image *a = cpl_image_new(3, 3, CPL_TYPE_FLOAT); + cpl_image *b = cpl_image_new(3, 3, CPL_TYPE_FLOAT); + cpl_image *c = NULL; + const cpl_mask *m = NULL; + float *data_a = cpl_image_get_data_float(a); + float *data_b = cpl_image_get_data_float(b); int i; /* Make sure the reference images are initialised. Otherwise stop here. */ @@ -2199,16 +2232,19 @@ cpl_test_nonnull(b); cpl_test_nonnull(data_a); cpl_test_nonnull(data_b); - if (a == NULL || b == NULL || data_a == NULL || data_b == NULL) return; + if (a == NULL || b == NULL || data_a == NULL || data_b == NULL) + return; /* [ 6 -7 8] * Set image A to [-3 4 -5] * [ 0 -1 2] */ - for (i = 0; i < 9; ++i) data_a[i] = (float)i * (i % 2 == 0 ? 1.0 : -1.0); + for (i = 0; i < 9; ++i) + data_a[i] = (float)i * (i % 2 == 0 ? 1.0 : -1.0); /* Image B should be all zeros from the function call cpl_image_new. */ - for (i = 0; i < 9; ++i) cpl_test(data_b[i] == 0.0); + for (i = 0; i < 9; ++i) + cpl_test(data_b[i] == 0.0); /* Check that dividing by image B with all zeros produces a CPL divide by * zero error code. */ @@ -2225,21 +2261,27 @@ * C_bpm = [X . .] * [X . X] */ - data_b[6] = 0.6; data_b[7] = 0.0; data_b[8] = 0.0; - data_b[3] = 0.0; data_b[4] = 0.4; data_b[5] = 0.5; - data_b[0] = 0.0; data_b[1] = 0.1; data_b[2] = 0.0; + data_b[6] = 0.6; + data_b[7] = 0.0; + data_b[8] = 0.0; + data_b[3] = 0.0; + data_b[4] = 0.4; + data_b[5] = 0.5; + data_b[0] = 0.0; + data_b[1] = 0.1; + data_b[2] = 0.0; c = cpl_image_divide_create(a, b); cpl_test_nonnull(c); cpl_test_error(CPL_ERROR_NONE); - cpl_test_abs(cpl_image_get_data_float_const(c)[0], 0.0, FLT_EPSILON); + cpl_test_abs(cpl_image_get_data_float_const(c)[0], 0.0, FLT_EPSILON); cpl_test_abs(cpl_image_get_data_float_const(c)[1], -10.0, FLT_EPSILON); - cpl_test_abs(cpl_image_get_data_float_const(c)[2], 0.0, FLT_EPSILON); - cpl_test_abs(cpl_image_get_data_float_const(c)[3], 0.0, FLT_EPSILON); - cpl_test_abs(cpl_image_get_data_float_const(c)[4], 10.0, FLT_EPSILON); + cpl_test_abs(cpl_image_get_data_float_const(c)[2], 0.0, FLT_EPSILON); + cpl_test_abs(cpl_image_get_data_float_const(c)[3], 0.0, FLT_EPSILON); + cpl_test_abs(cpl_image_get_data_float_const(c)[4], 10.0, FLT_EPSILON); cpl_test_abs(cpl_image_get_data_float_const(c)[5], -10.0, FLT_EPSILON); - cpl_test_abs(cpl_image_get_data_float_const(c)[6], 10.0, FLT_EPSILON); - cpl_test_abs(cpl_image_get_data_float_const(c)[7], 0.0, FLT_EPSILON); - cpl_test_abs(cpl_image_get_data_float_const(c)[8], 0.0, FLT_EPSILON); + cpl_test_abs(cpl_image_get_data_float_const(c)[6], 10.0, FLT_EPSILON); + cpl_test_abs(cpl_image_get_data_float_const(c)[7], 0.0, FLT_EPSILON); + cpl_test_abs(cpl_image_get_data_float_const(c)[8], 0.0, FLT_EPSILON); /* Check the bad pixels. */ m = cpl_image_get_bpm_const(c); cpl_test_nonnull(m); @@ -2263,21 +2305,27 @@ * C_bpm = [. . .] * [. . .] */ - data_b[6] = 0.6; data_b[7] = 0.7; data_b[8] = 0.8; - data_b[3] = 0.3; data_b[4] = 0.4; data_b[5] = 0.5; - data_b[0] = 0.9; data_b[1] = 0.1; data_b[2] = 0.2; + data_b[6] = 0.6; + data_b[7] = 0.7; + data_b[8] = 0.8; + data_b[3] = 0.3; + data_b[4] = 0.4; + data_b[5] = 0.5; + data_b[0] = 0.9; + data_b[1] = 0.1; + data_b[2] = 0.2; c = cpl_image_divide_create(a, b); cpl_test_nonnull(c); cpl_test_error(CPL_ERROR_NONE); - cpl_test_abs(cpl_image_get_data_float_const(c)[0], 0.0, FLT_EPSILON); + cpl_test_abs(cpl_image_get_data_float_const(c)[0], 0.0, FLT_EPSILON); cpl_test_abs(cpl_image_get_data_float_const(c)[1], -10.0, FLT_EPSILON); - cpl_test_abs(cpl_image_get_data_float_const(c)[2], 10.0, FLT_EPSILON); + cpl_test_abs(cpl_image_get_data_float_const(c)[2], 10.0, FLT_EPSILON); cpl_test_abs(cpl_image_get_data_float_const(c)[3], -10.0, FLT_EPSILON); - cpl_test_abs(cpl_image_get_data_float_const(c)[4], 10.0, FLT_EPSILON); + cpl_test_abs(cpl_image_get_data_float_const(c)[4], 10.0, FLT_EPSILON); cpl_test_abs(cpl_image_get_data_float_const(c)[5], -10.0, FLT_EPSILON); - cpl_test_abs(cpl_image_get_data_float_const(c)[6], 10.0, FLT_EPSILON); + cpl_test_abs(cpl_image_get_data_float_const(c)[6], 10.0, FLT_EPSILON); cpl_test_abs(cpl_image_get_data_float_const(c)[7], -10.0, FLT_EPSILON); - cpl_test_abs(cpl_image_get_data_float_const(c)[8], 10.0, FLT_EPSILON); + cpl_test_abs(cpl_image_get_data_float_const(c)[8], 10.0, FLT_EPSILON); /* Check that there are no bad pixels. Note, we check this using a slightly * different method from above to test also cpl_image_is_rejected. */ m = cpl_image_get_bpm_const(c); diff -Nru cpl-7.1.4+ds/cplcore/tests/cpl_image_bpm-test.c cpl-7.2.2+ds/cplcore/tests/cpl_image_bpm-test.c --- cpl-7.1.4+ds/cplcore/tests/cpl_image_bpm-test.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/tests/cpl_image_bpm-test.c 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -33,7 +33,7 @@ -----------------------------------------------------------------------------*/ #ifndef IMAGESZ -#define IMAGESZ 512 +#define IMAGESZ 512 #endif /*----------------------------------------------------------------------------- @@ -45,19 +45,20 @@ /*----------------------------------------------------------------------------- Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { - cpl_image * img; - const cpl_mask * tmp_map; - cpl_mask * map; - const int nx = 10; - const int ny = 10; - const int nbad = 10; + cpl_image *img; + const cpl_mask *tmp_map; + cpl_mask *map; + const int nx = 10; + const int ny = 10; + const int nbad = 10; /* the bad pixels positions */ - const int bad_pos_x[] = {4, 5, 6, 4, 5, 6, 4, 5, 6, 8}; - const int bad_pos_y[] = {5, 5, 5, 6, 6, 6, 7, 7, 7, 9}; + const int bad_pos_x[] = { 4, 5, 6, 4, 5, 6, 4, 5, 6, 8 }; + const int bad_pos_y[] = { 5, 5, 5, 6, 6, 6, 7, 7, 7, 9 }; cpl_error_code error; - int i; + int i; cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); @@ -78,75 +79,74 @@ /* Set some bad pixels */ cpl_msg_info(cpl_func, "Set %d bad pixels in the test image", nbad); - for (i=0; i %u - filtering %u X %u %s " - "to %s with %u X %u", filter_mode[ifilt], - filter_ones[ifilt], nx, ny, + cpl_msg_info(cpl_func, + "%u <=> %u - filtering %u X %u %s " + "to %s with %u X %u", + filter_mode[ifilt], filter_ones[ifilt], nx, ny, cpl_type_get_name(pixel_type[itype1]), cpl_type_get_name(pixel_type[itype2]), m, n); - cpl_test_zero(cpl_image_fill_noise_uniform(testimg, - xmin, xmax)); + cpl_test_zero( + cpl_image_fill_noise_uniform(testimg, xmin, xmax)); - error = filter_mask[ifilt] - ? cpl_image_filter_mask(filtim1, testimg, window1, - filter_mode[ifilt], - CPL_BORDER_FILTER) - : cpl_image_filter(filtim1, testimg, xwindow1, - filter_mode[ifilt], - CPL_BORDER_FILTER); + error = + filter_mask[ifilt] + ? cpl_image_filter_mask(filtim1, testimg, window1, + filter_mode[ifilt], + CPL_BORDER_FILTER) + : cpl_image_filter(filtim1, testimg, xwindow1, + filter_mode[ifilt], + CPL_BORDER_FILTER); cpl_test_eq_error(error, exp_err); - error = filter_mask[ifilt] - ? cpl_image_filter_mask(filtim2, testimg, window2, - filter_mode[ifilt], - CPL_BORDER_FILTER) - : cpl_image_filter(filtim2, testimg, xwindow2, - filter_mode[ifilt], - CPL_BORDER_FILTER); + error = + filter_mask[ifilt] + ? cpl_image_filter_mask(filtim2, testimg, window2, + filter_mode[ifilt], + CPL_BORDER_FILTER) + : cpl_image_filter(filtim2, testimg, xwindow2, + filter_mode[ifilt], + CPL_BORDER_FILTER); cpl_test_eq_error(error, exp_err); if (exp_err == CPL_ERROR_NONE) { - if (filter_mode[ifilt] == CPL_FILTER_MEDIAN) { /* FIXME: Cannot trust border (with even numbers) */ for (j = 1; j <= ny; j++) { for (i = 1; i <= nx; i++) { - if (j < n || ny - n < j || - i < m || nx - m < i) { + if (j < n || ny - n < j || i < m || + nx - m < i) { cpl_image_reject(filtim1, i, j); cpl_image_reject(filtim2, i, j); } } } - } else { + } + else { /* filt1 and filt2 must be identical, because the mask of filt2 equals filt1, except that is has a halo of zeros */ - if (filter_mode[ifilt] == CPL_FILTER_AVERAGE_FAST - || filter_mode[ifilt] == CPL_FILTER_STDEV_FAST) { + if (filter_mode[ifilt] == CPL_FILTER_AVERAGE_FAST || + filter_mode[ifilt] == CPL_FILTER_STDEV_FAST) { /* In this case filtim1 is actually done with CPL_FILTER_AVERAGE */ - tol = 10.0 * (xmax - xmin) - * ((pixel_type[itype1] == CPL_TYPE_FLOAT || + tol = 10.0 * (xmax - xmin) * + ((pixel_type[itype1] == CPL_TYPE_FLOAT || pixel_type[itype2] == CPL_TYPE_FLOAT) - ? FLT_EPSILON : DBL_EPSILON); - } else if (filter_mode[ifilt] == CPL_FILTER_STDEV - && pixel_type[itype2] == CPL_TYPE_DOUBLE - && m*n > 1 && nx > m && ny > n) { + ? FLT_EPSILON + : DBL_EPSILON); + } + else if (filter_mode[ifilt] == CPL_FILTER_STDEV && + pixel_type[itype2] == CPL_TYPE_DOUBLE && + m * n > 1 && nx > m && ny > n) { /* Verify a non-border value */ int is_bad; - const double stdev - = cpl_image_get_stdev_window(testimg, - nx-m+1, - ny-n+1, nx, - ny); - - const double filtered = cpl_image_get(filtim1, - nx-hm, - ny-hn, - &is_bad); + const double stdev = + cpl_image_get_stdev_window(testimg, + nx - m + 1, + ny - n + 1, nx, + ny); + + const double filtered = + cpl_image_get(filtim1, nx - hm, ny - hn, + &is_bad); if (!is_bad) { cpl_test_rel(stdev, filtered, 4.0 * DBL_EPSILON); @@ -293,49 +291,51 @@ /* The additions are reordered (sorted), i.e. different round-off */ const cpl_boolean isfloat = - pixel_type[itype1] == CPL_TYPE_FLOAT || + pixel_type[itype1] == CPL_TYPE_FLOAT || pixel_type[itype2] == CPL_TYPE_FLOAT; - tol = (xmax - xmin) - * (isfloat ? FLT_EPSILON : DBL_EPSILON); + tol = (xmax - xmin) * + (isfloat ? FLT_EPSILON : DBL_EPSILON); - if (filter_mode[ifilt] == CPL_FILTER_LINEAR_SCALE - && !isfloat) tol *= (double)(n*m); + if (filter_mode[ifilt] == CPL_FILTER_LINEAR_SCALE && + !isfloat) + tol *= (double)(n * m); else if (filter_mode[ifilt] == CPL_FILTER_LINEAR && filter_ones[ifilt] == CPL_FILTER_MORPHO && !isfloat) - tol *= 1.5; + tol *= 1.5; if (filter_mode[ifilt] == CPL_FILTER_AVERAGE_FAST) - tol *= (1.0 + (double)n)*(1.0 + (double)m); + tol *= (1.0 + (double)n) * (1.0 + (double)m); if (filter_mode[ifilt] == CPL_FILTER_STDEV_FAST || filter_ones[ifilt] == CPL_FILTER_STDEV_FAST) { if (pixel_type[itype1] == CPL_TYPE_INT && pixel_type[itype2] == CPL_TYPE_INT) tol = -1.0; /* FIXME: Not supported */ - else tol *= 100.0 * (double)(n * m); + else + tol *= 100.0 * (double)(n * m); } - error = filter_mask1[ifilt] ? - cpl_image_filter_mask(filtim2, testimg, window1, - filter_ones[ifilt], - CPL_BORDER_FILTER) : - cpl_image_filter(filtim2, testimg, - xwindow1, - filter_ones[ifilt], - CPL_BORDER_FILTER); + error = + filter_mask1[ifilt] + ? cpl_image_filter_mask(filtim2, testimg, + window1, + filter_ones[ifilt], + CPL_BORDER_FILTER) + : cpl_image_filter(filtim2, testimg, + xwindow1, + filter_ones[ifilt], + CPL_BORDER_FILTER); cpl_test_eq_error(error, exp_err); if (tol >= 0.0) cpl_test_image_abs(filtim1, filtim2, tol); } if (itype1 == itype2) { - /* If the input and output pixel types are identical a mask with 1 element corresponds to a shift */ /* Try all possible 1-element masks */ for (j = 1; j <= n; j++) { for (i = 1; i <= m; i++) { - /* Empty mask */ cpl_test_zero(cpl_mask_xor(shift, shift)); cpl_test_zero(cpl_matrix_fill(xshift, 0.0)); @@ -343,8 +343,8 @@ /* Set one element */ cpl_test_zero(cpl_mask_set(shift, i, j, CPL_BINARY_1)); - cpl_test_zero(cpl_matrix_set(xshift, n-j, - i-1, 1.0)); + cpl_test_zero(cpl_matrix_set(xshift, n - j, + i - 1, 1.0)); cpl_test_eq(cpl_mask_count(shift), 1); @@ -352,49 +352,49 @@ /* This filter corresponds to a shift of ((hm+1) - i, (hn+1) - j) */ error = filter_mask[ifilt] - ? cpl_image_filter_mask(filtim1, - testimg, - shift, - filter_mode[ifilt], - CPL_BORDER_FILTER) - - : cpl_image_filter(filtim1, - testimg, - xshift, - filter_mode[ifilt], - CPL_BORDER_FILTER); + ? cpl_image_filter_mask( + filtim1, testimg, shift, + filter_mode[ifilt], + CPL_BORDER_FILTER) + + : cpl_image_filter( + filtim1, testimg, xshift, + filter_mode[ifilt], + CPL_BORDER_FILTER); cpl_test_error(error); - if (filter_mode[ifilt] == CPL_FILTER_STDEV - || filter_mode[ifilt] == - CPL_FILTER_STDEV_FAST) { + if (filter_mode[ifilt] == + CPL_FILTER_STDEV || + filter_mode[ifilt] == + CPL_FILTER_STDEV_FAST) { cpl_test_eq(error, CPL_ERROR_DATA_NOT_FOUND); - } else { + } + else { cpl_test_zero(error); cpl_test_zero(cpl_image_copy(filtim2, - testimg, - 1, 1)); - cpl_test_zero(cpl_image_shift(filtim2, - (hm+1)-i, - (hn+1)-j)); + testimg, 1, + 1)); + cpl_test_zero( + cpl_image_shift(filtim2, + (hm + 1) - i, + (hn + 1) - j)); cpl_test_image_abs(filtim1, filtim2, 0.0); } - if (filter_mode[ifilt] == CPL_FILTER_MEDIAN) { - error = - cpl_image_filter_mask(filtim1, - testimg, - shift, - filter_mode[ifilt], - CPL_BORDER_COPY); + if (filter_mode[ifilt] == + CPL_FILTER_MEDIAN) { + error = cpl_image_filter_mask( + filtim1, testimg, shift, + filter_mode[ifilt], + CPL_BORDER_COPY); cpl_test_eq_error(error, CPL_ERROR_NONE); - if (i == hm+1 && j == hn+1) { + if (i == hm + 1 && j == hn + 1) { /* FIXME: Verify result also for non-zero shifts */ @@ -402,15 +402,12 @@ 0.0); } - error = - cpl_image_filter_mask(filtim1, - testimg, - shift, - filter_mode[ifilt], - CPL_BORDER_NOP); + error = cpl_image_filter_mask( + filtim1, testimg, shift, + filter_mode[ifilt], CPL_BORDER_NOP); cpl_test_eq_error(error, CPL_ERROR_NONE); - if (i == hm+1 && j == hn+1) { + if (i == hm + 1 && j == hn + 1) { /* FIXME: Verify result also for non-zero shifts */ @@ -426,7 +423,6 @@ cpl_image_delete(testimg); cpl_image_delete(filtim1); cpl_image_delete(filtim2); - } } } @@ -452,17 +448,17 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_image_filter_test_5198(void) +static void +cpl_image_filter_test_5198(void) { - - cpl_image * img = cpl_image_new(100, 163, CPL_TYPE_DOUBLE); - double * d = cpl_image_get_data_double(img); - cpl_mask * m = cpl_mask_new(3,3); + cpl_image *img = cpl_image_new(100, 163, CPL_TYPE_DOUBLE); + double *d = cpl_image_get_data_double(img); + cpl_mask *m = cpl_mask_new(3, 3); cpl_image *res; cpl_image *resbpm; cpl_size i, j; - for (i = 0; i < 100*163; i++) { + for (i = 0; i < 100 * 163; i++) { d[i] = i; } @@ -472,16 +468,14 @@ cpl_mask_not(m); - cpl_image_filter_mask(res, img, m, CPL_FILTER_MEDIAN, - CPL_BORDER_FILTER); + cpl_image_filter_mask(res, img, m, CPL_FILTER_MEDIAN, CPL_BORDER_FILTER); cpl_image_reject(img, 30, 30); - cpl_image_filter_mask(resbpm, img, m, CPL_FILTER_MEDIAN, - CPL_BORDER_FILTER); + cpl_image_filter_mask(resbpm, img, m, CPL_FILTER_MEDIAN, CPL_BORDER_FILTER); for (j = 27; j < 33; j++) { for (i = 27; i < 33; i++) { - cpl_image_set(res, i, j, 0.0); + cpl_image_set(res, i, j, 0.0); cpl_image_set(resbpm, i, j, 0.0); } } @@ -502,18 +496,19 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_image_filter_test_5320(void) +static void +cpl_image_filter_test_5320(void) { cpl_error_code code; /* The dimensions of the matrix and image/mask objects are specified differently! */ - cpl_matrix * kernel = cpl_matrix_new(91, 1); - cpl_mask * kernel2 = cpl_mask_new(1, 91); + cpl_matrix *kernel = cpl_matrix_new(91, 1); + cpl_mask *kernel2 = cpl_mask_new(1, 91); - cpl_image * unfiltered = cpl_image_load("unfiltered_image.fits", - CPL_TYPE_UNSPECIFIED, 0, 0); - cpl_image * filtered; - cpl_image * filtered2; + cpl_image *unfiltered = + cpl_image_load("unfiltered_image.fits", CPL_TYPE_UNSPECIFIED, 0, 0); + cpl_image *filtered; + cpl_image *filtered2; double tol = 0.0; @@ -530,12 +525,13 @@ code = cpl_image_fill_noise_uniform(unfiltered, 0.0, 1.0); cpl_test_eq_error(code, CPL_ERROR_NONE); tol = 8.0 * DBL_EPSILON; - } else { + } + else { cpl_test_error(CPL_ERROR_NONE); } - filtered = cpl_image_duplicate(unfiltered); - filtered2 = cpl_image_duplicate(unfiltered); + filtered = cpl_image_duplicate(unfiltered); + filtered2 = cpl_image_duplicate(unfiltered); code = cpl_matrix_fill(kernel, 1.0); cpl_test_eq_error(code, CPL_ERROR_NONE); @@ -543,8 +539,8 @@ code = cpl_mask_not(kernel2); cpl_test_eq_error(code, CPL_ERROR_NONE); - code = cpl_image_filter(filtered, unfiltered, kernel, - CPL_FILTER_LINEAR, CPL_BORDER_FILTER); + code = cpl_image_filter(filtered, unfiltered, kernel, CPL_FILTER_LINEAR, + CPL_BORDER_FILTER); cpl_test_eq_error(code, CPL_ERROR_NONE); @@ -564,16 +560,16 @@ cpl_test_image_abs(filtered, filtered2, 256.0 * DBL_EPSILON); - for (i = 0; i < 2; i +=1, ifilter = CPL_FILTER_AVERAGE) { - for (itheta = 0; itheta < 4; itheta +=2) { - + for (i = 0; i < 2; i += 1, ifilter = CPL_FILTER_AVERAGE) { + for (itheta = 0; itheta < 4; itheta += 2) { code = cpl_image_flip(unfiltered, itheta); cpl_test_eq_error(code, CPL_ERROR_NONE); - code = i == 0 ? cpl_image_filter(filtered2, unfiltered, kernel, - ifilter, CPL_BORDER_FILTER) - : cpl_image_filter_mask(filtered2, unfiltered, kernel2, - ifilter, CPL_BORDER_FILTER); + code = i == 0 + ? cpl_image_filter(filtered2, unfiltered, kernel, + ifilter, CPL_BORDER_FILTER) + : cpl_image_filter_mask(filtered2, unfiltered, kernel2, + ifilter, CPL_BORDER_FILTER); cpl_test_eq_error(code, CPL_ERROR_NONE); @@ -584,7 +580,6 @@ code = cpl_image_flip(unfiltered, itheta); cpl_test_eq_error(code, CPL_ERROR_NONE); - } } @@ -602,16 +597,17 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_image_filter_test_1d(void) +static void +cpl_image_filter_test_1d(void) { /* The length of the 1D-image from which to compute the running median */ const int nx = IMAGE_SIZE_X; - const int hsz = 15; /* Median half-size */ + const int hsz = 15; /* Median half-size */ const int winnx = 2 * hsz + 1; /* The running window size */ - cpl_image * raw = cpl_image_new(nx, 1, CPL_TYPE_FLOAT); - cpl_image * filtered = cpl_image_new(nx - 2 * hsz, 1, CPL_TYPE_FLOAT); - cpl_mask * kernel = cpl_mask_new(winnx, 1); + cpl_image *raw = cpl_image_new(nx, 1, CPL_TYPE_FLOAT); + cpl_image *filtered = cpl_image_new(nx - 2 * hsz, 1, CPL_TYPE_FLOAT); + cpl_mask *kernel = cpl_mask_new(winnx, 1); cpl_error_code code = cpl_image_fill_noise_uniform(raw, 0.0, 1.0); diff -Nru cpl-7.1.4+ds/cplcore/tests/cpl_image_gen-test.c cpl-7.2.2+ds/cplcore/tests/cpl_image_gen-test.c --- cpl-7.1.4+ds/cplcore/tests/cpl_image_gen-test.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/tests/cpl_image_gen-test.c 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -30,15 +30,16 @@ Define -----------------------------------------------------------------------------*/ -#define IMAGESZ 512 +#define IMAGESZ 512 /*----------------------------------------------------------------------------- Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { - cpl_image * img; - double cputime; + cpl_image *img; + double cputime; cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); @@ -46,44 +47,45 @@ /* Insert tests below */ /* Test cpl_image_fill_noise_uniform() for double image */ - img = cpl_image_new(IMAGESZ, IMAGESZ, CPL_TYPE_DOUBLE) ; + img = cpl_image_new(IMAGESZ, IMAGESZ, CPL_TYPE_DOUBLE); cputime = cpl_test_get_cputime(); cpl_test_zero(cpl_image_fill_noise_uniform(img, -100, 100)); - cpl_msg_info("","Time to generate DOUBLE noise %dx%d image: %g", + cpl_msg_info("", "Time to generate DOUBLE noise %dx%d image: %g", IMAGESZ, IMAGESZ, cputime - cpl_test_get_cputime()); cpl_image_delete(img); /* Test cpl_image_fill_noise_uniform() for float image */ - img = cpl_image_new(IMAGESZ, IMAGESZ, CPL_TYPE_FLOAT) ; + img = cpl_image_new(IMAGESZ, IMAGESZ, CPL_TYPE_FLOAT); cputime = cpl_test_get_cputime(); cpl_test_zero(cpl_image_fill_noise_uniform(img, -100, 100)); - cpl_msg_info("","Time to generate FLOAT noise %dx%d image: %g", + cpl_msg_info("", "Time to generate FLOAT noise %dx%d image: %g", IMAGESZ, IMAGESZ, cputime - cpl_test_get_cputime()); - cpl_image_delete(img) ; + cpl_image_delete(img); /* Test cpl_image_fill_gaussian() for double image */ - img = cpl_image_new(IMAGESZ, IMAGESZ, CPL_TYPE_DOUBLE) ; + img = cpl_image_new(IMAGESZ, IMAGESZ, CPL_TYPE_DOUBLE); cputime = cpl_test_get_cputime(); - cpl_test_zero(cpl_image_fill_gaussian(img, IMAGESZ/4, IMAGESZ/4, 1.0, 100, - 100)); - cpl_msg_info("","Time to generate DOUBLE gaussian %dx%d image: %g", - IMAGESZ/4, IMAGESZ/4, cputime - cpl_test_get_cputime()) ; - cpl_image_delete(img) ; + cpl_test_zero( + cpl_image_fill_gaussian(img, IMAGESZ / 4, IMAGESZ / 4, 1.0, 100, 100)); + cpl_msg_info("", "Time to generate DOUBLE gaussian %dx%d image: %g", + IMAGESZ / 4, IMAGESZ / 4, cputime - cpl_test_get_cputime()); + cpl_image_delete(img); /* Test cpl_image_fill_gaussian() for float image */ - img = cpl_image_new(IMAGESZ, IMAGESZ, CPL_TYPE_FLOAT) ; + img = cpl_image_new(IMAGESZ, IMAGESZ, CPL_TYPE_FLOAT); cputime = cpl_test_get_cputime(); - cpl_test_zero(cpl_image_fill_gaussian(img, 3*IMAGESZ/4, 3*IMAGESZ/4, - 1.0, 100, 100)); + cpl_test_zero(cpl_image_fill_gaussian(img, 3 * IMAGESZ / 4, 3 * IMAGESZ / 4, + 1.0, 100, 100)); - cpl_msg_info("","Time to generate FLOAT gaussian %dx%d image: %g", - 3*IMAGESZ/4, 3*IMAGESZ/4, cputime - cpl_test_get_cputime()) ; - cpl_image_delete(img) ; + cpl_msg_info("", "Time to generate FLOAT gaussian %dx%d image: %g", + 3 * IMAGESZ / 4, 3 * IMAGESZ / 4, + cputime - cpl_test_get_cputime()); + cpl_image_delete(img); /* Test cpl_image_fill_test_create() */ @@ -91,10 +93,10 @@ img = cpl_image_fill_test_create(IMAGESZ, IMAGESZ); cpl_test_nonnull(img); - cpl_msg_info("","Time to generate the standard %dx%d test image: %g", - IMAGESZ, IMAGESZ, cputime - cpl_test_get_cputime()) ; - cpl_image_delete(img) ; - + cpl_msg_info("", "Time to generate the standard %dx%d test image: %g", + IMAGESZ, IMAGESZ, cputime - cpl_test_get_cputime()); + cpl_image_delete(img); + return cpl_test_end(0); } diff -Nru cpl-7.1.4+ds/cplcore/tests/cpl_image_io-test.c cpl-7.2.2+ds/cplcore/tests/cpl_image_io-test.c --- cpl-7.1.4+ds/cplcore/tests/cpl_image_io-test.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/tests/cpl_image_io-test.c 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -30,7 +30,7 @@ -----------------------------------------------------------------------------*/ #ifndef IMAGESZ -#define IMAGESZ 32 +#define IMAGESZ 32 #endif #define FILENAME "cpl_image_test.fits" @@ -46,33 +46,33 @@ /*----------------------------------------------------------------------------- Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { - const cpl_type imtypes[] = {CPL_TYPE_DOUBLE, CPL_TYPE_FLOAT, - CPL_TYPE_INT, CPL_TYPE_DOUBLE_COMPLEX, - CPL_TYPE_FLOAT_COMPLEX}; - const cpl_type bpps[] = {CPL_TYPE_UCHAR, CPL_TYPE_SHORT, - CPL_TYPE_USHORT, CPL_TYPE_INT, - CPL_TYPE_FLOAT, CPL_TYPE_DOUBLE}; - const double minval[] = {0.0, -32767.0, 0.0, -2147483647.0, - -65535.0, -2147483647.0}; - const double maxval[] = {255.0, 32767.0, 65535.0, 2147483647.0, - 65535.0, 2147483647.0}; - const int nbad = 5; - const int bad_pos_x[] = {20, 20, 30, 31, 10}; - const int bad_pos_y[] = {30, 10, 20, 20, 22}; - const int nbpp = (int)(sizeof(bpps)/sizeof(bpps[0])); - FILE * stream; - const cpl_image * nullimg; - int ibpp; - int ityp; - int i; + const cpl_type imtypes[] = { CPL_TYPE_DOUBLE, CPL_TYPE_FLOAT, CPL_TYPE_INT, + CPL_TYPE_DOUBLE_COMPLEX, + CPL_TYPE_FLOAT_COMPLEX }; + const cpl_type bpps[] = { CPL_TYPE_UCHAR, CPL_TYPE_SHORT, CPL_TYPE_USHORT, + CPL_TYPE_INT, CPL_TYPE_FLOAT, CPL_TYPE_DOUBLE }; + const double minval[] = { 0.0, -32767.0, 0.0, + -2147483647.0, -65535.0, -2147483647.0 }; + const double maxval[] = { 255.0, 32767.0, 65535.0, + 2147483647.0, 65535.0, 2147483647.0 }; + const int nbad = 5; + const int bad_pos_x[] = { 20, 20, 30, 31, 10 }; + const int bad_pos_y[] = { 30, 10, 20, 20, 22 }; + const int nbpp = (int)(sizeof(bpps) / sizeof(bpps[0])); + FILE *stream; + const cpl_image *nullimg; + int ibpp; + int ityp; + int i; cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); - stream = cpl_msg_get_level() > CPL_MSG_INFO - ? fopen("/dev/null", "a") : stdout; + stream = + cpl_msg_get_level() > CPL_MSG_INFO ? fopen("/dev/null", "a") : stdout; /* Insert tests below */ @@ -81,25 +81,25 @@ (void)remove(FILENAME); /* May (also) exist with wrong perms */ /* Check the image type size */ - cpl_test_eq( cpl_type_get_sizeof(CPL_TYPE_DOUBLE), sizeof(double)); - cpl_test_eq( cpl_type_get_sizeof(CPL_TYPE_FLOAT), sizeof(float)); - cpl_test_eq( cpl_type_get_sizeof(CPL_TYPE_INT), sizeof(int)); - - cpl_test_eq( cpl_type_get_sizeof(CPL_TYPE_DOUBLE_COMPLEX), - sizeof(double complex)); - cpl_test_eq( cpl_type_get_sizeof(CPL_TYPE_FLOAT_COMPLEX), - sizeof(float complex)); + cpl_test_eq(cpl_type_get_sizeof(CPL_TYPE_DOUBLE), sizeof(double)); + cpl_test_eq(cpl_type_get_sizeof(CPL_TYPE_FLOAT), sizeof(float)); + cpl_test_eq(cpl_type_get_sizeof(CPL_TYPE_INT), sizeof(int)); + + cpl_test_eq(cpl_type_get_sizeof(CPL_TYPE_DOUBLE_COMPLEX), + sizeof(double complex)); + cpl_test_eq(cpl_type_get_sizeof(CPL_TYPE_FLOAT_COMPLEX), + sizeof(float complex)); /* Check error handling in image creation */ - nullimg = cpl_image_new(0, IMAGESZ, CPL_TYPE_INT); + nullimg = cpl_image_new(0, IMAGESZ, CPL_TYPE_INT); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); cpl_test_null(nullimg); - nullimg = cpl_image_new(IMAGESZ, 0, CPL_TYPE_INT); + nullimg = cpl_image_new(IMAGESZ, 0, CPL_TYPE_INT); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); cpl_test_null(nullimg); - nullimg = cpl_image_new(IMAGESZ, IMAGESZ, CPL_TYPE_CHAR); + nullimg = cpl_image_new(IMAGESZ, IMAGESZ, CPL_TYPE_CHAR); cpl_test_error(CPL_ERROR_INVALID_TYPE); cpl_test_null(nullimg); @@ -107,8 +107,8 @@ cpl_test_error(CPL_ERROR_NULL_INPUT); cpl_test_null(nullimg); - nullimg = cpl_image_load_window(NULL, CPL_TYPE_UNSPECIFIED, 0, 0, - 1, 1, 1, 1); + nullimg = + cpl_image_load_window(NULL, CPL_TYPE_UNSPECIFIED, 0, 0, 1, 1, 1, 1); cpl_test_error(CPL_ERROR_NULL_INPUT); cpl_test_null(nullimg); @@ -125,15 +125,15 @@ cpl_test_error(CPL_ERROR_NULL_INPUT); cpl_test_null(nullimg); - nullimg = cpl_image_wrap(1, 1, CPL_TYPE_POINTER, (void*)stream); + nullimg = cpl_image_wrap(1, 1, CPL_TYPE_POINTER, (void *)stream); cpl_test_error(CPL_ERROR_INVALID_TYPE); cpl_test_null(nullimg); - nullimg = cpl_image_wrap(0, 1, CPL_TYPE_INT, (void*)stream); + nullimg = cpl_image_wrap(0, 1, CPL_TYPE_INT, (void *)stream); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); cpl_test_null(nullimg); - nullimg = cpl_image_wrap(1, 0, CPL_TYPE_INT, (void*)stream); + nullimg = cpl_image_wrap(1, 0, CPL_TYPE_INT, (void *)stream); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); cpl_test_null(nullimg); @@ -142,11 +142,11 @@ cpl_test_error(CPL_ERROR_NULL_INPUT); cpl_test_null(nullimg); - nullimg = cpl_image_wrap_double(0, 1, (void*)stream); + nullimg = cpl_image_wrap_double(0, 1, (void *)stream); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); cpl_test_null(nullimg); - nullimg = cpl_image_wrap_double(1, 0, (void*)stream); + nullimg = cpl_image_wrap_double(1, 0, (void *)stream); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); cpl_test_null(nullimg); @@ -154,11 +154,11 @@ cpl_test_error(CPL_ERROR_NULL_INPUT); cpl_test_null(nullimg); - nullimg = cpl_image_wrap_float(0, 1, (void*)stream); + nullimg = cpl_image_wrap_float(0, 1, (void *)stream); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); cpl_test_null(nullimg); - nullimg = cpl_image_wrap_float(1, 0, (void*)stream); + nullimg = cpl_image_wrap_float(1, 0, (void *)stream); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); cpl_test_null(nullimg); @@ -166,11 +166,11 @@ cpl_test_error(CPL_ERROR_NULL_INPUT); cpl_test_null(nullimg); - nullimg = cpl_image_wrap_int(0, 1, (void*)stream); + nullimg = cpl_image_wrap_int(0, 1, (void *)stream); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); cpl_test_null(nullimg); - nullimg = cpl_image_wrap_int(1, 0, (void*)stream); + nullimg = cpl_image_wrap_int(1, 0, (void *)stream); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); cpl_test_null(nullimg); @@ -178,11 +178,11 @@ cpl_test_error(CPL_ERROR_NULL_INPUT); cpl_test_null(nullimg); - nullimg = cpl_image_wrap_double_complex(0, 1, (void*)stream); + nullimg = cpl_image_wrap_double_complex(0, 1, (void *)stream); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); cpl_test_null(nullimg); - nullimg = cpl_image_wrap_double_complex(1, 0, (void*)stream); + nullimg = cpl_image_wrap_double_complex(1, 0, (void *)stream); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); cpl_test_null(nullimg); @@ -190,11 +190,11 @@ cpl_test_error(CPL_ERROR_NULL_INPUT); cpl_test_null(nullimg); - nullimg = cpl_image_wrap_float_complex(0, 1, (void*)stream); + nullimg = cpl_image_wrap_float_complex(0, 1, (void *)stream); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); cpl_test_null(nullimg); - nullimg = cpl_image_wrap_float_complex(1, 0, (void*)stream); + nullimg = cpl_image_wrap_float_complex(1, 0, (void *)stream); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); cpl_test_null(nullimg); @@ -204,22 +204,38 @@ /* Create a data-less HDU, and append another to it */ for (ibpp = 0; ibpp < nbpp; ibpp++) { + cpl_propertylist *plist = cpl_propertylist_new(); + const char *sval = cpl_type_get_name(bpps[ibpp]); + cpl_error_code code; + cpl_size szval; + + cpl_msg_info(cpl_func, + "Testing saving with save type '%s' and no " + "pixels", + sval); - cpl_msg_info(cpl_func, "Testing saving with save type '%s' and no " - "pixels", cpl_type_get_name(bpps[ibpp])); + cpl_test_nonnull(sval); - cpl_test_zero(cpl_image_save(NULL, FILENAME, bpps[ibpp], - NULL, CPL_IO_CREATE)); - cpl_test_fits(FILENAME); + code = cpl_propertylist_append_string(plist, "SAVETYPE", sval); + cpl_test_eq_error(code, CPL_ERROR_NONE); - cpl_test_zero( cpl_fits_count_extensions(FILENAME) ); + code = cpl_image_save(NULL, FILENAME, bpps[ibpp], plist, CPL_IO_CREATE); + cpl_test_eq_error(code, CPL_ERROR_NONE); + cpl_test_fits(FILENAME); + szval = cpl_fits_count_extensions(FILENAME); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_zero(szval); - cpl_test_zero(cpl_image_save(NULL, FILENAME, bpps[ibpp], - NULL, CPL_IO_EXTEND)); + code = cpl_image_save(NULL, FILENAME, bpps[ibpp], plist, CPL_IO_EXTEND); + cpl_test_eq_error(code, CPL_ERROR_NONE); cpl_test_fits(FILENAME); - cpl_test_eq( cpl_fits_count_extensions(FILENAME), 1 ); + szval = cpl_fits_count_extensions(FILENAME); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(szval, 1); + + cpl_propertylist_delete(plist); } /* Check error handling with no data unit */ @@ -228,213 +244,213 @@ cpl_test_null(nullimg); /* Iterate through all pixel types */ - for (ityp = 0; ityp < (int)(sizeof(imtypes)/sizeof(imtypes[0])); ityp++) { + for (ityp = 0; ityp < (int)(sizeof(imtypes) / sizeof(imtypes[0])); ityp++) { const cpl_type imtype = imtypes[ityp]; - const void * nulldata; - cpl_error_code error; + const void *nulldata; + cpl_error_code code; int ityp2; - cpl_image * img = cpl_image_new(IMAGESZ, IMAGESZ, imtype); + cpl_image *img = cpl_image_new(IMAGESZ, IMAGESZ, imtype); - cpl_image * copy; + cpl_image *copy; cpl_msg_info(cpl_func, "Testing image with type '%s'", cpl_type_get_name(imtype)); cpl_test_nonnull(img); - error = cpl_image_dump_structure(img, stream); - cpl_test_eq_error(error, CPL_ERROR_NONE); + code = cpl_image_dump_structure(img, stream); + cpl_test_eq_error(code, CPL_ERROR_NONE); - cpl_test_eq(cpl_image_get_type(img), imtype); + cpl_test_eq(cpl_image_get_type(img), imtype); cpl_test_eq(cpl_image_get_size_x(img), IMAGESZ); - cpl_test_eq(cpl_image_get_size_y(img), IMAGESZ); + cpl_test_eq(cpl_image_get_size_y(img), IMAGESZ); /* Test cpl_image_get_data() */ - cpl_test_nonnull( cpl_image_get_data(img) ); - cpl_test_nonnull( cpl_image_get_data_const(img) ); + cpl_test_nonnull(cpl_image_get_data(img)); + cpl_test_nonnull(cpl_image_get_data_const(img)); - if (imtype != CPL_TYPE_FLOAT_COMPLEX && + if (imtype != CPL_TYPE_FLOAT_COMPLEX && imtype != CPL_TYPE_DOUBLE_COMPLEX) { /* Largest number with 8 BPP */ - error = cpl_image_add_scalar(img, 255.0); - cpl_test_eq_error(error, CPL_ERROR_NONE); + code = cpl_image_add_scalar(img, 255.0); + cpl_test_eq_error(code, CPL_ERROR_NONE); } if (imtype == CPL_TYPE_DOUBLE) { - cpl_test_nonnull( cpl_image_get_data_double(img) ); - cpl_test_nonnull( cpl_image_get_data_double_const(img) ); + cpl_test_nonnull(cpl_image_get_data_double(img)); + cpl_test_nonnull(cpl_image_get_data_double_const(img)); nulldata = cpl_image_get_data_float(img); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); cpl_test_null(nulldata); nulldata = cpl_image_get_data_float_const(img); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); - cpl_test_null( nulldata ); + cpl_test_null(nulldata); nulldata = cpl_image_get_data_int(img); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); - cpl_test_null( nulldata ); + cpl_test_null(nulldata); nulldata = cpl_image_get_data_int_const(img); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); - cpl_test_null( nulldata ); + cpl_test_null(nulldata); nulldata = cpl_image_get_data_double_complex(img); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); - cpl_test_null( nulldata ); + cpl_test_null(nulldata); nulldata = cpl_image_get_data_double_complex_const(img); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); - cpl_test_null( nulldata ); + cpl_test_null(nulldata); nulldata = cpl_image_get_data_float_complex(img); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); - cpl_test_null( nulldata ); + cpl_test_null(nulldata); nulldata = cpl_image_get_data_float_complex_const(img); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); - cpl_test_null( nulldata ); + cpl_test_null(nulldata); copy = cpl_image_wrap_double(IMAGESZ, IMAGESZ, cpl_image_get_data_double(img)); - - } else if (imtype == CPL_TYPE_FLOAT) { - cpl_test_nonnull( cpl_image_get_data_float(img) ); - cpl_test_nonnull( cpl_image_get_data_float_const(img) ); + } + else if (imtype == CPL_TYPE_FLOAT) { + cpl_test_nonnull(cpl_image_get_data_float(img)); + cpl_test_nonnull(cpl_image_get_data_float_const(img)); nulldata = cpl_image_get_data_double(img); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); - cpl_test_null( nulldata ); + cpl_test_null(nulldata); nulldata = cpl_image_get_data_double_const(img); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); - cpl_test_null( nulldata ); + cpl_test_null(nulldata); nulldata = cpl_image_get_data_int(img); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); - cpl_test_null( nulldata ); + cpl_test_null(nulldata); nulldata = cpl_image_get_data_int_const(img); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); - cpl_test_null( nulldata ); + cpl_test_null(nulldata); nulldata = cpl_image_get_data_double_complex(img); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); - cpl_test_null( nulldata ); + cpl_test_null(nulldata); nulldata = cpl_image_get_data_double_complex_const(img); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); - cpl_test_null( nulldata ); + cpl_test_null(nulldata); nulldata = cpl_image_get_data_float_complex(img); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); - cpl_test_null( nulldata ); + cpl_test_null(nulldata); nulldata = cpl_image_get_data_float_complex_const(img); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); - cpl_test_null( nulldata ); + cpl_test_null(nulldata); copy = cpl_image_wrap_float(IMAGESZ, IMAGESZ, cpl_image_get_data_float(img)); - - } else if (imtype == CPL_TYPE_INT) { - cpl_test_nonnull( cpl_image_get_data_int(img) ); - cpl_test_nonnull( cpl_image_get_data_int_const(img) ); + } + else if (imtype == CPL_TYPE_INT) { + cpl_test_nonnull(cpl_image_get_data_int(img)); + cpl_test_nonnull(cpl_image_get_data_int_const(img)); nulldata = cpl_image_get_data_double(img); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); - cpl_test_null( nulldata ); + cpl_test_null(nulldata); nulldata = cpl_image_get_data_double_const(img); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); - cpl_test_null( nulldata ); + cpl_test_null(nulldata); nulldata = cpl_image_get_data_float(img); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); - cpl_test_null( nulldata ); + cpl_test_null(nulldata); nulldata = cpl_image_get_data_float_const(img); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); - cpl_test_null( nulldata ); + cpl_test_null(nulldata); nulldata = cpl_image_get_data_double_complex(img); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); - cpl_test_null( nulldata ); + cpl_test_null(nulldata); nulldata = cpl_image_get_data_double_complex_const(img); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); - cpl_test_null( nulldata ); + cpl_test_null(nulldata); nulldata = cpl_image_get_data_float_complex(img); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); - cpl_test_null( nulldata ); + cpl_test_null(nulldata); nulldata = cpl_image_get_data_float_complex_const(img); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); - cpl_test_null( nulldata ); + cpl_test_null(nulldata); copy = cpl_image_wrap_int(IMAGESZ, IMAGESZ, cpl_image_get_data_int(img)); - - } else if (imtype == CPL_TYPE_DOUBLE_COMPLEX) { - cpl_test_nonnull( cpl_image_get_data_double_complex(img) ); - cpl_test_nonnull( cpl_image_get_data_double_complex_const(img) ); + } + else if (imtype == CPL_TYPE_DOUBLE_COMPLEX) { + cpl_test_nonnull(cpl_image_get_data_double_complex(img)); + cpl_test_nonnull(cpl_image_get_data_double_complex_const(img)); nulldata = cpl_image_get_data_double(img); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); - cpl_test_null( nulldata ); + cpl_test_null(nulldata); nulldata = cpl_image_get_data_double_const(img); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); - cpl_test_null( nulldata ); + cpl_test_null(nulldata); nulldata = cpl_image_get_data_float(img); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); - cpl_test_null( nulldata ); + cpl_test_null(nulldata); nulldata = cpl_image_get_data_float_const(img); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); - cpl_test_null( nulldata ); + cpl_test_null(nulldata); nulldata = cpl_image_get_data_int(img); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); - cpl_test_null( nulldata ); + cpl_test_null(nulldata); nulldata = cpl_image_get_data_int_const(img); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); - cpl_test_null( nulldata ); + cpl_test_null(nulldata); nulldata = cpl_image_get_data_float_complex(img); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); - cpl_test_null( nulldata ); + cpl_test_null(nulldata); nulldata = cpl_image_get_data_float_complex_const(img); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); - cpl_test_null( nulldata ); + cpl_test_null(nulldata); copy = cpl_image_wrap_double_complex( - IMAGESZ, IMAGESZ, cpl_image_get_data_double_complex(img) ); - - } else { /* CPL_TYPE_FLOAT_COMPLEX */ - cpl_test_nonnull( cpl_image_get_data_float_complex(img) ); - cpl_test_nonnull( cpl_image_get_data_float_complex_const(img) ); + IMAGESZ, IMAGESZ, cpl_image_get_data_double_complex(img)); + } + else { /* CPL_TYPE_FLOAT_COMPLEX */ + cpl_test_nonnull(cpl_image_get_data_float_complex(img)); + cpl_test_nonnull(cpl_image_get_data_float_complex_const(img)); nulldata = cpl_image_get_data_double(img); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); - cpl_test_null( nulldata ); + cpl_test_null(nulldata); nulldata = cpl_image_get_data_double_const(img); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); - cpl_test_null( nulldata ); + cpl_test_null(nulldata); nulldata = cpl_image_get_data_float(img); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); - cpl_test_null( nulldata ); + cpl_test_null(nulldata); nulldata = cpl_image_get_data_float_const(img); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); - cpl_test_null( nulldata ); + cpl_test_null(nulldata); nulldata = cpl_image_get_data_int(img); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); - cpl_test_null( nulldata ); + cpl_test_null(nulldata); nulldata = cpl_image_get_data_int_const(img); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); - cpl_test_null( nulldata ); + cpl_test_null(nulldata); nulldata = cpl_image_get_data_double_complex(img); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); - cpl_test_null( nulldata ); + cpl_test_null(nulldata); nulldata = cpl_image_get_data_double_complex_const(img); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); - cpl_test_null( nulldata ); + cpl_test_null(nulldata); copy = cpl_image_wrap_float_complex( - IMAGESZ, IMAGESZ, cpl_image_get_data_float_complex(img) ); + IMAGESZ, IMAGESZ, cpl_image_get_data_float_complex(img)); } cpl_test_nonnull(copy); @@ -445,8 +461,8 @@ cpl_image_get_data_const(copy)); cpl_test_nonnull(cpl_image_unwrap(copy)); - copy = cpl_image_wrap(IMAGESZ, IMAGESZ, imtype, - cpl_image_get_data(img)); + copy = + cpl_image_wrap(IMAGESZ, IMAGESZ, imtype, cpl_image_get_data(img)); cpl_test_nonnull(copy); @@ -455,342 +471,347 @@ cpl_test_eq_ptr(cpl_image_get_data_const(img), cpl_image_get_data_const(copy)); - if ( imtype != CPL_TYPE_FLOAT_COMPLEX && - imtype != CPL_TYPE_DOUBLE_COMPLEX) - cpl_test_image_abs(img, copy, 0.0); - else { - cpl_image * real_img = cpl_image_extract_real(img); - cpl_image * imag_img = cpl_image_extract_imag(img); - cpl_image * real_copy = cpl_image_extract_real(copy); - cpl_image * imag_copy = cpl_image_extract_imag(copy); - - cpl_test_image_abs(real_img, real_copy, 0.0); - cpl_test_image_abs(imag_img, imag_copy, 0.0); + if (imtype != CPL_TYPE_FLOAT_COMPLEX && + imtype != CPL_TYPE_DOUBLE_COMPLEX) + cpl_test_image_abs(img, copy, 0.0); + else { + cpl_image *real_img = cpl_image_extract_real(img); + cpl_image *imag_img = cpl_image_extract_imag(img); + cpl_image *real_copy = cpl_image_extract_real(copy); + cpl_image *imag_copy = cpl_image_extract_imag(copy); - /* Test cpl_image_conjugate() and cpl_image_fill_re_im() */ + cpl_test_image_abs(real_img, real_copy, 0.0); + cpl_test_image_abs(imag_img, imag_copy, 0.0); - error = cpl_image_conjugate(img, img); - cpl_test_eq_error(error, CPL_ERROR_NONE); + /* Test cpl_image_conjugate() and cpl_image_fill_re_im() */ - error = cpl_image_multiply_scalar(imag_copy, -1.0); - cpl_test_eq_error(error, CPL_ERROR_NONE); + code = cpl_image_conjugate(img, img); + cpl_test_eq_error(code, CPL_ERROR_NONE); - error = cpl_image_fill_re_im(real_img, imag_img, img); - cpl_test_eq_error(error, CPL_ERROR_NONE); + code = cpl_image_multiply_scalar(imag_copy, -1.0); + cpl_test_eq_error(code, CPL_ERROR_NONE); - cpl_test_image_abs(real_img, real_copy, 0.0); - cpl_test_image_abs(imag_img, imag_copy, 0.0); + code = cpl_image_fill_re_im(real_img, imag_img, img); + cpl_test_eq_error(code, CPL_ERROR_NONE); - error = cpl_image_fill_re_im(NULL, imag_img, img); - cpl_test_eq_error(error, CPL_ERROR_NONE); + cpl_test_image_abs(real_img, real_copy, 0.0); + cpl_test_image_abs(imag_img, imag_copy, 0.0); - error = cpl_image_fill_re_im(real_img, NULL, img); - cpl_test_eq_error(error, CPL_ERROR_NONE); + code = cpl_image_fill_re_im(NULL, imag_img, img); + cpl_test_eq_error(code, CPL_ERROR_NONE); - cpl_test_image_abs(real_img, real_copy, 0.0); - cpl_test_image_abs(imag_img, imag_copy, 0.0); + code = cpl_image_fill_re_im(real_img, NULL, img); + cpl_test_eq_error(code, CPL_ERROR_NONE); - /* Test in-place */ - error = cpl_image_fill_re_im(copy, NULL, copy); - cpl_test_eq_error(error, CPL_ERROR_NONE); + cpl_test_image_abs(real_img, real_copy, 0.0); + cpl_test_image_abs(imag_img, imag_copy, 0.0); - cpl_test_image_abs(copy, real_img, 0.0); + /* Test in-place */ + code = cpl_image_fill_re_im(copy, NULL, copy); + cpl_test_eq_error(code, CPL_ERROR_NONE); - error = cpl_image_fill_re_im(NULL, copy, copy); - cpl_test_eq_error(error, CPL_ERROR_NONE); + cpl_test_image_abs(copy, real_img, 0.0); - cpl_image_delete(real_img); - cpl_image_delete(imag_img); - cpl_image_delete(real_copy); - cpl_image_delete(imag_copy); + code = cpl_image_fill_re_im(NULL, copy, copy); + cpl_test_eq_error(code, CPL_ERROR_NONE); - } + cpl_image_delete(real_img); + cpl_image_delete(imag_img); + cpl_image_delete(real_copy); + cpl_image_delete(imag_copy); + } cpl_test_nonnull(cpl_image_unwrap(copy)); - /* Saving is not supported for complex types */ - if ( imtype != CPL_TYPE_FLOAT_COMPLEX && - imtype != CPL_TYPE_DOUBLE_COMPLEX) { - for (ibpp = 0; ibpp < nbpp; ibpp++) { - int j; - - cpl_msg_info(cpl_func, "Testing saving with BITPIX=%d and pixels " - "ranging: %g -> %g", bpps[ibpp], minval[ibpp], - maxval[ibpp]); - - /* Use bpp-specific value */ - cpl_test_zero(cpl_image_fill_noise_uniform(img, minval[ibpp], - maxval[ibpp])); - - /* First, do some failure testing */ - - /* NULL filename - and no image */ - error = cpl_image_save(NULL, NULL, bpps[ibpp], NULL, - CPL_IO_CREATE); - cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT); - - /* Directory as filename - and no image */ - error = cpl_image_save(NULL, ".", bpps[ibpp], NULL, - CPL_IO_CREATE); - cpl_test_eq_error(error, CPL_ERROR_FILE_IO); - - /* Invalid mode - and no image */ - error = cpl_image_save(NULL, FILENAME, bpps[ibpp], NULL, -1); - cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); - - /* More failure tests, with an image */ - /* NULL filename */ - error = cpl_image_save(img, NULL, bpps[ibpp], NULL, - CPL_IO_CREATE); - cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT); - - /* Directory as filename */ - error = cpl_image_save(img, ".", bpps[ibpp], NULL, - CPL_IO_CREATE); - cpl_test_eq_error(error, CPL_ERROR_FILE_IO); - - /* Invalid BPP */ - error = cpl_image_save(img, FILENAME, 0, NULL, - CPL_IO_CREATE); - cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); - - /* Invalid mode */ - error = cpl_image_save(img, FILENAME, bpps[ibpp], NULL, -1); - cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); - - /* Illegal mode combination */ - error = cpl_image_save(img, FILENAME, bpps[ibpp], NULL, - CPL_IO_CREATE | CPL_IO_EXTEND); - cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); - - /* Illegal mode combination */ - error = cpl_image_save(img, FILENAME, bpps[ibpp], NULL, - CPL_IO_APPEND); - cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); - - /* Create/Append file */ - error = cpl_image_save(img, FILENAME, bpps[ibpp], NULL, - ibpp ? CPL_IO_EXTEND : CPL_IO_CREATE); - cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_fits(FILENAME); - - cpl_test_eq( cpl_fits_count_extensions(FILENAME), ibpp ); - - error = cpl_image_save(img, FILENAME, bpps[ibpp] == CPL_TYPE_USHORT - ? CPL_TYPE_SHORT : bpps[ibpp], - NULL, CPL_IO_APPEND); - cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); - - cpl_test_eq( cpl_fits_count_extensions(FILENAME), ibpp ); - - for (j = 0; j < 1; j++) { /* Only 1 iteration, no append */ - /* Tests for no-casting type */ - copy = cpl_image_load(FILENAME, CPL_TYPE_UNSPECIFIED, - j, ibpp); - cpl_test_error(CPL_ERROR_NONE); - cpl_test_nonnull(copy); + /* Saving is not supported for complex types */ + if (imtype != CPL_TYPE_FLOAT_COMPLEX && + imtype != CPL_TYPE_DOUBLE_COMPLEX) { + for (ibpp = 0; ibpp < nbpp; ibpp++) { + cpl_propertylist *plist = cpl_propertylist_new(); + const char *sval = cpl_type_get_name(bpps[ibpp]); + int j; + + cpl_test_nonnull(sval); + + code = cpl_propertylist_append_string(plist, "SAVETYPE", sval); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + cpl_msg_info(cpl_func, + "Testing saving with BITPIX=%d and pixels " + "ranging: %g -> %g", + bpps[ibpp], minval[ibpp], maxval[ibpp]); + + /* Use bpp-specific value */ + cpl_test_zero(cpl_image_fill_noise_uniform(img, minval[ibpp], + maxval[ibpp])); + + /* First, do some failure testing */ + + /* NULL filename - and no image */ + code = + cpl_image_save(NULL, NULL, bpps[ibpp], NULL, CPL_IO_CREATE); + cpl_test_eq_error(code, CPL_ERROR_NULL_INPUT); + + /* Directory as filename - and no image */ + code = + cpl_image_save(NULL, ".", bpps[ibpp], NULL, CPL_IO_CREATE); + cpl_test_eq_error(code, CPL_ERROR_FILE_IO); + + /* Invalid mode - and no image */ + code = cpl_image_save(NULL, FILENAME, bpps[ibpp], NULL, -1); + cpl_test_eq_error(code, CPL_ERROR_ILLEGAL_INPUT); + + /* More failure tests, with an image */ + /* NULL filename */ + code = + cpl_image_save(img, NULL, bpps[ibpp], NULL, CPL_IO_CREATE); + cpl_test_eq_error(code, CPL_ERROR_NULL_INPUT); + + /* Directory as filename */ + code = + cpl_image_save(img, ".", bpps[ibpp], NULL, CPL_IO_CREATE); + cpl_test_eq_error(code, CPL_ERROR_FILE_IO); + + /* Invalid BPP */ + code = cpl_image_save(img, FILENAME, 0, NULL, CPL_IO_CREATE); + cpl_test_eq_error(code, CPL_ERROR_ILLEGAL_INPUT); + + /* Invalid mode */ + code = cpl_image_save(img, FILENAME, bpps[ibpp], NULL, -1); + cpl_test_eq_error(code, CPL_ERROR_ILLEGAL_INPUT); + + /* Illegal mode combination */ + code = cpl_image_save(img, FILENAME, bpps[ibpp], NULL, + CPL_IO_CREATE | CPL_IO_EXTEND); + cpl_test_eq_error(code, CPL_ERROR_ILLEGAL_INPUT); + + /* Illegal mode combination */ + code = cpl_image_save(img, FILENAME, bpps[ibpp], NULL, + CPL_IO_APPEND); + cpl_test_eq_error(code, CPL_ERROR_ILLEGAL_INPUT); + + /* Create/Append file */ + code = cpl_image_save(img, FILENAME, bpps[ibpp], plist, + ibpp ? CPL_IO_EXTEND : CPL_IO_CREATE); + cpl_test_eq_error(code, CPL_ERROR_NONE); + cpl_test_fits(FILENAME); + + cpl_test_eq(cpl_fits_count_extensions(FILENAME), ibpp); + + code = cpl_image_save(img, FILENAME, + bpps[ibpp] == CPL_TYPE_USHORT + ? CPL_TYPE_SHORT + : bpps[ibpp], + NULL, CPL_IO_APPEND); + cpl_test_eq_error(code, CPL_ERROR_ILLEGAL_INPUT); + + cpl_test_eq(cpl_fits_count_extensions(FILENAME), ibpp); + + for (j = 0; j < 1; j++) { /* Only 1 iteration, no append */ + /* Tests for no-casting type */ + copy = + cpl_image_load(FILENAME, CPL_TYPE_UNSPECIFIED, j, ibpp); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(copy); + + if (bpps[ibpp] == CPL_TYPE_UCHAR || + bpps[ibpp] == CPL_TYPE_SHORT || + bpps[ibpp] == CPL_TYPE_USHORT || + bpps[ibpp] == CPL_TYPE_INT) { + cpl_test_eq(cpl_image_get_type(copy), CPL_TYPE_INT); + cpl_test_image_abs(copy, img, 0.0); + } + else if (bpps[ibpp] == CPL_TYPE_FLOAT) { + cpl_test_eq(cpl_image_get_type(copy), CPL_TYPE_FLOAT); + cpl_test_image_abs(copy, img, + maxval[ibpp] * FLT_EPSILON); + } + else { + cpl_test_eq(cpl_image_get_type(copy), CPL_TYPE_DOUBLE); + cpl_test_image_abs(copy, img, + maxval[ibpp] * DBL_EPSILON); + } - if (bpps[ibpp] == CPL_TYPE_UCHAR || - bpps[ibpp] == CPL_TYPE_SHORT || - bpps[ibpp] == CPL_TYPE_USHORT || - bpps[ibpp] == CPL_TYPE_INT ) { - cpl_test_eq(cpl_image_get_type(copy), CPL_TYPE_INT); - cpl_test_image_abs(copy, img, 0.0); - } else if (bpps[ibpp] == CPL_TYPE_FLOAT) { - cpl_test_eq(cpl_image_get_type(copy), CPL_TYPE_FLOAT); - cpl_test_image_abs(copy, img, maxval[ibpp] * FLT_EPSILON); - } else { - cpl_test_eq(cpl_image_get_type(copy), CPL_TYPE_DOUBLE); - cpl_test_image_abs(copy, img, maxval[ibpp] * DBL_EPSILON); + cpl_image_delete(copy); } - cpl_image_delete(copy); - } + /* Check error handling in windowed image loading */ + nullimg = + cpl_image_load_window(FILENAME, CPL_TYPE_UNSPECIFIED, 0, + ibpp, 0, IMAGESZ / 4, 3 * IMAGESZ / 4, + 3 * IMAGESZ / 4); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(nullimg); - /* Check error handling in windowed image loading */ - nullimg = cpl_image_load_window(FILENAME, CPL_TYPE_UNSPECIFIED, - 0, ibpp, - 0, IMAGESZ/4, - 3*IMAGESZ/4, 3*IMAGESZ/4); - cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); - cpl_test_null(nullimg); - - nullimg = cpl_image_load_window(FILENAME, CPL_TYPE_UNSPECIFIED, - 0, ibpp, - IMAGESZ/4, 0, - 3*IMAGESZ/4, 3*IMAGESZ/4); - cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); - cpl_test_null(nullimg); - - nullimg = cpl_image_load_window(FILENAME, CPL_TYPE_UNSPECIFIED, - 0, ibpp, - 3*IMAGESZ/4, IMAGESZ/4, - IMAGESZ/4, 3*IMAGESZ/4); - cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); - cpl_test_null(nullimg); - - nullimg = cpl_image_load_window(FILENAME, CPL_TYPE_UNSPECIFIED, - 0, ibpp, - IMAGESZ/4, 3*IMAGESZ/4, - 3*IMAGESZ/4, IMAGESZ/4); - cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); - cpl_test_null(nullimg); - - nullimg = cpl_image_load_window(FILENAME, CPL_TYPE_UNSPECIFIED, - 0, ibpp, - IMAGESZ/4, IMAGESZ/4, - IMAGESZ+1, 3*IMAGESZ/4); - cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); - cpl_test_null(nullimg); - - nullimg = cpl_image_load_window(FILENAME, CPL_TYPE_UNSPECIFIED, - 0, ibpp, - IMAGESZ/4, IMAGESZ/4, - 3*IMAGESZ/4, IMAGESZ+1); - cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); - cpl_test_null(nullimg); - - - copy = cpl_image_load_window(FILENAME, CPL_TYPE_UNSPECIFIED, - 0, ibpp, - IMAGESZ/4, IMAGESZ/4, - 3*IMAGESZ/4, 3*IMAGESZ/4); - cpl_test_nonnull(copy); - cpl_test_error(CPL_ERROR_NONE); + nullimg = + cpl_image_load_window(FILENAME, CPL_TYPE_UNSPECIFIED, 0, + ibpp, IMAGESZ / 4, 0, 3 * IMAGESZ / 4, + 3 * IMAGESZ / 4); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(nullimg); - if (bpps[ibpp] == CPL_TYPE_UCHAR || - bpps[ibpp] == CPL_TYPE_SHORT || - bpps[ibpp] == CPL_TYPE_USHORT || - bpps[ibpp] == CPL_TYPE_INT ) - cpl_test_eq(cpl_image_get_type(copy), CPL_TYPE_INT); - else if (bpps[ibpp] == CPL_TYPE_FLOAT) - cpl_test_eq(cpl_image_get_type(copy), CPL_TYPE_FLOAT); - else - cpl_test_eq(cpl_image_get_type(copy), CPL_TYPE_DOUBLE); + nullimg = + cpl_image_load_window(FILENAME, CPL_TYPE_UNSPECIFIED, 0, + ibpp, 3 * IMAGESZ / 4, IMAGESZ / 4, + IMAGESZ / 4, 3 * IMAGESZ / 4); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(nullimg); - cpl_image_delete(copy); + nullimg = + cpl_image_load_window(FILENAME, CPL_TYPE_UNSPECIFIED, 0, + ibpp, IMAGESZ / 4, 3 * IMAGESZ / 4, + 3 * IMAGESZ / 4, IMAGESZ / 4); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(nullimg); - /* Load it again with casting */ - for (ityp2 = 0; - ityp2 < (int)(sizeof(imtypes)/sizeof(imtypes[0]) - 2); - ityp2++) { /* The '- 2' is to avoid complex types */ - const cpl_type imtype2 = imtypes[ityp2]; + nullimg = + cpl_image_load_window(FILENAME, CPL_TYPE_UNSPECIFIED, 0, + ibpp, IMAGESZ / 4, IMAGESZ / 4, + IMAGESZ + 1, 3 * IMAGESZ / 4); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(nullimg); + + nullimg = + cpl_image_load_window(FILENAME, CPL_TYPE_UNSPECIFIED, 0, + ibpp, IMAGESZ / 4, IMAGESZ / 4, + 3 * IMAGESZ / 4, IMAGESZ + 1); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(nullimg); - copy = cpl_image_load(ibpp % 2 ? FILENAME : "./" FILENAME, - imtype2, 0, ibpp); + copy = cpl_image_load_window(FILENAME, CPL_TYPE_UNSPECIFIED, 0, + ibpp, IMAGESZ / 4, IMAGESZ / 4, + 3 * IMAGESZ / 4, 3 * IMAGESZ / 4); cpl_test_nonnull(copy); - cpl_test_eq(cpl_image_get_type(copy), imtype2); + cpl_test_error(CPL_ERROR_NONE); - if (imtype == imtype2) { - const double precision - = cpl_image_get_precision(imtype, bpps[ibpp], - maxval[ibpp]); - cpl_test_image_abs(img, copy, precision); - } + if (bpps[ibpp] == CPL_TYPE_UCHAR || + bpps[ibpp] == CPL_TYPE_SHORT || + bpps[ibpp] == CPL_TYPE_USHORT || bpps[ibpp] == CPL_TYPE_INT) + cpl_test_eq(cpl_image_get_type(copy), CPL_TYPE_INT); + else if (bpps[ibpp] == CPL_TYPE_FLOAT) + cpl_test_eq(cpl_image_get_type(copy), CPL_TYPE_FLOAT); + else + cpl_test_eq(cpl_image_get_type(copy), CPL_TYPE_DOUBLE); cpl_image_delete(copy); - copy = cpl_image_load_window(FILENAME, imtype2, 0, ibpp, - 1, 1, - IMAGESZ, IMAGESZ); + /* Load it again with casting */ + for (ityp2 = 0; + ityp2 < (int)(sizeof(imtypes) / sizeof(imtypes[0]) - 2); + ityp2++) { /* The '- 2' is to avoid complex types */ + const cpl_type imtype2 = imtypes[ityp2]; + + copy = cpl_image_load(ibpp % 2 ? FILENAME : "./" FILENAME, + imtype2, 0, ibpp); + + cpl_test_nonnull(copy); + cpl_test_eq(cpl_image_get_type(copy), imtype2); + + if (imtype == imtype2) { + const double precision = + cpl_image_get_precision(imtype, bpps[ibpp], + maxval[ibpp]); + cpl_test_image_abs(img, copy, precision); + } - cpl_test_nonnull(copy); - cpl_test_eq(cpl_image_get_type(copy), imtype2); + cpl_image_delete(copy); - if (imtype == imtype2) { - const double precision - = cpl_image_get_precision(imtype, bpps[ibpp], - maxval[ibpp]); - cpl_test_image_abs(img, copy, precision); - } + copy = cpl_image_load_window(FILENAME, imtype2, 0, ibpp, 1, + 1, IMAGESZ, IMAGESZ); - cpl_image_delete(copy); + cpl_test_nonnull(copy); + cpl_test_eq(cpl_image_get_type(copy), imtype2); - copy = cpl_image_load_window(FILENAME, imtype2, 0, ibpp, - IMAGESZ/4, IMAGESZ/4, - 3*IMAGESZ/4, 3*IMAGESZ/4); - cpl_test_nonnull(copy); - cpl_test_eq(cpl_image_get_type(copy), imtype2); + if (imtype == imtype2) { + const double precision = + cpl_image_get_precision(imtype, bpps[ibpp], + maxval[ibpp]); + cpl_test_image_abs(img, copy, precision); + } + cpl_image_delete(copy); - cpl_test_eq(cpl_image_get_size_x(copy), 1+IMAGESZ/2); - cpl_test_eq(cpl_image_get_size_y(copy), 1+IMAGESZ/2); + copy = + cpl_image_load_window(FILENAME, imtype2, 0, ibpp, + IMAGESZ / 4, IMAGESZ / 4, + 3 * IMAGESZ / 4, 3 * IMAGESZ / 4); + cpl_test_nonnull(copy); + cpl_test_eq(cpl_image_get_type(copy), imtype2); - cpl_image_delete(copy); + cpl_test_eq(cpl_image_get_size_x(copy), 1 + IMAGESZ / 2); + cpl_test_eq(cpl_image_get_size_y(copy), 1 + IMAGESZ / 2); - copy = cpl_image_load_window(FILENAME, imtype2, 0, ibpp, - IMAGESZ, IMAGESZ, - IMAGESZ, IMAGESZ); + cpl_image_delete(copy); - cpl_test_nonnull(copy); - cpl_test_eq(cpl_image_get_type(copy), imtype2); - cpl_test_eq(cpl_image_get_size_x(copy), 1); - cpl_test_eq(cpl_image_get_size_y(copy), 1); + copy = cpl_image_load_window(FILENAME, imtype2, 0, ibpp, + IMAGESZ, IMAGESZ, IMAGESZ, + IMAGESZ); - cpl_image_delete(copy); + cpl_test_nonnull(copy); + cpl_test_eq(cpl_image_get_type(copy), imtype2); + cpl_test_eq(cpl_image_get_size_x(copy), 1); + cpl_test_eq(cpl_image_get_size_y(copy), 1); - copy = cpl_image_load_window(FILENAME, imtype2, 0, ibpp, - 2, 2, 1, 1); + cpl_image_delete(copy); - cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); - cpl_test_null(copy); - } - } + copy = cpl_image_load_window(FILENAME, imtype2, 0, ibpp, 2, + 2, 1, 1); - /* Append one data-less extension (DFS06130) */ + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(copy); + } + cpl_propertylist_delete(plist); + } - cpl_test_zero(cpl_image_save(NULL, FILENAME, CPL_TYPE_UCHAR, - NULL, CPL_IO_EXTEND)); - cpl_test_fits(FILENAME); + /* Append one data-less extension (DFS06130) */ - /* Create overflow with 8 BPP */ - cpl_image_threshold(img, 256.0, 256.0, 256.0, 256.0); + cpl_test_zero(cpl_image_save(NULL, FILENAME, CPL_TYPE_UCHAR, NULL, + CPL_IO_EXTEND)); + cpl_test_fits(FILENAME); - cpl_image_save(img, FILENAME, CPL_TYPE_UCHAR, NULL, - CPL_IO_EXTEND); - cpl_test_error(CPL_ERROR_FILE_IO); + /* Create overflow with 8 BPP */ + cpl_image_threshold(img, 256.0, 256.0, 256.0, 256.0); + cpl_image_save(img, FILENAME, CPL_TYPE_UCHAR, NULL, CPL_IO_EXTEND); + cpl_test_error(CPL_ERROR_FILE_IO); - /* Create underflow with 16 BPP signed */ - cpl_image_subtract_scalar(img, (double)(1<<15) + 256.0 + 1.0); - cpl_image_save(img, FILENAME, CPL_TYPE_SHORT, NULL, - CPL_IO_EXTEND); - cpl_test_error(CPL_ERROR_FILE_IO); + /* Create underflow with 16 BPP signed */ + cpl_image_subtract_scalar(img, (double)(1 << 15) + 256.0 + 1.0); + cpl_image_save(img, FILENAME, CPL_TYPE_SHORT, NULL, CPL_IO_EXTEND); + cpl_test_error(CPL_ERROR_FILE_IO); - /* Create overflow with 16 BPP unsigned */ - cpl_image_add_scalar(img, (double)(3<<16)); - cpl_image_save(img, FILENAME, CPL_TYPE_USHORT, NULL, - CPL_IO_EXTEND); - cpl_test_error(CPL_ERROR_FILE_IO); + /* Create overflow with 16 BPP unsigned */ + cpl_image_add_scalar(img, (double)(3 << 16)); - if (imtype != CPL_TYPE_INT) { - /* Create overflow with 32 BPP signed */ - cpl_image_add_scalar(img, 4294967296.0); + cpl_image_save(img, FILENAME, CPL_TYPE_USHORT, NULL, CPL_IO_EXTEND); + cpl_test_error(CPL_ERROR_FILE_IO); - cpl_image_save(img, FILENAME, CPL_TYPE_INT, NULL, - CPL_IO_EXTEND); - cpl_test_error(CPL_ERROR_FILE_IO); + if (imtype != CPL_TYPE_INT) { + /* Create overflow with 32 BPP signed */ + cpl_image_add_scalar(img, 4294967296.0); - } + cpl_image_save(img, FILENAME, CPL_TYPE_INT, NULL, + CPL_IO_EXTEND); + cpl_test_error(CPL_ERROR_FILE_IO); + } - } /* End of test on saving for non-complex types */ + } /* End of test on saving for non-complex types */ - /* Saving tests specific for double images */ + /* Saving tests specific for double images */ if (imtype == CPL_TYPE_DOUBLE) { - /* Create overflow with 32 BPP float */ cpl_image_add_scalar(img, 1e40); - cpl_test_zero(cpl_image_save(img, FILENAME, CPL_TYPE_FLOAT, - NULL, CPL_IO_CREATE)); + cpl_test_zero(cpl_image_save(img, FILENAME, CPL_TYPE_FLOAT, NULL, + CPL_IO_CREATE)); cpl_test_error(CPL_ERROR_NONE); cpl_test_fits(FILENAME); @@ -802,181 +823,180 @@ cpl_test_leq(cpl_image_get_max(img), cpl_image_get_min(copy)); cpl_image_delete(copy); - } /* Create a bad pixel map for this image */ /* FIXME: Move to cpl_image_bpm-test.c */ - for (i=0; i < nbad-1; i++) + for (i = 0; i < nbad - 1; i++) cpl_test_zero(cpl_image_reject(img, bad_pos_x[i], bad_pos_y[i])); - error = cpl_image_dump_structure(img, stream); - cpl_test_eq_error(error, CPL_ERROR_NONE); + code = cpl_image_dump_structure(img, stream); + cpl_test_eq_error(code, CPL_ERROR_NONE); - error = cpl_image_dump_window(img, bad_pos_x[0]-1, bad_pos_y[0]-1, - bad_pos_x[0]+1, bad_pos_y[0]+1, stream); - cpl_test_eq_error(error, CPL_ERROR_NONE); + code = + cpl_image_dump_window(img, bad_pos_x[0] - 1, bad_pos_y[0] - 1, + bad_pos_x[0] + 1, bad_pos_y[0] + 1, stream); + cpl_test_eq_error(code, CPL_ERROR_NONE); - cpl_test_eq( nbad-1, cpl_image_count_rejected(img) ); + cpl_test_eq(nbad - 1, cpl_image_count_rejected(img)); - cpl_test_zero(cpl_image_reject(img, bad_pos_x[nbad-1], - bad_pos_y[nbad-1])); + cpl_test_zero( + cpl_image_reject(img, bad_pos_x[nbad - 1], bad_pos_y[nbad - 1])); - cpl_test_eq( nbad, cpl_image_count_rejected(img) ); + cpl_test_eq(nbad, cpl_image_count_rejected(img)); - for (i=0; i < nbad-1; i++) + for (i = 0; i < nbad - 1; i++) cpl_test_zero(cpl_image_reject(img, bad_pos_x[i], bad_pos_y[i])); - cpl_test_eq( nbad, cpl_image_count_rejected(img) ); + cpl_test_eq(nbad, cpl_image_count_rejected(img)); - cpl_test_zero(cpl_image_fill_rejected(img, 0.0) ); + cpl_test_zero(cpl_image_fill_rejected(img, 0.0)); - cpl_test_eq( cpl_image_count_rejected(img), nbad); + cpl_test_eq(cpl_image_count_rejected(img), nbad); /* Test cpl_image_duplicate() */ copy = cpl_image_duplicate(img); cpl_test_nonnull(copy); - cpl_test_eq( cpl_image_count_rejected(copy), nbad); + cpl_test_eq(cpl_image_count_rejected(copy), nbad); - if ( imtype != CPL_TYPE_FLOAT_COMPLEX && - imtype != CPL_TYPE_DOUBLE_COMPLEX) - cpl_test_image_abs(img, copy, 0.0); - else { - cpl_image * real_img = cpl_image_extract_real(img); - cpl_image * imag_img = cpl_image_extract_imag(img); - cpl_image * real_copy = cpl_image_extract_real(copy); - cpl_image * imag_copy = cpl_image_extract_imag(copy); + if (imtype != CPL_TYPE_FLOAT_COMPLEX && + imtype != CPL_TYPE_DOUBLE_COMPLEX) + cpl_test_image_abs(img, copy, 0.0); + else { + cpl_image *real_img = cpl_image_extract_real(img); + cpl_image *imag_img = cpl_image_extract_imag(img); + cpl_image *real_copy = cpl_image_extract_real(copy); + cpl_image *imag_copy = cpl_image_extract_imag(copy); - cpl_test_image_abs(real_img, real_copy, 0.0); - cpl_test_image_abs(imag_img, imag_copy, 0.0); + cpl_test_image_abs(real_img, real_copy, 0.0); + cpl_test_image_abs(imag_img, imag_copy, 0.0); - /* Test cpl_image_conjugate() and cpl_image_fill_re_im() */ + /* Test cpl_image_conjugate() and cpl_image_fill_re_im() */ - error = cpl_image_conjugate(img, img); - cpl_test_eq_error(error, CPL_ERROR_NONE); + code = cpl_image_conjugate(img, img); + cpl_test_eq_error(code, CPL_ERROR_NONE); - error = cpl_image_multiply_scalar(imag_copy, -1.0); - cpl_test_eq_error(error, CPL_ERROR_NONE); + code = cpl_image_multiply_scalar(imag_copy, -1.0); + cpl_test_eq_error(code, CPL_ERROR_NONE); - error = cpl_image_fill_re_im(real_img, imag_img, img); - cpl_test_eq_error(error, CPL_ERROR_NONE); + code = cpl_image_fill_re_im(real_img, imag_img, img); + cpl_test_eq_error(code, CPL_ERROR_NONE); - cpl_test_image_abs(real_img, real_copy, 0.0); - cpl_test_image_abs(imag_img, imag_copy, 0.0); + cpl_test_image_abs(real_img, real_copy, 0.0); + cpl_test_image_abs(imag_img, imag_copy, 0.0); - /* Test in-place */ - error = cpl_image_fill_re_im(copy, NULL, copy); - cpl_test_eq_error(error, CPL_ERROR_NONE); + /* Test in-place */ + code = cpl_image_fill_re_im(copy, NULL, copy); + cpl_test_eq_error(code, CPL_ERROR_NONE); - cpl_test_image_abs(copy, real_img, 0.0); + cpl_test_image_abs(copy, real_img, 0.0); - error = cpl_image_fill_re_im(NULL, copy, copy); - cpl_test_eq_error(error, CPL_ERROR_NONE); + code = cpl_image_fill_re_im(NULL, copy, copy); + cpl_test_eq_error(code, CPL_ERROR_NONE); - cpl_image_delete(real_img); - cpl_image_delete(imag_img); - cpl_image_delete(real_copy); - cpl_image_delete(imag_copy); - } + cpl_image_delete(real_img); + cpl_image_delete(imag_img); + cpl_image_delete(real_copy); + cpl_image_delete(imag_copy); + } - cpl_image_delete(copy); + cpl_image_delete(copy); - for (ityp2 = 0; ityp2 < (int)(sizeof(imtypes)/sizeof(imtypes[0])); - ityp2++) { - const cpl_type imtype2 = imtypes[ityp2]; + for (ityp2 = 0; ityp2 < (int)(sizeof(imtypes) / sizeof(imtypes[0])); + ityp2++) { + const cpl_type imtype2 = imtypes[ityp2]; - copy = cpl_image_cast(img, imtype2); + copy = cpl_image_cast(img, imtype2); - if (((imtype2 == CPL_TYPE_DOUBLE || - imtype2 == CPL_TYPE_FLOAT || - imtype2 == CPL_TYPE_INT) - && - (imtype == CPL_TYPE_DOUBLE_COMPLEX || - imtype == CPL_TYPE_FLOAT_COMPLEX))) { - cpl_test_error(CPL_ERROR_TYPE_MISMATCH); - cpl_test_null(copy); - } else { - cpl_test_error(CPL_ERROR_NONE); - cpl_test_nonnull(copy); + if (((imtype2 == CPL_TYPE_DOUBLE || imtype2 == CPL_TYPE_FLOAT || + imtype2 == CPL_TYPE_INT) && + (imtype == CPL_TYPE_DOUBLE_COMPLEX || + imtype == CPL_TYPE_FLOAT_COMPLEX))) { + cpl_test_error(CPL_ERROR_TYPE_MISMATCH); + cpl_test_null(copy); + } + else { + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(copy); - if (imtype == imtype2) { - cpl_image * nullimage; + if (imtype == imtype2) { + cpl_image *nullimage; - if ( imtype != CPL_TYPE_FLOAT_COMPLEX && - imtype != CPL_TYPE_DOUBLE_COMPLEX) - cpl_test_image_abs(img, copy, 0.0); - else { - cpl_image * real_img = cpl_image_extract_real(img); - cpl_image * imag_img = cpl_image_extract_imag(img); - cpl_image * real_copy = cpl_image_extract_real(copy); - cpl_image * imag_copy = cpl_image_extract_imag(copy); + if (imtype != CPL_TYPE_FLOAT_COMPLEX && + imtype != CPL_TYPE_DOUBLE_COMPLEX) + cpl_test_image_abs(img, copy, 0.0); + else { + cpl_image *real_img = cpl_image_extract_real(img); + cpl_image *imag_img = cpl_image_extract_imag(img); + cpl_image *real_copy = cpl_image_extract_real(copy); + cpl_image *imag_copy = cpl_image_extract_imag(copy); - /* Test cpl_image_conjugate() and cpl_image_fill_re_im() */ + /* Test cpl_image_conjugate() and cpl_image_fill_re_im() */ - error = cpl_image_conjugate(img, img); - cpl_test_eq_error(error, CPL_ERROR_NONE); + code = cpl_image_conjugate(img, img); + cpl_test_eq_error(code, CPL_ERROR_NONE); - error = cpl_image_multiply_scalar(imag_copy, -1.0); - cpl_test_eq_error(error, CPL_ERROR_NONE); + code = cpl_image_multiply_scalar(imag_copy, -1.0); + cpl_test_eq_error(code, CPL_ERROR_NONE); - error = cpl_image_fill_re_im(real_img, imag_img, img); - cpl_test_eq_error(error, CPL_ERROR_NONE); + code = cpl_image_fill_re_im(real_img, imag_img, img); + cpl_test_eq_error(code, CPL_ERROR_NONE); - cpl_test_image_abs(real_img, real_copy, 0.0); - cpl_test_image_abs(imag_img, imag_copy, 0.0); + cpl_test_image_abs(real_img, real_copy, 0.0); + cpl_test_image_abs(imag_img, imag_copy, 0.0); - error = cpl_image_fill_re_im(NULL, imag_img, img); - cpl_test_eq_error(error, CPL_ERROR_NONE); + code = cpl_image_fill_re_im(NULL, imag_img, img); + cpl_test_eq_error(code, CPL_ERROR_NONE); - error = cpl_image_fill_re_im(real_img, NULL, img); - cpl_test_eq_error(error, CPL_ERROR_NONE); + code = cpl_image_fill_re_im(real_img, NULL, img); + cpl_test_eq_error(code, CPL_ERROR_NONE); - cpl_test_image_abs(real_img, real_copy, 0.0); - cpl_test_image_abs(imag_img, imag_copy, 0.0); + cpl_test_image_abs(real_img, real_copy, 0.0); + cpl_test_image_abs(imag_img, imag_copy, 0.0); - /* Test in-place */ - error = cpl_image_fill_re_im(copy, NULL, copy); - cpl_test_eq_error(error, CPL_ERROR_NONE); + /* Test in-place */ + code = cpl_image_fill_re_im(copy, NULL, copy); + cpl_test_eq_error(code, CPL_ERROR_NONE); - cpl_test_image_abs(copy, real_img, 0.0); + cpl_test_image_abs(copy, real_img, 0.0); - error = cpl_image_fill_re_im(NULL, copy, copy); - cpl_test_eq_error(error, CPL_ERROR_NONE); + code = cpl_image_fill_re_im(NULL, copy, copy); + cpl_test_eq_error(code, CPL_ERROR_NONE); - cpl_image_delete(real_img); - cpl_image_delete(imag_img); - cpl_image_delete(real_copy); - cpl_image_delete(imag_copy); + cpl_image_delete(real_img); + cpl_image_delete(imag_img); + cpl_image_delete(real_copy); + cpl_image_delete(imag_copy); + } + nullimage = cpl_image_cast(img, CPL_TYPE_UNSPECIFIED); + cpl_test_error(CPL_ERROR_INVALID_TYPE); + cpl_test_null(nullimage); } - nullimage = cpl_image_cast(img, CPL_TYPE_UNSPECIFIED); - cpl_test_error(CPL_ERROR_INVALID_TYPE); - cpl_test_null(nullimage); - } - cpl_test_eq( cpl_image_count_rejected(copy), nbad); + cpl_test_eq(cpl_image_count_rejected(copy), nbad); - cpl_image_delete(copy); + cpl_image_delete(copy); + } } - } - cpl_test_zero( cpl_image_accept_all(img)); + cpl_test_zero(cpl_image_accept_all(img)); - cpl_test_zero( cpl_image_count_rejected(img)); - - cpl_image_delete(img); + cpl_test_zero(cpl_image_count_rejected(img)); + cpl_image_delete(img); } /* Image compression tests */ cpl_image_save_compression_test(); - cpl_test_zero( remove(FILENAME) ); + cpl_test_zero(remove(FILENAME)); - if (stream != stdout) cpl_test_zero( fclose(stream) ); + if (stream != stdout) + cpl_test_zero(fclose(stream)); return cpl_test_end(0); } @@ -992,29 +1012,29 @@ @note Ugly, incorrect kludge for CPL_TYPE_FLOAT + CPL_TYPE_DOUBLE */ /*----------------------------------------------------------------------------*/ -static double cpl_image_get_precision(cpl_type pixeltype, cpl_type bpptype, - double rel2abs) +static double +cpl_image_get_precision(cpl_type pixeltype, cpl_type bpptype, double rel2abs) { - double precision = 0.0; if (pixeltype == CPL_TYPE_DOUBLE) { switch (bpptype) { - case CPL_TYPE_DOUBLE: - break; - case CPL_TYPE_FLOAT: - precision = FLT_EPSILON * rel2abs; - break; - default: - precision = 1.0; + case CPL_TYPE_DOUBLE: + break; + case CPL_TYPE_FLOAT: + precision = FLT_EPSILON * rel2abs; + break; + default: + precision = 1.0; } - } else if (pixeltype == CPL_TYPE_FLOAT) { + } + else if (pixeltype == CPL_TYPE_FLOAT) { switch (bpptype) { - case CPL_TYPE_DOUBLE: - case CPL_TYPE_FLOAT: - break; - default: - precision = 1.0; + case CPL_TYPE_DOUBLE: + case CPL_TYPE_FLOAT: + break; + default: + precision = 1.0; } } @@ -1029,35 +1049,34 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_image_fill_int_test(void) +static void +cpl_image_fill_int_test(void) { + cpl_image *self = cpl_image_new(2, 3, CPL_TYPE_FLOAT); + cpl_error_code code; - cpl_image * self = cpl_image_new(2, 3, CPL_TYPE_FLOAT); - cpl_error_code error; - - error = cpl_image_fill_int(NULL, 0); - cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT); + code = cpl_image_fill_int(NULL, 0); + cpl_test_eq_error(code, CPL_ERROR_NULL_INPUT); - error = cpl_image_fill_int(self, 0); - cpl_test_eq_error(error, CPL_ERROR_TYPE_MISMATCH); + code = cpl_image_fill_int(self, 0); + cpl_test_eq_error(code, CPL_ERROR_TYPE_MISMATCH); cpl_image_delete(self); self = cpl_image_new(2, 3, CPL_TYPE_INT); - error = cpl_image_fill_int(self, 0); - cpl_test_eq_error(error, CPL_ERROR_NONE); + code = cpl_image_fill_int(self, 0); + cpl_test_eq_error(code, CPL_ERROR_NONE); cpl_test_zero(cpl_image_get_min(self)); cpl_test_zero(cpl_image_get_max(self)); - error = cpl_image_fill_int(self, -2); - cpl_test_eq_error(error, CPL_ERROR_NONE); + code = cpl_image_fill_int(self, -2); + cpl_test_eq_error(code, CPL_ERROR_NONE); cpl_test_eq(cpl_image_get_min(self), -2); cpl_test_eq(cpl_image_get_max(self), -2); cpl_image_delete(self); - } /*----------------------------------------------------------------------------*/ @@ -1067,52 +1086,52 @@ @see cpl_image_save() */ /*----------------------------------------------------------------------------*/ -static void cpl_image_save_compression_test(void) +static void +cpl_image_save_compression_test(void) { /* Default CFITSIO quantization parameter for lossy floating point compression is q = 1, reducing precision to 4.08 % */ const double prec = 0.0408; const double maxval = 255.0; - const cpl_type imtypes[] = {CPL_TYPE_DOUBLE, CPL_TYPE_FLOAT, - CPL_TYPE_INT}; - const size_t ntyp = sizeof(imtypes)/sizeof(imtypes[0]); - size_t ityp; + const cpl_type imtypes[] = { CPL_TYPE_DOUBLE, CPL_TYPE_FLOAT, + CPL_TYPE_INT }; + const size_t ntyp = sizeof(imtypes) / sizeof(imtypes[0]); + size_t ityp; /* Saving with different image types, bitpix and compression types */ for (ityp = 0; ityp < ntyp; ityp++) { - const cpl_type bpps[] = {CPL_TYPE_UCHAR, CPL_TYPE_SHORT, - CPL_TYPE_USHORT, CPL_TYPE_INT, - CPL_TYPE_FLOAT, CPL_TYPE_DOUBLE, - CPL_TYPE_UNSPECIFIED}; - const size_t nbpp = sizeof(bpps)/sizeof(bpps[0]); + const cpl_type bpps[] = { CPL_TYPE_UCHAR, CPL_TYPE_SHORT, + CPL_TYPE_USHORT, CPL_TYPE_INT, + CPL_TYPE_FLOAT, CPL_TYPE_DOUBLE, + CPL_TYPE_UNSPECIFIED }; + const size_t nbpp = sizeof(bpps) / sizeof(bpps[0]); const cpl_type imtype = imtypes[ityp]; - cpl_image * img = cpl_image_new(IMAGESZ, IMAGESZ, imtype); - cpl_error_code error; + cpl_image *img = cpl_image_new(IMAGESZ, IMAGESZ, imtype); + cpl_error_code code; int isig; - error = cpl_image_add_scalar(img, maxval); - cpl_test_eq_error(error, CPL_ERROR_NONE); + code = cpl_image_add_scalar(img, maxval); + cpl_test_eq_error(code, CPL_ERROR_NONE); - for (isig=0; isig < 2; isig++) { - size_t ibpp; + for (isig = 0; isig < 2; isig++) { + size_t ibpp; for (ibpp = 0; ibpp < nbpp; ibpp++) { - const cpl_io_type comp_meths[] = {CPL_IO_COMPRESS_GZIP, - CPL_IO_COMPRESS_RICE, - CPL_IO_COMPRESS_HCOMPRESS, - CPL_IO_COMPRESS_PLIO}; - const size_t ncomp = sizeof(comp_meths)/sizeof(comp_meths[0]); - const int bitpix = - cpl_tools_get_bpp(bpps[ibpp] == CPL_TYPE_UNSPECIFIED - ? imtype : bpps[ibpp]); + const cpl_io_type comp_meths[] = { CPL_IO_COMPRESS_GZIP, + CPL_IO_COMPRESS_RICE, + CPL_IO_COMPRESS_HCOMPRESS, + CPL_IO_COMPRESS_PLIO }; + const size_t ncomp = sizeof(comp_meths) / sizeof(comp_meths[0]); + const int bitpix = cpl_tools_get_bpp( + bpps[ibpp] == CPL_TYPE_UNSPECIFIED ? imtype : bpps[ibpp]); size_t icomp; int ext = 0; - error = cpl_image_save(img, FILENAME, bpps[ibpp], NULL, - CPL_IO_CREATE); - cpl_test_eq_error(error, CPL_ERROR_NONE); + code = cpl_image_save(img, FILENAME, bpps[ibpp], NULL, + CPL_IO_CREATE); + cpl_test_eq_error(code, CPL_ERROR_NONE); /* Tests with compression */ for (icomp = 0; icomp < ncomp; icomp++) { @@ -1122,78 +1141,75 @@ cpl_test(comp_method); /* Saving with compression in non supported combinations */ - error = cpl_image_save(NULL, FILENAME, bpps[ibpp], NULL, - CPL_IO_EXTEND | comp_method); - cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); + code = cpl_image_save(NULL, FILENAME, bpps[ibpp], NULL, + CPL_IO_EXTEND | comp_method); + cpl_test_eq_error(code, CPL_ERROR_ILLEGAL_INPUT); /* Compression is only supported when adding new extensions, * not creating a new file and saving data in the main header */ - error = cpl_image_save(img, FILENAME, bpps[ibpp], NULL, - CPL_IO_CREATE | comp_method); - cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); + code = cpl_image_save(img, FILENAME, bpps[ibpp], NULL, + CPL_IO_CREATE | comp_method); + cpl_test_eq_error(code, CPL_ERROR_ILLEGAL_INPUT); for (size_t icomp2 = 0; icomp2 < icomp; icomp2++) { const cpl_io_type comp_method2 = comp_meths[icomp2]; - error = cpl_image_save(img, FILENAME, bpps[ibpp], NULL, - CPL_IO_EXTEND | comp_method - | comp_method2); - cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); + code = cpl_image_save(img, FILENAME, bpps[ibpp], NULL, + CPL_IO_EXTEND | comp_method | + comp_method2); + cpl_test_eq_error(code, CPL_ERROR_ILLEGAL_INPUT); for (size_t icomp3 = 0; icomp3 < icomp2; icomp3++) { const cpl_io_type comp_method3 = comp_meths[icomp3]; - error = cpl_image_save(img, FILENAME, bpps[ibpp], NULL, - CPL_IO_EXTEND | comp_method - | comp_method2 | comp_method3); - cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); + code = + cpl_image_save(img, FILENAME, bpps[ibpp], NULL, + CPL_IO_EXTEND | comp_method | + comp_method2 | comp_method3); + cpl_test_eq_error(code, CPL_ERROR_ILLEGAL_INPUT); } - } - error = cpl_image_save(img, FILENAME, bpps[ibpp], NULL, - CPL_IO_EXTEND | CPL_IO_COMPRESS_GZIP | - CPL_IO_COMPRESS_RICE | - CPL_IO_COMPRESS_HCOMPRESS | - CPL_IO_COMPRESS_PLIO); - cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); + code = cpl_image_save(img, FILENAME, bpps[ibpp], NULL, + CPL_IO_EXTEND | CPL_IO_COMPRESS_GZIP | + CPL_IO_COMPRESS_RICE | + CPL_IO_COMPRESS_HCOMPRESS | + CPL_IO_COMPRESS_PLIO); + cpl_test_eq_error(code, CPL_ERROR_ILLEGAL_INPUT); - error = cpl_image_save(img, FILENAME, bpps[ibpp], NULL, - CPL_IO_EXTEND | comp_method); + code = cpl_image_save(img, FILENAME, bpps[ibpp], NULL, + CPL_IO_EXTEND | comp_method); if ( #ifndef CPL_IO_COMPRESSION_LOSSY /* Currently, compression only allowed with integer data */ bitpix < 0 || #endif - /* FP-data compresses only to int, float or double */ + /* FP-data compresses only to int, float or double */ /* RICE-compression supports only int, float or double */ /* In fact, this applies to all compressions... */ abs(bitpix) < 32) { - cpl_test_eq_error(error, CPL_ERROR_UNSUPPORTED_MODE); - - } else { - - cpl_image * img_load; + cpl_test_eq_error(code, CPL_ERROR_UNSUPPORTED_MODE); + } + else { + cpl_image *img_load; - cpl_test_eq_error(error, CPL_ERROR_NONE); + cpl_test_eq_error(code, CPL_ERROR_NONE); cpl_test_fits(FILENAME); ext++; - cpl_test_eq( cpl_fits_count_extensions(FILENAME), ext); + cpl_test_eq(cpl_fits_count_extensions(FILENAME), ext); img_load = cpl_image_load(FILENAME, - CPL_TYPE_UNSPECIFIED, - 0, ext); + CPL_TYPE_UNSPECIFIED, 0, ext); cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(img_load); if (img_load != NULL) { - cpl_test_eq(cpl_image_get_size_x(img_load), IMAGESZ); cpl_test_eq(cpl_image_get_size_y(img_load), @@ -1201,7 +1217,8 @@ if (imtype == CPL_TYPE_INT) { cpl_test_image_abs(img, img_load, 0.0); - } else { + } + else { cpl_test_image_abs(img, img_load, prec * maxval); } @@ -1211,12 +1228,11 @@ } } - error = cpl_image_subtract_scalar(img, maxval); - cpl_test_eq_error(error, CPL_ERROR_NONE); - - error = cpl_image_fill_noise_uniform(img, 0.0, maxval); - cpl_test_eq_error(error, CPL_ERROR_NONE); + code = cpl_image_subtract_scalar(img, maxval); + cpl_test_eq_error(code, CPL_ERROR_NONE); + code = cpl_image_fill_noise_uniform(img, 0.0, maxval); + cpl_test_eq_error(code, CPL_ERROR_NONE); } cpl_image_delete(img); diff -Nru cpl-7.1.4+ds/cplcore/tests/cpl_image_iqe-test.c cpl-7.2.2+ds/cplcore/tests/cpl_image_iqe-test.c --- cpl-7.1.4+ds/cplcore/tests/cpl_image_iqe-test.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/tests/cpl_image_iqe-test.c 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -30,7 +30,7 @@ Defines -----------------------------------------------------------------------------*/ #ifndef IMAGESZ -#define IMAGESZ 512 +#define IMAGESZ 512 #endif #ifndef IMAGEMIN @@ -45,22 +45,23 @@ /*----------------------------------------------------------------------------- Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { - cpl_image * imf; - cpl_image * imd; - cpl_bivector * res; - FILE * stream; + cpl_image *imf; + cpl_image *imd; + cpl_bivector *res; + FILE *stream; cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); /* Insert tests below */ - stream = cpl_msg_get_level() > CPL_MSG_INFO - ? fopen("/dev/null", "a") : stdout; + stream = + cpl_msg_get_level() > CPL_MSG_INFO ? fopen("/dev/null", "a") : stdout; - cpl_test_nonnull( stream ); + cpl_test_nonnull(stream); /* Create the images */ imd = cpl_image_fill_test_create(IMAGESZ, IMAGESZ); @@ -72,66 +73,66 @@ res = cpl_image_iqe(NULL, IMAGEMIN, IMAGEMIN, IMAGEMAX, IMAGEMAX); - cpl_test_error( CPL_ERROR_NULL_INPUT ); + cpl_test_error(CPL_ERROR_NULL_INPUT); cpl_test_null(res); res = cpl_image_iqe(imd, IMAGEMIN, IMAGEMIN, IMAGEMAX, IMAGEMAX); - cpl_test_error( CPL_ERROR_INVALID_TYPE ); + cpl_test_error(CPL_ERROR_INVALID_TYPE); cpl_test_null(res); - res = cpl_image_iqe(imf, IMAGESZ, IMAGESZ, IMAGESZ+1, IMAGESZ+1); + res = cpl_image_iqe(imf, IMAGESZ, IMAGESZ, IMAGESZ + 1, IMAGESZ + 1); - cpl_test_error( CPL_ERROR_ILLEGAL_INPUT ); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); cpl_test_null(res); - res = cpl_image_iqe(imf, IMAGEMIN, IMAGEMIN, IMAGEMIN+2, IMAGEMAX); - cpl_test_error( CPL_ERROR_ILLEGAL_INPUT ); + res = cpl_image_iqe(imf, IMAGEMIN, IMAGEMIN, IMAGEMIN + 2, IMAGEMAX); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); cpl_test_null(res); - res = cpl_image_iqe(imf, IMAGEMIN, IMAGEMIN, IMAGEMAX, IMAGEMIN+2); - cpl_test_error( CPL_ERROR_ILLEGAL_INPUT ); + res = cpl_image_iqe(imf, IMAGEMIN, IMAGEMIN, IMAGEMAX, IMAGEMIN + 2); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); cpl_test_null(res); /* Compute the IQE */ res = cpl_image_iqe(imf, IMAGEMIN, IMAGEMIN, IMAGEMAX, IMAGEMAX); - cpl_test_error( CPL_ERROR_NONE ); + cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(res); - cpl_test_eq( cpl_bivector_get_size(res), 7); + cpl_test_eq(cpl_bivector_get_size(res), 7); cpl_bivector_dump(res, stream); cpl_bivector_delete(res); - cpl_image_delete(imd); + cpl_image_delete(imd); cpl_image_delete(imf); - + /* * Regression test for a copy and paste bug found in line cpl_image_iqe.c:745. */ imf = cpl_image_new(200, 64, CPL_TYPE_FLOAT); cpl_test_nonnull(imf); cpl_image_fill_noise_uniform(imf, -10, 10); - cpl_test_error( CPL_ERROR_NONE ); + cpl_test_error(CPL_ERROR_NONE); imd = cpl_image_duplicate(imf); cpl_test_nonnull(imd); cpl_image_fill_gaussian(imd, 168, 32, 50000.0, 15, 4); - cpl_test_error( CPL_ERROR_NONE ); + cpl_test_error(CPL_ERROR_NONE); cpl_image_add(imf, imd); - cpl_test_error( CPL_ERROR_NONE ); + cpl_test_error(CPL_ERROR_NONE); res = cpl_image_iqe(imf, 1, 1, cpl_image_get_size_x(imf), cpl_image_get_size_y(imf)); - cpl_test_error( CPL_ERROR_NONE ); + cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(res); cpl_bivector_delete(res); cpl_image_delete(imd); cpl_image_delete(imf); - if (stream != stdout) cpl_test_zero( fclose(stream) ); + if (stream != stdout) + cpl_test_zero(fclose(stream)); return cpl_test_end(0); } /**@}*/ - diff -Nru cpl-7.1.4+ds/cplcore/tests/cpl_imagelist_basic-test.c cpl-7.2.2+ds/cplcore/tests/cpl_imagelist_basic-test.c --- cpl-7.1.4+ds/cplcore/tests/cpl_imagelist_basic-test.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/tests/cpl_imagelist_basic-test.c 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -29,7 +29,7 @@ #include "cpl_image_gen.h" #include "cpl_image_bpm.h" #include "cpl_image_io.h" -#include "cpl_stats.h" +#include "cpl_stats.h" #include "cpl_msg.h" #include "cpl_test.h" #include "cpl_memory.h" @@ -41,15 +41,15 @@ Define -----------------------------------------------------------------------------*/ -#define IMAGESZ 10 -#define NFRAMES 10 -#define MAGIC_NUMBER 42 - -#define IMAGESZBIG 512 - -#define TEST 10.0 -#define BASE 10.0 -#define POW 2.0 +#define IMAGESZ 10 +#define NFRAMES 10 +#define MAGIC_NUMBER 42 + +#define IMAGESZBIG 512 + +#define TEST 10.0 +#define BASE 10.0 +#define POW 2.0 /*----------------------------------------------------------------------------- Private Function prototypes @@ -58,10 +58,10 @@ static void cpl_imagelist_collapse_median_create_tests(cpl_size, cpl_boolean); static void cpl_imagelist_collapse_median_create_bench(cpl_size); static void cpl_imagelist_collapse_minmax_create_bench(cpl_size); -static -void cpl_imagelist_collapse_sigclip_create_bench(cpl_size, cpl_collapse_mode); -static -void cpl_imagelist_collapse_sigclip_create_test_one(const cpl_imagelist *); +static void + cpl_imagelist_collapse_sigclip_create_bench(cpl_size, cpl_collapse_mode); +static void +cpl_imagelist_collapse_sigclip_create_test_one(const cpl_imagelist *); void cpl_imagelist_collapse_create_test(cpl_type); void cpl_imagelist_collapse_sigclip_create_test(void); @@ -70,22 +70,23 @@ /*----------------------------------------------------------------------------- Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { - const cpl_type pixel_type[] = {CPL_TYPE_INT, CPL_TYPE_FLOAT, - CPL_TYPE_DOUBLE, CPL_TYPE_FLOAT_COMPLEX, - CPL_TYPE_DOUBLE_COMPLEX}; - - const cpl_size size[] = {1, 2, 3, 5, 8}; - cpl_image * img; - cpl_size nbad; - cpl_size bpm_ind, bpm_x, bpm_y; - cpl_size i, j; - cpl_boolean do_bench; - cpl_imagelist * imlist1; - cpl_imagelist * imlist2; - unsigned itype1; - cpl_error_code error; + const cpl_type pixel_type[] = { CPL_TYPE_INT, CPL_TYPE_FLOAT, + CPL_TYPE_DOUBLE, CPL_TYPE_FLOAT_COMPLEX, + CPL_TYPE_DOUBLE_COMPLEX }; + + const cpl_size size[] = { 1, 2, 3, 5, 8 }; + cpl_image *img; + cpl_size nbad; + cpl_size bpm_ind, bpm_x, bpm_y; + cpl_size i, j; + cpl_boolean do_bench; + cpl_imagelist *imlist1; + cpl_imagelist *imlist2; + unsigned itype1; + cpl_error_code error; cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); @@ -101,55 +102,53 @@ cpl_imagelist_collapse_sigclip_create_test(); - for (itype1 = 0; - itype1 < sizeof(pixel_type)/sizeof(pixel_type[0]); + for (itype1 = 0; itype1 < sizeof(pixel_type) / sizeof(pixel_type[0]); itype1++) { unsigned itype2; - for (itype2 = 0; - itype2 < sizeof(pixel_type)/sizeof(pixel_type[0]); + for (itype2 = 0; itype2 < sizeof(pixel_type) / sizeof(pixel_type[0]); itype2++) { unsigned isize; - for (isize = 0; - isize < sizeof(size)/sizeof(size[0]); - isize++) { - const cpl_error_code exp_err = + for (isize = 0; isize < sizeof(size) / sizeof(size[0]); isize++) { + const cpl_error_code exp_err = !(pixel_type[itype1] & CPL_TYPE_COMPLEX) && - (pixel_type[itype2] & CPL_TYPE_COMPLEX) ? - CPL_ERROR_TYPE_MISMATCH : CPL_ERROR_NONE; + (pixel_type[itype2] & CPL_TYPE_COMPLEX) + ? CPL_ERROR_TYPE_MISMATCH + : CPL_ERROR_NONE; const double xmin = -100.0; - const double xmax = 200.0; + const double xmax = 200.0; - cpl_image * img2; + cpl_image *img2; - imlist1 = cpl_imagelist_new(); + imlist1 = cpl_imagelist_new(); imlist2 = cpl_imagelist_new(); for (i = 0; i < size[isize]; i++) { - cpl_image * iimg = + cpl_image *iimg = cpl_image_new(IMAGESZ, IMAGESZ, pixel_type[itype1]); - cpl_test_zero(cpl_image_fill_noise_uniform(iimg, xmin, - xmax)); + cpl_test_zero( + cpl_image_fill_noise_uniform(iimg, xmin, xmax)); cpl_test_zero(cpl_imagelist_set(imlist1, iimg, i)); } for (i = 0; i < size[isize]; i++) { - cpl_image * iimg = + cpl_image *iimg = cpl_image_new(IMAGESZ, IMAGESZ, pixel_type[itype2]); - cpl_test_zero(cpl_image_fill_noise_uniform(iimg, xmin, - xmax) ); + cpl_test_zero( + cpl_image_fill_noise_uniform(iimg, xmin, xmax)); - cpl_test_zero( cpl_imagelist_set(imlist2, iimg, i) ); + cpl_test_zero(cpl_imagelist_set(imlist2, iimg, i)); } - - cpl_msg_info(cpl_func, "Basic ops., types %s and %s, with " + + cpl_msg_info(cpl_func, + "Basic ops., types %s and %s, with " "imagelist size %" CPL_SIZE_FORMAT, cpl_type_get_name(pixel_type[itype1]), cpl_type_get_name(pixel_type[itype2]), @@ -173,15 +172,16 @@ if (pixel_type[itype1] == CPL_TYPE_INT || pixel_type[itype1] == CPL_TYPE_FLOAT || pixel_type[itype1] == CPL_TYPE_DOUBLE) { - cpl_imagelist_collapse_sigclip_create_test_one(imlist1); - cpl_msg_info(cpl_func, "Collapse type %s, with " + cpl_msg_info(cpl_func, + "Collapse type %s, with " "imagelist size %" CPL_SIZE_FORMAT, cpl_type_get_name(pixel_type[itype1]), size[isize]); - img = cpl_imagelist_collapse_minmax_create(imlist1, 0, 0); + img = + cpl_imagelist_collapse_minmax_create(imlist1, 0, 0); cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(img); @@ -191,17 +191,20 @@ if (pixel_type[itype1] != CPL_TYPE_INT) { /* FIXME: Cannot test int (due to DFS08578) */ - const double eps - = pixel_type[itype1] == CPL_TYPE_FLOAT - ? FLT_EPSILON : DBL_EPSILON; + const double eps = + pixel_type[itype1] == CPL_TYPE_FLOAT + ? FLT_EPSILON + : DBL_EPSILON; cpl_test_image_abs(img, img2, 300.0 * eps); } cpl_image_delete(img); cpl_image_delete(img2); - } else { + } + else { /* Cannot sort complex numbers */ - img = cpl_imagelist_collapse_minmax_create(imlist1, 0, 0); + img = + cpl_imagelist_collapse_minmax_create(imlist1, 0, 0); cpl_test_error(CPL_ERROR_INVALID_TYPE); cpl_test_null(img); @@ -218,10 +221,10 @@ /* Test cpl_imagelist_swap_axis_create() */ - img = cpl_image_fill_test_create(IMAGESZ, 2*IMAGESZ); + img = cpl_image_fill_test_create(IMAGESZ, 2 * IMAGESZ); imlist1 = cpl_imagelist_new(); - for (i=0; i<3*IMAGESZ; i++) { - cpl_test_zero(cpl_imagelist_set(imlist1,cpl_image_duplicate(img),i)); + for (i = 0; i < 3 * IMAGESZ; i++) { + cpl_test_zero(cpl_imagelist_set(imlist1, cpl_image_duplicate(img), i)); } cpl_image_delete(img); @@ -242,64 +245,64 @@ cpl_test_eq(cpl_image_count_rejected(cpl_imagelist_get(imlist2, 0)), 1); cpl_test_eq(cpl_image_count_rejected(cpl_imagelist_get(imlist2, 1)), 2); - cpl_test_zero(cpl_image_count_rejected(cpl_imagelist_get(imlist2, 2)) ); + cpl_test_zero(cpl_image_count_rejected(cpl_imagelist_get(imlist2, 2))); cpl_imagelist_delete(imlist2); imlist2 = cpl_imagelist_swap_axis_create(imlist1, CPL_SWAP_AXIS_YZ); cpl_test_nonnull(imlist2); cpl_imagelist_delete(imlist1); - cpl_test_eq(cpl_image_count_rejected(cpl_imagelist_get(imlist2,0)), 1); - cpl_test_eq(cpl_image_count_rejected(cpl_imagelist_get(imlist2,1)), 1); - cpl_test_zero(cpl_image_count_rejected(cpl_imagelist_get(imlist2,2)) ); - cpl_test_eq(cpl_image_count_rejected(cpl_imagelist_get(imlist2,4)), 1); + cpl_test_eq(cpl_image_count_rejected(cpl_imagelist_get(imlist2, 0)), 1); + cpl_test_eq(cpl_image_count_rejected(cpl_imagelist_get(imlist2, 1)), 1); + cpl_test_zero(cpl_image_count_rejected(cpl_imagelist_get(imlist2, 2))); + cpl_test_eq(cpl_image_count_rejected(cpl_imagelist_get(imlist2, 4)), 1); cpl_imagelist_delete(imlist2); /* Create two images set */ img = cpl_image_fill_test_create(IMAGESZ, IMAGESZ); imlist1 = cpl_imagelist_new(); imlist2 = cpl_imagelist_new(); - for (i=0; i nz/2) { + if (i > nz / 2) { code = cpl_image_fill_noise_uniform(image, 1.0, (double)nz); cpl_test_eq_error(code, CPL_ERROR_NONE); - } else if (i > 0) { + } + else if (i > 0) { code = cpl_image_fill_noise_uniform(image, (double)-nz, -1.0); cpl_test_eq_error(code, CPL_ERROR_NONE); } @@ -558,19 +562,18 @@ cpl_image_delete(image); cpl_imagelist_delete(imglist); - } /* small (< L2 cache) imagelist test */ { - cpl_imagelist * l = cpl_imagelist_new(); - cpl_imagelist * lb = cpl_imagelist_new(); + cpl_imagelist *l = cpl_imagelist_new(); + cpl_imagelist *lb = cpl_imagelist_new(); size_t i, j, k; int rej; - cpl_image * med, * medb; + cpl_image *med, *medb; for (i = 0; i < 107; i++) { - cpl_image * img = cpl_image_new(7, 13, CPL_TYPE_FLOAT); - cpl_image * imgb = cpl_image_new(7, 13, CPL_TYPE_FLOAT); + cpl_image *img = cpl_image_new(7, 13, CPL_TYPE_FLOAT); + cpl_image *imgb = cpl_image_new(7, 13, CPL_TYPE_FLOAT); for (j = 0; j < 7; j++) { for (k = 0; k < 13; k++) { cpl_image_set(img, j + 1, k + 1, k * 13 + j + i); @@ -605,7 +608,6 @@ } return; - } @@ -616,21 +618,23 @@ @return void */ /*----------------------------------------------------------------------------*/ -static void cpl_imagelist_collapse_median_create_bench(cpl_size mz) +static void +cpl_imagelist_collapse_median_create_bench(cpl_size mz) { - - cpl_imagelist * imglist = cpl_imagelist_new(); - cpl_image * image; - const cpl_size nz = mz; - const cpl_size nx = 2*IMAGESZBIG; - const cpl_size ny = 2*IMAGESZBIG; - double secs; - size_t bytes; - cpl_size i; + cpl_imagelist *imglist = cpl_imagelist_new(); + cpl_image *image; + const cpl_size nz = mz; + const cpl_size nx = 2 * IMAGESZBIG; + const cpl_size ny = 2 * IMAGESZBIG; + double secs; + size_t bytes; + cpl_size i; - cpl_msg_info(cpl_func, "Benchmarking with %" CPL_SIZE_FORMAT " %" - CPL_SIZE_FORMAT " X %" CPL_SIZE_FORMAT " images", nz, nx, ny); + cpl_msg_info(cpl_func, + "Benchmarking with %" CPL_SIZE_FORMAT " %" CPL_SIZE_FORMAT + " X %" CPL_SIZE_FORMAT " images", + nz, nx, ny); /* Fill imagelist */ for (i = 0; i < nz; i++) { @@ -641,34 +645,36 @@ cpl_test_eq(cpl_imagelist_get_size(imglist), nz); - cpl_msg_info(cpl_func, "Testing with %" CPL_SIZE_FORMAT " %" - CPL_SIZE_FORMAT " X %" CPL_SIZE_FORMAT " images", nz, nx, ny); + cpl_msg_info(cpl_func, + "Testing with %" CPL_SIZE_FORMAT " %" CPL_SIZE_FORMAT + " X %" CPL_SIZE_FORMAT " images", + nz, nx, ny); bytes = cpl_test_get_bytes_imagelist(imglist); - secs = cpl_test_get_cputime(); + secs = cpl_test_get_cputime(); image = cpl_imagelist_collapse_median_create(imglist); secs = cpl_test_get_cputime() - secs; - cpl_test_nonnull( image); - cpl_test_error( CPL_ERROR_NONE); + cpl_test_nonnull(image); + cpl_test_error(CPL_ERROR_NONE); cpl_image_delete(image); - cpl_msg_info(cpl_func, "Time spent median collapsing with %" - CPL_SIZE_FORMAT " X %" CPL_SIZE_FORMAT " X %" CPL_SIZE_FORMAT - ": [s]: %g", nz, nx, ny, secs); + cpl_msg_info(cpl_func, + "Time spent median collapsing with %" CPL_SIZE_FORMAT + " X %" CPL_SIZE_FORMAT " X %" CPL_SIZE_FORMAT ": [s]: %g", + nz, nx, ny, secs); if (secs > 0.0) { - cpl_msg_info(cpl_func,"Processing rate [MB/s]: %g", + cpl_msg_info(cpl_func, "Processing rate [MB/s]: %g", 1e-6 * (double)bytes / secs); } cpl_imagelist_delete(imglist); - return; - + return; } /*----------------------------------------------------------------------------*/ @@ -678,21 +684,23 @@ @return void */ /*----------------------------------------------------------------------------*/ -static void cpl_imagelist_collapse_minmax_create_bench(cpl_size mz) +static void +cpl_imagelist_collapse_minmax_create_bench(cpl_size mz) { - - cpl_imagelist * imglist = cpl_imagelist_new(); - cpl_image * image; - const cpl_size nz = mz; - const cpl_size nx = 2*IMAGESZBIG; - const cpl_size ny = 2*IMAGESZBIG; - double secs; - size_t bytes; - cpl_size i; + cpl_imagelist *imglist = cpl_imagelist_new(); + cpl_image *image; + const cpl_size nz = mz; + const cpl_size nx = 2 * IMAGESZBIG; + const cpl_size ny = 2 * IMAGESZBIG; + double secs; + size_t bytes; + cpl_size i; - cpl_msg_info(cpl_func, "Benchmarking with %" CPL_SIZE_FORMAT " %" - CPL_SIZE_FORMAT " X %" CPL_SIZE_FORMAT " images", nz, nx, ny); + cpl_msg_info(cpl_func, + "Benchmarking with %" CPL_SIZE_FORMAT " %" CPL_SIZE_FORMAT + " X %" CPL_SIZE_FORMAT " images", + nz, nx, ny); /* Fill imagelist */ for (i = 0; i < nz; i++) { @@ -703,34 +711,36 @@ cpl_test_eq(cpl_imagelist_get_size(imglist), nz); - cpl_msg_info(cpl_func, "Testing with %" CPL_SIZE_FORMAT " %" - CPL_SIZE_FORMAT " X %" CPL_SIZE_FORMAT " images", nz, nx, ny); + cpl_msg_info(cpl_func, + "Testing with %" CPL_SIZE_FORMAT " %" CPL_SIZE_FORMAT + " X %" CPL_SIZE_FORMAT " images", + nz, nx, ny); bytes = cpl_test_get_bytes_imagelist(imglist); - secs = cpl_test_get_cputime(); + secs = cpl_test_get_cputime(); image = cpl_imagelist_collapse_minmax_create(imglist, 1, 1); secs = cpl_test_get_cputime() - secs; - cpl_test_nonnull( image); - cpl_test_error( CPL_ERROR_NONE); + cpl_test_nonnull(image); + cpl_test_error(CPL_ERROR_NONE); cpl_image_delete(image); - cpl_msg_info(cpl_func, "Time spent min-max collapsing with %" - CPL_SIZE_FORMAT " X %" CPL_SIZE_FORMAT " X %" - CPL_SIZE_FORMAT ": [s]: %g", nz, nx, ny, secs); + cpl_msg_info(cpl_func, + "Time spent min-max collapsing with %" CPL_SIZE_FORMAT + " X %" CPL_SIZE_FORMAT " X %" CPL_SIZE_FORMAT ": [s]: %g", + nz, nx, ny, secs); if (secs > 0.0) { - cpl_msg_info(cpl_func,"Processing rate [MB/s]: %g", + cpl_msg_info(cpl_func, "Processing rate [MB/s]: %g", 1e-6 * (double)bytes / secs); } cpl_imagelist_delete(imglist); - return; - + return; } @@ -741,55 +751,58 @@ @return void */ /*----------------------------------------------------------------------------*/ -static -void cpl_imagelist_collapse_sigclip_create_test_one(const cpl_imagelist * self) +static void +cpl_imagelist_collapse_sigclip_create_test_one(const cpl_imagelist *self) { - - const unsigned clip_mode[] = {CPL_COLLAPSE_MEAN, CPL_COLLAPSE_MEDIAN, - CPL_COLLAPSE_MEDIAN_MEAN}; - const int nmode = sizeof(clip_mode)/sizeof(clip_mode[0]); - const cpl_size nsize = cpl_imagelist_get_size(self); - const cpl_image * image = cpl_imagelist_get_const(self, 0); - const cpl_type type = cpl_image_get_type(image); - const cpl_size nx = cpl_image_get_size_x(image); - const cpl_size ny = cpl_image_get_size_y(image); - cpl_image * map = cpl_image_new(nx, ny, CPL_TYPE_INT); - int imode; - - - cpl_msg_info(cpl_func, "Testing %s with %" CPL_SIZE_FORMAT " images of " - "type %s", "cpl_imagelist_collapse_sigclip_create", nsize, + const unsigned clip_mode[] = { CPL_COLLAPSE_MEAN, CPL_COLLAPSE_MEDIAN, + CPL_COLLAPSE_MEDIAN_MEAN }; + const int nmode = sizeof(clip_mode) / sizeof(clip_mode[0]); + const cpl_size nsize = cpl_imagelist_get_size(self); + const cpl_image *image = cpl_imagelist_get_const(self, 0); + const cpl_type type = cpl_image_get_type(image); + const cpl_size nx = cpl_image_get_size_x(image); + const cpl_size ny = cpl_image_get_size_y(image); + cpl_image *map = cpl_image_new(nx, ny, CPL_TYPE_INT); + int imode; + + + cpl_msg_info(cpl_func, + "Testing %s with %" CPL_SIZE_FORMAT " images of " + "type %s", + "cpl_imagelist_collapse_sigclip_create", nsize, cpl_type_get_name(type)); for (imode = 0; imode < nmode; imode++) { const unsigned mode = clip_mode[imode]; - cpl_size ikeep; - cpl_size jkeep = nsize; + cpl_size ikeep; + cpl_size jkeep = nsize; for (ikeep = nsize; ikeep > 0; ikeep--) { - const double keepfrac = (ikeep == nsize ? ikeep : ikeep + 0.5) - / (double)nsize; + const double keepfrac = + (ikeep == nsize ? ikeep : ikeep + 0.5) / (double)nsize; - cpl_image * clipped - = cpl_imagelist_collapse_sigclip_create(self, 0.5, 1.5, - keepfrac, mode, map); + cpl_image *clipped = + cpl_imagelist_collapse_sigclip_create(self, 0.5, 1.5, keepfrac, + mode, map); if (nsize == 1) { cpl_test_error(CPL_ERROR_DATA_NOT_FOUND); cpl_test_null(clipped); - } else if (type & CPL_TYPE_COMPLEX) { + } + else if (type & CPL_TYPE_COMPLEX) { cpl_test_error(CPL_ERROR_INVALID_TYPE); cpl_test_null(clipped); - } else { - cpl_image * contrib; - cpl_mask * bpm; + } + else { + cpl_image *contrib; + cpl_mask *bpm; /* In no-clip collapsed image */ - cpl_size minpix, maxpix, maxbad; + cpl_size minpix, maxpix, maxbad; cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(clipped); - cpl_test_eq(cpl_image_get_type(clipped), type); + cpl_test_eq(cpl_image_get_type(clipped), type); cpl_test_eq(cpl_image_get_size_x(clipped), nx); cpl_test_eq(cpl_image_get_size_x(clipped), ny); @@ -805,9 +818,10 @@ if (cpl_image_get_min(map) == 0) { cpl_test_eq_mask(bpm, cpl_image_get_bpm_const(clipped)); - } else { + } + else { cpl_test_null(cpl_image_get_bpm_const(clipped)); - cpl_test_zero(cpl_mask_count(bpm)); + cpl_test_zero(cpl_mask_count(bpm)); cpl_test_leq(CX_MAX(1, ikeep - maxbad), cpl_image_get_min(map)); @@ -820,7 +834,7 @@ if (ikeep == nsize) { /* Nothing was rejected */ - cpl_image * average = cpl_imagelist_collapse_create(self); + cpl_image *average = cpl_imagelist_collapse_create(self); cpl_test_error(CPL_ERROR_NONE); @@ -832,10 +846,14 @@ averaged one - except for integer pixels, where the average is computed using integer arithmetics, while the clipped uses floating point */ - cpl_test_image_abs(clipped, average, nsize * - (type == CPL_TYPE_INT ? 1 : 150.0 * - (type == CPL_TYPE_DOUBLE ? DBL_EPSILON - : FLT_EPSILON))); + cpl_test_image_abs(clipped, average, + nsize * + (type == CPL_TYPE_INT + ? 1 + : 150.0 * + (type == CPL_TYPE_DOUBLE + ? DBL_EPSILON + : FLT_EPSILON))); cpl_image_delete(average); } @@ -844,7 +862,6 @@ cpl_image_delete(clipped); } } - } cpl_image_delete(map); } @@ -859,25 +876,26 @@ @note Modified from cpl_imagelist_collapse_minmax_create_bench() */ /*----------------------------------------------------------------------------*/ -static void cpl_imagelist_collapse_sigclip_create_bench(cpl_size mz, - cpl_collapse_mode mode) +static void +cpl_imagelist_collapse_sigclip_create_bench(cpl_size mz, cpl_collapse_mode mode) { - - cpl_imagelist * imglist = cpl_imagelist_new(); - const cpl_size nz = mz; - const cpl_size nx = 2*IMAGESZBIG; - const cpl_size ny = 2*IMAGESZBIG; - cpl_image * image = NULL; - cpl_image * map = cpl_image_new(nx, ny, CPL_TYPE_INT); + cpl_imagelist *imglist = cpl_imagelist_new(); + const cpl_size nz = mz; + const cpl_size nx = 2 * IMAGESZBIG; + const cpl_size ny = 2 * IMAGESZBIG; + cpl_image *image = NULL; + cpl_image *map = cpl_image_new(nx, ny, CPL_TYPE_INT); cpl_error_code error; - double secs; - cpl_type type; - size_t bytes; - cpl_size i; + double secs; + cpl_type type; + size_t bytes; + cpl_size i; - cpl_msg_info(cpl_func, "Benchmarking with %" CPL_SIZE_FORMAT " %" - CPL_SIZE_FORMAT " X %" CPL_SIZE_FORMAT " images", nz, nx, ny); + cpl_msg_info(cpl_func, + "Benchmarking with %" CPL_SIZE_FORMAT " %" CPL_SIZE_FORMAT + " X %" CPL_SIZE_FORMAT " images", + nz, nx, ny); /* Fill imagelist */ for (i = 0; i < nz; i++) { @@ -896,15 +914,17 @@ cpl_test_eq(cpl_imagelist_get_size(imglist), nz); - cpl_msg_info(cpl_func, "Testing with %" CPL_SIZE_FORMAT " %" - CPL_SIZE_FORMAT " X %" CPL_SIZE_FORMAT " images", nz, nx, ny); + cpl_msg_info(cpl_func, + "Testing with %" CPL_SIZE_FORMAT " %" CPL_SIZE_FORMAT + " X %" CPL_SIZE_FORMAT " images", + nz, nx, ny); bytes = cpl_test_get_bytes_imagelist(imglist); - secs = cpl_test_get_cputime(); + secs = cpl_test_get_cputime(); - image = cpl_imagelist_collapse_sigclip_create(imglist, 0.5, 1.5, - 0.25, mode, map); + image = cpl_imagelist_collapse_sigclip_create(imglist, 0.5, 1.5, 0.25, mode, + map); secs = cpl_test_get_cputime() - secs; @@ -916,26 +936,27 @@ cpl_test_leq(1, cpl_image_get_min(map)); - cpl_msg_info(cpl_func, "Time spent kappa-sigma-clipping around the %s " - "with %" CPL_SIZE_FORMAT " X %" CPL_SIZE_FORMAT " X %" - CPL_SIZE_FORMAT ": [s]: %g", mode == CPL_COLLAPSE_MEAN - ? "mean" : (mode == CPL_COLLAPSE_MEDIAN ? "median" : - "median+mean"), nz, nx, ny, secs); + cpl_msg_info(cpl_func, + "Time spent kappa-sigma-clipping around the %s " + "with %" CPL_SIZE_FORMAT " X %" CPL_SIZE_FORMAT + " X %" CPL_SIZE_FORMAT ": [s]: %g", + mode == CPL_COLLAPSE_MEAN + ? "mean" + : (mode == CPL_COLLAPSE_MEDIAN ? "median" : "median+mean"), + nz, nx, ny, secs); if (secs > 0.0) { - cpl_msg_info(cpl_func,"Processing rate [MB/s]: %g", + cpl_msg_info(cpl_func, "Processing rate [MB/s]: %g", 1e-6 * (double)bytes / secs); } cpl_imagelist_delete(imglist); cpl_image_delete(map); - return; - + return; } - /*----------------------------------------------------------------------------*/ /** @brief Test the CPL function @@ -943,19 +964,19 @@ @return void */ /*----------------------------------------------------------------------------*/ -void cpl_imagelist_collapse_create_test(cpl_type type) +void +cpl_imagelist_collapse_create_test(cpl_type type) { - - cpl_imagelist * imlist1 = cpl_imagelist_new(); - cpl_image * img = cpl_image_new(IMAGESZ, IMAGESZ, type); - cpl_error_code error; + cpl_imagelist *imlist1 = cpl_imagelist_new(); + cpl_image *img = cpl_image_new(IMAGESZ, IMAGESZ, type); + cpl_error_code error; cpl_size i; /* Fill the list with integers 1 .. 2n+1 */ /* Their mean: 0.5 * (2n+1) * (2n+2) / 2n+1 = n + 1 */ - for (i=0; i < 2 * IMAGESZ + 1; i++) { + for (i = 0; i < 2 * IMAGESZ + 1; i++) { error = cpl_image_add_scalar(img, 1.0); cpl_test_eq_error(error, CPL_ERROR_NONE); error = cpl_imagelist_set(imlist1, cpl_image_duplicate(img), i); @@ -976,8 +997,7 @@ cpl_image_delete(img); cpl_imagelist_delete(imlist1); - return; - + return; } /*----------------------------------------------------------------------------*/ @@ -986,23 +1006,23 @@ @return void */ /*----------------------------------------------------------------------------*/ -void cpl_imagelist_collapse_sigclip_create_test(void) +void +cpl_imagelist_collapse_sigclip_create_test(void) { - - const unsigned clip_mode[] = {CPL_COLLAPSE_MEAN, CPL_COLLAPSE_MEDIAN, - CPL_COLLAPSE_MEDIAN_MEAN}; - const int nmode = sizeof(clip_mode)/sizeof(clip_mode[0]); - cpl_imagelist * imlist1 = cpl_imagelist_new(); - cpl_image * nullimg; /* Expected to be NULL */ - cpl_image * map = cpl_image_new(1, 1, CPL_TYPE_INT); - cpl_error_code error; - int imode; - cpl_size nz, i; + const unsigned clip_mode[] = { CPL_COLLAPSE_MEAN, CPL_COLLAPSE_MEDIAN, + CPL_COLLAPSE_MEDIAN_MEAN }; + const int nmode = sizeof(clip_mode) / sizeof(clip_mode[0]); + cpl_imagelist *imlist1 = cpl_imagelist_new(); + cpl_image *nullimg; /* Expected to be NULL */ + cpl_image *map = cpl_image_new(1, 1, CPL_TYPE_INT); + cpl_error_code error; + int imode; + cpl_size nz, i; for (imode = 0; imode < nmode; imode++) { const unsigned mode = clip_mode[imode]; - cpl_image * img = cpl_image_new(1, 1, CPL_TYPE_DOUBLE); + cpl_image *img = cpl_image_new(1, 1, CPL_TYPE_DOUBLE); cpl_imagelist_empty(imlist1); @@ -1010,7 +1030,7 @@ /* Their mean: 0.5 */ /* Their St.dev: 0.5 * n / (n-1) */ - for (i=0; i < IMAGESZ; i++) { + for (i = 0; i < IMAGESZ; i++) { error = cpl_imagelist_set(imlist1, cpl_image_duplicate(img), i); cpl_test_eq_error(error, CPL_ERROR_NONE); } @@ -1085,7 +1105,7 @@ cpl_test_zero(cpl_imagelist_set(imlist1, img, nz++)); cpl_test_eq(cpl_imagelist_get_size(imlist1), nz); - img = cpl_image_duplicate(cpl_imagelist_get_const(imlist1, nz-1)); + img = cpl_image_duplicate(cpl_imagelist_get_const(imlist1, nz - 1)); error = cpl_image_add_scalar(img, 2.0 / IMAGESZ); cpl_test_eq_error(error, CPL_ERROR_NONE); cpl_test_zero(cpl_imagelist_set(imlist1, img, nz++)); @@ -1155,8 +1175,8 @@ cpl_test_null(nullimg); nullimg = cpl_imagelist_collapse_sigclip_create(imlist1, 1.0, 1.0, - 1.0 + DBL_EPSILON, - mode, NULL); + 1.0 + DBL_EPSILON, mode, + NULL); cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); cpl_test_null(nullimg); @@ -1220,20 +1240,19 @@ mode, NULL); cpl_test_error(CPL_ERROR_INVALID_TYPE); cpl_test_null(nullimg); - } - nullimg = cpl_imagelist_collapse_sigclip_create(imlist1, 1.0, 1.0, 0.75, - CPL_COLLAPSE_MEAN + - CPL_COLLAPSE_MEDIAN + - CPL_COLLAPSE_MEDIAN_MEAN, - NULL); + nullimg = + cpl_imagelist_collapse_sigclip_create(imlist1, 1.0, 1.0, 0.75, + CPL_COLLAPSE_MEAN + + CPL_COLLAPSE_MEDIAN + + CPL_COLLAPSE_MEDIAN_MEAN, + NULL); cpl_test_error(CPL_ERROR_UNSUPPORTED_MODE); cpl_test_null(nullimg); cpl_imagelist_delete(imlist1); cpl_image_delete(map); - } /*----------------------------------------------------------------------------*/ @@ -1243,23 +1262,23 @@ @note This test activates the cache optimization given a 18MB L2 cache */ /*----------------------------------------------------------------------------*/ -static void cpl_imagelist_collapse_median_create_test_one(void) +static void +cpl_imagelist_collapse_median_create_test_one(void) { - - cpl_imagelist * imlist = cpl_imagelist_new(); - cpl_image * img; + cpl_imagelist *imlist = cpl_imagelist_new(); + cpl_image *img; cpl_size i; - for (i = 0 ; i < 300; i++) { - img = cpl_image_new(IMAGESZBIG, IMAGESZBIG/2, CPL_TYPE_FLOAT); - cpl_image_reject(img, IMAGESZBIG, IMAGESZBIG/2); + for (i = 0; i < 300; i++) { + img = cpl_image_new(IMAGESZBIG, IMAGESZBIG / 2, CPL_TYPE_FLOAT); + cpl_image_reject(img, IMAGESZBIG, IMAGESZBIG / 2); cpl_imagelist_set(imlist, img, i); } img = cpl_imagelist_collapse_median_create(imlist); cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(img); - cpl_test(cpl_image_is_rejected(img, IMAGESZBIG, IMAGESZBIG/2)); + cpl_test(cpl_image_is_rejected(img, IMAGESZBIG, IMAGESZBIG / 2)); cpl_image_delete(img); cpl_imagelist_delete(imlist); diff -Nru cpl-7.1.4+ds/cplcore/tests/cpl_imagelist_io-test.c cpl-7.2.2+ds/cplcore/tests/cpl_imagelist_io-test.c --- cpl-7.1.4+ds/cplcore/tests/cpl_imagelist_io-test.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/tests/cpl_imagelist_io-test.c 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -31,10 +31,10 @@ -----------------------------------------------------------------------------*/ #ifndef IMAGESZ -#define IMAGESZ 127 +#define IMAGESZ 127 #endif #ifndef NIMAGES -#define NIMAGES 10 +#define NIMAGES 10 #endif #define FILENAME "cpl_imagelist_test.fits" @@ -45,41 +45,44 @@ -----------------------------------------------------------------------------*/ static void cpl_imagelist_save_compression_test(void); -static void cpl_imagelist_save_compression_bench(cpl_size, cpl_size, - cpl_size, cpl_size); +static void cpl_imagelist_save_compression_bench(cpl_size, + cpl_size, + cpl_size, + cpl_size); /*----------------------------------------------------------------------------- Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { - const char * file = FILENAME; - cpl_imagelist * imlist; - cpl_imagelist * imlist2; - cpl_imagelist * imlista; - cpl_imagelist * nulllist; - cpl_image * image; - cpl_image * nullimg; - double flags[NIMAGES]; - cpl_vector * eraser; - cpl_size i; - FILE * stream; - int next; + const char *file = FILENAME; + cpl_imagelist *imlist; + cpl_imagelist *imlist2; + cpl_imagelist *imlista; + cpl_imagelist *nulllist; + cpl_image *image; + cpl_image *nullimg; + double flags[NIMAGES]; + cpl_vector *eraser; + cpl_size i; + FILE *stream; + int next; #if IMAGESZ > 127 - const cpl_size boxsize = 5; + const cpl_size boxsize = 5; #elif IMAGESZ < 25 /* FIXME: Will the tests pass with this ? */ - const cpl_size boxsize = 1; + const cpl_size boxsize = 1; #else - const cpl_size boxsize = IMAGESZ / 25; + const cpl_size boxsize = IMAGESZ / 25; #endif - cpl_error_code error; + cpl_error_code error; cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); - stream = cpl_msg_get_level() > CPL_MSG_INFO - ? fopen("/dev/null", "a") : stdout; + stream = + cpl_msg_get_level() > CPL_MSG_INFO ? fopen("/dev/null", "a") : stdout; /* Insert tests below */ @@ -90,126 +93,124 @@ cpl_msg_info("", "Checking various failures"); image = cpl_image_fill_test_create(IMAGESZ, IMAGESZ); - cpl_test_nonnull( image ); + cpl_test_nonnull(image); /* Test cpl_imagelist_new() */ imlist = cpl_imagelist_new(); - cpl_test_nonnull( imlist ); + cpl_test_nonnull(imlist); - cpl_test_zero( cpl_imagelist_get_size(imlist) ); - cpl_test_eq( cpl_imagelist_is_uniform(imlist), 1); + cpl_test_zero(cpl_imagelist_get_size(imlist)); + cpl_test_eq(cpl_imagelist_is_uniform(imlist), 1); /* Failure tests involving NULL end empty lists */ i = cpl_imagelist_get_size(NULL); - cpl_test_error( CPL_ERROR_NULL_INPUT ); - cpl_test_eq( i, -1 ); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_eq(i, -1); i = cpl_imagelist_is_uniform(NULL); - cpl_test_error( CPL_ERROR_NULL_INPUT ); - cpl_test( i < 0); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test(i < 0); error = cpl_imagelist_set(NULL, image, 0); - cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT ); + cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT); error = cpl_imagelist_set(imlist, NULL, 0); - cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT ); + cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT); error = cpl_imagelist_set(imlist, image, -1); - cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT ); + cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); error = cpl_imagelist_set(imlist, image, 1); - cpl_test_eq_error( error, CPL_ERROR_ACCESS_OUT_OF_RANGE ); + cpl_test_eq_error(error, CPL_ERROR_ACCESS_OUT_OF_RANGE); nullimg = cpl_imagelist_get(NULL, 0); - cpl_test_error( CPL_ERROR_NULL_INPUT ); - cpl_test_null( nullimg ); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(nullimg); nullimg = cpl_imagelist_get(imlist, -1); - cpl_test_error( CPL_ERROR_ILLEGAL_INPUT ); - cpl_test_null( nullimg ); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(nullimg); nullimg = cpl_imagelist_get(imlist, 0); - cpl_test_error( CPL_ERROR_ACCESS_OUT_OF_RANGE ); - cpl_test_null( nullimg ); + cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_test_null(nullimg); error = cpl_imagelist_erase(imlist, NULL); - cpl_test_eq_error( error, CPL_ERROR_NULL_INPUT ); + cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT); /* The elements of eraser are not initialized at this point, but they are also not supposed to be accessed */ error = cpl_imagelist_erase(NULL, eraser); - cpl_test_eq_error( error, CPL_ERROR_NULL_INPUT ); + cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT); error = cpl_imagelist_erase(imlist, eraser); - cpl_test_eq_error( error, CPL_ERROR_INCOMPATIBLE_INPUT ); + cpl_test_eq_error(error, CPL_ERROR_INCOMPATIBLE_INPUT); nulllist = cpl_imagelist_duplicate(NULL); - cpl_test_error( CPL_ERROR_NULL_INPUT ); - cpl_test_null( nulllist ); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(nulllist); + + error = + cpl_imagelist_save(imlist, NULL, CPL_TYPE_FLOAT, NULL, CPL_IO_CREATE); + cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT); + + error = cpl_imagelist_save(NULL, file, CPL_TYPE_FLOAT, NULL, CPL_IO_CREATE); + cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT); - error = cpl_imagelist_save(imlist, NULL, CPL_TYPE_FLOAT, NULL, - CPL_IO_CREATE); - cpl_test_eq_error( error, CPL_ERROR_NULL_INPUT ); - - error = cpl_imagelist_save(NULL, file, CPL_TYPE_FLOAT, NULL, - CPL_IO_CREATE); - cpl_test_eq_error( error, CPL_ERROR_NULL_INPUT ); - - error = cpl_imagelist_save(imlist, file, CPL_TYPE_FLOAT, NULL, - CPL_IO_CREATE); - cpl_test_eq_error( error, CPL_ERROR_ILLEGAL_INPUT ); + error = + cpl_imagelist_save(imlist, file, CPL_TYPE_FLOAT, NULL, CPL_IO_CREATE); + cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); nulllist = cpl_imagelist_load(NULL, CPL_TYPE_INT, 0); - cpl_test_error( CPL_ERROR_NULL_INPUT ); - cpl_test_null( nulllist ); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(nulllist); nulllist = cpl_imagelist_load(".", CPL_TYPE_INT, 0); - cpl_test_error( CPL_ERROR_FILE_IO ); - cpl_test_null( nulllist ); + cpl_test_error(CPL_ERROR_FILE_IO); + cpl_test_null(nulllist); nulllist = cpl_imagelist_load_window(NULL, CPL_TYPE_INT, 0, 1, 1, 2, 2); - cpl_test_error( CPL_ERROR_NULL_INPUT ); - cpl_test_null( nulllist ); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(nulllist); nulllist = cpl_imagelist_load_window(file, CPL_TYPE_INT, -1, 1, 1, 2, 2); - cpl_test_error( CPL_ERROR_ILLEGAL_INPUT ); - cpl_test_null( nulllist ); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(nulllist); nulllist = cpl_imagelist_load_window(".", CPL_TYPE_INT, 0, 1, 1, 2, 2); - cpl_test_error( CPL_ERROR_FILE_IO ); - cpl_test_null( nulllist ); + cpl_test_error(CPL_ERROR_FILE_IO); + cpl_test_null(nulllist); /* Test cpl_imagelist_duplicate() of empty list */ imlist2 = cpl_imagelist_duplicate(imlist); - cpl_test_nonnull( imlist2 ); - - cpl_test_zero( cpl_imagelist_get_size(imlist2) ); - cpl_test_eq( cpl_imagelist_is_uniform(imlist2), 1); + cpl_test_nonnull(imlist2); + + cpl_test_zero(cpl_imagelist_get_size(imlist2)); + cpl_test_eq(cpl_imagelist_is_uniform(imlist2), 1); cpl_imagelist_empty(imlist2); /* Test cpl_imagelist_unset() */ cpl_imagelist_delete(imlist2); - + cpl_msg_info("", "Create an image list of %d images", NIMAGES); /* Test cpl_imagelist_set() */ - for (i=0; i < NIMAGES; i++) { - cpl_image * copy = cpl_image_fill_test_create(IMAGESZ, IMAGESZ); + for (i = 0; i < NIMAGES; i++) { + cpl_image *copy = cpl_image_fill_test_create(IMAGESZ, IMAGESZ); flags[i] = i % 2 ? 1.0 : -1.0; error = cpl_imagelist_set(imlist, copy, i); cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_zero( cpl_imagelist_is_uniform(imlist) ); - cpl_test_eq( cpl_imagelist_get_size(imlist), i+1 ); - cpl_test_eq_ptr( cpl_imagelist_get(imlist, i), copy ); + cpl_test_zero(cpl_imagelist_is_uniform(imlist)); + cpl_test_eq(cpl_imagelist_get_size(imlist), i + 1); + cpl_test_eq_ptr(cpl_imagelist_get(imlist, i), copy); /* Insert image twice, last image will remain twice in list */ error = cpl_imagelist_set(imlist, copy, i + 1); cpl_test_eq_error(error, CPL_ERROR_NONE); - } cpl_image_delete(image); (void)cpl_imagelist_unset(imlist, NIMAGES); @@ -218,12 +219,9 @@ cpl_imagelist_dump_{structure, window} */ cpl_imagelist_dump_structure(imlist, stream); - cpl_imagelist_dump_window(imlist, - (IMAGESZ / 2) - boxsize, - (IMAGESZ / 2) - boxsize, - (IMAGESZ / 2) + boxsize, - (IMAGESZ / 2) + boxsize, - stream); + cpl_imagelist_dump_window(imlist, (IMAGESZ / 2) - boxsize, + (IMAGESZ / 2) - boxsize, (IMAGESZ / 2) + boxsize, + (IMAGESZ / 2) + boxsize, stream); cpl_msg_info("", "Cast the image list"); @@ -240,108 +238,108 @@ error = cpl_imagelist_cast(imlist2, imlist, CPL_TYPE_INVALID); cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); - cpl_test_zero( cpl_imagelist_get_size(imlist2)); + cpl_test_zero(cpl_imagelist_get_size(imlist2)); error = cpl_imagelist_cast(imlist2, imlist, CPL_TYPE_UNSPECIFIED); cpl_test_eq_error(error, CPL_ERROR_INVALID_TYPE); - cpl_test_zero( cpl_imagelist_get_size(imlist2)); + cpl_test_zero(cpl_imagelist_get_size(imlist2)); error = cpl_imagelist_cast(imlist2, imlist, CPL_TYPE_FLOAT); cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_zero( cpl_imagelist_is_uniform(imlist2)); - cpl_test_eq( cpl_imagelist_get_size(imlist2), NIMAGES ); + cpl_test_zero(cpl_imagelist_is_uniform(imlist2)); + cpl_test_eq(cpl_imagelist_get_size(imlist2), NIMAGES); error = cpl_imagelist_cast(imlist2, NULL, CPL_TYPE_INT); cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_zero( cpl_imagelist_is_uniform(imlist2)); - cpl_test_eq( cpl_imagelist_get_size(imlist2), NIMAGES ); + cpl_test_zero(cpl_imagelist_is_uniform(imlist2)); + cpl_test_eq(cpl_imagelist_get_size(imlist2), NIMAGES); error = cpl_imagelist_cast(imlist2, imlist, CPL_TYPE_UNSPECIFIED); cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_zero( cpl_imagelist_is_uniform(imlist2)); - cpl_test_eq( cpl_imagelist_get_size(imlist2), 2 * NIMAGES ); + cpl_test_zero(cpl_imagelist_is_uniform(imlist2)); + cpl_test_eq(cpl_imagelist_get_size(imlist2), 2 * NIMAGES); /* Test a cast with a shared image */ error = cpl_imagelist_set(imlist2, cpl_imagelist_get(imlist2, 0), cpl_imagelist_get_size(imlist2)); - cpl_test_eq( cpl_imagelist_get_size(imlist2), 2 * NIMAGES + 1); + cpl_test_eq(cpl_imagelist_get_size(imlist2), 2 * NIMAGES + 1); cpl_test_eq_error(error, CPL_ERROR_NONE); error = cpl_imagelist_cast(imlist2, NULL, CPL_TYPE_FLOAT_COMPLEX); cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_zero( cpl_imagelist_is_uniform(imlist2)); - cpl_test_eq( cpl_imagelist_get_size(imlist2), 2 * NIMAGES + 1); + cpl_test_zero(cpl_imagelist_is_uniform(imlist2)); + cpl_test_eq(cpl_imagelist_get_size(imlist2), 2 * NIMAGES + 1); error = cpl_imagelist_cast(imlist2, NULL, CPL_TYPE_FLOAT); cpl_test_eq_error(error, CPL_ERROR_TYPE_MISMATCH); - cpl_test_zero( cpl_imagelist_is_uniform(imlist2)); - cpl_test_eq( cpl_imagelist_get_size(imlist2), 2 * NIMAGES + 1); + cpl_test_zero(cpl_imagelist_is_uniform(imlist2)); + cpl_test_eq(cpl_imagelist_get_size(imlist2), 2 * NIMAGES + 1); cpl_imagelist_delete(imlist2); cpl_msg_info("", "Duplicate the image list"); imlist2 = cpl_imagelist_duplicate(imlist); - cpl_test_nonnull( imlist2 ); + cpl_test_nonnull(imlist2); - cpl_test_zero( cpl_imagelist_is_uniform(imlist2)); - cpl_test_eq( cpl_imagelist_get_size(imlist2), NIMAGES ); + cpl_test_zero(cpl_imagelist_is_uniform(imlist2)); + cpl_test_eq(cpl_imagelist_get_size(imlist2), NIMAGES); /* Failure tests involving non-empty, valid list */ - error = cpl_imagelist_save(imlist2, ".", CPL_TYPE_FLOAT, NULL, - CPL_IO_CREATE); - cpl_test_eq_error( error, CPL_ERROR_FILE_IO ); + error = + cpl_imagelist_save(imlist2, ".", CPL_TYPE_FLOAT, NULL, CPL_IO_CREATE); + cpl_test_eq_error(error, CPL_ERROR_FILE_IO); remove(file); - error = cpl_imagelist_save(imlist2, file, CPL_TYPE_FLOAT, NULL, - CPL_IO_APPEND); - cpl_test_eq_error( error, CPL_ERROR_FILE_IO ); + error = + cpl_imagelist_save(imlist2, file, CPL_TYPE_FLOAT, NULL, CPL_IO_APPEND); + cpl_test_eq_error(error, CPL_ERROR_FILE_IO); - error = cpl_imagelist_save(imlist2, file, CPL_TYPE_FLOAT, NULL, + error = cpl_imagelist_save(imlist2, file, CPL_TYPE_FLOAT, NULL, CPL_IO_CREATE | CPL_IO_EXTEND); - cpl_test_eq_error( error, CPL_ERROR_ILLEGAL_INPUT ); + cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); - error = cpl_imagelist_save(imlist2, file, CPL_TYPE_FLOAT, NULL, + error = cpl_imagelist_save(imlist2, file, CPL_TYPE_FLOAT, NULL, CPL_IO_CREATE | CPL_IO_EXTEND | CPL_IO_APPEND); - cpl_test_eq_error( error, CPL_ERROR_ILLEGAL_INPUT ); + cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); image = cpl_image_new(IMAGESZ, IMAGESZ, CPL_TYPE_INT); - cpl_test_nonnull( image ); + cpl_test_nonnull(image); error = cpl_imagelist_set(imlist2, image, 0); - cpl_test_eq_error( error, CPL_ERROR_TYPE_MISMATCH ); - cpl_test_zero( cpl_imagelist_is_uniform(imlist2) ); - cpl_test_eq( cpl_imagelist_get_size(imlist2), NIMAGES ); + cpl_test_eq_error(error, CPL_ERROR_TYPE_MISMATCH); + cpl_test_zero(cpl_imagelist_is_uniform(imlist2)); + cpl_test_eq(cpl_imagelist_get_size(imlist2), NIMAGES); cpl_image_delete(image); - image = cpl_image_new(IMAGESZ/2, IMAGESZ, CPL_TYPE_INT); - cpl_test_nonnull( image ); + image = cpl_image_new(IMAGESZ / 2, IMAGESZ, CPL_TYPE_INT); + cpl_test_nonnull(image); error = cpl_imagelist_set(imlist2, image, 0); - cpl_test_eq_error( error, CPL_ERROR_INCOMPATIBLE_INPUT ); - cpl_test_zero( cpl_imagelist_is_uniform(imlist2) ); - cpl_test_eq( cpl_imagelist_get_size(imlist2), NIMAGES ); - - nullimg = cpl_imagelist_get(imlist2, NIMAGES+1); - cpl_test_error( CPL_ERROR_ACCESS_OUT_OF_RANGE ); - cpl_test_null( nullimg ); + cpl_test_eq_error(error, CPL_ERROR_INCOMPATIBLE_INPUT); + cpl_test_zero(cpl_imagelist_is_uniform(imlist2)); + cpl_test_eq(cpl_imagelist_get_size(imlist2), NIMAGES); - cpl_test_zero( cpl_imagelist_is_uniform(imlist2) ); - cpl_test_eq( cpl_imagelist_get_size(imlist2), NIMAGES ); + nullimg = cpl_imagelist_get(imlist2, NIMAGES + 1); + cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_test_null(nullimg); + + cpl_test_zero(cpl_imagelist_is_uniform(imlist2)); + cpl_test_eq(cpl_imagelist_get_size(imlist2), NIMAGES); cpl_imagelist_empty(imlist2); /* Test cpl_imagelist_unset() */ /* Imagelist with 1 image */ error = cpl_imagelist_set(imlist2, image, 0); - cpl_test_eq_error( error, CPL_ERROR_NONE ); + cpl_test_eq_error(error, CPL_ERROR_NONE); /* Must be allowed to replace it w. image of different size/type */ - image = cpl_image_new(IMAGESZ, IMAGESZ/2, CPL_TYPE_DOUBLE); - cpl_test_nonnull( image ); + image = cpl_image_new(IMAGESZ, IMAGESZ / 2, CPL_TYPE_DOUBLE); + cpl_test_nonnull(image); error = cpl_imagelist_set(imlist2, image, 0); - cpl_test_eq_error( error, CPL_ERROR_NONE ); + cpl_test_eq_error(error, CPL_ERROR_NONE); cpl_imagelist_delete(imlist2); @@ -355,26 +353,26 @@ error = cpl_imagelist_set(imlista, image, i + NIMAGES); cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_zero( cpl_imagelist_is_uniform(imlista) ); - cpl_test_eq( cpl_imagelist_get_size(imlista), i+1 + NIMAGES ); - cpl_test_eq_ptr( cpl_imagelist_get_const(imlista, i + NIMAGES), - cpl_imagelist_get_const(imlista, i) ); + cpl_test_zero(cpl_imagelist_is_uniform(imlista)); + cpl_test_eq(cpl_imagelist_get_size(imlista), i + 1 + NIMAGES); + cpl_test_eq_ptr(cpl_imagelist_get_const(imlista, i + NIMAGES), + cpl_imagelist_get_const(imlista, i)); } /* Test cpl_imagelist_save() */ cpl_msg_info("", "Save the image list to %s", file); - error = cpl_imagelist_save(imlist, file, CPL_TYPE_FLOAT, NULL, - CPL_IO_CREATE); + error = + cpl_imagelist_save(imlist, file, CPL_TYPE_FLOAT, NULL, CPL_IO_CREATE); cpl_test_eq_error(error, CPL_ERROR_NONE); cpl_test_fits(file); - cpl_test_zero( cpl_fits_count_extensions(file)); + cpl_test_zero(cpl_fits_count_extensions(file)); next = 0; - error = cpl_imagelist_save(imlist, file, CPL_TYPE_FLOAT, NULL, - CPL_IO_EXTEND); + error = + cpl_imagelist_save(imlist, file, CPL_TYPE_FLOAT, NULL, CPL_IO_EXTEND); cpl_test_eq_error(error, CPL_ERROR_NONE); cpl_test_fits(file); - cpl_test_eq( cpl_fits_count_extensions(file), ++next); + cpl_test_eq(cpl_fits_count_extensions(file), ++next); /* cpl_image_load(): Test loading of NAXIS=3 data (DFS09929) */ image = cpl_image_load(file, CPL_TYPE_UNSPECIFIED, 0, 0); @@ -386,19 +384,19 @@ /* Test cpl_imagelist_load() handling of negative extension */ nulllist = cpl_imagelist_load(file, CPL_TYPE_INT, -1); - cpl_test_error( CPL_ERROR_ILLEGAL_INPUT ); - cpl_test_null( nulllist ); + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); + cpl_test_null(nulllist); /* Append error test */ - error = cpl_imagelist_save(imlist, file, CPL_TYPE_DOUBLE, NULL, - CPL_IO_APPEND); + error = + cpl_imagelist_save(imlist, file, CPL_TYPE_DOUBLE, NULL, CPL_IO_APPEND); cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); - image = cpl_image_new(IMAGESZ+1,IMAGESZ+1, CPL_TYPE_FLOAT); + image = cpl_image_new(IMAGESZ + 1, IMAGESZ + 1, CPL_TYPE_FLOAT); imlist2 = cpl_imagelist_new(); cpl_imagelist_set(imlist2, image, 0); - error = cpl_imagelist_save(imlist2, file, CPL_TYPE_FLOAT, NULL, - CPL_IO_APPEND); + error = + cpl_imagelist_save(imlist2, file, CPL_TYPE_FLOAT, NULL, CPL_IO_APPEND); cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); cpl_imagelist_delete(imlist2); @@ -410,11 +408,11 @@ cpl_test_imagelist_abs(imlist, imlist2, 10.0 * FLT_EPSILON); cpl_imagelist_delete(imlist2); - error = cpl_imagelist_save(imlist, file, CPL_TYPE_FLOAT, NULL, - CPL_IO_APPEND); + error = + cpl_imagelist_save(imlist, file, CPL_TYPE_FLOAT, NULL, CPL_IO_APPEND); cpl_test_eq_error(error, CPL_ERROR_NONE); cpl_test_fits(file); - cpl_test_eq( cpl_fits_count_extensions(file), next); + cpl_test_eq(cpl_fits_count_extensions(file), next); imlist2 = cpl_imagelist_load(file, CPL_TYPE_UNSPECIFIED, 1); cpl_test_error(CPL_ERROR_NONE); @@ -422,11 +420,11 @@ cpl_test_imagelist_abs(imlista, imlist2, 10.0 * FLT_EPSILON); cpl_imagelist_delete(imlista); - + error = cpl_imagelist_erase(imlist, eraser); cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_zero( cpl_imagelist_is_uniform(imlist) ); - cpl_test_eq( 2*cpl_imagelist_get_size(imlist), NIMAGES ); + cpl_test_zero(cpl_imagelist_is_uniform(imlist)); + cpl_test_eq(2 * cpl_imagelist_get_size(imlist), NIMAGES); cpl_imagelist_empty(imlist); /* Test cpl_imagelist_unset() */ cpl_imagelist_delete(imlist); @@ -442,8 +440,8 @@ cpl_imagelist_delete(imlist); imlist = cpl_imagelist_load_window(file, CPL_TYPE_UNSPECIFIED, 0, - IMAGESZ/4, IMAGESZ/4, - 3*IMAGESZ/4, 3*IMAGESZ/4); + IMAGESZ / 4, IMAGESZ / 4, + 3 * IMAGESZ / 4, 3 * IMAGESZ / 4); cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(imlist); @@ -456,33 +454,33 @@ cpl_msg_info("", "Load image list as type DOUBLE"); imlist = cpl_imagelist_load(file, CPL_TYPE_DOUBLE, 0); - cpl_test_nonnull( imlist ); - cpl_test_zero( cpl_imagelist_is_uniform(imlist) ); - cpl_test_eq( cpl_imagelist_get_size(imlist), NIMAGES ); + cpl_test_nonnull(imlist); + cpl_test_zero(cpl_imagelist_is_uniform(imlist)); + cpl_test_eq(cpl_imagelist_get_size(imlist), NIMAGES); error = cpl_imagelist_set(imlist, cpl_imagelist_get(imlist, 0), 2); cpl_test_eq_error(error, CPL_ERROR_NONE); error = cpl_imagelist_erase(imlist, eraser); cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_zero( cpl_imagelist_is_uniform(imlist) ); - cpl_test_eq( 2*cpl_imagelist_get_size(imlist), NIMAGES ); + cpl_test_zero(cpl_imagelist_is_uniform(imlist)); + cpl_test_eq(2 * cpl_imagelist_get_size(imlist), NIMAGES); cpl_imagelist_empty(imlist); /* Test cpl_imagelist_unset() */ cpl_imagelist_delete(imlist); - + /* Test cpl_imagelist_load() */ cpl_msg_info("", "Load image list as type FLOAT"); imlist = cpl_imagelist_load(file, CPL_TYPE_FLOAT, 0); - cpl_test_nonnull( imlist ); - cpl_test_zero( cpl_imagelist_is_uniform(imlist) ); - cpl_test_eq( cpl_imagelist_get_size(imlist), NIMAGES ); + cpl_test_nonnull(imlist); + cpl_test_zero(cpl_imagelist_is_uniform(imlist)); + cpl_test_eq(cpl_imagelist_get_size(imlist), NIMAGES); error = cpl_imagelist_erase(imlist, eraser); cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_zero( cpl_imagelist_is_uniform(imlist) ); - cpl_test_eq( 2*cpl_imagelist_get_size(imlist), NIMAGES ); + cpl_test_zero(cpl_imagelist_is_uniform(imlist)); + cpl_test_eq(2 * cpl_imagelist_get_size(imlist), NIMAGES); cpl_imagelist_empty(imlist); /* Test cpl_imagelist_unset() */ cpl_imagelist_delete(imlist); @@ -491,67 +489,70 @@ cpl_msg_info("", "Load image list as type INTEGER"); imlist = cpl_imagelist_load(file, CPL_TYPE_INT, 0); - cpl_test_nonnull( imlist ); - cpl_test_zero( cpl_imagelist_is_uniform(imlist) ); - cpl_test_eq( cpl_imagelist_get_size(imlist), NIMAGES ); + cpl_test_nonnull(imlist); + cpl_test_zero(cpl_imagelist_is_uniform(imlist)); + cpl_test_eq(cpl_imagelist_get_size(imlist), NIMAGES); error = cpl_imagelist_erase(imlist, eraser); cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_zero( cpl_imagelist_is_uniform(imlist) ); - cpl_test_eq( 2*cpl_imagelist_get_size(imlist), NIMAGES ); + cpl_test_zero(cpl_imagelist_is_uniform(imlist)); + cpl_test_eq(2 * cpl_imagelist_get_size(imlist), NIMAGES); cpl_imagelist_empty(imlist); /* Test cpl_imagelist_unset() */ cpl_imagelist_delete(imlist); /* Test cpl_imagelist_load_window() */ cpl_msg_info("", "Load image list as type DOUBLE from a window"); - imlist = cpl_imagelist_load_window(file, CPL_TYPE_DOUBLE, 0, IMAGESZ/4, - IMAGESZ/4, 3*IMAGESZ/4, 3*IMAGESZ/4); + imlist = cpl_imagelist_load_window(file, CPL_TYPE_DOUBLE, 0, IMAGESZ / 4, + IMAGESZ / 4, 3 * IMAGESZ / 4, + 3 * IMAGESZ / 4); - cpl_test_nonnull( imlist ); - cpl_test_zero( cpl_imagelist_is_uniform(imlist) ); - cpl_test_eq( cpl_imagelist_get_size(imlist), NIMAGES ); + cpl_test_nonnull(imlist); + cpl_test_zero(cpl_imagelist_is_uniform(imlist)); + cpl_test_eq(cpl_imagelist_get_size(imlist), NIMAGES); error = cpl_imagelist_erase(imlist, eraser); cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_zero( cpl_imagelist_is_uniform(imlist) ); - cpl_test_eq( 2*cpl_imagelist_get_size(imlist), NIMAGES ); + cpl_test_zero(cpl_imagelist_is_uniform(imlist)); + cpl_test_eq(2 * cpl_imagelist_get_size(imlist), NIMAGES); cpl_imagelist_empty(imlist); /* Test cpl_imagelist_unset() */ cpl_imagelist_delete(imlist); - + /* Test cpl_imagelist_load_window() */ cpl_msg_info("", "Load image list as type FLOAT from a window"); - imlist = cpl_imagelist_load_window(file, CPL_TYPE_FLOAT, 0, IMAGESZ/4, - IMAGESZ/4, 3*IMAGESZ/4, 3*IMAGESZ/4); + imlist = cpl_imagelist_load_window(file, CPL_TYPE_FLOAT, 0, IMAGESZ / 4, + IMAGESZ / 4, 3 * IMAGESZ / 4, + 3 * IMAGESZ / 4); - cpl_test_nonnull( imlist ); - cpl_test_zero( cpl_imagelist_is_uniform(imlist) ); - cpl_test_eq( cpl_imagelist_get_size(imlist), NIMAGES ); + cpl_test_nonnull(imlist); + cpl_test_zero(cpl_imagelist_is_uniform(imlist)); + cpl_test_eq(cpl_imagelist_get_size(imlist), NIMAGES); error = cpl_imagelist_erase(imlist, eraser); cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_zero( cpl_imagelist_is_uniform(imlist) ); - cpl_test_eq( 2*cpl_imagelist_get_size(imlist), NIMAGES ); + cpl_test_zero(cpl_imagelist_is_uniform(imlist)); + cpl_test_eq(2 * cpl_imagelist_get_size(imlist), NIMAGES); cpl_imagelist_empty(imlist); /* Test cpl_imagelist_unset() */ cpl_imagelist_delete(imlist); - + /* Test cpl_imagelist_load_window() */ cpl_msg_info("", "Load image list as type INTEGER from a window"); - imlist = cpl_imagelist_load_window(file, CPL_TYPE_INT, 0, IMAGESZ/4, - IMAGESZ/4, 3*IMAGESZ/4, 3*IMAGESZ/4); + imlist = cpl_imagelist_load_window(file, CPL_TYPE_INT, 0, IMAGESZ / 4, + IMAGESZ / 4, 3 * IMAGESZ / 4, + 3 * IMAGESZ / 4); - cpl_test_nonnull( imlist ); - cpl_test_zero( cpl_imagelist_is_uniform(imlist) ); - cpl_test_eq( cpl_imagelist_get_size(imlist), NIMAGES ); + cpl_test_nonnull(imlist); + cpl_test_zero(cpl_imagelist_is_uniform(imlist)); + cpl_test_eq(cpl_imagelist_get_size(imlist), NIMAGES); error = cpl_imagelist_erase(imlist, eraser); cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_zero( cpl_imagelist_is_uniform(imlist) ); - cpl_test_eq( 2*cpl_imagelist_get_size(imlist), NIMAGES ); + cpl_test_zero(cpl_imagelist_is_uniform(imlist)); + cpl_test_eq(2 * cpl_imagelist_get_size(imlist), NIMAGES); /* Clean up */ @@ -566,13 +567,15 @@ if (cpl_msg_get_level() <= CPL_MSG_INFO) { cpl_imagelist_save_compression_bench(256, 256, 12, 256); - } else { + } + else { cpl_imagelist_save_compression_bench(IMAGESZ, IMAGESZ, 32, 3); } - cpl_test_zero( remove(FILENAME) ); + cpl_test_zero(remove(FILENAME)); - if (stream != stdout) cpl_test_zero( fclose(stream) ); + if (stream != stdout) + cpl_test_zero(fclose(stream)); /* End of tests */ return cpl_test_end(0); @@ -586,31 +589,31 @@ @see cpl_imagelist_save() */ /*----------------------------------------------------------------------------*/ -static void cpl_imagelist_save_compression_test(void) +static void +cpl_imagelist_save_compression_test(void) { /* Default CFITSIO quantization parameter for lossy floating point compression is q = 1, reducing precision to 4.08 % */ const double prec = 0.0408; const double maxval = 255.0; - const cpl_type imtypes[] = {CPL_TYPE_DOUBLE, CPL_TYPE_FLOAT, - CPL_TYPE_INT}; - const size_t ntyp = sizeof(imtypes)/sizeof(imtypes[0]); - size_t ityp; + const cpl_type imtypes[] = { CPL_TYPE_DOUBLE, CPL_TYPE_FLOAT, + CPL_TYPE_INT }; + const size_t ntyp = sizeof(imtypes) / sizeof(imtypes[0]); + size_t ityp; /* Saving with different image types, bitpix and compression types */ - for (ityp = 0; ityp < ntyp; ityp++) - { - const cpl_type bpps[] = {CPL_TYPE_UCHAR, CPL_TYPE_SHORT, - CPL_TYPE_USHORT, CPL_TYPE_INT, - CPL_TYPE_FLOAT, CPL_TYPE_DOUBLE, - CPL_TYPE_UNSPECIFIED}; - const size_t nbpp = sizeof(bpps)/sizeof(bpps[0]); - size_t ibpp; + for (ityp = 0; ityp < ntyp; ityp++) { + const cpl_type bpps[] = { CPL_TYPE_UCHAR, CPL_TYPE_SHORT, + CPL_TYPE_USHORT, CPL_TYPE_INT, + CPL_TYPE_FLOAT, CPL_TYPE_DOUBLE, + CPL_TYPE_UNSPECIFIED }; + const size_t nbpp = sizeof(bpps) / sizeof(bpps[0]); + size_t ibpp; const cpl_type imtype = imtypes[ityp]; - cpl_image * img = cpl_image_new(IMAGESZ, IMAGESZ, imtype); - cpl_imagelist * imglist = cpl_imagelist_new(); + cpl_image *img = cpl_image_new(IMAGESZ, IMAGESZ, imtype); + cpl_imagelist *imglist = cpl_imagelist_new(); cpl_error_code error; @@ -620,27 +623,24 @@ error = cpl_imagelist_set(imglist, img, 0); cpl_test_eq_error(error, CPL_ERROR_NONE); - for (ibpp = 0; ibpp < nbpp; ibpp++) - { - const cpl_io_type comp_meths[] = {CPL_IO_COMPRESS_GZIP, - CPL_IO_COMPRESS_RICE, - CPL_IO_COMPRESS_HCOMPRESS, - CPL_IO_COMPRESS_PLIO}; - const size_t ncomp = sizeof(comp_meths)/sizeof(comp_meths[0]); + for (ibpp = 0; ibpp < nbpp; ibpp++) { + const cpl_io_type comp_meths[] = { CPL_IO_COMPRESS_GZIP, + CPL_IO_COMPRESS_RICE, + CPL_IO_COMPRESS_HCOMPRESS, + CPL_IO_COMPRESS_PLIO }; + const size_t ncomp = sizeof(comp_meths) / sizeof(comp_meths[0]); size_t icomp; - const int bitpix = - cpl_tools_get_bpp(bpps[ibpp] == CPL_TYPE_UNSPECIFIED - ? imtype : bpps[ibpp]); + const int bitpix = cpl_tools_get_bpp( + bpps[ibpp] == CPL_TYPE_UNSPECIFIED ? imtype : bpps[ibpp]); int ext = 0; error = cpl_imagelist_save(imglist, FILENAME, bpps[ibpp], NULL, - CPL_IO_CREATE); + CPL_IO_CREATE); cpl_test_eq_error(error, CPL_ERROR_NONE); /* Tests with compression */ - for(icomp = 0; icomp < ncomp; icomp++) - { + for (icomp = 0; icomp < ncomp; icomp++) { const cpl_io_type comp_method = comp_meths[icomp]; /* The compression method flag must be non-zero */ @@ -661,47 +661,54 @@ CPL_IO_APPEND | comp_method); cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); - for(size_t icomp2 = 0; icomp2 < icomp; icomp2++) { + for (size_t icomp2 = 0; icomp2 < icomp; icomp2++) { const cpl_io_type comp_method2 = comp_meths[icomp2]; - error = cpl_imagelist_save(imglist, FILENAME, bpps[ibpp], NULL, - CPL_IO_EXTEND | comp_method - | comp_method2); + error = + cpl_imagelist_save(imglist, FILENAME, bpps[ibpp], NULL, + CPL_IO_EXTEND | comp_method | + comp_method2); cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); - error = cpl_imagelist_save(imglist, FILENAME, bpps[ibpp], NULL, - CPL_IO_APPEND | comp_method - | comp_method2); + error = + cpl_imagelist_save(imglist, FILENAME, bpps[ibpp], NULL, + CPL_IO_APPEND | comp_method | + comp_method2); cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); - for(size_t icomp3 = 0; icomp3 < icomp2; icomp3++) { + for (size_t icomp3 = 0; icomp3 < icomp2; icomp3++) { const cpl_io_type comp_method3 = comp_meths[icomp3]; - error = cpl_imagelist_save(imglist, FILENAME, bpps[ibpp], NULL, - CPL_IO_EXTEND | comp_method - | comp_method2 | comp_method3); + error = + cpl_imagelist_save(imglist, FILENAME, bpps[ibpp], + NULL, + CPL_IO_EXTEND | comp_method | + comp_method2 | comp_method3); cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); - error = cpl_imagelist_save(imglist, FILENAME, bpps[ibpp], NULL, - CPL_IO_APPEND | comp_method - | comp_method2 | comp_method3); + error = + cpl_imagelist_save(imglist, FILENAME, bpps[ibpp], + NULL, + CPL_IO_APPEND | comp_method | + comp_method2 | comp_method3); cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); } - } - error = cpl_imagelist_save(imglist, FILENAME, bpps[ibpp], NULL, + error = + cpl_imagelist_save(imglist, FILENAME, bpps[ibpp], NULL, CPL_IO_EXTEND | CPL_IO_COMPRESS_GZIP | - CPL_IO_COMPRESS_RICE| - CPL_IO_COMPRESS_HCOMPRESS | - CPL_IO_COMPRESS_PLIO); + CPL_IO_COMPRESS_RICE | + CPL_IO_COMPRESS_HCOMPRESS | + CPL_IO_COMPRESS_PLIO); cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); - error = cpl_imagelist_save(imglist, FILENAME, bpps[ibpp], NULL, + error = + cpl_imagelist_save(imglist, FILENAME, bpps[ibpp], NULL, CPL_IO_APPEND | CPL_IO_COMPRESS_GZIP | - CPL_IO_COMPRESS_RICE| - CPL_IO_COMPRESS_HCOMPRESS | - CPL_IO_COMPRESS_PLIO); + CPL_IO_COMPRESS_RICE | + CPL_IO_COMPRESS_HCOMPRESS | + CPL_IO_COMPRESS_PLIO); cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); @@ -713,24 +720,23 @@ /* Currently, compression only allowed with integer data */ bitpix < 0 || #endif - /* FP-data compresses only to int, float or double */ + /* FP-data compresses only to int, float or double */ /* RICE-compression supports only int, float or double */ /* In fact, this applies to all compressions... */ abs(bitpix) < 32) { cpl_test_eq_error(error, CPL_ERROR_UNSUPPORTED_MODE); - - } else { - - cpl_image * img_load; + } + else { + cpl_image *img_load; cpl_test_eq_error(error, CPL_ERROR_NONE); cpl_test_fits(FILENAME); ext++; - cpl_test_eq( cpl_fits_count_extensions(FILENAME), ext); + cpl_test_eq(cpl_fits_count_extensions(FILENAME), ext); - img_load = cpl_image_load(FILENAME, CPL_TYPE_UNSPECIFIED, - 0, ext); + img_load = + cpl_image_load(FILENAME, CPL_TYPE_UNSPECIFIED, 0, ext); cpl_test_error(CPL_ERROR_NONE); cpl_test_eq(cpl_image_get_size_x(img_load), IMAGESZ); @@ -738,7 +744,8 @@ if (imtype == CPL_TYPE_INT) { cpl_test_image_abs(img, img_load, 0.0); - } else if (cpl_image_get_type(img_load) != CPL_TYPE_INT) { + } + else if (cpl_image_get_type(img_load) != CPL_TYPE_INT) { cpl_test_image_abs(img, img_load, prec * maxval); } cpl_image_delete(img_load); @@ -753,7 +760,7 @@ } cpl_imagelist_delete(imglist); } -} +} /*----------------------------------------------------------------------------*/ /** @@ -766,12 +773,14 @@ @see cpl_image_save() */ /*----------------------------------------------------------------------------*/ -static void cpl_imagelist_save_compression_bench(cpl_size nx, cpl_size ny, - cpl_size nz, cpl_size nr) +static void +cpl_imagelist_save_compression_bench(cpl_size nx, + cpl_size ny, + cpl_size nz, + cpl_size nr) { - - cpl_image * img = cpl_image_new(nx, ny, CPL_TYPE_INT); - cpl_imagelist * imglist = cpl_imagelist_new(); + cpl_image *img = cpl_image_new(nx, ny, CPL_TYPE_INT); + cpl_imagelist *imglist = cpl_imagelist_new(); cpl_error_code error; cpl_size i; double tsum = 0.0; @@ -785,22 +794,22 @@ } error = cpl_image_save(NULL, FILENAME, CPL_TYPE_UNSPECIFIED, NULL, - CPL_IO_CREATE); + CPL_IO_CREATE); cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_imagelist_save(imglist, FILENAME, CPL_TYPE_UNSPECIFIED, - NULL, CPL_IO_EXTEND | CPL_IO_COMPRESS_RICE); + error = cpl_imagelist_save(imglist, FILENAME, CPL_TYPE_UNSPECIFIED, NULL, + CPL_IO_EXTEND | CPL_IO_COMPRESS_RICE); cpl_test_eq_error(error, CPL_ERROR_NONE); cpl_test_fits(FILENAME); - cpl_test_eq( cpl_fits_count_extensions(FILENAME), 1); + cpl_test_eq(cpl_fits_count_extensions(FILENAME), 1); #ifdef _OPENMP #pragma omp parallel for private(i) reduction(+ : tsum) #endif for (i = 0; i < nr; i++) { const double t0 = cpl_test_get_walltime(); - cpl_imagelist * imgload = cpl_imagelist_load(FILENAME, - CPL_TYPE_UNSPECIFIED, 1); + cpl_imagelist *imgload = + cpl_imagelist_load(FILENAME, CPL_TYPE_UNSPECIFIED, 1); const double t1 = cpl_test_get_walltime() - t0; int j; @@ -815,11 +824,11 @@ cpl_imagelist_delete(imgload); } - cpl_msg_info(cpl_func, "Time to load Rice-compressed image list %d X %d " - "X %d %d times [s]: %g", (int)nx, (int)ny, (int)nz, (int)nr, - tsum); + cpl_msg_info(cpl_func, + "Time to load Rice-compressed image list %d X %d " + "X %d %d times [s]: %g", + (int)nx, (int)ny, (int)nz, (int)nr, tsum); cpl_imagelist_unwrap(imglist); cpl_image_delete(img); } - diff -Nru cpl-7.1.4+ds/cplcore/tests/cpl_image_resample-test.c cpl-7.2.2+ds/cplcore/tests/cpl_image_resample-test.c --- cpl-7.1.4+ds/cplcore/tests/cpl_image_resample-test.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/tests/cpl_image_resample-test.c 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -36,7 +36,7 @@ -----------------------------------------------------------------------------*/ #ifndef IMAGESZ -#define IMAGESZ 64 +#define IMAGESZ 64 #endif #define PIXRANGE 100 @@ -45,14 +45,19 @@ Private function prototypes -----------------------------------------------------------------------------*/ -static void check_kernel(cpl_image *, const cpl_image *, const cpl_image *, - const cpl_polynomial *, const cpl_polynomial *, - cpl_vector *, double, double); +static void check_kernel(cpl_image *, + const cpl_image *, + const cpl_image *, + const cpl_polynomial *, + const cpl_polynomial *, + cpl_vector *, + double, + double); static void cpl_image_warp_polynomial_test_turn(int, int, cpl_vector *, double); -static void cpl_image_warp_polynomial_test_shift(int, int, int, int, - cpl_vector *, double); +static void +cpl_image_warp_polynomial_test_shift(int, int, int, int, cpl_vector *, double); static void cpl_image_extract_subsample_test(void); static void cpl_image_get_interpolated_test(void); @@ -60,41 +65,42 @@ /*----------------------------------------------------------------------------- Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { - cpl_image * imf; - cpl_image * imd; - cpl_image * imtmp; - cpl_image * dx; - cpl_image * dy; - cpl_image * warped; - cpl_polynomial * px; - cpl_polynomial * py; - cpl_vector * xyprofile; - const double xyradius = 2.2; /* 2.3 gives much higher rounding ? */ - cpl_size expo[2]; - FILE * stream; - cpl_size i, j; + cpl_image *imf; + cpl_image *imd; + cpl_image *imtmp; + cpl_image *dx; + cpl_image *dy; + cpl_image *warped; + cpl_polynomial *px; + cpl_polynomial *py; + cpl_vector *xyprofile; + const double xyradius = 2.2; /* 2.3 gives much higher rounding ? */ + cpl_size expo[2]; + FILE *stream; + cpl_size i, j; cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); /* Insert tests below */ - stream = cpl_msg_get_level() > CPL_MSG_INFO - ? fopen("/dev/null", "a") : stdout; + stream = + cpl_msg_get_level() > CPL_MSG_INFO ? fopen("/dev/null", "a") : stdout; - cpl_test_nonnull( stream ); + cpl_test_nonnull(stream); cpl_image_get_interpolated_test(); cpl_image_extract_subsample_test(); xyprofile = cpl_vector_new(1 + xyradius * CPL_KERNEL_TABSPERPIX); - cpl_test_nonnull( xyprofile); + cpl_test_nonnull(xyprofile); - for (i = 1-IMAGESZ; i < IMAGESZ; i += IMAGESZ/2) { - for (j = 1-IMAGESZ; j < IMAGESZ; j += IMAGESZ/2) { + for (i = 1 - IMAGESZ; i < IMAGESZ; i += IMAGESZ / 2) { + for (j = 1 - IMAGESZ; j < IMAGESZ; j += IMAGESZ / 2) { cpl_image_warp_polynomial_test_shift(IMAGESZ, IMAGESZ, i, j, xyprofile, xyradius); } @@ -102,9 +108,9 @@ cpl_image_warp_polynomial_test_turn(IMAGESZ, IMAGESZ, xyprofile, xyradius); - cpl_test_zero( cpl_vector_set_size(xyprofile, CPL_KERNEL_DEF_SAMPLES)); - cpl_test_zero( cpl_vector_fill_kernel_profile(xyprofile, CPL_KERNEL_DEFAULT, - CPL_KERNEL_DEF_WIDTH) ); + cpl_test_zero(cpl_vector_set_size(xyprofile, CPL_KERNEL_DEF_SAMPLES)); + cpl_test_zero(cpl_vector_fill_kernel_profile(xyprofile, CPL_KERNEL_DEFAULT, + CPL_KERNEL_DEF_WIDTH)); /* Define the following polynomials : */ /* x = 0.945946.u + -0.135135.v + -6.75676 */ @@ -131,7 +137,7 @@ expo[0] = 0; expo[1] = 0; cpl_polynomial_set_coeff(py, expo, -12.8378); - + /* First create a test image */ cpl_msg_info("", "Create double and float test images."); imd = cpl_image_fill_test_create(IMAGESZ, IMAGESZ); @@ -139,44 +145,46 @@ cpl_msg_info("", "Apply the polynomial warping to the DOUBLE image."); /* Apply polynomial warping on the DOUBLE image */ - warped = cpl_image_new(IMAGESZ/3, IMAGESZ*2, CPL_TYPE_DOUBLE); - cpl_test_nonnull( warped ); + warped = cpl_image_new(IMAGESZ / 3, IMAGESZ * 2, CPL_TYPE_DOUBLE); + cpl_test_nonnull(warped); - cpl_test_zero( cpl_image_warp_polynomial(warped, imd, px, py, xyprofile, 2, - xyprofile, 2) ); + cpl_test_zero(cpl_image_warp_polynomial(warped, imd, px, py, xyprofile, 2, + xyprofile, 2)); cpl_image_multiply_scalar(warped, 0.0); - cpl_test_zero( cpl_image_fill_jacobian_polynomial(warped, px, py) ); + cpl_test_zero(cpl_image_fill_jacobian_polynomial(warped, px, py)); cpl_image_multiply_scalar(warped, 0.0); /* Apply polynomial warping on the FLOAT image */ - cpl_test_zero( cpl_image_warp_polynomial(warped, imf, px, py, xyprofile, 2, - xyprofile, 2) ); + cpl_test_zero(cpl_image_warp_polynomial(warped, imf, px, py, xyprofile, 2, + xyprofile, 2)); cpl_image_multiply_scalar(warped, 0.0); - + cpl_polynomial_delete(px); cpl_polynomial_delete(py); - + /* Test cpl_image_warp() */ dx = cpl_image_new(cpl_image_get_size_x(warped), - cpl_image_get_size_y(warped), CPL_TYPE_DOUBLE); + cpl_image_get_size_y(warped), CPL_TYPE_DOUBLE); dy = cpl_image_new(cpl_image_get_size_x(warped), - cpl_image_get_size_y(warped), CPL_TYPE_DOUBLE); + cpl_image_get_size_y(warped), CPL_TYPE_DOUBLE); cpl_image_add_scalar(dx, 1.0); cpl_image_add_scalar(dy, -2.0); - - cpl_test_zero( cpl_image_warp(warped, imd, dx, dy, xyprofile, 2, xyprofile, 2)); + + cpl_test_zero( + cpl_image_warp(warped, imd, dx, dy, xyprofile, 2, xyprofile, 2)); cpl_image_multiply_scalar(warped, 0.0); - cpl_test_zero( cpl_image_fill_jacobian(warped, dx, dy) ); + cpl_test_zero(cpl_image_fill_jacobian(warped, dx, dy)); cpl_image_multiply_scalar(warped, 0.0); - cpl_test_zero( cpl_image_warp(warped, imf, dx, dy, xyprofile, 2, xyprofile, 2)); + cpl_test_zero( + cpl_image_warp(warped, imf, dx, dy, xyprofile, 2, xyprofile, 2)); cpl_image_multiply_scalar(warped, 0.0); - + cpl_image_delete(dx); cpl_image_delete(dy); cpl_image_delete(warped); @@ -185,15 +193,16 @@ /* Test sub-sampling on imf and imd */ cpl_msg_info("", "Sub sample imf and imd"); imtmp = cpl_image_extract_subsample(imf, 2, 2); - cpl_test_nonnull( imtmp ); + cpl_test_nonnull(imtmp); cpl_image_delete(imtmp); imtmp = cpl_image_extract_subsample(imd, 2, 2); - cpl_test_nonnull( imtmp ); + cpl_test_nonnull(imtmp); cpl_image_delete(imtmp); cpl_image_delete(imf); cpl_image_delete(imd); - if (stream != stdout) cpl_test_zero( fclose(stream) ); + if (stream != stdout) + cpl_test_zero(fclose(stream)); return cpl_test_end(0); } @@ -215,39 +224,39 @@ */ /*----------------------------------------------------------------------------*/ -static void check_kernel(cpl_image * temp, - const cpl_image * ref, - const cpl_image * warp, - const cpl_polynomial * px, - const cpl_polynomial * py, - cpl_vector * xyprofile, - double xyradius, double imtol) +static void +check_kernel(cpl_image *temp, + const cpl_image *ref, + const cpl_image *warp, + const cpl_polynomial *px, + const cpl_polynomial *py, + cpl_vector *xyprofile, + double xyradius, + double imtol) { - /* These kernels preserve the actual pixel-values */ - cpl_kernel kernels[] = {CPL_KERNEL_TANH, CPL_KERNEL_SINC, CPL_KERNEL_SINC2, - CPL_KERNEL_LANCZOS, CPL_KERNEL_HANN, - CPL_KERNEL_NEAREST, - CPL_KERNEL_HAMMING}; + cpl_kernel kernels[] = { CPL_KERNEL_TANH, CPL_KERNEL_SINC, + CPL_KERNEL_SINC2, CPL_KERNEL_LANCZOS, + CPL_KERNEL_HANN, CPL_KERNEL_NEAREST, + CPL_KERNEL_HAMMING }; /* FIXME: Integer tolerence higher (1 for int) for CPL_KERNEL_TANH */ - const double imtol0 = cpl_image_get_type(ref) == CPL_TYPE_INT ? 1.0 - : imtol * 10.0 * PIXRANGE; + const double imtol0 = + cpl_image_get_type(ref) == CPL_TYPE_INT ? 1.0 : imtol * 10.0 * PIXRANGE; int ityp; - for (ityp = 0; ityp < (int)(sizeof(kernels)/sizeof(kernels[0])); ityp++) { + for (ityp = 0; ityp < (int)(sizeof(kernels) / sizeof(kernels[0])); ityp++) { const double tol = ityp ? imtol : imtol0; cpl_msg_debug(cpl_func, "%g-tol transform with kernel-radius (%d): %g", tol, kernels[ityp], xyradius); - cpl_test_zero(cpl_vector_fill_kernel_profile(xyprofile, kernels[ityp], - xyradius)); + cpl_test_zero( + cpl_vector_fill_kernel_profile(xyprofile, kernels[ityp], xyradius)); cpl_test_zero(cpl_image_warp_polynomial(temp, warp, px, py, xyprofile, xyradius, xyprofile, xyradius)); cpl_test_image_abs(temp, ref, xyradius * xyradius * tol); - } return; } @@ -268,20 +277,23 @@ */ /*----------------------------------------------------------------------------*/ static void -cpl_image_warp_polynomial_test_shift(int nx, int ny, int dx, int dy, - cpl_vector * xyprofile, double xyradius) +cpl_image_warp_polynomial_test_shift(int nx, + int ny, + int dx, + int dy, + cpl_vector *xyprofile, + double xyradius) { + const cpl_type imtypes[] = { CPL_TYPE_DOUBLE, CPL_TYPE_FLOAT, + CPL_TYPE_INT }; - const cpl_type imtypes[] = {CPL_TYPE_DOUBLE, CPL_TYPE_FLOAT, - CPL_TYPE_INT}; + const double imtol[] = { DBL_EPSILON, FLT_EPSILON, 0.0 }; - const double imtol[] = {DBL_EPSILON, FLT_EPSILON, 0.0}; - - cpl_polynomial * px = cpl_polynomial_new(2); - cpl_polynomial * py = cpl_polynomial_new(2); - cpl_mask * mask = NULL; - cpl_size expo[2]; - int ityp; + cpl_polynomial *px = cpl_polynomial_new(2); + cpl_polynomial *py = cpl_polynomial_new(2); + cpl_mask *mask = NULL; + cpl_size expo[2]; + int ityp; /* The shift: (u,v) = (x-dx, y-dy) */ @@ -297,16 +309,16 @@ cpl_polynomial_set_coeff(py, expo, 1.0); - for (ityp = 0; ityp < (int)(sizeof(imtypes)/sizeof(imtypes[0])); ityp++) { + for (ityp = 0; ityp < (int)(sizeof(imtypes) / sizeof(imtypes[0])); ityp++) { + cpl_image *noise = cpl_image_new(nx, ny, imtypes[ityp]); + cpl_image *trans = cpl_image_new(nx, ny, imtypes[ityp]); + cpl_image *temp = cpl_image_new(nx, ny, imtypes[ityp]); - cpl_image * noise = cpl_image_new(nx, ny, imtypes[ityp]); - cpl_image * trans = cpl_image_new(nx, ny, imtypes[ityp]); - cpl_image * temp = cpl_image_new(nx, ny, imtypes[ityp]); - - cpl_msg_info(cpl_func, "%d x %d shift a %d x %d %s image with a " - "polynomial-warp", dx, dy, nx, ny, - cpl_type_get_name(imtypes[ityp])); + cpl_msg_info(cpl_func, + "%d x %d shift a %d x %d %s image with a " + "polynomial-warp", + dx, dy, nx, ny, cpl_type_get_name(imtypes[ityp])); cpl_test_zero(cpl_image_fill_noise_uniform(noise, -PIXRANGE, PIXRANGE)); @@ -318,8 +330,8 @@ mask = cpl_mask_threshold_image_create(noise, -0.2 * PIXRANGE, 0.2 * PIXRANGE); count = cpl_mask_count(mask); - } while (count == 0 || count == nx*ny); - cpl_msg_info(cpl_func, "Rejecting %d of %d pixels", count, nx*ny); + } while (count == 0 || count == nx * ny); + cpl_msg_info(cpl_func, "Rejecting %d of %d pixels", count, nx * ny); cpl_test_zero(cpl_image_reject_from_mask(noise, mask)); } @@ -327,13 +339,12 @@ cpl_test_zero(cpl_image_shift(trans, dx, dy)); - check_kernel(temp, trans, noise, px, py, - xyprofile, xyradius, imtol[ityp]); + check_kernel(temp, trans, noise, px, py, xyprofile, xyradius, + imtol[ityp]); cpl_image_delete(temp); cpl_image_delete(noise); cpl_image_delete(trans); - } cpl_mask_delete(mask); @@ -356,26 +367,27 @@ */ /*----------------------------------------------------------------------------*/ static void -cpl_image_warp_polynomial_test_turn(int nx, int ny, cpl_vector * xyprofile, +cpl_image_warp_polynomial_test_turn(int nx, + int ny, + cpl_vector *xyprofile, double xyradius) { + const cpl_type imtypes[] = { CPL_TYPE_DOUBLE, CPL_TYPE_FLOAT, + CPL_TYPE_INT }; - const cpl_type imtypes[] = {CPL_TYPE_DOUBLE, CPL_TYPE_FLOAT, - CPL_TYPE_INT}; - - const double imtol[] = {DBL_EPSILON, FLT_EPSILON, 0.0}; + const double imtol[] = { DBL_EPSILON, FLT_EPSILON, 0.0 }; - cpl_polynomial * px = cpl_polynomial_new(2); - cpl_polynomial * py = cpl_polynomial_new(2); - cpl_mask * mask = NULL; - cpl_size expo[2]; - int ityp; + cpl_polynomial *px = cpl_polynomial_new(2); + cpl_polynomial *py = cpl_polynomial_new(2); + cpl_mask *mask = NULL; + cpl_size expo[2]; + int ityp; /* The rotation: (u,v) = (y, N+1-x) */ expo[0] = 0; expo[1] = 0; - cpl_polynomial_set_coeff(py, expo, 1+IMAGESZ); + cpl_polynomial_set_coeff(py, expo, 1 + IMAGESZ); expo[0] = 0; expo[1] = 1; cpl_polynomial_set_coeff(px, expo, 1); @@ -384,15 +396,16 @@ cpl_polynomial_set_coeff(py, expo, -1); - for (ityp = 0; ityp < (int)(sizeof(imtypes)/sizeof(imtypes[0])); ityp++) { - - cpl_image * noise = cpl_image_new(nx, ny, imtypes[ityp]); - cpl_image * trans = cpl_image_new(nx, ny, imtypes[ityp]); - cpl_image * temp = cpl_image_new(nx, ny, imtypes[ityp]); + for (ityp = 0; ityp < (int)(sizeof(imtypes) / sizeof(imtypes[0])); ityp++) { + cpl_image *noise = cpl_image_new(nx, ny, imtypes[ityp]); + cpl_image *trans = cpl_image_new(nx, ny, imtypes[ityp]); + cpl_image *temp = cpl_image_new(nx, ny, imtypes[ityp]); - cpl_msg_info(cpl_func, "Turn a %d x %d %s image with a polynomial-" - "warp", nx, ny, cpl_type_get_name(imtypes[ityp])); + cpl_msg_info(cpl_func, + "Turn a %d x %d %s image with a polynomial-" + "warp", + nx, ny, cpl_type_get_name(imtypes[ityp])); cpl_test_zero(cpl_image_fill_noise_uniform(noise, -PIXRANGE, PIXRANGE)); @@ -404,8 +417,8 @@ mask = cpl_mask_threshold_image_create(noise, -0.2 * PIXRANGE, 0.2 * PIXRANGE); count = cpl_mask_count(mask); - } while (count == 0 || count == nx*ny); - cpl_msg_info(cpl_func, "Rejecting %d of %d pixels", count, nx*ny); + } while (count == 0 || count == nx * ny); + cpl_msg_info(cpl_func, "Rejecting %d of %d pixels", count, nx * ny); cpl_test_zero(cpl_image_reject_from_mask(noise, mask)); } @@ -419,7 +432,6 @@ cpl_image_delete(temp); cpl_image_delete(noise); cpl_image_delete(trans); - } cpl_mask_delete(mask); @@ -439,29 +451,24 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_image_extract_subsample_test(void) +static void +cpl_image_extract_subsample_test(void) { cpl_image *carlo; cpl_image *subcarlo; cpl_image *expected; - int data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, - 10,11,12,13,14,15,16,17,18,19, - 20,21,22,23,24,25,26,27,28,29, - 30,31,32,33,34,35,36,37,38,39, - 40,41,42,43,44,45,46,47,48,49, - 50,51,52,53,54,55,56,57,58,59}; - - int exp_data[] = {0, 2, 4, 6, 8, - 20,22,24,26,28, - 40,42,44,46,48}; + int data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, + 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, + 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59 }; + + int exp_data[] = { 0, 2, 4, 6, 8, 20, 22, 24, 26, 28, 40, 42, 44, 46, 48 }; - int exp_data2[] = {0, 3, 6, 9, - 40,43,46,49}; + int exp_data2[] = { 0, 3, 6, 9, 40, 43, 46, 49 }; - int exp_data3[] = {102,120,138, - 222,240,258}; + int exp_data3[] = { 102, 120, 138, 222, 240, 258 }; - int exp_data4[] = {264, 328}; + int exp_data4[] = { 264, 328 }; cpl_error_code error; @@ -520,7 +527,6 @@ cpl_image_delete(subcarlo); cpl_test_eq_ptr(cpl_image_unwrap(expected), exp_data4); cpl_test_eq_ptr(cpl_image_unwrap(carlo), data); - } /*----------------------------------------------------------------------------*/ @@ -532,58 +538,62 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_image_get_interpolated_test(void) +static void +cpl_image_get_interpolated_test(void) { - - const cpl_type ttype[] = {CPL_TYPE_INT, CPL_TYPE_FLOAT, CPL_TYPE_DOUBLE}; - const cpl_size tsize[] = {50, 500}; - const double value1[] = {2, 3}; - const double value2[] = {5, 7}; - const double mean = (value1[0] + value1[1] + value2[0] + value2[1])/4.0; - const double txyrad[] = {-1.0, 0.0, CPL_KERNEL_DEF_WIDTH, 24.0, 100.0, - 240.0}; - cpl_vector * xyprofile = cpl_vector_new(CPL_KERNEL_DEF_SAMPLES); + const cpl_type ttype[] = { CPL_TYPE_INT, CPL_TYPE_FLOAT, CPL_TYPE_DOUBLE }; + const cpl_size tsize[] = { 50, 500 }; + const double value1[] = { 2, 3 }; + const double value2[] = { 5, 7 }; + const double mean = (value1[0] + value1[1] + value2[0] + value2[1]) / 4.0; + const double txyrad[] = { -1.0, 0.0, CPL_KERNEL_DEF_WIDTH, + 24.0, 100.0, 240.0 }; + cpl_vector *xyprofile = cpl_vector_new(CPL_KERNEL_DEF_SAMPLES); size_t isize; - for (isize = 0; isize < sizeof(tsize)/sizeof(tsize[0]); isize++) { + for (isize = 0; isize < sizeof(tsize) / sizeof(tsize[0]); isize++) { size_t itype; const cpl_size imsize = tsize[isize]; - const double c = 0.5 + (double)imsize / 2.0; + const double c = 0.5 + (double)imsize / 2.0; cpl_size i, j; cpl_error_code error; - cpl_image * dimage = cpl_image_new(imsize, imsize, CPL_TYPE_DOUBLE); + cpl_image *dimage = cpl_image_new(imsize, imsize, CPL_TYPE_DOUBLE); cpl_test_nonnull(dimage); for (j = 0; j < imsize; j++) { - const double * pvalue = 2 * j < imsize ? value1 : value2; + const double *pvalue = 2 * j < imsize ? value1 : value2; for (i = 0; i < imsize; i++) { - (void)cpl_image_set(dimage, i+1, j+1, - pvalue[2 * i < imsize ? 0 : 1]); + (void)cpl_image_set(dimage, i + 1, j + 1, + pvalue[2 * i < imsize ? 0 : 1]); } } - for (itype = 0; itype < sizeof(ttype)/sizeof(ttype[0]); itype++) { + for (itype = 0; itype < sizeof(ttype) / sizeof(ttype[0]); itype++) { size_t ixyrad; const cpl_type imtype = ttype[itype]; - cpl_image * image = imtype == CPL_TYPE_DOUBLE ? dimage : - cpl_image_cast(dimage, imtype); + cpl_image *image = imtype == CPL_TYPE_DOUBLE + ? dimage + : cpl_image_cast(dimage, imtype); - for (ixyrad = 0; ixyrad < sizeof(txyrad)/sizeof(txyrad[0]); + for (ixyrad = 0; ixyrad < sizeof(txyrad) / sizeof(txyrad[0]); ixyrad++) { const double xyradius = txyrad[ixyrad]; double value, confidence; - cpl_msg_info(cpl_func, "Interpolating from %d X %d %s-image, " - "r=%g", (int)imsize, (int)imsize, + cpl_msg_info(cpl_func, + "Interpolating from %d X %d %s-image, " + "r=%g", + (int)imsize, (int)imsize, cpl_type_get_name(imtype), xyradius); - + error = cpl_vector_fill_kernel_profile(xyprofile, CPL_KERNEL_DEFAULT, xyradius); - cpl_test_eq_error(error, xyradius > 0.0 ? CPL_ERROR_NONE - : CPL_ERROR_ILLEGAL_INPUT); + cpl_test_eq_error(error, xyradius > 0.0 + ? CPL_ERROR_NONE + : CPL_ERROR_ILLEGAL_INPUT); value = cpl_image_get_interpolated(image, c, c, xyprofile, xyradius, xyprofile, @@ -593,10 +603,12 @@ cpl_test_abs(value, mean, 4.0 * xyradius * DBL_EPSILON); if (xyradius < imsize) { cpl_test_abs(confidence, 1.0, 30.0 * DBL_EPSILON); - } else { + } + else { cpl_test_abs(confidence, 1.0, xyradius * DBL_EPSILON); } - } else { + } + else { cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); } } diff -Nru cpl-7.1.4+ds/cplcore/tests/cpl_io_fits-test.c cpl-7.2.2+ds/cplcore/tests/cpl_io_fits-test.c --- cpl-7.1.4+ds/cplcore/tests/cpl_io_fits-test.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/tests/cpl_io_fits-test.c 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -54,21 +54,47 @@ Function prototypes ----------------------------------------------------------------------------*/ +static void cpl_io_fits_test_all(const char *); static void cpl_io_fits_test_many(int); -static void cpl_io_fits_test_fulldisk_table(const char*); +static void cpl_io_fits_test_fulldisk_table(const char *); /*----------------------------------------------------------------------------- Main -----------------------------------------------------------------------------*/ -int main(int argc, char *argv[]) +int +main(int argc, char *argv[]) { - cpl_boolean do_bench; - int next = NEXT; - int j; + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + if (cpl_io_fits_is_enabled()) { + cpl_io_fits_test_all(argc == 2 ? argv[1] : NULL); + } + else { + cpl_msg_warning(cpl_func, + "Skipping tests: CPL FITS caching is not enabled"); + cpl_msg_warning(cpl_func, "To test CPL FITS caching rerun with " + "environment variable: CPL_IO_MODE=1"); + } + /* End of tests */ + return cpl_test_end(0); +} - cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief Perform all tests + @param Root string, or NULL + @return void + */ +/*----------------------------------------------------------------------------*/ +void +cpl_io_fits_test_all(const char *root) +{ + cpl_boolean do_bench; + cpl_size max_files; + int next = NEXT; + int j; do_bench = cpl_msg_get_level() <= CPL_MSG_INFO ? CPL_TRUE : CPL_FALSE; @@ -77,19 +103,23 @@ /* Insert tests below */ - if (argc == 2) { - cpl_io_fits_test_fulldisk_table(argv[1]); + max_files = cpl_io_get_max_open(); + cpl_test_error(CPL_ERROR_NONE); + + cpl_msg_info(cpl_func, "Maximum number of files kept open: %d", + (int)max_files); + + if (root != NULL) { + cpl_io_fits_test_fulldisk_table(root); } - cpl_io_fits_test_many(do_bench - ? 1 + CPL_IO_FITS_MAX_OPEN - : 1 + CPL_IO_FITS_MAX_OPEN/3); + cpl_io_fits_test_many(1 + max_files); #ifdef _OPENMP #pragma omp parallel for private(j) #endif for (j = 0; j < NFILE; j++) { - char * filename = cpl_sprintf(BASENAME "-%d.fits", j + 1); + char *filename = cpl_sprintf(BASENAME "-%d.fits", j + 1); int base = j * next * 10; /* Assume at most 10 load-loops */ int i; @@ -102,8 +132,8 @@ #endif for (i = 0; i <= next; i++) { cpl_error_code myerror; - cpl_image * myimage = cpl_image_new(1, 1, CPL_TYPE_INT); - cpl_propertylist * plist = cpl_propertylist_new(); + cpl_image *myimage = cpl_image_new(1, 1, CPL_TYPE_INT); + cpl_propertylist *plist = cpl_propertylist_new(); myerror = cpl_propertylist_append_int(plist, "MYINT", i + base); cpl_test_eq_error(myerror, CPL_ERROR_NONE); @@ -121,7 +151,6 @@ cpl_test_eq_error(myerror, CPL_ERROR_NONE); cpl_image_delete(myimage); cpl_propertylist_delete(plist); - } cpl_test_eq(cpl_fits_count_extensions(filename), next); @@ -132,8 +161,8 @@ #endif for (i = 0; i <= next; i++) { int is_bad; - cpl_image * myimage = cpl_image_load(filename, CPL_TYPE_INT, 0, i); - cpl_propertylist * plist; + cpl_image *myimage = cpl_image_load(filename, CPL_TYPE_INT, 0, i); + cpl_propertylist *plist; cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(myimage); @@ -162,8 +191,8 @@ #endif for (i = 0; i <= next; i++) { cpl_error_code myerror; - cpl_image * myimage = cpl_image_new(1, 1, CPL_TYPE_INT); - cpl_propertylist * plist = cpl_propertylist_new(); + cpl_image *myimage = cpl_image_new(1, 1, CPL_TYPE_INT); + cpl_propertylist *plist = cpl_propertylist_new(); myerror = cpl_propertylist_append_int(plist, "MYINT", i + base); cpl_test_eq_error(myerror, CPL_ERROR_NONE); @@ -175,15 +204,14 @@ #pragma omp ordered #endif { - myerror = cpl_image_save(myimage, filename, CPL_TYPE_INT, plist, - (i & 1) ? CPL_IO_EXTEND - : CPL_IO_CREATE); + myerror = + cpl_image_save(myimage, filename, CPL_TYPE_INT, plist, + (i & 1) ? CPL_IO_EXTEND : CPL_IO_CREATE); } cpl_test_eq_error(myerror, CPL_ERROR_NONE); cpl_image_delete(myimage); cpl_propertylist_delete(plist); - } cpl_test_eq(cpl_fits_count_extensions(filename), next & 1); @@ -194,14 +222,14 @@ #endif for (i = 0; i <= (next & 1); i++) { int is_bad; - cpl_image * myimage = cpl_image_load(filename, CPL_TYPE_INT, 0, i); - cpl_propertylist * plist; + cpl_image *myimage = cpl_image_load(filename, CPL_TYPE_INT, 0, i); + cpl_propertylist *plist; cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(myimage); - cpl_test_eq(cpl_image_get(myimage, 1, 1, &is_bad), i + (next & ~1) - + base); + cpl_test_eq(cpl_image_get(myimage, 1, 1, &is_bad), + i + (next & ~1) + base); cpl_test_zero(is_bad); cpl_image_delete(myimage); @@ -213,7 +241,6 @@ i + (next & ~1) + base); cpl_propertylist_delete(plist); - } base += next; @@ -226,8 +253,8 @@ for (i = 0; i <= next; i++) { int is_bad; cpl_error_code myerror; - cpl_image * myimage = cpl_image_new(1, 1, CPL_TYPE_INT); - cpl_propertylist * plist = cpl_propertylist_new(); + cpl_image *myimage = cpl_image_new(1, 1, CPL_TYPE_INT); + cpl_propertylist *plist = cpl_propertylist_new(); myerror = cpl_propertylist_append_int(plist, "MYINT", i + base); cpl_test_eq_error(myerror, CPL_ERROR_NONE); @@ -255,7 +282,6 @@ cpl_propertylist_delete(plist); plist = cpl_propertylist_load(filename, i); cpl_test_error(CPL_ERROR_NONE); - } cpl_test_nonnull(myimage); @@ -267,7 +293,6 @@ cpl_image_delete(myimage); cpl_propertylist_delete(plist); - } cpl_test_eq(cpl_fits_count_extensions(filename), next); @@ -283,56 +308,54 @@ #ifdef _OPENMP #pragma omp ordered #endif - { - if (i & 1) { - if (i > 2) { - /* Read the previously written extension */ - const int i2 = i / 2 - 1; - int is_bad; - cpl_propertylist * plist; - cpl_image * myimage = cpl_image_load(filename, - CPL_TYPE_INT, - 0, i2); - - cpl_test_error(CPL_ERROR_NONE); - cpl_test_nonnull(myimage); - cpl_test_eq(cpl_image_get(myimage, 1, 1, &is_bad), - i2 + base); - cpl_test_zero(is_bad); - cpl_image_delete(myimage); - - plist = cpl_propertylist_load(filename, i2); - cpl_test_error(CPL_ERROR_NONE); - - cpl_test_nonnull(plist); - cpl_test_eq(cpl_propertylist_get_int(plist, "MYINT"), - i2 + base); - - cpl_propertylist_delete(plist); - } - - } else { - cpl_error_code myerror; - cpl_image * myimage = cpl_image_new(1, 1, CPL_TYPE_INT); - cpl_propertylist * plist = cpl_propertylist_new(); - - myerror = cpl_propertylist_append_int(plist, "MYINT", - i/2 + base); - cpl_test_eq_error(myerror, CPL_ERROR_NONE); - - myerror = cpl_image_add_scalar(myimage, i/2 + base); - cpl_test_eq_error(myerror, CPL_ERROR_NONE); - - cpl_test_eq(i, i); - myerror = cpl_image_save(myimage, filename, - CPL_TYPE_INT, plist, - i ? CPL_IO_EXTEND : CPL_IO_CREATE); - - cpl_test_eq_error(myerror, CPL_ERROR_NONE); + { + if (i & 1) { + if (i > 2) { + /* Read the previously written extension */ + const int i2 = i / 2 - 1; + int is_bad; + cpl_propertylist *plist; + cpl_image *myimage = + cpl_image_load(filename, CPL_TYPE_INT, 0, i2); + + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(myimage); + cpl_test_eq(cpl_image_get(myimage, 1, 1, &is_bad), + i2 + base); + cpl_test_zero(is_bad); cpl_image_delete(myimage); + + plist = cpl_propertylist_load(filename, i2); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_nonnull(plist); + cpl_test_eq(cpl_propertylist_get_int(plist, "MYINT"), + i2 + base); + cpl_propertylist_delete(plist); } } + else { + cpl_error_code myerror; + cpl_image *myimage = cpl_image_new(1, 1, CPL_TYPE_INT); + cpl_propertylist *plist = cpl_propertylist_new(); + + myerror = + cpl_propertylist_append_int(plist, "MYINT", i / 2 + base); + cpl_test_eq_error(myerror, CPL_ERROR_NONE); + + myerror = cpl_image_add_scalar(myimage, i / 2 + base); + cpl_test_eq_error(myerror, CPL_ERROR_NONE); + + cpl_test_eq(i, i); + myerror = cpl_image_save(myimage, filename, CPL_TYPE_INT, plist, + i ? CPL_IO_EXTEND : CPL_IO_CREATE); + + cpl_test_eq_error(myerror, CPL_ERROR_NONE); + cpl_image_delete(myimage); + cpl_propertylist_delete(plist); + } + } cpl_test_eq(cpl_fits_count_extensions(filename), next); @@ -346,8 +369,8 @@ for (i = 0; i <= next; i++) { int is_bad; cpl_error_code myerror; - cpl_image * myimage = cpl_image_new(1, 1, CPL_TYPE_INT); - cpl_propertylist * plist = cpl_propertylist_new(); + cpl_image *myimage = cpl_image_new(1, 1, CPL_TYPE_INT); + cpl_propertylist *plist = cpl_propertylist_new(); myerror = cpl_propertylist_append_int(plist, "MYINT", i + base); cpl_test_eq_error(myerror, CPL_ERROR_NONE); @@ -359,9 +382,9 @@ #pragma omp ordered #endif { - myerror = cpl_image_save(myimage, filename, CPL_TYPE_INT, plist, - (i & 1) ? CPL_IO_EXTEND - : CPL_IO_CREATE); + myerror = + cpl_image_save(myimage, filename, CPL_TYPE_INT, plist, + (i & 1) ? CPL_IO_EXTEND : CPL_IO_CREATE); cpl_test_eq_error(myerror, CPL_ERROR_NONE); /* Make sure to jump around between the extensions */ @@ -375,7 +398,6 @@ cpl_propertylist_delete(plist); plist = cpl_propertylist_load(filename, i & 1); cpl_test_error(CPL_ERROR_NONE); - } cpl_test_nonnull(myimage); @@ -387,28 +409,24 @@ cpl_test_eq(cpl_propertylist_get_int(plist, "MYINT"), i + base); cpl_propertylist_delete(plist); - } cpl_test_eq(cpl_fits_count_extensions(filename), next & 1); - cpl_free((void*)filename); + cpl_free((void *)filename); } - if (cpl_fits_get_mode() | CPL_FITS_START_CACHING) { + if (cpl_fits_get_mode() & CPL_FITS_START_CACHING) { cpl_error_code myerror; myerror = cpl_fits_set_mode(CPL_FITS_STOP_CACHING); cpl_test_eq_error(myerror, CPL_ERROR_NONE); } for (j = 0; j < NFILE; j++) { - char * filename = cpl_sprintf(BASENAME "-%d.fits", j + 1); + char *filename = cpl_sprintf(BASENAME "-%d.fits", j + 1); cpl_test_zero(remove(filename)); cpl_free(filename); } - - /* End of tests */ - return cpl_test_end(0); } @@ -419,17 +437,17 @@ @return void */ /*----------------------------------------------------------------------------*/ -static void cpl_io_fits_test_many(int n) +static void +cpl_io_fits_test_many(int n) { - - cpl_propertylist * plist = cpl_propertylist_new(); + cpl_propertylist *plist = cpl_propertylist_new(); const cpl_fits_mode iomode = cpl_fits_get_mode(); cpl_msg_info(cpl_func, "Testing I/O-mode %d <=> %d with %d file(s)", (int)iomode, (int)CPL_FITS_START_CACHING, n); for (int i = 0; i < n; i++) { - char * filename = cpl_sprintf(BASENAME "-%d.fits", i + 1); + char *filename = cpl_sprintf(BASENAME "-%d.fits", i + 1); cpl_error_code myerror; myerror = cpl_propertylist_update_int(plist, "MYINT", i); cpl_test_eq_error(myerror, CPL_ERROR_NONE); @@ -445,23 +463,22 @@ cpl_test_eq(cpl_propertylist_get_int(plist, "MYINT"), i); cpl_free(filename); - } cpl_propertylist_delete(plist); - if (iomode | CPL_FITS_START_CACHING) { + if (iomode & CPL_FITS_START_CACHING) { cpl_error_code myerror; myerror = cpl_fits_set_mode(CPL_FITS_STOP_CACHING); cpl_test_eq_error(myerror, CPL_ERROR_NONE); } for (int i = 0; i < n; i++) { - char * filename = cpl_sprintf(BASENAME "-%d.fits", i + 1); + char *filename = cpl_sprintf(BASENAME "-%d.fits", i + 1); cpl_test_zero(remove(filename)); cpl_free(filename); } - if (iomode | CPL_FITS_START_CACHING) { + if (iomode & CPL_FITS_STOP_CACHING) { cpl_error_code myerror; myerror = cpl_fits_set_mode(iomode); cpl_test_eq_error(myerror, CPL_ERROR_NONE); @@ -471,15 +488,17 @@ /*----------------------------------------------------------------------------*/ /** + @internal @brief Test I/O on a user specified file system (of limited size) @param root The name of the file system to fill up @return void */ /*----------------------------------------------------------------------------*/ -static void cpl_io_fits_test_fulldisk_table(const char* root) +static void +cpl_io_fits_test_fulldisk_table(const char *root) { - cpl_table* mytab = cpl_table_new(1000); - char* filename = cpl_sprintf("%s/" BASENAME ".fits", root); + cpl_table *mytab = cpl_table_new(1000); + char *filename = cpl_sprintf("%s/" BASENAME ".fits", root); const cpl_fits_mode iomode = cpl_fits_get_mode(); cpl_error_code code; @@ -506,14 +525,17 @@ if (cpl_test_get_failed() > 0) { cpl_msg_warning(cpl_func, "Test failed, not deleting file:: %s", filename); - } else if (remove(filename) != 0) { - cpl_msg_info(cpl_func, "The failure-test file has already been deleted: " - "%s", filename); + } + else if (remove(filename) != 0) { + cpl_msg_info(cpl_func, + "The failure-test file has already been deleted: " + "%s", + filename); } cpl_table_delete(mytab); - if (iomode | CPL_FITS_START_CACHING) { + if (iomode & CPL_FITS_START_CACHING) { cpl_error_code myerror; myerror = cpl_fits_set_mode(CPL_FITS_STOP_CACHING); cpl_test_eq_error(myerror, CPL_ERROR_NONE); @@ -521,7 +543,7 @@ cpl_test_zero(remove(filename)); - if (iomode | CPL_FITS_START_CACHING) { + if (iomode & CPL_FITS_STOP_CACHING) { cpl_error_code myerror; myerror = cpl_fits_set_mode(iomode); cpl_test_eq_error(myerror, CPL_ERROR_NONE); diff -Nru cpl-7.1.4+ds/cplcore/tests/cpl_mask-test.c cpl-7.2.2+ds/cplcore/tests/cpl_mask-test.c --- cpl-7.1.4+ds/cplcore/tests/cpl_mask-test.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/tests/cpl_mask-test.c 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -49,8 +49,8 @@ -----------------------------------------------------------------------------*/ static cpl_error_code cpl_mask_shift_bf(cpl_mask *, int, int, cpl_binary); -static cpl_error_code cpl_mask_shift_filter(cpl_mask *, int, int, - cpl_filter_mode); +static cpl_error_code +cpl_mask_shift_filter(cpl_mask *, int, int, cpl_filter_mode); static void cpl_mask_flip_turn_test(const cpl_mask *); static void cpl_mask_shift_test(int, int); static void cpl_mask_test(cpl_boolean); @@ -69,24 +69,46 @@ static cpl_error_code cpl_mask_fill_test(cpl_mask *, double); static cpl_error_code cpl_mask_fill_border(cpl_mask *, int, int, cpl_binary); -static cpl_error_code cpl_mask_filter_bf(cpl_mask *, const cpl_mask *, - const cpl_mask *, cpl_filter_mode, +static cpl_error_code cpl_mask_filter_bf(cpl_mask *, + const cpl_mask *, + const cpl_mask *, + cpl_filter_mode, cpl_border_mode); -static -void cpl_mask_erosion_bf(cpl_binary *, const cpl_binary *, const cpl_binary *, - int, int, int, int, cpl_border_mode); -static -void cpl_mask_dilation_bf(cpl_binary *, const cpl_binary *, const cpl_binary *, - int, int, int, int, cpl_border_mode); -static -void cpl_mask_opening_bf(cpl_binary *, const cpl_binary *, const cpl_binary *, - int, int, int, int, cpl_border_mode); -static -void cpl_mask_closing_bf(cpl_binary *, const cpl_binary *, const cpl_binary *, - int, int, int, int, cpl_border_mode); +static void cpl_mask_erosion_bf(cpl_binary *, + const cpl_binary *, + const cpl_binary *, + int, + int, + int, + int, + cpl_border_mode); +static void cpl_mask_dilation_bf(cpl_binary *, + const cpl_binary *, + const cpl_binary *, + int, + int, + int, + int, + cpl_border_mode); +static void cpl_mask_opening_bf(cpl_binary *, + const cpl_binary *, + const cpl_binary *, + int, + int, + int, + int, + cpl_border_mode); +static void cpl_mask_closing_bf(cpl_binary *, + const cpl_binary *, + const cpl_binary *, + int, + int, + int, + int, + cpl_border_mode); -static double tshift = 0.0; +static double tshift = 0.0; static double tshiftbf = 0.0; static double tshiftfl = 0.0; static double tshiftb2 = 0.0; @@ -94,40 +116,38 @@ /*----------------------------------------------------------------------------- Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { - cpl_mask * bin1, - * bin2, - * bin1_dup; - cpl_mask * null; - cpl_image * labels1, - * labels2; - int count; - cpl_size nb_objs1, - nb_objs2; - const cpl_size new_pos[] = {1,2,3,4}; - const int nsize = IMAGESZ; - cpl_binary * bins; - cpl_error_code error; - cpl_boolean do_bench; - FILE * stream; + cpl_mask *bin1, *bin2, *bin1_dup; + cpl_mask *null; + cpl_image *labels1, *labels2; + int count; + cpl_size nb_objs1, nb_objs2; + const cpl_size new_pos[] = { 2, 3, 4, 1 }; /* Cyclic "shift" */ + const int nsize = IMAGESZ; + cpl_binary *bins; + cpl_error_code error; + cpl_boolean do_bench; + FILE *stream; cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); do_bench = cpl_msg_get_level() <= CPL_MSG_INFO ? CPL_TRUE : CPL_FALSE; - stream = cpl_msg_get_level() > CPL_MSG_INFO - ? fopen("/dev/null", "a") : stdout; + stream = + cpl_msg_get_level() > CPL_MSG_INFO ? fopen("/dev/null", "a") : stdout; /* Insert tests below */ - cpl_test_nonnull( stream ); + cpl_test_nonnull(stream); cpl_mask_count_window_test(7, 7); if (do_bench) { cpl_mask_count_bench(1024, 1000); - } else { + } + else { cpl_mask_count_bench(10, 1); } cpl_mask_filter_test_schalkoff(); @@ -143,7 +163,7 @@ cpl_mask_filter_bench(do_bench ? 1024 : 32, do_bench ? 3 : 1, 2, 3, 3, 3); cpl_mask_filter_test_matrix(2); - cpl_mask_filter_test_matrix(do_bench ? IMAGESZ/4 : 32); + cpl_mask_filter_test_matrix(do_bench ? IMAGESZ / 4 : 32); cpl_mask_test(do_bench); @@ -160,16 +180,16 @@ cpl_mask_shift_test(MASKSZ, MASKSZ); if (do_bench) { - cpl_mask_shift_test(IMAGESZ/4, 4 * MASKSZ); + cpl_mask_shift_test(IMAGESZ / 4, 4 * MASKSZ); } - cpl_msg_info(cpl_func, "Time to shift [s]: %g <=> %g (brute force)", - tshift, tshiftbf); + cpl_msg_info(cpl_func, "Time to shift [s]: %g <=> %g (brute force)", tshift, + tshiftbf); cpl_msg_info(cpl_func, "Time to filter shift [s]: %g <=> %g (brute force)", tshiftfl, tshiftb2); /* Create test image */ - cpl_msg_info("","Create a %dx%d test image", nsize, nsize); + cpl_msg_info("", "Create a %dx%d test image", nsize, nsize); bin1 = cpl_mask_new(nsize, nsize); cpl_test_nonnull(bin1); @@ -209,7 +229,8 @@ cpl_mask_set(bin1, 1, 1, CPL_BINARY_1); cpl_test_eq(cpl_mask_count(bin1), count + 1); cpl_test_eq(cpl_mask_count_window(bin1, 1, 1, 1, 1), 1); - } else { + } + else { cpl_test_eq(cpl_mask_count_window(bin1, 1, 1, 1, 1), 1); cpl_mask_set(bin1, 1, 1, CPL_BINARY_0); cpl_test_eq(cpl_mask_count(bin1), count - 1); @@ -228,10 +249,10 @@ error = cpl_mask_set(bin1, 1, 0, CPL_BINARY_1); cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); - error = cpl_mask_set(bin1, 1, 1+nsize, CPL_BINARY_1); + error = cpl_mask_set(bin1, 1, 1 + nsize, CPL_BINARY_1); cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); - error = cpl_mask_set(bin1, 1+nsize, 1, CPL_BINARY_1); + error = cpl_mask_set(bin1, 1 + nsize, 1, CPL_BINARY_1); cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); error = cpl_mask_set(bin1, 1, 1, (cpl_binary)-1); @@ -240,12 +261,12 @@ /* Compute number of selected pixels */ cpl_test_eq(cpl_mask_count(bin1), cpl_mask_count_window(bin1, 1, 1, nsize, nsize)); - + /* Test cpl_mask_duplicate() */ bin1_dup = cpl_mask_duplicate(bin1); cpl_test_eq_mask(bin1, bin1_dup); cpl_test_eq(cpl_mask_is_empty(bin1), cpl_mask_is_empty(bin1_dup)); - cpl_test_eq(cpl_mask_count(bin1), cpl_mask_count(bin1_dup)); + cpl_test_eq(cpl_mask_count(bin1), cpl_mask_count(bin1_dup)); /* Test error handling of cpl_mask_collapse_create() */ null = cpl_mask_collapse_create(NULL, 0); @@ -263,11 +284,11 @@ /* Test cpl_mask_turn() */ /* Rotate the mask all the way around */ - cpl_test(cpl_mask_turn(bin1, 9) == CPL_ERROR_NONE); - cpl_test(cpl_mask_turn(bin1, 6) == CPL_ERROR_NONE); + cpl_test(cpl_mask_turn(bin1, 9) == CPL_ERROR_NONE); + cpl_test(cpl_mask_turn(bin1, 6) == CPL_ERROR_NONE); cpl_test(cpl_mask_turn(bin1, -13) == CPL_ERROR_NONE); - cpl_test(cpl_mask_turn(bin1, 10) == CPL_ERROR_NONE); - cpl_test(cpl_mask_turn(bin1, 4) == CPL_ERROR_NONE); + cpl_test(cpl_mask_turn(bin1, 10) == CPL_ERROR_NONE); + cpl_test(cpl_mask_turn(bin1, 4) == CPL_ERROR_NONE); cpl_test_eq_mask(bin1, bin1_dup); /* Compare to its copy */ cpl_test_zero(cpl_mask_xor(bin1_dup, bin1)); @@ -291,37 +312,37 @@ cpl_test_eq_mask(bin1, bin1_dup); cpl_mask_delete(bin1_dup); - bin1_dup = cpl_mask_load_window(FILENAME, 0, 1, 1, 1, nsize, nsize ); + bin1_dup = cpl_mask_load_window(FILENAME, 0, 1, 1, 1, nsize, nsize); cpl_test_error(CPL_ERROR_NONE); cpl_test_eq_mask(bin1, bin1_dup); cpl_mask_delete(bin1_dup); - cpl_test_zero( remove(FILENAME) ); + cpl_test_zero(remove(FILENAME)); /* Labelize the binary maps */ labels1 = cpl_image_labelise_mask_create(bin1, &nb_objs1); cpl_test_nonnull(labels1); - cpl_msg_info("","Labelize bin1 ---> %" CPL_SIZE_FORMAT " objects found", + cpl_msg_info("", "Labelize bin1 ---> %" CPL_SIZE_FORMAT " objects found", nb_objs1); labels2 = cpl_image_labelise_mask_create(bin2, &nb_objs2); cpl_test_nonnull(labels2); - cpl_msg_info("","Labelize bin2 ---> %" CPL_SIZE_FORMAT " objects found", + cpl_msg_info("", "Labelize bin2 ---> %" CPL_SIZE_FORMAT " objects found", nb_objs2); - + /* sprintf(outname, "labelized1.fits"); */ /* cpl_image_save(labels1, outname, CPL_TYPE_FLOAT, NULL, CPL_IO_CREATE); */ /* sprintf(outname, "labelized2.fits"); */ /* cpl_image_save(labels2, outname, CPL_TYPE_FLOAT, NULL, CPL_IO_CREATE); */ - + cpl_image_delete(labels1); cpl_image_delete(labels2); - /* The following tests need to be done on a non-empty mask */ + /* The following tests need to be done on a non-empty mask */ cpl_test_zero(cpl_mask_is_empty(bin2)); cpl_test_zero(cpl_mask_set(bin1, IMAGESZ, IMAGESZ, CPL_BINARY_1)); @@ -331,13 +352,13 @@ cpl_test_zero(cpl_mask_and(bin1, bin2)); cpl_test_error(CPL_ERROR_NONE); cpl_test_leq(cpl_mask_count(bin1), cpl_mask_count(bin2)); - + /* Test cpl_mask_or */ cpl_test_zero(cpl_mask_or(bin1, bin2)); cpl_test_error(CPL_ERROR_NONE); cpl_test_eq_mask(bin1, bin2); - + /* Test cpl_mask_not */ cpl_test_zero(cpl_mask_not(bin2)); cpl_test_error(CPL_ERROR_NONE); @@ -372,40 +393,70 @@ error = cpl_mask_copy(bin2, bin1, 1, 0); cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); - error = cpl_mask_copy(bin2, bin1, nsize+1, 1); + error = cpl_mask_copy(bin2, bin1, nsize + 1, 1); cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); - error = cpl_mask_copy(bin2, bin1, 1, nsize+1); + error = cpl_mask_copy(bin2, bin1, 1, nsize + 1); cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); cpl_mask_delete(bin2); - + /* Test cpl_mask_extract() */ bin2 = cpl_mask_extract(bin1, 1, 1, 1, 1); cpl_test_nonnull(bin2); cpl_test_eq(cpl_mask_get_size_x(bin2), 1); cpl_test_eq(cpl_mask_get_size_y(bin2), 1); cpl_mask_delete(bin2); - + /* Test cpl_mask_shift() */ cpl_test_zero(cpl_mask_shift(bin1, 1, 1)); cpl_test_error(CPL_ERROR_NONE); - + cpl_test_zero(cpl_mask_set(bin1, IMAGESZ, IMAGESZ, CPL_BINARY_1)); cpl_test_zero(cpl_mask_is_empty(bin1)); + /* Test cpl_mask_move() */ + error = cpl_mask_move(NULL, 1, new_pos); + cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT); + error = cpl_mask_move(bin1, 1, NULL); + cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT); + error = cpl_mask_move(bin1, 0, new_pos); + cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); + error = cpl_mask_move(bin1, IMAGESZ + 1, new_pos); + cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); + error = cpl_mask_move(bin1, 1, new_pos); + cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); + + bin2 = cpl_mask_duplicate(bin1); + + nb_objs1 = 1; + error = cpl_mask_move(bin1, 1, &nb_objs1); + cpl_test_eq_error(error, CPL_ERROR_NONE); + cpl_test_eq_mask(bin2, bin1); + + error = cpl_mask_move(bin1, 2, new_pos); if (IMAGESZ % 2 == 0) { - /* Test cpl_mask_move() */ - cpl_test_zero(cpl_mask_move(bin1, 2, new_pos)); - cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_mask_move(bin1, 2, new_pos); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_mask_move(bin1, 2, new_pos); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_mask_move(bin1, 2, new_pos); + cpl_test_eq_error(error, CPL_ERROR_NONE); } + else { + cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); + } + cpl_test_eq_mask(bin2, bin1); + cpl_mask_delete(bin2); /* Test cpl_mask_extract_subsample() */ bin2 = cpl_mask_extract_subsample(bin1, 2, 2); cpl_test_nonnull(bin2); - cpl_test_zero(cpl_mask_dump_window(bin1, 1, 1, MASKSZ/2, MASKSZ/2, stream)); + cpl_test_zero( + cpl_mask_dump_window(bin1, 1, 1, MASKSZ / 2, MASKSZ / 2, stream)); cpl_test_zero(cpl_mask_dump_window(bin2, 1, 1, 1, 1, stream)); error = cpl_mask_dump_window(bin2, 1, 1, IMAGESZ, MASKSZ, stream); @@ -426,14 +477,14 @@ cpl_mask_delete(bin1); cpl_mask_delete(bin2); - if (stream != stdout) cpl_test_zero( fclose(stream) ); + if (stream != stdout) + cpl_test_zero(fclose(stream)); /* End of tests */ return cpl_test_end(0); } - /*----------------------------------------------------------------------------*/ /** @internal @@ -447,41 +498,41 @@ */ /*----------------------------------------------------------------------------*/ -static cpl_error_code cpl_mask_shift_bf(cpl_mask * in, - int x_shift, - int y_shift, - cpl_binary edge_fill) -{ - int xs_abs, ys_abs; - cpl_mask * loc; - cpl_binary * ploc; - cpl_binary * pin; - int i, j; +static cpl_error_code +cpl_mask_shift_bf(cpl_mask *in, int x_shift, int y_shift, cpl_binary edge_fill) +{ + int xs_abs, ys_abs; + cpl_mask *loc; + cpl_binary *ploc; + cpl_binary *pin; + int i, j; const int nx = cpl_mask_get_size_x(in); - const int ny = cpl_mask_get_size_y(in); + const int ny = cpl_mask_get_size_y(in); /* Initialise */ xs_abs = abs(x_shift); ys_abs = abs(y_shift); - - /* Check entries */ + + /* Check entries */ cpl_ensure_code(in != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code((xs_abs=0) && (i-x_shift=0) && (j-y_shift= 0) && (i - x_shift < nx) && + (j - y_shift >= 0) && (j - y_shift < ny)) { + pin[i + j * nx] = ploc[(i - x_shift) + (j - y_shift) * nx]; + } + else { + pin[i + j * nx] = edge_fill; } } } @@ -490,8 +541,6 @@ } - - /*----------------------------------------------------------------------------*/ /** @internal @@ -519,27 +568,25 @@ */ /*----------------------------------------------------------------------------*/ -static cpl_error_code cpl_mask_shift_filter(cpl_mask * self, - int x_shift, - int y_shift, - cpl_filter_mode filter) +static cpl_error_code +cpl_mask_shift_filter(cpl_mask *self, + int x_shift, + int y_shift, + cpl_filter_mode filter) { - const int mx = 1 + 2 * abs(x_shift); const int my = 1 + 2 * abs(y_shift); - cpl_mask * copy = cpl_mask_duplicate(self); - cpl_mask * kernel = cpl_mask_new(mx, my); - const cpl_error_code error - = cpl_mask_set(kernel, (mx + 1)/2 - x_shift, (my + 1)/2 - y_shift, - CPL_BINARY_1) - || cpl_mask_filter(self, copy, kernel, filter, - CPL_BORDER_ZERO); + cpl_mask *copy = cpl_mask_duplicate(self); + cpl_mask *kernel = cpl_mask_new(mx, my); + const cpl_error_code error = + cpl_mask_set(kernel, (mx + 1) / 2 - x_shift, (my + 1) / 2 - y_shift, + CPL_BINARY_1) || + cpl_mask_filter(self, copy, kernel, filter, CPL_BORDER_ZERO); cpl_mask_delete(kernel); cpl_mask_delete(copy); return error ? cpl_error_set_where(cpl_func) : CPL_ERROR_NONE; - } @@ -553,9 +600,10 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_mask_shift_test(int m, int n) +static void +cpl_mask_shift_test(int m, int n) { - cpl_mask * mask0 = cpl_mask_new(m, n); + cpl_mask *mask0 = cpl_mask_new(m, n); cpl_error_code error; @@ -579,12 +627,13 @@ cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); if (m == 1 && n == 1) { - cpl_mask * mask1 = cpl_mask_new(m, n); + cpl_mask *mask1 = cpl_mask_new(m, n); cpl_test_zero(cpl_mask_shift(mask1, 0, 0)); cpl_mask_delete(mask1); - } else { - cpl_mask * mask1 = cpl_mask_new(m, n); - cpl_mask * mask2 = cpl_mask_new(m, n); + } + else { + cpl_mask *mask1 = cpl_mask_new(m, n); + cpl_mask *mask2 = cpl_mask_new(m, n); int count; do { @@ -593,8 +642,8 @@ count = cpl_mask_count(mask0); } while (count == 0 || count == m * n); - for (int j = 1-n; j < n; j++) { - for (int i = 1-m; i < m; i++) { + for (int j = 1 - n; j < n; j++) { + for (int i = 1 - m; i < m; i++) { double time0, time1; cpl_mask_copy(mask1, mask0, 1, 1); @@ -603,25 +652,25 @@ time0 = cpl_test_get_cputime(); cpl_test_zero(cpl_mask_shift(mask1, i, j)); time1 = cpl_test_get_cputime(); - if (time1 > time0) tshift += time1 - time0; + if (time1 > time0) + tshift += time1 - time0; time0 = cpl_test_get_cputime(); cpl_test_zero(cpl_mask_shift_bf(mask2, i, j, CPL_BINARY_1)); time1 = cpl_test_get_cputime(); - if (time1 > time0) tshiftbf += time1 - time0; + if (time1 > time0) + tshiftbf += time1 - time0; cpl_test_eq_mask(mask1, mask2); if (4 * abs(i) < m && 4 * abs(j) < n) { + const cpl_filter_mode filter[] = { CPL_FILTER_EROSION, + CPL_FILTER_DILATION }; - const cpl_filter_mode filter[] = {CPL_FILTER_EROSION, - CPL_FILTER_DILATION}; - - const size_t nfilter = sizeof(filter)/sizeof(*filter); + const size_t nfilter = sizeof(filter) / sizeof(*filter); size_t k; for (k = 0; k < nfilter; k++) { - cpl_mask_copy(mask1, mask0, 1, 1); cpl_mask_fill_border(mask1, 2 * abs(i), 2 * abs(j), @@ -630,20 +679,20 @@ cpl_mask_copy(mask2, mask1, 1, 1); time0 = cpl_test_get_cputime(); - error = cpl_mask_shift_filter(mask1, i, j, - filter[k]); + error = cpl_mask_shift_filter(mask1, i, j, filter[k]); cpl_test_eq_error(error, CPL_ERROR_NONE); time1 = cpl_test_get_cputime(); - if (time1 > time0) tshiftfl += time1 - time0; + if (time1 > time0) + tshiftfl += time1 - time0; time0 = cpl_test_get_cputime(); cpl_mask_shift_bf(mask2, i, j, CPL_BINARY_0); time1 = cpl_test_get_cputime(); - if (time1 > time0) tshiftb2 += time1 - time0; + if (time1 > time0) + tshiftb2 += time1 - time0; cpl_test_eq_mask(mask1, mask2); } - } } } @@ -655,7 +704,6 @@ } - /*----------------------------------------------------------------------------*/ /** @internal @@ -666,18 +714,18 @@ */ /*----------------------------------------------------------------------------*/ -static cpl_error_code cpl_mask_fill_test(cpl_mask * self, double threshold) +static cpl_error_code +cpl_mask_fill_test(cpl_mask *self, double threshold) { - const int nx = cpl_mask_get_size_x(self); - const int ny = cpl_mask_get_size_y(self); - cpl_image * img = cpl_image_fill_test_create(nx, ny); - double med_dist; + const int ny = cpl_mask_get_size_y(self); + cpl_image *img = cpl_image_fill_test_create(nx, ny); + double med_dist; /* Compute the median and the mean dist. to the median of the image */ const double median = cpl_image_get_median_dev(img, &med_dist); const double minval = median + threshold * med_dist; - cpl_mask * other = cpl_mask_threshold_image_create(img, minval, DBL_MAX); + cpl_mask *other = cpl_mask_threshold_image_create(img, minval, DBL_MAX); cpl_ensure_code(img != NULL, cpl_error_get_code()); @@ -691,7 +739,6 @@ } - /*----------------------------------------------------------------------------*/ /** @internal @@ -705,13 +752,12 @@ */ /*----------------------------------------------------------------------------*/ -static cpl_error_code cpl_mask_fill_border(cpl_mask * self, int hx, int hy, - cpl_binary fill) +static cpl_error_code +cpl_mask_fill_border(cpl_mask *self, int hx, int hy, cpl_binary fill) { - const int nx = cpl_mask_get_size_x(self); const int ny = cpl_mask_get_size_y(self); - cpl_binary * pself = cpl_mask_get_data(self); + cpl_binary *pself = cpl_mask_get_data(self); int j; @@ -731,8 +777,7 @@ /* self-col now indexed from -hy to hy */ pself += hy * nx; - for (j = hy; j < ny-hy; j++, pself += nx) { - + for (j = hy; j < ny - hy; j++, pself += nx) { if (j > hy) { /* Do also last hx border elements of previous row */ (void)memset(pself - hx, fill, 2 * hx); @@ -743,7 +788,6 @@ (void)memset(pself - hx, fill, hx + hy * nx); return CPL_ERROR_NONE; - } @@ -756,33 +800,34 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_mask_test(cpl_boolean do_bench) +static void +cpl_mask_test(cpl_boolean do_bench) { + const int npix[] = { 1, 2, 3, 5, 10, 11, do_bench ? 2 * IMAGESZ : 13 }; - const int npix[] = {1, 2, 3, 5, 10, 11, do_bench ? 2*IMAGESZ : 13}; - - const cpl_binary buf9[] = {CPL_BINARY_1, CPL_BINARY_0, CPL_BINARY_1, - CPL_BINARY_0, CPL_BINARY_0, CPL_BINARY_1, - CPL_BINARY_1, CPL_BINARY_0, CPL_BINARY_1}; + const cpl_binary buf9[] = { CPL_BINARY_1, CPL_BINARY_0, CPL_BINARY_1, + CPL_BINARY_0, CPL_BINARY_0, CPL_BINARY_1, + CPL_BINARY_1, CPL_BINARY_0, CPL_BINARY_1 }; /* Rotation 90 degrees clockwise */ - const cpl_binary rot9[] = {CPL_BINARY_1, CPL_BINARY_1, CPL_BINARY_1, - CPL_BINARY_0, CPL_BINARY_0, CPL_BINARY_0, - CPL_BINARY_1, CPL_BINARY_0, CPL_BINARY_1}; + const cpl_binary rot9[] = { CPL_BINARY_1, CPL_BINARY_1, CPL_BINARY_1, + CPL_BINARY_0, CPL_BINARY_0, CPL_BINARY_0, + CPL_BINARY_1, CPL_BINARY_0, CPL_BINARY_1 }; /* This mask is not modified while wrapping around this buffer */ - cpl_mask * ref = cpl_mask_wrap(3, 3, (cpl_binary*)rot9); - cpl_mask * raw = cpl_mask_new(3, 3); + cpl_mask *ref = cpl_mask_wrap(3, 3, (cpl_binary *)rot9); + cpl_mask *raw = cpl_mask_new(3, 3); cpl_error_code error; - size_t ipix; - double tflip = 0.0; - double tturn = 0.0; - double tassi = 0.0; - double tcol0 = 0.0; - double tcol1 = 0.0; + size_t ipix; + double tflip = 0.0; + double tturn = 0.0; + double tassi = 0.0; + double tcol0 = 0.0; + double tcol1 = 0.0; /* Test 1: Verify direction of 90 degree rotation */ - cpl_test_nonnull(memcpy(cpl_mask_get_data(raw), buf9, 9*sizeof(cpl_binary))); + cpl_test_nonnull( + memcpy(cpl_mask_get_data(raw), buf9, 9 * sizeof(cpl_binary))); cpl_test_zero(cpl_mask_turn(raw, 1)); cpl_test_eq_mask(raw, ref); @@ -795,23 +840,23 @@ cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT); /* Test 3: Verify consistency of rotations across types */ - for (ipix = 0; ipix < sizeof(npix)/sizeof(npix[0]); ipix++) { + for (ipix = 0; ipix < sizeof(npix) / sizeof(npix[0]); ipix++) { const int nx = npix[ipix]; size_t jpix; - for (jpix = 0; jpix < sizeof(npix)/sizeof(npix[0]); jpix++) { + for (jpix = 0; jpix < sizeof(npix) / sizeof(npix[0]); jpix++) { const int ny = npix[jpix]; - cpl_image * noise = cpl_image_new(nx, ny, CPL_TYPE_FLOAT); - cpl_mask * collapsed; + cpl_image *noise = cpl_image_new(nx, ny, CPL_TYPE_FLOAT); + cpl_mask *collapsed; double ttemp0, ttemp1; int i; - cpl_test_zero(cpl_image_fill_noise_uniform(noise, (double)-ny, - (double)nx)); + cpl_test_zero( + cpl_image_fill_noise_uniform(noise, (double)-ny, (double)nx)); /* About 1/4 of the pixels are flagged */ - raw = cpl_mask_threshold_image_create(noise, -0.25*ny, 0.25*nx); + raw = cpl_mask_threshold_image_create(noise, -0.25 * ny, 0.25 * nx); cpl_image_delete(noise); ref = cpl_mask_extract(raw, 1, 1, nx, ny); @@ -823,13 +868,14 @@ cpl_test_zero(cpl_mask_turn(raw, 2)); cpl_test_zero(cpl_mask_turn(raw, 3)); cpl_test_zero(cpl_mask_turn(raw, 4)); - cpl_test_zero(cpl_mask_turn(raw,-1)); - cpl_test_zero(cpl_mask_turn(raw,-2)); - cpl_test_zero(cpl_mask_turn(raw,-3)); + cpl_test_zero(cpl_mask_turn(raw, -1)); + cpl_test_zero(cpl_mask_turn(raw, -2)); + cpl_test_zero(cpl_mask_turn(raw, -3)); cpl_test_zero(cpl_mask_turn(raw, 0)); ttemp1 = cpl_test_get_cputime(); - if (ttemp1 > ttemp0) tturn += ttemp1 - ttemp0; + if (ttemp1 > ttemp0) + tturn += ttemp1 - ttemp0; cpl_test_eq_mask(raw, ref); @@ -846,7 +892,8 @@ cpl_test_zero(cpl_mask_flip(raw, 3)); ttemp1 = cpl_test_get_cputime(); - if (ttemp1 > ttemp0) tflip += ttemp1 - ttemp0; + if (ttemp1 > ttemp0) + tflip += ttemp1 - ttemp0; cpl_test_eq_mask(raw, ref); @@ -863,8 +910,8 @@ /* cpl_mask_copy()... */ cpl_test_nonnull(memcpy(cpl_mask_get_data(raw), - cpl_mask_get_data_const(ref), - nx * ny * sizeof(cpl_binary))); + cpl_mask_get_data_const(ref), + nx * ny * sizeof(cpl_binary))); /* Empty the mask */ cpl_test_zero(cpl_mask_not(raw)); @@ -883,7 +930,8 @@ cpl_test_eq(cpl_mask_count(raw), nx * ny); ttemp1 = cpl_test_get_cputime(); - if (ttemp1 > ttemp0) tassi += ttemp1 - ttemp0; + if (ttemp1 > ttemp0) + tassi += ttemp1 - ttemp0; for (i = 1; i <= nx; i++) { /* First collapsed element will be CPL_BINARY_0 */ @@ -898,7 +946,8 @@ collapsed = cpl_mask_collapse_create(raw, 1); ttemp1 = cpl_test_get_cputime(); - if (ttemp1 > ttemp0) tcol1 += ttemp1 - ttemp0; + if (ttemp1 > ttemp0) + tcol1 += ttemp1 - ttemp0; cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(collapsed); @@ -925,7 +974,8 @@ cpl_test_zero(cpl_mask_not(raw)); cpl_test_zero(cpl_mask_or(raw, ref)); ttemp1 = cpl_test_get_cputime(); - if (ttemp1 > ttemp0) tassi += ttemp1 - ttemp0; + if (ttemp1 > ttemp0) + tassi += ttemp1 - ttemp0; cpl_test_eq(cpl_mask_count(raw), nx * ny); for (i = 1; i <= ny; i++) { @@ -941,7 +991,8 @@ collapsed = cpl_mask_collapse_create(raw, 0); ttemp1 = cpl_test_get_cputime(); - if (ttemp1 > ttemp0) tcol0 += ttemp1 - ttemp0; + if (ttemp1 > ttemp0) + tcol0 += ttemp1 - ttemp0; cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(collapsed); @@ -967,7 +1018,8 @@ cpl_test(cpl_mask_is_empty(raw)); cpl_test_zero(cpl_mask_not(raw)); ttemp1 = cpl_test_get_cputime(); - if (ttemp1 > ttemp0) tassi += ttemp1 - ttemp0; + if (ttemp1 > ttemp0) + tassi += ttemp1 - ttemp0; cpl_test_eq(cpl_mask_count(raw), nx * ny); /* Every other element on the diagonal is CPL_BINARY_0 */ @@ -975,13 +1027,14 @@ cpl_test_zero(cpl_mask_set(raw, i, i, CPL_BINARY_0)); nzero++; } - cpl_test_eq(cpl_mask_count(raw), nx * ny-nzero); + cpl_test_eq(cpl_mask_count(raw), nx * ny - nzero); ttemp0 = cpl_test_get_cputime(); collapsed = cpl_mask_collapse_create(raw, 1); ttemp1 = cpl_test_get_cputime(); - if (ttemp1 > ttemp0) tcol1 += ttemp1 - ttemp0; + if (ttemp1 > ttemp0) + tcol1 += ttemp1 - ttemp0; cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(collapsed); @@ -1002,7 +1055,8 @@ collapsed = cpl_mask_collapse_create(raw, 0); ttemp1 = cpl_test_get_cputime(); - if (ttemp1 > ttemp0) tcol0 += ttemp1 - ttemp0; + if (ttemp1 > ttemp0) + tcol0 += ttemp1 - ttemp0; cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(collapsed); @@ -1025,20 +1079,22 @@ cpl_test(cpl_mask_is_empty(raw)); cpl_test_zero(cpl_mask_not(raw)); ttemp1 = cpl_test_get_cputime(); - if (ttemp1 > ttemp0) tassi += ttemp1 - ttemp0; + if (ttemp1 > ttemp0) + tassi += ttemp1 - ttemp0; cpl_test_eq(cpl_mask_count(raw), nx * ny); /* The first row is all CPL_BINARY_0 */ for (i = 1; i <= nx; i++) { cpl_test_zero(cpl_mask_set(raw, i, 1, CPL_BINARY_0)); } - cpl_test_eq(cpl_mask_count(raw), nx * (ny-1)); + cpl_test_eq(cpl_mask_count(raw), nx * (ny - 1)); ttemp0 = cpl_test_get_cputime(); collapsed = cpl_mask_collapse_create(raw, 0); ttemp1 = cpl_test_get_cputime(); - if (ttemp1 > ttemp0) tcol0 += ttemp1 - ttemp0; + if (ttemp1 > ttemp0) + tcol0 += ttemp1 - ttemp0; cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(collapsed); @@ -1049,7 +1105,6 @@ cpl_test(cpl_mask_is_empty(collapsed)); cpl_mask_delete(collapsed); - } cpl_mask_delete(ref); @@ -1075,23 +1130,23 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_mask_filter_test(int nsize) +static void +cpl_mask_filter_test(int nsize) { - cpl_error_code error; - const cpl_filter_mode filter[] = {CPL_FILTER_EROSION, CPL_FILTER_DILATION, - CPL_FILTER_OPENING, CPL_FILTER_CLOSING}; + const cpl_filter_mode filter[] = { CPL_FILTER_EROSION, CPL_FILTER_DILATION, + CPL_FILTER_OPENING, CPL_FILTER_CLOSING }; - const size_t nfilter = sizeof(filter)/sizeof(*filter); + const size_t nfilter = sizeof(filter) / sizeof(*filter); size_t k; /* Build a 3x3 kernel */ - cpl_mask * kernel = cpl_mask_new(3, 3); + cpl_mask *kernel = cpl_mask_new(3, 3); - cpl_mask * mask1 = cpl_mask_new(nsize, nsize); - cpl_mask * copy1 = cpl_mask_new(nsize, nsize); + cpl_mask *mask1 = cpl_mask_new(nsize, nsize); + cpl_mask *copy1 = cpl_mask_new(nsize, nsize); - cpl_msg_info(cpl_func,"Testing filtering functions with %d x %d mask", + cpl_msg_info(cpl_func, "Testing filtering functions with %d x %d mask", nsize, nsize); error = cpl_mask_fill_test(mask1, 2.0); @@ -1107,32 +1162,31 @@ cpl_test_eq(cpl_mask_count(kernel), 5); for (k = 0; k < nfilter; k++) { - cpl_mask * evenr = cpl_mask_new(3, 4); - cpl_mask * evenc = cpl_mask_new(4, 3); + cpl_mask *evenr = cpl_mask_new(3, 4); + cpl_mask *evenc = cpl_mask_new(4, 3); - cpl_mask * id = cpl_mask_new(1,1); - cpl_mask * copy2 = cpl_mask_new(nsize, nsize); + cpl_mask *id = cpl_mask_new(1, 1); + cpl_mask *copy2 = cpl_mask_new(nsize, nsize); /* Error: NULL pointer */ - error = cpl_mask_filter(NULL, mask1, kernel, filter[k], - CPL_BORDER_ZERO); + error = + cpl_mask_filter(NULL, mask1, kernel, filter[k], CPL_BORDER_ZERO); cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT); - error = cpl_mask_filter(copy1, NULL, kernel, filter[k], - CPL_BORDER_ZERO); + error = + cpl_mask_filter(copy1, NULL, kernel, filter[k], CPL_BORDER_ZERO); cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT); - error = cpl_mask_filter(copy1, mask1, NULL, filter[k], - CPL_BORDER_ZERO); + error = cpl_mask_filter(copy1, mask1, NULL, filter[k], CPL_BORDER_ZERO); cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT); /* Error: Even sized kernels */ - error = cpl_mask_filter(copy1, mask1, evenr, filter[k], - CPL_BORDER_ZERO); + error = + cpl_mask_filter(copy1, mask1, evenr, filter[k], CPL_BORDER_ZERO); cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); - error = cpl_mask_filter(copy1, mask1, evenc, filter[k], - CPL_BORDER_ZERO); + error = + cpl_mask_filter(copy1, mask1, evenc, filter[k], CPL_BORDER_ZERO); cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); /* Error: Empty kernel */ @@ -1165,7 +1219,6 @@ cpl_mask_delete(evenc); cpl_mask_delete(copy2); cpl_mask_delete(id); - } error = cpl_mask_filter(copy1, mask1, kernel, CPL_FILTER_EROSION, @@ -1182,7 +1235,6 @@ cpl_mask_delete(mask1); cpl_mask_delete(copy1); cpl_mask_delete(kernel); - } @@ -1196,137 +1248,131 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_mask_filter_test_schalkoff(void) +static void +cpl_mask_filter_test_schalkoff(void) { - #define nx 21 #define ny 18 - const int borders[] = {CPL_BORDER_NOP, CPL_BORDER_ZERO, CPL_BORDER_COPY}; - const size_t nborders = sizeof(borders)/sizeof(borders[0]); + const int borders[] = { CPL_BORDER_NOP, CPL_BORDER_ZERO, CPL_BORDER_COPY }; + const size_t nborders = sizeof(borders) / sizeof(borders[0]); /* Binary Image 6.36a */ - const cpl_binary schallkoff_A[nx*ny] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + const cpl_binary schallkoff_A[nx * ny] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, + 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + }; /* Binary Image 6.37b from R. Schallkoff (Dilation w. 3x3 full kernel) */ - const cpl_binary schallkoff_D[nx*ny] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, - 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, - 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, - 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, - 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, - 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, - 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, - 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, - 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + const cpl_binary schallkoff_D[nx * ny] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, + 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + }; /* Binary Image 6.37c from R. Schallkoff (Erosion w. 3x3 full kernel) */ - const cpl_binary schallkoff_E[nx*ny] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + const cpl_binary schallkoff_E[nx * ny] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + }; /* Binary Image 6.39a from R. Schallkoff (Opening w. 3x3 full kernel) */ - const cpl_binary schallkoff_O[nx*ny] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + const cpl_binary schallkoff_O[nx * ny] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, + 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, + 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + }; /* Binary Image 6.39b from R. Schallkoff (Closing w. 3x3 full kernel) */ - const cpl_binary schallkoff_C[nx*ny] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + const cpl_binary schallkoff_C[nx * ny] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, + 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + }; - cpl_mask * mask0 = cpl_mask_new(nx, ny); + cpl_mask *mask0 = cpl_mask_new(nx, ny); /* NOT modified */ - cpl_mask * maskA = cpl_mask_wrap(nx, ny, (cpl_binary*)schallkoff_A); - cpl_mask * maskD = cpl_mask_wrap(nx, ny, (cpl_binary*)schallkoff_D); - cpl_mask * maskE = cpl_mask_wrap(nx, ny, (cpl_binary*)schallkoff_E); - cpl_mask * maskO = cpl_mask_wrap(nx, ny, (cpl_binary*)schallkoff_O); - cpl_mask * maskC = cpl_mask_wrap(nx, ny, (cpl_binary*)schallkoff_C); + cpl_mask *maskA = cpl_mask_wrap(nx, ny, (cpl_binary *)schallkoff_A); + cpl_mask *maskD = cpl_mask_wrap(nx, ny, (cpl_binary *)schallkoff_D); + cpl_mask *maskE = cpl_mask_wrap(nx, ny, (cpl_binary *)schallkoff_E); + cpl_mask *maskO = cpl_mask_wrap(nx, ny, (cpl_binary *)schallkoff_O); + cpl_mask *maskC = cpl_mask_wrap(nx, ny, (cpl_binary *)schallkoff_C); /* Build a 3x3 kernel inside a 5 x 5 mask */ - cpl_mask * kernel = cpl_mask_new(5, 5); + cpl_mask *kernel = cpl_mask_new(5, 5); cpl_error_code error; size_t iborder; - cpl_msg_info(cpl_func, "Schalkoff filter test on " CPL_STRINGIFY(nx) " x " - CPL_STRINGIFY(ny) " mask"); + cpl_msg_info(cpl_func, "Schalkoff filter test on " CPL_STRINGIFY(nx) " x " CPL_STRINGIFY(ny) " mask"); cpl_mask_flip_turn_test(maskA); @@ -1346,11 +1392,10 @@ for (iborder = 0; iborder < nborders; iborder++) { int iflip; for (iflip = 0; iflip < 3; iflip++) { - /* Test also with flipped images since the mask is traversed in one specific direction */ - cpl_mask * flip = cpl_mask_new(nx, ny); + cpl_mask *flip = cpl_mask_new(nx, ny); /* Test erosion */ @@ -1447,9 +1492,9 @@ nidem = 2; do { /* Idempotency test as well */ - error = cpl_mask_filter(mask0, flip, kernel, - CPL_FILTER_OPENING, - borders[iborder]); + error = + cpl_mask_filter(mask0, flip, kernel, CPL_FILTER_OPENING, + borders[iborder]); cpl_test_eq_error(error, CPL_ERROR_NONE); } while (--nidem); @@ -1473,9 +1518,9 @@ nidem = 2; do { /* Idempotency test as well */ - error = cpl_mask_filter(mask0, flip, kernel, - CPL_FILTER_CLOSING, - borders[iborder]); + error = + cpl_mask_filter(mask0, flip, kernel, CPL_FILTER_CLOSING, + borders[iborder]); cpl_test_eq_error(error, CPL_ERROR_NONE); } while (--nidem > 0); @@ -1521,13 +1566,11 @@ } cpl_test_eq_mask(maskO, mask0); - } /* Tests for one flip done */ cpl_mask_delete(flip); - } } @@ -1542,11 +1585,9 @@ #undef nx #undef ny - } - /*----------------------------------------------------------------------------*/ /** @internal @@ -1556,35 +1597,40 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_mask_filter_test_matrix(int nsize) { - - const int maxhxy = CX_MIN(9, nsize/4); +static void +cpl_mask_filter_test_matrix(int nsize) +{ + const int maxhxy = CX_MIN(9, nsize / 4); - cpl_error_code (*ffilter[4])(cpl_mask *, const cpl_matrix *) - = {cpl_mask_erosion_matrix, cpl_mask_dilation_matrix, - cpl_mask_opening_matrix, cpl_mask_closing_matrix}; + cpl_error_code (*ffilter[4])(cpl_mask *, const cpl_matrix *) = { + cpl_mask_erosion_matrix, cpl_mask_dilation_matrix, + cpl_mask_opening_matrix, cpl_mask_closing_matrix + }; - const cpl_filter_mode mfilter[] = {CPL_FILTER_EROSION, CPL_FILTER_DILATION, - CPL_FILTER_OPENING, CPL_FILTER_CLOSING}; + const cpl_filter_mode mfilter[] = { CPL_FILTER_EROSION, CPL_FILTER_DILATION, + CPL_FILTER_OPENING, + CPL_FILTER_CLOSING }; - const cpl_filter_mode mdual[] = {CPL_FILTER_DILATION, CPL_FILTER_EROSION, - CPL_FILTER_CLOSING, CPL_FILTER_OPENING}; + const cpl_filter_mode mdual[] = { CPL_FILTER_DILATION, CPL_FILTER_EROSION, + CPL_FILTER_CLOSING, CPL_FILTER_OPENING }; - const size_t nfilter = sizeof(ffilter)/sizeof(*ffilter); + const size_t nfilter = sizeof(ffilter) / sizeof(*ffilter); size_t k; - cpl_mask * raw = cpl_mask_new(nsize, nsize); + cpl_mask *raw = cpl_mask_new(nsize, nsize); int hx, hy; cpl_error_code error; double time_mask = 0.0; - double time_bf = 0.0; + double time_bf = 0.0; double time_matrix = 0.0; error = cpl_mask_fill_test(raw, 2.0); cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_msg_info(cpl_func, "Matrix testing of cpl_mask_filter() filters with " - "%d x %d mask", nsize, nsize); + cpl_msg_info(cpl_func, + "Matrix testing of cpl_mask_filter() filters with " + "%d x %d mask", + nsize, nsize); for (hy = 0; hy < maxhxy; hy++) { for (hx = 0; hx < maxhxy; hx++) { @@ -1592,21 +1638,23 @@ const int my = 1 + 2 * hy; int do_full; - if (mx > nsize || my > nsize) continue; + if (mx > nsize || my > nsize) + continue; for (do_full = mx * my > 1 ? 0 : 1; do_full < 2; do_full++) { - cpl_mask * kernel = cpl_mask_new(mx, my); - cpl_matrix * matrix = cpl_matrix_new(my, mx); + cpl_mask *kernel = cpl_mask_new(mx, my); + cpl_matrix *matrix = cpl_matrix_new(my, mx); - cpl_mask * filtered = cpl_mask_new(nsize, nsize); - cpl_mask * rawcopy = cpl_mask_new(nsize, nsize); + cpl_mask *filtered = cpl_mask_new(nsize, nsize); + cpl_mask *rawcopy = cpl_mask_new(nsize, nsize); if (do_full) { error = cpl_mask_not(kernel); cpl_test_eq_error(error, CPL_ERROR_NONE); error = cpl_matrix_fill(matrix, 1.0); cpl_test_eq_error(error, CPL_ERROR_NONE); - } else { + } + else { int i, j; int ncount; do { @@ -1622,20 +1670,21 @@ } } - cpl_msg_info(cpl_func, "The %u filters w. %d x %d kernel " - "(full and %d element(s))", (unsigned)nfilter, - mx, my, ncount); + cpl_msg_info(cpl_func, + "The %u filters w. %d x %d kernel " + "(full and %d element(s))", + (unsigned)nfilter, mx, my, ncount); } for (k = 0; k < nfilter; k++) { - double time0, time1; + double time0, time1; error = cpl_mask_copy(rawcopy, raw, 1, 1); cpl_test_eq_error(error, CPL_ERROR_NONE); time0 = cpl_test_get_cputime(); - error = cpl_mask_filter(filtered, raw, kernel, - mfilter[k], CPL_BORDER_ZERO); + error = cpl_mask_filter(filtered, raw, kernel, mfilter[k], + CPL_BORDER_ZERO); cpl_test_eq_error(error, CPL_ERROR_NONE); time1 = cpl_test_get_cputime(); if (time1 > time0) @@ -1662,7 +1711,6 @@ if (mfilter[k] == CPL_FILTER_OPENING || mfilter[k] == CPL_FILTER_CLOSING) { - /* Opening and closing can also be done in-place */ error = cpl_mask_copy(rawcopy, raw, 1, 1); @@ -1677,27 +1725,27 @@ /* Duality test */ cpl_mask_not(raw); - error = cpl_mask_filter(filtered, raw, kernel, - mdual[k], CPL_BORDER_ZERO); + error = cpl_mask_filter(filtered, raw, kernel, mdual[k], + CPL_BORDER_ZERO); cpl_test_eq_error(error, CPL_ERROR_NONE); cpl_mask_not(filtered); /* No duality on border */ cpl_mask_fill_border(filtered, mx, my, CPL_BINARY_0); - cpl_mask_fill_border(rawcopy, mx, my, CPL_BINARY_0); + cpl_mask_fill_border(rawcopy, mx, my, CPL_BINARY_0); cpl_test_eq_mask(filtered, rawcopy); - error = cpl_mask_filter_bf(filtered, raw, kernel, - mdual[k], CPL_BORDER_ZERO); + error = cpl_mask_filter_bf(filtered, raw, kernel, mdual[k], + CPL_BORDER_ZERO); cpl_test_eq_error(error, CPL_ERROR_NONE); cpl_mask_not(filtered); /* No duality on border */ cpl_mask_fill_border(filtered, mx, my, CPL_BINARY_0); - cpl_mask_fill_border(rawcopy, mx, my, CPL_BINARY_0); + cpl_mask_fill_border(rawcopy, mx, my, CPL_BINARY_0); cpl_test_eq_mask(filtered, rawcopy); @@ -1710,8 +1758,9 @@ int nidem = 2; do { - error = cpl_mask_filter(filtered, raw, kernel, - mfilter[k], CPL_BORDER_ZERO); + error = + cpl_mask_filter(filtered, raw, kernel, + mfilter[k], CPL_BORDER_ZERO); cpl_test_eq_error(error, CPL_ERROR_NONE); } while (--nidem > 0); @@ -1723,9 +1772,9 @@ nidem = 2; do { - error = cpl_mask_filter_bf(filtered, raw, kernel, - mfilter[k], - CPL_BORDER_ZERO); + error = + cpl_mask_filter_bf(filtered, raw, kernel, + mfilter[k], CPL_BORDER_ZERO); cpl_test_eq_error(error, CPL_ERROR_NONE); } while (--nidem > 0); @@ -1733,7 +1782,6 @@ cpl_mask_fill_border(filtered, mx, my, CPL_BINARY_0); cpl_test_eq_mask(filtered, rawcopy); - } } @@ -1746,7 +1794,8 @@ } if (time_mask > 0.0 || time_matrix > 0.0 || time_bf > 0.0) - cpl_msg_info(cpl_func, "Time to filter, mask <=> brute force <=> " + cpl_msg_info(cpl_func, + "Time to filter, mask <=> brute force <=> " "matrix [s]: %g <=> %g <=> %g", time_mask, time_bf, time_matrix); @@ -1764,10 +1813,11 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_mask_count_bench(int nsize, int nreps) { - - cpl_mask * mask1 = cpl_mask_new(nsize, nsize); - cpl_mask * mask2; +static void +cpl_mask_count_bench(int nsize, int nreps) +{ + cpl_mask *mask1 = cpl_mask_new(nsize, nsize); + cpl_mask *mask2; cpl_error_code error; double time0, time_mask = 0.0; int irep; @@ -1782,15 +1832,16 @@ time0 = cpl_test_get_cputime(); for (irep = 0; irep < nreps; irep++) { - cpl_test_eq(cpl_mask_count(mask1) + cpl_mask_count(mask2), nsize * nsize); } time_mask = cpl_test_get_cputime() - time0; - cpl_msg_info(cpl_func, "Time to count elements 2 X %d mask of size %d x %d " - "[s]: %g", nreps, nsize, nsize, time_mask); + cpl_msg_info(cpl_func, + "Time to count elements 2 X %d mask of size %d x %d " + "[s]: %g", + nreps, nsize, nsize, time_mask); cpl_mask_delete(mask1); cpl_mask_delete(mask2); } @@ -1806,30 +1857,38 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_mask_filter_bench(int nsize, int nreps, int minhx, int maxhx, - int minhy, int maxhy) { - - const cpl_filter_mode mfilter[] = {CPL_FILTER_EROSION, CPL_FILTER_DILATION, - CPL_FILTER_OPENING, CPL_FILTER_CLOSING}; +static void +cpl_mask_filter_bench(int nsize, + int nreps, + int minhx, + int maxhx, + int minhy, + int maxhy) +{ + const cpl_filter_mode mfilter[] = { CPL_FILTER_EROSION, CPL_FILTER_DILATION, + CPL_FILTER_OPENING, + CPL_FILTER_CLOSING }; - const cpl_filter_mode mdual[] = {CPL_FILTER_DILATION, CPL_FILTER_EROSION, - CPL_FILTER_CLOSING, CPL_FILTER_OPENING}; + const cpl_filter_mode mdual[] = { CPL_FILTER_DILATION, CPL_FILTER_EROSION, + CPL_FILTER_CLOSING, CPL_FILTER_OPENING }; - const size_t nfilter = sizeof(mfilter)/sizeof(*mfilter); + const size_t nfilter = sizeof(mfilter) / sizeof(*mfilter); size_t k; - cpl_mask * raw = cpl_mask_new(nsize, nsize); + cpl_mask *raw = cpl_mask_new(nsize, nsize); int hx, hy; cpl_error_code error; double time_mask = 0.0; - double time_bf = 0.0; + double time_bf = 0.0; int irep; error = cpl_mask_fill_test(raw, 2.0); cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_msg_info(cpl_func, "Matrix testing of cpl_mask_filter() filters with " - "%d x %d mask", nsize, nsize); + cpl_msg_info(cpl_func, + "Matrix testing of cpl_mask_filter() filters with " + "%d x %d mask", + nsize, nsize); for (irep = 0; irep < nreps; irep++) { for (hy = minhy; hy <= maxhy; hy++) { @@ -1838,18 +1897,20 @@ const int my = 1 + 2 * hy; int do_full; - if (mx > nsize || my > nsize) continue; + if (mx > nsize || my > nsize) + continue; for (do_full = mx * my > 1 ? 0 : 1; do_full < 2; do_full++) { - cpl_mask * kernel = cpl_mask_new(mx, my); + cpl_mask *kernel = cpl_mask_new(mx, my); - cpl_mask * filtered = cpl_mask_new(nsize, nsize); - cpl_mask * rawcopy = cpl_mask_new(nsize, nsize); + cpl_mask *filtered = cpl_mask_new(nsize, nsize); + cpl_mask *rawcopy = cpl_mask_new(nsize, nsize); if (do_full) { error = cpl_mask_not(kernel); cpl_test_eq_error(error, CPL_ERROR_NONE); - } else { + } + else { int ncount; do { error = cpl_mask_fill_test(kernel, 0.0); @@ -1857,13 +1918,14 @@ ncount = cpl_mask_count(kernel); } while (ncount == 0 || ncount == mx * my); - cpl_msg_info(cpl_func, "The %u filters w. %d x %d kernel " - "(full and %d element(s))", (unsigned)nfilter, - mx, my, ncount); + cpl_msg_info(cpl_func, + "The %u filters w. %d x %d kernel " + "(full and %d element(s))", + (unsigned)nfilter, mx, my, ncount); } for (k = 0; k < nfilter; k++) { - double time0, time1; + double time0, time1; time0 = cpl_test_get_cputime(); error = cpl_mask_filter(filtered, raw, kernel, @@ -1885,13 +1947,13 @@ if (mfilter[k] == CPL_FILTER_OPENING || mfilter[k] == CPL_FILTER_CLOSING) { - /* Opening and closing can also be done in-place */ error = cpl_mask_copy(rawcopy, raw, 1, 1); cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_mask_filter(rawcopy, rawcopy, kernel, - mfilter[k], CPL_BORDER_ZERO); + error = + cpl_mask_filter(rawcopy, rawcopy, kernel, + mfilter[k], CPL_BORDER_ZERO); cpl_test_eq_error(error, CPL_ERROR_NONE); cpl_test_eq_mask(filtered, rawcopy); @@ -1900,15 +1962,15 @@ /* Duality test */ cpl_mask_not(raw); - error = cpl_mask_filter(filtered, raw, kernel, - mdual[k], CPL_BORDER_ZERO); + error = cpl_mask_filter(filtered, raw, kernel, mdual[k], + CPL_BORDER_ZERO); cpl_test_eq_error(error, CPL_ERROR_NONE); cpl_mask_not(filtered); /* No duality on border */ cpl_mask_fill_border(filtered, mx, my, CPL_BINARY_0); - cpl_mask_fill_border(rawcopy, mx, my, CPL_BINARY_0); + cpl_mask_fill_border(rawcopy, mx, my, CPL_BINARY_0); cpl_test_eq_mask(filtered, rawcopy); @@ -1920,7 +1982,7 @@ /* No duality on border */ cpl_mask_fill_border(filtered, mx, my, CPL_BINARY_0); - cpl_mask_fill_border(rawcopy, mx, my, CPL_BINARY_0); + cpl_mask_fill_border(rawcopy, mx, my, CPL_BINARY_0); cpl_test_eq_mask(filtered, rawcopy); @@ -1934,29 +1996,31 @@ do { error = cpl_mask_filter(filtered, raw, kernel, - mfilter[k], CPL_BORDER_ZERO); + mfilter[k], + CPL_BORDER_ZERO); cpl_test_eq_error(error, CPL_ERROR_NONE); } while (--nidem > 0); /* No idempotency on border */ - cpl_mask_fill_border(filtered, mx, my, CPL_BINARY_0); + cpl_mask_fill_border(filtered, mx, my, + CPL_BINARY_0); cpl_test_eq_mask(filtered, rawcopy); nidem = 2; do { - error = cpl_mask_filter_bf(filtered, raw, kernel, - mfilter[k], + error = cpl_mask_filter_bf(filtered, raw, + kernel, mfilter[k], CPL_BORDER_ZERO); cpl_test_eq_error(error, CPL_ERROR_NONE); } while (--nidem > 0); /* No idempotency on border */ - cpl_mask_fill_border(filtered, mx, my, CPL_BINARY_0); + cpl_mask_fill_border(filtered, mx, my, + CPL_BINARY_0); cpl_test_eq_mask(filtered, rawcopy); - } } @@ -1969,14 +2033,15 @@ } if (time_mask > 0.0 || time_bf > 0.0) - cpl_msg_info(cpl_func, "Time to filter, mask <=> brute force [s]: " - "%g <=> %g", time_mask, time_bf); + cpl_msg_info(cpl_func, + "Time to filter, mask <=> brute force [s]: " + "%g <=> %g", + time_mask, time_bf); cpl_mask_delete(raw); } - /*----------------------------------------------------------------------------*/ /** @internal @@ -1997,9 +2062,8 @@ dilation cannot be done */ /*----------------------------------------------------------------------------*/ -static cpl_error_code cpl_mask_opening_matrix( - cpl_mask * in, - const cpl_matrix * ker) +static cpl_error_code +cpl_mask_opening_matrix(cpl_mask *in, const cpl_matrix *ker) { cpl_ensure_code(in && ker, CPL_ERROR_NULL_INPUT); if (cpl_mask_erosion_matrix(in, ker) != CPL_ERROR_NONE) @@ -2029,9 +2093,8 @@ dilation cannot be done */ /*----------------------------------------------------------------------------*/ -static cpl_error_code cpl_mask_closing_matrix( - cpl_mask * in, - const cpl_matrix * ker) +static cpl_error_code +cpl_mask_closing_matrix(cpl_mask *in, const cpl_matrix *ker) { cpl_ensure_code(in && ker, CPL_ERROR_NULL_INPUT); if (cpl_mask_dilation_matrix(in, ker) != CPL_ERROR_NONE) @@ -2059,20 +2122,19 @@ - CPL_ERROR_ILLEGAL_INPUT if the kernel is not as requested */ /*----------------------------------------------------------------------------*/ -static cpl_error_code cpl_mask_erosion_matrix( - cpl_mask * in, - const cpl_matrix * ker) -{ - const int nx = cpl_mask_get_size_x(in); - const int ny = cpl_mask_get_size_y(in); - cpl_binary * datain = cpl_mask_get_data(in); - cpl_binary * dataout; - cpl_mask * out; - const double * ker_arr; - int nc, nr; - int hsx, hsy; - int curr_pos, im_pos, filt_pos; - int i, j, k, l; +static cpl_error_code +cpl_mask_erosion_matrix(cpl_mask *in, const cpl_matrix *ker) +{ + const int nx = cpl_mask_get_size_x(in); + const int ny = cpl_mask_get_size_y(in); + cpl_binary *datain = cpl_mask_get_data(in); + cpl_binary *dataout; + cpl_mask *out; + const double *ker_arr; + int nc, nr; + int hsx, hsy; + int curr_pos, im_pos, filt_pos; + int i, j, k, l; /* Test entries */ cpl_ensure_code(in && ker, CPL_ERROR_NULL_INPUT); @@ -2083,33 +2145,34 @@ ker_arr = cpl_matrix_get_data_const(ker); /* Test the kernel validity */ - cpl_ensure_code(nc%2 && nr%2, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(nc<=31 && nr<=31, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(nc % 2 && nr % 2, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(nc <= 31 && nr <= 31, CPL_ERROR_ILLEGAL_INPUT); /* Initialise */ - hsx = (nc-1) / 2; - hsy = (nr-1) / 2; + hsx = (nc - 1) / 2; + hsy = (nr - 1) / 2; /* Create a tmp mask */ out = cpl_mask_new(nx, ny); dataout = cpl_mask_get_data(out); /* Main filter loop */ - for (j=0; j=nx-hsx) || (j=ny-hsy)) { + if ((i < hsx) || (i >= nx - hsx) || (j < hsy) || (j >= ny - hsy)) { dataout[curr_pos] = CPL_BINARY_0; - } else { + } + else { /* Initialise */ dataout[curr_pos] = CPL_BINARY_1; /* Go into upper left corner of current pixel */ - im_pos = curr_pos - hsx + hsy*nx; + im_pos = curr_pos - hsx + hsy * nx; filt_pos = 0; - for (k=0; k FLT_MIN)) (dataout)[curr_pos] = CPL_BINARY_0; @@ -2146,20 +2209,19 @@ - CPL_ERROR_ILLEGAL_INPUT if the kernel is not as requested */ /*----------------------------------------------------------------------------*/ -static cpl_error_code cpl_mask_dilation_matrix( - cpl_mask * in, - const cpl_matrix * ker) +static cpl_error_code +cpl_mask_dilation_matrix(cpl_mask *in, const cpl_matrix *ker) { const int nx = cpl_mask_get_size_x(in); const int ny = cpl_mask_get_size_y(in); - cpl_binary * datain = cpl_mask_get_data(in); - cpl_binary * dataout; - cpl_mask * out; - const double * ker_arr; - int nc, nr; - int hsx, hsy; - int curr_pos, im_pos, filt_pos; - int i, j, k, l; + cpl_binary *datain = cpl_mask_get_data(in); + cpl_binary *dataout; + cpl_mask *out; + const double *ker_arr; + int nc, nr; + int hsx, hsy; + int curr_pos, im_pos, filt_pos; + int i, j, k, l; /* Test entries */ cpl_ensure_code(in && ker, CPL_ERROR_NULL_INPUT); @@ -2170,35 +2232,36 @@ ker_arr = cpl_matrix_get_data_const(ker); /* Test the kernel validity */ - cpl_ensure_code(nc%2 && nr%2, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(nc<=31 && nr<=31, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(nc % 2 && nr % 2, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(nc <= 31 && nr <= 31, CPL_ERROR_ILLEGAL_INPUT); /* Initialise */ - hsx = (nc-1) / 2; - hsy = (nr-1) / 2; + hsx = (nc - 1) / 2; + hsy = (nr - 1) / 2; /* Create a tmp mask */ out = cpl_mask_new(nx, ny); dataout = cpl_mask_get_data(out); /* Main filter loop */ - for (j=0; j=nx-hsx) || (j=ny-hsy)) { + if ((i < hsx) || (i >= nx - hsx) || (j < hsy) || (j >= ny - hsy)) { (dataout)[curr_pos] = CPL_BINARY_0; - } else { + } + else { /* Initialise */ (dataout)[curr_pos] = CPL_BINARY_0; /* Go into upper left corner of current pixel */ - im_pos = curr_pos - hsx + hsy*nx; + im_pos = curr_pos - hsx + hsy * nx; filt_pos = 0; - for (k=0; k FLT_MIN)) + (fabs(ker_arr[filt_pos]) > FLT_MIN)) (dataout)[curr_pos] = CPL_BINARY_1; /* Next col */ filt_pos++; @@ -2216,7 +2279,6 @@ } - /*----------------------------------------------------------------------------*/ /** @brief Brute force (single byte) filter a mask using a binary kernel @@ -2231,31 +2293,32 @@ */ /*----------------------------------------------------------------------------*/ -static cpl_error_code cpl_mask_filter_bf(cpl_mask * self, const cpl_mask * other, - const cpl_mask * kernel, - cpl_filter_mode filter, - cpl_border_mode border) +static cpl_error_code +cpl_mask_filter_bf(cpl_mask *self, + const cpl_mask *other, + const cpl_mask *kernel, + cpl_filter_mode filter, + cpl_border_mode border) { - /* Modified from cpl_mask_filter() :-((((( */ - const int nsx = cpl_mask_get_size_x(self); - const int nsy = cpl_mask_get_size_y(self); - const int nx = cpl_mask_get_size_x(other); - const int ny = cpl_mask_get_size_y(other); - const int mx = cpl_mask_get_size_x(kernel); - const int my = cpl_mask_get_size_y(kernel); + const int nsx = cpl_mask_get_size_x(self); + const int nsy = cpl_mask_get_size_y(self); + const int nx = cpl_mask_get_size_x(other); + const int ny = cpl_mask_get_size_y(other); + const int mx = cpl_mask_get_size_x(kernel); + const int my = cpl_mask_get_size_y(kernel); const int hsizex = mx >> 1; const int hsizey = my >> 1; - const cpl_binary * pmask = cpl_mask_get_data_const(kernel); - const cpl_binary * pother = cpl_mask_get_data_const(other); - cpl_binary * pself = cpl_mask_get_data(self); + const cpl_binary *pmask = cpl_mask_get_data_const(kernel); + const cpl_binary *pother = cpl_mask_get_data_const(other); + cpl_binary *pself = cpl_mask_get_data(self); /* assert( sizeof(cpl_binary) == 1 ) */ - const cpl_binary * polast = pother + nx * ny; - const cpl_binary * psrows = pself + nsx * (1 + hsizey); + const cpl_binary *polast = pother + nx * ny; + const cpl_binary *psrows = pself + nsx * (1 + hsizey); /* pmask may not overlap pself at all */ - const cpl_binary * pmlast = pmask + mx * my; - const cpl_binary * pslast = pself + nsx * nsy; + const cpl_binary *pmlast = pmask + mx * my; + const cpl_binary *pslast = pself + nsx * nsy; /* In filtering it is generally faster with a special case for the full kernel. Some tests indicate that this is not the case of mask filtering. This may be due to the typically small kernels @@ -2265,20 +2328,22 @@ int, int, int, int, cpl_border_mode); - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(other != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(other != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(kernel != NULL, CPL_ERROR_NULL_INPUT); if (filter == CPL_FILTER_OPENING || filter == CPL_FILTER_CLOSING) { cpl_ensure_code(border == CPL_BORDER_ZERO || border == CPL_BORDER_COPY, CPL_ERROR_UNSUPPORTED_MODE); - } else { + } + else { /* pself has to be above all of the other buffer, or */ /* ...pother has to be above the first hsize+1 rows of pself */ cpl_ensure_code(pself >= polast || pother >= psrows, CPL_ERROR_UNSUPPORTED_MODE); cpl_ensure_code(border == CPL_BORDER_NOP || border == CPL_BORDER_ZERO || - border == CPL_BORDER_COPY, CPL_ERROR_UNSUPPORTED_MODE); + border == CPL_BORDER_COPY, + CPL_ERROR_UNSUPPORTED_MODE); } /* If this check fails, the caller is doing something really weird... */ @@ -2286,8 +2351,8 @@ CPL_ERROR_UNSUPPORTED_MODE); /* Only odd-sized masks allowed */ - cpl_ensure_code((mx&1) == 1, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code((my&1) == 1, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code((mx & 1) == 1, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code((my & 1) == 1, CPL_ERROR_ILLEGAL_INPUT); cpl_ensure_code(mx <= nx, CPL_ERROR_ACCESS_OUT_OF_RANGE); cpl_ensure_code(my <= ny, CPL_ERROR_ACCESS_OUT_OF_RANGE); @@ -2296,12 +2361,11 @@ cpl_ensure_code(nsx == nx - 2 * hsizex, CPL_ERROR_INCOMPATIBLE_INPUT); cpl_ensure_code(nsy == ny - 2 * hsizey, CPL_ERROR_INCOMPATIBLE_INPUT); - - } else { + } + else { cpl_ensure_code(nsx == nx, CPL_ERROR_INCOMPATIBLE_INPUT); cpl_ensure_code(nsy == ny, CPL_ERROR_INCOMPATIBLE_INPUT); - } cpl_ensure_code(!cpl_mask_is_empty(kernel), CPL_ERROR_DATA_NOT_FOUND); @@ -2310,19 +2374,21 @@ if (filter == CPL_FILTER_EROSION) { filter_func = cpl_mask_erosion_bf; - } else if (filter == CPL_FILTER_DILATION) { + } + else if (filter == CPL_FILTER_DILATION) { filter_func = cpl_mask_dilation_bf; - } else if (filter == CPL_FILTER_OPENING) { + } + else if (filter == CPL_FILTER_OPENING) { filter_func = cpl_mask_opening_bf; - } else if (filter == CPL_FILTER_CLOSING) { + } + else if (filter == CPL_FILTER_CLOSING) { filter_func = cpl_mask_closing_bf; } if (filter_func != NULL) { - filter_func(pself, pother, pmask, nx, ny, hsizex, hsizey, border); - - } else { + } + else { return cpl_error_set(cpl_func, CPL_ERROR_UNSUPPORTED_MODE); } @@ -2348,12 +2414,16 @@ */ /*----------------------------------------------------------------------------*/ -static -void cpl_mask_erosion_bf(cpl_binary * self, const cpl_binary * other, - const cpl_binary * kernel, - int nx, int ny, int hx, int hy, cpl_border_mode border) +static void +cpl_mask_erosion_bf(cpl_binary *self, + const cpl_binary *other, + const cpl_binary *kernel, + int nx, + int ny, + int hx, + int hy, + cpl_border_mode border) { - /* Modified from cpl_mask_erosion_() :-((((( */ if (border == CPL_BORDER_NOP || border == CPL_BORDER_ZERO || @@ -2364,35 +2434,38 @@ /* Handle border for first hy rows and first hx elements of next row */ if (border == CPL_BORDER_ZERO) { (void)memset(self, CPL_BINARY_0, hx + hy * nx); - } else if (border == CPL_BORDER_COPY) { + } + else if (border == CPL_BORDER_COPY) { (void)memcpy(self, other, hx + hy * nx); } - self += hy * nx; + self += hy * nx; kernel += hx; - for (j = hy; j < ny-hy; j++, self += nx, other += nx) { - + for (j = hy; j < ny - hy; j++, self += nx, other += nx) { if (j > hy) { /* Do also last hx border elements of previous row */ if (border == CPL_BORDER_ZERO) { (void)memset(self - hx, CPL_BINARY_0, 2 * hx); - } else if (border == CPL_BORDER_COPY) { + } + else if (border == CPL_BORDER_COPY) { (void)memcpy(self - hx, other - hx + hy * nx, 2 * hx); } } - for (i = hx; i < nx-hx; i++) { - const cpl_binary * otheri = other + i; - const cpl_binary * kernelk = kernel; + for (i = hx; i < nx - hx; i++) { + const cpl_binary *otheri = other + i; + const cpl_binary *kernelk = kernel; int k, l; for (k = -hy; k <= hy; k++, otheri += nx, kernelk += mx) { /* FIXME: Do binary ops using 64, 32, 16 bit integers */ for (l = -hx; l <= hx; l++) { - if (!otheri[l] && kernelk[l]) break; + if (!otheri[l] && kernelk[l]) + break; } - if (l <= hx) break; + if (l <= hx) + break; } self[i] = k <= hy ? CPL_BINARY_0 : CPL_BINARY_1; } @@ -2401,7 +2474,8 @@ /* Do also last hx border elements of previous row */ if (border == CPL_BORDER_ZERO) { (void)memset(self - hx, CPL_BINARY_0, hx + hy * nx); - } else if (border == CPL_BORDER_COPY) { + } + else if (border == CPL_BORDER_COPY) { (void)memcpy(self - hx, other - hx + hy * nx, hx + hy * nx); } } @@ -2428,12 +2502,16 @@ */ /*----------------------------------------------------------------------------*/ -static -void cpl_mask_dilation_bf(cpl_binary * self, const cpl_binary * other, - const cpl_binary * kernel, - int nx, int ny, int hx, int hy, cpl_border_mode border) +static void +cpl_mask_dilation_bf(cpl_binary *self, + const cpl_binary *other, + const cpl_binary *kernel, + int nx, + int ny, + int hx, + int hy, + cpl_border_mode border) { - if (border == CPL_BORDER_NOP || border == CPL_BORDER_ZERO || border == CPL_BORDER_COPY) { const int mx = 2 * hx + 1; @@ -2442,35 +2520,38 @@ /* Handle border for first hy rows and first hx elements of next row */ if (border == CPL_BORDER_ZERO) { (void)memset(self, CPL_BINARY_0, hx + hy * nx); - } else if (border == CPL_BORDER_COPY) { + } + else if (border == CPL_BORDER_COPY) { (void)memcpy(self, other, hx + hy * nx); } - self += hy * nx; /* self-col now indexed from -hy to hy */ + self += hy * nx; /* self-col now indexed from -hy to hy */ kernel += hx; - for (j = hy; j < ny-hy; j++, self += nx, other += nx) { - + for (j = hy; j < ny - hy; j++, self += nx, other += nx) { if (j > hy) { /* Do also last hx border elements of previous row */ if (border == CPL_BORDER_ZERO) { (void)memset(self - hx, CPL_BINARY_0, 2 * hx); - } else if (border == CPL_BORDER_COPY) { + } + else if (border == CPL_BORDER_COPY) { (void)memcpy(self - hx, other - hx + hy * nx, 2 * hx); } } - for (i = hx; i < nx-hx; i++) { - const cpl_binary * otheri = other + i; - const cpl_binary * kernelk = kernel; + for (i = hx; i < nx - hx; i++) { + const cpl_binary *otheri = other + i; + const cpl_binary *kernelk = kernel; int k, l; for (k = -hy; k <= hy; k++, otheri += nx, kernelk += mx) { /* FIXME: Do binary ops using 64, 32, 16 bit integers */ for (l = -hx; l <= hx; l++) { - if (otheri[l] && kernelk[l]) break; + if (otheri[l] && kernelk[l]) + break; } - if (l <= hx) break; + if (l <= hx) + break; } self[i] = k <= hy ? CPL_BINARY_1 : CPL_BINARY_0; } @@ -2479,7 +2560,8 @@ /* Do also last hx border elements of previous row */ if (border == CPL_BORDER_ZERO) { (void)memset(self - hx, CPL_BINARY_0, hx + hy * nx); - } else if (border == CPL_BORDER_COPY) { + } + else if (border == CPL_BORDER_COPY) { (void)memcpy(self - hx, other - hx + hy * nx, hx + hy * nx); } } @@ -2502,12 +2584,17 @@ */ /*----------------------------------------------------------------------------*/ -static -void cpl_mask_opening_bf(cpl_binary * self, const cpl_binary * other, - const cpl_binary * kernel, - int nx, int ny, int hx, int hy, cpl_border_mode border) +static void +cpl_mask_opening_bf(cpl_binary *self, + const cpl_binary *other, + const cpl_binary *kernel, + int nx, + int ny, + int hx, + int hy, + cpl_border_mode border) { - cpl_binary * middle = cpl_malloc((size_t)nx * ny * sizeof(cpl_binary)); + cpl_binary *middle = cpl_malloc((size_t)nx * ny * sizeof(cpl_binary)); cpl_mask_erosion_bf(middle, other, kernel, nx, ny, hx, hy, border); cpl_mask_dilation_bf(self, middle, kernel, nx, ny, hx, hy, border); @@ -2531,15 +2618,20 @@ */ /*----------------------------------------------------------------------------*/ -static -void cpl_mask_closing_bf(cpl_binary * self, const cpl_binary * other, - const cpl_binary * kernel, - int nx, int ny, int hx, int hy, cpl_border_mode border) +static void +cpl_mask_closing_bf(cpl_binary *self, + const cpl_binary *other, + const cpl_binary *kernel, + int nx, + int ny, + int hx, + int hy, + cpl_border_mode border) { - cpl_binary * middle = cpl_malloc((size_t)nx * ny * sizeof(cpl_binary)); + cpl_binary *middle = cpl_malloc((size_t)nx * ny * sizeof(cpl_binary)); cpl_mask_dilation_bf(middle, other, kernel, nx, ny, hx, hy, border); - cpl_mask_erosion_bf(self, middle, kernel, nx, ny, hx, hy, border); + cpl_mask_erosion_bf(self, middle, kernel, nx, ny, hx, hy, border); cpl_free(middle); } @@ -2567,11 +2659,11 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_mask_flip_turn_test(const cpl_mask * self) +static void +cpl_mask_flip_turn_test(const cpl_mask *self) { - cpl_error_code error; - cpl_mask * tmp = cpl_mask_duplicate(self); + cpl_mask *tmp = cpl_mask_duplicate(self); error = cpl_mask_turn(tmp, -1); cpl_test_eq_error(error, CPL_ERROR_NONE); @@ -2609,14 +2701,15 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_mask_count_window_test(int mx, int my) +static void +cpl_mask_count_window_test(int mx, int my) { int ntested = 0; for (int nx = 1; nx <= mx; nx++) { for (int ny = 1; ny <= my; ny++) { - cpl_mask * maskoff = cpl_mask_new(nx, ny); - cpl_mask * maskon = cpl_mask_new(nx, ny); + cpl_mask *maskoff = cpl_mask_new(nx, ny); + cpl_mask *maskon = cpl_mask_new(nx, ny); const cpl_error_code error = cpl_mask_not(maskon); cpl_test_eq_error(error, CPL_ERROR_NONE); @@ -2625,14 +2718,14 @@ for (int lly = 1; lly <= ny; lly++) { for (int urx = llx; urx <= nx; urx++) { for (int ury = lly; ury <= ny; ury++) { - const int ncount = (1 + urx - llx) - * (1 + ury - lly); + const int ncount = + (1 + urx - llx) * (1 + ury - lly); const cpl_size ijon = - cpl_mask_count_window(maskon, llx, lly, - urx, ury); + cpl_mask_count_window(maskon, llx, lly, urx, + ury); const cpl_size ijoff = - cpl_mask_count_window(maskoff, llx, lly, - urx, ury); + cpl_mask_count_window(maskoff, llx, lly, urx, + ury); cpl_test_error(CPL_ERROR_NONE); cpl_test_zero(ijoff); @@ -2647,6 +2740,8 @@ } } - cpl_msg_info(cpl_func, "Tests of cpl_mask_count_window() w. %d X %d mask: " - "%d", mx, my, ntested); + cpl_msg_info(cpl_func, + "Tests of cpl_mask_count_window() w. %d X %d mask: " + "%d", + mx, my, ntested); } diff -Nru cpl-7.1.4+ds/cplcore/tests/cpl_math-test.c cpl-7.2.2+ds/cplcore/tests/cpl_math-test.c --- cpl-7.1.4+ds/cplcore/tests/cpl_math-test.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/tests/cpl_math-test.c 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -43,7 +43,8 @@ /*----------------------------------------------------------------------------- Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { const double prec = CPL_MATH_PRECISION * DBL_EPSILON; @@ -68,13 +69,13 @@ cpl_test_rel(atan2(1.0, 1.0), CPL_MATH_PI_4, prec); /* 1/pi */ - cpl_test_rel(1.0/atan2(0.0, -1.0), CPL_MATH_1_PI, 2.0 * prec); + cpl_test_rel(1.0 / atan2(0.0, -1.0), CPL_MATH_1_PI, 2.0 * prec); /* 2/pi */ - cpl_test_rel(1.0/atan2(1.0, 0.0), CPL_MATH_2_PI, 2.0 * prec); + cpl_test_rel(1.0 / atan2(1.0, 0.0), CPL_MATH_2_PI, 2.0 * prec); /* 4/pi */ - cpl_test_rel(1.0/atan2(1.0, 1.0), CPL_MATH_4_PI, 2.0 * prec); + cpl_test_rel(1.0 / atan2(1.0, 1.0), CPL_MATH_4_PI, 2.0 * prec); /* sqrt(2pi) */ cpl_test_rel(sqrt(2.0 * atan2(0.0, -1.0)), CPL_MATH_SQRT2PI, 2.0 * prec); @@ -101,7 +102,7 @@ cpl_test_rel(log(10.0), CPL_MATH_LN10, prec); /* log2(e) */ - cpl_test_rel(1.0/log(2.0), CPL_MATH_LOG2E, 2.0 * prec); + cpl_test_rel(1.0 / log(2.0), CPL_MATH_LOG2E, 2.0 * prec); /* log10(e) */ cpl_test_rel(log10(exp(1.0)), CPL_MATH_LOG10E, prec); @@ -113,10 +114,10 @@ cpl_test_rel(CPL_MATH_RAD_DEG * CPL_MATH_DEG_RAD, 1.0, prec); /* 2.0*sqrt(2.0*log(2.0)) */ - cpl_test_rel(2.0*sqrt(2.0*log(2.0)), CPL_MATH_FWHM_SIG, prec); + cpl_test_rel(2.0 * sqrt(2.0 * log(2.0)), CPL_MATH_FWHM_SIG, prec); /* 0.5/sqrt(2.0*log(2.0)) */ - cpl_test_rel(0.5/sqrt(2.0*log(2.0)), CPL_MATH_SIG_FWHM, 2.0 * prec); + cpl_test_rel(0.5 / sqrt(2.0 * log(2.0)), CPL_MATH_SIG_FWHM, 2.0 * prec); cpl_test_zero(CPL_MIN(0, 1)); cpl_test_zero(CPL_MAX(0, -1)); diff -Nru cpl-7.1.4+ds/cplcore/tests/cpl_matrix-test.c cpl-7.2.2+ds/cplcore/tests/cpl_matrix-test.c --- cpl-7.1.4+ds/cplcore/tests/cpl_matrix-test.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/tests/cpl_matrix-test.c 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -25,7 +25,7 @@ Includes -----------------------------------------------------------------------------*/ -#define _XOPEN_SOURCE 500 // snprintf +#define _XOPEN_SOURCE 500 // snprintf #include #include @@ -49,12 +49,12 @@ * m = message */ -#define test_data(r,f,m) \ - do { \ - cpl_msg_info("", "%s", m); \ - r = (f); \ - cpl_test_error(CPL_ERROR_NONE); \ - cpl_test_nonnull(r); \ +#define test_data(r, f, m) \ + do { \ + cpl_msg_info("", "%s", m); \ + r = (f); \ + cpl_test_error(CPL_ERROR_NONE); \ + cpl_test_nonnull(r); \ } while (0) /* @@ -64,10 +64,10 @@ * m = message */ -#define test(f, m) \ - do { \ - cpl_msg_info("", "%s", m); \ - cpl_test_zero(f); \ +#define test(f, m) \ + do { \ + cpl_msg_info("", "%s", m); \ + cpl_test_zero(f); \ } while (0) @@ -78,10 +78,10 @@ * m = message */ -#define test_failure(f,m) \ - do { \ - cpl_msg_info("", "%s", m); \ - cpl_test(f); \ +#define test_failure(f, m) \ + do { \ + cpl_msg_info("", "%s", m); \ + cpl_test(f); \ } while (0) /* @@ -92,11 +92,11 @@ * m = message */ -#define test_ivalue(e,f,m) \ - do { \ - cpl_msg_info("", "%s", m); \ - cpl_test_eq(e, f); \ - } while (0) +#define test_ivalue(e, f, m) \ + do { \ + cpl_msg_info("", "%s", m); \ + cpl_test_eq(e, f); \ + } while (0) /* * Test for functions returning an expected floating point value. @@ -105,9 +105,8 @@ * t = tolerance on expected value * f = function call */ - -#define test_fvalue_(e,t,f) \ - cpl_test_abs(e, f, t) + +#define test_fvalue_(e, t, f) cpl_test_abs(e, f, t) /* * Test for functions returning an expected floating point value. @@ -117,12 +116,12 @@ * f = function call * m = message */ - -#define test_fvalue(e,t,f,m) \ - do { \ - cpl_msg_info("", "%s", m); \ - test_fvalue_(e,t,f); \ - } while (0) + +#define test_fvalue(e, t, f, m) \ + do { \ + cpl_msg_info("", "%s", m); \ + test_fvalue_(e, t, f); \ + } while (0) /*----------------------------------------------------------------------------- @@ -138,91 +137,83 @@ static void cpl_matrix_product_transpose_bench(int, int); static void cpl_matrix_solve_normal_bench(int, int); static void cpl_matrix_product_bilinear_test(cpl_size, cpl_size, cpl_boolean); -static cpl_matrix * cpl_matrix_product_bilinear_brute(const cpl_matrix *, - const cpl_matrix *); +static cpl_matrix * +cpl_matrix_product_bilinear_brute(const cpl_matrix *, const cpl_matrix *); static cpl_error_code cpl_matrix_shift_brute(cpl_matrix *, cpl_size, cpl_size); /*----------------------------------------------------------------------------- main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { - - const int nreps = 1; /* This is currently enough to expose the trouble */ - int nelem = 70; - int subnelem = 10; - int size; - - double a2390[] = {2.125581475848425e-314, 3.952525166729972e-323, - -0.000000000000000e+00, -2.393462054246040e-162, - 3.952525166729972e-323, 1.677069691870074e-311, - -0.000000000000000e+00, -6.726400100717507e-161, - -0.000000000000000e+00, -0.000000000000000e+00, - 0.000000000000000e+00, 1.172701769974922e-171, - -2.393462054246040e-162, -6.726400100717507e-161, - 1.172701769974922e-171, 6.189171527656329e+10}; - double b2390[] = {-1.709710615916477e-161, - -4.805142076113790e-160, - 8.376377601213216e-171, - 4.962260007044318e+01}; - - double a3097[] = {22.3366126198544243663945962908, - -16.2991659056583451103961124318, - 0.0747823788545301237906670621669, - 0.0237870531554605392499102123338, - - -16.2991659056583451103961124318, - 17.2102745748494783128990093246, - -0.124262796786316020991591813072, - 0.00881594777810015828301004603418, - - 0.0747823788545301237906670621669, - -0.124262796786316020991591813072, - 0.00370155728670603376487258096006, - 0.00719839528504809342962511564679, - - 0.0237870531554605392499102123338, - 0.00881594777810015828301004603418, - 0.00719839528504809342962511564679, - 0.0220958028150731733418865587737}; - - double b3097[] = {1, 2, 3, 4}; - - - double *dArray; - double *subdArray; - double value; - cpl_size i, j, k, l = 0; /* FIXME: What is l used for ? */ - cpl_size r, c; - - cpl_matrix *matrix; - cpl_matrix *copia; - cpl_matrix *copy; - cpl_matrix *product; - - cpl_matrix * xtrue; /* The true solution */ - cpl_matrix * xsolv; /* The solution computed by the cpl_matrix solver */ - FILE * stream; - const double * data; - cpl_boolean do_bench; - cpl_boolean did_fail; + const int nreps = 1; /* This is currently enough to expose the trouble */ + int nelem = 70; + int subnelem = 10; + int size; + + double a2390[] = { 2.125581475848425e-314, 3.952525166729972e-323, + -0.000000000000000e+00, -2.393462054246040e-162, + 3.952525166729972e-323, 1.677069691870074e-311, + -0.000000000000000e+00, -6.726400100717507e-161, + -0.000000000000000e+00, -0.000000000000000e+00, + 0.000000000000000e+00, 1.172701769974922e-171, + -2.393462054246040e-162, -6.726400100717507e-161, + 1.172701769974922e-171, 6.189171527656329e+10 }; + double b2390[] = { -1.709710615916477e-161, -4.805142076113790e-160, + 8.376377601213216e-171, 4.962260007044318e+01 }; + + double a3097[] = { + 22.3366126198544243663945962908, -16.2991659056583451103961124318, + 0.0747823788545301237906670621669, 0.0237870531554605392499102123338, + + -16.2991659056583451103961124318, 17.2102745748494783128990093246, + -0.124262796786316020991591813072, 0.00881594777810015828301004603418, + + 0.0747823788545301237906670621669, -0.124262796786316020991591813072, + 0.00370155728670603376487258096006, 0.00719839528504809342962511564679, + + 0.0237870531554605392499102123338, 0.00881594777810015828301004603418, + 0.00719839528504809342962511564679, 0.0220958028150731733418865587737 + }; + + double b3097[] = { 1, 2, 3, 4 }; + + + double *dArray; + double *subdArray; + double value; + cpl_size i, j, k, l = 0; /* FIXME: What is l used for ? */ + cpl_size r, c; + + cpl_matrix *matrix; + cpl_matrix *copia; + cpl_matrix *copy; + cpl_matrix *product; + + cpl_matrix *xtrue; /* The true solution */ + cpl_matrix *xsolv; /* The solution computed by the cpl_matrix solver */ + FILE *stream; + const double *data; + cpl_boolean do_bench; + cpl_boolean did_fail; cpl_error_code code; - const cpl_matrix * null; /* This one is expected to be NULL */ + const cpl_matrix *null; /* This one is expected to be NULL */ cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); do_bench = cpl_msg_get_level() <= CPL_MSG_INFO ? CPL_TRUE : CPL_FALSE; - /* + /* * Testing begins here */ - stream = cpl_msg_get_level() > CPL_MSG_INFO - ? fopen("/dev/null", "a") : stdout; + stream = + cpl_msg_get_level() > CPL_MSG_INFO ? fopen("/dev/null", "a") : stdout; - cpl_test_nonnull( stream ); + cpl_test_nonnull(stream); cpl_matrix_test_banded(10, 1); cpl_matrix_test_banded(10, 2); @@ -270,24 +261,22 @@ xsolv = cpl_matrix_solve(matrix, copia); if (cpl_error_get_code() == CPL_ERROR_SINGULAR_MATRIX) { - cpl_test_error(CPL_ERROR_SINGULAR_MATRIX); cpl_test_null(xsolv); - cpl_msg_info(cpl_func, "cpl_matrix_solve() classified a near-" + cpl_msg_info(cpl_func, + "cpl_matrix_solve() classified a near-" "singular matrix as singular. This is not a bug, " "but it indicates that cpl_matrix_solve() is less " "accurate on this computer. This loss of accuracy may " "be caused by compiling CPL with optimization"); cpl_test_abs(cpl_matrix_get_determinant(matrix), 0.0, 0.0); - - } else { - + } + else { cpl_test_nonnull(xsolv); test_fvalue(0.0, DBL_EPSILON, cpl_matrix_get_determinant(matrix), "Compute determinant of an ill-conditioned matrix"); - } @@ -308,21 +297,21 @@ if (cpl_error_get_code() == CPL_ERROR_SINGULAR_MATRIX) { cpl_test_null(xsolv); cpl_test_error(CPL_ERROR_SINGULAR_MATRIX); - cpl_msg_warning(cpl_func, "cpl_matrix_solve() classified a near-" + cpl_msg_warning(cpl_func, + "cpl_matrix_solve() classified a near-" "singular matrix as singular. This is not a bug, " "but it indicates that cpl_matrix_solve() is less " "accurate on this computer"); xsolv = cpl_matrix_duplicate(copia); - } else { + } + else { cpl_matrix_dump(xsolv, stream); value = cpl_matrix_get_mean(xsolv); cpl_test_error(CPL_ERROR_NONE); - cpl_test( value == value); /* Check for NaNs */ - - + cpl_test(value == value); /* Check for NaNs */ } cpl_matrix_unwrap(copia); @@ -336,1397 +325,1464 @@ cpl_matrix_delete(xsolv); cpl_matrix_unwrap(matrix); - test_data(matrix, cpl_matrix_new(7, 10), "Creating the test matrix... "); + test_data(matrix, cpl_matrix_new(7, 10), "Creating the test matrix... "); - cpl_matrix_delete(matrix); + cpl_matrix_delete(matrix); - r = 7; - c = 10; - test_data(matrix, cpl_matrix_new(r, c), "Creating another test matrix... "); - - cpl_matrix_fill(matrix, 13.565656565); - - for (i = 0; i < r; i++) { - for (j = 0; j < c; j++) { - cpl_msg_info(cpl_func, - "Check element %" CPL_SIZE_FORMAT ", %" - CPL_SIZE_FORMAT " of constant matrix... ", i, j); - test_fvalue_(13.565656565, .000001, cpl_matrix_get(matrix, i, j)); - } - } + r = 7; + c = 10; + test_data(matrix, cpl_matrix_new(r, c), "Creating another test matrix... "); + + cpl_matrix_fill(matrix, 13.565656565); + + for (i = 0; i < r; i++) { + for (j = 0; j < c; j++) { + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT + " of constant matrix... ", + i, j); + test_fvalue_(13.565656565, .000001, cpl_matrix_get(matrix, i, j)); + } + } - cpl_matrix_delete(matrix); + cpl_matrix_delete(matrix); -/* + /* test_data(matrix, cpl_matrix_new_identity(3), "Creating identity matrix... "); */ - matrix = cpl_matrix_new(3, 3); - for (i = 0; i < 3; i++) - cpl_matrix_set(matrix, i, i, 1); - - test_ivalue(1, cpl_matrix_is_identity(matrix, -1.), - "Checking if matrix is identity... "); - - cpl_matrix_delete(matrix); - - dArray = cpl_malloc((size_t)nelem * sizeof(double)); - - value = 9.00; - for (i = 0; i < nelem; i++) { - dArray[i] = value; - value += .01; - } - - subdArray = cpl_malloc((size_t)subnelem * sizeof(double)); - - value = 1.00; - for (i = 0; i < subnelem; i++) { - subdArray[i] = value; - value += .01; - } + matrix = cpl_matrix_new(3, 3); + for (i = 0; i < 3; i++) + cpl_matrix_set(matrix, i, i, 1); -/* + test_ivalue(1, cpl_matrix_is_identity(matrix, -1.), + "Checking if matrix is identity... "); + + cpl_matrix_delete(matrix); + + dArray = cpl_malloc((size_t)nelem * sizeof(double)); + + value = 9.00; + for (i = 0; i < nelem; i++) { + dArray[i] = value; + value += .01; + } + + subdArray = cpl_malloc((size_t)subnelem * sizeof(double)); + + value = 1.00; + for (i = 0; i < subnelem; i++) { + subdArray[i] = value; + value += .01; + } + + /* test_data(matrix, cpl_matrix_new_diagonal(dArray, 5), "Creating diagonal matrix... "); */ - matrix = cpl_matrix_new(5, 5); - for (i = 0; i < 5; i++) - cpl_matrix_set(matrix, i, i, dArray[i]); + matrix = cpl_matrix_new(5, 5); + for (i = 0; i < 5; i++) + cpl_matrix_set(matrix, i, i, dArray[i]); - test_ivalue(1, cpl_matrix_is_diagonal(matrix, -1.), - "Checking if matrix is diagonal... "); + test_ivalue(1, cpl_matrix_is_diagonal(matrix, -1.), + "Checking if matrix is diagonal... "); - cpl_matrix_delete(matrix); + cpl_matrix_delete(matrix); - test_data(matrix, cpl_matrix_wrap(7, 10, dArray), - "Creating the final test matrix... "); + test_data(matrix, cpl_matrix_wrap(7, 10, dArray), + "Creating the final test matrix... "); - test_fvalue(9.57, .001, cpl_matrix_get(matrix, 5, 7), - "Reading a matrix element... "); + test_fvalue(9.57, .001, cpl_matrix_get(matrix, 5, 7), + "Reading a matrix element... "); -/* + /* test_failure(cpl_matrix_set(matrix, 10, 10, 1.00), "Writing a matrix element out of range... "); */ - test(cpl_matrix_set(matrix, 6, 5, 1.00), - "Writing a matrix element... "); + test(cpl_matrix_set(matrix, 6, 5, 1.00), "Writing a matrix element... "); - test_fvalue(1.00, .001, cpl_matrix_get(matrix, 6, 5), - "Reading just written matrix element... "); + test_fvalue(1.00, .001, cpl_matrix_get(matrix, 6, 5), + "Reading just written matrix element... "); - test_data(copia, cpl_matrix_duplicate(matrix), "Copy a matrix... "); + test_data(copia, cpl_matrix_duplicate(matrix), "Copy a matrix... "); - test(cpl_matrix_subtract(copia, matrix), "Subtract original from copy... "); + test(cpl_matrix_subtract(copia, matrix), "Subtract original from copy... "); - test_ivalue(1, cpl_matrix_is_zero(copia, -1), "Check if result is zero... "); + test_ivalue(1, cpl_matrix_is_zero(copia, -1), + "Check if result is zero... "); - cpl_matrix_delete(copia); + cpl_matrix_delete(copia); - test_data(copia, cpl_matrix_extract(matrix, 2, 3, 1, 1, 4, 3), - "Extracting submatrix... "); + test_data(copia, cpl_matrix_extract(matrix, 2, 3, 1, 1, 4, 3), + "Extracting submatrix... "); - test_fvalue(9.44, .001, cpl_matrix_get(copia, 2, 1), - "Reading a submatrix element... "); + test_fvalue(9.44, .001, cpl_matrix_get(copia, 2, 1), + "Reading a submatrix element... "); - cpl_matrix_delete(copia); + cpl_matrix_delete(copia); - test_data(copia, cpl_matrix_extract(matrix, 4, 4, 1, 1, 1000, 1000), - "Extracting submatrix (beyond upper boundaries)... "); + test_data(copia, cpl_matrix_extract(matrix, 4, 4, 1, 1, 1000, 1000), + "Extracting submatrix (beyond upper boundaries)... "); - test_fvalue(9.55, .001, cpl_matrix_get(copia, 1, 1), - "Reading new submatrix element... "); + test_fvalue(9.55, .001, cpl_matrix_get(copia, 1, 1), + "Reading new submatrix element... "); - cpl_matrix_delete(copia); + cpl_matrix_delete(copia); - test_data(copia, cpl_matrix_extract(matrix, 0, 0, 3, 3, 1000, 1000), - "Extracting submatrix (step 3, beyond boundaries)... "); + test_data(copia, cpl_matrix_extract(matrix, 0, 0, 3, 3, 1000, 1000), + "Extracting submatrix (step 3, beyond boundaries)... "); - test_fvalue(9.33, .001, cpl_matrix_get(copia, 1, 1), - "Reading new submatrix element... "); + test_fvalue(9.33, .001, cpl_matrix_get(copia, 1, 1), + "Reading new submatrix element... "); - cpl_matrix_delete(copia); + cpl_matrix_delete(copia); - /* Test error handling for invalid input: */ - null = cpl_matrix_extract_row(NULL, 1); - cpl_test_error(CPL_ERROR_NULL_INPUT); - cpl_test_null(null); - null = cpl_matrix_extract_row(matrix, 9999999); - cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); - cpl_test_null(null); - null = cpl_matrix_extract_row(matrix, -1); - cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); - cpl_test_null(null); - null = cpl_matrix_extract_column(NULL, 1); - cpl_test_error(CPL_ERROR_NULL_INPUT); - cpl_test_null(null); - null = cpl_matrix_extract_column(matrix, 9999999); - cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); - cpl_test_null(null); - null = cpl_matrix_extract_column(matrix, -1); - cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); - cpl_test_null(null); - test_data(copia, cpl_matrix_extract_row(matrix, 2), "Copy one row... "); + /* Test error handling for invalid input: */ + null = cpl_matrix_extract_row(NULL, 1); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(null); + null = cpl_matrix_extract_row(matrix, 9999999); + cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_test_null(null); + null = cpl_matrix_extract_row(matrix, -1); + cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_test_null(null); + null = cpl_matrix_extract_column(NULL, 1); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(null); + null = cpl_matrix_extract_column(matrix, 9999999); + cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_test_null(null); + null = cpl_matrix_extract_column(matrix, -1); + cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); + cpl_test_null(null); + test_data(copia, cpl_matrix_extract_row(matrix, 2), "Copy one row... "); + + c = cpl_matrix_get_ncol(matrix); + + for (i = 0; i < c; i++) { + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT " of copied row... ", i); + test_fvalue_(cpl_matrix_get(matrix, 2, i), 0.00001, + cpl_matrix_get(copia, 0, i)); + } - c = cpl_matrix_get_ncol(matrix); + cpl_matrix_delete(copia); - for (i = 0; i < c; i++) { - cpl_msg_info(cpl_func, - "Check element %" CPL_SIZE_FORMAT " of copied row... ", i); - test_fvalue_(cpl_matrix_get(matrix, 2, i), 0.00001, - cpl_matrix_get(copia, 0, i)); - } +#ifdef CPL_MATRIX_TEST_EXTRA + test(cpl_matrix_copy_row_remove(matrix, subdArray, 1), "Write one row... "); - cpl_matrix_delete(copia); + for (i = 0; i < c; i++) { + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT " of written row... ", + i); + test_fvalue(subdArray[i], 0.00001, cpl_matrix_get(matrix, 1, i)); + } -#ifdef CPL_MATRIX_TEST_EXTRA - test(cpl_matrix_copy_row_remove(matrix, subdArray, 1), "Write one row... "); + test_data(copia, cpl_matrix_extract_column(matrix, 3), + "Copy one column... "); - for (i = 0; i < c; i++) { - cpl_msg_info(cpl_func, "Check element %" CPL_SIZE_FORMAT - " of written row... ", i); - test_fvalue(subdArray[i], 0.00001, cpl_matrix_get(matrix, 1, i)); - } - - test_data(copia, cpl_matrix_extract_column(matrix, 3), "Copy one column... "); - - r = cpl_matrix_get_nrow(matrix); - - for (i = 0; i < r; i++) { - cpl_msg_info(cpl_func, "Check element %" CPL_SIZE_FORMAT - " of copied column... ", i); - test_fvalue(cpl_matrix_get(matrix, i, 3), 0.00001, - cpl_matrix_get(copia, i, 0)); - } - - cpl_matrix_delete(copia); - - test(cpl_matrix_copy_column_remove(matrix, subdArray, 1), - "Write one column... "); - - for (i = 0; i < r; i++) { - cpl_msg_info(cpl_func, "Check element %" CPL_SIZE_FORMAT - " of written column... ", i); - test_fvalue(subdArray[i], 0.00001, cpl_matrix_get(matrix, i, 1)); - } + r = cpl_matrix_get_nrow(matrix); + + for (i = 0; i < r; i++) { + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT " of copied column... ", + i); + test_fvalue(cpl_matrix_get(matrix, i, 3), 0.00001, + cpl_matrix_get(copia, i, 0)); + } + + cpl_matrix_delete(copia); + + test(cpl_matrix_copy_column_remove(matrix, subdArray, 1), + "Write one column... "); + + for (i = 0; i < r; i++) { + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT " of written column... ", + i); + test_fvalue(subdArray[i], 0.00001, cpl_matrix_get(matrix, i, 1)); + } #endif - value = 9.00; - for (i = 0; i < nelem; i++) { - dArray[i] = value; - value += .01; - } - - test_data(copia, cpl_matrix_extract_diagonal(matrix, 0), - "Copy main diagonal... "); - - r = cpl_matrix_get_nrow(matrix); - - for (i = 0; i < r; i++) { - cpl_msg_info(cpl_func, "Check element %" CPL_SIZE_FORMAT - " of copied diagonal... ", i); - test_fvalue_(cpl_matrix_get(matrix, i, i), 0.00001, - cpl_matrix_get(copia, i, 0)); - } - - cpl_matrix_delete(copia); - - test_data(copia, cpl_matrix_extract_diagonal(matrix, 2), - "Copy third diagonal... "); - - for (i = 0; i < r; i++) { - cpl_msg_info(cpl_func, "Check element %" CPL_SIZE_FORMAT - " of copied third diagonal... ", i); - test_fvalue_(cpl_matrix_get(matrix, i , i + 2), 0.00001, - cpl_matrix_get(copia, i, 0)); - } + value = 9.00; + for (i = 0; i < nelem; i++) { + dArray[i] = value; + value += .01; + } + + test_data(copia, cpl_matrix_extract_diagonal(matrix, 0), + "Copy main diagonal... "); + + r = cpl_matrix_get_nrow(matrix); + + for (i = 0; i < r; i++) { + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT + " of copied diagonal... ", + i); + test_fvalue_(cpl_matrix_get(matrix, i, i), 0.00001, + cpl_matrix_get(copia, i, 0)); + } + + cpl_matrix_delete(copia); - cpl_matrix_delete(copia); + test_data(copia, cpl_matrix_extract_diagonal(matrix, 2), + "Copy third diagonal... "); + + for (i = 0; i < r; i++) { + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT + " of copied third diagonal... ", + i); + test_fvalue_(cpl_matrix_get(matrix, i, i + 2), 0.00001, + cpl_matrix_get(copia, i, 0)); + } + + cpl_matrix_delete(copia); #ifdef CPL_MATRIX_TEST_EXTRA - test(cpl_matrix_copy_diagonal_remove(matrix, subdArray, 0), - "Write main diagonal... "); + test(cpl_matrix_copy_diagonal_remove(matrix, subdArray, 0), + "Write main diagonal... "); - for (i = 0; i < r; i++) { - cpl_msg_info(cpl_func, - "Check element %" CPL_SIZE_FORMAT " of written " - "diagonal... ", i);; - test_fvalue(subdArray[i], 0.00001, cpl_matrix_get(matrix, i, i)); - } - - test(cpl_matrix_copy_diagonal_remove(matrix, subdArray, 2), - "Write third diagonal... "); - - for (i = 0; i < r; i++) { - cpl_msg_info(cpl_func, - "Check element %" CPL_SIZE_FORMAT " of written " - "diagonal... ", i); - test_fvalue(subdArray[i], 0.00001, cpl_matrix_get(matrix, i, i + 2)); - } + for (i = 0; i < r; i++) { + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT " of written " + "diagonal... ", + i); + ; + test_fvalue(subdArray[i], 0.00001, cpl_matrix_get(matrix, i, i)); + } + + test(cpl_matrix_copy_diagonal_remove(matrix, subdArray, 2), + "Write third diagonal... "); + + for (i = 0; i < r; i++) { + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT " of written " + "diagonal... ", + i); + test_fvalue(subdArray[i], 0.00001, cpl_matrix_get(matrix, i, i + 2)); + } #endif - value = 9.00; - for (i = 0; i < nelem; i++) { - dArray[i] = value; - value += .01; - } - - cpl_matrix_unwrap(matrix); - - test_data(matrix, cpl_matrix_wrap(10, 7, dArray), - "A new test matrix... "); - - test_data(copia, cpl_matrix_extract_diagonal(matrix, 0), - "Copy main diagonal (vertical)... "); - - c = cpl_matrix_get_ncol(matrix); - - for (i = 0; i < c; i++) { - cpl_msg_info(cpl_func, - "Check element %" CPL_SIZE_FORMAT " of copied diagonal " - "(vertical)... ", i); - test_fvalue_(cpl_matrix_get(matrix, i, i), 0.00001, - cpl_matrix_get(copia, 0, i)); - } - - cpl_matrix_delete(copia); - - test_data(copia, cpl_matrix_extract_diagonal(matrix, 1), - "Copy second diagonal (vertical)... "); - - for (i = 0; i < c; i++) { - cpl_msg_info(cpl_func, - "Check element %" CPL_SIZE_FORMAT " of copied second diagonal " - "(vertical)... ", i); - test_fvalue_(cpl_matrix_get(matrix, i + 1, i), 0.00001, - cpl_matrix_get(copia, 0, i)); - } + value = 9.00; + for (i = 0; i < nelem; i++) { + dArray[i] = value; + value += .01; + } + + cpl_matrix_unwrap(matrix); - cpl_matrix_delete(copia); + test_data(matrix, cpl_matrix_wrap(10, 7, dArray), "A new test matrix... "); + + test_data(copia, cpl_matrix_extract_diagonal(matrix, 0), + "Copy main diagonal (vertical)... "); + + c = cpl_matrix_get_ncol(matrix); + + for (i = 0; i < c; i++) { + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT " of copied diagonal " + "(vertical)... ", + i); + test_fvalue_(cpl_matrix_get(matrix, i, i), 0.00001, + cpl_matrix_get(copia, 0, i)); + } + + cpl_matrix_delete(copia); + + test_data(copia, cpl_matrix_extract_diagonal(matrix, 1), + "Copy second diagonal (vertical)... "); + + for (i = 0; i < c; i++) { + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT + " of copied second diagonal " + "(vertical)... ", + i); + test_fvalue_(cpl_matrix_get(matrix, i + 1, i), 0.00001, + cpl_matrix_get(copia, 0, i)); + } + + cpl_matrix_delete(copia); #ifdef CPL_MATRIX_TEST_EXTRA - test(cpl_matrix_copy_diagonal_remove(matrix, subdArray, 0), - "Write main diagonal (vertical)... "); + test(cpl_matrix_copy_diagonal_remove(matrix, subdArray, 0), + "Write main diagonal (vertical)... "); - for (i = 0; i < c; i++) { - cpl_msg_info(cpl_func, - "Check element %" CPL_SIZE_FORMAT " of written diagonal " - "(vertical)... ", i); - test_fvalue(subdArray[i], 0.00001, cpl_matrix_get(matrix, i, i)); - } - - test(cpl_matrix_copy_diagonal_remove(matrix, subdArray, 1), - "Write second diagonal (vertical)... "); - - for (i = 0; i < c; i++) { - cpl_msg_info(cpl_func, - "Check element %" CPL_SIZE_FORMAT " of written second diagonal " - "(vertical)... ", i); - test_fvalue(subdArray[i], 0.00001, cpl_matrix_get(matrix, i + 1, i)); - } + for (i = 0; i < c; i++) { + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT " of written diagonal " + "(vertical)... ", + i); + test_fvalue(subdArray[i], 0.00001, cpl_matrix_get(matrix, i, i)); + } + + test(cpl_matrix_copy_diagonal_remove(matrix, subdArray, 1), + "Write second diagonal (vertical)... "); + + for (i = 0; i < c; i++) { + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT + " of written second diagonal " + "(vertical)... ", + i); + test_fvalue(subdArray[i], 0.00001, cpl_matrix_get(matrix, i + 1, i)); + } #endif - cpl_free(subdArray); + cpl_free(subdArray); - test(cpl_matrix_fill(matrix, 3.33), "Write same value to entire matrix... "); + test(cpl_matrix_fill(matrix, 3.33), + "Write same value to entire matrix... "); - c = cpl_matrix_get_ncol(matrix); - r = c * cpl_matrix_get_nrow(matrix); + c = cpl_matrix_get_ncol(matrix); + r = c * cpl_matrix_get_nrow(matrix); - for (i = 0; i < r; i++) { - cpl_msg_info(cpl_func, - "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT - " of matrix... ", i / c, i % c); - test_fvalue_(3.33, 0.00001, cpl_matrix_get(matrix, i / c, i % c)); - } - - test(cpl_matrix_fill_row(matrix, 2.0, 4), "Write 2 to row 4..."); - - for (i = 0; i < c; i++) { - cpl_msg_info(cpl_func, - "Check element %" CPL_SIZE_FORMAT " of constant row... ", i); - test_fvalue_(2.0, 0.00001, cpl_matrix_get(matrix, 4, i)); - } - - test(cpl_matrix_fill_column(matrix, 9.99, 2), "Write 9.99 to column 2..."); - - r = cpl_matrix_get_nrow(matrix); - - for (i = 0; i < r; i++) { - cpl_msg_info(cpl_func, "Check element %" CPL_SIZE_FORMAT - " of constant column... ", i); - test_fvalue_(9.99, 0.00001, cpl_matrix_get(matrix, i, 2)); - } - - test(cpl_matrix_fill_diagonal(matrix, 1.11, 0), - "Write 1.11 to main diagonal..."); - - for (i = 0; i < c; i++) { - cpl_msg_info(cpl_func, "Check element %" CPL_SIZE_FORMAT - " of constant main diagonal... ", i); - test_fvalue_(1.11, 0.00001, cpl_matrix_get(matrix, i, i)); - } - - test(cpl_matrix_fill_diagonal(matrix, 1.10, -1), - "Write 1.11 to second diagonal..."); - - for (i = 0; i < c; i++) { - cpl_msg_info(cpl_func, "Check element %" CPL_SIZE_FORMAT - " of constant second diagonal... ", i); - test_fvalue_(1.1, 0.00001, cpl_matrix_get(matrix, i + 1, i)); - } - - value = 9.00; - for (i = 0; i < nelem; i++) { - dArray[i] = value; - value += .01; - } - - cpl_matrix_unwrap(matrix); - - test_data(matrix, cpl_matrix_wrap(7, 10, dArray), - "One more test matrix... "); - - test_data(copia, cpl_matrix_extract(matrix, 0, 0, 1, 1, 4, 4), - "Copying square submatrix... "); - - r = cpl_matrix_get_nrow(copia); - c = cpl_matrix_get_ncol(copia); - - for (i = 0; i < r; i++) { - for (j = 0; j < c; j++) { - cpl_msg_info(cpl_func, - "Check element %" CPL_SIZE_FORMAT ", %" - CPL_SIZE_FORMAT " of submatrix... ", i, j); - test_fvalue_(cpl_matrix_get(matrix, i, j), 0.00001, - cpl_matrix_get(copia, i, j)); - } - } - - test(cpl_matrix_add_scalar(copia, -8.), - "Subtracting constant from submatrix... "); - - for (i = 0; i < r; i++) { - for (j = 0; j < c; j++) { - cpl_msg_info(cpl_func, - "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT - " of modified submatrix... ", i, j); - test_fvalue_(cpl_matrix_get(matrix, i, j) - 8., 0.00001, - cpl_matrix_get(copia, i, j)); - } - } - - test(cpl_matrix_copy(matrix, copia, 2, 2), - "Writing submatrix into matrix..."); - - for (i = 0; i < r; i++) { - for (j = 0; j < c; j++) { - cpl_msg_info(cpl_func, - "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT - " of modified matrix... ", i + 2, j + 2); - test_fvalue_(cpl_matrix_get(copia, i, j), 0.00001, - cpl_matrix_get(matrix, i + 2, j + 2)); - } - } - - cpl_matrix_delete(copia); - - test(cpl_matrix_fill_window(matrix, 0., 1, 1, 4, 3), - "Writing same value into submatrix... "); - - for (i = 1; i < 4; i++) { - for (j = 1; j < 3; j++) { - cpl_msg_info(cpl_func, - "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT - " of constant submatrix... ", i, j); - test_fvalue_(0.0, 0.00001, cpl_matrix_get(matrix, i, j)); - } - } - - value = 9.00; - for (i = 0; i < nelem; i++) { - dArray[i] = value; - value += .01; - } - - copia = cpl_matrix_duplicate(matrix); - r = cpl_matrix_get_nrow(copia); - c = cpl_matrix_get_ncol(copia); - - test(cpl_matrix_fill_window(matrix, 0., 2, 2, 10, 10), - "Writing same value into submatrix (beyond borders)... "); - - for (i = 0; i < r; i++) { - for (j = 0; j < c; j++) { - cpl_msg_info(cpl_func, - "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT - " of overwritten matrix... ", i, j); - if (i > 1 && j > 1) { - test_fvalue_(0.0, 0.00001, - cpl_matrix_get(matrix, i, j)); - } - else { - test_fvalue_(cpl_matrix_get(copia, i, j), 0.00001, - cpl_matrix_get(matrix, i, j)); - } - } - } - - cpl_matrix_delete(copia); - - value = 9.00; - for (i = 0; i < nelem; i++) { - dArray[i] = value; - value += .01; - } - - copia = cpl_matrix_duplicate(matrix); - copy = cpl_matrix_duplicate(matrix); - r = cpl_matrix_get_nrow(copia); - c = cpl_matrix_get_ncol(copia); - - data = cpl_matrix_get_data_const(matrix); - test(cpl_matrix_shift(matrix, 1, 0), "Shift matrix elements by +1,0... "); - code = cpl_matrix_shift_brute(copy, 1, 0); - cpl_test_eq_error(code, CPL_ERROR_NONE); - cpl_test_matrix_abs(matrix, copy, 0.0); - - for (i = 0; i < r; i++) { - for (j = 0; j < c; j++) { - cpl_msg_info(cpl_func, - "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT - " of first shifted matrix... ", i, j); - if (i > r - 2) { - test_fvalue_(cpl_matrix_get(copia, i, j), 0.00001, - cpl_matrix_get(matrix, i + 1 - r, j)); - } - else { - test_fvalue_(cpl_matrix_get(copia, i, j), 0.00001, - cpl_matrix_get(matrix, i + 1, j)); - } - } - } - - test(cpl_matrix_shift(matrix, -1, 1), "Shift matrix elements by -1,+1... "); - code = cpl_matrix_shift_brute(copy, -1, 1); - cpl_test_eq_error(code, CPL_ERROR_NONE); - cpl_test_matrix_abs(matrix, copy, 0.0); - - for (i = 0; i < r; i++) { - for (j = 0; j < c; j++) { - cpl_msg_info(cpl_func, - "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT - " of second shifted matrix... ", i, j); - if (j > c - 2) { - test_fvalue_(cpl_matrix_get(copia, i, j), 0.00001, - cpl_matrix_get(matrix, i, j + 1 - c)); - } - else { - test_fvalue_(cpl_matrix_get(copia, i, j), 0.00001, - cpl_matrix_get(matrix, i, j + 1)); - } - } - } - - test(cpl_matrix_shift(matrix, 4, 3), "Shift matrix elements by +4,+3... "); - code = cpl_matrix_shift_brute(copy, 4, 3); - cpl_test_eq_error(code, CPL_ERROR_NONE); - cpl_test_matrix_abs(matrix, copy, 0.0); - - for (i = 0; i < r; i++) { - for (j = 0; j < c; j++) { - cpl_msg_info(cpl_func, - "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT - " of third shifted matrix... ", i, j); - if (j > c - 5 && i > r - 5) { - test_fvalue_(cpl_matrix_get(copia, i, j), 0.00001, - cpl_matrix_get(matrix, i + 4 - r, j + 4 - c)); - } - else if (j > c - 5) { - test_fvalue_(cpl_matrix_get(copia, i, j), 0.00001, - cpl_matrix_get(matrix, i + 4, j + 4 - c)); - } - else if (i > r - 5) { - test_fvalue_(cpl_matrix_get(copia, i, j), 0.00001, - cpl_matrix_get(matrix, i + 4 - r, j + 4)); - } - else { - test_fvalue_(cpl_matrix_get(copia, i, j), 0.00001, - cpl_matrix_get(matrix, i + 4, j + 4)); - } - } - } - - test(cpl_matrix_shift(matrix, -8, -8), "Shift matrix elements by -8,-8... "); - code = cpl_matrix_shift_brute(copy, -8, -8); - cpl_test_eq_error(code, CPL_ERROR_NONE); - cpl_test_matrix_abs(matrix, copy, 0.0); - - for (i = 0; i < r; i++) { - for (j = 0; j < c; j++) { - cpl_msg_info(cpl_func, - "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT - " of fourth shifted matrix... ", i, j); - if (j < 4 && i < 4) { - test_fvalue_(cpl_matrix_get(copia, i, j), 0.00001, - cpl_matrix_get(matrix, i - 4 + r, j - 4 + c)); - } - else if (j < 4) { - test_fvalue_(cpl_matrix_get(copia, i, j), 0.00001, - cpl_matrix_get(matrix, i - 4, j - 4 + c)); - } - else if (i < 4) { - test_fvalue_(cpl_matrix_get(copia, i, j), 0.00001, - cpl_matrix_get(matrix, i - 4 + r, j - 4)); - } - else { - test_fvalue_(cpl_matrix_get(copia, i, j), 0.00001, - cpl_matrix_get(matrix, i - 4, j - 4)); - } - } - } - - /* Shift matrix back to original */ - code = cpl_matrix_shift(matrix, 4, 4); - cpl_test_eq_error(code, CPL_ERROR_NONE); - - code = cpl_matrix_shift_brute(copy, 4, 4); - cpl_test_eq_error(code, CPL_ERROR_NONE); - cpl_test_matrix_abs(matrix, copy, 0.0); - - /* No information was lost since the shifts are cyclic */ - cpl_test_matrix_abs(matrix, copia, 0.0); - - /* The pointer to the elements is also unchanged */ - cpl_test_eq_ptr(data, cpl_matrix_get_data_const(matrix)); - - for (i = - 2 * cpl_matrix_get_nrow(matrix); - i < 2 + 2 * cpl_matrix_get_nrow(matrix); i++) { - for (j = - 2 * cpl_matrix_get_ncol(matrix); - j < 2 + 2 * cpl_matrix_get_ncol(matrix); j++) { - - code = cpl_matrix_shift(matrix, i, 0); - - code = cpl_matrix_shift_brute(copy, i, 0); - cpl_test_eq_error(code, CPL_ERROR_NONE); - cpl_test_matrix_abs(matrix, copy, 0.0); - - - code = cpl_matrix_shift(matrix, 0, j); - - code = cpl_matrix_shift_brute(copy, 0, j); - cpl_test_eq_error(code, CPL_ERROR_NONE); - cpl_test_matrix_abs(matrix, copy, 0.0); - - - code = cpl_matrix_shift(matrix, -i, -j); - - code = cpl_matrix_shift_brute(copy, -i, -j); - cpl_test_eq_error(code, CPL_ERROR_NONE); - cpl_test_matrix_abs(matrix, copy, 0.0); - - } - } - - cpl_matrix_delete(copia); - cpl_matrix_delete(copy); - - code = cpl_matrix_shift(NULL, 1, 1); - cpl_test_eq_error(code, CPL_ERROR_NULL_INPUT); - - copia = cpl_matrix_duplicate(matrix); - - test(cpl_matrix_threshold_small(matrix, 9.505), "Chop matrix... "); - - for (i = 0; i < r; i++) { - for (j = 0; j < c; j++) { - cpl_msg_info(cpl_func, - "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT - " of chopped matrix... ", i, j); - if (cpl_matrix_get(copia, i, j) < 9.505) { - test_fvalue_(0.0, 0.00001, - cpl_matrix_get(matrix, i, j)); - } - else { - test_fvalue_(cpl_matrix_get(copia, i, j), 0.00001, - cpl_matrix_get(matrix, i, j)); - } - } - } - - cpl_matrix_delete(copia); - cpl_matrix_delete(matrix); - - dArray = cpl_malloc((size_t)nelem * sizeof(double)); - - value = 9.00; - for (i = 0; i < nelem; i++) { - dArray[i] = value; - value += .01; - } - - test_data(matrix, cpl_matrix_wrap(7, 10, dArray), - "Creating one more test matrix... "); - - copia = cpl_matrix_duplicate(matrix); - - test(cpl_matrix_swap_rows(matrix, 1, 3), "Swap rows 1 and 3... "); - - for (j = 0; j < c; j++) { - cpl_msg_info(cpl_func, "Check column %" CPL_SIZE_FORMAT - " of row swapped matrix... ", j); - test_fvalue_(cpl_matrix_get(copia, 1, j), 0.00001, - cpl_matrix_get(matrix, 3, j)); - test_fvalue_(cpl_matrix_get(copia, 3, j), 0.00001, - cpl_matrix_get(matrix, 1, j)); - } - - value = 9.00; - for (i = 0; i < nelem; i++) { - dArray[i] = value; - value += .01; - } - - test(cpl_matrix_swap_columns(matrix, 1, 3), "Swap columns 1 and 3... "); - - for (i = 0; i < r; i++) { - cpl_msg_info(cpl_func, "Check row %" CPL_SIZE_FORMAT - " of column swapped matrix... ", i); - test_fvalue_(cpl_matrix_get(copia, i, 1), 0.00001, - cpl_matrix_get(matrix, i, 3)); - test_fvalue_(cpl_matrix_get(copia, i, 1), 0.00001, - cpl_matrix_get(matrix, i, 3)); - } - - cpl_matrix_delete(copia); - - value = 9.00; - for (i = 0; i < nelem; i++) { - dArray[i] = value; - value += .01; - } - - test_data(copia, cpl_matrix_new(5, 5), "Creating 5x5 square matrix... "); - - test(cpl_matrix_copy(copia, matrix, 0, 0), - "Writing upper left 5x5 of matrix into copy..."); - - test(cpl_matrix_swap_rowcolumn(copia, 1), - "Swapping row 1 with column 1... "); - - for (i = 0; i < 5; i++) { - cpl_msg_info(cpl_func, - "Check row/column element %" CPL_SIZE_FORMAT - " of swapped matrix... ", i); - test_fvalue_(cpl_matrix_get(matrix, i, 1), 0.00001, - cpl_matrix_get(copia, 1, i)); - test_fvalue_(cpl_matrix_get(matrix, i, 1), 0.00001, - cpl_matrix_get(copia, 1, i)); - } - - cpl_matrix_delete(copia); - - copia = cpl_matrix_duplicate(matrix); - - test(cpl_matrix_flip_rows(matrix), "Flip matrix upside down... "); - - for (i = 0; i < r; i++) { - for (j = 0; j < c; j++) { - cpl_msg_info(cpl_func, - "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT - " of row-flipped matrix... ", i, j); - test_fvalue_(cpl_matrix_get(copia, i, j), 0.00001, - cpl_matrix_get(matrix, r - i - 1, j)); - } - } - - test(cpl_matrix_flip_columns(matrix), "Flip matrix left right... "); - - for (i = 0; i < r; i++) { - for (j = 0; j < c; j++) { - cpl_msg_info(cpl_func, - "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT - " of row-flipped matrix... ", i, j); - test_fvalue_(cpl_matrix_get(copia, i, j), 0.00001, - cpl_matrix_get(matrix, r - i - 1, c - j - 1)); - } - } - - cpl_matrix_delete(copia); - - value = 9.00; - for (i = 0; i < nelem; i++) { - dArray[i] = value; - value += .01; - } - - test_data(copia, cpl_matrix_transpose_create(matrix), - "Compute transpose... "); - - for (i = 0; i < r; i++) { - for (j = 0; j < c; j++) { - cpl_msg_info(cpl_func, - "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT - " of transposed matrix... ", i, j); - test_fvalue_(cpl_matrix_get(matrix, i, j), 0.00001, - cpl_matrix_get(copia, j, i)); - } - } - - test(cpl_matrix_sort_rows(copia, 1), "Sort matrix rows... "); - - test(cpl_matrix_flip_columns(copia), "Flip matrix left right (again)... "); - test(cpl_matrix_sort_columns(copia, 1), "Sort matrix columns... "); - - cpl_matrix_delete(copia); - - copia = cpl_matrix_duplicate(matrix); - - test(cpl_matrix_erase_rows(matrix, 2, 3), "Delete rows 2 to 4... "); - - k = 0; - for (i = 0; i < r; i++) { - if (i > 1 && i < 5) - break; - for (j = 0; j < c; j++) { - cpl_msg_info(cpl_func, - "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT - " of row-deleted matrix... ", k, j); - test_fvalue_(cpl_matrix_get(copia, i, j), 0.00001, - cpl_matrix_get(matrix, k, j)); - } - k++; - } - - test(cpl_matrix_erase_columns(matrix, 2, 3), "Delete columns 2 to 4... "); + for (i = 0; i < r; i++) { + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT + " of matrix... ", + i / c, i % c); + test_fvalue_(3.33, 0.00001, cpl_matrix_get(matrix, i / c, i % c)); + } - k = 0; - for (i = 0; i < r; i++) { - if (i > 1 && i < 5) - break; - for (j = 0; j < c; j++) { - if (j > 1 && j < 5) - break; - cpl_msg_info(cpl_func, - "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT - " of row-deleted matrix... ", k, j); - test_fvalue_(cpl_matrix_get(copia, i, j), 0.00001, - cpl_matrix_get(matrix, k, j)); - l++; - } - k++; - } - - cpl_matrix_delete(copia); - cpl_matrix_delete(matrix); - - dArray = cpl_malloc((size_t)nelem * sizeof(double)); - - value = 9.00; - for (i = 0; i < nelem; i++) { - dArray[i] = value; - value += .01; - } - - test_data(matrix, cpl_matrix_wrap(7, 10, dArray), - "Creating the steenth test matrix... "); - - copia = cpl_matrix_duplicate(matrix); - - test(cpl_matrix_resize(matrix, -2, -2, -2, -2), - "Cut a frame around matrix... "); - - for (i = 2; i < r - 2; i++) { - for (j = 2; j < c - 2; j++) { - cpl_msg_info(cpl_func, - "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT - " of cropped matrix... ", i - 2, j - 2); - test_fvalue_(cpl_matrix_get(matrix, i - 2, j - 2), 0.00001, - cpl_matrix_get(copia, i, j)); - } - } - - test(cpl_matrix_resize(matrix, 2, 2, 2, 2), "Add a frame around matrix... "); - - for (i = 0; i < r; i++) { - for (j = 0; j < c; j++) { - cpl_msg_info(cpl_func, - "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT - " of expanded matrix... ", i, j); - if (i > 1 && i < r - 2 && j > 1 && j < c - 2) { - test_fvalue_(cpl_matrix_get(copia, i, j), 0.00001, - cpl_matrix_get(matrix, i, j)); - } - else { - test_fvalue_(0.0, 0.00001, - cpl_matrix_get(matrix, i, j)); - } - } - } - - test(cpl_matrix_resize(matrix, -2, 2, 2, -2), - "Reframe a matrix... "); - - cpl_matrix_delete(copia); - cpl_matrix_delete(matrix); - - dArray = cpl_malloc((size_t)nelem * sizeof(double)); - - value = 9.00; - for (i = 0; i < nelem; i++) { - dArray[i] = value; - value += .01; - } - - test_data(matrix, cpl_matrix_wrap(7, 10, dArray), - "Creating matrix for merging test... "); - - test_data(copia, cpl_matrix_extract(matrix, 0, 0, 1, 1, 7, 1), - "Creating second matrix for merging test... "); - - product = cpl_matrix_duplicate(copia); - - test(cpl_matrix_append(copia, matrix, 0), "Horizontal merging... "); - - for (i = 0; i < r; i++) { - for (j = 0; j < c; j++) { - cpl_msg_info(cpl_func, - "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT - " of horizontally merged matrix... ", - i, j + 1); - test_fvalue_(cpl_matrix_get(matrix, i, j), 0.00001, - cpl_matrix_get(copia, i, j + 1)); - } - } - - for (i = 0; i < r; i++) { - cpl_msg_info(cpl_func, - "Check element %" CPL_SIZE_FORMAT ", %d" - " of horizontally merged matrix... ", - i, 0); - test_fvalue_(cpl_matrix_get(product, i, 0), 0.00001, - cpl_matrix_get(copia, i, 0)); - } - - cpl_matrix_delete(product); - cpl_matrix_delete(copia); - - test_data(copia, cpl_matrix_extract(matrix, 0, 0, 1, 1, 4, 10), - "Creating third matrix for merging test... "); - - product = cpl_matrix_duplicate(copia); - - test(cpl_matrix_append(copia, matrix, 1), "Vertical merging... "); - - for (i = 0; i < 4; i++) { - for (j = 0; j < c; j++) { - cpl_msg_info(cpl_func, - "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT - " of vertically merged matrix... ", - i, j); - test_fvalue_(cpl_matrix_get(product, i, j), 0.00001, - cpl_matrix_get(copia, i, j)); - } - } - - for (i = 0; i < r; i++) { - for (j = 0; j < c; j++) { - cpl_msg_info(cpl_func, - "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT - " of vertically merged matrix... ", - i + 4, j); - test_fvalue_(cpl_matrix_get(matrix, i, j), 0.00001, - cpl_matrix_get(copia, i + 4, j)); - } - } - - cpl_matrix_delete(product); - cpl_matrix_delete(copia); - - test_data(copia, cpl_matrix_duplicate(matrix), - "Create matrix for add test... "); - - test(cpl_matrix_add(copia, matrix), "Adding two matrices... "); - - for (i = 0; i < r; i++) { - for (j = 0; j < c; j++) { - cpl_msg_info(cpl_func, - "Check element %" CPL_SIZE_FORMAT ", %" - CPL_SIZE_FORMAT " of sum matrix... ", i, j); - test_fvalue_(cpl_matrix_get(matrix, i, j) * 2, 0.00001, - cpl_matrix_get(copia, i, j)); - } - } - - test(cpl_matrix_subtract(copia, matrix), "Subtracting two matrices... "); - - for (i = 0; i < r; i++) { - for (j = 0; j < c; j++) { - cpl_msg_info(cpl_func, - "Check element %" CPL_SIZE_FORMAT ", %" - CPL_SIZE_FORMAT " of diff matrix... ", i, j); - test_fvalue_(cpl_matrix_get(matrix, i, j), 0.00001, - cpl_matrix_get(copia, i, j)); - } - } - - test(cpl_matrix_multiply(copia, matrix), "Multiply two matrices... "); - - for (i = 0; i < r; i++) { - for (j = 0; j < c; j++) { - cpl_msg_info(cpl_func, - "Check element %" CPL_SIZE_FORMAT ", %" - CPL_SIZE_FORMAT " of mult matrix... ", i, j); - test_fvalue_(cpl_matrix_get(matrix, i, j) * - cpl_matrix_get(matrix, i, j), 0.00001, - cpl_matrix_get(copia, i, j)); - } - } - - test(cpl_matrix_divide(copia, matrix), "Divide two matrices... "); - - for (i = 0; i < r; i++) { - for (j = 0; j < c; j++) { - cpl_msg_info(cpl_func, - "Check element %" CPL_SIZE_FORMAT ", %" - CPL_SIZE_FORMAT " of ratio matrix... ", i, j); - test_fvalue_(cpl_matrix_get(matrix, i, j), 0.00001, - cpl_matrix_get(copia, i, j)); - } - } - - test(cpl_matrix_multiply_scalar(copia, 1./2.), "Divide a matrix by 2... "); - - for (i = 0; i < r; i++) { - for (j = 0; j < c; j++) { - cpl_msg_info(cpl_func, - "Check element %" CPL_SIZE_FORMAT ", %" - CPL_SIZE_FORMAT " of half matrix... ", i, j); - test_fvalue_(cpl_matrix_get(matrix, i, j) / 2, 0.00001, - cpl_matrix_get(copia, i, j)); - } - } - - cpl_matrix_delete(matrix); - cpl_matrix_delete(copia); - - test_data(matrix, cpl_matrix_new(3, 4), - "Creating first matrix for product... "); - - test_data(copia, cpl_matrix_new(4, 5), - "Creating second matrix for product... "); - - value = 0.0; - for (i = 0, k = 0; i < 3; i++) { - for (j = 0; j < 4; j++) { - k++; - cpl_msg_info(cpl_func, - "Writing to element %" CPL_SIZE_FORMAT - " of the first matrix... ", k); - cpl_test_zero(cpl_matrix_set(matrix, i, j, value)); - value++; - } - } - - value = -10.0; - for (i = 0, k = 0; i < 4; i++) { - for (j = 0; j < 5; j++) { - k++; - cpl_msg_info(cpl_func, - "Writing to element %" CPL_SIZE_FORMAT - " of the second matrix... ", k); - cpl_test_zero(cpl_matrix_set(copia, i, j, value)); - value++; - } - } - - test_data(product, cpl_matrix_product_create(matrix, copia), - "Matrix product... "); - - test_fvalue(10., 0.00001, cpl_matrix_get(product, 0, 0), - "Check element 0, 0 of product... "); - test_fvalue(16., 0.00001, cpl_matrix_get(product, 0, 1), - "Check element 0, 1 of product... "); - test_fvalue(22., 0.00001, cpl_matrix_get(product, 0, 2), - "Check element 0, 2 of product... "); - test_fvalue(28., 0.00001, cpl_matrix_get(product, 0, 3), - "Check element 0, 3 of product... "); - test_fvalue(34., 0.00001, cpl_matrix_get(product, 0, 4), - "Check element 0, 4 of product... "); - test_fvalue(-30., 0.00001, cpl_matrix_get(product, 1, 0), - "Check element 1, 0 of product... "); - test_fvalue(-8., 0.00001, cpl_matrix_get(product, 1, 1), - "Check element 1, 1 of product... "); - test_fvalue(14., 0.00001, cpl_matrix_get(product, 1, 2), - "Check element 1, 2 of product... "); - test_fvalue(36., 0.00001, cpl_matrix_get(product, 1, 3), - "Check element 1, 3 of product... "); - test_fvalue(58., 0.00001, cpl_matrix_get(product, 1, 4), - "Check element 1, 4 of product... "); - test_fvalue(-70., 0.00001, cpl_matrix_get(product, 2, 0), - "Check element 2, 0 of product... "); - test_fvalue(-32., 0.00001, cpl_matrix_get(product, 2, 1), - "Check element 2, 1 of product... "); - test_fvalue(6., 0.00001, cpl_matrix_get(product, 2, 2), - "Check element 2, 2 of product... "); - test_fvalue(44., 0.00001, cpl_matrix_get(product, 2, 3), - "Check element 2, 3 of product... "); - test_fvalue(82., 0.00001, cpl_matrix_get(product, 2, 4), - "Check element 2, 4 of product... "); - - cpl_matrix_delete(copia); - cpl_matrix_delete(product); - cpl_matrix_delete(matrix); - - test_data(matrix, cpl_matrix_new(3, 3), "Creating coefficient matrix... "); - - cpl_matrix_set(matrix, 0, 0, 1); - cpl_matrix_set(matrix, 0, 1, 1); - cpl_matrix_set(matrix, 0, 2, 1); - cpl_matrix_set(matrix, 1, 0, 1); - cpl_matrix_set(matrix, 1, 1, -2); - cpl_matrix_set(matrix, 1, 2, 2); - cpl_matrix_set(matrix, 2, 0, 0); - cpl_matrix_set(matrix, 2, 1, 1); - cpl_matrix_set(matrix, 2, 2, -2); - - test(cpl_matrix_get_minpos(matrix, &r, &c), "Find min pos 2... "); - - test_ivalue(1, r, "Check min row pos 2..."); - test_ivalue(1, c, "Check min col pos 2..."); - - test_fvalue(-2.0, 0.0001, cpl_matrix_get_min(matrix), - "Check min value 2... "); - - test(cpl_matrix_get_maxpos(matrix, &r, &c), "Find max pos 2... "); - - test_ivalue(1, r, "Check max row pos 2..."); - test_ivalue(2, c, "Check max col pos 2..."); - - test_fvalue(2.0, 0.0001, cpl_matrix_get_max(matrix), "Check max value 2... "); - - test_data(copia, cpl_matrix_new(3, 1), "Creating nonhomo matrix... "); - - cpl_matrix_set(copia, 0, 0, 0); - cpl_matrix_set(copia, 1, 0, 4); - cpl_matrix_set(copia, 2, 0, 2); - - cpl_matrix_dump(matrix, stream); - test_fvalue(5.0, DBL_EPSILON, cpl_matrix_get_determinant(matrix), - "Compute determinant of a regular matrix"); - cpl_test_error(CPL_ERROR_NONE); - - test_data(product, cpl_matrix_solve(matrix, copia), - "Solving a linear system... "); - - test_fvalue(4., 0.0001, cpl_matrix_get(product, 0, 0), - "Check linear system solution, x = 4... "); - test_fvalue(-2., 0.0001, cpl_matrix_get(product, 1, 0), - "Check linear system solution, y = -2... "); - test_fvalue(-2., 0.0001, cpl_matrix_get(product, 2, 0), - "Check linear system solution, z = -2... "); - -/* */ - cpl_matrix_delete(product); - /* cpl_matrix_dump(matrix); */ - /* cpl_matrix_dump(copia); */ - - test_data(product, cpl_matrix_solve_normal(matrix, copia), - "Least squares... "); - - /* cpl_matrix_dump(product); */ -/* */ - - cpl_matrix_delete(copia); - cpl_matrix_delete(product); - cpl_matrix_delete(matrix); - - test_data(matrix, cpl_matrix_new(1, 1), "Creating 1x1 matrix to invert... "); - cpl_matrix_set(matrix, 0, 0, 2); - - test_fvalue(2.0, 0.0, cpl_matrix_get_determinant(matrix), - "Compute determinant of a 1x1-matrix"); - cpl_test_error(CPL_ERROR_NONE); - - test_data(copia, cpl_matrix_invert_create(matrix), "Invert 1x1 matrix... "); - - test_data(product, cpl_matrix_product_create(matrix, copia), - "Product by 1x1 inverse... "); - - test_ivalue(1, cpl_matrix_is_identity(product, -1.), - "Checking if 1x1 product is identity... "); - - - code = cpl_matrix_product(product, matrix, copia); - cpl_test_eq_error(code, CPL_ERROR_NONE); - - k = cpl_matrix_is_identity(product, -1.); - cpl_test_error(CPL_ERROR_NONE); - cpl_test_eq(1, k); - - cpl_matrix_delete(matrix); - cpl_matrix_delete(product); - cpl_matrix_delete(copia); - - test_data(matrix, cpl_matrix_new(2, 2), "Creating matrix to invert... "); - - cpl_matrix_set(matrix, 0, 0, 1); - cpl_matrix_set(matrix, 0, 1, 1); - cpl_matrix_set(matrix, 1, 0, -1); - cpl_matrix_set(matrix, 1, 1, 2); - - cpl_matrix_dump(matrix, stream); - test_data(copia, cpl_matrix_invert_create(matrix), "Invert matrix... "); - cpl_matrix_dump(copia, stream); - - test_data(product, cpl_matrix_product_create(matrix, copia), - "Product by inverse... "); - cpl_matrix_dump(product, stream); - - test_ivalue(1, cpl_matrix_is_identity(product, -1.), - "Checking if product is identity... "); - - /* Try to solve a 2 X 2 singular system */ - cpl_test_zero( cpl_matrix_set_size(matrix, 2, 2) ); - cpl_test_zero( cpl_matrix_set_size(copia, 2, 1) ); - - cpl_test_zero( cpl_matrix_fill(matrix, 0.0) ); - - for (i = 0; i < 2; i++) { - cpl_test_zero( cpl_matrix_set(matrix, i, 1, 1.0) ); - } - - cpl_test_zero( cpl_matrix_fill(copia, 1.0) ); - - cpl_matrix_dump(matrix, stream); - cpl_matrix_dump(copia, stream); - - cpl_msg_info("", "Try to solve a 2 X 2 singular system"); - null = cpl_matrix_solve(matrix, copia); - cpl_test_error(CPL_ERROR_SINGULAR_MATRIX); - cpl_test_null(null); - - cpl_matrix_delete(product); - xtrue = cpl_matrix_new(1,1); - - /* Compute the determinant */ - test_fvalue(0.0, 0.0, cpl_matrix_get_determinant(matrix), - "Compute determinant of a singular matrix"); - cpl_test_error(CPL_ERROR_NONE); - - - /* Compute the determinant */ - /* This time with an existing error code */ - do { - const cpl_error_code edummy = cpl_error_set(cpl_func, CPL_ERROR_EOL); - cpl_errorstate prev_state = cpl_errorstate_get(); - const double dvalzero = cpl_matrix_get_determinant(matrix); - const cpl_boolean is_equal = cpl_errorstate_is_equal(prev_state); - - cpl_test_eq_error(CPL_ERROR_EOL, edummy); - cpl_test(is_equal); - - test_fvalue(0.0, 0.0, dvalzero, - "Compute determinant of a singular matrix"); - } while (0); - - /* Try to solve increasingly ill-conditioned systems */ - cpl_msg_info("", "Try to solve increasingly large systems Ax=b, " - "with A(i,j) = 1/(2*n-(1+i+j)) and x(j) = 1"); - - for (size = subnelem; 1 < nreps * nelem; size++) { - cpl_matrix * p2; - double error, residual; - double x_min, x_max; - cpl_boolean is_done; - - /* The true solution consists of all ones */ - cpl_test_zero(cpl_matrix_set_size(xtrue, size, 1)); - cpl_test_zero(cpl_matrix_fill(xtrue, 1.0)); - - cpl_test_zero(cpl_matrix_fill_illcond(matrix, size)); - - product = cpl_matrix_product_create(matrix, xtrue); - cpl_test_nonnull(product); - - xsolv = cpl_matrix_solve(matrix, product); - cpl_test_nonnull(xsolv); - - x_min = cpl_matrix_get_min(xsolv); - x_max = cpl_matrix_get_max(xsolv); - - is_done = (x_min < 0.5 || x_max >= 2.0) ? CPL_TRUE : CPL_FALSE; - - /* Find the residual */ - p2 = cpl_matrix_product_create(matrix, xsolv); - cpl_test_zero(cpl_matrix_subtract(p2, product)); - - residual = cpl_matrix_get_2norm_1(p2); - cpl_matrix_delete(p2); - - /* Find the error on the solution */ - cpl_test_zero(cpl_matrix_subtract(xsolv, xtrue)); - - error = cpl_matrix_get_2norm_1(xsolv); - - cpl_msg_info("","2-norm of residual with ill-conditioned %d x %d " - "[DBL_EPSILON]: %g", size, size, residual/DBL_EPSILON); - - cpl_msg_info("","2-norm of error on solution with ill-conditioned " - "%d x %d : %g", size, size, error); - - cpl_matrix_dump(xsolv, stream); - - - cpl_matrix_delete(xsolv); - cpl_matrix_delete(product); - - if (is_done) { - cpl_msg_info("", "Stopping at n=%d, because the most significant bit " - "of at least one element in the solution is wrong, " - "x_min=%g, x_max=%g", size, x_min, x_max); - break; - } - } - - /* Badness squared: Try to solve the normal equations... */ - cpl_msg_info("", "Try to solve increasingly large systems A^TAx=A^Tb, " - "with A(i,j) = 1/(2*n-(1+i+j)) and x(j) = 1"); - - k = 0; - did_fail = CPL_FALSE; - for (size = 1; size < nreps * nelem; size++) { - cpl_matrix * p2; - double error, residual; - double x_min, x_max; - cpl_boolean is_done; - - /* The true solution consists of all ones */ - cpl_test_zero(cpl_matrix_set_size(xtrue, size, 1)); - cpl_test_zero(cpl_matrix_fill(xtrue, 1.0)); - - cpl_test_zero(cpl_matrix_fill_illcond(matrix, size)); - - product = cpl_matrix_product_create(matrix, xtrue); - cpl_test_nonnull(product); - - xsolv = cpl_matrix_solve_normal(matrix, product); - if (cpl_error_get_code()) { - cpl_test_error(CPL_ERROR_SINGULAR_MATRIX); - cpl_test_null(xsolv); - did_fail = CPL_TRUE; - cpl_matrix_delete(product); - break; - } - cpl_test_nonnull(xsolv); - - x_min = cpl_matrix_get_min(xsolv); - x_max = cpl_matrix_get_max(xsolv); - - is_done = (x_min < 0.5 || x_max >= 2.0) ? CPL_TRUE : CPL_FALSE; - - /* Find the residual */ - p2 = cpl_matrix_product_create(matrix, xsolv); - cpl_test_zero(cpl_matrix_subtract(p2, product)); - - residual = cpl_matrix_get_2norm_1(p2); - cpl_matrix_delete(p2); - - /* Find the error on the solution */ - cpl_test_zero(cpl_matrix_subtract(xsolv, xtrue)); - - error = cpl_matrix_get_2norm_1(xsolv); - - cpl_msg_info("","2-norm of residual with ill-conditioned %d x %d (normal)" - " [DBL_EPSILON]: %g", size, size, residual/DBL_EPSILON); - - cpl_msg_info("","2-norm of error on solution with ill-conditioned %d x %d" - " (normal): %g", size, size, error); - - cpl_matrix_dump(xsolv, stream); - - cpl_matrix_delete(xsolv); - cpl_matrix_delete(product); - - if (is_done) { - cpl_msg_info("", "Stopping at n=%d, because the most significant bit " - "of at least one element in the solution is wrong, " - "x_min=%g, x_max=%g", size, x_min, x_max); - break; - } - k++; - } + test(cpl_matrix_fill_row(matrix, 2.0, 4), "Write 2 to row 4..."); - if (did_fail) { - /* Solving stopped prematurely. Normally, we should stop when the system - is near-singular and so ill-conditioned that the solution has an - element where not even the most significant bit is correct. For this - final iteration we will allow the solver to alternatively fail (due a - singular matrix). - This should add support for Debian sbuild on mips64el */ - cpl_test_leq(6, k); - } + for (i = 0; i < c; i++) { + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT " of constant row... ", + i); + test_fvalue_(2.0, 0.00001, cpl_matrix_get(matrix, 4, i)); + } + + test(cpl_matrix_fill_column(matrix, 9.99, 2), "Write 9.99 to column 2..."); + + r = cpl_matrix_get_nrow(matrix); + + for (i = 0; i < r; i++) { + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT + " of constant column... ", + i); + test_fvalue_(9.99, 0.00001, cpl_matrix_get(matrix, i, 2)); + } + + test(cpl_matrix_fill_diagonal(matrix, 1.11, 0), + "Write 1.11 to main diagonal..."); + + for (i = 0; i < c; i++) { + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT + " of constant main diagonal... ", + i); + test_fvalue_(1.11, 0.00001, cpl_matrix_get(matrix, i, i)); + } + + test(cpl_matrix_fill_diagonal(matrix, 1.10, -1), + "Write 1.11 to second diagonal..."); + + for (i = 0; i < c; i++) { + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT + " of constant second diagonal... ", + i); + test_fvalue_(1.1, 0.00001, cpl_matrix_get(matrix, i + 1, i)); + } + + value = 9.00; + for (i = 0; i < nelem; i++) { + dArray[i] = value; + value += .01; + } + + cpl_matrix_unwrap(matrix); + + test_data(matrix, cpl_matrix_wrap(7, 10, dArray), + "One more test matrix... "); + + test_data(copia, cpl_matrix_extract(matrix, 0, 0, 1, 1, 4, 4), + "Copying square submatrix... "); + + r = cpl_matrix_get_nrow(copia); + c = cpl_matrix_get_ncol(copia); + + for (i = 0; i < r; i++) { + for (j = 0; j < c; j++) { + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT + " of submatrix... ", + i, j); + test_fvalue_(cpl_matrix_get(matrix, i, j), 0.00001, + cpl_matrix_get(copia, i, j)); + } + } + + test(cpl_matrix_add_scalar(copia, -8.), + "Subtracting constant from submatrix... "); + + for (i = 0; i < r; i++) { + for (j = 0; j < c; j++) { + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT + " of modified submatrix... ", + i, j); + test_fvalue_(cpl_matrix_get(matrix, i, j) - 8., 0.00001, + cpl_matrix_get(copia, i, j)); + } + } + + test(cpl_matrix_copy(matrix, copia, 2, 2), + "Writing submatrix into matrix..."); + + for (i = 0; i < r; i++) { + for (j = 0; j < c; j++) { + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT + " of modified matrix... ", + i + 2, j + 2); + test_fvalue_(cpl_matrix_get(copia, i, j), 0.00001, + cpl_matrix_get(matrix, i + 2, j + 2)); + } + } + + cpl_matrix_delete(copia); + + test(cpl_matrix_fill_window(matrix, 0., 1, 1, 4, 3), + "Writing same value into submatrix... "); + + for (i = 1; i < 4; i++) { + for (j = 1; j < 3; j++) { + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT + " of constant submatrix... ", + i, j); + test_fvalue_(0.0, 0.00001, cpl_matrix_get(matrix, i, j)); + } + } + + value = 9.00; + for (i = 0; i < nelem; i++) { + dArray[i] = value; + value += .01; + } + + copia = cpl_matrix_duplicate(matrix); + r = cpl_matrix_get_nrow(copia); + c = cpl_matrix_get_ncol(copia); + + test(cpl_matrix_fill_window(matrix, 0., 2, 2, 10, 10), + "Writing same value into submatrix (beyond borders)... "); + + for (i = 0; i < r; i++) { + for (j = 0; j < c; j++) { + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT + " of overwritten matrix... ", + i, j); + if (i > 1 && j > 1) { + test_fvalue_(0.0, 0.00001, cpl_matrix_get(matrix, i, j)); + } + else { + test_fvalue_(cpl_matrix_get(copia, i, j), 0.00001, + cpl_matrix_get(matrix, i, j)); + } + } + } + + cpl_matrix_delete(copia); + + value = 9.00; + for (i = 0; i < nelem; i++) { + dArray[i] = value; + value += .01; + } + + copia = cpl_matrix_duplicate(matrix); + copy = cpl_matrix_duplicate(matrix); + r = cpl_matrix_get_nrow(copia); + c = cpl_matrix_get_ncol(copia); + + data = cpl_matrix_get_data_const(matrix); + test(cpl_matrix_shift(matrix, 1, 0), "Shift matrix elements by +1,0... "); + code = cpl_matrix_shift_brute(copy, 1, 0); + cpl_test_eq_error(code, CPL_ERROR_NONE); + cpl_test_matrix_abs(matrix, copy, 0.0); + + for (i = 0; i < r; i++) { + for (j = 0; j < c; j++) { + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT + " of first shifted matrix... ", + i, j); + if (i > r - 2) { + test_fvalue_(cpl_matrix_get(copia, i, j), 0.00001, + cpl_matrix_get(matrix, i + 1 - r, j)); + } + else { + test_fvalue_(cpl_matrix_get(copia, i, j), 0.00001, + cpl_matrix_get(matrix, i + 1, j)); + } + } + } + + test(cpl_matrix_shift(matrix, -1, 1), "Shift matrix elements by -1,+1... "); + code = cpl_matrix_shift_brute(copy, -1, 1); + cpl_test_eq_error(code, CPL_ERROR_NONE); + cpl_test_matrix_abs(matrix, copy, 0.0); + + for (i = 0; i < r; i++) { + for (j = 0; j < c; j++) { + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT + " of second shifted matrix... ", + i, j); + if (j > c - 2) { + test_fvalue_(cpl_matrix_get(copia, i, j), 0.00001, + cpl_matrix_get(matrix, i, j + 1 - c)); + } + else { + test_fvalue_(cpl_matrix_get(copia, i, j), 0.00001, + cpl_matrix_get(matrix, i, j + 1)); + } + } + } + + test(cpl_matrix_shift(matrix, 4, 3), "Shift matrix elements by +4,+3... "); + code = cpl_matrix_shift_brute(copy, 4, 3); + cpl_test_eq_error(code, CPL_ERROR_NONE); + cpl_test_matrix_abs(matrix, copy, 0.0); + + for (i = 0; i < r; i++) { + for (j = 0; j < c; j++) { + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT + " of third shifted matrix... ", + i, j); + if (j > c - 5 && i > r - 5) { + test_fvalue_(cpl_matrix_get(copia, i, j), 0.00001, + cpl_matrix_get(matrix, i + 4 - r, j + 4 - c)); + } + else if (j > c - 5) { + test_fvalue_(cpl_matrix_get(copia, i, j), 0.00001, + cpl_matrix_get(matrix, i + 4, j + 4 - c)); + } + else if (i > r - 5) { + test_fvalue_(cpl_matrix_get(copia, i, j), 0.00001, + cpl_matrix_get(matrix, i + 4 - r, j + 4)); + } + else { + test_fvalue_(cpl_matrix_get(copia, i, j), 0.00001, + cpl_matrix_get(matrix, i + 4, j + 4)); + } + } + } + + test(cpl_matrix_shift(matrix, -8, -8), + "Shift matrix elements by -8,-8... "); + code = cpl_matrix_shift_brute(copy, -8, -8); + cpl_test_eq_error(code, CPL_ERROR_NONE); + cpl_test_matrix_abs(matrix, copy, 0.0); + + for (i = 0; i < r; i++) { + for (j = 0; j < c; j++) { + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT + " of fourth shifted matrix... ", + i, j); + if (j < 4 && i < 4) { + test_fvalue_(cpl_matrix_get(copia, i, j), 0.00001, + cpl_matrix_get(matrix, i - 4 + r, j - 4 + c)); + } + else if (j < 4) { + test_fvalue_(cpl_matrix_get(copia, i, j), 0.00001, + cpl_matrix_get(matrix, i - 4, j - 4 + c)); + } + else if (i < 4) { + test_fvalue_(cpl_matrix_get(copia, i, j), 0.00001, + cpl_matrix_get(matrix, i - 4 + r, j - 4)); + } + else { + test_fvalue_(cpl_matrix_get(copia, i, j), 0.00001, + cpl_matrix_get(matrix, i - 4, j - 4)); + } + } + } + + /* Shift matrix back to original */ + code = cpl_matrix_shift(matrix, 4, 4); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + code = cpl_matrix_shift_brute(copy, 4, 4); + cpl_test_eq_error(code, CPL_ERROR_NONE); + cpl_test_matrix_abs(matrix, copy, 0.0); + + /* No information was lost since the shifts are cyclic */ + cpl_test_matrix_abs(matrix, copia, 0.0); + + /* The pointer to the elements is also unchanged */ + cpl_test_eq_ptr(data, cpl_matrix_get_data_const(matrix)); + + for (i = -2 * cpl_matrix_get_nrow(matrix); + i < 2 + 2 * cpl_matrix_get_nrow(matrix); i++) { + for (j = -2 * cpl_matrix_get_ncol(matrix); + j < 2 + 2 * cpl_matrix_get_ncol(matrix); j++) { + code = cpl_matrix_shift(matrix, i, 0); + + code = cpl_matrix_shift_brute(copy, i, 0); + cpl_test_eq_error(code, CPL_ERROR_NONE); + cpl_test_matrix_abs(matrix, copy, 0.0); + + + code = cpl_matrix_shift(matrix, 0, j); + + code = cpl_matrix_shift_brute(copy, 0, j); + cpl_test_eq_error(code, CPL_ERROR_NONE); + cpl_test_matrix_abs(matrix, copy, 0.0); + + + code = cpl_matrix_shift(matrix, -i, -j); + + code = cpl_matrix_shift_brute(copy, -i, -j); + cpl_test_eq_error(code, CPL_ERROR_NONE); + cpl_test_matrix_abs(matrix, copy, 0.0); + } + } + + cpl_matrix_delete(copia); + cpl_matrix_delete(copy); + + code = cpl_matrix_shift(NULL, 1, 1); + cpl_test_eq_error(code, CPL_ERROR_NULL_INPUT); - cpl_msg_info("", "Compute the determinant of increasingly large " - "matrices, with A(i,j) = 1/(1+abs(i-j))"); + copia = cpl_matrix_duplicate(matrix); - for (size = 1; size < nelem*nreps; size++) { + test(cpl_matrix_threshold_small(matrix, 9.505), "Chop matrix... "); + + for (i = 0; i < r; i++) { + for (j = 0; j < c; j++) { + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT + " of chopped matrix... ", + i, j); + if (cpl_matrix_get(copia, i, j) < 9.505) { + test_fvalue_(0.0, 0.00001, cpl_matrix_get(matrix, i, j)); + } + else { + test_fvalue_(cpl_matrix_get(copia, i, j), 0.00001, + cpl_matrix_get(matrix, i, j)); + } + } + } + + cpl_matrix_delete(copia); + cpl_matrix_delete(matrix); + + dArray = cpl_malloc((size_t)nelem * sizeof(double)); + + value = 9.00; + for (i = 0; i < nelem; i++) { + dArray[i] = value; + value += .01; + } + + test_data(matrix, cpl_matrix_wrap(7, 10, dArray), + "Creating one more test matrix... "); + + copia = cpl_matrix_duplicate(matrix); + + test(cpl_matrix_swap_rows(matrix, 1, 3), "Swap rows 1 and 3... "); + + for (j = 0; j < c; j++) { + cpl_msg_info(cpl_func, + "Check column %" CPL_SIZE_FORMAT + " of row swapped matrix... ", + j); + test_fvalue_(cpl_matrix_get(copia, 1, j), 0.00001, + cpl_matrix_get(matrix, 3, j)); + test_fvalue_(cpl_matrix_get(copia, 3, j), 0.00001, + cpl_matrix_get(matrix, 1, j)); + } + + value = 9.00; + for (i = 0; i < nelem; i++) { + dArray[i] = value; + value += .01; + } + + test(cpl_matrix_swap_columns(matrix, 1, 3), "Swap columns 1 and 3... "); + + for (i = 0; i < r; i++) { + cpl_msg_info(cpl_func, + "Check row %" CPL_SIZE_FORMAT + " of column swapped matrix... ", + i); + test_fvalue_(cpl_matrix_get(copia, i, 1), 0.00001, + cpl_matrix_get(matrix, i, 3)); + test_fvalue_(cpl_matrix_get(copia, i, 1), 0.00001, + cpl_matrix_get(matrix, i, 3)); + } + + cpl_matrix_delete(copia); + + value = 9.00; + for (i = 0; i < nelem; i++) { + dArray[i] = value; + value += .01; + } + + test_data(copia, cpl_matrix_new(5, 5), "Creating 5x5 square matrix... "); + + test(cpl_matrix_copy(copia, matrix, 0, 0), + "Writing upper left 5x5 of matrix into copy..."); + + test(cpl_matrix_swap_rowcolumn(copia, 1), + "Swapping row 1 with column 1... "); + + for (i = 0; i < 5; i++) { + cpl_msg_info(cpl_func, + "Check row/column element %" CPL_SIZE_FORMAT + " of swapped matrix... ", + i); + test_fvalue_(cpl_matrix_get(matrix, i, 1), 0.00001, + cpl_matrix_get(copia, 1, i)); + test_fvalue_(cpl_matrix_get(matrix, i, 1), 0.00001, + cpl_matrix_get(copia, 1, i)); + } - cpl_test_zero(cpl_matrix_fill_test(matrix, size, size)); + cpl_matrix_delete(copia); - value = cpl_matrix_get_determinant(matrix); + copia = cpl_matrix_duplicate(matrix); - cpl_msg_debug("", "Determinant of %d by %d test-matrix: %g", size, size, - value); + test(cpl_matrix_flip_rows(matrix), "Flip matrix upside down... "); - } + for (i = 0; i < r; i++) { + for (j = 0; j < c; j++) { + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT + " of row-flipped matrix... ", + i, j); + test_fvalue_(cpl_matrix_get(copia, i, j), 0.00001, + cpl_matrix_get(matrix, r - i - 1, j)); + } + } - if (cpl_error_get_code()) { - cpl_msg_info("", "Stopping at n=%d, because the determinant was " - "truncated to zero", size); - cpl_test_error(CPL_ERROR_UNSPECIFIED); - } else { - cpl_msg_info("", "Stopping at n=%d, with a determinant of %g", size, - value); - } + test(cpl_matrix_flip_columns(matrix), "Flip matrix left right... "); - cpl_msg_info("", "Compute the determinant of increasingly large ill-" - "conditioned matrices, with A(i,j) = 1/(2*n-(1+i+j))"); + for (i = 0; i < r; i++) { + for (j = 0; j < c; j++) { + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT + " of row-flipped matrix... ", + i, j); + test_fvalue_(cpl_matrix_get(copia, i, j), 0.00001, + cpl_matrix_get(matrix, r - i - 1, c - j - 1)); + } + } - for (size = 1; !cpl_error_get_code(); size++) { + cpl_matrix_delete(copia); - cpl_test_zero(cpl_matrix_fill_illcond(matrix, size)); + value = 9.00; + for (i = 0; i < nelem; i++) { + dArray[i] = value; + value += .01; + } - value = cpl_matrix_get_determinant(matrix); + test_data(copia, cpl_matrix_transpose_create(matrix), + "Compute transpose... "); - cpl_msg_debug("", "Determinant of %d by %d ill-conditioned-matrix: %g", - size, size, value); + for (i = 0; i < r; i++) { + for (j = 0; j < c; j++) { + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT + " of transposed matrix... ", + i, j); + test_fvalue_(cpl_matrix_get(matrix, i, j), 0.00001, + cpl_matrix_get(copia, j, i)); + } + } - } + test(cpl_matrix_sort_rows(copia, 1), "Sort matrix rows... "); - cpl_test_error(CPL_ERROR_UNSPECIFIED); - cpl_msg_info("", "Stopping at n=%d, because the determinant was truncated to " - "zero", size); + test(cpl_matrix_flip_columns(copia), "Flip matrix left right (again)... "); + test(cpl_matrix_sort_columns(copia, 1), "Sort matrix columns... "); - cpl_matrix_solve_normal_bench(do_bench ? 400 : 40, do_bench ? 10 : 1); + cpl_matrix_delete(copia); - cpl_matrix_delete(xtrue); + copia = cpl_matrix_duplicate(matrix); - cpl_matrix_delete(matrix); - cpl_matrix_delete(copia); + test(cpl_matrix_erase_rows(matrix, 2, 3), "Delete rows 2 to 4... "); + + k = 0; + for (i = 0; i < r; i++) { + if (i > 1 && i < 5) + break; + for (j = 0; j < c; j++) { + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT + " of row-deleted matrix... ", + k, j); + test_fvalue_(cpl_matrix_get(copia, i, j), 0.00001, + cpl_matrix_get(matrix, k, j)); + } + k++; + } + + test(cpl_matrix_erase_columns(matrix, 2, 3), "Delete columns 2 to 4... "); - if (stream != stdout) cpl_test_zero( fclose(stream) ); + k = 0; + for (i = 0; i < r; i++) { + if (i > 1 && i < 5) + break; + for (j = 0; j < c; j++) { + if (j > 1 && j < 5) + break; + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT + " of row-deleted matrix... ", + k, j); + test_fvalue_(cpl_matrix_get(copia, i, j), 0.00001, + cpl_matrix_get(matrix, k, j)); + l++; + } + k++; + } - return cpl_test_end(0); + cpl_matrix_delete(copia); + cpl_matrix_delete(matrix); + dArray = cpl_malloc((size_t)nelem * sizeof(double)); + + value = 9.00; + for (i = 0; i < nelem; i++) { + dArray[i] = value; + value += .01; + } + + test_data(matrix, cpl_matrix_wrap(7, 10, dArray), + "Creating the steenth test matrix... "); + + copia = cpl_matrix_duplicate(matrix); + + test(cpl_matrix_resize(matrix, -2, -2, -2, -2), + "Cut a frame around matrix... "); + + for (i = 2; i < r - 2; i++) { + for (j = 2; j < c - 2; j++) { + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT + " of cropped matrix... ", + i - 2, j - 2); + test_fvalue_(cpl_matrix_get(matrix, i - 2, j - 2), 0.00001, + cpl_matrix_get(copia, i, j)); + } + } + + test(cpl_matrix_resize(matrix, 2, 2, 2, 2), + "Add a frame around matrix... "); + + for (i = 0; i < r; i++) { + for (j = 0; j < c; j++) { + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT + " of expanded matrix... ", + i, j); + if (i > 1 && i < r - 2 && j > 1 && j < c - 2) { + test_fvalue_(cpl_matrix_get(copia, i, j), 0.00001, + cpl_matrix_get(matrix, i, j)); + } + else { + test_fvalue_(0.0, 0.00001, cpl_matrix_get(matrix, i, j)); + } + } + } + + test(cpl_matrix_resize(matrix, -2, 2, 2, -2), "Reframe a matrix... "); + + cpl_matrix_delete(copia); + cpl_matrix_delete(matrix); + + dArray = cpl_malloc((size_t)nelem * sizeof(double)); + + value = 9.00; + for (i = 0; i < nelem; i++) { + dArray[i] = value; + value += .01; + } + + test_data(matrix, cpl_matrix_wrap(7, 10, dArray), + "Creating matrix for merging test... "); + + test_data(copia, cpl_matrix_extract(matrix, 0, 0, 1, 1, 7, 1), + "Creating second matrix for merging test... "); + + product = cpl_matrix_duplicate(copia); + + test(cpl_matrix_append(copia, matrix, 0), "Horizontal merging... "); + + for (i = 0; i < r; i++) { + for (j = 0; j < c; j++) { + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT + " of horizontally merged matrix... ", + i, j + 1); + test_fvalue_(cpl_matrix_get(matrix, i, j), 0.00001, + cpl_matrix_get(copia, i, j + 1)); + } + } + + for (i = 0; i < r; i++) { + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT ", %d" + " of horizontally merged matrix... ", + i, 0); + test_fvalue_(cpl_matrix_get(product, i, 0), 0.00001, + cpl_matrix_get(copia, i, 0)); + } + + cpl_matrix_delete(product); + cpl_matrix_delete(copia); + + test_data(copia, cpl_matrix_extract(matrix, 0, 0, 1, 1, 4, 10), + "Creating third matrix for merging test... "); + + product = cpl_matrix_duplicate(copia); + + test(cpl_matrix_append(copia, matrix, 1), "Vertical merging... "); + + for (i = 0; i < 4; i++) { + for (j = 0; j < c; j++) { + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT + " of vertically merged matrix... ", + i, j); + test_fvalue_(cpl_matrix_get(product, i, j), 0.00001, + cpl_matrix_get(copia, i, j)); + } + } + + for (i = 0; i < r; i++) { + for (j = 0; j < c; j++) { + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT + " of vertically merged matrix... ", + i + 4, j); + test_fvalue_(cpl_matrix_get(matrix, i, j), 0.00001, + cpl_matrix_get(copia, i + 4, j)); + } + } + + cpl_matrix_delete(product); + cpl_matrix_delete(copia); + + test_data(copia, cpl_matrix_duplicate(matrix), + "Create matrix for add test... "); + + test(cpl_matrix_add(copia, matrix), "Adding two matrices... "); + + for (i = 0; i < r; i++) { + for (j = 0; j < c; j++) { + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT + " of sum matrix... ", + i, j); + test_fvalue_(cpl_matrix_get(matrix, i, j) * 2, 0.00001, + cpl_matrix_get(copia, i, j)); + } + } + + test(cpl_matrix_subtract(copia, matrix), "Subtracting two matrices... "); + + for (i = 0; i < r; i++) { + for (j = 0; j < c; j++) { + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT + " of diff matrix... ", + i, j); + test_fvalue_(cpl_matrix_get(matrix, i, j), 0.00001, + cpl_matrix_get(copia, i, j)); + } + } + + test(cpl_matrix_multiply(copia, matrix), "Multiply two matrices... "); + + for (i = 0; i < r; i++) { + for (j = 0; j < c; j++) { + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT + " of mult matrix... ", + i, j); + test_fvalue_(cpl_matrix_get(matrix, i, j) * + cpl_matrix_get(matrix, i, j), + 0.00001, cpl_matrix_get(copia, i, j)); + } + } + + test(cpl_matrix_divide(copia, matrix), "Divide two matrices... "); + + for (i = 0; i < r; i++) { + for (j = 0; j < c; j++) { + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT + " of ratio matrix... ", + i, j); + test_fvalue_(cpl_matrix_get(matrix, i, j), 0.00001, + cpl_matrix_get(copia, i, j)); + } + } + + test(cpl_matrix_multiply_scalar(copia, 1. / 2.), + "Divide a matrix by 2... "); + + for (i = 0; i < r; i++) { + for (j = 0; j < c; j++) { + cpl_msg_info(cpl_func, + "Check element %" CPL_SIZE_FORMAT ", %" CPL_SIZE_FORMAT + " of half matrix... ", + i, j); + test_fvalue_(cpl_matrix_get(matrix, i, j) / 2, 0.00001, + cpl_matrix_get(copia, i, j)); + } + } + + cpl_matrix_delete(matrix); + cpl_matrix_delete(copia); + + test_data(matrix, cpl_matrix_new(3, 4), + "Creating first matrix for product... "); + + test_data(copia, cpl_matrix_new(4, 5), + "Creating second matrix for product... "); + + value = 0.0; + for (i = 0, k = 0; i < 3; i++) { + for (j = 0; j < 4; j++) { + k++; + cpl_msg_info(cpl_func, + "Writing to element %" CPL_SIZE_FORMAT + " of the first matrix... ", + k); + cpl_test_zero(cpl_matrix_set(matrix, i, j, value)); + value++; + } + } + + value = -10.0; + for (i = 0, k = 0; i < 4; i++) { + for (j = 0; j < 5; j++) { + k++; + cpl_msg_info(cpl_func, + "Writing to element %" CPL_SIZE_FORMAT + " of the second matrix... ", + k); + cpl_test_zero(cpl_matrix_set(copia, i, j, value)); + value++; + } + } + + test_data(product, cpl_matrix_product_create(matrix, copia), + "Matrix product... "); + + test_fvalue(10., 0.00001, cpl_matrix_get(product, 0, 0), + "Check element 0, 0 of product... "); + test_fvalue(16., 0.00001, cpl_matrix_get(product, 0, 1), + "Check element 0, 1 of product... "); + test_fvalue(22., 0.00001, cpl_matrix_get(product, 0, 2), + "Check element 0, 2 of product... "); + test_fvalue(28., 0.00001, cpl_matrix_get(product, 0, 3), + "Check element 0, 3 of product... "); + test_fvalue(34., 0.00001, cpl_matrix_get(product, 0, 4), + "Check element 0, 4 of product... "); + test_fvalue(-30., 0.00001, cpl_matrix_get(product, 1, 0), + "Check element 1, 0 of product... "); + test_fvalue(-8., 0.00001, cpl_matrix_get(product, 1, 1), + "Check element 1, 1 of product... "); + test_fvalue(14., 0.00001, cpl_matrix_get(product, 1, 2), + "Check element 1, 2 of product... "); + test_fvalue(36., 0.00001, cpl_matrix_get(product, 1, 3), + "Check element 1, 3 of product... "); + test_fvalue(58., 0.00001, cpl_matrix_get(product, 1, 4), + "Check element 1, 4 of product... "); + test_fvalue(-70., 0.00001, cpl_matrix_get(product, 2, 0), + "Check element 2, 0 of product... "); + test_fvalue(-32., 0.00001, cpl_matrix_get(product, 2, 1), + "Check element 2, 1 of product... "); + test_fvalue(6., 0.00001, cpl_matrix_get(product, 2, 2), + "Check element 2, 2 of product... "); + test_fvalue(44., 0.00001, cpl_matrix_get(product, 2, 3), + "Check element 2, 3 of product... "); + test_fvalue(82., 0.00001, cpl_matrix_get(product, 2, 4), + "Check element 2, 4 of product... "); + + cpl_matrix_delete(copia); + cpl_matrix_delete(product); + cpl_matrix_delete(matrix); + + test_data(matrix, cpl_matrix_new(3, 3), "Creating coefficient matrix... "); + + cpl_matrix_set(matrix, 0, 0, 1); + cpl_matrix_set(matrix, 0, 1, 1); + cpl_matrix_set(matrix, 0, 2, 1); + cpl_matrix_set(matrix, 1, 0, 1); + cpl_matrix_set(matrix, 1, 1, -2); + cpl_matrix_set(matrix, 1, 2, 2); + cpl_matrix_set(matrix, 2, 0, 0); + cpl_matrix_set(matrix, 2, 1, 1); + cpl_matrix_set(matrix, 2, 2, -2); + + test(cpl_matrix_get_minpos(matrix, &r, &c), "Find min pos 2... "); + + test_ivalue(1, r, "Check min row pos 2..."); + test_ivalue(1, c, "Check min col pos 2..."); + + test_fvalue(-2.0, 0.0001, cpl_matrix_get_min(matrix), + "Check min value 2... "); + + test(cpl_matrix_get_maxpos(matrix, &r, &c), "Find max pos 2... "); + + test_ivalue(1, r, "Check max row pos 2..."); + test_ivalue(2, c, "Check max col pos 2..."); + + test_fvalue(2.0, 0.0001, cpl_matrix_get_max(matrix), + "Check max value 2... "); + + test_data(copia, cpl_matrix_new(3, 1), "Creating nonhomo matrix... "); + + cpl_matrix_set(copia, 0, 0, 0); + cpl_matrix_set(copia, 1, 0, 4); + cpl_matrix_set(copia, 2, 0, 2); + + cpl_matrix_dump(matrix, stream); + test_fvalue(5.0, DBL_EPSILON, cpl_matrix_get_determinant(matrix), + "Compute determinant of a regular matrix"); + cpl_test_error(CPL_ERROR_NONE); + + test_data(product, cpl_matrix_solve(matrix, copia), + "Solving a linear system... "); + + test_fvalue(4., 0.0001, cpl_matrix_get(product, 0, 0), + "Check linear system solution, x = 4... "); + test_fvalue(-2., 0.0001, cpl_matrix_get(product, 1, 0), + "Check linear system solution, y = -2... "); + test_fvalue(-2., 0.0001, cpl_matrix_get(product, 2, 0), + "Check linear system solution, z = -2... "); + + /* */ + cpl_matrix_delete(product); + /* cpl_matrix_dump(matrix); */ + /* cpl_matrix_dump(copia); */ + + test_data(product, cpl_matrix_solve_normal(matrix, copia), + "Least squares... "); + + /* cpl_matrix_dump(product); */ + /* */ + + cpl_matrix_delete(copia); + cpl_matrix_delete(product); + cpl_matrix_delete(matrix); + + test_data(matrix, cpl_matrix_new(1, 1), + "Creating 1x1 matrix to invert... "); + cpl_matrix_set(matrix, 0, 0, 2); + + test_fvalue(2.0, 0.0, cpl_matrix_get_determinant(matrix), + "Compute determinant of a 1x1-matrix"); + cpl_test_error(CPL_ERROR_NONE); + + test_data(copia, cpl_matrix_invert_create(matrix), "Invert 1x1 matrix... "); + + test_data(product, cpl_matrix_product_create(matrix, copia), + "Product by 1x1 inverse... "); + + test_ivalue(1, cpl_matrix_is_identity(product, -1.), + "Checking if 1x1 product is identity... "); + + + code = cpl_matrix_product(product, matrix, copia); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + k = cpl_matrix_is_identity(product, -1.); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(1, k); + + cpl_matrix_delete(matrix); + cpl_matrix_delete(product); + cpl_matrix_delete(copia); + + test_data(matrix, cpl_matrix_new(2, 2), "Creating matrix to invert... "); + + cpl_matrix_set(matrix, 0, 0, 1); + cpl_matrix_set(matrix, 0, 1, 1); + cpl_matrix_set(matrix, 1, 0, -1); + cpl_matrix_set(matrix, 1, 1, 2); + + cpl_matrix_dump(matrix, stream); + test_data(copia, cpl_matrix_invert_create(matrix), "Invert matrix... "); + cpl_matrix_dump(copia, stream); + + test_data(product, cpl_matrix_product_create(matrix, copia), + "Product by inverse... "); + cpl_matrix_dump(product, stream); + + test_ivalue(1, cpl_matrix_is_identity(product, -1.), + "Checking if product is identity... "); + + /* Try to solve a 2 X 2 singular system */ + cpl_test_zero(cpl_matrix_set_size(matrix, 2, 2)); + cpl_test_zero(cpl_matrix_set_size(copia, 2, 1)); + + cpl_test_zero(cpl_matrix_fill(matrix, 0.0)); + + for (i = 0; i < 2; i++) { + cpl_test_zero(cpl_matrix_set(matrix, i, 1, 1.0)); + } + + cpl_test_zero(cpl_matrix_fill(copia, 1.0)); + + cpl_matrix_dump(matrix, stream); + cpl_matrix_dump(copia, stream); + + cpl_msg_info("", "Try to solve a 2 X 2 singular system"); + null = cpl_matrix_solve(matrix, copia); + cpl_test_error(CPL_ERROR_SINGULAR_MATRIX); + cpl_test_null(null); + + cpl_matrix_delete(product); + xtrue = cpl_matrix_new(1, 1); + + /* Compute the determinant */ + test_fvalue(0.0, 0.0, cpl_matrix_get_determinant(matrix), + "Compute determinant of a singular matrix"); + cpl_test_error(CPL_ERROR_NONE); + + + /* Compute the determinant */ + /* This time with an existing error code */ + do { + const cpl_error_code edummy = cpl_error_set(cpl_func, CPL_ERROR_EOL); + cpl_errorstate prev_state = cpl_errorstate_get(); + const double dvalzero = cpl_matrix_get_determinant(matrix); + const cpl_boolean is_equal = cpl_errorstate_is_equal(prev_state); + + cpl_test_eq_error(CPL_ERROR_EOL, edummy); + cpl_test(is_equal); + + test_fvalue(0.0, 0.0, dvalzero, + "Compute determinant of a singular matrix"); + } while (0); + + /* Try to solve increasingly ill-conditioned systems */ + cpl_msg_info("", "Try to solve increasingly large systems Ax=b, " + "with A(i,j) = 1/(2*n-(1+i+j)) and x(j) = 1"); + + for (size = subnelem; 1 < nreps * nelem; size++) { + cpl_matrix *p2; + double error, residual; + double x_min, x_max; + cpl_boolean is_done; + + /* The true solution consists of all ones */ + cpl_test_zero(cpl_matrix_set_size(xtrue, size, 1)); + cpl_test_zero(cpl_matrix_fill(xtrue, 1.0)); + + cpl_test_zero(cpl_matrix_fill_illcond(matrix, size)); + + product = cpl_matrix_product_create(matrix, xtrue); + cpl_test_nonnull(product); + + xsolv = cpl_matrix_solve(matrix, product); + cpl_test_nonnull(xsolv); + + x_min = cpl_matrix_get_min(xsolv); + x_max = cpl_matrix_get_max(xsolv); + + is_done = (x_min < 0.5 || x_max >= 2.0) ? CPL_TRUE : CPL_FALSE; + + /* Find the residual */ + p2 = cpl_matrix_product_create(matrix, xsolv); + cpl_test_zero(cpl_matrix_subtract(p2, product)); + + residual = cpl_matrix_get_2norm_1(p2); + cpl_matrix_delete(p2); + + /* Find the error on the solution */ + cpl_test_zero(cpl_matrix_subtract(xsolv, xtrue)); + + error = cpl_matrix_get_2norm_1(xsolv); + + cpl_msg_info("", + "2-norm of residual with ill-conditioned %d x %d " + "[DBL_EPSILON]: %g", + size, size, residual / DBL_EPSILON); + + cpl_msg_info("", + "2-norm of error on solution with ill-conditioned " + "%d x %d : %g", + size, size, error); + + cpl_matrix_dump(xsolv, stream); + + + cpl_matrix_delete(xsolv); + cpl_matrix_delete(product); + + if (is_done) { + cpl_msg_info("", + "Stopping at n=%d, because the most significant bit " + "of at least one element in the solution is wrong, " + "x_min=%g, x_max=%g", + size, x_min, x_max); + break; + } + } + + /* Badness squared: Try to solve the normal equations... */ + cpl_msg_info("", "Try to solve increasingly large systems A^TAx=A^Tb, " + "with A(i,j) = 1/(2*n-(1+i+j)) and x(j) = 1"); + + k = 0; + did_fail = CPL_FALSE; + for (size = 1; size < nreps * nelem; size++) { + cpl_matrix *p2; + double error, residual; + double x_min, x_max; + cpl_boolean is_done; + + /* The true solution consists of all ones */ + cpl_test_zero(cpl_matrix_set_size(xtrue, size, 1)); + cpl_test_zero(cpl_matrix_fill(xtrue, 1.0)); + + cpl_test_zero(cpl_matrix_fill_illcond(matrix, size)); + + product = cpl_matrix_product_create(matrix, xtrue); + cpl_test_nonnull(product); + + xsolv = cpl_matrix_solve_normal(matrix, product); + if (cpl_error_get_code()) { + cpl_test_error(CPL_ERROR_SINGULAR_MATRIX); + cpl_test_null(xsolv); + did_fail = CPL_TRUE; + cpl_matrix_delete(product); + break; + } + cpl_test_nonnull(xsolv); + + x_min = cpl_matrix_get_min(xsolv); + x_max = cpl_matrix_get_max(xsolv); + + is_done = (x_min < 0.5 || x_max >= 2.0) ? CPL_TRUE : CPL_FALSE; + + /* Find the residual */ + p2 = cpl_matrix_product_create(matrix, xsolv); + cpl_test_zero(cpl_matrix_subtract(p2, product)); + + residual = cpl_matrix_get_2norm_1(p2); + cpl_matrix_delete(p2); + + /* Find the error on the solution */ + cpl_test_zero(cpl_matrix_subtract(xsolv, xtrue)); + + error = cpl_matrix_get_2norm_1(xsolv); + + cpl_msg_info("", + "2-norm of residual with ill-conditioned %d x %d (normal)" + " [DBL_EPSILON]: %g", + size, size, residual / DBL_EPSILON); + + cpl_msg_info("", + "2-norm of error on solution with ill-conditioned %d x %d" + " (normal): %g", + size, size, error); + + cpl_matrix_dump(xsolv, stream); + + cpl_matrix_delete(xsolv); + cpl_matrix_delete(product); + + if (is_done) { + cpl_msg_info("", + "Stopping at n=%d, because the most significant bit " + "of at least one element in the solution is wrong, " + "x_min=%g, x_max=%g", + size, x_min, x_max); + break; + } + k++; + } + + if (did_fail) { + /* Solving stopped prematurely. Normally, we should stop when the system + is near-singular and so ill-conditioned that the solution has an + element where not even the most significant bit is correct. For this + final iteration we will allow the solver to alternatively fail (due a + singular matrix). + This should add support for Debian sbuild on mips64el */ + cpl_test_leq(6, k); + } + + cpl_msg_info("", "Compute the determinant of increasingly large " + "matrices, with A(i,j) = 1/(1+abs(i-j))"); + + for (size = 1; size < nelem * nreps; size++) { + cpl_test_zero(cpl_matrix_fill_test(matrix, size, size)); + + value = cpl_matrix_get_determinant(matrix); + + cpl_msg_debug("", "Determinant of %d by %d test-matrix: %g", size, size, + value); + } + + if (cpl_error_get_code()) { + cpl_msg_info("", + "Stopping at n=%d, because the determinant was " + "truncated to zero", + size); + cpl_test_error(CPL_ERROR_UNSPECIFIED); + } + else { + cpl_msg_info("", "Stopping at n=%d, with a determinant of %g", size, + value); + } + + cpl_msg_info("", "Compute the determinant of increasingly large ill-" + "conditioned matrices, with A(i,j) = 1/(2*n-(1+i+j))"); + + for (size = 1; !cpl_error_get_code(); size++) { + cpl_test_zero(cpl_matrix_fill_illcond(matrix, size)); + + value = cpl_matrix_get_determinant(matrix); + + cpl_msg_debug("", "Determinant of %d by %d ill-conditioned-matrix: %g", + size, size, value); + } + + cpl_test_error(CPL_ERROR_UNSPECIFIED); + cpl_msg_info("", + "Stopping at n=%d, because the determinant was truncated to " + "zero", + size); + + cpl_matrix_solve_normal_bench(do_bench ? 400 : 40, do_bench ? 10 : 1); + + cpl_matrix_delete(xtrue); + + cpl_matrix_delete(matrix); + cpl_matrix_delete(copia); + + if (stream != stdout) + cpl_test_zero(fclose(stream)); + + return cpl_test_end(0); } /**@}*/ @@ -1752,19 +1808,19 @@ - CPL_ERROR_ILLEGAL_INPUT if size is negative or zero */ /*----------------------------------------------------------------------------*/ -static cpl_error_code cpl_matrix_fill_illcond(cpl_matrix * self, int size) +static cpl_error_code +cpl_matrix_fill_illcond(cpl_matrix *self, int size) { + int i, j; - int i,j; - - cpl_ensure_code(self, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self, CPL_ERROR_NULL_INPUT); cpl_ensure_code(size > 0, CPL_ERROR_ILLEGAL_INPUT); cpl_ensure_code(!cpl_matrix_set_size(self, size, size), cpl_error_get_code()); - for (i = 0; i 0, CPL_ERROR_ILLEGAL_INPUT); cpl_ensure_code(nc > 0, CPL_ERROR_ILLEGAL_INPUT); @@ -1812,14 +1865,13 @@ for (i = 0; i < nr; i++) { for (j = 0; j < nc; j++) { - const double value = 1.0/(double)(1+labs(i-j)); + const double value = 1.0 / (double)(1 + llabs(i - j)); cpl_ensure_code(!cpl_matrix_set(self, i, j, value), cpl_error_get_code()); } } return CPL_ERROR_NONE; - } @@ -1838,12 +1890,13 @@ - CPL_ERROR_ILLEGAL_INPUT if size is negative or zero */ /*----------------------------------------------------------------------------*/ -static double cpl_matrix_get_2norm_1(const cpl_matrix * self) +static double +cpl_matrix_get_2norm_1(const cpl_matrix *self) { double norm = 0; int i; - cpl_ensure(self, CPL_ERROR_NULL_INPUT, -1.0); + cpl_ensure(self, CPL_ERROR_NULL_INPUT, -1.0); cpl_ensure(cpl_matrix_get_ncol(self) == 1, CPL_ERROR_ILLEGAL_INPUT, -2.0); for (i = 0; i < cpl_matrix_get_nrow(self); i++) { @@ -1852,7 +1905,6 @@ } return sqrt(norm); - } @@ -1865,12 +1917,12 @@ @return void */ /*----------------------------------------------------------------------------*/ -static void cpl_matrix_solve_normal_bench(int nsize, int n) +static void +cpl_matrix_solve_normal_bench(int nsize, int n) { - - cpl_matrix * xtrue = cpl_matrix_new(1,1); /* The true solution */ - cpl_matrix * matrix = cpl_matrix_new(1,1); /* The system to solve */ - cpl_matrix * product; /* The Right Hand Side */ + cpl_matrix *xtrue = cpl_matrix_new(1, 1); /* The true solution */ + cpl_matrix *matrix = cpl_matrix_new(1, 1); /* The system to solve */ + cpl_matrix *product; /* The Right Hand Side */ size_t bytes; cpl_flops flops0; double secs; @@ -1891,8 +1943,7 @@ secs = cpl_test_get_cputime(); for (i = 0; i < n; i++) { - - cpl_matrix * xsolv = cpl_matrix_solve_normal(matrix, product); + cpl_matrix *xsolv = cpl_matrix_solve_normal(matrix, product); cpl_test_nonnull(xsolv); @@ -1902,11 +1953,13 @@ secs = cpl_test_get_cputime() - secs; flops0 = cpl_tools_get_flops() - flops0; - cpl_msg_info(cpl_func,"Speed while solving with size %d X %d in %g secs " - "[Mflop/s]: %g (%g)", nsize, nsize, secs/(double)i, - (double)flops0/secs/1e6, (double)flops0); + cpl_msg_info(cpl_func, + "Speed while solving with size %d X %d in %g secs " + "[Mflop/s]: %g (%g)", + nsize, nsize, secs / (double)i, (double)flops0 / secs / 1e6, + (double)flops0); if (secs > 0.0) { - cpl_msg_info(cpl_func,"Processing rate [MB/s]: %g", + cpl_msg_info(cpl_func, "Processing rate [MB/s]: %g", 1e-6 * (double)bytes / secs); } @@ -1914,7 +1967,6 @@ cpl_matrix_delete(xtrue); cpl_matrix_delete(product); cpl_matrix_delete(matrix); - } @@ -1927,18 +1979,18 @@ @return void */ /*----------------------------------------------------------------------------*/ -static void cpl_matrix_product_transpose_bench(int nsize, int n) +static void +cpl_matrix_product_transpose_bench(int nsize, int n) { - - double secs; - cpl_matrix * in = cpl_matrix_new(nsize, nsize); - cpl_matrix * out = cpl_matrix_new(nsize, nsize); + double secs; + cpl_matrix *in = cpl_matrix_new(nsize, nsize); + cpl_matrix *out = cpl_matrix_new(nsize, nsize); const size_t bytes = (size_t)n * cpl_test_get_bytes_matrix(in); int i; cpl_matrix_fill(in, 1.0); - secs = cpl_test_get_cputime(); + secs = cpl_test_get_cputime(); for (i = 0; i < n; i++) { const cpl_error_code error = cpl_matrix_product_transpose(out, in, in); @@ -1947,10 +1999,12 @@ secs = cpl_test_get_cputime() - secs; - cpl_msg_info(cpl_func,"Time spent transposing %d %dx%d matrices " - "[s]: %g", n, nsize, nsize, secs); + cpl_msg_info(cpl_func, + "Time spent transposing %d %dx%d matrices " + "[s]: %g", + n, nsize, nsize, secs); if (secs > 0.0) { - cpl_msg_info(cpl_func,"Processing rate [MB/s]: %g", + cpl_msg_info(cpl_func, "Processing rate [MB/s]: %g", 1e-6 * (double)bytes / secs); } @@ -1972,30 +2026,28 @@ */ /*----------------------------------------------------------------------------*/ -static cpl_matrix * cpl_matrix_product_bilinear_brute(const cpl_matrix * A, - const cpl_matrix * B) +static cpl_matrix * +cpl_matrix_product_bilinear_brute(const cpl_matrix *A, const cpl_matrix *B) { - #if 1 - cpl_matrix * C = cpl_matrix_new(cpl_matrix_get_nrow(B), - cpl_matrix_get_ncol(B)); + cpl_matrix *C = + cpl_matrix_new(cpl_matrix_get_nrow(B), cpl_matrix_get_ncol(B)); const cpl_error_code error = cpl_matrix_product_transpose(C, A, B); - cpl_matrix * self = cpl_matrix_product_create(B, C); + cpl_matrix *self = cpl_matrix_product_create(B, C); cpl_ensure(!error, cpl_error_get_code(), NULL); - + #else /* An even less efficient method */ - cpl_matrix * Bt = cpl_matrix_transpose_create(B); - cpl_matrix * C = cpl_matrix_product_create(A, Bt); - cpl_matrix * self = cpl_matrix_product_create(B, C); + cpl_matrix *Bt = cpl_matrix_transpose_create(B); + cpl_matrix *C = cpl_matrix_product_create(A, Bt); + cpl_matrix *self = cpl_matrix_product_create(B, C); cpl_matrix_delete(Bt); #endif cpl_matrix_delete(C); return self; - } @@ -2012,9 +2064,8 @@ */ /*----------------------------------------------------------------------------*/ -static cpl_error_code cpl_matrix_shift_brute(cpl_matrix *matrix, - cpl_size rshift, - cpl_size cshift) +static cpl_error_code +cpl_matrix_shift_brute(cpl_matrix *matrix, cpl_size rshift, cpl_size cshift) { cpl_error_code error = CPL_ERROR_NONE; const cpl_size nr = cpl_matrix_get_nrow(matrix); @@ -2027,7 +2078,7 @@ cshift = cshift % nc; if (rshift != 0 || cshift != 0) { - cpl_matrix *copy = cpl_matrix_duplicate(matrix); + cpl_matrix *copy = cpl_matrix_duplicate(matrix); /* Should not be able to fail now */ @@ -2043,15 +2094,14 @@ error = cpl_matrix_copy(matrix, copy, rshift, cshift); - if (!error && rshift) error = - cpl_matrix_copy(matrix, copy, rshift - nr, cshift); + if (!error && rshift) + error = cpl_matrix_copy(matrix, copy, rshift - nr, cshift); - if (!error && cshift) error = - cpl_matrix_copy(matrix, copy, rshift, cshift - nc); + if (!error && cshift) + error = cpl_matrix_copy(matrix, copy, rshift, cshift - nc); - if (!error && rshift && cshift) error = - cpl_matrix_copy(matrix, copy, rshift - nr, - cshift - nc); + if (!error && rshift && cshift) + error = cpl_matrix_copy(matrix, copy, rshift - nr, cshift - nc); cpl_matrix_delete(copy); } @@ -2069,18 +2119,16 @@ @return void */ /*----------------------------------------------------------------------------*/ -static -void cpl_matrix_product_bilinear_test(cpl_size nr, cpl_size nc, - cpl_boolean do_bench) +static void +cpl_matrix_product_bilinear_test(cpl_size nr, cpl_size nc, cpl_boolean do_bench) { - - cpl_matrix * self = cpl_matrix_new(nr, nr); - cpl_matrix * jacobi = cpl_matrix_new(nr, nc); - cpl_matrix * matrix = cpl_matrix_new(nc, nc); - cpl_matrix * brute; + cpl_matrix *self = cpl_matrix_new(nr, nr); + cpl_matrix *jacobi = cpl_matrix_new(nr, nc); + cpl_matrix *matrix = cpl_matrix_new(nc, nc); + cpl_matrix *brute; cpl_error_code error; - double tfunc, tbrute, t0; - cpl_flops ffunc, fbrute, f0; + double tfunc, tbrute, t0; + cpl_flops ffunc, fbrute, f0; error = cpl_matrix_fill_test(jacobi, nr, nc); @@ -2113,20 +2161,23 @@ cpl_matrix_delete(brute); if (do_bench) { - cpl_msg_info(cpl_func,"Time spent on B * A * B', B: %" CPL_SIZE_FORMAT + cpl_msg_info(cpl_func, + "Time spent on B * A * B', B: %" CPL_SIZE_FORMAT "x%" CPL_SIZE_FORMAT " [s]: %g <=> %g (brute force)", nr, nc, tfunc, tbrute); if (tfunc > 0.0 && tbrute > 0.0) { - cpl_msg_info(cpl_func,"Speed while computing B * A * B', B: %" - CPL_SIZE_FORMAT "x%" CPL_SIZE_FORMAT " [Mflop/s]: " - "%g <=> %g (brute force)", nr, nc, - (double)ffunc/tfunc/1e6, (double)fbrute/tbrute/1e6); + cpl_msg_info( + cpl_func, + "Speed while computing B * A * B', B: %" CPL_SIZE_FORMAT + "x%" CPL_SIZE_FORMAT " [Mflop/s]: " + "%g <=> %g (brute force)", + nr, nc, (double)ffunc / tfunc / 1e6, + (double)fbrute / tbrute / 1e6); } } } - /*----------------------------------------------------------------------------*/ /** @internal @@ -2136,21 +2187,22 @@ @return void */ /*----------------------------------------------------------------------------*/ -static void cpl_matrix_test_banded(int nc, int np) +static void +cpl_matrix_test_banded(int nc, int np) { - cpl_matrix * A = cpl_matrix_new(nc, nc); - cpl_array * p = cpl_array_new(nc, CPL_TYPE_INT); + cpl_matrix *A = cpl_matrix_new(nc, nc); + cpl_array *p = cpl_array_new(nc, CPL_TYPE_INT); int i; cpl_error_code error; - double tfunc, t0; - cpl_flops ffunc, f0; + double tfunc, t0; + cpl_flops ffunc, f0; for (i = -np; i <= np; i++) { error = cpl_matrix_fill_diagonal(A, 1.0, i); cpl_test_eq_error(error, CPL_ERROR_NONE); } - if(cpl_msg_get_level() <= CPL_MSG_DEBUG) + if (cpl_msg_get_level() <= CPL_MSG_DEBUG) cpl_matrix_dump(A, stderr); f0 = cpl_tools_get_flops(); @@ -2160,16 +2212,18 @@ ffunc = cpl_tools_get_flops() - f0; cpl_test_eq_error(error, CPL_ERROR_NONE); - if(cpl_msg_get_level() <= CPL_MSG_DEBUG) + if (cpl_msg_get_level() <= CPL_MSG_DEBUG) cpl_array_dump(p, 0, nc, stderr); cpl_matrix_delete(A); cpl_array_delete(p); - cpl_msg_info(cpl_func,"Time spent on LU-decomposition: %d X %d [s]: %g", + cpl_msg_info(cpl_func, "Time spent on LU-decomposition: %d X %d [s]: %g", nc, nc, tfunc); if (tfunc > 0.0) { - cpl_msg_info(cpl_func,"Speed while computing LU-decomposition: %d " - "X %d [Mflop/s]: %g", nc, nc, (double)ffunc/tfunc/1e6); + cpl_msg_info(cpl_func, + "Speed while computing LU-decomposition: %d " + "X %d [Mflop/s]: %g", + nc, nc, (double)ffunc / tfunc / 1e6); } } diff -Nru cpl-7.1.4+ds/cplcore/tests/cpl_median-test.c cpl-7.2.2+ds/cplcore/tests/cpl_median-test.c --- cpl-7.1.4+ds/cplcore/tests/cpl_median-test.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/tests/cpl_median-test.c 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -43,43 +43,48 @@ /* The maximum number of data elements for which all possible permutations will * be tested. */ -#define MAX_ARRAY_ALL_PERMUTATIONS 8 +#define MAX_ARRAY_ALL_PERMUTATIONS 8 /* The maximum number of data elements for which a random sampling of * permutations will be tested. */ -#define MAX_ARRAY_RANDOM_PERMUTATIONS 26 +#define MAX_ARRAY_RANDOM_PERMUTATIONS 26 /* The maximum number of permutations to generate per call of the * cpl_test_random_permutations function. */ -#define MAX_PERMUTATIONS 10000 +#define MAX_PERMUTATIONS 10000 /*----------------------------------------------------------------------------- Private function prototypes -----------------------------------------------------------------------------*/ -static int cpl_test_all_permutations(double* data, cpl_size n, - int (*check_permutation)(double* data, cpl_size n)); - -static int cpl_test_random_permutations(double* data, cpl_size n, - int (*check_permutation)(double* data, cpl_size n)); - -static void cpl_print_failed_permutation(double* data, cpl_size n); -static int cpl_check_median_mid(double* data, cpl_size n); -static int cpl_check_median_floor(double* data, cpl_size n); -static int cpl_check_median_ceil(double* data, cpl_size n); +static int +cpl_test_all_permutations(double *data, + cpl_size n, + int (*check_permutation)(double *data, cpl_size n)); + +static int cpl_test_random_permutations(double *data, + cpl_size n, + int (*check_permutation)(double *data, + cpl_size n)); + +static void cpl_print_failed_permutation(double *data, cpl_size n); +static int cpl_check_median_mid(double *data, cpl_size n); +static int cpl_check_median_floor(double *data, cpl_size n); +static int cpl_check_median_ceil(double *data, cpl_size n); /*----------------------------------------------------------------------------- Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { cpl_size i, n; double data[MAX_ARRAY_RANDOM_PERMUTATIONS]; cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); - srand(1); /* Fix the seed for repeatable results. */ + srand(1); /* Fix the seed for repeatable results. */ /* Test special case with data array with only one element. */ data[0] = 1.5; @@ -102,9 +107,8 @@ for (i = 0; i < n; ++i) { data[i] = i; } - if (cpl_test_all_permutations(data, n, cpl_check_median_mid) - != EXIT_SUCCESS) - { + if (cpl_test_all_permutations(data, n, cpl_check_median_mid) != + EXIT_SUCCESS) { cpl_print_failed_permutation(data, n); break; } @@ -112,22 +116,20 @@ for (i = 0; i < n; ++i) { data[i] = i; } - data[0] = n/2; - if (cpl_test_all_permutations(data, n, cpl_check_median_floor) - != EXIT_SUCCESS) - { + data[0] = n / 2; + if (cpl_test_all_permutations(data, n, cpl_check_median_floor) != + EXIT_SUCCESS) { cpl_print_failed_permutation(data, n); break; } - if (n % 2) { /* If odd */ + if (n % 2) { /* If odd */ for (i = 0; i < n; ++i) { data[i] = i; } - data[0] = n/2+1; - if (cpl_test_all_permutations(data, n, cpl_check_median_ceil) - != EXIT_SUCCESS) - { + data[0] = n / 2 + 1; + if (cpl_test_all_permutations(data, n, cpl_check_median_ceil) != + EXIT_SUCCESS) { cpl_print_failed_permutation(data, n); break; } @@ -137,15 +139,13 @@ /* Run the 3 tests as before but generating random permutations for data * array sizes from MAX_ARRAY_ALL_PERMUTATIONS + 1 * to MAX_ARRAY_RANDOM_PERMUTATIONS. */ - for (n = MAX_ARRAY_ALL_PERMUTATIONS+1; n <= MAX_ARRAY_RANDOM_PERMUTATIONS; - ++n) - { + for (n = MAX_ARRAY_ALL_PERMUTATIONS + 1; n <= MAX_ARRAY_RANDOM_PERMUTATIONS; + ++n) { for (i = 0; i < n; ++i) { data[i] = i; } - if (cpl_test_random_permutations(data, n, cpl_check_median_mid) - != EXIT_SUCCESS) - { + if (cpl_test_random_permutations(data, n, cpl_check_median_mid) != + EXIT_SUCCESS) { cpl_print_failed_permutation(data, n); break; } @@ -153,22 +153,20 @@ for (i = 0; i < n; ++i) { data[i] = i; } - data[0] = n/2; - if (cpl_test_random_permutations(data, n, cpl_check_median_floor) - != EXIT_SUCCESS) - { + data[0] = n / 2; + if (cpl_test_random_permutations(data, n, cpl_check_median_floor) != + EXIT_SUCCESS) { cpl_print_failed_permutation(data, n); break; } - if (n % 2) { /* If odd */ + if (n % 2) { /* If odd */ for (i = 0; i < n; ++i) { data[i] = i; } - data[0] = n/2+1; - if (cpl_test_random_permutations(data, n, cpl_check_median_ceil) - != EXIT_SUCCESS) - { + data[0] = n / 2 + 1; + if (cpl_test_random_permutations(data, n, cpl_check_median_ceil) != + EXIT_SUCCESS) { cpl_print_failed_permutation(data, n); break; } @@ -185,14 +183,17 @@ @brief Prints out the data for a failed permutation as error messages. */ /*----------------------------------------------------------------------------*/ -static void cpl_print_failed_permutation(double* data, cpl_size n) +static void +cpl_print_failed_permutation(double *data, cpl_size n) { cpl_size i; - cpl_msg_error(cpl_func, "Failed test on permutation with %"CPL_SIZE_FORMAT - " elements:", n); + cpl_msg_error(cpl_func, + "Failed test on permutation with %" CPL_SIZE_FORMAT + " elements:", + n); cpl_msg_error(cpl_func, "Item\tValue"); for (i = 0; i < n; ++i) { - cpl_msg_error(cpl_func, "%"CPL_SIZE_FORMAT"\t%f", i+1, data[i]); + cpl_msg_error(cpl_func, "%" CPL_SIZE_FORMAT "\t%f", i + 1, data[i]); } } @@ -202,9 +203,10 @@ @brief Checks if median is computed correctly as (n-1)/2. */ /*----------------------------------------------------------------------------*/ -static int cpl_check_median_mid(double* data, cpl_size n) +static int +cpl_check_median_mid(double *data, cpl_size n) { - cpl_test_abs(cpl_tools_get_median_double(data, n), 0.5*(n-1), + cpl_test_abs(cpl_tools_get_median_double(data, n), 0.5 * (n - 1), DBL_EPSILON); cpl_test_error(CPL_ERROR_NONE); return cpl_test_get_failed() == 0 ? EXIT_SUCCESS : EXIT_FAILURE; @@ -216,9 +218,10 @@ @brief Checks if median is computed correctly as floor(n/2). */ /*----------------------------------------------------------------------------*/ -static int cpl_check_median_floor(double* data, cpl_size n) +static int +cpl_check_median_floor(double *data, cpl_size n) { - cpl_test_abs(cpl_tools_get_median_double(data, n), floor(0.5*n), + cpl_test_abs(cpl_tools_get_median_double(data, n), floor(0.5 * n), DBL_EPSILON); cpl_test_error(CPL_ERROR_NONE); return cpl_test_get_failed() == 0 ? EXIT_SUCCESS : EXIT_FAILURE; @@ -230,9 +233,10 @@ @brief Checks if median is computed correctly as ceil(n/2). */ /*----------------------------------------------------------------------------*/ -static int cpl_check_median_ceil(double* data, cpl_size n) +static int +cpl_check_median_ceil(double *data, cpl_size n) { - cpl_test_abs(cpl_tools_get_median_double(data, n), ceil(0.5*n), + cpl_test_abs(cpl_tools_get_median_double(data, n), ceil(0.5 * n), DBL_EPSILON); cpl_test_error(CPL_ERROR_NONE); return cpl_test_get_failed() == 0 ? EXIT_SUCCESS : EXIT_FAILURE; @@ -272,38 +276,43 @@ 6 (3): 293-4 */ /*----------------------------------------------------------------------------*/ -static int cpl_test_all_permutations(double* data, cpl_size n, - int (*check_permutation)(double* data, cpl_size n)) +static int +cpl_test_all_permutations(double *data, + cpl_size n, + int (*check_permutation)(double *data, cpl_size n)) { - cpl_size i; - cpl_size* p = cpl_malloc(sizeof(cpl_size)*n); - double* datacopy = cpl_malloc(sizeof(double)*n); + cpl_size i; + cpl_size *p = cpl_malloc(sizeof(cpl_size) * n); + double *datacopy = cpl_malloc(sizeof(double) * n); cpl_test_assert(p != NULL); cpl_test_assert(datacopy != NULL); for (i = 0; i < n; ++i) { - p[i] = i+1; + p[i] = i + 1; } - memcpy(datacopy, data, sizeof(double)*n); - if (check_permutation(datacopy, n) == EXIT_FAILURE) return EXIT_FAILURE; - for (i = 0; i < n-1; ) { - const cpl_size j = i+1; + memcpy(datacopy, data, sizeof(double) * n); + if (check_permutation(datacopy, n) == EXIT_FAILURE) + return EXIT_FAILURE; + for (i = 0; i < n - 1;) { + const cpl_size j = i + 1; --p[i]; if (j % 2) { /* swap position p[i] and j for odd j. */ double tmp = data[p[i]]; data[p[i]] = data[j]; data[j] = tmp; - } else { + } + else { /* swap position 0 and j for even j. */ double tmp = data[0]; data[0] = data[j]; data[j] = tmp; } - memcpy(datacopy, data, sizeof(double)*n); - if (check_permutation(datacopy, n) == EXIT_FAILURE) return EXIT_FAILURE; + memcpy(datacopy, data, sizeof(double) * n); + if (check_permutation(datacopy, n) == EXIT_FAILURE) + return EXIT_FAILURE; for (i = 0; p[i] == 0; ++i) { - p[i] = i+1; + p[i] = i + 1; } } @@ -332,34 +341,37 @@ also returned @c EXIT_FAILURE at any point in time. */ /*----------------------------------------------------------------------------*/ -static int cpl_test_random_permutations(double* data, cpl_size n, - int (*check_permutation)(double* data, cpl_size n)) +static int +cpl_test_random_permutations(double *data, + cpl_size n, + int (*check_permutation)(double *data, cpl_size n)) { cpl_size count = 0; - double* original = cpl_malloc(sizeof(double)*n); - double* datacopy = cpl_malloc(sizeof(double)*n); + double *original = cpl_malloc(sizeof(double) * n); + double *datacopy = cpl_malloc(sizeof(double) * n); cpl_test_assert(original != NULL); cpl_test_assert(datacopy != NULL); /* Store a copy of the original data. */ - memcpy(original, data, sizeof(double)*n); + memcpy(original, data, sizeof(double) * n); while (count < MAX_PERMUTATIONS) { for (cpl_size max_trans = 0; max_trans <= n; - max_trans = (max_trans+1)*2-1) { - /* Reset the data array and permute. */ - memcpy(data, original, sizeof(double)*n); - for (cpl_size i = 0; i < max_trans; ++i) { - const int y = rand() % n; - const double tmp = data[y]; - int x; - while ((x = rand() % n) == y); /* Make sure x != y. */ - data[y] = data[x]; - data[x] = tmp; + max_trans = (max_trans + 1) * 2 - 1) { + /* Reset the data array and permute. */ + memcpy(data, original, sizeof(double) * n); + for (cpl_size i = 0; i < max_trans; ++i) { + const int y = rand() % n; + const double tmp = data[y]; + int x; + while ((x = rand() % n) == y) + ; /* Make sure x != y. */ + data[y] = data[x]; + data[x] = tmp; } /* Now run the check method. */ - memcpy(datacopy, data, sizeof(double)*n); + memcpy(datacopy, data, sizeof(double) * n); if (check_permutation(datacopy, n) == EXIT_FAILURE) { return EXIT_FAILURE; } diff -Nru cpl-7.1.4+ds/cplcore/tests/cpl_memory-test.c cpl-7.2.2+ds/cplcore/tests/cpl_memory-test.c --- cpl-7.1.4+ds/cplcore/tests/cpl_memory-test.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/tests/cpl_memory-test.c 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -18,7 +18,7 @@ */ #ifdef HAVE_CONFIG_H -# include +#include #endif /*----------------------------------------------------------------------------- @@ -38,34 +38,33 @@ -----------------------------------------------------------------------------*/ #ifndef CPL_XMEMORY_MODE -# error "Must know CPL_XMEMORY_MODE" +#error "Must know CPL_XMEMORY_MODE" #endif #ifndef CPL_XMEMORY_MAXPTRS -# error "Must know CPL_XMEMORY_MAXPTRS" +#error "Must know CPL_XMEMORY_MAXPTRS" #endif /* Fill the xmemory table to this level */ /* A positive number not exceeding 1.0 */ #ifndef CPL_XMEMORY_FILL -# define CPL_XMEMORY_FILL 0.999 +#define CPL_XMEMORY_FILL 0.999 #endif /* Half the number of pointers to test with */ #if CPL_XMEMORY_MODE == 2 #define CPL_MEMORY_MAXPTRS_HALF \ - ((int)(0.5*CPL_XMEMORY_MAXPTRS*CPL_XMEMORY_FILL)) + ((int)(0.5 * CPL_XMEMORY_MAXPTRS * CPL_XMEMORY_FILL)) #else -#define CPL_MEMORY_MAXPTRS_HALF \ - ((int)(0.5*200003*CPL_XMEMORY_FILL)) +#define CPL_MEMORY_MAXPTRS_HALF ((int)(0.5 * 200003 * CPL_XMEMORY_FILL)) #endif #if CPL_XMEMORY_MODE == 0 -# define CPL_MEMORY_IS_EMPTY -1 -# define CPL_MEMORY_IS_NON_EMPTY -1 +#define CPL_MEMORY_IS_EMPTY -1 +#define CPL_MEMORY_IS_NON_EMPTY -1 #else -# define CPL_MEMORY_IS_EMPTY 1 -# define CPL_MEMORY_IS_NON_EMPTY 0 +#define CPL_MEMORY_IS_EMPTY 1 +#define CPL_MEMORY_IS_NON_EMPTY 0 #endif static int cpl_memory_test_is_empty(void); @@ -87,7 +86,8 @@ **/ /*----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { cpl_boolean do_bench; @@ -101,8 +101,7 @@ /* Insert tests below */ #if defined CPL_XMEMORY_MODE - cpl_msg_info(cpl_func, CPL_XSTRINGIFY(CPL_XMEMORY_MODE) ": " - CPL_STRINGIFY(CPL_XMEMORY_MODE) "\n"); + cpl_msg_info(cpl_func, CPL_XSTRINGIFY(CPL_XMEMORY_MODE) ": " CPL_STRINGIFY(CPL_XMEMORY_MODE) "\n"); #else cpl_msg_info(cpl_func, "CPL_XMEMORY_MODE is not defined\n"); #endif @@ -116,14 +115,13 @@ int ii = 2; int i; - void * buf1[CPL_MEMORY_MAXPTRS_HALF]; - void * buf2[CPL_MEMORY_MAXPTRS_HALF]; + void *buf1[CPL_MEMORY_MAXPTRS_HALF]; + void *buf2[CPL_MEMORY_MAXPTRS_HALF]; cpl_msg_info("", "Testing memory allocation with %d X 2*%d", ii, CPL_MEMORY_MAXPTRS_HALF); do { - for (i = 0; i < CPL_MEMORY_MAXPTRS_HALF; i++) { buf1[i] = cpl_malloc(16); buf2[i] = cpl_calloc(4, 16); @@ -146,65 +144,68 @@ cpl_test_eq(cpl_memory_is_empty(), cpl_memory_test_is_empty()); } while (--ii); - } - if (cpl_msg_get_level() <= CPL_MSG_INFO) cpl_memory_dump(); + if (cpl_msg_get_level() <= CPL_MSG_INFO) + cpl_memory_dump(); return cpl_test_end(0); } -static int cpl_memory_test_is_empty(void) { - +static int +cpl_memory_test_is_empty(void) +{ #if defined CPL_XMEMORY_MODE && CPL_XMEMORY_MODE != 0 - int is_empty = 1; + int is_empty = 1; #else - int is_empty = -1; + int is_empty = -1; #endif /* Copied from cpl_init() */ - const char * memory_mode_string = getenv("CPL_MEMORY_MODE"); + const char *memory_mode_string = getenv("CPL_MEMORY_MODE"); if (memory_mode_string != NULL) { if (strcmp("0", memory_mode_string) == 0) { is_empty = -1; - } else if (strcmp("1", memory_mode_string) == 0) { + } + else if (strcmp("1", memory_mode_string) == 0) { is_empty = 1; - } else if (strcmp("2", memory_mode_string) == 0) { + } + else if (strcmp("2", memory_mode_string) == 0) { is_empty = 1; } } return is_empty; - } -static int cpl_memory_test_is_non_empty(void) { - +static int +cpl_memory_test_is_non_empty(void) +{ #if defined CPL_XMEMORY_MODE && CPL_XMEMORY_MODE != 0 - int is_non_empty = 0; + int is_non_empty = 0; #else - int is_non_empty = -1; + int is_non_empty = -1; #endif /* Copied from cpl_init() */ - const char * memory_mode_string = getenv("CPL_MEMORY_MODE"); + const char *memory_mode_string = getenv("CPL_MEMORY_MODE"); if (memory_mode_string != NULL) { if (strcmp("0", memory_mode_string) == 0) { is_non_empty = -1; - } else if (strcmp("1", memory_mode_string) == 0) { + } + else if (strcmp("1", memory_mode_string) == 0) { is_non_empty = 0; - } else if (strcmp("2", memory_mode_string) == 0) { + } + else if (strcmp("2", memory_mode_string) == 0) { is_non_empty = 0; } } return is_non_empty; - - } /*----------------------------------------------------------------------------*/ @@ -216,19 +217,22 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_memory_test_alloc(void) +static void +cpl_memory_test_alloc(void) { const size_t size = 997; - void * buf1; - void * buf2; + void *buf1; + void *buf2; cpl_free(NULL); - if (cpl_msg_get_level() <= CPL_MSG_INFO) cpl_memory_dump(); + if (cpl_msg_get_level() <= CPL_MSG_INFO) + cpl_memory_dump(); cpl_test_eq(cpl_memory_is_empty(), cpl_memory_test_is_empty()); - if (cpl_msg_get_level() <= CPL_MSG_INFO) cpl_memory_dump(); + if (cpl_msg_get_level() <= CPL_MSG_INFO) + cpl_memory_dump(); buf1 = cpl_malloc(size); buf2 = cpl_calloc(size, size); @@ -253,7 +257,7 @@ cpl_test_nonnull(buf2); cpl_test(buf1 != buf2); - + cpl_test_zero(memcmp(buf1, buf2, size)); cpl_free(buf1); @@ -265,7 +269,8 @@ buf1 = cpl_malloc(0); if (buf1 == NULL) { cpl_msg_info(cpl_func, "cpl_malloc(0) returned NULL"); - } else { + } + else { cpl_test_eq(cpl_memory_is_empty(), cpl_memory_test_is_non_empty()); } @@ -277,7 +282,8 @@ buf2 = cpl_calloc(0, 0); if (buf2 == NULL) { cpl_msg_info(cpl_func, "cpl_calloc(0, 0) returned NULL"); - } else { + } + else { cpl_test_eq(cpl_memory_is_empty(), cpl_memory_test_is_non_empty()); } cpl_free(buf2); @@ -291,7 +297,8 @@ buf1 = cpl_calloc(size, 0); if (buf1 == NULL) { cpl_msg_info(cpl_func, "cpl_calloc(size, 0) returned NULL"); - } else { + } + else { cpl_test_eq(cpl_memory_is_empty(), cpl_memory_test_is_non_empty()); } cpl_free(buf1); @@ -300,14 +307,16 @@ buf1 = cpl_realloc(NULL, 0); if (buf1 == NULL) { cpl_msg_info(cpl_func, "cpl_realloc(NULL, 0) returned NULL"); - } else { + } + else { cpl_test_eq(cpl_memory_is_empty(), cpl_memory_test_is_non_empty()); } buf1 = cpl_realloc(buf1, 0); if (buf1 == NULL) { cpl_msg_info(cpl_func, "cpl_realloc(buf1, 0) returned NULL"); - } else { + } + else { cpl_test_eq(cpl_memory_is_empty(), cpl_memory_test_is_non_empty()); } @@ -317,14 +326,14 @@ buf1 = cpl_realloc(buf1, 0); if (buf1 == NULL) { cpl_msg_info(cpl_func, "cpl_realloc(buf1, 0) returned NULL"); - } else { + } + else { cpl_test_eq(cpl_memory_is_empty(), cpl_memory_test_is_non_empty()); } cpl_free(buf1); cpl_test_eq(cpl_memory_is_empty(), cpl_memory_test_is_empty()); - } /*----------------------------------------------------------------------------*/ @@ -336,14 +345,14 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_memory_sprintf_test(void) +static void +cpl_memory_sprintf_test(void) { - - const char * string = __FILE__; /* Some non-empty string */ + const char *string = __FILE__; /* Some non-empty string */ const size_t stringlen = strlen(string); - char * null; /* This string is supposed to always be NULL */ - const char * null2; /* This string is supposed to always be NULL */ - char * nonnull; /* String is supposed to never be NULL */ + char *null; /* This string is supposed to always be NULL */ + const char *null2; /* This string is supposed to always be NULL */ + char *nonnull; /* String is supposed to never be NULL */ int length; /* Create a copy of an empty string */ @@ -385,11 +394,14 @@ if (null != NULL) { cpl_test_error(CPL_ERROR_NONE); - cpl_msg_warning(cpl_func, "The supposedly illegal format '%s' " - "produced the string: '%s'", nonnull, null); + cpl_msg_warning(cpl_func, + "The supposedly illegal format '%s' " + "produced the string: '%s'", + nonnull, null); cpl_free(null); null = NULL; - } else { + } + else { cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); } @@ -409,7 +421,6 @@ cpl_test_noneq_string(nonnull, ""); cpl_free(nonnull); - } /*----------------------------------------------------------------------------*/ @@ -421,11 +432,11 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_memory_strdup_test(void) +static void +cpl_memory_strdup_test(void) { - - const char * string = __FILE__; /* Some non-empty string */ - char * nonnull; /* String is supposed to never be NULL */ + const char *string = __FILE__; /* Some non-empty string */ + char *nonnull; /* String is supposed to never be NULL */ /* Create a copy of the string */ nonnull = cpl_strdup(string); @@ -436,5 +447,4 @@ cpl_test_eq_string(nonnull, string); cpl_free(nonnull); - } diff -Nru cpl-7.1.4+ds/cplcore/tests/cpl_msg-test.c cpl-7.2.2+ds/cplcore/tests/cpl_msg-test.c --- cpl-7.1.4+ds/cplcore/tests/cpl_msg-test.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/tests/cpl_msg-test.c 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -32,19 +32,20 @@ Defines -----------------------------------------------------------------------------*/ -#ifndef STR_LENGTH +#ifndef STR_LENGTH #define STR_LENGTH 80 #endif /*----------------------------------------------------------------------------- Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { - char message[STR_LENGTH+1]; + char message[STR_LENGTH + 1]; char toolong[CPL_MAX_MSG_LENGTH]; - char* verylongname = NULL; - int verylongnamesize = 1024*1024; + char *verylongname = NULL; + int verylongnamesize = 1024 * 1024; int nindent = 0; cpl_msg_severity loglevel = CPL_MSG_OFF; @@ -53,7 +54,7 @@ /* Insert tests below */ /* Construct the null-terminated string of STR_LENGTH dots */ - (void)memset((void*)message, '.', STR_LENGTH); + (void)memset((void *)message, '.', STR_LENGTH); message[STR_LENGTH] = '\0'; /* - and display it */ @@ -61,40 +62,47 @@ message); cpl_msg_info(cpl_func, "Domain is: %s", cpl_msg_get_domain()); - cpl_msg_indent_more(); nindent++; - cpl_msg_info(cpl_func,"hhu: %hhu\n", (unsigned char)-1); - cpl_msg_indent_more(); nindent++; - cpl_msg_info(cpl_func,"hhd: %hhd\n", (char)-1); - cpl_msg_indent_more(); nindent++; - cpl_msg_info(cpl_func,"zu: %zu\n", sizeof(size_t)); - cpl_msg_indent_more(); nindent++; - cpl_msg_info(cpl_func,"td: %td\n", (__func__ ) - (__func__ + 2) ); - cpl_msg_indent_more(); nindent++; - cpl_msg_info(cpl_func,"llu: %llu\n", (unsigned long long)-1); - cpl_msg_indent_more(); nindent++; - cpl_msg_info(cpl_func,"lld: %lld\n", (long long)-1); - cpl_msg_indent_more(); nindent++; + cpl_msg_indent_more(); + nindent++; + cpl_msg_info(cpl_func, "hhu: %hhu\n", (unsigned char)-1); + cpl_msg_indent_more(); + nindent++; + cpl_msg_info(cpl_func, "hhd: %hhd\n", (char)-1); + cpl_msg_indent_more(); + nindent++; + cpl_msg_info(cpl_func, "zu: %zu\n", sizeof(size_t)); + cpl_msg_indent_more(); + nindent++; + cpl_msg_info(cpl_func, "td: %td\n", (__func__) - (__func__ + 2)); + cpl_msg_indent_more(); + nindent++; + cpl_msg_info(cpl_func, "llu: %llu\n", (unsigned long long)-1); + cpl_msg_indent_more(); + nindent++; + cpl_msg_info(cpl_func, "lld: %lld\n", (long long)-1); + cpl_msg_indent_more(); + nindent++; /* Test a too long message */ /* Construct the null-terminated string of STR_LENGTH dots */ - (void)memset((void*)toolong, '.', CPL_MAX_MSG_LENGTH-1); - toolong[CPL_MAX_MSG_LENGTH-1] = '\0'; + (void)memset((void *)toolong, '.', CPL_MAX_MSG_LENGTH - 1); + toolong[CPL_MAX_MSG_LENGTH - 1] = '\0'; cpl_msg_info(cpl_func, "Display a string of %d dots: %s", - CPL_MAX_MSG_LENGTH-1, toolong); + CPL_MAX_MSG_LENGTH - 1, toolong); cpl_msg_set_time_on(); - for (;nindent; nindent--) + for (; nindent; nindent--) cpl_msg_indent_less(); /* Undo the indenting */ /* Construct a very long null-terminated string of 'A' characters */ - verylongname = (char*) cpl_malloc(verylongnamesize); + verylongname = (char *)cpl_malloc(verylongnamesize); cpl_test_nonnull(verylongname); - (void)memset((void*)verylongname, 'A', verylongnamesize-1); - verylongname[verylongnamesize-1] = '\0'; - + (void)memset((void *)verylongname, 'A', verylongnamesize - 1); + verylongname[verylongnamesize - 1] = '\0'; + loglevel = cpl_msg_get_level(); cpl_msg_set_level(CPL_MSG_OFF); cpl_msg_debug(verylongname, "test for long component name"); @@ -116,15 +124,14 @@ #ifdef CPL_MSG_TEST_DEPRECATED for (int i = 0; i < 1000; i++) { -CPL_DIAG_PRAGMA_PUSH_IGN(-Wdeprecated-declarations); + CPL_DIAG_PRAGMA_PUSH_IGN(-Wdeprecated-declarations); cpl_msg_progress(cpl_func, i, 1000, "test: %d/%d", i, 1000); -CPL_DIAG_PRAGMA_POP; + CPL_DIAG_PRAGMA_POP; } #endif - + cpl_free(verylongname); /* End of tests */ return cpl_test_end(0); - } diff -Nru cpl-7.1.4+ds/cplcore/tests/cpl_plot-test.c cpl-7.2.2+ds/cplcore/tests/cpl_plot-test.c --- cpl-7.1.4+ds/cplcore/tests/cpl_plot-test.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/tests/cpl_plot-test.c 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -41,9 +41,9 @@ Define -----------------------------------------------------------------------------*/ -#define VEC_SIZE 1024 -#define IMA_SIZE 100 -#define TAB_SIZE 100 +#define VEC_SIZE 1024 +#define IMA_SIZE 100 +#define TAB_SIZE 100 #define CPL_PLOT_MIN(A, B) ((A) < (B) ? (A) : (B)) @@ -51,22 +51,25 @@ Private functions -----------------------------------------------------------------------------*/ -static -void cpl_plot_test_all(int, int, int); +static void cpl_plot_test_all(int, int, int); -static -void cpl_plot_test(const cpl_image *, const cpl_mask *, const cpl_table *, - int, const char *[], - const cpl_vector *, const cpl_bivector *, - int, const cpl_vector * const *); +static void cpl_plot_test(const cpl_image *, + const cpl_mask *, + const cpl_table *, + int, + const char *[], + const cpl_vector *, + const cpl_bivector *, + int, + const cpl_vector *const *); /*----------------------------------------------------------------------------- Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { - cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); cpl_plot_test_all(IMA_SIZE, VEC_SIZE, TAB_SIZE); @@ -89,24 +92,22 @@ */ /*----------------------------------------------------------------------------*/ -static -void cpl_plot_test_all(int n2d, int nvec, int nrow) +static void +cpl_plot_test_all(int n2d, int nvec, int nrow) { - - - cpl_vector * sinus; - cpl_vector * cosinus; - cpl_vector * x_deg; - cpl_vector * vec_array[3]; - cpl_bivector * sin_deg; - cpl_image * ima; - double med_dist, median, threshold; - cpl_mask * mask; - cpl_table * tab; - double * px; - double * py; - const char * names[] = {"COLUMN1", "COLUMN2", "COLUMN3"}; - int i; + cpl_vector *sinus; + cpl_vector *cosinus; + cpl_vector *x_deg; + cpl_vector *vec_array[3]; + cpl_bivector *sin_deg; + cpl_image *ima; + double med_dist, median, threshold; + cpl_mask *mask; + cpl_table *tab; + double *px; + double *py; + const char *names[] = { "COLUMN1", "COLUMN2", "COLUMN3" }; + int i; /* Create the vector sinus */ sinus = cpl_vector_new(nvec); @@ -114,16 +115,17 @@ px = cpl_vector_get_data(x_deg); py = cpl_vector_get_data(sinus); - for (i=0; i < nvec; i++) { + for (i = 0; i < nvec; i++) { px[i] = i * 360.0 / nvec; - py[i] = sin( i * CPL_MATH_2PI / nvec); + py[i] = sin(i * CPL_MATH_2PI / nvec); } /* Create the vector cosinus */ cosinus = cpl_vector_new(nvec); py = cpl_vector_get_data(cosinus); - for (i=0; i < nvec; i++) py[i] = cos( i * CPL_MATH_2PI / nvec); - + for (i = 0; i < nvec; i++) + py[i] = cos(i * CPL_MATH_2PI / nvec); + /* Create the vectors array */ vec_array[0] = x_deg; vec_array[1] = sinus; @@ -133,7 +135,7 @@ sin_deg = cpl_bivector_wrap_vectors(x_deg, sinus); /* Create the image */ - ima = cpl_image_fill_test_create(n2d, n2d); + ima = cpl_image_fill_test_create(n2d, n2d); /* Compute the median and the av. dist. to the median of the loaded image */ median = cpl_image_get_median_dev(ima, &med_dist); @@ -145,34 +147,34 @@ cpl_table_new_column(tab, names[0], CPL_TYPE_DOUBLE); cpl_table_new_column(tab, names[1], CPL_TYPE_DOUBLE); cpl_table_new_column(tab, names[2], CPL_TYPE_DOUBLE); - for (i=0; i < nrow; i++) { - cpl_table_set_double(tab, names[0], i, (double)(10*i+1)); - cpl_table_set_double(tab, names[1], i, sin(10*i+1)/(10*i+1)); - cpl_table_set_double(tab, names[2], i, log1p(i)/(i+1)); + for (i = 0; i < nrow; i++) { + cpl_table_set_double(tab, names[0], i, (double)(10 * i + 1)); + cpl_table_set_double(tab, names[1], i, sin(10 * i + 1) / (10 * i + 1)); + cpl_table_set_double(tab, names[2], i, log1p(i) / (i + 1)); } /* No errors should have happened in the plot preparation */ cpl_test_error(CPL_ERROR_NONE); - + /* No plotting is done unless the message level is modified */ if (cpl_msg_get_level() <= CPL_MSG_INFO) { - cpl_plot_test(ima, mask, tab, 3, names, sinus, sin_deg, 3, - (const cpl_vector* const *)vec_array); + (const cpl_vector *const *)vec_array); #ifdef HAVE_SETENV if (!setenv("CPL_IMAGER", "display - &", 1) && !setenv("CPL_PLOTTER", "cat > /dev/null; echo gnuplot > /dev/null", 1)) { cpl_plot_test(ima, mask, tab, 3, names, sinus, sin_deg, 3, - (const cpl_vector* const *)vec_array); + (const cpl_vector *const *)vec_array); } - } else { + } + else { if (!setenv("CPL_IMAGER", "cat > /dev/null", 1) && !setenv("CPL_PLOTTER", "cat > /dev/null; echo gnuplot > /dev/null", 1)) { cpl_plot_test(ima, mask, tab, 3, names, sinus, sin_deg, 3, - (const cpl_vector* const *)vec_array); + (const cpl_vector *const *)vec_array); } #endif } @@ -185,8 +187,6 @@ cpl_vector_delete(sinus); cpl_vector_delete(cosinus); cpl_vector_delete(x_deg); - - } @@ -206,13 +206,17 @@ */ /*----------------------------------------------------------------------------*/ -static -void cpl_plot_test(const cpl_image * image, const cpl_mask * mask, - const cpl_table * table, int ncolumns, const char *names[], - const cpl_vector * vector, const cpl_bivector * bivector, - int nvector, const cpl_vector * const *vec_array) +static void +cpl_plot_test(const cpl_image *image, + const cpl_mask *mask, + const cpl_table *table, + int ncolumns, + const char *names[], + const cpl_vector *vector, + const cpl_bivector *bivector, + int nvector, + const cpl_vector *const *vec_array) { - /* An error may occur, e.g. in the absence of gnuplot. The unit test should still succeed, and it is only verified that the return code equals the CPL error code. */ @@ -225,7 +229,7 @@ cpl_test_eq(cpl_table_get_ncol(table), ncolumns); cpl_test_leq(3, ncolumns); - + error = cpl_plot_bivector("", "w lines", "", bivector); cpl_test_eq_error(error, error0); @@ -233,8 +237,8 @@ cpl_test_eq_error(error, error0); CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); - error = cpl_plot_vectors("", "w lines", "", - (const cpl_vector**)vec_array, nvector); + error = cpl_plot_vectors("", "w lines", "", (const cpl_vector **)vec_array, + nvector); CPL_DIAG_PRAGMA_POP; cpl_test_eq_error(error, error0); @@ -244,26 +248,26 @@ error = cpl_plot_mask("", "w lines", "", mask); cpl_test_eq_error(error, error0); - error = cpl_plot_column("set grid;", "w lines", "", table, names[0], - names[1]); + error = + cpl_plot_column("set grid;", "w lines", "", table, names[0], names[1]); cpl_test_eq_error(error, error0); - error = cpl_plot_column("set grid;", "w lines", "", table, NULL, - names[2]); + error = cpl_plot_column("set grid;", "w lines", "", table, NULL, names[2]); cpl_test_eq_error(error, error0); - error = cpl_plot_columns("set grid;", "w lines", "", table, names, ncolumns); + error = + cpl_plot_columns("set grid;", "w lines", "", table, names, ncolumns); cpl_test_eq_error(error, error0); /* Example of some plotting using the options */ - error = cpl_plot_image_row("set xlabel 'X Position (pixels)';" - "set ylabel 'Counts (ADU)';", "", "", - image, 1, - CPL_PLOT_MIN(10, cpl_image_get_size_y(image)), 1); + error = + cpl_plot_image_row("set xlabel 'X Position (pixels)';" + "set ylabel 'Counts (ADU)';", + "", "", image, 1, + CPL_PLOT_MIN(10, cpl_image_get_size_y(image)), 1); cpl_test_eq_error(error, error0); error = cpl_plot_image_col("set xlabel 'Y Position (pixels)';" - "set ylabel 'Counts (ADU)';", "", "", - image, 1, 1, 1); + "set ylabel 'Counts (ADU)';", + "", "", image, 1, 1, 1); cpl_test_eq_error(error, error0); - } diff -Nru cpl-7.1.4+ds/cplcore/tests/cpl_polynomial-test.c cpl-7.2.2+ds/cplcore/tests/cpl_polynomial-test.c --- cpl-7.1.4+ds/cplcore/tests/cpl_polynomial-test.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/tests/cpl_polynomial-test.c 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -42,11 +42,11 @@ Defines -----------------------------------------------------------------------------*/ -#define POLY_COEF_NB 5 -#define VECTOR_SIZE 1024 -#define POLY_SIZE 24 -#define POLY_DIM 11 -#define BINOMIAL_SZ 8 +#define POLY_COEF_NB 5 +#define VECTOR_SIZE 1024 +#define POLY_SIZE 24 +#define POLY_DIM 11 +#define BINOMIAL_SZ 8 /*----------------------------------------------------------------------------- Pricate functions @@ -56,88 +56,86 @@ static void cpl_polynomial_test_delete(cpl_polynomial *); -static void cpl_polynomial_derivative_test_empty(cpl_polynomial *) - CPL_ATTR_NONNULL; +static void +cpl_polynomial_derivative_test_empty(cpl_polynomial *) CPL_ATTR_NONNULL; -static void cpl_polynomial_basic_test(FILE *) - CPL_ATTR_NONNULL; +static void cpl_polynomial_basic_test(FILE *) CPL_ATTR_NONNULL; -static void cpl_polynomial_shift_test_1d(FILE *) - CPL_ATTR_NONNULL; +static void cpl_polynomial_shift_test_1d(FILE *) CPL_ATTR_NONNULL; -static void cpl_polynomial_shift_test_2d(FILE *, cpl_size) - CPL_ATTR_NONNULL; +static void cpl_polynomial_shift_test_2d(FILE *, cpl_size) CPL_ATTR_NONNULL; -static void cpl_polynomial_shift_test_3d_one(FILE *) - CPL_ATTR_NONNULL; -static void cpl_polynomial_shift_test_2d_one(FILE *) - CPL_ATTR_NONNULL; +static void cpl_polynomial_shift_test_3d_one(FILE *) CPL_ATTR_NONNULL; +static void cpl_polynomial_shift_test_2d_one(FILE *) CPL_ATTR_NONNULL; -static void cpl_polynomial_extract_test_2d(FILE *, cpl_size) - CPL_ATTR_NONNULL; +static void cpl_polynomial_extract_test_2d(FILE *, cpl_size) CPL_ATTR_NONNULL; -static void cpl_polynomial_extract_test_2d_one(FILE *) - CPL_ATTR_NONNULL; -static void cpl_polynomial_extract_test_3d_one(FILE *) - CPL_ATTR_NONNULL; +static void cpl_polynomial_extract_test_2d_one(FILE *) CPL_ATTR_NONNULL; +static void cpl_polynomial_extract_test_3d_one(FILE *) CPL_ATTR_NONNULL; -static void cpl_polynomial_test_1(FILE *) - CPL_ATTR_NONNULL; +static void cpl_polynomial_test_1(FILE *) CPL_ATTR_NONNULL; -static void cpl_polynomial_test_2(FILE *) - CPL_ATTR_NONNULL; +static void cpl_polynomial_test_2(FILE *) CPL_ATTR_NONNULL; -static void cpl_polynomial_multiply_scalar_test_one(FILE *) - CPL_ATTR_NONNULL; +static void cpl_polynomial_multiply_scalar_test_one(FILE *) CPL_ATTR_NONNULL; static void cpl_polynomial_test_3(void); static void cpl_polynomial_test_4(void); -static void cpl_polynomial_test_5(FILE *) - CPL_ATTR_NONNULL; -static void cpl_polynomial_test_6(void) - CPL_ATTR_NONNULL; +static void cpl_polynomial_test_5(FILE *) CPL_ATTR_NONNULL; +static void cpl_polynomial_test_6(void) CPL_ATTR_NONNULL; -static void cpl_polynomial_test_7(FILE *) - CPL_ATTR_NONNULL; +static void cpl_polynomial_test_7(FILE *) CPL_ATTR_NONNULL; static void cpl_polynomial_test_dfs06121(void); -static void cpl_polynomial_fit_3(FILE *) - CPL_ATTR_NONNULL; +static void cpl_polynomial_fit_3(FILE *) CPL_ATTR_NONNULL; static void cpl_polynomial_fit_test_1d(FILE *); -static cpl_polynomial * cpl_polynomial_fit_test_2d(FILE *, cpl_boolean); +static cpl_polynomial *cpl_polynomial_fit_test_2d(FILE *, cpl_boolean); static void cpl_polynomial_fit_bench_2d(cpl_size, cpl_size, cpl_size); +static void cpl_polynomial_fit_test_3d(void); + +static void cpl_polynomial_fit_1d_test_sigma(void); +static void cpl_polynomial_fit_2d_test_sigma(void); +static void cpl_polynomial_fit_3d_test_sigma(void); + +static void cpl_polynomial_eval_2d_test(void); +static void cpl_polynomial_eval_3d_test(void); + static void cpl_vector_fill_polynomial_fit_residual_test(void); -static double cpl_vector_get_mse(const cpl_vector *, +static double cpl_vector_get_mse(const cpl_vector *, const cpl_polynomial *, - const cpl_matrix *, + const cpl_matrix *, double *); -static cpl_error_code cpl_polynomial_fit_cmp(cpl_polynomial *, - const cpl_matrix *, +static cpl_error_code cpl_polynomial_fit_cmp(cpl_polynomial *, + const cpl_matrix *, const cpl_boolean *, - const cpl_vector *, - const cpl_vector *, - cpl_boolean , - const cpl_size *, - const cpl_size *); + const cpl_vector *, + const cpl_vector *, + cpl_boolean, + const cpl_size *, + const cpl_size *); static void cpl_polynomial_fit_cmp_(const cpl_polynomial *, - const cpl_matrix *, + const cpl_matrix *, const cpl_boolean *, - const cpl_vector *, - const cpl_vector *, - cpl_boolean , - const cpl_size *, - const cpl_size *); + const cpl_vector *, + const cpl_vector *, + cpl_boolean, + const cpl_size *, + const cpl_size *); static cpl_error_code cpl_polynomial_multiply_1d(cpl_polynomial *, double); -static void cpl_polynomial_solve_1d_test_ok(const cpl_polynomial *, double, - double, cpl_size, double, double); +static void cpl_polynomial_solve_1d_test_ok(const cpl_polynomial *, + double, + double, + cpl_size, + double, + double); static void cpl_polynomial_compare_test(void); static void cpl_polynomial_multiply_test(void); @@ -145,24 +143,25 @@ static void cpl_polynomial_test_union(void); -static cpl_flops mse_flops = 0; -static double mse_secs = 0.0; +static cpl_flops mse_flops = 0; +static double mse_secs = 0.0; /**@{*/ /*----------------------------------------------------------------------------- Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { - FILE * stream; + FILE *stream; cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); - stream = cpl_msg_get_level() > CPL_MSG_INFO - ? fopen("/dev/null", "a") : stdout; + stream = + cpl_msg_get_level() > CPL_MSG_INFO ? fopen("/dev/null", "a") : stdout; - cpl_test_nonnull( stream ); + cpl_test_nonnull(stream); cpl_polynomial_eval_test_2d_one(); @@ -195,6 +194,15 @@ cpl_polynomial_fit_3(stream); + cpl_polynomial_fit_test_3d(); + + cpl_polynomial_fit_1d_test_sigma(); + cpl_polynomial_fit_2d_test_sigma(); + cpl_polynomial_fit_3d_test_sigma(); + + cpl_polynomial_eval_2d_test(); + cpl_polynomial_eval_3d_test(); + cpl_polynomial_multiply_test(); cpl_polynomial_multiply_test_2d(); @@ -203,30 +211,33 @@ cpl_vector_fill_polynomial_fit_residual_test(); cpl_polynomial_fit_test_1d(stream); - if (cpl_msg_get_level() <= CPL_MSG_INFO) + if (cpl_msg_get_level() <= CPL_MSG_INFO) cpl_polynomial_fit_bench_2d(1, 5 * POLY_SIZE, POLY_SIZE); if (mse_secs > 0.0) - cpl_msg_info("","Speed of cpl_vector_fill_polynomial_fit_residual() " - "over %g secs [Mflop/s]: %g", mse_secs, - (double)mse_flops/mse_secs/1e6); - if (stream != stdout) cpl_test_zero( fclose(stream) ); + cpl_msg_info("", + "Speed of cpl_vector_fill_polynomial_fit_residual() " + "over %g secs [Mflop/s]: %g", + mse_secs, (double)mse_flops / mse_secs / 1e6); + if (stream != stdout) + cpl_test_zero(fclose(stream)); return cpl_test_end(0); } -static void cpl_polynomial_test_union(void) +static void +cpl_polynomial_test_union(void) { - cpl_polynomial * poly1 = cpl_polynomial_new(1); - const cpl_size i0 = POLY_SIZE; - cpl_error_code code; + cpl_polynomial *poly1 = cpl_polynomial_new(1); + const cpl_size i0 = POLY_SIZE; + cpl_error_code code; code = cpl_polynomial_set_coeff(poly1, &i0, 1.0); cpl_test_eq_error(code, CPL_ERROR_NONE); #ifdef CPL_POLYNOMIAL_UNION_IS_DOUBLE_SZ cpl_test_eq(cpl_polynomial_get_1d_size(poly1), - (1+i0) * (cpl_size)sizeof(double)); + (1 + i0) * (cpl_size)sizeof(double)); #endif cpl_test_assert(cpl_test_get_failed() == 0); @@ -234,26 +245,27 @@ cpl_polynomial_test_delete(poly1); } -static void cpl_polynomial_test_1(FILE * stream) +static void +cpl_polynomial_test_1(FILE *stream) { - cpl_polynomial * poly1; - cpl_polynomial * poly2; - cpl_polynomial * nullpoly; - double x = 3.14; - double eps; - cpl_size i; - cpl_error_code code; + cpl_polynomial *poly1; + cpl_polynomial *poly2; + cpl_polynomial *nullpoly; + double x = 3.14; + double eps; + cpl_size i; + cpl_error_code code; nullpoly = cpl_polynomial_extract(NULL, 0, NULL); cpl_test_error(CPL_ERROR_NULL_INPUT); - - cpl_test_null( nullpoly ); + + cpl_test_null(nullpoly); code = cpl_polynomial_derivative(NULL, 0); cpl_test_eq_error(code, CPL_ERROR_NULL_INPUT); /* Create a polynomial */ - + poly1 = cpl_polynomial_new(1); cpl_polynomial_dump(poly1, stream); @@ -271,7 +283,7 @@ nullpoly = cpl_polynomial_extract(poly1, 0, poly1); cpl_test_error(CPL_ERROR_INVALID_TYPE); - cpl_test_null( nullpoly ); + cpl_test_null(nullpoly); code = cpl_polynomial_derivative(poly1, 1); @@ -282,20 +294,20 @@ eps = cpl_polynomial_eval_1d(poly1, 5, &x); cpl_test_error(CPL_ERROR_NONE); - cpl_test_abs( eps, 0.0, 0.0); + cpl_test_abs(eps, 0.0, 0.0); - cpl_test_abs(x, 0.0, 0.0 ); + cpl_test_abs(x, 0.0, 0.0); code = cpl_polynomial_solve_1d(poly1, 5, &x, 1); cpl_test_eq_error(code, CPL_ERROR_NONE); - cpl_test_abs(x, 0.0, 0.0 ); + cpl_test_abs(x, 0.0, 0.0); eps = cpl_polynomial_eval_1d(poly1, 5, &x); cpl_test_error(CPL_ERROR_NONE); - cpl_test_abs( eps, 0.0, 0.0); + cpl_test_abs(eps, 0.0, 0.0); - cpl_test_abs(x, 0.0, 0.0 ); + cpl_test_abs(x, 0.0, 0.0); /* Properly react to a 0-degree polynomial with no roots */ i = 0; @@ -303,7 +315,7 @@ cpl_test_eq_error(code, CPL_ERROR_NONE); eps = cpl_polynomial_get_coeff(poly1, &i); cpl_test_error(CPL_ERROR_NONE); - cpl_test_abs( eps, 1.0, 0.0 ); + cpl_test_abs(eps, 1.0, 0.0); code = cpl_polynomial_solve_1d(poly1, 1, &x, 1); cpl_test_eq_error(code, CPL_ERROR_DIVISION_BY_ZERO); @@ -313,81 +325,83 @@ code = cpl_polynomial_derivative(poly1, 0); cpl_test_eq_error(code, CPL_ERROR_NONE); - cpl_test_abs( cpl_polynomial_eval_1d(poly1, 5, &x), 0.0, 0.0); + cpl_test_abs(cpl_polynomial_eval_1d(poly1, 5, &x), 0.0, 0.0); - cpl_test_abs( x, 0.0, 0.0); + cpl_test_abs(x, 0.0, 0.0); i = VECTOR_SIZE; - code = cpl_polynomial_set_coeff(poly1, &i, 1) ; + code = cpl_polynomial_set_coeff(poly1, &i, 1); cpl_test_eq_error(code, CPL_ERROR_NONE); - cpl_test_abs( cpl_polynomial_get_coeff(poly1, &i), 1.0, 0.0 ); + cpl_test_abs(cpl_polynomial_get_coeff(poly1, &i), 1.0, 0.0); - code = cpl_polynomial_set_coeff(poly1, &i, 0) ; + code = cpl_polynomial_set_coeff(poly1, &i, 0); cpl_test_eq_error(code, CPL_ERROR_NONE); - cpl_test_eq( cpl_polynomial_get_dimension(poly1), 1); - cpl_test_zero( cpl_polynomial_get_degree(poly1)); + cpl_test_eq(cpl_polynomial_get_dimension(poly1), 1); + cpl_test_zero(cpl_polynomial_get_degree(poly1)); - cpl_test( poly2 = cpl_polynomial_duplicate(poly1) ); + cpl_test(poly2 = cpl_polynomial_duplicate(poly1)); - cpl_test_zero( cpl_polynomial_get_degree(poly2)); + cpl_test_zero(cpl_polynomial_get_degree(poly2)); cpl_polynomial_test_delete(poly2); - cpl_test( poly2 = cpl_polynomial_new(VECTOR_SIZE) ); + cpl_test(poly2 = cpl_polynomial_new(VECTOR_SIZE)); - cpl_test_eq( cpl_polynomial_get_dimension(poly2), VECTOR_SIZE ); - cpl_test_zero( cpl_polynomial_get_degree(poly2)); + cpl_test_eq(cpl_polynomial_get_dimension(poly2), VECTOR_SIZE); + cpl_test_zero(cpl_polynomial_get_degree(poly2)); code = cpl_polynomial_copy(poly2, poly1); cpl_test_eq_error(code, CPL_ERROR_NONE); - cpl_test_eq( cpl_polynomial_get_dimension(poly2), 1 ); - cpl_test_zero( cpl_polynomial_get_degree(poly2)); + cpl_test_eq(cpl_polynomial_get_dimension(poly2), 1); + cpl_test_zero(cpl_polynomial_get_degree(poly2)); cpl_polynomial_test_delete(poly1); cpl_polynomial_test_delete(poly2); - } -static void cpl_polynomial_test_2(FILE * stream) +static void +cpl_polynomial_test_2(FILE *stream) { - cpl_polynomial * poly1; - cpl_polynomial * poly2; - double x = 3.14; - double z1; - cpl_vector * vec; - double * vec_data; - cpl_size i, j; - int icmp; - cpl_error_code code; + cpl_polynomial *poly1; + cpl_polynomial *poly2; + double x = 3.14; + double z1; + cpl_vector *vec; + double *vec_data; + cpl_size i, j; + int icmp; + cpl_error_code code; poly1 = cpl_polynomial_new(1); /* Set the coefficients : 1 + 2.x + 3.x^2 + 4.x^3 + 5.x^4 */ for (i = 0; i < POLY_COEF_NB; i++) { - if (i % (POLY_COEF_NB-2) != 0) continue; - code = cpl_polynomial_set_coeff(poly1, &i, (double)(i+1)); + if (i % (POLY_COEF_NB - 2) != 0) + continue; + code = cpl_polynomial_set_coeff(poly1, &i, (double)(i + 1)); cpl_test_eq_error(code, CPL_ERROR_NONE); cpl_polynomial_dump(poly1, stream); } for (i = 0; i < POLY_COEF_NB; i++) { - if (i % (POLY_COEF_NB-2) == 0) continue; + if (i % (POLY_COEF_NB - 2) == 0) + continue; cpl_polynomial_dump(poly1, stream); - code = cpl_polynomial_set_coeff(poly1, &i, (double)(i+1)); + code = cpl_polynomial_set_coeff(poly1, &i, (double)(i + 1)); cpl_test_eq_error(code, CPL_ERROR_NONE); } cpl_polynomial_dump(poly1, stream); /* Test cpl_polynomial_get_degree() */ i = cpl_polynomial_get_degree(poly1); cpl_test_error(CPL_ERROR_NONE); - cpl_test_eq(i , POLY_COEF_NB-1); + cpl_test_eq(i, POLY_COEF_NB - 1); /* Test cpl_polynomial_get_coeff() */ - for (i=0; i < POLY_COEF_NB ; i++) { + for (i = 0; i < POLY_COEF_NB; i++) { const double coeff = cpl_polynomial_get_coeff(poly1, &i); cpl_test_error(CPL_ERROR_NONE); - cpl_test_abs(coeff, (double)(i+1), 0.0); + cpl_test_abs(coeff, (double)(i + 1), 0.0); } /* Test cpl_polynomial_eval() */ @@ -425,7 +439,7 @@ code = cpl_polynomial_multiply_scalar(poly1, poly2, 1.0); cpl_test_eq_error(code, CPL_ERROR_NONE); - cpl_test_polynomial_abs( poly1, poly2, 0.0); + cpl_test_polynomial_abs(poly1, poly2, 0.0); i = 10 + cpl_polynomial_get_degree(poly1); code = cpl_polynomial_set_coeff(poly1, &i, 42.0); @@ -463,12 +477,13 @@ cpl_polynomial_test_delete(poly2); } -static void cpl_polynomial_test_3(void) +static void +cpl_polynomial_test_3(void) { - cpl_polynomial * poly1; - double x; - cpl_size i; - cpl_error_code code; + cpl_polynomial *poly1; + double x; + cpl_size i; + cpl_error_code code; x = 3.14; @@ -490,9 +505,9 @@ cpl_test_eq_error(code, CPL_ERROR_NONE); code = cpl_polynomial_solve_1d(poly1, 5, &x, 1); - cpl_test_eq_error( code, CPL_ERROR_NONE); + cpl_test_eq_error(code, CPL_ERROR_NONE); - cpl_test_abs( x, 1.0, 0.0 ); + cpl_test_abs(x, 1.0, 0.0); cpl_polynomial_solve_1d_test_ok(poly1, 2.0, 2.0, 1, 0.0, 0.0); cpl_polynomial_solve_1d_test_ok(poly1, 2.0, 2.1, 1, 0.0, 0.0); @@ -502,21 +517,21 @@ cpl_polynomial_solve_1d_test_ok(poly1, 1.0, 2.0, 2, 5e5 * DBL_EPSILON, 0.0); cpl_polynomial_test_delete(poly1); - } -static void cpl_polynomial_test_4(void) +static void +cpl_polynomial_test_4(void) { - cpl_polynomial * poly1; - double x, y, z2; - cpl_vector * vec; - cpl_vector * taylor; - double * vec_data; - double xmax = 0; /* Maximum rounding error on x */ - double ymax = 0; /* Maximum rounding error on y */ - double eps; - cpl_size i; - cpl_error_code code; + cpl_polynomial *poly1; + double x, y, z2; + cpl_vector *vec; + cpl_vector *taylor; + double *vec_data; + double xmax = 0; /* Maximum rounding error on x */ + double ymax = 0; /* Maximum rounding error on y */ + double eps; + cpl_size i; + cpl_error_code code; x = 3.14; y = 2.72; @@ -525,81 +540,82 @@ poly1 = cpl_polynomial_new(1); /* Create a tmporary vector - with a small length */ - cpl_test_nonnull( vec = cpl_vector_new(POLY_SIZE) ); - + cpl_test_nonnull(vec = cpl_vector_new(POLY_SIZE)); + /* Fill the vector with a exp() Taylor series */ vec_data = cpl_vector_get_data(vec); - cpl_test_nonnull( vec_data ); + cpl_test_nonnull(vec_data); i = 0; vec_data[i] = 1; - for (i=1 ; i < POLY_SIZE ; i++) { - vec_data[i] = vec_data[i-1] / (double)i; + for (i = 1; i < POLY_SIZE; i++) { + vec_data[i] = vec_data[i - 1] / (double)i; } - for (i=POLY_SIZE-1 ; i >= 0; i--) { - code = cpl_polynomial_set_coeff(poly1, &i, vec_data[i]) ; + for (i = POLY_SIZE - 1; i >= 0; i--) { + code = cpl_polynomial_set_coeff(poly1, &i, vec_data[i]); cpl_test_eq_error(code, CPL_ERROR_NONE); } - cpl_test_eq( cpl_polynomial_get_degree(poly1), POLY_SIZE-1); + cpl_test_eq(cpl_polynomial_get_degree(poly1), POLY_SIZE - 1); cpl_test_abs(cpl_polynomial_eval_1d(poly1, 0, &y), 1.0, DBL_EPSILON); - cpl_test_abs( y, 1.0, DBL_EPSILON); + cpl_test_abs(y, 1.0, DBL_EPSILON); /* See how far away from zero the approximation holds */ x = DBL_EPSILON; - while ( fabs(cpl_polynomial_eval_1d(poly1, x, NULL)-exp( x)) - < DBL_EPSILON * exp( x) && - fabs(cpl_polynomial_eval_1d(poly1,-x, &y)-exp(-x)) - < DBL_EPSILON * exp(-x) ) { + while (fabs(cpl_polynomial_eval_1d(poly1, x, NULL) - exp(x)) < + DBL_EPSILON * exp(x) && + fabs(cpl_polynomial_eval_1d(poly1, -x, &y) - exp(-x)) < + DBL_EPSILON * exp(-x)) { /* Differentation of exp() does not change anything - but in the case of a Taylor approximation one term is lost and with it a bit of precision */ - cpl_test_rel( exp(-x), y, 7.5 * DBL_EPSILON); + cpl_test_rel(exp(-x), y, 7.5 * DBL_EPSILON); x *= 2; } x /= 2; /* FIXME: Verify the correctness of this test */ - cpl_test_leq( -x, -FLT_EPSILON); /* OK for POLY_SIZE >= 4 */ + cpl_test_leq(-x, -FLT_EPSILON); /* OK for POLY_SIZE >= 4 */ z2 = 2 * x / VECTOR_SIZE; /* Evaluate a sequence of exp()-approximations */ taylor = cpl_vector_new(VECTOR_SIZE); - cpl_test_zero( cpl_vector_fill_polynomial(taylor, poly1, -x, z2)); + cpl_test_zero(cpl_vector_fill_polynomial(taylor, poly1, -x, z2)); vec_data = cpl_vector_get_data(taylor); - cpl_test_nonnull( vec_data ); - for (i=0 ; i < VECTOR_SIZE ; i++) { - const double xapp = -x + (double)i * z2; - const double yapp = exp( xapp ); + cpl_test_nonnull(vec_data); + for (i = 0; i < VECTOR_SIZE; i++) { + const double xapp = -x + (double)i * z2; + const double yapp = exp(xapp); /* cpl_vector_fill_polynomial() is just a wrapper */ - cpl_test_abs( vec_data[i], cpl_polynomial_eval_1d(poly1, xapp, &y), - 2*DBL_EPSILON); + cpl_test_abs(vec_data[i], cpl_polynomial_eval_1d(poly1, xapp, &y), + 2 * DBL_EPSILON); - if ( fabs(y - yapp ) > ymax * yapp ) - ymax = fabs(y - yapp ) / yapp; + if (fabs(y - yapp) > ymax * yapp) + ymax = fabs(y - yapp) / yapp; - if ( fabs(vec_data[i] - yapp ) > xmax * yapp ) - xmax = fabs(vec_data[i] - yapp ) / yapp; + if (fabs(vec_data[i] - yapp) > xmax * yapp) + xmax = fabs(vec_data[i] - yapp) / yapp; } - cpl_msg_info("","Rounding on %d-term Taylor-exp() in range [%g; %g] " - "[DBL_EPSILON]: %7.5f %7.5f", POLY_SIZE, -x, x, xmax/DBL_EPSILON, - ymax/DBL_EPSILON); + cpl_msg_info("", + "Rounding on %d-term Taylor-exp() in range [%g; %g] " + "[DBL_EPSILON]: %7.5f %7.5f", + POLY_SIZE, -x, x, xmax / DBL_EPSILON, ymax / DBL_EPSILON); - cpl_test_leq( xmax, 2.0*DBL_EPSILON); - cpl_test_leq( xmax, ymax); - cpl_test_leq( ymax, 7.39*DBL_EPSILON); + cpl_test_leq(xmax, 2.0 * DBL_EPSILON); + cpl_test_leq(xmax, ymax); + cpl_test_leq(ymax, 7.39 * DBL_EPSILON); vec_data = cpl_vector_get_data(vec); eps = vec_data[0]; /* Solve p(y) = exp(x/2) - i.e. compute a logarithm */ i = 0; - vec_data[i] -= exp(x/2); + vec_data[i] -= exp(x / 2); cpl_polynomial_set_coeff(poly1, &i, vec_data[i]); code = cpl_polynomial_solve_1d(poly1, -x * x, &y, 1); cpl_test_eq_error(code, CPL_ERROR_NONE); @@ -608,10 +624,11 @@ cpl_polynomial_set_coeff(poly1, &i, vec_data[i]); /* Check solution - allow up to 2 * meps rounding */ - cpl_test_rel( y, x/2, 2.0*DBL_EPSILON); + cpl_test_rel(y, x / 2, 2.0 * DBL_EPSILON); /* Check Residual - allow up to 2 * meps rounding */ - cpl_test_rel( cpl_polynomial_eval_1d(poly1, y, NULL), exp(x/2), 2.0 * DBL_EPSILON ); + cpl_test_rel(cpl_polynomial_eval_1d(poly1, y, NULL), exp(x / 2), + 2.0 * DBL_EPSILON); /* Free */ cpl_vector_delete(vec); @@ -620,19 +637,20 @@ cpl_polynomial_test_delete(poly1); } -static void cpl_polynomial_test_5(FILE * stream) +static void +cpl_polynomial_test_5(FILE *stream) { - cpl_polynomial * poly1; - cpl_polynomial * poly2; - cpl_polynomial * poly3; - double x, y, z1, z2; - double z, x1; + cpl_polynomial *poly1; + cpl_polynomial *poly2; + cpl_polynomial *poly3; + double x, y, z1, z2; + double z, x1; /* Some binomial coefficients */ - double p15[8] = {1,15,105,455,1365,3003,5005,6435}; - double eps; - cpl_size expo[POLY_DIM]; - cpl_size i, j; - cpl_error_code code; + double p15[8] = { 1, 15, 105, 455, 1365, 3003, 5005, 6435 }; + double eps; + cpl_size expo[POLY_DIM]; + cpl_size i, j; + cpl_error_code code; x = 3.14; y = 2.72; @@ -647,7 +665,7 @@ i++; cpl_polynomial_set_coeff(poly1, &i, 1); - cpl_test_eq( cpl_polynomial_get_degree(poly1), 2); + cpl_test_eq(cpl_polynomial_get_degree(poly1), 2); /* Properly react on a polynomial with no real roots */ code = cpl_polynomial_solve_1d(poly1, 0, &x, 1); @@ -665,23 +683,23 @@ poly1 = cpl_polynomial_new(1); /* The simplest 15-degree polynomial */ - i =15; + i = 15; cpl_polynomial_set_coeff(poly1, &i, 1); - cpl_test_eq( cpl_polynomial_get_degree(poly1), i); + cpl_test_eq(cpl_polynomial_get_degree(poly1), i); code = cpl_polynomial_solve_1d(poly1, 10, &x, i); cpl_test_eq_error(code, CPL_ERROR_NONE); - cpl_test_abs( x, 0.0, DBL_EPSILON); - cpl_test_abs( cpl_polynomial_eval_1d(poly1, x, &y), 0.0, DBL_EPSILON); - cpl_test_abs( y, 0.0, DBL_EPSILON); + cpl_test_abs(x, 0.0, DBL_EPSILON); + cpl_test_abs(cpl_polynomial_eval_1d(poly1, x, &y), 0.0, DBL_EPSILON); + cpl_test_abs(y, 0.0, DBL_EPSILON); /* -1 is a root with multiplicity 15 */ x1 = -1; poly2 = cpl_polynomial_duplicate(poly1); - code = cpl_polynomial_shift_1d(poly2, 0, -x1) ; + code = cpl_polynomial_shift_1d(poly2, 0, -x1); cpl_test_eq_error(code, CPL_ERROR_NONE); /* poly2 now holds the binomial coefficients for n = 15 */ @@ -694,76 +712,79 @@ i = 15; - cpl_test_eq( cpl_polynomial_get_degree(poly1), i); + cpl_test_eq(cpl_polynomial_get_degree(poly1), i); for (i = 0; i < 8; i++) { j = 15 - i; z1 = cpl_polynomial_get_coeff(poly1, &i); z2 = cpl_polynomial_get_coeff(poly2, &i); - z = cpl_polynomial_get_coeff(poly2, &j); - cpl_test_rel( z1, z2, 1.0 * DBL_EPSILON); - cpl_test_rel( z, z2, 1.0 * DBL_EPSILON); + z = cpl_polynomial_get_coeff(poly2, &j); + cpl_test_rel(z1, z2, 1.0 * DBL_EPSILON); + cpl_test_rel(z, z2, 1.0 * DBL_EPSILON); } - cpl_test_zero( cpl_polynomial_compare(poly1,poly2,0) ); - + cpl_test_zero(cpl_polynomial_compare(poly1, poly2, 0)); + i = 15; - code = cpl_polynomial_solve_1d(poly1, 10*x1, &x, i); + code = cpl_polynomial_solve_1d(poly1, 10 * x1, &x, i); cpl_test_eq_error(code, CPL_ERROR_NONE); z = cpl_polynomial_eval_1d(poly1, x, &y); cpl_msg_info("", "(X+1)^15 (%" CPL_SIZE_FORMAT "): %g %g %g", i, - (x-x1)/DBL_EPSILON, z/DBL_EPSILON, y/DBL_EPSILON); - cpl_test_rel( x, x1, DBL_EPSILON ); - cpl_test_abs( z, 0.0, DBL_EPSILON ); - cpl_test_abs( y, 0.0, DBL_EPSILON); + (x - x1) / DBL_EPSILON, z / DBL_EPSILON, y / DBL_EPSILON); + cpl_test_rel(x, x1, DBL_EPSILON); + cpl_test_abs(z, 0.0, DBL_EPSILON); + cpl_test_abs(y, 0.0, DBL_EPSILON); /* Lots of round-off here, which depends on the long double precision */ i = 5; - code = cpl_polynomial_solve_1d(poly1, -10*x1, &x, i); + code = cpl_polynomial_solve_1d(poly1, -10 * x1, &x, i); cpl_test_eq_error(code, CPL_ERROR_NONE); z = cpl_polynomial_eval_1d(poly1, x, &y); - cpl_msg_info("", "(X+1)^15 (%" CPL_SIZE_FORMAT ") " CPL_LDBL_EPSILON_STR - ": %g %g %g", i, x-x1, - (double)(z/CPL_LDBL_EPSILON), - (double)(y/CPL_LDBL_EPSILON)); - cpl_test_rel( x, x1, 0.35 ); /* alphaev56 */ - cpl_test_abs( z, 0.0, 18202.0 * DBL_EPSILON); - cpl_test_abs( y, 0.0, 1554616.0 * DBL_EPSILON); /* alphaev56 */ + cpl_msg_info("", + "(X+1)^15 (%" CPL_SIZE_FORMAT ") " CPL_LDBL_EPSILON_STR + ": %g %g %g", + i, x - x1, (double)(z / CPL_LDBL_EPSILON), + (double)(y / CPL_LDBL_EPSILON)); + cpl_test_rel(x, x1, 0.35); /* alphaev56 */ + cpl_test_abs(z, 0.0, 18202.0 * DBL_EPSILON); + cpl_test_abs(y, 0.0, 1554616.0 * DBL_EPSILON); /* alphaev56 */ i = 15; eps = 2 * DBL_EPSILON; cpl_polynomial_set_coeff(poly1, &i, 1 + eps); - cpl_test( cpl_polynomial_compare(poly1,poly2,-eps/2) < 0); + cpl_test(cpl_polynomial_compare(poly1, poly2, -eps / 2) < 0); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); - cpl_test_zero( cpl_polynomial_compare(poly1,poly2,eps) ); - cpl_test( cpl_polynomial_compare(poly1,poly2,eps/2) > 0); + cpl_test_zero(cpl_polynomial_compare(poly1, poly2, eps)); + cpl_test(cpl_polynomial_compare(poly1, poly2, eps / 2) > 0); cpl_polynomial_test_delete(poly2); poly2 = cpl_polynomial_new(POLY_DIM); cpl_polynomial_dump(poly2, stream); - cpl_test_eq( cpl_polynomial_get_dimension(poly2), POLY_DIM); - cpl_test_zero( cpl_polynomial_get_degree(poly2)); + cpl_test_eq(cpl_polynomial_get_dimension(poly2), POLY_DIM); + cpl_test_zero(cpl_polynomial_get_degree(poly2)); /* Set and reset some (outragous) coefficient */ - for (j = 0; j =0; i--) - cpl_test_abs( cpl_polynomial_get_coeff(poly1, &i), 0.0, 0.0); + for (i = 14; i >= 0; i--) + cpl_test_abs(cpl_polynomial_get_coeff(poly1, &i), 0.0, 0.0); - code = cpl_polynomial_copy(poly1, poly2) ; + code = cpl_polynomial_copy(poly1, poly2); cpl_test_eq_error(code, CPL_ERROR_NONE); - cpl_test_eq( cpl_polynomial_get_dimension(poly2), POLY_DIM); - cpl_test_zero( cpl_polynomial_compare(poly1, poly2, 0) ); + cpl_test_eq(cpl_polynomial_get_dimension(poly2), POLY_DIM); + cpl_test_zero(cpl_polynomial_compare(poly1, poly2, 0)); i = 12; - for (j = 0; j 0; i--) { - + for (cpl_size i = POLY_SIZE - 1; i > 0; i--) { x1 *= (double)i; code = cpl_polynomial_derivative(poly1, 0); cpl_test_eq_error(code, CPL_ERROR_NONE); @@ -1245,8 +1270,8 @@ cpl_test_error(CPL_ERROR_NONE); cpl_test_zero(deg1); - /* Verify the value of the constant term */ - cpl_test_abs( x1, cpl_polynomial_get_coeff(poly1, &i0), 0.0); + /* Verify the value of the constant term */ + cpl_test_abs(x1, cpl_polynomial_get_coeff(poly1, &i0), 0.0); cpl_polynomial_test_delete(poly1); @@ -1259,19 +1284,19 @@ x1 = 1.0; for (cpl_size i = 0; i < POLY_SIZE; i++) { for (cpl_size j = 0; j < POLY_SIZE; j++) { - const cpl_size expo[2] = {i, j}; + const cpl_size expo[2] = { i, j }; code = cpl_polynomial_set_coeff(poly1, expo, x); cpl_test_eq_error(code, CPL_ERROR_NONE); } - if (i > 0) x1 *= (double)i; + if (i > 0) + x1 *= (double)i; } code = cpl_polynomial_set_coeff(poly3, &i0, y); cpl_test_eq_error(code, CPL_ERROR_NONE); for (cpl_size j = 0; j < 2; j++) { - poly2 = cpl_polynomial_extract(poly1, j, poly3); cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(poly2); @@ -1286,7 +1311,7 @@ for (cpl_size i = 0; i < POLY_SIZE; i++) { z = cpl_polynomial_get_coeff(poly2, &i); cpl_test_error(CPL_ERROR_NONE); - cpl_test_abs( z, z1, 2.0*POLY_SIZE*FLT_EPSILON); + cpl_test_abs(z, z1, 2.0 * POLY_SIZE * FLT_EPSILON); } code = cpl_polynomial_derivative(poly2, 0); @@ -1294,10 +1319,11 @@ z = cpl_polynomial_get_coeff(poly2, &i0); - for (cpl_size i = 1; i < POLY_SIZE-1; i++) { + for (cpl_size i = 1; i < POLY_SIZE - 1; i++) { z1 = cpl_polynomial_get_coeff(poly2, &i); cpl_test_error(CPL_ERROR_NONE); - cpl_test_abs( z * (double)(i+1), z1, 11.0*POLY_SIZE*FLT_EPSILON); + cpl_test_abs(z * (double)(i + 1), z1, + 11.0 * POLY_SIZE * FLT_EPSILON); } cpl_polynomial_test_delete(poly2); @@ -1305,7 +1331,7 @@ cpl_polynomial_test_delete(poly3); - for (cpl_size i = POLY_SIZE-1; i > 0; i--) { + for (cpl_size i = POLY_SIZE - 1; i > 0; i--) { code = cpl_polynomial_derivative(poly1, 0); cpl_test_eq_error(code, CPL_ERROR_NONE); @@ -1323,19 +1349,20 @@ /* The constant term is huge at this point - reduce by a factor eps which is inaccurate */ eps = x2 * DBL_EPSILON > 1 ? x2 * DBL_EPSILON : 1; - xmax = x2/eps - x * x1 * x1/eps; - cpl_test_abs( xmax, 0.0, 1.0); + xmax = x2 / eps - x * x1 * x1 / eps; + cpl_test_abs(xmax, 0.0, 1.0); cpl_polynomial_test_delete(poly1); } -static void cpl_polynomial_test_dfs06121(void) +static void +cpl_polynomial_test_dfs06121(void) { - cpl_polynomial * poly2; - cpl_size expo[2]; - cpl_size i; - cpl_error_code code; + cpl_polynomial *poly2; + cpl_size expo[2]; + cpl_size i; + cpl_error_code code; /* Test for DFS06121 */ @@ -1376,7 +1403,6 @@ cpl_test_zero(i); cpl_polynomial_test_delete(poly2); - } /**@}*/ @@ -1389,19 +1415,18 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_vector_fill_polynomial_fit_residual_test(void) +static void +cpl_vector_fill_polynomial_fit_residual_test(void) { - - cpl_error_code code; + cpl_error_code code; /* Test 1: NULL input */ - code = cpl_vector_fill_polynomial_fit_residual(NULL, NULL, NULL, NULL, - NULL, NULL); + code = cpl_vector_fill_polynomial_fit_residual(NULL, NULL, NULL, NULL, NULL, + NULL); cpl_test_eq_error(code, CPL_ERROR_NULL_INPUT); return; - } /*----------------------------------------------------------------------------*/ @@ -1414,29 +1439,28 @@ */ /*----------------------------------------------------------------------------*/ -static cpl_polynomial * cpl_polynomial_fit_test_2d(FILE * stream, - cpl_boolean dimdeg) +static cpl_polynomial * +cpl_polynomial_fit_test_2d(FILE *stream, cpl_boolean dimdeg) { - - cpl_matrix * xy_pos; - cpl_vector * xpoint; - cpl_vector * xpoint0; - const double xy_offset = 100; - cpl_size degree; - cpl_polynomial * poly1 = cpl_polynomial_new(2); - cpl_polynomial * poly2 = cpl_polynomial_new(2); - cpl_polynomial * poly2a = cpl_polynomial_new(2); - cpl_vector * vec; - double xmax = 0.0; /* Maximum rounding code on x */ - double ymax = 0.0; /* Maximum rounding code on y */ - double eps; - double x, y; - const cpl_size zerodeg2[] = {0, 0}; - const cpl_size zerodeg2a[] = {1, 1}; - cpl_size i, j, k; - double * dxy_pos; - double * dvec; - cpl_error_code code; + cpl_matrix *xy_pos; + cpl_vector *xpoint; + cpl_vector *xpoint0; + const double xy_offset = 100; + cpl_size degree; + cpl_polynomial *poly1 = cpl_polynomial_new(2); + cpl_polynomial *poly2 = cpl_polynomial_new(2); + cpl_polynomial *poly2a = cpl_polynomial_new(2); + cpl_vector *vec; + double xmax = 0.0; /* Maximum rounding code on x */ + double ymax = 0.0; /* Maximum rounding code on y */ + double eps; + double x, y; + const cpl_size zerodeg2[] = { 0, 0 }; + const cpl_size zerodeg2a[] = { 1, 1 }; + cpl_size i, j, k; + double *dxy_pos; + double *dvec; + cpl_error_code code; /* Try to fit increasing degrees to f(x,y) = sqrt(x)*log(1+y) @@ -1450,13 +1474,13 @@ xpoint = cpl_vector_new(2); /* f(1/4,sqrt(e)-1) = 1/4 */ - cpl_vector_set(xpoint, 0, 0.25+xy_offset); - cpl_vector_set(xpoint, 1, sqrt(CPL_MATH_E)-1+xy_offset); + cpl_vector_set(xpoint, 0, 0.25 + xy_offset); + cpl_vector_set(xpoint, 1, sqrt(CPL_MATH_E) - 1 + xy_offset); for (degree = 0; degree < POLY_SIZE; degree++) { - const cpl_size maxdeg[2] = {degree, degree}; - const cpl_size nc = dimdeg ? (degree+1)*(degree+1) - : (degree+1)*(degree+2)/2; + const cpl_size maxdeg[2] = { degree, degree }; + const cpl_size nc = dimdeg ? (degree + 1) * (degree + 1) + : (degree + 1) * (degree + 2) / 2; cpl_msg_info(cpl_func, "Fitting degree=%d, nc=%d, dimdeg=%d", (int)degree, (int)nc, (int)dimdeg); @@ -1469,31 +1493,33 @@ dxy_pos = cpl_matrix_get_data(xy_pos); for (i = 0; i < 1 + degree; i++) { - for (j=0; j < 1 + (dimdeg ? degree : i); j++, k++) { - dxy_pos[ k] = (double)i+xy_offset; - dxy_pos[nc + k] = (double)j+xy_offset; - dvec[ k] = sqrt((double)i) * log((double)(j+1)); + for (j = 0; j < 1 + (dimdeg ? degree : i); j++, k++) { + dxy_pos[k] = (double)i + xy_offset; + dxy_pos[nc + k] = (double)j + xy_offset; + dvec[k] = sqrt((double)i) * log((double)(j + 1)); } } - cpl_test_eq( k, nc ); + cpl_test_eq(k, nc); /* First try with mindeg = 1 */ - code = cpl_polynomial_fit_cmp(poly2a, xy_pos, NULL, vec, NULL, - dimdeg, zerodeg2a, maxdeg); + code = cpl_polynomial_fit_cmp(poly2a, xy_pos, NULL, vec, NULL, dimdeg, + zerodeg2a, maxdeg); if (degree == 0) { cpl_test_eq_error(code, CPL_ERROR_ILLEGAL_INPUT); - } else if (code == CPL_ERROR_SINGULAR_MATRIX) { + } + else if (code == CPL_ERROR_SINGULAR_MATRIX) { cpl_msg_info(cpl_func, "Singular fit: degree=%d, nc=%d, dimdeg=%d", (int)degree, (int)nc, (int)dimdeg); cpl_test_error(CPL_ERROR_SINGULAR_MATRIX); cpl_test_leq(11, nc); /* Currently attainable precision */ - } else { + } + else { cpl_test_eq_error(code, CPL_ERROR_NONE); - cpl_test_eq( cpl_polynomial_get_dimension(poly2a), 2 ); - cpl_test_eq( cpl_polynomial_get_degree(poly2a), - dimdeg ? 2 * degree : degree ); + cpl_test_eq(cpl_polynomial_get_dimension(poly2a), 2); + cpl_test_eq(cpl_polynomial_get_degree(poly2a), + dimdeg ? 2 * degree : degree); cpl_polynomial_dump(poly2a, stream); @@ -1507,52 +1533,55 @@ cpl_test_error(CPL_ERROR_NONE); } - code = cpl_polynomial_fit_cmp(poly2, xy_pos, NULL, vec, NULL, - dimdeg, zerodeg2, maxdeg); + code = cpl_polynomial_fit_cmp(poly2, xy_pos, NULL, vec, NULL, dimdeg, + zerodeg2, maxdeg); cpl_test_eq_error(code, CPL_ERROR_NONE); - cpl_test_eq( cpl_polynomial_get_dimension(poly2), 2 ); - cpl_test_eq( cpl_polynomial_get_degree(poly2), - dimdeg ? 2 * degree : degree ); + cpl_test_eq(cpl_polynomial_get_dimension(poly2), 2); + cpl_test_eq(cpl_polynomial_get_degree(poly2), + dimdeg ? 2 * degree : degree); cpl_polynomial_dump(poly2, stream); eps = cpl_vector_get_mse(vec, poly2, xy_pos, NULL); /* The increase in mse must be bound */ - if (xmax > 0) cpl_test_leq( eps/xmax, 5.39953e+09); + if (xmax > 0) + cpl_test_leq(eps / xmax, 5.39953e+09); cpl_matrix_delete(xy_pos); - cpl_msg_info(cpl_func,"2D-Polynomial with degree %" CPL_SIZE_FORMAT - " (dimdeg=%d) fit of a %" CPL_SIZE_FORMAT "-point " - "dataset has a mean square error ratio to a %" - CPL_SIZE_FORMAT "-degree fit: %g (%g > %g)", degree, - dimdeg, nc, degree-1, xmax > 0.0 ? eps/xmax : 0.0, - eps, xmax); + cpl_msg_info( + cpl_func, + "2D-Polynomial with degree %" CPL_SIZE_FORMAT + " (dimdeg=%d) fit of a %" CPL_SIZE_FORMAT "-point " + "dataset has a mean square error ratio to a %" CPL_SIZE_FORMAT + "-degree fit: %g (%g > %g)", + degree, dimdeg, nc, degree - 1, xmax > 0.0 ? eps / xmax : 0.0, eps, + xmax); xmax = eps; eps = cpl_polynomial_eval(poly2, xpoint); if (nc < (dimdeg ? 25 : 40)) - cpl_test_abs( eps, 0.25, fabs(0.25 - ymax)); + cpl_test_abs(eps, 0.25, fabs(0.25 - ymax)); cpl_vector_delete(vec); - if (fabs(0.25-eps) >= fabs(0.25 - ymax) && degree > 0) { + if (fabs(0.25 - eps) >= fabs(0.25 - ymax) && degree > 0) { /* Should be able to fit at least a 5-degree polynomial with increased accuracy - and without code-margin */ - cpl_msg_info(cpl_func,"2D-Polynomial with degree %" CPL_SIZE_FORMAT + cpl_msg_info(cpl_func, + "2D-Polynomial with degree %" CPL_SIZE_FORMAT " fit of a %" CPL_SIZE_FORMAT "-point dataset has a " "greater residual than a %" CPL_SIZE_FORMAT "-degree " "fit to a %" CPL_SIZE_FORMAT "-point dataset: " - "fabs(%g) > fabs(%g)", degree, nc, degree-1, - degree*(degree+1)/2, eps-0.25, ymax-0.25); + "fabs(%g) > fabs(%g)", + degree, nc, degree - 1, degree * (degree + 1) / 2, + eps - 0.25, ymax - 0.25); break; } ymax = eps; - - } /* Try to fit increasing degrees to f(x,y) = sqrt(x)*log(1+y) @@ -1561,41 +1590,40 @@ becomes near singular */ /* f(1/4,sqrt(e)-1) = 1/4 */ - cpl_vector_set(xpoint, 0, 0.25+xy_offset); - cpl_vector_set(xpoint, 1, sqrt(CPL_MATH_E)-1-xy_offset); + cpl_vector_set(xpoint, 0, 0.25 + xy_offset); + cpl_vector_set(xpoint, 1, sqrt(CPL_MATH_E) - 1 - xy_offset); k = 0; - vec = cpl_vector_new( 2 * POLY_SIZE * 2 * POLY_SIZE); + vec = cpl_vector_new(2 * POLY_SIZE * 2 * POLY_SIZE); dvec = cpl_vector_get_data(vec); xy_pos = cpl_matrix_new(2, 2 * POLY_SIZE * 2 * POLY_SIZE); dxy_pos = cpl_matrix_get_data(xy_pos); for (i = 0, k = 0; i < 2 * POLY_SIZE; i++) { - for (j=0; j < 2 * POLY_SIZE; j++, k++) { - - x = (double) i * 0.5; - y = (double) j * 2.0; - - dxy_pos[ k] = (double)i+xy_offset; - dxy_pos[2 * POLY_SIZE * 2 * POLY_SIZE + k] = (double)j-xy_offset; - dvec[ k] = sqrt(x) * log1p(y); + for (j = 0; j < 2 * POLY_SIZE; j++, k++) { + x = (double)i * 0.5; + y = (double)j * 2.0; + + dxy_pos[k] = (double)i + xy_offset; + dxy_pos[2 * POLY_SIZE * 2 * POLY_SIZE + k] = (double)j - xy_offset; + dvec[k] = sqrt(x) * log1p(y); } } - cpl_test_eq( 2 * POLY_SIZE * 2 * POLY_SIZE, k ); + cpl_test_eq(2 * POLY_SIZE * 2 * POLY_SIZE, k); ymax = 0; for (degree = 0; degree < POLY_SIZE; degree++) { - const cpl_size maxdeg[2] = {degree, degree}; + const cpl_size maxdeg[2] = { degree, degree }; const cpl_size nc = 2 * POLY_SIZE * 2 * POLY_SIZE; double mse; - code = cpl_polynomial_fit_cmp(poly2, xy_pos, NULL, vec, NULL, - dimdeg, zerodeg2, maxdeg); + code = cpl_polynomial_fit_cmp(poly2, xy_pos, NULL, vec, NULL, dimdeg, + zerodeg2, maxdeg); cpl_test_eq_error(code, CPL_ERROR_NONE); - cpl_test_eq( cpl_polynomial_get_dimension(poly2), 2 ); + cpl_test_eq(cpl_polynomial_get_dimension(poly2), 2); if (dimdeg) cpl_test_eq(cpl_polynomial_get_degree(poly2), degree * 2); else @@ -1608,23 +1636,27 @@ eps = cpl_polynomial_eval(poly2, xpoint); - cpl_msg_info(cpl_func, "2D-Polynomial with degree %" CPL_SIZE_FORMAT + cpl_msg_info(cpl_func, + "2D-Polynomial with degree %" CPL_SIZE_FORMAT " fit of a %" CPL_SIZE_FORMAT "-point dataset " "has a mean square error: %g (P0-code=%g)", - degree, nc, mse, 0.25-eps); + degree, nc, mse, 0.25 - eps); /* mse must decrease */ if (degree > 0) { - if (fabs(eps-0.25) > fabs(ymax - 0.25)) - cpl_msg_info(cpl_func, "2D-Polynomial with degree %" - CPL_SIZE_FORMAT " fit of a %" CPL_SIZE_FORMAT - "-point dataset has a larger error than a %" - CPL_SIZE_FORMAT "-degree fit: fabs(%g-0.25) > " - "fabs(%g-0.25)", - degree, nc, degree - 1, eps, ymax); + if (fabs(eps - 0.25) > fabs(ymax - 0.25)) + cpl_msg_info( + cpl_func, + "2D-Polynomial with degree %" CPL_SIZE_FORMAT + " fit of a %" CPL_SIZE_FORMAT + "-point dataset has a larger error than a %" CPL_SIZE_FORMAT + "-degree fit: fabs(%g-0.25) > " + "fabs(%g-0.25)", + degree, nc, degree - 1, eps, ymax); if (mse > xmax) { - cpl_msg_info(cpl_func, "2D-Polynomial with degree %" - CPL_SIZE_FORMAT " fit of a %" CPL_SIZE_FORMAT + cpl_msg_info(cpl_func, + "2D-Polynomial with degree %" CPL_SIZE_FORMAT + " fit of a %" CPL_SIZE_FORMAT "-point dataset has a larger mean square error " "than a %" CPL_SIZE_FORMAT "-degree fit: %g > %g", degree, nc, degree - 1, mse, xmax); @@ -1648,11 +1680,9 @@ cpl_polynomial_test_delete(poly2a); return poly1; - } - /*----------------------------------------------------------------------------*/ /** @internal @@ -1664,25 +1694,23 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_polynomial_fit_bench_2d(cpl_size nr, cpl_size nc, cpl_size nd) +static void +cpl_polynomial_fit_bench_2d(cpl_size nr, cpl_size nc, cpl_size nd) { + cpl_polynomial *poly2 = cpl_polynomial_new(2); + cpl_vector *vec = cpl_vector_new(nc * nc); + cpl_matrix *xy_pos = cpl_matrix_new(2, nc * nc); + cpl_flops flops = 0; + double secs = 0.0; + double xmax = DBL_MAX; /* This valuie should not be read */ + cpl_size i, j, k, degree = 0; + cpl_error_code code = CPL_ERROR_NONE; - cpl_polynomial * poly2 = cpl_polynomial_new(2); - cpl_vector * vec = cpl_vector_new(nc * nc); - cpl_matrix * xy_pos = cpl_matrix_new(2, nc * nc); - cpl_flops flops = 0; - double secs = 0.0; - double xmax = DBL_MAX; /* This valuie should not be read */ - cpl_size i, j, k, degree = 0; - cpl_error_code code = CPL_ERROR_NONE; - - - - for (i=0, k = 0; i < nc; i++) { - for (j=0; j < nc; j++, k++) { - const double x = (double) i * 0.5; - const double y = (double) j * 2.0; + for (i = 0, k = 0; i < nc; i++) { + for (j = 0; j < nc; j++, k++) { + const double x = (double)i * 0.5; + const double y = (double)j * 2.0; code = cpl_matrix_set(xy_pos, 0, k, (double)i); cpl_test_eq_error(code, CPL_ERROR_NONE); @@ -1690,47 +1718,49 @@ code = cpl_matrix_set(xy_pos, 1, k, (double)j); cpl_test_eq_error(code, CPL_ERROR_NONE); - code = cpl_vector_set(vec, k, sqrt(x)*log1p(y)); + code = cpl_vector_set(vec, k, sqrt(x) * log1p(y)); cpl_test_eq_error(code, CPL_ERROR_NONE); } } - cpl_test_eq( k, nc * nc ); + cpl_test_eq(k, nc * nc); for (i = 0; i < nr; i++) { for (degree = 0; degree < nd; degree++) { double mse; const cpl_flops flops0 = cpl_tools_get_flops(); - const double secs0 = cpl_test_get_cputime(); + const double secs0 = cpl_test_get_cputime(); code = cpl_polynomial_fit_cmp(poly2, xy_pos, NULL, vec, NULL, - CPL_FALSE, NULL, °ree); + CPL_FALSE, NULL, °ree); secs += cpl_test_get_cputime() - secs0; flops += cpl_tools_get_flops() - flops0; cpl_test_eq_error(code, CPL_ERROR_NONE); - if (code) break; + if (code) + break; mse = cpl_vector_get_mse(vec, poly2, xy_pos, NULL); - if (degree > 0 && mse > xmax) break; + if (degree > 0 && mse > xmax) + break; xmax = mse; - } - if (code) break; + if (code) + break; } cpl_vector_delete(vec); cpl_matrix_delete(xy_pos); cpl_polynomial_test_delete(poly2); - cpl_msg_info("","Speed while fitting %" CPL_SIZE_FORMAT " 2D-points with " + cpl_msg_info("", + "Speed while fitting %" CPL_SIZE_FORMAT " 2D-points with " "up to degree %" CPL_SIZE_FORMAT " in %g secs [Mflop/s]: %g", - nc*nc, degree, secs, (double)flops/secs/1e6); - + nc * nc, degree, secs, (double)flops / secs / 1e6); } /*----------------------------------------------------------------------------*/ @@ -1742,81 +1772,81 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_polynomial_fit_test_1d(FILE * stream) +static void +cpl_polynomial_fit_test_1d(FILE *stream) { - - const double dvec6[] = {1, 3, 5, 2, 4, 6}; - const double dtay6[] = {0, 2*4, 2*20, 2*1, 2*10, 2*35}; - const double dvec4[] = {1, 3, 4, 6}; - const double dtay4[] = {0, 2*4, 2*10, 2*35}; - const double dsq6[] = {1, 9, 25, 4, 16, 36}; + const double dvec6[] = { 1, 3, 5, 2, 4, 6 }; + const double dtay6[] = { 0, 2 * 4, 2 * 20, 2 * 1, 2 * 10, 2 * 35 }; + const double dvec4[] = { 1, 3, 4, 6 }; + const double dtay4[] = { 0, 2 * 4, 2 * 10, 2 * 35 }; + const double dsq6[] = { 1, 9, 25, 4, 16, 36 }; CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual) - cpl_matrix * samppos1 = cpl_matrix_wrap(1, 6, (double*)dvec6); - cpl_vector * taylor = cpl_vector_wrap(6, (double*)dtay6); - cpl_matrix * samppos14 = cpl_matrix_wrap(1, 4, (double*)dvec4); - cpl_vector * taylor4 = cpl_vector_wrap(4, (double*)dtay4); + cpl_matrix *samppos1 = cpl_matrix_wrap(1, 6, (double *)dvec6); + cpl_vector *taylor = cpl_vector_wrap(6, (double *)dtay6); + cpl_matrix *samppos14 = cpl_matrix_wrap(1, 4, (double *)dvec4); + cpl_vector *taylor4 = cpl_vector_wrap(4, (double *)dtay4); CPL_DIAG_PRAGMA_POP - cpl_matrix * samppos; - cpl_vector * fitvals; - cpl_polynomial * poly1a = cpl_polynomial_new(1); - cpl_polynomial * poly1b = cpl_polynomial_new(1); - cpl_polynomial * poly2 = cpl_polynomial_new(2); + cpl_matrix *samppos; + cpl_vector *fitvals; + cpl_polynomial *poly1a = cpl_polynomial_new(1); + cpl_polynomial *poly1b = cpl_polynomial_new(1); + cpl_polynomial *poly2 = cpl_polynomial_new(2); const cpl_boolean symsamp = CPL_TRUE; - const cpl_size zerodeg = 0; - const cpl_size sqdeg = 2; - const cpl_size maxdeg = 3; - cpl_size mindeg, errdeg, deg1; - double eps, rechisq; - double xmax; /* Maximum rounding code on x */ - double ymax; /* Maximum rounding code on y */ - double zmax; - cpl_error_code code; - cpl_size i, j; + const cpl_size zerodeg = 0; + const cpl_size sqdeg = 2; + const cpl_size maxdeg = 3; + cpl_size mindeg, errdeg, deg1; + double eps, rechisq; + double xmax; /* Maximum rounding code on x */ + double ymax; /* Maximum rounding code on y */ + double zmax; + cpl_error_code code; + cpl_size i, j; /* Test 1: NULL input */ - code = cpl_polynomial_fit_cmp(NULL, NULL, NULL, NULL, NULL, CPL_FALSE, - NULL, NULL); + code = cpl_polynomial_fit_cmp(NULL, NULL, NULL, NULL, NULL, CPL_FALSE, NULL, + NULL); cpl_test_eq_error(code, CPL_ERROR_NULL_INPUT); - code = cpl_polynomial_fit_cmp(NULL, samppos1, NULL, taylor, NULL, - CPL_FALSE, NULL, &maxdeg); + code = cpl_polynomial_fit_cmp(NULL, samppos1, NULL, taylor, NULL, CPL_FALSE, + NULL, &maxdeg); cpl_test_eq_error(code, CPL_ERROR_NULL_INPUT); - code = cpl_polynomial_fit_cmp(poly1a, NULL, NULL, taylor, NULL, - CPL_FALSE, NULL, &maxdeg); + code = cpl_polynomial_fit_cmp(poly1a, NULL, NULL, taylor, NULL, CPL_FALSE, + NULL, &maxdeg); cpl_test_eq_error(code, CPL_ERROR_NULL_INPUT); - code = cpl_polynomial_fit_cmp(poly1a, samppos1, NULL, NULL, NULL, - CPL_FALSE, NULL, &maxdeg); + code = cpl_polynomial_fit_cmp(poly1a, samppos1, NULL, NULL, NULL, CPL_FALSE, + NULL, &maxdeg); cpl_test_eq_error(code, CPL_ERROR_NULL_INPUT); code = cpl_polynomial_fit_cmp(poly1a, samppos1, NULL, taylor, NULL, - CPL_FALSE, NULL, NULL); + CPL_FALSE, NULL, NULL); cpl_test_eq_error(code, CPL_ERROR_NULL_INPUT); /* Test 1a: negative maxdeg */ errdeg = -1; code = cpl_polynomial_fit_cmp(poly1a, samppos1, NULL, taylor, NULL, - CPL_FALSE, NULL, &errdeg); + CPL_FALSE, NULL, &errdeg); cpl_test_eq_error(code, CPL_ERROR_ILLEGAL_INPUT); /* Test 1b: maxdeg less than mindeg*/ errdeg = 0; code = cpl_polynomial_fit_cmp(poly1a, samppos1, NULL, taylor, NULL, - CPL_FALSE, &maxdeg, &errdeg); + CPL_FALSE, &maxdeg, &errdeg); cpl_test_eq_error(code, CPL_ERROR_ILLEGAL_INPUT); /* Test 1c: Wrong dimension of poly */ code = cpl_polynomial_fit_cmp(poly2, samppos1, NULL, taylor, NULL, - CPL_FALSE, NULL, &maxdeg); + CPL_FALSE, NULL, &maxdeg); cpl_test_eq_error(code, CPL_ERROR_INCOMPATIBLE_INPUT); /* Test 2: Unordered insertion */ code = cpl_polynomial_fit_cmp(poly1a, samppos1, NULL, taylor, NULL, - CPL_FALSE, &zerodeg, &maxdeg); + CPL_FALSE, &zerodeg, &maxdeg); cpl_test_eq_error(code, CPL_ERROR_NONE); @@ -1829,7 +1859,7 @@ cpl_test_leq(0.0, rechisq); - cpl_test_abs( eps, 0.0, 4359*DBL_EPSILON*DBL_EPSILON); /* alphaev56 */ + cpl_test_abs(eps, 0.0, 4359 * DBL_EPSILON * DBL_EPSILON); /* alphaev56 */ /* Test 3: Symmetric 1D sampling (also test dimdeg and reset of preset 1D-coeffs) */ @@ -1837,21 +1867,21 @@ code = cpl_polynomial_set_coeff(poly1b, &errdeg, 1.0); cpl_test_eq_error(code, CPL_ERROR_NONE); code = cpl_polynomial_fit_cmp(poly1b, samppos1, &symsamp, taylor, NULL, - CPL_TRUE, &zerodeg, &maxdeg); + CPL_TRUE, &zerodeg, &maxdeg); cpl_test_eq_error(code, CPL_ERROR_NONE); cpl_test_polynomial_abs(poly1a, poly1b, DBL_EPSILON); - cpl_test_abs( cpl_vector_get_mse(taylor, poly1b, samppos1, NULL), 0.0, - fabs(eps)); + cpl_test_abs(cpl_vector_get_mse(taylor, poly1b, samppos1, NULL), 0.0, + fabs(eps)); /* Test 3A: Same, except mindeg set to 1 */ mindeg = 1; code = cpl_polynomial_set_coeff(poly1b, &errdeg, 1.0); cpl_test_eq_error(code, CPL_ERROR_NONE); code = cpl_polynomial_fit_cmp(poly1b, samppos1, &symsamp, taylor, NULL, - CPL_TRUE, &mindeg, &maxdeg); + CPL_TRUE, &mindeg, &maxdeg); cpl_test_eq_error(code, CPL_ERROR_NONE); @@ -1865,18 +1895,18 @@ cpl_test_polynomial_abs(poly1a, poly1b, 700.0 * DBL_EPSILON); - cpl_test_abs( cpl_vector_get_mse(taylor, poly1b, samppos1, NULL), 0.0, - 70.0 * fabs(eps)); + cpl_test_abs(cpl_vector_get_mse(taylor, poly1b, samppos1, NULL), 0.0, + 70.0 * fabs(eps)); /* Test 3B: Symmetric, non-equidistant 1D sampling (also test dimdeg and reset of preset 1D-coeffs) */ code = cpl_polynomial_fit_cmp(poly1a, samppos14, NULL, taylor4, NULL, - CPL_TRUE, &zerodeg, &maxdeg); + CPL_TRUE, &zerodeg, &maxdeg); cpl_test_eq_error(code, CPL_ERROR_NONE); code = cpl_polynomial_fit_cmp(poly1b, samppos14, &symsamp, taylor4, NULL, - CPL_TRUE, &zerodeg, &maxdeg); + CPL_TRUE, &zerodeg, &maxdeg); cpl_test_eq_error(code, CPL_ERROR_NONE); @@ -1884,7 +1914,7 @@ /* Test 3C: Same except mindeg set to 1 */ code = cpl_polynomial_fit_cmp(poly1b, samppos14, &symsamp, taylor4, NULL, - CPL_TRUE, &mindeg, &maxdeg); + CPL_TRUE, &mindeg, &maxdeg); cpl_test_eq_error(code, CPL_ERROR_NONE); @@ -1901,43 +1931,43 @@ cpl_test_error(CPL_ERROR_NONE); - cpl_test_abs( cpl_vector_get_mse(taylor4, poly1b, samppos14, NULL), 0.0, - 283.0 * fabs(eps)); + cpl_test_abs(cpl_vector_get_mse(taylor4, poly1b, samppos14, NULL), 0.0, + 283.0 * fabs(eps)); /* Test 4: Only one distinct sampling point */ samppos = cpl_matrix_new(1, 6); cpl_test_zero(cpl_matrix_fill(samppos, 1.0)); - /* - should not be able to fit with only one distinct x-value */ + /* - should not be able to fit with only one distinct x-value */ code = cpl_polynomial_fit_cmp(poly1a, samppos, &symsamp, taylor, NULL, - CPL_TRUE, &zerodeg, &maxdeg); + CPL_TRUE, &zerodeg, &maxdeg); cpl_test_eq_error(code, CPL_ERROR_SINGULAR_MATRIX); /* Test 4B: - unless the degree is 0 */ code = cpl_polynomial_fit_cmp(poly1a, samppos, &symsamp, taylor, NULL, - CPL_TRUE, &zerodeg, &zerodeg); + CPL_TRUE, &zerodeg, &zerodeg); cpl_test_eq_error(code, CPL_ERROR_NONE); deg1 = cpl_polynomial_get_degree(poly1a); cpl_test_error(CPL_ERROR_NONE); cpl_test_zero(deg1); - cpl_test_abs( cpl_polynomial_get_coeff(poly1a, &zerodeg), - cpl_vector_get_mean(taylor), DBL_EPSILON); + cpl_test_abs(cpl_polynomial_get_coeff(poly1a, &zerodeg), + cpl_vector_get_mean(taylor), DBL_EPSILON); /* Test 4B: - or unless mindeg equals the degree */ for (i = 1; i < POLY_SIZE; i++) { code = cpl_polynomial_fit_cmp(poly1a, samppos, &symsamp, taylor, NULL, - CPL_TRUE, &i, &i); + CPL_TRUE, &i, &i); cpl_test_eq_error(code, CPL_ERROR_NONE); cpl_test_eq(cpl_polynomial_get_degree(poly1a), i); /* FIXME: Weak test, sampling positions are all at 1.0 */ /* Another test should be added */ - cpl_test_abs( cpl_polynomial_get_coeff(poly1a, &i), - cpl_vector_get_mean(taylor), 16.0 * DBL_EPSILON); + cpl_test_abs(cpl_polynomial_get_coeff(poly1a, &i), + cpl_vector_get_mean(taylor), 16.0 * DBL_EPSILON); code = cpl_polynomial_set_coeff(poly1a, &i, 0.0); cpl_test_eq_error(code, CPL_ERROR_NONE); @@ -1957,21 +1987,21 @@ xmax = 0.0; ymax = -DBL_EPSILON; zmax = 0.0; - for (j=1; j <= POLY_SIZE; j++) { + for (j = 1; j <= POLY_SIZE; j++) { const cpl_size degree = j - 1; - cpl_test_zero( cpl_matrix_set_size(samppos, 1, j) ); - cpl_test_zero( cpl_vector_set_size(fitvals, j) ); - for (i=0; i < j; i++) { - cpl_test_zero( cpl_matrix_set(samppos, 0, i, (double)i) ); - cpl_test_zero( cpl_vector_set(fitvals, i, sqrt((double)i)) ); + cpl_test_zero(cpl_matrix_set_size(samppos, 1, j)); + cpl_test_zero(cpl_vector_set_size(fitvals, j)); + for (i = 0; i < j; i++) { + cpl_test_zero(cpl_matrix_set(samppos, 0, i, (double)i)); + cpl_test_zero(cpl_vector_set(fitvals, i, sqrt((double)i))); } code = cpl_polynomial_fit_cmp(poly1a, samppos, &symsamp, fitvals, NULL, - CPL_TRUE, &zerodeg, °ree); + CPL_TRUE, &zerodeg, °ree); if (code == CPL_ERROR_SINGULAR_MATRIX) { - - cpl_msg_info("FIXME","1D-Polynomial fit of a %" CPL_SIZE_FORMAT + cpl_msg_info("FIXME", + "1D-Polynomial fit of a %" CPL_SIZE_FORMAT "-point dataset with degree %" CPL_SIZE_FORMAT " leads to a (near) singular system of equations", j, degree); @@ -1979,10 +2009,10 @@ break; } - cpl_test_eq_error( code, CPL_ERROR_NONE ); + cpl_test_eq_error(code, CPL_ERROR_NONE); - cpl_test_eq( cpl_polynomial_get_dimension(poly1a), 1 ); - cpl_test_eq( cpl_polynomial_get_degree(poly1a), degree ); + cpl_test_eq(cpl_polynomial_get_dimension(poly1a), 1); + cpl_test_eq(cpl_polynomial_get_degree(poly1a), degree); cpl_polynomial_dump(poly1a, stream); @@ -1990,21 +2020,23 @@ /* The increase in mse must be bound (i686 can manage with a bound of 957 instead of 9016) */ - if (xmax > 0) cpl_test_leq( eps/xmax, 9016); + if (xmax > 0) + cpl_test_leq(eps / xmax, 9016); xmax = eps; eps = cpl_polynomial_get_coeff(poly1a, &zerodeg); if (fabs(eps) > fabs(zmax)) { - cpl_msg_info(cpl_func,"1D-Polynomial with degree %" CPL_SIZE_FORMAT + cpl_msg_info(cpl_func, + "1D-Polynomial with degree %" CPL_SIZE_FORMAT " fit of a %" CPL_SIZE_FORMAT "-point dataset has a " "greater code on P0 than a %" CPL_SIZE_FORMAT "-degree fit to a %" CPL_SIZE_FORMAT "-point dataset: " "fabs(%g) > fabs(%g)", - degree, j, degree-1, j-1, eps, zmax); + degree, j, degree - 1, j - 1, eps, zmax); } /* Should loose at most one decimal digit per degree fabs(eps) < DBL_EPSILON * 10 ** (degree-2) */ - cpl_test_abs( eps, 0.0, DBL_EPSILON * pow(10, (double)(j-3)) ); + cpl_test_abs(eps, 0.0, DBL_EPSILON * pow(10, (double)(j - 3))); zmax = eps; /* Compute approximation to sqrt(0.25) @@ -2013,45 +2045,45 @@ - until the approximation goes bad */ eps = cpl_polynomial_eval_1d(poly1a, 0.25, NULL); - if (j < 18) cpl_test_abs( eps, 0.5, fabs(0.5 - ymax)); + if (j < 18) + cpl_test_abs(eps, 0.5, fabs(0.5 - ymax)); if (eps <= ymax) { /* Should be able to fit at least an 18-degree polynomial with increased accuracy - and without code-margin */ - cpl_msg_info(cpl_func, "1D-Polynomial with degree %" - CPL_SIZE_FORMAT " fit of a %" CPL_SIZE_FORMAT "-point " - "dataset has a greater residual than a %" - CPL_SIZE_FORMAT "-degree fit to a %" CPL_SIZE_FORMAT - "-point dataset: %g > %g", - degree, j, degree-1, j-1, 0.5-eps, 0.5-ymax); + cpl_msg_info( + cpl_func, + "1D-Polynomial with degree %" CPL_SIZE_FORMAT + " fit of a %" CPL_SIZE_FORMAT "-point " + "dataset has a greater residual than a %" CPL_SIZE_FORMAT + "-degree fit to a %" CPL_SIZE_FORMAT "-point dataset: %g > %g", + degree, j, degree - 1, j - 1, 0.5 - eps, 0.5 - ymax); break; } ymax = eps; - } /* And the mse itself must be bound */ - cpl_test_leq( eps, 0.411456 * cpl_error_margin); + cpl_test_leq(eps, 0.411456 * cpl_error_margin); - /* Test 6: Try to fit increasing degrees to a sqrt() */ + /* Test 6: Try to fit increasing degrees to a sqrt() */ - cpl_test_zero( cpl_matrix_set_size(samppos, 1, VECTOR_SIZE) ); - cpl_test_zero( cpl_vector_set_size(fitvals, VECTOR_SIZE) ); - for (i=0; i < VECTOR_SIZE; i++) { - cpl_test_zero( cpl_matrix_set(samppos, 0, i, (double)i + 1e4) ); - cpl_test_zero( cpl_vector_set(fitvals, i, sqrt((double)i)) ); + cpl_test_zero(cpl_matrix_set_size(samppos, 1, VECTOR_SIZE)); + cpl_test_zero(cpl_vector_set_size(fitvals, VECTOR_SIZE)); + for (i = 0; i < VECTOR_SIZE; i++) { + cpl_test_zero(cpl_matrix_set(samppos, 0, i, (double)i + 1e4)); + cpl_test_zero(cpl_vector_set(fitvals, i, sqrt((double)i))); } eps = FLT_MAX; - for (i = 0; i < VECTOR_SIZE-1; i++) { - + for (i = 0; i < VECTOR_SIZE - 1; i++) { xmax = eps; code = cpl_polynomial_fit_cmp(poly1a, samppos, &symsamp, fitvals, NULL, - CPL_TRUE, &zerodeg, &i); + CPL_TRUE, &zerodeg, &i); cpl_test_eq_error(code, CPL_ERROR_NONE); - cpl_test_eq( cpl_polynomial_get_dimension(poly1a), 1 ); - cpl_test_eq( cpl_polynomial_get_degree(poly1a), i ); + cpl_test_eq(cpl_polynomial_get_dimension(poly1a), 1); + cpl_test_eq(cpl_polynomial_get_degree(poly1a), i); eps = cpl_vector_get_mse(fitvals, poly1a, samppos, NULL); @@ -2059,50 +2091,51 @@ /* Should be able to fit at least a 8-degree polynomial with no degradation - and without code-margin (i686 can manage one degree more) */ - if (i < 9) cpl_test_leq( eps, xmax); - cpl_msg_info(cpl_func, "1D-Polynomial with degree %" - CPL_SIZE_FORMAT " fit of a %d-point " - "dataset has a higher mean square error than a %" - CPL_SIZE_FORMAT "-degree fit: %g > %g", - i, VECTOR_SIZE, i-1, eps, xmax); + if (i < 9) + cpl_test_leq(eps, xmax); + cpl_msg_info(cpl_func, + "1D-Polynomial with degree %" CPL_SIZE_FORMAT + " fit of a %d-point " + "dataset has a higher mean square error than a " + "%" CPL_SIZE_FORMAT "-degree fit: %g > %g", + i, VECTOR_SIZE, i - 1, eps, xmax); break; } - } /* Test 7A: Fit a 2nd degree polynomial to a parabola, using mindeg */ cpl_vector_delete(fitvals); CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); - fitvals = cpl_vector_wrap(6, (double*)dsq6); /* Not modified */ + fitvals = cpl_vector_wrap(6, (double *)dsq6); /* Not modified */ CPL_DIAG_PRAGMA_POP; mindeg = 1; code = cpl_polynomial_fit_cmp(poly1a, samppos1, NULL, fitvals, NULL, - CPL_TRUE, &mindeg, &sqdeg); + CPL_TRUE, &mindeg, &sqdeg); cpl_test_eq_error(code, CPL_ERROR_NONE); - cpl_test_eq( cpl_polynomial_get_dimension(poly1a), 1 ); - cpl_test_eq( cpl_polynomial_get_degree(poly1a), sqdeg ); + cpl_test_eq(cpl_polynomial_get_dimension(poly1a), 1); + cpl_test_eq(cpl_polynomial_get_degree(poly1a), sqdeg); - cpl_test_abs( cpl_polynomial_get_coeff(poly1a, &zerodeg), 0.0, DBL_EPSILON); - cpl_test_abs( cpl_polynomial_get_coeff(poly1a, &mindeg), 0.0, - 6.0 * DBL_EPSILON); - cpl_test_abs( cpl_polynomial_get_coeff(poly1a, &sqdeg), 1.0, DBL_EPSILON); + cpl_test_abs(cpl_polynomial_get_coeff(poly1a, &zerodeg), 0.0, DBL_EPSILON); + cpl_test_abs(cpl_polynomial_get_coeff(poly1a, &mindeg), 0.0, + 6.0 * DBL_EPSILON); + cpl_test_abs(cpl_polynomial_get_coeff(poly1a, &sqdeg), 1.0, DBL_EPSILON); /* Test 7A: Fit a 2nd degree polynomial to a parabola, using mindeg */ code = cpl_polynomial_fit_cmp(poly1a, samppos1, NULL, fitvals, NULL, - CPL_TRUE, &sqdeg, &sqdeg); + CPL_TRUE, &sqdeg, &sqdeg); cpl_test_eq_error(code, CPL_ERROR_NONE); - cpl_test_eq( cpl_polynomial_get_dimension(poly1a), 1 ); - cpl_test_eq( cpl_polynomial_get_degree(poly1a), sqdeg ); + cpl_test_eq(cpl_polynomial_get_dimension(poly1a), 1); + cpl_test_eq(cpl_polynomial_get_degree(poly1a), sqdeg); - cpl_test_abs( cpl_polynomial_get_coeff(poly1a, &zerodeg), 0.0, DBL_EPSILON); - cpl_test_abs( cpl_polynomial_get_coeff(poly1a, &mindeg), 0.0, DBL_EPSILON); - cpl_test_abs( cpl_polynomial_get_coeff(poly1a, &sqdeg), 1.0, DBL_EPSILON); + cpl_test_abs(cpl_polynomial_get_coeff(poly1a, &zerodeg), 0.0, DBL_EPSILON); + cpl_test_abs(cpl_polynomial_get_coeff(poly1a, &mindeg), 0.0, DBL_EPSILON); + cpl_test_abs(cpl_polynomial_get_coeff(poly1a, &sqdeg), 1.0, DBL_EPSILON); cpl_polynomial_test_delete(poly1a); @@ -2121,6 +2154,1045 @@ /*----------------------------------------------------------------------------*/ /** @internal + @brief Test evaluations from a polynomial that fit + a samples cube following x*x+y*y+z*z with an + offset and a scale. + @param poly The polynomial to be evaluated. + @param cube_size_eval Width of the cube to be evaluated + (for instance, 3 for a (3x3x3) cube). + @param cube_offset The evaluated cube's offset. + @param cube_scale The evaluated cube's scale. + @param tolerance Accepted difference of the evaluated point + to the real value (x*x+y*y+z*z). + @return void + + */ +/*----------------------------------------------------------------------------*/ +static void +cpl_polynomial_fit_3d_check_evals(cpl_polynomial *poly, + cpl_size cube_size_eval, + double cube_offset, + double cube_scale, + double tolerance) +{ + double eval_point_data[3]; + cpl_vector *eval_point = cpl_vector_wrap(3, eval_point_data); + for (cpl_size x = 0; x < cube_size_eval; ++x) { + for (cpl_size y = 0; y < cube_size_eval; ++y) { + for (cpl_size z = 0; z < cube_size_eval; ++z) { + double eval_x = + cube_offset + + ((double)x / (double)cube_size_eval) * cube_scale; + double eval_y = + cube_offset + + ((double)y / (double)cube_size_eval) * cube_scale; + double eval_z = + cube_offset + + ((double)z / (double)cube_size_eval) * cube_scale; + + eval_point_data[0] = eval_x; + eval_point_data[1] = eval_y; + eval_point_data[2] = eval_z; + + /* Get the evaluation at a given point */ + double eval = cpl_polynomial_eval(poly, eval_point); + + /* Test value is within the tolerance range */ + cpl_test_abs(eval, + eval_x * eval_x + eval_y * eval_y + + eval_z * eval_z, + tolerance); + } + } + } + cpl_vector_unwrap(eval_point); +} + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief Test cpl_polynomial_fit() in 3D + @return void + + */ +/*----------------------------------------------------------------------------*/ +static void +cpl_polynomial_fit_test_3d(void) +{ + cpl_error_code error; + + /* Create sample points and the fit values */ + + const double cube_offset = 50.0; + const double cube_scale = 100.0; + const cpl_size cube_size = 10; + const cpl_size np = cube_size * cube_size * cube_size; + const double mytol = cube_scale * 10e-6; + const cpl_size ndim = 3; + double eval_point_data[ndim]; + + cpl_matrix *samppos = cpl_matrix_new(ndim, np); + cpl_vector *values = cpl_vector_new(np); + cpl_polynomial *poly = cpl_polynomial_new(ndim); + cpl_vector *eval_point = cpl_vector_wrap(ndim, eval_point_data); + + /* Create samples cube */ + for (cpl_size x = 0; x < cube_size; ++x) { + for (cpl_size y = 0; y < cube_size; ++y) { + for (cpl_size z = 0; z < cube_size; ++z) { + cpl_size j = x + (y * cube_size) + (z * cube_size * cube_size); + + /* Compute sample position in the cube */ + double sp_x = + cube_offset + ((double)x / (double)cube_size) * cube_scale; + double sp_y = + cube_offset + ((double)y / (double)cube_size) * cube_scale; + double sp_z = + cube_offset + ((double)z / (double)cube_size) * cube_scale; + + cpl_matrix_set(samppos, 0, j, sp_x); + cpl_matrix_set(samppos, 1, j, sp_y); + cpl_matrix_set(samppos, 2, j, sp_z); + + /* Add a bit of noise in the tolerance range */ + double noise = (cpl_drand() * 2.0 - 1.0) * mytol; + + /* Set the value to x*x + y*y + z*z */ + cpl_vector_set(values, j, + (double)(sp_x * sp_x + sp_y * sp_y + + sp_z * sp_z + noise)); + } + } + } + + /* Test input errors */ + + /* Check null inputs */ + error = + cpl_polynomial_fit(NULL, samppos, NULL, values, NULL, CPL_TRUE, + (cpl_size[]){ 0, 0, 0 }, (cpl_size[]){ 2, 2, 2 }); + cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT); + + /* Check bad min and max degrees */ + error = + cpl_polynomial_fit(poly, samppos, NULL, values, NULL, CPL_FALSE, + (cpl_size[]){ -1, 0, 0 }, (cpl_size[]){ 2, 0, 0 }); + cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); + + error = + cpl_polynomial_fit(poly, samppos, NULL, values, NULL, CPL_FALSE, + (cpl_size[]){ 3, 0, 0 }, (cpl_size[]){ 2, 0, 0 }); + cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); + + error = + cpl_polynomial_fit(poly, samppos, NULL, values, NULL, CPL_TRUE, + (cpl_size[]){ 0, -1, 0 }, (cpl_size[]){ 2, 2, 2 }); + cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); + + error = + cpl_polynomial_fit(poly, samppos, NULL, values, NULL, CPL_TRUE, + (cpl_size[]){ 0, 3, 0 }, (cpl_size[]){ 2, 2, 2 }); + cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); + + /* Test not enough samples */ + cpl_size nc = + (2 + 1) * (2 + 1) * (2 + 1); /* Minimum required sample count */ + cpl_matrix *badcount_samppos = + cpl_matrix_new(ndim, nc - 1); /* Missing one sample */ + cpl_vector *badcount_values = + cpl_vector_new(nc - 1); /* Missing one value */ + + error = cpl_polynomial_fit(poly, badcount_samppos, NULL, badcount_values, + NULL, CPL_TRUE, (cpl_size[]){ 0, 0, 0 }, + (cpl_size[]){ 2, 2, 2 }); + cpl_test_eq_error(error, CPL_ERROR_DATA_NOT_FOUND); + + cpl_matrix_delete(badcount_samppos); + cpl_vector_delete(badcount_values); + + /* Test basic 3d fit */ + + const cpl_size cube_size_eval = 10; + + /* Try to fit the cube */ + error = + cpl_polynomial_fit(poly, samppos, NULL, values, NULL, CPL_TRUE, + (cpl_size[]){ 0, 0, 0 }, (cpl_size[]){ 2, 2, 2 }); + cpl_test_eq_error(error, CPL_ERROR_NONE); + + /* Check degree */ + cpl_test_eq(cpl_polynomial_get_degree(poly), 2 + 2 + 2); + + /* Check polynomial evaluations */ + cpl_polynomial_fit_3d_check_evals(poly, cube_size_eval, cube_offset, + cube_scale, mytol); + + /* Test fit 3d with dimdeg = CPL_FALSE */ + error = cpl_polynomial_fit(poly, samppos, NULL, values, NULL, CPL_FALSE, + (cpl_size[]){ 0 }, (cpl_size[]){ 2 }); + cpl_test_eq_error(error, CPL_ERROR_NONE); + + /* Check degree */ + cpl_test_eq(cpl_polynomial_get_degree(poly), 2); + + /* Check polynomial evaluations */ + cpl_polynomial_fit_3d_check_evals(poly, cube_size_eval, cube_offset, + cube_size, mytol); + + /* Test coefficients anomalies */ + + /* Check singular matrix */ + /* The point 5 doesn't bring any information */ + double singular_samppos_data[] = { 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, + 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0 }; + double singular_values_data[] = { 0.0, 1.0, 2.0, 1.0, 0.0, 1.0, 2.0, 1.0 }; + + nc = (1 + 1) * (1 + 1) * (1 + 1); /* Minimum required sample count */ + cpl_matrix *bad_samppos = cpl_matrix_wrap(ndim, nc, singular_samppos_data); + cpl_vector *bad_values = cpl_vector_wrap(nc, singular_values_data); + + error = + cpl_polynomial_fit(poly, bad_samppos, NULL, bad_values, NULL, CPL_TRUE, + (cpl_size[]){ 0, 0, 0 }, (cpl_size[]){ 1, 1, 1 }); + cpl_test_eq_error(error, CPL_ERROR_SINGULAR_MATRIX); + + cpl_matrix_unwrap(bad_samppos); + cpl_vector_unwrap(bad_values); + + /* Test precision loss */ + + /* Fit to the cube */ + error = + cpl_polynomial_fit(poly, samppos, NULL, values, NULL, CPL_TRUE, + (cpl_size[]){ 0, 0, 0 }, (cpl_size[]){ 2, 2, 2 }); + cpl_test_eq_error(error, CPL_ERROR_NONE); + + /* Get MSE */ + double mse = cpl_vector_get_mse(values, poly, samppos, NULL); + cpl_test_leq(mse, 10e-6); + + /* Test fit 3d with mindeg */ + + error = + cpl_polynomial_fit(poly, samppos, NULL, values, NULL, CPL_TRUE, + (cpl_size[]){ 1, 1, 1 }, (cpl_size[]){ 2, 2, 2 }); + cpl_test_eq_error(error, CPL_ERROR_NONE); + + /* Check coefficients */ + for (cpl_size z = 0; z < 3; ++z) { + for (cpl_size y = 0; y < 3; ++y) { + for (cpl_size x = 0; x < 3; ++x) { + double coeff = + cpl_polynomial_get_coeff(poly, (cpl_size[]){ x, y, z }); + if (x == 0 || y == 0 || z == 0) { + cpl_test_abs(coeff, 0.0, CPL_LDBL_EPSILON); + } + } + } + } + + /* Test degree = 0 */ + + double degree0_samppos_data[] = { 1.0, 0.0, 0.0, 0.0, 1.0, + 0.0, 0.0, 0.0, 1.0 }; + double degree0_values_data[] = { 0.0, 2.0, 4.0 }; + + cpl_matrix *degree0_samppos = + cpl_matrix_wrap(ndim, 3, degree0_samppos_data); + cpl_vector *degree0_values = cpl_vector_wrap(3, degree0_values_data); + + error = + cpl_polynomial_fit(poly, degree0_samppos, NULL, degree0_values, NULL, + CPL_FALSE, (cpl_size[]){ 0 }, (cpl_size[]){ 0 }); + cpl_test_eq_error(error, CPL_ERROR_NONE); + + /* Check the only coefficient is the mean of the values */ + cpl_test_eq(cpl_polynomial_get_degree(poly), 0); + double degree0_coeff = + cpl_polynomial_get_coeff(poly, (cpl_size[]){ 0, 0, 0 }); + cpl_test_abs(degree0_coeff, 2.0, CPL_LDBL_EPSILON); + /* Evaluate a random point */ + eval_point_data[0] = 23423.0; + eval_point_data[1] = 422.0; + eval_point_data[2] = 2423.0; + double degree0_eval = cpl_polynomial_eval(poly, eval_point); + cpl_test_abs(degree0_eval, 2.0, CPL_LDBL_EPSILON); + + cpl_matrix_unwrap(degree0_samppos); + cpl_vector_unwrap(degree0_values); + + /* Test with only one active axis */ + + double one_axis_samppos_data[] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, + 8.0, 9.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; + double one_axis_values_data[] = { + 0.0, 1.0, 4.0, 9.0, 16.0, 25.0, 36.0, 49.0, 64.0, 81.0 /* value = x*x */ + }; + + cpl_matrix *one_axis_samppos = + cpl_matrix_wrap(ndim, 10, one_axis_samppos_data); + cpl_vector *one_axis_values = cpl_vector_wrap(10, one_axis_values_data); + + /* Try to fit with the dimdeg option deactivated (it should fail to fit) */ + error = + cpl_polynomial_fit(poly, one_axis_samppos, NULL, one_axis_values, NULL, + CPL_FALSE, (cpl_size[]){ 0 }, (cpl_size[]){ 2 }); + cpl_test_eq_error(error, CPL_ERROR_SINGULAR_MATRIX); + + /* Try to fit with only one active axis (maxdeg > 0) */ + error = cpl_polynomial_fit(poly, one_axis_samppos, NULL, one_axis_values, + NULL, CPL_TRUE, (cpl_size[]){ 0, 0, 0 }, + (cpl_size[]){ 2, 0, 0 }); + cpl_test_eq_error(error, CPL_ERROR_NONE); + + for (cpl_size i = 0; i < 10; ++i) { + eval_point_data[0] = (double)i; + eval_point_data[1] = 0.0; + eval_point_data[2] = 0.0; + double eval = cpl_polynomial_eval(poly, eval_point); + cpl_test_abs(eval, (double)(i * i), 10e-14); + } + + cpl_matrix_unwrap(one_axis_samppos); + cpl_vector_unwrap(one_axis_values); + + /* Test precision on a random polynomial */ + + /* Create a polynomial with random coefficients (between 0 and 1) */ + cpl_polynomial *random_poly = cpl_polynomial_new(ndim); + for (cpl_size z = 0; z < 3; ++z) { + for (cpl_size y = 0; y < 3; ++y) { + for (cpl_size x = 0; x < 3; ++x) { + double coeff = cpl_drand() * 1e-7; + cpl_polynomial_set_coeff(random_poly, (cpl_size[]){ x, y, z }, + coeff); + } + } + } + + /* Generate positions and values */ + cpl_matrix *random_samppos = cpl_matrix_duplicate(samppos); + cpl_vector *random_values = cpl_vector_new(np); + + for (cpl_size p = 0; p < cpl_matrix_get_ncol(random_samppos); p++) { + /* Read positions and set the evaluation point */ + double px = cpl_matrix_get(random_samppos, 0, p); + double py = cpl_matrix_get(random_samppos, 1, p); + double pz = cpl_matrix_get(random_samppos, 2, p); + eval_point_data[0] = px; + eval_point_data[1] = py; + eval_point_data[2] = pz; + + /* Evaluate the point and save it */ + double eval = cpl_polynomial_eval(random_poly, eval_point); + + /* Add noise (up to 0.5%) in the position and the value */ + px += (cpl_drand() * 2.0 - 1.0) * (cube_scale * 0.005); + py += (cpl_drand() * 2.0 - 1.0) * (cube_scale * 0.005); + pz += (cpl_drand() * 2.0 - 1.0) * (cube_scale * 0.005); + eval += cpl_drand() * 2.0 - 1.0; + + /* Save the new position and value */ + cpl_matrix_set(random_samppos, 0, p, px); + cpl_matrix_set(random_samppos, 1, p, py); + cpl_matrix_set(random_samppos, 2, p, pz); + cpl_vector_set(random_values, p, eval); + } + + /* Try to fit with the noise */ + error = cpl_polynomial_fit(random_poly, random_samppos, NULL, random_values, + NULL, CPL_TRUE, (cpl_size[]){ 0, 0, 0 }, + (cpl_size[]){ 2, 2, 2 }); + cpl_test_eq_error(error, CPL_ERROR_NONE); + + /* Measure the differences between values after the fit */ + for (cpl_size i = 0; i < cpl_vector_get_size(random_values); i++) { + eval_point_data[0] = cpl_matrix_get(random_samppos, 0, i); + eval_point_data[1] = cpl_matrix_get(random_samppos, 1, i); + eval_point_data[2] = cpl_matrix_get(random_samppos, 2, i); + double eval = cpl_polynomial_eval(random_poly, eval_point); + double diff = fabs(eval - cpl_vector_get(random_values, i)); + cpl_vector_set(random_values, i, diff); + } + + /* Get the median of differences */ + double median_error = cpl_vector_get_median(random_values); + cpl_test_leq(median_error, 300.0); + + cpl_polynomial_delete(random_poly); + cpl_matrix_delete(random_samppos); + cpl_vector_delete(random_values); + + /* Free resources */ + cpl_vector_delete(values); + cpl_matrix_delete(samppos); + cpl_polynomial_delete(poly); + cpl_vector_unwrap(eval_point); +} + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief Test 1D cpl_polynomial_fit() using uncertainties parameters + @return void + + */ +/*----------------------------------------------------------------------------*/ +static void +cpl_polynomial_fit_1d_test_sigma(void) +{ + const double mytol = 1e-6; + cpl_polynomial *poly; + cpl_matrix *samppos; + cpl_matrix *samppos_inf; + cpl_vector *values; + cpl_vector *values_inf; + cpl_vector *fitsigm; + cpl_vector *fitsigm_inf; + cpl_size np, np_inf, p; + cpl_error_code error; + double mse; + + /* Test basic 1D case */ + + np = 100; + poly = cpl_polynomial_new(1); + samppos = cpl_matrix_new(1, np); + values = cpl_vector_new(np); + fitsigm = cpl_vector_new(np); + cpl_vector_fill(fitsigm, 1.0); + + /* Fill valid points */ + for (p = 0; p < np; ++p) { + double value = 0.2 * (p - 1) * (p - 1); + cpl_matrix_set(samppos, 0, p, (double)p); + cpl_vector_set(values, p, value); + } + + /* Test the fit with no sigma input */ + error = cpl_polynomial_fit(poly, samppos, NULL, values, NULL, CPL_TRUE, + (cpl_size[]){ 0 }, (cpl_size[]){ 2 }); + cpl_test_eq_error(error, CPL_ERROR_NONE); + + mse = cpl_vector_get_mse(values, poly, samppos, NULL); + cpl_test_leq(mse, mytol); + + /* Test the fit with default sigma values (all at 1.0) */ + error = cpl_polynomial_fit(poly, samppos, NULL, values, fitsigm, CPL_TRUE, + (cpl_size[]){ 0 }, (cpl_size[]){ 2 }); + cpl_test_eq_error(error, CPL_ERROR_NONE); + + double default_mse = cpl_vector_get_mse(values, poly, samppos, NULL); + cpl_test_leq(default_mse, mytol); + + /* Fit with all same sigma != 1.0 but all same */ + cpl_vector_fill(fitsigm, 1000.0); + + error = cpl_polynomial_fit(poly, samppos, NULL, values, fitsigm, CPL_TRUE, + (cpl_size[]){ 0 }, (cpl_size[]){ 2 }); + cpl_test_eq_error(error, CPL_ERROR_NONE); + + double mse_notones = cpl_vector_get_mse(values, poly, samppos, NULL); + cpl_test_abs(mse_notones, default_mse, DBL_EPSILON); + + cpl_vector_fill(fitsigm, 1.0); /* Reset for the next test */ + + /* Test with sigma=infinity */ + np_inf = np + 50; + values_inf = cpl_vector_duplicate(values); + cpl_vector_set_size(values_inf, np_inf); + for (cpl_size i = np; i < np_inf; i++) + cpl_vector_set(values_inf, i, 0.0); + fitsigm_inf = cpl_vector_duplicate(fitsigm); + cpl_vector_set_size(fitsigm_inf, np_inf); + for (cpl_size i = np; i < np_inf; i++) + cpl_vector_set(fitsigm_inf, i, INFINITY); + samppos_inf = cpl_matrix_duplicate(samppos); + cpl_matrix_set_size(samppos_inf, 1, np_inf); + + error = cpl_polynomial_fit(poly, samppos_inf, NULL, values_inf, fitsigm_inf, + CPL_TRUE, (cpl_size[]){ 0 }, (cpl_size[]){ 2 }); + cpl_test_eq_error(error, CPL_ERROR_NONE); + + mse = cpl_vector_get_mse(values, poly, samppos, NULL); + cpl_test_abs(mse, default_mse, DBL_EPSILON); + + /* Add high noise on some points */ + /* Also prepare sigma vector */ + cpl_vector *values_1d_bad = cpl_vector_duplicate(values); + for (p = 0; p < np; p += 5) { + /* Set a random value to the point */ + double random = cpl_drand() * 1000.0; + cpl_vector_set(values_1d_bad, p, random); + /* Set the sigma to 1000.0 to nearly ignore this point */ + cpl_vector_set(fitsigm, p, 1000.0); + } + + /* Test the fit with ignored points */ + error = cpl_polynomial_fit(poly, samppos, NULL, values_1d_bad, fitsigm, + CPL_TRUE, (cpl_size[]){ 0 }, (cpl_size[]){ 2 }); + cpl_test_eq_error(error, CPL_ERROR_NONE); + + mse = cpl_vector_get_mse(values, poly, samppos, NULL); + cpl_test_leq(mse, mytol); + + /* Free resources */ + cpl_vector_delete(values_1d_bad); + cpl_polynomial_delete(poly); + cpl_matrix_delete(samppos); + cpl_matrix_delete(samppos_inf); + cpl_vector_delete(values); + cpl_vector_delete(values_inf); + cpl_vector_delete(fitsigm); + cpl_vector_delete(fitsigm_inf); + + /* Test degree = 0 */ + + double samppos_data[] = { 1, 2, 3, 4 }; + double values_data[] = { 1, 3, 5, 9 }; + + np = 4; + poly = cpl_polynomial_new(1); + samppos = cpl_matrix_wrap(1, np, samppos_data); + values = cpl_vector_wrap(np, values_data); + fitsigm = cpl_vector_new(np); + cpl_vector_fill(fitsigm, 1.0); + + /* Fit with all ones */ + error = cpl_polynomial_fit(poly, samppos, NULL, values, fitsigm, CPL_TRUE, + (cpl_size[]){ 0 }, (cpl_size[]){ 0 }); + cpl_test_eq_error(error, CPL_ERROR_NONE); + + double coeff = cpl_polynomial_get_coeff(poly, (cpl_size[]){ 0 }); + cpl_test_abs(coeff, cpl_vector_get_mean(values), CPL_LDBL_EPSILON); + + /* Fit with fitsigm */ + cpl_vector_set(fitsigm, 2, 1.4142135623730951); /* weight ~= 50% */ + cpl_vector_set(fitsigm, 3, INFINITY); /* weight ~= 0% */ + + error = cpl_polynomial_fit(poly, samppos, NULL, values, fitsigm, CPL_TRUE, + (cpl_size[]){ 0 }, (cpl_size[]){ 0 }); + cpl_test_eq_error(error, CPL_ERROR_NONE); + + coeff = cpl_polynomial_get_coeff(poly, (cpl_size[]){ 0 }); + cpl_test_abs(coeff, 2.3333333, mytol); + + cpl_polynomial_delete(poly); + cpl_matrix_unwrap(samppos); + cpl_vector_unwrap(values); + cpl_vector_delete(fitsigm); + + /* Test degree = mindeg and mindeg > 0 */ + + double samppos_linear[] = { 0, 1, 2, 3 }; + double values_linear[] = { 0, 1, 4, 3 }; + double fitsigm_linear[] = { 1.0, 1.0, INFINITY, 1.0 }; + + np = 4; + poly = cpl_polynomial_new(1); + samppos = cpl_matrix_wrap(1, np, samppos_linear); + values = cpl_vector_wrap(np, values_linear); + fitsigm = cpl_vector_wrap(np, fitsigm_linear); + + /* Fit with degree = mindeg = 1 */ + error = cpl_polynomial_fit(poly, samppos, NULL, values, fitsigm, CPL_TRUE, + (cpl_size[]){ 1 }, (cpl_size[]){ 1 }); + cpl_test_eq_error(error, CPL_ERROR_NONE); + + /* First coefficient should be 0 */ + coeff = cpl_polynomial_get_coeff(poly, (cpl_size[]){ 0 }); + cpl_test_abs(coeff, 0.0, CPL_LDBL_EPSILON); + + /* Second coefficient should be 1, f(x) = 0 + 1*x^1 */ + coeff = cpl_polynomial_get_coeff(poly, (cpl_size[]){ 1 }); + cpl_test_abs(coeff, 1.0, mytol); + + cpl_polynomial_delete(poly); + cpl_matrix_unwrap(samppos); + cpl_vector_unwrap(values); + cpl_vector_unwrap(fitsigm); + + /* Test invalid inputs */ + + poly = cpl_polynomial_new(1); + samppos = cpl_matrix_new(1, np); + values = cpl_vector_new(np); + fitsigm = cpl_vector_new(np - 1); /* wrong sigma count */ + + error = cpl_polynomial_fit(poly, samppos, NULL, values, fitsigm, CPL_TRUE, + (cpl_size[]){ 0 }, (cpl_size[]){ 1 }); + cpl_test_eq_error(error, CPL_ERROR_INCOMPATIBLE_INPUT); + + cpl_vector_delete(fitsigm); + fitsigm = cpl_vector_new(np); + cpl_vector_fill(fitsigm, 0.0); + + error = cpl_polynomial_fit(poly, samppos, NULL, values, fitsigm, CPL_TRUE, + (cpl_size[]){ 0 }, (cpl_size[]){ 1 }); + cpl_test_eq_error(error, CPL_ERROR_DIVISION_BY_ZERO); + + cpl_polynomial_delete(poly); + cpl_matrix_delete(samppos); + cpl_vector_delete(values); + cpl_vector_delete(fitsigm); +} + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief Test 2D cpl_polynomial_fit() using uncertainties parameters + @return void + + */ +/*----------------------------------------------------------------------------*/ +static void +cpl_polynomial_fit_2d_test_sigma(void) +{ + const double mytol = 10e-8; + + cpl_error_code error; + double mse; + + cpl_size np = 10; + cpl_polynomial *poly = cpl_polynomial_new(2); + cpl_matrix *samppos = cpl_matrix_new(2, np * np); + cpl_vector *values = cpl_vector_new(np * np); + cpl_vector *sigmas = cpl_vector_new(np * np); + cpl_vector_fill(sigmas, 1.0); + + /* Filling samples */ + for (cpl_size y = 0; y < np; ++y) { + for (cpl_size x = 0; x < np; ++x) { + cpl_size j = x + y * np; + + /* Fill position */ + cpl_matrix_set(samppos, 0, j, (double)x); + cpl_matrix_set(samppos, 1, j, (double)y); + + /* Fill values */ + double noise = (cpl_drand() * 2.0 - 1.0) * mytol; + cpl_vector_set(values, j, (double)x + (double)y + noise); + } + } + + /* Fit with all sigma ones */ + error = cpl_polynomial_fit(poly, samppos, NULL, values, sigmas, CPL_TRUE, + (cpl_size[]){ 0, 0 }, (cpl_size[]){ 1, 1 }); + cpl_test_eq_error(error, CPL_ERROR_NONE); + + mse = cpl_vector_get_mse(values, poly, samppos, NULL); + cpl_test_abs(mse, 0.0, mytol); + + /* Fit with all same sigma != 1.0 but all same */ + cpl_vector_fill(sigmas, 100.0); + + error = cpl_polynomial_fit(poly, samppos, NULL, values, sigmas, CPL_TRUE, + (cpl_size[]){ 0, 0 }, (cpl_size[]){ 1, 1 }); + cpl_test_eq_error(error, CPL_ERROR_NONE); + + double mse_notones = cpl_vector_get_mse(values, poly, samppos, NULL); + cpl_test_abs(mse_notones, mse, DBL_EPSILON); + + cpl_vector_fill(sigmas, 1.0); /* Reset for the next test */ + + /* Fit with infinity sigma */ + cpl_size np_inf = (np * np) + 50; + cpl_vector *values_inf = cpl_vector_duplicate(values); + cpl_vector_set_size(values_inf, np_inf); + for (cpl_size i = (np * np); i < np_inf; i++) + cpl_vector_set(values_inf, i, 0.0); + cpl_vector *sigmas_inf = cpl_vector_duplicate(sigmas); + cpl_vector_set_size(sigmas_inf, np_inf); + for (cpl_size i = (np * np); i < np_inf; i++) + cpl_vector_set(sigmas_inf, i, INFINITY); + cpl_matrix *samppos_inf = cpl_matrix_duplicate(samppos); + cpl_matrix_set_size(samppos_inf, 2, np_inf); + + error = cpl_polynomial_fit(poly, samppos_inf, NULL, values_inf, sigmas_inf, + CPL_TRUE, (cpl_size[]){ 0, 0 }, + (cpl_size[]){ 1, 1 }); + cpl_test_eq_error(error, CPL_ERROR_NONE); + + double mse_inf = cpl_vector_get_mse(values, poly, samppos, NULL); + cpl_test_abs(mse_inf, mse, DBL_EPSILON); + + cpl_vector_delete(values_inf); + cpl_vector_delete(sigmas_inf); + cpl_matrix_delete(samppos_inf); + + /* Set random points with bad values and high sigma */ + cpl_vector *correct_values = cpl_vector_duplicate(values); + for (cpl_size y = 0; y < np; ++y) { + for (cpl_size x = 0; x < np; ++x) { + if ((x + y) % 2 == 0) { + cpl_size j = x + y * np; + double random = (cpl_drand() * 2.0 - 1.0) * 50.0; + cpl_vector_set(values, j, random); + cpl_vector_set(sigmas, j, 100.0); + } + } + } + + /* Fit with different sigmas */ + error = cpl_polynomial_fit(poly, samppos, NULL, values, sigmas, CPL_TRUE, + (cpl_size[]){ 0, 0 }, (cpl_size[]){ 1, 1 }); + cpl_test_eq_error(error, CPL_ERROR_NONE); + + mse = cpl_vector_get_mse(correct_values, poly, samppos, NULL); + cpl_test_abs(mse, 0.0, mytol); + + cpl_vector_delete(correct_values); + cpl_polynomial_delete(poly); + cpl_matrix_delete(samppos); + cpl_vector_delete(values); + cpl_vector_delete(sigmas); + + /* Test degree = 0 */ + + double samppos_data[] = { 1, 2, 3, 4, 1, 2, 3, 4 }; + double values_data[] = { 1, 3, 5, 9 }; + + np = 4; + poly = cpl_polynomial_new(2); + samppos = cpl_matrix_wrap(2, np, samppos_data); + values = cpl_vector_wrap(np, values_data); + sigmas = cpl_vector_new(np); + cpl_vector_fill(sigmas, 1.0); + + /* Fit with all ones */ + error = cpl_polynomial_fit(poly, samppos, NULL, values, sigmas, CPL_TRUE, + (cpl_size[]){ 0, 0 }, (cpl_size[]){ 0, 0 }); + cpl_test_eq_error(error, CPL_ERROR_NONE); + + double coeff = cpl_polynomial_get_coeff(poly, (cpl_size[]){ 0, 0 }); + cpl_test_abs(coeff, cpl_vector_get_mean(values), CPL_LDBL_EPSILON); + + /* Fit with different sigmas */ + cpl_vector_set(sigmas, 2, 1.4142135623730951); /* weight ~= 50% */ + cpl_vector_set(sigmas, 3, INFINITY); /* weight ~= 0% */ + + error = cpl_polynomial_fit(poly, samppos, NULL, values, sigmas, CPL_TRUE, + (cpl_size[]){ 0, 0 }, (cpl_size[]){ 0, 0 }); + cpl_test_eq_error(error, CPL_ERROR_NONE); + + coeff = cpl_polynomial_get_coeff(poly, (cpl_size[]){ 0, 0 }); + cpl_test_abs(coeff, 2.3333333, mytol); + + cpl_polynomial_delete(poly); + cpl_matrix_unwrap(samppos); + cpl_vector_unwrap(values); + cpl_vector_delete(sigmas); +} + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief Test 3D cpl_polynomial_fit() using uncertainties parameters + @return void + + */ +/*----------------------------------------------------------------------------*/ +static void +cpl_polynomial_fit_3d_test_sigma(void) +{ + const double mytol = 10e-8; + + cpl_error_code error; + double mse; + + cpl_size np = 10; + cpl_polynomial *poly = cpl_polynomial_new(3); + cpl_matrix *samppos = cpl_matrix_new(3, np * np * np); + cpl_vector *values = cpl_vector_new(np * np * np); + cpl_vector *sigmas = cpl_vector_new(np * np * np); + cpl_vector_fill(sigmas, 1.0); + + /* Filling samples */ + for (cpl_size z = 0; z < np; ++z) { + for (cpl_size y = 0; y < np; ++y) { + for (cpl_size x = 0; x < np; ++x) { + cpl_size j = x + (y * np) + (z * np * np); + + /* Fill position */ + cpl_matrix_set(samppos, 0, j, (double)x); + cpl_matrix_set(samppos, 1, j, (double)y); + cpl_matrix_set(samppos, 2, j, (double)z); + + /* Fill values */ + cpl_vector_set(values, j, (double)x + (double)y + (double)z); + } + } + } + + /* Fit with all sigma ones */ + error = + cpl_polynomial_fit(poly, samppos, NULL, values, sigmas, CPL_TRUE, + (cpl_size[]){ 0, 0, 0 }, (cpl_size[]){ 1, 1, 1 }); + cpl_test_eq_error(error, CPL_ERROR_NONE); + + mse = cpl_vector_get_mse(values, poly, samppos, NULL); + cpl_test_abs(mse, 0.0, mytol); + + /* Fit with all same sigma != 1.0 but all same */ + cpl_vector_fill(sigmas, 100.0); + + error = + cpl_polynomial_fit(poly, samppos, NULL, values, sigmas, CPL_TRUE, + (cpl_size[]){ 0, 0, 0 }, (cpl_size[]){ 1, 1, 1 }); + cpl_test_eq_error(error, CPL_ERROR_NONE); + + double mse_notones = cpl_vector_get_mse(values, poly, samppos, NULL); + cpl_test_abs(mse_notones, mse, DBL_EPSILON); + + cpl_vector_fill(sigmas, 1.0); /* Reset for the next test */ + + /* Fit with infinity sigmas */ + cpl_size np_inf = (np * np * np) + 50; + cpl_vector *values_inf = cpl_vector_duplicate(values); + cpl_vector_set_size(values_inf, np_inf); + for (cpl_size i = np * np * np; i < np_inf; i++) + cpl_vector_set(values_inf, i, 0.0); + cpl_vector *sigmas_inf = cpl_vector_duplicate(sigmas); + cpl_vector_set_size(sigmas_inf, np_inf); + for (cpl_size i = np * np * np; i < np_inf; i++) + cpl_vector_set(sigmas_inf, i, INFINITY); + cpl_matrix *samppos_inf = cpl_matrix_duplicate(samppos); + cpl_matrix_set_size(samppos_inf, 3, np_inf); + + error = cpl_polynomial_fit(poly, samppos_inf, NULL, values_inf, sigmas_inf, + CPL_TRUE, (cpl_size[]){ 0, 0, 0 }, + (cpl_size[]){ 1, 1, 1 }); + cpl_test_eq_error(error, CPL_ERROR_NONE); + + double mse_inf = cpl_vector_get_mse(values, poly, samppos, NULL); + cpl_test_abs(mse_inf, mse, DBL_EPSILON); + + cpl_vector_delete(values_inf); + cpl_vector_delete(sigmas_inf); + cpl_matrix_delete(samppos_inf); + + /* Set random points with bad values and high sigma */ + cpl_vector *correct_values = cpl_vector_duplicate(values); + for (cpl_size z = 0; z < np; ++z) { + for (cpl_size y = 0; y < np; ++y) { + for (cpl_size x = 0; x < np; ++x) { + if ((x + y + z) % 2 == 0) { + cpl_size j = x + (y * np) + (z * np * np); + double random = (cpl_drand() * 2.0 - 1.0) * 100.0; + cpl_vector_set(values, j, random); + cpl_vector_set(sigmas, j, 100.0); + } + } + } + } + + /* Fit with different sigams */ + error = + cpl_polynomial_fit(poly, samppos, NULL, values, sigmas, CPL_TRUE, + (cpl_size[]){ 0, 0, 0 }, (cpl_size[]){ 1, 1, 1 }); + + mse = cpl_vector_get_mse(correct_values, poly, samppos, NULL); + cpl_test_abs(mse, 0.0, mytol); + + cpl_vector_delete(correct_values); + cpl_polynomial_delete(poly); + cpl_matrix_delete(samppos); + cpl_vector_delete(values); + cpl_vector_delete(sigmas); + + /* Test degree = 0 */ + + double samppos_data[] = { 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4 }; + double values_data[] = { 1, 3, 5, 9 }; + + np = 4; + poly = cpl_polynomial_new(3); + samppos = cpl_matrix_wrap(3, np, samppos_data); + values = cpl_vector_wrap(np, values_data); + sigmas = cpl_vector_new(np); + cpl_vector_fill(sigmas, 1.0); + + /* Fit will all ones */ + error = + cpl_polynomial_fit(poly, samppos, NULL, values, sigmas, CPL_TRUE, + (cpl_size[]){ 0, 0, 0 }, (cpl_size[]){ 0, 0, 0 }); + cpl_test_eq_error(error, CPL_ERROR_NONE); + + double coeff = cpl_polynomial_get_coeff(poly, (cpl_size[]){ 0, 0, 0 }); + cpl_test_abs(coeff, cpl_vector_get_mean(values), CPL_LDBL_EPSILON); + + /* Fit with different sigmas */ + cpl_vector_set(sigmas, 2, 1.4142135623730951); /* weight ~= 50% */ + cpl_vector_set(sigmas, 3, INFINITY); /* weight ~= 0% */ + + error = + cpl_polynomial_fit(poly, samppos, NULL, values, sigmas, CPL_TRUE, + (cpl_size[]){ 0, 0, 0 }, (cpl_size[]){ 0, 0, 0 }); + cpl_test_eq_error(error, CPL_ERROR_NONE); + + coeff = cpl_polynomial_get_coeff(poly, (cpl_size[]){ 0, 0, 0 }); + cpl_test_abs(coeff, 2.3333333, mytol); + + cpl_polynomial_delete(poly); + cpl_matrix_unwrap(samppos); + cpl_vector_unwrap(values); + cpl_vector_delete(sigmas); +} + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief Test the cpl_polynomial_eval_2d() optimized function. + @return void + + */ +/*----------------------------------------------------------------------------*/ +static void +cpl_polynomial_eval_2d_test(void) +{ + cpl_polynomial *poly, *dev_poly; + cpl_vector *eval_point; + double eval_xy[2]; + double gradient[2]; + double stable_eval, eval, stable_xpd, stable_ypd; + + const double mytol = 1e-7; + + poly = cpl_polynomial_new(2); + eval_point = cpl_vector_wrap(2, eval_xy); + + /* Test empty polynomial */ + eval = cpl_polynomial_eval_2d(poly, 123.0, 123.0, NULL); + cpl_test_abs(eval, 0.0, DBL_EPSILON); + + /* Test degree 0 polynomial */ + cpl_polynomial_set_coeff(poly, (cpl_size[]){ 0, 0 }, 123.0); + eval = cpl_polynomial_eval_2d(poly, 123.0, 123.0, NULL); + cpl_test_abs(eval, 123.0, DBL_EPSILON); + + /* Set random polynomial coefficients */ + /* Make sure one empty tree is present */ + cpl_polynomial_set_coeff(poly, (cpl_size[]){ 0, 1 }, cpl_drand()); + cpl_polynomial_set_coeff(poly, (cpl_size[]){ 1, 0 }, cpl_drand()); + cpl_polynomial_set_coeff(poly, (cpl_size[]){ 1, 1 }, cpl_drand()); + cpl_polynomial_set_coeff(poly, (cpl_size[]){ 2, 0 }, cpl_drand()); + cpl_polynomial_set_coeff(poly, (cpl_size[]){ 0, 3 }, cpl_drand()); + + /* Eval with the generic function */ + eval_xy[0] = cpl_drand(); + eval_xy[1] = cpl_drand(); + + stable_eval = cpl_polynomial_eval(poly, eval_point); + eval = cpl_polynomial_eval_2d(poly, eval_xy[0], eval_xy[1], NULL); + cpl_test_abs(stable_eval, eval, mytol); + + /* Test gradient */ + eval = cpl_polynomial_eval_2d(poly, eval_xy[0], eval_xy[1], gradient); + cpl_test_abs(stable_eval, eval, mytol); + + dev_poly = cpl_polynomial_duplicate(poly); + cpl_polynomial_derivative(dev_poly, 0); + stable_xpd = cpl_polynomial_eval(dev_poly, eval_point); + cpl_polynomial_delete(dev_poly); + + dev_poly = cpl_polynomial_duplicate(poly); + cpl_polynomial_derivative(dev_poly, 1); + stable_ypd = cpl_polynomial_eval(dev_poly, eval_point); + cpl_polynomial_delete(dev_poly); + + cpl_test_abs(stable_xpd, gradient[0], mytol); + cpl_test_abs(stable_ypd, gradient[1], mytol); + + /* Free resources */ + cpl_polynomial_delete(poly); + cpl_vector_unwrap(eval_point); +} + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief Test the cpl_polynomial_eval_3d() optimized function. + @return void; + + */ +/*----------------------------------------------------------------------------*/ +static void +cpl_polynomial_eval_3d_test(void) +{ + cpl_polynomial *poly, *dev_poly; + cpl_vector *eval_point; + double eval_xyz[3]; + double gradient[3]; + double stable_eval, eval, stable_xpd, stable_ypd, stable_zpd; + + const double mytol = 1e-7; + + poly = cpl_polynomial_new(3); + eval_point = cpl_vector_wrap(3, eval_xyz); + + /* Test empty polynomial */ + eval = cpl_polynomial_eval_3d(poly, 123.0, 123.0, 123.0, NULL); + cpl_test_abs(eval, 0.0, DBL_EPSILON); + + /* Test degree 0 polynomial */ + cpl_polynomial_set_coeff(poly, (cpl_size[]){ 0, 0, 0 }, 123.0); + eval = cpl_polynomial_eval_3d(poly, 123.0, 123.0, 123.0, NULL); + cpl_test_abs(eval, 123.0, DBL_EPSILON); + + /* Set random polynomial coefficients */ + /* Make sure one empty tree is present */ + cpl_polynomial_set_coeff(poly, (cpl_size[]){ 0, 1, 0 }, cpl_drand()); + cpl_polynomial_set_coeff(poly, (cpl_size[]){ 1, 0, 2 }, cpl_drand()); + cpl_polynomial_set_coeff(poly, (cpl_size[]){ 1, 1, 3 }, cpl_drand()); + cpl_polynomial_set_coeff(poly, (cpl_size[]){ 2, 0, 1 }, cpl_drand()); + cpl_polynomial_set_coeff(poly, (cpl_size[]){ 0, 3, 0 }, cpl_drand()); + cpl_polynomial_set_coeff(poly, (cpl_size[]){ 4, 0, 4 }, cpl_drand()); + + /* Eval with the generic function */ + eval_xyz[0] = cpl_drand(); + eval_xyz[1] = cpl_drand(); + eval_xyz[2] = cpl_drand(); + + stable_eval = cpl_polynomial_eval(poly, eval_point); + eval = cpl_polynomial_eval_3d(poly, eval_xyz[0], eval_xyz[1], eval_xyz[2], + gradient); + cpl_test_abs(stable_eval, eval, mytol); + + /* Test gradient */ + eval = cpl_polynomial_eval_3d(poly, eval_xyz[0], eval_xyz[1], eval_xyz[2], + gradient); + cpl_test_abs(stable_eval, eval, mytol); + + dev_poly = cpl_polynomial_duplicate(poly); + cpl_polynomial_derivative(dev_poly, 0); + stable_xpd = cpl_polynomial_eval(dev_poly, eval_point); + cpl_polynomial_delete(dev_poly); + + dev_poly = cpl_polynomial_duplicate(poly); + cpl_polynomial_derivative(dev_poly, 1); + stable_ypd = cpl_polynomial_eval(dev_poly, eval_point); + cpl_polynomial_delete(dev_poly); + + dev_poly = cpl_polynomial_duplicate(poly); + cpl_polynomial_derivative(dev_poly, 2); + stable_zpd = cpl_polynomial_eval(dev_poly, eval_point); + cpl_polynomial_delete(dev_poly); + + cpl_test_abs(stable_xpd, gradient[0], mytol); + cpl_test_abs(stable_ypd, gradient[1], mytol); + cpl_test_abs(stable_zpd, gradient[2], mytol); + + /* Free resources */ + cpl_polynomial_delete(poly); + cpl_vector_unwrap(eval_point); +} + +/*----------------------------------------------------------------------------*/ +/** + @internal @brief Get the mean squared code from a vector of residuals @param fitvals The fitted values @param fit The fitted polynomial @@ -2130,26 +3202,26 @@ */ /*----------------------------------------------------------------------------*/ -static double cpl_vector_get_mse(const cpl_vector * fitvals, - const cpl_polynomial * fit, - const cpl_matrix * samppos, - double * prechisq) +static double +cpl_vector_get_mse(const cpl_vector *fitvals, + const cpl_polynomial *fit, + const cpl_matrix *samppos, + double *prechisq) { - const cpl_size np = cpl_vector_get_size(fitvals); - cpl_vector * residual; - double mse; - cpl_flops flops = 0; - double secs = 0.0; + cpl_vector *residual; + double mse; + cpl_flops flops = 0; + double secs = 0.0; cpl_ensure(fitvals != NULL, CPL_ERROR_NULL_INPUT, -1.0); - cpl_ensure(fit != NULL, CPL_ERROR_NULL_INPUT, -2.0); + cpl_ensure(fit != NULL, CPL_ERROR_NULL_INPUT, -2.0); cpl_ensure(samppos != NULL, CPL_ERROR_NULL_INPUT, -3.0); - residual = cpl_vector_new(1+np/2); /* Just to test the resizing... */ + residual = cpl_vector_new(1 + np / 2); /* Just to test the resizing... */ flops = cpl_tools_get_flops(); - secs = cpl_test_get_cputime(); + secs = cpl_test_get_cputime(); cpl_vector_fill_polynomial_fit_residual(residual, fitvals, NULL, fit, samppos, prechisq); @@ -2180,22 +3252,22 @@ */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_polynomial_fit_cmp(cpl_polynomial * self, - const cpl_matrix * samppos, - const cpl_boolean * sampsym, - const cpl_vector * fitvals, - const cpl_vector * fitsigm, - cpl_boolean dimdeg, - const cpl_size * mindeg, - const cpl_size * maxdeg) +cpl_error_code +cpl_polynomial_fit_cmp(cpl_polynomial *self, + const cpl_matrix *samppos, + const cpl_boolean *sampsym, + const cpl_vector *fitvals, + const cpl_vector *fitsigm, + cpl_boolean dimdeg, + const cpl_size *mindeg, + const cpl_size *maxdeg) { - - const cpl_error_code code = cpl_polynomial_fit(self, samppos, sampsym, - fitvals, fitsigm, dimdeg, - mindeg, maxdeg); + const cpl_error_code code = + cpl_polynomial_fit(self, samppos, sampsym, fitvals, fitsigm, dimdeg, + mindeg, maxdeg); if (code == CPL_ERROR_NONE && self != NULL) { - cpl_polynomial_fit_cmp_(self, samppos, sampsym, fitvals, - fitsigm, dimdeg, mindeg, maxdeg); + cpl_polynomial_fit_cmp_(self, samppos, sampsym, fitvals, fitsigm, + dimdeg, mindeg, maxdeg); } return cpl_error_set_(code); /* Tested and reset by caller */ @@ -2218,43 +3290,44 @@ */ /*----------------------------------------------------------------------------*/ -void cpl_polynomial_fit_cmp_(const cpl_polynomial * self, - const cpl_matrix * samppos, - const cpl_boolean * sampsym, - const cpl_vector * fitvals, - const cpl_vector * fitsigm, - cpl_boolean dimdeg, - const cpl_size * mindeg, - const cpl_size * maxdeg) +void +cpl_polynomial_fit_cmp_(const cpl_polynomial *self, + const cpl_matrix *samppos, + const cpl_boolean *sampsym, + const cpl_vector *fitvals, + const cpl_vector *fitsigm, + cpl_boolean dimdeg, + const cpl_size *mindeg, + const cpl_size *maxdeg) { const cpl_error_code code = CPL_ERROR_NONE; const cpl_size mdim = cpl_polynomial_get_dimension(self); const cpl_size ndim = 1 + mdim; - cpl_polynomial * self1p = cpl_polynomial_new(ndim); + cpl_polynomial *self1p = cpl_polynomial_new(ndim); /* This is quaranteed to fail */ - const cpl_error_code error1e = cpl_polynomial_fit(self1p, samppos, - sampsym, fitvals, - fitsigm, dimdeg, - mindeg, maxdeg); + const cpl_error_code error1e = + cpl_polynomial_fit(self1p, samppos, sampsym, fitvals, fitsigm, dimdeg, + mindeg, maxdeg); cpl_test_error(error1e); cpl_test(error1e == code || error1e == CPL_ERROR_INCOMPATIBLE_INPUT); if (samppos != NULL && (mdim == 1 || dimdeg == CPL_TRUE)) { - cpl_polynomial * zeropol = cpl_polynomial_new(mdim); + cpl_polynomial *zeropol = cpl_polynomial_new(mdim); const cpl_size np = cpl_matrix_get_ncol(samppos); const cpl_size nc = cpl_matrix_get_nrow(samppos); - cpl_matrix * samppos1p = cpl_matrix_new(1 + nc, np); + cpl_matrix *samppos1p = cpl_matrix_new(1 + nc, np); - cpl_boolean * sampsym1p = sampsym - ? (cpl_boolean *)cpl_malloc((size_t)ndim * sizeof(*sampsym1p)) - : NULL; - cpl_size * mindeg1p = mindeg - ? (cpl_size*)cpl_malloc((size_t)ndim * sizeof(*mindeg1p)) - : NULL; - cpl_size * maxdeg1p = maxdeg - ? (cpl_size*)cpl_malloc((size_t)ndim * sizeof(*maxdeg1p)) - : NULL; + cpl_boolean *sampsym1p = + sampsym + ? (cpl_boolean *)cpl_malloc((size_t)ndim * sizeof(*sampsym1p)) + : NULL; + cpl_size *mindeg1p = + mindeg ? (cpl_size *)cpl_malloc((size_t)ndim * sizeof(*mindeg1p)) + : NULL; + cpl_size *maxdeg1p = + maxdeg ? (cpl_size *)cpl_malloc((size_t)ndim * sizeof(*maxdeg1p)) + : NULL; for (cpl_size idim = 0; idim < ndim; idim++) { cpl_error_code error1p; @@ -2268,110 +3341,129 @@ cpl_matrix_get(samppos, j, i)); } } - if (sampsym1p != NULL) sampsym1p[j] = sampsym[j]; - if (mindeg1p != NULL) mindeg1p [j] = mindeg [j]; - if (maxdeg1p != NULL) maxdeg1p [j] = maxdeg [j]; + if (sampsym1p != NULL) + sampsym1p[j] = sampsym[j]; + if (mindeg1p != NULL) + mindeg1p[j] = mindeg[j]; + if (maxdeg1p != NULL) + maxdeg1p[j] = maxdeg[j]; } if (j <= nc) { for (i = 0; i < np; i++) { cpl_matrix_set(samppos1p, j, i, 0.0); } } - if (sampsym1p != NULL) sampsym1p[j] = CPL_TRUE; - if (mindeg1p != NULL) mindeg1p [j] = 0; - if (maxdeg1p != NULL) maxdeg1p [j] = 0; + if (sampsym1p != NULL) + sampsym1p[j] = CPL_TRUE; + if (mindeg1p != NULL) + mindeg1p[j] = 0; + if (maxdeg1p != NULL) + maxdeg1p[j] = 0; for (j++; j < ndim; j++) { if (j <= nc) { for (i = 0; i < np; i++) { cpl_matrix_set(samppos1p, j, i, - cpl_matrix_get(samppos, j-1, i)); + cpl_matrix_get(samppos, j - 1, i)); } } - if (sampsym1p != NULL) sampsym1p[j] = sampsym[j-1]; - if (mindeg1p != NULL) mindeg1p [j] = mindeg [j-1]; - if (maxdeg1p != NULL) maxdeg1p [j] = maxdeg [j-1]; + if (sampsym1p != NULL) + sampsym1p[j] = sampsym[j - 1]; + if (mindeg1p != NULL) + mindeg1p[j] = mindeg[j - 1]; + if (maxdeg1p != NULL) + maxdeg1p[j] = maxdeg[j - 1]; } - error1p = cpl_polynomial_fit(self1p, samppos1p, - sampsym1p, fitvals, - fitsigm, CPL_TRUE, - mindeg1p, maxdeg1p); - if (ndim != 2) { + error1p = cpl_polynomial_fit(self1p, samppos1p, sampsym1p, fitvals, + fitsigm, CPL_TRUE, mindeg1p, maxdeg1p); + if (ndim > 3) { cpl_test_eq_error(error1p, CPL_ERROR_UNSUPPORTED_MODE); - } else { + } + else if (ndim < 3) { const cpl_size degree = cpl_polynomial_get_degree(self); if (!code && error1p == CPL_ERROR_SINGULAR_MATRIX && 1 + degree == np && np >= 20) { - cpl_test_eq_error(error1p, CPL_ERROR_SINGULAR_MATRIX); /* In the non-overdetermined case, the multi-variate fit is not as accurate as the uni-variate, for degree 20 the difference is a failure */ - cpl_msg_debug(cpl_func, "2D-fail(%d:%" CPL_SIZE_FORMAT + cpl_msg_debug(cpl_func, + "2D-fail(%d:%" CPL_SIZE_FORMAT ":%" CPL_SIZE_FORMAT ":%" CPL_SIZE_FORMAT - "): S: %" CPL_SIZE_FORMAT "x %" - CPL_SIZE_FORMAT, code, idim, maxdeg1p[0], - maxdeg1p[1], 1 + nc, np); + "): S: %" CPL_SIZE_FORMAT + "x %" CPL_SIZE_FORMAT, + code, idim, maxdeg1p[0], maxdeg1p[1], 1 + nc, + np); if (cpl_msg_get_level() <= CPL_MSG_DEBUG) cpl_matrix_dump(samppos1p, stdout); - } else if (!error1p && !code) { + } + else if (!error1p && !code) { const cpl_size i0 = 0; const double k0 = cpl_polynomial_get_coeff(self, &i0); - cpl_polynomial * self0p - = cpl_polynomial_extract(self1p, idim, zeropol); - const double mytol = mindeg != NULL && mindeg[0] > 0 - ? 6.0 : 1.0; + cpl_polynomial *self0p = + cpl_polynomial_extract(self1p, idim, zeropol); + const double mytol = + mindeg != NULL && mindeg[0] > 0 ? 6.0 : 1.0; /* FIXME: Need relative polynomial comparison */ - cpl_test_polynomial_abs(self, self0p, CX_MAX(fabs(k0),1) - * pow(10.0, (double)degree) - * mytol * DBL_EPSILON); + cpl_test_polynomial_abs(self, self0p, + CX_MAX(fabs(k0), 1) * + pow(10.0, (double)degree) * + mytol * DBL_EPSILON); cpl_polynomial_test_delete(self0p); -CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); + CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); if (mindeg != NULL) { - double mse = 0.0; - cpl_polynomial * self1d = cpl_polynomial_new(1); - cpl_vector * x_pos = - cpl_vector_wrap(np, - cpl_matrix_get_data((cpl_matrix *)samppos1p)); + double mse = 0.0; + cpl_polynomial *self1d = cpl_polynomial_new(1); + cpl_vector *x_pos = + cpl_vector_wrap(np, cpl_matrix_get_data( + (cpl_matrix *)samppos1p)); cpl_error_code code1d; -CPL_DIAG_PRAGMA_POP; - code1d = cpl_polynomial_fit_1d(self1d, x_pos, fitvals, - mindeg[0], maxdeg[0], - sampsym ? sampsym[0] : CPL_FALSE, - &mse); + CPL_DIAG_PRAGMA_POP; + code1d = cpl_polynomial_fit_1d( + self1d, x_pos, fitvals, NULL, mindeg[0], maxdeg[0], + sampsym ? sampsym[0] : CPL_FALSE, &mse); if (code1d == CPL_ERROR_SINGULAR_MATRIX) { - cpl_test_eq_error(code1d, CPL_ERROR_SINGULAR_MATRIX); - } else if (code1d == CPL_ERROR_DIVISION_BY_ZERO) { - cpl_test_eq_error(code1d, CPL_ERROR_DIVISION_BY_ZERO); - } else { + cpl_test_eq_error(code1d, + CPL_ERROR_SINGULAR_MATRIX); + } + else if (code1d == CPL_ERROR_DIVISION_BY_ZERO) { + cpl_test_eq_error(code1d, + CPL_ERROR_DIVISION_BY_ZERO); + } + else { cpl_test_eq_error(code1d, CPL_ERROR_NONE); - cpl_test_polynomial_abs(self1d, self, (double)degree - * mytol * DBL_EPSILON); - cpl_msg_info(cpl_func, "1D %d-degree fit to %d " + cpl_test_polynomial_abs(self1d, self, + (double)degree * mytol * + DBL_EPSILON); + cpl_msg_info(cpl_func, + "1D %d-degree fit to %d " "points has mean square error: %g", (int)maxdeg[0], (int)np, mse); } (void)cpl_vector_unwrap(x_pos); cpl_polynomial_test_delete(self1d); } - } else if (!error1p && code == CPL_ERROR_SINGULAR_MATRIX) { + } + else if (!error1p && code == CPL_ERROR_SINGULAR_MATRIX) { cpl_test_error(CPL_ERROR_NONE); - cpl_msg_warning(cpl_func, "Adding a dummy-dimension to " - "%" CPL_SIZE_FORMAT "-degree, %" - CPL_SIZE_FORMAT " dimension polynomial " + cpl_msg_warning(cpl_func, + "Adding a dummy-dimension to " + "%" CPL_SIZE_FORMAT + "-degree, %" CPL_SIZE_FORMAT + " dimension polynomial " "removes matrix singularity", degree, mdim); - } else { + } + else { cpl_test_eq_error(error1p, code); } } - } cpl_matrix_delete(samppos1p); @@ -2394,17 +3486,16 @@ */ /*----------------------------------------------------------------------------*/ -static -cpl_error_code cpl_polynomial_multiply_1d(cpl_polynomial * self, double root) +static cpl_error_code +cpl_polynomial_multiply_1d(cpl_polynomial *self, double root) { - - cpl_polynomial * poly1d; + cpl_polynomial *poly1d; cpl_size degree, i = 0; cpl_error_code code; - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(cpl_polynomial_get_dimension(self) == 1, - CPL_ERROR_ILLEGAL_INPUT); + CPL_ERROR_ILLEGAL_INPUT); degree = cpl_polynomial_get_degree(self); cpl_ensure_code(degree > 0 || cpl_polynomial_get_coeff(self, &i) != 0.0, @@ -2431,7 +3522,6 @@ } - /*----------------------------------------------------------------------------*/ /** @internal @@ -2447,13 +3537,15 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_polynomial_solve_1d_test_ok(const cpl_polynomial * self, - double root, double xfirst, - cpl_size nmulti, - double xtol, double restol) +static void +cpl_polynomial_solve_1d_test_ok(const cpl_polynomial *self, + double root, + double xfirst, + cpl_size nmulti, + double xtol, + double restol) { - - cpl_polynomial * copy; + cpl_polynomial *copy; cpl_error_code code; @@ -2475,66 +3567,70 @@ eps = cpl_polynomial_eval_1d(copy, x, NULL); cpl_test_error(CPL_ERROR_NONE); - cpl_test_abs( 0.0, eps, restol); + cpl_test_abs(0.0, eps, restol); /* Solve a second time, using the solution as a first guess. This will test the stopping criterion in the first iteration */ - xfirst = x; + xfirst = x; restol *= restol; } cpl_polynomial_test_delete(copy); } -static void cpl_polynomial_fit_3(FILE * stream) { - /* Speed [km/h] */ - const double v0[] = {55, 66, 77, 88, 99, 110, 121, 132, 143, 154, 165, 176, 182, 187, 193, 204, 209, 220}; - /* Force [Wh/km] */ - const double F0[] = {79, 87, 97, 110, 126, 144, 164, 186, 211, 238, 267, 298, 315, 332, 349, 386, 405, 445}; - const size_t n = sizeof(v0)/sizeof(v0[0]); - double v1[n], P1[n]; - - cpl_polynomial * fit1d = cpl_polynomial_new(1); - cpl_polynomial * deriv = NULL; - cpl_polynomial * vderiv = NULL; - cpl_polynomial * solver = cpl_polynomial_new(1); - cpl_matrix * samppos1d = cpl_matrix_wrap(1, n, v1); - cpl_vector * fitvals = cpl_vector_wrap(n, P1); - const cpl_boolean sampsym = CPL_FALSE; - const cpl_size maxdeg1d = 3; // Fit 4 coefficients - cpl_error_code code; - const double powers[] = {3000, 11000, 22000, 36000, 50000, 80000, 117000, 120000, 180000}; - const size_t npow = sizeof(powers)/sizeof(powers[0]); - - const cpl_size mplot = 200; - cpl_bivector * vvplot = cpl_bivector_new(mplot); - cpl_vector * v0plot = cpl_bivector_get_x(vvplot); - cpl_vector * v1plot = cpl_bivector_get_y(vvplot); - const double vmin = 0/3.6; /* m/s */ - const double vmax = 250/3.6; +static void +cpl_polynomial_fit_3(FILE *stream) +{ + /* Speed [km/h] */ + const double v0[] = { 55, 66, 77, 88, 99, 110, 121, 132, 143, + 154, 165, 176, 182, 187, 193, 204, 209, 220 }; + /* Force [Wh/km] */ + const double F0[] = { 79, 87, 97, 110, 126, 144, 164, 186, 211, + 238, 267, 298, 315, 332, 349, 386, 405, 445 }; + const size_t n = sizeof(v0) / sizeof(v0[0]); + double v1[n], P1[n]; + + cpl_polynomial *fit1d = cpl_polynomial_new(1); + cpl_polynomial *deriv = NULL; + cpl_polynomial *vderiv = NULL; + cpl_polynomial *solver = cpl_polynomial_new(1); + cpl_matrix *samppos1d = cpl_matrix_wrap(1, n, v1); + cpl_vector *fitvals = cpl_vector_wrap(n, P1); + const cpl_boolean sampsym = CPL_FALSE; + const cpl_size maxdeg1d = 3; // Fit 4 coefficients + cpl_error_code code; + const double powers[] = { 3000, 11000, 22000, 36000, 50000, + 80000, 117000, 120000, 180000 }; + const size_t npow = sizeof(powers) / sizeof(powers[0]); + + const cpl_size mplot = 200; + cpl_bivector *vvplot = cpl_bivector_new(mplot); + cpl_vector *v0plot = cpl_bivector_get_x(vvplot); + cpl_vector *v1plot = cpl_bivector_get_y(vvplot); + const double vmin = 0 / 3.6; /* m/s */ + const double vmax = 250 / 3.6; double vi1, pi1, vi2, pi2; const cpl_boolean is_debug = cpl_msg_get_level() == CPL_MSG_DEBUG; - const char * filei = "optispeed.txt"; - FILE* sfilei = fopen(is_debug ? filei : "/dev/null", "w"); + const char *filei = "optispeed.txt"; + FILE *sfilei = fopen(is_debug ? filei : "/dev/null", "w"); - const char * file0 = "power0.txt"; - FILE* sfile0 = fopen(is_debug ? file0 : "/dev/null", "w"); + const char *file0 = "power0.txt"; + FILE *sfile0 = fopen(is_debug ? file0 : "/dev/null", "w"); - const char * file1 = "power1.txt"; - FILE* sfile1 = fopen(is_debug ? file1 : "/dev/null", "w"); + const char *file1 = "power1.txt"; + FILE *sfile1 = fopen(is_debug ? file1 : "/dev/null", "w"); - const char * filep = "power.txt"; - FILE* sfilep = fopen(is_debug ? filep : "/dev/null", "w"); + const char *filep = "power.txt"; + FILE *sfilep = fopen(is_debug ? filep : "/dev/null", "w"); for (size_t i = 0; i < n; i++) { - v1[i] = v0[i] / 3.6; /* Convert km/h to m/s */ + v1[i] = v0[i] / 3.6; /* Convert km/h to m/s */ P1[i] = F0[i] * v0[i]; /* Convert Force to Power [W] */ } - code = - cpl_polynomial_fit(fit1d, samppos1d, &sampsym, fitvals, NULL, - CPL_FALSE, NULL, &maxdeg1d); + code = cpl_polynomial_fit(fit1d, samppos1d, &sampsym, fitvals, NULL, + CPL_FALSE, NULL, &maxdeg1d); cpl_test_eq_error(code, CPL_ERROR_NONE); cpl_msg_info(cpl_func, "Fitting %d-degree to %d values:", (int)maxdeg1d, (int)n); @@ -2556,8 +3652,8 @@ vi2 = 140.0 / 3.6; pi2 = cpl_polynomial_eval_1d(fit1d, vi2, NULL); - cpl_msg_info(cpl_func, "P(120): %g, P(140): %g, ratio: %g", - pi1, pi2, pi2/pi1); + cpl_msg_info(cpl_func, "P(120): %g, P(140): %g, ratio: %g", pi1, pi2, + pi2 / pi1); for (cpl_size i = 0; i < (cpl_size)n; i++) { const double v = v0[i]; @@ -2574,7 +3670,7 @@ fprintf(sfile1, "%g %g\n", v * 3.6, f / 1e3); } fclose(sfile1); - + for (cpl_size i = 0; i < mplot; i++) { const double v = 240.0 / 3.6 * i / (mplot - 1.0); const double p = cpl_polynomial_eval_1d(fit1d, v, NULL); @@ -2582,13 +3678,13 @@ fprintf(sfilep, "%g %g\n", v * 3.6, p / 1e3); } fclose(sfilep); - - for (cpl_size i = 0; i < mplot/4; i++) { - const double poweri = 300 + 240000 * i / (mplot/4 - 1.0); - const cpl_size i0 = 0; + + for (cpl_size i = 0; i < mplot / 4; i++) { + const double poweri = 300 + 240000 * i / (mplot / 4 - 1.0); + const cpl_size i0 = 0; const double c0 = cpl_polynomial_get_coeff(solver, &i0); - cpl_error_code code1 = cpl_polynomial_set_coeff(solver, &i0, - c0 + poweri); + cpl_error_code code1 = + cpl_polynomial_set_coeff(solver, &i0, c0 + poweri); double vc, pc, ve; cpl_test_eq_error(code1, CPL_ERROR_NONE); @@ -2604,18 +3700,17 @@ code1 = cpl_polynomial_set_coeff(solver, &i0, c0); cpl_test_eq_error(code1, CPL_ERROR_NONE); - } fclose(sfilei); for (cpl_size i = 0; i < (cpl_size)npow; i++) { - const cpl_size i0 = 0; + const cpl_size i0 = 0; const double c0 = cpl_polynomial_get_coeff(solver, &i0); - cpl_error_code code1 = cpl_polynomial_set_coeff(solver, &i0, - c0 + powers[i]); + cpl_error_code code1 = + cpl_polynomial_set_coeff(solver, &i0, c0 + powers[i]); double vc, pc, ve; - char * file = cpl_sprintf("pc_%d.txt", (int)powers[i]); - FILE* sfile = fopen(is_debug ? file : "/dev/null", "w"); + char *file = cpl_sprintf("pc_%d.txt", (int)powers[i]); + FILE *sfile = fopen(is_debug ? file : "/dev/null", "w"); cpl_test_eq_error(code1, CPL_ERROR_NONE); @@ -2629,8 +3724,8 @@ cpl_msg_info(cpl_func, "Power %g kW: Vcar=%.1f km/h " "Veff=%.1f km/h Pcar=%.1f kW F=%.0f Wh/km", - powers[i]/1e3, vc * 3.6, ve * 3.6, - pc/1e3, pc/vc/3.6); + powers[i] / 1e3, vc * 3.6, ve * 3.6, pc / 1e3, + pc / vc / 3.6); code1 = cpl_polynomial_set_coeff(solver, &i0, c0); cpl_test_eq_error(code1, CPL_ERROR_NONE); @@ -2655,7 +3750,6 @@ cpl_polynomial_test_delete(deriv); cpl_polynomial_test_delete(vderiv); cpl_polynomial_test_delete(solver); - } /*----------------------------------------------------------------------------*/ @@ -2666,23 +3760,24 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_polynomial_multiply_test(void) +static void +cpl_polynomial_multiply_test(void) { const double x1 = -1.0; - cpl_polynomial * poly10 = cpl_polynomial_new(1); - cpl_polynomial * poly1a = cpl_polynomial_new(1); - cpl_polynomial * poly1b = cpl_polynomial_new(1); - cpl_polynomial * poly1c = cpl_polynomial_new(1); - cpl_polynomial * poly1d = cpl_polynomial_new(1); - cpl_polynomial * poly1p = cpl_polynomial_new(1); /* Previous */ - cpl_polynomial * poly30 = cpl_polynomial_new(POLY_DIM); - cpl_polynomial * poly3a = cpl_polynomial_new(POLY_DIM); - cpl_polynomial * poly3b = cpl_polynomial_new(POLY_DIM); - cpl_polynomial * poly3c = cpl_polynomial_new(POLY_DIM); - cpl_polynomial * poly3d = cpl_polynomial_new(POLY_DIM); + cpl_polynomial *poly10 = cpl_polynomial_new(1); + cpl_polynomial *poly1a = cpl_polynomial_new(1); + cpl_polynomial *poly1b = cpl_polynomial_new(1); + cpl_polynomial *poly1c = cpl_polynomial_new(1); + cpl_polynomial *poly1d = cpl_polynomial_new(1); + cpl_polynomial *poly1p = cpl_polynomial_new(1); /* Previous */ + cpl_polynomial *poly30 = cpl_polynomial_new(POLY_DIM); + cpl_polynomial *poly3a = cpl_polynomial_new(POLY_DIM); + cpl_polynomial *poly3b = cpl_polynomial_new(POLY_DIM); + cpl_polynomial *poly3c = cpl_polynomial_new(POLY_DIM); + cpl_polynomial *poly3d = cpl_polynomial_new(POLY_DIM); - const cpl_size p0[POLY_DIM] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - const cpl_size p1[POLY_DIM] = {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + const cpl_size p0[POLY_DIM] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + const cpl_size p1[POLY_DIM] = { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; cpl_error_code code; @@ -2777,7 +3872,7 @@ for (cpl_size j = 0; j <= degree; j++) { /* Dimension independent */ - const cpl_size pi[POLY_DIM] = {j, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + const cpl_size pi[POLY_DIM] = { j, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; const double c1 = cpl_polynomial_get_coeff(poly1a, pi); const double c3 = cpl_polynomial_get_coeff(poly3a, pi); @@ -2793,7 +3888,8 @@ const double cj = cpl_polynomial_get_coeff(poly1p, &j); cpl_test_abs(c1, cp + cj, 0.0); - } else { + } + else { cpl_test_abs(c1, 1.0, 0.0); } } @@ -2802,7 +3898,6 @@ code = cpl_polynomial_solve_1d(poly1a, -x1, &x, degree); cpl_test_eq_error(code, CPL_ERROR_NONE); cpl_test_abs(x, x1, 0.0); - } cpl_polynomial_test_delete(poly10); @@ -2827,12 +3922,13 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_polynomial_compare_test(void) +static void +cpl_polynomial_compare_test(void) { - cpl_polynomial * poly1a = cpl_polynomial_new(1); - cpl_polynomial * poly1b = cpl_polynomial_new(1); - cpl_polynomial * poly3a = cpl_polynomial_new(POLY_DIM); - cpl_polynomial * poly3b = cpl_polynomial_new(POLY_DIM); + cpl_polynomial *poly1a = cpl_polynomial_new(1); + cpl_polynomial *poly1b = cpl_polynomial_new(1); + cpl_polynomial *poly3a = cpl_polynomial_new(POLY_DIM); + cpl_polynomial *poly3b = cpl_polynomial_new(POLY_DIM); cpl_error_code code; int retval; @@ -2865,7 +3961,9 @@ for (cpl_size dim = 1; dim <= POLY_DIM; dim++) { for (cpl_size degree = 0; degree < 4; degree++) { - const cpl_size p0[POLY_DIM] = {degree, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + const cpl_size p0[POLY_DIM] = { + degree, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + }; cpl_polynomial_empty(poly1a); cpl_polynomial_empty(poly1b); @@ -2936,7 +4034,6 @@ cpl_polynomial_test_delete(poly1b); cpl_polynomial_test_delete(poly3a); cpl_polynomial_test_delete(poly3b); - } /*----------------------------------------------------------------------------*/ @@ -2947,19 +4044,20 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_polynomial_multiply_test_2d(void) +static void +cpl_polynomial_multiply_test_2d(void) { + cpl_polynomial *poly2r = cpl_polynomial_new(2); + cpl_polynomial *poly2a = cpl_polynomial_new(2); + cpl_polynomial *poly2b = cpl_polynomial_new(2); + cpl_polynomial *poly2c = cpl_polynomial_new(2); + cpl_size expo[2], degree; + double value; + int icmp; + cpl_error_code code; - cpl_polynomial * poly2r = cpl_polynomial_new(2); - cpl_polynomial * poly2a = cpl_polynomial_new(2); - cpl_polynomial * poly2b = cpl_polynomial_new(2); - cpl_polynomial * poly2c = cpl_polynomial_new(2); - cpl_size expo[2], degree; - double value; - int icmp; - cpl_error_code code; - - expo[0] = 0; expo[1] = 0; + expo[0] = 0; + expo[1] = 0; code = cpl_polynomial_set_coeff(poly2a, expo, 1.0); cpl_test_eq_error(code, CPL_ERROR_NONE); code = cpl_polynomial_set_coeff(poly2b, expo, -1.0); @@ -2967,7 +4065,8 @@ code = cpl_polynomial_set_coeff(poly2r, expo, -1.0); cpl_test_eq_error(code, CPL_ERROR_NONE); - expo[0] = 1; expo[1] = 0; + expo[0] = 1; + expo[1] = 0; code = cpl_polynomial_set_coeff(poly2a, expo, 1.0); cpl_test_eq_error(code, CPL_ERROR_NONE); code = cpl_polynomial_set_coeff(poly2b, expo, -1.0); @@ -2975,17 +4074,20 @@ code = cpl_polynomial_set_coeff(poly2r, expo, -2.0); cpl_test_eq_error(code, CPL_ERROR_NONE); - expo[0] = 1; expo[1] = 1; + expo[0] = 1; + expo[1] = 1; code = cpl_polynomial_set_coeff(poly2a, expo, 1.0); cpl_test_eq_error(code, CPL_ERROR_NONE); code = cpl_polynomial_set_coeff(poly2b, expo, 1.0); cpl_test_eq_error(code, CPL_ERROR_NONE); - expo[0] = 2; expo[1] = 0; + expo[0] = 2; + expo[1] = 0; code = cpl_polynomial_set_coeff(poly2r, expo, -1.0); cpl_test_eq_error(code, CPL_ERROR_NONE); - expo[0] = 2; expo[1] = 2; + expo[0] = 2; + expo[1] = 2; code = cpl_polynomial_set_coeff(poly2r, expo, 1.0); cpl_test_eq_error(code, CPL_ERROR_NONE); @@ -2995,21 +4097,21 @@ code = cpl_polynomial_multiply(poly2c, poly2a, poly2b); cpl_test_eq_error(code, CPL_ERROR_NONE); - + icmp = cpl_polynomial_compare(poly2c, poly2r, 0.0); cpl_test_error(CPL_ERROR_NONE); cpl_test_zero(icmp); - + code = cpl_polynomial_multiply(poly2c, poly2b, poly2a); cpl_test_eq_error(code, CPL_ERROR_NONE); - + icmp = cpl_polynomial_compare(poly2c, poly2r, 0.0); cpl_test_error(CPL_ERROR_NONE); cpl_test_zero(icmp); - + code = cpl_polynomial_multiply(poly2b, poly2b, poly2a); cpl_test_eq_error(code, CPL_ERROR_NONE); - + icmp = cpl_polynomial_compare(poly2b, poly2r, 0.0); cpl_test_error(CPL_ERROR_NONE); cpl_test_zero(icmp); @@ -3020,11 +4122,12 @@ cpl_test_error(CPL_ERROR_NONE); cpl_test_zero(degree); - expo[0] = 0; expo[1] = 0; + expo[0] = 0; + expo[1] = 0; value = cpl_polynomial_get_coeff(poly2a, expo); cpl_test_error(CPL_ERROR_NONE); cpl_test_abs(value, 0.0, 0.0); - + cpl_polynomial_test_delete(poly2a); cpl_polynomial_test_delete(poly2b); cpl_polynomial_test_delete(poly2c); @@ -3040,20 +4143,20 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_polynomial_shift_test_1d(FILE * stream) +static void +cpl_polynomial_shift_test_1d(FILE *stream) { - - cpl_polynomial * poly1 = cpl_polynomial_new(1); - cpl_polynomial * poly2; + cpl_polynomial *poly1 = cpl_polynomial_new(1); + cpl_polynomial *poly2; /* Some binomial coefficients */ - double p15[BINOMIAL_SZ] = {1,15,105,455,1365,3003,5005,6435}; - cpl_size deg1; - const cpl_size i8 = 8; - const cpl_size i15 = 2 * i8 - 1; - cpl_size i; + double p15[BINOMIAL_SZ] = { 1, 15, 105, 455, 1365, 3003, 5005, 6435 }; + cpl_size deg1; + const cpl_size i8 = 8; + const cpl_size i15 = 2 * i8 - 1; + cpl_size i; /* -1 is a root with multiplicity 8 */ - const double x1 = -1.0; - cpl_error_code code; + const double x1 = -1.0; + cpl_error_code code; /* An 15-degree monomial */ code = cpl_polynomial_set_coeff(poly1, &i15, 1.0); @@ -3064,7 +4167,7 @@ cpl_test_eq(deg1, i15); poly2 = cpl_polynomial_duplicate(poly1); - code = cpl_polynomial_shift_1d(poly2, 0, -x1) ; + code = cpl_polynomial_shift_1d(poly2, 0, -x1); cpl_test_eq_error(code, CPL_ERROR_NONE); /* poly2 now holds the binomial coefficients for n = 15 */ @@ -3089,10 +4192,10 @@ const double z1 = cpl_polynomial_get_coeff(poly1, &i); const double z2 = cpl_polynomial_get_coeff(poly2, &i); - const double z = cpl_polynomial_get_coeff(poly2, &j); + const double z = cpl_polynomial_get_coeff(poly2, &j); - cpl_test_rel( z1, z2, DBL_EPSILON); - cpl_test_rel( z, z2, DBL_EPSILON); + cpl_test_rel(z1, z2, DBL_EPSILON); + cpl_test_rel(z, z2, DBL_EPSILON); } cpl_test_polynomial_abs(poly1, poly2, 0.0); @@ -3110,12 +4213,13 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_polynomial_shift_test_2d_one(FILE * stream) +static void +cpl_polynomial_shift_test_2d_one(FILE *stream) { - cpl_polynomial * poly1 = cpl_polynomial_new(2); - cpl_polynomial * poly2; - cpl_size expo[2]; - cpl_error_code code; + cpl_polynomial *poly1 = cpl_polynomial_new(2); + cpl_polynomial *poly2; + cpl_size expo[2]; + cpl_error_code code; expo[1] = 2; @@ -3155,12 +4259,13 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_polynomial_shift_test_3d_one(FILE * stream) +static void +cpl_polynomial_shift_test_3d_one(FILE *stream) { - cpl_polynomial * poly1 = cpl_polynomial_new(3); - cpl_polynomial * poly2; - cpl_size expo[3]; - cpl_error_code code; + cpl_polynomial *poly1 = cpl_polynomial_new(3); + cpl_polynomial *poly2; + cpl_size expo[3]; + cpl_error_code code; const cpl_error_code ecode = CPL_ERROR_NONE; expo[2] = 2; @@ -3212,26 +4317,26 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_polynomial_shift_test_2d(FILE * stream, cpl_size idim) +static void +cpl_polynomial_shift_test_2d(FILE *stream, cpl_size idim) { - - cpl_polynomial * poly1 = cpl_polynomial_new(2); - cpl_polynomial * poly2; + cpl_polynomial *poly1 = cpl_polynomial_new(2); + cpl_polynomial *poly2; /* Some binomial coefficients */ - double p15[BINOMIAL_SZ] = {1,15,105,455,1365,3003,5005,6435}; - cpl_size deg1; - const cpl_size i8 = 8; - const cpl_size i15 = 2 * i8 - 1; - cpl_size i; + double p15[BINOMIAL_SZ] = { 1, 15, 105, 455, 1365, 3003, 5005, 6435 }; + cpl_size deg1; + const cpl_size i8 = 8; + const cpl_size i15 = 2 * i8 - 1; + cpl_size i; /* -1 is a root with multiplicity 8 */ - const double x1 = -1.0; - cpl_error_code code; + const double x1 = -1.0; + cpl_error_code code; cpl_test_lt(-1, idim); cpl_test_lt(idim, 2); for (cpl_size k = 0; k < i8; k++) { - const cpl_size expo1[2] = {idim ? k : i15, idim ? i15 : k}; + const cpl_size expo1[2] = { idim ? k : i15, idim ? i15 : k }; /* An 15-degree monomial */ code = cpl_polynomial_set_coeff(poly1, expo1, 1.0); @@ -3243,7 +4348,7 @@ cpl_test_eq(deg1, i15 + i8 - 1); poly2 = cpl_polynomial_duplicate(poly1); - code = cpl_polynomial_shift_1d(poly2, idim, -x1) ; + code = cpl_polynomial_shift_1d(poly2, idim, -x1); cpl_test_eq_error(code, CPL_ERROR_NONE); /* poly2 now holds the binomial coefficients for n = 15 */ @@ -3253,8 +4358,8 @@ for (cpl_size k = 0; k < i8; k++) { for (i = 0; i < i8; i++) { const cpl_size j = i15 - i; - const cpl_size expoi[2] = {idim ? k : i, idim ? i : k}; - const cpl_size expoj[2] = {idim ? k : j, idim ? j : k}; + const cpl_size expoi[2] = { idim ? k : i, idim ? i : k }; + const cpl_size expoj[2] = { idim ? k : j, idim ? j : k }; code = cpl_polynomial_set_coeff(poly1, expoi, p15[i]); cpl_test_eq_error(code, CPL_ERROR_NONE); @@ -3265,20 +4370,20 @@ deg1 = cpl_polynomial_get_degree(poly1); cpl_test_error(CPL_ERROR_NONE); - cpl_test_eq(deg1, i15 + i8 -1); + cpl_test_eq(deg1, i15 + i8 - 1); for (cpl_size k = 0; k < i8; k++) { for (i = 0; i < i8; i++) { const cpl_size j = i15 - i; - const cpl_size expoi[2] = {idim ? k : i, idim ? i : k}; - const cpl_size expoj[2] = {idim ? k : j, idim ? j : k}; + const cpl_size expoi[2] = { idim ? k : i, idim ? i : k }; + const cpl_size expoj[2] = { idim ? k : j, idim ? j : k }; const double z1 = cpl_polynomial_get_coeff(poly1, expoi); const double z2 = cpl_polynomial_get_coeff(poly2, expoi); - const double z = cpl_polynomial_get_coeff(poly2, expoj); + const double z = cpl_polynomial_get_coeff(poly2, expoj); - cpl_test_rel( z1, z2, DBL_EPSILON); - cpl_test_rel( z, z2, DBL_EPSILON); + cpl_test_rel(z1, z2, DBL_EPSILON); + cpl_test_rel(z, z2, DBL_EPSILON); } } @@ -3286,7 +4391,6 @@ cpl_polynomial_test_delete(poly1); cpl_polynomial_test_delete(poly2); - } /*----------------------------------------------------------------------------*/ @@ -3298,19 +4402,20 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_polynomial_extract_test_3d_one(FILE * stream) +static void +cpl_polynomial_extract_test_3d_one(FILE *stream) { - const cpl_size nc = 3; - cpl_polynomial * poly1a = cpl_polynomial_new(1); - cpl_polynomial * poly2a = cpl_polynomial_new(2); - cpl_polynomial * poly3 = cpl_polynomial_new(3); + const cpl_size nc = 3; + cpl_polynomial *poly1a = cpl_polynomial_new(1); + cpl_polynomial *poly2a = cpl_polynomial_new(2); + cpl_polynomial *poly3 = cpl_polynomial_new(3); cpl_error_code code; /* Coefficients span powers of 2 from 1 to nc^3 */ for (cpl_size k = 0; k < nc; k++) { for (cpl_size j = 0; j < nc; j++) { for (cpl_size i = 0; i < nc; i++) { - const cpl_size expo[3] = {i, j, k}; + const cpl_size expo[3] = { i, j, k }; const double value = (double)(1 << ((nc * k + j) * nc + i)); code = cpl_polynomial_set_coeff(poly3, expo, value); @@ -3324,10 +4429,10 @@ for (cpl_size ival = -2; ival <= 2; ival++) { /* Evaluate at this point */ - double xval[3] = {(double)ival, (double)ival, (double)ival}; - cpl_vector * vxyz = cpl_vector_wrap(3, xval); - const double xyz = cpl_polynomial_eval(poly3, vxyz); - const cpl_size expo2[2] = {0, 0}; + double xval[3] = { (double)ival, (double)ival, (double)ival }; + cpl_vector *vxyz = cpl_vector_wrap(3, xval); + const double xyz = cpl_polynomial_eval(poly3, vxyz); + const cpl_size expo2[2] = { 0, 0 }; /* Setup collapsing polynomial2 */ code = cpl_polynomial_set_coeff(poly2a, expo2, xval[0]); @@ -3338,11 +4443,11 @@ /* Collapsing each dimension and then evaluating must give to same result*/ for (cpl_size idim1 = 0; idim1 < 3; idim1++) { - cpl_polynomial * poly2 = cpl_polynomial_extract(poly3, idim1, - poly2a); + cpl_polynomial *poly2 = + cpl_polynomial_extract(poly3, idim1, poly2a); for (cpl_size idim2 = 0; idim2 < 2; idim2++) { - cpl_polynomial * poly1 = cpl_polynomial_extract(poly2, idim2, - poly1a); + cpl_polynomial *poly1 = + cpl_polynomial_extract(poly2, idim2, poly1a); const double x = cpl_polynomial_eval_1d(poly1, xval[0], NULL); const cpl_size nfail = cpl_test_get_failed(); @@ -3381,17 +4486,18 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_polynomial_extract_test_2d_one(FILE * stream) +static void +cpl_polynomial_extract_test_2d_one(FILE *stream) { - const cpl_size nc = 5; - cpl_polynomial * poly1a = cpl_polynomial_new(1); - cpl_polynomial * poly2a = cpl_polynomial_new(2); + const cpl_size nc = 5; + cpl_polynomial *poly1a = cpl_polynomial_new(1); + cpl_polynomial *poly2a = cpl_polynomial_new(2); cpl_error_code code; /* Coefficients span powers of 2 from 1 to nc^2 */ for (cpl_size j = 0; j < nc; j++) { for (cpl_size i = 0; i < nc; i++) { - const cpl_size expo[2] = {i, j}; + const cpl_size expo[2] = { i, j }; const double value = (double)(1 << (nc * j + i)); code = cpl_polynomial_set_coeff(poly2a, expo, value); @@ -3404,10 +4510,10 @@ for (cpl_size ival = -2; ival <= 2; ival++) { /* Evaluate at this point */ - double xval[2] = {(double)ival, (double)ival}; - cpl_vector * vxy = cpl_vector_wrap(2, xval); - double xy = cpl_polynomial_eval(poly2a, vxy); - const cpl_size i0 = 0; + double xval[2] = { (double)ival, (double)ival }; + cpl_vector *vxy = cpl_vector_wrap(2, xval); + double xy = cpl_polynomial_eval(poly2a, vxy); + const cpl_size i0 = 0; /* Setup collapsing polynomial */ code = cpl_polynomial_set_coeff(poly1a, &i0, xval[0]); @@ -3416,8 +4522,8 @@ /* Collapsing either dimension and then evaluating must give to same result*/ for (cpl_size idim = 0; idim < 2; idim++) { - cpl_polynomial * poly1b = cpl_polynomial_extract(poly2a, idim, - poly1a); + cpl_polynomial *poly1b = + cpl_polynomial_extract(poly2a, idim, poly1a); const double x = cpl_polynomial_eval_1d(poly1b, xval[0], NULL); cpl_test_error(CPL_ERROR_NONE); @@ -3445,17 +4551,17 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_polynomial_extract_test_2d(FILE * stream, cpl_size idim) +static void +cpl_polynomial_extract_test_2d(FILE *stream, cpl_size idim) { - - cpl_polynomial * nullpoly; - cpl_polynomial * zeropol = cpl_polynomial_new(1); - cpl_polynomial * poly1 = cpl_polynomial_new(2); - cpl_polynomial * poly2 = NULL; - const cpl_size i0 = 0; + cpl_polynomial *nullpoly; + cpl_polynomial *zeropol = cpl_polynomial_new(1); + cpl_polynomial *poly1 = cpl_polynomial_new(2); + cpl_polynomial *poly2 = NULL; + const cpl_size i0 = 0; cpl_size dim, deg; double value; - cpl_error_code code; + cpl_error_code code; nullpoly = cpl_polynomial_extract(poly1, idim, poly2); cpl_test_error(CPL_ERROR_NULL_INPUT); @@ -3493,12 +4599,12 @@ cpl_test_abs(value, 0.0, 0.0); for (cpl_size j = 0; j <= POLY_SIZE; j++) { - const cpl_size pows1[2] = {idim ? j : 0, idim ? 0 : j}; - const cpl_size pows2[2] = {idim ? j : 1, idim ? 1 : j}; + const cpl_size pows1[2] = { idim ? j : 0, idim ? 0 : j }; + const cpl_size pows2[2] = { idim ? j : 1, idim ? 1 : j }; - code = cpl_polynomial_set_coeff(poly1, pows1, (double)(j+1)); + code = cpl_polynomial_set_coeff(poly1, pows1, (double)(j + 1)); cpl_test_eq_error(code, CPL_ERROR_NONE); - code = cpl_polynomial_set_coeff(poly1, pows2, (double)(j+1)); + code = cpl_polynomial_set_coeff(poly1, pows2, (double)(j + 1)); cpl_test_eq_error(code, CPL_ERROR_NONE); } @@ -3512,7 +4618,8 @@ cpl_test_error(CPL_ERROR_NONE); if (icollapse == -1) { cpl_test_zero(deg); - } else { + } + else { cpl_test_eq(deg, POLY_SIZE); } code = cpl_polynomial_dump(poly2, stream); @@ -3533,18 +4640,19 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_polynomial_basic_test(FILE * stream) +static void +cpl_polynomial_basic_test(FILE *stream) { /* Some binomial coefficients */ - const double p15[BINOMIAL_SZ] = {1,15,105,455,1365,3003,5005,6435}; - cpl_size expo[POLY_DIM]; - cpl_polynomial * poly1; - cpl_polynomial * poly2; - cpl_polynomial * poly3; - cpl_polynomial * nullpoly; - cpl_size i, j, k; - double x; - cpl_error_code code; + const double p15[BINOMIAL_SZ] = { 1, 15, 105, 455, 1365, 3003, 5005, 6435 }; + cpl_size expo[POLY_DIM]; + cpl_polynomial *poly1; + cpl_polynomial *poly2; + cpl_polynomial *poly3; + cpl_polynomial *nullpoly; + cpl_size i, j, k; + double x; + cpl_error_code code; nullpoly = cpl_polynomial_new(0); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); @@ -3619,7 +4727,7 @@ j = cpl_polynomial_get_degree(poly1); cpl_test_error(CPL_ERROR_NONE); - cpl_test_eq(j, ii == 1 ? k : (BINOMIAL_SZ-1)); + cpl_test_eq(j, ii == 1 ? k : (BINOMIAL_SZ - 1)); poly2 = cpl_polynomial_duplicate(poly1); cpl_test_error(CPL_ERROR_NONE); @@ -3631,7 +4739,7 @@ j = cpl_polynomial_get_degree(poly2); cpl_test_error(CPL_ERROR_NONE); - cpl_test_eq(j, ii == 1 ? k : (BINOMIAL_SZ-1)); + cpl_test_eq(j, ii == 1 ? k : (BINOMIAL_SZ - 1)); icmp = cpl_polynomial_compare(poly1, poly2, 0.0); cpl_test_error(CPL_ERROR_NONE); @@ -3665,7 +4773,7 @@ j = cpl_polynomial_get_degree(poly2); cpl_test_error(CPL_ERROR_NONE); - cpl_test_eq(j, ii == 1 ? k : (BINOMIAL_SZ-1)); + cpl_test_eq(j, ii == 1 ? k : (BINOMIAL_SZ - 1)); icmp = cpl_polynomial_compare(poly1, poly2, 0.0); cpl_test_error(CPL_ERROR_NONE); @@ -3749,7 +4857,6 @@ cpl_polynomial_test_delete(poly1); cpl_test_error(CPL_ERROR_NONE); } - } /*----------------------------------------------------------------------------*/ @@ -3761,11 +4868,11 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_polynomial_multiply_scalar_test_one(FILE * stream) +static void +cpl_polynomial_multiply_scalar_test_one(FILE *stream) { - - cpl_polynomial * poly2a = cpl_polynomial_new(2) ; - cpl_polynomial * poly2b = cpl_polynomial_new(2); + cpl_polynomial *poly2a = cpl_polynomial_new(2); + cpl_polynomial *poly2b = cpl_polynomial_new(2); cpl_error_code code; const cpl_size degree = 2; @@ -3774,14 +4881,13 @@ for (cpl_size j = 0; j < degree; j++) { for (cpl_size i = 0; i < degree; i++) { - const cpl_size expo[2] = {i, j}; + const cpl_size expo[2] = { i, j }; const double value = (double)(1 << (degree * j + i)); code = cpl_polynomial_set_coeff(poly2a, expo, value); cpl_test_eq_error(code, CPL_ERROR_NONE); if (j == 0) { - if (i == 0) { /* Test while poly2b is empty */ @@ -3791,7 +4897,6 @@ /* Redo set coeff */ code = cpl_polynomial_set_coeff(poly2a, expo, value); cpl_test_eq_error(code, CPL_ERROR_NONE); - } continue; @@ -3822,7 +4927,8 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_polynomial_test_delete(cpl_polynomial * self) +static void +cpl_polynomial_test_delete(cpl_polynomial *self) { if (self != NULL) { cpl_polynomial_derivative_test_empty(self); @@ -3841,71 +4947,75 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_polynomial_derivative_test_empty(cpl_polynomial * self) +static void +cpl_polynomial_derivative_test_empty(cpl_polynomial *self) { - const cpl_size dim = cpl_polynomial_get_dimension(self); - const cpl_size deg = cpl_polynomial_get_degree(self); - cpl_size* expo0 = cpl_calloc(dim, sizeof(*expo0)); - double coeff0 = cpl_polynomial_get_coeff(self, expo0); + const cpl_size dim = cpl_polynomial_get_dimension(self); + const cpl_size deg = cpl_polynomial_get_degree(self); + cpl_size *expo0 = cpl_calloc(dim, sizeof(*expo0)); + double coeff0 = cpl_polynomial_get_coeff(self, expo0); cpl_test_error(CPL_ERROR_NONE); if (deg > 0 || coeff0 != 0.0) { - cpl_polynomial* copy = NULL; - cpl_size deg0; + cpl_polynomial *copy = NULL; + cpl_size deg0; cpl_error_code code; cpl_msg_info(cpl_func, "Derivative-emptying dim %d, degree %d", (int)dim, (int)deg); switch (dim) { - case 1: - for (cpl_size i = deg; i > 0; i--) { - cpl_size mydeg; + case 1: + for (cpl_size i = deg; i > 0; i--) { + cpl_size mydeg; - code = cpl_polynomial_derivative(self, 0); - cpl_test_eq_error(code, CPL_ERROR_NONE); + code = cpl_polynomial_derivative(self, 0); + cpl_test_eq_error(code, CPL_ERROR_NONE); - mydeg = cpl_polynomial_get_degree(self); + mydeg = cpl_polynomial_get_degree(self); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_eq(i, 1 + mydeg); + } + + coeff0 = cpl_polynomial_get_coeff(self, expo0); cpl_test_error(CPL_ERROR_NONE); - cpl_test_eq(i, 1 + mydeg); - } + cpl_test_lt(0.0, fabs(coeff0)); - coeff0 = cpl_polynomial_get_coeff(self, expo0); - cpl_test_error(CPL_ERROR_NONE); + CPL_ATTR_FALLTRHU; /* fall through */ + default: + copy = cpl_polynomial_duplicate(self); - cpl_test_lt(0.0, fabs(coeff0)); + for (cpl_size j = 0; j < dim; j++) { + const cpl_size jj = + j < 2 ? (1 - j) : j; /* Switch 0 and 1 */ + const cpl_size newdeg1 = cpl_polynomial_get_degree(self); + const cpl_size newdeg2 = cpl_polynomial_get_degree(copy); - CPL_ATTR_FALLTRHU; /* fall through */ - default: - copy = cpl_polynomial_duplicate(self); - - for (cpl_size j = 0; j < dim; j++) { - const cpl_size jj = j < 2 ? (1 - j) : j; /* Switch 0 and 1 */ - const cpl_size newdeg1 = cpl_polynomial_get_degree(self); - const cpl_size newdeg2 = cpl_polynomial_get_degree(copy); - - for (cpl_size i = CPL_MAX(newdeg1, newdeg2); i > 0; i--) { - cpl_size mydeg1; - cpl_size mydeg2; + for (cpl_size i = CPL_MAX(newdeg1, newdeg2); i > 0; i--) { + cpl_size mydeg1; + cpl_size mydeg2; - code = cpl_polynomial_derivative(self, j); - cpl_test_eq_error(code, CPL_ERROR_NONE); + code = cpl_polynomial_derivative(self, j); + cpl_test_eq_error(code, CPL_ERROR_NONE); - code = cpl_polynomial_derivative(copy, jj); - cpl_test_eq_error(code, CPL_ERROR_NONE); + code = cpl_polynomial_derivative(copy, jj); + cpl_test_eq_error(code, CPL_ERROR_NONE); - mydeg1 = cpl_polynomial_get_degree(self); - cpl_test_error(CPL_ERROR_NONE); + mydeg1 = cpl_polynomial_get_degree(self); + cpl_test_error(CPL_ERROR_NONE); - mydeg2 = cpl_polynomial_get_degree(copy); - cpl_test_error(CPL_ERROR_NONE); + mydeg2 = cpl_polynomial_get_degree(copy); + cpl_test_error(CPL_ERROR_NONE); - if (mydeg1 == newdeg1 && mydeg2 == newdeg2) break; + if (mydeg1 == newdeg1 && mydeg2 == newdeg2) + break; + } + if (newdeg1 == 0 && newdeg2 == 0) + break; } - if (newdeg1 == 0 && newdeg2 == 0) break; - } } deg0 = cpl_polynomial_get_degree(self); @@ -3921,7 +5031,6 @@ cpl_test(coeff0 != 0.0 ? CPL_FALSE : CPL_TRUE); if (copy != NULL) { - deg0 = cpl_polynomial_get_degree(copy); cpl_test_error(CPL_ERROR_NONE); cpl_test_zero(deg0); @@ -3957,16 +5066,17 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_polynomial_eval_test_2d_one() +static void +cpl_polynomial_eval_test_2d_one(void) { /* Create a 2-Dimensions polynomial */ - cpl_polynomial * poly2d = cpl_polynomial_new(2); - cpl_size expo_2d[2]; - double xy[2]; - cpl_vector * xeval_2d = cpl_vector_wrap(2, xy); - double evalh, evalm; - cpl_error_code code; - + cpl_polynomial *poly2d = cpl_polynomial_new(2); + cpl_size expo_2d[2]; + double xy[2]; + cpl_vector *xeval_2d = cpl_vector_wrap(2, xy); + double evalh, evalm; + cpl_error_code code; + expo_2d[0] = 4; expo_2d[1] = 0; code = cpl_polynomial_set_coeff(poly2d, expo_2d, 1.0); @@ -3974,9 +5084,9 @@ expo_2d[0] = 5; expo_2d[1] = 1; - code = cpl_polynomial_set_coeff(poly2d, expo_2d, -1e-5); + code = cpl_polynomial_set_coeff(poly2d, expo_2d, -1e-5); cpl_test_eq_error(code, CPL_ERROR_NONE); - + /* Evaluate at a specific point, at a root */ xy[0] = 1e3; xy[1] = 1e2; @@ -3984,9 +5094,10 @@ cpl_test_error(CPL_ERROR_NONE); evalm = cpl_polynomial_eval_monomial(poly2d, xeval_2d); cpl_test_error(CPL_ERROR_NONE); - cpl_msg_info(cpl_func, "Evaluation at (polynomial zero) [%g, %g] using " - "horner vs classical evaluation: %g - %g = %g", xy[0], xy[1], - evalh, evalm, evalh - evalm); + cpl_msg_info(cpl_func, + "Evaluation at (polynomial zero) [%g, %g] using " + "horner vs classical evaluation: %g - %g = %g", + xy[0], xy[1], evalh, evalm, evalh - evalm); /* Evaluate at a specific point, at another root */ xy[0] = 1e5; @@ -3995,9 +5106,10 @@ cpl_test_error(CPL_ERROR_NONE); evalm = cpl_polynomial_eval_monomial(poly2d, xeval_2d); cpl_test_error(CPL_ERROR_NONE); - cpl_msg_info(cpl_func, "Evaluation at (polynomial zero) [%g, %g] using " - "horner vs classical evaluation: %g - %g = %g", xy[0], xy[1], - evalh, evalm, evalh - evalm); + cpl_msg_info(cpl_func, + "Evaluation at (polynomial zero) [%g, %g] using " + "horner vs classical evaluation: %g - %g = %g", + xy[0], xy[1], evalh, evalm, evalh - evalm); /* Evaluate at a specific point, not near a root */ xy[0] = 2.0; @@ -4006,10 +5118,11 @@ cpl_test_error(CPL_ERROR_NONE); evalm = cpl_polynomial_eval_monomial(poly2d, xeval_2d); cpl_test_error(CPL_ERROR_NONE); - cpl_msg_info(cpl_func, "Evaluation at [%g, %g] using " - "horner vs classical evaluation: %g - %g = %g", xy[0], xy[1], - evalh, evalm, evalh - evalm); - + cpl_msg_info(cpl_func, + "Evaluation at [%g, %g] using " + "horner vs classical evaluation: %g - %g = %g", + xy[0], xy[1], evalh, evalm, evalh - evalm); + /* Evaluate at a specific point, closer to a root */ xy[0] = 2e4; xy[1] = 1e0; @@ -4017,9 +5130,10 @@ cpl_test_error(CPL_ERROR_NONE); evalm = cpl_polynomial_eval_monomial(poly2d, xeval_2d); cpl_test_error(CPL_ERROR_NONE); - cpl_msg_info(cpl_func, "Evaluation at (polynomial zero) [%g, %g] using " - "horner vs classical evaluation: %g - %g = %g", xy[0], xy[1], - evalh, evalm, evalh - evalm); + cpl_msg_info(cpl_func, + "Evaluation at (polynomial zero) [%g, %g] using " + "horner vs classical evaluation: %g - %g = %g", + xy[0], xy[1], evalh, evalm, evalh - evalm); /* Free */ cpl_polynomial_delete(poly2d); diff -Nru cpl-7.1.4+ds/cplcore/tests/cpl_propertylist-test.c cpl-7.2.2+ds/cplcore/tests/cpl_propertylist-test.c --- cpl-7.1.4+ds/cplcore/tests/cpl_propertylist-test.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/tests/cpl_propertylist-test.c 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -42,6 +42,7 @@ #include #include +#include #include #undef CPL_HAVE_LOCALE @@ -67,8 +68,9 @@ #define FILENAME(N) BASE CPL_STRINGIFY(N) ".fits" -#define RMCARDQUOTE(KEYBASE, MYFILE) \ - "perl -pi -e 's/(" KEYBASE "\\d+ = )\\047([^\\047]*)\\047/$1 $2 /g' " MYFILE +#define RMCARDQUOTE(KEYBASE, MYFILE) \ + "perl -pi -e 's/(" KEYBASE "\\d+ = )\\047([^\\047]*)\\047/$1 $2 " \ + "/g' " MYFILE #define KEYBASE "ESO KEY" @@ -76,12 +78,11 @@ #define NOKEY "Non-existing key" -#define BADNUM "l.O" /* This complex format is valid and supported (when enclosed in parenthesis) */ #define COMPLEXVAL "1D1,2E2" -#define LONGNAME80 \ - "0123456789012345678901234567890123456789" \ +#define LONGNAME80 \ + "0123456789012345678901234567890123456789" \ "0123456789012345678901234567890123456789" @@ -89,12 +90,11 @@ Functions prototypes ----------------------------------------------------------------------------*/ -static int cpl_test_property_compare_name(const cpl_property *, - const cpl_property *); +static int +cpl_test_property_compare_name(const cpl_property *, const cpl_property *); -static void cpl_property_eq(const cpl_property *, - const cpl_property *) - CPL_ATTR_NONNULL; +static void +cpl_property_eq(const cpl_property *, const cpl_property *) CPL_ATTR_NONNULL; static void cpl_propertylist_test_numeric_type(void); @@ -103,24 +103,29 @@ static void cpl_propertylist_test_numeric_load_ok3(void); static void cpl_propertylist_test_numeric_load_bad(void); +static void cpl_propertylist_test_load_bad_key(void); + +static void cpl_propertylist_test_full_card(void); +static void cpl_propertylist_test_too_long_card(void); + static void cpl_propertylist_compare(const cpl_propertylist *, - const cpl_propertylist *) - CPL_ATTR_NONNULL; + const cpl_propertylist *) CPL_ATTR_NONNULL; -static void cpl_propertylist_test_file(const char *, cpl_size *) - CPL_ATTR_NONNULL; +static void cpl_propertylist_test_file(const char *, + cpl_size *, + cpl_boolean) CPL_ATTR_NONNULL; static void cpl_propertylist_test_local(void); /*----------------------------------------------------------------------------- Main -----------------------------------------------------------------------------*/ -int main(int argc, char *argv[]) +int +main(int argc, char *argv[]) { - /* The number of allowed failures (for invalid CLI files) */ - int nxfail = 0; - cpl_size maxsz = 0; + int nxfail = 0; + cpl_size maxsz = 0; cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); @@ -128,15 +133,19 @@ #ifdef CPL_HAVE_LOCALE /* Set the locale to a non POSIX one: LC_NUMERIC=de_DE.UTF8 */ locale_t nonposix_locale = - newlocale(LC_NUMERIC_MASK, CPL_NON_POSIX_LOCALE, (locale_t) 0); - if (nonposix_locale == (locale_t) 0) { - cpl_msg_warning(cpl_func, "Skipping test with unavailable " + newlocale(LC_NUMERIC_MASK, CPL_NON_POSIX_LOCALE, (locale_t)0); + if (nonposix_locale == (locale_t)0) { + cpl_msg_warning(cpl_func, + "Skipping test with unavailable " "non-POSIX locale: " CPL_NON_POSIX_LOCALE); - } else { + } + else { locale_t old_locale = uselocale(nonposix_locale); - cpl_msg_info(cpl_func, "Testing with non-POSIX locale (float: %g): " - CPL_NON_POSIX_LOCALE, 1.23); + cpl_msg_info(cpl_func, + "Testing with non-POSIX locale (float: " + "%g): " CPL_NON_POSIX_LOCALE, + 1.23); cpl_propertylist_test_local(); @@ -144,34 +153,37 @@ freelocale(nonposix_locale); } - cpl_msg_info(cpl_func, "Testing with default locale (float: %g)", - 1.23); + cpl_msg_info(cpl_func, "Testing with default locale (float: %g)", 1.23); #endif cpl_propertylist_test_local(); } for (int ifile = 0; ifile < argc; ifile++) { if (ifile == 0) { - const cpl_propertylist * nulllist - = cpl_propertylist_load(argv[0], 0); + const cpl_propertylist *nulllist = + cpl_propertylist_load(argv[0], 0); cpl_test_error(CPL_ERROR_BAD_FILE_FORMAT); cpl_test_null(nulllist); - } else { - const cpl_size nfailed = cpl_test_get_failed(); + } + else { + const cpl_size nfailed = cpl_test_get_failed(); const cpl_msg_severity msg_level = cpl_msg_get_level(); + cpl_boolean is_valid; cpl_msg_set_level(CPL_MSG_OFF); cpl_test_fits(argv[ifile]); cpl_msg_set_level(msg_level); - if (cpl_test_get_failed() == nfailed) { - cpl_propertylist_test_file(argv[ifile], &maxsz); - } else { - cpl_msg_info(cpl_func, "Skipping tests using %s (%d/%d)", - argv[ifile], ifile+1, argc); + is_valid = cpl_test_get_failed() == nfailed ? CPL_TRUE : CPL_FALSE; + + if (!is_valid) { + cpl_msg_info(cpl_func, "Testing with invalid %s (%d/%d)", + argv[ifile], ifile + 1, argc); nxfail++; } + + cpl_propertylist_test_file(argv[ifile], &maxsz, is_valid); } } @@ -181,16 +193,13 @@ } return cpl_test_end(-nxfail); - } -static void cpl_propertylist_test_local(void) +static void +cpl_propertylist_test_local(void) { - - const char *keys[] = { - "a", "b", "c", "d", "e", "f", "g", "h", "i", - "A", "B", "C", "D", "E", "F", "G", "H", "I", - }; + const char *keys[] = { "a", "b", "c", "d", "e", "f", "g", "h", "i", + "A", "B", "C", "D", "E", "F", "G", "H", "I" }; const char *comments[] = { "A character value", @@ -204,41 +213,35 @@ "A double precision complex number" }; - cpl_type types[] = { - CPL_TYPE_CHAR, - CPL_TYPE_BOOL, - CPL_TYPE_INT, - CPL_TYPE_LONG, - CPL_TYPE_FLOAT, - CPL_TYPE_DOUBLE, - CPL_TYPE_STRING, - CPL_TYPE_FLOAT_COMPLEX, - CPL_TYPE_DOUBLE_COMPLEX - }; + cpl_type types[] = { CPL_TYPE_CHAR, CPL_TYPE_BOOL, + CPL_TYPE_INT, CPL_TYPE_LONG, + CPL_TYPE_FLOAT, CPL_TYPE_DOUBLE, + CPL_TYPE_STRING, CPL_TYPE_FLOAT_COMPLEX, + CPL_TYPE_DOUBLE_COMPLEX }; int status, j; long i; - long naxes[2] = {256,256}; + long naxes[2] = { 256, 256 }; const float fval0 = -1.23456789; float fval1, fval2; const double dval0 = -1.23456789; double dval1, dval2; const float complex zf0 = fval0 + fval0 * fval0 * _Complex_I; - float complex zf1, zf2; + float complex zf1, zf2; const double complex zd0 = zf0; double complex zd1, zd2; - float f0,f1,f2; - double d0,d1,d2; - const int nprops = sizeof(types)/sizeof(types[0]); + float f0, f1, f2; + double d0, d1, d2; + const int nprops = sizeof(types) / sizeof(types[0]); char stringarray[FLEN_VALUE]; const char *filename3 = BASE ".fits"; /*const char regex[] = "^(DATE-OBS|ESO|COMMENT|HISTORY)$";*/ const char to_rm[] = "^HIERARCH ESO |^NBXIS1$|^NBXIS2$|^HISTORY$"; cpl_propertylist *plist, *_plist, *plist2; - const cpl_propertylist * nulllist; + const cpl_propertylist *nulllist; cpl_property *pro, *pro2; const cpl_property *pro1; const cpl_property *nullprop; @@ -246,9 +249,9 @@ cpl_type t1; cpl_error_code code; int value; - cpl_boolean do_bench; + cpl_boolean do_bench; int bench_size; - const char * strval; + const char *strval; int syscode; fitsfile *fptr = NULL; @@ -261,13 +264,13 @@ /* Always test the _dump functions, but produce no output when the message level is above info */ - stream = cpl_msg_get_level() > CPL_MSG_INFO - ? fopen("/dev/null", "a") : stdout; + stream = + cpl_msg_get_level() > CPL_MSG_INFO ? fopen("/dev/null", "a") : stdout; cpl_test_nonnull(stream); - cpl_test_eq(sizeof(comments)/sizeof(comments[0]), nprops); - cpl_test_eq(sizeof(keys)/sizeof(keys[0]), 2 * nprops); + cpl_test_eq(sizeof(comments) / sizeof(comments[0]), nprops); + cpl_test_eq(sizeof(keys) / sizeof(keys[0]), 2 * nprops); /* * Test 1: Create a property list and check its validity. @@ -319,7 +322,7 @@ cpl_test_eq(cpl_propertylist_get_size(plist), nprops); - pro1 = cpl_propertylist_get_const(plist, nprops-1); + pro1 = cpl_propertylist_get_const(plist, nprops - 1); cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(pro1); @@ -338,9 +341,9 @@ cpl_test_leq(nprops, cpl_propertylist_get_size(_plist)); for (i = 0; i < nprops; i++) { - const cpl_property * p1 = + const cpl_property *p1 = cpl_propertylist_get_property_const(plist, keys[i]); - const cpl_property * p2 = + const cpl_property *p2 = cpl_propertylist_get_property_const(_plist, keys[i + nprops]); cpl_test_eq(i, i); @@ -352,36 +355,45 @@ if (types[i] == CPL_TYPE_CHAR) { /* FITS I/O promotes this type to a single character string */ cpl_test_eq(cpl_property_get_type(p2), CPL_TYPE_STRING); - cpl_test_eq(cpl_property_get_string(p2)[0], cpl_property_get_char(p1)); - } else if (types[i] == CPL_TYPE_LONG) { + cpl_test_eq(cpl_property_get_string(p2)[0], + cpl_property_get_char(p1)); + } + else if (types[i] == CPL_TYPE_LONG) { /* FITS I/O casts this type to int */ cpl_test_eq(cpl_property_get_type(p2), CPL_TYPE_INT); cpl_test_eq(cpl_property_get_int(p2), cpl_property_get_long(p1)); - } else if (types[i] == CPL_TYPE_FLOAT) { + } + else if (types[i] == CPL_TYPE_FLOAT) { /* FITS I/O promotes this type to double */ cpl_test_eq(cpl_property_get_type(p2), CPL_TYPE_DOUBLE); cpl_test_abs(cpl_property_get_double(p2), cpl_property_get_float(p1), 2.0 * FLT_EPSILON); - } else if (types[i] == CPL_TYPE_FLOAT_COMPLEX) { + } + else if (types[i] == CPL_TYPE_FLOAT_COMPLEX) { /* FITS I/O promotes this type to double complex */ cpl_test_eq(cpl_property_get_type(p2), CPL_TYPE_DOUBLE_COMPLEX); zd1 = cpl_property_get_float_complex(p1); zd2 = cpl_property_get_double_complex(p2); cpl_test_abs_complex(zd1, zd2, 2.0 * FLT_EPSILON); - } else { + } + else { cpl_test_eq(cpl_property_get_type(p2), types[i]); if (types[i] == CPL_TYPE_BOOL) { cpl_test_eq(cpl_property_get_bool(p2), cpl_property_get_bool(p1)); - } else if (types[i] == CPL_TYPE_INT) { + } + else if (types[i] == CPL_TYPE_INT) { cpl_test_eq(cpl_property_get_int(p2), cpl_property_get_int(p1)); - } else if (types[i] == CPL_TYPE_DOUBLE) { + } + else if (types[i] == CPL_TYPE_DOUBLE) { cpl_test_abs(cpl_property_get_double(p2), cpl_property_get_double(p1), DBL_EPSILON); - } else if (types[i] == CPL_TYPE_STRING) { + } + else if (types[i] == CPL_TYPE_STRING) { cpl_test_eq_string(cpl_property_get_string(p2), cpl_property_get_string(p1)); - } else if (types[i] == CPL_TYPE_DOUBLE_COMPLEX) { + } + else if (types[i] == CPL_TYPE_DOUBLE_COMPLEX) { zd1 = cpl_property_get_double_complex(p1); zd2 = cpl_property_get_double_complex(p2); cpl_test_abs_complex(zd1, zd2, 32.0 * DBL_EPSILON); @@ -390,7 +402,6 @@ cpl_test_zero(strncmp(cpl_property_get_comment(p2), comments[i], strlen(cpl_property_get_comment(p2)))); - } cpl_propertylist_delete(_plist); @@ -406,7 +417,6 @@ cpl_test_eq_string(cpl_propertylist_get_comment(plist, keys[i]), comments[i]); cpl_test_eq(cpl_propertylist_get_type(plist, keys[i]), types[i]); - } cpl_test_eq(cpl_propertylist_get_char(plist, keys[0]), 'a'); @@ -507,70 +517,83 @@ * list. */ - cpl_test_eq(cpl_propertylist_insert_char(plist, keys[0], - keys[0 + nprops], 'a'), 0); + cpl_test_eq(cpl_propertylist_insert_char(plist, keys[0], keys[0 + nprops], + 'a'), + 0); cpl_test_eq(cpl_propertylist_insert_after_char(plist, keys[0], - keys[0 + nprops], 'c'), 0); + keys[0 + nprops], 'c'), + 0); - cpl_test_eq(cpl_propertylist_insert_bool(plist, keys[1], - keys[1 + nprops], 0), 0); + cpl_test_eq(cpl_propertylist_insert_bool(plist, keys[1], keys[1 + nprops], + 0), + 0); cpl_test_eq(cpl_propertylist_insert_after_bool(plist, keys[1], - keys[1 + nprops], 1), 0); + keys[1 + nprops], 1), + 0); - cpl_test_eq(cpl_propertylist_insert_int(plist, keys[2], - keys[2 + nprops], 0), 0); + cpl_test_eq(cpl_propertylist_insert_int(plist, keys[2], keys[2 + nprops], + 0), + 0); cpl_test_eq(cpl_propertylist_insert_after_int(plist, keys[2], - keys[2 + nprops], 1), 0); + keys[2 + nprops], 1), + 0); cpl_test_eq(cpl_propertylist_insert_long(plist, keys[3], keys[3 + nprops], - 123456789), 0); + 123456789), + 0); cpl_test_eq(cpl_propertylist_insert_after_long(plist, keys[3], - keys[3 + nprops], - 123456789), 0); + keys[3 + nprops], 123456789), + 0); cpl_test_eq(cpl_propertylist_insert_float(plist, keys[4], keys[4 + nprops], - fval0), 0); + fval0), + 0); cpl_test_eq(cpl_propertylist_insert_after_float(plist, keys[4], - keys[4 + nprops], - -fval0), 0); + keys[4 + nprops], -fval0), + 0); cpl_test_eq(cpl_propertylist_insert_double(plist, keys[5], keys[5 + nprops], - dval0), 0); + dval0), + 0); cpl_test_eq(cpl_propertylist_insert_after_double(plist, keys[5], - keys[5 + nprops], - -dval0), 0); + keys[5 + nprops], -dval0), + 0); - cpl_test_eq(cpl_propertylist_insert_string(plist, keys[6], - keys[6 + nprops], ""), 0); + cpl_test_eq(cpl_propertylist_insert_string(plist, keys[6], keys[6 + nprops], + ""), + 0); cpl_test_eq(cpl_propertylist_insert_after_string(plist, keys[6], - keys[6 + nprops], ""), 0); + keys[6 + nprops], ""), + 0); cpl_test_eq(cpl_propertylist_insert_float(plist, keys[7], keys[7 + nprops], - fval0), 0); + fval0), + 0); cpl_test_eq(cpl_propertylist_insert_after_float(plist, keys[7], - keys[7 + nprops], - -fval0), 0); + keys[7 + nprops], -fval0), + 0); cpl_test_eq(cpl_propertylist_insert_double(plist, keys[8], keys[8 + nprops], - dval0), 0); + dval0), + 0); cpl_test_eq(cpl_propertylist_insert_after_double(plist, keys[8], - keys[8 + nprops], - -dval0), 0); + keys[8 + nprops], -dval0), + 0); for (i = 0; i < nprops; i++) { @@ -584,51 +607,51 @@ cpl_test_eq_string(cpl_property_get_name(p2), keys[i + nprops]); switch (cpl_property_get_type(p0)) { - case CPL_TYPE_CHAR: - cpl_test_eq(cpl_property_get_char(p0), 'a'); - cpl_test_eq(cpl_property_get_char(p2), 'c'); - break; - - case CPL_TYPE_BOOL: - cpl_test_zero(cpl_property_get_bool(p0)); - cpl_test_eq(cpl_property_get_bool(p2), 1); - break; - - case CPL_TYPE_INT: - cpl_test_zero(cpl_property_get_int(p0)); - cpl_test_zero(cpl_property_get_int(p0)); - break; - - case CPL_TYPE_LONG: - cpl_test_eq(cpl_property_get_long(p0), 123456789); - cpl_test_eq(cpl_property_get_long(p0), 123456789); - break; - - case CPL_TYPE_FLOAT: - fval1 = cpl_property_get_float(p0); - cpl_test_abs(fval0, fval1, 0.0); - - fval1 = -cpl_property_get_float(p2); - cpl_test_abs(fval0, fval1, 0.0); - break; - - case CPL_TYPE_DOUBLE: - dval1 = cpl_property_get_double(p0); - cpl_test_abs(dval0, dval1, 0.0); - - dval1 = -cpl_property_get_double(p2); - cpl_test_abs(dval0, dval1, 0.0); - break; - - case CPL_TYPE_STRING: - cpl_test_eq_string(cpl_property_get_string(p0), ""); - cpl_test_eq_string(cpl_property_get_string(p2), ""); - break; - - default: - /* This point should never be reached */ - cpl_test(0); - break; + case CPL_TYPE_CHAR: + cpl_test_eq(cpl_property_get_char(p0), 'a'); + cpl_test_eq(cpl_property_get_char(p2), 'c'); + break; + + case CPL_TYPE_BOOL: + cpl_test_zero(cpl_property_get_bool(p0)); + cpl_test_eq(cpl_property_get_bool(p2), 1); + break; + + case CPL_TYPE_INT: + cpl_test_zero(cpl_property_get_int(p0)); + cpl_test_zero(cpl_property_get_int(p0)); + break; + + case CPL_TYPE_LONG: + cpl_test_eq(cpl_property_get_long(p0), 123456789); + cpl_test_eq(cpl_property_get_long(p0), 123456789); + break; + + case CPL_TYPE_FLOAT: + fval1 = cpl_property_get_float(p0); + cpl_test_abs(fval0, fval1, 0.0); + + fval1 = -cpl_property_get_float(p2); + cpl_test_abs(fval0, fval1, 0.0); + break; + + case CPL_TYPE_DOUBLE: + dval1 = cpl_property_get_double(p0); + cpl_test_abs(dval0, dval1, 0.0); + + dval1 = -cpl_property_get_double(p2); + cpl_test_abs(dval0, dval1, 0.0); + break; + + case CPL_TYPE_STRING: + cpl_test_eq_string(cpl_property_get_string(p0), ""); + cpl_test_eq_string(cpl_property_get_string(p2), ""); + break; + + default: + /* This point should never be reached */ + cpl_test(0); + break; } } @@ -736,7 +759,8 @@ if (cpl_property_get_comment(p) == NULL) { cpl_test_null(cpl_property_get_comment(_p)); - } else { + } + else { cpl_test_noneq_ptr(cpl_property_get_comment(p), cpl_property_get_comment(_p)); cpl_test_eq_string(cpl_property_get_comment(p), @@ -744,59 +768,58 @@ } switch (cpl_property_get_type(p)) { - case CPL_TYPE_CHAR: - cpl_test_eq(cpl_property_get_char(p), - cpl_property_get_char(_p)); - break; - - case CPL_TYPE_BOOL: - cpl_test_eq(cpl_property_get_bool(p), - cpl_property_get_bool(_p)); - break; - - case CPL_TYPE_INT: - cpl_test_eq(cpl_property_get_int(p), - cpl_property_get_int(_p)); - break; - - case CPL_TYPE_LONG: - cpl_test_eq(cpl_property_get_long(p), - cpl_property_get_long(_p)); - break; - - case CPL_TYPE_FLOAT: - fval1 = cpl_property_get_float(p); - fval2 = cpl_property_get_float(_p); - cpl_test_abs(fval1, fval2, 0.0); - break; - - case CPL_TYPE_DOUBLE: - dval1 = cpl_property_get_double(p); - dval2 = cpl_property_get_double(_p); - cpl_test_abs(dval1, dval2, 0.0); - break; - - case CPL_TYPE_STRING: - cpl_test_eq_string(cpl_property_get_string(p), - cpl_property_get_string(_p)); - break; - - case CPL_TYPE_FLOAT_COMPLEX: - zf1 = cpl_property_get_float_complex(p); - zf2 = cpl_property_get_float_complex(_p); - cpl_test_abs_complex(zf1, zf2, 0.0); - break; - - case CPL_TYPE_DOUBLE_COMPLEX: - zd1 = cpl_property_get_double_complex(p); - zd2 = cpl_property_get_double_complex(_p); - cpl_test_abs_complex(zd1, zd2, 0.0); - break; - - default: - /* This point should never be reached */ - cpl_test(0); - break; + case CPL_TYPE_CHAR: + cpl_test_eq(cpl_property_get_char(p), + cpl_property_get_char(_p)); + break; + + case CPL_TYPE_BOOL: + cpl_test_eq(cpl_property_get_bool(p), + cpl_property_get_bool(_p)); + break; + + case CPL_TYPE_INT: + cpl_test_eq(cpl_property_get_int(p), cpl_property_get_int(_p)); + break; + + case CPL_TYPE_LONG: + cpl_test_eq(cpl_property_get_long(p), + cpl_property_get_long(_p)); + break; + + case CPL_TYPE_FLOAT: + fval1 = cpl_property_get_float(p); + fval2 = cpl_property_get_float(_p); + cpl_test_abs(fval1, fval2, 0.0); + break; + + case CPL_TYPE_DOUBLE: + dval1 = cpl_property_get_double(p); + dval2 = cpl_property_get_double(_p); + cpl_test_abs(dval1, dval2, 0.0); + break; + + case CPL_TYPE_STRING: + cpl_test_eq_string(cpl_property_get_string(p), + cpl_property_get_string(_p)); + break; + + case CPL_TYPE_FLOAT_COMPLEX: + zf1 = cpl_property_get_float_complex(p); + zf2 = cpl_property_get_float_complex(_p); + cpl_test_abs_complex(zf1, zf2, 0.0); + break; + + case CPL_TYPE_DOUBLE_COMPLEX: + zd1 = cpl_property_get_double_complex(p); + zd2 = cpl_property_get_double_complex(_p); + cpl_test_abs_complex(zd1, zd2, 0.0); + break; + + default: + /* This point should never be reached */ + cpl_test(0); + break; } } @@ -849,39 +872,41 @@ cpl_propertylist_empty(plist); -// cpl_test_assert(cpl_propertylist_is_empty(plist)); + // cpl_test_assert(cpl_propertylist_is_empty(plist)); cpl_test(cpl_propertylist_is_empty(plist)); - cpl_test_zero(cpl_propertylist_get_size(plist)); + cpl_test_zero(cpl_propertylist_get_size(plist)); cpl_propertylist_delete(plist); - /* + /* * Test 10: Write a propertylist to a FITS file * and save it in disk */ - code = cpl_propertylist_update_string(plist2,"ESO OBS DID", "BLABLA"); + code = cpl_propertylist_update_string(plist2, "ESO OBS DID", "BLABLA"); cpl_test_eq_error(code, CPL_ERROR_NONE); - code = cpl_propertylist_update_string(plist2,"ESO OBS OBSERVER", "NAME"); + code = cpl_propertylist_update_string(plist2, "ESO OBS OBSERVER", "NAME"); cpl_test_eq_error(code, CPL_ERROR_NONE); - code = cpl_propertylist_update_string(plist2,"ESO OBS PI-COI NAME", "NAME"); + code = + cpl_propertylist_update_string(plist2, "ESO OBS PI-COI NAME", "NAME"); cpl_test_eq_error(code, CPL_ERROR_NONE); - code = cpl_propertylist_update_string(plist2,"ESO INS GRAT NAME", "DODO"); + code = cpl_propertylist_update_string(plist2, "ESO INS GRAT NAME", "DODO"); cpl_test_eq_error(code, CPL_ERROR_NONE); - code = cpl_propertylist_update_string(plist2,"ESO PRO CATG", "PRODUCT"); + code = cpl_propertylist_update_string(plist2, "ESO PRO CATG", "PRODUCT"); cpl_test_eq_error(code, CPL_ERROR_NONE); - code = cpl_propertylist_update_int(plist2,"ESO TPL NEXP", 4); + code = cpl_propertylist_update_int(plist2, "ESO TPL NEXP", 4); cpl_test_eq_error(code, CPL_ERROR_NONE); code = cpl_propertylist_update_int(plist2, "TOFITS", 6); cpl_test_eq_error(code, CPL_ERROR_NONE); - code = cpl_propertylist_set_comment(plist2, "TOFITS", "Test TOFITS function"); + code = + cpl_propertylist_set_comment(plist2, "TOFITS", "Test TOFITS function"); cpl_test_eq_error(code, CPL_ERROR_NONE); (void)remove(filename3); @@ -897,7 +922,7 @@ cpl_test_zero(status); /*Save a propertylist to a FITS file*/ - code = cpl_propertylist_to_fitsfile(fptr, plist2, NULL); + code = cpl_propertylist_to_fitsfile(fptr, plist2, NULL, CPL_FALSE); cpl_test_eq_error(code, CPL_ERROR_NONE); fits_close_file(fptr, &status); @@ -948,77 +973,78 @@ */ cpl_test_eq(cpl_propertylist_get_size(plist2), - cpl_propertylist_get_size(_plist)); + cpl_propertylist_get_size(_plist)); for (i = 0; i < cpl_propertylist_get_size(plist2); i++) { const cpl_property *p = cpl_propertylist_get_const(plist2, i); cpl_property *_p = cpl_propertylist_get(_plist, i); - cpl_test_eq_string(cpl_property_get_name(p), - cpl_property_get_name(_p)); + cpl_test_eq_string(cpl_property_get_name(p), cpl_property_get_name(_p)); cpl_test_eq_string(cpl_property_get_comment(p), cpl_property_get_comment(_p)); cpl_test_eq(cpl_property_get_type(p), cpl_property_get_type(_p)); switch (cpl_property_get_type(p)) { - case CPL_TYPE_BOOL: - cpl_test_eq(cpl_property_get_bool(p), cpl_property_get_bool(_p)); - break; - - case CPL_TYPE_INT: - cpl_test_eq(cpl_property_get_int(p), cpl_property_get_int(_p)); - break; - - case CPL_TYPE_DOUBLE: - cpl_test_eq(cpl_property_get_double(p), - cpl_property_get_double(_p)); - break; - - case CPL_TYPE_STRING: - cpl_test_eq_string(cpl_property_get_string(p), - cpl_property_get_string(_p)); - break; - - case CPL_TYPE_FLOAT_COMPLEX: { - const float complex cval1 = cpl_property_get_float_complex(p); - const float complex cval2 = cpl_property_get_float_complex(_p); - const float rval1 = crealf(cval1); - const float ival1 = cimagf(cval1); - const float rval2 = crealf(cval2); - const float ival2 = cimagf(cval2); + case CPL_TYPE_BOOL: + cpl_test_eq(cpl_property_get_bool(p), + cpl_property_get_bool(_p)); + break; + + case CPL_TYPE_INT: + cpl_test_eq(cpl_property_get_int(p), cpl_property_get_int(_p)); + break; + + case CPL_TYPE_DOUBLE: + cpl_test_eq(cpl_property_get_double(p), + cpl_property_get_double(_p)); + break; + + case CPL_TYPE_STRING: + cpl_test_eq_string(cpl_property_get_string(p), + cpl_property_get_string(_p)); + break; + + case CPL_TYPE_FLOAT_COMPLEX: { + const float complex cval1 = cpl_property_get_float_complex(p); + const float complex cval2 = cpl_property_get_float_complex(_p); + const float rval1 = crealf(cval1); + const float ival1 = cimagf(cval1); + const float rval2 = crealf(cval2); + const float ival2 = cimagf(cval2); - cpl_test_error(CPL_ERROR_NONE); + cpl_test_error(CPL_ERROR_NONE); - cpl_test_rel(rval1, rval2, FLT_EPSILON); - cpl_test_rel(ival1, ival2, FLT_EPSILON); + cpl_test_rel(rval1, rval2, FLT_EPSILON); + cpl_test_rel(ival1, ival2, FLT_EPSILON); - break; - } - case CPL_TYPE_DOUBLE_COMPLEX: { - const double complex cval1 = cpl_property_get_double_complex(p); - const double complex cval2 = cpl_property_get_double_complex(_p); - const double rval1 = creal(cval1); - const double ival1 = cimag(cval1); - const double rval2 = creal(cval2); - const double ival2 = cimag(cval2); + break; + } + case CPL_TYPE_DOUBLE_COMPLEX: { + const double complex cval1 = cpl_property_get_double_complex(p); + const double complex cval2 = + cpl_property_get_double_complex(_p); + const double rval1 = creal(cval1); + const double ival1 = cimag(cval1); + const double rval2 = creal(cval2); + const double ival2 = cimag(cval2); - cpl_test_error(CPL_ERROR_NONE); + cpl_test_error(CPL_ERROR_NONE); - cpl_test_rel(rval1, rval2, DBL_EPSILON); - cpl_test_rel(ival1, ival2, DBL_EPSILON); + cpl_test_rel(rval1, rval2, DBL_EPSILON); + cpl_test_rel(ival1, ival2, DBL_EPSILON); - break; - } - default: - /* This point should never be reached */ + break; + } + default: + /* This point should never be reached */ - cpl_test_eq(cpl_property_get_type(p), CPL_TYPE_INVALID); - cpl_test_noneq(cpl_property_get_type(p), CPL_TYPE_INVALID); + cpl_test_eq(cpl_property_get_type(p), CPL_TYPE_INVALID); + cpl_test_noneq(cpl_property_get_type(p), CPL_TYPE_INVALID); - cpl_property_dump(p, stderr); - cpl_property_dump(_p, stderr); + cpl_property_dump(p, stderr); + cpl_property_dump(_p, stderr); - break; + break; } } @@ -1074,7 +1100,7 @@ cpl_test_eq_error(code, CPL_ERROR_NONE); cpl_test_eq(cpl_propertylist_get_size(_plist), 6); - value = cpl_propertylist_erase_regexp(_plist, "^ESO OBS .*", 0); + value = cpl_propertylist_erase_regexp(_plist, "^ESO OBS .*", 0); cpl_test_eq(value, 3); cpl_test_eq(cpl_propertylist_get_size(_plist), 3); @@ -1284,7 +1310,7 @@ cpl_test_eq(cpl_propertylist_get_type(plist, keys[i]), types[i]); }*/ - /* + /* * Test 19: Try to access the next element and see * if the end of list is handled properly. */ @@ -1293,7 +1319,7 @@ cpl_test_eq(pro, NULL);*/ -/* + /* * Test 20: Create a FITS header using a list containing a property with * a name of length 80 characters (the length of a FITS card) */ @@ -1320,8 +1346,7 @@ cpl_test_zero(cpl_propertylist_get_size(plist)); - for(i = 0; i < 1; i++) { - + for (i = 0; i < 1; i++) { cpl_propertylist_append_int(plist, "FDEBACGH", -1); cpl_propertylist_set_comment(plist, "FDEBACGH", comments[2]); @@ -1345,7 +1370,6 @@ cpl_propertylist_append_double(plist, "HISTORY", dval0); cpl_propertylist_set_comment(plist, "HISTORY", comments[5]); - } cpl_test_zero(cpl_propertylist_is_empty(plist)); @@ -1373,6 +1397,12 @@ cpl_propertylist_append_string(plist, "COMMENT", ""); cpl_propertylist_append_string(plist, "COMMENT", "HELLO"); cpl_propertylist_append_string(plist, "COMMENT", "AGAIN"); + + /* These two will be written, but as commentary cards, + so they cannot be re-read with their original type, + and the FITS value indicator and quote-encoding remains... */ + cpl_propertylist_append_char(plist, "HISTORY", '\''); + cpl_propertylist_append_char(plist, "COMMENT", '\''); cpl_test_error(CPL_ERROR_NONE); t = cpl_table_new(1); @@ -1381,8 +1411,7 @@ cpl_test_fits(BASE "_21a.fits"); /* Two additional COMMENT cards will be added, so count only HISTORY */ - plist2 = cpl_propertylist_load_regexp(BASE "_21a.fits", 0, - "HISTORY", 0); + plist2 = cpl_propertylist_load_regexp(BASE "_21a.fits", 0, "HISTORY", 0); cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(plist2); @@ -1403,16 +1432,16 @@ if (plist == NULL) { cpl_test_error(CPL_ERROR_FILE_IO); - } else { - + } + else { /* Inactive per default */ code = cpl_propertylist_sort(plist, cpl_test_property_compare_name); cpl_test_eq_error(code, CPL_ERROR_NONE); - code = cpl_image_save(NULL, BASE "_sorted.fits", CPL_TYPE_UCHAR, - plist, CPL_IO_CREATE); + code = cpl_image_save(NULL, BASE "_sorted.fits", CPL_TYPE_UCHAR, plist, + CPL_IO_CREATE); cpl_test_eq_error(code, CPL_ERROR_NONE); cpl_test_fits(BASE "_sorted.fits"); cpl_test_zero(remove(BASE "_sorted.fits")); @@ -1433,7 +1462,7 @@ bench_size = do_bench ? 100000 : 10000; - for(i = 0; i < bench_size; i++) { + for (i = 0; i < bench_size; i++) { cpl_propertylist_append_float(plist, keys[4], fval0); cpl_propertylist_set_comment(plist, keys[4], comments[4]); @@ -1460,7 +1489,6 @@ cpl_propertylist_append_double_complex(plist, keys[8], dval0); cpl_propertylist_set_comment(plist, keys[8], comments[8]); - } cpl_test_zero(cpl_propertylist_is_empty(plist)); @@ -1475,7 +1503,7 @@ fits_create_img(fptr, 8, 0, naxes, &status); cpl_test_zero(status); - code = cpl_propertylist_to_fitsfile(fptr, plist, NULL); + code = cpl_propertylist_to_fitsfile(fptr, plist, NULL, CPL_FALSE); cpl_test_eq_error(code, CPL_ERROR_NONE); fits_close_file(fptr, &status); @@ -1555,7 +1583,7 @@ * Check that XTENSION is set to IMAGE */ - plist = cpl_propertylist_load(BASE "_null.fits",1); + plist = cpl_propertylist_load(BASE "_null.fits", 1); cpl_test_eq_string("IMAGE", cpl_propertylist_get_string(plist, "XTENSION")); cpl_propertylist_delete(plist); @@ -1594,8 +1622,10 @@ cpl_propertylist_append_double(plist, keys[5], dval0); cpl_propertylist_set_comment(plist, keys[5], comments[5]); - cpl_propertylist_append_string(plist, "HIERARCH ESO TEST1", "One string without any comment"); - cpl_propertylist_append_string(plist, "HIERARCH ESO TEST2", "Two string without any comment"); + cpl_propertylist_append_string(plist, "HIERARCH ESO TEST1", + "One string without any comment"); + cpl_propertylist_append_string(plist, "HIERARCH ESO TEST2", + "Two string without any comment"); cpl_propertylist_append_float_complex(plist, keys[7], zf0); @@ -1607,9 +1637,12 @@ cpl_propertylist_append_long(plist, "NBXIS2", 32769); cpl_propertylist_set_comment(plist, "NBXIS2", comments[3]); - cpl_propertylist_append_string(plist, "HISTORY", "One history string without any comment"); - cpl_propertylist_append_string(plist, "HISTORY", "Two history string without any comment"); - cpl_propertylist_append_string(plist, "HISTORY", "Three history string without any comment"); + cpl_propertylist_append_string(plist, "HISTORY", + "One history string without any comment"); + cpl_propertylist_append_string(plist, "HISTORY", + "Two history string without any comment"); + cpl_propertylist_append_string(plist, "HISTORY", + "Three history string without any comment"); #ifdef CPL_FITS_TEST_NON_STRING_HISTORY_COMMENT /* This will produce a pretty strange FITS header */ @@ -1630,25 +1663,25 @@ HIERARCH ESO |NBXIS1|NBXIS2|HISTORY */ - code = cpl_propertylist_to_fitsfile(fptr, plist, ")|("); + code = cpl_propertylist_to_fitsfile(fptr, plist, ")|(", CPL_FALSE); cpl_test_eq_error(code, CPL_ERROR_ILLEGAL_INPUT); - code = cpl_propertylist_to_fitsfile(fptr, plist, to_rm); + code = cpl_propertylist_to_fitsfile(fptr, plist, to_rm, CPL_FALSE); cpl_test_eq_error(code, CPL_ERROR_NONE); /* Pass a null regexp to the function*/ - code = cpl_propertylist_to_fitsfile(fptr, plist, NULL); + code = cpl_propertylist_to_fitsfile(fptr, plist, NULL, CPL_FALSE); cpl_test_eq_error(code, CPL_ERROR_NONE); /* Pass an empty property list to the function */ cpl_propertylist_empty(plist); - code = cpl_propertylist_to_fitsfile(fptr, plist, to_rm); + code = cpl_propertylist_to_fitsfile(fptr, plist, to_rm, CPL_FALSE); cpl_test_eq_error(code, CPL_ERROR_NONE); - code = cpl_propertylist_to_fitsfile(fptr, NULL, to_rm); + code = cpl_propertylist_to_fitsfile(fptr, NULL, to_rm, CPL_FALSE); cpl_test_eq_error(code, CPL_ERROR_NULL_INPUT); - code = cpl_propertylist_to_fitsfile(NULL, plist, to_rm); + code = cpl_propertylist_to_fitsfile(NULL, plist, to_rm, CPL_FALSE); cpl_test_eq_error(code, CPL_ERROR_NULL_INPUT); fits_close_file(fptr, &status); @@ -1670,7 +1703,7 @@ remove(BASE "_24.fits"); cpl_propertylist_empty(plist); - cpl_propertylist_append_string(plist,"ZTENSION", "COMPRESSED_EMPTY"); + cpl_propertylist_append_string(plist, "ZTENSION", "COMPRESSED_EMPTY"); cpl_propertylist_append_long(plist, "ZNAXIS", 2); cpl_propertylist_set_comment(plist, "ZNAXIS", "compressed NAXIS"); cpl_propertylist_append_long(plist, "ZNAXIS1", 2048); @@ -1688,7 +1721,7 @@ code = cpl_propertylist_save(plist, BASE "_24.fits", CPL_IO_EXTEND); cpl_test_eq_error(code, CPL_ERROR_NONE); cpl_test_fits(BASE "_24.fits"); -// cpl_propertylist_delete(plist); + // cpl_propertylist_delete(plist); /* primary header */ plist2 = cpl_propertylist_load(BASE "_24.fits", 0); @@ -1714,14 +1747,14 @@ cpl_propertylist_delete(plist); /* Check if compressed keywords were removed from headers*/ - plist = cpl_propertylist_load(BASE "_24.fits",1); + plist = cpl_propertylist_load(BASE "_24.fits", 1); cpl_test_zero(cpl_propertylist_has(plist, "ZTENSION")); cpl_test_zero(cpl_propertylist_has(plist, "ZNAXIS")); cpl_test_zero(cpl_propertylist_has(plist, "ZNAXIS1")); cpl_test_zero(cpl_propertylist_has(plist, "ZNAXIS2")); cpl_propertylist_delete(plist); - plist = cpl_propertylist_load(BASE "_24.fits",2); + plist = cpl_propertylist_load(BASE "_24.fits", 2); cpl_test_zero(cpl_propertylist_has(plist, "ZTENSION")); cpl_test_zero(cpl_propertylist_has(plist, "ZNAXIS")); cpl_test_zero(cpl_propertylist_has(plist, "ZNAXIS1")); @@ -1789,9 +1822,9 @@ cpl_test_zero(status); /* Create a completely blank card */ - syscode = system("perl -pi -e 's/(DELKEY += +.DELVALUE.)/" - "sprintf(\"%\".length($1).\"s\", \" \")/e' " - BASE "_26.fits"); + syscode = + system("perl -pi -e 's/(DELKEY += +.DELVALUE.)/" + "sprintf(\"%\".length($1).\"s\", \" \")/e' " BASE "_26.fits"); cpl_test_zero(syscode); /* Load cards with no letter in key, i.e. nine cards */ @@ -1815,65 +1848,66 @@ code = cpl_propertylist_append_property(plist, NULL); cpl_test_eq_error(code, CPL_ERROR_NULL_INPUT); - for(j = 0; j < 6; j++) { + for (j = 0; j < 6; j++) { char *name = cpl_sprintf("HIERARCH ESO TEST%d APPEND", j); cpl_property *p = cpl_property_new(name, CPL_TYPE_INT); cpl_free(name); cpl_test_nonnull(p); - cpl_test_zero(cpl_property_set_int(p, j+2)); + cpl_test_zero(cpl_property_set_int(p, j + 2)); cpl_test_zero(cpl_propertylist_append_property(plist, p)); cpl_property_delete(p); } - cpl_test_eq(cpl_propertylist_get_size(plist),6); - cpl_test_eq(cpl_propertylist_get_int(plist,"HIERARCH ESO TEST1 APPEND"),3); + cpl_test_eq(cpl_propertylist_get_size(plist), 6); + cpl_test_eq(cpl_propertylist_get_int(plist, "HIERARCH ESO TEST1 APPEND"), + 3); - /* + /* * Test 28: Prepend a property to a property list */ - /* Catch error code */ + /* Catch error code */ code = cpl_propertylist_prepend_property(plist, NULL); cpl_test_eq_error(code, CPL_ERROR_NULL_INPUT); - for(j = 0; j < 3; j++) { - char *name = cpl_sprintf("HIERARCH ESO TEST%d PREPEND",j); - cpl_property *p = cpl_property_new(name,CPL_TYPE_STRING); - cpl_free(name); + for (j = 0; j < 3; j++) { + char *name = cpl_sprintf("HIERARCH ESO TEST%d PREPEND", j); + cpl_property *p = cpl_property_new(name, CPL_TYPE_STRING); + cpl_free(name); cpl_test_nonnull(p); - cpl_test_zero(cpl_property_set_string(p,"test prepend")); - cpl_test_zero(cpl_propertylist_prepend_property(plist,p)); + cpl_test_zero(cpl_property_set_string(p, "test prepend")); + cpl_test_zero(cpl_propertylist_prepend_property(plist, p)); cpl_property_delete(p); } - cpl_test_eq(cpl_propertylist_get_size(plist),9); + cpl_test_eq(cpl_propertylist_get_size(plist), 9); - /* Test 29: Insert a property into a property list */ + /* Test 29: Insert a property into a property list */ code = cpl_propertylist_insert_property(plist, "HIERARCH ESO TEST0 APPEND", NULL); cpl_test_eq_error(code, CPL_ERROR_NULL_INPUT); - for(j = 0; j < 1; j++){ + for (j = 0; j < 1; j++) { const char *name = "HIERARCH ESO TEST0 APPEND"; cpl_property *p = cpl_property_new("INSERT1", CPL_TYPE_FLOAT); cpl_property *p1 = cpl_property_new("INSERT2", CPL_TYPE_FLOAT); cpl_test_nonnull(p); cpl_test_nonnull(p1); cpl_test_zero(cpl_property_set_float(p, 1.0)); - cpl_test_zero(cpl_propertylist_insert_property(plist,name,p)); + cpl_test_zero(cpl_propertylist_insert_property(plist, name, p)); cpl_test_zero(cpl_property_set_float(p1, 2.0)); - cpl_test_zero(cpl_propertylist_insert_after_property(plist,name,p1)); + cpl_test_zero(cpl_propertylist_insert_after_property(plist, name, p1)); cpl_property_delete(p); cpl_property_delete(p1); } - cpl_test_eq(cpl_propertylist_get_size(plist),11); + cpl_test_eq(cpl_propertylist_get_size(plist), 11); -// cpl_propertylist_dump(plist,stdout); + // cpl_propertylist_dump(plist,stdout); cpl_propertylist_delete(plist); @@ -1882,23 +1916,23 @@ */ plist = cpl_propertylist_new(); - cpl_test_zero(cpl_propertylist_update_string(plist,"C","String")); - cpl_test_zero(cpl_propertylist_update_int(plist,"I",8)); + cpl_test_zero(cpl_propertylist_update_string(plist, "C", "String")); + cpl_test_zero(cpl_propertylist_update_int(plist, "I", 8)); f0 = 235.89; - cpl_test_zero(cpl_propertylist_update_float(plist,"F",f0)); + cpl_test_zero(cpl_propertylist_update_float(plist, "F", f0)); d0 = 1234.9994048; - cpl_test_zero(cpl_propertylist_update_double(plist,"D",d0)); - cpl_test_zero(cpl_propertylist_save(plist,BASE "_30.fits",CPL_IO_CREATE)); + cpl_test_zero(cpl_propertylist_update_double(plist, "D", d0)); + cpl_test_zero(cpl_propertylist_save(plist, BASE "_30.fits", CPL_IO_CREATE)); cpl_test_fits(BASE "_30.fits"); cpl_propertylist_delete(plist); - plist = cpl_propertylist_load(BASE "_30.fits",0); + plist = cpl_propertylist_load(BASE "_30.fits", 0); cpl_test_nonnull(plist); /* The float keyword is casted to double when loaded from disk */ - t1 = cpl_propertylist_get_type(plist,"F"); - cpl_test_eq(t1,CPL_TYPE_DOUBLE); + t1 = cpl_propertylist_get_type(plist, "F"); + cpl_test_eq(t1, CPL_TYPE_DOUBLE); /* Test that the casting in cpl works */ f1 = cpl_propertylist_get_float(plist, "F"); @@ -1907,7 +1941,7 @@ d1 = cpl_propertylist_get_double(plist, "F"); cpl_test_error(CPL_ERROR_NONE); - f2 = cpl_propertylist_get_float(plist,"D"); + f2 = cpl_propertylist_get_float(plist, "D"); cpl_test_error(CPL_ERROR_NONE); d2 = cpl_propertylist_get_double(plist, "D"); @@ -1963,12 +1997,12 @@ code = cpl_propertylist_set_string(plist, keys[6], NULL); cpl_test_eq_error(CPL_ERROR_NULL_INPUT, code); - code = cpl_propertylist_insert_string(plist, keys[6], keys[6 + nprops], - NULL); + code = + cpl_propertylist_insert_string(plist, keys[6], keys[6 + nprops], NULL); cpl_test_eq_error(CPL_ERROR_NULL_INPUT, code); code = cpl_propertylist_insert_after_string(plist, keys[6], - keys[6 + nprops], NULL); + keys[6 + nprops], NULL); cpl_test_eq_error(CPL_ERROR_NULL_INPUT, code); code = cpl_propertylist_prepend_string(plist, keys[6], NULL); @@ -1994,7 +2028,8 @@ /* Create a card with an undefined value (FITS std. 4.2.1 1) */ code = cpl_propertylist_append_string(plist, "DELKEY1", "DELVALUE"); cpl_test_eq_error(code, CPL_ERROR_NONE); - code = cpl_propertylist_set_comment(plist, "DELKEY1", "Undefined value" + code = cpl_propertylist_set_comment(plist, "DELKEY1", + "Undefined value" " - also for the next card..."); cpl_test_eq_error(code, CPL_ERROR_NONE); @@ -2016,21 +2051,27 @@ code = cpl_propertylist_append_int(plist, " ", 77777); cpl_test_eq_error(code, CPL_ERROR_NONE); - /* This key is at its maximum length, */ - code = cpl_propertylist_append_double(plist, "HIERARCH ESO " + /* The below keys are at their maximum length, */ + code = cpl_propertylist_append_double(plist, + "HIERARCH ESO " "ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ " "ABCDEFGHIJ ABCDEFGHIJ AB", 1.23E-45); cpl_test_eq_error(code, CPL_ERROR_NONE); code = cpl_propertylist_save(plist, BASE "_34.fits", CPL_IO_CREATE); + + /* Need to close file due to non CPL access */ + cpl_test_zero(cpl_io_fits_close(BASE "_34.fits", &status)); + cpl_test_zero(status); cpl_test_fits(BASE "_34.fits"); syscode = system("perl -pi -e 's/(DELKEY. +=)( +.DELVALUE.)/" "sprintf(\"$1%\".length($2).\"s\", \" \")/eg;" - "s/1.23E-45/1.23D-45/i;' " - BASE "_34.fits"); + "s/1.23E-45/1.23D-45/i;' " BASE "_34.fits"); + cpl_test_zero(syscode); + cpl_test_fits(BASE "_34.fits"); plist2 = cpl_propertylist_load(BASE "_34.fits", 0); cpl_test_eq_error(code, CPL_ERROR_NONE); @@ -2042,7 +2083,7 @@ if (strval != NULL) { /* The FITS quote-encoding means that only half make it into the card */ value = strlen(strval); - cpl_test_eq(value, (FLEN_VALUE)/2 - 1); + cpl_test_eq(value, (FLEN_VALUE) / 2 - 1); cpl_test_zero(memcmp(strval, stringarray, value)); } @@ -2055,7 +2096,7 @@ if (strval != NULL) { /* The FITS HISTORY card should keep its not-a-value indicator */ - const char * start; + const char *start; value = strlen(strval); cpl_test_leq(7, value); cpl_test_zero(memcmp(strval, "= ", 2)); @@ -2065,13 +2106,67 @@ cpl_test_eq(*(start + 5), '\0'); } - dval1 = cpl_propertylist_get_double(plist, "HIERARCH ESO " - "ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ " - "ABCDEFGHIJ ABCDEFGHIJ AB"); + dval1 = + cpl_propertylist_get_double(plist, "HIERARCH ESO " + "ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ " + "ABCDEFGHIJ ABCDEFGHIJ AB"); cpl_test_error(CPL_ERROR_NONE); cpl_test_rel(dval1, 1.23E-45, 0.001); - cpl_propertylist_test_numeric_load_bad(); +#undef MYTEST +#define MYTEST 39 + +#undef MYFILE +#define MYFILE FILENAME(MYTEST) + + cpl_propertylist_empty(plist); + /* This key exceeds the maximum length by 1 */ + code = cpl_propertylist_append_double(plist, + "HIERARCH ESO " + "ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ " + "ABCDEFGHIJ ABCDEFGHIJ ABC", + 1.23E-45); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + code = cpl_propertylist_save(plist, MYFILE, CPL_IO_CREATE); + cpl_test_eq_error(code, CPL_ERROR_ILLEGAL_INPUT); + +#undef MYTEST +#define MYTEST 39 + +#undef MYFILE +#define MYFILE FILENAME(MYTEST) + + cpl_propertylist_empty(plist); + /* This key exceeds the maximum length by 1 */ + code = cpl_propertylist_append_double(plist, + "ESO " + "ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ " + "ABCDEFGHIJ ABCDEFGHIJ ABC", + 1.23E-45); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + code = cpl_propertylist_save(plist, MYFILE, CPL_IO_CREATE); + cpl_test_eq_error(code, CPL_ERROR_ILLEGAL_INPUT); + +#undef MYTEST +#define MYTEST 39 + +#undef MYFILE +#define MYFILE FILENAME(MYTEST) + + cpl_propertylist_empty(plist); + /* This key exceeds the maximum length by 1 */ + code = cpl_propertylist_append_double(plist, + "ESA " + "ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ " + "ABCDEFGHIJ ABCDEFGHIJ ABC", + 1.23E-45); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + code = cpl_propertylist_save(plist, MYFILE, CPL_IO_CREATE); + cpl_test_eq_error(code, CPL_ERROR_ILLEGAL_INPUT); + #undef MYTEST #define MYTEST 42 @@ -2110,8 +2205,8 @@ cpl_propertylist_empty(plist); /* This floating point value cannot be saved */ - code = cpl_propertylist_append_double_complex(plist, "BADFLOAT", - badval); + code = + cpl_propertylist_append_double_complex(plist, "BADFLOAT", badval); cpl_test_eq_error(code, CPL_ERROR_NONE); code = cpl_propertylist_save(plist, MYFILE, CPL_IO_CREATE); @@ -2122,12 +2217,17 @@ cpl_propertylist_delete(plist); cpl_propertylist_delete(plist2); + cpl_propertylist_test_numeric_load_bad(); + cpl_propertylist_test_load_bad_key(); + cpl_propertylist_test_full_card(); + cpl_propertylist_test_too_long_card(); + /* * All tests done */ - if (stream != stdout) cpl_test_zero( fclose(stream) ); - + if (stream != stdout) + cpl_test_zero(fclose(stream)); } @@ -2142,19 +2242,19 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_propertylist_compare(const cpl_propertylist * plist1, - const cpl_propertylist * plist2) +static void +cpl_propertylist_compare(const cpl_propertylist *plist1, + const cpl_propertylist *plist2) { - const cpl_size sz1 = cpl_propertylist_get_size(plist1); const cpl_size sz2 = cpl_propertylist_get_size(plist2); for (cpl_size j = 0; j < sz1; j++) { - const cpl_size nfailed = cpl_test_get_failed(); - const cpl_property *p1 = cpl_propertylist_get_const(plist1, j); - const char *name = cpl_property_get_name(p1); - const cpl_property *p2 = + const cpl_size nfailed = cpl_test_get_failed(); + const cpl_property *p1 = cpl_propertylist_get_const(plist1, j); + const char *name = cpl_property_get_name(p1); + const cpl_property *p2 = cpl_propertylist_get_property_const(plist2, name); cpl_test_error(CPL_ERROR_NONE); @@ -2165,19 +2265,19 @@ } if (cpl_test_get_failed() != nfailed) { - cpl_msg_warning(cpl_func, "FAILED(%d/%d<=>%d): %s", - (int)j, (int)sz1, (int)sz2, name); + cpl_msg_warning(cpl_func, "FAILED(%d/%d<=>%d): %s", (int)j, + (int)sz1, (int)sz2, name); } } } -static void cpl_property_eq(const cpl_property * self, - const cpl_property * other) +static void +cpl_property_eq(const cpl_property *self, const cpl_property *other) { const cpl_size nfailed = cpl_test_get_failed(); - const char * name1 = cpl_property_get_name(self); - const char * name2 = cpl_property_get_name(other); + const char *name1 = cpl_property_get_name(self); + const char *name2 = cpl_property_get_name(other); cpl_test_error(CPL_ERROR_NONE); @@ -2185,7 +2285,6 @@ cpl_test_nonnull(name2); if (cpl_test_get_failed() == nfailed) { - cpl_test_eq_string(name1, name2); if (cpl_test_get_failed() == nfailed) { @@ -2196,86 +2295,86 @@ if (cpl_test_get_failed() == nfailed) { switch (t1) { - case CPL_TYPE_BOOL: { - const int v1 = cpl_property_get_bool(self); - const int v2 = cpl_property_get_bool(other); - cpl_test_eq(v1, v2); - break; - } - case CPL_TYPE_CHAR: { - const char v1 = cpl_property_get_char(self); - const char v2 = cpl_property_get_char(other); - cpl_test_eq(v1, v2); - break; - } - case CPL_TYPE_INT: { - const int v1 = cpl_property_get_int(self); - const int v2 = cpl_property_get_int(other); - cpl_test_eq(v1, v2); - break; - } - case CPL_TYPE_LONG: { - const long v1 = cpl_property_get_long(self); - const long v2 = cpl_property_get_long(other); - cpl_test_eq(v1, v2); - break; - } - case CPL_TYPE_LONG_LONG: { - const long long v1 = cpl_property_get_long_long(self); - const long long v2 = cpl_property_get_long_long(other); - cpl_test_eq(v1, v2); - break; - } - case CPL_TYPE_FLOAT: { - const float v1 = cpl_property_get_float(self); - const float v2 = cpl_property_get_float(other); - cpl_test_rel(v1, v2, FLT_EPSILON * 4.0); - break; - } - case CPL_TYPE_DOUBLE: { - const double v1 = cpl_property_get_double(self); - const double v2 = cpl_property_get_double(other); - cpl_test_rel(v1, v2, DBL_EPSILON * 12.0); - break; - } - case CPL_TYPE_STRING: { - const char * v1 = cpl_property_get_string(self); - const char * v2 = cpl_property_get_string(other); + case CPL_TYPE_BOOL: { + const int v1 = cpl_property_get_bool(self); + const int v2 = cpl_property_get_bool(other); + cpl_test_eq(v1, v2); + break; + } + case CPL_TYPE_CHAR: { + const char v1 = cpl_property_get_char(self); + const char v2 = cpl_property_get_char(other); + cpl_test_eq(v1, v2); + break; + } + case CPL_TYPE_INT: { + const int v1 = cpl_property_get_int(self); + const int v2 = cpl_property_get_int(other); + cpl_test_eq(v1, v2); + break; + } + case CPL_TYPE_LONG: { + const long v1 = cpl_property_get_long(self); + const long v2 = cpl_property_get_long(other); + cpl_test_eq(v1, v2); + break; + } + case CPL_TYPE_LONG_LONG: { + const long long v1 = cpl_property_get_long_long(self); + const long long v2 = cpl_property_get_long_long(other); + cpl_test_eq(v1, v2); + break; + } + case CPL_TYPE_FLOAT: { + const float v1 = cpl_property_get_float(self); + const float v2 = cpl_property_get_float(other); + cpl_test_rel(v1, v2, FLT_EPSILON * 4.0); + break; + } + case CPL_TYPE_DOUBLE: { + const double v1 = cpl_property_get_double(self); + const double v2 = cpl_property_get_double(other); + cpl_test_rel(v1, v2, DBL_EPSILON * 12.0); + break; + } + case CPL_TYPE_STRING: { + const char *v1 = cpl_property_get_string(self); + const char *v2 = cpl_property_get_string(other); + + cpl_test_eq_string(v1, v2); + break; + } + case CPL_TYPE_DOUBLE_COMPLEX: { + const double complex v1 = + cpl_property_get_double_complex(self); + const double complex v2 = + cpl_property_get_double_complex(other); + const double v1r = creal(v1); + const double v2r = creal(v2); + const double v1i = cimag(v1); + const double v2i = cimag(v2); + + cpl_test_rel(v1r, v2r, DBL_EPSILON * 4.0); + cpl_test_rel(v1i, v2i, DBL_EPSILON * 4.0); + break; + } + case CPL_TYPE_FLOAT_COMPLEX: { + const float complex v1 = + cpl_property_get_float_complex(self); + const float complex v2 = + cpl_property_get_float_complex(other); + const float v1r = crealf(v1); + const float v2r = crealf(v2); + const float v1i = cimagf(v1); + const float v2i = cimagf(v2); + + cpl_test_rel(v1r, v2r, FLT_EPSILON * 4.0); + cpl_test_rel(v1i, v2i, FLT_EPSILON * 4.0); + break; + } - cpl_test_eq_string(v1, v2); - break; - } - case CPL_TYPE_DOUBLE_COMPLEX: { - const double complex v1 = - cpl_property_get_double_complex(self); - const double complex v2 = - cpl_property_get_double_complex(other); - const double v1r = creal(v1); - const double v2r = creal(v2); - const double v1i = cimag(v1); - const double v2i = cimag(v2); - - cpl_test_rel(v1r, v2r, DBL_EPSILON * 4.0); - cpl_test_rel(v1i, v2i, DBL_EPSILON * 4.0); - break; - } - case CPL_TYPE_FLOAT_COMPLEX: { - const float complex v1 = - cpl_property_get_float_complex(self); - const float complex v2 = - cpl_property_get_float_complex(other); - const float v1r = crealf(v1); - const float v2r = crealf(v2); - const float v1i = cimagf(v1); - const float v2i = cimagf(v2); - - cpl_test_rel(v1r, v2r, FLT_EPSILON * 4.0); - cpl_test_rel(v1i, v2i, FLT_EPSILON * 4.0); - break; - } - - default: - break; + default: + break; } } } @@ -2296,16 +2395,13 @@ */ /*----------------------------------------------------------------------------*/ -static int cpl_test_property_compare_name( - const cpl_property * p1, - const cpl_property * p2) +static int +cpl_test_property_compare_name(const cpl_property *p1, const cpl_property *p2) { - /* * Compare the two properties */ - return strcmp(cpl_property_get_name(p1), - cpl_property_get_name(p2)); + return strcmp(cpl_property_get_name(p1), cpl_property_get_name(p2)); } #undef MYTEST @@ -2322,26 +2418,53 @@ @internal @brief Load the headers of the named file - */ /*----------------------------------------------------------------------------*/ -static void cpl_propertylist_test_file(const char * filename, cpl_size *pmaxsz) +static void +cpl_propertylist_test_file(const char *filename, + cpl_size *pmaxsz, + cpl_boolean is_valid) { - const cpl_size nhdu = cpl_fits_count_extensions(filename); - - cpl_msg_info(cpl_func, "Test using %d header(s) from %s", - (int)nhdu, filename); + const cpl_errorstate prevstate = cpl_errorstate_get(); + const cpl_size nhdu = 1 + cpl_fits_count_extensions(filename); + cpl_size dohdu = nhdu; + + if (!is_valid) { + cpl_errorstate_dump(prevstate, CPL_FALSE, cpl_errorstate_dump_one_info); + cpl_errorstate_set(prevstate); + if (nhdu > 1) { + cpl_msg_warning(cpl_func, + "Limiting test of invalid, multi (%d) " + "extension file %s to primary header", + (int)nhdu, filename); + dohdu = 1; + } + cpl_msg_warning(cpl_func, "Testing invalid file with no extensions %s", + filename); + } + else { + cpl_msg_info(cpl_func, "Testing %d header(s) from %s", (int)nhdu, + filename); + } - for (cpl_size ihdu = 0; ihdu < nhdu; ihdu++) { - const cxchar *badkeys = ihdu ? /* Copied from cpl_propertylist_save() */ - CPL_FITS_BADKEYS_EXT "|" CPL_FITS_COMPRKEYS "|" CPL_TEST_FITS_IGNORE: - CPL_FITS_BADKEYS_PRIM "|" CPL_FITS_COMPRKEYS "|" CPL_TEST_FITS_IGNORE; + for (cpl_size ihdu = 0; ihdu < dohdu; ihdu++) { + const cxchar *badkeys = + ihdu ? /* Copied from cpl_propertylist_save() */ + CPL_FITS_BADKEYS_EXT "|" CPL_FITS_COMPRKEYS + "|" CPL_TEST_FITS_IGNORE + : CPL_FITS_BADKEYS_PRIM "|" CPL_FITS_COMPRKEYS + "|" CPL_TEST_FITS_IGNORE; /* Test that the header can be loaded */ cpl_propertylist *plist1 = cpl_propertylist_load(filename, ihdu); cpl_propertylist *plist2; - cpl_size sz1, sz2; - cpl_error_code code; + cpl_size sz1, sz2; + cpl_error_code code; + + if (plist1 == NULL) { + cpl_test_error(CPL_ERROR_BAD_FILE_FORMAT); + continue; + } cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(plist1); @@ -2367,7 +2490,15 @@ ihdu ? CPL_IO_EXTEND : CPL_IO_CREATE); cpl_test_eq_error(code, CPL_ERROR_NONE); - cpl_test_fits(MYFILE); + if (is_valid) { + cpl_test_fits(MYFILE); + } + else { + cpl_msg_warning(cpl_func, + "Skipping validation of extension %d of " + "invalid '%s'", + (int)ihdu, MYFILE); + } /* Test that the reduced header can be loaded */ plist2 = cpl_propertylist_load(MYFILE, ihdu); @@ -2387,11 +2518,13 @@ const cpl_size nfailed = cpl_test_get_failed(); cpl_propertylist_compare(plist2, plist1); if (cpl_test_get_failed() == nfailed) { - cpl_msg_warning(cpl_func, "Header %d seemingly has %d non-" - "unique card(s): %s", (int)ihdu, - (int)(sz1 - sz2), filename); + cpl_msg_warning(cpl_func, + "Header %d seemingly has %d non-" + "unique card(s): %s", + (int)ihdu, (int)(sz1 - sz2), filename); } - } else { + } + else { cpl_test_eq(sz1, sz2); } @@ -2415,7 +2548,8 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_propertylist_test_numeric_type(void) +static void +cpl_propertylist_test_numeric_type(void) { const char *keys[] = { "EQUINOX", @@ -2445,17 +2579,38 @@ "PV3_3", /* The below keys may not actually be valid, but fitsverify accepts them */ - "CRPIX001", - "CRVAL002", - "CDELT003", + /* Key length 6 */ + "CRPIX0", + "CRVAL0", + "CDELT0", "PC01_1", "PV01_1", "PC1_01", "PV1_01", - "PC01_01", + /* Key length 7 */ + "CRPIX01", + "CRVAL02", + "CDELT03", + "PV1_001", "PV01_01", - "PC1_01", + "PC01_01", + "PV001_1", + /* Key length 8 */ + "CRPIX001", + "CRVAL002", + "CDELT003", "PV1_0001", + "PC1_0001", + "PC01_001", + "PC001_01", + "PC0001_1", + /* The below keys are not actually valid, + causing fitsverify to issue a warning */ + "CRPIX999", + "CRPIX099", + "CRPIX000", + "CRPIX00", + "CRPIX0", }; const cpl_size nkeys = (cpl_size)CX_N_ELEMENTS(keys); @@ -2463,13 +2618,14 @@ cpl_propertylist *plist = cpl_propertylist_new(); cpl_size nkeys2; cpl_error_code code; - cpl_imagelist * imlist = cpl_imagelist_new(); - cpl_image * img = cpl_image_new(1, 1, CPL_TYPE_INT); + cpl_imagelist *imlist = cpl_imagelist_new(); + cpl_image *img = cpl_image_new(1, 1, CPL_TYPE_INT); const long long neglong = -9223372036854775807LL; /* LLONG_MIN */ - const long long poslong = 9223372036854775807LL; /* LLONG_MAX */ - const int bigint = 2147483647; /* (2<<31) - 1 */ + const long long poslong = 9223372036854775807LL; /* LLONG_MAX */ + const int bigint = 2147483647; /* (2<<31) - 1 */ int ival; long long lval; + int status = 0; int syscode; code = cpl_imagelist_set(imlist, img, 0); @@ -2516,10 +2672,10 @@ cpl_test_leq(nkeys, nkeys2); for (cpl_size i = 0; i < nkeys; i++) { - const cpl_property * p = cpl_propertylist_get_property_const(plist, - keys[i]); + const cpl_property *p = + cpl_propertylist_get_property_const(plist, keys[i]); const cpl_type type = cpl_property_get_type(p); - const char * name = cpl_property_get_name(p); + const char *name = cpl_property_get_name(p); cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(p); @@ -2533,7 +2689,8 @@ lval = cpl_propertylist_get_long(plist, "NEGLONG"); if (cpl_error_get_code()) { cpl_test_error(CPL_ERROR_TYPE_MISMATCH); - } else { + } + else { cpl_test_eq(lval, neglong); } @@ -2544,7 +2701,8 @@ lval = cpl_propertylist_get_long(plist, "POSLONG"); if (cpl_error_get_code()) { cpl_test_error(CPL_ERROR_TYPE_MISMATCH); - } else { + } + else { cpl_test_eq(lval, poslong); } @@ -2569,6 +2727,10 @@ cpl_propertylist_delete(plist); + /* Need to close file due to non CPL access */ + cpl_test_zero(cpl_io_fits_close(BASE "_32.fits", &status)); + cpl_test_zero(status); + /* EPOCH is deprecated, so rename it before validating file */ syscode = system("perl -pi -e 's/EPOCH /ESOCH /' " BASE "_32.fits"); if (!syscode) { @@ -2590,174 +2752,213 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_propertylist_test_numeric_load_ok(void) +static void +cpl_propertylist_test_numeric_load_ok(void) { - struct numerical { + struct numerical + { const char *number; cpl_type type; double expected; }; struct numerical okval[] = { - {"+000000000000", CPL_TYPE_INT, 0}, - {"-000000000000", CPL_TYPE_INT, 0}, - {".000000000000", CPL_TYPE_DOUBLE, 0}, - {"+0000000000000.", CPL_TYPE_DOUBLE, 0}, - {"-0000000000000.", CPL_TYPE_DOUBLE, 0}, - {"+0000000000000.00000000000000000000000000", CPL_TYPE_DOUBLE, 0}, - {"-0000000000000.00000000000000000000000000", CPL_TYPE_DOUBLE, 0}, + { "+000000000000", CPL_TYPE_INT, 0 }, + { "-000000000000", CPL_TYPE_INT, 0 }, + { ".000000000000", CPL_TYPE_DOUBLE, 0 }, + { "+0000000000000.", CPL_TYPE_DOUBLE, 0 }, + { "-0000000000000.", CPL_TYPE_DOUBLE, 0 }, + { "+0000000000000.50000000000000000000000000", CPL_TYPE_DOUBLE, .5 }, + { "-0000000000000.50000000000000000000000000", CPL_TYPE_DOUBLE, -.5 }, /* Floating-point constants that are FITS and C89 compliant */ - {"+0000000000000.0000000000000000000000E000", CPL_TYPE_DOUBLE, 0}, - {"-0000000000000.0000000000000000000000E000", CPL_TYPE_DOUBLE, 0}, - {"+0000000000000.0000000000000000000000E-00", CPL_TYPE_DOUBLE, 0}, - {"-0000000000000.0000000000000000000000E-00", CPL_TYPE_DOUBLE, 0}, - {"+0000000000000.0000000000000000000000E+00", CPL_TYPE_DOUBLE, 0}, - {"-0000000000000.0000000000000000000000E+00", CPL_TYPE_DOUBLE, 0}, - - {"+0000000000000.0000000000000000000000E099", CPL_TYPE_DOUBLE, 0}, - {"-0000000000000.0000000000000000000000E099", CPL_TYPE_DOUBLE, 0}, - {"+0000000000000.0000000000000000000000E-99", CPL_TYPE_DOUBLE, 0}, - {"-0000000000000.0000000000000000000000E-99", CPL_TYPE_DOUBLE, 0}, - {"+0000000000000.0000000000000000000000E+99", CPL_TYPE_DOUBLE, 0}, - {"-0000000000000.0000000000000000000000E+99", CPL_TYPE_DOUBLE, 0}, + { "+.50000000000000000000000000000000000E000", CPL_TYPE_DOUBLE, .5 }, + { "-.50000000000000000000000000000000000E000", CPL_TYPE_DOUBLE, -.5 }, + { "+0000000000000.5000000000000000000000E000", CPL_TYPE_DOUBLE, .5 }, + { "-0000000000000.5000000000000000000000E000", CPL_TYPE_DOUBLE, -.5 }, + { "+0000000000000.5000000000000000000000E000", CPL_TYPE_DOUBLE, .5 }, + { "-0000000000000.5000000000000000000000E000", CPL_TYPE_DOUBLE, -.5 }, + { "+0000000000000.5000000000000000000000E-00", CPL_TYPE_DOUBLE, .5 }, + { "-0000000000000.5000000000000000000000E-00", CPL_TYPE_DOUBLE, -.5 }, + { "+0000000000000.5000000000000000000000E+00", CPL_TYPE_DOUBLE, .5 }, + { "-0000000000000.5000000000000000000000E+00", CPL_TYPE_DOUBLE, -.5 }, + + { "+0000000000000.0000000000000000000000E099", CPL_TYPE_DOUBLE, 0 }, + { "-0000000000000.0000000000000000000000E099", CPL_TYPE_DOUBLE, 0 }, + { "+0000000000000.0000000000000000000000E-99", CPL_TYPE_DOUBLE, 0 }, + { "-0000000000000.0000000000000000000000E-99", CPL_TYPE_DOUBLE, 0 }, + { "+0000000000000.0000000000000000000000E+99", CPL_TYPE_DOUBLE, 0 }, + { "-0000000000000.0000000000000000000000E+99", CPL_TYPE_DOUBLE, 0 }, /* Floating-point constants that are FITS, but not C89 compliant */ - {"+0000000000000.0000000000000000000000D000", CPL_TYPE_DOUBLE, 0}, - {"-0000000000000.0000000000000000000000D000", CPL_TYPE_DOUBLE, 0}, - {"+0000000000000.0000000000000000000000D-00", CPL_TYPE_DOUBLE, 0}, - {"-0000000000000.0000000000000000000000D-00", CPL_TYPE_DOUBLE, 0}, - {"+0000000000000.0000000000000000000000D+00", CPL_TYPE_DOUBLE, 0}, - {"-0000000000000.0000000000000000000000D+00", CPL_TYPE_DOUBLE, 0}, - - {"+0000000000000.0000000000000000000000D099", CPL_TYPE_DOUBLE, 0}, - {"-0000000000000.0000000000000000000000D099", CPL_TYPE_DOUBLE, 0}, - {"+0000000000000.0000000000000000000000D-99", CPL_TYPE_DOUBLE, 0}, - {"-0000000000000.0000000000000000000000D-99", CPL_TYPE_DOUBLE, 0}, - {"+0000000000000.0000000000000000000000D+99", CPL_TYPE_DOUBLE, 0}, - {"-0000000000000.0000000000000000000000D+99", CPL_TYPE_DOUBLE, 0}, + { "+0000000000000.5000000000000000000000000/", CPL_TYPE_DOUBLE, .5 }, + { "-0000000000000.5000000000000000000000000/", CPL_TYPE_DOUBLE, -.5 }, + { "+0000000000000.5000000000000000000000D000", CPL_TYPE_DOUBLE, .5 }, + { "-0000000000000.5000000000000000000000D000", CPL_TYPE_DOUBLE, -.5 }, + { "+0000000000000.5000000000000000000000D-00", CPL_TYPE_DOUBLE, .5 }, + { "-0000000000000.5000000000000000000000D-00", CPL_TYPE_DOUBLE, -.5 }, + { "+0000000000000.5000000000000000000000D+00", CPL_TYPE_DOUBLE, .5 }, + { "-0000000000000.5000000000000000000000D+00", CPL_TYPE_DOUBLE, -.5 }, + + { "+0000000000000.0000000000000000000000D099", CPL_TYPE_DOUBLE, 0 }, + { "-0000000000000.0000000000000000000000D099", CPL_TYPE_DOUBLE, 0 }, + { "+0000000000000.0000000000000000000000D-99", CPL_TYPE_DOUBLE, 0 }, + { "-0000000000000.0000000000000000000000D-99", CPL_TYPE_DOUBLE, 0 }, + { "+0000000000000.0000000000000000000000D+99", CPL_TYPE_DOUBLE, 0 }, + { "-0000000000000.0000000000000000000000D+99", CPL_TYPE_DOUBLE, 0 }, /* Floating-point constants that are not FITS (!!!) but C89 compliant */ - {"+0000000000000.0000000000000000000000e000", CPL_TYPE_DOUBLE, 0}, - {"-0000000000000.0000000000000000000000e000", CPL_TYPE_DOUBLE, 0}, - {"+0000000000000.0000000000000000000000e-00", CPL_TYPE_DOUBLE, 0}, - {"-0000000000000.0000000000000000000000e-00", CPL_TYPE_DOUBLE, 0}, - {"+0000000000000.0000000000000000000000e+00", CPL_TYPE_DOUBLE, 0}, - {"-0000000000000.0000000000000000000000e+00", CPL_TYPE_DOUBLE, 0}, - - {"+0000000000000.0000000000000000000000e099", CPL_TYPE_DOUBLE, 0}, - {"-0000000000000.0000000000000000000000e099", CPL_TYPE_DOUBLE, 0}, - {"+0000000000000.0000000000000000000000e-99", CPL_TYPE_DOUBLE, 0}, - {"-0000000000000.0000000000000000000000e-99", CPL_TYPE_DOUBLE, 0}, - {"+0000000000000.0000000000000000000000e+99", CPL_TYPE_DOUBLE, 0}, - {"-0000000000000.0000000000000000000000e+99", CPL_TYPE_DOUBLE, 0}, - - {"( 0, 0)", CPL_TYPE_DOUBLE_COMPLEX, 0}, - {"( +0, +0)", CPL_TYPE_DOUBLE_COMPLEX, 0}, - {"( -0, -0)", CPL_TYPE_DOUBLE_COMPLEX, 0}, - {"( -0E0, -0E0)", CPL_TYPE_DOUBLE_COMPLEX, 0}, - {"( -0D0, -0E1)", CPL_TYPE_DOUBLE_COMPLEX, 0}, - {"(-0000000D0, -0E1)", CPL_TYPE_DOUBLE_COMPLEX, 0}, - {"(-0000000D0,+000000E1)", CPL_TYPE_DOUBLE_COMPLEX, 0}, + { "+0000000000000.5000000000000000000000e000", CPL_TYPE_DOUBLE, .5 }, + { "-0000000000000.5000000000000000000000e000", CPL_TYPE_DOUBLE, -.5 }, + { "+0000000000000.5000000000000000000000e-00", CPL_TYPE_DOUBLE, .5 }, + { "-0000000000000.5000000000000000000000e-00", CPL_TYPE_DOUBLE, -.5 }, + { "+0000000000000.5000000000000000000000e+00", CPL_TYPE_DOUBLE, .5 }, + { "-0000000000000.5000000000000000000000e+00", CPL_TYPE_DOUBLE, -.5 }, + + { "+0000000000000.0000000000000000000000e099", CPL_TYPE_DOUBLE, 0 }, + { "-0000000000000.0000000000000000000000e099", CPL_TYPE_DOUBLE, 0 }, + { "+0000000000000.0000000000000000000000e-99", CPL_TYPE_DOUBLE, 0 }, + { "-0000000000000.0000000000000000000000e-99", CPL_TYPE_DOUBLE, 0 }, + { "+0000000000000.0000000000000000000000e+99", CPL_TYPE_DOUBLE, 0 }, + { "-0000000000000.0000000000000000000000e+99", CPL_TYPE_DOUBLE, 0 }, + + { "( 0, 0)", CPL_TYPE_DOUBLE_COMPLEX, 0 }, + { "( +0, +0)", CPL_TYPE_DOUBLE_COMPLEX, 0 }, + { "( -0, -0)", CPL_TYPE_DOUBLE_COMPLEX, 0 }, + { "( -0E0, -0E0)", CPL_TYPE_DOUBLE_COMPLEX, 0 }, + { "( -0D0, -0E1)", CPL_TYPE_DOUBLE_COMPLEX, 0 }, + { "(-0000000D0, -0E1)", CPL_TYPE_DOUBLE_COMPLEX, 0 }, + { "(-0000000D0,+000000E1)", CPL_TYPE_DOUBLE_COMPLEX, 0 }, /* Can only set up tests with an expected value of type double... */ - {"( 420, 0)", CPL_TYPE_DOUBLE_COMPLEX, 420}, - {"(0420,0000)", CPL_TYPE_DOUBLE_COMPLEX, 420}, - {"(042E1,+0000)", CPL_TYPE_DOUBLE_COMPLEX, 420}, - {"(0.42E3,+0000E22)", CPL_TYPE_DOUBLE_COMPLEX, 420}, - {"(+0.000042E7,+0000E22)", CPL_TYPE_DOUBLE_COMPLEX, 420}, - {"(.000042E7,+0000E22)", CPL_TYPE_DOUBLE_COMPLEX, 420}, - {"(-00042E1,+0000E22)", CPL_TYPE_DOUBLE_COMPLEX, -420}, + { "( 420, 0)", CPL_TYPE_DOUBLE_COMPLEX, 420 }, + { "(0420,0000)", CPL_TYPE_DOUBLE_COMPLEX, 420 }, + { "(042E1,+0000)", CPL_TYPE_DOUBLE_COMPLEX, 420 }, + { "(0.42E3,+0000E22)", CPL_TYPE_DOUBLE_COMPLEX, 420 }, + { "(+0.000042E7,+0000E22)", CPL_TYPE_DOUBLE_COMPLEX, 420 }, + { "(.000042E7,+0000E22)", CPL_TYPE_DOUBLE_COMPLEX, 420 }, + { "(-00042E1,+0000E22)", CPL_TYPE_DOUBLE_COMPLEX, -420 }, /* Floating-point constants that are FITS and C89 compliant */ - {"00000000000000000000000000000000000000420", CPL_TYPE_INT, 420}, - {"+0000000000000000000000000000000000000420", CPL_TYPE_INT, 420}, - {"00000000000000000000000000000000000000420.", CPL_TYPE_DOUBLE, 420}, - {"+0000000000000000000000000000000000000420.", CPL_TYPE_DOUBLE, 420}, - {"00000000000000000000000000000000000000420E0", CPL_TYPE_DOUBLE, 420}, - {"+0000000000000000000000000000000000000420E0", CPL_TYPE_DOUBLE, 420}, - {"00000000000000000000000000000000000000420E-0", CPL_TYPE_DOUBLE, 420}, - {"+0000000000000000000000000000000000000420E-0", CPL_TYPE_DOUBLE, 420}, - {"00000000000000000000000000000000000000420E+0", CPL_TYPE_DOUBLE, 420}, - {"+0000000000000000000000000000000000000420E+0", CPL_TYPE_DOUBLE, 420}, - - {"0000000000000000000000000000000000000042E1", CPL_TYPE_DOUBLE, 420}, - {"+000000000000000000000000000000000000042E1", CPL_TYPE_DOUBLE, 420}, - {"0000000000000000000000000000000000004200E-1", CPL_TYPE_DOUBLE, 420}, - {"+000000000000000000000000000000000004200E-1", CPL_TYPE_DOUBLE, 420}, - {"0000000000000000000000000000000000000042E+1", CPL_TYPE_DOUBLE, 420}, - {"+000000000000000000000000000000000000042E+1", CPL_TYPE_DOUBLE, 420}, - - {"000000000000000000000000000004200000000E-7", CPL_TYPE_DOUBLE, 420}, - {"+00000000000000000000000000004200000000E-7", CPL_TYPE_DOUBLE, 420}, - {"000000000000000000000000000004200000000E-07", CPL_TYPE_DOUBLE, 420}, - {"+00000000000000000000000000004200000000E-07", CPL_TYPE_DOUBLE, 420}, - {"0000000000000000000000000000000000.000042E+7", CPL_TYPE_DOUBLE, 420}, - {"+000000000000000000000000000000000.000042E+7", CPL_TYPE_DOUBLE, 420}, - {"0000000000000000000000000000000000.000042E07", CPL_TYPE_DOUBLE, 420}, - {"+000000000000000000000000000000000.000042E07", CPL_TYPE_DOUBLE, 420}, + { "00000000000000000000000000000000000000420", CPL_TYPE_INT, 420 }, + { "+0000000000000000000000000000000000000420", CPL_TYPE_INT, 420 }, + { "00000000000000000000000000000000000000420.", CPL_TYPE_DOUBLE, 420 }, + { "+0000000000000000000000000000000000000420.", CPL_TYPE_DOUBLE, 420 }, + { "00000000000000000000000000000000000000420E0", CPL_TYPE_DOUBLE, 420 }, + { "+0000000000000000000000000000000000000420E0", CPL_TYPE_DOUBLE, 420 }, + { "00000000000000000000000000000000000000420E-0", CPL_TYPE_DOUBLE, + 420 }, + { "+0000000000000000000000000000000000000420E-0", CPL_TYPE_DOUBLE, + 420 }, + { "00000000000000000000000000000000000000420E+0", CPL_TYPE_DOUBLE, + 420 }, + { "+0000000000000000000000000000000000000420E+0", CPL_TYPE_DOUBLE, + 420 }, + + { "0000000000000000000000000000000000000042E1", CPL_TYPE_DOUBLE, 420 }, + { "+000000000000000000000000000000000000042E1", CPL_TYPE_DOUBLE, 420 }, + { "0000000000000000000000000000000000004200E-1", CPL_TYPE_DOUBLE, 420 }, + { "+000000000000000000000000000000000004200E-1", CPL_TYPE_DOUBLE, 420 }, + { "0000000000000000000000000000000000000042E+1", CPL_TYPE_DOUBLE, 420 }, + { "+000000000000000000000000000000000000042E+1", CPL_TYPE_DOUBLE, 420 }, + + { "000000000000000000000000000004200000000E-7", CPL_TYPE_DOUBLE, 420 }, + { "+00000000000000000000000000004200000000E-7", CPL_TYPE_DOUBLE, 420 }, + { "000000000000000000000000000004200000000E-07", CPL_TYPE_DOUBLE, 420 }, + { "+00000000000000000000000000004200000000E-07", CPL_TYPE_DOUBLE, 420 }, + { "0000000000000000000000000000000000.000042E+7", CPL_TYPE_DOUBLE, + 420 }, + { "+000000000000000000000000000000000.000042E+7", CPL_TYPE_DOUBLE, + 420 }, + { "0000000000000000000000000000000000.000042E07", CPL_TYPE_DOUBLE, + 420 }, + { "+000000000000000000000000000000000.000042E07", CPL_TYPE_DOUBLE, + 420 }, /* Floating-point constants that are FITS, but not C89 compliant */ - {"00000000000000000000000000000000000000420D0", CPL_TYPE_DOUBLE, 420}, - {"+0000000000000000000000000000000000000420D0", CPL_TYPE_DOUBLE, 420}, - {"00000000000000000000000000000000000000420D-0", CPL_TYPE_DOUBLE, 420}, - {"+0000000000000000000000000000000000000420D-0", CPL_TYPE_DOUBLE, 420}, - {"00000000000000000000000000000000000000420D+0", CPL_TYPE_DOUBLE, 420}, - {"+0000000000000000000000000000000000000420D+0", CPL_TYPE_DOUBLE, 420}, - - {"0000000000000000000000000000000000000042D1", CPL_TYPE_DOUBLE, 420}, - {"+000000000000000000000000000000000000042D1", CPL_TYPE_DOUBLE, 420}, - {"0000000000000000000000000000000000004200D-1", CPL_TYPE_DOUBLE, 420}, - {"+000000000000000000000000000000000004200D-1", CPL_TYPE_DOUBLE, 420}, - {"0000000000000000000000000000000000000042D+1", CPL_TYPE_DOUBLE, 420}, - {"+000000000000000000000000000000000000042D+1", CPL_TYPE_DOUBLE, 420}, - - {"000000000000000000000000000004200000000D-7", CPL_TYPE_DOUBLE, 420}, - {"+00000000000000000000000000004200000000D-7", CPL_TYPE_DOUBLE, 420}, - {"000000000000000000000000000004200000000D-07", CPL_TYPE_DOUBLE, 420}, - {"+00000000000000000000000000004200000000D-07", CPL_TYPE_DOUBLE, 420}, - {"0000000000000000000000000000000000.000042D+7", CPL_TYPE_DOUBLE, 420}, - {"+000000000000000000000000000000000.000042D+7", CPL_TYPE_DOUBLE, 420}, - {"0000000000000000000000000000000000.000042D07", CPL_TYPE_DOUBLE, 420}, - {"+000000000000000000000000000000000.000042D07", CPL_TYPE_DOUBLE, 420}, + { "00000000000000000000000000000000000000420D0", CPL_TYPE_DOUBLE, 420 }, + { "+0000000000000000000000000000000000000420D0", CPL_TYPE_DOUBLE, 420 }, + { "00000000000000000000000000000000000000420D-0", CPL_TYPE_DOUBLE, + 420 }, + { "+0000000000000000000000000000000000000420D-0", CPL_TYPE_DOUBLE, + 420 }, + { "00000000000000000000000000000000000000420D+0", CPL_TYPE_DOUBLE, + 420 }, + { "+0000000000000000000000000000000000000420D+0", CPL_TYPE_DOUBLE, + 420 }, + + { "0000000000000000000000000000000000000042D1", CPL_TYPE_DOUBLE, 420 }, + { "+000000000000000000000000000000000000042D1", CPL_TYPE_DOUBLE, 420 }, + { "0000000000000000000000000000000000004200D-1", CPL_TYPE_DOUBLE, 420 }, + { "+000000000000000000000000000000000004200D-1", CPL_TYPE_DOUBLE, 420 }, + { "0000000000000000000000000000000000000042D+1", CPL_TYPE_DOUBLE, 420 }, + { "+000000000000000000000000000000000000042D+1", CPL_TYPE_DOUBLE, 420 }, + + { "000000000000000000000000000004200000000D-7", CPL_TYPE_DOUBLE, 420 }, + { "+00000000000000000000000000004200000000D-7", CPL_TYPE_DOUBLE, 420 }, + { "000000000000000000000000000004200000000D-07", CPL_TYPE_DOUBLE, 420 }, + { "+00000000000000000000000000004200000000D-07", CPL_TYPE_DOUBLE, 420 }, + { "0000000000000000000000000000000000.000042D+7", CPL_TYPE_DOUBLE, + 420 }, + { "+000000000000000000000000000000000.000042D+7", CPL_TYPE_DOUBLE, + 420 }, + { "0000000000000000000000000000000000.000042D07", CPL_TYPE_DOUBLE, + 420 }, + { "+000000000000000000000000000000000.000042D07", CPL_TYPE_DOUBLE, + 420 }, /* Floating-point constants that are not FITS (!!!) but C89 compliant */ - {"00000000000000000000000000000000000000420.", CPL_TYPE_DOUBLE, 420}, - {"+0000000000000000000000000000000000000420.", CPL_TYPE_DOUBLE, 420}, + { "00000000000000000000000000000000000000420.", CPL_TYPE_DOUBLE, 420 }, + { "+0000000000000000000000000000000000000420.", CPL_TYPE_DOUBLE, 420 }, - {"0000000000000000000000000000000000000042.0e1", CPL_TYPE_DOUBLE, 420}, - {"+000000000000000000000000000000000000042.0e1", CPL_TYPE_DOUBLE, 420}, - {"0000000000000000000000000000000000004200.0e-1", CPL_TYPE_DOUBLE, 420}, - {"+000000000000000000000000000000000004200.0e-1", CPL_TYPE_DOUBLE, 420}, - {"0000000000000000000000000000000000000042.e+1", CPL_TYPE_DOUBLE, 420}, - {"+000000000000000000000000000000000000042.0e+1", CPL_TYPE_DOUBLE, 420}, - - {"0000000000000000000000000000000000.000042e+7", CPL_TYPE_DOUBLE, 420}, - {"+000000000000000000000000000000000.000042e+7", CPL_TYPE_DOUBLE, 420}, - {"0000000000000000000000000000000000.000042e07", CPL_TYPE_DOUBLE, 420}, - {"+000000000000000000000000000000000.000042e07", CPL_TYPE_DOUBLE, 420}, + { "0000000000000000000000000000000000000042.0e1", CPL_TYPE_DOUBLE, + 420 }, + { "+000000000000000000000000000000000000042.0e1", CPL_TYPE_DOUBLE, + 420 }, + { "0000000000000000000000000000000000004200.0e-1", CPL_TYPE_DOUBLE, + 420 }, + { "+000000000000000000000000000000000004200.0e-1", CPL_TYPE_DOUBLE, + 420 }, + { "0000000000000000000000000000000000000042.e+1", CPL_TYPE_DOUBLE, + 420 }, + { "+000000000000000000000000000000000000042.0e+1", CPL_TYPE_DOUBLE, + 420 }, + + { "0000000000000000000000000000000000.000042e+7", CPL_TYPE_DOUBLE, + 420 }, + { "+000000000000000000000000000000000.000042e+7", CPL_TYPE_DOUBLE, + 420 }, + { "0000000000000000000000000000000000.000042e07", CPL_TYPE_DOUBLE, + 420 }, + { "+000000000000000000000000000000000.000042e07", CPL_TYPE_DOUBLE, + 420 }, /* These integers do not fit in a signed long long */ - {"000018446744073709551615", CPL_TYPE_DOUBLE, 18446744073709551615E0}, - {"+00018446744073709551615", CPL_TYPE_DOUBLE, 18446744073709551615E0}, + { "000018446744073709551615", CPL_TYPE_DOUBLE, 18446744073709551615E0 }, + { "+00018446744073709551615", CPL_TYPE_DOUBLE, 18446744073709551615E0 }, /* These do not fit in a long long and cause unsigned overflow */ - {"+00184467440737095516150", CPL_TYPE_DOUBLE, 18446744073709551615E+1}, - {"184467440737095516150000", CPL_TYPE_DOUBLE, 18446744073709551615E+4}, - {"-00184467440737095516150", CPL_TYPE_DOUBLE, -18446744073709551615E1}, - {"-18446744073709551615000", CPL_TYPE_DOUBLE, -18446744073709551615E+3} + { "+00184467440737095516150", CPL_TYPE_DOUBLE, + 18446744073709551615E+1 }, + { "184467440737095516150000", CPL_TYPE_DOUBLE, + 18446744073709551615E+4 }, + { "-00184467440737095516150", CPL_TYPE_DOUBLE, + -18446744073709551615E1 }, + { "-18446744073709551615000", CPL_TYPE_DOUBLE, + -18446744073709551615E+3 } }; - const int nokval = (int)CX_N_ELEMENTS(okval); - cpl_propertylist * plist = cpl_propertylist_new(); - cpl_error_code code; - int syscode; - cpl_size k; + const int nokval = (int)CX_N_ELEMENTS(okval); + cpl_propertylist *plist = cpl_propertylist_new(); + cpl_error_code code; + int syscode; + int status = 0; + cpl_size k; for (int i = 0; i < nokval; i++) { /* Prepend key with a test of the comment support */ - char * ckey = cpl_sprintf("'/' " KEYFORM, 1+i); - const char * key = ckey + 4; + char *ckey = cpl_sprintf("'/' " KEYFORM, 1 + i); + const char *key = ckey + 4; cpl_propertylist_append_string(plist, key, okval[i].number); cpl_propertylist_set_comment(plist, key, ckey); @@ -2772,6 +2973,10 @@ cpl_test_eq_error(code, CPL_ERROR_NONE); cpl_propertylist_delete(plist); + /* Need to close file due to non CPL access */ + cpl_test_zero(cpl_io_fits_close(MYFILE, &status)); + cpl_test_zero(status); + /* For each card remove the quotes from the value, producing a number */ syscode = system(RMCARDQUOTE(KEYBASE, MYFILE)); @@ -2788,12 +2993,12 @@ cpl_test_eq(k, nokval); for (int i = 0; i < nokval; i++) { - char * key = cpl_sprintf(KEYFORM, 1+i); - const cpl_property * pp; + char *key = cpl_sprintf(KEYFORM, 1 + i); + const cpl_property *pp; cpl_type type; const cpl_size nfailed = cpl_test_get_failed(); - cpl_msg_info(cpl_func, "Testing OK-case %d/%d: %s (%s)", 1+i, + cpl_msg_info(cpl_func, "Testing OK-case %d/%d: %s (%s)", 1 + i, (int)nokval, okval[i].number, cpl_type_get_name(okval[i].type)); @@ -2811,16 +3016,18 @@ cpl_test_error(CPL_ERROR_NONE); cpl_test_rel(dval, okval[i].expected, DBL_EPSILON); - } else if (type == CPL_TYPE_DOUBLE_COMPLEX) { + } + else if (type == CPL_TYPE_DOUBLE_COMPLEX) { const double complex cval = cpl_property_get_double_complex(pp); - const double dval = creal(cval); - const double ival = cimag(cval); + const double dval = creal(cval); + const double ival = cimag(cval); cpl_test_error(CPL_ERROR_NONE); cpl_test_rel(dval, okval[i].expected, DBL_EPSILON); cpl_test_abs(ival, 0.0, 0.0); - } else { + } + else { const long long lval = cpl_property_get_long_long(pp); cpl_test_error(CPL_ERROR_NONE); @@ -2828,7 +3035,8 @@ cpl_test_eq(lval, (long long)okval[i].expected); } - if (cpl_test_get_failed() != nfailed) failcase++; + if (cpl_test_get_failed() != nfailed) + failcase++; cpl_free(key); } @@ -2855,41 +3063,45 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_propertylist_test_numeric_load_ok2(void) +static void +cpl_propertylist_test_numeric_load_ok2(void) { - struct numerical { + struct numerical + { const char *number; cpl_type type; - long long expected; }; struct numerical okval[] = { /* The below number is 2^63 */ - { "9223372036854775807", CPL_TYPE_LONG_LONG, 9223372036854775807LL}, - {"09223372036854775807", CPL_TYPE_LONG_LONG, 9223372036854775807LL}, - {"+9223372036854775807", CPL_TYPE_LONG_LONG, 9223372036854775807LL}, + { "9223372036854775807", CPL_TYPE_LONG_LONG }, + { "09223372036854775807", CPL_TYPE_LONG_LONG }, + { "+9223372036854775807", CPL_TYPE_LONG_LONG }, /* 1/machine precision, 1<<52 - 1, cast from double with no roundoff */ - {"00004503599627370495", CPL_TYPE_LONG_LONG, 4503599627370495LL}, - {"+0004503599627370495", CPL_TYPE_LONG_LONG, 4503599627370495LL}, - {"-0004503599627370495", CPL_TYPE_LONG_LONG, -4503599627370495LL}, + { "00004503599627370495", CPL_TYPE_LONG_LONG }, + { "+0004503599627370495", CPL_TYPE_LONG_LONG }, + { "-0004503599627370495", CPL_TYPE_LONG_LONG }, /* 1/machine precision, (1<<52) */ - {"00004503599627370496", CPL_TYPE_LONG_LONG, 4503599627370496LL}, - {"-0004503599627370496", CPL_TYPE_LONG_LONG, -4503599627370496LL}, - {"01000000000000000000", CPL_TYPE_LONG_LONG, 1000000000000000000LL}, - {"+1000000000000000000", CPL_TYPE_LONG_LONG, 1000000000000000000LL}, - {"-1000000000000000000", CPL_TYPE_LONG_LONG, -1000000000000000000LL} + { "00004503599627370496", CPL_TYPE_LONG_LONG }, + { "-0004503599627370496", CPL_TYPE_LONG_LONG }, + { "01000000000000000000", CPL_TYPE_LONG_LONG }, + { "+1000000000000000000", CPL_TYPE_LONG_LONG }, + { "-1000000000000000000", CPL_TYPE_LONG_LONG }, + /* ULLLONG_MAX: Would overflow a long long, so becomes double */ + { "18446744073709551615", CPL_TYPE_DOUBLE } }; - const int nokval = (int)CX_N_ELEMENTS(okval); - cpl_propertylist * plist = cpl_propertylist_new(); - cpl_error_code code; - int syscode; - cpl_size k; + const int nokval = (int)CX_N_ELEMENTS(okval); + cpl_propertylist *plist = cpl_propertylist_new(); + cpl_error_code code; + int syscode; + int status = 0; + cpl_size k; for (int i = 0; i < nokval; i++) { /* Prepend key with a test of the comment support */ - char * ckey = cpl_sprintf("'/' " KEYFORM, 1+i); - const char * key = ckey + 4; + char *ckey = cpl_sprintf("'/' " KEYFORM, 1 + i); + const char *key = ckey + 4; cpl_propertylist_append_string(plist, key, okval[i].number); cpl_propertylist_set_comment(plist, key, ckey); @@ -2904,6 +3116,10 @@ cpl_test_eq_error(code, CPL_ERROR_NONE); cpl_propertylist_delete(plist); + /* Need to close file due to non CPL access */ + cpl_test_zero(cpl_io_fits_close(MYFILE, &status)); + cpl_test_zero(status); + /* For each card remove the quotes from the value, producing a number */ syscode = system(RMCARDQUOTE(KEYBASE, MYFILE)); @@ -2912,12 +3128,12 @@ cpl_test_fits(MYFILE); for (int i = 0; i < nokval; i++) { - char * key = cpl_sprintf(KEYFORM, 1+i); - const cpl_property * pp; + char *key = cpl_sprintf(KEYFORM, 1 + i); + const cpl_property *pp; cpl_type type; const cpl_size nfailed = cpl_test_get_failed(); - cpl_msg_info(cpl_func, "Testing OK-case %d/%d: %s (%s)", 1+i, + cpl_msg_info(cpl_func, "Testing OK-case %d/%d: %s (%s)", 1 + i, (int)nokval, okval[i].number, cpl_type_get_name(okval[i].type)); @@ -2939,21 +3155,31 @@ if (type == CPL_TYPE_DOUBLE) { const double dval = cpl_property_get_double(pp); + double eval = 0.0; + const int iparse = sscanf(okval[i].number, "%lg", &eval); cpl_test_error(CPL_ERROR_NONE); - cpl_test_rel(dval, okval[i].expected, DBL_EPSILON); - } else { + cpl_test_eq(iparse, 1); + + cpl_test_rel(dval, eval, DBL_EPSILON); + } + else { const long long lval = cpl_property_get_long_long(pp); + long long eval = 0.0; + const int iparse = sscanf(okval[i].number, "%lld", &eval); cpl_test_error(CPL_ERROR_NONE); - cpl_test_eq(lval, (long long)okval[i].expected); + cpl_test_eq(iparse, 1); + + cpl_test_eq(lval, eval); } cpl_free(key); cpl_propertylist_delete(plist); - if (cpl_test_get_failed() != nfailed) failcase++; + if (cpl_test_get_failed() != nfailed) + failcase++; } if (failcase > 0) cpl_msg_error(cpl_func, "Failed %d of %d test case(s)", @@ -2974,46 +3200,36 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_propertylist_test_numeric_load_bad(void) +static void +cpl_propertylist_test_numeric_load_bad(void) { - const char* badval[] = { - "0.F", - " 0.F", - "+0.F", - "+0000.F", - " -0.F", - ".E0", - " .E000", - "+.E0", - " +.E0", - "-.E0", - "+-0.0", - " ++0.0", - " --0.0", - "+-0.0", - "TF", - "E", - "1EO", - "1DO", - "E", - "E123"}; + const char *badval[] = { + "1A", "-2#", "3,0", "-4.0.", "5E0$", "-6E0E", + "7D0)", "-8D0-", "NaN", "Inf", "+Inf", "-Inf", + "1e999", "-1e999", "0.F", " 0.F", "+0.F", "+0000.F", + " -0.F", ".E0", " .E000", "+.E0", " +.E0", "-.E0", + "+-0.0", " ++0.0", " --0.0", "+-0.0", "TF", "1EO", + "1DO", "E", "1EO", "1DO", "E", "E123" + }; - const int nbadval = (int)CX_N_ELEMENTS(badval); + const int nbadval = (int)CX_N_ELEMENTS(badval); for (int idocom = 0; idocom < 2; idocom++) { - cpl_propertylist * plist = cpl_propertylist_new(); - cpl_error_code code; - int syscode; - cpl_size k; - + cpl_propertylist *plist = cpl_propertylist_new(); + cpl_error_code code; + int syscode; + int status = 0; + cpl_size k; + for (int i = 0; i < nbadval; i++) { /* Prepend key with a test of the comment support */ - char * ckey = cpl_sprintf("'/' " KEYFORM, 1+i); - const char * key = ckey + 4; + char *ckey = cpl_sprintf("'/' " KEYFORM, 1 + i); + const char *key = ckey + 4; cpl_propertylist_append_string(plist, key, badval[i]); - if (idocom) cpl_propertylist_set_comment(plist, key, ckey); + if (idocom) + cpl_propertylist_set_comment(plist, key, ckey); cpl_free(ckey); } @@ -3025,6 +3241,10 @@ cpl_test_eq_error(code, CPL_ERROR_NONE); cpl_propertylist_delete(plist); + /* Need to close file due to non CPL access */ + cpl_test_zero(cpl_io_fits_close(MYFILE, &status)); + cpl_test_zero(status); + /* For each card remove the quotes from the value, producing a number */ syscode = system(RMCARDQUOTE(KEYBASE, MYFILE)); @@ -3033,12 +3253,12 @@ cpl_test_fits(MYFILE); for (int i = 0; i < nbadval; i++) { - cpl_propertylist * nulllist; - char * key = cpl_sprintf(KEYFORM, 1+i); + cpl_propertylist *nulllist; + char *key = cpl_sprintf(KEYFORM, 1 + i); const cpl_size nfailed = cpl_test_get_failed(); - cpl_msg_info(cpl_func, "Testing BAD-case %d/%d: %s", - 1+i, (int)nbadval, badval[i]); + cpl_msg_info(cpl_func, "Testing BAD-case %d/%d: %s", 1 + i, + (int)nbadval, badval[i]); nulllist = cpl_propertylist_load_regexp(MYFILE, 0, key, 0); cpl_test_error(CPL_ERROR_BAD_FILE_FORMAT); @@ -3050,7 +3270,8 @@ } cpl_free(key); - if (cpl_test_get_failed() != nfailed) failcase++; + if (cpl_test_get_failed() != nfailed) + failcase++; } if (failcase > 0) cpl_msg_error(cpl_func, "Failed %d of %d test case(s)", @@ -3074,34 +3295,37 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_propertylist_test_numeric_load_ok3(void) +static void +cpl_propertylist_test_numeric_load_ok3(void) { - struct numerical { + struct numerical + { const char *number; cpl_type type; - double real_expect; - double imag_expect; + double real_expect; + double imag_expect; }; struct numerical okval[] = { - { "(1, 0.0)", CPL_TYPE_DOUBLE_COMPLEX, 1.0, 0.0}, - { "(1, 1)", CPL_TYPE_DOUBLE_COMPLEX, 1.0, 1.0}, - { "(+1, +01)", CPL_TYPE_DOUBLE_COMPLEX, 1.0, 1.0}, - { "(+1E0, +01D-0)", CPL_TYPE_DOUBLE_COMPLEX, 1.0, 1.0}, - { "(1D1,2E2)", CPL_TYPE_DOUBLE_COMPLEX, 1E1, 2E2}, - { "(1D1,2E2)", CPL_TYPE_DOUBLE_COMPLEX, 1E1, 2E2} + { "(1, 0.0)", CPL_TYPE_DOUBLE_COMPLEX, 1.0, 0.0 }, + { "(1, 1)", CPL_TYPE_DOUBLE_COMPLEX, 1.0, 1.0 }, + { "(+1, +01)", CPL_TYPE_DOUBLE_COMPLEX, 1.0, 1.0 }, + { "(+1E0, +01D-0)", CPL_TYPE_DOUBLE_COMPLEX, 1.0, 1.0 }, + { "(1D1,2E2)", CPL_TYPE_DOUBLE_COMPLEX, 1E1, 2E2 }, + { "(1D1,2E2)", CPL_TYPE_DOUBLE_COMPLEX, 1E1, 2E2 } }; - const int nokval = (int)CX_N_ELEMENTS(okval); - cpl_propertylist * plist = cpl_propertylist_new(); - cpl_error_code code; - int syscode; - cpl_size k; + const int nokval = (int)CX_N_ELEMENTS(okval); + cpl_propertylist *plist = cpl_propertylist_new(); + cpl_error_code code; + int syscode; + int status = 0; + cpl_size k; for (int i = 0; i < nokval; i++) { /* Prepend key with a test of the comment support */ - char * ckey = cpl_sprintf("'/' " KEYFORM, 1+i); - const char * key = ckey + 4; + char *ckey = cpl_sprintf("'/' " KEYFORM, 1 + i); + const char *key = ckey + 4; cpl_propertylist_append_string(plist, key, okval[i].number); cpl_propertylist_set_comment(plist, key, ckey); @@ -3116,6 +3340,10 @@ cpl_test_eq_error(code, CPL_ERROR_NONE); cpl_propertylist_delete(plist); + /* Need to close file due to non CPL access */ + cpl_test_zero(cpl_io_fits_close(MYFILE, &status)); + cpl_test_zero(status); + /* For each card remove the quotes from the value, producing a number */ syscode = system(RMCARDQUOTE(KEYBASE, MYFILE)); @@ -3124,12 +3352,12 @@ cpl_test_fits(MYFILE); for (int i = 0; i < nokval; i++) { - char * key = cpl_sprintf(KEYFORM, 1+i); - const cpl_property * pp; + char *key = cpl_sprintf(KEYFORM, 1 + i); + const cpl_property *pp; cpl_type type; const cpl_size nfailed = cpl_test_get_failed(); - cpl_msg_info(cpl_func, "Testing OK-case %d/%d: %s (%s)", 1+i, + cpl_msg_info(cpl_func, "Testing OK-case %d/%d: %s (%s)", 1 + i, (int)nokval, okval[i].number, cpl_type_get_name(okval[i].type)); @@ -3150,10 +3378,9 @@ cpl_test_eq(type, okval[i].type); if (type == CPL_TYPE_DOUBLE_COMPLEX) { - const double complex cval = cpl_property_get_double_complex(pp); - const double dval = creal(cval); - const double ival = cimag(cval); + const double dval = creal(cval); + const double ival = cimag(cval); cpl_test_error(CPL_ERROR_NONE); @@ -3163,10 +3390,440 @@ cpl_free(key); cpl_propertylist_delete(plist); - if (cpl_test_get_failed() != nfailed) failcase++; + if (cpl_test_get_failed() != nfailed) + failcase++; } if (failcase > 0) cpl_msg_error(cpl_func, "Failed %d of %d test case(s)", (int)failcase, nokval); } } + +#undef MYTEST +#define MYTEST 38 + +#undef MYFILE +#define MYFILE FILENAME(MYTEST) + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief Check loading of bad keys + + */ +/*----------------------------------------------------------------------------*/ +static void +cpl_propertylist_test_load_bad_key(void) +{ + cpl_propertylist *plist = cpl_propertylist_new(); + const char *strval; + cpl_error_code code; + int syscode; + int status = 0; + cpl_size nsize; + int ival; + + code = cpl_propertylist_append_string(plist, "ESO DELKEY", "DELVALUE"); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + code = cpl_propertylist_set_comment(plist, "ESO DELKEY", + " VALUE INDICATOR = 'is missing'"); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + code = cpl_propertylist_save(plist, MYFILE, CPL_IO_CREATE); + cpl_test_eq_error(code, CPL_ERROR_NONE); + cpl_propertylist_delete(plist); + + /* Need to close file due to non CPL access */ + cpl_test_zero(cpl_io_fits_close(MYFILE, &status)); + cpl_test_zero(status); + + /* Create an invalid HIERARCH card */ + syscode = system("perl -pi -e 's/ESO DELKEY/ /' " MYFILE); + cpl_test_zero(syscode); + + cpl_test_fits(MYFILE); + + plist = cpl_propertylist_load_regexp(MYFILE, 0, "HIERARCH", 0); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(plist); + + nsize = cpl_propertylist_get_size(plist); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(nsize, 1); + + ival = cpl_propertylist_has(plist, "HIERARCH"); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_eq(ival, 1); + + strval = cpl_propertylist_get_string(plist, "HIERARCH"); + cpl_test_nonnull(strval); + cpl_test_eq_string(strval, "DELVALUE"); + + cpl_propertylist_delete(plist); + + /* Need to close file due to non CPL access */ + cpl_test_zero(cpl_io_fits_close(MYFILE, &status)); + cpl_test_zero(status); + + /* Remove the value indicator from the invalid HIERARCH card */ + syscode = system("perl -pi -e 's/(HIERARCH +)=/$1 /' " MYFILE); + cpl_test_zero(syscode); + + cpl_test_fits(MYFILE); + + /* The card is no longer loadable */ + plist = cpl_propertylist_load_regexp(MYFILE, 0, "HIERARCH", 0); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(plist); + + nsize = cpl_propertylist_get_size(plist); + cpl_test_error(CPL_ERROR_NONE); + + cpl_test_zero(nsize); + + cpl_propertylist_delete(plist); +} + + +#undef MYTEST +#define MYTEST 40 + +#undef MYFILE +#define MYFILE FILENAME(MYTEST) + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief Check support for full cards + + */ +/*----------------------------------------------------------------------------*/ +static void +cpl_propertylist_test_full_card(void) +{ + cpl_propertylist *plist = cpl_propertylist_new(); + cpl_propertylist *plist2; + cpl_size nsize, msize; + int status = 0; + cpl_error_code code; + + + code = cpl_propertylist_append_double(plist, + "ESO " + "ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ " + "ABCDEFGHIJ ABCDEFGHIJ AA", + 1.23E-45); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + code = cpl_propertylist_append_double(plist, + "ESO " + "ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ " + "ABCDEFGHIJ ABCDEFGHIJ AB", + -1.2E-34); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + code = cpl_propertylist_append_char(plist, + "ESO " + "ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ " + "ABCDEFGHIJ ABCDEFGHIJ AC", + '\''); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + code = cpl_propertylist_append_string(plist, + "ESO " + "ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ " + "ABCDEFGHIJ ABCDEFGHIJ AD", + "KEEPMENO"); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + code = cpl_propertylist_append_string(plist, + "ESO " + "ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ " + "ABCDEFGHIJ ABCDEFGHIJ AE", + "QUOTE'"); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + code = cpl_propertylist_append_string(plist, + "ESO " + "ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ " + "ABCDEFGHIJ ABCDEFGHIJ AF", + "O'HARA"); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + code = cpl_propertylist_append_int(plist, + "ESO " + "ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ " + "ABCDEFGHIJ ABCDEFGHIJ AG", + 12345678); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + code = cpl_propertylist_append_int(plist, + "ESO " + "ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ " + "ABCDEFGHIJ ABCDEFGHIJ AH", + -1234567); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + code = cpl_propertylist_append_double_complex(plist, + "ESO " + "ABCDEFGHIJ ABCDEFGHIJ " + "ABCDEFGHIJ ABCDEFGHIJ " + "ABCDEFGHIJ AI", + 12 + 34 * _Complex_I); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + nsize = cpl_propertylist_get_size(plist); + cpl_test_error(CPL_ERROR_NONE); + + code = cpl_propertylist_save(plist, MYFILE, CPL_IO_CREATE); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + /* Need to close file due to non CPL access */ + cpl_test_zero(cpl_io_fits_close(MYFILE, &status)); + cpl_test_zero(status); + + cpl_test_fits(MYFILE); + + plist2 = cpl_propertylist_load_regexp(MYFILE, 0, "ESO ", 0); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(plist2); + + msize = cpl_propertylist_get_size(plist2); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(nsize, msize); + + for (cpl_size j = 0; j < nsize; j++) { + const cpl_size nfailed = cpl_test_get_failed(); + const cpl_property *p1 = cpl_propertylist_get_const(plist, j); + const char *name = cpl_property_get_name(p1); + const cpl_property *p2 = + cpl_propertylist_get_property_const(plist2, name); + const cpl_type t1 = cpl_property_get_type(p1); + cpl_type t2 = CPL_TYPE_INVALID; + + + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(p2); + + if (p2 != NULL) { + const cpl_type t1e = t1 == CPL_TYPE_CHAR ? CPL_TYPE_STRING : t1; + + t2 = cpl_property_get_type(p2); + + cpl_test_eq(t1e, t2); + + if (t1 == CPL_TYPE_STRING && t2 == CPL_TYPE_STRING) { + const char *v1 = cpl_property_get_string(p1); + const char *v2 = cpl_property_get_string(p2); + const int l1 = strlen(v1); + const int l2 = strlen(v2); + + if (strlen("HIERARCH ") + strlen(name) + l1 + 4 <= 80 && + memchr(v1, '\'', l1) == NULL) { + cpl_test_eq(l1, l2); + cpl_test_eq_string(v1, v2); + } + else { + cpl_test_lt(l2, l1); + cpl_test_zero(memcmp(v1, v2, l2)); + } + } + else if (t1 == CPL_TYPE_DOUBLE && t2 == CPL_TYPE_DOUBLE) { + const double v1 = cpl_property_get_double(p1); + const double v2 = cpl_property_get_double(p2); + if (v1 < 0.0) { + cpl_test_rel(v1, v2, 5 * 1e-1); + } + else { + cpl_test_rel(v1, v2, 5 * 1e-2); + } + } + } + + if (cpl_test_get_failed() != nfailed) { + cpl_msg_warning(cpl_func, "FAILED(%d/%d<=>%d): %s (%s <=> %s)", + (int)j, (int)nsize, (int)msize, name, + cpl_type_get_name(t1), cpl_type_get_name(t2)); + } + } + + cpl_propertylist_delete(plist); + cpl_propertylist_delete(plist2); +} + + +#undef MYTEST +#define MYTEST 41 + +#undef MYFILE +#define MYFILE FILENAME(MYTEST) + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief Check support for too long cards + + */ +/*----------------------------------------------------------------------------*/ +static void +cpl_propertylist_test_too_long_card(void) +{ + cpl_propertylist *plist = cpl_propertylist_new(); + cpl_propertylist *plist2 = cpl_propertylist_new(); + cpl_size nsize; + cpl_error_code code; + + + code = cpl_propertylist_append_double(plist, + "ESO " + "ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ " + "ABCDEFGHIJ ABCDEFGHIJ AA", + 1.236E-45); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + code = cpl_propertylist_append_double(plist, + "ESO " + "ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ " + "ABCDEFGHIJ ABCDEFGHIJ AB", + -1.25E-34); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + code = cpl_propertylist_append_double(plist, + "ESO " + "ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ " + "ABCDEFGHIJ ABCDEFGHIJ AC", + 12345678.0); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + code = cpl_propertylist_append_double(plist, + "ESO " + "ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ " + "ABCDEFGHIJ ABCDEFGHIJ AD", + -1234567.0); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + code = cpl_propertylist_append_float(plist, + "ESO " + "ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ " + "ABCDEFGHIJ ABCDEFGHIJ AE", + 1.236E-45); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + code = cpl_propertylist_append_float(plist, + "ESO " + "ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ " + "ABCDEFGHIJ ABCDEFGHIJ AF", + -1.25E-34); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + code = cpl_propertylist_append_float(plist, + "ESO " + "ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ " + "ABCDEFGHIJ ABCDEFGHIJ AG", + 12345678.0); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + code = cpl_propertylist_append_float(plist, + "ESO " + "ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ " + "ABCDEFGHIJ ABCDEFGHIJ AH", + -1234567.0); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + code = cpl_propertylist_append_int(plist, + "ESO " + "ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ " + "ABCDEFGHIJ ABCDEFGHIJ AI", + 123456789); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + code = cpl_propertylist_append_int(plist, + "ESO " + "ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ " + "ABCDEFGHIJ ABCDEFGHIJ AJ", + -12345678); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + code = cpl_propertylist_append_long(plist, + "ESO " + "ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ " + "ABCDEFGHIJ ABCDEFGHIJ AK", + 987654321); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + code = cpl_propertylist_append_long(plist, + "ESO " + "ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ " + "ABCDEFGHIJ ABCDEFGHIJ AL", + -98765432); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + + code = cpl_propertylist_append_long_long(plist, + "ESO " + "ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ " + "ABCDEFGHIJ ABCDEFGHIJ AM", + 987654321); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + code = cpl_propertylist_append_long_long(plist, + "ESO " + "ABCDEFGHIJ ABCDEFGHIJ ABCDEFGHIJ " + "ABCDEFGHIJ ABCDEFGHIJ AN", + -98765432); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + + code = cpl_propertylist_append_double_complex(plist, + "ESO " + "ABCDEFGHIJ ABCDEFGHIJ " + "ABCDEFGHIJ ABCDEFGHIJ " + "ABCDEFGHIJ AO", + 12 + 34.5 * _Complex_I); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + code = cpl_propertylist_append_double_complex(plist, + "ESO " + "ABCDEFGHIJ ABCDEFGHIJ " + "ABCDEFGHIJ ABCDEFGHIJ " + "ABCDEFGHIJ AP", + 12.5 + 34 * _Complex_I); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + code = cpl_propertylist_append_float_complex(plist, + "ESO " + "ABCDEFGHIJ ABCDEFGHIJ " + "ABCDEFGHIJ ABCDEFGHIJ " + "ABCDEFGHIJ AQ", + 12 + 34.5 * _Complex_I); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + code = cpl_propertylist_append_float_complex(plist, + "ESO " + "ABCDEFGHIJ ABCDEFGHIJ " + "ABCDEFGHIJ ABCDEFGHIJ " + "ABCDEFGHIJ AR", + 12.5 + 34 * _Complex_I); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + nsize = cpl_propertylist_get_size(plist); + cpl_test_error(CPL_ERROR_NONE); + + for (cpl_size j = 0; j < nsize; j++) { + const cpl_property *p = cpl_propertylist_get_const(plist, j); + + code = cpl_propertylist_append_property(plist2, p); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + (void)remove(MYFILE); + code = cpl_propertylist_save(plist2, MYFILE, CPL_IO_CREATE); + cpl_test_eq_error(code, CPL_ERROR_ILLEGAL_INPUT); + + cpl_propertylist_empty(plist2); + } + + cpl_propertylist_delete(plist); + cpl_propertylist_delete(plist2); +} diff -Nru cpl-7.1.4+ds/cplcore/tests/cpl_property-test.c cpl-7.2.2+ds/cplcore/tests/cpl_property-test.c --- cpl-7.1.4+ds/cplcore/tests/cpl_property-test.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/tests/cpl_property-test.c 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -20,87 +20,74 @@ #include #include "cpl_test.h" -#include "cpl_property_impl.h" +#include "cpl_property_dicb.h" #include #include -#define STRING100 \ - "01234567890123456789012345678901234567890123456789" \ +#define STRING100 \ + "01234567890123456789012345678901234567890123456789" \ "01234567890123456789012345678901234567890123456789" #define CPL_NPROPS 9 -int main(void) +int +main(void) { + const char *names[] = { "char", "bool", "int", + "long", "float", "double", + "string", "float complex", "double complex" }; - const char *names[] = { - "char", - "bool", - "int", - "long", - "float", - "double", - "string", - "float complex", - "double complex" - }; - - const char *strings[] = { - "Mary", - "Mary had a little lamb", - "Mary had a", - STRING100, - STRING100 STRING100, - "Mary had" - }; + const char *strings[] = { "Mary", "Mary had a little lamb", "Mary had a", + STRING100, STRING100 STRING100, "Mary had" }; const float fval0 = 1.23456789; float fval1, fval2; const double dval0 = fval0; double dval1, dval2; const float complex zf0 = fval0 + fval0 * fval0 * _Complex_I; - float complex zf1, zf2; + float complex zf1, zf2; const double complex zd0 = zf0; double complex zd1, zd2; cpl_error_code code; - const cpl_type types[] = { - CPL_TYPE_CHAR, - CPL_TYPE_BOOL, - CPL_TYPE_INT, - CPL_TYPE_LONG, - CPL_TYPE_FLOAT, - CPL_TYPE_DOUBLE, - CPL_TYPE_STRING, - CPL_TYPE_FLOAT_COMPLEX, - CPL_TYPE_DOUBLE_COMPLEX - }; - - cpl_property * property; - cpl_property * plist[CPL_NPROPS]; - const size_t nprops = CX_N_ELEMENTS(names); - const size_t nstrings = CX_N_ELEMENTS(strings); - cpl_property * nullprop; + const cpl_type types[] = { CPL_TYPE_CHAR, CPL_TYPE_BOOL, + CPL_TYPE_INT, CPL_TYPE_LONG, + CPL_TYPE_FLOAT, CPL_TYPE_DOUBLE, + CPL_TYPE_STRING, CPL_TYPE_FLOAT_COMPLEX, + CPL_TYPE_DOUBLE_COMPLEX }; + + cpl_property *property; + cpl_property *plist[CPL_NPROPS]; + const size_t nprops = CX_N_ELEMENTS(names); + const size_t nstrings = CX_N_ELEMENTS(strings); + cpl_property *nullprop; - FILE * stream; + FILE *stream; cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); - stream = cpl_msg_get_level() > CPL_MSG_INFO - ? fopen("/dev/null", "a") : stdout; + stream = + cpl_msg_get_level() > CPL_MSG_INFO ? fopen("/dev/null", "a") : stdout; - cpl_test_nonnull( stream ); + cpl_test_nonnull(stream); cpl_test_assert(nprops == CPL_NPROPS); + /* cpl_property_compare_sortkey() relies on sortkey being unsigned */ + cpl_test_assert(CPL_PROPERTY_SORT_UNDEF == (cpl_property_sorttype)0); + cpl_test_assert(CPL_PROPERTY_SORT_UNDEF < CPL_PROPERTY_SORT_MAX); + + cpl_test_assert(CPL_DICB_PRIMARY < CPL_DICB_HIERARCH_XYZ); + cpl_test_assert(CPL_DICB_END < CPL_PROPERTY_SORT_MAX); + /* * Test 1: Create a properties of different types, check their validity * and destroy them again. */ - cpl_test_eq(sizeof(names)/sizeof(names[0]), - sizeof(types)/sizeof(types[0])); + cpl_test_eq(sizeof(names) / sizeof(names[0]), + sizeof(types) / sizeof(types[0])); nullprop = cpl_property_new(NULL, types[0]); @@ -154,7 +141,8 @@ cpl_test_eq(cpl_property_get_type(property), types[i]); if (types[i] & CPL_TYPE_FLAG_ARRAY) { cpl_test_eq(cpl_property_get_size(property), j); - } else { + } + else { cpl_test_eq(cpl_property_get_size(property), 1); } @@ -187,14 +175,13 @@ code = cpl_property_set_name(plist[i], strings[j]); cpl_test_eq_error(code, CPL_ERROR_NONE); cpl_test_eq_string(cpl_property_get_name(plist[i]), strings[j]); - } } for (size_t i = 0; i < nprops; i++) { cpl_property_set_name(plist[i], names[nprops - 1 - i]); cpl_test_eq_string(cpl_property_get_name(plist[i]), - names[nprops -1 - i]); + names[nprops - 1 - i]); cpl_property_delete(plist[i]); } @@ -213,17 +200,17 @@ cpl_property_set_bool(plist[1], 1); cpl_test_eq(cpl_property_get_bool(plist[1]), 1); - + cpl_property_set_int(plist[2], 100); cpl_test_eq(cpl_property_get_int(plist[2]), 100); - + cpl_property_set_long(plist[3], 10L); cpl_test_eq(cpl_property_get_long(plist[3]), 10L); - + cpl_property_set_float(plist[4], fval0); fval1 = cpl_property_get_float(plist[4]); cpl_test_abs(fval0, fval1, 0.0); - + cpl_property_set_double(plist[5], dval0); dval1 = cpl_property_get_double(plist[5]); cpl_test_abs(dval0, dval1, 0.0); @@ -258,7 +245,7 @@ cpl_test_abs_complex(zf0, zf1, 0.0); cpl_test_eq(cpl_type_get_sizeof(CPL_TYPE_FLOAT_COMPLEX), sizeof(zf0)); - + cpl_property_set_double_complex(plist[8], zd0); cpl_test_eq_error(code, CPL_ERROR_NONE); zd1 = cpl_property_get_double_complex(plist[8]); @@ -267,17 +254,14 @@ for (size_t i = 0; i < nprops; i++) { for (size_t j = 0; j < nstrings; j++) { - code = cpl_property_set_comment(plist[i], strings[j]); cpl_test_eq_error(code, CPL_ERROR_NONE); for (size_t k = 0; k < nstrings; k++) { - code = cpl_property_set_name(plist[i], strings[k]); cpl_test_eq_error(code, CPL_ERROR_NONE); - cpl_test_eq_string(cpl_property_get_name(plist[i]), - strings[k]); + cpl_test_eq_string(cpl_property_get_name(plist[i]), strings[k]); cpl_test_eq_string(cpl_property_get_comment(plist[i]), strings[j]); @@ -286,7 +270,8 @@ if (types[i] != CPL_TYPE_STRING) { cpl_test_eq_error(code, CPL_ERROR_TYPE_MISMATCH); - } else { + } + else { cpl_test_eq_error(code, CPL_ERROR_NONE); cpl_test_eq_string(cpl_property_get_string(plist[i]), @@ -310,9 +295,9 @@ cpl_test_noneq_ptr(property, plist[i]); cpl_test_noneq_ptr(cpl_property_get_name(property), - cpl_property_get_name(plist[i])); + cpl_property_get_name(plist[i])); cpl_test_noneq_ptr(cpl_property_get_comment(property), - cpl_property_get_comment(plist[i])); + cpl_property_get_comment(plist[i])); cpl_test_eq(cpl_property_get_size(property), cpl_property_get_size(plist[i])); cpl_test_eq(cpl_property_get_type(property), @@ -323,7 +308,7 @@ cpl_test_eq(cpl_property_get_char(property), cpl_property_get_char(plist[i])); break; - + case CPL_TYPE_BOOL: cpl_test_eq(cpl_property_get_bool(property), cpl_property_get_bool(plist[i])); @@ -388,8 +373,8 @@ * All tests finished */ - if (stream != stdout) cpl_test_zero( fclose(stream) ); + if (stream != stdout) + cpl_test_zero(fclose(stream)); return cpl_test_end(0); - } diff -Nru cpl-7.1.4+ds/cplcore/tests/cpl_stats-test.c cpl-7.2.2+ds/cplcore/tests/cpl_stats-test.c --- cpl-7.1.4+ds/cplcore/tests/cpl_stats-test.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/tests/cpl_stats-test.c 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -51,79 +51,81 @@ #define TOL (16.0 * DBL_EPSILON) #endif -#define CPL_STAT_CMP(OP, FUNC) \ - do { \ - \ - cpl_stats * statone; \ - \ - cpl_test_nonnull( statone = cpl_stats_new_from_image \ - (img, CPL_CONCAT2X(CPL_STATS,OP))); \ - \ - /* Compare result from one-stats object with all-stats object */ \ - cpl_test_abs( CPL_CONCAT2X(cpl_stats_get, FUNC)(statall), \ - CPL_CONCAT2X(cpl_stats_get, FUNC)(statone), \ - TOL); \ - \ - cpl_stats_delete(statone); \ - \ - } while (0) - - -#define CPL_STAT_CMP_IMAGE(OP) \ - do { \ - \ - /* Test NULL input */ \ - (void)CPL_CONCAT2X(cpl_stats_get, OP)(NULL); \ - cpl_test_error(CPL_ERROR_NULL_INPUT); \ - \ - (void)CPL_CONCAT2X(cpl_image_get, OP)(NULL); \ - cpl_test_error(CPL_ERROR_NULL_INPUT); \ - \ - (void)CPL_CONCAT2X(cpl_image_get, CPL_CONCAT2X(OP,window)) \ - (NULL, 1, 1, IMAGE_SIZE_X, IMAGE_SIZE_Y); \ - cpl_test_error(CPL_ERROR_NULL_INPUT); \ - \ - /* Test out-of-range windows parameters */ \ - (void)CPL_CONCAT2X(cpl_image_get, CPL_CONCAT2X(OP,window)) \ - (img, 0, 1, IMAGE_SIZE_X, IMAGE_SIZE_Y); \ - cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); \ - \ - (void)CPL_CONCAT2X(cpl_image_get, CPL_CONCAT2X(OP,window)) \ - (img, 1, 0, IMAGE_SIZE_X, IMAGE_SIZE_Y); \ - cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); \ - \ - (void)CPL_CONCAT2X(cpl_image_get, CPL_CONCAT2X(OP,window)) \ - (img, 1, 1, IMAGE_SIZE_X+1, IMAGE_SIZE_Y); \ - cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); \ - \ - (void)CPL_CONCAT2X(cpl_image_get, CPL_CONCAT2X(OP,window)) \ - (img, 1, 1, IMAGE_SIZE_X, IMAGE_SIZE_Y+1); \ - cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); \ - \ - /* Compare result from stats object with image window accessor */ \ - cpl_test_abs( CPL_CONCAT2X(cpl_stats_get, OP)(statall), \ - CPL_CONCAT2X(cpl_image_get, CPL_CONCAT2X(OP,window)) \ - (img, 1, 1, IMAGE_SIZE_X, IMAGE_SIZE_Y), \ - TOL); \ - \ - /* Compare result from stats object with image accessor */ \ - cpl_test_abs( CPL_CONCAT2X(cpl_stats_get, OP)(statall), \ - CPL_CONCAT2X(cpl_image_get, OP)(img), \ - TOL); \ - } while (0) - - -#define CPL_STAT_CMP_VECTOR(OP, TOL) \ - do { \ - cpl_vector * vtest \ - = cpl_vector_wrap(IMAGE_SIZE_X*IMAGE_SIZE_Y, \ - cpl_image_get_data_double(img)); \ - cpl_test_nonnull(vtest); \ - cpl_test_abs(CPL_CONCAT2X(cpl_stats_get, OP)(statall), \ - CPL_CONCAT2X(cpl_vector_get, OP)(vtest), \ - TOL* DBL_EPSILON); \ - cpl_test_nonnull(cpl_vector_unwrap(vtest)); \ - } while (0) +#define CPL_STAT_CMP(OP, FUNC) \ + do { \ + cpl_stats *statone; \ + \ + cpl_test_nonnull( \ + statone = \ + cpl_stats_new_from_image(img, CPL_CONCAT2X(CPL_STATS, OP))); \ + \ + /* Compare result from one-stats object with all-stats object */ \ + cpl_test_abs(CPL_CONCAT2X(cpl_stats_get, FUNC)(statall), \ + CPL_CONCAT2X(cpl_stats_get, FUNC)(statone), TOL); \ + \ + cpl_stats_delete(statone); \ + \ + } while (0) + + +#define CPL_STAT_CMP_IMAGE(OP) \ + do { \ + /* Test NULL input */ \ + (void)CPL_CONCAT2X(cpl_stats_get, OP)(NULL); \ + cpl_test_error(CPL_ERROR_NULL_INPUT); \ + \ + (void)CPL_CONCAT2X(cpl_image_get, OP)(NULL); \ + cpl_test_error(CPL_ERROR_NULL_INPUT); \ + \ + (void)CPL_CONCAT2X(cpl_image_get, \ + CPL_CONCAT2X(OP, window))(NULL, 1, 1, IMAGE_SIZE_X, \ + IMAGE_SIZE_Y); \ + cpl_test_error(CPL_ERROR_NULL_INPUT); \ + \ + /* Test out-of-range windows parameters */ \ + (void)CPL_CONCAT2X(cpl_image_get, \ + CPL_CONCAT2X(OP, window))(img, 0, 1, IMAGE_SIZE_X, \ + IMAGE_SIZE_Y); \ + cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); \ + \ + (void)CPL_CONCAT2X(cpl_image_get, \ + CPL_CONCAT2X(OP, window))(img, 1, 0, IMAGE_SIZE_X, \ + IMAGE_SIZE_Y); \ + cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); \ + \ + (void)CPL_CONCAT2X(cpl_image_get, \ + CPL_CONCAT2X(OP, window))(img, 1, 1, \ + IMAGE_SIZE_X + 1, \ + IMAGE_SIZE_Y); \ + cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); \ + \ + (void)CPL_CONCAT2X(cpl_image_get, \ + CPL_CONCAT2X(OP, window))(img, 1, 1, IMAGE_SIZE_X, \ + IMAGE_SIZE_Y + 1); \ + cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); \ + \ + /* Compare result from stats object with image window accessor */ \ + cpl_test_abs(CPL_CONCAT2X(cpl_stats_get, OP)(statall), \ + CPL_CONCAT2X(cpl_image_get, CPL_CONCAT2X(OP, window))( \ + img, 1, 1, IMAGE_SIZE_X, IMAGE_SIZE_Y), \ + TOL); \ + \ + /* Compare result from stats object with image accessor */ \ + cpl_test_abs(CPL_CONCAT2X(cpl_stats_get, OP)(statall), \ + CPL_CONCAT2X(cpl_image_get, OP)(img), TOL); \ + } while (0) + + +#define CPL_STAT_CMP_VECTOR(OP, TOL) \ + do { \ + cpl_vector *vtest = cpl_vector_wrap(IMAGE_SIZE_X * IMAGE_SIZE_Y, \ + cpl_image_get_data_double(img)); \ + cpl_test_nonnull(vtest); \ + cpl_test_abs(CPL_CONCAT2X(cpl_stats_get, OP)(statall), \ + CPL_CONCAT2X(cpl_vector_get, OP)(vtest), \ + TOL *DBL_EPSILON); \ + cpl_test_nonnull(cpl_vector_unwrap(vtest)); \ + } while (0) /*----------------------------------------------------------------------------- Private function prototypes @@ -136,32 +138,34 @@ /*----------------------------------------------------------------------------- Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { - const cpl_type img_types[] = {CPL_TYPE_DOUBLE, CPL_TYPE_FLOAT, CPL_TYPE_INT}; - const cpl_stats_mode istats[] = {CPL_STATS_MIN, CPL_STATS_MAX, - CPL_STATS_MEDIAN, CPL_STATS_MEDIAN_DEV, - CPL_STATS_MAD, - CPL_STATS_STDEV, CPL_STATS_FLUX, - CPL_STATS_ABSFLUX, CPL_STATS_SQFLUX, - CPL_STATS_MINPOS, CPL_STATS_MAXPOS, - CPL_STATS_CENTROID, CPL_STATS_MEAN}; - FILE * stream; - unsigned itype; - cpl_boolean do_bench; - cpl_mask * ones; - cpl_error_code error; + const cpl_type img_types[] = { CPL_TYPE_DOUBLE, CPL_TYPE_FLOAT, + CPL_TYPE_INT }; + const cpl_stats_mode istats[] = { CPL_STATS_MIN, CPL_STATS_MAX, + CPL_STATS_MEDIAN, CPL_STATS_MEDIAN_DEV, + CPL_STATS_MAD, CPL_STATS_STDEV, + CPL_STATS_FLUX, CPL_STATS_ABSFLUX, + CPL_STATS_SQFLUX, CPL_STATS_MINPOS, + CPL_STATS_MAXPOS, CPL_STATS_CENTROID, + CPL_STATS_MEAN }; + FILE *stream; + unsigned itype; + cpl_boolean do_bench; + cpl_mask *ones; + cpl_error_code error; cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); do_bench = cpl_msg_get_level() <= CPL_MSG_INFO ? CPL_TRUE : CPL_FALSE; - stream = cpl_msg_get_level() > CPL_MSG_INFO - ? fopen("/dev/null", "a") : stdout; + stream = + cpl_msg_get_level() > CPL_MSG_INFO ? fopen("/dev/null", "a") : stdout; /* Test 1: NULL image */ - cpl_test_null( cpl_stats_new_from_image(NULL, CPL_STATS_ALL) ); + cpl_test_null(cpl_stats_new_from_image(NULL, CPL_STATS_ALL)); cpl_test_error(CPL_ERROR_NULL_INPUT); error = cpl_stats_dump(NULL, CPL_STATS_ALL, stream); @@ -172,17 +176,17 @@ error = cpl_mask_not(ones); cpl_test_eq_error(error, CPL_ERROR_NONE); - for (itype = 0; itype < sizeof(img_types)/sizeof(img_types[0]); itype++) { + for (itype = 0; itype < sizeof(img_types) / sizeof(img_types[0]); itype++) { const cpl_type img_type = img_types[itype]; - cpl_image * img = cpl_image_new(IMAGE_SIZE_X, IMAGE_SIZE_Y, img_type); - cpl_stats * statall; - cpl_stats * nullstat; - unsigned istat; - double med1, med2; - double sig1, sig2; + cpl_image *img = cpl_image_new(IMAGE_SIZE_X, IMAGE_SIZE_Y, img_type); + cpl_stats *statall; + cpl_stats *nullstat; + unsigned istat; + double med1, med2; + double sig1, sig2; - cpl_msg_info(cpl_func, "Testing %d X %d-image (type %u)", - IMAGE_SIZE_X, IMAGE_SIZE_Y, (unsigned)img_type); + cpl_msg_info(cpl_func, "Testing %d X %d-image (type %u)", IMAGE_SIZE_X, + IMAGE_SIZE_Y, (unsigned)img_type); cpl_test_nonnull(img); @@ -199,20 +203,19 @@ cpl_test_error(CPL_ERROR_UNSUPPORTED_MODE); cpl_test_null(nullstat); - nullstat = cpl_stats_new_from_image_window(img, CPL_STATS_ALL, 2, 2, - 1, 1); + nullstat = + cpl_stats_new_from_image_window(img, CPL_STATS_ALL, 2, 2, 1, 1); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); cpl_test_null(nullstat); - nullstat = cpl_stats_new_from_image_window(img, CPL_STATS_ALL, 1, 1, - IMAGE_SIZE_X, - IMAGE_SIZE_Y+1); + nullstat = + cpl_stats_new_from_image_window(img, CPL_STATS_ALL, 1, 1, + IMAGE_SIZE_X, IMAGE_SIZE_Y + 1); cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); cpl_test_null(nullstat); nullstat = cpl_stats_new_from_image_window(img, CPL_STATS_ALL, 0, 0, - IMAGE_SIZE_X, - IMAGE_SIZE_Y); + IMAGE_SIZE_X, IMAGE_SIZE_Y); cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); cpl_test_null(nullstat); @@ -238,13 +241,13 @@ cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); /* Test 5: Dump all */ - cpl_test_zero( cpl_stats_dump(statall, CPL_STATS_ALL, stream) ); + cpl_test_zero(cpl_stats_dump(statall, CPL_STATS_ALL, stream)); - for (istat = 0; istat < sizeof(istats)/sizeof(istats[0]); istat++) { - cpl_stats * statone; + for (istat = 0; istat < sizeof(istats) / sizeof(istats[0]); istat++) { + cpl_stats *statone; - cpl_test_nonnull( statone - = cpl_stats_new_from_image(img, istats[istat])); + cpl_test_nonnull(statone = + cpl_stats_new_from_image(img, istats[istat])); /* Test 6: Illegal dump on valid object */ error = cpl_stats_dump(statone, CPL_STATS_ALL | (~istats[istat]), @@ -290,31 +293,32 @@ CPL_STAT_CMP_IMAGE(centroid_x); CPL_STAT_CMP_IMAGE(centroid_y); - cpl_test_abs( cpl_stats_get_median(statall), - cpl_image_get_mad_window(img, 1, 1, IMAGE_SIZE_X, - IMAGE_SIZE_Y, &sig1), - 0.0); + cpl_test_abs(cpl_stats_get_median(statall), + cpl_image_get_mad_window(img, 1, 1, IMAGE_SIZE_X, + IMAGE_SIZE_Y, &sig1), + 0.0); - cpl_test_abs( cpl_stats_get_median(statall), - cpl_image_get_mad(img, &sig2), 0.0); + cpl_test_abs(cpl_stats_get_median(statall), + cpl_image_get_mad(img, &sig2), 0.0); - cpl_test_abs( sig1, sig2, 0.0); + cpl_test_abs(sig1, sig2, 0.0); /* Pixel values are not Gaussian, so the MAD cannot be used to estimate the standard deviation. */ - cpl_msg_info(cpl_func, "MAD as std.dev. estimator: MAD * 1.4826 = %g " - "<=> %g = st.dev.", sig1 * CPL_MATH_STD_MAD, - cpl_stats_get_stdev(statall)); - - cpl_test_abs( cpl_stats_get_median(statall), - cpl_image_get_median_dev_window(img, 1, 1, IMAGE_SIZE_X, - IMAGE_SIZE_Y, &sig1), - 0.0); + cpl_msg_info(cpl_func, + "MAD as std.dev. estimator: MAD * 1.4826 = %g " + "<=> %g = st.dev.", + sig1 * CPL_MATH_STD_MAD, cpl_stats_get_stdev(statall)); + + cpl_test_abs(cpl_stats_get_median(statall), + cpl_image_get_median_dev_window(img, 1, 1, IMAGE_SIZE_X, + IMAGE_SIZE_Y, &sig1), + 0.0); - cpl_test_abs( cpl_stats_get_median(statall), - cpl_image_get_median_dev(img, &sig2), 0.0); + cpl_test_abs(cpl_stats_get_median(statall), + cpl_image_get_median_dev(img, &sig2), 0.0); - cpl_test_abs( sig1, sig2, 0.0); + cpl_test_abs(sig1, sig2, 0.0); if (img_type == CPL_TYPE_DOUBLE) { /* FIXME: Tolerance needed for mean and stdev */ @@ -330,15 +334,16 @@ /* Test cpl_image_get_median_dev() */ med1 = cpl_image_get_median_dev(img, &sig1); - cpl_test_abs( med1, med2, 0.0 ); + cpl_test_abs(med1, med2, 0.0); + + cpl_test_leq(0.0, sig1); - cpl_test_leq( 0.0, sig1 ); - if (do_bench) { cpl_stats_new_all_bench(img, 500); cpl_stats_new_std_bench(img, 500); cpl_stats_new_median_bench(img, 100); - } else { + } + else { cpl_stats_new_all_bench(img, 1); cpl_stats_new_std_bench(img, 1); cpl_stats_new_median_bench(img, 1); @@ -357,12 +362,12 @@ (void)cpl_image_get_median_dev(NULL, &sig1); cpl_test_error(CPL_ERROR_NULL_INPUT); - } cpl_mask_delete(ones); - if (stream != stdout) cpl_test_zero( fclose(stream) ); + if (stream != stdout) + cpl_test_zero(fclose(stream)); return cpl_test_end(0); } @@ -376,18 +381,18 @@ @return void */ /*----------------------------------------------------------------------------*/ -static void cpl_stats_new_all_bench(const cpl_image * image, int n) +static void +cpl_stats_new_all_bench(const cpl_image *image, int n) { + double secs; + int i; - double secs; - int i; - - secs = cpl_test_get_cputime(); + secs = cpl_test_get_cputime(); for (i = 0; i < n; i++) { - cpl_stats * self - = cpl_stats_new_from_image_window(image, CPL_STATS_ALL, 2, 2, - IMAGE_SIZE_X-1, IMAGE_SIZE_Y-1); + cpl_stats *self = + cpl_stats_new_from_image_window(image, CPL_STATS_ALL, 2, 2, + IMAGE_SIZE_X - 1, IMAGE_SIZE_Y - 1); cpl_test_nonnull(self); @@ -396,8 +401,10 @@ secs = cpl_test_get_cputime() - secs; - cpl_msg_info(cpl_func,"Time spent computing %d %d X %d - sized image " - "statistics [s]: %g", n, IMAGE_SIZE_X, IMAGE_SIZE_Y, secs); + cpl_msg_info(cpl_func, + "Time spent computing %d %d X %d - sized image " + "statistics [s]: %g", + n, IMAGE_SIZE_X, IMAGE_SIZE_Y, secs); } @@ -410,20 +417,20 @@ @return void */ /*----------------------------------------------------------------------------*/ -static void cpl_stats_new_std_bench(const cpl_image * image, int n) +static void +cpl_stats_new_std_bench(const cpl_image *image, int n) { + double secs; + int i; - double secs; - int i; - - secs = cpl_test_get_cputime(); + secs = cpl_test_get_cputime(); for (i = 0; i < n; i++) { - cpl_stats * self - = cpl_stats_new_from_image_window(image, - CPL_STATS_MEAN | CPL_STATS_STDEV, - 2, 2, - IMAGE_SIZE_X-1, IMAGE_SIZE_Y-1); + cpl_stats *self = + cpl_stats_new_from_image_window(image, + CPL_STATS_MEAN | CPL_STATS_STDEV, 2, + 2, IMAGE_SIZE_X - 1, + IMAGE_SIZE_Y - 1); cpl_test_nonnull(self); @@ -432,8 +439,10 @@ secs = cpl_test_get_cputime() - secs; - cpl_msg_info(cpl_func,"Time spent computing %d %d X %d - sized image " - "mean and stdev [s]: %g", n, IMAGE_SIZE_X, IMAGE_SIZE_Y, secs); + cpl_msg_info(cpl_func, + "Time spent computing %d %d X %d - sized image " + "mean and stdev [s]: %g", + n, IMAGE_SIZE_X, IMAGE_SIZE_Y, secs); } /*----------------------------------------------------------------------------*/ @@ -445,18 +454,18 @@ @return void */ /*----------------------------------------------------------------------------*/ -static void cpl_stats_new_median_bench(const cpl_image * image, int n) +static void +cpl_stats_new_median_bench(const cpl_image *image, int n) { + double secs; + int i; - double secs; - int i; - - secs = cpl_test_get_cputime(); + secs = cpl_test_get_cputime(); for (i = 0; i < n; i++) { - cpl_stats * self - = cpl_stats_new_from_image_window(image, CPL_STATS_MEDIAN, 2, 2, - IMAGE_SIZE_X-1, IMAGE_SIZE_Y-1); + cpl_stats *self = + cpl_stats_new_from_image_window(image, CPL_STATS_MEDIAN, 2, 2, + IMAGE_SIZE_X - 1, IMAGE_SIZE_Y - 1); cpl_test_nonnull(self); @@ -465,6 +474,8 @@ secs = cpl_test_get_cputime() - secs; - cpl_msg_info(cpl_func,"Time spent computing %d %d X %d - sized image " - "median [s]: %g", n, IMAGE_SIZE_X, IMAGE_SIZE_Y, secs); + cpl_msg_info(cpl_func, + "Time spent computing %d %d X %d - sized image " + "median [s]: %g", + n, IMAGE_SIZE_X, IMAGE_SIZE_Y, secs); } diff -Nru cpl-7.1.4+ds/cplcore/tests/cpl_table-test.c cpl-7.2.2+ds/cplcore/tests/cpl_table-test.c --- cpl-7.1.4+ds/cplcore/tests/cpl_table-test.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/tests/cpl_table-test.c 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -31,8 +31,8 @@ #include "cpl_table.h" #include "cpl_math_const.h" -#include "cpl_test.h" #include "cpl_memory.h" +#include "cpl_test.h" #include @@ -63,13 +63,13 @@ * m = message */ -#define test_data(r,f,m) \ - do { \ - cpl_msg_info("test_data", "%s", m); \ - r = f; \ - cpl_assert(r != NULL); \ - cpl_test_error(CPL_ERROR_NONE); \ - } while (0) \ +#define test_data(r, f, m) \ + do { \ + cpl_msg_info("test_data", "%s", m); \ + r = f; \ + cpl_assert(r != NULL); \ + cpl_test_error(CPL_ERROR_NONE); \ + } while (0) /* @@ -79,12 +79,12 @@ * m = message */ -#define test(f,m) \ - do { \ - cpl_msg_info("test", "%s", m); \ - cpl_test_zero(f); \ - cpl_test_error(CPL_ERROR_NONE); \ - } while (0) +#define test(f, m) \ + do { \ + cpl_msg_info("test", "%s", m); \ + cpl_test_zero(f); \ + cpl_test_error(CPL_ERROR_NONE); \ + } while (0) /* * Test for expected failure in functions returning 0 on success. @@ -94,11 +94,11 @@ * m = message */ -#define test_failure(e,f,m) \ - do { \ - cpl_msg_info("test_failure", "%s", m); \ - cpl_test_eq_error(f, e); \ - } while (0) +#define test_failure(e, f, m) \ + do { \ + cpl_msg_info("test_failure", "%s", m); \ + cpl_test_eq_error(f, e); \ + } while (0) /* * Test for functions returning an expected integer value. @@ -108,12 +108,12 @@ * m = message */ -#define test_ivalue(e,f,m) \ - do { \ - cpl_msg_info("test_ivalue", "%s", m); \ - cpl_test_eq(f, e); \ - cpl_test_error(CPL_ERROR_NONE); \ - } while (0) +#define test_ivalue(e, f, m) \ + do { \ + cpl_msg_info("test_ivalue", "%s", m); \ + cpl_test_eq(f, e); \ + cpl_test_error(CPL_ERROR_NONE); \ + } while (0) /* * Test for functions returning an expected pointer value. @@ -123,12 +123,12 @@ * m = message */ -#define test_pvalue(e,f,m) \ - do { \ - cpl_msg_info("test_pvalue", "%s", m); \ - cpl_test_eq_ptr(f, e); \ - cpl_test_error(CPL_ERROR_NONE); \ - } while (0) +#define test_pvalue(e, f, m) \ + do { \ + cpl_msg_info("test_pvalue", "%s", m); \ + cpl_test_eq_ptr(f, e); \ + cpl_test_error(CPL_ERROR_NONE); \ + } while (0) /* * Test for functions returning an expected floating point value. @@ -139,12 +139,12 @@ * m = message */ -#define test_fvalue(e,t,f,m) \ - do { \ - cpl_msg_info("test_fvalue", "%s", m); \ - cpl_test_abs(f, e, t); \ - cpl_test_error(CPL_ERROR_NONE); \ - } while (0) +#define test_fvalue(e, t, f, m) \ + do { \ + cpl_msg_info("test_fvalue", "%s", m); \ + cpl_test_abs(f, e, t); \ + cpl_test_error(CPL_ERROR_NONE); \ + } while (0) /* * Test for functions returning an expected complex value. @@ -155,13 +155,13 @@ * m = message */ -#define test_cvalue(e,t,f,m) \ - do { \ - cpl_msg_info("test_cvalue", "%s", m); \ - cpl_test_abs_complex(f, e, t); \ - cpl_test_error(CPL_ERROR_NONE); \ - } while (0) - +#define test_cvalue(e, t, f, m) \ + do { \ + cpl_msg_info("test_cvalue", "%s", m); \ + cpl_test_abs_complex(f, e, t); \ + cpl_test_error(CPL_ERROR_NONE); \ + } while (0) + /* * Test for functions returning an expected character string. * @@ -170,12 +170,12 @@ * m = message */ -#define test_svalue(e,f,m) \ - do { \ - cpl_msg_info("test_svalue", "%s", m); \ - cpl_test_eq_string(f, e); \ - cpl_test_error(CPL_ERROR_NONE); \ - } while (0) +#define test_svalue(e, f, m) \ + do { \ + cpl_msg_info("test_svalue", "%s", m); \ + cpl_test_eq_string(f, e); \ + cpl_test_error(CPL_ERROR_NONE); \ + } while (0) /*----------------------------------------------------------------------------- Private function prototypes @@ -194,9 +194,9 @@ Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { - cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); /* @@ -211,9 +211,6 @@ cpl_table_test_large(NROWS_LARGE); return cpl_test_end(0); - - - } /*----------------------------------------------------------------------------*/ @@ -223,44 +220,44 @@ @return Zero iff successful */ /*----------------------------------------------------------------------------*/ -static int cpl_table_test_main(void) +static int +cpl_table_test_main(void) { - - int nrows = NROWS; - int i, j, k, null; - char message[80]; - - int *iArray; - long long *llArray; - float *fArray; - double *dArray; - double *ddArray; + int nrows = NROWS; + int i, j, k, null; + char message[80]; + + int *iArray; + long long *llArray; + float *fArray; + double *dArray; + double *ddArray; #ifdef _Complex_I - float complex *cfArray; - double complex *cdArray; - double complex *cddArray; -#endif - char **sArray; - - int icheck[25]; - float fcheck[25]; - double dcheck[25]; + float complex *cfArray; + double complex *cdArray; + double complex *cddArray; +#endif + char **sArray; + + int icheck[25]; + float fcheck[25]; + double dcheck[25]; #ifdef _Complex_I - float complex cfcheck[25]; - double complex cdcheck[25]; + float complex cfcheck[25]; + double complex cdcheck[25]; #endif - const char *scheck[25]; + const char *scheck[25]; - const char *names[2]; + const char *names[2]; - cpl_table *table; - cpl_table *copia; - cpl_array *array; - cpl_array *new_array; - cpl_array *colnames; + cpl_table *table; + cpl_table *copia; + cpl_array *array; + cpl_array *new_array; + cpl_array *colnames; - cpl_propertylist *reflist; - cpl_error_code error; + cpl_propertylist *reflist; + cpl_error_code error; iArray = cpl_malloc(nrows * sizeof(int)); @@ -355,4341 +352,4465 @@ sArray[9] = cpl_strdup("daaa"); - /* - * Testing tables with more rows - */ + /* + * Testing tables with more rows + */ - test_data(table, cpl_table_new(nrows), "Creating the test table... "); + test_data(table, cpl_table_new(nrows), "Creating the test table... "); - test(cpl_table_wrap_int(table, iArray, "Integer"), - "Wrapping the Integer column... "); + test(cpl_table_wrap_int(table, iArray, "Integer"), + "Wrapping the Integer column... "); - test_pvalue(iArray, cpl_table_unwrap(table, "Integer"), - "Unwrap the Integer column data... "); + test_pvalue(iArray, cpl_table_unwrap(table, "Integer"), + "Unwrap the Integer column data... "); - test(cpl_table_wrap_int(table, iArray, "Integer"), - "Creating the Integer column... "); + test(cpl_table_wrap_int(table, iArray, "Integer"), + "Creating the Integer column... "); - test(cpl_table_wrap_long_long(table, llArray, "LongLong"), - "Creating the LongLong column... "); + test(cpl_table_wrap_long_long(table, llArray, "LongLong"), + "Creating the LongLong column... "); - test(cpl_table_wrap_double(table, dArray, "Double"), - "Creating the Double column... "); + test(cpl_table_wrap_double(table, dArray, "Double"), + "Creating the Double column... "); - test(cpl_table_wrap_double(table, ddArray, "DoubleDouble"), - "Creating the DoubleDouble column... "); + test(cpl_table_wrap_double(table, ddArray, "DoubleDouble"), + "Creating the DoubleDouble column... "); #ifdef _Complex_I - test(cpl_table_wrap_double_complex(table, cdArray, "CDouble"), - "Creating the CDouble column... "); + test(cpl_table_wrap_double_complex(table, cdArray, "CDouble"), + "Creating the CDouble column... "); - test(cpl_table_wrap_double_complex(table, cddArray, "CDoubleDouble"), - "Creating the CDoubleDouble column... "); + test(cpl_table_wrap_double_complex(table, cddArray, "CDoubleDouble"), + "Creating the CDoubleDouble column... "); #endif - test(cpl_table_wrap_string(table, sArray, "String"), - "Creating the String column... "); + test(cpl_table_wrap_string(table, sArray, "String"), + "Creating the String column... "); - test(cpl_table_new_column(table, "Float", CPL_TYPE_FLOAT), - "Creating the Float column... "); + test(cpl_table_new_column(table, "Float", CPL_TYPE_FLOAT), + "Creating the Float column... "); - for (i = 0; i < nrows; i++) { - sprintf(message, "Writing to row %d of the Float column... ", i); - test(cpl_table_set_float(table, "Float", i, fArray[i]), message); - } + for (i = 0; i < nrows; i++) { + sprintf(message, "Writing to row %d of the Float column... ", i); + test(cpl_table_set_float(table, "Float", i, fArray[i]), message); + } - test(cpl_table_new_column(table, "CFloat", CPL_TYPE_FLOAT_COMPLEX), - "Creating the CFloat column... "); + test(cpl_table_new_column(table, "CFloat", CPL_TYPE_FLOAT_COMPLEX), + "Creating the CFloat column... "); #ifdef _Complex_I - for (i = 0; i < nrows; i++) { - sprintf(message, "Writing to row %d of the CFloat column... ", i); - test(cpl_table_set_float_complex(table, "CFloat", i, cfArray[i]), message); - } -#endif - - test(cpl_table_new_column_array(table, "AInt", - CPL_TYPE_INT | CPL_TYPE_POINTER, 20), - "Creating the ArrayInt column... "); - - test(cpl_table_new_column_array(table, "ALongLong", - CPL_TYPE_LONG_LONG | CPL_TYPE_POINTER, 20), - "Creating the ArrayLongLong column... "); - - test(cpl_table_new_column_array(table, "AFloat", CPL_TYPE_FLOAT, 20), - "Creating the ArrayFloat column... "); - - test(cpl_table_new_column_array(table, "ADouble", - CPL_TYPE_DOUBLE | CPL_TYPE_POINTER, 20), - "Creating the ArrayDouble column... "); - - test(cpl_table_new_column_array(table, "CAFloat", CPL_TYPE_FLOAT_COMPLEX, 20), - "Creating the CArrayFloat column... "); - - test(cpl_table_new_column_array(table, "CADouble", - CPL_TYPE_DOUBLE_COMPLEX | CPL_TYPE_POINTER, 20), - "Creating the CArrayDouble column... "); - - test(cpl_table_new_column_array(table, "AString", CPL_TYPE_STRING, 10), - "Creating the ArrayString column... "); - - test_ivalue(20, cpl_table_get_column_depth(table, "AInt"), - "Check \"AInt\" depth (2)... "); - - k = 0; - array = cpl_array_new(20, CPL_TYPE_INT); - for (i = 0; i < nrows; i++) { - for (j = 0; j < 20; j++) { - sprintf(message, - "Writing element %d of array %d of the AInt column... ", j, i); - k++; - test(cpl_array_set_int(array, j, k), message); - } - sprintf(message, "Setting array at position %d of the AInt column... ", i); - test(cpl_table_set_array(table, "AInt", i, array), message); - } - new_array = cpl_array_cast(array, CPL_TYPE_DOUBLE); - cpl_array_delete(new_array); - cpl_array_delete(array); - - k = 0; - for (i = 0; i < nrows; i++) { - sprintf(message, "Getting array %d of the AInt column... ", i); - test_data(array, (cpl_array *)cpl_table_get_array(table, "AInt", i), - message); - for (j = 0; j < 20; j++) { - sprintf(message, - "Reading element %d of array %d of the AInt column... ", j, i); - k++; - test_ivalue(k, cpl_array_get_int(array, j, &null), message); - cpl_test_zero(null); - } - } - - k = 0; - array = cpl_array_new(20, CPL_TYPE_LONG_LONG); - for (i = 0; i < nrows; i++) { - for (j = 0; j < 20; j++) { - sprintf(message, - "Writing element %d of array %d of the ALongLong column... ", j, i); - k++; - test(cpl_array_set_long_long(array, j, k), message); - } - sprintf(message, "Setting array at position %d of the ALongLong column... ", i); - test(cpl_table_set_array(table, "ALongLong", i, array), message); - } - new_array = cpl_array_cast(array, CPL_TYPE_DOUBLE); - cpl_array_delete(new_array); - cpl_array_delete(array); - - k = 0; - for (i = 0; i < nrows; i++) { - sprintf(message, "Getting array %d of the ALongLong column... ", i); - test_data(array, (cpl_array *)cpl_table_get_array(table, "ALongLong", i), - message); - for (j = 0; j < 20; j++) { - sprintf(message, - "Reading element %d of array %d of the ALongLong column... ", j, i); - k++; - test_ivalue((long long)k, cpl_array_get_long_long(array, j, &null), message); - cpl_test_zero(null); - } - } - - k = 0; - array = cpl_array_new(20, CPL_TYPE_FLOAT); - for (i = 0; i < nrows; i++) { - for (j = 0; j < 20; j++) { - sprintf(message, - "Writing element %d of array %d of the AFloat column... ", j, i); - k++; - test(cpl_array_set_float(array, j, k), message); - } - sprintf(message, - "Setting array at position %d of the AFloat column... ", i); - test(cpl_table_set_array(table, "AFloat", i, array), message); - } - new_array = cpl_array_cast(array, CPL_TYPE_INT); - cpl_array_delete(new_array); - cpl_array_delete(array); - - k = 0; - for (i = 0; i < nrows; i++) { - sprintf(message, "Getting array %d of the AFloat column... ", i); - test_data(array, (cpl_array *)cpl_table_get_array(table, "AFloat", i), - message); - for (j = 0; j < 20; j++) { - sprintf(message, - "Reading element %d of array %d of the AFloat column... ", j, i); - k++; - test_fvalue((float)k, 0.0001, - cpl_array_get_float(array, j, &null), message); - cpl_test_zero(null); + for (i = 0; i < nrows; i++) { + sprintf(message, "Writing to row %d of the CFloat column... ", i); + test(cpl_table_set_float_complex(table, "CFloat", i, cfArray[i]), + message); } - } +#endif -#ifdef _Complex_I - k = 0; - array = cpl_array_new(20, CPL_TYPE_FLOAT_COMPLEX); - for (i = 0; i < nrows; i++) { - for (j = 0; j < 20; j++) { - sprintf(message, - "Writing element %d of array %d of the CAFloat column... ", j, i); - k++; - test(cpl_array_set_float_complex(array, j, k + k * I), message); - } - sprintf(message, - "Setting array at position %d of the CAFloat column... ", i); - test(cpl_table_set_array(table, "CAFloat", i, array), message); - } - - cpl_array_delete(array); - - - k = 0; - for (i = 0; i < nrows; i++) { - sprintf(message, "Getting array %d of the CAFloat column... ", i); - test_data(array, (cpl_array *)cpl_table_get_array(table, "CAFloat", i), - message); - for (j = 0; j < 20; j++) { - sprintf(message, - "Reading element %d of array %d of the CAFloat column... ", j, i); - k++; - test_cvalue(k + k * I, 0.0001, - cpl_array_get_float_complex(array, j, &null), message); + test(cpl_table_new_column_array(table, "AInt", + CPL_TYPE_INT | CPL_TYPE_POINTER, 20), + "Creating the ArrayInt column... "); + + test(cpl_table_new_column_array(table, "ALongLong", + CPL_TYPE_LONG_LONG | CPL_TYPE_POINTER, 20), + "Creating the ArrayLongLong column... "); + + test(cpl_table_new_column_array(table, "AFloat", CPL_TYPE_FLOAT, 20), + "Creating the ArrayFloat column... "); + + test(cpl_table_new_column_array(table, "ADouble", + CPL_TYPE_DOUBLE | CPL_TYPE_POINTER, 20), + "Creating the ArrayDouble column... "); + + test(cpl_table_new_column_array(table, "CAFloat", CPL_TYPE_FLOAT_COMPLEX, + 20), + "Creating the CArrayFloat column... "); + + test(cpl_table_new_column_array(table, "CADouble", + CPL_TYPE_DOUBLE_COMPLEX | CPL_TYPE_POINTER, + 20), + "Creating the CArrayDouble column... "); + + test(cpl_table_new_column_array(table, "AString", CPL_TYPE_STRING, 10), + "Creating the ArrayString column... "); + + test_ivalue(20, cpl_table_get_column_depth(table, "AInt"), + "Check \"AInt\" depth (2)... "); + + k = 0; + array = cpl_array_new(20, CPL_TYPE_INT); + for (i = 0; i < nrows; i++) { + for (j = 0; j < 20; j++) { + sprintf(message, + "Writing element %d of array %d of the AInt column... ", j, + i); + k++; + test(cpl_array_set_int(array, j, k), message); + } + sprintf(message, "Setting array at position %d of the AInt column... ", + i); + test(cpl_table_set_array(table, "AInt", i, array), message); + } + new_array = cpl_array_cast(array, CPL_TYPE_DOUBLE); + cpl_array_delete(new_array); + cpl_array_delete(array); + + k = 0; + for (i = 0; i < nrows; i++) { + sprintf(message, "Getting array %d of the AInt column... ", i); + test_data(array, (cpl_array *)cpl_table_get_array(table, "AInt", i), + message); + for (j = 0; j < 20; j++) { + sprintf(message, + "Reading element %d of array %d of the AInt column... ", j, + i); + k++; + test_ivalue(k, cpl_array_get_int(array, j, &null), message); cpl_test_zero(null); + } } - } -#endif - k = 0; - array = cpl_array_new(20, CPL_TYPE_DOUBLE); - for (i = 0; i < nrows; i++) { - for (j = 0; j < 20; j++) { - sprintf(message, - "Writing element %d of array %d of the ADouble column... ", j, i); - k++; - test(cpl_array_set_double(array, j, k), message); - } - sprintf(message, - "Setting array at position %d of the ADouble column... ", i); - test(cpl_table_set_array(table, "ADouble", i, array), message); - } - cpl_array_delete(array); - - k = 0; - for (i = 0; i < nrows; i++) { - sprintf(message, "Getting array %d of the ADouble column... ", i); - test_data(array, (cpl_array *)cpl_table_get_array(table, "ADouble", i), - message); - for (j = 0; j < 20; j++) { - sprintf(message, - "Reading element %d of array %d of the ADouble column... ", j, i); - k++; - test_fvalue((float)k, 0.0001, - cpl_array_get_double(array, j, &null), message); + k = 0; + array = cpl_array_new(20, CPL_TYPE_LONG_LONG); + for (i = 0; i < nrows; i++) { + for (j = 0; j < 20; j++) { + sprintf( + message, + "Writing element %d of array %d of the ALongLong column... ", j, + i); + k++; + test(cpl_array_set_long_long(array, j, k), message); + } + sprintf(message, + "Setting array at position %d of the ALongLong column... ", i); + test(cpl_table_set_array(table, "ALongLong", i, array), message); + } + new_array = cpl_array_cast(array, CPL_TYPE_DOUBLE); + cpl_array_delete(new_array); + cpl_array_delete(array); + + k = 0; + for (i = 0; i < nrows; i++) { + sprintf(message, "Getting array %d of the ALongLong column... ", i); + test_data(array, + (cpl_array *)cpl_table_get_array(table, "ALongLong", i), + message); + for (j = 0; j < 20; j++) { + sprintf( + message, + "Reading element %d of array %d of the ALongLong column... ", j, + i); + k++; + test_ivalue((long long)k, cpl_array_get_long_long(array, j, &null), + message); cpl_test_zero(null); + } } - } + k = 0; + array = cpl_array_new(20, CPL_TYPE_FLOAT); + for (i = 0; i < nrows; i++) { + for (j = 0; j < 20; j++) { + sprintf(message, + "Writing element %d of array %d of the AFloat column... ", + j, i); + k++; + test(cpl_array_set_float(array, j, k), message); + } + sprintf(message, + "Setting array at position %d of the AFloat column... ", i); + test(cpl_table_set_array(table, "AFloat", i, array), message); + } + new_array = cpl_array_cast(array, CPL_TYPE_INT); + cpl_array_delete(new_array); + cpl_array_delete(array); + + k = 0; + for (i = 0; i < nrows; i++) { + sprintf(message, "Getting array %d of the AFloat column... ", i); + test_data(array, (cpl_array *)cpl_table_get_array(table, "AFloat", i), + message); + for (j = 0; j < 20; j++) { + sprintf(message, + "Reading element %d of array %d of the AFloat column... ", + j, i); + k++; + test_fvalue((float)k, 0.0001, cpl_array_get_float(array, j, &null), + message); + cpl_test_zero(null); + } + } #ifdef _Complex_I - k = 0; - array = cpl_array_new(20, CPL_TYPE_DOUBLE_COMPLEX); - for (i = 0; i < nrows; i++) { - for (j = 0; j < 20; j++) { - sprintf(message, - "Writing element %d of array %d of the CADouble column... ", j, i); - k++; - test(cpl_array_set_double_complex(array, j, k + k * I), message); - } - sprintf(message, - "Setting array at position %d of the CADouble column... ", i); - test(cpl_table_set_array(table, "CADouble", i, array), message); - } - - cpl_array_delete(array); - - k = 0; - for (i = 0; i < nrows; i++) { - sprintf(message, "Getting array %d of the CADouble column... ", i); - test_data(array, (cpl_array *)cpl_table_get_array(table, "CADouble", i), - message); - for (j = 0; j < 20; j++) { - sprintf(message, - "Reading element %d of array %d of the CADouble column... ", j, i); - k++; - test_cvalue(k + k * I, 0.0001, - cpl_array_get_double_complex(array, j, &null), message); + k = 0; + array = cpl_array_new(20, CPL_TYPE_FLOAT_COMPLEX); + for (i = 0; i < nrows; i++) { + for (j = 0; j < 20; j++) { + sprintf(message, + "Writing element %d of array %d of the CAFloat column... ", + j, i); + k++; + test(cpl_array_set_float_complex(array, j, k + k * I), message); + } + sprintf(message, + "Setting array at position %d of the CAFloat column... ", i); + test(cpl_table_set_array(table, "CAFloat", i, array), message); + } + + cpl_array_delete(array); + + + k = 0; + for (i = 0; i < nrows; i++) { + sprintf(message, "Getting array %d of the CAFloat column... ", i); + test_data(array, (cpl_array *)cpl_table_get_array(table, "CAFloat", i), + message); + for (j = 0; j < 20; j++) { + sprintf(message, + "Reading element %d of array %d of the CAFloat column... ", + j, i); + k++; + test_cvalue(k + k * I, 0.0001, + cpl_array_get_float_complex(array, j, &null), message); cpl_test_zero(null); + } } - } #endif - test_ivalue(20, cpl_table_get_column_depth(table, "AInt"), - "Check \"AInt\" depth (3)... "); + k = 0; + array = cpl_array_new(20, CPL_TYPE_DOUBLE); + for (i = 0; i < nrows; i++) { + for (j = 0; j < 20; j++) { + sprintf(message, + "Writing element %d of array %d of the ADouble column... ", + j, i); + k++; + test(cpl_array_set_double(array, j, k), message); + } + sprintf(message, + "Setting array at position %d of the ADouble column... ", i); + test(cpl_table_set_array(table, "ADouble", i, array), message); + } + cpl_array_delete(array); - test_data(array, (cpl_array *)cpl_table_get_array(table, "AInt", 0), - "Get AInt array "); - test_ivalue(CPL_TYPE_INT, cpl_array_get_type(array), - "Array AInt must be int... "); - - test_ivalue(10, cpl_table_get_nrow(table), "Check table length (1)... "); - test_ivalue(16, cpl_table_get_ncol(table), "Check table width... "); - - test_failure(CPL_ERROR_DATA_NOT_FOUND, - cpl_table_erase_column(table, "Diable"), - "Trying to delete a not existing column... "); - - test(cpl_table_erase_column(table, "DoubleDouble"), - "Delete column \"DoubleDouble\"... "); - - test_ivalue(15, cpl_table_get_ncol(table), "Check again table width... "); - - test_ivalue(CPL_TYPE_INT, cpl_table_get_column_type(table, "Integer"), - "Column Integer must be int... "); - test_ivalue(CPL_TYPE_DOUBLE, cpl_table_get_column_type(table, "Double"), - "Column Double must be double... "); - test_ivalue(CPL_TYPE_STRING, cpl_table_get_column_type(table, "String"), - "Column String must be char*... "); - test_ivalue(CPL_TYPE_FLOAT, cpl_table_get_column_type(table, "Float"), - "Column Float must be float... "); - test_ivalue(CPL_TYPE_FLOAT_COMPLEX, - cpl_table_get_column_type(table, "CFloat"), - "Column CFloat must be float complex... "); - test_ivalue(CPL_TYPE_DOUBLE_COMPLEX, - cpl_table_get_column_type(table, "CDouble"), - "Column CDouble must be double complex... "); - test_ivalue((CPL_TYPE_INT | CPL_TYPE_POINTER), - cpl_table_get_column_type(table, "AInt"), - "Column AInt must be arrays of int... "); - test_ivalue((CPL_TYPE_DOUBLE | CPL_TYPE_POINTER), - cpl_table_get_column_type(table, "ADouble"), - "Column Double must be arrays of double... "); - test_ivalue((CPL_TYPE_FLOAT | CPL_TYPE_POINTER), - cpl_table_get_column_type(table, "AFloat"), - "Column Float must be arrays of float... "); - test_ivalue((CPL_TYPE_FLOAT_COMPLEX | CPL_TYPE_POINTER), - cpl_table_get_column_type(table, "CAFloat"), - "Column CAFloat must be arrays of float complex... "); - test_ivalue((CPL_TYPE_DOUBLE_COMPLEX | CPL_TYPE_POINTER), - cpl_table_get_column_type(table, "CADouble"), - "Column CADouble must be arrays of double complex... "); - test_pvalue(iArray, cpl_table_get_data_int(table, "Integer"), - "Check pointer to column Integer data... "); - - test_pvalue(dArray, cpl_table_get_data_double(table, "Double"), - "Check pointer to column Double data... "); - test_pvalue(sArray, cpl_table_get_data_string(table, "String"), - "Check pointer to column String data... "); - - copia = cpl_table_new(5); - - error = cpl_table_set_column_unit(table, "Integer", "Counts"); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_set_column_unit(table, "Double", "erg/sec"); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_set_column_unit(table, "String", "Name"); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_set_column_unit(table, "AFloat", "erg/sec"); - cpl_test_eq_error(error, CPL_ERROR_NONE); - - test(cpl_table_copy_structure(copia, table), - "Creating a new cpl_table modeled on an existing cpl_table... "); - - test_ivalue(5, cpl_table_get_nrow(copia), "Check table length (2)... "); - test_ivalue(15, cpl_table_get_ncol(copia), "Check table width... "); - - test(cpl_table_compare_structure(table, copia), - "Tables must have the same structure... "); - cpl_table_erase_column(copia, "Double"); - test_ivalue(1, cpl_table_compare_structure(table, copia), - "Deleting column Double - now tables must have different structure... "); - test(cpl_table_new_column(copia, "Double", CPL_TYPE_DOUBLE), - "Creating again the Double column... "); - error = cpl_table_set_column_unit(copia, "Double", "erg/sec"); - cpl_test_eq_error(error, CPL_ERROR_NONE); - test(cpl_table_compare_structure(table, copia), - "Tables must have the same structure again... "); - - test(cpl_table_fill_column_window_int(copia, "Integer", 0, 5, -1), - "Fill column Integer of new table... "); - test(cpl_table_fill_column_window_long_long(copia, "LongLong", 0, 5, -1), - "Fill column LongLong of new table... "); - test(cpl_table_fill_column_window_double(copia, "Double", 0, 5, -1.11), - "Fill column Double of new table... "); - test(cpl_table_fill_column_window_float(copia, "Float", 0, 5, -1.1), - "Fill column Float of new table... "); + k = 0; + for (i = 0; i < nrows; i++) { + sprintf(message, "Getting array %d of the ADouble column... ", i); + test_data(array, (cpl_array *)cpl_table_get_array(table, "ADouble", i), + message); + for (j = 0; j < 20; j++) { + sprintf(message, + "Reading element %d of array %d of the ADouble column... ", + j, i); + k++; + test_fvalue((float)k, 0.0001, cpl_array_get_double(array, j, &null), + message); + cpl_test_zero(null); + } + } -#ifdef _Complex_I - test(cpl_table_fill_column_window_double_complex(copia, "CDouble", - 0, 5, -1.11 + 4.11 * I), - "Fill column CDouble of new table... "); - - test(cpl_table_fill_column_window_float_complex(copia, "CFloat", - 0, 5, -1.1 + 4.1 * I), - "Fill column CFloat of new table... "); -#endif - test(cpl_table_fill_column_window_string(copia, "String", 0, 5, "extra"), - "Fill column String of new table... "); - - array = cpl_array_new(20, CPL_TYPE_INT); - for (j = 0; j < 20; j++) - cpl_array_set_int(array, j, j); - test(cpl_table_fill_column_window_array(copia, "AInt", 0, 5, array), - "Fill column AInt of new table... "); - cpl_array_delete(array); - - array = cpl_array_new(20, CPL_TYPE_LONG_LONG); - for (j = 0; j < 20; j++) - cpl_array_set_long_long(array, j, j); - test(cpl_table_fill_column_window_array(copia, "ALongLong", 0, 5, array), - "Fill column ALongLong of new table... "); - cpl_array_delete(array); - - array = cpl_array_new(20, CPL_TYPE_FLOAT); - for (j = 0; j < 20; j++) - cpl_array_set_float(array, j, j); - test(cpl_table_fill_column_window_array(copia, "AFloat", 0, 5, array), - "Fill column AFloat of new table... "); - cpl_array_delete(array); - - array = cpl_array_new(20, CPL_TYPE_DOUBLE); - for (j = 0; j < 20; j++) - cpl_array_set_double(array, j, j); - test(cpl_table_fill_column_window_array(copia, "ADouble", 0, 5, array), - "Fill column ADouble of new table... "); - cpl_array_delete(array); #ifdef _Complex_I - array = cpl_array_new(20, CPL_TYPE_FLOAT_COMPLEX); - for (j = 0; j < 20; j++) - cpl_array_set_float_complex(array, j, j + 0.5*I); - test(cpl_table_fill_column_window_array(copia, "CAFloat", 0, 5, array), - "Fill column CAFloat of new table... "); - cpl_array_delete(array); - - array = cpl_array_new(20, CPL_TYPE_DOUBLE_COMPLEX); - for (j = 0; j < 20; j++) - cpl_array_set_double_complex(array, j, j + 0.5*I); - test(cpl_table_fill_column_window_array(copia, "CADouble", 0, 5, array), - "Fill column CADouble of new table... "); - cpl_array_delete(array); -#endif - - array = cpl_array_wrap_string(sArray, 10); - test(cpl_table_fill_column_window_array(copia, "AString", 0, 5, array), - "Fill column AString of new table... "); - cpl_array_unwrap(array); - - - test(cpl_table_insert(table, copia, 15), - "Appending new table to old table... "); - test(cpl_table_insert(table, copia, 5), - "Inserting new table in old table... "); - test(cpl_table_insert(table, copia, 0), - "Prepending new table to old table... "); - - cpl_table_delete(copia); - -/**+ FIXME: RESTORE!!! */ - error = cpl_table_fill_invalid_int(table, "Integer", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_int(table, "AInt", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_long_long(table, "LongLong", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_long_long(table, "ALongLong", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_save(table, NULL, NULL, BASE "2.fits", CPL_IO_CREATE); - cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_fits(BASE "2.fits"); - cpl_table_delete(table); - table = cpl_table_load(BASE "2.fits", 1, 1); - cpl_test_nonnull(table); - // FIXME: IO_APPEND initial test only! - cpl_table_save(table, NULL, NULL, BASE "2a.fits", CPL_IO_CREATE); - cpl_table_save(table, NULL, NULL, BASE "2a.fits", CPL_IO_APPEND); - cpl_test_fits(BASE "2a.fits"); -/**/ - - test_ivalue(25, cpl_table_get_nrow(table), "Check table length (3)... "); - - icheck[0] = -1; - icheck[1] = -1; - icheck[2] = -1; - icheck[3] = -1; - icheck[4] = -1; - icheck[5] = 5; - icheck[6] = 0; - icheck[7] = 2; - icheck[8] = 8; - icheck[9] = 9; - icheck[10] = -1; - icheck[11] = -1; - icheck[12] = -1; - icheck[13] = -1; - icheck[14] = -1; - icheck[15] = 3; - icheck[16] = 7; - icheck[17] = 1; - icheck[18] = 4; - icheck[19] = 6; - icheck[20] = -1; - icheck[21] = -1; - icheck[22] = -1; - icheck[23] = -1; - icheck[24] = -1; - - for (i = 0; i < 25; i++) { - test_ivalue(icheck[i], cpl_table_get_int(table, "Integer", i, &null), - "Check Integer column... "); - cpl_test_zero(null); - } - - for (i = 0; i < 25; i++) { - test_ivalue(icheck[i], cpl_table_get_long_long(table, "LongLong", - i, &null), - "Check LongLong column... "); - cpl_test_zero(null); - } - - dcheck[0] = -1.1100; - dcheck[1] = -1.1100; - dcheck[2] = -1.1100; - dcheck[3] = -1.1100; - dcheck[4] = -1.1100; - dcheck[5] = 5.1100; - dcheck[6] = 0.1100; - dcheck[7] = 2.1100; - dcheck[8] = 8.1100; - dcheck[9] = 9.1100; - dcheck[10] = -1.1100; - dcheck[11] = -1.1100; - dcheck[12] = -1.1100; - dcheck[13] = -1.1100; - dcheck[14] = -1.1100; - dcheck[15] = 3.1100; - dcheck[16] = 7.1100; - dcheck[17] = 1.1100; - dcheck[18] = 4.1100; - dcheck[19] = 6.1100; - dcheck[20] = -1.1100; - dcheck[21] = -1.1100; - dcheck[22] = -1.1100; - dcheck[23] = -1.1100; - dcheck[24] = -1.1100; - - for (i = 0; i < 25; i++) { - test_fvalue(dcheck[i], 0.00001, - cpl_table_get_double(table, "Double", i, &null), - "Check Double column... "); - cpl_test_zero(null); - } - - scheck[0] = "extra"; - scheck[1] = "extra"; - scheck[2] = "extra"; - scheck[3] = "extra"; - scheck[4] = "extra"; - scheck[5] = "caaaa"; - scheck[6] = "abcd"; - scheck[7] = "aaaa"; - scheck[8] = "daaa"; - scheck[9] = "acde"; - scheck[10] = "extra"; - scheck[11] = "extra"; - scheck[12] = "extra"; - scheck[13] = "extra"; - scheck[14] = "extra"; - scheck[15] = "baaa"; - scheck[16] = "aaaa"; - scheck[17] = "acde"; - scheck[18] = " sss"; - scheck[19] = "daaa"; - scheck[20] = "extra"; - scheck[21] = "extra"; - scheck[22] = "extra"; - scheck[23] = "extra"; - scheck[24] = "extra"; - - for (i = 0; i < 25; i++) { - test_svalue(scheck[i], cpl_table_get_string(table, "String", i), - "Check String column... "); - } - - fcheck[0] = -1.10; - fcheck[1] = -1.10; - fcheck[2] = -1.10; - fcheck[3] = -1.10; - fcheck[4] = -1.10; - fcheck[5] = 5.10; - fcheck[6] = 0.10; - fcheck[7] = 2.10; - fcheck[8] = 8.10; - fcheck[9] = 9.10; - fcheck[10] = -1.10; - fcheck[11] = -1.10; - fcheck[12] = -1.10; - fcheck[13] = -1.10; - fcheck[14] = -1.10; - fcheck[15] = 3.10; - fcheck[16] = 7.10; - fcheck[17] = 1.10; - fcheck[18] = 4.10; - fcheck[19] = 6.10; - fcheck[20] = -1.10; - fcheck[21] = -1.10; - fcheck[22] = -1.10; - fcheck[23] = -1.10; - fcheck[24] = -1.10; - - for (i = 0; i < 25; i++) { - test_fvalue(fcheck[i], 0.00001, - cpl_table_get_float(table, "Float", i, &null), - "Check Float column... "); - cpl_test_zero(null); - } + k = 0; + array = cpl_array_new(20, CPL_TYPE_DOUBLE_COMPLEX); + for (i = 0; i < nrows; i++) { + for (j = 0; j < 20; j++) { + sprintf(message, + "Writing element %d of array %d of the CADouble column... ", + j, i); + k++; + test(cpl_array_set_double_complex(array, j, k + k * I), message); + } + sprintf(message, + "Setting array at position %d of the CADouble column... ", i); + test(cpl_table_set_array(table, "CADouble", i, array), message); + } -#ifdef _Complex_I - cfcheck[0] = -1.1 + 4.1 * I; - cfcheck[1] = -1.1 + 4.1 * I; - cfcheck[2] = -1.1 + 4.1 * I; - cfcheck[3] = -1.1 + 4.1 * I; - cfcheck[4] = -1.1 + 4.1 * I; - cfcheck[5] = 5.1; - cfcheck[6] = 0.1 * I; - cfcheck[7] = 2.1; - cfcheck[8] = 8.1 * I; - cfcheck[9] = 9.1 + 9.1 * I; - cfcheck[10] = -1.1 + 4.1 * I; - cfcheck[11] = -1.1 + 4.1 * I; - cfcheck[12] = -1.1 + 4.1 * I; - cfcheck[13] = -1.1 + 4.1 * I; - cfcheck[14] = -1.1 + 4.1 * I; - cfcheck[15] = 3.1 - 3.1 * I; - cfcheck[16] = 7.1 + 1.1 * I; - cfcheck[17] = 1.1 - 7.1 * I; - cfcheck[18] = -4.1 + 4.1 * I; - cfcheck[19] = -6.1 - 6.1 * I; - cfcheck[20] = -1.1 + 4.1 * I; - cfcheck[21] = -1.1 + 4.1 * I; - cfcheck[22] = -1.1 + 4.1 * I; - cfcheck[23] = -1.1 + 4.1 * I; - cfcheck[24] = -1.1 + 4.1 * I; - - for (i = 0; i < 25; i++) { - test_cvalue(cfcheck[i], 0.00001, - cpl_table_get_float_complex(table, "CFloat", i, &null), - "Check CFloat column... "); - cpl_test_zero(null); - } - - cdcheck[0] = -1.11 + 4.11 * I; - cdcheck[1] = -1.11 + 4.11 * I; - cdcheck[2] = -1.11 + 4.11 * I; - cdcheck[3] = -1.11 + 4.11 * I; - cdcheck[4] = -1.11 + 4.11 * I; - cdcheck[5] = 5.11; - cdcheck[6] = 0.11 * I; - cdcheck[7] = 2.11; - cdcheck[8] = 8.11 * I; - cdcheck[9] = 9.11 + 9.11 * I; - cdcheck[10] = -1.11 + 4.11 * I; - cdcheck[11] = -1.11 + 4.11 * I; - cdcheck[12] = -1.11 + 4.11 * I; - cdcheck[13] = -1.11 + 4.11 * I; - cdcheck[14] = -1.11 + 4.11 * I; - cdcheck[15] = 3.11 - 3.11 * I; - cdcheck[16] = 7.11 + 1.11 * I; - cdcheck[17] = 1.11 - 7.11 * I; - cdcheck[18] = -4.11 + 4.11 * I; - cdcheck[19] = -6.11 - 6.11 * I; - cdcheck[20] = -1.11 + 4.11 * I; - cdcheck[21] = -1.11 + 4.11 * I; - cdcheck[22] = -1.11 + 4.11 * I; - cdcheck[23] = -1.11 + 4.11 * I; - cdcheck[24] = -1.11 + 4.11 * I; - - for (i = 0; i < 25; i++) { - test_cvalue(cdcheck[i], 0.00001, - cpl_table_get_double_complex(table, "CDouble", i, &null), - "Check CDouble column... "); - cpl_test_zero(null); - } -#endif - - test(cpl_table_set_invalid(table, "Integer", 0), - "Set Integer 0 to NULL... "); - test(cpl_table_set_invalid(table, "Integer", 5), - "Set Integer 5 to NULL... "); - test(cpl_table_set_invalid(table, "Integer", 24), - "Set Integer 24 to NULL... "); - - test(cpl_table_set_invalid(table, "LongLong", 0), - "Set LongLong 0 to NULL... "); - test(cpl_table_set_invalid(table, "LongLong", 5), - "Set LongLong 5 to NULL... "); - test(cpl_table_set_invalid(table, "LongLong", 24), - "Set LongLong 24 to NULL... "); - - test(cpl_table_set_invalid(table, "AInt", 0), - "Set AInt 0 to NULL... "); - test(cpl_table_set_invalid(table, "ALongLong", 0), - "Set ALongLong 0 to NULL... "); - test(cpl_table_set_invalid(table, "AFloat", 5), - "Set AFloat 5 to NULL... "); - test(cpl_table_set_invalid(table, "ADouble", 24), - "Set ADouble 24 to NULL... "); - test(cpl_table_set_invalid(table, "CAFloat", 5), - "Set CAFloat 5 to NULL... "); - test(cpl_table_set_invalid(table, "CADouble", 24), - "Set CADouble 24 to NULL... "); - - - test_ivalue(3, cpl_table_count_invalid(table, "Integer"), - "Count Integer written NULLs... "); - test_ivalue(1, cpl_table_count_invalid(table, "AInt"), - "Count AInt written NULLs... "); - test_ivalue(3, cpl_table_count_invalid(table, "LongLong"), - "Count LongLong written NULLs... "); - test_ivalue(1, cpl_table_count_invalid(table, "ALongLong"), - "Count ALongLong written NULLs... "); - test_ivalue(1, cpl_table_count_invalid(table, "AFloat"), - "Count AFloat written NULLs... "); - test_ivalue(1, cpl_table_count_invalid(table, "ADouble"), - "Count ADouble written NULLs... "); - test_ivalue(1, cpl_table_count_invalid(table, "CAFloat"), - "Count CAFloat written NULLs... "); - test_ivalue(1, cpl_table_count_invalid(table, "CADouble"), - "Count CADouble written NULLs... "); - - -/**+ FIXME: RESTORE!!! */ - error = cpl_table_fill_invalid_int(table, "Integer", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_int(table, "AInt", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_long_long(table, "LongLong", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_long_long(table, "ALongLong", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_float(table, "AFloat", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_double(table, "ADouble", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_float_complex(table, "CAFloat", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_double_complex(table, "CADouble", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - - test_ivalue(3, cpl_table_count_invalid(table, "Integer"), - "Count Integer written NULLs... "); - test_ivalue(3, cpl_table_count_invalid(table, "LongLong"), - "Count LongLong written NULLs... "); - test_ivalue(1, cpl_table_count_invalid(table, "AFloat"), - "Count AFloat written NULLs... "); - test_ivalue(1, cpl_table_count_invalid(table, "ADouble"), - "Count ADouble written NULLs... "); - test_ivalue(1, cpl_table_count_invalid(table, "CAFloat"), - "Count CAFloat written NULLs... "); - test_ivalue(1, cpl_table_count_invalid(table, "CADouble"), - "Count CADouble written NULLs... "); - /* Array elements are flagged as valid! */ - test_ivalue(0, cpl_table_count_invalid(table, "AInt"), - "Count AInt written NULLs... "); - test_ivalue(0, cpl_table_count_invalid(table, "ALongLong"), - "Count ALongLong written NULLs... "); - - error = cpl_table_save(table, NULL, NULL, BASE "3.fits", CPL_IO_CREATE); - cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_fits(BASE "3.fits"); - cpl_table_delete(table); - table = cpl_table_load(BASE "3.fits", 1, 1); - cpl_test_nonnull(table); - cpl_test_eq(cpl_table_get_nrow(table), 25); -/**/ - - test_ivalue(3, cpl_table_count_invalid(table, "Integer"), - "Count Integer written NULLs... "); - test_ivalue(1, cpl_table_count_invalid(table, "AInt"), - "Count AInt written NULLs... "); - test_ivalue(3, cpl_table_count_invalid(table, "LongLong"), - "Count LongLong written NULLs... "); - test_ivalue(1, cpl_table_count_invalid(table, "ALongLong"), - "Count ALongLong written NULLs... "); - test_ivalue(1, cpl_table_count_invalid(table, "AFloat"), - "Count AFloat written NULLs... "); - test_ivalue(1, cpl_table_count_invalid(table, "ADouble"), - "Count ADouble written NULLs... "); - test_ivalue(1, cpl_table_count_invalid(table, "CAFloat"), - "Count CAFloat written NULLs... "); - test_ivalue(1, cpl_table_count_invalid(table, "CADouble"), - "Count CADouble written NULLs... "); - - for (i = 0; i < 25; i++) { - const int ival = cpl_table_get_int(table, "Integer", i, &null); - if (!null) { - test_ivalue(icheck[i], ival, "Check Integer column... "); - } else { - cpl_test(i == 0 || i == 5 || i == 24); - } - } - - for (i = 0; i < 25; i++) { - const long long ival = cpl_table_get_long_long(table, "LongLong", i, &null); - if (!null) { - test_ivalue(icheck[i], ival, "Check LongLong column... "); - } else { - cpl_test(i == 0 || i == 5 || i == 24); - } - } - - test(cpl_table_set_int(table, "Integer", 0, -1), - "Set Integer 0 to -1... "); - test(cpl_table_set_int(table, "Integer", 5, 5), - "Set Integer 5 to 5... "); - test(cpl_table_set_int(table, "Integer", 24, -1), - "Set Integer 24 to -1... "); - - array = cpl_array_new(20, CPL_TYPE_INT); - for (j = 0; j < 20; j++) - cpl_array_set_int(array, j, j); - test(cpl_table_set_array(table, "AInt", 0, array), - "Set a valid array to AInt 0... "); - cpl_array_delete(array); - test_ivalue(0, cpl_table_count_invalid(table, "AInt"), - "No invalid elements in AInt... "); - - test(cpl_table_set_long_long(table, "LongLong", 0, -1), - "Set LongLong 0 to -1... "); - test(cpl_table_set_long_long(table, "LongLong", 5, 5), - "Set LongLong 5 to 5... "); - test(cpl_table_set_long_long(table, "LongLong", 24, -1), - "Set LongLong 24 to -1... "); - - array = cpl_array_new(20, CPL_TYPE_LONG_LONG); - for (j = 0; j < 20; j++) - cpl_array_set_long_long(array, j, j); - test(cpl_table_set_array(table, "ALongLong", 0, array), - "Set a valid array to ALongLong 0... "); - cpl_array_delete(array); - test_ivalue(0, cpl_table_count_invalid(table, "ALongLong"), - "No invalid elements in ALongLong... "); - - array = cpl_array_new(20, CPL_TYPE_FLOAT); - for (j = 0; j < 20; j++) - cpl_array_set_float(array, j, j); - test(cpl_table_set_array(table, "AFloat", 5, array), - "Set a valid array to AFloat 5... "); - cpl_array_delete(array); - test_ivalue(0, cpl_table_count_invalid(table, "AFloat"), - "No invalid elements in AFloat... "); - - array = cpl_array_new(20, CPL_TYPE_DOUBLE); - for (j = 0; j < 20; j++) - cpl_array_set_double(array, j, j); - test(cpl_table_set_array(table, "ADouble", 24, array), - "Set a valid array to ADouble 24... "); - cpl_array_delete(array); - test_ivalue(0, cpl_table_count_invalid(table, "ADouble"), - "No invalid elements in ADouble... "); + cpl_array_delete(array); -#ifdef _Complex_I - array = cpl_array_new(20, CPL_TYPE_FLOAT_COMPLEX); - for (j = 0; j < 20; j++) - cpl_array_set_float_complex(array, j, j + 0.5*I); - test(cpl_table_set_array(table, "CAFloat", 5, array), - "Set a valid array to CAFloat 5... "); - cpl_array_delete(array); - test_ivalue(0, cpl_table_count_invalid(table, "CAFloat"), - "No invalid elements in CAFloat... "); - - array = cpl_array_new(20, CPL_TYPE_DOUBLE_COMPLEX); - for (j = 0; j < 20; j++) - cpl_array_set_double_complex(array, j, j + 0.5*I); - test(cpl_table_set_array(table, "CADouble", 24, array), - "Set a valid array to CADouble 24... "); - cpl_array_delete(array); - test_ivalue(0, cpl_table_count_invalid(table, "CADouble"), - "No invalid elements in CADouble... "); -#endif - -/**+ FIXME: RESTORE!!! %%%%% */ - error = cpl_table_fill_invalid_int(table, "Integer", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_int(table, "AInt", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_long_long(table, "LongLong", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_long_long(table, "ALongLong", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_save(table, NULL, NULL, BASE "4.fits", CPL_IO_CREATE); - cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_fits(BASE "4.fits"); - cpl_table_delete(table); - table = cpl_table_load(BASE "4.fits", 1, 1); - cpl_test_nonnull(table); - cpl_test_eq(cpl_table_get_nrow(table), 25); -/**/ - - test_ivalue(0, cpl_table_count_invalid(table, "Integer"), - "Count NULLs... "); - - for (i = 0; i < 25; i++) { - const int ival = cpl_table_get_int(table, "Integer", i, &null); - - cpl_test_zero(null); - - if (!null) { - test_ivalue(icheck[i], ival, "Check Integer column... "); - } - } - - test_ivalue(0, cpl_table_count_invalid(table, "LongLong"), - "Count NULLs... "); - - for (i = 0; i < 25; i++) { - const int ival = cpl_table_get_long_long(table, "LongLong", i, &null); - - cpl_test_zero(null); - - if (!null) { - test_ivalue(icheck[i], ival, "Check LongLong column... "); - } - } - - test(cpl_table_set_invalid(table, "Double", 0), "Set Double 0 to NULL... "); - test(cpl_table_set_invalid(table, "Double", 5), "Set Double 5 to NULL... "); - test(cpl_table_set_invalid(table, "Double", 24), "Set Double 24 to NULL... "); - -/**+ FIXME: RESTORE!!! */ - error = cpl_table_fill_invalid_int(table, "Integer", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_int(table, "AInt", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_long_long(table, "LongLong", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_long_long(table, "ALongLong", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_save(table, NULL, NULL, BASE "5.fits", CPL_IO_CREATE); - cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_fits(BASE "5.fits"); - cpl_table_delete(table); - table = cpl_table_load(BASE "5.fits", 1, 1); - cpl_test_nonnull(table); - cpl_test_eq(cpl_table_get_nrow(table), 25); -/**/ - - test_ivalue(3, cpl_table_count_invalid(table, "Double"), - "Count written Double NULLs... "); - - for (i = 0; i < 25; i++) { - const double dval = cpl_table_get_double(table, "Double", i, &null); - if (!null) { - test_fvalue(dcheck[i], 0.0, dval, "Check Double column... "); - } - else { - cpl_test(i == 0 || i == 5 || i == 24); - } - } - - test(cpl_table_set_double(table, "Double", 0, -1.11), - "Set Double 0 to -1.11... "); - test(cpl_table_set_double(table, "Double", 5, 5.11), - "Set Double 5 to 5.11... "); - test(cpl_table_set_double(table, "Double", 24, -1.11), - "Set Double 24 to -1.11... "); - -/**+ FIXME: RESTORE!!! */ - error = cpl_table_fill_invalid_int(table, "Integer", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_int(table, "AInt", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_long_long(table, "LongLong", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_long_long(table, "ALongLong", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_save(table, NULL, NULL, BASE "6.fits", CPL_IO_CREATE); - cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_fits(BASE "6.fits"); - cpl_table_delete(table); - table = cpl_table_load(BASE "6.fits", 1, 1); - cpl_test_nonnull(table); - cpl_test_eq(cpl_table_get_nrow(table), 25); -/**/ - - test_ivalue(0, cpl_table_count_invalid(table, "Double"), - "Count NULLs... "); - - for (i = 0; i < 25; i++) { - const double dval = cpl_table_get_double(table, "Double", i, &null); - - cpl_test_zero(null); - if (!null) { - test_fvalue(dcheck[i], 0.00001, dval, "Check Double column... "); - } - } - - test(cpl_table_set_invalid(table, "String", 0), "Set String 0 to NULL... "); - test(cpl_table_set_invalid(table, "String", 5), "Set String 5 to NULL... "); - test(cpl_table_set_invalid(table, "String", 24), "Set String 24 to NULL... "); - -/**+ FIXME: RESTORE!!! %%% */ - error = cpl_table_fill_invalid_int(table, "Integer", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_int(table, "AInt", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_long_long(table, "LongLong", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_long_long(table, "ALongLong", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_save(table, NULL, NULL, BASE "7.fits", CPL_IO_CREATE); - cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_fits(BASE "7.fits"); - cpl_table_delete(table); - table = cpl_table_load(BASE "7.fits", 1, 1); - cpl_test_nonnull(table); - cpl_test_eq(cpl_table_get_nrow(table), 25); -/**/ - - test_ivalue(3, cpl_table_count_invalid(table, "String"), - "Count written String NULLs... "); - - for (i = 0; i < 25; i++) { - const char * sval = cpl_table_get_string(table, "String", i); - - if (sval != NULL) { - test_svalue(scheck[i], sval, "Check String column... "); - } else { - cpl_test(i == 0 || i == 5 || i == 24); - } - } - - test(cpl_table_set_string(table, "String", 0, "extra"), - "Set String 0 to \"extra\"... "); - test(cpl_table_set_string(table, "String", 5, "caaaa"), - "Set String 5 to \"caaaa\"... "); - test(cpl_table_set_string(table, "String", 24, "extra"), - "Set String 24 to \"extra\"... "); - -/**+ FIXME: RESTORE!!! %%% */ - error = cpl_table_fill_invalid_int(table, "Integer", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_int(table, "AInt", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_long_long(table, "LongLong", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_long_long(table, "ALongLong", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_save(table, NULL, NULL, BASE "8.fits", CPL_IO_CREATE); - cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_fits(BASE "8.fits"); - cpl_table_delete(table); - table = cpl_table_load(BASE "8.fits", 1, 1); - cpl_test_nonnull(table); - cpl_test_eq(cpl_table_get_nrow(table), 25); -/**/ - - test_ivalue(0, cpl_table_count_invalid(table, "String"), - "Count NULLs... "); - - for (i = 0; i < 25; i++) { - - test_svalue(scheck[i], cpl_table_get_string(table, "String", i), - "Check String column... "); - } - - test(cpl_table_set_invalid(table, "Float", 0), "Set Float 0 to NULL... "); - test(cpl_table_set_invalid(table, "Float", 5), "Set Float 5 to NULL... "); - test(cpl_table_set_invalid(table, "Float", 24), "Set Float 24 to NULL... "); - -/**+ FIXME: RESTORE!!! */ - error = cpl_table_fill_invalid_int(table, "Integer", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_int(table, "AInt", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_long_long(table, "LongLong", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_long_long(table, "ALongLong", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_save(table, NULL, NULL, BASE "9.fits", CPL_IO_CREATE); - cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_fits(BASE "9.fits"); - cpl_table_delete(table); - table = cpl_table_load(BASE "9.fits", 1, 1); - cpl_test_nonnull(table); - cpl_test_eq(cpl_table_get_nrow(table), 25); -/**/ - - test_ivalue(3, cpl_table_count_invalid(table, "Float"), - "Count written Float NULLs... "); - - for (i = 0; i < 25; i++) { - const float fval = cpl_table_get_float(table, "Float", i, &null); - - if (!null) { - test_fvalue(fcheck[i], 0.0, fval, "Check Float column... "); - } else { - cpl_test(i == 0 || i == 5 || i == 24); - } - } - - test(cpl_table_set_float(table, "Float", 0, -1.1), - "Set Float 0 to -1.1... "); - test(cpl_table_set_float(table, "Float", 5, 5.1), - "Set Float 5 to 5.1... "); - test(cpl_table_set_float(table, "Float", 24, -1.1), - "Set Float 24 to -1.1... "); - -/**+ FIXME: RESTORE!!! */ - error = cpl_table_fill_invalid_int(table, "Integer", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_int(table, "AInt", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_long_long(table, "LongLong", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_long_long(table, "ALongLong", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_save(table, NULL, NULL, BASE "10.fits", CPL_IO_CREATE); - cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_fits(BASE "10.fits"); - cpl_table_delete(table); - table = cpl_table_load(BASE "10.fits", 1, 1); - cpl_test_nonnull(table); - cpl_test_eq(cpl_table_get_nrow(table), 25); -/**/ - - test_ivalue(0, cpl_table_count_invalid(table, "Float"), - "Count NULLs... "); - - for (i = 0; i < 25; i++) { - const float fval = cpl_table_get_float(table, "Float", i, &null); - - cpl_test_zero(null); - if (!null) { - test_fvalue(fcheck[i], 0.00001, fval, "Check Float column... "); - - } - } - - /* %%% */ - - test(cpl_table_set_invalid(table, "CFloat", 0), "Set CFloat 0 to NULL... "); - test(cpl_table_set_invalid(table, "CFloat", 5), "Set CFloat 5 to NULL... "); - test(cpl_table_set_invalid(table, "CFloat", 24), "Set CFloat 24 to NULL... "); - -/**+ FIXME: RESTORE!!! */ - error = cpl_table_fill_invalid_int(table, "Integer", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_int(table, "AInt", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_long_long(table, "LongLong", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_long_long(table, "ALongLong", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_save(table, NULL, NULL, BASE "9a.fits", CPL_IO_CREATE); - cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_fits(BASE "9a.fits"); - cpl_table_delete(table); - table = cpl_table_load(BASE "9a.fits", 1, 1); - cpl_test_nonnull(table); - cpl_test_eq(cpl_table_get_nrow(table), 25); -/**/ + k = 0; + for (i = 0; i < nrows; i++) { + sprintf(message, "Getting array %d of the CADouble column... ", i); + test_data(array, (cpl_array *)cpl_table_get_array(table, "CADouble", i), + message); + for (j = 0; j < 20; j++) { + sprintf(message, + "Reading element %d of array %d of the CADouble column... ", + j, i); + k++; + test_cvalue(k + k * I, 0.0001, + cpl_array_get_double_complex(array, j, &null), message); + cpl_test_zero(null); + } + } +#endif -#ifdef _Complex_I - test_ivalue(3, cpl_table_count_invalid(table, "CFloat"), - "Count written CFloat NULLs... "); - - for (i = 0; i < 25; i++) { - const float complex fval = cpl_table_get_float_complex(table, - "CFloat", i, &null); - - if (!null) { - test_cvalue(cfcheck[i], 0.0, fval, "Check CFloat column... "); - } else { - cpl_test(i == 0 || i == 5 || i == 24); - } - } - - test(cpl_table_set_float_complex(table, "CFloat", 0, -1.1 + 4.1*I), - "Set CFloat 0 to -1.1 + i4.1... "); - test(cpl_table_set_float_complex(table, "CFloat", 5, 5.1), - "Set CFloat 5 to 5.1... "); - test(cpl_table_set_float_complex(table, "CFloat", 24, -1.1 + 4.1*I), - "Set CFloat 24 to -1.1 + i4.1... "); -#endif - -/**+ FIXME: RESTORE!!! */ - error = cpl_table_fill_invalid_int(table, "Integer", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_int(table, "AInt", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_long_long(table, "LongLong", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_long_long(table, "ALongLong", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_save(table, NULL, NULL, BASE "10.fits", CPL_IO_CREATE); - cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_fits(BASE "10.fits"); - cpl_table_delete(table); - table = cpl_table_load(BASE "10.fits", 1, 1); - cpl_test_nonnull(table); - cpl_test_eq(cpl_table_get_nrow(table), 25); -/**/ + test_ivalue(20, cpl_table_get_column_depth(table, "AInt"), + "Check \"AInt\" depth (3)... "); -#ifdef _Complex_I - test_ivalue(0, cpl_table_count_invalid(table, "CFloat"), "Count NULLs... "); + test_data(array, (cpl_array *)cpl_table_get_array(table, "AInt", 0), + "Get AInt array "); + test_ivalue(CPL_TYPE_INT, cpl_array_get_type(array), + "Array AInt must be int... "); + + test_ivalue(10, cpl_table_get_nrow(table), "Check table length (1)... "); + test_ivalue(16, cpl_table_get_ncol(table), "Check table width... "); + + test_failure(CPL_ERROR_DATA_NOT_FOUND, + cpl_table_erase_column(table, "Diable"), + "Trying to delete a not existing column... "); + + test(cpl_table_erase_column(table, "DoubleDouble"), + "Delete column \"DoubleDouble\"... "); + + test_ivalue(15, cpl_table_get_ncol(table), "Check again table width... "); + + test_ivalue(CPL_TYPE_INT, cpl_table_get_column_type(table, "Integer"), + "Column Integer must be int... "); + test_ivalue(CPL_TYPE_DOUBLE, cpl_table_get_column_type(table, "Double"), + "Column Double must be double... "); + test_ivalue(CPL_TYPE_STRING, cpl_table_get_column_type(table, "String"), + "Column String must be char*... "); + test_ivalue(CPL_TYPE_FLOAT, cpl_table_get_column_type(table, "Float"), + "Column Float must be float... "); + test_ivalue(CPL_TYPE_FLOAT_COMPLEX, + cpl_table_get_column_type(table, "CFloat"), + "Column CFloat must be float complex... "); + test_ivalue(CPL_TYPE_DOUBLE_COMPLEX, + cpl_table_get_column_type(table, "CDouble"), + "Column CDouble must be double complex... "); + test_ivalue((CPL_TYPE_INT | CPL_TYPE_POINTER), + cpl_table_get_column_type(table, "AInt"), + "Column AInt must be arrays of int... "); + test_ivalue((CPL_TYPE_DOUBLE | CPL_TYPE_POINTER), + cpl_table_get_column_type(table, "ADouble"), + "Column Double must be arrays of double... "); + test_ivalue((CPL_TYPE_FLOAT | CPL_TYPE_POINTER), + cpl_table_get_column_type(table, "AFloat"), + "Column Float must be arrays of float... "); + test_ivalue((CPL_TYPE_FLOAT_COMPLEX | CPL_TYPE_POINTER), + cpl_table_get_column_type(table, "CAFloat"), + "Column CAFloat must be arrays of float complex... "); + test_ivalue((CPL_TYPE_DOUBLE_COMPLEX | CPL_TYPE_POINTER), + cpl_table_get_column_type(table, "CADouble"), + "Column CADouble must be arrays of double complex... "); + test_pvalue(iArray, cpl_table_get_data_int(table, "Integer"), + "Check pointer to column Integer data... "); + + test_pvalue(dArray, cpl_table_get_data_double(table, "Double"), + "Check pointer to column Double data... "); + test_pvalue(sArray, cpl_table_get_data_string(table, "String"), + "Check pointer to column String data... "); - for (i = 0; i < 25; i++) { - const float complex fval = cpl_table_get_float_complex(table, - "CFloat", i, &null); - - cpl_test_zero(null); - if (!null) { - test_cvalue(cfcheck[i], 0.00001, fval, "Check CFloat column... "); - - } - } -#endif - - /* %%% */ - - test(cpl_table_set_column_invalid(table, "Integer", 0, 3), - "Set Integer 0-2 to NULL... "); - test(cpl_table_set_column_invalid(table, "Integer", 5, 3), - "Set Integer 5-7 to NULL... "); - test(cpl_table_set_column_invalid(table, "Integer", 20, 20), - "Set Integer 20 till end to NULL... "); - - test(cpl_table_set_column_invalid(table, "AInt", 0, 3), - "Set AInt 0-2 to NULL... "); - test(cpl_table_set_column_invalid(table, "AInt", 5, 3), - "Set AInt 5-7 to NULL... "); - test(cpl_table_set_column_invalid(table, "AInt", 20, 20), - "Set AInt 20 till end to NULL... "); - - /********/ - - array = (cpl_array *)cpl_table_get_array(table, "AInt", 3); - test_ivalue(0, cpl_array_get_int(array, 0, &null), - "Read array element 0..."); - test_ivalue(0, null, "Check array element 0 is valid..."); - test_ivalue(5, cpl_array_get_int(array, 5, &null), - "Read array element 5..."); - test_ivalue(0, null, "Check array element 5 is valid..."); - test_ivalue(19, cpl_array_get_int(array, 19, &null), - "Read array element 19..."); - test_ivalue(0, null, "Check array element 19 is valid..."); - - cpl_array_set_invalid(array, 0); - cpl_array_set_invalid(array, 5); - cpl_array_set_invalid(array, 19); - - test_ivalue(0, cpl_array_get_int(array, 0, &null), - "Read again array element 0..."); - test_ivalue(1, null, "Check array element 0 is invalid..."); - test_ivalue(0, cpl_array_get_int(array, 5, &null), - "Read again array element 5..."); - test_ivalue(1, null, "Check array element 5 is invalid..."); - test_ivalue(0, cpl_array_get_int(array, 19, &null), - "Read again array element 19..."); - test_ivalue(1, null, "Check array element 19 is invalid..."); - - - test(cpl_table_set_column_invalid(table, "LongLong", 0, 3), - "Set LongLong 0-2 to NULL... "); - test(cpl_table_set_column_invalid(table, "LongLong", 5, 3), - "Set LongLong 5-7 to NULL... "); - test(cpl_table_set_column_invalid(table, "LongLong", 20, 20), - "Set LongLong 20 till end to NULL... "); - - test(cpl_table_set_column_invalid(table, "ALongLong", 0, 3), - "Set ALongLong 0-2 to NULL... "); - test(cpl_table_set_column_invalid(table, "ALongLong", 5, 3), - "Set ALongLong 5-7 to NULL... "); - test(cpl_table_set_column_invalid(table, "ALongLong", 20, 20), - "Set ALongLong 20 till end to NULL... "); - - array = (cpl_array *)cpl_table_get_array(table, "ALongLong", 3); - test_ivalue(0, cpl_array_get_long_long(array, 0, &null), - "Read array element 0..."); - test_ivalue(0, null, "Check array element 0 is valid..."); - test_ivalue(5, cpl_array_get_long_long(array, 5, &null), - "Read array element 5..."); - test_ivalue(0, null, "Check array element 5 is valid..."); - test_ivalue(19, cpl_array_get_long_long(array, 19, &null), - "Read array element 19..."); - test_ivalue(0, null, "Check array element 19 is valid..."); - - cpl_array_set_invalid(array, 0); - cpl_array_set_invalid(array, 5); - cpl_array_set_invalid(array, 19); - - test_ivalue(0, cpl_array_get_long_long(array, 0, &null), - "Read again array element 0..."); - test_ivalue(1, null, "Check array element 0 is invalid..."); - test_ivalue(0, cpl_array_get_long_long(array, 5, &null), - "Read again array element 5..."); - test_ivalue(1, null, "Check array element 5 is invalid..."); - test_ivalue(0, cpl_array_get_long_long(array, 19, &null), - "Read again array element 19..."); - test_ivalue(1, null, "Check array element 19 is invalid..."); - -/**+ FIXME: RESTORE!!! */ - error = cpl_table_fill_invalid_int(table, "Integer", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_int(table, "AInt", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_long_long(table, "LongLong", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_long_long(table, "ALongLong", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_save(table, NULL, NULL, BASE "11.fits", CPL_IO_CREATE); - cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_fits(BASE "11.fits"); - cpl_table_delete(table); - table = cpl_table_load(BASE "11.fits", 1, 1); - cpl_test_nonnull(table); - cpl_test_eq(cpl_table_get_nrow(table), 25); -/**/ - - test_ivalue(11, cpl_table_count_invalid(table, "Integer"), - "Count Integer NULLs... "); - - test_ivalue(11, cpl_table_count_invalid(table, "AInt"), - "Count AInt NULLs... "); - - for (i = 0; i < 25; i++) { - const int ival = cpl_table_get_int(table, "Integer", i, &null); - if (!null) { - test_ivalue(icheck[i], ival, "Check Integer column... "); - } else { - cpl_test(i <= 2 || i >= 5); - cpl_test(i <= 7 || i >= 20); - } - } - - test_ivalue(11, cpl_table_count_invalid(table, "LongLong"), - "Count LongLong NULLs... "); - - test_ivalue(11, cpl_table_count_invalid(table, "ALongLong"), - "Count ALongLong NULLs... "); - - for (i = 0; i < 25; i++) { - const long long llval = cpl_table_get_long_long(table, "LongLong", i, &null); - if (!null) { - test_ivalue(icheck[i], llval, "Check LongLong column... "); - } else { - cpl_test(i <= 2 || i >= 5); - cpl_test(i <= 7 || i >= 20); - } - } - - /* - * Test valid and invalid elements of an array of AInt (after loading). - */ - - array = (cpl_array *)cpl_table_get_array(table, "AInt", 3); - - test_ivalue(0, cpl_array_get_int(array, 0, &null), - "Load again array element 0..."); - test_ivalue(1, null, "Reloaded array element 0 is invalid..."); - test_ivalue(0, cpl_array_get_int(array, 5, &null), - "Load again array element 5..."); - test_ivalue(1, null, "Reloaded array element 5 is invalid..."); - test_ivalue(0, cpl_array_get_int(array, 19, &null), - "Load again array element 19..."); - test_ivalue(1, null, "Reloaded array element 19 is invalid..."); - - test_ivalue(6, cpl_array_get_int(array, 6, &null), - "Load array element 6..."); - test_ivalue(0, null, "Reloaded array element 6 is valid..."); - - - /* - * Test valid and invalid elements of an array of ALongLong (after loading). - */ - - array = (cpl_array *)cpl_table_get_array(table, "ALongLong", 3); - - test_ivalue(0, cpl_array_get_long_long(array, 0, &null), - "Load again array element 0..."); - test_ivalue(1, null, "Reloaded array element 0 is invalid..."); - test_ivalue(0, cpl_array_get_long_long(array, 5, &null), - "Load again array element 5..."); - test_ivalue(1, null, "Reloaded array element 5 is invalid..."); - test_ivalue(0, cpl_array_get_long_long(array, 19, &null), - "Load again array element 19..."); - test_ivalue(1, null, "Reloaded array element 19 is invalid..."); - - test_ivalue(6, cpl_array_get_long_long(array, 6, &null), - "Load array element 6..."); - test_ivalue(0, null, "Reloaded array element 6 is valid..."); - - - /****/ - - test(cpl_table_set_column_invalid(table, "Double", 0, 3), - "Set Double 0-2 to NULL... "); - test(cpl_table_set_column_invalid(table, "Double", 5, 3), - "Set Double 5-7 to NULL... "); - test(cpl_table_set_column_invalid(table, "Double", 20, 20), - "Set Double 20 till end to NULL... "); - - array = (cpl_array *)cpl_table_get_array(table, "ADouble", 3); - test_fvalue(0.0, 0.0001, cpl_array_get_double(array, 0, &null), - "Read double array element 0..."); - test_ivalue(0, null, "Check double array element 0 is valid..."); - test_fvalue(5.0, 0.0001, cpl_array_get_double(array, 5, &null), - "Read double array element 5..."); - test_ivalue(0, null, "Check double array element 5 is valid..."); - test_fvalue(19.0, 0.0001, cpl_array_get_double(array, 19, &null), - "Read double array element 19..."); - test_ivalue(0, null, "Check array element 19 is valid..."); - - cpl_array_set_invalid(array, 0); - cpl_array_set_invalid(array, 5); - cpl_array_set_invalid(array, 19); - - test_fvalue(0.0, 0.0001, cpl_array_get_double(array, 0, &null), - "Read again double array element 0..."); - test_ivalue(1, null, "Check double array element 0 is invalid..."); - test_fvalue(0.0, 0.0001, cpl_array_get_double(array, 5, &null), - "Read again double array element 5..."); - test_ivalue(1, null, "Check double array element 5 is invalid..."); - test_fvalue(0.0, 0.0001, cpl_array_get_double(array, 19, &null), - "Read again double array element 19..."); - test_ivalue(1, null, "Check double array element 19 is invalid..."); - - -/**+ FIXME: RESTORE!!! */ - error = cpl_table_fill_invalid_int(table, "Integer", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_int(table, "AInt", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_long_long(table, "LongLong", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_long_long(table, "ALongLong", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_save(table, NULL, NULL, BASE "12.fits", CPL_IO_CREATE); - cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_fits(BASE "12.fits"); - cpl_table_delete(table); - table = cpl_table_load(BASE "12.fits", 1, 1); - cpl_test_nonnull(table); - cpl_test_eq(cpl_table_get_nrow(table), 25); -/**/ - - test_ivalue(11, cpl_table_count_invalid(table, "Double"), - "Re-count written Double NULLs... "); - - for (i = 0; i < 25; i++) { - const double dval = cpl_table_get_double(table, "Double", i, &null); - if (!null) { - test_fvalue(dcheck[i], 0.000001, dval, "Check Double column... "); - } else { - cpl_test(i <= 2 || i >= 5); - cpl_test(i <= 7 || i >= 20); - } - } - - /* - * Check double array after reload - */ - - array = (cpl_array *)cpl_table_get_array(table, "ADouble", 3); - - test_fvalue(0.0, 0.0001, cpl_array_get_double(array, 0, &null), - "Read loaded double array element 0..."); - test_ivalue(1, null, "Loaded double array element 0 is invalid..."); - test_fvalue(0.0, 0.0001, cpl_array_get_double(array, 5, &null), - "Read loaded double array element 5..."); - test_ivalue(1, null, "Loaded double array element 5 is invalid..."); - test_fvalue(0.0, 0.0001, cpl_array_get_double(array, 19, &null), - "Read loaded double array element 19..."); - test_ivalue(1, null, "Loaded double array element 19 is invalid..."); - - /****/ - - test(cpl_table_set_column_invalid(table, "Float", 0, 3), - "Set Float 0-2 to NULL... "); - test(cpl_table_set_column_invalid(table, "Float", 5, 3), - "Set Float 5-7 to NULL... "); - test(cpl_table_set_column_invalid(table, "Float", 20, 20), - "Set Float 20 till end to NULL... "); - - array = (cpl_array *)cpl_table_get_array(table, "AFloat", 3); - test_fvalue(0.0, 0.0001, cpl_array_get_float(array, 0, &null), - "Read float array element 0..."); - test_ivalue(0, null, "Check float array element 0 is valid..."); - test_fvalue(5.0, 0.0001, cpl_array_get_float(array, 5, &null), - "Read float array element 5..."); - test_ivalue(0, null, "Check double array element 5 is valid..."); - test_fvalue(19.0, 0.0001, cpl_array_get_float(array, 19, &null), - "Read float array element 19..."); - test_ivalue(0, null, "Check float array element 19 is valid..."); - - cpl_array_set_invalid(array, 0); - cpl_array_set_invalid(array, 5); - cpl_array_set_invalid(array, 19); - - test_fvalue(0.0, 0.0001, cpl_array_get_float(array, 0, &null), - "Read again float array element 0..."); - test_ivalue(1, null, "Check float array element 0 is invalid..."); - test_fvalue(0.0, 0.0001, cpl_array_get_float(array, 5, &null), - "Read again float array element 5..."); - test_ivalue(1, null, "Check float array element 5 is invalid..."); - test_fvalue(0.0, 0.0001, cpl_array_get_float(array, 19, &null), - "Read again float array element 19..."); - test_ivalue(1, null, "Check float array element 19 is invalid..."); - -/**+ FIXME: RESTORE!!! */ - error = cpl_table_fill_invalid_int(table, "Integer", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_int(table, "AInt", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_long_long(table, "LongLong", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_long_long(table, "ALongLong", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_save(table, NULL, NULL, BASE "13.fits", CPL_IO_CREATE); - cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_fits(BASE "13.fits"); - cpl_table_delete(table); - table = cpl_table_load(BASE "13.fits", 1, 1); - cpl_test_nonnull(table); - cpl_test_eq(cpl_table_get_nrow(table), 25); -/**/ - - test_ivalue(11, cpl_table_count_invalid(table, "Float"), - "Re-count written Float NULLs... "); - - for (i = 0; i < 25; i++) { - const float fval = cpl_table_get_float(table, "Float", i, &null); - if (!null) { - test_fvalue(fcheck[i], 0.000001, fval, "Check Float column... "); - } else { - cpl_test(i <= 2 || i >= 5); - cpl_test(i <= 7 || i >= 20); - } - } - - /* - * Check float array after reload - */ - - array = (cpl_array *)cpl_table_get_array(table, "AFloat", 3); - - test_fvalue(0.0, 0.0001, cpl_array_get_float(array, 0, &null), - "Read loaded float array element 0..."); - test_ivalue(1, null, "Loaded float array element 0 is invalid..."); - test_fvalue(0.0, 0.0001, cpl_array_get_float(array, 5, &null), - "Read loaded float array element 5..."); - test_ivalue(1, null, "Loaded float array element 5 is invalid..."); - test_fvalue(0.0, 0.0001, cpl_array_get_float(array, 19, &null), - "Read loaded float array element 19..."); - test_ivalue(1, null, "Loaded float array element 19 is invalid..."); - - /****/ - - test(cpl_table_set_column_invalid(table, "String", 0, 3), - "Set String 0-2 to NULL... "); - test(cpl_table_set_column_invalid(table, "String", 5, 3), - "Set String 5-7 to NULL... "); - test(cpl_table_set_column_invalid(table, "String", 20, 20), - "Set String 20 till end to NULL... "); - -/**+ FIXME: RESTORE!!! */ - error = cpl_table_fill_invalid_int(table, "Integer", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_int(table, "AInt", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_long_long(table, "LongLong", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_long_long(table, "ALongLong", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_save(table, NULL, NULL, BASE "14.fits", CPL_IO_CREATE); - cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_fits(BASE "14.fits"); - cpl_table_delete(table); - table = cpl_table_load(BASE "14.fits", 1, 1); - cpl_test_nonnull(table); - cpl_test_eq(cpl_table_get_nrow(table), 25); -/**/ - - test_ivalue(11, cpl_table_count_invalid(table, "String"), - "Re-count written String NULLs... "); - - for (i = 0; i < 25; i++) { - const char * sval = cpl_table_get_string(table, "String", i); - - if (sval != NULL) { - test_svalue(scheck[i], sval, "Check String column... "); - } else { - cpl_test(i <= 2 || i >= 5); - cpl_test(i <= 7 || i >= 20); - } - } - - test(cpl_table_erase_window(table, 21, 4), "Delete last 4 table rows... "); - - test(cpl_table_erase_window(table, 7, 4), - "Delete table rows from 7 to 10... "); - - test(cpl_table_erase_window(table, 3, 3), - "Delete table rows from 3 to 5... "); - - test(cpl_table_erase_window(table, 0, 2), "Delete first two table rows... "); - - test_ivalue(12, cpl_table_get_nrow(table), "Check table length (4)... "); - - test_ivalue(3, cpl_table_count_invalid(table, "Integer"), - "Count Integer NULLs... "); - - test_ivalue(3, cpl_table_count_invalid(table, "LongLong"), - "Count LongLong NULLs... "); - - test_ivalue(3, cpl_table_count_invalid(table, "Double"), - "Count Double NULLs... "); - - test_ivalue(3, cpl_table_count_invalid(table, "String"), - "Count String NULLs... "); - - test_ivalue(3, cpl_table_count_invalid(table, "Float"), - "Count Float NULLs... "); - - test_ivalue(3, cpl_table_count_invalid(table, "AInt"), - "Count AInt NULLs... "); - - test_ivalue(0, cpl_table_count_invalid(table, "ADouble"), - "Count ADouble NULLs... "); - - test_ivalue(0, cpl_table_count_invalid(table, "AFloat"), - "Count AFloat NULLs... "); - - test(cpl_table_insert_window(table, 20, 5), - "Append 5 NULLs at table end... "); - - test(cpl_table_insert_window(table, 6, 4), - "Insert segment of 4 NULLs at row 6... "); - - test(cpl_table_insert_window(table, 1, 2), - "Insert segment of 2 NULLs at row 1... "); - - test_ivalue(23, cpl_table_get_nrow(table), "Check table length (5)... "); - - test_ivalue(14, cpl_table_count_invalid(table, "Integer"), - "Count Integer NULLs... "); - - test_ivalue(14, cpl_table_count_invalid(table, "LongLong"), - "Count LongLong NULLs... "); - - test_ivalue(14, cpl_table_count_invalid(table, "Double"), - "Count Double NULLs... "); - - test_ivalue(14, cpl_table_count_invalid(table, "String"), - "Count String NULLs... "); - - test_ivalue(14, cpl_table_count_invalid(table, "Float"), - "Count Float NULLs... "); - - test(cpl_table_fill_column_window_int(table, "Integer", 0, 2, 999), - "Write 999 in \"Integer\" column from 0 to 1... "); - - test(cpl_table_fill_column_window_int(table, "Integer", 3, 3, 999), - "Write 999 in \"Integer\" column from 3 to 5... "); - - test(cpl_table_fill_column_window_int(table, "Integer", 7, 4, 999), - "Write 999 in \"Integer\" column from 7 to 10... "); - - test(cpl_table_fill_column_window_int(table, "Integer", 20, 7, 999), - "Write 999 in \"Integer\" column from 20 to end... "); - - test(cpl_table_fill_column_window_long_long(table, "LongLong", 0, 2, 999), - "Write 999 in \"LongLong\" column from 0 to 1... "); - - test(cpl_table_fill_column_window_long_long(table, "LongLong", 3, 3, 999), - "Write 999 in \"LongLong\" column from 3 to 5... "); - - test(cpl_table_fill_column_window_long_long(table, "LongLong", 7, 4, 999), - "Write 999 in \"LongLong\" column from 7 to 10... "); - - test(cpl_table_fill_column_window_long_long(table, "LongLong", 20, 7, 999), - "Write 999 in \"LongLong\" column from 20 to end... "); - - test(cpl_table_fill_column_window_float(table, "Float", 0, 2, 999.99), - "Write 999.99 in \"Float\" column from 0 to 1... "); - - test(cpl_table_fill_column_window_float(table, "Float", 3, 3, 999.99), - "Write 999.99 in \"Float\" column from 3 to 5... "); - - test(cpl_table_fill_column_window_float(table, "Float", 7, 4, 999.99), - "Write 999.99 in \"Float\" column from 7 to 10... "); - - test(cpl_table_fill_column_window_float(table, "Float", 20, 7, 999.99), - "Write 999.99 in \"Float\" column from 20 to end... "); - - test(cpl_table_fill_column_window_double(table, "Double", 0, 2, 999.88), - "Write 999.88 in \"Double\" column from 0 to 1... "); - - test(cpl_table_fill_column_window_double(table, "Double", 3, 3, 999.88), - "Write 999.88 in \"Double\" column from 3 to 5... "); - - test(cpl_table_fill_column_window_double(table, "Double", 7, 4, 999.88), - "Write 999.88 in \"Double\" column from 7 to 10... "); - - test(cpl_table_fill_column_window_double(table, "Double", 20, 7, 999.88), - "Write 999.88 in \"Double\" column from 20 to end... "); - - test(cpl_table_fill_column_window_string(table, "String", 0, 2, "999"), - "Write \"999\" in \"String\" column from 0 to 1... "); - - test(cpl_table_fill_column_window_string(table, "String", 3, 3, "999"), - "Write \"999\" in \"String\" column from 3 to 5... "); - - test(cpl_table_fill_column_window_string(table, "String", 7, 4, "999"), - "Write \"999\" in \"String\" column from 7 to 10... "); - - test(cpl_table_fill_column_window_string(table, "String", 20, 7, "999"), - "Write \"999\" in \"String\" column from 20 to end... "); - -/**+ FIXME: RESTORE!!! */ - error = cpl_table_fill_invalid_int(table, "Integer", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_int(table, "AInt", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_long_long(table, "LongLong", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_long_long(table, "ALongLong", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_save(table, NULL, NULL, BASE "15.fits", CPL_IO_CREATE); - cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_fits(BASE "15.fits"); - cpl_table_delete(table); - table = cpl_table_load(BASE "15.fits", 1, 1); -/**/ - - test_ivalue(23, cpl_table_get_nrow(table), "Check table length (6)... "); - - test_ivalue(5, cpl_table_count_invalid(table, "Integer"), - "Count Integer NULLs... "); - - test_ivalue(5, cpl_table_count_invalid(table, "LongLong"), - "Count LongLong NULLs... "); - - test_ivalue(5, cpl_table_count_invalid(table, "Float"), - "Count Float NULLs... "); - - test_ivalue(5, cpl_table_count_invalid(table, "Double"), - "Count Double NULLs... "); - - test_ivalue(5, cpl_table_count_invalid(table, "String"), - "Count String NULLs... "); - - test_ivalue(14, cpl_table_count_invalid(table, "AInt"), - "Count AInt NULLs... "); - - test_ivalue(14, cpl_table_count_invalid(table, "ALongLong"), - "Count AInt NULLs... "); - - test_ivalue(11, cpl_table_count_invalid(table, "AFloat"), - "Count AFloat NULLs... "); - - test_ivalue(11, cpl_table_count_invalid(table, "ADouble"), - "Count ADouble NULLs... "); - - test_ivalue(0, cpl_table_is_valid(table, "Integer", 2), - "Check that third element of \"Integer\" is NULL... "); - - test_ivalue(0, cpl_table_is_valid(table, "LongLong", 2), - "Check that third element of \"LongLong\" is NULL... "); - - test_ivalue(1, cpl_table_is_valid(table, "Double", 0), - "Check that first element of \"Double\" is not NULL... "); - - test_ivalue(1, cpl_table_is_valid(table, "String", 0), - "Check that first element of \"String\" is not NULL... "); - - test_ivalue(0, cpl_table_is_valid(table, "String", 2), - "Check that third element of \"String\" is NULL... "); - - test_ivalue(0, cpl_table_is_valid(table, "AInt", 17), - "Check that third element of \"AInt\" is NULL... "); - - test_ivalue(0, cpl_table_is_valid(table, "ALongLong", 17), - "Check that third element of \"ALongLong\" is NULL... "); - - test_ivalue(1, cpl_table_is_valid(table, "ADouble", 17), - "Check that first element of \"ADouble\" is not NULL... "); - - test_ivalue(1, cpl_table_is_valid(table, "AFloat", 17), - "Check that third element of \"AFloat\" is NULL... "); - - test_data(copia, cpl_table_duplicate(table), "Duplicate table... "); - - test(cpl_table_duplicate_column(table, "New Integer", table, "Integer"), - "Duplicate \"Integer\" column within same table... "); - - test(cpl_table_duplicate_column(table, "New LongLong", table, "LongLong"), - "Duplicate \"LongLong\" column within same table... "); - - test(cpl_table_duplicate_column(table, "New Float", table, "Float"), - "Duplicate \"Float\" column within same table... "); - - test(cpl_table_duplicate_column(table, "New Double", table, "Double"), - "Duplicate \"Double\" column within same table... "); - - test(cpl_table_duplicate_column(table, "New String", table, "String"), - "Duplicate \"String\" column within same table... "); - - test(cpl_table_duplicate_column(table, "New AInt", table, "AInt"), - "Duplicate \"AInt\" column within same table... "); - - test(cpl_table_duplicate_column(table, "New ALongLong", table, "ALongLong"), - "Duplicate \"ALongLong\" column within same table... "); - - test(cpl_table_duplicate_column(table, "New AFloat", table, "AFloat"), - "Duplicate \"AFloat\" column within same table... "); - - test(cpl_table_duplicate_column(table, "New ADouble", table, "ADouble"), - "Duplicate \"ADouble\" column within same table... "); - - test_ivalue(5, cpl_table_count_invalid(table, "New Integer"), - "Count New Integer NULLs... "); - - test_ivalue(5, cpl_table_count_invalid(table, "New LongLong"), - "Count New LongLong NULLs... "); - - test_ivalue(5, cpl_table_count_invalid(table, "New Float"), - "Count New Float NULLs... "); - - test_ivalue(5, cpl_table_count_invalid(table, "New Double"), - "Count New Double NULLs... "); - - test_ivalue(5, cpl_table_count_invalid(table, "New String"), - "Count New String NULLs... "); - - test_ivalue(14, cpl_table_count_invalid(table, "New AInt"), - "Count New AInt NULLs... "); - - test_ivalue(14, cpl_table_count_invalid(table, "New ALongLong"), - "Count New ALongLong NULLs... "); - - test_ivalue(11, cpl_table_count_invalid(table, "New AFloat"), - "Count New AFloat NULLs... "); - - test_ivalue(11, cpl_table_count_invalid(table, "New ADouble"), - "Count New ADouble NULLs... "); - - test(cpl_table_move_column(copia, "New Integer", table), - "Moving column \"New Integer\" to another table... "); - - test(cpl_table_move_column(copia, "New LongLong", table), - "Moving column \"New LongLong\" to another table... "); - - test(cpl_table_move_column(copia, "New Float", table), - "Moving column \"New Float\" to another table... "); - - test(cpl_table_move_column(copia, "New Double", table), - "Moving column \"New Double\" to another table... "); - - test(cpl_table_move_column(copia, "New String", table), - "Moving column \"New String\" to another table... "); - - test_failure(CPL_ERROR_ILLEGAL_OUTPUT, - cpl_table_name_column(copia, "New String", "String"), - "Try illegal column renaming... "); - - test(cpl_table_name_column(copia, "New Integer", "Old Integer"), - "Try legal column renaming... "); - -/**+ FIXME: RESTORE!!! */ - error = cpl_table_fill_invalid_int(table, "Integer", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_int(table, "AInt", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_int(table, "New AInt", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_long_long(table, "LongLong", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_long_long(table, "ALongLong", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_long_long(table, "New ALongLong", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_save(table, NULL, NULL, BASE "16.fits", CPL_IO_CREATE); - cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_fits(BASE "16.fits"); - cpl_table_delete(table); - table = cpl_table_load(BASE "16.fits", 1, 1); -/**/ + copia = cpl_table_new(5); - test_ivalue(!0, cpl_table_has_column(copia, "Old Integer"), - "Check if column \"Old Integer\" exists... "); + error = cpl_table_set_column_unit(table, "Integer", "Counts"); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_set_column_unit(table, "Double", "erg/sec"); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_set_column_unit(table, "String", "Name"); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_set_column_unit(table, "AFloat", "erg/sec"); + cpl_test_eq_error(error, CPL_ERROR_NONE); -#ifdef CPL_TABLE_TEST_DEPRECATED - test_svalue("Integer", cpl_table_get_column_name(copia), - "Check name column 1... "); + test(cpl_table_copy_structure(copia, table), + "Creating a new cpl_table modeled on an existing cpl_table... "); - test_svalue("LongLong", cpl_table_get_column_name(NULL), - "Check name column 2... "); + test_ivalue(5, cpl_table_get_nrow(copia), "Check table length (2)... "); + test_ivalue(15, cpl_table_get_ncol(copia), "Check table width... "); - test_svalue("Double", cpl_table_get_column_name(NULL), - "Check name column 3... "); + test(cpl_table_compare_structure(table, copia), + "Tables must have the same structure... "); + cpl_table_erase_column(copia, "Double"); + test_ivalue(1, cpl_table_compare_structure(table, copia), + "Deleting column Double - now tables must have different " + "structure... "); + test(cpl_table_new_column(copia, "Double", CPL_TYPE_DOUBLE), + "Creating again the Double column... "); + error = cpl_table_set_column_unit(copia, "Double", "erg/sec"); + cpl_test_eq_error(error, CPL_ERROR_NONE); + test(cpl_table_compare_structure(table, copia), + "Tables must have the same structure again... "); - test_svalue("CDouble", cpl_table_get_column_name(NULL), - "Check name column 3a... "); + test(cpl_table_fill_column_window_int(copia, "Integer", 0, 5, -1), + "Fill column Integer of new table... "); + test(cpl_table_fill_column_window_long_long(copia, "LongLong", 0, 5, -1), + "Fill column LongLong of new table... "); + test(cpl_table_fill_column_window_double(copia, "Double", 0, 5, -1.11), + "Fill column Double of new table... "); + test(cpl_table_fill_column_window_float(copia, "Float", 0, 5, -1.1), + "Fill column Float of new table... "); - test_svalue("CDoubleDouble", cpl_table_get_column_name(NULL), - "Check name column 3b... "); +#ifdef _Complex_I + test(cpl_table_fill_column_window_double_complex(copia, "CDouble", 0, 5, + -1.11 + 4.11 * I), + "Fill column CDouble of new table... "); + + test(cpl_table_fill_column_window_float_complex(copia, "CFloat", 0, 5, + -1.1 + 4.1 * I), + "Fill column CFloat of new table... "); +#endif + test(cpl_table_fill_column_window_string(copia, "String", 0, 5, "extra"), + "Fill column String of new table... "); + + array = cpl_array_new(20, CPL_TYPE_INT); + for (j = 0; j < 20; j++) + cpl_array_set_int(array, j, j); + test(cpl_table_fill_column_window_array(copia, "AInt", 0, 5, array), + "Fill column AInt of new table... "); + cpl_array_delete(array); + + array = cpl_array_new(20, CPL_TYPE_LONG_LONG); + for (j = 0; j < 20; j++) + cpl_array_set_long_long(array, j, j); + test(cpl_table_fill_column_window_array(copia, "ALongLong", 0, 5, array), + "Fill column ALongLong of new table... "); + cpl_array_delete(array); + + array = cpl_array_new(20, CPL_TYPE_FLOAT); + for (j = 0; j < 20; j++) + cpl_array_set_float(array, j, j); + test(cpl_table_fill_column_window_array(copia, "AFloat", 0, 5, array), + "Fill column AFloat of new table... "); + cpl_array_delete(array); + + array = cpl_array_new(20, CPL_TYPE_DOUBLE); + for (j = 0; j < 20; j++) + cpl_array_set_double(array, j, j); + test(cpl_table_fill_column_window_array(copia, "ADouble", 0, 5, array), + "Fill column ADouble of new table... "); + cpl_array_delete(array); - test_svalue("String", cpl_table_get_column_name(NULL), - "Check name column 4... "); +#ifdef _Complex_I + array = cpl_array_new(20, CPL_TYPE_FLOAT_COMPLEX); + for (j = 0; j < 20; j++) + cpl_array_set_float_complex(array, j, j + 0.5 * I); + test(cpl_table_fill_column_window_array(copia, "CAFloat", 0, 5, array), + "Fill column CAFloat of new table... "); + cpl_array_delete(array); + + array = cpl_array_new(20, CPL_TYPE_DOUBLE_COMPLEX); + for (j = 0; j < 20; j++) + cpl_array_set_double_complex(array, j, j + 0.5 * I); + test(cpl_table_fill_column_window_array(copia, "CADouble", 0, 5, array), + "Fill column CADouble of new table... "); + cpl_array_delete(array); +#endif + + array = cpl_array_wrap_string(sArray, 10); + test(cpl_table_fill_column_window_array(copia, "AString", 0, 5, array), + "Fill column AString of new table... "); + cpl_array_unwrap(array); + + + test(cpl_table_insert(table, copia, 15), + "Appending new table to old table... "); + test(cpl_table_insert(table, copia, 5), + "Inserting new table in old table... "); + test(cpl_table_insert(table, copia, 0), + "Prepending new table to old table... "); - test_svalue("Float", cpl_table_get_column_name(NULL), - "Check name column 5... "); + cpl_table_delete(copia); - test_svalue("CFloat", cpl_table_get_column_name(NULL), - "Check name column 5a... "); + /**+ FIXME: RESTORE!!! */ + error = cpl_table_fill_invalid_int(table, "Integer", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_int(table, "AInt", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_long_long(table, "LongLong", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_long_long(table, "ALongLong", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_save(table, NULL, NULL, BASE "2.fits", CPL_IO_CREATE); + cpl_test_eq_error(error, CPL_ERROR_NONE); + cpl_test_fits(BASE "2.fits"); + cpl_table_delete(table); + table = cpl_table_load(BASE "2.fits", 1, 1); + cpl_test_nonnull(table); + // FIXME: IO_APPEND initial test only! + cpl_table_save(table, NULL, NULL, BASE "2a.fits", CPL_IO_CREATE); + cpl_table_save(table, NULL, NULL, BASE "2a.fits", CPL_IO_APPEND); + cpl_test_fits(BASE "2a.fits"); + /**/ + + test_ivalue(25, cpl_table_get_nrow(table), "Check table length (3)... "); + + icheck[0] = -1; + icheck[1] = -1; + icheck[2] = -1; + icheck[3] = -1; + icheck[4] = -1; + icheck[5] = 5; + icheck[6] = 0; + icheck[7] = 2; + icheck[8] = 8; + icheck[9] = 9; + icheck[10] = -1; + icheck[11] = -1; + icheck[12] = -1; + icheck[13] = -1; + icheck[14] = -1; + icheck[15] = 3; + icheck[16] = 7; + icheck[17] = 1; + icheck[18] = 4; + icheck[19] = 6; + icheck[20] = -1; + icheck[21] = -1; + icheck[22] = -1; + icheck[23] = -1; + icheck[24] = -1; + + for (i = 0; i < 25; i++) { + test_ivalue(icheck[i], cpl_table_get_int(table, "Integer", i, &null), + "Check Integer column... "); + cpl_test_zero(null); + } - test_svalue("AInt", cpl_table_get_column_name(NULL), - "Check name column 6... "); + for (i = 0; i < 25; i++) { + test_ivalue(icheck[i], + cpl_table_get_long_long(table, "LongLong", i, &null), + "Check LongLong column... "); + cpl_test_zero(null); + } - test_svalue("ALongLong", cpl_table_get_column_name(NULL), - "Check name column 7... "); + dcheck[0] = -1.1100; + dcheck[1] = -1.1100; + dcheck[2] = -1.1100; + dcheck[3] = -1.1100; + dcheck[4] = -1.1100; + dcheck[5] = 5.1100; + dcheck[6] = 0.1100; + dcheck[7] = 2.1100; + dcheck[8] = 8.1100; + dcheck[9] = 9.1100; + dcheck[10] = -1.1100; + dcheck[11] = -1.1100; + dcheck[12] = -1.1100; + dcheck[13] = -1.1100; + dcheck[14] = -1.1100; + dcheck[15] = 3.1100; + dcheck[16] = 7.1100; + dcheck[17] = 1.1100; + dcheck[18] = 4.1100; + dcheck[19] = 6.1100; + dcheck[20] = -1.1100; + dcheck[21] = -1.1100; + dcheck[22] = -1.1100; + dcheck[23] = -1.1100; + dcheck[24] = -1.1100; + + for (i = 0; i < 25; i++) { + test_fvalue(dcheck[i], 0.00001, + cpl_table_get_double(table, "Double", i, &null), + "Check Double column... "); + cpl_test_zero(null); + } - test_svalue("AFloat", cpl_table_get_column_name(NULL), - "Check name column 8... "); - - test_svalue("ADouble", cpl_table_get_column_name(NULL), - "Check name column 9... "); + scheck[0] = "extra"; + scheck[1] = "extra"; + scheck[2] = "extra"; + scheck[3] = "extra"; + scheck[4] = "extra"; + scheck[5] = "caaaa"; + scheck[6] = "abcd"; + scheck[7] = "aaaa"; + scheck[8] = "daaa"; + scheck[9] = "acde"; + scheck[10] = "extra"; + scheck[11] = "extra"; + scheck[12] = "extra"; + scheck[13] = "extra"; + scheck[14] = "extra"; + scheck[15] = "baaa"; + scheck[16] = "aaaa"; + scheck[17] = "acde"; + scheck[18] = " sss"; + scheck[19] = "daaa"; + scheck[20] = "extra"; + scheck[21] = "extra"; + scheck[22] = "extra"; + scheck[23] = "extra"; + scheck[24] = "extra"; + + for (i = 0; i < 25; i++) { + test_svalue(scheck[i], cpl_table_get_string(table, "String", i), + "Check String column... "); + } - test_svalue("CAFloat", cpl_table_get_column_name(NULL), - "Check name column 8a... "); - - test_svalue("CADouble", cpl_table_get_column_name(NULL), - "Check name column 9a... "); - - test_svalue("AString", cpl_table_get_column_name(NULL), - "Check name column 10... "); + fcheck[0] = -1.10; + fcheck[1] = -1.10; + fcheck[2] = -1.10; + fcheck[3] = -1.10; + fcheck[4] = -1.10; + fcheck[5] = 5.10; + fcheck[6] = 0.10; + fcheck[7] = 2.10; + fcheck[8] = 8.10; + fcheck[9] = 9.10; + fcheck[10] = -1.10; + fcheck[11] = -1.10; + fcheck[12] = -1.10; + fcheck[13] = -1.10; + fcheck[14] = -1.10; + fcheck[15] = 3.10; + fcheck[16] = 7.10; + fcheck[17] = 1.10; + fcheck[18] = 4.10; + fcheck[19] = 6.10; + fcheck[20] = -1.10; + fcheck[21] = -1.10; + fcheck[22] = -1.10; + fcheck[23] = -1.10; + fcheck[24] = -1.10; + + for (i = 0; i < 25; i++) { + test_fvalue(fcheck[i], 0.00001, + cpl_table_get_float(table, "Float", i, &null), + "Check Float column... "); + cpl_test_zero(null); + } - test_svalue("Old Integer", cpl_table_get_column_name(NULL), - "Check name column 11... "); +#ifdef _Complex_I + cfcheck[0] = -1.1 + 4.1 * I; + cfcheck[1] = -1.1 + 4.1 * I; + cfcheck[2] = -1.1 + 4.1 * I; + cfcheck[3] = -1.1 + 4.1 * I; + cfcheck[4] = -1.1 + 4.1 * I; + cfcheck[5] = 5.1; + cfcheck[6] = 0.1 * I; + cfcheck[7] = 2.1; + cfcheck[8] = 8.1 * I; + cfcheck[9] = 9.1 + 9.1 * I; + cfcheck[10] = -1.1 + 4.1 * I; + cfcheck[11] = -1.1 + 4.1 * I; + cfcheck[12] = -1.1 + 4.1 * I; + cfcheck[13] = -1.1 + 4.1 * I; + cfcheck[14] = -1.1 + 4.1 * I; + cfcheck[15] = 3.1 - 3.1 * I; + cfcheck[16] = 7.1 + 1.1 * I; + cfcheck[17] = 1.1 - 7.1 * I; + cfcheck[18] = -4.1 + 4.1 * I; + cfcheck[19] = -6.1 - 6.1 * I; + cfcheck[20] = -1.1 + 4.1 * I; + cfcheck[21] = -1.1 + 4.1 * I; + cfcheck[22] = -1.1 + 4.1 * I; + cfcheck[23] = -1.1 + 4.1 * I; + cfcheck[24] = -1.1 + 4.1 * I; + + for (i = 0; i < 25; i++) { + test_cvalue(cfcheck[i], 0.00001, + cpl_table_get_float_complex(table, "CFloat", i, &null), + "Check CFloat column... "); + cpl_test_zero(null); + } - test_svalue("New LongLong", cpl_table_get_column_name(NULL), - "Check name column 12... "); + cdcheck[0] = -1.11 + 4.11 * I; + cdcheck[1] = -1.11 + 4.11 * I; + cdcheck[2] = -1.11 + 4.11 * I; + cdcheck[3] = -1.11 + 4.11 * I; + cdcheck[4] = -1.11 + 4.11 * I; + cdcheck[5] = 5.11; + cdcheck[6] = 0.11 * I; + cdcheck[7] = 2.11; + cdcheck[8] = 8.11 * I; + cdcheck[9] = 9.11 + 9.11 * I; + cdcheck[10] = -1.11 + 4.11 * I; + cdcheck[11] = -1.11 + 4.11 * I; + cdcheck[12] = -1.11 + 4.11 * I; + cdcheck[13] = -1.11 + 4.11 * I; + cdcheck[14] = -1.11 + 4.11 * I; + cdcheck[15] = 3.11 - 3.11 * I; + cdcheck[16] = 7.11 + 1.11 * I; + cdcheck[17] = 1.11 - 7.11 * I; + cdcheck[18] = -4.11 + 4.11 * I; + cdcheck[19] = -6.11 - 6.11 * I; + cdcheck[20] = -1.11 + 4.11 * I; + cdcheck[21] = -1.11 + 4.11 * I; + cdcheck[22] = -1.11 + 4.11 * I; + cdcheck[23] = -1.11 + 4.11 * I; + cdcheck[24] = -1.11 + 4.11 * I; + + for (i = 0; i < 25; i++) { + test_cvalue(cdcheck[i], 0.00001, + cpl_table_get_double_complex(table, "CDouble", i, &null), + "Check CDouble column... "); + cpl_test_zero(null); + } +#endif - test_svalue("New Float", cpl_table_get_column_name(NULL), - "Check name column 13... "); + test(cpl_table_set_invalid(table, "Integer", 0), + "Set Integer 0 to NULL... "); + test(cpl_table_set_invalid(table, "Integer", 5), + "Set Integer 5 to NULL... "); + test(cpl_table_set_invalid(table, "Integer", 24), + "Set Integer 24 to NULL... "); + + test(cpl_table_set_invalid(table, "LongLong", 0), + "Set LongLong 0 to NULL... "); + test(cpl_table_set_invalid(table, "LongLong", 5), + "Set LongLong 5 to NULL... "); + test(cpl_table_set_invalid(table, "LongLong", 24), + "Set LongLong 24 to NULL... "); + + test(cpl_table_set_invalid(table, "AInt", 0), "Set AInt 0 to NULL... "); + test(cpl_table_set_invalid(table, "ALongLong", 0), + "Set ALongLong 0 to NULL... "); + test(cpl_table_set_invalid(table, "AFloat", 5), "Set AFloat 5 to NULL... "); + test(cpl_table_set_invalid(table, "ADouble", 24), + "Set ADouble 24 to NULL... "); + test(cpl_table_set_invalid(table, "CAFloat", 5), + "Set CAFloat 5 to NULL... "); + test(cpl_table_set_invalid(table, "CADouble", 24), + "Set CADouble 24 to NULL... "); + + + test_ivalue(3, cpl_table_count_invalid(table, "Integer"), + "Count Integer written NULLs... "); + test_ivalue(1, cpl_table_count_invalid(table, "AInt"), + "Count AInt written NULLs... "); + test_ivalue(3, cpl_table_count_invalid(table, "LongLong"), + "Count LongLong written NULLs... "); + test_ivalue(1, cpl_table_count_invalid(table, "ALongLong"), + "Count ALongLong written NULLs... "); + test_ivalue(1, cpl_table_count_invalid(table, "AFloat"), + "Count AFloat written NULLs... "); + test_ivalue(1, cpl_table_count_invalid(table, "ADouble"), + "Count ADouble written NULLs... "); + test_ivalue(1, cpl_table_count_invalid(table, "CAFloat"), + "Count CAFloat written NULLs... "); + test_ivalue(1, cpl_table_count_invalid(table, "CADouble"), + "Count CADouble written NULLs... "); - test_svalue("New Double", cpl_table_get_column_name(NULL), - "Check name column 14... "); - test_svalue("New String", cpl_table_get_column_name(NULL), - "Check name column 15... "); + /**+ FIXME: RESTORE!!! */ + error = cpl_table_fill_invalid_int(table, "Integer", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_int(table, "AInt", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_long_long(table, "LongLong", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_long_long(table, "ALongLong", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_float(table, "AFloat", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_double(table, "ADouble", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_float_complex(table, "CAFloat", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_double_complex(table, "CADouble", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); - test_pvalue(NULL, (void *)cpl_table_get_column_name(NULL), - "Check if no more colums... "); -#endif + test_ivalue(3, cpl_table_count_invalid(table, "Integer"), + "Count Integer written NULLs... "); + test_ivalue(3, cpl_table_count_invalid(table, "LongLong"), + "Count LongLong written NULLs... "); + test_ivalue(1, cpl_table_count_invalid(table, "AFloat"), + "Count AFloat written NULLs... "); + test_ivalue(1, cpl_table_count_invalid(table, "ADouble"), + "Count ADouble written NULLs... "); + test_ivalue(1, cpl_table_count_invalid(table, "CAFloat"), + "Count CAFloat written NULLs... "); + test_ivalue(1, cpl_table_count_invalid(table, "CADouble"), + "Count CADouble written NULLs... "); + /* Array elements are flagged as valid! */ + test_ivalue(0, cpl_table_count_invalid(table, "AInt"), + "Count AInt written NULLs... "); + test_ivalue(0, cpl_table_count_invalid(table, "ALongLong"), + "Count ALongLong written NULLs... "); - /* - * Test new function cpl_table_get_column_names() - */ + error = cpl_table_save(table, NULL, NULL, BASE "3.fits", CPL_IO_CREATE); + cpl_test_eq_error(error, CPL_ERROR_NONE); + cpl_test_fits(BASE "3.fits"); + cpl_table_delete(table); + table = cpl_table_load(BASE "3.fits", 1, 1); + cpl_test_nonnull(table); + cpl_test_eq(cpl_table_get_nrow(table), 25); + /**/ - colnames = cpl_table_get_column_names(copia); - test_ivalue(20, cpl_array_get_size(colnames), "Count table colnames... "); + test_ivalue(3, cpl_table_count_invalid(table, "Integer"), + "Count Integer written NULLs... "); + test_ivalue(1, cpl_table_count_invalid(table, "AInt"), + "Count AInt written NULLs... "); + test_ivalue(3, cpl_table_count_invalid(table, "LongLong"), + "Count LongLong written NULLs... "); + test_ivalue(1, cpl_table_count_invalid(table, "ALongLong"), + "Count ALongLong written NULLs... "); + test_ivalue(1, cpl_table_count_invalid(table, "AFloat"), + "Count AFloat written NULLs... "); + test_ivalue(1, cpl_table_count_invalid(table, "ADouble"), + "Count ADouble written NULLs... "); + test_ivalue(1, cpl_table_count_invalid(table, "CAFloat"), + "Count CAFloat written NULLs... "); + test_ivalue(1, cpl_table_count_invalid(table, "CADouble"), + "Count CADouble written NULLs... "); + + for (i = 0; i < 25; i++) { + const int ival = cpl_table_get_int(table, "Integer", i, &null); + if (!null) { + test_ivalue(icheck[i], ival, "Check Integer column... "); + } + else { + cpl_test(i == 0 || i == 5 || i == 24); + } + } - test_svalue("Integer", cpl_array_get_string(colnames, 0), - "Check name col 1... "); + for (i = 0; i < 25; i++) { + const long long ival = + cpl_table_get_long_long(table, "LongLong", i, &null); + if (!null) { + test_ivalue(icheck[i], ival, "Check LongLong column... "); + } + else { + cpl_test(i == 0 || i == 5 || i == 24); + } + } - test_svalue("LongLong", cpl_array_get_string(colnames, 1), - "Check name col 2... "); + test(cpl_table_set_int(table, "Integer", 0, -1), "Set Integer 0 to -1... "); + test(cpl_table_set_int(table, "Integer", 5, 5), "Set Integer 5 to 5... "); + test(cpl_table_set_int(table, "Integer", 24, -1), + "Set Integer 24 to -1... "); + + array = cpl_array_new(20, CPL_TYPE_INT); + for (j = 0; j < 20; j++) + cpl_array_set_int(array, j, j); + test(cpl_table_set_array(table, "AInt", 0, array), + "Set a valid array to AInt 0... "); + cpl_array_delete(array); + test_ivalue(0, cpl_table_count_invalid(table, "AInt"), + "No invalid elements in AInt... "); + + test(cpl_table_set_long_long(table, "LongLong", 0, -1), + "Set LongLong 0 to -1... "); + test(cpl_table_set_long_long(table, "LongLong", 5, 5), + "Set LongLong 5 to 5... "); + test(cpl_table_set_long_long(table, "LongLong", 24, -1), + "Set LongLong 24 to -1... "); + + array = cpl_array_new(20, CPL_TYPE_LONG_LONG); + for (j = 0; j < 20; j++) + cpl_array_set_long_long(array, j, j); + test(cpl_table_set_array(table, "ALongLong", 0, array), + "Set a valid array to ALongLong 0... "); + cpl_array_delete(array); + test_ivalue(0, cpl_table_count_invalid(table, "ALongLong"), + "No invalid elements in ALongLong... "); + + array = cpl_array_new(20, CPL_TYPE_FLOAT); + for (j = 0; j < 20; j++) + cpl_array_set_float(array, j, j); + test(cpl_table_set_array(table, "AFloat", 5, array), + "Set a valid array to AFloat 5... "); + cpl_array_delete(array); + test_ivalue(0, cpl_table_count_invalid(table, "AFloat"), + "No invalid elements in AFloat... "); + + array = cpl_array_new(20, CPL_TYPE_DOUBLE); + for (j = 0; j < 20; j++) + cpl_array_set_double(array, j, j); + test(cpl_table_set_array(table, "ADouble", 24, array), + "Set a valid array to ADouble 24... "); + cpl_array_delete(array); + test_ivalue(0, cpl_table_count_invalid(table, "ADouble"), + "No invalid elements in ADouble... "); - test_svalue("Double", cpl_array_get_string(colnames, 2), - "Check name col 3... "); +#ifdef _Complex_I + array = cpl_array_new(20, CPL_TYPE_FLOAT_COMPLEX); + for (j = 0; j < 20; j++) + cpl_array_set_float_complex(array, j, j + 0.5 * I); + test(cpl_table_set_array(table, "CAFloat", 5, array), + "Set a valid array to CAFloat 5... "); + cpl_array_delete(array); + test_ivalue(0, cpl_table_count_invalid(table, "CAFloat"), + "No invalid elements in CAFloat... "); + + array = cpl_array_new(20, CPL_TYPE_DOUBLE_COMPLEX); + for (j = 0; j < 20; j++) + cpl_array_set_double_complex(array, j, j + 0.5 * I); + test(cpl_table_set_array(table, "CADouble", 24, array), + "Set a valid array to CADouble 24... "); + cpl_array_delete(array); + test_ivalue(0, cpl_table_count_invalid(table, "CADouble"), + "No invalid elements in CADouble... "); +#endif - test_svalue("CDouble", cpl_array_get_string(colnames, 3), - "Check name col 4... "); + /**+ FIXME: RESTORE!!! %%%%% */ + error = cpl_table_fill_invalid_int(table, "Integer", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_int(table, "AInt", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_long_long(table, "LongLong", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_long_long(table, "ALongLong", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_save(table, NULL, NULL, BASE "4.fits", CPL_IO_CREATE); + cpl_test_eq_error(error, CPL_ERROR_NONE); + cpl_test_fits(BASE "4.fits"); + cpl_table_delete(table); + table = cpl_table_load(BASE "4.fits", 1, 1); + cpl_test_nonnull(table); + cpl_test_eq(cpl_table_get_nrow(table), 25); + /**/ - test_svalue("CDoubleDouble", cpl_array_get_string(colnames, 4), - "Check name column 5... "); + test_ivalue(0, cpl_table_count_invalid(table, "Integer"), + "Count NULLs... "); - test_svalue("String", cpl_array_get_string(colnames, 5), - "Check name col 6... "); + for (i = 0; i < 25; i++) { + const int ival = cpl_table_get_int(table, "Integer", i, &null); - test_svalue("Float", cpl_array_get_string(colnames, 6), - "Check name col 7... "); + cpl_test_zero(null); - test_svalue("CFloat", cpl_array_get_string(colnames, 7), - "Check name col 8... "); + if (!null) { + test_ivalue(icheck[i], ival, "Check Integer column... "); + } + } - test_svalue("AInt", cpl_array_get_string(colnames, 8), - "Check name col 9... "); + test_ivalue(0, cpl_table_count_invalid(table, "LongLong"), + "Count NULLs... "); - test_svalue("ALongLong", cpl_array_get_string(colnames, 9), - "Check name col 10... "); + for (i = 0; i < 25; i++) { + const int ival = cpl_table_get_long_long(table, "LongLong", i, &null); - test_svalue("AFloat", cpl_array_get_string(colnames, 10), - "Check name col 11... "); + cpl_test_zero(null); - test_svalue("ADouble", cpl_array_get_string(colnames, 11), - "Check name col 12... "); + if (!null) { + test_ivalue(icheck[i], ival, "Check LongLong column... "); + } + } - test_svalue("CAFloat", cpl_array_get_string(colnames, 12), - "Check name col 13... "); + test(cpl_table_set_invalid(table, "Double", 0), "Set Double 0 to NULL... "); + test(cpl_table_set_invalid(table, "Double", 5), "Set Double 5 to NULL... "); + test(cpl_table_set_invalid(table, "Double", 24), + "Set Double 24 to NULL... "); - test_svalue("CADouble", cpl_array_get_string(colnames, 13), - "Check name col 14... "); + /**+ FIXME: RESTORE!!! */ + error = cpl_table_fill_invalid_int(table, "Integer", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_int(table, "AInt", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_long_long(table, "LongLong", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_long_long(table, "ALongLong", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_save(table, NULL, NULL, BASE "5.fits", CPL_IO_CREATE); + cpl_test_eq_error(error, CPL_ERROR_NONE); + cpl_test_fits(BASE "5.fits"); + cpl_table_delete(table); + table = cpl_table_load(BASE "5.fits", 1, 1); + cpl_test_nonnull(table); + cpl_test_eq(cpl_table_get_nrow(table), 25); + /**/ - test_svalue("AString", cpl_array_get_string(colnames, 14), - "Check name col 15... "); + test_ivalue(3, cpl_table_count_invalid(table, "Double"), + "Count written Double NULLs... "); - test_svalue("Old Integer", cpl_array_get_string(colnames, 15), - "Check name col 16... "); + for (i = 0; i < 25; i++) { + const double dval = cpl_table_get_double(table, "Double", i, &null); + if (!null) { + test_fvalue(dcheck[i], 0.0, dval, "Check Double column... "); + } + else { + cpl_test(i == 0 || i == 5 || i == 24); + } + } - test_svalue("New LongLong", cpl_array_get_string(colnames, 16), - "Check name col 17... "); + test(cpl_table_set_double(table, "Double", 0, -1.11), + "Set Double 0 to -1.11... "); + test(cpl_table_set_double(table, "Double", 5, 5.11), + "Set Double 5 to 5.11... "); + test(cpl_table_set_double(table, "Double", 24, -1.11), + "Set Double 24 to -1.11... "); - test_svalue("New Float", cpl_array_get_string(colnames, 17), - "Check name col 18... "); + /**+ FIXME: RESTORE!!! */ + error = cpl_table_fill_invalid_int(table, "Integer", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_int(table, "AInt", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_long_long(table, "LongLong", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_long_long(table, "ALongLong", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_save(table, NULL, NULL, BASE "6.fits", CPL_IO_CREATE); + cpl_test_eq_error(error, CPL_ERROR_NONE); + cpl_test_fits(BASE "6.fits"); + cpl_table_delete(table); + table = cpl_table_load(BASE "6.fits", 1, 1); + cpl_test_nonnull(table); + cpl_test_eq(cpl_table_get_nrow(table), 25); + /**/ - test_svalue("New Double", cpl_array_get_string(colnames, 18), - "Check name col 19... "); + test_ivalue(0, cpl_table_count_invalid(table, "Double"), "Count NULLs... "); - test_svalue("New String", cpl_array_get_string(colnames, 19), - "Check name col 20... "); - cpl_array_delete(colnames); - cpl_table_delete(copia); + for (i = 0; i < 25; i++) { + const double dval = cpl_table_get_double(table, "Double", i, &null); + cpl_test_zero(null); + if (!null) { + test_fvalue(dcheck[i], 0.00001, dval, "Check Double column... "); + } + } - test(cpl_table_set_size(table, 30), "Expanding table to 30 rows... "); + test(cpl_table_set_invalid(table, "String", 0), "Set String 0 to NULL... "); + test(cpl_table_set_invalid(table, "String", 5), "Set String 5 to NULL... "); + test(cpl_table_set_invalid(table, "String", 24), + "Set String 24 to NULL... "); -/* - * The following would do the same as cpl_table_set_size(table, 30), in - * case cpl_table_set_size() would be crossed out... + /**+ FIXME: RESTORE!!! %%% */ + error = cpl_table_fill_invalid_int(table, "Integer", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_int(table, "AInt", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_long_long(table, "LongLong", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_long_long(table, "ALongLong", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_save(table, NULL, NULL, BASE "7.fits", CPL_IO_CREATE); + cpl_test_eq_error(error, CPL_ERROR_NONE); + cpl_test_fits(BASE "7.fits"); + cpl_table_delete(table); + table = cpl_table_load(BASE "7.fits", 1, 1); + cpl_test_nonnull(table); + cpl_test_eq(cpl_table_get_nrow(table), 25); + /**/ - test(cpl_table_insert_window(table, 24, 7), "Expanding table to 30 rows... "); -*/ + test_ivalue(3, cpl_table_count_invalid(table, "String"), + "Count written String NULLs... "); - test_ivalue(12, cpl_table_count_invalid(table, "Integer"), - "Count \"Integer\" NULLs... "); + for (i = 0; i < 25; i++) { + const char *sval = cpl_table_get_string(table, "String", i); - test_ivalue(12, cpl_table_count_invalid(table, "String"), - "Count \"String\" NULLs... "); + if (sval != NULL) { + test_svalue(scheck[i], sval, "Check String column... "); + } + else { + cpl_test(i == 0 || i == 5 || i == 24); + } + } - test(cpl_table_set_size(table, 22), "Truncating table to 22 rows... "); + test(cpl_table_set_string(table, "String", 0, "extra"), + "Set String 0 to \"extra\"... "); + test(cpl_table_set_string(table, "String", 5, "caaaa"), + "Set String 5 to \"caaaa\"... "); + test(cpl_table_set_string(table, "String", 24, "extra"), + "Set String 24 to \"extra\"... "); -/* - * The following would do the same as cpl_table_set_size(table, 30), in - * case cpl_table_set_size() would be crossed out... + /**+ FIXME: RESTORE!!! %%% */ + error = cpl_table_fill_invalid_int(table, "Integer", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_int(table, "AInt", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_long_long(table, "LongLong", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_long_long(table, "ALongLong", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_save(table, NULL, NULL, BASE "8.fits", CPL_IO_CREATE); + cpl_test_eq_error(error, CPL_ERROR_NONE); + cpl_test_fits(BASE "8.fits"); + cpl_table_delete(table); + table = cpl_table_load(BASE "8.fits", 1, 1); + cpl_test_nonnull(table); + cpl_test_eq(cpl_table_get_nrow(table), 25); + /**/ - test(cpl_table_erase_window(table, 22, 1000), - "Truncating table to 22 rows... "); -*/ - -/**+ FIXME: RESTORE!!! */ - error = cpl_table_fill_invalid_int(table, "Integer", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_int(table, "AInt", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_int(table, "New AInt", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_long_long(table, "LongLong", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_long_long(table, "ALongLong", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_long_long(table, "New ALongLong", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_save(table, NULL, NULL, BASE "17.fits", CPL_IO_CREATE); - cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_fits(BASE "17.fits"); - cpl_table_delete(table); - table = cpl_table_load(BASE "17.fits", 1, 1); -/**/ - - cpl_table_erase_column(table, "CDouble"); - cpl_table_erase_column(table, "CDoubleDouble"); - cpl_table_erase_column(table, "CFloat"); - cpl_table_erase_column(table, "CAFloat"); - cpl_table_erase_column(table, "CADouble"); - - // FIXME: To be continued. - cpl_table_erase_column(table, "LongLong"); - cpl_table_erase_column(table, "ALongLong"); - cpl_table_erase_column(table, "New ALongLong"); - - // FIXME: Remove the string array column here because for some of - // the following tests it would mess up the expected row/column - // numbers. They need to be fixed before this line is removed! - cpl_table_erase_column(table, "AString"); - - - test_ivalue(5, cpl_table_count_invalid(table, "Integer"), - "Count \"Integer\" NULLs (2)... "); - - test_ivalue(5, cpl_table_count_invalid(table, "String"), - "Count \"String\" NULLs (2)... "); - - test_data(copia, cpl_table_extract(table, 0, 5), - "Creating subtable from rows 0-5 of original... "); - - test_ivalue(1, cpl_table_count_invalid(copia, "Integer"), - "Count \"Integer\" NULLs... "); - - test_ivalue(1, cpl_table_count_invalid(copia, "String"), - "Count \"String\" NULLs... "); - - cpl_table_delete(copia); - - test_data(copia, cpl_table_extract(table, 8, 5), - "Creating subtable from rows 8-5 of original... "); - - test_ivalue(1, cpl_table_count_invalid(copia, "Float"), - "Count \"Float\" NULLs... "); + test_ivalue(0, cpl_table_count_invalid(table, "String"), "Count NULLs... "); - test_ivalue(1, cpl_table_count_invalid(copia, "String"), - "Count \"String\" NULLs... "); + for (i = 0; i < 25; i++) { + test_svalue(scheck[i], cpl_table_get_string(table, "String", i), + "Check String column... "); + } - cpl_table_delete(copia); + test(cpl_table_set_invalid(table, "Float", 0), "Set Float 0 to NULL... "); + test(cpl_table_set_invalid(table, "Float", 5), "Set Float 5 to NULL... "); + test(cpl_table_set_invalid(table, "Float", 24), "Set Float 24 to NULL... "); - test_data(copia, cpl_table_extract(table, 15, 30), - "Creating subtable from rows 15 till end of original... "); + /**+ FIXME: RESTORE!!! */ + error = cpl_table_fill_invalid_int(table, "Integer", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_int(table, "AInt", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_long_long(table, "LongLong", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_long_long(table, "ALongLong", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_save(table, NULL, NULL, BASE "9.fits", CPL_IO_CREATE); + cpl_test_eq_error(error, CPL_ERROR_NONE); + cpl_test_fits(BASE "9.fits"); + cpl_table_delete(table); + table = cpl_table_load(BASE "9.fits", 1, 1); + cpl_test_nonnull(table); + cpl_test_eq(cpl_table_get_nrow(table), 25); + /**/ + + test_ivalue(3, cpl_table_count_invalid(table, "Float"), + "Count written Float NULLs... "); - test_ivalue(3, cpl_table_count_invalid(copia, "Double"), - "Count \"Double\" NULLs... "); + for (i = 0; i < 25; i++) { + const float fval = cpl_table_get_float(table, "Float", i, &null); - test_ivalue(3, cpl_table_count_invalid(copia, "String"), - "Count \"String\" NULLs... "); + if (!null) { + test_fvalue(fcheck[i], 0.0, fval, "Check Float column... "); + } + else { + cpl_test(i == 0 || i == 5 || i == 24); + } + } - cpl_table_delete(copia); + test(cpl_table_set_float(table, "Float", 0, -1.1), + "Set Float 0 to -1.1... "); + test(cpl_table_set_float(table, "Float", 5, 5.1), "Set Float 5 to 5.1... "); + test(cpl_table_set_float(table, "Float", 24, -1.1), + "Set Float 24 to -1.1... "); - test(cpl_table_cast_column(table, "Float", "FloatToInt", CPL_TYPE_INT), - "Casting float column to integer colum... "); - -/**+ FIXME: RESTORE!!! */ - error = cpl_table_fill_invalid_int(table, "Integer", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_int(table, "FloatToInt", -2); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_int(table, "AInt", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_int(table, "New AInt", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_save(table, NULL, NULL, BASE "18.fits", CPL_IO_CREATE); - cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_fits(BASE "18.fits"); - cpl_table_delete(table); - table = cpl_table_load(BASE "18.fits", 1, 1); -/**/ - - test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 0, &null), - "Check element 1 of casted column... "); - cpl_test_zero(null); - test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 1, &null), - "Check element 2 of casted column... "); - cpl_test_zero(null); - test_ivalue(0, cpl_table_is_valid(table, "FloatToInt", 2), - "Check element 3 of casted column... "); - test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 3, &null), - "Check element 4 of casted column... "); - cpl_test_zero(null); - test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 4, &null), - "Check element 5 of casted column... "); - cpl_test_zero(null); - test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 5, &null), - "Check element 6 of casted column... "); - cpl_test_zero(null); - test_ivalue(-1, cpl_table_get_int(table, "FloatToInt", 6, &null), - "Check element 7 of casted column... "); - cpl_test_zero(null); - test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 7, &null), - "Check element 8 of casted column... "); - cpl_test_zero(null); - test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 8, &null), - "Check element 9 of casted column... "); - cpl_test_zero(null); - test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 9, &null), - "Check element 10 of casted column... "); - cpl_test_zero(null); - test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 10, &null), - "Check element 11 of casted column... "); - cpl_test_zero(null); - test_ivalue(0, cpl_table_is_valid(table, "FloatToInt", 11), - "Check element 12 of casted column... "); - test_ivalue(3, cpl_table_get_int(table, "FloatToInt", 12, &null), - "Check element 13 of casted column... "); - cpl_test_zero(null); - test_ivalue(7, cpl_table_get_int(table, "FloatToInt", 13, &null), - "Check element 14 of casted column... "); - cpl_test_zero(null); - test_ivalue(1, cpl_table_get_int(table, "FloatToInt", 14, &null), - "Check element 15 of casted column... "); - cpl_test_zero(null); - test_ivalue(4, cpl_table_get_int(table, "FloatToInt", 15, &null), - "Check element 16 of casted column... "); - cpl_test_zero(null); - test_ivalue(6, cpl_table_get_int(table, "FloatToInt", 16, &null), - "Check element 17 of casted column... "); - cpl_test_zero(null); - test_ivalue(0, cpl_table_is_valid(table, "FloatToInt", 17), - "Check element 18 of casted column... "); - test_ivalue(0, cpl_table_is_valid(table, "FloatToInt", 18), - "Check element 19 of casted column... "); - test_ivalue(0, cpl_table_is_valid(table, "FloatToInt", 19), - "Check element 20 of casted column... "); - test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 20, &null), - "Check element 21 of casted column... "); - cpl_test_zero(null); - test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 21, &null), - "Check element 22 of casted column... "); - cpl_test_zero(null); - - test(cpl_table_erase_column(table, "FloatToInt"), - "Delete casted column... "); - - test(cpl_table_cast_column(table, "Integer", "IntToFloat", CPL_TYPE_FLOAT), - "Casting integer column to float colum... "); - -/**- FIXME: RESTORE!!! */ - error = cpl_table_fill_invalid_int(table, "Integer", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_int(table, "AInt", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_int(table, "New AInt", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_save(table, NULL, NULL, BASE "19.fits", CPL_IO_CREATE); - cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_fits(BASE "19.fits"); - cpl_table_delete(table); - table = cpl_table_load(BASE "19.fits", 1, 1); -/**/ - - test_fvalue(999.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 0, &null), - "Check element 1 of casted column (2)... "); - cpl_test_zero(null); - test_fvalue(999.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 1, &null), - "Check element 2 of casted column (2)... "); - cpl_test_zero(null); - test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 2), - "Check element 3 of casted column (2)... "); - test_fvalue(999.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 3, &null), - "Check element 4 of casted column (2)... "); - cpl_test_zero(null); - test_fvalue(999.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 4, &null), - "Check element 5 of casted column (2)... "); - cpl_test_zero(null); - test_fvalue(999.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 5, &null), - "Check element 6 of casted column (2)... "); - cpl_test_zero(null); - test_fvalue(-1.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 6, &null), - "Check element 7 of casted column (2)... "); - cpl_test_zero(null); - test_fvalue(999.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 7, &null), - "Check element 8 of casted column (2)... "); - cpl_test_zero(null); - test_fvalue(999.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 8, &null), - "Check element 9 of casted column (2)... "); - cpl_test_zero(null); - test_fvalue(999.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 9, &null), - "Check element 10 of casted column (2)... "); - cpl_test_zero(null); - test_fvalue(999.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 10, &null), - "Check element 11 of casted column (2)... "); - cpl_test_zero(null); - test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 11), - "Check element 12 of casted column (2)... "); - test_fvalue(3.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 12, &null), - "Check element 13 of casted column (2)... "); - cpl_test_zero(null); - test_fvalue(7.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 13, &null), - "Check element 14 of casted column (2)... "); - cpl_test_zero(null); - test_fvalue(1.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 14, &null), - "Check element 15 of casted column (2)... "); - cpl_test_zero(null); - test_fvalue(4.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 15, &null), - "Check element 16 of casted column (2)... "); - cpl_test_zero(null); - test_fvalue(6.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 16, &null), - "Check element 17 of casted column (2)... "); - cpl_test_zero(null); - test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 17), - "Check element 18 of casted column (2)... "); - test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 18), - "Check element 19 of casted column (2)... "); - test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 19), - "Check element 20 of casted column (2)... "); - test_fvalue(999.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 20, &null), - "Check element 21 of casted column (2)... "); - cpl_test_zero(null); - test_fvalue(999.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 21, &null), - "Check element 22 of casted column (2)... "); - cpl_test_zero(null); - - test(cpl_table_shift_column(table, "IntToFloat", 1), - "Shift new column one position down... "); - - test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 0), - "Check element 1 of shifted column... "); - test_fvalue(999.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 1, &null), - "Check element 2 of shifted column... "); - cpl_test_zero(null); - test_fvalue(999.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 2, &null), - "Check element 3 of shifted column... "); - cpl_test_zero(null); - test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 3), - "Check element 4 of shifted column... "); - test_fvalue(999.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 4, &null), - "Check element 5 of shifted column... "); - cpl_test_zero(null); - test_fvalue(999.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 5, &null), - "Check element 6 of shifted column... "); - cpl_test_zero(null); - test_fvalue(999.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 6, &null), - "Check element 7 of shifted column... "); - cpl_test_zero(null); - test_fvalue(-1.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 7, &null), - "Check element 8 of shifted column... "); - cpl_test_zero(null); - test_fvalue(999.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 8, &null), - "Check element 9 of shifted column... "); - cpl_test_zero(null); - test_fvalue(999.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 9, &null), - "Check element 10 of shifted column... "); - cpl_test_zero(null); - test_fvalue(999.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 10, &null), - "Check element 11 of shifted column... "); - cpl_test_zero(null); - test_fvalue(999.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 11, &null), - "Check element 12 of shifted column... "); - cpl_test_zero(null); - test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 12), - "Check element 13 of shifted column... "); - test_fvalue(3.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 13, &null), - "Check element 14 of shifted column... "); - cpl_test_zero(null); - test_fvalue(7.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 14, &null), - "Check element 15 of shifted column... "); - cpl_test_zero(null); - test_fvalue(1.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 15, &null), - "Check element 16 of shifted column... "); - cpl_test_zero(null); - test_fvalue(4.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 16, &null), - "Check element 17 of shifted column... "); - cpl_test_zero(null); - test_fvalue(6.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 17, &null), - "Check element 18 of shifted column... "); - cpl_test_zero(null); - test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 18), - "Check element 19 of shifted column... "); - test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 19), - "Check element 20 of shifted column... "); - test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 20), - "Check element 21 of shifted column... "); - test_fvalue(999.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 21, &null), - "Check element 22 of shifted column... "); - cpl_test_zero(null); - - test(cpl_table_add_columns(table, "Integer", "IntToFloat"), - "Sum \"IntToFloat\" to \"Integer\"... "); - -/**- FIXME: RESTORE!!! */ - error = cpl_table_fill_invalid_int(table, "Integer", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_int(table, "AInt", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_int(table, "New AInt", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_save(table, NULL, NULL, BASE "20.fits", CPL_IO_CREATE); - cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_fits(BASE "20.fits"); - cpl_table_delete(table); - table = cpl_table_load(BASE "20.fits", 1, 1); -/**/ - - cpl_table_test_20(table); - - test(cpl_table_name_column(table, "IntToFloat", "Float"), - "Renaming \"IntToFloat\" to \"Float\"... "); - - test(cpl_table_set_column_invalid(table, "Integer", 7, 2), - "Set NULLs in \"Integer\" column... "); - - test(cpl_table_set_invalid(table, "Float", 7), - "Set NULL in \"Float\" column... "); - - test(cpl_table_set_invalid(table, "Float", 9), - "Set another NULL in \"Float\" column... "); - - test(cpl_table_set_invalid(table, "Double", 7), - "Set NULL in \"Double\" column... "); - - test(cpl_table_set_invalid(table, "String", 7), - "Set NULL in \"String\" column... "); - - test(cpl_table_new_column(table, "Sequence", CPL_TYPE_INT), - "Creating the \"Sequence\" column... "); - - for (i = 0; i < 18; i++) { - sprintf(message, "Writing to row %d of the \"Sequence\" column... ", i); - test(cpl_table_set_int(table, "Sequence", i, i), message); - } - - names[0] = "Integer"; - - reflist = cpl_propertylist_new(); - cpl_propertylist_append_bool(reflist, names[0], 0); -/* %$% */ -/* *+ -error = cpl_table_set_column_unit(table, "Integer", "Pixel"); -cpl_test_eq_error(error, CPL_ERROR_NONE); -cpl_table_dump_structure(table, NULL); -cpl_table_dump(table, 0, cpl_table_get_nrow(table), NULL); -exit; -+* */ - - { - int *hold = cpl_table_get_data_int(table, "Integer"); - - test(cpl_table_sort(table, reflist), - "Sorting by increasing values of the \"Integer\" column... "); - - test_pvalue(hold, cpl_table_get_data_int(table, "Integer"), - "Check pointer... "); - - cpl_propertylist_delete(reflist); - - error = cpl_table_set_column_unit(table, "AInt", "Pixel"); + /**+ FIXME: RESTORE!!! */ + error = cpl_table_fill_invalid_int(table, "Integer", 320); cpl_test_eq_error(error, CPL_ERROR_NONE); - - test_svalue("Pixel", cpl_table_get_column_unit(table, "AInt"), - "Check column unit... "); - } + error = cpl_table_fill_invalid_int(table, "AInt", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_long_long(table, "LongLong", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_long_long(table, "ALongLong", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_save(table, NULL, NULL, BASE "10.fits", CPL_IO_CREATE); + cpl_test_eq_error(error, CPL_ERROR_NONE); + cpl_test_fits(BASE "10.fits"); + cpl_table_delete(table); + table = cpl_table_load(BASE "10.fits", 1, 1); + cpl_test_nonnull(table); + cpl_test_eq(cpl_table_get_nrow(table), 25); + /**/ -/* - if (strcmp(unit = (char *)cpl_table_get_column_unit(table, "AInt"), - "Pixel")) { - printf("Check column unit... "); - printf("Expected \"Pixel\", obtained \"%s\"\n", unit); - cpl_end(); - return 1; - } -*/ - -/**- FIXME: RESTORE!!! */ - error = cpl_table_fill_invalid_int(table, "Integer", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_int(table, "AInt", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_int(table, "New AInt", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_save(table, NULL, NULL, BASE "21.fits", CPL_IO_CREATE); - cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_fits(BASE "21.fits"); - cpl_table_delete(table); - table = cpl_table_load(BASE "21.fits", 1, 1); -/**/ - - cpl_table_test_21(table); - - cpl_table_delete(table); - table = cpl_table_load(BASE "22.fits", 1, 1); -/**/ - - cpl_table_test_22(table); - - /* - * Here partial loading of table is tested - */ - - error = cpl_table_fill_invalid_int(table, "Integer", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_int(table, "AInt", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_int(table, "New AInt", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_save(table, NULL, NULL, BASE "24.fits", CPL_IO_CREATE); - cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_fits(BASE "24.fits"); - cpl_table_delete(table); - colnames = cpl_array_new(7, CPL_TYPE_STRING); - cpl_array_set_string(colnames, 0, "Integer"); - cpl_array_set_string(colnames, 1, "Double"); - cpl_array_set_string(colnames, 2, "String"); - cpl_array_set_string(colnames, 3, "AInt"); - cpl_array_set_string(colnames, 4, "AFloat"); - cpl_array_set_string(colnames, 5, "ADouble"); - cpl_array_set_string(colnames, 6, "Float"); - table = cpl_table_load_window(BASE "24.fits", 1, 1, colnames, 7, 6); - cpl_array_delete(colnames); - - /* Test some values here... */ - - error = cpl_table_fill_invalid_int(table, "Integer", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_int(table, "AInt", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_save(table, NULL, NULL, BASE "25.fits", CPL_IO_CREATE); - cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_fits(BASE "25.fits"); + test_ivalue(0, cpl_table_count_invalid(table, "Float"), "Count NULLs... "); - cpl_table_delete(table); - cpl_free(fArray); -#ifdef _Complex_I - cpl_free(cfArray); -#endif + for (i = 0; i < 25; i++) { + const float fval = cpl_table_get_float(table, "Float", i, &null); - return 0; + cpl_test_zero(null); + if (!null) { + test_fvalue(fcheck[i], 0.00001, fval, "Check Float column... "); + } + } -} + /* %%% */ -/*----------------------------------------------------------------------------*/ -/** - @internal - @brief Test the another part of the CPL table functions - @return Zero iff successful - */ -/*----------------------------------------------------------------------------*/ -static int cpl_table_test_rest(void) -{ + test(cpl_table_set_invalid(table, "CFloat", 0), "Set CFloat 0 to NULL... "); + test(cpl_table_set_invalid(table, "CFloat", 5), "Set CFloat 5 to NULL... "); + test(cpl_table_set_invalid(table, "CFloat", 24), + "Set CFloat 24 to NULL... "); - int nrows = NROWS; - int i, j, k, null; - int pp; - char message[80]; - - const char *unit; - - cpl_table *table; - cpl_table *copia; - cpl_array *array; - cpl_array *dimensions; - cpl_array **arrays; - - FILE *stream; - - cpl_error_code error; - - stream = cpl_msg_get_level() > CPL_MSG_INFO - ? fopen("/dev/null", "a") : stdout; - - cpl_test_nonnull( stream ); - - - /* - * Powers - */ - - nrows = 7; - - table = cpl_table_new(nrows); - error = cpl_table_new_column(table, "Int", CPL_TYPE_INT); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_new_column(table, "Float", CPL_TYPE_FLOAT); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_new_column(table, "Double", CPL_TYPE_DOUBLE); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_new_column(table, "CFloat", CPL_TYPE_FLOAT_COMPLEX); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_new_column(table, "CDouble", CPL_TYPE_DOUBLE_COMPLEX); - cpl_test_eq_error(error, CPL_ERROR_NONE); - - for (i = 0; i < nrows; i++) { - error = cpl_table_set_int(table, "Int", i, i); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_set_float(table, "Float", i, i); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_set_double(table, "Double", i, i); - cpl_test_eq_error(error, CPL_ERROR_NONE); -#ifdef _Complex_I - error = cpl_table_set_float_complex(table, "CFloat", i, i + i * I); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_set_double_complex(table, "CDouble", i, i + I); - cpl_test_eq_error(error, CPL_ERROR_NONE); -#endif - } - - error = cpl_table_exponential_column(table, "Int", 2); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_exponential_column(table, "Float", 2); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_exponential_column(table, "Double", 2); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_exponential_column(table, "CFloat", 2); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_exponential_column(table, "CDouble", 2); - cpl_test_eq_error(error, CPL_ERROR_NONE); + /**+ FIXME: RESTORE!!! */ + error = cpl_table_fill_invalid_int(table, "Integer", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_int(table, "AInt", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_long_long(table, "LongLong", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_long_long(table, "ALongLong", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_save(table, NULL, NULL, BASE "9a.fits", CPL_IO_CREATE); + cpl_test_eq_error(error, CPL_ERROR_NONE); + cpl_test_fits(BASE "9a.fits"); + cpl_table_delete(table); + table = cpl_table_load(BASE "9a.fits", 1, 1); + cpl_test_nonnull(table); + cpl_test_eq(cpl_table_get_nrow(table), 25); + /**/ - pp = 1; - for (i = 0; i < nrows; i++) { #ifdef _Complex_I - const double ln2 = CPL_MATH_LN2; + test_ivalue(3, cpl_table_count_invalid(table, "CFloat"), + "Count written CFloat NULLs... "); - test_cvalue(exp(i*ln2)*(cos(i*ln2) + I*sin(i*ln2)), 0.00001, - cpl_table_get_float_complex(table, "CFloat", i, &null), - "Check expo CFloat... "); - cpl_test_zero(null); - - test_cvalue(exp(i*ln2)*(cos(ln2) + I*sin(ln2)), 0.00001, - cpl_table_get_double_complex(table, "CDouble", i, &null), - "Check expo CDouble... "); - cpl_test_zero(null); -#endif - - test_ivalue(pp, cpl_table_get_int(table, - "Int", i, &null), "Check expo Int... "); - cpl_test_zero(null); - test_fvalue((float)pp, 0.00001, cpl_table_get_float(table, - "Float", i, &null), "Check expo Float... "); - cpl_test_zero(null); - test_fvalue((float)pp, 0.00001, cpl_table_get_double(table, - "Double", i, &null), "Check expo Double... "); - cpl_test_zero(null); - pp *= 2; - - } - - error = cpl_table_logarithm_column(table, "Int", 2); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_logarithm_column(table, "Float", 2); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_logarithm_column(table, "Double", 2); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_logarithm_column(table, "CFloat", 2); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_logarithm_column(table, "CDouble", 2); - cpl_test_eq_error(error, CPL_ERROR_NONE); + for (i = 0; i < 25; i++) { + const float complex fval = + cpl_table_get_float_complex(table, "CFloat", i, &null); + + if (!null) { + test_cvalue(cfcheck[i], 0.0, fval, "Check CFloat column... "); + } + else { + cpl_test(i == 0 || i == 5 || i == 24); + } + } - for (i = 0; i < nrows; i++) { -#ifdef _Complex_I - const double ln2 = CPL_MATH_LN2; + test(cpl_table_set_float_complex(table, "CFloat", 0, -1.1 + 4.1 * I), + "Set CFloat 0 to -1.1 + i4.1... "); + test(cpl_table_set_float_complex(table, "CFloat", 5, 5.1), + "Set CFloat 5 to 5.1... "); + test(cpl_table_set_float_complex(table, "CFloat", 24, -1.1 + 4.1 * I), + "Set CFloat 24 to -1.1 + i4.1... "); +#endif - test_cvalue(clog(exp(i*ln2)*(cos(i*ln2) + I*sin(i*ln2)))/ln2, 0.00001, - cpl_table_get_float_complex(table, - "CFloat", i, &null), "Check log CFloat... "); - cpl_test_zero(null); - test_cvalue(clog(exp(i*ln2)*(cos(ln2) + I*sin(ln2)))/ln2, 0.00001, - cpl_table_get_double_complex(table, - "CDouble", i, &null), "Check log CDouble... "); - cpl_test_zero(null); -#endif - test_ivalue(i, cpl_table_get_int(table, - "Int", i, &null), "Check log Int... "); - cpl_test_zero(null); - test_fvalue((float)i, 0.00001, cpl_table_get_float(table, - "Float", i, &null), "Check log Float... "); - cpl_test_zero(null); - test_fvalue((float)i, 0.00001, cpl_table_get_double(table, - "Double", i, &null), "Check log Double... "); - cpl_test_zero(null); - } + /**+ FIXME: RESTORE!!! */ + error = cpl_table_fill_invalid_int(table, "Integer", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_int(table, "AInt", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_long_long(table, "LongLong", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_long_long(table, "ALongLong", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_save(table, NULL, NULL, BASE "10.fits", CPL_IO_CREATE); + cpl_test_eq_error(error, CPL_ERROR_NONE); + cpl_test_fits(BASE "10.fits"); + cpl_table_delete(table); + table = cpl_table_load(BASE "10.fits", 1, 1); + cpl_test_nonnull(table); + cpl_test_eq(cpl_table_get_nrow(table), 25); + /**/ #ifdef _Complex_I - for (i = 0; i < nrows; i++) { - error = cpl_table_set_float_complex(table, "CFloat", i, i + i * I); - cpl_test_eq_error(error, CPL_ERROR_NONE); - test_cvalue(i + i*I, 0.0, cpl_table_get_float_complex(table, - "CFloat", i, &null), " "); - cpl_test_zero(null); - error = cpl_table_set_double_complex(table, "CDouble", i, i + I); - cpl_test_eq_error(error, CPL_ERROR_NONE); - test_cvalue(i + I, 0.0, cpl_table_get_double_complex(table, - "CDouble", i, &null), " "); - cpl_test_zero(null); - } -#endif - - cpl_test_zero(cpl_table_count_invalid(table, "CFloat")); - cpl_test_zero(cpl_table_count_invalid(table, "CDouble")); - - error = cpl_table_power_column(table, "Int", 2.0); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_power_column(table, "Float", 2.0); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_power_column(table, "Double", 2.0); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_power_column(table, "CFloat", 2.0); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_power_column(table, "CDouble", 2.0); - cpl_test_eq_error(error, CPL_ERROR_NONE); - - cpl_test_zero(cpl_table_count_invalid(table, "CFloat")); - cpl_test_zero(cpl_table_count_invalid(table, "CDouble")); - - for (i = 0; i < nrows; i++) { - test_ivalue(i*i, cpl_table_get_int(table, - "Int", i, &null), "Check pow Int... "); - cpl_test_zero(null); - test_fvalue((float)i*i, 0.00001, cpl_table_get_float(table, - "Float", i, &null), "Check pow Float... "); - cpl_test_zero(null); - test_fvalue((float)i*i, 0.00001, cpl_table_get_double(table, - "Double", i, &null), "Check pow Double... "); - cpl_test_zero(null); -#ifdef _Complex_I - test_cvalue(2*I*i*i, 0.00001, cpl_table_get_float_complex(table, - "CFloat", i, &null), "Check pow CFloat... "); - cpl_test_zero(null); - test_cvalue(i*i - 1 + 2*i*I, 0.00001, cpl_table_get_double_complex(table, - "CDouble", i, &null), "Check pow CDouble... "); - cpl_test_zero(null); -#endif - } + test_ivalue(0, cpl_table_count_invalid(table, "CFloat"), "Count NULLs... "); -#ifdef _Complex_I - /* On a ppc-Mac with gcc 4.0 cpowf(0.0, 2.0) returns NaN */ - /* FIXME: For a proper unit test the table should be re-set for each test */ - error = cpl_table_set_float_complex(table, "CFloat", 0, 0.0); - cpl_test_eq_error(error, CPL_ERROR_NONE); -#endif - - error = cpl_table_power_column(table, "Int", 0.5); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_power_column(table, "Float", 0.5); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_power_column(table, "Double", 0.5); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_power_column(table, "CFloat", 0.5); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_power_column(table, "CDouble", 0.5); - cpl_test_eq_error(error, CPL_ERROR_NONE); - - - for (i = 0; i < nrows; i++) { - test_ivalue(i, cpl_table_get_int(table, - "Int", i, &null), "Check sqrt Int... "); - cpl_test_zero(null); - test_fvalue((float)i, 0.00001, cpl_table_get_float(table, - "Float", i, &null), "Check sqrt Float... "); - cpl_test_zero(null); - test_fvalue((float)i, 0.00001, cpl_table_get_double(table, - "Double", i, &null), "Check sqrt Double... "); - cpl_test_zero(null); -#ifdef _Complex_I - test_cvalue(i + i*I, 0.00001, cpl_table_get_float_complex(table, - "CFloat", i, &null), "Check sqrt CFloat... "); - cpl_test_zero(null); - test_cvalue(i + I, 0.00001, cpl_table_get_double_complex(table, - "CDouble", i, &null), "Check sqrt CDouble... "); - cpl_test_zero(null); + for (i = 0; i < 25; i++) { + const float complex fval = + cpl_table_get_float_complex(table, "CFloat", i, &null); + + cpl_test_zero(null); + if (!null) { + test_cvalue(cfcheck[i], 0.00001, fval, "Check CFloat column... "); + } + } #endif - } -#ifdef _Complex_I - /* On a ppc-Mac with gcc 4.0 cpowf(0.0, 0.5) returns NaN */ - /* FIXME: For a proper unit test the table should be re-set for each test */ - error = cpl_table_set_float_complex(table, "CFloat", 0, 0.0); - cpl_test_eq_error(error, CPL_ERROR_NONE); -#endif - - error = cpl_table_power_column(table, "Int", -1.0); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_power_column(table, "Float", -1.0); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_power_column(table, "Double", -1.0); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_power_column(table, "CFloat", -1.0); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_power_column(table, "CDouble", -1.0); - cpl_test_eq_error(error, CPL_ERROR_NONE); - - /* Zero valued elements are rejected */ - cpl_test_zero(cpl_table_is_valid(table, "Int", 0)); - cpl_test_zero(cpl_table_is_valid(table, "Float", 0)); - cpl_test_zero(cpl_table_is_valid(table, "Double", 0)); - cpl_test_zero(cpl_table_is_valid(table, "CFloat", 0)); - - cpl_test_eq(cpl_table_count_invalid(table, "Int"), 1); - cpl_test_eq(cpl_table_count_invalid(table, "Float"), 1); - cpl_test_eq(cpl_table_count_invalid(table, "Double"), 1); - cpl_test_eq(cpl_table_count_invalid(table, "CFloat"), 1); - - for (i = 1; i < nrows; i++) { - test_ivalue(i == 1 || i == 2 ? 1.0 : 0.0, cpl_table_get_int(table, - "Int", i, &null), "Check pow(-1) Int... "); - cpl_test_zero(null); - test_fvalue(1.0/(double)i, 0.00001, cpl_table_get_float(table, - "Float", i, &null), "Check pow(-1) Float... "); - cpl_test_zero(null); - test_fvalue(1.0/(double)i, 0.00001, cpl_table_get_double(table, - "Double", i, &null), "Check pow(-1) Double... "); - cpl_test_zero(null); -#ifdef _Complex_I - test_cvalue(1.0/((double)i + (double)i*I), 0.00001, - cpl_table_get_float_complex(table, - "CFloat", i, &null), "Check pow(-1) CFloat... "); - cpl_test_zero(null); - test_cvalue(1.0/((double)i + I), 0.00001, - cpl_table_get_double_complex(table, - "CDouble", i, &null), "Check pow(-1) CDouble... "); - cpl_test_zero(null); -#endif - } - - - /* Set the values back */ - for (i = 0; i < nrows; i++) { - error = cpl_table_set_int(table, "Int", i, i); - cpl_test_eq_error(error, CPL_ERROR_NONE); - } - error = cpl_table_power_column(table, "Float", -1.0); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_power_column(table, "Double", -1.0); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_power_column(table, "CFloat", -1.0); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_power_column(table, "CDouble", -1.0); - cpl_test_eq_error(error, CPL_ERROR_NONE); - - error = cpl_table_set_float(table, "Float", 0, 0.0); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_set_double(table, "Double", 0, 0.0); - cpl_test_eq_error(error, CPL_ERROR_NONE); -#ifdef _Complex_I - error = cpl_table_set_float_complex(table, "CFloat", 0, 0.0); - cpl_test_eq_error(error, CPL_ERROR_NONE); -#endif + /* %%% */ - cpl_test_zero(cpl_table_has_invalid(table, "Int")); - cpl_test_zero(cpl_table_has_invalid(table, "Float")); - cpl_test_zero(cpl_table_has_invalid(table, "Double")); - cpl_test_zero(cpl_table_has_invalid(table, "CFloat")); - cpl_test_zero(cpl_table_has_invalid(table, "CDouble")); - - /* - * Test cpl_table_abs_column() - */ - - error = cpl_table_set_int(table, "Int", 2, -2); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_set_float(table, "Float", 2, -2); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_set_double(table, "Double", 2, -2); - cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_table_abs_column(table, "Int"); - cpl_table_abs_column(table, "Float"); - cpl_table_abs_column(table, "Double"); - cpl_table_abs_column(table, "CFloat"); - cpl_table_abs_column(table, "CDouble"); - - for (i = 0; i < nrows; i++) { - double s2 = sqrt(2.0); - - test_ivalue(i, cpl_table_get_int(table, - "Int", i, &null), "Check abs Int... "); - cpl_test_zero(null); - test_fvalue((float)i, 0.00001, cpl_table_get_float(table, - "Float", i, &null), "Check abs Float... "); - cpl_test_zero(null); - test_fvalue((float)i, 0.00001, cpl_table_get_double(table, - "Double", i, &null), "Check abs Double... "); - cpl_test_zero(null); - test_fvalue(i*s2, 0.00001, cpl_table_get_float(table, - "CFloat", i, &null), "Check abs CFloat... "); - cpl_test_zero(null); - test_fvalue(sqrt(i*i + 1), 0.00001, cpl_table_get_double(table, - "CDouble", i, &null), "Check abs CDouble... "); - cpl_test_zero(null); - } - - cpl_table_delete(table); - - - /* - * Testing the selection functions - */ - - nrows = 7; - - table = cpl_table_new(nrows); - cpl_table_new_column(table, "Int", CPL_TYPE_INT); - cpl_table_new_column(table, "String", CPL_TYPE_STRING); + test(cpl_table_set_column_invalid(table, "Integer", 0, 3), + "Set Integer 0-2 to NULL... "); + test(cpl_table_set_column_invalid(table, "Integer", 5, 3), + "Set Integer 5-7 to NULL... "); + test(cpl_table_set_column_invalid(table, "Integer", 20, 20), + "Set Integer 20 till end to NULL... "); + + test(cpl_table_set_column_invalid(table, "AInt", 0, 3), + "Set AInt 0-2 to NULL... "); + test(cpl_table_set_column_invalid(table, "AInt", 5, 3), + "Set AInt 5-7 to NULL... "); + test(cpl_table_set_column_invalid(table, "AInt", 20, 20), + "Set AInt 20 till end to NULL... "); + + /********/ + + array = (cpl_array *)cpl_table_get_array(table, "AInt", 3); + test_ivalue(0, cpl_array_get_int(array, 0, &null), + "Read array element 0..."); + test_ivalue(0, null, "Check array element 0 is valid..."); + test_ivalue(5, cpl_array_get_int(array, 5, &null), + "Read array element 5..."); + test_ivalue(0, null, "Check array element 5 is valid..."); + test_ivalue(19, cpl_array_get_int(array, 19, &null), + "Read array element 19..."); + test_ivalue(0, null, "Check array element 19 is valid..."); + + cpl_array_set_invalid(array, 0); + cpl_array_set_invalid(array, 5); + cpl_array_set_invalid(array, 19); + + test_ivalue(0, cpl_array_get_int(array, 0, &null), + "Read again array element 0..."); + test_ivalue(1, null, "Check array element 0 is invalid..."); + test_ivalue(0, cpl_array_get_int(array, 5, &null), + "Read again array element 5..."); + test_ivalue(1, null, "Check array element 5 is invalid..."); + test_ivalue(0, cpl_array_get_int(array, 19, &null), + "Read again array element 19..."); + test_ivalue(1, null, "Check array element 19 is invalid..."); + + + test(cpl_table_set_column_invalid(table, "LongLong", 0, 3), + "Set LongLong 0-2 to NULL... "); + test(cpl_table_set_column_invalid(table, "LongLong", 5, 3), + "Set LongLong 5-7 to NULL... "); + test(cpl_table_set_column_invalid(table, "LongLong", 20, 20), + "Set LongLong 20 till end to NULL... "); + + test(cpl_table_set_column_invalid(table, "ALongLong", 0, 3), + "Set ALongLong 0-2 to NULL... "); + test(cpl_table_set_column_invalid(table, "ALongLong", 5, 3), + "Set ALongLong 5-7 to NULL... "); + test(cpl_table_set_column_invalid(table, "ALongLong", 20, 20), + "Set ALongLong 20 till end to NULL... "); + + array = (cpl_array *)cpl_table_get_array(table, "ALongLong", 3); + test_ivalue(0, cpl_array_get_long_long(array, 0, &null), + "Read array element 0..."); + test_ivalue(0, null, "Check array element 0 is valid..."); + test_ivalue(5, cpl_array_get_long_long(array, 5, &null), + "Read array element 5..."); + test_ivalue(0, null, "Check array element 5 is valid..."); + test_ivalue(19, cpl_array_get_long_long(array, 19, &null), + "Read array element 19..."); + test_ivalue(0, null, "Check array element 19 is valid..."); + + cpl_array_set_invalid(array, 0); + cpl_array_set_invalid(array, 5); + cpl_array_set_invalid(array, 19); + + test_ivalue(0, cpl_array_get_long_long(array, 0, &null), + "Read again array element 0..."); + test_ivalue(1, null, "Check array element 0 is invalid..."); + test_ivalue(0, cpl_array_get_long_long(array, 5, &null), + "Read again array element 5..."); + test_ivalue(1, null, "Check array element 5 is invalid..."); + test_ivalue(0, cpl_array_get_long_long(array, 19, &null), + "Read again array element 19..."); + test_ivalue(1, null, "Check array element 19 is invalid..."); - unit = "abcd\0efgh\0ijkl\0mnop\0qrst\0uvwx\0yz"; + /**+ FIXME: RESTORE!!! */ + error = cpl_table_fill_invalid_int(table, "Integer", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_int(table, "AInt", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_long_long(table, "LongLong", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_long_long(table, "ALongLong", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_save(table, NULL, NULL, BASE "11.fits", CPL_IO_CREATE); + cpl_test_eq_error(error, CPL_ERROR_NONE); + cpl_test_fits(BASE "11.fits"); + cpl_table_delete(table); + table = cpl_table_load(BASE "11.fits", 1, 1); + cpl_test_nonnull(table); + cpl_test_eq(cpl_table_get_nrow(table), 25); + /**/ - for (i = 0; i < nrows; i++) { - error = cpl_table_set_int(table, "Int", i, i); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_set_string(table, "String", i, unit + i*5); - cpl_test_eq_error(error, CPL_ERROR_NONE); - } + test_ivalue(11, cpl_table_count_invalid(table, "Integer"), + "Count Integer NULLs... "); - cpl_table_duplicate_column(table, "Int2", table, "Int"); - cpl_table_multiply_columns(table, "Int2", "Int2"); - cpl_table_cast_column(table, "Int", "Float", CPL_TYPE_FLOAT); + test_ivalue(11, cpl_table_count_invalid(table, "AInt"), + "Count AInt NULLs... "); -#ifdef VERBOSE + for (i = 0; i < 25; i++) { + const int ival = cpl_table_get_int(table, "Integer", i, &null); + if (!null) { + test_ivalue(icheck[i], ival, "Check Integer column... "); + } + else { + cpl_test(i <= 2 || i >= 5); + cpl_test(i <= 7 || i >= 20); + } + } - cpl_msg_info(cpl_func, "This is the test table:\n\n"); - cpl_table_dump(table, 0, cpl_table_get_nrow(table), stream); + test_ivalue(11, cpl_table_count_invalid(table, "LongLong"), + "Count LongLong NULLs... "); - cpl_msg_info(cpl_func, "Now erase all selected:\n\n"); + test_ivalue(11, cpl_table_count_invalid(table, "ALongLong"), + "Count ALongLong NULLs... "); -#endif + for (i = 0; i < 25; i++) { + const long long llval = + cpl_table_get_long_long(table, "LongLong", i, &null); + if (!null) { + test_ivalue(icheck[i], llval, "Check LongLong column... "); + } + else { + cpl_test(i <= 2 || i >= 5); + cpl_test(i <= 7 || i >= 20); + } + } - copia = cpl_table_duplicate(table); - test_ivalue(7, cpl_table_count_selected(copia), "Check all selected... "); - cpl_table_erase_selected(copia); -#ifdef VERBOSE - cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), stream); -#endif - test_ivalue(0, cpl_table_get_nrow(copia), - "Check length erase all selected... "); - cpl_table_delete(copia); + /* + * Test valid and invalid elements of an array of AInt (after loading). + */ -#ifdef VERBOSE + array = (cpl_array *)cpl_table_get_array(table, "AInt", 3); - cpl_msg_info(cpl_func, "This is the test table:\n\n"); - cpl_table_dump(table, 0, cpl_table_get_nrow(table), stream); + test_ivalue(0, cpl_array_get_int(array, 0, &null), + "Load again array element 0..."); + test_ivalue(1, null, "Reloaded array element 0 is invalid..."); + test_ivalue(0, cpl_array_get_int(array, 5, &null), + "Load again array element 5..."); + test_ivalue(1, null, "Reloaded array element 5 is invalid..."); + test_ivalue(0, cpl_array_get_int(array, 19, &null), + "Load again array element 19..."); + test_ivalue(1, null, "Reloaded array element 19 is invalid..."); + + test_ivalue(6, cpl_array_get_int(array, 6, &null), + "Load array element 6..."); + test_ivalue(0, null, "Reloaded array element 6 is valid..."); - cpl_msg_info(cpl_func, "Now delete all Int >= Int2:\n\n"); -#endif + /* + * Test valid and invalid elements of an array of ALongLong (after loading). + */ - copia = cpl_table_duplicate(table); - cpl_table_and_selected(copia, "Int", CPL_NOT_LESS_THAN, "Int2"); - test_ivalue(2, cpl_table_count_selected(copia), - "Check Int >= Int2 selected... "); - array = cpl_table_where_selected(copia); - test_ivalue(CPL_TYPE_SIZE, cpl_array_get_type(array), - "Check type of where array..."); - test_ivalue(2, cpl_array_get_size(array), "Check size of where array..."); - test_ivalue(0, cpl_array_get_cplsize(array, 0, &null), - "Check first element of where array..."); - cpl_test_zero(null); - test_ivalue(1, cpl_array_get_cplsize(array, 1, &null), - "Check second element of where array..."); - cpl_test_zero(null); - cpl_array_delete(array); - cpl_table_erase_selected(copia); -#ifdef VERBOSE - cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), stream); -#endif - test_ivalue(5, cpl_table_get_nrow(copia), - "Check length erase all Int >= Int2... "); - array = cpl_table_where_selected(copia); - test_ivalue(CPL_TYPE_SIZE, cpl_array_get_type(array), - "Check type of everywhere array..."); - test_ivalue(5, cpl_array_get_size(array), - "Check size of everywhere array..."); - test_ivalue(0, cpl_array_get_cplsize(array, 0, &null), - "Check first element of everywhere array..."); - cpl_test_zero(null); - test_ivalue(1, cpl_array_get_cplsize(array, 1, &null), - "Check second element of everywhere array..."); - cpl_test_zero(null); - test_ivalue(2, cpl_array_get_cplsize(array, 2, &null), - "Check third element of everywhere array..."); - cpl_test_zero(null); - test_ivalue(3, cpl_array_get_cplsize(array, 3, &null), - "Check fourth element of everywhere array..."); - cpl_test_zero(null); - test_ivalue(4, cpl_array_get_cplsize(array, 4, &null), - "Check fifth element of everywhere array..."); - cpl_test_zero(null); - cpl_array_delete(array); - - cpl_table_unselect_all(copia); - array = cpl_table_where_selected(copia); - test_ivalue(CPL_TYPE_SIZE, cpl_array_get_type(array), - "Check type of nowhere array..."); - test_ivalue(0, cpl_array_get_size(array), - "Check size of nowhere array..."); - cpl_array_delete(array); + array = (cpl_array *)cpl_table_get_array(table, "ALongLong", 3); - cpl_table_delete(copia); + test_ivalue(0, cpl_array_get_long_long(array, 0, &null), + "Load again array element 0..."); + test_ivalue(1, null, "Reloaded array element 0 is invalid..."); + test_ivalue(0, cpl_array_get_long_long(array, 5, &null), + "Load again array element 5..."); + test_ivalue(1, null, "Reloaded array element 5 is invalid..."); + test_ivalue(0, cpl_array_get_long_long(array, 19, &null), + "Load again array element 19..."); + test_ivalue(1, null, "Reloaded array element 19 is invalid..."); + + test_ivalue(6, cpl_array_get_long_long(array, 6, &null), + "Load array element 6..."); + test_ivalue(0, null, "Reloaded array element 6 is valid..."); + + + /****/ + + test(cpl_table_set_column_invalid(table, "Double", 0, 3), + "Set Double 0-2 to NULL... "); + test(cpl_table_set_column_invalid(table, "Double", 5, 3), + "Set Double 5-7 to NULL... "); + test(cpl_table_set_column_invalid(table, "Double", 20, 20), + "Set Double 20 till end to NULL... "); + + array = (cpl_array *)cpl_table_get_array(table, "ADouble", 3); + test_fvalue(0.0, 0.0001, cpl_array_get_double(array, 0, &null), + "Read double array element 0..."); + test_ivalue(0, null, "Check double array element 0 is valid..."); + test_fvalue(5.0, 0.0001, cpl_array_get_double(array, 5, &null), + "Read double array element 5..."); + test_ivalue(0, null, "Check double array element 5 is valid..."); + test_fvalue(19.0, 0.0001, cpl_array_get_double(array, 19, &null), + "Read double array element 19..."); + test_ivalue(0, null, "Check array element 19 is valid..."); + + cpl_array_set_invalid(array, 0); + cpl_array_set_invalid(array, 5); + cpl_array_set_invalid(array, 19); + + test_fvalue(0.0, 0.0001, cpl_array_get_double(array, 0, &null), + "Read again double array element 0..."); + test_ivalue(1, null, "Check double array element 0 is invalid..."); + test_fvalue(0.0, 0.0001, cpl_array_get_double(array, 5, &null), + "Read again double array element 5..."); + test_ivalue(1, null, "Check double array element 5 is invalid..."); + test_fvalue(0.0, 0.0001, cpl_array_get_double(array, 19, &null), + "Read again double array element 19..."); + test_ivalue(1, null, "Check double array element 19 is invalid..."); -#ifdef VERBOSE - cpl_msg_info(cpl_func, "This is the test table:\n\n"); - cpl_table_dump(table, 0, cpl_table_get_nrow(table), stream); + /**+ FIXME: RESTORE!!! */ + error = cpl_table_fill_invalid_int(table, "Integer", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_int(table, "AInt", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_long_long(table, "LongLong", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_long_long(table, "ALongLong", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_save(table, NULL, NULL, BASE "12.fits", CPL_IO_CREATE); + cpl_test_eq_error(error, CPL_ERROR_NONE); + cpl_test_fits(BASE "12.fits"); + cpl_table_delete(table); + table = cpl_table_load(BASE "12.fits", 1, 1); + cpl_test_nonnull(table); + cpl_test_eq(cpl_table_get_nrow(table), 25); + /**/ - cpl_msg_info(cpl_func, "Now delete all Int > 3:\n\n"); + test_ivalue(11, cpl_table_count_invalid(table, "Double"), + "Re-count written Double NULLs... "); -#endif + for (i = 0; i < 25; i++) { + const double dval = cpl_table_get_double(table, "Double", i, &null); + if (!null) { + test_fvalue(dcheck[i], 0.000001, dval, "Check Double column... "); + } + else { + cpl_test(i <= 2 || i >= 5); + cpl_test(i <= 7 || i >= 20); + } + } - copia = cpl_table_duplicate(table); - cpl_table_and_selected_int(copia, "Int", CPL_GREATER_THAN, 3); - test_ivalue(3, cpl_table_count_selected(copia), - "Check Int > 3 selected... "); - cpl_table_erase_selected(copia); -#ifdef VERBOSE - cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), stream); -#endif - test_ivalue(4, cpl_table_get_nrow(copia), - "Check length erase all Int > 3... "); - cpl_table_delete(copia); + /* + * Check double array after reload + */ -#ifdef VERBOSE + array = (cpl_array *)cpl_table_get_array(table, "ADouble", 3); - cpl_msg_info(cpl_func, "This is the test table:\n\n"); - cpl_table_dump(table, 0, cpl_table_get_nrow(table), stream); + test_fvalue(0.0, 0.0001, cpl_array_get_double(array, 0, &null), + "Read loaded double array element 0..."); + test_ivalue(1, null, "Loaded double array element 0 is invalid..."); + test_fvalue(0.0, 0.0001, cpl_array_get_double(array, 5, &null), + "Read loaded double array element 5..."); + test_ivalue(1, null, "Loaded double array element 5 is invalid..."); + test_fvalue(0.0, 0.0001, cpl_array_get_double(array, 19, &null), + "Read loaded double array element 19..."); + test_ivalue(1, null, "Loaded double array element 19 is invalid..."); + + /****/ + + test(cpl_table_set_column_invalid(table, "Float", 0, 3), + "Set Float 0-2 to NULL... "); + test(cpl_table_set_column_invalid(table, "Float", 5, 3), + "Set Float 5-7 to NULL... "); + test(cpl_table_set_column_invalid(table, "Float", 20, 20), + "Set Float 20 till end to NULL... "); + + array = (cpl_array *)cpl_table_get_array(table, "AFloat", 3); + test_fvalue(0.0, 0.0001, cpl_array_get_float(array, 0, &null), + "Read float array element 0..."); + test_ivalue(0, null, "Check float array element 0 is valid..."); + test_fvalue(5.0, 0.0001, cpl_array_get_float(array, 5, &null), + "Read float array element 5..."); + test_ivalue(0, null, "Check double array element 5 is valid..."); + test_fvalue(19.0, 0.0001, cpl_array_get_float(array, 19, &null), + "Read float array element 19..."); + test_ivalue(0, null, "Check float array element 19 is valid..."); + + cpl_array_set_invalid(array, 0); + cpl_array_set_invalid(array, 5); + cpl_array_set_invalid(array, 19); + + test_fvalue(0.0, 0.0001, cpl_array_get_float(array, 0, &null), + "Read again float array element 0..."); + test_ivalue(1, null, "Check float array element 0 is invalid..."); + test_fvalue(0.0, 0.0001, cpl_array_get_float(array, 5, &null), + "Read again float array element 5..."); + test_ivalue(1, null, "Check float array element 5 is invalid..."); + test_fvalue(0.0, 0.0001, cpl_array_get_float(array, 19, &null), + "Read again float array element 19..."); + test_ivalue(1, null, "Check float array element 19 is invalid..."); - cpl_msg_info(cpl_func, "Now delete all Int2 > Float:\n\n"); + /**+ FIXME: RESTORE!!! */ + error = cpl_table_fill_invalid_int(table, "Integer", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_int(table, "AInt", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_long_long(table, "LongLong", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_long_long(table, "ALongLong", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_save(table, NULL, NULL, BASE "13.fits", CPL_IO_CREATE); + cpl_test_eq_error(error, CPL_ERROR_NONE); + cpl_test_fits(BASE "13.fits"); + cpl_table_delete(table); + table = cpl_table_load(BASE "13.fits", 1, 1); + cpl_test_nonnull(table); + cpl_test_eq(cpl_table_get_nrow(table), 25); + /**/ -#endif + test_ivalue(11, cpl_table_count_invalid(table, "Float"), + "Re-count written Float NULLs... "); - copia = cpl_table_duplicate(table); - cpl_table_and_selected(copia, "Int2", CPL_GREATER_THAN, "Float"); - test_ivalue(5, cpl_table_count_selected(copia), - "Check Int2 > Float selected... "); - cpl_table_erase_selected(copia); -#ifdef VERBOSE - cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), stream); -#endif - test_ivalue(2, cpl_table_get_nrow(copia), - "Check length erase all Int2 > Float... "); - cpl_table_delete(copia); + for (i = 0; i < 25; i++) { + const float fval = cpl_table_get_float(table, "Float", i, &null); + if (!null) { + test_fvalue(fcheck[i], 0.000001, fval, "Check Float column... "); + } + else { + cpl_test(i <= 2 || i >= 5); + cpl_test(i <= 7 || i >= 20); + } + } -#ifdef VERBOSE + /* + * Check float array after reload + */ - cpl_msg_info(cpl_func, "This is the test table:\n\n"); - cpl_table_dump(table, 0, cpl_table_get_nrow(table), stream); + array = (cpl_array *)cpl_table_get_array(table, "AFloat", 3); - cpl_msg_info(cpl_func, "Now delete all String == \"^[a-l].*\":\n\n"); + test_fvalue(0.0, 0.0001, cpl_array_get_float(array, 0, &null), + "Read loaded float array element 0..."); + test_ivalue(1, null, "Loaded float array element 0 is invalid..."); + test_fvalue(0.0, 0.0001, cpl_array_get_float(array, 5, &null), + "Read loaded float array element 5..."); + test_ivalue(1, null, "Loaded float array element 5 is invalid..."); + test_fvalue(0.0, 0.0001, cpl_array_get_float(array, 19, &null), + "Read loaded float array element 19..."); + test_ivalue(1, null, "Loaded float array element 19 is invalid..."); + + /****/ + + test(cpl_table_set_column_invalid(table, "String", 0, 3), + "Set String 0-2 to NULL... "); + test(cpl_table_set_column_invalid(table, "String", 5, 3), + "Set String 5-7 to NULL... "); + test(cpl_table_set_column_invalid(table, "String", 20, 20), + "Set String 20 till end to NULL... "); -#endif + /**+ FIXME: RESTORE!!! */ + error = cpl_table_fill_invalid_int(table, "Integer", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_int(table, "AInt", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_long_long(table, "LongLong", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_long_long(table, "ALongLong", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_save(table, NULL, NULL, BASE "14.fits", CPL_IO_CREATE); + cpl_test_eq_error(error, CPL_ERROR_NONE); + cpl_test_fits(BASE "14.fits"); + cpl_table_delete(table); + table = cpl_table_load(BASE "14.fits", 1, 1); + cpl_test_nonnull(table); + cpl_test_eq(cpl_table_get_nrow(table), 25); + /**/ - copia = cpl_table_duplicate(table); - cpl_table_and_selected_string(copia, "String", CPL_EQUAL_TO, "^[a-l].*"); - test_ivalue(3, cpl_table_count_selected(copia), - "Check String == \"^[a-l].*\" selected... "); - cpl_table_erase_selected(copia); -#ifdef VERBOSE - cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), stream); -#endif - test_ivalue(4, cpl_table_get_nrow(copia), - "Check length erase all String == \"^[a-l].*\"... "); - cpl_table_delete(copia); + test_ivalue(11, cpl_table_count_invalid(table, "String"), + "Re-count written String NULLs... "); -#ifdef VERBOSE + for (i = 0; i < 25; i++) { + const char *sval = cpl_table_get_string(table, "String", i); - cpl_msg_info(cpl_func, "This is the test table:\n\n"); - cpl_table_dump(table, 0, cpl_table_get_nrow(table), stream); + if (sval != NULL) { + test_svalue(scheck[i], sval, "Check String column... "); + } + else { + cpl_test(i <= 2 || i >= 5); + cpl_test(i <= 7 || i >= 20); + } + } - cpl_msg_info(cpl_func, "Now delete all String > \"carlo\":\n\n"); + test(cpl_table_erase_window(table, 21, 4), "Delete last 4 table rows... "); -#endif + test(cpl_table_erase_window(table, 7, 4), + "Delete table rows from 7 to 10... "); - copia = cpl_table_duplicate(table); - cpl_table_and_selected_string(copia, "String", CPL_GREATER_THAN, "carlo"); - test_ivalue(6, cpl_table_count_selected(copia), - "Check String > \"carlo\" selected... "); - cpl_table_erase_selected(copia); -#ifdef VERBOSE - cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), stream); -#endif - test_ivalue(1, cpl_table_get_nrow(copia), - "Check length erase all String > \"carlo\"... "); - cpl_table_delete(copia); + test(cpl_table_erase_window(table, 3, 3), + "Delete table rows from 3 to 5... "); + test(cpl_table_erase_window(table, 0, 2), + "Delete first two table rows... "); + + test_ivalue(12, cpl_table_get_nrow(table), "Check table length (4)... "); + + test_ivalue(3, cpl_table_count_invalid(table, "Integer"), + "Count Integer NULLs... "); + + test_ivalue(3, cpl_table_count_invalid(table, "LongLong"), + "Count LongLong NULLs... "); + + test_ivalue(3, cpl_table_count_invalid(table, "Double"), + "Count Double NULLs... "); + + test_ivalue(3, cpl_table_count_invalid(table, "String"), + "Count String NULLs... "); + + test_ivalue(3, cpl_table_count_invalid(table, "Float"), + "Count Float NULLs... "); + + test_ivalue(3, cpl_table_count_invalid(table, "AInt"), + "Count AInt NULLs... "); + + test_ivalue(0, cpl_table_count_invalid(table, "ADouble"), + "Count ADouble NULLs... "); + + test_ivalue(0, cpl_table_count_invalid(table, "AFloat"), + "Count AFloat NULLs... "); + + test(cpl_table_insert_window(table, 20, 5), + "Append 5 NULLs at table end... "); + + test(cpl_table_insert_window(table, 6, 4), + "Insert segment of 4 NULLs at row 6... "); + + test(cpl_table_insert_window(table, 1, 2), + "Insert segment of 2 NULLs at row 1... "); + + test_ivalue(23, cpl_table_get_nrow(table), "Check table length (5)... "); + + test_ivalue(14, cpl_table_count_invalid(table, "Integer"), + "Count Integer NULLs... "); + + test_ivalue(14, cpl_table_count_invalid(table, "LongLong"), + "Count LongLong NULLs... "); + + test_ivalue(14, cpl_table_count_invalid(table, "Double"), + "Count Double NULLs... "); + + test_ivalue(14, cpl_table_count_invalid(table, "String"), + "Count String NULLs... "); + + test_ivalue(14, cpl_table_count_invalid(table, "Float"), + "Count Float NULLs... "); + + test(cpl_table_fill_column_window_int(table, "Integer", 0, 2, 999), + "Write 999 in \"Integer\" column from 0 to 1... "); + + test(cpl_table_fill_column_window_int(table, "Integer", 3, 3, 999), + "Write 999 in \"Integer\" column from 3 to 5... "); + + test(cpl_table_fill_column_window_int(table, "Integer", 7, 4, 999), + "Write 999 in \"Integer\" column from 7 to 10... "); + + test(cpl_table_fill_column_window_int(table, "Integer", 20, 7, 999), + "Write 999 in \"Integer\" column from 20 to end... "); + + test(cpl_table_fill_column_window_long_long(table, "LongLong", 0, 2, 999), + "Write 999 in \"LongLong\" column from 0 to 1... "); + + test(cpl_table_fill_column_window_long_long(table, "LongLong", 3, 3, 999), + "Write 999 in \"LongLong\" column from 3 to 5... "); + + test(cpl_table_fill_column_window_long_long(table, "LongLong", 7, 4, 999), + "Write 999 in \"LongLong\" column from 7 to 10... "); + + test(cpl_table_fill_column_window_long_long(table, "LongLong", 20, 7, 999), + "Write 999 in \"LongLong\" column from 20 to end... "); + + test(cpl_table_fill_column_window_float(table, "Float", 0, 2, 999.99), + "Write 999.99 in \"Float\" column from 0 to 1... "); + + test(cpl_table_fill_column_window_float(table, "Float", 3, 3, 999.99), + "Write 999.99 in \"Float\" column from 3 to 5... "); + + test(cpl_table_fill_column_window_float(table, "Float", 7, 4, 999.99), + "Write 999.99 in \"Float\" column from 7 to 10... "); + + test(cpl_table_fill_column_window_float(table, "Float", 20, 7, 999.99), + "Write 999.99 in \"Float\" column from 20 to end... "); + + test(cpl_table_fill_column_window_double(table, "Double", 0, 2, 999.88), + "Write 999.88 in \"Double\" column from 0 to 1... "); + + test(cpl_table_fill_column_window_double(table, "Double", 3, 3, 999.88), + "Write 999.88 in \"Double\" column from 3 to 5... "); + + test(cpl_table_fill_column_window_double(table, "Double", 7, 4, 999.88), + "Write 999.88 in \"Double\" column from 7 to 10... "); + + test(cpl_table_fill_column_window_double(table, "Double", 20, 7, 999.88), + "Write 999.88 in \"Double\" column from 20 to end... "); + + test(cpl_table_fill_column_window_string(table, "String", 0, 2, "999"), + "Write \"999\" in \"String\" column from 0 to 1... "); + + test(cpl_table_fill_column_window_string(table, "String", 3, 3, "999"), + "Write \"999\" in \"String\" column from 3 to 5... "); + + test(cpl_table_fill_column_window_string(table, "String", 7, 4, "999"), + "Write \"999\" in \"String\" column from 7 to 10... "); + + test(cpl_table_fill_column_window_string(table, "String", 20, 7, "999"), + "Write \"999\" in \"String\" column from 20 to end... "); + + /**+ FIXME: RESTORE!!! */ + error = cpl_table_fill_invalid_int(table, "Integer", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_int(table, "AInt", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_long_long(table, "LongLong", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_long_long(table, "ALongLong", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_save(table, NULL, NULL, BASE "15.fits", CPL_IO_CREATE); + cpl_test_eq_error(error, CPL_ERROR_NONE); + cpl_test_fits(BASE "15.fits"); + cpl_table_delete(table); + table = cpl_table_load(BASE "15.fits", 1, 1); + /**/ + + test_ivalue(23, cpl_table_get_nrow(table), "Check table length (6)... "); + + test_ivalue(5, cpl_table_count_invalid(table, "Integer"), + "Count Integer NULLs... "); + + test_ivalue(5, cpl_table_count_invalid(table, "LongLong"), + "Count LongLong NULLs... "); + + test_ivalue(5, cpl_table_count_invalid(table, "Float"), + "Count Float NULLs... "); + + test_ivalue(5, cpl_table_count_invalid(table, "Double"), + "Count Double NULLs... "); + + test_ivalue(5, cpl_table_count_invalid(table, "String"), + "Count String NULLs... "); + + test_ivalue(14, cpl_table_count_invalid(table, "AInt"), + "Count AInt NULLs... "); + + test_ivalue(14, cpl_table_count_invalid(table, "ALongLong"), + "Count AInt NULLs... "); + + test_ivalue(11, cpl_table_count_invalid(table, "AFloat"), + "Count AFloat NULLs... "); + + test_ivalue(11, cpl_table_count_invalid(table, "ADouble"), + "Count ADouble NULLs... "); + + test_ivalue(0, cpl_table_is_valid(table, "Integer", 2), + "Check that third element of \"Integer\" is NULL... "); + + test_ivalue(0, cpl_table_is_valid(table, "LongLong", 2), + "Check that third element of \"LongLong\" is NULL... "); + + test_ivalue(1, cpl_table_is_valid(table, "Double", 0), + "Check that first element of \"Double\" is not NULL... "); + + test_ivalue(1, cpl_table_is_valid(table, "String", 0), + "Check that first element of \"String\" is not NULL... "); + + test_ivalue(0, cpl_table_is_valid(table, "String", 2), + "Check that third element of \"String\" is NULL... "); + + test_ivalue(0, cpl_table_is_valid(table, "AInt", 17), + "Check that third element of \"AInt\" is NULL... "); + + test_ivalue(0, cpl_table_is_valid(table, "ALongLong", 17), + "Check that third element of \"ALongLong\" is NULL... "); + + test_ivalue(1, cpl_table_is_valid(table, "ADouble", 17), + "Check that first element of \"ADouble\" is not NULL... "); + + test_ivalue(1, cpl_table_is_valid(table, "AFloat", 17), + "Check that third element of \"AFloat\" is NULL... "); + + test_data(copia, cpl_table_duplicate(table), "Duplicate table... "); + + test(cpl_table_duplicate_column(table, "New Integer", table, "Integer"), + "Duplicate \"Integer\" column within same table... "); + + test(cpl_table_duplicate_column(table, "New LongLong", table, "LongLong"), + "Duplicate \"LongLong\" column within same table... "); + + test(cpl_table_duplicate_column(table, "New Float", table, "Float"), + "Duplicate \"Float\" column within same table... "); + + test(cpl_table_duplicate_column(table, "New Double", table, "Double"), + "Duplicate \"Double\" column within same table... "); + + test(cpl_table_duplicate_column(table, "New String", table, "String"), + "Duplicate \"String\" column within same table... "); + + test(cpl_table_duplicate_column(table, "New AInt", table, "AInt"), + "Duplicate \"AInt\" column within same table... "); + + test(cpl_table_duplicate_column(table, "New ALongLong", table, "ALongLong"), + "Duplicate \"ALongLong\" column within same table... "); + + test(cpl_table_duplicate_column(table, "New AFloat", table, "AFloat"), + "Duplicate \"AFloat\" column within same table... "); + + test(cpl_table_duplicate_column(table, "New ADouble", table, "ADouble"), + "Duplicate \"ADouble\" column within same table... "); + + test_ivalue(5, cpl_table_count_invalid(table, "New Integer"), + "Count New Integer NULLs... "); + + test_ivalue(5, cpl_table_count_invalid(table, "New LongLong"), + "Count New LongLong NULLs... "); + + test_ivalue(5, cpl_table_count_invalid(table, "New Float"), + "Count New Float NULLs... "); + + test_ivalue(5, cpl_table_count_invalid(table, "New Double"), + "Count New Double NULLs... "); + + test_ivalue(5, cpl_table_count_invalid(table, "New String"), + "Count New String NULLs... "); + + test_ivalue(14, cpl_table_count_invalid(table, "New AInt"), + "Count New AInt NULLs... "); + + test_ivalue(14, cpl_table_count_invalid(table, "New ALongLong"), + "Count New ALongLong NULLs... "); + + test_ivalue(11, cpl_table_count_invalid(table, "New AFloat"), + "Count New AFloat NULLs... "); + + test_ivalue(11, cpl_table_count_invalid(table, "New ADouble"), + "Count New ADouble NULLs... "); + + test(cpl_table_move_column(copia, "New Integer", table), + "Moving column \"New Integer\" to another table... "); + + test(cpl_table_move_column(copia, "New LongLong", table), + "Moving column \"New LongLong\" to another table... "); + + test(cpl_table_move_column(copia, "New Float", table), + "Moving column \"New Float\" to another table... "); + + test(cpl_table_move_column(copia, "New Double", table), + "Moving column \"New Double\" to another table... "); + + test(cpl_table_move_column(copia, "New String", table), + "Moving column \"New String\" to another table... "); + + test_failure(CPL_ERROR_ILLEGAL_OUTPUT, + cpl_table_name_column(copia, "New String", "String"), + "Try illegal column renaming... "); + + test(cpl_table_name_column(copia, "New Integer", "Old Integer"), + "Try legal column renaming... "); + + /**+ FIXME: RESTORE!!! */ + error = cpl_table_fill_invalid_int(table, "Integer", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_int(table, "AInt", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_int(table, "New AInt", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_long_long(table, "LongLong", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_long_long(table, "ALongLong", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_long_long(table, "New ALongLong", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_save(table, NULL, NULL, BASE "16.fits", CPL_IO_CREATE); + cpl_test_eq_error(error, CPL_ERROR_NONE); + cpl_test_fits(BASE "16.fits"); + cpl_table_delete(table); + table = cpl_table_load(BASE "16.fits", 1, 1); + /**/ + + test_ivalue(!0, cpl_table_has_column(copia, "Old Integer"), + "Check if column \"Old Integer\" exists... "); + +#ifdef CPL_TABLE_TEST_DEPRECATED + test_svalue("Integer", cpl_table_get_column_name(copia), + "Check name column 1... "); + + test_svalue("LongLong", cpl_table_get_column_name(NULL), + "Check name column 2... "); + + test_svalue("Double", cpl_table_get_column_name(NULL), + "Check name column 3... "); + + test_svalue("CDouble", cpl_table_get_column_name(NULL), + "Check name column 3a... "); + + test_svalue("CDoubleDouble", cpl_table_get_column_name(NULL), + "Check name column 3b... "); + + test_svalue("String", cpl_table_get_column_name(NULL), + "Check name column 4... "); + + test_svalue("Float", cpl_table_get_column_name(NULL), + "Check name column 5... "); + + test_svalue("CFloat", cpl_table_get_column_name(NULL), + "Check name column 5a... "); + + test_svalue("AInt", cpl_table_get_column_name(NULL), + "Check name column 6... "); + + test_svalue("ALongLong", cpl_table_get_column_name(NULL), + "Check name column 7... "); + + test_svalue("AFloat", cpl_table_get_column_name(NULL), + "Check name column 8... "); + + test_svalue("ADouble", cpl_table_get_column_name(NULL), + "Check name column 9... "); + + test_svalue("CAFloat", cpl_table_get_column_name(NULL), + "Check name column 8a... "); + + test_svalue("CADouble", cpl_table_get_column_name(NULL), + "Check name column 9a... "); + + test_svalue("AString", cpl_table_get_column_name(NULL), + "Check name column 10... "); + + test_svalue("Old Integer", cpl_table_get_column_name(NULL), + "Check name column 11... "); + + test_svalue("New LongLong", cpl_table_get_column_name(NULL), + "Check name column 12... "); + + test_svalue("New Float", cpl_table_get_column_name(NULL), + "Check name column 13... "); + + test_svalue("New Double", cpl_table_get_column_name(NULL), + "Check name column 14... "); + + test_svalue("New String", cpl_table_get_column_name(NULL), + "Check name column 15... "); + + test_pvalue(NULL, (void *)cpl_table_get_column_name(NULL), + "Check if no more colums... "); +#endif + + /* + * Test new function cpl_table_get_column_names() + */ + + colnames = cpl_table_get_column_names(copia); + test_ivalue(20, cpl_array_get_size(colnames), "Count table colnames... "); + + test_svalue("Integer", cpl_array_get_string(colnames, 0), + "Check name col 1... "); + + test_svalue("LongLong", cpl_array_get_string(colnames, 1), + "Check name col 2... "); + + test_svalue("Double", cpl_array_get_string(colnames, 2), + "Check name col 3... "); + + test_svalue("CDouble", cpl_array_get_string(colnames, 3), + "Check name col 4... "); + + test_svalue("CDoubleDouble", cpl_array_get_string(colnames, 4), + "Check name column 5... "); + + test_svalue("String", cpl_array_get_string(colnames, 5), + "Check name col 6... "); + + test_svalue("Float", cpl_array_get_string(colnames, 6), + "Check name col 7... "); + + test_svalue("CFloat", cpl_array_get_string(colnames, 7), + "Check name col 8... "); + + test_svalue("AInt", cpl_array_get_string(colnames, 8), + "Check name col 9... "); + + test_svalue("ALongLong", cpl_array_get_string(colnames, 9), + "Check name col 10... "); + + test_svalue("AFloat", cpl_array_get_string(colnames, 10), + "Check name col 11... "); + + test_svalue("ADouble", cpl_array_get_string(colnames, 11), + "Check name col 12... "); + + test_svalue("CAFloat", cpl_array_get_string(colnames, 12), + "Check name col 13... "); + + test_svalue("CADouble", cpl_array_get_string(colnames, 13), + "Check name col 14... "); + + test_svalue("AString", cpl_array_get_string(colnames, 14), + "Check name col 15... "); + + test_svalue("Old Integer", cpl_array_get_string(colnames, 15), + "Check name col 16... "); + + test_svalue("New LongLong", cpl_array_get_string(colnames, 16), + "Check name col 17... "); + + test_svalue("New Float", cpl_array_get_string(colnames, 17), + "Check name col 18... "); + + test_svalue("New Double", cpl_array_get_string(colnames, 18), + "Check name col 19... "); + + test_svalue("New String", cpl_array_get_string(colnames, 19), + "Check name col 20... "); + cpl_array_delete(colnames); + cpl_table_delete(copia); + + + test(cpl_table_set_size(table, 30), "Expanding table to 30 rows... "); + + /* + * The following would do the same as cpl_table_set_size(table, 30), in + * case cpl_table_set_size() would be crossed out... + + test(cpl_table_insert_window(table, 24, 7), "Expanding table to 30 rows... "); + */ + + test_ivalue(12, cpl_table_count_invalid(table, "Integer"), + "Count \"Integer\" NULLs... "); + + test_ivalue(12, cpl_table_count_invalid(table, "String"), + "Count \"String\" NULLs... "); + + test(cpl_table_set_size(table, 22), "Truncating table to 22 rows... "); + + /* + * The following would do the same as cpl_table_set_size(table, 30), in + * case cpl_table_set_size() would be crossed out... + + test(cpl_table_erase_window(table, 22, 1000), + "Truncating table to 22 rows... "); + */ + + /**+ FIXME: RESTORE!!! */ + error = cpl_table_fill_invalid_int(table, "Integer", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_int(table, "AInt", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_int(table, "New AInt", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_long_long(table, "LongLong", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_long_long(table, "ALongLong", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_long_long(table, "New ALongLong", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_save(table, NULL, NULL, BASE "17.fits", CPL_IO_CREATE); + cpl_test_eq_error(error, CPL_ERROR_NONE); + cpl_test_fits(BASE "17.fits"); + cpl_table_delete(table); + table = cpl_table_load(BASE "17.fits", 1, 1); + /**/ + + cpl_table_erase_column(table, "CDouble"); + cpl_table_erase_column(table, "CDoubleDouble"); + cpl_table_erase_column(table, "CFloat"); + cpl_table_erase_column(table, "CAFloat"); + cpl_table_erase_column(table, "CADouble"); + + // FIXME: To be continued. + cpl_table_erase_column(table, "LongLong"); + cpl_table_erase_column(table, "ALongLong"); + cpl_table_erase_column(table, "New ALongLong"); + + // FIXME: Remove the string array column here because for some of + // the following tests it would mess up the expected row/column + // numbers. They need to be fixed before this line is removed! + cpl_table_erase_column(table, "AString"); + + + test_ivalue(5, cpl_table_count_invalid(table, "Integer"), + "Count \"Integer\" NULLs (2)... "); + + test_ivalue(5, cpl_table_count_invalid(table, "String"), + "Count \"String\" NULLs (2)... "); + + test_data(copia, cpl_table_extract(table, 0, 5), + "Creating subtable from rows 0-5 of original... "); + + test_ivalue(1, cpl_table_count_invalid(copia, "Integer"), + "Count \"Integer\" NULLs... "); + + test_ivalue(1, cpl_table_count_invalid(copia, "String"), + "Count \"String\" NULLs... "); + + cpl_table_delete(copia); + + test_data(copia, cpl_table_extract(table, 8, 5), + "Creating subtable from rows 8-5 of original... "); + + test_ivalue(1, cpl_table_count_invalid(copia, "Float"), + "Count \"Float\" NULLs... "); + + test_ivalue(1, cpl_table_count_invalid(copia, "String"), + "Count \"String\" NULLs... "); + + cpl_table_delete(copia); + + test_data(copia, cpl_table_extract(table, 15, 30), + "Creating subtable from rows 15 till end of original... "); + + test_ivalue(3, cpl_table_count_invalid(copia, "Double"), + "Count \"Double\" NULLs... "); + + test_ivalue(3, cpl_table_count_invalid(copia, "String"), + "Count \"String\" NULLs... "); + + cpl_table_delete(copia); + + test(cpl_table_cast_column(table, "Float", "FloatToInt", CPL_TYPE_INT), + "Casting float column to integer colum... "); + + /**+ FIXME: RESTORE!!! */ + error = cpl_table_fill_invalid_int(table, "Integer", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_int(table, "FloatToInt", -2); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_int(table, "AInt", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_int(table, "New AInt", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_save(table, NULL, NULL, BASE "18.fits", CPL_IO_CREATE); + cpl_test_eq_error(error, CPL_ERROR_NONE); + cpl_test_fits(BASE "18.fits"); + cpl_table_delete(table); + table = cpl_table_load(BASE "18.fits", 1, 1); + /**/ + + test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 0, &null), + "Check element 1 of casted column... "); + cpl_test_zero(null); + test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 1, &null), + "Check element 2 of casted column... "); + cpl_test_zero(null); + test_ivalue(0, cpl_table_is_valid(table, "FloatToInt", 2), + "Check element 3 of casted column... "); + test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 3, &null), + "Check element 4 of casted column... "); + cpl_test_zero(null); + test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 4, &null), + "Check element 5 of casted column... "); + cpl_test_zero(null); + test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 5, &null), + "Check element 6 of casted column... "); + cpl_test_zero(null); + test_ivalue(-1, cpl_table_get_int(table, "FloatToInt", 6, &null), + "Check element 7 of casted column... "); + cpl_test_zero(null); + test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 7, &null), + "Check element 8 of casted column... "); + cpl_test_zero(null); + test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 8, &null), + "Check element 9 of casted column... "); + cpl_test_zero(null); + test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 9, &null), + "Check element 10 of casted column... "); + cpl_test_zero(null); + test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 10, &null), + "Check element 11 of casted column... "); + cpl_test_zero(null); + test_ivalue(0, cpl_table_is_valid(table, "FloatToInt", 11), + "Check element 12 of casted column... "); + test_ivalue(3, cpl_table_get_int(table, "FloatToInt", 12, &null), + "Check element 13 of casted column... "); + cpl_test_zero(null); + test_ivalue(7, cpl_table_get_int(table, "FloatToInt", 13, &null), + "Check element 14 of casted column... "); + cpl_test_zero(null); + test_ivalue(1, cpl_table_get_int(table, "FloatToInt", 14, &null), + "Check element 15 of casted column... "); + cpl_test_zero(null); + test_ivalue(4, cpl_table_get_int(table, "FloatToInt", 15, &null), + "Check element 16 of casted column... "); + cpl_test_zero(null); + test_ivalue(6, cpl_table_get_int(table, "FloatToInt", 16, &null), + "Check element 17 of casted column... "); + cpl_test_zero(null); + test_ivalue(0, cpl_table_is_valid(table, "FloatToInt", 17), + "Check element 18 of casted column... "); + test_ivalue(0, cpl_table_is_valid(table, "FloatToInt", 18), + "Check element 19 of casted column... "); + test_ivalue(0, cpl_table_is_valid(table, "FloatToInt", 19), + "Check element 20 of casted column... "); + test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 20, &null), + "Check element 21 of casted column... "); + cpl_test_zero(null); + test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 21, &null), + "Check element 22 of casted column... "); + cpl_test_zero(null); + + test(cpl_table_erase_column(table, "FloatToInt"), + "Delete casted column... "); + + test(cpl_table_cast_column(table, "Integer", "IntToFloat", CPL_TYPE_FLOAT), + "Casting integer column to float colum... "); + + /**- FIXME: RESTORE!!! */ + error = cpl_table_fill_invalid_int(table, "Integer", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_int(table, "AInt", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_int(table, "New AInt", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_save(table, NULL, NULL, BASE "19.fits", CPL_IO_CREATE); + cpl_test_eq_error(error, CPL_ERROR_NONE); + cpl_test_fits(BASE "19.fits"); + cpl_table_delete(table); + table = cpl_table_load(BASE "19.fits", 1, 1); + /**/ + + test_fvalue(999.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 0, &null), + "Check element 1 of casted column (2)... "); + cpl_test_zero(null); + test_fvalue(999.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 1, &null), + "Check element 2 of casted column (2)... "); + cpl_test_zero(null); + test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 2), + "Check element 3 of casted column (2)... "); + test_fvalue(999.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 3, &null), + "Check element 4 of casted column (2)... "); + cpl_test_zero(null); + test_fvalue(999.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 4, &null), + "Check element 5 of casted column (2)... "); + cpl_test_zero(null); + test_fvalue(999.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 5, &null), + "Check element 6 of casted column (2)... "); + cpl_test_zero(null); + test_fvalue(-1.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 6, &null), + "Check element 7 of casted column (2)... "); + cpl_test_zero(null); + test_fvalue(999.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 7, &null), + "Check element 8 of casted column (2)... "); + cpl_test_zero(null); + test_fvalue(999.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 8, &null), + "Check element 9 of casted column (2)... "); + cpl_test_zero(null); + test_fvalue(999.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 9, &null), + "Check element 10 of casted column (2)... "); + cpl_test_zero(null); + test_fvalue(999.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 10, &null), + "Check element 11 of casted column (2)... "); + cpl_test_zero(null); + test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 11), + "Check element 12 of casted column (2)... "); + test_fvalue(3.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 12, &null), + "Check element 13 of casted column (2)... "); + cpl_test_zero(null); + test_fvalue(7.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 13, &null), + "Check element 14 of casted column (2)... "); + cpl_test_zero(null); + test_fvalue(1.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 14, &null), + "Check element 15 of casted column (2)... "); + cpl_test_zero(null); + test_fvalue(4.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 15, &null), + "Check element 16 of casted column (2)... "); + cpl_test_zero(null); + test_fvalue(6.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 16, &null), + "Check element 17 of casted column (2)... "); + cpl_test_zero(null); + test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 17), + "Check element 18 of casted column (2)... "); + test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 18), + "Check element 19 of casted column (2)... "); + test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 19), + "Check element 20 of casted column (2)... "); + test_fvalue(999.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 20, &null), + "Check element 21 of casted column (2)... "); + cpl_test_zero(null); + test_fvalue(999.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 21, &null), + "Check element 22 of casted column (2)... "); + cpl_test_zero(null); + + test(cpl_table_shift_column(table, "IntToFloat", 1), + "Shift new column one position down... "); + + test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 0), + "Check element 1 of shifted column... "); + test_fvalue(999.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 1, &null), + "Check element 2 of shifted column... "); + cpl_test_zero(null); + test_fvalue(999.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 2, &null), + "Check element 3 of shifted column... "); + cpl_test_zero(null); + test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 3), + "Check element 4 of shifted column... "); + test_fvalue(999.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 4, &null), + "Check element 5 of shifted column... "); + cpl_test_zero(null); + test_fvalue(999.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 5, &null), + "Check element 6 of shifted column... "); + cpl_test_zero(null); + test_fvalue(999.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 6, &null), + "Check element 7 of shifted column... "); + cpl_test_zero(null); + test_fvalue(-1.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 7, &null), + "Check element 8 of shifted column... "); + cpl_test_zero(null); + test_fvalue(999.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 8, &null), + "Check element 9 of shifted column... "); + cpl_test_zero(null); + test_fvalue(999.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 9, &null), + "Check element 10 of shifted column... "); + cpl_test_zero(null); + test_fvalue(999.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 10, &null), + "Check element 11 of shifted column... "); + cpl_test_zero(null); + test_fvalue(999.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 11, &null), + "Check element 12 of shifted column... "); + cpl_test_zero(null); + test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 12), + "Check element 13 of shifted column... "); + test_fvalue(3.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 13, &null), + "Check element 14 of shifted column... "); + cpl_test_zero(null); + test_fvalue(7.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 14, &null), + "Check element 15 of shifted column... "); + cpl_test_zero(null); + test_fvalue(1.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 15, &null), + "Check element 16 of shifted column... "); + cpl_test_zero(null); + test_fvalue(4.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 16, &null), + "Check element 17 of shifted column... "); + cpl_test_zero(null); + test_fvalue(6.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 17, &null), + "Check element 18 of shifted column... "); + cpl_test_zero(null); + test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 18), + "Check element 19 of shifted column... "); + test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 19), + "Check element 20 of shifted column... "); + test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 20), + "Check element 21 of shifted column... "); + test_fvalue(999.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 21, &null), + "Check element 22 of shifted column... "); + cpl_test_zero(null); + + test(cpl_table_add_columns(table, "Integer", "IntToFloat"), + "Sum \"IntToFloat\" to \"Integer\"... "); + + /**- FIXME: RESTORE!!! */ + error = cpl_table_fill_invalid_int(table, "Integer", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_int(table, "AInt", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_int(table, "New AInt", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_save(table, NULL, NULL, BASE "20.fits", CPL_IO_CREATE); + cpl_test_eq_error(error, CPL_ERROR_NONE); + cpl_test_fits(BASE "20.fits"); + cpl_table_delete(table); + table = cpl_table_load(BASE "20.fits", 1, 1); + /**/ + + cpl_table_test_20(table); + + test(cpl_table_name_column(table, "IntToFloat", "Float"), + "Renaming \"IntToFloat\" to \"Float\"... "); + + test(cpl_table_set_column_invalid(table, "Integer", 7, 2), + "Set NULLs in \"Integer\" column... "); + + test(cpl_table_set_invalid(table, "Float", 7), + "Set NULL in \"Float\" column... "); + + test(cpl_table_set_invalid(table, "Float", 9), + "Set another NULL in \"Float\" column... "); + + test(cpl_table_set_invalid(table, "Double", 7), + "Set NULL in \"Double\" column... "); + + test(cpl_table_set_invalid(table, "String", 7), + "Set NULL in \"String\" column... "); + + test(cpl_table_new_column(table, "Sequence", CPL_TYPE_INT), + "Creating the \"Sequence\" column... "); + + for (i = 0; i < 18; i++) { + sprintf(message, "Writing to row %d of the \"Sequence\" column... ", i); + test(cpl_table_set_int(table, "Sequence", i, i), message); + } + + names[0] = "Integer"; + + reflist = cpl_propertylist_new(); + cpl_propertylist_append_bool(reflist, names[0], 0); + /* %$% */ + /* *+ + error = cpl_table_set_column_unit(table, "Integer", "Pixel"); + cpl_test_eq_error(error, CPL_ERROR_NONE); + cpl_table_dump_structure(table, NULL); + cpl_table_dump(table, 0, cpl_table_get_nrow(table), NULL); + exit; + +* */ + + { + int *hold = cpl_table_get_data_int(table, "Integer"); + + test(cpl_table_sort(table, reflist), + "Sorting by increasing values of the \"Integer\" column... "); + + test_pvalue(hold, cpl_table_get_data_int(table, "Integer"), + "Check pointer... "); + + cpl_propertylist_delete(reflist); + + error = cpl_table_set_column_unit(table, "AInt", "Pixel"); + cpl_test_eq_error(error, CPL_ERROR_NONE); + + test_svalue("Pixel", cpl_table_get_column_unit(table, "AInt"), + "Check column unit... "); + } + + /* + if (strcmp(unit = (char *)cpl_table_get_column_unit(table, "AInt"), + "Pixel")) { + printf("Check column unit... "); + printf("Expected \"Pixel\", obtained \"%s\"\n", unit); + cpl_end(); + return 1; + } + */ + + /**- FIXME: RESTORE!!! */ + error = cpl_table_fill_invalid_int(table, "Integer", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_int(table, "AInt", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_int(table, "New AInt", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_save(table, NULL, NULL, BASE "21.fits", CPL_IO_CREATE); + cpl_test_eq_error(error, CPL_ERROR_NONE); + cpl_test_fits(BASE "21.fits"); + cpl_table_delete(table); + table = cpl_table_load(BASE "21.fits", 1, 1); + /**/ + + cpl_table_test_21(table); + + cpl_table_delete(table); + table = cpl_table_load(BASE "22.fits", 1, 1); + /**/ + + cpl_table_test_22(table); + + /* + * Here partial loading of table is tested + */ + + error = cpl_table_fill_invalid_int(table, "Integer", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_int(table, "AInt", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_int(table, "New AInt", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_save(table, NULL, NULL, BASE "24.fits", CPL_IO_CREATE); + cpl_test_eq_error(error, CPL_ERROR_NONE); + cpl_test_fits(BASE "24.fits"); + cpl_table_delete(table); + colnames = cpl_array_new(7, CPL_TYPE_STRING); + cpl_array_set_string(colnames, 0, "Integer"); + cpl_array_set_string(colnames, 1, "Double"); + cpl_array_set_string(colnames, 2, "String"); + cpl_array_set_string(colnames, 3, "AInt"); + cpl_array_set_string(colnames, 4, "AFloat"); + cpl_array_set_string(colnames, 5, "ADouble"); + cpl_array_set_string(colnames, 6, "Float"); + table = cpl_table_load_window(BASE "24.fits", 1, 1, colnames, 7, 6); + cpl_array_delete(colnames); + + /* Test some values here... */ + + error = cpl_table_fill_invalid_int(table, "Integer", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_int(table, "AInt", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_save(table, NULL, NULL, BASE "25.fits", CPL_IO_CREATE); + cpl_test_eq_error(error, CPL_ERROR_NONE); + cpl_test_fits(BASE "25.fits"); + + cpl_table_delete(table); + cpl_free(fArray); +#ifdef _Complex_I + cpl_free(cfArray); +#endif + + return 0; +} + +/*----------------------------------------------------------------------------*/ +/** + @internal + @brief Test the another part of the CPL table functions + @return Zero iff successful + */ +/*----------------------------------------------------------------------------*/ +static int +cpl_table_test_rest(void) +{ + int nrows = NROWS; + int i, j, k, null; + int pp; + char message[80]; + + const char *unit; + + cpl_table *table; + cpl_table *copia; + cpl_array *array; + cpl_array *dimensions; + cpl_array **arrays; + + FILE *stream; + + cpl_error_code error; + + stream = + cpl_msg_get_level() > CPL_MSG_INFO ? fopen("/dev/null", "a") : stdout; + + cpl_test_nonnull(stream); + + + /* + * Powers + */ + + nrows = 7; + + table = cpl_table_new(nrows); + error = cpl_table_new_column(table, "Int", CPL_TYPE_INT); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_new_column(table, "Float", CPL_TYPE_FLOAT); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_new_column(table, "Double", CPL_TYPE_DOUBLE); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_new_column(table, "CFloat", CPL_TYPE_FLOAT_COMPLEX); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_new_column(table, "CDouble", CPL_TYPE_DOUBLE_COMPLEX); + cpl_test_eq_error(error, CPL_ERROR_NONE); + + for (i = 0; i < nrows; i++) { + error = cpl_table_set_int(table, "Int", i, i); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_set_float(table, "Float", i, i); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_set_double(table, "Double", i, i); + cpl_test_eq_error(error, CPL_ERROR_NONE); +#ifdef _Complex_I + error = cpl_table_set_float_complex(table, "CFloat", i, i + i * I); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_set_double_complex(table, "CDouble", i, i + I); + cpl_test_eq_error(error, CPL_ERROR_NONE); +#endif + } + + error = cpl_table_exponential_column(table, "Int", 2); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_exponential_column(table, "Float", 2); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_exponential_column(table, "Double", 2); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_exponential_column(table, "CFloat", 2); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_exponential_column(table, "CDouble", 2); + cpl_test_eq_error(error, CPL_ERROR_NONE); + + pp = 1; + for (i = 0; i < nrows; i++) { +#ifdef _Complex_I + const double ln2 = CPL_MATH_LN2; + + test_cvalue(exp(i * ln2) * (cos(i * ln2) + I * sin(i * ln2)), 0.00001, + cpl_table_get_float_complex(table, "CFloat", i, &null), + "Check expo CFloat... "); + cpl_test_zero(null); + + test_cvalue(exp(i * ln2) * (cos(ln2) + I * sin(ln2)), 0.00001, + cpl_table_get_double_complex(table, "CDouble", i, &null), + "Check expo CDouble... "); + cpl_test_zero(null); +#endif + + test_ivalue(pp, cpl_table_get_int(table, "Int", i, &null), + "Check expo Int... "); + cpl_test_zero(null); + test_fvalue((float)pp, 0.00001, + cpl_table_get_float(table, "Float", i, &null), + "Check expo Float... "); + cpl_test_zero(null); + test_fvalue((float)pp, 0.00001, + cpl_table_get_double(table, "Double", i, &null), + "Check expo Double... "); + cpl_test_zero(null); + pp *= 2; + } + + error = cpl_table_logarithm_column(table, "Int", 2); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_logarithm_column(table, "Float", 2); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_logarithm_column(table, "Double", 2); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_logarithm_column(table, "CFloat", 2); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_logarithm_column(table, "CDouble", 2); + cpl_test_eq_error(error, CPL_ERROR_NONE); + + for (i = 0; i < nrows; i++) { +#ifdef _Complex_I + const double ln2 = CPL_MATH_LN2; + + test_cvalue(clog(exp(i * ln2) * (cos(i * ln2) + I * sin(i * ln2))) / + ln2, + 0.00001, + cpl_table_get_float_complex(table, "CFloat", i, &null), + "Check log CFloat... "); + cpl_test_zero(null); + test_cvalue(clog(exp(i * ln2) * (cos(ln2) + I * sin(ln2))) / ln2, + 0.00001, + cpl_table_get_double_complex(table, "CDouble", i, &null), + "Check log CDouble... "); + cpl_test_zero(null); +#endif + test_ivalue(i, cpl_table_get_int(table, "Int", i, &null), + "Check log Int... "); + cpl_test_zero(null); + test_fvalue((float)i, 0.00001, + cpl_table_get_float(table, "Float", i, &null), + "Check log Float... "); + cpl_test_zero(null); + test_fvalue((float)i, 0.00001, + cpl_table_get_double(table, "Double", i, &null), + "Check log Double... "); + cpl_test_zero(null); + } + +#ifdef _Complex_I + for (i = 0; i < nrows; i++) { + error = cpl_table_set_float_complex(table, "CFloat", i, i + i * I); + cpl_test_eq_error(error, CPL_ERROR_NONE); + test_cvalue(i + i * I, 0.0, + cpl_table_get_float_complex(table, "CFloat", i, &null), + " "); + cpl_test_zero(null); + error = cpl_table_set_double_complex(table, "CDouble", i, i + I); + cpl_test_eq_error(error, CPL_ERROR_NONE); + test_cvalue(i + I, 0.0, + cpl_table_get_double_complex(table, "CDouble", i, &null), + " "); + cpl_test_zero(null); + } +#endif + + cpl_test_zero(cpl_table_count_invalid(table, "CFloat")); + cpl_test_zero(cpl_table_count_invalid(table, "CDouble")); + + error = cpl_table_power_column(table, "Int", 2.0); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_power_column(table, "Float", 2.0); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_power_column(table, "Double", 2.0); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_power_column(table, "CFloat", 2.0); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_power_column(table, "CDouble", 2.0); + cpl_test_eq_error(error, CPL_ERROR_NONE); + + cpl_test_zero(cpl_table_count_invalid(table, "CFloat")); + cpl_test_zero(cpl_table_count_invalid(table, "CDouble")); + + for (i = 0; i < nrows; i++) { + test_ivalue(i * i, cpl_table_get_int(table, "Int", i, &null), + "Check pow Int... "); + cpl_test_zero(null); + test_fvalue((float)i * i, 0.00001, + cpl_table_get_float(table, "Float", i, &null), + "Check pow Float... "); + cpl_test_zero(null); + test_fvalue((float)i * i, 0.00001, + cpl_table_get_double(table, "Double", i, &null), + "Check pow Double... "); + cpl_test_zero(null); +#ifdef _Complex_I + test_cvalue(2 * I * i * i, 0.00001, + cpl_table_get_float_complex(table, "CFloat", i, &null), + "Check pow CFloat... "); + cpl_test_zero(null); + test_cvalue(i * i - 1 + 2 * i * I, 0.00001, + cpl_table_get_double_complex(table, "CDouble", i, &null), + "Check pow CDouble... "); + cpl_test_zero(null); +#endif + } + +#ifdef _Complex_I + /* On a ppc-Mac with gcc 4.0 cpowf(0.0, 2.0) returns NaN */ + /* FIXME: For a proper unit test the table should be re-set for each test */ + error = cpl_table_set_float_complex(table, "CFloat", 0, 0.0); + cpl_test_eq_error(error, CPL_ERROR_NONE); +#endif + + error = cpl_table_power_column(table, "Int", 0.5); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_power_column(table, "Float", 0.5); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_power_column(table, "Double", 0.5); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_power_column(table, "CFloat", 0.5); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_power_column(table, "CDouble", 0.5); + cpl_test_eq_error(error, CPL_ERROR_NONE); + + + for (i = 0; i < nrows; i++) { + test_ivalue(i, cpl_table_get_int(table, "Int", i, &null), + "Check sqrt Int... "); + cpl_test_zero(null); + test_fvalue((float)i, 0.00001, + cpl_table_get_float(table, "Float", i, &null), + "Check sqrt Float... "); + cpl_test_zero(null); + test_fvalue((float)i, 0.00001, + cpl_table_get_double(table, "Double", i, &null), + "Check sqrt Double... "); + cpl_test_zero(null); +#ifdef _Complex_I + test_cvalue(i + i * I, 0.00001, + cpl_table_get_float_complex(table, "CFloat", i, &null), + "Check sqrt CFloat... "); + cpl_test_zero(null); + test_cvalue(i + I, 0.00001, + cpl_table_get_double_complex(table, "CDouble", i, &null), + "Check sqrt CDouble... "); + cpl_test_zero(null); +#endif + } + +#ifdef _Complex_I + /* On a ppc-Mac with gcc 4.0 cpowf(0.0, 0.5) returns NaN */ + /* FIXME: For a proper unit test the table should be re-set for each test */ + error = cpl_table_set_float_complex(table, "CFloat", 0, 0.0); + cpl_test_eq_error(error, CPL_ERROR_NONE); +#endif + + error = cpl_table_power_column(table, "Int", -1.0); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_power_column(table, "Float", -1.0); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_power_column(table, "Double", -1.0); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_power_column(table, "CFloat", -1.0); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_power_column(table, "CDouble", -1.0); + cpl_test_eq_error(error, CPL_ERROR_NONE); + + /* Zero valued elements are rejected */ + cpl_test_zero(cpl_table_is_valid(table, "Int", 0)); + cpl_test_zero(cpl_table_is_valid(table, "Float", 0)); + cpl_test_zero(cpl_table_is_valid(table, "Double", 0)); + cpl_test_zero(cpl_table_is_valid(table, "CFloat", 0)); + + cpl_test_eq(cpl_table_count_invalid(table, "Int"), 1); + cpl_test_eq(cpl_table_count_invalid(table, "Float"), 1); + cpl_test_eq(cpl_table_count_invalid(table, "Double"), 1); + cpl_test_eq(cpl_table_count_invalid(table, "CFloat"), 1); + + for (i = 1; i < nrows; i++) { + test_ivalue(i == 1 || i == 2 ? 1.0 : 0.0, + cpl_table_get_int(table, "Int", i, &null), + "Check pow(-1) Int... "); + cpl_test_zero(null); + test_fvalue(1.0 / (double)i, 0.00001, + cpl_table_get_float(table, "Float", i, &null), + "Check pow(-1) Float... "); + cpl_test_zero(null); + test_fvalue(1.0 / (double)i, 0.00001, + cpl_table_get_double(table, "Double", i, &null), + "Check pow(-1) Double... "); + cpl_test_zero(null); +#ifdef _Complex_I + test_cvalue(1.0 / ((double)i + (double)i * I), 0.00001, + cpl_table_get_float_complex(table, "CFloat", i, &null), + "Check pow(-1) CFloat... "); + cpl_test_zero(null); + test_cvalue(1.0 / ((double)i + I), 0.00001, + cpl_table_get_double_complex(table, "CDouble", i, &null), + "Check pow(-1) CDouble... "); + cpl_test_zero(null); +#endif + } + + + /* Set the values back */ + for (i = 0; i < nrows; i++) { + error = cpl_table_set_int(table, "Int", i, i); + cpl_test_eq_error(error, CPL_ERROR_NONE); + } + error = cpl_table_power_column(table, "Float", -1.0); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_power_column(table, "Double", -1.0); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_power_column(table, "CFloat", -1.0); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_power_column(table, "CDouble", -1.0); + cpl_test_eq_error(error, CPL_ERROR_NONE); + + error = cpl_table_set_float(table, "Float", 0, 0.0); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_set_double(table, "Double", 0, 0.0); + cpl_test_eq_error(error, CPL_ERROR_NONE); +#ifdef _Complex_I + error = cpl_table_set_float_complex(table, "CFloat", 0, 0.0); + cpl_test_eq_error(error, CPL_ERROR_NONE); +#endif + + cpl_test_zero(cpl_table_has_invalid(table, "Int")); + cpl_test_zero(cpl_table_has_invalid(table, "Float")); + cpl_test_zero(cpl_table_has_invalid(table, "Double")); + cpl_test_zero(cpl_table_has_invalid(table, "CFloat")); + cpl_test_zero(cpl_table_has_invalid(table, "CDouble")); + + /* + * Test cpl_table_abs_column() + */ + + error = cpl_table_set_int(table, "Int", 2, -2); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_set_float(table, "Float", 2, -2); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_set_double(table, "Double", 2, -2); + cpl_test_eq_error(error, CPL_ERROR_NONE); + cpl_table_abs_column(table, "Int"); + cpl_table_abs_column(table, "Float"); + cpl_table_abs_column(table, "Double"); + cpl_table_abs_column(table, "CFloat"); + cpl_table_abs_column(table, "CDouble"); + + for (i = 0; i < nrows; i++) { + double s2 = sqrt(2.0); + + test_ivalue(i, cpl_table_get_int(table, "Int", i, &null), + "Check abs Int... "); + cpl_test_zero(null); + test_fvalue((float)i, 0.00001, + cpl_table_get_float(table, "Float", i, &null), + "Check abs Float... "); + cpl_test_zero(null); + test_fvalue((float)i, 0.00001, + cpl_table_get_double(table, "Double", i, &null), + "Check abs Double... "); + cpl_test_zero(null); + test_fvalue(i * s2, 0.00001, + cpl_table_get_float(table, "CFloat", i, &null), + "Check abs CFloat... "); + cpl_test_zero(null); + test_fvalue(sqrt(i * i + 1), 0.00001, + cpl_table_get_double(table, "CDouble", i, &null), + "Check abs CDouble... "); + cpl_test_zero(null); + } + + cpl_table_delete(table); + + + /* + * Testing the selection functions + */ + + nrows = 7; + + table = cpl_table_new(nrows); + cpl_table_new_column(table, "Int", CPL_TYPE_INT); + cpl_table_new_column(table, "String", CPL_TYPE_STRING); + + unit = "abcd\0efgh\0ijkl\0mnop\0qrst\0uvwx\0yz"; + + for (i = 0; i < nrows; i++) { + error = cpl_table_set_int(table, "Int", i, i); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_set_string(table, "String", i, unit + i * 5); + cpl_test_eq_error(error, CPL_ERROR_NONE); + } + + cpl_table_duplicate_column(table, "Int2", table, "Int"); + cpl_table_multiply_columns(table, "Int2", "Int2"); + cpl_table_cast_column(table, "Int", "Float", CPL_TYPE_FLOAT); + +#ifdef VERBOSE + + cpl_msg_info(cpl_func, "This is the test table:\n\n"); + cpl_table_dump(table, 0, cpl_table_get_nrow(table), stream); + + cpl_msg_info(cpl_func, "Now erase all selected:\n\n"); + +#endif + + copia = cpl_table_duplicate(table); + test_ivalue(7, cpl_table_count_selected(copia), "Check all selected... "); + cpl_table_erase_selected(copia); +#ifdef VERBOSE + cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), stream); +#endif + test_ivalue(0, cpl_table_get_nrow(copia), + "Check length erase all selected... "); + cpl_table_delete(copia); + +#ifdef VERBOSE + + cpl_msg_info(cpl_func, "This is the test table:\n\n"); + cpl_table_dump(table, 0, cpl_table_get_nrow(table), stream); + + cpl_msg_info(cpl_func, "Now delete all Int >= Int2:\n\n"); + +#endif + + copia = cpl_table_duplicate(table); + cpl_table_and_selected(copia, "Int", CPL_NOT_LESS_THAN, "Int2"); + test_ivalue(2, cpl_table_count_selected(copia), + "Check Int >= Int2 selected... "); + array = cpl_table_where_selected(copia); + test_ivalue(CPL_TYPE_SIZE, cpl_array_get_type(array), + "Check type of where array..."); + test_ivalue(2, cpl_array_get_size(array), "Check size of where array..."); + test_ivalue(0, cpl_array_get_cplsize(array, 0, &null), + "Check first element of where array..."); + cpl_test_zero(null); + test_ivalue(1, cpl_array_get_cplsize(array, 1, &null), + "Check second element of where array..."); + cpl_test_zero(null); + cpl_array_delete(array); + cpl_table_erase_selected(copia); +#ifdef VERBOSE + cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), stream); +#endif + test_ivalue(5, cpl_table_get_nrow(copia), + "Check length erase all Int >= Int2... "); + array = cpl_table_where_selected(copia); + test_ivalue(CPL_TYPE_SIZE, cpl_array_get_type(array), + "Check type of everywhere array..."); + test_ivalue(5, cpl_array_get_size(array), + "Check size of everywhere array..."); + test_ivalue(0, cpl_array_get_cplsize(array, 0, &null), + "Check first element of everywhere array..."); + cpl_test_zero(null); + test_ivalue(1, cpl_array_get_cplsize(array, 1, &null), + "Check second element of everywhere array..."); + cpl_test_zero(null); + test_ivalue(2, cpl_array_get_cplsize(array, 2, &null), + "Check third element of everywhere array..."); + cpl_test_zero(null); + test_ivalue(3, cpl_array_get_cplsize(array, 3, &null), + "Check fourth element of everywhere array..."); + cpl_test_zero(null); + test_ivalue(4, cpl_array_get_cplsize(array, 4, &null), + "Check fifth element of everywhere array..."); + cpl_test_zero(null); + cpl_array_delete(array); + + cpl_table_unselect_all(copia); + array = cpl_table_where_selected(copia); + test_ivalue(CPL_TYPE_SIZE, cpl_array_get_type(array), + "Check type of nowhere array..."); + test_ivalue(0, cpl_array_get_size(array), "Check size of nowhere array..."); + cpl_array_delete(array); + + cpl_table_delete(copia); + +#ifdef VERBOSE + + cpl_msg_info(cpl_func, "This is the test table:\n\n"); + cpl_table_dump(table, 0, cpl_table_get_nrow(table), stream); + + cpl_msg_info(cpl_func, "Now delete all Int > 3:\n\n"); + +#endif + + copia = cpl_table_duplicate(table); + cpl_table_and_selected_int(copia, "Int", CPL_GREATER_THAN, 3); + test_ivalue(3, cpl_table_count_selected(copia), + "Check Int > 3 selected... "); + cpl_table_erase_selected(copia); +#ifdef VERBOSE + cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), stream); +#endif + test_ivalue(4, cpl_table_get_nrow(copia), + "Check length erase all Int > 3... "); + cpl_table_delete(copia); + +#ifdef VERBOSE + + cpl_msg_info(cpl_func, "This is the test table:\n\n"); + cpl_table_dump(table, 0, cpl_table_get_nrow(table), stream); + + cpl_msg_info(cpl_func, "Now delete all Int2 > Float:\n\n"); + +#endif + + copia = cpl_table_duplicate(table); + cpl_table_and_selected(copia, "Int2", CPL_GREATER_THAN, "Float"); + test_ivalue(5, cpl_table_count_selected(copia), + "Check Int2 > Float selected... "); + cpl_table_erase_selected(copia); +#ifdef VERBOSE + cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), stream); +#endif + test_ivalue(2, cpl_table_get_nrow(copia), + "Check length erase all Int2 > Float... "); + cpl_table_delete(copia); + +#ifdef VERBOSE + + cpl_msg_info(cpl_func, "This is the test table:\n\n"); + cpl_table_dump(table, 0, cpl_table_get_nrow(table), stream); + + cpl_msg_info(cpl_func, "Now delete all String == \"^[a-l].*\":\n\n"); + +#endif + + copia = cpl_table_duplicate(table); + cpl_table_and_selected_string(copia, "String", CPL_EQUAL_TO, "^[a-l].*"); + test_ivalue(3, cpl_table_count_selected(copia), + "Check String == \"^[a-l].*\" selected... "); + cpl_table_erase_selected(copia); +#ifdef VERBOSE + cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), stream); +#endif + test_ivalue(4, cpl_table_get_nrow(copia), + "Check length erase all String == \"^[a-l].*\"... "); + cpl_table_delete(copia); + +#ifdef VERBOSE + + cpl_msg_info(cpl_func, "This is the test table:\n\n"); + cpl_table_dump(table, 0, cpl_table_get_nrow(table), stream); + + cpl_msg_info(cpl_func, "Now delete all String > \"carlo\":\n\n"); + +#endif + + copia = cpl_table_duplicate(table); + cpl_table_and_selected_string(copia, "String", CPL_GREATER_THAN, "carlo"); + test_ivalue(6, cpl_table_count_selected(copia), + "Check String > \"carlo\" selected... "); + cpl_table_erase_selected(copia); +#ifdef VERBOSE + cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), stream); +#endif + test_ivalue(1, cpl_table_get_nrow(copia), + "Check length erase all String > \"carlo\"... "); + cpl_table_delete(copia); + +#ifdef VERBOSE + + cpl_msg_info(cpl_func, "This is the test table:\n\n"); + cpl_table_dump(table, 0, cpl_table_get_nrow(table), stream); + + cpl_msg_info(cpl_func, + "Now delete all String > \"tattoo\" and Int == 3:\n\n"); + +#endif + + copia = cpl_table_duplicate(table); + cpl_table_and_selected_string(copia, "String", CPL_GREATER_THAN, "tattoo"); + cpl_table_or_selected_int(copia, "Int", CPL_EQUAL_TO, 3); + test_ivalue(3, cpl_table_count_selected(copia), + "Check String > \"tattoo\" and Int == 3 selected... "); + cpl_table_erase_selected(copia); +#ifdef VERBOSE + cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), stream); +#endif + test_ivalue(4, cpl_table_get_nrow(copia), + "Check length erase all String > \"tattoo\" and Int == 3... "); + cpl_table_delete(copia); + +#ifdef VERBOSE + + cpl_msg_info(cpl_func, + "Now keep all String > \"tattoo\" and Int == 3:\n\n"); + +#endif + + copia = cpl_table_duplicate(table); + cpl_table_and_selected_string(copia, "String", CPL_GREATER_THAN, "tattoo"); + cpl_table_or_selected_int(copia, "Int", CPL_EQUAL_TO, 3); + cpl_table_not_selected(copia); + test_ivalue(4, cpl_table_count_selected(copia), + "Check String > \"tattoo\" and Int == 3 rejected... "); + cpl_table_erase_selected(copia); +#ifdef VERBOSE + cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), stream); +#endif + test_ivalue(3, cpl_table_get_nrow(copia), + "Check length keep all String > \"tattoo\" and Int == 3... "); + cpl_table_delete(copia); + +#ifdef VERBOSE + + cpl_msg_info(cpl_func, "This is the test table:\n\n"); + cpl_table_dump(table, 0, cpl_table_get_nrow(table), stream); + + cpl_msg_info(cpl_func, "Now delete rows 0, 2, and 6:\n\n"); + +#endif + + copia = cpl_table_duplicate(table); + cpl_table_unselect_all(copia); + cpl_table_select_row(copia, 0); + cpl_table_select_row(copia, 2); + cpl_table_select_row(copia, 6); + test_ivalue(3, cpl_table_count_selected(copia), + "Check rows 0, 2, and 6 selected... "); + cpl_table_erase_selected(copia); #ifdef VERBOSE + cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), stream); +#endif + test_ivalue(4, cpl_table_get_nrow(copia), + "Check length erase rows 0, 2, and 6... "); + cpl_table_delete(copia); - cpl_msg_info(cpl_func, "This is the test table:\n\n"); - cpl_table_dump(table, 0, cpl_table_get_nrow(table), stream); +#ifdef VERBOSE - cpl_msg_info(cpl_func, "Now delete all String > \"tattoo\" and Int == 3:\n\n"); + cpl_msg_info(cpl_func, "Now keep rows 0, 2, and 6:\n\n"); #endif - copia = cpl_table_duplicate(table); - cpl_table_and_selected_string(copia, "String", CPL_GREATER_THAN, "tattoo"); - cpl_table_or_selected_int(copia, "Int", CPL_EQUAL_TO, 3); - test_ivalue(3, cpl_table_count_selected(copia), - "Check String > \"tattoo\" and Int == 3 selected... "); - cpl_table_erase_selected(copia); + copia = cpl_table_duplicate(table); + cpl_table_unselect_row(copia, 0); + cpl_table_unselect_row(copia, 2); + cpl_table_unselect_row(copia, 6); + test_ivalue(4, cpl_table_count_selected(copia), + "Check rows 0, 2, and 6 rejected... "); + cpl_table_erase_selected(copia); #ifdef VERBOSE - cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), stream); + cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), stream); #endif - test_ivalue(4, cpl_table_get_nrow(copia), - "Check length erase all String > \"tattoo\" and Int == 3... "); - cpl_table_delete(copia); + test_ivalue(3, cpl_table_get_nrow(copia), + "Check length erase rows 0, 2, and 6... "); + cpl_table_delete(copia); #ifdef VERBOSE - cpl_msg_info(cpl_func, "Now keep all String > \"tattoo\" and Int == 3:\n\n"); + cpl_msg_info(cpl_func, "This is the test table:\n\n"); + cpl_table_dump(table, 0, cpl_table_get_nrow(table), stream); + + cpl_msg_info(cpl_func, "Now delete first 3 rows:\n\n"); #endif - copia = cpl_table_duplicate(table); - cpl_table_and_selected_string(copia, "String", CPL_GREATER_THAN, "tattoo"); - cpl_table_or_selected_int(copia, "Int", CPL_EQUAL_TO, 3); - cpl_table_not_selected(copia); - test_ivalue(4, cpl_table_count_selected(copia), - "Check String > \"tattoo\" and Int == 3 rejected... "); - cpl_table_erase_selected(copia); + copia = cpl_table_duplicate(table); + cpl_table_and_selected_window(copia, 0, 3); + test_ivalue(3, cpl_table_count_selected(copia), + "Check first 3 rows selected... "); + cpl_table_erase_selected(copia); #ifdef VERBOSE - cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), stream); + cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), stream); #endif - test_ivalue(3, cpl_table_get_nrow(copia), - "Check length keep all String > \"tattoo\" and Int == 3... "); - cpl_table_delete(copia); + test_ivalue(4, cpl_table_get_nrow(copia), + "Check length erase first 3 rows... "); + cpl_table_delete(copia); #ifdef VERBOSE - cpl_msg_info(cpl_func, "This is the test table:\n\n"); - cpl_table_dump(table, 0, cpl_table_get_nrow(table), stream); + cpl_msg_info(cpl_func, "Now delete last 2 rows:\n\n"); - cpl_msg_info(cpl_func, "Now delete rows 0, 2, and 6:\n\n"); +#endif + + copia = cpl_table_duplicate(table); + cpl_table_and_selected_window(copia, 5, 2); + test_ivalue(2, cpl_table_count_selected(copia), + "Check last 2 rows selected... "); + cpl_table_erase_selected(copia); +#ifdef VERBOSE + cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), stream); +#endif + test_ivalue(5, cpl_table_get_nrow(copia), + "Check length erase last 2 rows... "); + cpl_table_delete(copia); + +#ifdef VERBOSE + + cpl_msg_info(cpl_func, "Now delete rows from 2 to 3:\n\n"); #endif - copia = cpl_table_duplicate(table); - cpl_table_unselect_all(copia); - cpl_table_select_row(copia, 0); - cpl_table_select_row(copia, 2); - cpl_table_select_row(copia, 6); - test_ivalue(3, cpl_table_count_selected(copia), - "Check rows 0, 2, and 6 selected... "); - cpl_table_erase_selected(copia); + copia = cpl_table_duplicate(table); + cpl_table_and_selected_window(copia, 2, 2); + test_ivalue(2, cpl_table_count_selected(copia), + "Check middle 2 rows selected... "); + cpl_table_erase_selected(copia); #ifdef VERBOSE - cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), stream); + cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), stream); #endif - test_ivalue(4, cpl_table_get_nrow(copia), - "Check length erase rows 0, 2, and 6... "); - cpl_table_delete(copia); + test_ivalue(5, cpl_table_get_nrow(copia), + "Check length erase rows from 2 to 3... "); + cpl_table_delete(copia); #ifdef VERBOSE - cpl_msg_info(cpl_func, "Now keep rows 0, 2, and 6:\n\n"); + cpl_msg_info(cpl_func, "Now delete rows from 1 to 3 and row 6:\n\n"); #endif - copia = cpl_table_duplicate(table); - cpl_table_unselect_row(copia, 0); - cpl_table_unselect_row(copia, 2); - cpl_table_unselect_row(copia, 6); - test_ivalue(4, cpl_table_count_selected(copia), - "Check rows 0, 2, and 6 rejected... "); - cpl_table_erase_selected(copia); + copia = cpl_table_duplicate(table); + cpl_table_and_selected_window(copia, 1, 3); + cpl_table_or_selected_window(copia, 6, 1); + test_ivalue(4, cpl_table_count_selected(copia), + "Check rows 1 to 3 and row 6 rejected... "); + cpl_table_erase_selected(copia); #ifdef VERBOSE - cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), stream); + cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), stream); #endif - test_ivalue(3, cpl_table_get_nrow(copia), - "Check length erase rows 0, 2, and 6... "); - cpl_table_delete(copia); + test_ivalue(3, cpl_table_get_nrow(copia), + "Check length erase rows from 1 to 3 and row 6... "); + cpl_table_delete(copia); + + /* Erase only invalid elements */ + copia = cpl_table_duplicate(table); + for (i = 0; i < nrows; i++) { + error = cpl_table_set_invalid(copia, "Int", i); + cpl_test_eq_error(error, CPL_ERROR_NONE); + } + cpl_table_unselect_row(copia, nrows - 1); + + cpl_table_erase_selected(copia); #ifdef VERBOSE + cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), stream); +#endif + test_ivalue(1, cpl_table_get_nrow(copia), + "Check length erase last row, only invalid values... "); + + cpl_table_delete(copia); + + /* Erase array column with valid/invalid values */ + copia = cpl_table_duplicate(table); - cpl_msg_info(cpl_func, "This is the test table:\n\n"); - cpl_table_dump(table, 0, cpl_table_get_nrow(table), stream); + cpl_table_cast_column(copia, "Int", "Double", CPL_TYPE_DOUBLE); - cpl_msg_info(cpl_func, "Now delete first 3 rows:\n\n"); + test(cpl_table_new_column_array(copia, "ADouble", + CPL_TYPE_DOUBLE | CPL_TYPE_POINTER, 2), + "Creating the ArrayDouble column... "); + + array = cpl_array_new(2, CPL_TYPE_DOUBLE); + test(cpl_table_set_array(copia, "ADouble", 1, array), + "Set a valid array to ADouble 1... "); + test(cpl_table_set_array(copia, "ADouble", 2, array), + "Set a valid array to ADouble 2... "); + cpl_array_delete(array); + + cpl_table_unselect_row(copia, 0); + cpl_table_unselect_row(copia, 2); + error = cpl_table_set_invalid(copia, "Int", 6); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_set_invalid(copia, "Int2", 0); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_set_invalid(copia, "Int2", 1); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_set_invalid(copia, "Double", 0); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_set_invalid(copia, "Double", 1); + cpl_test_eq_error(error, CPL_ERROR_NONE); + cpl_table_erase_selected(copia); +#ifdef VERBOSE + cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), stream); #endif + test_ivalue(2, cpl_table_get_nrow(copia), + "Check length erase valid/invalid values... "); + test_ivalue(0, cpl_table_is_valid(copia, "Int2", 0), + "Check that first element of \"Int2\" is still NULL... "); + test_ivalue(1, cpl_table_is_valid(copia, "Int2", 1), + "Check that first element of \"Int2\" is now valid... "); + + cpl_table_unselect_row(copia, 0); + cpl_table_unselect_row(copia, 1); + cpl_table_erase_selected(copia); + test_ivalue(2, cpl_table_count_selected(copia), + "Check that rows are selected... "); + + cpl_table_delete(copia); + + cpl_table_delete(table); + + /* + * Select invalid rows + */ + nrows = 3; + + table = cpl_table_new(nrows); + cpl_table_new_column(table, "Int", CPL_TYPE_INT); + cpl_table_new_column(table, "String", CPL_TYPE_STRING); + + error = cpl_table_set_int(table, "Int", 0, 18); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_set_int(table, "Int", 1, 18); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_set_invalid(table, "Int", 2); + cpl_test_eq_error(error, CPL_ERROR_NONE); + + error = cpl_table_set_string(table, "String", 0, "hello"); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_set_string(table, "String", 1, "hello"); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_set_invalid(table, "String", 2); + cpl_test_eq_error(error, CPL_ERROR_NONE); - copia = cpl_table_duplicate(table); - cpl_table_and_selected_window(copia, 0, 3); - test_ivalue(3, cpl_table_count_selected(copia), - "Check first 3 rows selected... "); - cpl_table_erase_selected(copia); #ifdef VERBOSE - cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), stream); + cpl_table_dump(table, 0, cpl_table_get_nrow(table), stream); #endif - test_ivalue(4, cpl_table_get_nrow(copia), - "Check length erase first 3 rows... "); - cpl_table_delete(copia); + + cpl_table_select_all(table); + + /* + * This test (next 4 calls) is related to ticket DFS03619 + */ + + test_ivalue(1, cpl_table_and_selected_invalid(table, "String"), + "Check number of selected rows (string)... "); + test_ivalue(0, cpl_table_is_selected(table, 0), + "Check that row is not selected..."); + test_ivalue(0, cpl_table_is_selected(table, 1), + "Check that row is not selected..."); + test_ivalue(1, cpl_table_is_selected(table, 2), + "Check that row is selected..."); + + cpl_table_select_all(table); + test_ivalue(1, cpl_table_and_selected_invalid(table, "Int"), + "Check number of selected rows (integer)... "); + test_ivalue(0, cpl_table_is_selected(table, 0), + "Check that row is not selected..."); + test_ivalue(0, cpl_table_is_selected(table, 1), + "Check that row is not selected..."); + test_ivalue(1, cpl_table_is_selected(table, 2), + "Check that row is selected..."); + + cpl_table_delete(table); + + /* + * Test case: dividing a double column by integer + */ + + nrows = 100; + + table = cpl_table_new(nrows); + cpl_table_new_column(table, "Int", CPL_TYPE_INT); + + for (i = 0; i < nrows; i++) { + error = cpl_table_set_int(table, "Int", i, i + 1); + cpl_test_eq_error(error, CPL_ERROR_NONE); + } + + cpl_table_cast_column(table, "Int", "Double", CPL_TYPE_DOUBLE); + + test(cpl_table_divide_columns(table, "Double", "Int"), + "Divide double column with integer column... "); + + for (i = 0; i < nrows; i++) { + sprintf(message, "Check element %d of result column... ", i); + test_fvalue(1.0, 0.00001, + cpl_table_get_double(table, "Double", i, &null), message); + cpl_test_zero(null); + } #ifdef VERBOSE + cpl_table_dump(table, 0, cpl_table_get_nrow(table), stream); +#endif + + cpl_table_delete(table); + + /* + * Test table of images + */ + + table = cpl_table_new(5); + test(cpl_table_new_column_array(table, "ADouble", CPL_TYPE_DOUBLE, 30), + "Creating the ADouble column... "); + + k = 0; + arrays = cpl_table_get_data_array(table, "ADouble"); + for (i = 0; i < 5; i++) { + arrays[i] = cpl_array_new(30, CPL_TYPE_DOUBLE); + for (j = 0; j < 30; j++) { + cpl_array_set_double(arrays[i], j, k * .123456); + k++; + } + } + + dimensions = cpl_array_new(2, CPL_TYPE_INT); + cpl_array_set_int(dimensions, 0, 5); + cpl_array_set_int(dimensions, 1, 5); + + test_failure(CPL_ERROR_INCOMPATIBLE_INPUT, + cpl_table_set_column_dimensions(table, "ADouble", dimensions), + "Try impossible column dimensions... "); + + cpl_array_set_int(dimensions, 1, 6); + + test_ivalue(1, cpl_table_get_column_dimensions(table, "ADouble"), + "Check no dimensions assigned to column ADouble... "); + + test(cpl_table_set_column_dimensions(table, "ADouble", dimensions), + "Set appropriate dimensions for column of images... "); + + cpl_array_delete(dimensions); + + error = cpl_table_save(table, NULL, NULL, BASE "23.fits", CPL_IO_CREATE); + cpl_test_eq_error(error, CPL_ERROR_NONE); + cpl_test_fits(BASE "23.fits"); + cpl_table_delete(table); + table = cpl_table_load(BASE "23.fits", 1, 1); + + test_ivalue(2, cpl_table_get_column_dimensions(table, "ADouble"), + "Check column ADouble has dimension 2... "); + + test_ivalue(5, cpl_table_get_column_dimension(table, "ADouble", 0), + "Check column ADouble dimension 1 is 5... "); + test_ivalue(6, cpl_table_get_column_dimension(table, "ADouble", 1), + "Check column ADouble dimension 2 is 6... "); + + // FIXME: CPL_IO_APPEND is supported now. Adjust test case accordingly + //test_failure(cpl_table_save(table, NULL, NULL, BASE "23.fits", + // CPL_IO_APPEND), CPL_ERROR_UNSUPPORTED_MODE, + // "Verify failure with CPL_IO_APPEND"); + //cpl_test_fits(BASE "23.fits"); + + cpl_table_delete(table); + + + /*********************************************** + * Testing all types of casting + ***********************************************/ + + table = cpl_table_new(10); + + cpl_table_new_column(table, "double", CPL_TYPE_DOUBLE); + for (i = 0; i < 10; i++) { + if (i != 5) { /* Leave intentionally an invalid value */ + error = cpl_table_set_double(table, "double", i, i / 3.); + cpl_test_eq_error(error, CPL_ERROR_NONE); + } + } + + /* + * Case 7: + * from_name type = CPL_TYPE_XXX + * specified type = CPL_TYPE_YYY + * to_name type = CPL_TYPE_YYY + */ + + cpl_table_cast_column(table, "double", "float_from_double", CPL_TYPE_FLOAT); + cpl_table_cast_column(table, "double", "int_from_double", CPL_TYPE_INT); + cpl_table_cast_column(table, "int_from_double", "double_from_int", + CPL_TYPE_DOUBLE); + cpl_table_cast_column(table, "int_from_double", "float_from_int", + CPL_TYPE_FLOAT); + cpl_table_cast_column(table, "float_from_double", "double_from_float", + CPL_TYPE_DOUBLE); + cpl_table_cast_column(table, "float_from_double", "int_from_float", + CPL_TYPE_INT); + + for (i = 0; i < 10; i++) { + if (i != 5) { + test_fvalue(i / 3., 0.00001, + cpl_table_get_float(table, "float_from_double", i, + &null), + "Invalid cast from double to float"); + cpl_test_zero(null); + test_ivalue(i / 3, + cpl_table_get_int(table, "int_from_double", i, &null), + "Invalid cast from double to int"); + cpl_test_zero(null); + test_fvalue(i / 3, 0.00001, + cpl_table_get_double(table, "double_from_int", i, + &null), + "Invalid cast from int to double"); + cpl_test_zero(null); + test_fvalue(i / 3, 0.00001, + cpl_table_get_float(table, "float_from_int", i, &null), + "Invalid cast from int to float"); + cpl_test_zero(null); + test_fvalue(i / 3., 0.00001, + cpl_table_get_double(table, "double_from_float", i, + &null), + "Invalid cast from float to double"); + cpl_test_zero(null); + test_ivalue(i / 3, + cpl_table_get_int(table, "int_from_float", i, &null), + "Invalid cast from float to int"); + cpl_test_zero(null); + } + else { + test_ivalue(0, cpl_table_is_valid(table, "float_from_double", i), + "Invalid cast from double to float"); + test_ivalue(0, cpl_table_is_valid(table, "int_from_double", i), + "Invalid cast from double to int"); + test_ivalue(0, cpl_table_is_valid(table, "double_from_int", i), + "Invalid cast from int to double"); + test_ivalue(0, cpl_table_is_valid(table, "float_from_int", i), + "Invalid cast from int to float"); + test_ivalue(0, cpl_table_is_valid(table, "double_from_float", i), + "Invalid cast from float to double"); + test_ivalue(0, cpl_table_is_valid(table, "int_from_float", i), + "Invalid cast from float to int"); + } + } + + /* In place: */ + + cpl_table_cast_column(table, "double_from_int", NULL, CPL_TYPE_INT); + cpl_table_cast_column(table, "float_from_int", NULL, CPL_TYPE_INT); + cpl_table_cast_column(table, "double_from_float", NULL, CPL_TYPE_FLOAT); + cpl_table_cast_column(table, "int_from_float", NULL, CPL_TYPE_FLOAT); + cpl_table_cast_column(table, "float_from_double", NULL, CPL_TYPE_DOUBLE); + cpl_table_cast_column(table, "int_from_double", NULL, CPL_TYPE_DOUBLE); + + for (i = 0; i < 10; i++) { + if (i != 5) { + test_ivalue(i / 3, + cpl_table_get_int(table, "double_from_int", i, &null), + "Invalid in-place cast from double to int"); + cpl_test_zero(null); + test_ivalue(i / 3, + cpl_table_get_int(table, "float_from_int", i, &null), + "Invalid in-place cast from float to int"); + cpl_test_zero(null); + test_fvalue(i / 3., 0.00001, + cpl_table_get_float(table, "double_from_float", i, + &null), + "Invalid in-place cast from double to float"); + cpl_test_zero(null); + test_fvalue(i / 3, 0.00001, + cpl_table_get_float(table, "int_from_float", i, &null), + "Invalid in-place cast from int to float"); + cpl_test_zero(null); + test_fvalue(i / 3., 0.00001, + cpl_table_get_double(table, "float_from_double", i, + &null), + "Invalid in-place cast from float to double"); + cpl_test_zero(null); + test_fvalue(i / 3, 0.00001, + cpl_table_get_double(table, "int_from_double", i, + &null), + "Invalid in-place cast from int to double"); + cpl_test_zero(null); + } + else { + test_ivalue(0, cpl_table_is_valid(table, "double_from_int", i), + "Invalid in-place cast from double to int"); + test_ivalue(0, cpl_table_is_valid(table, "float_from_int", i), + "Invalid in-place cast from float to int"); + test_ivalue(0, cpl_table_is_valid(table, "double_from_float", i), + "Invalid in-place cast from double to float"); + test_ivalue(0, cpl_table_is_valid(table, "int_from_float", i), + "Invalid in-place cast from int to float"); + test_ivalue(0, cpl_table_is_valid(table, "float_from_double", i), + "Invalid in-place cast from float to double"); + test_ivalue(0, cpl_table_is_valid(table, "int_from_double", i), + "Invalid in-place cast from int to double"); + } + } + + + /* + * Case 1: + * from_name type = CPL_TYPE_XXX + * specified type = CPL_TYPE_XXX + * to_name type = CPL_TYPE_XXX + * + * (Note that now double_from_float is float, and double_from_int is int) + */ + + cpl_table_cast_column(table, "double", "double_from_double", + CPL_TYPE_DOUBLE); + cpl_table_cast_column(table, "double_from_float", "float_from_float", + CPL_TYPE_FLOAT); + cpl_table_cast_column(table, "double_from_int", "int_from_int", + CPL_TYPE_INT); + + for (i = 0; i < 10; i++) { + if (i != 5) { + test_ivalue(i / 3, + cpl_table_get_int(table, "int_from_int", i, &null), + "Invalid cast from int to int"); + cpl_test_zero(null); + test_fvalue(i / 3., 0.00001, + cpl_table_get_float(table, "float_from_float", i, + &null), + "Invalid cast from float to float"); + cpl_test_zero(null); + test_fvalue(i / 3., 0.00001, + cpl_table_get_double(table, "double_from_double", i, + &null), + "Invalid cast from double to double"); + cpl_test_zero(null); + } + else { + test_ivalue(0, cpl_table_is_valid(table, "int_from_int", i), + "Invalid cast from int to int"); + test_ivalue(0, cpl_table_is_valid(table, "float_from_float", i), + "Invalid cast from float to float"); + test_ivalue(0, cpl_table_is_valid(table, "double_from_double", i), + "Invalid cast from double to double"); + } + } + + /* In place: */ + + cpl_table_cast_column(table, "double_from_double", NULL, CPL_TYPE_DOUBLE); + cpl_table_cast_column(table, "float_from_float", NULL, CPL_TYPE_FLOAT); + cpl_table_cast_column(table, "int_from_int", NULL, CPL_TYPE_INT); + + for (i = 0; i < 10; i++) { + if (i != 5) { + test_ivalue(i / 3, + cpl_table_get_int(table, "int_from_int", i, &null), + "Invalid cast from int to int"); + cpl_test_zero(null); + test_fvalue(i / 3., 0.00001, + cpl_table_get_float(table, "float_from_float", i, + &null), + "Invalid cast from float to float"); + cpl_test_zero(null); + test_fvalue(i / 3., 0.00001, + cpl_table_get_double(table, "double_from_double", i, + &null), + "Invalid cast from double to double"); + cpl_test_zero(null); + } + else { + test_ivalue(0, cpl_table_is_valid(table, "int_from_int", i), + "Invalid cast from int to int"); + test_ivalue(0, cpl_table_is_valid(table, "float_from_float", i), + "Invalid cast from float to float"); + test_ivalue(0, cpl_table_is_valid(table, "double_from_double", i), + "Invalid cast from double to double"); + } + } + + + /* + * RESET: start from a new table + */ + + cpl_table_delete(table); + + table = cpl_table_new(10); + + cpl_table_new_column(table, "double", CPL_TYPE_DOUBLE); + for (i = 0; i < 10; i++) { + if (i != 5) { /* Leave intentionally an invalid value */ + error = cpl_table_set_double(table, "double", i, i / 3.); + cpl_test_eq_error(error, CPL_ERROR_NONE); + } + } + + cpl_table_cast_column(table, "double", "float", CPL_TYPE_FLOAT); + cpl_table_cast_column(table, "double", "int", CPL_TYPE_INT); + + + /* + * Case 11: + * from_name type = CPL_TYPE_XXX + * specified type = CPL_TYPE_YYY | CPL_TYPE_POINTER + * to_name type = CPL_TYPE_YYY | CPL_TYPE_POINTER (depth = 1) + */ + + cpl_table_cast_column(table, "double", "float1_from_double", + CPL_TYPE_FLOAT | CPL_TYPE_POINTER); + cpl_table_cast_column(table, "double", "int1_from_double", + CPL_TYPE_INT | CPL_TYPE_POINTER); + cpl_table_cast_column(table, "int", "double1_from_int", + CPL_TYPE_DOUBLE | CPL_TYPE_POINTER); + cpl_table_cast_column(table, "int", "float1_from_int", + CPL_TYPE_FLOAT | CPL_TYPE_POINTER); + cpl_table_cast_column(table, "float", "double1_from_float", + CPL_TYPE_DOUBLE | CPL_TYPE_POINTER); + cpl_table_cast_column(table, "float", "int1_from_float", + CPL_TYPE_INT | CPL_TYPE_POINTER); + + for (i = 0; i < 10; i++) { + if (i != 5) { + test_fvalue(i / 3., 0.00001, + cpl_array_get_float( + cpl_table_get_array(table, "float1_from_double", i), + 0, NULL), + "Invalid cast from double to float1"); + test_ivalue(i / 3, + cpl_array_get_int( + cpl_table_get_array(table, "int1_from_double", i), + 0, NULL), + "Invalid cast from double to int1"); + test_fvalue(i / 3, 0.00001, + cpl_array_get_double( + cpl_table_get_array(table, "double1_from_int", i), + 0, NULL), + "Invalid cast from int to double1"); + test_fvalue(i / 3, 0.00001, + cpl_array_get_float( + cpl_table_get_array(table, "float1_from_int", i), 0, + NULL), + "Invalid cast from int to float1"); + test_fvalue(i / 3., 0.00001, + cpl_array_get_double( + cpl_table_get_array(table, "double1_from_float", i), + 0, NULL), + "Invalid cast from float to double1"); + test_ivalue(i / 3, + cpl_array_get_int(cpl_table_get_array(table, + "int1_from_float", + i), + 0, NULL), + "Invalid cast from float to int1"); + } + else { + test_ivalue(0, cpl_table_is_valid(table, "float1_from_double", i), + "Invalid cast from double to float1"); + test_ivalue(0, cpl_table_is_valid(table, "int1_from_double", i), + "Invalid cast from double to int1"); + test_ivalue(0, cpl_table_is_valid(table, "double1_from_int", i), + "Invalid cast from int to double1"); + test_ivalue(0, cpl_table_is_valid(table, "float1_from_int", i), + "Invalid cast from int to float1"); + test_ivalue(0, cpl_table_is_valid(table, "double1_from_float", i), + "Invalid cast from float to double1"); + test_ivalue(0, cpl_table_is_valid(table, "int1_from_float", i), + "Invalid cast from float to int1"); + } + } + + + /* + * Case 10 in-place: + * from_name type = CPL_TYPE_XXX | CPL_TYPE_POINTER (depth = 1) + * specified type = CPL_TYPE_YYY + * to_name type = CPL_TYPE_YYY + */ + + cpl_table_cast_column(table, "float1_from_double", NULL, CPL_TYPE_DOUBLE); + cpl_table_cast_column(table, "int1_from_double", NULL, CPL_TYPE_DOUBLE); + cpl_table_cast_column(table, "double1_from_int", NULL, CPL_TYPE_INT); + cpl_table_cast_column(table, "float1_from_int", NULL, CPL_TYPE_INT); + cpl_table_cast_column(table, "double1_from_float", NULL, CPL_TYPE_FLOAT); + cpl_table_cast_column(table, "int1_from_float", NULL, CPL_TYPE_FLOAT); + + for (i = 0; i < 10; i++) { + if (i != 5) { + test_fvalue(i / 3., 0.00001, + cpl_table_get_double(table, "float1_from_double", i, + &null), + "Invalid cast from float1 to double"); + cpl_test_zero(null); + test_fvalue(i / 3, 0.00001, + cpl_table_get_double(table, "int1_from_double", i, + &null), + "Invalid cast from int1 to double"); + cpl_test_zero(null); + test_ivalue(i / 3, + cpl_table_get_int(table, "double1_from_int", i, &null), + "Invalid cast from double1 to int"); + cpl_test_zero(null); + test_fvalue(i / 3, 0.00001, + cpl_table_get_int(table, "float1_from_int", i, &null), + "Invalid cast from float1 to int"); + cpl_test_zero(null); + test_fvalue(i / 3., 0.00001, + cpl_table_get_float(table, "double1_from_float", i, + &null), + "Invalid cast from double1 to float"); + cpl_test_zero(null); + test_ivalue(i / 3, + cpl_table_get_float(table, "int1_from_float", i, &null), + "Invalid cast from int1 to float"); + cpl_test_zero(null); + } + else { + test_ivalue(0, cpl_table_is_valid(table, "float1_from_double", i), + "Invalid cast from float1 to double"); + test_ivalue(0, cpl_table_is_valid(table, "int1_from_double", i), + "Invalid cast from int1 to double"); + test_ivalue(0, cpl_table_is_valid(table, "double1_from_int", i), + "Invalid cast from double1 to int"); + test_ivalue(0, cpl_table_is_valid(table, "float1_from_int", i), + "Invalid cast from float1 to int"); + test_ivalue(0, cpl_table_is_valid(table, "double1_from_float", i), + "Invalid cast from double1 to float"); + test_ivalue(0, cpl_table_is_valid(table, "int1_from_float", i), + "Invalid cast from int1 to float"); + } + } + + + /* + * RESET: start from a new table + */ + + cpl_table_delete(table); + + table = cpl_table_new(10); + + cpl_table_new_column(table, "double", CPL_TYPE_DOUBLE); + for (i = 0; i < 10; i++) { + if (i != 5) { /* Leave intentionally an invalid value */ + error = cpl_table_set_double(table, "double", i, i / 3.); + cpl_test_eq_error(error, CPL_ERROR_NONE); + } + } + + cpl_table_duplicate_column(table, "double_to_float1", table, "double"); + cpl_table_duplicate_column(table, "double_to_int1", table, "double"); + cpl_table_cast_column(table, "double", "float", CPL_TYPE_FLOAT); + cpl_table_duplicate_column(table, "float_to_double1", table, "float"); + cpl_table_duplicate_column(table, "float_to_int1", table, "float"); + cpl_table_cast_column(table, "double", "int", CPL_TYPE_INT); + cpl_table_duplicate_column(table, "int_to_double1", table, "int"); + cpl_table_duplicate_column(table, "int_to_float1", table, "int"); + + /* + * Case 11, in-place: + * from_name type = CPL_TYPE_XXX + * specified type = CPL_TYPE_YYY | CPL_TYPE_POINTER + * to_name type = CPL_TYPE_YYY | CPL_TYPE_POINTER (depth = 1) + */ + + cpl_table_cast_column(table, "double_to_float1", NULL, + CPL_TYPE_FLOAT | CPL_TYPE_POINTER); + cpl_table_cast_column(table, "double_to_int1", NULL, + CPL_TYPE_INT | CPL_TYPE_POINTER); + cpl_table_cast_column(table, "int_to_double1", NULL, + CPL_TYPE_DOUBLE | CPL_TYPE_POINTER); + cpl_table_cast_column(table, "int_to_float1", NULL, + CPL_TYPE_FLOAT | CPL_TYPE_POINTER); + cpl_table_cast_column(table, "float_to_double1", NULL, + CPL_TYPE_DOUBLE | CPL_TYPE_POINTER); + cpl_table_cast_column(table, "float_to_int1", NULL, + CPL_TYPE_INT | CPL_TYPE_POINTER); + + for (i = 0; i < 10; i++) { + if (i != 5) { + test_fvalue(i / 3., 0.00001, + cpl_array_get_float( + cpl_table_get_array(table, "double_to_float1", i), + 0, NULL), + "Invalid cast from double to float1"); + test_ivalue(i / 3, + cpl_array_get_int(cpl_table_get_array(table, + "double_to_int1", + i), + 0, NULL), + "Invalid cast from double to int1"); + test_fvalue(i / 3, 0.00001, + cpl_array_get_double( + cpl_table_get_array(table, "int_to_double1", i), 0, + NULL), + "Invalid cast from int to double1"); + test_fvalue(i / 3, 0.00001, + cpl_array_get_float(cpl_table_get_array(table, + "int_to_float1", + i), + 0, NULL), + "Invalid cast from int to float1"); + test_fvalue(i / 3., 0.00001, + cpl_array_get_double( + cpl_table_get_array(table, "float_to_double1", i), + 0, NULL), + "Invalid cast from float to double1"); + test_ivalue(i / 3, + cpl_array_get_int(cpl_table_get_array(table, + "float_to_int1", + i), + 0, NULL), + "Invalid cast from float to int1"); + } + else { + test_ivalue(0, cpl_table_is_valid(table, "double_to_float1", i), + "Invalid cast from double to float1"); + test_ivalue(0, cpl_table_is_valid(table, "double_to_int1", i), + "Invalid cast from double to int1"); + test_ivalue(0, cpl_table_is_valid(table, "int_to_double1", i), + "Invalid cast from int to double1"); + test_ivalue(0, cpl_table_is_valid(table, "int_to_float1", i), + "Invalid cast from int to float1"); + test_ivalue(0, cpl_table_is_valid(table, "float_to_double1", i), + "Invalid cast from float to double1"); + test_ivalue(0, cpl_table_is_valid(table, "float_to_int1", i), + "Invalid cast from float to int1"); + } + } + + /* + * RESET: start from a new table + */ + + cpl_table_delete(table); + + table = cpl_table_new(10); + + cpl_table_new_column(table, "double", CPL_TYPE_DOUBLE); + for (i = 0; i < 10; i++) { + if (i != 5) { /* Leave intentionally an invalid value */ + error = cpl_table_set_double(table, "double", i, i / 3.); + cpl_test_eq_error(error, CPL_ERROR_NONE); + } + } + + cpl_table_cast_column(table, "double", "float", CPL_TYPE_FLOAT); + cpl_table_cast_column(table, "double", "int", CPL_TYPE_INT); + + /* + * Case 5 & 6: + * from_name type = CPL_TYPE_XXX + * specified type = CPL_TYPE_XXX | CPL_TYPE_POINTER + * to_name type = CPL_TYPE_XXX | CPL_TYPE_POINTER (depth = 1) + * + * from_name type = CPL_TYPE_XXX + * specified type = CPL_TYPE_POINTER + * to_name type = CPL_TYPE_XXX | CPL_TYPE_POINTER (depth = 1) + */ + + cpl_table_cast_column(table, "double", "double1", CPL_TYPE_POINTER); + cpl_table_cast_column(table, "float", "float1", CPL_TYPE_POINTER); + cpl_table_cast_column(table, "int", "int1", CPL_TYPE_POINTER); + + for (i = 0; i < 10; i++) { + if (i != 5) { + test_fvalue(i / 3., 0.00001, + cpl_array_get_float(cpl_table_get_array(table, "float1", + i), + 0, NULL), + "Invalid cast from float to float1"); + test_ivalue(i / 3, + cpl_array_get_int(cpl_table_get_array(table, "int1", i), + 0, NULL), + "Invalid cast from int to int1"); + test_fvalue(i / 3., 0.00001, + cpl_array_get_double(cpl_table_get_array(table, + "double1", i), + 0, NULL), + "Invalid cast from double to double1"); + } + else { + test_ivalue(0, cpl_table_is_valid(table, "float1", i), + "Invalid cast from float to float1"); + test_ivalue(0, cpl_table_is_valid(table, "int1", i), + "Invalid cast from int to int1"); + test_ivalue(0, cpl_table_is_valid(table, "double1", i), + "Invalid cast from double to double1"); + } + } + + + /* + * RESET: start from a new table + */ + + cpl_table_delete(table); + + table = cpl_table_new(10); + + cpl_table_new_column(table, "double", CPL_TYPE_DOUBLE); + for (i = 0; i < 10; i++) { + if (i != 5) { /* Leave intentionally an invalid value */ + error = cpl_table_set_double(table, "double", i, i / 3.); + cpl_test_eq_error(error, CPL_ERROR_NONE); + } + } + + cpl_table_cast_column(table, "double", "float", CPL_TYPE_FLOAT); + cpl_table_cast_column(table, "double", "int", CPL_TYPE_INT); + + /* + * Case 5 in-place: + * from_name type = CPL_TYPE_XXX + * specified type = CPL_TYPE_POINTER + * to_name type = CPL_TYPE_XXX | CPL_TYPE_POINTER (depth = 1) + */ + + cpl_table_cast_column(table, "double", NULL, CPL_TYPE_POINTER); + cpl_table_cast_column(table, "float", NULL, CPL_TYPE_POINTER); + cpl_table_cast_column(table, "int", NULL, CPL_TYPE_POINTER); + + for (i = 0; i < 10; i++) { + if (i != 5) { + test_fvalue(i / 3., 0.00001, + cpl_array_get_float(cpl_table_get_array(table, "float", + i), + 0, NULL), + "Invalid in-place cast from float to float1"); + test_ivalue(i / 3, + cpl_array_get_int(cpl_table_get_array(table, "int", i), + 0, NULL), + "Invalid in-place cast from int to int1"); + test_fvalue(i / 3., 0.00001, + cpl_array_get_double(cpl_table_get_array(table, + "double", i), + 0, NULL), + "Invalid in-place cast from double to double1"); + } + else { + test_ivalue(0, cpl_table_is_valid(table, "float", i), + "Invalid in-place cast from float to float1"); + test_ivalue(0, cpl_table_is_valid(table, "int", i), + "Invalid in-place cast from int to int1"); + test_ivalue(0, cpl_table_is_valid(table, "double", i), + "Invalid in-place cast from double to double1"); + } + } + + /* + * RESET: start from a new table + */ + + cpl_table_delete(table); + + table = cpl_table_new(10); + + cpl_table_new_column_array(table, "double", + CPL_TYPE_DOUBLE | CPL_TYPE_POINTER, 2); + + array = cpl_array_new(2, CPL_TYPE_DOUBLE); + + for (i = 0; i < 2; i++) { + cpl_array_set_double(array, i, (i + 5) / 3.); + } + + for (i = 0; i < 10; i++) { + if (i != 5) { /* Leave intentionally an invalid value */ + error = cpl_table_set_array(table, "double", i, array); + cpl_test_eq_error(error, CPL_ERROR_NONE); + } + } + + cpl_array_delete(array); + + cpl_table_duplicate_column(table, "double1", table, "double"); + + /* + * Case 8 & 9: + * from_name type = CPL_TYPE_XXX | CPL_TYPE_POINTER + * specified type = CPL_TYPE_YYY | CPL_TYPE_POINTER + * to_name type = CPL_TYPE_YYY | CPL_TYPE_POINTER + */ + + cpl_table_cast_column(table, "double", "float", + CPL_TYPE_FLOAT | CPL_TYPE_POINTER); + cpl_table_cast_column(table, "double", "float1", CPL_TYPE_FLOAT); + + for (i = 0; i < 10; i++) { + if (i != 5) { + test_fvalue(5 / 3., 0.00001, + cpl_array_get_float(cpl_table_get_array(table, "float", + i), + 0, NULL), + "Invalid cast from double2 to float2"); + test_fvalue(6 / 3., 0.00001, + cpl_array_get_float(cpl_table_get_array(table, "float", + i), + 1, NULL), + "Invalid cast from double2 to float2"); + test_fvalue(5 / 3., 0.00001, + cpl_array_get_float(cpl_table_get_array(table, "float1", + i), + 0, NULL), + "Invalid cast from double2 to float2"); + test_fvalue(6 / 3., 0.00001, + cpl_array_get_float(cpl_table_get_array(table, "float1", + i), + 1, NULL), + "Invalid cast from double2 to float2"); + } + else { + test_ivalue(0, cpl_table_is_valid(table, "float1", i), + "Invalid cast from double2 to float2"); + } + } + + + /* In place: */ - cpl_msg_info(cpl_func, "Now delete last 2 rows:\n\n"); + cpl_table_cast_column(table, "double", NULL, + CPL_TYPE_FLOAT | CPL_TYPE_POINTER); + cpl_table_cast_column(table, "double1", NULL, CPL_TYPE_FLOAT); + + for (i = 0; i < 10; i++) { + if (i != 5) { + test_fvalue(5 / 3., 0.00001, + cpl_array_get_float(cpl_table_get_array(table, "double", + i), + 0, NULL), + "Invalid in-place cast from double2 to float2"); + test_fvalue(6 / 3., 0.00001, + cpl_array_get_float(cpl_table_get_array(table, "double", + i), + 1, NULL), + "Invalid in-place cast from double2 to float2"); + test_fvalue(5 / 3., 0.00001, + cpl_array_get_float(cpl_table_get_array(table, + "double1", i), + 0, NULL), + "Invalid in-place cast from double2 to float2"); + test_fvalue(6 / 3., 0.00001, + cpl_array_get_float(cpl_table_get_array(table, + "double1", i), + 1, NULL), + "Invalid in-place cast from double2 to float2"); + } + else { + test_ivalue(0, cpl_table_is_valid(table, "float1", i), + "Invalid in-place cast from doueble1 to float1"); + } + } -#endif + cpl_table_delete(table); - copia = cpl_table_duplicate(table); - cpl_table_and_selected_window(copia, 5, 2); - test_ivalue(2, cpl_table_count_selected(copia), - "Check last 2 rows selected... "); - cpl_table_erase_selected(copia); -#ifdef VERBOSE - cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), stream); -#endif - test_ivalue(5, cpl_table_get_nrow(copia), - "Check length erase last 2 rows... "); - cpl_table_delete(copia); + /* + * Testing comparison between string columns. + */ -#ifdef VERBOSE + table = cpl_table_new(5); + cpl_table_new_column(table, "stringa", CPL_TYPE_STRING); + cpl_table_new_column(table, "stringb", CPL_TYPE_STRING); - cpl_msg_info(cpl_func, "Now delete rows from 2 to 3:\n\n"); + error = cpl_table_set_string(table, "stringa", 0, "bb"); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_set_string(table, "stringa", 1, "bb"); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_set_string(table, "stringa", 2, "bb"); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_set_string(table, "stringa", 3, "bb"); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_set_string(table, "stringa", 4, "bb"); + cpl_test_eq_error(error, CPL_ERROR_NONE); -#endif + error = cpl_table_set_string(table, "stringb", 0, "a"); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_set_string(table, "stringb", 1, "ba"); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_set_string(table, "stringb", 2, "bb"); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_set_string(table, "stringb", 3, "bbb"); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_set_string(table, "stringb", 4, "bc"); + cpl_test_eq_error(error, CPL_ERROR_NONE); - copia = cpl_table_duplicate(table); - cpl_table_and_selected_window(copia, 2, 2); - test_ivalue(2, cpl_table_count_selected(copia), - "Check middle 2 rows selected... "); - cpl_table_erase_selected(copia); -#ifdef VERBOSE - cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), stream); -#endif - test_ivalue(5, cpl_table_get_nrow(copia), - "Check length erase rows from 2 to 3... "); - cpl_table_delete(copia); + /* + * And equal to + */ -#ifdef VERBOSE + test_ivalue(1, + cpl_table_and_selected(table, "stringa", CPL_EQUAL_TO, + "stringb"), + "Invalid string comparison (and equal to)"); + array = cpl_table_where_selected(table); + test_ivalue(1, cpl_array_get_size(array), "Check how many equal to..."); + test_ivalue(2, cpl_array_get_cplsize(array, 0, &null), + "Check where equal to..."); + cpl_test_zero(null); + cpl_array_delete(array); + cpl_table_select_all(table); - cpl_msg_info(cpl_func, "Now delete rows from 1 to 3 and row 6:\n\n"); + /* + * And not equal to + */ -#endif + cpl_table_select_all(table); + test_ivalue(4, + cpl_table_and_selected(table, "stringa", CPL_NOT_EQUAL_TO, + "stringb"), + "Invalid string comparison (and not equal to)"); + array = cpl_table_where_selected(table); + test_ivalue(4, cpl_array_get_size(array), "Check how many not equal to..."); + test_ivalue(0, cpl_array_get_cplsize(array, 0, &null), + "Check where not equal to..."); + cpl_test_zero(null); + test_ivalue(1, cpl_array_get_cplsize(array, 1, &null), + "Check where not equal to..."); + cpl_test_zero(null); + test_ivalue(3, cpl_array_get_cplsize(array, 2, &null), + "Check where not equal to..."); + cpl_test_zero(null); + test_ivalue(4, cpl_array_get_cplsize(array, 3, &null), + "Check where not equal to..."); + cpl_test_zero(null); + cpl_array_delete(array); - copia = cpl_table_duplicate(table); - cpl_table_and_selected_window(copia, 1, 3); - cpl_table_or_selected_window(copia, 6, 1); - test_ivalue(4, cpl_table_count_selected(copia), - "Check rows 1 to 3 and row 6 rejected... "); - cpl_table_erase_selected(copia); -#ifdef VERBOSE - cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), stream); -#endif - test_ivalue(3, cpl_table_get_nrow(copia), - "Check length erase rows from 1 to 3 and row 6... "); - cpl_table_delete(copia); - - /* Erase only invalid elements */ - copia = cpl_table_duplicate(table); - for (i = 0; i < nrows; i++) { - error = cpl_table_set_invalid(copia, "Int", i); - cpl_test_eq_error(error, CPL_ERROR_NONE); - } + /* + * And greater than + */ - cpl_table_unselect_row(copia, nrows-1); + cpl_table_select_all(table); + test_ivalue(2, + cpl_table_and_selected(table, "stringa", CPL_GREATER_THAN, + "stringb"), + "Invalid string comparison (and greater than)"); + array = cpl_table_where_selected(table); + test_ivalue(2, cpl_array_get_size(array), "Check how many greater than..."); + test_ivalue(0, cpl_array_get_cplsize(array, 0, &null), + "Check where greater than..."); + cpl_test_zero(null); + test_ivalue(1, cpl_array_get_cplsize(array, 1, &null), + "Check where greater than..."); + cpl_test_zero(null); + cpl_array_delete(array); - cpl_table_erase_selected(copia); -#ifdef VERBOSE - cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), stream); -#endif - test_ivalue(1, cpl_table_get_nrow(copia), - "Check length erase last row, only invalid values... "); + /* + * And not greater than + */ - cpl_table_delete(copia); + cpl_table_select_all(table); + test_ivalue(3, + cpl_table_and_selected(table, "stringa", CPL_NOT_GREATER_THAN, + "stringb"), + "Invalid string comparison (and not greater than)"); + array = cpl_table_where_selected(table); + test_ivalue(3, cpl_array_get_size(array), + "Check how many not greater than..."); + test_ivalue(2, cpl_array_get_cplsize(array, 0, &null), + "Check where not greater than..."); + cpl_test_zero(null); + test_ivalue(3, cpl_array_get_cplsize(array, 1, &null), + "Check where not greater than..."); + cpl_test_zero(null); + test_ivalue(4, cpl_array_get_cplsize(array, 2, &null), + "Check where not greater than..."); + cpl_test_zero(null); + cpl_array_delete(array); - /* Erase array column with valid/invalid values */ - copia = cpl_table_duplicate(table); - - cpl_table_cast_column(copia, "Int", "Double", CPL_TYPE_DOUBLE); - - test(cpl_table_new_column_array(copia, "ADouble", - CPL_TYPE_DOUBLE | CPL_TYPE_POINTER, 2), - "Creating the ArrayDouble column... "); - - array = cpl_array_new(2, CPL_TYPE_DOUBLE); - test(cpl_table_set_array(copia, "ADouble", 1, array), - "Set a valid array to ADouble 1... "); - test(cpl_table_set_array(copia, "ADouble", 2, array), - "Set a valid array to ADouble 2... "); - cpl_array_delete(array); - - cpl_table_unselect_row(copia, 0); - cpl_table_unselect_row(copia, 2); - error = cpl_table_set_invalid(copia, "Int", 6); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_set_invalid(copia, "Int2", 0); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_set_invalid(copia, "Int2", 1); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_set_invalid(copia, "Double", 0); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_set_invalid(copia, "Double", 1); - cpl_test_eq_error(error, CPL_ERROR_NONE); + /* + * And less than + */ - cpl_table_erase_selected(copia); -#ifdef VERBOSE - cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), stream); -#endif - test_ivalue(2, cpl_table_get_nrow(copia), - "Check length erase valid/invalid values... "); - test_ivalue(0, cpl_table_is_valid(copia, "Int2", 0), - "Check that first element of \"Int2\" is still NULL... "); - test_ivalue(1, cpl_table_is_valid(copia, "Int2", 1), - "Check that first element of \"Int2\" is now valid... "); - - cpl_table_unselect_row(copia, 0); - cpl_table_unselect_row(copia, 1); - cpl_table_erase_selected(copia); - test_ivalue(2, cpl_table_count_selected(copia), - "Check that rows are selected... "); - - cpl_table_delete(copia); - - cpl_table_delete(table); - - /* - * Select invalid rows - */ - nrows = 3; - - table = cpl_table_new(nrows); - cpl_table_new_column(table, "Int", CPL_TYPE_INT); - cpl_table_new_column(table, "String", CPL_TYPE_STRING); - - error = cpl_table_set_int(table, "Int", 0, 18); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_set_int(table, "Int", 1, 18); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_set_invalid(table, "Int", 2); - cpl_test_eq_error(error, CPL_ERROR_NONE); - - error = cpl_table_set_string(table, "String", 0, "hello"); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_set_string(table, "String", 1, "hello"); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_set_invalid(table, "String", 2); - cpl_test_eq_error(error, CPL_ERROR_NONE); + cpl_table_select_all(table); + test_ivalue(2, + cpl_table_and_selected(table, "stringa", CPL_LESS_THAN, + "stringb"), + "Invalid string comparison (and less than)"); + array = cpl_table_where_selected(table); + test_ivalue(2, cpl_array_get_size(array), "Check how many less than..."); + test_ivalue(3, cpl_array_get_cplsize(array, 0, &null), + "Check where less than..."); + cpl_test_zero(null); + test_ivalue(4, cpl_array_get_cplsize(array, 1, &null), + "Check where less than..."); + cpl_test_zero(null); + cpl_array_delete(array); -#ifdef VERBOSE - cpl_table_dump(table, 0, cpl_table_get_nrow(table), stream); -#endif + /* + * And not less than + */ - cpl_table_select_all(table); + cpl_table_select_all(table); + test_ivalue(3, + cpl_table_and_selected(table, "stringa", CPL_NOT_LESS_THAN, + "stringb"), + "Invalid string comparison (and not less than)"); + array = cpl_table_where_selected(table); + test_ivalue(3, cpl_array_get_size(array), + "Check how many not less than..."); + test_ivalue(0, cpl_array_get_cplsize(array, 0, &null), + "Check where not less than..."); + cpl_test_zero(null); + test_ivalue(1, cpl_array_get_cplsize(array, 1, &null), + "Check where not less than..."); + cpl_test_zero(null); + test_ivalue(2, cpl_array_get_cplsize(array, 2, &null), + "Check where not less than..."); + cpl_test_zero(null); + cpl_array_delete(array); -/* - * This test (next 4 calls) is related to ticket DFS03619 - */ + /* + * Or equal to + */ - test_ivalue(1, cpl_table_and_selected_invalid(table, "String"), - "Check number of selected rows (string)... "); - test_ivalue(0, cpl_table_is_selected(table, 0), - "Check that row is not selected..."); - test_ivalue(0, cpl_table_is_selected(table, 1), - "Check that row is not selected..."); - test_ivalue(1, cpl_table_is_selected(table, 2), - "Check that row is selected..."); - - cpl_table_select_all(table); - test_ivalue(1, cpl_table_and_selected_invalid(table, "Int"), - "Check number of selected rows (integer)... "); - test_ivalue(0, cpl_table_is_selected(table, 0), - "Check that row is not selected..."); - test_ivalue(0, cpl_table_is_selected(table, 1), - "Check that row is not selected..."); - test_ivalue(1, cpl_table_is_selected(table, 2), - "Check that row is selected..."); - - cpl_table_delete(table); - - /* - * Test case: dividing a double column by integer - */ + cpl_table_unselect_all(table); + test_ivalue(1, + cpl_table_or_selected(table, "stringa", CPL_EQUAL_TO, + "stringb"), + "Invalid string comparison (or equal to)"); + array = cpl_table_where_selected(table); + test_ivalue(1, cpl_array_get_size(array), "Check how many equal to..."); + test_ivalue(2, cpl_array_get_cplsize(array, 0, &null), + "Check where equal to..."); + cpl_test_zero(null); + cpl_array_delete(array); + cpl_table_select_all(table); - nrows = 100; + /* + * Or not equal to + */ - table = cpl_table_new(nrows); - cpl_table_new_column(table, "Int", CPL_TYPE_INT); + cpl_table_unselect_all(table); + test_ivalue(4, + cpl_table_or_selected(table, "stringa", CPL_NOT_EQUAL_TO, + "stringb"), + "Invalid string comparison (or not equal to)"); + array = cpl_table_where_selected(table); + test_ivalue(4, cpl_array_get_size(array), "Check how many not equal to..."); + test_ivalue(0, cpl_array_get_cplsize(array, 0, &null), + "Check where not equal to..."); + cpl_test_zero(null); + test_ivalue(1, cpl_array_get_cplsize(array, 1, &null), + "Check where not equal to..."); + cpl_test_zero(null); + test_ivalue(3, cpl_array_get_cplsize(array, 2, &null), + "Check where not equal to..."); + cpl_test_zero(null); + test_ivalue(4, cpl_array_get_cplsize(array, 3, &null), + "Check where not equal to..."); + cpl_test_zero(null); + cpl_array_delete(array); - for (i = 0; i < nrows; i++) - error = cpl_table_set_int(table, "Int", i, i + 1); - cpl_test_eq_error(error, CPL_ERROR_NONE); + /* + * Or greater than + */ - cpl_table_cast_column(table, "Int", "Double", CPL_TYPE_DOUBLE); + cpl_table_unselect_all(table); + test_ivalue(2, + cpl_table_or_selected(table, "stringa", CPL_GREATER_THAN, + "stringb"), + "Invalid string comparison (or greater than)"); + array = cpl_table_where_selected(table); + test_ivalue(2, cpl_array_get_size(array), "Check how many greater than..."); + test_ivalue(0, cpl_array_get_cplsize(array, 0, &null), + "Check where greater than..."); + cpl_test_zero(null); + test_ivalue(1, cpl_array_get_cplsize(array, 1, &null), + "Check where greater than..."); + cpl_test_zero(null); + cpl_array_delete(array); - test(cpl_table_divide_columns(table, "Double", "Int"), - "Divide double column with integer column... "); + /* + * Or not greater than + */ - for (i = 0; i < nrows; i++) { - sprintf(message, "Check element %d of result column... ", i); - test_fvalue(1.0, 0.00001, cpl_table_get_double(table, "Double", i, &null), - message); + cpl_table_unselect_all(table); + test_ivalue(3, + cpl_table_or_selected(table, "stringa", CPL_NOT_GREATER_THAN, + "stringb"), + "Invalid string comparison (or not greater than)"); + array = cpl_table_where_selected(table); + test_ivalue(3, cpl_array_get_size(array), + "Check how many not greater than..."); + test_ivalue(2, cpl_array_get_cplsize(array, 0, &null), + "Check where not greater than..."); + cpl_test_zero(null); + test_ivalue(3, cpl_array_get_cplsize(array, 1, &null), + "Check where not greater than..."); + cpl_test_zero(null); + test_ivalue(4, cpl_array_get_cplsize(array, 2, &null), + "Check where not greater than..."); cpl_test_zero(null); - } -#ifdef VERBOSE - cpl_table_dump(table, 0, cpl_table_get_nrow(table), stream); -#endif + cpl_array_delete(array); - cpl_table_delete(table); + /* + * Or less than + */ + + cpl_table_unselect_all(table); + test_ivalue(2, + cpl_table_or_selected(table, "stringa", CPL_LESS_THAN, + "stringb"), + "Invalid string comparison (or less than)"); + array = cpl_table_where_selected(table); + test_ivalue(2, cpl_array_get_size(array), "Check how many less than..."); + test_ivalue(3, cpl_array_get_cplsize(array, 0, &null), + "Check where less than..."); + cpl_test_zero(null); + test_ivalue(4, cpl_array_get_cplsize(array, 1, &null), + "Check where less than..."); + cpl_test_zero(null); + cpl_array_delete(array); - /* - * Test table of images - */ - - table = cpl_table_new(5); - test(cpl_table_new_column_array(table, "ADouble", CPL_TYPE_DOUBLE, 30), - "Creating the ADouble column... "); - - k = 0; - arrays = cpl_table_get_data_array(table, "ADouble"); - for (i = 0; i < 5; i++) { - arrays[i] = cpl_array_new(30, CPL_TYPE_DOUBLE); - for (j = 0; j < 30; j++) { - cpl_array_set_double(arrays[i], j, k * .123456); - k++; - } - } - - dimensions = cpl_array_new(2, CPL_TYPE_INT); - cpl_array_set_int(dimensions, 0, 5); - cpl_array_set_int(dimensions, 1, 5); - - test_failure(CPL_ERROR_INCOMPATIBLE_INPUT, - cpl_table_set_column_dimensions(table, "ADouble", dimensions), - "Try impossible column dimensions... "); - - cpl_array_set_int(dimensions, 1, 6); - - test_ivalue(1, cpl_table_get_column_dimensions(table, "ADouble"), - "Check no dimensions assigned to column ADouble... "); - - test(cpl_table_set_column_dimensions(table, "ADouble", dimensions), - "Set appropriate dimensions for column of images... "); - - cpl_array_delete(dimensions); - - error = cpl_table_save(table, NULL, NULL, BASE "23.fits", CPL_IO_CREATE); - cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_fits(BASE "23.fits"); - cpl_table_delete(table); - table = cpl_table_load(BASE "23.fits", 1, 1); - - test_ivalue(2, cpl_table_get_column_dimensions(table, "ADouble"), - "Check column ADouble has dimension 2... "); - - test_ivalue(5, cpl_table_get_column_dimension(table, "ADouble", 0), - "Check column ADouble dimension 1 is 5... "); - test_ivalue(6, cpl_table_get_column_dimension(table, "ADouble", 1), - "Check column ADouble dimension 2 is 6... "); - - // FIXME: CPL_IO_APPEND is supported now. Adjust test case accordingly - //test_failure(cpl_table_save(table, NULL, NULL, BASE "23.fits", - // CPL_IO_APPEND), CPL_ERROR_UNSUPPORTED_MODE, - // "Verify failure with CPL_IO_APPEND"); - //cpl_test_fits(BASE "23.fits"); - - cpl_table_delete(table); - - - /*********************************************** - * Testing all types of casting - ***********************************************/ - - table = cpl_table_new(10); - - cpl_table_new_column(table, "double" , CPL_TYPE_DOUBLE); - for (i = 0; i < 10; i++) - if (i != 5) /* Leave intentionally an invalid value */ - error = cpl_table_set_double(table, "double", i, i/3.); - cpl_test_eq_error(error, CPL_ERROR_NONE); - - /* - * Case 7: - * from_name type = CPL_TYPE_XXX - * specified type = CPL_TYPE_YYY - * to_name type = CPL_TYPE_YYY - */ - - cpl_table_cast_column(table, - "double", "float_from_double", CPL_TYPE_FLOAT); - cpl_table_cast_column(table, - "double", "int_from_double", CPL_TYPE_INT); - cpl_table_cast_column(table, - "int_from_double", "double_from_int", CPL_TYPE_DOUBLE); - cpl_table_cast_column(table, - "int_from_double", "float_from_int", CPL_TYPE_FLOAT); - cpl_table_cast_column(table, - "float_from_double", "double_from_float", CPL_TYPE_DOUBLE); - cpl_table_cast_column(table, - "float_from_double", "int_from_float", CPL_TYPE_INT); - - for (i = 0; i < 10; i++) { - if (i != 5) { - test_fvalue(i/3., 0.00001, - cpl_table_get_float(table, "float_from_double", i, &null), - "Invalid cast from double to float"); - cpl_test_zero(null); - test_ivalue(i/3, cpl_table_get_int(table, "int_from_double", i, &null), - "Invalid cast from double to int"); - cpl_test_zero(null); - test_fvalue(i/3, 0.00001, - cpl_table_get_double(table, "double_from_int", i, &null), - "Invalid cast from int to double"); - cpl_test_zero(null); - test_fvalue(i/3, 0.00001, - cpl_table_get_float(table, "float_from_int", i, &null), - "Invalid cast from int to float"); - cpl_test_zero(null); - test_fvalue(i/3., 0.00001, - cpl_table_get_double(table, "double_from_float", i, &null), - "Invalid cast from float to double"); - cpl_test_zero(null); - test_ivalue(i/3, cpl_table_get_int(table, "int_from_float", i, &null), - "Invalid cast from float to int"); - cpl_test_zero(null); - } - else { - test_ivalue(0, cpl_table_is_valid(table, "float_from_double", i), - "Invalid cast from double to float"); - test_ivalue(0, cpl_table_is_valid(table, "int_from_double", i), - "Invalid cast from double to int"); - test_ivalue(0, cpl_table_is_valid(table, "double_from_int", i), - "Invalid cast from int to double"); - test_ivalue(0, cpl_table_is_valid(table, "float_from_int", i), - "Invalid cast from int to float"); - test_ivalue(0, cpl_table_is_valid(table, "double_from_float", i), - "Invalid cast from float to double"); - test_ivalue(0, cpl_table_is_valid(table, "int_from_float", i), - "Invalid cast from float to int"); - } - } - - /* In place: */ - - cpl_table_cast_column(table, "double_from_int", NULL, CPL_TYPE_INT); - cpl_table_cast_column(table, "float_from_int", NULL, CPL_TYPE_INT); - cpl_table_cast_column(table, "double_from_float", NULL, CPL_TYPE_FLOAT); - cpl_table_cast_column(table, "int_from_float", NULL, CPL_TYPE_FLOAT); - cpl_table_cast_column(table, "float_from_double", NULL, CPL_TYPE_DOUBLE); - cpl_table_cast_column(table, "int_from_double", NULL, CPL_TYPE_DOUBLE); - - for (i = 0; i < 10; i++) { - if (i != 5) { - test_ivalue(i/3, - cpl_table_get_int(table, "double_from_int", i, &null), - "Invalid in-place cast from double to int"); - cpl_test_zero(null); - test_ivalue(i/3, cpl_table_get_int(table, "float_from_int", i, &null), - "Invalid in-place cast from float to int"); - cpl_test_zero(null); - test_fvalue(i/3., 0.00001, - cpl_table_get_float(table, "double_from_float", i, &null), - "Invalid in-place cast from double to float"); - cpl_test_zero(null); - test_fvalue(i/3, 0.00001, - cpl_table_get_float(table, "int_from_float", i, &null), - "Invalid in-place cast from int to float"); - cpl_test_zero(null); - test_fvalue(i/3., 0.00001, - cpl_table_get_double(table, "float_from_double", i, &null), - "Invalid in-place cast from float to double"); - cpl_test_zero(null); - test_fvalue(i/3, 0.00001, - cpl_table_get_double(table, "int_from_double", i, &null), - "Invalid in-place cast from int to double"); - cpl_test_zero(null); - } - else { - test_ivalue(0, cpl_table_is_valid(table, "double_from_int", i), - "Invalid in-place cast from double to int"); - test_ivalue(0, cpl_table_is_valid(table, "float_from_int", i), - "Invalid in-place cast from float to int"); - test_ivalue(0, cpl_table_is_valid(table, "double_from_float", i), - "Invalid in-place cast from double to float"); - test_ivalue(0, cpl_table_is_valid(table, "int_from_float", i), - "Invalid in-place cast from int to float"); - test_ivalue(0, cpl_table_is_valid(table, "float_from_double", i), - "Invalid in-place cast from float to double"); - test_ivalue(0, cpl_table_is_valid(table, "int_from_double", i), - "Invalid in-place cast from int to double"); - } - } - - - /* - * Case 1: - * from_name type = CPL_TYPE_XXX - * specified type = CPL_TYPE_XXX - * to_name type = CPL_TYPE_XXX - * - * (Note that now double_from_float is float, and double_from_int is int) - */ - - cpl_table_cast_column(table, - "double", "double_from_double", CPL_TYPE_DOUBLE); - cpl_table_cast_column(table, - "double_from_float", "float_from_float", CPL_TYPE_FLOAT); - cpl_table_cast_column(table, - "double_from_int", "int_from_int", CPL_TYPE_INT); - - for (i = 0; i < 10; i++) { - if (i != 5) { - test_ivalue(i/3, - cpl_table_get_int(table, "int_from_int", i, &null), - "Invalid cast from int to int"); - cpl_test_zero(null); - test_fvalue(i/3., 0.00001, - cpl_table_get_float(table, "float_from_float", i, &null), - "Invalid cast from float to float"); - cpl_test_zero(null); - test_fvalue(i/3., 0.00001, - cpl_table_get_double(table, "double_from_double", i, &null), - "Invalid cast from double to double"); - cpl_test_zero(null); - } - else { - test_ivalue(0, cpl_table_is_valid(table, "int_from_int", i), - "Invalid cast from int to int"); - test_ivalue(0, cpl_table_is_valid(table, "float_from_float", i), - "Invalid cast from float to float"); - test_ivalue(0, cpl_table_is_valid(table, "double_from_double", i), - "Invalid cast from double to double"); - } - } - - /* In place: */ - - cpl_table_cast_column(table, "double_from_double", NULL, CPL_TYPE_DOUBLE); - cpl_table_cast_column(table, "float_from_float", NULL, CPL_TYPE_FLOAT); - cpl_table_cast_column(table, "int_from_int", NULL, CPL_TYPE_INT); - - for (i = 0; i < 10; i++) { - if (i != 5) { - test_ivalue(i/3, - cpl_table_get_int(table, "int_from_int", i, &null), - "Invalid cast from int to int"); - cpl_test_zero(null); - test_fvalue(i/3., 0.00001, - cpl_table_get_float(table, "float_from_float", i, &null), - "Invalid cast from float to float"); - cpl_test_zero(null); - test_fvalue(i/3., 0.00001, - cpl_table_get_double(table, "double_from_double", i, &null), - "Invalid cast from double to double"); - cpl_test_zero(null); - } - else { - test_ivalue(0, cpl_table_is_valid(table, "int_from_int", i), - "Invalid cast from int to int"); - test_ivalue(0, cpl_table_is_valid(table, "float_from_float", i), - "Invalid cast from float to float"); - test_ivalue(0, cpl_table_is_valid(table, "double_from_double", i), - "Invalid cast from double to double"); - } - } - - - /* - * RESET: start from a new table - */ - - cpl_table_delete(table); - - table = cpl_table_new(10); - - cpl_table_new_column(table, "double" , CPL_TYPE_DOUBLE); - for (i = 0; i < 10; i++) - if (i != 5) /* Leave intentionally an invalid value */ - error = cpl_table_set_double(table, "double", i, i/3.); - cpl_test_eq_error(error, CPL_ERROR_NONE); - - cpl_table_cast_column(table, "double", "float", CPL_TYPE_FLOAT); - cpl_table_cast_column(table, "double", "int", CPL_TYPE_INT); - - - /* - * Case 11: - * from_name type = CPL_TYPE_XXX - * specified type = CPL_TYPE_YYY | CPL_TYPE_POINTER - * to_name type = CPL_TYPE_YYY | CPL_TYPE_POINTER (depth = 1) - */ - - cpl_table_cast_column(table, "double", "float1_from_double", - CPL_TYPE_FLOAT | CPL_TYPE_POINTER); - cpl_table_cast_column(table, "double", "int1_from_double", - CPL_TYPE_INT | CPL_TYPE_POINTER); - cpl_table_cast_column(table, "int", "double1_from_int", - CPL_TYPE_DOUBLE | CPL_TYPE_POINTER); - cpl_table_cast_column(table, "int", "float1_from_int", - CPL_TYPE_FLOAT | CPL_TYPE_POINTER); - cpl_table_cast_column(table, "float", "double1_from_float", - CPL_TYPE_DOUBLE | CPL_TYPE_POINTER); - cpl_table_cast_column(table, "float", "int1_from_float", - CPL_TYPE_INT | CPL_TYPE_POINTER); - - for (i = 0; i < 10; i++) { - if (i != 5) { - test_fvalue(i/3., 0.00001, - cpl_array_get_float(cpl_table_get_array(table, - "float1_from_double", i), 0, NULL), - "Invalid cast from double to float1"); - test_ivalue(i/3, - cpl_array_get_int(cpl_table_get_array(table, - "int1_from_double", i), 0, NULL), - "Invalid cast from double to int1"); - test_fvalue(i/3, 0.00001, - cpl_array_get_double(cpl_table_get_array(table, - "double1_from_int", i), 0, NULL), - "Invalid cast from int to double1"); - test_fvalue(i/3, 0.00001, - cpl_array_get_float(cpl_table_get_array(table, - "float1_from_int", i), 0, NULL), - "Invalid cast from int to float1"); - test_fvalue(i/3., 0.00001, - cpl_array_get_double(cpl_table_get_array(table, - "double1_from_float", i), 0, NULL), - "Invalid cast from float to double1"); - test_ivalue(i/3, - cpl_array_get_int(cpl_table_get_array(table, - "int1_from_float", i), 0, NULL), - "Invalid cast from float to int1"); - } - else { - test_ivalue(0, cpl_table_is_valid(table, "float1_from_double", i), - "Invalid cast from double to float1"); - test_ivalue(0, cpl_table_is_valid(table, "int1_from_double", i), - "Invalid cast from double to int1"); - test_ivalue(0, cpl_table_is_valid(table, "double1_from_int", i), - "Invalid cast from int to double1"); - test_ivalue(0, cpl_table_is_valid(table, "float1_from_int", i), - "Invalid cast from int to float1"); - test_ivalue(0, cpl_table_is_valid(table, "double1_from_float", i), - "Invalid cast from float to double1"); - test_ivalue(0, cpl_table_is_valid(table, "int1_from_float", i), - "Invalid cast from float to int1"); - } - } - - - /* - * Case 10 in-place: - * from_name type = CPL_TYPE_XXX | CPL_TYPE_POINTER (depth = 1) - * specified type = CPL_TYPE_YYY - * to_name type = CPL_TYPE_YYY - */ - - cpl_table_cast_column(table, "float1_from_double", NULL, CPL_TYPE_DOUBLE); - cpl_table_cast_column(table, "int1_from_double", NULL, CPL_TYPE_DOUBLE); - cpl_table_cast_column(table, "double1_from_int", NULL, CPL_TYPE_INT); - cpl_table_cast_column(table, "float1_from_int", NULL, CPL_TYPE_INT); - cpl_table_cast_column(table, "double1_from_float", NULL, CPL_TYPE_FLOAT); - cpl_table_cast_column(table, "int1_from_float", NULL, CPL_TYPE_FLOAT); - - for (i = 0; i < 10; i++) { - if (i != 5) { - test_fvalue(i/3., 0.00001, - cpl_table_get_double(table, "float1_from_double", i, &null), - "Invalid cast from float1 to double"); - cpl_test_zero(null); - test_fvalue(i/3, 0.00001, - cpl_table_get_double(table, "int1_from_double", i, &null), - "Invalid cast from int1 to double"); - cpl_test_zero(null); - test_ivalue(i/3, - cpl_table_get_int(table, "double1_from_int", i, &null), - "Invalid cast from double1 to int"); - cpl_test_zero(null); - test_fvalue(i/3, 0.00001, - cpl_table_get_int(table, "float1_from_int", i, &null), - "Invalid cast from float1 to int"); - cpl_test_zero(null); - test_fvalue(i/3., 0.00001, - cpl_table_get_float(table, "double1_from_float", i, &null), - "Invalid cast from double1 to float"); - cpl_test_zero(null); - test_ivalue(i/3, - cpl_table_get_float(table, "int1_from_float", i, &null), - "Invalid cast from int1 to float"); - cpl_test_zero(null); - } - else { - test_ivalue(0, cpl_table_is_valid(table, "float1_from_double", i), - "Invalid cast from float1 to double"); - test_ivalue(0, cpl_table_is_valid(table, "int1_from_double", i), - "Invalid cast from int1 to double"); - test_ivalue(0, cpl_table_is_valid(table, "double1_from_int", i), - "Invalid cast from double1 to int"); - test_ivalue(0, cpl_table_is_valid(table, "float1_from_int", i), - "Invalid cast from float1 to int"); - test_ivalue(0, cpl_table_is_valid(table, "double1_from_float", i), - "Invalid cast from double1 to float"); - test_ivalue(0, cpl_table_is_valid(table, "int1_from_float", i), - "Invalid cast from int1 to float"); - } - } - - - /* - * RESET: start from a new table - */ - - cpl_table_delete(table); - - table = cpl_table_new(10); - - cpl_table_new_column(table, "double" , CPL_TYPE_DOUBLE); - for (i = 0; i < 10; i++) - if (i != 5) /* Leave intentionally an invalid value */ - error = cpl_table_set_double(table, "double", i, i/3.); - cpl_test_eq_error(error, CPL_ERROR_NONE); - - cpl_table_duplicate_column(table, "double_to_float1", table, "double"); - cpl_table_duplicate_column(table, "double_to_int1", table, "double"); - cpl_table_cast_column(table, "double", "float", CPL_TYPE_FLOAT); - cpl_table_duplicate_column(table, "float_to_double1", table, "float"); - cpl_table_duplicate_column(table, "float_to_int1", table, "float"); - cpl_table_cast_column(table, "double", "int", CPL_TYPE_INT); - cpl_table_duplicate_column(table, "int_to_double1", table, "int"); - cpl_table_duplicate_column(table, "int_to_float1", table, "int"); - - /* - * Case 11, in-place: - * from_name type = CPL_TYPE_XXX - * specified type = CPL_TYPE_YYY | CPL_TYPE_POINTER - * to_name type = CPL_TYPE_YYY | CPL_TYPE_POINTER (depth = 1) - */ - - cpl_table_cast_column(table, "double_to_float1", NULL, - CPL_TYPE_FLOAT | CPL_TYPE_POINTER); - cpl_table_cast_column(table, "double_to_int1", NULL, - CPL_TYPE_INT | CPL_TYPE_POINTER); - cpl_table_cast_column(table, "int_to_double1", NULL, - CPL_TYPE_DOUBLE | CPL_TYPE_POINTER); - cpl_table_cast_column(table, "int_to_float1", NULL, - CPL_TYPE_FLOAT | CPL_TYPE_POINTER); - cpl_table_cast_column(table, "float_to_double1", NULL, - CPL_TYPE_DOUBLE | CPL_TYPE_POINTER); - cpl_table_cast_column(table, "float_to_int1", NULL, - CPL_TYPE_INT | CPL_TYPE_POINTER); - - for (i = 0; i < 10; i++) { - if (i != 5) { - test_fvalue(i/3., 0.00001, - cpl_array_get_float(cpl_table_get_array(table, - "double_to_float1", i), 0, NULL), - "Invalid cast from double to float1"); - test_ivalue(i/3, - cpl_array_get_int(cpl_table_get_array(table, - "double_to_int1", i), 0, NULL), - "Invalid cast from double to int1"); - test_fvalue(i/3, 0.00001, - cpl_array_get_double(cpl_table_get_array(table, - "int_to_double1", i), 0, NULL), - "Invalid cast from int to double1"); - test_fvalue(i/3, 0.00001, - cpl_array_get_float(cpl_table_get_array(table, - "int_to_float1", i), 0, NULL), - "Invalid cast from int to float1"); - test_fvalue(i/3., 0.00001, - cpl_array_get_double(cpl_table_get_array(table, - "float_to_double1", i), 0, NULL), - "Invalid cast from float to double1"); - test_ivalue(i/3, - cpl_array_get_int(cpl_table_get_array(table, - "float_to_int1", i), 0, NULL), - "Invalid cast from float to int1"); - } - else { - test_ivalue(0, cpl_table_is_valid(table, "double_to_float1", i), - "Invalid cast from double to float1"); - test_ivalue(0, cpl_table_is_valid(table, "double_to_int1", i), - "Invalid cast from double to int1"); - test_ivalue(0, cpl_table_is_valid(table, "int_to_double1", i), - "Invalid cast from int to double1"); - test_ivalue(0, cpl_table_is_valid(table, "int_to_float1", i), - "Invalid cast from int to float1"); - test_ivalue(0, cpl_table_is_valid(table, "float_to_double1", i), - "Invalid cast from float to double1"); - test_ivalue(0, cpl_table_is_valid(table, "float_to_int1", i), - "Invalid cast from float to int1"); - } - } - - /* - * RESET: start from a new table - */ - - cpl_table_delete(table); - - table = cpl_table_new(10); - - cpl_table_new_column(table, "double" , CPL_TYPE_DOUBLE); - for (i = 0; i < 10; i++) - if (i != 5) /* Leave intentionally an invalid value */ - error = cpl_table_set_double(table, "double", i, i/3.); - cpl_test_eq_error(error, CPL_ERROR_NONE); - - cpl_table_cast_column(table, "double", "float", CPL_TYPE_FLOAT); - cpl_table_cast_column(table, "double", "int", CPL_TYPE_INT); - - /* - * Case 5 & 6: - * from_name type = CPL_TYPE_XXX - * specified type = CPL_TYPE_XXX | CPL_TYPE_POINTER - * to_name type = CPL_TYPE_XXX | CPL_TYPE_POINTER (depth = 1) - * - * from_name type = CPL_TYPE_XXX - * specified type = CPL_TYPE_POINTER - * to_name type = CPL_TYPE_XXX | CPL_TYPE_POINTER (depth = 1) - */ - - cpl_table_cast_column(table, "double", "double1", CPL_TYPE_POINTER); - cpl_table_cast_column(table, "float", "float1", CPL_TYPE_POINTER); - cpl_table_cast_column(table, "int", "int1", CPL_TYPE_POINTER); - - for (i = 0; i < 10; i++) { - if (i != 5) { - test_fvalue(i/3., 0.00001, - cpl_array_get_float(cpl_table_get_array(table, - "float1", i), 0, NULL), - "Invalid cast from float to float1"); - test_ivalue(i/3, - cpl_array_get_int(cpl_table_get_array(table, - "int1", i), 0, NULL), - "Invalid cast from int to int1"); - test_fvalue(i/3., 0.00001, - cpl_array_get_double(cpl_table_get_array(table, - "double1", i), 0, NULL), - "Invalid cast from double to double1"); - } - else { - test_ivalue(0, cpl_table_is_valid(table, "float1", i), - "Invalid cast from float to float1"); - test_ivalue(0, cpl_table_is_valid(table, "int1", i), - "Invalid cast from int to int1"); - test_ivalue(0, cpl_table_is_valid(table, "double1", i), - "Invalid cast from double to double1"); - } - } - - - /* - * RESET: start from a new table - */ - - cpl_table_delete(table); - - table = cpl_table_new(10); - - cpl_table_new_column(table, "double" , CPL_TYPE_DOUBLE); - for (i = 0; i < 10; i++) - if (i != 5) /* Leave intentionally an invalid value */ - error = cpl_table_set_double(table, "double", i, i/3.); - cpl_test_eq_error(error, CPL_ERROR_NONE); - - cpl_table_cast_column(table, "double", "float", CPL_TYPE_FLOAT); - cpl_table_cast_column(table, "double", "int", CPL_TYPE_INT); - - /* - * Case 5 in-place: - * from_name type = CPL_TYPE_XXX - * specified type = CPL_TYPE_POINTER - * to_name type = CPL_TYPE_XXX | CPL_TYPE_POINTER (depth = 1) - */ - - cpl_table_cast_column(table, "double", NULL, CPL_TYPE_POINTER); - cpl_table_cast_column(table, "float", NULL, CPL_TYPE_POINTER); - cpl_table_cast_column(table, "int", NULL, CPL_TYPE_POINTER); - - for (i = 0; i < 10; i++) { - if (i != 5) { - test_fvalue(i/3., 0.00001, - cpl_array_get_float(cpl_table_get_array(table, - "float", i), 0, NULL), - "Invalid in-place cast from float to float1"); - test_ivalue(i/3, - cpl_array_get_int(cpl_table_get_array(table, - "int", i), 0, NULL), - "Invalid in-place cast from int to int1"); - test_fvalue(i/3., 0.00001, - cpl_array_get_double(cpl_table_get_array(table, - "double", i), 0, NULL), - "Invalid in-place cast from double to double1"); - } - else { - test_ivalue(0, cpl_table_is_valid(table, "float", i), - "Invalid in-place cast from float to float1"); - test_ivalue(0, cpl_table_is_valid(table, "int", i), - "Invalid in-place cast from int to int1"); - test_ivalue(0, cpl_table_is_valid(table, "double", i), - "Invalid in-place cast from double to double1"); - } - } - - /* - * RESET: start from a new table - */ - - cpl_table_delete(table); - - table = cpl_table_new(10); - - cpl_table_new_column_array(table, "double", - CPL_TYPE_DOUBLE | CPL_TYPE_POINTER, 2); - - array = cpl_array_new(2, CPL_TYPE_DOUBLE); - - for (i = 0; i < 2; i++) - cpl_array_set_double(array, i, (i+5)/3.); - - for (i = 0; i < 10; i++) - if (i != 5) /* Leave intentionally an invalid value */ - error = cpl_table_set_array(table, "double", i, array); - cpl_test_eq_error(error, CPL_ERROR_NONE); - - cpl_array_delete(array); - - cpl_table_duplicate_column(table, "double1", table, "double"); - - /* - * Case 8 & 9: - * from_name type = CPL_TYPE_XXX | CPL_TYPE_POINTER - * specified type = CPL_TYPE_YYY | CPL_TYPE_POINTER - * to_name type = CPL_TYPE_YYY | CPL_TYPE_POINTER - */ - - cpl_table_cast_column(table, "double", "float", - CPL_TYPE_FLOAT | CPL_TYPE_POINTER); - cpl_table_cast_column(table, "double", "float1", CPL_TYPE_FLOAT); - - for (i = 0; i < 10; i++) { - if (i != 5) { - test_fvalue(5/3., 0.00001, - cpl_array_get_float(cpl_table_get_array(table, - "float", i), 0, NULL), - "Invalid cast from double2 to float2"); - test_fvalue(6/3., 0.00001, - cpl_array_get_float(cpl_table_get_array(table, - "float", i), 1, NULL), - "Invalid cast from double2 to float2"); - test_fvalue(5/3., 0.00001, - cpl_array_get_float(cpl_table_get_array(table, - "float1", i), 0, NULL), - "Invalid cast from double2 to float2"); - test_fvalue(6/3., 0.00001, - cpl_array_get_float(cpl_table_get_array(table, - "float1", i), 1, NULL), - "Invalid cast from double2 to float2"); - } - else { - test_ivalue(0, cpl_table_is_valid(table, "float1", i), - "Invalid cast from double2 to float2"); - } - } - - - /* In place: */ - - cpl_table_cast_column(table, "double", NULL, - CPL_TYPE_FLOAT | CPL_TYPE_POINTER); - cpl_table_cast_column(table, "double1", NULL, CPL_TYPE_FLOAT); - - for (i = 0; i < 10; i++) { - if (i != 5) { - test_fvalue(5/3., 0.00001, - cpl_array_get_float(cpl_table_get_array(table, - "double", i), 0, NULL), - "Invalid in-place cast from double2 to float2"); - test_fvalue(6/3., 0.00001, - cpl_array_get_float(cpl_table_get_array(table, - "double", i), 1, NULL), - "Invalid in-place cast from double2 to float2"); - test_fvalue(5/3., 0.00001, - cpl_array_get_float(cpl_table_get_array(table, - "double1", i), 0, NULL), - "Invalid in-place cast from double2 to float2"); - test_fvalue(6/3., 0.00001, - cpl_array_get_float(cpl_table_get_array(table, - "double1", i), 1, NULL), - "Invalid in-place cast from double2 to float2"); - } - else { - test_ivalue(0, cpl_table_is_valid(table, "float1", i), - "Invalid in-place cast from doueble1 to float1"); - } - } - - cpl_table_delete(table); - - /* - * Testing comparison between string columns. - */ - - table = cpl_table_new(5); - cpl_table_new_column(table, "stringa", CPL_TYPE_STRING); - cpl_table_new_column(table, "stringb", CPL_TYPE_STRING); - - error = cpl_table_set_string(table, "stringa", 0, "bb"); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_set_string(table, "stringa", 1, "bb"); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_set_string(table, "stringa", 2, "bb"); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_set_string(table, "stringa", 3, "bb"); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_set_string(table, "stringa", 4, "bb"); - cpl_test_eq_error(error, CPL_ERROR_NONE); - - error = cpl_table_set_string(table, "stringb", 0, "a"); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_set_string(table, "stringb", 1, "ba"); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_set_string(table, "stringb", 2, "bb"); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_set_string(table, "stringb", 3, "bbb"); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_set_string(table, "stringb", 4, "bc"); - cpl_test_eq_error(error, CPL_ERROR_NONE); - - /* - * And equal to - */ - - test_ivalue(1, cpl_table_and_selected(table, "stringa", CPL_EQUAL_TO, - "stringb"), "Invalid string comparison (and equal to)"); - array = cpl_table_where_selected(table); - test_ivalue(1, cpl_array_get_size(array), "Check how many equal to..."); - test_ivalue(2, cpl_array_get_cplsize(array, 0, &null), - "Check where equal to..."); - cpl_test_zero(null); - cpl_array_delete(array); - cpl_table_select_all(table); - - /* - * And not equal to - */ - - cpl_table_select_all(table); - test_ivalue(4, cpl_table_and_selected(table, "stringa", CPL_NOT_EQUAL_TO, - "stringb"), "Invalid string comparison (and not equal to)"); - array = cpl_table_where_selected(table); - test_ivalue(4, cpl_array_get_size(array), - "Check how many not equal to..."); - test_ivalue(0, cpl_array_get_cplsize(array, 0, &null), - "Check where not equal to..."); - cpl_test_zero(null); - test_ivalue(1, cpl_array_get_cplsize(array, 1, &null), - "Check where not equal to..."); - cpl_test_zero(null); - test_ivalue(3, cpl_array_get_cplsize(array, 2, &null), - "Check where not equal to..."); - cpl_test_zero(null); - test_ivalue(4, cpl_array_get_cplsize(array, 3, &null), - "Check where not equal to..."); - cpl_test_zero(null); - cpl_array_delete(array); - - /* - * And greater than - */ - - cpl_table_select_all(table); - test_ivalue(2, cpl_table_and_selected(table, "stringa", CPL_GREATER_THAN, - "stringb"), "Invalid string comparison (and greater than)"); - array = cpl_table_where_selected(table); - test_ivalue(2, cpl_array_get_size(array), - "Check how many greater than..."); - test_ivalue(0, cpl_array_get_cplsize(array, 0, &null), - "Check where greater than..."); - cpl_test_zero(null); - test_ivalue(1, cpl_array_get_cplsize(array, 1, &null), - "Check where greater than..."); - cpl_test_zero(null); - cpl_array_delete(array); - - /* - * And not greater than - */ - - cpl_table_select_all(table); - test_ivalue(3, cpl_table_and_selected(table, "stringa", CPL_NOT_GREATER_THAN, - "stringb"), "Invalid string comparison (and not greater than)"); - array = cpl_table_where_selected(table); - test_ivalue(3, cpl_array_get_size(array), - "Check how many not greater than..."); - test_ivalue(2, cpl_array_get_cplsize(array, 0, &null), - "Check where not greater than..."); - cpl_test_zero(null); - test_ivalue(3, cpl_array_get_cplsize(array, 1, &null), - "Check where not greater than..."); - cpl_test_zero(null); - test_ivalue(4, cpl_array_get_cplsize(array, 2, &null), - "Check where not greater than..."); - cpl_test_zero(null); - cpl_array_delete(array); - - /* - * And less than - */ - - cpl_table_select_all(table); - test_ivalue(2, cpl_table_and_selected(table, "stringa", CPL_LESS_THAN, - "stringb"), "Invalid string comparison (and less than)"); - array = cpl_table_where_selected(table); - test_ivalue(2, cpl_array_get_size(array), - "Check how many less than..."); - test_ivalue(3, cpl_array_get_cplsize(array, 0, &null), - "Check where less than..."); - cpl_test_zero(null); - test_ivalue(4, cpl_array_get_cplsize(array, 1, &null), - "Check where less than..."); - cpl_test_zero(null); - cpl_array_delete(array); - - /* - * And not less than - */ - - cpl_table_select_all(table); - test_ivalue(3, cpl_table_and_selected(table, "stringa", CPL_NOT_LESS_THAN, - "stringb"), "Invalid string comparison (and not less than)"); - array = cpl_table_where_selected(table); - test_ivalue(3, cpl_array_get_size(array), - "Check how many not less than..."); - test_ivalue(0, cpl_array_get_cplsize(array, 0, &null), - "Check where not less than..."); - cpl_test_zero(null); - test_ivalue(1, cpl_array_get_cplsize(array, 1, &null), - "Check where not less than..."); - cpl_test_zero(null); - test_ivalue(2, cpl_array_get_cplsize(array, 2, &null), - "Check where not less than..."); - cpl_test_zero(null); - cpl_array_delete(array); - - /* - * Or equal to - */ - - cpl_table_unselect_all(table); - test_ivalue(1, cpl_table_or_selected(table, "stringa", CPL_EQUAL_TO, - "stringb"), "Invalid string comparison (or equal to)"); - array = cpl_table_where_selected(table); - test_ivalue(1, cpl_array_get_size(array), "Check how many equal to..."); - test_ivalue(2, cpl_array_get_cplsize(array, 0, &null), - "Check where equal to..."); - cpl_test_zero(null); - cpl_array_delete(array); - cpl_table_select_all(table); - - /* - * Or not equal to - */ - - cpl_table_unselect_all(table); - test_ivalue(4, cpl_table_or_selected(table, "stringa", CPL_NOT_EQUAL_TO, - "stringb"), "Invalid string comparison (or not equal to)"); - array = cpl_table_where_selected(table); - test_ivalue(4, cpl_array_get_size(array), - "Check how many not equal to..."); - test_ivalue(0, cpl_array_get_cplsize(array, 0, &null), - "Check where not equal to..."); - cpl_test_zero(null); - test_ivalue(1, cpl_array_get_cplsize(array, 1, &null), - "Check where not equal to..."); - cpl_test_zero(null); - test_ivalue(3, cpl_array_get_cplsize(array, 2, &null), - "Check where not equal to..."); - cpl_test_zero(null); - test_ivalue(4, cpl_array_get_cplsize(array, 3, &null), - "Check where not equal to..."); - cpl_test_zero(null); - cpl_array_delete(array); - - /* - * Or greater than - */ - - cpl_table_unselect_all(table); - test_ivalue(2, cpl_table_or_selected(table, "stringa", CPL_GREATER_THAN, - "stringb"), "Invalid string comparison (or greater than)"); - array = cpl_table_where_selected(table); - test_ivalue(2, cpl_array_get_size(array), - "Check how many greater than..."); - test_ivalue(0, cpl_array_get_cplsize(array, 0, &null), - "Check where greater than..."); - cpl_test_zero(null); - test_ivalue(1, cpl_array_get_cplsize(array, 1, &null), - "Check where greater than..."); - cpl_test_zero(null); - cpl_array_delete(array); - - /* - * Or not greater than - */ - - cpl_table_unselect_all(table); - test_ivalue(3, cpl_table_or_selected(table, "stringa", CPL_NOT_GREATER_THAN, - "stringb"), "Invalid string comparison (or not greater than)"); - array = cpl_table_where_selected(table); - test_ivalue(3, cpl_array_get_size(array), - "Check how many not greater than..."); - test_ivalue(2, cpl_array_get_cplsize(array, 0, &null), - "Check where not greater than..."); - cpl_test_zero(null); - test_ivalue(3, cpl_array_get_cplsize(array, 1, &null), - "Check where not greater than..."); - cpl_test_zero(null); - test_ivalue(4, cpl_array_get_cplsize(array, 2, &null), - "Check where not greater than..."); - cpl_test_zero(null); - - cpl_array_delete(array); - - /* - * Or less than - */ - - cpl_table_unselect_all(table); - test_ivalue(2, cpl_table_or_selected(table, "stringa", CPL_LESS_THAN, - "stringb"), "Invalid string comparison (or less than)"); - array = cpl_table_where_selected(table); - test_ivalue(2, cpl_array_get_size(array), - "Check how many less than..."); - test_ivalue(3, cpl_array_get_cplsize(array, 0, &null), - "Check where less than..."); - cpl_test_zero(null); - test_ivalue(4, cpl_array_get_cplsize(array, 1, &null), - "Check where less than..."); - cpl_test_zero(null); - cpl_array_delete(array); - - /* - * Or not less than - */ - - cpl_table_unselect_all(table); - test_ivalue(3, cpl_table_or_selected(table, "stringa", CPL_NOT_LESS_THAN, - "stringb"), "Invalid string comparison (or not less than)"); - array = cpl_table_where_selected(table); - test_ivalue(3, cpl_array_get_size(array), - "Check how many not less than..."); - test_ivalue(0, cpl_array_get_cplsize(array, 0, &null), - "Check where not less than..."); - cpl_test_zero(null); - test_ivalue(1, cpl_array_get_cplsize(array, 1, &null), - "Check where not less than..."); - cpl_test_zero(null); - test_ivalue(2, cpl_array_get_cplsize(array, 2, &null), - "Check where not less than..."); - cpl_test_zero(null); - cpl_array_delete(array); + /* + * Or not less than + */ - cpl_table_delete(table); + cpl_table_unselect_all(table); + test_ivalue(3, + cpl_table_or_selected(table, "stringa", CPL_NOT_LESS_THAN, + "stringb"), + "Invalid string comparison (or not less than)"); + array = cpl_table_where_selected(table); + test_ivalue(3, cpl_array_get_size(array), + "Check how many not less than..."); + test_ivalue(0, cpl_array_get_cplsize(array, 0, &null), + "Check where not less than..."); + cpl_test_zero(null); + test_ivalue(1, cpl_array_get_cplsize(array, 1, &null), + "Check where not less than..."); + cpl_test_zero(null); + test_ivalue(2, cpl_array_get_cplsize(array, 2, &null), + "Check where not less than..."); + cpl_test_zero(null); + cpl_array_delete(array); - if (stream != stdout) cpl_test_zero( fclose(stream) ); + cpl_table_delete(table); - return 0; + if (stream != stdout) + cpl_test_zero(fclose(stream)); + return 0; } @@ -4700,9 +4821,9 @@ @return void */ /*----------------------------------------------------------------------------*/ -static void cpl_table_test_large(cpl_size nrows) +static void +cpl_table_test_large(cpl_size nrows) { - cpl_table *table; cpl_error_code error; double time0, time1; @@ -4749,26 +4870,26 @@ cpl_test_eq_error(error, CPL_ERROR_NONE); error = cpl_table_fill_column_window_float(table, "Float2", 0, nrows, 0.0); cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_column_window_double(table, "Double2", 0, nrows, - 0.0); + error = + cpl_table_fill_column_window_double(table, "Double2", 0, nrows, 0.0); cpl_test_eq_error(error, CPL_ERROR_NONE); error = cpl_table_fill_column_window_int(table, "Int3", 0, nrows, 0); cpl_test_eq_error(error, CPL_ERROR_NONE); error = cpl_table_fill_column_window_float(table, "Float3", 0, nrows, 0.0); cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_column_window_double(table, "Double3", 0, nrows, - 0.0); + error = + cpl_table_fill_column_window_double(table, "Double3", 0, nrows, 0.0); cpl_test_eq_error(error, CPL_ERROR_NONE); error = cpl_table_fill_column_window_int(table, "Int4", 0, nrows, 0); cpl_test_eq_error(error, CPL_ERROR_NONE); error = cpl_table_fill_column_window_float(table, "Float4", 0, nrows, 0.0); cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_column_window_double(table, "Double4", 0, nrows, - 0.0); + error = + cpl_table_fill_column_window_double(table, "Double4", 0, nrows, 0.0); cpl_test_eq_error(error, CPL_ERROR_NONE); #if 1 - error = cpl_table_fill_column_window_string(table, "String", 0, nrows, - "dummy"); + error = + cpl_table_fill_column_window_string(table, "String", 0, nrows, "dummy"); cpl_test_eq_error(error, CPL_ERROR_NONE); #endif cpl_msg_info("test", "Saving table with %" CPL_SIZE_FORMAT " rows", nrows); @@ -4787,7 +4908,6 @@ cpl_test_eq(cpl_table_get_nrow(table), NROWS_LARGE); cpl_msg_info("test", "%f sec", time1 - time0); cpl_table_delete(table); - } @@ -4798,30 +4918,29 @@ @return void */ /*----------------------------------------------------------------------------*/ -static void cpl_table_test_zero_one(void) +static void +cpl_table_test_zero_one(void) { + /* Test 1: Test saving a table with empty propertylists */ + cpl_table *table = cpl_table_new(1); + cpl_propertylist *tlist = cpl_propertylist_new(); + cpl_propertylist *plist = cpl_propertylist_new(); + cpl_array *adc = cpl_array_new(232, CPL_TYPE_DOUBLE_COMPLEX); + cpl_array *adf = cpl_array_new(232, CPL_TYPE_FLOAT_COMPLEX); + cpl_array *add = cpl_array_new(232, CPL_TYPE_DOUBLE); + cpl_error_code code; - /* Test 1: Test saving a table with empty propertylists */ - - cpl_table *table = cpl_table_new(1); - cpl_propertylist *tlist = cpl_propertylist_new(); - cpl_propertylist *plist = cpl_propertylist_new(); - cpl_array *adc = cpl_array_new(232, CPL_TYPE_DOUBLE_COMPLEX); - cpl_array *adf = cpl_array_new(232, CPL_TYPE_FLOAT_COMPLEX); - cpl_array *add = cpl_array_new(232, CPL_TYPE_DOUBLE); - cpl_error_code code; - (void)remove(BASE ".fits"); test(cpl_table_save(table, plist, tlist, BASE ".fits", CPL_IO_CREATE), "Saving 1-length table to disk using empty propertylists..."); cpl_test_fits(BASE ".fits"); - + cpl_propertylist_delete(plist); cpl_propertylist_delete(tlist); cpl_table_delete(table); cpl_test_zero(remove(BASE ".fits")); - + /* * Testing tables with zero rows. */ @@ -4831,37 +4950,37 @@ cpl_test_nonnull(table); cpl_test_zero(cpl_table_get_nrow(table)); - test(cpl_table_new_column(table, "Int", CPL_TYPE_INT), + test(cpl_table_new_column(table, "Int", CPL_TYPE_INT), "Creating empty Integer column... "); test(cpl_table_new_column(table, "LongLong", CPL_TYPE_LONG_LONG), "Creating empty Integer column... "); - test(cpl_table_new_column(table, "Float", CPL_TYPE_FLOAT), + test(cpl_table_new_column(table, "Float", CPL_TYPE_FLOAT), "Creating empty Float column... "); - test(cpl_table_new_column(table, "Double", CPL_TYPE_DOUBLE), + test(cpl_table_new_column(table, "Double", CPL_TYPE_DOUBLE), "Creating empty Double column... "); - test(cpl_table_new_column(table, "CFloat", CPL_TYPE_FLOAT_COMPLEX), + test(cpl_table_new_column(table, "CFloat", CPL_TYPE_FLOAT_COMPLEX), "Creating empty Float Complex column... "); - test(cpl_table_new_column(table, "CDouble", CPL_TYPE_DOUBLE_COMPLEX), + test(cpl_table_new_column(table, "CDouble", CPL_TYPE_DOUBLE_COMPLEX), "Creating empty Double Complex column... "); - test(cpl_table_new_column(table, "String", CPL_TYPE_STRING), + test(cpl_table_new_column(table, "String", CPL_TYPE_STRING), "Creating empty String column... "); - test(cpl_table_new_column_array(table, "AInt", + test(cpl_table_new_column_array(table, "AInt", CPL_TYPE_INT | CPL_TYPE_POINTER, 232), "Creating empty IntegerArray column... "); test(cpl_table_new_column_array(table, "ALongLong", CPL_TYPE_LONG_LONG | CPL_TYPE_POINTER, 232), "Creating empty LongLongArray column... "); - test(cpl_table_new_column_array(table, "AFloat", + test(cpl_table_new_column_array(table, "AFloat", CPL_TYPE_FLOAT | CPL_TYPE_POINTER, 232), "Creating empty FloatArray column... "); - test(cpl_table_new_column_array(table, "ADouble", + test(cpl_table_new_column_array(table, "ADouble", CPL_TYPE_DOUBLE | CPL_TYPE_POINTER, 232), "Creating empty DoubleArray column... "); - test(cpl_table_new_column_array(table, "CAFloat", + test(cpl_table_new_column_array(table, "CAFloat", CPL_TYPE_FLOAT_COMPLEX | CPL_TYPE_POINTER, 232), "Creating empty FloatComplexArray column... "); - test(cpl_table_new_column_array(table, "CADouble", + test(cpl_table_new_column_array(table, "CADouble", CPL_TYPE_DOUBLE_COMPLEX | CPL_TYPE_POINTER, 232), "Creating empty DoubleComplexArray column... "); @@ -4869,19 +4988,19 @@ test_ivalue(0, cpl_table_get_nrow(table), "Check zero table length... "); test_ivalue(13, cpl_table_get_ncol(table), "Check zero table width... "); - test_ivalue(0, cpl_table_get_column_depth(table, "Double"), + test_ivalue(0, cpl_table_get_column_depth(table, "Double"), "Check \"Double\" depth... "); - test_ivalue(0, cpl_table_get_column_depth(table, "CDouble"), + test_ivalue(0, cpl_table_get_column_depth(table, "CDouble"), "Check \"CDouble\" depth... "); - test_ivalue(232, cpl_table_get_column_depth(table, "AInt"), + test_ivalue(232, cpl_table_get_column_depth(table, "AInt"), "Check \"AInt\" depth... "); - test_ivalue(232, cpl_table_get_column_depth(table, "CAFloat"), + test_ivalue(232, cpl_table_get_column_depth(table, "CAFloat"), "Check \"CAFloat\" depth... "); - test_ivalue(232, cpl_table_get_column_depth(table, "CADouble"), + test_ivalue(232, cpl_table_get_column_depth(table, "CADouble"), "Check \"CADouble\" depth... "); test(cpl_table_set_size(table, 1), "Expanding table to one row... "); @@ -4899,7 +5018,7 @@ test(cpl_table_set_size(table, 0), "Deleting all rows from table... "); - test_ivalue(0, cpl_table_get_nrow(table), + test_ivalue(0, cpl_table_get_nrow(table), "Check again zero table length... "); test(cpl_table_erase_column(table, "Double"), @@ -4922,41 +5041,39 @@ test_pvalue(NULL, cpl_table_get_data_float(table, "Float"), "Check NULL pointer to column Float... "); - test_failure(CPL_ERROR_NULL_INPUT, - cpl_table_erase_selected(NULL), + test_failure(CPL_ERROR_NULL_INPUT, cpl_table_erase_selected(NULL), "Erase selected on NULL table... "); - test(cpl_table_erase_selected(table), - "Erase selected on empty table... "); + test(cpl_table_erase_selected(table), "Erase selected on empty table... "); - test_failure(CPL_ERROR_NULL_INPUT, + test_failure(CPL_ERROR_NULL_INPUT, cpl_table_set_column_unit(NULL, "Float", "arcsec"), "Try to assign unit to NULL table... "); - test_failure(CPL_ERROR_NULL_INPUT, + test_failure(CPL_ERROR_NULL_INPUT, cpl_table_set_column_unit(table, NULL, "arcsec"), "Try to assign unit to NULL column... "); - test_failure(CPL_ERROR_DATA_NOT_FOUND, + test_failure(CPL_ERROR_DATA_NOT_FOUND, cpl_table_set_column_unit(table, "Double", "arcsec"), "Try to assign unit to non existing column... "); test(cpl_table_set_column_unit(table, "Float", "arcsec"), "Assign unit 'arcsec' to column Float... "); - + test_svalue("arcsec", cpl_table_get_column_unit(table, "Float"), "Check column unit... "); /* - if (strcmp(unit = (char *)cpl_table_get_column_unit(table, "Float"), - "arcsec")) { - printf("Check column unit... "); - printf("Expected \"arcsec\", obtained \"%s\"\n", unit); - cpl_end(); - return 1; - } - */ + if (strcmp(unit = (char *)cpl_table_get_column_unit(table, "Float"), + "arcsec")) { + printf("Check column unit... "); + printf("Expected \"arcsec\", obtained \"%s\"\n", unit); + cpl_end(); + return 1; + } + */ test(cpl_table_set_column_unit(table, "Float", NULL), "Assign unit NULL to column Float... "); @@ -4999,7 +5116,6 @@ cpl_array_delete(adf); cpl_array_delete(add); cpl_table_delete(table); - } @@ -5014,368 +5130,366 @@ table 21 + 22 if it is pasted into cpl_table_test_main() */ /*----------------------------------------------------------------------------*/ -static void cpl_table_test_20(cpl_table * table) +static void +cpl_table_test_20(cpl_table *table) { - int null; - cpl_table *copia; + int null; + cpl_table *copia; + + + test_ivalue(0, cpl_table_is_valid(table, "Integer", 0), + "Check element 1 of \"Integer\" += \"IntToFloat\"... "); + test_ivalue(1998, cpl_table_get_int(table, "Integer", 1, &null), + "Check element 2 of \"Integer\" += \"IntToFloat\"... "); + cpl_test_zero(null); + test_ivalue(0, cpl_table_is_valid(table, "Integer", 2), + "Check element 3 of \"Integer\" += \"IntToFloat\"... "); + test_ivalue(0, cpl_table_is_valid(table, "Integer", 3), + "Check element 4 of \"Integer\" += \"IntToFloat\"... "); + test_ivalue(1998, cpl_table_get_int(table, "Integer", 4, &null), + "Check element 5 of \"Integer\" += \"IntToFloat\"... "); + cpl_test_zero(null); + test_ivalue(1998, cpl_table_get_int(table, "Integer", 5, &null), + "Check element 6 of \"Integer\" += \"IntToFloat\"... "); + cpl_test_zero(null); + test_ivalue(998, cpl_table_get_int(table, "Integer", 6, &null), + "Check element 7 of \"Integer\" += \"IntToFloat\"... "); + cpl_test_zero(null); + test_ivalue(998, cpl_table_get_int(table, "Integer", 7, &null), + "Check element 8 of \"Integer\" += \"IntToFloat\"... "); + cpl_test_zero(null); + test_ivalue(1998, cpl_table_get_int(table, "Integer", 8, &null), + "Check element 9 of \"Integer\" += \"IntToFloat\"... "); + cpl_test_zero(null); + test_ivalue(1998, cpl_table_get_int(table, "Integer", 9, &null), + "Check element 10 of \"Integer\" += \"IntToFloat\"... "); + cpl_test_zero(null); + test_ivalue(1998, cpl_table_get_int(table, "Integer", 10, &null), + "Check element 11 of \"Integer\" += \"IntToFloat\"... "); + cpl_test_zero(null); + test_ivalue(0, cpl_table_is_valid(table, "Integer", 11), + "Check element 12 of \"Integer\" += \"IntToFloat\"... "); + test_ivalue(0, cpl_table_is_valid(table, "Integer", 12), + "Check element 13 of \"Integer\" += \"IntToFloat\"... "); + test_ivalue(10, cpl_table_get_int(table, "Integer", 13, &null), + "Check element 14 of \"Integer\" += \"IntToFloat\"... "); + cpl_test_zero(null); + test_ivalue(8, cpl_table_get_int(table, "Integer", 14, &null), + "Check element 15 of \"Integer\" += \"IntToFloat\"... "); + cpl_test_zero(null); + test_ivalue(5, cpl_table_get_int(table, "Integer", 15, &null), + "Check element 16 of \"Integer\" += \"IntToFloat\"... "); + cpl_test_zero(null); + test_ivalue(10, cpl_table_get_int(table, "Integer", 16, &null), + "Check element 17 of \"Integer\" += \"IntToFloat\"... "); + cpl_test_zero(null); + test_ivalue(0, cpl_table_is_valid(table, "Integer", 17), + "Check element 18 of \"Integer\" += \"IntToFloat\"... "); + test_ivalue(0, cpl_table_is_valid(table, "Integer", 18), + "Check element 19 of \"Integer\" += \"IntToFloat\"... "); + test_ivalue(0, cpl_table_is_valid(table, "Integer", 19), + "Check element 20 of \"Integer\" += \"IntToFloat\"... "); + test_ivalue(0, cpl_table_is_valid(table, "Integer", 20), + "Check element 21 of \"Integer\" += \"IntToFloat\"... "); + test_ivalue(1998, cpl_table_get_int(table, "Integer", 21, &null), + "Check element 22 of \"Integer\" += \"IntToFloat\"... "); + cpl_test_zero(null); + + test(cpl_table_subtract_columns(table, "Integer", "IntToFloat"), + "Subtract \"IntToFloat\" from \"Integer\"... "); + + test(cpl_table_subtract_columns(table, "IntToFloat", "Integer"), + "Subtract \"Integer\" from \"IntToFloat\"... "); + + test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 0), + "Check element 1 of \"IntToFloat\" -= \"Integer\"... "); + test_fvalue(0.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 1, &null), + "Check element 2 of \"IntToFloat\" -= \"Integer\"... "); + cpl_test_zero(null); + test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 2), + "Check element 3 of \"IntToFloat\" -= \"Integer\"... "); + test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 3), + "Check element 4 of \"IntToFloat\" -= \"Integer\"... "); + test_fvalue(0.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 4, &null), + "Check element 5 of \"IntToFloat\" -= \"Integer\"... "); + cpl_test_zero(null); + test_fvalue(0.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 5, &null), + "Check element 6 of \"IntToFloat\" -= \"Integer\"... "); + cpl_test_zero(null); + test_fvalue(1000.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 6, &null), + "Check element 7 of \"IntToFloat\" -= \"Integer\"... "); + cpl_test_zero(null); + test_fvalue(-1000.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 7, &null), + "Check element 8 of \"IntToFloat\" -= \"Integer\"... "); + cpl_test_zero(null); + test_fvalue(0.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 8, &null), + "Check element 9 of \"IntToFloat\" -= \"Integer\"... "); + cpl_test_zero(null); + test_fvalue(0.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 9, &null), + "Check element 10 of \"IntToFloat\" -= \"Integer\"... "); + cpl_test_zero(null); + test_fvalue(0.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 10, &null), + "Check element 11 of \"IntToFloat\" -= \"Integer\"... "); + cpl_test_zero(null); + test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 11), + "Check element 12 of \"IntToFloat\" -= \"Integer\"... "); + test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 12), + "Check element 13 of \"IntToFloat\" -= \"Integer\"... "); + test_fvalue(-4.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 13, &null), + "Check element 14 of \"IntToFloat\" -= \"Integer\"... "); + cpl_test_zero(null); + test_fvalue(6.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 14, &null), + "Check element 15 of \"IntToFloat\" -= \"Integer\"... "); + cpl_test_zero(null); + test_fvalue(-3.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 15, &null), + "Check element 16 of \"IntToFloat\" -= \"Integer\"... "); + cpl_test_zero(null); + test_fvalue(-2.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 16, &null), + "Check element 17 of \"IntToFloat\" -= \"Integer\"... "); + cpl_test_zero(null); + test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 17), + "Check element 18 of \"IntToFloat\" -= \"Integer\"... "); + test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 18), + "Check element 19 of \"IntToFloat\" -= \"Integer\"... "); + test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 19), + "Check element 20 of \"IntToFloat\" -= \"Integer\"... "); + test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 20), + "Check element 21 of \"IntToFloat\" -= \"Integer\"... "); + test_fvalue(0.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 21, &null), + "Check element 22 of \"IntToFloat\" -= \"Integer\"... "); + cpl_test_zero(null); + + test(cpl_table_multiply_columns(table, "IntToFloat", "Double"), + "Multiply double column with float column... "); + + test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 0), + "Check element 1 of \"IntToFloat\" *= \"Double\"... "); + test_fvalue(0.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 1, &null), + "Check element 2 of \"IntToFloat\" *= \"Double\"... "); + cpl_test_zero(null); + test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 2), + "Check element 3 of \"IntToFloat\" *= \"Double\"... "); + test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 3), + "Check element 4 of \"IntToFloat\" *= \"Double\"... "); + test_fvalue(0.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 4, &null), + "Check element 5 of \"IntToFloat\" *= \"Double\"... "); + cpl_test_zero(null); + test_fvalue(0.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 5, &null), + "Check element 6 of \"IntToFloat\" *= \"Double\"... "); + cpl_test_zero(null); + test_fvalue(-1110.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 6, &null), + "Check element 7 of \"IntToFloat\" *= \"Double\"... "); + cpl_test_zero(null); + test_fvalue(-999880.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 7, &null), + "Check element 8 of \"IntToFloat\" *= \"Double\"... "); + cpl_test_zero(null); + test_fvalue(0.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 8, &null), + "Check element 9 of \"IntToFloat\" *= \"Double\"... "); + cpl_test_zero(null); + test_fvalue(0.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 9, &null), + "Check element 10 of \"IntToFloat\" *= \"Double\"... "); + cpl_test_zero(null); + test_fvalue(0.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 10, &null), + "Check element 11 of \"IntToFloat\" *= \"Double\"... "); + cpl_test_zero(null); + test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 11), + "Check element 12 of \"IntToFloat\" *= \"Double\"... "); + test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 12), + "Check element 13 of \"IntToFloat\" *= \"Double\"... "); + test_fvalue(-28.44, 0.00001, + cpl_table_get_float(table, "IntToFloat", 13, &null), + "Check element 14 of \"IntToFloat\" *= \"Double\"... "); + cpl_test_zero(null); + test_fvalue(6.66, 0.00001, + cpl_table_get_float(table, "IntToFloat", 14, &null), + "Check element 15 of \"IntToFloat\" *= \"Double\"... "); + cpl_test_zero(null); + test_fvalue(-12.33, 0.00001, + cpl_table_get_float(table, "IntToFloat", 15, &null), + "Check element 16 of \"IntToFloat\" *= \"Double\"... "); + cpl_test_zero(null); + test_fvalue(-12.22, 0.00001, + cpl_table_get_float(table, "IntToFloat", 16, &null), + "Check element 17 of \"IntToFloat\" *= \"Double\"... "); + cpl_test_zero(null); + test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 17), + "Check element 18 of \"IntToFloat\" *= \"Double\"... "); + test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 18), + "Check element 19 of \"IntToFloat\" *= \"Double\"... "); + test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 19), + "Check element 20 of \"IntToFloat\" *= \"Double\"... "); + test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 20), + "Check element 21 of \"IntToFloat\" *= \"Double\"... "); + test_fvalue(0.0, 0.00001, + cpl_table_get_float(table, "IntToFloat", 21, &null), + "Check element 22 of \"IntToFloat\" *= \"Double\"... "); + cpl_test_zero(null); + + test(cpl_table_divide_columns(table, "Float", "IntToFloat"), + "Divide float column with float column... "); + + test_ivalue(0, cpl_table_is_valid(table, "Float", 0), + "Check element 1 of \"Float\" /= \"IntToFloat\"... "); + test_ivalue(0, cpl_table_is_valid(table, "Float", 1), + "Check element 2 of \"Float\" /= \"IntToFloat\"... "); + test_ivalue(0, cpl_table_is_valid(table, "Float", 2), + "Check element 3 of \"Float\" /= \"IntToFloat\"... "); + test_ivalue(0, cpl_table_is_valid(table, "Float", 3), + "Check element 4 of \"Float\" /= \"IntToFloat\"... "); + test_ivalue(0, cpl_table_is_valid(table, "Float", 4), + "Check element 5 of \"Float\" /= \"IntToFloat\"... "); + test_ivalue(0, cpl_table_is_valid(table, "Float", 5), + "Check element 6 of \"Float\" /= \"IntToFloat\"... "); + test_fvalue(0.000991, 0.0000001, + cpl_table_get_float(table, "Float", 6, &null), + "Check element 7 of \"Float\" /= \"IntToFloat\"... "); + cpl_test_zero(null); + test_fvalue(-0.0010001, 0.0000001, + cpl_table_get_float(table, "Float", 7, &null), + "Check element 8 of \"Float\" /= \"IntToFloat\"... "); + cpl_test_zero(null); + test_ivalue(0, cpl_table_is_valid(table, "Float", 8), + "Check element 9 of \"Float\" /= \"IntToFloat\"... "); + test_ivalue(0, cpl_table_is_valid(table, "Float", 9), + "Check element 10 of \"Float\" /= \"IntToFloat\"... "); + test_ivalue(0, cpl_table_is_valid(table, "Float", 10), + "Check element 11 of \"Float\" /= \"IntToFloat\"... "); + test_ivalue(0, cpl_table_is_valid(table, "Float", 11), + "Check element 12 of \"Float\" /= \"IntToFloat\"... "); + test_ivalue(0, cpl_table_is_valid(table, "Float", 12), + "Check element 13 of \"Float\" /= \"IntToFloat\"... "); + test_fvalue(-0.2496484, 0.0000001, + cpl_table_get_float(table, "Float", 13, &null), + "Check element 14 of \"Float\" /= \"IntToFloat\"... "); + cpl_test_zero(null); + test_fvalue(0.1651652, 0.0000001, + cpl_table_get_float(table, "Float", 14, &null), + "Check element 15 of \"Float\" /= \"IntToFloat\"... "); + cpl_test_zero(null); + test_fvalue(-0.3325223, 0.0000001, + cpl_table_get_float(table, "Float", 15, &null), + "Check element 16 of \"Float\" /= \"IntToFloat\"... "); + cpl_test_zero(null); + test_fvalue(-0.4991817, 0.0000001, + cpl_table_get_float(table, "Float", 16, &null), + "Check element 17 of \"Float\" /= \"IntToFloat\"... "); + cpl_test_zero(null); + test_ivalue(0, cpl_table_is_valid(table, "Float", 17), + "Check element 18 of \"Float\" /= \"IntToFloat\"... "); + test_ivalue(0, cpl_table_is_valid(table, "Float", 18), + "Check element 19 of \"Float\" /= \"IntToFloat\"... "); + test_ivalue(0, cpl_table_is_valid(table, "Float", 19), + "Check element 20 of \"Float\" /= \"IntToFloat\"... "); + test_ivalue(0, cpl_table_is_valid(table, "Float", 20), + "Check element 21 of \"Float\" /= \"IntToFloat\"... "); + test_ivalue(0, cpl_table_is_valid(table, "Float", 21), + "Check element 22 of \"Float\" /= \"IntToFloat\"... "); + + test(cpl_table_add_scalar(table, "Float", 1), + "Add integer constant to \"Float\"... "); + + test_ivalue(0, cpl_table_is_valid(table, "Float", 0), + "Check element 1 of adding 1 to \"Float\"... "); + test_ivalue(0, cpl_table_is_valid(table, "Float", 1), + "Check element 2 of adding 1 to \"Float\"... "); + test_ivalue(0, cpl_table_is_valid(table, "Float", 2), + "Check element 3 of adding 1 to \"Float\"... "); + test_ivalue(0, cpl_table_is_valid(table, "Float", 3), + "Check element 4 of adding 1 to \"Float\"... "); + test_ivalue(0, cpl_table_is_valid(table, "Float", 4), + "Check element 5 of adding 1 to \"Float\"... "); + test_ivalue(0, cpl_table_is_valid(table, "Float", 5), + "Check element 6 of adding 1 to \"Float\"... "); + test_fvalue(1.000991, 0.0000001, + cpl_table_get_float(table, "Float", 6, &null), + "Check element 7 of adding 1 to \"Float\"... "); + cpl_test_zero(null); + test_fvalue(1 - 0.0010001, 0.0000001, + cpl_table_get_float(table, "Float", 7, &null), + "Check element 8 of adding 1 to \"Float\"... "); + cpl_test_zero(null); + test_ivalue(0, cpl_table_is_valid(table, "Float", 8), + "Check element 9 of adding 1 to \"Float\"... "); + test_ivalue(0, cpl_table_is_valid(table, "Float", 9), + "Check element 10 of adding 1 to \"Float\"... "); + test_ivalue(0, cpl_table_is_valid(table, "Float", 10), + "Check element 11 of adding 1 to \"Float\"... "); + test_ivalue(0, cpl_table_is_valid(table, "Float", 11), + "Check element 12 of adding 1 to \"Float\"... "); + test_ivalue(0, cpl_table_is_valid(table, "Float", 12), + "Check element 13 of adding 1 to \"Float\"... "); + test_fvalue(1 - 0.2496484, 0.0000001, + cpl_table_get_float(table, "Float", 13, &null), + "Check element 14 of adding 1 to \"Float\"... "); + cpl_test_zero(null); + test_fvalue(1.1651652, 0.0000001, + cpl_table_get_float(table, "Float", 14, &null), + "Check element 15 of adding 1 to \"Float\"... "); + cpl_test_zero(null); + test_fvalue(1 - 0.3325223, 0.0000001, + cpl_table_get_float(table, "Float", 15, &null), + "Check element 16 of adding 1 to \"Float\"... "); + cpl_test_zero(null); + test_fvalue(1 - 0.4991817, 0.0000001, + cpl_table_get_float(table, "Float", 16, &null), + "Check element 17 of adding 1 to \"Float\"... "); + cpl_test_zero(null); + test_ivalue(0, cpl_table_is_valid(table, "Float", 17), + "Check element 18 of adding 1 to \"Float\"... "); + test_ivalue(0, cpl_table_is_valid(table, "Float", 18), + "Check element 19 of adding 1 to \"Float\"... "); + test_ivalue(0, cpl_table_is_valid(table, "Float", 19), + "Check element 20 of adding 1 to \"Float\"... "); + test_ivalue(0, cpl_table_is_valid(table, "Float", 20), + "Check element 21 of adding 1 to \"Float\"... "); + test_ivalue(0, cpl_table_is_valid(table, "Float", 21), + "Check element 22 of adding 1 to \"Float\"... "); + + test(cpl_table_set_column_invalid(table, "Float", 0, + cpl_table_get_nrow(table)), + "Set \"Float\" column to NULL... "); + copia = cpl_table_duplicate(table); + cpl_test_nonnull(copia); - test_ivalue(0, cpl_table_is_valid(table, "Integer", 0), - "Check element 1 of \"Integer\" += \"IntToFloat\"... "); - test_ivalue(1998, cpl_table_get_int(table, "Integer", 1, &null), - "Check element 2 of \"Integer\" += \"IntToFloat\"... "); - cpl_test_zero(null); - test_ivalue(0, cpl_table_is_valid(table, "Integer", 2), - "Check element 3 of \"Integer\" += \"IntToFloat\"... "); - test_ivalue(0, cpl_table_is_valid(table, "Integer", 3), - "Check element 4 of \"Integer\" += \"IntToFloat\"... "); - test_ivalue(1998, cpl_table_get_int(table, "Integer", 4, &null), - "Check element 5 of \"Integer\" += \"IntToFloat\"... "); - cpl_test_zero(null); - test_ivalue(1998, cpl_table_get_int(table, "Integer", 5, &null), - "Check element 6 of \"Integer\" += \"IntToFloat\"... "); - cpl_test_zero(null); - test_ivalue(998, cpl_table_get_int(table, "Integer", 6, &null), - "Check element 7 of \"Integer\" += \"IntToFloat\"... "); - cpl_test_zero(null); - test_ivalue(998, cpl_table_get_int(table, "Integer", 7, &null), - "Check element 8 of \"Integer\" += \"IntToFloat\"... "); - cpl_test_zero(null); - test_ivalue(1998, cpl_table_get_int(table, "Integer", 8, &null), - "Check element 9 of \"Integer\" += \"IntToFloat\"... "); - cpl_test_zero(null); - test_ivalue(1998, cpl_table_get_int(table, "Integer", 9, &null), - "Check element 10 of \"Integer\" += \"IntToFloat\"... "); - cpl_test_zero(null); - test_ivalue(1998, cpl_table_get_int(table, "Integer", 10, &null), - "Check element 11 of \"Integer\" += \"IntToFloat\"... "); - cpl_test_zero(null); - test_ivalue(0, cpl_table_is_valid(table, "Integer", 11), - "Check element 12 of \"Integer\" += \"IntToFloat\"... "); - test_ivalue(0, cpl_table_is_valid(table, "Integer", 12), - "Check element 13 of \"Integer\" += \"IntToFloat\"... "); - test_ivalue(10, cpl_table_get_int(table, "Integer", 13, &null), - "Check element 14 of \"Integer\" += \"IntToFloat\"... "); - cpl_test_zero(null); - test_ivalue(8, cpl_table_get_int(table, "Integer", 14, &null), - "Check element 15 of \"Integer\" += \"IntToFloat\"... "); - cpl_test_zero(null); - test_ivalue(5, cpl_table_get_int(table, "Integer", 15, &null), - "Check element 16 of \"Integer\" += \"IntToFloat\"... "); - cpl_test_zero(null); - test_ivalue(10, cpl_table_get_int(table, "Integer", 16, &null), - "Check element 17 of \"Integer\" += \"IntToFloat\"... "); - cpl_test_zero(null); - test_ivalue(0, cpl_table_is_valid(table, "Integer", 17), - "Check element 18 of \"Integer\" += \"IntToFloat\"... "); - test_ivalue(0, cpl_table_is_valid(table, "Integer", 18), - "Check element 19 of \"Integer\" += \"IntToFloat\"... "); - test_ivalue(0, cpl_table_is_valid(table, "Integer", 19), - "Check element 20 of \"Integer\" += \"IntToFloat\"... "); - test_ivalue(0, cpl_table_is_valid(table, "Integer", 20), - "Check element 21 of \"Integer\" += \"IntToFloat\"... "); - test_ivalue(1998, cpl_table_get_int(table, "Integer", 21, &null), - "Check element 22 of \"Integer\" += \"IntToFloat\"... "); - cpl_test_zero(null); - - test(cpl_table_subtract_columns(table, "Integer", "IntToFloat"), - "Subtract \"IntToFloat\" from \"Integer\"... "); - - test(cpl_table_subtract_columns(table, "IntToFloat", "Integer"), - "Subtract \"Integer\" from \"IntToFloat\"... "); - - test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 0), - "Check element 1 of \"IntToFloat\" -= \"Integer\"... "); - test_fvalue(0.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 1, &null), - "Check element 2 of \"IntToFloat\" -= \"Integer\"... "); - cpl_test_zero(null); - test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 2), - "Check element 3 of \"IntToFloat\" -= \"Integer\"... "); - test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 3), - "Check element 4 of \"IntToFloat\" -= \"Integer\"... "); - test_fvalue(0.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 4, &null), - "Check element 5 of \"IntToFloat\" -= \"Integer\"... "); - cpl_test_zero(null); - test_fvalue(0.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 5, &null), - "Check element 6 of \"IntToFloat\" -= \"Integer\"... "); - cpl_test_zero(null); - test_fvalue(1000.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 6, &null), - "Check element 7 of \"IntToFloat\" -= \"Integer\"... "); - cpl_test_zero(null); - test_fvalue(-1000.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 7, &null), - "Check element 8 of \"IntToFloat\" -= \"Integer\"... "); - cpl_test_zero(null); - test_fvalue(0.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 8, &null), - "Check element 9 of \"IntToFloat\" -= \"Integer\"... "); - cpl_test_zero(null); - test_fvalue(0.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 9, &null), - "Check element 10 of \"IntToFloat\" -= \"Integer\"... "); - cpl_test_zero(null); - test_fvalue(0.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 10, &null), - "Check element 11 of \"IntToFloat\" -= \"Integer\"... "); - cpl_test_zero(null); - test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 11), - "Check element 12 of \"IntToFloat\" -= \"Integer\"... "); - test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 12), - "Check element 13 of \"IntToFloat\" -= \"Integer\"... "); - test_fvalue(-4.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 13, &null), - "Check element 14 of \"IntToFloat\" -= \"Integer\"... "); - cpl_test_zero(null); - test_fvalue(6.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 14, &null), - "Check element 15 of \"IntToFloat\" -= \"Integer\"... "); - cpl_test_zero(null); - test_fvalue(-3.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 15, &null), - "Check element 16 of \"IntToFloat\" -= \"Integer\"... "); - cpl_test_zero(null); - test_fvalue(-2.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 16, &null), - "Check element 17 of \"IntToFloat\" -= \"Integer\"... "); - cpl_test_zero(null); - test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 17), - "Check element 18 of \"IntToFloat\" -= \"Integer\"... "); - test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 18), - "Check element 19 of \"IntToFloat\" -= \"Integer\"... "); - test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 19), - "Check element 20 of \"IntToFloat\" -= \"Integer\"... "); - test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 20), - "Check element 21 of \"IntToFloat\" -= \"Integer\"... "); - test_fvalue(0.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 21, &null), - "Check element 22 of \"IntToFloat\" -= \"Integer\"... "); - cpl_test_zero(null); - - test(cpl_table_multiply_columns(table, "IntToFloat", "Double"), - "Multiply double column with float column... "); - - test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 0), - "Check element 1 of \"IntToFloat\" *= \"Double\"... "); - test_fvalue(0.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 1, &null), - "Check element 2 of \"IntToFloat\" *= \"Double\"... "); - cpl_test_zero(null); - test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 2), - "Check element 3 of \"IntToFloat\" *= \"Double\"... "); - test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 3), - "Check element 4 of \"IntToFloat\" *= \"Double\"... "); - test_fvalue(0.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 4, &null), - "Check element 5 of \"IntToFloat\" *= \"Double\"... "); - cpl_test_zero(null); - test_fvalue(0.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 5, &null), - "Check element 6 of \"IntToFloat\" *= \"Double\"... "); - cpl_test_zero(null); - test_fvalue(-1110.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 6, &null), - "Check element 7 of \"IntToFloat\" *= \"Double\"... "); - cpl_test_zero(null); - test_fvalue(-999880.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 7, &null), - "Check element 8 of \"IntToFloat\" *= \"Double\"... "); - cpl_test_zero(null); - test_fvalue(0.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 8, &null), - "Check element 9 of \"IntToFloat\" *= \"Double\"... "); - cpl_test_zero(null); - test_fvalue(0.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 9, &null), - "Check element 10 of \"IntToFloat\" *= \"Double\"... "); - cpl_test_zero(null); - test_fvalue(0.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 10, &null), - "Check element 11 of \"IntToFloat\" *= \"Double\"... "); - cpl_test_zero(null); - test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 11), - "Check element 12 of \"IntToFloat\" *= \"Double\"... "); - test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 12), - "Check element 13 of \"IntToFloat\" *= \"Double\"... "); - test_fvalue(-28.44, 0.00001, - cpl_table_get_float(table, "IntToFloat", 13, &null), - "Check element 14 of \"IntToFloat\" *= \"Double\"... "); - cpl_test_zero(null); - test_fvalue(6.66, 0.00001, - cpl_table_get_float(table, "IntToFloat", 14, &null), - "Check element 15 of \"IntToFloat\" *= \"Double\"... "); - cpl_test_zero(null); - test_fvalue(-12.33, 0.00001, - cpl_table_get_float(table, "IntToFloat", 15, &null), - "Check element 16 of \"IntToFloat\" *= \"Double\"... "); - cpl_test_zero(null); - test_fvalue(-12.22, 0.00001, - cpl_table_get_float(table, "IntToFloat", 16, &null), - "Check element 17 of \"IntToFloat\" *= \"Double\"... "); - cpl_test_zero(null); - test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 17), - "Check element 18 of \"IntToFloat\" *= \"Double\"... "); - test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 18), - "Check element 19 of \"IntToFloat\" *= \"Double\"... "); - test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 19), - "Check element 20 of \"IntToFloat\" *= \"Double\"... "); - test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 20), - "Check element 21 of \"IntToFloat\" *= \"Double\"... "); - test_fvalue(0.0, 0.00001, - cpl_table_get_float(table, "IntToFloat", 21, &null), - "Check element 22 of \"IntToFloat\" *= \"Double\"... "); - cpl_test_zero(null); - - test(cpl_table_divide_columns(table, "Float", "IntToFloat"), - "Divide float column with float column... "); - - test_ivalue(0, cpl_table_is_valid(table, "Float", 0), - "Check element 1 of \"Float\" /= \"IntToFloat\"... "); - test_ivalue(0, cpl_table_is_valid(table, "Float", 1), - "Check element 2 of \"Float\" /= \"IntToFloat\"... "); - test_ivalue(0, cpl_table_is_valid(table, "Float", 2), - "Check element 3 of \"Float\" /= \"IntToFloat\"... "); - test_ivalue(0, cpl_table_is_valid(table, "Float", 3), - "Check element 4 of \"Float\" /= \"IntToFloat\"... "); - test_ivalue(0, cpl_table_is_valid(table, "Float", 4), - "Check element 5 of \"Float\" /= \"IntToFloat\"... "); - test_ivalue(0, cpl_table_is_valid(table, "Float", 5), - "Check element 6 of \"Float\" /= \"IntToFloat\"... "); - test_fvalue(0.000991, 0.0000001, - cpl_table_get_float(table, "Float", 6, &null), - "Check element 7 of \"Float\" /= \"IntToFloat\"... "); - cpl_test_zero(null); - test_fvalue(-0.0010001, 0.0000001, - cpl_table_get_float(table, "Float", 7, &null), - "Check element 8 of \"Float\" /= \"IntToFloat\"... "); - cpl_test_zero(null); - test_ivalue(0, cpl_table_is_valid(table, "Float", 8), - "Check element 9 of \"Float\" /= \"IntToFloat\"... "); - test_ivalue(0, cpl_table_is_valid(table, "Float", 9), - "Check element 10 of \"Float\" /= \"IntToFloat\"... "); - test_ivalue(0, cpl_table_is_valid(table, "Float", 10), - "Check element 11 of \"Float\" /= \"IntToFloat\"... "); - test_ivalue(0, cpl_table_is_valid(table, "Float", 11), - "Check element 12 of \"Float\" /= \"IntToFloat\"... "); - test_ivalue(0, cpl_table_is_valid(table, "Float", 12), - "Check element 13 of \"Float\" /= \"IntToFloat\"... "); - test_fvalue(-0.2496484, 0.0000001, - cpl_table_get_float(table, "Float", 13, &null), - "Check element 14 of \"Float\" /= \"IntToFloat\"... "); - cpl_test_zero(null); - test_fvalue(0.1651652, 0.0000001, - cpl_table_get_float(table, "Float", 14, &null), - "Check element 15 of \"Float\" /= \"IntToFloat\"... "); - cpl_test_zero(null); - test_fvalue(-0.3325223, 0.0000001, - cpl_table_get_float(table, "Float", 15, &null), - "Check element 16 of \"Float\" /= \"IntToFloat\"... "); - cpl_test_zero(null); - test_fvalue(-0.4991817, 0.0000001, - cpl_table_get_float(table, "Float", 16, &null), - "Check element 17 of \"Float\" /= \"IntToFloat\"... "); - cpl_test_zero(null); - test_ivalue(0, cpl_table_is_valid(table, "Float", 17), - "Check element 18 of \"Float\" /= \"IntToFloat\"... "); - test_ivalue(0, cpl_table_is_valid(table, "Float", 18), - "Check element 19 of \"Float\" /= \"IntToFloat\"... "); - test_ivalue(0, cpl_table_is_valid(table, "Float", 19), - "Check element 20 of \"Float\" /= \"IntToFloat\"... "); - test_ivalue(0, cpl_table_is_valid(table, "Float", 20), - "Check element 21 of \"Float\" /= \"IntToFloat\"... "); - test_ivalue(0, cpl_table_is_valid(table, "Float", 21), - "Check element 22 of \"Float\" /= \"IntToFloat\"... "); - - test(cpl_table_add_scalar(table, "Float", 1), - "Add integer constant to \"Float\"... "); - - test_ivalue(0, cpl_table_is_valid(table, "Float", 0), - "Check element 1 of adding 1 to \"Float\"... "); - test_ivalue(0, cpl_table_is_valid(table, "Float", 1), - "Check element 2 of adding 1 to \"Float\"... "); - test_ivalue(0, cpl_table_is_valid(table, "Float", 2), - "Check element 3 of adding 1 to \"Float\"... "); - test_ivalue(0, cpl_table_is_valid(table, "Float", 3), - "Check element 4 of adding 1 to \"Float\"... "); - test_ivalue(0, cpl_table_is_valid(table, "Float", 4), - "Check element 5 of adding 1 to \"Float\"... "); - test_ivalue(0, cpl_table_is_valid(table, "Float", 5), - "Check element 6 of adding 1 to \"Float\"... "); - test_fvalue(1.000991, 0.0000001, - cpl_table_get_float(table, "Float", 6, &null), - "Check element 7 of adding 1 to \"Float\"... "); - cpl_test_zero(null); - test_fvalue(1-0.0010001, 0.0000001, - cpl_table_get_float(table, "Float", 7, &null), - "Check element 8 of adding 1 to \"Float\"... "); - cpl_test_zero(null); - test_ivalue(0, cpl_table_is_valid(table, "Float", 8), - "Check element 9 of adding 1 to \"Float\"... "); - test_ivalue(0, cpl_table_is_valid(table, "Float", 9), - "Check element 10 of adding 1 to \"Float\"... "); - test_ivalue(0, cpl_table_is_valid(table, "Float", 10), - "Check element 11 of adding 1 to \"Float\"... "); - test_ivalue(0, cpl_table_is_valid(table, "Float", 11), - "Check element 12 of adding 1 to \"Float\"... "); - test_ivalue(0, cpl_table_is_valid(table, "Float", 12), - "Check element 13 of adding 1 to \"Float\"... "); - test_fvalue(1-0.2496484, 0.0000001, - cpl_table_get_float(table, "Float", 13, &null), - "Check element 14 of adding 1 to \"Float\"... "); - cpl_test_zero(null); - test_fvalue(1.1651652, 0.0000001, - cpl_table_get_float(table, "Float", 14, &null), - "Check element 15 of adding 1 to \"Float\"... "); - cpl_test_zero(null); - test_fvalue(1-0.3325223, 0.0000001, - cpl_table_get_float(table, "Float", 15, &null), - "Check element 16 of adding 1 to \"Float\"... "); - cpl_test_zero(null); - test_fvalue(1-0.4991817, 0.0000001, - cpl_table_get_float(table, "Float", 16, &null), - "Check element 17 of adding 1 to \"Float\"... "); - cpl_test_zero(null); - test_ivalue(0, cpl_table_is_valid(table, "Float", 17), - "Check element 18 of adding 1 to \"Float\"... "); - test_ivalue(0, cpl_table_is_valid(table, "Float", 18), - "Check element 19 of adding 1 to \"Float\"... "); - test_ivalue(0, cpl_table_is_valid(table, "Float", 19), - "Check element 20 of adding 1 to \"Float\"... "); - test_ivalue(0, cpl_table_is_valid(table, "Float", 20), - "Check element 21 of adding 1 to \"Float\"... "); - test_ivalue(0, cpl_table_is_valid(table, "Float", 21), - "Check element 22 of adding 1 to \"Float\"... "); - - test(cpl_table_set_column_invalid(table, "Float", 0, - cpl_table_get_nrow(table)), - "Set \"Float\" column to NULL... "); - - copia = cpl_table_duplicate(table); - cpl_test_nonnull(copia); - - test(cpl_table_erase_invalid_rows(table), "Pruning table... "); - - test_ivalue(18, cpl_table_get_nrow(table), - "Checking table length after pruning... "); - - test_ivalue(10, cpl_table_get_ncol(table), - "Checking table width after pruning... "); - - test(cpl_table_erase_invalid(copia), "Cleaning table... "); + test(cpl_table_erase_invalid_rows(table), "Pruning table... "); - test_ivalue(8, cpl_table_get_nrow(copia), - "Checking table length after cleaning... "); + test_ivalue(18, cpl_table_get_nrow(table), + "Checking table length after pruning... "); - test_ivalue(10, cpl_table_get_ncol(copia), - "Checking table width after cleaning... "); + test_ivalue(10, cpl_table_get_ncol(table), + "Checking table width after pruning... "); - cpl_table_delete(copia); + test(cpl_table_erase_invalid(copia), "Cleaning table... "); + test_ivalue(8, cpl_table_get_nrow(copia), + "Checking table length after cleaning... "); + test_ivalue(10, cpl_table_get_ncol(copia), + "Checking table width after cleaning... "); + cpl_table_delete(copia); } @@ -5390,378 +5504,378 @@ table 20 + 22 if it is pasted into cpl_table_test_main() */ /*----------------------------------------------------------------------------*/ -static void cpl_table_test_21(cpl_table * table) +static void +cpl_table_test_21(cpl_table *table) { - cpl_size i; - int null; - char message[80]; - const char *names[2]; - cpl_table *copia; - cpl_propertylist *reflist; - cpl_error_code error; - - - test_svalue("Pixel", cpl_table_get_column_unit(table, "AInt"), - "Check column unit... "); + cpl_size i; + int null; + char message[80]; + const char *names[2]; + cpl_table *copia; + cpl_propertylist *reflist; + cpl_error_code error; -/* - if (strcmp(unit = (char *)cpl_table_get_column_unit(table, "AInt"), - "Pixel")) { - printf("Check column unit... "); - printf("Expected \"Pixel\", obtained \"%s\"\n", unit); - cpl_end(); - return 1; - } -*/ - test_ivalue(18, cpl_table_get_nrow(table), - "Checking table length after sorting... "); + test_svalue("Pixel", cpl_table_get_column_unit(table, "AInt"), + "Check column unit... "); - test_ivalue(11, cpl_table_get_ncol(table), - "Checking table width after sorting... "); + /* + if (strcmp(unit = (char *)cpl_table_get_column_unit(table, "AInt"), + "Pixel")) { + printf("Check column unit... "); + printf("Expected \"Pixel\", obtained \"%s\"\n", unit); + cpl_end(); + return 1; + } + */ - test_ivalue(7, cpl_table_count_invalid(table, "Integer"), - "Count \"Integer\" NULLs after sorting... "); + test_ivalue(18, cpl_table_get_nrow(table), + "Checking table length after sorting... "); - test_ivalue(7, cpl_table_count_invalid(table, "Float"), - "Count \"Float\" NULLs after sorting... "); + test_ivalue(11, cpl_table_get_ncol(table), + "Checking table width after sorting... "); - test_ivalue(2, cpl_table_count_invalid(table, "Double"), - "Count \"Double\" NULLs after sorting... "); + test_ivalue(7, cpl_table_count_invalid(table, "Integer"), + "Count \"Integer\" NULLs after sorting... "); - test_ivalue(2, cpl_table_count_invalid(table, "String"), - "Count \"String\" NULLs after sorting... "); + test_ivalue(7, cpl_table_count_invalid(table, "Float"), + "Count \"Float\" NULLs after sorting... "); - for (i = 0; i < 7; i++) { - sprintf(message, "Check element %" CPL_SIZE_FORMAT - " of sorted \"Integer\"... ", i + 1); - test_ivalue(0, cpl_table_is_valid(table, "Integer", i), message); - } + test_ivalue(2, cpl_table_count_invalid(table, "Double"), + "Count \"Double\" NULLs after sorting... "); - test_ivalue(-1, cpl_table_get_int(table, "Integer", 7, &null), - "Check element 7 of sorted \"Integer\"... "); - cpl_test_zero(null); + test_ivalue(2, cpl_table_count_invalid(table, "String"), + "Count \"String\" NULLs after sorting... "); - test_ivalue(1, cpl_table_get_int(table, "Integer", 8, &null), - "Check element 8 of sorted \"Integer\"... "); - cpl_test_zero(null); + for (i = 0; i < 7; i++) { + sprintf(message, + "Check element %" CPL_SIZE_FORMAT " of sorted \"Integer\"... ", + i + 1); + test_ivalue(0, cpl_table_is_valid(table, "Integer", i), message); + } - test_ivalue(4, cpl_table_get_int(table, "Integer", 9, &null), - "Check element 9 of sorted \"Integer\"... "); - cpl_test_zero(null); + test_ivalue(-1, cpl_table_get_int(table, "Integer", 7, &null), + "Check element 7 of sorted \"Integer\"... "); + cpl_test_zero(null); - test_ivalue(6, cpl_table_get_int(table, "Integer", 10, &null), - "Check element 10 of sorted \"Integer\"... "); - cpl_test_zero(null); + test_ivalue(1, cpl_table_get_int(table, "Integer", 8, &null), + "Check element 8 of sorted \"Integer\"... "); + cpl_test_zero(null); - test_ivalue(7, cpl_table_get_int(table, "Integer", 11, &null), - "Check element 11 of sorted \"Integer\"... "); - cpl_test_zero(null); + test_ivalue(4, cpl_table_get_int(table, "Integer", 9, &null), + "Check element 9 of sorted \"Integer\"... "); + cpl_test_zero(null); - for (i = 12; i < 18; i++) { - sprintf(message, "Check element %" CPL_SIZE_FORMAT - " of sorted \"Integer\"... ", i + 1); - test_ivalue(999, cpl_table_get_int(table, "Integer", i, &null), - message); + test_ivalue(6, cpl_table_get_int(table, "Integer", 10, &null), + "Check element 10 of sorted \"Integer\"... "); cpl_test_zero(null); - } - test_fvalue(999.88, 0.00001, - cpl_table_get_double(table, "Double", 0, &null), - "Check element 1 of sorted \"Double\"... "); - cpl_test_zero(null); + test_ivalue(7, cpl_table_get_int(table, "Integer", 11, &null), + "Check element 11 of sorted \"Integer\"... "); + cpl_test_zero(null); - test_fvalue(999.88, 0.00001, - cpl_table_get_double(table, "Double", 1, &null), - "Check element 2 of sorted \"Double\"... "); - cpl_test_zero(null); + for (i = 12; i < 18; i++) { + sprintf(message, + "Check element %" CPL_SIZE_FORMAT " of sorted \"Integer\"... ", + i + 1); + test_ivalue(999, cpl_table_get_int(table, "Integer", i, &null), + message); + cpl_test_zero(null); + } - test_ivalue(0, cpl_table_is_valid(table, "Double", 2), - "Check element 3 of sorted \"Double\"... "); + test_fvalue(999.88, 0.00001, + cpl_table_get_double(table, "Double", 0, &null), + "Check element 1 of sorted \"Double\"... "); + cpl_test_zero(null); - test_fvalue(999.88, 0.00001, - cpl_table_get_double(table, "Double", 3, &null), - "Check element 4 of sorted \"Double\"... "); - cpl_test_zero(null); + test_fvalue(999.88, 0.00001, + cpl_table_get_double(table, "Double", 1, &null), + "Check element 2 of sorted \"Double\"... "); + cpl_test_zero(null); - test_fvalue(3.11, 0.00001, - cpl_table_get_double(table, "Double", 4, &null), - "Check element 5 of sorted \"Double\"... "); - cpl_test_zero(null); + test_ivalue(0, cpl_table_is_valid(table, "Double", 2), + "Check element 3 of sorted \"Double\"... "); - test_ivalue(0, cpl_table_is_valid(table, "Double", 5), - "Check element 6 of sorted \"Double\"... "); + test_fvalue(999.88, 0.00001, + cpl_table_get_double(table, "Double", 3, &null), + "Check element 4 of sorted \"Double\"... "); + cpl_test_zero(null); - test_fvalue(999.88, 0.00001, - cpl_table_get_double(table, "Double", 6, &null), - "Check element 7 of sorted \"Double\"... "); - cpl_test_zero(null); + test_fvalue(3.11, 0.00001, cpl_table_get_double(table, "Double", 4, &null), + "Check element 5 of sorted \"Double\"... "); + cpl_test_zero(null); - test_fvalue(-1.11, 0.00001, - cpl_table_get_double(table, "Double", 7, &null), - "Check element 8 of sorted \"Double\"... "); - cpl_test_zero(null); + test_ivalue(0, cpl_table_is_valid(table, "Double", 5), + "Check element 6 of sorted \"Double\"... "); - test_fvalue(1.11, 0.00001, - cpl_table_get_double(table, "Double", 8, &null), - "Check element 9 of sorted \"Double\"... "); - cpl_test_zero(null); + test_fvalue(999.88, 0.00001, + cpl_table_get_double(table, "Double", 6, &null), + "Check element 7 of sorted \"Double\"... "); + cpl_test_zero(null); - test_fvalue(4.11, 0.00001, - cpl_table_get_double(table, "Double", 9, &null), - "Check element 10 of sorted \"Double\"... "); - cpl_test_zero(null); + test_fvalue(-1.11, 0.00001, cpl_table_get_double(table, "Double", 7, &null), + "Check element 8 of sorted \"Double\"... "); + cpl_test_zero(null); - test_fvalue(6.11, 0.00001, - cpl_table_get_double(table, "Double", 10, &null), - "Check element 11 of sorted \"Double\"... "); - cpl_test_zero(null); + test_fvalue(1.11, 0.00001, cpl_table_get_double(table, "Double", 8, &null), + "Check element 9 of sorted \"Double\"... "); + cpl_test_zero(null); - test_fvalue(7.11, 0.00001, - cpl_table_get_double(table, "Double", 11, &null), - "Check element 12 of sorted \"Double\"... "); - cpl_test_zero(null); + test_fvalue(4.11, 0.00001, cpl_table_get_double(table, "Double", 9, &null), + "Check element 10 of sorted \"Double\"... "); + cpl_test_zero(null); - for (i = 12; i < 18; i++) { - sprintf(message, "Check element %" CPL_SIZE_FORMAT - " of sorted \"Double\"... ", i + 1); - test_fvalue(999.88, 0.00001, - cpl_table_get_double(table, "Double", i, &null), message); - cpl_test_zero(null); - } + test_fvalue(6.11, 0.00001, cpl_table_get_double(table, "Double", 10, &null), + "Check element 11 of sorted \"Double\"... "); + cpl_test_zero(null); - test_svalue("999", cpl_table_get_string(table, "String", 0), - "Check element 1 of sorted \"String\"... "); + test_fvalue(7.11, 0.00001, cpl_table_get_double(table, "Double", 11, &null), + "Check element 12 of sorted \"Double\"... "); + cpl_test_zero(null); - test_svalue("999", cpl_table_get_string(table, "String", 1), - "Check element 2 of sorted \"String\"... "); + for (i = 12; i < 18; i++) { + sprintf(message, + "Check element %" CPL_SIZE_FORMAT " of sorted \"Double\"... ", + i + 1); + test_fvalue(999.88, 0.00001, + cpl_table_get_double(table, "Double", i, &null), message); + cpl_test_zero(null); + } - test_ivalue(0, cpl_table_is_valid(table, "String", 2), - "Check element 3 of sorted \"String\"... "); + test_svalue("999", cpl_table_get_string(table, "String", 0), + "Check element 1 of sorted \"String\"... "); - test_svalue("999", cpl_table_get_string(table, "String", 3), - "Check element 4 of sorted \"String\"... "); + test_svalue("999", cpl_table_get_string(table, "String", 1), + "Check element 2 of sorted \"String\"... "); - test_svalue("baaa", cpl_table_get_string(table, "String", 4), - "Check element 5 of sorted \"String\"... "); + test_ivalue(0, cpl_table_is_valid(table, "String", 2), + "Check element 3 of sorted \"String\"... "); - test_ivalue(0, cpl_table_is_valid(table, "String", 5), - "Check element 6 of sorted \"String\"... "); + test_svalue("999", cpl_table_get_string(table, "String", 3), + "Check element 4 of sorted \"String\"... "); - test_svalue("999", cpl_table_get_string(table, "String", 6), - "Check element 7 of sorted \"String\"... "); + test_svalue("baaa", cpl_table_get_string(table, "String", 4), + "Check element 5 of sorted \"String\"... "); - test_svalue("extra", cpl_table_get_string(table, "String", 7), - "Check element 8 of sorted \"String\"... "); + test_ivalue(0, cpl_table_is_valid(table, "String", 5), + "Check element 6 of sorted \"String\"... "); - test_svalue("acde", cpl_table_get_string(table, "String", 8), - "Check element 9 of sorted \"String\"... "); + test_svalue("999", cpl_table_get_string(table, "String", 6), + "Check element 7 of sorted \"String\"... "); - test_svalue(" sss", cpl_table_get_string(table, "String", 9), - "Check element 10 of sorted \"String\"... "); + test_svalue("extra", cpl_table_get_string(table, "String", 7), + "Check element 8 of sorted \"String\"... "); - test_svalue("daaa", cpl_table_get_string(table, "String", 10), - "Check element 11 of sorted \"String\"... "); + test_svalue("acde", cpl_table_get_string(table, "String", 8), + "Check element 9 of sorted \"String\"... "); - test_svalue("aaaa", cpl_table_get_string(table, "String", 11), - "Check element 11 of sorted \"String\"... "); + test_svalue(" sss", cpl_table_get_string(table, "String", 9), + "Check element 10 of sorted \"String\"... "); - for (i = 12; i < 18; i++) { - sprintf(message, "Check element %" CPL_SIZE_FORMAT - " of sorted \"String\"... ", i + 1); - test_svalue("999", cpl_table_get_string(table, "String", i), message); - } + test_svalue("daaa", cpl_table_get_string(table, "String", 10), + "Check element 11 of sorted \"String\"... "); - test_ivalue(0, cpl_table_is_valid(table, "Float", 0), - "Check element 1 of sorted \"Float\"... "); + test_svalue("aaaa", cpl_table_get_string(table, "String", 11), + "Check element 11 of sorted \"String\"... "); - test_ivalue(0, cpl_table_is_valid(table, "Float", 1), - "Check element 2 of sorted \"Float\"... "); + for (i = 12; i < 18; i++) { + sprintf(message, + "Check element %" CPL_SIZE_FORMAT " of sorted \"String\"... ", + i + 1); + test_svalue("999", cpl_table_get_string(table, "String", i), message); + } - test_ivalue(0, cpl_table_is_valid(table, "Float", 2), - "Check element 3 of sorted \"Float\"... "); + test_ivalue(0, cpl_table_is_valid(table, "Float", 0), + "Check element 1 of sorted \"Float\"... "); - test_fvalue(0.0, 0.00001, cpl_table_get_float(table, "Float", 3, &null), - "Check element 4 of sorted \"Float\"... "); - cpl_test_zero(null); + test_ivalue(0, cpl_table_is_valid(table, "Float", 1), + "Check element 2 of sorted \"Float\"... "); - test_ivalue(0, cpl_table_is_valid(table, "Float", 4), - "Check element 5 of sorted \"Float\"... "); + test_ivalue(0, cpl_table_is_valid(table, "Float", 2), + "Check element 3 of sorted \"Float\"... "); - test_ivalue(0, cpl_table_is_valid(table, "Float", 5), - "Check element 6 of sorted \"Float\"... "); + test_fvalue(0.0, 0.00001, cpl_table_get_float(table, "Float", 3, &null), + "Check element 4 of sorted \"Float\"... "); + cpl_test_zero(null); - test_ivalue(0, cpl_table_is_valid(table, "Float", 6), - "Check element 7 of sorted \"Float\"... "); + test_ivalue(0, cpl_table_is_valid(table, "Float", 4), + "Check element 5 of sorted \"Float\"... "); - test_fvalue(-1110.0, 0.00001, - cpl_table_get_float(table, "Float", 7, &null), - "Check element 8 of sorted \"Float\"... "); - cpl_test_zero(null); + test_ivalue(0, cpl_table_is_valid(table, "Float", 5), + "Check element 6 of sorted \"Float\"... "); - test_fvalue(6.66, 0.00001, - cpl_table_get_float(table, "Float", 8, &null), - "Check element 9 of sorted \"Float\"... "); - cpl_test_zero(null); + test_ivalue(0, cpl_table_is_valid(table, "Float", 6), + "Check element 7 of sorted \"Float\"... "); - test_fvalue(-12.33, 0.00001, - cpl_table_get_float(table, "Float", 9, &null), - "Check element 10 of sorted \"Float\"... "); - cpl_test_zero(null); + test_fvalue(-1110.0, 0.00001, cpl_table_get_float(table, "Float", 7, &null), + "Check element 8 of sorted \"Float\"... "); + cpl_test_zero(null); - test_fvalue(-12.22, 0.00001, - cpl_table_get_float(table, "Float", 10, &null), - "Check element 11 of sorted \"Float\"... "); - cpl_test_zero(null); + test_fvalue(6.66, 0.00001, cpl_table_get_float(table, "Float", 8, &null), + "Check element 9 of sorted \"Float\"... "); + cpl_test_zero(null); - test_fvalue(-28.44, 0.00001, - cpl_table_get_float(table, "Float", 11, &null), - "Check element 12 of sorted \"Float\"... "); - cpl_test_zero(null); + test_fvalue(-12.33, 0.00001, cpl_table_get_float(table, "Float", 9, &null), + "Check element 10 of sorted \"Float\"... "); + cpl_test_zero(null); - test_fvalue(0.0, 0.00001, - cpl_table_get_float(table, "Float", 12, &null), - "Check element 13 of sorted \"Float\"... "); - cpl_test_zero(null); + test_fvalue(-12.22, 0.00001, cpl_table_get_float(table, "Float", 10, &null), + "Check element 11 of sorted \"Float\"... "); + cpl_test_zero(null); - test_fvalue(0.0, 0.00001, - cpl_table_get_float(table, "Float", 13, &null), - "Check element 14 of sorted \"Float\"... "); - cpl_test_zero(null); + test_fvalue(-28.44, 0.00001, cpl_table_get_float(table, "Float", 11, &null), + "Check element 12 of sorted \"Float\"... "); + cpl_test_zero(null); - test_fvalue(0.0, 0.00001, - cpl_table_get_float(table, "Float", 14, &null), - "Check element 15 of sorted \"Float\"... "); - cpl_test_zero(null); + test_fvalue(0.0, 0.00001, cpl_table_get_float(table, "Float", 12, &null), + "Check element 13 of sorted \"Float\"... "); + cpl_test_zero(null); - test_fvalue(-999880.0, 0.00001, - cpl_table_get_float(table, "Float", 15, &null), - "Check element 16 of sorted \"Float\"... "); - cpl_test_zero(null); + test_fvalue(0.0, 0.00001, cpl_table_get_float(table, "Float", 13, &null), + "Check element 14 of sorted \"Float\"... "); + cpl_test_zero(null); - test_ivalue(0, cpl_table_is_valid(table, "Float", 16), - "Check element 17 of sorted \"Float\"... "); + test_fvalue(0.0, 0.00001, cpl_table_get_float(table, "Float", 14, &null), + "Check element 15 of sorted \"Float\"... "); + cpl_test_zero(null); - test_fvalue(0.0, 0.00001, - cpl_table_get_float(table, "Float", 17, &null), - "Check element 18 of sorted \"Float\"... "); - cpl_test_zero(null); + test_fvalue(-999880.0, 0.00001, + cpl_table_get_float(table, "Float", 15, &null), + "Check element 16 of sorted \"Float\"... "); + cpl_test_zero(null); - names[0] = "Sequence"; + test_ivalue(0, cpl_table_is_valid(table, "Float", 16), + "Check element 17 of sorted \"Float\"... "); - reflist = cpl_propertylist_new(); - cpl_propertylist_append_bool(reflist, names[0], 0); + test_fvalue(0.0, 0.00001, cpl_table_get_float(table, "Float", 17, &null), + "Check element 18 of sorted \"Float\"... "); + cpl_test_zero(null); - test(cpl_table_sort(table, reflist), "Undo table sorting... "); + names[0] = "Sequence"; - cpl_propertylist_delete(reflist); + reflist = cpl_propertylist_new(); + cpl_propertylist_append_bool(reflist, names[0], 0); - names[0] = "Integer"; + test(cpl_table_sort(table, reflist), "Undo table sorting... "); - reflist = cpl_propertylist_new(); - cpl_propertylist_append_bool(reflist, names[0], 1); + cpl_propertylist_delete(reflist); - test(cpl_table_sort(table, reflist), - "Sorting by decreasing values of the \"Integer\" column... "); + names[0] = "Integer"; -/* %$% */ -/* -cpl_table_dump_structure(table, NULL); -cpl_table_dump(table, 0, cpl_table_get_nrow(table), NULL); -*/ + reflist = cpl_propertylist_new(); + cpl_propertylist_append_bool(reflist, names[0], 1); -/* - cpl_table_dump_structure(table, NULL); - cpl_table_dump(table, 0, cpl_table_get_nrow(table), NULL); + test(cpl_table_sort(table, reflist), + "Sorting by decreasing values of the \"Integer\" column... "); - printf("Median of Integer: %d\n", cpl_table_median_int(table, "Integer")); - printf("Median of Float: %f\n", cpl_table_median_float(table, "Float")); - printf("Median of Double: %f\n", cpl_table_median_double(table, "Double")); - printf("Median of Sequence: %d\n", cpl_table_median_int(table, "Sequence")); -*/ + /* %$% */ + /* + cpl_table_dump_structure(table, NULL); + cpl_table_dump(table, 0, cpl_table_get_nrow(table), NULL); + */ - copia = cpl_table_extract(table, 12, 6); -/* + /* + cpl_table_dump_structure(table, NULL); + cpl_table_dump(table, 0, cpl_table_get_nrow(table), NULL); -cpl_table_dump_structure(table, NULL); -cpl_table_dump(table, 0, cpl_table_get_nrow(table), NULL); -cpl_table_dump_structure(copia, NULL); -cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), NULL); + printf("Median of Integer: %d\n", cpl_table_median_int(table, "Integer")); + printf("Median of Float: %f\n", cpl_table_median_float(table, "Float")); + printf("Median of Double: %f\n", cpl_table_median_double(table, "Double")); + printf("Median of Sequence: %d\n", cpl_table_median_int(table, "Sequence")); + */ - */ + copia = cpl_table_extract(table, 12, 6); + /* - test_fvalue(999.000000, 0.001, cpl_table_get_column_median(table, "Integer"), - "Median of Integer..."); - test_fvalue(0.000000, 0.001, cpl_table_get_column_median(table, "Float"), - "Median of Float..."); - test_fvalue(999.880000, 0.001, cpl_table_get_column_median(table, "Double"), - "Median of Double..."); - test_fvalue(8.000000, 0.001, cpl_table_get_column_median(table, "Sequence"), - "Median of Sequence..."); - test_fvalue(546.454545, 0.001, cpl_table_get_column_mean(table, "Integer"), - "Mean of Integer..."); - test_fvalue(-91003.302727, 0.001, cpl_table_get_column_mean(table, "Float"), - "Mean of Float..."); - test_fvalue(626.202500, 0.001, cpl_table_get_column_mean(table, "Double"), - "Mean of Double..."); - test_fvalue(8.500000, 0.001, cpl_table_get_column_mean(table, "Sequence"), - "Mean of Sequence..."); - test_fvalue(519.939489, 0.001, cpl_table_get_column_stdev(table, "Integer"), - "Stdev of Integer..."); - test_fvalue(301440.480937, 0.001, cpl_table_get_column_stdev(table, "Float"), - "Stdev of Float..."); - test_fvalue(498.239830, 0.001, cpl_table_get_column_stdev(table, "Double"), - "Stdev of Double..."); - test_fvalue(5.338539, 0.001, cpl_table_get_column_stdev(table, "Sequence"), - "Stdev of Sequence..."); - - /* Test on columns without invalid elements */ - - test_fvalue(406.463118, 0.001, cpl_table_get_column_stdev(copia, "Integer"), - "Stdev of Integer from 6 last elements..."); - test_fvalue(449.534137, 0.001, cpl_table_get_column_stdev(copia, "Float"), - "Stdev of Float from 6 last elements..."); - test_fvalue(406.795909, 0.001, cpl_table_get_column_stdev(copia, "Double"), - "Stdev of Double from 6 last elements..."); - - cpl_table_delete(copia); - - cpl_msg_info(cpl_func, "median of Integer: %f\n", cpl_table_get_column_median(table, "Integer")); - cpl_msg_info(cpl_func, "median of Float: %f\n", cpl_table_get_column_median(table, "Float")); - cpl_msg_info(cpl_func, "median of Double: %f\n", cpl_table_get_column_median(table, "Double")); - cpl_msg_info(cpl_func, "median of Sequence: %f\n", cpl_table_get_column_median(table, "Sequence")); - cpl_msg_info(cpl_func, "mean of Integer: %f\n", cpl_table_get_column_mean(table, "Integer")); - cpl_msg_info(cpl_func, "mean of Float: %f\n", cpl_table_get_column_mean(table, "Float")); - cpl_msg_info(cpl_func, "mean of Double: %f\n", cpl_table_get_column_mean(table, "Double")); - cpl_msg_info(cpl_func, "mean of Sequence: %f\n", cpl_table_get_column_mean(table, "Sequence")); - cpl_msg_info(cpl_func, "Stdev of Integer: %f\n", cpl_table_get_column_stdev(table, "Integer")); - cpl_msg_info(cpl_func, "Stdev of Float: %f\n", cpl_table_get_column_stdev(table, "Float")); - cpl_msg_info(cpl_func, "Stdev of Double: %f\n", cpl_table_get_column_stdev(table, "Double")); - cpl_msg_info(cpl_func, "Stdev of Sequence: %f\n", cpl_table_get_column_stdev(table, "Sequence")); - -/**- FIXME: RESTORE!!! */ - error = cpl_table_fill_invalid_int(table, "Integer", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_int(table, "AInt", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_fill_invalid_int(table, "New AInt", 320); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_table_save(table, NULL, NULL, BASE "22.fits", CPL_IO_CREATE); - cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_fits(BASE "22.fits"); - - /* Test sorting table with only invalid elements (exposes DFS04044) */ - for (i = 0; i < cpl_table_get_nrow(table); i++) { - error = cpl_table_set_invalid(table, "Integer",i); - cpl_test_eq_error(error, CPL_ERROR_NONE); - } - cpl_table_sort(table, reflist); + cpl_table_dump_structure(table, NULL); + cpl_table_dump(table, 0, cpl_table_get_nrow(table), NULL); + cpl_table_dump_structure(copia, NULL); + cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), NULL); - cpl_propertylist_delete(reflist); + */ + test_fvalue(999.000000, 0.001, + cpl_table_get_column_median(table, "Integer"), + "Median of Integer..."); + test_fvalue(0.000000, 0.001, cpl_table_get_column_median(table, "Float"), + "Median of Float..."); + test_fvalue(999.880000, 0.001, cpl_table_get_column_median(table, "Double"), + "Median of Double..."); + test_fvalue(8.000000, 0.001, cpl_table_get_column_median(table, "Sequence"), + "Median of Sequence..."); + test_fvalue(546.454545, 0.001, cpl_table_get_column_mean(table, "Integer"), + "Mean of Integer..."); + test_fvalue(-91003.302727, 0.001, cpl_table_get_column_mean(table, "Float"), + "Mean of Float..."); + test_fvalue(626.202500, 0.001, cpl_table_get_column_mean(table, "Double"), + "Mean of Double..."); + test_fvalue(8.500000, 0.001, cpl_table_get_column_mean(table, "Sequence"), + "Mean of Sequence..."); + test_fvalue(519.939489, 0.001, cpl_table_get_column_stdev(table, "Integer"), + "Stdev of Integer..."); + test_fvalue(301440.480937, 0.001, + cpl_table_get_column_stdev(table, "Float"), + "Stdev of Float..."); + test_fvalue(498.239830, 0.001, cpl_table_get_column_stdev(table, "Double"), + "Stdev of Double..."); + test_fvalue(5.338539, 0.001, cpl_table_get_column_stdev(table, "Sequence"), + "Stdev of Sequence..."); + + /* Test on columns without invalid elements */ + + test_fvalue(406.463118, 0.001, cpl_table_get_column_stdev(copia, "Integer"), + "Stdev of Integer from 6 last elements..."); + test_fvalue(449.534137, 0.001, cpl_table_get_column_stdev(copia, "Float"), + "Stdev of Float from 6 last elements..."); + test_fvalue(406.795909, 0.001, cpl_table_get_column_stdev(copia, "Double"), + "Stdev of Double from 6 last elements..."); + + cpl_table_delete(copia); + + cpl_msg_info(cpl_func, "median of Integer: %f\n", + cpl_table_get_column_median(table, "Integer")); + cpl_msg_info(cpl_func, "median of Float: %f\n", + cpl_table_get_column_median(table, "Float")); + cpl_msg_info(cpl_func, "median of Double: %f\n", + cpl_table_get_column_median(table, "Double")); + cpl_msg_info(cpl_func, "median of Sequence: %f\n", + cpl_table_get_column_median(table, "Sequence")); + cpl_msg_info(cpl_func, "mean of Integer: %f\n", + cpl_table_get_column_mean(table, "Integer")); + cpl_msg_info(cpl_func, "mean of Float: %f\n", + cpl_table_get_column_mean(table, "Float")); + cpl_msg_info(cpl_func, "mean of Double: %f\n", + cpl_table_get_column_mean(table, "Double")); + cpl_msg_info(cpl_func, "mean of Sequence: %f\n", + cpl_table_get_column_mean(table, "Sequence")); + cpl_msg_info(cpl_func, "Stdev of Integer: %f\n", + cpl_table_get_column_stdev(table, "Integer")); + cpl_msg_info(cpl_func, "Stdev of Float: %f\n", + cpl_table_get_column_stdev(table, "Float")); + cpl_msg_info(cpl_func, "Stdev of Double: %f\n", + cpl_table_get_column_stdev(table, "Double")); + cpl_msg_info(cpl_func, "Stdev of Sequence: %f\n", + cpl_table_get_column_stdev(table, "Sequence")); + /**- FIXME: RESTORE!!! */ + error = cpl_table_fill_invalid_int(table, "Integer", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_int(table, "AInt", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_fill_invalid_int(table, "New AInt", 320); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = cpl_table_save(table, NULL, NULL, BASE "22.fits", CPL_IO_CREATE); + cpl_test_eq_error(error, CPL_ERROR_NONE); + cpl_test_fits(BASE "22.fits"); + /* Test sorting table with only invalid elements (exposes DFS04044) */ + for (i = 0; i < cpl_table_get_nrow(table); i++) { + error = cpl_table_set_invalid(table, "Integer", i); + cpl_test_eq_error(error, CPL_ERROR_NONE); + } + cpl_table_sort(table, reflist); + cpl_propertylist_delete(reflist); } /*----------------------------------------------------------------------------*/ @@ -5775,248 +5889,238 @@ table 20 + 21 if it is pasted into cpl_table_test_main() */ /*----------------------------------------------------------------------------*/ -static void cpl_table_test_22(cpl_table * table) +static void +cpl_table_test_22(cpl_table *table) { - cpl_size i; - int null; - char message[80]; - + cpl_size i; + int null; + char message[80]; - test_ivalue(18, cpl_table_get_nrow(table), - "Checking table length after decreasing sorting... "); - test_ivalue(11, cpl_table_get_ncol(table), - "Checking table width after decreasing sorting... "); + test_ivalue(18, cpl_table_get_nrow(table), + "Checking table length after decreasing sorting... "); - test_ivalue(7, cpl_table_count_invalid(table, "Integer"), - "Count \"Integer\" NULLs after decreasing sorting... "); + test_ivalue(11, cpl_table_get_ncol(table), + "Checking table width after decreasing sorting... "); - test_ivalue(7, cpl_table_count_invalid(table, "Float"), - "Count \"Float\" NULLs after decreasing sorting... "); + test_ivalue(7, cpl_table_count_invalid(table, "Integer"), + "Count \"Integer\" NULLs after decreasing sorting... "); - test_ivalue(2, cpl_table_count_invalid(table, "Double"), - "Count \"Double\" NULLs after decreasing sorting... "); + test_ivalue(7, cpl_table_count_invalid(table, "Float"), + "Count \"Float\" NULLs after decreasing sorting... "); - test_ivalue(2, cpl_table_count_invalid(table, "String"), - "Count \"String\" NULLs after decreasing sorting... "); + test_ivalue(2, cpl_table_count_invalid(table, "Double"), + "Count \"Double\" NULLs after decreasing sorting... "); - for (i = 0; i < 7; i++) { - sprintf(message, "Check element %" CPL_SIZE_FORMAT - " of sorted \"Integer\"... ", i + 1); - test_ivalue(0, cpl_table_is_valid(table, "Integer", i), message); - } + test_ivalue(2, cpl_table_count_invalid(table, "String"), + "Count \"String\" NULLs after decreasing sorting... "); - for (i = 7; i < 13; i++) { - sprintf(message, "Check element %" CPL_SIZE_FORMAT - " of sorted \"Integer\"... ", i + 1); - test_ivalue(999, cpl_table_get_int(table, "Integer", i, &null), - message); - cpl_test_zero(null); - } + for (i = 0; i < 7; i++) { + sprintf(message, + "Check element %" CPL_SIZE_FORMAT " of sorted \"Integer\"... ", + i + 1); + test_ivalue(0, cpl_table_is_valid(table, "Integer", i), message); + } - test_ivalue(7, cpl_table_get_int(table, "Integer", 13, &null), - "Check element 13 of sorted \"Integer\"... "); - cpl_test_zero(null); + for (i = 7; i < 13; i++) { + sprintf(message, + "Check element %" CPL_SIZE_FORMAT " of sorted \"Integer\"... ", + i + 1); + test_ivalue(999, cpl_table_get_int(table, "Integer", i, &null), + message); + cpl_test_zero(null); + } - test_ivalue(6, cpl_table_get_int(table, "Integer", 14, &null), - "Check element 14 of sorted \"Integer\"... "); - cpl_test_zero(null); + test_ivalue(7, cpl_table_get_int(table, "Integer", 13, &null), + "Check element 13 of sorted \"Integer\"... "); + cpl_test_zero(null); - test_ivalue(4, cpl_table_get_int(table, "Integer", 15, &null), - "Check element 15 of sorted \"Integer\"... "); - cpl_test_zero(null); + test_ivalue(6, cpl_table_get_int(table, "Integer", 14, &null), + "Check element 14 of sorted \"Integer\"... "); + cpl_test_zero(null); - test_ivalue(1, cpl_table_get_int(table, "Integer", 16, &null), - "Check element 16 of sorted \"Integer\"... "); - cpl_test_zero(null); + test_ivalue(4, cpl_table_get_int(table, "Integer", 15, &null), + "Check element 15 of sorted \"Integer\"... "); + cpl_test_zero(null); - test_ivalue(-1, cpl_table_get_int(table, "Integer", 17, &null), - "Check element 17 of sorted \"Integer\"... "); - cpl_test_zero(null); + test_ivalue(1, cpl_table_get_int(table, "Integer", 16, &null), + "Check element 16 of sorted \"Integer\"... "); + cpl_test_zero(null); + test_ivalue(-1, cpl_table_get_int(table, "Integer", 17, &null), + "Check element 17 of sorted \"Integer\"... "); + cpl_test_zero(null); - test_fvalue(999.88, 0.00001, - cpl_table_get_double(table, "Double", 0, &null), - "Check element 1 of sorted \"Double\"... "); - cpl_test_zero(null); - test_fvalue(999.88, 0.00001, - cpl_table_get_double(table, "Double", 1, &null), - "Check element 2 of sorted \"Double\"... "); - cpl_test_zero(null); + test_fvalue(999.88, 0.00001, + cpl_table_get_double(table, "Double", 0, &null), + "Check element 1 of sorted \"Double\"... "); + cpl_test_zero(null); - test_ivalue(0, cpl_table_is_valid(table, "Double", 2), - "Check element 3 of sorted \"Double\"... "); + test_fvalue(999.88, 0.00001, + cpl_table_get_double(table, "Double", 1, &null), + "Check element 2 of sorted \"Double\"... "); + cpl_test_zero(null); - test_fvalue(999.88, 0.00001, - cpl_table_get_double(table, "Double", 3, &null), - "Check element 4 of sorted \"Double\"... "); - cpl_test_zero(null); + test_ivalue(0, cpl_table_is_valid(table, "Double", 2), + "Check element 3 of sorted \"Double\"... "); - test_fvalue(3.11, 0.00001, - cpl_table_get_double(table, "Double", 4, &null), - "Check element 5 of sorted \"Double\"... "); - cpl_test_zero(null); + test_fvalue(999.88, 0.00001, + cpl_table_get_double(table, "Double", 3, &null), + "Check element 4 of sorted \"Double\"... "); + cpl_test_zero(null); - test_ivalue(0, cpl_table_is_valid(table, "Double", 5), - "Check element 6 of sorted \"Double\"... "); + test_fvalue(3.11, 0.00001, cpl_table_get_double(table, "Double", 4, &null), + "Check element 5 of sorted \"Double\"... "); + cpl_test_zero(null); - test_fvalue(999.88, 0.00001, - cpl_table_get_double(table, "Double", 6, &null), - "Check element 7 of sorted \"Double\"... "); - cpl_test_zero(null); + test_ivalue(0, cpl_table_is_valid(table, "Double", 5), + "Check element 6 of sorted \"Double\"... "); - for (i = 7; i < 13; i++) { - sprintf(message, "Check element %" CPL_SIZE_FORMAT - " of sorted \"Double\"... ", i + 1); test_fvalue(999.88, 0.00001, - cpl_table_get_double(table, "Double", i, &null), message); - cpl_test_zero(null); - } - - test_fvalue(7.11, 0.00001, - cpl_table_get_double(table, "Double", 13, &null), - "Check element 14 of sorted \"Double\"... "); - cpl_test_zero(null); + cpl_table_get_double(table, "Double", 6, &null), + "Check element 7 of sorted \"Double\"... "); + cpl_test_zero(null); - test_fvalue(6.11, 0.00001, - cpl_table_get_double(table, "Double", 14, &null), - "Check element 15 of sorted \"Double\"... "); - cpl_test_zero(null); + for (i = 7; i < 13; i++) { + sprintf(message, + "Check element %" CPL_SIZE_FORMAT " of sorted \"Double\"... ", + i + 1); + test_fvalue(999.88, 0.00001, + cpl_table_get_double(table, "Double", i, &null), message); + cpl_test_zero(null); + } - test_fvalue(4.11, 0.00001, - cpl_table_get_double(table, "Double", 15, &null), - "Check element 16 of sorted \"Double\"... "); - cpl_test_zero(null); + test_fvalue(7.11, 0.00001, cpl_table_get_double(table, "Double", 13, &null), + "Check element 14 of sorted \"Double\"... "); + cpl_test_zero(null); - test_fvalue(1.11, 0.00001, - cpl_table_get_double(table, "Double", 16, &null), - "Check element 17 of sorted \"Double\"... "); - cpl_test_zero(null); + test_fvalue(6.11, 0.00001, cpl_table_get_double(table, "Double", 14, &null), + "Check element 15 of sorted \"Double\"... "); + cpl_test_zero(null); - test_fvalue(-1.11, 0.00001, - cpl_table_get_double(table, "Double", 17, &null), - "Check element 18 of sorted \"Double\"... "); - cpl_test_zero(null); + test_fvalue(4.11, 0.00001, cpl_table_get_double(table, "Double", 15, &null), + "Check element 16 of sorted \"Double\"... "); + cpl_test_zero(null); + test_fvalue(1.11, 0.00001, cpl_table_get_double(table, "Double", 16, &null), + "Check element 17 of sorted \"Double\"... "); + cpl_test_zero(null); - test_svalue("999", cpl_table_get_string(table, "String", 0), - "Check element 1 of sorted \"String\"... "); + test_fvalue(-1.11, 0.00001, + cpl_table_get_double(table, "Double", 17, &null), + "Check element 18 of sorted \"Double\"... "); + cpl_test_zero(null); - test_svalue("999", cpl_table_get_string(table, "String", 1), - "Check element 2 of sorted \"String\"... "); - test_ivalue(0, cpl_table_is_valid(table, "String", 2), - "Check element 3 of sorted \"String\"... "); + test_svalue("999", cpl_table_get_string(table, "String", 0), + "Check element 1 of sorted \"String\"... "); - test_svalue("999", cpl_table_get_string(table, "String", 3), - "Check element 4 of sorted \"String\"... "); + test_svalue("999", cpl_table_get_string(table, "String", 1), + "Check element 2 of sorted \"String\"... "); - test_svalue("baaa", cpl_table_get_string(table, "String", 4), - "Check element 5 of sorted \"String\"... "); + test_ivalue(0, cpl_table_is_valid(table, "String", 2), + "Check element 3 of sorted \"String\"... "); - test_ivalue(0, cpl_table_is_valid(table, "String", 5), - "Check element 6 of sorted \"String\"... "); + test_svalue("999", cpl_table_get_string(table, "String", 3), + "Check element 4 of sorted \"String\"... "); - test_svalue("999", cpl_table_get_string(table, "String", 6), - "Check element 7 of sorted \"String\"... "); + test_svalue("baaa", cpl_table_get_string(table, "String", 4), + "Check element 5 of sorted \"String\"... "); - for (i = 7; i < 13; i++) { - sprintf(message, "Check element %" CPL_SIZE_FORMAT - " of sorted \"String\"... ", i + 1); - test_svalue("999", cpl_table_get_string(table, "String", i), message); - } + test_ivalue(0, cpl_table_is_valid(table, "String", 5), + "Check element 6 of sorted \"String\"... "); - test_svalue("aaaa", cpl_table_get_string(table, "String", 13), - "Check element 14 of sorted \"String\"... "); + test_svalue("999", cpl_table_get_string(table, "String", 6), + "Check element 7 of sorted \"String\"... "); - test_svalue("daaa", cpl_table_get_string(table, "String", 14), - "Check element 15 of sorted \"String\"... "); + for (i = 7; i < 13; i++) { + sprintf(message, + "Check element %" CPL_SIZE_FORMAT " of sorted \"String\"... ", + i + 1); + test_svalue("999", cpl_table_get_string(table, "String", i), message); + } - test_svalue(" sss", cpl_table_get_string(table, "String", 15), - "Check element 16 of sorted \"String\"... "); + test_svalue("aaaa", cpl_table_get_string(table, "String", 13), + "Check element 14 of sorted \"String\"... "); - test_svalue("acde", cpl_table_get_string(table, "String", 16), - "Check element 17 of sorted \"String\"... "); + test_svalue("daaa", cpl_table_get_string(table, "String", 14), + "Check element 15 of sorted \"String\"... "); - test_svalue("extra", cpl_table_get_string(table, "String", 17), - "Check element 18 of sorted \"String\"... "); + test_svalue(" sss", cpl_table_get_string(table, "String", 15), + "Check element 16 of sorted \"String\"... "); + test_svalue("acde", cpl_table_get_string(table, "String", 16), + "Check element 17 of sorted \"String\"... "); - test_ivalue(0, cpl_table_is_valid(table, "Float", 0), - "Check element 1 of sorted \"Float\"... "); + test_svalue("extra", cpl_table_get_string(table, "String", 17), + "Check element 18 of sorted \"String\"... "); - test_ivalue(0, cpl_table_is_valid(table, "Float", 1), - "Check element 2 of sorted \"Float\"... "); - test_ivalue(0, cpl_table_is_valid(table, "Float", 2), - "Check element 3 of sorted \"Float\"... "); + test_ivalue(0, cpl_table_is_valid(table, "Float", 0), + "Check element 1 of sorted \"Float\"... "); - test_fvalue(0.0, 0.00001, cpl_table_get_float(table, "Float", 3, &null), - "Check element 4 of sorted \"Float\"... "); - cpl_test_zero(null); + test_ivalue(0, cpl_table_is_valid(table, "Float", 1), + "Check element 2 of sorted \"Float\"... "); - test_ivalue(0, cpl_table_is_valid(table, "Float", 4), - "Check element 5 of sorted \"Float\"... "); + test_ivalue(0, cpl_table_is_valid(table, "Float", 2), + "Check element 3 of sorted \"Float\"... "); - test_ivalue(0, cpl_table_is_valid(table, "Float", 5), - "Check element 6 of sorted \"Float\"... "); + test_fvalue(0.0, 0.00001, cpl_table_get_float(table, "Float", 3, &null), + "Check element 4 of sorted \"Float\"... "); + cpl_test_zero(null); - test_ivalue(0, cpl_table_is_valid(table, "Float", 6), - "Check element 7 of sorted \"Float\"... "); + test_ivalue(0, cpl_table_is_valid(table, "Float", 4), + "Check element 5 of sorted \"Float\"... "); - test_fvalue(0.0, 0.00001, - cpl_table_get_float(table, "Float", 7, &null), - "Check element 8 of sorted \"Float\"... "); - cpl_test_zero(null); + test_ivalue(0, cpl_table_is_valid(table, "Float", 5), + "Check element 6 of sorted \"Float\"... "); - test_fvalue(0.0, 0.00001, - cpl_table_get_float(table, "Float", 8, &null), - "Check element 9 of sorted \"Float\"... "); - cpl_test_zero(null); + test_ivalue(0, cpl_table_is_valid(table, "Float", 6), + "Check element 7 of sorted \"Float\"... "); - test_fvalue(0.0, 0.00001, - cpl_table_get_float(table, "Float", 9, &null), - "Check element 10 of sorted \"Float\"... "); - cpl_test_zero(null); + test_fvalue(0.0, 0.00001, cpl_table_get_float(table, "Float", 7, &null), + "Check element 8 of sorted \"Float\"... "); + cpl_test_zero(null); - test_fvalue(-999880.0, 0.00001, - cpl_table_get_float(table, "Float", 10, &null), - "Check element 11 of sorted \"Float\"... "); - cpl_test_zero(null); + test_fvalue(0.0, 0.00001, cpl_table_get_float(table, "Float", 8, &null), + "Check element 9 of sorted \"Float\"... "); + cpl_test_zero(null); - test_ivalue(0, cpl_table_is_valid(table, "Float", 11), - "Check element 12 of sorted \"Float\"... "); + test_fvalue(0.0, 0.00001, cpl_table_get_float(table, "Float", 9, &null), + "Check element 10 of sorted \"Float\"... "); + cpl_test_zero(null); - test_fvalue(0.0, 0.00001, - cpl_table_get_float(table, "Float", 12, &null), - "Check element 13 of sorted \"Float\"... "); - cpl_test_zero(null); + test_fvalue(-999880.0, 0.00001, + cpl_table_get_float(table, "Float", 10, &null), + "Check element 11 of sorted \"Float\"... "); + cpl_test_zero(null); - test_fvalue(-28.44, 0.00001, - cpl_table_get_float(table, "Float", 13, &null), - "Check element 14 of sorted \"Float\"... "); - cpl_test_zero(null); + test_ivalue(0, cpl_table_is_valid(table, "Float", 11), + "Check element 12 of sorted \"Float\"... "); - test_fvalue(-12.22, 0.00001, - cpl_table_get_float(table, "Float", 14, &null), - "Check element 15 of sorted \"Float\"... "); - cpl_test_zero(null); + test_fvalue(0.0, 0.00001, cpl_table_get_float(table, "Float", 12, &null), + "Check element 13 of sorted \"Float\"... "); + cpl_test_zero(null); - test_fvalue(-12.33, 0.00001, - cpl_table_get_float(table, "Float", 15, &null), - "Check element 16 of sorted \"Float\"... "); - cpl_test_zero(null); + test_fvalue(-28.44, 0.00001, cpl_table_get_float(table, "Float", 13, &null), + "Check element 14 of sorted \"Float\"... "); + cpl_test_zero(null); - test_fvalue(6.66, 0.00001, - cpl_table_get_float(table, "Float", 16, &null), - "Check element 17 of sorted \"Float\"... "); - cpl_test_zero(null); + test_fvalue(-12.22, 0.00001, cpl_table_get_float(table, "Float", 14, &null), + "Check element 15 of sorted \"Float\"... "); + cpl_test_zero(null); - test_fvalue(-1110.0, 0.00001, - cpl_table_get_float(table, "Float", 17, &null), - "Check element 18 of sorted \"Float\"... "); - cpl_test_zero(null); + test_fvalue(-12.33, 0.00001, cpl_table_get_float(table, "Float", 15, &null), + "Check element 16 of sorted \"Float\"... "); + cpl_test_zero(null); + test_fvalue(6.66, 0.00001, cpl_table_get_float(table, "Float", 16, &null), + "Check element 17 of sorted \"Float\"... "); + cpl_test_zero(null); + test_fvalue(-1110.0, 0.00001, + cpl_table_get_float(table, "Float", 17, &null), + "Check element 18 of sorted \"Float\"... "); + cpl_test_zero(null); } diff -Nru cpl-7.1.4+ds/cplcore/tests/cpl_test_init-test.c cpl-7.2.2+ds/cplcore/tests/cpl_test_init-test.c --- cpl-7.1.4+ds/cplcore/tests/cpl_test_init-test.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/tests/cpl_test_init-test.c 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -50,33 +50,35 @@ #ifdef HAVE_UNISTD_H /* The pipe on which the child writes the log file name to the parent. */ -int pipefd[2] = {-1, -1}; +int pipefd[2] = { -1, -1 }; /* The signal handler for writing the log file name in the child process. We do the writing in a signal handler at the abort stage since the cpl_test_init_macro() routine that we are testing might abort if it can not create a file with the filename it generated during the test. */ -static void signal_handler(int sig) +static void +signal_handler(int sig) { if (sig == SIGABRT) { ssize_t total_written = 0; - + /* We are assuming that cpl_msg_get_log_name() is reentrant and safe for a signal handler. Since this only happens once at abort it probably does not matter much anyway, even if it technically is not safe. */ - const char* logname = cpl_msg_get_log_name(); - + const char *logname = cpl_msg_get_log_name(); + /* Write the message taking into account partial writes. Note: on the child side we only ever touch pipefd in the signal handler so no chance of a race condition. Plus these routines are all fine to use in signal handlers according to POSIX. */ do { - ssize_t bytes_written = write(pipefd[1], logname+total_written, - strlen(logname)+1-total_written); - if (bytes_written < 0) break; + ssize_t bytes_written = write(pipefd[1], logname + total_written, + strlen(logname) + 1 - total_written); + if (bytes_written < 0) + break; total_written += bytes_written; - } while (total_written != (ssize_t)(strlen(logname)+1)); + } while (total_written != (ssize_t)(strlen(logname) + 1)); /* Do not bother testing fsync() or close() success in the child since we are not interested in reporting such errors. We have anyway closed @@ -98,7 +100,8 @@ /*----------------------------------------------------------------------------- Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { #ifdef HAVE_UNISTD_H @@ -107,70 +110,48 @@ pid_t child_pid = 0; ssize_t bytes_read = 0; int current_file = 0; - + /* The filenames to check. */ - const char* filename[NUMBER_OF_FILENAMES] = { - "", - ".", - "..", - "../", - "file", - "/file", - "./file", - "./file.c", - "./file.cxx", - "./file.name", - "./file.name.c", - "/dir/file", - "/dir/file.c", - "/dir/file.cxx", - "/dir.name/file", - "..\\", - "\\file", - ".\\file", - ".\\file.c", - ".\\file.cxx", - ".\\file.name", - ".\\file.name.c", - "\\dir\\file", - "\\dir\\file.c", - "\\dir\\file.cxx", - "\\dir.name\\file" - }; - + const char *filename[NUMBER_OF_FILENAMES] = { "", + ".", + "..", + "../", + "file", + "/file", + "./file", + "./file.c", + "./file.cxx", + "./file.name", + "./file.name.c", + "/dir/file", + "/dir/file.c", + "/dir/file.cxx", + "/dir.name/file", + "..\\", + "\\file", + ".\\file", + ".\\file.c", + ".\\file.cxx", + ".\\file.name", + ".\\file.name.c", + "\\dir\\file", + "\\dir\\file.c", + "\\dir\\file.cxx", + "\\dir.name\\file" }; + /* List of expected filenames. */ - const char* expected_filename[NUMBER_OF_FILENAMES] = { - ".log", - ".log", - ".log", - ".log", - "file.log", - "file.log", - "file.log", - "file.log", - "file.log", - "file.log", - "file.name.log", - "file.log", - "file.log", - "file.log", - "file.log", - ".log", - "file.log", - "file.log", - "file.log", - "file.log", - "file.log", - "file.name.log", - "file.log", - "file.log", - "file.log", + const char *expected_filename[NUMBER_OF_FILENAMES] = { + ".log", ".log", ".log", ".log", "file.log", + "file.log", "file.log", "file.log", "file.log", "file.log", + "file.name.log", "file.log", "file.log", "file.log", "file.log", + ".log", "file.log", "file.log", "file.log", "file.log", + "file.log", "file.name.log", "file.log", "file.log", "file.log", "file.log" }; /* Buffer containing the generated filename returned by the child. */ char generated_filename[1024]; - + /* We run the test on cpl_test_init_macro(). However, this is a bit tricky since we can only make one call to cpl_test_init_macro() per process. In addition, that routine might abort if a failure is triggered, which @@ -184,22 +165,22 @@ print the diagnostics. We use a pipe to deliver the file name actually created by the cpl_test_init_macro() routine in the child to the parent process. */ - - for (current_file = 0; current_file < NUMBER_OF_FILENAMES; ++current_file) { + for (current_file = 0; current_file < NUMBER_OF_FILENAMES; ++current_file) { pipe_create_result = pipe(pipefd); - if (pipe_create_result != 0) break; + if (pipe_create_result != 0) + break; child_pid = fork(); - if (child_pid == -1) break; - + if (child_pid == -1) + break; + if (child_pid == 0) { - /* Child process code: */ - + struct sigaction siginfo; struct rlimit rlim; int result = 0; - const char * fname = filename[current_file]; + const char *fname = filename[current_file]; /* The child will always be calling the abort command so make sure we do not create core dumps */ @@ -209,7 +190,7 @@ if (result != 0) { fname = "FAILED"; } - + /* Catch the abort signal that will be generated by the child either in cpl_test_init_macro because the log file could not be created or from the explicit call afterwards. */ @@ -217,28 +198,27 @@ siginfo.sa_handler = &signal_handler; sigemptyset(&siginfo.sa_mask); sigaction(SIGABRT, &siginfo, NULL); - + /* Close all std(in)(out)(err) so the child does not write there. */ close(STDIN_FILENO); close(STDOUT_FILENO); close(STDERR_FILENO); - + cpl_test_init_macro(fname, PACKAGE_BUGREPORT, CPL_MSG_OFF); - + /* Children always abort so that we can then handle the write to the output pipe in one place (the signal handler). */ abort(); - - } else { - + } + else { /* Parent process code: */ - + size_t total_read = 0; - + /* Make the filename a null terminated string by filling the buffer with zeros. */ memset(&generated_filename, 0x0, sizeof(generated_filename)); - + /* The parent has to close the write end of the pipe before trying to read from it. If we do not do this we could deadlock, because only when all file descriptors for the write end of the pipe get @@ -249,44 +229,47 @@ we must make sure the write end is indeed closed to avoid any deadlock. */ pipe_close_result = close(pipefd[1]); - if (pipe_close_result != 0) break; - + if (pipe_close_result != 0) + break; + /* Read the filename string from the child. We keep going if we get interrupted or until a NULL terminator is read. */ do { bytes_read = read(pipefd[0], generated_filename + total_read, - sizeof(generated_filename)-1-total_read); + sizeof(generated_filename) - 1 - total_read); if (bytes_read > 0) { total_read += bytes_read; - if (generated_filename[total_read-1] == '\0') break; + if (generated_filename[total_read - 1] == '\0') + break; } } while (bytes_read == -1 && errno == EINTR); - + /* Can now close the pipe. Do not bother checking the status of the file closure, since any error here means that generated_filename contains a value that was not expected and an error will be generated later anyway. */ close(pipefd[0]); - + /* Try remove the generated log file. We do not check the return status since the file might not actually have been generated, so we will fail in remove() in such a case. */ remove(generated_filename); - - if (bytes_read < 0) break; /* Had a read error? */ - + + if (bytes_read < 0) + break; /* Had a read error? */ + /* Check that we got the correct response from the child. */ - if (strcmp(generated_filename, - expected_filename[current_file]) != 0) { + if (strcmp(generated_filename, expected_filename[current_file]) != + 0) { break; } } } - + /* We can finally initialise the CPL subsystem in the parent since no more children will be created, check the status and print test diagnostics. */ cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); - + cpl_test_assert(pipe_create_result == 0); cpl_test_assert(pipe_close_result == 0); cpl_test_assert(child_pid != -1); @@ -295,8 +278,8 @@ /* Check that the child was able to set itself up correcly, e.g. set the RLIMIT_CORE value. Then generate the message for unexpected filenames. */ - cpl_test_assert(strstr(generated_filename, "FAILED") - != generated_filename); + cpl_test_assert(strstr(generated_filename, "FAILED") != + generated_filename); cpl_test_eq_string(generated_filename, expected_filename[current_file]); } cpl_test_eq(current_file, NUMBER_OF_FILENAMES); @@ -304,13 +287,13 @@ return cpl_test_end(0); #else /* HAVE_UNISTD_H */ - + /* In the case that we dont have unistd.h we just write a warning. */ cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); - cpl_msg_warning(cpl_func, - "No support for unistd.h, so this test cannot be completed"); + cpl_msg_warning( + cpl_func, "No support for unistd.h, so this test cannot be completed"); cpl_test_end(0); - return 77; /* 77 is used by automake to indicate a skipped test. */ + return 77; /* 77 is used by automake to indicate a skipped test. */ #endif /* HAVE_UNISTD_H */ } diff -Nru cpl-7.1.4+ds/cplcore/tests/cpl_test-test.c cpl-7.2.2+ds/cplcore/tests/cpl_test-test.c --- cpl-7.1.4+ds/cplcore/tests/cpl_test-test.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/tests/cpl_test-test.c 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -45,97 +45,97 @@ #define CPL_TEST_FITS_NAME "cpl_test-test.fits" -#define B2880 \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ - "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ +#define B2880 \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" \ + "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" /*----------------------------------------------------------------------------- Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { - int nxfail = 0; /* The number of expected failures */ cpl_msg_severity level; - cpl_vector * vec1; - cpl_vector * vec2; - cpl_matrix * mat1; - cpl_matrix * mat2; - cpl_array * arr1i; - cpl_array * arr2i; - cpl_array * arr1f; - cpl_array * arr2f; - cpl_array * arr1d; - cpl_array * arr2d; - cpl_array * arr1s; - cpl_array * arr2s; - cpl_image * img1; - cpl_image * img2; - cpl_image * img3; - cpl_imagelist * imglist1; - cpl_imagelist * imglist2; - cpl_polynomial * poly1; - cpl_polynomial * poly2; - cpl_mask * mask1; - cpl_mask * mask2; - cpl_errorstate cleanstate; - cpl_errorstate errstate; - cpl_error_code error; - double wallstart, cpustart; - double wallstop, cpustop; - cpl_size tested, failed; - FILE * fp; + cpl_vector *vec1; + cpl_vector *vec2; + cpl_matrix *mat1; + cpl_matrix *mat2; + cpl_array *arr1i; + cpl_array *arr2i; + cpl_array *arr1f; + cpl_array *arr2f; + cpl_array *arr1d; + cpl_array *arr2d; + cpl_array *arr1s; + cpl_array *arr2s; + cpl_image *img1; + cpl_image *img2; + cpl_image *img3; + cpl_imagelist *imglist1; + cpl_imagelist *imglist2; + cpl_polynomial *poly1; + cpl_polynomial *poly2; + cpl_mask *mask1; + cpl_mask *mask2; + cpl_errorstate cleanstate; + cpl_errorstate errstate; + cpl_error_code error; + double wallstart, cpustart; + double wallstop, cpustop; + cpl_size tested, failed; + FILE *fp; const unsigned int tsleep = 1; - unsigned int tleft; + unsigned int tleft; cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); wallstart = cpl_test_get_walltime(); - cpustart = cpl_test_get_cputime(); + cpustart = cpl_test_get_cputime(); tested = cpl_test_get_tested(); failed = cpl_test_get_failed(); @@ -203,11 +203,11 @@ cpl_test_rel(1.0, 1.0, 0.0); - cpl_test_rel(-1.0, -2.0, 1.0); - cpl_test_rel(-2.0, -1.0, 1.0); + cpl_test_rel(-1.0, -2.0, 1.0); + cpl_test_rel(-2.0, -1.0, 1.0); cpl_test_leq(0.0, 0.0); - cpl_test_lt(0.0, 1.0); + cpl_test_lt(0.0, 1.0); vec1 = cpl_vector_new(IMAGESZ); error = cpl_vector_fill(vec1, 0.0); @@ -300,8 +300,7 @@ cpl_test_image_abs(img1, img2, 1.0 + FLT_EPSILON); /* Round-off */ - cpl_test_eq(cpl_test_get_bytes_image(img1), - cpl_test_get_bytes_image(img2)); + cpl_test_eq(cpl_test_get_bytes_image(img1), cpl_test_get_bytes_image(img2)); imglist1 = cpl_imagelist_new(); cpl_imagelist_set(imglist1, img1, 0); @@ -346,162 +345,234 @@ level = cpl_msg_get_level(); cpl_msg_set_level(CPL_MSG_OFF); - cpl_test(0); nxfail++; - cpl_test_zero(41); nxfail++; - - cpl_test_null(cpl_func); nxfail++; - cpl_test_nonnull(NULL); nxfail++; - - cpl_test_eq_ptr(NULL, cpl_func); nxfail++; - cpl_test_eq_ptr(cpl_func, NULL);nxfail++; - - cpl_test_noneq_ptr(NULL, NULL); nxfail++; - cpl_test_noneq_ptr(cpl_func, cpl_func); nxfail++; + cpl_test(0); + nxfail++; + cpl_test_zero(41); + nxfail++; + + cpl_test_null(cpl_func); + nxfail++; + cpl_test_nonnull(NULL); + nxfail++; + + cpl_test_eq_ptr(NULL, cpl_func); + nxfail++; + cpl_test_eq_ptr(cpl_func, NULL); + nxfail++; + + cpl_test_noneq_ptr(NULL, NULL); + nxfail++; + cpl_test_noneq_ptr(cpl_func, cpl_func); + nxfail++; - cpl_test_errorstate(errstate); nxfail++; + cpl_test_errorstate(errstate); + nxfail++; - cpl_test_error(CPL_ERROR_EOL); nxfail++; + cpl_test_error(CPL_ERROR_EOL); + nxfail++; - cpl_test_eq_error(CPL_ERROR_NONE, CPL_ERROR_EOL); nxfail++; + cpl_test_eq_error(CPL_ERROR_NONE, CPL_ERROR_EOL); + nxfail++; /* Set a CPL error */ (void)cpl_msg_set_log_name(NULL); - cpl_test_errorstate(cleanstate); nxfail++; + cpl_test_errorstate(cleanstate); + nxfail++; /* Set a CPL error */ (void)cpl_msg_set_log_name(NULL); - cpl_test_error(CPL_ERROR_NONE); nxfail++; + cpl_test_error(CPL_ERROR_NONE); + nxfail++; /* Set a CPL error */ (void)cpl_msg_set_log_name(NULL); - cpl_test_eq_error(CPL_ERROR_NONE, cpl_error_get_code()); nxfail++; + cpl_test_eq_error(CPL_ERROR_NONE, cpl_error_get_code()); + nxfail++; /* Set a CPL error */ (void)cpl_msg_set_log_name(NULL); - cpl_test_eq_error(CPL_ERROR_EOL, CPL_ERROR_EOL); nxfail++; - - cpl_test_eq(0, 1); nxfail++; - - cpl_test_noneq(0, 0); nxfail++; - - cpl_test_eq_string("A", "B"); nxfail++; - cpl_test_eq_string(NULL, ""); nxfail++; - cpl_test_eq_string(NULL, NULL); nxfail++; - - cpl_test_noneq_string(cpl_func, cpl_func); nxfail++; - cpl_test_noneq_string(cpl_func, NULL); nxfail++; - cpl_test_noneq_string(NULL, cpl_func); nxfail++; - cpl_test_noneq_string(NULL, NULL); nxfail++; - - cpl_test_abs(0.0, 0.0, -1.0); nxfail++; - - cpl_test_abs(0.0, 2.0, 1.0); nxfail++; - cpl_test_abs(2.0, 0.0, 1.0); nxfail++; - - - cpl_test_abs_complex(0.0, 0.0, -1.0); nxfail++; + cpl_test_eq_error(CPL_ERROR_EOL, CPL_ERROR_EOL); + nxfail++; - cpl_test_abs_complex(0.0, 2.0 * _Complex_I, 1.0); nxfail++; - cpl_test_abs_complex(2.0 * _Complex_I, 0.0, 1.0); nxfail++; + cpl_test_eq(0, 1); + nxfail++; + cpl_test_noneq(0, 0); + nxfail++; - cpl_test_rel(0.0, 0.0, -1.0); nxfail++; - cpl_test_rel(0.0, 1.0, 1.0); nxfail++; - cpl_test_rel(1.0, 0.0, 1.0); nxfail++; + cpl_test_eq_string("A", "B"); + nxfail++; + cpl_test_eq_string(NULL, ""); + nxfail++; + cpl_test_eq_string(NULL, NULL); + nxfail++; + + cpl_test_noneq_string(cpl_func, cpl_func); + nxfail++; + cpl_test_noneq_string(cpl_func, NULL); + nxfail++; + cpl_test_noneq_string(NULL, cpl_func); + nxfail++; + cpl_test_noneq_string(NULL, NULL); + nxfail++; + + cpl_test_abs(0.0, 0.0, -1.0); + nxfail++; + + cpl_test_abs(0.0, 2.0, 1.0); + nxfail++; + cpl_test_abs(2.0, 0.0, 1.0); + nxfail++; + + + cpl_test_abs_complex(0.0, 0.0, -1.0); + nxfail++; + + cpl_test_abs_complex(0.0, 2.0 * _Complex_I, 1.0); + nxfail++; + cpl_test_abs_complex(2.0 * _Complex_I, 0.0, 1.0); + nxfail++; + + + cpl_test_rel(0.0, 0.0, -1.0); + nxfail++; + cpl_test_rel(0.0, 1.0, 1.0); + nxfail++; + cpl_test_rel(1.0, 0.0, 1.0); + nxfail++; + + cpl_test_rel(1.0, 3.0, 1.0); + nxfail++; + + cpl_test_leq(1.0, 0.0); + nxfail++; + cpl_test_lt(0.0, 0.0); + nxfail++; + + cpl_test_vector_abs(NULL, NULL, 1.0); + nxfail++; + + cpl_test_vector_abs(vec1, vec2, 0.5); + nxfail++; + + cpl_test_matrix_abs(mat1, mat2, 0.5); + nxfail++; + + cpl_test_array_abs(NULL, NULL, 1.0); + nxfail++; + + cpl_test_array_abs(arr1i, arr2i, 0.5); + nxfail++; + + cpl_test_array_abs(arr1f, arr2f, 0.5); + nxfail++; + + cpl_test_array_abs(arr1d, arr2d, 0.5); + nxfail++; + + cpl_test_array_abs(arr1s, arr2s, 0.0); + nxfail++; + + cpl_test_image_abs(img1, NULL, 1.0); + nxfail++; + cpl_test_image_abs(NULL, img2, 1.0); + nxfail++; + cpl_test_image_rel(img1, NULL, 1.0); + nxfail++; + cpl_test_image_rel(NULL, img2, 1.0); + nxfail++; - cpl_test_rel(1.0, 3.0, 1.0); nxfail++; + cpl_test_image_abs(img1, img2, 0.5); + nxfail++; - cpl_test_leq(1.0, 0.0); nxfail++; - cpl_test_lt(0.0, 0.0); nxfail++; - - cpl_test_vector_abs(NULL, NULL, 1.0); nxfail++; - - cpl_test_vector_abs(vec1, vec2, 0.5); nxfail++; - - cpl_test_matrix_abs(mat1, mat2, 0.5); nxfail++; - - cpl_test_array_abs(NULL, NULL, 1.0); nxfail++; - - cpl_test_array_abs(arr1i, arr2i, 0.5); nxfail++; - - cpl_test_array_abs(arr1f, arr2f, 0.5); nxfail++; - - cpl_test_array_abs(arr1d, arr2d, 0.5); nxfail++; - - cpl_test_array_abs(arr1s, arr2s, 0.0); nxfail++; - - cpl_test_image_abs(img1, NULL, 1.0); nxfail++; - cpl_test_image_abs(NULL, img2, 1.0); nxfail++; - cpl_test_image_rel(img1, NULL, 1.0); nxfail++; - cpl_test_image_rel(NULL, img2, 1.0); nxfail++; - - cpl_test_image_abs(img1, img2, 0.5); nxfail++; - - cpl_test_image_rel(img1, img1, -0.5); nxfail++; + cpl_test_image_rel(img1, img1, -0.5); + nxfail++; img3 = cpl_image_duplicate(img1); error = cpl_image_multiply_scalar(img1, 2.0); cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_image_rel(img1, img3, 1.0 - FLT_EPSILON); nxfail++; + cpl_test_image_rel(img1, img3, 1.0 - FLT_EPSILON); + nxfail++; error = cpl_image_multiply_scalar(img1, 0.5); cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_imagelist_abs(NULL, NULL, 1.0); nxfail++; - cpl_test_imagelist_abs(imglist1, NULL, 1.0); nxfail++; - cpl_test_imagelist_abs(NULL, imglist2, 1.0); nxfail++; - cpl_test_imagelist_abs(imglist1, imglist2, 0.5); nxfail++; + cpl_test_imagelist_abs(NULL, NULL, 1.0); + nxfail++; + cpl_test_imagelist_abs(imglist1, NULL, 1.0); + nxfail++; + cpl_test_imagelist_abs(NULL, imglist2, 1.0); + nxfail++; + cpl_test_imagelist_abs(imglist1, imglist2, 0.5); + nxfail++; (void)cpl_imagelist_unset(imglist1, 0); - cpl_test_imagelist_abs(imglist1, imglist2, 1.0 + FLT_EPSILON); nxfail++; + cpl_test_imagelist_abs(imglist1, imglist2, 1.0 + FLT_EPSILON); + nxfail++; - cpl_test_polynomial_abs(poly1, poly2, -1.0); nxfail++; + cpl_test_polynomial_abs(poly1, poly2, -1.0); + nxfail++; cpl_polynomial_delete(poly2); - poly2 = cpl_polynomial_new(cpl_polynomial_get_dimension(poly1)+1); + poly2 = cpl_polynomial_new(cpl_polynomial_get_dimension(poly1) + 1); - cpl_test_polynomial_abs(poly1, poly2, 0.0); nxfail++; - cpl_test_polynomial_abs(NULL, poly2, 0.0); nxfail++; - cpl_test_polynomial_abs(poly1, NULL, 0.0); nxfail++; - cpl_test_polynomial_abs(NULL, NULL, 0.0); nxfail++; - - cpl_test_eq_mask(mask1, NULL); nxfail++; - cpl_test_eq_mask(NULL, mask1); nxfail++; - cpl_test_eq_mask(mask1, mask2); nxfail++; + cpl_test_polynomial_abs(poly1, poly2, 0.0); + nxfail++; + cpl_test_polynomial_abs(NULL, poly2, 0.0); + nxfail++; + cpl_test_polynomial_abs(poly1, NULL, 0.0); + nxfail++; + cpl_test_polynomial_abs(NULL, NULL, 0.0); + nxfail++; + + cpl_test_eq_mask(mask1, NULL); + nxfail++; + cpl_test_eq_mask(NULL, mask1); + nxfail++; + cpl_test_eq_mask(mask1, mask2); + nxfail++; cpl_mask_delete(mask2); - mask2 = cpl_mask_new(IMAGESZ+1, IMAGESZ); - cpl_test_eq_mask(mask1, mask2); nxfail++; + mask2 = cpl_mask_new(IMAGESZ + 1, IMAGESZ); + cpl_test_eq_mask(mask1, mask2); + nxfail++; cpl_mask_delete(mask2); - mask2 = cpl_mask_new(IMAGESZ, IMAGESZ+1); - cpl_test_eq_mask(mask1, mask2); nxfail++; - - cpl_test_fits(NULL); nxfail++; - cpl_test_fits("/dev/null"); nxfail++; + mask2 = cpl_mask_new(IMAGESZ, IMAGESZ + 1); + cpl_test_eq_mask(mask1, mask2); + nxfail++; + + cpl_test_fits(NULL); + nxfail++; + cpl_test_fits("/dev/null"); + nxfail++; if (getenv(CPL_TEST_FITS)) { - cpl_test_fits("."); nxfail++; + cpl_test_fits("."); + nxfail++; } fp = fopen(CPL_TEST_FITS_NAME, "w"); cpl_test_nonnull(fp); if (fp != NULL) { /* This file size is non-FITS */ - const size_t size = fwrite(B2880, 1, 80, fp) - + fwrite(B2880, 1, 2880, fp) - + fwrite(B2880, 1, 2880, fp); + const size_t size = fwrite(B2880, 1, 80, fp) + + fwrite(B2880, 1, 2880, fp) + + fwrite(B2880, 1, 2880, fp); cpl_test_zero(fclose(fp)); cpl_test_eq(size, 80 + 2880 + 2880); - cpl_test_fits(CPL_TEST_FITS_NAME); nxfail++; + cpl_test_fits(CPL_TEST_FITS_NAME); + nxfail++; cpl_test_zero(remove(CPL_TEST_FITS_NAME)); - } else { + } + else { (void)remove(CPL_TEST_FITS_NAME); } - cpl_test_fits(CPL_TEST_FITS_NAME); nxfail++; + cpl_test_fits(CPL_TEST_FITS_NAME); + nxfail++; /* Tests done - reinstate normal messaging */ @@ -542,14 +613,13 @@ #endif wallstop = cpl_test_get_walltime(); - cpustop = cpl_test_get_cputime(); + cpustop = cpl_test_get_cputime(); cpl_test_leq(wallstart + (double)tsleep, wallstop + (double)tleft); cpl_test_leq(cpustart, cpustop); - cpl_msg_info(cpl_func, "Wall-clock time [s]: %g", wallstop-wallstart); - cpl_msg_info(cpl_func, "CPU time [s]: %g", cpustop-cpustart); + cpl_msg_info(cpl_func, "Wall-clock time [s]: %g", wallstop - wallstart); + cpl_msg_info(cpl_func, "CPU time [s]: %g", cpustop - cpustart); return cpl_test_end(-nxfail); - } diff -Nru cpl-7.1.4+ds/cplcore/tests/cpl_tools-test.c cpl-7.2.2+ds/cplcore/tests/cpl_tools-test.c --- cpl-7.1.4+ds/cplcore/tests/cpl_tools-test.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/tests/cpl_tools-test.c 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -36,7 +36,7 @@ Defines -----------------------------------------------------------------------------*/ -#define NBC 8 +#define NBC 8 #define NBC2 11 /*----------------------------------------------------------------------------- @@ -50,39 +50,39 @@ /*----------------------------------------------------------------------------- Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { - /* Some binomial coefficients - in reverse order */ - const int p15[NBC2] = {646646, 497420, 319770, 170544, 74613, 26334, - 7315, 1540, 231, 22, 1}; - const float pf15[NBC2] = {646646, 497420, 319770, 170544, 74613, 26334, - 7315, 1540, 231, 22, 1}; - int c15[NBC2]; + const int p15[NBC2] = { 646646, 497420, 319770, 170544, 74613, 26334, + 7315, 1540, 231, 22, 1 }; + const float pf15[NBC2] = { 646646, 497420, 319770, 170544, 74613, 26334, + 7315, 1540, 231, 22, 1 }; + int c15[NBC2]; float cf15[NBC2]; - int c0[NBC] = {1, 1, 1, 1, 0, 0, 0, 0}; - cpl_boolean do_bench; + int c0[NBC] = { 1, 1, 1, 1, 0, 0, 0, 0 }; + cpl_boolean do_bench; cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); do_bench = cpl_msg_get_level() <= CPL_MSG_INFO ? CPL_TRUE : CPL_FALSE; - cpl_test_abs( cpl_tools_ipow(1.0, 0), 1.0, 0.0); - cpl_test_abs( cpl_tools_ipow(0.0, 0), 1.0, 0.0); - cpl_test_abs( cpl_tools_ipow(0.0, 1), 0.0, 0.0); - cpl_test_abs( cpl_tools_ipow(0.0, 2), 0.0, 0.0); + cpl_test_abs(cpl_tools_ipow(1.0, 0), 1.0, 0.0); + cpl_test_abs(cpl_tools_ipow(0.0, 0), 1.0, 0.0); + cpl_test_abs(cpl_tools_ipow(0.0, 1), 0.0, 0.0); + cpl_test_abs(cpl_tools_ipow(0.0, 2), 0.0, 0.0); cpl_test_eq_ptr(c15, memcpy(c15, p15, sizeof(p15))); /* Find two smallest */ - cpl_test_eq(p15[NBC2-2], cpl_tools_get_kth_int(c15, NBC2, 1)); + cpl_test_eq(p15[NBC2 - 2], cpl_tools_get_kth_int(c15, NBC2, 1)); /* Find two largest */ - cpl_test_eq(p15[1], cpl_tools_get_kth_int(c15, NBC2, NBC2-2)); - cpl_test_eq(p15[0], c15[NBC2-1]); + cpl_test_eq(p15[1], cpl_tools_get_kth_int(c15, NBC2, NBC2 - 2)); + cpl_test_eq(p15[0], c15[NBC2 - 1]); - cpl_test_eq(p15[NBC2-1], c15[0]); /* Check of 2nd smallest delayed */ + cpl_test_eq(p15[NBC2 - 1], c15[0]); /* Check of 2nd smallest delayed */ cpl_test_zero(cpl_tools_get_kth_int(c0, NBC, 3)); cpl_test_zero(c0[0]); @@ -97,8 +97,9 @@ cpl_test_eq_ptr(c15, memcpy(c15, p15, sizeof(p15))); /* Find median */ - cpl_test_eq(p15[(NBC2-1)/2], cpl_tools_quickselection_int(c15, NBC2, (NBC2-1)/2)); - cpl_test_eq(p15[(NBC2-1)/2], c15[(NBC2-1)/2]); + cpl_test_eq(p15[(NBC2 - 1) / 2], + cpl_tools_quickselection_int(c15, NBC2, (NBC2 - 1) / 2)); + cpl_test_eq(p15[(NBC2 - 1) / 2], c15[(NBC2 - 1) / 2]); /* Special case: 3 element median computation */ cpl_test_eq_ptr(c15, memcpy(c15, p15, sizeof(p15))); @@ -116,7 +117,7 @@ /* Special case: 6 element median computation */ cpl_test_eq_ptr(c15, memcpy(c15, p15, sizeof(p15))); - cpl_test_eq((p15[2]+p15[3])/2, cpl_tools_get_median_int(c15, 6)); + cpl_test_eq((p15[2] + p15[3]) / 2, cpl_tools_get_median_int(c15, 6)); cpl_test_lt(c15[0], c15[2]); cpl_test_lt(c15[1], c15[2]); cpl_test_lt(c15[2], c15[3]); @@ -135,7 +136,7 @@ /* Normal median case with even number: 10 element median computation */ cpl_test_eq_ptr(c15, memcpy(c15, p15, sizeof(p15))); - cpl_test_eq((p15[4]+p15[5])/2, cpl_tools_get_median_int(c15, 10)); + cpl_test_eq((p15[4] + p15[5]) / 2, cpl_tools_get_median_int(c15, 10)); cpl_test_lt(c15[0], c15[4]); cpl_test_lt(c15[1], c15[4]); cpl_test_lt(c15[2], c15[4]); @@ -162,7 +163,7 @@ /* Float case */ /* Normal median case with even number: 10 element median computation */ cpl_test_eq_ptr(cf15, memcpy(cf15, pf15, sizeof(pf15))); - cpl_test_eq((pf15[4]+pf15[5])/2., cpl_tools_get_median_float(cf15, 10)); + cpl_test_eq((pf15[4] + pf15[5]) / 2., cpl_tools_get_median_float(cf15, 10)); cpl_test_lt(cf15[0], cf15[4]); cpl_test_lt(cf15[1], cf15[4]); cpl_test_lt(cf15[2], cf15[4]); @@ -213,33 +214,32 @@ if (do_bench) { cpl_tools_sort_bench(5, 100001, CPL_FALSE); - cpl_tools_sort_bench(5, 10001, CPL_TRUE); - cpl_tools_get_kth_quickselection_bench(5, 10001, CPL_FALSE); - cpl_tools_get_kth_quickselection_bench(5, 10001, CPL_TRUE); - cpl_tools_get_kth_quickselection_bench(5, 25001, CPL_FALSE); - cpl_tools_get_kth_quickselection_bench(5, 25001, CPL_TRUE); - cpl_tools_get_kth_quickselection_bench(5, 200001, CPL_FALSE); + cpl_tools_sort_bench(5, 10001, CPL_TRUE); + cpl_tools_get_kth_quickselection_bench(5, 10001, CPL_FALSE); + cpl_tools_get_kth_quickselection_bench(5, 10001, CPL_TRUE); + cpl_tools_get_kth_quickselection_bench(5, 25001, CPL_FALSE); + cpl_tools_get_kth_quickselection_bench(5, 25001, CPL_TRUE); + cpl_tools_get_kth_quickselection_bench(5, 200001, CPL_FALSE); cpl_tools_get_kth_quickselection_bench(5, 2000001, CPL_FALSE); #ifdef CPL_TOOLS_TEST_LONG /* Example output (Intel E6750 @ 2.66GHz): [ INFO ] Benchmarked kth 5 x 200001 [s]: 484.03 <=> 311.49 [ INFO ] Benchmarked kth 5 x 2000001 [s]: 52318.6 <=> 32385.4 */ - cpl_tools_get_kth_quickselection_bench(5, 200001, CPL_TRUE); + cpl_tools_get_kth_quickselection_bench(5, 200001, CPL_TRUE); cpl_tools_get_kth_quickselection_bench(5, 2000001, CPL_TRUE); #endif - cpl_tools_get_median_bench(5, 25000, CPL_FALSE); - cpl_tools_get_median_bench(5, 25000, CPL_TRUE); - cpl_tools_get_median_bench(5, 25001, CPL_FALSE); - cpl_tools_get_median_bench(5, 25001, CPL_TRUE); - cpl_tools_get_median_bench(5, 200000, CPL_FALSE); - cpl_tools_get_median_bench(5, 200001, CPL_FALSE); + cpl_tools_get_median_bench(5, 25000, CPL_FALSE); + cpl_tools_get_median_bench(5, 25000, CPL_TRUE); + cpl_tools_get_median_bench(5, 25001, CPL_FALSE); + cpl_tools_get_median_bench(5, 25001, CPL_TRUE); + cpl_tools_get_median_bench(5, 200000, CPL_FALSE); + cpl_tools_get_median_bench(5, 200001, CPL_FALSE); cpl_tools_get_median_bench(5, 2000000, CPL_FALSE); cpl_tools_get_median_bench(5, 2000001, CPL_FALSE); } return cpl_test_end(0); - } @@ -254,26 +254,25 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_tools_get_kth_quickselection_bench(int m, int n, - cpl_boolean do_sortmost) +static void +cpl_tools_get_kth_quickselection_bench(int m, int n, cpl_boolean do_sortmost) { - double tqsel = 0.0; - double tkth = 0.0; + double tkth = 0.0; int i; for (i = 0; i < m; i++) { - double * dd = (double*)cpl_malloc((size_t)n * sizeof(double)); - float * df = (float*) cpl_malloc((size_t)n * sizeof(float)); - int * di = (int*) cpl_malloc((size_t)n * sizeof(int)); - - double * cd = (double*)cpl_malloc((size_t)n * sizeof(double)); - float * cf = (float*) cpl_malloc((size_t)n * sizeof(float)); - int * ci = (int*) cpl_malloc((size_t)n * sizeof(int)); + double *dd = (double *)cpl_malloc((size_t)n * sizeof(double)); + float *df = (float *)cpl_malloc((size_t)n * sizeof(float)); + int *di = (int *)cpl_malloc((size_t)n * sizeof(int)); + + double *cd = (double *)cpl_malloc((size_t)n * sizeof(double)); + float *cf = (float *)cpl_malloc((size_t)n * sizeof(float)); + int *ci = (int *)cpl_malloc((size_t)n * sizeof(int)); double sec0; double dmed1, dmed2; - float fmed1, fmed2; - int imed1, imed2; + float fmed1, fmed2; + int imed1, imed2; int j; @@ -284,9 +283,9 @@ if (do_sortmost) { cpl_tools_sort_int(di, n); - di[n/2-1] = di[n/2]; - di[n/2] = RAND_MAX; - di[n/2+1] = -1; + di[n / 2 - 1] = di[n / 2]; + di[n / 2] = RAND_MAX; + di[n / 2 + 1] = -1; } for (j = 0; j < n; j++) { @@ -297,36 +296,36 @@ /* Benchmark in double precision */ cpl_test_eq_ptr(cd, memcpy(cd, dd, n * sizeof(*dd))); sec0 = cpl_test_get_cputime(); - dmed1 = cpl_tools_get_kth_double(cd, n, (n&1) ? n / 2 : n / 2 - 1); + dmed1 = cpl_tools_get_kth_double(cd, n, (n & 1) ? n / 2 : n / 2 - 1); tkth += cpl_test_get_cputime() - sec0; cpl_test_eq_ptr(cd, memcpy(cd, dd, n * sizeof(*dd))); sec0 = cpl_test_get_cputime(); - dmed2 = cpl_tools_quickselection_double(cd, n, (n-1)/2); + dmed2 = cpl_tools_quickselection_double(cd, n, (n - 1) / 2); tqsel += cpl_test_get_cputime() - sec0; cpl_test_abs(dmed1, dmed2, DBL_EPSILON); /* Benchmark with float */ cpl_test_eq_ptr(cf, memcpy(cf, df, n * sizeof(*df))); sec0 = cpl_test_get_cputime(); - fmed1 = cpl_tools_get_kth_float(cf, n, (n&1) ? n / 2 : n / 2 - 1); + fmed1 = cpl_tools_get_kth_float(cf, n, (n & 1) ? n / 2 : n / 2 - 1); tkth += cpl_test_get_cputime() - sec0; cpl_test_eq_ptr(cf, memcpy(cf, df, n * sizeof(*df))); sec0 = cpl_test_get_cputime(); - fmed2 = cpl_tools_quickselection_float(cf, n, (n-1)/2); + fmed2 = cpl_tools_quickselection_float(cf, n, (n - 1) / 2); tqsel += cpl_test_get_cputime() - sec0; cpl_test_abs(fmed1, fmed2, FLT_EPSILON); /* Benchmark with int */ cpl_test_eq_ptr(ci, memcpy(ci, di, n * sizeof(*di))); sec0 = cpl_test_get_cputime(); - imed1 = cpl_tools_get_kth_int(ci, n, (n&1) ? n / 2 : n / 2 - 1); + imed1 = cpl_tools_get_kth_int(ci, n, (n & 1) ? n / 2 : n / 2 - 1); tkth += cpl_test_get_cputime() - sec0; cpl_test_eq_ptr(ci, memcpy(ci, di, n * sizeof(*di))); sec0 = cpl_test_get_cputime(); - imed2 = cpl_tools_quickselection_int(ci, n, (n-1)/2); + imed2 = cpl_tools_quickselection_int(ci, n, (n - 1) / 2); tqsel += cpl_test_get_cputime() - sec0; cpl_test_eq(imed1, imed2); @@ -339,12 +338,12 @@ cpl_free(ci); } - cpl_msg_info(cpl_func, "Benchmarked kth <=> QuickSelect%s %d x %d [s]: " - "%g <=> %g", do_sortmost ? " (NS)" : "", - m, n, tkth, tqsel); + cpl_msg_info(cpl_func, + "Benchmarked kth <=> QuickSelect%s %d x %d [s]: " + "%g <=> %g", + do_sortmost ? " (NS)" : "", m, n, tkth, tqsel); return; - } /*----------------------------------------------------------------------------*/ @@ -358,21 +357,20 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_tools_get_median_bench(int m, int n, - cpl_boolean do_sortmost) +static void +cpl_tools_get_median_bench(int m, int n, cpl_boolean do_sortmost) { - - double tmedian = 0.0; + double tmedian = 0.0; int i; for (i = 0; i < m; i++) { - double * dd = (double*)cpl_malloc((size_t)n * sizeof(double)); - float * df = (float*) cpl_malloc((size_t)n * sizeof(float)); - int * di = (int*) cpl_malloc((size_t)n * sizeof(int)); - - double * cd = (double*)cpl_malloc((size_t)n * sizeof(double)); - float * cf = (float*) cpl_malloc((size_t)n * sizeof(float)); - int * ci = (int*) cpl_malloc((size_t)n * sizeof(int)); + double *dd = (double *)cpl_malloc((size_t)n * sizeof(double)); + float *df = (float *)cpl_malloc((size_t)n * sizeof(float)); + int *di = (int *)cpl_malloc((size_t)n * sizeof(int)); + + double *cd = (double *)cpl_malloc((size_t)n * sizeof(double)); + float *cf = (float *)cpl_malloc((size_t)n * sizeof(float)); + int *ci = (int *)cpl_malloc((size_t)n * sizeof(int)); double sec0; int j; @@ -384,9 +382,9 @@ if (do_sortmost) { cpl_tools_sort_int(di, n); - di[n/2-1] = di[n/2]; - di[n/2] = RAND_MAX; - di[n/2+1] = -1; + di[n / 2 - 1] = di[n / 2]; + di[n / 2] = RAND_MAX; + di[n / 2 + 1] = -1; } for (j = 0; j < n; j++) { @@ -421,12 +419,12 @@ cpl_free(ci); } - cpl_msg_info(cpl_func, "Benchmarked median%s %d x %d [s]: " - "%g", do_sortmost ? " (NS)" : "", - m, n, tmedian); + cpl_msg_info(cpl_func, + "Benchmarked median%s %d x %d [s]: " + "%g", + do_sortmost ? " (NS)" : "", m, n, tmedian); return; - } /*----------------------------------------------------------------------------*/ @@ -441,25 +439,25 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_tools_sort_bench(int m, int n, cpl_boolean do_sortmost) +static void +cpl_tools_sort_bench(int m, int n, cpl_boolean do_sortmost) { - double tqs = 0.0; - double tcpl = 0.0; + double tcpl = 0.0; int i; for (i = 0; i < m; i++) { - double * dd = (double*)cpl_malloc((size_t)n * sizeof(double)); - float * df = (float*) cpl_malloc((size_t)n * sizeof(float)); - int * di = (int*) cpl_malloc((size_t)n * sizeof(int)); - - double * cd = (double*)cpl_malloc((size_t)n * sizeof(double)); - float * cf = (float*) cpl_malloc((size_t)n * sizeof(float)); - int * ci = (int*) cpl_malloc((size_t)n * sizeof(int)); + double *dd = (double *)cpl_malloc((size_t)n * sizeof(double)); + float *df = (float *)cpl_malloc((size_t)n * sizeof(float)); + int *di = (int *)cpl_malloc((size_t)n * sizeof(int)); + + double *cd = (double *)cpl_malloc((size_t)n * sizeof(double)); + float *cf = (float *)cpl_malloc((size_t)n * sizeof(float)); + int *ci = (int *)cpl_malloc((size_t)n * sizeof(int)); double sec0; double dmed1, dmed2; - float fmed1, fmed2; - int imed1, imed2; + float fmed1, fmed2; + int imed1, imed2; int j; @@ -470,9 +468,9 @@ if (do_sortmost) { cpl_tools_sort_int(di, n); - di[n/2-1] = di[n/2]; - di[n/2] = RAND_MAX; - di[n/2+1] = -1; + di[n / 2 - 1] = di[n / 2]; + di[n / 2] = RAND_MAX; + di[n / 2 + 1] = -1; } for (j = 0; j < n; j++) { @@ -486,14 +484,14 @@ cpl_tools_sort_double(cd, n); tcpl += cpl_test_get_cputime() - sec0; - dmed1 = cd[n/2]; + dmed1 = cd[n / 2]; cpl_test_eq_ptr(cd, memcpy(cd, dd, n * sizeof(*dd))); sec0 = cpl_test_get_cputime(); cpl_tools_sort_ascn_double(cd, n); tqs += cpl_test_get_cputime() - sec0; - dmed2 = cd[n/2]; + dmed2 = cd[n / 2]; cpl_test_abs(dmed1, dmed2, DBL_EPSILON); @@ -503,14 +501,14 @@ cpl_tools_sort_float(cf, n); tcpl += cpl_test_get_cputime() - sec0; - fmed1 = cf[n/2]; + fmed1 = cf[n / 2]; cpl_test_eq_ptr(cf, memcpy(cf, df, n * sizeof(*df))); sec0 = cpl_test_get_cputime(); cpl_tools_sort_ascn_float(cf, n); tqs += cpl_test_get_cputime() - sec0; - fmed2 = cf[n/2]; + fmed2 = cf[n / 2]; cpl_test_abs(fmed1, fmed2, DBL_EPSILON); /* Benchmark with int */ @@ -519,14 +517,14 @@ cpl_tools_sort_int(ci, n); tcpl += cpl_test_get_cputime() - sec0; - imed1 = ci[n/2]; + imed1 = ci[n / 2]; cpl_test_eq_ptr(ci, memcpy(ci, di, n * sizeof(*di))); sec0 = cpl_test_get_cputime(); cpl_tools_sort_ascn_int(ci, n); tqs += cpl_test_get_cputime() - sec0; - imed2 = ci[n/2]; + imed2 = ci[n / 2]; cpl_test_eq(imed1, imed2); cpl_free(dd); @@ -541,5 +539,4 @@ tcpl, tqs); return; - } diff -Nru cpl-7.1.4+ds/cplcore/tests/cpl_type-test.c cpl-7.2.2+ds/cplcore/tests/cpl_type-test.c --- cpl-7.1.4+ds/cplcore/tests/cpl_type-test.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/tests/cpl_type-test.c 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -34,37 +34,39 @@ /*----------------------------------------------------------------------------- Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { - typedef struct { + typedef struct + { cpl_type type; size_t size; } typelist; - const typelist supported[] = { {CPL_TYPE_INVALID, 0}, - {CPL_TYPE_STRING, sizeof(char)}, - {CPL_TYPE_CHAR, sizeof(char)}, - {CPL_TYPE_UCHAR, sizeof(unsigned char)}, - {CPL_TYPE_BOOL, sizeof(cpl_boolean)}, - {CPL_TYPE_SHORT, sizeof(short)}, - {CPL_TYPE_USHORT, sizeof(unsigned short)}, - {CPL_TYPE_INT, sizeof(int)}, - {CPL_TYPE_UINT, sizeof(unsigned int)}, - {CPL_TYPE_LONG, sizeof(long int)}, - {CPL_TYPE_ULONG, sizeof(unsigned long int)}, - {CPL_TYPE_LONG_LONG, sizeof(long long int)}, - {CPL_TYPE_SIZE, sizeof(cpl_size)}, - {CPL_TYPE_FLOAT, sizeof(float)}, - {CPL_TYPE_DOUBLE, sizeof(double)}, - {CPL_TYPE_FLOAT_COMPLEX, - sizeof(float complex)}, - {CPL_TYPE_DOUBLE_COMPLEX, - sizeof(double complex)}, - {CPL_TYPE_UNSPECIFIED, 0}, - {CPL_TYPE_POINTER, sizeof(void*)}}; + const typelist supported[] = { + { CPL_TYPE_INVALID, 0 }, + { CPL_TYPE_STRING, sizeof(char) }, + { CPL_TYPE_CHAR, sizeof(char) }, + { CPL_TYPE_UCHAR, sizeof(unsigned char) }, + { CPL_TYPE_BOOL, sizeof(cpl_boolean) }, + { CPL_TYPE_SHORT, sizeof(short) }, + { CPL_TYPE_USHORT, sizeof(unsigned short) }, + { CPL_TYPE_INT, sizeof(int) }, + { CPL_TYPE_UINT, sizeof(unsigned int) }, + { CPL_TYPE_LONG, sizeof(long int) }, + { CPL_TYPE_ULONG, sizeof(unsigned long int) }, + { CPL_TYPE_LONG_LONG, sizeof(long long int) }, + { CPL_TYPE_SIZE, sizeof(cpl_size) }, + { CPL_TYPE_FLOAT, sizeof(float) }, + { CPL_TYPE_DOUBLE, sizeof(double) }, + { CPL_TYPE_FLOAT_COMPLEX, sizeof(float complex) }, + { CPL_TYPE_DOUBLE_COMPLEX, sizeof(double complex) }, + { CPL_TYPE_UNSPECIFIED, 0 }, + { CPL_TYPE_POINTER, sizeof(void *) } + }; const int nsupported = (int)(sizeof(supported) / sizeof(typelist)); - const char * empty; + const char *empty; int i; cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); @@ -75,25 +77,25 @@ cpl_test_noneq(CPL_FALSE, CPL_TRUE); for (i = 0; i < nsupported; i++) { - const char * name = cpl_type_get_name(supported[i].type); + const char *name = cpl_type_get_name(supported[i].type); - cpl_msg_info(cpl_func, "Testing type: %s (size=%u)", - name, (unsigned)supported[i].size); + cpl_msg_info(cpl_func, "Testing type: %s (size=%u)", name, + (unsigned)supported[i].size); cpl_test_eq(cpl_type_get_sizeof(supported[i].type), supported[i].size); - cpl_test_eq(cpl_type_get_sizeof(supported[i].type | CPL_TYPE_FLAG_ARRAY), + cpl_test_eq(cpl_type_get_sizeof(supported[i].type | + CPL_TYPE_FLAG_ARRAY), supported[i].size); cpl_test_nonnull(name); if (supported[i].size != 0) { - const char * array = cpl_type_get_name(supported[i].type - | CPL_TYPE_POINTER); + const char *array = + cpl_type_get_name(supported[i].type | CPL_TYPE_POINTER); cpl_test_nonnull(array); if (array != NULL) { - if (name != NULL) { /* Array name starts with type name, e.g. "double array" */ cpl_test_eq_string(strstr(array, name), array); @@ -102,7 +104,8 @@ if (supported[i].type != CPL_TYPE_POINTER) { /* And also contains the sub-string " array" */ cpl_test_nonnull(strstr(array, " array")); - } else { + } + else { cpl_test_null(strstr(array, " array")); } } @@ -111,15 +114,14 @@ /* Get a new name by combining with flag array */ /* Cannot be done for pointer, nor for char/string since those two are defined using this combination */ - if (supported[i].size != 0 && supported[i].type != CPL_TYPE_POINTER - && supported[i].type != CPL_TYPE_STRING - && supported[i].type != CPL_TYPE_CHAR) { - const char * array = cpl_type_get_name(supported[i].type - | CPL_TYPE_FLAG_ARRAY); + if (supported[i].size != 0 && supported[i].type != CPL_TYPE_POINTER && + supported[i].type != CPL_TYPE_STRING && + supported[i].type != CPL_TYPE_CHAR) { + const char *array = + cpl_type_get_name(supported[i].type | CPL_TYPE_FLAG_ARRAY); cpl_test_nonnull(array); if (array != NULL) { - if (name != NULL) { /* Array name starts with type name, e.g. "double array" */ cpl_test_eq_string(strstr(array, name), array); @@ -137,7 +139,8 @@ empty = cpl_type_get_name(CPL_TYPE_POINTER | CPL_TYPE_FLAG_ARRAY); cpl_test_error(CPL_ERROR_INVALID_TYPE); cpl_test_nonnull(empty); - if (empty != NULL) cpl_test_zero(*empty); + if (empty != NULL) + cpl_test_zero(*empty); return cpl_test_end(0); } diff -Nru cpl-7.1.4+ds/cplcore/tests/cpl_vector-test.c cpl-7.2.2+ds/cplcore/tests/cpl_vector-test.c --- cpl-7.1.4+ds/cplcore/tests/cpl_vector-test.c 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/tests/cpl_vector-test.c 2022-04-29 14:56:01.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -39,7 +39,7 @@ /* Must have three digits, for perl-test to work */ #define VECTOR_SIZE 256 -#define VECTOR_CUT 24 +#define VECTOR_CUT 24 /* alphaev56 SIGFPE's with more than 20 */ #define POLY_SIZE 20 @@ -58,33 +58,36 @@ /*----------------------------------------------------------------------------- Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { - double xc; - double emax = 0; /* Maximum observed xc-error */ - double tmp; - cpl_vector * null; - cpl_vector * sinus; - cpl_vector * cosinus; - cpl_vector * tmp_vec; - cpl_vector * taylor; - cpl_vector * tmp_vec2; - cpl_vector * vxc; - cpl_vector * vxc1; - cpl_vector * vxc3; - double * data; - const double five[] = {1,2,3,4,5}; + double xc; + double emax = 0; /* Maximum observed xc-error */ + double tmp; + cpl_vector *null; + cpl_vector *sinus; + cpl_vector *cosinus; + cpl_vector *tmp_vec; + cpl_vector *taylor; + cpl_vector *tmp_vec2; + cpl_vector *vxc; + cpl_vector *vxc1; + cpl_vector *vxc3; + double *data; + const double five[] = { 1, 2, 3, 4, 5 }; const cpl_size vdif = VECTOR_SIZE - VECTOR_CUT > VECTOR_CUT - ? VECTOR_CUT : VECTOR_SIZE - VECTOR_CUT; - const cpl_size vdif2 = (VECTOR_SIZE - VECTOR_CUT)/2 > VECTOR_CUT/2 - ? VECTOR_CUT/2 : (VECTOR_SIZE - VECTOR_CUT)/2; - cpl_size delta; - cpl_size half_search; - cpl_size i,k; - cpl_boolean do_bench; - FILE * stream; - FILE * f_out; - char filename[1024]; + ? VECTOR_CUT + : VECTOR_SIZE - VECTOR_CUT; + const cpl_size vdif2 = (VECTOR_SIZE - VECTOR_CUT) / 2 > VECTOR_CUT / 2 + ? VECTOR_CUT / 2 + : (VECTOR_SIZE - VECTOR_CUT) / 2; + cpl_size delta; + cpl_size half_search; + cpl_size i, k; + cpl_boolean do_bench; + FILE *stream; + FILE *f_out; + char filename[1024]; cpl_boolean did_test_large = CPL_FALSE; cpl_error_code error; const int omp_num_threads = @@ -92,19 +95,19 @@ /* Measure scaled speed-up */ getenv("OMP_NUM_THREADS") ? atoi(getenv("OMP_NUM_THREADS")) : #endif - 1; + 1; const int npe = omp_num_threads > 1 ? omp_num_threads : 1; cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); - stream = cpl_msg_get_level() > CPL_MSG_INFO - ? fopen("/dev/null", "a") : stdout; + stream = + cpl_msg_get_level() > CPL_MSG_INFO ? fopen("/dev/null", "a") : stdout; do_bench = cpl_msg_get_level() <= CPL_MSG_INFO ? CPL_TRUE : CPL_FALSE; /* Insert tests below */ - cpl_test_nonnull( stream ); + cpl_test_nonnull(stream); /* Test both odd and even numbered */ cpl_vector_cycle_test(13); @@ -136,73 +139,76 @@ cpl_test_rel(1.5, cpl_vector_get_median(tmp_vec), DBL_EPSILON); cpl_test_rel(1.5, cpl_vector_get_median_const(tmp_vec), DBL_EPSILON); cpl_vector_delete(tmp_vec); - + /* Create the vector sinus */ - cpl_test_nonnull( sinus = cpl_vector_new(VECTOR_SIZE) ); - + cpl_test_nonnull(sinus = cpl_vector_new(VECTOR_SIZE)); + /* Test cpl_vector_get_size() */ - cpl_test_eq( cpl_vector_get_size(sinus), VECTOR_SIZE ); + cpl_test_eq(cpl_vector_get_size(sinus), VECTOR_SIZE); /* Fill the vector sinus */ /* Test cpl_vector_get_data(), cpl_vector_set(), cpl_vector_get() */ data = cpl_vector_get_data(sinus); - cpl_test_nonnull( data ); - for (i=0; i < VECTOR_SIZE; i++) { - const double value = sin(i*CPL_MATH_2PI/VECTOR_SIZE); - cpl_test_zero( cpl_vector_set(sinus, i, value) ); - cpl_test_eq( cpl_vector_get(sinus, i), data[i] ); + cpl_test_nonnull(data); + for (i = 0; i < VECTOR_SIZE; i++) { + const double value = sin(i * CPL_MATH_2PI / VECTOR_SIZE); + cpl_test_zero(cpl_vector_set(sinus, i, value)); + cpl_test_eq(cpl_vector_get(sinus, i), data[i]); } /* Create a Taylor-expansion of exp() */ - cpl_test_nonnull( taylor = cpl_vector_new(POLY_SIZE) ); + cpl_test_nonnull(taylor = cpl_vector_new(POLY_SIZE)); i = 0; cpl_vector_set(taylor, i, 1); - for (i=1; i 0; k--) { - cpl_test_zero( cpl_vector_multiply(tmp_vec2, sinus) ); - if (k&1) { - cpl_test_zero( cpl_vector_add_scalar(tmp_vec2, - cpl_vector_get(taylor, k-1)) ); - } else { - cpl_test_zero( cpl_vector_subtract_scalar(tmp_vec2, - -cpl_vector_get(taylor, k-1)) ); + + for (k = POLY_SIZE - 1; k > 0; k--) { + cpl_test_zero(cpl_vector_multiply(tmp_vec2, sinus)); + if (k & 1) { + cpl_test_zero( + cpl_vector_add_scalar(tmp_vec2, cpl_vector_get(taylor, k - 1))); } - } + else { + cpl_test_zero( + cpl_vector_subtract_scalar(tmp_vec2, + -cpl_vector_get(taylor, k - 1))); + } + } /* Verify the result (against cpl_vector_exponential() ) */ - cpl_test( tmp_vec = cpl_vector_duplicate(sinus) ); + cpl_test(tmp_vec = cpl_vector_duplicate(sinus)); - cpl_test_zero( cpl_vector_exponential(tmp_vec, CPL_MATH_E) ); + cpl_test_zero(cpl_vector_exponential(tmp_vec, CPL_MATH_E)); - cpl_test_zero( cpl_vector_subtract(tmp_vec2, tmp_vec) ); - cpl_test_zero( cpl_vector_divide(tmp_vec2, tmp_vec) ); - cpl_test_zero( cpl_vector_divide_scalar(tmp_vec2, DBL_EPSILON) ); + cpl_test_zero(cpl_vector_subtract(tmp_vec2, tmp_vec)); + cpl_test_zero(cpl_vector_divide(tmp_vec2, tmp_vec)); + cpl_test_zero(cpl_vector_divide_scalar(tmp_vec2, DBL_EPSILON)); - cpl_test_leq( fabs(cpl_vector_get_max(tmp_vec2)), 2.60831 ); - cpl_test_leq( fabs(cpl_vector_get_min(tmp_vec2)), 2.03626 ); + cpl_test_leq(fabs(cpl_vector_get_max(tmp_vec2)), 2.60831); + cpl_test_leq(fabs(cpl_vector_get_min(tmp_vec2)), 2.03626); /* Evaluate exp() using cpl_vector_pow() on the Taylor expansion */ - cpl_test_zero( cpl_vector_fill(tmp_vec2, cpl_vector_get(taylor, 0)) ); + cpl_test_zero(cpl_vector_fill(tmp_vec2, cpl_vector_get(taylor, 0))); /* POLY_SIZE > 20 on alphaev56: Program received signal SIGFPE, Arithmetic exception. 0x200000a3ff0 in cpl_vector_multiply_scalar () */ - for (k=1; k < POLY_SIZE; k++) { - cpl_vector * vtmp = cpl_vector_duplicate(sinus); - cpl_test_zero( cpl_vector_power(vtmp, k) ); - cpl_test_zero( cpl_vector_multiply_scalar(vtmp, cpl_vector_get(taylor, k)) ); - cpl_test_zero( cpl_vector_add(tmp_vec2, vtmp) ); + for (k = 1; k < POLY_SIZE; k++) { + cpl_vector *vtmp = cpl_vector_duplicate(sinus); + cpl_test_zero(cpl_vector_power(vtmp, k)); + cpl_test_zero( + cpl_vector_multiply_scalar(vtmp, cpl_vector_get(taylor, k))); + cpl_test_zero(cpl_vector_add(tmp_vec2, vtmp)); cpl_vector_delete(vtmp); - } + } /* Much less precise than Horner ... */ cpl_test_vector_abs(tmp_vec, tmp_vec2, 8.0 * DBL_EPSILON); @@ -218,65 +224,67 @@ cpl_vector_delete(taylor); /* Verify cpl_vector_logarithm() ) */ - cpl_test_zero( cpl_vector_logarithm(tmp_vec, CPL_MATH_E) ); - for (i=0; i < VECTOR_SIZE; i++) { + cpl_test_zero(cpl_vector_logarithm(tmp_vec, CPL_MATH_E)); + for (i = 0; i < VECTOR_SIZE; i++) { const double value = cpl_vector_get(sinus, i); - double lerror = value - cpl_vector_get(tmp_vec, i); - if (2*i == VECTOR_SIZE) { + double lerror = value - cpl_vector_get(tmp_vec, i); + if (2 * i == VECTOR_SIZE) { /* value should really be zero */ - cpl_test_abs( value, 0.0, 0.552 * DBL_EPSILON ); - } else { - if (value != 0) lerror /= value; - cpl_test_abs( lerror, 0.0, 330 * DBL_EPSILON ); + cpl_test_abs(value, 0.0, 0.552 * DBL_EPSILON); + } + else { + if (value != 0) + lerror /= value; + cpl_test_abs(lerror, 0.0, 330 * DBL_EPSILON); } } /* Verify cpl_vector_power() */ - cpl_test_zero( cpl_vector_copy(tmp_vec, sinus) ); + cpl_test_zero(cpl_vector_copy(tmp_vec, sinus)); /* Just be positive */ - cpl_test_zero( cpl_vector_exponential(tmp_vec, CPL_MATH_E) ); + cpl_test_zero(cpl_vector_exponential(tmp_vec, CPL_MATH_E)); - cpl_test_zero( cpl_vector_copy(tmp_vec2, tmp_vec) ); + cpl_test_zero(cpl_vector_copy(tmp_vec2, tmp_vec)); - cpl_test_zero( cpl_vector_sqrt(tmp_vec2) ); - cpl_test_zero( cpl_vector_power(tmp_vec, 0.5) ); + cpl_test_zero(cpl_vector_sqrt(tmp_vec2)); + cpl_test_zero(cpl_vector_power(tmp_vec, 0.5)); /* Necessary on AMD 64 (x86_64) Linux */ cpl_test_vector_abs(tmp_vec, tmp_vec2, 1.1 * DBL_EPSILON); - cpl_test_zero( cpl_vector_copy(tmp_vec, sinus) ); - cpl_test_zero( cpl_vector_exponential(tmp_vec, CPL_MATH_E) ); + cpl_test_zero(cpl_vector_copy(tmp_vec, sinus)); + cpl_test_zero(cpl_vector_exponential(tmp_vec, CPL_MATH_E)); - cpl_test_zero( cpl_vector_multiply(tmp_vec2, tmp_vec) ); + cpl_test_zero(cpl_vector_multiply(tmp_vec2, tmp_vec)); - cpl_test_zero( cpl_vector_power(tmp_vec, 1.5) ); + cpl_test_zero(cpl_vector_power(tmp_vec, 1.5)); cpl_test_vector_abs(tmp_vec, tmp_vec2, 8.0 * DBL_EPSILON); - cpl_test_zero( cpl_vector_copy(tmp_vec2, tmp_vec) ); + cpl_test_zero(cpl_vector_copy(tmp_vec2, tmp_vec)); - cpl_test_zero( cpl_vector_power(tmp_vec, 2) ); + cpl_test_zero(cpl_vector_power(tmp_vec, 2)); - cpl_test_zero( cpl_vector_divide(tmp_vec2, tmp_vec) ); + cpl_test_zero(cpl_vector_divide(tmp_vec2, tmp_vec)); - cpl_test_zero( cpl_vector_power(tmp_vec, -0.5) ); + cpl_test_zero(cpl_vector_power(tmp_vec, -0.5)); cpl_test_vector_abs(tmp_vec, tmp_vec2, 8.0 * DBL_EPSILON); - cpl_test_zero( cpl_vector_fill(tmp_vec, 1) ); + cpl_test_zero(cpl_vector_fill(tmp_vec, 1)); - cpl_test_zero( cpl_vector_power(tmp_vec2, 0) ); + cpl_test_zero(cpl_vector_power(tmp_vec2, 0)); cpl_test_vector_abs(tmp_vec, tmp_vec2, 0.0); cpl_vector_delete(tmp_vec2); /* Test 0^0 */ - cpl_test_nonnull( tmp_vec2 = cpl_vector_new(VECTOR_SIZE) ); - for (i = 0; i < VECTOR_SIZE; i++) - cpl_test_zero( cpl_vector_set(tmp_vec2, i, 0.0) ); + cpl_test_nonnull(tmp_vec2 = cpl_vector_new(VECTOR_SIZE)); + for (i = 0; i < VECTOR_SIZE; i++) + cpl_test_zero(cpl_vector_set(tmp_vec2, i, 0.0)); - cpl_test_zero( cpl_vector_power(tmp_vec2, 0.0) ); + cpl_test_zero(cpl_vector_power(tmp_vec2, 0.0)); cpl_test_vector_abs(tmp_vec, tmp_vec2, 0.0); cpl_vector_delete(tmp_vec); @@ -289,51 +297,51 @@ /* Test failures on cpl_vector_read() */ tmp_vec = cpl_vector_read(NULL); cpl_test_error(CPL_ERROR_NULL_INPUT); - cpl_test_null( tmp_vec ); + cpl_test_null(tmp_vec); tmp_vec = cpl_vector_read("/nonexisting"); cpl_test_error(CPL_ERROR_FILE_IO); - cpl_test_null( tmp_vec ); + cpl_test_null(tmp_vec); tmp_vec = cpl_vector_read("/dev/null"); cpl_test_error(CPL_ERROR_BAD_FILE_FORMAT); - cpl_test_null( tmp_vec ); + cpl_test_null(tmp_vec); /* Test correct case on cpl_vector_read() */ sprintf(filename, "cpl_vector_dump.txt"); - cpl_test_nonnull( filename ); - cpl_test_nonnull( f_out = fopen(filename, "w") ); + cpl_test_nonnull(filename); + cpl_test_nonnull(f_out = fopen(filename, "w")); cpl_vector_dump(sinus, f_out); fclose(f_out); tmp_vec = cpl_vector_read("cpl_vector_dump.txt"); - cpl_test_zero( remove("cpl_vector_dump.txt") ); - cpl_test_nonnull( tmp_vec ); + cpl_test_zero(remove("cpl_vector_dump.txt")); + cpl_test_nonnull(tmp_vec); - cpl_test_eq( cpl_vector_get_size(tmp_vec), cpl_vector_get_size(sinus) ); + cpl_test_eq(cpl_vector_get_size(tmp_vec), cpl_vector_get_size(sinus)); /* Test cpl_vector_save() / cpl_vector_load() */ error = cpl_vector_save(tmp_vec, "cpl_vector_save.fits", CPL_TYPE_DOUBLE, - NULL, CPL_IO_CREATE | CPL_IO_EXTEND); - cpl_test_eq_error( error, CPL_ERROR_ILLEGAL_INPUT ); + NULL, CPL_IO_CREATE | CPL_IO_EXTEND); + cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); error = cpl_vector_save(tmp_vec, "cpl_vector_save.fits", CPL_TYPE_DOUBLE, - NULL, CPL_IO_APPEND); - cpl_test_eq_error( error, CPL_ERROR_ILLEGAL_INPUT ); + NULL, CPL_IO_APPEND); + cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); error = cpl_vector_save(tmp_vec, "cpl_vector_save.fits", CPL_TYPE_DOUBLE, - NULL, CPL_IO_CREATE | CPL_IO_APPEND); - cpl_test_eq_error( error, CPL_ERROR_ILLEGAL_INPUT ); + NULL, CPL_IO_CREATE | CPL_IO_APPEND); + cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); error = cpl_vector_save(tmp_vec, "cpl_vector_save.fits", CPL_TYPE_DOUBLE, - NULL, CPL_IO_CREATE); - cpl_test_eq_error( error, CPL_ERROR_NONE ); + NULL, CPL_IO_CREATE); + cpl_test_eq_error(error, CPL_ERROR_NONE); cpl_test_fits("cpl_vector_save.fits"); tmp_vec2 = cpl_vector_load("cpl_vector_save.fits", 0); - cpl_test_error( CPL_ERROR_NONE ); - cpl_test_zero( remove("cpl_vector_save.fits") ); - cpl_test_nonnull( tmp_vec2 ); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_zero(remove("cpl_vector_save.fits")); + cpl_test_nonnull(tmp_vec2); /* Verify that the save/load did not change the vector */ cpl_test_vector_abs(tmp_vec, tmp_vec2, 0.0); @@ -341,40 +349,39 @@ cpl_vector_delete(tmp_vec2); /* Repeat test cpl_vector_save() / cpl_vector_load() on APPEND mode*/ - error = cpl_vector_save(tmp_vec, "cpl_vector_save.fits", - CPL_TYPE_DOUBLE, NULL, CPL_IO_CREATE); - cpl_test_eq_error( error, CPL_ERROR_NONE ); + error = cpl_vector_save(tmp_vec, "cpl_vector_save.fits", CPL_TYPE_DOUBLE, + NULL, CPL_IO_CREATE); + cpl_test_eq_error(error, CPL_ERROR_NONE); cpl_test_fits("cpl_vector_save.fits"); - error = cpl_vector_save(tmp_vec, "cpl_vector_save.fits", - CPL_TYPE_DOUBLE, NULL, CPL_IO_EXTEND); - cpl_test_eq_error( error, CPL_ERROR_NONE ); + error = cpl_vector_save(tmp_vec, "cpl_vector_save.fits", CPL_TYPE_DOUBLE, + NULL, CPL_IO_EXTEND); + cpl_test_eq_error(error, CPL_ERROR_NONE); cpl_test_fits("cpl_vector_save.fits"); /* Verify that the save/load did not change the vector on 0. ext. */ tmp_vec2 = cpl_vector_load("cpl_vector_save.fits", 0); - cpl_test_nonnull( tmp_vec2 ); + cpl_test_nonnull(tmp_vec2); cpl_test_vector_abs(tmp_vec, tmp_vec2, 0.0); cpl_vector_delete(tmp_vec2); /* Verify that the save/load did not change the vector on 1. ext. */ tmp_vec2 = cpl_vector_load("cpl_vector_save.fits", 1); - cpl_test_nonnull( tmp_vec2 ); + cpl_test_nonnull(tmp_vec2); cpl_test_vector_abs(tmp_vec, tmp_vec2, 0.0); cpl_vector_delete(tmp_vec2); if (!cpl_io_fits_is_enabled()) { /* Decrease the number of elements by one, thus verifying that an external application may modify the file */ - if (system("perl -pi -e 'BEGIN{sleep(1)};/NAXIS1/ and s/" - CPL_STRINGIFY(VECTOR_SIZE) "/sprintf(\"%d\"," - CPL_STRINGIFY(VECTOR_SIZE-1) - ")/e' cpl_vector_save.fits") == 0) { - + if (system("perl -pi -e 'BEGIN{sleep(1)};/NAXIS1/ and s/" CPL_STRINGIFY(VECTOR_SIZE) "/sprintf(\"%d\"," CPL_STRINGIFY(VECTOR_SIZE-1) ")/e' " + "cpl_vector_" + "save.fits") == + 0) { tmp_vec2 = cpl_vector_load("cpl_vector_save.fits", 0); cpl_test_error(CPL_ERROR_NONE); - cpl_test_nonnull( tmp_vec2 ); - cpl_test_eq(cpl_vector_get_size(tmp_vec2), VECTOR_SIZE-1); + cpl_test_nonnull(tmp_vec2); + cpl_test_eq(cpl_vector_get_size(tmp_vec2), VECTOR_SIZE - 1); cpl_vector_delete(tmp_vec2); } } @@ -385,13 +392,11 @@ /* Cannot load a vector longer than 2**31 - 1 */ /* Increase the number of elements to more than 2**31 */ - if (system("perl -pi -e '/NAXIS1/ and s/ " - CPL_STRINGIFY(VECTOR_SIZE) - "/2200000000/' cpl_vector_save.fits") == 0) { - + if (system("perl -pi -e '/NAXIS1/ and s/ " CPL_STRINGIFY(VECTOR_SIZE) "/2200000000/' cpl_vector_save.fits") == + 0) { tmp_vec2 = cpl_vector_load("cpl_vector_save.fits", 0); cpl_test_error(CPL_ERROR_UNSUPPORTED_MODE); - cpl_test_null( tmp_vec2 ); + cpl_test_null(tmp_vec2); if (tmp_vec2 != NULL) { /* The original size is VECTOR_SIZE */ cpl_test_noneq(cpl_vector_get_size(tmp_vec2), VECTOR_SIZE); @@ -403,8 +408,9 @@ } #endif #ifdef CPL_TEST_LARGE - } else if (sizeof(cpl_size) == 8) { - cpl_vector * long_vec = cpl_vector_new(2200000000L); + } + else if (sizeof(cpl_size) == 8) { + cpl_vector *long_vec = cpl_vector_new(2200000000L); error = cpl_vector_save(long_vec, "cpl_vector_save.fits", CPL_TYPE_DOUBLE, NULL, CPL_IO_CREATE); cpl_test_eq_error(error, CPL_ERROR_NONE); @@ -422,7 +428,7 @@ cpl_msg_info(cpl_func, "I/O-testing of large vectors inactive"); } - cpl_test_zero( remove("cpl_vector_save.fits") ); + cpl_test_zero(remove("cpl_vector_save.fits")); /* Loss of precision in cpl_vector_dump() */ cpl_test_vector_abs(tmp_vec, sinus, 10.0 * FLT_EPSILON); @@ -430,8 +436,8 @@ cpl_vector_subtract(tmp_vec, sinus); /* Same loss for positive as for negative numbers */ - cpl_test_abs( cpl_vector_get_max(tmp_vec)+cpl_vector_get_min(tmp_vec), 0.0, - 2.5 * DBL_EPSILON); + cpl_test_abs(cpl_vector_get_max(tmp_vec) + cpl_vector_get_min(tmp_vec), 0.0, + 2.5 * DBL_EPSILON); cpl_vector_delete(tmp_vec); @@ -440,43 +446,43 @@ cpl_test_vector_abs(tmp_vec, sinus, 0.0); /* Test fill function */ - cpl_test_eq_error( cpl_vector_fill(tmp_vec, 1.0), CPL_ERROR_NONE ); - cpl_test_abs( cpl_vector_get_mean(tmp_vec), 1.0, DBL_EPSILON ); + cpl_test_eq_error(cpl_vector_fill(tmp_vec, 1.0), CPL_ERROR_NONE); + cpl_test_abs(cpl_vector_get_mean(tmp_vec), 1.0, DBL_EPSILON); - cpl_test_abs( cpl_vector_get_sum(tmp_vec), (double)(VECTOR_SIZE), - DBL_EPSILON * sqrt((double)(VECTOR_SIZE))); + cpl_test_abs(cpl_vector_get_sum(tmp_vec), (double)(VECTOR_SIZE), + DBL_EPSILON * sqrt((double)(VECTOR_SIZE))); (void)cpl_vector_get_sum(NULL); cpl_test_error(CPL_ERROR_NULL_INPUT); /* Test extract function */ - tmp_vec2 = cpl_vector_extract(tmp_vec, 0, VECTOR_SIZE/2, 1); - cpl_test_nonnull( tmp_vec2 ); + tmp_vec2 = cpl_vector_extract(tmp_vec, 0, VECTOR_SIZE / 2, 1); + cpl_test_nonnull(tmp_vec2); cpl_vector_delete(tmp_vec2); null = cpl_vector_extract(NULL, 0, 1, 1); cpl_test_error(CPL_ERROR_NULL_INPUT); - cpl_test_null( null ); - + cpl_test_null(null); + null = cpl_vector_extract(tmp_vec, 2, 1, 1); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); - cpl_test_null( null ); + cpl_test_null(null); null = cpl_vector_extract(tmp_vec, 1, 2, 2); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); - cpl_test_null( null ); + cpl_test_null(null); null = cpl_vector_extract(tmp_vec, -1, 2, 1); cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); - cpl_test_null( null ); + cpl_test_null(null); null = cpl_vector_extract(tmp_vec, 0, VECTOR_SIZE + 2, 1); cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); - cpl_test_null( null ); + cpl_test_null(null); CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); - vxc = cpl_vector_wrap(5, (double*)five); + vxc = cpl_vector_wrap(5, (double *)five); CPL_DIAG_PRAGMA_POP; vxc1 = cpl_vector_extract(vxc, 1, 4, 1); @@ -485,7 +491,7 @@ cpl_test_eq_ptr(five, cpl_vector_unwrap(vxc)); CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); - vxc = cpl_vector_wrap(4, (double*)five + 1); + vxc = cpl_vector_wrap(4, (double *)five + 1); CPL_DIAG_PRAGMA_POP; cpl_test_vector_abs(vxc, vxc1, 0.0); @@ -494,25 +500,26 @@ /* Create the vector cosinus */ cosinus = cpl_vector_new(VECTOR_SIZE); - cpl_test_eq( cpl_vector_get_size(sinus), VECTOR_SIZE ); - + cpl_test_eq(cpl_vector_get_size(sinus), VECTOR_SIZE); + /* Fill the vector cosinus */ data = cpl_vector_get_data(cosinus); - cpl_test_nonnull( data ); - for (i=0; i emax) emax = fabs(1-xc); + cpl_test_abs(xc, 1.0, 5.0 * DBL_EPSILON); + if (fabs(1 - xc) > emax) + emax = fabs(1 - xc); if (VECTOR_SIZE % 2 == 0) { /* Sinus and cosinus have zero cross-correlation with zero shift */ - cpl_test_zero( cpl_vector_correlate(vxc1, sinus, cosinus) ); + cpl_test_zero(cpl_vector_correlate(vxc1, sinus, cosinus)); xc = cpl_vector_get(vxc1, 0); - cpl_test_leq( fabs(xc), 2.82*DBL_EPSILON ); - if (fabs(xc) > emax) emax = fabs(xc); + cpl_test_leq(fabs(xc), 2.82 * DBL_EPSILON); + if (fabs(xc) > emax) + emax = fabs(xc); } /* cosinus and -cosinus have cross-correlation -1 with zero shift */ tmp_vec = cpl_vector_duplicate(cosinus); cpl_test_vector_abs(tmp_vec, cosinus, 0.0); - cpl_test_zero( cpl_vector_divide_scalar(tmp_vec, -1) ); + cpl_test_zero(cpl_vector_divide_scalar(tmp_vec, -1)); - cpl_test_zero( cpl_vector_correlate(vxc1, tmp_vec, cosinus) ); + cpl_test_zero(cpl_vector_correlate(vxc1, tmp_vec, cosinus)); xc = cpl_vector_get(vxc1, 0); cpl_vector_delete(tmp_vec); - cpl_test_abs( xc, -1.0, 5.0 * DBL_EPSILON ); - if (fabs(1+xc) > emax) emax = fabs(1+xc); + cpl_test_abs(xc, -1.0, 5.0 * DBL_EPSILON); + if (fabs(1 + xc) > emax) + emax = fabs(1 + xc); - vxc = cpl_vector_new( 1 ); + vxc = cpl_vector_new(1); if (VECTOR_SIZE % 2 == 0) { /* Cross-correlation between sinus and cosinus grows to maximum at shift of pi/2 */ - for (i=0; i xcp ); - cpl_test_eq( llabs(delta-(i+1)), i+1 ); + cpl_test(xc > xcp); + cpl_test_eq(llabs(delta - (i + 1)), i + 1); } - cpl_test_abs( xc, 1.0, 260*DBL_EPSILON); - half_search = VECTOR_SIZE/3; - cpl_test_zero( cpl_vector_set_size(vxc, 2*half_search + 1) ); + cpl_test_abs(xc, 1.0, 260 * DBL_EPSILON); + half_search = VECTOR_SIZE / 3; + cpl_test_zero(cpl_vector_set_size(vxc, 2 * half_search + 1)); delta = cpl_vector_correlate(vxc, sinus, cosinus); - xc = cpl_vector_get(vxc, delta ); - cpl_test_eq( llabs(delta-VECTOR_SIZE/3), VECTOR_SIZE/4 ); - if (fabs(1-xc) > emax) emax = fabs(1-xc); + xc = cpl_vector_get(vxc, delta); + cpl_test_eq(llabs(delta - VECTOR_SIZE / 3), VECTOR_SIZE / 4); + if (fabs(1 - xc) > emax) + emax = fabs(1 - xc); } cpl_vector_delete(sinus); @@ -760,73 +775,74 @@ /* Vectors of almost the same length - no commutativity */ /* Create the vector sinus */ - cpl_test_nonnull( sinus = cpl_vector_new(VECTOR_SIZE-VECTOR_CUT) ); - + cpl_test_nonnull(sinus = cpl_vector_new(VECTOR_SIZE - VECTOR_CUT)); + /* Fill the vector sinus */ data = cpl_vector_get_data(sinus); - cpl_test_nonnull( data ); - for (i=0; i emax) emax = fabs(1-xc); + cpl_test_zero(delta + VECTOR_CUT / 2); + cpl_test_abs(xc, 1.0, 16.5 * DBL_EPSILON); + if (fabs(1 - xc) > emax) + emax = fabs(1 - xc); /* Compare with increasing shift and increasing drop of elements - only up to the length-difference */ for (k = 1; k < vdif; k++) { - - for (i=0; i emax) emax = fabs(1-xc); - + cpl_test_eq(delta + VECTOR_CUT / 2, k); + cpl_test_abs(xc, 1.0, 18.5 * DBL_EPSILON); + if (fabs(1 - xc) > emax) + emax = fabs(1 - xc); } /* Continue - maximum xc found with drop */ for (; k < vdif; k++) { - half_search = k-VECTOR_CUT/2; - cpl_test_zero( cpl_vector_set_size(vxc, 2*half_search + 1) ); + half_search = k - VECTOR_CUT / 2; + cpl_test_zero(cpl_vector_set_size(vxc, 2 * half_search + 1)); - for (i=0; i emax) emax = fabs(1-xc); + cpl_test_abs(xc, 1.0, 25.0 * DBL_EPSILON); + cpl_test_eq(delta + VECTOR_CUT / 2, k); + if (fabs(1 - xc) > emax) + emax = fabs(1 - xc); } /* Compare with increasing negative shift and increasing drop of elements - only up to half the length-difference */ half_search = VECTOR_CUT; - cpl_test_zero( cpl_vector_set_size(vxc, 2*half_search + 1) ); + cpl_test_zero(cpl_vector_set_size(vxc, 2 * half_search + 1)); xc = 1; for (k = 1; k < vdif2; k++) { const double xcp = xc; - for (i=0; i emax) emax = fabs(1-xc); + cpl_test_zero(delta); + cpl_test_abs(xc, 1.0, 5.0 * DBL_EPSILON); + if (fabs(1 - xc) > emax) + emax = fabs(1 - xc); /* Verify commutativity */ - cpl_test_eq( delta+half_search, cpl_vector_correlate(vxc, cosinus, sinus) ); - cpl_test_eq( xc, cpl_vector_get(vxc, delta+half_search) ); + cpl_test_eq(delta + half_search, cpl_vector_correlate(vxc, cosinus, sinus)); + cpl_test_eq(xc, cpl_vector_get(vxc, delta + half_search)); data = cpl_vector_get_data(sinus); - cpl_test_nonnull( data ); + cpl_test_nonnull(data); - half_search = VECTOR_SIZE/2; - cpl_test_zero( cpl_vector_set_size(vxc, 2*half_search + 1) ); + half_search = VECTOR_SIZE / 2; + cpl_test_zero(cpl_vector_set_size(vxc, 2 * half_search + 1)); /* Compare with increasing shift and increasing drop of elements - delta tests will not hold for large shifts */ xc = 1; - for (k = 1; k < VECTOR_SIZE/50; k+=7) { + for (k = 1; k < VECTOR_SIZE / 50; k += 7) { const double xcp = xc; double xcn; - for (i=0; i emax) emax = fabs(1-xc); - + cpl_test_leq(delta, 0.0); + cpl_test_abs(xc, 1.0, 23.5 * DBL_EPSILON); + if (fabs(1 - xc) > emax) + emax = fabs(1 - xc); } - cpl_msg_info("","Largest cross-correlation rounding error [DBL_EPSILON]: " - "%g", emax/DBL_EPSILON); + cpl_msg_info("", + "Largest cross-correlation rounding error [DBL_EPSILON]: " + "%g", + emax / DBL_EPSILON); if (do_bench) { - cpl_vector_corr_bench(4 * npe); cpl_vector_get_stdev_bench(64 * npe); /* cpl_msg_set_component_on(); */ cpl_vector_save_bench(200); /* cpl_msg_set_component_off(); */ - } else { + } + else { cpl_vector_corr_bench(1); cpl_vector_get_stdev_bench(1); cpl_vector_save_bench(1); @@ -944,7 +966,8 @@ cpl_vector_valarray_bench(50000); cpl_vector_valarray_bench(500000); cpl_vector_valarray_bench(5000000); - } else { + } + else { cpl_vector_valarray_bench(10); } @@ -961,7 +984,8 @@ cpl_vector_delete(vxc1); cpl_vector_delete(vxc3); - if (stream != stdout) cpl_test_zero( fclose(stream) ); + if (stream != stdout) + cpl_test_zero(fclose(stream)); /* End of tests */ return cpl_test_end(0); @@ -977,23 +1001,24 @@ @return void */ /*----------------------------------------------------------------------------*/ -static void cpl_vector_corr_bench(int n) +static void +cpl_vector_corr_bench(int n) { - - double secs; - const cpl_size nsize = 10*VECTOR_SIZE*VECTOR_SIZE; - cpl_vector * cosinus = cpl_vector_new(nsize); - cpl_vector * vxc = cpl_vector_new(5*VECTOR_SIZE | 1); - double * data = cpl_vector_get_data(cosinus); - cpl_flops flops0; + double secs; + const cpl_size nsize = 10 * VECTOR_SIZE * VECTOR_SIZE; + cpl_vector *cosinus = cpl_vector_new(nsize); + cpl_vector *vxc = cpl_vector_new(5 * VECTOR_SIZE | 1); + double *data = cpl_vector_get_data(cosinus); + cpl_flops flops0; const size_t bytes = (size_t)n * cpl_test_get_bytes_vector(cosinus); - int i; + int i; /* Fill the vector cosinus */ - for (i=0; i < nsize; i++) data[i] = cos(i*CPL_MATH_2PI/nsize); + for (i = 0; i < nsize; i++) + data[i] = cos(i * CPL_MATH_2PI / nsize); flops0 = cpl_tools_get_flops(); - secs = cpl_test_get_walltime(); + secs = cpl_test_get_walltime(); #ifdef _OPENMP #pragma omp parallel for private(i) @@ -1006,16 +1031,16 @@ flops0 = cpl_tools_get_flops() - flops0; if (secs > 0.0) { - cpl_msg_info("","Speed during %d correlations of size %" CPL_SIZE_FORMAT - " in %g secs [Mflop/s]: %g (%g)", n, nsize, secs, - flops0/secs/1e6, (double)flops0); - cpl_msg_info(cpl_func,"Processing rate [MB/s]: %g", + cpl_msg_info("", + "Speed during %d correlations of size %" CPL_SIZE_FORMAT + " in %g secs [Mflop/s]: %g (%g)", + n, nsize, secs, flops0 / secs / 1e6, (double)flops0); + cpl_msg_info(cpl_func, "Processing rate [MB/s]: %g", 1e-6 * (double)bytes / secs); } cpl_vector_delete(cosinus); cpl_vector_delete(vxc); - } /*----------------------------------------------------------------------------*/ /** @@ -1024,45 +1049,46 @@ @return void */ /*----------------------------------------------------------------------------*/ -static void cpl_vector_get_stdev_bench(int n) +static void +cpl_vector_get_stdev_bench(int n) { - - double secs; - const cpl_size nsize = 10 * VECTOR_SIZE*VECTOR_SIZE; - cpl_vector * cosinus = cpl_vector_new(nsize); - double * data = cpl_vector_get_data(cosinus); - cpl_flops flops0; + double secs; + const cpl_size nsize = 10 * VECTOR_SIZE * VECTOR_SIZE; + cpl_vector *cosinus = cpl_vector_new(nsize); + double *data = cpl_vector_get_data(cosinus); + cpl_flops flops0; const size_t bytes = (size_t)n * cpl_test_get_bytes_vector(cosinus); - int i; + int i; /* Fill the vector cosinus */ - for (i=0; i < nsize; i++) data[i] = cos(i*CPL_MATH_2PI/nsize); + for (i = 0; i < nsize; i++) + data[i] = cos(i * CPL_MATH_2PI / nsize); flops0 = cpl_tools_get_flops(); - secs = cpl_test_get_walltime(); + secs = cpl_test_get_walltime(); #ifdef _OPENMP #pragma omp parallel for private(i) #endif for (i = 0; i < n; i++) { - cpl_test_abs( cpl_vector_get_stdev(cosinus), - sqrt(nsize*0.5/(nsize - 1)), - 0.36 * DBL_EPSILON * sqrt(nsize)); + cpl_test_abs(cpl_vector_get_stdev(cosinus), + sqrt(nsize * 0.5 / (nsize - 1)), + 0.36 * DBL_EPSILON * sqrt(nsize)); } secs = cpl_test_get_walltime() - secs; flops0 = cpl_tools_get_flops() - flops0; if (secs > 0.0) { - cpl_msg_info(cpl_func,"Speed during %d standard devs of size %" - CPL_SIZE_FORMAT "in %g secs [Mflop/s]: %g (%g)", n, nsize, - secs, flops0/secs/1e6, (double)flops0); - cpl_msg_info(cpl_func,"Processing rate [MB/s]: %g", + cpl_msg_info(cpl_func, + "Speed during %d standard devs of size %" CPL_SIZE_FORMAT + "in %g secs [Mflop/s]: %g (%g)", + n, nsize, secs, flops0 / secs / 1e6, (double)flops0); + cpl_msg_info(cpl_func, "Processing rate [MB/s]: %g", 1e-6 * (double)bytes / secs); } cpl_vector_delete(cosinus); - } /*----------------------------------------------------------------------------*/ @@ -1072,69 +1098,65 @@ @return void */ /*----------------------------------------------------------------------------*/ -static void cpl_vector_save_bench(int n) +static void +cpl_vector_save_bench(int n) { - - const int nprops = 100; - int i; - double secs; - const char * filename = "cpl_vector_save_bench.fits"; - const double vval[] = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0}; - const int nvals = (int)(sizeof(vval)/sizeof(double)); - cpl_propertylist * qclist = cpl_propertylist_new(); - char key[81]; - const cpl_vector * vec; + const int nprops = 100; + int i; + double secs; + const char *filename = "cpl_vector_save_bench.fits"; + const double vval[] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; + const int nvals = (int)(sizeof(vval) / sizeof(double)); + cpl_propertylist *qclist = cpl_propertylist_new(); + char key[81]; + const cpl_vector *vec; size_t bytes; CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); - vec = cpl_vector_wrap(nvals, (double*)vval); + vec = cpl_vector_wrap(nvals, (double *)vval); CPL_DIAG_PRAGMA_POP; bytes = (size_t)n * cpl_test_get_bytes_vector(vec); cpl_msg_info(cpl_func, "Benchmarking with %d %d-length vectors", n, nvals); for (i = 0; i < nprops; i++) { - const int nlen = snprintf(key, 81, "ESO QC CARD%04d", i); - cpl_test( nlen > 0 && nlen < 81); - - cpl_test_zero( cpl_propertylist_append_int(qclist, key, i)); + cpl_test(nlen > 0 && nlen < 81); + cpl_test_zero(cpl_propertylist_append_int(qclist, key, i)); } - cpl_test_eq( cpl_propertylist_get_size(qclist), nprops); + cpl_test_eq(cpl_propertylist_get_size(qclist), nprops); - secs = cpl_test_get_cputime(); + secs = cpl_test_get_cputime(); for (i = 0; i < n; i++) { - - cpl_test_zero( cpl_vector_save(vec, filename, CPL_TYPE_DOUBLE, - qclist, CPL_IO_CREATE)); + cpl_test_zero(cpl_vector_save(vec, filename, CPL_TYPE_DOUBLE, qclist, + CPL_IO_CREATE)); } secs = cpl_test_get_cputime() - secs; - cpl_msg_info(cpl_func,"Time spent saving %d %d-sized vectors [s]: %g", - n, nvals, secs); + cpl_msg_info(cpl_func, "Time spent saving %d %d-sized vectors [s]: %g", n, + nvals, secs); if (secs > 0.0) { - cpl_msg_info(cpl_func,"Processing rate [MB/s]: %g", + cpl_msg_info(cpl_func, "Processing rate [MB/s]: %g", 1e-6 * (double)bytes / secs); } cpl_test_fits(filename); - cpl_test_zero( remove(filename) ); + cpl_test_zero(remove(filename)); CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); - cpl_vector_unwrap((cpl_vector*)vec); + cpl_vector_unwrap((cpl_vector *)vec); CPL_DIAG_PRAGMA_POP; cpl_propertylist_delete(qclist); return; - } @@ -1145,50 +1167,44 @@ @return void */ /*----------------------------------------------------------------------------*/ -static void cpl_vector_fit_gaussian_test_one(FILE * stream) +static void +cpl_vector_fit_gaussian_test_one(FILE *stream) { + const int N = 50; + cpl_vector *yval = cpl_vector_new(N); + cpl_vector *xval = cpl_vector_new(N); + cpl_vector *ysig = cpl_vector_new(N); - const int N = 50; - cpl_vector *yval = cpl_vector_new(N); - cpl_vector *xval = cpl_vector_new(N); - cpl_vector *ysig = cpl_vector_new(N); - - cpl_matrix *cov = NULL; - cpl_matrix *matrix = NULL; - - const double in_sigma = 10.0, - in_centre = 25.0, - peak = 769.52; - - int n; - double pos = 0.0, - centre, - offset, - sigma, - area, - mse, - chisq; + cpl_matrix *cov = NULL; + cpl_matrix *matrix = NULL; + + const double in_sigma = 10.0, in_centre = 25.0, peak = 769.52; + + int n; + double pos = 0.0, centre, offset, sigma, area, mse, chisq; cpl_error_code error; - + for (n = 0; n < N; n++) { const double d = (double)pos - in_centre; error = cpl_vector_set(xval, n, pos); cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_vector_set(yval, n, peak*exp(-d*d/(2.0*in_sigma*in_sigma))); + error = + cpl_vector_set(yval, n, + peak * exp(-d * d / (2.0 * in_sigma * in_sigma))); cpl_test_eq_error(error, CPL_ERROR_NONE); - + /* the following line seems to make it fail. * normally, it should have no influence at all since all sigmas * are the same. strangely, using 1.0/sqrt(N-1) also fails, * but modifying this value slightly (e.g. by adding 1e-6) * lets the fitting succeed. is there a meaning in the failure * for 1.0/sqrt(integer)? */ - - error = cpl_vector_set(ysig, n, 1.0/sqrt(N)); + + error = cpl_vector_set(ysig, n, 1.0 / sqrt(N)); cpl_test_eq_error(error, CPL_ERROR_NONE); - + pos += 1.0; /* create one missing value, * this has no special meaning, just replicates the generation of @@ -1203,18 +1219,9 @@ cpl_vector_dump(yval, stream); cpl_vector_dump(ysig, stream); - error = cpl_vector_fit_gaussian(xval, - NULL, - yval, - ysig, - CPL_FIT_ALL, - ¢re, - &sigma, - &area, - &offset, - &mse, - &chisq, - &cov); + error = + cpl_vector_fit_gaussian(xval, NULL, yval, ysig, CPL_FIT_ALL, ¢re, + &sigma, &area, &offset, &mse, &chisq, &cov); cpl_test_eq_error(error, CPL_ERROR_NONE); cpl_msg_info(cpl_func, "%d-length Gaussian fit, center: %g", N, centre); @@ -1244,7 +1251,6 @@ cpl_vector_delete(xval); cpl_matrix_delete(cov); cpl_matrix_delete(matrix); - } /*----------------------------------------------------------------------------*/ @@ -1255,32 +1261,32 @@ @return void */ /*----------------------------------------------------------------------------*/ -static void cpl_vector_valarray_bench_one(cpl_vector * a, cpl_vector * b) +static void +cpl_vector_valarray_bench_one(cpl_vector *a, cpl_vector *b) { - const cpl_size n = cpl_vector_get_size(a); - double cputime, tstop; - const double tstart = cpl_test_get_cputime(); - - cpl_vector_add(a, b); - cpl_vector_subtract(a, b); - cpl_vector_multiply(a, b); - cpl_vector_divide(a, b); - cpl_vector_add_scalar(a, 10); - cpl_vector_subtract_scalar(a, 10); - cpl_vector_multiply_scalar(a, 10); - cpl_vector_divide_scalar(a, 10); - cpl_vector_get_min(a); - cpl_vector_get_max(a); - cpl_vector_get_sum(a); - cpl_vector_get_mean(a); - cpl_vector_get_stdev(a); + const cpl_size n = cpl_vector_get_size(a); + double cputime, tstop; + const double tstart = cpl_test_get_cputime(); + + cpl_vector_add(a, b); + cpl_vector_subtract(a, b); + cpl_vector_multiply(a, b); + cpl_vector_divide(a, b); + cpl_vector_add_scalar(a, 10); + cpl_vector_subtract_scalar(a, 10); + cpl_vector_multiply_scalar(a, 10); + cpl_vector_divide_scalar(a, 10); + cpl_vector_get_min(a); + cpl_vector_get_max(a); + cpl_vector_get_sum(a); + cpl_vector_get_mean(a); + cpl_vector_get_stdev(a); - tstop = cpl_test_get_cputime(); - cputime = tstop - tstart; - - cpl_msg_info(cpl_func, "valarray-test. n=%u. CPU-time [ms]: %g", - (unsigned)n, 1e3 * cputime); + tstop = cpl_test_get_cputime(); + cputime = tstop - tstart; + cpl_msg_info(cpl_func, "valarray-test. n=%u. CPU-time [ms]: %g", + (unsigned)n, 1e3 * cputime); } /*----------------------------------------------------------------------------*/ @@ -1290,11 +1296,11 @@ @return void */ /*----------------------------------------------------------------------------*/ -static void cpl_vector_valarray_bench(cpl_size n) +static void +cpl_vector_valarray_bench(cpl_size n) { - - cpl_vector * a = cpl_vector_new(n); - cpl_vector * b = cpl_vector_new(n); + cpl_vector *a = cpl_vector_new(n); + cpl_vector *b = cpl_vector_new(n); cpl_vector_fill(a, 10.0); cpl_vector_fill(b, 15.0); @@ -1306,7 +1312,6 @@ } - /*----------------------------------------------------------------------------*/ /** @brief Test the CPL function @@ -1314,16 +1319,16 @@ @return void */ /*----------------------------------------------------------------------------*/ -static void cpl_vector_cycle_test(cpl_size n) +static void +cpl_vector_cycle_test(cpl_size n) { - - const cpl_boolean do_plot = cpl_msg_get_level() <= CPL_MSG_INFO - ? CPL_TRUE : CPL_FALSE; - cpl_vector* src; - cpl_vector* dest; + const cpl_boolean do_plot = + cpl_msg_get_level() <= CPL_MSG_INFO ? CPL_TRUE : CPL_FALSE; + cpl_vector *src; + cpl_vector *dest; cpl_error_code code; - src = cpl_vector_new(n); + src = cpl_vector_new(n); dest = cpl_vector_new(n + 1); /* Shift something non-constant, so the correctness can be verified */ @@ -1342,7 +1347,7 @@ cpl_vector_delete(dest); dest = cpl_vector_new(n); - code = cpl_vector_cycle(dest, src, CPL_MATH_SQRT2 + (double)n/3.0); + code = cpl_vector_cycle(dest, src, CPL_MATH_SQRT2 + (double)n / 3.0); cpl_test_eq_error(code, CPL_ERROR_NONE); if (do_plot) { @@ -1350,12 +1355,13 @@ cpl_test_error(code); } - code = cpl_vector_cycle(dest, NULL, -CPL_MATH_SQRT2 - (double)n/3.0); + code = cpl_vector_cycle(dest, NULL, -CPL_MATH_SQRT2 - (double)n / 3.0); cpl_test_eq_error(code, CPL_ERROR_NONE); if (cpl_tools_is_power_of_2(n)) { cpl_test_vector_abs(dest, src, 0.5 / n); - } else { + } + else { cpl_test_vector_abs(dest, src, 10.0 * DBL_EPSILON); } @@ -1384,7 +1390,7 @@ cpl_test_eq_error(code, CPL_ERROR_NONE); if (n > 1) { - cpl_test_abs(cpl_vector_get(dest, n-1), cpl_vector_get(src, 0), 0.0); + cpl_test_abs(cpl_vector_get(dest, n - 1), cpl_vector_get(src, 0), 0.0); cpl_test_abs(cpl_vector_get(dest, 0), cpl_vector_get(src, 1), 0.0); } @@ -1396,11 +1402,11 @@ cpl_test_eq_error(code, CPL_ERROR_NONE); if (n > 2) { - cpl_test_abs(cpl_vector_get(dest, n-2), cpl_vector_get(src, 0), 0.0); + cpl_test_abs(cpl_vector_get(dest, n - 2), cpl_vector_get(src, 0), 0.0); cpl_test_abs(cpl_vector_get(dest, 0), cpl_vector_get(src, 2), 0.0); } - code = cpl_vector_cycle(dest, NULL, 2.0); + code = cpl_vector_cycle(dest, NULL, 2.0); cpl_test_eq_error(code, CPL_ERROR_NONE); cpl_test_vector_abs(dest, src, 0.0); @@ -1415,16 +1421,16 @@ - any linear combination of full sine and cosine curves will be cycled accurately... */ - for (cpl_size i=0; i < n; i++) { + for (cpl_size i = 0; i < n; i++) { const double value = sin(i * CPL_MATH_2PI / n); code = cpl_vector_set(src, i, value); cpl_test_eq_error(code, CPL_ERROR_NONE); } - code = cpl_vector_cycle(dest, src, CPL_MATH_E + (double)n/5.0); + code = cpl_vector_cycle(dest, src, CPL_MATH_E + (double)n / 5.0); cpl_test_eq_error(code, CPL_ERROR_NONE); - code = cpl_vector_cycle(dest, NULL, -CPL_MATH_E - (double)n/5.0); + code = cpl_vector_cycle(dest, NULL, -CPL_MATH_E - (double)n / 5.0); cpl_test_eq_error(code, CPL_ERROR_NONE); cpl_test_vector_abs(dest, src, 20.0 * DBL_EPSILON); @@ -1450,5 +1456,4 @@ cpl_vector_delete(src); cpl_vector_delete(dest); - } diff -Nru cpl-7.1.4+ds/cplcore/tests/Makefile.am cpl-7.2.2+ds/cplcore/tests/Makefile.am --- cpl-7.1.4+ds/cplcore/tests/Makefile.am 2021-05-07 12:09:06.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/tests/Makefile.am 2022-04-29 14:56:01.000000000 +0000 @@ -1,7 +1,7 @@ ## Process this file with automake to produce Makefile.in ## This file is part of the ESO Common Pipeline Library -## Copyright (C) 2001-2017 European Southern Observatory +## Copyright (C) 2001-2022 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 diff -Nru cpl-7.1.4+ds/cplcore/tests/Makefile.in cpl-7.2.2+ds/cplcore/tests/Makefile.in --- cpl-7.1.4+ds/cplcore/tests/Makefile.in 2021-05-07 12:10:10.000000000 +0000 +++ cpl-7.2.2+ds/cplcore/tests/Makefile.in 2022-04-29 14:56:28.000000000 +0000 @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.15.1 from Makefile.am. +# Makefile.in generated by automake 1.16.3 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2017 Free Software Foundation, Inc. +# Copyright (C) 1994-2020 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -324,7 +324,31 @@ am__v_at_1 = DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) depcomp = $(SHELL) $(top_srcdir)/admin/depcomp -am__depfiles_maybe = depfiles +am__maybe_remake_depfiles = depfiles +am__depfiles_remade = ./$(DEPDIR)/cpl_array-test.Po \ + ./$(DEPDIR)/cpl_bivector-test.Po ./$(DEPDIR)/cpl_error-test.Po \ + ./$(DEPDIR)/cpl_errorstate-test.Po \ + ./$(DEPDIR)/cpl_filter-test.Po ./$(DEPDIR)/cpl_fits-test.Po \ + ./$(DEPDIR)/cpl_image_basic-test.Po \ + ./$(DEPDIR)/cpl_image_bpm-test.Po \ + ./$(DEPDIR)/cpl_image_filter-test.Po \ + ./$(DEPDIR)/cpl_image_gen-test.Po \ + ./$(DEPDIR)/cpl_image_io-test.Po \ + ./$(DEPDIR)/cpl_image_iqe-test.Po \ + ./$(DEPDIR)/cpl_image_resample-test.Po \ + ./$(DEPDIR)/cpl_imagelist_basic-test.Po \ + ./$(DEPDIR)/cpl_imagelist_io-test.Po \ + ./$(DEPDIR)/cpl_io_fits-test.Po ./$(DEPDIR)/cpl_mask-test.Po \ + ./$(DEPDIR)/cpl_math-test.Po ./$(DEPDIR)/cpl_matrix-test.Po \ + ./$(DEPDIR)/cpl_median-test.Po ./$(DEPDIR)/cpl_memory-test.Po \ + ./$(DEPDIR)/cpl_msg-test.Po ./$(DEPDIR)/cpl_plot-test.Po \ + ./$(DEPDIR)/cpl_polynomial-test.Po \ + ./$(DEPDIR)/cpl_property-test.Po \ + ./$(DEPDIR)/cpl_propertylist-test.Po \ + ./$(DEPDIR)/cpl_stats-test.Po ./$(DEPDIR)/cpl_table-test.Po \ + ./$(DEPDIR)/cpl_test-test.Po ./$(DEPDIR)/cpl_test_init-test.Po \ + ./$(DEPDIR)/cpl_tools-test.Po ./$(DEPDIR)/cpl_type-test.Po \ + ./$(DEPDIR)/cpl_vector-test.Po am__mv = mv -f COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) @@ -586,6 +610,7 @@ bases='$(TEST_LOGS)'; \ bases=`for i in $$bases; do echo $$i; done | sed 's/\.log$$//'`; \ bases=`echo $$bases` +AM_TESTSUITE_SUMMARY_HEADER = ' for $(PACKAGE_STRING)' RECHECK_LOGS = $(TEST_LOGS) AM_RECURSIVE_TARGETS = check recheck TEST_SUITE_LOG = test-suite.log @@ -629,6 +654,7 @@ CPLCORE_INCLUDES = @CPLCORE_INCLUDES@ CPLDFS_INCLUDES = @CPLDFS_INCLUDES@ CPLDRS_INCLUDES = @CPLDRS_INCLUDES@ +CPLJAVA_INCLUDES = @CPLJAVA_INCLUDES@ CPLUI_INCLUDES = @CPLUI_INCLUDES@ CPL_BINARY_AGE = @CPL_BINARY_AGE@ CPL_BINARY_VERSION = @CPL_BINARY_VERSION@ @@ -689,6 +715,7 @@ LIBCPLCORE = @LIBCPLCORE@ LIBCPLDFS = @LIBCPLDFS@ LIBCPLDRS = @LIBCPLDRS@ +LIBCPLGASGANO = @LIBCPLGASGANO@ LIBCPLUI = @LIBCPLUI@ LIBFFTW = @LIBFFTW@ LIBFFTWF = @LIBFFTWF@ @@ -795,6 +822,7 @@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ @@ -875,8 +903,8 @@ *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);; \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ esac; $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) @@ -1035,39 +1063,45 @@ distclean-compile: -rm -f *.tab.c -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_array-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_bivector-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_error-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_errorstate-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_filter-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_fits-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_image_basic-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_image_bpm-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_image_filter-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_image_gen-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_image_io-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_image_iqe-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_image_resample-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_imagelist_basic-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_imagelist_io-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_io_fits-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_mask-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_math-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_matrix-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_median-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_memory-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_msg-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_plot-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_polynomial-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_property-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_propertylist-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_stats-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_table-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_test-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_test_init-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_tools-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_type-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_vector-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_array-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_bivector-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_error-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_errorstate-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_filter-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_fits-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_image_basic-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_image_bpm-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_image_filter-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_image_gen-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_image_io-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_image_iqe-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_image_resample-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_imagelist_basic-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_imagelist_io-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_io_fits-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_mask-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_math-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_matrix-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_median-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_memory-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_msg-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_plot-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_polynomial-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_property-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_propertylist-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_stats-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_table-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_test-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_test_init-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_tools-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_type-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_vector-test.Po@am__quote@ # am--include-marker + +$(am__depfiles_remade): + @$(MKDIR_P) $(@D) + @echo '# dummy' >$@-t && $(am__mv) $@-t $@ + +am--depfiles: $(am__depfiles_remade) .c.o: @am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @@ -1255,7 +1289,7 @@ test x"$$VERBOSE" = x || cat $(TEST_SUITE_LOG); \ fi; \ echo "$${col}$$br$${std}"; \ - echo "$${col}Testsuite summary for $(PACKAGE_STRING)$${std}"; \ + echo "$${col}Testsuite summary"$(AM_TESTSUITE_SUMMARY_HEADER)"$${std}"; \ echo "$${col}$$br$${std}"; \ create_testsuite_report --maybe-color; \ echo "$$col$$br$$std"; \ @@ -1268,7 +1302,7 @@ fi; \ $$success || exit 1 -check-TESTS: +check-TESTS: $(check_PROGRAMS) @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) @@ -1535,7 +1569,10 @@ @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) +distdir: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) distdir-am + +distdir-am: $(DISTFILES) @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ list='$(DISTFILES)'; \ @@ -1612,7 +1649,39 @@ mostlyclean-am distclean: distclean-am - -rm -rf ./$(DEPDIR) + -rm -f ./$(DEPDIR)/cpl_array-test.Po + -rm -f ./$(DEPDIR)/cpl_bivector-test.Po + -rm -f ./$(DEPDIR)/cpl_error-test.Po + -rm -f ./$(DEPDIR)/cpl_errorstate-test.Po + -rm -f ./$(DEPDIR)/cpl_filter-test.Po + -rm -f ./$(DEPDIR)/cpl_fits-test.Po + -rm -f ./$(DEPDIR)/cpl_image_basic-test.Po + -rm -f ./$(DEPDIR)/cpl_image_bpm-test.Po + -rm -f ./$(DEPDIR)/cpl_image_filter-test.Po + -rm -f ./$(DEPDIR)/cpl_image_gen-test.Po + -rm -f ./$(DEPDIR)/cpl_image_io-test.Po + -rm -f ./$(DEPDIR)/cpl_image_iqe-test.Po + -rm -f ./$(DEPDIR)/cpl_image_resample-test.Po + -rm -f ./$(DEPDIR)/cpl_imagelist_basic-test.Po + -rm -f ./$(DEPDIR)/cpl_imagelist_io-test.Po + -rm -f ./$(DEPDIR)/cpl_io_fits-test.Po + -rm -f ./$(DEPDIR)/cpl_mask-test.Po + -rm -f ./$(DEPDIR)/cpl_math-test.Po + -rm -f ./$(DEPDIR)/cpl_matrix-test.Po + -rm -f ./$(DEPDIR)/cpl_median-test.Po + -rm -f ./$(DEPDIR)/cpl_memory-test.Po + -rm -f ./$(DEPDIR)/cpl_msg-test.Po + -rm -f ./$(DEPDIR)/cpl_plot-test.Po + -rm -f ./$(DEPDIR)/cpl_polynomial-test.Po + -rm -f ./$(DEPDIR)/cpl_property-test.Po + -rm -f ./$(DEPDIR)/cpl_propertylist-test.Po + -rm -f ./$(DEPDIR)/cpl_stats-test.Po + -rm -f ./$(DEPDIR)/cpl_table-test.Po + -rm -f ./$(DEPDIR)/cpl_test-test.Po + -rm -f ./$(DEPDIR)/cpl_test_init-test.Po + -rm -f ./$(DEPDIR)/cpl_tools-test.Po + -rm -f ./$(DEPDIR)/cpl_type-test.Po + -rm -f ./$(DEPDIR)/cpl_vector-test.Po -rm -f Makefile distclean-am: clean-am distclean-compile distclean-generic \ distclean-tags @@ -1658,7 +1727,39 @@ installcheck-am: maintainer-clean: maintainer-clean-am - -rm -rf ./$(DEPDIR) + -rm -f ./$(DEPDIR)/cpl_array-test.Po + -rm -f ./$(DEPDIR)/cpl_bivector-test.Po + -rm -f ./$(DEPDIR)/cpl_error-test.Po + -rm -f ./$(DEPDIR)/cpl_errorstate-test.Po + -rm -f ./$(DEPDIR)/cpl_filter-test.Po + -rm -f ./$(DEPDIR)/cpl_fits-test.Po + -rm -f ./$(DEPDIR)/cpl_image_basic-test.Po + -rm -f ./$(DEPDIR)/cpl_image_bpm-test.Po + -rm -f ./$(DEPDIR)/cpl_image_filter-test.Po + -rm -f ./$(DEPDIR)/cpl_image_gen-test.Po + -rm -f ./$(DEPDIR)/cpl_image_io-test.Po + -rm -f ./$(DEPDIR)/cpl_image_iqe-test.Po + -rm -f ./$(DEPDIR)/cpl_image_resample-test.Po + -rm -f ./$(DEPDIR)/cpl_imagelist_basic-test.Po + -rm -f ./$(DEPDIR)/cpl_imagelist_io-test.Po + -rm -f ./$(DEPDIR)/cpl_io_fits-test.Po + -rm -f ./$(DEPDIR)/cpl_mask-test.Po + -rm -f ./$(DEPDIR)/cpl_math-test.Po + -rm -f ./$(DEPDIR)/cpl_matrix-test.Po + -rm -f ./$(DEPDIR)/cpl_median-test.Po + -rm -f ./$(DEPDIR)/cpl_memory-test.Po + -rm -f ./$(DEPDIR)/cpl_msg-test.Po + -rm -f ./$(DEPDIR)/cpl_plot-test.Po + -rm -f ./$(DEPDIR)/cpl_polynomial-test.Po + -rm -f ./$(DEPDIR)/cpl_property-test.Po + -rm -f ./$(DEPDIR)/cpl_propertylist-test.Po + -rm -f ./$(DEPDIR)/cpl_stats-test.Po + -rm -f ./$(DEPDIR)/cpl_table-test.Po + -rm -f ./$(DEPDIR)/cpl_test-test.Po + -rm -f ./$(DEPDIR)/cpl_test_init-test.Po + -rm -f ./$(DEPDIR)/cpl_tools-test.Po + -rm -f ./$(DEPDIR)/cpl_type-test.Po + -rm -f ./$(DEPDIR)/cpl_vector-test.Po -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic @@ -1679,19 +1780,20 @@ .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 +.PHONY: CTAGS GTAGS TAGS all all-am am--depfiles 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 diff -Nru cpl-7.1.4+ds/cpldfs/cpl_dfs.c cpl-7.2.2+ds/cpldfs/cpl_dfs.c --- cpl-7.1.4+ds/cpldfs/cpl_dfs.c 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cpldfs/cpl_dfs.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -18,7 +18,7 @@ */ #ifdef HAVE_CONFIG_H -# include +#include #endif /*----------------------------------------------------------------------------- @@ -55,37 +55,37 @@ * Product keywords aliases */ -#define DATE "DATE" -#define DATAMD5 "DATAMD5" -#define ARCFILE "ARCFILE" -#define PIPEFILE "PIPEFILE" -#define CHECKSUM "CHECKSUM" -#define DATASUM "DATASUM" -#define PRO_DID "ESO PRO DID" -#define DPR_CATG "ESO DPR CATG" -#define PRO_CATG CPL_DFS_PRO_CATG -#define PRO_TYPE CPL_DFS_PRO_TYPE -#define DPR_TECH "ESO DPR TECH" -#define PRO_TECH CPL_DFS_PRO_TECH -#define PRO_SCIENCE CPL_DFS_PRO_SCIENCE -#define PRO_ANCESTOR "ESO PRO ANCESTOR" -#define PRO_DATE "ESO PRO DATE" -#define PRO_DATANCOM "ESO PRO DATANCOM" -#define PRO_RECi_ID "ESO PRO REC%d ID" -#define PRO_RECi_DRS_ID "ESO PRO REC%d DRS ID" -#define PRO_RECi_PIPE_ID "ESO PRO REC%d PIPE ID" -#define PRO_RECi_RAWi_NAME "ESO PRO REC%d RAW%d NAME" -#define PRO_RECi_RAWi_CATG "ESO PRO REC%d RAW%d CATG" -#define PRO_RECi_CALi_NAME "ESO PRO REC%d CAL%d NAME" -#define PRO_RECi_CALi_CATG "ESO PRO REC%d CAL%d CATG" -#define PRO_RECi_CALi_DATAMD5 "ESO PRO REC%d CAL%d " DATAMD5 -#define PRO_RECi_PARAMi_NAME "ESO PRO REC%d PARAM%d NAME" -#define PRO_RECi_PARAMi_VALUE "ESO PRO REC%d PARAM%d VALUE" +#define DATE "DATE" +#define DATAMD5 "DATAMD5" +#define ARCFILE "ARCFILE" +#define PIPEFILE "PIPEFILE" +#define CHECKSUM "CHECKSUM" +#define DATASUM "DATASUM" +#define PRO_DID "ESO PRO DID" +#define DPR_CATG "ESO DPR CATG" +#define PRO_CATG CPL_DFS_PRO_CATG +#define PRO_TYPE CPL_DFS_PRO_TYPE +#define DPR_TECH "ESO DPR TECH" +#define PRO_TECH CPL_DFS_PRO_TECH +#define PRO_SCIENCE CPL_DFS_PRO_SCIENCE +#define PRO_ANCESTOR "ESO PRO ANCESTOR" +#define PRO_DATE "ESO PRO DATE" +#define PRO_DATANCOM "ESO PRO DATANCOM" +#define PRO_RECi_ID "ESO PRO REC%d ID" +#define PRO_RECi_DRS_ID "ESO PRO REC%d DRS ID" +#define PRO_RECi_PIPE_ID "ESO PRO REC%d PIPE ID" +#define PRO_RECi_RAWi_NAME "ESO PRO REC%d RAW%d NAME" +#define PRO_RECi_RAWi_CATG "ESO PRO REC%d RAW%d CATG" +#define PRO_RECi_CALi_NAME "ESO PRO REC%d CAL%d NAME" +#define PRO_RECi_CALi_CATG "ESO PRO REC%d CAL%d CATG" +#define PRO_RECi_CALi_DATAMD5 "ESO PRO REC%d CAL%d " DATAMD5 +#define PRO_RECi_PARAMi_NAME "ESO PRO REC%d PARAM%d NAME" +#define PRO_RECi_PARAMi_VALUE "ESO PRO REC%d PARAM%d VALUE" #define MAX_PLENGTH (64) /* Size of a 128-bit MD5 hash in bytes */ -#define MD5HASHSZ 32 +#define MD5HASHSZ 32 /* Use at least this many places when printing the PAF key */ #define PAF_KEY_LEN 21 @@ -123,34 +123,31 @@ #if defined CFITSIO_MAJOR && (CFITSIO_MAJOR > 3 || CFITSIO_MINOR >= 26) /* Not needed from 3.26 */ #else -static char * cpl_dfs_extract_printable(const char *) CPL_ATTR_ALLOC; +static char *cpl_dfs_extract_printable(const char *) CPL_ATTR_ALLOC; #endif -inline static cpl_error_code _cpl_dfs_sign_product(const cpl_frame *frame, - cxuint flags); +inline static cpl_error_code +_cpl_dfs_sign_product(const cpl_frame *frame, cxuint flags); static cpl_error_code cpl_dfs_update_product_header_(cpl_frameset *); -static cpl_error_code cpl_dfs_find_md5sum(char *, fitsfile *) - CPL_ATTR_NONNULL; +static cpl_error_code cpl_dfs_find_md5sum(char *, fitsfile *) CPL_ATTR_NONNULL; static int cpl_is_fits(const char *); -static -const char *cpl_get_base_name(const char *) CPL_ATTR_PURE; +static const char *cpl_get_base_name(const char *) CPL_ATTR_PURE; -static FILE * cpl_dfs_paf_init(const char *, const char *, const char *); +static FILE *cpl_dfs_paf_init(const char *, const char *, const char *); static cpl_error_code cpl_dfs_paf_dump(const cpl_propertylist *, FILE *); -static -cpl_error_code cpl_dfs_paf_dump_string(const char *, const char *, - const char *, FILE *); +static cpl_error_code +cpl_dfs_paf_dump_string(const char *, const char *, const char *, FILE *); -static cpl_error_code cpl_dfs_paf_dump_double(const char *, double, - const char *, FILE *); +static cpl_error_code +cpl_dfs_paf_dump_double(const char *, double, const char *, FILE *); -static cpl_error_code cpl_dfs_paf_dump_int(const char *, cpl_size, - const char *, FILE *); +static cpl_error_code +cpl_dfs_paf_dump_int(const char *, cpl_size, const char *, FILE *); static cpl_error_code cpl_dfs_product_save(cpl_frameset *, cpl_propertylist *, @@ -204,24 +201,25 @@ */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_dfs_save_image(cpl_frameset * allframes, - cpl_propertylist * header, - const cpl_parameterlist * parlist, - const cpl_frameset * usedframes, - const cpl_frame * inherit, - const cpl_image * image, - cpl_type type, - const char * recipe, - const cpl_propertylist * applist, - const char * remregexp, - const char * pipe_id, - const char * filename) +cpl_error_code +cpl_dfs_save_image(cpl_frameset *allframes, + cpl_propertylist *header, + const cpl_parameterlist *parlist, + const cpl_frameset *usedframes, + const cpl_frame *inherit, + const cpl_image *image, + cpl_type type, + const char *recipe, + const cpl_propertylist *applist, + const char *remregexp, + const char *pipe_id, + const char *filename) { return cpl_dfs_product_save(allframes, header, parlist, usedframes, inherit, NULL, image, type, NULL, NULL, recipe, applist, remregexp, pipe_id, filename) - ? cpl_error_set_where_() : CPL_ERROR_NONE; - + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -250,22 +248,24 @@ */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_dfs_save_propertylist(cpl_frameset * allframes, - cpl_propertylist * header, - const cpl_parameterlist * parlist, - const cpl_frameset * usedframes, - const cpl_frame * inherit, - const char * recipe, - const cpl_propertylist * applist, - const char * remregexp, - const char * pipe_id, - const char * filename) +cpl_error_code +cpl_dfs_save_propertylist(cpl_frameset *allframes, + cpl_propertylist *header, + const cpl_parameterlist *parlist, + const cpl_frameset *usedframes, + const cpl_frame *inherit, + const char *recipe, + const cpl_propertylist *applist, + const char *remregexp, + const char *pipe_id, + const char *filename) { /* Use CPL_TYPE_INVALID to ensure it is not referenced */ return cpl_dfs_product_save(allframes, header, parlist, usedframes, inherit, NULL, NULL, CPL_TYPE_INVALID, NULL, NULL, recipe, applist, remregexp, pipe_id, filename) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } /*----------------------------------------------------------------------------*/ @@ -289,25 +289,27 @@ */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_dfs_save_imagelist(cpl_frameset * allframes, - cpl_propertylist * header, - const cpl_parameterlist * parlist, - const cpl_frameset * usedframes, - const cpl_frame * inherit, - const cpl_imagelist * imagelist, - cpl_type type, - const char * recipe, - const cpl_propertylist * applist, - const char * remregexp, - const char * pipe_id, - const char * filename) +cpl_error_code +cpl_dfs_save_imagelist(cpl_frameset *allframes, + cpl_propertylist *header, + const cpl_parameterlist *parlist, + const cpl_frameset *usedframes, + const cpl_frame *inherit, + const cpl_imagelist *imagelist, + cpl_type type, + const char *recipe, + const cpl_propertylist *applist, + const char *remregexp, + const char *pipe_id, + const char *filename) { cpl_ensure_code(imagelist != NULL, CPL_ERROR_NULL_INPUT); - return cpl_dfs_product_save(allframes, header, parlist, usedframes, - inherit, imagelist, NULL, type, NULL, NULL, - recipe, applist, remregexp, pipe_id, filename) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + return cpl_dfs_product_save(allframes, header, parlist, usedframes, inherit, + imagelist, NULL, type, NULL, NULL, recipe, + applist, remregexp, pipe_id, filename) + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -331,27 +333,28 @@ */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_dfs_save_table(cpl_frameset * allframes, - cpl_propertylist * header, - const cpl_parameterlist * parlist, - const cpl_frameset * usedframes, - const cpl_frame * inherit, - const cpl_table * table, - const cpl_propertylist * tablelist, - const char * recipe, - const cpl_propertylist * applist, - const char * remregexp, - const char * pipe_id, - const char * filename) +cpl_error_code +cpl_dfs_save_table(cpl_frameset *allframes, + cpl_propertylist *header, + const cpl_parameterlist *parlist, + const cpl_frameset *usedframes, + const cpl_frame *inherit, + const cpl_table *table, + const cpl_propertylist *tablelist, + const char *recipe, + const cpl_propertylist *applist, + const char *remregexp, + const char *pipe_id, + const char *filename) { - cpl_ensure_code(table != NULL, CPL_ERROR_NULL_INPUT); /* Use CPL_TYPE_INVALID to ensure it is not referenced */ return cpl_dfs_product_save(allframes, header, parlist, usedframes, inherit, NULL, NULL, CPL_TYPE_INVALID, table, tablelist, recipe, applist, remregexp, pipe_id, filename) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -386,19 +389,20 @@ */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_dfs_save_paf(const char * instrume, const char *recipe, - const cpl_propertylist * paflist, - const char * filename) +cpl_error_code +cpl_dfs_save_paf(const char *instrume, + const char *recipe, + const cpl_propertylist *paflist, + const char *filename) { - - FILE * paf; + FILE *paf; cpl_error_code status; - cpl_ensure_code(instrume != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(recipe != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(paflist != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(filename != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(instrume != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(recipe != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(paflist != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(filename != NULL, CPL_ERROR_NULL_INPUT); paf = cpl_dfs_paf_init(instrume, recipe, filename); @@ -411,12 +415,12 @@ if (status == CPL_ERROR_NONE) { cpl_ensure_code(fclose(paf) == 0, CPL_ERROR_FILE_IO); - } else { + } + else { (void)fclose(paf); } return status; - } @@ -495,7 +499,7 @@ * -# Copy to @em header, if they are present, the following primary * FITS keywords from the first input frame in the @em framelist: * ORIGIN, TELESCOPE, INSTRUME, OBJECT, RA, DEC, EPOCH, EQUINOX, - * RADECSYS, DATE-OBS, MJD-OBS, UTC, LST, PI-COI, OBSERVER. If those + * RADESYS, DATE-OBS, MJD-OBS, UTC, LST, PI-COI, OBSERVER. If those * keywords are already present in the @em header property list, they * are overwritten only in case they have the same type. If any of * these keywords are present with an unexpected type, a warning is @@ -544,32 +548,31 @@ * Non-FITS files are handled as files with an empty FITS header. */ -cpl_error_code cpl_dfs_setup_product_header(cpl_propertylist *header, - const cpl_frame *product_frame, - const cpl_frameset *framelist, - const cpl_parameterlist *parlist, - const char *recid, - const char *pipeline_id, - const char *dictionary_id, - const cpl_frame *inherit_frame) +cpl_error_code +cpl_dfs_setup_product_header(cpl_propertylist *header, + const cpl_frame *product_frame, + const cpl_frameset *framelist, + const cpl_parameterlist *parlist, + const char *recid, + const char *pipeline_id, + const char *dictionary_id, + const cpl_frame *inherit_frame) { - - char cval[FLEN_VALUE]; - const char *datamd5; - const cpl_frame *frame; - const cpl_frame *first_frame = NULL; + char ckey[FLEN_KEYWORD]; + const cpl_frame *frame; + const cpl_frame *first_frame = NULL; cpl_frameset_iterator *it = NULL; cpl_propertylist *plist; const cpl_parameter *param; - int keylen; - int level = 0; - int empty = 0; - int nraw; - int ncal; - int npar; - int i; + cpl_property *propupd; + int keylen; + int level = 0; + int nraw; + int ncal; + int npar; + int i; - const char *kname; + const char *kname; /* @@ -577,79 +580,84 @@ * second in output _image_ header: */ - typedef struct { + typedef struct + { const cpl_cstr *key; cpl_type type; } klist; - klist mandatory[] = {{CXSTR("ORIGIN", 6), CPL_TYPE_STRING}, - {CXSTR("TELESCOP", 8), CPL_TYPE_STRING}, - {CXSTR("INSTRUME", 8), CPL_TYPE_STRING}, - {CXSTR("OBJECT", 6), CPL_TYPE_STRING}, - {CXSTR("RA", 2), CPL_TYPE_DOUBLE}, - {CXSTR("DEC", 3), CPL_TYPE_DOUBLE}, - {CXSTR("EPOCH", 5), CPL_TYPE_STRING}, - {CXSTR("EQUINOX", 7), CPL_TYPE_DOUBLE}, - {CXSTR("RADECSYS", 8), CPL_TYPE_STRING}, - {CXSTR("DATE-OBS", 8), CPL_TYPE_STRING}, - {CXSTR("MJD-OBS", 7), CPL_TYPE_DOUBLE}, - {CXSTR("UTC", 3), CPL_TYPE_DOUBLE}, - {CXSTR("LST", 3), CPL_TYPE_DOUBLE}, - {CXSTR("PI-COI", 6), CPL_TYPE_STRING}, - {CXSTR("OBSERVER", 8), CPL_TYPE_STRING}}; + klist mandatory[] = { { CXSTR("ORIGIN", 6), CPL_TYPE_STRING }, + { CXSTR("TELESCOP", 8), CPL_TYPE_STRING }, + { CXSTR("INSTRUME", 8), CPL_TYPE_STRING }, + { CXSTR("OBJECT", 6), CPL_TYPE_STRING }, + { CXSTR("RA", 2), CPL_TYPE_DOUBLE }, + { CXSTR("DEC", 3), CPL_TYPE_DOUBLE }, + { CXSTR("EPOCH", 5), CPL_TYPE_STRING }, + { CXSTR("EQUINOX", 7), CPL_TYPE_DOUBLE }, + { CXSTR("RADESYS", 7), CPL_TYPE_STRING }, + { CXSTR("DATE-OBS", 8), CPL_TYPE_STRING }, + { CXSTR("MJD-OBS", 7), CPL_TYPE_DOUBLE }, + { CXSTR("UTC", 3), CPL_TYPE_DOUBLE }, + { CXSTR("LST", 3), CPL_TYPE_DOUBLE }, + { CXSTR("PI-COI", 6), CPL_TYPE_STRING }, + { CXSTR("OBSERVER", 8), CPL_TYPE_STRING } }; const int count_mandatory = (int)CX_N_ELEMENTS(mandatory); - /* Here are the mandatory keys again + ARCFILE - - without their associated type */ - - const cpl_cstr * exactkeys[] = {CXSTR("ORIGIN", 6), - CXSTR("TELESCOP", 8), - CXSTR("INSTRUME", 8), - CXSTR("OBJECT", 6), - CXSTR("RA", 2), - CXSTR("DEC", 3), - CXSTR("EPOCH", 5), - CXSTR("EQUINOX", 7), - CXSTR("RADECSYS", 8), - CXSTR("DATE-OBS", 8), - CXSTR("MJD-OBS", 7), - CXSTR("UTC", 3), - CXSTR("LST", 3), - CXSTR("PI-COI", 6), - CXSTR("OBSERVER", 8), - CXSTR("ARCFILE", 7)}; - - /* The same list, will use a counter one less */ - const cpl_cstr ** mandatorykeys = exactkeys; - - /* ESO HIERACH keys are also to be loaded */ - const cpl_cstr * esokeys[] = {CXSTR("ESO ", 4)}; + /* + * These are the mandatory keys to be loaded from the reference frames. + * Included are ARCFILE and RADECSYS to make sure they are loaded and + * available for internal processing here. + */ - const int nesokeys = (int)CX_N_ELEMENTS(esokeys); + const cpl_cstr *exactkeys[] = { + CXSTR("ORIGIN", 6), CXSTR("TELESCOP", 8), CXSTR("INSTRUME", 8), + CXSTR("OBJECT", 6), CXSTR("RA", 2), CXSTR("DEC", 3), + CXSTR("EPOCH", 5), CXSTR("EQUINOX", 7), CXSTR("RADESYS", 7), + CXSTR("DATE-OBS", 8), CXSTR("MJD-OBS", 7), CXSTR("UTC", 3), + CXSTR("LST", 3), CXSTR("PI-COI", 6), CXSTR("OBSERVER", 8), + CXSTR("RADECSYS", 8), CXSTR("ARCFILE", 7) + }; + + const cpl_cstr *copykeys[] = { CXSTR("ESO PRO REC", 11) }; + const cpl_cstr *avoidkeys[] = { CXSTR("ESO DPR ", 8), CXSTR("ESO DRS ", 8), + CXSTR("ESO PRO ", 8), CXSTR("ESO QC ", 7) }; + + const cpl_cstr *erasekeys1[] = { CXSTR("ESO DPR ", 8) }; + const cpl_cstr *erasekeys2[] = { CXSTR("ARCFILE", 7), CXSTR("ORIGFILE", 8), + CXSTR("CHECKSUM", 8), CXSTR("DATASUM", 7), + CXSTR("HDRVER", 6) }; + + /* The same list, except the last two elements are not used */ + const cpl_cstr **mandatorykeys = exactkeys; + + /* ESO HIERARCH keys are also to be loaded */ + const cpl_cstr *esokeys[] = { CXSTR("ESO ", 4) }; + + const int ncopykeys = (int)CX_N_ELEMENTS(copykeys); + const int navoidkeys = (int)CX_N_ELEMENTS(avoidkeys); + const int nesokeys = (int)CX_N_ELEMENTS(esokeys); const int nexactkeys = (int)CX_N_ELEMENTS(exactkeys); - const int nmandatorykeys = nexactkeys - 1; - - int pro_science = 0; - + const int nerasekeys1 = (int)CX_N_ELEMENTS(erasekeys1); + const int nerasekeys2 = (int)CX_N_ELEMENTS(erasekeys2); + const int nmandatorykeys = nexactkeys - 2; assert(count_mandatory == nmandatorykeys); - assert(nexactkeys == nmandatorykeys + 1); - assert(nesokeys == 1); + assert(nexactkeys == nmandatorykeys + 2); + assert(nesokeys == 1); - cpl_ensure_code(header != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(header != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(product_frame != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(framelist != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(recid != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(framelist != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(recid != NULL, CPL_ERROR_NULL_INPUT); /* * Forbidden keywords are removed from product header. */ - cpl_propertylist_erase_regexp(header, - "^ESO DPR |^ARCFILE$|^ORIGFILE$|" - "^CHECKSUM$|^DATASUM$", 0); + cpl_propertylist_erase_name_(header, nerasekeys1, erasekeys1, nerasekeys2, + erasekeys2, 0); /* * Get the first input frame in the input set-of-frames. @@ -659,8 +667,7 @@ frame = cpl_frameset_iterator_get_const(it); while (frame != NULL) { - - cpl_errorstate status; + cpl_errorstate status; if (cpl_frame_get_group(frame) == CPL_FRAME_GROUP_RAW) { first_frame = frame; @@ -672,23 +679,20 @@ cpl_frameset_iterator_advance(it, 1); if (cpl_error_get_code() == CPL_ERROR_ACCESS_OUT_OF_RANGE) { - cpl_errorstate_set(status); + cpl_errorstate_set(status); } frame = cpl_frameset_iterator_get_const(it); - } if (first_frame == NULL) { - - cpl_frameset_iterator_reset(it); + cpl_frameset_iterator_reset(it); frame = cpl_frameset_iterator_get_const(it); while (frame != NULL) { + cpl_errorstate status; - cpl_errorstate status; - - if (cpl_frame_get_group(frame) == CPL_FRAME_GROUP_CALIB) { + if (cpl_frame_get_group(frame) == CPL_FRAME_GROUP_CALIB) { first_frame = frame; break; } @@ -698,20 +702,19 @@ cpl_frameset_iterator_advance(it, 1); if (cpl_error_get_code() == CPL_ERROR_ACCESS_OUT_OF_RANGE) { - cpl_errorstate_set(status); + cpl_errorstate_set(status); } frame = cpl_frameset_iterator_get_const(it); - } } - cpl_frameset_iterator_delete(it); - it = NULL; + cpl_frameset_iterator_delete(it); + it = NULL; if (first_frame == NULL) { return cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, - "Empty set-of-frames"); + "Empty set-of-frames"); } if (inherit_frame) { @@ -726,23 +729,22 @@ frame = cpl_frameset_iterator_get_const(it); while (frame != NULL) { - - cpl_errorstate status; + cpl_errorstate status; iframe++; if (cpl_frame_get_filename(frame) == NULL) { + cpl_frameset_iterator_delete(it); - cpl_frameset_iterator_delete(it); - - return cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, "Frame " - "%d/%d has no filename", iframe, - (int)cpl_frameset_get_size - (framelist)); - + return cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, + "Frame " + "%d/%d has no filename", + iframe, + (int)cpl_frameset_get_size( + framelist)); } - if (strcmp(cpl_frame_get_filename(frame), + if (strcmp(cpl_frame_get_filename(frame), cpl_frame_get_filename(inherit_frame)) == 0) { break; } @@ -752,11 +754,10 @@ cpl_frameset_iterator_advance(it, 1); if (cpl_error_get_code() == CPL_ERROR_ACCESS_OUT_OF_RANGE) { - cpl_errorstate_set(status); + cpl_errorstate_set(status); } frame = cpl_frameset_iterator_get_const(it); - } cpl_frameset_iterator_delete(it); @@ -764,24 +765,26 @@ if (frame != NULL) { switch (cpl_is_fits(cpl_frame_get_filename(inherit_frame))) { - case 0: - return cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, - "Cannot inherit information from non-FITS file"); - case 1: - break; - default: - return cpl_error_set_(CPL_ERROR_FILE_NOT_FOUND); + case 0: + return cpl_error_set_message_( + CPL_ERROR_ILLEGAL_INPUT, + "Cannot inherit information from non-FITS file"); + case 1: + break; + default: + return cpl_error_set_(CPL_ERROR_FILE_NOT_FOUND); } } else { return cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, - "The reference frame does not belong to the input set-of-frames"); + "The reference frame does not belong " + "to the input set-of-frames"); } } else { inherit_frame = first_frame; } - + /* * Now copy all the required entries, if present, from input to @@ -789,59 +792,104 @@ */ switch (cpl_is_fits(cpl_frame_get_filename(first_frame))) { - case 0: - plist = cpl_propertylist_new(); - break; - case 1: - /* Load only the mandatory keywords and the HIERACH ESO keywords */ - if (first_frame == inherit_frame) { - plist = cpl_propertylist_load_name_( - cpl_frame_get_filename(first_frame), 0, - nesokeys, esokeys, - nexactkeys, exactkeys, 0); - - cpl_ensure_code(plist != NULL, cpl_error_get_code()); - } - else { - cpl_propertylist *plist2; - const cpl_cstr * exactkey[] = {CXSTR("ARCFILE", 7)}; + case 0: + plist = cpl_propertylist_new(); + break; + case 1: + /* Load only the mandatory keywords and the HIERARCH ESO keywords */ + if (first_frame == inherit_frame) { + plist = cpl_propertylist_load_name_(cpl_frame_get_filename( + first_frame), + 0, nesokeys, esokeys, + nexactkeys, exactkeys, 0); - plist = cpl_propertylist_load_name_( - cpl_frame_get_filename(first_frame), 0, - nmandatorykeys, mandatorykeys, 0, NULL, 0); - cpl_ensure_code(plist != NULL, cpl_error_get_code()); - plist2 = cpl_propertylist_load_name_( - cpl_frame_get_filename(inherit_frame), 0, - nesokeys, esokeys, 1, exactkey, 0); - cpl_ensure_code(plist2 != NULL, cpl_error_get_code()); - if (cpl_propertylist_copy_property_regexp(plist, plist2, - "^ESO|^ARCFILE$", 0)) { + cpl_ensure_code(plist != NULL, cpl_error_get_code()); + } + else { + cpl_propertylist *plist2; + const cpl_cstr *exactkey[] = { CXSTR("ARCFILE", 7) }; + const int nkeys = (int)CX_N_ELEMENTS(exactkey); + cpl_error_code code; + + plist = cpl_propertylist_load_name_(cpl_frame_get_filename( + first_frame), + 0, nmandatorykeys, + mandatorykeys, 0, NULL, 0); + cpl_ensure_code(plist != NULL, cpl_error_get_code()); + plist2 = cpl_propertylist_load_name_(cpl_frame_get_filename( + inherit_frame), + 0, nesokeys, esokeys, + nkeys, exactkey, 0); + cpl_ensure_code(plist2 != NULL, cpl_error_get_code()); + code = cpl_propertylist_append(plist, plist2); cpl_propertylist_delete(plist2); - return cpl_error_set_where_(); + cpl_ensure_code(!code, code); } - cpl_propertylist_delete(plist2); + break; + default: + return cpl_error_get_code() == CPL_ERROR_NULL_INPUT + ? cpl_error_set_(CPL_ERROR_DATA_NOT_FOUND) + : cpl_error_set_where_(); + } + + + /* + * Handle the deprecated RADECSYS keyword. RADECSYS has been replaced + * by RADESYS but in order to be backwards compatible the following + * scheme is adopted: + * + * Both keyword names are loaded when the list of mandatory keywords is + * loaded in the previous code section. + * + * If RADECSYS is present and RADESYS is not, RADECSYS is renamed to + * RADESYS. If RADECSYS is not present but RADESYS is already there + * nothing needs to be done. + * + * If both keywords are there it is assumed that RADESYS contains the + * correct information. In this case, following the DICB policy, the + * keyword RADECSYS is dropped and only RADESYS is copied to the product + * header. + */ + + if (cpl_propertylist_has(plist, "RADECSYS")) { + if (!cpl_propertylist_has(plist, "RADESYS")) { + const cpl_property *_property = + cpl_propertylist_get_property_const(plist, "RADECSYS"); + cpl_property *property = cpl_property_duplicate(_property); + cpl_property_set_name(property, "RADESYS"); + cpl_propertylist_append_property(plist, property); + cpl_property_delete(property); } - break; - default: - return cpl_error_get_code() == CPL_ERROR_NULL_INPUT - ? cpl_error_set_(CPL_ERROR_DATA_NOT_FOUND) : cpl_error_set_where_(); + cpl_propertylist_erase(plist, "RADECSYS"); } + for (i = 0; i < count_mandatory; i++) { - if (cpl_propertylist_has_cx(plist, mandatory[i].key)) { - if (cpl_propertylist_get_type_cx(plist, mandatory[i].key) != - mandatory[i].type) { - cpl_msg_warning(cpl_func, "Unexpected type for keyword %s in " - "input header", mandatory[i].key->data); - } - if (cpl_propertylist_has_cx(header, mandatory[i].key)) { - if (cpl_propertylist_get_type_cx(header, mandatory[i].key) != - mandatory[i].type) { - cpl_msg_warning(cpl_func, "Unexpected type for keyword %s " - "in output header", mandatory[i].key->data); + const cpl_property *propin = + cpl_propertylist_get_const_cx(plist, mandatory[i].key); + if (propin != NULL) { + const cpl_property *propout = + cpl_propertylist_get_const_cx(header, mandatory[i].key); + const cpl_type intype = cpl_property_get_type(propin); + + if (intype != mandatory[i].type) { + cpl_msg_warning(cpl_func, + "Unexpected type for keyword %s in " + "input header: %s", + mandatory[i].key->data, + cpl_type_get_name(intype)); + } + if (propout != NULL) { + const cpl_type outtype = cpl_property_get_type(propout); + + if (outtype != mandatory[i].type) { + cpl_msg_warning(cpl_func, + "Unexpected type for keyword %s " + "in output header: %s", + mandatory[i].key->data, + cpl_type_get_name(outtype)); } - if (cpl_propertylist_get_type_cx(plist, mandatory[i].key) != - cpl_propertylist_get_type_cx(header, mandatory[i].key)) { + if (intype != outtype) { /* Do not copy this keyword */ cpl_propertylist_erase_cx(plist, mandatory[i].key); } @@ -855,12 +903,10 @@ * the next free slot in the product processing history. */ - while (!empty) { - ++level; - - keylen = snprintf(cval, FLEN_VALUE, PRO_RECi_ID, level); - empty = !cpl_propertylist_has_cx(plist, CXSTR(cval, keylen)); - } + do { + level++; + keylen = snprintf(ckey, FLEN_KEYWORD, PRO_RECi_ID, level); + } while (cpl_propertylist_has_cx(plist, CXSTR(ckey, keylen))); /* @@ -873,29 +919,32 @@ /* Also copy the mandatory keywords, if any */ - cpl_propertylist_copy_property_regexp(header, plist, - "^ESO (DPR|DRS|PRO|QC) ", 1); - + cpl_propertylist_copy_name_(header, plist, navoidkeys, avoidkeys, 0, NULL, + 1); /* Copy the processing history */ - cpl_propertylist_copy_property_regexp(header, plist, - "^ESO PRO (REC[1-9]*) ", 0); + cpl_propertylist_copy_name_(header, plist, ncopykeys, copykeys, 0, NULL, 0); /* Copy or create the product's ancestor */ if (!cpl_propertylist_has_cx(header, CXSTR(PRO_ANCESTOR, 16))) { + const cpl_property *propin = + cpl_propertylist_get_const_cx(plist, CXSTR(PRO_ANCESTOR, 16)); - if (cpl_propertylist_has_cx(plist, CXSTR(PRO_ANCESTOR, 16))) { - cpl_propertylist_copy_property(header, plist, PRO_ANCESTOR); + if (propin != NULL) { + cpl_propertylist_append_property(header, propin); } - else if (cpl_propertylist_has_cx(plist, CXSTR(ARCFILE, 7))) { - - const char *s = cpl_propertylist_get_string(plist, ARCFILE); - - cpl_propertylist_append_string(header, PRO_ANCESTOR, s); - + else { + propin = cpl_propertylist_get_const_cx(plist, CXSTR(ARCFILE, 7)); + if (propin != NULL) { + propupd = cpl_property_new_cx(CXSTR(PRO_ANCESTOR, 16), + CPL_TYPE_STRING); + cpl_property_set_string_cx( + propupd, CXSTR(cpl_property_get_string(propin), + cpl_property_get_size(propin) - 1)); + cpl_propertylist_set_property(header, propupd); + } } - } cpl_propertylist_delete(plist); @@ -904,10 +953,10 @@ /* * DATAMD5 (placeholder: will be computed by esorex) */ - - cpl_propertylist_update_string(header, DATAMD5, "Not computed"); - cpl_propertylist_set_comment_cx(header, CXSTR(DATAMD5, 7), - CXSTR("MD5 checksum", 12)); + propupd = cpl_propertylist_update_string_(header, CXSTR(DATAMD5, 7), + CXSTR("Not computed", 12)); + cpl_ensure_code(propupd != NULL, cpl_error_get_code()); + cpl_property_set_comment_cx(propupd, CXSTR("MD5 checksum", 12)); /* @@ -916,17 +965,20 @@ kname = cpl_frame_get_filename(product_frame); cpl_ensure_code(kname != NULL, cpl_error_get_code()); - cpl_propertylist_update_string(header, PIPEFILE, kname); - cpl_propertylist_set_comment_cx(header, CXSTR(PIPEFILE, 8), - CXSTR("Filename of data product", 24)); + propupd = cpl_propertylist_update_string_(header, CXSTR(PIPEFILE, 8), + CXSTR(kname, strlen(kname))); + cpl_ensure_code(propupd != NULL, cpl_error_get_code()); + cpl_property_set_comment_cx(propupd, CXSTR("Filename of data product", 24)); /* * PRO DID */ - cpl_propertylist_update_string(header, PRO_DID, dictionary_id); - cpl_propertylist_set_comment_cx(header, CXSTR(PRO_DID, 11), - CXSTR("Data dictionary for PRO", 23)); + propupd = cpl_propertylist_update_string_(header, CXSTR(PRO_DID, 11), + CXSTR(dictionary_id, + strlen(dictionary_id))); + cpl_ensure_code(propupd != NULL, cpl_error_get_code()); + cpl_property_set_comment_cx(propupd, CXSTR("Data dictionary for PRO", 23)); /* @@ -936,25 +988,34 @@ kname = cpl_frame_get_tag(product_frame); if (kname == NULL) { return cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, - "Product frame has no tag"); + "Product frame has no tag"); } - cpl_propertylist_update_string(header, PRO_CATG, kname); - cpl_propertylist_set_comment_cx(header, CXSTR(PRO_CATG, 12), - CXSTR("Category of pipeline product frame", - 34)); + propupd = cpl_propertylist_update_string_(header, CXSTR(PRO_CATG, 12), + CXSTR(kname, strlen(kname))); + cpl_ensure_code(propupd != NULL, cpl_error_get_code()); + cpl_property_set_comment_cx(propupd, + CXSTR("Category of pipeline product frame", + 34)); /* The product frame must be grouped correctly */ - cpl_ensure_code(cpl_frame_get_group(product_frame) - == CPL_FRAME_GROUP_PRODUCT, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(cpl_frame_get_group(product_frame) == + CPL_FRAME_GROUP_PRODUCT, + CPL_ERROR_ILLEGAL_INPUT); /* - * Load only the HIERACH ESO DPR keywords + * Load only the HIERARCH ESO DPR keywords */ if (cpl_is_fits(cpl_frame_get_filename(first_frame))) { - const cpl_cstr * startkey[] = {CXSTR("ESO DPR ", 8)}; + const cpl_cstr *startkey[] = { CXSTR("ESO DPR ", 8) +#ifdef CPL_FIX_PIPE_8268 + , + CXSTR("ESO PRO ", 8) +#endif + }; + const int nkeys = (int)CX_N_ELEMENTS(startkey); plist = cpl_propertylist_load_name_(cpl_frame_get_filename(first_frame), - 0, 1, startkey, 0, NULL, 0); + 0, nkeys, startkey, 0, NULL, 0); cpl_ensure_code(plist != NULL, cpl_error_get_code()); } else @@ -967,9 +1028,10 @@ */ if (!cpl_propertylist_has_cx(header, CXSTR(PRO_TYPE, 12))) { - cpl_propertylist_update_string(header, PRO_TYPE, "REDUCED"); - cpl_propertylist_set_comment_cx(header, CXSTR(PRO_TYPE, 12), - CXSTR("Product type", 12)); + propupd = cpl_property_new_cx(CXSTR(PRO_TYPE, 12), CPL_TYPE_STRING); + cpl_property_set_string_cx(propupd, CXSTR("REDUCED", 7)); + cpl_property_set_comment_cx(propupd, CXSTR("Product type", 12)); + cpl_propertylist_set_property(header, propupd); } /* @@ -981,19 +1043,25 @@ */ if (!cpl_propertylist_has_cx(header, CXSTR(PRO_TECH, 12))) { - if (plist && cpl_propertylist_has_cx(plist, CXSTR(DPR_TECH, 12))) { - cpl_propertylist_update_string(header, PRO_TECH, - cpl_propertylist_get_string(plist, DPR_TECH)); - } - else if (plist && cpl_propertylist_has_cx(plist, CXSTR(PRO_TECH, 12))) { - cpl_propertylist_update_string(header, PRO_TECH, - cpl_propertylist_get_string(plist, PRO_TECH)); - } - else { - cpl_propertylist_update_string(header, PRO_TECH, "UNDEFINED"); + const cpl_property *propin = NULL; + + if (plist != NULL) { + propin = cpl_propertylist_get_const_cx(plist, CXSTR(DPR_TECH, 12)); +#ifdef CPL_FIX_PIPE_8268 + if (propin == NULL) { + propin = + cpl_propertylist_get_const_cx(plist, CXSTR(PRO_TECH, 12)); + } +#endif } - cpl_propertylist_set_comment_cx(header, CXSTR(PRO_TECH, 12), - CXSTR("Observation technique", 21)); + propupd = cpl_property_new_cx(CXSTR(PRO_TECH, 12), CPL_TYPE_STRING); + cpl_property_set_string_cx( + propupd, propin == NULL ? CXSTR("UNDEFINED", 9) + : CXSTR(cpl_property_get_string(propin), + cpl_property_get_size(propin) - 1)); + cpl_property_set_comment_cx(propupd, + CXSTR("Observation technique", 21)); + cpl_propertylist_set_property(header, propupd); } /* @@ -1005,18 +1073,32 @@ */ if (!cpl_propertylist_has_cx(header, CXSTR(PRO_SCIENCE, 15))) { - if (plist && cpl_propertylist_has_cx(plist, CXSTR(DPR_CATG, 12))) { - pro_science = !strncmp(cpl_propertylist_get_string(plist, DPR_CATG), - "SCIENCE", 7); - } - else if (plist && cpl_propertylist_has_cx(plist, - CXSTR(PRO_SCIENCE, 15))) { - pro_science = cpl_propertylist_get_bool(plist, PRO_SCIENCE); - } - cpl_propertylist_update_bool(header, PRO_SCIENCE, pro_science); - cpl_propertylist_set_comment_cx(header, CXSTR(PRO_SCIENCE, 15), - CXSTR("Scientific product if T", - 23)); + int pro_science = 0; + if (plist != NULL) { + const cpl_property *propin = + cpl_propertylist_get_const_cx(plist, CXSTR(DPR_CATG, 12)); + if (propin != NULL && + cpl_property_get_type(propin) == CPL_TYPE_STRING && + cpl_property_get_size(propin) - 1 == 7 && + !memcmp(cpl_property_get_string(propin), "SCIENCE", 7)) { + pro_science = !0; +#ifdef CPL_FIX_PIPE_8268 + } + else { + propin = cpl_propertylist_get_const_cx(plist, + CXSTR(PRO_SCIENCE, 15)); + if (propin != NULL && + cpl_property_get_type(propin) == CPL_TYPE_BOOL) { + pro_science = cpl_property_get_bool(propin); + } +#endif + } + } + propupd = cpl_property_new_cx(CXSTR(PRO_SCIENCE, 15), CPL_TYPE_BOOL); + cpl_property_set_bool(propupd, pro_science); + cpl_property_set_comment_cx(propupd, + CXSTR("Scientific product if T", 23)); + cpl_propertylist_set_property(header, propupd); } cpl_propertylist_delete(plist); @@ -1025,11 +1107,13 @@ * PRO REC1 ID */ - keylen = snprintf(cval, FLEN_VALUE, PRO_RECi_ID, level); - cpl_propertylist_update_string(header, cval, recid); - cpl_propertylist_set_comment_cx(header, CXSTR(cval, keylen), - CXSTR("Pipeline recipe (unique) identifier", - 35)); + keylen = snprintf(ckey, FLEN_KEYWORD, PRO_RECi_ID, level); + propupd = cpl_propertylist_update_string_(header, CXSTR(ckey, keylen), + CXSTR(recid, strlen(recid))); + cpl_ensure_code(propupd != NULL, cpl_error_get_code()); + cpl_property_set_comment_cx(propupd, + CXSTR("Pipeline recipe (unique) identifier", + 35)); /* @@ -1039,21 +1123,27 @@ /* cpl_propertylist_update_string(header, PRO_REC_DRS_ID, cpl_get_version()); */ - keylen = snprintf(cval, FLEN_VALUE, PRO_RECi_DRS_ID, level); - cpl_propertylist_update_string(header, cval, - PACKAGE "-" PACKAGE_VERSION); - cpl_propertylist_set_comment_cx(header, CXSTR(cval, keylen), - CXSTR("Data Reduction System identifier", - 32)); + keylen = snprintf(ckey, FLEN_KEYWORD, PRO_RECi_DRS_ID, level); + propupd = + cpl_propertylist_update_string_(header, CXSTR(ckey, keylen), + CXSTR(PACKAGE "-" PACKAGE_VERSION, + strlen(PACKAGE + "-" PACKAGE_VERSION))); + cpl_ensure_code(propupd != NULL, cpl_error_get_code()); + cpl_property_set_comment_cx(propupd, + CXSTR("Data Reduction System identifier", 32)); /* * PRO REC1 PIPE ID */ - keylen = snprintf(cval, FLEN_VALUE, PRO_RECi_PIPE_ID, level); - cpl_propertylist_update_string(header, cval, pipeline_id); - cpl_propertylist_set_comment_cx(header, CXSTR(cval, keylen), - CXSTR("Pipeline (unique) identifier", 28)); + keylen = snprintf(ckey, FLEN_KEYWORD, PRO_RECi_PIPE_ID, level); + propupd = cpl_propertylist_update_string_(header, CXSTR(ckey, keylen), + CXSTR(pipeline_id, + strlen(pipeline_id))); + cpl_ensure_code(propupd != NULL, cpl_error_get_code()); + cpl_property_set_comment_cx(propupd, + CXSTR("Pipeline (unique) identifier", 28)); /* @@ -1066,28 +1156,40 @@ frame = cpl_frameset_iterator_get_const(it); while (frame != NULL) { - - cpl_errorstate status; + cpl_errorstate status; if (cpl_frame_get_group(frame) == CPL_FRAME_GROUP_RAW) { + const char *filename = cpl_frame_get_filename(frame); + const char *basename = cpl_get_base_name(filename); + const char *tagname = cpl_frame_get_tag(frame); ++nraw; - keylen = snprintf(cval, FLEN_VALUE, PRO_RECi_RAWi_NAME, level, - nraw); - cpl_propertylist_update_string(header, cval, - cpl_get_base_name(cpl_frame_get_filename(frame))); - cpl_propertylist_set_comment_cx(header, CXSTR(cval, keylen), - CXSTR("File name of raw frame", - 22)); - - keylen = snprintf(cval, FLEN_VALUE, PRO_RECi_RAWi_CATG, level, - nraw); - cpl_propertylist_update_string(header, cval, - cpl_frame_get_tag(frame)); - cpl_propertylist_set_comment_cx(header, CXSTR(cval, keylen), - CXSTR("Category of raw frame", 21)); + keylen = + snprintf(ckey, FLEN_KEYWORD, PRO_RECi_RAWi_NAME, level, nraw); + propupd = + cpl_propertylist_update_string_(header, CXSTR(ckey, keylen), + CXSTR(basename, + strlen(basename))); + if (propupd == NULL) { + cpl_frameset_iterator_delete(it); + return cpl_error_set_where_(); + } + cpl_property_set_comment_cx(propupd, + CXSTR("File name of raw frame", 22)); + keylen = + snprintf(ckey, FLEN_KEYWORD, PRO_RECi_RAWi_CATG, level, nraw); + propupd = + cpl_propertylist_update_string_(header, CXSTR(ckey, keylen), + CXSTR(tagname, + strlen(tagname))); + if (propupd == NULL) { + cpl_frameset_iterator_delete(it); + return cpl_error_set_where_(); + } + cpl_property_set_comment_cx(propupd, + CXSTR("Category of raw frame", 21)); } status = cpl_errorstate_get(); @@ -1095,11 +1197,10 @@ cpl_frameset_iterator_advance(it, 1); if (cpl_error_get_code() == CPL_ERROR_ACCESS_OUT_OF_RANGE) { - cpl_errorstate_set(status); + cpl_errorstate_set(status); } frame = cpl_frameset_iterator_get_const(it); - } cpl_frameset_iterator_delete(it); @@ -1109,11 +1210,12 @@ /* * PRO DATANCOM */ - if (!cpl_propertylist_has_cx(header, CXSTR(PRO_DATANCOM, 16))) { - cpl_propertylist_update_int(header, PRO_DATANCOM, nraw); - cpl_propertylist_set_comment_cx(header, CXSTR(PRO_DATANCOM, 16), - CXSTR("Number of combined frames", 25)); + propupd = cpl_property_new_cx(CXSTR(PRO_DATANCOM, 16), CPL_TYPE_INT); + cpl_property_set_int(propupd, nraw); + cpl_property_set_comment_cx(propupd, + CXSTR("Number of combined frames", 25)); + cpl_propertylist_set_property(header, propupd); } @@ -1127,67 +1229,101 @@ frame = cpl_frameset_iterator_get_const(it); while (frame != NULL) { - - cpl_errorstate status; + cpl_errorstate status; if (cpl_frame_get_group(frame) == CPL_FRAME_GROUP_CALIB) { - const cpl_cstr * exactkey[] = {CXSTR(DATAMD5, 7)}; + const cpl_cstr *exactkey[] = { CXSTR(DATAMD5, 7) }; + const char *filename = cpl_frame_get_filename(frame); + const char *basename = cpl_get_base_name(filename); + const char *tagname = cpl_frame_get_tag(frame); + const int nkeys = (int)CX_N_ELEMENTS(exactkey); ++ncal; - keylen = snprintf(cval, FLEN_VALUE, PRO_RECi_CALi_NAME, level, - ncal); - cpl_propertylist_update_string(header, cval, - cpl_get_base_name(cpl_frame_get_filename(frame))); - cpl_propertylist_set_comment_cx(header, CXSTR(cval, keylen), - CXSTR("File name of calibration " - "frame", 30)); - - keylen = snprintf(cval, FLEN_VALUE, PRO_RECi_CALi_CATG, level, - ncal); - cpl_propertylist_update_string(header, cval, - cpl_frame_get_tag(frame)); - cpl_propertylist_set_comment_cx(header, CXSTR(cval, keylen), - CXSTR("Category of calibration " - "frame", 29)); - - keylen = snprintf(cval, FLEN_VALUE, PRO_RECi_CALi_DATAMD5, level, - ncal); - - switch (cpl_is_fits(cpl_frame_get_filename(frame))) { - case 0: - plist = cpl_propertylist_new(); - break; - case 1: - plist = - cpl_propertylist_load_name_(cpl_frame_get_filename(frame), - 0, 0, NULL, 1, exactkey, 0); - cpl_ensure_code(plist != NULL, cpl_error_get_code()); - break; - default: - cpl_frameset_iterator_delete(it); - return cpl_error_get_code() == CPL_ERROR_NULL_INPUT - ? cpl_error_set_(CPL_ERROR_DATA_NOT_FOUND) - : cpl_error_set_where_(); - break; + keylen = + snprintf(ckey, FLEN_KEYWORD, PRO_RECi_CALi_NAME, level, ncal); + propupd = + cpl_propertylist_update_string_(header, CXSTR(ckey, keylen), + CXSTR(basename, + strlen(basename))); + if (propupd == NULL) { + cpl_frameset_iterator_delete(it); + return cpl_error_set_where_(); } - - if (cpl_propertylist_has_cx(plist, CXSTR(DATAMD5, 7))) { - if (cpl_propertylist_get_type(plist, DATAMD5) != - CPL_TYPE_STRING) { - cpl_msg_warning(cpl_func, "Unexpected type for keyword " - DATAMD5 " in input header"); - } - else { - datamd5 = cpl_propertylist_get_string(plist, DATAMD5); - cpl_propertylist_update_string(header, cval, datamd5); - cpl_propertylist_set_comment_cx(header, - CXSTR(cval, keylen), - CXSTR("MD5 signature of " - "calib frame", 28)); - } + cpl_property_set_comment_cx(propupd, + CXSTR("File name of calibration frame", + 30)); + + keylen = + snprintf(ckey, FLEN_KEYWORD, PRO_RECi_CALi_CATG, level, ncal); + propupd = + cpl_propertylist_update_string_(header, CXSTR(ckey, keylen), + CXSTR(tagname, + strlen(tagname))); + if (propupd == NULL) { + cpl_frameset_iterator_delete(it); + return cpl_error_set_where_(); + } + cpl_property_set_comment_cx(propupd, + CXSTR("Category of calibration frame", + 29)); + + switch (cpl_is_fits(filename)) { + case 0: + break; + case 1: + plist = cpl_propertylist_load_name_(filename, 0, 0, NULL, + nkeys, exactkey, 0); + if (plist == NULL) { + cpl_frameset_iterator_delete(it); + return cpl_error_set_where_(); + } + else { + const cpl_property *propin = + cpl_propertylist_get_const_cx(plist, + CXSTR(DATAMD5, 7)); + + if (propin != NULL) { + if (cpl_property_get_type(propin) != + CPL_TYPE_STRING) { + cpl_msg_warning(cpl_func, + "Card " DATAMD5 " in %s " + "has non-string type: %s", + filename, + cpl_type_get_name( + cpl_property_get_type( + propin))); + } + else { + keylen = snprintf(ckey, FLEN_KEYWORD, + PRO_RECi_CALi_DATAMD5, level, + ncal); + propupd = cpl_propertylist_update_string_( + header, CXSTR(ckey, keylen), + CXSTR(cpl_property_get_string(propin), + cpl_property_get_size(propin) - 1)); + + if (propupd == NULL) { + cpl_propertylist_delete(plist); + cpl_frameset_iterator_delete(it); + return cpl_error_set_where_(); + } + cpl_property_set_comment_cx( + propupd, CXSTR("MD5 signature of " + "calib frame", + 28)); + } + } + cpl_propertylist_delete(plist); + } + break; + default: + cpl_frameset_iterator_delete(it); + return cpl_error_get_code() == CPL_ERROR_NULL_INPUT + ? cpl_error_set_(CPL_ERROR_DATA_NOT_FOUND) + : cpl_error_set_where_(); + break; } - cpl_propertylist_delete(plist); } status = cpl_errorstate_get(); @@ -1195,11 +1331,10 @@ cpl_frameset_iterator_advance(it, 1); if (cpl_error_get_code() == CPL_ERROR_ACCESS_OUT_OF_RANGE) { - cpl_errorstate_set(status); + cpl_errorstate_set(status); } frame = cpl_frameset_iterator_get_const(it); - } cpl_frameset_iterator_delete(it); @@ -1210,14 +1345,14 @@ param = cpl_parameterlist_get_first_const(parlist); while (param != NULL) { - char * pval; - char * dval; /* The default value for value comment */ + char *pval; + char *dval; /* The default value for value comment */ #if defined CFITSIO_MAJOR && (CFITSIO_MAJOR > 3 || CFITSIO_MINOR >= 26) - char * help = NULL; - const char * comment = cpl_parameter_get_help(param); + char *help = NULL; + const char *comment = cpl_parameter_get_help(param); #else - char * help = cpl_dfs_extract_printable(cpl_parameter_get_help(param)); - const char * comment = help; + char *help = cpl_dfs_extract_printable(cpl_parameter_get_help(param)); + const char *comment = help; #endif int dvallen = 0; @@ -1226,61 +1361,82 @@ kname = cpl_parameter_get_alias(param, CPL_PARAMETER_MODE_CLI); switch (cpl_parameter_get_type(param)) { - case CPL_TYPE_BOOL: - pval = cpl_strdup(cpl_parameter_get_bool(param) == 1 - ? "true" : "false"); - dval = cpl_sprintf("Default: %s%n", - cpl_parameter_get_default_bool(param) == 1 - ? "true" : "false", &dvallen); - if (!comment) comment = "Boolean recipe parameter"; - break; - case CPL_TYPE_INT: - pval = cpl_sprintf("%d", cpl_parameter_get_int(param)); - dval = cpl_sprintf("Default: %d%n", - cpl_parameter_get_default_int(param), &dvallen); - if (!comment) comment = "Integer recipe parameter"; - break; - case CPL_TYPE_DOUBLE: - pval = cpl_sprintf("%g", cpl_parameter_get_double(param)); - dval = cpl_sprintf("Default: %g%n", - cpl_parameter_get_default_double(param), - &dvallen); - if (!comment) comment = "Floating point recipe parameter"; - break; - case CPL_TYPE_STRING: - pval = cpl_strdup(cpl_parameter_get_string(param)); - dval = cpl_sprintf("Default: '%s'%n", - cpl_parameter_get_default_string(param), - &dvallen); - if (!comment) comment = "String recipe parameter"; - break; - default: - - /* - * Theoretically impossible to get here - */ - - cpl_free((void*)help); - return cpl_error_set_(CPL_ERROR_UNSPECIFIED); - } + case CPL_TYPE_BOOL: + pval = cpl_strdup(cpl_parameter_get_bool(param) == 1 ? "true" + : "false"); + dval = cpl_sprintf("Default: %s%n", + cpl_parameter_get_default_bool(param) == 1 + ? "true" + : "false", + &dvallen); + if (!comment) + comment = "Boolean recipe parameter"; + break; + case CPL_TYPE_INT: + pval = cpl_sprintf("%d", cpl_parameter_get_int(param)); + dval = + cpl_sprintf("Default: %d%n", + cpl_parameter_get_default_int(param), &dvallen); + if (!comment) + comment = "Integer recipe parameter"; + break; + case CPL_TYPE_DOUBLE: + pval = cpl_sprintf("%g", cpl_parameter_get_double(param)); + dval = cpl_sprintf("Default: %g%n", + cpl_parameter_get_default_double(param), + &dvallen); + if (!comment) + comment = "Floating point recipe parameter"; + break; + case CPL_TYPE_STRING: + pval = cpl_strdup(cpl_parameter_get_string(param)); + dval = cpl_sprintf("Default: '%s'%n", + cpl_parameter_get_default_string(param), + &dvallen); + if (!comment) + comment = "String recipe parameter"; + break; + default: - snprintf(cval, FLEN_VALUE, PRO_RECi_PARAMi_NAME, level, npar); - cpl_propertylist_update_string(header, cval, kname); - cpl_propertylist_set_comment(header, cval, comment); - - keylen = snprintf(cval, FLEN_VALUE, PRO_RECi_PARAMi_VALUE, level, npar); - cpl_propertylist_update_string(header, cval, pval); - cpl_propertylist_set_comment_cx(header, CXSTR(cval, keylen), - CXSTR(dval, dvallen)); - - cpl_free((void*)help); - cpl_free((void*)pval); - cpl_free((void*)dval); + /* + * Theoretically impossible to get here + */ + + cpl_free((void *)help); + return cpl_error_set_(CPL_ERROR_UNSPECIFIED); + } + + keylen = + snprintf(ckey, FLEN_KEYWORD, PRO_RECi_PARAMi_NAME, level, npar); + propupd = cpl_propertylist_update_string_(header, CXSTR(ckey, keylen), + CXSTR(kname, strlen(kname))); + cpl_ensure_code(propupd != NULL, cpl_error_get_code()); + cpl_property_set_comment(propupd, comment); + + keylen = + snprintf(ckey, FLEN_KEYWORD, PRO_RECi_PARAMi_VALUE, level, npar); + propupd = cpl_propertylist_update_string_(header, CXSTR(ckey, keylen), + CXSTR(pval, strlen(pval))); + cpl_ensure_code(propupd != NULL, cpl_error_get_code()); + cpl_property_set_comment_cx(propupd, CXSTR(dval, dvallen)); + + cpl_free((void *)help); + cpl_free((void *)pval); + cpl_free((void *)dval); param = cpl_parameterlist_get_next_const(parlist); } + /* + * Final consistency checks of the created, finalized product header. + */ + + if (cpl_propertylist_has(header, "RADECSYS")) { + cpl_msg_warning(cpl_func, "Product header contains deprecated " + "keyword 'RADECSYS'!"); + } + return CPL_ERROR_NONE; } @@ -1328,11 +1484,14 @@ */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_dfs_update_product_header(cpl_frameset * self) +cpl_error_code +cpl_dfs_update_product_header(cpl_frameset *self) { - return cpl_dfs_update_product_header_(self) - | cpl_io_fits_close_tid(CPL_IO_FITS_ALL) /* FIXME: Close only writers */ - ? cpl_error_set_where_() : CPL_ERROR_NONE; + return cpl_dfs_update_product_header_(self) | + cpl_io_fits_close_tid( + CPL_IO_FITS_ALL) /* FIXME: Close only writers */ + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } @@ -1414,7 +1573,7 @@ it = cpl_frameset_iterator_new(set); while (((frame = cpl_frameset_iterator_get_const(it)) != NULL) && - (status == CPL_ERROR_NONE)) { + (status == CPL_ERROR_NONE)) { cpl_errorstate _status; if (cpl_frame_get_group(frame) == CPL_FRAME_GROUP_PRODUCT) { @@ -1428,7 +1587,6 @@ if (cpl_error_get_code() == CPL_ERROR_ACCESS_OUT_OF_RANGE) { cpl_errorstate_set(_status); } - } cpl_frameset_iterator_delete(it); @@ -1437,7 +1595,6 @@ status |= cpl_io_fits_close_tid(CPL_IO_FITS_ALL); return status ? cpl_error_set_where_() : CPL_ERROR_NONE; - } /**@}*/ @@ -1463,18 +1620,14 @@ inline static cpl_error_code _cpl_dfs_sign_product(const cpl_frame *frame, cxuint flags) { - const cxchar *filename = cpl_frame_get_filename(frame); if (filename == NULL) { - cpl_error_set(cpl_func, CPL_ERROR_DATA_NOT_FOUND); return CPL_ERROR_DATA_NOT_FOUND; - } if (cpl_is_fits(filename)) { - cxint _status = 0; fitsfile *fptr; cxint chdu; @@ -1482,22 +1635,18 @@ if (cpl_io_fits_open_diskfile(&fptr, filename, READWRITE, &_status)) { - - return cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, - _status, fits_open_diskfile, - "filename='%s'", filename); - + return cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, _status, + fits_open_diskfile, "filename='%s'", + filename); } fits_get_num_hdus(fptr, &nhdu, &_status); if (_status) { - - return cpl_error_set_fits(CPL_ERROR_FILE_IO, - _status, fits_get_num_hdus, - "filename='%s'", filename); - + return cpl_error_set_fits(CPL_ERROR_FILE_IO, _status, + fits_get_num_hdus, "filename='%s'", + filename); } @@ -1508,11 +1657,9 @@ fits_movabs_hdu(fptr, 1, NULL, &_status); if (_status) { - - return cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, - _status, fits_movabs_hdu, - "filename='%s'", filename); - + return cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, _status, + fits_movabs_hdu, "filename='%s'", + filename); } @@ -1524,63 +1671,50 @@ "Filename of data product", &_status); if (_status) { - - return cpl_error_set_fits(CPL_ERROR_FILE_IO, - _status, fits_update_key_str, - "filename='%s', key='" - PIPEFILE "'", filename); - + return cpl_error_set_fits(CPL_ERROR_FILE_IO, _status, + fits_update_key_str, + "filename='%s', key='" PIPEFILE "'", + filename); } if (flags & CPL_DFS_SIGNATURE_DATAMD5) { - cxchar md5sum[MD5HASHSZ + 1]; if (cpl_dfs_find_md5sum(md5sum, fptr)) { return cpl_error_set_where_(); } - fits_update_key_str(fptr, DATAMD5, md5sum, - "MD5 checksum", &_status); + fits_update_key_str(fptr, DATAMD5, md5sum, "MD5 checksum", + &_status); if (_status) { - - return cpl_error_set_fits(CPL_ERROR_FILE_IO, - _status, fits_update_key_str, - "filename='%s', key='" - DATAMD5 "', value='%s'", + return cpl_error_set_fits(CPL_ERROR_FILE_IO, _status, + fits_update_key_str, + "filename='%s', key='" DATAMD5 + "', value='%s'", filename, md5sum); - } - } else { - fits_delete_key(fptr, DATAMD5, &_status); if (_status == KEY_NO_EXIST) { _status = 0; } - } if (flags & CPL_DFS_SIGNATURE_CHECKSUM) { - fits_write_chksum(fptr, &_status); if (_status) { - - return cpl_error_set_fits(CPL_ERROR_FILE_IO, - _status, fits_write_chksum, - "filename='%s'", filename); - + return cpl_error_set_fits(CPL_ERROR_FILE_IO, _status, + fits_write_chksum, "filename='%s'", + filename); } - } else { - fits_delete_key(fptr, CHECKSUM, &_status); if (_status == KEY_NO_EXIST) { @@ -1592,7 +1726,6 @@ if (_status == KEY_NO_EXIST) { _status = 0; } - } @@ -1601,7 +1734,6 @@ */ if (nhdu > 1) { - /* * Move file pointer to the first extension */ @@ -1609,30 +1741,22 @@ fits_movabs_hdu(fptr, 2, NULL, &_status); if (_status) { - - return cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, - _status, fits_movabs_hdu, - "filename='%s'", filename); - + return cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, _status, + fits_movabs_hdu, "filename='%s'", + filename); } for (chdu = 2; chdu <= nhdu; ++chdu) { - if (flags & CPL_DFS_SIGNATURE_CHECKSUM) { - fits_write_chksum(fptr, &_status); if (_status) { - - return cpl_error_set_fits(CPL_ERROR_FILE_IO, - _status, fits_write_chksum, + return cpl_error_set_fits(CPL_ERROR_FILE_IO, _status, + fits_write_chksum, "filename='%s'", filename); - } - } else { - fits_delete_key(fptr, CHECKSUM, &_status); if (_status == KEY_NO_EXIST) { @@ -1646,36 +1770,27 @@ } if (_status) { - - return cpl_error_set_fits(CPL_ERROR_FILE_IO, - _status, fits_delete_key, + return cpl_error_set_fits(CPL_ERROR_FILE_IO, _status, + fits_delete_key, "filename='%s'", filename); - } - } if (chdu < nhdu) { fits_movrel_hdu(fptr, 1, NULL, &_status); } - } - } if (cpl_io_fits_close_file(fptr, &_status)) { - - return cpl_error_set_fits(CPL_ERROR_FILE_IO, - _status, fits_close_file, - "filename='%s'", filename); - + return cpl_error_set_fits(CPL_ERROR_FILE_IO, _status, + fits_close_file, "filename='%s'", + filename); } - } return CPL_ERROR_NONE; - } @@ -1688,9 +1803,10 @@ @see cpl_dfs_update_product_header() */ /*----------------------------------------------------------------------------*/ -static cpl_error_code cpl_dfs_update_product_header_(cpl_frameset * self) +static cpl_error_code +cpl_dfs_update_product_header_(cpl_frameset *self) { - const cpl_frame * frame; + const cpl_frame *frame; cpl_frameset_iterator *it; @@ -1700,40 +1816,33 @@ it = cpl_frameset_iterator_new(self); while ((frame = cpl_frameset_iterator_get_const(it)) != NULL) { - - cpl_errorstate status; + cpl_errorstate status; if (cpl_frame_get_group(frame) == CPL_FRAME_GROUP_PRODUCT) { - - const char * filename = cpl_frame_get_filename(frame); + const char *filename = cpl_frame_get_filename(frame); if (filename == NULL) { + cpl_frameset_iterator_delete(it); - cpl_frameset_iterator_delete(it); - - cpl_error_set(cpl_func, CPL_ERROR_DATA_NOT_FOUND); - return CPL_ERROR_DATA_NOT_FOUND; - + cpl_error_set(cpl_func, CPL_ERROR_DATA_NOT_FOUND); + return CPL_ERROR_DATA_NOT_FOUND; } if (cpl_is_fits(filename)) { - - fitsfile * fproduct = NULL; - char card[FLEN_CARD]; - int error = 0; /* CFITSIO requires this to be zero */ + fitsfile *fproduct = NULL; + char card[FLEN_CARD]; + int error = 0; /* CFITSIO requires this to be zero */ cpl_error_code code = CPL_ERROR_NONE; if (cpl_io_fits_open_diskfile(&fproduct, filename, READWRITE, &error)) { - - cpl_frameset_iterator_delete(it); + cpl_frameset_iterator_delete(it); return cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, error, fits_open_diskfile, "filename='%s'", filename); - } #ifndef CPL_IO_FITS_REWIND @@ -1741,43 +1850,45 @@ previous I/O, so the file pointer needs to be moved */ if (fits_movabs_hdu(fproduct, 1, NULL, &error)) { code = cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, error, - fits_movabs_hdu, - "filename='%s'", filename); + fits_movabs_hdu, "filename='%s'", + filename); } #endif if (fits_read_card(fproduct, DATAMD5, card, &error)) { code = cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, error, - fits_read_card, "filename='%s', " - "key='" DATAMD5 "'", filename); + fits_read_card, + "filename='%s', " + "key='" DATAMD5 "'", + filename); error = 0; } else { - /* The fits header has the MD5-card, update it */ char md5sum[MD5HASHSZ + 1]; if (cpl_dfs_find_md5sum(md5sum, fproduct)) { code = cpl_error_set_where_(); - } else { - char* inclist; + } + else { + char *inclist; if (fits_update_key_str(fproduct, DATAMD5, md5sum, "MD5 checksum", &error)) { - code = cpl_error_set_fits(CPL_ERROR_FILE_IO, error, - fits_update_key_str, - "filename='%s', key='" - DATAMD5 "', value='%s'", - filename, md5sum); + code = cpl_error_set_fits( + CPL_ERROR_FILE_IO, error, fits_update_key_str, + "filename='%s', key='" DATAMD5 "', value='%s'", + filename, md5sum); error = 0; - } else if (fits_update_key_str(fproduct, PIPEFILE, - filename, - "Filename of data" - " product", &error)) { - code = cpl_error_set_fits(CPL_ERROR_FILE_IO, error, - fits_update_key_str, - "filename='%s', key='" - PIPEFILE "'", filename); + } + else if (fits_update_key_str(fproduct, PIPEFILE, + filename, + "Filename of data" + " product", + &error)) { + code = cpl_error_set_fits( + CPL_ERROR_FILE_IO, error, fits_update_key_str, + "filename='%s', key='" PIPEFILE "'", filename); error = 0; } @@ -1788,40 +1899,38 @@ /* CFITSIO (up to ver. 3450) has missing const correctness in fits_find_nextkey()/ffgnxk() */ CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); - inclist = (char*)CHECKSUM; + inclist = (char *)CHECKSUM; CPL_DIAG_PRAGMA_POP; - if (!fits_find_nextkey(fproduct, &inclist, 1, - NULL, 0, card, &error)) { - + if (!fits_find_nextkey(fproduct, &inclist, 1, NULL, 0, + card, &error)) { if (fits_write_chksum(fproduct, &error)) { - code = cpl_error_set_fits(CPL_ERROR_FILE_IO, - error, - fits_update_key_str, - "filename='%s', key='" - CHECKSUM "'", filename); + code = cpl_error_set_fits( + CPL_ERROR_FILE_IO, error, + fits_update_key_str, + "filename='%s', key='" CHECKSUM "'", + filename); error = 0; } - } else if (error == KEY_NO_EXIST) { + } + else if (error == KEY_NO_EXIST) { error = 0; /* Reset error if key not found */ - } else { - code = cpl_error_set_fits(CPL_ERROR_FILE_IO, error, - fits_update_key_str, - "filename='%s', key='" - CHECKSUM "'", filename); + } + else { + code = cpl_error_set_fits( + CPL_ERROR_FILE_IO, error, fits_update_key_str, + "filename='%s', key='" CHECKSUM "'", filename); error = 0; } } } if (cpl_io_fits_close_file(fproduct, &error)) { - cpl_frameset_iterator_delete(it); return cpl_error_set_fits(CPL_ERROR_FILE_IO, error, - fits_close_file, - "filename='%s'", filename); - + fits_close_file, "filename='%s'", + filename); } if (code) { @@ -1836,16 +1945,14 @@ cpl_frameset_iterator_advance(it, 1); if (cpl_error_get_code() == CPL_ERROR_ACCESS_OUT_OF_RANGE) { - cpl_errorstate_set(status); + cpl_errorstate_set(status); } - } cpl_frameset_iterator_delete(it); it = NULL; return CPL_ERROR_NONE; - } /*----------------------------------------------------------------------------*/ @@ -1860,12 +1967,13 @@ */ /*----------------------------------------------------------------------------*/ -static cpl_error_code cpl_dfs_find_md5sum(char * md5sum, fitsfile * fproduct) +static cpl_error_code +cpl_dfs_find_md5sum(char *md5sum, fitsfile *fproduct) { struct MD5Context ctx; - unsigned char digest[(MD5HASHSZ)>>1]; - int error = 0; - int next = 0; + unsigned char digest[(MD5HASHSZ) >> 1]; + int error = 0; + int next = 0; /* For performance reasons the number of bytes read and passed on by this function should be: @@ -1883,11 +1991,10 @@ L1 cache from Intel from about year 2006. It is also a whole number (90) of 512 bytes, a common disk sector size. */ const long maxblocksize = 2880 * 16; - void * buffer = NULL; + void *buffer = NULL; /* Iterate through main HDU and all extensions */ do { - CPL_OFF_TYPE datastart, datapos, dataend; if (CPL_OFF_FUNC(fproduct, NULL, &datastart, &dataend, &error)) { @@ -1899,7 +2006,7 @@ datapos = datastart; while (datapos < dataend) { - const long datatodo = (long)(dataend - datapos); + const long datatodo = (long)(dataend - datapos); const LONGLONG blocksize = CX_MIN(datatodo, maxblocksize); if (buffer == NULL) { @@ -1912,8 +2019,8 @@ ffmbyt(fproduct, datastart, 0, &error)) { cpl_free(buffer); return cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, error, - ffmbyt, "HDU#=%d, datapos=%lu", - next, (unsigned long)datapos); + ffmbyt, "HDU#=%d, datapos=%lu", next, + (unsigned long)datapos); } @@ -1926,8 +2033,7 @@ } /* Update MD5 sum with data in current buffer */ - MD5Update(&ctx, (const unsigned char *)buffer, - (unsigned)blocksize); + MD5Update(&ctx, (const unsigned char *)buffer, (unsigned)blocksize); datapos += blocksize; } @@ -1937,10 +2043,9 @@ cpl_free(buffer); return cpl_error_set_message_(CPL_ERROR_BAD_FILE_FORMAT, "HDU#=%d, datapos=%ld != " - "dataend=%ld, sizeof(" - CPL_STRINGIFY(CPL_OFF_TYPE) ")=%zu", - next, (long)datapos, (long)dataend, - sizeof(CPL_OFF_TYPE)); + "dataend=%ld, sizeof(" CPL_STRINGIFY(CPL_OFF_TYPE) ")=%zu", next, + (long)datapos, (long)dataend, + sizeof(CPL_OFF_TYPE)); } next++; @@ -1957,41 +2062,30 @@ nsize = sprintf(md5sum, "%02x%02x%02x%02x%02x%02x%02x%02x" "%02x%02x%02x%02x%02x%02x%02x%02x", - digest[ 0], - digest[ 1], - digest[ 2], - digest[ 3], - digest[ 4], - digest[ 5], - digest[ 6], - digest[ 7], - digest[ 8], - digest[ 9], - digest[10], - digest[11], - digest[12], - digest[13], - digest[14], - digest[15]); + digest[0], digest[1], digest[2], digest[3], digest[4], + digest[5], digest[6], digest[7], digest[8], digest[9], + digest[10], digest[11], digest[12], digest[13], + digest[14], digest[15]); assert(nsize == MD5HASHSZ); - } else { + } + else { /* The FITS file has no data, which has the below checksum */ - (void)memcpy(md5sum, "d41d8cd98f00b204e9800998ecf8427e", - 1 + MD5HASHSZ); + (void)memcpy(md5sum, "d41d8cd98f00b204e9800998ecf8427e", 1 + MD5HASHSZ); } if (error == END_OF_FILE) { error = 0; /* Reset CFITSIO error */ - } else { + } + else { return cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, error, fits_movabs_hdu, "HDU#=%d", next); } /* Move back to beginning */ if (fits_movabs_hdu(fproduct, 1, NULL, &error)) { - return cpl_error_set_fits(CPL_ERROR_FILE_IO, error, - fits_movabs_hdu, "HDU#=%d", next); + return cpl_error_set_fits(CPL_ERROR_FILE_IO, error, fits_movabs_hdu, + "HDU#=%d", next); } return CPL_ERROR_NONE; @@ -2007,52 +2101,61 @@ */ /*----------------------------------------------------------------------------*/ -static int cpl_is_fits(const char * self) +static int +cpl_is_fits(const char *self) { - cpl_errorstate prestate = cpl_errorstate_get(); - int error = 0; - int is_fits = 1; - fitsfile * fptr; + int is_fits = 1; cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1); - if (cpl_io_fits_open_diskfile(&fptr, self, READONLY, &error)) { - is_fits = error == FILE_NOT_OPENED ? -2 : 0; + if (!cpl_io_fits_is_open(self)) { + cpl_errorstate prestate = cpl_errorstate_get(); + int error = 0; + fitsfile *fptr; - if (is_fits < 0) { - (void)cpl_error_set_message_(CPL_ERROR_FILE_NOT_FOUND, - "filename='%s'", self); - } else { - cpl_errorstate_set(prestate); - } - error = 0; + if (cpl_io_fits_open_diskfile(&fptr, self, READONLY, &error)) { + is_fits = error == FILE_NOT_OPENED ? -2 : 0; + + if (is_fits < 0) { + (void)cpl_error_set_message_(CPL_ERROR_FILE_NOT_FOUND, + "filename='%s'", self); + } + else { + cpl_errorstate_set(prestate); + } + error = 0; #ifndef CPL_IO_FITS_REWIND - } else if (fits_movabs_hdu(fptr, 1, NULL, &error)) { - /* The open call may be reusing file handle opened for - previous I/O, so the file pointer needs to be moved */ - is_fits = error == FILE_NOT_OPENED ? -2 : 0; - - if (is_fits < 0) - (void)cpl_error_set_fits(CPL_ERROR_FILE_NOT_FOUND, error, - fits_movabs_hdu, "filename='%s'", self); - error = 0; + } + else if (fits_movabs_hdu(fptr, 1, NULL, &error)) { + /* The open call may be reusing file handle opened for + previous I/O, so the file pointer needs to be moved */ + is_fits = error == FILE_NOT_OPENED ? -2 : 0; + + if (is_fits < 0) + (void)cpl_error_set_fits(CPL_ERROR_FILE_NOT_FOUND, error, + fits_movabs_hdu, "filename='%s'", + self); + error = 0; #endif - } else if (fits_read_imghdr(fptr, 0, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, &error)) { - is_fits = error == FILE_NOT_OPENED ? -2 : 0; - - if (is_fits < 0) - (void)cpl_error_set_fits(CPL_ERROR_FILE_NOT_FOUND, error, - fits_read_imghdr, "filename='%s'", self); - error = 0; - } - - if (fptr != NULL && cpl_io_fits_close_file(fptr, &error) != 0) { - /* FIXME: Is this even possible ? */ - is_fits = -1; - (void)cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, error, - fits_close_file, "filename='%s'", self); + } + else if (fits_read_imghdr(fptr, 0, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, &error)) { + is_fits = error == FILE_NOT_OPENED ? -2 : 0; + + if (is_fits < 0) + (void)cpl_error_set_fits(CPL_ERROR_FILE_NOT_FOUND, error, + fits_read_imghdr, "filename='%s'", + self); + error = 0; + } + + if (fptr != NULL && cpl_io_fits_close_file(fptr, &error) != 0) { + /* FIXME: Is this even possible ? */ + is_fits = -1; + (void)cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, error, + fits_close_file, "filename='%s'", self); + } } return is_fits; @@ -2070,15 +2173,15 @@ */ /*----------------------------------------------------------------------------*/ -static const char * cpl_get_base_name(const char * self) +static const char * +cpl_get_base_name(const char *self) { - const char * p = self ? strrchr(self, '/') : NULL; + const char *p = self ? strrchr(self, '/') : NULL; return p ? p + 1 : self; } - /*----------------------------------------------------------------------------*/ /** @brief Open a new PAF file, output a default header. @@ -2100,73 +2203,81 @@ */ /*----------------------------------------------------------------------------*/ -static FILE * cpl_dfs_paf_init(const char * instrume, - const char * recipe, - const char * filename) +static FILE * +cpl_dfs_paf_init(const char *instrume, const char *recipe, const char *filename) { - FILE * paf = NULL; - char * paf_id = NULL; + FILE *paf = NULL; + char *paf_id = NULL; const char paf_desc[] = "QC file"; int nlen; cpl_error_code error = CPL_ERROR_NONE; - cpl_ensure(instrume != NULL, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(recipe != NULL, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(filename != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(instrume != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(recipe != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(filename != NULL, CPL_ERROR_NULL_INPUT, NULL); - cpl_msg_info(cpl_func, "Writing PAF: %s" , filename); + cpl_msg_info(cpl_func, "Writing PAF: %s", filename); paf_id = cpl_sprintf("%s/%s", instrume, recipe); - assert( paf_id != NULL); + assert(paf_id != NULL); paf = fopen(filename, "w"); - if (paf == NULL) error = CPL_ERROR_FILE_IO; + if (paf == NULL) + error = CPL_ERROR_FILE_IO; /* Some ugly, traditional error handling that obscures the actual functionality (i.e. to fprintf() some strings) */ - + if (!error) { nlen = fprintf(paf, "PAF.HDR.START ;# start of header\n"); - if (nlen <= PAF_KEY_LEN) error = CPL_ERROR_FILE_IO; + if (nlen <= PAF_KEY_LEN) + error = CPL_ERROR_FILE_IO; } if (!error) { nlen = fprintf(paf, "PAF.TYPE \"pipeline product\" ;\n"); - if (nlen <= PAF_KEY_LEN) error = CPL_ERROR_FILE_IO; + if (nlen <= PAF_KEY_LEN) + error = CPL_ERROR_FILE_IO; } if (!error) { nlen = fprintf(paf, "PAF.ID \"%s\"\n", paf_id); - if (nlen <= PAF_KEY_LEN) error = CPL_ERROR_FILE_IO; + if (nlen <= PAF_KEY_LEN) + error = CPL_ERROR_FILE_IO; } cpl_free(paf_id); if (!error) { nlen = fprintf(paf, "PAF.NAME \"%s\"\n", filename); - if (nlen <= PAF_KEY_LEN) error = CPL_ERROR_FILE_IO; + if (nlen <= PAF_KEY_LEN) + error = CPL_ERROR_FILE_IO; } if (!error) { nlen = fprintf(paf, "PAF.DESC \"%s\"\n", paf_desc); - if (nlen <= PAF_KEY_LEN) error = CPL_ERROR_FILE_IO; + if (nlen <= PAF_KEY_LEN) + error = CPL_ERROR_FILE_IO; } if (!error) { nlen = fprintf(paf, "PAF.CHCK.CHECKSUM \"\"\n"); - if (nlen <= PAF_KEY_LEN) error = CPL_ERROR_FILE_IO; + if (nlen <= PAF_KEY_LEN) + error = CPL_ERROR_FILE_IO; } if (!error) { nlen = fprintf(paf, "PAF.HDR.END ;# end of header\n"); - if (nlen <= PAF_KEY_LEN) error = CPL_ERROR_FILE_IO; + if (nlen <= PAF_KEY_LEN) + error = CPL_ERROR_FILE_IO; } if (!error) { nlen = fprintf(paf, "\n"); - if (nlen != 1) error = CPL_ERROR_FILE_IO; + if (nlen != 1) + error = CPL_ERROR_FILE_IO; } if (error) { @@ -2174,13 +2285,13 @@ (void)fclose(paf); paf = NULL; } - (void)cpl_error_set_message_(error, "Could not write PAF, instrume=%s, " - "recipe=%s, filename=%s", instrume, - recipe, filename); + (void)cpl_error_set_message_(error, + "Could not write PAF, instrume=%s, " + "recipe=%s, filename=%s", + instrume, recipe, filename); } return paf; - } /*----------------------------------------------------------------------------*/ @@ -2214,52 +2325,57 @@ */ /*----------------------------------------------------------------------------*/ -static -cpl_error_code cpl_dfs_paf_dump(const cpl_propertylist * self, FILE * paf) +static cpl_error_code +cpl_dfs_paf_dump(const cpl_propertylist *self, FILE *paf) { const cpl_size nproperties = cpl_propertylist_get_size(self); cpl_size i; cpl_ensure_code(self, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(paf, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(paf, CPL_ERROR_NULL_INPUT); - for (i=0; i < nproperties; i++) { - const cpl_property * prop = cpl_propertylist_get_const(self, i); - const char * name = cpl_property_get_name(prop); - const char * comment = cpl_property_get_comment(prop); - const char * usekey; - const char * usecom; - char * qckey = NULL; - char * qccom = NULL; + for (i = 0; i < nproperties; i++) { + const cpl_property *prop = cpl_propertylist_get_const(self, i); + const char *name = cpl_property_get_name(prop); + const char *comment = cpl_property_get_comment(prop); + const char *usekey; + const char *usecom; + char *qckey = NULL; + char *qccom = NULL; /* Initialization needed in absence of #if for CPL_TYPE_LONG */ cpl_error_code err = CPL_ERROR_UNSUPPORTED_MODE; if (strstr(name, "ESO ") == name) { /* Drop prefix "ESO " */ - qckey = cpl_sprintf("%s", name+4); - } else if (strchr(name, ' ')) { + qckey = cpl_sprintf("%s", name + 4); + } + else if (strchr(name, ' ')) { qckey = cpl_strdup(name); } if (qckey != NULL) { /* Replace with . */ - char * p; + char *p; for (p = qckey; *p != '\0'; p++) - if (*p == ' ') *p = '.'; + if (*p == ' ') + *p = '.'; usekey = qckey; - } else { + } + else { usekey = name; } if (comment != NULL && strchr(comment, '\n')) { - char * p; + char *p; /* Replace line-feed with space */ qccom = cpl_strdup(comment); for (p = qccom; *p != '\0'; p++) - if (*p == '\n') *p = ' '; + if (*p == '\n') + *p = ' '; usecom = qccom; - } else { + } + else { usecom = comment; } @@ -2267,47 +2383,51 @@ /* Print the property as PAF */ switch (cpl_property_get_type(prop)) { - case CPL_TYPE_CHAR: - err = cpl_dfs_paf_dump_int(usekey, cpl_property_get_char(prop), - usecom, paf); - break; - case CPL_TYPE_BOOL: - err = cpl_dfs_paf_dump_int(usekey, cpl_property_get_bool(prop), - usecom, paf); - break; - case CPL_TYPE_INT: - err = cpl_dfs_paf_dump_int(usekey, cpl_property_get_int(prop), - usecom, paf); - break; - case CPL_TYPE_LONG: - err = cpl_dfs_paf_dump_int(usekey, cpl_property_get_long(prop), - usecom, paf); - break; - case CPL_TYPE_LONG_LONG: - err = cpl_dfs_paf_dump_int(usekey, cpl_property_get_long_long(prop), - usecom, paf); - break; - case CPL_TYPE_FLOAT: - err = cpl_dfs_paf_dump_double(usekey, cpl_property_get_float(prop), - usecom, paf); - break; - case CPL_TYPE_DOUBLE: - err = cpl_dfs_paf_dump_double(usekey, cpl_property_get_double(prop), - usecom, paf); - break; - case CPL_TYPE_STRING: - err = cpl_dfs_paf_dump_string(usekey, cpl_property_get_string(prop), - usecom, paf); - break; - default: - err = CPL_ERROR_UNSUPPORTED_MODE; + case CPL_TYPE_CHAR: + err = cpl_dfs_paf_dump_int(usekey, cpl_property_get_char(prop), + usecom, paf); + break; + case CPL_TYPE_BOOL: + err = cpl_dfs_paf_dump_int(usekey, cpl_property_get_bool(prop), + usecom, paf); + break; + case CPL_TYPE_INT: + err = cpl_dfs_paf_dump_int(usekey, cpl_property_get_int(prop), + usecom, paf); + break; + case CPL_TYPE_LONG: + err = cpl_dfs_paf_dump_int(usekey, cpl_property_get_long(prop), + usecom, paf); + break; + case CPL_TYPE_LONG_LONG: + err = cpl_dfs_paf_dump_int(usekey, + cpl_property_get_long_long(prop), + usecom, paf); + break; + case CPL_TYPE_FLOAT: + err = cpl_dfs_paf_dump_double(usekey, + cpl_property_get_float(prop), + usecom, paf); + break; + case CPL_TYPE_DOUBLE: + err = cpl_dfs_paf_dump_double(usekey, + cpl_property_get_double(prop), + usecom, paf); + break; + case CPL_TYPE_STRING: + err = cpl_dfs_paf_dump_string(usekey, + cpl_property_get_string(prop), + usecom, paf); + break; + default: + err = CPL_ERROR_UNSUPPORTED_MODE; } cpl_free(qckey); cpl_free(qccom); - if (err) return cpl_error_set_(err); - + if (err) + return cpl_error_set_(err); } return CPL_ERROR_NONE; @@ -2327,21 +2447,23 @@ - CPL_ERROR_FILE_IO if fprintf() fails */ /*----------------------------------------------------------------------------*/ -static cpl_error_code cpl_dfs_paf_dump_string(const char * key, - const char * value, - const char * comment, FILE * paf) +static cpl_error_code +cpl_dfs_paf_dump_string(const char *key, + const char *value, + const char *comment, + FILE *paf) { - cpl_ensure_code(paf, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(key, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(paf, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(key, CPL_ERROR_NULL_INPUT); cpl_ensure_code(value, CPL_ERROR_NULL_INPUT); if (comment == NULL) - cpl_ensure_code(fprintf(paf, PAF_KEY_FORMAT "\"%s\"\n", - key, value) > PAF_KEY_LEN, + cpl_ensure_code(fprintf(paf, PAF_KEY_FORMAT "\"%s\"\n", key, value) > + PAF_KEY_LEN, CPL_ERROR_FILE_IO); else - cpl_ensure_code(fprintf(paf, PAF_KEY_FORMAT "\"%s\" ; # %s\n", - key, value, comment) > PAF_KEY_LEN, + cpl_ensure_code(fprintf(paf, PAF_KEY_FORMAT "\"%s\" ; # %s\n", key, + value, comment) > PAF_KEY_LEN, CPL_ERROR_FILE_IO); return CPL_ERROR_NONE; @@ -2360,27 +2482,28 @@ */ /*----------------------------------------------------------------------------*/ -static cpl_error_code cpl_dfs_paf_dump_double(const char * key, - double value, - const char * comment, FILE * paf) +static cpl_error_code +cpl_dfs_paf_dump_double(const char *key, + double value, + const char *comment, + FILE *paf) { - cpl_ensure_code(paf, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(key, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(paf, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(key, CPL_ERROR_NULL_INPUT); /* The number of decimals for double keywords in CFITSIO is 15 * (see putkey.c in cfitsio). So we match here that number not to * lose precision */ if (comment == NULL) - cpl_ensure_code(fprintf(paf, PAF_KEY_FORMAT "%.15g\n", - key, value) > PAF_KEY_LEN, + cpl_ensure_code(fprintf(paf, PAF_KEY_FORMAT "%.15g\n", key, value) > + PAF_KEY_LEN, CPL_ERROR_FILE_IO); else - cpl_ensure_code(fprintf(paf, PAF_KEY_FORMAT "%.15g ; # %s\n", - key, value, comment) > PAF_KEY_LEN, + cpl_ensure_code(fprintf(paf, PAF_KEY_FORMAT "%.15g ; # %s\n", key, + value, comment) > PAF_KEY_LEN, CPL_ERROR_FILE_IO); return CPL_ERROR_NONE; - } /*----------------------------------------------------------------------------*/ @@ -2395,28 +2518,29 @@ */ /*----------------------------------------------------------------------------*/ -static cpl_error_code cpl_dfs_paf_dump_int(const char * key, cpl_size value, - const char * comment, FILE * paf) +static cpl_error_code +cpl_dfs_paf_dump_int(const char *key, + cpl_size value, + const char *comment, + FILE *paf) { - cpl_ensure_code(paf, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(key, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(paf, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(key, CPL_ERROR_NULL_INPUT); if (comment == NULL) cpl_ensure_code(fprintf(paf, PAF_KEY_FORMAT "%" CPL_SIZE_FORMAT "\n", key, value) > PAF_KEY_LEN, CPL_ERROR_FILE_IO); else - cpl_ensure_code(fprintf(paf, PAF_KEY_FORMAT "%" CPL_SIZE_FORMAT - "; # %s\n", key, value, comment) > PAF_KEY_LEN, + cpl_ensure_code(fprintf(paf, + PAF_KEY_FORMAT "%" CPL_SIZE_FORMAT "; # %s\n", + key, value, comment) > PAF_KEY_LEN, CPL_ERROR_FILE_IO); return CPL_ERROR_NONE; - } - - /*----------------------------------------------------------------------------*/ /** @internal @@ -2444,39 +2568,40 @@ */ /*----------------------------------------------------------------------------*/ -static cpl_error_code cpl_dfs_product_save(cpl_frameset * allframes, - cpl_propertylist * header, - const cpl_parameterlist * parlist, - const cpl_frameset * usedframes, - const cpl_frame * inherit, - const cpl_imagelist * imagelist, - const cpl_image * image, - cpl_type type, - const cpl_table * table, - const cpl_propertylist * tablelist, - const char * recipe, - const cpl_propertylist * applist, - const char * remregexp, - const char * pipe_id, - const char * filename) { - - const char * procat; - cpl_propertylist * plist; - cpl_frame * product_frame; +static cpl_error_code +cpl_dfs_product_save(cpl_frameset *allframes, + cpl_propertylist *header, + const cpl_parameterlist *parlist, + const cpl_frameset *usedframes, + const cpl_frame *inherit, + const cpl_imagelist *imagelist, + const cpl_image *image, + cpl_type type, + const cpl_table *table, + const cpl_propertylist *tablelist, + const char *recipe, + const cpl_propertylist *applist, + const char *remregexp, + const char *pipe_id, + const char *filename) +{ + const char *procat; + cpl_propertylist *plist; + cpl_frame *product_frame; /* Inside this function the product-types are numbered: 0: imagelist 1: table 2: image 3: propertylist only */ - const unsigned pronum - = imagelist != NULL ? 0 : table != NULL ? 1 : (image != NULL ? 2 : 3); - const char * proname[] = {"imagelist", "table", "image", - "propertylist"}; + const unsigned pronum = imagelist != NULL ? 0 + : table != NULL ? 1 + : (image != NULL ? 2 : 3); + const char *proname[] = { "imagelist", "table", "image", "propertylist" }; /* FIXME: Define a frame type for an imagelist and when data-less */ - const int protype[] = {CPL_FRAME_TYPE_ANY, CPL_FRAME_TYPE_TABLE, - CPL_FRAME_TYPE_IMAGE, CPL_FRAME_TYPE_ANY}; - cpl_error_code error = CPL_ERROR_NONE; + const int protype[] = { CPL_FRAME_TYPE_ANY, CPL_FRAME_TYPE_TABLE, + CPL_FRAME_TYPE_IMAGE, CPL_FRAME_TYPE_ANY }; + cpl_error_code error = CPL_ERROR_NONE; /* No more than one of imagelist, table and image may be non-NULL */ @@ -2486,16 +2611,19 @@ assert(image == NULL); assert(table == NULL); assert(tablelist == NULL); - } else if (table != NULL) { + } + else if (table != NULL) { assert(pronum == 1); assert(imagelist == NULL); assert(image == NULL); - } else if (image != NULL) { + } + else if (image != NULL) { assert(pronum == 2); assert(imagelist == NULL); assert(table == NULL); assert(tablelist == NULL); - } else { + } + else { assert(pronum == 3); assert(imagelist == NULL); assert(table == NULL); @@ -2503,17 +2631,17 @@ assert(image == NULL); } - cpl_ensure_code(allframes != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(parlist != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(allframes != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(parlist != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(usedframes != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(recipe != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(applist != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(pipe_id != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(filename != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(recipe != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(applist != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(pipe_id != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(filename != NULL, CPL_ERROR_NULL_INPUT); procat = cpl_propertylist_get_string(applist, CPL_DFS_PRO_CATG); - cpl_ensure_code(procat != NULL, cpl_error_get_code()); + cpl_ensure_code(procat != NULL, cpl_error_get_code()); cpl_msg_info(cpl_func, "Writing FITS %s product(%s): %s", proname[pronum], procat, filename); @@ -2536,7 +2664,8 @@ if (header != NULL) { cpl_propertylist_empty(header); plist = header; - } else { + } + else { plist = cpl_propertylist_new(); } @@ -2552,7 +2681,8 @@ if (remregexp != NULL && !error) { cpl_errorstate prestate = cpl_errorstate_get(); (void)cpl_propertylist_erase_regexp(plist, remregexp, 0); - if (!cpl_errorstate_is_equal(prestate)) error = cpl_error_get_code(); + if (!cpl_errorstate_is_equal(prestate)) + error = cpl_error_get_code(); } if (!error) { @@ -2566,8 +2696,8 @@ CPL_IO_CREATE); break; case 2: - error = cpl_image_save(image, filename, type, plist, - CPL_IO_CREATE); + error = + cpl_image_save(image, filename, type, plist, CPL_IO_CREATE); break; default: /* case 3: */ @@ -2578,16 +2708,16 @@ if (!error) { /* Insert the frame of the saved file in the input frameset */ error = cpl_frameset_insert(allframes, product_frame); - - } else { + } + else { cpl_frame_delete(product_frame); } - if (plist != header) cpl_propertylist_delete(plist); + if (plist != header) + cpl_propertylist_delete(plist); return error ? cpl_error_set_where_() : CPL_ERROR_NONE; - -} +} #if defined CFITSIO_MAJOR && (CFITSIO_MAJOR > 3 || CFITSIO_MINOR >= 26) /* Not needed from 3.26 */ @@ -2613,18 +2743,17 @@ */ /*----------------------------------------------------------------------------*/ -static char * cpl_dfs_extract_printable(const char * self) +static char * +cpl_dfs_extract_printable(const char *self) { - - char * card = NULL; + char *card = NULL; if (self != NULL) { int ii; card = cpl_strdup(self); - for (ii = 0; ; ii++) { - + for (ii = 0;; ii++) { /* Transform various white-space characters to a space */ /* The if-statements have been copied from fftrec() in fitscore.c */ if (card[ii] == 9) @@ -2639,8 +2768,8 @@ card[ii] = ' '; else /* All of the above cases are OK and need no check below */ - /* This line has been copied from fftrec() in fitscore.c */ - if (card[ii] < 32 || card[ii] > 126) + /* This line has been copied from fftrec() in fitscore.c */ + if (card[ii] < 32 || card[ii] > 126) break; /* Will at the latest break on the NULL-terminator */ } card[ii] = '\0'; diff -Nru cpl-7.1.4+ds/cpldfs/cpl_dfs.h cpl-7.2.2+ds/cpldfs/cpl_dfs.h --- cpl-7.1.4+ds/cpldfs/cpl_dfs.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cpldfs/cpl_dfs.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -34,7 +34,7 @@ -----------------------------------------------------------------------------*/ #define CPL_DFS_FITS ".fits" -#define CPL_DFS_PAF ".paf" +#define CPL_DFS_PAF ".paf" /*----------------------------------------------------------------------------*/ @@ -90,21 +90,22 @@ * product files. The values may be combined using bitwise or. */ -enum { +enum +{ /** * Do not compute any signatures * @hideinitializer */ - CPL_DFS_SIGNATURE_NONE = 0, + CPL_DFS_SIGNATURE_NONE = 0, /** * Compute the DATAMD5 data hash * @hideinitializer */ - CPL_DFS_SIGNATURE_DATAMD5 = 1 << 0, + CPL_DFS_SIGNATURE_DATAMD5 = 1 << 0, /** * Compute FITS standard CHECKSUM and DATASUM @@ -169,13 +170,15 @@ const char *, const char *); -cpl_error_code cpl_dfs_save_paf(const char *, const char *, - const cpl_propertylist *, const char *); - -cpl_error_code cpl_dfs_setup_product_header(cpl_propertylist *, - const cpl_frame *, - const cpl_frameset *, - const cpl_parameterlist *, +cpl_error_code cpl_dfs_save_paf(const char *, + const char *, + const cpl_propertylist *, + const char *); + +cpl_error_code cpl_dfs_setup_product_header(cpl_propertylist *, + const cpl_frame *, + const cpl_frameset *, + const cpl_parameterlist *, const char *, const char *, const char *, @@ -183,8 +186,8 @@ cpl_error_code cpl_dfs_update_product_header(cpl_frameset *); -cpl_error_code cpl_dfs_sign_products(const cpl_frameset *set, - unsigned int flags); +cpl_error_code +cpl_dfs_sign_products(const cpl_frameset *set, unsigned int flags); CPL_END_DECLS diff -Nru cpl-7.1.4+ds/cpldfs/cpl_multiframe.c cpl-7.2.2+ds/cpldfs/cpl_multiframe.c --- cpl-7.1.4+ds/cpldfs/cpl_multiframe.c 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cpldfs/cpl_multiframe.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -18,7 +18,7 @@ */ #ifdef HAVE_CONFIG_H -# include +#include #endif @@ -49,13 +49,12 @@ struct _cpl_regex_ { - regex _m_re; - flag_type _m_flags; - cxbool _m_negated; + regex _m_re; + flag_type _m_flags; + cxbool _m_negated; }; - /** * @brief * Create a new regular expression filter. @@ -84,11 +83,9 @@ cpl_regex * cpl_regex_new(const char *expression, int negated, flag_type flags) { - cpl_regex *self = cx_malloc(sizeof *self); if (self) { - cxint _flags = REG_NOSUB; @@ -101,15 +98,12 @@ } if ((flags & CPL_REGEX_BASIC) && (flags & CPL_REGEX_EXTENDED)) { - cx_free(self); cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); return NULL; - } else { - if (flags & CPL_REGEX_BASIC) { _flags = _flags & ~REG_EXTENDED; } @@ -117,7 +111,6 @@ if (flags & CPL_REGEX_EXTENDED) { _flags = _flags | REG_EXTENDED; } - } @@ -131,11 +124,9 @@ self->_m_flags = flags | CPL_REGEX_NOSUBS; self->_m_negated = negated ? TRUE : FALSE; } - } return self; - } @@ -156,14 +147,12 @@ void cpl_regex_delete(cpl_regex *self) { - if (self) { regfree(&self->_m_re); cx_free(self); } return; - } @@ -189,14 +178,12 @@ int cpl_regex_apply(const cpl_regex *self, const char *string) { - cxint status = regexec(&self->_m_re, string, 0, 0, 0); cxbool match = (status == REG_NOMATCH) ? FALSE : TRUE; return self->_m_negated ? !match : match; - } @@ -242,7 +229,6 @@ /**@}*/ - // DICB FITS keyword ranking typedef struct _cpl_dicb_header_order_ cpl_dicb_header_order; @@ -254,91 +240,41 @@ cxuint rank; }; -static cpl_dicb_header_order _cpl_dicb_primary_ranking[] = -{ - {"SIMPLE ", 7, 0}, - {"XTENSION", 8, 0}, - {"BITPIX ", 7, 10}, - {"NAXIS ", 6, 11}, - {"NAXIS", 5, 12}, - {"GROUP ", 6, 20}, - {"PCOUNT ", 7, 30}, - {"GCOUNT ", 7, 31}, - {"EXTEND ", 7, 32}, - {"BZERO ", 6, 33}, - {"BSCALE ", 7, 34}, - {"BUNIT ", 6, 35}, - {"BLANK ", 6, 36}, - {"TFIELDS ", 8, 37}, - {"TBCOL", 5, 38}, - {"TFORM", 5, 39}, - {"TUNIT", 5, 40}, - {"INSTRUME", 8, 100}, - {"TELESCOP", 8, 101}, - {"OBJECT ", 7, 102}, - {"ORIGIN ", 7, 103}, - {"PI-COI ", 7, 104}, - {"EXPTIME ", 8, 105}, - {"RA ", 3, 106}, - {"DEC ", 4, 107}, - {"EQUINOX ", 8, 108}, - {"RADECSYS", 8, 109}, - {"MJD-OBS ", 8, 110}, - {"DATE-OBS", 8, 111}, - {"TIMESYS ", 8, 112}, - {"LST ", 4, 113}, - {"UTC ", 4, 114}, - {"WCSAXES ", 8, 200}, - {"CTYPE", 5, 201}, - {"CRVAL", 5, 202}, - {"CRPIX", 5, 203}, - {"CD", 2, 204}, - {"CUNIT", 5, 205}, - {"CUNIT", 5, 205}, - {"HDUCLASS", 8, 500}, - {"HDUCLAS", 7, 501}, - {"HDUDOC ", 7, 502}, - {"HDUVERS ", 7, 503}, - {"SCIDATA ", 7, 504}, - {"ERRDATA ", 7, 505}, - {"QUALDATA", 8, 506}, - {"QUALMASK", 8, 506}, - {"ORIGFILE", 8, 600}, - {"PIPEFILE", 8, 601}, - {"ARCFILE ", 8, 602}, - {"ZHECKSUM", 8, 700}, - {"DATASUM ", 8, 701}, - {"ZDATASUM", 8, 701}, - {"DATAMD5 ", 8, 702}, - {"INHERIT ", 8, 800}, - {"HISTORY ", 8, 1001}, - {"COMMENT ", 8, 1002}, - {" ", 8, 1003} +static cpl_dicb_header_order _cpl_dicb_primary_ranking[] = { + { "SIMPLE ", 7, 0 }, { "XTENSION", 8, 0 }, { "BITPIX ", 7, 10 }, + { "NAXIS ", 6, 11 }, { "NAXIS", 5, 12 }, { "GROUP ", 6, 20 }, + { "PCOUNT ", 7, 30 }, { "GCOUNT ", 7, 31 }, { "EXTEND ", 7, 32 }, + { "BZERO ", 6, 33 }, { "BSCALE ", 7, 34 }, { "BUNIT ", 6, 35 }, + { "BLANK ", 6, 36 }, { "TFIELDS ", 8, 37 }, { "TBCOL", 5, 38 }, + { "TFORM", 5, 39 }, { "TUNIT", 5, 40 }, { "INSTRUME", 8, 100 }, + { "TELESCOP", 8, 101 }, { "OBJECT ", 7, 102 }, { "ORIGIN ", 7, 103 }, + { "PI-COI ", 7, 104 }, { "EXPTIME ", 8, 105 }, { "RA ", 3, 106 }, + { "DEC ", 4, 107 }, { "EQUINOX ", 8, 108 }, { "RADESYS", 7, 109 }, + { "RADECSYS", 8, 109 }, { "MJD-OBS ", 8, 110 }, { "DATE-OBS", 8, 111 }, + { "TIMESYS ", 8, 112 }, { "LST ", 4, 113 }, { "UTC ", 4, 114 }, + { "WCSAXES ", 8, 200 }, { "CTYPE", 5, 201 }, { "CRVAL", 5, 202 }, + { "CRPIX", 5, 203 }, { "CD", 2, 204 }, { "CUNIT", 5, 205 }, + { "CUNIT", 5, 205 }, { "HDUCLASS", 8, 500 }, { "HDUCLAS", 7, 501 }, + { "HDUDOC ", 7, 502 }, { "HDUVERS ", 7, 503 }, { "SCIDATA ", 7, 504 }, + { "ERRDATA ", 7, 505 }, { "QUALDATA", 8, 506 }, { "QUALMASK", 8, 506 }, + { "ORIGFILE", 8, 600 }, { "PIPEFILE", 8, 601 }, { "ARCFILE ", 8, 602 }, + { "ZHECKSUM", 8, 700 }, { "DATASUM ", 8, 701 }, { "ZDATASUM", 8, 701 }, + { "DATAMD5 ", 8, 702 }, { "INHERIT ", 8, 800 }, { "HISTORY ", 8, 1001 }, + { "COMMENT ", 8, 1002 }, { " ", 8, 1003 } }; -static cpl_dicb_header_order _cpl_dicb_hierarch_ranking[] = -{ - {"ESO DPR ", 8, 900}, - {"ESO OBS ", 8, 901}, - {"ESO TPL ", 8, 902}, - {"ESO GEN ", 8, 903}, - {"ESO TEL ", 8, 904}, - {"ESO ADA ", 8, 905}, - {"ESO INS ", 8, 906}, - {"ESO DET ", 8, 907}, - {"ESO DET1 ", 9, 907}, - {"ESO DET2 ", 9, 908}, - {"ESO PRO ", 8, 909}, - {"ESO LOG ", 8, 910}, - {"ESO QC ", 7, 911}, - {"ESO DRS ", 8, 912} +static cpl_dicb_header_order _cpl_dicb_hierarch_ranking[] = { + { "ESO DPR ", 8, 900 }, { "ESO OBS ", 8, 901 }, { "ESO TPL ", 8, 902 }, + { "ESO GEN ", 8, 903 }, { "ESO TEL ", 8, 904 }, { "ESO ADA ", 8, 905 }, + { "ESO INS ", 8, 906 }, { "ESO DET ", 8, 907 }, { "ESO DET1 ", 9, 907 }, + { "ESO DET2 ", 9, 908 }, { "ESO PRO ", 8, 909 }, { "ESO LOG ", 8, 910 }, + { "ESO QC ", 7, 911 }, { "ESO DRS ", 8, 912 } }; inline static cxuint _cpl_dicb_header_get_keyword_rank(const cxchar *cstr) { - cxuint rank = 0; cxsize ngroups; @@ -347,14 +283,11 @@ if (strncmp(cstr, "HIERARCH ", 9) != 0) { - rank = 899; ranks = _cpl_dicb_primary_ranking; ngroups = CX_N_ELEMENTS(_cpl_dicb_primary_ranking); - } else { - /* * add byte offset to skip 'HIERARCH ' prefix in header cards. */ @@ -364,23 +297,19 @@ rank = 999; ranks = _cpl_dicb_hierarch_ranking; ngroups = CX_N_ELEMENTS(_cpl_dicb_hierarch_ranking); - } cxsize ig; for (ig = 0; ig < ngroups; ++ig) { - if (strncmp(cstr, ranks[ig].key, ranks[ig].length) == 0) { rank = ranks[ig].rank; break; } - } return rank; - } @@ -394,7 +323,6 @@ #include - typedef struct _cpl_fitscard_ cpl_fitscard; struct _cpl_fitscard_ @@ -407,13 +335,12 @@ static const cxchar *const _cpl_fits_keyword_traits = - "._-ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + "._-ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; inline static cxint _cpl_fits_parse_keyname(cx_string *keyname, const cxchar *name) { - cxsize length = strlen(name); cx_string *_keyname; @@ -429,34 +356,29 @@ _keyname = cx_string_create("HISTORY "); } else if (strncmp(name, "HIERARCH ", 9) == 0) { - if (length <= 9) { return -1; } _keyname = cx_string_create(name); - cx_string_replace_character(_keyname, 9, cx_string_size(_keyname), - '.', ' '); + cx_string_replace_character(_keyname, 9, cx_string_size(_keyname), '.', + ' '); if (cx_string_get(_keyname)[length - 1] != ' ') { cx_string_append(_keyname, " "); } - } else if ((strchr(name, ' ') != 0) || (strchr(name, '.') != 0)) { - _keyname = cx_string_create("HIERARCH "); cx_string_append(_keyname, name); - cx_string_replace_character(_keyname, 0, cx_string_size(_keyname), - '.', ' '); + cx_string_replace_character(_keyname, 0, cx_string_size(_keyname), '.', + ' '); if (cx_string_get(_keyname)[cx_string_size(_keyname) - 1] != ' ') { cx_string_append(_keyname, " "); } - } else { - if (strlen(name) > 8) { return -2; } @@ -468,21 +390,18 @@ if (padding > 0) { cx_string_extend(_keyname, padding, ' '); } - } cx_string_set(keyname, cx_string_get(_keyname)); cx_string_delete(_keyname); return 0; - } inline static cxint _cpl_fits_get_keyname(const cxchar *card, cx_string *keyname, int *status) { - if (*status) { return *status; } @@ -502,15 +421,15 @@ } return *status; - } inline static cxint -_cpl_fits_format_card(cx_string *record, const cxchar *keyname, - const cxchar *value, const cxchar *comment) +_cpl_fits_format_card(cx_string *record, + const cxchar *keyname, + const cxchar *value, + const cxchar *comment) { - if (strlen(keyname) == 0) { return -1; } @@ -528,93 +447,83 @@ } - cxbool has_value = value != NULL; + cxbool has_value = value != NULL; cxbool has_comment = (comment != NULL) && (strlen(comment) > 0); - cxbool is_comment = FALSE; + cxbool is_comment = FALSE; /* * Fill in the keyword name */ - cx_string *_record = cx_string_create(keyname); + cx_string *_record = cx_string_create(keyname); - if (strncmp(keyname, " ", 8) == 0) { - is_comment = TRUE; - } - else if (strncmp(keyname, "COMMENT", 7) == 0) { - is_comment = TRUE; - } - else if (strncmp(keyname, "HISTORY", 7) == 0) { - is_comment = TRUE; - } + if (strncmp(keyname, " ", 8) == 0) { + is_comment = TRUE; + } + else if (strncmp(keyname, "COMMENT", 7) == 0) { + is_comment = TRUE; + } + else if (strncmp(keyname, "HISTORY", 7) == 0) { + is_comment = TRUE; + } - /* + /* * Add value indicator if needed */ - if (!is_comment) { - cx_string_append(_record, "= "); - } + if (!is_comment) { + cx_string_append(_record, "= "); + } - /* + /* * Add the value if it is present */ - if (has_value) { - - cxsize length = strlen(value); + if (has_value) { + cxsize length = strlen(value); - if (value[0] == '\'') { - - if (value[length - 1] != '\'') { - cx_string_delete(_record); - return -5; - } + if (value[0] == '\'') { + if (value[length - 1] != '\'') { + cx_string_delete(_record); + return -5; + } - cxchar *_s = cx_calloc(length - 1, sizeof(cxchar)); - memcpy(_s, &value[1], length - 2); + cxchar *_s = cx_calloc(length - 1, sizeof(cxchar)); + memcpy(_s, &value[1], length - 2); - cx_string *s = cx_string_create(_s); + cx_string *s = cx_string_create(_s); - cx_free(_s); + cx_free(_s); - _s = (cxchar *)cx_string_get(s); + _s = (cxchar *)cx_string_get(s); - /* + /* * Expand single quote characters if necessary */ - while ((_s = strchr(_s, '\'')) != NULL) { - - cxsize pos = _s - cx_string_get(s); - - if (pos == cx_string_size(s) - 1) { - - cx_string_append(s, "'"); - _s = (cxchar *)cx_string_get(s) + pos + 1; - - } - else { - - if (*(_s + 1) != '\'') { - - cx_string_insert(s, pos, "'"); - _s = (cxchar *)cx_string_get(s) + pos + 2; - - } - - } + while ((_s = strchr(_s, '\'')) != NULL) { + cxsize pos = _s - cx_string_get(s); - } + if (pos == cx_string_size(s) - 1) { + cx_string_append(s, "'"); + _s = (cxchar *)cx_string_get(s) + pos + 1; + } + else { + if (*(_s + 1) != '\'') { + cx_string_insert(s, pos, "'"); + _s = (cxchar *)cx_string_get(s) + pos + 2; + } + } + } - /* + /* * Fixed format strings are required to have at least 8 * characters. Thus they may have to be padded with spaces. * This does not actually apply to hierarchical keywords, @@ -625,47 +534,41 @@ * Therefore the padding is applied here to all string values. */ - cxint padding = 8 - cx_string_size(s); - - if (padding > 0) { - cx_string_extend(s, padding, ' '); - } - - cx_string_append(_record, "'"); - cx_string_append(_record, cx_string_get(s)); - cx_string_append(_record, "'"); - - cx_string_delete(s); + cxint padding = 8 - cx_string_size(s); - } - else if (value[0] == '(') { - - if (value[length - 1] != ')') { - return -6; - } - - cx_string_append(_record, value); + if (padding > 0) { + cx_string_extend(s, padding, ' '); + } - } - else if ((value[0] == 'T' || value[0] == 'F') && (length == 1)) { + cx_string_append(_record, "'"); + cx_string_append(_record, cx_string_get(s)); + cx_string_append(_record, "'"); + + cx_string_delete(s); + } + else if (value[0] == '(') { + if (value[length - 1] != ')') { + return -6; + } - /* + cx_string_append(_record, value); + } + else if ((value[0] == 'T' || value[0] == 'F') && (length == 1)) { + /* * The value of a logical keyword must appear in byte 30 * of the card. */ - cxint padding = 29 - cx_string_size(_record); - - if (padding > 0) { - cx_string_extend(_record, padding, ' '); - } - - cx_string_append(_record, value); + cxint padding = 29 - cx_string_size(_record); - } - else { + if (padding > 0) { + cx_string_extend(_record, padding, ' '); + } - /* + cx_string_append(_record, value); + } + else { + /* * Fixed format numerical values occupy the bytes 11 through 30, * and they are right justified in that field. Free format * numerical values may appear anywhere starting at byte 11. @@ -675,73 +578,63 @@ * This behavior is replicated here. */ - cxint padding = 30 - cx_string_size(_record) - length; - - if (padding > 0) { - cx_string_extend(_record, padding, ' '); - } + cxint padding = 30 - cx_string_size(_record) - length; - cx_string_append(_record, value); - - } + if (padding > 0) { + cx_string_extend(_record, padding, ' '); + } - if (cx_string_size(_record) > FLEN_CARD - 1) { - cx_string_delete(_record); - return -7; - } + cx_string_append(_record, value); + } - } + if (cx_string_size(_record) > FLEN_CARD - 1) { + cx_string_delete(_record); + return -7; + } + } - /* + /* * Add the optional comment */ - if (has_comment) { - - if (is_comment) { - cx_string_append(_record, comment); - } - else { - - /* + if (has_comment) { + if (is_comment) { + cx_string_append(_record, comment); + } + else { + /* * The keyword comment indicator ' / ' should appear in byte 32 * of the card, or later. If no character of the comment would * appear in the final card, due to its size constraint, the whole * comment, including the comment indicator, is dropped. */ - if ((FLEN_CARD - 1) - cx_string_size(_record) > 3) { - - cxint padding = 30 - cx_string_size(_record); - - if (padding > 0) { - cx_string_extend(_record, padding, ' '); - } + if ((FLEN_CARD - 1) - cx_string_size(_record) > 3) { + cxint padding = 30 - cx_string_size(_record); - cx_string_append(_record, " / "); - cx_string_append(_record, comment); - - } - - } - - } + if (padding > 0) { + cx_string_extend(_record, padding, ' '); + } - cx_string_truncate(_record, FLEN_CARD); - cx_string_set(record, cx_string_get(_record)); + cx_string_append(_record, " / "); + cx_string_append(_record, comment); + } + } + } - cx_string_delete(_record); + cx_string_truncate(_record, FLEN_CARD); + cx_string_set(record, cx_string_get(_record)); - return 0; + cx_string_delete(_record); + return 0; } inline static cxssize _cpl_fitsfile_find_extension(fitsfile *file, const cxchar *name, cxsize version) { - cxint status = 0; cxint chdu = -1; @@ -755,15 +648,14 @@ fits_get_hdu_num(file, &chdu); return chdu - 1; - } inline static cxssize -_cpl_fits_find_extension(const cxchar *filename, const cxchar *name, +_cpl_fits_find_extension(const cxchar *filename, + const cxchar *name, cxsize version) { - cxint status = 0; cxssize chdu = -1; @@ -781,40 +673,33 @@ fits_close_file(fp, &status); return chdu; - } inline static cpl_fitscard * _cpl_fitscard_new(const cxchar *record) { - cpl_fitscard *self = NULL; if (record && (strlen(record) < FLEN_CARD)) { - self = cx_malloc(sizeof *self); self->_m_record = cx_string_create(record); - } return self; - } inline static void _cpl_fitscard_delete(cpl_fitscard *self) { - if (self) { cx_string_delete(self->_m_record); cx_free(self); } return; - } @@ -829,7 +714,6 @@ inline static cpl_fitscard * _cpl_fitscard_set_card(cpl_fitscard *self, const cxchar *record) { - cx_assert(self != NULL); cx_assert(record != NULL); @@ -840,14 +724,12 @@ cx_string_set(self->_m_record, record); return self; - } inline static cx_string * _cpl_fitscard_get_key(const cpl_fitscard *self) { - cx_assert(self != NULL); @@ -857,22 +739,20 @@ cxint status = 0; - fits_get_keyname((cxchar *)cx_string_get(self->_m_record), keyname, - &keylen, &status); + fits_get_keyname((cxchar *)cx_string_get(self->_m_record), keyname, &keylen, + &status); if (status) { return NULL; } return cx_string_create(keyname); - } inline static cx_string * _cpl_fitscard_get_value(const cpl_fitscard *self) { - cx_assert(self != NULL); @@ -881,23 +761,20 @@ cxint status = 0; - fits_parse_value((cxchar *)cx_string_get(self->_m_record), value, - 0, &status); + fits_parse_value((cxchar *)cx_string_get(self->_m_record), value, 0, + &status); - if (status) - { + if (status) { return NULL; } return cx_string_create(value); - } inline static cx_string * _cpl_fitscard_get_comment(const cpl_fitscard *self) { - cx_assert(self != NULL); @@ -912,23 +789,20 @@ * always be retrieved (as the function name suggests). */ - fits_parse_value((cxchar *)cx_string_get(self->_m_record), value, - comment, &status); + fits_parse_value((cxchar *)cx_string_get(self->_m_record), value, comment, + &status); - if (status) - { + if (status) { return NULL; } return cx_string_create(comment); - } inline static cxint _cpl_fitscard_set_key(cpl_fitscard *self, const cxchar *keyname) { - cx_assert(self != NULL); cx_assert(keyname != NULL); @@ -939,7 +813,8 @@ if ((cx_string_find_first_not_of(_keyname, _cpl_fits_keyword_traits) != - cx_string_size(_keyname)) || (keyname[0] == '.')) { + cx_string_size(_keyname)) || + (keyname[0] == '.')) { return BAD_KEYCHAR; } @@ -962,27 +837,24 @@ cxchar value[FLEN_VALUE]; cxchar comment[FLEN_COMMENT]; - fits_parse_value((cxchar *)cx_string_get(self->_m_record), value, - comment, &status); + fits_parse_value((cxchar *)cx_string_get(self->_m_record), value, comment, + &status); - if (status) - { + if (status) { cx_string_delete(_keyname); return status; } cx_string *record = cx_string_new(); - status = _cpl_fits_format_card(record, cx_string_get(_keyname), - value, comment); + status = + _cpl_fits_format_card(record, cx_string_get(_keyname), value, comment); if (status) { - cx_string_delete(record); cx_string_delete(_keyname); return status; - } cx_string_set(self->_m_record, cx_string_get(record)); @@ -991,15 +863,14 @@ cx_string_delete(_keyname); return 0; - } inline static cxint -_cpl_fitscard_set_value(cpl_fitscard *self, const cxchar *value, +_cpl_fitscard_set_value(cpl_fitscard *self, + const cxchar *value, const cxchar *comment) { - cx_assert(self != NULL); cx_assert(value != NULL); @@ -1019,16 +890,14 @@ cx_string *record = cx_string_new(); - status = _cpl_fits_format_card(record, cx_string_get(keyname), - value, comment); + status = + _cpl_fits_format_card(record, cx_string_get(keyname), value, comment); if (status) { - cx_string_delete(record); cx_string_delete(keyname); return status; - } cx_string_set(self->_m_record, cx_string_get(record)); @@ -1037,14 +906,12 @@ cx_string_delete(keyname); return 0; - } inline static cxint _cpl_fitscard_set_comment(cpl_fitscard *self, const cxchar *comment) { - cx_assert(self != NULL); @@ -1062,11 +929,10 @@ return status; } - fits_parse_value((cxchar *)cx_string_get(self->_m_record), _value, - 0, &status); + fits_parse_value((cxchar *)cx_string_get(self->_m_record), _value, 0, + &status); - if (status) - { + if (status) { cx_string_delete(keyname); return status; } @@ -1074,16 +940,14 @@ cx_string *record = cx_string_new(); - status = _cpl_fits_format_card(record, cx_string_get(keyname), - _value, comment); + status = + _cpl_fits_format_card(record, cx_string_get(keyname), _value, comment); if (status) { - cx_string_delete(record); cx_string_delete(keyname); return status; - } cx_string_set(self->_m_record, cx_string_get(record)); @@ -1092,7 +956,6 @@ cx_string_delete(keyname); return 0; - } @@ -1112,11 +975,9 @@ } return (ra < rb) ? -1 : 1; - } - // FITS header implementation #include @@ -1126,43 +987,37 @@ struct _cpl_fitsheader_ { - cx_deque *_m_records; + cx_deque *_m_records; }; inline static cpl_fitsheader * _cpl_fitsheader_new(void) { - cpl_fitsheader *self = cx_malloc(sizeof *self); if (self) { - self->_m_records = cx_deque_new(); if (!self->_m_records) { cx_free(self); self = NULL; } - } return self; - } inline static cpl_fitsheader * _cpl_fitsheader_duplicate(const cpl_fitsheader *other) { - cx_assert(other != NULL); cpl_fitsheader *self = _cpl_fitsheader_new(); if (self) { - cx_deque *cards = other->_m_records; cxsize ic; @@ -1170,18 +1025,15 @@ for (ic = 0; ic < sz; ++ic) { - cpl_fitscard *card = cx_deque_get(cards, ic); - cpl_fitscard *_card = _cpl_fitscard_new(cx_string_get(_cpl_fitscard_get_card(card))); + cpl_fitscard *_card = + _cpl_fitscard_new(cx_string_get(_cpl_fitscard_get_card(card))); cx_deque_push_back(self->_m_records, _card); - } - } return self; - } @@ -1200,43 +1052,36 @@ inline static cxsize _cpl_fitsheader_get_size(const cpl_fitsheader *self) { - cx_assert(self != NULL); return cx_deque_size(self->_m_records); - } inline static cpl_fitscard * _cpl_fitsheader_get(cpl_fitsheader *self, cxsize irecord) { - cx_assert(self != NULL); cx_assert(irecord < cx_deque_size(self->_m_records)); cpl_fitscard *card = cx_deque_get(self->_m_records, irecord); return card; - } inline static const cpl_fitscard * _cpl_fitsheader_get_const(const cpl_fitsheader *self, cxsize irecord) { - cx_assert(self != NULL); cx_assert(irecord < cx_deque_size(self->_m_records)); return _cpl_fitsheader_get((cpl_fitsheader *)self, irecord); - } inline static cpl_fitscard * _cpl_fitsheader_find(cpl_fitsheader *self, const cxchar *keyname) { - cx_assert(self != NULL); cx_assert(keyname != NULL); @@ -1249,7 +1094,6 @@ for (ic = 0; ic < sz; ++ic) { - cpl_fitscard *_card = cx_deque_get(cards, ic); cx_string *_keyname = _cpl_fitscard_get_key(_card); @@ -1263,30 +1107,25 @@ card = _card; break; } - } return card; - } inline static const cpl_fitscard * _cpl_fitsheader_find_const(const cpl_fitsheader *self, const cxchar *keyname) { - cx_assert(self != NULL); cx_assert(keyname != NULL); return _cpl_fitsheader_find((cpl_fitsheader *)self, keyname); - } inline static cxsize _cpl_fitsheader_find_card(const cpl_fitsheader *self, const cpl_fitscard *card) { - cx_assert(self != NULL); cx_assert(card != NULL); @@ -1301,7 +1140,6 @@ for (ic = 0; ic < sz; ++ic) { - cpl_fitscard *_card = cx_deque_get(cards, ic); cx_string *_keyname = _cpl_fitscard_get_key(_card); @@ -1315,20 +1153,17 @@ pos = ic; break; } - } cx_string_delete(keyname); return pos; - } inline static cxsize _cpl_fitsheader_get_position(const cpl_fitsheader *self, const cxchar *keyname) { - cx_assert(self != NULL); cx_assert(keyname != NULL); @@ -1340,7 +1175,6 @@ cxsize pos = sz; for (ic = 0; ic < sz; ++ic) { - cpl_fitscard *_card = cx_deque_get(cards, ic); cx_string *_keyname = _cpl_fitscard_get_key(_card); @@ -1354,22 +1188,19 @@ pos = ic; break; } - } return pos; - } inline static cpl_fitsheader * _cpl_fitsheader_create_from_file(fitsfile *file, cxsize position) { - cx_assert(file != NULL); - cxint status = 0; + cxint status = 0; cxint nrecords = 0; @@ -1386,9 +1217,7 @@ cpl_fitsheader *self = _cpl_fitsheader_new(); if (nrecords > 0) { - for (cxint i = 0; i < nrecords; ++i) { - cxchar record[FLEN_CARD]; fits_read_record(file, i + 1, record, &status); @@ -1396,7 +1225,6 @@ if (!status) { cx_deque_push_back(self->_m_records, _cpl_fitscard_new(record)); } - } } @@ -1406,14 +1234,12 @@ } return self; - } inline static cpl_fitsheader * _cpl_fitsheader_create(const cxchar *filename, cxsize position) { - cx_assert(filename != NULL); @@ -1437,7 +1263,6 @@ } return self; - } @@ -1445,7 +1270,6 @@ _cpl_fitsheader_create_from_filter(const cpl_fitsheader *other, const cpl_regex *filter) { - cx_assert(other != NULL); cx_assert(filter != NULL); @@ -1459,46 +1283,37 @@ for (ic = 0; ic < sz; ++ic) { - cpl_fitscard *card = cx_deque_get(cards, ic); const cxchar *record = cx_string_get(_cpl_fitscard_get_card(card)); if (cpl_regex_apply(filter, record)) { - cpl_fitscard *_card = _cpl_fitscard_new(record); cx_deque_push_back(self->_m_records, _card); - } - } return self; - } inline static cxint _cpl_fitsheader_append(cpl_fitsheader *self, cpl_fitscard *card) { - cx_assert(self != NULL); cx_assert(card != NULL); cx_deque_push_back(self->_m_records, card); return 0; - } inline static cxint -_cpl_fitsheader_insert(cpl_fitsheader *self, cpl_fitscard *card, - cxsize irecord) +_cpl_fitsheader_insert(cpl_fitsheader *self, cpl_fitscard *card, cxsize irecord) { - cx_assert(self != NULL); cx_assert(card != NULL); cx_assert(irecord < cx_deque_size(self->_m_records)); @@ -1506,28 +1321,24 @@ cx_deque_insert(self->_m_records, irecord, card); return 0; - } inline static cpl_fitscard * _cpl_fitsheader_remove(cpl_fitsheader *self, cxsize irecord) { - cx_assert(self != NULL); cx_assert(irecord < cx_deque_size(self->_m_records)); cpl_fitscard *card = cx_deque_extract(self->_m_records, irecord); return card; - } inline static cpl_fitscard * _cpl_fitsheader_remove_card(cpl_fitsheader *self, cpl_fitscard *card) { - cx_assert(self != NULL); cx_assert(card != NULL); @@ -1536,14 +1347,12 @@ cpl_fitscard *_card = cx_deque_extract(self->_m_records, irecord); return _card; - } inline static cxint _cpl_fitsheader_join(cpl_fitsheader *self, const cpl_fitsheader *other) { - cx_assert(self != NULL); cx_assert(other != NULL); @@ -1555,7 +1364,6 @@ for (ic = 0; ic < sz; ++ic) { - cpl_fitscard *card = cx_deque_get(cards, ic); const cxchar *record = cx_string_get(_cpl_fitscard_get_card(card)); @@ -1564,25 +1372,21 @@ cx_deque_push_back(self->_m_records, _card); - } return 0; - } inline static cxint _cpl_fitsheader_sort(cpl_fitsheader *self, cpl_fitscard_compare_func cmp) { - cx_assert(self != 0); cx_assert(cmp != NULL); cx_deque_sort(self->_m_records, (cx_compare_func)cmp); return 0; - } @@ -1625,8 +1429,8 @@ enum _cpl_fits_du_type_ { CPL_FITS_DU_TYPE_IMAGE = IMAGE_HDU, - CPL_FITS_DU_TYPE_ATBL = ASCII_TBL, - CPL_FITS_DU_TYPE_BTBL = BINARY_TBL, + CPL_FITS_DU_TYPE_ATBL = ASCII_TBL, + CPL_FITS_DU_TYPE_BTBL = BINARY_TBL, CPL_FITS_DU_TYPE_EMPTY }; @@ -1635,23 +1439,23 @@ struct _cpl_fitsdataunit_ { - fitsfile *_m_file; + fitsfile *_m_file; - cxulong _m_position; - cxint _m_type; + cxulong _m_position; + cxint _m_type; cx_string *_m_name; - cxulong _m_version; - cxulong _m_level; + cxulong _m_version; + cxulong _m_level; - cxint _m_bitpix; - cxlong _m_pcount; - cxlong _m_gcount; + cxint _m_bitpix; + cxlong _m_pcount; + cxlong _m_gcount; - cxulong _m_unitsize; - cxulong _m_datasize; + cxulong _m_unitsize; + cxulong _m_datasize; - cxint _m_naxes; - LONGLONG *_m_naxis; + cxint _m_naxes; + LONGLONG *_m_naxis; /* @@ -1662,15 +1466,11 @@ }; - inline static cxint -_cpl_fits_read_axes(fitsfile *fptr, cxint naxis, LONGLONG *naxes, - cxint *status) +_cpl_fits_read_axes(fitsfile *fptr, cxint naxis, LONGLONG *naxes, cxint *status) { - if (*status == 0) { - - cxchar keyn[FLEN_KEYWORD] = {'N', 'A', 'X', 'I', 'S', '\0'}; + cxchar keyn[FLEN_KEYWORD] = { 'N', 'A', 'X', 'I', 'S', '\0' }; cxint i; @@ -1679,30 +1479,31 @@ snprintf(&keyn[5], FLEN_KEYWORD - 5, "%d", i + 1); fits_read_key(fptr, TLONGLONG, keyn, &naxes[i], 0, status); } - } return *status; - } inline static int -_cpl_fits_read_extinfo(fitsfile *fptr, cxint *hdutype, - cxint *bitpix, cxint *naxis, LONGLONG *naxes, - cxlong *pcount, cxlong *gcount, cxint *status) +_cpl_fits_read_extinfo(fitsfile *fptr, + cxint *hdutype, + cxint *bitpix, + cxint *naxis, + LONGLONG *naxes, + cxlong *pcount, + cxlong *gcount, + cxint *status) { - if (*status == 0) { - cxint _status = 0; if (hdutype) { fits_get_hdu_type(fptr, hdutype, &_status); } - fits_read_key(fptr, TINT, "BITPIX", bitpix, 0, &_status); - fits_read_key(fptr, TINT, "NAXIS", naxis, 0, &_status); + fits_read_key(fptr, TINT, "BITPIX", bitpix, 0, &_status); + fits_read_key(fptr, TINT, "NAXIS", naxis, 0, &_status); if (naxes) { _cpl_fits_read_axes(fptr, *naxis, naxes, &_status); @@ -1717,7 +1518,6 @@ fits_read_key(fptr, TLONG, "GCOUNT", gcount, 0, &_status); if (_status == KEY_NO_EXIST) { - cxint hdunum; fits_get_hdu_num(fptr, &hdunum); @@ -1727,30 +1527,28 @@ * these keyword may not be present in a primary HDU. */ - if (hdunum == 1) - { + if (hdunum == 1) { _status = 0; *pcount = 0; *gcount = 1; } - } *status = _status; } return *status; - } inline static int -_cpl_fits_read_extid(fitsfile *fptr, cxchar *extname, cxulong *extvers, - cxulong *extlevel, cxint *status) +_cpl_fits_read_extid(fitsfile *fptr, + cxchar *extname, + cxulong *extvers, + cxulong *extlevel, + cxint *status) { - if (*status == 0) { - cxint _status = 0; fits_read_key(fptr, TSTRING, "EXTNAME", extname, 0, &_status); @@ -1772,107 +1570,95 @@ } *status = _status; - } return *status; - } inline static cxint _cpl_fitsdataunit_init_empty(cpl_fitsdataunit *self) { - - self->_m_file = NULL; + self->_m_file = NULL; self->_m_position = 0; - self->_m_type = ANY_HDU; - self->_m_name = NULL; - self->_m_version = 0; - self->_m_level = 0; - self->_m_bitpix = 0; - self->_m_pcount = 0; - self->_m_gcount = 0; + self->_m_type = ANY_HDU; + self->_m_name = NULL; + self->_m_version = 0; + self->_m_level = 0; + self->_m_bitpix = 0; + self->_m_pcount = 0; + self->_m_gcount = 0; self->_m_unitsize = 0; self->_m_datasize = 0; - self->_m_naxes = 0; - self->_m_naxis = NULL; + self->_m_naxes = 0; + self->_m_naxis = NULL; self->_m_write_layout = NULL; return 0; - } inline static cxint -_cpl_fitsdataunit_init(cpl_fitsdataunit *self, fitsfile *file, - cxulong position) +_cpl_fitsdataunit_init(cpl_fitsdataunit *self, fitsfile *file, cxulong position) { - _cpl_fitsdataunit_init_empty(self); - self->_m_file = file; + self->_m_file = file; self->_m_position = position + 1; - self->_m_name = cx_string_new(); + self->_m_name = cx_string_new(); return 0; - } inline static void _cpl_fitsdataunit_clear(cpl_fitsdataunit *self) { - cx_string_delete(self->_m_name); cx_free(self->_m_naxis); - self->_m_file = NULL; + self->_m_file = NULL; self->_m_position = 0; - self->_m_type = ANY_HDU; - self->_m_name = NULL; - self->_m_version = 0; - self->_m_level = 0; - self->_m_bitpix = 0; - self->_m_pcount = 0; - self->_m_gcount = 0; + self->_m_type = ANY_HDU; + self->_m_name = NULL; + self->_m_version = 0; + self->_m_level = 0; + self->_m_bitpix = 0; + self->_m_pcount = 0; + self->_m_gcount = 0; self->_m_unitsize = 0; self->_m_datasize = 0; - self->_m_naxes = 0; - self->_m_naxis = NULL; + self->_m_naxes = 0; + self->_m_naxis = NULL; self->_m_write_layout = NULL; return; - } inline static cxint _cpl_fitsdataunit_copy(cpl_fitsdataunit *self, const cpl_fitsdataunit *other) { - - self->_m_file = other->_m_file; + self->_m_file = other->_m_file; self->_m_position = other->_m_position; - self->_m_type = other->_m_type; - self->_m_name = cx_string_copy(other->_m_name); - self->_m_version = other->_m_version; - self->_m_level = other->_m_level; - self->_m_bitpix = other->_m_bitpix; - self->_m_pcount = other->_m_pcount; - self->_m_gcount = other->_m_gcount; + self->_m_type = other->_m_type; + self->_m_name = cx_string_copy(other->_m_name); + self->_m_version = other->_m_version; + self->_m_level = other->_m_level; + self->_m_bitpix = other->_m_bitpix; + self->_m_pcount = other->_m_pcount; + self->_m_gcount = other->_m_gcount; self->_m_unitsize = other->_m_unitsize; self->_m_datasize = other->_m_datasize; - self->_m_naxes = other->_m_naxes; + self->_m_naxes = other->_m_naxes; if (other->_m_naxis) { - register size_t sz = other->_m_naxes * sizeof *other->_m_naxis; self->_m_naxis = cx_malloc(sz); memcpy(self->_m_naxis, other->_m_naxis, sz); - } else { self->_m_naxis = NULL; @@ -1881,33 +1667,31 @@ self->_m_write_layout = other->_m_write_layout; return 0; - } inline static cxint _cpl_fitsdataunit_make_current(cpl_fitsdataunit *self) { - cxint status = 0; cxint hdutype = ANY_HDU; fits_movabs_hdu(self->_m_file, self->_m_position, &hdutype, &status); return status; - } inline static cxint -_cpl_fitsdataunit_initialize(cpl_fitsdataunit *self, fitsfile *file, +_cpl_fitsdataunit_initialize(cpl_fitsdataunit *self, + fitsfile *file, cxulong position) { - cxint status = 0; - cxint idummy = 0; + cxint status = 0; + cxint idummy = 0; LONGLONG start = 0; - LONGLONG end = 0; + LONGLONG end = 0; _cpl_fitsdataunit_init(self, file, position); @@ -1935,12 +1719,10 @@ if (self->_m_naxes > 0) { - self->_m_naxis = cx_malloc(self->_m_naxes * sizeof *self->_m_naxis); _cpl_fits_read_axes(self->_m_file, self->_m_naxes, &self->_m_naxis[0], &status); - } if (status) { @@ -1950,10 +1732,8 @@ if (self->_m_position == 0) { - cxint hdunum; self->_m_position = fits_get_hdu_num(self->_m_file, &hdunum); - } if (self->_m_type == ANY_HDU) { @@ -1967,8 +1747,7 @@ if (cx_string_size(self->_m_name)) { - - cxchar extname[FLEN_VALUE] = {'\0'}; + cxchar extname[FLEN_VALUE] = { '\0' }; _cpl_fits_read_extid(self->_m_file, extname, &self->_m_version, &self->_m_level, &status); @@ -1985,21 +1764,18 @@ * Calculate the size of the payload in bytes */ - if (self->_m_naxis != NULL) { - - cxint i; - - self->_m_datasize = self->_m_bitpix < 0 ? - -self->_m_bitpix / 8 : self->_m_bitpix / 8; - - for (i = 0; i < self->_m_naxes; ++i) { - self->_m_datasize *= self->_m_naxis[i]; - } + if (self->_m_naxis != NULL) { + cxint i; - } + self->_m_datasize = + self->_m_bitpix < 0 ? -self->_m_bitpix / 8 : self->_m_bitpix / 8; - return status; + for (i = 0; i < self->_m_naxes; ++i) { + self->_m_datasize *= self->_m_naxis[i]; + } + } + return status; } @@ -2070,8 +1846,7 @@ inline static cx_string * _cpl_fitsdataunit_get_filename(const cpl_fitsdataunit *self) { - - cxchar name[FLEN_FILENAME] = {'\0'}; + cxchar name[FLEN_FILENAME] = { '\0' }; cxint status = 0; @@ -2082,14 +1857,12 @@ } return cx_string_create(name); - } inline static cxint _cpl_fitsdataunit_write_data(cpl_fitsdataunit *self, fitsfile *file) { - cxint status = 0; status = _cpl_fitsdataunit_make_current(self); @@ -2101,24 +1874,20 @@ fits_copy_data(self->_m_file, file, &status); return status; - } inline static cxint _cpl_fitsdataunit_write_layout(cpl_fitsdataunit *self, fitsfile *file) { - if (self->_m_write_layout == NULL) { return -1; } return self->_m_write_layout(self, file); - } - // FITS image data unit implementation #include @@ -2128,14 +1897,13 @@ struct _cpl_fitsemptyunit_ { - cpl_fitsdataunit base; /* Must be the first member */ + cpl_fitsdataunit base; /* Must be the first member */ }; inline static void _cpl_fitsemptyunit_delete(cpl_fitsemptyunit *self) { - if (self) { _cpl_fitsdataunit_clear((cpl_fitsdataunit *)self); } @@ -2143,14 +1911,12 @@ cx_free(self); return; - } static cxint _cpl_fitsemptyunit_write_layout(cpl_fitsdataunit *self, fitsfile *file) { - cx_assert(self != NULL); cx_assert(file != NULL); @@ -2161,14 +1927,12 @@ &self->_m_naxis[0], &status); return 0; - } inline static cpl_fitsemptyunit * _cpl_fitsemptyunit_new(void) { - cpl_fitsemptyunit *self = cx_malloc(sizeof *self); cpl_fitsdataunit *_self = (cpl_fitsdataunit *)self; @@ -2177,24 +1941,21 @@ _cpl_fitsdataunit_init_empty(_self); _self->_m_bitpix = 8; - _self->_m_type = CPL_FITS_DU_TYPE_EMPTY; + _self->_m_type = CPL_FITS_DU_TYPE_EMPTY; _self->_m_write_layout = _cpl_fitsemptyunit_write_layout; return self; - } inline static cpl_fitsemptyunit * _cpl_fitsemptyunit_clone(const cpl_fitsemptyunit *other) { - - cpl_fitsdataunit *_other = (cpl_fitsdataunit *)other; if (((_other->_m_file != NULL) && (_other->_m_position != 0)) || - (_other->_m_type != CPL_FITS_DU_TYPE_EMPTY)) { + (_other->_m_type != CPL_FITS_DU_TYPE_EMPTY)) { return NULL; } @@ -2209,11 +1970,9 @@ } return self; - } - // FITS image data unit implementation #include @@ -2223,14 +1982,13 @@ struct _cpl_fitsimageunit_ { - cpl_fitsdataunit base; /* Must be the first member */ + cpl_fitsdataunit base; /* Must be the first member */ }; inline static void _cpl_fitsimageunit_delete(cpl_fitsimageunit *self) { - if (self) { _cpl_fitsdataunit_clear((cpl_fitsdataunit *)self); } @@ -2238,14 +1996,12 @@ cx_free(self); return; - } static cxint _cpl_fitsimageunit_write_layout(cpl_fitsdataunit *self, fitsfile *file) { - cx_assert(self != NULL); cx_assert(file != NULL); @@ -2256,14 +2012,12 @@ &self->_m_naxis[0], &status); return 0; - } inline static cpl_fitsimageunit * _cpl_fitsimageunit_new(fitsfile *file, cxulong position) { - cpl_fitsimageunit *self = cx_malloc(sizeof *self); cpl_fitsdataunit *_self = (cpl_fitsdataunit *)self; @@ -2296,20 +2050,17 @@ _self->_m_write_layout = _cpl_fitsimageunit_write_layout; return self; - } inline static cpl_fitsimageunit * _cpl_fitsimageunit_clone(const cpl_fitsimageunit *other) { - - cpl_fitsdataunit *_other = (cpl_fitsdataunit *)other; if ((_other->_m_file == NULL) || (_other->_m_position == 0) || - (_other->_m_type != CPL_FITS_DU_TYPE_IMAGE)) { + (_other->_m_type != CPL_FITS_DU_TYPE_IMAGE)) { return NULL; } @@ -2324,11 +2075,9 @@ } return self; - } - // FITS binary table data unit implementation #include @@ -2340,38 +2089,35 @@ struct _cpl_fitsbtableunit_ { - cpl_fitsdataunit base; /* Must be the first member */ + cpl_fitsdataunit base; /* Must be the first member */ - cxint _m_columns; - LONGLONG _m_rows; + cxint _m_columns; + LONGLONG _m_rows; - cxchar **_m_ttype; - cxchar **_m_tform; - cxchar **_m_tunit; - cxchar **_m_tdisp; - cxchar **_m_tdim; - cxchar **_m_tscale; - cxchar **_m_tzero; - cxchar **_m_tnull; + cxchar **_m_ttype; + cxchar **_m_tform; + cxchar **_m_tunit; + cxchar **_m_tdisp; + cxchar **_m_tdim; + cxchar **_m_tscale; + cxchar **_m_tzero; + cxchar **_m_tnull; - cxchar *_m_tfields; - cxchar *_m_theap; + cxchar *_m_tfields; + cxchar *_m_theap; }; inline static void _cpl_fitsbtableunit_delete(cpl_fitsbtableunit *self) { - if (self) { - cxint i; cx_free(self->_m_theap); cx_free(self->_m_tfields); for (i = 0; i < self->_m_columns; ++i) { - cx_free(self->_m_tnull[i]); cx_free(self->_m_tzero[i]); cx_free(self->_m_tscale[i]); @@ -2380,7 +2126,6 @@ cx_free(self->_m_tunit[i]); cx_free(self->_m_tform[i]); cx_free(self->_m_ttype[i]); - } cx_free(self->_m_tnull); @@ -2393,20 +2138,17 @@ cx_free(self->_m_ttype); _cpl_fitsdataunit_clear((cpl_fitsdataunit *)self); - } cx_free(self); return; - } static cxint _cpl_fitsbtableunit_write_layout(cpl_fitsdataunit *self, fitsfile *file) { - cxint status = 0; cxint hdunum = 0; @@ -2419,7 +2161,7 @@ return NOT_BTABLE; } - long axis[] = {self->_m_naxis[0], self->_m_naxis[1]}; + long axis[] = { self->_m_naxis[0], self->_m_naxis[1] }; fits_write_exthdr(file, "BINTABLE", self->_m_bitpix, self->_m_naxes, axis, self->_m_pcount, self->_m_gcount, &status); @@ -2436,16 +2178,11 @@ * in favor of binary table specific ones. */ - fits_modify_comment(file, "XTENSION", "binary table extension", - &status); - fits_modify_comment(file, "BITPIX", "8-bit bytes", - &status); - fits_modify_comment(file, "NAXIS", "2-dimensional binary table", - &status); - fits_modify_comment(file, "NAXIS1", "width of table in bytes", - &status); - fits_modify_comment(file, "NAXIS2", "number of rows in table", - &status); + fits_modify_comment(file, "XTENSION", "binary table extension", &status); + fits_modify_comment(file, "BITPIX", "8-bit bytes", &status); + fits_modify_comment(file, "NAXIS", "2-dimensional binary table", &status); + fits_modify_comment(file, "NAXIS1", "width of table in bytes", &status); + fits_modify_comment(file, "NAXIS2", "number of rows in table", &status); if (status) { return status; @@ -2456,23 +2193,22 @@ * Write table meta data */ - typedef cxchar ** _cpl_stringarray; + typedef cxchar **_cpl_stringarray; - _cpl_stringarray *tdata[] = {&_self->_m_ttype, &_self->_m_tform, - &_self->_m_tunit, &_self->_m_tdisp, - &_self->_m_tdim, &_self->_m_tscale, - &_self->_m_tzero, &_self->_m_tnull, 0}; + _cpl_stringarray *tdata[] = { + &_self->_m_ttype, &_self->_m_tform, &_self->_m_tunit, + &_self->_m_tdisp, &_self->_m_tdim, &_self->_m_tscale, + &_self->_m_tzero, &_self->_m_tnull, 0 + }; cxint i; for (i = 0; i < _self->_m_columns; ++i) { - cxsize k = 0; status = 0; while (tdata[k]) { - cxchar *const *td = *tdata[k]; if ((td[i] != NULL) && (strlen(td[i]) > 0)) { @@ -2485,7 +2221,6 @@ if (status) { return status; } - } if ((_self->_m_theap != NULL) && (strlen(_self->_m_theap) > 0)) { @@ -2493,14 +2228,12 @@ } return status; - } inline static cpl_fitsbtableunit * _cpl_fitsbtableunit_new(fitsfile *file, cxulong position) { - cpl_fitsbtableunit *self = cx_malloc(sizeof *self); cpl_fitsdataunit *_self = (cpl_fitsdataunit *)self; @@ -2537,17 +2270,17 @@ _self->_m_write_layout = _cpl_fitsbtableunit_write_layout; - self->_m_ttype = NULL; - self->_m_tform = NULL; - self->_m_tunit = NULL; - self->_m_tdisp = NULL; - self->_m_tdim = NULL; + self->_m_ttype = NULL; + self->_m_tform = NULL; + self->_m_tunit = NULL; + self->_m_tdisp = NULL; + self->_m_tdim = NULL; self->_m_tscale = NULL; - self->_m_tzero = NULL; - self->_m_tnull = NULL; + self->_m_tzero = NULL; + self->_m_tnull = NULL; self->_m_tfields = NULL; - self->_m_theap = NULL; + self->_m_theap = NULL; /* @@ -2565,15 +2298,14 @@ } if (self->_m_columns) { - - self->_m_ttype = cx_malloc(self->_m_columns * sizeof(cxchar *)); - self->_m_tform = cx_malloc(self->_m_columns * sizeof(cxchar *)); - self->_m_tunit = cx_malloc(self->_m_columns * sizeof(cxchar *)); - self->_m_tdisp = cx_malloc(self->_m_columns * sizeof(cxchar *)); - self->_m_tdim = cx_malloc(self->_m_columns * sizeof(cxchar *)); + self->_m_ttype = cx_malloc(self->_m_columns * sizeof(cxchar *)); + self->_m_tform = cx_malloc(self->_m_columns * sizeof(cxchar *)); + self->_m_tunit = cx_malloc(self->_m_columns * sizeof(cxchar *)); + self->_m_tdisp = cx_malloc(self->_m_columns * sizeof(cxchar *)); + self->_m_tdim = cx_malloc(self->_m_columns * sizeof(cxchar *)); self->_m_tscale = cx_malloc(self->_m_columns * sizeof(cxchar *)); - self->_m_tzero = cx_malloc(self->_m_columns * sizeof(cxchar *)); - self->_m_tnull = cx_malloc(self->_m_columns * sizeof(cxchar *)); + self->_m_tzero = cx_malloc(self->_m_columns * sizeof(cxchar *)); + self->_m_tnull = cx_malloc(self->_m_columns * sizeof(cxchar *)); cxchar card[FLEN_CARD]; @@ -2600,12 +2332,12 @@ * Read the table meta data */ - typedef cxchar ** _cpl_stringarray; + typedef cxchar **_cpl_stringarray; struct _cpl_btable_metadata { const cxchar *name; - cxbool required; + cxbool required; _cpl_stringarray *data; @@ -2613,37 +2345,33 @@ }; struct _cpl_btable_metadata tdata[] = { - {"TTYPE", FALSE, &self->_m_ttype, KEY_NO_EXIST}, - {"TFORM", TRUE, &self->_m_tform, NO_TFORM}, - {"TUNIT", FALSE, &self->_m_tunit, KEY_NO_EXIST}, - {"TDISP", FALSE, &self->_m_tdisp, KEY_NO_EXIST}, - {"TDIM", FALSE, &self->_m_tdim, KEY_NO_EXIST}, - {"TSCALE", FALSE, &self->_m_tscale, KEY_NO_EXIST}, - {"TZERO", FALSE, &self->_m_tzero, KEY_NO_EXIST}, - {"TNULL", FALSE, &self->_m_tnull, KEY_NO_EXIST}, - {0, FALSE, 0, 0} + { "TTYPE", FALSE, &self->_m_ttype, KEY_NO_EXIST }, + { "TFORM", TRUE, &self->_m_tform, NO_TFORM }, + { "TUNIT", FALSE, &self->_m_tunit, KEY_NO_EXIST }, + { "TDISP", FALSE, &self->_m_tdisp, KEY_NO_EXIST }, + { "TDIM", FALSE, &self->_m_tdim, KEY_NO_EXIST }, + { "TSCALE", FALSE, &self->_m_tscale, KEY_NO_EXIST }, + { "TZERO", FALSE, &self->_m_tzero, KEY_NO_EXIST }, + { "TNULL", FALSE, &self->_m_tnull, KEY_NO_EXIST }, + { 0, FALSE, 0, 0 } }; cxint i; for (i = 0; i < self->_m_columns; ++i) { - cxsize k = 0; while (tdata[k].name) { + cxchar keyname[FLEN_KEYWORD] = { '\0' }; - cxchar keyname[FLEN_KEYWORD] = {'\0'}; - - snprintf(keyname, FLEN_KEYWORD - 1 , "%s%d", - tdata[k].name, i + 1); + snprintf(keyname, FLEN_KEYWORD - 1, "%s%d", tdata[k].name, + i + 1); card[0] = '\0'; fits_read_card(_self->_m_file, keyname, card, &status); if (status) { - if (status == KEY_NO_EXIST) { - /* * Ignore keyword not found errors unless the keyword * is a required keyword. @@ -2653,13 +2381,11 @@ _cpl_fitsbtableunit_delete(self); return NULL; } - } else { _cpl_fitsbtableunit_delete(self); return NULL; } - } @@ -2680,9 +2406,7 @@ } ++k; - } - } card[0] = '\0'; @@ -2696,24 +2420,20 @@ if (status == 0) { self->_m_theap = (cxchar *)cx_strdup(card); } - } return self; - } inline static cpl_fitsbtableunit * _cpl_fitsbtableunit_clone(const cpl_fitsbtableunit *other) { - - cpl_fitsdataunit *_other = (cpl_fitsdataunit *)other; if ((_other->_m_file == NULL) || (_other->_m_position == 0) || - (_other->_m_type != CPL_FITS_DU_TYPE_BTBL)) { + (_other->_m_type != CPL_FITS_DU_TYPE_BTBL)) { return NULL; } @@ -2733,23 +2453,21 @@ */ self->_m_columns = other->_m_columns; - self->_m_rows = other->_m_rows; + self->_m_rows = other->_m_rows; if (self->_m_columns) { - - self->_m_ttype = cx_malloc(other->_m_columns * sizeof(cxchar *)); - self->_m_tform = cx_malloc(other->_m_columns * sizeof(cxchar *)); - self->_m_tunit = cx_malloc(other->_m_columns * sizeof(cxchar *)); - self->_m_tdisp = cx_malloc(other->_m_columns * sizeof(cxchar *)); - self->_m_tdim = cx_malloc(other->_m_columns * sizeof(cxchar *)); + self->_m_ttype = cx_malloc(other->_m_columns * sizeof(cxchar *)); + self->_m_tform = cx_malloc(other->_m_columns * sizeof(cxchar *)); + self->_m_tunit = cx_malloc(other->_m_columns * sizeof(cxchar *)); + self->_m_tdisp = cx_malloc(other->_m_columns * sizeof(cxchar *)); + self->_m_tdim = cx_malloc(other->_m_columns * sizeof(cxchar *)); self->_m_tscale = cx_malloc(other->_m_columns * sizeof(cxchar *)); - self->_m_tzero = cx_malloc(other->_m_columns * sizeof(cxchar *)); - self->_m_tnull = cx_malloc(other->_m_columns * sizeof(cxchar *)); + self->_m_tzero = cx_malloc(other->_m_columns * sizeof(cxchar *)); + self->_m_tnull = cx_malloc(other->_m_columns * sizeof(cxchar *)); cxint i; for (i = 0; i < self->_m_columns; ++i) { - self->_m_tnull[i] = cx_strdup(other->_m_tnull[i]); self->_m_tzero[i] = cx_strdup(other->_m_tzero[i]); self->_m_tscale[i] = cx_strdup(other->_m_tscale[i]); @@ -2758,72 +2476,65 @@ self->_m_tunit[i] = cx_strdup(other->_m_tunit[i]); self->_m_tform[i] = cx_strdup(other->_m_tform[i]); self->_m_ttype[i] = cx_strdup(other->_m_ttype[i]); - } - } else { - - self->_m_ttype = NULL; - self->_m_tform = NULL; - self->_m_tunit = NULL; - self->_m_tdisp = NULL; - self->_m_tdim = NULL; + self->_m_ttype = NULL; + self->_m_tform = NULL; + self->_m_tunit = NULL; + self->_m_tdisp = NULL; + self->_m_tdim = NULL; self->_m_tscale = NULL; - self->_m_tzero = NULL; - self->_m_tnull = NULL; - + self->_m_tzero = NULL; + self->_m_tnull = NULL; } self->_m_tfields = cx_strdup(other->_m_tfields); self->_m_theap = cx_strdup(other->_m_theap); return self; - } - // FITS dataset implementation #include static const cxchar *_CPL_FITSDATASET_IGNORE_KEYPATTERN = - "(^SIMPLE =|^XTENSION=|^BITPIX =|^NAXIS =|^NAXIS[1-9][0-9]*" - "|^PCOUNT =|^GCOUNT =" - "|^EXTEND =|^EXTNAME =|^EXTVERS =|^EXTLEVEL=" - "|^TFIELDS =" - "|^TTYPE[1-9][0-9]* *=|^TFORM[1-9][0-9]* *=|^TUNIT[1-9][0-9]* *=" - "|^TDISP[1-9][0-9]* *=|^TDIM[1-9][0-9]* *=" - "|^TSCALE[1-9][0-9]* *=|^TZERO[1-9][0-9]* *=|^TNULL[1-9][0-9]* *=" - "|^THEAP =" - "|^CHECKSUM=|^DATASUM =|^DATAMD5 =|^DATE =|^END *$" - "|^ZHECKSUM=|^ZDATASUM=" - "|^ORIGFILE=|^ARCHFILE=" - "|^COMMENT *FITS \\(Flexible Image Transport System\\) format" - "|^COMMENT *and Astrophysics', volume 376, page 359;)"; + "(^SIMPLE =|^XTENSION=|^BITPIX =|^NAXIS =|^NAXIS[1-9][0-9]*" + "|^PCOUNT =|^GCOUNT =" + "|^EXTEND =|^EXTNAME =|^EXTVERS =|^EXTLEVEL=" + "|^TFIELDS =" + "|^TTYPE[1-9][0-9]* *=|^TFORM[1-9][0-9]* *=|^TUNIT[1-9][0-9]* *=" + "|^TDISP[1-9][0-9]* *=|^TDIM[1-9][0-9]* *=" + "|^TSCALE[1-9][0-9]* *=|^TZERO[1-9][0-9]* *=|^TNULL[1-9][0-9]* *=" + "|^THEAP =" + "|^CHECKSUM=|^DATASUM =|^DATAMD5 =|^DATE =|^END *$" + "|^ZHECKSUM=|^ZDATASUM=" + "|^ORIGFILE=|^ARCHFILE=" + "|^COMMENT *FITS \\(Flexible Image Transport System\\) format" + "|^COMMENT *and Astrophysics', volume 376, page 359;)"; typedef struct _cpl_fitsdataset_ cpl_fitsdataset; struct _cpl_fitsdataset_ { - const cxchar *_m_name; + const cxchar *_m_name; - cxulong _m_version; - cxulong _m_level; + cxulong _m_version; + cxulong _m_level; - cpl_fitsheader *_m_header; - cpl_fitsdataunit *_m_data; + cpl_fitsheader *_m_header; + cpl_fitsdataunit *_m_data; }; inline static cpl_fitsdataunit * _cpl_fitsdataset_make_dataunit(fitsfile *file, cxulong position) { - - cxint status = 0; + cxint status = 0; cxint hdutype = ANY_HDU; fits_movabs_hdu(file, position + 1, &hdutype, &status); @@ -2837,51 +2548,45 @@ switch (hdutype) { case IMAGE_HDU: - dataunit = (cpl_fitsdataunit *)_cpl_fitsimageunit_new(file, - position); + dataunit = + (cpl_fitsdataunit *)_cpl_fitsimageunit_new(file, position); break; case BINARY_TBL: - dataunit = (cpl_fitsdataunit *)_cpl_fitsbtableunit_new(file, - position); + dataunit = + (cpl_fitsdataunit *)_cpl_fitsbtableunit_new(file, position); break; default: break; - } return dataunit; - } inline static cpl_fitsdataunit * _cpl_fitsdataset_clone_dataunit(const cpl_fitsdataunit *other) { - cpl_fitsdataunit *dataunit = NULL; switch (_cpl_fitsdataunit_get_type(other)) { - - case CPL_FITS_DU_TYPE_IMAGE: - { + case CPL_FITS_DU_TYPE_IMAGE: { const cpl_fitsimageunit *_other = (const cpl_fitsimageunit *)other; dataunit = (cpl_fitsdataunit *)_cpl_fitsimageunit_clone(_other); break; } - case CPL_FITS_DU_TYPE_BTBL: - { - const cpl_fitsbtableunit *_other = (const cpl_fitsbtableunit *)other; + case CPL_FITS_DU_TYPE_BTBL: { + const cpl_fitsbtableunit *_other = + (const cpl_fitsbtableunit *)other; dataunit = (cpl_fitsdataunit *)_cpl_fitsbtableunit_clone(_other); break; } - case CPL_FITS_DU_TYPE_EMPTY: - { + case CPL_FITS_DU_TYPE_EMPTY: { const cpl_fitsemptyunit *_other = (const cpl_fitsemptyunit *)other; dataunit = (cpl_fitsdataunit *)_cpl_fitsemptyunit_clone(_other); @@ -2890,18 +2595,15 @@ default: break; - } return dataunit; - } inline static void _cpl_fitsdataset_delete(cpl_fitsdataset *self) { - if (self->_m_name) { cx_free((cxchar *)self->_m_name); } @@ -2911,9 +2613,7 @@ } if (self->_m_data) { - switch (_cpl_fitsdataunit_get_type(self->_m_data)) { - case CPL_FITS_DU_TYPE_IMAGE: _cpl_fitsimageunit_delete((cpl_fitsimageunit *)self->_m_data); break; @@ -2928,31 +2628,28 @@ default: break; - } } cx_free(self); return; - } inline static cpl_fitsdataset * _cpl_fitsdataset_new(fitsfile *file, cxulong position) { - cpl_fitsdataset *self = cx_malloc(sizeof *self); - self->_m_name = NULL; + self->_m_name = NULL; self->_m_version = 0; - self->_m_level = 0; - self->_m_data = NULL; + self->_m_level = 0; + self->_m_data = NULL; cpl_regex *ignore_keys = - cpl_regex_new(_CPL_FITSDATASET_IGNORE_KEYPATTERN, TRUE, - CPL_REGEX_EXTENDED | CPL_REGEX_NOSUBS); + cpl_regex_new(_CPL_FITSDATASET_IGNORE_KEYPATTERN, TRUE, + CPL_REGEX_EXTENDED | CPL_REGEX_NOSUBS); cpl_fitsheader *hdr = _cpl_fitsheader_create_from_file(file, position); @@ -2962,27 +2659,24 @@ cpl_regex_delete(ignore_keys); ignore_keys = NULL; - cpl_fitscard *name = _cpl_fitsheader_find(hdr, "EXTNAME"); + cpl_fitscard *name = _cpl_fitsheader_find(hdr, "EXTNAME"); cpl_fitscard *version = _cpl_fitsheader_find(hdr, "EXTVER"); - cpl_fitscard *level = _cpl_fitsheader_find(hdr, "EXTLEVEL"); + cpl_fitscard *level = _cpl_fitsheader_find(hdr, "EXTLEVEL"); if (name) { - cx_string *_name = _cpl_fitscard_get_value(name); cxsize start = cx_string_find_first_not_of(_name, " '"); - cxsize end = cx_string_find_last_not_of(_name, " '"); + cxsize end = cx_string_find_last_not_of(_name, " '"); cx_string *s = cx_string_substr(_name, start, end); self->_m_name = cx_strdup(cx_string_get(s)); cx_string_delete(s); cx_string_delete(_name); - } if (version) { - cx_string *value = _cpl_fitscard_get_value(version); cxchar *end; @@ -2992,20 +2686,16 @@ cx_string_delete(value); if (*end != '\0') { - _cpl_fitsheader_delete(hdr); _cpl_fitsdataset_delete(self); return NULL; - } self->_m_version = _version; - } if (level) { - cx_string *value = _cpl_fitscard_get_value(level); cxchar *end; @@ -3015,12 +2705,10 @@ cx_string_delete(value); if (*end != '\0') { - _cpl_fitsheader_delete(hdr); _cpl_fitsdataset_delete(self); return NULL; - } self->_m_level = _level; @@ -3031,24 +2719,22 @@ self->_m_data = _cpl_fitsdataset_make_dataunit(file, position); return self; - } inline static cpl_fitsdataset * _cpl_fitsdataset_create(const cpl_fitsheader *hdr, const cpl_fitsdataunit *data) { - cpl_fitsdataset *self = cx_malloc(sizeof *self); - self->_m_name = NULL; + self->_m_name = NULL; self->_m_version = 0; - self->_m_level = 0; - self->_m_data = NULL; + self->_m_level = 0; + self->_m_data = NULL; cpl_regex *ignore_keys = - cpl_regex_new(_CPL_FITSDATASET_IGNORE_KEYPATTERN, TRUE, - CPL_REGEX_EXTENDED | CPL_REGEX_NOSUBS); + cpl_regex_new(_CPL_FITSDATASET_IGNORE_KEYPATTERN, TRUE, + CPL_REGEX_EXTENDED | CPL_REGEX_NOSUBS); self->_m_header = _cpl_fitsheader_create_from_filter(hdr, ignore_keys); @@ -3058,7 +2744,6 @@ self->_m_data = _cpl_fitsdataset_clone_dataunit(data); return self; - } @@ -3111,22 +2796,19 @@ } - inline static cxint _cpl_fitsdataset_set_header(cpl_fitsdataset *self, const cpl_fitsheader *hdr) { - cpl_regex *ignore_keys = - cpl_regex_new(_CPL_FITSDATASET_IGNORE_KEYPATTERN, TRUE, - CPL_REGEX_EXTENDED | CPL_REGEX_NOSUBS); + cpl_regex_new(_CPL_FITSDATASET_IGNORE_KEYPATTERN, TRUE, + CPL_REGEX_EXTENDED | CPL_REGEX_NOSUBS); if (ignore_keys == NULL) { return 1; } - cpl_fitsheader *_hdr = _cpl_fitsheader_create_from_filter(hdr, - ignore_keys); + cpl_fitsheader *_hdr = _cpl_fitsheader_create_from_filter(hdr, ignore_keys); cpl_regex_delete(ignore_keys); ignore_keys = NULL; @@ -3142,15 +2824,15 @@ self->_m_header = _hdr; return 0; - } inline static cxint -_cpl_fitsdataset_set_id(cpl_fitsdataset *self, const cxchar *name, - cxulong version, cxulong level) +_cpl_fitsdataset_set_id(cpl_fitsdataset *self, + const cxchar *name, + cxulong version, + cxulong level) { - cx_assert(name != NULL); @@ -3170,15 +2852,15 @@ } return 0; - } inline static cxint -_cpl_fitsdataset_write(const cpl_fitsdataset *self, fitsfile *file, - cxbool is_primary, cxbool checksums) +_cpl_fitsdataset_write(const cpl_fitsdataset *self, + fitsfile *file, + cxbool is_primary, + cxbool checksums) { - cxint status = 0; /* @@ -3217,21 +2899,17 @@ } if (self->_m_version > 0) { - cxulong version = self->_m_version; fits_write_key(file, TULONG, "EXTVER", &version, "FITS Extension identification", &status); - } if (self->_m_level > 0) { - cxulong level = self->_m_level; - fits_write_key(file, TULONG, "EXTLEVEL", &level, - "FITS Extension level", &status); - + fits_write_key(file, TULONG, "EXTLEVEL", &level, "FITS Extension level", + &status); } if (status) { @@ -3245,8 +2923,7 @@ if (is_primary) { fits_write_key(file, TSTRING, (cxchar *)"DATE", - (cxchar *)"YYYY-MM-DDThh:mm:ss", - NULL, &status); + (cxchar *)"YYYY-MM-DDThh:mm:ss", NULL, &status); } @@ -3254,13 +2931,11 @@ fits_write_key(file, TSTRING, (cxchar *)"CHECKSUM", (cxchar *)"0000000000000000", (cxchar *)"ASCII 1's complement checksum", &status); - fits_write_key(file, TSTRING, (cxchar *)"DATASUM", - (cxchar *)" 0", + fits_write_key(file, TSTRING, (cxchar *)"DATASUM", (cxchar *)" 0", (cxchar *)"", &status); } - if (status) - { + if (status) { return status; } @@ -3275,16 +2950,14 @@ cxsize i; for (i = 0; i < _cpl_fitsheader_get_size(self->_m_header); ++i) { - - const cpl_fitscard *card = _cpl_fitsheader_get_const(self->_m_header, - i); + const cpl_fitscard *card = + _cpl_fitsheader_get_const(self->_m_header, i); const cx_string *record = _cpl_fitscard_get_card(card); fits_write_record(file, cx_string_get(record), &status); - } - if (status) { + if (status) { return status; } @@ -3305,11 +2978,9 @@ */ if (is_primary) { - fits_write_date(file, &status); fits_modify_comment(file, "DATE", "Date this file was written", &status); - } if (checksums) { @@ -3317,7 +2988,6 @@ } return status; - } @@ -3348,34 +3018,32 @@ #include - struct _cpl_multiframe_ { - cx_map *_m_files; - cx_deque *_m_datasets; + cx_map *_m_files; + cx_deque *_m_datasets; }; static cxbool _cpl_multiframe_key_compare(cxcptr a, cxcptr b) { - const cxchar *_a = a; const cxchar *_b = b; return (strcmp(_a, _b) < 0) ? TRUE : FALSE; - } inline static cpl_error_code -_cpl_multiframe_append_dataset(cpl_multiframe *self, const cxchar *id, - const cxchar *filename, cxsize position, +_cpl_multiframe_append_dataset(cpl_multiframe *self, + const cxchar *id, + const cxchar *filename, + cxsize position, const cpl_regex *filter1, const cpl_regex *filter2, cxuint flags) { - cx_assert(self != NULL); cx_assert(id != NULL); cx_assert(filename != NULL); @@ -3401,15 +3069,11 @@ fp = cx_map_get_value(self->_m_files, it); } else { - fits_open_diskfile(&fp, filename, READONLY, &status); if (status) { - return cpl_error_set_(CPL_ERROR_ASSIGNING_STREAM); - } - } @@ -3419,57 +3083,49 @@ if (_dataset == NULL) { - fits_close_file(fp, &status); return cpl_error_set_(CPL_ERROR_DATA_NOT_FOUND); - } if (filter1) { - hdr0 = _cpl_fitsheader_create_from_filter(_cpl_fitsdataset_get_header_const(_dataset), - filter1); + hdr0 = _cpl_fitsheader_create_from_filter( + _cpl_fitsdataset_get_header_const(_dataset), filter1); } else { - hdr0 = _cpl_fitsheader_duplicate(_cpl_fitsdataset_get_header_const(_dataset)); + hdr0 = _cpl_fitsheader_duplicate( + _cpl_fitsdataset_get_header_const(_dataset)); } if (hdr0 == NULL) { - _cpl_fitsdataset_delete(_dataset); - fits_close_file(fp, &status); + fits_close_file(fp, &status); return cpl_error_set_(CPL_ERROR_ILLEGAL_OUTPUT); - } cpl_fitsdataset *dataset = NULL; if (position == 0) { - cpl_fitsheader *_hdr0 = _cpl_fitsheader_new(); - dataset = _cpl_fitsdataset_create(_hdr0, - _cpl_fitsdataset_get_data_const(_dataset)); + dataset = + _cpl_fitsdataset_create(_hdr0, + _cpl_fitsdataset_get_data_const(_dataset)); _cpl_fitsheader_delete(_hdr0); - } else { - dataset = _cpl_fitsdataset_new(fp, position); - } if (dataset == NULL) { - _cpl_fitsheader_delete(hdr0); _cpl_fitsdataset_delete(_dataset); fits_close_file(fp, &status); return cpl_error_set_(CPL_ERROR_DATA_NOT_FOUND); - } @@ -3479,14 +3135,12 @@ */ if (filter2) { - const cpl_fitsheader *hdr = _cpl_fitsdataset_get_header_const(dataset); cpl_fitsheader *_hdr = _cpl_fitsheader_create_from_filter(hdr, filter2); if (_hdr == NULL) { - _cpl_fitsdataset_delete(dataset); _cpl_fitsheader_delete(hdr0); _cpl_fitsdataset_delete(_dataset); @@ -3494,7 +3148,6 @@ fits_close_file(fp, &status); return cpl_error_set_(CPL_ERROR_ILLEGAL_OUTPUT); - } status = _cpl_fitsdataset_set_header(dataset, _hdr); @@ -3503,7 +3156,6 @@ _hdr = NULL; if (status) { - _cpl_fitsdataset_delete(dataset); _cpl_fitsheader_delete(hdr0); _cpl_fitsdataset_delete(_dataset); @@ -3511,9 +3163,7 @@ fits_close_file(fp, &status); return cpl_error_set_(CPL_ERROR_ILLEGAL_OUTPUT); - } - } @@ -3523,12 +3173,10 @@ */ if ((hdr0 != NULL) && (_cpl_fitsheader_get_size(hdr0) > 0)) { - cpl_fitsheader *_hdr = _cpl_fitsdataset_get_header(dataset); _cpl_fitsheader_join(_hdr, hdr0); _cpl_fitsheader_sort(_hdr, _cpl_fitscard_compare_dicb); - } _cpl_fitsheader_delete(hdr0); @@ -3545,35 +3193,28 @@ switch (flags) { - - case CPL_MULTIFRAME_ID_SET: - { + case CPL_MULTIFRAME_ID_SET: { _id = cx_string_create(id); break; } - case CPL_MULTIFRAME_ID_PREFIX: - { + case CPL_MULTIFRAME_ID_PREFIX: { _id = cx_string_create(id); cx_string_append(_id, _name); break; } - case CPL_MULTIFRAME_ID_JOIN: - { - + case CPL_MULTIFRAME_ID_JOIN: { const cxchar *_prefix = _cpl_fitsdataset_get_name(_dataset); if ((_prefix == NULL) || (strlen(_prefix) == 0)) { - _cpl_fitsdataset_delete(dataset); _cpl_fitsdataset_delete(_dataset); fits_close_file(fp, &status); return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); - } _id = cx_string_create(_prefix); @@ -3584,12 +3225,9 @@ } break; - } - default: - { - + default: { /* This point should never be reached */ _cpl_fitsdataset_delete(dataset); @@ -3599,9 +3237,7 @@ return cpl_error_set_(CPL_ERROR_UNSUPPORTED_MODE); break; - } - } _cpl_fitsdataset_delete(_dataset); @@ -3619,12 +3255,10 @@ _id = NULL; if (status) { - _cpl_fitsdataset_delete(dataset); fits_close_file(fp, &status); return cpl_error_set_(CPL_ERROR_ILLEGAL_OUTPUT); - } @@ -3636,23 +3270,20 @@ cx_deque_push_back(self->_m_datasets, dataset); if (it == cx_map_end(self->_m_files)) { - cx_map_insert(self->_m_files, cx_strdup(filename), fp); - } return CPL_ERROR_NONE; - } inline static cpl_fitsdataset * -_cpl_multiframe_merge(fitsfile *fp, cxsize position, +_cpl_multiframe_merge(fitsfile *fp, + cxsize position, const cpl_fitsheader *hdr, const cpl_regex *filter1, const cpl_regex *filter2) { - cx_assert(fp != NULL); cx_assert(hdr != NULL); @@ -3674,22 +3305,18 @@ } if (hdr0 == NULL) { - cpl_error_set_(CPL_ERROR_ILLEGAL_OUTPUT); return NULL; - } cpl_fitsdataset *dataset = _cpl_fitsdataset_new(fp, position); if (dataset == NULL) { - _cpl_fitsheader_delete(hdr0); cpl_error_set_(CPL_ERROR_DATA_NOT_FOUND); return NULL; - } @@ -3699,21 +3326,19 @@ */ if (filter2) { - const cpl_fitsheader *hdr1 = _cpl_fitsdataset_get_header_const(dataset); - cpl_fitsheader *_hdr = _cpl_fitsheader_create_from_filter(hdr1, filter2); + cpl_fitsheader *_hdr = + _cpl_fitsheader_create_from_filter(hdr1, filter2); if (_hdr == NULL) { - _cpl_fitsdataset_delete(dataset); _cpl_fitsheader_delete(hdr0); cpl_error_set_(CPL_ERROR_ILLEGAL_OUTPUT); return NULL; - } status = _cpl_fitsdataset_set_header(dataset, _hdr); @@ -3722,16 +3347,13 @@ _hdr = NULL; if (status) { - _cpl_fitsdataset_delete(dataset); _cpl_fitsheader_delete(hdr0); cpl_error_set_(CPL_ERROR_ILLEGAL_OUTPUT); return NULL; - } - } @@ -3741,51 +3363,46 @@ */ if ((hdr0 != NULL) && (_cpl_fitsheader_get_size(hdr0) > 0)) { - cpl_fitsheader *_hdr = _cpl_fitsdataset_get_header(dataset); _cpl_fitsheader_join(_hdr, hdr0); _cpl_fitsheader_sort(_hdr, _cpl_fitscard_compare_dicb); - } _cpl_fitsheader_delete(hdr0); return dataset; - } inline static cpl_error_code -_cpl_multiframe_append_datagroup(cpl_multiframe *self, const cxchar *id, +_cpl_multiframe_append_datagroup(cpl_multiframe *self, + const cxchar *id, const cxchar *filename, - cxsize nsets, cpl_size *positions, + cxsize nsets, + cpl_size *positions, const cpl_regex **filter1, const cpl_regex **filter2, const cxchar **links, cxint flags) { - cx_assert(self != NULL); cx_assert(id != NULL); cx_assert(filename != NULL); cx_assert(positions != NULL); cx_assert(nsets > 1); - cx_assert((flags == CPL_MULTIFRAME_ID_PREFIX) || (flags == CPL_MULTIFRAME_ID_JOIN)); + cx_assert((flags == CPL_MULTIFRAME_ID_PREFIX) || + (flags == CPL_MULTIFRAME_ID_JOIN)); cx_assert((flags != CPL_MULTIFRAME_ID_PREFIX) || (*id != '\0')); cxsize is; for (is = 0; is < nsets; ++is) { - if (positions[is] < 1) { - return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); - } - } @@ -3800,37 +3417,30 @@ fp = cx_map_get_value(self->_m_files, it); } else { - fits_open_diskfile(&fp, filename, READONLY, &status); if (status) { - return cpl_error_set_(CPL_ERROR_ASSIGNING_STREAM); - } - } cpl_fitsdataset *_dataset = _cpl_fitsdataset_new(fp, 0); if (_dataset == NULL) { - fits_close_file(fp, &status); return cpl_error_set_(CPL_ERROR_DATA_NOT_FOUND); - } const cxchar *name0 = _cpl_fitsdataset_get_name(_dataset); - if ((flags == CPL_MULTIFRAME_ID_JOIN) && ((name0 == NULL) || (*name0 == '\0'))) { - + if ((flags == CPL_MULTIFRAME_ID_JOIN) && + ((name0 == NULL) || (*name0 == '\0'))) { _cpl_fitsdataset_delete(_dataset); fits_close_file(fp, &status); return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); - } @@ -3838,15 +3448,13 @@ for (is = 0; is < nsets; ++is) { - const cpl_regex *_filter1 = (filter1 != NULL) ? filter1[is] : NULL; const cpl_regex *_filter2 = (filter2 != NULL) ? filter2[is] : NULL; - cpl_fitsdataset *dataset = _cpl_multiframe_merge(fp, positions[is], hdr0, - _filter1, _filter2); + cpl_fitsdataset *dataset = + _cpl_multiframe_merge(fp, positions[is], hdr0, _filter1, _filter2); if (dataset == NULL) { - cpl_error_code _status = cpl_error_get_code(); _cpl_fitsdataset_delete(_dataset); @@ -3855,32 +3463,27 @@ cpl_error_set_where(cpl_func); return _status; - } /* * Create and set the new dataset id */ - cxchar *name = cx_strdup(_cpl_fitsdataset_get_name(dataset)); + cxchar *name = cx_strdup(_cpl_fitsdataset_get_name(dataset)); cx_string *_id; if (flags == CPL_MULTIFRAME_ID_JOIN) { - _id = cx_string_create(name0); if (name && (*name != '\0')) { cx_string_append(_id, id); cx_string_append(_id, name); } - } else { - _id = cx_string_create(id); cx_string_append(_id, name); - } // FIXME: The following call does not handle the dataset version and level. @@ -3894,7 +3497,6 @@ _id = NULL; if (status) { - cx_free(name); _cpl_fitsdataset_delete(dataset); @@ -3903,7 +3505,6 @@ fits_close_file(fp, &status); return cpl_error_set_(CPL_ERROR_ILLEGAL_OUTPUT); - } @@ -3912,61 +3513,53 @@ */ if (links) { - cpl_fitsheader *hdr = _cpl_fitsdataset_get_header(dataset); const cxchar **_links = links; const cxchar *lnkname; while ((lnkname = *_links)) { - cpl_fitscard *card = _cpl_fitsheader_find(hdr, lnkname); if (card) { - - cx_string *value = _cpl_fitscard_get_value(card); + cx_string *value = _cpl_fitscard_get_value(card); cx_string *comment = _cpl_fitscard_get_comment(card); cxsize first = cx_string_find_first_not_of(value, "'"); - cxsize last = cx_string_find_last_not_of(value, "' "); + cxsize last = cx_string_find_last_not_of(value, "' "); - cx_string *_value = cx_string_substr(value, first, last - first + 1); + cx_string *_value = + cx_string_substr(value, first, last - first + 1); cx_string_delete(value); value = cx_string_create("'"); if (flags == CPL_MULTIFRAME_ID_JOIN) { - cx_string_append(value, name0); if (name && (*name != '\0')) { cx_string_append(value, id); cx_string_append(value, cx_string_get(_value)); } - } else { - cx_string_append(value, id); cx_string_append(value, cx_string_get(_value)); - } cx_string_append(value, "'"); - _cpl_fitscard_set_value(card, cx_string_get(value), cx_string_get(comment)); + _cpl_fitscard_set_value(card, cx_string_get(value), + cx_string_get(comment)); cx_string_delete(_value); cx_string_delete(comment); cx_string_delete(value); - } ++_links; - } - } cx_free(name); @@ -3977,7 +3570,6 @@ */ cx_deque_push_back(self->_m_datasets, dataset); - } _cpl_fitsdataset_delete(_dataset); @@ -3992,7 +3584,6 @@ } return CPL_ERROR_NONE; - } @@ -4019,10 +3610,8 @@ */ cpl_multiframe * -cpl_multiframe_new(const cpl_frame *head, const char *id, - cpl_regex *filter) +cpl_multiframe_new(const cpl_frame *head, const char *id, cpl_regex *filter) { - if ((head == NULL) || (id == NULL)) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return NULL; @@ -4035,14 +3624,11 @@ self->_m_datasets = cx_deque_new(); - const cxchar *filename = cpl_frame_get_filename(head); if (filename == NULL) { - cpl_multiframe_delete(self); return NULL; - } @@ -4053,22 +3639,18 @@ fits_open_diskfile(&fp, filename, READONLY, &status); if (status) { - cpl_multiframe_delete(self); return NULL; - } cpl_fitsdataset *dataset = _cpl_fitsdataset_new(fp, 0); if (dataset == NULL) { - fits_close_file(fp, &status); cpl_multiframe_delete(self); return NULL; - } @@ -4082,21 +3664,19 @@ "|^BLANK =|^DATAMIN =|^DATAMAX =)"; cpl_regex *ignore_keys = - cpl_regex_new(ignore_key_pattern, TRUE, - CPL_REGEX_EXTENDED | CPL_REGEX_NOSUBS); + cpl_regex_new(ignore_key_pattern, TRUE, + CPL_REGEX_EXTENDED | CPL_REGEX_NOSUBS); cpl_fitsheader *_hdr = _cpl_fitsheader_create_from_filter(hdr, ignore_keys); cpl_regex_delete(ignore_keys); if (_hdr == NULL) { - _cpl_fitsdataset_delete(dataset); fits_close_file(fp, &status); cpl_multiframe_delete(self); return NULL; - } @@ -4105,22 +3685,18 @@ */ if (filter) { - cpl_fitsheader *hdr0 = _cpl_fitsheader_create_from_filter(_hdr, filter); if (hdr0 == NULL) { - _cpl_fitsdataset_delete(dataset); fits_close_file(fp, &status); cpl_multiframe_delete(self); return NULL; - } _cpl_fitsheader_delete(_hdr); _hdr = hdr0; - } @@ -4145,25 +3721,21 @@ //if (status) { if (!dataset) { - fits_close_file(fp, &status); cpl_multiframe_delete(self); return NULL; - } status = _cpl_fitsdataset_set_id(dataset, id, 0, 0); if (status) { - _cpl_fitsdataset_delete(dataset); fits_close_file(fp, &status); cpl_multiframe_delete(self); return NULL; - } @@ -4175,7 +3747,6 @@ cx_map_insert(self->_m_files, cx_strdup(cpl_frame_get_filename(head)), fp); return self; - } @@ -4195,34 +3766,28 @@ cpl_multiframe_delete(cpl_multiframe *self) { if (self != NULL) { - if (self->_m_datasets != NULL) { cx_deque_destroy(self->_m_datasets, (cx_free_func)_cpl_fitsdataset_delete); } if (self->_m_files) { - cxint status = 0; cx_map_iterator it = cx_map_begin(self->_m_files); while (it != cx_map_end(self->_m_files)) { - fits_close_file(cx_map_get_value(self->_m_files, it), &status); status = 0; it = cx_map_next(self->_m_files, it); - } cx_map_delete(self->_m_files); - } cx_free(self); - } return; @@ -4246,14 +3811,12 @@ cpl_size cpl_multiframe_get_size(const cpl_multiframe *self) { - if (self == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return 0L; } return (cpl_size)cx_deque_size(self->_m_datasets); - } @@ -4306,47 +3869,37 @@ */ cpl_error_code -cpl_multiframe_append_dataset_from_position(cpl_multiframe *self, const char *id, - const cpl_frame *frame, cpl_size position, +cpl_multiframe_append_dataset_from_position(cpl_multiframe *self, + const char *id, + const cpl_frame *frame, + cpl_size position, const cpl_regex *filter1, const cpl_regex *filter2, unsigned int flags) { - if ((self == NULL) || (id == NULL) || (frame == NULL)) { - return cpl_error_set_(CPL_ERROR_NULL_INPUT); - } if (position < 0) { - return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); - } if ((flags != CPL_MULTIFRAME_ID_SET) && - (flags != CPL_MULTIFRAME_ID_PREFIX) && - (flags != CPL_MULTIFRAME_ID_JOIN)) - { - + (flags != CPL_MULTIFRAME_ID_PREFIX) && + (flags != CPL_MULTIFRAME_ID_JOIN)) { return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); - } if ((flags == CPL_MULTIFRAME_ID_PREFIX) && (*id == '\0')) { - return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); - } const cxchar *filename = cpl_frame_get_filename(frame); if (filename == NULL) { - return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); - } @@ -4359,7 +3912,6 @@ } return CPL_ERROR_NONE; - } @@ -4412,59 +3964,47 @@ */ cpl_error_code -cpl_multiframe_append_dataset(cpl_multiframe *self, const char *id, - const cpl_frame *frame, const char *name, +cpl_multiframe_append_dataset(cpl_multiframe *self, + const char *id, + const cpl_frame *frame, + const char *name, const cpl_regex *filter1, const cpl_regex *filter2, unsigned int flags) { - if ((self == NULL) || (id == NULL) || (frame == NULL) || (name == NULL)) { - return cpl_error_set_(CPL_ERROR_NULL_INPUT); - } if ((flags != CPL_MULTIFRAME_ID_SET) && - (flags != CPL_MULTIFRAME_ID_PREFIX) && - (flags != CPL_MULTIFRAME_ID_JOIN)) - { - + (flags != CPL_MULTIFRAME_ID_PREFIX) && + (flags != CPL_MULTIFRAME_ID_JOIN)) { return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); - } if ((flags == CPL_MULTIFRAME_ID_PREFIX) && (*id == '\0')) { - return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); - } const cxchar *filename = cpl_frame_get_filename(frame); if (filename == NULL) { - return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); - } cxsize position = 0; if (strlen(name) > 0) { - cxssize _position = _cpl_fits_find_extension(filename, name, 0); if (_position < 0) { - return cpl_error_set_(CPL_ERROR_DATA_NOT_FOUND); - } position = _position; - } @@ -4477,7 +4017,6 @@ } return CPL_ERROR_NONE; - } @@ -4544,57 +4083,47 @@ */ cpl_error_code -cpl_multiframe_append_datagroup_from_position(cpl_multiframe *self, const char *id, +cpl_multiframe_append_datagroup_from_position(cpl_multiframe *self, + const char *id, const cpl_frame *frame, - cpl_size nsets, cpl_size *positions, + cpl_size nsets, + cpl_size *positions, const cpl_regex **filter1, const cpl_regex **filter2, const char **properties, unsigned int flags) { - if ((self == NULL) || (id == NULL) || (frame == NULL)) { - return cpl_error_set_(CPL_ERROR_NULL_INPUT); - } if (positions == NULL) { - return cpl_error_set_(CPL_ERROR_NULL_INPUT); - } if (nsets < 2) { - return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); - } - if ((flags != CPL_MULTIFRAME_ID_PREFIX) && (flags != CPL_MULTIFRAME_ID_JOIN)) - { - + if ((flags != CPL_MULTIFRAME_ID_PREFIX) && + (flags != CPL_MULTIFRAME_ID_JOIN)) { return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); - } if ((flags == CPL_MULTIFRAME_ID_PREFIX) && (*id == '\0')) { - return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); - } const cxchar *filename = cpl_frame_get_filename(frame); if (filename == NULL) { - return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); - } - cxint status = _cpl_multiframe_append_datagroup(self, id, filename, nsets, positions, - filter1, filter2, properties, flags); + cxint status = + _cpl_multiframe_append_datagroup(self, id, filename, nsets, positions, + filter1, filter2, properties, flags); if (status) { cpl_error_set_where(cpl_func); @@ -4602,7 +4131,6 @@ } return CPL_ERROR_NONE; - } @@ -4633,53 +4161,42 @@ */ cpl_error_code -cpl_multiframe_append_datagroup(cpl_multiframe *self, const char *id, +cpl_multiframe_append_datagroup(cpl_multiframe *self, + const char *id, const cpl_frame *frame, - cpl_size nsets, const char **names, + cpl_size nsets, + const char **names, const cpl_regex **filter1, const cpl_regex **filter2, const char **properties, unsigned int flags) { - if ((self == NULL) || (id == NULL) || (frame == NULL)) { - return cpl_error_set_(CPL_ERROR_NULL_INPUT); - } if (names == NULL) { - return cpl_error_set_(CPL_ERROR_NULL_INPUT); - } if (nsets < 2) { - return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); - } - if ((flags != CPL_MULTIFRAME_ID_PREFIX) && (flags != CPL_MULTIFRAME_ID_JOIN)) - { - + if ((flags != CPL_MULTIFRAME_ID_PREFIX) && + (flags != CPL_MULTIFRAME_ID_JOIN)) { return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); - } if ((flags == CPL_MULTIFRAME_ID_PREFIX) && (*id == '\0')) { - return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); - } const cxchar *filename = cpl_frame_get_filename(frame); if (filename == NULL) { - return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); - } cxssize is; @@ -4687,24 +4204,21 @@ cpl_size *positions = cx_calloc(nsets, sizeof(cpl_size)); for (is = 0; is < nsets; ++is) { - cxint _position = cpl_fits_find_extension(filename, names[is]); if (_position > 0) { positions[is] = _position; } else { - cx_free(positions); return cpl_error_set_(CPL_ERROR_DATA_NOT_FOUND); - } - } - cxint status = _cpl_multiframe_append_datagroup(self, id, filename, nsets, positions, - filter1, filter2, properties, flags); + cxint status = + _cpl_multiframe_append_datagroup(self, id, filename, nsets, positions, + filter1, filter2, properties, flags); cx_free(positions); positions = NULL; @@ -4715,7 +4229,6 @@ } return CPL_ERROR_NONE; - } @@ -4739,32 +4252,26 @@ cpl_error_code cpl_multiframe_add_empty(cpl_multiframe *self, const char *id) { - if ((self == NULL) || (id == NULL) || (*id == '\0')) { - return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); - } - cpl_fitsheader *hdr = _cpl_fitsheader_new(); + cpl_fitsheader *hdr = _cpl_fitsheader_new(); cpl_fitsemptyunit *data = _cpl_fitsemptyunit_new(); if ((hdr == NULL) || (data == NULL)) { - return cpl_error_set_(CPL_ERROR_ILLEGAL_OUTPUT); - } - cpl_fitsdataset *dataset = _cpl_fitsdataset_create(hdr, (cpl_fitsdataunit *)data); + cpl_fitsdataset *dataset = + _cpl_fitsdataset_create(hdr, (cpl_fitsdataunit *)data); _cpl_fitsheader_delete(hdr); _cpl_fitsemptyunit_delete(data); if (dataset == NULL) { - return cpl_error_set_(CPL_ERROR_ILLEGAL_OUTPUT); - } @@ -4776,9 +4283,7 @@ cxint status = _cpl_fitsdataset_set_id(dataset, id, 0, 0); if (status) { - return cpl_error_set_(CPL_ERROR_ILLEGAL_OUTPUT); - } @@ -4790,7 +4295,6 @@ return CPL_ERROR_NONE; - } @@ -4815,11 +4319,8 @@ cpl_error_code cpl_multiframe_write(cpl_multiframe *self, const char *filename) { - if ((self == NULL) || (filename == NULL)) { - return cpl_error_set_(CPL_ERROR_NULL_INPUT); - } @@ -4831,7 +4332,6 @@ fits_create_file(&fp, filename, &status); if (status == FILE_NOT_CREATED) { - cx_string *_filename = cx_string_create("!"); cx_string_append(_filename, filename); @@ -4841,23 +4341,18 @@ cx_string_delete(_filename); _filename = NULL; - } if (status) { - return cpl_error_set_(CPL_ERROR_FILE_NOT_CREATED); - } cxsize sz = cx_deque_size(self->_m_datasets); if (sz == 0) { - fits_close_file(fp, &status); return cpl_error_set_(CPL_ERROR_DATA_NOT_FOUND); - } @@ -4867,18 +4362,18 @@ cpl_fitsdataset *dataset = cx_deque_get(self->_m_datasets, 0); - _cpl_fitsheader_sort(_cpl_fitsdataset_get_header(dataset), _cpl_fitscard_compare_dicb); + _cpl_fitsheader_sort(_cpl_fitsdataset_get_header(dataset), + _cpl_fitscard_compare_dicb); _cpl_fitsdataset_write(dataset, fp, TRUE, FALSE); cxsize i; for (i = 1; i < sz; ++i) { - dataset = cx_deque_get(self->_m_datasets, i); - _cpl_fitsheader_sort(_cpl_fitsdataset_get_header(dataset), _cpl_fitscard_compare_dicb); + _cpl_fitsheader_sort(_cpl_fitsdataset_get_header(dataset), + _cpl_fitscard_compare_dicb); _cpl_fitsdataset_write(dataset, fp, FALSE, FALSE); - } @@ -4896,6 +4391,5 @@ fits_close_file(fp, &status); return CPL_ERROR_NONE; - } /**@}*/ diff -Nru cpl-7.1.4+ds/cpldfs/cpl_multiframe.h cpl-7.2.2+ds/cpldfs/cpl_multiframe.h --- cpl-7.1.4+ds/cpldfs/cpl_multiframe.h 2021-05-07 12:09:10.000000000 +0000 +++ cpl-7.2.2+ds/cpldfs/cpl_multiframe.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -26,7 +26,6 @@ #include - CPL_BEGIN_DECLS /** @@ -43,21 +42,21 @@ * @hideinitializer */ - CPL_REGEX_ICASE = 1 << 0, + CPL_REGEX_ICASE = 1 << 0, /** * No sub-expressions. * @hideinitializer */ - CPL_REGEX_NOSUBS = 1 << 1, + CPL_REGEX_NOSUBS = 1 << 1, /** * Basic POSIX grammer. * @hideinitializer */ - CPL_REGEX_BASIC = 1 << 2, + CPL_REGEX_BASIC = 1 << 2, /** * Extended POSIX grammer. @@ -77,7 +76,7 @@ * */ -typedef enum _cpl_regex_syntax_option_ cpl_regex_syntax_option; +typedef enum _cpl_regex_syntax_option_ cpl_regex_syntax_option; /** @@ -90,8 +89,9 @@ typedef struct _cpl_regex_ cpl_regex; -cpl_regex *cpl_regex_new(const char *expression, int negated, - cpl_regex_syntax_option flags); +cpl_regex *cpl_regex_new(const char *expression, + int negated, + cpl_regex_syntax_option flags); void cpl_regex_delete(cpl_regex *self); int cpl_regex_apply(const cpl_regex *self, const char *string); @@ -100,7 +100,6 @@ void cpl_regex_negate(cpl_regex *self); - /** * @ingroup cpl_multiframe * @@ -116,7 +115,7 @@ * @hideinitializer */ - CPL_MULTIFRAME_ID_SET = 1 << 0, + CPL_MULTIFRAME_ID_SET = 1 << 0, /** * Create the dataset name from the given identifier by appending the name of the source @@ -132,7 +131,7 @@ * @hideinitializer */ - CPL_MULTIFRAME_ID_JOIN = 1 << 2 + CPL_MULTIFRAME_ID_JOIN = 1 << 2 }; @@ -157,8 +156,8 @@ typedef struct _cpl_multiframe_ cpl_multiframe; -cpl_multiframe *cpl_multiframe_new(const cpl_frame *head, const char *id, - cpl_regex *filter); +cpl_multiframe * +cpl_multiframe_new(const cpl_frame *head, const char *id, cpl_regex *filter); void cpl_multiframe_delete(cpl_multiframe *self); cpl_size cpl_multiframe_get_size(const cpl_multiframe *self); @@ -171,34 +170,39 @@ const cpl_regex *filter2, unsigned int flags); -cpl_error_code cpl_multiframe_append_dataset_from_position(cpl_multiframe *self, - const char *id, - const cpl_frame *frame, - cpl_size position, - const cpl_regex *filter1, - const cpl_regex *filter2, - unsigned int flags); +cpl_error_code +cpl_multiframe_append_dataset_from_position(cpl_multiframe *self, + const char *id, + const cpl_frame *frame, + cpl_size position, + const cpl_regex *filter1, + const cpl_regex *filter2, + unsigned int flags); -cpl_error_code cpl_multiframe_append_datagroup(cpl_multiframe *self, const char *id, +cpl_error_code cpl_multiframe_append_datagroup(cpl_multiframe *self, + const char *id, const cpl_frame *frame, - cpl_size nsets, const char **names, + cpl_size nsets, + const char **names, const cpl_regex **filter1, const cpl_regex **filter2, const char **properties, unsigned int flags); -cpl_error_code cpl_multiframe_append_datagroup_from_position(cpl_multiframe *self, const char *id, - const cpl_frame *frame, - cpl_size nsets, cpl_size *positions, - const cpl_regex **filter1, - const cpl_regex **filter2, - const char **properties, - unsigned int flags); +cpl_error_code +cpl_multiframe_append_datagroup_from_position(cpl_multiframe *self, + const char *id, + const cpl_frame *frame, + cpl_size nsets, + cpl_size *positions, + const cpl_regex **filter1, + const cpl_regex **filter2, + const char **properties, + unsigned int flags); cpl_error_code cpl_multiframe_add_empty(cpl_multiframe *self, const char *id); -cpl_error_code cpl_multiframe_write(cpl_multiframe *self, - const char *filename); +cpl_error_code cpl_multiframe_write(cpl_multiframe *self, const char *filename); CPL_END_DECLS diff -Nru cpl-7.1.4+ds/cpldfs/Makefile.am cpl-7.2.2+ds/cpldfs/Makefile.am --- cpl-7.1.4+ds/cpldfs/Makefile.am 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cpldfs/Makefile.am 2022-04-29 14:56:02.000000000 +0000 @@ -1,7 +1,7 @@ ## Process this file with automake to produce Makefile.in ## This file is part of the ESO Common Pipeline Library -## Copyright (C) 2001-2017 European Southern Observatory +## Copyright (C) 2001-2022 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 diff -Nru cpl-7.1.4+ds/cpldfs/Makefile.in cpl-7.2.2+ds/cpldfs/Makefile.in --- cpl-7.1.4+ds/cpldfs/Makefile.in 2021-05-07 12:10:10.000000000 +0000 +++ cpl-7.2.2+ds/cpldfs/Makefile.in 2022-04-29 14:56:28.000000000 +0000 @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.15.1 from Makefile.am. +# Makefile.in generated by automake 1.16.3 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2017 Free Software Foundation, Inc. +# Copyright (C) 1994-2020 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -158,7 +158,9 @@ am__v_at_1 = DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) depcomp = $(SHELL) $(top_srcdir)/admin/depcomp -am__depfiles_maybe = depfiles +am__maybe_remake_depfiles = depfiles +am__depfiles_remade = ./$(DEPDIR)/cpl_dfs.Plo \ + ./$(DEPDIR)/cpl_multiframe.Plo am__mv = mv -f COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) @@ -201,7 +203,7 @@ $(RECURSIVE_CLEAN_TARGETS) \ $(am__extra_recursive_targets) AM_RECURSIVE_TARGETS = $(am__recursive_targets:-recursive=) TAGS CTAGS \ - distdir + distdir distdir-am 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 @@ -267,6 +269,7 @@ CPLCORE_INCLUDES = @CPLCORE_INCLUDES@ CPLDFS_INCLUDES = @CPLDFS_INCLUDES@ CPLDRS_INCLUDES = @CPLDRS_INCLUDES@ +CPLJAVA_INCLUDES = @CPLJAVA_INCLUDES@ CPLUI_INCLUDES = @CPLUI_INCLUDES@ CPL_BINARY_AGE = @CPL_BINARY_AGE@ CPL_BINARY_VERSION = @CPL_BINARY_VERSION@ @@ -327,6 +330,7 @@ LIBCPLCORE = @LIBCPLCORE@ LIBCPLDFS = @LIBCPLDFS@ LIBCPLDRS = @LIBCPLDRS@ +LIBCPLGASGANO = @LIBCPLGASGANO@ LIBCPLUI = @LIBCPLUI@ LIBFFTW = @LIBFFTW@ LIBFFTWF = @LIBFFTWF@ @@ -433,6 +437,7 @@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ @@ -483,8 +488,8 @@ *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);; \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ esac; $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) @@ -540,8 +545,14 @@ distclean-compile: -rm -f *.tab.c -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_dfs.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_multiframe.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_dfs.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_multiframe.Plo@am__quote@ # am--include-marker + +$(am__depfiles_remade): + @$(MKDIR_P) $(@D) + @echo '# dummy' >$@-t && $(am__mv) $@-t $@ + +am--depfiles: $(am__depfiles_remade) .c.o: @am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @@ -690,7 +701,10 @@ distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags -distdir: $(DISTFILES) +distdir: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) distdir-am + +distdir-am: $(DISTFILES) @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ list='$(DISTFILES)'; \ @@ -791,7 +805,8 @@ mostlyclean-am distclean: distclean-recursive - -rm -rf ./$(DEPDIR) + -rm -f ./$(DEPDIR)/cpl_dfs.Plo + -rm -f ./$(DEPDIR)/cpl_multiframe.Plo -rm -f Makefile distclean-am: clean-am distclean-compile distclean-generic \ distclean-tags @@ -837,7 +852,8 @@ installcheck-am: maintainer-clean: maintainer-clean-recursive - -rm -rf ./$(DEPDIR) + -rm -f ./$(DEPDIR)/cpl_dfs.Plo + -rm -f ./$(DEPDIR)/cpl_multiframe.Plo -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic @@ -858,21 +874,22 @@ .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-libLTLIBRARIES \ - clean-libtool 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-includeHEADERS install-info \ - install-info-am install-libLTLIBRARIES 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 \ - uninstall-includeHEADERS uninstall-libLTLIBRARIES +.PHONY: $(am__recursive_targets) CTAGS GTAGS TAGS all all-am \ + am--depfiles check check-am clean clean-generic \ + clean-libLTLIBRARIES clean-libtool 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-includeHEADERS install-info install-info-am \ + install-libLTLIBRARIES 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 uninstall-includeHEADERS \ + uninstall-libLTLIBRARIES .PRECIOUS: Makefile diff -Nru cpl-7.1.4+ds/cpldfs/md5.c cpl-7.2.2+ds/cpldfs/md5.c --- cpl-7.1.4+ds/cpldfs/md5.c 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cpldfs/md5.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -21,7 +21,7 @@ Includes -----------------------------------------------------------------------------*/ -#include +#include #include "md5.h" @@ -29,12 +29,11 @@ Private Function prototypes -----------------------------------------------------------------------------*/ -static void MD5Transform(word32 buf[4], word32 const in[16]) - CPL_ATTR_NONNULL; +static void MD5Transform(word32 buf[4], word32 const in[16]) CPL_ATTR_NONNULL; #if defined(WORDS_BIGENDIAN) && WORDS_BIGENDIAN != 0 -inline static void byteReverse(unsigned char * restrict buf, unsigned longs) - CPL_ATTR_NONNULL; +inline static void +byteReverse(unsigned char *restrict buf, unsigned longs) CPL_ATTR_NONNULL; #else #define byteReverse(BUF, LONGS) /* Do nothing */ #endif @@ -78,7 +77,8 @@ * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious * initialization constants. */ -static void MD5Init(struct MD5Context * restrict ctx) +static void +MD5Init(struct MD5Context *restrict ctx) { ctx->buf[0] = 0x67452301; ctx->buf[1] = 0xefcdab89; @@ -93,44 +93,46 @@ * Update context to reflect the concatenation of another buffer full * of bytes. */ -static void MD5Update(struct MD5Context * restrict ctx, - unsigned char const * restrict buf, unsigned len) +static void +MD5Update(struct MD5Context *restrict ctx, + unsigned char const *restrict buf, + unsigned len) { register word32 t; /* Update bitcount */ t = ctx->bits[0]; - if ((ctx->bits[0] = t + ((word32) len << 3)) < t) - ctx->bits[1]++; /* Carry from low to high */ + if ((ctx->bits[0] = t + ((word32)len << 3)) < t) + ctx->bits[1]++; /* Carry from low to high */ ctx->bits[1] += len >> 29; - t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */ + t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */ /* Handle any leading odd-sized chunks */ if (t) { - unsigned char *p = (unsigned char *) ctx->in + t; + unsigned char *p = (unsigned char *)ctx->in + t; - t = 64 - t; - if (len < t) { - memcpy(p, buf, len); - return; - } - memcpy(p, buf, t); - byteReverse(ctx->in, 16); - MD5Transform(ctx->buf, (word32 *) ctx->in); - buf += t; - len -= t; + t = 64 - t; + if (len < t) { + memcpy(p, buf, len); + return; + } + memcpy(p, buf, t); + byteReverse(ctx->in, 16); + MD5Transform(ctx->buf, (word32 *)ctx->in); + buf += t; + len -= t; } /* Process data in 64-byte chunks */ while (len >= 64) { - memcpy(ctx->in, buf, 64); - byteReverse(ctx->in, 16); - MD5Transform(ctx->buf, (word32 *) ctx->in); - buf += 64; - len -= 64; + memcpy(ctx->in, buf, 64); + byteReverse(ctx->in, 16); + MD5Transform(ctx->buf, (word32 *)ctx->in); + buf += 64; + len -= 64; } /* Handle any remaining bytes of data. */ @@ -142,8 +144,8 @@ * Final wrapup - pad to 64-byte boundary with the bit pattern * 1 0* (64-bit count of bits processed, MSB-first) */ -static void MD5Final(unsigned char * restrict digest, - struct MD5Context * restrict ctx) +static void +MD5Final(unsigned char *restrict digest, struct MD5Context *restrict ctx) { unsigned int count; unsigned char *p; @@ -161,16 +163,17 @@ /* Pad out to 56 mod 64 */ if (count < 8) { - /* Two lots of padding: Pad the first block to 64 bytes */ - memset(p, 0, count); - byteReverse(ctx->in, 16); - MD5Transform(ctx->buf, (word32 *) ctx->in); - - /* Now fill the next block with 56 bytes */ - memset(ctx->in, 0, 56); - } else { - /* Pad block to 56 bytes */ - memset(p, 0, count - 8); + /* Two lots of padding: Pad the first block to 64 bytes */ + memset(p, 0, count); + byteReverse(ctx->in, 16); + MD5Transform(ctx->buf, (word32 *)ctx->in); + + /* Now fill the next block with 56 bytes */ + memset(ctx->in, 0, 56); + } + else { + /* Pad block to 56 bytes */ + memset(p, 0, count - 8); } byteReverse(ctx->in, 14); @@ -181,10 +184,10 @@ */ (void)memcpy(ctx->in + 56, ctx->bits, 8); - MD5Transform(ctx->buf, (word32 *) ctx->in); - byteReverse((unsigned char *) ctx->buf, 4); + MD5Transform(ctx->buf, (word32 *)ctx->in); + byteReverse((unsigned char *)ctx->buf, 4); memcpy(digest, ctx->buf, 16); - memset(ctx, 0, sizeof(*ctx)); /* In case it's sensitive */ + memset(ctx, 0, sizeof(*ctx)); /* In case it's sensitive */ } /* The four core functions - F1 is optimized somewhat */ @@ -197,14 +200,15 @@ /* This is the central step in the MD5 algorithm. */ #define MD5STEP(f, w, x, y, z, data, s) \ - ( w += f(x, y, z) + data, w = w<>(32-s), w += x ) + (w += f(x, y, z) + data, w = w << s | w >> (32 - s), w += x) /* * The core of the MD5 algorithm, this alters an existing MD5 hash to * reflect the addition of 16 longwords of new data. MD5Update blocks * the data and converts bytes into longwords for this routine. */ -static void MD5Transform(word32 buf[4], word32 const in[16]) +static void +MD5Transform(word32 buf[4], word32 const in[16]) { register word32 a, b, c, d; @@ -288,14 +292,15 @@ } #if defined(WORDS_BIGENDIAN) && WORDS_BIGENDIAN != 0 -inline static void byteReverse(unsigned char * restrict buf, unsigned longs) +inline static void +byteReverse(unsigned char *restrict buf, unsigned longs) { word32 t; do { - t = (word32) ((unsigned) buf[3] << 8 | buf[2]) << 16 | - ((unsigned) buf[1] << 8 | buf[0]); - *(word32 *) buf = t; - buf += 4; + t = (word32)((unsigned)buf[3] << 8 | buf[2]) << 16 | + ((unsigned)buf[1] << 8 | buf[0]); + *(word32 *)buf = t; + buf += 4; } while (--longs); } #endif diff -Nru cpl-7.1.4+ds/cpldfs/md5.h cpl-7.2.2+ds/cpldfs/md5.h --- cpl-7.1.4+ds/cpldfs/md5.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cpldfs/md5.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -22,25 +22,23 @@ typedef unsigned int word32; -struct MD5Context { +struct MD5Context +{ word32 buf[4]; word32 bits[2]; unsigned char in[64]; }; -static void MD5Init(struct MD5Context * restrict context) - CPL_ATTR_NONNULL; -static void MD5Update(struct MD5Context * restrict context, - unsigned char const * restrict buf, - unsigned len) - CPL_ATTR_NONNULL; -static void MD5Final(unsigned char * restrict digest, - struct MD5Context * restrict context) - CPL_ATTR_NONNULL; +static void MD5Init(struct MD5Context *restrict context) CPL_ATTR_NONNULL; +static void MD5Update(struct MD5Context *restrict context, + unsigned char const *restrict buf, + unsigned len) CPL_ATTR_NONNULL; +static void MD5Final(unsigned char *restrict digest, + struct MD5Context *restrict context) CPL_ATTR_NONNULL; /* * This is needed to make RSAREF happy on some MS-DOS compilers. */ typedef struct MD5Context MD5_CTX; -#endif +#endif diff -Nru cpl-7.1.4+ds/cpldfs/tests/cpl_dfs-test.c cpl-7.2.2+ds/cpldfs/tests/cpl_dfs-test.c --- cpl-7.1.4+ds/cpldfs/tests/cpl_dfs-test.c 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cpldfs/tests/cpl_dfs-test.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -33,14 +33,15 @@ #include "cpl_image.h" #include "cpl_io_fits.h" +#include "cpl_fits.h" /*----------------------------------------------------------------------------- Defines -----------------------------------------------------------------------------*/ -#define IMAGE_SIZE_X 1009 -#define IMAGE_SIZE_Y 1031 -#define IMAGE_NEXT 32 +#define IMAGE_SIZE_X 1009 +#define IMAGE_SIZE_Y 1031 +#define IMAGE_NEXT 32 #define CPL_DFS_RAW_ASCII "ascii.txt" #define CPL_DFS_FITSFILE "product.fits" @@ -49,6 +50,8 @@ Private declarations -----------------------------------------------------------------------------*/ +static void cpl_dfs_product_test_one(const char *, const char *); + static void cpl_dfs_product_tests(const char *); static void cpl_dfs_save_tests(const char *); @@ -57,17 +60,17 @@ static void cpl_dfs_parameterlist_fill(cpl_parameterlist *); -static void cpl_dfs_propertylist_append_dicb(cpl_propertylist *) - CPL_ATTR_NONNULL; +static void +cpl_dfs_propertylist_append_dicb(cpl_propertylist *) CPL_ATTR_NONNULL; /*----------------------------------------------------------------------------- Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(int argc, char *argv[]) { - - cpl_propertylist * plist = NULL; - cpl_error_code code; + cpl_propertylist *plist = NULL; + cpl_error_code code; cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); @@ -80,8 +83,7 @@ code = cpl_propertylist_append_int(plist, "EQUINOX", 2000); cpl_test_eq_error(code, CPL_ERROR_NONE); - cpl_image_save(NULL, "inherit.fits", - CPL_TYPE_FLOAT, plist, CPL_IO_CREATE); + cpl_image_save(NULL, "inherit.fits", CPL_TYPE_FLOAT, plist, CPL_IO_CREATE); cpl_propertylist_delete(plist); /* Insert tests here */ @@ -92,40 +94,44 @@ remove(CPL_DFS_RAW_ASCII); + if (argc == 3) { + cpl_dfs_product_test_one(argv[1], argv[2]); + } + /* Testing finished */ return cpl_test_end(0); - } -static void cpl_dfs_product_tests(const char * rawname) +static void +cpl_dfs_product_tests(const char *rawname) { - cpl_frame * rawframe; - cpl_frame * inhframe; - cpl_frame * proframe; - cpl_frame * emptyframe; - cpl_frameset * frameset = NULL; - cpl_propertylist * plist = NULL; - cpl_parameterlist * parlist = NULL; - cpl_image * image; - const char * md5sum; - - cpl_error_code error; - const int next = IMAGE_NEXT; - int fstatus = 0; /* CFITSIO error status */ - int i; + cpl_frame *rawframe; + cpl_frame *inhframe; + cpl_frame *proframe; + cpl_frame *emptyframe; + cpl_frameset *frameset = NULL; + cpl_propertylist *plist = NULL; + cpl_parameterlist *parlist = NULL; + cpl_image *image; + const char *md5sum; + + cpl_error_code error; + const int next = IMAGE_NEXT; + int fstatus = 0; /* CFITSIO error status */ + int i; /* Test 1: Check the error handling of NULL-pointer(s) */ - error = cpl_dfs_setup_product_header(NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL); + error = cpl_dfs_setup_product_header(NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL); - cpl_test_eq_error( error, CPL_ERROR_NULL_INPUT); + cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT); /* Test 1a: Check the error handling of NULL-pointer(s) */ error = cpl_dfs_update_product_header(NULL); - cpl_test_eq_error( error, CPL_ERROR_NULL_INPUT); + cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT); /* Test 2: Check the error handling of an empty frame/frameset */ @@ -136,26 +142,25 @@ /* Insert CHECKSUM and DATASUM (with wrong values) */ - error = cpl_propertylist_append_string(plist, "CHECKSUM", - "BADAKIZUEUSKARAZ"); + error = + cpl_propertylist_append_string(plist, "CHECKSUM", "BADAKIZUEUSKARAZ"); cpl_test_eq_error(error, CPL_ERROR_NONE); error = cpl_propertylist_set_comment(plist, "CHECKSUM", "HDU checksum"); cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_propertylist_append_string(plist, "DATASUM", - "3141592653"); + error = cpl_propertylist_append_string(plist, "DATASUM", "3141592653"); cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_propertylist_set_comment(plist, "DATASUM", - "data unit checksum"); + error = + cpl_propertylist_set_comment(plist, "DATASUM", "data unit checksum"); cpl_test_eq_error(error, CPL_ERROR_NONE); cpl_dfs_parameterlist_fill(parlist); - error = cpl_dfs_setup_product_header(plist, proframe, frameset, parlist, - "Recipe", "Pipeline", "PRO-1.16", - NULL); + error = + cpl_dfs_setup_product_header(plist, proframe, frameset, parlist, + "Recipe", "Pipeline", "PRO-1.16", NULL); - cpl_test_eq_error( error, CPL_ERROR_DATA_NOT_FOUND); + cpl_test_eq_error(error, CPL_ERROR_DATA_NOT_FOUND); /* Test 2a: Check the handling of an empty frameset */ @@ -173,11 +178,11 @@ error = cpl_frameset_insert(frameset, rawframe); cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_dfs_setup_product_header(plist, proframe, frameset, parlist, - "Recipe", "Pipeline", "PRO-1.16", - NULL); + error = + cpl_dfs_setup_product_header(plist, proframe, frameset, parlist, + "Recipe", "Pipeline", "PRO-1.16", NULL); - cpl_test_eq_error( error, CPL_ERROR_DATA_NOT_FOUND); + cpl_test_eq_error(error, CPL_ERROR_DATA_NOT_FOUND); cpl_frameset_delete(frameset); /* Test 4: Check the error handling of an empty product frame @@ -195,11 +200,11 @@ cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_dfs_setup_product_header(plist, proframe, frameset, parlist, - "Recipe", "Pipeline", "PRO-1.16", - NULL); + error = + cpl_dfs_setup_product_header(plist, proframe, frameset, parlist, + "Recipe", "Pipeline", "PRO-1.16", NULL); - cpl_test_eq_error( error, CPL_ERROR_DATA_NOT_FOUND); + cpl_test_eq_error(error, CPL_ERROR_DATA_NOT_FOUND); /* Test 4c: Check the error handling of an product frame with a (non-fits) @@ -209,10 +214,10 @@ error = cpl_frame_set_filename(proframe, CPL_DFS_FITSFILE); cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_dfs_setup_product_header(plist, proframe, frameset, parlist, - "Recipe", "Pipeline", "PRO-1.16", - NULL); - cpl_test_eq_error( error, CPL_ERROR_ILLEGAL_INPUT); + error = + cpl_dfs_setup_product_header(plist, proframe, frameset, parlist, + "Recipe", "Pipeline", "PRO-1.16", NULL); + cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); /* Test 4d: Check the error handling of an product frame with a filename and tagged (and a valid, non-fits rawframe) - should fail on missing @@ -221,9 +226,9 @@ error = cpl_frame_set_tag(proframe, "PRODUCT"); cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_dfs_setup_product_header(plist, proframe, frameset, parlist, - "Recipe", "Pipeline", "PRO-1.16", - NULL); + error = + cpl_dfs_setup_product_header(plist, proframe, frameset, parlist, + "Recipe", "Pipeline", "PRO-1.16", NULL); cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); /* Set product group */ @@ -233,23 +238,23 @@ /* Test 5c: Check the error handling of an inherit-frame not present in the frameset */ - error = cpl_dfs_setup_product_header(plist, proframe, frameset, - parlist, "Recipe", "Pipeline", - "PRO-1.16", proframe); + error = cpl_dfs_setup_product_header(plist, proframe, frameset, parlist, + "Recipe", "Pipeline", "PRO-1.16", + proframe); - cpl_test_eq_error( error, CPL_ERROR_ILLEGAL_INPUT); + cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); /* Test 5: 2 simple successful calls */ - error = cpl_dfs_setup_product_header(plist, proframe, frameset, - parlist, "Recipe", "Pipeline", - "PRO-1.16", NULL); + error = + cpl_dfs_setup_product_header(plist, proframe, frameset, parlist, + "Recipe", "Pipeline", "PRO-1.16", NULL); cpl_test_eq_error(error, CPL_ERROR_NONE); cpl_test_zero(cpl_propertylist_has(plist, "CHECKSUM")); cpl_test_zero(cpl_propertylist_has(plist, "DATASUM")); - cpl_msg_debug("","Size of product header: %" CPL_SIZE_FORMAT, + cpl_msg_debug("", "Size of product header: %" CPL_SIZE_FORMAT, cpl_propertylist_get_size(plist)); inhframe = cpl_frame_new(); @@ -266,15 +271,15 @@ as an integer, since that format is also valid */ cpl_propertylist_append_int(plist, "EQUINOX", 2000); - error = cpl_dfs_setup_product_header(plist, proframe, frameset, - parlist, "Recipe", "Pipeline", - "PRO-1.16", inhframe); + error = cpl_dfs_setup_product_header(plist, proframe, frameset, parlist, + "Recipe", "Pipeline", "PRO-1.16", + inhframe); cpl_test_eq_error(error, CPL_ERROR_NONE); cpl_test_zero(cpl_propertylist_has(plist, "CHECKSUM")); cpl_test_zero(cpl_propertylist_has(plist, "DATASUM")); - cpl_msg_debug("","Size of product header: %" CPL_SIZE_FORMAT, + cpl_msg_debug("", "Size of product header: %" CPL_SIZE_FORMAT, cpl_propertylist_get_size(plist)); cpl_propertylist_append_char(plist, "ESO QC MYCHAR", 42); @@ -283,8 +288,8 @@ cpl_propertylist_append_string(plist, "ARCFILE", "IIINSTRUME.2013-08-28T12:50:43.3381"); - error = cpl_dfs_save_paf("IIINSTRUME", "RRRECIPE", plist, - "cpl_dfs-test.paf"); + error = + cpl_dfs_save_paf("IIINSTRUME", "RRRECIPE", plist, "cpl_dfs-test.paf"); cpl_test_eq_error(error, CPL_ERROR_NONE); #if 0 @@ -306,23 +311,23 @@ cpl_test_eq_error(error, CPL_ERROR_NONE); error = cpl_dfs_update_product_header(frameset); - cpl_test_eq_error( error, CPL_ERROR_BAD_FILE_FORMAT); + cpl_test_eq_error(error, CPL_ERROR_BAD_FILE_FORMAT); /* Test 5b: Check the error handling of an inherit-frame present in the frameset, but not present on the filesystem */ - error = cpl_dfs_setup_product_header(plist, proframe, frameset, - parlist, "Recipe", "Pipeline", - "PRO-1.16", proframe); + error = cpl_dfs_setup_product_header(plist, proframe, frameset, parlist, + "Recipe", "Pipeline", "PRO-1.16", + proframe); + + cpl_test_eq_error(error, CPL_ERROR_FILE_NOT_FOUND); - cpl_test_eq_error( error, CPL_ERROR_FILE_NOT_FOUND); - /* Test 5c: Check error handling when given an empty frame with no filename set. */ emptyframe = cpl_frame_new(); - error = cpl_dfs_setup_product_header(plist, proframe, frameset, - parlist, "Recipe", "Pipeline", - "PRO-1.16", emptyframe); + error = cpl_dfs_setup_product_header(plist, proframe, frameset, parlist, + "Recipe", "Pipeline", "PRO-1.16", + emptyframe); cpl_test_eq_error(error, CPL_ERROR_DATA_NOT_FOUND); cpl_frame_delete(emptyframe); @@ -340,7 +345,7 @@ error = cpl_dfs_update_product_header(frameset); - cpl_test_eq_error( error, CPL_ERROR_BAD_FILE_FORMAT); + cpl_test_eq_error(error, CPL_ERROR_BAD_FILE_FORMAT); /* Test 6a: Also support non-fits */ @@ -358,8 +363,8 @@ as an integer, since that format is also valid */ cpl_propertylist_append_int(plist, "EQUINOX", 2000); - cpl_test_zero(cpl_image_save(NULL, CPL_DFS_FITSFILE, CPL_TYPE_UCHAR, - plist, CPL_IO_CREATE)); + cpl_test_zero(cpl_image_save(NULL, CPL_DFS_FITSFILE, CPL_TYPE_UCHAR, plist, + CPL_IO_CREATE)); cpl_test_fits(CPL_DFS_FITSFILE); error = cpl_dfs_update_product_header(frameset); @@ -394,8 +399,8 @@ cpl_test(cpl_propertylist_has(plist, "EQUINOX")); - cpl_test_zero(cpl_image_save(image, CPL_DFS_FITSFILE, CPL_TYPE_UCHAR, - plist, CPL_IO_CREATE)); + cpl_test_zero(cpl_image_save(image, CPL_DFS_FITSFILE, CPL_TYPE_UCHAR, plist, + CPL_IO_CREATE)); cpl_test_fits(CPL_DFS_FITSFILE); error = cpl_dfs_update_product_header(frameset); @@ -421,8 +426,8 @@ /* Test 7c: A successful call of cpl_dfs_update_product_header() with a main HDU and one data-less extension */ - cpl_test_zero(cpl_image_save(NULL, CPL_DFS_FITSFILE, CPL_TYPE_UCHAR, - plist, CPL_IO_EXTEND)); + cpl_test_zero(cpl_image_save(NULL, CPL_DFS_FITSFILE, CPL_TYPE_UCHAR, plist, + CPL_IO_EXTEND)); cpl_test_fits(CPL_DFS_FITSFILE); error = cpl_dfs_update_product_header(frameset); @@ -449,8 +454,8 @@ with a main HDU, one data-less extension and one non-empty extension. */ - cpl_test_zero(cpl_image_save(image, CPL_DFS_FITSFILE, CPL_TYPE_UCHAR, - plist, CPL_IO_EXTEND)); + cpl_test_zero(cpl_image_save(image, CPL_DFS_FITSFILE, CPL_TYPE_UCHAR, plist, + CPL_IO_EXTEND)); cpl_test_fits(CPL_DFS_FITSFILE); error = cpl_dfs_update_product_header(frameset); @@ -484,17 +489,16 @@ image = cpl_image_new(IMAGE_SIZE_X, IMAGE_SIZE_Y, CPL_TYPE_INT); for (i = 0; i < next; i++) { - error = cpl_image_add_scalar(image, 1.0); cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_image_save(image, i % 2 ? CPL_DFS_FITSFILE - : "./" CPL_DFS_FITSFILE, i >= 255 ? CPL_TYPE_INT - : CPL_TYPE_UCHAR, plist, CPL_IO_EXTEND); + error = cpl_image_save(image, + i % 2 ? CPL_DFS_FITSFILE : "./" CPL_DFS_FITSFILE, + i >= 255 ? CPL_TYPE_INT : CPL_TYPE_UCHAR, plist, + CPL_IO_EXTEND); cpl_test_eq_error(error, CPL_ERROR_NONE); cpl_test_fits(CPL_DFS_FITSFILE); - } error = cpl_dfs_update_product_header(frameset); @@ -532,14 +536,13 @@ /* Test 9: A successful call of cpl_dfs_update_product_header() - after renaming the file */ do { - /* Renaming the file attribute of a frame belonging to a frameset is not allowed. This strange limitation requires a cumbersome work-around :-( */ - cpl_frameset * newframes = cpl_frameset_new(); - const char * newformat = "newname_%04d.fits"; - cpl_frame * newframe; + cpl_frameset *newframes = cpl_frameset_new(); + const char *newformat = "newname_%04d.fits"; + cpl_frame *newframe; cpl_frameset_iterator *it = cpl_frameset_iterator_new(frameset); const cpl_frame *frame = cpl_frameset_iterator_get_const(it); @@ -554,13 +557,12 @@ cpl_errorstate status; if (cpl_frame_get_group(frame) == CPL_FRAME_GROUP_PRODUCT) { - const cpl_frame_type type = cpl_frame_get_type(frame); if (type == CPL_FRAME_TYPE_TABLE || type == CPL_FRAME_TYPE_IMAGE) { - const char * oldname = cpl_frame_get_filename(frame); - char * newname = cpl_sprintf(newformat, ++i); + const char *oldname = cpl_frame_get_filename(frame); + char *newname = cpl_sprintf(newformat, ++i); /* Rename product */ cpl_test_zero(rename(oldname, newname)); @@ -573,7 +575,6 @@ error = cpl_frameset_insert(newframes, newframe); cpl_test_eq_error(error, CPL_ERROR_NONE); - } } @@ -586,7 +587,6 @@ } frame = cpl_frameset_iterator_get_const(it); - } cpl_frameset_iterator_delete(it); @@ -600,12 +600,13 @@ /* Do not remove file(s) if there was a failure */ if (cpl_error_get_code() == CPL_ERROR_NONE) { for (; i; i--) { - char * newname = cpl_sprintf(newformat, i); + char *newname = cpl_sprintf(newformat, i); error = remove(newname); cpl_free(newname); - if (error) break; + if (error) + break; } cpl_test_zero(i); } @@ -617,54 +618,52 @@ cpl_parameterlist_delete(parlist); return; - } -static void cpl_dfs_save_tests(const char * rawname) +static void +cpl_dfs_save_tests(const char *rawname) { - - cpl_error_code error; - const char * remregexp = "DROP"; - cpl_frameset * frames = NULL; - cpl_propertylist * tlist = NULL; - cpl_propertylist * qclist = NULL; - cpl_parameterlist * parlist = NULL; - cpl_image * image = NULL; - cpl_imagelist * imlist = NULL; - cpl_table * table = NULL; - cpl_frame * rawframe = cpl_frame_new(); - int framesetsize; + cpl_error_code error; + const char *remregexp = "DROP"; + cpl_frameset *frames = NULL; + cpl_propertylist *tlist = NULL; + cpl_propertylist *qclist = NULL; + cpl_parameterlist *parlist = NULL; + cpl_image *image = NULL; + cpl_imagelist *imlist = NULL; + cpl_table *table = NULL; + cpl_frame *rawframe = cpl_frame_new(); + int framesetsize; /* Test 1: Check the error handling of NULL-pointer(s) */ error = cpl_dfs_save_image(frames, NULL, parlist, frames, NULL, image, - CPL_TYPE_UCHAR, - "recipe", qclist, "none", "pipe_id", - CPL_DFS_FITSFILE); + CPL_TYPE_UCHAR, "recipe", qclist, "none", + "pipe_id", CPL_DFS_FITSFILE); cpl_test_eq(error, CPL_ERROR_NULL_INPUT); error = cpl_dfs_save_imagelist(frames, NULL, parlist, frames, NULL, imlist, - CPL_TYPE_UCHAR, "recipe", - qclist, "none", "pipe_id", CPL_DFS_FITSFILE); + CPL_TYPE_UCHAR, "recipe", qclist, "none", + "pipe_id", CPL_DFS_FITSFILE); - cpl_test_eq_error( error, CPL_ERROR_NULL_INPUT); + cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT); error = cpl_dfs_save_table(frames, NULL, parlist, frames, NULL, table, tlist, "recipe", qclist, "none", "pipe_id", CPL_DFS_FITSFILE); - cpl_test_eq_error( error, CPL_ERROR_NULL_INPUT); + cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT); error = cpl_dfs_save_paf("INSTRUME", "recipe", qclist, CPL_DFS_FITSFILE); - cpl_test_eq_error( error, CPL_ERROR_NULL_INPUT); + cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT); - frames = cpl_frameset_new(); - tlist = cpl_propertylist_new(); - qclist = cpl_propertylist_new(); + frames = cpl_frameset_new(); + tlist = cpl_propertylist_new(); + qclist = cpl_propertylist_new(); parlist = cpl_parameterlist_new(); table = cpl_table_new(1); imlist = cpl_imagelist_new(); @@ -676,8 +675,8 @@ error = cpl_propertylist_append_int(qclist, "EQUINOX", 2000); cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_zero(cpl_propertylist_append_string(qclist, CPL_DFS_PRO_CATG, - "procat")); + cpl_test_zero( + cpl_propertylist_append_string(qclist, CPL_DFS_PRO_CATG, "procat")); cpl_dfs_propertylist_append_dicb(qclist); cpl_dfs_propertylist_append_dicb(tlist); @@ -685,27 +684,26 @@ /* Test 1a: Try an illegal filename */ error = cpl_dfs_save_paf("INSTRUME", "recipe", qclist, "."); - cpl_test_eq_error( error, CPL_ERROR_FILE_IO); + cpl_test_eq_error(error, CPL_ERROR_FILE_IO); /* Test 2: Check handling of empty objects (frameset) */ error = cpl_dfs_save_image(frames, NULL, parlist, frames, NULL, image, - CPL_TYPE_UCHAR, - "recipe", qclist, "none", "pipe_id", - "image" CPL_DFS_FITS); + CPL_TYPE_UCHAR, "recipe", qclist, "none", + "pipe_id", "image" CPL_DFS_FITS); - cpl_test_eq_error( error, CPL_ERROR_DATA_NOT_FOUND); + cpl_test_eq_error(error, CPL_ERROR_DATA_NOT_FOUND); error = cpl_dfs_save_imagelist(frames, NULL, parlist, frames, NULL, imlist, - CPL_TYPE_UCHAR, "recipe", - qclist, "none", "pipe_id", "imlist" CPL_DFS_FITS); + CPL_TYPE_UCHAR, "recipe", qclist, "none", + "pipe_id", "imlist" CPL_DFS_FITS); - cpl_test_eq_error( error, CPL_ERROR_DATA_NOT_FOUND); + cpl_test_eq_error(error, CPL_ERROR_DATA_NOT_FOUND); error = cpl_dfs_save_table(frames, NULL, parlist, frames, NULL, table, tlist, "recipe", qclist, "none", "pipe_id", "table" CPL_DFS_FITS); - cpl_test_eq_error( error, CPL_ERROR_DATA_NOT_FOUND); + cpl_test_eq_error(error, CPL_ERROR_DATA_NOT_FOUND); /* Test 3A: Check handling of empty objects (except frameset) - using a non-existing input file */ @@ -727,15 +725,14 @@ error = cpl_dfs_save_image(frames, NULL, parlist, frames, NULL, image, CPL_TYPE_UCHAR, "recipe", qclist, "none", "pipe_id", "image" CPL_DFS_FITS); - cpl_test_eq_error( error, CPL_ERROR_FILE_NOT_FOUND); - cpl_test_eq( cpl_frameset_get_size(frames), framesetsize); + cpl_test_eq_error(error, CPL_ERROR_FILE_NOT_FOUND); + cpl_test_eq(cpl_frameset_get_size(frames), framesetsize); error = cpl_dfs_save_imagelist(frames, NULL, parlist, frames, NULL, imlist, - CPL_TYPE_UCHAR, "recipe", - qclist, "none", "pipe_id", - "imlist" CPL_DFS_FITS); - cpl_test_eq_error( error, CPL_ERROR_FILE_NOT_FOUND); - cpl_test_eq( cpl_frameset_get_size(frames), framesetsize); + CPL_TYPE_UCHAR, "recipe", qclist, "none", + "pipe_id", "imlist" CPL_DFS_FITS); + cpl_test_eq_error(error, CPL_ERROR_FILE_NOT_FOUND); + cpl_test_eq(cpl_frameset_get_size(frames), framesetsize); /* Test 3B: Check handling of empty objects (except frameset) */ @@ -757,11 +754,10 @@ /* Make sure file does not exist */ (void)remove("imlist" CPL_DFS_FITS); error = cpl_dfs_save_imagelist(frames, NULL, parlist, frames, NULL, imlist, - CPL_TYPE_UCHAR, "recipe", - qclist, "none", "pipe_id", - "imlist" CPL_DFS_FITS); + CPL_TYPE_UCHAR, "recipe", qclist, "none", + "pipe_id", "imlist" CPL_DFS_FITS); cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); - cpl_test_eq( cpl_frameset_get_size(frames), framesetsize); + cpl_test_eq(cpl_frameset_get_size(frames), framesetsize); /* Test 3: Check handling of empty objects (except frameset + imagelist) */ @@ -772,21 +768,19 @@ /* Make sure file does not exist */ (void)remove("image" CPL_DFS_FITS); error = cpl_dfs_save_image(frames, NULL, parlist, frames, NULL, image, - CPL_TYPE_UCHAR, - "recipe", qclist, "none", "pipe_id", - "image" CPL_DFS_FITS); + CPL_TYPE_UCHAR, "recipe", qclist, "none", + "pipe_id", "image" CPL_DFS_FITS); cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_eq( cpl_frameset_get_size(frames), ++framesetsize); + cpl_test_eq(cpl_frameset_get_size(frames), ++framesetsize); cpl_test_fits("image" CPL_DFS_FITS); /* Make sure file does not exist */ (void)remove("imlist" CPL_DFS_FITS); error = cpl_dfs_save_imagelist(frames, NULL, parlist, frames, NULL, imlist, - CPL_TYPE_UCHAR, "recipe", - qclist, "none", "pipe_id", - "imlist" CPL_DFS_FITS); + CPL_TYPE_UCHAR, "recipe", qclist, "none", + "pipe_id", "imlist" CPL_DFS_FITS); cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_eq( cpl_frameset_get_size(frames), ++framesetsize); + cpl_test_eq(cpl_frameset_get_size(frames), ++framesetsize); cpl_test_fits("imlist" CPL_DFS_FITS); /* Make sure file does not exist */ @@ -796,12 +790,13 @@ "table" CPL_DFS_FITS); cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_eq( cpl_frameset_get_size(frames), ++framesetsize); + cpl_test_eq(cpl_frameset_get_size(frames), ++framesetsize); cpl_test_fits("table" CPL_DFS_FITS); /* Make sure file does not exist */ (void)remove("recipe" CPL_DFS_PAF); - error = cpl_dfs_save_paf("INSTRUME", "recipe", qclist, "recipe" CPL_DFS_PAF); + error = + cpl_dfs_save_paf("INSTRUME", "recipe", qclist, "recipe" CPL_DFS_PAF); cpl_test_eq_error(error, CPL_ERROR_NONE); @@ -811,36 +806,35 @@ /* Test 4: Check handling of empty objects (except frameset and qclist) */ /* And remove one property */ cpl_test_zero(cpl_propertylist_append_string(qclist, "ESO QC STRING", - "'Lorem ipsum'")); + "'Lorem ipsum'")); error = cpl_propertylist_append_int(qclist, "ESO QC INT", 42); cpl_test_eq_error(error, CPL_ERROR_NONE); /* Use the value 1/3 to see the accuracy in the FITS header */ - error = cpl_propertylist_append_float(qclist, "ESO QC FLOAT", 1.0F/3.0F); + error = cpl_propertylist_append_float(qclist, "ESO QC FLOAT", 1.0F / 3.0F); cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_zero(cpl_propertylist_append_double(qclist, "ESO QC DOUBLE", - 1.0/3.0)); + cpl_test_zero( + cpl_propertylist_append_double(qclist, "ESO QC DOUBLE", 1.0 / 3.0)); error = cpl_propertylist_append_string(qclist, "ESO QC DROP", "image"); cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_zero(cpl_propertylist_set_comment(qclist, "ESO QC STRING", - "string")); + cpl_test_zero( + cpl_propertylist_set_comment(qclist, "ESO QC STRING", "string")); error = cpl_propertylist_set_comment(qclist, "ESO QC INT", "int"); cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_zero(cpl_propertylist_set_comment(qclist, "ESO QC FLOAT", - "float")); - cpl_test_zero(cpl_propertylist_set_comment(qclist, "ESO QC DOUBLE", - "double")); + cpl_test_zero( + cpl_propertylist_set_comment(qclist, "ESO QC FLOAT", "float")); + cpl_test_zero( + cpl_propertylist_set_comment(qclist, "ESO QC DOUBLE", "double")); /* Make sure file does not exist */ (void)remove("image" CPL_DFS_FITS); image = cpl_image_new(1, 41, CPL_TYPE_FLOAT); error = cpl_dfs_save_image(frames, NULL, parlist, frames, NULL, image, - CPL_TYPE_UCHAR, "recipe", - qclist, remregexp, "pipe_id", - "image" CPL_DFS_FITS); + CPL_TYPE_UCHAR, "recipe", qclist, remregexp, + "pipe_id", "image" CPL_DFS_FITS); cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_eq( cpl_frameset_get_size(frames), ++framesetsize); + cpl_test_eq(cpl_frameset_get_size(frames), ++framesetsize); cpl_test_fits("image" CPL_DFS_FITS); @@ -866,17 +860,16 @@ "table" CPL_DFS_FITS); cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_eq( cpl_frameset_get_size(frames), ++framesetsize); + cpl_test_eq(cpl_frameset_get_size(frames), ++framesetsize); cpl_test_fits("table" CPL_DFS_FITS); /* Make sure file does not exist */ (void)remove("imlist" CPL_DFS_FITS); error = cpl_dfs_save_imagelist(frames, NULL, parlist, frames, NULL, imlist, - CPL_TYPE_UCHAR, "recipe", - qclist, "none", "pipe_id", - "imlist" CPL_DFS_FITS); + CPL_TYPE_UCHAR, "recipe", qclist, "none", + "pipe_id", "imlist" CPL_DFS_FITS); cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_eq( cpl_frameset_get_size(frames), ++framesetsize); + cpl_test_eq(cpl_frameset_get_size(frames), ++framesetsize); cpl_test_fits("imlist" CPL_DFS_FITS); /* Create an extension, with the QC list */ @@ -888,25 +881,25 @@ /* Make sure file does not exist */ (void)remove("nullimage" CPL_DFS_FITS); error = cpl_dfs_save_image(frames, NULL, parlist, frames, NULL, NULL, - CPL_TYPE_UCHAR, - "recipe", qclist, remregexp, "pipe_id", - "nullimage" CPL_DFS_FITS); + CPL_TYPE_UCHAR, "recipe", qclist, remregexp, + "pipe_id", "nullimage" CPL_DFS_FITS); cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_eq( cpl_frameset_get_size(frames), ++framesetsize); + cpl_test_eq(cpl_frameset_get_size(frames), ++framesetsize); cpl_test_fits("nullimage" CPL_DFS_FITS); /* Make sure file does not exist */ (void)remove("dataless" CPL_DFS_FITS); error = cpl_dfs_save_propertylist(frames, NULL, parlist, frames, NULL, - "recipe", qclist, remregexp, "pipe_id", - "dataless" CPL_DFS_FITS); + "recipe", qclist, remregexp, "pipe_id", + "dataless" CPL_DFS_FITS); cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_eq( cpl_frameset_get_size(frames), ++framesetsize); + cpl_test_eq(cpl_frameset_get_size(frames), ++framesetsize); cpl_test_fits("dataless" CPL_DFS_FITS); /* Make sure file does not exist */ (void)remove("recipe" CPL_DFS_PAF); - error = cpl_dfs_save_paf("INSTRUME", "recipe", qclist, "recipe" CPL_DFS_PAF); + error = + cpl_dfs_save_paf("INSTRUME", "recipe", qclist, "recipe" CPL_DFS_PAF); cpl_test_eq_error(error, CPL_ERROR_NONE); @@ -917,8 +910,7 @@ cpl_msg_info(cpl_func, "New size of frameset: %d", framesetsize); - if (cpl_test_get_failed() == 0 && - cpl_msg_get_level() > CPL_MSG_INFO) { + if (cpl_test_get_failed() == 0 && cpl_msg_get_level() > CPL_MSG_INFO) { cpl_test_zero(remove("imlist" CPL_DFS_FITS)); cpl_test_zero(remove("image" CPL_DFS_FITS)); cpl_test_zero(remove("table" CPL_DFS_FITS)); @@ -934,20 +926,18 @@ cpl_table_delete(table); return; - } -static void cpl_dfs_save_txt(const char * self) +static void +cpl_dfs_save_txt(const char *self) { + FILE *stream = fopen(self, "w"); - FILE * stream = fopen(self, "w"); - - cpl_test_nonnull( stream ); + cpl_test_nonnull(stream); cpl_test_leq(1, fprintf(stream, self, "SIMPLE ASCII file - not FITS\n")); - cpl_test_zero( fclose(stream)); - + cpl_test_zero(fclose(stream)); } @@ -960,41 +950,47 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_dfs_parameterlist_fill(cpl_parameterlist * self) +static void +cpl_dfs_parameterlist_fill(cpl_parameterlist *self) { - cpl_error_code error; - error = cpl_parameterlist_append - (self, cpl_parameter_new_value("my_bool", CPL_TYPE_BOOL, "test bool", - "bool context", CPL_TRUE)); + error = cpl_parameterlist_append( + self, cpl_parameter_new_value("my_bool", CPL_TYPE_BOOL, "test bool", + "bool context", CPL_TRUE)); cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_parameterlist_append - (self, cpl_parameter_new_value("my_int", CPL_TYPE_INT, "test integer", - "int context", 42)); + error = + cpl_parameterlist_append(self, + cpl_parameter_new_value("my_int", CPL_TYPE_INT, + "test integer", + "int context", 42)); cpl_test_eq_error(error, CPL_ERROR_NONE); /* Use the value 1/3 to see the accuracy in the FITS header */ - error = cpl_parameterlist_append - (self, cpl_parameter_new_value("my_double", CPL_TYPE_DOUBLE, - "test double", "double context", - 1.0/3.0)); + error = + cpl_parameterlist_append(self, cpl_parameter_new_value("my_double", + CPL_TYPE_DOUBLE, + "test double", + "double context", + 1.0 / 3.0)); cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_parameterlist_append - (self, cpl_parameter_new_value("my_string", CPL_TYPE_STRING, - "test string", "string context", - "Hello, World")); + error = + cpl_parameterlist_append(self, cpl_parameter_new_value("my_string", + CPL_TYPE_STRING, + "test string", + "string context", + "Hello, World")); cpl_test_eq_error(error, CPL_ERROR_NONE); /* The help text here has a newline and a tab both of which are not allowed in a FITS card. */ - error = cpl_parameterlist_append - (self, cpl_parameter_new_range("my_range", CPL_TYPE_INT, - "1 == Median,\n 2 == Mean.\t last word.", - "range context", 1, 1, 2)); + error = cpl_parameterlist_append( + self, cpl_parameter_new_range("my_range", CPL_TYPE_INT, + "1 == Median,\n 2 == Mean.\t last word.", + "range context", 1, 1, 2)); cpl_test_eq_error(error, CPL_ERROR_NONE); } @@ -1008,67 +1004,130 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_dfs_propertylist_append_dicb(cpl_propertylist * self) +static void +cpl_dfs_propertylist_append_dicb(cpl_propertylist *self) { - cpl_error_code code; /* Some FITS cards, ordered reversely according to DICB */ - code = cpl_propertylist_append_string(self, "NAXISKEYS", - "Nine letter card"); + code = + cpl_propertylist_append_string(self, "NAXISKEYS", "Nine letter card"); cpl_test_eq_error(code, CPL_ERROR_NONE); - code = cpl_propertylist_append_string(self, "COMMENT", - "Comment card"); + code = cpl_propertylist_append_string(self, "COMMENT", "Comment card"); cpl_test_eq_error(code, CPL_ERROR_NONE); - code = cpl_propertylist_append_string(self, "HISTORY", - "History card"); + code = cpl_propertylist_append_string(self, "HISTORY", "History card"); cpl_test_eq_error(code, CPL_ERROR_NONE); code = cpl_propertylist_append_string(self, "NAXISKEY", - "NAX IS KEY 8-letter card!"); + "NAX IS KEY 8-letter card!"); cpl_test_eq_error(code, CPL_ERROR_NONE); code = cpl_propertylist_append_string(self, "TBCOLKEY", - "TBCOL KEY 8-letter card!"); + "TBCOL KEY 8-letter card!"); cpl_test_eq_error(code, CPL_ERROR_NONE); code = cpl_propertylist_append_string(self, "TFORMKEY", - "TFORM KEY 8-letter card!"); + "TFORM KEY 8-letter card!"); cpl_test_eq_error(code, CPL_ERROR_NONE); code = cpl_propertylist_append_string(self, "ESO AA", - "ESO card, after standard ones"); + "ESO card, after standard ones"); cpl_test_eq_error(code, CPL_ERROR_NONE); code = cpl_propertylist_append_string(self, "ESO DET DID", - "ESO-VLT-DIC.NGCDCS-123456"); + "ESO-VLT-DIC.NGCDCS-123456"); cpl_test_eq_error(code, CPL_ERROR_NONE); - code = cpl_propertylist_append_string(self, "ESO INS DATE", - "2018-10-25"); + code = cpl_propertylist_append_string(self, "ESO INS DATE", "2018-10-25"); cpl_test_eq_error(code, CPL_ERROR_NONE); - code = cpl_propertylist_append_string(self, "ESO TEL DID", - "ESO-VLT-DIC.TCS"); + code = + cpl_propertylist_append_string(self, "ESO TEL DID", "ESO-VLT-DIC.TCS"); cpl_test_eq_error(code, CPL_ERROR_NONE); code = cpl_propertylist_append_double(self, "ESO GEN MOON PHASE", 0.5); cpl_test_eq_error(code, CPL_ERROR_NONE); code = cpl_propertylist_append_string(self, "ESO TPL DID", - "ESO-VLT-DIC.TPL-1.9"); + "ESO-VLT-DIC.TPL-1.9"); cpl_test_eq_error(code, CPL_ERROR_NONE); code = cpl_propertylist_append_string(self, "ESO OBS DID", - "ESO-VLT-DIC.OBS-1.12"); + "ESO-VLT-DIC.OBS-1.12"); cpl_test_eq_error(code, CPL_ERROR_NONE); - code = cpl_propertylist_append_string(self, "ESO DPR CATG", - "CALIB"); + code = cpl_propertylist_append_string(self, "ESO DPR CATG", "CALIB"); cpl_test_eq_error(code, CPL_ERROR_NONE); +} + +static void +cpl_dfs_product_test_one(const char *infilename, const char *outfilename) +{ + const cpl_size next = cpl_fits_count_extensions(infilename); + cpl_error_code code; + + cpl_assert(infilename != NULL); + cpl_assert(outfilename != NULL); + + for (cpl_size i = 0; i <= next; i++) { + cpl_propertylist *plist = + i == 0 ? cpl_propertylist_load_regexp(infilename, i, + "^ESO |" + "^COMMENT|" + "^DATAMD5|" + "^PIPEFILE|" + "^CHECKSUM|" + "^DATASUM", + 1) + : cpl_propertylist_load(infilename, i); + + + cpl_msg_info(cpl_func, "Reading %d", (int)i); + + if (i == 0) { + code = cpl_propertylist_save(plist, outfilename, CPL_IO_CREATE); + cpl_test_eq_error(code, CPL_ERROR_NONE); + } + else { + cpl_table *mytab = cpl_table_load(infilename, i, 0); + const double mymax = cpl_table_get_column_max(mytab, "Efficiency"); + + /* Unitless */ + code = cpl_table_set_column_unit(mytab, "Efficiency", ""); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + code = cpl_table_name_column(mytab, "Efficiency", + "Quantum_Efficiency"); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + code = cpl_table_duplicate_column(mytab, "Grating_Efficiency", + mytab, "Quantum_Efficiency"); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + cpl_msg_info(cpl_func, "Scaling efficiency from: %g", mymax); + + code = cpl_table_multiply_scalar(mytab, "Quantum_Efficiency", + 0.80 / mymax); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + code = cpl_table_multiply_scalar(mytab, "Grating_Efficiency", + 0.95 / mymax); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + code = + cpl_table_save(mytab, NULL, plist, outfilename, CPL_IO_EXTEND); + cpl_test_eq_error(code, CPL_ERROR_NONE); + + + cpl_table_delete(mytab); + } + + cpl_propertylist_delete(plist); + } + cpl_test_fits(outfilename); } diff -Nru cpl-7.1.4+ds/cpldfs/tests/Makefile.am cpl-7.2.2+ds/cpldfs/tests/Makefile.am --- cpl-7.1.4+ds/cpldfs/tests/Makefile.am 2021-05-07 12:09:10.000000000 +0000 +++ cpl-7.2.2+ds/cpldfs/tests/Makefile.am 2022-04-29 14:56:02.000000000 +0000 @@ -1,7 +1,7 @@ ## Process this file with automake to produce Makefile.in ## This file is part of the ESO Common Pipeline Library -## Copyright (C) 2001-2017 European Southern Observatory +## Copyright (C) 2001-2022 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 diff -Nru cpl-7.1.4+ds/cpldfs/tests/Makefile.in cpl-7.2.2+ds/cpldfs/tests/Makefile.in --- cpl-7.1.4+ds/cpldfs/tests/Makefile.in 2021-05-07 12:10:10.000000000 +0000 +++ cpl-7.2.2+ds/cpldfs/tests/Makefile.in 2022-04-29 14:56:28.000000000 +0000 @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.15.1 from Makefile.am. +# Makefile.in generated by automake 1.16.3 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2017 Free Software Foundation, Inc. +# Copyright (C) 1994-2020 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -130,7 +130,8 @@ am__v_at_1 = DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) depcomp = $(SHELL) $(top_srcdir)/admin/depcomp -am__depfiles_maybe = depfiles +am__maybe_remake_depfiles = depfiles +am__depfiles_remade = ./$(DEPDIR)/cpl_dfs-test.Po am__mv = mv -f COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) @@ -358,6 +359,7 @@ bases='$(TEST_LOGS)'; \ bases=`for i in $$bases; do echo $$i; done | sed 's/\.log$$//'`; \ bases=`echo $$bases` +AM_TESTSUITE_SUMMARY_HEADER = ' for $(PACKAGE_STRING)' RECHECK_LOGS = $(TEST_LOGS) AM_RECURSIVE_TARGETS = check recheck TEST_SUITE_LOG = test-suite.log @@ -401,6 +403,7 @@ CPLCORE_INCLUDES = @CPLCORE_INCLUDES@ CPLDFS_INCLUDES = @CPLDFS_INCLUDES@ CPLDRS_INCLUDES = @CPLDRS_INCLUDES@ +CPLJAVA_INCLUDES = @CPLJAVA_INCLUDES@ CPLUI_INCLUDES = @CPLUI_INCLUDES@ CPL_BINARY_AGE = @CPL_BINARY_AGE@ CPL_BINARY_VERSION = @CPL_BINARY_VERSION@ @@ -461,6 +464,7 @@ LIBCPLCORE = @LIBCPLCORE@ LIBCPLDFS = @LIBCPLDFS@ LIBCPLDRS = @LIBCPLDRS@ +LIBCPLGASGANO = @LIBCPLGASGANO@ LIBCPLUI = @LIBCPLUI@ LIBFFTW = @LIBFFTW@ LIBFFTWF = @LIBFFTWF@ @@ -567,6 +571,7 @@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ @@ -613,8 +618,8 @@ *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);; \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ esac; $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) @@ -645,7 +650,13 @@ distclean-compile: -rm -f *.tab.c -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_dfs-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_dfs-test.Po@am__quote@ # am--include-marker + +$(am__depfiles_remade): + @$(MKDIR_P) $(@D) + @echo '# dummy' >$@-t && $(am__mv) $@-t $@ + +am--depfiles: $(am__depfiles_remade) .c.o: @am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @@ -833,7 +844,7 @@ test x"$$VERBOSE" = x || cat $(TEST_SUITE_LOG); \ fi; \ echo "$${col}$$br$${std}"; \ - echo "$${col}Testsuite summary for $(PACKAGE_STRING)$${std}"; \ + echo "$${col}Testsuite summary"$(AM_TESTSUITE_SUMMARY_HEADER)"$${std}"; \ echo "$${col}$$br$${std}"; \ create_testsuite_report --maybe-color; \ echo "$$col$$br$$std"; \ @@ -846,7 +857,7 @@ fi; \ $$success || exit 1 -check-TESTS: +check-TESTS: $(check_PROGRAMS) @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) @@ -889,7 +900,10 @@ @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) +distdir: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) distdir-am + +distdir-am: $(DISTFILES) @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ list='$(DISTFILES)'; \ @@ -966,7 +980,7 @@ mostlyclean-am distclean: distclean-am - -rm -rf ./$(DEPDIR) + -rm -f ./$(DEPDIR)/cpl_dfs-test.Po -rm -f Makefile distclean-am: clean-am distclean-compile distclean-generic \ distclean-tags @@ -1012,7 +1026,7 @@ installcheck-am: maintainer-clean: maintainer-clean-am - -rm -rf ./$(DEPDIR) + -rm -f ./$(DEPDIR)/cpl_dfs-test.Po -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic @@ -1033,19 +1047,20 @@ .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 +.PHONY: CTAGS GTAGS TAGS all all-am am--depfiles 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 diff -Nru cpl-7.1.4+ds/cpldrs/cpl_apertures.c cpl-7.2.2+ds/cpldrs/cpl_apertures.c --- cpl-7.1.4+ds/cpldrs/cpl_apertures.c 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cpldrs/cpl_apertures.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -60,40 +60,41 @@ Type definition -----------------------------------------------------------------------------*/ -struct _cpl_apertures_ { +struct _cpl_apertures_ +{ /* Number of apertures */ - cpl_size naperts; + cpl_size naperts; /* All positions are in FITS conventions : (1,1) is the lower left) */ /* Aperture center: x=sum(x*1)/sum(1) */ - double * x; - double * y; + double *x; + double *y; /* The position of the aperture maximum */ - cpl_size* maxpos_x; - cpl_size* maxpos_y; + cpl_size *maxpos_x; + cpl_size *maxpos_y; /* The position of the aperture minimum */ - cpl_size* minpos_x; - cpl_size* minpos_y; + cpl_size *minpos_x; + cpl_size *minpos_y; /* Aperture weighted center : xcentroid=sum(x*f(x)) / sum(f(x)) */ - double * xcentroid; - double * ycentroid; + double *xcentroid; + double *ycentroid; - cpl_size* npix; - cpl_size* left_x; - cpl_size* left_y; - cpl_size* right_x; - cpl_size* right_y; - cpl_size* top_x; - cpl_size* top_y; - cpl_size* bottom_x; - cpl_size* bottom_y; - double * max_val; - double * min_val; - double * mean; - double * varsum; - double * median; - double * stdev; - double * flux; + cpl_size *npix; + cpl_size *left_x; + cpl_size *left_y; + cpl_size *right_x; + cpl_size *right_y; + cpl_size *top_x; + cpl_size *top_y; + cpl_size *bottom_x; + cpl_size *bottom_y; + double *max_val; + double *min_val; + double *mean; + double *varsum; + double *median; + double *stdev; + double *flux; }; @@ -101,10 +102,11 @@ Private functions -----------------------------------------------------------------------------*/ -static cpl_apertures * cpl_apertures_new(cpl_size) CPL_ATTR_ALLOC; -static cpl_apertures * cpl_apertures_new_from_image_(const cpl_image *, - const cpl_image *, - cpl_size, cpl_boolean); +static cpl_apertures *cpl_apertures_new(cpl_size) CPL_ATTR_ALLOC; +static cpl_apertures *cpl_apertures_new_from_image_(const cpl_image *, + const cpl_image *, + cpl_size, + cpl_boolean); /*----------------------------------------------------------------------------- Function codes @@ -121,10 +123,10 @@ */ /*----------------------------------------------------------------------------*/ -void cpl_apertures_delete(cpl_apertures * self) +void +cpl_apertures_delete(cpl_apertures *self) { - - if (self !=NULL) { + if (self != NULL) { cpl_free(self->x); cpl_free(self->y); cpl_free(self->maxpos_x); @@ -165,10 +167,10 @@ this function does nothing. */ /*----------------------------------------------------------------------------*/ -void cpl_apertures_dump(const cpl_apertures * self, - FILE * fp) +void +cpl_apertures_dump(const cpl_apertures *self, FILE *fp) { - if (self !=NULL && fp !=NULL && self->naperts > 0) { + if (self != NULL && fp != NULL && self->naperts > 0) { cpl_size i; fprintf(fp, "# X Y"); @@ -185,10 +187,10 @@ fprintf(fp, "\n"); for (i = 0; i < self->naperts; i++) { - fprintf(fp, "% 3" CPL_SIZE_FORMAT " %6.1f %6.1f", i+1, - self->x[i], self->y[i]); - fprintf(fp, " %6.1f %6.1f", - self->xcentroid[i], self->ycentroid[i]); + fprintf(fp, "% 3" CPL_SIZE_FORMAT " %6.1f %6.1f", i + 1, self->x[i], + self->y[i]); + fprintf(fp, " %6.1f %6.1f", self->xcentroid[i], + self->ycentroid[i]); fprintf(fp, " %6" CPL_SIZE_FORMAT " %6" CPL_SIZE_FORMAT, self->maxpos_x[i], self->maxpos_y[i]); fprintf(fp, " %6" CPL_SIZE_FORMAT " %6" CPL_SIZE_FORMAT, @@ -237,14 +239,14 @@ - CPL_ERROR_DATA_NOT_FOUND if one of the lab values is missing. */ /*----------------------------------------------------------------------------*/ -cpl_apertures * cpl_apertures_new_from_image(const cpl_image * self, - const cpl_image * lab) +cpl_apertures * +cpl_apertures_new_from_image(const cpl_image *self, const cpl_image *lab) { + cpl_apertures *aperts = + cpl_apertures_new_from_image_(self, lab, 0, CPL_TRUE); - cpl_apertures * aperts = cpl_apertures_new_from_image_(self, lab, 0, - CPL_TRUE); - - if (aperts == NULL) (void)cpl_error_set_where_(); + if (aperts == NULL) + (void)cpl_error_set_where_(); return aperts; } @@ -259,7 +261,8 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_apertures_get_size(const cpl_apertures * self) +cpl_size +cpl_apertures_get_size(const cpl_apertures *self) { cpl_ensure(self, CPL_ERROR_NULL_INPUT, -1); return self->naperts; @@ -276,15 +279,14 @@ */ /*----------------------------------------------------------------------------*/ -double cpl_apertures_get_pos_x(const cpl_apertures * self, - cpl_size ind) +double +cpl_apertures_get_pos_x(const cpl_apertures *self, cpl_size ind) { + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1.0); + cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, -2.0); + cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, -3.0); - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1.0); - cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, -2.0); - cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, -3.0); - - return self->x[ind-1]; + return self->x[ind - 1]; } /*----------------------------------------------------------------------------*/ @@ -296,15 +298,14 @@ @see cpl_apertures_get_pos_x() */ /*----------------------------------------------------------------------------*/ -double cpl_apertures_get_pos_y(const cpl_apertures * self, - cpl_size ind) +double +cpl_apertures_get_pos_y(const cpl_apertures *self, cpl_size ind) { + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1.0); + cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, -2.0); + cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, -3.0); - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1.0); - cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, -2.0); - cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, -3.0); - - return self->y[ind-1]; + return self->y[ind - 1]; } /*----------------------------------------------------------------------------*/ @@ -317,8 +318,8 @@ */ /*----------------------------------------------------------------------------*/ -double cpl_apertures_get_max_x(const cpl_apertures * self, - cpl_size ind) +double +cpl_apertures_get_max_x(const cpl_apertures *self, cpl_size ind) { return cpl_apertures_get_pos_x(self, ind); } @@ -334,8 +335,8 @@ */ /*----------------------------------------------------------------------------*/ -double cpl_apertures_get_max_y(const cpl_apertures * self, - cpl_size ind) +double +cpl_apertures_get_max_y(const cpl_apertures *self, cpl_size ind) { return cpl_apertures_get_pos_y(self, ind); } @@ -357,15 +358,14 @@ - CPL_ERROR_ACCESS_OUT_OF_RANGE if ind exceeds the number of apertures in self */ /*----------------------------------------------------------------------------*/ -double cpl_apertures_get_centroid_x(const cpl_apertures * self, - cpl_size ind) +double +cpl_apertures_get_centroid_x(const cpl_apertures *self, cpl_size ind) { + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1.0); + cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, -2.0); + cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, -3.0); - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1.0); - cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, -2.0); - cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, -3.0); - - return self->xcentroid[ind-1]; + return self->xcentroid[ind - 1]; } /*----------------------------------------------------------------------------*/ @@ -379,15 +379,14 @@ */ /*----------------------------------------------------------------------------*/ -double cpl_apertures_get_centroid_y(const cpl_apertures * self, - cpl_size ind) +double +cpl_apertures_get_centroid_y(const cpl_apertures *self, cpl_size ind) { + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1.0); + cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, -2.0); + cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, -3.0); - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1.0); - cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, -2.0); - cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, -3.0); - - return self->ycentroid[ind-1]; + return self->ycentroid[ind - 1]; } /*----------------------------------------------------------------------------*/ @@ -401,15 +400,14 @@ */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_apertures_get_maxpos_x(const cpl_apertures * self, - cpl_size ind) +cpl_size +cpl_apertures_get_maxpos_x(const cpl_apertures *self, cpl_size ind) { + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1); + cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, -2); + cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, -3); - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1); - cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, -2); - cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, -3); - - return self->maxpos_x[ind-1]; + return self->maxpos_x[ind - 1]; } /*----------------------------------------------------------------------------*/ @@ -423,15 +421,14 @@ */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_apertures_get_maxpos_y(const cpl_apertures * self, - cpl_size ind) +cpl_size +cpl_apertures_get_maxpos_y(const cpl_apertures *self, cpl_size ind) { + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1); + cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, -2); + cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, -3); - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1); - cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, -2); - cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, -3); - - return self->maxpos_y[ind-1]; + return self->maxpos_y[ind - 1]; } @@ -446,15 +443,14 @@ */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_apertures_get_minpos_x(const cpl_apertures * self, - cpl_size ind) +cpl_size +cpl_apertures_get_minpos_x(const cpl_apertures *self, cpl_size ind) { + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1); + cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, -2); + cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, -3); - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1); - cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, -2); - cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, -3); - - return self->minpos_x[ind-1]; + return self->minpos_x[ind - 1]; } /*----------------------------------------------------------------------------*/ @@ -468,15 +464,14 @@ */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_apertures_get_minpos_y(const cpl_apertures * self, - cpl_size ind) +cpl_size +cpl_apertures_get_minpos_y(const cpl_apertures *self, cpl_size ind) { + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1); + cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, -2); + cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, -3); - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1); - cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, -2); - cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, -3); - - return self->minpos_y[ind-1]; + return self->minpos_y[ind - 1]; } /*----------------------------------------------------------------------------*/ @@ -493,15 +488,14 @@ - CPL_ERROR_ACCESS_OUT_OF_RANGE if ind exceeds the number of apertures in self */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_apertures_get_npix(const cpl_apertures * self, - cpl_size ind) +cpl_size +cpl_apertures_get_npix(const cpl_apertures *self, cpl_size ind) { + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1); + cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, -2); + cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, -3); - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1); - cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, -2); - cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, -3); - - return self->npix[ind-1]; + return self->npix[ind - 1]; } /*----------------------------------------------------------------------------*/ @@ -515,15 +509,14 @@ */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_apertures_get_left(const cpl_apertures * self, - cpl_size ind) +cpl_size +cpl_apertures_get_left(const cpl_apertures *self, cpl_size ind) { + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1); + cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, -2); + cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, -3); - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1); - cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, -2); - cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, -3); - - return self->left_x[ind-1]; + return self->left_x[ind - 1]; } /*----------------------------------------------------------------------------*/ @@ -538,15 +531,14 @@ */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_apertures_get_left_y(const cpl_apertures * self, - cpl_size ind) +cpl_size +cpl_apertures_get_left_y(const cpl_apertures *self, cpl_size ind) { + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1); + cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, -2); + cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, -3); - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1); - cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, -2); - cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, -3); - - return self->left_y[ind-1]; + return self->left_y[ind - 1]; } /*----------------------------------------------------------------------------*/ @@ -560,15 +552,14 @@ */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_apertures_get_right(const cpl_apertures * self, - cpl_size ind) +cpl_size +cpl_apertures_get_right(const cpl_apertures *self, cpl_size ind) { + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1); + cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, -2); + cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, -3); - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1); - cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, -2); - cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, -3); - - return self->right_x[ind-1]; + return self->right_x[ind - 1]; } /*----------------------------------------------------------------------------*/ @@ -582,15 +573,14 @@ @see cpl_apertures_get_maxpos_x() */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_apertures_get_right_y(const cpl_apertures * self, - cpl_size ind) +cpl_size +cpl_apertures_get_right_y(const cpl_apertures *self, cpl_size ind) { + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1); + cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, -2); + cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, -3); - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1); - cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, -2); - cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, -3); - - return self->right_y[ind-1]; + return self->right_y[ind - 1]; } /*----------------------------------------------------------------------------*/ @@ -605,15 +595,14 @@ */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_apertures_get_bottom_x(const cpl_apertures * self, - cpl_size ind) +cpl_size +cpl_apertures_get_bottom_x(const cpl_apertures *self, cpl_size ind) { + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1); + cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, -2); + cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, -3); - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1); - cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, -2); - cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, -3); - - return self->bottom_x[ind-1]; + return self->bottom_x[ind - 1]; } /*----------------------------------------------------------------------------*/ @@ -627,15 +616,14 @@ */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_apertures_get_bottom(const cpl_apertures * self, - cpl_size ind) +cpl_size +cpl_apertures_get_bottom(const cpl_apertures *self, cpl_size ind) { + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1); + cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, -2); + cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, -3); - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1); - cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, -2); - cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, -3); - - return self->bottom_y[ind-1]; + return self->bottom_y[ind - 1]; } /*----------------------------------------------------------------------------*/ @@ -650,15 +638,14 @@ */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_apertures_get_top_x(const cpl_apertures * self, - cpl_size ind) +cpl_size +cpl_apertures_get_top_x(const cpl_apertures *self, cpl_size ind) { + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1); + cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, -2); + cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, -3); - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1); - cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, -2); - cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, -3); - - return self->top_x[ind-1]; + return self->top_x[ind - 1]; } /*----------------------------------------------------------------------------*/ @@ -672,15 +659,14 @@ */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_apertures_get_top(const cpl_apertures * self, - cpl_size ind) +cpl_size +cpl_apertures_get_top(const cpl_apertures *self, cpl_size ind) { + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1); + cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, -2); + cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, -3); - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1); - cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, -2); - cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, -3); - - return self->top_y[ind-1]; + return self->top_y[ind - 1]; } /*----------------------------------------------------------------------------*/ @@ -697,15 +683,14 @@ - CPL_ERROR_ACCESS_OUT_OF_RANGE if ind exceeds the number of apertures in self */ /*----------------------------------------------------------------------------*/ -double cpl_apertures_get_max(const cpl_apertures * self, - cpl_size ind) +double +cpl_apertures_get_max(const cpl_apertures *self, cpl_size ind) { + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, 0.0); + cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, 0.0); + cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, 0.0); - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, 0.0); - cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, 0.0); - cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, 0.0); - - return self->max_val[ind-1]; + return self->max_val[ind - 1]; } /*----------------------------------------------------------------------------*/ @@ -718,15 +703,14 @@ */ /*----------------------------------------------------------------------------*/ -double cpl_apertures_get_min(const cpl_apertures * self, - cpl_size ind) +double +cpl_apertures_get_min(const cpl_apertures *self, cpl_size ind) { + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, 0.0); + cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, 0.0); + cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, 0.0); - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, 0.0); - cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, 0.0); - cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, 0.0); - - return self->min_val[ind-1]; + return self->min_val[ind - 1]; } /*----------------------------------------------------------------------------*/ @@ -739,15 +723,14 @@ */ /*----------------------------------------------------------------------------*/ -double cpl_apertures_get_mean(const cpl_apertures * self, - cpl_size ind) +double +cpl_apertures_get_mean(const cpl_apertures *self, cpl_size ind) { + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, 0.0); + cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, 0.0); + cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, 0.0); - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, 0.0); - cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, 0.0); - cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, 0.0); - - return self->mean[ind-1]; + return self->mean[ind - 1]; } /*----------------------------------------------------------------------------*/ @@ -759,15 +742,14 @@ @see cpl_apertures_get_max() */ /*----------------------------------------------------------------------------*/ -double cpl_apertures_get_median(const cpl_apertures * self, - cpl_size ind) +double +cpl_apertures_get_median(const cpl_apertures *self, cpl_size ind) { + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, 0.0); + cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, 0.0); + cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, 0.0); - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, 0.0); - cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, 0.0); - cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, 0.0); - - return self->median[ind-1]; + return self->median[ind - 1]; } /*----------------------------------------------------------------------------*/ @@ -786,19 +768,18 @@ */ /*----------------------------------------------------------------------------*/ -double cpl_apertures_get_stdev(const cpl_apertures * self, - cpl_size ind) +double +cpl_apertures_get_stdev(const cpl_apertures *self, cpl_size ind) { - - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1.0); - cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, -2.0); - cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, -3.0); + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, -1.0); + cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, -2.0); + cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, -3.0); /* A negative value is used as internal representation of an undefined stdev. An error is raised only when the stdev is asked for */ - cpl_ensure(self->stdev[ind-1] >= 0.0, CPL_ERROR_DATA_NOT_FOUND, -4.0); + cpl_ensure(self->stdev[ind - 1] >= 0.0, CPL_ERROR_DATA_NOT_FOUND, -4.0); - return self->stdev[ind-1]; + return self->stdev[ind - 1]; } /*----------------------------------------------------------------------------*/ @@ -810,15 +791,14 @@ @see cpl_apertures_get_max() */ /*----------------------------------------------------------------------------*/ -double cpl_apertures_get_flux(const cpl_apertures * self, - cpl_size ind) +double +cpl_apertures_get_flux(const cpl_apertures *self, cpl_size ind) { + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, 0.0); + cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, 0.0); + cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, 0.0); - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, 0.0); - cpl_ensure(ind > 0, CPL_ERROR_ILLEGAL_INPUT, 0.0); - cpl_ensure(ind <= self->naperts, CPL_ERROR_ACCESS_OUT_OF_RANGE, 0.0); - - return self->flux[ind-1]; + return self->flux[ind - 1]; } /*----------------------------------------------------------------------------*/ @@ -831,16 +811,17 @@ - CPL_ERROR_NULL_INPUT if an input pointer is NULL */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_apertures_sort_by_npix(cpl_apertures * self) +cpl_error_code +cpl_apertures_sort_by_npix(cpl_apertures *self) { - cpl_apertures * sorted_apert; - void * swap; - cpl_size naperts; - cpl_size * sorted_ind; - cpl_size * computed; - cpl_size max_npix; - cpl_size max_ind = -1; /* Avoid (false) uninit warning */ - cpl_size i, j; + cpl_apertures *sorted_apert; + void *swap; + cpl_size naperts; + cpl_size *sorted_ind; + cpl_size *computed; + cpl_size max_npix; + cpl_size max_ind = -1; /* Avoid (false) uninit warning */ + cpl_size i, j; /* Test entries */ cpl_ensure_code(self, CPL_ERROR_NULL_INPUT); @@ -850,11 +831,11 @@ /* Compute the sorted index array - FIXME: Use better sort algorithm ? */ sorted_ind = cpl_malloc((size_t)naperts * sizeof(*sorted_ind)); - computed = cpl_calloc((size_t)naperts, sizeof(*computed)); + computed = cpl_calloc((size_t)naperts, sizeof(*computed)); for (j = 0; j < naperts; j++) { max_npix = -1; for (i = 0; i < naperts; i++) { - if ((computed[i]==0) && (max_npix < self->npix[i])) { + if ((computed[i] == 0) && (max_npix < self->npix[i])) { max_npix = self->npix[i]; max_ind = i; } @@ -867,37 +848,37 @@ /* Now sort the input apertures */ sorted_apert = cpl_apertures_new(naperts); for (i = 0; i < sorted_apert->naperts; i++) { - sorted_apert->x[i] = self->x[sorted_ind[i]]; - sorted_apert->y[i] = self->y[sorted_ind[i]]; - sorted_apert->maxpos_x[i] = self->maxpos_x[sorted_ind[i]]; - sorted_apert->maxpos_y[i] = self->maxpos_y[sorted_ind[i]]; - sorted_apert->minpos_x[i] = self->minpos_x[sorted_ind[i]]; - sorted_apert->minpos_y[i] = self->minpos_y[sorted_ind[i]]; - sorted_apert->xcentroid[i] = self->xcentroid[sorted_ind[i]]; - sorted_apert->ycentroid[i] = self->ycentroid[sorted_ind[i]]; - sorted_apert->npix[i] = self->npix[sorted_ind[i]]; - sorted_apert->left_x[i] = self->left_x[sorted_ind[i]]; - sorted_apert->left_y[i] = self->left_y[sorted_ind[i]]; - sorted_apert->right_x[i] = self->right_x[sorted_ind[i]]; - sorted_apert->right_y[i] = self->right_y[sorted_ind[i]]; - sorted_apert->top_x[i] = self->top_x[sorted_ind[i]]; - sorted_apert->top_y[i] = self->top_y[sorted_ind[i]]; - sorted_apert->bottom_x[i] = self->bottom_x[sorted_ind[i]]; - sorted_apert->bottom_y[i] = self->bottom_y[sorted_ind[i]]; - sorted_apert->max_val[i] = self->max_val[sorted_ind[i]]; - sorted_apert->min_val[i] = self->min_val[sorted_ind[i]]; - sorted_apert->mean[i] = self->mean[sorted_ind[i]]; - sorted_apert->median[i] = self->median[sorted_ind[i]]; - sorted_apert->stdev[i] = self->stdev[sorted_ind[i]]; - sorted_apert->flux[i] = self->flux[sorted_ind[i]]; + sorted_apert->x[i] = self->x[sorted_ind[i]]; + sorted_apert->y[i] = self->y[sorted_ind[i]]; + sorted_apert->maxpos_x[i] = self->maxpos_x[sorted_ind[i]]; + sorted_apert->maxpos_y[i] = self->maxpos_y[sorted_ind[i]]; + sorted_apert->minpos_x[i] = self->minpos_x[sorted_ind[i]]; + sorted_apert->minpos_y[i] = self->minpos_y[sorted_ind[i]]; + sorted_apert->xcentroid[i] = self->xcentroid[sorted_ind[i]]; + sorted_apert->ycentroid[i] = self->ycentroid[sorted_ind[i]]; + sorted_apert->npix[i] = self->npix[sorted_ind[i]]; + sorted_apert->left_x[i] = self->left_x[sorted_ind[i]]; + sorted_apert->left_y[i] = self->left_y[sorted_ind[i]]; + sorted_apert->right_x[i] = self->right_x[sorted_ind[i]]; + sorted_apert->right_y[i] = self->right_y[sorted_ind[i]]; + sorted_apert->top_x[i] = self->top_x[sorted_ind[i]]; + sorted_apert->top_y[i] = self->top_y[sorted_ind[i]]; + sorted_apert->bottom_x[i] = self->bottom_x[sorted_ind[i]]; + sorted_apert->bottom_y[i] = self->bottom_y[sorted_ind[i]]; + sorted_apert->max_val[i] = self->max_val[sorted_ind[i]]; + sorted_apert->min_val[i] = self->min_val[sorted_ind[i]]; + sorted_apert->mean[i] = self->mean[sorted_ind[i]]; + sorted_apert->median[i] = self->median[sorted_ind[i]]; + sorted_apert->stdev[i] = self->stdev[sorted_ind[i]]; + sorted_apert->flux[i] = self->flux[sorted_ind[i]]; } cpl_free(sorted_ind); /* Swap the sorted and the input apertures */ swap = cpl_malloc(sizeof(cpl_apertures)); - memcpy(swap, sorted_apert, sizeof(cpl_apertures)); - memcpy(sorted_apert, self, sizeof(cpl_apertures)); - memcpy(self, swap, sizeof(cpl_apertures)); + memcpy(swap, sorted_apert, sizeof(cpl_apertures)); + memcpy(sorted_apert, self, sizeof(cpl_apertures)); + memcpy(self, swap, sizeof(cpl_apertures)); cpl_free(swap); cpl_apertures_delete(sorted_apert); @@ -913,16 +894,17 @@ @see cpl_apertures_sort_by_npix() */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_apertures_sort_by_max(cpl_apertures * self) +cpl_error_code +cpl_apertures_sort_by_max(cpl_apertures *self) { - cpl_apertures * sorted_apert; - void * swap; - cpl_size naperts; - cpl_size * sorted_ind; - cpl_size * computed; - double max_max = DBL_MAX; /* Avoid (false) uninit warning */ - cpl_size max_ind; - cpl_size i, j; + cpl_apertures *sorted_apert; + void *swap; + cpl_size naperts; + cpl_size *sorted_ind; + cpl_size *computed; + double max_max = DBL_MAX; /* Avoid (false) uninit warning */ + cpl_size max_ind; + cpl_size i, j; /* Test entries */ cpl_ensure_code(self, CPL_ERROR_NULL_INPUT); @@ -932,11 +914,12 @@ /* Compute the sorted index array - FIXME: Use better sort algorithm ? */ sorted_ind = cpl_malloc((size_t)naperts * sizeof(*sorted_apert)); - computed = cpl_calloc((size_t)naperts, sizeof(*computed)); + computed = cpl_calloc((size_t)naperts, sizeof(*computed)); for (j = 0; j < naperts; j++) { max_ind = -1; for (i = 0; i < naperts; i++) { - if ((computed[i]==0) && (max_ind < 0 || max_max < self->max_val[i])) { + if ((computed[i] == 0) && + (max_ind < 0 || max_max < self->max_val[i])) { max_max = self->max_val[i]; max_ind = i; } @@ -949,37 +932,37 @@ /* Now sort the input apertures */ sorted_apert = cpl_apertures_new(naperts); for (i = 0; i < sorted_apert->naperts; i++) { - sorted_apert->x[i] = self->x[sorted_ind[i]]; - sorted_apert->y[i] = self->y[sorted_ind[i]]; - sorted_apert->maxpos_x[i] = self->maxpos_x[sorted_ind[i]]; - sorted_apert->maxpos_y[i] = self->maxpos_y[sorted_ind[i]]; - sorted_apert->minpos_x[i] = self->minpos_x[sorted_ind[i]]; - sorted_apert->minpos_y[i] = self->minpos_y[sorted_ind[i]]; - sorted_apert->xcentroid[i] = self->xcentroid[sorted_ind[i]]; - sorted_apert->ycentroid[i] = self->ycentroid[sorted_ind[i]]; - sorted_apert->npix[i] = self->npix[sorted_ind[i]]; - sorted_apert->left_x[i] = self->left_x[sorted_ind[i]]; - sorted_apert->left_y[i] = self->left_y[sorted_ind[i]]; - sorted_apert->right_x[i] = self->right_x[sorted_ind[i]]; - sorted_apert->right_y[i] = self->right_y[sorted_ind[i]]; - sorted_apert->top_x[i] = self->top_x[sorted_ind[i]]; - sorted_apert->top_y[i] = self->top_y[sorted_ind[i]]; - sorted_apert->bottom_x[i] = self->bottom_x[sorted_ind[i]]; - sorted_apert->bottom_y[i] = self->bottom_y[sorted_ind[i]]; - sorted_apert->max_val[i] = self->max_val[sorted_ind[i]]; - sorted_apert->min_val[i] = self->min_val[sorted_ind[i]]; - sorted_apert->mean[i] = self->mean[sorted_ind[i]]; - sorted_apert->median[i] = self->median[sorted_ind[i]]; - sorted_apert->stdev[i] = self->stdev[sorted_ind[i]]; - sorted_apert->flux[i] = self->flux[sorted_ind[i]]; + sorted_apert->x[i] = self->x[sorted_ind[i]]; + sorted_apert->y[i] = self->y[sorted_ind[i]]; + sorted_apert->maxpos_x[i] = self->maxpos_x[sorted_ind[i]]; + sorted_apert->maxpos_y[i] = self->maxpos_y[sorted_ind[i]]; + sorted_apert->minpos_x[i] = self->minpos_x[sorted_ind[i]]; + sorted_apert->minpos_y[i] = self->minpos_y[sorted_ind[i]]; + sorted_apert->xcentroid[i] = self->xcentroid[sorted_ind[i]]; + sorted_apert->ycentroid[i] = self->ycentroid[sorted_ind[i]]; + sorted_apert->npix[i] = self->npix[sorted_ind[i]]; + sorted_apert->left_x[i] = self->left_x[sorted_ind[i]]; + sorted_apert->left_y[i] = self->left_y[sorted_ind[i]]; + sorted_apert->right_x[i] = self->right_x[sorted_ind[i]]; + sorted_apert->right_y[i] = self->right_y[sorted_ind[i]]; + sorted_apert->top_x[i] = self->top_x[sorted_ind[i]]; + sorted_apert->top_y[i] = self->top_y[sorted_ind[i]]; + sorted_apert->bottom_x[i] = self->bottom_x[sorted_ind[i]]; + sorted_apert->bottom_y[i] = self->bottom_y[sorted_ind[i]]; + sorted_apert->max_val[i] = self->max_val[sorted_ind[i]]; + sorted_apert->min_val[i] = self->min_val[sorted_ind[i]]; + sorted_apert->mean[i] = self->mean[sorted_ind[i]]; + sorted_apert->median[i] = self->median[sorted_ind[i]]; + sorted_apert->stdev[i] = self->stdev[sorted_ind[i]]; + sorted_apert->flux[i] = self->flux[sorted_ind[i]]; } cpl_free(sorted_ind); /* Swap the sorted and the input apertures */ swap = cpl_malloc(sizeof(cpl_apertures)); - memcpy(swap, sorted_apert, sizeof(cpl_apertures)); - memcpy(sorted_apert, self, sizeof(cpl_apertures)); - memcpy(self, swap, sizeof(cpl_apertures)); + memcpy(swap, sorted_apert, sizeof(cpl_apertures)); + memcpy(sorted_apert, self, sizeof(cpl_apertures)); + memcpy(self, swap, sizeof(cpl_apertures)); cpl_free(swap); cpl_apertures_delete(sorted_apert); @@ -995,16 +978,17 @@ @see cpl_apertures_sort_by_npix() */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_apertures_sort_by_flux(cpl_apertures * self) +cpl_error_code +cpl_apertures_sort_by_flux(cpl_apertures *self) { - cpl_apertures * sorted_apert; - void * swap; - cpl_size naperts; - cpl_size * sorted_ind; - cpl_size * computed; - double max_flux = DBL_MAX; /* Avoid (false) uninit warning */ - cpl_size max_ind; - cpl_size i, j; + cpl_apertures *sorted_apert; + void *swap; + cpl_size naperts; + cpl_size *sorted_ind; + cpl_size *computed; + double max_flux = DBL_MAX; /* Avoid (false) uninit warning */ + cpl_size max_ind; + cpl_size i, j; /* Test entries */ cpl_ensure_code(self, CPL_ERROR_NULL_INPUT); @@ -1014,11 +998,12 @@ /* Compute the sorted index array - FIXME: Use better sort algorithm ? */ sorted_ind = cpl_malloc((size_t)naperts * sizeof(*sorted_ind)); - computed = cpl_calloc((size_t)naperts, sizeof(*computed)); + computed = cpl_calloc((size_t)naperts, sizeof(*computed)); for (j = 0; j < naperts; j++) { max_ind = -1; for (i = 0; i < naperts; i++) { - if ((computed[i]==0) && (max_ind < 0 || max_flux < self->flux[i])) { + if ((computed[i] == 0) && + (max_ind < 0 || max_flux < self->flux[i])) { max_flux = self->flux[i]; max_ind = i; } @@ -1031,37 +1016,37 @@ /* Now sort the input apertures */ sorted_apert = cpl_apertures_new(naperts); for (i = 0; i < sorted_apert->naperts; i++) { - sorted_apert->x[i] = self->x[sorted_ind[i]]; - sorted_apert->y[i] = self->y[sorted_ind[i]]; - sorted_apert->maxpos_x[i] = self->maxpos_x[sorted_ind[i]]; - sorted_apert->maxpos_y[i] = self->maxpos_y[sorted_ind[i]]; - sorted_apert->minpos_x[i] = self->minpos_x[sorted_ind[i]]; - sorted_apert->minpos_y[i] = self->minpos_y[sorted_ind[i]]; - sorted_apert->xcentroid[i] = self->xcentroid[sorted_ind[i]]; - sorted_apert->ycentroid[i] = self->ycentroid[sorted_ind[i]]; - sorted_apert->npix[i] = self->npix[sorted_ind[i]]; - sorted_apert->left_x[i] = self->left_x[sorted_ind[i]]; - sorted_apert->left_y[i] = self->left_y[sorted_ind[i]]; - sorted_apert->right_x[i] = self->right_x[sorted_ind[i]]; - sorted_apert->right_y[i] = self->right_y[sorted_ind[i]]; - sorted_apert->top_x[i] = self->top_x[sorted_ind[i]]; - sorted_apert->top_y[i] = self->top_y[sorted_ind[i]]; - sorted_apert->bottom_x[i] = self->bottom_x[sorted_ind[i]]; - sorted_apert->bottom_y[i] = self->bottom_y[sorted_ind[i]]; - sorted_apert->max_val[i] = self->max_val[sorted_ind[i]]; - sorted_apert->min_val[i] = self->min_val[sorted_ind[i]]; - sorted_apert->mean[i] = self->mean[sorted_ind[i]]; - sorted_apert->median[i] = self->median[sorted_ind[i]]; - sorted_apert->stdev[i] = self->stdev[sorted_ind[i]]; - sorted_apert->flux[i] = self->flux[sorted_ind[i]]; + sorted_apert->x[i] = self->x[sorted_ind[i]]; + sorted_apert->y[i] = self->y[sorted_ind[i]]; + sorted_apert->maxpos_x[i] = self->maxpos_x[sorted_ind[i]]; + sorted_apert->maxpos_y[i] = self->maxpos_y[sorted_ind[i]]; + sorted_apert->minpos_x[i] = self->minpos_x[sorted_ind[i]]; + sorted_apert->minpos_y[i] = self->minpos_y[sorted_ind[i]]; + sorted_apert->xcentroid[i] = self->xcentroid[sorted_ind[i]]; + sorted_apert->ycentroid[i] = self->ycentroid[sorted_ind[i]]; + sorted_apert->npix[i] = self->npix[sorted_ind[i]]; + sorted_apert->left_x[i] = self->left_x[sorted_ind[i]]; + sorted_apert->left_y[i] = self->left_y[sorted_ind[i]]; + sorted_apert->right_x[i] = self->right_x[sorted_ind[i]]; + sorted_apert->right_y[i] = self->right_y[sorted_ind[i]]; + sorted_apert->top_x[i] = self->top_x[sorted_ind[i]]; + sorted_apert->top_y[i] = self->top_y[sorted_ind[i]]; + sorted_apert->bottom_x[i] = self->bottom_x[sorted_ind[i]]; + sorted_apert->bottom_y[i] = self->bottom_y[sorted_ind[i]]; + sorted_apert->max_val[i] = self->max_val[sorted_ind[i]]; + sorted_apert->min_val[i] = self->min_val[sorted_ind[i]]; + sorted_apert->mean[i] = self->mean[sorted_ind[i]]; + sorted_apert->median[i] = self->median[sorted_ind[i]]; + sorted_apert->stdev[i] = self->stdev[sorted_ind[i]]; + sorted_apert->flux[i] = self->flux[sorted_ind[i]]; } cpl_free(sorted_ind); /* Swap the sorted and the input apertures */ swap = cpl_malloc(sizeof(cpl_apertures)); - memcpy(swap, sorted_apert, sizeof(cpl_apertures)); - memcpy(sorted_apert, self, sizeof(cpl_apertures)); - memcpy(self, swap, sizeof(cpl_apertures)); + memcpy(swap, sorted_apert, sizeof(cpl_apertures)); + memcpy(sorted_apert, self, sizeof(cpl_apertures)); + memcpy(self, swap, sizeof(cpl_apertures)); cpl_free(swap); cpl_apertures_delete(sorted_apert); @@ -1085,26 +1070,29 @@ - CPL_ERROR_DATA_NOT_FOUND if the apertures cannot be detected */ /*----------------------------------------------------------------------------*/ -cpl_apertures * cpl_apertures_extract(const cpl_image * self, - const cpl_vector * sigmas, - cpl_size * pisigma) -{ - cpl_errorstate prestate = cpl_errorstate_get(); - cpl_apertures * aperts = NULL; - const cpl_size n = cpl_vector_get_size(sigmas); - cpl_size i; +cpl_apertures * +cpl_apertures_extract(const cpl_image *self, + const cpl_vector *sigmas, + cpl_size *pisigma) +{ + cpl_errorstate prestate = cpl_errorstate_get(); + cpl_apertures *aperts = NULL; + const cpl_size n = cpl_vector_get_size(sigmas); + cpl_size i; - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); cpl_ensure(sigmas != NULL, CPL_ERROR_NULL_INPUT, NULL); for (i = 0; i < n; i++) { const double sigma = cpl_vector_get(sigmas, i); - if (sigma <= 0.0) break; + if (sigma <= 0.0) + break; /* Apply the detection */ aperts = cpl_apertures_extract_sigma(self, sigma); - if (aperts != NULL) break; + if (aperts != NULL) + break; } cpl_ensure(aperts != NULL, CPL_ERROR_DATA_NOT_FOUND, NULL); @@ -1112,7 +1100,8 @@ /* Recover from any errors set in cpl_apertures_extract_sigma() */ cpl_errorstate_set(prestate); - if (pisigma) *pisigma = i; + if (pisigma) + *pisigma = i; return aperts; } @@ -1132,20 +1121,21 @@ @see cpl_image_extract() */ /*----------------------------------------------------------------------------*/ -cpl_apertures * cpl_apertures_extract_window(const cpl_image * self, - const cpl_vector * sigmas, - cpl_size llx, - cpl_size lly, - cpl_size urx, - cpl_size ury, - cpl_size * pisigma) -{ - cpl_apertures * aperts; - cpl_image * extracted; - cpl_size i; +cpl_apertures * +cpl_apertures_extract_window(const cpl_image *self, + const cpl_vector *sigmas, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury, + cpl_size *pisigma) +{ + cpl_apertures *aperts; + cpl_image *extracted; + cpl_size i; /* Test entries */ - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); cpl_ensure(sigmas != NULL, CPL_ERROR_NULL_INPUT, NULL); /* Extract the subwindow - and check entries */ @@ -1202,22 +1192,19 @@ - CPL_ERROR_DATA_NOT_FOUND if the selection mask is empty */ /*----------------------------------------------------------------------------*/ -cpl_apertures * cpl_apertures_extract_mask(const cpl_image * self, - const cpl_mask * selection) +cpl_apertures * +cpl_apertures_extract_mask(const cpl_image *self, const cpl_mask *selection) { - cpl_errorstate prestate = cpl_errorstate_get(); - cpl_apertures * aperts = NULL; - cpl_size nlabels; + cpl_errorstate prestate = cpl_errorstate_get(); + cpl_apertures *aperts = NULL; + cpl_size nlabels; /* Labelise the user provided selection */ - cpl_image * labels = cpl_image_labelise_mask_create(selection, - &nlabels); + cpl_image *labels = cpl_image_labelise_mask_create(selection, &nlabels); if (labels != NULL && nlabels > 0) { - /* Create the detected apertures list */ - aperts = cpl_apertures_new_from_image_(self, labels, nlabels, - CPL_FALSE); - + aperts = + cpl_apertures_new_from_image_(self, labels, nlabels, CPL_FALSE); } if (aperts == NULL) { @@ -1253,17 +1240,17 @@ - CPL_ERROR_DATA_NOT_FOUND if the no apertures are found */ /*----------------------------------------------------------------------------*/ -cpl_apertures * cpl_apertures_extract_sigma(const cpl_image * self, - double sigma) +cpl_apertures * +cpl_apertures_extract_sigma(const cpl_image *self, double sigma) { - double median, med_dist; - double threshold; - cpl_mask * selection; - cpl_apertures * aperts = NULL; + double median, med_dist; + double threshold; + cpl_mask *selection; + cpl_apertures *aperts = NULL; /* Check entries */ - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(sigma > 0.0, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(sigma > 0.0, CPL_ERROR_ILLEGAL_INPUT, NULL); /* Compute the threshold */ median = cpl_image_get_median_dev(self, &med_dist); @@ -1273,12 +1260,12 @@ selection = cpl_mask_threshold_image_create(self, threshold, DBL_MAX); if (selection != NULL) { /* Use a morphological opening to remove the single pixel detections */ - cpl_mask * kernel = cpl_mask_new(3, 3); + cpl_mask *kernel = cpl_mask_new(3, 3); /* These two should not be able to fail */ - const int error = cpl_mask_not(kernel) || - cpl_mask_filter(selection, selection, kernel, CPL_FILTER_OPENING, - CPL_BORDER_ZERO); + const int error = cpl_mask_not(kernel) || + cpl_mask_filter(selection, selection, kernel, + CPL_FILTER_OPENING, CPL_BORDER_ZERO); cpl_mask_delete(kernel); if (!error) { @@ -1308,18 +1295,18 @@ */ /*----------------------------------------------------------------------------*/ -cpl_bivector * cpl_apertures_get_fwhm(const cpl_image * self, - const cpl_apertures * aperts) +cpl_bivector * +cpl_apertures_get_fwhm(const cpl_image *self, const cpl_apertures *aperts) { cpl_errorstate prevstate = cpl_errorstate_get(); - cpl_bivector * fwhms; - double * fwhms_x; - double * fwhms_y; - cpl_size naperts; - cpl_size i, nok = 0; + cpl_bivector *fwhms; + double *fwhms_x; + double *fwhms_y; + cpl_size naperts; + cpl_size i, nok = 0; - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); cpl_ensure(aperts != NULL, CPL_ERROR_NULL_INPUT, NULL); naperts = cpl_apertures_get_size(aperts); @@ -1332,20 +1319,21 @@ /* Compute FWHM on all apertures */ - for (i=0; i < naperts; i++) { - const cpl_error_code error - = cpl_image_get_fwhm(self, - (cpl_size)cpl_apertures_get_pos_x(aperts, i+1), - (cpl_size)cpl_apertures_get_pos_y(aperts, i+1), - &(fwhms_x[i]), - &(fwhms_y[i])); + for (i = 0; i < naperts; i++) { + const cpl_error_code error = + cpl_image_get_fwhm(self, + (cpl_size)cpl_apertures_get_pos_x(aperts, i + 1), + (cpl_size)cpl_apertures_get_pos_y(aperts, i + 1), + &(fwhms_x[i]), &(fwhms_y[i])); if (!error) { nok++; - } else if (error == CPL_ERROR_DATA_NOT_FOUND) { + } + else if (error == CPL_ERROR_DATA_NOT_FOUND) { /* This error can be ignored */ cpl_errorstate_set(prevstate); - } else { + } + else { /* This unexpected error cannot be ignored */ cpl_bivector_delete(fwhms); (void)cpl_error_set_where_(); @@ -1378,9 +1366,10 @@ - CPL_ERROR_ILLEGAL_INPUT if naperts is not strictly positive */ /*----------------------------------------------------------------------------*/ -static cpl_apertures * cpl_apertures_new(cpl_size naperts) +static cpl_apertures * +cpl_apertures_new(cpl_size naperts) { - cpl_apertures * aperts; + cpl_apertures *aperts; /* Check entries */ cpl_ensure(naperts > 0, CPL_ERROR_ILLEGAL_INPUT, NULL); @@ -1390,30 +1379,30 @@ aperts->naperts = naperts; /* Allocate data holders */ - aperts->x = cpl_calloc((size_t)naperts, sizeof(double)); - aperts->y = cpl_calloc((size_t)naperts, sizeof(double)); - aperts->maxpos_x = cpl_calloc((size_t)naperts, sizeof(cpl_size)); - aperts->maxpos_y = cpl_calloc((size_t)naperts, sizeof(cpl_size)); - aperts->minpos_x = cpl_calloc((size_t)naperts, sizeof(cpl_size)); - aperts->minpos_y = cpl_calloc((size_t)naperts, sizeof(cpl_size)); - aperts->xcentroid = cpl_calloc((size_t)naperts, sizeof(double)); - aperts->ycentroid = cpl_calloc((size_t)naperts, sizeof(double)); - aperts->npix = cpl_calloc((size_t)naperts, sizeof(cpl_size)); - aperts->left_x = cpl_calloc((size_t)naperts, sizeof(cpl_size)); - aperts->left_y = cpl_calloc((size_t)naperts, sizeof(cpl_size)); - aperts->right_x = cpl_calloc((size_t)naperts, sizeof(cpl_size)); - aperts->right_y = cpl_calloc((size_t)naperts, sizeof(cpl_size)); - aperts->top_x = cpl_calloc((size_t)naperts, sizeof(cpl_size)); - aperts->top_y = cpl_calloc((size_t)naperts, sizeof(cpl_size)); - aperts->bottom_x = cpl_calloc((size_t)naperts, sizeof(cpl_size)); - aperts->bottom_y = cpl_calloc((size_t)naperts, sizeof(cpl_size)); - aperts->max_val = cpl_calloc((size_t)naperts, sizeof(double)); - aperts->min_val = cpl_calloc((size_t)naperts, sizeof(double)); - aperts->mean = cpl_calloc((size_t)naperts, sizeof(double)); - aperts->varsum = cpl_calloc((size_t)naperts, sizeof(double)); - aperts->median = cpl_calloc((size_t)naperts, sizeof(double)); - aperts->stdev = cpl_calloc((size_t)naperts, sizeof(double)); - aperts->flux = cpl_calloc((size_t)naperts, sizeof(double)); + aperts->x = cpl_calloc((size_t)naperts, sizeof(double)); + aperts->y = cpl_calloc((size_t)naperts, sizeof(double)); + aperts->maxpos_x = cpl_calloc((size_t)naperts, sizeof(cpl_size)); + aperts->maxpos_y = cpl_calloc((size_t)naperts, sizeof(cpl_size)); + aperts->minpos_x = cpl_calloc((size_t)naperts, sizeof(cpl_size)); + aperts->minpos_y = cpl_calloc((size_t)naperts, sizeof(cpl_size)); + aperts->xcentroid = cpl_calloc((size_t)naperts, sizeof(double)); + aperts->ycentroid = cpl_calloc((size_t)naperts, sizeof(double)); + aperts->npix = cpl_calloc((size_t)naperts, sizeof(cpl_size)); + aperts->left_x = cpl_calloc((size_t)naperts, sizeof(cpl_size)); + aperts->left_y = cpl_calloc((size_t)naperts, sizeof(cpl_size)); + aperts->right_x = cpl_calloc((size_t)naperts, sizeof(cpl_size)); + aperts->right_y = cpl_calloc((size_t)naperts, sizeof(cpl_size)); + aperts->top_x = cpl_calloc((size_t)naperts, sizeof(cpl_size)); + aperts->top_y = cpl_calloc((size_t)naperts, sizeof(cpl_size)); + aperts->bottom_x = cpl_calloc((size_t)naperts, sizeof(cpl_size)); + aperts->bottom_y = cpl_calloc((size_t)naperts, sizeof(cpl_size)); + aperts->max_val = cpl_calloc((size_t)naperts, sizeof(double)); + aperts->min_val = cpl_calloc((size_t)naperts, sizeof(double)); + aperts->mean = cpl_calloc((size_t)naperts, sizeof(double)); + aperts->varsum = cpl_calloc((size_t)naperts, sizeof(double)); + aperts->median = cpl_calloc((size_t)naperts, sizeof(double)); + aperts->stdev = cpl_calloc((size_t)naperts, sizeof(double)); + aperts->flux = cpl_calloc((size_t)naperts, sizeof(double)); return aperts; } @@ -1433,38 +1422,39 @@ */ /*----------------------------------------------------------------------------*/ -cpl_apertures * cpl_apertures_new_from_image_(const cpl_image * self, - const cpl_image * lab, - cpl_size maperts, - cpl_boolean bpm_check) -{ - cpl_apertures * aperts; - const cpl_image * dimage; - cpl_image * cimage = NULL; - cpl_image * labcopy = NULL; - const cpl_image * labuse; - cpl_size naperts; - const double * pd; - const int * plab; - double * medians; - cpl_size * medianc; - const cpl_size nx = cpl_image_get_size_x(self); - const cpl_size ny = cpl_image_get_size_y(self); - const double ep = 1e-10; - cpl_size i, j, k; +cpl_apertures * +cpl_apertures_new_from_image_(const cpl_image *self, + const cpl_image *lab, + cpl_size maperts, + cpl_boolean bpm_check) +{ + cpl_apertures *aperts; + const cpl_image *dimage; + cpl_image *cimage = NULL; + cpl_image *labcopy = NULL; + const cpl_image *labuse; + cpl_size naperts; + const double *pd; + const int *plab; + double *medians; + cpl_size *medianc; + const cpl_size nx = cpl_image_get_size_x(self); + const cpl_size ny = cpl_image_get_size_y(self); + const double ep = 1e-10; + cpl_size i, j, k; /* Test entries */ cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(lab != NULL, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(cpl_image_get_type(lab) == CPL_TYPE_INT, - CPL_ERROR_TYPE_MISMATCH, NULL); - cpl_ensure(nx == cpl_image_get_size_x(lab), - CPL_ERROR_INCOMPATIBLE_INPUT, NULL); - cpl_ensure(ny == cpl_image_get_size_y(lab), - CPL_ERROR_INCOMPATIBLE_INPUT, NULL); + cpl_ensure(lab != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(cpl_image_get_type(lab) == CPL_TYPE_INT, CPL_ERROR_TYPE_MISMATCH, + NULL); + cpl_ensure(nx == cpl_image_get_size_x(lab), CPL_ERROR_INCOMPATIBLE_INPUT, + NULL); + cpl_ensure(ny == cpl_image_get_size_y(lab), CPL_ERROR_INCOMPATIBLE_INPUT, + NULL); if (bpm_check) { - const cpl_mask * bpm = cpl_image_get_bpm_const(self); + const cpl_mask *bpm = cpl_image_get_bpm_const(self); if (bpm != NULL && !cpl_mask_is_empty(bpm)) { /* Set the bad pixels of the input image to 0 in the lab image */ @@ -1488,8 +1478,9 @@ } /* Convert input image in a double image */ - dimage = cpl_image_get_type(self) == CPL_TYPE_DOUBLE ? self - : (cimage = cpl_image_cast(self, CPL_TYPE_DOUBLE)); + dimage = cpl_image_get_type(self) == CPL_TYPE_DOUBLE + ? self + : (cimage = cpl_image_cast(self, CPL_TYPE_DOUBLE)); if (dimage == NULL) { cpl_image_delete(labcopy); @@ -1514,9 +1505,10 @@ for (i = 0; i < nx; i++) { double pix, delta; - k = plab[i+j*nx]-1; + k = plab[i + j * nx] - 1; /* Background: do nothing */ - if (k==-1) continue; + if (k == -1) + continue; if (k < 0) { cpl_apertures_delete(aperts); cpl_image_delete(cimage); @@ -1525,54 +1517,54 @@ return NULL; } - assert( k < naperts ); + assert(k < naperts); /* Current pixel value */ - pix = pd[i+j*nx]; + pix = pd[i + j * nx]; /* See cpl_tools_get_variance_double() */ delta = pix - aperts->mean[k]; - aperts->varsum[k] += (double)aperts->npix[k] * delta * delta - / (double)(aperts->npix[k] + 1); - aperts->mean[k] += delta / (double)(aperts->npix[k] + 1); + aperts->varsum[k] += (double)aperts->npix[k] * delta * delta / + (double)(aperts->npix[k] + 1); + aperts->mean[k] += delta / (double)(aperts->npix[k] + 1); /* Accumulate positions */ - aperts->x[k] += (double)(i+1); - aperts->y[k] += (double)(j+1); + aperts->x[k] += (double)(i + 1); + aperts->y[k] += (double)(j + 1); /* Increase number of pixels */ - aperts->npix[k] ++; + aperts->npix[k]++; /* Store pixel sum and squared sum */ aperts->flux[k] += pix; /* Check max pos value */ if (pix > aperts->max_val[k]) { aperts->max_val[k] = pix; - aperts->maxpos_x[k] = i+1; - aperts->maxpos_y[k] = j+1; + aperts->maxpos_x[k] = i + 1; + aperts->maxpos_y[k] = j + 1; } /* Check min pos value */ if (pix < aperts->min_val[k]) { aperts->min_val[k] = pix; - aperts->minpos_x[k] = i+1; - aperts->minpos_y[k] = j+1; + aperts->minpos_x[k] = i + 1; + aperts->minpos_y[k] = j + 1; } /* Check object extremities */ - if ((i+1 < aperts->left_x[k]) || (aperts->left_x[k] == 0)) { - aperts->left_x[k] = i+1; - aperts->left_y[k] = j+1; + if ((i + 1 < aperts->left_x[k]) || (aperts->left_x[k] == 0)) { + aperts->left_x[k] = i + 1; + aperts->left_y[k] = j + 1; } - if (i+1 > aperts->right_x[k]) { - aperts->right_x[k] = i+1; - aperts->right_y[k] = j+1; + if (i + 1 > aperts->right_x[k]) { + aperts->right_x[k] = i + 1; + aperts->right_y[k] = j + 1; } - if ((j+1 < aperts->bottom_y[k]) || (aperts->bottom_y[k] == 0)) { - aperts->bottom_x[k] = i+1; - aperts->bottom_y[k] = j+1; + if ((j + 1 < aperts->bottom_y[k]) || (aperts->bottom_y[k] == 0)) { + aperts->bottom_x[k] = i + 1; + aperts->bottom_y[k] = j + 1; } - if (j+1 > aperts->top_y[k]) { - aperts->top_x[k] = i+1; - aperts->top_y[k] = j+1; + if (j + 1 > aperts->top_y[k]) { + aperts->top_x[k] = i + 1; + aperts->top_y[k] = j + 1; } } } @@ -1580,22 +1572,23 @@ /* Centroiding */ for (j = 0; j < ny; j++) { for (i = 0; i < nx; i++) { - k = plab[i+j*nx]-1; + k = plab[i + j * nx] - 1; if (k >= 0) { /* Ignore background */ /* Current pixel value */ - const double pix = pd[i+j*nx]; + const double pix = pd[i + j * nx]; if (aperts->min_val[k] <= 0) { /* Accumulate weighted positions */ aperts->xcentroid[k] += - (double)(i+1)*(pix-aperts->min_val[k]+ep); - aperts->ycentroid[k] += - (double)(j+1)*(pix-aperts->min_val[k]+ep); - } else { + (double)(i + 1) * (pix - aperts->min_val[k] + ep); + aperts->ycentroid[k] += + (double)(j + 1) * (pix - aperts->min_val[k] + ep); + } + else { /* Accumulate weighted positions */ - aperts->xcentroid[k] += (double)(i+1) * pix; - aperts->ycentroid[k] += (double)(j+1) * pix; + aperts->xcentroid[k] += (double)(i + 1) * pix; + aperts->ycentroid[k] += (double)(j + 1) * pix; } } } @@ -1615,18 +1608,20 @@ cpl_image_delete(cimage); cpl_image_delete(labcopy); cpl_free(medianc); - (void)cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, "Label image" + (void)cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, + "Label image" " of size %d X %d with %d label(s) " - "has no pixel labeled %d", (int)nx, - (int)ny, (int)naperts, (int)k); + "has no pixel labeled %d", + (int)nx, (int)ny, (int)naperts, + (int)k); return NULL; } /* Determine end index for each median */ medianc[k] = k > 0 ? npix + medianc[k - 1] : npix; - aperts->stdev[k] = npix > 1 ? - sqrt(aperts->varsum[k]/((double)npix-1.0)) : -1.0; + aperts->stdev[k] = + npix > 1 ? sqrt(aperts->varsum[k] / ((double)npix - 1.0)) : -1.0; aperts->x[k] /= (double)npix; aperts->y[k] /= (double)npix; @@ -1640,7 +1635,8 @@ aperts->xcentroid[k] <= weight * (double)aperts->right_x[k] && weight != 0.0) { aperts->xcentroid[k] /= weight; - } else { + } + else { aperts->xcentroid[k] = 0.0; } @@ -1648,18 +1644,20 @@ aperts->ycentroid[k] <= weight * (double)aperts->top_y[k] && weight != 0.0) { aperts->ycentroid[k] /= weight; - } else { + } + else { aperts->ycentroid[k] = 0.0; } } /* Allocate space for all pixels belonging to an aperture */ - medians = cpl_malloc((size_t)medianc[aperts->naperts-1] * sizeof(*medians)); + medians = + cpl_malloc((size_t)medianc[aperts->naperts - 1] * sizeof(*medians)); /* Repack all pixels belonging to an aperture into an array specific to that aperture */ for (i = 0; i < nx * ny; i++) { - k = plab[i]-1; + k = plab[i] - 1; if (k >= 0) { /* Ignore background */ /* Insert value into its array, while adjusting the index for the @@ -1672,7 +1670,6 @@ assert(medianc[0] == 0); aperts->median[0] = cpl_tools_get_median_double(medians, aperts->npix[0]); for (k = 1; k < aperts->naperts; k++) { - assert(medianc[k] == medianc[k - 1] + aperts->npix[k - 1]); aperts->median[k] = diff -Nru cpl-7.1.4+ds/cpldrs/cpl_apertures.h cpl-7.2.2+ds/cpldrs/cpl_apertures.h --- cpl-7.1.4+ds/cpldrs/cpl_apertures.h 2021-05-07 12:09:10.000000000 +0000 +++ cpl-7.2.2+ds/cpldrs/cpl_apertures.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -45,17 +45,17 @@ void cpl_apertures_dump(const cpl_apertures *, FILE *); /* Statistics computation */ -cpl_apertures * cpl_apertures_new_from_image(const cpl_image *, - const cpl_image *) CPL_ATTR_ALLOC; +cpl_apertures *cpl_apertures_new_from_image(const cpl_image *, + const cpl_image *) CPL_ATTR_ALLOC; /* Accessor functions */ cpl_size cpl_apertures_get_size(const cpl_apertures *); double cpl_apertures_get_pos_x(const cpl_apertures *, cpl_size); double cpl_apertures_get_pos_y(const cpl_apertures *, cpl_size); -double cpl_apertures_get_max_x(const cpl_apertures *, cpl_size) - CPL_ATTR_DEPRECATED; -double cpl_apertures_get_max_y(const cpl_apertures *, cpl_size) - CPL_ATTR_DEPRECATED; +double +cpl_apertures_get_max_x(const cpl_apertures *, cpl_size) CPL_ATTR_DEPRECATED; +double +cpl_apertures_get_max_y(const cpl_apertures *, cpl_size) CPL_ATTR_DEPRECATED; double cpl_apertures_get_centroid_x(const cpl_apertures *, cpl_size); double cpl_apertures_get_centroid_y(const cpl_apertures *, cpl_size); cpl_size cpl_apertures_get_maxpos_x(const cpl_apertures *, cpl_size); @@ -80,26 +80,29 @@ /* Sorting functions */ cpl_error_code cpl_apertures_sort_by_npix(cpl_apertures *); -cpl_error_code cpl_apertures_sort_by_max(cpl_apertures *); +cpl_error_code cpl_apertures_sort_by_max(cpl_apertures *); cpl_error_code cpl_apertures_sort_by_flux(cpl_apertures *); /* Detection functions */ -cpl_apertures * cpl_apertures_extract(const cpl_image *, const cpl_vector *, - cpl_size *) CPL_ATTR_ALLOC; -cpl_apertures * cpl_apertures_extract_window(const cpl_image *, - const cpl_vector *, cpl_size, - cpl_size, cpl_size, - cpl_size, cpl_size *) - CPL_ATTR_ALLOC; - -cpl_apertures * cpl_apertures_extract_mask(const cpl_image *, - const cpl_mask *) CPL_ATTR_ALLOC; -cpl_apertures * cpl_apertures_extract_sigma(const cpl_image *, - double) CPL_ATTR_ALLOC; +cpl_apertures *cpl_apertures_extract(const cpl_image *, + const cpl_vector *, + cpl_size *) CPL_ATTR_ALLOC; +cpl_apertures *cpl_apertures_extract_window(const cpl_image *, + const cpl_vector *, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_size *) CPL_ATTR_ALLOC; + +cpl_apertures * +cpl_apertures_extract_mask(const cpl_image *, const cpl_mask *) CPL_ATTR_ALLOC; +cpl_apertures * +cpl_apertures_extract_sigma(const cpl_image *, double) CPL_ATTR_ALLOC; -cpl_bivector* cpl_apertures_get_fwhm(const cpl_image*, - const cpl_apertures*) CPL_ATTR_DEPRECATED; +cpl_bivector *cpl_apertures_get_fwhm(const cpl_image *, + const cpl_apertures *) CPL_ATTR_DEPRECATED; CPL_END_DECLS -#endif +#endif diff -Nru cpl-7.1.4+ds/cpldrs/cpl_apertures_img.h cpl-7.2.2+ds/cpldrs/cpl_apertures_img.h --- cpl-7.1.4+ds/cpldrs/cpl_apertures_img.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cpldrs/cpl_apertures_img.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -28,4 +28,4 @@ #include "cpl_apertures.h" -#endif +#endif diff -Nru cpl-7.1.4+ds/cpldrs/cpl_detector_body.h cpl-7.2.2+ds/cpldrs/cpl_detector_body.h --- cpl-7.1.4+ds/cpldrs/cpl_detector_body.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cpldrs/cpl_detector_body.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -20,12 +20,12 @@ #define CPL_TYPE_ADD(a) CONCAT2X(a, CPL_NAME_TYPE) -static cpl_error_code -CPL_TYPE_ADD(cpl_detector_interpolate_rejected)(CPL_TYPE * pi, - const cpl_binary * bpm, - cpl_size nx, cpl_size ny, - cpl_binary * doit) - CPL_ATTR_NONNULL; +static cpl_error_code CPL_TYPE_ADD(cpl_detector_interpolate_rejected)( + CPL_TYPE *pi, + const cpl_binary *bpm, + cpl_size nx, + cpl_size ny, + cpl_binary *doit) CPL_ATTR_NONNULL; /*----------------------------------------------------------------------------*/ /** @@ -45,23 +45,23 @@ */ /*----------------------------------------------------------------------------*/ static cpl_error_code -CPL_TYPE_ADD(cpl_detector_interpolate_rejected)(CPL_TYPE * pi, - const cpl_binary * bpm, - cpl_size nx, cpl_size ny, - cpl_binary * doit) + CPL_TYPE_ADD(cpl_detector_interpolate_rejected)(CPL_TYPE *pi, + const cpl_binary *bpm, + cpl_size nx, + cpl_size ny, + cpl_binary *doit) { - /* Need a copy of the bpm, to not use as interpolation source pixels that have been interpolated in the same pass */ - cpl_binary * bpmcopy = cpl_malloc((size_t)(nx * ny) * sizeof(*bpm)); - cpl_mask * copy = cpl_mask_wrap(nx, ny, bpmcopy); - const cpl_binary * prev = doit; - cpl_boolean ok; /* All pixels may be bad */ + cpl_binary *bpmcopy = cpl_malloc((size_t)(nx * ny) * sizeof(*bpm)); + cpl_mask *copy = cpl_mask_wrap(nx, ny, bpmcopy); + const cpl_binary *prev = doit; + cpl_boolean ok; /* All pixels may be bad */ (void)memset(bpmcopy, CPL_BINARY_0, (size_t)(prev - bpm)); do { - cpl_binary * found = doit; + cpl_binary *found = doit; /* assert( *doit ); */ @@ -70,7 +70,7 @@ (size_t)(doit - prev)); /* Bad pixels may have been cleaned in remaining buffer as well */ (void)memcpy(bpmcopy + (doit - bpm), doit, - (size_t)(nx * ny - (doit - bpm)) * sizeof(*bpm)); + (size_t)(nx * ny - (doit - bpm)) * sizeof(*bpm)); prev = doit; doit = NULL; @@ -107,7 +107,7 @@ npix++; } if (j + 1 < ny && bpmcopy[ij + nx] == CPL_BINARY_0) { - sumpix += (CPL_SUM_TYPE)pi[ij + nx]; + sumpix += (CPL_SUM_TYPE)pi[ij + nx]; npix++; } @@ -125,7 +125,7 @@ npix++; } } - + if (npix > 0) { /* Found source pixel(s) for interpolation */ #ifdef CPL_DO_ROUND @@ -135,11 +135,12 @@ pi[ij] = (CPL_TYPE)(sumpix / (CPL_SUM_TYPE)npix); *found = CPL_BINARY_0; ok = CPL_TRUE; - } else if (doit == NULL) { + } + else if (doit == NULL) { doit = found; /* First bad pixel to redo */ } - found = memchr(found+1, CPL_BINARY_1, + found = memchr(found + 1, CPL_BINARY_1, (size_t)(nx * ny - ij - 1) * sizeof(*bpm)); } while (found); @@ -148,7 +149,6 @@ cpl_mask_delete(copy); return ok ? CPL_ERROR_NONE : cpl_error_set_(CPL_ERROR_DATA_NOT_FOUND); - } #undef CPL_TYPE_ADD diff -Nru cpl-7.1.4+ds/cpldrs/cpl_detector.c cpl-7.2.2+ds/cpldrs/cpl_detector.c --- cpl-7.1.4+ds/cpldrs/cpl_detector.c 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cpldrs/cpl_detector.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -41,15 +41,16 @@ -----------------------------------------------------------------------------*/ /* Computes the square of an euclidean distance bet. 2 points */ -#define pdist(x1,y1,x2,y2) (((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2))) +#define pdist(x1, y1, x2, y2) \ + (((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2))) /** Computes the square of an euclidean distance bet. 2 points (polar coord) */ -#define qdist(r1,t1,r2,t2) \ - ((r1*r1)+(r2*r2)-2*r1*r2*cos((t1-t2))) +#define qdist(r1, t1, r2, t2) \ + ((r1 * r1) + (r2 * r2) - 2 * r1 * r2 * cos((t1 - t2))) -#define CPL_CLASS_NONE 0 -#define CPL_CLASS_DOUBLE 1 -#define CPL_CLASS_FLOAT 2 -#define CPL_CLASS_INT 3 +#define CPL_CLASS_NONE 0 +#define CPL_CLASS_DOUBLE 1 +#define CPL_CLASS_FLOAT 2 +#define CPL_CLASS_INT 3 /*----------------------------------------------------------------------------*/ /** @@ -71,37 +72,37 @@ /* These three macros are needed for support of the different pixel types */ -#define CONCAT(a,b) a ## _ ## b -#define CONCAT2X(a,b) CONCAT(a,b) +#define CONCAT(a, b) a##_##b +#define CONCAT2X(a, b) CONCAT(a, b) -#define CPL_TYPE double complex +#define CPL_TYPE double complex #define CPL_NAME_TYPE double_complex -#define CPL_SUM_TYPE double complex +#define CPL_SUM_TYPE double complex #include "cpl_detector_body.h" #undef CPL_TYPE #undef CPL_NAME_TYPE -#define CPL_TYPE float complex +#define CPL_TYPE float complex #define CPL_NAME_TYPE float_complex #include "cpl_detector_body.h" #undef CPL_TYPE #undef CPL_NAME_TYPE #undef CPL_SUM_TYPE -#define CPL_TYPE double +#define CPL_TYPE double #define CPL_NAME_TYPE double -#define CPL_SUM_TYPE double +#define CPL_SUM_TYPE double #include "cpl_detector_body.h" #undef CPL_TYPE #undef CPL_NAME_TYPE -#define CPL_TYPE float +#define CPL_TYPE float #define CPL_NAME_TYPE float #include "cpl_detector_body.h" #undef CPL_TYPE #undef CPL_NAME_TYPE -#define CPL_TYPE int +#define CPL_TYPE int #define CPL_NAME_TYPE int #define CPL_DO_ROUND #include "cpl_detector_body.h" @@ -110,25 +111,30 @@ #undef CPL_DO_ROUND #undef CPL_SUM_TYPE -static cpl_error_code cpl_flux_get_window(const cpl_image *, const cpl_size *, - cpl_size, cpl_size, double *, - double *, double *, double *); - -static cpl_bivector * cpl_bivector_gen_rect_poisson(const cpl_size *, - const cpl_size, - const cpl_size) - CPL_ATTR_NONNULL CPL_ATTR_ALLOC; -static cpl_bivector * cpl_bivector_gen_ring_poisson(const double *, - const cpl_size, - const cpl_size) - CPL_ATTR_NONNULL CPL_ATTR_ALLOC; +static cpl_error_code cpl_flux_get_window(const cpl_image *, + const cpl_size *, + cpl_size, + cpl_size, + double *, + double *, + double *, + double *); + +static cpl_bivector * +cpl_bivector_gen_rect_poisson(const cpl_size *, + const cpl_size, + const cpl_size) CPL_ATTR_NONNULL CPL_ATTR_ALLOC; +static cpl_bivector * +cpl_bivector_gen_ring_poisson(const double *, + const cpl_size, + const cpl_size) CPL_ATTR_NONNULL CPL_ATTR_ALLOC; /*----------------------------------------------------------------------------- Function codes -----------------------------------------------------------------------------*/ -#define RECT_RON_HS 4 -#define RECT_RON_SAMPLES 100 +#define RECT_RON_HS 4 +#define RECT_RON_SAMPLES 100 /*----------------------------------------------------------------------------*/ /** @brief Compute the readout noise in a rectangle. @@ -168,16 +174,18 @@ - CPL_ERROR_ILLEGAL_INPUT if the specified window (zone_def) is invalid */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_flux_get_noise_window(const cpl_image * diff, - const cpl_size * zone_def, - cpl_size ron_hsize, - cpl_size ron_nsamp, - double * noise, - double * error) +cpl_error_code +cpl_flux_get_noise_window(const cpl_image *diff, + const cpl_size *zone_def, + cpl_size ron_hsize, + cpl_size ron_nsamp, + double *noise, + double *error) { - return cpl_flux_get_window(diff, zone_def, ron_hsize, ron_nsamp, - noise, error, NULL, NULL) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + return cpl_flux_get_window(diff, zone_def, ron_hsize, ron_nsamp, noise, + error, NULL, NULL) + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } /*----------------------------------------------------------------------------*/ @@ -194,16 +202,18 @@ @note No calls to srand() are made from CPL */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_flux_get_bias_window(const cpl_image * diff, - const cpl_size * zone_def, - cpl_size ron_hsize, - cpl_size ron_nsamp, - double * bias, - double * error) +cpl_error_code +cpl_flux_get_bias_window(const cpl_image *diff, + const cpl_size *zone_def, + cpl_size ron_hsize, + cpl_size ron_nsamp, + double *bias, + double *error) { - return cpl_flux_get_window(diff, zone_def, ron_hsize, ron_nsamp, - NULL, NULL, bias, error) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + return cpl_flux_get_window(diff, zone_def, ron_hsize, ron_nsamp, NULL, NULL, + bias, error) + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } /*----------------------------------------------------------------------------*/ @@ -211,34 +221,34 @@ @brief Internal function, wrapped by cpl_flux_get_{noise,bias}_window(). */ /*----------------------------------------------------------------------------*/ -static cpl_error_code cpl_flux_get_window( - const cpl_image * diff, - const cpl_size * zone_def, - cpl_size ron_hsize, - cpl_size ron_nsamp, - double * noise, - double * noise_error, - double * bias, - double * bias_error) +static cpl_error_code +cpl_flux_get_window(const cpl_image *diff, + const cpl_size *zone_def, + cpl_size ron_hsize, + cpl_size ron_nsamp, + double *noise, + double *noise_error, + double *bias, + double *bias_error) { cpl_errorstate prestate = cpl_errorstate_get(); - const cpl_size hsize = ron_hsize < 0 ? RECT_RON_HS : ron_hsize; + const cpl_size hsize = ron_hsize < 0 ? RECT_RON_HS : ron_hsize; const cpl_size nsamples = ron_nsamp < 0 ? RECT_RON_SAMPLES : ron_nsamp; - cpl_bivector * sample_reg; - cpl_vector * rms_list = NULL; - cpl_vector * bias_list = NULL; - cpl_size rect[4]; - cpl_size zone[4]; - const double * px; - const double * py; - double * pr1 = NULL; - double * pr2 = NULL; - cpl_size i; + cpl_bivector *sample_reg; + cpl_vector *rms_list = NULL; + cpl_vector *bias_list = NULL; + cpl_size rect[4]; + cpl_size zone[4]; + const double *px; + const double *py; + double *pr1 = NULL; + double *pr2 = NULL; + cpl_size i; /* Test entries */ - cpl_ensure_code(diff != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(diff != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(noise != NULL || bias != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(nsamples > 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(nsamples > 0, CPL_ERROR_ILLEGAL_INPUT); /* Generate nsamples window centers in the image */ if (zone_def != NULL) { @@ -246,65 +256,75 @@ rect[1] = zone_def[1] - hsize - 1; /* xmax */ rect[2] = zone_def[2] + hsize + 1; /* ymin */ rect[3] = zone_def[3] - hsize - 1; /* ymax */ - } else { - rect[0] = hsize + 1; /* xmin */ - rect[1] = cpl_image_get_size_x(diff) - hsize - 1; /* xmax */ - rect[2] = hsize + 1; /* ymin */ - rect[3] = cpl_image_get_size_y(diff) - hsize - 1; /* ymax */ + } + else { + rect[0] = hsize + 1; /* xmin */ + rect[1] = cpl_image_get_size_x(diff) - hsize - 1; /* xmax */ + rect[2] = hsize + 1; /* ymin */ + rect[3] = cpl_image_get_size_y(diff) - hsize - 1; /* ymax */ } - cpl_ensure_code( rect[0] < rect[1] && rect[2] < rect[3], - CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(rect[0] < rect[1] && rect[2] < rect[3], + CPL_ERROR_ILLEGAL_INPUT); /* Generate n+1 regions, because the first region is always at (0,0) */ /* and it would bias the measurement. */ - sample_reg = cpl_bivector_gen_rect_poisson(rect, nsamples+1, nsamples+1); - cpl_ensure_code( sample_reg != NULL, CPL_ERROR_ILLEGAL_INPUT); + sample_reg = + cpl_bivector_gen_rect_poisson(rect, nsamples + 1, nsamples + 1); + cpl_ensure_code(sample_reg != NULL, CPL_ERROR_ILLEGAL_INPUT); px = cpl_bivector_get_x_data_const(sample_reg); py = cpl_bivector_get_y_data_const(sample_reg); /* Now, for each window center, extract a vignette and compute the */ /* signal RMS in it. Store this rms into a table. */ - if (noise) rms_list = cpl_vector_new(nsamples); - if (bias) bias_list = cpl_vector_new(nsamples); - - if (noise) pr1 = cpl_vector_get_data(rms_list); - if (bias) pr2 = cpl_vector_get_data(bias_list); - - for (i=0; i nx) continue; + if (zone[1] > nx) + continue; zone[2] = (cpl_size)dy - hsize; - if (zone[2] < 1) continue; + if (zone[2] < 1) + continue; zone[3] = (cpl_size)dy + hsize; - if (zone[3] > ny) continue; + if (zone[3] > ny) + continue; - stdev = cpl_image_get_stdev_window(diff, zone[0], zone[2], - zone[1], zone[3]); + stdev = cpl_image_get_stdev_window(diff, zone[0], zone[2], zone[1], + zone[3]); if (!cpl_errorstate_is_equal(prestate)) { /* All pixels could be bad */ @@ -411,19 +435,21 @@ return cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, "Need at least %" CPL_SIZE_FORMAT "/4 " "(not %" CPL_SIZE_FORMAT ") samples" - " to compute noise", nsamp, rsize); + " to compute noise", + nsamp, rsize); } /* Ignore all but the first rsize elements */ - rms_list = cpl_vector_wrap(rsize, (double*)cpl_vector_unwrap(rms_list)); + rms_list = cpl_vector_wrap(rsize, (double *)cpl_vector_unwrap(rms_list)); /* The error is the rms of the rms */ - if (error != NULL) *error = cpl_vector_get_stdev(rms_list); - + if (error != NULL) + *error = cpl_vector_get_stdev(rms_list); + /* The final computed RMS is the median of all values. */ /* This call will modify the rms_list */ *noise = cpl_vector_get_median(rms_list); - + cpl_vector_delete(rms_list); return CPL_ERROR_NONE; @@ -458,53 +484,61 @@ - CPL_ERROR_DATA_NOT_FOUND if all pixels are bad */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_detector_interpolate_rejected(cpl_image * self) +cpl_error_code +cpl_detector_interpolate_rejected(cpl_image *self) { - const cpl_mask * mask = cpl_image_get_bpm_const(self); + const cpl_mask *mask = cpl_image_get_bpm_const(self); if (mask != NULL) { const cpl_size nx = cpl_image_get_size_x(self); const cpl_size ny = cpl_image_get_size_y(self); - const cpl_binary * bpm = cpl_mask_get_data_const(mask); - cpl_binary * doit = memchr(bpm, CPL_BINARY_1, - (size_t)nx * (size_t)ny * sizeof(*bpm)); + const cpl_binary *bpm = cpl_mask_get_data_const(mask); + cpl_binary *doit = + memchr(bpm, CPL_BINARY_1, (size_t)nx * (size_t)ny * sizeof(*bpm)); if (doit) { - /* Switch on image type */ switch (cpl_image_get_type(self)) { - case CPL_TYPE_DOUBLE: - cpl_ensure_code(!cpl_detector_interpolate_rejected_double - ((double*)cpl_image_get_data(self), bpm, nx, ny, - doit), cpl_error_get_code()); - break; - case CPL_TYPE_FLOAT: - cpl_ensure_code(!cpl_detector_interpolate_rejected_float - ((float*)cpl_image_get_data(self), bpm, nx, ny, - doit), cpl_error_get_code()); - break; - case CPL_TYPE_INT: - cpl_ensure_code(!cpl_detector_interpolate_rejected_int - ((int*)cpl_image_get_data(self), bpm, nx, ny, - doit), cpl_error_get_code()); - break; - case CPL_TYPE_DOUBLE_COMPLEX: - cpl_ensure_code(!cpl_detector_interpolate_rejected_double_complex - ((double complex*)cpl_image_get_data(self), - bpm, nx, ny, doit), cpl_error_get_code()); - break; - case CPL_TYPE_FLOAT_COMPLEX: - cpl_ensure_code(!cpl_detector_interpolate_rejected_float_complex - ((float complex*)cpl_image_get_data(self), - bpm, nx, ny, doit), cpl_error_get_code()); - break; - default: - return cpl_error_set_(CPL_ERROR_INVALID_TYPE); + case CPL_TYPE_DOUBLE: + cpl_ensure_code(!cpl_detector_interpolate_rejected_double( + (double *)cpl_image_get_data(self), bpm, + nx, ny, doit), + cpl_error_get_code()); + break; + case CPL_TYPE_FLOAT: + cpl_ensure_code(!cpl_detector_interpolate_rejected_float( + (float *)cpl_image_get_data(self), bpm, + nx, ny, doit), + cpl_error_get_code()); + break; + case CPL_TYPE_INT: + cpl_ensure_code(!cpl_detector_interpolate_rejected_int( + (int *)cpl_image_get_data(self), bpm, + nx, ny, doit), + cpl_error_get_code()); + break; + case CPL_TYPE_DOUBLE_COMPLEX: + cpl_ensure_code( + !cpl_detector_interpolate_rejected_double_complex( + (double complex *)cpl_image_get_data(self), bpm, nx, + ny, doit), + cpl_error_get_code()); + break; + case CPL_TYPE_FLOAT_COMPLEX: + cpl_ensure_code( + !cpl_detector_interpolate_rejected_float_complex( + (float complex *)cpl_image_get_data(self), bpm, nx, + ny, doit), + cpl_error_get_code()); + break; + default: + return cpl_error_set_(CPL_ERROR_INVALID_TYPE); } } (void)cpl_image_accept_all(self); /* bpm could be empty */ - } else if (self == NULL) { + } + else if (self == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } @@ -555,28 +589,29 @@ - CPL_ERROR_ILLEGAL_INPUT if np is not strictly positive */ /*----------------------------------------------------------------------------*/ -static cpl_bivector * cpl_bivector_gen_rect_poisson(const cpl_size * r, - const cpl_size np, - const cpl_size homog) +static cpl_bivector * +cpl_bivector_gen_rect_poisson(const cpl_size *r, + const cpl_size np, + const cpl_size homog) { - double min_dist; - cpl_size i; - cpl_size gnp; - cpl_bivector * list; - double cand_x, cand_y; - cpl_boolean ok; - cpl_size start_ndx; - cpl_size xmin, xmax, ymin, ymax; + double min_dist; + cpl_size i; + cpl_size gnp; + cpl_bivector *list; + double cand_x, cand_y; + cpl_boolean ok; + cpl_size start_ndx; + cpl_size xmin, xmax, ymin, ymax; /* Corrected Homogeneity factor */ - const cpl_size homogc = 0 < homog && homog < np ? homog : np; - double * px; - double * py; + const cpl_size homogc = 0 < homog && homog < np ? homog : np; + double *px; + double *py; /* error handling: test arguments are correct */ - cpl_ensure( np > 0, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(np > 0, CPL_ERROR_ILLEGAL_INPUT, NULL); list = cpl_bivector_new(np); - cpl_ensure(list, CPL_ERROR_NULL_INPUT,NULL); + cpl_ensure(list, CPL_ERROR_NULL_INPUT, NULL); px = cpl_bivector_get_x_data(list); py = cpl_bivector_get_y_data(list); @@ -585,11 +620,11 @@ ymin = r[2]; ymax = r[3]; - min_dist = CPL_MATH_SQRT1_2*(double)((xmax-xmin)*(ymax-ymin)) - / (double)(homogc+1); - gnp = 1; - px[0] = 0; - py[0] = 0; + min_dist = CPL_MATH_SQRT1_2 * (double)((xmax - xmin) * (ymax - ymin)) / + (double)(homogc + 1); + gnp = 1; + px[0] = 0; + py[0] = 0; /* First: generate points */ while (gnp < homogc) { @@ -599,8 +634,8 @@ /* Check the candidate obeys the minimal Poisson distance */ ok = CPL_TRUE; - for (i=0; i points. */ - start_ndx=0; + start_ndx = 0; while (gnp < np) { /* Pick a random point within requested range */ cand_x = cpl_drand() * (double)(xmax - xmin) + (double)xmin; @@ -624,11 +659,9 @@ /* Check the candidate obeys the minimal Poisson distance */ ok = CPL_TRUE; - for (i=0; i points. */ - start_ndx=0; + start_ndx = 0; while (gnp < np) { /* Pick a random point within requested range */ cand_x = cpl_drand() * (double)(xmax - xmin) + (double)xmin; @@ -652,11 +685,9 @@ /* Check the candidate obeys the minimal Poisson distance */ ok = CPL_TRUE; - for (i=0; i points */ while (gnp < homogc) { @@ -728,7 +759,7 @@ /* Check the candidate obeys the minimal Poisson distance */ ok = CPL_TRUE; - for (i=0; i imsize) ijdo = imsize - ij; + if (ij + ijdo > imsize) + ijdo = imsize - ij; /* Upper limit for pixel index in this iteration */ ijstop = ij + ijdo; - - /* Fill in matrices */ - for (k=0; k < np; k++) { + /* Fill in matrices */ + for (k = 0; k < np; k++) { ii = ii0; ini = ini0; - for (i=0; i < ijdo; i++, ii++) { + for (i = 0; i < ijdo; i++, ii++) { if (ii == nx) { ii = 0; ini += innx; @@ -138,7 +136,7 @@ if (xnmean != 0.0) { /* Shift polynomials back */ - for (i=0; i < ijdo; i++) { + for (i = 0; i < ijdo; i++) { cpl_polynomial_shift_double(px + i * nc, (int)nc, xnmean); } } @@ -162,22 +160,23 @@ if (fiterror != NULL) { switch (cpl_image_get_type(fiterror)) { - case CPL_TYPE_DOUBLE: - cpl_fit_imagelist_residual_double(fiterror, ij, ijstop, + case CPL_TYPE_DOUBLE: + cpl_fit_imagelist_residual_double(fiterror, ij, ijstop, + x_pos, xpow, mx, mb); + break; + case CPL_TYPE_FLOAT: + cpl_fit_imagelist_residual_float(fiterror, ij, ijstop, x_pos, xpow, mx, mb); - break; - case CPL_TYPE_FLOAT: - cpl_fit_imagelist_residual_float(fiterror, ij, ijstop, - x_pos, xpow, mx, mb); - break; - case CPL_TYPE_INT: - cpl_fit_imagelist_residual_int(fiterror, ij, ijstop, - x_pos, xpow, mx, mb); - break; - default: - error = cpl_error_set_(CPL_ERROR_UNSUPPORTED_MODE); + break; + case CPL_TYPE_INT: + cpl_fit_imagelist_residual_int(fiterror, ij, ijstop, x_pos, + xpow, mx, mb); + break; + default: + error = cpl_error_set_(CPL_ERROR_UNSUPPORTED_MODE); } - if (error) break; + if (error) + break; } } cpl_matrix_delete(mx); @@ -188,7 +187,6 @@ } - /*----------------------------------------------------------------------------*/ /** @brief Fill a row in the imagelist with the contents of the matrix @@ -202,23 +200,23 @@ */ /*----------------------------------------------------------------------------*/ -static void CPL_TYPE_ADD(cpl_fit_imagelist_fill)(cpl_imagelist * self, - cpl_size ij, cpl_size ijstop, - const cpl_matrix * mx) +static void CPL_TYPE_ADD(cpl_fit_imagelist_fill)(cpl_imagelist *self, + cpl_size ij, + cpl_size ijstop, + const cpl_matrix *mx) { - const cpl_size ijdo = ijstop - ij; const cpl_size nc = cpl_matrix_get_ncol(mx); - const double * px = cpl_matrix_get_data_const(mx); - cpl_size i, k; + const double *px = cpl_matrix_get_data_const_(mx); + cpl_size i, k; assert(cpl_imagelist_get_size(self) == nc); - for (k=0; k < nc; k++) { - CPL_TYPE * pdest = ij - + CPL_TYPE_ADD(cpl_image_get_data)(cpl_imagelist_get(self, k)); - for (i=0; i < ijdo; i++) { + for (k = 0; k < nc; k++) { + CPL_TYPE *pdest = + ij + CPL_TYPE_ADD(cpl_image_get_data)(cpl_imagelist_get(self, k)); + for (i = 0; i < ijdo; i++) { #ifdef CPL_TYPE_INT_ROUND /* Round off to nearest integer */ pdest[i] = CPL_TYPE_INT_ROUND(px[nc * i + k]); @@ -245,48 +243,49 @@ */ /*----------------------------------------------------------------------------*/ -static void CPL_TYPE_ADD(cpl_fit_imagelist_residual)(cpl_image * self, +static void CPL_TYPE_ADD(cpl_fit_imagelist_residual)(cpl_image *self, cpl_size ij, cpl_size ijstop, - const cpl_vector * x_pos, - const cpl_vector * xpow, - const cpl_matrix * mx, - const cpl_matrix * mb) + const cpl_vector *x_pos, + const cpl_vector *xpow, + const cpl_matrix *mx, + const cpl_matrix *mb) { - double err, sq_err; + double err, sq_err; const cpl_size nc = cpl_matrix_get_ncol(mx); const cpl_size np = cpl_vector_get_size(x_pos); /* pself points to 1st element in jj'th row */ - CPL_TYPE * pself = CPL_TYPE_ADD(cpl_image_get_data)(self); + CPL_TYPE *pself = CPL_TYPE_ADD(cpl_image_get_data)(self); - const double * pp = cpl_vector_get_data_const(x_pos); + const double *pp = cpl_vector_get_data_const(x_pos); /* If mindeg == 0 xpow is NULL (since no multiplication is needed) */ - const double * pm = xpow != NULL ? cpl_vector_get_data_const(xpow) : NULL; - const double * px = cpl_matrix_get_data_const(mx); - const double * pb = cpl_matrix_get_data_const(mb); + const double *pm = xpow != NULL ? cpl_vector_get_data_const(xpow) : NULL; + const double *px = cpl_matrix_get_data_const(mx); + const double *pb = cpl_matrix_get_data_const(mb); cpl_size i, j, k; - for (i=ij; i < ijstop; i++, pb += np, px += nc) { + for (i = ij; i < ijstop; i++, pb += np, px += nc) { sq_err = 0.0; - for (j=0; j < np; j++) { - + for (j = 0; j < np; j++) { /* Evaluate the polynomial using Horners scheme, see cpl_polynomial_eval_1d() */ k = nc; err = px[--k]; - while (k) err = pp[j] * err + px[--k]; + while (k) + err = pp[j] * err + px[--k]; /* Multiply by x^mindeg - wheen needed */ /* Substract expected value to compute the residual */ if (pm != NULL) { err = err * pm[j] - pb[j]; - } else { + } + else { err -= pb[j]; } @@ -294,14 +293,13 @@ } #ifdef CPL_TYPE_INT_ROUND /* Round off to nearest integer */ - pself[i] = CPL_TYPE_INT_ROUND(sq_err/(double)np); + pself[i] = CPL_TYPE_INT_ROUND(sq_err / (double)np); #else - pself[i] = (CPL_TYPE)(sq_err/(double)np); + pself[i] = (CPL_TYPE)(sq_err / (double)np); #endif } cpl_tools_add_flops((cpl_flops)((ijstop - ij) * (np * (2 * nc + 1) + 1))); - } #undef CPL_TYPE_ADD diff -Nru cpl-7.1.4+ds/cpldrs/cpl_fit.c cpl-7.2.2+ds/cpldrs/cpl_fit.c --- cpl-7.1.4+ds/cpldrs/cpl_fit.c 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cpldrs/cpl_fit.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -75,15 +75,17 @@ Private function prototypes -----------------------------------------------------------------------------*/ -static -cpl_error_code cpl_fit_imagelist_polynomial_window_(cpl_imagelist *, - const cpl_vector *, - const cpl_imagelist *, - cpl_size, cpl_size, - cpl_size, cpl_boolean, - cpl_image *) +static cpl_error_code +cpl_fit_imagelist_polynomial_window_(cpl_imagelist *, + const cpl_vector *, + const cpl_imagelist *, + cpl_size, + cpl_size, + cpl_size, + cpl_boolean, + cpl_image *) #ifdef CPL_HAVE_ATTR_NONNULL - __attribute__((nonnull(1,2,3))) + __attribute__((nonnull(1, 2, 3))) #endif ; @@ -91,71 +93,94 @@ const cpl_mask *, const cpl_vector *, const cpl_imagelist *, - cpl_size, cpl_size, - cpl_size, cpl_image *); + cpl_size, + cpl_size, + cpl_size, + cpl_image *); static cpl_error_code cpl_fit_imagelist_polynomial_one(cpl_imagelist *, cpl_polynomial *, double *, double *, - cpl_size, cpl_size, + cpl_size, + cpl_size, const cpl_vector *, const cpl_imagelist *, - cpl_size, cpl_size, - cpl_size, cpl_image *); + cpl_size, + cpl_size, + cpl_size, + cpl_image *); static cpl_error_code cpl_fit_imagelist_polynomial_double(cpl_imagelist *, const cpl_matrix *, const cpl_matrix *, const cpl_vector *, const cpl_imagelist *, - cpl_size, cpl_size, + cpl_size, + cpl_size, const cpl_vector *, - double, cpl_image *); + double, + cpl_image *); static cpl_error_code cpl_fit_imagelist_polynomial_float(cpl_imagelist *, const cpl_matrix *, const cpl_matrix *, const cpl_vector *, const cpl_imagelist *, - cpl_size, cpl_size, + cpl_size, + cpl_size, const cpl_vector *, - double, cpl_image *); + double, + cpl_image *); static cpl_error_code cpl_fit_imagelist_polynomial_int(cpl_imagelist *, const cpl_matrix *, const cpl_matrix *, const cpl_vector *, const cpl_imagelist *, - cpl_size, cpl_size, + cpl_size, + cpl_size, const cpl_vector *, - double, cpl_image *); + double, + cpl_image *); -static void cpl_fit_imagelist_residual_double(cpl_image *, cpl_size, cpl_size, +static void cpl_fit_imagelist_residual_double(cpl_image *, + cpl_size, + cpl_size, const cpl_vector *, const cpl_vector *, const cpl_matrix *, const cpl_matrix *); -static void cpl_fit_imagelist_residual_float(cpl_image *, cpl_size, cpl_size, +static void cpl_fit_imagelist_residual_float(cpl_image *, + cpl_size, + cpl_size, const cpl_vector *, const cpl_vector *, const cpl_matrix *, const cpl_matrix *); -static void cpl_fit_imagelist_residual_int(cpl_image *, cpl_size, cpl_size, +static void cpl_fit_imagelist_residual_int(cpl_image *, + cpl_size, + cpl_size, const cpl_vector *, const cpl_vector *, const cpl_matrix *, const cpl_matrix *); -static void cpl_fit_imagelist_fill_double(cpl_imagelist *, cpl_size, cpl_size, +static void cpl_fit_imagelist_fill_double(cpl_imagelist *, + cpl_size, + cpl_size, const cpl_matrix *); - -static void cpl_fit_imagelist_fill_float(cpl_imagelist *, cpl_size, cpl_size, + +static void cpl_fit_imagelist_fill_float(cpl_imagelist *, + cpl_size, + cpl_size, const cpl_matrix *); - -static void cpl_fit_imagelist_fill_int(cpl_imagelist *, cpl_size, cpl_size, + +static void cpl_fit_imagelist_fill_int(cpl_imagelist *, + cpl_size, + cpl_size, const cpl_matrix *); static cpl_size cpl_fit_imagelist_polynomial_find_block_size(cpl_size, @@ -166,8 +191,8 @@ cpl_type); static int bigauss(const double[], const double[], double *) CPL_ATTR_NONNULL; -static int bigauss_derivative(const double[], const double[], double[]) - CPL_ATTR_NONNULL; +static int +bigauss_derivative(const double[], const double[], double[]) CPL_ATTR_NONNULL; /*----------------------------------------------------------------------------- @@ -260,10 +285,13 @@ /*----------------------------------------------------------------------------*/ cpl_error_code -cpl_fit_lvmq(const cpl_matrix *x, const cpl_matrix *sigma_x, - const cpl_vector *y, const cpl_vector *sigma_y, - cpl_vector *a, const int ia[], - int (*f)(const double x[], const double a[], double *result), +cpl_fit_lvmq(const cpl_matrix *x, + const cpl_matrix *sigma_x, + const cpl_vector *y, + const cpl_vector *sigma_y, + cpl_vector *a, + const int ia[], + int (*f)(const double x[], const double a[], double *result), int (*dfda)(const double x[], const double a[], double result[]), double relative_tolerance, int tolerance_count, @@ -272,11 +300,11 @@ double *red_chisq, cpl_matrix **covariance) { - return cpl_fit_lvmq_(x, sigma_x, y, sigma_y, a, ia, NULL, NULL, f, dfda, - relative_tolerance, tolerance_count, - max_iterations, mse, red_chisq, covariance) - ? cpl_error_set_where_() : CPL_ERROR_NONE; + relative_tolerance, tolerance_count, max_iterations, + mse, red_chisq, covariance) + ? cpl_error_set_where_() + : CPL_ERROR_NONE; } /*----------------------------------------------------------------------------*/ @@ -363,60 +391,60 @@ CPL_TYPE_DOUBLE, CPL_TYPE_FLOAT, CPL_TYPE_INT. */ /*----------------------------------------------------------------------------*/ -cpl_imagelist * -cpl_fit_imagelist_polynomial_window(const cpl_vector * x_pos, - const cpl_imagelist * values, - cpl_size llx, - cpl_size lly, - cpl_size urx, - cpl_size ury, - cpl_size mindeg, - cpl_size maxdeg, - cpl_boolean is_symsamp, - cpl_type pixeltype, - cpl_image * fiterror) +cpl_imagelist * +cpl_fit_imagelist_polynomial_window(const cpl_vector *x_pos, + const cpl_imagelist *values, + cpl_size llx, + cpl_size lly, + cpl_size urx, + cpl_size ury, + cpl_size mindeg, + cpl_size maxdeg, + cpl_boolean is_symsamp, + cpl_type pixeltype, + cpl_image *fiterror) { + cpl_imagelist *self; + cpl_mask *redo = NULL; - cpl_imagelist * self; - cpl_mask * redo = NULL; - - const cpl_image * first = cpl_imagelist_get_const(values, 0); - const cpl_size mx = cpl_image_get_size_x(first); - const cpl_size my = cpl_image_get_size_y(first); + const cpl_image *first = cpl_imagelist_get_const(values, 0); + const cpl_size mx = cpl_image_get_size_x(first); + const cpl_size my = cpl_image_get_size_y(first); - cpl_error_code error = CPL_ERROR_NONE; + cpl_error_code error = CPL_ERROR_NONE; /* Number of unknowns to determine */ - const cpl_size nc = 1 + maxdeg - mindeg; - const cpl_size np = cpl_vector_get_size(x_pos); - const cpl_size nx = urx - llx + 1; - const cpl_size ny = ury - lly + 1; + const cpl_size nc = 1 + maxdeg - mindeg; + const cpl_size np = cpl_vector_get_size(x_pos); + const cpl_size nx = urx - llx + 1; + const cpl_size ny = ury - lly + 1; - cpl_size i; + cpl_size i; - cpl_ensure(x_pos != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(x_pos != NULL, CPL_ERROR_NULL_INPUT, NULL); cpl_ensure(values != NULL, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(mindeg >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(mindeg >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL); cpl_ensure(maxdeg >= mindeg, CPL_ERROR_ILLEGAL_INPUT, NULL); cpl_ensure(np == cpl_imagelist_get_size(values), CPL_ERROR_INCOMPATIBLE_INPUT, NULL); - cpl_ensure(cpl_imagelist_is_uniform(values)==0, + cpl_ensure(cpl_imagelist_is_uniform(values) == 0, CPL_ERROR_INCOMPATIBLE_INPUT, NULL); cpl_ensure(pixeltype == CPL_TYPE_DOUBLE || pixeltype == CPL_TYPE_FLOAT || - pixeltype == CPL_TYPE_INT, CPL_ERROR_UNSUPPORTED_MODE, NULL); + pixeltype == CPL_TYPE_INT, + CPL_ERROR_UNSUPPORTED_MODE, NULL); if (fiterror != NULL) { cpl_ensure(cpl_image_get_size_x(fiterror) == nx && - cpl_image_get_size_y(fiterror) == ny, + cpl_image_get_size_y(fiterror) == ny, CPL_ERROR_INCOMPATIBLE_INPUT, NULL); } - cpl_ensure(np >= nc, CPL_ERROR_DATA_NOT_FOUND, NULL); + cpl_ensure(np >= nc, CPL_ERROR_DATA_NOT_FOUND, NULL); cpl_ensure(llx >= 1 && llx <= urx, CPL_ERROR_ILLEGAL_INPUT, NULL); cpl_ensure(lly >= 1 && lly <= ury, CPL_ERROR_ILLEGAL_INPUT, NULL); @@ -433,32 +461,35 @@ cpl_ensure(!cpl_vector_ensure_distinct(x_pos, nc), CPL_ERROR_SINGULAR_MATRIX, NULL); - + /* Allocate nc images to store the results */ self = cpl_imagelist_new(); - for (i=0; i < nc; i++) { - cpl_image * image = cpl_image_wrap(nx, ny, pixeltype, cpl_malloc - ((size_t)nx * (size_t)ny - * cpl_type_get_sizeof(pixeltype))); - + for (i = 0; i < nc; i++) { + cpl_image *image = + cpl_image_wrap(nx, ny, pixeltype, + cpl_malloc((size_t)nx * (size_t)ny * + cpl_type_get_sizeof(pixeltype))); + (void)cpl_imagelist_set(self, image, i); } /* Find the bad input pixels and create a map of bpm-interpolations */ for (i = 0; i < np; i++) { - const cpl_image * img = cpl_imagelist_get_const(values, i); - const cpl_mask * mask = cpl_image_get_bpm_const(img); + const cpl_image *img = cpl_imagelist_get_const(values, i); + const cpl_mask *mask = cpl_image_get_bpm_const(img); if (mask != NULL) { if (redo == NULL) { redo = cpl_mask_extract_(mask, llx, lly, urx, ury); - } else if (nx == mx && ny == my) { + } + else if (nx == mx && ny == my) { /* The below extraction is not needed */ cpl_mask_or(redo, mask); - } else { - cpl_mask * window = cpl_mask_extract_(mask, llx, lly, urx, ury); + } + else { + cpl_mask *window = cpl_mask_extract_(mask, llx, lly, urx, ury); if (window != NULL) { cpl_mask_or(redo, window); cpl_mask_delete(window); @@ -467,23 +498,22 @@ } } - if (redo == NULL || cpl_mask_get_first_window(redo, 1, 1, nx, ny, - CPL_BINARY_0) >= 0) { + if (redo == NULL || + cpl_mask_get_first_window(redo, 1, 1, nx, ny, CPL_BINARY_0) >= 0) { /* Some (or all) interpolations are free of bad pixels */ - error = cpl_fit_imagelist_polynomial_window_(self, x_pos, values, - llx, lly, mindeg, - is_symsamp, fiterror); + error = + cpl_fit_imagelist_polynomial_window_(self, x_pos, values, llx, lly, + mindeg, is_symsamp, fiterror); } - if (!error && redo != NULL - && cpl_mask_get_first_window(redo, 1, 1, nx, ny, - CPL_BINARY_1) >= 0) { + if (!error && redo != NULL && + cpl_mask_get_first_window(redo, 1, 1, nx, ny, CPL_BINARY_1) >= 0) { /* Some (or all) interpolations have bad pixels */ - error = cpl_fit_imagelist_polynomial_bpm(self, redo, x_pos, values, - llx, lly, mindeg, fiterror); + error = cpl_fit_imagelist_polynomial_bpm(self, redo, x_pos, values, llx, + lly, mindeg, fiterror); } cpl_mask_delete(redo); @@ -498,7 +528,6 @@ } - /*----------------------------------------------------------------------------*/ /** @brief Least-squares fit a polynomial to each pixel in a list of images @@ -519,35 +548,35 @@ */ /*----------------------------------------------------------------------------*/ static cpl_error_code -cpl_fit_imagelist_polynomial_window_(cpl_imagelist * self, - const cpl_vector * x_pos, - const cpl_imagelist * values, - cpl_size llx, - cpl_size lly, - cpl_size mindeg, - cpl_boolean is_symsamp, - cpl_image * fiterror) +cpl_fit_imagelist_polynomial_window_(cpl_imagelist *self, + const cpl_vector *x_pos, + const cpl_imagelist *values, + cpl_size llx, + cpl_size lly, + cpl_size mindeg, + cpl_boolean is_symsamp, + cpl_image *fiterror) { - - const cpl_size nc = cpl_imagelist_get_size(self); - const cpl_size np = cpl_vector_get_size_(x_pos); - cpl_matrix * mv; /* The transpose of the Vandermonde matrix, V' */ - cpl_matrix * mh; /* Upper triangular part of SPD Hankel matrix, + const cpl_size nc = cpl_imagelist_get_size(self); + const cpl_size np = cpl_vector_get_size_(x_pos); + cpl_matrix *mv; /* The transpose of the Vandermonde matrix, V' */ + cpl_matrix *mh; /* Upper triangular part of SPD Hankel matrix, H = V' * V */ const cpl_boolean is_eqzero = is_symsamp && mindeg == 0; - const cpl_vector * xhat; - cpl_vector * xtmp = NULL; - const double * dx; - double * dmv; - double xmean; - cpl_error_code error; + const cpl_vector *xhat; + cpl_vector *xtmp = NULL; + const double *dx; + double *dmv; + double xmean; + cpl_error_code error; int i, j, k; if (mindeg == 0) { /* Transform: xhat = x - mean(x) */ xhat = xtmp = cpl_vector_transform_mean(x_pos, &xmean); - } else { + } + else { xhat = x_pos; xmean = 0.0; } @@ -555,20 +584,20 @@ dx = cpl_vector_get_data_const_(xhat); /* Create matrices */ - dmv = (double*)cpl_malloc((size_t)nc * (size_t)np * sizeof(*dmv)); - mv = cpl_matrix_wrap(nc, np, dmv); + dmv = (double *)cpl_malloc((size_t)nc * (size_t)np * sizeof(*dmv)); + mv = cpl_matrix_wrap(nc, np, dmv); /* Fill Vandermonde matrix */ - for (j=0; j < np; j++) { + for (j = 0; j < np; j++) { double f_prod = cpl_tools_ipow(dx[j], (int)mindeg); dmv[j] = f_prod; - for (k=1; k < nc; k++) { + for (k = 1; k < nc; k++) { f_prod *= dx[j]; dmv[np * k + j] = f_prod; } } - cpl_tools_add_flops( (cpl_flops)(np * ( nc - 1))); + cpl_tools_add_flops((cpl_flops)(np * (nc - 1))); cpl_vector_delete(xtmp); @@ -582,11 +611,10 @@ mh = cpl_matrix_product_normal_create(mv); if (is_eqzero) { - /* Ensure that the Hankel matrix has zeros on all odd skew diagonals - above the (non-skew) main diagonal */ - double * dmh = cpl_matrix_get_data(mh); + double *dmh = cpl_matrix_get_data_(mh); for (i = 0; i < nc; i++) { for (j = i + 1; j < nc; j += 2) { @@ -603,58 +631,57 @@ error = cpl_matrix_decomp_chol(mh); if (!error) { - const cpl_image * first = cpl_imagelist_get_const(values, 0); + const cpl_image *first = cpl_imagelist_get_const(values, 0); - const cpl_vector * xpow = NULL; + const cpl_vector *xpow = NULL; xtmp = NULL; /* Should not be able to fail at this point */ if (mindeg == 1) { xpow = x_pos; - } if (mindeg > 1) { - const double * d_pos = cpl_vector_get_data_const_(x_pos); - double * ppow = (double*)cpl_malloc((size_t)np - * sizeof(*ppow)); + } + if (mindeg > 1) { + const double *d_pos = cpl_vector_get_data_const_(x_pos); + double *ppow = (double *)cpl_malloc((size_t)np * sizeof(*ppow)); xpow = xtmp = cpl_vector_wrap(np, ppow); for (i = 0; i < np; i++) { ppow[i] = cpl_tools_ipow(d_pos[i], (int)mindeg); } - } switch (cpl_image_get_type(first)) { - case CPL_TYPE_DOUBLE: - error = cpl_fit_imagelist_polynomial_double(self, mh, mv, x_pos, - values, llx, lly, - xpow, -xmean, fiterror); - break; - case CPL_TYPE_FLOAT: - error = cpl_fit_imagelist_polynomial_float(self, mh, mv, x_pos, - values, llx, lly, - xpow, -xmean, fiterror); - break; - case CPL_TYPE_INT: - error = cpl_fit_imagelist_polynomial_int(self, mh, mv, x_pos, - values, llx, lly, - xpow, -xmean, fiterror); - break; - default: - error = CPL_ERROR_UNSUPPORTED_MODE; - break; + case CPL_TYPE_DOUBLE: + error = + cpl_fit_imagelist_polynomial_double(self, mh, mv, x_pos, + values, llx, lly, xpow, + -xmean, fiterror); + break; + case CPL_TYPE_FLOAT: + error = + cpl_fit_imagelist_polynomial_float(self, mh, mv, x_pos, + values, llx, lly, xpow, + -xmean, fiterror); + break; + case CPL_TYPE_INT: + error = cpl_fit_imagelist_polynomial_int(self, mh, mv, x_pos, + values, llx, lly, xpow, + -xmean, fiterror); + break; + default: + error = CPL_ERROR_UNSUPPORTED_MODE; + break; } cpl_vector_delete(xtmp); - } cpl_matrix_delete(mh); cpl_matrix_delete(mv); return error ? cpl_error_set_where_() : CPL_ERROR_NONE; - } /*----------------------------------------------------------------------------*/ @@ -685,25 +712,27 @@ CPL_TYPE_DOUBLE, CPL_TYPE_FLOAT, CPL_TYPE_INT. */ /*----------------------------------------------------------------------------*/ -cpl_imagelist * cpl_fit_imagelist_polynomial(const cpl_vector * x_pos, - const cpl_imagelist * values, - cpl_size mindeg, - cpl_size maxdeg, - cpl_boolean is_symsamp, - cpl_type pixeltype, - cpl_image * fiterror) +cpl_imagelist * +cpl_fit_imagelist_polynomial(const cpl_vector *x_pos, + const cpl_imagelist *values, + cpl_size mindeg, + cpl_size maxdeg, + cpl_boolean is_symsamp, + cpl_type pixeltype, + cpl_image *fiterror) { - const cpl_image * first = cpl_imagelist_get_const(values, 0); - const cpl_size nx = cpl_image_get_size_x(first); - const cpl_size ny = cpl_image_get_size_y(first); - - cpl_imagelist * self - = cpl_fit_imagelist_polynomial_window(x_pos, values, 1, 1, nx, ny, - mindeg, maxdeg, is_symsamp, - pixeltype, fiterror); + const cpl_image *first = cpl_imagelist_get_const(values, 0); + const cpl_size nx = cpl_image_get_size_x(first); + const cpl_size ny = cpl_image_get_size_y(first); + + cpl_imagelist *self = + cpl_fit_imagelist_polynomial_window(x_pos, values, 1, 1, nx, ny, mindeg, + maxdeg, is_symsamp, pixeltype, + fiterror); /* Propagate error, if any */ - if (self == NULL) (void)cpl_error_set_where_(); + if (self == NULL) + (void)cpl_error_set_where_(); return self; } @@ -755,10 +784,11 @@ const double b2 = (x[0] - a[3]) / a[5]; const double b3 = (x[1] - a[4]) / a[6]; - *result = a[0] - + a[1] / (CPL_MATH_2PI * a[5] * a[6] * sqrt(1.0 - a[2] * a[2])) - * exp(-0.5 * (b2 * b2 - 2 * a[2] * b2 * b3 + b3 * b3) - / (1.0 - a[2] * a[2])); + *result = + a[0] + a[1] / + (CPL_MATH_2PI * a[5] * a[6] * sqrt(1.0 - a[2] * a[2])) * + exp(-0.5 * (b2 * b2 - 2 * a[2] * b2 * b3 + b3 * b3) / + (1.0 - a[2] * a[2])); return 0; } @@ -803,8 +833,8 @@ result[2] = b7 * b1 * ((b2 * b3 - a[2] * b0 * b1) + a[2]); result[3] = b7 / a[5] * b1 * (b2 - a[2] * b3); result[4] = b7 / a[6] * b1 * (b3 - a[2] * b2); - result[5] =-b7 / a[5] * (b1 * b2 * (a[2] * b3 - b2) + 1); - result[6] =-b7 / a[6] * (b1 * b3 * (a[2] * b2 - b3) + 1); + result[5] = -b7 / a[5] * (b1 * b2 * (a[2] * b3 - b2) + 1); + result[6] = -b7 / a[6] * (b1 * b3 * (a[2] * b2 - b3) + 1); return errno ? -1 : 0; } @@ -956,22 +986,23 @@ * and C is the 7x7 matrix of the gaussian parameters. */ -cpl_error_code cpl_fit_image_gaussian(const cpl_image *im, - const cpl_image *im_err, - cpl_size xpos, - cpl_size ypos, - cpl_size xsize, - cpl_size ysize, - cpl_array *parameters, - cpl_array *err_params, - const cpl_array *fit_params, - double *rms, - double *red_chisq, - cpl_matrix **covariance, - double *major, - double *minor, - double *angle, - cpl_matrix **phys_cov) +cpl_error_code +cpl_fit_image_gaussian(const cpl_image *im, + const cpl_image *im_err, + cpl_size xpos, + cpl_size ypos, + cpl_size xsize, + cpl_size ysize, + cpl_array *parameters, + cpl_array *err_params, + const cpl_array *fit_params, + double *rms, + double *red_chisq, + cpl_matrix **covariance, + double *major, + double *minor, + double *angle, + cpl_matrix **phys_cov) { const cpl_size mx = cpl_image_get_size_x(im); const cpl_size my = cpl_image_get_size_y(im); @@ -979,46 +1010,46 @@ * Extraction box */ - const cpl_size llx = CX_MAX(xpos - xsize/2, 1); - const cpl_size lly = CX_MAX(ypos - ysize/2, 1); - const cpl_size urx = CX_MIN(xpos + xsize/2, mx); - const cpl_size ury = CX_MIN(ypos + ysize/2, my); + const cpl_size llx = CX_MAX(xpos - xsize / 2, 1); + const cpl_size lly = CX_MAX(ypos - ysize / 2, 1); + const cpl_size urx = CX_MIN(xpos + xsize / 2, mx); + const cpl_size ury = CX_MIN(ypos + ysize / 2, my); const cpl_size nx = urx - llx + 1; const cpl_size ny = ury - lly + 1; - int ia[] = {1, 1, 1, 1, 1, 1, 1}; - double background; - double amplitude; - double normalisation; - double correlation; - double xcen, ycen; - double xsigma, ysigma; + int ia[] = { 1, 1, 1, 1, 1, 1, 1 }; + double background; + double amplitude; + double normalisation; + double correlation; + double xcen, ycen; + double xsigma, ysigma; cpl_size ixcen, iycen; cpl_size nrow; - int i, j; - int invalid; + int i, j; + int invalid; cpl_boolean do_wrap = CPL_FALSE; cpl_boolean has_bpm; - cpl_size nfit = 7; /* Number of parameters to fit, up to 7 */ + cpl_size nfit = 7; /* Number of parameters to fit, up to 7 */ - cpl_image *ubox = NULL; - const cpl_image *box = NULL; - const cpl_image *ebox = NULL; - cpl_image *fbox = NULL; - cpl_vector *a = NULL; - double *adata; - cpl_size acols; - cpl_vector *values = NULL; - cpl_vector *dvalues = NULL; - cpl_matrix *positions = NULL; - cpl_matrix *own_cov = NULL; - double *posi_data; - double *val_data; - double *dval_data = NULL; + cpl_image *ubox = NULL; + const cpl_image *box = NULL; + const cpl_image *ebox = NULL; + cpl_image *fbox = NULL; + cpl_vector *a = NULL; + double *adata; + cpl_size acols; + cpl_vector *values = NULL; + cpl_vector *dvalues = NULL; + cpl_matrix *positions = NULL; + cpl_matrix *own_cov = NULL; + double *posi_data; + double *val_data; + double *dval_data = NULL; - cpl_array *lowersan = NULL; - cpl_array *uppersan = NULL; + cpl_array *lowersan = NULL; + cpl_array *uppersan = NULL; cpl_errorstate prestate = cpl_errorstate_get(); cpl_error_code status = CPL_ERROR_NONE; @@ -1028,9 +1059,12 @@ * Always reset physical parameters */ - if (major ) *major = 0.0; - if (minor ) *minor = 0.0; - if (angle ) *angle = 0.0; + if (major) + *major = 0.0; + if (minor) + *minor = 0.0; + if (angle) + *angle = 0.0; /* @@ -1039,60 +1073,60 @@ if (im == NULL) return cpl_error_set_message_(CPL_ERROR_NULL_INPUT, - "Missing input data image."); + "Missing input data image."); - if (xpos < 1 || - ypos < 1 || - xpos > mx || - ypos > my || - xsize > mx || + if (xpos < 1 || ypos < 1 || xpos > mx || ypos > my || xsize > mx || ysize > my) return cpl_error_set_message_(CPL_ERROR_ACCESS_OUT_OF_RANGE, - "Fitting box extends beyond image."); + "Fitting box extends beyond image."); if (xsize < 3 || ysize < 3) return cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, - "Fitting box is too small."); + "Fitting box is too small."); if (im_err) - if (cpl_image_get_size_x(im_err) != mx || + if (cpl_image_get_size_x(im_err) != mx || cpl_image_get_size_y(im_err) != my) return cpl_error_set_message_(CPL_ERROR_INCOMPATIBLE_INPUT, - "Input images must have same size."); + "Input images must have same size."); if (parameters == NULL) return cpl_error_set_message_(CPL_ERROR_NULL_INPUT, - "Missing input parameters array."); + "Missing input parameters array."); if (cpl_array_get_type(parameters) != CPL_TYPE_DOUBLE) - return cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, - "Parameters array should be CPL_TYPE_DOUBLE."); + return cpl_error_set_message_( + CPL_ERROR_INVALID_TYPE, + "Parameters array should be CPL_TYPE_DOUBLE."); if (err_params) if (cpl_array_get_type(err_params) != CPL_TYPE_DOUBLE) - return cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, - "Parameters error array should be CPL_TYPE_DOUBLE."); + return cpl_error_set_message_( + CPL_ERROR_INVALID_TYPE, + "Parameters error array should be CPL_TYPE_DOUBLE."); if (fit_params) if (cpl_array_get_type(fit_params) != CPL_TYPE_INT) - return cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, - "Parameters error array should be CPL_TYPE_INT."); + return cpl_error_set_message_( + CPL_ERROR_INVALID_TYPE, + "Parameters error array should be CPL_TYPE_INT."); if (err_params || covariance || red_chisq || phys_cov) if (im_err == NULL) return cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, - "Missing input parameters errors."); + "Missing input parameters errors."); - switch(cpl_image_get_type(im)) { /* List of legal types, ended by break */ - case CPL_TYPE_DOUBLE: - do_wrap = CPL_TRUE; - case CPL_TYPE_INT: - case CPL_TYPE_FLOAT: - break; - default: - return cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, - "Cannot fit a gaussian to %s values", - cpl_type_get_name(cpl_image_get_type(im))); + switch (cpl_image_get_type(im)) { /* List of legal types, ended by break */ + case CPL_TYPE_DOUBLE: + do_wrap = CPL_TRUE; + case CPL_TYPE_INT: + case CPL_TYPE_FLOAT: + break; + default: + return cpl_error_set_message_(CPL_ERROR_INVALID_TYPE, + "Cannot fit a gaussian to %s values", + cpl_type_get_name( + cpl_image_get_type(im))); } if (im_err && cpl_image_get_type(im) != cpl_image_get_type(im_err)) { @@ -1100,8 +1134,8 @@ "Data and error images must have " "same type, not %s and %s", cpl_type_get_name(cpl_image_get_type(im)), - cpl_type_get_name(cpl_image_get_type - (im_err))); + cpl_type_get_name( + cpl_image_get_type(im_err))); } /* @@ -1110,14 +1144,16 @@ if (llx == 1 && lly == 1 && urx == mx && ury == my) { box = im; - } else { + } + else { box = ubox = cpl_image_extract(im, llx, lly, urx, ury); } if (im_err) { if (box == im) { ebox = im_err; - } else { + } + else { ebox = fbox = cpl_image_extract(im_err, llx, lly, urx, ury); } } @@ -1133,15 +1169,16 @@ if (invalid || flag) continue; - ia[i] = 0; /* Flag it as frozen */ + ia[i] = 0; /* Flag it as frozen */ nfit--; cpl_array_get_double(parameters, i, &invalid); if (invalid) { cpl_image_delete(ubox); cpl_image_delete(fbox); - return cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, - "Missing value for frozen parameter %d.", i); + return cpl_error_set_message_( + CPL_ERROR_ILLEGAL_INPUT, + "Missing value for frozen parameter %d.", i); } } @@ -1184,7 +1221,6 @@ normalisation = (cpl_image_get_mean(box) - background) * (double)(nx * ny); if (fabs(normalisation) < FLT_EPSILON) { - /* * Image is flat: return a flat gaussian, with undefined * position of max and sigmas... @@ -1192,13 +1228,13 @@ cpl_image_delete(ubox); cpl_image_delete(fbox); - cpl_array_set_double (parameters, 0, background); - cpl_array_set_double (parameters, 1, 0.0); + cpl_array_set_double(parameters, 0, background); + cpl_array_set_double(parameters, 1, 0.0); cpl_array_set_invalid(parameters, 2); cpl_array_set_invalid(parameters, 3); cpl_array_set_invalid(parameters, 4); cpl_array_set_invalid(parameters, 5); - cpl_array_set_double (parameters, 6, 0.0); + cpl_array_set_double(parameters, 6, 0.0); return CPL_ERROR_NONE; } @@ -1217,7 +1253,7 @@ if (ia[2]) { /* Correlation has hard boundaries */ cpl_array_set_double(lowersan, 2, -1.0); - cpl_array_set_double(uppersan, 2, 1.0); + cpl_array_set_double(uppersan, 2, 1.0); } /* @@ -1227,7 +1263,8 @@ if (normalisation > 0.0) { cpl_image_get_maxpos(box, &ixcen, &iycen); amplitude = cpl_image_get_(box, ixcen, iycen) - background; - } else { + } + else { cpl_image_get_minpos(box, &ixcen, &iycen); amplitude = cpl_image_get_(box, ixcen, iycen) - background; } @@ -1256,43 +1293,48 @@ if (invalid) { ysigma = cpl_array_get_double(parameters, 6, &invalid); if (invalid) { - int xhalf = 0; - const double value = amplitude / 2.0 + background; - cpl_boolean found = CPL_FALSE; + int xhalf = 0; + const double value = amplitude / 2.0 + background; + cpl_boolean found = CPL_FALSE; if (normalisation > 0.0) { for (i = 1; i < nx; i++) { int bad; - const double prev = cpl_image_get(box, i, iycen, &bad); - const double next = bad ? 0.0 : - cpl_image_get(box, i + 1, iycen, &bad); + const double prev = cpl_image_get(box, i, iycen, &bad); + const double next = + bad ? 0.0 : cpl_image_get(box, i + 1, iycen, &bad); - if (bad) continue; + if (bad) + continue; if (prev < value && value <= next) { xhalf = i - 1; found = CPL_TRUE; break; - } else if (value < prev && next <= value) { + } + else if (value < prev && next <= value) { xhalf = i + 1; found = CPL_TRUE; break; } } - } else { + } + else { for (i = 1; i < nx; i++) { int bad; - const double prev = cpl_image_get(box, i, iycen, &bad); - const double next = bad ? 0.0 : - cpl_image_get(box, i + 1, iycen, &bad); + const double prev = cpl_image_get(box, i, iycen, &bad); + const double next = + bad ? 0.0 : cpl_image_get(box, i + 1, iycen, &bad); - if (bad) continue; + if (bad) + continue; if (value < prev && next <= value) { xhalf = i - 1; found = CPL_TRUE; break; - } else if (prev < value && value <= next) { + } + else if (prev < value && value <= next) { xhalf = i + 1; found = CPL_TRUE; break; @@ -1301,14 +1343,17 @@ } if (found) { xsigma = ysigma = fabs(xcen - xhalf); - } else { + } + else { xsigma = (double)xsize; ysigma = (double)ysize; } - } else { + } + else { xsigma = ysigma; } - } else { + } + else { ysigma = cpl_array_get_double(parameters, 6, &invalid); if (invalid) { ysigma = xsigma; @@ -1318,12 +1363,14 @@ if (ia[3]) { /* Do not allow the center to be far outside the box limit */ cpl_array_set_double(lowersan, 3, 1.0 - 3.0 * CPL_MAX(xsize, xsigma)); - cpl_array_set_double(uppersan, 3, (double)nx + 3.0 * CPL_MAX(xsize, xsigma)); + cpl_array_set_double(uppersan, 3, + (double)nx + 3.0 * CPL_MAX(xsize, xsigma)); } if (ia[4]) { /* Do not allow the center to be far outside the box limit */ cpl_array_set_double(lowersan, 4, 1.0 - 3.0 * CPL_MAX(ysize, ysigma)); - cpl_array_set_double(uppersan, 4, (double)ny + 3.0 * CPL_MAX(ysize, ysigma)); + cpl_array_set_double(uppersan, 4, + (double)ny + 3.0 * CPL_MAX(ysize, ysigma)); } if (ia[5]) { @@ -1335,7 +1382,7 @@ if (ia[6]) { cpl_array_set_double(lowersan, 6, 0.0); /* Sigma must remain positive */ /* The fit has nothing to work with if the slope is outside the box */ - cpl_array_set_double(uppersan, 6, + cpl_array_set_double(uppersan, 6, 5.0 * CPL_MATH_FWHM_SIG * CPL_MAX(ysize, ysigma)); } @@ -1347,7 +1394,6 @@ normalisation = cpl_array_get_double(parameters, 1, &invalid); if (invalid) { - /* * It would be possible to guess the normalisation * (i.e., the volume of the gaussian, i.e. the total @@ -1386,9 +1432,10 @@ if (amplitude > 0.0) { cpl_array_set_double(lowersan, 0, -amplitude); - cpl_array_set_double(uppersan, 0, amplitude); - } else if (amplitude < 0.0) { - cpl_array_set_double(lowersan, 0, amplitude); + cpl_array_set_double(uppersan, 0, amplitude); + } + else if (amplitude < 0.0) { + cpl_array_set_double(lowersan, 0, amplitude); cpl_array_set_double(uppersan, 0, -amplitude); } } @@ -1403,29 +1450,34 @@ !cpl_mask_is_empty(cpl_image_get_bpm_const(box))) { has_bpm = CPL_TRUE; do_wrap = CPL_FALSE; - } else if (ebox != NULL && cpl_image_get_bpm_const(ebox) != NULL && - !cpl_mask_is_empty(cpl_image_get_bpm_const(ebox))) { + } + else if (ebox != NULL && cpl_image_get_bpm_const(ebox) != NULL && + !cpl_mask_is_empty(cpl_image_get_bpm_const(ebox))) { has_bpm = CPL_TRUE; do_wrap = CPL_FALSE; - } else { + } + else { has_bpm = CPL_FALSE; } /* Allocate all temporary data in one go */ acols = do_wrap ? 2 : (ebox ? 4 : 3); - adata = (double*)cpl_malloc((7 + acols * nrow) * sizeof(double)); + adata = (double *)cpl_malloc((7 + acols * nrow) * sizeof(double)); posi_data = adata + 7; if (do_wrap) { CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual); - val_data = (double*)cpl_image_get_data_double_const(box); - if (ebox) dval_data = (double*)cpl_image_get_data_double_const(ebox); + val_data = (double *)cpl_image_get_data_double_const(box); + if (ebox) + dval_data = (double *)cpl_image_get_data_double_const(ebox); CPL_DIAG_PRAGMA_POP; - } else { + } + else { /* Arrays are oversized by number of bad pixels if any. Don't care */ - val_data = posi_data + 2 * nrow; - if (ebox) dval_data = val_data + nrow; + val_data = posi_data + 2 * nrow; + if (ebox) + dval_data = val_data + nrow; } if (has_bpm) { @@ -1437,16 +1489,19 @@ for (j = 0; j < ny; j++) { for (i = 0; i < nx; i++) { int bad; - const double value = cpl_image_get(box, i+1, j+1, &bad); + const double value = cpl_image_get(box, i + 1, j + 1, &bad); if (!bad) { - posi_data[2 * row ] = (double)(i + 1); + posi_data[2 * row] = (double)(i + 1); posi_data[2 * row + 1] = (double)(j + 1); val_data[row] = value; if (ebox) { - const double evalue = cpl_image_get(ebox, i+1, j+1, &bad); - if (!bad) dval_data[row++] = evalue; - } else { + const double evalue = + cpl_image_get(ebox, i + 1, j + 1, &bad); + if (!bad) + dval_data[row++] = evalue; + } + else { row++; } } @@ -1454,26 +1509,25 @@ } assert(row < nrow); nrow = row; - - } else { + } + else { cpl_size row = 0; for (j = 0; j < ny; j++) { for (i = 0; i < nx; i++, row++) { - - posi_data[2 * row ] = (double)(i + 1); + posi_data[2 * row] = (double)(i + 1); posi_data[2 * row + 1] = (double)(j + 1); - val_data[row] = cpl_image_get_(box, i+1, j+1); + val_data[row] = cpl_image_get_(box, i + 1, j + 1); - if (ebox) dval_data[row] = cpl_image_get_(ebox, i+1, j+1); + if (ebox) + dval_data[row] = cpl_image_get_(ebox, i + 1, j + 1); } } assert(row == nrow); } if (nrow < nfit) { - /* * Too few values for the free parameters! */ @@ -1485,13 +1539,14 @@ cpl_image_delete(fbox); cpl_free(adata); - return cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, "%d/%d good " + return cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, + "%d/%d good " "pixel(s) too few for %d free parameter" - "(s)", (int)nrow, (int)(nx * ny), - (int)nfit); + "(s)", + (int)nrow, (int)(nx * ny), (int)nfit); } - values = cpl_vector_wrap(nrow, val_data); + values = cpl_vector_wrap(nrow, val_data); dvalues = dval_data ? cpl_vector_wrap(nrow, dval_data) : NULL; positions = cpl_matrix_wrap(nrow, 2, posi_data); @@ -1525,13 +1580,14 @@ if (dvalues) { #ifndef NDEBUG - const double * dval_data2 = cpl_vector_get_data_const_(dvalues); + const double *dval_data2 = cpl_vector_get_data_const_(dvalues); assert(dval_data2 == dval_data); #endif /* Defer check for non-positive errors to here so bpms can be ignored */ for (i = 0; i < nrow; i++) { - if (dval_data[i] <= 0.0) break; + if (dval_data[i] <= 0.0) + break; } if (i < nrow) { @@ -1547,34 +1603,28 @@ return cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, "Non-positive error %g found in error" - " image, sample %d/%d", dval_data[i], - 1+(int)i, (int)nrow); + " image, sample %d/%d", + dval_data[i], 1 + (int)i, (int)nrow); } - if (red_chisq != NULL) *red_chisq = 0.0; - status = cpl_fit_lvmq_(positions, NULL, - values, dvalues, - a, ia, lowersan, uppersan, bigauss, bigauss_derivative, - CPL_FIT_LVMQ_TOLERANCE, - CPL_FIT_LVMQ_COUNT, - CPL_FIT_LVMQ_MAXITER, - rms, red_chisq, &own_cov); + if (red_chisq != NULL) + *red_chisq = 0.0; + status = cpl_fit_lvmq_(positions, NULL, values, dvalues, a, ia, + lowersan, uppersan, bigauss, bigauss_derivative, + CPL_FIT_LVMQ_TOLERANCE, CPL_FIT_LVMQ_COUNT, + CPL_FIT_LVMQ_MAXITER, rms, red_chisq, &own_cov); } else { - status = cpl_fit_lvmq_(positions, NULL, - values, NULL, - a, ia, lowersan, uppersan, bigauss, bigauss_derivative, - CPL_FIT_LVMQ_TOLERANCE, - CPL_FIT_LVMQ_COUNT, - CPL_FIT_LVMQ_MAXITER, - rms, NULL, NULL); + status = cpl_fit_lvmq_(positions, NULL, values, NULL, a, ia, lowersan, + uppersan, bigauss, bigauss_derivative, + CPL_FIT_LVMQ_TOLERANCE, CPL_FIT_LVMQ_COUNT, + CPL_FIT_LVMQ_MAXITER, rms, NULL, NULL); } cpl_array_delete(lowersan); cpl_array_delete(uppersan); if (status == CPL_ERROR_SINGULAR_MATRIX) { - /* * Betting these two errors are really to be ignored... */ @@ -1600,11 +1650,10 @@ cpl_vector_unwrap(dvalues); if (status == CPL_ERROR_NONE) { - - double S_x, S_y, R, theta, A, B; - double DS_x, DS_y, DR; - double S_x_plus, S_y_plus, R_plus; - double theta_plus, A_plus, B_plus; + double S_x, S_y, R, theta, A, B; + double DS_x, DS_y, DR; + double S_x_plus, S_y_plus, R_plus; + double theta_plus, A_plus, B_plus; if (rms) *rms = sqrt(*rms); @@ -1629,104 +1678,101 @@ End of check section, requiring -std=c99 */ - /* + /* * Save best fit parameters: center of gaussian is * converted to input image coordinates, evaluations * of sigmas are forced positive (they might be both * negative - it would generate the same gaussian). */ - cpl_array_set_double(parameters, 0, cpl_vector_get_(a, 0)); - cpl_array_set_double(parameters, 1, cpl_vector_get_(a, 1)); - cpl_array_set_double(parameters, 2, cpl_vector_get_(a, 2)); - cpl_array_set_double(parameters, 3, cpl_vector_get_(a, 3) - + (double)(llx - 1)); - cpl_array_set_double(parameters, 4, cpl_vector_get_(a, 4) - + (double)(lly - 1)); - cpl_array_set_double(parameters, 5, fabs(cpl_vector_get_(a, 5))); - cpl_array_set_double(parameters, 6, fabs(cpl_vector_get_(a, 6))); + cpl_array_set_double(parameters, 0, cpl_vector_get_(a, 0)); + cpl_array_set_double(parameters, 1, cpl_vector_get_(a, 1)); + cpl_array_set_double(parameters, 2, cpl_vector_get_(a, 2)); + cpl_array_set_double(parameters, 3, + cpl_vector_get_(a, 3) + (double)(llx - 1)); + cpl_array_set_double(parameters, 4, + cpl_vector_get_(a, 4) + (double)(lly - 1)); + cpl_array_set_double(parameters, 5, fabs(cpl_vector_get_(a, 5))); + cpl_array_set_double(parameters, 6, fabs(cpl_vector_get_(a, 6))); - /* + /* * Get from the diagonal of the covariance matrix the variances * and fill the error array: */ - if (err_params && own_cov) { - for (i = 0; i < 7; i++) { - if (ia[i]) - cpl_array_set_double(err_params, i, - sqrt(cpl_matrix_get(own_cov, i, i))); - } + if (err_params && own_cov) { + for (i = 0; i < 7; i++) { + if (ia[i]) + cpl_array_set_double(err_params, i, + sqrt(cpl_matrix_get_(own_cov, i, i))); } + } - /* + /* * Obtain semiaxes and rotation angle of ellipse at 1-sigma level */ - S_x = cpl_array_get_double(parameters, 5, NULL); - S_y = cpl_array_get_double(parameters, 6, NULL); - R = cpl_array_get_double(parameters, 2, NULL); - - if (err_params) { - DS_x = cpl_array_get_double(err_params, 5, NULL); - DS_y = cpl_array_get_double(err_params, 6, NULL); - DR = cpl_array_get_double(err_params, 2, NULL); - } - else { - DS_x = 0.0; - DS_y = 0.0; - DR = 0.0; - } + S_x = cpl_array_get_double(parameters, 5, NULL); + S_y = cpl_array_get_double(parameters, 6, NULL); + R = cpl_array_get_double(parameters, 2, NULL); + if (err_params) { + DS_x = cpl_array_get_double(err_params, 5, NULL); + DS_y = cpl_array_get_double(err_params, 6, NULL); + DR = cpl_array_get_double(err_params, 2, NULL); + } + else { + DS_x = 0.0; + DS_y = 0.0; + DR = 0.0; + } - if (fabs(R) <= DR) { - if (S_x - S_y >= - sqrt(DS_x * DS_x + DS_y * DS_y)) { - /* + if (fabs(R) <= DR) { + if (S_x - S_y >= -sqrt(DS_x * DS_x + DS_y * DS_y)) { + /* * Circular distribution, or elongated along x axis * (within known uncertainties). */ - theta = 0.0; - A = S_x; - B = S_y; - } - else { - - /* + theta = 0.0; + A = S_x; + B = S_y; + } + else { + /* * Distribution elongated along y axis (within known * uncertainties). */ - theta = CPL_MATH_PI_2; - A = S_y; - B = S_x; - } + theta = CPL_MATH_PI_2; + A = S_y; + B = S_x; } - else { - theta = 0.5 * atan2(2 * R, (S_x * S_x - S_y * S_y)/ S_x / S_y); - A = S_x * S_y - * sqrt(2 * (1 - R * R) * cos(2 * theta) - / ((S_x * S_x + S_y * S_y) * cos(2 * theta) - + S_y * S_y - S_x * S_x)); - B = S_x * S_y - * sqrt(2 * (1 - R * R) * cos(2 * theta) - / ((S_x * S_x + S_y * S_y) * cos(2 * theta) - - S_y * S_y + S_x * S_x)); - } - - if (angle) - *angle = theta; - if (major) - *major = A; - if (minor) - *minor = B; - - if (phys_cov) { + } + else { + theta = 0.5 * atan2(2 * R, (S_x * S_x - S_y * S_y) / S_x / S_y); + A = S_x * S_y * + sqrt(2 * (1 - R * R) * cos(2 * theta) / + ((S_x * S_x + S_y * S_y) * cos(2 * theta) + S_y * S_y - + S_x * S_x)); + B = S_x * S_y * + sqrt(2 * (1 - R * R) * cos(2 * theta) / + ((S_x * S_x + S_y * S_y) * cos(2 * theta) - S_y * S_y + + S_x * S_x)); + } + + if (angle) + *angle = theta; + if (major) + *major = A; + if (minor) + *minor = B; - /* + if (phys_cov) { + /* * Compute the 3x3 covariance matrix G for the derived * quantities theta, A and B: * @@ -1739,235 +1785,235 @@ * numerically when the analytical approach is impervious. */ - cpl_matrix *jacobian = cpl_matrix_new(3, 7); + cpl_matrix *jacobian = cpl_matrix_new(3, 7); - /* + /* * First row: derivatives of theta. */ - cpl_matrix_set(jacobian, 0, 0, 0.0); /* d(theta)/d(p0) */ - cpl_matrix_set(jacobian, 0, 1, 0.0); /* d(theta)/d(p1) */ + cpl_matrix_set_(jacobian, 0, 0, 0.0); /* d(theta)/d(p0) */ + cpl_matrix_set_(jacobian, 0, 1, 0.0); /* d(theta)/d(p1) */ - R_plus = R + DR; - S_x_plus = S_x + DS_x; - S_y_plus = S_y + DS_y; - - if (fabs(R_plus) <= DR) { - if (S_x - S_y >= - sqrt(DS_x * DS_x + DS_y * DS_y)) { - theta_plus = 0.0; - } - else { - theta_plus = CPL_MATH_PI_2; - } + R_plus = R + DR; + S_x_plus = S_x + DS_x; + S_y_plus = S_y + DS_y; + + if (fabs(R_plus) <= DR) { + if (S_x - S_y >= -sqrt(DS_x * DS_x + DS_y * DS_y)) { + theta_plus = 0.0; } else { - theta_plus = 0.5 * atan2(2 * R_plus, - (S_x * S_x - S_y * S_y)/ S_x / S_y); + theta_plus = CPL_MATH_PI_2; } + } + else { + theta_plus = 0.5 * atan2(2 * R_plus, + (S_x * S_x - S_y * S_y) / S_x / S_y); + } - if (DR == 0.0) - cpl_matrix_set(jacobian, 0, 2, 0.0); - else - cpl_matrix_set(jacobian, 0, 2, (theta_plus-theta) / DR); - /* d(theta)/d(p2) */ - cpl_matrix_set(jacobian, 0, 3, 0.0); /* d(theta)/d(p3) */ - cpl_matrix_set(jacobian, 0, 4, 0.0); /* d(theta)/d(p4) */ - - if (fabs(R) <= DR) { - if (S_x_plus - S_y >= - sqrt(DS_x * DS_x + DS_y * DS_y)) { - theta_plus = 0.0; - } - else { - theta_plus = CPL_MATH_PI_2; - } + if (DR == 0.0) + cpl_matrix_set_(jacobian, 0, 2, 0.0); + else + cpl_matrix_set_(jacobian, 0, 2, (theta_plus - theta) / DR); + /* d(theta)/d(p2) */ + cpl_matrix_set_(jacobian, 0, 3, 0.0); /* d(theta)/d(p3) */ + cpl_matrix_set_(jacobian, 0, 4, 0.0); /* d(theta)/d(p4) */ + + if (fabs(R) <= DR) { + if (S_x_plus - S_y >= -sqrt(DS_x * DS_x + DS_y * DS_y)) { + theta_plus = 0.0; } else { - theta_plus = 0.5 * atan2(2 * R, - (S_x_plus * S_x_plus - S_y * S_y) - / S_x_plus / S_y); + theta_plus = CPL_MATH_PI_2; } + } + else { + theta_plus = + 0.5 * atan2(2 * R, (S_x_plus * S_x_plus - S_y * S_y) / + S_x_plus / S_y); + } - if (DS_x == 0.0) - cpl_matrix_set(jacobian, 0, 5, 0.0); - else - cpl_matrix_set(jacobian, 0, 5, (theta_plus-theta) / DS_x); - /* d(theta)/d(p5) */ - - if (fabs(R) <= DR) { - if (S_x - S_y_plus >= - sqrt(DS_x * DS_x + DS_y * DS_y)) { - theta_plus = 0.0; - } - else { - theta_plus = CPL_MATH_PI_2; - } + if (DS_x == 0.0) + cpl_matrix_set_(jacobian, 0, 5, 0.0); + else + cpl_matrix_set_(jacobian, 0, 5, (theta_plus - theta) / DS_x); + /* d(theta)/d(p5) */ + + if (fabs(R) <= DR) { + if (S_x - S_y_plus >= -sqrt(DS_x * DS_x + DS_y * DS_y)) { + theta_plus = 0.0; } else { - theta_plus = 0.5 * atan2(2 * R, - (S_x * S_x - S_y_plus * S_y_plus) - / S_x / S_y_plus); + theta_plus = CPL_MATH_PI_2; } + } + else { + theta_plus = + 0.5 * atan2(2 * R, (S_x * S_x - S_y_plus * S_y_plus) / S_x / + S_y_plus); + } - if (DS_y == 0.0) - cpl_matrix_set(jacobian, 0, 6, 0.0); - else - cpl_matrix_set(jacobian, 0, 6, (theta_plus-theta) / DS_y); - /* d(theta)/d(p6) */ + if (DS_y == 0.0) + cpl_matrix_set_(jacobian, 0, 6, 0.0); + else + cpl_matrix_set_(jacobian, 0, 6, (theta_plus - theta) / DS_y); + /* d(theta)/d(p6) */ - /* + /* * Second row: derivatives of A. */ - cpl_matrix_set(jacobian, 1, 0, 0.0); /* d(A)/d(p0) */ - cpl_matrix_set(jacobian, 1, 1, 0.0); /* d(A)/d(p1) */ + cpl_matrix_set_(jacobian, 1, 0, 0.0); /* d(A)/d(p0) */ + cpl_matrix_set_(jacobian, 1, 1, 0.0); /* d(A)/d(p1) */ - if (fabs(R_plus) <= DR) { - if (S_x - S_y >= - sqrt(DS_x * DS_x + DS_y * DS_y)) { - A_plus = S_x; - } - else { - A_plus = S_y; - } + if (fabs(R_plus) <= DR) { + if (S_x - S_y >= -sqrt(DS_x * DS_x + DS_y * DS_y)) { + A_plus = S_x; } else { - A_plus = S_x * S_y - * sqrt(2 * (1 - R_plus * R_plus) * cos(2 * theta) - / ((S_x * S_x + S_y * S_y) * cos(2 * theta) - + S_y * S_y - S_x * S_x)); - } - - if (DR == 0.0) - cpl_matrix_set(jacobian, 1, 2, 0.0); - else - cpl_matrix_set(jacobian, 1, 2, (A_plus-A) / DR); - /* d(A)/d(p2) */ - cpl_matrix_set(jacobian, 1, 3, 0.0); /* d(A)/d(p3) */ - cpl_matrix_set(jacobian, 1, 4, 0.0); /* d(A)/d(p4) */ - - if (fabs(R) <= DR) { - if (S_x_plus - S_y >= - sqrt(DS_x * DS_x + DS_y * DS_y)) { - A_plus = S_x_plus; - } - else { - A_plus = S_y; - } + A_plus = S_y; + } + } + else { + A_plus = S_x * S_y * + sqrt(2 * (1 - R_plus * R_plus) * cos(2 * theta) / + ((S_x * S_x + S_y * S_y) * cos(2 * theta) + + S_y * S_y - S_x * S_x)); + } + + if (DR == 0.0) + cpl_matrix_set_(jacobian, 1, 2, 0.0); + else + cpl_matrix_set_(jacobian, 1, 2, (A_plus - A) / DR); + /* d(A)/d(p2) */ + cpl_matrix_set_(jacobian, 1, 3, 0.0); /* d(A)/d(p3) */ + cpl_matrix_set_(jacobian, 1, 4, 0.0); /* d(A)/d(p4) */ + + if (fabs(R) <= DR) { + if (S_x_plus - S_y >= -sqrt(DS_x * DS_x + DS_y * DS_y)) { + A_plus = S_x_plus; } else { - A = S_x_plus * S_y - * sqrt(2 * (1 - R * R) * cos(2 * theta) - / ((S_x_plus * S_x_plus + S_y * S_y) * cos(2 * theta) - + S_y * S_y - S_x_plus * S_x_plus)); + A_plus = S_y; } + } + else { + A = S_x_plus * S_y * + sqrt(2 * (1 - R * R) * cos(2 * theta) / + ((S_x_plus * S_x_plus + S_y * S_y) * cos(2 * theta) + + S_y * S_y - S_x_plus * S_x_plus)); + } - if (DS_x == 0.0) - cpl_matrix_set(jacobian, 1, 5, 0.0); - else - cpl_matrix_set(jacobian, 1, 5, (A_plus-A) / DS_x); - /* d(A)/d(p5) */ - - if (fabs(R) <= DR) { - if (S_x - S_y_plus >= - sqrt(DS_x * DS_x + DS_y * DS_y)) { - A_plus = S_x; - } - else { - A_plus = S_y_plus; - } + if (DS_x == 0.0) + cpl_matrix_set_(jacobian, 1, 5, 0.0); + else + cpl_matrix_set_(jacobian, 1, 5, (A_plus - A) / DS_x); + /* d(A)/d(p5) */ + + if (fabs(R) <= DR) { + if (S_x - S_y_plus >= -sqrt(DS_x * DS_x + DS_y * DS_y)) { + A_plus = S_x; } else { - A = S_x * S_y_plus - * sqrt(2 * (1 - R * R) * cos(2 * theta) - / ((S_x * S_x + S_y_plus * S_y_plus) * cos(2 * theta) - + S_y_plus * S_y_plus - S_x * S_x)); + A_plus = S_y_plus; } + } + else { + A = S_x * S_y_plus * + sqrt(2 * (1 - R * R) * cos(2 * theta) / + ((S_x * S_x + S_y_plus * S_y_plus) * cos(2 * theta) + + S_y_plus * S_y_plus - S_x * S_x)); + } - if (DS_y == 0.0) - cpl_matrix_set(jacobian, 1, 6, 0.0); - else - cpl_matrix_set(jacobian, 1, 6, (A_plus-A) / DS_y); - /* d(A)/d(p6) */ + if (DS_y == 0.0) + cpl_matrix_set_(jacobian, 1, 6, 0.0); + else + cpl_matrix_set_(jacobian, 1, 6, (A_plus - A) / DS_y); + /* d(A)/d(p6) */ - /* + /* * Third row: derivatives of B. */ - cpl_matrix_set(jacobian, 2, 0, 0.0); /* d(B)/d(p0) */ - cpl_matrix_set(jacobian, 2, 1, 0.0); /* d(B)/d(p1) */ + cpl_matrix_set_(jacobian, 2, 0, 0.0); /* d(B)/d(p0) */ + cpl_matrix_set_(jacobian, 2, 1, 0.0); /* d(B)/d(p1) */ - if (fabs(R_plus) <= DR) { - if (S_x - S_y >= - sqrt(DS_x * DS_x + DS_y * DS_y)) { - B_plus = S_y; - } - else { - B_plus = S_x; - } + if (fabs(R_plus) <= DR) { + if (S_x - S_y >= -sqrt(DS_x * DS_x + DS_y * DS_y)) { + B_plus = S_y; } else { - B_plus = S_x * S_y - * sqrt(2 * (1 - R_plus * R_plus) * cos(2 * theta) - / ((S_x * S_x + S_y * S_y) * cos(2 * theta) - - S_y * S_y + S_x * S_x)); - } - - if (DR == 0.0) - cpl_matrix_set(jacobian, 2, 2, 0.0); - else - cpl_matrix_set(jacobian, 2, 2, (B_plus-B) / DR); - /* d(B)/d(p2) */ - cpl_matrix_set(jacobian, 2, 3, 0.0); /* d(B)/d(p3) */ - cpl_matrix_set(jacobian, 2, 4, 0.0); /* d(B)/d(p4) */ - - if (fabs(R) <= DR) { - if (S_x_plus - S_y >= - sqrt(DS_x * DS_x + DS_y * DS_y)) { - B_plus = S_y; - } - else { - B_plus = S_x_plus; - } + B_plus = S_x; + } + } + else { + B_plus = S_x * S_y * + sqrt(2 * (1 - R_plus * R_plus) * cos(2 * theta) / + ((S_x * S_x + S_y * S_y) * cos(2 * theta) - + S_y * S_y + S_x * S_x)); + } + + if (DR == 0.0) + cpl_matrix_set_(jacobian, 2, 2, 0.0); + else + cpl_matrix_set_(jacobian, 2, 2, (B_plus - B) / DR); + /* d(B)/d(p2) */ + cpl_matrix_set_(jacobian, 2, 3, 0.0); /* d(B)/d(p3) */ + cpl_matrix_set_(jacobian, 2, 4, 0.0); /* d(B)/d(p4) */ + + if (fabs(R) <= DR) { + if (S_x_plus - S_y >= -sqrt(DS_x * DS_x + DS_y * DS_y)) { + B_plus = S_y; } else { - B = S_x_plus * S_y - * sqrt(2 * (1 - R * R) * cos(2 * theta) - / ((S_x_plus * S_x_plus + S_y * S_y) * cos(2 * theta) - - S_y * S_y + S_x_plus * S_x_plus)); + B_plus = S_x_plus; } + } + else { + B = S_x_plus * S_y * + sqrt(2 * (1 - R * R) * cos(2 * theta) / + ((S_x_plus * S_x_plus + S_y * S_y) * cos(2 * theta) - + S_y * S_y + S_x_plus * S_x_plus)); + } - if (DS_x == 0.0) - cpl_matrix_set(jacobian, 2, 5, 0.0); - else - cpl_matrix_set(jacobian, 2, 5, (B_plus-B) / DS_x); - /* d(B)/d(p5) */ - - if (fabs(R) <= DR) { - if (S_x - S_y_plus >= - sqrt(DS_x * DS_x + DS_y * DS_y)) { - B_plus = S_y_plus; - } - else { - B_plus = S_x; - } + if (DS_x == 0.0) + cpl_matrix_set_(jacobian, 2, 5, 0.0); + else + cpl_matrix_set_(jacobian, 2, 5, (B_plus - B) / DS_x); + /* d(B)/d(p5) */ + + if (fabs(R) <= DR) { + if (S_x - S_y_plus >= -sqrt(DS_x * DS_x + DS_y * DS_y)) { + B_plus = S_y_plus; } else { - B = S_x * S_y_plus - * sqrt(2 * (1 - R * R) * cos(2 * theta) - / ((S_x * S_x + S_y_plus * S_y_plus) * cos(2 * theta) - - S_y_plus * S_y_plus + S_x * S_x)); + B_plus = S_x; } + } + else { + B = S_x * S_y_plus * + sqrt(2 * (1 - R * R) * cos(2 * theta) / + ((S_x * S_x + S_y_plus * S_y_plus) * cos(2 * theta) - + S_y_plus * S_y_plus + S_x * S_x)); + } - if (DS_y == 0.0) - cpl_matrix_set(jacobian, 2, 6, 0.0); - else - cpl_matrix_set(jacobian, 2, 6, (B_plus-B) / DS_y); - /* d(B)/d(p6) */ + if (DS_y == 0.0) + cpl_matrix_set_(jacobian, 2, 6, 0.0); + else + cpl_matrix_set_(jacobian, 2, 6, (B_plus - B) / DS_y); + /* d(B)/d(p6) */ - /* + /* * The jacobian is complete, now transpose it and * derive the covariance matrix for theta, A, and B: * C_{ph} = J * C * J' */ - *phys_cov = cpl_matrix_new(3, 3); - cpl_matrix_product_bilinear(*phys_cov, own_cov, jacobian); - cpl_matrix_delete(jacobian); - } + *phys_cov = cpl_matrix_new(3, 3); + cpl_matrix_product_bilinear(*phys_cov, own_cov, jacobian); + cpl_matrix_delete(jacobian); + } /* This closing-block bracket is the one related to the isfinite() * check, which would require -std=c99. } @@ -1982,7 +2028,6 @@ */ if (status) { - /* * The LM algorithm did not converge, or it converged to * a non-sensical result. @@ -1996,7 +2041,8 @@ if (covariance) { *covariance = own_cov; - } else { + } + else { cpl_matrix_delete(own_cov); } @@ -2024,34 +2070,39 @@ */ /*----------------------------------------------------------------------------*/ -double cpl_gaussian_eval_2d(const cpl_array * self, double x, double y) +double +cpl_gaussian_eval_2d(const cpl_array *self, double x, double y) { 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); + 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_(); - } else if (cpl_array_get_size(self) != 7) { + } + else if (cpl_array_get_size(self) != 7) { (void)cpl_error_set_(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; + } + 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_ERROR_ILLEGAL_OUTPUT, - "fabs(R=%g) > 1", R); - } else { + 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_ERROR_ILLEGAL_OUTPUT, "fabs(R=%g) > 1", + R); + } + else { (void)cpl_error_set_message_(CPL_ERROR_DIVISION_BY_ZERO, "R=%g. Sigma=(%g, %g)", R, S_x, S_y); } @@ -2078,22 +2129,22 @@ */ /*----------------------------------------------------------------------------*/ -static cpl_size cpl_fit_imagelist_polynomial_find_block_size(cpl_size np, - cpl_size nc, - cpl_boolean do_err, - cpl_type ip, - cpl_type op, - cpl_type ep) +static cpl_size +cpl_fit_imagelist_polynomial_find_block_size(cpl_size np, + cpl_size nc, + cpl_boolean do_err, + cpl_type ip, + cpl_type op, + cpl_type ep) { - cpl_size blocksize; /* The storage [bytes] needed for mv and mh */ cpl_size c0 = (nc * nc + nc * np) * (cpl_size)sizeof(double); /* Storage per pixel needed for mx, mb and the input and output images */ - cpl_size c1 = np * (cpl_size)cpl_type_get_sizeof(ip) - + nc * (cpl_size)cpl_type_get_sizeof(op) - + (nc + np) * (cpl_size)sizeof(double); + cpl_size c1 = np * (cpl_size)cpl_type_get_sizeof(ip) + + nc * (cpl_size)cpl_type_get_sizeof(op) + + (nc + np) * (cpl_size)sizeof(double); if (do_err) { /* The storage [bytes] needed for xpos and xpow */ @@ -2108,10 +2159,9 @@ Apparently, the effective size of the cache is observed to be about four times smaller */ - blocksize = ((L2_CACHE_BYTES)/4 - 10 * c0 - 1024) / c1; + blocksize = ((L2_CACHE_BYTES) / 4 - 10 * c0 - 1024) / c1; return blocksize > 0 ? blocksize : 1; - } @@ -2132,30 +2182,29 @@ */ /*----------------------------------------------------------------------------*/ -static -cpl_error_code cpl_fit_imagelist_polynomial_bpm(cpl_imagelist * self, - const cpl_mask * redo, - const cpl_vector * x_pos, - const cpl_imagelist * values, - cpl_size llx, - cpl_size lly, - cpl_size mindeg, - cpl_image * fiterror) +static cpl_error_code +cpl_fit_imagelist_polynomial_bpm(cpl_imagelist *self, + const cpl_mask *redo, + const cpl_vector *x_pos, + const cpl_imagelist *values, + cpl_size llx, + cpl_size lly, + cpl_size mindeg, + cpl_image *fiterror) { - - const cpl_image * first = cpl_imagelist_get_const(self, 0); - const cpl_size nx = cpl_image_get_size_x(first); - const cpl_size ny = cpl_image_get_size_y(first); - const cpl_size np = cpl_imagelist_get_size(values); - cpl_error_code error = CPL_ERROR_NONE; - - const cpl_binary * bpm = cpl_mask_get_data_const(redo); - const cpl_binary * found = bpm - 1; /* Prepare iteration */ - cpl_size todo = nx * ny; /* Number of pixels to search */ - cpl_polynomial * fit1d = cpl_polynomial_new(1); - double * xgood = cpl_malloc((size_t)np * sizeof(*xgood)); - double * ygood = cpl_malloc((size_t)np * sizeof(*ygood)); + const cpl_image *first = cpl_imagelist_get_const(self, 0); + const cpl_size nx = cpl_image_get_size_x(first); + const cpl_size ny = cpl_image_get_size_y(first); + const cpl_size np = cpl_imagelist_get_size(values); + cpl_error_code error = CPL_ERROR_NONE; + + const cpl_binary *bpm = cpl_mask_get_data_const(redo); + const cpl_binary *found = bpm - 1; /* Prepare iteration */ + cpl_size todo = nx * ny; /* Number of pixels to search */ + cpl_polynomial *fit1d = cpl_polynomial_new(1); + double *xgood = cpl_malloc((size_t)np * sizeof(*xgood)); + double *ygood = cpl_malloc((size_t)np * sizeof(*ygood)); while (!error && (found = memchr(found + 1, CPL_BINARY_1, (size_t)todo * sizeof(*bpm)))) { @@ -2165,9 +2214,9 @@ const cpl_size i = ij - j * nx; - error = cpl_fit_imagelist_polynomial_one(self, fit1d, xgood, ygood, - i, j, x_pos, values, llx, - lly, mindeg, fiterror); + error = cpl_fit_imagelist_polynomial_one(self, fit1d, xgood, ygood, i, + j, x_pos, values, llx, lly, + mindeg, fiterror); /* Update number of pixels to search. Can never become negative */ todo = nx * ny - ij - 1; @@ -2205,48 +2254,47 @@ */ /*----------------------------------------------------------------------------*/ -static -cpl_error_code cpl_fit_imagelist_polynomial_one(cpl_imagelist * self, - cpl_polynomial * fit1d, - double * xgood, - double * ygood, - cpl_size i, - cpl_size j, - const cpl_vector * x_pos, - const cpl_imagelist * values, - cpl_size llx, - cpl_size lly, - cpl_size mindeg, - cpl_image * fiterror) +static cpl_error_code +cpl_fit_imagelist_polynomial_one(cpl_imagelist *self, + cpl_polynomial *fit1d, + double *xgood, + double *ygood, + cpl_size i, + cpl_size j, + const cpl_vector *x_pos, + const cpl_imagelist *values, + cpl_size llx, + cpl_size lly, + cpl_size mindeg, + cpl_image *fiterror) { + const cpl_image *first = cpl_imagelist_get_const(self, 0); + const cpl_size nx = cpl_image_get_size_x(first); + const cpl_size ny = cpl_image_get_size_y(first); + const cpl_size np = cpl_imagelist_get_size(values); + const cpl_size nc = cpl_imagelist_get_size(self); + const int imindeg = (int)mindeg; + cpl_size k; + cpl_error_code error = CPL_ERROR_NONE; + cpl_size igood = 0; - const cpl_image * first = cpl_imagelist_get_const(self, 0); - const cpl_size nx = cpl_image_get_size_x(first); - const cpl_size ny = cpl_image_get_size_y(first); - const cpl_size np = cpl_imagelist_get_size(values); - const cpl_size nc = cpl_imagelist_get_size(self); - const int imindeg = (int)mindeg; - cpl_size k; - cpl_error_code error = CPL_ERROR_NONE; - cpl_size igood = 0; - - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(x_pos != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(x_pos != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(values != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(llx > 0, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(lly > 0, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(mindeg >= 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(llx > 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(lly > 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(mindeg >= 0, CPL_ERROR_ILLEGAL_INPUT); cpl_ensure_code((cpl_size)imindeg == mindeg, CPL_ERROR_ILLEGAL_INPUT); if (fiterror != NULL) { cpl_ensure_code(cpl_image_get_size_x(fiterror) == nx && - cpl_image_get_size_y(fiterror) == ny, + cpl_image_get_size_y(fiterror) == ny, CPL_ERROR_INCOMPATIBLE_INPUT); } for (k = 0; k < np; k++) { - const cpl_image * img = cpl_imagelist_get_const(values, k); + const cpl_image *img = cpl_imagelist_get_const(values, k); int is_rejected = 0; const double value = cpl_image_get(img, llx + i, lly + j, &is_rejected); @@ -2261,24 +2309,24 @@ /* No samples available for this pixel */ /* Bad pixels are set to zero. */ for (k = 0; k < nc; k++) { - cpl_image * img = cpl_imagelist_get(self, k); - cpl_image_set_ (img, 1 + i, 1 + j, 0.0); + cpl_image *img = cpl_imagelist_get(self, k); + cpl_image_set_(img, 1 + i, 1 + j, 0.0); cpl_image_reject_(img, 1 + i, 1 + j); } if (fiterror != NULL) { cpl_image_set_(fiterror, 1 + i, 1 + j, 0.0); } - - } else { - cpl_vector * vxgood = cpl_vector_wrap(igood, xgood); - cpl_vector * vygood = cpl_vector_wrap(igood, ygood); - cpl_vector * vxcopy = cpl_vector_duplicate(vxgood); + } + else { + cpl_vector *vxgood = cpl_vector_wrap(igood, xgood); + cpl_vector *vygood = cpl_vector_wrap(igood, ygood); + cpl_vector *vxcopy = cpl_vector_duplicate(vxgood); /* If there is a shortage of usable samples the number of coefficients to fit is reduced to the number of distinct sample positions */ cpl_size ndistinct; - const cpl_error_code err2 = cpl_vector_count_distinct(vxcopy, - &ndistinct); - const cpl_size ncfit = CX_MIN(nc, ndistinct); + const cpl_error_code err2 = + cpl_vector_count_distinct(vxcopy, &ndistinct); + const cpl_size ncfit = CX_MIN(nc, ndistinct); const cpl_size degree = ncfit + imindeg - 1; /* Do error estimate only if the system is overdetermined */ const cpl_boolean do_err = fiterror != NULL && (igood > nc); @@ -2286,40 +2334,42 @@ /* assert(igood < np); */ - error = err2 ? err2 : cpl_polynomial_fit_1d(fit1d, vxgood, vygood, - imindeg, degree, CPL_FALSE, - do_err ? &mse : NULL); + error = err2 ? err2 + : cpl_polynomial_fit_1d(fit1d, vxgood, vygood, NULL, + imindeg, degree, CPL_FALSE, + do_err ? &mse : NULL); cpl_vector_delete(vxcopy); (void)cpl_vector_unwrap(vxgood); (void)cpl_vector_unwrap(vygood); for (k = 0; k < ncfit; k++) { - cpl_image * img = cpl_imagelist_get(self, k); + cpl_image *img = cpl_imagelist_get(self, k); const cpl_size kk = k + mindeg; const double value = cpl_polynomial_get_coeff(fit1d, &kk); cpl_image_set_(img, 1 + i, 1 + j, cpl_image_get_type(img) == CPL_TYPE_INT - ? floor(0.5 + value) : value); + ? floor(0.5 + value) + : value); cpl_image_accept_(img, 1 + i, 1 + j); } /* Higher order terms that could not be fitted are rejected, and set to zero. The zero-value(s) means that the lower-degree polynomial is still usable */ for (; k < nc; k++) { - cpl_image * img = cpl_imagelist_get(self, k); - cpl_image_set_ (img, 1 + i, 1 + j, 0.0); + cpl_image *img = cpl_imagelist_get(self, k); + cpl_image_set_(img, 1 + i, 1 + j, 0.0); cpl_image_reject_(img, 1 + i, 1 + j); } if (fiterror != NULL) { /* In the non-bpm case, the error is set to zero for a non-overdetermined system. */ - cpl_image_set_(fiterror, 1 + i, 1 + j, + cpl_image_set_(fiterror, 1 + i, 1 + j, cpl_image_get_type(fiterror) == CPL_TYPE_INT - ? floor(0.5 + mse) : mse); + ? floor(0.5 + mse) + : mse); cpl_image_accept_(fiterror, 1 + i, 1 + j); - } } @@ -2331,9 +2381,9 @@ /* These two macros are needed for support of the different pixel types */ -#define CONCAT(a,b) a ## _ ## b -#define CONCAT2X(a,b) CONCAT(a,b) -#define CONCAT3X(a,b,c) CONCAT2X(CONCAT2X(a,b),c) +#define CONCAT(a, b) a##_##b +#define CONCAT2X(a, b) CONCAT(a, b) +#define CONCAT3X(a, b, c) CONCAT2X(CONCAT2X(a, b), c) #define CPL_TYPE double #include "cpl_fit_body.h" @@ -2344,7 +2394,7 @@ #undef CPL_TYPE #define CPL_TYPE_INT_ROUND(A) ((int)floor(0.5 + (A))) -#define CPL_TYPE int +#define CPL_TYPE int #include "cpl_fit_body.h" #undef CPL_TYPE #undef CPL_TYPE_INT_ROUND diff -Nru cpl-7.1.4+ds/cpldrs/cpl_fit.h cpl-7.2.2+ds/cpldrs/cpl_fit.h --- cpl-7.1.4+ds/cpldrs/cpl_fit.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cpldrs/cpl_fit.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -50,12 +50,12 @@ to machine precision.) */ #ifndef CPL_FIT_LVMQ_COUNT -#define CPL_FIT_LVMQ_COUNT 5 +#define CPL_FIT_LVMQ_COUNT 5 #endif /* Should be somewhat greater than 1 */ #ifndef CPL_FIT_LVMQ_MAXITER -#define CPL_FIT_LVMQ_MAXITER 1000 +#define CPL_FIT_LVMQ_MAXITER 1000 #endif /* Should be >> 1 */ @@ -63,39 +63,58 @@ Function prototypes -----------------------------------------------------------------------------*/ -cpl_error_code cpl_fit_lvmq(const cpl_matrix*, const cpl_matrix*, - const cpl_vector*, const cpl_vector*, - cpl_vector*, const int[], - int (*)(const double[], - const double[], double*), - int (*)(const double[], - const double[], double[]), - double, int, int, double*, double*, cpl_matrix**); - - -cpl_imagelist* cpl_fit_imagelist_polynomial(const cpl_vector*, - const cpl_imagelist*, - cpl_size, cpl_size, cpl_boolean, - cpl_type, cpl_image*) - CPL_ATTR_ALLOC; - -cpl_imagelist* cpl_fit_imagelist_polynomial_window(const cpl_vector*, - const cpl_imagelist*, - cpl_size, cpl_size, - cpl_size, cpl_size, - cpl_size, cpl_size, +cpl_error_code cpl_fit_lvmq(const cpl_matrix *, + const cpl_matrix *, + const cpl_vector *, + const cpl_vector *, + cpl_vector *, + const int[], + int (*)(const double[], const double[], double *), + int (*)(const double[], const double[], double[]), + double, + int, + int, + double *, + double *, + cpl_matrix **); + + +cpl_imagelist *cpl_fit_imagelist_polynomial(const cpl_vector *, + const cpl_imagelist *, + cpl_size, + cpl_size, + cpl_boolean, + cpl_type, + cpl_image *) CPL_ATTR_ALLOC; + +cpl_imagelist *cpl_fit_imagelist_polynomial_window(const cpl_vector *, + const cpl_imagelist *, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_size, cpl_boolean, - cpl_type, cpl_image*) - CPL_ATTR_ALLOC; + cpl_type, + cpl_image *) CPL_ATTR_ALLOC; -cpl_error_code cpl_fit_image_gaussian(const cpl_image*, const cpl_image*, - cpl_size, cpl_size, - cpl_size, cpl_size, - cpl_array*, cpl_array*, - const cpl_array*, double*, - double*, cpl_matrix**, - double*, double*, - double*, cpl_matrix**); +cpl_error_code cpl_fit_image_gaussian(const cpl_image *, + const cpl_image *, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_array *, + cpl_array *, + const cpl_array *, + double *, + double *, + cpl_matrix **, + double *, + double *, + double *, + cpl_matrix **); double cpl_gaussian_eval_2d(const cpl_array *, double, double); diff -Nru cpl-7.1.4+ds/cpldrs/cpl_geom_img_body.h cpl-7.2.2+ds/cpldrs/cpl_geom_img_body.h --- cpl-7.1.4+ds/cpldrs/cpl_geom_img_body.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cpldrs/cpl_geom_img_body.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -17,7 +17,7 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#define CPL_TYPE_ADD(a) CPL_CONCAT2X(a, CPL_TYPE) +#define CPL_TYPE_ADD(a) CPL_CONCAT2X(a, CPL_TYPE) #define CPL_TYPE_ADD_CONST(a) CPL_CONCAT3X(a, CPL_TYPE, const) /*----------------------------------------------------------------------------*/ @@ -43,36 +43,35 @@ */ /*----------------------------------------------------------------------------*/ -static -void CPL_TYPE_ADD(cpl_geom_ima_offset_xcorr_subw)(double * correl, - const cpl_image * im1, - const cpl_image * im2, - cpl_size x_1, - cpl_size y_1, - cpl_size x_2, - cpl_size y_2, - cpl_size s_hx, - cpl_size s_hy, - cpl_size m_hx, - cpl_size m_hy, - cpl_size * pk_min, - cpl_size * pl_min) +static void CPL_TYPE_ADD(cpl_geom_ima_offset_xcorr_subw)(double *correl, + const cpl_image *im1, + const cpl_image *im2, + cpl_size x_1, + cpl_size y_1, + cpl_size x_2, + cpl_size y_2, + cpl_size s_hx, + cpl_size s_hy, + cpl_size m_hx, + cpl_size m_hy, + cpl_size *pk_min, + cpl_size *pl_min) { - double sqsum_min = DBL_MAX; - const cpl_size nx = cpl_image_get_size_x(im1); - const cpl_size ny = cpl_image_get_size_y(im1); + double sqsum_min = DBL_MAX; + const cpl_size nx = cpl_image_get_size_x(im1); + const cpl_size ny = cpl_image_get_size_y(im1); /* Point to the center corellation position */ - const CPL_TYPE * pi1 = CPL_TYPE_ADD_CONST(cpl_image_get_data)(im1) - + x_1 + y_1 * nx; - const CPL_TYPE * pi2 = CPL_TYPE_ADD_CONST(cpl_image_get_data)(im2) - + x_2 + y_2 * nx; - double * pxc = correl + s_hx; /* Offset for indexing with k */ - const cpl_size s_hx_min = -CX_MIN(s_hx, CX_MIN(x_1, x_2)); - const cpl_size s_hy_min = -CX_MIN(s_hy, CX_MIN(y_1, y_2)); - const cpl_size s_hx_max = CX_MIN(s_hx, nx-1-CX_MAX(x_1, x_2)); - const cpl_size s_hy_max = CX_MIN(s_hy, ny-1-CX_MAX(y_1, y_2)); - cpl_size k, l; + const CPL_TYPE *pi1 = + CPL_TYPE_ADD_CONST(cpl_image_get_data)(im1) + x_1 + y_1 * nx; + const CPL_TYPE *pi2 = + CPL_TYPE_ADD_CONST(cpl_image_get_data)(im2) + x_2 + y_2 * nx; + double *pxc = correl + s_hx; /* Offset for indexing with k */ + const cpl_size s_hx_min = -CX_MIN(s_hx, CX_MIN(x_1, x_2)); + const cpl_size s_hy_min = -CX_MIN(s_hy, CX_MIN(y_1, y_2)); + const cpl_size s_hx_max = CX_MIN(s_hx, nx - 1 - CX_MAX(x_1, x_2)); + const cpl_size s_hy_max = CX_MIN(s_hy, ny - 1 - CX_MAX(y_1, y_2)); + cpl_size k, l; /* Outside the image(s) */ @@ -91,24 +90,28 @@ for (; k <= s_hx_max; k++) { const cpl_size m_hx_min = -CX_MIN(m_hx, CX_MIN(x_1 + k, x_2)); const cpl_size m_hy_min = -CX_MIN(m_hy, CX_MIN(y_1 + l, y_2)); - const cpl_size m_hx_max = CX_MIN(m_hx, nx-1-CX_MAX(x_1 + k, x_2)); - const cpl_size m_hy_max = CX_MIN(m_hy, ny-1-CX_MAX(y_1 + l, y_2)); - const cpl_size npix = (1+m_hx_max-m_hx_min) * (1+m_hy_max-m_hy_min); + const cpl_size m_hx_max = + CX_MIN(m_hx, nx - 1 - CX_MAX(x_1 + k, x_2)); + const cpl_size m_hy_max = + CX_MIN(m_hy, ny - 1 - CX_MAX(y_1 + l, y_2)); + const cpl_size npix = + (1 + m_hx_max - m_hx_min) * (1 + m_hy_max - m_hy_min); if (npix < m_hx + m_hy) { /* FIXME: Arbitrary lower limit on sampled pixels */ pxc[k] = -1.0; - } else { - double sqsum = 0.0; - const double rnpix = 1.0 / (double)npix; - const CPL_TYPE * pos1 = pi1 + k + (l + m_hy_min) * nx; - const CPL_TYPE * pos2 = pi2 + ( m_hy_min) * nx; - cpl_size i, j; + } + else { + double sqsum = 0.0; + const double rnpix = 1.0 / (double)npix; + const CPL_TYPE *pos1 = pi1 + k + (l + m_hy_min) * nx; + const CPL_TYPE *pos2 = pi2 + (m_hy_min)*nx; + cpl_size i, j; /* One sum of squared differences */ for (j = m_hy_min; j <= m_hy_max; j++, pos1 += nx, pos2 += nx) { for (i = m_hx_min; i <= m_hx_max; i++) { - const double diff = (double)pos1[i]-(double)pos2[i]; + const double diff = (double)pos1[i] - (double)pos2[i]; sqsum += diff * diff; } } @@ -162,158 +165,148 @@ */ /*----------------------------------------------------------------------------*/ -static void CPL_TYPE_ADD(cpl_geom_img_offset_saa)(cpl_image * final, - cpl_image * contrib, - cpl_size rmin, cpl_size rmax, +static void CPL_TYPE_ADD(cpl_geom_img_offset_saa)(cpl_image *final, + cpl_image *contrib, + cpl_size rmin, + cpl_size rmax, double start_x, double start_y, - const cpl_imagelist * ilist, + const cpl_imagelist *ilist, cpl_size firstbpm, - const cpl_bivector * offs, - const cpl_vector * xyprofile, + const cpl_bivector *offs, + const cpl_vector *xyprofile, cpl_size tabsperpix) { + const cpl_size nima = cpl_imagelist_get_size(ilist); + const cpl_image *img1 = cpl_imagelist_get_const(ilist, 0); + const cpl_size sizex = cpl_image_get_size_x(img1); + const cpl_size sizey = cpl_image_get_size_y(img1); + const cpl_size nx = cpl_image_get_size_x(final); + const cpl_size ny = cpl_image_get_size_y(final); + const cpl_size rtot = rmin + rmax; + CPL_TYPE *po = CPL_TYPE_ADD(cpl_image_get_data)(final); + const double *offs_x = cpl_bivector_get_x_data_const(offs); + const double *offs_y = cpl_bivector_get_y_data_const(offs); + double *acc = + (double *)cpl_malloc((size_t)nx * (size_t)nima * sizeof(*acc)); + int *pcontrib = cpl_image_get_data_int(contrib); + const CPL_TYPE **ppi = cpl_malloc((size_t)nima * sizeof(CPL_TYPE *)); + const cpl_binary **ppibpm = NULL; + int *ncontrib = (int *)cpl_calloc(sizeof(int), (size_t)nx); + cpl_size *offset_ij = cpl_malloc(2 * (size_t)nima * sizeof(*offset_ij)); + double *rsc = (double *)cpl_malloc((size_t)nima * 8 * sizeof(*rsc)); + cpl_boolean *isint = + (cpl_boolean *)cpl_calloc((size_t)nima, sizeof(*isint)); + cpl_size j, p; + cpl_flops myflop_count = 0; - const cpl_size nima = cpl_imagelist_get_size(ilist); - const cpl_image * img1 = cpl_imagelist_get_const(ilist, 0); - const cpl_size sizex = cpl_image_get_size_x(img1); - const cpl_size sizey = cpl_image_get_size_y(img1); - const cpl_size nx = cpl_image_get_size_x(final); - const cpl_size ny = cpl_image_get_size_y(final); - const cpl_size rtot = rmin + rmax; - CPL_TYPE * po = CPL_TYPE_ADD(cpl_image_get_data)(final); - const double * offs_x = cpl_bivector_get_x_data_const(offs); - const double * offs_y = cpl_bivector_get_y_data_const(offs); - double * acc = (double*)cpl_malloc((size_t)nx * (size_t)nima - * sizeof(*acc)); - int * pcontrib = cpl_image_get_data_int(contrib); - const CPL_TYPE ** ppi = cpl_malloc((size_t)nima * sizeof(CPL_TYPE*)); - const cpl_binary ** ppibpm = NULL; - int * ncontrib = (int*)cpl_calloc(sizeof(int), (size_t)nx); - cpl_size * offset_ij = cpl_malloc(2 * (size_t)nima - * sizeof(*offset_ij)); - double * rsc = (double*)cpl_malloc((size_t)nima * 8 - * sizeof(*rsc)); - cpl_boolean * isint = (cpl_boolean*)cpl_calloc((size_t)nima, - sizeof(*isint)); - cpl_size j, p; - cpl_flops myflop_count = 0; - - for (p=0; p < nima; p++) { - - const double offset_x = start_x - offs_x[p]; - const double offset_y = start_y - offs_y[p]; - const double suboff_x = offset_x - floor(offset_x); - const double suboff_y = offset_y - floor(offset_y); + for (p = 0; p < nima; p++) { + const double offset_x = start_x - offs_x[p]; + const double offset_y = start_y - offs_y[p]; + const double suboff_x = offset_x - floor(offset_x); + const double suboff_y = offset_y - floor(offset_y); /* Which tabulated value index shall be used? */ - const cpl_size tabx = (int)(0.5 + suboff_x * (double)(tabsperpix)); - const cpl_size taby = (int)(0.5 + suboff_y * (double)(tabsperpix)); + const cpl_size tabx = (int)(0.5 + suboff_x * (double)(tabsperpix)); + const cpl_size taby = (int)(0.5 + suboff_y * (double)(tabsperpix)); offset_ij[0 + p * 2] = (cpl_size)floor(offset_x); offset_ij[1 + p * 2] = (cpl_size)floor(offset_y); - ppi[p] = CPL_TYPE_ADD_CONST(cpl_image_get_data) - (cpl_imagelist_get_const(ilist, p)); + ppi[p] = CPL_TYPE_ADD_CONST(cpl_image_get_data)( + cpl_imagelist_get_const(ilist, p)); ppi[p] += offset_ij[0 + p * 2]; if (tabx == 0 && taby == 0) { isint[p] = CPL_TRUE; - } else { - - const double * interp_kernel - = cpl_vector_get_data_const(xyprofile); + } + else { + const double *interp_kernel = cpl_vector_get_data_const(xyprofile); - const double sumrs - = ( interp_kernel[ tabsperpix + tabx] - + interp_kernel[ tabx] - + interp_kernel[ tabsperpix - tabx] - + interp_kernel[2 * tabsperpix - tabx]) - * ( interp_kernel[ tabsperpix + taby] - + interp_kernel[ taby] - + interp_kernel[ tabsperpix - taby] - + interp_kernel[2 * tabsperpix - taby]); + const double sumrs = + (interp_kernel[tabsperpix + tabx] + interp_kernel[tabx] + + interp_kernel[tabsperpix - tabx] + + interp_kernel[2 * tabsperpix - tabx]) * + (interp_kernel[tabsperpix + taby] + interp_kernel[taby] + + interp_kernel[tabsperpix - taby] + + interp_kernel[2 * tabsperpix - taby]); /* Compute resampling coefficients */ /* rsc[0..3] in x, rsc[4..7] in y */ /* Also divide the y-rsc with the sum of the rsc */ - rsc[0 + p * 8] = interp_kernel[ tabsperpix + tabx]; - rsc[1 + p * 8] = interp_kernel[ tabx]; - rsc[2 + p * 8] = interp_kernel[ tabsperpix - tabx]; + rsc[0 + p * 8] = interp_kernel[tabsperpix + tabx]; + rsc[1 + p * 8] = interp_kernel[tabx]; + rsc[2 + p * 8] = interp_kernel[tabsperpix - tabx]; rsc[3 + p * 8] = interp_kernel[2 * tabsperpix - tabx]; - rsc[4 + p * 8] = interp_kernel[ tabsperpix + taby] / sumrs; - rsc[5 + p * 8] = interp_kernel[ taby] / sumrs; - rsc[6 + p * 8] = interp_kernel[ tabsperpix - taby] / sumrs; + rsc[4 + p * 8] = interp_kernel[tabsperpix + taby] / sumrs; + rsc[5 + p * 8] = interp_kernel[taby] / sumrs; + rsc[6 + p * 8] = interp_kernel[tabsperpix - taby] / sumrs; rsc[7 + p * 8] = interp_kernel[2 * tabsperpix - taby] / sumrs; - } } /* Get the masks if there are bad pixels */ if (firstbpm < nima) { - ppibpm = (const cpl_binary **)cpl_malloc((size_t)nima - * sizeof(cpl_binary*)); + ppibpm = (const cpl_binary **)cpl_malloc((size_t)nima * + sizeof(cpl_binary *)); for (p = 0; p < firstbpm; p++) { ppibpm[p] = NULL; } for (; p < nima; p++) { - const cpl_mask * bpm - = cpl_image_get_bpm_const(cpl_imagelist_get_const(ilist, p)); + const cpl_mask *bpm = + cpl_image_get_bpm_const(cpl_imagelist_get_const(ilist, p)); if (p == firstbpm || (bpm != NULL && !cpl_mask_is_empty(bpm))) { ppibpm[p] = cpl_mask_get_data_const(bpm); ppibpm[p] += offset_ij[0 + p * 2]; - } else { + } + else { ppibpm[p] = NULL; } } } /* Triple loop */ - for (j=0; j < ny; j++) { + for (j = 0; j < ny; j++) { cpl_flops myintp_count = 0; - cpl_size i; - - for (p=0; p < nima; p++) { + cpl_size i; + for (p = 0; p < nima; p++) { const cpl_size py = j + offset_ij[1 + p * 2]; /* If original pixel is present in the current plane */ - if (py > 1 && py < (sizey-2)) { + if (py > 1 && py < (sizey - 2)) { + const CPL_TYPE *pi = ppi[p] + py * sizex; + const cpl_binary *pibpm = NULL; - const CPL_TYPE * pi = ppi[p] + py * sizex; - const cpl_binary * pibpm = NULL; - /* First offset source location used */ const cpl_size i0 = CX_MAX(0, 2 - offset_ij[0 + p * 2]); /* First offset source location not used */ - const cpl_size i1 = CX_MIN(sizex - 2 - offset_ij[0 + p * 2], - nx); + const cpl_size i1 = + CX_MIN(sizex - 2 - offset_ij[0 + p * 2], nx); - if(ppibpm != NULL && ppibpm[p] != NULL) + if (ppibpm != NULL && ppibpm[p] != NULL) pibpm = ppibpm[p] + py * sizex; if (isint[p]) { /* The shift is purely integer, so no interpolation done */ /* When the whole list has integer shifts, the speed-up is a factor between 3 and 4 on the unit tests */ - + for (i = i0; i < i1; i++) { - /* assert( px == i + offset_ij[0 + p * 2] ); */ /* Check if the pixel used * is a bad pixel. If true, this image is not used * for this pixel */ if (pibpm == NULL || !pibpm[i]) { - /* Collect pixel and update number of contributing pixels */ /* acc[] is accessed with stride nima here, in order @@ -322,10 +315,9 @@ ncontrib[i]++; } } - } else { - + } + else { for (i = i0; i < i1; i++) { - /* assert( px == i + offset_ij[0 + p * 2] ); */ /* Check if any of the pixels used for the interpolation @@ -333,39 +325,38 @@ * for this pixel */ /* An earlier check required the pixel to be bad and the resampling coefficient to be non-zero. - This was dropped to support bad pixels w. NaNs */ - if(pibpm == NULL || - /* One read for all 4 pixels in the bpm row */ - (!*((const uint32_t*)(pibpm + i - 1 - sizex )) && - !*((const uint32_t*)(pibpm + i - 1 )) && - !*((const uint32_t*)(pibpm + i - 1 + sizex )) && - !*((const uint32_t*)(pibpm + i - 1 + sizex * 2)))) { - + This was dropped to support bad pixels w. NaNs */ + if (pibpm == NULL || + /* One read for all 4 pixels in the bpm row */ + (!*((const uint32_t *)(pibpm + i - 1 - sizex)) && + !*((const uint32_t *)(pibpm + i - 1)) && + !*((const uint32_t *)(pibpm + i - 1 + sizex)) && + !*((const uint32_t *)(pibpm + i - 1 + + sizex * 2)))) { /* Compute interpolated pixel and update number of contributing pixels */ /* acc[] is accessed with stride nima here, in order to achieve stride one access below */ - acc[ncontrib[i] + i * nima] - = rsc[4 + 8*p] * - (rsc[0 + 8*p] * pi[i - 1 - sizex] + - rsc[1 + 8*p] * pi[i - sizex] + - rsc[2 + 8*p] * pi[i + 1 - sizex] + - rsc[3 + 8*p] * pi[i + 2 - sizex] ) - + rsc[5 + 8*p] * - (rsc[0 + 8*p] * pi[i - 1] + - rsc[1 + 8*p] * pi[i ] + - rsc[2 + 8*p] * pi[i + 1] + - rsc[3 + 8*p] * pi[i + 2] ) - + rsc[6 + 8*p] * - (rsc[0 + 8*p] * pi[i - 1 + sizex] + - rsc[1 + 8*p] * pi[i + sizex] + - rsc[2 + 8*p] * pi[i + 1 + sizex] + - rsc[3 + 8*p] * pi[i + 2 + sizex] ) - + rsc[7 + 8*p] * - (rsc[0 + 8*p] * pi[i - 1 + sizex * 2] + - rsc[1 + 8*p] * pi[i + sizex * 2] + - rsc[2 + 8*p] * pi[i + 1 + sizex * 2] + - rsc[3 + 8*p] * pi[i + 2 + sizex * 2]); + acc[ncontrib[i] + i * nima] = + rsc[4 + 8 * p] * + (rsc[0 + 8 * p] * pi[i - 1 - sizex] + + rsc[1 + 8 * p] * pi[i - sizex] + + rsc[2 + 8 * p] * pi[i + 1 - sizex] + + rsc[3 + 8 * p] * pi[i + 2 - sizex]) + + rsc[5 + 8 * p] * (rsc[0 + 8 * p] * pi[i - 1] + + rsc[1 + 8 * p] * pi[i] + + rsc[2 + 8 * p] * pi[i + 1] + + rsc[3 + 8 * p] * pi[i + 2]) + + rsc[6 + 8 * p] * + (rsc[0 + 8 * p] * pi[i - 1 + sizex] + + rsc[1 + 8 * p] * pi[i + sizex] + + rsc[2 + 8 * p] * pi[i + 1 + sizex] + + rsc[3 + 8 * p] * pi[i + 2 + sizex]) + + rsc[7 + 8 * p] * + (rsc[0 + 8 * p] * pi[i - 1 + sizex * 2] + + rsc[1 + 8 * p] * pi[i + sizex * 2] + + rsc[2 + 8 * p] * pi[i + 1 + sizex * 2] + + rsc[3 + 8 * p] * pi[i + 2 + sizex * 2]); ncontrib[i]++; myintp_count++; @@ -374,34 +365,34 @@ } } } - for (i=0; i < nx; i++) { + for (i = 0; i < nx; i++) { if (ncontrib[i] > rtot) { double finpix = 0.0; - double * acci = acc + i * nima; + double *acci = acc + i * nima; /* Place rmin and rmax samples at the ends */ #ifdef CPL_GEOM_USE_KTH /* Equivalent, but slower in unit tests */ if (rmin > 0) - (void)cpl_tools_get_kth_double(acci, ncontrib[i], rmin-1); + (void)cpl_tools_get_kth_double(acci, ncontrib[i], rmin - 1); if (rmax > 0) (void)cpl_tools_get_kth_double(acci + rmin, ncontrib[i] - rmin, ncontrib[i] - rtot); #else - cpl_geom_img_get_min_max_double(acci, ncontrib[i], - rmin, rmax); + cpl_geom_img_get_min_max_double(acci, ncontrib[i], rmin, rmax); #endif - for (p=rmin; p<(ncontrib[i]-rmax); p++) + for (p = rmin; p < (ncontrib[i] - rmax); p++) finpix += acci[p]; - finpix /= (double)(ncontrib[i]-rtot); + finpix /= (double)(ncontrib[i] - rtot); - po[i+j*nx] = (CPL_TYPE)finpix; - pcontrib[i+j*nx] = ncontrib[i] - rtot; + po[i + j * nx] = (CPL_TYPE)finpix; + pcontrib[i + j * nx] = ncontrib[i] - rtot; myflop_count += 1 + ncontrib[i] - rtot; - } else { - cpl_image_reject(final, i+1, j+1); + } + else { + cpl_image_reject(final, i + 1, j + 1); } ncontrib[i] = 0; } @@ -413,9 +404,9 @@ cpl_free(rsc); cpl_free(acc); cpl_free(ncontrib); - cpl_free((void*)ppi); - cpl_free((void*)ppibpm); - cpl_free((void*)isint); + cpl_free((void *)ppi); + cpl_free((void *)ppibpm); + cpl_free((void *)isint); return; } @@ -437,61 +428,60 @@ */ /*----------------------------------------------------------------------------*/ -static -void CPL_TYPE_ADD(cpl_geom_img_offset_saa_all)(cpl_image * final, - cpl_image * contrib, - double start_x, - double start_y, - const cpl_imagelist * ilist, - const cpl_bivector * offs, - const cpl_vector * xyprofile, - cpl_size tabsperpix) +static void + CPL_TYPE_ADD(cpl_geom_img_offset_saa_all)(cpl_image *final, + cpl_image *contrib, + double start_x, + double start_y, + const cpl_imagelist *ilist, + const cpl_bivector *offs, + const cpl_vector *xyprofile, + cpl_size tabsperpix) { - - const cpl_size nima = cpl_imagelist_get_size(ilist); - const cpl_image * img1 = cpl_imagelist_get_const(ilist, 0); - const cpl_size sizex = cpl_image_get_size_x(img1); - const cpl_size sizey = cpl_image_get_size_y(img1); - const cpl_size nx = cpl_image_get_size_x(final); - const cpl_size ny = cpl_image_get_size_y(final); - - CPL_TYPE * po = CPL_TYPE_ADD(cpl_image_get_data)(final); - const double * offs_x = cpl_bivector_get_x_data_const(offs); - const double * offs_y = cpl_bivector_get_y_data_const(offs); - const double * interp_kernel = cpl_vector_get_data_const(xyprofile); + const cpl_size nima = cpl_imagelist_get_size(ilist); + const cpl_image *img1 = cpl_imagelist_get_const(ilist, 0); + const cpl_size sizex = cpl_image_get_size_x(img1); + const cpl_size sizey = cpl_image_get_size_y(img1); + const cpl_size nx = cpl_image_get_size_x(final); + const cpl_size ny = cpl_image_get_size_y(final); + + CPL_TYPE *po = CPL_TYPE_ADD(cpl_image_get_data)(final); + const double *offs_x = cpl_bivector_get_x_data_const(offs); + const double *offs_y = cpl_bivector_get_y_data_const(offs); + const double *interp_kernel = cpl_vector_get_data_const(xyprofile); /* The contribution map. */ - int * pcontrib = cpl_image_get_data_int(contrib); + int *pcontrib = cpl_image_get_data_int(contrib); /* A more compact contribution map yields a small performance gain */ - unsigned char * pcb = cpl_calloc(1, nx * ny); - const unsigned char * pbjr = pcb; /* Pointer for j'th row of pcb */ - /* The resampling coefficients, 4 in X and 4 in Y. + unsigned char *pcb = cpl_calloc(1, nx * ny); + const unsigned char *pbjr = pcb; /* Pointer for j'th row of pcb */ + /* The resampling coefficients, 4 in X and 4 in Y. No speed-up by declaring as CPL_TYPE. No speed-up by forming the 16 products (saves four multiplications, but introduces eight reads). */ - double rsc[8]; - cpl_flops myintp_count = 0; - cpl_flops myaddp_count = 0; - cpl_flops myflop_count = nx * ny + 4 * nima; - cpl_size i, j, p; + double rsc[8]; + cpl_flops myintp_count = 0; + cpl_flops myaddp_count = 0; + cpl_flops myflop_count = nx * ny + 4 * nima; + cpl_size i, j, p; /* Triple loop */ for (p = 0; p < nima; p++) { - const cpl_image * imgp = cpl_imagelist_get_const(ilist, p); - const CPL_TYPE * pij = CPL_TYPE_ADD_CONST(cpl_image_get_data)(imgp); - const double offset_x = start_x - offs_x[p]; - const double offset_y = start_y - offs_y[p]; - const double suboff_x = offset_x - floor(offset_x); - const double suboff_y = offset_y - floor(offset_y); - const cpl_size offset_i = (int)floor(offset_x); - const cpl_size offset_j = (int)floor(offset_y); + const cpl_image *imgp = cpl_imagelist_get_const(ilist, p); + const CPL_TYPE *pij = CPL_TYPE_ADD_CONST(cpl_image_get_data)(imgp); + const double offset_x = start_x - offs_x[p]; + const double offset_y = start_y - offs_y[p]; + const double suboff_x = offset_x - floor(offset_x); + const double suboff_y = offset_y - floor(offset_y); + const cpl_size offset_i = (int)floor(offset_x); + const cpl_size offset_j = (int)floor(offset_y); /* Which tabulated value index shall be used? */ - const cpl_size tabx = (int)(0.5 + suboff_x * (double)(tabsperpix)); - const cpl_size taby = (int)(0.5 + suboff_y * (double)(tabsperpix)); + const cpl_size tabx = (int)(0.5 + suboff_x * (double)(tabsperpix)); + const cpl_size taby = (int)(0.5 + suboff_y * (double)(tabsperpix)); - CPL_TYPE * poj = po; - int * pcj = pcontrib; - unsigned char * pbj = pcb; /* Pointer for j'th row of pcb */ + CPL_TYPE *poj = po; + int *pcj = pcontrib; + unsigned char *pbj = pcb; /* Pointer for j'th row of pcb */ if (tabx == 0 && taby == 0) { /* No sub-pixel shift, add input image */ @@ -514,27 +504,24 @@ pij += py0 * sizex; myaddp_count += (py1 - py0) * (px1 - px0); - for (py = py0; py < py1; py++, poj += nx, pcj += nx, pbj += nx, - pij += sizex) { - + for (py = py0; py < py1; + py++, poj += nx, pcj += nx, pbj += nx, pij += sizex) { for (px = px0; px < px1; px++) { - poj[px] += pij[px]; - if (++pbj[px] == 0) pcj[px] += 256; + if (++pbj[px] == 0) + pcj[px] += 256; } } - } else { - - const double sumrs - = ( interp_kernel[ tabsperpix + tabx] - + interp_kernel[ tabx] - + interp_kernel[ tabsperpix - tabx] - + interp_kernel[2 * tabsperpix - tabx]) - * ( interp_kernel[ tabsperpix + taby] - + interp_kernel[ taby] - + interp_kernel[ tabsperpix - taby] - + interp_kernel[2 * tabsperpix - taby]); + } + else { + const double sumrs = + (interp_kernel[tabsperpix + tabx] + interp_kernel[tabx] + + interp_kernel[tabsperpix - tabx] + + interp_kernel[2 * tabsperpix - tabx]) * + (interp_kernel[tabsperpix + taby] + interp_kernel[taby] + + interp_kernel[tabsperpix - taby] + + interp_kernel[2 * tabsperpix - taby]); /* Interpolate values from any source pixel at least 2 pixels away from the source boundary */ @@ -556,13 +543,13 @@ /* rsc[0..3] in x, rsc[4..7] in y */ /* Also divide the y-rsc with the sum of the rsc */ - rsc[0] = interp_kernel[ tabsperpix + tabx]; - rsc[1] = interp_kernel[ tabx]; - rsc[2] = interp_kernel[ tabsperpix - tabx]; + rsc[0] = interp_kernel[tabsperpix + tabx]; + rsc[1] = interp_kernel[tabx]; + rsc[2] = interp_kernel[tabsperpix - tabx]; rsc[3] = interp_kernel[2 * tabsperpix - tabx]; - rsc[4] = interp_kernel[ tabsperpix + taby] / sumrs; - rsc[5] = interp_kernel[ taby] / sumrs; - rsc[6] = interp_kernel[ tabsperpix - taby] / sumrs; + rsc[4] = interp_kernel[tabsperpix + taby] / sumrs; + rsc[5] = interp_kernel[taby] / sumrs; + rsc[6] = interp_kernel[tabsperpix - taby] / sumrs; rsc[7] = interp_kernel[2 * tabsperpix - taby] / sumrs; /* Interpolate from input image */ @@ -573,30 +560,28 @@ pbj += (py0 - offset_j) * nx - offset_i; pij += py0 * sizex; - for (py = py0; py < py1; py++, poj += nx, pcj += nx, pbj += nx, pij += sizex) { - + for (py = py0; py < py1; + py++, poj += nx, pcj += nx, pbj += nx, pij += sizex) { for (px = px0; px < px1; px++) { - /* Compute interpolated pixel now */ - poj[px] += - rsc[4] * ( rsc[0] * pij[px - 1 - sizex] + - rsc[1] * pij[px - sizex] + - rsc[2] * pij[px + 1 - sizex] + - rsc[3] * pij[px + 2 - sizex] ) + - rsc[5] * ( rsc[0] * pij[px - 1] + - rsc[1] * pij[px ] + - rsc[2] * pij[px + 1] + - rsc[3] * pij[px + 2] ) + - rsc[6] * ( rsc[0] * pij[px - 1 + sizex] + - rsc[1] * pij[px + sizex] + - rsc[2] * pij[px + 1 + sizex] + - rsc[3] * pij[px + 2 + sizex] ) + - rsc[7] * ( rsc[0] * pij[px - 1 + sizex * 2] + - rsc[1] * pij[px + sizex * 2] + - rsc[2] * pij[px + 1 + sizex * 2] + - rsc[3] * pij[px + 2 + sizex * 2] ); + poj[px] += + rsc[4] * (rsc[0] * pij[px - 1 - sizex] + + rsc[1] * pij[px - sizex] + + rsc[2] * pij[px + 1 - sizex] + + rsc[3] * pij[px + 2 - sizex]) + + rsc[5] * (rsc[0] * pij[px - 1] + rsc[1] * pij[px] + + rsc[2] * pij[px + 1] + rsc[3] * pij[px + 2]) + + rsc[6] * (rsc[0] * pij[px - 1 + sizex] + + rsc[1] * pij[px + sizex] + + rsc[2] * pij[px + 1 + sizex] + + rsc[3] * pij[px + 2 + sizex]) + + rsc[7] * (rsc[0] * pij[px - 1 + sizex * 2] + + rsc[1] * pij[px + sizex * 2] + + rsc[2] * pij[px + 1 + sizex * 2] + + rsc[3] * pij[px + 2 + sizex * 2]); - if (++pbj[px] == 0) pcj[px] += 256; + if (++pbj[px] == 0) + pcj[px] += 256; } } } @@ -607,8 +592,9 @@ pcontrib[i] += (int)pbjr[i]; if (pcontrib[i] > 0) { po[i] /= (CPL_TYPE)pcontrib[i]; - } else { - cpl_image_reject(final, i+1, j+1); + } + else { + cpl_image_reject(final, i + 1, j + 1); myflop_count--; } } diff -Nru cpl-7.1.4+ds/cpldrs/cpl_geom_img.c cpl-7.2.2+ds/cpldrs/cpl_geom_img.c --- cpl-7.1.4+ds/cpldrs/cpl_geom_img.c 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cpldrs/cpl_geom_img.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -68,68 +68,104 @@ #define inline /* inline */ #endif -#define CPL_SORT(a, i, j, tmp) do { \ - if (a[i] < a[j]) { tmp = a[i]; a[i] = a[j]; a[j] = tmp; }} while (0) +#define CPL_SORT(a, i, j, tmp) \ + do { \ + if (a[i] < a[j]) { \ + tmp = a[i]; \ + a[i] = a[j]; \ + a[j] = tmp; \ + } \ + } while (0) /*----------------------------------------------------------------------------- Static Function Prototypes -----------------------------------------------------------------------------*/ -static void cpl_geom_img_get_min_max_double(double *, cpl_size, cpl_size, +static void cpl_geom_img_get_min_max_double(double *, + cpl_size, + cpl_size, cpl_size) CPL_ATTR_NONNULL; -static double cpl_geom_ima_offset_xcorr(const cpl_image *, const cpl_image *, +static double cpl_geom_ima_offset_xcorr(const cpl_image *, + const cpl_image *, const cpl_bivector *, - cpl_size, cpl_size, cpl_size, cpl_size, - double *, double *) CPL_ATTR_NONNULL; + cpl_size, + cpl_size, + cpl_size, + cpl_size, + double *, + double *) CPL_ATTR_NONNULL; -static double cpl_geom_ima_offset_xcorr_subw(double *, const cpl_image *, +static double cpl_geom_ima_offset_xcorr_subw(double *, const cpl_image *, - cpl_size, cpl_size, - cpl_size, cpl_size, - cpl_size, cpl_size, - cpl_size, cpl_size, double *, + const cpl_image *, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + double *, double *) CPL_ATTR_NONNULL; -static -void cpl_geom_ima_offset_xcorr_subw_double(double *, - const cpl_image *, - const cpl_image *, - cpl_size, cpl_size, - cpl_size, cpl_size, - cpl_size, cpl_size, - cpl_size, cpl_size, - cpl_size *, cpl_size *) - CPL_ATTR_NONNULL; - -static -void cpl_geom_ima_offset_xcorr_subw_float(double *, - const cpl_image *, - const cpl_image *, - cpl_size, cpl_size, - cpl_size, cpl_size, - cpl_size, cpl_size, - cpl_size, cpl_size, - cpl_size *, cpl_size *) - CPL_ATTR_NONNULL; - -static void cpl_geom_img_offset_saa_double(cpl_image *, cpl_image *, - cpl_size, cpl_size, double, double, - const cpl_imagelist *, cpl_size, +static void cpl_geom_ima_offset_xcorr_subw_double(double *, + const cpl_image *, + const cpl_image *, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_size *, + cpl_size *) CPL_ATTR_NONNULL; + +static void cpl_geom_ima_offset_xcorr_subw_float(double *, + const cpl_image *, + const cpl_image *, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_size *, + cpl_size *) CPL_ATTR_NONNULL; + +static void cpl_geom_img_offset_saa_double(cpl_image *, + cpl_image *, + cpl_size, + cpl_size, + double, + double, + const cpl_imagelist *, + cpl_size, const cpl_bivector *, const cpl_vector *, cpl_size) CPL_ATTR_NONNULL; -static void cpl_geom_img_offset_saa_float(cpl_image *, cpl_image *, - cpl_size, cpl_size, double, double, - const cpl_imagelist *, cpl_size, +static void cpl_geom_img_offset_saa_float(cpl_image *, + cpl_image *, + cpl_size, + cpl_size, + double, + double, + const cpl_imagelist *, + cpl_size, const cpl_bivector *, const cpl_vector *, cpl_size) CPL_ATTR_NONNULL; static void cpl_geom_img_offset_saa_all_double(cpl_image *, cpl_image *, - double, double, + double, + double, const cpl_imagelist *, const cpl_bivector *, const cpl_vector *, @@ -137,17 +173,18 @@ static void cpl_geom_img_offset_saa_all_float(cpl_image *, cpl_image *, - double, double, + double, + double, const cpl_imagelist *, const cpl_bivector *, const cpl_vector *, cpl_size) CPL_ATTR_NONNULL; -static cpl_imagelist * cpl_imagelist_wrap_all_but_first(cpl_imagelist *) - CPL_ATTR_ALLOC; +static cpl_imagelist * +cpl_imagelist_wrap_all_but_first(cpl_imagelist *) CPL_ATTR_ALLOC; -static cpl_bivector * cpl_bivector_wrap_all_but_first(cpl_bivector *) - CPL_ATTR_ALLOC; +static cpl_bivector * +cpl_bivector_wrap_all_but_first(cpl_bivector *) CPL_ATTR_ALLOC; static void cpl_bivector_unwrap(cpl_bivector *); @@ -190,63 +227,66 @@ Possible #_cpl_error_code_ set in this function: - CPL_ERROR_NULL_INPUT if (one of) the input pointer(s) is NULL - CPL_ERROR_ILLEGAL_INPUT if ilist is not valid + - CPL_ERROR_INCOMPATIBLE_INPUT if ilist and correl have different lengths */ /*----------------------------------------------------------------------------*/ -cpl_bivector * cpl_geom_img_offset_fine( - const cpl_imagelist * ilist, - const cpl_bivector * estimates, - const cpl_bivector * anchors, - cpl_size s_hx, - cpl_size s_hy, - cpl_size m_hx, - cpl_size m_hy, - cpl_vector * correl) +cpl_bivector * +cpl_geom_img_offset_fine(const cpl_imagelist *ilist, + const cpl_bivector *estimates, + const cpl_bivector *anchors, + cpl_size s_hx, + cpl_size s_hy, + cpl_size m_hx, + cpl_size m_hy, + cpl_vector *correl) { - cpl_errorstate prevstate = cpl_errorstate_get(); - const cpl_size nima = cpl_imagelist_get_size(ilist); - const cpl_image * img1 = cpl_imagelist_get_const(ilist, 0); - const cpl_type type = cpl_image_get_type(img1); - const cpl_size nx = cpl_image_get_size_x(img1); - const cpl_size ny = cpl_image_get_size_y(img1); - cpl_image * med1; - cpl_image * medi; - cpl_mask * kernel; - double * correl_data; - const double * anchors_x_data = cpl_bivector_get_x_data_const(anchors); - const double * anchors_y_data = cpl_bivector_get_y_data_const(anchors); - const double * estim_x_data = cpl_bivector_get_x_data_const(estimates); - const double * estim_y_data = cpl_bivector_get_y_data_const(estimates); - cpl_bivector * offsets; - double * offsets_x_data; - double * offsets_y_data; - double offsx, offsy; - cpl_size i; - + cpl_errorstate prevstate = cpl_errorstate_get(); + const cpl_size nima = cpl_imagelist_get_size(ilist); + const cpl_image *img1 = cpl_imagelist_get_const(ilist, 0); + const cpl_type type = cpl_image_get_type(img1); + const cpl_size nx = cpl_image_get_size_x(img1); + const cpl_size ny = cpl_image_get_size_y(img1); + cpl_image *med1; + cpl_image *medi; + cpl_mask *kernel; + double *correl_data; + const double *anchors_x_data = cpl_bivector_get_x_data_const(anchors); + const double *anchors_y_data = cpl_bivector_get_y_data_const(anchors); + const double *estim_x_data = cpl_bivector_get_x_data_const(estimates); + const double *estim_y_data = cpl_bivector_get_y_data_const(estimates); + cpl_bivector *offsets; + double *offsets_x_data; + double *offsets_y_data; + double offsx, offsy; + cpl_size i; + /* Check entries */ - cpl_ensure(ilist, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(ilist, CPL_ERROR_NULL_INPUT, NULL); cpl_ensure(estimates, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(anchors, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(correl, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(cpl_imagelist_is_uniform(ilist)==0, CPL_ERROR_ILLEGAL_INPUT, - NULL); + cpl_ensure(anchors, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(correl, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(cpl_vector_get_size(correl) == nima, + CPL_ERROR_INCOMPATIBLE_INPUT, NULL); + cpl_ensure(cpl_imagelist_is_uniform(ilist) == 0, CPL_ERROR_ILLEGAL_INPUT, + NULL); for (i = 0; i < cpl_bivector_get_size(anchors); i++) { cpl_ensure(anchors_x_data[i] >= 0.0, CPL_ERROR_ILLEGAL_INPUT, NULL); - cpl_ensure(anchors_x_data[i] < nx, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(anchors_x_data[i] < nx, CPL_ERROR_ILLEGAL_INPUT, NULL); cpl_ensure(anchors_y_data[i] >= 0.0, CPL_ERROR_ILLEGAL_INPUT, NULL); - cpl_ensure(anchors_y_data[i] < ny, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(anchors_y_data[i] < ny, CPL_ERROR_ILLEGAL_INPUT, NULL); } /* Create the kernel for the filtering operations */ kernel = cpl_mask_new(3, 3); cpl_mask_not(kernel); - + /* Filter the first image */ medi = cpl_image_new(nx, ny, type); med1 = cpl_image_new(nx, ny, type); cpl_image_filter_mask(med1, img1, kernel, CPL_FILTER_MEDIAN, CPL_BORDER_FILTER); - + /* Create the offsets container */ offsets = cpl_bivector_new(nima); offsets_x_data = cpl_bivector_get_x_data(offsets); @@ -256,8 +296,7 @@ offsets_x_data[0] = 0.0; offsets_y_data[0] = 0.0; correl_data[0] = 0.0; - for (i=1; i < nima; i++) { - + for (i = 1; i < nima; i++) { /* Filter the current image */ cpl_image_filter_mask(medi, cpl_imagelist_get_const(ilist, i), kernel, CPL_FILTER_MEDIAN, CPL_BORDER_FILTER); @@ -265,11 +304,11 @@ /* Set the estimates */ offsx = estim_x_data[i]; offsy = estim_y_data[i]; - + /* Perform cross-correlation */ - correl_data[i] = cpl_geom_ima_offset_xcorr(med1, medi, anchors, - s_hx, s_hy, m_hx, m_hy, - &offsx, &offsy); + correl_data[i] = + cpl_geom_ima_offset_xcorr(med1, medi, anchors, s_hx, s_hy, m_hx, + m_hy, &offsx, &offsy); cpl_errorstate_set(prevstate); if (correl_data[i] < 0.0) { @@ -277,32 +316,36 @@ /* declare the offset as invalid: null offsets and dist=-1 */ offsets_x_data[i] = 0.0; offsets_y_data[i] = 0.0; - } else { + } + else { /* Something was found. */ /* One standard failure case is when the returned offset is */ /* located on the border of the search zone. Identify such */ /* cases and flag the frame as not registrable by setting */ /* the offset vector to nil and the distance to -1. */ - if ((fabs(fabs(estim_x_data[i]-offsx)-(double)s_hx)<1) || - (fabs(fabs(estim_y_data[i]-offsy)-(double)s_hy)<1)) { + if ((fabs(fabs(estim_x_data[i] - offsx) - (double)s_hx) < 1) || + (fabs(fabs(estim_y_data[i] - offsy) - (double)s_hy) < 1)) { offsets_x_data[i] = 0.0; offsets_y_data[i] = 0.0; correl_data[i] = -1.0; - } else { + } + else { /* The returned offset is correct */ offsets_x_data[i] = offsx; offsets_y_data[i] = offsy; } } if (correl_data[i] < 0.0) { - cpl_msg_debug(cpl_func, "Frame %" CPL_SIZE_FORMAT "/%" - CPL_SIZE_FORMAT " does not correlate in window " + cpl_msg_debug(cpl_func, + "Frame %" CPL_SIZE_FORMAT "/%" CPL_SIZE_FORMAT + " does not correlate in window " " 1 + 2%" CPL_SIZE_FORMAT " X 1 + 2%" CPL_SIZE_FORMAT - " sampling 1 + 2%" CPL_SIZE_FORMAT " X 1 + 2%" - CPL_SIZE_FORMAT, 1 + i, nima, s_hx, s_hy, m_hx, m_hy); + " sampling 1 + 2%" CPL_SIZE_FORMAT + " X 1 + 2%" CPL_SIZE_FORMAT, + 1 + i, nima, s_hx, s_hy, m_hx, m_hy); } } - + cpl_mask_delete(kernel); cpl_image_delete(med1); cpl_image_delete(medi); @@ -313,7 +356,7 @@ /*----------------------------------------------------------------------------*/ /** @brief Images list recombination - @param self Input imagelist - with refining images may be erased + @param self Input imagelist @param offs List of offsets in x and y @param refine Iff non-zero, the offsets will be refined @param aperts List of correlation apertures or NULL if unknown @@ -335,10 +378,8 @@ This function detects cross correlation points in the first image (if not provided by the user), use them to refine the provided offsets with a cross correlation method, and then apply the shift and add to recombine the images - together. Non-correlating images are removed from self. + together. - Without offset refinement self is not modified. - The supported types are CPL_TYPE_DOUBLE, CPL_TYPE_FLOAT. The number of provided offsets shall be equal to the number of input images. @@ -368,50 +409,50 @@ - CPL_ERROR_DATA_NOT_FOUND if the shift and add of the images fails */ /*----------------------------------------------------------------------------*/ -cpl_image ** cpl_geom_img_offset_combine(const cpl_imagelist* self, - const cpl_bivector * offs, - int refine, - const cpl_bivector * aperts, - const cpl_vector * sigmas, - cpl_size * pisigma, - cpl_size s_hx, - cpl_size s_hy, - cpl_size m_hx, - cpl_size m_hy, - cpl_size min_rej, - cpl_size max_rej, - cpl_geom_combine union_flag) +cpl_image ** +cpl_geom_img_offset_combine(const cpl_imagelist *self, + const cpl_bivector *offs, + int refine, + const cpl_bivector *aperts, + const cpl_vector *sigmas, + cpl_size *pisigma, + cpl_size s_hx, + cpl_size s_hy, + cpl_size m_hx, + cpl_size m_hy, + cpl_size min_rej, + cpl_size max_rej, + cpl_geom_combine union_flag) { - const cpl_imagelist* uselist = self; - cpl_imagelist * modlist = NULL; - const cpl_bivector * use_offs = offs; - cpl_bivector * offs_fine = NULL; - const cpl_size nima = cpl_imagelist_get_size(self); - cpl_image ** combined; + const cpl_imagelist *uselist = self; + cpl_imagelist *modlist = NULL; + const cpl_bivector *use_offs = offs; + cpl_bivector *offs_fine = NULL; + const cpl_size nima = cpl_imagelist_get_size(self); + cpl_image **combined; /* Check inputs */ cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); cpl_ensure(cpl_imagelist_is_uniform(self) == 0, CPL_ERROR_ILLEGAL_INPUT, - NULL); - cpl_ensure(offs != NULL, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(cpl_bivector_get_size(offs) == nima, CPL_ERROR_INCOMPATIBLE_INPUT, NULL); + cpl_ensure(offs != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(cpl_bivector_get_size(offs) == nima, + CPL_ERROR_INCOMPATIBLE_INPUT, NULL); if (refine != 0 && nima > 1) { - const cpl_bivector * use_aperts = aperts; /* May be NULL */ - cpl_bivector * anchor = NULL; + const cpl_bivector *use_aperts = aperts; /* May be NULL */ + cpl_bivector *anchor = NULL; if (use_aperts == NULL) { /* No apertures are provided, look for a cross correlation point */ - double * anchor_x; - double * anchor_y; - cpl_apertures * apertures - = cpl_apertures_extract(cpl_imagelist_get_const(self, 0), - sigmas, pisigma); + double *anchor_x; + double *anchor_y; + cpl_apertures *apertures = + cpl_apertures_extract(cpl_imagelist_get_const(self, 0), sigmas, + pisigma); if (apertures != NULL) { - /* Found some, just pick a single point */ anchor = cpl_bivector_new(1); anchor_x = cpl_bivector_get_x_data(anchor); @@ -430,18 +471,18 @@ if (use_aperts != NULL) { /* Refine the offsets */ - cpl_vector * correl = cpl_vector_new(nima); + cpl_vector *correl = cpl_vector_new(nima); - offs_fine = cpl_geom_img_offset_fine(self, offs, use_aperts, - s_hx, s_hy, m_hx, m_hy, correl); + offs_fine = cpl_geom_img_offset_fine(self, offs, use_aperts, s_hx, + s_hy, m_hx, m_hy, correl); cpl_bivector_delete(anchor); if (offs_fine != NULL) { - const double * correl_data = cpl_vector_get_data_const(correl); - double * offs_fine_x = cpl_bivector_get_x_data(offs_fine); - double * offs_fine_y = cpl_bivector_get_y_data(offs_fine); - cpl_size ngood = 0; - cpl_size i; + const double *correl_data = cpl_vector_get_data_const(correl); + double *offs_fine_x = cpl_bivector_get_x_data(offs_fine); + double *offs_fine_y = cpl_bivector_get_y_data(offs_fine); + cpl_size ngood = 0; + cpl_size i; /* Create a modified list, with the correlating images */ modlist = cpl_imagelist_new(); @@ -452,8 +493,9 @@ offs_fine_x[ngood] = offs_fine_x[i]; offs_fine_y[ngood] = offs_fine_y[i]; /* modlist will _not_ be modified */ - cpl_imagelist_set(modlist, (cpl_image*) - cpl_imagelist_get_const(self, i), + cpl_imagelist_set(modlist, + (cpl_image *) + cpl_imagelist_get_const(self, i), ngood); ngood++; } @@ -468,8 +510,8 @@ uselist = modlist; - assert( cpl_bivector_get_size(offs_fine) == ngood ); - assert( cpl_imagelist_get_size(uselist) == ngood ); + assert(cpl_bivector_get_size(offs_fine) == ngood); + assert(cpl_imagelist_get_size(uselist) == ngood); } use_offs = offs_fine; @@ -480,9 +522,9 @@ } /* Shift & add */ - combined = cpl_geom_img_offset_saa(uselist, use_offs, CPL_KERNEL_DEFAULT, - min_rej, max_rej, union_flag, - NULL, NULL); + combined = + cpl_geom_img_offset_saa(uselist, use_offs, CPL_KERNEL_DEFAULT, min_rej, + max_rej, union_flag, NULL, NULL); cpl_bivector_delete(offs_fine); if (modlist != NULL) { cpl_size i = cpl_imagelist_get_size(modlist); @@ -494,9 +536,11 @@ } if (combined == NULL) { - (void)cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, "Could not " + (void)cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, + "Could not " "shift and add %" CPL_SIZE_FORMAT - " images", nima); + " images", + nima); } return combined; @@ -572,51 +616,52 @@ @em CPL_GEOM_FIRST. */ /*----------------------------------------------------------------------------*/ -cpl_image ** cpl_geom_img_offset_saa(const cpl_imagelist * ilist, - const cpl_bivector * offs, - cpl_kernel kernel, - cpl_size rejmin, - cpl_size rejmax, - cpl_geom_combine union_flag, - double * ppos_x, - double * ppos_y) +cpl_image ** +cpl_geom_img_offset_saa(const cpl_imagelist *ilist, + const cpl_bivector *offs, + cpl_kernel kernel, + cpl_size rejmin, + cpl_size rejmax, + cpl_geom_combine union_flag, + double *ppos_x, + double *ppos_y) { - cpl_imagelist * copy = (cpl_imagelist *)ilist; /* Not modified */ - cpl_bivector * offscopy = (cpl_bivector *)offs; /* Not modified */ - const cpl_size nima = cpl_imagelist_get_size(ilist); - const cpl_image * img1 = cpl_imagelist_get_const(ilist, 0); - const cpl_size sizex = cpl_image_get_size_x(img1); - const cpl_size sizey = cpl_image_get_size_y(img1); - const cpl_type type = cpl_image_get_type(img1); - const cpl_vector * voffsx; - const cpl_vector * voffsy; + cpl_imagelist *copy = (cpl_imagelist *)ilist; /* Not modified */ + cpl_bivector *offscopy = (cpl_bivector *)offs; /* Not modified */ + const cpl_size nima = cpl_imagelist_get_size(ilist); + const cpl_image *img1 = cpl_imagelist_get_const(ilist, 0); + const cpl_size sizex = cpl_image_get_size_x(img1); + const cpl_size sizey = cpl_image_get_size_y(img1); + const cpl_type type = cpl_image_get_type(img1); + const cpl_vector *voffsx; + const cpl_vector *voffsy; /* Test rejection parameters */ - const cpl_boolean do_rej = nima > 3 && nima > 2*(rejmin+rejmax) - ? CPL_TRUE : CPL_FALSE; - const cpl_size rmin = do_rej ? rejmin : 0; - const cpl_size rmax = do_rej ? rejmax : 0; - const cpl_size rtot = rmin + rmax; - const cpl_size tabsperpix = CPL_KERNEL_TABSPERPIX; - cpl_vector * xyprofile; - cpl_size nx, ny; - double start_x, start_y; - cpl_image * final; - cpl_image * contrib; - cpl_image ** out_arr; - cpl_size i_ima; - cpl_size firstbpm; + const cpl_boolean do_rej = + nima > 3 && nima > 2 * (rejmin + rejmax) ? CPL_TRUE : CPL_FALSE; + const cpl_size rmin = do_rej ? rejmin : 0; + const cpl_size rmax = do_rej ? rejmax : 0; + const cpl_size rtot = rmin + rmax; + const cpl_size tabsperpix = CPL_KERNEL_TABSPERPIX; + cpl_vector *xyprofile; + cpl_size nx, ny; + double start_x, start_y; + cpl_image *final; + cpl_image *contrib; + cpl_image **out_arr; + cpl_size i_ima; + cpl_size firstbpm; cpl_ensure(ilist != NULL, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(offs != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(offs != NULL, CPL_ERROR_NULL_INPUT, NULL); cpl_ensure(cpl_imagelist_is_uniform(ilist) == 0, CPL_ERROR_ILLEGAL_INPUT, NULL); - cpl_ensure(cpl_bivector_get_size(offs) == nima, CPL_ERROR_INCOMPATIBLE_INPUT, - NULL); - cpl_ensure(rejmin>=0, CPL_ERROR_ILLEGAL_INPUT, NULL); - cpl_ensure(rejmax>=0, CPL_ERROR_ILLEGAL_INPUT, NULL); - - + cpl_ensure(cpl_bivector_get_size(offs) == nima, + CPL_ERROR_INCOMPATIBLE_INPUT, NULL); + cpl_ensure(rejmin >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(rejmax >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL); + + /* Compute output image size for union/intersection */ voffsx = cpl_bivector_get_x_const(offs); voffsy = cpl_bivector_get_y_const(offs); @@ -627,11 +672,11 @@ /* For this mode, the rejection arguments are also used to reduce the size of the resulting image */ - cpl_vector * ox_tmp = cpl_vector_duplicate(voffsx); - cpl_vector * oy_tmp = cpl_vector_duplicate(voffsy); - const double * ox_data = cpl_vector_get_data_const(ox_tmp); - const double * oy_data = cpl_vector_get_data_const(oy_tmp); - double ox_max, oy_max; + cpl_vector *ox_tmp = cpl_vector_duplicate(voffsx); + cpl_vector *oy_tmp = cpl_vector_duplicate(voffsy); + const double *ox_data = cpl_vector_get_data_const(ox_tmp); + const double *oy_data = cpl_vector_get_data_const(oy_tmp); + double ox_max, oy_max; cpl_vector_sort(ox_tmp, 1); @@ -640,8 +685,10 @@ start_x = ox_data[rtot]; start_y = oy_data[rtot]; - if (ppos_x != NULL) *ppos_x = 1.0 - start_x; - if (ppos_y != NULL) *ppos_y = 1.0 - start_y; + if (ppos_x != NULL) + *ppos_x = 1.0 - start_x; + if (ppos_y != NULL) + *ppos_y = 1.0 - start_y; ox_max = ox_data[nima - rtot - 1]; oy_max = oy_data[nima - rtot - 1]; @@ -652,7 +699,8 @@ cpl_vector_delete(ox_tmp); cpl_vector_delete(oy_tmp); - } else if (union_flag == CPL_GEOM_INTERSECT) { + } + else if (union_flag == CPL_GEOM_INTERSECT) { /* Intersection image */ const double ox_min = cpl_vector_get_min(voffsx); const double oy_min = cpl_vector_get_min(voffsy); @@ -660,8 +708,10 @@ start_x = cpl_vector_get_max(voffsx); start_y = cpl_vector_get_max(voffsy); - if (ppos_x != NULL) *ppos_x = start_x; - if (ppos_y != NULL) *ppos_y = start_y; + if (ppos_x != NULL) + *ppos_x = start_x; + if (ppos_y != NULL) + *ppos_y = start_y; /* Round down */ nx = (cpl_size)((double)sizex - start_x + ox_min); @@ -669,16 +719,18 @@ cpl_ensure(nx > 0, CPL_ERROR_ILLEGAL_OUTPUT, NULL); cpl_ensure(ny > 0, CPL_ERROR_ILLEGAL_OUTPUT, NULL); - - } else if (union_flag == CPL_GEOM_FIRST) { + } + else if (union_flag == CPL_GEOM_FIRST) { /* First image as reference */ nx = sizex; ny = sizey; start_x = 0.0; start_y = 0.0; - if (ppos_x != NULL) *ppos_x = 1.0; - if (ppos_y != NULL) *ppos_y = 1.0; + if (ppos_x != NULL) + *ppos_x = 1.0; + if (ppos_y != NULL) + *ppos_y = 1.0; if (rtot == 0 && nima > 1) { /* Create shallow copies, without the 1st element */ @@ -688,8 +740,8 @@ /* copy and offscopy are NOT modified below */ } - - } else { + } + else { /* union_flag is not one of the three supported modes */ (void)cpl_error_set_(CPL_ERROR_UNSUPPORTED_MODE); return NULL; @@ -701,8 +753,10 @@ radius of 2.0 */ if (cpl_vector_fill_kernel_profile(xyprofile, kernel, 2.0)) { cpl_vector_delete(xyprofile); - if (copy != ilist) cpl_imagelist_unwrap(copy); - if (offscopy != offs) cpl_bivector_unwrap(offscopy); + if (copy != ilist) + cpl_imagelist_unwrap(copy); + if (offscopy != offs) + cpl_bivector_unwrap(offscopy); (void)cpl_error_set_where_(); return NULL; } @@ -713,20 +767,22 @@ /* Create output contribution image, initialized to zero */ contrib = cpl_image_new(nx, ny, CPL_TYPE_INT); - } else { + } + else { /* Create output image, duplicated from 1st image */ final = cpl_image_duplicate(img1); if (cpl_image_get_bpm_const(final) != NULL) { /* Check for bpm */ - cpl_mask * mask1 = cpl_image_get_bpm(final); + cpl_mask *mask1 = cpl_image_get_bpm(final); cpl_mask_not(mask1); contrib = cpl_image_new_from_mask(mask1); cpl_image_fill_rejected(final, 0.0); cpl_image_accept_all(final); - } else { + } + else { /* Create an integer image filled with 1's */ - int * dcontrib = cpl_malloc((size_t)(nx * ny) * sizeof(*dcontrib)); + int *dcontrib = cpl_malloc((size_t)(nx * ny) * sizeof(*dcontrib)); contrib = cpl_image_wrap_int(nx, ny, dcontrib); (void)cpl_image_fill_int(contrib, 1); @@ -735,12 +791,11 @@ /* Find first plane with a non-empty bad pixel map - if any */ firstbpm = nima; - for(i_ima=0; i_ima < nima; i_ima++) - { - const cpl_mask * bpm - = cpl_image_get_bpm_const(cpl_imagelist_get_const(ilist, i_ima)); + for (i_ima = 0; i_ima < nima; i_ima++) { + const cpl_mask *bpm = + cpl_image_get_bpm_const(cpl_imagelist_get_const(ilist, i_ima)); - if(bpm != NULL && !cpl_mask_is_empty(bpm)) { + if (bpm != NULL && !cpl_mask_is_empty(bpm)) { firstbpm = i_ima; break; } @@ -749,49 +804,53 @@ /* Switch on the data type */ if (type == CPL_TYPE_DOUBLE) { if (rtot > 0 || firstbpm < nima) { - cpl_geom_img_offset_saa_double(final, contrib, rmin, rmax, - start_x, start_y, - ilist, firstbpm, offs, + cpl_geom_img_offset_saa_double(final, contrib, rmin, rmax, start_x, + start_y, ilist, firstbpm, offs, xyprofile, tabsperpix); - } else { - cpl_geom_img_offset_saa_all_double(final, contrib, - start_x, start_y, - copy, offscopy, - xyprofile, tabsperpix); } - } else if (type == CPL_TYPE_FLOAT) { + else { + cpl_geom_img_offset_saa_all_double(final, contrib, start_x, start_y, + copy, offscopy, xyprofile, + tabsperpix); + } + } + else if (type == CPL_TYPE_FLOAT) { if (rtot > 0 || firstbpm < nima) { - cpl_geom_img_offset_saa_float(final, contrib, rmin, rmax, - start_x, start_y, - ilist, firstbpm, offs, + cpl_geom_img_offset_saa_float(final, contrib, rmin, rmax, start_x, + start_y, ilist, firstbpm, offs, xyprofile, tabsperpix); - } else { - cpl_geom_img_offset_saa_all_float(final, contrib, - start_x, start_y, - copy, offscopy, - xyprofile, tabsperpix); } - } else { - cpl_vector_delete(xyprofile); - cpl_image_delete(final); - cpl_image_delete(contrib); - if (copy != ilist) cpl_imagelist_unwrap(copy); - if (offscopy != offs) cpl_bivector_unwrap(offscopy); - (void)cpl_error_set_(CPL_ERROR_INVALID_TYPE); - return NULL; + else { + cpl_geom_img_offset_saa_all_float(final, contrib, start_x, start_y, + copy, offscopy, xyprofile, + tabsperpix); + } + } + else { + cpl_vector_delete(xyprofile); + cpl_image_delete(final); + cpl_image_delete(contrib); + if (copy != ilist) + cpl_imagelist_unwrap(copy); + if (offscopy != offs) + cpl_bivector_unwrap(offscopy); + (void)cpl_error_set_(CPL_ERROR_INVALID_TYPE); + return NULL; } cpl_vector_delete(xyprofile); - out_arr = cpl_malloc(2*sizeof(cpl_image *)); + out_arr = cpl_malloc(2 * sizeof(cpl_image *)); out_arr[0] = final; out_arr[1] = contrib; - if (copy != ilist) cpl_imagelist_unwrap(copy); - if (offscopy != offs) cpl_bivector_unwrap(offscopy); + if (copy != ilist) + cpl_imagelist_unwrap(copy); + if (offscopy != offs) + cpl_bivector_unwrap(offscopy); return out_arr; } - + /**@}*/ /*----------------------------------------------------------------------------*/ @@ -837,32 +896,33 @@ - CPL_ERROR_INVALID_TYPE */ /*----------------------------------------------------------------------------*/ -static double cpl_geom_ima_offset_xcorr(const cpl_image * im1, - const cpl_image * im2, - const cpl_bivector * anchors, - cpl_size s_hx, - cpl_size s_hy, - cpl_size m_hx, - cpl_size m_hy, - double * offs_x, - double * offs_y) +static double +cpl_geom_ima_offset_xcorr(const cpl_image *im1, + const cpl_image *im2, + const cpl_bivector *anchors, + cpl_size s_hx, + cpl_size s_hy, + cpl_size m_hx, + cpl_size m_hy, + double *offs_x, + double *offs_y) { const cpl_size nx = cpl_image_get_size_x(im1); const cpl_size ny = cpl_image_get_size_y(im1); const cpl_size nanchors = cpl_bivector_get_size(anchors); - const double * anchor_x = cpl_bivector_get_x_data_const(anchors); - const double * anchor_y = cpl_bivector_get_y_data_const(anchors); - cpl_bivector * delta = cpl_bivector_new(nanchors); - double * delta_x = cpl_bivector_get_x_data(delta); - double * delta_y = cpl_bivector_get_y_data(delta); - cpl_vector * correl = cpl_vector_new(nanchors); - double * correl_data = cpl_vector_get_data(correl); + const double *anchor_x = cpl_bivector_get_x_data_const(anchors); + const double *anchor_y = cpl_bivector_get_y_data_const(anchors); + cpl_bivector *delta = cpl_bivector_new(nanchors); + double *delta_x = cpl_bivector_get_x_data(delta); + double *delta_y = cpl_bivector_get_y_data(delta); + cpl_vector *correl = cpl_vector_new(nanchors); + double *correl_data = cpl_vector_get_data(correl); /* Temporary work array */ - double * corr_tmp - = cpl_malloc((size_t)(2*s_hx+1) * (size_t)(2*s_hy+1) * sizeof(double)); - double best_xcorr = -1.0; /* Assume failure */ - cpl_size nvalid = 0; - cpl_size i; + double *corr_tmp = cpl_malloc((size_t)(2 * s_hx + 1) * + (size_t)(2 * s_hy + 1) * sizeof(double)); + double best_xcorr = -1.0; /* Assume failure */ + cpl_size nvalid = 0; + cpl_size i; /* Loop on all correlating points */ @@ -872,18 +932,21 @@ const int x_2 = x_1 - (int)(*offs_x); const int y_2 = y_1 - (int)(*offs_y); - correl_data[nvalid] = 0 <= x_2 && x_2 < nx && 0 <= y_2 && y_2 < ny - ? cpl_geom_ima_offset_xcorr_subw(corr_tmp, im1, im2, x_1, y_1, - x_2, y_2, s_hx, s_hy, m_hx, m_hy, - delta_x+nvalid, delta_y+nvalid) - : -1.0; + correl_data[nvalid] = + 0 <= x_2 && x_2 < nx && 0 <= y_2 && y_2 < ny + ? cpl_geom_ima_offset_xcorr_subw(corr_tmp, im1, im2, x_1, y_1, + x_2, y_2, s_hx, s_hy, m_hx, + m_hy, delta_x + nvalid, + delta_y + nvalid) + : -1.0; - if (correl_data[nvalid] >= 0.0) nvalid++; + if (correl_data[nvalid] >= 0.0) + nvalid++; } cpl_free(corr_tmp); - if (nvalid > 0) { /* There are valid points */ + if (nvalid > 0) { /* There are valid points */ cpl_size best_rank = 0; if (nvalid > 1) { @@ -891,7 +954,6 @@ double min_sqdist; if (nvalid < nanchors) { - /* Resize for the median computation - invalidates the data pointers! */ cpl_vector_set_size(cpl_bivector_get_x(delta), nvalid); @@ -899,21 +961,20 @@ delta_x = cpl_bivector_get_x_data(delta); delta_y = cpl_bivector_get_y_data(delta); - } - + /* Compute a median offset from the correlations */ median_dx = cpl_vector_get_median_const(cpl_bivector_get_x(delta)); median_dy = cpl_vector_get_median_const(cpl_bivector_get_y(delta)); /* Find the offset measurement closest to this median */ - min_sqdist = (delta_x[0]-median_dx) * (delta_x[0]-median_dx) - + (delta_y[0]-median_dy) * (delta_y[0]-median_dy); + min_sqdist = (delta_x[0] - median_dx) * (delta_x[0] - median_dx) + + (delta_y[0] - median_dy) * (delta_y[0] - median_dy); for (i = 1; i < nvalid; i++) { - const double sqdist - = (delta_x[i]-median_dx) * (delta_x[i]-median_dx) - + (delta_y[i]-median_dy) * (delta_y[i]-median_dy); + const double sqdist = + (delta_x[i] - median_dx) * (delta_x[i] - median_dx) + + (delta_y[i] - median_dy) * (delta_y[i] - median_dy); if (sqdist < min_sqdist) { min_sqdist = sqdist; @@ -925,7 +986,6 @@ *offs_x = (int)(*offs_x) + delta_x[best_rank]; *offs_y = (int)(*offs_y) + delta_y[best_rank]; best_xcorr = correl_data[best_rank]; - } cpl_bivector_delete(delta); @@ -975,55 +1035,41 @@ - CPL_ERROR_INVALID_TYPE */ /*----------------------------------------------------------------------------*/ -static double cpl_geom_ima_offset_xcorr_subw(double * correl, - const cpl_image * im1, - const cpl_image * im2, - cpl_size im1_posx, - cpl_size im1_posy, - cpl_size im2_posx, - cpl_size im2_posy, - cpl_size s_hx, - cpl_size s_hy, - cpl_size m_hx, - cpl_size m_hy, - double * offs_x, - double * offs_y) +static double +cpl_geom_ima_offset_xcorr_subw(double *correl, + const cpl_image *im1, + const cpl_image *im2, + cpl_size im1_posx, + cpl_size im1_posy, + cpl_size im2_posx, + cpl_size im2_posy, + cpl_size s_hx, + cpl_size s_hy, + cpl_size m_hx, + cpl_size m_hy, + double *offs_x, + double *offs_y) { const cpl_type type = cpl_image_get_type(im1); - cpl_size k_min = 0; - cpl_size l_min = 0; - double inc_x, inc_y; - cpl_size pos_min; - double best_correl; - + cpl_size k_min = 0; + cpl_size l_min = 0; + double inc_x, inc_y; + cpl_size pos_min; + double best_correl; + /* Switch on the data type */ if (type == CPL_TYPE_DOUBLE) { - cpl_geom_ima_offset_xcorr_subw_double(correl, - im1, - im2, - im1_posx, - im1_posy, - im2_posx, - im2_posy, - s_hx, - s_hy, - m_hx, - m_hy, - &k_min, &l_min); - } else if (type == CPL_TYPE_FLOAT) { - cpl_geom_ima_offset_xcorr_subw_float(correl, - im1, - im2, - im1_posx, - im1_posy, - im2_posx, - im2_posy, - s_hx, - s_hy, - m_hx, - m_hy, - &k_min, &l_min); - } else { + cpl_geom_ima_offset_xcorr_subw_double(correl, im1, im2, im1_posx, + im1_posy, im2_posx, im2_posy, + s_hx, s_hy, m_hx, m_hy, &k_min, + &l_min); + } + else if (type == CPL_TYPE_FLOAT) { + cpl_geom_ima_offset_xcorr_subw_float(correl, im1, im2, im1_posx, + im1_posy, im2_posx, im2_posy, s_hx, + s_hy, m_hx, m_hy, &k_min, &l_min); + } + else { (void)cpl_error_set_(CPL_ERROR_INVALID_TYPE); return -1.0; } @@ -1033,14 +1079,21 @@ best_correl = correl[pos_min]; /* Compute inc_x and inc_y (sub-pixel precision) */ - if ((k_min == -s_hx) || (k_min == s_hx)) inc_x = 0.0; - else inc_x = 0.5*((correl[pos_min-1]-correl[pos_min+1])/ - (correl[pos_min-1]-(2.0*correl[pos_min])+correl[pos_min+1])); - - if ((l_min == -s_hy) || (l_min == s_hy)) inc_y = 0.0; - else inc_y = 0.5*((correl[pos_min-(2*s_hx+1)]-correl[pos_min+(2*s_hx+1)])/ - (correl[pos_min-(2*s_hx+1)]-(2.0*correl[pos_min])+ - correl[pos_min+(2*s_hx+1)])); + if ((k_min == -s_hx) || (k_min == s_hx)) + inc_x = 0.0; + else + inc_x = 0.5 * ((correl[pos_min - 1] - correl[pos_min + 1]) / + (correl[pos_min - 1] - (2.0 * correl[pos_min]) + + correl[pos_min + 1])); + + if ((l_min == -s_hy) || (l_min == s_hy)) + inc_y = 0.0; + else + inc_y = + 0.5 * ((correl[pos_min - (2 * s_hx + 1)] - + correl[pos_min + (2 * s_hx + 1)]) / + (correl[pos_min - (2 * s_hx + 1)] - (2.0 * correl[pos_min]) + + correl[pos_min + (2 * s_hx + 1)])); /* Return the sub-pixel precision offsets */ *offs_x = (double)k_min + inc_x; @@ -1066,12 +1119,12 @@ */ /*----------------------------------------------------------------------------*/ -inline static void cpl_geom_img_get_min_max_double(double * a, - cpl_size n, - cpl_size rmin, - cpl_size rmax) +inline static void +cpl_geom_img_get_min_max_double(double *a, + cpl_size n, + cpl_size rmin, + cpl_size rmax) { - double tmp; const cpl_size jeq = CX_MIN(rmin, rmax); cpl_size i, j; @@ -1080,12 +1133,12 @@ /* Gain some locality */ for (j = 0; j < jeq; j++) { /* Bubble one minimum value into place */ - for (i = n-j-1; i > j; i--) { - CPL_SORT(a, i, i-1, tmp); + for (i = n - j - 1; i > j; i--) { + CPL_SORT(a, i, i - 1, tmp); } /* Bubble one maximum value into place */ for (i += 2; i < n - j; i++) { - CPL_SORT(a, i, i-1, tmp); + CPL_SORT(a, i, i - 1, tmp); } } @@ -1093,20 +1146,20 @@ /* Bubble one minimum value into place */ for (; j < rmin; j++) { - for (i = n-rmax-1; i > j; i--) { - CPL_SORT(a, i, i-1, tmp); + for (i = n - rmax - 1; i > j; i--) { + CPL_SORT(a, i, i - 1, tmp); } } /* Bubble one maximum value into place */ for (; j < rmax; j++) { - for (i = rmin+1; i < n - j; i++) { - CPL_SORT(a, i, i-1, tmp); + for (i = rmin + 1; i < n - j; i++) { + CPL_SORT(a, i, i - 1, tmp); } } - cpl_tools_add_flops( n * (rmin + rmax) - - ((rmin + rmax) * (rmin + rmax + 1)) / 2); + cpl_tools_add_flops(n * (rmin + rmax) - + ((rmin + rmax) * (rmin + rmax + 1)) / 2); } @@ -1119,10 +1172,10 @@ */ /*----------------------------------------------------------------------------*/ -static cpl_imagelist * cpl_imagelist_wrap_all_but_first(cpl_imagelist * other) +static cpl_imagelist * +cpl_imagelist_wrap_all_but_first(cpl_imagelist *other) { - - cpl_imagelist * self; + cpl_imagelist *self; const cpl_size n = cpl_imagelist_get_size(other); cpl_size i; @@ -1131,9 +1184,9 @@ self = cpl_imagelist_new(); - for (i=1; i < n; i++) { - cpl_image * copy = cpl_imagelist_get(other, i); - (void)cpl_imagelist_set(self, copy, i-1); + for (i = 1; i < n; i++) { + cpl_image *copy = cpl_imagelist_get(other, i); + (void)cpl_imagelist_set(self, copy, i - 1); } return self; @@ -1148,19 +1201,19 @@ */ /*----------------------------------------------------------------------------*/ -static cpl_bivector * cpl_bivector_wrap_all_but_first(cpl_bivector * self) +static cpl_bivector * +cpl_bivector_wrap_all_but_first(cpl_bivector *self) { - const cpl_size n = cpl_bivector_get_size(self); - cpl_vector * xvec; - cpl_vector * yvec; + cpl_vector *xvec; + cpl_vector *yvec; - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(n > 1, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(n > 1, CPL_ERROR_ILLEGAL_INPUT, NULL); - xvec = cpl_vector_wrap(n-1, 1 + cpl_bivector_get_x_data(self)); - yvec = cpl_vector_wrap(n-1, 1 + cpl_bivector_get_y_data(self)); + xvec = cpl_vector_wrap(n - 1, 1 + cpl_bivector_get_x_data(self)); + yvec = cpl_vector_wrap(n - 1, 1 + cpl_bivector_get_y_data(self)); return cpl_bivector_wrap_vectors(xvec, yvec); } @@ -1174,7 +1227,8 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_bivector_unwrap(cpl_bivector * self) +static void +cpl_bivector_unwrap(cpl_bivector *self) { if (self != NULL) { (void)cpl_vector_unwrap(cpl_bivector_get_x(self)); diff -Nru cpl-7.1.4+ds/cpldrs/cpl_geom_img.h cpl-7.2.2+ds/cpldrs/cpl_geom_img.h --- cpl-7.1.4+ds/cpldrs/cpl_geom_img.h 2021-05-07 12:09:09.000000000 +0000 +++ cpl-7.2.2+ds/cpldrs/cpl_geom_img.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -44,7 +44,8 @@ * The CPL Geometry combination modes */ -typedef enum { +typedef enum +{ /** * Combine using the intersection of the images. @@ -55,7 +56,7 @@ * Combine using the union of the images. */ CPL_GEOM_UNION, - + /** * Combine using the first image to aggregate the other ones. */ @@ -70,26 +71,38 @@ -----------------------------------------------------------------------------*/ /* Offsets detection and frames recombination */ -cpl_bivector * cpl_geom_img_offset_fine(const cpl_imagelist *, +cpl_bivector *cpl_geom_img_offset_fine(const cpl_imagelist *, + const cpl_bivector *, + const cpl_bivector *, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_vector *) CPL_ATTR_ALLOC; + +cpl_image **cpl_geom_img_offset_saa(const cpl_imagelist *, + const cpl_bivector *, + cpl_kernel, + cpl_size, + cpl_size, + cpl_geom_combine, + double *, + double *) CPL_ATTR_ALLOC; + +cpl_image **cpl_geom_img_offset_combine(const cpl_imagelist *, const cpl_bivector *, + int, const cpl_bivector *, - cpl_size, cpl_size, cpl_size, cpl_size, - cpl_vector *) CPL_ATTR_ALLOC; - -cpl_image ** cpl_geom_img_offset_saa(const cpl_imagelist *, - const cpl_bivector *, - cpl_kernel, cpl_size, - cpl_size, cpl_geom_combine, - double *, double *) CPL_ATTR_ALLOC; - -cpl_image ** cpl_geom_img_offset_combine(const cpl_imagelist *, - const cpl_bivector *, int, - const cpl_bivector *, - const cpl_vector *, cpl_size *, - cpl_size, cpl_size, cpl_size, - cpl_size, cpl_size, cpl_size, - cpl_geom_combine) CPL_ATTR_ALLOC; + const cpl_vector *, + cpl_size *, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_size, + cpl_geom_combine) CPL_ATTR_ALLOC; CPL_END_DECLS -#endif +#endif diff -Nru cpl-7.1.4+ds/cpldrs/cpl_photom.c cpl-7.2.2+ds/cpldrs/cpl_photom.c --- cpl-7.1.4+ds/cpldrs/cpl_photom.c 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cpldrs/cpl_photom.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -105,62 +105,64 @@ - CPL_ERROR_ILLEGAL_INPUT if temp or a wavelength is non-positive */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_photom_fill_blackbody(cpl_vector * spectrum, - cpl_unit out_unit, - const cpl_vector * evalpoints, - cpl_unit in_unit, - double temp) +cpl_error_code +cpl_photom_fill_blackbody(cpl_vector *spectrum, + cpl_unit out_unit, + const cpl_vector *evalpoints, + cpl_unit in_unit, + double temp) { + double walpha = CPL_MATH_2PI; + double wbeta = CPL_PHYS_H / (CPL_PHYS_K * temp); + double *sp = cpl_vector_get_data(spectrum); + const double *wlf = cpl_vector_get_data_const(evalpoints); + const cpl_size n = cpl_vector_get_size(evalpoints); + int ipow; + cpl_size i; - double walpha = CPL_MATH_2PI; - double wbeta = CPL_PHYS_H / (CPL_PHYS_K * temp); - double * sp = cpl_vector_get_data( spectrum ); - const double * wlf = cpl_vector_get_data_const( evalpoints ); - const cpl_size n = cpl_vector_get_size( evalpoints ); - int ipow; - cpl_size i; - - cpl_ensure_code(spectrum != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(spectrum != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(evalpoints != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(n == cpl_vector_get_size( spectrum ), + cpl_ensure_code(n == cpl_vector_get_size(spectrum), CPL_ERROR_INCOMPATIBLE_INPUT); - cpl_ensure_code(temp > 0.0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(temp > 0.0, CPL_ERROR_ILLEGAL_INPUT); - assert( wlf != NULL ); - assert( sp != NULL ); + assert(wlf != NULL); + assert(sp != NULL); switch (in_unit) { case CPL_UNIT_LENGTH: { switch (out_unit) { - case CPL_UNIT_LESS: { - walpha *= 7.5 * cpl_tools_ipow(CPL_PHYS_H * CPL_PHYS_C - /(CPL_MATH_PI*CPL_PHYS_K * temp), - 5); - ipow = 5; - break; - } - case CPL_UNIT_PHOTONRADIANCE: { - walpha *= CPL_PHYS_C; - ipow = 4; - break; - } - case CPL_UNIT_ENERGYRADIANCE: { - walpha *= CPL_PHYS_H * CPL_PHYS_C * CPL_PHYS_C; - ipow = 5; - break; - } - default: - return cpl_error_set_(CPL_ERROR_UNSUPPORTED_MODE); + case CPL_UNIT_LESS: { + walpha *= + 7.5 * + cpl_tools_ipow(CPL_PHYS_H * CPL_PHYS_C / + (CPL_MATH_PI * CPL_PHYS_K * temp), + 5); + ipow = 5; + break; + } + case CPL_UNIT_PHOTONRADIANCE: { + walpha *= CPL_PHYS_C; + ipow = 4; + break; + } + case CPL_UNIT_ENERGYRADIANCE: { + walpha *= CPL_PHYS_H * CPL_PHYS_C * CPL_PHYS_C; + ipow = 5; + break; + } + default: + return cpl_error_set_(CPL_ERROR_UNSUPPORTED_MODE); } - wbeta *= CPL_PHYS_C; + wbeta *= CPL_PHYS_C; - for (i=0; i < n; i++) { + for (i = 0; i < n; i++) { if (wlf[i] <= 0.0) return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); - sp[i] = walpha / (cpl_tools_ipow(wlf[i], ipow) - * (expm1(wbeta / wlf[i]))); + sp[i] = walpha / (cpl_tools_ipow(wlf[i], ipow) * + (expm1(wbeta / wlf[i]))); } break; @@ -168,25 +170,25 @@ case CPL_UNIT_FREQUENCY: { switch (out_unit) { - case CPL_UNIT_PHOTONRADIANCE: { - walpha /= CPL_PHYS_C * CPL_PHYS_C; - ipow = 2; - break; - } - case CPL_UNIT_ENERGYRADIANCE: { - walpha *= CPL_PHYS_H / (CPL_PHYS_C * CPL_PHYS_C); - ipow = 3; - break; - } - default: - return cpl_error_set_(CPL_ERROR_UNSUPPORTED_MODE); + case CPL_UNIT_PHOTONRADIANCE: { + walpha /= CPL_PHYS_C * CPL_PHYS_C; + ipow = 2; + break; + } + case CPL_UNIT_ENERGYRADIANCE: { + walpha *= CPL_PHYS_H / (CPL_PHYS_C * CPL_PHYS_C); + ipow = 3; + break; + } + default: + return cpl_error_set_(CPL_ERROR_UNSUPPORTED_MODE); } - for (i=0; i < n; i++) { + for (i = 0; i < n; i++) { if (wlf[i] <= 0.0) return cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); - sp[i] = walpha * cpl_tools_ipow(wlf[i], ipow) - / (expm1(wbeta * wlf[i])); + sp[i] = walpha * cpl_tools_ipow(wlf[i], ipow) / + (expm1(wbeta * wlf[i])); } break; @@ -196,6 +198,5 @@ } return CPL_ERROR_NONE; - } /**@}*/ diff -Nru cpl-7.1.4+ds/cpldrs/cpl_photom.h cpl-7.2.2+ds/cpldrs/cpl_photom.h --- cpl-7.1.4+ds/cpldrs/cpl_photom.h 2021-05-07 12:09:10.000000000 +0000 +++ cpl-7.2.2+ds/cpldrs/cpl_photom.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -37,10 +37,12 @@ Function prototypes -----------------------------------------------------------------------------*/ -cpl_error_code cpl_photom_fill_blackbody(cpl_vector *, cpl_unit, - const cpl_vector *, cpl_unit, double); +cpl_error_code cpl_photom_fill_blackbody(cpl_vector *, + cpl_unit, + const cpl_vector *, + cpl_unit, + double); CPL_END_DECLS #endif - diff -Nru cpl-7.1.4+ds/cpldrs/cpl_phys_const.h cpl-7.2.2+ds/cpldrs/cpl_phys_const.h --- cpl-7.1.4+ds/cpldrs/cpl_phys_const.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cpldrs/cpl_phys_const.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -34,7 +34,7 @@ */ /* Planck constant [Js] */ -#define CPL_PHYS_H 6.6260693E-34 +#define CPL_PHYS_H 6.6260693E-34 /* Boltzmann constant [J/K] */ #define CPL_PHYS_K 1.3806505E-23 @@ -45,27 +45,28 @@ /* The speed of light in vacuum [m/s] */ #define CPL_PHYS_C 299792458.0 -enum _cpl_unit_ { - CPL_UNIT_LESS = 1, /* Dimension-less */ - CPL_UNIT_RADIAN = 2, /* [radian] */ - CPL_UNIT_LENGTH = 3, /* [m] */ - CPL_UNIT_TIME = 5, /* [s] */ - CPL_UNIT_PERLENGTH = 7, /* [1/m] */ - CPL_UNIT_FREQUENCY = 11, /* [1/s] */ - CPL_UNIT_MASS = 13, /* [kg] */ +enum _cpl_unit_ +{ + CPL_UNIT_LESS = 1, /* Dimension-less */ + CPL_UNIT_RADIAN = 2, /* [radian] */ + CPL_UNIT_LENGTH = 3, /* [m] */ + CPL_UNIT_TIME = 5, /* [s] */ + CPL_UNIT_PERLENGTH = 7, /* [1/m] */ + CPL_UNIT_FREQUENCY = 11, /* [1/s] */ + CPL_UNIT_MASS = 13, /* [kg] */ /* Derived quantities */ - CPL_UNIT_ACCELERATION /* [m/s^2]*/ - = CPL_UNIT_LENGTH * CPL_UNIT_FREQUENCY * CPL_UNIT_FREQUENCY, - CPL_UNIT_FORCE /* [N] = [kg * m/s^2]*/ - = CPL_UNIT_MASS * CPL_UNIT_ACCELERATION, - CPL_UNIT_ENERGY /* [J] = [m * N] */ + CPL_UNIT_ACCELERATION /* [m/s^2]*/ + = CPL_UNIT_LENGTH * CPL_UNIT_FREQUENCY * CPL_UNIT_FREQUENCY, + CPL_UNIT_FORCE /* [N] = [kg * m/s^2]*/ + = CPL_UNIT_MASS * CPL_UNIT_ACCELERATION, + CPL_UNIT_ENERGY /* [J] = [m * N] */ = CPL_UNIT_LENGTH * CPL_UNIT_FORCE, - CPL_UNIT_PHOTONRADIANCE /* [ radian/s/m^3] */ - = CPL_UNIT_RADIAN * CPL_UNIT_FREQUENCY * CPL_UNIT_PERLENGTH - * CPL_UNIT_PERLENGTH * CPL_UNIT_PERLENGTH, - CPL_UNIT_ENERGYRADIANCE /* [J*radian/s/m^3] */ + CPL_UNIT_PHOTONRADIANCE /* [ radian/s/m^3] */ + = CPL_UNIT_RADIAN * CPL_UNIT_FREQUENCY * CPL_UNIT_PERLENGTH * + CPL_UNIT_PERLENGTH * CPL_UNIT_PERLENGTH, + CPL_UNIT_ENERGYRADIANCE /* [J*radian/s/m^3] */ = CPL_UNIT_ENERGY * CPL_UNIT_PHOTONRADIANCE }; @@ -74,4 +75,3 @@ CPL_END_DECLS #endif - diff -Nru cpl-7.1.4+ds/cpldrs/cpl_ppm.c cpl-7.2.2+ds/cpldrs/cpl_ppm.c --- cpl-7.1.4+ds/cpldrs/cpl_ppm.c 2021-05-07 12:09:09.000000000 +0000 +++ cpl-7.2.2+ds/cpldrs/cpl_ppm.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -35,6 +35,7 @@ #include #include #include +#include "cpl_matrix_impl.h" /** * @defgroup cpl_ppm Point pattern matching module @@ -45,6 +46,8 @@ * @endcode */ +/**@{*/ + /* The "triangle" is actually the element 2D pattern made of 3 points. It carries its coordinates in the parameter space of similar triangles, and an identifier of the three points composing it. @@ -53,19 +56,19 @@ typedef struct _triangle { - double ratsq; /* (Rmin/Rmax)^2 */ - double dratsq; /* Error */ + double ratsq; /* (Rmin/Rmax)^2 */ + double dratsq; /* Error */ - double theta; /* Angle min - Angle max in [0; 2pi[ */ - double dtheta; /* Error */ + double theta; /* Angle min - Angle max in [0; 2pi[ */ + double dtheta; /* Error */ - double xref, yref; /* Reference point */ - double xmin, ymin; /* Nearest point */ - double xmax, ymax; /* Farthest point */ - - int id_ref; /* Identifier of reference point */ - int id_min; /* Identifier of nearest point */ - int id_max; /* Identifier of farthest point */ + double xref, yref; /* Reference point */ + double xmin, ymin; /* Nearest point */ + double xmax, ymax; /* Farthest point */ + + int id_ref; /* Identifier of reference point */ + int id_min; /* Identifier of nearest point */ + int id_max; /* Identifier of farthest point */ } triangle; @@ -73,15 +76,17 @@ typedef struct _triangles { - int n; + int n; triangle **t; } triangles; -static cpl_array * -find_all_matches(const cpl_matrix *, const cpl_matrix *, - double, const cpl_polynomial *, - const cpl_polynomial *, - cpl_matrix **, cpl_matrix **) CPL_ATTR_ALLOC; +static cpl_array *find_all_matches(const cpl_matrix *, + const cpl_matrix *, + double, + const cpl_polynomial *, + const cpl_polynomial *, + cpl_matrix **, + cpl_matrix **) CPL_ATTR_ALLOC; static cpl_array * find_matches(const triangles *, const triangles *, int) CPL_ATTR_ALLOC; @@ -91,11 +96,16 @@ static triangles * triangles_from_points(const cpl_matrix *, int, double) CPL_ATTR_ALLOC; -static triangle * -triangle_new(double, double, double, double, double, double, - double, int, int, int) CPL_ATTR_ALLOC; - -/**@{*/ +static triangle *triangle_new(double, + double, + double, + double, + double, + double, + double, + int, + int, + int) CPL_ATTR_ALLOC; /** * @brief @@ -164,111 +174,110 @@ * be set. */ -cpl_bivector *cpl_ppm_match_positions(const cpl_vector *peaks, - const cpl_vector *lines, - double min_disp, double max_disp, - double tolerance, cpl_array **seq_peaks, - cpl_array **seq_lines) -{ - - int i, j, k, l; - cpl_size nlint, npint; - int minpos; - double min; - double lratio, pratio; - double lo_start, lo_end, hi_start, hi_end, denom; - double disp = 0.0; - double variation, prev_variation; - int max, maxpos, minl, mink; - int ambiguous; - int npeaks_lo, npeaks_hi; - int *peak_lo; - int *peak_hi; - int **ident; - int *nident; - int *lident; - - const double *peak; - const double *line; - cpl_size npeaks, nlines; - - double *xpos; - double *lambda; - int *ilambda; - double *tmp_xpos; - double *tmp_lambda; - int *tmp_ilambda; - int *flag; - int n = 0; - int nn; - int nseq = 0; - int gap; - int *seq_length; - int found; - - - if (seq_lines || seq_peaks) { - cpl_error_set(cpl_func, CPL_ERROR_UNSUPPORTED_MODE); - return NULL; - } +cpl_bivector * +cpl_ppm_match_positions(const cpl_vector *peaks, + const cpl_vector *lines, + double min_disp, + double max_disp, + double tolerance, + cpl_array **seq_peaks, + cpl_array **seq_lines) +{ + int i, j, k, l; + cpl_size nlint, npint; + int minpos; + double min; + double lratio, pratio; + double lo_start, lo_end, hi_start, hi_end, denom; + double disp = 0.0; + double variation, prev_variation; + int max, maxpos, minl, mink; + int ambiguous; + int npeaks_lo, npeaks_hi; + int *peak_lo; + int *peak_hi; + int **ident; + int *nident; + int *lident; + + const double *peak; + const double *line; + cpl_size npeaks, nlines; + + double *xpos; + double *lambda; + int *ilambda; + double *tmp_xpos; + double *tmp_lambda; + int *tmp_ilambda; + int *flag; + int n = 0; + int nn; + int nseq = 0; + int gap; + int *seq_length; + int found; + + + if (seq_lines || seq_peaks) { + cpl_error_set(cpl_func, CPL_ERROR_UNSUPPORTED_MODE); + return NULL; + } + + peak = cpl_vector_get_data_const(peaks); + npeaks = cpl_vector_get_size(peaks); + line = cpl_vector_get_data_const(lines); + nlines = cpl_vector_get_size(lines); - peak = cpl_vector_get_data_const(peaks); - npeaks = cpl_vector_get_size(peaks); - line = cpl_vector_get_data_const(lines); - nlines = cpl_vector_get_size(lines); - - if (npeaks < 4) - return NULL; - - peak_lo = cpl_malloc((size_t)npeaks * sizeof(int)); - peak_hi = cpl_malloc((size_t)npeaks * sizeof(int)); - nident = cpl_calloc((size_t)npeaks, sizeof(int)); - lident = cpl_calloc((size_t)nlines, sizeof(int)); - xpos = cpl_calloc((size_t)npeaks, sizeof(double)); - lambda = cpl_calloc((size_t)npeaks, sizeof(double)); - ilambda = cpl_calloc((size_t)npeaks, sizeof(int)); - tmp_xpos = cpl_calloc((size_t)npeaks, sizeof(double)); - tmp_lambda = cpl_calloc((size_t)npeaks, sizeof(double)); - tmp_ilambda = cpl_calloc((size_t)npeaks, sizeof(int)); - flag = cpl_calloc((size_t)npeaks, sizeof(int)); - seq_length = cpl_calloc((size_t)npeaks, sizeof(int)); - ident = cpl_malloc((size_t)npeaks * sizeof(int *)); - for (i = 0; i < npeaks; i++) - ident[i] = cpl_malloc(3 * (size_t)npeaks * sizeof(int)); + if (npeaks < 4) + return NULL; - /* + peak_lo = cpl_malloc((size_t)npeaks * sizeof(int)); + peak_hi = cpl_malloc((size_t)npeaks * sizeof(int)); + nident = cpl_calloc((size_t)npeaks, sizeof(int)); + lident = cpl_calloc((size_t)nlines, sizeof(int)); + xpos = cpl_calloc((size_t)npeaks, sizeof(double)); + lambda = cpl_calloc((size_t)npeaks, sizeof(double)); + ilambda = cpl_calloc((size_t)npeaks, sizeof(int)); + tmp_xpos = cpl_calloc((size_t)npeaks, sizeof(double)); + tmp_lambda = cpl_calloc((size_t)npeaks, sizeof(double)); + tmp_ilambda = cpl_calloc((size_t)npeaks, sizeof(int)); + flag = cpl_calloc((size_t)npeaks, sizeof(int)); + seq_length = cpl_calloc((size_t)npeaks, sizeof(int)); + ident = cpl_malloc((size_t)npeaks * sizeof(int *)); + for (i = 0; i < npeaks; i++) + ident[i] = cpl_malloc(3 * (size_t)npeaks * sizeof(int)); + + /* * This is just the number of intervals - one less than the number * of points (catalog wavelengths, or detected peaks). */ - nlint = nlines - 1; - npint = npeaks - 1; + nlint = nlines - 1; + npint = npeaks - 1; - /* + /* * Here the big loops on catalog lines begins. */ - for (i = 1; i < nlint; i++) { - - - /* + for (i = 1; i < nlint; i++) { + /* * For each catalog wavelength I take the previous and the next one, * and compute the ratio of the corresponding wavelength intervals. * This ratio will be compared to all the ratios obtained doing the * same with all the detected peaks positions. */ - lratio = (line[i+1] - line[i]) / (line[i] - line[i-1]); + lratio = (line[i + 1] - line[i]) / (line[i] - line[i - 1]); - /* + /* * Here the loop on detected peaks positions begins. */ - for (j = 1; j < npint; j++) { - - /* + for (j = 1; j < npint; j++) { + /* * Not all peaks are used for computing ratios: just the ones * that are compatible with the expected spectral dispersion * are taken into consideration. Therefore, I define the pixel @@ -279,37 +288,37 @@ * with the next. */ - lo_start = peak[j] - (line[i] - line[i-1]) / min_disp; - lo_end = peak[j] - (line[i] - line[i-1]) / max_disp; - hi_start = peak[j] + (line[i+1] - line[i]) / max_disp; - hi_end = peak[j] + (line[i+1] - line[i]) / min_disp; - - for (npeaks_lo = 0, k = 0; k < npeaks; k++) { - if (peak[k] > lo_end) - break; - if (peak[k] > lo_start) { - peak_lo[npeaks_lo] = k; - ++npeaks_lo; - } - } + lo_start = peak[j] - (line[i] - line[i - 1]) / min_disp; + lo_end = peak[j] - (line[i] - line[i - 1]) / max_disp; + hi_start = peak[j] + (line[i + 1] - line[i]) / max_disp; + hi_end = peak[j] + (line[i + 1] - line[i]) / min_disp; + + for (npeaks_lo = 0, k = 0; k < npeaks; k++) { + if (peak[k] > lo_end) + break; + if (peak[k] > lo_start) { + peak_lo[npeaks_lo] = k; + ++npeaks_lo; + } + } - if (npeaks_lo == 0) - continue; + if (npeaks_lo == 0) + continue; - for (npeaks_hi = 0, k = 0; k < npeaks; k++) { - if (peak[k] > hi_end) - break; - if (peak[k] > hi_start) { - peak_hi[npeaks_hi] = k; - ++npeaks_hi; - } - } + for (npeaks_hi = 0, k = 0; k < npeaks; k++) { + if (peak[k] > hi_end) + break; + if (peak[k] > hi_start) { + peak_hi[npeaks_hi] = k; + ++npeaks_hi; + } + } - if (npeaks_hi == 0) - continue; + if (npeaks_hi == 0) + continue; - /* + /* * Now I have all peaks that may help for a local identification. * peak_lo[k] is the sequence number of the k-th peak of the lower * interval; peak_hi[l] is the sequence number of the l-th peak of @@ -317,22 +326,21 @@ * current peak (second big loop). */ - prev_variation = 1000.0; - minl = mink = 0; - - for (k = 0; k < npeaks_lo; k++) { - denom = peak[j] - peak[peak_lo[k]]; - for (l = 0; l < npeaks_hi; l++) { + prev_variation = 1000.0; + minl = mink = 0; - /* + for (k = 0; k < npeaks_lo; k++) { + denom = peak[j] - peak[peak_lo[k]]; + for (l = 0; l < npeaks_hi; l++) { + /* * For any pair of peaks - one from the lower and the other * from the higher interval - I compute the same ratio that * was computed with the current line catalog wavelength. */ - pratio = (peak[peak_hi[l]] - peak[j]) / denom; + pratio = (peak[peak_hi[l]] - peak[j]) / denom; - /* + /* * If the two ratios are compatible within the specified * tolerance, we have a preliminary identification. This * will be marked in the matrix ident[][], where the first @@ -343,114 +351,108 @@ * tolerance, the closest to the expected ratio is selected. */ - variation = fabs(lratio-pratio) / pratio; + variation = fabs(lratio - pratio) / pratio; - if (variation < tolerance) { - if (variation < prev_variation) { - prev_variation = variation; - minl = l; - mink = k; + if (variation < tolerance) { + if (variation < prev_variation) { + prev_variation = variation; + minl = l; + mink = k; + } + } + } } - } - } - } - if (prev_variation < tolerance) { - ident[j][nident[j]] = i; - ident[peak_hi[minl]][nident[peak_hi[minl]]] = i + 1; - ident[peak_lo[mink]][nident[peak_lo[mink]]] = i - 1; - ++nident[j]; - ++nident[peak_hi[minl]]; - ++nident[peak_lo[mink]]; - } - } /* End loop on positions */ - } /* End loop on lines */ + if (prev_variation < tolerance) { + ident[j][nident[j]] = i; + ident[peak_hi[minl]][nident[peak_hi[minl]]] = i + 1; + ident[peak_lo[mink]][nident[peak_lo[mink]]] = i - 1; + ++nident[j]; + ++nident[peak_hi[minl]]; + ++nident[peak_lo[mink]]; + } + } /* End loop on positions */ + } /* End loop on lines */ - /* + /* * At this point I have filled the ident matrix with all my preliminary * identifications. Ambiguous identifications must be eliminated. */ - for (i = 0; i < npeaks; i++) { - - - /* + for (i = 0; i < npeaks; i++) { + /* * I don't take into consideration peaks that were never identified. * They are likely contaminations, or emission lines that were not * listed in the input wavelength catalog. */ - if (nident[i] > 1) { - - - /* + if (nident[i] > 1) { + /* * Initialise the histogram of wavelengths assigned to the i-th peak. */ - for (j = 0; j < nlines; j++) - lident[j] = 0; + for (j = 0; j < nlines; j++) + lident[j] = 0; - /* + /* * Count how many times each catalog wavelength was assigned * to the i-th peak. */ - for (j = 0; j < nident[i]; j++) - ++lident[ident[i][j]]; + for (j = 0; j < nident[i]; j++) + ++lident[ident[i][j]]; - /* + /* * What wavelength was most frequently assigned to the i-th peak? */ - max = 0; - maxpos = 0; - for (j = 0; j < nlines; j++) { - if (max < lident[j]) { - max = lident[j]; - maxpos = j; - } - } + max = 0; + maxpos = 0; + for (j = 0; j < nlines; j++) { + if (max < lident[j]) { + max = lident[j]; + maxpos = j; + } + } - /* + /* * Were there other wavelengths assigned with the same frequency? * This would be the case of an ambiguous identification. It is * safer to reject this peak... */ - ambiguous = 0; + ambiguous = 0; - for (k = maxpos + 1; k < nlines; k++) { - if (lident[k] == max) { - ambiguous = 1; - break; - } - } + for (k = maxpos + 1; k < nlines; k++) { + if (lident[k] == max) { + ambiguous = 1; + break; + } + } - if (ambiguous) - continue; + if (ambiguous) + continue; - /* + /* * Otherwise, I assign to the i-th peak the wavelength that was * most often assigned to it. */ - tmp_xpos[n] = peak[i]; - tmp_lambda[n] = line[maxpos]; - tmp_ilambda[n] = maxpos; - - ++n; + tmp_xpos[n] = peak[i]; + tmp_lambda[n] = line[maxpos]; + tmp_ilambda[n] = maxpos; + ++n; + } } - } - - /* + /* * Check on identified peaks. Contaminations from other spectra might * be present and should be excluded: this type of contamination * consists of peaks that have been _correctly_ identified! The non- @@ -462,118 +464,118 @@ * is ignored). */ - if (n > 1) { - nn = 0; /* Number of peaks in the list of sequences */ - nseq = 0; /* Current sequence */ - for (k = 0; k < n; k++) { - if (flag[k] == 0) { /* Was peak k already assigned to a sequence? */ - flag[k] = 1; - xpos[nn] = tmp_xpos[k]; /* Begin the nseq-th sequence */ - lambda[nn] = tmp_lambda[k]; - ilambda[nn] = tmp_ilambda[k]; - ++seq_length[nseq]; - ++nn; + if (n > 1) { + nn = 0; /* Number of peaks in the list of sequences */ + nseq = 0; /* Current sequence */ + for (k = 0; k < n; k++) { + if (flag[k] == 0) { /* Was peak k already assigned to a sequence? */ + flag[k] = 1; + xpos[nn] = tmp_xpos[k]; /* Begin the nseq-th sequence */ + lambda[nn] = tmp_lambda[k]; + ilambda[nn] = tmp_ilambda[k]; + ++seq_length[nseq]; + ++nn; - /* + /* * Now look for all the following peaks that are compatible * with the expected spectral dispersion, and add them in * sequence to xpos. Note that missing peaks are not a problem... */ - - i = k; - while (i < n - 1) { - found = 0; - for (j = i + 1; j < n; j++) { - if (flag[j] == 0) { - disp = (tmp_lambda[j] - tmp_lambda[i]) - / (tmp_xpos[j] - tmp_xpos[i]); - if (disp >= min_disp && disp <= max_disp) { - flag[j] = 1; - xpos[nn] = tmp_xpos[j]; - lambda[nn] = tmp_lambda[j]; - ilambda[nn] = tmp_ilambda[j]; - ++seq_length[nseq]; - ++nn; - i = j; - found = 1; - break; - } - } - } - if (!found) - break; - } - /* + i = k; + while (i < n - 1) { + found = 0; + for (j = i + 1; j < n; j++) { + if (flag[j] == 0) { + disp = (tmp_lambda[j] - tmp_lambda[i]) / + (tmp_xpos[j] - tmp_xpos[i]); + if (disp >= min_disp && disp <= max_disp) { + flag[j] = 1; + xpos[nn] = tmp_xpos[j]; + lambda[nn] = tmp_lambda[j]; + ilambda[nn] = tmp_ilambda[j]; + ++seq_length[nseq]; + ++nn; + i = j; + found = 1; + break; + } + } + } + if (!found) + break; + } + + /* * Current sequence is completed: begin new sequence on the * excluded peaks, starting the loop on peaks again. */ - ++nseq; - k = 0; - } - } + ++nseq; + k = 0; + } + } - /* + /* * Find the longest sequence of self-consistent peaks. */ - max = 0; - maxpos = 0; - for (i = 0; i < nseq; i++) { - if (seq_length[i] > max) { - max = seq_length[i]; - maxpos = i; - } - } + max = 0; + maxpos = 0; + for (i = 0; i < nseq; i++) { + if (seq_length[i] > max) { + max = seq_length[i]; + maxpos = i; + } + } - /* + /* * Find where this sequence starts in the whole peak position * storage. */ - nn = 0; - for (i = 0; i < maxpos; i++) - nn += seq_length[i]; + nn = 0; + for (i = 0; i < maxpos; i++) + nn += seq_length[i]; - /* + /* * Move the longest sequence at the beginning of the returned lists */ - n = max; - for (i = 0; i < n; i++, nn++) { - xpos[i] = xpos[nn]; - lambda[i] = lambda[nn]; - ilambda[i] = ilambda[nn]; - } + n = max; + for (i = 0; i < n; i++, nn++) { + xpos[i] = xpos[nn]; + lambda[i] = lambda[nn]; + ilambda[i] = ilambda[nn]; + } - /* + /* * Are some wavelengths missing? Recover them. */ - for (i = 1; i < n; i++) { - gap = ilambda[i] - ilambda[i-1]; - for (j = 1; j < gap; j++) { - - if (j == 1) { - - /* + for (i = 1; i < n; i++) { + gap = ilambda[i] - ilambda[i - 1]; + for (j = 1; j < gap; j++) { + if (j == 1) { + /* * Determine the local dispersion from the current pair of peaks */ - - disp = (lambda[i] - lambda[i-1]) / (xpos[i] - xpos[i-1]); - } - /* + disp = + (lambda[i] - lambda[i - 1]) / (xpos[i] - xpos[i - 1]); + } + + /* * With this, find the expected position of the missing * peak by linear interpolation. */ - hi_start = xpos[i-1] + (line[ilambda[i-1] + j] - lambda[i-1]) / disp; + hi_start = xpos[i - 1] + + (line[ilambda[i - 1] + j] - lambda[i - 1]) / disp; - /* + /* * Is there a peak at that position? Here a peak from the * original list is searched, that is closer than 2 pixels * to the expected position. If it is found, insert it at @@ -585,59 +587,60 @@ * the following missing peaks in this interval. */ - found = 0; - for (k = 0; k < npeaks; k++) { - if (fabs(peak[k] - hi_start) < 2) { - for (l = n; l > i; l--) { - xpos[l] = xpos[l-1]; - lambda[l] = lambda[l-1]; - ilambda[l] = ilambda[l-1]; + found = 0; + for (k = 0; k < npeaks; k++) { + if (fabs(peak[k] - hi_start) < 2) { + for (l = n; l > i; l--) { + xpos[l] = xpos[l - 1]; + lambda[l] = lambda[l - 1]; + ilambda[l] = ilambda[l - 1]; + } + xpos[i] = peak[k]; + lambda[i] = line[ilambda[i - 1] + j]; + ilambda[i] = ilambda[i - 1] + j; + ++n; + found = 1; + break; + } + } + if (found) + break; } - xpos[i] = peak[k]; - lambda[i] = line[ilambda[i-1] + j]; - ilambda[i] = ilambda[i-1] + j; - ++n; - found = 1; - break; - } } - if (found) - break; - } - } - /* + /* * Try to extrapolate forward */ - found = 1; - - if (n > 0) { - while (ilambda[n-1] < nlines - 1 && found) { + found = 1; - /* + if (n > 0) { + while (ilambda[n - 1] < nlines - 1 && found) { + /* * Determine the local dispersion from the last pair of * identified peaks */ - if (n > 1) - disp = (lambda[n-1] - lambda[n-2]) / (xpos[n-1] - xpos[n-2]); - else - disp = 0.0; + if (n > 1) + disp = (lambda[n - 1] - lambda[n - 2]) / + (xpos[n - 1] - xpos[n - 2]); + else + disp = 0.0; - if (disp > max_disp || disp < min_disp) - break; + if (disp > max_disp || disp < min_disp) + break; - /* + /* * With this, find the expected position of the missing * peak by linear interpolation. */ - hi_start = xpos[n-1] + (line[ilambda[n-1] + 1] - lambda[n-1]) / disp; + hi_start = xpos[n - 1] + + (line[ilambda[n - 1] + 1] - lambda[n - 1]) / disp; - /* + /* * Is there a peak at that position? Here a peak from the * original list is searched, that is closer than 6 pixels * to the expected position. If it is found, insert it at @@ -645,52 +648,51 @@ * found, leave the loop. */ - found = 0; - min = fabs(peak[0] - hi_start); - minpos = 0; - for (k = 1; k < npeaks; k++) { - if (min > fabs(peak[k] - hi_start)) { - min = fabs(peak[k] - hi_start); - minpos = k; + found = 0; + min = fabs(peak[0] - hi_start); + minpos = 0; + for (k = 1; k < npeaks; k++) { + if (min > fabs(peak[k] - hi_start)) { + min = fabs(peak[k] - hi_start); + minpos = k; + } + } + if (min < 6.0 && fabs(peak[minpos] - xpos[n - 1]) > 1.0) { + xpos[n] = peak[minpos]; + lambda[n] = line[ilambda[n - 1] + 1]; + ilambda[n] = ilambda[n - 1] + 1; + ++n; + found = 1; + } } - } - if (min < 6.0 && fabs(peak[minpos] - xpos[n-1]) > 1.0) { - xpos[n] = peak[minpos]; - lambda[n] = line[ilambda[n-1] + 1]; - ilambda[n] = ilambda[n-1] + 1; - ++n; - found = 1; - } } - } - /* + /* * Try to extrapolate backward */ - found = 1; - while (ilambda[0] > 0 && found) { - - /* + found = 1; + while (ilambda[0] > 0 && found) { + /* * Determine the local dispersion from the first pair of * identified peaks */ - disp = (lambda[1] - lambda[0]) / (xpos[1] - xpos[0]); + disp = (lambda[1] - lambda[0]) / (xpos[1] - xpos[0]); - if (disp > max_disp || disp < min_disp) - break; + if (disp > max_disp || disp < min_disp) + break; - /* + /* * With this, find the expected position of the missing * peak by linear interpolation. */ - hi_start = xpos[0] - (lambda[0] - line[ilambda[0] - 1]) / disp; + hi_start = xpos[0] - (lambda[0] - line[ilambda[0] - 1]) / disp; - /* + /* * Is there a peak at that position? Here a peak from the * original list is searched, that is closer than 6 pixels * to the expected position. If it is found, insert it at @@ -698,37 +700,37 @@ * found, leave the loop. */ - found = 0; - min = fabs(peak[0] - hi_start); - minpos = 0; - for (k = 1; k < npeaks; k++) { - if (min > fabs(peak[k] - hi_start)) { - min = fabs(peak[k] - hi_start); - minpos = k; - } - } - if (min < 6.0 && fabs(peak[minpos] - xpos[0]) > 1.0) { - for (j = n; j > 0; j--) { - xpos[j] = xpos[j-1]; - lambda[j] = lambda[j-1]; - ilambda[j] = ilambda[j-1]; + found = 0; + min = fabs(peak[0] - hi_start); + minpos = 0; + for (k = 1; k < npeaks; k++) { + if (min > fabs(peak[k] - hi_start)) { + min = fabs(peak[k] - hi_start); + minpos = k; + } + } + if (min < 6.0 && fabs(peak[minpos] - xpos[0]) > 1.0) { + for (j = n; j > 0; j--) { + xpos[j] = xpos[j - 1]; + lambda[j] = lambda[j - 1]; + ilambda[j] = ilambda[j - 1]; + } + xpos[0] = peak[minpos]; + lambda[0] = line[ilambda[0] - 1]; + ilambda[0] = ilambda[0] - 1; + ++n; + found = 1; + } } - xpos[0] = peak[minpos]; - lambda[0] = line[ilambda[0] - 1]; - ilambda[0] = ilambda[0] - 1; - ++n; - found = 1; - } } - } - /* + /* * At this point all peaks are processed. Free memory, and return * the result. */ -/************************************************+ + /************************************************+ for (i = 0; i < npeaks; i++) { printf("Peak %d:\n ", i); for (j = 0; j < nident[i]; j++) @@ -741,28 +743,28 @@ for (i = 0; i < n; i++) printf("%.2f, %.2f\n", xpos[i], lambda[i]); +************************************************/ - for (i = 0; i < npeaks; i++) - cpl_free(ident[i]); - cpl_free(ident); - cpl_free(nident); - cpl_free(lident); - cpl_free(ilambda); - cpl_free(tmp_xpos); - cpl_free(tmp_lambda); - cpl_free(tmp_ilambda); - cpl_free(peak_lo); - cpl_free(flag); - cpl_free(seq_length); - cpl_free(peak_hi); - - if (n == 0) { - cpl_free(xpos); - cpl_free(lambda); - return NULL; - } + for (i = 0; i < npeaks; i++) + cpl_free(ident[i]); + cpl_free(ident); + cpl_free(nident); + cpl_free(lident); + cpl_free(ilambda); + cpl_free(tmp_xpos); + cpl_free(tmp_lambda); + cpl_free(tmp_ilambda); + cpl_free(peak_lo); + cpl_free(flag); + cpl_free(seq_length); + cpl_free(peak_hi); + + if (n == 0) { + cpl_free(xpos); + cpl_free(lambda); + return NULL; + } - return cpl_bivector_wrap_vectors(cpl_vector_wrap(n, xpos), - cpl_vector_wrap(n, lambda)); + return cpl_bivector_wrap_vectors(cpl_vector_wrap(n, xpos), + cpl_vector_wrap(n, lambda)); } /* End of function for 1D point pattern matching */ @@ -773,7 +775,7 @@ /* This one subtracts y from x, with error propagation. */ -static double +static double double_subtract(double x, double dx, double y, double dy, double *error) { *error = hypot(dx, dy); @@ -782,15 +784,15 @@ /* This one divides x by y, with error propagation. */ -static double +static double double_divide(double x, double dx, double y, double dy, double *error) -{ - const double y2 = y*y; +{ + const double y2 = y * y; if (y2 > 0.0) { - *error = sqrt(( dx*dx + dy*dy * x*x / (y2) ) / (y2)); - return x/y; + *error = sqrt((dx * dx + dy * dy * x * x / (y2)) / (y2)); + return x / y; } *error = 0.0; @@ -800,22 +802,20 @@ /* This one finds angle of the direction defined by point (x,y), with error propagation. */ -static double +static double double_atan2(double y, double dy, double x, double dx, double *error) { - const double x2 = x*x; - const double y2 = y*y; + const double x2 = x * x; + const double y2 = y * y; if (x2 > 0.0 || y2 > 0.0) { - /* * Using error propagation formula and d(atan(u))/du = 1/(1+u^2) */ - *error = sqrt((dy*dy*x2 + dx*dx*y2) / ((x2 + y2)*(x2 + y2))); + *error = sqrt((dy * dy * x2 + dx * dx * y2) / ((x2 + y2) * (x2 + y2))); return atan2(y, x); - } *error = 0.0; @@ -824,30 +824,38 @@ /* This one returns the square of the distance between two points */ -static double +static double point_distsq(double xa, double ya, double xb, double yb) { - return ((xa - xb)*(xa - xb) + (ya - yb)*(ya - yb)); + return ((xa - xb) * (xa - xb) + (ya - yb) * (ya - yb)); } /* This constructs a triangle from three points, propagates errors, and keeps the points identifiers. */ static triangle * -triangle_new(double xa, double ya, double xb, double yb, double xc, double yc, - double error, int ida, int idb, int idc) +triangle_new(double xa, + double ya, + double xb, + double yb, + double xc, + double yc, + double error, + int ida, + int idb, + int idc) { const double r1 = point_distsq(xa, ya, xb, yb); const double r2 = point_distsq(xa, ya, xc, yc); - const double dr1 = sqrt(8*error*error*r1); - const double dr2 = sqrt(8*error*error*r2); + const double dr1 = sqrt(8 * error * error * r1); + const double dr2 = sqrt(8 * error * error * r2); - double dt1, dt2; + double dt1, dt2; - const double t1 = double_atan2(ya - yb, CPL_MATH_SQRT2 * error, - xa - xb, CPL_MATH_SQRT2 * error, &dt1); - const double t2 = double_atan2(ya - yc, CPL_MATH_SQRT2 * error, - xa - xc, CPL_MATH_SQRT2 * error, &dt2); + const double t1 = double_atan2(ya - yb, CPL_MATH_SQRT2 * error, xa - xb, + CPL_MATH_SQRT2 * error, &dt1); + const double t2 = double_atan2(ya - yc, CPL_MATH_SQRT2 * error, xa - xc, + CPL_MATH_SQRT2 * error, &dt2); triangle *t = cpl_calloc(1, sizeof(triangle)); @@ -856,29 +864,30 @@ t->id_ref = ida; if (r1 < r2) { - t->ratsq = double_divide(r1, dr1, r2, dr2, &t->dratsq); - t->theta = double_subtract(t1, dt1, t2, dt2, &t->dtheta); - t->xmin = xb; - t->ymin = yb; + t->ratsq = double_divide(r1, dr1, r2, dr2, &t->dratsq); + t->theta = double_subtract(t1, dt1, t2, dt2, &t->dtheta); + t->xmin = xb; + t->ymin = yb; t->id_min = idb; - t->xmax = xc; - t->ymax = yc; + t->xmax = xc; + t->ymax = yc; t->id_max = idc; - } else { - t->ratsq = double_divide(r2, dr2, r1, dr1, &t->dratsq); - t->theta = double_subtract(t2, dt2, t1, dt1, &t->dtheta); - t->xmin = xc; - t->ymin = yc; + } + else { + t->ratsq = double_divide(r2, dr2, r1, dr1, &t->dratsq); + t->theta = double_subtract(t2, dt2, t1, dt1, &t->dtheta); + t->xmin = xc; + t->ymin = yc; t->id_min = idc; - t->xmax = xb; - t->ymax = yb; + t->xmax = xb; + t->ymax = yb; t->id_max = idb; } - while (t->theta < 0.0) + while (t->theta < 0.0) t->theta += CPL_MATH_2PI; - while (t->theta >= CPL_MATH_2PI) + while (t->theta >= CPL_MATH_2PI) t->theta -= CPL_MATH_2PI; return t; @@ -886,7 +895,7 @@ /* Triangle destructor */ -static void +static void triangle_delete(triangle **t) { cpl_free(*t); @@ -895,19 +904,21 @@ /* A constructor of arrays of triangles... */ -static triangles *triangles_new(int n) +static triangles * +triangles_new(int n) { triangles *t = cpl_calloc(1, sizeof(triangles)); t->t = cpl_calloc((size_t)n, sizeof(triangle *)); t->n = n; - + return t; } /* ... and this one destroys sets of triangles. */ -static void triangles_delete(triangles **t) +static void +triangles_delete(triangles **t) { while ((*t)->n--) triangle_delete((*t)->t + (*t)->n); @@ -916,7 +927,8 @@ *t = NULL; } -static void triangles_delete_holder(triangles **t) +static void +triangles_delete_holder(triangles **t) { cpl_free((*t)->t); cpl_free(*t); @@ -930,12 +942,12 @@ static triangles * triangles_from_points(const cpl_matrix *points, int n, double err) { - triangles *pattern; - const double *m = cpl_matrix_get_data_const(points); + triangles *pattern; + const double *m = cpl_matrix_get_data_const(points); const cpl_size nc = cpl_matrix_get_ncol(points); - const int nt = n*(n-1)*(n-2)/2; - int count; - int i, j, k; + const int nt = n * (n - 1) * (n - 2) / 2; + int count; + int i, j, k; cpl_msg_debug(cpl_func, "Evaluate %d triangles...", nt); @@ -943,10 +955,10 @@ pattern = triangles_new(nt); count = 0; - for (i = 0; i < n-2; i++) { - for (j = i+1; j < n-1; j++) { - for (k = j+1; k < n; k++) { - double x1, x2, x3, y1, y2, y3; + for (i = 0; i < n - 2; i++) { + for (j = i + 1; j < n - 1; j++) { + for (k = j + 1; k < n; k++) { + double x1, x2, x3, y1, y2, y3; /* * i, j, and k, are the matrix columns where the @@ -961,14 +973,14 @@ y2 = m[j + nc]; y3 = m[k + nc]; - pattern->t[count] = triangle_new(x1, y1, x2, y2, x3, y3, err, - i, j, k); + pattern->t[count] = + triangle_new(x1, y1, x2, y2, x3, y3, err, i, j, k); count++; - pattern->t[count] = triangle_new(x2, y2, x1, y1, x3, y3, err, - j, i, k); + pattern->t[count] = + triangle_new(x2, y2, x1, y1, x3, y3, err, j, i, k); count++; - pattern->t[count] = triangle_new(x3, y3, x2, y2, x1, y1, err, - k, j, i); + pattern->t[count] = + triangle_new(x3, y3, x2, y2, x1, y1, err, k, j, i); count++; } } @@ -981,23 +993,28 @@ * Difference between angles (in radians) in [0;pi] */ -static double +static double difference_of_angles(double a1, double a2) { - double d; /* NB: Handle a1 = 2pi - epsilon, a2 = epsilon => d = 2 epsilon */ - while (a1 < -CPL_MATH_PI) a1 += CPL_MATH_2PI; - while (a1 > CPL_MATH_PI) a1 -= CPL_MATH_2PI; - while (a2 < -CPL_MATH_PI) a2 += CPL_MATH_2PI; - while (a2 > CPL_MATH_PI) a2 -= CPL_MATH_2PI; + while (a1 < -CPL_MATH_PI) + a1 += CPL_MATH_2PI; + while (a1 > CPL_MATH_PI) + a1 -= CPL_MATH_2PI; + while (a2 < -CPL_MATH_PI) + a2 += CPL_MATH_2PI; + while (a2 > CPL_MATH_PI) + a2 -= CPL_MATH_2PI; d = a1 - a2; - /* NB: Handle a1 = pi - epsilon, a2 = epsilon - pi => d = 2 epsilon */ - while (d < -CPL_MATH_PI) d += CPL_MATH_2PI; - while (d > CPL_MATH_PI) d -= CPL_MATH_2PI; + /* NB: Handle a1 = pi - epsilon, a2 = epsilon - pi => d = 2 epsilon */ + while (d < -CPL_MATH_PI) + d += CPL_MATH_2PI; + while (d > CPL_MATH_PI) + d -= CPL_MATH_2PI; return fabs(d); } @@ -1014,17 +1031,18 @@ const double dtheta = difference_of_angles(t1->theta, t2->theta); /* in [0;pi] */ const double dr = t1->ratsq - t2->ratsq; - const double rr = t1->dratsq*t1->dratsq + t2->dratsq*t2->dratsq; - const double tt = (t1->dtheta*t1->dtheta + t2->dtheta*t2->dtheta) / 4; + const double rr = t1->dratsq * t1->dratsq + t2->dratsq * t2->dratsq; + const double tt = (t1->dtheta * t1->dtheta + t2->dtheta * t2->dtheta) / 4; const double dist = hypot(dr, dtheta / CPL_MATH_PI); if (error) { if (dist != 0.0) { const double dist_in_errs = - sqrt((dr * dr)/rr + (dtheta * dtheta)/tt); + sqrt((dr * dr) / rr + (dtheta * dtheta) / tt); *error = dist / dist_in_errs; - } else { + } + else { *error = 1.0; } } @@ -1036,13 +1054,13 @@ nearest_triangle(triangle *t, triangles *list) { triangle **pattern = list->t; - const int n = list->n; - triangle *nearest; + const int n = list->n; + triangle *nearest; + + double dist, mindist; + int i; - double dist, mindist; - int i; - mindist = distance_of_triangles(t, pattern[0], NULL); nearest = pattern[0]; for (i = 1; i < n; i++) { @@ -1061,13 +1079,13 @@ * Get scale ratio of matching triangles (t1 / t2) */ -static double +static double scaling_factor_of_triangles(const triangle *t1, const triangle *t2) { const double s1 = point_distsq(t1->xref, t1->yref, t1->xmax, t1->ymax); const double s2 = point_distsq(t2->xref, t2->yref, t2->xmax, t2->ymax); - return (s2 != 0.0) ? sqrt(s1/s2) : 0.0; + return (s2 != 0.0) ? sqrt(s1 / s2) : 0.0; } @@ -1075,16 +1093,16 @@ * Get angle of orientation between matching patterns */ -static double +static double angle_between_triangles(const triangle *t1, const triangle *t2) { const double a1 = atan2(t1->yref - t1->ymax, t1->xref - t1->xmax); const double a2 = atan2(t2->yref - t2->ymax, t2->xref - t2->xmax); double a = a1 - a2; - while (a >= CPL_MATH_2PI) + while (a >= CPL_MATH_2PI) a -= CPL_MATH_2PI; - while (a < 0) + while (a < 0) a += CPL_MATH_2PI; return a; @@ -1094,9 +1112,9 @@ static cpl_array * find_matches(const triangles *p_triangle, const triangles *n_triangle, int np) { - int nt = p_triangle->n; - int i; - int *data; + int nt = p_triangle->n; + int i; + int *data; cpl_array *matches = cpl_array_new(np, CPL_TYPE_INT); @@ -1116,36 +1134,37 @@ cpl_array_set_invalid(matches, i); return matches; - } /* Returns 0 on success */ static int -find_transform(const cpl_array *matches, const cpl_matrix *pattern, - const cpl_matrix *data, cpl_size degree, - cpl_polynomial *trans_x, cpl_polynomial *trans_y) -{ - - cpl_errorstate prev_state = cpl_errorstate_get(); - cpl_error_code error; - cpl_vector *xdpos; /* x positions on data */ - cpl_vector *ydpos; /* y positions on data */ - cpl_matrix *ppos; /* x,y positions on pattern */ - double *xd; - double *yd; - double *xp; - double *yp; - const cpl_size np = cpl_array_get_size(matches); - const cpl_size nvalid = np - cpl_array_count_invalid(matches); - int null; - int count = 0; - int i, j; +find_transform(const cpl_array *matches, + const cpl_matrix *pattern, + const cpl_matrix *data, + cpl_size degree, + cpl_polynomial *trans_x, + cpl_polynomial *trans_y) +{ + cpl_errorstate prev_state = cpl_errorstate_get(); + cpl_error_code error; + cpl_vector *xdpos; /* x positions on data */ + cpl_vector *ydpos; /* y positions on data */ + cpl_matrix *ppos; /* x,y positions on pattern */ + double *xd; + double *yd; + double *xp; + double *yp; + const cpl_size np = cpl_array_get_size(matches); + const cpl_size nvalid = np - cpl_array_count_invalid(matches); + int null; + int count = 0; + int i, j; xdpos = cpl_vector_new(nvalid); ydpos = cpl_vector_new(nvalid); - ppos = cpl_matrix_new(2, nvalid); + ppos = cpl_matrix_new(2, nvalid); xd = cpl_vector_get_data(xdpos); yd = cpl_vector_get_data(ydpos); @@ -1164,21 +1183,20 @@ count++; } - error = cpl_polynomial_fit(trans_x, ppos, NULL, xdpos, NULL, - CPL_FALSE, NULL, °ree); + error = cpl_polynomial_fit(trans_x, ppos, NULL, xdpos, NULL, CPL_FALSE, + NULL, °ree); if (error == CPL_ERROR_SINGULAR_MATRIX) { - /* * Try a 1-D fit */ - const cpl_size degrees[] = {degree, 0}; + const cpl_size degrees[] = { degree, 0 }; cpl_errorstate_set(prev_state); - error = cpl_polynomial_fit(trans_x, ppos, NULL, xdpos, NULL, - CPL_TRUE, NULL, degrees); + error = cpl_polynomial_fit(trans_x, ppos, NULL, xdpos, NULL, CPL_TRUE, + NULL, degrees); if (error == CPL_ERROR_SINGULAR_MATRIX) { cpl_errorstate_set(prev_state); @@ -1187,19 +1205,18 @@ } if (!error) { - error = cpl_polynomial_fit(trans_y, ppos, NULL, ydpos, NULL, - CPL_FALSE, NULL, °ree); + error = cpl_polynomial_fit(trans_y, ppos, NULL, ydpos, NULL, CPL_FALSE, + NULL, °ree); if (error == CPL_ERROR_SINGULAR_MATRIX) { - /* * Try a 1-D fit */ - const cpl_size degrees[] = {0, degree}; + const cpl_size degrees[] = { 0, degree }; cpl_errorstate_set(prev_state); - + error = cpl_polynomial_fit(trans_y, ppos, NULL, ydpos, NULL, CPL_TRUE, NULL, degrees); @@ -1220,23 +1237,22 @@ } return 0; - } static int nearest_point(double x, double y, const cpl_matrix *matrix) { - const cpl_size nc = cpl_matrix_get_ncol(matrix); - const double *data = cpl_matrix_get_data_const(matrix); - int minpos, i; - double min, value; + const cpl_size nc = cpl_matrix_get_ncol(matrix); + const double *data = cpl_matrix_get_data_const(matrix); + int minpos, i; + double min, value; minpos = 0; - min = point_distsq(x, y, data[0], data[nc]); + min = point_distsq(x, y, data[0], data[nc]); for (i = 1; i < nc; i++) { - value = point_distsq(x, y, data[i], data[i+nc]); + value = point_distsq(x, y, data[i], data[i + nc]); if (min > value) { min = value; minpos = i; @@ -1244,28 +1260,30 @@ } return minpos; - } static cpl_array * -find_all_matches(const cpl_matrix *pattern, const cpl_matrix *data, - double radius, const cpl_polynomial *trans_x, +find_all_matches(const cpl_matrix *pattern, + const cpl_matrix *data, + double radius, + const cpl_polynomial *trans_x, const cpl_polynomial *trans_y, - cpl_matrix **mpattern, cpl_matrix **mdata) + cpl_matrix **mpattern, + cpl_matrix **mdata) { - cpl_vector *point = cpl_vector_new(2); - double *p = cpl_vector_get_data(point); - const double *ddata = cpl_matrix_get_data_const(data); - const cpl_size dnc = cpl_matrix_get_ncol(data); - const double *dpatt = cpl_matrix_get_data_const(pattern); - const cpl_size pnc = cpl_matrix_get_ncol(pattern); - cpl_array *matches = cpl_array_new(pnc, CPL_TYPE_INT); - double exp_x, exp_y; - double *md; - double *mp; - cpl_size nvalid, count; - int null; - int i, j; + cpl_vector *point = cpl_vector_new(2); + double *p = cpl_vector_get_data(point); + const double *ddata = cpl_matrix_get_data_const(data); + const cpl_size dnc = cpl_matrix_get_ncol(data); + const double *dpatt = cpl_matrix_get_data_const(pattern); + const cpl_size pnc = cpl_matrix_get_ncol(pattern); + cpl_array *matches = cpl_array_new(pnc, CPL_TYPE_INT); + double exp_x, exp_y; + double *md; + double *mp; + cpl_size nvalid, count; + int null; + int i, j; radius *= radius; @@ -1288,9 +1306,9 @@ if (nvalid) { if (mpattern && mdata) { *mdata = cpl_matrix_new(2, nvalid); - md = cpl_matrix_get_data(*mdata); + md = cpl_matrix_get_data_(*mdata); *mpattern = cpl_matrix_new(2, nvalid); - mp = cpl_matrix_get_data(*mpattern); + mp = cpl_matrix_get_data_(*mpattern); count = 0; for (i = 0; i < pnc; i++) { j = cpl_array_get_int(matches, i, &null); @@ -1540,29 +1558,35 @@ */ cpl_array * -cpl_ppm_match_points(const cpl_matrix *data, cpl_size use_data, double err_data, - const cpl_matrix *pattern, cpl_size use_pattern, double - err_pattern, double tolerance, double radius, - cpl_matrix **mdata, cpl_matrix **mpattern, - double *lin_scale, double *lin_angle) -{ - - cpl_size nd, np; /* Number of points in data and pattern */ - triangles *d_triangle; /* Triangles from data points */ - triangles *p_triangle; /* Triangles from pattern points */ - triangles *n_triangle; /* Nearest d_triangles to each p_triangle */ - cpl_array *matches = NULL; - cpl_table *table = NULL; +cpl_ppm_match_points(const cpl_matrix *data, + cpl_size use_data, + double err_data, + const cpl_matrix *pattern, + cpl_size use_pattern, + double err_pattern, + double tolerance, + double radius, + cpl_matrix **mdata, + cpl_matrix **mpattern, + double *lin_scale, + double *lin_angle) +{ + cpl_size nd, np; /* Number of points in data and pattern */ + triangles *d_triangle; /* Triangles from data points */ + triangles *p_triangle; /* Triangles from pattern points */ + triangles *n_triangle; /* Nearest d_triangles to each p_triangle */ + cpl_array *matches = NULL; + cpl_table *table = NULL; cpl_polynomial *trans_x; cpl_polynomial *trans_y; - double err; - double *distance; - double *scale, median_scale; - double *angle, median_angle; - double *angle_s; - double *angle_c; - double scale_tolerance, angle_tolerance; - int i; + double err; + double *distance; + double *scale, median_scale; + double *angle, median_angle; + double *angle_s; + double *angle_c; + double scale_tolerance, angle_tolerance; + int i; if (mpattern) @@ -1582,8 +1606,8 @@ return NULL; } - nd = cpl_matrix_get_ncol(data); - np = cpl_matrix_get_ncol(pattern); + nd = cpl_matrix_get_ncol_(data); + np = cpl_matrix_get_ncol_(pattern); if (nd < 3 || np < 3 || use_data < 3 || use_pattern < 3) { cpl_error_set(cpl_func, CPL_ERROR_ILLEGAL_INPUT); @@ -1604,7 +1628,7 @@ return NULL; } -/* + /* if (use_data < use_pattern) { cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, "A pattern larger than data is not yet supported"); @@ -1656,28 +1680,26 @@ table = cpl_table_new(p_triangle->n); cpl_table_new_column(table, "distance", CPL_TYPE_DOUBLE); - cpl_table_fill_column_window_double(table, "distance", - 0, p_triangle->n, 0.0); + cpl_table_fill_column_window_double(table, "distance", 0, p_triangle->n, + 0.0); distance = cpl_table_get_data_double(table, "distance"); cpl_table_new_column(table, "scale", CPL_TYPE_DOUBLE); - cpl_table_fill_column_window_double(table, "scale", - 0, p_triangle->n, 0.0); + cpl_table_fill_column_window_double(table, "scale", 0, p_triangle->n, 0.0); scale = cpl_table_get_data_double(table, "scale"); cpl_table_new_column(table, "angle", CPL_TYPE_DOUBLE); - cpl_table_fill_column_window_double(table, "angle", - 0, p_triangle->n, 0.0); + cpl_table_fill_column_window_double(table, "angle", 0, p_triangle->n, 0.0); angle = cpl_table_get_data_double(table, "angle"); cpl_table_new_column(table, "angle_s", CPL_TYPE_DOUBLE); - cpl_table_fill_column_window_double(table, "angle_s", - 0, p_triangle->n, 0.0); + cpl_table_fill_column_window_double(table, "angle_s", 0, p_triangle->n, + 0.0); angle_s = cpl_table_get_data_double(table, "angle_s"); cpl_table_new_column(table, "angle_c", CPL_TYPE_DOUBLE); - cpl_table_fill_column_window_double(table, "angle_c", - 0, p_triangle->n, 0.0); + cpl_table_fill_column_window_double(table, "angle_c", 0, p_triangle->n, + 0.0); angle_c = cpl_table_get_data_double(table, "angle_c"); /* @@ -1687,7 +1709,7 @@ */ for (i = 0; i < p_triangle->n; i++) { - triangle *nearest = /* Nearest triangle */ + triangle *nearest = /* Nearest triangle */ nearest_triangle(p_triangle->t[i], d_triangle); distance[i] = distance_of_triangles(p_triangle->t[i], nearest, &err); if (distance[i] / err < 1.0) { @@ -1696,7 +1718,7 @@ angle_s[i] = sin(angle[i]); angle_c[i] = cos(angle[i]); n_triangle->t[i] = nearest; -/* + /* cpl_msg_debug(cpl_func, "distance, error, scale, angle = %f, %f, %f, %f", distance[i], err, scale[i], angle[i]); @@ -1708,7 +1730,7 @@ cpl_table_set_invalid(table, "angle", i); cpl_table_set_invalid(table, "angle_s", i); cpl_table_set_invalid(table, "angle_c", i); -/* + /* cpl_msg_debug(cpl_func, "EXCLUDED:\ndistance, error = %f, %f", distance[i], err); */ @@ -1723,9 +1745,9 @@ if (cpl_table_has_valid(table, "distance")) { const double median_s = cpl_table_get_column_median(table, "angle_s"); #ifdef CPL_PPM_DEBUG - const double rms_s = cpl_table_get_column_stdev(table, "angle_s"); - const double rms_c = cpl_table_get_column_stdev(table, "angle_c"); - const double rms_angle= hypot(rms_s, rms_c); + const double rms_s = cpl_table_get_column_stdev(table, "angle_s"); + const double rms_c = cpl_table_get_column_stdev(table, "angle_c"); + const double rms_angle = hypot(rms_s, rms_c); double rms_scale; #endif const double median_c = cpl_table_get_column_median(table, "angle_c"); @@ -1740,12 +1762,13 @@ #ifdef CPL_PPM_DEBUG rms_scale = cpl_table_get_column_stdev(table, "scale"); - cpl_msg_debug(cpl_func, - "Median scale (first iteration) = %.4f +/- %.4f", + cpl_msg_debug(cpl_func, + "Median scale (first iteration) = %.4f +/- %.4f", median_scale, rms_scale); - cpl_msg_debug(cpl_func, - "Median angle (first iteration) = %.4f +/- %.4f degrees", - median_angle*CPL_MATH_DEG_RAD, rms_angle*CPL_MATH_DEG_RAD); + cpl_msg_debug(cpl_func, + "Median angle (first iteration) = %.4f +/- %.4f degrees", + median_angle * CPL_MATH_DEG_RAD, + rms_angle * CPL_MATH_DEG_RAD); #endif } else { @@ -1773,13 +1796,16 @@ for (i = 0; i < p_triangle->n; i++) { if (n_triangle->t[i]) { - if (fabs(scale[i] - median_scale) > scale_tolerance - || difference_of_angles(angle[i], median_angle) > angle_tolerance) { + if (fabs(scale[i] - median_scale) > scale_tolerance || + difference_of_angles(angle[i], median_angle) > + angle_tolerance) { #ifdef CPL_PPM_DEBUG - cpl_msg_debug(cpl_func, "Discarding %d/%d: |%g - %g| > %g * %g or " - "diff_angle(%g, %g) > %g * |%g|", i+1, p_triangle->n, - scale[i], median_scale, tolerance, median_scale, - angle[i], median_angle, tolerance, median_angle); + cpl_msg_debug(cpl_func, + "Discarding %d/%d: |%g - %g| > %g * %g or " + "diff_angle(%g, %g) > %g * |%g|", + i + 1, p_triangle->n, scale[i], median_scale, + tolerance, median_scale, angle[i], median_angle, + tolerance, median_angle); #endif n_triangle->t[i] = NULL; cpl_table_set_invalid(table, "distance", i); @@ -1799,9 +1825,9 @@ if (cpl_table_has_valid(table, "distance")) { const double median_s = cpl_table_get_column_median(table, "angle_s"); #ifdef CPL_PPM_DEBUG - const double rms_s = cpl_table_get_column_stdev(table, "angle_s"); - const double rms_c = cpl_table_get_column_stdev(table, "angle_c"); - const double rms_angle= hypot(rms_s, rms_c); + const double rms_s = cpl_table_get_column_stdev(table, "angle_s"); + const double rms_c = cpl_table_get_column_stdev(table, "angle_c"); + const double rms_angle = hypot(rms_s, rms_c); double rms_scale; #endif const double median_c = cpl_table_get_column_median(table, "angle_c"); @@ -1812,16 +1838,17 @@ #ifdef CPL_PPM_DEBUG rms_scale = cpl_table_get_column_stdev(table, "scale"); - cpl_msg_debug(cpl_func, + cpl_msg_debug(cpl_func, "Median scale (second iteration) = %.4f +/- %.4f", median_scale, rms_scale); - cpl_msg_debug(cpl_func, - "Median angle (second iteration) = %.4f +/- %.4f degrees", - median_angle*CPL_MATH_DEG_RAD, rms_angle*CPL_MATH_DEG_RAD); + cpl_msg_debug(cpl_func, + "Median angle (second iteration) = %.4f +/- %.4f degrees", + median_angle * CPL_MATH_DEG_RAD, + rms_angle * CPL_MATH_DEG_RAD); #endif } else { -/* + /* cpl_msg_warning(cpl_func, "No match found (impossible!)"); cpl_error_set_message(cpl_func, CPL_ERROR_UNSPECIFIED, "No match found (impossible!)"); @@ -1842,11 +1869,11 @@ * [data_size = median_scale * pattern_size] and of the angle * [data_orientation = median_angle + pattern_orientation]. */ - + if (lin_scale) { *lin_scale = median_scale; } - + if (lin_angle) { *lin_angle = median_angle * CPL_MATH_DEG_RAD; } @@ -1898,7 +1925,6 @@ cpl_polynomial_delete(trans_y); return matches; - } /**@}*/ diff -Nru cpl-7.1.4+ds/cpldrs/cpl_ppm.h cpl-7.2.2+ds/cpldrs/cpl_ppm.h --- cpl-7.1.4+ds/cpldrs/cpl_ppm.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cpldrs/cpl_ppm.h 2022-04-29 14:56:02.000000000 +0000 @@ -25,17 +25,27 @@ CPL_BEGIN_DECLS -cpl_bivector *cpl_ppm_match_positions(const cpl_vector *, const cpl_vector *, - double, double, double, - cpl_array **, cpl_array **) - CPL_ATTR_ALLOC; +cpl_bivector *cpl_ppm_match_positions(const cpl_vector *, + const cpl_vector *, + double, + double, + double, + cpl_array **, + cpl_array **) CPL_ATTR_ALLOC; -cpl_array *cpl_ppm_match_points(const cpl_matrix *, cpl_size, double, - const cpl_matrix *, cpl_size, double, - double, double, - cpl_matrix **, cpl_matrix **, - double *, double *) CPL_ATTR_ALLOC; +cpl_array *cpl_ppm_match_points(const cpl_matrix *, + cpl_size, + double, + const cpl_matrix *, + cpl_size, + double, + double, + double, + cpl_matrix **, + cpl_matrix **, + double *, + double *) CPL_ATTR_ALLOC; CPL_END_DECLS -#endif /* CPL_PPM_H */ +#endif /* CPL_PPM_H */ diff -Nru cpl-7.1.4+ds/cpldrs/cpl_wcs.c cpl-7.2.2+ds/cpldrs/cpl_wcs.c --- cpl-7.1.4+ds/cpldrs/cpl_wcs.c 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cpldrs/cpl_wcs.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -26,23 +26,22 @@ Includes ----------------------------------------------------------------------------*/ +#include "cpl_wcs.h" + #include #include #include #include -#include #include #include - -#include "cpl_wcs.h" +#include "cpl_matrix_impl.h" #include #include #include -#include #include -#ifdef CPL_WCS_INSTALLED /* If WCS is installed */ +#ifdef CPL_WCS_INSTALLED /* If WCS is installed */ /* * Undefine PACKAGE_ symbols to avoid redefinition warnings from the compiler. @@ -51,27 +50,27 @@ */ #ifdef PACKAGE_NAME -# undef PACKAGE_NAME +#undef PACKAGE_NAME #endif #ifdef PACKAGE_VERSION -# undef PACKAGE_VERSION +#undef PACKAGE_VERSION #endif #ifdef PACKAGE_TARNAME -# undef PACKAGE_TARNAME +#undef PACKAGE_TARNAME #endif #ifdef PACKAGE_STRING -# undef PACKAGE_STRING +#undef PACKAGE_STRING #endif #ifdef PACKAGE_BUGREPORT -# undef PACKAGE_BUGREPORT +#undef PACKAGE_BUGREPORT #endif #include -#endif /* End If WCS is installed */ +#endif /* End If WCS is installed */ /*---------------------------------------------------------------------------*/ @@ -98,25 +97,26 @@ Type definition ----------------------------------------------------------------------------*/ -#ifdef CPL_WCS_INSTALLED /* If WCS is installed */ -struct _cpl_wcs_ { - struct wcsprm *wcsptr; /* WCSLIB structure */ - int istab; /* Set if header is from a table */ - int naxis; /* Number of dimensions of the image */ - cpl_array *imdims; /* Dimensions of image */ - cpl_array *crval; /* CRVALia keyvalues for each coord axis */ - cpl_array *crpix; /* CRPIXja keyvalues for each pixel axis */ - cpl_array *ctype; /* CTYPEja keyvalues for each pixel axis */ - cpl_array *cunit; /* CUNITja keyvalues for each pixel axis */ - cpl_matrix *cd; /* CDi_ja linear transformation matrix */ +#ifdef CPL_WCS_INSTALLED /* If WCS is installed */ +struct _cpl_wcs_ +{ + struct wcsprm *wcsptr; /* WCSLIB structure */ + int istab; /* Set if header is from a table */ + int naxis; /* Number of dimensions of the image */ + cpl_array *imdims; /* Dimensions of image */ + cpl_array *crval; /* CRVALia keyvalues for each coord axis */ + cpl_array *crpix; /* CRPIXja keyvalues for each pixel axis */ + cpl_array *ctype; /* CTYPEja keyvalues for each pixel axis */ + cpl_array *cunit; /* CUNITja keyvalues for each pixel axis */ + cpl_matrix *cd; /* CDi_ja linear transformation matrix */ }; /*---------------------------------------------------------------------------- Private functions ----------------------------------------------------------------------------*/ -inline static cpl_wcs *_cpl_wcs_init(struct wcsprm *wcs, - int is_tab) CPL_ATTR_ALLOC; +inline static cpl_wcs * +_cpl_wcs_init(struct wcsprm *wcs, int is_tab) CPL_ATTR_ALLOC; inline static int _cpl_wcs_set_ctype(cpl_wcs *self); inline static int _cpl_wcs_set_cunit(cpl_wcs *self); @@ -124,29 +124,16 @@ inline static int _cpl_wcsset(cpl_wcs *wcs); +static void cpl_wcs_platesol_4(const cpl_matrix *xy, + const cpl_matrix *std, + const cpl_array *bad, + cpl_array **plateconsts) CPL_ATTR_NONNULL; +static void cpl_wcs_platesol_6(const cpl_matrix *xy, + const cpl_matrix *std, + const cpl_array *bad, + cpl_array **plateconsts) CPL_ATTR_NONNULL; -/* Fix when cfitsio is upgraded */ -/* static char *cpl_wcs_plist2fitsstr(const cpl_propertylist *self); */ -static char *cpl_wcs_plist2fitsstr(const cpl_propertylist *self, int *nkeys); -static -cpl_propertylist *cpl_wcs_fitsstr2plist(const char *fitsstr) CPL_ATTR_ALLOC; -static void cpl_wcs_platesol_4(const cpl_matrix *xy, const cpl_matrix *std, - const cpl_array *bad, cpl_array **plateconsts) - CPL_ATTR_NONNULL; -static void cpl_wcs_platesol_6(const cpl_matrix *xy, const cpl_matrix *std, - const cpl_array *bad, cpl_array **plateconsts) - CPL_ATTR_NONNULL; - -#ifdef fits_write_hdu - /* fits_write_hdu() was introduced in CFITSIO version 3.03 */ -#define cpl_wcs_ffhdr2str fits_hdr2str -#else -static int cpl_wcs_ffhdr2str(fitsfile *fptr, int exclude_comm, char **exclist, - int nexc, char **header, int *nkeys, int *status); - -#endif - -#endif /* End If WCS is installed */ +#endif /* End If WCS is installed */ /*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/ @@ -212,12 +199,14 @@ * @see cpl_wcs_delete() */ -cpl_wcs *cpl_wcs_new_from_propertylist(const cpl_propertylist *plist) { -#ifdef CPL_WCS_INSTALLED /* If WCS is installed */ +cpl_wcs * +cpl_wcs_new_from_propertylist(const cpl_propertylist *plist) +{ +#ifdef CPL_WCS_INSTALLED /* If WCS is installed */ char *shdr; - int retval,nrej,nwcs; - int np = 0; + int retval, nrej, nwcs; + int np = 0, ip; int istab = -1; cpl_propertylist *testp = NULL; @@ -234,13 +223,16 @@ /* See if the propertylist has some form of WCS in it */ testp = cpl_propertylist_new(); - if (!cpl_propertylist_copy_property_regexp(testp, plist, "^CRVAL", 0) - && cpl_propertylist_get_size(testp) > 0) { + if (!cpl_propertylist_copy_property_regexp(testp, plist, "^CRVAL", 0) && + cpl_propertylist_get_size(testp) > 0) { istab = 0; - } else if (!cpl_propertylist_copy_property_regexp(testp, plist, "^TCRVL", 0) - && cpl_propertylist_get_size(testp) > 0) { + } + else if (!cpl_propertylist_copy_property_regexp(testp, plist, "^TCRVL", + 0) && + cpl_propertylist_get_size(testp) > 0) { istab = 1; - } else { + } + else { /* The input propertylist contains no WCS */ /* FIXME: This error code is not according to the doxygen */ (void)cpl_error_set_(CPL_ERROR_UNSPECIFIED); @@ -254,36 +246,48 @@ /* Convert the propertylist into a string */ - shdr = cpl_wcs_plist2fitsstr(plist, &np); - if (shdr == NULL) { - cpl_error_set_where_(); + np = cpl_propertylist_get_size(plist); + /* Allocate space for np + 1 FITS cards, and 1 null-byte */ + shdr = (char *)cpl_malloc(80 * (np + 1) + 1); + + for (ip = 0; ip < np; ip++) { + const cpl_property *p = cpl_propertylist_get_const(plist, ip); + if (cpl_fits_fill_card(shdr + ip * 80, p)) + break; + } + + if (ip < np) { + cpl_free(shdr); + (void)cpl_error_set_where_(); return NULL; } + /* It may not be needed, but add an END card and a null-byte */ + memcpy(shdr + np * 80, "END", 3); + memset(shdr + np * 80 + 3, ' ', 77); + np++; + shdr[80 * np] = '\0'; /* * Parse the header string to get all WCS representations which are * present. The number of WCS representations is stored in nwcs. */ - if (!istab) { - retval = wcspih(shdr,np,0,0,&nrej,&nwcs,&wwcs); - } - else { - retval = wcsbth(shdr,np,0,0,0,NULL,&nrej,&nwcs,&wwcs); - } - free(shdr); + retval = istab ? wcsbth(shdr, np, 0, 0, 0, NULL, &nrej, &nwcs, &wwcs) + : wcspih(shdr, np, 0, 0, &nrej, &nwcs, &wwcs); + + cpl_free(shdr); if (retval != 0) { - wcsvfree(&nwcs,&wwcs); + wcsvfree(&nwcs, &wwcs); if (istab) { - (void)cpl_error_set_wcs(CPL_ERROR_UNSPECIFIED, retval, - "wcsbth", "np=%d", np); + (void)cpl_error_set_wcs(CPL_ERROR_UNSPECIFIED, retval, "wcsbth", + "np=%d", np); } else { - (void)cpl_error_set_wcs(CPL_ERROR_UNSPECIFIED, retval, - "wcspih", "np=%d", np); + (void)cpl_error_set_wcs(CPL_ERROR_UNSPECIFIED, retval, "wcspih", + "np=%d", np); } return NULL; } @@ -301,22 +305,19 @@ wcs = _cpl_wcs_init(wwcs, istab); - wcsvfree(&nwcs,&wwcs); + wcsvfree(&nwcs, &wwcs); if (wcs->naxis > 0) { - if (!istab) { - cpl_errorstate prevstate = cpl_errorstate_get(); /* This is an image, see if it's a compressed image */ const int compressed = cpl_propertylist_has(plist, "ZNAXIS"); int i = wcs->naxis; /* Sufficient, minimal length */ - char * nax = compressed - ? cpl_sprintf("ZNAXIS%d", i) - : cpl_sprintf("NAXIS%d", i); - char * naxd = nax + (compressed ? 6 : 5); /* Digit(s) start here */ + char *nax = compressed ? cpl_sprintf("ZNAXIS%d", i) + : cpl_sprintf("NAXIS%d", i); + char *naxd = nax + (compressed ? 6 : 5); /* Digit(s) start here */ /* Now copy the stuff over to someplace where we can get it */ @@ -327,7 +328,8 @@ for (; i > 0;) { const int inax = cpl_propertylist_get_int(plist, nax); - if (!cpl_errorstate_is_equal(prevstate)) break; /* Card not OK*/ + if (!cpl_errorstate_is_equal(prevstate)) + break; /* Card not OK*/ i--; @@ -350,7 +352,6 @@ cpl_array_get_size(wcs->imdims), 0); wcs->naxis = 0; /* crval, crpix and cd are still non-NULL */ } - } } @@ -360,7 +361,7 @@ cpl_ensure(plist != NULL, CPL_ERROR_NULL_INPUT, NULL); (void)cpl_error_set_(CPL_ERROR_NO_WCS); return NULL; -#endif /* End If WCS is installed */ +#endif /* End If WCS is installed */ } /** @@ -386,12 +387,13 @@ * contents. If @em wcs is @c NULL, nothing is done and no error is set. */ -void cpl_wcs_delete(cpl_wcs *wcs) { - +void +cpl_wcs_delete(cpl_wcs *wcs) +{ if (wcs == NULL) return; -#ifdef CPL_WCS_INSTALLED /* If WCS is installed */ +#ifdef CPL_WCS_INSTALLED /* If WCS is installed */ /* Free the workspace */ if (wcs->imdims != NULL) { @@ -415,7 +417,7 @@ #else cpl_error_set_(CPL_ERROR_NO_WCS); -#endif /* End If WCS is installed */ +#endif /* End If WCS is installed */ } /** @@ -499,26 +501,30 @@ * */ -cpl_error_code cpl_wcs_convert(const cpl_wcs *wcs, const cpl_matrix *from, - cpl_matrix **to, cpl_array **status, - cpl_wcs_trans_mode transform) { -#ifdef CPL_WCS_INSTALLED /* If WCS is installed */ +cpl_error_code +cpl_wcs_convert(const cpl_wcs *wcs, + const cpl_matrix *from, + cpl_matrix **to, + cpl_array **status, + cpl_wcs_trans_mode transform) +{ +#ifdef CPL_WCS_INSTALLED /* If WCS is installed */ const cpl_size mrows = cpl_matrix_get_nrow(from); const cpl_size mcols = cpl_matrix_get_ncol(from); const int nrows = (int)mrows; const int ncols = (int)mcols; - int *sdata,retval; + int *sdata, retval; cpl_matrix *x1; - cpl_array *x2,*x3; - double *tdata,*x1data,*x2data,*x3data; + cpl_array *x2, *x3; + double *tdata, *x1data, *x2data, *x3data; const double *fdata; - const char * wcsfunc = NULL; + const char *wcsfunc = NULL; /* Basic checks on the input pointers */ - cpl_ensure_code(wcs != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(from != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(to != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(wcs != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(from != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(to != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(status != NULL, CPL_ERROR_NULL_INPUT); /* FIXME: Perhaps this should be an assertion ? */ cpl_ensure_code(wcs->wcsptr != NULL, CPL_ERROR_NULL_INPUT); @@ -549,10 +555,10 @@ /* Now get the pointers for the data arrays */ - fdata = cpl_matrix_get_data_const(from); - tdata = cpl_matrix_get_data(*to); + fdata = cpl_matrix_get_data_const_(from); + tdata = cpl_matrix_get_data_(*to); sdata = cpl_array_get_data_int(*status); - x1data = cpl_matrix_get_data(x1); + x1data = cpl_matrix_get_data_(x1); x2data = cpl_array_get_data_double(x2); x3data = cpl_array_get_data_double(x3); @@ -560,28 +566,28 @@ to world coordinates */ switch (transform) { - case CPL_WCS_PHYS2WORLD: - wcsfunc = "wcsp2s"; - retval = wcsp2s(wcs->wcsptr,nrows,wcs->naxis,fdata,x1data,x2data, - x3data,tdata,sdata); - break; - case CPL_WCS_WORLD2PHYS: - wcsfunc = "wcss2p"; - retval = wcss2p(wcs->wcsptr,nrows,wcs->naxis,fdata,x2data,x3data, - x1data,tdata,sdata); - break; - case CPL_WCS_WORLD2STD: - wcsfunc = "wcss2p"; - retval = wcss2p(wcs->wcsptr,nrows,wcs->naxis,fdata,x2data,x3data, - tdata,x1data,sdata); - break; - case CPL_WCS_PHYS2STD: - wcsfunc = "wcsp2s"; - retval = wcsp2s(wcs->wcsptr,nrows,wcs->naxis,fdata,tdata,x2data, - x3data,x1data,sdata); - break; - default: - break; + case CPL_WCS_PHYS2WORLD: + wcsfunc = "wcsp2s"; + retval = wcsp2s(wcs->wcsptr, nrows, wcs->naxis, fdata, x1data, + x2data, x3data, tdata, sdata); + break; + case CPL_WCS_WORLD2PHYS: + wcsfunc = "wcss2p"; + retval = wcss2p(wcs->wcsptr, nrows, wcs->naxis, fdata, x2data, + x3data, x1data, tdata, sdata); + break; + case CPL_WCS_WORLD2STD: + wcsfunc = "wcss2p"; + retval = wcss2p(wcs->wcsptr, nrows, wcs->naxis, fdata, x2data, + x3data, tdata, x1data, sdata); + break; + case CPL_WCS_PHYS2STD: + wcsfunc = "wcsp2s"; + retval = wcsp2s(wcs->wcsptr, nrows, wcs->naxis, fdata, tdata, + x2data, x3data, x1data, sdata); + break; + default: + break; } /* Ditch the intermediate coordinate results */ @@ -593,34 +599,35 @@ if (wcsfunc == NULL) { cpl_matrix_delete(*to); cpl_array_delete(*status); - *to = NULL; + *to = NULL; *status = NULL; return cpl_error_set_(CPL_ERROR_UNSUPPORTED_MODE); } - return retval ? cpl_error_set_wcs(retval == 1 ? CPL_ERROR_NULL_INPUT - : CPL_ERROR_UNSPECIFIED, retval, wcsfunc, - "transform=%d", transform) - : CPL_ERROR_NONE; + return retval + ? cpl_error_set_wcs(retval == 1 ? CPL_ERROR_NULL_INPUT + : CPL_ERROR_UNSPECIFIED, + retval, wcsfunc, "transform=%d", transform) + : CPL_ERROR_NONE; #else - cpl_ensure_code(wcs != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(from != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(to != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(wcs != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(from != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(to != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(status != NULL, CPL_ERROR_NULL_INPUT); switch (transform) { - case CPL_WCS_PHYS2WORLD: - case CPL_WCS_WORLD2PHYS: - case CPL_WCS_WORLD2STD: - case CPL_WCS_PHYS2STD: - break; - default: - return cpl_error_set_(CPL_ERROR_UNSUPPORTED_MODE); + case CPL_WCS_PHYS2WORLD: + case CPL_WCS_WORLD2PHYS: + case CPL_WCS_WORLD2STD: + case CPL_WCS_PHYS2STD: + break; + default: + return cpl_error_set_(CPL_ERROR_UNSUPPORTED_MODE); } return cpl_error_set_(CPL_ERROR_NO_WCS); -#endif /* End If WCS is installed */ +#endif /* End If WCS is installed */ } /** @@ -707,18 +714,22 @@ * @see cpl_wcs_convert() */ -cpl_error_code cpl_wcs_platesol(const cpl_propertylist *ilist, - const cpl_matrix *cel, - const cpl_matrix *xy, int niter, float thresh, - cpl_wcs_platesol_fitmode fitmode, - cpl_wcs_platesol_outmode outmode, - cpl_propertylist **olist) { -#ifdef CPL_WCS_INSTALLED /* If WCS is installed */ +cpl_error_code +cpl_wcs_platesol(const cpl_propertylist *ilist, + const cpl_matrix *cel, + const cpl_matrix *xy, + int niter, + float thresh, + cpl_wcs_platesol_fitmode fitmode, + cpl_wcs_platesol_outmode outmode, + cpl_propertylist **olist) +{ +#ifdef CPL_WCS_INSTALLED /* If WCS is installed */ const cpl_size npts = cpl_matrix_get_nrow(cel); - int iter,n,i; - int * isbad; - double xifit,etafit,mederr_xi,mederr_eta; - double crval1,crval2,phi,theta; + int iter, n, i; + int *isbad; + double xifit, etafit, mederr_xi, mederr_eta; + double crval1, crval2, phi, theta; double crpix1 = 0.0; /* Avoid uninit warning (See below comment on pc) */ double crpix2 = 0.0; /* Avoid uninit warning (See below comment on pc) */ const double *xydata = cpl_matrix_get_data_const(xy); @@ -744,36 +755,39 @@ /* Basic checks on the input pointers */ - cpl_ensure_code(cel != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(xy != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(cel != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(xy != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(ilist != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(niter > 0, CPL_ERROR_ILLEGAL_INPUT); cpl_ensure_code(fitmode == CPL_WCS_PLATESOL_6 || - fitmode == CPL_WCS_PLATESOL_4, CPL_ERROR_UNSUPPORTED_MODE); + fitmode == CPL_WCS_PLATESOL_4, + CPL_ERROR_UNSUPPORTED_MODE); /* Open the cpl_wcs structure */ wcs = cpl_wcs_new_from_propertylist(ilist); if (wcs == NULL) { return cpl_error_set_message_(CPL_ERROR_UNSPECIFIED, - "Unable to parse header"); + "Unable to parse header"); } /* Get the number of celestial points and compare this with the size of the matrix with the xy coordinates. Also look at the total number of points available */ - if (npts != cpl_matrix_get_nrow(xy)) { + if (npts != cpl_matrix_get_nrow_(xy)) { cpl_wcs_delete(wcs); return cpl_error_set_(CPL_ERROR_INCOMPATIBLE_INPUT); } if (npts < 2) { cpl_wcs_delete(wcs); - return cpl_error_set_message_(CPL_ERROR_UNSPECIFIED, "Insufficient " - "points for a fit: npoints=%" - CPL_SIZE_FORMAT " < 2", npts); + return cpl_error_set_message_( + CPL_ERROR_UNSPECIFIED, + "Insufficient " + "points for a fit: npoints=%" CPL_SIZE_FORMAT " < 2", + npts); } /* Convert the celestial coordinates to standard coordinates */ @@ -783,22 +797,23 @@ stddata = cpl_matrix_get_data_const(std); /* Get some workspace for rejection algorithm */ - eta_work = (double*)cpl_malloc((size_t)npts * sizeof(double)); - xi_work = (double*)cpl_malloc((size_t)npts * sizeof(double)); + eta_work = (double *)cpl_malloc((size_t)npts * sizeof(double)); + xi_work = (double *)cpl_malloc((size_t)npts * sizeof(double)); /* Get an array to flag bad pairs */ - isbad = (int*)cpl_calloc((size_t)npts, sizeof(int)); - bad = cpl_array_wrap_int(isbad, npts); + isbad = (int *)cpl_calloc((size_t)npts, sizeof(int)); + bad = cpl_array_wrap_int(isbad, npts); /* Iterative loop */ plateconsts = NULL; - for (iter = 1;iter <= niter && nprev < nbad && nbad + 1 < npts; iter++) { - double mederr; + for (iter = 1; iter <= niter && nprev < nbad && nbad + 1 < npts; iter++) { + double mederr; /* Do a plate solution */ cpl_array_delete(plateconsts); - (fitmode == CPL_WCS_PLATESOL_6 ? cpl_wcs_platesol_6 : cpl_wcs_platesol_4) - (xy, std, bad, &plateconsts); + (fitmode == CPL_WCS_PLATESOL_6 + ? cpl_wcs_platesol_6 + : cpl_wcs_platesol_4)(xy, std, bad, &plateconsts); pc = cpl_array_get_data_double_const(plateconsts); @@ -807,13 +822,13 @@ n = 0; for (i = 0; i < npts; i++) { if (!isbad[i]) { - const double xifiti - = xydata[2*i]*pc[0] + xydata[2*i+1]*pc[1] + pc[2]; - const double etafiti - = xydata[2*i]*pc[3] + xydata[2*i+1]*pc[4] + pc[5]; + const double xifiti = + xydata[2 * i] * pc[0] + xydata[2 * i + 1] * pc[1] + pc[2]; + const double etafiti = + xydata[2 * i] * pc[3] + xydata[2 * i + 1] * pc[4] + pc[5]; - xi_work [n] = fabs(xifiti - stddata[2*i]); - eta_work[n] = fabs(etafiti - stddata[2*i+1]); + xi_work[n] = fabs(xifiti - stddata[2 * i]); + eta_work[n] = fabs(etafiti - stddata[2 * i + 1]); n++; } } @@ -824,11 +839,11 @@ if (med_work == NULL) { /* Need copy due to permutation in median computation */ - med_work = (double*)cpl_malloc( 2 * (size_t)n * sizeof(double)); + med_work = (double *)cpl_malloc(2 * (size_t)n * sizeof(double)); } /* Get the median of the array */ - (void)memcpy(med_work, xi_work, (size_t)n * sizeof(double)); + (void)memcpy(med_work, xi_work, (size_t)n * sizeof(double)); (void)memcpy(med_work + n, eta_work, (size_t)n * sizeof(double)); mederr = 1.48 * cpl_tools_get_median_double(med_work, 2 * n); @@ -836,7 +851,7 @@ nprev = nbad; for (i = 0; i < npts; i++) { if (!isbad[i] && (eta_work[i] > thresh * mederr || - xi_work [i] > thresh * mederr)) { + xi_work[i] > thresh * mederr)) { isbad[i] = 1; nbad++; } @@ -861,7 +876,7 @@ /* Now work out the median error in each axis */ - mederr_xi = 1.48 * cpl_tools_get_median_double(xi_work, n); + mederr_xi = 1.48 * cpl_tools_get_median_double(xi_work, n); mederr_eta = 1.48 * cpl_tools_get_median_double(eta_work, n); /* Do some intermediate tidying */ @@ -872,35 +887,38 @@ wp = wcs->wcsptr; switch (outmode) { - case CPL_WCS_MV_CRPIX: - crpix1 = (pc[4]*pc[2] - pc[1]*pc[5])/(pc[3]*pc[1] - pc[4]*pc[0]); - crpix2 = (pc[0]*pc[5] - pc[3]*pc[2])/(pc[3]*pc[1] - pc[4]*pc[0]); - crval1 = (wp->crval)[0]; - crval2 = (wp->crval)[1]; - break; - case CPL_WCS_MV_CRVAL: { - int retval, sdata[] = {0}; - crpix1 = (wp->crpix)[0]; - crpix2 = (wp->crpix)[1]; - xifit = crpix1*pc[0] + crpix2*pc[1] + pc[2]; - etafit = crpix1*pc[3] + crpix2*pc[4] + pc[5]; - retval = celx2s(&(wp->cel),1,1,2,2,&xifit,&etafit,&phi,&theta, - &crval1,&crval2,sdata); - if (retval) { + case CPL_WCS_MV_CRPIX: + crpix1 = (pc[4] * pc[2] - pc[1] * pc[5]) / + (pc[3] * pc[1] - pc[4] * pc[0]); + crpix2 = (pc[0] * pc[5] - pc[3] * pc[2]) / + (pc[3] * pc[1] - pc[4] * pc[0]); + crval1 = (wp->crval)[0]; + crval2 = (wp->crval)[1]; + break; + case CPL_WCS_MV_CRVAL: { + int retval, sdata[] = { 0 }; + crpix1 = (wp->crpix)[0]; + crpix2 = (wp->crpix)[1]; + xifit = crpix1 * pc[0] + crpix2 * pc[1] + pc[2]; + etafit = crpix1 * pc[3] + crpix2 * pc[4] + pc[5]; + retval = celx2s(&(wp->cel), 1, 1, 2, 2, &xifit, &etafit, &phi, + &theta, &crval1, &crval2, sdata); + if (retval) { + cpl_wcs_delete(wcs); + cpl_array_delete(plateconsts); + return cpl_error_set_wcs(CPL_ERROR_UNSPECIFIED, retval, + "celx2s", + "niter=%d, thresh=%f, " + "fitmode=%d, outmode=%d", + niter, (double)thresh, (int)fitmode, + (int)outmode); + } + break; + } + default: cpl_wcs_delete(wcs); cpl_array_delete(plateconsts); - return cpl_error_set_wcs(CPL_ERROR_UNSPECIFIED, retval, - "celx2s", "niter=%d, thresh=%f, " - "fitmode=%d, outmode=%d", niter, - (double)thresh, (int)fitmode, - (int)outmode); - } - break; - } - default: - cpl_wcs_delete(wcs); - cpl_array_delete(plateconsts); - return cpl_error_set_(CPL_ERROR_UNSUPPORTED_MODE); + return cpl_error_set_(CPL_ERROR_UNSUPPORTED_MODE); } /* Now update the wcs structure */ @@ -924,30 +942,52 @@ /* Make a FITS string and convert it to a propertylist */ - if (wcshdo(0,wp, &i, &o)) { + if (wcshdo(0, wp, &i, &o)) { code = CPL_ERROR_NULL_INPUT; - } else { - cpl_errorstate prestate = cpl_errorstate_get(); - cpl_propertylist *pvlist; - cpl_property *p = NULL; - char *outstr = cpl_calloc((size_t)(i+1) * 80 + 1, 1); - /* FITS END card */ - const char *endcard = "END " - " "; - cpl_size nprop, iprop; - char *cd = NULL; - int cdlen = 0; - - strncpy(outstr, o, (size_t)i * 80); + } + else { + /* The FITS string is far from valid: + its size is not a multiple of 36 * 80, and + it is missing several mandatory cards, e.g. SIMPLE, NAXIS, END. + + Since this puts limits on how it can be written and read by CFITSIO + we instead read the string directly by the CPL FITS card parser. */ + + char cardi[FLEN_CARD]; + cpl_errorstate prestate = cpl_errorstate_get(); + const cpl_cstr *erasekeys[] = { + CXSTR("PC1_1", 5), CXSTR("PC1_2", 5), CXSTR("PC2_1", 5), + CXSTR("PC2_2", 5), CXSTR("CDELT1", 6), CXSTR("CDELT2", 6), + CXSTR("RESTFRQ", 7), CXSTR("RESTWAV", 7), CXSTR("END", 3) + }; + const int nerasekeys = (int)CX_N_ELEMENTS(erasekeys); + + cpl_property *p = NULL; + char *cd = NULL; + int cdlen = 0; + + *olist = cpl_propertylist_new(); + + /* Need null-terminator for parsing a card with a numerical value */ + cardi[FLEN_CARD - 1] = '\0'; + + /* Convert each FITS card to a CPL property, ensuring that the WCS + keys that need to be floating point are indeed that (e.g. PV1_1). + */ + + for (int k = 0; k < i; k++) { + (void)memcpy(cardi, o + k * (FLEN_CARD - 1), FLEN_CARD - 1); + if (cpl_propertylist_append_from_string(*olist, cardi, NULL, + NULL)) { + (void)cpl_error_set_message_(cpl_error_get_code(), + "Bad WCS FITS Card %d/%d", k, i); + break; + } + } free(o); - strncat(outstr,endcard,79); - *olist = cpl_wcs_fitsstr2plist(outstr); - cpl_free(outstr); - for (i = 2; i > 0; --i) { - for (int j = 2; j > 0; j--) - { + for (int j = 2; j > 0; j--) { const double cd_val = cpl_matrix_get(wcs->cd, i - 1, j - 1); if (p == NULL) { @@ -957,7 +997,8 @@ "transformation " "matrix element", 40)); - } else { + } + else { const int keylen = sprintf(cd, "CD%1d_%1d", i, j); assert(keylen == cdlen); cpl_property_set_name_cx(p, CXSTR(cd, cdlen)); @@ -974,36 +1015,15 @@ /* * Remove keywords which are not needed for the DICB required * CD representation of the linear transformation matrix. + * + * FIXME: What about the RESTFRQ, RESTWAV stuff? Needed or not? + * */ - // FIXME: What about the RESTFRQ, RESTWAV stuff? Needed or not? + cpl_propertylist_erase_name_(*olist, 0, NULL, nerasekeys, erasekeys, 0); - cpl_propertylist_erase_regexp(*olist, "^PC[12]_[12]$", 0); - cpl_propertylist_erase(*olist,"CDELT1"); - cpl_propertylist_erase(*olist,"CDELT2"); - cpl_propertylist_erase(*olist,"RESTFRQ"); - cpl_propertylist_erase(*olist,"RESTWAV"); - cpl_propertylist_erase(*olist,"END"); - - - /* Fix boo-boo in wcslib */ - /* The above uninformative comment means: - Change type of PV-properties from int to double */ - - pvlist = cpl_propertylist_new(); - cpl_propertylist_copy_property_regexp(pvlist, *olist, "PV", 0); - nprop = cpl_propertylist_get_size(pvlist); - for (iprop = 0; iprop < nprop; iprop++) { - p = cpl_propertylist_get(pvlist, iprop); - if (cpl_property_get_type(p) == CPL_TYPE_INT) { - const int ival = cpl_property_get_int(p); - cpl_propertylist_erase(*olist, cpl_property_get_name(p)); - cpl_propertylist_append_double(*olist, cpl_property_get_name(p), - (double)ival); - } - } - cpl_propertylist_delete(pvlist); - if (!cpl_errorstate_is_equal(prestate)) code = cpl_error_get_code(); + if (!cpl_errorstate_is_equal(prestate)) + code = cpl_error_get_code(); } /* Tidy and exit */ @@ -1015,31 +1035,31 @@ #else cpl_ensure_code(olist != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(cel != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(xy != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(cel != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(xy != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(ilist != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(niter > 0, CPL_ERROR_ILLEGAL_INPUT); cpl_ensure_code(thresh > 0.0, CPL_ERROR_DATA_NOT_FOUND); switch (fitmode) { - case CPL_WCS_PLATESOL_6: - case CPL_WCS_PLATESOL_4: - break; - default: - return cpl_error_set_(CPL_ERROR_UNSUPPORTED_MODE); + case CPL_WCS_PLATESOL_6: + case CPL_WCS_PLATESOL_4: + break; + default: + return cpl_error_set_(CPL_ERROR_UNSUPPORTED_MODE); } switch (outmode) { - case CPL_WCS_MV_CRPIX: - case CPL_WCS_MV_CRVAL: - break; - default: - return cpl_error_set_(CPL_ERROR_UNSUPPORTED_MODE); + case CPL_WCS_MV_CRPIX: + case CPL_WCS_MV_CRVAL: + break; + default: + return cpl_error_set_(CPL_ERROR_UNSUPPORTED_MODE); } return cpl_error_set_(CPL_ERROR_NO_WCS); -#endif /* End If WCS is installed */ +#endif /* End If WCS is installed */ } @@ -1076,19 +1096,20 @@ * If the header was not parsed correctly then this is -1. */ -int cpl_wcs_is_table(const cpl_wcs *wcs) { - +int +cpl_wcs_is_table(const cpl_wcs *wcs) +{ /* Check for NULL input */ cpl_ensure(wcs != NULL, CPL_ERROR_NULL_INPUT, -1); -#ifdef CPL_WCS_INSTALLED /* If WCS is installed */ +#ifdef CPL_WCS_INSTALLED /* If WCS is installed */ /* Return the relevant value */ - return(wcs->istab); + return (wcs->istab); #else (void)cpl_error_set_(CPL_ERROR_NO_WCS); return -1; -#endif /* End If WCS is installed */ +#endif /* End If WCS is installed */ } #endif @@ -1122,19 +1143,20 @@ * If no image was used to define the WCS then a value of zero is returned. */ -int cpl_wcs_get_image_naxis(const cpl_wcs *wcs) { - +int +cpl_wcs_get_image_naxis(const cpl_wcs *wcs) +{ /* Check for NULL input */ cpl_ensure(wcs != NULL, CPL_ERROR_NULL_INPUT, 0); -#ifdef CPL_WCS_INSTALLED /* If WCS is installed */ +#ifdef CPL_WCS_INSTALLED /* If WCS is installed */ /* Return the relevant value */ - return(wcs->naxis); + return (wcs->naxis); #else (void)cpl_error_set_(CPL_ERROR_NO_WCS); return 0; -#endif /* End If WCS is installed */ +#endif /* End If WCS is installed */ } /** @@ -1167,12 +1189,13 @@ * a NULL value will be returned. */ -const cpl_array *cpl_wcs_get_image_dims(const cpl_wcs *wcs) { - +const cpl_array * +cpl_wcs_get_image_dims(const cpl_wcs *wcs) +{ /* Check for NULL input */ cpl_ensure(wcs != NULL, CPL_ERROR_NULL_INPUT, NULL); -#ifdef CPL_WCS_INSTALLED /* If WCS is installed */ +#ifdef CPL_WCS_INSTALLED /* If WCS is installed */ /* Return the array, or NULL when unavailable */ return wcs->naxis == 0 ? NULL : wcs->imdims; @@ -1180,7 +1203,7 @@ #else (void)cpl_error_set_(CPL_ERROR_NO_WCS); return NULL; -#endif /* End If WCS is installed */ +#endif /* End If WCS is installed */ } /** @@ -1213,19 +1236,20 @@ * this WCS. */ -const cpl_array *cpl_wcs_get_crval(const cpl_wcs *wcs) { - +const cpl_array * +cpl_wcs_get_crval(const cpl_wcs *wcs) +{ /* Check for NULL input */ cpl_ensure(wcs != NULL, CPL_ERROR_NULL_INPUT, NULL); -#ifdef CPL_WCS_INSTALLED /* If WCS is installed */ +#ifdef CPL_WCS_INSTALLED /* If WCS is installed */ return wcs->wcsptr->naxis == 0 ? NULL : wcs->crval; #else (void)cpl_error_set_(CPL_ERROR_NO_WCS); return NULL; -#endif /* End If WCS is installed */ +#endif /* End If WCS is installed */ } /** @@ -1258,19 +1282,20 @@ * this WCS. */ -const cpl_array *cpl_wcs_get_crpix(const cpl_wcs *wcs) { - +const cpl_array * +cpl_wcs_get_crpix(const cpl_wcs *wcs) +{ /* Check for NULL input */ cpl_ensure(wcs != NULL, CPL_ERROR_NULL_INPUT, NULL); -#ifdef CPL_WCS_INSTALLED /* If WCS is installed */ +#ifdef CPL_WCS_INSTALLED /* If WCS is installed */ return wcs->wcsptr->naxis == 0 ? NULL : wcs->crpix; #else (void)cpl_error_set_(CPL_ERROR_NO_WCS); return NULL; -#endif /* End If WCS is installed */ +#endif /* End If WCS is installed */ } /** @@ -1303,19 +1328,20 @@ * this WCS. */ -const cpl_array *cpl_wcs_get_ctype(const cpl_wcs *wcs) { - +const cpl_array * +cpl_wcs_get_ctype(const cpl_wcs *wcs) +{ /* Check for NULL input */ cpl_ensure(wcs != NULL, CPL_ERROR_NULL_INPUT, NULL); -#ifdef CPL_WCS_INSTALLED /* If WCS is installed */ +#ifdef CPL_WCS_INSTALLED /* If WCS is installed */ return wcs->wcsptr->naxis == 0 ? NULL : wcs->ctype; #else (void)cpl_error_set_(CPL_ERROR_NO_WCS); return NULL; -#endif /* End If WCS is installed */ +#endif /* End If WCS is installed */ } /** @@ -1348,19 +1374,20 @@ * this WCS. */ -const cpl_array *cpl_wcs_get_cunit(const cpl_wcs *wcs) { - +const cpl_array * +cpl_wcs_get_cunit(const cpl_wcs *wcs) +{ /* Check for NULL input */ cpl_ensure(wcs != NULL, CPL_ERROR_NULL_INPUT, NULL); -#ifdef CPL_WCS_INSTALLED /* If WCS is installed */ +#ifdef CPL_WCS_INSTALLED /* If WCS is installed */ return wcs->wcsptr->naxis == 0 ? NULL : wcs->cunit; #else (void)cpl_error_set_(CPL_ERROR_NO_WCS); return NULL; -#endif /* End If WCS is installed */ +#endif /* End If WCS is installed */ } /** @@ -1393,25 +1420,25 @@ * this WCS. */ -const cpl_matrix *cpl_wcs_get_cd(const cpl_wcs *wcs) { - +const cpl_matrix * +cpl_wcs_get_cd(const cpl_wcs *wcs) +{ /* Check for NULL input */ cpl_ensure(wcs != NULL, CPL_ERROR_NULL_INPUT, NULL); -#ifdef CPL_WCS_INSTALLED /* If WCS is installed */ +#ifdef CPL_WCS_INSTALLED /* If WCS is installed */ return wcs->wcsptr->naxis == 0 ? NULL : wcs->cd; #else (void)cpl_error_set_(CPL_ERROR_NO_WCS); return NULL; -#endif /* End If WCS is installed */ +#endif /* End If WCS is installed */ } - /**@}*/ -#ifdef CPL_WCS_INSTALLED /* If WCS is installed */ +#ifdef CPL_WCS_INSTALLED /* If WCS is installed */ /*-------------------------------------------------------------------------*/ /** @@ -1438,11 +1465,9 @@ inline static cpl_wcs * _cpl_wcs_init(struct wcsprm *wcs, int is_tab) { - cpl_wcs *self = NULL; if (wcs != NULL) { - struct wcsprm *_wcs = NULL; self = cpl_calloc(1, sizeof *self); @@ -1457,16 +1482,15 @@ self->istab = is_tab; self->naxis = _wcs->naxis; - self->crpix = NULL; - self->crval = NULL; - self->cunit = NULL; - self->ctype = NULL; - self->cd = NULL; + self->crpix = NULL; + self->crval = NULL; + self->cunit = NULL; + self->ctype = NULL; + self->cd = NULL; self->imdims = NULL; if (self->naxis > 0) { - self->crpix = cpl_array_wrap_double(_wcs->crpix, self->naxis); self->crval = cpl_array_wrap_double(_wcs->crval, self->naxis); @@ -1483,8 +1507,8 @@ * to. */ - self->ctype = cpl_array_new(self->naxis, CPL_TYPE_STRING); - self->cunit = cpl_array_new(self->naxis, CPL_TYPE_STRING); + self->ctype = cpl_array_new(self->naxis, CPL_TYPE_STRING); + self->cunit = cpl_array_new(self->naxis, CPL_TYPE_STRING); _cpl_wcs_set_ctype(self); _cpl_wcs_set_cunit(self); @@ -1516,166 +1540,12 @@ self->imdims = cpl_array_new(self->naxis, CPL_TYPE_INT); cpl_array_fill_window_int(self->imdims, 0, self->naxis, 0); } - } - } return self; } -/** - * @internal - * @brief - * Convert a propertylist to a FITS string - * - * @param self The input propertylist - * @param nkeys On success, *nkeys points to the number of keys (cards) - * - * @return - * The output character string with the properties formatted as in a FITS - * header. - * - * @error - * - * - * - * - * - *
CPL_ERROR_NULL_INPUT - * The parameter self is a NULL pointer. - *
- * @enderror - * - * This converts a propertylist into a single string with all properties formatted - * as FITS cards. This is needed for wcspih. The output string must be freed by - * the calling routine. - */ - -/* static char *cpl_wcs_plist2fitsstr(const cpl_propertylist *self) { */ -static char *cpl_wcs_plist2fitsstr(const cpl_propertylist *self, int *nkeys) { - - char * header = NULL; - int ioerror = 0; - fitsfile * fptr; - - /* Sanity testing of input propertylist */ - - if (self == NULL) { - (void)cpl_error_set_(CPL_ERROR_NULL_INPUT); - return(NULL); - } - - /* Open a memory file with CFITSIO */ - - if (fits_create_file(&fptr, "mem://", &ioerror)) { - (void)cpl_error_set_fits(CPL_ERROR_FILE_IO, ioerror, fits_create_file, - "filename='mem://'"); - return NULL; - } - - /* Add the properties into the FITS file */ - - if (cpl_propertylist_to_fitsfile(fptr, self, NULL)) { - (void)cpl_error_set_where_(); - return NULL; - } - - /* Parse the header */ - - if (cpl_wcs_ffhdr2str(fptr, 1, NULL, 0, &header, nkeys, &ioerror)) { - (void)cpl_error_set_fits(CPL_ERROR_FILE_IO, ioerror, fits_hdr2str, - "filename='mem://'"); - ioerror = 0; - } - - /* The close will likely fail due to a missing 1st SIMPLE/EXTENSION key */ - if (fits_close_file(fptr, &ioerror) && ioerror != UNKNOWN_REC - && ioerror != NO_SIMPLE) { - free(header); - header = NULL; - (void)cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, ioerror, - fits_close_file, - "filename='mem://'"); - } - - return(header); -} - -/** - * @internal - * @brief - * Convert a FITS string to a propertylist - * - * @param fitsstr The input FITS header string - * - * @return - * The output propertylist. - * - * @error - * - * - * - * - * - *
CPL_ERROR_NULL_INPUT - * The parameter fitsstr is a NULL pointer. - *
- * @enderror - * - * This converts a single string formatted with FITS cards into a propertylist. - * This is needed for wcspih. The output propertylist must be freed by the - * calling routine - */ - -static cpl_propertylist *cpl_wcs_fitsstr2plist(const char *fitsstr) { - int ioerror = 0; - fitsfile * fptr; - const char * f = fitsstr; - cpl_propertylist * p = NULL; - - /* Check input */ - - if (fitsstr == NULL) { - cpl_error_set_(CPL_ERROR_NULL_INPUT); - return(NULL); - } - - /* Create a memory file using CFITSIO. We can then add individual cards to - the header and allow CFITSIO to decide on data types etc. */ - - if (fits_create_file(&fptr, "mem://", &ioerror)) { - (void)cpl_error_set_fits(CPL_ERROR_FILE_IO, ioerror, fits_create_file, - "fitsstr='%s'", fitsstr); - return NULL; - } - - /* Loop for all the cards in the FITS string and add them to the - memory FITS header */ - while (strncmp(f, "END ", 8) && !fits_insert_card(fptr, f, &ioerror)) { - f += (FLEN_CARD - 1); - } - if (ioerror || fits_insert_card(fptr, f, &ioerror)) { - (void)cpl_error_set_fits(CPL_ERROR_FILE_IO, ioerror, fits_insert_card, - "fitsstr='%s'", fitsstr); - ioerror = 0; - } else { - - /* Now create the propertylist */ - p = cpl_propertylist_from_fitsfile(fptr); - } - - /* The close will likely fail due to a missing 1st SIMPLE/EXTENSION key */ - if (fits_close_file(fptr, &ioerror) && ioerror != UNKNOWN_REC - && ioerror != NO_SIMPLE) { - cpl_propertylist_delete(p); - p = NULL; - (void)cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, ioerror, - fits_close_file, "fitsstr='%s'", fitsstr); - } - - return(p); -} /** * @internal @@ -1698,16 +1568,21 @@ * */ -static void cpl_wcs_platesol_6(const cpl_matrix *xy, const cpl_matrix *std, - const cpl_array *bad, cpl_array **plateconsts) { - double sx1sq,sy1sq,sx1y1,sx1x2,sy1x2,*pc; - double sy1y2,sx1y2,xposmean,yposmean,ximean,etamean,xx1,yy1,xx2,yy2; +static void +cpl_wcs_platesol_6(const cpl_matrix *xy, + const cpl_matrix *std, + const cpl_array *bad, + cpl_array **plateconsts) +{ + double sx1sq, sy1sq, sx1y1, sx1x2, sy1x2, *pc; + double sy1y2, sx1y2, xposmean, yposmean, ximean, etamean, xx1, yy1, xx2, + yy2; /* Get some convenience variables */ - const double *xydata = cpl_matrix_get_data_const(xy); - const double *stddata = cpl_matrix_get_data_const(std); - const int *isbad = cpl_array_get_data_int_const(bad); + const double *xydata = cpl_matrix_get_data_const(xy); + const double *stddata = cpl_matrix_get_data_const(std); + const int *isbad = cpl_array_get_data_int_const(bad); const cpl_size nstds = cpl_array_get_size(bad); - cpl_size i,ngood; + cpl_size i, ngood; /* Initialise all the counters and summations */ @@ -1729,10 +1604,10 @@ for (i = 0; i < nstds; i++) { if (isbad[i] != 0) continue; - xposmean += xydata[2*i]; - yposmean += xydata[2*i+1]; - ximean += stddata[2*i]; - etamean += stddata[2*i+1]; + xposmean += xydata[2 * i]; + yposmean += xydata[2 * i + 1]; + ximean += stddata[2 * i]; + etamean += stddata[2 * i + 1]; ngood++; } xposmean /= (double)ngood; @@ -1743,38 +1618,37 @@ /* Now accumulate the sums */ for (i = 0; i < nstds; i++) { - if (! isbad[i]) { - xx1 = xydata[2*i] - xposmean; - yy1 = xydata[2*i+1] - yposmean; - xx2 = stddata[2*i] - ximean; - yy2 = stddata[2*i+1] - etamean; - sx1sq += xx1*xx1; - sy1sq += yy1*yy1; - sx1y1 += xx1*yy1; - sx1x2 += xx1*xx2; - sy1x2 += yy1*xx2; - sy1y2 += yy1*yy2; - sx1y2 += xx1*yy2; + if (!isbad[i]) { + xx1 = xydata[2 * i] - xposmean; + yy1 = xydata[2 * i + 1] - yposmean; + xx2 = stddata[2 * i] - ximean; + yy2 = stddata[2 * i + 1] - etamean; + sx1sq += xx1 * xx1; + sy1sq += yy1 * yy1; + sx1y1 += xx1 * yy1; + sx1x2 += xx1 * xx2; + sy1x2 += yy1 * xx2; + sy1y2 += yy1 * yy2; + sx1y2 += xx1 * yy2; } } /* Get an output array for the results */ - *plateconsts = cpl_array_new(6,CPL_TYPE_DOUBLE); + *plateconsts = cpl_array_new(6, CPL_TYPE_DOUBLE); pc = cpl_array_get_data_double(*plateconsts); /* Do solution for X */ - pc[0] = (sx1y1*sy1x2 - sx1x2*sy1sq)/(sx1y1*sx1y1 - sx1sq*sy1sq); - pc[1] = (sx1x2*sx1y1 - sx1sq*sy1x2)/(sx1y1*sx1y1 - sx1sq*sy1sq); - pc[2] = -xposmean*pc[0] - yposmean*pc[1] + ximean; + pc[0] = (sx1y1 * sy1x2 - sx1x2 * sy1sq) / (sx1y1 * sx1y1 - sx1sq * sy1sq); + pc[1] = (sx1x2 * sx1y1 - sx1sq * sy1x2) / (sx1y1 * sx1y1 - sx1sq * sy1sq); + pc[2] = -xposmean * pc[0] - yposmean * pc[1] + ximean; /* Now the solution for Y */ - pc[3] = (sy1y2*sx1y1 - sy1sq*sx1y2)/(sx1y1*sx1y1 - sy1sq*sx1sq); - pc[4] = (sx1y1*sx1y2 - sy1y2*sx1sq)/(sx1y1*sx1y1 - sy1sq*sx1sq); - pc[5] = -xposmean*pc[3] - yposmean*pc[4] + etamean; - + pc[3] = (sy1y2 * sx1y1 - sy1sq * sx1y2) / (sx1y1 * sx1y1 - sy1sq * sx1sq); + pc[4] = (sx1y1 * sx1y2 - sy1y2 * sx1sq) / (sx1y1 * sx1y1 - sy1sq * sx1sq); + pc[5] = -xposmean * pc[3] - yposmean * pc[4] + etamean; } /** @@ -1799,17 +1673,21 @@ * */ -static void cpl_wcs_platesol_4(const cpl_matrix *xy, const cpl_matrix *std, - const cpl_array *bad, cpl_array **plateconsts) { - double sx1sq,sy1sq,sx1x2,sy1x2,sy1y2,sx1y2,xposmean,yposmean,*pc; - double ximean,etamean,xx1,yy1,xx2,yy2,det,num,denom,theta,mag; - double stheta,ctheta; +static void +cpl_wcs_platesol_4(const cpl_matrix *xy, + const cpl_matrix *std, + const cpl_array *bad, + cpl_array **plateconsts) +{ + double sx1sq, sy1sq, sx1x2, sy1x2, sy1y2, sx1y2, xposmean, yposmean, *pc; + double ximean, etamean, xx1, yy1, xx2, yy2, det, num, denom, theta, mag; + double stheta, ctheta; /* Get some convenience variables */ - const double *xydata = cpl_matrix_get_data_const(xy); - const double *stddata = cpl_matrix_get_data_const(std); - const int *isbad = cpl_array_get_data_int_const(bad); + const double *xydata = cpl_matrix_get_data_const(xy); + const double *stddata = cpl_matrix_get_data_const(std); + const int *isbad = cpl_array_get_data_int_const(bad); const cpl_size nstds = cpl_array_get_size(bad); - cpl_size i,ngood; + cpl_size i, ngood; /* Initialise all the counters and summations */ @@ -1831,10 +1709,10 @@ for (i = 0; i < nstds; i++) { if (isbad[i] != 0) continue; - xposmean += xydata[2*i]; - yposmean += xydata[2*i+1]; - ximean += stddata[2*i]; - etamean += stddata[2*i+1]; + xposmean += xydata[2 * i]; + yposmean += xydata[2 * i + 1]; + ximean += stddata[2 * i]; + etamean += stddata[2 * i + 1]; ngood++; } xposmean /= (double)ngood; @@ -1845,34 +1723,36 @@ /* Now accumulate the sums */ for (i = 0; i < nstds; i++) { - if (! isbad[i]) { - xx1 = xydata[2*i] - xposmean; - yy1 = xydata[2*i+1] - yposmean; - xx2 = stddata[2*i] - ximean; - yy2 = stddata[2*i+1] - etamean; - sx1sq += xx1*xx1; - sy1sq += yy1*yy1; - sx1x2 += xx1*xx2; - sy1x2 += yy1*xx2; - sy1y2 += yy1*yy2; - sx1y2 += xx1*yy2; + if (!isbad[i]) { + xx1 = xydata[2 * i] - xposmean; + yy1 = xydata[2 * i + 1] - yposmean; + xx2 = stddata[2 * i] - ximean; + yy2 = stddata[2 * i + 1] - etamean; + sx1sq += xx1 * xx1; + sy1sq += yy1 * yy1; + sx1x2 += xx1 * xx2; + sy1x2 += yy1 * xx2; + sy1y2 += yy1 * yy2; + sx1y2 += xx1 * yy2; } } /* Compute the rotation angle */ - det = sx1x2*sy1y2 - sy1x2*sx1y2; + det = sx1x2 * sy1y2 - sy1x2 * sx1y2; if (det < 0.0) { num = sy1x2 + sx1y2; denom = -sx1x2 + sy1y2; - } else { + } + else { num = sy1x2 - sx1y2; denom = sx1x2 + sy1y2; } if (num == 0.0 && denom == 0.0) { theta = 0.0; - } else { - theta = atan2(num,denom); + } + else { + theta = atan2(num, denom); if (theta < 0.0) theta += CPL_MATH_2PI; } @@ -1881,39 +1761,40 @@ ctheta = cos(theta); stheta = sin(theta); - num = denom*ctheta + num*stheta; + num = denom * ctheta + num * stheta; denom = sx1sq + sy1sq; if (denom <= 0.0) { mag = 1.0; - } else { - mag = num/denom; + } + else { + mag = num / denom; } /* Get an output array for the results */ - *plateconsts = cpl_array_new(6,CPL_TYPE_DOUBLE); + *plateconsts = cpl_array_new(6, CPL_TYPE_DOUBLE); pc = cpl_array_get_data_double(*plateconsts); /* Compute coeffs */ if (det < 0.0) { - pc[0] = -mag*ctheta; - pc[3] = mag*stheta; - } else { - pc[0] = mag*ctheta; - pc[3] = -mag*stheta; - } - pc[1] = mag*stheta; - pc[4] = mag*ctheta; - pc[2] = -xposmean*pc[0] - yposmean*pc[1] + ximean; - pc[5] = -xposmean*pc[3] - yposmean*pc[4] + etamean; + pc[0] = -mag * ctheta; + pc[3] = mag * stheta; + } + else { + pc[0] = mag * ctheta; + pc[3] = -mag * stheta; + } + pc[1] = mag * stheta; + pc[4] = mag * ctheta; + pc[2] = -xposmean * pc[0] - yposmean * pc[1] + ximean; + pc[5] = -xposmean * pc[3] - yposmean * pc[4] + etamean; } inline static int _cpl_wcs_set_cd(cpl_wcs *self) { - register int k; @@ -1925,28 +1806,24 @@ */ for (k = 0; k < self->naxis; ++k) { - register int l; register double _cdelt = self->wcsptr->lin.cdelt[k]; - double *_pc = &self->wcsptr->lin.pc[k * self->naxis]; + double *_pc = &self->wcsptr->lin.pc[k * self->naxis]; for (l = 0; l < self->naxis; ++l) { - cpl_matrix_set(self->cd, k, l, _cdelt * _pc[l]); + cpl_matrix_set_(self->cd, k, l, _cdelt * _pc[l]); } - } return 0; - } inline static int _cpl_wcs_set_ctype(cpl_wcs *self) { - register int k; for (k = 0; k < self->naxis; ++k) { @@ -1960,7 +1837,6 @@ inline static int _cpl_wcs_set_cunit(cpl_wcs *self) { - register int k; for (k = 0; k < self->naxis; ++k) { @@ -1994,7 +1870,6 @@ inline static int _cpl_wcsset(cpl_wcs *wcs) { - struct wcsprm *_wcs = wcs->wcsptr; int status = wcsset(_wcs); @@ -2009,126 +1884,6 @@ _cpl_wcs_set_cunit(wcs); return status; - } - -#ifndef fits_write_hdu - -/*-------------------------------------------------------------------------*/ -/* - * NOTE: - * Work around for cfitsio-2.5.10 memory errors in ffhdr2str(). This - * problem has been fixed in cfitsio > 3.0.3. - * In spite of the above comment: The below work-around is disabled for - * cfitsio version >= 3.03, so we'll stick with that. - */ -/* - read header keywords into a long string of chars. This routine allocates - memory for the string, so the calling routine must eventually free the - memory when it is not needed any more. If exclude_comm is TRUE, then all - the COMMENT, HISTORY, and keywords will be excluded from the output - string of keywords. Any other list of keywords to be excluded may be - specified with the exclist parameter. -*/ - -static int cpl_wcs_ffhdr2str( - fitsfile *fptr, /* I - FITS file pointer */ - int exclude_comm, /* I - if TRUE, exclude commentary keywords */ - char **exclist, /* I - list of excluded keyword names */ - int nexc, /* I - number of names in exclist */ - char **header, /* O - returned header string */ - int *nkeys, /* O - returned number of 80-char keywords */ - int *status) /* IO - error status */ -{ - - int casesn, match, exact, totkeys; - long ii, jj; - char keybuf[162], keyname[FLEN_KEYWORD], *headptr; - - /* NOTE: Use the actual CFITSIO function if the - version number is more recent than 3.0.3 */ - float version; - fits_get_version(&version); - - if (version >= 3.030) - return ffhdr2str(fptr, exclude_comm, exclist, nexc, header, nkeys, status); - - - *nkeys = 0; - - if (*status > 0) - return(*status); - - /* get number of keywords in the header (doesn't include END) */ - if (ffghsp(fptr, &totkeys, NULL, status) > 0) - return(*status); - - /* allocate memory for all the keywords (multiple of 2880 bytes) */ - *header = (char *) calloc ( (totkeys + 1) * 80 + 1, 1); - if (!(*header)) - { - *status = MEMORY_ALLOCATION; - ffpmsg("failed to allocate memory to hold all the header keywords"); - return(*status); - } - - headptr = *header; - casesn = FALSE; - - /* read every keyword */ - for (ii = 1; ii <= totkeys; ii++) - { - ffgrec(fptr, ii, keybuf, status); - /* pad record with blanks so that it is at least 80 chars long */ - strcat(keybuf, - " "); - - keyname[0] = '\0'; - strncat(keyname, keybuf, 8); /* copy the keyword name */ - - if (exclude_comm) - { - if (!FSTRCMP("COMMENT ", keyname) || - !FSTRCMP("HISTORY ", keyname) || - !FSTRCMP(" ", keyname) ) - continue; /* skip this commentary keyword */ - } - - /* does keyword match any names in the exclusion list? */ - for (jj = 0; jj < nexc; jj++ ) - { - ffcmps(exclist[jj], keyname, casesn, &match, &exact); - if (match) - break; - } - - if (jj == nexc) - { - /* not in exclusion list, add this keyword to the string */ - strcpy(headptr, keybuf); - headptr += 80; - (*nkeys)++; - } - } - - /* add the END keyword */ - strcpy(headptr, - "END "); - headptr += 80; - (*nkeys)++; - - *headptr = '\0'; /* terminate the header string */ - - /* - * This is the actual fix for this function - * (Version 2.510 forgot to assign result to *header) - */ - *header = realloc(*header, (*nkeys *80) + 1); /* minimize the allocated memory */ - - return(*status); -} - -#endif - -#endif /* End If WCS is installed */ +#endif /* End If WCS is installed */ diff -Nru cpl-7.1.4+ds/cpldrs/cpl_wcs.h cpl-7.2.2+ds/cpldrs/cpl_wcs.h --- cpl-7.1.4+ds/cpldrs/cpl_wcs.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cpldrs/cpl_wcs.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -31,25 +31,31 @@ /* Enumerate the modes available for the convert routine */ -enum cpl_wcs_trans_mode { +enum cpl_wcs_trans_mode +{ CPL_WCS_PHYS2WORLD, CPL_WCS_WORLD2PHYS, CPL_WCS_PHYS2STD, - CPL_WCS_WORLD2STD}; + CPL_WCS_WORLD2STD +}; typedef enum cpl_wcs_trans_mode cpl_wcs_trans_mode; /* Enumerate the modes available for the plate solution routine */ -enum cpl_wcs_platesol_fitmode { +enum cpl_wcs_platesol_fitmode +{ CPL_WCS_PLATESOL_6, - CPL_WCS_PLATESOL_4}; + CPL_WCS_PLATESOL_4 +}; typedef enum cpl_wcs_platesol_fitmode cpl_wcs_platesol_fitmode; -enum cpl_wcs_platesol_outmode { +enum cpl_wcs_platesol_outmode +{ CPL_WCS_MV_CRVAL, - CPL_WCS_MV_CRPIX}; + CPL_WCS_MV_CRPIX +}; typedef enum cpl_wcs_platesol_outmode cpl_wcs_platesol_outmode; @@ -62,22 +68,27 @@ @brief A regular expression that matches the FITS keys used for WCS */ /*----------------------------------------------------------------------------*/ -#define CPL_WCS_REGEXP "WCSAXES|WCSNAME|(PC|CD|PV|PS)[0-9]+_[0-9]+|" \ +#define CPL_WCS_REGEXP \ + "WCSAXES|WCSNAME|(PC|CD|PV|PS)[0-9]+_[0-9]+|" \ "C(RVAL|RPIX|DELT|TYPE|UNIT|RDER|SYER)[0-9]+" /* Function prototypes */ CPL_BEGIN_DECLS -cpl_wcs *cpl_wcs_new_from_propertylist(const cpl_propertylist *plist) - CPL_ATTR_ALLOC; +cpl_wcs * +cpl_wcs_new_from_propertylist(const cpl_propertylist *plist) CPL_ATTR_ALLOC; void cpl_wcs_delete(cpl_wcs *wcs); -cpl_error_code cpl_wcs_convert(const cpl_wcs *wcs, const cpl_matrix *from, - cpl_matrix **to, cpl_array **status, +cpl_error_code cpl_wcs_convert(const cpl_wcs *wcs, + const cpl_matrix *from, + cpl_matrix **to, + cpl_array **status, cpl_wcs_trans_mode transform); cpl_error_code cpl_wcs_platesol(const cpl_propertylist *ilist, const cpl_matrix *cel, - const cpl_matrix *xy, int niter, float thresh, + const cpl_matrix *xy, + int niter, + float thresh, cpl_wcs_platesol_fitmode fitmode, cpl_wcs_platesol_outmode outmode, cpl_propertylist **olist); @@ -95,4 +106,3 @@ CPL_END_DECLS #endif /* CPL_WCS_H */ - diff -Nru cpl-7.1.4+ds/cpldrs/cpl_wlcalib.c cpl-7.2.2+ds/cpldrs/cpl_wlcalib.c --- cpl-7.1.4+ds/cpldrs/cpl_wlcalib.c 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cpldrs/cpl_wlcalib.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -70,54 +70,53 @@ New Types -----------------------------------------------------------------------------*/ -struct cpl_wlcalib_slitmodel_ { - cpl_size cost; /* May be incremented for cost counting */ - cpl_size xcost; /* Ditto (can exclude failed fills) */ - cpl_size ulines; /* May be set to number of lines used */ - - double wslit; /* Slit Width */ - double wfwhm; /* FWHM of transfer function */ - double lthres; /* Line truncation threshold */ - cpl_bivector * lines; /* Catalog of intensities, with +struct cpl_wlcalib_slitmodel_ +{ + cpl_size cost; /* May be incremented for cost counting */ + cpl_size xcost; /* Ditto (can exclude failed fills) */ + cpl_size ulines; /* May be set to number of lines used */ + + double wslit; /* Slit Width */ + double wfwhm; /* FWHM of transfer function */ + double lthres; /* Line truncation threshold */ + cpl_bivector *lines; /* Catalog of intensities, with increasing X-vector elements */ /* Private members, filled automatically */ - cpl_vector * linepix; /* Catalog of line pixel positions + cpl_vector *linepix; /* Catalog of line pixel positions - zero for uninitialized */ - cpl_vector * erftmp; /* Temporary storage for erf() values + cpl_vector *erftmp; /* Temporary storage for erf() values - zero for uninitialized */ }; - /*----------------------------------------------------------------------------- Private Function Prototypes -----------------------------------------------------------------------------*/ inline static double cpl_erf_antideriv(double x, double); -static -cpl_error_code cpl_wlcalib_fill_line_spectrum_model(cpl_vector *, - cpl_vector *, - cpl_vector **, - const cpl_polynomial *, - const cpl_bivector *, - double, - double, - double, - cpl_size, - cpl_boolean, - cpl_boolean, - cpl_size *); - -static -cpl_error_code cpl_wlcalib_evaluate(cpl_vector *, - cpl_size *, - cpl_vector *, - const cpl_vector *, - void *, - cpl_error_code (*)(cpl_vector *, void *, - const cpl_polynomial *), - const cpl_polynomial *); +static cpl_error_code +cpl_wlcalib_fill_line_spectrum_model(cpl_vector *, + cpl_vector *, + cpl_vector **, + const cpl_polynomial *, + const cpl_bivector *, + double, + double, + double, + cpl_size, + cpl_boolean, + cpl_boolean, + cpl_size *); + +static cpl_error_code cpl_wlcalib_evaluate( + cpl_vector *, + cpl_size *, + cpl_vector *, + const cpl_vector *, + void *, + cpl_error_code (*)(cpl_vector *, void *, const cpl_polynomial *), + const cpl_polynomial *); /*----------------------------------------------------------------------------- Function Prototypes @@ -144,12 +143,11 @@ */ /*----------------------------------------------------------------------------*/ -cpl_wlcalib_slitmodel * cpl_wlcalib_slitmodel_new(void) +cpl_wlcalib_slitmodel * +cpl_wlcalib_slitmodel_new(void) { - - return - (cpl_wlcalib_slitmodel*)cpl_calloc(1, sizeof(cpl_wlcalib_slitmodel)); - + return (cpl_wlcalib_slitmodel *)cpl_calloc(1, + sizeof(cpl_wlcalib_slitmodel)); } @@ -163,11 +161,10 @@ */ /*----------------------------------------------------------------------------*/ -void cpl_wlcalib_slitmodel_delete(cpl_wlcalib_slitmodel * self) +void +cpl_wlcalib_slitmodel_delete(cpl_wlcalib_slitmodel *self) { - if (self != NULL) { - cpl_bivector_delete(self->lines); cpl_vector_delete(self->linepix); cpl_vector_delete(self->erftmp); @@ -194,11 +191,10 @@ - CPL_ERROR_NULL_INPUT if an input pointer is @em NULL */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_wlcalib_slitmodel_add_cost(cpl_wlcalib_slitmodel * self, - cpl_size value) +cpl_error_code +cpl_wlcalib_slitmodel_add_cost(cpl_wlcalib_slitmodel *self, cpl_size value) { - - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); self->cost += value; @@ -220,11 +216,10 @@ - CPL_ERROR_NULL_INPUT if an input pointer is @em NULL */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_wlcalib_slitmodel_add_xcost(cpl_wlcalib_slitmodel * self, - cpl_size value) +cpl_error_code +cpl_wlcalib_slitmodel_add_xcost(cpl_wlcalib_slitmodel *self, cpl_size value) { - - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); self->xcost += value; @@ -246,11 +241,10 @@ - CPL_ERROR_NULL_INPUT if an input pointer is @em NULL */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_wlcalib_slitmodel_add_ulines(cpl_wlcalib_slitmodel * self, - cpl_size value) +cpl_error_code +cpl_wlcalib_slitmodel_add_ulines(cpl_wlcalib_slitmodel *self, cpl_size value) { - - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); self->ulines += value; @@ -270,12 +264,11 @@ - CPL_ERROR_ILLEGAL_INPUT the value is non-positive */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_wlcalib_slitmodel_set_wslit(cpl_wlcalib_slitmodel * self, - double value) +cpl_error_code +cpl_wlcalib_slitmodel_set_wslit(cpl_wlcalib_slitmodel *self, double value) { - - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(value > 0.0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(value > 0.0, CPL_ERROR_ILLEGAL_INPUT); self->wslit = value; @@ -296,12 +289,11 @@ - CPL_ERROR_ILLEGAL_INPUT the value is non-positive */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_wlcalib_slitmodel_set_wfwhm(cpl_wlcalib_slitmodel * self, - double value) +cpl_error_code +cpl_wlcalib_slitmodel_set_wfwhm(cpl_wlcalib_slitmodel *self, double value) { - - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(value > 0.0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(value > 0.0, CPL_ERROR_ILLEGAL_INPUT); self->wfwhm = value; @@ -330,12 +322,11 @@ - CPL_ERROR_ILLEGAL_INPUT the value is negative */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_wlcalib_slitmodel_set_threshold(cpl_wlcalib_slitmodel * self, - double value) +cpl_error_code +cpl_wlcalib_slitmodel_set_threshold(cpl_wlcalib_slitmodel *self, double value) { - - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(value >= 0.0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(value >= 0.0, CPL_ERROR_ILLEGAL_INPUT); self->lthres = value; @@ -357,11 +348,11 @@ - CPL_ERROR_NULL_INPUT if an input pointer is @em NULL */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_wlcalib_slitmodel_set_catalog(cpl_wlcalib_slitmodel * self, - cpl_bivector * catalog) +cpl_error_code +cpl_wlcalib_slitmodel_set_catalog(cpl_wlcalib_slitmodel *self, + cpl_bivector *catalog) { - - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(catalog != NULL, CPL_ERROR_NULL_INPUT); cpl_bivector_delete(self->lines); @@ -383,9 +374,9 @@ - CPL_ERROR_NULL_INPUT if an input pointer is @em NULL */ /*----------------------------------------------------------------------------*/ -double cpl_wlcalib_slitmodel_get_wslit(const cpl_wlcalib_slitmodel * self) +double +cpl_wlcalib_slitmodel_get_wslit(const cpl_wlcalib_slitmodel *self) { - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, 0.0); return self->wslit; @@ -403,9 +394,9 @@ - CPL_ERROR_NULL_INPUT if an input pointer is @em NULL */ /*----------------------------------------------------------------------------*/ -double cpl_wlcalib_slitmodel_get_wfwhm(const cpl_wlcalib_slitmodel * self) +double +cpl_wlcalib_slitmodel_get_wfwhm(const cpl_wlcalib_slitmodel *self) { - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, 0.0); return self->wfwhm; @@ -423,9 +414,9 @@ - CPL_ERROR_NULL_INPUT if an input pointer is @em NULL */ /*----------------------------------------------------------------------------*/ -double cpl_wlcalib_slitmodel_get_threshold(const cpl_wlcalib_slitmodel * self) +double +cpl_wlcalib_slitmodel_get_threshold(const cpl_wlcalib_slitmodel *self) { - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, 0.0); return self->lthres; @@ -443,9 +434,9 @@ - CPL_ERROR_NULL_INPUT if an input pointer is @em NULL */ /*----------------------------------------------------------------------------*/ -cpl_bivector * cpl_wlcalib_slitmodel_get_catalog(cpl_wlcalib_slitmodel * self) +cpl_bivector * +cpl_wlcalib_slitmodel_get_catalog(cpl_wlcalib_slitmodel *self) { - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); return self->lines; @@ -464,9 +455,8 @@ */ /*----------------------------------------------------------------------------*/ const cpl_bivector * -cpl_wlcalib_slitmodel_get_catalog_const(const cpl_wlcalib_slitmodel * self) +cpl_wlcalib_slitmodel_get_catalog_const(const cpl_wlcalib_slitmodel *self) { - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); return self->lines; @@ -485,10 +475,10 @@ - CPL_ERROR_NULL_INPUT if an input pointer is @em NULL */ /*----------------------------------------------------------------------------*/ -cpl_bivector * cpl_wlcalib_slitmodel_unset_catalog(cpl_wlcalib_slitmodel * self) +cpl_bivector * +cpl_wlcalib_slitmodel_unset_catalog(cpl_wlcalib_slitmodel *self) { - - cpl_bivector * lines; + cpl_bivector *lines; cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); @@ -511,7 +501,8 @@ - CPL_ERROR_NULL_INPUT if an input pointer is @em NULL */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_wlcalib_slitmodel_get_cost(const cpl_wlcalib_slitmodel * self) +cpl_size +cpl_wlcalib_slitmodel_get_cost(const cpl_wlcalib_slitmodel *self) { cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, 0); @@ -531,7 +522,8 @@ - CPL_ERROR_NULL_INPUT if an input pointer is @em NULL */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_wlcalib_slitmodel_get_xcost(const cpl_wlcalib_slitmodel * self) +cpl_size +cpl_wlcalib_slitmodel_get_xcost(const cpl_wlcalib_slitmodel *self) { cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, 0); @@ -551,7 +543,8 @@ - CPL_ERROR_NULL_INPUT if an input pointer is @em NULL */ /*----------------------------------------------------------------------------*/ -cpl_size cpl_wlcalib_slitmodel_get_ulines(const cpl_wlcalib_slitmodel * self) +cpl_size +cpl_wlcalib_slitmodel_get_ulines(const cpl_wlcalib_slitmodel *self) { cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, 0); @@ -622,25 +615,21 @@ found to be in non-increasing order. */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_wlcalib_fill_line_spectrum(cpl_vector * self, - void * model, - const cpl_polynomial * disp) +cpl_error_code +cpl_wlcalib_fill_line_spectrum(cpl_vector *self, + void *model, + const cpl_polynomial *disp) { - cpl_wlcalib_slitmodel * mymodel = (cpl_wlcalib_slitmodel *)model; + cpl_wlcalib_slitmodel *mymodel = (cpl_wlcalib_slitmodel *)model; const cpl_size hsize = 0; /* FIXME: remove */ cpl_ensure_code(model != NULL, CPL_ERROR_NULL_INPUT); mymodel->cost++; - if (cpl_wlcalib_fill_line_spectrum_model(self, - mymodel->linepix, - NULL, - disp, - mymodel->lines, - mymodel->wslit, - mymodel->wfwhm, - mymodel->lthres, + if (cpl_wlcalib_fill_line_spectrum_model(self, mymodel->linepix, NULL, disp, + mymodel->lines, mymodel->wslit, + mymodel->wfwhm, mymodel->lthres, hsize, CPL_FALSE, CPL_FALSE, &(mymodel->ulines))) { return cpl_error_set_where_(); @@ -664,26 +653,21 @@ */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_wlcalib_fill_logline_spectrum(cpl_vector * self, - void * model, - const cpl_polynomial * disp) +cpl_error_code +cpl_wlcalib_fill_logline_spectrum(cpl_vector *self, + void *model, + const cpl_polynomial *disp) { - - cpl_wlcalib_slitmodel * mymodel = (cpl_wlcalib_slitmodel *)model; + cpl_wlcalib_slitmodel *mymodel = (cpl_wlcalib_slitmodel *)model; const cpl_size hsize = 0; /* FIXME: remove */ cpl_ensure_code(model != NULL, CPL_ERROR_NULL_INPUT); mymodel->cost++; - if (cpl_wlcalib_fill_line_spectrum_model(self, - mymodel->linepix, - NULL, - disp, - mymodel->lines, - mymodel->wslit, - mymodel->wfwhm, - mymodel->lthres, + if (cpl_wlcalib_fill_line_spectrum_model(self, mymodel->linepix, NULL, disp, + mymodel->lines, mymodel->wslit, + mymodel->wfwhm, mymodel->lthres, hsize, CPL_FALSE, CPL_TRUE, &(mymodel->ulines))) { return cpl_error_set_where_(); @@ -716,26 +700,21 @@ */ /*----------------------------------------------------------------------------*/ cpl_error_code -cpl_wlcalib_fill_line_spectrum_fast(cpl_vector * self, - void * model, - const cpl_polynomial * disp) +cpl_wlcalib_fill_line_spectrum_fast(cpl_vector *self, + void *model, + const cpl_polynomial *disp) { - - cpl_wlcalib_slitmodel * mymodel = (cpl_wlcalib_slitmodel *)model; + cpl_wlcalib_slitmodel *mymodel = (cpl_wlcalib_slitmodel *)model; const cpl_size hsize = 0; /* FIXME: remove */ cpl_ensure_code(model != NULL, CPL_ERROR_NULL_INPUT); mymodel->cost++; - if (cpl_wlcalib_fill_line_spectrum_model(self, - mymodel->linepix, - &(mymodel->erftmp), - disp, - mymodel->lines, - mymodel->wslit, - mymodel->wfwhm, - mymodel->lthres, + if (cpl_wlcalib_fill_line_spectrum_model(self, mymodel->linepix, + &(mymodel->erftmp), disp, + mymodel->lines, mymodel->wslit, + mymodel->wfwhm, mymodel->lthres, hsize, CPL_TRUE, CPL_FALSE, &(mymodel->ulines))) { return cpl_error_set_where_(); @@ -759,26 +738,21 @@ */ /*----------------------------------------------------------------------------*/ cpl_error_code -cpl_wlcalib_fill_logline_spectrum_fast(cpl_vector * self, - void * model, - const cpl_polynomial * disp) +cpl_wlcalib_fill_logline_spectrum_fast(cpl_vector *self, + void *model, + const cpl_polynomial *disp) { - - cpl_wlcalib_slitmodel * mymodel = (cpl_wlcalib_slitmodel *)model; + cpl_wlcalib_slitmodel *mymodel = (cpl_wlcalib_slitmodel *)model; const cpl_size hsize = 0; /* FIXME: remove */ cpl_ensure_code(model != NULL, CPL_ERROR_NULL_INPUT); mymodel->cost++; - if (cpl_wlcalib_fill_line_spectrum_model(self, - mymodel->linepix, - &(mymodel->erftmp), - disp, - mymodel->lines, - mymodel->wslit, - mymodel->wfwhm, - mymodel->lthres, + if (cpl_wlcalib_fill_line_spectrum_model(self, mymodel->linepix, + &(mymodel->erftmp), disp, + mymodel->lines, mymodel->wslit, + mymodel->wfwhm, mymodel->lthres, hsize, CPL_TRUE, CPL_TRUE, &(mymodel->ulines))) { return cpl_error_set_where_(); @@ -841,48 +815,50 @@ supplied model and filler */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_wlcalib_find_best_1d(cpl_polynomial * self, - const cpl_polynomial * guess, - const cpl_vector * spectrum, - void * model, - cpl_error_code (* filler)(cpl_vector *, - void *, const cpl_polynomial *), - const cpl_vector * wl_search, - cpl_size nsamples, - cpl_size hsize, - double * xcmax, - cpl_vector * xcorrs) -{ - cpl_errorstate prestate = cpl_errorstate_get(); - cpl_errorstate errorstate = prestate; /* Fix (false) uninit warning */ - const cpl_size spec_sz = cpl_vector_get_size(spectrum); - const cpl_size nfree = cpl_vector_get_size(wl_search); - const cpl_size degree = nfree - 1; - const cpl_size nxc = 1 + 2 * hsize; - cpl_size ntests = 1; - cpl_vector * spmodel; - cpl_vector * vxc; - cpl_vector * init_pts_wl; - cpl_vector * init_pts_x; - cpl_vector * pts_wl; - cpl_vector * conv_kernel = NULL; - cpl_polynomial * cand; - double * xcdata = xcorrs ? cpl_vector_get_data(xcorrs) : NULL; - const double * pwl_search = cpl_vector_get_data_const(wl_search); - const double * pinit_pts_wl; - double * ppts_wl; - cpl_boolean has_solution = CPL_FALSE; - cpl_boolean has_no_error = CPL_TRUE; - cpl_size i; +cpl_error_code +cpl_wlcalib_find_best_1d(cpl_polynomial *self, + const cpl_polynomial *guess, + const cpl_vector *spectrum, + void *model, + cpl_error_code (*filler)(cpl_vector *, + void *, + const cpl_polynomial *), + const cpl_vector *wl_search, + cpl_size nsamples, + cpl_size hsize, + double *xcmax, + cpl_vector *xcorrs) +{ + cpl_errorstate prestate = cpl_errorstate_get(); + cpl_errorstate errorstate = prestate; /* Fix (false) uninit warning */ + const cpl_size spec_sz = cpl_vector_get_size(spectrum); + const cpl_size nfree = cpl_vector_get_size(wl_search); + const cpl_size degree = nfree - 1; + const cpl_size nxc = 1 + 2 * hsize; + cpl_size ntests = 1; + cpl_vector *spmodel; + cpl_vector *vxc; + cpl_vector *init_pts_wl; + cpl_vector *init_pts_x; + cpl_vector *pts_wl; + cpl_vector *conv_kernel = NULL; + cpl_polynomial *cand; + double *xcdata = xcorrs ? cpl_vector_get_data(xcorrs) : NULL; + const double *pwl_search = cpl_vector_get_data_const(wl_search); + const double *pinit_pts_wl; + double *ppts_wl; + cpl_boolean has_solution = CPL_FALSE; + cpl_boolean has_no_error = CPL_TRUE; + cpl_size i; - cpl_ensure_code(xcmax != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(xcmax != NULL, CPL_ERROR_NULL_INPUT); *xcmax = -1.0; /* In case of failure */ - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(guess != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(spectrum != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(model != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(filler != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(guess != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(spectrum != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(model != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(filler != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(wl_search != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(cpl_polynomial_get_dimension(self) == 1, @@ -890,15 +866,16 @@ cpl_ensure_code(cpl_polynomial_get_dimension(guess) == 1, CPL_ERROR_INVALID_TYPE); - cpl_ensure_code(nfree >= 2, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(nsamples > 0, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(hsize >= 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(nfree >= 2, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(nsamples > 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(hsize >= 0, CPL_ERROR_ILLEGAL_INPUT); if (nsamples > 1) { /* Search place must consist of more than one point */ /* FIXME: The bounds should probably not be negative */ for (i = 0; i < nfree; i++) { - if (pwl_search[i] != 0.0) break; + if (pwl_search[i] != 0.0) + break; } cpl_ensure_code(i < nfree, CPL_ERROR_ILLEGAL_INPUT); } @@ -908,21 +885,20 @@ cpl_ensure_code(cpl_vector_get_size(xcorrs) >= ncand, CPL_ERROR_ILLEGAL_INPUT); } - + /* Create initial test points */ - init_pts_x = cpl_vector_new(nfree); + init_pts_x = cpl_vector_new(nfree); init_pts_wl = cpl_vector_new(nfree); - pts_wl = cpl_vector_new(nfree); + pts_wl = cpl_vector_new(nfree); for (i = 0; i < nfree; i++) { - const double xpos = spec_sz * i / (double)degree; - const double wlpos = cpl_polynomial_eval_1d(guess, xpos, NULL) - - 0.5 * pwl_search[i]; + const double xpos = spec_sz * i / (double)degree; + const double wlpos = + cpl_polynomial_eval_1d(guess, xpos, NULL) - 0.5 * pwl_search[i]; - cpl_vector_set(init_pts_x, i, xpos); + cpl_vector_set(init_pts_x, i, xpos); cpl_vector_set(init_pts_wl, i, wlpos); ntests *= nsamples; /* Count number of tests */ - } cand = cpl_polynomial_new(1); @@ -933,18 +909,18 @@ /* Create the polynomial candidates and estimate them */ for (i = 0; i < ntests; i++) { - cpl_size idiv = i; - cpl_size deg; + cpl_size idiv = i; + cpl_size deg; cpl_error_code error = CPL_ERROR_NONE; /* Update wavelength at one anchor point - and reset wavelengths to their default for any anchor point(s) at higher wavelengths */ for (deg = degree; deg >= 0; deg--, idiv /= nsamples) { - const cpl_size imod = idiv % nsamples; - const double wlpos = pinit_pts_wl[deg] - + imod * pwl_search[deg] / nsamples; + const cpl_size imod = idiv % nsamples; + const double wlpos = + pinit_pts_wl[deg] + imod * pwl_search[deg] / nsamples; - if (deg < degree && wlpos >= ppts_wl[deg+1]) { + if (deg < degree && wlpos >= ppts_wl[deg + 1]) { /* The current anchor points do not form a monotonely increasing sequence. This is not physical, so mark the polynomial as invalid. Still need to complete loop @@ -954,18 +930,17 @@ } ppts_wl[deg] = wlpos; - if (imod > 0) break; + if (imod > 0) + break; } if (!error) { - has_no_error = cpl_errorstate_is_equal(prestate); /* Fit the candidate polynomial, init_pts_x is symmetric */ - error = cpl_polynomial_fit_1d(cand, init_pts_x, pts_wl, 0, degree, - CPL_TRUE, NULL); + error = cpl_polynomial_fit_1d(cand, init_pts_x, pts_wl, NULL, 0, + degree, CPL_TRUE, NULL); if (!error && cpl_polynomial_get_degree(cand) > 0) { - /* In spmodel input pixel 0 is at position hsize, shift accordingly */ error = cpl_polynomial_shift_1d(cand, 0, -hsize); @@ -997,11 +972,13 @@ cpl_errorstate_dump_one_debug); #endif cpl_errorstate_set(prestate); - } else if (has_no_error) { + } + else if (has_no_error) { /* Keep error(s) from 1st failed try in case no solutions are found */ errorstate = cpl_errorstate_get(); - } else { + } + else { /* Reset all subsequent errors - which may be many */ #ifdef CPL_WLCALIB_DEBUG cpl_errorstate_dump(errorstate, CPL_FALSE, @@ -1013,7 +990,8 @@ } if (xcdata != NULL) { - if (error) (void)cpl_vector_fill(vxc, -1.0); + if (error) + (void)cpl_vector_fill(vxc, -1.0); xcdata += nxc; (void)cpl_vector_rewrap(vxc, nxc, xcdata); } @@ -1027,8 +1005,8 @@ cpl_vector_delete(init_pts_wl); cpl_polynomial_delete(cand); - return has_solution ? CPL_ERROR_NONE : - cpl_error_set_(CPL_ERROR_DATA_NOT_FOUND); + return has_solution ? CPL_ERROR_NONE + : cpl_error_set_(CPL_ERROR_DATA_NOT_FOUND); } /**@}*/ @@ -1054,53 +1032,52 @@ */ /*----------------------------------------------------------------------------*/ -static -cpl_error_code cpl_wlcalib_fill_line_spectrum_model(cpl_vector * self, - cpl_vector * linepix, - cpl_vector ** perftmp, - const cpl_polynomial * disp, - const cpl_bivector * lines, - double wslit, - double wfwhm, - double lthres, - cpl_size hsize, - cpl_boolean dofast, - cpl_boolean dolog, - cpl_size * pulines) -{ - cpl_errorstate prestate; - const double sigma = wfwhm * CPL_MATH_SIG_FWHM; - const cpl_vector * xlines = cpl_bivector_get_x_const(lines); - const double * dxlines = cpl_vector_get_data_const(xlines); - const double * dylines = cpl_bivector_get_y_data_const(lines); - double * plinepix - = linepix ? cpl_vector_get_data(linepix) : NULL; - const cpl_size nlines = cpl_vector_get_size(xlines); - const cpl_size nself = cpl_vector_get_size(self); - double * dself = cpl_vector_get_data(self); - cpl_polynomial * dispi; - double * profile = NULL; - cpl_size i0 = 0; - const double p0 = cpl_polynomial_get_coeff(disp, &i0); - const cpl_size degree = cpl_polynomial_get_degree(disp); - double wl; - const double xtrunc = 0.5 * wslit + lthres * sigma; - double xpos = (double)(1-hsize)-xtrunc; - const double xmax = (double)(nself-hsize)+xtrunc; - double xderiv; - cpl_error_code error = CPL_ERROR_NONE; - cpl_size iline; - cpl_size ulines = 0; - - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(disp != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(lines != NULL, CPL_ERROR_NULL_INPUT); - - cpl_ensure_code(wslit > 0.0, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(wfwhm > 0.0, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(hsize >= 0, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(xtrunc > 0.0, CPL_ERROR_ILLEGAL_INPUT); - cpl_ensure_code(nself > 2 * hsize, CPL_ERROR_ILLEGAL_INPUT); +static cpl_error_code +cpl_wlcalib_fill_line_spectrum_model(cpl_vector *self, + cpl_vector *linepix, + cpl_vector **perftmp, + const cpl_polynomial *disp, + const cpl_bivector *lines, + double wslit, + double wfwhm, + double lthres, + cpl_size hsize, + cpl_boolean dofast, + cpl_boolean dolog, + cpl_size *pulines) +{ + cpl_errorstate prestate; + const double sigma = wfwhm * CPL_MATH_SIG_FWHM; + const cpl_vector *xlines = cpl_bivector_get_x_const(lines); + const double *dxlines = cpl_vector_get_data_const(xlines); + const double *dylines = cpl_bivector_get_y_data_const(lines); + double *plinepix = linepix ? cpl_vector_get_data(linepix) : NULL; + const cpl_size nlines = cpl_vector_get_size(xlines); + const cpl_size nself = cpl_vector_get_size(self); + double *dself = cpl_vector_get_data(self); + cpl_polynomial *dispi; + double *profile = NULL; + cpl_size i0 = 0; + const double p0 = cpl_polynomial_get_coeff(disp, &i0); + const cpl_size degree = cpl_polynomial_get_degree(disp); + double wl; + const double xtrunc = 0.5 * wslit + lthres * sigma; + double xpos = (double)(1 - hsize) - xtrunc; + const double xmax = (double)(nself - hsize) + xtrunc; + double xderiv; + cpl_error_code error = CPL_ERROR_NONE; + cpl_size iline; + cpl_size ulines = 0; + + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(disp != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(lines != NULL, CPL_ERROR_NULL_INPUT); + + cpl_ensure_code(wslit > 0.0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(wfwhm > 0.0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(hsize >= 0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(xtrunc > 0.0, CPL_ERROR_ILLEGAL_INPUT); + cpl_ensure_code(nself > 2 * hsize, CPL_ERROR_ILLEGAL_INPUT); cpl_ensure_code(cpl_polynomial_get_dimension(disp) == 1, CPL_ERROR_INVALID_TYPE); @@ -1109,57 +1086,63 @@ /* The smallest wavelength contributing to the spectrum. */ wl = cpl_polynomial_eval_1d(disp, xpos, &xderiv); - if (wl <= 0.0) return - cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, "Non-positive " - "wavelength at x=%g: P(x)=%g, P'(x)=%g", - xpos, wl, xderiv); - - if (xderiv <= 0.0) return - cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, "Non-increasing " - "dispersion at x=%g: P'(x)=%g, P(x)=%g, " - "degree=%" CPL_SIZE_FORMAT, xpos, xderiv, - wl, degree); + if (wl <= 0.0) + return cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, + "Non-positive " + "wavelength at x=%g: P(x)=%g, P'(x)=%g", + xpos, wl, xderiv); + + if (xderiv <= 0.0) + return cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, + "Non-increasing " + "dispersion at x=%g: P'(x)=%g, P(x)=%g, " + "degree=%" CPL_SIZE_FORMAT, + xpos, xderiv, wl, degree); /* Find the 1st line */ iline = cpl_vector_find(xlines, wl); if (iline < 0) { - return cpl_error_set_message_(CPL_ERROR_INCOMPATIBLE_INPUT, "Invalid " + return cpl_error_set_message_(CPL_ERROR_INCOMPATIBLE_INPUT, + "Invalid " "%" CPL_SIZE_FORMAT "-entry catalog", nlines); } /* The first line must be at least at wl */ - if (dxlines[iline] < wl) iline++; + if (dxlines[iline] < wl) + iline++; - if (iline >= nlines) return - cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, "The %" CPL_SIZE_FORMAT - "-line catalog has only lines below " - "P(%g)=%g > %g, degree=%" CPL_SIZE_FORMAT, - nlines, xpos, wl, dxlines[nlines-1], degree); + if (iline >= nlines) + return cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, + "The %" CPL_SIZE_FORMAT + "-line catalog has only lines below " + "P(%g)=%g > %g, degree=%" CPL_SIZE_FORMAT, + nlines, xpos, wl, dxlines[nlines - 1], + degree); (void)memset(dself, 0, nself * sizeof(double)); prestate = cpl_errorstate_get(); if (dofast) { - const cpl_size npix = 1+(cpl_size)xtrunc; + const cpl_size npix = 1 + (cpl_size)xtrunc; if (*perftmp != NULL && cpl_vector_get_size(*perftmp) == npix && cpl_vector_get(*perftmp, 0) > 0.0) { profile = cpl_vector_get_data(*perftmp); - } else { - - const double yval = 0.5 / wslit; - const double x0p = 0.5 * wslit + 0.5; - const double x0n = -0.5 * wslit + 0.5; - double x1diff - = cpl_erf_antideriv(x0p, sigma) - - cpl_erf_antideriv(x0n, sigma); - cpl_size ipix; + } + else { + const double yval = 0.5 / wslit; + const double x0p = 0.5 * wslit + 0.5; + const double x0n = -0.5 * wslit + 0.5; + double x1diff = + cpl_erf_antideriv(x0p, sigma) - cpl_erf_antideriv(x0n, sigma); + cpl_size ipix; if (*perftmp == NULL) { *perftmp = cpl_vector_new(npix); - } else { + } + else { cpl_vector_set_size(*perftmp, npix); } profile = cpl_vector_get_data(*perftmp); @@ -1172,15 +1155,13 @@ const double x1n = x1 - 0.5 * wslit + 0.5; const double x0diff = x1diff; - x1diff = cpl_erf_antideriv(x1p, sigma) - - cpl_erf_antideriv(x1n, sigma); + x1diff = cpl_erf_antideriv(x1p, sigma) - + cpl_erf_antideriv(x1n, sigma); profile[ipix] = yval * (x1diff - x0diff); - } - cpl_tools_add_flops( 33 * npix ); - + cpl_tools_add_flops(33 * npix); } } @@ -1193,151 +1174,162 @@ /* Iterate through the lines */ for (; !error && iline < nlines; iline++) { - - if (iline > 0 && dxlines[iline-1] >= dxlines[iline]) { - error = cpl_error_set_message_(CPL_ERROR_INCOMPATIBLE_INPUT, - "Non-increasing wavelengths in %" - CPL_SIZE_FORMAT "-entry catalog: I(%" - CPL_SIZE_FORMAT ") = %g >= %g = I(%" - CPL_SIZE_FORMAT "+1)", nlines, iline, - dxlines[iline-1], dxlines[iline], - iline); + if (iline > 0 && dxlines[iline - 1] >= dxlines[iline]) { + error = cpl_error_set_message_( + CPL_ERROR_INCOMPATIBLE_INPUT, + "Non-increasing wavelengths in %" CPL_SIZE_FORMAT + "-entry catalog: I(%" CPL_SIZE_FORMAT + ") = %g >= %g = I(%" CPL_SIZE_FORMAT "+1)", + nlines, iline, dxlines[iline - 1], dxlines[iline], iline); break; } /* Lines may have a non-physical intensity (e.g. zero) to indicate some property of the line, e.g. unknown intensity due to blending */ - if (dylines[iline] <= 0.0) continue; + if (dylines[iline] <= 0.0) + continue; /* Use 1st guess, if available (Use 0.0 to flag unavailable) */ - if (plinepix != NULL && plinepix[iline] > 0.0) xpos = plinepix[iline]; + if (plinepix != NULL && plinepix[iline] > 0.0) + xpos = plinepix[iline]; - if (xpos > xmax) xpos = xmax; /* FIXME: Better to limit xpos ? */ + if (xpos > xmax) + xpos = xmax; /* FIXME: Better to limit xpos ? */ /* Find the (sub-) pixel position of the line */ /* Also, verify monotony of dispersion */ error = cpl_polynomial_set_coeff(dispi, &i0, p0 - dxlines[iline]) || - cpl_polynomial_solve_1d_(dispi, xpos, &xpos, 1, CPL_TRUE); + cpl_polynomial_solve_1d_(dispi, xpos, &xpos, 1, CPL_TRUE); if (xpos > xmax) { if (error) { error = 0; #ifdef CPL_WLCALIB_DEBUG - cpl_msg_debug(cpl_func, "Stopping spectrum fill at line %d/%d " - "at xpos=%g > xmax=%g", - iline, nlines, xpos, xmax); + cpl_msg_debug(cpl_func, + "Stopping spectrum fill at line %d/%d " + "at xpos=%g > xmax=%g", + iline, nlines, xpos, xmax); cpl_errorstate_dump(prestate, CPL_FALSE, cpl_errorstate_dump_one_debug); #endif cpl_errorstate_set(prestate); } break; - } else if (error) { - if (linepix != NULL && ulines) (void)cpl_vector_fill(linepix, 0.0); + } + else if (error) { + if (linepix != NULL && ulines) + (void)cpl_vector_fill(linepix, 0.0); (void)cpl_error_set_message_(cpl_error_get_code(), "Could not find pixel-position " - "of line %" CPL_SIZE_FORMAT "/%" - CPL_SIZE_FORMAT " at wavelength=%g. " - "xpos=%g, xmax=%g", iline, nlines, - dxlines[iline], xpos, xmax); + "of line %" CPL_SIZE_FORMAT + "/%" CPL_SIZE_FORMAT + " at wavelength=%g. " + "xpos=%g, xmax=%g", + iline, nlines, dxlines[iline], xpos, + xmax); break; - } else if (dofast) { - const double frac = fabs(xpos - floor(xpos)); + } + else if (dofast) { + const double frac = fabs(xpos - floor(xpos)); #ifdef CPL_WAVECAL_FAST_FAST const double frac0 = 1.0 - frac; /* Weight opposite of distance */ #else /* Center intensity correctly */ const double ep1pw = cpl_erf_antideriv(frac + 0.5 * wslit, sigma); - const double en1pw = cpl_erf_antideriv(frac + 0.5 * wslit - 1.0, - sigma); + const double en1pw = + cpl_erf_antideriv(frac + 0.5 * wslit - 1.0, sigma); const double ep1nw = cpl_erf_antideriv(frac - 0.5 * wslit, sigma); - const double en1nw = cpl_erf_antideriv(frac - 0.5 * wslit - 1.0, - sigma); - const double frac0 - = (en1nw - en1pw) / (ep1pw - en1pw - ep1nw + en1nw); + const double en1nw = + cpl_erf_antideriv(frac - 0.5 * wslit - 1.0, sigma); + const double frac0 = + (en1nw - en1pw) / (ep1pw - en1pw - ep1nw + en1nw); #endif const double frac1 = 1.0 - frac0; const double yval0 = frac0 * dylines[iline]; const double yval1 = frac1 * dylines[iline]; - const cpl_size npix = 1+(cpl_size)xtrunc; - cpl_size ipix; - cpl_size i0n = hsize - 1 + floor(xpos); - cpl_size i0p = i0n; - cpl_size i1n = i0n + 1; - cpl_size i1p = i1n; - cpl_boolean didline = CPL_FALSE; + const cpl_size npix = 1 + (cpl_size)xtrunc; + cpl_size ipix; + cpl_size i0n = hsize - 1 + floor(xpos); + cpl_size i0p = i0n; + cpl_size i1n = i0n + 1; + cpl_size i1p = i1n; + cpl_boolean didline = CPL_FALSE; /* Update 1st guess for next time, if available */ - if (plinepix != NULL) plinepix[iline] = xpos; + if (plinepix != NULL) + plinepix[iline] = xpos; if (frac0 < 0.0) { - (void)cpl_error_set_message_(CPL_ERROR_UNSPECIFIED, "Illegal " + (void)cpl_error_set_message_(CPL_ERROR_UNSPECIFIED, + "Illegal " "split at x=%g: %g + %g = 1", xpos, frac0, frac1); #ifdef CPL_WAVEVAL_DEBUG - } else { - cpl_msg_warning(cpl_func,"profile split at x=%g: %g + %g = 1", + } + else { + cpl_msg_warning(cpl_func, "profile split at x=%g: %g + %g = 1", xpos, frac0, frac1); #endif } for (ipix = 0; ipix < npix; ipix++, i0n--, i0p++, i1n--, i1p++) { - if (i0n >= 0 && i0n < nself) { dself[i0n] += yval0 * profile[ipix]; didline = CPL_TRUE; } if (i1n >= 0 && i1n < nself && ipix + 1 < npix) { - dself[i1n] += yval1 * profile[ipix+1]; + dself[i1n] += yval1 * profile[ipix + 1]; didline = CPL_TRUE; } - if (ipix == 0) continue; + if (ipix == 0) + continue; if (i0p >= 0 && i0p < nself) { dself[i0p] += yval0 * profile[ipix]; didline = CPL_TRUE; } if (i1p >= 0 && i1p < nself && ipix + 1 < npix) { - dself[i1p] += yval1 * profile[ipix+1]; + dself[i1p] += yval1 * profile[ipix + 1]; didline = CPL_TRUE; } } - if (didline) ulines++; - - } else { - const double yval = 0.5 * dylines[iline] / wslit; - const cpl_size ifirst = CX_MAX((cpl_size)(xpos-xtrunc+0.5), - 1-hsize); - const cpl_size ilast = CX_MIN((cpl_size)(xpos+xtrunc), - nself-hsize); - cpl_size ipix; - const double x0 = (double)ifirst - xpos; - const double x0p = x0 + 0.5*wslit - 0.5; - const double x0n = x0 - 0.5*wslit - 0.5; - double x1diff - = cpl_erf_antideriv(x0p, sigma) - - cpl_erf_antideriv(x0n, sigma); + if (didline) + ulines++; + } + else { + const double yval = 0.5 * dylines[iline] / wslit; + const cpl_size ifirst = + CX_MAX((cpl_size)(xpos - xtrunc + 0.5), 1 - hsize); + const cpl_size ilast = + CX_MIN((cpl_size)(xpos + xtrunc), nself - hsize); + cpl_size ipix; + const double x0 = (double)ifirst - xpos; + const double x0p = x0 + 0.5 * wslit - 0.5; + const double x0n = x0 - 0.5 * wslit - 0.5; + double x1diff = + cpl_erf_antideriv(x0p, sigma) - cpl_erf_antideriv(x0n, sigma); /* Update 1st guess for next time, if available */ - if (plinepix != NULL) plinepix[iline] = xpos; + if (plinepix != NULL) + plinepix[iline] = xpos; - if (ilast >= ifirst) ulines++; + if (ilast >= ifirst) + ulines++; for (ipix = ifirst; ipix < 1 + ilast; ipix++) { const double x1 = (double)ipix - xpos; - const double x1p = x1 + 0.5*wslit + 0.5; - const double x1n = x1 - 0.5*wslit + 0.5; + const double x1p = x1 + 0.5 * wslit + 0.5; + const double x1n = x1 - 0.5 * wslit + 0.5; const double x0diff = x1diff; - x1diff = cpl_erf_antideriv(x1p, sigma) - - cpl_erf_antideriv(x1n, sigma); - - dself[ipix+hsize-1] += yval * (x1diff - x0diff); + x1diff = cpl_erf_antideriv(x1p, sigma) - + cpl_erf_antideriv(x1n, sigma); + dself[ipix + hsize - 1] += yval * (x1diff - x0diff); } } } @@ -1351,19 +1343,22 @@ for (i = 0; i < nself; i++) { dself[i] = dself[i] > 0.0 ? log1p(dself[i]) : 0.0; } - cpl_tools_add_flops( 2 * nself ); + cpl_tools_add_flops(2 * nself); } - if (!ulines) return - cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, "The %" CPL_SIZE_FORMAT - "-line catalog has no lines in the range " - "%g -> P(%g)=%g", nlines, wl, xmax, - cpl_polynomial_eval_1d(disp, xmax, NULL)); + if (!ulines) + return cpl_error_set_message_(CPL_ERROR_DATA_NOT_FOUND, + "The %" CPL_SIZE_FORMAT + "-line catalog has no lines in the range " + "%g -> P(%g)=%g", + nlines, wl, xmax, + cpl_polynomial_eval_1d(disp, xmax, NULL)); - cpl_tools_add_flops( ulines * (dofast ? 4 * (cpl_flops)xtrunc + 74 - : 70 * (cpl_flops)xtrunc + 35 )); + cpl_tools_add_flops(ulines * (dofast ? 4 * (cpl_flops)xtrunc + 74 + : 70 * (cpl_flops)xtrunc + 35)); - if (pulines != NULL) *pulines += ulines; + if (pulines != NULL) + *pulines += ulines; return CPL_ERROR_NONE; } @@ -1382,10 +1377,11 @@ */ /*----------------------------------------------------------------------------*/ -inline static double cpl_erf_antideriv(double x, double sigma) +inline static double +cpl_erf_antideriv(double x, double sigma) { - return x * erf( x / (sigma * CPL_MATH_SQRT2)) - + 2.0 * sigma/CPL_MATH_SQRT2PI * exp(-0.5 * x * x / (sigma * sigma)); + return x * erf(x / (sigma * CPL_MATH_SQRT2)) + + 2.0 * sigma / CPL_MATH_SQRT2PI * exp(-0.5 * x * x / (sigma * sigma)); } /*----------------------------------------------------------------------------*/ @@ -1403,32 +1399,33 @@ */ /*----------------------------------------------------------------------------*/ -static cpl_error_code cpl_wlcalib_evaluate(cpl_vector * vxc, - cpl_size * pixcmax, - cpl_vector * spmodel, - const cpl_vector * observed, - void * model, - cpl_error_code (* filler) - (cpl_vector *, void *, - const cpl_polynomial *), - const cpl_polynomial * disp) +static cpl_error_code +cpl_wlcalib_evaluate(cpl_vector *vxc, + cpl_size *pixcmax, + cpl_vector *spmodel, + const cpl_vector *observed, + void *model, + cpl_error_code (*filler)(cpl_vector *, + void *, + const cpl_polynomial *), + const cpl_polynomial *disp) { - cpl_error_code error; - cpl_ensure_code(vxc != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(pixcmax != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(spmodel != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(vxc != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(pixcmax != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(spmodel != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(observed != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(model != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(filler != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(disp != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(model != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(filler != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(disp != NULL, CPL_ERROR_NULL_INPUT); error = filler(spmodel, model, disp); if (!error) { *pixcmax = cpl_vector_correlate(vxc, spmodel, observed); - if (*pixcmax < 0) error = cpl_error_get_code(); + if (*pixcmax < 0) + error = cpl_error_get_code(); } return error ? cpl_error_set_where_() : CPL_ERROR_NONE; diff -Nru cpl-7.1.4+ds/cpldrs/cpl_wlcalib.h cpl-7.2.2+ds/cpldrs/cpl_wlcalib.h --- cpl-7.1.4+ds/cpldrs/cpl_wlcalib.h 2021-05-07 12:09:10.000000000 +0000 +++ cpl-7.2.2+ds/cpldrs/cpl_wlcalib.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -27,6 +27,8 @@ #include #include +CPL_BEGIN_DECLS + /*----------------------------------------------------------------------------- New types -----------------------------------------------------------------------------*/ @@ -38,42 +40,45 @@ -----------------------------------------------------------------------------*/ /* Functions to create and destroy a slitmodel */ -cpl_wlcalib_slitmodel * cpl_wlcalib_slitmodel_new(void) CPL_ATTR_ALLOC; +cpl_wlcalib_slitmodel *cpl_wlcalib_slitmodel_new(void) CPL_ATTR_ALLOC; void cpl_wlcalib_slitmodel_delete(cpl_wlcalib_slitmodel *); /* Functions to initialize the slitmodel */ cpl_error_code cpl_wlcalib_slitmodel_set_wslit(cpl_wlcalib_slitmodel *, double); cpl_error_code cpl_wlcalib_slitmodel_set_wfwhm(cpl_wlcalib_slitmodel *, double); -cpl_error_code cpl_wlcalib_slitmodel_set_threshold(cpl_wlcalib_slitmodel *, - double); -cpl_error_code cpl_wlcalib_slitmodel_set_catalog(cpl_wlcalib_slitmodel *, - cpl_bivector *); +cpl_error_code +cpl_wlcalib_slitmodel_set_threshold(cpl_wlcalib_slitmodel *, double); +cpl_error_code +cpl_wlcalib_slitmodel_set_catalog(cpl_wlcalib_slitmodel *, cpl_bivector *); /* Functions to make a model spectrum using the slitmodel */ -cpl_error_code cpl_wlcalib_fill_line_spectrum(cpl_vector *, void *, - const cpl_polynomial *); +cpl_error_code +cpl_wlcalib_fill_line_spectrum(cpl_vector *, void *, const cpl_polynomial *); -cpl_error_code cpl_wlcalib_fill_logline_spectrum(cpl_vector *, void *, - const cpl_polynomial *); +cpl_error_code +cpl_wlcalib_fill_logline_spectrum(cpl_vector *, void *, const cpl_polynomial *); -cpl_error_code cpl_wlcalib_fill_line_spectrum_fast(cpl_vector *, void *, +cpl_error_code cpl_wlcalib_fill_line_spectrum_fast(cpl_vector *, + void *, const cpl_polynomial *); -cpl_error_code cpl_wlcalib_fill_logline_spectrum_fast(cpl_vector *, void *, +cpl_error_code cpl_wlcalib_fill_logline_spectrum_fast(cpl_vector *, + void *, const cpl_polynomial *); /* Function to calibrate a spectrum using a spectral model */ -cpl_error_code cpl_wlcalib_find_best_1d(cpl_polynomial *, - const cpl_polynomial *, - const cpl_vector *, - void *, - cpl_error_code (*) - (cpl_vector *, void *, - const cpl_polynomial *), - const cpl_vector *, - cpl_size, - cpl_size, - double *, - cpl_vector *); +cpl_error_code cpl_wlcalib_find_best_1d( + cpl_polynomial *, + const cpl_polynomial *, + const cpl_vector *, + void *, + cpl_error_code (*)(cpl_vector *, void *, const cpl_polynomial *), + const cpl_vector *, + cpl_size, + cpl_size, + double *, + cpl_vector *); + +CPL_END_DECLS #endif diff -Nru cpl-7.1.4+ds/cpldrs/cpl_wlcalib_impl.h cpl-7.2.2+ds/cpldrs/cpl_wlcalib_impl.h --- cpl-7.1.4+ds/cpldrs/cpl_wlcalib_impl.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cpldrs/cpl_wlcalib_impl.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -26,18 +26,19 @@ #include "cpl_wlcalib.h" +CPL_BEGIN_DECLS /*----------------------------------------------------------------------------- Functions prototypes -----------------------------------------------------------------------------*/ /* Cost counting functions for the slitmodel */ -cpl_error_code cpl_wlcalib_slitmodel_add_cost(cpl_wlcalib_slitmodel *, - cpl_size); -cpl_error_code cpl_wlcalib_slitmodel_add_xcost(cpl_wlcalib_slitmodel *, - cpl_size); -cpl_error_code cpl_wlcalib_slitmodel_add_ulines(cpl_wlcalib_slitmodel *, - cpl_size); +cpl_error_code +cpl_wlcalib_slitmodel_add_cost(cpl_wlcalib_slitmodel *, cpl_size); +cpl_error_code +cpl_wlcalib_slitmodel_add_xcost(cpl_wlcalib_slitmodel *, cpl_size); +cpl_error_code +cpl_wlcalib_slitmodel_add_ulines(cpl_wlcalib_slitmodel *, cpl_size); /* Acessors of the slitmodel */ double cpl_wlcalib_slitmodel_get_wslit(const cpl_wlcalib_slitmodel *); @@ -47,9 +48,11 @@ cpl_size cpl_wlcalib_slitmodel_get_xcost(const cpl_wlcalib_slitmodel *); cpl_size cpl_wlcalib_slitmodel_get_ulines(const cpl_wlcalib_slitmodel *); -cpl_bivector * cpl_wlcalib_slitmodel_get_catalog(cpl_wlcalib_slitmodel *); +cpl_bivector *cpl_wlcalib_slitmodel_get_catalog(cpl_wlcalib_slitmodel *); const cpl_bivector * - cpl_wlcalib_slitmodel_get_catalog_const(const cpl_wlcalib_slitmodel *); -cpl_bivector * cpl_wlcalib_slitmodel_unset_catalog(cpl_wlcalib_slitmodel *); +cpl_wlcalib_slitmodel_get_catalog_const(const cpl_wlcalib_slitmodel *); +cpl_bivector *cpl_wlcalib_slitmodel_unset_catalog(cpl_wlcalib_slitmodel *); + +CPL_END_DECLS #endif diff -Nru cpl-7.1.4+ds/cpldrs/Makefile.am cpl-7.2.2+ds/cpldrs/Makefile.am --- cpl-7.1.4+ds/cpldrs/Makefile.am 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cpldrs/Makefile.am 2022-04-29 14:56:02.000000000 +0000 @@ -1,7 +1,7 @@ ## Process this file with automake to produce Makefile.in ## This file is part of the ESO Common Pipeline Library -## Copyright (C) 2001-2017 European Southern Observatory +## Copyright (C) 2001-2022 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 diff -Nru cpl-7.1.4+ds/cpldrs/Makefile.in cpl-7.2.2+ds/cpldrs/Makefile.in --- cpl-7.1.4+ds/cpldrs/Makefile.in 2021-05-07 12:10:10.000000000 +0000 +++ cpl-7.2.2+ds/cpldrs/Makefile.in 2022-04-29 14:56:28.000000000 +0000 @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.15.1 from Makefile.am. +# Makefile.in generated by automake 1.16.3 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2017 Free Software Foundation, Inc. +# Copyright (C) 1994-2020 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -160,7 +160,12 @@ am__v_at_1 = DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) depcomp = $(SHELL) $(top_srcdir)/admin/depcomp -am__depfiles_maybe = depfiles +am__maybe_remake_depfiles = depfiles +am__depfiles_remade = ./$(DEPDIR)/cpl_apertures.Plo \ + ./$(DEPDIR)/cpl_detector.Plo ./$(DEPDIR)/cpl_fft.Plo \ + ./$(DEPDIR)/cpl_fit.Plo ./$(DEPDIR)/cpl_geom_img.Plo \ + ./$(DEPDIR)/cpl_photom.Plo ./$(DEPDIR)/cpl_ppm.Plo \ + ./$(DEPDIR)/cpl_wcs.Plo ./$(DEPDIR)/cpl_wlcalib.Plo am__mv = mv -f COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) @@ -203,7 +208,7 @@ $(RECURSIVE_CLEAN_TARGETS) \ $(am__extra_recursive_targets) AM_RECURSIVE_TARGETS = $(am__recursive_targets:-recursive=) TAGS CTAGS \ - distdir + distdir distdir-am 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 @@ -269,6 +274,7 @@ CPLCORE_INCLUDES = @CPLCORE_INCLUDES@ CPLDFS_INCLUDES = @CPLDFS_INCLUDES@ CPLDRS_INCLUDES = @CPLDRS_INCLUDES@ +CPLJAVA_INCLUDES = @CPLJAVA_INCLUDES@ CPLUI_INCLUDES = @CPLUI_INCLUDES@ CPL_BINARY_AGE = @CPL_BINARY_AGE@ CPL_BINARY_VERSION = @CPL_BINARY_VERSION@ @@ -329,6 +335,7 @@ LIBCPLCORE = @LIBCPLCORE@ LIBCPLDFS = @LIBCPLDFS@ LIBCPLDRS = @LIBCPLDRS@ +LIBCPLGASGANO = @LIBCPLGASGANO@ LIBCPLUI = @LIBCPLUI@ LIBFFTW = @LIBFFTW@ LIBFFTWF = @LIBFFTWF@ @@ -435,6 +442,7 @@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ @@ -513,8 +521,8 @@ *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);; \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ esac; $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) @@ -570,15 +578,21 @@ distclean-compile: -rm -f *.tab.c -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_apertures.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_detector.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_fft.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_fit.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_geom_img.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_photom.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_ppm.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_wcs.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_wlcalib.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_apertures.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_detector.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_fft.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_fit.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_geom_img.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_photom.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_ppm.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_wcs.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_wlcalib.Plo@am__quote@ # am--include-marker + +$(am__depfiles_remade): + @$(MKDIR_P) $(@D) + @echo '# dummy' >$@-t && $(am__mv) $@-t $@ + +am--depfiles: $(am__depfiles_remade) .c.o: @am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @@ -727,7 +741,10 @@ distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags -distdir: $(DISTFILES) +distdir: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) distdir-am + +distdir-am: $(DISTFILES) @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ list='$(DISTFILES)'; \ @@ -828,7 +845,15 @@ mostlyclean-am distclean: distclean-recursive - -rm -rf ./$(DEPDIR) + -rm -f ./$(DEPDIR)/cpl_apertures.Plo + -rm -f ./$(DEPDIR)/cpl_detector.Plo + -rm -f ./$(DEPDIR)/cpl_fft.Plo + -rm -f ./$(DEPDIR)/cpl_fit.Plo + -rm -f ./$(DEPDIR)/cpl_geom_img.Plo + -rm -f ./$(DEPDIR)/cpl_photom.Plo + -rm -f ./$(DEPDIR)/cpl_ppm.Plo + -rm -f ./$(DEPDIR)/cpl_wcs.Plo + -rm -f ./$(DEPDIR)/cpl_wlcalib.Plo -rm -f Makefile distclean-am: clean-am distclean-compile distclean-generic \ distclean-tags @@ -874,7 +899,15 @@ installcheck-am: maintainer-clean: maintainer-clean-recursive - -rm -rf ./$(DEPDIR) + -rm -f ./$(DEPDIR)/cpl_apertures.Plo + -rm -f ./$(DEPDIR)/cpl_detector.Plo + -rm -f ./$(DEPDIR)/cpl_fft.Plo + -rm -f ./$(DEPDIR)/cpl_fit.Plo + -rm -f ./$(DEPDIR)/cpl_geom_img.Plo + -rm -f ./$(DEPDIR)/cpl_photom.Plo + -rm -f ./$(DEPDIR)/cpl_ppm.Plo + -rm -f ./$(DEPDIR)/cpl_wcs.Plo + -rm -f ./$(DEPDIR)/cpl_wlcalib.Plo -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic @@ -895,21 +928,22 @@ .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-libLTLIBRARIES \ - clean-libtool 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-includeHEADERS install-info \ - install-info-am install-libLTLIBRARIES 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 \ - uninstall-includeHEADERS uninstall-libLTLIBRARIES +.PHONY: $(am__recursive_targets) CTAGS GTAGS TAGS all all-am \ + am--depfiles check check-am clean clean-generic \ + clean-libLTLIBRARIES clean-libtool 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-includeHEADERS install-info install-info-am \ + install-libLTLIBRARIES 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 uninstall-includeHEADERS \ + uninstall-libLTLIBRARIES .PRECIOUS: Makefile diff -Nru cpl-7.1.4+ds/cpldrs/tests/cpl_apertures-test.c cpl-7.2.2+ds/cpldrs/tests/cpl_apertures-test.c --- cpl-7.1.4+ds/cpldrs/tests/cpl_apertures-test.c 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cpldrs/tests/cpl_apertures-test.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -38,17 +38,17 @@ Define -----------------------------------------------------------------------------*/ -#define IMAGESZ 10 -#define IMAGESZ2 512 - -#define CPL_APERTS_CMP_IMAGE(OP) \ - do { \ - cpl_test_abs( CPL_CONCAT(cpl_apertures_get, OP)(aperts, 1), \ - CPL_CONCAT2X(cpl_image_get, CPL_CONCAT(OP,window)) \ - (imb, 1, 1, IMAGESZ, IMAGESZ), \ - 4.0 * DBL_EPSILON); \ - } while (0) +#define IMAGESZ 10 +#define IMAGESZ2 512 +#define CPL_APERTS_CMP_IMAGE(OP) \ + do { \ + cpl_test_abs(CPL_CONCAT(cpl_apertures_get, OP)(aperts, 1), \ + CPL_CONCAT2X(cpl_image_get, \ + CPL_CONCAT(OP, window))(imb, 1, 1, IMAGESZ, \ + IMAGESZ), \ + 4.0 * DBL_EPSILON); \ + } while (0) /*----------------------------------------------------------------------------- @@ -60,63 +60,58 @@ /*----------------------------------------------------------------------------- Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { - const cpl_type img_type[] = {CPL_TYPE_DOUBLE, CPL_TYPE_FLOAT, CPL_TYPE_INT}; - cpl_size (*ap_get_cpl_size[])(const cpl_apertures *, cpl_size) = - {cpl_apertures_get_maxpos_x, - cpl_apertures_get_maxpos_y, - cpl_apertures_get_minpos_x, - cpl_apertures_get_minpos_y, - cpl_apertures_get_npix, - cpl_apertures_get_left, - cpl_apertures_get_left_y, - cpl_apertures_get_right, - cpl_apertures_get_right_y, - cpl_apertures_get_top_x, - cpl_apertures_get_top, - cpl_apertures_get_bottom_x, - cpl_apertures_get_bottom}; - const size_t napsize = sizeof(ap_get_cpl_size)/sizeof(*ap_get_cpl_size); + const cpl_type img_type[] = { CPL_TYPE_DOUBLE, CPL_TYPE_FLOAT, + CPL_TYPE_INT }; + cpl_size (*ap_get_cpl_size[])(const cpl_apertures *, cpl_size) = { + cpl_apertures_get_maxpos_x, cpl_apertures_get_maxpos_y, + cpl_apertures_get_minpos_x, cpl_apertures_get_minpos_y, + cpl_apertures_get_npix, cpl_apertures_get_left, + cpl_apertures_get_left_y, cpl_apertures_get_right, + cpl_apertures_get_right_y, cpl_apertures_get_top_x, + cpl_apertures_get_top, cpl_apertures_get_bottom_x, + cpl_apertures_get_bottom + }; + const size_t napsize = sizeof(ap_get_cpl_size) / sizeof(*ap_get_cpl_size); double (*ap_get_double_pos[])(const cpl_apertures *, cpl_size) = { - cpl_apertures_get_pos_x, - cpl_apertures_get_pos_y, - cpl_apertures_get_centroid_x, - cpl_apertures_get_centroid_y}; - const size_t napdpos = sizeof(ap_get_double_pos)/sizeof(*ap_get_double_pos); + cpl_apertures_get_pos_x, cpl_apertures_get_pos_y, + cpl_apertures_get_centroid_x, cpl_apertures_get_centroid_y + }; + const size_t napdpos = + sizeof(ap_get_double_pos) / sizeof(*ap_get_double_pos); double (*ap_get_double[])(const cpl_apertures *, cpl_size) = { - cpl_apertures_get_max, - cpl_apertures_get_min, - cpl_apertures_get_mean, - cpl_apertures_get_median, - cpl_apertures_get_stdev, - cpl_apertures_get_flux}; - const size_t napdbl = sizeof(ap_get_double)/sizeof(*ap_get_double); - - size_t isize; - cpl_image * imd; - cpl_mask * bpm; - cpl_apertures * aperts; - cpl_apertures * nullapert; - double * val; - const double psigmas[] = {5, 2, 1, 0.5}; - const double maxval = 10.0; - cpl_vector * sigmas; - unsigned itype; - FILE * stream; - cpl_error_code error; - cpl_size errsize, nsize, pos; - cpl_boolean is_bench; - int nreps, ireps; + cpl_apertures_get_max, cpl_apertures_get_min, + cpl_apertures_get_mean, cpl_apertures_get_median, + cpl_apertures_get_stdev, cpl_apertures_get_flux + }; + const size_t napdbl = sizeof(ap_get_double) / sizeof(*ap_get_double); + + size_t isize; + cpl_image *imd; + cpl_mask *bpm; + cpl_apertures *aperts; + cpl_apertures *nullapert; + double *val; + const double psigmas[] = { 5, 2, 1, 0.5 }; + const double maxval = 10.0; + cpl_vector *sigmas; + unsigned itype; + FILE *stream; + cpl_error_code error; + cpl_size errsize, nsize, pos; + cpl_boolean is_bench; + int nreps, ireps; cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); /* Insert tests below */ - stream = cpl_msg_get_level() > CPL_MSG_INFO - ? fopen("/dev/null", "a") : stdout; + stream = + cpl_msg_get_level() > CPL_MSG_INFO ? fopen("/dev/null", "a") : stdout; is_bench = cpl_msg_get_level() > CPL_MSG_INFO ? CPL_FALSE : CPL_TRUE; nreps = is_bench ? 10 : 1; @@ -124,8 +119,8 @@ cpl_msg_info(cpl_func, "Repetitions for benchmarking: %d", nreps); /* Test 1: NULL pointers */ - cpl_apertures_delete(NULL); /* Just verify the return */ - cpl_apertures_dump(NULL, NULL); /* Just verify the return */ + cpl_apertures_delete(NULL); /* Just verify the return */ + cpl_apertures_dump(NULL, NULL); /* Just verify the return */ cpl_apertures_dump(NULL, stream); /* Just verify the return */ for (isize = 0; isize < napsize; isize++) { @@ -192,21 +187,22 @@ cpl_test_eq_error(error, CPL_ERROR_NONE); for (ireps = 0; ireps < nreps; ireps++) { - for (itype = 0; itype < sizeof(img_type)/sizeof(img_type[0]); itype++) { + for (itype = 0; itype < sizeof(img_type) / sizeof(img_type[0]); + itype++) { const cpl_size naperts = 2; const cpl_type type = img_type[itype]; - cpl_image * labels = cpl_image_new(IMAGESZ, IMAGESZ, CPL_TYPE_INT); - cpl_image * img = cpl_image_cast(imd, type); - cpl_image * imb = cpl_image_duplicate(img); - cpl_mask * bin; - cpl_size xpos, ypos; + cpl_image *labels = cpl_image_new(IMAGESZ, IMAGESZ, CPL_TYPE_INT); + cpl_image *img = cpl_image_cast(imd, type); + cpl_image *imb = cpl_image_duplicate(img); + cpl_mask *bin; + cpl_size xpos, ypos; error = cpl_image_reject_from_mask(imb, bpm); cpl_test_eq_error(error, CPL_ERROR_NONE); /* Create test image and the labels */ - cpl_msg_info(cpl_func, "Testing with a %d X %d %s-image", - IMAGESZ, IMAGESZ, cpl_type_get_name(type)); + cpl_msg_info(cpl_func, "Testing with a %d X %d %s-image", IMAGESZ, + IMAGESZ, cpl_type_get_name(type)); /* Test 3: with a 'bad' label image */ nullapert = cpl_apertures_new_from_image(img, NULL); @@ -236,7 +232,7 @@ if (type != CPL_TYPE_INT) { /* Test (error) handling of a complex image */ - cpl_image * imgc = cpl_image_cast(imd, type | CPL_TYPE_COMPLEX); + cpl_image *imgc = cpl_image_cast(imd, type | CPL_TYPE_COMPLEX); aperts = cpl_apertures_new_from_image(imgc, labels); cpl_test_error(CPL_ERROR_TYPE_MISMATCH); @@ -262,7 +258,7 @@ cpl_mask_delete(bin); /* Compute statistics on the apertures */ - cpl_msg_info("","Compute statistics on detected apertures"); + cpl_msg_info("", "Compute statistics on detected apertures"); aperts = cpl_apertures_new_from_image(img, labels); cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(aperts); @@ -278,7 +274,8 @@ cpl_apertures_test_one(aperts, stream); - cpl_msg_info("","Compare statistics with those from same " + cpl_msg_info("", + "Compare statistics with those from same " "image with %" CPL_SIZE_FORMAT "rejected pixels", cpl_image_count_rejected(imb)); @@ -313,7 +310,7 @@ cpl_test_leq(ypos, cpl_apertures_get_top(aperts, 1)); cpl_apertures_delete(aperts); - + /* Set a bad pixel and recompute the apertures */ error = cpl_image_reject(img, 6, 6); cpl_test_eq_error(error, CPL_ERROR_NONE); @@ -336,10 +333,10 @@ cpl_image_delete(labels); /* Get the biggest object */ - cpl_msg_info("","Get the biggest aperture:"); + cpl_msg_info("", "Get the biggest aperture:"); error = cpl_apertures_sort_by_npix(aperts); cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_msg_info("","number of pixels: %" CPL_SIZE_FORMAT, + cpl_msg_info("", "number of pixels: %" CPL_SIZE_FORMAT, cpl_apertures_get_npix(aperts, 1)); cpl_apertures_test_one(aperts, stream); @@ -348,10 +345,10 @@ cpl_apertures_get_npix(aperts, 1)); /* Get the brightest object */ - cpl_msg_info("","Get the brightest aperture:"); + cpl_msg_info("", "Get the brightest aperture:"); error = cpl_apertures_sort_by_flux(aperts); cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_msg_info("","flux: %g", cpl_apertures_get_flux(aperts, 1)); + cpl_msg_info("", "flux: %g", cpl_apertures_get_flux(aperts, 1)); cpl_apertures_test_one(aperts, stream); @@ -359,10 +356,11 @@ cpl_apertures_get_flux(aperts, 1)); /* Get the aperture with the highest peak */ - cpl_msg_info("","Get the aperture with the highest peak:"); + cpl_msg_info("", "Get the aperture with the highest peak:"); error = cpl_apertures_sort_by_max(aperts); cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_msg_info("","maximum value: %g", cpl_apertures_get_max(aperts, 1)); + cpl_msg_info("", "maximum value: %g", + cpl_apertures_get_max(aperts, 1)); cpl_apertures_test_one(aperts, stream); @@ -376,7 +374,7 @@ errsize = ap_get_cpl_size[isize](aperts, 0); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); cpl_test_lt(errsize, 0.0); - errsize = ap_get_cpl_size[isize](aperts, 1+naperts); + errsize = ap_get_cpl_size[isize](aperts, 1 + naperts); cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); cpl_test_lt(errsize, 0.0); } @@ -385,7 +383,7 @@ double errpos = ap_get_double_pos[isize](aperts, 0); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); cpl_test_lt(errpos, 0.0); - errpos = ap_get_double_pos[isize](aperts, 1+naperts); + errpos = ap_get_double_pos[isize](aperts, 1 + naperts); cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); cpl_test_lt(errpos, 0.0); } @@ -393,26 +391,25 @@ for (isize = 0; isize < napdbl; isize++) { (void)ap_get_double[isize](aperts, 0); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); - (void)ap_get_double[isize](aperts, 1+naperts); + (void)ap_get_double[isize](aperts, 1 + naperts); cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); } cpl_apertures_delete(aperts); cpl_image_delete(imb); cpl_image_delete(img); - } } cpl_image_delete(imd); - + /* Create a new test image */ imd = cpl_image_fill_test_create(IMAGESZ2, IMAGESZ2); - - sigmas = cpl_vector_wrap(4, (double*)psigmas); + + sigmas = cpl_vector_wrap(4, (double *)psigmas); /* Test cpl_apertures_extract() */ - cpl_msg_info("","Test the apertures detection with a thresholding method"); + cpl_msg_info("", "Test the apertures detection with a thresholding method"); aperts = cpl_apertures_extract(imd, sigmas, &pos); cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(aperts); @@ -438,9 +435,10 @@ cpl_test_null(nullapert); /* Test cpl_apertures_extract_window() */ - cpl_msg_info("","Test the apertures detection (threshold) on a zone"); - aperts = cpl_apertures_extract_window(imd, sigmas, IMAGESZ2/4, IMAGESZ2/4, - 3*IMAGESZ2/4, 3*IMAGESZ2/4, &pos); + cpl_msg_info("", "Test the apertures detection (threshold) on a zone"); + aperts = + cpl_apertures_extract_window(imd, sigmas, IMAGESZ2 / 4, IMAGESZ2 / 4, + 3 * IMAGESZ2 / 4, 3 * IMAGESZ2 / 4, &pos); cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(aperts); @@ -456,7 +454,7 @@ cpl_apertures_test_one(aperts, stream); for (pos = 1; pos < nsize; pos++) { - cpl_test_leq(cpl_apertures_get_max(aperts, pos+1), + cpl_test_leq(cpl_apertures_get_max(aperts, pos + 1), cpl_apertures_get_max(aperts, pos)); } @@ -467,7 +465,7 @@ cpl_apertures_test_one(aperts, stream); for (pos = 1; pos < nsize; pos++) { - cpl_test_leq(cpl_apertures_get_npix(aperts, pos+1), + cpl_test_leq(cpl_apertures_get_npix(aperts, pos + 1), cpl_apertures_get_npix(aperts, pos)); } @@ -479,7 +477,7 @@ cpl_apertures_test_one(aperts, stream); for (pos = 1; pos < nsize; pos++) { - cpl_test_leq(cpl_apertures_get_flux(aperts, pos+1), + cpl_test_leq(cpl_apertures_get_flux(aperts, pos + 1), cpl_apertures_get_flux(aperts, pos)); } @@ -488,13 +486,13 @@ cpl_image_delete(imd); cpl_mask_delete(bpm); - if (stream != stdout) cpl_test_zero( fclose(stream) ); + if (stream != stdout) + cpl_test_zero(fclose(stream)); return cpl_test_end(0); } - /*----------------------------------------------------------------------------*/ /** @internal @@ -505,7 +503,8 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_apertures_test_one(const cpl_apertures * self, FILE * stream) +static void +cpl_apertures_test_one(const cpl_apertures *self, FILE *stream) { const cpl_size nsize = cpl_apertures_get_size(self); cpl_size i; diff -Nru cpl-7.1.4+ds/cpldrs/tests/cpl_detector-test.c cpl-7.2.2+ds/cpldrs/tests/cpl_detector-test.c --- cpl-7.1.4+ds/cpldrs/tests/cpl_detector-test.c 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cpldrs/tests/cpl_detector-test.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -35,30 +35,31 @@ Define -----------------------------------------------------------------------------*/ -#define IMAGESZX 10 -#define IMAGESZY 20 -#define IMAGESZ2 100 +#define IMAGESZX 10 +#define IMAGESZY 20 +#define IMAGESZ2 100 /*----------------------------------------------------------------------------- Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { - const cpl_type pixel_type[] = {CPL_TYPE_DOUBLE, CPL_TYPE_FLOAT, - CPL_TYPE_INT, CPL_TYPE_DOUBLE_COMPLEX, - CPL_TYPE_FLOAT_COMPLEX}; - const int nbad = 10; + const cpl_type pixel_type[] = { CPL_TYPE_DOUBLE, CPL_TYPE_FLOAT, + CPL_TYPE_INT, CPL_TYPE_DOUBLE_COMPLEX, + CPL_TYPE_FLOAT_COMPLEX }; + const int nbad = 10; /* The bad pixel positions */ - const int bad_pos_x[] = {4, 5, 6, 4, 5, 6, 4, 5, 6, 8}; - const int bad_pos_y[] = {5, 5, 5, 6, 6, 6, 7, 7, 7, 9}; + const int bad_pos_x[] = { 4, 5, 6, 4, 5, 6, 4, 5, 6, 8 }; + const int bad_pos_y[] = { 5, 5, 5, 6, 6, 6, 7, 7, 7, 9 }; /* Two concentric circles in the image center */ - const double zone1[] - = {0.5*IMAGESZ2, 0.5*IMAGESZ2, IMAGESZ2/10.0, IMAGESZ2/5.0}; - const double zone2[] - = {0.5*IMAGESZ2, 0.5*IMAGESZ2, IMAGESZ2/10.0, IMAGESZ2/10.0}; - double noise, errnoise; - unsigned itype; - int i; + const double zone1[] = { 0.5 * IMAGESZ2, 0.5 * IMAGESZ2, IMAGESZ2 / 10.0, + IMAGESZ2 / 5.0 }; + const double zone2[] = { 0.5 * IMAGESZ2, 0.5 * IMAGESZ2, IMAGESZ2 / 10.0, + IMAGESZ2 / 10.0 }; + double noise, errnoise; + unsigned itype; + int i; cpl_error_code error; @@ -67,20 +68,19 @@ /* Insert tests below */ /* Test 0: Test with nbad pixels */ - cpl_test_eq(nbad, sizeof(bad_pos_x)/sizeof(bad_pos_x[0])); - cpl_test_eq(nbad, sizeof(bad_pos_y)/sizeof(bad_pos_y[0])); + cpl_test_eq(nbad, sizeof(bad_pos_x) / sizeof(bad_pos_x[0])); + cpl_test_eq(nbad, sizeof(bad_pos_y) / sizeof(bad_pos_y[0])); - for (itype = 0; - itype < sizeof(pixel_type)/sizeof(pixel_type[0]); + for (itype = 0; itype < sizeof(pixel_type) / sizeof(pixel_type[0]); itype++) { const cpl_type mytype = pixel_type[itype]; const cpl_boolean is_complex = pixel_type[itype] == CPL_TYPE_DOUBLE_COMPLEX || pixel_type[itype] == CPL_TYPE_FLOAT_COMPLEX; - cpl_image * im; - cpl_image * copy; - double stdev; + cpl_image *im; + cpl_image *copy; + double stdev; /* Create the test image */ im = cpl_image_new(IMAGESZX, IMAGESZY, mytype); @@ -94,7 +94,8 @@ error = cpl_detector_interpolate_rejected(copy); cpl_test_eq_error(error, CPL_ERROR_NONE); - if (!is_complex) cpl_test_image_abs(im, copy, 0.0); + if (!is_complex) + cpl_test_image_abs(im, copy, 0.0); cpl_image_delete(copy); /* Set the bad pixels values */ @@ -110,20 +111,22 @@ copy = cpl_image_duplicate(im); - if (!is_complex) stdev = cpl_image_get_stdev(im); + if (!is_complex) + stdev = cpl_image_get_stdev(im); error = cpl_detector_interpolate_rejected(im); cpl_test_eq_error(error, CPL_ERROR_NONE); cpl_test_null(cpl_image_get_bpm_const(im)); - if (!is_complex) cpl_test_leq(cpl_image_get_stdev(im), stdev); + if (!is_complex) + cpl_test_leq(cpl_image_get_stdev(im), stdev); if (pixel_type[itype] == CPL_TYPE_DOUBLE) { /* In absence of an actual unit test for the cleaning, a regression test may be used to ensure that no unintended changes occur */ - cpl_image * load - = cpl_image_load("regression.fits", CPL_TYPE_DOUBLE, 0, 0); + cpl_image *load = + cpl_image_load("regression.fits", CPL_TYPE_DOUBLE, 0, 0); if (load == NULL) { cpl_test_error(CPL_ERROR_FILE_IO); @@ -133,10 +136,11 @@ cpl_detector_interpolate_rejected() to enable a regression test of your changes. */ - cpl_image_save(im, "regression.fits", CPL_TYPE_DOUBLE, - NULL, CPL_IO_CREATE); + cpl_image_save(im, "regression.fits", CPL_TYPE_DOUBLE, NULL, + CPL_IO_CREATE); #endif - } else { + } + else { cpl_test_error(CPL_ERROR_NONE); cpl_test_image_abs(load, im, 20.0 * DBL_EPSILON); @@ -148,7 +152,7 @@ /* Test 2a: Verify that the cleaning is isotropic */ for (i = 1; i < 4; i++) { - cpl_image * turn = cpl_image_duplicate(copy); + cpl_image *turn = cpl_image_duplicate(copy); cpl_test_nonnull(turn); @@ -217,7 +221,6 @@ cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT); cpl_image_delete(im); - } /* Test 6B: NULL input */ diff -Nru cpl-7.1.4+ds/cpldrs/tests/cpl_fft-test.c cpl-7.2.2+ds/cpldrs/tests/cpl_fft-test.c --- cpl-7.1.4+ds/cpldrs/tests/cpl_fft-test.c 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cpldrs/tests/cpl_fft-test.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -18,7 +18,7 @@ */ #ifdef HAVE_CONFIG_H -# include +#include #endif /*----------------------------------------------------------------------------- @@ -36,7 +36,7 @@ -----------------------------------------------------------------------------*/ #ifndef IMAGESZ -#define IMAGESZ 10 +#define IMAGESZ 10 #endif #ifndef IMAGENZ @@ -44,7 +44,7 @@ #endif #ifndef CONSTANT -#define CONSTANT 200 +#define CONSTANT 200 #endif /*----------------------------------------------------------------------------*/ @@ -54,7 +54,6 @@ /*----------------------------------------------------------------------------*/ - /*----------------------------------------------------------------------------- Private Function prototypes -----------------------------------------------------------------------------*/ @@ -62,8 +61,8 @@ #if defined CPL_FFTWF_INSTALLED || defined CPL_FFTW_INSTALLED static void cpl_fft_image_test_one(cpl_size, cpl_size, cpl_type); static void cpl_fft_imagelist_test_one(cpl_size, cpl_size, cpl_size, cpl_type); -static -void cpl_fft_imagelist_test_image(cpl_size, cpl_size, cpl_size, cpl_type); +static void + cpl_fft_imagelist_test_image(cpl_size, cpl_size, cpl_size, cpl_type); static void cpl_fft_image_test_correlate(cpl_size, cpl_size, cpl_type); @@ -75,9 +74,10 @@ **/ /*----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { - const cpl_type imtypes[] = {CPL_TYPE_DOUBLE, CPL_TYPE_FLOAT}; + const cpl_type imtypes[] = { CPL_TYPE_DOUBLE, CPL_TYPE_FLOAT }; cpl_boolean do_bench; int i; @@ -96,17 +96,17 @@ /* Collect wisdom */ #ifdef CPL_FFTWF_INSTALLED if (imtypes[i] == CPL_TYPE_FLOAT) { - cpl_fft_image_test_one( 16, 16, imtypes[i]); - cpl_fft_image_test_one( 4, 32, imtypes[i]); - cpl_fft_image_test_one( 4, 4, imtypes[i]); - cpl_fft_image_test_one( 2, 128, imtypes[i]); - cpl_fft_image_test_one(128, 2, imtypes[i]); - cpl_fft_image_test_one(128, 1, imtypes[i]); - cpl_fft_image_test_one( 1, 128, imtypes[i]); - - cpl_fft_image_test_correlate( 16, 16, imtypes[i]); - cpl_fft_image_test_correlate( 64, 128, imtypes[i]); - cpl_fft_image_test_correlate(128, 64, imtypes[i]); + cpl_fft_image_test_one(16, 16, imtypes[i]); + cpl_fft_image_test_one(4, 32, imtypes[i]); + cpl_fft_image_test_one(4, 4, imtypes[i]); + cpl_fft_image_test_one(2, 128, imtypes[i]); + cpl_fft_image_test_one(128, 2, imtypes[i]); + cpl_fft_image_test_one(128, 1, imtypes[i]); + cpl_fft_image_test_one(1, 128, imtypes[i]); + + cpl_fft_image_test_correlate(16, 16, imtypes[i]); + cpl_fft_image_test_correlate(64, 128, imtypes[i]); + cpl_fft_image_test_correlate(128, 64, imtypes[i]); cpl_fft_image_test_correlate(128, 128, imtypes[i]); if (do_bench) { @@ -118,17 +118,17 @@ #ifdef CPL_FFTW_INSTALLED if (imtypes[i] == CPL_TYPE_DOUBLE) { - cpl_fft_image_test_one( 16, 16, imtypes[i]); - cpl_fft_image_test_one( 32, 4, imtypes[i]); - cpl_fft_image_test_one( 4, 4, imtypes[i]); - cpl_fft_image_test_one( 2, 128, imtypes[i]); - cpl_fft_image_test_one(128, 2, imtypes[i]); - cpl_fft_image_test_one(128, 1, imtypes[i]); - cpl_fft_image_test_one( 1, 128, imtypes[i]); - - cpl_fft_image_test_correlate( 16, 16, imtypes[i]); - cpl_fft_image_test_correlate( 64, 128, imtypes[i]); - cpl_fft_image_test_correlate(128, 64, imtypes[i]); + cpl_fft_image_test_one(16, 16, imtypes[i]); + cpl_fft_image_test_one(32, 4, imtypes[i]); + cpl_fft_image_test_one(4, 4, imtypes[i]); + cpl_fft_image_test_one(2, 128, imtypes[i]); + cpl_fft_image_test_one(128, 2, imtypes[i]); + cpl_fft_image_test_one(128, 1, imtypes[i]); + cpl_fft_image_test_one(1, 128, imtypes[i]); + + cpl_fft_image_test_correlate(16, 16, imtypes[i]); + cpl_fft_image_test_correlate(64, 128, imtypes[i]); + cpl_fft_image_test_correlate(128, 64, imtypes[i]); cpl_fft_image_test_correlate(128, 128, imtypes[i]); if (do_bench) { @@ -139,17 +139,16 @@ #endif - - for (nz = 1; nz <= 1 + mz; nz+= mz) { + for (nz = 1; nz <= 1 + mz; nz += mz) { #ifdef CPL_FFTWF_INSTALLED if (imtypes[i] == CPL_TYPE_FLOAT) { - cpl_fft_imagelist_test_image( 16, 16, nz, imtypes[i]); - cpl_fft_imagelist_test_image( 4, 32, nz, imtypes[i]); - cpl_fft_imagelist_test_image( 4, 4, nz, imtypes[i]); - cpl_fft_imagelist_test_image( 2, 128, nz, imtypes[i]); - cpl_fft_imagelist_test_image(128, 2, nz, imtypes[i]); - cpl_fft_imagelist_test_image(128, 1, nz, imtypes[i]); - cpl_fft_imagelist_test_image( 1, 128, nz, imtypes[i]); + cpl_fft_imagelist_test_image(16, 16, nz, imtypes[i]); + cpl_fft_imagelist_test_image(4, 32, nz, imtypes[i]); + cpl_fft_imagelist_test_image(4, 4, nz, imtypes[i]); + cpl_fft_imagelist_test_image(2, 128, nz, imtypes[i]); + cpl_fft_imagelist_test_image(128, 2, nz, imtypes[i]); + cpl_fft_imagelist_test_image(128, 1, nz, imtypes[i]); + cpl_fft_imagelist_test_image(1, 128, nz, imtypes[i]); if (do_bench) { cpl_fft_imagelist_test_image(256, 256, nz, imtypes[i]); @@ -159,13 +158,13 @@ #ifdef CPL_FFTW_INSTALLED if (imtypes[i] == CPL_TYPE_DOUBLE) { - cpl_fft_imagelist_test_image( 16, 16, nz, imtypes[i]); - cpl_fft_imagelist_test_image( 32, 4, nz, imtypes[i]); - cpl_fft_imagelist_test_image( 4, 4, nz, imtypes[i]); - cpl_fft_imagelist_test_image( 2, 128, nz, imtypes[i]); - cpl_fft_imagelist_test_image(128, 2, nz, imtypes[i]); - cpl_fft_imagelist_test_image(128, 1, nz, imtypes[i]); - cpl_fft_imagelist_test_image( 1, 128, nz, imtypes[i]); + cpl_fft_imagelist_test_image(16, 16, nz, imtypes[i]); + cpl_fft_imagelist_test_image(32, 4, nz, imtypes[i]); + cpl_fft_imagelist_test_image(4, 4, nz, imtypes[i]); + cpl_fft_imagelist_test_image(2, 128, nz, imtypes[i]); + cpl_fft_imagelist_test_image(128, 2, nz, imtypes[i]); + cpl_fft_imagelist_test_image(128, 1, nz, imtypes[i]); + cpl_fft_imagelist_test_image(1, 128, nz, imtypes[i]); if (do_bench) { cpl_fft_imagelist_test_image(256, 256, nz, imtypes[i]); @@ -190,24 +189,25 @@ **/ /*----------------------------------------------------------------------------*/ -static void cpl_fft_image_test(void) +static void +cpl_fft_image_test(void) { - const cpl_type imtypes[] = {CPL_TYPE_DOUBLE, CPL_TYPE_FLOAT, - CPL_TYPE_INT, CPL_TYPE_DOUBLE_COMPLEX, - CPL_TYPE_FLOAT_COMPLEX}; - int ityp; - int nok = 0; /* Number of successful calls */ + const cpl_type imtypes[] = { CPL_TYPE_DOUBLE, CPL_TYPE_FLOAT, CPL_TYPE_INT, + CPL_TYPE_DOUBLE_COMPLEX, + CPL_TYPE_FLOAT_COMPLEX }; + int ityp; + int nok = 0; /* Number of successful calls */ /* Insert tests below */ /* Iterate through all pixel types */ - for (ityp = 0; ityp < (int)(sizeof(imtypes)/sizeof(imtypes[0])); ityp++) { + for (ityp = 0; ityp < (int)(sizeof(imtypes) / sizeof(imtypes[0])); ityp++) { const cpl_type imtype = imtypes[ityp]; int ityp2; - cpl_image * img1 = cpl_image_new(IMAGESZ, IMAGESZ, imtype); - cpl_image * img3 = cpl_image_new(IMAGESZ, IMAGESZ, imtype); + cpl_image *img1 = cpl_image_new(IMAGESZ, IMAGESZ, imtype); + cpl_image *img3 = cpl_image_new(IMAGESZ, IMAGESZ, imtype); cpl_error_code error; /* Various error checks */ @@ -225,28 +225,33 @@ #else cpl_test_eq_error(error, CPL_ERROR_UNSUPPORTED_MODE); #endif - } else if (imtype & CPL_TYPE_FLOAT) { + } + else if (imtype & CPL_TYPE_FLOAT) { #ifdef CPL_FFTWF_INSTALLED cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); #else cpl_test_eq_error(error, CPL_ERROR_UNSUPPORTED_MODE); #endif - } else { + } + else { cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); } - } else if (imtype == CPL_TYPE_DOUBLE) { + } + else if (imtype == CPL_TYPE_DOUBLE) { #ifdef CPL_FFTW_INSTALLED cpl_test_eq_error(error, CPL_ERROR_TYPE_MISMATCH); #else cpl_test_eq_error(error, CPL_ERROR_UNSUPPORTED_MODE); #endif - } else if (imtype == CPL_TYPE_FLOAT) { + } + else if (imtype == CPL_TYPE_FLOAT) { #ifdef CPL_FFTWF_INSTALLED cpl_test_eq_error(error, CPL_ERROR_TYPE_MISMATCH); #else cpl_test_eq_error(error, CPL_ERROR_UNSUPPORTED_MODE); #endif - } else { + } + else { cpl_test_eq_error(error, CPL_ERROR_TYPE_MISMATCH); } @@ -255,12 +260,12 @@ cpl_test_eq_error(error, CPL_ERROR_NONE); } - for (ityp2 = 0; ityp2 < (int)(sizeof(imtypes)/sizeof(imtypes[0])); + for (ityp2 = 0; ityp2 < (int)(sizeof(imtypes) / sizeof(imtypes[0])); ityp2++) { const cpl_type imtype2 = imtypes[ityp2]; - cpl_image * img2 = cpl_image_new(IMAGESZ, IMAGESZ, imtype2); - const cpl_image * imgin = img3; - cpl_image * imgout = img2; + cpl_image *img2 = cpl_image_new(IMAGESZ, IMAGESZ, imtype2); + const cpl_image *imgin = img3; + cpl_image *imgout = img2; int idir; /* No scaling on the forward transform has no effect */ unsigned mode = CPL_FFT_FORWARD | CPL_FFT_NOSCALE; @@ -273,14 +278,13 @@ /* Those two iterations will succeed iff the input image and output image have matching non-integer precision */ - for (idir = 0; idir < 2; idir++, mode = CPL_FFT_BACKWARD, - imgin = img2, imgout = img3) { - + for (idir = 0; idir < 2; + idir++, mode = CPL_FFT_BACKWARD, imgin = img2, imgout = img3) { error = cpl_fft_image(imgout, imgin, mode); if (cpl_image_get_type(img3) == CPL_TYPE_FLOAT && - cpl_image_get_type(img2) == - (CPL_TYPE_FLOAT | CPL_TYPE_COMPLEX)) { + cpl_image_get_type(img2) == + (CPL_TYPE_FLOAT | CPL_TYPE_COMPLEX)) { #ifdef CPL_FFTWF_INSTALLED cpl_test_eq_error(CPL_ERROR_NONE, error); nok++; @@ -294,9 +298,10 @@ #else cpl_test_eq_error(CPL_ERROR_UNSUPPORTED_MODE, error); #endif - } else if (cpl_image_get_type(img3) == CPL_TYPE_DOUBLE && - cpl_image_get_type(img2) == - (CPL_TYPE_DOUBLE | CPL_TYPE_COMPLEX)) { + } + else if (cpl_image_get_type(img3) == CPL_TYPE_DOUBLE && + cpl_image_get_type(img2) == + (CPL_TYPE_DOUBLE | CPL_TYPE_COMPLEX)) { #ifdef CPL_FFTW_INSTALLED cpl_test_eq_error(CPL_ERROR_NONE, error); nok++; @@ -310,33 +315,38 @@ #else cpl_test_eq_error(CPL_ERROR_UNSUPPORTED_MODE, error); #endif - - } else if (cpl_image_get_type(img3) == - (CPL_TYPE_DOUBLE | CPL_TYPE_COMPLEX) && - cpl_image_get_type(img2) == - (CPL_TYPE_DOUBLE | CPL_TYPE_COMPLEX)) { + } + else if (cpl_image_get_type(img3) == + (CPL_TYPE_DOUBLE | CPL_TYPE_COMPLEX) && + cpl_image_get_type(img2) == + (CPL_TYPE_DOUBLE | CPL_TYPE_COMPLEX)) { #ifdef CPL_FFTW_INSTALLED cpl_test_eq_error(CPL_ERROR_NONE, error); #else cpl_test_eq_error(CPL_ERROR_UNSUPPORTED_MODE, error); #endif - } else if (cpl_image_get_type(img3) == - (CPL_TYPE_FLOAT | CPL_TYPE_COMPLEX) && - cpl_image_get_type(img2) == - (CPL_TYPE_FLOAT | CPL_TYPE_COMPLEX)) { + } + else if (cpl_image_get_type(img3) == + (CPL_TYPE_FLOAT | CPL_TYPE_COMPLEX) && + cpl_image_get_type(img2) == + (CPL_TYPE_FLOAT | CPL_TYPE_COMPLEX)) { #ifdef CPL_FFTWF_INSTALLED cpl_test_eq_error(CPL_ERROR_NONE, error); #else cpl_test_eq_error(CPL_ERROR_UNSUPPORTED_MODE, error); #endif - } else if ((imtype & CPL_TYPE_INT) || - (imtype2 & CPL_TYPE_INT)) { + } + else if ((imtype & CPL_TYPE_INT) || (imtype2 & CPL_TYPE_INT)) { cpl_test_eq_error(CPL_ERROR_TYPE_MISMATCH, error); - } else if ((imtype & (CPL_TYPE_FLOAT | CPL_TYPE_DOUBLE | CPL_TYPE_INT)) != - (imtype2 & (CPL_TYPE_FLOAT | CPL_TYPE_DOUBLE | CPL_TYPE_INT))) { + } + else if ((imtype & + (CPL_TYPE_FLOAT | CPL_TYPE_DOUBLE | CPL_TYPE_INT)) != + (imtype2 & + (CPL_TYPE_FLOAT | CPL_TYPE_DOUBLE | CPL_TYPE_INT))) { cpl_test_eq_error(CPL_ERROR_TYPE_MISMATCH, error); - } else if (!((imtype & CPL_TYPE_COMPLEX) ^ - (imtype2 & CPL_TYPE_COMPLEX))) { + } + else if (!((imtype & CPL_TYPE_COMPLEX) ^ + (imtype2 & CPL_TYPE_COMPLEX))) { /* None or both are complex */ if (imtype == CPL_TYPE_DOUBLE) { #ifdef CPL_FFTW_INSTALLED @@ -344,28 +354,33 @@ #else cpl_test_eq_error(CPL_ERROR_UNSUPPORTED_MODE, error); #endif - } else if (imtype == CPL_TYPE_FLOAT) { + } + else if (imtype == CPL_TYPE_FLOAT) { #ifdef CPL_FFTWF_INSTALLED cpl_test_eq_error(CPL_ERROR_TYPE_MISMATCH, error); #else cpl_test_eq_error(CPL_ERROR_UNSUPPORTED_MODE, error); #endif - } else { + } + else { cpl_test_eq_error(CPL_ERROR_TYPE_MISMATCH, error); } - } else if (imtype & CPL_TYPE_DOUBLE) { + } + else if (imtype & CPL_TYPE_DOUBLE) { #ifdef CPL_FFTW_INSTALLED - cpl_test_eq_error(CPL_ERROR_TYPE_MISMATCH, error); + cpl_test_eq_error(CPL_ERROR_TYPE_MISMATCH, error); #else - cpl_test_eq_error(CPL_ERROR_UNSUPPORTED_MODE, error); + cpl_test_eq_error(CPL_ERROR_UNSUPPORTED_MODE, error); #endif - } else if (imtype & CPL_TYPE_FLOAT) { + } + else if (imtype & CPL_TYPE_FLOAT) { #ifdef CPL_FFTWF_INSTALLED - cpl_test_eq_error(CPL_ERROR_TYPE_MISMATCH, error); + cpl_test_eq_error(CPL_ERROR_TYPE_MISMATCH, error); #else - cpl_test_eq_error(CPL_ERROR_UNSUPPORTED_MODE, error); + cpl_test_eq_error(CPL_ERROR_UNSUPPORTED_MODE, error); #endif - } else { + } + else { cpl_test_eq_error(CPL_ERROR_TYPE_MISMATCH, error); } } @@ -378,17 +393,16 @@ cpl_test_eq(nok, 4); /* Forward and backward of float and double */ #elif defined CPL_FFTWF_INSTALLED cpl_msg_warning(cpl_func, "Double precision FFT not available for " - "unit testing"); + "unit testing"); cpl_test_eq(nok, 2); /* Forward and backward of type float */ #elif defined CPL_FFTW_INSTALLED cpl_msg_warning(cpl_func, "Single precision FFT not available for " - "unit testing"); + "unit testing"); cpl_test_eq(nok, 2); /* Forward and backward of type double */ #else cpl_msg_warning(cpl_func, "FFT not available for unit testing"); cpl_test_zero(nok); #endif - } #if defined CPL_FFTWF_INSTALLED || defined CPL_FFTW_INSTALLED @@ -404,20 +418,20 @@ **/ /*----------------------------------------------------------------------------*/ -static void cpl_fft_image_test_one(cpl_size nx, cpl_size ny, cpl_type type) +static void +cpl_fft_image_test_one(cpl_size nx, cpl_size ny, cpl_type type) { - - const int rigor = CPL_FFT_FIND_MEASURE; - cpl_image * image1r = cpl_image_new(nx, ny, type); - cpl_image * image1c; - cpl_image * image2 = cpl_image_new(nx, ny, type); - cpl_image * image3r = cpl_image_new(nx, ny, type | CPL_TYPE_COMPLEX); - cpl_image * image3c = cpl_image_new(nx, ny, type | CPL_TYPE_COMPLEX); - cpl_image * image3h = cpl_image_new(nx/2+1, ny, type | CPL_TYPE_COMPLEX); - cpl_image * image4; - cpl_image * image4r; - cpl_image * image4c; - cpl_image * image5 = cpl_image_new(nx, ny, type); + const int rigor = CPL_FFT_FIND_MEASURE; + cpl_image *image1r = cpl_image_new(nx, ny, type); + cpl_image *image1c; + cpl_image *image2 = cpl_image_new(nx, ny, type); + cpl_image *image3r = cpl_image_new(nx, ny, type | CPL_TYPE_COMPLEX); + cpl_image *image3c = cpl_image_new(nx, ny, type | CPL_TYPE_COMPLEX); + cpl_image *image3h = cpl_image_new(nx / 2 + 1, ny, type | CPL_TYPE_COMPLEX); + cpl_image *image4; + cpl_image *image4r; + cpl_image *image4c; + cpl_image *image5 = cpl_image_new(nx, ny, type); cpl_error_code error; error = cpl_image_fill_noise_uniform(image1r, 0.0, 1.0); @@ -430,15 +444,16 @@ cpl_test_eq_error(error, CPL_ERROR_NONE); /* Extract half of r2c transform */ - image4 = cpl_image_extract(image3r, 1, 1, nx/2 + 1, ny); + image4 = cpl_image_extract(image3r, 1, 1, nx / 2 + 1, ny); /* Real-to-complex, complex is half size */ error = cpl_fft_image(image3h, image1r, CPL_FFT_FORWARD | rigor); cpl_test_eq_error(error, CPL_ERROR_NONE); /* That half has to match the transform onto the half-sized image */ - cpl_test_image_abs(image3h, image4, 80.0 * (type == CPL_TYPE_DOUBLE ? - DBL_EPSILON : FLT_EPSILON)); + cpl_test_image_abs(image3h, image4, + 80.0 * (type == CPL_TYPE_DOUBLE ? DBL_EPSILON + : FLT_EPSILON)); /* Complex-to-complex of same real values */ error = cpl_fft_image(image3c, image1c, CPL_FFT_FORWARD | rigor); @@ -448,31 +463,36 @@ error = cpl_fft_image(image1c, image1c, CPL_FFT_FORWARD | rigor); cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_image_abs(image3c, image1c, type == CPL_TYPE_DOUBLE ? - 128.0 * DBL_EPSILON : 40.0 * FLT_EPSILON); + cpl_test_image_abs(image3c, image1c, + type == CPL_TYPE_DOUBLE ? 128.0 * DBL_EPSILON + : 40.0 * FLT_EPSILON); /* Extract half of c2c transform */ cpl_image_delete(image4); - image4 = cpl_image_extract(image3c, 1, 1, nx/2 + 1, ny); + image4 = cpl_image_extract(image3c, 1, 1, nx / 2 + 1, ny); - cpl_test_image_abs(image3h, image4, 128.0 * nx * - (type == CPL_TYPE_DOUBLE ? DBL_EPSILON : FLT_EPSILON)); + cpl_test_image_abs(image3h, image4, + 128.0 * nx * + (type == CPL_TYPE_DOUBLE ? DBL_EPSILON + : FLT_EPSILON)); /* Complex-to-real, both full size */ error = cpl_fft_image(image2, image3r, CPL_FFT_BACKWARD | rigor); cpl_test_eq_error(error, CPL_ERROR_NONE); /* The back-transformed must match the original image */ - cpl_test_image_abs(image1r, image2, 6.0 * (type == CPL_TYPE_DOUBLE ? - DBL_EPSILON : FLT_EPSILON)); + cpl_test_image_abs(image1r, image2, + 6.0 * (type == CPL_TYPE_DOUBLE ? DBL_EPSILON + : FLT_EPSILON)); /* Complex-to-real, complex is half size */ error = cpl_fft_image(image2, image3h, CPL_FFT_BACKWARD | rigor); cpl_test_eq_error(error, CPL_ERROR_NONE); /* The back-transformed must match the original image */ - cpl_test_image_abs(image1r, image2, 6.0 * (type == CPL_TYPE_DOUBLE ? - DBL_EPSILON : FLT_EPSILON)); + cpl_test_image_abs(image1r, image2, + 6.0 * (type == CPL_TYPE_DOUBLE ? DBL_EPSILON + : FLT_EPSILON)); /* Complex-to-complex of same real values */ error = cpl_fft_image(image3r, image3c, CPL_FFT_BACKWARD | rigor); @@ -482,22 +502,25 @@ error = cpl_fft_image(image3c, image3c, CPL_FFT_BACKWARD | rigor); cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_image_abs(image3r, image3c, 3.2 * (type == CPL_TYPE_DOUBLE ? - DBL_EPSILON : FLT_EPSILON)); + cpl_test_image_abs(image3r, image3c, + 3.2 * (type == CPL_TYPE_DOUBLE ? DBL_EPSILON + : FLT_EPSILON)); /* The back-transformed must match the original image - on the real part */ image4r = cpl_image_extract_real(image3r); - cpl_test_image_abs(image1r, image4r, 6.0 * (type == CPL_TYPE_DOUBLE ? - DBL_EPSILON : FLT_EPSILON)); + cpl_test_image_abs(image1r, image4r, + 6.0 * (type == CPL_TYPE_DOUBLE ? DBL_EPSILON + : FLT_EPSILON)); /* The back-transformed must have a zero-valued imaginary part */ image4c = cpl_image_extract_imag(image3r); cpl_image_delete(image4); image4 = cpl_image_new(nx, ny, type); - cpl_test_image_abs(image4c, image4, 2.0 * (type == CPL_TYPE_DOUBLE ? - DBL_EPSILON : FLT_EPSILON)); + cpl_test_image_abs(image4c, image4, + 2.0 * (type == CPL_TYPE_DOUBLE ? DBL_EPSILON + : FLT_EPSILON)); cpl_image_delete(image1r); cpl_image_delete(image1c); @@ -509,7 +532,6 @@ cpl_image_delete(image4r); cpl_image_delete(image4c); cpl_image_delete(image5); - } /*----------------------------------------------------------------------------*/ @@ -524,35 +546,35 @@ **/ /*----------------------------------------------------------------------------*/ -static void cpl_fft_imagelist_test_one(cpl_size nx, cpl_size ny, cpl_size nz, - cpl_type type) +static void +cpl_fft_imagelist_test_one(cpl_size nx, cpl_size ny, cpl_size nz, cpl_type type) { - const int rigor = CPL_FFT_FIND_MEASURE; - cpl_imagelist * ilist1r = cpl_imagelist_new(); - cpl_imagelist * ilist1c = cpl_imagelist_new(); - cpl_imagelist * ilist2 = cpl_imagelist_new(); - cpl_imagelist * ilist3r = cpl_imagelist_new(); - cpl_imagelist * ilist3c = cpl_imagelist_new(); - cpl_imagelist * ilist3h = cpl_imagelist_new(); - cpl_imagelist * ilist4 = cpl_imagelist_new(); - cpl_imagelist * ilist4r = cpl_imagelist_new(); - cpl_imagelist * ilist4c = cpl_imagelist_new(); - cpl_imagelist * ilistr = cpl_imagelist_new(); - cpl_imagelist * ilistc = cpl_imagelist_new(); - cpl_imagelist * ilist5 = cpl_imagelist_new(); + const int rigor = CPL_FFT_FIND_MEASURE; + cpl_imagelist *ilist1r = cpl_imagelist_new(); + cpl_imagelist *ilist1c = cpl_imagelist_new(); + cpl_imagelist *ilist2 = cpl_imagelist_new(); + cpl_imagelist *ilist3r = cpl_imagelist_new(); + cpl_imagelist *ilist3c = cpl_imagelist_new(); + cpl_imagelist *ilist3h = cpl_imagelist_new(); + cpl_imagelist *ilist4 = cpl_imagelist_new(); + cpl_imagelist *ilist4r = cpl_imagelist_new(); + cpl_imagelist *ilist4c = cpl_imagelist_new(); + cpl_imagelist *ilistr = cpl_imagelist_new(); + cpl_imagelist *ilistc = cpl_imagelist_new(); + cpl_imagelist *ilist5 = cpl_imagelist_new(); cpl_error_code error; - cpl_size i; + cpl_size i; for (i = 0; i < nz; i++) { - cpl_image * image1r = cpl_image_new(nx, ny, type); - cpl_image * image1c; - cpl_image * image2 = cpl_image_new(nx, ny, type); - cpl_image * image3r = cpl_image_new(nx, ny, type | CPL_TYPE_COMPLEX); - cpl_image * image3c; - cpl_image * image3h = cpl_image_new(nx/2+1, ny, type - | CPL_TYPE_COMPLEX); - cpl_image * image5 = cpl_image_new(nx, ny, type); + cpl_image *image1r = cpl_image_new(nx, ny, type); + cpl_image *image1c; + cpl_image *image2 = cpl_image_new(nx, ny, type); + cpl_image *image3r = cpl_image_new(nx, ny, type | CPL_TYPE_COMPLEX); + cpl_image *image3c; + cpl_image *image3h = + cpl_image_new(nx / 2 + 1, ny, type | CPL_TYPE_COMPLEX); + cpl_image *image5 = cpl_image_new(nx, ny, type); error = cpl_image_fill_noise_uniform(image1r, 0.0, 1.0); cpl_test_eq_error(error, CPL_ERROR_NONE); @@ -563,7 +585,7 @@ error = cpl_imagelist_set(ilist1c, image1c, i); cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_imagelist_set(ilist2 , image2, i); + error = cpl_imagelist_set(ilist2, image2, i); cpl_test_eq_error(error, CPL_ERROR_NONE); error = cpl_imagelist_set(ilist3r, image3r, i); @@ -576,9 +598,8 @@ error = cpl_imagelist_set(ilist3h, image3h, i); cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_imagelist_set(ilist5, image5, i); + error = cpl_imagelist_set(ilist5, image5, i); cpl_test_eq_error(error, CPL_ERROR_NONE); - } @@ -588,9 +609,8 @@ /* Extract half of r2c transform */ for (i = 0; i < nz; i++) { - const cpl_image * image3r = cpl_imagelist_get_const(ilist3r, i); - cpl_image * image4 = cpl_image_extract(image3r, 1, 1, - nx/2 + 1, ny); + const cpl_image *image3r = cpl_imagelist_get_const(ilist3r, i); + cpl_image *image4 = cpl_image_extract(image3r, 1, 1, nx / 2 + 1, ny); error = cpl_imagelist_set(ilist4, image4, i); cpl_test_eq_error(error, CPL_ERROR_NONE); @@ -601,8 +621,9 @@ cpl_test_eq_error(error, CPL_ERROR_NONE); /* That half has to match the transform onto the half-sized image */ - cpl_test_imagelist_abs(ilist3h, ilist4, 80.0 * (type == CPL_TYPE_DOUBLE ? - DBL_EPSILON : FLT_EPSILON)); + cpl_test_imagelist_abs(ilist3h, ilist4, + 80.0 * (type == CPL_TYPE_DOUBLE ? DBL_EPSILON + : FLT_EPSILON)); /* Complex-to-complex of same real values */ error = cpl_fft_imagelist(ilist3c, ilist1c, CPL_FFT_FORWARD | rigor); @@ -612,39 +633,43 @@ error = cpl_fft_imagelist(ilist1c, ilist1c, CPL_FFT_FORWARD | rigor); cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_imagelist_abs(ilist3c, ilist1c, 2.0 * (nx + ny) * - (type == CPL_TYPE_DOUBLE ? - DBL_EPSILON : FLT_EPSILON)); + cpl_test_imagelist_abs(ilist3c, ilist1c, + 2.0 * (nx + ny) * + (type == CPL_TYPE_DOUBLE ? DBL_EPSILON + : FLT_EPSILON)); /* Extract half of c2c transform */ cpl_imagelist_empty(ilist4); for (i = 0; i < nz; i++) { - const cpl_image * image3c = cpl_imagelist_get_const(ilist3c, i); - cpl_image * image4 = cpl_image_extract(image3c, 1, 1, - nx/2 + 1, ny); + const cpl_image *image3c = cpl_imagelist_get_const(ilist3c, i); + cpl_image *image4 = cpl_image_extract(image3c, 1, 1, nx / 2 + 1, ny); error = cpl_imagelist_set(ilist4, image4, i); cpl_test_eq_error(error, CPL_ERROR_NONE); } - cpl_test_imagelist_abs(ilist3h, ilist4, 128.0 * nx * - (type == CPL_TYPE_DOUBLE ? DBL_EPSILON : FLT_EPSILON)); + cpl_test_imagelist_abs(ilist3h, ilist4, + 128.0 * nx * + (type == CPL_TYPE_DOUBLE ? DBL_EPSILON + : FLT_EPSILON)); /* Complex-to-real, both full size */ error = cpl_fft_imagelist(ilist2, ilist3r, CPL_FFT_BACKWARD | rigor); cpl_test_eq_error(error, CPL_ERROR_NONE); /* The back-transformed must match the original image */ - cpl_test_imagelist_abs(ilist1r, ilist2, 6.0 * (type == CPL_TYPE_DOUBLE ? - DBL_EPSILON : FLT_EPSILON)); + cpl_test_imagelist_abs(ilist1r, ilist2, + 6.0 * (type == CPL_TYPE_DOUBLE ? DBL_EPSILON + : FLT_EPSILON)); /* Complex-to-real, complex is half size */ error = cpl_fft_imagelist(ilist2, ilist3h, CPL_FFT_BACKWARD | rigor); cpl_test_eq_error(error, CPL_ERROR_NONE); /* The back-transformed must match the original image */ - cpl_test_imagelist_abs(ilist1r, ilist2, 6.0 * (type == CPL_TYPE_DOUBLE ? - DBL_EPSILON : FLT_EPSILON)); + cpl_test_imagelist_abs(ilist1r, ilist2, + 6.0 * (type == CPL_TYPE_DOUBLE ? DBL_EPSILON + : FLT_EPSILON)); /* Complex-to-complex of same real values */ error = cpl_fft_imagelist(ilist3r, ilist3c, CPL_FFT_BACKWARD | rigor); @@ -654,18 +679,19 @@ error = cpl_fft_imagelist(ilist3c, ilist3c, CPL_FFT_BACKWARD | rigor); cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_test_imagelist_abs(ilist3r, ilist3c, 8.0 * (type == CPL_TYPE_DOUBLE ? - DBL_EPSILON : FLT_EPSILON)); + cpl_test_imagelist_abs(ilist3r, ilist3c, + 8.0 * (type == CPL_TYPE_DOUBLE ? DBL_EPSILON + : FLT_EPSILON)); /* The back-transformed must match the original image - on the real part */ /* - and the back-transformed must have a zero-valued imaginary part */ cpl_imagelist_empty(ilist4); for (i = 0; i < nz; i++) { - const cpl_image * image3r = cpl_imagelist_get_const(ilist3r, i); - cpl_image * image4r = cpl_image_extract_real(image3r); - cpl_image * image4c = cpl_image_extract_imag(image3r); - cpl_image * image4 = cpl_image_new(nx, ny, type); + const cpl_image *image3r = cpl_imagelist_get_const(ilist3r, i); + cpl_image *image4r = cpl_image_extract_real(image3r); + cpl_image *image4c = cpl_image_extract_imag(image3r); + cpl_image *image4 = cpl_image_new(nx, ny, type); error = cpl_imagelist_set(ilist4r, image4r, i); @@ -676,11 +702,13 @@ cpl_test_eq_error(error, CPL_ERROR_NONE); } - cpl_test_imagelist_abs(ilist1r, ilist4r, 6.0 * (type == CPL_TYPE_DOUBLE ? - DBL_EPSILON : FLT_EPSILON)); - - cpl_test_imagelist_abs(ilist4c, ilist4, 2.0 * (type == CPL_TYPE_DOUBLE ? - DBL_EPSILON : FLT_EPSILON)); + cpl_test_imagelist_abs(ilist1r, ilist4r, + 6.0 * (type == CPL_TYPE_DOUBLE ? DBL_EPSILON + : FLT_EPSILON)); + + cpl_test_imagelist_abs(ilist4c, ilist4, + 2.0 * (type == CPL_TYPE_DOUBLE ? DBL_EPSILON + : FLT_EPSILON)); cpl_imagelist_delete(ilist1r); cpl_imagelist_delete(ilist1c); @@ -694,8 +722,6 @@ cpl_imagelist_delete(ilistr); cpl_imagelist_delete(ilistc); cpl_imagelist_delete(ilist5); - - } /*----------------------------------------------------------------------------*/ @@ -709,10 +735,12 @@ @see cpl_fft_imagelist_test_one() cpl_fft_image_test_one() **/ /*----------------------------------------------------------------------------*/ -static void cpl_fft_imagelist_test_image(cpl_size nx, cpl_size ny, cpl_size nz, - cpl_type type) +static void +cpl_fft_imagelist_test_image(cpl_size nx, + cpl_size ny, + cpl_size nz, + cpl_type type) { - cpl_flops flopl0, flopl1, flopi0, flopi1; double timel0, timel1, timei0, timei1; cpl_size i; @@ -738,21 +766,23 @@ timei1 = cpl_test_get_cputime() - timei0; if (timei1 > 0.0 && timel1 > 0.0) { - cpl_msg_info(cpl_func, "List vs single %d X %d X %d (%s): %g <=> %g " - "[s] (%g <=> %g [MFLOP/s])", (int)nx, (int)ny, - (int)nz, cpl_type_get_name(type), timel1, timei1, - 1e-6*(double)flopl1/timel1, - 1e-6*(double)flopi1/timei1); - } else { - cpl_msg_info(cpl_func, "List vs single %d X %d X %d (%s): %g <=> %g " - "[s] (%g <=> %g [MFLOP])", (int)nx, (int)ny, - (int)nz, cpl_type_get_name(type), timel1, timei1, - 1e-6*(double)flopl1, 1e-6*(double)flopi1); + cpl_msg_info(cpl_func, + "List vs single %d X %d X %d (%s): %g <=> %g " + "[s] (%g <=> %g [MFLOP/s])", + (int)nx, (int)ny, (int)nz, cpl_type_get_name(type), timel1, + timei1, 1e-6 * (double)flopl1 / timel1, + 1e-6 * (double)flopi1 / timei1); + } + else { + cpl_msg_info(cpl_func, + "List vs single %d X %d X %d (%s): %g <=> %g " + "[s] (%g <=> %g [MFLOP])", + (int)nx, (int)ny, (int)nz, cpl_type_get_name(type), timel1, + timei1, 1e-6 * (double)flopl1, 1e-6 * (double)flopi1); } } - /*----------------------------------------------------------------------------*/ /** @internal @@ -763,18 +793,17 @@ @see cpl_fft_image_test_one() **/ /*----------------------------------------------------------------------------*/ -static -void cpl_fft_image_test_correlate(cpl_size nx, cpl_size ny, cpl_type type) +static void +cpl_fft_image_test_correlate(cpl_size nx, cpl_size ny, cpl_type type) { - - cpl_image * ia = cpl_image_new(nx, ny, type); - cpl_image * ib = cpl_image_new(nx, ny, type); - cpl_image * ic = cpl_image_new(nx, ny, type); - cpl_image * fa = cpl_image_new(nx, ny, type | CPL_TYPE_COMPLEX); - cpl_image * fb = cpl_image_new(nx, ny, type | CPL_TYPE_COMPLEX); - cpl_image * fc = cpl_image_new(nx, ny, type | CPL_TYPE_COMPLEX); - cpl_imagelist * iab = cpl_imagelist_new(); - cpl_imagelist * fab = cpl_imagelist_new(); + cpl_image *ia = cpl_image_new(nx, ny, type); + cpl_image *ib = cpl_image_new(nx, ny, type); + cpl_image *ic = cpl_image_new(nx, ny, type); + cpl_image *fa = cpl_image_new(nx, ny, type | CPL_TYPE_COMPLEX); + cpl_image *fb = cpl_image_new(nx, ny, type | CPL_TYPE_COMPLEX); + cpl_image *fc = cpl_image_new(nx, ny, type | CPL_TYPE_COMPLEX); + cpl_imagelist *iab = cpl_imagelist_new(); + cpl_imagelist *fab = cpl_imagelist_new(); cpl_size xmax, ymax; cpl_error_code code; @@ -788,13 +817,13 @@ code = cpl_imagelist_set(fab, fb, 1); cpl_test_eq_error(code, CPL_ERROR_NONE); - code = cpl_image_fill_gaussian(ia, nx/2.0, ny/2.0, 1.0, 1.0, 1.0); + code = cpl_image_fill_gaussian(ia, nx / 2.0, ny / 2.0, 1.0, 1.0, 1.0); cpl_test_eq_error(code, CPL_ERROR_NONE); code = cpl_image_copy(ib, ia, 1, 1); cpl_test_eq_error(code, CPL_ERROR_NONE); - code = cpl_image_shift(ib, nx/4, ny/4); + code = cpl_image_shift(ib, nx / 4, ny / 4); cpl_test_eq_error(code, CPL_ERROR_NONE); code = cpl_fft_imagelist(fab, iab, CPL_FFT_FORWARD); @@ -829,8 +858,8 @@ code = cpl_image_get_maxpos(ic, &xmax, &ymax); cpl_test_eq_error(code, CPL_ERROR_NONE); - cpl_test_eq(xmax, 1 + nx/2 + nx/4); - cpl_test_eq(ymax, 1 + ny/2 + ny/4); + cpl_test_eq(xmax, 1 + nx / 2 + nx / 4); + cpl_test_eq(ymax, 1 + ny / 2 + ny / 4); cpl_imagelist_delete(iab); cpl_imagelist_delete(fab); diff -Nru cpl-7.1.4+ds/cpldrs/tests/cpl_fit-test.c cpl-7.2.2+ds/cpldrs/tests/cpl_fit-test.c --- cpl-7.1.4+ds/cpldrs/tests/cpl_fit-test.c 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cpldrs/tests/cpl_fit-test.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -18,7 +18,7 @@ */ #ifdef HAVE_CONFIG_H -# include +#include #endif /*----------------------------------------------------------------------------- @@ -42,15 +42,15 @@ -----------------------------------------------------------------------------*/ #ifndef IMAGESZ -#define IMAGESZ 10 +#define IMAGESZ 10 #endif #ifndef IMAGESZFIT -#define IMAGESZFIT 256 +#define IMAGESZFIT 256 #endif #ifndef WINSTART -#define WINSTART 3 +#define WINSTART 3 #endif #define IMSZ 6 @@ -68,10 +68,9 @@ Defines -----------------------------------------------------------------------------*/ -#define cpl_fit_imagelist_is_zero(A, B) \ +#define cpl_fit_imagelist_is_zero(A, B) \ cpl_fit_imagelist_is_zero_macro(A, B, __LINE__) -#define cpl_fit_image_is_zero(A, B) \ - cpl_fit_image_is_zero_macro(A, B, __LINE__) +#define cpl_fit_image_is_zero(A, B) cpl_fit_image_is_zero_macro(A, B, __LINE__) /*----------------------------------------------------------------------------- Private Function prototypes @@ -80,27 +79,40 @@ static void cpl_fit_imagelist_polynomial_tests(void); static void cpl_fit_imagelist_polynomial_bpm(void); static void cpl_fit_image_gaussian_tests(cpl_type, FILE *); -static void cpl_fit_imagelist_is_zero_macro(const cpl_imagelist *, double, - int); +static void cpl_fit_imagelist_is_zero_macro(const cpl_imagelist *, double, int); static void cpl_fit_image_is_zero_macro(const cpl_image *, double, int); static void eval_gauss(const double x[], const double a[], double *); -static int check_gauss_success(const char **, const double *, const double *, - const char **, const double *, const double *, - const cpl_array *, const cpl_array *, - double, double, double, const cpl_matrix *, - FILE *); +static int check_gauss_success(const char **, + const double *, + const double *, + const char **, + const double *, + const double *, + const cpl_array *, + const cpl_array *, + double, + double, + double, + const cpl_matrix *, + FILE *); static void cpl_fit_image_gaussian_test_one(void); static void cpl_fit_image_gaussian_test_local(void); static void cpl_fit_image_gaussian_test_bpm(void); -static -cpl_imagelist * cpl_fit_imagelist_polynomial_window_test(const cpl_vector *, - const cpl_imagelist *, - int, int, int, int, - int, int, cpl_boolean, - cpl_type, cpl_image *); +static cpl_imagelist * +cpl_fit_imagelist_polynomial_window_test(const cpl_vector *, + const cpl_imagelist *, + int, + int, + int, + int, + int, + int, + cpl_boolean, + cpl_type, + cpl_image *); /*----------------------------------------------------------------------------*/ /** @@ -109,16 +121,17 @@ **/ /*----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { - FILE * stream; + FILE *stream; cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); - stream = cpl_msg_get_level() > CPL_MSG_INFO - ? fopen("/dev/null", "a") : stdout; + stream = + cpl_msg_get_level() > CPL_MSG_INFO ? fopen("/dev/null", "a") : stdout; - cpl_test_nonnull( stream ); + cpl_test_nonnull(stream); /* Insert tests below */ cpl_fit_imagelist_polynomial_bpm(); @@ -130,109 +143,104 @@ cpl_fit_image_gaussian_test_local(); cpl_fit_image_gaussian_test_bpm(); - if (stream != stdout) cpl_test_zero( fclose(stream) ); + if (stream != stdout) + cpl_test_zero(fclose(stream)); /* End of tests */ return cpl_test_end(0); } -static void cpl_fit_imagelist_polynomial_tests(void) +static void +cpl_fit_imagelist_polynomial_tests(void) { - - const double ditval[] = {0.0, 1.0, 2.0, 3.0, 4.0, - 5.0, 6.0, 7.0, 8.0}; - const double neqditval[] = {1.0, 2.0, 4.0, 6.0, 10.0, - 14.0, 16.0, 18.0, 19.0}; - cpl_imagelist * fit; - cpl_imagelist * fit_eq; - cpl_imagelist * input; - cpl_image * dfiterror - = cpl_image_new(IMAGESZFIT, IMAGESZFIT, CPL_TYPE_DOUBLE); - cpl_image * ffiterror - = cpl_image_new(IMAGESZFIT, IMAGESZFIT, CPL_TYPE_FLOAT); - cpl_image * ifiterror - = cpl_image_new(IMAGESZFIT, IMAGESZFIT, CPL_TYPE_INT); - cpl_image * cfiterror - = cpl_image_new(IMAGESZFIT, IMAGESZFIT, CPL_TYPE_FLOAT_COMPLEX); - cpl_image * dfiterrorwin; - const int ndits = (int)(sizeof(ditval)/sizeof(double)); + const double ditval[] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; + const double neqditval[] = { 1.0, 2.0, 4.0, 6.0, 10.0, + 14.0, 16.0, 18.0, 19.0 }; + cpl_imagelist *fit; + cpl_imagelist *fit_eq; + cpl_imagelist *input; + cpl_image *dfiterror = + cpl_image_new(IMAGESZFIT, IMAGESZFIT, CPL_TYPE_DOUBLE); + cpl_image *ffiterror = + cpl_image_new(IMAGESZFIT, IMAGESZFIT, CPL_TYPE_FLOAT); + cpl_image *ifiterror = cpl_image_new(IMAGESZFIT, IMAGESZFIT, CPL_TYPE_INT); + cpl_image *cfiterror = + cpl_image_new(IMAGESZFIT, IMAGESZFIT, CPL_TYPE_FLOAT_COMPLEX); + cpl_image *dfiterrorwin; + const int ndits = (int)(sizeof(ditval) / sizeof(double)); CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual) - cpl_vector * vdit = cpl_vector_wrap(ndits, (double*)ditval); - cpl_vector * nvdit = cpl_vector_wrap(ndits, (double*)neqditval); + cpl_vector *vdit = cpl_vector_wrap(ndits, (double *)ditval); + cpl_vector *nvdit = cpl_vector_wrap(ndits, (double *)neqditval); CPL_DIAG_PRAGMA_POP - cpl_polynomial * vfiller = cpl_polynomial_new(1); - const double sqsum = 204.0; /* Sum of squares of ditvals */ - const double mytol = 5.52 * FLT_EPSILON; - cpl_size i; - const cpl_type pixel_type[] = {CPL_TYPE_DOUBLE, CPL_TYPE_FLOAT, - CPL_TYPE_INT}; - const int ntypes = (int)(sizeof(pixel_type)/sizeof(pixel_type[0])); - int ntest; - cpl_flops flopsum = 0; - cpl_flops flops; - double secs = 0.0; - size_t bytes = 0; - double cputime; - double demax; + cpl_polynomial *vfiller = cpl_polynomial_new(1); + const double sqsum = 204.0; /* Sum of squares of ditvals */ + const double mytol = 5.52 * FLT_EPSILON; + cpl_size i; + const cpl_type pixel_type[] = { CPL_TYPE_DOUBLE, CPL_TYPE_FLOAT, + CPL_TYPE_INT }; + const int ntypes = (int)(sizeof(pixel_type) / sizeof(pixel_type[0])); + int ntest; + cpl_flops flopsum = 0; + cpl_flops flops; + double secs = 0.0; + size_t bytes = 0; + double cputime; + double demax; cpl_error_code error; - cpl_msg_info(cpl_func, "Testing with %d %d X %d images", - ndits, IMAGESZFIT, IMAGESZFIT); + cpl_msg_info(cpl_func, "Testing with %d %d X %d images", ndits, IMAGESZFIT, + IMAGESZFIT); fit = cpl_fit_imagelist_polynomial(NULL, NULL, 0, 0, CPL_FALSE, CPL_TYPE_FLOAT, NULL); cpl_test_error(CPL_ERROR_NULL_INPUT); - cpl_test_null( fit ); + cpl_test_null(fit); cpl_imagelist_delete(fit); - fit = cpl_fit_imagelist_polynomial_window(NULL, NULL, 1, 1, - IMAGESZFIT, IMAGESZFIT, - 0, 0, CPL_FALSE, + fit = cpl_fit_imagelist_polynomial_window(NULL, NULL, 1, 1, IMAGESZFIT, + IMAGESZFIT, 0, 0, CPL_FALSE, CPL_TYPE_FLOAT, NULL); cpl_test_error(CPL_ERROR_NULL_INPUT); - cpl_test_null( fit ); + cpl_test_null(fit); cpl_imagelist_delete(fit); input = cpl_imagelist_new(); fit = cpl_fit_imagelist_polynomial(vdit, input, 0, 0, CPL_FALSE, CPL_TYPE_FLOAT, NULL); cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT); - cpl_test_null( fit ); + cpl_test_null(fit); cpl_imagelist_delete(fit); - fit = cpl_fit_imagelist_polynomial_window(vdit, input, 1, 1, - IMAGESZFIT, IMAGESZFIT, - 0, 0, CPL_FALSE, + fit = cpl_fit_imagelist_polynomial_window(vdit, input, 1, 1, IMAGESZFIT, + IMAGESZFIT, 0, 0, CPL_FALSE, CPL_TYPE_FLOAT, NULL); cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT); - cpl_test_null( fit ); + cpl_test_null(fit); cpl_imagelist_delete(fit); fit = cpl_fit_imagelist_polynomial(vdit, input, 1, 1, CPL_FALSE, CPL_TYPE_FLOAT, NULL); cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT); - cpl_test_null( fit ); + cpl_test_null(fit); cpl_imagelist_delete(fit); - fit = cpl_fit_imagelist_polynomial_window(vdit, input, 1, 1, - IMAGESZFIT, IMAGESZFIT, - 0, 0, CPL_FALSE, + fit = cpl_fit_imagelist_polynomial_window(vdit, input, 1, 1, IMAGESZFIT, + IMAGESZFIT, 0, 0, CPL_FALSE, CPL_TYPE_FLOAT, NULL); cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT); - cpl_test_null( fit ); + cpl_test_null(fit); cpl_imagelist_delete(fit); /* Test with all types of pixels */ for (ntest = 0; ntest < ntypes; ntest++) { - const cpl_type test_type = pixel_type[ntest]; - cpl_image * image = cpl_image_new(IMAGESZFIT, IMAGESZ, test_type); + cpl_image *image = cpl_image_new(IMAGESZFIT, IMAGESZ, test_type); + - cpl_msg_info(cpl_func, "Fitting with pixel type: %s", cpl_type_get_name(test_type)); @@ -252,14 +260,12 @@ /* A perfectly linear set */ for (i = 2; i < ndits; i++) { - - image - = cpl_image_multiply_scalar_create(cpl_imagelist_get(input, 1), - ditval[i]); + image = + cpl_image_multiply_scalar_create(cpl_imagelist_get(input, 1), + ditval[i]); error = cpl_imagelist_set(input, image, i); cpl_test_eq_error(error, CPL_ERROR_NONE); - } flops = cpl_tools_get_flops(); @@ -267,15 +273,15 @@ cputime = cpl_test_get_cputime(); fit = cpl_fit_imagelist_polynomial_window_test(vdit, input, 1, 1, - IMAGESZFIT, IMAGESZ, - 1, ndits-1, CPL_FALSE, + IMAGESZFIT, IMAGESZ, 1, + ndits - 1, CPL_FALSE, test_type, NULL); secs += cpl_test_get_cputime() - cputime; flopsum += cpl_tools_get_flops() - flops; bytes += cpl_test_get_bytes_imagelist(input); - cpl_test_error(CPL_ERROR_NONE ); - cpl_test_eq( cpl_imagelist_get_size(fit), ndits - 1 ); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(cpl_imagelist_get_size(fit), ndits - 1); /* The linarity must be equal to the values in image 1 - normalize */ @@ -295,19 +301,19 @@ cputime = cpl_test_get_cputime(); - fit = cpl_fit_imagelist_polynomial_window_test(vdit, input, - WINSTART, WINSTART, + fit = cpl_fit_imagelist_polynomial_window_test(vdit, input, WINSTART, + WINSTART, IMAGESZFIT - WINSTART, - IMAGESZ - WINSTART, - 1, ndits-1, CPL_FALSE, + IMAGESZ - WINSTART, 1, + ndits - 1, CPL_FALSE, test_type, NULL); secs += cpl_test_get_cputime() - cputime; flopsum += cpl_tools_get_flops() - flops; bytes += cpl_test_get_bytes_imagelist(input); - cpl_test_error(CPL_ERROR_NONE ); - cpl_test_eq( cpl_imagelist_get_size(fit), ndits - 1 ); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(cpl_imagelist_get_size(fit), ndits - 1); cpl_imagelist_delete(fit); @@ -340,14 +346,12 @@ /* A perfectly linear set */ for (i = 1; i < ndits; i++) { - - image - = cpl_image_multiply_scalar_create(cpl_imagelist_get(input, 0), - neqditval[i]); + image = + cpl_image_multiply_scalar_create(cpl_imagelist_get(input, 0), + neqditval[i]); error = cpl_imagelist_set(input, image, i); cpl_test_eq_error(error, CPL_ERROR_NONE); - } /* Fit without is_eqdist option */ @@ -356,25 +360,26 @@ cputime = cpl_test_get_cputime(); fit = cpl_fit_imagelist_polynomial_window_test(nvdit, input, 1, 1, - IMAGESZFIT, IMAGESZ, - 1, ndits-1, CPL_FALSE, + IMAGESZFIT, IMAGESZ, 1, + ndits - 1, CPL_FALSE, test_type, NULL); secs += cpl_test_get_cputime() - cputime; flopsum += cpl_tools_get_flops() - flops; bytes += cpl_test_get_bytes_imagelist(input); - cpl_test_error(CPL_ERROR_NONE ); - cpl_test_eq( cpl_imagelist_get_size(fit), ndits - 1 ); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(cpl_imagelist_get_size(fit), ndits - 1); /* Repeat with is_eqdist */ flops = cpl_tools_get_flops(); cputime = cpl_test_get_cputime(); - fit_eq = cpl_fit_imagelist_polynomial_window_test(nvdit, input, 1, 1, - IMAGESZFIT, IMAGESZ, - 1, ndits-1, CPL_TRUE, - test_type, NULL); + fit_eq = + cpl_fit_imagelist_polynomial_window_test(nvdit, input, 1, 1, + IMAGESZFIT, IMAGESZ, 1, + ndits - 1, CPL_TRUE, + test_type, NULL); secs += cpl_test_get_cputime() - cputime; flopsum += cpl_tools_get_flops() - flops; bytes += cpl_test_get_bytes_imagelist(input); @@ -385,38 +390,37 @@ cpl_imagelist_delete(fit_eq); cpl_imagelist_delete(input); input = cpl_imagelist_new(); - } - /* 2nd order function check with and without eq_dist */ - for (i=0; i < ndits; i++) { - cpl_image * image = cpl_image_new(IMAGESZFIT, IMAGESZFIT, - CPL_TYPE_DOUBLE); + for (i = 0; i < ndits; i++) { + cpl_image *image = + cpl_image_new(IMAGESZFIT, IMAGESZFIT, CPL_TYPE_DOUBLE); - error = cpl_image_add_scalar(image, neqditval[i]*neqditval[i]); + error = cpl_image_add_scalar(image, neqditval[i] * neqditval[i]); cpl_test_eq_error(error, CPL_ERROR_NONE); error = cpl_imagelist_set(input, image, i); cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_msg_debug(cpl_func, "Dit and mean of input image no. %" - CPL_SIZE_FORMAT ": %g %g", + cpl_msg_debug(cpl_func, + "Dit and mean of input image no. %" CPL_SIZE_FORMAT + ": %g %g", i, ditval[i], cpl_image_get_mean(image)); } fit = cpl_fit_imagelist_polynomial_window_test(nvdit, input, 1, 1, - IMAGESZFIT, IMAGESZFIT, - 1, ndits, CPL_FALSE, + IMAGESZFIT, IMAGESZFIT, 1, + ndits, CPL_FALSE, CPL_TYPE_FLOAT, NULL); cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(fit); - fit_eq = cpl_fit_imagelist_polynomial_window_test(nvdit, input, 1, 1, - IMAGESZFIT, IMAGESZFIT, - 1, ndits, CPL_TRUE, - CPL_TYPE_FLOAT, NULL); + fit_eq = + cpl_fit_imagelist_polynomial_window_test(nvdit, input, 1, 1, IMAGESZFIT, + IMAGESZFIT, 1, ndits, CPL_TRUE, + CPL_TYPE_FLOAT, NULL); cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(fit_eq); @@ -430,26 +434,26 @@ cpl_test_eq_ptr(cpl_vector_unwrap(nvdit), neqditval); /* Create a list of images with a 2nd order function */ - for (i=0; i < ndits; i++) { - cpl_image * image = cpl_image_new(IMAGESZFIT, IMAGESZFIT, - CPL_TYPE_DOUBLE); + for (i = 0; i < ndits; i++) { + cpl_image *image = + cpl_image_new(IMAGESZFIT, IMAGESZFIT, CPL_TYPE_DOUBLE); - error = cpl_image_add_scalar(image, ditval[i]*ditval[i]); + error = cpl_image_add_scalar(image, ditval[i] * ditval[i]); cpl_test_eq_error(error, CPL_ERROR_NONE); error = cpl_imagelist_set(input, image, i); cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_msg_info(cpl_func, "Dit and mean of input image no. %" - CPL_SIZE_FORMAT ": %g %g", + cpl_msg_info(cpl_func, + "Dit and mean of input image no. %" CPL_SIZE_FORMAT + ": %g %g", i, ditval[i], cpl_image_get_mean(image)); } /* Fit a high-order overdetermined system and a maximum-order, non-overdetermined system */ - for (i = ndits-1; i <= ndits; i++) { - + for (i = ndits - 1; i <= ndits; i++) { fit = cpl_fit_imagelist_polynomial_window_test(vdit, input, 1, 1, IMAGESZFIT, IMAGESZFIT, 1, i, CPL_FALSE, @@ -462,51 +466,50 @@ decomposition fails. */ cpl_test_error(CPL_ERROR_SINGULAR_MATRIX); - } else + } + else #endif - { - cpl_test_error(CPL_ERROR_NONE); - cpl_test_nonnull(fit); - cpl_imagelist_delete(fit); - } - + { + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(fit); + cpl_imagelist_delete(fit); + } } /* Illegal max-degree */ fit = cpl_fit_imagelist_polynomial(vdit, input, 1, 0, CPL_FALSE, CPL_TYPE_FLOAT, NULL); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); - cpl_test_null( fit ); + cpl_test_null(fit); /* Illegal min-degree */ fit = cpl_fit_imagelist_polynomial(vdit, input, -1, 0, CPL_FALSE, CPL_TYPE_FLOAT, NULL); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); - cpl_test_null( fit ); + cpl_test_null(fit); /* Illegal pixeltype */ fit = cpl_fit_imagelist_polynomial(vdit, input, 0, 0, CPL_FALSE, CPL_TYPE_INVALID, NULL); cpl_test_error(CPL_ERROR_UNSUPPORTED_MODE); - cpl_test_null( fit ); + cpl_test_null(fit); flops = cpl_tools_get_flops(); cputime = cpl_test_get_cputime(); /* Fit with zero-order term */ /* Also, try to use an integer-type image for fitting error */ - fit = cpl_fit_imagelist_polynomial_window_test(vdit, input, 1, 1, - IMAGESZFIT, IMAGESZFIT, - 0, 2, CPL_TRUE, - CPL_TYPE_FLOAT, - ifiterror); + fit = + cpl_fit_imagelist_polynomial_window_test(vdit, input, 1, 1, IMAGESZFIT, + IMAGESZFIT, 0, 2, CPL_TRUE, + CPL_TYPE_FLOAT, ifiterror); secs += cpl_test_get_cputime() - cputime; flopsum += cpl_tools_get_flops() - flops; bytes += cpl_test_get_bytes_imagelist(input); - cpl_test_error(CPL_ERROR_NONE ); - cpl_test_eq( cpl_imagelist_get_size(fit), 3 ); - cpl_fit_image_is_zero(ifiterror, mytol); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(cpl_imagelist_get_size(fit), 3); + cpl_fit_image_is_zero(ifiterror, mytol); error = cpl_image_subtract_scalar(cpl_imagelist_get(fit, 2), 1.0); cpl_test_eq_error(error, CPL_ERROR_NONE); @@ -522,16 +525,15 @@ /* Fit with zero-order term */ /* Also, try to use an integer-type image for fitting error */ fit = cpl_fit_imagelist_polynomial_window_test(vdit, input, 1, 1, - IMAGESZFIT, IMAGESZFIT, - 0, ndits-1, CPL_TRUE, - CPL_TYPE_FLOAT, - ifiterror); + IMAGESZFIT, IMAGESZFIT, 0, + ndits - 1, CPL_TRUE, + CPL_TYPE_FLOAT, ifiterror); secs += cpl_test_get_cputime() - cputime; flopsum += cpl_tools_get_flops() - flops; bytes += cpl_test_get_bytes_imagelist(input); - cpl_test_error(CPL_ERROR_NONE ); - cpl_test_eq( cpl_imagelist_get_size(fit), ndits ); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(cpl_imagelist_get_size(fit), ndits); cpl_fit_image_is_zero(ifiterror, mytol); error = cpl_image_subtract_scalar(cpl_imagelist_get(fit, 2), 1.0); @@ -543,15 +545,15 @@ /* Fit without zero-order term */ fit = cpl_fit_imagelist_polynomial_window_test(vdit, input, 1, 1, - IMAGESZFIT, IMAGESZFIT, - 1, ndits-1, CPL_FALSE, + IMAGESZFIT, IMAGESZFIT, 1, + ndits - 1, CPL_FALSE, CPL_TYPE_FLOAT, dfiterror); secs += cpl_test_get_cputime() - cputime; flopsum += cpl_tools_get_flops() - flops; bytes += cpl_test_get_bytes_imagelist(input); - cpl_test_error(CPL_ERROR_NONE ); - cpl_test_eq( cpl_imagelist_get_size(fit), ndits-1 ); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(cpl_imagelist_get_size(fit), ndits - 1); error = cpl_image_subtract_scalar(cpl_imagelist_get(fit, 1), 1.0); cpl_test_eq_error(error, CPL_ERROR_NONE); @@ -562,13 +564,13 @@ cpl_imagelist_delete(fit); /* A valid fit, except that the fitting error is complex */ - fit = cpl_fit_imagelist_polynomial(vdit, input, 1, ndits-1, CPL_FALSE, + fit = cpl_fit_imagelist_polynomial(vdit, input, 1, ndits - 1, CPL_FALSE, CPL_TYPE_FLOAT, cfiterror); cpl_test_error(CPL_ERROR_UNSUPPORTED_MODE); cpl_test_null(fit); /* A valid fit, except that the fitting type is complex */ - fit = cpl_fit_imagelist_polynomial(vdit, input, 1, ndits-1, CPL_FALSE, + fit = cpl_fit_imagelist_polynomial(vdit, input, 1, ndits - 1, CPL_FALSE, CPL_TYPE_FLOAT_COMPLEX, ffiterror); cpl_test_error(CPL_ERROR_UNSUPPORTED_MODE); cpl_test_null(fit); @@ -578,27 +580,26 @@ /* Repeat previous test on _window() function */ dfiterrorwin = cpl_image_new(IMAGESZFIT - 2 * WINSTART + 1, - IMAGESZ - 2 * WINSTART + 1, - CPL_TYPE_DOUBLE); + IMAGESZ - 2 * WINSTART + 1, CPL_TYPE_DOUBLE); - fit = cpl_fit_imagelist_polynomial_window_test(vdit, input, - WINSTART, WINSTART, - IMAGESZFIT - WINSTART, - IMAGESZ - WINSTART, - 1, ndits-1, CPL_FALSE, - CPL_TYPE_FLOAT, - dfiterrorwin); + fit = + cpl_fit_imagelist_polynomial_window_test(vdit, input, WINSTART, + WINSTART, + IMAGESZFIT - WINSTART, + IMAGESZ - WINSTART, 1, + ndits - 1, CPL_FALSE, + CPL_TYPE_FLOAT, dfiterrorwin); secs += cpl_test_get_cputime() - cputime; flopsum += cpl_tools_get_flops() - flops; bytes += cpl_test_get_bytes_imagelist(input); /* FIXME: Too large... */ - cpl_test_error(CPL_ERROR_NONE ); - cpl_test_eq( cpl_imagelist_get_size(fit), ndits-1 ); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(cpl_imagelist_get_size(fit), ndits - 1); - cpl_test_eq(cpl_image_get_size_x(cpl_imagelist_get(fit, 0)), - IMAGESZFIT - 2 * WINSTART + 1 ); - cpl_test_eq(cpl_image_get_size_y(cpl_imagelist_get(fit, 0)), - IMAGESZ - 2 * WINSTART + 1 ); + cpl_test_eq(cpl_image_get_size_x(cpl_imagelist_get(fit, 0)), + IMAGESZFIT - 2 * WINSTART + 1); + cpl_test_eq(cpl_image_get_size_y(cpl_imagelist_get(fit, 0)), + IMAGESZ - 2 * WINSTART + 1); error = cpl_image_subtract_scalar(cpl_imagelist_get(fit, 1), 1.0); cpl_test_eq_error(error, CPL_ERROR_NONE); @@ -613,16 +614,16 @@ cputime = cpl_test_get_cputime(); /* Fit with no zero- and 1st-order terms */ - fit = cpl_fit_imagelist_polynomial_window_test(vdit, input, 1, 1, - IMAGESZFIT, IMAGESZFIT, - 2, ndits, CPL_TRUE, - CPL_TYPE_FLOAT, ffiterror); + fit = + cpl_fit_imagelist_polynomial_window_test(vdit, input, 1, 1, IMAGESZFIT, + IMAGESZFIT, 2, ndits, CPL_TRUE, + CPL_TYPE_FLOAT, ffiterror); secs += cpl_test_get_cputime() - cputime; flopsum += cpl_tools_get_flops() - flops; bytes += cpl_test_get_bytes_imagelist(input); - cpl_test_error(CPL_ERROR_NONE ); - cpl_test_eq( cpl_imagelist_get_size(fit), ndits-1 ); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(cpl_imagelist_get_size(fit), ndits - 1); error = cpl_image_subtract_scalar(cpl_imagelist_get(fit, 0), 1.0); cpl_test_eq_error(error, CPL_ERROR_NONE); @@ -636,20 +637,19 @@ cputime = cpl_test_get_cputime(); /* Fit with one zero-term */ - fit = cpl_fit_imagelist_polynomial_window_test(vdit, input, 1, 1, - IMAGESZFIT, IMAGESZFIT, - 0, 0, CPL_TRUE, - CPL_TYPE_FLOAT, - dfiterror); + fit = + cpl_fit_imagelist_polynomial_window_test(vdit, input, 1, 1, IMAGESZFIT, + IMAGESZFIT, 0, 0, CPL_TRUE, + CPL_TYPE_FLOAT, dfiterror); secs += cpl_test_get_cputime() - cputime; flopsum += cpl_tools_get_flops() - flops; bytes += cpl_test_get_bytes_imagelist(input); - cpl_test_error(CPL_ERROR_NONE ); - cpl_test_eq( cpl_imagelist_get_size(fit), 1 ); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(cpl_imagelist_get_size(fit), 1); error = cpl_image_subtract_scalar(cpl_imagelist_get(fit, 0), - sqsum/(double)ndits); + sqsum / (double)ndits); cpl_test_eq_error(error, CPL_ERROR_NONE); cpl_fit_imagelist_is_zero(fit, mytol); @@ -689,17 +689,18 @@ /* Create a list of images with a 2nd order function */ for (i = ntest - 1; i < ntest; i++) { - cpl_image * image = cpl_image_new(IMAGESZFIT, IMAGESZFIT, - CPL_TYPE_FLOAT); + cpl_image *image = + cpl_image_new(IMAGESZFIT, IMAGESZFIT, CPL_TYPE_FLOAT); - error = cpl_image_add_scalar(image, gain * ditval[i]*ditval[i]); + error = cpl_image_add_scalar(image, gain * ditval[i] * ditval[i]); cpl_test_eq_error(error, CPL_ERROR_NONE); error = cpl_imagelist_set(input, image, i); cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_msg_info(cpl_func, "Dit and mean of input image no. %" - CPL_SIZE_FORMAT ": %g %g", + cpl_msg_info(cpl_func, + "Dit and mean of input image no. %" CPL_SIZE_FORMAT + ": %g %g", i, ditval[i], cpl_image_get_mean(image)); } @@ -709,16 +710,18 @@ cputime = cpl_test_get_cputime(); /* Fit with zero-order term */ - fit = cpl_fit_imagelist_polynomial_window_test(vdit, input, 1, 1, - IMAGESZFIT, IMAGESZFIT, - 0, ntest-1, CPL_TRUE, - CPL_TYPE_FLOAT, - ffiterror); + fit = + cpl_fit_imagelist_polynomial_window_test(vdit, input, 1, 1, + IMAGESZFIT, IMAGESZFIT, 0, + ntest - 1, CPL_TRUE, + CPL_TYPE_FLOAT, ffiterror); if (cpl_error_get_code() != CPL_ERROR_NONE) { - cpl_test_error(CPL_ERROR_SINGULAR_MATRIX ); - cpl_test_null( fit ); - cpl_msg_warning(cpl_func, "Could not fit %d coefficients to as many " - "points", ntest); + cpl_test_error(CPL_ERROR_SINGULAR_MATRIX); + cpl_test_null(fit); + cpl_msg_warning(cpl_func, + "Could not fit %d coefficients to as many " + "points", + ntest); break; @@ -728,12 +731,13 @@ flopsum += cpl_tools_get_flops() - flops; bytes += cpl_test_get_bytes_imagelist(input); - cpl_test_eq( cpl_imagelist_get_size(fit), ntest ); + cpl_test_eq(cpl_imagelist_get_size(fit), ntest); if (ntest == 2) { error = cpl_image_subtract_scalar(cpl_imagelist_get(fit, 1), gain); cpl_test_eq_error(error, CPL_ERROR_NONE); - } else if (ntest > 2) { + } + else if (ntest > 2) { error = cpl_image_subtract_scalar(cpl_imagelist_get(fit, 2), gain); cpl_test_eq_error(error, CPL_ERROR_NONE); } @@ -772,49 +776,67 @@ error = cpl_vector_set(vdit, 8, 7.0); cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_imagelist_set(input, cpl_image_fill_test_create(IMAGESZFIT, - IMAGESZFIT), 0); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_imagelist_set(input, cpl_image_fill_test_create(IMAGESZFIT, - IMAGESZFIT), 1); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_imagelist_set(input, cpl_image_fill_test_create(IMAGESZFIT, - IMAGESZFIT), 2); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_imagelist_set(input, cpl_image_fill_test_create(IMAGESZFIT, - IMAGESZFIT), 3); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_imagelist_set(input, cpl_image_fill_test_create(IMAGESZFIT, - IMAGESZFIT), 4); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_imagelist_set(input, cpl_image_fill_test_create(IMAGESZFIT, - IMAGESZFIT), 5); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_imagelist_set(input, cpl_image_fill_test_create(IMAGESZFIT, - IMAGESZFIT), 6); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_imagelist_set(input, cpl_image_fill_test_create(IMAGESZFIT, - IMAGESZFIT), 7); - cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_imagelist_set(input, cpl_image_fill_test_create(IMAGESZFIT, - IMAGESZFIT), 8); + error = + cpl_imagelist_set(input, + cpl_image_fill_test_create(IMAGESZFIT, IMAGESZFIT), + 0); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = + cpl_imagelist_set(input, + cpl_image_fill_test_create(IMAGESZFIT, IMAGESZFIT), + 1); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = + cpl_imagelist_set(input, + cpl_image_fill_test_create(IMAGESZFIT, IMAGESZFIT), + 2); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = + cpl_imagelist_set(input, + cpl_image_fill_test_create(IMAGESZFIT, IMAGESZFIT), + 3); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = + cpl_imagelist_set(input, + cpl_image_fill_test_create(IMAGESZFIT, IMAGESZFIT), + 4); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = + cpl_imagelist_set(input, + cpl_image_fill_test_create(IMAGESZFIT, IMAGESZFIT), + 5); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = + cpl_imagelist_set(input, + cpl_image_fill_test_create(IMAGESZFIT, IMAGESZFIT), + 6); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = + cpl_imagelist_set(input, + cpl_image_fill_test_create(IMAGESZFIT, IMAGESZFIT), + 7); + cpl_test_eq_error(error, CPL_ERROR_NONE); + error = + cpl_imagelist_set(input, + cpl_image_fill_test_create(IMAGESZFIT, IMAGESZFIT), + 8); cpl_test_eq_error(error, CPL_ERROR_NONE); /* Fit a non-over-determined set without constant and linear terms */ flops = cpl_tools_get_flops(); cputime = cpl_test_get_cputime(); - fit = cpl_fit_imagelist_polynomial_window_test(vdit, input, 1, 1, - IMAGESZFIT, IMAGESZFIT, - 2, 4, CPL_FALSE, - CPL_TYPE_DOUBLE, dfiterror); + fit = + cpl_fit_imagelist_polynomial_window_test(vdit, input, 1, 1, IMAGESZFIT, + IMAGESZFIT, 2, 4, CPL_FALSE, + CPL_TYPE_DOUBLE, dfiterror); secs += cpl_test_get_cputime() - cputime; flopsum += cpl_tools_get_flops() - flops; bytes += cpl_test_get_bytes_imagelist(input); - cpl_test_error(CPL_ERROR_NONE ); - cpl_test_eq( cpl_imagelist_get_size(fit), 3 ); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(cpl_imagelist_get_size(fit), 3); cpl_fit_image_is_zero(dfiterror, DBL_MAX); @@ -824,17 +846,17 @@ flops = cpl_tools_get_flops(); cputime = cpl_test_get_cputime(); - fit = cpl_fit_imagelist_polynomial_window_test(vdit, input, 1, 1, - IMAGESZFIT, IMAGESZFIT, - 0, 2, CPL_FALSE, - CPL_TYPE_DOUBLE, dfiterror); + fit = + cpl_fit_imagelist_polynomial_window_test(vdit, input, 1, 1, IMAGESZFIT, + IMAGESZFIT, 0, 2, CPL_FALSE, + CPL_TYPE_DOUBLE, dfiterror); secs += cpl_test_get_cputime() - cputime; flopsum += cpl_tools_get_flops() - flops; bytes += cpl_test_get_bytes_imagelist(input); - cpl_test_error(CPL_ERROR_NONE ); - cpl_test_eq( cpl_imagelist_get_size(fit), 3 ); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(cpl_imagelist_get_size(fit), 3); cpl_fit_image_is_zero(dfiterror, DBL_MAX); @@ -848,21 +870,21 @@ flops = cpl_tools_get_flops(); cputime = cpl_test_get_cputime(); - fit = cpl_fit_imagelist_polynomial_window_test(vdit, input, 1, 1, - IMAGESZFIT, IMAGESZFIT, - 0, 2, CPL_TRUE, - CPL_TYPE_DOUBLE, dfiterror); + fit = + cpl_fit_imagelist_polynomial_window_test(vdit, input, 1, 1, IMAGESZFIT, + IMAGESZFIT, 0, 2, CPL_TRUE, + CPL_TYPE_DOUBLE, dfiterror); secs += cpl_test_get_cputime() - cputime; flopsum += cpl_tools_get_flops() - flops; bytes += cpl_test_get_bytes_imagelist(input); - cpl_test_error(CPL_ERROR_NONE ); - cpl_test_eq( cpl_imagelist_get_size(fit), 3 ); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(cpl_imagelist_get_size(fit), 3); cpl_fit_image_is_zero(dfiterror, DBL_MAX); - cpl_test_leq( cpl_image_get_sqflux(dfiterror), demax ); + cpl_test_leq(cpl_image_get_sqflux(dfiterror), demax); cpl_imagelist_delete(fit); @@ -873,17 +895,17 @@ flops = cpl_tools_get_flops(); cputime = cpl_test_get_cputime(); - fit = cpl_fit_imagelist_polynomial_window_test(vdit, input, 1, 1, - IMAGESZFIT, IMAGESZFIT, - 0, 2, CPL_TRUE, - CPL_TYPE_DOUBLE, dfiterror); + fit = + cpl_fit_imagelist_polynomial_window_test(vdit, input, 1, 1, IMAGESZFIT, + IMAGESZFIT, 0, 2, CPL_TRUE, + CPL_TYPE_DOUBLE, dfiterror); secs += cpl_test_get_cputime() - cputime; flopsum += cpl_tools_get_flops() - flops; bytes += cpl_test_get_bytes_imagelist(input); - cpl_test_error(CPL_ERROR_NONE ); - cpl_test_eq( cpl_imagelist_get_size(fit), 3 ); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_eq(cpl_imagelist_get_size(fit), 3); cpl_fit_image_is_zero(dfiterror, DBL_MAX); @@ -893,18 +915,19 @@ fit = cpl_fit_imagelist_polynomial(vdit, input, 1, 4, CPL_FALSE, CPL_TYPE_DOUBLE, dfiterror); - cpl_test_error(CPL_ERROR_SINGULAR_MATRIX ); - cpl_test_null( fit ); + cpl_test_error(CPL_ERROR_SINGULAR_MATRIX); + cpl_test_null(fit); cpl_imagelist_delete(input); cpl_vector_delete(vdit); - cpl_msg_info("","Speed while fitting with image size %d in %g secs " - "[Mflop/s]: %g", IMAGESZFIT, secs, - (double)flopsum/secs/1e6); + cpl_msg_info("", + "Speed while fitting with image size %d in %g secs " + "[Mflop/s]: %g", + IMAGESZFIT, secs, (double)flopsum / secs / 1e6); if (secs > 0.0) { - cpl_msg_info(cpl_func,"Processing rate [MB/s]: %g", + cpl_msg_info(cpl_func, "Processing rate [MB/s]: %g", 1e-6 * (double)bytes / secs); } @@ -913,11 +936,9 @@ cpl_image_delete(ffiterror); cpl_image_delete(ifiterror); cpl_polynomial_delete(vfiller); - } - /*----------------------------------------------------------------------------*/ /** @internal @@ -929,15 +950,13 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_fit_imagelist_is_zero_macro(const cpl_imagelist * self, - double tol, int line) +static void +cpl_fit_imagelist_is_zero_macro(const cpl_imagelist *self, double tol, int line) { - const cpl_size n = cpl_imagelist_get_size(self); cpl_size i; for (i = 0; i < n; i++) { - /* FIXME: Need traceback of failure */ cpl_fit_image_is_zero_macro(cpl_imagelist_get_const(self, i), tol, @@ -957,13 +976,12 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_fit_image_is_zero_macro(const cpl_image * self, double tol, - int line) +static void +cpl_fit_image_is_zero_macro(const cpl_image *self, double tol, int line) { - - cpl_stats * stats = cpl_stats_new_from_image(self, - CPL_STATS_MIN | CPL_STATS_MAX - | CPL_STATS_MEAN); + cpl_stats *stats = + cpl_stats_new_from_image(self, CPL_STATS_MIN | CPL_STATS_MAX | + CPL_STATS_MEAN); const double mymin = cpl_stats_get_min(stats); const double mymax = cpl_stats_get_max(stats); @@ -971,73 +989,61 @@ /* FIXME: Need traceback of failure */ cpl_test(line > 0); - cpl_test_leq( fabs(mymin), tol ); - cpl_test_leq( fabs(mymax), tol ); + cpl_test_leq(fabs(mymin), tol); + cpl_test_leq(fabs(mymax), tol); cpl_stats_delete(stats); - } -static void cpl_fit_image_gaussian_tests(cpl_type pixeltype, FILE * stream) +static void +cpl_fit_image_gaussian_tests(cpl_type pixeltype, FILE *stream) { - cpl_image *box = NULL; - cpl_image *image = NULL; - cpl_image *eimage = NULL; + cpl_image *box = NULL; + cpl_image *image = NULL; + cpl_image *eimage = NULL; cpl_matrix *covariance = NULL; - cpl_matrix *phys_cov = NULL; - cpl_array *parameters = NULL; - cpl_array *err_params = NULL; - cpl_array *fit_params = NULL; - double major, minor, angle, rms, chisq, value; - const int nx = 30; - const int ny = 30; - const int lnx = 2438; - const int lny = 2438; - int i, j; + cpl_matrix *phys_cov = NULL; + cpl_array *parameters = NULL; + cpl_array *err_params = NULL; + cpl_array *fit_params = NULL; + double major, minor, angle, rms, chisq, value; + const int nx = 30; + const int ny = 30; + const int lnx = 2438; + const int lny = 2438; + int i, j; cpl_error_code error; double x[2]; - const char *p[7] = { /* Parameter names */ - "Background ", - "Normalisation ", - "Correlation ", - "Center position x", - "Center position y", - "Sigma x ", - "Sigma y "}; + const char *p[7] = { /* Parameter names */ + "Background ", "Normalisation ", + "Correlation ", "Center position x", + "Center position y", "Sigma x ", + "Sigma y " + }; double u[7] = { /* Parameter values of simulated gaussian */ - 2.130659, - 104274.700696, - 0.779320, - 796.851741, - 1976.324361, - 4.506552, - 3.248286 }; + 2.130659, 104274.700696, 0.779320, 796.851741, + 1976.324361, 4.506552, 3.248286 + }; const double e[7] = { /* Errors on parameters of simulated gaussian */ - 2.029266, - 955.703656, - 0.004452, - 0.035972, - 0.025949, - 0.037186, - 0.026913 }; - - const char *fp[3] = { /* Physical parameter names */ - "Angle ", - "Major semi-axis ", - "Minor semi-axis "}; - + 2.029266, 955.703656, 0.004452, 0.035972, + 0.025949, 0.037186, 0.026913 + }; + + const char *fp[3] = { /* Physical parameter names */ + "Angle ", "Major semi-axis ", + "Minor semi-axis " + }; + const double fu[3] = { /* Physical parameter values of simulated gaussian */ - 33.422720, - 5.276152, - 1.738563}; + 33.422720, 5.276152, 1.738563 + }; const double fe[3] = { /* Errors on physical parameters of gaussian */ - 0.238359, - 0.283202, - 0.052671}; + 0.238359, 0.283202, 0.052671 + }; /* @@ -1051,9 +1057,9 @@ for (j = 1; j <= ny; j++) { x[1] = j; for (i = 1; i <= nx; i++) { - x[0] = i; - eval_gauss(x, u, &value); - cpl_image_set(box, i, j, value); + x[0] = i; + eval_gauss(x, u, &value); + cpl_image_set(box, i, j, value); } } u[3] += 782; @@ -1066,7 +1072,8 @@ image = cpl_image_new(lnx, lny, pixeltype); cpl_image_copy(image, box, 783, 1962); - cpl_image_delete(box); box = NULL; + cpl_image_delete(box); + box = NULL; /* @@ -1097,13 +1104,12 @@ */ for (int itry = 0; itry < 2; itry++) { - phys_cov = NULL; covariance = NULL; error = cpl_fit_image_gaussian(image, eimage, 797, 1976, 30, 30, - parameters, err_params, fit_params, - &rms, &chisq, &covariance, &major, - &minor, &angle, &phys_cov); + parameters, err_params, fit_params, &rms, + &chisq, &covariance, &major, &minor, + &angle, &phys_cov); cpl_test_eq_error(error, CPL_ERROR_NONE); if (!error || cpl_msg_get_level() <= CPL_MSG_INFO) cpl_test(check_gauss_success(p, u, e, fp, fu, fe, parameters, @@ -1135,13 +1141,12 @@ cpl_array_set(err_params, i, e[i]); for (int itry = 0; itry < 2; itry++) { - phys_cov = NULL; covariance = NULL; error = cpl_fit_image_gaussian(image, eimage, 797, 1976, 30, 30, - parameters, err_params, fit_params, - &rms, &chisq, &covariance, &major, - &minor, &angle, &phys_cov); + parameters, err_params, fit_params, &rms, + &chisq, &covariance, &major, &minor, + &angle, &phys_cov); cpl_test_eq_error(error, CPL_ERROR_NONE); if (!error || cpl_msg_get_level() <= CPL_MSG_INFO) @@ -1168,9 +1173,9 @@ phys_cov = NULL; covariance = NULL; error = cpl_fit_image_gaussian(image, eimage, 797, 1976, 30, 30, - parameters, err_params, fit_params, - &rms, &chisq, &covariance, &major, - &minor, &angle, &phys_cov); + parameters, err_params, fit_params, &rms, + &chisq, &covariance, &major, &minor, + &angle, &phys_cov); cpl_test_eq_error(error, CPL_ERROR_NONE); if (!error || cpl_msg_get_level() <= CPL_MSG_INFO) @@ -1189,9 +1194,8 @@ phys_cov = NULL; covariance = NULL; error = cpl_fit_image_gaussian(image, NULL, 797, 1976, 30, 30, - parameters, NULL, fit_params, - &rms, NULL, NULL, &major, - &minor, &angle, NULL); + parameters, NULL, fit_params, &rms, NULL, + NULL, &major, &minor, &angle, NULL); cpl_test_eq_error(error, CPL_ERROR_NONE); if (!error || cpl_msg_get_level() <= CPL_MSG_INFO) @@ -1204,105 +1208,105 @@ * Try different error situations: */ - error = cpl_fit_image_gaussian(NULL, eimage, 797, 1976, 30, 30, - parameters, err_params, fit_params, - &rms, &chisq, &covariance, &major, - &minor, &angle, &phys_cov); + error = + cpl_fit_image_gaussian(NULL, eimage, 797, 1976, 30, 30, parameters, + err_params, fit_params, &rms, &chisq, + &covariance, &major, &minor, &angle, &phys_cov); cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT); - error = cpl_fit_image_gaussian(image, eimage, 797, 1976, 30, 30, - NULL, err_params, fit_params, - &rms, &chisq, &covariance, &major, - &minor, &angle, &phys_cov); + error = + cpl_fit_image_gaussian(image, eimage, 797, 1976, 30, 30, NULL, + err_params, fit_params, &rms, &chisq, + &covariance, &major, &minor, &angle, &phys_cov); cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT); - error = cpl_fit_image_gaussian(image, eimage, -1, 1976, 30, 30, - parameters, err_params, fit_params, - &rms, &chisq, &covariance, &major, - &minor, &angle, &phys_cov); + error = + cpl_fit_image_gaussian(image, eimage, -1, 1976, 30, 30, parameters, + err_params, fit_params, &rms, &chisq, + &covariance, &major, &minor, &angle, &phys_cov); cpl_test_eq_error(error, CPL_ERROR_ACCESS_OUT_OF_RANGE); - error = cpl_fit_image_gaussian(image, eimage, 797, 197600, 30, 30, - parameters, err_params, fit_params, - &rms, &chisq, &covariance, &major, - &minor, &angle, &phys_cov); + error = + cpl_fit_image_gaussian(image, eimage, 797, 197600, 30, 30, parameters, + err_params, fit_params, &rms, &chisq, + &covariance, &major, &minor, &angle, &phys_cov); cpl_test_eq_error(error, CPL_ERROR_ACCESS_OUT_OF_RANGE); - error = cpl_fit_image_gaussian(image, eimage, 797, 1976, 300000, 30, - parameters, err_params, fit_params, - &rms, &chisq, &covariance, &major, - &minor, &angle, &phys_cov); + error = + cpl_fit_image_gaussian(image, eimage, 797, 1976, 300000, 30, parameters, + err_params, fit_params, &rms, &chisq, + &covariance, &major, &minor, &angle, &phys_cov); cpl_test_eq_error(error, CPL_ERROR_ACCESS_OUT_OF_RANGE); - error = cpl_fit_image_gaussian(image, eimage, 797, 1976, 2, 30, - parameters, err_params, fit_params, - &rms, &chisq, &covariance, &major, - &minor, &angle, &phys_cov); - + error = + cpl_fit_image_gaussian(image, eimage, 797, 1976, 2, 30, parameters, + err_params, fit_params, &rms, &chisq, + &covariance, &major, &minor, &angle, &phys_cov); + cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); - error = cpl_fit_image_gaussian(image, eimage, 797, 1976, 30, 300000, - parameters, err_params, fit_params, - &rms, &chisq, &covariance, &major, - &minor, &angle, &phys_cov); + error = + cpl_fit_image_gaussian(image, eimage, 797, 1976, 30, 300000, parameters, + err_params, fit_params, &rms, &chisq, + &covariance, &major, &minor, &angle, &phys_cov); cpl_test_eq_error(error, CPL_ERROR_ACCESS_OUT_OF_RANGE); - error = cpl_fit_image_gaussian(image, eimage, 797, 1976, 30, 2, - parameters, err_params, fit_params, - &rms, &chisq, &covariance, &major, - &minor, &angle, &phys_cov); + error = + cpl_fit_image_gaussian(image, eimage, 797, 1976, 30, 2, parameters, + err_params, fit_params, &rms, &chisq, + &covariance, &major, &minor, &angle, &phys_cov); cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); box = cpl_image_new(46, 72, pixeltype); - error = cpl_fit_image_gaussian(image, box, 797, 1976, 30, 30, - parameters, err_params, fit_params, - &rms, &chisq, &covariance, &major, - &minor, &angle, &phys_cov); + error = + cpl_fit_image_gaussian(image, box, 797, 1976, 30, 30, parameters, + err_params, fit_params, &rms, &chisq, + &covariance, &major, &minor, &angle, &phys_cov); cpl_image_delete(box); cpl_test_eq_error(error, CPL_ERROR_INCOMPATIBLE_INPUT); - error = cpl_fit_image_gaussian(image, eimage, 797, 1976, 30, 30, - parameters, fit_params, fit_params, - &rms, &chisq, &covariance, &major, - &minor, &angle, &phys_cov); + error = + cpl_fit_image_gaussian(image, eimage, 797, 1976, 30, 30, parameters, + fit_params, fit_params, &rms, &chisq, + &covariance, &major, &minor, &angle, &phys_cov); cpl_test_eq_error(error, CPL_ERROR_INVALID_TYPE); - error = cpl_fit_image_gaussian(image, eimage, 797, 1976, 30, 30, - fit_params, err_params, fit_params, - &rms, &chisq, &covariance, &major, - &minor, &angle, &phys_cov); + error = + cpl_fit_image_gaussian(image, eimage, 797, 1976, 30, 30, fit_params, + err_params, fit_params, &rms, &chisq, + &covariance, &major, &minor, &angle, &phys_cov); cpl_test_eq_error(error, CPL_ERROR_INVALID_TYPE); - error = cpl_fit_image_gaussian(image, eimage, 797, 1976, 30, 30, - parameters, err_params, err_params, - &rms, &chisq, &covariance, &major, - &minor, &angle, &phys_cov); + error = + cpl_fit_image_gaussian(image, eimage, 797, 1976, 30, 30, parameters, + err_params, err_params, &rms, &chisq, + &covariance, &major, &minor, &angle, &phys_cov); cpl_test_eq_error(error, CPL_ERROR_INVALID_TYPE); - error = cpl_fit_image_gaussian(image, NULL, 797, 1976, 30, 30, - parameters, err_params, fit_params, - &rms, &chisq, &covariance, &major, - &minor, &angle, &phys_cov); + error = + cpl_fit_image_gaussian(image, NULL, 797, 1976, 30, 30, parameters, + err_params, fit_params, &rms, &chisq, + &covariance, &major, &minor, &angle, &phys_cov); cpl_test_eq_error(error, CPL_ERROR_DATA_NOT_FOUND); for (i = 0; i < 7; i++) cpl_array_set(fit_params, i, 0); /* All frozen */ - error = cpl_fit_image_gaussian(image, eimage, 797, 1976, 30, 30, - parameters, err_params, fit_params, - &rms, &chisq, &covariance, &major, - &minor, &angle, &phys_cov); + error = + cpl_fit_image_gaussian(image, eimage, 797, 1976, 30, 30, parameters, + err_params, fit_params, &rms, &chisq, + &covariance, &major, &minor, &angle, &phys_cov); cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); @@ -1311,10 +1315,10 @@ cpl_image_delete(eimage); eimage = cpl_image_duplicate(image); - error = cpl_fit_image_gaussian(image, eimage, 797, 1976, 30, 30, - parameters, err_params, fit_params, - &rms, &chisq, &covariance, &major, - &minor, &angle, &phys_cov); + error = + cpl_fit_image_gaussian(image, eimage, 797, 1976, 30, 30, parameters, + err_params, fit_params, &rms, &chisq, + &covariance, &major, &minor, &angle, &phys_cov); cpl_test_eq_error(error, CPL_ERROR_INVALID_TYPE); @@ -1323,21 +1327,22 @@ cpl_image_delete(eimage); eimage = cpl_image_duplicate(image); - error = cpl_fit_image_gaussian(image, eimage, 797, 1976, 30, 30, - parameters, err_params, fit_params, - &rms, &chisq, &covariance, &major, - &minor, &angle, &phys_cov); + error = + cpl_fit_image_gaussian(image, eimage, 797, 1976, 30, 30, parameters, + err_params, fit_params, &rms, &chisq, + &covariance, &major, &minor, &angle, &phys_cov); cpl_test_eq_error(error, CPL_ERROR_INVALID_TYPE); cpl_image_delete(image); - image = cpl_image_new(lnx, lny, pixeltype == CPL_TYPE_DOUBLE - ? CPL_TYPE_FLOAT : CPL_TYPE_DOUBLE); - - error = cpl_fit_image_gaussian(image, eimage, 797, 1976, 30, 30, - parameters, err_params, fit_params, - &rms, &chisq, &covariance, &major, - &minor, &angle, &phys_cov); + image = cpl_image_new(lnx, lny, + pixeltype == CPL_TYPE_DOUBLE ? CPL_TYPE_FLOAT + : CPL_TYPE_DOUBLE); + + error = + cpl_fit_image_gaussian(image, eimage, 797, 1976, 30, 30, parameters, + err_params, fit_params, &rms, &chisq, + &covariance, &major, &minor, &angle, &phys_cov); cpl_test_eq_error(error, CPL_ERROR_TYPE_MISMATCH); @@ -1346,11 +1351,11 @@ cpl_array_delete(parameters); cpl_array_delete(err_params); cpl_array_delete(fit_params); - } -static void eval_gauss(const double x[], const double a[], double *result) +static void +eval_gauss(const double x[], const double a[], double *result) { if (a[5] == 0.0) { if (x[0] == a[3]) { @@ -1373,39 +1378,41 @@ double b2 = (x[0] - a[3]) / a[5]; double b3 = (x[1] - a[4]) / a[6]; - *result = a[0] - + a[1] / (CPL_MATH_2PI * a[5] * a[6] * sqrt(1 - a[2] * a[2])) - * exp(b1 * (b2 * b2 - 2 * a[2] * b2 * b3 + b3 * b3)); + *result = + a[0] + a[1] / (CPL_MATH_2PI * a[5] * a[6] * sqrt(1 - a[2] * a[2])) * + exp(b1 * (b2 * b2 - 2 * a[2] * b2 * b3 + b3 * b3)); } return; } -static int check_gauss_success(const char **p, - const double *u, - const double *e, - const char **fp, - const double *fu, - const double *fe, - const cpl_array *parameters, - const cpl_array *err_params, - double angle, - double major, - double minor, - const cpl_matrix *phys_cov, - FILE * stream) +static int +check_gauss_success(const char **p, + const double *u, + const double *e, + const char **fp, + const double *fu, + const double *fe, + const cpl_array *parameters, + const cpl_array *err_params, + double angle, + double major, + double minor, + const cpl_matrix *phys_cov, + FILE *stream) { - cpl_matrix *matrix = NULL; - int success = 0; - int i; + cpl_matrix *matrix = NULL; + int success = 0; + int i; if (phys_cov == NULL) { matrix = cpl_matrix_new(3, 3); cpl_matrix_fill(matrix, 0.0); phys_cov = matrix; - } else { + } + else { /* The covariance matrix must be 3 X 3, symmetric, positive definite */ cpl_error_code error; @@ -1419,11 +1426,9 @@ cpl_test_eq_error(error, CPL_ERROR_NONE); cpl_matrix_dump(phys_cov, stream); - } for (i = 0; i < 7; i++) { - /* * The info message is only printed if * cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_INFO); @@ -1432,8 +1437,8 @@ */ cpl_msg_info(cpl_func, "%s = %f +- %f", p[i], - cpl_array_get_double(parameters, i, NULL), - cpl_array_get_double(err_params, i, NULL)); + cpl_array_get_double(parameters, i, NULL), + cpl_array_get_double(err_params, i, NULL)); /* * The result must not differ from expectations more than 3 sigmas. @@ -1445,8 +1450,8 @@ * problem would be to store simulated images in the CPL repository. */ - success = fabs(cpl_array_get_double(parameters, i, NULL) - u[i]) - < 3.0 * e[i]; + success = + fabs(cpl_array_get_double(parameters, i, NULL) - u[i]) < 3.0 * e[i]; if (!success) { cpl_msg_error(cpl_func, "Expected value for %s = %f +- %f", p[i], @@ -1458,13 +1463,13 @@ return success; } } - + cpl_msg_info(cpl_func, "%s = %f +- %f (degrees)", fp[0], - angle * CPL_MATH_DEG_RAD, + angle * CPL_MATH_DEG_RAD, sqrt(cpl_matrix_get(phys_cov, 0, 0)) * CPL_MATH_DEG_RAD); - success = fabs(angle * CPL_MATH_DEG_RAD - fu[0]) - < 3.0 * fe[0] * CPL_MATH_DEG_RAD; + success = + fabs(angle * CPL_MATH_DEG_RAD - fu[0]) < 3.0 * fe[0] * CPL_MATH_DEG_RAD; if (!success) { cpl_msg_error(cpl_func, "Expected value for %s = %f +- %f", fp[0], @@ -1476,8 +1481,8 @@ return success; } - cpl_msg_info(cpl_func, "%s = %f +- %f", fp[1], - major, sqrt(cpl_matrix_get(phys_cov, 1, 1))); + cpl_msg_info(cpl_func, "%s = %f +- %f", fp[1], major, + sqrt(cpl_matrix_get(phys_cov, 1, 1))); success = fabs(major - fu[1]) < 3.0 * fe[1]; @@ -1485,13 +1490,13 @@ cpl_msg_error(cpl_func, "Expected value for %s = %f +- %f", fp[1], fu[1], fe[1]); cpl_msg_error(cpl_func, "Obtained value for %s = %f +- %f", fp[1], - major, sqrt(cpl_matrix_get(phys_cov, 1, 1))); + major, sqrt(cpl_matrix_get(phys_cov, 1, 1))); cpl_matrix_delete(matrix); return success; } - cpl_msg_info(cpl_func, "%s = %f +- %f\n", fp[2], - minor, sqrt(cpl_matrix_get(phys_cov, 2, 2))); + cpl_msg_info(cpl_func, "%s = %f +- %f\n", fp[2], minor, + sqrt(cpl_matrix_get(phys_cov, 2, 2))); success = fabs(minor - fu[2]) < 3.0 * fe[2]; @@ -1499,7 +1504,7 @@ cpl_msg_error(cpl_func, "Expected value for %s = %f +- %f", fp[2], fu[2], fe[2]); cpl_msg_error(cpl_func, "Obtained value for %s = %f +- %f", fp[2], - major, sqrt(cpl_matrix_get(phys_cov, 2, 2))); + major, sqrt(cpl_matrix_get(phys_cov, 2, 2))); } cpl_matrix_delete(matrix); @@ -1516,46 +1521,46 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_fit_image_gaussian_test_one(void) +static void +cpl_fit_image_gaussian_test_one(void) { - double rms = 0.0; - double redchi = 0.0; - cpl_image * image; - cpl_image * imerr; - cpl_array * params; - cpl_array * paramserr; + double rms = 0.0; + double redchi = 0.0; + cpl_image *image; + cpl_image *imerr; + cpl_array *params; + cpl_array *paramserr; cpl_error_code error; params = cpl_array_new(7, CPL_TYPE_DOUBLE); paramserr = cpl_array_new(7, CPL_TYPE_DOUBLE); image = cpl_image_new(IMAGESZFIT, IMAGESZFIT, CPL_TYPE_DOUBLE); - error = cpl_image_fill_gaussian(image, IMAGESZFIT/2, IMAGESZFIT/2, - 20.0, 20.0, 20.0); + error = cpl_image_fill_gaussian(image, IMAGESZFIT / 2, IMAGESZFIT / 2, 20.0, + 20.0, 20.0); cpl_test_eq_error(error, CPL_ERROR_NONE); imerr = cpl_image_new(IMAGESZFIT, IMAGESZFIT, CPL_TYPE_DOUBLE); - error = cpl_image_fill_noise_uniform(imerr,1.0,1.00001); + error = cpl_image_fill_noise_uniform(imerr, 1.0, 1.00001); cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_fit_image_gaussian(image, imerr, IMAGESZFIT/2, IMAGESZFIT/2, - IMAGESZFIT/5, IMAGESZFIT/5, - params, paramserr, NULL, &rms, NULL, - NULL, NULL, NULL, NULL, NULL); + error = cpl_fit_image_gaussian(image, imerr, IMAGESZFIT / 2, IMAGESZFIT / 2, + IMAGESZFIT / 5, IMAGESZFIT / 5, params, + paramserr, NULL, &rms, NULL, NULL, NULL, + NULL, NULL, NULL); cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_fit_image_gaussian(image, imerr, IMAGESZFIT/2, IMAGESZFIT/2, - IMAGESZFIT/5, IMAGESZFIT/5, - params, paramserr, NULL, &rms, &redchi, - NULL, NULL, NULL, NULL, NULL); + error = cpl_fit_image_gaussian(image, imerr, IMAGESZFIT / 2, IMAGESZFIT / 2, + IMAGESZFIT / 5, IMAGESZFIT / 5, params, + paramserr, NULL, &rms, &redchi, NULL, NULL, + NULL, NULL, NULL); cpl_test_eq_error(error, CPL_ERROR_NONE); cpl_image_delete(image); cpl_image_delete(imerr); cpl_array_delete(params); cpl_array_delete(paramserr); - } @@ -1567,48 +1572,52 @@ */ /*----------------------------------------------------------------------------*/ -static -cpl_imagelist * -cpl_fit_imagelist_polynomial_window_test(const cpl_vector * x_pos, - const cpl_imagelist * values, - int llx, - int lly, - int urx, - int ury, - int mindeg, - int maxdeg, - cpl_boolean is_symsamp, - cpl_type pixeltype, - cpl_image * fiterror) +static cpl_imagelist * +cpl_fit_imagelist_polynomial_window_test(const cpl_vector *x_pos, + const cpl_imagelist *values, + int llx, + int lly, + int urx, + int ury, + int mindeg, + int maxdeg, + cpl_boolean is_symsamp, + cpl_type pixeltype, + cpl_image *fiterror) { - - cpl_imagelist * self = + cpl_imagelist *self = cpl_fit_imagelist_polynomial_window(x_pos, values, llx, lly, urx, ury, mindeg, maxdeg, is_symsamp, pixeltype, fiterror); if (self != NULL) { const cpl_size np = cpl_vector_get_size(x_pos); - cpl_imagelist * icopy = cpl_imagelist_duplicate(values); - cpl_vector * vcopy = cpl_vector_new(np + 1); - cpl_image * bad = cpl_image_duplicate(cpl_imagelist_get_const(icopy, 0)); + cpl_imagelist *icopy = cpl_imagelist_duplicate(values); + cpl_vector *vcopy = cpl_vector_new(np + 1); + cpl_image *bad = cpl_image_duplicate(cpl_imagelist_get_const(icopy, 0)); const cpl_size mx = cpl_image_get_size_x(bad); const cpl_size my = cpl_image_get_size_y(bad); - cpl_mask * mask = cpl_mask_new(mx, my); - cpl_imagelist * fitbad; - cpl_image * baderror = fiterror ? cpl_image_duplicate(fiterror) : NULL; - const double tol = pixeltype == CPL_TYPE_INT ? 0.0 - : (pixeltype == CPL_TYPE_FLOAT + cpl_mask *mask = cpl_mask_new(mx, my); + cpl_imagelist *fitbad; + cpl_image *baderror = fiterror ? cpl_image_duplicate(fiterror) : NULL; + const double tol = + pixeltype == CPL_TYPE_INT + ? 0.0 + : (pixeltype == CPL_TYPE_FLOAT #if defined SIZEOF_SIZE_T && SIZEOF_SIZE_T == 4 - /* FIXME: Extreme loss of precision on (some) 32-bit machines */ - ? 0.004 : 30.0 * FLT_EPSILON + /* FIXME: Extreme loss of precision on (some) 32-bit machines */ + ? 0.004 + : 30.0 * FLT_EPSILON #else - ? FLT_EPSILON : 800.0 * DBL_EPSILON + ? FLT_EPSILON + : 800.0 * DBL_EPSILON #endif - ); + ); cpl_error_code error; - cpl_msg_info(cpl_func, "Testing with %" CPL_SIZE_FORMAT " X %" - CPL_SIZE_FORMAT " bad pixels", mx, my); + cpl_msg_info(cpl_func, + "Testing with %" CPL_SIZE_FORMAT " X %" CPL_SIZE_FORMAT + " bad pixels", + mx, my); cpl_test_eq_ptr(memcpy(cpl_vector_get_data(vcopy), cpl_vector_get_data_const(x_pos), @@ -1633,10 +1642,10 @@ cpl_test_eq(cpl_imagelist_get_size(icopy), np + 1); cpl_test_eq(cpl_vector_get_size(vcopy), np + 1); - fitbad = cpl_fit_imagelist_polynomial_window(vcopy, icopy, llx, lly, - urx, ury, mindeg, maxdeg, - is_symsamp, pixeltype, - baderror); + fitbad = + cpl_fit_imagelist_polynomial_window(vcopy, icopy, llx, lly, urx, + ury, mindeg, maxdeg, is_symsamp, + pixeltype, baderror); cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(fitbad); cpl_test_imagelist_abs(self, fitbad, tol); @@ -1649,7 +1658,6 @@ cpl_image_delete(baderror); cpl_vector_delete(vcopy); cpl_mask_delete(mask); - } return self; @@ -1664,23 +1672,21 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_fit_imagelist_polynomial_bpm(void) +static void +cpl_fit_imagelist_polynomial_bpm(void) { - - - const double ditval[] = {0.0, 1.0, 2.0, 3.0, 4.0, - 5.0, 6.0, 7.0, 8.0}; - const int ndits = (int)(sizeof(ditval)/sizeof(double)); + const double ditval[] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; + const int ndits = (int)(sizeof(ditval) / sizeof(double)); CPL_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual) - cpl_vector * vdit = cpl_vector_wrap(ndits, (double*)ditval); + cpl_vector *vdit = cpl_vector_wrap(ndits, (double *)ditval); CPL_DIAG_PRAGMA_POP const int mx = 2; /* Two pixels: one all good, one mixed */ const int my = 1; - cpl_image * dfiterror = cpl_image_new(mx, my, CPL_TYPE_DOUBLE); - cpl_imagelist * imlist = cpl_imagelist_new(); - cpl_imagelist * fit; + cpl_image *dfiterror = cpl_image_new(mx, my, CPL_TYPE_DOUBLE); + cpl_imagelist *imlist = cpl_imagelist_new(); + cpl_imagelist *fit; int is_bad = 0; int i; @@ -1688,8 +1694,8 @@ /* Test 1: A perfectly linear fit */ for (i = 0; i < ndits; i++) { - const double value = ditval[i]; - cpl_image * bad = cpl_image_new(mx, my, CPL_TYPE_DOUBLE); + const double value = ditval[i]; + cpl_image *bad = cpl_image_new(mx, my, CPL_TYPE_DOUBLE); cpl_image_set(bad, 1, 1, value); cpl_image_set(bad, 2, 1, value); cpl_imagelist_set(imlist, bad, i); @@ -1704,11 +1710,11 @@ cpl_test_error(CPL_ERROR_NONE); cpl_test_eq(cpl_imagelist_get_size(fit), 2); - cpl_test_abs(cpl_image_get(cpl_imagelist_get(fit, 0), 1, 1, &is_bad), - 0.0, 4.0 * DBL_EPSILON); + cpl_test_abs(cpl_image_get(cpl_imagelist_get(fit, 0), 1, 1, &is_bad), 0.0, + 4.0 * DBL_EPSILON); cpl_test_zero(is_bad); - cpl_test_rel(cpl_image_get(cpl_imagelist_get(fit, 1), 1, 1, &is_bad), - 1.0, 2.0 * DBL_EPSILON); + cpl_test_rel(cpl_image_get(cpl_imagelist_get(fit, 1), 1, 1, &is_bad), 1.0, + 2.0 * DBL_EPSILON); cpl_test_zero(is_bad); cpl_test_abs(cpl_image_get(dfiterror, 1, 1, &is_bad), 0.0, DBL_EPSILON); @@ -1719,7 +1725,7 @@ for (i = 0; i < ndits; i++) { const double value = ditval[i] * ditval[i]; - cpl_image * bad = cpl_imagelist_get(imlist, i); + cpl_image *bad = cpl_imagelist_get(imlist, i); cpl_image_set(bad, 1, 1, value); cpl_image_set(bad, 2, 1, value); if (i & 1) { @@ -1734,14 +1740,14 @@ cpl_test_error(CPL_ERROR_NONE); cpl_test_eq(cpl_imagelist_get_size(fit), 3); - cpl_test_abs(cpl_image_get(cpl_imagelist_get(fit, 0), 1, 1, &is_bad), - 0.0, 12.0 * DBL_EPSILON); + cpl_test_abs(cpl_image_get(cpl_imagelist_get(fit, 0), 1, 1, &is_bad), 0.0, + 12.0 * DBL_EPSILON); cpl_test_zero(is_bad); - cpl_test_abs(cpl_image_get(cpl_imagelist_get(fit, 1), 1, 1, &is_bad), - 0.0, 24.0 * DBL_EPSILON); + cpl_test_abs(cpl_image_get(cpl_imagelist_get(fit, 1), 1, 1, &is_bad), 0.0, + 24.0 * DBL_EPSILON); cpl_test_zero(is_bad); - cpl_test_rel(cpl_image_get(cpl_imagelist_get(fit, 2), 1, 1, &is_bad), - 1.0, 2.0 * DBL_EPSILON); + cpl_test_rel(cpl_image_get(cpl_imagelist_get(fit, 2), 1, 1, &is_bad), 1.0, + 2.0 * DBL_EPSILON); cpl_test_zero(is_bad); cpl_test_abs(cpl_image_get(dfiterror, 1, 1, &is_bad), 0.0, DBL_EPSILON); @@ -1751,7 +1757,7 @@ for (i = 0; i < ndits; i++) { const double value = ditval[i] * ditval[i]; - cpl_image * bad = cpl_imagelist_get(imlist, i); + cpl_image *bad = cpl_imagelist_get(imlist, i); cpl_image_set(bad, 1, 1, value); cpl_image_set(bad, 2, 1, value); if (i & 1) { @@ -1766,8 +1772,8 @@ cpl_test_error(CPL_ERROR_NONE); cpl_test_eq(cpl_imagelist_get_size(fit), 1); - cpl_test_rel(cpl_image_get(cpl_imagelist_get(fit, 0), 1, 1, &is_bad), - 1.0, 2.0 * DBL_EPSILON); + cpl_test_rel(cpl_image_get(cpl_imagelist_get(fit, 0), 1, 1, &is_bad), 1.0, + 2.0 * DBL_EPSILON); cpl_test_zero(is_bad); cpl_test_abs(cpl_image_get(dfiterror, 1, 1, &is_bad), 0.0, DBL_EPSILON); @@ -1788,28 +1794,39 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_fit_image_gaussian_test_bpm(void) +static void +cpl_fit_image_gaussian_test_bpm(void) { - cpl_array * params = cpl_array_new(7, CPL_TYPE_DOUBLE); - const double values[IM13 * IM13] - = {856.781, 832.831, 876.031, 894.781, 1015.83, 1160.33, 1276.03, 1295.73, 1274.58, 1173.18, 1042.88, 970.481, 912.681, - 894.575, 919.775, 925.975, 984.075, 1109.33, 1233.38, 1291.92, 1312.77, 1198.62, 1120.77, 1038.83, 1016.58, 975.075, - 980.519, 980.419, 999.319, 1021.72, 1255.82, 1536.47, 1735.57, 1686.22, 1493.17, 1196.32, 1071.27, 1110.17, 1076.17, - 1076.92, 1076.47, 1052.22, 1192.12, 1647.82, 2262.62, 2979.22, 3011.62, 2484.32, 1769.47, 1389.27, 1211.72, 1159.97, - 1164.42, 1188.47, 1198.07, 1537.72, 2522.32, 4171.52, 5487.42, 5950.92, 4712.87, 3176.17, 1998.07, 1494.47, 1321.77, - 1320.96, 1352.11, 1480.96, 2152.26, 3932.41, 6727.36, 9276.11, 9706.51, 7825.66, 5090.06, 2894.41, 1878.91, 1498.41, - 1411.61, 1496.16, 1751.36, 2709.61, 5201.41, 8742.31, 12128.6, 12650.6, -4.0375, 6567.81, 3663.51, 2145.31, 1623.26, - 1411.12, 1544.52, 1822.82, 2780.97, 5355.67, 8861.92, 12061, 12846.3, 10185.7, 6598.87, 3677.82, 2073.72, 1517.12, - 1377.82, 1478.97, 1764.62, 2456.02, 4256.12, 7063.37, 9463.02, 9937.97, 8086.52, 4928.32, 2861.67, 1698.72, 1353.57, - 1219.54, 1313.94, 1447.39, 1844.84, 2740.39, 4471.04, 5562.24, 6004.69, 4866.64, 3301.69, 1990.74, 1307.34, 1171.99, - 1057.14, 1130.09, 1146.79, 1242.09, 1617.19, 2364.34, 2982.64, 3218.14, 2812.74, 2019.04, 1492.14, 1201.34, 1051.94, - 910.269, 929.319, 988.369, 1011.37, 1107.87, 1442.02, 1782.92, 1927.97, 1893.52, 1681.77, 1432.52, 1192.67, 1014.22, - 889.488, 846.738, 876.587, 917.688, 802.588, 1168.19, 1421.54, 1701.69, 1707.54, 1562.19, 1312.04, 1156.39, 999.287}; + cpl_array *params = cpl_array_new(7, CPL_TYPE_DOUBLE); + const double values[IM13 * IM13] = { + 856.781, 832.831, 876.031, 894.781, 1015.83, 1160.33, 1276.03, 1295.73, + 1274.58, 1173.18, 1042.88, 970.481, 912.681, 894.575, 919.775, 925.975, + 984.075, 1109.33, 1233.38, 1291.92, 1312.77, 1198.62, 1120.77, 1038.83, + 1016.58, 975.075, 980.519, 980.419, 999.319, 1021.72, 1255.82, 1536.47, + 1735.57, 1686.22, 1493.17, 1196.32, 1071.27, 1110.17, 1076.17, 1076.92, + 1076.47, 1052.22, 1192.12, 1647.82, 2262.62, 2979.22, 3011.62, 2484.32, + 1769.47, 1389.27, 1211.72, 1159.97, 1164.42, 1188.47, 1198.07, 1537.72, + 2522.32, 4171.52, 5487.42, 5950.92, 4712.87, 3176.17, 1998.07, 1494.47, + 1321.77, 1320.96, 1352.11, 1480.96, 2152.26, 3932.41, 6727.36, 9276.11, + 9706.51, 7825.66, 5090.06, 2894.41, 1878.91, 1498.41, 1411.61, 1496.16, + 1751.36, 2709.61, 5201.41, 8742.31, 12128.6, 12650.6, -4.0375, 6567.81, + 3663.51, 2145.31, 1623.26, 1411.12, 1544.52, 1822.82, 2780.97, 5355.67, + 8861.92, 12061, 12846.3, 10185.7, 6598.87, 3677.82, 2073.72, 1517.12, + 1377.82, 1478.97, 1764.62, 2456.02, 4256.12, 7063.37, 9463.02, 9937.97, + 8086.52, 4928.32, 2861.67, 1698.72, 1353.57, 1219.54, 1313.94, 1447.39, + 1844.84, 2740.39, 4471.04, 5562.24, 6004.69, 4866.64, 3301.69, 1990.74, + 1307.34, 1171.99, 1057.14, 1130.09, 1146.79, 1242.09, 1617.19, 2364.34, + 2982.64, 3218.14, 2812.74, 2019.04, 1492.14, 1201.34, 1051.94, 910.269, + 929.319, 988.369, 1011.37, 1107.87, 1442.02, 1782.92, 1927.97, 1893.52, + 1681.77, 1432.52, 1192.67, 1014.22, 889.488, 846.738, 876.587, 917.688, + 802.588, 1168.19, 1421.54, 1701.69, 1707.54, 1562.19, 1312.04, 1156.39, + 999.287 + }; const size_t image_bytes = IM13 * IM13 * sizeof(double); - double * image_data = (double*)cpl_malloc(image_bytes); - cpl_image * image = cpl_image_wrap_double(IM13, IM13, image_data); - cpl_image * errim; + double *image_data = (double *)cpl_malloc(image_bytes); + cpl_image *image = cpl_image_wrap_double(IM13, IM13, image_data); + cpl_image *errim; const double xfrac = 0.115; const double yfrac = 0.511; @@ -1826,10 +1843,10 @@ cpl_array_set(params, 4, 1.0 + (IM13 - 1) * 0.5 + yfrac); for (int idoerrim = 0; idoerrim < 2; idoerrim++) { - const cpl_image * use_errim = idoerrim ? errim : NULL; + const cpl_image *use_errim = idoerrim ? errim : NULL; - cpl_msg_info(cpl_func, idoerrim ? "Testing with error image" : - "Testing without error image"); + cpl_msg_info(cpl_func, idoerrim ? "Testing with error image" + : "Testing without error image"); for (int idobpm = 0; idobpm < 2; idobpm++) { double rms0, major0, minor0, angle0; @@ -1837,14 +1854,14 @@ double drms = 0.0, dmajor = 0.0, dminor = 0.0, dangle = 0.0; cpl_error_code code; - cpl_msg_info(cpl_func, idobpm ? "Testing with bpm" : - "Testing without bpm"); + cpl_msg_info(cpl_func, + idobpm ? "Testing with bpm" : "Testing without bpm"); if (idobpm) { cpl_size nbad; - cpl_mask * nullmask; - cpl_mask * bpm = cpl_mask_threshold_image_create(image, - -FLT_MAX, 0.0); + cpl_mask *nullmask; + cpl_mask *bpm = + cpl_mask_threshold_image_create(image, -FLT_MAX, 0.0); cpl_test_error(CPL_ERROR_NONE); @@ -1859,21 +1876,22 @@ } for (int iretry = 0; iretry < 2; iretry++) { - cpl_matrix * phys_cov = NULL; - cpl_matrix **pphys_cov = use_errim ? &phys_cov : NULL; + cpl_matrix *phys_cov = NULL; + cpl_matrix **pphys_cov = use_errim ? &phys_cov : NULL; - cpl_msg_info(cpl_func, iretry ? "Testing with first guess" : - "Testing without first guess"); + cpl_msg_info(cpl_func, iretry ? "Testing with first guess" + : "Testing without first guess"); rms0 = rms1; major0 = major1; minor0 = minor1; angle0 = angle1; - code = cpl_fit_image_gaussian(image, use_errim, IM13/2, IM13/2, - IM13, IM13, params, NULL, NULL, - &rms1, NULL, NULL, &major1, - &minor1, &angle1, pphys_cov); + code = + cpl_fit_image_gaussian(image, use_errim, IM13 / 2, IM13 / 2, + IM13, IM13, params, NULL, NULL, + &rms1, NULL, NULL, &major1, &minor1, + &angle1, pphys_cov); if (code == CPL_ERROR_SINGULAR_MATRIX) { cpl_test(idoerrim); @@ -1886,44 +1904,46 @@ cpl_array_set(params, 3, 1.0 + (IM13 - 1) * 0.5 + xfrac); cpl_array_set(params, 4, 1.0 + (IM13 - 1) * 0.5 + yfrac); - code = cpl_fit_image_gaussian(image, use_errim, IM13/2, - IM13/2, IM13, IM13, params, - NULL, NULL, &rms1, NULL, NULL, - &major1, &minor1, &angle1, - NULL); + code = + cpl_fit_image_gaussian(image, use_errim, IM13 / 2, + IM13 / 2, IM13, IM13, params, + NULL, NULL, &rms1, NULL, NULL, + &major1, &minor1, &angle1, NULL); cpl_test_eq_error(code, CPL_ERROR_NONE); - } else if (idoerrim) { + } + else if (idoerrim) { cpl_test_eq_error(code, CPL_ERROR_NONE); cpl_test_nonnull(phys_cov); cpl_matrix_delete(phys_cov); - } else { + } + else { cpl_test_eq_error(code, CPL_ERROR_NONE); cpl_test_null(phys_cov); - code = cpl_fit_image_gaussian(image, NULL, IM13/2, IM13/2, - IM13, IM13, params, NULL, - NULL, &rms1, NULL, NULL, - &major1, &minor1, &angle1, - &phys_cov); + code = + cpl_fit_image_gaussian(image, NULL, IM13 / 2, IM13 / 2, + IM13, IM13, params, NULL, NULL, + &rms1, NULL, NULL, &major1, + &minor1, &angle1, &phys_cov); cpl_test_eq_error(code, CPL_ERROR_DATA_NOT_FOUND); } } - cpl_msg_info(cpl_func, CPL_STRINGIFY(IM13) " X " CPL_STRINGIFY(IM13) - " double-image: Major: %g - %g = %g. Minor: %g - %g " - "= %g. Angle: %g - %g = %g. RMS=%g - %g = %g", - major1, major0, major1 - major0, - minor1, minor0, minor1 - minor0, - angle1, angle0, angle1 - angle0, - rms1, rms0, rms1 - rms0); + cpl_msg_info( + cpl_func, + CPL_STRINGIFY(IM13) " X " CPL_STRINGIFY(IM13) " double-image: Major: %g - %g = %g. Minor: %g - %g " + "= %g. Angle: %g - %g = %g. RMS=%g - %g = %g", + major1, major0, major1 - major0, minor1, minor0, + minor1 - minor0, angle1, angle0, angle1 - angle0, rms1, + rms0, rms1 - rms0); if (idobpm) { /* With bpm, the change is less or equal. FIXME: Why ? */ cpl_test_leq(fabs(dmajor), fabs(major1 - major0)); cpl_test_leq(fabs(dminor), fabs(minor1 - minor0)); cpl_test_leq(fabs(dangle), fabs(angle1 - angle0)); - cpl_test_leq(fabs(drms), fabs(rms1 - rms0)); + cpl_test_leq(fabs(drms), fabs(rms1 - rms0)); } code = cpl_image_accept_all(image); @@ -1932,7 +1952,7 @@ dmajor = major1 - major0; dminor = minor1 - minor0; dangle = angle1 - angle0; - drms = rms1 - rms0; + drms = rms1 - rms0; } } @@ -1950,56 +1970,57 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_fit_image_gaussian_test_local(void) +static void +cpl_fit_image_gaussian_test_local(void) { + cpl_array *params = cpl_array_new(7, CPL_TYPE_DOUBLE); - cpl_array * params = cpl_array_new(7, CPL_TYPE_DOUBLE); - - const int values[][IMSZ * IMSZ] - = {{111, 477, 1596, 1263, 194, 64, 255, 970, 3210, 2640, 469, 141, 1565, - 8840, 30095, 17625, 2381, 656, 4982, 33104, 65535, 63588, 7276, - 2377, 1822, 12167, 37548, 20715, 2597, 856, 353, 1440, 4042, 3121, - 535, 135}, - {408, 880, 1043, 719, 249, 93, 1512, 2730, 2253, 1159, 470, 212, - 11366, 22069, 18434, 7102, 1898, 789, 15630, 52992, 65535, 43330, - 11619, 2834, 3422, 13283, 31354, 32311, 13946, 3225, 616, 1717, - 3143, 3298, 2029, 662}, - {161, 587, 1618, 1487, 409, 103, 475, 1681, 4511, 4295, 1302, 308, - 2009, 10686, 40660, 42502, 10990, 1559, 4526, 26557, 65535, 65535, - 16232, 2942, 1136, 6054, 17506, 13985, 3569, 697, 249, 1057, 2944, - 2536, 633, 115}, - {684, 1620, 2240, 2021, 1041, 346, 3549, 8272, 11679, 9524, 4789, - 1661, 18252, 45616, 65535, 57247, 28755, 9689, 7025, 17892, 26878, - 23738, 12277, 4084, 905, 2057, 3227, 2941, 1546, 586, 275, 651, 998, - 978, 581, 218}, - {419, 964, 1470, 1165, 428, 118, 2547, 7622, 7975, 3391, 979, 335, - 5931, 29549, 51281, 22243, 3797, 1143, 4522, 21513, 65535, 62954, - 13954, 2253, 1293, 4305, 15660, 26446, 12002, 1870, 243, 849, 2525, - 3565, 2228, 491}, - {207, 747, 2302, 3383, 2176, 762, 867, 2512, 10026, 22327, 16365, - 3663, 2689, 11998, 55855, 65535, 27336, 4542, 3587, 20606, 52265, - 33975, 7420, 1594, 1275, 5343, 7709, 4121, 1060, 319, 210, 744, - 1303, 1024, 391, 87} + const int values[][IMSZ * IMSZ] = { + { 111, 477, 1596, 1263, 194, 64, 255, 970, 3210, + 2640, 469, 141, 1565, 8840, 30095, 17625, 2381, 656, + 4982, 33104, 65535, 63588, 7276, 2377, 1822, 12167, 37548, + 20715, 2597, 856, 353, 1440, 4042, 3121, 535, 135 }, + { 408, 880, 1043, 719, 249, 93, 1512, 2730, 2253, + 1159, 470, 212, 11366, 22069, 18434, 7102, 1898, 789, + 15630, 52992, 65535, 43330, 11619, 2834, 3422, 13283, 31354, + 32311, 13946, 3225, 616, 1717, 3143, 3298, 2029, 662 }, + { 161, 587, 1618, 1487, 409, 103, 475, 1681, 4511, + 4295, 1302, 308, 2009, 10686, 40660, 42502, 10990, 1559, + 4526, 26557, 65535, 65535, 16232, 2942, 1136, 6054, 17506, + 13985, 3569, 697, 249, 1057, 2944, 2536, 633, 115 }, + { 684, 1620, 2240, 2021, 1041, 346, 3549, 8272, 11679, + 9524, 4789, 1661, 18252, 45616, 65535, 57247, 28755, 9689, + 7025, 17892, 26878, 23738, 12277, 4084, 905, 2057, 3227, + 2941, 1546, 586, 275, 651, 998, 978, 581, 218 }, + { 419, 964, 1470, 1165, 428, 118, 2547, 7622, 7975, + 3391, 979, 335, 5931, 29549, 51281, 22243, 3797, 1143, + 4522, 21513, 65535, 62954, 13954, 2253, 1293, 4305, 15660, + 26446, 12002, 1870, 243, 849, 2525, 3565, 2228, 491 }, + { 207, 747, 2302, 3383, 2176, 762, 867, 2512, 10026, + 22327, 16365, 3663, 2689, 11998, 55855, 65535, 27336, 4542, + 3587, 20606, 52265, 33975, 7420, 1594, 1275, 5343, 7709, + 4121, 1060, 319, 210, 744, 1303, 1024, 391, 87 } }; - const double major[] = {5.80423, 1.25846, 0.9219, 1.35805, 1.08065, - 1.09118}; - const double minor[] = {2.82963, 0.661684, 0.714119, 0.601602, 0.661207, - 0.679018}; - const double angle[] = {0.865826, 0.318316, -0.13699, 0.0127396, 0.613033, - -0.556366}; + const double major[] = { + 5.80423, 1.25846, 0.9219, 1.35805, 1.08065, 1.09118 + }; + const double minor[] = { 2.82963, 0.661684, 0.714119, + 0.601602, 0.661207, 0.679018 }; + const double angle[] = { 0.865826, 0.318316, -0.13699, + 0.0127396, 0.613033, -0.556366 }; - const size_t n = sizeof(values)/sizeof(values[0]); + const size_t n = sizeof(values) / sizeof(values[0]); const size_t image_bytes = IMSZ * IMSZ * sizeof(int); - int * image_data = (int*)cpl_malloc(image_bytes); - cpl_image * image = cpl_image_wrap_int(IMSZ, IMSZ, image_data); + int *image_data = (int *)cpl_malloc(image_bytes); + cpl_image *image = cpl_image_wrap_int(IMSZ, IMSZ, image_data); cpl_test_nonnull(image); - cpl_test_assert(sizeof(major)/sizeof(major[0]) == n); - cpl_test_assert(sizeof(minor)/sizeof(minor[0]) == n); - cpl_test_assert(sizeof(angle)/sizeof(angle[0]) == n); + cpl_test_assert(sizeof(major) / sizeof(major[0]) == n); + cpl_test_assert(sizeof(minor) / sizeof(minor[0]) == n); + cpl_test_assert(sizeof(angle) / sizeof(angle[0]) == n); for (size_t i = 0; i < n; i++) { const double tol = 1e-5; @@ -2013,42 +2034,43 @@ error = cpl_array_fill_window_invalid(params, 1, 7); cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_fit_image_gaussian(image, NULL, nx/2, ny/2, nx, ny, + error = cpl_fit_image_gaussian(image, NULL, nx / 2, ny / 2, nx, ny, params, NULL, NULL, &rms, NULL, NULL, &mymajor, &myminor, &myangle, NULL); cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_msg_info(cpl_func, CPL_STRINGIFY(IMSZ) " X " CPL_STRINGIFY(IMSZ) - " int-image %d/%d: Major: %g - %g = %g. Minor: %g - %g " - "= %g. Angle: %g - %g = %g. RMS=%g", (int)i + 1, (int)n, - mymajor, major[i], mymajor - major[i], - myminor, minor[i], myminor - minor[i], - myangle, angle[i], myangle - angle[i], rms); + cpl_msg_info( + cpl_func, + CPL_STRINGIFY(IMSZ) " X " CPL_STRINGIFY(IMSZ) " int-image %d/%d: Major: %g - %g = %g. Minor: %g - %g " + "= %g. Angle: %g - %g = %g. RMS=%g", + (int)i + 1, (int)n, mymajor, major[i], mymajor - major[i], + myminor, minor[i], myminor - minor[i], myangle, angle[i], + myangle - angle[i], rms); cpl_test_abs(mymajor, major[i], tol); cpl_test_abs(myminor, minor[i], tol); cpl_test_abs(myangle, angle[i], tol); - if (i == 0) continue; /* Converges to a non-global minimum... */ + if (i == 0) + continue; /* Converges to a non-global minimum... */ /* Re-try with the solution as 1st guess */ - error = cpl_fit_image_gaussian(image, NULL, nx/2, ny/2, nx, ny, + error = cpl_fit_image_gaussian(image, NULL, nx / 2, ny / 2, nx, ny, params, NULL, NULL, &rms, NULL, NULL, &mymajor, &myminor, &myangle, NULL); cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_msg_info(cpl_func, CPL_STRINGIFY(IMSZ) " X " CPL_STRINGIFY(IMSZ) - " int-image %d/%d: Major: %g - %g = %g. Minor: %g - %g " - "= %g. Angle: %g - %g = %g. RMS=%g (retry)", - (int)i + 1, (int)n, - mymajor, major[i], mymajor - major[i], - myminor, minor[i], myminor - minor[i], - myangle, angle[i], myangle - angle[i], rms); + cpl_msg_info( + cpl_func, + CPL_STRINGIFY(IMSZ) " X " CPL_STRINGIFY(IMSZ) " int-image %d/%d: Major: %g - %g = %g. Minor: %g - %g " + "= %g. Angle: %g - %g = %g. RMS=%g (retry)", + (int)i + 1, (int)n, mymajor, major[i], mymajor - major[i], + myminor, minor[i], myminor - minor[i], myangle, angle[i], + myangle - angle[i], rms); cpl_test_abs(mymajor, major[i], tol); cpl_test_abs(myminor, minor[i], tol); cpl_test_abs(myangle, angle[i], tol); - } cpl_array_delete(params); diff -Nru cpl-7.1.4+ds/cpldrs/tests/cpl_geom_img-test.c cpl-7.2.2+ds/cpldrs/tests/cpl_geom_img-test.c --- cpl-7.1.4+ds/cpldrs/tests/cpl_geom_img-test.c 2021-05-07 12:09:09.000000000 +0000 +++ cpl-7.2.2+ds/cpldrs/tests/cpl_geom_img-test.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -45,12 +45,12 @@ -----------------------------------------------------------------------------*/ #ifndef IMAGESZ -#define IMAGESZ 256 +#define IMAGESZ 256 #endif -#define NFRAMES 10 -#define NSIGMAS 4 -#define MAX_SHIFT_ERROR1 15 -#define MAX_SHIFT_ERROR2 0.1 +#define NFRAMES 10 +#define NSIGMAS 4 +#define MAX_SHIFT_ERROR1 15 +#define MAX_SHIFT_ERROR2 0.1 /*----------------------------------------------------------------------------- Pricate functions @@ -58,46 +58,49 @@ static void cpl_geom_img_offset_saa_one(cpl_kernel); -static -void cpl_geom_img_offset_saa_bench(cpl_geom_combine, int, int, int, int, int); +static void +cpl_geom_img_offset_saa_bench(cpl_geom_combine, int, int, int, int, int); -static void cpl_imagelist_fill_shifted(cpl_imagelist *, cpl_size, - const double *, const double *); +static void cpl_imagelist_fill_shifted(cpl_imagelist *, + cpl_size, + const double *, + const double *); /**@{*/ /*----------------------------------------------------------------------------- Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { /* These kernels preserve the actual pixel-values */ - cpl_kernel kernels[] = {CPL_KERNEL_DEFAULT, - CPL_KERNEL_NEAREST}; - const cpl_geom_combine geoms[] = {CPL_GEOM_INTERSECT, CPL_GEOM_UNION, - CPL_GEOM_FIRST}; + cpl_kernel kernels[] = { CPL_KERNEL_DEFAULT, CPL_KERNEL_NEAREST }; + const cpl_geom_combine geoms[] = { CPL_GEOM_INTERSECT, CPL_GEOM_UNION, + CPL_GEOM_FIRST }; /* Shift by non-integer amount to evaluate resampling */ - const double off_x_init[] = { 0.0, -6.5, -18.5, 54.5, 33.5, - 46.5, -3.5, 36.5, 42.5, -13.5}; - const double off_y_init[] = { 0.0, 13.5, 3.5, 8.5, 32.5, - 22.5, 18.5, -56.5, 3.5, 10.5}; - cpl_imagelist * iset; - cpl_image * img; - cpl_bivector * offs_est; - cpl_vector * off_vec_x; - cpl_vector * off_vec_y; - cpl_bivector * offs_ref; - cpl_apertures * aperts; - int naperts; - cpl_bivector * aperts_pos; - cpl_vector * aperts_pos_x; - cpl_vector * aperts_pos_y; - cpl_vector * correl; - const double psigmas[] = {5, 2, 1, 0.5}; - cpl_vector * sigmas; - cpl_image ** combined; - int i; - cpl_size pos; + const double off_x_init[] = { 0.0, -6.5, -18.5, 54.5, 33.5, + 46.5, -3.5, 36.5, 42.5, -13.5 }; + const double off_y_init[] = { 0.0, 13.5, 3.5, 8.5, 32.5, + 22.5, 18.5, -56.5, 3.5, 10.5 }; + cpl_imagelist *iset; + cpl_image *img; + cpl_bivector *offs_est; + cpl_vector *off_vec_x; + cpl_vector *off_vec_y; + cpl_bivector *offs_ref; + cpl_apertures *aperts; + int naperts; + cpl_bivector *aperts_pos; + cpl_vector *aperts_pos_x; + cpl_vector *aperts_pos_y; + cpl_vector *correl; + const double psigmas[] = { 5, 2, 1, 0.5 }; + cpl_vector *sigmas; + cpl_image **combined; + int i; + cpl_size pos; + cpl_error_code code; cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); @@ -105,7 +108,7 @@ /* Verify the test data */ cpl_test_eq(sizeof(off_x_init), NFRAMES * sizeof(off_x_init[0])); cpl_test_eq(sizeof(off_y_init), sizeof(off_x_init)); - cpl_test_eq(sizeof(psigmas), NSIGMAS * sizeof(psigmas[0])); + cpl_test_eq(sizeof(psigmas), NSIGMAS * sizeof(psigmas[0])); for (i = 0; i < NFRAMES; i++) { cpl_test_leq(fabs(off_x_init[i]), IMAGESZ); cpl_test_leq(fabs(off_y_init[i]), IMAGESZ); @@ -121,18 +124,18 @@ cpl_flops fpost, nflops; #ifndef _OPENMP - cpl_geom_img_offset_saa_bench(CPL_GEOM_FIRST, 10, 16, 4*IMAGESZ, - 4*IMAGESZ, 0); - cpl_geom_img_offset_saa_bench(CPL_GEOM_FIRST, 6, 18, 4*IMAGESZ, - 4*IMAGESZ, 1); + cpl_geom_img_offset_saa_bench(CPL_GEOM_FIRST, 10, 16, 4 * IMAGESZ, + 4 * IMAGESZ, 0); + cpl_geom_img_offset_saa_bench(CPL_GEOM_FIRST, 6, 18, 4 * IMAGESZ, + 4 * IMAGESZ, 1); #endif #ifdef _OPENMP #pragma omp parallel for private(i) #endif - for (i=0; i < 8; i++) { - cpl_geom_img_offset_saa_bench(CPL_GEOM_FIRST, 6, 18, 4*IMAGESZ, - 4*IMAGESZ, 1); + for (i = 0; i < 8; i++) { + cpl_geom_img_offset_saa_bench(CPL_GEOM_FIRST, 6, 18, 4 * IMAGESZ, + 4 * IMAGESZ, 1); } tpost = cpl_test_get_cputime(); @@ -141,11 +144,11 @@ nflops = fpost - fprev; cpl_msg_info(cpl_func, "Time to benchmark [s]: %g (%g MFLOP/s)", cputime, - cputime > 0.0 ? (double)nflops/cputime/1e6 : 0.0); - - } else { - cpl_geom_img_offset_saa_bench(CPL_GEOM_FIRST, 1, 4, IMAGESZ/4, - IMAGESZ/4, 1); + cputime > 0.0 ? (double)nflops / cputime / 1e6 : 0.0); + } + else { + cpl_geom_img_offset_saa_bench(CPL_GEOM_FIRST, 1, 4, IMAGESZ / 4, + IMAGESZ / 4, 1); } @@ -158,10 +161,8 @@ /* Test with empty imagelist */ iset = cpl_imagelist_new(); - combined = cpl_geom_img_offset_saa(iset, offs_ref, - CPL_KERNEL_DEFAULT, - 0, 0, CPL_GEOM_FIRST, - NULL, NULL); + combined = cpl_geom_img_offset_saa(iset, offs_ref, CPL_KERNEL_DEFAULT, 0, 0, + CPL_GEOM_FIRST, NULL, NULL); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); cpl_test_null(combined); @@ -170,16 +171,14 @@ img = cpl_image_fill_test_create(IMAGESZ, IMAGESZ); cpl_imagelist_set(iset, img, 0); - for (i = 0; i < (int)(sizeof(geoms)/sizeof(geoms[0])); i++) { + for (i = 0; i < (int)(sizeof(geoms) / sizeof(geoms[0])); i++) { const cpl_geom_combine geom = geoms[i]; /* Shift and add */ cpl_msg_info("", "Shift and add single image with geom number %d", (int)geom); - combined = cpl_geom_img_offset_saa(iset, offs_ref, - CPL_KERNEL_DEFAULT, - 0, 0, geom, - NULL, NULL); + combined = cpl_geom_img_offset_saa(iset, offs_ref, CPL_KERNEL_DEFAULT, + 0, 0, geom, NULL, NULL); cpl_test_error(CPL_ERROR_NONE); @@ -210,13 +209,13 @@ cpl_bivector_unwrap_vectors(offs_ref); cpl_vector_delete(off_vec_x); - cpl_imagelist_fill_shifted(iset, NFRAMES-1, off_x_init, off_y_init); + cpl_imagelist_fill_shifted(iset, NFRAMES - 1, off_x_init, off_y_init); cpl_test_eq(cpl_imagelist_get_size(iset), NFRAMES); - + /* Not modified */ - off_vec_x = cpl_vector_wrap(NFRAMES, (double*)off_x_init); - off_vec_y = cpl_vector_wrap(NFRAMES, (double*)off_y_init); + off_vec_x = cpl_vector_wrap(NFRAMES, (double *)off_x_init); + off_vec_y = cpl_vector_wrap(NFRAMES, (double *)off_y_init); offs_est = cpl_bivector_new(NFRAMES); cpl_vector_copy(cpl_bivector_get_x(offs_est), off_vec_x); cpl_vector_copy(cpl_bivector_get_y(offs_est), off_vec_y); @@ -225,13 +224,13 @@ cpl_vector_add_scalar(cpl_bivector_get_x(offs_est), 2.0); cpl_vector_add_scalar(cpl_bivector_get_y(offs_est), -3.0); - sigmas = cpl_vector_wrap(NSIGMAS, (double*)psigmas); /* Not modified */ + sigmas = cpl_vector_wrap(NSIGMAS, (double *)psigmas); /* Not modified */ cpl_test_error(CPL_ERROR_NONE); /* Get some cross-correlation apertures */ - aperts = cpl_apertures_extract(cpl_imagelist_get_const(iset, 0), sigmas, - &pos); + aperts = + cpl_apertures_extract(cpl_imagelist_get_const(iset, 0), sigmas, &pos); cpl_vector_unwrap(sigmas); cpl_test_nonnull(aperts); @@ -240,31 +239,46 @@ cpl_test_leq(1, naperts); - cpl_msg_info("","Detected %d apertures at sigma %g (%" CPL_SIZE_FORMAT "/%" - CPL_SIZE_FORMAT ")", naperts, psigmas[pos], 1+pos, - (cpl_size)NSIGMAS); + cpl_msg_info("", + "Detected %d apertures at sigma %g (%" CPL_SIZE_FORMAT + "/%" CPL_SIZE_FORMAT ")", + naperts, psigmas[pos], 1 + pos, (cpl_size)NSIGMAS); if (cpl_msg_get_level() <= CPL_MSG_DEBUG) cpl_apertures_dump(aperts, stdout); aperts_pos = cpl_bivector_new(naperts); aperts_pos_x = cpl_bivector_get_x(aperts_pos); aperts_pos_y = cpl_bivector_get_y(aperts_pos); - for (i=0; i 0.0 ? (double)nflops/cputime/1e6 : 0.0); + cputime > 0.0 ? (double)nflops / cputime / 1e6 : 0.0); if (cputime > 0.0) { - cpl_msg_info(cpl_func,"Processing rate [MB/s]: %g", + cpl_msg_info(cpl_func, "Processing rate [MB/s]: %g", 1e-6 * (double)bytes / cputime); } @@ -703,27 +734,28 @@ */ /*----------------------------------------------------------------------------*/ -static -void cpl_imagelist_fill_shifted(cpl_imagelist * self, cpl_size napp, - const double * dx, const double * dy) +static void +cpl_imagelist_fill_shifted(cpl_imagelist *self, + cpl_size napp, + const double *dx, + const double *dy) { - - const cpl_image * img = cpl_imagelist_get_const(self, 0); - const cpl_size type = cpl_image_get_type (img); - const cpl_size nx = cpl_image_get_size_x(img); - const cpl_size ny = cpl_image_get_size_x(img); - const cpl_size ishift_0[2] = {0, 0}; - const cpl_size ishift_x[2] = {1, 0}; - const cpl_size ishift_y[2] = {0, 1}; - - const double xyradius = CPL_KERNEL_DEF_WIDTH; - - cpl_vector * xyprofile = cpl_vector_new(CPL_KERNEL_DEF_SAMPLES); - - cpl_polynomial * shift_x = cpl_polynomial_new(2); - cpl_polynomial * shift_y = cpl_polynomial_new(2); - cpl_error_code error; - cpl_size i; + const cpl_image *img = cpl_imagelist_get_const(self, 0); + const cpl_size type = cpl_image_get_type(img); + const cpl_size nx = cpl_image_get_size_x(img); + const cpl_size ny = cpl_image_get_size_x(img); + const cpl_size ishift_0[2] = { 0, 0 }; + const cpl_size ishift_x[2] = { 1, 0 }; + const cpl_size ishift_y[2] = { 0, 1 }; + + const double xyradius = CPL_KERNEL_DEF_WIDTH; + + cpl_vector *xyprofile = cpl_vector_new(CPL_KERNEL_DEF_SAMPLES); + + cpl_polynomial *shift_x = cpl_polynomial_new(2); + cpl_polynomial *shift_y = cpl_polynomial_new(2); + cpl_error_code error; + cpl_size i; cpl_test_eq(cpl_imagelist_get_size(self), 1); @@ -739,13 +771,13 @@ cpl_test_eq_error(error, CPL_ERROR_NONE); /* Resampling profile */ - error = cpl_vector_fill_kernel_profile(xyprofile, CPL_KERNEL_DEFAULT, - xyradius); + error = + cpl_vector_fill_kernel_profile(xyprofile, CPL_KERNEL_DEFAULT, xyradius); cpl_test_eq_error(error, CPL_ERROR_NONE); /* Append images to image set */ - for (i=1; i < napp+1; i++) { - cpl_image * copy = cpl_image_new(nx, ny, type); + for (i = 1; i < napp + 1; i++) { + cpl_image *copy = cpl_image_new(nx, ny, type); /* Shift in X and Y */ error = cpl_polynomial_set_coeff(shift_x, ishift_0, dx[i]); @@ -754,22 +786,20 @@ error = cpl_polynomial_set_coeff(shift_y, ishift_0, dy[i]); cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_image_warp_polynomial(copy, img, shift_x, shift_y, - xyprofile, xyradius, - xyprofile, xyradius); + error = + cpl_image_warp_polynomial(copy, img, shift_x, shift_y, xyprofile, + xyradius, xyprofile, xyradius); cpl_test_eq_error(error, CPL_ERROR_NONE); error = cpl_imagelist_set(self, copy, i); cpl_test_eq_error(error, CPL_ERROR_NONE); - } cpl_polynomial_delete(shift_x); cpl_polynomial_delete(shift_y); cpl_vector_delete(xyprofile); - cpl_test_eq(cpl_imagelist_get_size(self), napp+1); - + cpl_test_eq(cpl_imagelist_get_size(self), napp + 1); } @@ -783,28 +813,27 @@ */ /*----------------------------------------------------------------------------*/ -static -void cpl_geom_img_offset_saa_one(cpl_kernel kernel) +static void +cpl_geom_img_offset_saa_one(cpl_kernel kernel) { - - const int nz = 2 + NFRAMES; - cpl_imagelist * imglist = cpl_imagelist_new(); - cpl_image ** combined; - cpl_bivector * offset = cpl_bivector_new(nz); - cpl_vector * off_x = cpl_bivector_get_x(offset); - cpl_vector * off_y = cpl_bivector_get_y(offset); - cpl_error_code error; - cpl_size iz; - cpl_image * central0; - cpl_image * central1; + const int nz = 2 + NFRAMES; + cpl_imagelist *imglist = cpl_imagelist_new(); + cpl_image **combined; + cpl_bivector *offset = cpl_bivector_new(nz); + cpl_vector *off_x = cpl_bivector_get_x(offset); + cpl_vector *off_y = cpl_bivector_get_y(offset); + cpl_error_code error; + cpl_size iz; + cpl_image *central0; + cpl_image *central1; for (iz = 0; iz < nz; iz++) { - cpl_image * img = cpl_image_new(IMAGESZ, IMAGESZ, CPL_TYPE_FLOAT); + cpl_image *img = cpl_image_new(IMAGESZ, IMAGESZ, CPL_TYPE_FLOAT); cpl_test_nonnull(img); /* Insert flat images with known sum of the non-rejected planes */ - error = cpl_image_add_scalar(img, (double)(nz - iz - nz/5)); + error = cpl_image_add_scalar(img, (double)(nz - iz - nz / 5)); cpl_test_eq_error(error, CPL_ERROR_NONE); error = cpl_imagelist_set(imglist, img, iz); @@ -814,7 +843,7 @@ cpl_vector_set(off_y, iz, iz ? cpl_drand() : 0.0); } - combined = cpl_geom_img_offset_saa(imglist, offset, kernel, nz/5, nz/4, + combined = cpl_geom_img_offset_saa(imglist, offset, kernel, nz / 5, nz / 4, CPL_GEOM_INTERSECT, NULL, NULL); cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(combined); @@ -823,16 +852,14 @@ cpl_test_eq_error(error, CPL_ERROR_NONE); cpl_test_eq(cpl_image_get_max(combined[0]), - (nz - nz/5 - nz/4 + 1) /2.0); - cpl_test_eq(cpl_image_get_max(combined[1]), nz - nz/5 - - nz/4); + (nz - nz / 5 - nz / 4 + 1) / 2.0); + cpl_test_eq(cpl_image_get_max(combined[1]), nz - nz / 5 - nz / 4); central0 = cpl_image_extract(combined[0], 3, 3, IMAGESZ - 2, IMAGESZ - 2); central1 = cpl_image_extract(combined[1], 3, 3, IMAGESZ - 2, IMAGESZ - 2); - cpl_test_eq(cpl_image_get_min(central0), - (nz - nz/5 - nz/4 + 1) /2.0); - cpl_test_eq(cpl_image_get_min(central1), nz - nz/5 - nz/4); + cpl_test_eq(cpl_image_get_min(central0), (nz - nz / 5 - nz / 4 + 1) / 2.0); + cpl_test_eq(cpl_image_get_min(central1), nz - nz / 5 - nz / 4); cpl_image_delete(combined[0]); cpl_image_delete(combined[1]); @@ -843,5 +870,4 @@ cpl_imagelist_delete(imglist); cpl_bivector_delete(offset); - } diff -Nru cpl-7.1.4+ds/cpldrs/tests/cpl_photom-test.c cpl-7.2.2+ds/cpldrs/tests/cpl_photom-test.c --- cpl-7.1.4+ds/cpldrs/tests/cpl_photom-test.c 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cpldrs/tests/cpl_photom-test.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -38,7 +38,7 @@ -----------------------------------------------------------------------------*/ #ifndef FUNCTION_SIZE -#define FUNCTION_SIZE 1024 +#define FUNCTION_SIZE 1024 #endif /* A telescope main mirror could for example have a temperature of 12C */ @@ -50,7 +50,7 @@ /* The relevant range for black-body radiation is about [2;32[ micron */ -#define WL_MIN 2e-6 +#define WL_MIN 2e-6 #define WL_MAX 32e-6 /*----------------------------------------------------------------------------- @@ -59,25 +59,29 @@ static void cpl_photom_units_test(void); -static void cpl_photom_fill_blackbody_test(cpl_vector *, cpl_unit, +static void cpl_photom_fill_blackbody_test(cpl_vector *, + cpl_unit, const cpl_vector *, - cpl_unit, double, unsigned); + cpl_unit, + double, + unsigned); /*----------------------------------------------------------------------------- Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { - cpl_polynomial * poly1 ; - cpl_bivector * fun ; - cpl_bivector * trans; - FILE * ftrans; - const double temp = TEMP_BB; - cpl_size i; - const cpl_size half_search = FUNCTION_SIZE/2; - cpl_vector * vxc; - cpl_error_code error; - double * wlf; + cpl_polynomial *poly1; + cpl_bivector *fun; + cpl_bivector *trans; + FILE *ftrans; + const double temp = TEMP_BB; + cpl_size i; + const cpl_size half_search = FUNCTION_SIZE / 2; + cpl_vector *vxc; + cpl_error_code error; + double *wlf; cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); @@ -85,38 +89,40 @@ /* Insert tests below */ cpl_msg_info("", CPL_STRINGIFY(TEMP_BB) "K Black-Body radiation peaks at " - "[m]: %g", CPL_PHYS_Wien/temp); + "[m]: %g", + CPL_PHYS_Wien / temp); cpl_msg_info("", CPL_STRINGIFY(TEMP_BB) "K Black-Body radiation peaks at " - "[Hz]: %g", CPL_PHYS_Wien_Freq * temp); + "[Hz]: %g", + CPL_PHYS_Wien_Freq * temp); cpl_photom_units_test(); poly1 = cpl_polynomial_new(1); - cpl_test_nonnull( poly1 ); + cpl_test_nonnull(poly1); i = 0; error = cpl_polynomial_set_coeff(poly1, &i, WL_MIN); cpl_test_eq_error(error, CPL_ERROR_NONE); i++; - error = cpl_polynomial_set_coeff(poly1, &i, (WL_MAX-WL_MIN)/FUNCTION_SIZE); + error = + cpl_polynomial_set_coeff(poly1, &i, (WL_MAX - WL_MIN) / FUNCTION_SIZE); cpl_test_eq_error(error, CPL_ERROR_NONE); fun = cpl_bivector_new(FUNCTION_SIZE); - cpl_test_nonnull( fun ); + cpl_test_nonnull(fun); - error = cpl_vector_fill_polynomial(cpl_bivector_get_x(fun), - poly1, 0, 1); + error = cpl_vector_fill_polynomial(cpl_bivector_get_x(fun), poly1, 0, 1); cpl_test_eq_error(error, CPL_ERROR_NONE); cpl_photom_fill_blackbody_test(cpl_bivector_get_y(fun), CPL_UNIT_PHOTONRADIANCE, - cpl_bivector_get_x(fun), - CPL_UNIT_LENGTH, temp, __LINE__); + cpl_bivector_get_x(fun), CPL_UNIT_LENGTH, + temp, __LINE__); ftrans = fopen("planck1.txt", "w"); - cpl_test_nonnull( ftrans ); + cpl_test_nonnull(ftrans); cpl_bivector_dump(fun, ftrans); - cpl_test_zero( fclose(ftrans) ); + cpl_test_zero(fclose(ftrans)); cpl_photom_fill_blackbody_test(cpl_bivector_get_y(fun), CPL_UNIT_ENERGYRADIANCE, @@ -124,41 +130,40 @@ CPL_UNIT_LENGTH, temp, __LINE__); trans = cpl_bivector_new(FUNCTION_SIZE); - cpl_test_nonnull( trans ); + cpl_test_nonnull(trans); error = cpl_vector_copy(cpl_bivector_get_x(trans), cpl_bivector_get_x_const(fun)); cpl_test_eq_error(error, CPL_ERROR_NONE); - cpl_photom_fill_blackbody_test(cpl_bivector_get_y(trans), - CPL_UNIT_LESS, + cpl_photom_fill_blackbody_test(cpl_bivector_get_y(trans), CPL_UNIT_LESS, cpl_bivector_get_x_const(trans), CPL_UNIT_LENGTH, temp, __LINE__); - vxc = cpl_vector_new(2*half_search + 1); + vxc = cpl_vector_new(2 * half_search + 1); - cpl_test_eq( cpl_vector_correlate(vxc, cpl_bivector_get_y_const(trans), - cpl_bivector_get_y_const(fun)), - half_search ); + cpl_test_eq(cpl_vector_correlate(vxc, cpl_bivector_get_y_const(trans), + cpl_bivector_get_y_const(fun)), + half_search); cpl_test_error(CPL_ERROR_NONE); cpl_test_abs(cpl_vector_get(vxc, half_search), 1.0, FUNCTION_SIZE * DBL_EPSILON); ftrans = fopen("planck2.txt", "w"); - cpl_test_nonnull( ftrans ); + cpl_test_nonnull(ftrans); cpl_bivector_dump(trans, ftrans); - cpl_test_zero( fclose(ftrans) ); + cpl_test_zero(fclose(ftrans)); if (cpl_msg_get_level() <= CPL_MSG_DEBUG) { - const char * options[] = {"t '" CPL_STRINGIFY(TEMP_BB) "K black body " - "radiance' w points;", - "t '" CPL_STRINGIFY(TEMP_BB) "K black body " - "radiance peak';"}; - cpl_bivector *pair[] = {cpl_bivector_new(1), trans}; + const char *options[] = { "t '" CPL_STRINGIFY(TEMP_BB) "K black body " + "radiance' w points;", + "t '" CPL_STRINGIFY(TEMP_BB) "K black body " + "radiance peak';" }; + cpl_bivector *pair[] = { cpl_bivector_new(1), trans }; error = cpl_vector_set(cpl_bivector_get_x(pair[0]), 0, - CPL_PHYS_Wien/temp); + CPL_PHYS_Wien / temp); cpl_test_eq_error(error, CPL_ERROR_NONE); cpl_photom_fill_blackbody_test(cpl_bivector_get_y(pair[0]), @@ -168,7 +173,7 @@ error = cpl_plot_bivectors("set xlabel 'Wavelength [m]';" "set ylabel 'Unit less';", - options, "", (const cpl_bivector**)pair, 2); + options, "", (const cpl_bivector **)pair, 2); cpl_test_eq_error(error, CPL_ERROR_NONE); cpl_bivector_delete(pair[0]); } @@ -181,8 +186,8 @@ cpl_photom_fill_blackbody_test(cpl_bivector_get_y(fun), CPL_UNIT_PHOTONRADIANCE, - cpl_bivector_get_x(fun), - CPL_UNIT_FREQUENCY, temp, __LINE__); + cpl_bivector_get_x(fun), CPL_UNIT_FREQUENCY, + temp, __LINE__); cpl_photom_fill_blackbody_test(cpl_bivector_get_y(fun), CPL_UNIT_ENERGYRADIANCE, @@ -190,11 +195,11 @@ CPL_UNIT_FREQUENCY, temp, __LINE__); if (cpl_msg_get_level() <= CPL_MSG_DEBUG) { - const char * options[] = {"t '" CPL_STRINGIFY(TEMP_BB) "K black body " - "radiance' w points;", - "t '" CPL_STRINGIFY(TEMP_BB) "K black body " - "radiance peak';"}; - cpl_bivector *pair[] = {cpl_bivector_new(1), fun}; + const char *options[] = { "t '" CPL_STRINGIFY(TEMP_BB) "K black body " + "radiance' w points;", + "t '" CPL_STRINGIFY(TEMP_BB) "K black body " + "radiance peak';" }; + cpl_bivector *pair[] = { cpl_bivector_new(1), fun }; error = cpl_vector_set(cpl_bivector_get_x(pair[0]), 0, CPL_PHYS_Wien_Freq * temp); @@ -207,65 +212,56 @@ error = cpl_plot_bivectors("set xlabel 'Frequency [hz]';" "set ylabel 'Energy Radiance';", - options, "", (const cpl_bivector**)pair, 2); + options, "", (const cpl_bivector **)pair, 2); cpl_test_eq_error(error, CPL_ERROR_NONE); cpl_bivector_delete(pair[0]); } /* Error testing */ - error = cpl_photom_fill_blackbody(NULL, - CPL_UNIT_LESS, + error = cpl_photom_fill_blackbody(NULL, CPL_UNIT_LESS, cpl_bivector_get_x_const(trans), CPL_UNIT_LENGTH, temp); cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT); - error = cpl_photom_fill_blackbody(cpl_bivector_get_y(trans), - CPL_UNIT_LESS, - NULL, - CPL_UNIT_LENGTH, temp); + error = cpl_photom_fill_blackbody(cpl_bivector_get_y(trans), CPL_UNIT_LESS, + NULL, CPL_UNIT_LENGTH, temp); cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT); - error = cpl_photom_fill_blackbody(vxc, - CPL_UNIT_LESS, + error = cpl_photom_fill_blackbody(vxc, CPL_UNIT_LESS, cpl_bivector_get_x_const(trans), CPL_UNIT_LENGTH, temp); cpl_test_eq_error(error, CPL_ERROR_INCOMPATIBLE_INPUT); - error = cpl_photom_fill_blackbody(cpl_bivector_get_y(trans), - CPL_UNIT_LESS, + error = cpl_photom_fill_blackbody(cpl_bivector_get_y(trans), CPL_UNIT_LESS, cpl_bivector_get_x_const(trans), CPL_UNIT_LENGTH, 0.0); cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); - error = cpl_photom_fill_blackbody(cpl_bivector_get_y(trans), - CPL_UNIT_LESS, + error = cpl_photom_fill_blackbody(cpl_bivector_get_y(trans), CPL_UNIT_LESS, cpl_bivector_get_x_const(trans), CPL_UNIT_FREQUENCY, temp); cpl_test_eq_error(error, CPL_ERROR_UNSUPPORTED_MODE); - error = cpl_photom_fill_blackbody(cpl_bivector_get_y(trans), - CPL_UNIT_LESS, + error = cpl_photom_fill_blackbody(cpl_bivector_get_y(trans), CPL_UNIT_LESS, cpl_bivector_get_x_const(trans), CPL_UNIT_FREQUENCY, temp); cpl_test_eq_error(error, CPL_ERROR_UNSUPPORTED_MODE); - error = cpl_photom_fill_blackbody(cpl_bivector_get_y(trans), - CPL_UNIT_LESS, + error = cpl_photom_fill_blackbody(cpl_bivector_get_y(trans), CPL_UNIT_LESS, cpl_bivector_get_x_const(trans), CPL_UNIT_LESS, temp); cpl_test_eq_error(error, CPL_ERROR_UNSUPPORTED_MODE); - error = cpl_photom_fill_blackbody(cpl_bivector_get_y(trans), - CPL_UNIT_LENGTH, - cpl_bivector_get_x_const(trans), - CPL_UNIT_ENERGYRADIANCE, temp); + error = + cpl_photom_fill_blackbody(cpl_bivector_get_y(trans), CPL_UNIT_LENGTH, + cpl_bivector_get_x_const(trans), + CPL_UNIT_ENERGYRADIANCE, temp); cpl_test_eq_error(error, CPL_ERROR_UNSUPPORTED_MODE); error = cpl_vector_set(cpl_bivector_get_x(trans), 0, 0.0); cpl_test_error(CPL_ERROR_NONE); - error = cpl_photom_fill_blackbody(cpl_bivector_get_y(trans), - CPL_UNIT_LESS, + error = cpl_photom_fill_blackbody(cpl_bivector_get_y(trans), CPL_UNIT_LESS, cpl_bivector_get_x_const(trans), CPL_UNIT_LENGTH, temp); cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); @@ -285,23 +281,17 @@ @return void */ /*----------------------------------------------------------------------------*/ -static void cpl_photom_units_test(void) +static void +cpl_photom_units_test(void) { + const cpl_unit units[] = { + CPL_UNIT_LESS, CPL_UNIT_RADIAN, CPL_UNIT_LENGTH, + CPL_UNIT_TIME, CPL_UNIT_PERLENGTH, CPL_UNIT_FREQUENCY, + CPL_UNIT_MASS, CPL_UNIT_ACCELERATION, CPL_UNIT_FORCE, + CPL_UNIT_ENERGY, CPL_UNIT_PHOTONRADIANCE, CPL_UNIT_ENERGYRADIANCE + }; - const cpl_unit units[] = { CPL_UNIT_LESS, - CPL_UNIT_RADIAN, - CPL_UNIT_LENGTH, - CPL_UNIT_TIME, - CPL_UNIT_PERLENGTH, - CPL_UNIT_FREQUENCY, - CPL_UNIT_MASS, - CPL_UNIT_ACCELERATION, - CPL_UNIT_FORCE, - CPL_UNIT_ENERGY, - CPL_UNIT_PHOTONRADIANCE, - CPL_UNIT_ENERGYRADIANCE}; - - const unsigned nunits = sizeof(units)/sizeof(units[0]); + const unsigned nunits = sizeof(units) / sizeof(units[0]); unsigned i, j; /* No-unit must be the identity element with respect to multiplication */ @@ -310,7 +300,8 @@ /* Verify uniqueness of units */ for (i = 0; i < nunits; i++) { for (j = 0; j < nunits; j++) { - if (i == j) continue; + if (i == j) + continue; cpl_test_noneq(units[i], units[j]); } } @@ -327,12 +318,13 @@ cpl_test_eq(CPL_UNIT_ENERGY, CPL_UNIT_LENGTH * CPL_UNIT_FORCE); - cpl_test_eq(CPL_UNIT_PHOTONRADIANCE, CPL_UNIT_RADIAN * CPL_UNIT_FREQUENCY - * CPL_UNIT_PERLENGTH * CPL_UNIT_PERLENGTH * CPL_UNIT_PERLENGTH); - cpl_test_eq(CPL_UNIT_ENERGYRADIANCE, CPL_UNIT_ENERGY * CPL_UNIT_PHOTONRADIANCE); + cpl_test_eq(CPL_UNIT_PHOTONRADIANCE, + CPL_UNIT_RADIAN * CPL_UNIT_FREQUENCY * CPL_UNIT_PERLENGTH * + CPL_UNIT_PERLENGTH * CPL_UNIT_PERLENGTH); + cpl_test_eq(CPL_UNIT_ENERGYRADIANCE, + CPL_UNIT_ENERGY * CPL_UNIT_PHOTONRADIANCE); return; - } /*----------------------------------------------------------------------------*/ @@ -354,61 +346,63 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_photom_fill_blackbody_test(cpl_vector * spectrum, - cpl_unit out_unit, - const cpl_vector * evalpoints, - cpl_unit in_unit, - double temp, unsigned line) +static void +cpl_photom_fill_blackbody_test(cpl_vector *spectrum, + cpl_unit out_unit, + const cpl_vector *evalpoints, + cpl_unit in_unit, + double temp, + unsigned line) { - - const cpl_size fsize = cpl_vector_get_size(spectrum); - const cpl_error_code error = cpl_photom_fill_blackbody(spectrum, out_unit, - evalpoints, in_unit, - temp); + const cpl_size fsize = cpl_vector_get_size(spectrum); + const cpl_error_code error = + cpl_photom_fill_blackbody(spectrum, out_unit, evalpoints, in_unit, + temp); cpl_test_eq_error(error, CPL_ERROR_NONE); if (error != CPL_ERROR_NONE) { cpl_msg_error(cpl_func, "Failure from line %u", line); - } else if (out_unit == CPL_UNIT_ENERGYRADIANCE) { + } + else if (out_unit == CPL_UNIT_ENERGYRADIANCE) { /* FIXME: Test also CPL_UNIT_PHOTONRADIANCE */ - const double * sp = cpl_vector_get_data_const(spectrum); - const double * wl = cpl_vector_get_data_const(evalpoints); - cpl_size i; + const double *sp = cpl_vector_get_data_const(spectrum); + const double *wl = cpl_vector_get_data_const(evalpoints); + cpl_size i; if (in_unit == CPL_UNIT_LENGTH) { - const double xtpt = CPL_PHYS_Wien/temp; /* wavelength */ + const double xtpt = CPL_PHYS_Wien / temp; /* wavelength */ cpl_test_lt(0.0, sp[0]); for (i = 1; i < fsize; i++) { - /* Wavelengths must increase */ - cpl_test_lt(wl[i-1], wl[i]); + cpl_test_lt(wl[i - 1], wl[i]); if (wl[i] < xtpt) { /* Must be monotonely increasing */ - cpl_test_lt(sp[i-1], sp[i]); - } else if (i < fsize - 1) { + cpl_test_lt(sp[i - 1], sp[i]); + } + else if (i < fsize - 1) { /* Must be monotonely decreasing */ - cpl_test_lt(sp[i+1], sp[i]); + cpl_test_lt(sp[i + 1], sp[i]); } } - } else if (in_unit == CPL_UNIT_FREQUENCY) { - + } + else if (in_unit == CPL_UNIT_FREQUENCY) { const double xtpt = temp * CPL_PHYS_Wien_Freq; /* Frequency */ cpl_test_lt(0.0, sp[0]); for (i = 1; i < fsize; i++) { - /* Frequencies must increase */ - cpl_test_lt(wl[i], wl[i-1]); + cpl_test_lt(wl[i], wl[i - 1]); if (xtpt < wl[i]) { /* Must be monotonely increasing */ - cpl_test_lt(sp[i-1], sp[i]); - } else if (i < fsize - 1) { + cpl_test_lt(sp[i - 1], sp[i]); + } + else if (i < fsize - 1) { /* Must be monotonely decreasing */ - cpl_test_lt(sp[i+1], sp[i]); + cpl_test_lt(sp[i + 1], sp[i]); } } } diff -Nru cpl-7.1.4+ds/cpldrs/tests/cpl_ppm-test.c cpl-7.2.2+ds/cpldrs/tests/cpl_ppm-test.c --- cpl-7.1.4+ds/cpldrs/tests/cpl_ppm-test.c 2021-05-07 12:09:09.000000000 +0000 +++ cpl-7.2.2+ds/cpldrs/tests/cpl_ppm-test.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -21,135 +21,232 @@ #include #endif +#include +#include #include #include #include -#include -#include -#include "cpl_test.h" -#include "cpl_math_const.h" -#include "cpl_ppm.h" #include "cpl_error.h" -#include "cpl_msg.h" +#include "cpl_math_const.h" #include "cpl_memory.h" +#include "cpl_msg.h" +#include "cpl_ppm.h" +#include "cpl_test.h" -int main(void) +int +main(void) { - cpl_matrix *pattern = NULL; - cpl_matrix *data = NULL; - cpl_matrix *rdata = NULL; + cpl_matrix *pattern = NULL; + cpl_matrix *data = NULL; + cpl_matrix *rdata = NULL; cpl_matrix *mpattern = NULL; - cpl_matrix *mdata = NULL; - cpl_array *matches = NULL; - cpl_array *nullarray= NULL; - cpl_matrix *rotate = NULL; + cpl_matrix *mdata = NULL; + cpl_array *matches = NULL; + cpl_array *nullarray = NULL; + cpl_matrix *rotate = NULL; cpl_matrix *twobytwo = NULL; - const double buffer[] = {96.807119, 6.673062, - 47.828109, 90.953442, - 35.169238, 93.253366, - 65.443582, 2.107025, - 51.220486, 20.201893, - 93.997703, 20.408227, - 37.882893, 79.311394, - 28.820079, 26.715673, - 35.682260, 12.837355, - 70.329776, 73.741373, - 80.252114, 91.523087, - 51.138163, 76.205738, - 45.638141, 47.106201, - 29.955025, 61.255939, - 7.338079, 49.818536, - 21.958749, 4.145198, - 56.491598, 69.786858, - 95.098640, 91.660836, - 63.040224, 60.542222, - 93.767861, 14.260710, - 80.744116, 87.765564, - 34.668937, 18.627008, - 67.076958, 63.489016, - 45.342681, 2.759218, - 76.326371, 15.672457, - 76.500591, 56.578485, - 7.195544, 27.638754, - 32.784223, 52.833685, - 74.744955, 62.739249, - 14.089624, 82.083033, - 12.557785, 36.048373, - 86.228231, 69.049383, - 5.835231, 81.326871, - 60.710220, 68.875455, - 41.869094, 54.478081, - 83.136166, 22.613209, - 42.243645, 17.805103, - 41.240218, 9.320603, - 81.294120, 86.582899, - 12.079821, 57.620490, - 2.255356, 88.580412, - 14.198976, 9.450900, - 16.219166, 46.983199, - 62.284586, 90.964121, - 9.722447, 76.374210, - 73.047154, 22.280233, - 12.422583, 59.275385, - 91.329616, 18.257814, - 40.602257, 52.039836, - 87.133270, 82.471350, - 6.517916, 70.269436, - 5.084560, 48.761561, - 88.074539, 46.324777, - 58.082164, 69.368659, - 32.907676, 70.161985, - 26.989149, 35.163032, - 58.742397, 41.188125, - 44.613932, 74.961563, - 88.171324, 6.898518, - 65.925684, 97.893771, - 83.272728, 38.972839, - 20.174004, 95.695311, - 98.248224, 11.503620, - 13.953125, 38.850481, - 63.543456, 1.086395, - 21.321831, 70.061372, - 71.355831, 26.406390, - 18.822933, 59.430370, - 72.731168, 76.905097, - 28.799029, 5.638844, - 47.067082, 55.788179, - 40.801876, 5.809480, - 96.976304, 85.415809, - 80.771043, 85.147628, - 92.314327, 46.696728, - 83.041400, 75.587054, - 85.669566, 3.215404, - 71.282365, 83.917790, - 14.719024, 85.235491, - 22.768271, 78.262480, - 86.321886, 44.090102, - 48.323852, 57.677717, - 70.496492, 67.146785, - 17.108088, 43.227660, - 44.051883, 45.907117, - 48.866504, 91.118965, - 1.695296, 89.668380, - 96.928445, 98.671600, - 75.084189, 77.699488, - 83.819228, 67.398515, - 24.396216, 66.860628, - 42.985570, 10.065782, - 70.076031, 14.267935, - 93.983572, 84.795055, - 99.503426, 16.751843, - 63.057535, 85.825312, - 60.841945, 11.381387, - 43.503029, 31.338437, - 78.528172, 60.611117, - 74.566097, 22.580055}; - - const int permute[] - = {8, 2, 1, 13, 7, 3, 5, 9, 14, 4, 0, 6, 11, 10, 12, - 23, 17, 16, 28, 22, 18, 20, 24, 29, 19, 15, 21, 26, 25, 27}; + // clang-format off + const double pointdata[] = { + 96.807119, 6.673062, + 47.828109, 90.953442, + 35.169238, 93.253366, + 65.443582, 2.107025, + 51.220486, 20.201893, + 93.997703, 20.408227, + 37.882893, 79.311394, + 28.820079, 26.715673, + 35.682260, 12.837355, + 70.329776, 73.741373, + 80.252114, 91.523087, + 51.138163, 76.205738, + 45.638141, 47.106201, + 29.955025, 61.255939, + 7.338079, 49.818536, + 21.958749, 4.145198, + 56.491598, 69.786858, + 95.098640, 91.660836, + 63.040224, 60.542222, + 93.767861, 14.260710, + 80.744116, 87.765564, + 34.668937, 18.627008, + 67.076958, 63.489016, + 45.342681, 2.759218, + 76.326371, 15.672457, + 76.500591, 56.578485, + 7.195544, 27.638754, + 32.784223, 52.833685, + 74.744955, 62.739249, + 14.089624, 82.083033, + 12.557785, 36.048373, + 86.228231, 69.049383, + 5.835231, 81.326871, + 60.710220, 68.875455, + 41.869094, 54.478081, + 83.136166, 22.613209, + 42.243645, 17.805103, + 41.240218, 9.320603, + 81.294120, 86.582899, + 12.079821, 57.620490, + 2.255356, 88.580412, + 14.198976, 9.450900, + 16.219166, 46.983199, + 62.284586, 90.964121, + 9.722447, 76.374210, + 73.047154, 22.280233, + 12.422583, 59.275385, + 91.329616, 18.257814, + 40.602257, 52.039836, + 87.133270, 82.471350, + 6.517916, 70.269436, + 5.084560, 48.761561, + 88.074539, 46.324777, + 58.082164, 69.368659, + 32.907676, 70.161985, + 26.989149, 35.163032, + 58.742397, 41.188125, + 44.613932, 74.961563, + 88.171324, 6.898518, + 65.925684, 97.893771, + 83.272728, 38.972839, + 20.174004, 95.695311, + 98.248224, 11.503620, + 13.953125, 38.850481, + 63.543456, 1.086395, + 21.321831, 70.061372, + 71.355831, 26.406390, + 18.822933, 59.430370, + 72.731168, 76.905097, + 28.799029, 5.638844, + 47.067082, 55.788179, + 40.801876, 5.809480, + 96.976304, 85.415809, + 80.771043, 85.147628, + 92.314327, 46.696728, + 83.041400, 75.587054, + 85.669566, 3.215404, + 71.282365, 83.917790, + 14.719024, 85.235491, + 22.768271, 78.262480, + 86.321886, 44.090102, + 48.323852, 57.677717, + 70.496492, 67.146785, + 17.108088, 43.227660, + 44.051883, 45.907117, + 48.866504, 91.118965, + 1.695296, 89.668380, + 96.928445, 98.671600, + 75.084189, 77.699488, + 83.819228, 67.398515, + 24.396216, 66.860628, + 42.985570, 10.065782, + 70.076031, 14.267935, + 93.983572, 84.795055, + 99.503426, 16.751843, + 63.057535, 85.825312, + 60.841945, 11.381387, + 43.503029, 31.338437, + 78.528172, 60.611117, + 74.566097, 22.580055}; + // clang-format on + + const int permute[] = { 8, 2, 1, 13, 7, 3, 5, 9, 14, 4, + 0, 6, 11, 10, 12, 23, 17, 16, 28, 22, + 18, 20, 24, 29, 19, 15, 21, 26, 25, 27 }; + + + const double positions[] = { 0.1, 0.25, 1., 3., 9., 10., 11., 12.5 }; + + const double min_disp = 1.1875; + const double max_disp = 1.3125; + const double tolerance = 0.1; + + const double peakdata[] = { + 686.772, 973.745, 1140.69, 1184.02, 1219.17, 1236.48, 1262.11, 1273.67, + 1289.98, 1332.57, 1371.65, 1402.06, 1425.62, 1464.21, 1479.52, 1562.45, + 1583.41, 1636.00, 1678.33, 1699.17, 1730.06, 1899.42, 1981.58, 2002.91, + 2094.64, 2151.58, 2306.59, 2333.43, 2346.61, 2384.20, 2390.81, 2711.13, + 2823.12, 2852.02, 2866.53, 2965.52, 2998.58, 3051.23, 3060.80, 3093.66, + 3129.96, 3155.82, 3195.60, 3217.07, 3233.23, 3268.28, 3278.29, 3284.29, + 3305.73, 3324.35, 3379.01, 3386.96, 3445.52, 3455.10, 3498.60, 3684.23, + 3727.32, 3742.57, 3807.69, 3828.57, 3997.14 + }; + + const double linedata[] = { + 5400.56, 5764.42, 5820.16, 5852.49, 5872.83, 5881.90, 5901.41, 5944.83, + 5975.12, 6030.00, 6074.34, 6096.16, 6128.45, 6143.06, 6163.59, 6217.28, + 6266.50, 6304.79, 6332.77, 6382.99, 6402.25, 6506.53, 6532.88, 6598.95, + 6652.09, 6678.28, 6717.04, 6929.47, 7024.05, 7032.41, 7051.29, 7059.11, + 7173.94, 7245.17, 7438.90, 7472.44, 7488.87, 7535.77, 7544.04, 7943.18, + 8082.46, 8118.55, 8136.41, 8259.38, 8266.08, 8300.33, 8365.75, 8377.51, + 8418.43, 8463.36, 8495.36, 8544.70, 8571.35, 8591.26, 8634.65, 8647.04, + 8654.38, 8680.79, 8704.11, 8771.66, 8781.97, 8853.87, 8865.70, 8919.50, + 9148.67, 9201.76, 9220.47, 9300.85, 9326.51, 9425.38, 9534.16, 9665.42 + }; + + // clang-format off + const struct {double x; double y;} reference_matches[] = { + {1140.69, 5975.12}, + {1184.02, 6030.00}, + {1219.17, 6074.34}, + {1236.48, 6096.16}, + {1262.11, 6128.45}, + {1273.67, 6143.06}, + {1289.98, 6163.59}, + {1332.57, 6217.28}, + {1371.65, 6266.50}, + {1402.06, 6304.79}, + {1425.62, 6332.77}, + {1464.21, 6382.99}, + {1479.52, 6402.25}, + {1562.45, 6506.53}, + {1583.41, 6532.88}, + {1636.00, 6598.95}, + {1678.33, 6652.09}, + {1699.17, 6678.28}, + {1730.06, 6717.04}, + {1899.42, 6929.47}, + {1981.58, 7032.41}, + {2002.91, 7059.11}, + {2094.64, 7173.94}, + {2151.58, 7245.17}, + {2306.59, 7438.90}, + {2333.43, 7472.44}, + {2346.61, 7488.87}, + {2384.20, 7535.77}, + {2390.81, 7544.04}, + {2711.13, 7943.18}, + {2823.12, 8082.46}, + {2852.02, 8118.55}, + {2866.53, 8136.41}, + {2965.52, 8259.38}, + {2998.58, 8300.33}, + {3051.23, 8365.75}, + {3060.80, 8377.51}, + {3093.66, 8418.43}, + {3129.96, 8463.36}, + {3155.82, 8495.36}, + {3195.60, 8544.70}, + {3217.07, 8571.35}, + {3233.23, 8591.26}, + {3268.28, 8634.65}, + {3278.29, 8647.04}, + {3284.29, 8654.38}, + {3305.73, 8680.79}, + {3324.35, 8704.11}, + {3379.01, 8771.66}, + {3386.96, 8781.97}, + {3445.52, 8853.87}, + {3455.10, 8865.70}, + {3498.60, 8919.50}, + {3684.23, 9148.67}, + {3727.32, 9201.76}, + {3742.57, 9220.47}, + {3807.69, 9300.85}, + {3828.57, 9326.51} + }; + // clang-format on int i, j, k, npattern, ndata; @@ -172,6 +269,10 @@ cpl_matrix_set(pattern, 1, 2, 9.0); /* + * Testing cpl_ppm_match_points() + */ + + /* * Create an identical data matrix */ @@ -184,8 +285,8 @@ cpl_msg_info(cpl_func, "Trying to match 3 identical points:"); - matches = cpl_ppm_match_points(data, 3, 1, pattern, 3, 0, - 0.1, 1, &mdata, &mpattern, NULL, NULL); + matches = cpl_ppm_match_points(data, 3, 1, pattern, 3, 0, 0.1, 1, &mdata, + &mpattern, NULL, NULL); cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(matches); @@ -205,8 +306,8 @@ cpl_matrix_multiply_scalar(data, 2.0); - matches = cpl_ppm_match_points(data, 3, 1, pattern, 3, 0, - 0.1, 1, &mdata, &mpattern, NULL, NULL); + matches = cpl_ppm_match_points(data, 3, 1, pattern, 3, 0, 0.1, 1, &mdata, + &mpattern, NULL, NULL); cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(matches); @@ -225,18 +326,18 @@ cpl_msg_info(cpl_func, "Rotate data points by +45 degrees:"); rotate = cpl_matrix_new(2, 2); - cpl_matrix_set(rotate, 0, 0, sqrt(2)/2); - cpl_matrix_set(rotate, 0, 1, -sqrt(2)/2); - cpl_matrix_set(rotate, 1, 0, sqrt(2)/2); - cpl_matrix_set(rotate, 1, 1, sqrt(2)/2); + cpl_matrix_set(rotate, 0, 0, sqrt(2) / 2); + cpl_matrix_set(rotate, 0, 1, -sqrt(2) / 2); + cpl_matrix_set(rotate, 1, 0, sqrt(2) / 2); + cpl_matrix_set(rotate, 1, 1, sqrt(2) / 2); rdata = cpl_matrix_product_create(rotate, data); cpl_matrix_delete(rotate); cpl_matrix_delete(data); - matches = cpl_ppm_match_points(rdata, 3, 1, pattern, 3, 0, - 0.1, 1, &mdata, &mpattern, NULL, NULL); + matches = cpl_ppm_match_points(rdata, 3, 1, pattern, 3, 0, 0.1, 1, &mdata, + &mpattern, NULL, NULL); cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(matches); @@ -256,8 +357,8 @@ cpl_matrix_add_scalar(rdata, -15); - matches = cpl_ppm_match_points(rdata, 3, 1, pattern, 3, 0, - 0.1, 1, &mdata, &mpattern, NULL, NULL); + matches = cpl_ppm_match_points(rdata, 3, 1, pattern, 3, 0, 0.1, 1, &mdata, + &mpattern, NULL, NULL); cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(matches); @@ -319,8 +420,8 @@ cpl_msg_info(cpl_func, "Trying to match 8 identical points:"); - matches = cpl_ppm_match_points(data, 4, 1, pattern, 3, 0, - 0.1, 1, &mdata, &mpattern, NULL, NULL); + matches = cpl_ppm_match_points(data, 4, 1, pattern, 3, 0, 0.1, 1, &mdata, + &mpattern, NULL, NULL); cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(matches); @@ -341,8 +442,8 @@ rdata = cpl_matrix_duplicate(data); cpl_matrix_erase_columns(rdata, 6, 1); - matches = cpl_ppm_match_points(rdata, 4, 1, pattern, 3, 0, - 0.1, 1, &mdata, &mpattern, NULL, NULL); + matches = cpl_ppm_match_points(rdata, 4, 1, pattern, 3, 0, 0.1, 1, &mdata, + &mpattern, NULL, NULL); cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(matches); @@ -364,18 +465,18 @@ cpl_msg_info(cpl_func, "Rotate data points by -27 degrees:"); rotate = cpl_matrix_new(2, 2); - cpl_matrix_set(rotate, 0, 0, cos(-27./180.*CPL_MATH_PI)); - cpl_matrix_set(rotate, 0, 1, -sin(-27./180.*CPL_MATH_PI)); - cpl_matrix_set(rotate, 1, 0, sin(-27./180.*CPL_MATH_PI)); - cpl_matrix_set(rotate, 1, 1, cos(-27./180.*CPL_MATH_PI)); + cpl_matrix_set(rotate, 0, 0, cos(-27. / 180. * CPL_MATH_PI)); + cpl_matrix_set(rotate, 0, 1, -sin(-27. / 180. * CPL_MATH_PI)); + cpl_matrix_set(rotate, 1, 0, sin(-27. / 180. * CPL_MATH_PI)); + cpl_matrix_set(rotate, 1, 1, cos(-27. / 180. * CPL_MATH_PI)); rdata = cpl_matrix_product_create(rotate, data); cpl_matrix_delete(rotate); cpl_matrix_delete(data); - matches = cpl_ppm_match_points(rdata, 4, 1, pattern, 3, 0, - 0.1, 1, &mdata, &mpattern, NULL, NULL); + matches = cpl_ppm_match_points(rdata, 4, 1, pattern, 3, 0, 0.1, 1, &mdata, + &mpattern, NULL, NULL); cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(matches); @@ -403,14 +504,15 @@ * degrees and rescaled by a factor 2.35. */ - cpl_msg_info(cpl_func, "100 random distributed data points " + cpl_msg_info(cpl_func, + "100 random distributed data points " "(70 in pattern, 30 false-detections), data rescaled " "by 2.35 and rotated by 95 degrees..."); pattern = cpl_matrix_new(2, 100); for (k = 0, i = 0; i < 2; i++) { for (j = 0; j < 100; j++, k++) { - cpl_matrix_set(pattern, i, j, buffer[k]); + cpl_matrix_set(pattern, i, j, pointdata[k]); } } @@ -418,18 +520,18 @@ cpl_matrix_erase_columns(pattern, 70, 30); cpl_matrix_multiply_scalar(data, 2.35); rotate = cpl_matrix_new(2, 2); - cpl_matrix_set(rotate, 0, 0, cos(95./180.*CPL_MATH_PI)); - cpl_matrix_set(rotate, 0, 1, -sin(95./180.*CPL_MATH_PI)); - cpl_matrix_set(rotate, 1, 0, sin(95./180.*CPL_MATH_PI)); - cpl_matrix_set(rotate, 1, 1, cos(95./180.*CPL_MATH_PI)); + cpl_matrix_set(rotate, 0, 0, cos(95. / 180. * CPL_MATH_PI)); + cpl_matrix_set(rotate, 0, 1, -sin(95. / 180. * CPL_MATH_PI)); + cpl_matrix_set(rotate, 1, 0, sin(95. / 180. * CPL_MATH_PI)); + cpl_matrix_set(rotate, 1, 1, cos(95. / 180. * CPL_MATH_PI)); rdata = cpl_matrix_product_create(rotate, data); cpl_matrix_delete(rotate); cpl_matrix_delete(data); - matches = cpl_ppm_match_points(rdata, 20, 1, pattern, 10, 0, - 0.1, 0.1, &mdata, &mpattern, NULL, NULL); + matches = cpl_ppm_match_points(rdata, 20, 1, pattern, 10, 0, 0.1, 0.1, + &mdata, &mpattern, NULL, NULL); cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(matches); @@ -459,7 +561,8 @@ npattern = 10; ndata = 20; - cpl_msg_info(cpl_func, "%d random distributed data points " + cpl_msg_info(cpl_func, + "%d random distributed data points " "(%d in pattern, %d in data, i.e., including %d " "false-detections), data rescaled " "by 2.35 and rotated by 95 degrees...", @@ -468,7 +571,7 @@ pattern = cpl_matrix_new(2, ndata); for (k = 0, i = 0; i < 2; i++) { for (j = 0; j < ndata; j++, k++) { - cpl_matrix_set(pattern, i, j, buffer[k]); + cpl_matrix_set(pattern, i, j, pointdata[k]); } } @@ -476,18 +579,18 @@ cpl_matrix_erase_columns(pattern, npattern, ndata - npattern); cpl_matrix_multiply_scalar(data, 2.35); rotate = cpl_matrix_new(2, 2); - cpl_matrix_set(rotate, 0, 0, cos(95./180.*CPL_MATH_PI)); - cpl_matrix_set(rotate, 0, 1, -sin(95./180.*CPL_MATH_PI)); - cpl_matrix_set(rotate, 1, 0, sin(95./180.*CPL_MATH_PI)); - cpl_matrix_set(rotate, 1, 1, cos(95./180.*CPL_MATH_PI)); + cpl_matrix_set(rotate, 0, 0, cos(95. / 180. * CPL_MATH_PI)); + cpl_matrix_set(rotate, 0, 1, -sin(95. / 180. * CPL_MATH_PI)); + cpl_matrix_set(rotate, 1, 0, sin(95. / 180. * CPL_MATH_PI)); + cpl_matrix_set(rotate, 1, 1, cos(95. / 180. * CPL_MATH_PI)); rdata = cpl_matrix_product_create(rotate, data); cpl_matrix_delete(rotate); cpl_matrix_delete(data); - matches = cpl_ppm_match_points(rdata, ndata, 1, pattern, npattern, 0, - 0.1, 0.1, &mdata, &mpattern, NULL, NULL); + matches = cpl_ppm_match_points(rdata, ndata, 1, pattern, npattern, 0, 0.1, + 0.1, &mdata, &mpattern, NULL, NULL); cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(matches); @@ -515,8 +618,9 @@ npattern = 15; ndata = 10; - - cpl_msg_info(cpl_func, "%d random distributed data points " + + cpl_msg_info(cpl_func, + "%d random distributed data points " "(%d in pattern, %d in data, i.e., with %d " "missing detections), data rescaled " "by 2.35 and rotated by 95 degrees...", @@ -525,32 +629,32 @@ pattern = cpl_matrix_new(2, npattern); for (k = 0, i = 0; i < 2; i++) { for (j = 0; j < npattern; j++, k++) { - cpl_matrix_set(pattern, i, j, buffer[permute[k]]); + cpl_matrix_set(pattern, i, j, pointdata[permute[k]]); } } data = cpl_matrix_new(2, npattern); for (k = 0, i = 0; i < 2; i++) { for (j = 0; j < npattern; j++, k++) { - cpl_matrix_set(data, i, j, buffer[k]); + cpl_matrix_set(data, i, j, pointdata[k]); } } - + cpl_matrix_erase_columns(data, ndata, npattern - ndata); cpl_matrix_multiply_scalar(data, 2.35); rotate = cpl_matrix_new(2, 2); - cpl_matrix_set(rotate, 0, 0, cos(95./180.*CPL_MATH_PI)); - cpl_matrix_set(rotate, 0, 1, -sin(95./180.*CPL_MATH_PI)); - cpl_matrix_set(rotate, 1, 0, sin(95./180.*CPL_MATH_PI)); - cpl_matrix_set(rotate, 1, 1, cos(95./180.*CPL_MATH_PI)); + cpl_matrix_set(rotate, 0, 0, cos(95. / 180. * CPL_MATH_PI)); + cpl_matrix_set(rotate, 0, 1, -sin(95. / 180. * CPL_MATH_PI)); + cpl_matrix_set(rotate, 1, 0, sin(95. / 180. * CPL_MATH_PI)); + cpl_matrix_set(rotate, 1, 1, cos(95. / 180. * CPL_MATH_PI)); rdata = cpl_matrix_product_create(rotate, data); cpl_matrix_delete(rotate); cpl_matrix_delete(data); - - matches = cpl_ppm_match_points(rdata, ndata, 1, pattern, npattern, 0, - 0.1, 0.1, &mdata, &mpattern, NULL, NULL); + + matches = cpl_ppm_match_points(rdata, ndata, 1, pattern, npattern, 0, 0.1, + 0.1, &mdata, &mpattern, NULL, NULL); cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(matches); @@ -579,14 +683,15 @@ npattern = 10; ndata = 20; - cpl_msg_info(cpl_func, "%d random distributed aligned data points " + cpl_msg_info(cpl_func, + "%d random distributed aligned data points " "(%d in pattern, %d in data, i.e., including %d " "false-detections), data rescaled by 2.35...", ndata, npattern, ndata, ndata - npattern); pattern = cpl_matrix_new(2, ndata); for (j = 0; j < ndata; j++, k++) - cpl_matrix_set(pattern, 0, j, buffer[k]); + cpl_matrix_set(pattern, 0, j, pointdata[k]); for (j = 0; j < ndata; j++, k++) cpl_matrix_set(pattern, 1, j, 0.0); @@ -594,8 +699,8 @@ cpl_matrix_erase_columns(pattern, npattern, ndata - npattern); cpl_matrix_multiply_scalar(data, 2.35); - matches = cpl_ppm_match_points(data, ndata, 1, pattern, npattern, 0, - 0.1, 0.1, &mdata, &mpattern, NULL, NULL); + matches = cpl_ppm_match_points(data, ndata, 1, pattern, npattern, 0, 0.1, + 0.1, &mdata, &mpattern, NULL, NULL); cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(matches); @@ -612,8 +717,8 @@ cpl_array_delete(matches); /* Use data also as pattern */ - matches = cpl_ppm_match_points(data, ndata, 1, data, ndata, 0, - 0.1, 0.1, &mdata, &mpattern, NULL, NULL); + matches = cpl_ppm_match_points(data, ndata, 1, data, ndata, 0, 0.1, 0.1, + &mdata, &mpattern, NULL, NULL); cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(matches); @@ -630,31 +735,31 @@ cpl_array_delete(matches); cpl_msg_info(cpl_func, "Check handling of NULL input"); - nullarray = cpl_ppm_match_points(NULL, ndata, 1, pattern, npattern, 0, - 0.1, 0.1, &mdata, &mpattern, NULL, NULL); + nullarray = cpl_ppm_match_points(NULL, ndata, 1, pattern, npattern, 0, 0.1, + 0.1, &mdata, &mpattern, NULL, NULL); cpl_test_error(CPL_ERROR_NULL_INPUT); cpl_test_null(nullarray); cpl_test_null(mpattern); cpl_test_null(mdata); - nullarray = cpl_ppm_match_points(data, ndata, 1, NULL, npattern, 0, - 0.1, 0.1, &mdata, &mpattern, NULL, NULL); + nullarray = cpl_ppm_match_points(data, ndata, 1, NULL, npattern, 0, 0.1, + 0.1, &mdata, &mpattern, NULL, NULL); cpl_test_error(CPL_ERROR_NULL_INPUT); cpl_test_null(nullarray); cpl_test_null(mpattern); cpl_test_null(mdata); - nullarray = cpl_ppm_match_points(data, ndata, 1, pattern, npattern, 0, - 0.1, 0.1, NULL, &mpattern, NULL, NULL); + nullarray = cpl_ppm_match_points(data, ndata, 1, pattern, npattern, 0, 0.1, + 0.1, NULL, &mpattern, NULL, NULL); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); cpl_test_null(nullarray); cpl_test_null(mpattern); - nullarray = cpl_ppm_match_points(data, ndata, 1, pattern, npattern, 0, - 0.1, 0.1, &mdata, NULL, NULL, NULL); + nullarray = cpl_ppm_match_points(data, ndata, 1, pattern, npattern, 0, 0.1, + 0.1, &mdata, NULL, NULL, NULL); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); cpl_test_null(nullarray); @@ -663,8 +768,8 @@ cpl_msg_info(cpl_func, "Check handling of other invalid input"); /* ndata too small */ - nullarray = cpl_ppm_match_points(data, 2, 1, pattern, npattern, 0, - 0.1, 0.1, &mdata, &mpattern, NULL, NULL); + nullarray = cpl_ppm_match_points(data, 2, 1, pattern, npattern, 0, 0.1, 0.1, + &mdata, &mpattern, NULL, NULL); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); cpl_test_null(nullarray); @@ -672,7 +777,7 @@ cpl_test_null(mdata); /* ndata too large */ - nullarray = cpl_ppm_match_points(data, ndata+1, 1, pattern, npattern, 0, + nullarray = cpl_ppm_match_points(data, ndata + 1, 1, pattern, npattern, 0, 0.1, 0.1, &mdata, &mpattern, NULL, NULL); cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); @@ -681,7 +786,7 @@ cpl_test_null(mdata); /* npattern too large */ - nullarray = cpl_ppm_match_points(data, ndata, 1, pattern, npattern+1, 0, + nullarray = cpl_ppm_match_points(data, ndata, 1, pattern, npattern + 1, 0, 0.1, 0.1, &mdata, &mpattern, NULL, NULL); cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE); @@ -690,8 +795,8 @@ cpl_test_null(mdata); /* npattern too small */ - nullarray = cpl_ppm_match_points(data, ndata, 1, pattern, 2, 0, - 0.1, 0.1, &mdata, &mpattern, NULL, NULL); + nullarray = cpl_ppm_match_points(data, ndata, 1, pattern, 2, 0, 0.1, 0.1, + &mdata, &mpattern, NULL, NULL); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); cpl_test_null(nullarray); @@ -736,8 +841,8 @@ cpl_test_null(mdata); /* Too few columns in pattern */ - matches = cpl_ppm_match_points(data, ndata, 1, twobytwo, npattern, 0, - 0.1, 0.1, &mdata, &mpattern, NULL, NULL); + matches = cpl_ppm_match_points(data, ndata, 1, twobytwo, npattern, 0, 0.1, + 0.1, &mdata, &mpattern, NULL, NULL); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); cpl_test_null(nullarray); @@ -748,5 +853,175 @@ cpl_matrix_delete(data); cpl_matrix_delete(pattern); + + /* + * Testing cpl_ppm_match_positions() + */ + + cpl_vector *peaks = NULL; + cpl_vector *lines = NULL; + cpl_bivector *matched_positions = NULL; + + /* + * Test the case where peaks and lines are identical + */ + + cpl_msg_info(cpl_func, "Testing cpl_ppm_match_positions(): " + "identical data and pattern"); + + peaks = cpl_vector_wrap(4, (double *)&positions[2]); + lines = cpl_vector_wrap(4, (double *)&positions[2]); + + matched_positions = + cpl_ppm_match_positions(peaks, lines, 0.99, 1.01, 1.0, NULL, NULL); + + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(matched_positions); + cpl_test_eq(cpl_bivector_get_size(matched_positions), + cpl_vector_get_size(peaks) - 1); + + cpl_bivector_delete(matched_positions); + cpl_vector_unwrap(peaks); + + /* add additional peaks at the end */ + cpl_msg_info(cpl_func, "Testing cpl_ppm_match_positions(): " + "extra data (not in the pattern) at the end"); + + peaks = cpl_vector_wrap(6, (double *)&positions[2]); + matched_positions = + cpl_ppm_match_positions(peaks, lines, 0.9, 1.1, 0.9, NULL, NULL); + + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(matched_positions); + cpl_test_eq(cpl_bivector_get_size(matched_positions), + cpl_vector_get_size(lines) - 1); + + cpl_bivector_delete(matched_positions); + cpl_vector_unwrap(peaks); + + /* add additional peaks at both ends */ + cpl_msg_info(cpl_func, "Testing cpl_ppm_match_positions(): " + "extra data (not in the pattern) at both ends"); + + peaks = cpl_vector_wrap(8, (double *)&positions[0]); + matched_positions = + cpl_ppm_match_positions(peaks, lines, 0.9, 1.1, 0.9, NULL, NULL); + + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(matched_positions); + cpl_test_eq(cpl_bivector_get_size(matched_positions), + cpl_vector_get_size(lines) - 1); + + cpl_bivector_delete(matched_positions); + cpl_vector_unwrap(peaks); + cpl_vector_unwrap(lines); + + /* inverse scenario: extra lines at both ends compared to the peaks */ + cpl_msg_info(cpl_func, + "Testing cpl_ppm_match_positions(): " + "extra lines in the pattern (not in the data) at both ends"); + + peaks = cpl_vector_wrap(4, (double *)&positions[2]); + lines = cpl_vector_wrap(8, (double *)&positions[0]); + + matched_positions = + cpl_ppm_match_positions(peaks, lines, 0.9, 1.1, 0.9, NULL, NULL); + + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(matched_positions); + cpl_test_eq(cpl_bivector_get_size(matched_positions), + cpl_vector_get_size(peaks) - 1); + + cpl_bivector_delete(matched_positions); + cpl_vector_unwrap(peaks); + cpl_vector_unwrap(lines); + + /* + * Test real life scenario + */ + cpl_msg_info(cpl_func, "Testing cpl_ppm_match_positions(): " + "real life wavelength calibration test case"); + + peaks = cpl_vector_wrap(CX_N_ELEMENTS(peakdata), (double *)&peakdata[0]); + lines = cpl_vector_wrap(CX_N_ELEMENTS(linedata), (double *)&linedata[0]); + + matched_positions = + cpl_ppm_match_positions(peaks, lines, min_disp, max_disp, tolerance, + NULL, NULL); + + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(matched_positions); + cpl_test_eq(cpl_bivector_get_size(matched_positions), + CX_N_ELEMENTS(reference_matches)); + + const double *matches_x = cpl_bivector_get_x_data_const(matched_positions); + const double *matches_y = cpl_bivector_get_y_data_const(matched_positions); + + const double epsilon = 100. * DBL_EPSILON; + + int false_matches = 0; + size_t imatch; + for (imatch = 0; imatch < CX_N_ELEMENTS(reference_matches); ++imatch) { + double dx = fabs(matches_x[imatch] - reference_matches[imatch].x); + double dy = fabs(matches_y[imatch] - reference_matches[imatch].y); + if ((dx > epsilon) || (dy > epsilon)) { + ++false_matches; + } + } + cpl_test_zero(false_matches); + + cpl_bivector_delete(matched_positions); + cpl_vector_unwrap(peaks); + cpl_vector_unwrap(lines); + + /* + * Test error handling + */ + + /* Check for NULL return when there are less than 4 peaks in input. */ + cpl_msg_info(cpl_func, "Testing cpl_ppm_match_positions(): " + "error handling: insufficient data"); + + peaks = cpl_vector_wrap(3, (double *)&positions[2]); + lines = cpl_vector_wrap(3, (double *)&positions[2]); + + matched_positions = + cpl_ppm_match_positions(peaks, lines, 0.9, 1.1, 0.9, NULL, NULL); + + cpl_test_error(CPL_ERROR_NONE); + cpl_test_null(matched_positions); + + /* Check unsupported output arrays */ + cpl_msg_info(cpl_func, "Testing cpl_ppm_match_positions(): " + "error handling: use of unsupported output arrays"); + + cpl_array *seq_peaks = cpl_array_new(3, CPL_TYPE_DOUBLE); + cpl_array *seq_lines = cpl_array_new(3, CPL_TYPE_DOUBLE); + + matched_positions = cpl_ppm_match_positions(peaks, lines, 1.0, 1.0, 1.0, + &seq_peaks, &seq_lines); + cpl_test_error(CPL_ERROR_UNSUPPORTED_MODE); + cpl_test_null(matched_positions); + + cpl_array_delete(seq_peaks); + cpl_array_delete(seq_lines); + + /* Check null input handling */ + cpl_msg_info(cpl_func, "Testing cpl_ppm_match_positions(): " + "error handling: NULL input"); + + matched_positions = + cpl_ppm_match_positions(NULL, lines, 0.0, 0.0, 0.0, NULL, NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(matched_positions); + + matched_positions = + cpl_ppm_match_positions(peaks, NULL, 0.0, 0.0, 0.0, NULL, NULL); + cpl_test_error(CPL_ERROR_NULL_INPUT); + cpl_test_null(matched_positions); + + cpl_vector_unwrap(peaks); + cpl_vector_unwrap(lines); + return cpl_test_end(0); } diff -Nru cpl-7.1.4+ds/cpldrs/tests/cpl_wcs-test.c cpl-7.2.2+ds/cpldrs/tests/cpl_wcs-test.c --- cpl-7.1.4+ds/cpldrs/tests/cpl_wcs-test.c 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cpldrs/tests/cpl_wcs-test.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -48,236 +48,130 @@ #define NDK 13 #define NIK 3 -const char *skeys[NSK] = {"CTYPE1", "CTYPE2"}; -const char *skeys_tab[NSK] = {"TCTYP3","TCTYP5"}; +const char *skeys[NSK] = { "CTYPE1", "CTYPE2" }; +const char *skeys_tab[NSK] = { "TCTYP3", "TCTYP5" }; -const char *dkeys[NDK] = {"CRVAL1", "CRVAL2", "CRPIX1", "CRPIX2", - "CD1_1", "CD1_2", "CD2_1", "CD2_2", "PV2_1", - "PV2_2", "PV2_3", "PV2_4", "PV2_5"}; -const char *dkeys_tab[NDK] = {"TCRVL3","TCRVL5","TCRPX3","TCRPX5", - "TC3_3","TC3_5","TC5_3","TC5_5","TV5_1", - "TV5_2","TV5_3","TV5_4","TV5_5"}; - -const char *ikeys[NIK] = {"NAXIS","NAXIS1","NAXIS2"}; - - -const char *svals[NSK] = {"RA---ZPN", "DEC--ZPN"}; -const double dvals[NDK] = {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}; -const int ivals[NIK] = {2, 2048, 2048}; - -const char *svals2[NSK] = {"RA---ZPN", "DEC--ZPN"}; -const double dvals2[NDK] = {136.018529319233, 34.5793698413348, - 3000.83678222321, -936.601342583387, - 5.33299465243094E-08, -0.000111500211205622, - 0.000111494500595739, -1.41761930842942E-08, - 1.0, 0.0, -45.0, 0.0, 0.0}; -const int ivals2[NIK] = {2, 2064, 2064}; +const char *dkeys[NDK] = { "CRVAL1", "CRVAL2", "CRPIX1", "CRPIX2", "CD1_1", + "CD1_2", "CD2_1", "CD2_2", "PV2_1", "PV2_2", + "PV2_3", "PV2_4", "PV2_5" }; +const char *dkeys_tab[NDK] = { "TCRVL3", "TCRVL5", "TCRPX3", "TCRPX5", "TC3_3", + "TC3_5", "TC5_3", "TC5_5", "TV5_1", "TV5_2", + "TV5_3", "TV5_4", "TV5_5" }; + +const char *ikeys[NIK] = { "NAXIS", "NAXIS1", "NAXIS2" }; + + +const char *svals[NSK] = { "RA---ZPN", "DEC--ZPN" }; +const double dvals[NDK] = { 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 }; +const int ivals[NIK] = { 2, 2048, 2048 }; + +const char *svals2[NSK] = { "RA---ZPN", "DEC--ZPN" }; +const double dvals2[NDK] = { 136.018529319233, + 34.5793698413348, + 3000.83678222321, + -936.601342583387, + 5.33299465243094E-08, + -0.000111500211205622, + 0.000111494500595739, + -1.41761930842942E-08, + 1.0, + 0.0, + -45.0, + 0.0, + 0.0 }; +const int ivals2[NIK] = { 2, 2064, 2064 }; #define NP 2 -const double physin[2*NP] = {1024.0, 1024.0, 1025.0, 1023.0}; -const double worldout[2*NP] = {3.825029720, -71.636524754, - 3.824722171, -71.636616487}; -const double stdcout[2] = {-0.554171733, 0.415628800}; +const double physin[2 * NP] = { 1024.0, 1024.0, 1025.0, 1023.0 }; +const double worldout[2 * NP] = { 3.825029720, -71.636524754, 3.824722171, + -71.636616487 }; +const double stdcout[2] = { -0.554171733, 0.415628800 }; -const double worldin[2] = {3.824875946, -71.636570620}; -const double physout[2] = {1024.5, 1023.5}; +const double worldin[2] = { 3.824875946, -71.636570620 }; +const double physout[2] = { 1024.5, 1023.5 }; #define NSTDS 94 const double xy[] = { - 382.252, 36.261, - 18.097, 38.428, - 1551.399, 51.774, - 800.372, 85.623, - 296.776, 97.524, - 1688.610, 137.485, - 1137.220, 207.411, - 881.385, 213.913, - 1301.158, 239.626, - 1925.201, 242.518, - 152.270, 252.434, - 493.289, 274.073, - 1027.982, 286.037, - 1123.301, 302.822, - 791.430, 309.277, - 1634.414, 329.992, - 45.455, 334.707, - 224.075, 343.282, - 622.339, 352.331, - 1967.698, 358.488, - 901.068, 409.338, - 953.233, 417.257, - 1289.861, 426.885, - 596.422, 430.980, - 129.039, 446.756, - 1534.073, 463.523, - 1476.210, 464.923, - 749.281, 475.854, - 441.555, 478.242, - 1333.284, 482.094, - 662.150, 536.999, - 1246.223, 585.173, - 475.595, 656.727, - 169.960, 679.461, - 1502.242, 689.464, - 93.412, 694.360, - 545.388, 696.031, - 247.199, 746.899, - 615.903, 757.244, - 1927.821, 864.380, - 1724.554, 889.479, - 1449.032, 895.684, - 1558.846, 906.941, - 777.762, 912.936, - 1327.582, 914.718, - 857.511, 920.258, - 850.675, 936.752, - 317.737, 966.788, - 1954.225, 967.560, - 1334.811,1055.225, - 311.918,1075.083, - 1132.445,1097.327, - 1600.109,1096.887, - 1254.242,1119.658, - 1285.886,1141.102, - 665.050,1149.314, - 259.059,1182.549, - 1511.898,1203.002, - 1041.352,1220.464, - 944.823,1302.967, - 990.619,1303.994, - 1303.476,1320.765, - 1059.565,1334.145, - 1035.701,1340.268, - 441.037,1340.244, - 1149.912,1355.465, - 225.527,1356.680, - 1558.375,1387.388, - 2034.853,1410.099, - 799.400,1429.687, - 1285.559,1491.646, - 218.601,1500.189, - 726.648,1516.822, - 1112.176,1520.933, - 147.153,1531.091, - 904.416,1534.735, - 1736.805,1557.387, - 1496.763,1603.196, - 1478.237,1618.552, - 770.317,1656.818, - 1625.301,1676.042, - 1207.898,1696.559, - 470.996,1727.196, - 1807.232,1732.755, - 1462.826,1735.153, - 1098.744,1753.648, - 67.590,1757.731, - 431.763,1811.486, - 92.574,1834.930, - 833.029,1939.049, - 244.391,1953.157, - 1040.013,1959.332, - 874.378,1980.592, - 1396.658,2014.189 + 382.252, 36.261, 18.097, 38.428, 1551.399, 51.774, 800.372, + 85.623, 296.776, 97.524, 1688.610, 137.485, 1137.220, 207.411, + 881.385, 213.913, 1301.158, 239.626, 1925.201, 242.518, 152.270, + 252.434, 493.289, 274.073, 1027.982, 286.037, 1123.301, 302.822, + 791.430, 309.277, 1634.414, 329.992, 45.455, 334.707, 224.075, + 343.282, 622.339, 352.331, 1967.698, 358.488, 901.068, 409.338, + 953.233, 417.257, 1289.861, 426.885, 596.422, 430.980, 129.039, + 446.756, 1534.073, 463.523, 1476.210, 464.923, 749.281, 475.854, + 441.555, 478.242, 1333.284, 482.094, 662.150, 536.999, 1246.223, + 585.173, 475.595, 656.727, 169.960, 679.461, 1502.242, 689.464, + 93.412, 694.360, 545.388, 696.031, 247.199, 746.899, 615.903, + 757.244, 1927.821, 864.380, 1724.554, 889.479, 1449.032, 895.684, + 1558.846, 906.941, 777.762, 912.936, 1327.582, 914.718, 857.511, + 920.258, 850.675, 936.752, 317.737, 966.788, 1954.225, 967.560, + 1334.811, 1055.225, 311.918, 1075.083, 1132.445, 1097.327, 1600.109, + 1096.887, 1254.242, 1119.658, 1285.886, 1141.102, 665.050, 1149.314, + 259.059, 1182.549, 1511.898, 1203.002, 1041.352, 1220.464, 944.823, + 1302.967, 990.619, 1303.994, 1303.476, 1320.765, 1059.565, 1334.145, + 1035.701, 1340.268, 441.037, 1340.244, 1149.912, 1355.465, 225.527, + 1356.680, 1558.375, 1387.388, 2034.853, 1410.099, 799.400, 1429.687, + 1285.559, 1491.646, 218.601, 1500.189, 726.648, 1516.822, 1112.176, + 1520.933, 147.153, 1531.091, 904.416, 1534.735, 1736.805, 1557.387, + 1496.763, 1603.196, 1478.237, 1618.552, 770.317, 1656.818, 1625.301, + 1676.042, 1207.898, 1696.559, 470.996, 1727.196, 1807.232, 1732.755, + 1462.826, 1735.153, 1098.744, 1753.648, 67.590, 1757.731, 431.763, + 1811.486, 92.574, 1834.930, 833.029, 1939.049, 244.391, 1953.157, + 1040.013, 1959.332, 874.378, 1980.592, 1396.658, 2014.189 }; const double radec[] = { - 135.88677979, 34.28698730, - 135.88664246, 34.24613953, - 135.88479614, 34.41748047, - 135.88023376, 34.33363724, - 135.87858582, 34.27736664, - 135.87304688, 34.43286514, - 135.86373901, 34.37126541, - 135.86285400, 34.34273529, - 135.85929871, 34.38956833, - 135.85894775, 34.45923233, - 135.85778809, 34.26112366, - 135.85470581, 34.29931259, - 135.85314941, 34.35920334, - 135.85084534, 34.36973190, - 135.84997559, 34.33263397, - 135.84710693, 34.42679977, - 135.84652710, 34.24911499, - 135.84542847, 34.26911163, - 135.84413147, 34.31375504, - 135.84321594, 34.46398163, - 135.83653259, 34.34495163, - 135.83547974, 34.35073853, - 135.83410645, 34.38834763, - 135.83352661, 34.31077576, - 135.83146667, 34.25836945, - 135.82904053, 34.41551590, - 135.82885742, 34.40904236, - 135.82754517, 34.32785416, - 135.82716370, 34.29343414, - 135.82658386, 34.39306641, - 135.81916809, 34.31809998, - 135.81260681, 34.38336945, - 135.80287170, 34.29724884, - 135.79995728, 34.26297760, - 135.79847717, 34.41189957, - 135.79797363, 34.25428772, - 135.79760742, 34.30493546, - 135.79077148, 34.27165985, - 135.78939819, 34.31282425, - 135.77473450, 34.45937729, - 135.77145386, 34.43675232, - 135.77061462, 34.40594864, - 135.76892090, 34.41823959, - 135.76821899, 34.33092880, - 135.76800537, 34.39233398, - 135.76731873, 34.33979416, - 135.76509094, 34.33901596, - 135.76103210, 34.27935028, - 135.76074219, 34.46220398, - 135.74896240, 34.39315033, - 135.74639893, 34.27863312, - 135.74327087, 34.37044907, - 135.74317932, 34.42278671, - 135.74020386, 34.38416672, - 135.73742676, 34.38760376, - 135.73634338, 34.31815338, - 135.73170471, 34.27264023, - 135.72891235, 34.41275406, - 135.72660828, 34.36019516, - 135.71536255, 34.34933853, - 135.71527100, 34.35440445, - 135.71296692, 34.38951492, - 135.71118164, 34.36217117, - 135.71046448, 34.35951996, - 135.71041870, 34.29297638, - 135.70826721, 34.37225342, - 135.70826721, 34.26868439, - 135.70388794, 34.41787720, - 135.70075989, 34.47105789, - 135.69830322, 34.33304977, - 135.68984985, 34.38727188, - 135.68881226, 34.26796341, - 135.68650818, 34.32481003, - 135.68591309, 34.36791611, - 135.68466187, 34.25994110, - 135.68405151, 34.34471130, - 135.68084717, 34.43779755, - 135.67460632, 34.41091919, - 135.67254639, 34.40884781, - 135.66752625, 34.32962036, - 135.66487122, 34.42524338, - 135.66201782, 34.37860870, - 135.65805054, 34.29612732, - 135.65704346, 34.44551849, - 135.65676880, 34.40697479, - 135.65438843, 34.36631012, - 135.65388489, 34.25082397, - 135.64648438, 34.29161072, - 135.64344788, 34.25370026, - 135.62927246, 34.33645630, - 135.62741089, 34.27054977, - 135.62643433, 34.35960388, - 135.62356567, 34.34106827, - 135.61895752, 34.39946365 + 135.88677979, 34.28698730, 135.88664246, 34.24613953, 135.88479614, + 34.41748047, 135.88023376, 34.33363724, 135.87858582, 34.27736664, + 135.87304688, 34.43286514, 135.86373901, 34.37126541, 135.86285400, + 34.34273529, 135.85929871, 34.38956833, 135.85894775, 34.45923233, + 135.85778809, 34.26112366, 135.85470581, 34.29931259, 135.85314941, + 34.35920334, 135.85084534, 34.36973190, 135.84997559, 34.33263397, + 135.84710693, 34.42679977, 135.84652710, 34.24911499, 135.84542847, + 34.26911163, 135.84413147, 34.31375504, 135.84321594, 34.46398163, + 135.83653259, 34.34495163, 135.83547974, 34.35073853, 135.83410645, + 34.38834763, 135.83352661, 34.31077576, 135.83146667, 34.25836945, + 135.82904053, 34.41551590, 135.82885742, 34.40904236, 135.82754517, + 34.32785416, 135.82716370, 34.29343414, 135.82658386, 34.39306641, + 135.81916809, 34.31809998, 135.81260681, 34.38336945, 135.80287170, + 34.29724884, 135.79995728, 34.26297760, 135.79847717, 34.41189957, + 135.79797363, 34.25428772, 135.79760742, 34.30493546, 135.79077148, + 34.27165985, 135.78939819, 34.31282425, 135.77473450, 34.45937729, + 135.77145386, 34.43675232, 135.77061462, 34.40594864, 135.76892090, + 34.41823959, 135.76821899, 34.33092880, 135.76800537, 34.39233398, + 135.76731873, 34.33979416, 135.76509094, 34.33901596, 135.76103210, + 34.27935028, 135.76074219, 34.46220398, 135.74896240, 34.39315033, + 135.74639893, 34.27863312, 135.74327087, 34.37044907, 135.74317932, + 34.42278671, 135.74020386, 34.38416672, 135.73742676, 34.38760376, + 135.73634338, 34.31815338, 135.73170471, 34.27264023, 135.72891235, + 34.41275406, 135.72660828, 34.36019516, 135.71536255, 34.34933853, + 135.71527100, 34.35440445, 135.71296692, 34.38951492, 135.71118164, + 34.36217117, 135.71046448, 34.35951996, 135.71041870, 34.29297638, + 135.70826721, 34.37225342, 135.70826721, 34.26868439, 135.70388794, + 34.41787720, 135.70075989, 34.47105789, 135.69830322, 34.33304977, + 135.68984985, 34.38727188, 135.68881226, 34.26796341, 135.68650818, + 34.32481003, 135.68591309, 34.36791611, 135.68466187, 34.25994110, + 135.68405151, 34.34471130, 135.68084717, 34.43779755, 135.67460632, + 34.41091919, 135.67254639, 34.40884781, 135.66752625, 34.32962036, + 135.66487122, 34.42524338, 135.66201782, 34.37860870, 135.65805054, + 34.29612732, 135.65704346, 34.44551849, 135.65676880, 34.40697479, + 135.65438843, 34.36631012, 135.65388489, 34.25082397, 135.64648438, + 34.29161072, 135.64344788, 34.25370026, 135.62927246, 34.33645630, + 135.62741089, 34.27054977, 135.62643433, 34.35960388, 135.62356567, + 34.34106827, 135.61895752, 34.39946365 }; static void cpl_wcs_error_test(int); @@ -285,25 +179,27 @@ static void cpl_wcs_test_one(void); static void cpl_wcs_test_5115(void); -int main (void) { +int +main(void) +{ int i; double crval1, crval2, crpix1, crpix2, cd1, cd2, cd3, cd4; - cpl_propertylist *pl,*opl; + cpl_propertylist *pl, *opl; cpl_wcs *wcs; - cpl_matrix *from,*xymat,*rdmat; - cpl_matrix * to = NULL; - cpl_array * status = NULL; - const cpl_array * nullarray; - const cpl_array * arrdims; - const cpl_matrix * nullmatrix; + cpl_matrix *from, *xymat, *rdmat; + cpl_matrix *to = NULL; + cpl_array *status = NULL; + const cpl_array *nullarray; + const cpl_array *arrdims; + const cpl_matrix *nullmatrix; const cpl_array *crval, *crpix; const cpl_matrix *cd; - double d1,d2; + double d1, d2; cpl_error_code error; /* Initialise */ - cpl_test_init(PACKAGE_BUGREPORT,CPL_MSG_WARNING); + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); cpl_wcs_test_5115(); cpl_wcs_test_one(); @@ -325,8 +221,8 @@ if (cpl_error_get_code() == CPL_ERROR_NO_WCS) { cpl_test_error(CPL_ERROR_NO_WCS); cpl_test_null(wcs); - cpl_msg_warning(cpl_func, "WCSLIB not found - skip cpl_wcs tests") ; - cpl_propertylist_delete(pl) ; + cpl_msg_warning(cpl_func, "WCSLIB not found - skip cpl_wcs tests"); + cpl_propertylist_delete(pl); return cpl_test_end(0); } @@ -359,7 +255,7 @@ cpl_test_null(nullmatrix); /* Create a matrix. physin is _not_ modified */ - from = cpl_matrix_wrap(NP, 2, (double*)physin); + from = cpl_matrix_wrap(NP, 2, (double *)physin); /* Test handling of NULL wcs */ error = cpl_wcs_convert(NULL, from, &to, &status, CPL_WCS_PHYS2WORLD); @@ -370,11 +266,11 @@ /* Create the WCS header */ for (i = 0; i < NSK; i++) - cpl_propertylist_append_string(pl,skeys[i],svals[i]); + cpl_propertylist_append_string(pl, skeys[i], svals[i]); for (i = 0; i < NDK; i++) - cpl_propertylist_append_double(pl,dkeys[i],dvals[i]); + cpl_propertylist_append_double(pl, dkeys[i], dvals[i]); for (i = 0; i < NIK; i++) - cpl_propertylist_append_int(pl,ikeys[i],ivals[i]); + cpl_propertylist_append_int(pl, ikeys[i], ivals[i]); /* Get a wcs structure */ @@ -389,7 +285,7 @@ cpl_test_eq(cpl_array_get_type(arrdims), CPL_TYPE_INT); cpl_test_eq(cpl_array_get_size(arrdims), 2); for (i = 1; i < NIK; i++) { - cpl_test_eq(cpl_array_get_int(arrdims, i-1, NULL), ivals[i]); + cpl_test_eq(cpl_array_get_int(arrdims, i - 1, NULL), ivals[i]); } crval = cpl_wcs_get_crval(wcs); @@ -410,25 +306,25 @@ /* Test cpl_wcs_convert to see if we get the correct error messages */ /* If wcs is NULL */ - error = cpl_wcs_convert(NULL,from,&to,&status,CPL_WCS_PHYS2WORLD); + error = cpl_wcs_convert(NULL, from, &to, &status, CPL_WCS_PHYS2WORLD); cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT); cpl_test_null(to); cpl_test_null(status); /* If from is NULL */ - error = cpl_wcs_convert(wcs,NULL,&to,&status,CPL_WCS_PHYS2WORLD); + error = cpl_wcs_convert(wcs, NULL, &to, &status, CPL_WCS_PHYS2WORLD); cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT); cpl_test_null(to); cpl_test_null(status); /* If to is NULL */ - error = cpl_wcs_convert(wcs,from,NULL,&status,CPL_WCS_PHYS2WORLD); + error = cpl_wcs_convert(wcs, from, NULL, &status, CPL_WCS_PHYS2WORLD); cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT); cpl_test_null(to); cpl_test_null(status); /* If status is NULL */ - error = cpl_wcs_convert(wcs,from,&to,NULL,CPL_WCS_PHYS2WORLD); + error = cpl_wcs_convert(wcs, from, &to, NULL, CPL_WCS_PHYS2WORLD); cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT); cpl_test_null(to); cpl_test_null(status); @@ -442,8 +338,8 @@ /* Ok, do a conversion of physical to world coordinates */ - cpl_msg_info("","Transform physical -> world (2 points)"); - error = cpl_wcs_convert(wcs,from,&to,&status,CPL_WCS_PHYS2WORLD); + cpl_msg_info("", "Transform physical -> world (2 points)"); + error = cpl_wcs_convert(wcs, from, &to, &status, CPL_WCS_PHYS2WORLD); cpl_test_eq_error(error, CPL_ERROR_NONE); cpl_test_nonnull(to); cpl_test_nonnull(status); @@ -460,34 +356,34 @@ cpl_test_abs(worldout[2], cpl_matrix_get(to, 1, 0), FLT_EPSILON); cpl_test_abs(worldout[3], cpl_matrix_get(to, 1, 1), FLT_EPSILON); - d1 = fabs(worldout[0] - cpl_matrix_get(to,0,0)); - d2 = fabs(worldout[1] - cpl_matrix_get(to,0,1)); - cpl_msg_info("","phys1,phys2: %15.9f %15.9f",physin[0],physin[1]); - cpl_msg_info("","world1,world2: %15.9f %15.9f",worldout[0],worldout[1]); - cpl_msg_info("","calc1,calc2: %15.9f %15.9f",cpl_matrix_get(to,0,0), - cpl_matrix_get(to,0,1)); - cpl_msg_info("","diff1,diff2: %15.9f %15.9f",d1,d2); - cpl_msg_info("","status: %d", + d1 = fabs(worldout[0] - cpl_matrix_get(to, 0, 0)); + d2 = fabs(worldout[1] - cpl_matrix_get(to, 0, 1)); + cpl_msg_info("", "phys1,phys2: %15.9f %15.9f", physin[0], physin[1]); + cpl_msg_info("", "world1,world2: %15.9f %15.9f", worldout[0], worldout[1]); + cpl_msg_info("", "calc1,calc2: %15.9f %15.9f", cpl_matrix_get(to, 0, 0), + cpl_matrix_get(to, 0, 1)); + cpl_msg_info("", "diff1,diff2: %15.9f %15.9f", d1, d2); + cpl_msg_info("", "status: %d", cpl_array_get_data_int_const(status)[0]); - d1 = fabs(worldout[2] - cpl_matrix_get(to,1,0)); - d2 = fabs(worldout[3] - cpl_matrix_get(to,1,1)); - cpl_msg_info("","phys1,phys2: %15.9f %15.9f",physin[2],physin[3]); - cpl_msg_info("","world1,world2: %15.9f %15.9f",worldout[2],worldout[3]); - cpl_msg_info("","calc1,calc2: %15.9f %15.9f",cpl_matrix_get(to,1,0), - cpl_matrix_get(to,1,1)); - cpl_msg_info("","diff1,diff2: %15.9f %15.9f",d1,d2); - cpl_msg_info("","status: %d", + d1 = fabs(worldout[2] - cpl_matrix_get(to, 1, 0)); + d2 = fabs(worldout[3] - cpl_matrix_get(to, 1, 1)); + cpl_msg_info("", "phys1,phys2: %15.9f %15.9f", physin[2], physin[3]); + cpl_msg_info("", "world1,world2: %15.9f %15.9f", worldout[2], worldout[3]); + cpl_msg_info("", "calc1,calc2: %15.9f %15.9f", cpl_matrix_get(to, 1, 0), + cpl_matrix_get(to, 1, 1)); + cpl_msg_info("", "diff1,diff2: %15.9f %15.9f", d1, d2); + cpl_msg_info("", "status: %d", (cpl_array_get_data_int_const(status)[1])); cpl_matrix_delete(to); cpl_array_delete(status); /* Do world to physical conversion */ - cpl_msg_info("","Transform world -> physical"); + cpl_msg_info("", "Transform world -> physical"); /* worldin is _not_ modified */ - from = cpl_matrix_wrap(1,2, (double*)worldin); - error = cpl_wcs_convert(wcs,from,&to,&status,CPL_WCS_WORLD2PHYS); + from = cpl_matrix_wrap(1, 2, (double *)worldin); + error = cpl_wcs_convert(wcs, from, &to, &status, CPL_WCS_WORLD2PHYS); cpl_test_eq_error(error, CPL_ERROR_NONE); cpl_test_nonnull(to); cpl_test_nonnull(status); @@ -497,26 +393,26 @@ cpl_test_zero(cpl_array_get_data_int_const(status)[0]); cpl_test_abs(physout[0], cpl_matrix_get(to, 0, 0), 100.0 * FLT_EPSILON); - cpl_test_abs(physout[1], cpl_matrix_get(to, 0, 1), 20.0 * FLT_EPSILON); + cpl_test_abs(physout[1], cpl_matrix_get(to, 0, 1), 20.0 * FLT_EPSILON); - d1 = fabs(physout[0] - cpl_matrix_get(to,0,0)); - d2 = fabs(physout[1] - cpl_matrix_get(to,0,1)); - cpl_msg_info("","world1,world2: %15.9f %15.9f",worldin[0],worldin[1]); - cpl_msg_info("","phys1,phys2: %15.9f %15.9f",physout[0],physout[1]); - cpl_msg_info("","calc1,calc2: %15.9f %15.9f",cpl_matrix_get(to,0,0), - cpl_matrix_get(to,0,1)); - cpl_msg_info("","diff1,diff2: %15.9f %15.9f",d1,d2); - cpl_msg_info("","status: %d", + d1 = fabs(physout[0] - cpl_matrix_get(to, 0, 0)); + d2 = fabs(physout[1] - cpl_matrix_get(to, 0, 1)); + cpl_msg_info("", "world1,world2: %15.9f %15.9f", worldin[0], worldin[1]); + cpl_msg_info("", "phys1,phys2: %15.9f %15.9f", physout[0], physout[1]); + cpl_msg_info("", "calc1,calc2: %15.9f %15.9f", cpl_matrix_get(to, 0, 0), + cpl_matrix_get(to, 0, 1)); + cpl_msg_info("", "diff1,diff2: %15.9f %15.9f", d1, d2); + cpl_msg_info("", "status: %d", cpl_array_get_data_int_const(status)[0]); cpl_matrix_delete(to); cpl_array_delete(status); /* Do physical to standard */ - cpl_msg_info("","Transform physical -> standard"); + cpl_msg_info("", "Transform physical -> standard"); /* physin is _not_ modified */ - from = cpl_matrix_wrap(1, 2, (double*)physin); - error = cpl_wcs_convert(wcs,from,&to,&status,CPL_WCS_PHYS2STD); + from = cpl_matrix_wrap(1, 2, (double *)physin); + error = cpl_wcs_convert(wcs, from, &to, &status, CPL_WCS_PHYS2STD); cpl_test_eq_error(error, CPL_ERROR_NONE); cpl_test_nonnull(to); cpl_test_nonnull(status); @@ -528,23 +424,23 @@ cpl_test_abs(stdcout[0], cpl_matrix_get(to, 0, 0), 1.7e-9); cpl_test_abs(stdcout[1], cpl_matrix_get(to, 0, 1), 1.7e-9); - d1 = fabs(stdcout[0] - cpl_matrix_get(to,0,0)); - d2 = fabs(stdcout[1] - cpl_matrix_get(to,0,1)); - cpl_msg_info("","phys1,phys2: %15.9f %15.9f",physin[0],physin[1]); - cpl_msg_info("","std1,std2: %15.9f %15.9f",stdcout[0],stdcout[1]); - cpl_msg_info("","calc1,calc2: %15.9f %15.9f",cpl_matrix_get(to,0,0), - cpl_matrix_get(to,0,1)); - cpl_msg_info("","diff1,diff2: %15.9f %15.9f",d1,d2); - cpl_msg_info("","status: %d", + d1 = fabs(stdcout[0] - cpl_matrix_get(to, 0, 0)); + d2 = fabs(stdcout[1] - cpl_matrix_get(to, 0, 1)); + cpl_msg_info("", "phys1,phys2: %15.9f %15.9f", physin[0], physin[1]); + cpl_msg_info("", "std1,std2: %15.9f %15.9f", stdcout[0], stdcout[1]); + cpl_msg_info("", "calc1,calc2: %15.9f %15.9f", cpl_matrix_get(to, 0, 0), + cpl_matrix_get(to, 0, 1)); + cpl_msg_info("", "diff1,diff2: %15.9f %15.9f", d1, d2); + cpl_msg_info("", "status: %d", cpl_array_get_data_int_const(status)[0]); cpl_matrix_delete(to); cpl_array_delete(status); /* Do world to standard */ - cpl_msg_info("","Transform world -> standard"); + cpl_msg_info("", "Transform world -> standard"); /* worldout is _not_ modified */ - from = cpl_matrix_wrap(1, 2, (double*)worldout); + from = cpl_matrix_wrap(1, 2, (double *)worldout); error = cpl_wcs_convert(wcs, from, &to, &status, CPL_WCS_WORLD2STD); cpl_test_eq_error(error, CPL_ERROR_NONE); cpl_test_nonnull(to); @@ -554,17 +450,17 @@ /* Test the output values again */ cpl_test_zero(cpl_array_get_data_int_const(status)[0]); - cpl_test_abs(stdcout[0], cpl_matrix_get(to,0,0), 1.7e-9); - cpl_test_abs(stdcout[1], cpl_matrix_get(to,0,1), 1.7e-9); + cpl_test_abs(stdcout[0], cpl_matrix_get(to, 0, 0), 1.7e-9); + cpl_test_abs(stdcout[1], cpl_matrix_get(to, 0, 1), 1.7e-9); - d1 = fabs(stdcout[0] - cpl_matrix_get(to,0,0)); - d2 = fabs(stdcout[1] - cpl_matrix_get(to,0,1)); - cpl_msg_info("","world1,world2: %15.9f %15.9f",worldout[0],worldout[1]); - cpl_msg_info("","std1,std2: %15.9f %15.9f",stdcout[0],stdcout[1]); - cpl_msg_info("","calc1,calc2: %15.9f %15.9f",cpl_matrix_get(to,0,0), - cpl_matrix_get(to,0,1)); - cpl_msg_info("","diff1,diff2: %15.9f %15.9f",d1,d2); - cpl_msg_info("","status: %d", + d1 = fabs(stdcout[0] - cpl_matrix_get(to, 0, 0)); + d2 = fabs(stdcout[1] - cpl_matrix_get(to, 0, 1)); + cpl_msg_info("", "world1,world2: %15.9f %15.9f", worldout[0], worldout[1]); + cpl_msg_info("", "std1,std2: %15.9f %15.9f", stdcout[0], stdcout[1]); + cpl_msg_info("", "calc1,calc2: %15.9f %15.9f", cpl_matrix_get(to, 0, 0), + cpl_matrix_get(to, 0, 1)); + cpl_msg_info("", "diff1,diff2: %15.9f %15.9f", d1, d2); + cpl_msg_info("", "status: %d", cpl_array_get_data_int_const(status)[0]); cpl_matrix_delete(to); cpl_array_delete(status); @@ -577,17 +473,17 @@ pl = cpl_propertylist_new(); for (i = 0; i < NDK; i++) - cpl_propertylist_append_double(pl,dkeys[i],dvals2[i]); + cpl_propertylist_append_double(pl, dkeys[i], dvals2[i]); for (i = 0; i < NSK; i++) - cpl_propertylist_append_string(pl,skeys[i],svals2[i]); + cpl_propertylist_append_string(pl, skeys[i], svals2[i]); for (i = 0; i < NIK; i++) - cpl_propertylist_append_int(pl,ikeys[i],ivals2[i]); + cpl_propertylist_append_int(pl, ikeys[i], ivals2[i]); /* Wrap the coordinates into matrices */ /* xy and radec are _not_ modified */ - xymat = cpl_matrix_wrap(NSTDS, 2, (double*)xy); - rdmat = cpl_matrix_wrap(NSTDS, 2, (double*)radec); + xymat = cpl_matrix_wrap(NSTDS, 2, (double *)xy); + rdmat = cpl_matrix_wrap(NSTDS, 2, (double *)radec); if (cpl_msg_get_level() <= CPL_MSG_DEBUG) { cpl_matrix_dump(xymat, stdout); cpl_matrix_dump(rdmat, stdout); @@ -595,39 +491,38 @@ /* Do 6 constant plate solution - first with failure checks */ - error = cpl_wcs_platesol(NULL, rdmat, xymat, 3, 3.0,CPL_WCS_PLATESOL_6, - CPL_WCS_MV_CRVAL,&opl); + error = cpl_wcs_platesol(NULL, rdmat, xymat, 3, 3.0, CPL_WCS_PLATESOL_6, + CPL_WCS_MV_CRVAL, &opl); cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT); cpl_test_null(opl); - error = cpl_wcs_platesol(pl, NULL, xymat, 3, 3.0,CPL_WCS_PLATESOL_6, - CPL_WCS_MV_CRVAL,&opl); + error = cpl_wcs_platesol(pl, NULL, xymat, 3, 3.0, CPL_WCS_PLATESOL_6, + CPL_WCS_MV_CRVAL, &opl); cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT); cpl_test_null(opl); - error = cpl_wcs_platesol(pl, rdmat, NULL, 3, 3.0,CPL_WCS_PLATESOL_6, - CPL_WCS_MV_CRVAL,&opl); + error = cpl_wcs_platesol(pl, rdmat, NULL, 3, 3.0, CPL_WCS_PLATESOL_6, + CPL_WCS_MV_CRVAL, &opl); cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT); cpl_test_null(opl); - error = cpl_wcs_platesol(pl, rdmat, xymat, 3, 3.0,CPL_WCS_PLATESOL_6, + error = cpl_wcs_platesol(pl, rdmat, xymat, 3, 3.0, CPL_WCS_PLATESOL_6, CPL_WCS_MV_CRVAL, NULL); cpl_test_eq_error(error, CPL_ERROR_NULL_INPUT); error = cpl_wcs_platesol(pl, rdmat, xymat, 3, 3.0, 2 * CPL_WCS_PLATESOL_4 + 2 * CPL_WCS_PLATESOL_6, - CPL_WCS_MV_CRVAL,&opl); + CPL_WCS_MV_CRVAL, &opl); cpl_test_eq_error(error, CPL_ERROR_UNSUPPORTED_MODE); cpl_test_null(opl); - error = cpl_wcs_platesol(pl, rdmat, xymat, 3, 3.0,CPL_WCS_PLATESOL_6, - 2 * CPL_WCS_MV_CRVAL + 2 * CPL_WCS_MV_CRPIX, - &opl); + error = cpl_wcs_platesol(pl, rdmat, xymat, 3, 3.0, CPL_WCS_PLATESOL_6, + 2 * CPL_WCS_MV_CRVAL + 2 * CPL_WCS_MV_CRPIX, &opl); cpl_test_eq_error(error, CPL_ERROR_UNSUPPORTED_MODE); cpl_test_null(opl); - error = cpl_wcs_platesol(pl,rdmat,xymat, 0, 3.0,CPL_WCS_PLATESOL_6, - CPL_WCS_MV_CRVAL,&opl); + error = cpl_wcs_platesol(pl, rdmat, xymat, 0, 3.0, CPL_WCS_PLATESOL_6, + CPL_WCS_MV_CRVAL, &opl); cpl_test_eq_error(error, CPL_ERROR_ILLEGAL_INPUT); cpl_test_null(opl); @@ -638,13 +533,13 @@ /* Do 6 constant plate solution */ - error = cpl_wcs_platesol(pl,rdmat,xymat,3,3.0,CPL_WCS_PLATESOL_6, - CPL_WCS_MV_CRVAL,&opl); + error = cpl_wcs_platesol(pl, rdmat, xymat, 3, 3.0, CPL_WCS_PLATESOL_6, + CPL_WCS_MV_CRVAL, &opl); cpl_test_eq_error(error, CPL_ERROR_NONE); cpl_test_nonnull(opl); - d1 = cpl_propertylist_get_double(opl,"CSYER1"); - d2 = cpl_propertylist_get_double(opl,"CSYER2"); - cpl_msg_info("","WCS 6 constant fit with errors: %20.12g %20.12g",d1,d2); + d1 = cpl_propertylist_get_double(opl, "CSYER1"); + d2 = cpl_propertylist_get_double(opl, "CSYER2"); + cpl_msg_info("", "WCS 6 constant fit with errors: %20.12g %20.12g", d1, d2); cpl_test_leq(d1, 3.8e-5); cpl_test_leq(d2, 3.8e-5); cpl_wcs_test_propertylist(opl); @@ -654,13 +549,13 @@ /* Do 6 constant plate solution - using CPL_WCS_MV_CRPIX */ - error = cpl_wcs_platesol(pl,rdmat,xymat,3,3.0,CPL_WCS_PLATESOL_6, + error = cpl_wcs_platesol(pl, rdmat, xymat, 3, 3.0, CPL_WCS_PLATESOL_6, CPL_WCS_MV_CRPIX, &opl); cpl_test_eq_error(error, CPL_ERROR_NONE); cpl_test_nonnull(opl); - d1 = cpl_propertylist_get_double(opl,"CSYER1"); - d2 = cpl_propertylist_get_double(opl,"CSYER2"); - cpl_msg_info("","WCS 6 constant fit with errors: %20.12g %20.12g",d1,d2); + d1 = cpl_propertylist_get_double(opl, "CSYER1"); + d2 = cpl_propertylist_get_double(opl, "CSYER2"); + cpl_msg_info("", "WCS 6 constant fit with errors: %20.12g %20.12g", d1, d2); cpl_test_leq(d1, 3.8e-5); cpl_test_leq(d2, 3.8e-5); cpl_wcs_test_propertylist(opl); @@ -674,9 +569,9 @@ CPL_WCS_MV_CRVAL, &opl); cpl_test_eq_error(error, CPL_ERROR_NONE); cpl_test_nonnull(opl); - d1 = cpl_propertylist_get_double(opl,"CSYER1"); - d2 = cpl_propertylist_get_double(opl,"CSYER2"); - cpl_msg_info("","WCS 4 constant fit with errors: %20.12g %20.12g",d1,d2); + d1 = cpl_propertylist_get_double(opl, "CSYER1"); + d2 = cpl_propertylist_get_double(opl, "CSYER2"); + cpl_msg_info("", "WCS 4 constant fit with errors: %20.12g %20.12g", d1, d2); cpl_test_leq(d1, 1.05e-4); cpl_test_leq(d2, 7.3e-5); cpl_wcs_test_propertylist(opl); @@ -689,9 +584,9 @@ CPL_WCS_MV_CRPIX, &opl); cpl_test_eq_error(error, CPL_ERROR_NONE); cpl_test_nonnull(opl); - d1 = cpl_propertylist_get_double(opl,"CSYER1"); - d2 = cpl_propertylist_get_double(opl,"CSYER2"); - cpl_msg_info("","WCS 6 constant fit with errors: %20.12g %20.12g",d1,d2); + d1 = cpl_propertylist_get_double(opl, "CSYER1"); + d2 = cpl_propertylist_get_double(opl, "CSYER2"); + cpl_msg_info("", "WCS 6 constant fit with errors: %20.12g %20.12g", d1, d2); cpl_test_leq(d1, 1.05e-4); cpl_test_leq(d2, 7.3e-5); cpl_wcs_test_propertylist(opl); @@ -709,11 +604,11 @@ pl = cpl_propertylist_new(); for (i = 0; i < NDK; i++) - cpl_propertylist_append_double(pl,dkeys[i],dvals2[i]); + cpl_propertylist_append_double(pl, dkeys[i], dvals2[i]); for (i = 0; i < NSK; i++) - cpl_propertylist_append_string(pl,skeys[i],svals2[i]); + cpl_propertylist_append_string(pl, skeys[i], svals2[i]); for (i = 0; i < NIK; i++) - cpl_propertylist_append_int(pl,ikeys[i],ivals2[i]); + cpl_propertylist_append_int(pl, ikeys[i], ivals2[i]); wcs = cpl_wcs_new_from_propertylist(pl); cpl_test_nonnull(wcs); @@ -724,7 +619,7 @@ cpl_test_eq(cpl_array_get_type(arrdims), CPL_TYPE_INT); cpl_test_eq(cpl_array_get_size(arrdims), 2); for (i = 1; i < NIK; i++) { - cpl_test_eq(cpl_array_get_int(arrdims, i-1, NULL), ivals2[i]); + cpl_test_eq(cpl_array_get_int(arrdims, i - 1, NULL), ivals2[i]); } crval = cpl_wcs_get_crval(wcs); @@ -770,9 +665,9 @@ pl = cpl_propertylist_new(); for (i = 0; i < NDK; i++) - cpl_propertylist_append_double(pl,dkeys_tab[i],dvals[i]); + cpl_propertylist_append_double(pl, dkeys_tab[i], dvals[i]); for (i = 0; i < NSK; i++) - cpl_propertylist_append_string(pl,skeys_tab[i],svals[i]); + cpl_propertylist_append_string(pl, skeys_tab[i], svals[i]); wcs = cpl_wcs_new_from_propertylist(pl); cpl_test_error(CPL_ERROR_NONE); @@ -800,33 +695,34 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_wcs_test_propertylist(const cpl_propertylist * self) +static void +cpl_wcs_test_propertylist(const cpl_propertylist *self) { - cpl_wcs * wcs = cpl_wcs_new_from_propertylist(self); - const int naxis = cpl_wcs_get_image_naxis(wcs); - const cpl_array * ardims = cpl_wcs_get_image_dims(wcs); - const cpl_array * arcrval = cpl_wcs_get_crval(wcs); - const cpl_array * arcrpix = cpl_wcs_get_crpix(wcs); - const cpl_matrix * mtcd = cpl_wcs_get_cd(wcs); + cpl_wcs *wcs = cpl_wcs_new_from_propertylist(self); + const int naxis = cpl_wcs_get_image_naxis(wcs); + const cpl_array *ardims = cpl_wcs_get_image_dims(wcs); + const cpl_array *arcrval = cpl_wcs_get_crval(wcs); + const cpl_array *arcrpix = cpl_wcs_get_crpix(wcs); + const cpl_matrix *mtcd = cpl_wcs_get_cd(wcs); - cpl_test_error(CPL_ERROR_NONE); - cpl_test_nonnull(wcs); + cpl_test_error(CPL_ERROR_NONE); + cpl_test_nonnull(wcs); - cpl_test_zero(naxis); + cpl_test_zero(naxis); - cpl_test_null(ardims); + cpl_test_null(ardims); - cpl_test_nonnull(arcrval); - cpl_test_eq(cpl_array_get_size(arcrval), 2); + cpl_test_nonnull(arcrval); + cpl_test_eq(cpl_array_get_size(arcrval), 2); - cpl_test_nonnull(arcrpix); - cpl_test_eq(cpl_array_get_size(arcrpix), 2); + cpl_test_nonnull(arcrpix); + cpl_test_eq(cpl_array_get_size(arcrpix), 2); - cpl_test_nonnull(mtcd); - cpl_test_eq(cpl_matrix_get_nrow(mtcd), 2); - cpl_test_eq(cpl_matrix_get_ncol(mtcd), 2); + cpl_test_nonnull(mtcd); + cpl_test_eq(cpl_matrix_get_nrow(mtcd), 2); + cpl_test_eq(cpl_matrix_get_ncol(mtcd), 2); - cpl_wcs_delete(wcs); + cpl_wcs_delete(wcs); } /*----------------------------------------------------------------------------*/ @@ -839,8 +735,9 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_wcs_error_test(int nerror) { - +static void +cpl_wcs_error_test(int nerror) +{ int i; for (i = -1; i < nerror; i++) { @@ -849,7 +746,7 @@ error = cpl_error_set_wcs(CPL_ERROR_NONE, i, "my_wcs_dummy", "OK"); cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_error_set_wcs(CPL_ERROR_EOL, i, "my_wcs_dummy", "FAIL"); + error = cpl_error_set_wcs(CPL_ERROR_EOL, i, "my_wcs_dummy", "FAIL"); cpl_test_eq_error(error, CPL_ERROR_EOL); } } @@ -863,24 +760,24 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_wcs_test_one(void) +static void +cpl_wcs_test_one(void) { + cpl_propertylist *pl = cpl_propertylist_load(TESTFILE, 0); - cpl_propertylist * pl = cpl_propertylist_load(TESTFILE, 0); - - cpl_msg_info(cpl_func, "Testing " TESTFILE ": %p", (const void*)pl); + cpl_msg_info(cpl_func, "Testing " TESTFILE ": %p", (const void *)pl); if (pl == NULL) { /* Ignore errors */ cpl_test_error(cpl_error_get_code()); - } else { + } + else { cpl_wcs_test_propertylist(pl); cpl_propertylist_delete(pl); } } - /*----------------------------------------------------------------------------*/ /** @internal @@ -889,10 +786,11 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_wcs_test_5115(void) +static void +cpl_wcs_test_5115(void) { - cpl_propertylist * header = cpl_propertylist_new(); - cpl_wcs * wcs; + cpl_propertylist *header = cpl_propertylist_new(); + cpl_wcs *wcs; cpl_error_code code; code = cpl_propertylist_append_int(header, "NAXIS", 3); diff -Nru cpl-7.1.4+ds/cpldrs/tests/cpl_wlcalib-test.c cpl-7.2.2+ds/cpldrs/tests/cpl_wlcalib-test.c --- cpl-7.1.4+ds/cpldrs/tests/cpl_wlcalib-test.c 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cpldrs/tests/cpl_wlcalib-test.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -69,7 +69,8 @@ /*----------------------------------------------------------------------------- Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); @@ -86,46 +87,47 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_wlcalib_test_one(void) +static void +cpl_wlcalib_test_one(void) { - const double linepos[] = {0.2 * CPL_WLCALIB_SPC_SIZE, - 0.24 * CPL_WLCALIB_SPC_SIZE, - 0.5 * CPL_WLCALIB_SPC_SIZE, - 0.75 * CPL_WLCALIB_SPC_SIZE, - 0.82 * CPL_WLCALIB_SPC_SIZE}; - const double lineval[] = {1.0, 1.0, 2.0, 3.0, 4.0}; + const double linepos[] = { 0.2 * CPL_WLCALIB_SPC_SIZE, + 0.24 * CPL_WLCALIB_SPC_SIZE, + 0.5 * CPL_WLCALIB_SPC_SIZE, + 0.75 * CPL_WLCALIB_SPC_SIZE, + 0.82 * CPL_WLCALIB_SPC_SIZE }; + const double lineval[] = { 1.0, 1.0, 2.0, 3.0, 4.0 }; /* The true dispersion relation */ - const double coeffs[] = {1.0, - 2.0 / CPL_WLCALIB_SPC_SIZE, - 3.0 /(CPL_WLCALIB_SPC_SIZE*CPL_WLCALIB_SPC_SIZE)}; - const cpl_size ncoeffs = (cpl_size)(sizeof(coeffs)/sizeof(coeffs[0])); - const cpl_size nlines = (cpl_size)(sizeof(linepos)/sizeof(linepos[0])); - cpl_polynomial * dtrue = cpl_polynomial_new(1); - cpl_polynomial * dcand = cpl_polynomial_new(1); - cpl_polynomial * dfind = cpl_polynomial_new(1); - cpl_bivector * lines = cpl_bivector_new(nlines); - cpl_vector * observed = cpl_vector_new(CPL_WLCALIB_SPC_SIZE); - cpl_vector * obsfast = cpl_vector_new(CPL_WLCALIB_SPC_SIZE); - cpl_vector * wl_search = cpl_vector_new(ncoeffs); - cpl_vector * wl_sfine = cpl_vector_new(ncoeffs); - cpl_vector * xcorrs; - double xcmax = -1.0; - double tn0, tn1, tf0, tf1; - cpl_size cost, xcost; - cpl_size ntests = 1; - const cpl_size nsamples = 25; - const cpl_size hsize = 2 + abs(CPL_WLCALIB_SHIFT); - cpl_size nxc = 1 + 2 * hsize; - cpl_wlcalib_slitmodel * model = cpl_wlcalib_slitmodel_new(); + const double coeffs[] = { 1.0, 2.0 / CPL_WLCALIB_SPC_SIZE, + 3.0 / (CPL_WLCALIB_SPC_SIZE * + CPL_WLCALIB_SPC_SIZE) }; + const cpl_size ncoeffs = (cpl_size)(sizeof(coeffs) / sizeof(coeffs[0])); + const cpl_size nlines = (cpl_size)(sizeof(linepos) / sizeof(linepos[0])); + cpl_polynomial *dtrue = cpl_polynomial_new(1); + cpl_polynomial *dcand = cpl_polynomial_new(1); + cpl_polynomial *dfind = cpl_polynomial_new(1); + cpl_bivector *lines = cpl_bivector_new(nlines); + cpl_vector *observed = cpl_vector_new(CPL_WLCALIB_SPC_SIZE); + cpl_vector *obsfast = cpl_vector_new(CPL_WLCALIB_SPC_SIZE); + cpl_vector *wl_search = cpl_vector_new(ncoeffs); + cpl_vector *wl_sfine = cpl_vector_new(ncoeffs); + cpl_vector *xcorrs; + double xcmax = -1.0; + double tn0, tn1, tf0, tf1; + cpl_size cost, xcost; + cpl_size ntests = 1; + const cpl_size nsamples = 25; + const cpl_size hsize = 2 + abs(CPL_WLCALIB_SHIFT); + cpl_size nxc = 1 + 2 * hsize; + cpl_wlcalib_slitmodel *model = cpl_wlcalib_slitmodel_new(); - FILE * stream = cpl_msg_get_level() > CPL_MSG_INFO - ? fopen("/dev/null", "a") : stdout; + FILE *stream = + cpl_msg_get_level() > CPL_MSG_INFO ? fopen("/dev/null", "a") : stdout; cpl_error_code error; cpl_size i; - cpl_test_eq(nlines, (cpl_size)(sizeof(lineval)/sizeof(lineval[0]))); + cpl_test_eq(nlines, (cpl_size)(sizeof(lineval) / sizeof(lineval[0]))); cpl_test_nonnull(model); @@ -133,12 +135,11 @@ error = cpl_polynomial_set_coeff(dtrue, &i, coeffs[i]); cpl_test_eq_error(error, CPL_ERROR_NONE); - error = cpl_polynomial_set_coeff(dcand, &i, coeffs[i] - * CPL_WLCALIB_NOISE); + error = + cpl_polynomial_set_coeff(dcand, &i, coeffs[i] * CPL_WLCALIB_NOISE); cpl_test_eq_error(error, CPL_ERROR_NONE); ntests *= nsamples; - } nxc *= ntests; cpl_test_eq(cpl_polynomial_get_degree(dtrue), ncoeffs - 1); @@ -186,10 +187,10 @@ cpl_test_vector_abs(observed, obsfast, 0.2); if (cpl_msg_get_level() <= CPL_MSG_INFO) { - const cpl_vector * dual[] = {NULL, observed, obsfast}; - cpl_vector * fdiff = cpl_vector_duplicate(observed); + const cpl_vector *dual[] = { NULL, observed, obsfast }; + cpl_vector *fdiff = cpl_vector_duplicate(observed); - error = cpl_plot_vectors("", "", "", (const cpl_vector**)dual, 3); + error = cpl_plot_vectors("", "", "", (const cpl_vector **)dual, 3); cpl_test_eq_error(error, CPL_ERROR_NONE); error = cpl_vector_subtract(fdiff, obsfast); @@ -219,8 +220,8 @@ cpl_test_eq_error(error, CPL_ERROR_NONE); error = cpl_wlcalib_find_best_1d(dfind, dfind, observed, model, - cpl_wlcalib_fill_line_spectrum, - wl_search, nsamples, 0, &xcmax, NULL); + cpl_wlcalib_fill_line_spectrum, wl_search, + nsamples, 0, &xcmax, NULL); cpl_test_eq_error(error, CPL_ERROR_DATA_NOT_FOUND); cpl_test_abs(xcmax, -1.0, 0.0); @@ -233,8 +234,8 @@ cost = cpl_wlcalib_slitmodel_get_cost(model); xcost = cpl_wlcalib_slitmodel_get_xcost(model); error = cpl_wlcalib_find_best_1d(dfind, dtrue, observed, model, - cpl_wlcalib_fill_line_spectrum, - wl_search, 2*nsamples, 0, &xcmax, NULL); + cpl_wlcalib_fill_line_spectrum, wl_search, + 2 * nsamples, 0, &xcmax, NULL); cpl_test_eq_error(error, CPL_ERROR_NONE); cpl_msg_info(cpl_func, "Perfect 1st guess, XC: %g", xcmax); @@ -291,10 +292,10 @@ cost = cpl_wlcalib_slitmodel_get_cost(model); xcost = cpl_wlcalib_slitmodel_get_xcost(model); tf0 = cpl_test_get_cputime(); - error = cpl_wlcalib_find_best_1d(dfind, dcand, observed, model, - cpl_wlcalib_fill_line_spectrum_fast, - wl_search, nsamples, hsize, &xcmax, - xcorrs); + error = + cpl_wlcalib_find_best_1d(dfind, dcand, observed, model, + cpl_wlcalib_fill_line_spectrum_fast, wl_search, + nsamples, hsize, &xcmax, xcorrs); cpl_test_eq_error(error, CPL_ERROR_NONE); tf1 = cpl_test_get_cputime() - tf0; @@ -341,8 +342,8 @@ cpl_test_eq_error(error, CPL_ERROR_NONE); tn1 = cpl_test_get_cputime() - tn0; - cpl_msg_info(cpl_func, "Shifted " CPL_STRINGIFY(CPL_WLCALIB_SHIFT) - " pixel(s), XC: %g (%gsecs)", xcmax, tn1); + cpl_msg_info(cpl_func, "Shifted " CPL_STRINGIFY(CPL_WLCALIB_SHIFT) " pixel(s), XC: %g (%gsecs)", + xcmax, tn1); cpl_test_abs(xcmax, cpl_vector_get_max(xcorrs), 0.0); cpl_test_leq(xcmax, 1.0); @@ -412,14 +413,16 @@ cost = cpl_wlcalib_slitmodel_get_cost(model); xcost = cpl_wlcalib_slitmodel_get_xcost(model); tf0 = cpl_test_get_cputime(); - error = cpl_wlcalib_find_best_1d(dfind, dfind, observed, model, - cpl_wlcalib_fill_line_spectrum_fast, - wl_search, nsamples, hsize, &xcmax, xcorrs); + error = + cpl_wlcalib_find_best_1d(dfind, dfind, observed, model, + cpl_wlcalib_fill_line_spectrum_fast, wl_search, + nsamples, hsize, &xcmax, xcorrs); cpl_test_eq_error(error, CPL_ERROR_NONE); tf1 = cpl_test_get_cputime() - tf0; - cpl_msg_info(cpl_func, "Shifted " CPL_STRINGIFY(CPL_WLCALIB_SHIFT) - " pixel(s) (fast), XC: %g (%gsecs)", xcmax, tf1); + cpl_msg_info(cpl_func, + "Shifted " CPL_STRINGIFY(CPL_WLCALIB_SHIFT) " pixel(s) (fast), XC: %g (%gsecs)", + xcmax, tf1); cpl_test_abs(xcmax, cpl_vector_get_max(xcorrs), 0.0); cpl_test_leq(xcmax, 1.0); @@ -490,7 +493,8 @@ cpl_test_abs(xcmax, cpl_vector_get_max(xcorrs), 0.0); cpl_test_leq(xcmax, -1.0); - if (stream != stdout) cpl_test_zero( fclose(stream) ); + if (stream != stdout) + cpl_test_zero(fclose(stream)); cpl_wlcalib_slitmodel_delete(model); cpl_polynomial_delete(dtrue); @@ -501,5 +505,4 @@ cpl_vector_delete(wl_search); cpl_vector_delete(wl_sfine); cpl_vector_delete(xcorrs); - } diff -Nru cpl-7.1.4+ds/cpldrs/tests/Makefile.am cpl-7.2.2+ds/cpldrs/tests/Makefile.am --- cpl-7.1.4+ds/cpldrs/tests/Makefile.am 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cpldrs/tests/Makefile.am 2022-04-29 14:56:02.000000000 +0000 @@ -1,7 +1,7 @@ ## Process this file with automake to produce Makefile.in ## This file is part of the ESO Common Pipeline Library -## Copyright (C) 2001-2017 European Southern Observatory +## Copyright (C) 2001-2022 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 diff -Nru cpl-7.1.4+ds/cpldrs/tests/Makefile.in cpl-7.2.2+ds/cpldrs/tests/Makefile.in --- cpl-7.1.4+ds/cpldrs/tests/Makefile.in 2021-05-07 12:10:10.000000000 +0000 +++ cpl-7.2.2+ds/cpldrs/tests/Makefile.in 2022-04-29 14:56:28.000000000 +0000 @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.15.1 from Makefile.am. +# Makefile.in generated by automake 1.16.3 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2017 Free Software Foundation, Inc. +# Copyright (C) 1994-2020 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -186,7 +186,12 @@ am__v_at_1 = DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) depcomp = $(SHELL) $(top_srcdir)/admin/depcomp -am__depfiles_maybe = depfiles +am__maybe_remake_depfiles = depfiles +am__depfiles_remade = ./$(DEPDIR)/cpl_apertures-test.Po \ + ./$(DEPDIR)/cpl_detector-test.Po ./$(DEPDIR)/cpl_fft-test.Po \ + ./$(DEPDIR)/cpl_fit-test.Po ./$(DEPDIR)/cpl_geom_img-test.Po \ + ./$(DEPDIR)/cpl_photom-test.Po ./$(DEPDIR)/cpl_ppm-test.Po \ + ./$(DEPDIR)/cpl_wcs-test.Po ./$(DEPDIR)/cpl_wlcalib-test.Po am__mv = mv -f COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) @@ -422,6 +427,7 @@ bases='$(TEST_LOGS)'; \ bases=`for i in $$bases; do echo $$i; done | sed 's/\.log$$//'`; \ bases=`echo $$bases` +AM_TESTSUITE_SUMMARY_HEADER = ' for $(PACKAGE_STRING)' RECHECK_LOGS = $(TEST_LOGS) AM_RECURSIVE_TARGETS = check recheck TEST_SUITE_LOG = test-suite.log @@ -465,6 +471,7 @@ CPLCORE_INCLUDES = @CPLCORE_INCLUDES@ CPLDFS_INCLUDES = @CPLDFS_INCLUDES@ CPLDRS_INCLUDES = @CPLDRS_INCLUDES@ +CPLJAVA_INCLUDES = @CPLJAVA_INCLUDES@ CPLUI_INCLUDES = @CPLUI_INCLUDES@ CPL_BINARY_AGE = @CPL_BINARY_AGE@ CPL_BINARY_VERSION = @CPL_BINARY_VERSION@ @@ -525,6 +532,7 @@ LIBCPLCORE = @LIBCPLCORE@ LIBCPLDFS = @LIBCPLDFS@ LIBCPLDRS = @LIBCPLDRS@ +LIBCPLGASGANO = @LIBCPLGASGANO@ LIBCPLUI = @LIBCPLUI@ LIBFFTW = @LIBFFTW@ LIBFFTWF = @LIBFFTWF@ @@ -631,6 +639,7 @@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ @@ -687,8 +696,8 @@ *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);; \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ esac; $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) @@ -751,15 +760,21 @@ distclean-compile: -rm -f *.tab.c -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_apertures-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_detector-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_fft-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_fit-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_geom_img-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_photom-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_ppm-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_wcs-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_wlcalib-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_apertures-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_detector-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_fft-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_fit-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_geom_img-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_photom-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_ppm-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_wcs-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_wlcalib-test.Po@am__quote@ # am--include-marker + +$(am__depfiles_remade): + @$(MKDIR_P) $(@D) + @echo '# dummy' >$@-t && $(am__mv) $@-t $@ + +am--depfiles: $(am__depfiles_remade) .c.o: @am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @@ -947,7 +962,7 @@ test x"$$VERBOSE" = x || cat $(TEST_SUITE_LOG); \ fi; \ echo "$${col}$$br$${std}"; \ - echo "$${col}Testsuite summary for $(PACKAGE_STRING)$${std}"; \ + echo "$${col}Testsuite summary"$(AM_TESTSUITE_SUMMARY_HEADER)"$${std}"; \ echo "$${col}$$br$${std}"; \ create_testsuite_report --maybe-color; \ echo "$$col$$br$$std"; \ @@ -960,7 +975,7 @@ fi; \ $$success || exit 1 -check-TESTS: +check-TESTS: $(check_PROGRAMS) @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) @@ -1059,7 +1074,10 @@ @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) +distdir: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) distdir-am + +distdir-am: $(DISTFILES) @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ list='$(DISTFILES)'; \ @@ -1136,7 +1154,15 @@ mostlyclean-am distclean: distclean-am - -rm -rf ./$(DEPDIR) + -rm -f ./$(DEPDIR)/cpl_apertures-test.Po + -rm -f ./$(DEPDIR)/cpl_detector-test.Po + -rm -f ./$(DEPDIR)/cpl_fft-test.Po + -rm -f ./$(DEPDIR)/cpl_fit-test.Po + -rm -f ./$(DEPDIR)/cpl_geom_img-test.Po + -rm -f ./$(DEPDIR)/cpl_photom-test.Po + -rm -f ./$(DEPDIR)/cpl_ppm-test.Po + -rm -f ./$(DEPDIR)/cpl_wcs-test.Po + -rm -f ./$(DEPDIR)/cpl_wlcalib-test.Po -rm -f Makefile distclean-am: clean-am distclean-compile distclean-generic \ distclean-tags @@ -1182,7 +1208,15 @@ installcheck-am: maintainer-clean: maintainer-clean-am - -rm -rf ./$(DEPDIR) + -rm -f ./$(DEPDIR)/cpl_apertures-test.Po + -rm -f ./$(DEPDIR)/cpl_detector-test.Po + -rm -f ./$(DEPDIR)/cpl_fft-test.Po + -rm -f ./$(DEPDIR)/cpl_fit-test.Po + -rm -f ./$(DEPDIR)/cpl_geom_img-test.Po + -rm -f ./$(DEPDIR)/cpl_photom-test.Po + -rm -f ./$(DEPDIR)/cpl_ppm-test.Po + -rm -f ./$(DEPDIR)/cpl_wcs-test.Po + -rm -f ./$(DEPDIR)/cpl_wlcalib-test.Po -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic @@ -1203,19 +1237,20 @@ .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 +.PHONY: CTAGS GTAGS TAGS all all-am am--depfiles 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 diff -Nru cpl-7.1.4+ds/cpl.h cpl-7.2.2+ds/cpl.h --- cpl-7.1.4+ds/cpl.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cpl.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 diff -Nru cpl-7.1.4+ds/cpljava/cpl_gasgano.c cpl-7.2.2+ds/cpljava/cpl_gasgano.c --- cpl-7.1.4+ds/cpljava/cpl_gasgano.c 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cpljava/cpl_gasgano.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -18,7 +18,7 @@ */ #ifdef HAVE_CONFIG_H -# include +#include #endif #include @@ -27,7 +27,7 @@ #include #ifdef HAVE_UNISTD_H -# include +#include #endif #include @@ -56,9 +56,8 @@ #include "org_eso_cpl_jni_LibraryLoader.h" #include "org_eso_cpl_jni_PluginLibrary.h" -#if defined (HAVE_ORG_ESO_CPL_TEST_NATIVE_TEST_H) && \ - defined (ENABLE_NATIVE_TESTS) -# include "org_eso_cpl_test_NativeTest.h" +#if defined(HAVE_ORG_ESO_CPL_TEST_NATIVE_TEST_H) && defined(ENABLE_NATIVE_TESTS) +#include "org_eso_cpl_test_NativeTest.h" #endif #ifdef _OPENMP @@ -78,43 +77,44 @@ * the cpl_plugin structure to execute. */ -#define EXECUTE_CPL_PLUGIN_FUNC(env, this, Xname) \ -{ \ - jbyteArray jState = NULL; \ - cpl_plugin *plugin = NULL; \ - int ok = 1; \ - int status; \ - \ - /* Get the pointer to the function to execute. */ \ - ok = ok && \ - (jState = (*env)->GetObjectField(env, this, JNIRecipeStateField)) && \ - (plugin = (cpl_plugin *) \ - (*env)->GetByteArrayElements(env, jState, NULL)); \ - \ - /* Execute the function if it is non-NULL. */ \ - if (ok) { \ - const cpl_plugin_func cplfunc = plugin->Xname; \ - if (cplfunc) { \ - currentEnv = env; \ - status = (*cplfunc)(plugin); \ - currentEnv = NULL; \ -} \ - else { \ - status = 0; \ -} \ -} \ - else { \ - status = -1; \ -} \ - \ - /* Release array elements. */ \ - if (plugin) { \ - (*env)->ReleaseByteArrayElements(env, jState, (jbyte *) plugin, 0); \ -} \ - \ - /* Return the execution status. */ \ - return status; \ -} +#define EXECUTE_CPL_PLUGIN_FUNC(env, this, Xname) \ + { \ + jbyteArray jState = NULL; \ + cpl_plugin *plugin = NULL; \ + int ok = 1; \ + int status; \ + \ + /* Get the pointer to the function to execute. */ \ + ok = ok && \ + (jState = \ + (*env)->GetObjectField(env, this, JNIRecipeStateField)) && \ + (plugin = (cpl_plugin *)(*env)->GetByteArrayElements(env, jState, \ + NULL)); \ + \ + /* Execute the function if it is non-NULL. */ \ + if (ok) { \ + const cpl_plugin_func cplfunc = plugin->Xname; \ + if (cplfunc) { \ + currentEnv = env; \ + status = (*cplfunc)(plugin); \ + currentEnv = NULL; \ + } \ + else { \ + status = 0; \ + } \ + } \ + else { \ + status = -1; \ + } \ + \ + /* Release array elements. */ \ + if (plugin) { \ + (*env)->ReleaseByteArrayElements(env, jState, (jbyte *)plugin, 0); \ + } \ + \ + /* Return the execution status. */ \ + return status; \ + } /* @@ -235,7 +235,8 @@ static void err_message_handler(const cxchar *msg); static void default_log_message_handler(const cxchar *msg, cx_log_level_flags flags, - const cxchar *, cxptr); + const cxchar *, + cxptr); static cpl_error_code setCplMessaging(cpl_boolean); @@ -249,23 +250,21 @@ static jobject makeDouble(JNIEnv *env, double val); static jobject makeInteger(JNIEnv *env, int val); static jobject makeJavaFrame(JNIEnv *env, cpl_frame *frame); -static jobject makeJNIRecipe(JNIEnv *env, const cpl_recipe *recipe, - jobject jPluglib); -static jobject makeParameter(JNIEnv *env, cpl_parameter *param, - jobject jRecipe); -static jobject makePluginLibrary(JNIEnv *env, jstring jLocation, - lt_dlhandle dlhandle); +static jobject +makeJNIRecipe(JNIEnv *env, const cpl_recipe *recipe, jobject jPluglib); +static jobject +makeParameter(JNIEnv *env, cpl_parameter *param, jobject jRecipe); +static jobject +makePluginLibrary(JNIEnv *env, jstring jLocation, lt_dlhandle dlhandle); static jobject makeString(JNIEnv *env, const char *val); static jobjectArray makeFrameArray(JNIEnv *env, cpl_frameset *fset); -static jobjectArray makeParameterArray(JNIEnv *env, - cpl_parameterlist *parlist, - jobject jRecipe); +static jobjectArray +makeParameterArray(JNIEnv *env, cpl_parameterlist *parlist, jobject jRecipe); static jthrowable makeLTDLException(JNIEnv *env); - /* * CPLControl native methods. */ @@ -292,7 +291,6 @@ } - /* * LibraryLoader native methods. */ @@ -304,9 +302,9 @@ JNIEXPORT void JNICALL Java_org_eso_cpl_jni_LibraryLoader_nativeLTDLInit(JNIEnv *env, jclass class) { - if (class == NULL || lt_dlinit()) { - (*env)->Throw(env, makeLTDLException(env)); - } + if (class == NULL || lt_dlinit()) { + (*env)->Throw(env, makeLTDLException(env)); + } } @@ -402,27 +400,26 @@ } - /* * JNIRecipe native methods. */ JNIEXPORT jint JNICALL -Java_org_eso_cpl_jni_JNIRecipe_nativeInitialize(JNIEnv *env, jobject this) -{ - EXECUTE_CPL_PLUGIN_FUNC(env, this, initialize) +Java_org_eso_cpl_jni_JNIRecipe_nativeInitialize(JNIEnv *env, jobject this){ + EXECUTE_CPL_PLUGIN_FUNC(env, this, initialize) } JNIEXPORT jint JNICALL -Java_org_eso_cpl_jni_JNIRecipe_nativeDeinitialize(JNIEnv *env, jobject this) + Java_org_eso_cpl_jni_JNIRecipe_nativeDeinitialize(JNIEnv *env, jobject this) { - EXECUTE_CPL_PLUGIN_FUNC(env, this, deinitialize) + EXECUTE_CPL_PLUGIN_FUNC(env, this, deinitialize) } -int doExec(JNIEnv *env, jobject recipe) { - +int +doExec(JNIEnv *env, jobject recipe) +{ jbyteArray jState = NULL; cpl_plugin *plugin = NULL; int ok = 1; @@ -430,13 +427,12 @@ /* Get the pointer to the function to execute. */ ok = ok && - (jState = (*env)->GetObjectField(env, recipe, JNIRecipeStateField)) && - (plugin = (cpl_plugin *) - (*env)->GetByteArrayElements(env, jState, NULL)); + (jState = (*env)->GetObjectField(env, recipe, JNIRecipeStateField)) && + (plugin = + (cpl_plugin *)(*env)->GetByteArrayElements(env, jState, NULL)); /* Execute the function if it is non-NULL. */ if (ok) { - const cpl_plugin_func cplfunc = cpl_plugin_get_exec(plugin); if (cplfunc) { @@ -445,12 +441,10 @@ currentEnv = NULL; if (cpl_plugin_get_type(plugin) & CPL_PLUGIN_TYPE_RECIPE) { - - cpl_recipe* _recipe = (cpl_recipe*)plugin; + cpl_recipe *_recipe = (cpl_recipe *)plugin; /* Ignore a failure here */ (void)cpl_dfs_update_product_header(_recipe->frames); - } } else { @@ -466,20 +460,19 @@ /* Release array elements. */ if (plugin) { - (*env)->ReleaseByteArrayElements(env, jState, (jbyte *) plugin, 0); + (*env)->ReleaseByteArrayElements(env, jState, (jbyte *)plugin, 0); } /* Return the execution status. */ return status; - } JNIEXPORT jint JNICALL -Java_org_eso_cpl_jni_JNIRecipe_nativeExecute(JNIEnv *env, jobject this, +Java_org_eso_cpl_jni_JNIRecipe_nativeExecute(JNIEnv *env, + jobject this, jstring jCurrentDir, jstring jExecDir) { - const char *currentDir; const char *execDir; @@ -531,7 +524,6 @@ } return status; - } @@ -539,7 +531,6 @@ Java_org_eso_cpl_jni_JNIRecipe_nativeGetParameterArray(JNIEnv *env, jobject this) { - int ok = 1; cpl_recipe *recipe = NULL; @@ -553,10 +544,10 @@ */ ok = ok && - (jState = (*env)->GetObjectField(env, this, JNIRecipeStateField)) && - (recipe = (cpl_recipe *) - (*env)->GetByteArrayElements(env, jState, NULL)) && - (parlist = recipe->parameters); + (jState = (*env)->GetObjectField(env, this, JNIRecipeStateField)) && + (recipe = + (cpl_recipe *)(*env)->GetByteArrayElements(env, jState, NULL)) && + (parlist = recipe->parameters); /* @@ -564,7 +555,7 @@ */ if (recipe) { - (*env)->ReleaseByteArrayElements(env, jState, (jbyte *) recipe, 0); + (*env)->ReleaseByteArrayElements(env, jState, (jbyte *)recipe, 0); } @@ -573,7 +564,6 @@ */ return ok ? makeParameterArray(env, parlist, this) : NULL; - } @@ -594,10 +584,10 @@ */ ok = ok && - (jState = (*env)->GetObjectField(env, this, JNIRecipeStateField)) && - (recipe = (cpl_recipe *) - (*env)->GetByteArrayElements(env, jState, NULL)) && - (fset = recipe->frames); + (jState = (*env)->GetObjectField(env, this, JNIRecipeStateField)) && + (recipe = + (cpl_recipe *)(*env)->GetByteArrayElements(env, jState, NULL)) && + (fset = recipe->frames); /* @@ -605,7 +595,7 @@ */ if (recipe) { - (*env)->ReleaseByteArrayElements(env, jState, (jbyte *) recipe, 0); + (*env)->ReleaseByteArrayElements(env, jState, (jbyte *)recipe, 0); } /* @@ -615,15 +605,14 @@ rc = ok ? makeFrameArray(env, fset) : NULL; return rc; - } JNIEXPORT void JNICALL -Java_org_eso_cpl_jni_JNIRecipe_nativeSetFrameArray(JNIEnv *env, jobject this, +Java_org_eso_cpl_jni_JNIRecipe_nativeSetFrameArray(JNIEnv *env, + jobject this, jobjectArray jFrames) { - int ok = 1; cpl_recipe *recipe = NULL; @@ -645,10 +634,9 @@ */ ok = ok && - (jState = (*env)->GetObjectField(env, this, - JNIRecipeStateField)) && - (recipe = (cpl_recipe *) (*env)->GetByteArrayElements(env, jState, - NULL)); + (jState = (*env)->GetObjectField(env, this, JNIRecipeStateField)) && + (recipe = + (cpl_recipe *)(*env)->GetByteArrayElements(env, jState, NULL)); /* * If a frameset exists there, destroy it. @@ -673,11 +661,10 @@ */ if (recipe) { - (*env)->ReleaseByteArrayElements(env, jState, (jbyte *) recipe, 0); + (*env)->ReleaseByteArrayElements(env, jState, (jbyte *)recipe, 0); } return; - } @@ -686,10 +673,10 @@ */ JNIEXPORT void JNICALL -Java_org_eso_cpl_jni_JNIParameterImp_nativeSetValue(JNIEnv *env, jobject this, +Java_org_eso_cpl_jni_JNIParameterImp_nativeSetValue(JNIEnv *env, + jobject this, jobject jVal) { - const char *strVal; int boolVal; @@ -709,14 +696,14 @@ */ ok = ok && - (jState = (*env)->GetObjectField(env, this, - JNIParameterImpStateField)) && - (param_p = (cpl_parameter **) - (*env)->GetByteArrayElements(env, jState, NULL)) && - (param = *param_p); + (jState = + (*env)->GetObjectField(env, this, JNIParameterImpStateField)) && + (param_p = (cpl_parameter **)(*env)->GetByteArrayElements(env, jState, + NULL)) && + (param = *param_p); if (param_p) { - (*env)->ReleaseByteArrayElements(env, jState, (jbyte *) param_p, 0); + (*env)->ReleaseByteArrayElements(env, jState, (jbyte *)param_p, 0); } @@ -726,48 +713,45 @@ switch (cpl_parameter_get_type(param)) { case CPL_TYPE_BOOL: - boolVal = (*env)->CallBooleanMethod(env, jVal, - BooleanBooleanValueMethod); - ok = ok && - !(*env)->ExceptionCheck(env) && - !cpl_parameter_set_bool(param, boolVal); + boolVal = + (*env)->CallBooleanMethod(env, jVal, BooleanBooleanValueMethod); + ok = ok && !(*env)->ExceptionCheck(env) && + !cpl_parameter_set_bool(param, boolVal); break; case CPL_TYPE_INT: - intVal = (*env)->CallIntMethod(env, jVal, - IntegerIntValueMethod); - ok = ok && - !(*env)->ExceptionCheck(env) && - !cpl_parameter_set_int(param, intVal); + intVal = (*env)->CallIntMethod(env, jVal, IntegerIntValueMethod); + ok = ok && !(*env)->ExceptionCheck(env) && + !cpl_parameter_set_int(param, intVal); break; case CPL_TYPE_DOUBLE: - doubleVal = (*env)->CallDoubleMethod(env, jVal, - DoubleDoubleValueMethod); - ok = ok && - !(*env)->ExceptionCheck(env) && - !cpl_parameter_set_double(param, doubleVal); + doubleVal = + (*env)->CallDoubleMethod(env, jVal, DoubleDoubleValueMethod); + ok = ok && !(*env)->ExceptionCheck(env) && + !cpl_parameter_set_double(param, doubleVal); break; case CPL_TYPE_STRING: strVal = NULL; ok = ok && - (strVal = (*env)->GetStringUTFChars(env, (jstring) jVal, NULL)) && - !cpl_parameter_set_string(param, strVal); + (strVal = + (*env)->GetStringUTFChars(env, (jstring)jVal, NULL)) && + !cpl_parameter_set_string(param, strVal); if (strVal) { - (*env)->ReleaseStringUTFChars(env, (jstring) jVal, strVal); + (*env)->ReleaseStringUTFChars(env, (jstring)jVal, strVal); } break; default: (*env)->ThrowNew(env, IllegalStateExceptionClass, - "Unknown parameter type" ); + "Unknown parameter type"); return; } - /* + /* * An error shouldn't happen here, since validation before this stage * should have caught bad values, but better check. */ @@ -778,7 +762,6 @@ } return; - } @@ -789,30 +772,29 @@ JNIEXPORT void JNICALL Java_org_eso_cpl_jni_PluginLibrary_nativeUnload(JNIEnv *env, jobject this) { - jobject jState = NULL; lt_dlhandle *handle_p = NULL; int ok = 1; jthrowable error = NULL; - ok = ok && - (jState = (*env)->GetObjectField(env, this, PluginLibraryStateField)) && - (handle_p = (lt_dlhandle *) - (*env)->GetByteArrayElements(env, jState, NULL)); + ok = + ok && + (jState = (*env)->GetObjectField(env, this, PluginLibraryStateField)) && + (handle_p = + (lt_dlhandle *)(*env)->GetByteArrayElements(env, jState, NULL)); if (ok) { if (!lt_dlclose(*handle_p)) { error = makeLTDLException(env); } } if (handle_p) { - (*env)->ReleaseByteArrayElements(env, jState, (jbyte *) handle_p, 0); + (*env)->ReleaseByteArrayElements(env, jState, (jbyte *)handle_p, 0); } if (error) { (*env)->Throw(env, error); } return; - } @@ -820,8 +802,7 @@ * NativeTest native methods. */ -#if defined (HAVE_ORG_ESO_CPL_TEST_NATIVE_TEST_H) && \ - defined (ENABLE_NATIVE_TESTS) +#if defined(HAVE_ORG_ESO_CPL_TEST_NATIVE_TEST_H) && defined(ENABLE_NATIVE_TESTS) JNIEXPORT void JNICALL Java_org_eso_cpl_test_NativeTest_nativeLTDLTest(JNIEnv *env, jclass class) @@ -848,31 +829,31 @@ * Static functions for determining compile-time constant values. **********************************************************************/ -#define TEST_ID_NAME(Xname) \ - if (!strcmp(idname, #Xname)) { \ - id = Xname; \ - done = 1; \ -} +#define TEST_ID_NAME(Xname) \ + if (!strcmp(idname, #Xname)) { \ + id = Xname; \ + done = 1; \ + } -static cpl_frame_group getFrameGroupID(JNIEnv *env, jobject jFgroup) { +static cpl_frame_group +getFrameGroupID(JNIEnv *env, jobject jFgroup) +{ cpl_frame_group id = CPL_FRAME_GROUP_NONE; jstring jIdname = (jstring)0; const char *idname = (char *)0; int done = 0; int ok = 1; - ok = ok && - jFgroup && - (!(*env)->ExceptionCheck(env)) && - (jIdname = (*env)->GetObjectField(env, jFgroup, FrameGroupIDNameField)) && - (idname = (*env)->GetStringUTFChars(env, jIdname, NULL)); + ok = ok && jFgroup && (!(*env)->ExceptionCheck(env)) && + (jIdname = + (*env)->GetObjectField(env, jFgroup, FrameGroupIDNameField)) && + (idname = (*env)->GetStringUTFChars(env, jIdname, NULL)); if (ok) { TEST_ID_NAME(CPL_FRAME_GROUP_NONE) - else TEST_ID_NAME(CPL_FRAME_GROUP_RAW) - else TEST_ID_NAME(CPL_FRAME_GROUP_CALIB) - else TEST_ID_NAME(CPL_FRAME_GROUP_PRODUCT) - (*env)->ReleaseStringUTFChars(env, jIdname, idname); + else TEST_ID_NAME(CPL_FRAME_GROUP_RAW) else TEST_ID_NAME( + CPL_FRAME_GROUP_CALIB) else TEST_ID_NAME(CPL_FRAME_GROUP_PRODUCT)(*env) + ->ReleaseStringUTFChars(env, jIdname, idname); } if (!done && !(*env)->ExceptionCheck(env)) { (*env)->ThrowNew(env, RuntimeExceptionClass, "Unknown frame group ID"); @@ -881,24 +862,24 @@ } -static cpl_frame_level getFrameLevelID(JNIEnv *env, jobject jFlevel) { +static cpl_frame_level +getFrameLevelID(JNIEnv *env, jobject jFlevel) +{ cpl_frame_level id = CPL_FRAME_LEVEL_NONE; jstring jIdname = (jstring)0; const char *idname = (char *)0; int done = 0; int ok = 1; - ok = ok && - jFlevel && - (!(*env)->ExceptionCheck(env)) && - (jIdname = (*env)->GetObjectField(env, jFlevel, FrameLevelIDNameField)) && - (idname = (*env)->GetStringUTFChars(env, jIdname, NULL)); + ok = ok && jFlevel && (!(*env)->ExceptionCheck(env)) && + (jIdname = + (*env)->GetObjectField(env, jFlevel, FrameLevelIDNameField)) && + (idname = (*env)->GetStringUTFChars(env, jIdname, NULL)); if (ok) { TEST_ID_NAME(CPL_FRAME_LEVEL_NONE) - else TEST_ID_NAME(CPL_FRAME_LEVEL_TEMPORARY) - else TEST_ID_NAME(CPL_FRAME_LEVEL_INTERMEDIATE) - else TEST_ID_NAME(CPL_FRAME_LEVEL_FINAL) - (*env)->ReleaseStringUTFChars(env, jIdname, idname); + else TEST_ID_NAME(CPL_FRAME_LEVEL_TEMPORARY) else TEST_ID_NAME( + CPL_FRAME_LEVEL_INTERMEDIATE) else TEST_ID_NAME(CPL_FRAME_LEVEL_FINAL)(*env) + ->ReleaseStringUTFChars(env, jIdname, idname); } if (!done && (*env)->ExceptionCheck(env)) { (*env)->ThrowNew(env, RuntimeExceptionClass, "Unknown frame level ID"); @@ -907,23 +888,23 @@ } -static cpl_frame_type getFrameTypeID(JNIEnv *env, jobject jFtype) { +static cpl_frame_type +getFrameTypeID(JNIEnv *env, jobject jFtype) +{ cpl_frame_type id = CPL_FRAME_TYPE_NONE; jstring jIdname = (jstring)0; const char *idname = (char *)0; int done = 0; int ok = 1; - ok = ok && - jFtype && - (!(*env)->ExceptionCheck(env)) && - (jIdname = (*env)->GetObjectField(env, jFtype, FrameTypeIDNameField)) && - (idname = (*env)->GetStringUTFChars(env, jIdname, NULL)); + ok = + ok && jFtype && (!(*env)->ExceptionCheck(env)) && + (jIdname = (*env)->GetObjectField(env, jFtype, FrameTypeIDNameField)) && + (idname = (*env)->GetStringUTFChars(env, jIdname, NULL)); if (ok) { TEST_ID_NAME(CPL_FRAME_TYPE_NONE) - else TEST_ID_NAME(CPL_FRAME_TYPE_IMAGE) - else TEST_ID_NAME(CPL_FRAME_TYPE_MATRIX) - else TEST_ID_NAME(CPL_FRAME_TYPE_TABLE) + else TEST_ID_NAME(CPL_FRAME_TYPE_IMAGE) else TEST_ID_NAME( + CPL_FRAME_TYPE_MATRIX) else TEST_ID_NAME(CPL_FRAME_TYPE_TABLE) } if (!done && (*env)->ExceptionCheck(env)) { (*env)->ThrowNew(env, RuntimeExceptionClass, "Unknown frame type ID"); @@ -945,19 +926,20 @@ * and no further JNI methods should be called since an exception is * probably pending. */ #define DEFINE_CLASS(Xname, Xpath) \ - (Xname = (*env)->NewGlobalRef(env, (*env)->FindClass(env, Xpath))) + (Xname = (*env)->NewGlobalRef(env, (*env)->FindClass(env, Xpath))) #define DEFINE_CONSTRUCTOR(Xname, Xclass, Xargs) \ - (Xname = (*env)->GetMethodID(env, Xclass, "", "(" Xargs ")V")) + (Xname = (*env)->GetMethodID(env, Xclass, "", "(" Xargs ")V")) #define DEFINE_METHOD(Xname, Xclass, Xmethod, Xsig) \ - (Xname = (*env)->GetMethodID(env, Xclass, Xmethod, Xsig)) + (Xname = (*env)->GetMethodID(env, Xclass, Xmethod, Xsig)) #define DEFINE_STATICMETHOD(Xname, Xclass, Xmethod, Xsig) \ - (Xname = (*env)->GetStaticMethodID(env, Xclass, Xmethod, Xsig)) + (Xname = (*env)->GetStaticMethodID(env, Xclass, Xmethod, Xsig)) #define DEFINE_FIELD(Xname, Xclass, Xfield, Xsig) \ - (Xname = (*env)->GetFieldID(env, Xclass, Xfield, Xsig)) -#define DEFINE_CONSTANT(Xname, Xclass, Xfield, Xsig) \ - ((constField = (*env)->GetStaticFieldID(env, Xclass, Xfield, Xsig)) && \ - (Xname = (*env)->NewGlobalRef(env, \ - (*env)->GetStaticObjectField(env, Xclass, constField)))) + (Xname = (*env)->GetFieldID(env, Xclass, Xfield, Xsig)) +#define DEFINE_CONSTANT(Xname, Xclass, Xfield, Xsig) \ + ((constField = (*env)->GetStaticFieldID(env, Xclass, Xfield, Xsig)) && \ + (Xname = (*env)->NewGlobalRef(env, \ + (*env)->GetStaticObjectField(env, Xclass, \ + constField)))) /* * Lazily performs initialization of some static variables required here. @@ -965,188 +947,193 @@ * If it fails, there is a zero return and an exception is thrown. */ -static int ensureConstantsSetup(JNIEnv *env) +static int +ensureConstantsSetup(JNIEnv *env) { - jfieldID constField; - if (!isConstantsSetup) { - int ok = 1; - - /* Do the reflection. */ - ok = ok && - DEFINE_CLASS(AssertionErrorClass, "java/lang/AssertionError") && - DEFINE_CLASS(BooleanClass, "java/lang/Boolean") && - DEFINE_CLASS(DoubleClass, "java/lang/Double") && - DEFINE_CLASS(FileClass, "java/io/File") && - DEFINE_CLASS(IllegalArgumentExceptionClass, - "java/lang/IllegalArgumentException") && - DEFINE_CLASS(IllegalStateExceptionClass, - "java/lang/IllegalStateException") && - DEFINE_CLASS(IntegerClass, "java/lang/Integer") && - DEFINE_CLASS(LinkageErrorClass, "java/lang/LinkageError") && - DEFINE_CLASS(NullPointerExceptionClass, - "java/lang/NullPointerException") && - DEFINE_CLASS(ObjectClass, "java/lang/Object") && - DEFINE_CLASS(PrintStreamClass, "java/io/PrintStream") && - DEFINE_CLASS(RuntimeExceptionClass, "java/lang/RuntimeException") && - DEFINE_CLASS(StringClass, "java/lang/String") && - - DEFINE_CLASS(BadAPIPluginClass, - "org/eso/cpl/jni/OtherPlugin$BadAPIPlugin") && - DEFINE_CLASS(CPLControlClass, - "org/eso/cpl/jni/CPLControl") && - DEFINE_CLASS(CPLExceptionClass, "org/eso/cpl/CPLException") && - DEFINE_CLASS(EnumConstraintClass, "org/eso/cpl/EnumConstraint") && - DEFINE_CLASS(FrameClass, "org/eso/cpl/Frame") && - DEFINE_CLASS(FrameGroupClass, "org/eso/cpl/FrameGroup") && - DEFINE_CLASS(FrameLevelClass, "org/eso/cpl/FrameLevel") && - DEFINE_CLASS(FrameTypeClass, "org/eso/cpl/FrameType") && - DEFINE_CLASS(JNIParameterImpClass, "org/eso/cpl/jni/JNIParameterImp") && - DEFINE_CLASS(JNIRecipeClass, "org/eso/cpl/jni/JNIRecipe") && - DEFINE_CLASS(LTDLExceptionClass, "org/eso/cpl/jni/LTDLException") && - DEFINE_CLASS(NonRecipePluginClass, - "org/eso/cpl/jni/OtherPlugin$NonRecipePlugin") && - DEFINE_CLASS(OtherPluginClass, "org/eso/cpl/jni/OtherPlugin") && - DEFINE_CLASS(ParameterClass, "org/eso/cpl/Parameter") && - DEFINE_CLASS(ParameterTypeClass, "org/eso/cpl/ParameterType") && - DEFINE_CLASS(ParameterValueExceptionClass, - "org/eso/cpl/ParameterValueException") && - DEFINE_CLASS(PluginLibraryClass, "org/eso/cpl/jni/PluginLibrary") && - DEFINE_CLASS(RangeConstraintClass, "org/eso/cpl/RangeConstraint") && - - DEFINE_CONSTRUCTOR(BadAPIPluginConstructor, BadAPIPluginClass, - "Ljava/lang/String;II") && - DEFINE_CONSTRUCTOR(DoubleConstructor, DoubleClass, "D") && - DEFINE_CONSTRUCTOR(EnumConstraintConstructor, EnumConstraintClass, - "[Ljava/lang/Object;") && - DEFINE_CONSTRUCTOR(FileConstructor, FileClass, "Ljava/lang/String;") && - DEFINE_CONSTRUCTOR(FrameConstructor, FrameClass, "Ljava/io/File;") && - DEFINE_CONSTRUCTOR(IntegerConstructor, IntegerClass, "I") && - DEFINE_CONSTRUCTOR(JNIParameterImpConstructor, JNIParameterImpClass, - "[BLorg/eso/cpl/jni/JNIRecipe;" - "Lorg/eso/cpl/ParameterType;" - "Lorg/eso/cpl/ParameterConstraint;" - "Ljava/lang/Object;") && - DEFINE_CONSTRUCTOR(JNIRecipeConstructor, JNIRecipeClass, - "[BLorg/eso/cpl/jni/PluginLibrary;") && - DEFINE_CONSTRUCTOR(LTDLExceptionConstructor, LTDLExceptionClass, + jfieldID constField; + if (!isConstantsSetup) { + int ok = 1; + + /* Do the reflection. */ + ok = + ok && + DEFINE_CLASS(AssertionErrorClass, "java/lang/AssertionError") && + DEFINE_CLASS(BooleanClass, "java/lang/Boolean") && + DEFINE_CLASS(DoubleClass, "java/lang/Double") && + DEFINE_CLASS(FileClass, "java/io/File") && + DEFINE_CLASS(IllegalArgumentExceptionClass, + "java/lang/IllegalArgumentException") && + DEFINE_CLASS(IllegalStateExceptionClass, + "java/lang/IllegalStateException") && + DEFINE_CLASS(IntegerClass, "java/lang/Integer") && + DEFINE_CLASS(LinkageErrorClass, "java/lang/LinkageError") && + DEFINE_CLASS(NullPointerExceptionClass, + "java/lang/NullPointerException") && + DEFINE_CLASS(ObjectClass, "java/lang/Object") && + DEFINE_CLASS(PrintStreamClass, "java/io/PrintStream") && + DEFINE_CLASS(RuntimeExceptionClass, "java/lang/RuntimeException") && + DEFINE_CLASS(StringClass, "java/lang/String") && + + DEFINE_CLASS(BadAPIPluginClass, + "org/eso/cpl/jni/OtherPlugin$BadAPIPlugin") && + DEFINE_CLASS(CPLControlClass, "org/eso/cpl/jni/CPLControl") && + DEFINE_CLASS(CPLExceptionClass, "org/eso/cpl/CPLException") && + DEFINE_CLASS(EnumConstraintClass, "org/eso/cpl/EnumConstraint") && + DEFINE_CLASS(FrameClass, "org/eso/cpl/Frame") && + DEFINE_CLASS(FrameGroupClass, "org/eso/cpl/FrameGroup") && + DEFINE_CLASS(FrameLevelClass, "org/eso/cpl/FrameLevel") && + DEFINE_CLASS(FrameTypeClass, "org/eso/cpl/FrameType") && + DEFINE_CLASS(JNIParameterImpClass, + "org/eso/cpl/jni/JNIParameterImp") && + DEFINE_CLASS(JNIRecipeClass, "org/eso/cpl/jni/JNIRecipe") && + DEFINE_CLASS(LTDLExceptionClass, "org/eso/cpl/jni/LTDLException") && + DEFINE_CLASS(NonRecipePluginClass, + "org/eso/cpl/jni/OtherPlugin$NonRecipePlugin") && + DEFINE_CLASS(OtherPluginClass, "org/eso/cpl/jni/OtherPlugin") && + DEFINE_CLASS(ParameterClass, "org/eso/cpl/Parameter") && + DEFINE_CLASS(ParameterTypeClass, "org/eso/cpl/ParameterType") && + DEFINE_CLASS(ParameterValueExceptionClass, + "org/eso/cpl/ParameterValueException") && + DEFINE_CLASS(PluginLibraryClass, "org/eso/cpl/jni/PluginLibrary") && + DEFINE_CLASS(RangeConstraintClass, "org/eso/cpl/RangeConstraint") && + + DEFINE_CONSTRUCTOR(BadAPIPluginConstructor, BadAPIPluginClass, + "Ljava/lang/String;II") && + DEFINE_CONSTRUCTOR(DoubleConstructor, DoubleClass, "D") && + DEFINE_CONSTRUCTOR(EnumConstraintConstructor, EnumConstraintClass, + "[Ljava/lang/Object;") && + DEFINE_CONSTRUCTOR(FileConstructor, FileClass, + "Ljava/lang/String;") && + DEFINE_CONSTRUCTOR(FrameConstructor, FrameClass, + "Ljava/io/File;") && + DEFINE_CONSTRUCTOR(IntegerConstructor, IntegerClass, "I") && + DEFINE_CONSTRUCTOR(JNIParameterImpConstructor, JNIParameterImpClass, + "[BLorg/eso/cpl/jni/JNIRecipe;" + "Lorg/eso/cpl/ParameterType;" + "Lorg/eso/cpl/ParameterConstraint;" + "Ljava/lang/Object;") && + DEFINE_CONSTRUCTOR(JNIRecipeConstructor, JNIRecipeClass, + "[BLorg/eso/cpl/jni/PluginLibrary;") && + DEFINE_CONSTRUCTOR(LTDLExceptionConstructor, LTDLExceptionClass, + "Ljava/lang/String;") && + DEFINE_CONSTRUCTOR(NonRecipePluginConstructor, NonRecipePluginClass, + "Ljava/lang/String;") && + DEFINE_CONSTRUCTOR(ParameterConstructor, ParameterClass, + "Lorg/eso/cpl/ParameterImp;") && + DEFINE_CONSTRUCTOR( + PluginLibraryConstructor, PluginLibraryClass, + "[BLjava/lang/String;[Lorg/eso/cpl/jni/JNIRecipe;" + "[Lorg/eso/cpl/jni/OtherPlugin;") && + DEFINE_CONSTRUCTOR(RangeConstraintConstructor, RangeConstraintClass, + "Lorg/eso/cpl/ParameterType;" + "Ljava/lang/Object;Ljava/lang/Object;") && + + DEFINE_METHOD(BooleanBooleanValueMethod, BooleanClass, + "booleanValue", "()Z") && + DEFINE_METHOD(DoubleDoubleValueMethod, DoubleClass, "doubleValue", + "()D") && + DEFINE_METHOD(IntegerIntValueMethod, IntegerClass, "intValue", + "()I") && + DEFINE_METHOD(PrintStreamPrintlnMethod, PrintStreamClass, "println", + "(Ljava/lang/String;)V") && + + DEFINE_STATICMETHOD(CPLControlErrMessageMethod, CPLControlClass, + "errMessage", "(Ljava/lang/String;)V") && + DEFINE_STATICMETHOD(CPLControlLogMessageMethod, CPLControlClass, + "logMessage", + "(Ljava/lang/String;Ljava/lang/String;I)V") && + DEFINE_STATICMETHOD(CPLControlOutMessageMethod, CPLControlClass, + "outMessage", "(Ljava/lang/String;)V") && + + DEFINE_FIELD(FrameCanonicalPathField, FrameClass, "canonicalPath_", + "Ljava/lang/String;") && + DEFINE_FIELD(FrameGroupField, FrameClass, "group_", + "Lorg/eso/cpl/FrameGroup;") && + DEFINE_FIELD(FrameLevelField, FrameClass, "level_", + "Lorg/eso/cpl/FrameLevel;") && + DEFINE_FIELD(FrameTagField, FrameClass, "tag_", + "Ljava/lang/String;") && + DEFINE_FIELD(FrameTypeField, FrameClass, "type_", + "Lorg/eso/cpl/FrameType;") && + DEFINE_FIELD(FrameGroupIDNameField, FrameGroupClass, "idName_", + "Ljava/lang/String;") && + DEFINE_FIELD(FrameLevelIDNameField, FrameLevelClass, "idName_", + "Ljava/lang/String;") && + DEFINE_FIELD(FrameTypeIDNameField, FrameTypeClass, "idName_", + "Ljava/lang/String;") && + DEFINE_FIELD(JNIParameterImpStateField, JNIParameterImpClass, + "nativeState_", "[B") && + DEFINE_FIELD(JNIParameterImpContextField, JNIParameterImpClass, + "context_", "Ljava/lang/String;") && + DEFINE_FIELD(JNIParameterImpHelpField, JNIParameterImpClass, + "help_", "Ljava/lang/String;") && + DEFINE_FIELD(JNIParameterImpNameField, JNIParameterImpClass, + "name_", "Ljava/lang/String;") && + DEFINE_FIELD(JNIParameterImpTagField, JNIParameterImpClass, "tag_", "Ljava/lang/String;") && - DEFINE_CONSTRUCTOR(NonRecipePluginConstructor, NonRecipePluginClass, + DEFINE_FIELD(JNIRecipeAuthorField, JNIRecipeClass, "author_", "Ljava/lang/String;") && - DEFINE_CONSTRUCTOR(ParameterConstructor, ParameterClass, - "Lorg/eso/cpl/ParameterImp;") && - DEFINE_CONSTRUCTOR(PluginLibraryConstructor, PluginLibraryClass, - "[BLjava/lang/String;[Lorg/eso/cpl/jni/JNIRecipe;" - "[Lorg/eso/cpl/jni/OtherPlugin;") && - DEFINE_CONSTRUCTOR(RangeConstraintConstructor, RangeConstraintClass, - "Lorg/eso/cpl/ParameterType;" - "Ljava/lang/Object;Ljava/lang/Object;") && - - DEFINE_METHOD(BooleanBooleanValueMethod, BooleanClass, - "booleanValue", "()Z") && - DEFINE_METHOD(DoubleDoubleValueMethod, DoubleClass, - "doubleValue", "()D") && - DEFINE_METHOD(IntegerIntValueMethod, IntegerClass, - "intValue", "()I") && - DEFINE_METHOD(PrintStreamPrintlnMethod, PrintStreamClass, - "println", "(Ljava/lang/String;)V") && - - DEFINE_STATICMETHOD(CPLControlErrMessageMethod, CPLControlClass, - "errMessage", "(Ljava/lang/String;)V") && - DEFINE_STATICMETHOD(CPLControlLogMessageMethod, CPLControlClass, - "logMessage", - "(Ljava/lang/String;Ljava/lang/String;I)V") && - DEFINE_STATICMETHOD(CPLControlOutMessageMethod, CPLControlClass, - "outMessage", "(Ljava/lang/String;)V") && - - DEFINE_FIELD(FrameCanonicalPathField, FrameClass, - "canonicalPath_", "Ljava/lang/String;") && - DEFINE_FIELD(FrameGroupField, FrameClass, - "group_", "Lorg/eso/cpl/FrameGroup;") && - DEFINE_FIELD(FrameLevelField, FrameClass, - "level_", "Lorg/eso/cpl/FrameLevel;") && - DEFINE_FIELD(FrameTagField, FrameClass, - "tag_", "Ljava/lang/String;") && - DEFINE_FIELD(FrameTypeField, FrameClass, - "type_", "Lorg/eso/cpl/FrameType;") && - DEFINE_FIELD(FrameGroupIDNameField, FrameGroupClass, - "idName_", "Ljava/lang/String;") && - DEFINE_FIELD(FrameLevelIDNameField, FrameLevelClass, - "idName_", "Ljava/lang/String;") && - DEFINE_FIELD(FrameTypeIDNameField, FrameTypeClass, - "idName_", "Ljava/lang/String;") && - DEFINE_FIELD(JNIParameterImpStateField, JNIParameterImpClass, - "nativeState_", "[B") && - DEFINE_FIELD(JNIParameterImpContextField, JNIParameterImpClass, - "context_", "Ljava/lang/String;") && - DEFINE_FIELD(JNIParameterImpHelpField, JNIParameterImpClass, - "help_", "Ljava/lang/String;") && - DEFINE_FIELD(JNIParameterImpNameField, JNIParameterImpClass, - "name_", "Ljava/lang/String;") && - DEFINE_FIELD(JNIParameterImpTagField, JNIParameterImpClass, - "tag_", "Ljava/lang/String;") && - DEFINE_FIELD(JNIRecipeAuthorField, JNIRecipeClass, - "author_", "Ljava/lang/String;") && - DEFINE_FIELD(JNIRecipeCopyrightField, JNIRecipeClass, - "copyright_", "Ljava/lang/String;") && - DEFINE_FIELD(JNIRecipeDescriptionField, JNIRecipeClass, - "description_", "Ljava/lang/String;") && - DEFINE_FIELD(JNIRecipeEmailField, JNIRecipeClass, - "email_", "Ljava/lang/String;") && - DEFINE_FIELD(JNIRecipeNameField, JNIRecipeClass, - "name_", "Ljava/lang/String;") && - DEFINE_FIELD(JNIRecipeStateField, JNIRecipeClass, - "nativeState_", "[B") && - DEFINE_FIELD(JNIRecipeSynopsisField, JNIRecipeClass, - "synopsis_", "Ljava/lang/String;") && - DEFINE_FIELD(JNIRecipeVersionField, JNIRecipeClass, - "version_", "J") && - DEFINE_FIELD(PluginLibraryStateField, PluginLibraryClass, - "nativeState_", "[B") && - - DEFINE_CONSTANT(BooleanFALSEConstant, BooleanClass, - "FALSE", "Ljava/lang/Boolean;") && - DEFINE_CONSTANT(BooleanTRUEConstant, BooleanClass, - "TRUE", "Ljava/lang/Boolean;") && - DEFINE_CONSTANT(FrameGroupRAWConstant, FrameGroupClass, - "RAW", "Lorg/eso/cpl/FrameGroup;") && - DEFINE_CONSTANT(FrameGroupCALIBConstant, FrameGroupClass, - "CALIB", "Lorg/eso/cpl/FrameGroup;") && - DEFINE_CONSTANT(FrameGroupPRODUCTConstant, FrameGroupClass, - "PRODUCT", "Lorg/eso/cpl/FrameGroup;") && - DEFINE_CONSTANT(FrameLevelTEMPORARYConstant, FrameLevelClass, - "TEMPORARY", "Lorg/eso/cpl/FrameLevel;") && - DEFINE_CONSTANT(FrameLevelINTERMEDIATEConstant, FrameLevelClass, - "INTERMEDIATE", "Lorg/eso/cpl/FrameLevel;") && - DEFINE_CONSTANT(FrameLevelFINALConstant, FrameLevelClass, - "FINAL", "Lorg/eso/cpl/FrameLevel;") && - DEFINE_CONSTANT(FrameTypeIMAGEConstant, FrameTypeClass, - "IMAGE", "Lorg/eso/cpl/FrameType;") && - DEFINE_CONSTANT(FrameTypeMATRIXConstant, FrameTypeClass, - "MATRIX", "Lorg/eso/cpl/FrameType;") && - DEFINE_CONSTANT(FrameTypeTABLEConstant, FrameTypeClass, - "TABLE", "Lorg/eso/cpl/FrameType;") && - DEFINE_CONSTANT(ParameterTypeBOOLConstant, ParameterTypeClass, - "BOOL", "Lorg/eso/cpl/ParameterType;") && - DEFINE_CONSTANT(ParameterTypeDOUBLEConstant, ParameterTypeClass, - "DOUBLE", "Lorg/eso/cpl/ParameterType;") && - DEFINE_CONSTANT(ParameterTypeINTConstant, ParameterTypeClass, - "INT", "Lorg/eso/cpl/ParameterType;") && - DEFINE_CONSTANT(ParameterTypeSTRINGConstant, ParameterTypeClass, - "STRING", "Lorg/eso/cpl/ParameterType;") && + DEFINE_FIELD(JNIRecipeCopyrightField, JNIRecipeClass, "copyright_", + "Ljava/lang/String;") && + DEFINE_FIELD(JNIRecipeDescriptionField, JNIRecipeClass, + "description_", "Ljava/lang/String;") && + DEFINE_FIELD(JNIRecipeEmailField, JNIRecipeClass, "email_", + "Ljava/lang/String;") && + DEFINE_FIELD(JNIRecipeNameField, JNIRecipeClass, "name_", + "Ljava/lang/String;") && + DEFINE_FIELD(JNIRecipeStateField, JNIRecipeClass, "nativeState_", + "[B") && + DEFINE_FIELD(JNIRecipeSynopsisField, JNIRecipeClass, "synopsis_", + "Ljava/lang/String;") && + DEFINE_FIELD(JNIRecipeVersionField, JNIRecipeClass, "version_", + "J") && + DEFINE_FIELD(PluginLibraryStateField, PluginLibraryClass, + "nativeState_", "[B") && + + DEFINE_CONSTANT(BooleanFALSEConstant, BooleanClass, "FALSE", + "Ljava/lang/Boolean;") && + DEFINE_CONSTANT(BooleanTRUEConstant, BooleanClass, "TRUE", + "Ljava/lang/Boolean;") && + DEFINE_CONSTANT(FrameGroupRAWConstant, FrameGroupClass, "RAW", + "Lorg/eso/cpl/FrameGroup;") && + DEFINE_CONSTANT(FrameGroupCALIBConstant, FrameGroupClass, "CALIB", + "Lorg/eso/cpl/FrameGroup;") && + DEFINE_CONSTANT(FrameGroupPRODUCTConstant, FrameGroupClass, + "PRODUCT", "Lorg/eso/cpl/FrameGroup;") && + DEFINE_CONSTANT(FrameLevelTEMPORARYConstant, FrameLevelClass, + "TEMPORARY", "Lorg/eso/cpl/FrameLevel;") && + DEFINE_CONSTANT(FrameLevelINTERMEDIATEConstant, FrameLevelClass, + "INTERMEDIATE", "Lorg/eso/cpl/FrameLevel;") && + DEFINE_CONSTANT(FrameLevelFINALConstant, FrameLevelClass, "FINAL", + "Lorg/eso/cpl/FrameLevel;") && + DEFINE_CONSTANT(FrameTypeIMAGEConstant, FrameTypeClass, "IMAGE", + "Lorg/eso/cpl/FrameType;") && + DEFINE_CONSTANT(FrameTypeMATRIXConstant, FrameTypeClass, "MATRIX", + "Lorg/eso/cpl/FrameType;") && + DEFINE_CONSTANT(FrameTypeTABLEConstant, FrameTypeClass, "TABLE", + "Lorg/eso/cpl/FrameType;") && + DEFINE_CONSTANT(ParameterTypeBOOLConstant, ParameterTypeClass, + "BOOL", "Lorg/eso/cpl/ParameterType;") && + DEFINE_CONSTANT(ParameterTypeDOUBLEConstant, ParameterTypeClass, + "DOUBLE", "Lorg/eso/cpl/ParameterType;") && + DEFINE_CONSTANT(ParameterTypeINTConstant, ParameterTypeClass, "INT", + "Lorg/eso/cpl/ParameterType;") && + DEFINE_CONSTANT(ParameterTypeSTRINGConstant, ParameterTypeClass, + "STRING", "Lorg/eso/cpl/ParameterType;") && - (VersionString = (*env)->NewGlobalRef(env, - (*env)->NewStringUTF(env, JAVACPL_VERSION))) && + (VersionString = (*env)->NewGlobalRef( + env, (*env)->NewStringUTF(env, JAVACPL_VERSION))) && - 1; + 1; - /* If there was a failure but we don't have an exception to show + /* If there was a failure but we don't have an exception to show * for it, throw an exception here. */ - if (!ok && !(*env)->ExceptionOccurred(env)) { - (*env)->ThrowNew(env, RuntimeExceptionClass, "Reflection trouble"); - } - isConstantsSetup = ok; - } - return isConstantsSetup; + if (!ok && !(*env)->ExceptionOccurred(env)) { + (*env)->ThrowNew(env, RuntimeExceptionClass, "Reflection trouble"); + } + isConstantsSetup = ok; + } + return isConstantsSetup; } #undef DEFINE_CLASS @@ -1157,30 +1144,35 @@ #undef DEFINE_CONSTANT -static int ensureHandlersSetup(JNIEnv *env) { - if (!isHandlersSetup) { - int ok = 1; - - cpl_init(CPL_INIT_DEFAULT); - - if (cpl_error_get_code()) { - cpl_msg_warning("Java CPL", "CPL initialization failed: '%s' at %s\n", - cpl_error_get_message(), cpl_error_get_where()); - } else { - (void)setCplMessaging(CPL_TRUE); - } +static int +ensureHandlersSetup(JNIEnv *env) +{ + if (!isHandlersSetup) { + int ok = 1; + + cpl_init(CPL_INIT_DEFAULT); + + if (cpl_error_get_code()) { + cpl_msg_warning("Java CPL", + "CPL initialization failed: '%s' at %s\n", + cpl_error_get_message(), cpl_error_get_where()); + } + else { + (void)setCplMessaging(CPL_TRUE); + } #ifndef GASGANO_HAS_NO_CPL_EXCEPTION_HANDLER - if (cpl_error_get_code() && !(*env)->ExceptionCheck(env)) { - /* The only option for handling the error at this point is to throw + if (cpl_error_get_code() && !(*env)->ExceptionCheck(env)) { + /* The only option for handling the error at this point is to throw an exception. */ - (*env)->ThrowNew(env, CPLExceptionClass, "CPL initialization failed"); - } + (*env)->ThrowNew(env, CPLExceptionClass, + "CPL initialization failed"); + } #endif - inistate = cpl_errorstate_get(); - isHandlersSetup = ok; - } - return isHandlersSetup; + inistate = cpl_errorstate_get(); + isHandlersSetup = ok; + } + return isHandlersSetup; } @@ -1189,8 +1181,9 @@ * cext's message handling facilities. */ -static cpl_error_code setCplMessaging(cpl_boolean startlog) { - +static cpl_error_code +setCplMessaging(cpl_boolean startlog) +{ cpl_errorstate prestate = cpl_errorstate_get(); /* cx_log_level_flags cx_level = CX_LOG_LEVEL_DEBUG; */ @@ -1208,107 +1201,109 @@ cpl_msg_set_width(132); cpl_msg_set_indentation(4); cpl_msg_set_level(cpl_level); - if (startlog) cpl_msg_set_log_level(cpl_log_level); /* Do this only once */ + if (startlog) + cpl_msg_set_log_level(cpl_log_level); /* Do this only once */ if (!cpl_errorstate_is_equal(prestate)) { - cpl_msg_warning("Java CPL", "CPL-messaging initialization failed:\n"); cpl_errorstate_dump(prestate, CPL_FALSE, NULL); return cpl_error_set_where(cpl_func); - } else { + } + else { return CPL_ERROR_NONE; } } -static void out_message_handler(const cxchar *msg) { - JNIEnv *env; - jstring jMsg = (jstring)0; - int ok = 1; - /* java method cannot be called from multiple threads +static void +out_message_handler(const cxchar *msg) +{ + JNIEnv *env; + jstring jMsg = (jstring)0; + int ok = 1; + /* java method cannot be called from multiple threads * for unknown reasons a lock is insufficient too */ #ifdef _OPENMP - ok = omp_get_thread_num() == 0; + ok = omp_get_thread_num() == 0; #endif - ok = ok && - (env = currentEnv); - if (msg) { - ok = ok && - (jMsg = (*env)->NewStringUTF(env, msg)); - } - if (ok) { - (*env)->CallStaticVoidMethod(env, CPLControlClass, - CPLControlOutMessageMethod, jMsg); - } - else { - fprintf(stdout, "Lost output message: %s\n", msg ? msg : "null"); - } + ok = ok && (env = currentEnv); + if (msg) { + ok = ok && (jMsg = (*env)->NewStringUTF(env, msg)); + } + if (ok) { + (*env)->CallStaticVoidMethod(env, CPLControlClass, + CPLControlOutMessageMethod, jMsg); + } + else { + fprintf(stdout, "Lost output message: %s\n", msg ? msg : "null"); + } } -static void err_message_handler(const cxchar *msg) { - JNIEnv *env; - jstring jMsg = (jstring)0; - int ok = 1; - /* java method cannot be called from multiple threads +static void +err_message_handler(const cxchar *msg) +{ + JNIEnv *env; + jstring jMsg = (jstring)0; + int ok = 1; + /* java method cannot be called from multiple threads * for unknown reasons a lock is insufficient too */ #ifdef _OPENMP - ok = omp_get_thread_num() == 0; + ok = omp_get_thread_num() == 0; #endif - ok = ok && - (env = currentEnv); - if (msg) { - ok = ok && - (jMsg = (*env)->NewStringUTF(env, msg)); - } - if (ok) { - (*env)->CallStaticVoidMethod(env, CPLControlClass, - CPLControlErrMessageMethod, jMsg); - } - else { - fprintf(stderr, "Lost error message: %s\n", msg ? msg : "null"); - } + ok = ok && (env = currentEnv); + if (msg) { + ok = ok && (jMsg = (*env)->NewStringUTF(env, msg)); + } + if (ok) { + (*env)->CallStaticVoidMethod(env, CPLControlClass, + CPLControlErrMessageMethod, jMsg); + } + else { + fprintf(stderr, "Lost error message: %s\n", msg ? msg : "null"); + } } -static void default_log_message_handler(const cxchar *domain, - cx_log_level_flags flags, - const cxchar *msg, cxptr ptr) { - JNIEnv *env = currentEnv; - jstring jDomain; - jstring jMsg; - int ok = 1; - /* java method cannot be called from multiple threads +static void +default_log_message_handler(const cxchar *domain, + cx_log_level_flags flags, + const cxchar *msg, + cxptr ptr) +{ + JNIEnv *env = currentEnv; + jstring jDomain; + jstring jMsg; + int ok = 1; + /* java method cannot be called from multiple threads * for unknown reasons a lock is insufficient too */ #ifdef _OPENMP - ok = omp_get_thread_num() == 0; + ok = omp_get_thread_num() == 0; #endif - ok = ok && env; - jMsg = NULL; - if (msg) { - ok = ok && - (jMsg = (*env)->NewStringUTF(env, msg)); - } - jDomain = NULL; - if (domain) { - ok = ok && - (jDomain = (*env)->NewStringUTF(env, domain)); - } - if (ok) { - (*env)->CallStaticVoidMethod(env, CPLControlClass, - CPLControlLogMessageMethod, jDomain, jMsg, - (jint) flags); - } - else { - /* Use ptr to avoid compiler warning */ - char * nullmsg = cpl_sprintf("null (ptr=%p)", (const void*)ptr); - fprintf(stderr, "Lost log message: %s\n", msg ? msg : nullmsg); - cpl_free(nullmsg); - } + ok = ok && env; + jMsg = NULL; + if (msg) { + ok = ok && (jMsg = (*env)->NewStringUTF(env, msg)); + } + jDomain = NULL; + if (domain) { + ok = ok && (jDomain = (*env)->NewStringUTF(env, domain)); + } + if (ok) { + (*env)->CallStaticVoidMethod(env, CPLControlClass, + CPLControlLogMessageMethod, jDomain, jMsg, + (jint)flags); + } + else { + /* Use ptr to avoid compiler warning */ + char *nullmsg = cpl_sprintf("null (ptr=%p)", (const void *)ptr); + fprintf(stderr, "Lost log message: %s\n", msg ? msg : nullmsg); + cpl_free(nullmsg); + } } @@ -1317,39 +1312,41 @@ * the most recent error to occur. */ -static jthrowable makeLTDLException(JNIEnv *env) { - const char *msg; - jstring jMsg; - jthrowable error = (jthrowable)0; +static jthrowable +makeLTDLException(JNIEnv *env) +{ + const char *msg; + jstring jMsg; + jthrowable error = (jthrowable)0; - /* Check that some constants have been initialized. If they have not + /* Check that some constants have been initialized. If they have not * for some reason, throw the exception which describes why not. */ - if (!ensureConstantsSetup(env)) { - error = (*env)->ExceptionOccurred(env); - (*env)->ExceptionClear(env); - return error; - } - - /* Get the error message. */ - msg = lt_dlerror(); - if (!msg) { - msg = "no error"; - } - jMsg = (*env)->NewStringUTF(env, msg); - if (jMsg) { - error = (*env)->NewObject(env, LTDLExceptionClass, - LTDLExceptionConstructor, jMsg); - } + if (!ensureConstantsSetup(env)) { + error = (*env)->ExceptionOccurred(env); + (*env)->ExceptionClear(env); + return error; + } - /* If for some reason construction of the exception failed, return the + /* Get the error message. */ + msg = lt_dlerror(); + if (!msg) { + msg = "no error"; + } + jMsg = (*env)->NewStringUTF(env, msg); + if (jMsg) { + error = (*env)->NewObject(env, LTDLExceptionClass, + LTDLExceptionConstructor, jMsg); + } + + /* If for some reason construction of the exception failed, return the * reason for its failure, and clear the exception. */ - if (!error) { - error = (*env)->ExceptionOccurred(env); - (*env)->ExceptionClear(env); - } + if (!error) { + error = (*env)->ExceptionOccurred(env); + (*env)->ExceptionClear(env); + } - /* Return the exception. */ - return error; + /* Return the exception. */ + return error; } @@ -1357,8 +1354,9 @@ * Constructs and returns a PluginLibrary object from a DLL handle. */ -static jobject makePluginLibrary(JNIEnv *env, jstring jLocation, - lt_dlhandle dlhandle) { +static jobject +makePluginLibrary(JNIEnv *env, jstring jLocation, lt_dlhandle dlhandle) +{ jobject jPluglib = (jobject)0; #ifdef GASGANO_HAS_NO_CPL_EXCEPTION_HANDLER @@ -1367,12 +1365,12 @@ #else if (cpl_error_get_code() || setCplMessaging(CPL_FALSE) != CPL_ERROR_NONE) { cpl_msg_warning("Java CPL", "Not loading plugins due to pre-existing " - "CPL error\n"); - } else + "CPL error\n"); + } + else #endif if (1) { - - const char * cpl_version; + const char *cpl_version; int (*list_function)(cpl_pluginlist *); const cpl_plugin *plugin; cpl_pluginlist *pluginlist; @@ -1395,8 +1393,9 @@ /* Cast from object pointer to function pointer is not allowed in ISO C. Circumvent the cast with a union... */ - union cast_dl_ { - void * address; + union cast_dl_ + { + void *address; int (*function)(cpl_pluginlist *); } cast_dl; @@ -1408,7 +1407,7 @@ return jPluglib; } - cast_dl.address = (void*)lt_dlsym(dlhandle, "cpl_plugin_get_info"); + cast_dl.address = (void *)lt_dlsym(dlhandle, "cpl_plugin_get_info"); list_function = cast_dl.function; if (list_function == NULL) { @@ -1420,14 +1419,13 @@ } cpl_version = cpl_version_get_version(); - if (cpl_version != NULL && - strcmp(PACKAGE_VERSION, cpl_version)) { + if (cpl_version != NULL && strcmp(PACKAGE_VERSION, cpl_version)) { /* The plugin has caused functions from libcplcore.so that have not already been loaded, to be loaded from the wrong libcplcore.so, f.ex. the libcplcore.so used to compile the plugin */ #ifndef GASGANO_HAS_NO_CPL_EXCEPTION_HANDLER - (*env)->ThrowNew(env, CPLExceptionClass, "CPL " PACKAGE_VERSION - " library version error"); + (*env)->ThrowNew(env, CPLExceptionClass, + "CPL " PACKAGE_VERSION " library version error"); #endif return jPluglib; } @@ -1435,7 +1433,7 @@ /* Populate a plugin list with all the plugins known by this DLL. * list_function returns an int, zero on success and one on failure. */ pluginlist = cpl_pluginlist_new(); - ok = ok && !( (*list_function)(pluginlist) ); + ok = ok && !((*list_function)(pluginlist)); /* Split the list of plugins into two mutually exclusive sublists; * usable recipes and the rest. */ @@ -1455,16 +1453,17 @@ nother = nplugin - nrec; /* Construct a new PluginLibrary object which will contain the recipes. */ - ok = ok && - (jState = (*env)->NewByteArray(env, sizeof(lt_dlhandle))) && - (state = (*env)->GetByteArrayElements(env, jState, NULL)) && - (jRecipes = (*env)->NewObjectArray(env, nrec, JNIRecipeClass, NULL)) && - (jOthers = (*env)->NewObjectArray(env, nother, OtherPluginClass, NULL)) && - (jPluglib = (*env)->NewObject(env, PluginLibraryClass, - PluginLibraryConstructor, jState, - jLocation, jRecipes, jOthers)); + ok = ok && (jState = (*env)->NewByteArray(env, sizeof(lt_dlhandle))) && + (state = (*env)->GetByteArrayElements(env, jState, NULL)) && + (jRecipes = + (*env)->NewObjectArray(env, nrec, JNIRecipeClass, NULL)) && + (jOthers = (*env)->NewObjectArray(env, nother, OtherPluginClass, + NULL)) && + (jPluglib = (*env)->NewObject(env, PluginLibraryClass, + PluginLibraryConstructor, jState, + jLocation, jRecipes, jOthers)); if (state && ok) { - *((lt_dlhandle *) state) = dlhandle; + *((lt_dlhandle *)state) = dlhandle; (*env)->ReleaseByteArrayElements(env, jState, state, 0); } @@ -1480,13 +1479,13 @@ if ((papi == CPL_PLUGIN_API) && (ptype & CPL_PLUGIN_TYPE_RECIPE)) { const cpl_recipe *recipe = (const cpl_recipe *)plugin; jobject jRecipe = (jobject)0; - ok = ok && - (jRecipe = makeJNIRecipe(env, recipe, jPluglib)); + ok = ok && (jRecipe = makeJNIRecipe(env, recipe, jPluglib)); if (ok) { (*env)->SetObjectArrayElement(env, jRecipes, irec, jRecipe); } irec++; - } else { + } + else { jstring jName; jobject jOther = (jobject)0; const char *name = cpl_plugin_get_name(plugin); @@ -1495,19 +1494,19 @@ * unless we know the API versions match, but it's probably OK... */ jName = (*env)->NewStringUTF(env, name); if (papi != CPL_PLUGIN_API) { - ok = ok && + ok = + ok && (jOther = (*env)->NewObject(env, BadAPIPluginClass, BadAPIPluginConstructor, - jName, - (jint) CPL_PLUGIN_API, - (jint) papi)); + jName, (jint)CPL_PLUGIN_API, + (jint)papi)); } else { cx_assert((ptype & CPL_PLUGIN_TYPE_RECIPE) == 0); ok = ok && - (jOther = (*env)->NewObject(env, NonRecipePluginClass, - NonRecipePluginConstructor, - jName)); + (jOther = (*env)->NewObject(env, NonRecipePluginClass, + NonRecipePluginConstructor, + jName)); } if (ok) { (*env)->SetObjectArrayElement(env, jOthers, iother, jOther); @@ -1515,9 +1514,9 @@ iother++; } } - cx_assert( irec == nrec ); - cx_assert( iother == nother ); - cx_assert( nother + nrec == nplugin ); + cx_assert(irec == nrec); + cx_assert(iother == nother); + cx_assert(nother + nrec == nplugin); /* Free workspace. */ cpl_pluginlist_delete(pluginlist); @@ -1532,42 +1531,41 @@ * Turns a CPL frameset into an array of java Frame objects. */ -static jobjectArray makeFrameArray(JNIEnv *env, cpl_frameset *fset) { - jobject jFrame = (jobject)0; - jobjectArray jFrames = (jobjectArray)0; - cpl_frame *frame; - jsize ifrm; - jsize nfrm; - int ok = 1; - - /* Determine the size of the frameset. */ - nfrm = cpl_frameset_get_size(fset); - - /* Construct an empty array to hold the new Frame objects. */ - ok = ok && - (jFrames = (*env)->NewObjectArray(env, nfrm, FrameClass, NULL)); +static jobjectArray +makeFrameArray(JNIEnv *env, cpl_frameset *fset) +{ + jobject jFrame = (jobject)0; + jobjectArray jFrames = (jobjectArray)0; + cpl_frame *frame; + jsize ifrm; + jsize nfrm; + int ok = 1; + + /* Determine the size of the frameset. */ + nfrm = cpl_frameset_get_size(fset); + + /* Construct an empty array to hold the new Frame objects. */ + ok = ok && (jFrames = (*env)->NewObjectArray(env, nfrm, FrameClass, NULL)); - /* Populate the array with new Frame objects constructed from the frames + /* Populate the array with new Frame objects constructed from the frames * in the frameset. */ - ifrm = 0; + ifrm = 0; - cpl_frameset_iterator *it = cpl_frameset_iterator_new(fset); + cpl_frameset_iterator *it = cpl_frameset_iterator_new(fset); - while (ok && (frame = cpl_frameset_iterator_get(it))) - { - ok = ok && - (jFrame = makeJavaFrame(env, frame)); - if (ok) { - (*env)->SetObjectArrayElement(env, jFrames, ifrm++, jFrame); - } + while (ok && (frame = cpl_frameset_iterator_get(it))) { + ok = ok && (jFrame = makeJavaFrame(env, frame)); + if (ok) { + (*env)->SetObjectArrayElement(env, jFrames, ifrm++, jFrame); + } - cpl_frameset_iterator_advance(it, 1); - } + cpl_frameset_iterator_advance(it, 1); + } - cpl_frameset_iterator_delete(it); + cpl_frameset_iterator_delete(it); - /* Return the array. */ - return ok ? jFrames : NULL; + /* Return the array. */ + return ok ? jFrames : NULL; } @@ -1575,136 +1573,141 @@ * Turns a CPL frame into a java Frame object. */ -static jobject makeJavaFrame(JNIEnv *env, cpl_frame *frame) { - jobject jFrame; - const char *filename; - const char *tag; - jstring jFilename; - jobject jFile; - jstring jTag; - jobject jFtype; - jobject jFgroup; - jobject jFlevel; - int frameType; - int frameGroup; - int frameLevel; - - /* Get the frame's filename as a java string. */ - filename = cpl_frame_get_filename(frame); - jFilename = filename ? (*env)->NewStringUTF(env, filename) : NULL; - jFile = jFilename ? (*env)->NewObject(env, FileClass, FileConstructor, - jFilename) - : NULL; - - /* Get the tag as a java string. */ - tag = cpl_frame_get_tag(frame); - jTag = tag ? (*env)->NewStringUTF(env, tag) : NULL; +static jobject +makeJavaFrame(JNIEnv *env, cpl_frame *frame) +{ + jobject jFrame; + const char *filename; + const char *tag; + jstring jFilename; + jobject jFile; + jstring jTag; + jobject jFtype; + jobject jFgroup; + jobject jFlevel; + int frameType; + int frameGroup; + int frameLevel; + + /* Get the frame's filename as a java string. */ + filename = cpl_frame_get_filename(frame); + jFilename = filename ? (*env)->NewStringUTF(env, filename) : NULL; + jFile = jFilename + ? (*env)->NewObject(env, FileClass, FileConstructor, jFilename) + : NULL; + + /* Get the tag as a java string. */ + tag = cpl_frame_get_tag(frame); + jTag = tag ? (*env)->NewStringUTF(env, tag) : NULL; - /* Get the frame type. */ - jFtype = NULL; + /* Get the frame type. */ + jFtype = NULL; - /* In order to handle the possible addition of "new" frame types without + /* In order to handle the possible addition of "new" frame types without throwing an exception, the default case behaves the same as type NONE. */ - frameType = cpl_frame_get_type(frame); - switch (frameType) { - case CPL_FRAME_TYPE_NONE: - jFtype = NULL; - break; - case CPL_FRAME_TYPE_IMAGE: - jFtype = FrameTypeIMAGEConstant; - break; - case CPL_FRAME_TYPE_MATRIX: - jFtype = FrameTypeMATRIXConstant; - break; - case CPL_FRAME_TYPE_TABLE: - jFtype = FrameTypeTABLEConstant; - break; - default: - /* + frameType = cpl_frame_get_type(frame); + switch (frameType) { + case CPL_FRAME_TYPE_NONE: + jFtype = NULL; + break; + case CPL_FRAME_TYPE_IMAGE: + jFtype = FrameTypeIMAGEConstant; + break; + case CPL_FRAME_TYPE_MATRIX: + jFtype = FrameTypeMATRIXConstant; + break; + case CPL_FRAME_TYPE_TABLE: + jFtype = FrameTypeTABLEConstant; + break; + default: + /* (*env)->ThrowNew(env, RuntimeExceptionClass, "Unknown frame type"); return NULL; map unexpected values to NULL */ - cpl_msg_warning("Java CPL", "Frame %s has unexpected frame type: %d\n", - filename, frameType); - jFtype = NULL; - } + cpl_msg_warning("Java CPL", + "Frame %s has unexpected frame type: %d\n", + filename, frameType); + jFtype = NULL; + } - /* Get the frame group. */ - jFgroup = NULL; + /* Get the frame group. */ + jFgroup = NULL; - /* + /* In order to handle the possible addition of "new" frame groups without throwing an exception, the default case behaves the same as group NONE. */ - frameGroup = cpl_frame_get_group(frame); - switch (frameGroup) { - case CPL_FRAME_GROUP_NONE: - jFgroup = NULL; - break; - case CPL_FRAME_GROUP_RAW: - jFgroup = FrameGroupRAWConstant; - break; - case CPL_FRAME_GROUP_CALIB: - jFgroup = FrameGroupCALIBConstant; - break; - case CPL_FRAME_GROUP_PRODUCT: - jFgroup = FrameGroupPRODUCTConstant; - break; - default: - /* + frameGroup = cpl_frame_get_group(frame); + switch (frameGroup) { + case CPL_FRAME_GROUP_NONE: + jFgroup = NULL; + break; + case CPL_FRAME_GROUP_RAW: + jFgroup = FrameGroupRAWConstant; + break; + case CPL_FRAME_GROUP_CALIB: + jFgroup = FrameGroupCALIBConstant; + break; + case CPL_FRAME_GROUP_PRODUCT: + jFgroup = FrameGroupPRODUCTConstant; + break; + default: + /* (*env)->ThrowNew(env, RuntimeExceptionClass, "Unknown frame group"); return NULL; */ - cpl_msg_warning("Java CPL", "Frame %s has unexpected frame group: %d\n", - filename, frameGroup); - jFgroup = NULL; - } + cpl_msg_warning("Java CPL", + "Frame %s has unexpected frame group: %d\n", + filename, frameGroup); + jFgroup = NULL; + } - /* Get the frame level. */ - /* + /* Get the frame level. */ + /* In order to handle the possible addition of "new" frame levels without throwing an exception, the default case behaves the same as level NONE. */ - jFlevel = NULL; - frameLevel = cpl_frame_get_level(frame); - switch (frameLevel) { - case CPL_FRAME_LEVEL_NONE: - jFlevel = NULL; - break; - case CPL_FRAME_LEVEL_TEMPORARY: - jFlevel = FrameLevelTEMPORARYConstant; - break; - case CPL_FRAME_LEVEL_INTERMEDIATE: - jFlevel = FrameLevelINTERMEDIATEConstant; - break; - case CPL_FRAME_LEVEL_FINAL: - jFlevel = FrameLevelFINALConstant; - break; - default: - /* + jFlevel = NULL; + frameLevel = cpl_frame_get_level(frame); + switch (frameLevel) { + case CPL_FRAME_LEVEL_NONE: + jFlevel = NULL; + break; + case CPL_FRAME_LEVEL_TEMPORARY: + jFlevel = FrameLevelTEMPORARYConstant; + break; + case CPL_FRAME_LEVEL_INTERMEDIATE: + jFlevel = FrameLevelINTERMEDIATEConstant; + break; + case CPL_FRAME_LEVEL_FINAL: + jFlevel = FrameLevelFINALConstant; + break; + default: + /* (*env)->ThrowNew(env, RuntimeExceptionClass, "Unknown frame level"); return NULL; */ - cpl_msg_warning("Java CPL", "Frame %s has unexpected frame level: %d\n", - filename, frameLevel); - jFlevel = NULL; - } + cpl_msg_warning("Java CPL", + "Frame %s has unexpected frame level: %d\n", + filename, frameLevel); + jFlevel = NULL; + } - /* Construct a new Frame object and populate its fields with the + /* Construct a new Frame object and populate its fields with the * values we have calculated. */ - jFrame = (*env)->NewObject(env, FrameClass, FrameConstructor, jFile); - (*env)->SetObjectField(env, jFrame, FrameTagField, jTag); - (*env)->SetObjectField(env, jFrame, FrameTypeField, jFtype); - (*env)->SetObjectField(env, jFrame, FrameGroupField, jFgroup); - (*env)->SetObjectField(env, jFrame, FrameLevelField, jFlevel); + jFrame = (*env)->NewObject(env, FrameClass, FrameConstructor, jFile); + (*env)->SetObjectField(env, jFrame, FrameTagField, jTag); + (*env)->SetObjectField(env, jFrame, FrameTypeField, jFtype); + (*env)->SetObjectField(env, jFrame, FrameGroupField, jFgroup); + (*env)->SetObjectField(env, jFrame, FrameLevelField, jFlevel); - /* Return the populated object. */ - return jFrame; + /* Return the populated object. */ + return jFrame; } @@ -1712,72 +1715,75 @@ * Turns an array of java Frame objects into a CPL frameset. */ -static cpl_frameset *makeFrameSet(JNIEnv *env, jobjectArray jFrames) { - cpl_frameset *fset = (cpl_frameset *)0; - cpl_frame *frame = (cpl_frame *)0; - jobject jFrame = (jobject)0; - jsize nfrm; - jsize ifrm; - int ok = 1; - - /* Get the size of the frame array. */ - nfrm = (*env)->GetArrayLength(env, jFrames); - if ((*env)->ExceptionCheck(env)) { - return NULL; - } - ok = ok && - (fset = cpl_frameset_new()); - for (ifrm = 0; ok && ifrm < nfrm; ifrm++) { - ok = ok && - (jFrame = (*env)->GetObjectArrayElement(env, jFrames, ifrm)) && - (frame = makeCplFrame(env, jFrame)) && - (!cpl_frameset_insert(fset, frame)); - if (!jFrame && !(*env)->ExceptionCheck(env)) { - (*env)->ThrowNew(env, NullPointerExceptionClass, NULL); - return NULL; - } - } - return ok ? fset : NULL; -} - - -static cpl_frame *makeCplFrame(JNIEnv *env, jobject jFrame) { - cpl_frame *frame; - jstring jFilename; - jstring jTag; - jobject jFtype; - jobject jFgroup; - jobject jFlevel; - - frame = cpl_frame_new(); - if (!frame) { - return NULL; - } - jFilename = (*env)->GetObjectField(env, jFrame, FrameCanonicalPathField); - if (jFilename) { - const char *filename = (*env)->GetStringUTFChars(env, jFilename, NULL); - cpl_frame_set_filename(frame, filename); - (*env)->ReleaseStringUTFChars(env, jFilename, filename); - } - jTag = (*env)->GetObjectField(env, jFrame, FrameTagField); - if (jTag) { - const char *tag = (*env)->GetStringUTFChars(env, jTag, NULL); - cpl_frame_set_tag(frame, tag); - (*env)->ReleaseStringUTFChars(env, jTag, tag); - } - jFtype = (*env)->GetObjectField(env, jFrame, FrameTypeField); - if (jFtype) { - cpl_frame_set_type(frame, getFrameTypeID(env, jFtype)); - } - jFgroup = (*env)->GetObjectField(env, jFrame, FrameGroupField); - if (jFgroup) { - cpl_frame_set_group(frame, getFrameGroupID(env, jFgroup)); - } - jFlevel = (*env)->GetObjectField(env, jFrame, FrameLevelField); - if (jFlevel) { - cpl_frame_set_level(frame, getFrameLevelID(env, jFlevel)); - } - return frame; +static cpl_frameset * +makeFrameSet(JNIEnv *env, jobjectArray jFrames) +{ + cpl_frameset *fset = (cpl_frameset *)0; + cpl_frame *frame = (cpl_frame *)0; + jobject jFrame = (jobject)0; + jsize nfrm; + jsize ifrm; + int ok = 1; + + /* Get the size of the frame array. */ + nfrm = (*env)->GetArrayLength(env, jFrames); + if ((*env)->ExceptionCheck(env)) { + return NULL; + } + ok = ok && (fset = cpl_frameset_new()); + for (ifrm = 0; ok && ifrm < nfrm; ifrm++) { + ok = ok && + (jFrame = (*env)->GetObjectArrayElement(env, jFrames, ifrm)) && + (frame = makeCplFrame(env, jFrame)) && + (!cpl_frameset_insert(fset, frame)); + if (!jFrame && !(*env)->ExceptionCheck(env)) { + (*env)->ThrowNew(env, NullPointerExceptionClass, NULL); + return NULL; + } + } + return ok ? fset : NULL; +} + + +static cpl_frame * +makeCplFrame(JNIEnv *env, jobject jFrame) +{ + cpl_frame *frame; + jstring jFilename; + jstring jTag; + jobject jFtype; + jobject jFgroup; + jobject jFlevel; + + frame = cpl_frame_new(); + if (!frame) { + return NULL; + } + jFilename = (*env)->GetObjectField(env, jFrame, FrameCanonicalPathField); + if (jFilename) { + const char *filename = (*env)->GetStringUTFChars(env, jFilename, NULL); + cpl_frame_set_filename(frame, filename); + (*env)->ReleaseStringUTFChars(env, jFilename, filename); + } + jTag = (*env)->GetObjectField(env, jFrame, FrameTagField); + if (jTag) { + const char *tag = (*env)->GetStringUTFChars(env, jTag, NULL); + cpl_frame_set_tag(frame, tag); + (*env)->ReleaseStringUTFChars(env, jTag, tag); + } + jFtype = (*env)->GetObjectField(env, jFrame, FrameTypeField); + if (jFtype) { + cpl_frame_set_type(frame, getFrameTypeID(env, jFtype)); + } + jFgroup = (*env)->GetObjectField(env, jFrame, FrameGroupField); + if (jFgroup) { + cpl_frame_set_group(frame, getFrameGroupID(env, jFgroup)); + } + jFlevel = (*env)->GetObjectField(env, jFrame, FrameLevelField); + if (jFlevel) { + cpl_frame_set_level(frame, getFrameLevelID(env, jFlevel)); + } + return frame; } @@ -1787,56 +1793,57 @@ * NULL. */ -static jobject makeJNIRecipe(JNIEnv *env, const cpl_recipe *recipe, - jobject jPluglib) { - int ok = 1; - jbyteArray jState = NULL; - cpl_recipe *state = NULL; - jobject jRecipe = NULL; - - /* Copy the recipe struct into a java byte array. */ - ok = ok && - (jState = (*env)->NewByteArray(env, sizeof(cpl_recipe))) && - (state = (cpl_recipe *) (*env)->GetByteArrayElements(env, jState, NULL)); - if (ok) { - *state = *recipe; - } - if (state) { - (*env)->ReleaseByteArrayElements(env, jState, (jbyte *) state, 0); - } - - /* Construct a new JNIRecipe object. */ - ok = ok && - (jRecipe = (*env)->NewObject(env, JNIRecipeClass, JNIRecipeConstructor, - jState, jPluglib)); +static jobject +makeJNIRecipe(JNIEnv *env, const cpl_recipe *recipe, jobject jPluglib) +{ + int ok = 1; + jbyteArray jState = NULL; + cpl_recipe *state = NULL; + jobject jRecipe = NULL; + + /* Copy the recipe struct into a java byte array. */ + ok = + ok && (jState = (*env)->NewByteArray(env, sizeof(cpl_recipe))) && + (state = (cpl_recipe *)(*env)->GetByteArrayElements(env, jState, NULL)); + if (ok) { + *state = *recipe; + } + if (state) { + (*env)->ReleaseByteArrayElements(env, jState, (jbyte *)state, 0); + } - /* Populate the JNIRecipe object's fields from the contents of the + /* Construct a new JNIRecipe object. */ + ok = ok && + (jRecipe = (*env)->NewObject(env, JNIRecipeClass, JNIRecipeConstructor, + jState, jPluglib)); + + /* Populate the JNIRecipe object's fields from the contents of the * cpl_recipe structure. * TODO: the struct members should not be used directly, instead * they should be accessed through functions of the form: * cpl_plugin_get_name() * cpl_plugin_get_version(), etc. */ - if (ok) { - const cpl_plugin *plugin = (const cpl_plugin *) recipe; - (*env)->SetObjectField(env, jRecipe, JNIRecipeAuthorField, - (*env)->NewStringUTF(env, plugin->author)); - (*env)->SetObjectField(env, jRecipe, JNIRecipeCopyrightField, - (*env)->NewStringUTF(env, plugin->copyright)); - (*env)->SetObjectField(env, jRecipe, JNIRecipeDescriptionField, - (*env)->NewStringUTF(env, plugin->description)); - (*env)->SetObjectField(env, jRecipe, JNIRecipeEmailField, - (*env)->NewStringUTF(env, plugin->email)); - (*env)->SetObjectField(env, jRecipe, JNIRecipeNameField, - (*env)->NewStringUTF(env, plugin->name)); - (*env)->SetObjectField(env, jRecipe, JNIRecipeSynopsisField, - (*env)->NewStringUTF(env, plugin->synopsis)); - (*env)->SetLongField(env, jRecipe, JNIRecipeVersionField, - (jlong) plugin->version); - } + if (ok) { + const cpl_plugin *plugin = (const cpl_plugin *)recipe; + (*env)->SetObjectField(env, jRecipe, JNIRecipeAuthorField, + (*env)->NewStringUTF(env, plugin->author)); + (*env)->SetObjectField(env, jRecipe, JNIRecipeCopyrightField, + (*env)->NewStringUTF(env, plugin->copyright)); + (*env)->SetObjectField(env, jRecipe, JNIRecipeDescriptionField, + (*env)->NewStringUTF(env, plugin->description)); + (*env)->SetObjectField(env, jRecipe, JNIRecipeEmailField, + (*env)->NewStringUTF(env, plugin->email)); + (*env)->SetObjectField(env, jRecipe, JNIRecipeNameField, + (*env)->NewStringUTF(env, plugin->name)); + (*env)->SetObjectField(env, jRecipe, JNIRecipeSynopsisField, + (*env)->NewStringUTF(env, plugin->synopsis)); + (*env)->SetLongField(env, jRecipe, JNIRecipeVersionField, + (jlong)plugin->version); + } - /* Return the new object. */ - return ok ? jRecipe : NULL; + /* Return the new object. */ + return ok ? jRecipe : NULL; } @@ -1845,36 +1852,35 @@ * of a cpl_parameterlist structure. */ -static jobjectArray makeParameterArray(JNIEnv *env, cpl_parameterlist *parlist, - jobject jRecipe) { - int ok = 1; - int npar; - int ip; - cpl_parameter *param; - jobject jParam = (jobject)0; - jobjectArray jParray = NULL; - - /* Null in, null out. */ - if (!parlist || (*env)->ExceptionCheck(env)) { - return NULL; - } - - /* Assemble a java array of all the cpl_parameters in this cpl_parameterlist. */ - ok = ok && - ((npar = cpl_parameterlist_get_size(parlist)) >= 0) && - (jParray = (*env)->NewObjectArray(env, npar, ParameterClass, NULL)); - ip = 0; - for (param = cpl_parameterlist_get_first(parlist); ok && (param != NULL); - param = cpl_parameterlist_get_next(parlist)) { - ok = ok && - (jParam = makeParameter(env, param, jRecipe)); - if (ok) { - (*env)->SetObjectArrayElement(env, jParray, ip++, jParam); - } - } +static jobjectArray +makeParameterArray(JNIEnv *env, cpl_parameterlist *parlist, jobject jRecipe) +{ + int ok = 1; + int npar; + int ip; + cpl_parameter *param; + jobject jParam = (jobject)0; + jobjectArray jParray = NULL; - /* Return the populated array. */ - return ok ? jParray : NULL; + /* Null in, null out. */ + if (!parlist || (*env)->ExceptionCheck(env)) { + return NULL; + } + + /* Assemble a java array of all the cpl_parameters in this cpl_parameterlist. */ + ok = ok && ((npar = cpl_parameterlist_get_size(parlist)) >= 0) && + (jParray = (*env)->NewObjectArray(env, npar, ParameterClass, NULL)); + ip = 0; + for (param = cpl_parameterlist_get_first(parlist); ok && (param != NULL); + param = cpl_parameterlist_get_next(parlist)) { + ok = ok && (jParam = makeParameter(env, param, jRecipe)); + if (ok) { + (*env)->SetObjectArrayElement(env, jParray, ip++, jParam); + } + } + + /* Return the populated array. */ + return ok ? jParray : NULL; } @@ -1882,160 +1888,170 @@ * Constructs a Parameter object from a cpl_parameter in a cpl_parameterlist. */ -static jobject makeParameter(JNIEnv *env, cpl_parameter *param, - jobject jRecipe) { - cpl_type ptype; - cpl_parameter_class pclass; - jbyteArray jState = NULL; - jbyte *state = NULL; - jobject jPtype = NULL; - jobject jInitval = NULL; - jobject jConstraint = NULL; - jobject jMin; - jobject jMax; - jobjectArray jOptions; - jobject jOpt; - jobject jParimp; - int ptrsz; - int nopt; - int iopt; - - /* Prepare a byte array containing a pointer to the parameter object. */ - ptrsz = sizeof(cpl_parameter *); - jState = (*env)->NewByteArray(env, ptrsz); - if (jState) { - state = (*env)->GetByteArrayElements(env, jState, NULL); - memcpy(state, ¶m, ptrsz); - (*env)->ReleaseByteArrayElements(env, jState, state, 0); - } - else { - return NULL; - } - - /* Ascertain the parameter type and its initial value. */ - ptype = cpl_parameter_get_type(param); - switch (ptype) { - case CPL_TYPE_BOOL: - jPtype = ParameterTypeBOOLConstant; - jInitval = makeBoolean(cpl_parameter_get_default_bool(param)); - break; - case CPL_TYPE_INT: - jPtype = ParameterTypeINTConstant; - jInitval = makeInteger(env, cpl_parameter_get_default_int(param)); - break; - case CPL_TYPE_DOUBLE: - jPtype = ParameterTypeDOUBLEConstant; - jInitval = makeDouble(env, cpl_parameter_get_default_double(param)); - break; - case CPL_TYPE_STRING: - jPtype = ParameterTypeSTRINGConstant; - jInitval = makeString(env, cpl_parameter_get_default_string(param)); - break; - default: - (*env)->ThrowNew(env, IllegalStateExceptionClass, - "Unknown parameter type" ); - return NULL; - } - - /* Construct a suitable ParameterConstraint object. */ - pclass = cpl_parameter_get_class(param); - switch (pclass) { - - /* Value class - no restrictions. */ - case CPL_PARAMETER_CLASS_VALUE: - jConstraint = NULL; - break; - - /* Range class - minimum and maximum values are set. */ - case CPL_PARAMETER_CLASS_RANGE: - jMin = NULL; - jMax = NULL; - switch (ptype) { - case CPL_TYPE_INT: - jMin = makeInteger(env, - cpl_parameter_get_range_min_int(param)); - jMax = makeInteger(env, - cpl_parameter_get_range_max_int(param)); - break; - case CPL_TYPE_DOUBLE: - jMin = makeDouble(env, - cpl_parameter_get_range_min_double(param)); - jMax = makeDouble(env, - cpl_parameter_get_range_max_double(param)); - break; - default: - (*env)->ThrowNew(env, IllegalStateExceptionClass, - "Bad type for range parameter" ); - return NULL; - } - jConstraint = (*env)->NewObject(env, RangeConstraintClass, - RangeConstraintConstructor, - jPtype, jMin, jMax); - if (!jConstraint) { +static jobject +makeParameter(JNIEnv *env, cpl_parameter *param, jobject jRecipe) +{ + cpl_type ptype; + cpl_parameter_class pclass; + jbyteArray jState = NULL; + jbyte *state = NULL; + jobject jPtype = NULL; + jobject jInitval = NULL; + jobject jConstraint = NULL; + jobject jMin; + jobject jMax; + jobjectArray jOptions; + jobject jOpt; + jobject jParimp; + int ptrsz; + int nopt; + int iopt; + + /* Prepare a byte array containing a pointer to the parameter object. */ + ptrsz = sizeof(cpl_parameter *); + jState = (*env)->NewByteArray(env, ptrsz); + if (jState) { + state = (*env)->GetByteArrayElements(env, jState, NULL); + memcpy(state, ¶m, ptrsz); + (*env)->ReleaseByteArrayElements(env, jState, state, 0); + } + else { + return NULL; + } + + /* Ascertain the parameter type and its initial value. */ + ptype = cpl_parameter_get_type(param); + switch (ptype) { + case CPL_TYPE_BOOL: + jPtype = ParameterTypeBOOLConstant; + jInitval = makeBoolean(cpl_parameter_get_default_bool(param)); + break; + case CPL_TYPE_INT: + jPtype = ParameterTypeINTConstant; + jInitval = makeInteger(env, cpl_parameter_get_default_int(param)); + break; + case CPL_TYPE_DOUBLE: + jPtype = ParameterTypeDOUBLEConstant; + jInitval = makeDouble(env, cpl_parameter_get_default_double(param)); + break; + case CPL_TYPE_STRING: + jPtype = ParameterTypeSTRINGConstant; + jInitval = makeString(env, cpl_parameter_get_default_string(param)); + break; + default: + (*env)->ThrowNew(env, IllegalStateExceptionClass, + "Unknown parameter type"); return NULL; - } - break; + } - /* Enum class - a discrete list of options is set. */ - case CPL_PARAMETER_CLASS_ENUM: - nopt = cpl_parameter_get_enum_size(param); - jOptions = (*env)->NewObjectArray(env, nopt, ObjectClass, NULL); - jOpt = NULL; - for (iopt = 0; iopt < nopt; iopt++) { + /* Construct a suitable ParameterConstraint object. */ + pclass = cpl_parameter_get_class(param); + switch (pclass) { + /* Value class - no restrictions. */ + case CPL_PARAMETER_CLASS_VALUE: + jConstraint = NULL; + break; + + /* Range class - minimum and maximum values are set. */ + case CPL_PARAMETER_CLASS_RANGE: + jMin = NULL; + jMax = NULL; switch (ptype) { - case CPL_TYPE_INT: - jOpt = makeInteger(env, - cpl_parameter_get_enum_int(param, iopt)); - break; - case CPL_TYPE_DOUBLE: - jOpt = makeDouble(env, - cpl_parameter_get_enum_double(param, iopt)); - break; - case CPL_TYPE_STRING: - jOpt = makeString(env, - cpl_parameter_get_enum_string(param, iopt)); - break; - default: - (*env)->ThrowNew(env, AssertionErrorClass, NULL); - return NULL; + case CPL_TYPE_INT: + jMin = makeInteger(env, + cpl_parameter_get_range_min_int(param)); + jMax = makeInteger(env, + cpl_parameter_get_range_max_int(param)); + break; + case CPL_TYPE_DOUBLE: + jMin = + makeDouble(env, + cpl_parameter_get_range_min_double(param)); + jMax = + makeDouble(env, + cpl_parameter_get_range_max_double(param)); + break; + default: + (*env)->ThrowNew(env, IllegalStateExceptionClass, + "Bad type for range parameter"); + return NULL; } - if ((*env)->ExceptionCheck(env)) { - return NULL; + jConstraint = (*env)->NewObject(env, RangeConstraintClass, + RangeConstraintConstructor, jPtype, + jMin, jMax); + if (!jConstraint) { + return NULL; } - (*env)->SetObjectArrayElement(env, jOptions, iopt, jOpt); - } - jConstraint = (*env)->NewObject(env, EnumConstraintClass, - EnumConstraintConstructor, jOptions); - break; - - /* Unknown. */ - default: - (*env)->ThrowNew(env, IllegalStateExceptionClass, - "Unknown parameter class"); - return NULL; - } - - /* Construct a JNIParameterImp object from the objects we have made. */ - jParimp = (*env)->NewObject(env, JNIParameterImpClass, - JNIParameterImpConstructor, jState, jRecipe, - jPtype, jConstraint, jInitval); - if (!jParimp) { - return NULL; - } - - /* Initialise the remaining fields in the ParameterImp. */ - (*env)->SetObjectField(env, jParimp, JNIParameterImpContextField, - (*env)->NewStringUTF(env, cpl_parameter_get_context(param))); - (*env)->SetObjectField(env, jParimp, JNIParameterImpHelpField, - (*env)->NewStringUTF(env, cpl_parameter_get_help(param))); - (*env)->SetObjectField(env, jParimp, JNIParameterImpNameField, - (*env)->NewStringUTF(env, cpl_parameter_get_name(param))); - (*env)->SetObjectField(env, jParimp, JNIParameterImpTagField, - (*env)->NewStringUTF(env, cpl_parameter_get_tag(param))); - - /* Make and return a Parameter object from the ParameterImp. */ - return (*env)->NewObject(env, ParameterClass, ParameterConstructor, - jParimp); + break; + + /* Enum class - a discrete list of options is set. */ + case CPL_PARAMETER_CLASS_ENUM: + nopt = cpl_parameter_get_enum_size(param); + jOptions = (*env)->NewObjectArray(env, nopt, ObjectClass, NULL); + jOpt = NULL; + for (iopt = 0; iopt < nopt; iopt++) { + switch (ptype) { + case CPL_TYPE_INT: + jOpt = + makeInteger(env, cpl_parameter_get_enum_int(param, + iopt)); + break; + case CPL_TYPE_DOUBLE: + jOpt = makeDouble(env, + cpl_parameter_get_enum_double(param, + iopt)); + break; + case CPL_TYPE_STRING: + jOpt = makeString(env, + cpl_parameter_get_enum_string(param, + iopt)); + break; + default: + (*env)->ThrowNew(env, AssertionErrorClass, NULL); + return NULL; + } + if ((*env)->ExceptionCheck(env)) { + return NULL; + } + (*env)->SetObjectArrayElement(env, jOptions, iopt, jOpt); + } + jConstraint = + (*env)->NewObject(env, EnumConstraintClass, + EnumConstraintConstructor, jOptions); + break; + + /* Unknown. */ + default: + (*env)->ThrowNew(env, IllegalStateExceptionClass, + "Unknown parameter class"); + return NULL; + } + + /* Construct a JNIParameterImp object from the objects we have made. */ + jParimp = + (*env)->NewObject(env, JNIParameterImpClass, JNIParameterImpConstructor, + jState, jRecipe, jPtype, jConstraint, jInitval); + if (!jParimp) { + return NULL; + } + + /* Initialise the remaining fields in the ParameterImp. */ + (*env)->SetObjectField(env, jParimp, JNIParameterImpContextField, + (*env)->NewStringUTF(env, cpl_parameter_get_context( + param))); + (*env)->SetObjectField(env, jParimp, JNIParameterImpHelpField, + (*env)->NewStringUTF(env, + cpl_parameter_get_help(param))); + (*env)->SetObjectField(env, jParimp, JNIParameterImpNameField, + (*env)->NewStringUTF(env, + cpl_parameter_get_name(param))); + (*env)->SetObjectField(env, jParimp, JNIParameterImpTagField, + (*env)->NewStringUTF(env, + cpl_parameter_get_tag(param))); + + /* Make and return a Parameter object from the ParameterImp. */ + return (*env)->NewObject(env, ParameterClass, ParameterConstructor, + jParimp); } @@ -2043,8 +2059,10 @@ * Makes a java Boolean object from a boolean (int) value. */ -static jobject makeBoolean(int val) { - return val ? BooleanTRUEConstant : BooleanFALSEConstant; +static jobject +makeBoolean(int val) +{ + return val ? BooleanTRUEConstant : BooleanFALSEConstant; } @@ -2052,9 +2070,10 @@ * Makes a java Integer object from an int value. */ -static jobject makeInteger(JNIEnv *env, int val) { - return (*env)->NewObject(env, IntegerClass, IntegerConstructor, - (jint) val); +static jobject +makeInteger(JNIEnv *env, int val) +{ + return (*env)->NewObject(env, IntegerClass, IntegerConstructor, (jint)val); } @@ -2062,9 +2081,10 @@ * Makes a java Double object from a double value. */ -static jobject makeDouble(JNIEnv *env, double val) { - return (*env)->NewObject(env, DoubleClass, DoubleConstructor, - (jdouble) val); +static jobject +makeDouble(JNIEnv *env, double val) +{ + return (*env)->NewObject(env, DoubleClass, DoubleConstructor, (jdouble)val); } @@ -2072,8 +2092,10 @@ * Makes a java String object from a char* value. */ -static jobject makeString(JNIEnv *env, const char *val) { - return (*env)->NewStringUTF(env, val); +static jobject +makeString(JNIEnv *env, const char *val) +{ + return (*env)->NewStringUTF(env, val); } #undef EXECUTE_CPL_PLUGIN_FUNC diff -Nru cpl-7.1.4+ds/cpljava/Makefile.am cpl-7.2.2+ds/cpljava/Makefile.am --- cpl-7.1.4+ds/cpljava/Makefile.am 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cpljava/Makefile.am 2022-04-29 14:56:02.000000000 +0000 @@ -1,7 +1,7 @@ ## Process this file with automake to produce Makefile.in ## This file is part of the ESO Common Pipeline Library -## Copyright (C) 2001-2017 European Southern Observatory +## Copyright (C) 2001-2022 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 @@ -28,6 +28,8 @@ endif +SUBDIRS = tests + AM_CPPFLAGS = $(CPLCORE_INCLUDES) $(CPLUI_INCLUDES) $(CPLDFS_INCLUDES) \ $(CX_INCLUDES) $(JAVA_INCLUDES) $(INCLTDL) diff -Nru cpl-7.1.4+ds/cpljava/Makefile.in cpl-7.2.2+ds/cpljava/Makefile.in --- cpl-7.1.4+ds/cpljava/Makefile.in 2021-05-07 12:10:10.000000000 +0000 +++ cpl-7.2.2+ds/cpljava/Makefile.in 2022-04-29 14:56:28.000000000 +0000 @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.15.1 from Makefile.am. +# Makefile.in generated by automake 1.16.3 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2017 Free Software Foundation, Inc. +# Copyright (C) 1994-2020 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -159,7 +159,8 @@ am__v_at_1 = DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) depcomp = $(SHELL) $(top_srcdir)/admin/depcomp -am__depfiles_maybe = depfiles +am__maybe_remake_depfiles = depfiles +am__depfiles_remade = ./$(DEPDIR)/cpl_gasgano.Plo am__mv = mv -f COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) @@ -181,12 +182,28 @@ am__v_CCLD_1 = SOURCES = $(libcplgasgano_la_SOURCES) DIST_SOURCES = $(libcplgasgano_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 distdir-am 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 @@ -206,8 +223,34 @@ 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@ @@ -226,6 +269,7 @@ CPLCORE_INCLUDES = @CPLCORE_INCLUDES@ CPLDFS_INCLUDES = @CPLDFS_INCLUDES@ CPLDRS_INCLUDES = @CPLDRS_INCLUDES@ +CPLJAVA_INCLUDES = @CPLJAVA_INCLUDES@ CPLUI_INCLUDES = @CPLUI_INCLUDES@ CPL_BINARY_AGE = @CPL_BINARY_AGE@ CPL_BINARY_VERSION = @CPL_BINARY_VERSION@ @@ -286,6 +330,7 @@ LIBCPLCORE = @LIBCPLCORE@ LIBCPLDFS = @LIBCPLDFS@ LIBCPLDRS = @LIBCPLDRS@ +LIBCPLGASGANO = @LIBCPLGASGANO@ LIBCPLUI = @LIBCPLUI@ LIBFFTW = @LIBFFTW@ LIBFFTWF = @LIBFFTWF@ @@ -392,6 +437,7 @@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ @@ -405,6 +451,7 @@ AUTOMAKE_OPTIONS = 1.8 foreign DISTCLEANFILES = *~ @MAINTAINER_MODE_TRUE@MAINTAINERCLEANFILES = $(srcdir)/Makefile.in +SUBDIRS = tests AM_CPPFLAGS = $(CPLCORE_INCLUDES) $(CPLUI_INCLUDES) $(CPLDFS_INCLUDES) \ $(CX_INCLUDES) $(JAVA_INCLUDES) $(INCLTDL) @@ -420,7 +467,7 @@ libcplgasgano_la_LDFLAGS = $(CX_LDFLAGS) $(GASGANO_SHREXT) -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) libcplgasgano_la_LIBADD = $(LIBCPLDFS) $(LIBCPLUI) $(LIBCPLCORE) $(LIBCEXT) $(LIBLTDL) libcplgasgano_la_DEPENDENCIES = $(LIBCPLDFS) $(LIBCPLUI) $(LIBCPLCORE) $(LIBLTDL) -all: all-am +all: all-recursive .SUFFIXES: .SUFFIXES: .c .lo .o .obj @@ -441,8 +488,8 @@ *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);; \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ esac; $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) @@ -498,7 +545,13 @@ distclean-compile: -rm -f *.tab.c -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_gasgano.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_gasgano.Plo@am__quote@ # am--include-marker + +$(am__depfiles_remade): + @$(MKDIR_P) $(@D) + @echo '# dummy' >$@-t && $(am__mv) $@-t $@ + +am--depfiles: $(am__depfiles_remade) .c.o: @am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @@ -527,14 +580,61 @@ 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-am +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 \ @@ -547,7 +647,7 @@ $$unique; \ fi; \ fi -ctags: ctags-am +ctags: ctags-recursive CTAGS: ctags ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) @@ -560,7 +660,7 @@ here=`$(am__cd) $(top_builddir) && pwd` \ && $(am__cd) $(top_srcdir) \ && gtags -i $(GTAGS_ARGS) "$$here" -cscopelist: cscopelist-am +cscopelist: cscopelist-recursive cscopelist-am: $(am__tagged_files) list='$(am__tagged_files)'; \ @@ -579,7 +679,10 @@ distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags -distdir: $(DISTFILES) +distdir: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) distdir-am + +distdir-am: $(DISTFILES) @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ list='$(DISTFILES)'; \ @@ -609,22 +712,48 @@ || 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-am +check: check-recursive all-am: Makefile $(LTLIBRARIES) $(HEADERS) -installdirs: +installdirs: installdirs-recursive +installdirs-am: for dir in "$(DESTDIR)$(libdir)"; do \ test -z "$$dir" || $(MKDIR_P) "$$dir"; \ done -install: install-am -install-exec: install-exec-am -install-data: install-data-am -uninstall: uninstall-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-am +installcheck: installcheck-recursive install-strip: if test -z '$(STRIP)'; then \ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ @@ -648,80 +777,81 @@ @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: clean-recursive clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \ mostlyclean-am -distclean: distclean-am - -rm -rf ./$(DEPDIR) +distclean: distclean-recursive + -rm -f ./$(DEPDIR)/cpl_gasgano.Plo -rm -f Makefile distclean-am: clean-am distclean-compile distclean-generic \ distclean-tags -dvi: dvi-am +dvi: dvi-recursive dvi-am: -html: html-am +html: html-recursive html-am: -info: info-am +info: info-recursive info-am: install-data-am: -install-dvi: install-dvi-am +install-dvi: install-dvi-recursive install-dvi-am: install-exec-am: install-libLTLIBRARIES -install-html: install-html-am +install-html: install-html-recursive install-html-am: -install-info: install-info-am +install-info: install-info-recursive install-info-am: install-man: -install-pdf: install-pdf-am +install-pdf: install-pdf-recursive install-pdf-am: -install-ps: install-ps-am +install-ps: install-ps-recursive install-ps-am: installcheck-am: -maintainer-clean: maintainer-clean-am - -rm -rf ./$(DEPDIR) +maintainer-clean: maintainer-clean-recursive + -rm -f ./$(DEPDIR)/cpl_gasgano.Plo -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic -mostlyclean: mostlyclean-am +mostlyclean: mostlyclean-recursive mostlyclean-am: mostlyclean-compile mostlyclean-generic \ mostlyclean-libtool -pdf: pdf-am +pdf: pdf-recursive pdf-am: -ps: ps-am +ps: ps-recursive ps-am: uninstall-am: uninstall-libLTLIBRARIES -.MAKE: install-am install-strip +.MAKE: $(am__recursive_targets) install-am install-strip -.PHONY: CTAGS GTAGS TAGS all all-am check check-am clean clean-generic \ +.PHONY: $(am__recursive_targets) CTAGS GTAGS TAGS all all-am \ + am--depfiles check check-am clean clean-generic \ clean-libLTLIBRARIES clean-libtool cscopelist-am ctags \ ctags-am distclean distclean-compile distclean-generic \ distclean-libtool distclean-tags distdir dvi dvi-am html \ @@ -730,10 +860,11 @@ install-exec-am install-html install-html-am install-info \ install-info-am install-libLTLIBRARIES 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 \ - tags tags-am uninstall uninstall-am uninstall-libLTLIBRARIES + 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 .PRECIOUS: Makefile diff -Nru cpl-7.1.4+ds/cpljava/org_eso_cpl_jni_CPLControl.h cpl-7.2.2+ds/cpljava/org_eso_cpl_jni_CPLControl.h --- cpl-7.1.4+ds/cpljava/org_eso_cpl_jni_CPLControl.h 2021-05-07 12:09:10.000000000 +0000 +++ cpl-7.2.2+ds/cpljava/org_eso_cpl_jni_CPLControl.h 2022-04-29 14:56:02.000000000 +0000 @@ -12,16 +12,16 @@ * Method: nativeEnsureSetup * Signature: ()V */ -JNIEXPORT void JNICALL Java_org_eso_cpl_jni_CPLControl_nativeEnsureSetup - (JNIEnv *, jclass); +JNIEXPORT void JNICALL +Java_org_eso_cpl_jni_CPLControl_nativeEnsureSetup(JNIEnv *, jclass); /* * Class: org_eso_cpl_jni_CPLControl * Method: nativeGetVersion * Signature: ()Ljava/lang/String; */ -JNIEXPORT jstring JNICALL Java_org_eso_cpl_jni_CPLControl_nativeGetVersion - (JNIEnv *, jclass); +JNIEXPORT jstring JNICALL +Java_org_eso_cpl_jni_CPLControl_nativeGetVersion(JNIEnv *, jclass); #ifdef __cplusplus } diff -Nru cpl-7.1.4+ds/cpljava/org_eso_cpl_jni_JNIParameterImp.h cpl-7.2.2+ds/cpljava/org_eso_cpl_jni_JNIParameterImp.h --- cpl-7.1.4+ds/cpljava/org_eso_cpl_jni_JNIParameterImp.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cpljava/org_eso_cpl_jni_JNIParameterImp.h 2022-04-29 14:56:02.000000000 +0000 @@ -12,8 +12,8 @@ * Method: nativeSetValue * Signature: (Ljava/lang/Object;)V */ -JNIEXPORT void JNICALL Java_org_eso_cpl_jni_JNIParameterImp_nativeSetValue - (JNIEnv *, jobject, jobject); +JNIEXPORT void JNICALL +Java_org_eso_cpl_jni_JNIParameterImp_nativeSetValue(JNIEnv *, jobject, jobject); #ifdef __cplusplus } diff -Nru cpl-7.1.4+ds/cpljava/org_eso_cpl_jni_JNIRecipe.h cpl-7.2.2+ds/cpljava/org_eso_cpl_jni_JNIRecipe.h --- cpl-7.1.4+ds/cpljava/org_eso_cpl_jni_JNIRecipe.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cpljava/org_eso_cpl_jni_JNIRecipe.h 2022-04-29 14:56:02.000000000 +0000 @@ -12,48 +12,52 @@ * Method: nativeInitialize * Signature: ()I */ -JNIEXPORT jint JNICALL Java_org_eso_cpl_jni_JNIRecipe_nativeInitialize - (JNIEnv *, jobject); +JNIEXPORT jint JNICALL Java_org_eso_cpl_jni_JNIRecipe_nativeInitialize(JNIEnv *, + jobject); /* * Class: org_eso_cpl_jni_JNIRecipe * Method: nativeDeinitialize * Signature: ()I */ -JNIEXPORT jint JNICALL Java_org_eso_cpl_jni_JNIRecipe_nativeDeinitialize - (JNIEnv *, jobject); +JNIEXPORT jint JNICALL +Java_org_eso_cpl_jni_JNIRecipe_nativeDeinitialize(JNIEnv *, jobject); /* * Class: org_eso_cpl_jni_JNIRecipe * Method: nativeExecute * Signature: (Ljava/lang/String;Ljava/lang/String;)I */ -JNIEXPORT jint JNICALL Java_org_eso_cpl_jni_JNIRecipe_nativeExecute - (JNIEnv *, jobject, jstring, jstring); +JNIEXPORT jint JNICALL Java_org_eso_cpl_jni_JNIRecipe_nativeExecute(JNIEnv *, + jobject, + jstring, + jstring); /* * Class: org_eso_cpl_jni_JNIRecipe * Method: nativeGetParameterArray * Signature: ()[Lorg/eso/cpl/Parameter; */ -JNIEXPORT jobjectArray JNICALL Java_org_eso_cpl_jni_JNIRecipe_nativeGetParameterArray - (JNIEnv *, jobject); +JNIEXPORT jobjectArray JNICALL +Java_org_eso_cpl_jni_JNIRecipe_nativeGetParameterArray(JNIEnv *, jobject); /* * Class: org_eso_cpl_jni_JNIRecipe * Method: nativeGetFrameArray * Signature: ()[Lorg/eso/cpl/Frame; */ -JNIEXPORT jobjectArray JNICALL Java_org_eso_cpl_jni_JNIRecipe_nativeGetFrameArray - (JNIEnv *, jobject); +JNIEXPORT jobjectArray JNICALL +Java_org_eso_cpl_jni_JNIRecipe_nativeGetFrameArray(JNIEnv *, jobject); /* * Class: org_eso_cpl_jni_JNIRecipe * Method: nativeSetFrameArray * Signature: ([Lorg/eso/cpl/Frame;)V */ -JNIEXPORT void JNICALL Java_org_eso_cpl_jni_JNIRecipe_nativeSetFrameArray - (JNIEnv *, jobject, jobjectArray); +JNIEXPORT void JNICALL +Java_org_eso_cpl_jni_JNIRecipe_nativeSetFrameArray(JNIEnv *, + jobject, + jobjectArray); #ifdef __cplusplus } diff -Nru cpl-7.1.4+ds/cpljava/org_eso_cpl_jni_LibraryLoader.h cpl-7.2.2+ds/cpljava/org_eso_cpl_jni_LibraryLoader.h --- cpl-7.1.4+ds/cpljava/org_eso_cpl_jni_LibraryLoader.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cpljava/org_eso_cpl_jni_LibraryLoader.h 2022-04-29 14:56:02.000000000 +0000 @@ -12,24 +12,27 @@ * Method: nativeLTDLInit * Signature: ()V */ -JNIEXPORT void JNICALL Java_org_eso_cpl_jni_LibraryLoader_nativeLTDLInit - (JNIEnv *, jclass); +JNIEXPORT void JNICALL +Java_org_eso_cpl_jni_LibraryLoader_nativeLTDLInit(JNIEnv *, jclass); /* * Class: org_eso_cpl_jni_LibraryLoader * Method: nativeLTDLExit * Signature: ()V */ -JNIEXPORT void JNICALL Java_org_eso_cpl_jni_LibraryLoader_nativeLTDLExit - (JNIEnv *, jclass); +JNIEXPORT void JNICALL +Java_org_eso_cpl_jni_LibraryLoader_nativeLTDLExit(JNIEnv *, jclass); /* * Class: org_eso_cpl_jni_LibraryLoader * Method: nativeMakeLibrary * Signature: (Ljava/lang/String;Ljava/lang/String;)Lorg/eso/cpl/jni/PluginLibrary; */ -JNIEXPORT jobject JNICALL Java_org_eso_cpl_jni_LibraryLoader_nativeMakeLibrary - (JNIEnv *, jclass, jstring, jstring); +JNIEXPORT jobject JNICALL +Java_org_eso_cpl_jni_LibraryLoader_nativeMakeLibrary(JNIEnv *, + jclass, + jstring, + jstring); #ifdef __cplusplus } diff -Nru cpl-7.1.4+ds/cpljava/org_eso_cpl_jni_PluginLibrary.h cpl-7.2.2+ds/cpljava/org_eso_cpl_jni_PluginLibrary.h --- cpl-7.1.4+ds/cpljava/org_eso_cpl_jni_PluginLibrary.h 2021-05-07 12:09:10.000000000 +0000 +++ cpl-7.2.2+ds/cpljava/org_eso_cpl_jni_PluginLibrary.h 2022-04-29 14:56:02.000000000 +0000 @@ -12,8 +12,8 @@ * Method: nativeUnload * Signature: ()V */ -JNIEXPORT void JNICALL Java_org_eso_cpl_jni_PluginLibrary_nativeUnload - (JNIEnv *, jobject); +JNIEXPORT void JNICALL Java_org_eso_cpl_jni_PluginLibrary_nativeUnload(JNIEnv *, + jobject); #ifdef __cplusplus } diff -Nru cpl-7.1.4+ds/cpljava/tests/cpl_gasgano-test.c cpl-7.2.2+ds/cpljava/tests/cpl_gasgano-test.c --- cpl-7.1.4+ds/cpljava/tests/cpl_gasgano-test.c 1970-01-01 00:00:00.000000000 +0000 +++ cpl-7.2.2+ds/cpljava/tests/cpl_gasgano-test.c 2022-04-29 14:56:02.000000000 +0000 @@ -0,0 +1,68 @@ +/* + * This file is part of the ESO Common Pipeline Library + * Copyright (C) 2001-2022 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 + +#include "cpl_test.h" + +#include +#include +#include +#include + +#ifdef HAVE_UNISTD_H +#include +#endif + +#include + +#include "ltdl.h" + +#include "org_eso_cpl_jni_CPLControl.h" +#include "org_eso_cpl_jni_JNIParameterImp.h" +#include "org_eso_cpl_jni_JNIRecipe.h" +#include "org_eso_cpl_jni_LibraryLoader.h" +#include "org_eso_cpl_jni_PluginLibrary.h" + +/*----------------------------------------------------------------------------- + Main + -----------------------------------------------------------------------------*/ + +int +main(void) +{ + jstring nullstring; + + cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + + /* Only tests whether the function can actually be called, i.e. linking */ + Java_org_eso_cpl_jni_CPLControl_nativeEnsureSetup(NULL, 0); + + cpl_test_error(CPL_ERROR_NONE); + + /* Only tests the function in a non-useful mode */ + nullstring = Java_org_eso_cpl_jni_CPLControl_nativeGetVersion(NULL, 0); + + cpl_test_error(CPL_ERROR_NONE); + cpl_test_null(nullstring); + + return cpl_test_end(0); +} diff -Nru cpl-7.1.4+ds/cpljava/tests/Makefile.am cpl-7.2.2+ds/cpljava/tests/Makefile.am --- cpl-7.1.4+ds/cpljava/tests/Makefile.am 1970-01-01 00:00:00.000000000 +0000 +++ cpl-7.2.2+ds/cpljava/tests/Makefile.am 2022-04-29 14:56:02.000000000 +0000 @@ -0,0 +1,55 @@ +## Process this file with automake to produce Makefile.in + +## This file is part of the ESO Common Pipeline Library +## Copyright (C) 2001-2022 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 Street, Fifth Floor, Boston, MA 02111-1307 USA + + +AUTOMAKE_OPTIONS = 1.8 foreign + +DISTCLEANFILES = *~ + + +if MAINTAINER_MODE + +MAINTAINERCLEANFILES = $(srcdir)/Makefile.in + +endif + +AM_CPPFLAGS = $(CPLCORE_INCLUDES) $(CX_INCLUDES) $(CFITSIO_INCLUDES) \ + $(CPLJAVA_INCLUDES) $(CPL_CFLAGS) $(JAVA_INCLUDES) $(INCLTDL) +AM_LDFLAGS = $(CFITSIO_LDFLAGS) + +LDADD = $(LIBCPLGASGANO) $(LIBCPLCORE) $(LIBCEXT) $(LIBCFITSIO) + +check_PROGRAMS = cpl_gasgano-test + +cpl_gasgano_test_SOURCES = cpl_gasgano-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)" + + +TESTS = cpl_gasgano-test + +XFAIL_TESTS = + +# We need to remove any files that the above tests created. +clean-local: + $(RM) *.fits *.tfits *.log *dump.txt diff -Nru cpl-7.1.4+ds/cpljava/tests/Makefile.in cpl-7.2.2+ds/cpljava/tests/Makefile.in --- cpl-7.1.4+ds/cpljava/tests/Makefile.in 1970-01-01 00:00:00.000000000 +0000 +++ cpl-7.2.2+ds/cpljava/tests/Makefile.in 2022-04-29 14:56:28.000000000 +0000 @@ -0,0 +1,1075 @@ +# Makefile.in generated by automake 1.16.3 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994-2020 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@ +check_PROGRAMS = cpl_gasgano-test$(EXEEXT) +TESTS = cpl_gasgano-test$(EXEEXT) +XFAIL_TESTS = +subdir = cpljava/tests +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/m4/cpl.m4 $(top_srcdir)/m4/eso.m4 \ + $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltargz.m4 \ + $(top_srcdir)/m4/ltdl.m4 $(top_srcdir)/m4/ltoptions.m4 \ + $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ + $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/omp.m4 \ + $(top_srcdir)/acinclude.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_cpl_gasgano_test_OBJECTS = cpl_gasgano-test.$(OBJEXT) +cpl_gasgano_test_OBJECTS = $(am_cpl_gasgano_test_OBJECTS) +cpl_gasgano_test_LDADD = $(LDADD) +am__DEPENDENCIES_1 = +cpl_gasgano_test_DEPENDENCIES = $(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_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__maybe_remake_depfiles = depfiles +am__depfiles_remade = ./$(DEPDIR)/cpl_gasgano-test.Po +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 = $(cpl_gasgano_test_SOURCES) +DIST_SOURCES = $(cpl_gasgano_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` +AM_TESTSUITE_SUMMARY_HEADER = ' for $(PACKAGE_STRING)' +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@ +CFITSIODIR = @CFITSIODIR@ +CFITSIO_CFLAGS = @CFITSIO_CFLAGS@ +CFITSIO_INCLUDES = @CFITSIO_INCLUDES@ +CFITSIO_LDFLAGS = @CFITSIO_LDFLAGS@ +CFLAGS = @CFLAGS@ +CPLCORE_INCLUDES = @CPLCORE_INCLUDES@ +CPLDFS_INCLUDES = @CPLDFS_INCLUDES@ +CPLDRS_INCLUDES = @CPLDRS_INCLUDES@ +CPLJAVA_INCLUDES = @CPLJAVA_INCLUDES@ +CPLUI_INCLUDES = @CPLUI_INCLUDES@ +CPL_BINARY_AGE = @CPL_BINARY_AGE@ +CPL_BINARY_VERSION = @CPL_BINARY_VERSION@ +CPL_CFLAGS = @CPL_CFLAGS@ +CPL_INTERFACE_AGE = @CPL_INTERFACE_AGE@ +CPL_LDFLAGS = @CPL_LDFLAGS@ +CPL_MAJOR_VERSION = @CPL_MAJOR_VERSION@ +CPL_MICRO_VERSION = @CPL_MICRO_VERSION@ +CPL_MINOR_VERSION = @CPL_MINOR_VERSION@ +CPL_VERSION = @CPL_VERSION@ +CPL_VERSION_STRING = @CPL_VERSION_STRING@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CX_CFLAGS = @CX_CFLAGS@ +CX_INCLUDES = @CX_INCLUDES@ +CX_LDFLAGS = @CX_LDFLAGS@ +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@ +FFTWDIR = @FFTWDIR@ +FFTWF_CFLAGS = @FFTWF_CFLAGS@ +FFTWF_INCLUDES = @FFTWF_INCLUDES@ +FFTWF_LDFLAGS = @FFTWF_LDFLAGS@ +FFTW_CFLAGS = @FFTW_CFLAGS@ +FFTW_INCLUDES = @FFTW_INCLUDES@ +FFTW_LDFLAGS = @FFTW_LDFLAGS@ +FGREP = @FGREP@ +GASGANO_SHREXT = @GASGANO_SHREXT@ +GREP = @GREP@ +INCLTDL = @INCLTDL@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +JAVA = @JAVA@ +JAVAC = @JAVAC@ +JAVA_INCLUDES = @JAVA_INCLUDES@ +LATEX = @LATEX@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBADD_DL = @LIBADD_DL@ +LIBADD_DLD_LINK = @LIBADD_DLD_LINK@ +LIBADD_DLOPEN = @LIBADD_DLOPEN@ +LIBADD_SHL_LOAD = @LIBADD_SHL_LOAD@ +LIBCEXT = @LIBCEXT@ +LIBCFITSIO = @LIBCFITSIO@ +LIBCPLCORE = @LIBCPLCORE@ +LIBCPLDFS = @LIBCPLDFS@ +LIBCPLDRS = @LIBCPLDRS@ +LIBCPLGASGANO = @LIBCPLGASGANO@ +LIBCPLUI = @LIBCPLUI@ +LIBFFTW = @LIBFFTW@ +LIBFFTWF = @LIBFFTWF@ +LIBLTDL = @LIBLTDL@ +LIBOBJS = @LIBOBJS@ +LIBPTHREAD = @LIBPTHREAD@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIBTOOL_DEPS = @LIBTOOL_DEPS@ +LIBWCS = @LIBWCS@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTDLDEPS = @LTDLDEPS@ +LTDLINCL = @LTDLINCL@ +LTDLOPEN = @LTDLOPEN@ +LTLIBOBJS = @LTLIBOBJS@ +LT_AGE = @LT_AGE@ +LT_ARGZ_H = @LT_ARGZ_H@ +LT_CONFIG_H = @LT_CONFIG_H@ +LT_CURRENT = @LT_CURRENT@ +LT_DLLOADERS = @LT_DLLOADERS@ +LT_DLPREOPEN = @LT_DLPREOPEN@ +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@ +OPENMP_CFLAGS = @OPENMP_CFLAGS@ +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@ +PKGCONFIG = @PKGCONFIG@ +PTHREAD_CFLAGS = @PTHREAD_CFLAGS@ +RANLIB = @RANLIB@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +WCSDIR = @WCSDIR@ +WCS_CFLAGS = @WCS_CFLAGS@ +WCS_INCLUDES = @WCS_INCLUDES@ +WCS_LDFLAGS = @WCS_LDFLAGS@ +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@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +apidocdir = @apidocdir@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +configdir = @configdir@ +cpl_includes = @cpl_includes@ +cpl_libraries = @cpl_libraries@ +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@ +libcext = @libcext@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +ltdl_LIBOBJS = @ltdl_LIBOBJS@ +ltdl_LTLIBOBJS = @ltdl_LTLIBOBJS@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +runstatedir = @runstatedir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +subdirs = @subdirs@ +sys_symbol_underscore = @sys_symbol_underscore@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +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 = $(CPLCORE_INCLUDES) $(CX_INCLUDES) $(CFITSIO_INCLUDES) \ + $(CPLJAVA_INCLUDES) $(CPL_CFLAGS) $(JAVA_INCLUDES) $(INCLTDL) + +AM_LDFLAGS = $(CFITSIO_LDFLAGS) +LDADD = $(LIBCPLGASGANO) $(LIBCPLCORE) $(LIBCEXT) $(LIBCFITSIO) +cpl_gasgano_test_SOURCES = cpl_gasgano-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)" + +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 cpljava/tests/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --foreign cpljava/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__maybe_remake_depfiles)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ + 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 + +cpl_gasgano-test$(EXEEXT): $(cpl_gasgano_test_OBJECTS) $(cpl_gasgano_test_DEPENDENCIES) $(EXTRA_cpl_gasgano_test_DEPENDENCIES) + @rm -f cpl_gasgano-test$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(cpl_gasgano_test_OBJECTS) $(cpl_gasgano_test_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_gasgano-test.Po@am__quote@ # am--include-marker + +$(am__depfiles_remade): + @$(MKDIR_P) $(@D) + @echo '# dummy' >$@-t && $(am__mv) $@-t $@ + +am--depfiles: $(am__depfiles_remade) + +.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"$(AM_TESTSUITE_SUMMARY_HEADER)"$${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: $(check_PROGRAMS) + @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 $$? +cpl_gasgano-test.log: cpl_gasgano-test$(EXEEXT) + @p='cpl_gasgano-test$(EXEEXT)'; \ + b='cpl_gasgano-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: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) distdir-am + +distdir-am: $(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 -f ./$(DEPDIR)/cpl_gasgano-test.Po + -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 -f ./$(DEPDIR)/cpl_gasgano-test.Po + -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 am--depfiles 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 *dump.txt + +# 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-7.1.4+ds/cplui/cpl_frame.c cpl-7.2.2+ds/cplui/cpl_frame.c --- cpl-7.1.4+ds/cplui/cpl_frame.c 2021-05-07 12:09:09.000000000 +0000 +++ cpl-7.2.2+ds/cplui/cpl_frame.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -18,7 +18,7 @@ */ #ifdef HAVE_CONFIG_H -# include +#include #endif #include @@ -66,19 +66,22 @@ typedef struct _cpl_frame_attributes_ cpl_frame_attributes; typedef struct _cpl_frame_fileinfo_ cpl_frame_fileinfo; -struct _cpl_frame_attributes_ { +struct _cpl_frame_attributes_ +{ cpl_frame_type type; cpl_frame_group group; cpl_frame_level level; }; -struct _cpl_frame_fileinfo_ { +struct _cpl_frame_fileinfo_ +{ cxchar *name; }; -struct _cpl_frame_ { +struct _cpl_frame_ +{ cpl_frame_attributes attributes; cpl_frame_fileinfo *fileinfo; cxchar *tag; @@ -92,20 +95,17 @@ inline static cpl_frame_fileinfo * _cpl_frame_fileinfo_new(void) { - cpl_frame_fileinfo *info = cx_malloc(sizeof *info); info->name = NULL; return info; - } inline static void _cpl_frame_fileinfo_delete(cpl_frame_fileinfo *info) { - if (info->name) { cx_free(info->name); } @@ -131,13 +131,13 @@ cpl_size cpl_frame_get_nplanes(const cpl_frame *self, cpl_size extnum) { - cpl_size next; - cpl_size nplanes; - cxint naxis; + cpl_size next; + cpl_size nplanes; + cxint naxis; cxint status = 0; cxint hdu_type = ANY_HDU; cxint hdu_position = extnum + 1; - fitsfile *file = NULL; + fitsfile *file = NULL; if (self == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); @@ -164,16 +164,13 @@ cpl_io_fits_close_file(file, &status); cpl_error_set_(CPL_ERROR_FILE_IO); return -1; - } else { - if (status != 0) { status = 0; cpl_io_fits_close_file(file, &status); cpl_error_set_(CPL_ERROR_BAD_FILE_FORMAT); return -1; - } } @@ -185,7 +182,6 @@ cpl_error_set_(CPL_ERROR_DATA_NOT_FOUND); return -1; - } /* Find the number of axes */ @@ -210,7 +206,7 @@ CPL_FITSIO_TYPE *naxes = cx_malloc(naxis * sizeof(CPL_FITSIO_TYPE)); CPL_FITSIO_GET_SIZE(file, naxis, naxes, &status); nplanes = (cpl_size)naxes[2]; - if(naxes[2] < 1) + if (naxes[2] < 1) nplanes = 0; cx_free(naxes); @@ -220,7 +216,6 @@ cx_assert(status == 0); return nplanes; - } /* @@ -285,8 +280,6 @@ cpl_frame * cpl_frame_duplicate(const cpl_frame *other) { - - cpl_frame *copy; @@ -302,7 +295,6 @@ } if (other->fileinfo) { - copy->fileinfo = cx_malloc(sizeof(cpl_frame_fileinfo)); if (other->fileinfo->name) { @@ -311,7 +303,6 @@ else { copy->fileinfo->name = NULL; } - } copy->attributes.type = other->attributes.type; @@ -320,7 +311,6 @@ return copy; - } @@ -339,7 +329,6 @@ void cpl_frame_delete(cpl_frame *self) { - if (self) { if (self->tag) { cx_free(self->tag); @@ -353,7 +342,6 @@ } return; - } @@ -393,9 +381,6 @@ const char * cpl_frame_get_filename(const cpl_frame *self) { - - - if (self == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return NULL; @@ -409,11 +394,9 @@ cx_assert(self->fileinfo->name != NULL); return self->fileinfo->name; - } - /** * @brief * Get the category tag of a frame. @@ -442,16 +425,12 @@ const char * cpl_frame_get_tag(const cpl_frame *self) { - - - if (self == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return NULL; } return self->tag; - } @@ -483,16 +462,12 @@ cpl_frame_type cpl_frame_get_type(const cpl_frame *self) { - - - if (self == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return CPL_FRAME_TYPE_NONE; } return self->attributes.type; - } @@ -523,16 +498,12 @@ cpl_frame_group cpl_frame_get_group(const cpl_frame *self) { - - - if (self == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return CPL_FRAME_GROUP_NONE; } return self->attributes.group; - } @@ -563,16 +534,12 @@ cpl_frame_level cpl_frame_get_level(const cpl_frame *self) { - - - if (self == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return CPL_FRAME_LEVEL_NONE; } return self->attributes.level; - } @@ -608,8 +575,6 @@ cpl_error_code cpl_frame_set_filename(cpl_frame *self, const char *filename) { - - cpl_frame_fileinfo *info; @@ -632,7 +597,6 @@ info->name = cx_strdup(filename); return CPL_ERROR_NONE; - } @@ -667,9 +631,6 @@ cpl_error_code cpl_frame_set_tag(cpl_frame *self, const char *tag) { - - - if (self == NULL || tag == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } @@ -682,7 +643,6 @@ self->tag = cx_strdup(tag); return CPL_ERROR_NONE; - } @@ -714,16 +674,12 @@ cpl_error_code cpl_frame_set_type(cpl_frame *self, cpl_frame_type type) { - - - if (self == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } self->attributes.type = type; return CPL_ERROR_NONE; - } @@ -755,16 +711,12 @@ cpl_error_code cpl_frame_set_group(cpl_frame *self, cpl_frame_group group) { - - - if (self == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } self->attributes.group = group; return CPL_ERROR_NONE; - } @@ -796,16 +748,12 @@ cpl_error_code cpl_frame_set_level(cpl_frame *self, cpl_frame_level level) { - - - if (self == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } self->attributes.level = level; return CPL_ERROR_NONE; - } /** @@ -852,11 +800,10 @@ return -1; } - if((next = cpl_fits_count_extensions(self->fileinfo->name)) == -1) + if ((next = cpl_fits_count_extensions(self->fileinfo->name)) == -1) return -1; return next; - } @@ -877,7 +824,6 @@ void cpl_frame_dump(const cpl_frame *frame, FILE *stream) { - const char *name; const char *tag; @@ -899,38 +845,38 @@ group = cpl_frame_get_group(frame); level = cpl_frame_get_level(frame); - fprintf(stream, "%s \t%s ",name, tag); + fprintf(stream, "%s \t%s ", name, tag); switch (type) { case CPL_FRAME_TYPE_IMAGE: - fprintf(stream, "%s ","CPL_FRAME_TYPE_IMAGE"); + fprintf(stream, "%s ", "CPL_FRAME_TYPE_IMAGE"); break; case CPL_FRAME_TYPE_MATRIX: - fprintf(stream, "%s ","CPL_FRAME_TYPE_MATRIX"); + fprintf(stream, "%s ", "CPL_FRAME_TYPE_MATRIX"); break; case CPL_FRAME_TYPE_TABLE: - fprintf(stream, "%s ","CPL_FRAME_TYPE_TABLE"); + fprintf(stream, "%s ", "CPL_FRAME_TYPE_TABLE"); break; case CPL_FRAME_TYPE_PAF: - fprintf(stream, "%s ","CPL_FRAME_TYPE_PAF"); + fprintf(stream, "%s ", "CPL_FRAME_TYPE_PAF"); break; case CPL_FRAME_TYPE_ANY: - fprintf(stream, "%s ","CPL_FRAME_TYPE_ANY"); + fprintf(stream, "%s ", "CPL_FRAME_TYPE_ANY"); break; default: - fprintf(stream, "%s ","CPL_FRAME_TYPE_NONE"); + fprintf(stream, "%s ", "CPL_FRAME_TYPE_NONE"); break; } switch (group) { case CPL_FRAME_GROUP_RAW: - fprintf(stream, "%s ","CPL_FRAME_GROUP_RAW"); + fprintf(stream, "%s ", "CPL_FRAME_GROUP_RAW"); break; case CPL_FRAME_GROUP_CALIB: @@ -942,18 +888,18 @@ break; default: - fprintf(stream, "%s ","CPL_FRAME_GROUP_NONE"); + fprintf(stream, "%s ", "CPL_FRAME_GROUP_NONE"); break; } switch (level) { case CPL_FRAME_LEVEL_TEMPORARY: - fprintf(stream, "%s ","CPL_FRAME_LEVEL_TEMPORARY"); + fprintf(stream, "%s ", "CPL_FRAME_LEVEL_TEMPORARY"); break; case CPL_FRAME_LEVEL_INTERMEDIATE: - fprintf(stream, "%s ","CPL_FRAME_LEVEL_INTERMEDIATE"); + fprintf(stream, "%s ", "CPL_FRAME_LEVEL_INTERMEDIATE"); break; case CPL_FRAME_LEVEL_FINAL: @@ -961,15 +907,13 @@ break; default: - fprintf(stream, "%s ","CPL_FRAME_LEVEL_NONE"); + fprintf(stream, "%s ", "CPL_FRAME_LEVEL_NONE"); break; - } fprintf(stream, "\n"); return; - } diff -Nru cpl-7.1.4+ds/cplui/cpl_framedata.c cpl-7.2.2+ds/cplui/cpl_framedata.c --- cpl-7.1.4+ds/cplui/cpl_framedata.c 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplui/cpl_framedata.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -18,7 +18,7 @@ */ #ifdef HAVE_CONFIG_H -# include +#include #endif #include @@ -73,18 +73,16 @@ * and both, @em min_count and @em max_count are set to @c -1. */ -cpl_framedata* +cpl_framedata * cpl_framedata_new(void) { - - cpl_framedata* self = cx_calloc(1, sizeof *self); + cpl_framedata *self = cx_calloc(1, sizeof *self); self->tag = NULL; self->min_count = -1; self->max_count = -1; return self; - } @@ -105,18 +103,16 @@ * @em min_count, and @em max_count. */ -cpl_framedata* -cpl_framedata_create(const char* tag, cpl_size min_count, cpl_size max_count) +cpl_framedata * +cpl_framedata_create(const char *tag, cpl_size min_count, cpl_size max_count) { - - cpl_framedata* self = cx_calloc(1, sizeof *self); + cpl_framedata *self = cx_calloc(1, sizeof *self); self->tag = cx_strdup(tag); self->min_count = (min_count < -1) ? -1 : min_count; self->max_count = (max_count < -1) ? -1 : max_count; return self; - } @@ -145,28 +141,23 @@ * The created copy does not share any resources with the original object. */ -cpl_framedata* -cpl_framedata_duplicate(const cpl_framedata* other) +cpl_framedata * +cpl_framedata_duplicate(const cpl_framedata *other) { - - - cpl_framedata* self = NULL; + cpl_framedata *self = NULL; if (other == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); } else { - self = cx_calloc(1, sizeof *self); self->tag = cx_strdup(other->tag); self->min_count = other->min_count; self->max_count = other->max_count; - } return self; - } @@ -185,9 +176,8 @@ */ void -cpl_framedata_clear(cpl_framedata* self) +cpl_framedata_clear(cpl_framedata *self) { - if (self != NULL) { if (self->tag != NULL) { cx_free((cxptr)self->tag); @@ -199,7 +189,6 @@ } return; - } @@ -217,9 +206,8 @@ */ void -cpl_framedata_delete(cpl_framedata* self) +cpl_framedata_delete(cpl_framedata *self) { - if (self != NULL) { cpl_framedata_clear(self); @@ -228,7 +216,6 @@ } return; - } @@ -257,19 +244,15 @@ * object @em self. */ -const char* -cpl_framedata_get_tag(const cpl_framedata* self) +const char * +cpl_framedata_get_tag(const cpl_framedata *self) { - - - if (self == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return NULL; } return self->tag; - } @@ -301,18 +284,14 @@ */ cpl_size -cpl_framedata_get_min_count(const cpl_framedata* self) +cpl_framedata_get_min_count(const cpl_framedata *self) { - - - if (self == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return -2; } return self->min_count; - } @@ -344,18 +323,14 @@ */ cpl_size -cpl_framedata_get_max_count(const cpl_framedata* self) +cpl_framedata_get_max_count(const cpl_framedata *self) { - - - if (self == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return -2; } return self->max_count; - } @@ -394,11 +369,8 @@ */ cpl_error_code -cpl_framedata_set_tag(cpl_framedata* self, const char* tag) +cpl_framedata_set_tag(cpl_framedata *self, const char *tag) { - - - if (self == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } @@ -413,7 +385,6 @@ self->tag = cx_strdup(tag); return CPL_ERROR_NONE; - } @@ -445,11 +416,8 @@ */ cpl_error_code -cpl_framedata_set_min_count(cpl_framedata* self, cpl_size min_count) +cpl_framedata_set_min_count(cpl_framedata *self, cpl_size min_count) { - - - if (self == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } @@ -457,7 +425,6 @@ self->min_count = (min_count < -1) ? -1 : min_count; return CPL_ERROR_NONE; - } @@ -489,11 +456,8 @@ */ cpl_error_code -cpl_framedata_set_max_count(cpl_framedata* self, cpl_size max_count) +cpl_framedata_set_max_count(cpl_framedata *self, cpl_size max_count) { - - - if (self == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } @@ -501,7 +465,6 @@ self->max_count = (max_count < -1) ? -1 : max_count; return CPL_ERROR_NONE; - } @@ -545,12 +508,11 @@ */ cpl_error_code -cpl_framedata_set(cpl_framedata* self, const char* tag, cpl_size min_count, +cpl_framedata_set(cpl_framedata *self, + const char *tag, + cpl_size min_count, cpl_size max_count) { - - - if (self == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } @@ -568,6 +530,5 @@ self->max_count = (max_count < -1) ? -1 : max_count; return CPL_ERROR_NONE; - } /**@}*/ diff -Nru cpl-7.1.4+ds/cplui/cpl_framedata.h cpl-7.2.2+ds/cplui/cpl_framedata.h --- cpl-7.1.4+ds/cplui/cpl_framedata.h 2021-05-07 12:09:09.000000000 +0000 +++ cpl-7.2.2+ds/cplui/cpl_framedata.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -51,14 +51,14 @@ * still be done using the member functions. */ -struct _cpl_framedata_ { - +struct _cpl_framedata_ +{ /** * The frame tag. A unique string identifier for a particular kind of * frame. */ - const char* tag; + const char *tag; /** * The minimum number of frames of the kind given by the @em tag, @@ -75,7 +75,6 @@ */ cpl_size max_count; - }; @@ -83,37 +82,40 @@ * Create, copy and destroy operations */ -cpl_framedata* cpl_framedata_new(void) CPL_ATTR_ALLOC; -cpl_framedata* cpl_framedata_create(const char* tag, cpl_size min_count, +cpl_framedata *cpl_framedata_new(void) CPL_ATTR_ALLOC; +cpl_framedata *cpl_framedata_create(const char *tag, + cpl_size min_count, cpl_size max_count) CPL_ATTR_ALLOC; -cpl_framedata* cpl_framedata_duplicate(const cpl_framedata* other) - CPL_ATTR_ALLOC; -void cpl_framedata_clear(cpl_framedata* self); -void cpl_framedata_delete(cpl_framedata* self); +cpl_framedata * +cpl_framedata_duplicate(const cpl_framedata *other) CPL_ATTR_ALLOC; +void cpl_framedata_clear(cpl_framedata *self); +void cpl_framedata_delete(cpl_framedata *self); /* * Non modifying operations */ -const char* cpl_framedata_get_tag(const cpl_framedata* self); +const char *cpl_framedata_get_tag(const cpl_framedata *self); -cpl_size cpl_framedata_get_min_count(const cpl_framedata* self); -cpl_size cpl_framedata_get_max_count(const cpl_framedata* self); +cpl_size cpl_framedata_get_min_count(const cpl_framedata *self); +cpl_size cpl_framedata_get_max_count(const cpl_framedata *self); /* * Assignment operations */ -cpl_error_code cpl_framedata_set_tag(cpl_framedata* self, const char* tag); - -cpl_error_code cpl_framedata_set_min_count(cpl_framedata* self, - cpl_size min_count); -cpl_error_code cpl_framedata_set_max_count(cpl_framedata* self, - cpl_size max_count); +cpl_error_code cpl_framedata_set_tag(cpl_framedata *self, const char *tag); -cpl_error_code cpl_framedata_set(cpl_framedata* self, const char* tag, - cpl_size min_count, cpl_size max_count); +cpl_error_code +cpl_framedata_set_min_count(cpl_framedata *self, cpl_size min_count); +cpl_error_code +cpl_framedata_set_max_count(cpl_framedata *self, cpl_size max_count); + +cpl_error_code cpl_framedata_set(cpl_framedata *self, + const char *tag, + cpl_size min_count, + cpl_size max_count); CPL_END_DECLS diff -Nru cpl-7.1.4+ds/cplui/cpl_frame.h cpl-7.2.2+ds/cplui/cpl_frame.h --- cpl-7.1.4+ds/cplui/cpl_frame.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplui/cpl_frame.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -63,20 +63,21 @@ * Defines the possible values for the frame's type attribute. */ -enum _cpl_frame_type_ { +enum _cpl_frame_type_ +{ /** * Undefined frame type * @hideinitializer */ - CPL_FRAME_TYPE_NONE = 1 << 0, + CPL_FRAME_TYPE_NONE = 1 << 0, /** * Image frame type identifier * @hideinitializer */ - CPL_FRAME_TYPE_IMAGE = 1 << 1, + CPL_FRAME_TYPE_IMAGE = 1 << 1, /** * Matrix frame type identifier @@ -90,21 +91,21 @@ * @hideinitializer */ - CPL_FRAME_TYPE_TABLE = 1 << 3, + CPL_FRAME_TYPE_TABLE = 1 << 3, /** * paf frame type identifier * @hideinitializer */ - CPL_FRAME_TYPE_PAF = 1 << 4, + CPL_FRAME_TYPE_PAF = 1 << 4, /** * identifier for any other type * @hideinitializer */ - CPL_FRAME_TYPE_ANY = 1 << 5 + CPL_FRAME_TYPE_ANY = 1 << 5 }; @@ -127,7 +128,8 @@ * Defines the possible values for the frame's group attribute. */ -enum _cpl_frame_group_ { +enum _cpl_frame_group_ +{ /** * The frame does not belong to any supported group. @@ -176,7 +178,8 @@ * to trigger the appropriate action for the different levels. */ -enum _cpl_frame_level_ { +enum _cpl_frame_level_ +{ /** * Undefined processing level @@ -230,7 +233,7 @@ * Frame group tag for unprocessed data. */ -#define CPL_FRAME_GROUP_RAW_ID "RAW" +#define CPL_FRAME_GROUP_RAW_ID "RAW" /** * @ingroup cpl_frame @@ -239,7 +242,7 @@ * Frame group tag for calibration data. */ -#define CPL_FRAME_GROUP_CALIB_ID "CALIB" +#define CPL_FRAME_GROUP_CALIB_ID "CALIB" /** * @ingroup cpl_frame @@ -248,7 +251,7 @@ * Frame group tag for processed data. */ -#define CPL_FRAME_GROUP_PRODUCT_ID "PRODUCT" +#define CPL_FRAME_GROUP_PRODUCT_ID "PRODUCT" /* diff -Nru cpl-7.1.4+ds/cplui/cpl_frame_impl.h cpl-7.2.2+ds/cplui/cpl_frame_impl.h --- cpl-7.1.4+ds/cplui/cpl_frame_impl.h 2021-05-07 12:09:11.000000000 +0000 +++ cpl-7.2.2+ds/cplui/cpl_frame_impl.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 diff -Nru cpl-7.1.4+ds/cplui/cpl_frameset.c cpl-7.2.2+ds/cplui/cpl_frameset.c --- cpl-7.1.4+ds/cplui/cpl_frameset.c 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplui/cpl_frameset.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -18,7 +18,7 @@ */ #ifdef HAVE_CONFIG_H -# include +#include #endif #include @@ -57,7 +57,8 @@ * The frame set type. */ -enum _cpl_frameset_cacheid { +enum _cpl_frameset_cacheid +{ TAG, POS, ALL @@ -66,7 +67,8 @@ typedef enum _cpl_frameset_cacheid cpl_frameset_cacheid; -struct _cpl_frameset_cache_ { +struct _cpl_frameset_cache_ +{ cx_multimap_iterator tag; cx_multimap_iterator pos; }; @@ -74,7 +76,8 @@ typedef struct _cpl_frameset_cache_ cpl_frameset_cache; -struct _cpl_frameset_ { +struct _cpl_frameset_ +{ cx_multimap *frames; cx_list *history; @@ -89,26 +92,24 @@ inline static cxbool _cpl_frameset_cache_empty(const cpl_frameset *self, cpl_frameset_cacheid id) { - cxbool state; switch (id) { - case TAG: - state = self->cache.tag == NULL; - break; - - case POS: - state = self->cache.pos == NULL; - break; - - case ALL: - state = (self->cache.tag == NULL && self->cache.pos == NULL); - break; + case TAG: + state = self->cache.tag == NULL; + break; + + case POS: + state = self->cache.pos == NULL; + break; + + case ALL: + state = (self->cache.tag == NULL && self->cache.pos == NULL); + break; } return state; - } @@ -136,30 +137,27 @@ inline static void _cpl_frameset_cache_reset(const cpl_frameset *self, cpl_frameset_cacheid id) { - - cpl_frameset * myself = (cpl_frameset *)self; + cpl_frameset *myself = (cpl_frameset *)self; switch (id) { - case TAG: - myself->cache.tag = NULL; - break; - - case POS: - myself->cache.pos = NULL; - break; - - case ALL: - myself->cache.tag = NULL; - myself->cache.pos = NULL; - break; + case TAG: + myself->cache.tag = NULL; + break; + + case POS: + myself->cache.pos = NULL; + break; + + case ALL: + myself->cache.tag = NULL; + myself->cache.pos = NULL; + break; } return; - } - /* @internal @@ -184,62 +182,57 @@ */ inline static void -_cpl_frameset_cache_push(const cpl_frameset *self, cpl_frameset_cacheid id, +_cpl_frameset_cache_push(const cpl_frameset *self, + cpl_frameset_cacheid id, cx_multimap_const_iterator position) { - - cpl_frameset * myself = (cpl_frameset *)self; + cpl_frameset *myself = (cpl_frameset *)self; switch (id) { - case TAG: - myself->cache.tag = (cx_multimap_iterator)position; - break; - - case POS: - myself->cache.pos = (cx_multimap_iterator)position; - break; - - case ALL: - myself->cache.tag = (cx_multimap_iterator)position; - myself->cache.pos = (cx_multimap_iterator)position; - break; + case TAG: + myself->cache.tag = (cx_multimap_iterator)position; + break; + + case POS: + myself->cache.pos = (cx_multimap_iterator)position; + break; + + case ALL: + myself->cache.tag = (cx_multimap_iterator)position; + myself->cache.pos = (cx_multimap_iterator)position; + break; } return; - } inline static cx_multimap_iterator _cpl_frameset_cache_get(const cpl_frameset *self, cpl_frameset_cacheid id) { - cxptr entry; switch (id) { - case TAG: - entry = self->cache.tag; - break; - - case POS: - entry = self->cache.pos; - break; - - default: - entry = NULL; - break; + case TAG: + entry = self->cache.tag; + break; + + case POS: + entry = self->cache.pos; + break; + + default: + entry = NULL; + break; } return entry; - } static cxbool _cpl_frameset_compare(cxcptr s, cxcptr t) { - return strcmp(s, t) < 0 ? TRUE : FALSE; - } @@ -251,7 +244,6 @@ inline static cpl_frame * _cpl_frameset_get(const cpl_frameset *self, const char *tag) { - cx_multimap_iterator entry; @@ -261,7 +253,6 @@ return NULL; return cx_multimap_get_value(self->frames, entry); - } @@ -270,62 +261,54 @@ */ inline static void -_cpl_frameset_history_merge(cx_list *self, cx_list *other, +_cpl_frameset_history_merge(cx_list *self, + cx_list *other, const cx_multimap *frames, cpl_frame_compare_func compare) { - cx_assert((self != NULL) && (other != NULL)); cx_assert(frames != NULL); cx_assert(compare != NULL); if (self != other) { - cx_list_iterator first1 = cx_list_begin(self); - cx_list_iterator last1 = cx_list_end(self); + cx_list_iterator last1 = cx_list_end(self); cx_list_iterator first2 = cx_list_begin(other); - cx_list_iterator last2 = cx_list_end(other); + cx_list_iterator last2 = cx_list_end(other); while ((first1 != last1) && (first2 != last2)) { - cx_multimap_const_iterator node1 = cx_list_get(self, first1); cx_multimap_const_iterator node2 = cx_list_get(other, first2); if (compare(cx_multimap_get_value(frames, node1), cx_multimap_get_value(frames, node2)) > 0) { - cx_list_iterator next = cx_list_next(other, first2); - cx_list_splice(self, first1, other,first2, next); + cx_list_splice(self, first1, other, first2, next); first2 = next; - } else { first1 = cx_list_next(self, first1); } - } if (first2 != last2) { cx_list_splice(self, last1, other, first2, last2); } - } return; - } inline static cpl_error_code -_cpl_frameset_history_sort(cx_list *self, const cx_multimap *frames, +_cpl_frameset_history_sort(cx_list *self, + const cx_multimap *frames, cpl_frame_compare_func compare) { - if (cx_list_size(self) > 1) { - cx_list *tmp = cx_list_new(); cx_list_iterator position = cx_list_begin(self); @@ -335,8 +318,8 @@ position = cx_list_next(self, position); } - cx_list_splice(tmp, cx_list_begin(tmp), - self, position, cx_list_end(self)); + cx_list_splice(tmp, cx_list_begin(tmp), self, position, + cx_list_end(self)); _cpl_frameset_history_sort(self, frames, compare); _cpl_frameset_history_sort(tmp, frames, compare); @@ -345,18 +328,15 @@ cx_assert(cx_list_empty(tmp)); cx_list_delete(tmp); - } return CPL_ERROR_NONE; - } inline static cpl_frame * _cpl_frameset_get_first(const cpl_frameset *self) { - cx_list_iterator first; cx_multimap_iterator position; @@ -373,14 +353,12 @@ _cpl_frameset_cache_push(self, POS, position); return cx_multimap_get_value(self->frames, position); - } inline static cpl_frame * _cpl_frameset_get_next(const cpl_frameset *self) { - cx_list_iterator first; cx_list_iterator last; @@ -394,7 +372,6 @@ last = cx_list_end(self->history); while (first != last) { - next = cx_list_get(self->history, first); if (next == _cpl_frameset_cache_get(self, POS)) { @@ -402,10 +379,9 @@ } first = cx_list_next(self->history, first); - } - first = cx_list_next(self->history, first); + first = cx_list_next(self->history, first); if (first == cx_list_end(self->history)) { return NULL; } @@ -419,7 +395,6 @@ _cpl_frameset_cache_push(self, POS, next); return cx_multimap_get_value(self->frames, next); - } @@ -441,17 +416,15 @@ cpl_frameset * cpl_frameset_new(void) { - cpl_frameset *self = cx_malloc(sizeof *self); self->frames = cx_multimap_new(_cpl_frameset_compare, NULL, - (cx_free_func)cpl_frame_delete); + (cx_free_func)cpl_frame_delete); self->history = cx_list_new(); _cpl_frameset_cache_reset(self, ALL); return self; - } @@ -484,8 +457,6 @@ cpl_frameset * cpl_frameset_duplicate(const cpl_frameset *other) { - - cx_list_iterator first, last; cpl_frameset *self = NULL; @@ -502,7 +473,6 @@ last = cx_list_end(other->history); while (first != last) { - cx_multimap_iterator position = cx_list_get(other->history, first); cpl_frame *frame = cx_multimap_get_value(other->frames, position); @@ -513,13 +483,11 @@ cx_list_push_back(self->history, position); first = cx_list_next(other->history, first); - } _cpl_frameset_cache_reset(self, ALL); return self; - } @@ -538,7 +506,6 @@ void cpl_frameset_delete(cpl_frameset *self) { - if (self) { cx_multimap_delete(self->frames); cx_list_delete(self->history); @@ -546,7 +513,6 @@ } return; - } @@ -578,16 +544,12 @@ cpl_size cpl_frameset_get_size(const cpl_frameset *self) { - - - if (self == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return 0; } return cx_multimap_size(self->frames); - } @@ -618,16 +580,12 @@ int cpl_frameset_is_empty(const cpl_frameset *self) { - - - if (self == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return 0; } return cx_multimap_empty(self->frames); - } @@ -661,16 +619,12 @@ int cpl_frameset_count_tags(const cpl_frameset *self, const char *tag) { - - - if (self == NULL || tag == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return 0; } return cx_multimap_count(self->frames, tag); - } @@ -716,22 +670,18 @@ const cpl_frame * cpl_frameset_find_const(const cpl_frameset *self, const char *tag) { - - cx_multimap_iterator pos; cx_multimap_iterator cached; cpl_frame *frame; - if (self == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return NULL; } if (tag) { - /* * Find the first frame with this tag in the set. Make sure that * we really found something. @@ -744,10 +694,8 @@ _cpl_frameset_cache_reset(self, TAG); return NULL; } - } else { - cxptr last_tag; @@ -771,7 +719,6 @@ if (pos == cx_multimap_upper_bound(self->frames, last_tag)) { return NULL; } - } /* Will modify internals of self! */ @@ -779,7 +726,6 @@ frame = cx_multimap_get_value(self->frames, pos); return frame; - } /** @@ -824,7 +770,6 @@ cpl_frame * cpl_frameset_find(cpl_frameset *self, const char *tag) { - cpl_errorstate prestate = cpl_errorstate_get(); cpl_frame *frame = (cpl_frame *)cpl_frameset_find_const(self, tag); @@ -871,15 +816,12 @@ const cpl_frame * cpl_frameset_get_first_const(const cpl_frameset *self) { - - if (self == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return NULL; } return (const cpl_frame *)_cpl_frameset_get_first(self); - } /** @@ -918,15 +860,12 @@ cpl_frame * cpl_frameset_get_first(cpl_frameset *self) { - - if (self == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return NULL; } return _cpl_frameset_get_first(self); - } /** @@ -969,16 +908,12 @@ const cpl_frame * cpl_frameset_get_next_const(const cpl_frameset *self) { - - - if (self == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return NULL; } return (const cpl_frame *)_cpl_frameset_get_next(self); - } @@ -1022,16 +957,15 @@ cpl_frame * cpl_frameset_get_next(cpl_frameset *self) { - - if (self == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return NULL; } return _cpl_frameset_get_next(self); - } + + /** * @brief * Insert a frame into the given frame set. @@ -1070,7 +1004,7 @@ * * In addition, the frame pointer returned by any member function call * returning a handle to a frameset's member frame, must not be used to - * insert the returned frame into another framset without prior duplication + * insert the returned frame into another frameset without prior duplication * of this frame, and, it must not be used to modify the frames tag without * removing it from the frameset first and re-inserting it with the new * tag afterwards. @@ -1079,9 +1013,6 @@ cpl_error_code cpl_frameset_insert(cpl_frameset *self, cpl_frame *frame) { - - - const cxchar *tag = NULL; cx_multimap_iterator position; @@ -1102,7 +1033,6 @@ cx_list_push_back(self->history, position); return CPL_ERROR_NONE; - } @@ -1138,8 +1068,6 @@ cpl_size cpl_frameset_erase(cpl_frameset *self, const char *tag) { - - cxsize count = 0; cx_multimap_iterator first; @@ -1157,12 +1085,10 @@ position = first; while (position != last) { - - cx_assert(strcmp(cx_multimap_get_key(self->frames, position), - tag) == 0); + cx_assert(strcmp(cx_multimap_get_key(self->frames, position), tag) == + 0); if (_cpl_frameset_cache_get(self, TAG) == position) { - cx_multimap_iterator p; p = cx_multimap_previous(self->frames, position); @@ -1175,7 +1101,6 @@ } if (_cpl_frameset_cache_get(self, POS) == position) { - cx_list_iterator p = cx_list_begin(self->history); while (cx_list_get(self->history, p) != position && @@ -1191,20 +1116,17 @@ } _cpl_frameset_cache_push(self, POS, cx_list_get(self->history, p)); - } ++count; cx_list_remove(self->history, position); position = cx_multimap_next(self->frames, position); - } cx_multimap_erase_range(self->frames, first, last); return count; - } @@ -1240,8 +1162,6 @@ cpl_error_code cpl_frameset_erase_frame(cpl_frameset *self, cpl_frame *frame) { - - cx_multimap_iterator first, last; @@ -1258,9 +1178,7 @@ while (first != last) { if (cx_multimap_get_value(self->frames, first) == frame) { - if (_cpl_frameset_cache_get(self, TAG) == first) { - cx_multimap_iterator p; p = cx_multimap_previous(self->frames, first); @@ -1273,7 +1191,6 @@ } if (_cpl_frameset_cache_get(self, POS) == first) { - cx_list_iterator p = cx_list_begin(self->history); while (cx_list_get(self->history, p) != first && @@ -1290,7 +1207,6 @@ _cpl_frameset_cache_push(self, POS, cx_list_get(self->history, p)); - } cx_multimap_erase_position(self->frames, first); @@ -1302,7 +1218,6 @@ } return CPL_ERROR_NONE; - } @@ -1338,23 +1253,18 @@ cpl_error_code cpl_frameset_join(cpl_frameset *self, const cpl_frameset *other) { - - - if (self == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } if ((other != NULL) && (cpl_frameset_is_empty(other) != 1)) { - cx_multimap_iterator position = cx_multimap_begin(other->frames); cpl_error_code status = CPL_ERROR_NONE; while (position != cx_multimap_end(other->frames)) { - - cpl_frame *frame = cx_multimap_get_value(other->frames, position); + cpl_frame *frame = cx_multimap_get_value(other->frames, position); frame = cpl_frame_duplicate(frame); @@ -1373,13 +1283,10 @@ } position = cx_multimap_next(other->frames, position); - } - } return CPL_ERROR_NONE; - } @@ -1424,15 +1331,11 @@ cpl_error_code cpl_frameset_sort(cpl_frameset *self, cpl_frame_compare_func compare) { - - - if ((self == NULL) || (compare == NULL)) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } return _cpl_frameset_history_sort(self->history, self->frames, compare); - } @@ -1479,10 +1382,9 @@ cpl_size * cpl_frameset_labelise(const cpl_frameset *self, - int (*compare)(const cpl_frame*, const cpl_frame*), + int (*compare)(const cpl_frame *, const cpl_frame *), cpl_size *nb_labels) { - cpl_size *labels; cpl_size *labelsinv; cpl_size nframes; @@ -1490,36 +1392,33 @@ cpl_size j = 0; cpl_size nlabels = 0; cpl_size ncomp = 0; - const cpl_frame ** framelist; - const cpl_frame * frame1; + const cpl_frame **framelist; + const cpl_frame *frame1; cpl_frameset_iterator *it = NULL; - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(compare != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(compare != NULL, CPL_ERROR_NULL_INPUT, NULL); cpl_ensure(nb_labels != NULL, CPL_ERROR_NULL_INPUT, NULL); nframes = cpl_frameset_get_size(self); cpl_ensure(nframes >= 1, CPL_ERROR_ILLEGAL_INPUT, NULL); - labels = cx_malloc(nframes * sizeof(cpl_size)); + labels = cx_malloc(nframes * sizeof(cpl_size)); labelsinv = cx_malloc(nframes * sizeof(cpl_size)); framelist = cx_malloc(nframes * sizeof(const cpl_frame *)); it = cpl_frameset_iterator_new(self); - while ((frame1 = cpl_frameset_iterator_get(it)) != NULL) - { - - cpl_errorstate status; + while ((frame1 = cpl_frameset_iterator_get(it)) != NULL) { + cpl_errorstate status; cpl_size jj; for (jj = 0; jj < nlabels; jj++, j = (j == nlabels - 1) ? 0 : j + 1) { - const cpl_frame *frame2 = framelist[j]; /* @@ -1536,10 +1435,11 @@ if (comp == 1) { /* Identical */ break; - } else if (comp != 0) { + } + else if (comp != 0) { /* Error */ - cpl_frameset_iterator_delete(it); + cpl_frameset_iterator_delete(it); cx_free(framelist); cx_free(labelsinv); @@ -1557,24 +1457,22 @@ framelist[nlabels] = frame1; labelsinv[nlabels] = i; labels[i] = nlabels++; - - } else { + } + else { /* Identical */ labels[i] = labels[labelsinv[j]]; } - status = cpl_errorstate_get(); + status = cpl_errorstate_get(); - cpl_frameset_iterator_advance(it, 1); + cpl_frameset_iterator_advance(it, 1); - if (cpl_error_get_code() == CPL_ERROR_ACCESS_OUT_OF_RANGE) - { + if (cpl_error_get_code() == CPL_ERROR_ACCESS_OUT_OF_RANGE) { cpl_errorstate_set(status); } - ++i; - + ++i; } cpl_frameset_iterator_delete(it); @@ -1584,12 +1482,12 @@ cx_free(framelist); cx_free(labelsinv); - cpl_msg_debug(cpl_func, "%" CPL_SIZE_FORMAT " frames labelized with %" - CPL_SIZE_FORMAT " labels after %" CPL_SIZE_FORMAT - "comparisons", nframes, nlabels, ncomp); + cpl_msg_debug(cpl_func, + "%" CPL_SIZE_FORMAT " frames labelized with %" CPL_SIZE_FORMAT + " labels after %" CPL_SIZE_FORMAT " comparisons", + nframes, nlabels, ncomp); return labels; - } @@ -1645,8 +1543,6 @@ const cpl_frame * cpl_frameset_get_frame_const(const cpl_frameset *set, cpl_size position) { - - if (set == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return NULL; @@ -1658,7 +1554,6 @@ } return cpl_frameset_get_position_const(set, position); - } @@ -1715,8 +1610,6 @@ cpl_frame * cpl_frameset_get_frame(cpl_frameset *set, cpl_size position) { - - if (set == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return NULL; @@ -1728,7 +1621,6 @@ } return cpl_frameset_get_position(set, position); - } @@ -1769,8 +1661,6 @@ cpl_frame * cpl_frameset_get_position(cpl_frameset *self, cpl_size position) { - - cx_list_iterator _position = NULL; cx_multimap_iterator frame = NULL; @@ -1800,7 +1690,6 @@ cx_assert(frame != cx_multimap_end(self->frames)); return cx_multimap_get_value(self->frames, frame); - } @@ -1841,8 +1730,6 @@ const cpl_frame * cpl_frameset_get_position_const(const cpl_frameset *self, cpl_size position) { - - cx_list_iterator _position = NULL; cx_multimap_iterator frame = NULL; @@ -1872,7 +1759,6 @@ cx_assert(frame != cx_multimap_end(self->frames)); return cx_multimap_get_value(self->frames, frame); - } @@ -1905,24 +1791,22 @@ */ cpl_frameset * -cpl_frameset_extract(const cpl_frameset *self, const cpl_size *labels, +cpl_frameset_extract(const cpl_frameset *self, + const cpl_size *labels, cpl_size desired_label) { - - cpl_frameset *selected = NULL; + cpl_frameset *selected = NULL; const cpl_frame *frame; cpl_size i = 0; - cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL); cpl_ensure(labels != NULL, CPL_ERROR_NULL_INPUT, NULL); cpl_frameset_iterator *it = cpl_frameset_iterator_new(self); while ((frame = cpl_frameset_iterator_get_const(it))) { - if (labels[i] == desired_label) { - /* * Duplicate frame and insert it in the selected object */ @@ -1934,7 +1818,6 @@ } cpl_frameset_insert(selected, _frame); - } @@ -1942,19 +1825,16 @@ cpl_frameset_iterator_advance(it, 1); - if (cpl_error_get_code() == CPL_ERROR_ACCESS_OUT_OF_RANGE) - { + if (cpl_error_get_code() == CPL_ERROR_ACCESS_OUT_OF_RANGE) { cpl_errorstate_set(status); } ++i; - } cpl_frameset_iterator_delete(it); return selected; - } /** @@ -1990,12 +1870,11 @@ if (n == 0) return; - fprintf (stream, "+++ Frameset at address: %p\n", (const void *)self); + fprintf(stream, "+++ Frameset at address: %p\n", (const void *)self); cpl_frameset_iterator *it = cpl_frameset_iterator_new(self); while ((frame = cpl_frameset_iterator_get_const(it))) { - fprintf(stream, "%3d ", i++); cpl_frame_dump(frame, stream); @@ -2003,11 +1882,9 @@ cpl_frameset_iterator_advance(it, 1); - if (cpl_error_get_code() == CPL_ERROR_ACCESS_OUT_OF_RANGE) - { + if (cpl_error_get_code() == CPL_ERROR_ACCESS_OUT_OF_RANGE) { cpl_errorstate_set(status); } - } cpl_frameset_iterator_delete(it); @@ -2090,8 +1967,6 @@ cpl_frameset_iterator * cpl_frameset_iterator_new(const cpl_frameset *parent) { - - cpl_frameset_iterator *self = NULL; @@ -2103,12 +1978,11 @@ self = cx_malloc(sizeof *self); - self->parent = parent; - self->position = cx_list_begin(parent->history); + self->parent = parent; + self->position = cx_list_begin(parent->history); self->direction = 0; return self; - } @@ -2142,8 +2016,6 @@ cpl_frameset_iterator * cpl_frameset_iterator_duplicate(const cpl_frameset_iterator *other) { - - cpl_frameset_iterator *self = NULL; @@ -2154,12 +2026,11 @@ self = cx_malloc(sizeof *self); - self->parent = other->parent; - self->position = other->position; + self->parent = other->parent; + self->position = other->position; self->direction = other->direction; return self; - } @@ -2223,9 +2094,6 @@ cpl_frameset_iterator_assign(cpl_frameset_iterator *self, const cpl_frameset_iterator *other) { - - - if ((self == NULL) || (other == NULL)) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } @@ -2235,11 +2103,10 @@ } - self->position = other->position; + self->position = other->position; self->direction = other->direction; return CPL_ERROR_NONE; - } @@ -2262,14 +2129,12 @@ void cpl_frameset_iterator_reset(cpl_frameset_iterator *self) { - if (self != NULL) { - self->position = cx_list_begin(self->parent->history); + self->position = cx_list_begin(self->parent->history); self->direction = 0; } return; - } @@ -2316,20 +2181,16 @@ cpl_error_code cpl_frameset_iterator_advance(cpl_frameset_iterator *self, int distance) { - - if (self == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } else { - cxint _distance = distance; cx_list_iterator position = self->position; if (_distance < 0) { - if (self->direction == -1) { position = cx_list_previous(self->parent->history, position); ++_distance; @@ -2340,10 +2201,8 @@ position = cx_list_previous(self->parent->history, position); ++_distance; } - } else { - if (self->direction == 1) { position = cx_list_begin(self->parent->history); --_distance; @@ -2354,16 +2213,12 @@ position = cx_list_next(self->parent->history, position); --_distance; } - } if (_distance != 0) { - return cpl_error_set_(CPL_ERROR_ACCESS_OUT_OF_RANGE); - } else { - if (position == cx_list_end(self->parent->history)) { self->direction = (distance < 0) ? 1 : -1; } @@ -2373,11 +2228,9 @@ self->position = position; } - } return CPL_ERROR_NONE; - } @@ -2429,8 +2282,6 @@ cpl_frameset_iterator_distance(const cpl_frameset_iterator *self, const cpl_frameset_iterator *other) { - - int invalid = 0; @@ -2450,7 +2301,6 @@ */ if (self->position != other->position) { - /* * ... otherwise try forward direction first ... */ @@ -2459,14 +2309,12 @@ cx_list_iterator position = self->position; while (position != cx_list_end(self->parent->history)) { - if (position == other->position) { return distance; } ++distance; position = cx_list_next(self->parent->history, position); - } @@ -2478,14 +2326,12 @@ position = self->position; while (position != cx_list_end(self->parent->history)) { - if (position == other->position) { return distance; } --distance; position = cx_list_previous(self->parent->history, position); - } @@ -2495,11 +2341,9 @@ cpl_error_set_(CPL_ERROR_DATA_NOT_FOUND); return invalid; - } return 0; - } @@ -2533,8 +2377,6 @@ cpl_frame * cpl_frameset_iterator_get(cpl_frameset_iterator *self) { - - cx_multimap_iterator position = NULL; @@ -2551,7 +2393,6 @@ cx_assert(position != cx_multimap_end(self->parent->frames)); return cx_multimap_get_value(self->parent->frames, position); - } @@ -2585,8 +2426,6 @@ const cpl_frame * cpl_frameset_iterator_get_const(const cpl_frameset_iterator *self) { - - cx_multimap_iterator position = NULL; @@ -2603,6 +2442,5 @@ cx_assert(position != cx_multimap_end(self->parent->frames)); return cx_multimap_get_value(self->parent->frames, position); - } /**@}*/ diff -Nru cpl-7.1.4+ds/cplui/cpl_frameset.h cpl-7.2.2+ds/cplui/cpl_frameset.h --- cpl-7.1.4+ds/cplui/cpl_frameset.h 2021-05-07 12:09:09.000000000 +0000 +++ cpl-7.2.2+ds/cplui/cpl_frameset.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -61,18 +61,20 @@ * Search operations */ -const cpl_frame *cpl_frameset_find_const(const cpl_frameset *self, - const char *tag); +const cpl_frame * +cpl_frameset_find_const(const cpl_frameset *self, const char *tag); cpl_frame *cpl_frameset_find(cpl_frameset *self, const char *tag); /* * Sequential access */ -const cpl_frame *cpl_frameset_get_first_const(const cpl_frameset *self) CPL_ATTR_DEPRECATED; +const cpl_frame * +cpl_frameset_get_first_const(const cpl_frameset *self) CPL_ATTR_DEPRECATED; cpl_frame *cpl_frameset_get_first(cpl_frameset *self) CPL_ATTR_DEPRECATED; -const cpl_frame *cpl_frameset_get_next_const(const cpl_frameset *self) CPL_ATTR_DEPRECATED; +const cpl_frame * +cpl_frameset_get_next_const(const cpl_frameset *self) CPL_ATTR_DEPRECATED; cpl_frame *cpl_frameset_get_next(cpl_frameset *self) CPL_ATTR_DEPRECATED; /* @@ -87,31 +89,34 @@ * Element access */ -const cpl_frame *cpl_frameset_get_frame_const(const cpl_frameset *self, - cpl_size position) CPL_ATTR_DEPRECATED; -cpl_frame *cpl_frameset_get_frame(cpl_frameset *self, cpl_size position) CPL_ATTR_DEPRECATED; +const cpl_frame * +cpl_frameset_get_frame_const(const cpl_frameset *self, + cpl_size position) CPL_ATTR_DEPRECATED; +cpl_frame *cpl_frameset_get_frame(cpl_frameset *self, + cpl_size position) CPL_ATTR_DEPRECATED; cpl_frame *cpl_frameset_get_position(cpl_frameset *self, cpl_size position); -const cpl_frame *cpl_frameset_get_position_const(const cpl_frameset *self, - cpl_size position); +const cpl_frame * +cpl_frameset_get_position_const(const cpl_frameset *self, cpl_size position); /* * Miscellaneous functions */ cpl_error_code cpl_frameset_join(cpl_frameset *self, const cpl_frameset *other); -cpl_error_code cpl_frameset_sort(cpl_frameset *self, - cpl_frame_compare_func compare); +cpl_error_code +cpl_frameset_sort(cpl_frameset *self, cpl_frame_compare_func compare); cpl_frameset *cpl_frameset_extract(const cpl_frameset *self, const cpl_size *labels, cpl_size desired_label) CPL_ATTR_ALLOC; -cpl_size *cpl_frameset_labelise(const cpl_frameset *self, - int (*compare)(const cpl_frame *, - const cpl_frame *), cpl_size *nb_labels); +cpl_size * +cpl_frameset_labelise(const cpl_frameset *self, + int (*compare)(const cpl_frame *, const cpl_frame *), + cpl_size *nb_labels); void cpl_frameset_dump(const cpl_frameset *self, FILE *stream); @@ -139,8 +144,8 @@ cpl_frameset_iterator * cpl_frameset_iterator_new(const cpl_frameset *parent) CPL_ATTR_ALLOC; -cpl_frameset_iterator * -cpl_frameset_iterator_duplicate(const cpl_frameset_iterator *other) CPL_ATTR_ALLOC; +cpl_frameset_iterator *cpl_frameset_iterator_duplicate( + const cpl_frameset_iterator *other) CPL_ATTR_ALLOC; void cpl_frameset_iterator_delete(cpl_frameset_iterator *self); @@ -148,16 +153,15 @@ * Iterator assignment */ -cpl_error_code -cpl_frameset_iterator_assign(cpl_frameset_iterator *self, - const cpl_frameset_iterator *other); +cpl_error_code cpl_frameset_iterator_assign(cpl_frameset_iterator *self, + const cpl_frameset_iterator *other); /* * Iterator positioning */ -cpl_error_code cpl_frameset_iterator_advance(cpl_frameset_iterator *self, - int distance); +cpl_error_code +cpl_frameset_iterator_advance(cpl_frameset_iterator *self, int distance); int cpl_frameset_iterator_distance(const cpl_frameset_iterator *self, const cpl_frameset_iterator *other); diff -Nru cpl-7.1.4+ds/cplui/cpl_frameset_io.c cpl-7.2.2+ds/cplui/cpl_frameset_io.c --- cpl-7.1.4+ds/cplui/cpl_frameset_io.c 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplui/cpl_frameset_io.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -40,7 +40,6 @@ #include - /** * @defgroup cpl_frameset_io Frame Sets IO functions * @@ -57,9 +56,12 @@ */ -static cpl_error_code -cpl_imagelist_append_from_file(cpl_imagelist *, cpl_size *, const char *, - cpl_type, cpl_size, cpl_size); +static cpl_error_code cpl_imagelist_append_from_file(cpl_imagelist *, + cpl_size *, + const char *, + cpl_type, + cpl_size, + cpl_size); /*----------------------------------------------------------------------------*/ /** @@ -77,20 +79,21 @@ or one image cannot be loaded as specified */ /*----------------------------------------------------------------------------*/ -cpl_imagelist * cpl_imagelist_load_frameset(const cpl_frameset * fset, - cpl_type im_type, - cpl_size pnum, - cpl_size xtnum) +cpl_imagelist * +cpl_imagelist_load_frameset(const cpl_frameset *fset, + cpl_type im_type, + cpl_size pnum, + cpl_size xtnum) { - cpl_imagelist * self; - const cpl_frame * cur_frame; - cpl_size selfsize; + cpl_imagelist *self; + const cpl_frame *cur_frame; + cpl_size selfsize; /* Test entries */ - cpl_ensure(fset != NULL, CPL_ERROR_NULL_INPUT, NULL); - cpl_ensure(pnum >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL); - cpl_ensure(xtnum >= -1, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(fset != NULL, CPL_ERROR_NULL_INPUT, NULL); + cpl_ensure(pnum >= 0, CPL_ERROR_ILLEGAL_INPUT, NULL); + cpl_ensure(xtnum >= -1, CPL_ERROR_ILLEGAL_INPUT, NULL); /* Create empty output image list */ self = cpl_imagelist_new(); @@ -99,7 +102,7 @@ cpl_frameset_iterator *it = cpl_frameset_iterator_new(fset); while ((cur_frame = cpl_frameset_iterator_get_const(it)) != NULL) { - const char * filename = cpl_frame_get_filename(cur_frame); + const char *filename = cpl_frame_get_filename(cur_frame); cpl_errorstate prestate; @@ -107,18 +110,18 @@ /* Image(s) from all extensions requested. */ - int nextensions, ixtnum; + int nextensions, ixtnum; const cpl_size presize = selfsize; - fitsfile * fptr; - int error = 0; + fitsfile *fptr; + int error = 0; prestate = cpl_errorstate_get(); /* Initialize to indicate that they need to be read from the file */ - int naxis = 0; - CPL_FITSIO_TYPE naxes[3] ={0, 0, 0}; - cpl_type pix_type = im_type; + int naxis = 0; + CPL_FITSIO_TYPE naxes[3] = { 0, 0, 0 }; + cpl_type pix_type = im_type; /* FIXME: Version 3.2 of fits_open_diskfile() seg-faults on NULL. If fixed in CFITSIO, this check should be removed */ @@ -131,20 +134,24 @@ if (cpl_io_fits_open_diskfile(&fptr, filename, READONLY, &error)) { (void)cpl_error_set_fits(CPL_ERROR_ILLEGAL_INPUT, error, - fits_open_diskfile, "filename='%s', " + fits_open_diskfile, + "filename='%s', " "im_type=%u, pnum=%" CPL_SIZE_FORMAT - ", xtnum=%" CPL_SIZE_FORMAT, filename, - (unsigned)im_type, pnum, xtnum); + ", xtnum=%" CPL_SIZE_FORMAT, + filename, (unsigned)im_type, pnum, + xtnum); break; } /* Get the number of extensions (the primary HDU counts as one) */ if (fits_get_num_hdus(fptr, &nextensions, &error)) { (void)cpl_error_set_fits(CPL_ERROR_ILLEGAL_INPUT, error, - fits_get_num_hdus, "filename='%s', " + fits_get_num_hdus, + "filename='%s', " "im_type=%u, pnum=%" CPL_SIZE_FORMAT - ", xtnum=%" CPL_SIZE_FORMAT, filename, - (unsigned)im_type, pnum, xtnum); + ", xtnum=%" CPL_SIZE_FORMAT, + filename, (unsigned)im_type, pnum, + xtnum); /* Ensure that the file is closed below */ error = nextensions = 0; } @@ -156,14 +163,13 @@ /* Load 1 image from the extension. This will set naxis and naxes[] (and optionally the pixel type) for use in subsequent calls */ - cpl_image * image = cpl_image_load_(fptr, &naxis, naxes, - &pix_type, filename, - iplane, ixtnum, - CPL_FALSE, 0, 0, 0, 0); + cpl_image *image = + cpl_image_load_(fptr, &naxis, naxes, &pix_type, filename, + iplane, ixtnum, CPL_FALSE, 0, 0, 0, 0); if (!cpl_errorstate_is_equal(prestate)) { - if (cpl_error_get_code() == CPL_ERROR_DATA_NOT_FOUND - && ixtnum == 0) { + if (cpl_error_get_code() == CPL_ERROR_DATA_NOT_FOUND && + ixtnum == 0) { /* Main HDU allowed to not have image data */ cpl_errorstate_set(prestate); continue; @@ -184,7 +190,8 @@ image = cpl_image_load_(fptr, &naxis, naxes, &pix_type, filename, iplane, ixtnum, CPL_FALSE, 0, 0, 0, 0); - if (image == NULL) break; + if (image == NULL) + break; if (cpl_imagelist_set(self, image, selfsize)) { cpl_image_delete(image); @@ -193,23 +200,28 @@ selfsize++; } - if (iplane < naxes[2]) break; + if (iplane < naxes[2]) + break; } } if (cpl_io_fits_close_file(fptr, &error)) { (void)cpl_error_set_fits(CPL_ERROR_BAD_FILE_FORMAT, error, - fits_close_file, "filename='%s', " + fits_close_file, + "filename='%s', " "im_type=%u, pnum=%" CPL_SIZE_FORMAT - ", xtnum=%" CPL_SIZE_FORMAT, filename, - (unsigned)im_type, pnum, xtnum); + ", xtnum=%" CPL_SIZE_FORMAT, + filename, (unsigned)im_type, pnum, + xtnum); } - if (ixtnum < nextensions || selfsize == presize) break; - - } else { + if (ixtnum < nextensions || selfsize == presize) + break; + } + else { if (cpl_imagelist_append_from_file(self, &selfsize, filename, - im_type, pnum, xtnum)) break; + im_type, pnum, xtnum)) + break; } prestate = cpl_errorstate_get(); @@ -221,14 +233,14 @@ cpl_errorstate_set(prestate); } } - } if (cur_frame != NULL) { - const char * filename = cpl_frame_get_filename(cur_frame); + const char *filename = cpl_frame_get_filename(cur_frame); cpl_imagelist_delete(self); - (void)cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, "file=%s, " + (void)cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, + "file=%s, " "im_type=%u, pnum=%" CPL_SIZE_FORMAT ", xtnum=%" CPL_SIZE_FORMAT, filename ? filename : "", @@ -241,13 +253,14 @@ /* Require created imagelist to be non-empty */ if (selfsize == 0) { - const char * filename = cpl_frame_get_filename(cur_frame); + const char *filename = cpl_frame_get_filename(cur_frame); cpl_imagelist_delete(self); - (void)cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, "file=%s, " + (void)cpl_error_set_message_(CPL_ERROR_ILLEGAL_INPUT, + "file=%s, " "im_type=%d, pnum=%" CPL_SIZE_FORMAT ", xtnum=%" CPL_SIZE_FORMAT, - filename ? filename : "", - im_type, pnum, xtnum); + filename ? filename : "", im_type, + pnum, xtnum); cpl_frameset_iterator_delete(it); return NULL; } @@ -255,7 +268,6 @@ cpl_frameset_iterator_delete(it); return self; - } /**@}*/ @@ -279,32 +291,31 @@ or one image cannot be loaded as specified */ /*----------------------------------------------------------------------------*/ -static cpl_error_code cpl_imagelist_append_from_file(cpl_imagelist * self, - cpl_size * pselfsize, - const char * filename, - cpl_type im_type, - cpl_size pnum, - cpl_size xtnum) +static cpl_error_code +cpl_imagelist_append_from_file(cpl_imagelist *self, + cpl_size *pselfsize, + const char *filename, + cpl_type im_type, + cpl_size pnum, + cpl_size xtnum) { - cpl_size selfsize = cpl_imagelist_get_size(self); - cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT); cpl_ensure_code(pselfsize != NULL, CPL_ERROR_NULL_INPUT); - cpl_ensure_code(filename != NULL, CPL_ERROR_NULL_INPUT); + cpl_ensure_code(filename != NULL, CPL_ERROR_NULL_INPUT); if (pnum == 0) { /* All planes required */ - cpl_imagelist * onelist = cpl_imagelist_load(filename, im_type, - xtnum); + cpl_imagelist *onelist = cpl_imagelist_load(filename, im_type, xtnum); const cpl_size onesize = cpl_imagelist_get_size(onelist); - cpl_size j; + cpl_size j; cpl_ensure_code(onelist != NULL, CPL_ERROR_ILLEGAL_INPUT); /* Move the images from onelist to self */ for (j = 0; j < onesize; j++) { - cpl_image * img = cpl_imagelist_unset(onelist, 0); + cpl_image *img = cpl_imagelist_unset(onelist, 0); if (cpl_imagelist_set(self, img, selfsize)) { /* Type or size could differ */ @@ -316,9 +327,10 @@ } cx_assert(cpl_imagelist_get_size(onelist) == 0); cpl_imagelist_delete(onelist); - } else { + } + else { /* Only one plane required */ - cpl_image * img = cpl_image_load(filename, im_type, pnum-1, xtnum); + cpl_image *img = cpl_image_load(filename, im_type, pnum - 1, xtnum); cpl_ensure_code(img != NULL, CPL_ERROR_ILLEGAL_INPUT); if (cpl_imagelist_set(self, img, selfsize)) { /* Type or size could differ */ @@ -333,5 +345,4 @@ *pselfsize = selfsize; return CPL_ERROR_NONE; - } diff -Nru cpl-7.1.4+ds/cplui/cpl_frameset_io.h cpl-7.2.2+ds/cplui/cpl_frameset_io.h --- cpl-7.1.4+ds/cplui/cpl_frameset_io.h 2021-05-07 12:09:11.000000000 +0000 +++ cpl-7.2.2+ds/cplui/cpl_frameset_io.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -28,8 +28,10 @@ CPL_BEGIN_DECLS /* Load an image list from a frame set */ -cpl_imagelist * cpl_imagelist_load_frameset(const cpl_frameset *, cpl_type, - cpl_size, cpl_size) CPL_ATTR_ALLOC; +cpl_imagelist *cpl_imagelist_load_frameset(const cpl_frameset *, + cpl_type, + cpl_size, + cpl_size) CPL_ATTR_ALLOC; CPL_END_DECLS diff -Nru cpl-7.1.4+ds/cplui/cpl_parameter.c cpl-7.2.2+ds/cplui/cpl_parameter.c --- cpl-7.1.4+ds/cplui/cpl_parameter.c 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplui/cpl_parameter.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -18,7 +18,7 @@ */ #ifdef HAVE_CONFIG_H -# include +#include #endif #include @@ -30,7 +30,6 @@ #include "cpl_error.h" #include "cpl_parameter.h" - /** * @defgroup cpl_parameter Parameters * @@ -141,7 +140,8 @@ typedef struct _cpl_parameter_info_ cpl_parameter_info; -struct _cpl_parameter_info_ { +struct _cpl_parameter_info_ +{ cxbool f_active; cxchar *f_key; @@ -155,12 +155,12 @@ cxbool present; }; - /* * Utility data types to store parameter values */ -union _cpl_parameter_data_ { +union _cpl_parameter_data_ +{ cxchar c; cxbool b; cxint i; @@ -172,8 +172,8 @@ typedef union _cpl_parameter_data_ cpl_parameter_data; - -struct _cpl_parameter_value_ { +struct _cpl_parameter_value_ +{ cpl_type type; cpl_parameter_data data; cpl_parameter_data preset; @@ -181,8 +181,8 @@ typedef struct _cpl_parameter_value_ cpl_parameter_value; - -struct _cpl_parameter_range_ { +struct _cpl_parameter_range_ +{ cpl_parameter_value value; cpl_parameter_data min; cpl_parameter_data max; @@ -190,8 +190,8 @@ typedef struct _cpl_parameter_range_ cpl_parameter_range; - -struct _cpl_parameter_enum_ { +struct _cpl_parameter_enum_ +{ cpl_parameter_value value; cpl_parameter_data *vlist; cxsize sz; @@ -199,8 +199,8 @@ typedef struct _cpl_parameter_enum_ cpl_parameter_enum; - -struct _cpl_parameter_ { +struct _cpl_parameter_ +{ cxchar *name; cxchar *context; cxchar *description; @@ -212,7 +212,6 @@ cpl_parameter_info info; }; - /* * Private functions */ @@ -220,7 +219,6 @@ inline static cxbool _cpl_parameter_validate_type(cpl_type type) { - switch (type) { case CPL_TYPE_BOOL: case CPL_TYPE_INT: @@ -234,163 +232,137 @@ } return TRUE; - } - inline static cxint -_cpl_parameter_data_create(cpl_parameter_data *item, cpl_type type, - va_list *ap) +_cpl_parameter_data_create(cpl_parameter_data *item, cpl_type type, va_list *ap) { - switch (type) { - case CPL_TYPE_CHAR: - { - item->c = (cxchar)va_arg(*ap, cxint); - break; - } + case CPL_TYPE_CHAR: { + item->c = (cxchar)va_arg(*ap, cxint); + break; + } - case CPL_TYPE_BOOL: - { - cxint arg = va_arg(*ap, cxint); - item->b = arg ? TRUE : FALSE; - break; - } + case CPL_TYPE_BOOL: { + cxint arg = va_arg(*ap, cxint); + item->b = arg ? TRUE : FALSE; + break; + } - case CPL_TYPE_INT: - { - item->i = va_arg(*ap, cxint); - break; - } + case CPL_TYPE_INT: { + item->i = va_arg(*ap, cxint); + break; + } - case CPL_TYPE_LONG: - { - item->l = va_arg(*ap, cxlong); - break; - } + case CPL_TYPE_LONG: { + item->l = va_arg(*ap, cxlong); + break; + } - case CPL_TYPE_FLOAT: - { - item->f = (float)va_arg(*ap, cxdouble); - break; - } + case CPL_TYPE_FLOAT: { + item->f = (float)va_arg(*ap, cxdouble); + break; + } - case CPL_TYPE_DOUBLE: - { - item->d = va_arg(*ap, cxdouble); - break; - } + case CPL_TYPE_DOUBLE: { + item->d = va_arg(*ap, cxdouble); + break; + } - case CPL_TYPE_STRING: - { - const cxchar *arg = va_arg(*ap, const cxchar *); + case CPL_TYPE_STRING: { + const cxchar *arg = va_arg(*ap, const cxchar *); - if (item->s) { - cx_free(item->s); - item->s = NULL; - } + if (item->s) { + cx_free(item->s); + item->s = NULL; + } - if (arg) { - item->s = cx_strdup(arg); + if (arg) { + item->s = cx_strdup(arg); + } + break; } - break; - } - default: - return 1; - break; + default: + return 1; + break; } return 0; } - inline static cxint _cpl_parameter_data_set(cpl_parameter_data *item, cpl_type type, cxptr value) { - switch (type) { - case CPL_TYPE_CHAR: - { - item->c = *(cxchar *)value; - break; - } + case CPL_TYPE_CHAR: { + item->c = *(cxchar *)value; + break; + } - case CPL_TYPE_BOOL: - { - cxint arg = *(cxint *)value; - item->b = arg ? TRUE : FALSE; - break; - } + case CPL_TYPE_BOOL: { + cxint arg = *(cxint *)value; + item->b = arg ? TRUE : FALSE; + break; + } - case CPL_TYPE_INT: - { - item->i = *(cxint *)value; - break; - } + case CPL_TYPE_INT: { + item->i = *(cxint *)value; + break; + } - case CPL_TYPE_LONG: - { - item->l = *(cxlong *)value; - break; - } + case CPL_TYPE_LONG: { + item->l = *(cxlong *)value; + break; + } - case CPL_TYPE_FLOAT: - { - item->f = *(cxfloat *)value; - break; - } + case CPL_TYPE_FLOAT: { + item->f = *(cxfloat *)value; + break; + } - case CPL_TYPE_DOUBLE: - { - item->d = *(cxdouble *)value; - break; - } + case CPL_TYPE_DOUBLE: { + item->d = *(cxdouble *)value; + break; + } - case CPL_TYPE_STRING: - { - const cxchar *const arg = *(const cxchar *const *)value; + case CPL_TYPE_STRING: { + const cxchar *const arg = *(const cxchar *const *)value; - if (item->s) { - cx_free(item->s); - item->s = NULL; - } + if (item->s) { + cx_free(item->s); + item->s = NULL; + } - if (arg) { - item->s = cx_strdup(arg); + if (arg) { + item->s = cx_strdup(arg); + } + break; } - break; - } - default: - return 1; - break; + default: + return 1; + break; } return 0; } - inline static cpl_parameter_value * _cpl_parameter_value_new(cpl_type type, cxsize size) { - cpl_parameter_value *self = (cpl_parameter_value *)cx_calloc(1, size); self->type = type; return self; - } - inline static cxint _cpl_parameter_value_create(cpl_parameter *self, va_list *ap) { - cpl_parameter_value *data = NULL; cpl_type type = CPL_TYPE_INVALID; - cx_assert(self != NULL); data = self->data; @@ -407,21 +379,17 @@ } return 0; - } - inline static int _cpl_parameter_value_copy(cpl_parameter *self, const cpl_parameter *other) { - - cpl_parameter_value *data = NULL; + cpl_parameter_value *data = NULL; cpl_parameter_value *_data = NULL; - cx_assert((self != NULL) && (other != NULL)); - data = (cpl_parameter_value *)self->data; + data = (cpl_parameter_value *)self->data; _data = (cpl_parameter_value *)other->data; cx_assert((data != NULL) && (_data != NULL)); @@ -437,14 +405,11 @@ } return 0; - } - inline static void _cpl_parameter_value_destroy(cpl_parameter_value *self) { - if (self->type == CPL_TYPE_STRING) { if (self->data.s) { cx_free(self->data.s); @@ -458,18 +423,14 @@ } return; - } - inline static cxint _cpl_parameter_range_create(cpl_parameter *self, va_list *ap) { - cpl_parameter_range *data = NULL; cpl_type type = CPL_TYPE_INVALID; - cx_assert(self != NULL); data = (cpl_parameter_range *)self->data; @@ -481,8 +442,7 @@ return 1; } - if (_cpl_parameter_data_set(&data->value.data, type, - &data->value.preset)) { + if (_cpl_parameter_data_set(&data->value.data, type, &data->value.preset)) { return 1; } @@ -495,21 +455,16 @@ } return 0; - } - inline static int _cpl_parameter_range_copy(cpl_parameter *self, const cpl_parameter *other) { - - cpl_parameter_range *data = NULL; + cpl_parameter_range *data = NULL; cpl_parameter_range *_data = NULL; - cx_assert((self != NULL) && (other != NULL)); - /* * Copy the value part first */ @@ -518,12 +473,11 @@ return 1; } - /* * Copy domain limits of the range */ - data = (cpl_parameter_range *)self->data; + data = (cpl_parameter_range *)self->data; _data = (cpl_parameter_range *)other->data; cx_assert((data != NULL) && (_data != NULL)); @@ -537,14 +491,11 @@ } return 0; - } - inline static void _cpl_parameter_range_destroy(cpl_parameter_value *self) { - cpl_parameter_range *_self = (cpl_parameter_range *)self; cpl_type type = self->type; @@ -563,20 +514,16 @@ _cpl_parameter_value_destroy(self); return; - } - inline static cxint _cpl_parameter_enum_create(cpl_parameter *self, va_list *ap) { - register cxsize i; cpl_parameter_enum *data = NULL; cpl_type type = CPL_TYPE_INVALID; - cx_assert(self != NULL); data = (cpl_parameter_enum *)self->data; @@ -588,12 +535,10 @@ return 1; } - if (_cpl_parameter_data_set(&data->value.data, type, - &data->value.preset)) { + if (_cpl_parameter_data_set(&data->value.data, type, &data->value.preset)) { return 1; } - /* * Copy the enum alternatives from the argument list. A zero length * list of alternatives is not allowed. @@ -614,23 +559,18 @@ } return 0; - } - inline static int _cpl_parameter_enum_copy(cpl_parameter *self, const cpl_parameter *other) { - register cxsize i = 0; - cpl_parameter_enum *data = NULL; + cpl_parameter_enum *data = NULL; cpl_parameter_enum *_data = NULL; - cx_assert((self != NULL) && (other != NULL)); - /* * Copy the value part first */ @@ -639,12 +579,11 @@ return 1; } - /* * Copy the enum alternatives */ - data = (cpl_parameter_enum *)self->data; + data = (cpl_parameter_enum *)self->data; _data = (cpl_parameter_enum *)other->data; cx_assert((data != NULL) && (_data != NULL)); @@ -663,11 +602,9 @@ return 0; } - inline static void _cpl_parameter_enum_destroy(cpl_parameter_value *self) { - cpl_parameter_enum *_self = (cpl_parameter_enum *)self; cpl_type type = self->type; @@ -688,18 +625,14 @@ _cpl_parameter_value_destroy(self); return; - } - inline static cxint _cpl_parameter_default_set(cpl_parameter *self, cxptr value) { - cpl_parameter_value *data = self->data; cpl_type type = data->type; - cx_assert(value != NULL); if (_cpl_parameter_data_set(&data->preset, type, value)) { @@ -709,15 +642,12 @@ return 0; } - inline static cxint _cpl_parameter_value_set(cpl_parameter *self, cxptr value) { - cpl_parameter_value *data = self->data; cpl_type type = data->type; - cx_assert(value != NULL); if (_cpl_parameter_data_set(&data->data, type, value)) { @@ -725,20 +655,18 @@ } return 0; - } - inline static cpl_parameter * -_cpl_parameter_create(const cxchar *name, const cxchar *description, +_cpl_parameter_create(const cxchar *name, + const cxchar *description, const cxchar *context) { cpl_parameter *self = NULL; - cx_assert(name != 0); - self = (cpl_parameter *) cx_malloc(sizeof(cpl_parameter)); + self = (cpl_parameter *)cx_malloc(sizeof(cpl_parameter)); self->name = cx_strdup(name); self->context = context ? cx_strdup(context) : NULL; @@ -763,109 +691,103 @@ return self; } - inline static int _cpl_parameter_init(cpl_parameter *parameter, va_list *ap) { - cxint status; cx_assert(parameter != NULL); cx_assert(ap != NULL); switch (parameter->class) { - case CPL_PARAMETER_CLASS_VALUE: - status = _cpl_parameter_value_create(parameter, ap); - break; - - case CPL_PARAMETER_CLASS_RANGE: - status = _cpl_parameter_range_create(parameter, ap); - break; - - case CPL_PARAMETER_CLASS_ENUM: - status = _cpl_parameter_enum_create(parameter, ap); - break; - - default: - cpl_error_set(cpl_func, CPL_ERROR_INVALID_TYPE); - status = -1; - break; - } + case CPL_PARAMETER_CLASS_VALUE: + status = _cpl_parameter_value_create(parameter, ap); + break; - if (status) { - switch (status) { - case -1: - cx_warning("%s: parameter at %p has invalid class id %02x", - cpl_func, (const void*)parameter, parameter->class); + case CPL_PARAMETER_CLASS_RANGE: + status = _cpl_parameter_range_create(parameter, ap); break; - case -2: - cx_warning("%s: parameter at %p is corrupted due to invalid " - "initialization data", cpl_func, - (const void*)parameter); + case CPL_PARAMETER_CLASS_ENUM: + status = _cpl_parameter_enum_create(parameter, ap); break; default: - cx_warning("%s: parameter at %p has illegal combination of " - "class id (%02x) and type id (%02x)", cpl_func, - (const void*)parameter, - parameter->class, parameter->data->type); + cpl_error_set(cpl_func, CPL_ERROR_INVALID_TYPE); + status = -1; break; + } + + if (status) { + switch (status) { + case -1: + cx_warning("%s: parameter at %p has invalid class id %02x", + cpl_func, (const void *)parameter, parameter->class); + break; + + case -2: + cx_warning("%s: parameter at %p is corrupted due to invalid " + "initialization data", + cpl_func, (const void *)parameter); + break; + + default: + cx_warning("%s: parameter at %p has illegal combination of " + "class id (%02x) and type id (%02x)", + cpl_func, (const void *)parameter, parameter->class, + parameter->data->type); + break; } cpl_error_set(cpl_func, CPL_ERROR_ILLEGAL_INPUT); return 1; } return 0; - } - inline static int _cpl_parameter_copy(cpl_parameter *self, const cpl_parameter *other) { - cxint status; cx_assert((self != NULL) && (other != NULL)); switch (self->class) { - case CPL_PARAMETER_CLASS_VALUE: - status = _cpl_parameter_value_copy(self, other); - break; - - case CPL_PARAMETER_CLASS_RANGE: - status = _cpl_parameter_range_copy(self, other); - break; - - case CPL_PARAMETER_CLASS_ENUM: - status = _cpl_parameter_enum_copy(self, other); - break; - - default: - cpl_error_set(cpl_func, CPL_ERROR_INVALID_TYPE); - status = -1; - break; + case CPL_PARAMETER_CLASS_VALUE: + status = _cpl_parameter_value_copy(self, other); + break; + + case CPL_PARAMETER_CLASS_RANGE: + status = _cpl_parameter_range_copy(self, other); + break; + + case CPL_PARAMETER_CLASS_ENUM: + status = _cpl_parameter_enum_copy(self, other); + break; + + default: + cpl_error_set(cpl_func, CPL_ERROR_INVALID_TYPE); + status = -1; + break; } if (status) { if (status == -1) { - cx_warning("%s: parameter at %p has invalid class id %02x", cpl_func, - (const void *)self, self->class); + cx_warning("%s: parameter at %p has invalid class id %02x", + cpl_func, (const void *)self, self->class); } else { cx_warning("%s: parameter at %p has illegal combination of" - "class id (%02x) and type id (%02x)", cpl_func, - (const void *)self, self->class, self->data->type); + "class id (%02x) and type id (%02x)", + cpl_func, (const void *)self, self->class, + self->data->type); } return 1; } return 0; - } - /** * @brief * Create a new value parameter. @@ -916,7 +838,7 @@ * * The following example creates an integer value parameter with the * unique name @c application.setup.value which belongs to the context - * @c application.setup with the default value @em def + * @c application.setup with the default value @c def * * @par Example: * @code @@ -933,15 +855,15 @@ */ cpl_parameter * -cpl_parameter_new_value(const char *name, cpl_type type, - const char *description, const char *context, ...) +cpl_parameter_new_value(const char *name, + cpl_type type, + const char *description, + const char *context, + ...) { - - va_list ap; cpl_parameter *p; - if (!name) { cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); return NULL; @@ -954,7 +876,7 @@ return NULL; } - p = _cpl_parameter_create(name, description, context); + p = _cpl_parameter_create(name, description, context); cx_assert(p != NULL); p->class = CPL_PARAMETER_CLASS_VALUE; @@ -974,7 +896,6 @@ return p; } - /** * @brief * Create a new range parameter. @@ -995,7 +916,7 @@ * * CPL_ERROR_NULL_INPUT * - * The parameter self is a NULL pointer. + * The parameter name is a NULL pointer. * * * @@ -1004,7 +925,7 @@ * An unsupported type was passed as type. * * - * + * * CPL_ERROR_ILLEGAL_INPUT * * The provided parameter initialisation data is invalid. @@ -1027,7 +948,7 @@ * * The following example creates a double range parameter with the * unique name @c application.setup.range which belongs to the context - * @c application.setup with the default @em def and the range boundary + * @c application.setup with the default @c def and the range boundary * values @em minimum and @em maximum. * * @par Example: @@ -1047,14 +968,15 @@ */ cpl_parameter * -cpl_parameter_new_range(const char *name, cpl_type type, - const char *description, const char *context, ...) +cpl_parameter_new_range(const char *name, + cpl_type type, + const char *description, + const char *context, + ...) { - va_list ap; cpl_parameter *p; - if (!name) { cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); return NULL; @@ -1079,7 +1001,7 @@ return NULL; } - p = _cpl_parameter_create(name, description, context); + p = _cpl_parameter_create(name, description, context); cx_assert(p != NULL); p->class = CPL_PARAMETER_CLASS_RANGE; @@ -1099,7 +1021,6 @@ return p; } - /** * @brief * Create a new enumeration parameter. @@ -1120,7 +1041,7 @@ * * CPL_ERROR_NULL_INPUT * - * The parameter self is a NULL pointer. + * The parameter name is a NULL pointer. * * * @@ -1155,7 +1076,7 @@ * * The following example creates a string enumeration parameter with the * unique name @c application.setup.enum which belongs to the context - * @c application.setup with the default @em def and 3 enumeration + * @c application.setup with the default @c first and 3 enumeration * alternatives. * * @par Example: @@ -1172,18 +1093,20 @@ * third); * @endcode * - * @see cpl_parameter_new_value(), cpl_parameter_new_range() + * @see cpl_parameter_new_value(), cpl_parameter_new_range(), + * cpl_parameter_new_enum_from_array() */ cpl_parameter * -cpl_parameter_new_enum(const char *name, cpl_type type, - const char *description, const char *context, ...) +cpl_parameter_new_enum(const char *name, + cpl_type type, + const char *description, + const char *context, + ...) { - va_list ap; cpl_parameter *p; - if (!name) { cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); return NULL; @@ -1208,7 +1131,7 @@ return NULL; } - p = _cpl_parameter_create(name, description, context); + p = _cpl_parameter_create(name, description, context); cx_assert(p != NULL); p->class = CPL_PARAMETER_CLASS_ENUM; @@ -1228,6 +1151,151 @@ return p; } +/** + * @brief + * Create a new enumeration parameter from an array of alternative values. + * + * @param name The parameter's unique name + * @param type The type of the parameter's current and default value. + * @param description An optional comment or description of the parameter. + * @param context The context to which the parameter belongs. + * @param position The index of the alternative to use as default value. + * @param size The size of the enumeration alternatives list. + * @param alternatives The array of enumeration alternatives. + * + * @return + * The function returns the newly created parameter, or @c NULL if + * the parameter could not be created. In the latter case an appropriate + * error code is set. + * + * @error + * + * + * + * + * + * + * + * + * + * + * + * + * + *
CPL_ERROR_NULL_INPUT + * The parameter name is a NULL pointer. + *
CPL_ERROR_INVALID_TYPE + * An unsupported type was passed as type. + *
CPL_ERROR_ILLEGAL_INPUT + * The provided parameter initialisation data is invalid. + *
+ * @enderror + * + * The function allocates memory for an enumeration parameter with the name + * @em name and a value type @em type. Optionally a comment describing the + * parameter may be passed by @em description and the context to which the + * parameter belongs may be given by @em context. + * + * To properly initialise the newly created enumeration the index @em position + * of the parameter's default value in the array of alternatives + * @em alternatives must be given. The size of the array of alternatives is + * given by @em size. The type of all alternatives given must match the + * parameter's value type as it is indicated by @em type. Enumeration + * parameters can only be created for the value types integer, double or + * string. + * + * The following example creates a string enumeration parameter with the + * unique name @c application.setup.enum which belongs to the context + * @c application.setup with the default @c first and 3 enumeration + * alternatives. + * + * @par Example: + * @code + * const char *alternatives = {"first", "second", "third"}; + * + * cpl_parameter *p = + * cpl_parameter_new_enum_array_from_array("application.setup.enum", + * CPL_TYPE_STRING, + * "An enum of type string", + * "application.setup", + * 0, 3, alternatives); + * @endcode + * + * @see cpl_parameter_new_value(), cpl_parameter_new_range(), + * cpl_parameter_new_enum() + */ + +cpl_parameter * +cpl_parameter_new_enum_from_array(const char *name, + cpl_type type, + const char *description, + const char *context, + cpl_size position, + cpl_size size, + const void *alternatives) +{ + if (!name) { + cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); + return NULL; + } + + if (_cpl_parameter_validate_type(type) != TRUE) { + cpl_error_set_message(cpl_func, CPL_ERROR_INVALID_TYPE, + "Unsupported parameter type %s", + cpl_type_get_name(type)); + return NULL; + } + + /* + * A enum parameter of type bool does not make sense and is not supported + */ + + if (type == CPL_TYPE_BOOL) { + cpl_error_set_message(cpl_func, CPL_ERROR_INVALID_TYPE, + "Unsupported parameter type %s", + cpl_type_get_name(type)); + return NULL; + } + + if (size < 1) { + cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, + "Invalid number of enumeration alternatives"); + return NULL; + } + + if ((position < 0) || (position >= size)) { + cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, + "Illegal parameter default value index"); + return NULL; + } + + cpl_parameter *p = _cpl_parameter_create(name, description, context); + cx_assert(p != NULL); + + p->class = CPL_PARAMETER_CLASS_ENUM; + p->data = _cpl_parameter_value_new(type, sizeof(cpl_parameter_enum)); + cx_assert(p->data != NULL); + + /* Initialize the parameter value */ + cpl_parameter_enum *data = (cpl_parameter_enum *)p->data; + + data->sz = size; + data->vlist = cx_calloc(data->sz, sizeof(cpl_parameter_data)); + + cxsize sz = (type & CPL_TYPE_FLAG_ARRAY) ? sizeof(cxptr) + : cpl_type_get_sizeof(type); + cxuchar *_alternatives = (cxuchar *)alternatives; + cxsize i; + for (i = 0; i < data->sz; ++i) { + _cpl_parameter_data_set(data->vlist + i, type, _alternatives + i * sz); + } + + _cpl_parameter_data_set(&data->value.preset, type, + _alternatives + position * sz); + _cpl_parameter_data_set(&data->value.data, type, &data->value.preset); + + return p; +} /** * @brief @@ -1254,12 +1322,11 @@ * deep copy, i.e. all parameter properties are copied. */ -cpl_parameter *cpl_parameter_duplicate(const cpl_parameter *self) +cpl_parameter * +cpl_parameter_duplicate(const cpl_parameter *self) { - cpl_parameter *_self = NULL; - if (self == NULL) { cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); return NULL; @@ -1276,26 +1343,26 @@ _self->data = NULL; switch (_self->class) { - case CPL_PARAMETER_CLASS_VALUE: - _self->data = _cpl_parameter_value_new(self->data->type, - sizeof(cpl_parameter_value)); - break; - - case CPL_PARAMETER_CLASS_RANGE: - _self->data = _cpl_parameter_value_new(self->data->type, - sizeof(cpl_parameter_range)); - break; - - case CPL_PARAMETER_CLASS_ENUM: - _self->data = _cpl_parameter_value_new(self->data->type, - sizeof(cpl_parameter_enum)); - break; + case CPL_PARAMETER_CLASS_VALUE: + _self->data = _cpl_parameter_value_new(self->data->type, + sizeof(cpl_parameter_value)); + break; - default: - cpl_parameter_delete(_self); - cpl_error_set(cpl_func, CPL_ERROR_INVALID_TYPE); - return NULL; - break; + case CPL_PARAMETER_CLASS_RANGE: + _self->data = _cpl_parameter_value_new(self->data->type, + sizeof(cpl_parameter_range)); + break; + + case CPL_PARAMETER_CLASS_ENUM: + _self->data = _cpl_parameter_value_new(self->data->type, + sizeof(cpl_parameter_enum)); + break; + + default: + cpl_parameter_delete(_self); + cpl_error_set(cpl_func, CPL_ERROR_INVALID_TYPE); + return NULL; + break; } cx_assert(_self->data != NULL); @@ -1317,10 +1384,8 @@ _self->info.id = self->info.id; return _self; - } - /** * @brief * Delete a parameter. @@ -1337,10 +1402,8 @@ void cpl_parameter_delete(cpl_parameter *self) { - if (self != NULL) { if (self->data != NULL) { - switch (self->class) { case CPL_PARAMETER_CLASS_VALUE: _cpl_parameter_value_destroy(self->data); @@ -1402,7 +1465,6 @@ return; } - /** * @brief * Assign a boolean value to a parameter. @@ -1440,9 +1502,6 @@ cpl_error_code cpl_parameter_set_bool(cpl_parameter *self, int value) { - - - if (!self) { return cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); } @@ -1450,19 +1509,19 @@ cx_assert(self->data); if (self->data->type != CPL_TYPE_BOOL) { - return cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, "%s of " - "type %s", cpl_parameter_get_name(self), - cpl_type_get_name(cpl_parameter_get_type - (self))); + return cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, + "%s of " + "type %s", + cpl_parameter_get_name(self), + cpl_type_get_name( + cpl_parameter_get_type(self))); } _cpl_parameter_value_set(self, &value); return CPL_ERROR_NONE; - } - /** * @brief * Assign an integer value to a parameter. @@ -1499,9 +1558,6 @@ cpl_error_code cpl_parameter_set_int(cpl_parameter *self, int value) { - - - if (!self) { return cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); } @@ -1509,20 +1565,18 @@ cx_assert(self->data); if (self->data->type != CPL_TYPE_INT) { - return cpl_error_set_message(cpl_func, - CPL_ERROR_TYPE_MISMATCH, "%s of type %s", + return cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, + "%s of type %s", cpl_parameter_get_name(self), - cpl_type_get_name(cpl_parameter_get_type - (self))); + cpl_type_get_name( + cpl_parameter_get_type(self))); } _cpl_parameter_value_set(self, &value); return CPL_ERROR_NONE; - } - /** * @brief * Assign a double value to a parameter. @@ -1559,9 +1613,6 @@ cpl_error_code cpl_parameter_set_double(cpl_parameter *self, double value) { - - - if (!self) { return cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); } @@ -1569,19 +1620,19 @@ cx_assert(self->data); if (self->data->type != CPL_TYPE_DOUBLE) { - return cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, "%s of " - "type %s", cpl_parameter_get_name(self), - cpl_type_get_name(cpl_parameter_get_type - (self))); + return cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, + "%s of " + "type %s", + cpl_parameter_get_name(self), + cpl_type_get_name( + cpl_parameter_get_type(self))); } _cpl_parameter_value_set(self, &value); return CPL_ERROR_NONE; - } - /** * @brief * Assign a string value to a parameter. @@ -1618,9 +1669,6 @@ cpl_error_code cpl_parameter_set_string(cpl_parameter *self, const char *value) { - - - if (!self) { return cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); } @@ -1628,19 +1676,19 @@ cx_assert(self->data); if (self->data->type != CPL_TYPE_STRING) { - return cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, "%s of " - "type %s", cpl_parameter_get_name(self), - cpl_type_get_name(cpl_parameter_get_type - (self))); + return cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, + "%s of " + "type %s", + cpl_parameter_get_name(self), + cpl_type_get_name( + cpl_parameter_get_type(self))); } _cpl_parameter_value_set(self, &value); return CPL_ERROR_NONE; - } - /** * @brief * Modify the default value of a boolean parameter. @@ -1679,8 +1727,6 @@ cpl_error_code cpl_parameter_set_default_bool(cpl_parameter *self, int value) { - - if (!self) { return cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); } @@ -1688,19 +1734,19 @@ cx_assert(self->data); if (self->data->type != CPL_TYPE_BOOL) { - return cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, "%s of " - "type %s", cpl_parameter_get_name(self), - cpl_type_get_name(cpl_parameter_get_type - (self))); + return cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, + "%s of " + "type %s", + cpl_parameter_get_name(self), + cpl_type_get_name( + cpl_parameter_get_type(self))); } _cpl_parameter_default_set(self, &value); return CPL_ERROR_NONE; - } - /** * @brief * Modify the default value of an integer parameter. @@ -1737,9 +1783,7 @@ cpl_error_code cpl_parameter_set_default_int(cpl_parameter *self, int value) -{ - - +{ if (!self) { return cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); } @@ -1747,19 +1791,19 @@ cx_assert(self->data); if (self->data->type != CPL_TYPE_INT) { - return cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, "%s of " - "type %s", cpl_parameter_get_name(self), - cpl_type_get_name(cpl_parameter_get_type - (self))); + return cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, + "%s of " + "type %s", + cpl_parameter_get_name(self), + cpl_type_get_name( + cpl_parameter_get_type(self))); } _cpl_parameter_default_set(self, &value); return CPL_ERROR_NONE; - } - /** * @brief * Modify the default value of a double parameter. @@ -1797,8 +1841,6 @@ cpl_error_code cpl_parameter_set_default_double(cpl_parameter *self, double value) { - - if (!self) { return cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); } @@ -1806,19 +1848,19 @@ cx_assert(self->data); if (self->data->type != CPL_TYPE_DOUBLE) { - return cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, "%s of " - "type %s", cpl_parameter_get_name(self), - cpl_type_get_name(cpl_parameter_get_type - (self))); + return cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, + "%s of " + "type %s", + cpl_parameter_get_name(self), + cpl_type_get_name( + cpl_parameter_get_type(self))); } _cpl_parameter_default_set(self, &value); return CPL_ERROR_NONE; - } - /** * @brief * Modify the default value of a string parameter. @@ -1856,8 +1898,6 @@ cpl_error_code cpl_parameter_set_default_string(cpl_parameter *self, const char *value) { - - if (!self) { return cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); } @@ -1865,19 +1905,19 @@ cx_assert(self->data); if (self->data->type != CPL_TYPE_STRING) { - return cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, "%s of " - "type %s", cpl_parameter_get_name(self), - cpl_type_get_name(cpl_parameter_get_type - (self))); + return cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, + "%s of " + "type %s", + cpl_parameter_get_name(self), + cpl_type_get_name( + cpl_parameter_get_type(self))); } _cpl_parameter_default_set(self, &value); return CPL_ERROR_NONE; - } - /** * @brief * Get the name of a parameter. @@ -1907,8 +1947,6 @@ const char * cpl_parameter_get_name(const cpl_parameter *self) { - - if (self == NULL) { cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); return NULL; @@ -1917,10 +1955,8 @@ cx_assert(self->name != NULL); return self->name; - } - /** * @brief * Get the context of a parameter. @@ -1950,19 +1986,14 @@ const char * cpl_parameter_get_context(const cpl_parameter *self) { - - - if (!self) { cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); return NULL; } return self->context; - } - /** * @brief * Get the description of a parameter. @@ -1992,18 +2023,14 @@ const char * cpl_parameter_get_help(const cpl_parameter *self) { - if (!self) { (void)cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); return NULL; } return self->description; - } - - /** * @brief * Get the parameter's value type. @@ -2033,18 +2060,14 @@ cpl_type cpl_parameter_get_type(const cpl_parameter *self) { - - if (!self) { cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); return CPL_TYPE_INVALID; } return self->data->type; - } - /** * @brief * Get the parameter's class. @@ -2073,18 +2096,14 @@ cpl_parameter_class cpl_parameter_get_class(const cpl_parameter *self) { - - if (!self) { cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); return CPL_PARAMETER_CLASS_INVALID; } return self->class; - } - /** * @brief * Get the value of the given boolean parameter. @@ -2121,9 +2140,6 @@ int cpl_parameter_get_bool(const cpl_parameter *self) { - - - if (!self) { cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); return 0; @@ -2132,18 +2148,18 @@ cx_assert(self->data); if (self->data->type != CPL_TYPE_BOOL) { - (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, "%s of " - "type %s", cpl_parameter_get_name(self), - cpl_type_get_name(cpl_parameter_get_type - (self))); + (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, + "%s of " + "type %s", + cpl_parameter_get_name(self), + cpl_type_get_name( + cpl_parameter_get_type(self))); return 0; } return self->data->data.b; - } - /** * @brief * Get the value of the given integer parameter. @@ -2178,9 +2194,6 @@ int cpl_parameter_get_int(const cpl_parameter *self) { - - - if (!self) { cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); return 0; @@ -2189,18 +2202,18 @@ cx_assert(self->data); if (self->data->type != CPL_TYPE_INT) { - (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, "%s of " - "type %s", cpl_parameter_get_name(self), - cpl_type_get_name(cpl_parameter_get_type - (self))); + (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, + "%s of " + "type %s", + cpl_parameter_get_name(self), + cpl_type_get_name( + cpl_parameter_get_type(self))); return 0; } return self->data->data.i; - } - /** * @brief * Get the value of the given double parameter. @@ -2235,9 +2248,6 @@ double cpl_parameter_get_double(const cpl_parameter *self) { - - - if (!self) { cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); return 0.; @@ -2246,18 +2256,18 @@ cx_assert(self->data); if (self->data->type != CPL_TYPE_DOUBLE) { - (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, "%s of " - "type %s", cpl_parameter_get_name(self), - cpl_type_get_name(cpl_parameter_get_type - (self))); + (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, + "%s of " + "type %s", + cpl_parameter_get_name(self), + cpl_type_get_name( + cpl_parameter_get_type(self))); return 0.; } return self->data->data.d; - } - /** * @brief * Get the value of the given string parameter. @@ -2292,9 +2302,6 @@ const char * cpl_parameter_get_string(const cpl_parameter *self) { - - - if (!self) { cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); return NULL; @@ -2303,18 +2310,18 @@ cx_assert(self->data); if (self->data->type != CPL_TYPE_STRING) { - (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, "%s of " - "type %s", cpl_parameter_get_name(self), - cpl_type_get_name(cpl_parameter_get_type - (self))); + (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, + "%s of " + "type %s", + cpl_parameter_get_name(self), + cpl_type_get_name( + cpl_parameter_get_type(self))); return NULL; } return self->data->data.s; - } - /** * @brief * Get the default value of the given boolean parameter. @@ -2351,8 +2358,6 @@ int cpl_parameter_get_default_bool(const cpl_parameter *self) { - - if (!self) { cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); return 0; @@ -2361,18 +2366,18 @@ cx_assert(self->data); if (self->data->type != CPL_TYPE_BOOL) { - (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, "%s of " - "type %s", cpl_parameter_get_name(self), - cpl_type_get_name(cpl_parameter_get_type - (self))); + (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, + "%s of " + "type %s", + cpl_parameter_get_name(self), + cpl_type_get_name( + cpl_parameter_get_type(self))); return 0; } return self->data->preset.b; - } - /** * @brief * Get the default value of the given integer parameter. @@ -2407,9 +2412,6 @@ int cpl_parameter_get_default_int(const cpl_parameter *self) { - - - if (!self) { cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); return 0; @@ -2418,18 +2420,18 @@ cx_assert(self->data); if (self->data->type != CPL_TYPE_INT) { - (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, "%s of " - "type %s", cpl_parameter_get_name(self), - cpl_type_get_name(cpl_parameter_get_type - (self))); + (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, + "%s of " + "type %s", + cpl_parameter_get_name(self), + cpl_type_get_name( + cpl_parameter_get_type(self))); return 0; } return self->data->preset.i; - } - /** * @brief * Get the default value of the given double parameter. @@ -2464,9 +2466,6 @@ double cpl_parameter_get_default_double(const cpl_parameter *self) { - - - if (!self) { cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); return 0.; @@ -2475,18 +2474,18 @@ cx_assert(self->data); if (self->data->type != CPL_TYPE_DOUBLE) { - (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, "%s of " - "type %s", cpl_parameter_get_name(self), - cpl_type_get_name(cpl_parameter_get_type - (self))); + (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, + "%s of " + "type %s", + cpl_parameter_get_name(self), + cpl_type_get_name( + cpl_parameter_get_type(self))); return 0.; } return self->data->preset.d; - } - /** * @brief * Get the default value of the given string parameter. @@ -2525,9 +2524,6 @@ const char * cpl_parameter_get_default_string(const cpl_parameter *self) { - - - if (!self) { cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); return NULL; @@ -2536,18 +2532,18 @@ cx_assert(self->data); if (self->data->type != CPL_TYPE_STRING) { - (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, "%s of " - "type %s", cpl_parameter_get_name(self), - cpl_type_get_name(cpl_parameter_get_type - (self))); + (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, + "%s of " + "type %s", + cpl_parameter_get_name(self), + cpl_type_get_name( + cpl_parameter_get_type(self))); return NULL; } return self->data->preset.s; - } - /** * @brief * Get the number of alternatives of an enumeration parameter. @@ -2585,28 +2581,26 @@ int cpl_parameter_get_enum_size(const cpl_parameter *self) { - - if (!self) { cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); return 0; } if (self->class != CPL_PARAMETER_CLASS_ENUM) { - (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, "%s of " - "type %s", cpl_parameter_get_name(self), - cpl_type_get_name(cpl_parameter_get_type - (self))); + (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, + "%s of " + "type %s", + cpl_parameter_get_name(self), + cpl_type_get_name( + cpl_parameter_get_type(self))); return 0; } cx_assert(self->data); return ((cpl_parameter_enum *)self->data)->sz; - } - /** * @brief * Get the possible values for an integer enumeration. @@ -2653,28 +2647,30 @@ int cpl_parameter_get_enum_int(const cpl_parameter *self, int position) { - - if (!self) { cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); return 0; } if (self->class != CPL_PARAMETER_CLASS_ENUM) { - (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, "%s of " - "type %s", cpl_parameter_get_name(self), - cpl_type_get_name(cpl_parameter_get_type - (self))); + (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, + "%s of " + "type %s", + cpl_parameter_get_name(self), + cpl_type_get_name( + cpl_parameter_get_type(self))); return 0; } cx_assert(self->data); if (((cpl_parameter_enum *)self->data)->value.type != CPL_TYPE_INT) { - (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, "%s of " - "type %s", cpl_parameter_get_name(self), - cpl_type_get_name(cpl_parameter_get_type - (self))); + (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, + "%s of " + "type %s", + cpl_parameter_get_name(self), + cpl_type_get_name( + cpl_parameter_get_type(self))); return 0; } @@ -2686,10 +2682,8 @@ } return ((cpl_parameter_enum *)self->data)->vlist[position].i; - } - /** * @brief * Get the possible values for a double enumeration. @@ -2736,29 +2730,30 @@ double cpl_parameter_get_enum_double(const cpl_parameter *self, int position) { - - if (!self) { cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); return 0.; } if (self->class != CPL_PARAMETER_CLASS_ENUM) { - (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, "%s of " - "type %s", cpl_parameter_get_name(self), - cpl_type_get_name(cpl_parameter_get_type - (self))); + (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, + "%s of " + "type %s", + cpl_parameter_get_name(self), + cpl_type_get_name( + cpl_parameter_get_type(self))); return 0.; } cx_assert(self->data); - if (((cpl_parameter_enum *)self->data)->value.type != - CPL_TYPE_DOUBLE) { - (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, "%s of " - "type %s", cpl_parameter_get_name(self), - cpl_type_get_name(cpl_parameter_get_type - (self))); + if (((cpl_parameter_enum *)self->data)->value.type != CPL_TYPE_DOUBLE) { + (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, + "%s of " + "type %s", + cpl_parameter_get_name(self), + cpl_type_get_name( + cpl_parameter_get_type(self))); return 0.; } @@ -2770,10 +2765,8 @@ } return ((cpl_parameter_enum *)self->data)->vlist[position].d; - } - /** * @brief * Get the possible values for a string enumeration. @@ -2819,29 +2812,30 @@ const char * cpl_parameter_get_enum_string(const cpl_parameter *self, int position) { - - if (!self) { cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); return NULL; } if (self->class != CPL_PARAMETER_CLASS_ENUM) { - (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, "%s of " - "type %s", cpl_parameter_get_name(self), - cpl_type_get_name(cpl_parameter_get_type - (self))); + (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, + "%s of " + "type %s", + cpl_parameter_get_name(self), + cpl_type_get_name( + cpl_parameter_get_type(self))); return NULL; } cx_assert(self->data); - if (((cpl_parameter_enum *)self->data)->value.type != - CPL_TYPE_STRING) { - (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, "%s of " - "type %s", cpl_parameter_get_name(self), - cpl_type_get_name(cpl_parameter_get_type - (self))); + if (((cpl_parameter_enum *)self->data)->value.type != CPL_TYPE_STRING) { + (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, + "%s of " + "type %s", + cpl_parameter_get_name(self), + cpl_type_get_name( + cpl_parameter_get_type(self))); return NULL; } @@ -2853,10 +2847,8 @@ } return ((cpl_parameter_enum *)self->data)->vlist[position].s; - } - /** * @brief * Get the minimum value of an integer range parameter. @@ -2894,36 +2886,36 @@ int cpl_parameter_get_range_min_int(const cpl_parameter *self) { - - if (!self) { cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); return 0; } if (self->class != CPL_PARAMETER_CLASS_RANGE) { - (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, "%s of " - "type %s", cpl_parameter_get_name(self), - cpl_type_get_name(cpl_parameter_get_type - (self))); + (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, + "%s of " + "type %s", + cpl_parameter_get_name(self), + cpl_type_get_name( + cpl_parameter_get_type(self))); return 0; } cx_assert(self->data); if (((cpl_parameter_range *)self->data)->value.type != CPL_TYPE_INT) { - (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, "%s of " - "type %s", cpl_parameter_get_name(self), - cpl_type_get_name(cpl_parameter_get_type - (self))); + (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, + "%s of " + "type %s", + cpl_parameter_get_name(self), + cpl_type_get_name( + cpl_parameter_get_type(self))); return 0; } return ((cpl_parameter_range *)self->data)->min.i; - } - /** * @brief * Get the minimum value of a double range parameter. @@ -2961,37 +2953,36 @@ double cpl_parameter_get_range_min_double(const cpl_parameter *self) { - - if (!self) { cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); return 0.; } if (self->class != CPL_PARAMETER_CLASS_RANGE) { - (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, "%s of " - "type %s", cpl_parameter_get_name(self), - cpl_type_get_name(cpl_parameter_get_type - (self))); + (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, + "%s of " + "type %s", + cpl_parameter_get_name(self), + cpl_type_get_name( + cpl_parameter_get_type(self))); return 0.; } cx_assert(self->data); - if (((cpl_parameter_range *)self->data)->value.type != - CPL_TYPE_DOUBLE) { - (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, "%s of " - "type %s", cpl_parameter_get_name(self), - cpl_type_get_name(cpl_parameter_get_type - (self))); + if (((cpl_parameter_range *)self->data)->value.type != CPL_TYPE_DOUBLE) { + (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, + "%s of " + "type %s", + cpl_parameter_get_name(self), + cpl_type_get_name( + cpl_parameter_get_type(self))); return 0.; } return ((cpl_parameter_range *)self->data)->min.d; - } - /** * @brief * Get the maximum value of an integer range parameter. @@ -3029,36 +3020,36 @@ int cpl_parameter_get_range_max_int(const cpl_parameter *self) { - - if (!self) { cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); return 0; } - if (self->class!=CPL_PARAMETER_CLASS_RANGE) { - (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, "%s of " - "type %s", cpl_parameter_get_name(self), - cpl_type_get_name(cpl_parameter_get_type - (self))); + if (self->class != CPL_PARAMETER_CLASS_RANGE) { + (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, + "%s of " + "type %s", + cpl_parameter_get_name(self), + cpl_type_get_name( + cpl_parameter_get_type(self))); return 0; } cx_assert(self->data); if (((cpl_parameter_range *)self->data)->value.type != CPL_TYPE_INT) { - (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, "%s of " - "type %s", cpl_parameter_get_name(self), - cpl_type_get_name(cpl_parameter_get_type - (self))); + (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, + "%s of " + "type %s", + cpl_parameter_get_name(self), + cpl_type_get_name( + cpl_parameter_get_type(self))); return 0; } return ((cpl_parameter_range *)self->data)->max.i; - } - /** * @brief * Get the maximum value of a double range parameter. @@ -3096,37 +3087,36 @@ double cpl_parameter_get_range_max_double(const cpl_parameter *self) { - - if (!self) { cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); return 0.; } if (self->class != CPL_PARAMETER_CLASS_RANGE) { - (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, "%s of " - "type %s", cpl_parameter_get_name(self), - cpl_type_get_name(cpl_parameter_get_type - (self))); + (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, + "%s of " + "type %s", + cpl_parameter_get_name(self), + cpl_type_get_name( + cpl_parameter_get_type(self))); return 0.; } cx_assert(self->data); - if (((cpl_parameter_range *)self->data)->value.type != - CPL_TYPE_DOUBLE) { - (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, "%s of " - "type %s", cpl_parameter_get_name(self), - cpl_type_get_name(cpl_parameter_get_type - (self))); + if (((cpl_parameter_range *)self->data)->value.type != CPL_TYPE_DOUBLE) { + (void)cpl_error_set_message(cpl_func, CPL_ERROR_TYPE_MISMATCH, + "%s of " + "type %s", + cpl_parameter_get_name(self), + cpl_type_get_name( + cpl_parameter_get_type(self))); return 0.; } return ((cpl_parameter_range *)self->data)->max.d; - } - /** * @brief * Get the presence status flag of the given parameter. @@ -3162,19 +3152,14 @@ int cpl_parameter_get_default_flag(const cpl_parameter *self) { - - - if (self == NULL) { cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); return 0; } return self->info.present == TRUE ? 1 : 0; - } - /** * @brief * Change the presence status flag of the given parameter. @@ -3208,19 +3193,14 @@ cpl_error_code cpl_parameter_set_default_flag(cpl_parameter *self, int status) { - - - if (self == NULL) { return cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); } self->info.present = status == 0 ? FALSE : TRUE; return CPL_ERROR_NONE; - } - /** * @brief * Get the numerical identifier of the given parameter. @@ -3252,19 +3232,14 @@ int cpl_parameter_get_id(const cpl_parameter *self) { - - - if (self == NULL) { cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); return 0; } return self->info.id; - } - /** * @brief * Set the numerical identifier of the given parameter. @@ -3300,19 +3275,14 @@ cpl_error_code cpl_parameter_set_id(cpl_parameter *self, int id) { - - - if (self == NULL) { return cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); } self->info.id = id; return CPL_ERROR_NONE; - } - /** * @brief * Get the parameter's user tag. @@ -3342,18 +3312,14 @@ const char * cpl_parameter_get_tag(const cpl_parameter *self) { - - if (!self) { cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); return NULL; } return self->usertag; - } - /** * @brief * Set the tag of the given parameter. @@ -3387,9 +3353,6 @@ cpl_error_code cpl_parameter_set_tag(cpl_parameter *self, const char *tag) { - - - if (self == NULL || tag == NULL) { return cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); } @@ -3402,10 +3365,8 @@ self->usertag = cx_strdup(tag); return CPL_ERROR_NONE; - } - /** * @brief * Set alias names for the given parameter. @@ -3448,50 +3409,46 @@ */ cpl_error_code -cpl_parameter_set_alias(cpl_parameter *self, cpl_parameter_mode mode, +cpl_parameter_set_alias(cpl_parameter *self, + cpl_parameter_mode mode, const char *alias) { - - - if (self == NULL) { return cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); } switch (mode) { - case CPL_PARAMETER_MODE_CLI: - if (self->info.c_key) { - cx_free(self->info.c_key); - } - self->info.c_key = cx_strdup(alias); - break; + case CPL_PARAMETER_MODE_CLI: + if (self->info.c_key) { + cx_free(self->info.c_key); + } + self->info.c_key = cx_strdup(alias); + break; - case CPL_PARAMETER_MODE_ENV: - if (self->info.e_key) { - cx_free(self->info.e_key); - } - self->info.e_key = cx_strdup(alias); - break; + case CPL_PARAMETER_MODE_ENV: + if (self->info.e_key) { + cx_free(self->info.e_key); + } + self->info.e_key = cx_strdup(alias); + break; - case CPL_PARAMETER_MODE_CFG: - if (self->info.f_key) { - cx_free(self->info.f_key); - } - self->info.f_key = cx_strdup(alias); - break; + case CPL_PARAMETER_MODE_CFG: + if (self->info.f_key) { + cx_free(self->info.f_key); + } + self->info.f_key = cx_strdup(alias); + break; - default: - return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, - "%s, mode=%d, alias=%s", - cpl_parameter_get_name(self), (int)mode, - alias); + default: + return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, + "%s, mode=%d, alias=%s", + cpl_parameter_get_name(self), + (int)mode, alias); } return CPL_ERROR_NONE; - } - /** * @brief * Get the parameter's alias name for the given mode. @@ -3533,41 +3490,37 @@ const char * cpl_parameter_get_alias(const cpl_parameter *self, cpl_parameter_mode mode) { - - const cxchar *alias = NULL; - if (self == NULL) { cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); return NULL; } switch (mode) { - case CPL_PARAMETER_MODE_CLI: - alias = self->info.c_key; - break; - - case CPL_PARAMETER_MODE_ENV: - alias = self->info.e_key; - break; - - case CPL_PARAMETER_MODE_CFG: - alias = self->info.f_key; - break; - - default: - (void)cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, - "%s, mode=%d", - cpl_parameter_get_name(self), (int)mode); - break; + case CPL_PARAMETER_MODE_CLI: + alias = self->info.c_key; + break; + + case CPL_PARAMETER_MODE_ENV: + alias = self->info.e_key; + break; + + case CPL_PARAMETER_MODE_CFG: + alias = self->info.f_key; + break; + + default: + (void)cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, + "%s, mode=%d", + cpl_parameter_get_name(self), + (int)mode); + break; } return alias; - } - /** * @brief * Get the parameter's activity status for the environment context. @@ -3609,41 +3562,37 @@ int cpl_parameter_is_enabled(const cpl_parameter *self, cpl_parameter_mode mode) { - - cxbool active = FALSE; - if (self == NULL) { cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); return 0; } switch (mode) { - case CPL_PARAMETER_MODE_CLI: - active = self->info.c_active; - break; - - case CPL_PARAMETER_MODE_ENV: - active = self->info.e_active; - break; - - case CPL_PARAMETER_MODE_CFG: - active = self->info.f_active; - break; - - default: - (void)cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, - "%s, mode=%d", - cpl_parameter_get_name(self), (int)mode); - break; + case CPL_PARAMETER_MODE_CLI: + active = self->info.c_active; + break; + + case CPL_PARAMETER_MODE_ENV: + active = self->info.e_active; + break; + + case CPL_PARAMETER_MODE_CFG: + active = self->info.f_active; + break; + + default: + (void)cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, + "%s, mode=%d", + cpl_parameter_get_name(self), + (int)mode); + break; } return active == TRUE ? 1 : 0; - } - /** * @brief * Activates a parameter for the given mode. @@ -3678,38 +3627,34 @@ cpl_error_code cpl_parameter_enable(cpl_parameter *self, cpl_parameter_mode mode) { - - - if (self == NULL) { return cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); } switch (mode) { - case CPL_PARAMETER_MODE_CLI: - self->info.c_active = TRUE; - break; - - case CPL_PARAMETER_MODE_ENV: - self->info.e_active = TRUE; - break; - - case CPL_PARAMETER_MODE_CFG: - self->info.f_active = TRUE; - break; - - default: - return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, - "%s, mode=%d", - cpl_parameter_get_name(self), (int)mode); - break; + case CPL_PARAMETER_MODE_CLI: + self->info.c_active = TRUE; + break; + + case CPL_PARAMETER_MODE_ENV: + self->info.e_active = TRUE; + break; + + case CPL_PARAMETER_MODE_CFG: + self->info.f_active = TRUE; + break; + + default: + return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, + "%s, mode=%d", + cpl_parameter_get_name(self), + (int)mode); + break; } return CPL_ERROR_NONE; - } - /** * @brief * Deactivate a parameter for the given mode. @@ -3744,38 +3689,34 @@ cpl_error_code cpl_parameter_disable(cpl_parameter *self, cpl_parameter_mode mode) { - - - if (self == NULL) { return cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT); } switch (mode) { - case CPL_PARAMETER_MODE_CLI: - self->info.c_active = FALSE; - break; - - case CPL_PARAMETER_MODE_ENV: - self->info.e_active = FALSE; - break; - - case CPL_PARAMETER_MODE_CFG: - self->info.f_active = FALSE; - break; - - default: - return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, - "%s, mode=%d", - cpl_parameter_get_name(self), (int)mode); - break; + case CPL_PARAMETER_MODE_CLI: + self->info.c_active = FALSE; + break; + + case CPL_PARAMETER_MODE_ENV: + self->info.e_active = FALSE; + break; + + case CPL_PARAMETER_MODE_CFG: + self->info.f_active = FALSE; + break; + + default: + return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, + "%s, mode=%d", + cpl_parameter_get_name(self), + (int)mode); + break; } return CPL_ERROR_NONE; - } - /** * @brief * Dump the parameter debugging information to the given stream. @@ -3793,64 +3734,62 @@ void cpl_parameter_dump(const cpl_parameter *self, FILE *stream) { - if (self != NULL) { - const cxchar *class; const cxchar *type; const cpl_parameter_value *value = NULL; - if (stream == NULL) { stream = stdout; } switch (self->class) { - case CPL_PARAMETER_CLASS_VALUE: - class = "Value"; - break; - - case CPL_PARAMETER_CLASS_RANGE: - class = "Range"; - break; - - case CPL_PARAMETER_CLASS_ENUM: - class = "Enum"; - break; - - default: - class = "Unknown"; - break; + case CPL_PARAMETER_CLASS_VALUE: + class = "Value"; + break; + + case CPL_PARAMETER_CLASS_RANGE: + class = "Range"; + break; + + case CPL_PARAMETER_CLASS_ENUM: + class = "Enum"; + break; + + default: + class = "Unknown"; + break; } value = self->data; switch (value->type) { - case CPL_TYPE_BOOL: - type = "bool"; - break; - - case CPL_TYPE_INT: - type = "int"; - break; - - case CPL_TYPE_DOUBLE: - type = "double"; - break; - - case CPL_TYPE_STRING: - type = "string"; - break; - - default: - type = "unknown"; - break; - } - - fprintf(stream, "Parameter at %p: class %02x (%s), type %02x (%s)\n" - " Attributes:", (const void *)self, self->class, class, - value->type, type); + case CPL_TYPE_BOOL: + type = "bool"; + break; + + case CPL_TYPE_INT: + type = "int"; + break; + + case CPL_TYPE_DOUBLE: + type = "double"; + break; + + case CPL_TYPE_STRING: + type = "string"; + break; + + default: + type = "unknown"; + break; + } + + fprintf(stream, + "Parameter at %p: class %02x (%s), type %02x (%s)\n" + " Attributes:", + (const void *)self, self->class, class, value->type, type); fprintf(stream, " name (at %p): %s", self->name, self->name); @@ -3884,55 +3823,53 @@ fprintf(stream, "\n Values: "); switch (value->type) { - case CPL_TYPE_BOOL: - fprintf(stream, " Current: %d Default: %d", value->data.b, - value->preset.b); - break; - - case CPL_TYPE_INT: - fprintf(stream, " Current: %d Default: %d", value->data.i, - value->preset.i); - break; - - case CPL_TYPE_DOUBLE: - fprintf(stream, " Current: %g Default: %g", value->data.d, - value->preset.d); - break; - - case CPL_TYPE_STRING: - if (value->data.s) { - if (value->preset.s) { - fprintf(stream, " Current: %s Default: %s", - value->data.s, value->preset.s); - } - else { - fprintf(stream, " Current: %s Default: %p", - value->data.s, value->preset.s); - } - } - else { - if (value->preset.s) { - fprintf(stream, " Current: %p Default: %s", - value->data.s, value->preset.s); + case CPL_TYPE_BOOL: + fprintf(stream, " Current: %d Default: %d", value->data.b, + value->preset.b); + break; + + case CPL_TYPE_INT: + fprintf(stream, " Current: %d Default: %d", value->data.i, + value->preset.i); + break; + + case CPL_TYPE_DOUBLE: + fprintf(stream, " Current: %g Default: %g", value->data.d, + value->preset.d); + break; + + case CPL_TYPE_STRING: + if (value->data.s) { + if (value->preset.s) { + fprintf(stream, " Current: %s Default: %s", + value->data.s, value->preset.s); + } + else { + fprintf(stream, " Current: %s Default: %p", + value->data.s, value->preset.s); + } } else { - fprintf(stream, " Current: %p Default: %p", - value->data.s, value->preset.s); + if (value->preset.s) { + fprintf(stream, " Current: %p Default: %s", + value->data.s, value->preset.s); + } + else { + fprintf(stream, " Current: %p Default: %p", + value->data.s, value->preset.s); + } } - } - break; + break; - default: - fprintf(stream, " Current: invalid Default: invalid"); - break; + default: + fprintf(stream, " Current: invalid Default: invalid"); + break; } fprintf(stream, "\n"); - } return; - } /**@}*/ diff -Nru cpl-7.1.4+ds/cplui/cpl_parameter.h cpl-7.2.2+ds/cplui/cpl_parameter.h --- cpl-7.1.4+ds/cplui/cpl_parameter.h 2021-05-07 12:09:09.000000000 +0000 +++ cpl-7.2.2+ds/cplui/cpl_parameter.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -25,7 +25,6 @@ #include #include - CPL_BEGIN_DECLS /** @@ -38,28 +37,29 @@ * attributes. */ -enum _cpl_parameter_mode_ { +enum _cpl_parameter_mode_ +{ /** * Command line mode of the parameter. * @hideinitializer */ - CPL_PARAMETER_MODE_CLI = 1 << 0, + CPL_PARAMETER_MODE_CLI = 1 << 0, /** * Environment variable mode of the parameter. * @hideinitializer */ - CPL_PARAMETER_MODE_ENV = 1 << 1, + CPL_PARAMETER_MODE_ENV = 1 << 1, /** * Configuration file mode of the parameter. * @hideinitializer */ - CPL_PARAMETER_MODE_CFG = 1 << 2 + CPL_PARAMETER_MODE_CFG = 1 << 2 }; @@ -72,7 +72,6 @@ typedef enum _cpl_parameter_mode_ cpl_parameter_mode; - /** * @ingroup cpl_parameter * @@ -80,7 +79,8 @@ * Supported parameter classes. */ -enum _cpl_parameter_class_ { +enum _cpl_parameter_class_ +{ /** * Parameter of undefined or invalid class. @@ -94,25 +94,24 @@ * @hideinitializer */ - CPL_PARAMETER_CLASS_VALUE = 1 << 1, + CPL_PARAMETER_CLASS_VALUE = 1 << 1, /** * Parameter representing a range of values. * @hideinitializer */ - CPL_PARAMETER_CLASS_RANGE = 1 << 2, + CPL_PARAMETER_CLASS_RANGE = 1 << 2, /** * Parameter representing an enumeration value. * @hideinitializer */ - CPL_PARAMETER_CLASS_ENUM = 1 << 3 + CPL_PARAMETER_CLASS_ENUM = 1 << 3 }; - /** * @ingroup cpl_parameter * @@ -122,7 +121,6 @@ typedef enum _cpl_parameter_class_ cpl_parameter_class; - /** * @ingroup cpl_parameter * @@ -132,25 +130,39 @@ typedef struct _cpl_parameter_ cpl_parameter; - /* * Create and destroy operations */ -cpl_parameter *cpl_parameter_new_value(const char *name, cpl_type type, +cpl_parameter *cpl_parameter_new_value(const char *name, + cpl_type type, const char *description, - const char *context, ...) CPL_ATTR_ALLOC; -cpl_parameter *cpl_parameter_new_range(const char *name, cpl_type type, + const char *context, + ...) CPL_ATTR_ALLOC; +cpl_parameter *cpl_parameter_new_range(const char *name, + cpl_type type, const char *description, - const char *context, ...) CPL_ATTR_ALLOC; -cpl_parameter *cpl_parameter_new_enum(const char *name, cpl_type type, + const char *context, + ...) CPL_ATTR_ALLOC; +cpl_parameter *cpl_parameter_new_enum(const char *name, + cpl_type type, const char *description, - const char *context, ...) CPL_ATTR_ALLOC; + const char *context, + ...) CPL_ATTR_ALLOC; -cpl_parameter *cpl_parameter_duplicate(const cpl_parameter *other) CPL_ATTR_ALLOC; +cpl_parameter * +cpl_parameter_new_enum_from_array(const char *name, + cpl_type type, + const char *description, + const char *context, + cpl_size position, + cpl_size size, + const void *alternatives) CPL_ATTR_ALLOC; -void cpl_parameter_delete(cpl_parameter *self); +cpl_parameter * +cpl_parameter_duplicate(const cpl_parameter *other) CPL_ATTR_ALLOC; +void cpl_parameter_delete(cpl_parameter *self); /* * Non-modifying operations @@ -159,9 +171,8 @@ cpl_type cpl_parameter_get_type(const cpl_parameter *self); cpl_parameter_class cpl_parameter_get_class(const cpl_parameter *self); - -int cpl_parameter_is_enabled(const cpl_parameter *self, - cpl_parameter_mode mode); +int +cpl_parameter_is_enabled(const cpl_parameter *self, cpl_parameter_mode mode); /* * Assignment operations @@ -170,20 +181,16 @@ cpl_error_code cpl_parameter_set_bool(cpl_parameter *self, int value); cpl_error_code cpl_parameter_set_int(cpl_parameter *self, int value); cpl_error_code cpl_parameter_set_double(cpl_parameter *self, double value); -cpl_error_code cpl_parameter_set_string(cpl_parameter *self, - const char *value); +cpl_error_code cpl_parameter_set_string(cpl_parameter *self, const char *value); -cpl_error_code cpl_parameter_set_default_bool(cpl_parameter *self, - int value); -cpl_error_code cpl_parameter_set_default_int(cpl_parameter *self, - int value); -cpl_error_code cpl_parameter_set_default_double(cpl_parameter *self, - double value); -cpl_error_code cpl_parameter_set_default_string(cpl_parameter *self, - const char *value); +cpl_error_code cpl_parameter_set_default_bool(cpl_parameter *self, int value); +cpl_error_code cpl_parameter_set_default_int(cpl_parameter *self, int value); +cpl_error_code +cpl_parameter_set_default_double(cpl_parameter *self, double value); +cpl_error_code +cpl_parameter_set_default_string(cpl_parameter *self, const char *value); -cpl_error_code cpl_parameter_set_default_flag(cpl_parameter *self, - int status); +cpl_error_code cpl_parameter_set_default_flag(cpl_parameter *self, int status); /* * Element access @@ -197,14 +204,14 @@ int cpl_parameter_get_range_min_int(const cpl_parameter *self); double cpl_parameter_get_range_min_double(const cpl_parameter *self); -int cpl_parameter_get_range_max_int(const cpl_parameter *self); +int cpl_parameter_get_range_max_int(const cpl_parameter *self); double cpl_parameter_get_range_max_double(const cpl_parameter *self); int cpl_parameter_get_enum_size(const cpl_parameter *self); int cpl_parameter_get_enum_int(const cpl_parameter *self, int position); double cpl_parameter_get_enum_double(const cpl_parameter *self, int position); -const char *cpl_parameter_get_enum_string(const cpl_parameter *self, - int position); +const char * +cpl_parameter_get_enum_string(const cpl_parameter *self, int position); int cpl_parameter_get_default_bool(const cpl_parameter *self); int cpl_parameter_get_default_int(const cpl_parameter *self); @@ -220,10 +227,10 @@ * Miscellaneous */ -cpl_error_code cpl_parameter_enable(cpl_parameter *self, - cpl_parameter_mode mode); -cpl_error_code cpl_parameter_disable(cpl_parameter *self, - cpl_parameter_mode mode); +cpl_error_code +cpl_parameter_enable(cpl_parameter *self, cpl_parameter_mode mode); +cpl_error_code +cpl_parameter_disable(cpl_parameter *self, cpl_parameter_mode mode); int cpl_parameter_get_id(const cpl_parameter *self); cpl_error_code cpl_parameter_set_id(cpl_parameter *self, int id); @@ -232,8 +239,8 @@ cpl_error_code cpl_parameter_set_tag(cpl_parameter *self, const char *tag); -const char *cpl_parameter_get_alias(const cpl_parameter *self, - cpl_parameter_mode mode); +const char * +cpl_parameter_get_alias(const cpl_parameter *self, cpl_parameter_mode mode); cpl_error_code cpl_parameter_set_alias(cpl_parameter *self, cpl_parameter_mode mode, diff -Nru cpl-7.1.4+ds/cplui/cpl_parameterlist.c cpl-7.2.2+ds/cplui/cpl_parameterlist.c --- cpl-7.1.4+ds/cplui/cpl_parameterlist.c 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplui/cpl_parameterlist.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -18,7 +18,7 @@ */ #ifdef HAVE_CONFIG_H -# include +#include #endif #include @@ -60,7 +60,8 @@ * Parameter list data type representation */ -struct _cpl_parameterlist_ { +struct _cpl_parameterlist_ +{ cx_slist *data; cx_slist_iterator search; }; @@ -107,14 +108,12 @@ void cpl_parameterlist_delete(cpl_parameterlist *self) { - if (self) { cx_slist_destroy(self->data, (cx_free_func)cpl_parameter_delete); cx_free(self); } return; - } @@ -147,16 +146,12 @@ cpl_size cpl_parameterlist_get_size(const cpl_parameterlist *self) { - - - if (self == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return 0; } return (cpl_size)cx_slist_size(self->data); - } @@ -188,9 +183,6 @@ cpl_error_code cpl_parameterlist_append(cpl_parameterlist *self, cpl_parameter *parameter) { - - - if (self == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } @@ -198,7 +190,6 @@ cx_slist_push_back(self->data, parameter); return CPL_ERROR_NONE; - } @@ -233,8 +224,6 @@ const cpl_parameter * cpl_parameterlist_get_first_const(const cpl_parameterlist *self) { - - cpl_parameterlist *_self = (cpl_parameterlist *)self; @@ -250,7 +239,6 @@ } return cx_slist_get(self->data, self->search); - } /** @@ -285,13 +273,13 @@ cpl_parameterlist_get_first(cpl_parameterlist *self) { cpl_errorstate prestate = cpl_errorstate_get(); - cpl_parameter *par = (cpl_parameter *)cpl_parameterlist_get_first_const(self); + cpl_parameter *par = + (cpl_parameter *)cpl_parameterlist_get_first_const(self); if (!cpl_errorstate_is_equal(prestate)) (void)cpl_error_set_where(cpl_func); return par; - } /** @@ -329,8 +317,6 @@ const cpl_parameter * cpl_parameterlist_get_next_const(const cpl_parameterlist *self) { - - cx_slist_iterator next; cpl_parameterlist *_self = (cpl_parameterlist *)self; @@ -350,7 +336,6 @@ _self->search = next; return cx_slist_get(self->data, next); - } /** @@ -389,13 +374,13 @@ cpl_parameterlist_get_next(cpl_parameterlist *self) { cpl_errorstate prestate = cpl_errorstate_get(); - cpl_parameter *par = (cpl_parameter *)cpl_parameterlist_get_next_const(self); + cpl_parameter *par = + (cpl_parameter *)cpl_parameterlist_get_next_const(self); if (!cpl_errorstate_is_equal(prestate)) (void)cpl_error_set_where(cpl_func); return par; - } /** @@ -433,9 +418,6 @@ const cpl_parameter * cpl_parameterlist_get_last_const(const cpl_parameterlist *self) { - - - if (self == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return NULL; @@ -447,7 +429,6 @@ } return cx_slist_back(self->data); - } /** @@ -485,9 +466,9 @@ cpl_parameter * cpl_parameterlist_get_last(cpl_parameterlist *self) { - cpl_errorstate prestate = cpl_errorstate_get(); - cpl_parameter *par = (cpl_parameter *)cpl_parameterlist_get_last_const(self); + cpl_parameter *par = + (cpl_parameter *)cpl_parameterlist_get_last_const(self); if (!cpl_errorstate_is_equal(prestate)) (void)cpl_error_set_where(cpl_func); @@ -528,8 +509,6 @@ const cpl_parameter * cpl_parameterlist_find_const(const cpl_parameterlist *self, const char *name) { - - cx_slist_iterator first, last; @@ -542,7 +521,6 @@ last = cx_slist_end(self->data); while (first != last) { - cpl_parameter *p = cx_slist_get(self->data, first); @@ -551,7 +529,6 @@ } first = cx_slist_next(self->data, first); - } return NULL; @@ -590,15 +567,14 @@ cpl_parameter * cpl_parameterlist_find(cpl_parameterlist *self, const char *name) { - cpl_errorstate prestate = cpl_errorstate_get(); - cpl_parameter *par = (cpl_parameter *)cpl_parameterlist_find_const(self, name); + cpl_parameter *par = + (cpl_parameter *)cpl_parameterlist_find_const(self, name); if (!cpl_errorstate_is_equal(prestate)) (void)cpl_error_set_where(cpl_func); return par; - } /** @@ -634,8 +610,6 @@ const cpl_parameter * cpl_parameterlist_find_type_const(const cpl_parameterlist *self, cpl_type type) { - - cx_slist_iterator first, last; @@ -648,7 +622,6 @@ last = cx_slist_end(self->data); while (first != last) { - cpl_parameter *p = cx_slist_get(self->data, first); @@ -657,7 +630,6 @@ } first = cx_slist_next(self->data, first); - } return NULL; @@ -696,15 +668,14 @@ cpl_parameter * cpl_parameterlist_find_type(cpl_parameterlist *self, cpl_type type) { - cpl_errorstate prestate = cpl_errorstate_get(); - cpl_parameter *par = (cpl_parameter *)cpl_parameterlist_find_type_const(self, type); + cpl_parameter *par = + (cpl_parameter *)cpl_parameterlist_find_type_const(self, type); if (!cpl_errorstate_is_equal(prestate)) (void)cpl_error_set_where(cpl_func); return par; - } /** @@ -739,10 +710,8 @@ const cpl_parameter * cpl_parameterlist_find_context_const(const cpl_parameterlist *self, - const char *context) + const char *context) { - - cx_slist_iterator first, last; @@ -755,35 +724,26 @@ last = cx_slist_end(self->data); while (first != last) { - cpl_parameter *p = cx_slist_get(self->data, first); const cxchar *_context = cpl_parameter_get_context(p); if ((context == NULL) && (_context == NULL)) { - return p; - } else { - if (context != NULL && _context != NULL) { - if (strcmp(_context, context) == 0) { return p; } - } - } first = cx_slist_next(self->data, first); - } return NULL; - } /** @@ -817,18 +777,16 @@ */ cpl_parameter * -cpl_parameterlist_find_context(cpl_parameterlist *self, - const char *context) +cpl_parameterlist_find_context(cpl_parameterlist *self, const char *context) { - cpl_errorstate prestate = cpl_errorstate_get(); - cpl_parameter *par = (cpl_parameter *)cpl_parameterlist_find_context_const(self, context); + cpl_parameter *par = + (cpl_parameter *)cpl_parameterlist_find_context_const(self, context); if (!cpl_errorstate_is_equal(prestate)) (void)cpl_error_set_where(cpl_func); return par; - } @@ -865,7 +823,6 @@ const cpl_parameter * cpl_parameterlist_find_tag_const(const cpl_parameterlist *self, const char *tag) { - cx_slist_iterator first, last; @@ -878,34 +835,26 @@ last = cx_slist_end(self->data); while (first != last) { - cpl_parameter *p = cx_slist_get(self->data, first); const cxchar *_tag = cpl_parameter_get_tag(p); if ((tag == NULL) && (_tag == NULL)) { - return p; } else { - if ((tag != NULL) && (_tag != NULL)) { - if (strcmp(_tag, tag) == 0) { return p; } - } - } first = cx_slist_next(self->data, first); - } return NULL; - } /** @@ -941,15 +890,14 @@ cpl_parameter * cpl_parameterlist_find_tag(cpl_parameterlist *self, const char *tag) { - cpl_errorstate prestate = cpl_errorstate_get(); - cpl_parameter *par = (cpl_parameter *)cpl_parameterlist_find_tag_const(self, tag); + cpl_parameter *par = + (cpl_parameter *)cpl_parameterlist_find_tag_const(self, tag); if (!cpl_errorstate_is_equal(prestate)) (void)cpl_error_set_where(cpl_func); return par; - } /** @@ -972,9 +920,7 @@ void cpl_parameterlist_dump(const cpl_parameterlist *self, FILE *stream) { - if (self != NULL) { - cx_slist_const_iterator pos = cx_slist_begin(self->data); if (stream == NULL) { @@ -982,17 +928,13 @@ } while (pos != cx_slist_end(self->data)) { - - const cpl_parameter *p = cx_slist_get(self->data, pos); + const cpl_parameter *p = cx_slist_get(self->data, pos); cpl_parameter_dump(p, stream); pos = cx_slist_next(self->data, pos); - } - } return; - } /**@}*/ diff -Nru cpl-7.1.4+ds/cplui/cpl_parameterlist.h cpl-7.2.2+ds/cplui/cpl_parameterlist.h --- cpl-7.1.4+ds/cplui/cpl_parameterlist.h 2021-05-07 12:09:09.000000000 +0000 +++ cpl-7.2.2+ds/cplui/cpl_parameterlist.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -55,41 +55,46 @@ * Element insertion. */ -cpl_error_code cpl_parameterlist_append(cpl_parameterlist *self, - cpl_parameter *parameter); +cpl_error_code +cpl_parameterlist_append(cpl_parameterlist *self, cpl_parameter *parameter); /* * Element access */ -const cpl_parameter *cpl_parameterlist_get_first_const(const cpl_parameterlist *self); +const cpl_parameter * +cpl_parameterlist_get_first_const(const cpl_parameterlist *self); cpl_parameter *cpl_parameterlist_get_first(cpl_parameterlist *self); -const cpl_parameter *cpl_parameterlist_get_next_const(const cpl_parameterlist *self); +const cpl_parameter * +cpl_parameterlist_get_next_const(const cpl_parameterlist *self); cpl_parameter *cpl_parameterlist_get_next(cpl_parameterlist *self); -const cpl_parameter *cpl_parameterlist_get_last_const(const cpl_parameterlist *self); +const cpl_parameter * +cpl_parameterlist_get_last_const(const cpl_parameterlist *self); cpl_parameter *cpl_parameterlist_get_last(cpl_parameterlist *self); -const cpl_parameter *cpl_parameterlist_find_const(const cpl_parameterlist *self, - const char *name); -cpl_parameter *cpl_parameterlist_find(cpl_parameterlist *self, - const char *name); - -const cpl_parameter *cpl_parameterlist_find_type_const(const cpl_parameterlist *self, - cpl_type type); -cpl_parameter *cpl_parameterlist_find_type(cpl_parameterlist *self, - cpl_type type); - -const cpl_parameter *cpl_parameterlist_find_context_const(const cpl_parameterlist *self, - const char *context); -cpl_parameter *cpl_parameterlist_find_context(cpl_parameterlist *self, - const char *context); - -const cpl_parameter *cpl_parameterlist_find_tag_const(const cpl_parameterlist *self, - const char *tag); -cpl_parameter *cpl_parameterlist_find_tag(cpl_parameterlist *self, - const char *tag); +const cpl_parameter * +cpl_parameterlist_find_const(const cpl_parameterlist *self, const char *name); +cpl_parameter * +cpl_parameterlist_find(cpl_parameterlist *self, const char *name); + +const cpl_parameter * +cpl_parameterlist_find_type_const(const cpl_parameterlist *self, cpl_type type); +cpl_parameter * +cpl_parameterlist_find_type(cpl_parameterlist *self, cpl_type type); + +const cpl_parameter * +cpl_parameterlist_find_context_const(const cpl_parameterlist *self, + const char *context); +cpl_parameter * +cpl_parameterlist_find_context(cpl_parameterlist *self, const char *context); + +const cpl_parameter * +cpl_parameterlist_find_tag_const(const cpl_parameterlist *self, + const char *tag); +cpl_parameter * +cpl_parameterlist_find_tag(cpl_parameterlist *self, const char *tag); /* * Debugging diff -Nru cpl-7.1.4+ds/cplui/cpl_plugin.c cpl-7.2.2+ds/cplui/cpl_plugin.c --- cpl-7.1.4+ds/cplui/cpl_plugin.c 2021-05-07 12:09:11.000000000 +0000 +++ cpl-7.2.2+ds/cplui/cpl_plugin.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -18,7 +18,7 @@ */ #ifdef HAVE_CONFIG_H -# include +#include #endif #include @@ -101,27 +101,25 @@ cpl_plugin * cpl_plugin_new(void) { + cpl_plugin *self = (cpl_plugin *)cx_malloc(sizeof *self); - cpl_plugin *self = (cpl_plugin *) cx_malloc(sizeof *self); + self->api = 0; + self->version = 0L; + self->type = 0L; + + self->name = NULL; + self->synopsis = NULL; + self->description = NULL; + self->author = NULL; + self->email = NULL; + self->copyright = NULL; - self->api = 0; - self->version = 0L; - self->type = 0L; - - self->name = NULL; - self->synopsis = NULL; - self->description = NULL; - self->author = NULL; - self->email = NULL; - self->copyright = NULL; - - self->initialize = NULL; - self->execute = NULL; + self->initialize = NULL; + self->execute = NULL; self->deinitialize = NULL; return self; - } @@ -175,9 +173,6 @@ cpl_error_code cpl_plugin_copy(cpl_plugin *self, const cpl_plugin *other) { - - - if (self == NULL || other == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } @@ -221,7 +216,6 @@ self->deinitialize = other->deinitialize; return CPL_ERROR_NONE; - } @@ -251,12 +245,10 @@ void cpl_plugin_delete(cpl_plugin *self) { - if (self != NULL) { - - self->api = 0; - self->version = 0L; - self->type = 0L; + self->api = 0; + self->version = 0L; + self->type = 0L; if (self->name != NULL) { cx_free((cxptr)self->name); @@ -288,16 +280,14 @@ self->copyright = NULL; } - self->initialize = NULL; - self->execute = NULL; + self->initialize = NULL; + self->execute = NULL; self->deinitialize = NULL; cx_free(self); - } return; - } @@ -337,9 +327,6 @@ cpl_error_code cpl_plugin_set_api(cpl_plugin *self, unsigned int api) { - - - if (self == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } @@ -347,7 +334,6 @@ self->api = api; return CPL_ERROR_NONE; - } @@ -381,16 +367,12 @@ unsigned int cpl_plugin_get_api(const cpl_plugin *self) { - - - if (self == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return 0; } return self->api; - } @@ -426,9 +408,6 @@ int cpl_plugin_set_version(cpl_plugin *self, unsigned long version) { - - - if (self == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } @@ -436,7 +415,6 @@ self->version = version; return CPL_ERROR_NONE; - } @@ -467,16 +445,12 @@ unsigned long cpl_plugin_get_version(const cpl_plugin *self) { - - - if (self == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return 0; } return self->version; - } @@ -515,8 +489,6 @@ char * cpl_plugin_get_version_string(const cpl_plugin *self) { - - unsigned long version; unsigned major; unsigned minor; @@ -529,14 +501,13 @@ version = self->version; - micro = version % 100; + micro = version % 100; version = version / 100; - minor = version % 100; + minor = version % 100; version = version / 100; - major = version; + major = version; return cpl_sprintf("%-u.%-u.%-u", major, minor, micro); - } @@ -569,9 +540,6 @@ cpl_error_code cpl_plugin_set_type(cpl_plugin *self, unsigned long type) { - - - if (self == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } @@ -579,7 +547,6 @@ self->type = type; return CPL_ERROR_NONE; - } @@ -612,16 +579,12 @@ unsigned long cpl_plugin_get_type(const cpl_plugin *self) { - - - if (self == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); - return (unsigned long) CPL_PLUGIN_TYPE_NONE; + return (unsigned long)CPL_PLUGIN_TYPE_NONE; } return self->type; - } @@ -656,7 +619,6 @@ char * cpl_plugin_get_type_string(const cpl_plugin *self) { - const char *stype; if (self == NULL) { @@ -716,9 +678,6 @@ cpl_error_code cpl_plugin_set_name(cpl_plugin *self, const char *name) { - - - if (self == NULL || name == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } @@ -728,7 +687,6 @@ self->name = cx_strdup(name); return CPL_ERROR_NONE; - } @@ -762,15 +720,12 @@ const char * cpl_plugin_get_name(const cpl_plugin *self) { - - if (self == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return NULL; } return self->name; - } @@ -803,7 +758,6 @@ cpl_error_code cpl_plugin_set_synopsis(cpl_plugin *self, const char *synopsis) { - if (self == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } @@ -813,7 +767,6 @@ self->synopsis = synopsis ? cx_strdup(synopsis) : NULL; return CPL_ERROR_NONE; - } @@ -848,14 +801,12 @@ const char * cpl_plugin_get_synopsis(const cpl_plugin *self) { - if (self == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return NULL; } return self->synopsis; - } @@ -889,9 +840,6 @@ cpl_error_code cpl_plugin_set_description(cpl_plugin *self, const char *description) { - - - if (self == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } @@ -901,7 +849,6 @@ self->description = description ? cx_strdup(description) : NULL; return CPL_ERROR_NONE; - } @@ -936,16 +883,12 @@ const char * cpl_plugin_get_description(const cpl_plugin *self) { - - - if (self == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return NULL; } return self->description; - } @@ -979,7 +922,6 @@ cpl_error_code cpl_plugin_set_author(cpl_plugin *self, const char *author) { - if (self == NULL || author == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } @@ -989,7 +931,6 @@ self->author = cx_strdup(author); return CPL_ERROR_NONE; - } @@ -1023,16 +964,12 @@ const char * cpl_plugin_get_author(const cpl_plugin *self) { - - - if (self == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return NULL; } return self->author; - } @@ -1068,7 +1005,6 @@ cpl_error_code cpl_plugin_set_email(cpl_plugin *self, const char *email) { - if (self == NULL || email == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } @@ -1078,7 +1014,6 @@ self->email = cx_strdup(email); return CPL_ERROR_NONE; - } @@ -1113,16 +1048,12 @@ const char * cpl_plugin_get_email(const cpl_plugin *self) { - - - if (self == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return NULL; } return self->email; - } @@ -1157,7 +1088,6 @@ cpl_error_code cpl_plugin_set_copyright(cpl_plugin *self, const char *copyright) { - if (self == NULL || copyright == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } @@ -1167,7 +1097,6 @@ self->copyright = cx_strdup(copyright); return CPL_ERROR_NONE; - } @@ -1202,16 +1131,12 @@ const char * cpl_plugin_get_copyright(const cpl_plugin *self) { - - - if (self == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return NULL; } return self->copyright; - } @@ -1245,9 +1170,6 @@ cpl_error_code cpl_plugin_set_init(cpl_plugin *self, cpl_plugin_func func) { - - - if (self == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } @@ -1255,7 +1177,6 @@ self->initialize = func; return CPL_ERROR_NONE; - } @@ -1286,16 +1207,12 @@ cpl_plugin_func cpl_plugin_get_init(const cpl_plugin *self) { - - - if (self == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return NULL; } return self->initialize; - } @@ -1330,9 +1247,6 @@ cpl_error_code cpl_plugin_set_exec(cpl_plugin *self, cpl_plugin_func func) { - - - if (self == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } @@ -1340,7 +1254,6 @@ self->execute = func; return CPL_ERROR_NONE; - } @@ -1371,16 +1284,12 @@ cpl_plugin_func cpl_plugin_get_exec(const cpl_plugin *self) { - - - if (self == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return NULL; } return self->execute; - } @@ -1414,9 +1323,6 @@ cpl_error_code cpl_plugin_set_deinit(cpl_plugin *self, cpl_plugin_func func) { - - - if (self == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } @@ -1424,7 +1330,6 @@ self->deinitialize = func; return CPL_ERROR_NONE; - } @@ -1455,16 +1360,12 @@ cpl_plugin_func cpl_plugin_get_deinit(const cpl_plugin *self) { - - - if (self == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return NULL; } return self->deinitialize; - } @@ -1509,13 +1410,20 @@ */ cpl_error_code -cpl_plugin_init(cpl_plugin *self, unsigned int api, unsigned long version, - unsigned long type, const char *name, const char *synopsis, - const char *description, const char *author, const char *email, - const char *copyright, cpl_plugin_func create, - cpl_plugin_func execute, cpl_plugin_func destroy) +cpl_plugin_init(cpl_plugin *self, + unsigned int api, + unsigned long version, + unsigned long type, + const char *name, + const char *synopsis, + const char *description, + const char *author, + const char *email, + const char *copyright, + cpl_plugin_func create, + cpl_plugin_func execute, + cpl_plugin_func destroy) { - if (self == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } @@ -1539,7 +1447,6 @@ cpl_plugin_set_deinit(self, destroy); return CPL_ERROR_NONE; - } /** @@ -1559,9 +1466,7 @@ void cpl_plugin_dump(const cpl_plugin *self, FILE *stream) { - if (self != NULL) { - const char *s; char *a; @@ -1569,7 +1474,7 @@ stream = stdout; } - fprintf(stream, "Plugin at %p:\n", (const void*)self); + fprintf(stream, "Plugin at %p:\n", (const void *)self); s = cpl_plugin_get_name(self); fprintf(stream, " Name (%p): %s\n", s, s); @@ -1585,14 +1490,14 @@ fprintf(stream, " API Version: %u", cpl_plugin_get_api(self)); -CPL_DIAG_PRAGMA_PUSH_IGN(-Wformat=); + CPL_DIAG_PRAGMA_PUSH_IGN(-Wformat=); fprintf(stream, " Initialization handler at %p\n", cpl_plugin_get_init(self)); fprintf(stream, " Execution handler at %p\n", cpl_plugin_get_exec(self)); fprintf(stream, " Cleanup handler at %p\n", cpl_plugin_get_deinit(self)); -CPL_DIAG_PRAGMA_POP; + CPL_DIAG_PRAGMA_POP; s = cpl_plugin_get_synopsis(self); fprintf(stream, " Synopsis (%p): %s\n", s, s); @@ -1611,6 +1516,5 @@ } return; - } /**@}*/ diff -Nru cpl-7.1.4+ds/cplui/cpl_plugin.h cpl-7.2.2+ds/cplui/cpl_plugin.h --- cpl-7.1.4+ds/cplui/cpl_plugin.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplui/cpl_plugin.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -37,7 +37,7 @@ * @hideinitializer */ -#define CPL_PLUGIN_API (1) +#define CPL_PLUGIN_API (1) /** @@ -49,12 +49,13 @@ * Predefined plugin types supported by the Common Pipeline Library itself. */ -enum _cpl_plugin_type_ { +enum _cpl_plugin_type_ +{ /** * Plugin is of unknown or undefined type */ - CPL_PLUGIN_TYPE_NONE = 0, + CPL_PLUGIN_TYPE_NONE = 0, /** * Plugin is a complete data reduction task, i.e. a sequence of individual @@ -103,8 +104,8 @@ * The type representation of the generic plugin interface. */ -struct _cpl_plugin_ { - +struct _cpl_plugin_ +{ /** * @brief * The API version the Plugin complies to. @@ -252,7 +253,6 @@ */ cpl_plugin_func deinitialize; - }; @@ -268,7 +268,7 @@ * Accessor Functions */ -cpl_error_code cpl_plugin_set_api(cpl_plugin *self , unsigned int api); +cpl_error_code cpl_plugin_set_api(cpl_plugin *self, unsigned int api); unsigned int cpl_plugin_get_api(const cpl_plugin *self); int cpl_plugin_set_version(cpl_plugin *self, unsigned long version); @@ -285,8 +285,8 @@ cpl_error_code cpl_plugin_set_synopsis(cpl_plugin *self, const char *synopsis); const char *cpl_plugin_get_synopsis(const cpl_plugin *self); -cpl_error_code cpl_plugin_set_description(cpl_plugin *self, - const char *description); +cpl_error_code +cpl_plugin_set_description(cpl_plugin *self, const char *description); const char *cpl_plugin_get_description(const cpl_plugin *self); cpl_error_code cpl_plugin_set_author(cpl_plugin *self, const char *author); @@ -295,8 +295,8 @@ cpl_error_code cpl_plugin_set_email(cpl_plugin *self, const char *email); const char *cpl_plugin_get_email(const cpl_plugin *self); -cpl_error_code cpl_plugin_set_copyright(cpl_plugin *self, - const char *copyright); +cpl_error_code +cpl_plugin_set_copyright(cpl_plugin *self, const char *copyright); const char *cpl_plugin_get_copyright(const cpl_plugin *self); cpl_error_code cpl_plugin_set_init(cpl_plugin *self, cpl_plugin_func); @@ -313,11 +313,16 @@ * Convenience Functions */ -cpl_error_code cpl_plugin_init(cpl_plugin *self, unsigned int api, - unsigned long version, unsigned long type, - const char *name, const char *synopsis, - const char *description, const char *author, - const char *email, const char *copyright, +cpl_error_code cpl_plugin_init(cpl_plugin *self, + unsigned int api, + unsigned long version, + unsigned long type, + const char *name, + const char *synopsis, + const char *description, + const char *author, + const char *email, + const char *copyright, cpl_plugin_func initialize, cpl_plugin_func execute, cpl_plugin_func deinitialize); diff -Nru cpl-7.1.4+ds/cplui/cpl_plugininfo.h cpl-7.2.2+ds/cplui/cpl_plugininfo.h --- cpl-7.1.4+ds/cplui/cpl_plugininfo.h 2021-05-07 12:09:11.000000000 +0000 +++ cpl-7.2.2+ds/cplui/cpl_plugininfo.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 diff -Nru cpl-7.1.4+ds/cplui/cpl_pluginlist.c cpl-7.2.2+ds/cplui/cpl_pluginlist.c --- cpl-7.1.4+ds/cplui/cpl_pluginlist.c 2021-05-07 12:09:09.000000000 +0000 +++ cpl-7.2.2+ds/cplui/cpl_pluginlist.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -18,7 +18,7 @@ */ #ifdef HAVE_CONFIG_H -# include +#include #endif #include @@ -53,7 +53,8 @@ /**@{*/ -struct _cpl_pluginlist_ { +struct _cpl_pluginlist_ +{ cx_list *data; cx_list_iterator search; }; @@ -73,7 +74,6 @@ cpl_pluginlist * cpl_pluginlist_new(void) { - cpl_pluginlist *self; @@ -93,7 +93,6 @@ self->search = NULL; return self; - } @@ -112,9 +111,7 @@ void cpl_pluginlist_delete(cpl_pluginlist *self) { - if (self) { - if (self->data) { cx_list_destroy(self->data, (cx_free_func)cpl_plugin_delete); self->data = NULL; @@ -127,7 +124,6 @@ } return; - } @@ -160,9 +156,6 @@ int cpl_pluginlist_get_size(cpl_pluginlist *self) { - - - if (self == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return 0; @@ -171,7 +164,6 @@ cx_assert(self->data != NULL); return (int)cx_list_size(self->data); - } @@ -208,9 +200,6 @@ cpl_error_code cpl_pluginlist_append(cpl_pluginlist *self, const cpl_plugin *plugin) { - - - if (self == NULL || plugin == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } @@ -218,7 +207,6 @@ cx_list_push_back(self->data, (cxptr)plugin); return CPL_ERROR_NONE; - } @@ -255,9 +243,6 @@ cpl_error_code cpl_pluginlist_prepend(cpl_pluginlist *self, const cpl_plugin *plugin) { - - - if (self == NULL || plugin == NULL) { return cpl_error_set_(CPL_ERROR_NULL_INPUT); } @@ -265,7 +250,6 @@ cx_list_push_front(self->data, (cxptr)plugin); return CPL_ERROR_NONE; - } @@ -298,9 +282,6 @@ cpl_plugin * cpl_pluginlist_get_first(cpl_pluginlist *self) { - - - if (self == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return NULL; @@ -315,8 +296,7 @@ return NULL; } - return (cpl_plugin *) cx_list_get(self->data, self->search); - + return (cpl_plugin *)cx_list_get(self->data, self->search); } @@ -361,8 +341,6 @@ cpl_plugin * cpl_pluginlist_get_next(cpl_pluginlist *self) { - - cx_list_iterator next; @@ -378,7 +356,7 @@ cx_assert(self->data != NULL); - next = cx_list_next(self->data, self->search); + next = cx_list_next(self->data, self->search); if (next == cx_list_end(self->data)) { self->search = cx_list_begin(self->data); @@ -387,8 +365,7 @@ self->search = next; - return (cpl_plugin *) cx_list_get(self->data, self->search); - + return (cpl_plugin *)cx_list_get(self->data, self->search); } @@ -420,9 +397,6 @@ cpl_plugin * cpl_pluginlist_get_last(cpl_pluginlist *self) { - - - if (self == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return NULL; @@ -434,8 +408,7 @@ return NULL; } - return (cpl_plugin *) cx_list_back(self->data); - + return (cpl_plugin *)cx_list_back(self->data); } @@ -471,8 +444,6 @@ cpl_plugin * cpl_pluginlist_find(cpl_pluginlist *self, const char *name) { - - cx_list_iterator first, last; @@ -496,7 +467,6 @@ } return NULL; - } @@ -520,9 +490,7 @@ void cpl_pluginlist_dump(const cpl_pluginlist *self, FILE *stream) { - if (self != NULL) { - cx_list_const_iterator pos = cx_list_begin(self->data); if (stream == NULL) { @@ -530,18 +498,13 @@ } while (pos != cx_list_end(self->data)) { - const cpl_plugin *p = cx_list_get(self->data, pos); cpl_plugin_dump(p, stream); pos = cx_list_next(self->data, pos); - } - } return; - } /**@}*/ - diff -Nru cpl-7.1.4+ds/cplui/cpl_pluginlist.h cpl-7.2.2+ds/cplui/cpl_pluginlist.h --- cpl-7.1.4+ds/cplui/cpl_pluginlist.h 2021-05-07 12:09:09.000000000 +0000 +++ cpl-7.2.2+ds/cplui/cpl_pluginlist.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -27,7 +27,6 @@ #include - CPL_BEGIN_DECLS /** diff -Nru cpl-7.1.4+ds/cplui/cpl_recipeconfig.c cpl-7.2.2+ds/cplui/cpl_recipeconfig.c --- cpl-7.1.4+ds/cplui/cpl_recipeconfig.c 2021-05-07 12:09:11.000000000 +0000 +++ cpl-7.2.2+ds/cplui/cpl_recipeconfig.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -18,7 +18,7 @@ */ #ifdef HAVE_CONFIG_H -# include +#include #endif #include @@ -72,13 +72,12 @@ typedef struct _cpl_frameinfo_ cpl_frameinfo; -struct _cpl_frameinfo_ { - +struct _cpl_frameinfo_ +{ cpl_framedata data; - cx_list* iframes; - cx_list* oframes; - + cx_list *iframes; + cx_list *oframes; }; @@ -86,27 +85,23 @@ * The recipe configuration object */ -struct _cpl_recipeconfig_ { - cx_list* frames; +struct _cpl_recipeconfig_ +{ + cx_list *frames; }; - static void -_cpl_frameinfo_delete(cpl_frameinfo* self) +_cpl_frameinfo_delete(cpl_frameinfo *self) { - if (self != NULL) { - if (self->oframes != NULL) { - cx_list_destroy(self->oframes, - (cx_free_func)cpl_framedata_delete); + cx_list_destroy(self->oframes, (cx_free_func)cpl_framedata_delete); self->oframes = NULL; } if (self->iframes != NULL) { - cx_list_destroy(self->iframes, - (cx_free_func)cpl_framedata_delete); + cx_list_destroy(self->iframes, (cx_free_func)cpl_framedata_delete); self->iframes = NULL; } @@ -114,25 +109,25 @@ cx_free(self); self = NULL; - } return; - } -inline static cpl_frameinfo* -_cpl_frameinfo_create(const cxchar* tag, cxint min_count, cxint max_count, - const cx_list* iframes, const cx_list* oframes) +inline static cpl_frameinfo * +_cpl_frameinfo_create(const cxchar *tag, + cxint min_count, + cxint max_count, + const cx_list *iframes, + const cx_list *oframes) { - - cpl_frameinfo* self = cx_calloc(1, sizeof *self); + cpl_frameinfo *self = cx_calloc(1, sizeof *self); cpl_errorstate prevstate = cpl_errorstate_get(); - cpl_framedata_set((cpl_framedata*)self, tag, min_count, max_count); + cpl_framedata_set((cpl_framedata *)self, tag, min_count, max_count); if (!cpl_errorstate_is_equal(prevstate)) { if (cpl_error_get_code() == CPL_ERROR_ILLEGAL_INPUT) { @@ -140,49 +135,44 @@ self = NULL; return NULL; - } else { + } + else { cpl_errorstate_set(prevstate); } } - self->iframes = (cx_list*)iframes; - self->oframes = (cx_list*)oframes; + self->iframes = (cx_list *)iframes; + self->oframes = (cx_list *)oframes; return self; - } -inline static cxchar** -_cpl_recipeconfig_get_tags(const cx_list* self) +inline static cxchar ** +_cpl_recipeconfig_get_tags(const cx_list *self) { - - cxchar** tags = NULL; + cxchar **tags = NULL; if (self == NULL) { return tags; } if (cx_list_empty(self) == TRUE) { - - tags = cx_malloc(sizeof(const cxchar*)); + tags = cx_malloc(sizeof(const cxchar *)); tags[0] = NULL; return tags; - } else { - cxsize i = 0; cxsize sz = cx_list_size(self); cx_list_iterator entry = cx_list_begin(self); - tags = cx_calloc(sz + 1, sizeof(const cxchar*)); + tags = cx_calloc(sz + 1, sizeof(const cxchar *)); while (entry != cx_list_end(self)) { - - const cxchar** tag = cx_list_get(self, entry); + const cxchar **tag = cx_list_get(self, entry); tags[i] = cx_strdup(*tag); entry = cx_list_next(self, entry); @@ -190,18 +180,15 @@ } tags[sz] = NULL; - } return tags; - } inline static cxptr -_cpl_recipeconfig_find(const cx_list* tags, const cxchar* tag) +_cpl_recipeconfig_find(const cx_list *tags, const cxchar *tag) { - cxptr data = NULL; cx_list_iterator entry = NULL; @@ -213,8 +200,7 @@ entry = cx_list_begin(tags); while (entry != cx_list_end(tags)) { - - const cxchar** _data = cx_list_get(tags, entry); + const cxchar **_data = cx_list_get(tags, entry); if (strcmp(*_data, tag) == 0) { data = _data; @@ -222,23 +208,19 @@ } entry = cx_list_next(tags, entry); - } return data; - } -inline static cpl_frameinfo* -_cpl_recipeconfig_get_config(const cpl_recipeconfig* self, const cxchar* tag) +inline static cpl_frameinfo * +_cpl_recipeconfig_get_config(const cpl_recipeconfig *self, const cxchar *tag) { - cx_assert((self != NULL) && (self->frames != NULL)); cx_assert(tag != NULL); - return (cpl_frameinfo*)_cpl_recipeconfig_find(self->frames, tag); - + return (cpl_frameinfo *)_cpl_recipeconfig_find(self->frames, tag); } @@ -252,16 +234,14 @@ * The function creates a new, empty recipe configuration object. */ -cpl_recipeconfig* +cpl_recipeconfig * cpl_recipeconfig_new(void) { - - cpl_recipeconfig* self = cx_calloc(1, sizeof *self); + cpl_recipeconfig *self = cx_calloc(1, sizeof *self); self->frames = cx_list_new(); return self; - } @@ -280,13 +260,11 @@ */ void -cpl_recipeconfig_delete(cpl_recipeconfig* self) +cpl_recipeconfig_delete(cpl_recipeconfig *self) { - if (self != NULL) { if (self->frames != NULL) { - cx_list_destroy(self->frames, - (cx_free_func)_cpl_frameinfo_delete); + cx_list_destroy(self->frames, (cx_free_func)_cpl_frameinfo_delete); self->frames = NULL; } @@ -295,7 +273,6 @@ } return; - } @@ -315,37 +292,29 @@ */ void -cpl_recipeconfig_clear(cpl_recipeconfig* self) +cpl_recipeconfig_clear(cpl_recipeconfig *self) { - if (self != NULL) { - cx_assert(self->frames != NULL); if (cx_list_empty(self->frames) == FALSE) { - cx_list_iterator position = cx_list_begin(self->frames); while (position != cx_list_end(self->frames)) { - - cpl_frameinfo* data = cx_list_get(self->frames, position); + cpl_frameinfo *data = cx_list_get(self->frames, position); _cpl_frameinfo_delete(data); data = NULL; position = cx_list_next(self->frames, position); - } cx_list_clear(self->frames); cx_assert(cx_list_empty(self->frames)); - } - } return; - } @@ -385,12 +354,9 @@ * itself must be deallocated using cpl_free(). */ -char** -cpl_recipeconfig_get_tags(const cpl_recipeconfig* self) +char ** +cpl_recipeconfig_get_tags(const cpl_recipeconfig *self) { - - - if (self == NULL) { cpl_error_set_(CPL_ERROR_NULL_INPUT); return NULL; @@ -399,7 +365,6 @@ cx_assert(self->frames != NULL); return _cpl_recipeconfig_get_tags(self->frames); - } @@ -450,11 +415,8 @@ */ int -cpl_recipeconfig_set_tags(cpl_recipeconfig* self, const cpl_framedata* data) +cpl_recipeconfig_set_tags(cpl_recipeconfig *self, const cpl_framedata *data) { - - - cxint status = 0; cxsize i = 0; @@ -472,7 +434,6 @@ cx_assert(self->frames != NULL); while (data[i].tag != NULL) { - if (data[i].tag[0] == '\0') { cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); status = 1; @@ -491,14 +452,11 @@ data[i].max_count, cx_list_new(), cx_list_new()); cx_list_push_back(self->frames, info); - } ++i; - } return status; - } @@ -546,12 +504,11 @@ */ int -cpl_recipeconfig_set_tag(cpl_recipeconfig* self, const char* tag, - cpl_size min_count, cpl_size max_count) +cpl_recipeconfig_set_tag(cpl_recipeconfig *self, + const char *tag, + cpl_size min_count, + cpl_size max_count) { - - - cxptr info = NULL; @@ -577,13 +534,12 @@ info = NULL; } - info = _cpl_frameinfo_create(tag, min_count, max_count, - cx_list_new(), cx_list_new()); + info = _cpl_frameinfo_create(tag, min_count, max_count, cx_list_new(), + cx_list_new()); cx_list_push_back(self->frames, info); return 0; - } @@ -630,13 +586,10 @@ * i.e. the last element of the array is set to @c NULL. */ -char** -cpl_recipeconfig_get_inputs(const cpl_recipeconfig* self, const char* tag) +char ** +cpl_recipeconfig_get_inputs(const cpl_recipeconfig *self, const char *tag) { - - - - cxchar** tags = NULL; + cxchar **tags = NULL; if (self == NULL) { @@ -651,8 +604,7 @@ return NULL; } else { - - cpl_frameinfo* info = _cpl_recipeconfig_get_config(self, tag); + cpl_frameinfo *info = _cpl_recipeconfig_get_config(self, tag); if (info == NULL) { cpl_error_set_(CPL_ERROR_DATA_NOT_FOUND); @@ -660,11 +612,9 @@ } tags = _cpl_recipeconfig_get_tags(info->iframes); - } return tags; - } @@ -734,17 +684,15 @@ */ int -cpl_recipeconfig_set_inputs(cpl_recipeconfig* self, const char* tag, - const cpl_framedata* data) +cpl_recipeconfig_set_inputs(cpl_recipeconfig *self, + const char *tag, + const cpl_framedata *data) { - - - cxint status = 0; cxsize i = 0; - cpl_frameinfo* info = NULL; + cpl_frameinfo *info = NULL; if ((self == NULL) || (tag == NULL)) { @@ -776,13 +724,11 @@ } while (data[i].tag != NULL) { - if ((data[i].tag[0] == '\0') || (strcmp(data[i].tag, tag) == 0)) { cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); status = 3; } else { - cxptr _data = _cpl_recipeconfig_find(info->iframes, data[i].tag); if (_data != NULL) { @@ -795,11 +741,9 @@ cx_list_push_back(info->iframes, _data); } ++i; - } return status; - } @@ -865,16 +809,15 @@ */ int -cpl_recipeconfig_set_input(cpl_recipeconfig* self, - const char* tag, const char* input, - cpl_size min_count, cpl_size max_count) +cpl_recipeconfig_set_input(cpl_recipeconfig *self, + const char *tag, + const char *input, + cpl_size min_count, + cpl_size max_count) { - - - cxptr data = NULL; - cpl_frameinfo* info = NULL; + cpl_frameinfo *info = NULL; if ((self == NULL) || (tag == NULL) || (input == NULL)) { @@ -918,7 +861,6 @@ cx_list_push_back(info->iframes, data); return 0; - } @@ -965,13 +907,10 @@ * i.e. the last element of the array is set to @c NULL. */ -char** -cpl_recipeconfig_get_outputs(const cpl_recipeconfig* self, const char* tag) +char ** +cpl_recipeconfig_get_outputs(const cpl_recipeconfig *self, const char *tag) { - - - - cxchar** tags = NULL; + cxchar **tags = NULL; if (self == NULL) { @@ -986,8 +925,7 @@ return NULL; } else { - - cpl_frameinfo* info = _cpl_recipeconfig_get_config(self, tag); + cpl_frameinfo *info = _cpl_recipeconfig_get_config(self, tag); if (info == NULL) { cpl_error_set_(CPL_ERROR_DATA_NOT_FOUND); @@ -995,11 +933,9 @@ } tags = _cpl_recipeconfig_get_tags(info->oframes); - } return tags; - } @@ -1063,17 +999,15 @@ */ int -cpl_recipeconfig_set_outputs(cpl_recipeconfig* self, const char* tag, - const char** data) +cpl_recipeconfig_set_outputs(cpl_recipeconfig *self, + const char *tag, + const char **data) { - - - cxint status = 0; cxsize i = 0; - cpl_frameinfo* info = NULL; + cpl_frameinfo *info = NULL; if ((self == NULL) || (tag == NULL)) { @@ -1105,13 +1039,11 @@ } while (data[i] != NULL) { - if (*data[i] == '\0') { cpl_error_set_(CPL_ERROR_ILLEGAL_INPUT); status = 3; } else { - cxptr _data = _cpl_recipeconfig_find(info->oframes, data[i]); if (_data != NULL) { @@ -1122,14 +1054,11 @@ _data = cpl_framedata_create(data[i], -1, -1); cx_list_push_back(info->oframes, _data); - } ++i; - } return status; - } @@ -1188,15 +1117,13 @@ */ int -cpl_recipeconfig_set_output(cpl_recipeconfig* self, const char* tag, - const char* output) +cpl_recipeconfig_set_output(cpl_recipeconfig *self, + const char *tag, + const char *output) { - - - cxptr data = NULL; - cpl_frameinfo* info = NULL; + cpl_frameinfo *info = NULL; if ((self == NULL) || (tag == NULL) || (output == NULL)) { @@ -1240,7 +1167,6 @@ cx_list_push_back(info->oframes, data); return 0; - } @@ -1293,14 +1219,12 @@ */ cpl_size -cpl_recipeconfig_get_min_count(const cpl_recipeconfig* self, - const char* tag, const char* input) +cpl_recipeconfig_get_min_count(const cpl_recipeconfig *self, + const char *tag, + const char *input) { - - - - const cpl_frameinfo* info = NULL; - const cpl_framedata* data = NULL; + const cpl_frameinfo *info = NULL; + const cpl_framedata *data = NULL; if (self == NULL) { @@ -1323,7 +1247,7 @@ } if (strcmp(tag, input) == 0) { - data = (const cpl_framedata*)info; + data = (const cpl_framedata *)info; } else { data = _cpl_recipeconfig_find(info->iframes, input); @@ -1335,7 +1259,6 @@ } return data->min_count; - } @@ -1388,14 +1311,12 @@ */ cpl_size -cpl_recipeconfig_get_max_count(const cpl_recipeconfig* self, - const char* tag, const char* input) +cpl_recipeconfig_get_max_count(const cpl_recipeconfig *self, + const char *tag, + const char *input) { - - - - const cpl_frameinfo* info = NULL; - const cpl_framedata* data = NULL; + const cpl_frameinfo *info = NULL; + const cpl_framedata *data = NULL; if (self == NULL) { @@ -1418,7 +1339,7 @@ } if (strcmp(tag, input) == 0) { - data = (const cpl_framedata*)info; + data = (const cpl_framedata *)info; } else { data = _cpl_recipeconfig_find(info->iframes, input); @@ -1430,7 +1351,6 @@ } return data->max_count; - } @@ -1483,14 +1403,12 @@ */ int -cpl_recipeconfig_is_required(const cpl_recipeconfig* self, - const char* tag, const char* input) +cpl_recipeconfig_is_required(const cpl_recipeconfig *self, + const char *tag, + const char *input) { - - - - const cpl_frameinfo* info = NULL; - const cpl_framedata* data = NULL; + const cpl_frameinfo *info = NULL; + const cpl_framedata *data = NULL; if (self == NULL) { @@ -1511,7 +1429,7 @@ } if (strcmp(tag, input) == 0) { - data = (const cpl_framedata*)info; + data = (const cpl_framedata *)info; } else { data = _cpl_recipeconfig_find(info->iframes, input); @@ -1523,6 +1441,5 @@ } return (data->min_count > 0); - } /**@}*/ diff -Nru cpl-7.1.4+ds/cplui/cpl_recipeconfig.h cpl-7.2.2+ds/cplui/cpl_recipeconfig.h --- cpl-7.1.4+ds/cplui/cpl_recipeconfig.h 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplui/cpl_recipeconfig.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -41,45 +41,55 @@ * Create, copy and destroy operations */ -cpl_recipeconfig* cpl_recipeconfig_new(void) CPL_ATTR_ALLOC; -void cpl_recipeconfig_delete(cpl_recipeconfig* self); -void cpl_recipeconfig_clear(cpl_recipeconfig* self); +cpl_recipeconfig *cpl_recipeconfig_new(void) CPL_ATTR_ALLOC; +void cpl_recipeconfig_delete(cpl_recipeconfig *self); +void cpl_recipeconfig_clear(cpl_recipeconfig *self); /* * Non modifying operations */ -char** cpl_recipeconfig_get_tags(const cpl_recipeconfig* self); -char** cpl_recipeconfig_get_inputs(const cpl_recipeconfig* self, - const char* tag); -char** cpl_recipeconfig_get_outputs(const cpl_recipeconfig* self, - const char* tag); - -cpl_size cpl_recipeconfig_get_min_count(const cpl_recipeconfig* self, - const char* tag, const char* input); -cpl_size cpl_recipeconfig_get_max_count(const cpl_recipeconfig* self, - const char* tag, const char* input); -int cpl_recipeconfig_is_required(const cpl_recipeconfig* self, - const char* tag, const char* input); +char **cpl_recipeconfig_get_tags(const cpl_recipeconfig *self); +char ** +cpl_recipeconfig_get_inputs(const cpl_recipeconfig *self, const char *tag); +char ** +cpl_recipeconfig_get_outputs(const cpl_recipeconfig *self, const char *tag); + +cpl_size cpl_recipeconfig_get_min_count(const cpl_recipeconfig *self, + const char *tag, + const char *input); +cpl_size cpl_recipeconfig_get_max_count(const cpl_recipeconfig *self, + const char *tag, + const char *input); +int cpl_recipeconfig_is_required(const cpl_recipeconfig *self, + const char *tag, + const char *input); /* * Assignment operations */ -int cpl_recipeconfig_set_tag(cpl_recipeconfig* self, const char* tag, - cpl_size min_count, cpl_size max_count); -int cpl_recipeconfig_set_input(cpl_recipeconfig* self, const char* tag, - const char* input, cpl_size min_count, +int cpl_recipeconfig_set_tag(cpl_recipeconfig *self, + const char *tag, + cpl_size min_count, + cpl_size max_count); +int cpl_recipeconfig_set_input(cpl_recipeconfig *self, + const char *tag, + const char *input, + cpl_size min_count, cpl_size max_count); -int cpl_recipeconfig_set_output(cpl_recipeconfig* self, const char* tag, - const char* output); - -int cpl_recipeconfig_set_tags(cpl_recipeconfig* self, - const cpl_framedata* data); -int cpl_recipeconfig_set_inputs(cpl_recipeconfig* self, const char* tag, - const cpl_framedata* data); -int cpl_recipeconfig_set_outputs(cpl_recipeconfig* self, const char* tag, - const char** outputs); +int cpl_recipeconfig_set_output(cpl_recipeconfig *self, + const char *tag, + const char *output); + +int +cpl_recipeconfig_set_tags(cpl_recipeconfig *self, const cpl_framedata *data); +int cpl_recipeconfig_set_inputs(cpl_recipeconfig *self, + const char *tag, + const cpl_framedata *data); +int cpl_recipeconfig_set_outputs(cpl_recipeconfig *self, + const char *tag, + const char **outputs); CPL_END_DECLS diff -Nru cpl-7.1.4+ds/cplui/cpl_recipedefine.c cpl-7.2.2+ds/cplui/cpl_recipedefine.c --- cpl-7.1.4+ds/cplui/cpl_recipedefine.c 2021-05-07 12:09:11.000000000 +0000 +++ cpl-7.2.2+ds/cplui/cpl_recipedefine.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -18,7 +18,7 @@ */ #ifdef HAVE_CONFIG_H -# include +#include #endif #include "cpl_recipedefine.h" @@ -62,40 +62,48 @@ @note Should never be called directly, only via cpl_recipe_define(). */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_recipedefine_init(cpl_pluginlist * list, - unsigned long cplversion, - unsigned long version, - const char *name, const char *synopsis, - const char *description, const char *author, - const char *email, const char *copyright, - cpl_plugin_func create, - cpl_plugin_func execute, - cpl_plugin_func destroy) +cpl_error_code +cpl_recipedefine_init(cpl_pluginlist *list, + unsigned long cplversion, + unsigned long version, + const char *name, + const char *synopsis, + const char *description, + const char *author, + const char *email, + const char *copyright, + cpl_plugin_func create, + cpl_plugin_func execute, + cpl_plugin_func destroy) { - - cpl_recipe * recipe; - cpl_plugin * plugin; - const char * msgname = name ? name : ""; + cpl_recipe *recipe; + cpl_plugin *plugin; + const char *msgname = name ? name : ""; /* Verify that the compile-time and run-time versions of CPL match */ /* - this will work for run-time versions going back to CPL 3.0 */ /* - earlier versions will cause an exit with an unresolved symbol */ - const unsigned vruntime = CPL_VERSION(cpl_version_get_major(), - cpl_version_get_minor(), - cpl_version_get_micro()); + const unsigned vruntime = + CPL_VERSION(cpl_version_get_major(), cpl_version_get_minor(), + cpl_version_get_micro()); /* The version number of the first major version */ const unsigned vmruntime = CPL_VERSION(cpl_version_get_major(), 0, 0); if (vruntime < cplversion) { - cpl_msg_warning(cpl_func, "Run-time version %s of CPL is lower than " + cpl_msg_warning(cpl_func, + "Run-time version %s of CPL is lower than " "the version (%lX) used to compile %s", cpl_version_get_version(), cplversion, msgname); - } else if (vmruntime > cplversion) { - cpl_msg_warning(cpl_func, "Run-time version %s of CPL has a newer major " + } + else if (vmruntime > cplversion) { + cpl_msg_warning(cpl_func, + "Run-time version %s of CPL has a newer major " "version than the version (%lX) used to compile %s", cpl_version_get_version(), cplversion, msgname); - } else if (vruntime > cplversion) { - cpl_msg_info(cpl_func, "Run-time version %s of CPL is higher than " + } + else if (vruntime > cplversion) { + cpl_msg_info(cpl_func, + "Run-time version %s of CPL is higher than " "the version (%lX) used to compile %s", cpl_version_get_version(), cplversion, msgname); } @@ -103,33 +111,23 @@ recipe = cpl_calloc(1, sizeof(*recipe)); if (recipe == NULL) { return cpl_error_set_message_(CPL_ERROR_ILLEGAL_OUTPUT, - "Recipe allocation failed"); + "Recipe allocation failed"); } plugin = &recipe->interface; - if (cpl_plugin_init(plugin, - CPL_PLUGIN_API, - version, - CPL_PLUGIN_TYPE_RECIPE, - name, - synopsis, - description, - author, - email, - copyright, - create, - execute, - destroy)) { + if (cpl_plugin_init(plugin, CPL_PLUGIN_API, version, CPL_PLUGIN_TYPE_RECIPE, + name, synopsis, description, author, email, copyright, + create, execute, destroy)) { cpl_plugin_delete(plugin); return cpl_error_set_message_(cpl_error_get_code(), - "Plugin initialization failed"); + "Plugin initialization failed"); } if (cpl_pluginlist_append(list, plugin)) { cpl_plugin_delete(plugin); return cpl_error_set_message_(cpl_error_get_code(), - "Error adding plugin to list"); + "Error adding plugin to list"); } return CPL_ERROR_NONE; @@ -146,37 +144,37 @@ @note Should never be called directly, only via cpl_recipe_define(). */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_recipedefine_create(cpl_plugin * plugin) +cpl_error_code +cpl_recipedefine_create(cpl_plugin *plugin) { - cpl_recipe * recipe; + cpl_recipe *recipe; /* Return immediately if an error code is already set */ if (cpl_error_get_code() != CPL_ERROR_NONE) { return cpl_error_set_message_(cpl_error_get_code(), - "An error is already set"); + "An error is already set"); } if (plugin == NULL) { - return cpl_error_set_message_(CPL_ERROR_NULL_INPUT, - "Null plugin"); + return cpl_error_set_message_(CPL_ERROR_NULL_INPUT, "Null plugin"); } /* Verify plugin type */ if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) { return cpl_error_set_message_(CPL_ERROR_TYPE_MISMATCH, - "Plugin is not a recipe: %lu <=> %d", - cpl_plugin_get_type(plugin), - CPL_PLUGIN_TYPE_RECIPE); + "Plugin is not a recipe: %lu <=> %d", + cpl_plugin_get_type(plugin), + CPL_PLUGIN_TYPE_RECIPE); } /* Get the recipe */ recipe = (cpl_recipe *)plugin; - /* Create the parameters list in the cpl_recipe object */ + /* Create the parameters list in the cpl_recipe object */ recipe->parameters = cpl_parameterlist_new(); if (recipe->parameters == NULL) { return cpl_error_set_message_(CPL_ERROR_ILLEGAL_OUTPUT, - "Parameter list allocation failed"); + "Parameter list allocation failed"); } return CPL_ERROR_NONE; @@ -193,15 +191,17 @@ @note Should never be called directly, only via cpl_recipe_define(). */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_recipedefine_create_is_ok(cpl_errorstate prestate, - cpl_error_code fill_error) +cpl_error_code +cpl_recipedefine_create_is_ok(cpl_errorstate prestate, + cpl_error_code fill_error) { /* Propagate any error and set a CPL error if the filler failed without setting one */ return fill_error || !cpl_errorstate_is_equal(prestate) - ? cpl_error_set_message_(fill_error ? fill_error : cpl_error_get_code(), - "Parameter list fill failed") - : CPL_ERROR_NONE; + ? cpl_error_set_message_(fill_error ? fill_error + : cpl_error_get_code(), + "Parameter list fill failed") + : CPL_ERROR_NONE; } /*----------------------------------------------------------------------------*/ @@ -215,23 +215,23 @@ @note Should never be called directly, only via cpl_recipe_define(). */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_recipedefine_exec(cpl_plugin * plugin, - int (*function)(cpl_frameset *, - const cpl_parameterlist *)) +cpl_error_code +cpl_recipedefine_exec(cpl_plugin *plugin, + int (*function)(cpl_frameset *, + const cpl_parameterlist *)) { - cpl_recipe * recipe; + cpl_recipe *recipe; int recipe_status; cpl_errorstate initial_errorstate = cpl_errorstate_get(); /* Return immediately if an error code is already set */ if (cpl_error_get_code() != CPL_ERROR_NONE) { return cpl_error_set_message_(cpl_error_get_code(), - "An error is already set"); + "An error is already set"); } if (plugin == NULL) { - return cpl_error_set_message_(CPL_ERROR_NULL_INPUT, - "Null plugin"); + return cpl_error_set_message_(CPL_ERROR_NULL_INPUT, "Null plugin"); } /* Verify plugin type */ @@ -247,19 +247,19 @@ /* Verify parameter and frame lists */ if (recipe->parameters == NULL) { - return cpl_error_set_message_(CPL_ERROR_NULL_INPUT, - "Recipe invoked with NULL parameter list"); + return cpl_error_set_message_( + CPL_ERROR_NULL_INPUT, "Recipe invoked with NULL parameter list"); } if (recipe->frames == NULL) { return cpl_error_set_message_(CPL_ERROR_NULL_INPUT, - "Recipe invoked with NULL frame set"); + "Recipe invoked with NULL frame set"); } if (function == NULL) { /* Reaching this point indicates either an error in cpl_recipe_define() or that the caller is non-standard. */ return cpl_error_set_message_(CPL_ERROR_NULL_INPUT, - "Recipe invoked with NULL function"); + "Recipe invoked with NULL function"); } /* Invoke the recipe */ @@ -284,28 +284,28 @@ @note Should never be called directly, only via cpl_recipe_define(). */ /*----------------------------------------------------------------------------*/ -cpl_error_code cpl_recipedefine_destroy(cpl_plugin * plugin) +cpl_error_code +cpl_recipedefine_destroy(cpl_plugin *plugin) { - cpl_recipe * recipe; - - if (plugin == NULL) { - return cpl_error_set_message_(CPL_ERROR_NULL_INPUT, - "Null plugin"); - } - - /* Verify plugin type */ - if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) { + cpl_recipe *recipe; + + if (plugin == NULL) { + return cpl_error_set_message_(CPL_ERROR_NULL_INPUT, "Null plugin"); + } + + /* Verify plugin type */ + if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) { return cpl_error_set_message_(CPL_ERROR_TYPE_MISMATCH, "Plugin is not a recipe: %lu <=> %d", cpl_plugin_get_type(plugin), CPL_PLUGIN_TYPE_RECIPE); - } - - /* Get the recipe */ - recipe = (cpl_recipe *)plugin; + } + + /* Get the recipe */ + recipe = (cpl_recipe *)plugin; + + cpl_parameterlist_delete(recipe->parameters); /* May be NULL */ - cpl_parameterlist_delete(recipe->parameters); /* May be NULL */ - return CPL_ERROR_NONE; } diff -Nru cpl-7.1.4+ds/cplui/cpl_recipedefine.h cpl-7.2.2+ds/cplui/cpl_recipedefine.h --- cpl-7.1.4+ds/cplui/cpl_recipedefine.h 2021-05-07 12:09:09.000000000 +0000 +++ cpl-7.2.2+ds/cplui/cpl_recipedefine.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -48,23 +48,23 @@ */ /*----------------------------------------------------------------------------*/ -#define cpl_get_license(PACKAGE_NAME, YEAR) \ - "This file is part of the " PACKAGE_NAME "\n" \ - "Copyright (C) " YEAR " 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" \ +#define cpl_get_license(PACKAGE_NAME, YEAR) \ + "This file is part of the " PACKAGE_NAME "\n" \ + "Copyright (C) " YEAR " 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 02111-1307 USA" /*----------------------------------------------------------------------------*/ @@ -134,72 +134,77 @@ */ /*----------------------------------------------------------------------------*/ -#define cpl_recipe_define(RECIPE_NAME, RECIPE_VERSION, RECIPE_AUTHOR, \ - RECIPE_EMAIL, RECIPE_YEAR, \ - RECIPE_SYNOPSIS, RECIPE_DESCRIPTION) \ - \ - /* The prototypes of the recipe create, exec and destroy functions */ \ -static int CPL_CONCAT2X(RECIPE_NAME,create) (cpl_plugin * plugin); \ -static int CPL_CONCAT2X(RECIPE_NAME,exec) (cpl_plugin * plugin); \ -static int CPL_CONCAT2X(RECIPE_NAME,destroy)(cpl_plugin * plugin); \ - \ - /* The prototype of the function called by the recipe exec function */ \ -static int RECIPE_NAME(cpl_frameset *, const cpl_parameterlist *); \ - \ - /* The prototype of the parameterlist filler function */ \ -static cpl_error_code CPL_CONCAT2X(RECIPE_NAME,fill_parameterlist) \ - (cpl_parameterlist *); \ - \ -int cpl_plugin_get_info(cpl_pluginlist * list) \ -{ \ - /* Propagate error, if any. Return 1 on failure */ \ - return cpl_recipedefine_init(list, CPL_VERSION_CODE, \ - RECIPE_VERSION, \ - #RECIPE_NAME, \ - RECIPE_SYNOPSIS, \ - RECIPE_DESCRIPTION, \ - RECIPE_AUTHOR, \ - RECIPE_EMAIL, \ - cpl_get_license(PACKAGE_NAME, RECIPE_YEAR), \ - CPL_CONCAT2X(RECIPE_NAME,create), \ - CPL_CONCAT2X(RECIPE_NAME,exec), \ - CPL_CONCAT2X(RECIPE_NAME,destroy)) \ - ? ((void)cpl_error_set_where(cpl_func), 1) : 0; \ -} \ - \ - /* The definition of the recipe create function */ \ -static int CPL_CONCAT2X(RECIPE_NAME,create)(cpl_plugin * plugin) \ -{ \ - cpl_recipe * recipe = (cpl_recipe *)plugin; /* Needed for the fill */ \ - cpl_errorstate prestate = cpl_errorstate_get(); /* To check the fill */ \ - \ - /* Propagate error, if any */ \ - /* - Need two function calls to ensure plugin validity before the fill */ \ - return cpl_recipedefine_create(plugin) \ - || cpl_recipedefine_create_is_ok(prestate, \ - CPL_CONCAT2X(RECIPE_NAME,fill_parameterlist)(recipe->parameters)) \ - ? (int)cpl_error_set_where(cpl_func) : 0; \ -} \ - \ - /* The definition of the recipe exec function */ \ -static int CPL_CONCAT2X(RECIPE_NAME,exec)(cpl_plugin * plugin) \ -{ \ - /* Propagate error, if any */ \ - return cpl_recipedefine_exec(plugin, RECIPE_NAME) \ - ? (int)cpl_error_set_where(cpl_func) : 0; \ -} \ - \ - /* The definition of the recipe destroy function */ \ -static int CPL_CONCAT2X(RECIPE_NAME,destroy)(cpl_plugin * plugin) \ -{ \ - /* Propagate error, if any */ \ - return cpl_recipedefine_destroy(plugin) \ - ? (int)cpl_error_set_where(cpl_func) : 0; \ -} \ - \ - /* This dummy declaration requires the macro to be invoked as if it was \ - a kind of function declaration, with a terminating ; */ \ -extern int cpl_plugin_end +#define cpl_recipe_define(RECIPE_NAME, RECIPE_VERSION, RECIPE_AUTHOR, \ + RECIPE_EMAIL, RECIPE_YEAR, RECIPE_SYNOPSIS, \ + RECIPE_DESCRIPTION) \ + \ + /* The prototypes of the recipe create, exec and destroy functions */ \ + static int CPL_CONCAT2X(RECIPE_NAME, create)(cpl_plugin * plugin); \ + static int CPL_CONCAT2X(RECIPE_NAME, exec)(cpl_plugin * plugin); \ + static int CPL_CONCAT2X(RECIPE_NAME, destroy)(cpl_plugin * plugin); \ + \ + /* The prototype of the function called by the recipe exec function */ \ + static int RECIPE_NAME(cpl_frameset *, const cpl_parameterlist *); \ + \ + /* The prototype of the parameterlist filler function */ \ + static cpl_error_code CPL_CONCAT2X(RECIPE_NAME, fill_parameterlist)( \ + cpl_parameterlist *); \ + \ + int cpl_plugin_get_info(cpl_pluginlist *list) \ + { \ + /* Propagate error, if any. Return 1 on failure */ \ + return cpl_recipedefine_init(list, CPL_VERSION_CODE, RECIPE_VERSION, \ + #RECIPE_NAME, RECIPE_SYNOPSIS, \ + RECIPE_DESCRIPTION, RECIPE_AUTHOR, \ + RECIPE_EMAIL, \ + cpl_get_license(PACKAGE_NAME, \ + RECIPE_YEAR), \ + CPL_CONCAT2X(RECIPE_NAME, create), \ + CPL_CONCAT2X(RECIPE_NAME, exec), \ + CPL_CONCAT2X(RECIPE_NAME, destroy)) \ + ? ((void)cpl_error_set_where(cpl_func), 1) \ + : 0; \ + } \ + \ + /* The definition of the recipe create function */ \ + static int CPL_CONCAT2X(RECIPE_NAME, create)(cpl_plugin * plugin) \ + { \ + cpl_recipe *recipe = (cpl_recipe *)plugin; /* Needed for the fill */ \ + cpl_errorstate prestate = \ + cpl_errorstate_get(); /* To check the fill */ \ + \ + /* Propagate error, if any */ \ + /* - Need two function calls to ensure plugin validity before the fill */ \ + return cpl_recipedefine_create(plugin) || \ + cpl_recipedefine_create_is_ok( \ + prestate, \ + CPL_CONCAT2X(RECIPE_NAME, fill_parameterlist)( \ + recipe->parameters)) \ + ? (int)cpl_error_set_where(cpl_func) \ + : 0; \ + } \ + \ + /* The definition of the recipe exec function */ \ + static int CPL_CONCAT2X(RECIPE_NAME, exec)(cpl_plugin * plugin) \ + { \ + /* Propagate error, if any */ \ + return cpl_recipedefine_exec(plugin, RECIPE_NAME) \ + ? (int)cpl_error_set_where(cpl_func) \ + : 0; \ + } \ + \ + /* The definition of the recipe destroy function */ \ + static int CPL_CONCAT2X(RECIPE_NAME, destroy)(cpl_plugin * plugin) \ + { \ + /* Propagate error, if any */ \ + return cpl_recipedefine_destroy(plugin) \ + ? (int)cpl_error_set_where(cpl_func) \ + : 0; \ + } \ + \ + /* This dummy declaration requires the macro to be invoked as if it was \ + a kind of function declaration, with a terminating ; */ \ + extern int cpl_plugin_end /*----------------------------------------------------------------------------*/ @@ -221,78 +226,89 @@ */ /*----------------------------------------------------------------------------*/ -#define CPL_RECIPE_DEFINE(RECIPE_NAME, RECIPE_VERSION, RECIPE_FILL_PARAMS, \ - RECIPE_AUTHOR, RECIPE_AUTHOR_EMAIL, RECIPE_YEAR, \ - RECIPE_SYNOPSIS, RECIPE_DESCRIPTION) \ - \ - /* The prototypes of the recipe create, exec and destroy functions */ \ -static int CPL_CONCAT2X(RECIPE_NAME,create) (cpl_plugin * plugin); \ -static int CPL_CONCAT2X(RECIPE_NAME,exec) (cpl_plugin * plugin); \ -static int CPL_CONCAT2X(RECIPE_NAME,destroy)(cpl_plugin * plugin); \ - \ - /* The prototype of the function called by the recipe exec function */ \ -static int RECIPE_NAME(cpl_frameset *, const cpl_parameterlist *); \ - \ -int cpl_plugin_get_info(cpl_pluginlist * list) \ -{ \ - /* Propagate error, if any. Return 1 on failure */ \ - return cpl_recipedefine_init(list, CPL_VERSION_CODE, \ - RECIPE_VERSION, \ - #RECIPE_NAME, \ - RECIPE_SYNOPSIS, \ - RECIPE_DESCRIPTION, \ - RECIPE_AUTHOR, \ - RECIPE_AUTHOR_EMAIL, \ - cpl_get_license(PACKAGE_NAME, RECIPE_YEAR), \ - CPL_CONCAT2X(RECIPE_NAME,create), \ - CPL_CONCAT2X(RECIPE_NAME,exec), \ - CPL_CONCAT2X(RECIPE_NAME,destroy)) \ - ? ((void)cpl_error_set_where(cpl_func), 1) : 0; \ -} \ - \ - /* The definition of the recipe create function */ \ -static int CPL_CONCAT2X(RECIPE_NAME,create)(cpl_plugin * plugin) \ -{ \ - cpl_recipe * recipe = (cpl_recipe *)plugin; /* Needed for the fill */ \ - cpl_errorstate prestate = cpl_errorstate_get(); /* To check the fill */ \ - \ - /* Propagate error, if any */ \ - /* - Need two function calls to ensure plugin validity before the fill */ \ - return cpl_recipedefine_create(plugin) \ - || cpl_recipedefine_create_is_ok(prestate, (RECIPE_FILL_PARAMS)) \ - ? (int)cpl_error_set_where(cpl_func) : 0; \ -} \ - \ - /* The definition of the recipe exec function */ \ -static int CPL_CONCAT2X(RECIPE_NAME,exec)(cpl_plugin * plugin) \ -{ \ - /* Propagate error, if any */ \ - return cpl_recipedefine_exec(plugin, RECIPE_NAME) \ - ? (int)cpl_error_set_where(cpl_func) : 0; \ -} \ - \ - /* The definition of the recipe destroy function */ \ -static int CPL_CONCAT2X(RECIPE_NAME,destroy)(cpl_plugin * plugin) \ -{ \ - /* Propagate error, if any */ \ - return cpl_recipedefine_destroy(plugin) \ - ? (int)cpl_error_set_where(cpl_func) : 0; \ -} \ - \ - /* This dummy declaration requires the macro to be invoked as if it was \ - a kind of function declaration, with a terminating ; */ \ -extern int cpl_plugin_end +#define CPL_RECIPE_DEFINE(RECIPE_NAME, RECIPE_VERSION, RECIPE_FILL_PARAMS, \ + RECIPE_AUTHOR, RECIPE_AUTHOR_EMAIL, RECIPE_YEAR, \ + RECIPE_SYNOPSIS, RECIPE_DESCRIPTION) \ + \ + /* The prototypes of the recipe create, exec and destroy functions */ \ + static int CPL_CONCAT2X(RECIPE_NAME, create)(cpl_plugin * plugin); \ + static int CPL_CONCAT2X(RECIPE_NAME, exec)(cpl_plugin * plugin); \ + static int CPL_CONCAT2X(RECIPE_NAME, destroy)(cpl_plugin * plugin); \ + \ + /* The prototype of the function called by the recipe exec function */ \ + static int RECIPE_NAME(cpl_frameset *, const cpl_parameterlist *); \ + \ + int cpl_plugin_get_info(cpl_pluginlist *list) \ + { \ + /* Propagate error, if any. Return 1 on failure */ \ + return cpl_recipedefine_init(list, CPL_VERSION_CODE, RECIPE_VERSION, \ + #RECIPE_NAME, RECIPE_SYNOPSIS, \ + RECIPE_DESCRIPTION, RECIPE_AUTHOR, \ + RECIPE_AUTHOR_EMAIL, \ + cpl_get_license(PACKAGE_NAME, \ + RECIPE_YEAR), \ + CPL_CONCAT2X(RECIPE_NAME, create), \ + CPL_CONCAT2X(RECIPE_NAME, exec), \ + CPL_CONCAT2X(RECIPE_NAME, destroy)) \ + ? ((void)cpl_error_set_where(cpl_func), 1) \ + : 0; \ + } \ + \ + /* The definition of the recipe create function */ \ + static int CPL_CONCAT2X(RECIPE_NAME, create)(cpl_plugin * plugin) \ + { \ + cpl_recipe *recipe = (cpl_recipe *)plugin; /* Needed for the fill */ \ + cpl_errorstate prestate = \ + cpl_errorstate_get(); /* To check the fill */ \ + \ + /* Propagate error, if any */ \ + /* - Need two function calls to ensure plugin validity before the fill */ \ + return cpl_recipedefine_create(plugin) || \ + cpl_recipedefine_create_is_ok(prestate, \ + (RECIPE_FILL_PARAMS)) \ + ? (int)cpl_error_set_where(cpl_func) \ + : 0; \ + } \ + \ + /* The definition of the recipe exec function */ \ + static int CPL_CONCAT2X(RECIPE_NAME, exec)(cpl_plugin * plugin) \ + { \ + /* Propagate error, if any */ \ + return cpl_recipedefine_exec(plugin, RECIPE_NAME) \ + ? (int)cpl_error_set_where(cpl_func) \ + : 0; \ + } \ + \ + /* The definition of the recipe destroy function */ \ + static int CPL_CONCAT2X(RECIPE_NAME, destroy)(cpl_plugin * plugin) \ + { \ + /* Propagate error, if any */ \ + return cpl_recipedefine_destroy(plugin) \ + ? (int)cpl_error_set_where(cpl_func) \ + : 0; \ + } \ + \ + /* This dummy declaration requires the macro to be invoked as if it was \ + a kind of function declaration, with a terminating ; */ \ + extern int cpl_plugin_end /*----------------------------------------------------------------------------- Function prototypes -----------------------------------------------------------------------------*/ -cpl_error_code cpl_recipedefine_init(cpl_pluginlist *, unsigned long, - unsigned long, const char *, const char *, - const char *, const char *, const char *, - const char *, cpl_plugin_func, - cpl_plugin_func, cpl_plugin_func) +cpl_error_code cpl_recipedefine_init(cpl_pluginlist *, + unsigned long, + unsigned long, + const char *, + const char *, + const char *, + const char *, + const char *, + const char *, + cpl_plugin_func, + cpl_plugin_func, + cpl_plugin_func) #ifdef CPL_HAVE_ATTR_NONNULL __attribute__((nonnull(9, 10, 11, 12))) #endif @@ -302,9 +318,9 @@ cpl_error_code cpl_recipedefine_create_is_ok(cpl_errorstate, cpl_error_code); -cpl_error_code cpl_recipedefine_exec(cpl_plugin *, - int (*)(cpl_frameset *, - const cpl_parameterlist *)); +cpl_error_code +cpl_recipedefine_exec(cpl_plugin *, + int (*)(cpl_frameset *, const cpl_parameterlist *)); cpl_error_code cpl_recipedefine_destroy(cpl_plugin *); diff -Nru cpl-7.1.4+ds/cplui/cpl_recipe.h cpl-7.2.2+ds/cplui/cpl_recipe.h --- cpl-7.1.4+ds/cplui/cpl_recipe.h 2021-05-07 12:09:09.000000000 +0000 +++ cpl-7.2.2+ds/cplui/cpl_recipe.h 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -65,8 +65,8 @@ * The type representation of the recipe plugin interface. */ -struct _cpl_recipe_ { - +struct _cpl_recipe_ +{ /** * @brief * Generic plugin interface @@ -74,7 +74,7 @@ * See the @ref cpl_plugin documentation for a detailed description. */ - cpl_plugin interface; /* Must be the first member! */ + cpl_plugin interface; /* Must be the first member! */ /** * @brief @@ -107,18 +107,16 @@ */ cpl_frameset *frames; - }; typedef struct _cpl_recipe2_ cpl_recipe2; -struct _cpl_recipe2_ { - +struct _cpl_recipe2_ +{ cpl_recipe base; cpl_recipeconfig *config; - }; /**@}*/ diff -Nru cpl-7.1.4+ds/cplui/Makefile.am cpl-7.2.2+ds/cplui/Makefile.am --- cpl-7.1.4+ds/cplui/Makefile.am 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplui/Makefile.am 2022-04-29 14:56:02.000000000 +0000 @@ -1,7 +1,7 @@ ## Process this file with automake to produce Makefile.in ## This file is part of the ESO Common Pipeline Library -## Copyright (C) 2001-2017 European Southern Observatory +## Copyright (C) 2001-2022 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 diff -Nru cpl-7.1.4+ds/cplui/Makefile.in cpl-7.2.2+ds/cplui/Makefile.in --- cpl-7.1.4+ds/cplui/Makefile.in 2021-05-07 12:10:10.000000000 +0000 +++ cpl-7.2.2+ds/cplui/Makefile.in 2022-04-29 14:56:28.000000000 +0000 @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.15.1 from Makefile.am. +# Makefile.in generated by automake 1.16.3 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2017 Free Software Foundation, Inc. +# Copyright (C) 1994-2020 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -161,7 +161,14 @@ am__v_at_1 = DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) depcomp = $(SHELL) $(top_srcdir)/admin/depcomp -am__depfiles_maybe = depfiles +am__maybe_remake_depfiles = depfiles +am__depfiles_remade = ./$(DEPDIR)/cpl_frame.Plo \ + ./$(DEPDIR)/cpl_framedata.Plo ./$(DEPDIR)/cpl_frameset.Plo \ + ./$(DEPDIR)/cpl_frameset_io.Plo ./$(DEPDIR)/cpl_parameter.Plo \ + ./$(DEPDIR)/cpl_parameterlist.Plo ./$(DEPDIR)/cpl_plugin.Plo \ + ./$(DEPDIR)/cpl_pluginlist.Plo \ + ./$(DEPDIR)/cpl_recipeconfig.Plo \ + ./$(DEPDIR)/cpl_recipedefine.Plo am__mv = mv -f COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) @@ -204,7 +211,7 @@ $(RECURSIVE_CLEAN_TARGETS) \ $(am__extra_recursive_targets) AM_RECURSIVE_TARGETS = $(am__recursive_targets:-recursive=) TAGS CTAGS \ - distdir + distdir distdir-am 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 @@ -270,6 +277,7 @@ CPLCORE_INCLUDES = @CPLCORE_INCLUDES@ CPLDFS_INCLUDES = @CPLDFS_INCLUDES@ CPLDRS_INCLUDES = @CPLDRS_INCLUDES@ +CPLJAVA_INCLUDES = @CPLJAVA_INCLUDES@ CPLUI_INCLUDES = @CPLUI_INCLUDES@ CPL_BINARY_AGE = @CPL_BINARY_AGE@ CPL_BINARY_VERSION = @CPL_BINARY_VERSION@ @@ -330,6 +338,7 @@ LIBCPLCORE = @LIBCPLCORE@ LIBCPLDFS = @LIBCPLDFS@ LIBCPLDRS = @LIBCPLDRS@ +LIBCPLGASGANO = @LIBCPLGASGANO@ LIBCPLUI = @LIBCPLUI@ LIBFFTW = @LIBFFTW@ LIBFFTWF = @LIBFFTWF@ @@ -436,6 +445,7 @@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ @@ -489,8 +499,8 @@ *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);; \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ esac; $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) @@ -546,16 +556,22 @@ distclean-compile: -rm -f *.tab.c -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_frame.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_framedata.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_frameset.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_frameset_io.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_parameter.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_parameterlist.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_plugin.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_pluginlist.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_recipeconfig.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_recipedefine.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_frame.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_framedata.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_frameset.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_frameset_io.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_parameter.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_parameterlist.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_plugin.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_pluginlist.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_recipeconfig.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_recipedefine.Plo@am__quote@ # am--include-marker + +$(am__depfiles_remade): + @$(MKDIR_P) $(@D) + @echo '# dummy' >$@-t && $(am__mv) $@-t $@ + +am--depfiles: $(am__depfiles_remade) .c.o: @am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @@ -704,7 +720,10 @@ distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags -distdir: $(DISTFILES) +distdir: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) distdir-am + +distdir-am: $(DISTFILES) @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ list='$(DISTFILES)'; \ @@ -805,7 +824,16 @@ mostlyclean-am distclean: distclean-recursive - -rm -rf ./$(DEPDIR) + -rm -f ./$(DEPDIR)/cpl_frame.Plo + -rm -f ./$(DEPDIR)/cpl_framedata.Plo + -rm -f ./$(DEPDIR)/cpl_frameset.Plo + -rm -f ./$(DEPDIR)/cpl_frameset_io.Plo + -rm -f ./$(DEPDIR)/cpl_parameter.Plo + -rm -f ./$(DEPDIR)/cpl_parameterlist.Plo + -rm -f ./$(DEPDIR)/cpl_plugin.Plo + -rm -f ./$(DEPDIR)/cpl_pluginlist.Plo + -rm -f ./$(DEPDIR)/cpl_recipeconfig.Plo + -rm -f ./$(DEPDIR)/cpl_recipedefine.Plo -rm -f Makefile distclean-am: clean-am distclean-compile distclean-generic \ distclean-tags @@ -851,7 +879,16 @@ installcheck-am: maintainer-clean: maintainer-clean-recursive - -rm -rf ./$(DEPDIR) + -rm -f ./$(DEPDIR)/cpl_frame.Plo + -rm -f ./$(DEPDIR)/cpl_framedata.Plo + -rm -f ./$(DEPDIR)/cpl_frameset.Plo + -rm -f ./$(DEPDIR)/cpl_frameset_io.Plo + -rm -f ./$(DEPDIR)/cpl_parameter.Plo + -rm -f ./$(DEPDIR)/cpl_parameterlist.Plo + -rm -f ./$(DEPDIR)/cpl_plugin.Plo + -rm -f ./$(DEPDIR)/cpl_pluginlist.Plo + -rm -f ./$(DEPDIR)/cpl_recipeconfig.Plo + -rm -f ./$(DEPDIR)/cpl_recipedefine.Plo -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic @@ -872,21 +909,22 @@ .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-libLTLIBRARIES \ - clean-libtool 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-includeHEADERS install-info \ - install-info-am install-libLTLIBRARIES 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 \ - uninstall-includeHEADERS uninstall-libLTLIBRARIES +.PHONY: $(am__recursive_targets) CTAGS GTAGS TAGS all all-am \ + am--depfiles check check-am clean clean-generic \ + clean-libLTLIBRARIES clean-libtool 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-includeHEADERS install-info install-info-am \ + install-libLTLIBRARIES 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 uninstall-includeHEADERS \ + uninstall-libLTLIBRARIES .PRECIOUS: Makefile diff -Nru cpl-7.1.4+ds/cplui/tests/cpl_framedata-test.c cpl-7.2.2+ds/cplui/tests/cpl_framedata-test.c --- cpl-7.1.4+ds/cplui/tests/cpl_framedata-test.c 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplui/tests/cpl_framedata-test.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -24,17 +24,17 @@ #include "cpl_test.h" #include "cpl_framedata.h" -int main(void) +int +main(void) { - - const char* tags[] = {"One", "Two"}; - const char* tag = NULL; + const char *tags[] = { "One", "Two" }; + const char *tag = NULL; cpl_error_code status; - int count; + int count; - cpl_framedata* framedata = NULL; - cpl_framedata* _framedata = NULL; + cpl_framedata *framedata = NULL; + cpl_framedata *_framedata = NULL; cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); @@ -77,7 +77,7 @@ * identical. */ - framedata = cpl_framedata_create(tags[1], 5, -1); + framedata = cpl_framedata_create(tags[1], 5, -1); cpl_test_nonnull(framedata); _framedata = cpl_framedata_duplicate(framedata); @@ -207,5 +207,4 @@ */ return cpl_test_end(0); - } diff -Nru cpl-7.1.4+ds/cplui/tests/cpl_frameset_io-test.c cpl-7.2.2+ds/cplui/tests/cpl_frameset_io-test.c --- cpl-7.1.4+ds/cplui/tests/cpl_frameset_io-test.c 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplui/tests/cpl_frameset_io-test.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -39,9 +39,9 @@ #define IMAGESZ 512 #endif -int main(void) +int +main(void) { - const cxchar *names[] = { "cpl_frameset-io_test1.fits", "cpl_frameset-io_test2.fits", @@ -73,7 +73,7 @@ cxlong i; cxlong has_primary; cpl_frameset *frameset; - cpl_image *img1; + cpl_image *img1; cpl_imagelist *imlist; cpl_error_code error; @@ -99,27 +99,26 @@ */ imlist = cpl_imagelist_load_frameset(frameset, CPL_TYPE_FLOAT, 0, -1); - + cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); cpl_test_null(imlist); /* * Test 2A: Test error-handling of cpl_imagelist_load_frameset() */ - + imlist = cpl_imagelist_load_frameset(NULL, CPL_TYPE_FLOAT, 0, -1); cpl_test_error(CPL_ERROR_NULL_INPUT); cpl_test_null(imlist); - /* Add frames to the frame set created in the previous test + /* Add frames to the frame set created in the previous test and verify the data.*/ - /* The corresponding files do not exist yet */ + /* The corresponding files do not exist yet */ for (i = 0; (cxsize)i < CX_N_ELEMENTS(names); i++) { - cpl_frame *_frame = cpl_frame_new(); remove(names[i]); @@ -137,7 +136,6 @@ error = cpl_frameset_insert(frameset, _frame); cpl_test_eq_error(error, CPL_ERROR_NONE); - } cpl_test_zero(cpl_frameset_is_empty(frameset)); @@ -149,7 +147,7 @@ * Test 2B: Test error-handling of cpl_imagelist_load_frameset() with missing files. */ - + imlist = cpl_imagelist_load_frameset(frameset, CPL_TYPE_FLOAT, 0, -1); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); @@ -157,7 +155,7 @@ img1 = cpl_image_fill_test_create(IMAGESZ, IMAGESZ); cpl_test_nonnull(img1); - + /* * Test 2BB: Test error-handling of cpl_imagelist_load_frameset() on frame with a single image in primary HDU and more than @@ -165,8 +163,7 @@ */ /* Create file, with image */ - error = cpl_image_save(img1, names[0], CPL_TYPE_FLOAT, NULL, - CPL_IO_CREATE); + error = cpl_image_save(img1, names[0], CPL_TYPE_FLOAT, NULL, CPL_IO_CREATE); cpl_test_eq_error(error, CPL_ERROR_NONE); imlist = cpl_imagelist_new(); error = cpl_imagelist_set(imlist, cpl_image_duplicate(img1), 0); @@ -175,15 +172,14 @@ cpl_test_eq_error(error, CPL_ERROR_NONE); error = cpl_imagelist_save(imlist, names[0], CPL_TYPE_FLOAT, NULL, - CPL_IO_EXTEND); + CPL_IO_EXTEND); cpl_test_eq_error(error, CPL_ERROR_NONE); cpl_imagelist_delete(imlist); - + /* Replicate the file */ for (i = 1; (cxsize)i < CX_N_ELEMENTS(names); i++) { - - char * cmd = cpl_sprintf("cp %s %s", names[0], names[i]); + char *cmd = cpl_sprintf("cp %s %s", names[0], names[i]); cpl_test_zero(system(cmd)); cpl_free(cmd); @@ -199,7 +195,7 @@ * Create images to insert into frameset * First case: primary HDU image is NULL */ - + for (has_primary = 0; has_primary <= 1; has_primary++) { const cxsize isave = 1; cxlong ii; @@ -207,14 +203,15 @@ /* The fits file contains three or four images */ const cxlong nimg = 3 + has_primary; cxlong iplane; - - cpl_msg_info(cpl_func, "Testing with %u frames and %d X %d-images, " - "has_primary=%d", (unsigned)CX_N_ELEMENTS(names), IMAGESZ, - IMAGESZ, (int)has_primary); + + cpl_msg_info(cpl_func, + "Testing with %u frames and %d X %d-images, " + "has_primary=%d", + (unsigned)CX_N_ELEMENTS(names), IMAGESZ, IMAGESZ, + (int)has_primary); /* Replicate the file */ for (ii = 0; (cxsize)ii < isave; ii++) { - /* Create file, either with or without image */ error = cpl_image_save(has_primary ? img1 : NULL, names[ii], CPL_TYPE_FLOAT, NULL, CPL_IO_CREATE); @@ -223,18 +220,15 @@ /* Append some extensions */ for (i = has_primary; i < nimg; i++) { - /* Append an extension */ - error = cpl_image_save(img1, names[ii], CPL_TYPE_FLOAT, - NULL, CPL_IO_EXTEND); + error = cpl_image_save(img1, names[ii], CPL_TYPE_FLOAT, NULL, + CPL_IO_EXTEND); cpl_test_eq_error(error, CPL_ERROR_NONE); - } } for (i = isave; (cxsize)i < CX_N_ELEMENTS(names); i++) { - - char * cmd = cpl_sprintf("cp %s %s", names[0], names[i]); - + char *cmd = cpl_sprintf("cp %s %s", names[0], names[i]); + cpl_test_zero(system(cmd)); cpl_free(cmd); } @@ -248,7 +242,7 @@ * Test 2D: Test error-handling of cpl_imagelist_load_frameset() with invalid type. */ - + imlist = cpl_imagelist_load_frameset(frameset, CPL_TYPE_INVALID, 0, -1); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); @@ -258,7 +252,7 @@ * Test 2E: Test error-handling of cpl_imagelist_load_frameset() with invalid plane number. */ - + imlist = cpl_imagelist_load_frameset(frameset, CPL_TYPE_FLOAT, 2, -1); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); @@ -268,8 +262,9 @@ * Test 2F: Test error-handling of cpl_imagelist_load_frameset() with invalid extension number. */ - - imlist = cpl_imagelist_load_frameset(frameset, CPL_TYPE_FLOAT, 0, 1+nimg); + + imlist = + cpl_imagelist_load_frameset(frameset, CPL_TYPE_FLOAT, 0, 1 + nimg); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); cpl_test_null(imlist); @@ -281,12 +276,14 @@ for (iplane = 0; iplane <= 1; iplane++) { for (i = 0; i < nimg; i++) { - imlist = cpl_imagelist_load_frameset(frameset, CPL_TYPE_FLOAT, - iplane, i+1-has_primary); - + imlist = + cpl_imagelist_load_frameset(frameset, CPL_TYPE_FLOAT, + iplane, i + 1 - has_primary); + cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(imlist); - cpl_test_eq(cpl_imagelist_get_size(imlist), cpl_frameset_get_size(frameset)); + cpl_test_eq(cpl_imagelist_get_size(imlist), + cpl_frameset_get_size(frameset)); cpl_imagelist_delete(imlist); } } @@ -297,11 +294,13 @@ */ for (iplane = 0; iplane <= 1; iplane++) { - imlist = cpl_imagelist_load_frameset(frameset, CPL_TYPE_FLOAT, iplane, -1); - + imlist = cpl_imagelist_load_frameset(frameset, CPL_TYPE_FLOAT, + iplane, -1); + cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(imlist); - cpl_test_eq(cpl_imagelist_get_size(imlist), nimg * cpl_frameset_get_size(frameset)); + cpl_test_eq(cpl_imagelist_get_size(imlist), + nimg * cpl_frameset_get_size(frameset)); cpl_imagelist_delete(imlist); } @@ -315,6 +314,6 @@ cpl_test_zero(remove(names[i])); } } - + return cpl_test_end(0); } diff -Nru cpl-7.1.4+ds/cplui/tests/cpl_frameset-test.c cpl-7.2.2+ds/cplui/tests/cpl_frameset-test.c --- cpl-7.1.4+ds/cplui/tests/cpl_frameset-test.c 2021-05-07 12:09:10.000000000 +0000 +++ cpl-7.2.2+ds/cplui/tests/cpl_frameset-test.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -31,94 +31,69 @@ static int nframe = 0; static int -frame_equal(const cpl_frame * frame1, const cpl_frame * frame2) +frame_equal(const cpl_frame *frame1, const cpl_frame *frame2) { - - if (frame1 == NULL) return -1; - if (frame2 == NULL) return -1; + if (frame1 == NULL) + return -1; + if (frame2 == NULL) + return -1; return 1; } static int -frame_differ(const cpl_frame * frame1, const cpl_frame * frame2) +frame_differ(const cpl_frame *frame1, const cpl_frame *frame2) { - - if (frame1 == NULL) return -1; - if (frame2 == NULL) return -1; + if (frame1 == NULL) + return -1; + if (frame2 == NULL) + return -1; return frame1 == frame2 ? 1 : 0; } static int -frame_oddeven(const cpl_frame * frame1, const cpl_frame * frame2) +frame_oddeven(const cpl_frame *frame1, const cpl_frame *frame2) { + if (frame1 == NULL) + return -1; + if (frame2 == NULL) + return -1; - if (frame1 == NULL) return -1; - if (frame2 == NULL) return -1; - - if (frame1 == frame2) return 1; + if (frame1 == frame2) + return 1; return (nframe++ & 1); } -int main(void) +int +main(void) { - - const char *names[] = { - "flat1.fits", - "flat2.fits", - "flat3.fits", - "bias1.fits", - "bias2.fits", - "bias3.fits", - "mbias.fits", - "mflat.fits", - "science.fits", - "product.fits" - }; + const char *names[] = { "flat1.fits", "flat2.fits", "flat3.fits", + "bias1.fits", "bias2.fits", "bias3.fits", + "mbias.fits", "mflat.fits", "science.fits", + "product.fits" }; const char *tags[] = { - "FLAT", - "FLAT", - "FLAT", - "BIAS", - "BIAS", - "BIAS", - "MASTER_BIAS", - "MASTER_FLAT", - "SCIENCE", - "SCIENCE_CALIBRATED" + "FLAT", "FLAT", "FLAT", "BIAS", "BIAS", + "BIAS", "MASTER_BIAS", "MASTER_FLAT", "SCIENCE", "SCIENCE_CALIBRATED" }; cpl_frame_group groups[] = { - CPL_FRAME_GROUP_RAW, - CPL_FRAME_GROUP_RAW, - CPL_FRAME_GROUP_RAW, - CPL_FRAME_GROUP_RAW, - CPL_FRAME_GROUP_RAW, - CPL_FRAME_GROUP_RAW, - CPL_FRAME_GROUP_CALIB, - CPL_FRAME_GROUP_CALIB, - CPL_FRAME_GROUP_RAW, + CPL_FRAME_GROUP_RAW, CPL_FRAME_GROUP_RAW, CPL_FRAME_GROUP_RAW, + CPL_FRAME_GROUP_RAW, CPL_FRAME_GROUP_RAW, CPL_FRAME_GROUP_RAW, + CPL_FRAME_GROUP_CALIB, CPL_FRAME_GROUP_CALIB, CPL_FRAME_GROUP_RAW, CPL_FRAME_GROUP_PRODUCT }; - cpl_frame_level levels[] = { - CPL_FRAME_LEVEL_NONE, - CPL_FRAME_LEVEL_NONE, - CPL_FRAME_LEVEL_NONE, - CPL_FRAME_LEVEL_NONE, - CPL_FRAME_LEVEL_NONE, - CPL_FRAME_LEVEL_NONE, - CPL_FRAME_LEVEL_NONE, - CPL_FRAME_LEVEL_NONE, - CPL_FRAME_LEVEL_NONE, - CPL_FRAME_LEVEL_FINAL - }; + cpl_frame_level levels[] = { CPL_FRAME_LEVEL_NONE, CPL_FRAME_LEVEL_NONE, + CPL_FRAME_LEVEL_NONE, CPL_FRAME_LEVEL_NONE, + CPL_FRAME_LEVEL_NONE, CPL_FRAME_LEVEL_NONE, + CPL_FRAME_LEVEL_NONE, CPL_FRAME_LEVEL_NONE, + CPL_FRAME_LEVEL_NONE, CPL_FRAME_LEVEL_FINAL }; long i; @@ -129,7 +104,7 @@ cpl_frameset *frameset; cpl_frameset *_frameset; - cpl_frameset_iterator *it = NULL; + cpl_frameset_iterator *it = NULL; cpl_frameset_iterator *_it = NULL; cpl_frameset *allframes; @@ -168,13 +143,13 @@ } cpl_test_zero(cpl_frameset_is_empty(frameset)); - cpl_test_eq(cpl_frameset_get_size(frameset), CX_N_ELEMENTS(names)); - cpl_test_eq(cpl_frameset_count_tags(frameset, tags[0]), 3); - cpl_test_eq(cpl_frameset_count_tags(frameset, tags[3]), 3); - cpl_test_eq(cpl_frameset_count_tags(frameset, tags[6]), 1); - cpl_test_eq(cpl_frameset_count_tags(frameset, tags[7]), 1); - cpl_test_eq(cpl_frameset_count_tags(frameset, tags[8]), 1); - cpl_test_eq(cpl_frameset_count_tags(frameset, tags[9]), 1); + cpl_test_eq(cpl_frameset_get_size(frameset), CX_N_ELEMENTS(names)); + cpl_test_eq(cpl_frameset_count_tags(frameset, tags[0]), 3); + cpl_test_eq(cpl_frameset_count_tags(frameset, tags[3]), 3); + cpl_test_eq(cpl_frameset_count_tags(frameset, tags[6]), 1); + cpl_test_eq(cpl_frameset_count_tags(frameset, tags[7]), 1); + cpl_test_eq(cpl_frameset_count_tags(frameset, tags[8]), 1); + cpl_test_eq(cpl_frameset_count_tags(frameset, tags[9]), 1); /* @@ -183,7 +158,7 @@ out = fopen(filename1, "w"); cpl_frameset_dump(frameset, out); - fclose (out); + fclose(out); allframes = cpl_frameset_duplicate(frameset); @@ -261,8 +236,8 @@ * structure and its contents. */ - cpl_test_eq(cpl_frameset_erase(frameset, tags[0]), 3); - cpl_test_eq(cpl_frameset_get_size(frameset), (CX_N_ELEMENTS(tags) - 3)); + cpl_test_eq(cpl_frameset_erase(frameset, tags[0]), 3); + cpl_test_eq(cpl_frameset_get_size(frameset), (CX_N_ELEMENTS(tags) - 3)); cpl_test_zero(cpl_frameset_count_tags(frameset, tags[0])); @@ -280,7 +255,7 @@ cpl_frameset_erase_frame(frameset, f); }; - cpl_test_eq(cpl_frameset_get_size(frameset), (CX_N_ELEMENTS(tags) - 6)); + cpl_test_eq(cpl_frameset_get_size(frameset), (CX_N_ELEMENTS(tags) - 6)); cpl_test_zero(cpl_frameset_count_tags(frameset, tags[3])); i = 6; @@ -313,7 +288,7 @@ cpl_test_eq(cpl_frameset_get_size(_frameset), cpl_frameset_get_size(frameset)); - it = cpl_frameset_iterator_new(frameset); + it = cpl_frameset_iterator_new(frameset); _it = cpl_frameset_iterator_new(_frameset); frame = cpl_frameset_iterator_get(it); @@ -326,8 +301,7 @@ cpl_frame_get_filename(frame)); cpl_test_noneq_ptr(cpl_frame_get_tag(_frame), cpl_frame_get_tag(frame)); - cpl_test_eq_string(cpl_frame_get_tag(_frame), - cpl_frame_get_tag(frame)); + cpl_test_eq_string(cpl_frame_get_tag(_frame), cpl_frame_get_tag(frame)); cpl_frameset_iterator_advance(it, 1); cpl_frameset_iterator_advance(_it, 1); @@ -348,10 +322,11 @@ { cpl_size nlabs; - const cpl_size *labnull = cpl_frameset_labelise(allframes, NULL, &nlabs); + const cpl_size *labnull = + cpl_frameset_labelise(allframes, NULL, &nlabs); cpl_size *labels; - const cpl_frameset * setnull; + const cpl_frameset *setnull; cpl_test_error(CPL_ERROR_NULL_INPUT); cpl_test_null(labnull); @@ -367,10 +342,10 @@ cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(labels); - cpl_test_eq(nlabs, 1); + cpl_test_eq(nlabs, 1); while (nlabs-- > 0) { - cpl_test_eq(labels[nlabs], nlabs); + cpl_test_eq(labels[nlabs], nlabs); } cpl_free(labels); @@ -381,10 +356,10 @@ cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(labels); - cpl_test_eq(nlabs, cpl_frameset_get_size(allframes)); + cpl_test_eq(nlabs, cpl_frameset_get_size(allframes)); while (nlabs-- > 0) { - cpl_test_eq(labels[nlabs], nlabs); + cpl_test_eq(labels[nlabs], nlabs); } cpl_free(labels); @@ -395,10 +370,9 @@ cpl_test_error(CPL_ERROR_NONE); cpl_test_nonnull(labels); - cpl_test_eq(nlabs, 2); + cpl_test_eq(nlabs, 2); cpl_free(labels); - } cpl_frameset_delete(_frameset); diff -Nru cpl-7.1.4+ds/cplui/tests/cpl_frame-test.c cpl-7.2.2+ds/cplui/tests/cpl_frame-test.c --- cpl-7.1.4+ds/cplui/tests/cpl_frame-test.c 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplui/tests/cpl_frame-test.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -18,13 +18,13 @@ */ #ifdef HAVE_CONFIG_H -# include +#include #endif #include #include #ifdef HAVE_UNISTD_H -# include +#include #endif #include @@ -36,22 +36,22 @@ #include "cpl_error.h" -int main(void) +int +main(void) { - int i; int next; cpl_size np; int status = 0; - const char *filename = "cplframetest1.fits"; + const char *filename = "cplframetest1.fits"; const char *filename1 = "cplframeplane.fits"; const char *filename2 = "cplframedump.txt"; - const long naxes[2] = {256, 256}; - const long nplanes[3] = {128, 256, 64}; + const long naxes[2] = { 256, 256 }; + const long nplanes[3] = { 128, 256, 64 }; cpl_frame *frame, *_frame; fitsfile *file = NULL; cpl_error_code error; - FILE * out; + FILE *out; cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); @@ -63,9 +63,9 @@ frame = cpl_frame_new(); cpl_test_nonnull(frame); - cpl_test_null(cpl_frame_get_filename(frame) ); + cpl_test_null(cpl_frame_get_filename(frame)); cpl_test_error(CPL_ERROR_DATA_NOT_FOUND); - cpl_test_null(cpl_frame_get_tag(frame) ); + cpl_test_null(cpl_frame_get_tag(frame)); cpl_test_eq(cpl_frame_get_type(frame), CPL_FRAME_TYPE_NONE); cpl_test_eq(cpl_frame_get_group(frame), CPL_FRAME_GROUP_NONE); cpl_test_eq(cpl_frame_get_level(frame), CPL_FRAME_LEVEL_NONE); @@ -113,13 +113,12 @@ cpl_test(_frame != frame); cpl_test(cpl_frame_get_filename(frame) != cpl_frame_get_filename(_frame)); - cpl_test(cpl_frame_get_tag(frame) != cpl_frame_get_tag(_frame)); + cpl_test(cpl_frame_get_tag(frame) != cpl_frame_get_tag(_frame)); cpl_test_eq_string(cpl_frame_get_filename(frame), cpl_frame_get_filename(_frame)); - cpl_test_eq_string(cpl_frame_get_tag(frame), - cpl_frame_get_tag(_frame)); + cpl_test_eq_string(cpl_frame_get_tag(frame), cpl_frame_get_tag(_frame)); cpl_test_eq(cpl_frame_get_type(frame), cpl_frame_get_type(_frame)); cpl_test_eq(cpl_frame_get_group(frame), cpl_frame_get_group(_frame)); @@ -137,14 +136,14 @@ /* * Create first HDU */ - fits_create_img(file, 8, 0, (long*)naxes, &status); + fits_create_img(file, 8, 0, (long *)naxes, &status); cpl_test_zero(status); /* * Create 3 extensions */ - for(i = 0; i < 3; i++) { - fits_insert_img(file, 16, 2, (long*)naxes, &status); + for (i = 0; i < 3; i++) { + fits_insert_img(file, 16, 2, (long *)naxes, &status); cpl_test_zero(status); } fits_close_file(file, &status); @@ -179,10 +178,10 @@ /* * Create first HDU */ - fits_create_img(file, 8, 0, (long*)nplanes, &status); + fits_create_img(file, 8, 0, (long *)nplanes, &status); cpl_test_zero(status); - fits_insert_img(file, 8, 3, (long*)nplanes, &status); + fits_insert_img(file, 8, 3, (long *)nplanes, &status); cpl_test_zero(status); fits_close_file(file, &status); diff -Nru cpl-7.1.4+ds/cplui/tests/cpl_parameterlist-test.c cpl-7.2.2+ds/cplui/tests/cpl_parameterlist-test.c --- cpl-7.1.4+ds/cplui/tests/cpl_parameterlist-test.c 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplui/tests/cpl_parameterlist-test.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -24,16 +24,16 @@ #include "cpl_test.h" #include "cpl_parameterlist.h" -int main(void) +int +main(void) { - const cpl_parameter *cq = NULL; cpl_parameter *p[4]; cpl_parameter *q = NULL; cpl_parameterlist *list = NULL; - cpl_error_code error; + cpl_error_code error; cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); @@ -52,26 +52,26 @@ * Test 2: Append parameters to the list */ - p[0] = cpl_parameter_new_value("a", CPL_TYPE_STRING, "parameter1", - "None", "value1"); + p[0] = cpl_parameter_new_value("a", CPL_TYPE_STRING, "parameter1", "None", + "value1"); error = cpl_parameterlist_append(list, p[0]); cpl_test_eq_error(error, CPL_ERROR_NONE); cpl_test_eq(cpl_parameterlist_get_size(list), 1); - p[1] = cpl_parameter_new_value("b", CPL_TYPE_STRING, "parameter2", - "None", "value2"); + p[1] = cpl_parameter_new_value("b", CPL_TYPE_STRING, "parameter2", "None", + "value2"); error = cpl_parameterlist_append(list, p[1]); cpl_test_eq_error(error, CPL_ERROR_NONE); cpl_test_eq(cpl_parameterlist_get_size(list), 2); - p[2] = cpl_parameter_new_value("c", CPL_TYPE_STRING, "parameter3", - "None", "value3"); + p[2] = cpl_parameter_new_value("c", CPL_TYPE_STRING, "parameter3", "None", + "value3"); error = cpl_parameterlist_append(list, p[2]); cpl_test_eq_error(error, CPL_ERROR_NONE); cpl_test_eq(cpl_parameterlist_get_size(list), 3); - p[3] = cpl_parameter_new_value("d", CPL_TYPE_STRING, "parameter4", - "None", "value4"); + p[3] = cpl_parameter_new_value("d", CPL_TYPE_STRING, "parameter4", "None", + "value4"); error = cpl_parameterlist_append(list, p[3]); cpl_test_eq_error(error, CPL_ERROR_NONE); @@ -117,28 +117,28 @@ list = cpl_parameterlist_new(); cpl_test_nonnull(list); - p[0] = cpl_parameter_new_value("a", CPL_TYPE_STRING, "parameter1", - "None", "value1"); + p[0] = cpl_parameter_new_value("a", CPL_TYPE_STRING, "parameter1", "None", + "value1"); cpl_test_nonnull(p[0]); error = cpl_parameter_set_tag(p[0], "mytag"); cpl_test_eq_error(error, CPL_ERROR_NONE); error = cpl_parameterlist_append(list, p[0]); cpl_test_eq_error(error, CPL_ERROR_NONE); - + cq = cpl_parameterlist_find_tag_const(list, NULL); cpl_test_null(cq); cpl_test_eq_error(error, CPL_ERROR_NONE); - - p[1] = cpl_parameter_new_value("b", CPL_TYPE_STRING, "parameter2", - "None", "value2"); + + p[1] = cpl_parameter_new_value("b", CPL_TYPE_STRING, "parameter2", "None", + "value2"); cpl_test_nonnull(p[1]); error = cpl_parameterlist_append(list, p[1]); cpl_test_eq_error(error, CPL_ERROR_NONE); - + cq = cpl_parameterlist_find_tag_const(list, NULL); cpl_test_eq_ptr(cq, p[1]); cpl_test_eq_error(error, CPL_ERROR_NONE); - + cpl_parameterlist_delete(list); @@ -154,24 +154,24 @@ cpl_test_nonnull(p[0]); error = cpl_parameterlist_append(list, p[0]); cpl_test_eq_error(error, CPL_ERROR_NONE); - p[1] = cpl_parameter_new_value("b", CPL_TYPE_STRING, "parameter2", - NULL, "value2"); + p[1] = cpl_parameter_new_value("b", CPL_TYPE_STRING, "parameter2", NULL, + "value2"); cpl_test_nonnull(p[1]); error = cpl_parameterlist_append(list, p[1]); cpl_test_eq_error(error, CPL_ERROR_NONE); - + cq = cpl_parameterlist_find_context_const(list, "Context1"); cpl_test_eq_ptr(cq, p[0]); cpl_test_eq_error(error, CPL_ERROR_NONE); - + cq = cpl_parameterlist_find_context_const(list, "Context2"); cpl_test_null(cq); cpl_test_eq_error(error, CPL_ERROR_NONE); - + cq = cpl_parameterlist_find_context_const(list, NULL); cpl_test_eq_ptr(cq, p[1]); cpl_test_eq_error(error, CPL_ERROR_NONE); - + cpl_parameterlist_delete(list); /* diff -Nru cpl-7.1.4+ds/cplui/tests/cpl_parameter-test.c cpl-7.2.2+ds/cplui/tests/cpl_parameter-test.c --- cpl-7.1.4+ds/cplui/tests/cpl_parameter-test.c 2021-05-07 12:09:10.000000000 +0000 +++ cpl-7.2.2+ds/cplui/tests/cpl_parameter-test.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -24,9 +24,9 @@ #include "cpl_test.h" #include "cpl_parameter.h" -int main(void) +int +main(void) { - const cxchar *sval1 = "abcdefghijklmnopqrstuvwxyz"; const cxchar *sval2 = "zyxwvutsrqponmlkjihgfedcba"; @@ -40,13 +40,16 @@ cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); + /* + * Test 1: Create a parameter and check its validity + */ /* - * Test 1: Create a string parameter and check its validity + * Test 1.1: Create a string parameter and check its validity */ - p = cpl_parameter_new_value("a", CPL_TYPE_STRING, "Test parameter", - "None", sval1); + p = cpl_parameter_new_value("a", CPL_TYPE_STRING, "Test parameter", "None", + sval1); cpl_test_nonnull(p); @@ -61,12 +64,82 @@ cpl_test_eq_string(cpl_parameter_get_string(p), sval1); cpl_test_noneq_ptr(cpl_parameter_get_string(p), sval1); + cpl_parameter_delete(p); + + /* + * Test 1.2: Create an enumeration parameter and check its validity + */ + + p = cpl_parameter_new_enum("a", CPL_TYPE_STRING, "Test parameter", "None", + "a", 3, "a", "b", "c"); + + cpl_test_eq_string(cpl_parameter_get_name(p), "a"); + cpl_test_eq_string(cpl_parameter_get_help(p), "Test parameter"); + cpl_test_eq_string(cpl_parameter_get_context(p), "None"); + cpl_test_null(cpl_parameter_get_tag(p)); + + cpl_test_eq(cpl_parameter_get_type(p), CPL_TYPE_STRING); + cpl_test_eq(cpl_parameter_get_class(p), CPL_PARAMETER_CLASS_ENUM); + + cpl_test_eq_string(cpl_parameter_get_string(p), "a"); + + cpl_parameter_delete(p); + + const cxchar *s_values[] = { "first", "second", "third" }; + cxsize nvalues = sizeof(s_values) / sizeof(s_values[0]); + + p = cpl_parameter_new_enum_from_array("a", CPL_TYPE_STRING, + "A string enumeration", "None", 0, + nvalues, s_values); + + cpl_test_eq_string(cpl_parameter_get_name(p), "a"); + cpl_test_eq_string(cpl_parameter_get_help(p), "A string enumeration"); + cpl_test_eq_string(cpl_parameter_get_context(p), "None"); + cpl_test_null(cpl_parameter_get_tag(p)); + + cpl_test_eq(cpl_parameter_get_type(p), CPL_TYPE_STRING); + cpl_test_eq(cpl_parameter_get_class(p), CPL_PARAMETER_CLASS_ENUM); + + cpl_test_eq(cpl_parameter_get_enum_size(p), nvalues); + for (cxsize ivalue = 0; ivalue < nvalues; ++ivalue) { + cpl_test_eq_string(cpl_parameter_get_enum_string(p, ivalue), + s_values[ivalue]); + } + + cpl_parameter_delete(p); + + const int i_values[] = { 1, 3, 5 }; + nvalues = sizeof(i_values) / sizeof(i_values[0]); + + p = cpl_parameter_new_enum_from_array("a", CPL_TYPE_INT, + "An integer enumeration", "None", 1, + nvalues, i_values); + + cpl_test_eq_string(cpl_parameter_get_name(p), "a"); + cpl_test_eq_string(cpl_parameter_get_help(p), "An integer enumeration"); + cpl_test_eq_string(cpl_parameter_get_context(p), "None"); + cpl_test_null(cpl_parameter_get_tag(p)); + + cpl_test_eq(cpl_parameter_get_type(p), CPL_TYPE_INT); + cpl_test_eq(cpl_parameter_get_class(p), CPL_PARAMETER_CLASS_ENUM); + + cpl_test_eq(cpl_parameter_get_enum_size(p), nvalues); + for (cxsize ivalue = 0; ivalue < nvalues; ++ivalue) { + cpl_test_eq(cpl_parameter_get_enum_int(p, ivalue), i_values[ivalue]); + } + + cpl_parameter_delete(p); /* * Test 2: Assign a new string value to the parameter and check * its validity */ + p = cpl_parameter_new_value("a", CPL_TYPE_STRING, "Test parameter", "None", + sval1); + + cpl_test_nonnull(p); + error = cpl_parameter_set_string(p, sval2); cpl_test_eq_error(error, CPL_ERROR_NONE); @@ -81,8 +154,8 @@ * Test 3: Change the parameter's default value. */ - p = cpl_parameter_new_value("b", CPL_TYPE_BOOL, "A boolean value.", - "None", 0); + p = cpl_parameter_new_value("b", CPL_TYPE_BOOL, "A boolean value.", "None", + 0); cpl_test_zero(cpl_parameter_get_default_bool(p)); cpl_test_eq(cpl_parameter_get_default_bool(p), cpl_parameter_get_bool(p)); @@ -91,13 +164,14 @@ cpl_test_eq_error(error, CPL_ERROR_NONE); cpl_test_eq(cpl_parameter_get_default_bool(p), 1); - cpl_test_noneq(cpl_parameter_get_default_bool(p), cpl_parameter_get_bool(p)); + cpl_test_noneq(cpl_parameter_get_default_bool(p), + cpl_parameter_get_bool(p)); cpl_parameter_delete(p); - p = cpl_parameter_new_value("c", CPL_TYPE_STRING, "A string value.", - "None", sval1); + p = cpl_parameter_new_value("c", CPL_TYPE_STRING, "A string value.", "None", + sval1); cpl_test_eq_string(cpl_parameter_get_default_string(p), sval1); cpl_test_eq_string(cpl_parameter_get_default_string(p), @@ -118,32 +192,26 @@ * Test 4.1: Copy an enum parameter */ - p = cpl_parameter_new_enum("a", CPL_TYPE_STRING, "A string enum.", - "None", sval1, 2, sval1, sval2); + p = cpl_parameter_new_enum("a", CPL_TYPE_STRING, "A string enum.", "None", + sval1, 2, sval1, sval2); q = cpl_parameter_duplicate(p); cpl_test_nonnull(q); - cpl_test_eq(cpl_parameter_get_class(q), - cpl_parameter_get_class(p)); - cpl_test_eq(cpl_parameter_get_type(q), - cpl_parameter_get_type(p)); - - cpl_test_eq_string(cpl_parameter_get_name(q), - cpl_parameter_get_name(p)); - cpl_test_noneq_ptr(cpl_parameter_get_name(q), - cpl_parameter_get_name(p)); + cpl_test_eq(cpl_parameter_get_class(q), cpl_parameter_get_class(p)); + cpl_test_eq(cpl_parameter_get_type(q), cpl_parameter_get_type(p)); + + cpl_test_eq_string(cpl_parameter_get_name(q), cpl_parameter_get_name(p)); + cpl_test_noneq_ptr(cpl_parameter_get_name(q), cpl_parameter_get_name(p)); cpl_test_eq_string(cpl_parameter_get_context(q), cpl_parameter_get_context(p)); cpl_test_noneq_ptr(cpl_parameter_get_context(q), cpl_parameter_get_context(p)); - cpl_test_eq_string(cpl_parameter_get_help(q), - cpl_parameter_get_help(p)); - cpl_test_noneq_ptr(cpl_parameter_get_help(q), - cpl_parameter_get_help(p)); + cpl_test_eq_string(cpl_parameter_get_help(q), cpl_parameter_get_help(p)); + cpl_test_noneq_ptr(cpl_parameter_get_help(q), cpl_parameter_get_help(p)); cpl_test_eq_string(cpl_parameter_get_default_string(q), cpl_parameter_get_default_string(p)); @@ -155,8 +223,7 @@ cpl_test_noneq_ptr(cpl_parameter_get_string(q), cpl_parameter_get_string(p)); - cpl_test_eq(cpl_parameter_get_enum_size(q), - cpl_parameter_get_enum_size(p)); + cpl_test_eq(cpl_parameter_get_enum_size(q), cpl_parameter_get_enum_size(p)); cpl_test_eq_string(cpl_parameter_get_enum_string(q, 0), cpl_parameter_get_enum_string(p, 0)); @@ -175,22 +242,18 @@ * Test 4.2: Copy an integer range parameter */ - p = cpl_parameter_new_range("a", CPL_TYPE_INT, "An int range.", - "None", (int)3, (int)1, (int)5); + p = cpl_parameter_new_range("a", CPL_TYPE_INT, "An int range.", "None", + (int)3, (int)1, (int)5); q = cpl_parameter_duplicate(p); cpl_test_nonnull(q); - cpl_test_eq(cpl_parameter_get_class(q), - cpl_parameter_get_class(p)); - cpl_test_eq(cpl_parameter_get_type(q), - cpl_parameter_get_type(p)); + cpl_test_eq(cpl_parameter_get_class(q), cpl_parameter_get_class(p)); + cpl_test_eq(cpl_parameter_get_type(q), cpl_parameter_get_type(p)); cpl_test_error(CPL_ERROR_NONE); - cpl_test_eq_string(cpl_parameter_get_name(q), - cpl_parameter_get_name(p)); - cpl_test_noneq_ptr(cpl_parameter_get_name(q), - cpl_parameter_get_name(p)); + cpl_test_eq_string(cpl_parameter_get_name(q), cpl_parameter_get_name(p)); + cpl_test_noneq_ptr(cpl_parameter_get_name(q), cpl_parameter_get_name(p)); cpl_test_error(CPL_ERROR_NONE); cpl_test_eq_string(cpl_parameter_get_context(q), @@ -199,18 +262,15 @@ cpl_parameter_get_context(p)); cpl_test_error(CPL_ERROR_NONE); - cpl_test_eq_string(cpl_parameter_get_help(q), - cpl_parameter_get_help(p)); - cpl_test_noneq_ptr(cpl_parameter_get_help(q), - cpl_parameter_get_help(p)); + cpl_test_eq_string(cpl_parameter_get_help(q), cpl_parameter_get_help(p)); + cpl_test_noneq_ptr(cpl_parameter_get_help(q), cpl_parameter_get_help(p)); cpl_test_error(CPL_ERROR_NONE); cpl_test_eq(cpl_parameter_get_default_int(q), cpl_parameter_get_default_int(p)); cpl_test_error(CPL_ERROR_NONE); - cpl_test_eq(cpl_parameter_get_int(q), - cpl_parameter_get_int(p)); + cpl_test_eq(cpl_parameter_get_int(q), cpl_parameter_get_int(p)); cpl_test_error(CPL_ERROR_NONE); cpl_test_eq(cpl_parameter_get_range_min_int(q), @@ -224,25 +284,21 @@ /* - * Test 4.3: Copy an integer range parameter + * Test 4.3: Copy an double range parameter */ - p = cpl_parameter_new_range("a", CPL_TYPE_DOUBLE, "A double range.", - "None", (double)3.4, (double)1.2, (double)5.7); + p = cpl_parameter_new_range("a", CPL_TYPE_DOUBLE, "A double range.", "None", + (double)3.4, (double)1.2, (double)5.7); q = cpl_parameter_duplicate(p); cpl_test_nonnull(q); - cpl_test_eq(cpl_parameter_get_class(q), - cpl_parameter_get_class(p)); - cpl_test_eq(cpl_parameter_get_type(q), - cpl_parameter_get_type(p)); + cpl_test_eq(cpl_parameter_get_class(q), cpl_parameter_get_class(p)); + cpl_test_eq(cpl_parameter_get_type(q), cpl_parameter_get_type(p)); cpl_test_error(CPL_ERROR_NONE); - cpl_test_eq_string(cpl_parameter_get_name(q), - cpl_parameter_get_name(p)); - cpl_test_noneq_ptr(cpl_parameter_get_name(q), - cpl_parameter_get_name(p)); + cpl_test_eq_string(cpl_parameter_get_name(q), cpl_parameter_get_name(p)); + cpl_test_noneq_ptr(cpl_parameter_get_name(q), cpl_parameter_get_name(p)); cpl_test_error(CPL_ERROR_NONE); cpl_test_eq_string(cpl_parameter_get_context(q), @@ -251,28 +307,22 @@ cpl_parameter_get_context(p)); cpl_test_error(CPL_ERROR_NONE); - cpl_test_eq_string(cpl_parameter_get_help(q), - cpl_parameter_get_help(p)); - cpl_test_noneq_ptr(cpl_parameter_get_help(q), - cpl_parameter_get_help(p)); + cpl_test_eq_string(cpl_parameter_get_help(q), cpl_parameter_get_help(p)); + cpl_test_noneq_ptr(cpl_parameter_get_help(q), cpl_parameter_get_help(p)); cpl_test_error(CPL_ERROR_NONE); cpl_test_abs(cpl_parameter_get_default_double(q), - cpl_parameter_get_default_double(p), - DBL_EPSILON); + cpl_parameter_get_default_double(p), DBL_EPSILON); cpl_test_error(CPL_ERROR_NONE); - cpl_test_abs(cpl_parameter_get_double(q), - cpl_parameter_get_double(p), + cpl_test_abs(cpl_parameter_get_double(q), cpl_parameter_get_double(p), DBL_EPSILON); cpl_test_error(CPL_ERROR_NONE); cpl_test_abs(cpl_parameter_get_range_min_double(q), - cpl_parameter_get_range_min_double(p), - DBL_EPSILON); + cpl_parameter_get_range_min_double(p), DBL_EPSILON); cpl_test_abs(cpl_parameter_get_range_max_double(q), - cpl_parameter_get_range_max_double(p), - DBL_EPSILON); + cpl_parameter_get_range_max_double(p), DBL_EPSILON); cpl_test_error(CPL_ERROR_NONE); cpl_parameter_delete(q); @@ -283,8 +333,8 @@ * Test 5: Test some error handling */ - p = cpl_parameter_new_value("a", CPL_TYPE_STRING, "A string value.", - "None", sval1); + p = cpl_parameter_new_value("a", CPL_TYPE_STRING, "A string value.", "None", + sval1); error = cpl_parameter_set_int(p, 0); cpl_test_eq_error(error, CPL_ERROR_TYPE_MISMATCH); @@ -299,15 +349,15 @@ cpl_parameter_delete(p); - p = cpl_parameter_new_range("a", CPL_TYPE_BOOL, "A boolean range.", - "None", FALSE, FALSE, TRUE); + p = cpl_parameter_new_range("a", CPL_TYPE_BOOL, "A boolean range.", "None", + FALSE, FALSE, TRUE); cpl_test_null(p); cpl_test_error(CPL_ERROR_INVALID_TYPE); cpl_parameter_delete(p); - p = cpl_parameter_new_range("a", CPL_TYPE_STRING, "A string range.", - "None", "aaa", "aaa", "zzz"); + p = cpl_parameter_new_range("a", CPL_TYPE_STRING, "A string range.", "None", + "aaa", "aaa", "zzz"); cpl_test_null(p); cpl_test_error(CPL_ERROR_INVALID_TYPE); @@ -332,5 +382,4 @@ */ return cpl_test_end(0); - } diff -Nru cpl-7.1.4+ds/cplui/tests/cpl_pluginlist-test.c cpl-7.2.2+ds/cplui/tests/cpl_pluginlist-test.c --- cpl-7.1.4+ds/cplui/tests/cpl_pluginlist-test.c 2021-05-07 12:09:10.000000000 +0000 +++ cpl-7.2.2+ds/cplui/tests/cpl_pluginlist-test.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -25,21 +25,15 @@ #include "cpl_pluginlist.h" #include "cpl_recipedefine.h" -int main(void) +int +main(void) { + const char *eso_gpl_license = cpl_get_license(PACKAGE_NAME, "2005, 2008"); - const char * eso_gpl_license = cpl_get_license(PACKAGE_NAME, "2005, 2008"); + cpl_plugin *pl1 = NULL, *pl2 = NULL, *pl3 = NULL, *pl4 = NULL, *pl5 = NULL, + *front = NULL, *back = NULL, *search = NULL; - cpl_plugin *pl1 = NULL, - *pl2 = NULL, - *pl3 = NULL, - *pl4 = NULL, - *pl5 = NULL, - *front = NULL, - *back = NULL, - *search = NULL; - - cpl_pluginlist *pllst = NULL; + cpl_pluginlist *pllst = NULL; cpl_error_code error; @@ -51,92 +45,52 @@ pl1 = cpl_plugin_new(); cpl_test_nonnull(pl1); - error = cpl_plugin_init(pl1, - 1, - 10000, - (unsigned long) CPL_PLUGIN_TYPE_RECIPE, - "cmdlcaller.test.plgn1", - "synopsis1", - "description1", - "Fname Lname", - PACKAGE_BUGREPORT, - eso_gpl_license, - NULL, - NULL, - NULL); + error = + cpl_plugin_init(pl1, 1, 10000, (unsigned long)CPL_PLUGIN_TYPE_RECIPE, + "cmdlcaller.test.plgn1", "synopsis1", "description1", + "Fname Lname", PACKAGE_BUGREPORT, eso_gpl_license, NULL, + NULL, NULL); cpl_test_eq_error(error, CPL_ERROR_NONE); pl2 = cpl_plugin_new(); cpl_test_nonnull(pl2); - error = cpl_plugin_init(pl2, - 1, - 10000, - (unsigned long) CPL_PLUGIN_TYPE_RECIPE, - "cmdlcaller.test.plgn2", - "synopsis2", - "description2", - "Fname Lname", - PACKAGE_BUGREPORT, - eso_gpl_license, - NULL, - NULL, - NULL); + error = + cpl_plugin_init(pl2, 1, 10000, (unsigned long)CPL_PLUGIN_TYPE_RECIPE, + "cmdlcaller.test.plgn2", "synopsis2", "description2", + "Fname Lname", PACKAGE_BUGREPORT, eso_gpl_license, NULL, + NULL, NULL); cpl_test_eq_error(error, CPL_ERROR_NONE); pl3 = cpl_plugin_new(); cpl_test_nonnull(pl3); - error = cpl_plugin_init(pl3, - 1, - 10000, - (unsigned long) CPL_PLUGIN_TYPE_RECIPE, - "cmdlcaller.test.plgn3", - "synopsis3", - "description3", - "Fname Lname", - PACKAGE_BUGREPORT, - eso_gpl_license, - NULL, - NULL, - NULL); + error = + cpl_plugin_init(pl3, 1, 10000, (unsigned long)CPL_PLUGIN_TYPE_RECIPE, + "cmdlcaller.test.plgn3", "synopsis3", "description3", + "Fname Lname", PACKAGE_BUGREPORT, eso_gpl_license, NULL, + NULL, NULL); cpl_test_eq_error(error, CPL_ERROR_NONE); pl4 = cpl_plugin_new(); cpl_test_nonnull(pl4); - error = cpl_plugin_init(pl4, - 1, - 10000, - (unsigned long) CPL_PLUGIN_TYPE_RECIPE, - "cmdlcaller.test.plgn4", - "synopsis4", - "description4", - "Fname Lname", - PACKAGE_BUGREPORT, - eso_gpl_license, - NULL, - NULL, - NULL); + error = + cpl_plugin_init(pl4, 1, 10000, (unsigned long)CPL_PLUGIN_TYPE_RECIPE, + "cmdlcaller.test.plgn4", "synopsis4", "description4", + "Fname Lname", PACKAGE_BUGREPORT, eso_gpl_license, NULL, + NULL, NULL); cpl_test_eq_error(error, CPL_ERROR_NONE); pl5 = cpl_plugin_new(); cpl_test_nonnull(pl5); - error = cpl_plugin_init(pl5, - 1, - 10000, - (unsigned long) CPL_PLUGIN_TYPE_RECIPE, - "cmdlcaller.test.plgn5", - "synopsis5", - "description5", - "Fname Lname", - PACKAGE_BUGREPORT, - eso_gpl_license, - NULL, - NULL, - NULL); + error = + cpl_plugin_init(pl5, 1, 10000, (unsigned long)CPL_PLUGIN_TYPE_RECIPE, + "cmdlcaller.test.plgn5", "synopsis5", "description5", + "Fname Lname", PACKAGE_BUGREPORT, eso_gpl_license, NULL, + NULL, NULL); cpl_test_eq_error(error, CPL_ERROR_NONE); pllst = cpl_pluginlist_new(); @@ -173,8 +127,8 @@ */ - front = cpl_pluginlist_get_first(pllst); - back = cpl_pluginlist_get_last(pllst); + front = cpl_pluginlist_get_first(pllst); + back = cpl_pluginlist_get_last(pllst); cpl_test_noneq_ptr(front, back); @@ -190,6 +144,4 @@ cpl_pluginlist_delete(pllst); return cpl_test_end(0); - } - diff -Nru cpl-7.1.4+ds/cplui/tests/cpl_plugin-test.c cpl-7.2.2+ds/cplui/tests/cpl_plugin-test.c --- cpl-7.1.4+ds/cplui/tests/cpl_plugin-test.c 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplui/tests/cpl_plugin-test.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -27,49 +27,35 @@ #include -int main(void) +int +main(void) { + cpl_plugin *plgn1; - cpl_plugin *plgn1; - - int ecode; + int ecode; const unsigned int api1 = 1; - unsigned int aapi1; + unsigned int aapi1; - const unsigned long version1 = 30507L, - type1 = 1L; + const unsigned long version1 = 30507L, type1 = 1L; - unsigned long aversion1, - atype1; + unsigned long aversion1, atype1; - char *asversion1, *astype1; - const char *asnull; - const char *sversion1 = "3.5.7", - *stype1 = "recipe", - *sname1 = "eso.cpl.test", - *asname1, - *ssynopsis1 = "test_synopsis", - *assynopsis1, - *sdescription1 = "test_description", - *asdescription1, - *sauthor1 = "test_author", - *asauthor1, - *semail1 = "test_email", - *asemail1, - *scopyright1 = "test_copyright", - *ascopyright1; - - cpl_plugin_func initialize1 = (cpl_plugin_func)1, - ainitialize1, - execute1 = (cpl_plugin_func)1, - aexecute1, - deinitialize1 = (cpl_plugin_func)1, - adeinitialize1; + char *asversion1, *astype1; + const char *asnull; + const char *sversion1 = "3.5.7", *stype1 = "recipe", + *sname1 = "eso.cpl.test", *asname1, + *ssynopsis1 = "test_synopsis", *assynopsis1, + *sdescription1 = "test_description", *asdescription1, + *sauthor1 = "test_author", *asauthor1, *semail1 = "test_email", + *asemail1, *scopyright1 = "test_copyright", *ascopyright1; - FILE * stream; + cpl_plugin_func initialize1 = (cpl_plugin_func)1, ainitialize1, + execute1 = (cpl_plugin_func)1, aexecute1, + deinitialize1 = (cpl_plugin_func)1, adeinitialize1; + FILE *stream; cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); @@ -79,8 +65,8 @@ * Test1 : Accessor Functions */ - stream = cpl_msg_get_level() > CPL_MSG_INFO - ? fopen("/dev/null", "a") : stdout; + stream = + cpl_msg_get_level() > CPL_MSG_INFO ? fopen("/dev/null", "a") : stdout; cpl_test_nonnull(stream); @@ -93,7 +79,7 @@ ecode = cpl_plugin_set_api(NULL, api1); cpl_test_eq_error(ecode, CPL_ERROR_NULL_INPUT); - aapi1 = cpl_plugin_get_api(NULL); + aapi1 = cpl_plugin_get_api(NULL); cpl_test_error(CPL_ERROR_NULL_INPUT); cpl_test_zero(aapi1); @@ -108,7 +94,7 @@ ecode = cpl_plugin_set_version(NULL, version1); cpl_test_eq_error(ecode, CPL_ERROR_NULL_INPUT); - aversion1 = cpl_plugin_get_version(NULL); + aversion1 = cpl_plugin_get_version(NULL); cpl_test_error(CPL_ERROR_NULL_INPUT); cpl_test_zero(aversion1); @@ -119,7 +105,7 @@ ecode = cpl_plugin_set_version(plgn1, version1); cpl_test_eq_error(ecode, CPL_ERROR_NONE); - aversion1 = cpl_plugin_get_version(plgn1); + aversion1 = cpl_plugin_get_version(plgn1); cpl_test_eq(aversion1, version1); @@ -135,7 +121,7 @@ ecode = cpl_plugin_set_type(NULL, type1); cpl_test_eq_error(ecode, CPL_ERROR_NULL_INPUT); - atype1 = cpl_plugin_get_type(NULL); + atype1 = cpl_plugin_get_type(NULL); cpl_test_error(CPL_ERROR_NULL_INPUT); cpl_test_eq(atype1, CPL_PLUGIN_TYPE_NONE); @@ -146,7 +132,7 @@ ecode = cpl_plugin_set_type(plgn1, type1); cpl_test_eq_error(ecode, CPL_ERROR_NONE); - atype1 = cpl_plugin_get_type(plgn1); + atype1 = cpl_plugin_get_type(plgn1); cpl_test_eq(atype1, type1); @@ -165,14 +151,14 @@ ecode = cpl_plugin_set_name(plgn1, NULL); cpl_test_eq_error(ecode, CPL_ERROR_NULL_INPUT); - asnull = cpl_plugin_get_name(NULL); + asnull = cpl_plugin_get_name(NULL); cpl_test_error(CPL_ERROR_NULL_INPUT); cpl_test_null(asnull); ecode = cpl_plugin_set_name(plgn1, sname1); cpl_test_eq_error(ecode, CPL_ERROR_NONE); - asname1 = cpl_plugin_get_name(plgn1); + asname1 = cpl_plugin_get_name(plgn1); cpl_test_noneq_ptr(sname1, asname1); cpl_test_eq_string(sname1, asname1); @@ -181,21 +167,21 @@ ecode = cpl_plugin_set_synopsis(NULL, ssynopsis1); cpl_test_eq_error(ecode, CPL_ERROR_NULL_INPUT); - asnull = cpl_plugin_get_synopsis(NULL); + asnull = cpl_plugin_get_synopsis(NULL); cpl_test_error(CPL_ERROR_NULL_INPUT); cpl_test_null(asnull); ecode = cpl_plugin_set_synopsis(plgn1, NULL); cpl_test_eq_error(ecode, CPL_ERROR_NONE); - asnull = cpl_plugin_get_synopsis(plgn1); + asnull = cpl_plugin_get_synopsis(plgn1); cpl_test_error(CPL_ERROR_NONE); cpl_test_null(asnull); ecode = cpl_plugin_set_synopsis(plgn1, ssynopsis1); cpl_test_eq_error(ecode, CPL_ERROR_NONE); - assynopsis1 = cpl_plugin_get_synopsis(plgn1); + assynopsis1 = cpl_plugin_get_synopsis(plgn1); cpl_test_noneq_ptr(ssynopsis1, assynopsis1); cpl_test_eq_string(ssynopsis1, assynopsis1); @@ -204,20 +190,20 @@ ecode = cpl_plugin_set_description(NULL, sdescription1); cpl_test_eq_error(ecode, CPL_ERROR_NULL_INPUT); - asnull = cpl_plugin_get_description(NULL); + asnull = cpl_plugin_get_description(NULL); cpl_test_error(CPL_ERROR_NULL_INPUT); cpl_test_null(asnull); ecode = cpl_plugin_set_description(plgn1, NULL); cpl_test_eq_error(ecode, CPL_ERROR_NONE); - asnull = cpl_plugin_get_description(plgn1); + asnull = cpl_plugin_get_description(plgn1); cpl_test_null(asnull); ecode = cpl_plugin_set_description(plgn1, sdescription1); cpl_test_eq_error(ecode, CPL_ERROR_NONE); - asdescription1 = cpl_plugin_get_description(plgn1); + asdescription1 = cpl_plugin_get_description(plgn1); cpl_test_noneq_ptr(sdescription1, asdescription1); cpl_test_eq_string(sdescription1, asdescription1); @@ -229,14 +215,14 @@ ecode = cpl_plugin_set_author(plgn1, NULL); cpl_test_eq_error(ecode, CPL_ERROR_NULL_INPUT); - asnull = cpl_plugin_get_author(NULL); + asnull = cpl_plugin_get_author(NULL); cpl_test_error(CPL_ERROR_NULL_INPUT); cpl_test_null(asnull); ecode = cpl_plugin_set_author(plgn1, sauthor1); cpl_test_eq_error(ecode, CPL_ERROR_NONE); - asauthor1 = cpl_plugin_get_author(plgn1); + asauthor1 = cpl_plugin_get_author(plgn1); cpl_test_noneq_ptr(sauthor1, asauthor1); cpl_test_eq_string(sauthor1, asauthor1); @@ -248,14 +234,14 @@ ecode = cpl_plugin_set_email(plgn1, NULL); cpl_test_eq_error(ecode, CPL_ERROR_NULL_INPUT); - asnull = cpl_plugin_get_email(NULL); + asnull = cpl_plugin_get_email(NULL); cpl_test_error(CPL_ERROR_NULL_INPUT); cpl_test_null(asnull); ecode = cpl_plugin_set_email(plgn1, semail1); cpl_test_eq_error(ecode, CPL_ERROR_NONE); - asemail1 = cpl_plugin_get_email(plgn1); + asemail1 = cpl_plugin_get_email(plgn1); cpl_test_noneq_ptr(semail1, asemail1); cpl_test_eq_string(semail1, asemail1); @@ -267,14 +253,14 @@ ecode = cpl_plugin_set_copyright(plgn1, NULL); cpl_test_eq_error(ecode, CPL_ERROR_NULL_INPUT); - asnull = cpl_plugin_get_copyright(NULL); + asnull = cpl_plugin_get_copyright(NULL); cpl_test_error(CPL_ERROR_NULL_INPUT); cpl_test_null(asnull); ecode = cpl_plugin_set_copyright(plgn1, scopyright1); cpl_test_eq_error(ecode, CPL_ERROR_NONE); - ascopyright1 = cpl_plugin_get_copyright(plgn1); + ascopyright1 = cpl_plugin_get_copyright(plgn1); cpl_test_noneq_ptr(scopyright1, ascopyright1); cpl_test_eq_string(scopyright1, ascopyright1); @@ -286,17 +272,17 @@ ecode = cpl_plugin_set_init(plgn1, NULL); cpl_test_eq_error(ecode, CPL_ERROR_NONE); - ainitialize1 = cpl_plugin_get_init(NULL); + ainitialize1 = cpl_plugin_get_init(NULL); cpl_test_error(CPL_ERROR_NULL_INPUT); cpl_test(ainitialize1 == NULL); - ainitialize1 = cpl_plugin_get_init(plgn1); + ainitialize1 = cpl_plugin_get_init(plgn1); cpl_test(ainitialize1 == NULL); ecode = cpl_plugin_set_init(plgn1, initialize1); cpl_test_eq_error(ecode, CPL_ERROR_NONE); - ainitialize1 = cpl_plugin_get_init(plgn1); + ainitialize1 = cpl_plugin_get_init(plgn1); cpl_test(ainitialize1 == initialize1); /* PLUGIN EXECUTE */ @@ -304,20 +290,20 @@ ecode = cpl_plugin_set_exec(NULL, execute1); cpl_test_eq_error(ecode, CPL_ERROR_NULL_INPUT); - aexecute1 = cpl_plugin_get_exec(NULL); + aexecute1 = cpl_plugin_get_exec(NULL); cpl_test_error(CPL_ERROR_NULL_INPUT); cpl_test(aexecute1 == NULL); ecode = cpl_plugin_set_exec(plgn1, NULL); cpl_test_eq_error(ecode, CPL_ERROR_NONE); - aexecute1 = cpl_plugin_get_exec(plgn1); + aexecute1 = cpl_plugin_get_exec(plgn1); cpl_test(aexecute1 == NULL); ecode = cpl_plugin_set_exec(plgn1, execute1); cpl_test_eq_error(ecode, CPL_ERROR_NONE); - aexecute1 = cpl_plugin_get_exec(plgn1); + aexecute1 = cpl_plugin_get_exec(plgn1); cpl_test(aexecute1 == execute1); /* PLUGIN DEINITIALIZE */ @@ -325,20 +311,20 @@ ecode = cpl_plugin_set_deinit(NULL, deinitialize1); cpl_test_eq_error(ecode, CPL_ERROR_NULL_INPUT); - adeinitialize1 = cpl_plugin_get_deinit(NULL); + adeinitialize1 = cpl_plugin_get_deinit(NULL); cpl_test_error(CPL_ERROR_NULL_INPUT); cpl_test(adeinitialize1 == NULL); ecode = cpl_plugin_set_deinit(plgn1, NULL); cpl_test_eq_error(ecode, CPL_ERROR_NONE); - adeinitialize1 = cpl_plugin_get_deinit(plgn1); + adeinitialize1 = cpl_plugin_get_deinit(plgn1); cpl_test(adeinitialize1 == NULL); ecode = cpl_plugin_set_deinit(plgn1, deinitialize1); cpl_test_eq_error(ecode, CPL_ERROR_NONE); - adeinitialize1 = cpl_plugin_get_deinit(plgn1); + adeinitialize1 = cpl_plugin_get_deinit(plgn1); cpl_test(adeinitialize1 == deinitialize1); cpl_plugin_delete(plgn1); @@ -348,134 +334,54 @@ /* PLUGIN INIT */ - ecode = cpl_plugin_init(NULL, - api1, - version1, - type1, - sname1, - ssynopsis1, - sdescription1, - sauthor1, - semail1, - scopyright1, - initialize1, - execute1, - deinitialize1); - cpl_test_eq_error(ecode, CPL_ERROR_NULL_INPUT); - - ecode = cpl_plugin_init(plgn1, - api1, - version1, - type1, - NULL, - ssynopsis1, - sdescription1, - sauthor1, - semail1, - scopyright1, - initialize1, - execute1, - deinitialize1); - cpl_test_eq_error(ecode, CPL_ERROR_NULL_INPUT); - - ecode = cpl_plugin_init(plgn1, - api1, - version1, - type1, - sname1, - NULL, - sdescription1, - sauthor1, - semail1, - scopyright1, - initialize1, - execute1, - deinitialize1); - cpl_test_eq_error(ecode, CPL_ERROR_NULL_INPUT); - - ecode = cpl_plugin_init(plgn1, - api1, - version1, - type1, - sname1, - ssynopsis1, - NULL, - sauthor1, - semail1, - scopyright1, - initialize1, - execute1, - deinitialize1); - cpl_test_eq_error(ecode, CPL_ERROR_NULL_INPUT); - - ecode = cpl_plugin_init(plgn1, - api1, - version1, - type1, - sname1, - ssynopsis1, - sdescription1, - NULL, - semail1, - scopyright1, - initialize1, - execute1, - deinitialize1); - cpl_test_eq_error(ecode, CPL_ERROR_NULL_INPUT); - - ecode = cpl_plugin_init(plgn1, - api1, - version1, - type1, - sname1, - ssynopsis1, - sdescription1, - sauthor1, - NULL, - scopyright1, - initialize1, - execute1, - deinitialize1); - cpl_test_eq_error(ecode, CPL_ERROR_NULL_INPUT); - - ecode = cpl_plugin_init(plgn1, - api1, - version1, - type1, - sname1, - ssynopsis1, - sdescription1, - sauthor1, - semail1, - NULL, - initialize1, - execute1, - deinitialize1); - cpl_test_eq_error(ecode, CPL_ERROR_NULL_INPUT); - - ecode = cpl_plugin_init(plgn1, - api1, - version1, - type1, - sname1, - ssynopsis1, - sdescription1, - sauthor1, - semail1, - scopyright1, - initialize1, - execute1, - deinitialize1); + ecode = cpl_plugin_init(NULL, api1, version1, type1, sname1, ssynopsis1, + sdescription1, sauthor1, semail1, scopyright1, + initialize1, execute1, deinitialize1); + cpl_test_eq_error(ecode, CPL_ERROR_NULL_INPUT); + + ecode = cpl_plugin_init(plgn1, api1, version1, type1, NULL, ssynopsis1, + sdescription1, sauthor1, semail1, scopyright1, + initialize1, execute1, deinitialize1); + cpl_test_eq_error(ecode, CPL_ERROR_NULL_INPUT); + + ecode = cpl_plugin_init(plgn1, api1, version1, type1, sname1, NULL, + sdescription1, sauthor1, semail1, scopyright1, + initialize1, execute1, deinitialize1); + cpl_test_eq_error(ecode, CPL_ERROR_NULL_INPUT); + + ecode = cpl_plugin_init(plgn1, api1, version1, type1, sname1, ssynopsis1, + NULL, sauthor1, semail1, scopyright1, initialize1, + execute1, deinitialize1); + cpl_test_eq_error(ecode, CPL_ERROR_NULL_INPUT); + + ecode = cpl_plugin_init(plgn1, api1, version1, type1, sname1, ssynopsis1, + sdescription1, NULL, semail1, scopyright1, + initialize1, execute1, deinitialize1); + cpl_test_eq_error(ecode, CPL_ERROR_NULL_INPUT); + + ecode = cpl_plugin_init(plgn1, api1, version1, type1, sname1, ssynopsis1, + sdescription1, sauthor1, NULL, scopyright1, + initialize1, execute1, deinitialize1); + cpl_test_eq_error(ecode, CPL_ERROR_NULL_INPUT); + + ecode = cpl_plugin_init(plgn1, api1, version1, type1, sname1, ssynopsis1, + sdescription1, sauthor1, semail1, NULL, initialize1, + execute1, deinitialize1); + cpl_test_eq_error(ecode, CPL_ERROR_NULL_INPUT); + + ecode = cpl_plugin_init(plgn1, api1, version1, type1, sname1, ssynopsis1, + sdescription1, sauthor1, semail1, scopyright1, + initialize1, execute1, deinitialize1); cpl_test_eq_error(ecode, CPL_ERROR_NONE); /* PLUGIN API */ - aapi1 = cpl_plugin_get_api(plgn1); + aapi1 = cpl_plugin_get_api(plgn1); cpl_test_eq(aapi1, api1); /* PLUGIN VERSION */ - aversion1 = cpl_plugin_get_version(plgn1); + aversion1 = cpl_plugin_get_version(plgn1); cpl_test_eq(aversion1, version1); asversion1 = cpl_plugin_get_version_string(plgn1); @@ -486,69 +392,69 @@ /* PLUGIN TYPE */ - atype1 = cpl_plugin_get_type(plgn1); + atype1 = cpl_plugin_get_type(plgn1); cpl_test_eq(atype1, type1); astype1 = cpl_plugin_get_type_string(plgn1); - cpl_test_noneq_ptr(stype1,astype1); - cpl_test_eq_string(stype1,astype1); + cpl_test_noneq_ptr(stype1, astype1); + cpl_test_eq_string(stype1, astype1); cpl_free(astype1); /* PLUGIN NAME */ - asname1 = cpl_plugin_get_name(plgn1); + asname1 = cpl_plugin_get_name(plgn1); cpl_test_noneq_ptr(sname1, asname1); cpl_test_eq_string(sname1, asname1); /* PLUGIN SYNOPSIS */ - assynopsis1 = cpl_plugin_get_synopsis(plgn1); + assynopsis1 = cpl_plugin_get_synopsis(plgn1); cpl_test_noneq_ptr(ssynopsis1, assynopsis1); cpl_test_eq_string(ssynopsis1, assynopsis1); /* PLUGIN DESCRIPTION */ - asdescription1 = cpl_plugin_get_description(plgn1); + asdescription1 = cpl_plugin_get_description(plgn1); cpl_test_noneq_ptr(sdescription1, asdescription1); cpl_test_eq_string(sdescription1, asdescription1); /* PLUGIN AUTHOR */ - asauthor1 = cpl_plugin_get_author(plgn1); + asauthor1 = cpl_plugin_get_author(plgn1); cpl_test_noneq_ptr(sauthor1, asauthor1); cpl_test_eq_string(sauthor1, asauthor1); /* PLUGIN EMAIL */ - asemail1 = cpl_plugin_get_email(plgn1); - cpl_test_noneq_ptr(semail1,asemail1); - cpl_test_eq_string(semail1,asemail1); + asemail1 = cpl_plugin_get_email(plgn1); + cpl_test_noneq_ptr(semail1, asemail1); + cpl_test_eq_string(semail1, asemail1); /* PLUGIN COPYRIGHT */ - ascopyright1 = cpl_plugin_get_copyright(plgn1); + ascopyright1 = cpl_plugin_get_copyright(plgn1); cpl_test_noneq_ptr(scopyright1, ascopyright1); cpl_test_eq_string(scopyright1, ascopyright1); /* PLUGIN INITIALIZE */ - ainitialize1 = cpl_plugin_get_init(plgn1); + ainitialize1 = cpl_plugin_get_init(plgn1); cpl_test(ainitialize1 == initialize1); /* PLUGIN EXECUTE */ - aexecute1 = cpl_plugin_get_exec(plgn1); + aexecute1 = cpl_plugin_get_exec(plgn1); cpl_test(aexecute1 == execute1); /* PLUGIN DEINITIALIZE */ - adeinitialize1 = cpl_plugin_get_deinit(plgn1); + adeinitialize1 = cpl_plugin_get_deinit(plgn1); cpl_test(adeinitialize1 == deinitialize1); cpl_plugin_dump(NULL, stream); @@ -559,13 +465,12 @@ cpl_plugin_delete(plgn1); - if (stream != stdout) cpl_test_zero( fclose(stream) ); + if (stream != stdout) + cpl_test_zero(fclose(stream)); /* * All tests succeeded */ return cpl_test_end(0); - } - diff -Nru cpl-7.1.4+ds/cplui/tests/cpl_recipeconfig-test.c cpl-7.2.2+ds/cplui/tests/cpl_recipeconfig-test.c --- cpl-7.1.4+ds/cplui/tests/cpl_recipeconfig-test.c 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplui/tests/cpl_recipeconfig-test.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -27,43 +27,34 @@ /* Needed for cx_strfreev() */ #include "cxstrutils.h" -int main(void) +int +main(void) { - - char** tags = NULL; + char **tags = NULL; int status = 0; - cpl_recipeconfig* config = NULL; + cpl_recipeconfig *config = NULL; + + const cpl_framedata frames[] = { { "frameA", 1, 5 }, + { "frameB", 0, -1 }, + { NULL, 0, 0 } }; + + const cpl_framedata inputs[] = { { "inputA", 1, -1 }, + { "inputB", 0, -1 }, + { "inputC", -1, -1 }, + { NULL, 0, 0 } }; + + const cpl_framedata _inputs[] = { { "inputD", 0, 3 }, + { "inputE", 1, 1 }, + { "inputF", 1, -1 }, + { NULL, 0, 0 } }; + + const char *outputs[] = { "outputA", "outputB", "outputC", NULL }; - const cpl_framedata frames[] = { - {"frameA", 1, 5}, - {"frameB", 0, -1}, - {NULL, 0, 0} - }; - - const cpl_framedata inputs[] = { - {"inputA", 1, -1}, - {"inputB", 0, -1}, - {"inputC", -1, -1}, - {NULL, 0, 0} - }; - - const cpl_framedata _inputs[] = { - {"inputD", 0, 3}, - {"inputE", 1, 1}, - {"inputF", 1, -1}, - {NULL, 0, 0} - }; - - const char* outputs[] = {"outputA", "outputB", "outputC", NULL}; - - const cpl_framedata bad[] = { - {"", 1, 3}, - {NULL, 0, 0} - }; + const cpl_framedata bad[] = { { "", 1, 3 }, { NULL, 0, 0 } }; - const char* _bad[] = {"outputA", "", "outputC", NULL}; + const char *_bad[] = { "outputA", "", "outputC", NULL }; cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); @@ -80,7 +71,7 @@ cpl_test_nonnull(tags); cpl_test_null(tags[0]); - cx_strfreev((cxchar**)tags); + cx_strfreev((cxchar **)tags); tags = NULL; cpl_recipeconfig_delete(config); @@ -104,13 +95,16 @@ cpl_test_eq_string(tags[0], frames[0].tag); cpl_test_null(tags[1]); cpl_test_eq(cpl_recipeconfig_get_min_count(config, frames[0].tag, - frames[0].tag), 1); + frames[0].tag), + 1); cpl_test_eq(cpl_recipeconfig_get_max_count(config, frames[0].tag, - frames[0].tag), -1); + frames[0].tag), + -1); cpl_test_eq(cpl_recipeconfig_is_required(config, frames[0].tag, - frames[0].tag), 1); + frames[0].tag), + 1); - cx_strfreev((cxchar**)tags); + cx_strfreev((cxchar **)tags); tags = NULL; cpl_recipeconfig_delete(config); @@ -135,7 +129,7 @@ cpl_test_nonnull(tags); cpl_test_null(tags[0]); - cx_strfreev((cxchar**)tags); + cx_strfreev((cxchar **)tags); tags = NULL; cpl_recipeconfig_delete(config); @@ -155,13 +149,13 @@ cpl_test_error(CPL_ERROR_NONE); cpl_test_zero(status); - status = cpl_recipeconfig_set_input(config, frames[0].tag, - inputs[0].tag, 2, 5); + status = + cpl_recipeconfig_set_input(config, frames[0].tag, inputs[0].tag, 2, 5); cpl_test_error(CPL_ERROR_NONE); cpl_test_zero(status); - status = cpl_recipeconfig_set_input(config, frames[0].tag, - inputs[1].tag, 0, -1); + status = + cpl_recipeconfig_set_input(config, frames[0].tag, inputs[1].tag, 0, -1); cpl_test_error(CPL_ERROR_NONE); cpl_test_zero(status); @@ -181,21 +175,25 @@ cpl_test_nonnull(tags); cpl_test_eq_string(tags[0], inputs[0].tag); cpl_test_eq(cpl_recipeconfig_get_min_count(config, frames[0].tag, - inputs[0].tag), 2); + inputs[0].tag), + 2); cpl_test_eq(cpl_recipeconfig_get_max_count(config, frames[0].tag, - inputs[0].tag), 5); + inputs[0].tag), + 5); cpl_test_eq(cpl_recipeconfig_is_required(config, frames[0].tag, - inputs[0].tag), 1); + inputs[0].tag), + 1); cpl_test_eq_string(tags[1], inputs[1].tag); - cpl_test_zero(cpl_recipeconfig_get_min_count(config, frames[0].tag, - inputs[1].tag)); + cpl_test_zero( + cpl_recipeconfig_get_min_count(config, frames[0].tag, inputs[1].tag)); cpl_test_eq(cpl_recipeconfig_get_max_count(config, frames[0].tag, - inputs[1].tag), -1); - cpl_test_zero(cpl_recipeconfig_is_required(config, frames[0].tag, - inputs[1].tag)); + inputs[1].tag), + -1); + cpl_test_zero( + cpl_recipeconfig_is_required(config, frames[0].tag, inputs[1].tag)); - cx_strfreev((cxchar**)tags); + cx_strfreev((cxchar **)tags); tags = NULL; tags = cpl_recipeconfig_get_outputs(config, frames[0].tag); @@ -204,7 +202,7 @@ cpl_test_eq_string(tags[1], outputs[1]); cpl_test_eq_string(tags[2], outputs[2]); - cx_strfreev((cxchar**)tags); + cx_strfreev((cxchar **)tags); tags = NULL; cpl_recipeconfig_delete(config); @@ -224,43 +222,53 @@ cpl_test_error(CPL_ERROR_NONE); cpl_test_zero(status); cpl_test_eq(cpl_recipeconfig_get_min_count(config, frames[0].tag, - frames[0].tag), 1); + frames[0].tag), + 1); cpl_test_eq(cpl_recipeconfig_get_max_count(config, frames[0].tag, - frames[0].tag), -1); + frames[0].tag), + -1); cpl_test_eq(cpl_recipeconfig_is_required(config, frames[0].tag, - frames[0].tag), 1); + frames[0].tag), + 1); - status = cpl_recipeconfig_set_input(config, frames[0].tag, - inputs[0].tag, 0, 5); + status = + cpl_recipeconfig_set_input(config, frames[0].tag, inputs[0].tag, 0, 5); cpl_test_error(CPL_ERROR_NONE); cpl_test_zero(status); - cpl_test_zero(cpl_recipeconfig_get_min_count(config, frames[0].tag, - inputs[0].tag)); + cpl_test_zero( + cpl_recipeconfig_get_min_count(config, frames[0].tag, inputs[0].tag)); cpl_test_eq(cpl_recipeconfig_get_max_count(config, frames[0].tag, - inputs[0].tag), 5); - cpl_test_zero(cpl_recipeconfig_is_required(config, frames[0].tag, - inputs[0].tag)); + inputs[0].tag), + 5); + cpl_test_zero( + cpl_recipeconfig_is_required(config, frames[0].tag, inputs[0].tag)); status = cpl_recipeconfig_set_tag(config, frames[0].tag, 2, 5); cpl_test_error(CPL_ERROR_NONE); cpl_test_zero(status); cpl_test_eq(cpl_recipeconfig_get_min_count(config, frames[0].tag, - frames[0].tag), 2); + frames[0].tag), + 2); cpl_test_eq(cpl_recipeconfig_get_max_count(config, frames[0].tag, - frames[0].tag), 5); + frames[0].tag), + 5); cpl_test_eq(cpl_recipeconfig_is_required(config, frames[0].tag, - frames[0].tag), 1); + frames[0].tag), + 1); - status = cpl_recipeconfig_set_input(config, frames[0].tag, - inputs[0].tag, 1, -1); + status = + cpl_recipeconfig_set_input(config, frames[0].tag, inputs[0].tag, 1, -1); cpl_test_error(CPL_ERROR_NONE); cpl_test_zero(status); cpl_test_eq(cpl_recipeconfig_get_min_count(config, frames[0].tag, - inputs[0].tag), 1); + inputs[0].tag), + 1); cpl_test_eq(cpl_recipeconfig_get_max_count(config, frames[0].tag, - inputs[0].tag), -1); + inputs[0].tag), + -1); cpl_test_eq(cpl_recipeconfig_is_required(config, frames[0].tag, - inputs[0].tag), 1); + inputs[0].tag), + 1); cpl_recipeconfig_delete(config); config = NULL; @@ -301,7 +309,7 @@ frames[1].tag), (frames[1].min_count > 0)); - cx_strfreev((cxchar**)tags); + cx_strfreev((cxchar **)tags); tags = NULL; status = cpl_recipeconfig_set_inputs(config, frames[0].tag, inputs); @@ -314,7 +322,7 @@ cpl_test_eq_string(tags[2], inputs[2].tag); cpl_test_null(tags[3]); - cx_strfreev((cxchar**)tags); + cx_strfreev((cxchar **)tags); tags = NULL; status = cpl_recipeconfig_set_outputs(config, frames[0].tag, outputs); @@ -327,7 +335,7 @@ cpl_test_eq_string(tags[2], outputs[2]); cpl_test_null(tags[3]); - cx_strfreev((cxchar**)tags); + cx_strfreev((cxchar **)tags); tags = NULL; status = cpl_recipeconfig_set_inputs(config, frames[1].tag, _inputs); @@ -340,7 +348,7 @@ cpl_test_eq_string(tags[2], _inputs[2].tag); cpl_test_null(tags[3]); - cx_strfreev((cxchar**)tags); + cx_strfreev((cxchar **)tags); tags = NULL; status = cpl_recipeconfig_set_outputs(config, frames[1].tag, outputs); @@ -353,7 +361,7 @@ cpl_test_eq_string(tags[2], outputs[2]); cpl_test_null(tags[3]); - cx_strfreev((cxchar**)tags); + cx_strfreev((cxchar **)tags); tags = NULL; cpl_recipeconfig_delete(config); @@ -461,109 +469,92 @@ cpl_test_error(CPL_ERROR_DATA_NOT_FOUND); - status = cpl_recipeconfig_get_min_count(NULL, frames[0].tag, - inputs[0].tag); + status = cpl_recipeconfig_get_min_count(NULL, frames[0].tag, inputs[0].tag); cpl_test_error(CPL_ERROR_NULL_INPUT); cpl_test_eq(status, -1); - status = cpl_recipeconfig_get_min_count(config, NULL, - inputs[0].tag); + status = cpl_recipeconfig_get_min_count(config, NULL, inputs[0].tag); cpl_test_error(CPL_ERROR_NULL_INPUT); cpl_test_eq(status, -1); - status = cpl_recipeconfig_get_min_count(config, "", - inputs[0].tag); + status = cpl_recipeconfig_get_min_count(config, "", inputs[0].tag); cpl_test_error(CPL_ERROR_DATA_NOT_FOUND); cpl_test_eq(status, -1); - status = cpl_recipeconfig_get_min_count(config, frames[1].tag, - inputs[0].tag); + status = + cpl_recipeconfig_get_min_count(config, frames[1].tag, inputs[0].tag); cpl_test_error(CPL_ERROR_DATA_NOT_FOUND); cpl_test_eq(status, -1); - status = cpl_recipeconfig_get_min_count(config, frames[0].tag, - NULL); + status = cpl_recipeconfig_get_min_count(config, frames[0].tag, NULL); cpl_test_error(CPL_ERROR_NULL_INPUT); cpl_test_eq(status, -1); - status = cpl_recipeconfig_get_min_count(config, frames[0].tag, - ""); + status = cpl_recipeconfig_get_min_count(config, frames[0].tag, ""); cpl_test_error(CPL_ERROR_DATA_NOT_FOUND); cpl_test_eq(status, -1); - status = cpl_recipeconfig_get_min_count(config, frames[0].tag, - inputs[1].tag); + status = + cpl_recipeconfig_get_min_count(config, frames[0].tag, inputs[1].tag); cpl_test_error(CPL_ERROR_DATA_NOT_FOUND); cpl_test_eq(status, -1); - status = cpl_recipeconfig_get_max_count(NULL, frames[0].tag, - inputs[0].tag); + status = cpl_recipeconfig_get_max_count(NULL, frames[0].tag, inputs[0].tag); cpl_test_error(CPL_ERROR_NULL_INPUT); cpl_test_eq(status, -1); - status = cpl_recipeconfig_get_max_count(config, NULL, - inputs[0].tag); + status = cpl_recipeconfig_get_max_count(config, NULL, inputs[0].tag); cpl_test_error(CPL_ERROR_NULL_INPUT); cpl_test_eq(status, -1); - status = cpl_recipeconfig_get_max_count(config, "", - inputs[0].tag); + status = cpl_recipeconfig_get_max_count(config, "", inputs[0].tag); cpl_test_error(CPL_ERROR_DATA_NOT_FOUND); cpl_test_eq(status, -1); - status = cpl_recipeconfig_get_max_count(config, frames[1].tag, - inputs[0].tag); + status = + cpl_recipeconfig_get_max_count(config, frames[1].tag, inputs[0].tag); cpl_test_error(CPL_ERROR_DATA_NOT_FOUND); cpl_test_eq(status, -1); - status = cpl_recipeconfig_get_max_count(config, frames[0].tag, - NULL); + status = cpl_recipeconfig_get_max_count(config, frames[0].tag, NULL); cpl_test_error(CPL_ERROR_NULL_INPUT); cpl_test_eq(status, -1); - status = cpl_recipeconfig_get_max_count(config, frames[0].tag, - ""); + status = cpl_recipeconfig_get_max_count(config, frames[0].tag, ""); cpl_test_error(CPL_ERROR_DATA_NOT_FOUND); cpl_test_eq(status, -1); - status = cpl_recipeconfig_get_max_count(config, frames[0].tag, - inputs[1].tag); + status = + cpl_recipeconfig_get_max_count(config, frames[0].tag, inputs[1].tag); cpl_test_error(CPL_ERROR_DATA_NOT_FOUND); cpl_test_eq(status, -1); - status = cpl_recipeconfig_is_required(NULL, frames[0].tag, - inputs[0].tag); + status = cpl_recipeconfig_is_required(NULL, frames[0].tag, inputs[0].tag); cpl_test_error(CPL_ERROR_NULL_INPUT); cpl_test_eq(status, -1); - status = cpl_recipeconfig_is_required(config, NULL, - inputs[0].tag); + status = cpl_recipeconfig_is_required(config, NULL, inputs[0].tag); cpl_test_error(CPL_ERROR_NULL_INPUT); cpl_test_eq(status, -1); - status = cpl_recipeconfig_is_required(config, "", - inputs[0].tag); + status = cpl_recipeconfig_is_required(config, "", inputs[0].tag); cpl_test_error(CPL_ERROR_DATA_NOT_FOUND); cpl_test_eq(status, -1); - status = cpl_recipeconfig_is_required(config, frames[1].tag, - inputs[0].tag); + status = cpl_recipeconfig_is_required(config, frames[1].tag, inputs[0].tag); cpl_test_error(CPL_ERROR_DATA_NOT_FOUND); cpl_test_eq(status, -1); - status = cpl_recipeconfig_is_required(config, frames[0].tag, - NULL); + status = cpl_recipeconfig_is_required(config, frames[0].tag, NULL); cpl_test_error(CPL_ERROR_NULL_INPUT); cpl_test_eq(status, -1); - status = cpl_recipeconfig_is_required(config, frames[0].tag, - ""); + status = cpl_recipeconfig_is_required(config, frames[0].tag, ""); cpl_test_error(CPL_ERROR_DATA_NOT_FOUND); cpl_test_eq(status, -1); - status = cpl_recipeconfig_is_required(config, frames[0].tag, - inputs[1].tag); + status = cpl_recipeconfig_is_required(config, frames[0].tag, inputs[1].tag); cpl_test_error(CPL_ERROR_DATA_NOT_FOUND); cpl_test_eq(status, -1); @@ -581,18 +572,16 @@ cpl_test_eq(status, -1); - status = cpl_recipeconfig_set_input(NULL, frames[0].tag, inputs[0].tag, - -1, -1); + status = + cpl_recipeconfig_set_input(NULL, frames[0].tag, inputs[0].tag, -1, -1); cpl_test_error(CPL_ERROR_NULL_INPUT); cpl_test_eq(status, -1); - status = cpl_recipeconfig_set_input(config, NULL, inputs[0].tag, - -1, -1); + status = cpl_recipeconfig_set_input(config, NULL, inputs[0].tag, -1, -1); cpl_test_error(CPL_ERROR_NULL_INPUT); cpl_test_eq(status, -1); - status = cpl_recipeconfig_set_input(config, "", inputs[0].tag, - -1, -1); + status = cpl_recipeconfig_set_input(config, "", inputs[0].tag, -1, -1); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); cpl_test_eq(status, -1); @@ -601,13 +590,11 @@ cpl_test_error(CPL_ERROR_DATA_NOT_FOUND); cpl_test_eq(status, 2); - status = cpl_recipeconfig_set_input(config, frames[0].tag, NULL, - -1, -1); + status = cpl_recipeconfig_set_input(config, frames[0].tag, NULL, -1, -1); cpl_test_error(CPL_ERROR_NULL_INPUT); cpl_test_eq(status, -1); - status = cpl_recipeconfig_set_input(config, frames[0].tag, "", - -1, -1); + status = cpl_recipeconfig_set_input(config, frames[0].tag, "", -1, -1); cpl_test_error(CPL_ERROR_ILLEGAL_INPUT); cpl_test_eq(status, -1); @@ -709,5 +696,4 @@ */ return cpl_test_end(0); - } diff -Nru cpl-7.1.4+ds/cplui/tests/cpl_recipedefine-test.c cpl-7.2.2+ds/cplui/tests/cpl_recipedefine-test.c --- cpl-7.1.4+ds/cplui/tests/cpl_recipedefine-test.c 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplui/tests/cpl_recipedefine-test.c 2022-04-29 14:56:02.000000000 +0000 @@ -1,6 +1,6 @@ /* * This file is part of the ESO Common Pipeline Library - * Copyright (C) 2001-2017 European Southern Observatory + * Copyright (C) 2001-2022 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 @@ -25,9 +25,13 @@ ----------------------------------------------------------------------------*/ static void cpl_recipedefine_test(cpl_pluginlist *); -cpl_recipe_define(my_recipe, 10101, - "Fname Lname", PACKAGE_BUGREPORT, "2008", - "Test recipe", "Description of test recipe"); +cpl_recipe_define(my_recipe, + 10101, + "Fname Lname", + PACKAGE_BUGREPORT, + "2008", + "Test recipe", + "Description of test recipe"); /* Enable my_recipe_fill_parameterlist() to either pass or fail */ static cpl_error_code fill_status = CPL_ERROR_NONE; @@ -36,10 +40,10 @@ Main -----------------------------------------------------------------------------*/ -int main(void) +int +main(void) { - - cpl_pluginlist * pluginlist; + cpl_pluginlist *pluginlist; int error; cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING); @@ -60,13 +64,12 @@ return cpl_test_end(0); } -static cpl_error_code my_recipe_fill_parameterlist(cpl_parameterlist * self) +static cpl_error_code +my_recipe_fill_parameterlist(cpl_parameterlist *self) { - cpl_test_nonnull(self); return fill_status; - } @@ -79,9 +82,9 @@ */ /*----------------------------------------------------------------------------*/ -static int my_recipe(cpl_frameset * frameset, const cpl_parameterlist * plist) +static int +my_recipe(cpl_frameset *frameset, const cpl_parameterlist *plist) { - /* The recipe definition ensures that the actual recipe execution is done with non-NULL parameters */ @@ -89,7 +92,6 @@ cpl_test_nonnull(plist); return 0; - } @@ -101,28 +103,28 @@ */ /*----------------------------------------------------------------------------*/ -static void cpl_recipedefine_test(cpl_pluginlist * self) +static void +cpl_recipedefine_test(cpl_pluginlist *self) { - - cpl_plugin * plugin; - cpl_recipe * recipe; - int (*recipe_create) (cpl_plugin *); - int (*recipe_exec ) (cpl_plugin *); - int (*recipe_deinit) (cpl_plugin *); + cpl_plugin *plugin; + cpl_recipe *recipe; + int (*recipe_create)(cpl_plugin *); + int (*recipe_exec)(cpl_plugin *); + int (*recipe_deinit)(cpl_plugin *); cpl_errorstate prestate = cpl_errorstate_get(); - int error; - FILE * stream = cpl_msg_get_level() > CPL_MSG_INFO - ? fopen("/dev/null", "a") : stdout; + int error; + FILE *stream = + cpl_msg_get_level() > CPL_MSG_INFO ? fopen("/dev/null", "a") : stdout; plugin = cpl_pluginlist_get_first(self); - recipe = (cpl_recipe *) plugin; + recipe = (cpl_recipe *)plugin; cpl_test_nonnull(plugin); cpl_plugin_dump(plugin, stream); recipe_create = cpl_plugin_get_init(plugin); - recipe_exec = cpl_plugin_get_exec(plugin); + recipe_exec = cpl_plugin_get_exec(plugin); recipe_deinit = cpl_plugin_get_deinit(plugin); /* Only plugins of type recipe are defined */ @@ -139,13 +141,13 @@ recipe->frames = NULL; /* Execute recipe */ - cpl_test( recipe_exec(plugin) ); + cpl_test(recipe_exec(plugin)); /* Expect the errorstate to change */ - cpl_test_zero( cpl_errorstate_is_equal(prestate) ); + cpl_test_zero(cpl_errorstate_is_equal(prestate)); /* ... and the error code to not change */ - cpl_test_error( CPL_ERROR_NULL_INPUT ); + cpl_test_error(CPL_ERROR_NULL_INPUT); /* Test 2: Check handling of pre-existing error code */ @@ -154,26 +156,26 @@ cpl_error_set(cpl_func, CPL_ERROR_EOL); prestate = cpl_errorstate_get(); /* Execute recipe */ - cpl_test( recipe_exec(plugin) ); + cpl_test(recipe_exec(plugin)); /* Expect the errorstate to change */ - cpl_test_zero( cpl_errorstate_is_equal(prestate) ); + cpl_test_zero(cpl_errorstate_is_equal(prestate)); /* ... and the error code to not change */ - cpl_test_error( CPL_ERROR_EOL ); + cpl_test_error(CPL_ERROR_EOL); /* Test 3: Check success on empty frameset */ /* Execute recipe */ - cpl_test_zero( recipe_exec(plugin) ); + cpl_test_zero(recipe_exec(plugin)); /* Expect the error code to not change */ - cpl_test_error( CPL_ERROR_NONE ); + cpl_test_error(CPL_ERROR_NONE); cpl_frameset_delete(recipe->frames); - cpl_test_zero(recipe_deinit(plugin) ); + cpl_test_zero(recipe_deinit(plugin)); /* Test 4: Check failure on failed parameterlist fill */ @@ -181,12 +183,12 @@ error = recipe_create(plugin); - cpl_test_error( error ); + cpl_test_error(error); - cpl_test_zero(recipe_deinit(plugin) ); + cpl_test_zero(recipe_deinit(plugin)); - if (stream != stdout) cpl_test_zero( fclose(stream) ); + if (stream != stdout) + cpl_test_zero(fclose(stream)); return; - } diff -Nru cpl-7.1.4+ds/cplui/tests/Makefile.am cpl-7.2.2+ds/cplui/tests/Makefile.am --- cpl-7.1.4+ds/cplui/tests/Makefile.am 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/cplui/tests/Makefile.am 2022-04-29 14:56:02.000000000 +0000 @@ -1,7 +1,7 @@ ## Process this file with automake to produce Makefile.in ## This file is part of the ESO Common Pipeline Library -## Copyright (C) 2001-2017 European Southern Observatory +## Copyright (C) 2001-2022 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 diff -Nru cpl-7.1.4+ds/cplui/tests/Makefile.in cpl-7.2.2+ds/cplui/tests/Makefile.in --- cpl-7.1.4+ds/cplui/tests/Makefile.in 2021-05-07 12:10:11.000000000 +0000 +++ cpl-7.2.2+ds/cplui/tests/Makefile.in 2022-04-29 14:56:28.000000000 +0000 @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.15.1 from Makefile.am. +# Makefile.in generated by automake 1.16.3 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2017 Free Software Foundation, Inc. +# Copyright (C) 1994-2020 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -192,7 +192,17 @@ am__v_at_1 = DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) depcomp = $(SHELL) $(top_srcdir)/admin/depcomp -am__depfiles_maybe = depfiles +am__maybe_remake_depfiles = depfiles +am__depfiles_remade = ./$(DEPDIR)/cpl_frame-test.Po \ + ./$(DEPDIR)/cpl_framedata-test.Po \ + ./$(DEPDIR)/cpl_frameset-test.Po \ + ./$(DEPDIR)/cpl_frameset_io-test.Po \ + ./$(DEPDIR)/cpl_parameter-test.Po \ + ./$(DEPDIR)/cpl_parameterlist-test.Po \ + ./$(DEPDIR)/cpl_plugin-test.Po \ + ./$(DEPDIR)/cpl_pluginlist-test.Po \ + ./$(DEPDIR)/cpl_recipeconfig-test.Po \ + ./$(DEPDIR)/cpl_recipedefine-test.Po am__mv = mv -f COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) @@ -432,6 +442,7 @@ bases='$(TEST_LOGS)'; \ bases=`for i in $$bases; do echo $$i; done | sed 's/\.log$$//'`; \ bases=`echo $$bases` +AM_TESTSUITE_SUMMARY_HEADER = ' for $(PACKAGE_STRING)' RECHECK_LOGS = $(TEST_LOGS) AM_RECURSIVE_TARGETS = check recheck TEST_SUITE_LOG = test-suite.log @@ -475,6 +486,7 @@ CPLCORE_INCLUDES = @CPLCORE_INCLUDES@ CPLDFS_INCLUDES = @CPLDFS_INCLUDES@ CPLDRS_INCLUDES = @CPLDRS_INCLUDES@ +CPLJAVA_INCLUDES = @CPLJAVA_INCLUDES@ CPLUI_INCLUDES = @CPLUI_INCLUDES@ CPL_BINARY_AGE = @CPL_BINARY_AGE@ CPL_BINARY_VERSION = @CPL_BINARY_VERSION@ @@ -535,6 +547,7 @@ LIBCPLCORE = @LIBCPLCORE@ LIBCPLDFS = @LIBCPLDFS@ LIBCPLDRS = @LIBCPLDRS@ +LIBCPLGASGANO = @LIBCPLGASGANO@ LIBCPLUI = @LIBCPLUI@ LIBFFTW = @LIBFFTW@ LIBFFTWF = @LIBFFTWF@ @@ -641,6 +654,7 @@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ @@ -697,8 +711,8 @@ *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);; \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ esac; $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) @@ -765,16 +779,22 @@ distclean-compile: -rm -f *.tab.c -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_frame-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_framedata-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_frameset-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_frameset_io-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_parameter-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_parameterlist-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_plugin-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_pluginlist-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_recipeconfig-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_recipedefine-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_frame-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_framedata-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_frameset-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_frameset_io-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_parameter-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_parameterlist-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_plugin-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_pluginlist-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_recipeconfig-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpl_recipedefine-test.Po@am__quote@ # am--include-marker + +$(am__depfiles_remade): + @$(MKDIR_P) $(@D) + @echo '# dummy' >$@-t && $(am__mv) $@-t $@ + +am--depfiles: $(am__depfiles_remade) .c.o: @am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @@ -962,7 +982,7 @@ test x"$$VERBOSE" = x || cat $(TEST_SUITE_LOG); \ fi; \ echo "$${col}$$br$${std}"; \ - echo "$${col}Testsuite summary for $(PACKAGE_STRING)$${std}"; \ + echo "$${col}Testsuite summary"$(AM_TESTSUITE_SUMMARY_HEADER)"$${std}"; \ echo "$${col}$$br$${std}"; \ create_testsuite_report --maybe-color; \ echo "$$col$$br$$std"; \ @@ -975,7 +995,7 @@ fi; \ $$success || exit 1 -check-TESTS: +check-TESTS: $(check_PROGRAMS) @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) @@ -1081,7 +1101,10 @@ @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) +distdir: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) distdir-am + +distdir-am: $(DISTFILES) @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ list='$(DISTFILES)'; \ @@ -1158,7 +1181,16 @@ mostlyclean-am distclean: distclean-am - -rm -rf ./$(DEPDIR) + -rm -f ./$(DEPDIR)/cpl_frame-test.Po + -rm -f ./$(DEPDIR)/cpl_framedata-test.Po + -rm -f ./$(DEPDIR)/cpl_frameset-test.Po + -rm -f ./$(DEPDIR)/cpl_frameset_io-test.Po + -rm -f ./$(DEPDIR)/cpl_parameter-test.Po + -rm -f ./$(DEPDIR)/cpl_parameterlist-test.Po + -rm -f ./$(DEPDIR)/cpl_plugin-test.Po + -rm -f ./$(DEPDIR)/cpl_pluginlist-test.Po + -rm -f ./$(DEPDIR)/cpl_recipeconfig-test.Po + -rm -f ./$(DEPDIR)/cpl_recipedefine-test.Po -rm -f Makefile distclean-am: clean-am distclean-compile distclean-generic \ distclean-tags @@ -1204,7 +1236,16 @@ installcheck-am: maintainer-clean: maintainer-clean-am - -rm -rf ./$(DEPDIR) + -rm -f ./$(DEPDIR)/cpl_frame-test.Po + -rm -f ./$(DEPDIR)/cpl_framedata-test.Po + -rm -f ./$(DEPDIR)/cpl_frameset-test.Po + -rm -f ./$(DEPDIR)/cpl_frameset_io-test.Po + -rm -f ./$(DEPDIR)/cpl_parameter-test.Po + -rm -f ./$(DEPDIR)/cpl_parameterlist-test.Po + -rm -f ./$(DEPDIR)/cpl_plugin-test.Po + -rm -f ./$(DEPDIR)/cpl_pluginlist-test.Po + -rm -f ./$(DEPDIR)/cpl_recipeconfig-test.Po + -rm -f ./$(DEPDIR)/cpl_recipedefine-test.Po -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic @@ -1225,19 +1266,20 @@ .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 +.PHONY: CTAGS GTAGS TAGS all all-am am--depfiles 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 diff -Nru cpl-7.1.4+ds/debian/changelog cpl-7.2.2+ds/debian/changelog --- cpl-7.1.4+ds/debian/changelog 2021-08-16 18:31:20.000000000 +0000 +++ cpl-7.2.2+ds/debian/changelog 2022-05-11 19:08:33.000000000 +0000 @@ -1,3 +1,12 @@ +cpl (7.2.2+ds-1) unstable; urgency=medium + + * New upstream version 7.2.2+ds + * Rediff patches + * Push Standards-Version to 4.6.0. No changes needed. + * Add new symbols to symbol table + + -- Ole Streicher Wed, 11 May 2022 21:08:33 +0200 + cpl (7.1.4+ds-1) unstable; urgency=medium * Remove prebuilt html files from sources diff -Nru cpl-7.1.4+ds/debian/control cpl-7.2.2+ds/debian/control --- cpl-7.1.4+ds/debian/control 2021-08-16 18:19:27.000000000 +0000 +++ cpl-7.2.2+ds/debian/control 2022-05-11 19:02:50.000000000 +0000 @@ -11,7 +11,7 @@ libltdl-dev, texlive-fonts-recommended, wcslib-dev -Standards-Version: 4.5.1 +Standards-Version: 4.6.0 Vcs-Browser: https://salsa.debian.org/debian-astro-team/cpl Vcs-Git: https://salsa.debian.org/debian-astro-team/cpl.git Homepage: https://www.eso.org/sci/software/cpl/ diff -Nru cpl-7.1.4+ds/debian/libcplcore26.symbols cpl-7.2.2+ds/debian/libcplcore26.symbols --- cpl-7.1.4+ds/debian/libcplcore26.symbols 2020-06-26 07:25:13.000000000 +0000 +++ cpl-7.2.2+ds/debian/libcplcore26.symbols 2022-05-11 19:08:26.000000000 +0000 @@ -375,6 +375,7 @@ cpl_fft_image_cycle@Base 7.1 cpl_fits_add_properties@Base 6.0 cpl_fits_count_extensions@Base 6.0 + cpl_fits_fill_card@Base 7.2.2 cpl_fits_find_extension@Base 6.0 cpl_fits_get_extension_nb@Base 6.0 cpl_fits_get_mode@Base 6.1.1 @@ -599,7 +600,9 @@ cpl_io_fits_end@Base 6.0 cpl_io_fits_init@Base 6.0 cpl_io_fits_is_enabled@Base 6.0 + cpl_io_fits_is_open@Base 7.2.2 cpl_io_fits_open_diskfile@Base 6.0 + cpl_io_get_max_open@Base 7.2.2 cpl_malloc@Base 6.0 cpl_mask_and@Base 6.0 cpl_mask_closing@Base 6.0 @@ -668,8 +671,11 @@ cpl_matrix_flip_columns@Base 6.0 cpl_matrix_flip_rows@Base 6.0 cpl_matrix_get@Base 6.0 + cpl_matrix_get_@Base 7.2.2 cpl_matrix_get_data@Base 6.0 + cpl_matrix_get_data_@Base 7.2.2 cpl_matrix_get_data_const@Base 6.0 + cpl_matrix_get_data_const_@Base 7.2.2 cpl_matrix_get_determinant@Base 6.0 cpl_matrix_get_max@Base 6.0 cpl_matrix_get_maxpos@Base 6.0 @@ -678,7 +684,9 @@ cpl_matrix_get_min@Base 6.0 cpl_matrix_get_minpos@Base 6.0 cpl_matrix_get_ncol@Base 6.0 + cpl_matrix_get_ncol_@Base 7.2.2 cpl_matrix_get_nrow@Base 6.0 + cpl_matrix_get_nrow_@Base 7.2.2 cpl_matrix_get_stdev@Base 6.0 cpl_matrix_invert_create@Base 6.0 cpl_matrix_is_diagonal@Base 6.0 @@ -697,6 +705,7 @@ cpl_matrix_product_transpose@Base 6.0 cpl_matrix_resize@Base 6.0 cpl_matrix_set@Base 6.0 + cpl_matrix_set_@Base 7.2.2 cpl_matrix_set_size@Base 6.0 cpl_matrix_shift@Base 6.0 cpl_matrix_solve@Base 6.0 @@ -707,6 +716,7 @@ cpl_matrix_solve_normal@Base 6.0 cpl_matrix_solve_spd@Base 6.0 cpl_matrix_solve_svd@Base 7.1 + cpl_matrix_solve_svd_threshold@Base 7.2.2 cpl_matrix_sort_columns@Base 6.0 cpl_matrix_sort_rows@Base 6.0 cpl_matrix_subtract@Base 6.0 @@ -774,6 +784,8 @@ cpl_polynomial_eval@Base 6.0 cpl_polynomial_eval_1d@Base 6.0 cpl_polynomial_eval_1d_diff@Base 6.0 + cpl_polynomial_eval_2d@Base 7.2.2 + cpl_polynomial_eval_3d@Base 7.2.2 cpl_polynomial_eval_monomial@Base 7.1.2 cpl_polynomial_extract@Base 6.0 cpl_polynomial_fit@Base 6.0 @@ -826,6 +838,7 @@ cpl_property_set_long_long@Base 6.0 cpl_property_set_name@Base 6.0 cpl_property_set_name_cx@Base 7.1.2 + cpl_property_set_sortkey_@Base 7.2.2 cpl_property_set_string@Base 6.0 cpl_property_set_string_cx@Base 7.1.2 cpl_propertylist_append@Base 6.0 @@ -835,11 +848,13 @@ cpl_propertylist_append_double_complex@Base 6.0 cpl_propertylist_append_float@Base 6.0 cpl_propertylist_append_float_complex@Base 6.0 + cpl_propertylist_append_from_string@Base 7.2.2 cpl_propertylist_append_int@Base 6.0 cpl_propertylist_append_long@Base 6.0 cpl_propertylist_append_long_long@Base 6.0 cpl_propertylist_append_property@Base 6.0 cpl_propertylist_append_string@Base 6.0 + cpl_propertylist_copy_name_@Base 7.2.2 cpl_propertylist_copy_property@Base 6.0 cpl_propertylist_copy_property_regexp@Base 6.0 cpl_propertylist_delete@Base 6.0 @@ -848,6 +863,7 @@ cpl_propertylist_empty@Base 6.0 cpl_propertylist_erase@Base 6.0 cpl_propertylist_erase_cx@Base 7.1.2 + cpl_propertylist_erase_name_@Base 7.2.2 cpl_propertylist_erase_regexp@Base 6.0 cpl_propertylist_from_fitsfile@Base 6.0 cpl_propertylist_get@Base 6.0 @@ -855,6 +871,7 @@ cpl_propertylist_get_char@Base 6.0 cpl_propertylist_get_comment@Base 6.0 cpl_propertylist_get_const@Base 6.0 + cpl_propertylist_get_const_cx@Base 7.2.2 cpl_propertylist_get_double@Base 6.0 cpl_propertylist_get_double_complex@Base 6.0 cpl_propertylist_get_float@Base 6.0 @@ -920,6 +937,7 @@ cpl_propertylist_set_int@Base 6.0 cpl_propertylist_set_long@Base 6.0 cpl_propertylist_set_long_long@Base 6.0 + cpl_propertylist_set_property@Base 7.2.2 cpl_propertylist_set_string@Base 6.0 cpl_propertylist_sort@Base 6.0 cpl_propertylist_to_fitsfile@Base 6.0 @@ -933,6 +951,7 @@ cpl_propertylist_update_long@Base 6.0 cpl_propertylist_update_long_long@Base 6.0 cpl_propertylist_update_string@Base 6.0 + cpl_propertylist_update_string_@Base 7.2.2 cpl_realloc@Base 6.0 cpl_sprintf@Base 6.0 cpl_stats_delete@Base 6.0 diff -Nru cpl-7.1.4+ds/debian/libcplui26.symbols cpl-7.2.2+ds/debian/libcplui26.symbols --- cpl-7.1.4+ds/debian/libcplui26.symbols 2017-02-04 10:14:19.000000000 +0000 +++ cpl-7.2.2+ds/debian/libcplui26.symbols 2022-05-11 19:08:26.000000000 +0000 @@ -93,6 +93,7 @@ cpl_parameter_get_type@Base 6.0 cpl_parameter_is_enabled@Base 6.0 cpl_parameter_new_enum@Base 6.0 + cpl_parameter_new_enum_from_array@Base 7.2.2 cpl_parameter_new_range@Base 6.0 cpl_parameter_new_value@Base 6.0 cpl_parameter_set_alias@Base 6.0 diff -Nru cpl-7.1.4+ds/debian/patches/Don-t-run-a-loop-which-may-cause-unaligned-access-SIGBUS.patch cpl-7.2.2+ds/debian/patches/Don-t-run-a-loop-which-may-cause-unaligned-access-SIGBUS.patch --- cpl-7.1.4+ds/debian/patches/Don-t-run-a-loop-which-may-cause-unaligned-access-SIGBUS.patch 2021-08-16 18:20:47.000000000 +0000 +++ cpl-7.2.2+ds/debian/patches/Don-t-run-a-loop-which-may-cause-unaligned-access-SIGBUS.patch 2022-05-11 19:02:39.000000000 +0000 @@ -9,10 +9,10 @@ 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cplcore/cpl_mask.c b/cplcore/cpl_mask.c -index 4826648..ae1f533 100644 +index 3e6be96..213e761 100644 --- a/cplcore/cpl_mask.c +++ b/cplcore/cpl_mask.c -@@ -1120,7 +1120,7 @@ cpl_size cpl_mask_count_window(const cpl_mask * self, +@@ -1226,7 +1226,7 @@ cpl_mask_count_window(const cpl_mask *self, for (cpl_size j = lly - 1; j < ury; j++, pi += self->nx) { cpl_size i = llx - 1; @@ -20,4 +20,4 @@ +#if defined (CPL_MASK_WORD) && !defined(__arm__) && !defined(sparcv9) /* FIXME: Should really ensure byte-wise iteration to word-boundary */ for (; i < CPL_MIN(llx - 1 + CPL_MASK_PAD2WORD2(llx - 1), urx); i++) { - if (pi[i] != CPL_BINARY_0) count++; + if (pi[i] != CPL_BINARY_0) diff -Nru cpl-7.1.4+ds/debian/patches/Fix-angle-tolerance-in-i386.patch cpl-7.2.2+ds/debian/patches/Fix-angle-tolerance-in-i386.patch --- cpl-7.1.4+ds/debian/patches/Fix-angle-tolerance-in-i386.patch 2021-08-16 18:20:47.000000000 +0000 +++ cpl-7.2.2+ds/debian/patches/Fix-angle-tolerance-in-i386.patch 2022-05-11 19:02:39.000000000 +0000 @@ -16,10 +16,10 @@ 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpldrs/cpl_ppm.c b/cpldrs/cpl_ppm.c -index 803cf84..e4c3624 100644 +index 78aa692..ec16903 100644 --- a/cpldrs/cpl_ppm.c +++ b/cpldrs/cpl_ppm.c -@@ -1769,7 +1769,7 @@ cpl_ppm_match_points(const cpl_matrix *data, cpl_size use_data, double err_data, +@@ -1792,7 +1792,7 @@ cpl_ppm_match_points(const cpl_matrix *data, */ scale_tolerance = tolerance * median_scale; diff -Nru cpl-7.1.4+ds/debian/patches/Force-serial-tests-to-get-better-verbose-output.patch cpl-7.2.2+ds/debian/patches/Force-serial-tests-to-get-better-verbose-output.patch --- cpl-7.1.4+ds/debian/patches/Force-serial-tests-to-get-better-verbose-output.patch 2021-08-16 18:20:47.000000000 +0000 +++ cpl-7.2.2+ds/debian/patches/Force-serial-tests-to-get-better-verbose-output.patch 2022-05-11 19:02:39.000000000 +0000 @@ -11,7 +11,7 @@ 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cplcore/tests/Makefile.am b/cplcore/tests/Makefile.am -index 53725af..858a67c 100644 +index 850a661..18a132a 100644 --- a/cplcore/tests/Makefile.am +++ b/cplcore/tests/Makefile.am @@ -18,7 +18,7 @@ @@ -24,7 +24,7 @@ DISTCLEANFILES = *~ diff --git a/cpldfs/tests/Makefile.am b/cpldfs/tests/Makefile.am -index da5ca18..30b6e8a 100644 +index 4bb9520..11561eb 100644 --- a/cpldfs/tests/Makefile.am +++ b/cpldfs/tests/Makefile.am @@ -18,7 +18,7 @@ @@ -37,7 +37,7 @@ DISTCLEANFILES = *~ diff --git a/cpldrs/tests/Makefile.am b/cpldrs/tests/Makefile.am -index 56278f4..623def1 100644 +index 62a788c..ea6244a 100644 --- a/cpldrs/tests/Makefile.am +++ b/cpldrs/tests/Makefile.am @@ -18,7 +18,7 @@ @@ -50,7 +50,7 @@ DISTCLEANFILES = *~ diff --git a/cplui/tests/Makefile.am b/cplui/tests/Makefile.am -index f5a0458..55c00ba 100644 +index 2521e1c..cf10dc7 100644 --- a/cplui/tests/Makefile.am +++ b/cplui/tests/Makefile.am @@ -18,7 +18,7 @@ diff -Nru cpl-7.1.4+ds/debian/patches/Loose-tests.patch cpl-7.2.2+ds/debian/patches/Loose-tests.patch --- cpl-7.1.4+ds/debian/patches/Loose-tests.patch 2021-08-16 18:20:47.000000000 +0000 +++ cpl-7.2.2+ds/debian/patches/Loose-tests.patch 2022-05-11 19:02:39.000000000 +0000 @@ -12,15 +12,15 @@ 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpldrs/tests/cpl_fit-test.c b/cpldrs/tests/cpl_fit-test.c -index 3feeb7f..fa5c3c7 100644 +index f59bad0..d821ffc 100644 --- a/cpldrs/tests/cpl_fit-test.c +++ b/cpldrs/tests/cpl_fit-test.c -@@ -1598,7 +1598,7 @@ cpl_fit_imagelist_polynomial_window_test(const cpl_vector * x_pos, - cpl_image * baderror = fiterror ? cpl_image_duplicate(fiterror) : NULL; - const double tol = pixeltype == CPL_TYPE_INT ? 0.0 - : (pixeltype == CPL_TYPE_FLOAT +@@ -1603,7 +1603,7 @@ cpl_fit_imagelist_polynomial_window_test(const cpl_vector *x_pos, + pixeltype == CPL_TYPE_INT + ? 0.0 + : (pixeltype == CPL_TYPE_FLOAT -#if defined SIZEOF_SIZE_T && SIZEOF_SIZE_T == 4 +#if 1 - /* FIXME: Extreme loss of precision on (some) 32-bit machines */ - ? 0.004 : 30.0 * FLT_EPSILON - #else + /* FIXME: Extreme loss of precision on (some) 32-bit machines */ + ? 0.004 + : 30.0 * FLT_EPSILON diff -Nru cpl-7.1.4+ds/debian/patches/Remove-cfitsio-version-check.patch cpl-7.2.2+ds/debian/patches/Remove-cfitsio-version-check.patch --- cpl-7.1.4+ds/debian/patches/Remove-cfitsio-version-check.patch 2021-08-16 18:20:47.000000000 +0000 +++ cpl-7.2.2+ds/debian/patches/Remove-cfitsio-version-check.patch 2022-05-11 19:02:38.000000000 +0000 @@ -8,11 +8,11 @@ obsolete. For Debian, runtime dependency checks should be put into the install dependency anyway instead of checking it at runtime. --- - cplcore/cpl_init.c | 18 ------------------ - 1 file changed, 18 deletions(-) + cplcore/cpl_init.c | 19 ------------------- + 1 file changed, 19 deletions(-) diff --git a/cplcore/cpl_init.c b/cplcore/cpl_init.c -index c998499..2d176c2 100644 +index 2c7e53a..b81d0d4 100644 --- a/cplcore/cpl_init.c +++ b/cplcore/cpl_init.c @@ -99,11 +99,6 @@ @@ -27,21 +27,22 @@ */ void -@@ -135,19 +130,6 @@ cpl_init(unsigned self) +@@ -136,20 +131,6 @@ cpl_init(unsigned self) cpl_msg_warning(cpl_func, "Illegal input ignored"); } - float _cfitsio_version; -- const int cfitsio_version_min = (int)(1000. * CPL_CFITSIO_VERSION + 0.5); -- const int cfitsio_version = (int)(1000. * -- fits_get_version(&_cfitsio_version) + 0.5); +- const int cfitsio_version_min = +- (int)(100. * CPL_CFITSIO_MAJOR + CPL_CFITSIO_MINOR); +- const int cfitsio_version = +- (int)(100. * fits_get_version(&_cfitsio_version)); - - if (cfitsio_version < cfitsio_version_min) { - (void)cpl_error_set_message_(CPL_ERROR_INCOMPATIBLE_INPUT, - "Run-time version %.3f of CFITSIO " - "is not supported. Minimum required " -- "version is %.3f", _cfitsio_version, -- CPL_CFITSIO_VERSION); +- "version is %.3f", +- _cfitsio_version, CPL_CFITSIO_VERSION); - } - #ifdef HAVE_LIBPTHREAD diff -Nru cpl-7.1.4+ds/debian/patches/Remove-CPU-check-at-compile-time.patch cpl-7.2.2+ds/debian/patches/Remove-CPU-check-at-compile-time.patch --- cpl-7.1.4+ds/debian/patches/Remove-CPU-check-at-compile-time.patch 2021-08-16 18:20:47.000000000 +0000 +++ cpl-7.2.2+ds/debian/patches/Remove-CPU-check-at-compile-time.patch 2022-05-11 19:02:39.000000000 +0000 @@ -12,7 +12,7 @@ 1 file changed, 1 deletion(-) diff --git a/configure.ac b/configure.ac -index 0a6c590..0664189 100644 +index d8c9581..1e3259e 100644 --- a/configure.ac +++ b/configure.ac @@ -116,7 +116,6 @@ CPL_CREATE_SYMBOLS(build) diff -Nru cpl-7.1.4+ds/debian/patches/Remove-private-library-libltdl-and-use-the-installed-one.patch cpl-7.2.2+ds/debian/patches/Remove-private-library-libltdl-and-use-the-installed-one.patch --- cpl-7.1.4+ds/debian/patches/Remove-private-library-libltdl-and-use-the-installed-one.patch 2021-08-16 18:20:47.000000000 +0000 +++ cpl-7.2.2+ds/debian/patches/Remove-private-library-libltdl-and-use-the-installed-one.patch 2022-05-11 19:02:39.000000000 +0000 @@ -7,7 +7,7 @@ 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Makefile.am b/Makefile.am -index 9baa174..12d46bf 100644 +index b952741..de159f0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -25,11 +25,10 @@ ACLOCAL_AMFLAGS = -I m4 diff -Nru cpl-7.1.4+ds/debian/patches/Remove-timestamp-macros-from-source-for-repoducible-build.patch cpl-7.2.2+ds/debian/patches/Remove-timestamp-macros-from-source-for-repoducible-build.patch --- cpl-7.1.4+ds/debian/patches/Remove-timestamp-macros-from-source-for-repoducible-build.patch 2021-08-16 18:20:47.000000000 +0000 +++ cpl-7.2.2+ds/debian/patches/Remove-timestamp-macros-from-source-for-repoducible-build.patch 2022-05-11 19:02:39.000000000 +0000 @@ -3,32 +3,35 @@ Subject: Remove timestamp macros from source for repoducible builds --- - cplcore/cpl_test.c | 9 --------- - 1 file changed, 9 deletions(-) + cplcore/cpl_test.c | 12 ------------ + 1 file changed, 12 deletions(-) diff --git a/cplcore/cpl_test.c b/cplcore/cpl_test.c -index c62265d..ef9a4d8 100644 +index 4926e86..e3b1fb3 100644 --- a/cplcore/cpl_test.c +++ b/cplcore/cpl_test.c -@@ -3041,12 +3041,6 @@ static const char * cpl_test_get_description(void) - "This platform is not big-endian\n" +@@ -3261,14 +3261,6 @@ cpl_test_get_description(void) + "This platform is not big-endian\n" #endif -#ifdef __DATE__ -- "Compile date: " __DATE__ "\n" +- "Compile date: " __DATE__ +- "\n" -#endif -#ifdef __TIME__ -- "Compile time: " __TIME__ "\n" +- "Compile time: " __TIME__ +- "\n" -#endif #ifdef __STDC__ CPL_XSTRINGIFY(__STDC__) ": " CPL_STRINGIFY(__STDC__) "\n" #endif -@@ -3089,9 +3083,6 @@ static const char * cpl_test_get_description(void) +@@ -3313,10 +3305,6 @@ cpl_test_get_description(void) #ifdef __OPTIMIZE__ CPL_XSTRINGIFY(__OPTIMIZE__) ": " CPL_STRINGIFY(__OPTIMIZE__) "\n" #endif -#ifdef __TIMESTAMP__ -- "Last modification of " __FILE__ ": " __TIMESTAMP__ "\n" +- "Last modification of " __FILE__ ": " __TIMESTAMP__ +- "\n" -#endif #endif ; diff -Nru cpl-7.1.4+ds/debian/patches/Remove-WCS-versioninfo.patch cpl-7.2.2+ds/debian/patches/Remove-WCS-versioninfo.patch --- cpl-7.1.4+ds/debian/patches/Remove-WCS-versioninfo.patch 2021-08-16 18:20:47.000000000 +0000 +++ cpl-7.2.2+ds/debian/patches/Remove-WCS-versioninfo.patch 2022-05-11 19:02:38.000000000 +0000 @@ -11,22 +11,22 @@ 1 file changed, 9 deletions(-) diff --git a/cplcore/cpl_init.c b/cplcore/cpl_init.c -index d9ebd7b..c998499 100644 +index bec951a..2c7e53a 100644 --- a/cplcore/cpl_init.c +++ b/cplcore/cpl_init.c @@ -39,11 +39,6 @@ /* strcmp() */ #include --#ifdef CPL_WCS_INSTALLED /* If WCS is installed */ +-#ifdef CPL_WCS_INSTALLED /* If WCS is installed */ -/* Get WCSLIB version number */ -#include --#endif /* End If WCS is installed */ +-#endif /* End If WCS is installed */ - #if defined CPL_FFTWF_INSTALLED || defined CPL_FFTW_INSTALLED #include #endif -@@ -182,11 +177,7 @@ const char * cpl_get_description(unsigned self) +@@ -182,11 +177,7 @@ cpl_get_description(unsigned self) only, or both */ #ifdef CPL_WCS_INSTALLED diff -Nru cpl-7.1.4+ds/debian/patches/Use-standard-paths-for-libraries.patch cpl-7.2.2+ds/debian/patches/Use-standard-paths-for-libraries.patch --- cpl-7.1.4+ds/debian/patches/Use-standard-paths-for-libraries.patch 2021-08-16 18:20:47.000000000 +0000 +++ cpl-7.2.2+ds/debian/patches/Use-standard-paths-for-libraries.patch 2022-05-11 19:02:38.000000000 +0000 @@ -14,7 +14,7 @@ 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cplcore/cpl_test.c b/cplcore/cpl_test.c -index 7f01031..c62265d 100644 +index 1f4f7a1..4926e86 100644 --- a/cplcore/cpl_test.c +++ b/cplcore/cpl_test.c @@ -103,7 +103,7 @@ @@ -27,20 +27,20 @@ #ifndef inline diff --git a/cpldrs/cpl_wcs.c b/cpldrs/cpl_wcs.c -index 61a21b1..ed5df78 100644 +index d4e1896..a930f54 100644 --- a/cpldrs/cpl_wcs.c +++ b/cpldrs/cpl_wcs.c -@@ -70,7 +70,7 @@ - # undef PACKAGE_BUGREPORT +@@ -69,7 +69,7 @@ + #undef PACKAGE_BUGREPORT #endif -#include +#include - #endif /* End If WCS is installed */ + #endif /* End If WCS is installed */ diff --git a/cpldrs/tests/cpl_wcs-test.c b/cpldrs/tests/cpl_wcs-test.c -index 9ca01c2..200e8f5 100644 +index 6adbfda..f1815fb 100644 --- a/cpldrs/tests/cpl_wcs-test.c +++ b/cpldrs/tests/cpl_wcs-test.c @@ -39,7 +39,7 @@ diff -Nru cpl-7.1.4+ds/debian/patches/Work-around-MIPS-compiler-optimization-problem.patch cpl-7.2.2+ds/debian/patches/Work-around-MIPS-compiler-optimization-problem.patch --- cpl-7.1.4+ds/debian/patches/Work-around-MIPS-compiler-optimization-problem.patch 2021-08-16 18:20:47.000000000 +0000 +++ cpl-7.2.2+ds/debian/patches/Work-around-MIPS-compiler-optimization-problem.patch 2022-05-11 19:02:39.000000000 +0000 @@ -9,7 +9,7 @@ 1 file changed, 4 insertions(+) diff --git a/cplcore/cpl_imagelist_basic.c b/cplcore/cpl_imagelist_basic.c -index 12e15cb..0bcfab5 100644 +index 27c04c6..45271ec 100644 --- a/cplcore/cpl_imagelist_basic.c +++ b/cplcore/cpl_imagelist_basic.c @@ -21,6 +21,10 @@ diff -Nru cpl-7.1.4+ds/Doxyfile.in cpl-7.2.2+ds/Doxyfile.in --- cpl-7.1.4+ds/Doxyfile.in 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/Doxyfile.in 2022-04-29 14:56:02.000000000 +0000 @@ -32,7 +32,7 @@ # title of most generated pages and in a few other places. # The default value is: My Project. -PROJECT_NAME = "Common Pipeline Library Reference Manual" +PROJECT_NAME = "Common Pipeline Library Reference" # The PROJECT_NUMBER tag can be used to enter a project or revision number. This # could be handy for archiving the generated documentation or if some version @@ -1581,7 +1581,7 @@ # MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols # This tag requires that the tag USE_MATHJAX is set to YES. -MATHJAX_EXTENSIONS = +MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols # The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces # of code that will be used on startup of the MathJax code. See the MathJax site @@ -1610,7 +1610,7 @@ # The default value is: YES. # This tag requires that the tag GENERATE_HTML is set to YES. -SEARCHENGINE = NO +SEARCHENGINE = YES # When the SERVER_BASED_SEARCH tag is enabled the search engine will be # implemented using a web server instead of a web client using JavaScript. There @@ -1741,7 +1741,7 @@ # The default value is: a4. # This tag requires that the tag GENERATE_LATEX is set to YES. -PAPER_TYPE = a4wide +PAPER_TYPE = a4 # The EXTRA_PACKAGES tag can be used to specify one or more LaTeX package names # that should be included in the LaTeX output. The package can be specified just @@ -1753,7 +1753,7 @@ # If left blank no extra packages will be included. # This tag requires that the tag GENERATE_LATEX is set to YES. -EXTRA_PACKAGES = times +EXTRA_PACKAGES = times amsmath # The LATEX_HEADER tag can be used to specify a personal LaTeX header for the # generated LaTeX document. The header should contain everything until the first @@ -1808,7 +1808,7 @@ # The default value is: YES. # This tag requires that the tag GENERATE_LATEX is set to YES. -PDF_HYPERLINKS = NO +PDF_HYPERLINKS = YES # If the USE_PDFLATEX tag is set to YES, doxygen will use the engine as # specified with LATEX_CMD_NAME to generate the PDF file directly from the LaTeX diff -Nru cpl-7.1.4+ds/libcext/aclocal.m4 cpl-7.2.2+ds/libcext/aclocal.m4 --- cpl-7.1.4+ds/libcext/aclocal.m4 2021-05-07 12:09:56.000000000 +0000 +++ cpl-7.2.2+ds/libcext/aclocal.m4 2022-04-29 14:56:22.000000000 +0000 @@ -1,6 +1,6 @@ -# generated automatically by aclocal 1.15.1 -*- Autoconf -*- +# generated automatically by aclocal 1.16.3 -*- Autoconf -*- -# Copyright (C) 1996-2017 Free Software Foundation, Inc. +# Copyright (C) 1996-2020 Free Software Foundation, Inc. # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -14,13 +14,13 @@ 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. +m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.71],, +[m4_warning([this file was generated for autoconf 2.71. 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-2017 Free Software Foundation, Inc. +# Copyright (C) 2002-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -32,10 +32,10 @@ # 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' +[am__api_version='1.16' 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.1], [], +m4_if([$1], [1.16.3], [], [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl ]) @@ -51,14 +51,14 @@ # 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.1])dnl +[AM_AUTOMAKE_VERSION([1.16.3])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-2017 Free Software Foundation, Inc. +# Copyright (C) 2001-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -110,7 +110,7 @@ # AM_CONDITIONAL -*- Autoconf -*- -# Copyright (C) 1997-2017 Free Software Foundation, Inc. +# Copyright (C) 1997-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -141,7 +141,7 @@ Usually this means the macro was only invoked conditionally.]]) fi])]) -# Copyright (C) 1999-2017 Free Software Foundation, Inc. +# Copyright (C) 1999-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -332,13 +332,12 @@ # Generate code to set up dependency tracking. -*- Autoconf -*- -# Copyright (C) 1999-2017 Free Software Foundation, Inc. +# Copyright (C) 1999-2020 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], @@ -346,49 +345,43 @@ # 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 + # TODO: see whether this extra hack can be removed once we start + # requiring Autoconf 2.70 or later. + AS_CASE([$CONFIG_FILES], + [*\'*], [eval set x "$CONFIG_FILES"], + [*], [set x $CONFIG_FILES]) shift - for mf + # Used to flag and report bootstrapping failures. + am_rc=0 + for am_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 + am_mf=`AS_ECHO(["$am_mf"]) | sed -e 's/:.*$//'` + # Check whether this is an Automake generated Makefile which includes + # dependency-tracking related rules and includes. + # Grep'ing the whole file directly is not great: 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 + sed -n 's,^am--depfiles:.*,X,p' "$am_mf" | grep X >/dev/null 2>&1 \ + || continue + am_dirpart=`AS_DIRNAME(["$am_mf"])` + am_filepart=`AS_BASENAME(["$am_mf"])` + AM_RUN_LOG([cd "$am_dirpart" \ + && sed -e '/# am--include-marker/d' "$am_filepart" \ + | $MAKE -f - am--depfiles]) || am_rc=$? done + if test $am_rc -ne 0; then + AC_MSG_FAILURE([Something went wrong bootstrapping makefile fragments + for automatic dependency tracking. If GNU make was not used, consider + re-running the configure script with MAKE="gmake" (or whatever is + necessary). You can also try re-running configure with the + '--disable-dependency-tracking' option to at least be able to build + the package (albeit without support for automatic dependency tracking).]) + fi + AS_UNSET([am_dirpart]) + AS_UNSET([am_filepart]) + AS_UNSET([am_mf]) + AS_UNSET([am_rc]) + rm -f conftest-deps.mk } ])# _AM_OUTPUT_DEPENDENCY_COMMANDS @@ -397,18 +390,17 @@ # ----------------------------- # 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. +# This code is only required when automatic dependency tracking is enabled. +# This creates each '.Po' and '.Plo' makefile fragment that we'll 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"]) -]) + [AMDEP_TRUE="$AMDEP_TRUE" MAKE="${MAKE-make}"])]) # Do all the work for Automake. -*- Autoconf -*- -# Copyright (C) 1996-2017 Free Software Foundation, Inc. +# Copyright (C) 1996-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -472,7 +464,7 @@ [_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]), + m4_ifset([AC_PACKAGE_NAME], [ok]):m4_ifset([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 @@ -495,8 +487,8 @@ 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. @@ -563,7 +555,7 @@ 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: . +that behaves properly: . If you want to complete the configuration process using your problematic 'rm' anyway, export the environment variable ACCEPT_INFERIOR_RM_PROGRAM @@ -605,7 +597,7 @@ done echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count]) -# Copyright (C) 2001-2017 Free Software Foundation, Inc. +# Copyright (C) 2001-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -626,7 +618,7 @@ fi AC_SUBST([install_sh])]) -# Copyright (C) 2003-2017 Free Software Foundation, Inc. +# Copyright (C) 2003-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -648,7 +640,7 @@ # Add --enable-maintainer-mode option to configure. -*- Autoconf -*- # From Jim Meyering -# Copyright (C) 1996-2017 Free Software Foundation, Inc. +# Copyright (C) 1996-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -683,7 +675,7 @@ # Check to see how 'make' treats includes. -*- Autoconf -*- -# Copyright (C) 2001-2017 Free Software Foundation, Inc. +# Copyright (C) 2001-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -691,49 +683,42 @@ # AM_MAKE_INCLUDE() # ----------------- -# Check to see how make treats includes. +# Check whether make has an 'include' directive that can support all +# the idioms we need for our automatic dependency tracking code. AC_DEFUN([AM_MAKE_INCLUDE], -[am_make=${MAKE-make} -cat > confinc << 'END' +[AC_MSG_CHECKING([whether ${MAKE-make} supports the include directive]) +cat > confinc.mk << 'END' am__doit: - @echo this is the am__doit target + @echo this is the am__doit target >confinc.out .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 -]) +# BSD make does it like this. +echo '.include "confinc.mk" # ignored' > confmf.BSD +# Other make implementations (GNU, Solaris 10, AIX) do it like this. +echo 'include confinc.mk # ignored' > confmf.GNU +_am_result=no +for s in GNU BSD; do + AM_RUN_LOG([${MAKE-make} -f confmf.$s && cat confinc.out]) + AS_CASE([$?:`cat confinc.out 2>/dev/null`], + ['0:this is the am__doit target'], + [AS_CASE([$s], + [BSD], [am__include='.include' am__quote='"'], + [am__include='include' am__quote=''])]) + if test "$am__include" != "#"; then + _am_result="yes ($s style)" + break + fi +done +rm -f confinc.* confmf.* +AC_MSG_RESULT([${_am_result}]) +AC_SUBST([am__include])]) +AC_SUBST([am__quote])]) # Fake the existence of programs that GNU maintainers use. -*- Autoconf -*- -# Copyright (C) 1997-2017 Free Software Foundation, Inc. +# Copyright (C) 1997-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -754,12 +739,7 @@ [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 + MISSING="\${SHELL} '$am_aux_dir/missing'" fi # Use eval to expand $SHELL if eval "$MISSING --is-lightweight"; then @@ -772,7 +752,7 @@ # Helper functions for option handling. -*- Autoconf -*- -# Copyright (C) 2001-2017 Free Software Foundation, Inc. +# Copyright (C) 2001-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -801,7 +781,7 @@ AC_DEFUN([_AM_IF_OPTION], [m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])]) -# Copyright (C) 1999-2017 Free Software Foundation, Inc. +# Copyright (C) 1999-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -848,7 +828,7 @@ # For backward compatibility. AC_DEFUN_ONCE([AM_PROG_CC_C_O], [AC_REQUIRE([AC_PROG_CC])]) -# Copyright (C) 2001-2017 Free Software Foundation, Inc. +# Copyright (C) 2001-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -867,7 +847,7 @@ # Check to make sure that the build environment is sane. -*- Autoconf -*- -# Copyright (C) 1996-2017 Free Software Foundation, Inc. +# Copyright (C) 1996-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -948,7 +928,7 @@ rm -f conftest.file ]) -# Copyright (C) 2009-2017 Free Software Foundation, Inc. +# Copyright (C) 2009-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -1008,7 +988,7 @@ _AM_SUBST_NOTMAKE([AM_BACKSLASH])dnl ]) -# Copyright (C) 2001-2017 Free Software Foundation, Inc. +# Copyright (C) 2001-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -1036,7 +1016,7 @@ INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s" AC_SUBST([INSTALL_STRIP_PROGRAM])]) -# Copyright (C) 2006-2017 Free Software Foundation, Inc. +# Copyright (C) 2006-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -1055,7 +1035,7 @@ # Check how to create a tarball. -*- Autoconf -*- -# Copyright (C) 2004-2017 Free Software Foundation, Inc. +# Copyright (C) 2004-2020 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, diff -Nru cpl-7.1.4+ds/libcext/admin/compile cpl-7.2.2+ds/libcext/admin/compile --- cpl-7.1.4+ds/libcext/admin/compile 2021-05-07 12:09:58.000000000 +0000 +++ cpl-7.2.2+ds/libcext/admin/compile 2022-04-29 14:56:23.000000000 +0000 @@ -1,9 +1,9 @@ #! /bin/sh # Wrapper for compilers which do not understand '-c -o'. -scriptversion=2016-01-11.22; # UTC +scriptversion=2018-03-07.03; # UTC -# Copyright (C) 1999-2017 Free Software Foundation, Inc. +# Copyright (C) 1999-2020 Free Software Foundation, Inc. # Written by Tom Tromey . # # This program is free software; you can redistribute it and/or modify @@ -17,7 +17,7 @@ # 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 . +# 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 @@ -53,7 +53,7 @@ MINGW*) file_conv=mingw ;; - CYGWIN*) + CYGWIN* | MSYS*) file_conv=cygwin ;; *) @@ -67,7 +67,7 @@ mingw/*) file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` ;; - cygwin/*) + cygwin/* | msys/*) file=`cygpath -m "$file" || echo "$file"` ;; wine/*) @@ -340,7 +340,7 @@ # Local Variables: # mode: shell-script # sh-indentation: 2 -# eval: (add-hook 'write-file-hooks 'time-stamp) +# eval: (add-hook 'before-save-hook 'time-stamp) # time-stamp-start: "scriptversion=" # time-stamp-format: "%:y-%02m-%02d.%02H" # time-stamp-time-zone: "UTC0" diff -Nru cpl-7.1.4+ds/libcext/admin/config.guess cpl-7.2.2+ds/libcext/admin/config.guess --- cpl-7.1.4+ds/libcext/admin/config.guess 2021-05-07 12:09:58.000000000 +0000 +++ cpl-7.2.2+ds/libcext/admin/config.guess 2022-04-29 14:56:23.000000000 +0000 @@ -1,8 +1,8 @@ #! /bin/sh # Attempt to guess a canonical system name. -# Copyright 1992-2017 Free Software Foundation, Inc. +# Copyright 1992-2021 Free Software Foundation, Inc. -timestamp='2017-05-27' +timestamp='2021-01-25' # 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 @@ -15,7 +15,7 @@ # 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 . +# 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 @@ -27,19 +27,19 @@ # 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 +# https://git.savannah.gnu.org/cgit/config.git/plain/config.guess # # Please send patches to . -me=`echo "$0" | sed -e 's,.*/,,'` +me=$(echo "$0" | sed -e 's,.*/,,') usage="\ Usage: $0 [OPTION] Output the configuration name of the system \`$me' is run on. -Operation modes: +Options: -h, --help print this help, then exit -t, --time-stamp print date of last modification, then exit -v, --version print version number, then exit @@ -50,7 +50,7 @@ GNU config.guess ($timestamp) Originally written by Per Bothner. -Copyright 1992-2017 Free Software Foundation, Inc. +Copyright 1992-2021 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." @@ -84,8 +84,6 @@ 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 @@ -96,76 +94,89 @@ # 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= ;' +tmp= +# shellcheck disable=SC2172 +trap 'test -z "$tmp" || rm -fr "$tmp"' 0 1 2 13 15 + +set_cc_for_build() { + # prevent multiple calls if $tmp is already set + test "$tmp" && return 0 + : "${TMPDIR=/tmp}" + # shellcheck disable=SC2039 + { 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" 2>/dev/null) ; } || + { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir "$tmp" 2>/dev/null) && echo "Warning: creating insecure temp directory" >&2 ; } || + { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } + dummy=$tmp/dummy + case ${CC_FOR_BUILD-},${HOST_CC-},${CC-} in + ,,) echo "int x;" > "$dummy.c" + for driver in cc gcc c89 c99 ; do + if ($driver -c -o "$dummy.o" "$dummy.c") >/dev/null 2>&1 ; then + CC_FOR_BUILD="$driver" + 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 +} # 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 +if test -f /.attbin/uname ; 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 +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 +case "$UNAME_SYSTEM" in Linux|GNU|GNU/*) - # If the system lacks a compiler, then just pick glibc. - # We could probably try harder. - LIBC=gnu + LIBC=unknown - eval $set_cc_for_build - cat <<-EOF > $dummy.c + set_cc_for_build + cat <<-EOF > "$dummy.c" #include #if defined(__UCLIBC__) LIBC=uclibc #elif defined(__dietlibc__) LIBC=dietlibc - #else + #elif defined(__GLIBC__) LIBC=gnu + #else + #include + /* First heuristic to detect musl libc. */ + #ifdef __DEFINED_va_list + LIBC=musl + #endif #endif EOF - eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^LIBC' | sed 's, ,,g'` - ;; -esac + eval "$($CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^LIBC' | sed 's, ,,g')" + + # Second heuristic to detect musl libc. + if [ "$LIBC" = unknown ] && + command -v ldd >/dev/null && + ldd --version 2>&1 | grep -q ^musl; then + LIBC=musl + fi -case "${UNAME_MACHINE}" in - i?86) - test -z "$VENDOR" && VENDOR=pc - ;; - *) - test -z "$VENDOR" && VENDOR=unknown - ;; + # If the system lacks a compiler, then just pick glibc. + # We could probably try harder. + if [ "$LIBC" = unknown ]; then + LIBC=gnu + fi + ;; esac -test -f /etc/SuSE-release -o -f /.buildenv && VENDOR=suse # Note: order is significant - the case branches are not exclusive. -case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in +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*, @@ -177,32 +188,32 @@ # # 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=`(uname -p 2>/dev/null || \ - /sbin/$sysctl 2>/dev/null || \ - /usr/sbin/$sysctl 2>/dev/null || \ - echo unknown)` - case "${UNAME_MACHINE_ARCH}" in + UNAME_MACHINE_ARCH=$( (uname -p 2>/dev/null || \ + /sbin/sysctl -n hw.machine_arch 2>/dev/null || \ + /usr/sbin/sysctl -n hw.machine_arch 2>/dev/null || \ + echo unknown)) + case "$UNAME_MACHINE_ARCH" in + aarch64eb) machine=aarch64_be-unknown ;; armeb) machine=armeb-unknown ;; arm*) machine=arm-unknown ;; sh3el) machine=shl-unknown ;; sh3eb) machine=sh-unknown ;; sh5el) machine=sh5le-unknown ;; earmv*) - arch=`echo ${UNAME_MACHINE_ARCH} | sed -e 's,^e\(armv[0-9]\).*$,\1,'` - endian=`echo ${UNAME_MACHINE_ARCH} | sed -ne 's,^.*\(eb\)$,\1,p'` - machine=${arch}${endian}-${VENDOR}-unknown + arch=$(echo "$UNAME_MACHINE_ARCH" | sed -e 's,^e\(armv[0-9]\).*$,\1,') + endian=$(echo "$UNAME_MACHINE_ARCH" | sed -ne 's,^.*\(eb\)$,\1,p') + machine="${arch}${endian}"-unknown ;; - *) machine=${UNAME_MACHINE_ARCH}-${VENDOR}-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) and ABI. - case "${UNAME_MACHINE_ARCH}" in + case "$UNAME_MACHINE_ARCH" in earm*) os=netbsdelf ;; arm*|i386|m68k|ns32k|sh3*|sparc|vax) - eval $set_cc_for_build + set_cc_for_build if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \ | grep -q __ELF__ then @@ -218,10 +229,10 @@ ;; esac # Determine ABI tags. - case "${UNAME_MACHINE_ARCH}" in + case "$UNAME_MACHINE_ARCH" in earm*) expr='s/^earmv[0-9]/-eabi/;s/eb$//' - abi=`echo ${UNAME_MACHINE_ARCH} | sed -e "$expr"` + abi=$(echo "$UNAME_MACHINE_ARCH" | sed -e "$expr") ;; esac # The OS release @@ -229,60 +240,75 @@ # 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 + case "$UNAME_VERSION" in Debian*) release='-gnu' ;; *) - release=`echo ${UNAME_RELEASE} | sed -e 's/[-_].*//' | cut -d. -f1,2` + release=$(echo "$UNAME_RELEASE" | sed -e 's/[-_].*//' | cut -d. -f1,2) ;; 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}${abi}" + echo "$machine-${os}${release}${abi-}" exit ;; *:Bitrig:*:*) - UNAME_MACHINE_ARCH=`arch | sed 's/Bitrig.//'` - echo ${UNAME_MACHINE_ARCH}-${VENDOR}-bitrig${UNAME_RELEASE} + 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}-${VENDOR}-openbsd${UNAME_RELEASE} + UNAME_MACHINE_ARCH=$(arch | sed 's/OpenBSD.//') + echo "$UNAME_MACHINE_ARCH"-unknown-openbsd"$UNAME_RELEASE" exit ;; *:LibertyBSD:*:*) - UNAME_MACHINE_ARCH=`arch | sed 's/^.*BSD\.//'` - echo ${UNAME_MACHINE_ARCH}-${VENDOR}-libertybsd${UNAME_RELEASE} + UNAME_MACHINE_ARCH=$(arch | sed 's/^.*BSD\.//') + echo "$UNAME_MACHINE_ARCH"-unknown-libertybsd"$UNAME_RELEASE" + exit ;; + *:MidnightBSD:*:*) + echo "$UNAME_MACHINE"-unknown-midnightbsd"$UNAME_RELEASE" exit ;; *:ekkoBSD:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-ekkobsd${UNAME_RELEASE} + echo "$UNAME_MACHINE"-unknown-ekkobsd"$UNAME_RELEASE" exit ;; *:SolidBSD:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-solidbsd${UNAME_RELEASE} + echo "$UNAME_MACHINE"-unknown-solidbsd"$UNAME_RELEASE" + exit ;; + *:OS108:*:*) + echo "$UNAME_MACHINE"-unknown-os108_"$UNAME_RELEASE" exit ;; macppc:MirBSD:*:*) - echo powerpc-${VENDOR}-mirbsd${UNAME_RELEASE} + echo powerpc-unknown-mirbsd"$UNAME_RELEASE" exit ;; *:MirBSD:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-mirbsd${UNAME_RELEASE} + echo "$UNAME_MACHINE"-unknown-mirbsd"$UNAME_RELEASE" exit ;; *:Sortix:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-sortix + echo "$UNAME_MACHINE"-unknown-sortix + exit ;; + *:Twizzler:*:*) + echo "$UNAME_MACHINE"-unknown-twizzler + exit ;; + *:Redox:*:*) + echo "$UNAME_MACHINE"-unknown-redox + exit ;; + mips:OSF1:*.*) + echo mips-dec-osf1 exit ;; alpha:OSF1:*:*) case $UNAME_RELEASE in *4.0) - UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` + UNAME_RELEASE=$(/usr/sbin/sizer -v | awk '{print $3}') ;; *5.*) - UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'` + 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` + 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 ;; @@ -320,28 +346,19 @@ # 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` + 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-${VENDOR}-sysv4 + echo m68k-unknown-sysv4 exit ;; *:[Aa]miga[Oo][Ss]:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-amigaos + echo "$UNAME_MACHINE"-unknown-amigaos exit ;; *:[Mm]orph[Oo][Ss]:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-morphos + echo "$UNAME_MACHINE"-unknown-morphos exit ;; *:OS/390:*:*) echo i370-ibm-openedition @@ -353,17 +370,17 @@ echo powerpc-ibm-os400 exit ;; arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) - echo arm-acorn-riscix${UNAME_RELEASE} + echo arm-acorn-riscix"$UNAME_RELEASE" exit ;; arm*:riscos:*:*|arm*:RISCOS:*:*) - echo arm-${VENDOR}-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 + if test "$( (/bin/universe) 2>/dev/null)" = att ; then echo pyramid-pyramid-sysv3 else echo pyramid-pyramid-bsd @@ -376,28 +393,28 @@ echo sparc-icl-nx6 exit ;; DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*) - case `/usr/bin/uname -p` in + 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/[^.]*//'` + 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/[^.]*//'` + 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/[^.]*//'` + echo sparc-sun-solaris2"$(echo "$UNAME_RELEASE" | sed -e 's/[^.]*//')" exit ;; i86pc:AuroraUX:5.*:* | i86xen:AuroraUX:5.*:*) - echo i386-pc-auroraux${UNAME_RELEASE} + echo i386-pc-auroraux"$UNAME_RELEASE" exit ;; i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*) - eval $set_cc_for_build + 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 test "$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 @@ -405,40 +422,40 @@ SUN_ARCH=x86_64 fi fi - echo ${SUN_ARCH}-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + 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/[^.]*//'` + echo sparc-sun-solaris3"$(echo "$UNAME_RELEASE"|sed -e 's/[^.]*//')" exit ;; sun4*:SunOS:*:*) - case "`/usr/bin/arch -k`" in + case "$(/usr/bin/arch -k)" in Series*|S4*) - UNAME_RELEASE=`uname -v` + 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/-/_/'` + echo sparc-sun-sunos"$(echo "$UNAME_RELEASE"|sed -e 's/-/_/')" exit ;; sun3*:SunOS:*:*) - echo m68k-sun-sunos${UNAME_RELEASE} + 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 + 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} + echo m68k-sun-sunos"$UNAME_RELEASE" ;; sun4) - echo sparc-sun-sunos${UNAME_RELEASE} + echo sparc-sun-sunos"$UNAME_RELEASE" ;; esac exit ;; aushp:SunOS:*:*) - echo sparc-auspex-sunos${UNAME_RELEASE} + 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 @@ -449,44 +466,44 @@ # 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} + echo m68k-atari-mint"$UNAME_RELEASE" exit ;; atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) - echo m68k-atari-mint${UNAME_RELEASE} + echo m68k-atari-mint"$UNAME_RELEASE" exit ;; *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) - echo m68k-atari-mint${UNAME_RELEASE} + echo m68k-atari-mint"$UNAME_RELEASE" exit ;; milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) - echo m68k-milan-mint${UNAME_RELEASE} + echo m68k-milan-mint"$UNAME_RELEASE" exit ;; hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) - echo m68k-hades-mint${UNAME_RELEASE} + echo m68k-hades-mint"$UNAME_RELEASE" exit ;; *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) - echo m68k-${VENDOR}-mint${UNAME_RELEASE} + echo m68k-unknown-mint"$UNAME_RELEASE" exit ;; m68k:machten:*:*) - echo m68k-apple-machten${UNAME_RELEASE} + echo m68k-apple-machten"$UNAME_RELEASE" exit ;; powerpc:machten:*:*) - echo powerpc-apple-machten${UNAME_RELEASE} + echo powerpc-apple-machten"$UNAME_RELEASE" exit ;; RISC*:Mach:*:*) echo mips-dec-mach_bsd4.3 exit ;; RISC*:ULTRIX:*:*) - echo mips-dec-ultrix${UNAME_RELEASE} + echo mips-dec-ultrix"$UNAME_RELEASE" exit ;; VAX*:ULTRIX*:*:*) - echo vax-dec-ultrix${UNAME_RELEASE} + echo vax-dec-ultrix"$UNAME_RELEASE" exit ;; 2020:CLIX:*:* | 2430:CLIX:*:*) - echo clipper-intergraph-clix${UNAME_RELEASE} + echo clipper-intergraph-clix"$UNAME_RELEASE" exit ;; mips:*:*:UMIPS | mips:*:*:RISCos) - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c + set_cc_for_build + sed 's/^ //' << EOF > "$dummy.c" #ifdef __cplusplus #include /* for printf() prototype */ int main (int argc, char *argv[]) { @@ -495,23 +512,23 @@ #endif #if defined (host_mips) && defined (MIPSEB) #if defined (SYSTYPE_SYSV) - printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0); + 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); + 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); + 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` && + $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} + echo mips-mips-riscos"$UNAME_RELEASE" exit ;; Motorola:PowerMAX_OS:*:*) echo powerpc-motorola-powermax @@ -536,18 +553,18 @@ exit ;; AViiON:dgux:*:*) # DG/UX returns AViiON for all architectures - UNAME_PROCESSOR=`/usr/bin/uname -p` - if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ] + UNAME_PROCESSOR=$(/usr/bin/uname -p) + if test "$UNAME_PROCESSOR" = mc88100 || test "$UNAME_PROCESSOR" = mc88110 then - if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \ - [ ${TARGET_BINARY_INTERFACE}x = x ] + if test "$TARGET_BINARY_INTERFACE"x = m88kdguxelfx || \ + test "$TARGET_BINARY_INTERFACE"x = x then - echo m88k-dg-dgux${UNAME_RELEASE} + echo m88k-dg-dgux"$UNAME_RELEASE" else - echo m88k-dg-dguxbcs${UNAME_RELEASE} + echo m88k-dg-dguxbcs"$UNAME_RELEASE" fi else - echo i586-dg-dgux${UNAME_RELEASE} + echo i586-dg-dgux"$UNAME_RELEASE" fi exit ;; M88*:DolphinOS:*:*) # DolphinOS (SVR3) @@ -564,26 +581,26 @@ echo m68k-tektronix-bsd exit ;; *:IRIX*:*:*) - echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'` + 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 ' + 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` + if test -x /usr/bin/oslevel ; then + IBM_REV=$(/usr/bin/oslevel) else - IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} + IBM_REV="$UNAME_VERSION.$UNAME_RELEASE" fi - echo ${UNAME_MACHINE}-ibm-aix${IBM_REV} + 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 + set_cc_for_build + sed 's/^ //' << EOF > "$dummy.c" #include main() @@ -594,7 +611,7 @@ exit(0); } EOF - if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` + if $CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=$("$dummy") then echo "$SYSTEM_NAME" else @@ -607,28 +624,28 @@ 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_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/` + if test -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} + IBM_REV="$UNAME_VERSION.$UNAME_RELEASE" fi - echo ${IBM_ARCH}-ibm-aix${IBM_REV} + echo "$IBM_ARCH"-ibm-aix"$IBM_REV" exit ;; *:AIX:*:*) echo rs6000-ibm-aix exit ;; - ibmrt:4.4BSD:*|romp-ibm:BSD:*) + ibmrt:4.4BSD:*|romp-ibm:4.4BSD:*) 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 + echo romp-ibm-bsd"$UNAME_RELEASE" # 4.3 with uname added to exit ;; # report: romp-ibm BSD 4.3 *:BOSX:*:*) echo rs6000-bull-bosx @@ -643,28 +660,28 @@ 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 ;; + 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 + if test -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 + 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 + if test "$HP_ARCH" = ""; then + set_cc_for_build + sed 's/^ //' << EOF > "$dummy.c" #define _HPUX_SOURCE #include @@ -697,13 +714,13 @@ exit (0); } EOF - (CCOPTS="" $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy` + (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 ] + if test "$HP_ARCH" = hppa2.0w then - eval $set_cc_for_build + 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 @@ -722,15 +739,15 @@ HP_ARCH=hppa64 fi fi - echo ${HP_ARCH}-hp-hpux${HPUX_REV} + 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} + 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 + set_cc_for_build + sed 's/^ //' << EOF > "$dummy.c" #include int main () @@ -755,11 +772,11 @@ exit (0); } EOF - $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` && + $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:*:* ) + 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:*) echo hppa1.1-hp-bsd exit ;; 9000/8??:4.3bsd:*:*) @@ -768,17 +785,17 @@ *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) echo hppa1.0-hp-mpeix exit ;; - hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* ) + 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}-${VENDOR}-osf1mk + if test -x /usr/sbin/sysversion ; then + echo "$UNAME_MACHINE"-unknown-osf1mk else - echo ${UNAME_MACHINE}-${VENDOR}-osf1 + echo "$UNAME_MACHINE"-unknown-osf1 fi exit ;; parisc*:Lites*:*:*) @@ -803,131 +820,123 @@ echo c4-convex-bsd exit ;; CRAY*Y-MP:*:*:*) - echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + echo ymp-cray-unicos"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/' exit ;; CRAY*[A-Z]90:*:*:*) - echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \ + 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/' + echo t90-cray-unicos"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/' exit ;; CRAY*T3E:*:*:*) - echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + echo alphaev5-cray-unicosmk"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/' exit ;; CRAY*SV1:*:*:*) - echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + echo sv1-cray-unicos"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/' exit ;; *:UNICOS/mp:*:*) - echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + 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/ /_/'` + 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/ /_/'` + 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} + echo "$UNAME_MACHINE"-pc-bsdi"$UNAME_RELEASE" exit ;; sparc*:BSD/OS:*:*) - echo sparc-${VENDOR}-bsdi${UNAME_RELEASE} + echo sparc-unknown-bsdi"$UNAME_RELEASE" exit ;; *:BSD/OS:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-bsdi${UNAME_RELEASE} + echo "$UNAME_MACHINE"-unknown-bsdi"$UNAME_RELEASE" + exit ;; + arm:FreeBSD:*:*) + UNAME_PROCESSOR=$(uname -p) + set_cc_for_build + if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \ + | grep -q __ARM_PCS_VFP + then + echo "${UNAME_PROCESSOR}"-unknown-freebsd"$(echo ${UNAME_RELEASE}|sed -e 's/[-(].*//')"-gnueabi + else + echo "${UNAME_PROCESSOR}"-unknown-freebsd"$(echo ${UNAME_RELEASE}|sed -e 's/[-(].*//')"-gnueabihf + fi exit ;; *:FreeBSD:*:*) - UNAME_PROCESSOR=`/usr/bin/uname -p` - case ${UNAME_PROCESSOR} in + UNAME_PROCESSOR=$(/usr/bin/uname -p) + case "$UNAME_PROCESSOR" in amd64) UNAME_PROCESSOR=x86_64 ;; i386) UNAME_PROCESSOR=i586 ;; esac - echo ${UNAME_PROCESSOR}-${VENDOR}-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` + echo "$UNAME_PROCESSOR"-unknown-freebsd"$(echo "$UNAME_RELEASE"|sed -e 's/[-(].*//')" exit ;; i*:CYGWIN*:*) - echo ${UNAME_MACHINE}-pc-cygwin + echo "$UNAME_MACHINE"-pc-cygwin exit ;; *:MINGW64*:*) - echo ${UNAME_MACHINE}-pc-mingw64 + echo "$UNAME_MACHINE"-pc-mingw64 exit ;; *:MINGW*:*) - echo ${UNAME_MACHINE}-pc-mingw32 + 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 + echo "$UNAME_MACHINE"-pc-msys exit ;; i*:PW*:*) - echo ${UNAME_MACHINE}-pc-pw32 + echo "$UNAME_MACHINE"-pc-pw32 exit ;; *:Interix*:*) - case ${UNAME_MACHINE} in + case "$UNAME_MACHINE" in x86) - echo i586-pc-interix${UNAME_RELEASE} + echo i586-pc-interix"$UNAME_RELEASE" exit ;; authenticamd | genuineintel | EM64T) - echo x86_64-${VENDOR}-interix${UNAME_RELEASE} + echo x86_64-unknown-interix"$UNAME_RELEASE" exit ;; IA64) - echo ia64-${VENDOR}-interix${UNAME_RELEASE} + 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 + echo "$UNAME_MACHINE"-pc-uwin exit ;; amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*) - echo x86_64-${VENDOR}-cygwin - exit ;; - p*:CYGWIN*:*) - echo powerpcle-${VENDOR}-cygwin + echo x86_64-pc-cygwin exit ;; prep*:SunOS:5.*:*) - echo powerpcle-${VENDOR}-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + echo powerpcle-unknown-solaris2"$(echo "$UNAME_RELEASE"|sed -e 's/[^.]*//')" exit ;; *:GNU:*:*) # the GNU system - echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-${VENDOR}-${LIBC}`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'` + 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}-${VENDOR}-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr "[:upper:]" "[:lower:]"``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-${LIBC} + echo "$UNAME_MACHINE-unknown-$(echo "$UNAME_SYSTEM" | sed 's,^[^/]*/,,' | tr "[:upper:]" "[:lower:]")$(echo "$UNAME_RELEASE"|sed -e 's/[-(].*//')-$LIBC" exit ;; - i*86:Minix:*:*) - echo ${UNAME_MACHINE}-pc-minix + *:Minix:*:*) + echo "$UNAME_MACHINE"-unknown-minix exit ;; aarch64:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; aarch64_be:Linux:*:*) UNAME_MACHINE=aarch64_be - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; alpha:Linux:*:*) - case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in + case $(sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' /proc/cpuinfo 2>/dev/null) in EV5) UNAME_MACHINE=alphaev5 ;; EV56) UNAME_MACHINE=alphaev56 ;; PCA56) UNAME_MACHINE=alphapca56 ;; @@ -938,140 +947,181 @@ esac objdump --private-headers /bin/sh | grep -q ld.so.1 if test "$?" = 0 ; then LIBC=gnulibc1 ; fi - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; arc:Linux:*:* | arceb:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; arm*:Linux:*:*) - eval $set_cc_for_build + set_cc_for_build if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \ | grep -q __ARM_EABI__ then - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC} + 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}-${VENDOR}-linux-${LIBC}eabi + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"eabi else - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC}eabihf + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"eabihf fi fi exit ;; avr32*:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; cris:Linux:*:*) - echo ${UNAME_MACHINE}-axis-linux-${LIBC} + echo "$UNAME_MACHINE"-axis-linux-"$LIBC" exit ;; crisv32:Linux:*:*) - echo ${UNAME_MACHINE}-axis-linux-${LIBC} + echo "$UNAME_MACHINE"-axis-linux-"$LIBC" exit ;; e2k:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; frv:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; hexagon:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; i*86:Linux:*:*) - echo ${UNAME_MACHINE}-pc-linux-${LIBC} + echo "$UNAME_MACHINE"-pc-linux-"$LIBC" exit ;; ia64:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; k1om:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" + exit ;; + loongarch32:Linux:*:* | loongarch64:Linux:*:* | loongarchx32:Linux:*:*) + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; m32r*:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; m68*:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; mips:Linux:*:* | mips64:Linux:*:*) - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c + set_cc_for_build + IS_GLIBC=0 + test x"${LIBC}" = xgnu && IS_GLIBC=1 + sed 's/^ //' << EOF > "$dummy.c" #undef CPU - #undef ${UNAME_MACHINE} - #undef ${UNAME_MACHINE}el + #undef mips + #undef mipsel + #undef mips64 + #undef mips64el + #if ${IS_GLIBC} && defined(_ABI64) + LIBCABI=gnuabi64 + #else + #if ${IS_GLIBC} && defined(_ABIN32) + LIBCABI=gnuabin32 + #else + LIBCABI=${LIBC} + #endif + #endif + + #if ${IS_GLIBC} && defined(__mips64) && defined(__mips_isa_rev) && __mips_isa_rev>=6 + CPU=mipsisa64r6 + #else + #if ${IS_GLIBC} && !defined(__mips64) && defined(__mips_isa_rev) && __mips_isa_rev>=6 + CPU=mipsisa32r6 + #else + #if defined(__mips64) + CPU=mips64 + #else + CPU=mips + #endif + #endif + #endif + #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) - CPU=${UNAME_MACHINE}el + MIPS_ENDIAN=el #else #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) - CPU=${UNAME_MACHINE} + MIPS_ENDIAN= #else - CPU= + MIPS_ENDIAN= #endif #endif EOF - eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^CPU'` - test x"${CPU}" != x && { echo "${CPU}-${VENDOR}-linux-${LIBC}"; exit; } + eval "$($CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^CPU\|^MIPS_ENDIAN\|^LIBCABI')" + test "x$CPU" != x && { echo "$CPU${MIPS_ENDIAN}-unknown-linux-$LIBCABI"; exit; } ;; mips64el:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; openrisc*:Linux:*:*) - echo or1k-${VENDOR}-linux-${LIBC} + echo or1k-unknown-linux-"$LIBC" exit ;; or32:Linux:*:* | or1k*:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; padre:Linux:*:*) - echo sparc-${VENDOR}-linux-${LIBC} + echo sparc-unknown-linux-"$LIBC" exit ;; parisc64:Linux:*:* | hppa64:Linux:*:*) - echo hppa64-${VENDOR}-linux-${LIBC} + 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-${VENDOR}-linux-${LIBC} ;; - PA8*) echo hppa2.0-${VENDOR}-linux-${LIBC} ;; - *) echo hppa-${VENDOR}-linux-${LIBC} ;; + 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-${VENDOR}-linux-${LIBC} + echo powerpc64-unknown-linux-"$LIBC" exit ;; ppc:Linux:*:*) - echo powerpc-${VENDOR}-linux-${LIBC} + echo powerpc-unknown-linux-"$LIBC" exit ;; ppc64le:Linux:*:*) - echo powerpc64le-${VENDOR}-linux-${LIBC} + echo powerpc64le-unknown-linux-"$LIBC" exit ;; ppcle:Linux:*:*) - echo powerpcle-${VENDOR}-linux-${LIBC} + echo powerpcle-unknown-linux-"$LIBC" exit ;; - riscv32:Linux:*:* | riscv64:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC} + riscv32:Linux:*:* | riscv32be:Linux:*:* | riscv64:Linux:*:* | riscv64be:Linux:*:*) + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; s390:Linux:*:* | s390x:Linux:*:*) - echo ${UNAME_MACHINE}-ibm-linux-${LIBC} + echo "$UNAME_MACHINE"-ibm-linux-"$LIBC" exit ;; sh64*:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; sh*:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; sparc:Linux:*:* | sparc64:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; tile*:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; vax:Linux:*:*) - echo ${UNAME_MACHINE}-dec-linux-${LIBC} + echo "$UNAME_MACHINE"-dec-linux-"$LIBC" exit ;; x86_64:Linux:*:*) - echo ${UNAME_MACHINE}-pc-linux-${LIBC} + set_cc_for_build + LIBCABI=$LIBC + if test "$CC_FOR_BUILD" != no_compiler_found; then + if (echo '#ifdef __ILP32__'; echo IS_X32; echo '#endif') | \ + (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ + grep IS_X32 >/dev/null + then + LIBCABI="$LIBC"x32 + fi + fi + echo "$UNAME_MACHINE"-pc-linux-"$LIBCABI" exit ;; xtensa*:Linux:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-linux-${LIBC} + echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" exit ;; i*86:DYNIX/ptx:4*:*) # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. @@ -1085,51 +1135,51 @@ # 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} + 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 + echo "$UNAME_MACHINE"-pc-os2-emx exit ;; i*86:XTS-300:*:STOP) - echo ${UNAME_MACHINE}-${VENDOR}-stop + echo "$UNAME_MACHINE"-unknown-stop exit ;; i*86:atheos:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-atheos + echo "$UNAME_MACHINE"-unknown-atheos exit ;; i*86:syllable:*:*) - echo ${UNAME_MACHINE}-pc-syllable + echo "$UNAME_MACHINE"-pc-syllable exit ;; i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.[02]*:*) - echo i386-${VENODR}-lynxos${UNAME_RELEASE} + echo i386-unknown-lynxos"$UNAME_RELEASE" exit ;; i*86:*DOS:*:*) - echo ${UNAME_MACHINE}-pc-msdosdjgpp + echo "$UNAME_MACHINE"-pc-msdosdjgpp exit ;; - i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*) - UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'` + i*86:*: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} + echo "$UNAME_MACHINE"-univel-sysv"$UNAME_REL" else - echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL} + 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 + case $(/bin/uname -X | grep "^Machine") in *486*) UNAME_MACHINE=i486 ;; *Pentium) UNAME_MACHINE=i586 ;; *Pent*|*Celeron) UNAME_MACHINE=i686 ;; esac - echo ${UNAME_MACHINE}-${VENDOR}-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} + 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/.*= //')` + 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 @@ -1137,9 +1187,9 @@ && UNAME_MACHINE=i686 (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \ && UNAME_MACHINE=i686 - echo ${UNAME_MACHINE}-pc-sco$UNAME_REL + echo "$UNAME_MACHINE"-pc-sco"$UNAME_REL" else - echo ${UNAME_MACHINE}-pc-sysv32 + echo "$UNAME_MACHINE"-pc-sysv32 fi exit ;; pc:*:*:*) @@ -1159,9 +1209,9 @@ 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 + echo i860-stardent-sysv"$UNAME_RELEASE" # Stardent Vistra i860-SVR4 else # Add other i860-SVR4 vendors below as they are discovered. - echo i860-${VENODR}-sysv${UNAME_RELEASE} # Unknown i860-SVR4 + echo i860-unknown-sysv"$UNAME_RELEASE" # Unknown i860-SVR4 fi exit ;; mini*:CTIX:SYS*5:*) @@ -1179,41 +1229,41 @@ 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` + && 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; } + && { 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; } ;; + && { 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` + && 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; } + && { 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; } + && { 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; } ;; + && { echo i586-ncr-sysv4.3"$OS_REL"; exit; } ;; m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) - echo m68k-${VENDOR}-lynxos${UNAME_RELEASE} + echo m68k-unknown-lynxos"$UNAME_RELEASE" exit ;; mc68030:UNIX_System_V:4.*:*) echo m68k-atari-sysv4 exit ;; TSUNAMI:LynxOS:2.*:*) - echo sparc-${VENDOR}-lynxos${UNAME_RELEASE} + echo sparc-unknown-lynxos"$UNAME_RELEASE" exit ;; rs6000:LynxOS:2.*:*) - echo rs6000-${VENDOR}-lynxos${UNAME_RELEASE} + echo rs6000-unknown-lynxos"$UNAME_RELEASE" exit ;; PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.[02]*:*) - echo powerpc-${VENDOR}-lynxos${UNAME_RELEASE} + echo powerpc-unknown-lynxos"$UNAME_RELEASE" exit ;; SM[BE]S:UNIX_SV:*:*) - echo mips-dde-sysv${UNAME_RELEASE} + echo mips-dde-sysv"$UNAME_RELEASE" exit ;; RM*:ReliantUNIX-*:*:*) echo mips-sni-sysv4 @@ -1223,8 +1273,8 @@ exit ;; *:SINIX-*:*:*) if uname -p 2>/dev/null >/dev/null ; then - UNAME_MACHINE=`(uname -p) 2>/dev/null` - echo ${UNAME_MACHINE}-sni-sysv4 + UNAME_MACHINE=$( (uname -p) 2>/dev/null) + echo "$UNAME_MACHINE"-sni-sysv4 else echo ns32k-sni-sysv fi @@ -1244,23 +1294,23 @@ exit ;; i*86:VOS:*:*) # From Paul.Green@stratus.com. - echo ${UNAME_MACHINE}-stratus-vos + 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} + 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} + if test -d /usr/nec; then + echo mips-nec-sysv"$UNAME_RELEASE" else - echo mips-${VENDOR}-sysv${UNAME_RELEASE} + echo mips-unknown-sysv"$UNAME_RELEASE" fi exit ;; BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. @@ -1276,93 +1326,100 @@ echo i586-pc-haiku exit ;; x86_64:Haiku:*:*) - echo x86_64-${VENDOR}-haiku + echo x86_64-unknown-haiku exit ;; SX-4:SUPER-UX:*:*) - echo sx4-nec-superux${UNAME_RELEASE} + echo sx4-nec-superux"$UNAME_RELEASE" exit ;; SX-5:SUPER-UX:*:*) - echo sx5-nec-superux${UNAME_RELEASE} + echo sx5-nec-superux"$UNAME_RELEASE" exit ;; SX-6:SUPER-UX:*:*) - echo sx6-nec-superux${UNAME_RELEASE} + echo sx6-nec-superux"$UNAME_RELEASE" exit ;; SX-7:SUPER-UX:*:*) - echo sx7-nec-superux${UNAME_RELEASE} + echo sx7-nec-superux"$UNAME_RELEASE" exit ;; SX-8:SUPER-UX:*:*) - echo sx8-nec-superux${UNAME_RELEASE} + echo sx8-nec-superux"$UNAME_RELEASE" exit ;; SX-8R:SUPER-UX:*:*) - echo sx8r-nec-superux${UNAME_RELEASE} + echo sx8r-nec-superux"$UNAME_RELEASE" exit ;; SX-ACE:SUPER-UX:*:*) - echo sxace-nec-superux${UNAME_RELEASE} + echo sxace-nec-superux"$UNAME_RELEASE" exit ;; Power*:Rhapsody:*:*) - echo powerpc-apple-rhapsody${UNAME_RELEASE} + echo powerpc-apple-rhapsody"$UNAME_RELEASE" exit ;; *:Rhapsody:*:*) - echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE} + echo "$UNAME_MACHINE"-apple-rhapsody"$UNAME_RELEASE" + exit ;; + arm64:Darwin:*:*) + echo aarch64-apple-darwin"$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 - # On 10.4-10.6 one might compile for PowerPC via gcc -arch ppc - if (echo '#ifdef __POWERPC__'; echo IS_PPC; echo '#endif') | \ - (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ - grep IS_PPC >/dev/null - then - UNAME_PROCESSOR=powerpc - fi + UNAME_PROCESSOR=$(uname -p) + case $UNAME_PROCESSOR in + unknown) UNAME_PROCESSOR=powerpc ;; + esac + if command -v xcode-select > /dev/null 2> /dev/null && \ + ! xcode-select --print-path > /dev/null 2> /dev/null ; then + # Avoid executing cc if there is no toolchain installed as + # cc will be a stub that puts up a graphical alert + # prompting the user to install developer tools. + CC_FOR_BUILD=no_compiler_found + else + set_cc_for_build + fi + if test "$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 + # On 10.4-10.6 one might compile for PowerPC via gcc -arch ppc + if (echo '#ifdef __POWERPC__'; echo IS_PPC; echo '#endif') | \ + (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ + grep IS_PPC >/dev/null + then + UNAME_PROCESSOR=powerpc 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 + # uname -m returns i386 or x86_64 + UNAME_PROCESSOR=$UNAME_MACHINE fi - echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE} + echo "$UNAME_PROCESSOR"-apple-darwin"$UNAME_RELEASE" exit ;; *:procnto*:*:* | *:QNX:[0123456789]*:*) - UNAME_PROCESSOR=`uname -p` + 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} + 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} + echo neo-tandem-nsk"$UNAME_RELEASE" exit ;; NSE-*:NONSTOP_KERNEL:*:*) - echo nse-tandem-nsk${UNAME_RELEASE} + echo nse-tandem-nsk"$UNAME_RELEASE" exit ;; NSR-*:NONSTOP_KERNEL:*:*) - echo nsr-tandem-nsk${UNAME_RELEASE} + echo nsr-tandem-nsk"$UNAME_RELEASE" + exit ;; + NSV-*:NONSTOP_KERNEL:*:*) + echo nsv-tandem-nsk"$UNAME_RELEASE" exit ;; NSX-*:NONSTOP_KERNEL:*:*) - echo nsx-tandem-nsk${UNAME_RELEASE} + echo nsx-tandem-nsk"$UNAME_RELEASE" exit ;; *:NonStop-UX:*:*) echo mips-compaq-nonstopux @@ -1371,24 +1428,25 @@ echo bs2000-siemens-sysv exit ;; DS/*:UNIX_System_V:*:*) - echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE} + 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. + # shellcheck disable=SC2154 if test "$cputype" = 386; then UNAME_MACHINE=i386 else UNAME_MACHINE="$cputype" fi - echo ${UNAME_MACHINE}-${VENDOR}-plan9 + echo "$UNAME_MACHINE"-unknown-plan9 exit ;; *:TOPS-10:*:*) - echo pdp10-${VENDOR}-tops10 + echo pdp10-unknown-tops10 exit ;; *:TENEX:*:*) - echo pdp10-${VENDOR}-tenex + echo pdp10-unknown-tenex exit ;; KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*) echo pdp10-dec-tops20 @@ -1397,20 +1455,20 @@ echo pdp10-xkl-tops20 exit ;; *:TOPS-20:*:*) - echo pdp10-${VENDOR}-tops20 + echo pdp10-unknown-tops20 exit ;; *:ITS:*:*) - echo pdp10-${VENDOR}-its + echo pdp10-unknown-its exit ;; SEI:*:*:SEIUX) - echo mips-sei-seiux${UNAME_RELEASE} + echo mips-sei-seiux"$UNAME_RELEASE" exit ;; *:DragonFly:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` + echo "$UNAME_MACHINE"-unknown-dragonfly"$(echo "$UNAME_RELEASE"|sed -e 's/[-(].*//')" exit ;; *:*VMS:*:*) - UNAME_MACHINE=`(uname -p) 2>/dev/null` - case "${UNAME_MACHINE}" in + 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 ;; @@ -1419,32 +1477,190 @@ echo i386-pc-xenix exit ;; i*86:skyos:*:*) - echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE} | sed -e 's/ .*$//'` + echo "$UNAME_MACHINE"-pc-skyos"$(echo "$UNAME_RELEASE" | sed -e 's/ .*$//')" exit ;; i*86:rdos:*:*) - echo ${UNAME_MACHINE}-pc-rdos + echo "$UNAME_MACHINE"-pc-rdos exit ;; - i*86:AROS:*:*) - echo ${UNAME_MACHINE}-pc-aros + *:AROS:*:*) + echo "$UNAME_MACHINE"-unknown-aros exit ;; x86_64:VMkernel:*:*) - echo ${UNAME_MACHINE}-${VENDOR}-esx + echo "$UNAME_MACHINE"-unknown-esx exit ;; amd64:Isilon\ OneFS:*:*) - echo x86_64-${VENDOR}-onefs + echo x86_64-unknown-onefs + exit ;; + *:Unleashed:*:*) + echo "$UNAME_MACHINE"-unknown-unleashed"$UNAME_RELEASE" exit ;; esac +# No uname command or uname output not recognized. +set_cc_for_build +cat > "$dummy.c" < +#include +#endif +#if defined(ultrix) || defined(_ultrix) || defined(__ultrix) || defined(__ultrix__) +#if defined (vax) || defined (__vax) || defined (__vax__) || defined(mips) || defined(__mips) || defined(__mips__) || defined(MIPS) || defined(__MIPS__) +#include +#if defined(_SIZE_T_) || defined(SIGLOST) +#include +#endif +#endif +#endif +main () +{ +#if defined (sony) +#if defined (MIPSEB) + /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed, + I don't know.... */ + printf ("mips-sony-bsd\n"); exit (0); +#else +#include + printf ("m68k-sony-newsos%s\n", +#ifdef NEWSOS4 + "4" +#else + "" +#endif + ); exit (0); +#endif +#endif + +#if defined (NeXT) +#if !defined (__ARCHITECTURE__) +#define __ARCHITECTURE__ "m68k" +#endif + int version; + version=$( (hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null); + if (version < 4) + printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version); + else + printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version); + exit (0); +#endif + +#if defined (MULTIMAX) || defined (n16) +#if defined (UMAXV) + printf ("ns32k-encore-sysv\n"); exit (0); +#else +#if defined (CMU) + printf ("ns32k-encore-mach\n"); exit (0); +#else + printf ("ns32k-encore-bsd\n"); exit (0); +#endif +#endif +#endif + +#if defined (__386BSD__) + printf ("i386-pc-bsd\n"); exit (0); +#endif + +#if defined (sequent) +#if defined (i386) + printf ("i386-sequent-dynix\n"); exit (0); +#endif +#if defined (ns32000) + printf ("ns32k-sequent-dynix\n"); exit (0); +#endif +#endif + +#if defined (_SEQUENT_) + struct utsname un; + + uname(&un); + if (strncmp(un.version, "V2", 2) == 0) { + printf ("i386-sequent-ptx2\n"); exit (0); + } + if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */ + printf ("i386-sequent-ptx1\n"); exit (0); + } + printf ("i386-sequent-ptx\n"); exit (0); +#endif + +#if defined (vax) +#if !defined (ultrix) +#include +#if defined (BSD) +#if BSD == 43 + printf ("vax-dec-bsd4.3\n"); exit (0); +#else +#if BSD == 199006 + printf ("vax-dec-bsd4.3reno\n"); exit (0); +#else + printf ("vax-dec-bsd\n"); exit (0); +#endif +#endif +#else + printf ("vax-dec-bsd\n"); exit (0); +#endif +#else +#if defined(_SIZE_T_) || defined(SIGLOST) + struct utsname un; + uname (&un); + printf ("vax-dec-ultrix%s\n", un.release); exit (0); +#else + printf ("vax-dec-ultrix\n"); exit (0); +#endif +#endif +#endif +#if defined(ultrix) || defined(_ultrix) || defined(__ultrix) || defined(__ultrix__) +#if defined(mips) || defined(__mips) || defined(__mips__) || defined(MIPS) || defined(__MIPS__) +#if defined(_SIZE_T_) || defined(SIGLOST) + struct utsname *un; + uname (&un); + printf ("mips-dec-ultrix%s\n", un.release); exit (0); +#else + printf ("mips-dec-ultrix\n"); exit (0); +#endif +#endif +#endif + +#if defined (alliant) && defined (i860) + printf ("i860-alliant-bsd\n"); exit (0); +#endif + + exit (1); +} +EOF + +$CC_FOR_BUILD -o "$dummy" "$dummy.c" 2>/dev/null && SYSTEM_NAME=$($dummy) && + { echo "$SYSTEM_NAME"; exit; } + +# Apollos put the system type in the environment. +test -d /usr/apollo && { echo "$ISP-apollo-$SYSTYPE"; exit; } + +echo "$0: unable to guess system type" >&2 + +case "$UNAME_MACHINE:$UNAME_SYSTEM" in + mips:Linux | mips64:Linux) + # If we got here on MIPS GNU/Linux, output extra information. + cat >&2 <&2 <&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} +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 +fi exit 1 # Local variables: -# eval: (add-hook 'write-file-hooks 'time-stamp) +# eval: (add-hook 'before-save-hook 'time-stamp) # time-stamp-start: "timestamp='" # time-stamp-format: "%:y-%02m-%02d" # time-stamp-end: "'" diff -Nru cpl-7.1.4+ds/libcext/admin/config.sub cpl-7.2.2+ds/libcext/admin/config.sub --- cpl-7.1.4+ds/libcext/admin/config.sub 2021-05-07 12:09:58.000000000 +0000 +++ cpl-7.2.2+ds/libcext/admin/config.sub 2022-04-29 14:56:23.000000000 +0000 @@ -1,8 +1,8 @@ #! /bin/sh # Configuration validation subroutine script. -# Copyright 1992-2017 Free Software Foundation, Inc. +# Copyright 1992-2021 Free Software Foundation, Inc. -timestamp='2017-04-02' +timestamp='2021-01-08' # 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 @@ -15,7 +15,7 @@ # 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 . +# 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 @@ -33,7 +33,7 @@ # 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 +# https://git.savannah.gnu.org/cgit/config.git/plain/config.sub # This file is supposed to be the same for all GNU packages # and recognize all the CPU types, system types and aliases @@ -50,14 +50,14 @@ # CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM # It is wrong to echo any other type of specification. -me=`echo "$0" | sed -e 's,.*/,,'` +me=$(echo "$0" | sed -e 's,.*/,,') usage="\ Usage: $0 [OPTION] CPU-MFR-OPSYS or ALIAS Canonicalize a configuration name. -Operation modes: +Options: -h, --help print this help, then exit -t, --time-stamp print date of last modification, then exit -v, --version print version number, then exit @@ -67,7 +67,7 @@ version="\ GNU config.sub ($timestamp) -Copyright 1992-2017 Free Software Foundation, Inc. +Copyright 1992-2021 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." @@ -89,12 +89,12 @@ - ) # Use stdin as input. break ;; -* ) - echo "$me: invalid option $1$help" + echo "$me: invalid option $1$help" >&2 exit 1 ;; *local*) # First pass through any local machine types. - echo $1 + echo "$1" exit ;; * ) @@ -110,1258 +110,1169 @@ 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* | netbsd*-eabi* | \ - kopensolaris*-gnu* | cloudabi*-eabi* | \ - 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 +# Split fields of configuration type +# shellcheck disable=SC2162 +IFS="-" read field1 field2 field3 field4 <&2 + exit 1 ;; - -ptx*) - basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'` + *-*-*-*) + basic_machine=$field1-$field2 + basic_os=$field3-$field4 ;; - -windowsnt*) - os=`echo $os | sed -e 's/windowsnt/winnt/'` + *-*-*) + # Ambiguous whether COMPANY is present, or skipped and KERNEL-OS is two + # parts + maybe_os=$field2-$field3 + case $maybe_os in + nto-qnx* | linux-* | uclinux-uclibc* \ + | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* \ + | netbsd*-eabi* | kopensolaris*-gnu* | cloudabi*-eabi* \ + | storm-chaos* | os2-emx* | rtmk-nova*) + basic_machine=$field1 + basic_os=$maybe_os + ;; + android-linux) + basic_machine=$field1-unknown + basic_os=linux-android + ;; + *) + basic_machine=$field1-$field2 + basic_os=$field3 + ;; + esac ;; - -psos*) - os=-psos + *-*) + # A lone config we happen to match not fitting any pattern + case $field1-$field2 in + decstation-3100) + basic_machine=mips-dec + basic_os= + ;; + *-*) + # Second component is usually, but not always the OS + case $field2 in + # Prevent following clause from handling this valid os + sun*os*) + basic_machine=$field1 + basic_os=$field2 + ;; + # Manufacturers + dec* | mips* | sequent* | encore* | pc533* | 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* | sim | cisco \ + | oki | wec | wrs | winbond) + basic_machine=$field1-$field2 + basic_os= + ;; + *) + basic_machine=$field1 + basic_os=$field2 + ;; + esac + ;; + esac ;; - -mint | -mint[0-9]*) - basic_machine=m68k-atari - os=-mint + *) + # Convert single-component short-hands not valid as part of + # multi-component configurations. + case $field1 in + 386bsd) + basic_machine=i386-pc + basic_os=bsd + ;; + a29khif) + basic_machine=a29k-amd + basic_os=udi + ;; + adobe68k) + basic_machine=m68010-adobe + basic_os=scout + ;; + alliant) + basic_machine=fx80-alliant + basic_os= + ;; + altos | altos3068) + basic_machine=m68k-altos + basic_os= + ;; + am29k) + basic_machine=a29k-none + basic_os=bsd + ;; + amdahl) + basic_machine=580-amdahl + basic_os=sysv + ;; + amiga) + basic_machine=m68k-unknown + basic_os= + ;; + amigaos | amigados) + basic_machine=m68k-unknown + basic_os=amigaos + ;; + amigaunix | amix) + basic_machine=m68k-unknown + basic_os=sysv4 + ;; + apollo68) + basic_machine=m68k-apollo + basic_os=sysv + ;; + apollo68bsd) + basic_machine=m68k-apollo + basic_os=bsd + ;; + aros) + basic_machine=i386-pc + basic_os=aros + ;; + aux) + basic_machine=m68k-apple + basic_os=aux + ;; + balance) + basic_machine=ns32k-sequent + basic_os=dynix + ;; + blackfin) + basic_machine=bfin-unknown + basic_os=linux + ;; + cegcc) + basic_machine=arm-unknown + basic_os=cegcc + ;; + convex-c1) + basic_machine=c1-convex + basic_os=bsd + ;; + convex-c2) + basic_machine=c2-convex + basic_os=bsd + ;; + convex-c32) + basic_machine=c32-convex + basic_os=bsd + ;; + convex-c34) + basic_machine=c34-convex + basic_os=bsd + ;; + convex-c38) + basic_machine=c38-convex + basic_os=bsd + ;; + cray) + basic_machine=j90-cray + basic_os=unicos + ;; + crds | unos) + basic_machine=m68k-crds + basic_os= + ;; + da30) + basic_machine=m68k-da30 + basic_os= + ;; + decstation | pmax | pmin | dec3100 | decstatn) + basic_machine=mips-dec + basic_os= + ;; + delta88) + basic_machine=m88k-motorola + basic_os=sysv3 + ;; + dicos) + basic_machine=i686-pc + basic_os=dicos + ;; + djgpp) + basic_machine=i586-pc + basic_os=msdosdjgpp + ;; + ebmon29k) + basic_machine=a29k-amd + basic_os=ebmon + ;; + es1800 | OSE68k | ose68k | ose | OSE) + basic_machine=m68k-ericsson + basic_os=ose + ;; + gmicro) + basic_machine=tron-gmicro + basic_os=sysv + ;; + go32) + basic_machine=i386-pc + basic_os=go32 + ;; + h8300hms) + basic_machine=h8300-hitachi + basic_os=hms + ;; + h8300xray) + basic_machine=h8300-hitachi + basic_os=xray + ;; + h8500hms) + basic_machine=h8500-hitachi + basic_os=hms + ;; + harris) + basic_machine=m88k-harris + basic_os=sysv3 + ;; + hp300 | hp300hpux) + basic_machine=m68k-hp + basic_os=hpux + ;; + hp300bsd) + basic_machine=m68k-hp + basic_os=bsd + ;; + hppaosf) + basic_machine=hppa1.1-hp + basic_os=osf + ;; + hppro) + basic_machine=hppa1.1-hp + basic_os=proelf + ;; + i386mach) + basic_machine=i386-mach + basic_os=mach + ;; + isi68 | isi) + basic_machine=m68k-isi + basic_os=sysv + ;; + m68knommu) + basic_machine=m68k-unknown + basic_os=linux + ;; + magnum | m3230) + basic_machine=mips-mips + basic_os=sysv + ;; + merlin) + basic_machine=ns32k-utek + basic_os=sysv + ;; + mingw64) + basic_machine=x86_64-pc + basic_os=mingw64 + ;; + mingw32) + basic_machine=i686-pc + basic_os=mingw32 + ;; + mingw32ce) + basic_machine=arm-unknown + basic_os=mingw32ce + ;; + monitor) + basic_machine=m68k-rom68k + basic_os=coff + ;; + morphos) + basic_machine=powerpc-unknown + basic_os=morphos + ;; + moxiebox) + basic_machine=moxie-unknown + basic_os=moxiebox + ;; + msdos) + basic_machine=i386-pc + basic_os=msdos + ;; + msys) + basic_machine=i686-pc + basic_os=msys + ;; + mvs) + basic_machine=i370-ibm + basic_os=mvs + ;; + nacl) + basic_machine=le32-unknown + basic_os=nacl + ;; + ncr3000) + basic_machine=i486-ncr + basic_os=sysv4 + ;; + netbsd386) + basic_machine=i386-pc + basic_os=netbsd + ;; + netwinder) + basic_machine=armv4l-rebel + basic_os=linux + ;; + news | news700 | news800 | news900) + basic_machine=m68k-sony + basic_os=newsos + ;; + news1000) + basic_machine=m68030-sony + basic_os=newsos + ;; + necv70) + basic_machine=v70-nec + basic_os=sysv + ;; + nh3000) + basic_machine=m68k-harris + basic_os=cxux + ;; + nh[45]000) + basic_machine=m88k-harris + basic_os=cxux + ;; + nindy960) + basic_machine=i960-intel + basic_os=nindy + ;; + mon960) + basic_machine=i960-intel + basic_os=mon960 + ;; + nonstopux) + basic_machine=mips-compaq + basic_os=nonstopux + ;; + os400) + basic_machine=powerpc-ibm + basic_os=os400 + ;; + OSE68000 | ose68000) + basic_machine=m68000-ericsson + basic_os=ose + ;; + os68k) + basic_machine=m68k-none + basic_os=os68k + ;; + paragon) + basic_machine=i860-intel + basic_os=osf + ;; + parisc) + basic_machine=hppa-unknown + basic_os=linux + ;; + psp) + basic_machine=mipsallegrexel-sony + basic_os=psp + ;; + pw32) + basic_machine=i586-unknown + basic_os=pw32 + ;; + rdos | rdos64) + basic_machine=x86_64-pc + basic_os=rdos + ;; + rdos32) + basic_machine=i386-pc + basic_os=rdos + ;; + rom68k) + basic_machine=m68k-rom68k + basic_os=coff + ;; + sa29200) + basic_machine=a29k-amd + basic_os=udi + ;; + sei) + basic_machine=mips-sei + basic_os=seiux + ;; + sequent) + basic_machine=i386-sequent + basic_os= + ;; + sps7) + basic_machine=m68k-bull + basic_os=sysv2 + ;; + st2000) + basic_machine=m68k-tandem + basic_os= + ;; + stratus) + basic_machine=i860-stratus + basic_os=sysv4 + ;; + sun2) + basic_machine=m68000-sun + basic_os= + ;; + sun2os3) + basic_machine=m68000-sun + basic_os=sunos3 + ;; + sun2os4) + basic_machine=m68000-sun + basic_os=sunos4 + ;; + sun3) + basic_machine=m68k-sun + basic_os= + ;; + sun3os3) + basic_machine=m68k-sun + basic_os=sunos3 + ;; + sun3os4) + basic_machine=m68k-sun + basic_os=sunos4 + ;; + sun4) + basic_machine=sparc-sun + basic_os= + ;; + sun4os3) + basic_machine=sparc-sun + basic_os=sunos3 + ;; + sun4os4) + basic_machine=sparc-sun + basic_os=sunos4 + ;; + sun4sol2) + basic_machine=sparc-sun + basic_os=solaris2 + ;; + sun386 | sun386i | roadrunner) + basic_machine=i386-sun + basic_os= + ;; + sv1) + basic_machine=sv1-cray + basic_os=unicos + ;; + symmetry) + basic_machine=i386-sequent + basic_os=dynix + ;; + t3e) + basic_machine=alphaev5-cray + basic_os=unicos + ;; + t90) + basic_machine=t90-cray + basic_os=unicos + ;; + toad1) + basic_machine=pdp10-xkl + basic_os=tops20 + ;; + tpf) + basic_machine=s390x-ibm + basic_os=tpf + ;; + udi29k) + basic_machine=a29k-amd + basic_os=udi + ;; + ultra3) + basic_machine=a29k-nyu + basic_os=sym1 + ;; + v810 | necv810) + basic_machine=v810-nec + basic_os=none + ;; + vaxv) + basic_machine=vax-dec + basic_os=sysv + ;; + vms) + basic_machine=vax-dec + basic_os=vms + ;; + vsta) + basic_machine=i386-pc + basic_os=vsta + ;; + vxworks960) + basic_machine=i960-wrs + basic_os=vxworks + ;; + vxworks68) + basic_machine=m68k-wrs + basic_os=vxworks + ;; + vxworks29k) + basic_machine=a29k-wrs + basic_os=vxworks + ;; + xbox) + basic_machine=i686-pc + basic_os=mingw32 + ;; + ymp) + basic_machine=ymp-cray + basic_os=unicos + ;; + *) + basic_machine=$1 + basic_os= + ;; + esac ;; esac -# Decode aliases for certain CPU-COMPANY combinations. +# Decode 1-component or ad-hoc basic machines 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 \ - | ba \ - | be32 | be64 \ - | bfin \ - | c4x | c8051 | clipper \ - | d10v | d30v | dlx | dsp16xx \ - | e2k | epiphany \ - | fido | fr30 | frv | ft32 \ - | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \ - | hexagon \ - | i370 | i860 | i960 | ia16 | 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 \ - | pru \ - | pyramid \ - | riscv32 | riscv64 \ - | rl78 | rx \ - | score \ - | sh | sh[1234] | sh[24]a | sh[24]aeb | sh[23]e | sh[234]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 \ - | wasm32 \ - | 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 + # 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) + cpu=hppa1.1 + vendor=winbond ;; - m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k) + op50n) + cpu=hppa1.1 + vendor=oki ;; - ms1) - basic_machine=mt-unknown + op60c) + cpu=hppa1.1 + vendor=oki ;; - - strongarm | thumb | xscale) - basic_machine=arm-unknown + ibm*) + cpu=i370 + vendor=ibm ;; - xgate) - basic_machine=$basic_machine-unknown - os=-none + orion105) + cpu=clipper + vendor=highlevel ;; - xscaleeb) - basic_machine=armeb-unknown + mac | mpw | mac-mpw) + cpu=m68k + vendor=apple ;; - - xscaleel) - basic_machine=armel-unknown + pmac | pmac-mpw) + cpu=powerpc + vendor=apple ;; - # 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-* \ - | ba-* \ - | be32-* | be64-* \ - | bfin-* | bs2000-* \ - | c[123]* | c30-* | [cjt]90-* | c4x-* \ - | c8051-* | clipper-* | craynv-* | cydra-* \ - | d10v-* | d30v-* | dlx-* \ - | e2k-* | elxsi-* \ - | f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \ - | h8300-* | h8500-* \ - | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \ - | hexagon-* \ - | i*86-* | i860-* | i960-* | ia16-* | 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-* \ - | pru-* \ - | pyramid-* \ - | riscv32-* | riscv64-* \ - | 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-* \ - | wasm32-* \ - | 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 + cpu=m68000 + vendor=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 - ;; - asmjs) - basic_machine=asmjs-unknown - ;; - 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 + cpu=we32k + vendor=att ;; 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 + cpu=powerpc + vendor=ibm + basic_os=cnk ;; decsystem10* | dec10*) - basic_machine=pdp10-dec - os=-tops10 + cpu=pdp10 + vendor=dec + basic_os=tops10 ;; decsystem20* | dec20*) - basic_machine=pdp10-dec - os=-tops20 + cpu=pdp10 + vendor=dec + basic_os=tops20 ;; delta | 3300 | motorola-3300 | motorola-delta \ | 3300-motorola | delta-motorola) - basic_machine=m68k-motorola + cpu=m68k + vendor=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 - ;; - e500v[12]) - basic_machine=powerpc-unknown - os=$os"spe" - ;; - e500v[12]-*) - basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'` - os=$os"spe" - ;; - ebmon29k) - basic_machine=a29k-amd - os=-ebmon - ;; - elxsi) - basic_machine=elxsi-elxsi - os=-bsd + dpx2*) + cpu=m68k + vendor=bull + basic_os=sysv3 ;; encore | umax | mmax) - basic_machine=ns32k-encore + cpu=ns32k + vendor=encore ;; - es1800 | OSE68k | ose68k | ose | OSE) - basic_machine=m68k-ericsson - os=-ose + elxsi) + cpu=elxsi + vendor=elxsi + basic_os=${basic_os:-bsd} ;; fx2800) - basic_machine=i860-alliant + cpu=i860 + vendor=alliant ;; genix) - basic_machine=ns32k-ns - ;; - gmicro) - basic_machine=tron-gmicro - os=-sysv - ;; - go32) - basic_machine=i386-pc - os=-go32 + cpu=ns32k + vendor=ns ;; 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 + cpu=hppa1.1 + vendor=hitachi + basic_os=hiuxwe2 ;; hp3k9[0-9][0-9] | hp9[0-9][0-9]) - basic_machine=hppa1.0-hp + cpu=hppa1.0 + vendor=hp ;; hp9k2[0-9][0-9] | hp9k31[0-9]) - basic_machine=m68000-hp + cpu=m68000 + vendor=hp ;; hp9k3[2-9][0-9]) - basic_machine=m68k-hp + cpu=m68k + vendor=hp ;; hp9k6[0-9][0-9] | hp6[0-9][0-9]) - basic_machine=hppa1.0-hp + cpu=hppa1.0 + vendor=hp ;; hp9k7[0-79][0-9] | hp7[0-79][0-9]) - basic_machine=hppa1.1-hp + cpu=hppa1.1 + vendor=hp ;; hp9k78[0-9] | hp78[0-9]) # FIXME: really hppa2.0-hp - basic_machine=hppa1.1-hp + cpu=hppa1.1 + vendor=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 + cpu=hppa1.1 + vendor=hp ;; hp9k8[0-9][13679] | hp8[0-9][13679]) - basic_machine=hppa1.1-hp + cpu=hppa1.1 + vendor=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 + cpu=hppa1.0 + vendor=hp ;; i*86v32) - basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` - os=-sysv32 + cpu=$(echo "$1" | sed -e 's/86.*/86/') + vendor=pc + basic_os=sysv32 ;; i*86v4*) - basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` - os=-sysv4 + cpu=$(echo "$1" | sed -e 's/86.*/86/') + vendor=pc + basic_os=sysv4 ;; i*86v) - basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` - os=-sysv + cpu=$(echo "$1" | sed -e 's/86.*/86/') + vendor=pc + basic_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 + cpu=$(echo "$1" | sed -e 's/86.*/86/') + vendor=pc + basic_os=solaris2 + ;; + j90 | j90-cray) + cpu=j90 + vendor=cray + basic_os=${basic_os:-unicos} ;; iris | iris4d) - basic_machine=mips-sgi - case $os in - -irix*) + cpu=mips + vendor=sgi + case $basic_os in + irix*) ;; *) - os=-irix4 + basic_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-/'` + cpu=m68000 + vendor=convergent ;; - 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 + *mint | mint[0-9]* | *MiNT | *MiNT[0-9]*) + cpu=m68k + vendor=atari + basic_os=mint ;; 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* ) + cpu=mips + vendor=sony + basic_os=newsos + ;; + next | m*-next) + cpu=m68k + vendor=next + case $basic_os in + openstep*) + ;; + nextstep*) ;; - -ns2*) - os=-nextstep2 + ns2*) + basic_os=nextstep2 ;; *) - os=-nextstep3 + basic_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 - ;; - nsx-tandem) - basic_machine=nsx-tandem + cpu=np1 + vendor=gould ;; 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 + cpu=hppa1.1 + vendor=oki + basic_os=proelf ;; 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 + cpu=hppa1.1 + vendor=hitachi + basic_os=hiuxwe2 ;; pbd) - basic_machine=sparc-tti + cpu=sparc + vendor=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 + cpu=m68k + vendor=tti ;; - pentiumii | pentium2 | pentiumiii | pentium3) - basic_machine=i686-pc + pc532) + cpu=ns32k + vendor=pc532 ;; - 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/^[^-]*-//'` + pn) + cpu=pn + vendor=gould ;; - pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*) - basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` + power) + cpu=power + vendor=ibm ;; - pentium4-*) - basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'` + ps2) + cpu=i386 + vendor=ibm ;; - pn) - basic_machine=pn-gould + rm[46]00) + cpu=mips + vendor=siemens ;; - power) basic_machine=power-ibm + rtpc | rtpc-*) + cpu=romp + vendor=ibm ;; - ppc | ppcbe) basic_machine=powerpc-unknown + sde) + cpu=mipsisa32 + vendor=sde + basic_os=${basic_os:-elf} + ;; + simso-wrs) + cpu=sparclite + vendor=wrs + basic_os=vxworks ;; - ppc-* | ppcbe-*) - basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'` + tower | tower-32) + cpu=m68k + vendor=ncr ;; - ppcle | powerpclittle) - basic_machine=powerpcle-unknown + vpp*|vx|vx-*) + cpu=f301 + vendor=fujitsu ;; - ppcle-* | powerpclittle-*) - basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'` + w65) + cpu=w65 + vendor=wdc ;; - ppc64) basic_machine=powerpc64-unknown + w89k-*) + cpu=hppa1.1 + vendor=winbond + basic_os=proelf ;; - ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'` + none) + cpu=none + vendor=none ;; - ppc64le | powerpc64little) - basic_machine=powerpc64le-unknown + leon|leon[3-9]) + cpu=sparc + vendor=$basic_machine ;; - ppc64le-* | powerpc64little-*) - basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'` + leon-*|leon[3-9]-*) + cpu=sparc + vendor=$(echo "$basic_machine" | sed 's/-.*//') ;; - ps2) - basic_machine=i386-ibm + + *-*) + # shellcheck disable=SC2162 + IFS="-" read cpu vendor <&2 - exit 1 + # Recognize the canonical CPU types that are allowed with any + # company name. + case $cpu in + 1750a | 580 \ + | a29k \ + | aarch64 | aarch64_be \ + | abacus \ + | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] \ + | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] \ + | alphapca5[67] | alpha64pca5[67] \ + | am33_2.0 \ + | amdgcn \ + | arc | arceb \ + | arm | arm[lb]e | arme[lb] | armv* \ + | avr | avr32 \ + | asmjs \ + | ba \ + | be32 | be64 \ + | bfin | bpf | bs2000 \ + | c[123]* | c30 | [cjt]90 | c4x \ + | c8051 | clipper | craynv | csky | cydra \ + | d10v | d30v | dlx | dsp16xx \ + | e2k | elxsi | epiphany \ + | f30[01] | f700 | fido | fr30 | frv | ft32 | fx80 \ + | h8300 | h8500 \ + | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \ + | hexagon \ + | i370 | i*86 | i860 | i960 | ia16 | ia64 \ + | ip2k | iq2000 \ + | k1om \ + | le32 | le64 \ + | lm32 \ + | loongarch32 | loongarch64 | loongarchx32 \ + | m32c | m32r | m32rle \ + | m5200 | m68000 | m680[012346]0 | m68360 | m683?2 | m68k \ + | m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x \ + | m88110 | m88k | maxq | mb | mcore | mep | metag \ + | microblaze | microblazeel \ + | mips | mipsbe | mipseb | mipsel | mipsle \ + | mips16 \ + | mips64 | mips64eb | 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 \ + | mn10200 | mn10300 \ + | moxie \ + | mt \ + | msp430 \ + | nds32 | nds32le | nds32be \ + | nfp \ + | nios | nios2 | nios2eb | nios2el \ + | none | np1 | ns16k | ns32k | nvptx \ + | open8 \ + | or1k* \ + | or32 \ + | orion \ + | picochip \ + | pdp10 | pdp11 | pj | pjl | pn | power \ + | powerpc | powerpc64 | powerpc64le | powerpcle | powerpcspe \ + | pru \ + | pyramid \ + | riscv | riscv32 | riscv32be | riscv64 | riscv64be \ + | rl78 | romp | rs6000 | rx \ + | s390 | s390x \ + | score \ + | sh | shl \ + | sh[1234] | sh[24]a | sh[24]ae[lb] | sh[23]e | she[lb] | sh[lb]e \ + | sh[1234]e[lb] | sh[12345][lb]e | sh[23]ele | sh64 | sh64le \ + | sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet \ + | sparclite \ + | sparcv8 | sparcv9 | sparcv9b | sparcv9v | sv1 | sx* \ + | spu \ + | tahoe \ + | thumbv7* \ + | tic30 | tic4x | tic54x | tic55x | tic6x | tic80 \ + | tron \ + | ubicom32 \ + | v70 | v850 | v850e | v850e1 | v850es | v850e2 | v850e2v3 \ + | vax \ + | visium \ + | w65 \ + | wasm32 | wasm64 \ + | we32k \ + | x86 | x86_64 | xc16x | xgate | xps100 \ + | xstormy16 | xtensa* \ + | ymp \ + | z8k | z80) + ;; + + *) + echo Invalid configuration \`"$1"\': machine \`"$cpu-$vendor"\' not recognized 1>&2 + exit 1 + ;; + esac ;; esac # Here we canonicalize certain aliases for manufacturers. -case $basic_machine in - *-digital*) - basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'` +case $vendor in + digital*) + vendor=dec ;; - *-commodore*) - basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'` + commodore*) + vendor=cbm ;; *) ;; @@ -1369,203 +1280,213 @@ # Decode manufacturer-specific aliases for certain operating systems. -if [ x"$os" != x"" ] +if test x$basic_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 + +# First recognize some ad-hoc caes, or perhaps split kernel-os, or else just +# set os. +case $basic_os in + gnu/linux*) + kernel=linux + os=$(echo $basic_os | sed -e 's|gnu/linux|gnu|') + ;; + os2-emx) + kernel=os2 + os=$(echo $basic_os | sed -e 's|os2-emx|emx|') + ;; + nto-qnx*) + kernel=nto + os=$(echo $basic_os | sed -e 's|nto-qnx|qnx|') + ;; + *-*) + # shellcheck disable=SC2162 + IFS="-" read kernel os <&2 - exit 1 + # No normalization, but not necessarily accepted, that comes below. ;; esac + else # Here we handle the default operating systems that come with various machines. @@ -1578,264 +1499,361 @@ # will signal an error saying that MANUFACTURER isn't an operating # system, and we'll never get to this point. -case $basic_machine in +kernel= +case $cpu-$vendor in score-*) - os=-elf + os=elf ;; spu-*) - os=-elf + os=elf ;; *-acorn) - os=-riscix1.2 + os=riscix1.2 ;; arm*-rebel) - os=-linux + kernel=linux + os=gnu ;; arm*-semi) - os=-aout + os=aout ;; c4x-* | tic4x-*) - os=-coff + os=coff ;; c8051-*) - os=-elf + os=elf + ;; + clipper-intergraph) + os=clix ;; hexagon-*) - os=-elf + os=elf ;; tic54x-*) - os=-coff + os=coff ;; tic55x-*) - os=-coff + os=coff ;; tic6x-*) - os=-coff + os=coff ;; # This must come before the *-dec entry. pdp10-*) - os=-tops20 + os=tops20 ;; pdp11-*) - os=-none + os=none ;; *-dec | vax-*) - os=-ultrix4.2 + os=ultrix4.2 ;; m68*-apollo) - os=-domain + os=domain ;; i386-sun) - os=-sunos4.0.2 + os=sunos4.0.2 ;; m68000-sun) - os=-sunos3 + os=sunos3 ;; m68*-cisco) - os=-aout + os=aout ;; mep-*) - os=-elf + os=elf ;; mips*-cisco) - os=-elf + os=elf ;; mips*-*) - os=-elf + os=elf ;; or32-*) - os=-coff + os=coff ;; *-tti) # must be before sparc entry or we get the wrong os. - os=-sysv3 + os=sysv3 ;; sparc-* | *-sun) - os=-sunos4.1.1 + os=sunos4.1.1 ;; pru-*) - os=-elf + os=elf ;; *-be) - os=-beos - ;; - *-haiku) - os=-haiku + os=beos ;; *-ibm) - os=-aix + os=aix ;; *-knuth) - os=-mmixware + os=mmixware ;; *-wec) - os=-proelf + os=proelf ;; *-winbond) - os=-proelf + os=proelf ;; *-oki) - os=-proelf + os=proelf ;; *-hp) - os=-hpux + os=hpux ;; *-hitachi) - os=-hiux + os=hiux ;; i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent) - os=-sysv + os=sysv ;; *-cbm) - os=-amigaos + os=amigaos ;; *-dg) - os=-dgux + os=dgux ;; *-dolphin) - os=-sysv3 + os=sysv3 ;; m68k-ccur) - os=-rtu + os=rtu ;; m88k-omron*) - os=-luna + os=luna ;; - *-next ) - os=-nextstep + *-next) + os=nextstep ;; *-sequent) - os=-ptx + os=ptx ;; *-crds) - os=-unos + os=unos ;; *-ns) - os=-genix + os=genix ;; i370-*) - os=-mvs - ;; - *-next) - os=-nextstep3 + os=mvs ;; *-gould) - os=-sysv + os=sysv ;; *-highlevel) - os=-bsd + os=bsd ;; *-encore) - os=-bsd + os=bsd ;; *-sgi) - os=-irix + os=irix ;; *-siemens) - os=-sysv4 + os=sysv4 ;; *-masscomp) - os=-rtu + os=rtu ;; f30[01]-fujitsu | f700-fujitsu) - os=-uxpv + os=uxpv ;; *-rom68k) - os=-coff + os=coff ;; *-*bug) - os=-coff + os=coff ;; *-apple) - os=-macos + os=macos ;; *-atari*) - os=-mint + os=mint + ;; + *-wrs) + os=vxworks ;; *) - os=-none + os=none ;; esac + fi +# Now, validate our (potentially fixed-up) OS. +case $os in + # Sometimes we do "kernel-libc", so those need to count as OSes. + musl* | newlib* | uclibc*) + ;; + # Likewise for "kernel-abi" + eabi* | gnueabi*) + ;; + # VxWorks passes extra cpu info in the 4th filed. + simlinux | simwindows | spe) + ;; + # Now accept the basic system types. + # The portable systems comes first. + # Each alternative MUST end in a * to match a version number. + gnu* | android* | bsd* | mach* | minix* | genix* | ultrix* | irix* \ + | *vms* | esix* | aix* | cnk* | sunos | sunos[34]* \ + | hpux* | unos* | osf* | luna* | dgux* | auroraux* | solaris* \ + | sym* | plan9* | psp* | sim* | xray* | os68k* | v88r* \ + | hiux* | abug | nacl* | netware* | windows* \ + | os9* | macos* | osx* | ios* \ + | mpw* | magic* | mmixware* | mon960* | lnews* \ + | amigaos* | amigados* | msdos* | newsos* | unicos* | aof* \ + | aos* | aros* | cloudabi* | sortix* | twizzler* \ + | nindy* | vxsim* | vxworks* | ebmon* | hms* | mvs* \ + | clix* | riscos* | uniplus* | iris* | isc* | rtu* | xenix* \ + | mirbsd* | netbsd* | dicos* | openedition* | ose* \ + | bitrig* | openbsd* | solidbsd* | libertybsd* | os108* \ + | ekkobsd* | freebsd* | riscix* | lynxos* | os400* \ + | bosx* | nextstep* | cxux* | aout* | elf* | oabi* \ + | ptx* | coff* | ecoff* | winnt* | domain* | vsta* \ + | udi* | lites* | ieee* | go32* | aux* | hcos* \ + | chorusrdb* | cegcc* | glidix* \ + | cygwin* | msys* | pe* | moss* | proelf* | rtems* \ + | midipix* | mingw32* | mingw64* | mint* \ + | uxpv* | beos* | mpeix* | udk* | moxiebox* \ + | interix* | uwin* | mks* | rhapsody* | darwin* \ + | openstep* | oskit* | conix* | pw32* | nonstopux* \ + | storm-chaos* | tops10* | tenex* | tops20* | its* \ + | os2* | vos* | palmos* | uclinux* | nucleus* | morphos* \ + | scout* | superux* | sysv* | rtmk* | tpf* | windiss* \ + | powermax* | dnix* | nx6 | nx7 | sei* | dragonfly* \ + | skyos* | haiku* | rdos* | toppers* | drops* | es* \ + | onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \ + | midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \ + | nsk* | powerunix* | genode* | zvmoe* | qnx* | emx*) + ;; + # This one is extra strict with allowed versions + sco3.2v2 | sco3.2v[4-9]* | sco5v6*) + # Don't forget version if it is 3.2v4 or newer. + ;; + none) + ;; + *) + echo Invalid configuration \`"$1"\': OS \`"$os"\' not recognized 1>&2 + exit 1 + ;; +esac + +# As a final step for OS-related things, validate the OS-kernel combination +# (given a valid OS), if there is a kernel. +case $kernel-$os in + linux-gnu* | linux-dietlibc* | linux-android* | linux-newlib* | linux-musl* | linux-uclibc* ) + ;; + uclinux-uclibc* ) + ;; + -dietlibc* | -newlib* | -musl* | -uclibc* ) + # These are just libc implementations, not actual OSes, and thus + # require a kernel. + echo "Invalid configuration \`$1': libc \`$os' needs explicit kernel." 1>&2 + exit 1 + ;; + kfreebsd*-gnu* | kopensolaris*-gnu*) + ;; + vxworks-simlinux | vxworks-simwindows | vxworks-spe) + ;; + nto-qnx*) + ;; + os2-emx) + ;; + *-eabi* | *-gnueabi*) + ;; + -*) + # Blank kernel with real OS is always fine. + ;; + *-*) + echo "Invalid configuration \`$1': Kernel \`$kernel' not known to work with OS \`$os'." 1>&2 + exit 1 + ;; +esac + # 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*) +case $vendor in + unknown) + case $cpu-$os in + *-riscix*) vendor=acorn ;; - -sunos*) + *-sunos*) vendor=sun ;; - -cnk*|-aix*) + *-cnk* | *-aix*) vendor=ibm ;; - -beos*) + *-beos*) vendor=be ;; - -hpux*) + *-hpux*) vendor=hp ;; - -mpeix*) + *-mpeix*) vendor=hp ;; - -hiux*) + *-hiux*) vendor=hitachi ;; - -unos*) + *-unos*) vendor=crds ;; - -dgux*) + *-dgux*) vendor=dg ;; - -luna*) + *-luna*) vendor=omron ;; - -genix*) + *-genix*) vendor=ns ;; - -mvs* | -opened*) + *-clix*) + vendor=intergraph + ;; + *-mvs* | *-opened*) + vendor=ibm + ;; + *-os400*) vendor=ibm ;; - -os400*) + s390-* | s390x-*) vendor=ibm ;; - -ptx*) + *-ptx*) vendor=sequent ;; - -tpf*) + *-tpf*) vendor=ibm ;; - -vxsim* | -vxworks* | -windiss*) + *-vxsim* | *-vxworks* | *-windiss*) vendor=wrs ;; - -aux*) + *-aux*) vendor=apple ;; - -hms*) + *-hms*) vendor=hitachi ;; - -mpw* | -macos*) + *-mpw* | *-macos*) vendor=apple ;; - -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) + *-*mint | *-mint[0-9]* | *-*MiNT | *-MiNT[0-9]*) vendor=atari ;; - -vos*) + *-vos*) vendor=stratus ;; esac - basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"` ;; esac -echo $basic_machine$os +echo "$cpu-$vendor-${kernel:+$kernel-}$os" exit # Local variables: -# eval: (add-hook 'write-file-hooks 'time-stamp) +# eval: (add-hook 'before-save-hook 'time-stamp) # time-stamp-start: "timestamp='" # time-stamp-format: "%:y-%02m-%02d" # time-stamp-end: "'" diff -Nru cpl-7.1.4+ds/libcext/admin/depcomp cpl-7.2.2+ds/libcext/admin/depcomp --- cpl-7.1.4+ds/libcext/admin/depcomp 2021-05-07 12:09:58.000000000 +0000 +++ cpl-7.2.2+ds/libcext/admin/depcomp 2022-04-29 14:56:23.000000000 +0000 @@ -1,9 +1,9 @@ #! /bin/sh # depcomp - compile a program generating dependencies as side-effects -scriptversion=2016-01-11.22; # UTC +scriptversion=2018-03-07.03; # UTC -# Copyright (C) 1999-2017 Free Software Foundation, Inc. +# Copyright (C) 1999-2020 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 @@ -16,7 +16,7 @@ # 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 . +# 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 @@ -783,7 +783,7 @@ # Local Variables: # mode: shell-script # sh-indentation: 2 -# eval: (add-hook 'write-file-hooks 'time-stamp) +# eval: (add-hook 'before-save-hook 'time-stamp) # time-stamp-start: "scriptversion=" # time-stamp-format: "%:y-%02m-%02d.%02H" # time-stamp-time-zone: "UTC0" diff -Nru cpl-7.1.4+ds/libcext/admin/install-sh cpl-7.2.2+ds/libcext/admin/install-sh --- cpl-7.1.4+ds/libcext/admin/install-sh 2021-05-07 12:09:58.000000000 +0000 +++ cpl-7.2.2+ds/libcext/admin/install-sh 2022-04-29 14:56:23.000000000 +0000 @@ -1,7 +1,7 @@ #!/bin/sh # install - install a program, script, or datafile -scriptversion=2016-01-11.22; # UTC +scriptversion=2020-11-14.01; # UTC # This originates from X11R5 (mit/util/scripts/install.sh), which was # later released in X11R6 (xc/config/util/install.sh) with the @@ -69,6 +69,11 @@ # Desired mode of installed file. mode=0755 +# Create dirs (including intermediate dirs) using mode 755. +# This is like GNU 'install' as of coreutils 8.32 (2020). +mkdir_umask=22 + +backupsuffix= chgrpcmd= chmodcmd=$chmodprog chowncmd= @@ -99,18 +104,28 @@ --version display version info and exit. -c (ignored) - -C install only if different (preserve the last data modification time) + -C install only if different (preserve 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. + -p pass -p to $cpprog. -s $stripprog installed files. + -S SUFFIX attempt to back up existing files, with suffix SUFFIX. -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 + +By default, rm is invoked with -f; when overridden with RMPROG, +it's up to you to specify -f if you want it. + +If -S is not specified, no backups are attempted. + +Email bug reports to bug-automake@gnu.org. +Automake home page: https://www.gnu.org/software/automake/ " while test $# -ne 0; do @@ -137,8 +152,13 @@ -o) chowncmd="$chownprog $2" shift;; + -p) cpprog="$cpprog -p";; + -s) stripcmd=$stripprog;; + -S) backupsuffix="$2" + shift;; + -t) is_target_a_directory=always dst_arg=$2 @@ -255,6 +275,10 @@ dstdir=$dst test -d "$dstdir" dstdir_status=$? + # Don't chown directories that already exist. + if test $dstdir_status = 0; then + chowncmd="" + fi else # Waiting for this to be detected by the "$cpprog $src $dsttmp" command @@ -271,15 +295,18 @@ fi dst=$dst_arg - # If destination is a directory, append the input filename; won't work - # if double slashes aren't ignored. + # If destination is a directory, append the input filename. 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"` + dstbase=`basename "$src"` + case $dst in + */) dst=$dst$dstbase;; + *) dst=$dst/$dstbase;; + esac dstdir_status=0 else dstdir=`dirname "$dst"` @@ -288,27 +315,16 @@ fi fi + case $dstdir in + */) dstdirslash=$dstdir;; + *) dstdirslash=$dstdir/;; + esac + 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 @@ -318,43 +334,49 @@ 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;; + # The $RANDOM variable is not portable (e.g., dash). Use it + # here however when possible just to lower collision chance. + tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ + + trap ' + ret=$? + rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null + exit $ret + ' 0 + + # Because "mkdir -p" follows existing symlinks and we likely work + # directly in world-writeable /tmp, make sure that the '$tmpdir' + # directory is successfully created first before we actually test + # 'mkdir -p'. + if (umask $mkdir_umask && + $mkdirprog $mkdir_mode "$tmpdir" && + exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/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. + test_tmpdir="$tmpdir/a" + ls_ld_tmpdir=`ls -ld "$test_tmpdir"` + case $ls_ld_tmpdir in + d????-?r-*) different_mode=700;; + d????-?--*) different_mode=755;; + *) false;; + esac && + $mkdirprog -m$different_mode -p -- "$test_tmpdir" && { + ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"` + test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" + } + } + then posix_mkdir=: + fi + rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" + else + # Remove any dirs left behind by ancient mkdir implementations. + rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null + fi + trap '' 0;; esac if @@ -365,7 +387,7 @@ then : else - # The umask is ridiculous, or mkdir does not conform to POSIX, + # 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. @@ -394,7 +416,7 @@ prefixes= else if $posix_mkdir; then - (umask=$mkdir_umask && + (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 @@ -427,14 +449,25 @@ else # Make a couple of temp file names in the proper directory. - dsttmp=$dstdir/_inst.$$_ - rmtmp=$dstdir/_rm.$$_ + dsttmp=${dstdirslash}_inst.$$_ + rmtmp=${dstdirslash}_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") && + (umask $cp_umask && + { test -z "$stripcmd" || { + # Create $dsttmp read-write so that cp doesn't create it read-only, + # which would cause strip to fail. + if test -z "$doit"; then + : >"$dsttmp" # No need to fork-exec 'touch'. + else + $doit touch "$dsttmp" + fi + } + } && + $doit_exec $cpprog "$src" "$dsttmp") && # and set any options; do chmod last to preserve setuid bits. # @@ -460,6 +493,13 @@ then rm -f "$dsttmp" else + # If $backupsuffix is set, and the file being installed + # already exists, attempt a backup. Don't worry if it fails, + # e.g., if mv doesn't support -f. + if test -n "$backupsuffix" && test -f "$dst"; then + $doit $mvcmd -f "$dst" "$dst$backupsuffix" 2>/dev/null + fi + # Rename the file to the real destination. $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || @@ -474,9 +514,9 @@ # file should still install successfully. { test ! -f "$dst" || - $doit $rmcmd -f "$dst" 2>/dev/null || + $doit $rmcmd "$dst" 2>/dev/null || { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && - { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } + { $doit $rmcmd "$rmtmp" 2>/dev/null; :; } } || { echo "$0: cannot unlink or rename $dst" >&2 (exit 1); exit 1 @@ -493,7 +533,7 @@ done # Local variables: -# eval: (add-hook 'write-file-hooks 'time-stamp) +# eval: (add-hook 'before-save-hook 'time-stamp) # time-stamp-start: "scriptversion=" # time-stamp-format: "%:y-%02m-%02d.%02H" # time-stamp-time-zone: "UTC0" diff -Nru cpl-7.1.4+ds/libcext/admin/missing cpl-7.2.2+ds/libcext/admin/missing --- cpl-7.1.4+ds/libcext/admin/missing 2021-05-07 12:09:58.000000000 +0000 +++ cpl-7.2.2+ds/libcext/admin/missing 2022-04-29 14:56:23.000000000 +0000 @@ -1,9 +1,9 @@ #! /bin/sh # Common wrapper for a few potentially missing GNU programs. -scriptversion=2016-01-11.22; # UTC +scriptversion=2018-03-07.03; # UTC -# Copyright (C) 1996-2017 Free Software Foundation, Inc. +# Copyright (C) 1996-2020 Free Software Foundation, Inc. # Originally written by Fran,cois Pinard , 1996. # This program is free software; you can redistribute it and/or modify @@ -17,7 +17,7 @@ # 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 . +# 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 @@ -101,9 +101,9 @@ exit $st fi -perl_URL=http://www.perl.org/ -flex_URL=http://flex.sourceforge.net/ -gnu_software_URL=http://www.gnu.org/software +perl_URL=https://www.perl.org/ +flex_URL=https://github.com/westes/flex +gnu_software_URL=https://www.gnu.org/software program_details () { @@ -207,7 +207,7 @@ exit $st # Local variables: -# eval: (add-hook 'write-file-hooks 'time-stamp) +# eval: (add-hook 'before-save-hook 'time-stamp) # time-stamp-start: "scriptversion=" # time-stamp-format: "%:y-%02m-%02d.%02H" # time-stamp-time-zone: "UTC0" diff -Nru cpl-7.1.4+ds/libcext/admin/test-driver cpl-7.2.2+ds/libcext/admin/test-driver --- cpl-7.1.4+ds/libcext/admin/test-driver 2021-05-07 12:09:58.000000000 +0000 +++ cpl-7.2.2+ds/libcext/admin/test-driver 2022-04-29 14:56:23.000000000 +0000 @@ -1,9 +1,9 @@ #! /bin/sh # test-driver - basic testsuite driver script. -scriptversion=2016-01-11.22; # UTC +scriptversion=2018-03-07.03; # UTC -# Copyright (C) 2011-2017 Free Software Foundation, Inc. +# Copyright (C) 2011-2020 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 @@ -16,7 +16,7 @@ # 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 . +# 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 @@ -42,11 +42,13 @@ { cat <$@-t && $(am__mv) $@-t $@ + +am--depfiles: $(am__depfiles_remade) .c.o: @am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @@ -576,7 +589,10 @@ distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags -distdir: $(DISTFILES) +distdir: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) distdir-am + +distdir-am: $(DISTFILES) @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ list='$(DISTFILES)'; \ @@ -616,7 +632,8 @@ done install: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) install-am -install-exec: install-exec-am +install-exec: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data: install-data-am uninstall: uninstall-am @@ -654,7 +671,19 @@ mostlyclean-am distclean: distclean-am - -rm -rf ./$(DEPDIR) + -rm -f ./$(DEPDIR)/cxdeque.Plo + -rm -f ./$(DEPDIR)/cxfileutils.Plo + -rm -f ./$(DEPDIR)/cxlist.Plo + -rm -f ./$(DEPDIR)/cxmap.Plo + -rm -f ./$(DEPDIR)/cxmemory.Plo + -rm -f ./$(DEPDIR)/cxmessages.Plo + -rm -f ./$(DEPDIR)/cxmultimap.Plo + -rm -f ./$(DEPDIR)/cxslist.Plo + -rm -f ./$(DEPDIR)/cxstring.Plo + -rm -f ./$(DEPDIR)/cxstrutils.Plo + -rm -f ./$(DEPDIR)/cxtree.Plo + -rm -f ./$(DEPDIR)/cxutils.Plo + -rm -f ./$(DEPDIR)/snprintf.Plo -rm -f Makefile distclean-am: clean-am distclean-compile distclean-generic \ distclean-tags @@ -700,7 +729,19 @@ installcheck-am: maintainer-clean: maintainer-clean-am - -rm -rf ./$(DEPDIR) + -rm -f ./$(DEPDIR)/cxdeque.Plo + -rm -f ./$(DEPDIR)/cxfileutils.Plo + -rm -f ./$(DEPDIR)/cxlist.Plo + -rm -f ./$(DEPDIR)/cxmap.Plo + -rm -f ./$(DEPDIR)/cxmemory.Plo + -rm -f ./$(DEPDIR)/cxmessages.Plo + -rm -f ./$(DEPDIR)/cxmultimap.Plo + -rm -f ./$(DEPDIR)/cxslist.Plo + -rm -f ./$(DEPDIR)/cxstring.Plo + -rm -f ./$(DEPDIR)/cxstrutils.Plo + -rm -f ./$(DEPDIR)/cxtree.Plo + -rm -f ./$(DEPDIR)/cxutils.Plo + -rm -f ./$(DEPDIR)/snprintf.Plo -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic @@ -720,11 +761,11 @@ uninstall-am: uninstall-includeHEADERS uninstall-libLTLIBRARIES \ uninstall-nodist_configHEADERS -.MAKE: all check install install-am install-strip +.MAKE: all check install install-am install-exec install-strip -.PHONY: CTAGS GTAGS TAGS all all-am check check-am clean clean-generic \ - clean-libLTLIBRARIES clean-libtool cscopelist-am ctags \ - ctags-am distclean distclean-compile distclean-generic \ +.PHONY: CTAGS GTAGS TAGS all all-am am--depfiles check check-am clean \ + clean-generic clean-libLTLIBRARIES clean-libtool 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 \ diff -Nru cpl-7.1.4+ds/libcext/config.h.in cpl-7.2.2+ds/libcext/config.h.in --- cpl-7.1.4+ds/libcext/config.h.in 2021-05-07 12:09:57.000000000 +0000 +++ cpl-7.2.2+ds/libcext/config.h.in 2022-04-29 14:56:23.000000000 +0000 @@ -55,9 +55,6 @@ /* Define to 1 if you have the `memcpy' function. */ #undef HAVE_MEMCPY -/* Define to 1 if you have the header file. */ -#undef HAVE_MEMORY_H - /* Define if you have the `pathconf' function */ #undef HAVE_PATHCONF @@ -102,6 +99,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_STDINT_H +/* Define to 1 if you have the header file. */ +#undef HAVE_STDIO_H + /* Define to 1 if you have the header file. */ #undef HAVE_STDLIB_H @@ -226,17 +226,14 @@ /* Define to 1 if the `S_IS*' macros in do not work properly. */ #undef STAT_MACROS_BROKEN -/* Define to 1 if you have the ANSI C header files. */ +/* Define to 1 if all of the C90 standard headers exist (not just the ones + required in a freestanding environment). This macro is provided for + backward compatibility; new code need not use it. */ #undef STDC_HEADERS /* Version number of package */ #undef VERSION -/* 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 diff -Nru cpl-7.1.4+ds/libcext/configure cpl-7.2.2+ds/libcext/configure --- cpl-7.1.4+ds/libcext/configure 2021-05-07 12:09:57.000000000 +0000 +++ cpl-7.2.2+ds/libcext/configure 2022-04-29 14:56:23.000000000 +0000 @@ -1,11 +1,12 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for C Extension Library 1.2.4. +# Generated by GNU Autoconf 2.71 for C Extension Library 1.2.4. # # Report bugs to . # # -# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. +# Copyright (C) 1992-1996, 1998-2017, 2020-2021 Free Software Foundation, +# Inc. # # # This configure script is free software; the Free Software Foundation @@ -16,14 +17,16 @@ # Be more Bourne compatible DUALCASE=1; export DUALCASE # for MKS sh -if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : +as_nop=: +if test ${ZSH_VERSION+y} && (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 +else $as_nop case `(set -o) 2>/dev/null` in #( *posix*) : set -o posix ;; #( @@ -33,46 +36,46 @@ fi + +# Reset variables that may have inherited troublesome values from +# the environment. + +# IFS needs to be set, to space, tab, and newline, in precisely that order. +# (If _AS_PATH_WALK were called with IFS unset, it would have the +# side effect of setting IFS to empty, thus disabling word splitting.) +# Quoting is to prevent editors from complaining about space-tab. 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 +IFS=" "" $as_nl" + +PS1='$ ' +PS2='> ' +PS4='+ ' + +# Ensure predictable behavior from utilities with locale-dependent output. +LC_ALL=C +export LC_ALL +LANGUAGE=C +export LANGUAGE + +# We cannot yet rely on "unset" to work, but we need these variables +# to be unset--not just set to an empty or harmless value--now, to +# avoid bugs in old shells (e.g. pre-3.0 UWIN ksh). This construct +# also avoids known problems related to "unset" and subshell syntax +# in other old shells (e.g. bash 2.01 and pdksh 5.2.14). +for as_var in BASH_ENV ENV MAIL MAILPATH CDPATH +do eval test \${$as_var+y} \ + && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : +done + +# Ensure that fds 0, 1, and 2 are open. +if (exec 3>&0) 2>/dev/null; then :; else exec 0&1) 2>/dev/null; then :; else exec 1>/dev/null; fi +if (exec 3>&2) ; then :; else exec 2>/dev/null; fi # The user is always right. -if test "${PATH_SEPARATOR+set}" != set; then +if ${PATH_SEPARATOR+false} :; 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 || @@ -81,13 +84,6 @@ 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 #(( @@ -96,8 +92,12 @@ 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 + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + test -r "$as_dir$0" && as_myself=$as_dir$0 && break done IFS=$as_save_IFS @@ -109,30 +109,10 @@ 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 + printf "%s\n" "$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. @@ -154,20 +134,22 @@ 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 +printf "%s\n" "$0: could not re-execute with $CONFIG_SHELL" >&2 +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 : + as_bourne_compatible="as_nop=: +if test \${ZSH_VERSION+y} && (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 +else \$as_nop case \`(set -o) 2>/dev/null\` in #( *posix*) : set -o posix ;; #( @@ -187,12 +169,15 @@ 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 : +if ( set x; as_fn_ret_success y && test x = \"\$1\" ) +then : -else +else \$as_nop exitcode=1; echo positional parameters were not saved. fi test x\$exitcode = x0 || exit 1 +blah=\$(echo \$(echo blah)) +test x\"\$blah\" = xblah || 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 @@ -207,30 +192,38 @@ 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 : + if (eval "$as_required") 2>/dev/null +then : as_have_required=yes -else +else $as_nop as_have_required=no fi - if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null; then : + if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null +then : -else +else $as_nop 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=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac 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 + 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 : + as_run=a "$as_shell" -c "$as_bourne_compatible""$as_required" 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 : + if as_run=a "$as_shell" -c "$as_bourne_compatible""$as_suggested" 2>/dev/null +then : break 2 fi fi @@ -238,14 +231,21 @@ 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 $as_found +then : + +else $as_nop + if { test -f "$SHELL" || test -f "$SHELL.exe"; } && + as_run=a "$SHELL" -c "$as_bourne_compatible""$as_required" 2>/dev/null +then : + CONFIG_SHELL=$SHELL as_have_required=yes +fi +fi - if test "x$CONFIG_SHELL" != x; then : + 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 @@ -263,18 +263,19 @@ 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 +printf "%s\n" "$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." + if test x$as_have_required = xno +then : + printf "%s\n" "$0: This script requires a shell more modern than all" + printf "%s\n" "$0: the shells that I found on your system." + if test ${ZSH_VERSION+y} ; then + printf "%s\n" "$0: In particular, zsh $ZSH_VERSION has bugs and should" + printf "%s\n" "$0: be upgraded to zsh 4.3.4 or later." else - $as_echo "$0: Please tell bug-autoconf@gnu.org and cpl-help@eso.org + printf "%s\n" "$0: Please tell bug-autoconf@gnu.org and cpl-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 @@ -302,6 +303,7 @@ } as_unset=as_fn_unset + # as_fn_set_status STATUS # ----------------------- # Set $? to STATUS, without forking. @@ -319,6 +321,14 @@ as_fn_set_status $1 exit $1 } # as_fn_exit +# as_fn_nop +# --------- +# Do nothing but, unlike ":", preserve the value of $?. +as_fn_nop () +{ + return $? +} +as_nop=as_fn_nop # as_fn_mkdir_p # ------------- @@ -333,7 +343,7 @@ as_dirs= while :; do case $as_dir in #( - *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( + *\'*) as_qdir=`printf "%s\n" "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( *) as_qdir=$as_dir;; esac as_dirs="'$as_qdir' $as_dirs" @@ -342,7 +352,7 @@ X"$as_dir" : 'X\(//\)[^/]' \| \ X"$as_dir" : 'X\(//\)$' \| \ X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || -$as_echo X"$as_dir" | +printf "%s\n" X"$as_dir" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q @@ -381,12 +391,13 @@ # 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 : +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 +else $as_nop as_fn_append () { eval $1=\$$1\$2 @@ -398,18 +409,27 @@ # 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 : +if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null +then : eval 'as_fn_arith () { as_val=$(( $* )) }' -else +else $as_nop as_fn_arith () { as_val=`expr "$@" || test $? -eq 1` } fi # as_fn_arith +# as_fn_nop +# --------- +# Do nothing but, unlike ":", preserve the value of $?. +as_fn_nop () +{ + return $? +} +as_nop=as_fn_nop # as_fn_error STATUS ERROR [LINENO LOG_FD] # ---------------------------------------- @@ -421,9 +441,9 @@ 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 fi - $as_echo "$as_me: error: $2" >&2 + printf "%s\n" "$as_me: error: $2" >&2 as_fn_exit $as_status } # as_fn_error @@ -450,7 +470,7 @@ $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ X"$0" : 'X\(//\)$' \| \ X"$0" : 'X\(/\)' \| . 2>/dev/null || -$as_echo X/"$0" | +printf "%s\n" X/"$0" | sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/ q @@ -494,7 +514,7 @@ 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; } + { printf "%s\n" "$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 @@ -508,6 +528,10 @@ exit } + +# Determine whether it's possible to make 'echo' print without a newline. +# These variables are no longer used directly by Autoconf, but are AC_SUBSTed +# for compatibility with existing Makefiles. ECHO_C= ECHO_N= ECHO_T= case `echo -n x` in #((((( -n*) @@ -521,6 +545,13 @@ ECHO_N='-n';; esac +# For backward compatibility with old third-party macros, we provide +# the shell variables $as_echo and $as_echo_n. New code should use +# AS_ECHO(["message"]) and AS_ECHO_N(["message"]), respectively. +as_echo='printf %s\n' +as_echo_n='printf %s' + + rm -f conf$$ conf$$.exe conf$$.file if test -d conf$$.dir; then rm -f conf$$.dir/conf$$.file @@ -598,40 +629,36 @@ 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 +#include +#ifdef HAVE_STDIO_H +# include #endif -#ifdef STDC_HEADERS +#ifdef HAVE_STDLIB_H # 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_STRINGS_H +# include +#endif +#ifdef HAVE_SYS_TYPES_H +# include +#endif +#ifdef HAVE_SYS_STAT_H +# include +#endif #ifdef HAVE_UNISTD_H # include #endif" +ac_header_c_list= ac_subst_vars='am__EXEEXT_FALSE am__EXEEXT_TRUE LTLIBOBJS @@ -644,7 +671,6 @@ LIBPTHREAD PTHREAD_CFLAGS LIBTOOL_DEPS -CPP LT_SYS_LIBRARY_PATH OTOOL64 OTOOL @@ -686,7 +712,6 @@ AMDEPBACKSLASH AMDEP_FALSE AMDEP_TRUE -am__quote am__include DEPDIR OBJEXT @@ -748,6 +773,7 @@ docdir oldincludedir includedir +runstatedir localstatedir sharedstatedir sysconfdir @@ -766,7 +792,8 @@ PACKAGE_TARNAME PACKAGE_NAME PATH_SEPARATOR -SHELL' +SHELL +am__quote' ac_subst_files='' ac_user_opts=' enable_option_checking @@ -796,8 +823,7 @@ CPPFLAGS DOXYGEN LATEX -LT_SYS_LIBRARY_PATH -CPP' +LT_SYS_LIBRARY_PATH' # Initialize some variables set by options. @@ -836,6 +862,7 @@ sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' +runstatedir='${localstatedir}/run' includedir='${prefix}/include' oldincludedir='/usr/include' docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' @@ -865,8 +892,6 @@ *) ac_optarg=yes ;; esac - # Accept the important Cygnus configure options, so we can diagnose typos. - case $ac_dashdash$ac_option in --) ac_dashdash=yes ;; @@ -907,9 +932,9 @@ 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" + as_fn_error $? "invalid feature name: \`$ac_useropt'" ac_useropt_orig=$ac_useropt - ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "enable_$ac_useropt" @@ -933,9 +958,9 @@ 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" + as_fn_error $? "invalid feature name: \`$ac_useropt'" ac_useropt_orig=$ac_useropt - ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "enable_$ac_useropt" @@ -1088,6 +1113,15 @@ | -silent | --silent | --silen | --sile | --sil) silent=yes ;; + -runstatedir | --runstatedir | --runstatedi | --runstated \ + | --runstate | --runstat | --runsta | --runst | --runs \ + | --run | --ru | --r) + ac_prev=runstatedir ;; + -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \ + | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \ + | --run=* | --ru=* | --r=*) + runstatedir=$ac_optarg ;; + -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ @@ -1137,9 +1171,9 @@ 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" + as_fn_error $? "invalid package name: \`$ac_useropt'" ac_useropt_orig=$ac_useropt - ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "with_$ac_useropt" @@ -1153,9 +1187,9 @@ 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" + as_fn_error $? "invalid package name: \`$ac_useropt'" ac_useropt_orig=$ac_useropt - ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "with_$ac_useropt" @@ -1199,9 +1233,9 @@ *) # FIXME: should be removed in autoconf 3.0. - $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2 + printf "%s\n" "$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 + printf "%s\n" "$as_me: WARNING: invalid host type: $ac_option" >&2 : "${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}" ;; @@ -1217,7 +1251,7 @@ 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 ;; + *) printf "%s\n" "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;; esac fi @@ -1225,7 +1259,7 @@ 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 + libdir localedir mandir runstatedir do eval ac_val=\$$ac_var # Remove trailing slashes. @@ -1281,7 +1315,7 @@ X"$as_myself" : 'X\(//\)[^/]' \| \ X"$as_myself" : 'X\(//\)$' \| \ X"$as_myself" : 'X\(/\)' \| . 2>/dev/null || -$as_echo X"$as_myself" | +printf "%s\n" X"$as_myself" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q @@ -1378,6 +1412,7 @@ --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] + --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] @@ -1460,7 +1495,6 @@ LATEX latex command LT_SYS_LIBRARY_PATH User-defined run-time library search path. - CPP C preprocessor Use these variables to override the choices made by `configure' or to help it to find libraries and programs with nonstandard names/locations. @@ -1481,9 +1515,9 @@ case "$ac_dir" in .) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; *) - ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` + ac_dir_suffix=/`printf "%s\n" "$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|/||'` + ac_top_builddir_sub=`printf "%s\n" "$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/ ;; @@ -1511,7 +1545,8 @@ ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix cd "$ac_dir" || { ac_status=$?; continue; } - # Check for guested configure. + # Check for configure.gnu first; this name is used for a wrapper for + # Metaconfig's "Configure" on case-insensitive file systems. if test -f "$ac_srcdir/configure.gnu"; then echo && $SHELL "$ac_srcdir/configure.gnu" --help=recursive @@ -1519,7 +1554,7 @@ echo && $SHELL "$ac_srcdir/configure" --help=recursive else - $as_echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2 + printf "%s\n" "$as_me: WARNING: no configuration information is in $ac_dir" >&2 fi || ac_status=$? cd "$ac_pwd" || { ac_status=$?; break; } done @@ -1529,9 +1564,9 @@ if $ac_init_version; then cat <<\_ACEOF C Extension Library configure 1.2.4 -generated by GNU Autoconf 2.69 +generated by GNU Autoconf 2.71 -Copyright (C) 2012 Free Software Foundation, Inc. +Copyright (C) 2021 Free Software Foundation, Inc. This configure script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it. _ACEOF @@ -1548,14 +1583,14 @@ ac_fn_c_try_compile () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - rm -f conftest.$ac_objext + rm -f conftest.$ac_objext conftest.beam 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 +printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_compile") 2>conftest.err ac_status=$? if test -s conftest.err; then @@ -1563,14 +1598,15 @@ cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$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 : + } && test -s conftest.$ac_objext +then : ac_retval=0 -else - $as_echo "$as_me: failed program was:" >&5 +else $as_nop + printf "%s\n" "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 @@ -1586,14 +1622,14 @@ 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 + rm -f conftest.$ac_objext conftest.beam 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 +printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_link") 2>conftest.err ac_status=$? if test -s conftest.err; then @@ -1601,17 +1637,18 @@ cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$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 : + } +then : ac_retval=0 -else - $as_echo "$as_me: failed program was:" >&5 +else $as_nop + printf "%s\n" "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 @@ -1633,120 +1670,44 @@ 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +printf %s "checking for $2... " >&6; } +if eval test \${$3+y} +then : + printf %s "(cached) " >&6 +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 #include <$2> _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : eval "$3=yes" -else +else $as_nop eval "$3=no" fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi eval ac_res=\$$3 - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_header_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_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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +printf %s "checking for $2... " >&6; } +if eval test \${$3+y} +then : + printf %s "(cached) " >&6 +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Define $2 to an innocuous variant, in case declares $2. @@ -1754,16 +1715,9 @@ #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 + which can conflict with char $2 (); below. */ +#include #undef $2 /* Override any GCC internal prototype to avoid an error. @@ -1781,119 +1735,29 @@ #endif int -main () +main (void) { return $2 (); ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : eval "$3=yes" -else +else $as_nop eval "$3=no" fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$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 cpl-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_type LINENO TYPE VAR INCLUDES # ------------------------------------------- # Tests whether TYPE exists after having included INCLUDES, setting cache @@ -1901,17 +1765,18 @@ ac_fn_c_check_type () { 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +printf %s "checking for $2... " >&6; } +if eval test \${$3+y} +then : + printf %s "(cached) " >&6 +else $as_nop eval "$3=no" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int -main () +main (void) { if (sizeof ($2)) return 0; @@ -1919,12 +1784,13 @@ return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int -main () +main (void) { if (sizeof (($2))) return 0; @@ -1932,22 +1798,66 @@ return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : -else +else $as_nop eval "$3=yes" fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi eval ac_res=\$$3 - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_type +# ac_fn_c_try_run LINENO +# ---------------------- +# Try to run 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\"" +printf "%s\n" "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + printf "%s\n" "$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\"" +printf "%s\n" "$ac_try_echo"; } >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; } +then : + ac_retval=0 +else $as_nop + printf "%s\n" "$as_me: program exited with status $ac_status" >&5 + printf "%s\n" "$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_compute_int LINENO EXPR VAR INCLUDES # -------------------------------------------- # Tries to find the compile-time value of EXPR in a program that includes @@ -1962,7 +1872,7 @@ /* end confdefs.h. */ $4 int -main () +main (void) { static int test_array [1 - 2 * !(($2) >= 0)]; test_array [0] = 0; @@ -1972,14 +1882,15 @@ return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : ac_lo=0 ac_mid=0 while :; do cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int -main () +main (void) { static int test_array [1 - 2 * !(($2) <= $ac_mid)]; test_array [0] = 0; @@ -1989,9 +1900,10 @@ return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : ac_hi=$ac_mid; break -else +else $as_nop as_fn_arith $ac_mid + 1 && ac_lo=$as_val if test $ac_lo -le $ac_mid; then ac_lo= ac_hi= @@ -1999,14 +1911,14 @@ fi as_fn_arith 2 '*' $ac_mid + 1 && ac_mid=$as_val fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext done -else +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int -main () +main (void) { static int test_array [1 - 2 * !(($2) < 0)]; test_array [0] = 0; @@ -2016,14 +1928,15 @@ return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : ac_hi=-1 ac_mid=-1 while :; do cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int -main () +main (void) { static int test_array [1 - 2 * !(($2) >= $ac_mid)]; test_array [0] = 0; @@ -2033,9 +1946,10 @@ return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : ac_lo=$ac_mid; break -else +else $as_nop as_fn_arith '(' $ac_mid ')' - 1 && ac_hi=$as_val if test $ac_mid -le $ac_hi; then ac_lo= ac_hi= @@ -2043,14 +1957,14 @@ fi as_fn_arith 2 '*' $ac_mid && ac_mid=$as_val fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext done -else +else $as_nop ac_lo= ac_hi= fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext # Binary search between lo and hi bounds. while test "x$ac_lo" != "x$ac_hi"; do as_fn_arith '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo && ac_mid=$as_val @@ -2058,7 +1972,7 @@ /* end confdefs.h. */ $4 int -main () +main (void) { static int test_array [1 - 2 * !(($2) <= $ac_mid)]; test_array [0] = 0; @@ -2068,12 +1982,13 @@ return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : ac_hi=$ac_mid -else +else $as_nop as_fn_arith '(' $ac_mid ')' + 1 && ac_lo=$as_val fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext done case $ac_lo in #(( ?*) eval "$3=\$ac_lo"; ac_retval=0 ;; @@ -2083,12 +1998,12 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 -static long int longval () { return $2; } -static unsigned long int ulongval () { return $2; } +static long int longval (void) { return $2; } +static unsigned long int ulongval (void) { return $2; } #include #include int -main () +main (void) { FILE *f = fopen ("conftest.val", "w"); @@ -2116,9 +2031,10 @@ return 0; } _ACEOF -if ac_fn_c_try_run "$LINENO"; then : +if ac_fn_c_try_run "$LINENO" +then : echo >>conftest.val; read $3 &5 -$as_echo_n "checking for $2.$3... " >&6; } -if eval \${$4+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $2.$3" >&5 +printf %s "checking for $2.$3... " >&6; } +if eval test \${$4+y} +then : + printf %s "(cached) " >&6 +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $5 int -main () +main (void) { static $2 ac_aggr; if (ac_aggr.$3) @@ -2156,14 +2073,15 @@ return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : eval "$4=yes" -else +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $5 int -main () +main (void) { static $2 ac_aggr; if (sizeof ac_aggr.$3) @@ -2172,41 +2090,45 @@ return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : eval "$4=yes" -else +else $as_nop eval "$4=no" fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi eval ac_res=\$$4 - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_member -# ac_fn_c_check_decl LINENO SYMBOL VAR INCLUDES -# --------------------------------------------- +# ac_fn_check_decl LINENO SYMBOL VAR INCLUDES EXTRA-OPTIONS FLAG-VAR +# ------------------------------------------------------------------ # Tests whether SYMBOL is declared in INCLUDES, setting cache variable VAR -# accordingly. -ac_fn_c_check_decl () +# accordingly. Pass EXTRA-OPTIONS to the compiler, using FLAG-VAR. +ac_fn_check_decl () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack as_decl_name=`echo $2|sed 's/ *(.*//'` + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $as_decl_name is declared" >&5 +printf %s "checking whether $as_decl_name is declared... " >&6; } +if eval test \${$3+y} +then : + printf %s "(cached) " >&6 +else $as_nop 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 + eval ac_save_FLAGS=\$$6 + as_fn_append $6 " $5" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int -main () +main (void) { #ifndef $as_decl_name #ifdef __cplusplus @@ -2220,27 +2142,50 @@ return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : eval "$3=yes" -else +else $as_nop eval "$3=no" fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext + eval $6=\$ac_save_FLAGS + fi eval ac_res=\$$3 - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno -} # ac_fn_c_check_decl +} # ac_fn_check_decl +ac_configure_args_raw= +for ac_arg +do + case $ac_arg in + *\'*) + ac_arg=`printf "%s\n" "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; + esac + as_fn_append ac_configure_args_raw " '$ac_arg'" +done + +case $ac_configure_args_raw in + *$as_nl*) + ac_safe_unquote= ;; + *) + ac_unsafe_z='|&;<>()$`\\"*?[ '' ' # This string ends in space, tab. + ac_unsafe_a="$ac_unsafe_z#~" + ac_safe_unquote="s/ '\\([^$ac_unsafe_a][^$ac_unsafe_z]*\\)'/ \\1/g" + ac_configure_args_raw=` printf "%s\n" "$ac_configure_args_raw" | sed "$ac_safe_unquote"`;; +esac + 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 C Extension Library $as_me 1.2.4, which was -generated by GNU Autoconf 2.69. Invocation command line was +generated by GNU Autoconf 2.71. Invocation command line was - $ $0 $@ + $ $0$ac_configure_args_raw _ACEOF exec 5>>config.log @@ -2273,8 +2218,12 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - $as_echo "PATH: $as_dir" + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + printf "%s\n" "PATH: $as_dir" done IFS=$as_save_IFS @@ -2309,7 +2258,7 @@ | -silent | --silent | --silen | --sile | --sil) continue ;; *\'*) - ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; + ac_arg=`printf "%s\n" "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; esac case $ac_pass in 1) as_fn_append ac_configure_args0 " '$ac_arg'" ;; @@ -2344,11 +2293,13 @@ # 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=$? + # Sanitize IFS. + IFS=" "" $as_nl" # Save into config.log some information that might help in debugging. { echo - $as_echo "## ---------------- ## + printf "%s\n" "## ---------------- ## ## Cache variables. ## ## ---------------- ##" echo @@ -2359,8 +2310,8 @@ 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;} ;; + *_cv_*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 +printf "%s\n" "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; esac case $ac_var in #( _ | IFS | as_nl) ;; #( @@ -2384,7 +2335,7 @@ ) echo - $as_echo "## ----------------- ## + printf "%s\n" "## ----------------- ## ## Output variables. ## ## ----------------- ##" echo @@ -2392,14 +2343,14 @@ do eval ac_val=\$$ac_var case $ac_val in - *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; + *\'\''*) ac_val=`printf "%s\n" "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; esac - $as_echo "$ac_var='\''$ac_val'\''" + printf "%s\n" "$ac_var='\''$ac_val'\''" done | sort echo if test -n "$ac_subst_files"; then - $as_echo "## ------------------- ## + printf "%s\n" "## ------------------- ## ## File substitutions. ## ## ------------------- ##" echo @@ -2407,15 +2358,15 @@ do eval ac_val=\$$ac_var case $ac_val in - *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; + *\'\''*) ac_val=`printf "%s\n" "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; esac - $as_echo "$ac_var='\''$ac_val'\''" + printf "%s\n" "$ac_var='\''$ac_val'\''" done | sort echo fi if test -s confdefs.h; then - $as_echo "## ----------- ## + printf "%s\n" "## ----------- ## ## confdefs.h. ## ## ----------- ##" echo @@ -2423,8 +2374,8 @@ echo fi test "$ac_signal" != 0 && - $as_echo "$as_me: caught signal $ac_signal" - $as_echo "$as_me: exit $exit_status" + printf "%s\n" "$as_me: caught signal $ac_signal" + printf "%s\n" "$as_me: exit $exit_status" } >&5 rm -f core *.core core.conftest.* && rm -f -r conftest* confdefs* conf$$* $ac_clean_files && @@ -2438,63 +2389,48 @@ # confdefs.h avoids OS command line length limits that DEFS can exceed. rm -f -r conftest* confdefs.h -$as_echo "/* confdefs.h */" > confdefs.h +printf "%s\n" "/* confdefs.h */" > confdefs.h # Predefined preprocessor variables. -cat >>confdefs.h <<_ACEOF -#define PACKAGE_NAME "$PACKAGE_NAME" -_ACEOF +printf "%s\n" "#define PACKAGE_NAME \"$PACKAGE_NAME\"" >>confdefs.h -cat >>confdefs.h <<_ACEOF -#define PACKAGE_TARNAME "$PACKAGE_TARNAME" -_ACEOF +printf "%s\n" "#define PACKAGE_TARNAME \"$PACKAGE_TARNAME\"" >>confdefs.h -cat >>confdefs.h <<_ACEOF -#define PACKAGE_VERSION "$PACKAGE_VERSION" -_ACEOF +printf "%s\n" "#define PACKAGE_VERSION \"$PACKAGE_VERSION\"" >>confdefs.h -cat >>confdefs.h <<_ACEOF -#define PACKAGE_STRING "$PACKAGE_STRING" -_ACEOF +printf "%s\n" "#define PACKAGE_STRING \"$PACKAGE_STRING\"" >>confdefs.h -cat >>confdefs.h <<_ACEOF -#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT" -_ACEOF +printf "%s\n" "#define PACKAGE_BUGREPORT \"$PACKAGE_BUGREPORT\"" >>confdefs.h -cat >>confdefs.h <<_ACEOF -#define PACKAGE_URL "$PACKAGE_URL" -_ACEOF +printf "%s\n" "#define PACKAGE_URL \"$PACKAGE_URL\"" >>confdefs.h # 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 + ac_site_files="$CONFIG_SITE" elif test "x$prefix" != xNONE; then - ac_site_file1=$prefix/share/config.site - ac_site_file2=$prefix/etc/config.site + ac_site_files="$prefix/share/config.site $prefix/etc/config.site" else - ac_site_file1=$ac_default_prefix/share/config.site - ac_site_file2=$ac_default_prefix/etc/config.site + ac_site_files="$ac_default_prefix/share/config.site $ac_default_prefix/etc/config.site" fi -for ac_site_file in "$ac_site_file1" "$ac_site_file2" + +for ac_site_file in $ac_site_files 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;} + case $ac_site_file in #( + */*) : + ;; #( + *) : + ac_site_file=./$ac_site_file ;; +esac + if test -f "$ac_site_file" && test -r "$ac_site_file"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5 +printf "%s\n" "$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;} + || { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$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 @@ -2504,19 +2440,434 @@ # 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;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5 +printf "%s\n" "$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;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5 +printf "%s\n" "$as_me: creating cache $cache_file" >&6;} >$cache_file fi +# Test code for whether the C compiler supports C89 (global declarations) +ac_c_conftest_c89_globals=' +/* Does the compiler advertise C89 conformance? + Do not test the value of __STDC__, because some compilers set it to 0 + while being otherwise adequately conformant. */ +#if !defined __STDC__ +# error "Compiler does not advertise C89 conformance" +#endif + +#include +#include +struct stat; +/* Most of the following tests are stolen from RCS 5.7 src/conf.sh. */ +struct buf { int x; }; +struct buf * (*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 do not provoke an error unfortunately, instead are silently treated + as an "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 is necessary to write \x00 == 0 to get something + that is 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 **, int *(*)(struct buf *, struct stat *, int), + int, int);' + +# Test code for whether the C compiler supports C89 (body of main). +ac_c_conftest_c89_main=' +ok |= (argc == 0 || f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]); +' + +# Test code for whether the C compiler supports C99 (global declarations) +ac_c_conftest_c99_globals=' +// Does the compiler advertise C99 conformance? +#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 199901L +# error "Compiler does not advertise C99 conformance" +#endif + +#include +extern int puts (const char *); +extern int printf (const char *, ...); +extern int dprintf (int, const char *, ...); +extern void *malloc (size_t); + +// Check varargs macros. These examples are taken from C99 6.10.3.5. +// dprintf is used instead of fprintf to avoid needing to declare +// FILE and stderr. +#define debug(...) dprintf (2, __VA_ARGS__) +#define showlist(...) puts (#__VA_ARGS__) +#define report(test,...) ((test) ? puts (#test) : printf (__VA_ARGS__)) +static void +test_varargs_macros (void) +{ + int x = 1234; + int y = 5678; + debug ("Flag"); + debug ("X = %d\n", x); + showlist (The first, second, and third items.); + report (x>y, "x is %d but y is %d", x, y); +} + +// Check long long types. +#define BIG64 18446744073709551615ull +#define BIG32 4294967295ul +#define BIG_OK (BIG64 / BIG32 == 4294967297ull && BIG64 % BIG32 == 0) +#if !BIG_OK + #error "your preprocessor is broken" +#endif +#if BIG_OK +#else + #error "your preprocessor is broken" +#endif +static long long int bignum = -9223372036854775807LL; +static unsigned long long int ubignum = BIG64; + +struct incomplete_array +{ + int datasize; + double data[]; +}; + +struct named_init { + int number; + const wchar_t *name; + double average; +}; + +typedef const char *ccp; + +static inline int +test_restrict (ccp restrict text) +{ + // See if C++-style comments work. + // Iterate through items via the restricted pointer. + // Also check for declarations in for loops. + for (unsigned int i = 0; *(text+i) != '\''\0'\''; ++i) + continue; + return 0; +} + +// Check varargs and va_copy. +static bool +test_varargs (const char *format, ...) +{ + va_list args; + va_start (args, format); + va_list args_copy; + va_copy (args_copy, args); + + const char *str = ""; + int number = 0; + float fnumber = 0; + + while (*format) + { + switch (*format++) + { + case '\''s'\'': // string + str = va_arg (args_copy, const char *); + break; + case '\''d'\'': // int + number = va_arg (args_copy, int); + break; + case '\''f'\'': // float + fnumber = va_arg (args_copy, double); + break; + default: + break; + } + } + va_end (args_copy); + va_end (args); + + return *str && number && fnumber; +} +' + +# Test code for whether the C compiler supports C99 (body of main). +ac_c_conftest_c99_main=' + // Check bool. + _Bool success = false; + success |= (argc != 0); + + // Check restrict. + if (test_restrict ("String literal") == 0) + success = true; + char *restrict newvar = "Another string"; + + // Check varargs. + success &= test_varargs ("s, d'\'' f .", "string", 65, 34.234); + test_varargs_macros (); + + // Check flexible array members. + struct incomplete_array *ia = + malloc (sizeof (struct incomplete_array) + (sizeof (double) * 10)); + ia->datasize = 10; + for (int i = 0; i < ia->datasize; ++i) + ia->data[i] = i * 1.234; + + // Check named initializers. + struct named_init ni = { + .number = 34, + .name = L"Test wide string", + .average = 543.34343, + }; + + ni.number = 58; + + int dynamic_array[ni.number]; + dynamic_array[0] = argv[0][0]; + dynamic_array[ni.number - 1] = 543; + + // work around unused variable warnings + ok |= (!success || bignum == 0LL || ubignum == 0uLL || newvar[0] == '\''x'\'' + || dynamic_array[ni.number - 1] != 543); +' + +# Test code for whether the C compiler supports C11 (global declarations) +ac_c_conftest_c11_globals=' +// Does the compiler advertise C11 conformance? +#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112L +# error "Compiler does not advertise C11 conformance" +#endif + +// Check _Alignas. +char _Alignas (double) aligned_as_double; +char _Alignas (0) no_special_alignment; +extern char aligned_as_int; +char _Alignas (0) _Alignas (int) aligned_as_int; + +// Check _Alignof. +enum +{ + int_alignment = _Alignof (int), + int_array_alignment = _Alignof (int[100]), + char_alignment = _Alignof (char) +}; +_Static_assert (0 < -_Alignof (int), "_Alignof is signed"); + +// Check _Noreturn. +int _Noreturn does_not_return (void) { for (;;) continue; } + +// Check _Static_assert. +struct test_static_assert +{ + int x; + _Static_assert (sizeof (int) <= sizeof (long int), + "_Static_assert does not work in struct"); + long int y; +}; + +// Check UTF-8 literals. +#define u8 syntax error! +char const utf8_literal[] = u8"happens to be ASCII" "another string"; + +// Check duplicate typedefs. +typedef long *long_ptr; +typedef long int *long_ptr; +typedef long_ptr long_ptr; + +// Anonymous structures and unions -- taken from C11 6.7.2.1 Example 1. +struct anonymous +{ + union { + struct { int i; int j; }; + struct { int k; long int l; } w; + }; + int m; +} v1; +' + +# Test code for whether the C compiler supports C11 (body of main). +ac_c_conftest_c11_main=' + _Static_assert ((offsetof (struct anonymous, i) + == offsetof (struct anonymous, w.k)), + "Anonymous union alignment botch"); + v1.i = 2; + v1.w.k = 5; + ok |= v1.i != 5; +' + +# Test code for whether the C compiler supports C11 (complete). +ac_c_conftest_c11_program="${ac_c_conftest_c89_globals} +${ac_c_conftest_c99_globals} +${ac_c_conftest_c11_globals} + +int +main (int argc, char **argv) +{ + int ok = 0; + ${ac_c_conftest_c89_main} + ${ac_c_conftest_c99_main} + ${ac_c_conftest_c11_main} + return ok; +} +" + +# Test code for whether the C compiler supports C99 (complete). +ac_c_conftest_c99_program="${ac_c_conftest_c89_globals} +${ac_c_conftest_c99_globals} + +int +main (int argc, char **argv) +{ + int ok = 0; + ${ac_c_conftest_c89_main} + ${ac_c_conftest_c99_main} + return ok; +} +" + +# Test code for whether the C compiler supports C89 (complete). +ac_c_conftest_c89_program="${ac_c_conftest_c89_globals} + +int +main (int argc, char **argv) +{ + int ok = 0; + ${ac_c_conftest_c89_main} + return ok; +} +" + +as_fn_append ac_header_c_list " stdio.h stdio_h HAVE_STDIO_H" +as_fn_append ac_header_c_list " stdlib.h stdlib_h HAVE_STDLIB_H" +as_fn_append ac_header_c_list " string.h string_h HAVE_STRING_H" +as_fn_append ac_header_c_list " inttypes.h inttypes_h HAVE_INTTYPES_H" +as_fn_append ac_header_c_list " stdint.h stdint_h HAVE_STDINT_H" +as_fn_append ac_header_c_list " strings.h strings_h HAVE_STRINGS_H" +as_fn_append ac_header_c_list " sys/stat.h sys_stat_h HAVE_SYS_STAT_H" +as_fn_append ac_header_c_list " sys/types.h sys_types_h HAVE_SYS_TYPES_H" +as_fn_append ac_header_c_list " unistd.h unistd_h HAVE_UNISTD_H" + +# Auxiliary files required by this configure script. +ac_aux_files="config.guess config.sub ltmain.sh compile missing install-sh" + +# Locations in which to look for auxiliary files. +ac_aux_dir_candidates="${srcdir}/admin" + +# Search for a directory containing all of the required auxiliary files, +# $ac_aux_files, from the $PATH-style list $ac_aux_dir_candidates. +# If we don't find one directory that contains all the files we need, +# we report the set of missing files from the *first* directory in +# $ac_aux_dir_candidates and give up. +ac_missing_aux_files="" +ac_first_candidate=: +printf "%s\n" "$as_me:${as_lineno-$LINENO}: looking for aux files: $ac_aux_files" >&5 +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +as_found=false +for as_dir in $ac_aux_dir_candidates +do + IFS=$as_save_IFS + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + as_found=: + + printf "%s\n" "$as_me:${as_lineno-$LINENO}: trying $as_dir" >&5 + ac_aux_dir_found=yes + ac_install_sh= + for ac_aux in $ac_aux_files + do + # As a special case, if "install-sh" is required, that requirement + # can be satisfied by any of "install-sh", "install.sh", or "shtool", + # and $ac_install_sh is set appropriately for whichever one is found. + if test x"$ac_aux" = x"install-sh" + then + if test -f "${as_dir}install-sh"; then + printf "%s\n" "$as_me:${as_lineno-$LINENO}: ${as_dir}install-sh found" >&5 + ac_install_sh="${as_dir}install-sh -c" + elif test -f "${as_dir}install.sh"; then + printf "%s\n" "$as_me:${as_lineno-$LINENO}: ${as_dir}install.sh found" >&5 + ac_install_sh="${as_dir}install.sh -c" + elif test -f "${as_dir}shtool"; then + printf "%s\n" "$as_me:${as_lineno-$LINENO}: ${as_dir}shtool found" >&5 + ac_install_sh="${as_dir}shtool install -c" + else + ac_aux_dir_found=no + if $ac_first_candidate; then + ac_missing_aux_files="${ac_missing_aux_files} install-sh" + else + break + fi + fi + else + if test -f "${as_dir}${ac_aux}"; then + printf "%s\n" "$as_me:${as_lineno-$LINENO}: ${as_dir}${ac_aux} found" >&5 + else + ac_aux_dir_found=no + if $ac_first_candidate; then + ac_missing_aux_files="${ac_missing_aux_files} ${ac_aux}" + else + break + fi + fi + fi + done + if test "$ac_aux_dir_found" = yes; then + ac_aux_dir="$as_dir" + break + fi + ac_first_candidate=false + + as_found=false +done +IFS=$as_save_IFS +if $as_found +then : + +else $as_nop + as_fn_error $? "cannot find required auxiliary files:$ac_missing_aux_files" "$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. +if test -f "${ac_aux_dir}config.guess"; then + ac_config_guess="$SHELL ${ac_aux_dir}config.guess" +fi +if test -f "${ac_aux_dir}config.sub"; then + ac_config_sub="$SHELL ${ac_aux_dir}config.sub" +fi +if test -f "$ac_aux_dir/configure"; then + ac_configure="$SHELL ${ac_aux_dir}configure" +fi + # Check that the precious variables saved in the cache have kept the same # value. ac_cache_corrupted=false @@ -2527,12 +2878,12 @@ 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;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 +printf "%s\n" "$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;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5 +printf "%s\n" "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} ac_cache_corrupted=: ;; ,);; *) @@ -2541,24 +2892,24 @@ 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;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5 +printf "%s\n" "$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;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5 +printf "%s\n" "$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;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: former value: \`$ac_old_val'" >&5 +printf "%s\n" "$as_me: former value: \`$ac_old_val'" >&2;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: current value: \`$ac_new_val'" >&5 +printf "%s\n" "$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=`printf "%s\n" "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;; *) ac_arg=$ac_var=$ac_new_val ;; esac case " $ac_configure_args " in @@ -2568,11 +2919,12 @@ 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5 +printf "%s\n" "$as_me: error: changes in the environment can compromise the build" >&2;} + as_fn_error $? "run \`${MAKE-make} distclean' and/or \`rm $cache_file' + and start over" "$LINENO" 5 fi ## -------------------- ## ## Main body of script. ## @@ -2588,42 +2940,16 @@ -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. +ac_config_headers="$ac_config_headers config.h" -ac_config_headers="$ac_config_headers config.h" +am__api_version='1.16' -am__api_version='1.15' -# Find a good install program. We prefer a C program (faster), + # 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 @@ -2637,20 +2963,25 @@ # 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for a BSD-compatible install" >&5 +printf %s "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 +if test ${ac_cv_path_install+y} +then : + printf %s "(cached) " >&6 +else $as_nop 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]/* | \ + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + # Account for fact that we put trailing slashes in our PATH walk. +case $as_dir in #(( + ./ | /[cC]/* | \ /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \ ?:[\\/]os2[\\/]install[\\/]* | ?:[\\/]OS2[\\/]INSTALL[\\/]* | \ /usr/ucb/* ) ;; @@ -2660,13 +2991,13 @@ # 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 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 + 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 + 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 @@ -2674,12 +3005,12 @@ 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" && + 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" + ac_cv_path_install="$as_dir$ac_prog$ac_exec_ext -c" break 3 fi fi @@ -2695,7 +3026,7 @@ rm -rf conftest.one conftest.two conftest.dir fi - if test "${ac_cv_path_install+set}" = set; then + if test ${ac_cv_path_install+y}; then INSTALL=$ac_cv_path_install else # As a last resort, use the slow shell script. Don't cache a @@ -2705,8 +3036,8 @@ INSTALL=$ac_install_sh fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $INSTALL" >&5 -$as_echo "$INSTALL" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $INSTALL" >&5 +printf "%s\n" "$INSTALL" >&6; } # Use test -z because SunOS4 sh mishandles braces in ${var-val}. # It thinks the first close brace ends the variable substitution. @@ -2716,8 +3047,8 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether build environment is sane" >&5 +printf %s "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=' @@ -2771,8 +3102,8 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "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= @@ -2791,26 +3122,23 @@ # 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"` +program_transform_name=`printf "%s\n" "$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 + + if test x"${MISSING+set}" != xset; then + MISSING="\${SHELL} '$am_aux_dir/missing'" 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;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: 'missing' script is too old or missing" >&5 +printf "%s\n" "$as_me: WARNING: 'missing' script is too old or missing" >&2;} fi if test x"${install_sh+set}" != xset; then @@ -2830,11 +3158,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_STRIP+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$STRIP"; then ac_cv_prog_STRIP="$STRIP" # Let the user override the test. else @@ -2842,11 +3171,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -2857,11 +3190,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $STRIP" >&5 +printf "%s\n" "$STRIP" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -2870,11 +3203,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_STRIP+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_STRIP"; then ac_cv_prog_ac_ct_STRIP="$ac_ct_STRIP" # Let the user override the test. else @@ -2882,11 +3216,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -2897,11 +3235,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_STRIP" >&5 +printf "%s\n" "$ac_ct_STRIP" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi if test "x$ac_ct_STRIP" = x; then @@ -2909,8 +3247,8 @@ 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;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac STRIP=$ac_ct_STRIP @@ -2922,25 +3260,31 @@ 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; } + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for a race-free mkdir -p" >&5 +printf %s "checking for a race-free mkdir -p... " >&6; } if test -z "$MKDIR_P"; then - if ${ac_cv_path_mkdir+:} false; then : - $as_echo_n "(cached) " >&6 -else + if test ${ac_cv_path_mkdir+y} +then : + printf %s "(cached) " >&6 +else $as_nop 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=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac 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) '* | \ + 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 ('*'coreutils) '* | \ + 'BusyBox '* | \ 'mkdir (fileutils) '4.1*) - ac_cv_path_mkdir=$as_dir/$ac_prog$ac_exec_ext + ac_cv_path_mkdir=$as_dir$ac_prog$ac_exec_ext break 3;; esac done @@ -2951,7 +3295,7 @@ fi test -d ./--version && rmdir ./--version - if test "${ac_cv_path_mkdir+set}" = set; then + if test ${ac_cv_path_mkdir+y}; then MKDIR_P="$ac_cv_path_mkdir -p" else # As a last resort, use the slow shell script. Don't cache a @@ -2961,18 +3305,19 @@ MKDIR_P="$ac_install_sh -d" fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $MKDIR_P" >&5 -$as_echo "$MKDIR_P" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $MKDIR_P" >&5 +printf "%s\n" "$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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_AWK+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$AWK"; then ac_cv_prog_AWK="$AWK" # Let the user override the test. else @@ -2980,11 +3325,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -2995,24 +3344,25 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $AWK" >&5 +printf "%s\n" "$AWK" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} sets \$(MAKE)" >&5 +printf %s "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 +ac_make=`printf "%s\n" "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'` +if eval test \${ac_cv_prog_make_${ac_make}_set+y} +then : + printf %s "(cached) " >&6 +else $as_nop cat >conftest.make <<\_ACEOF SHELL = /bin/sh all: @@ -3028,12 +3378,12 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } SET_MAKE= else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } SET_MAKE="MAKE=${MAKE-make}" fi @@ -3047,7 +3397,8 @@ rmdir .tst 2>/dev/null # Check whether --enable-silent-rules was given. -if test "${enable_silent_rules+set}" = set; then : +if test ${enable_silent_rules+y} +then : enableval=$enable_silent_rules; fi @@ -3057,12 +3408,13 @@ *) 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)) +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $am_make supports nested variables" >&5 +printf %s "checking whether $am_make supports nested variables... " >&6; } +if test ${am_cv_make_support_nested_variables+y} +then : + printf %s "(cached) " >&6 +else $as_nop + if printf "%s\n" 'TRUE=$(BAR$(V)) BAR0=false BAR1=true V=1 @@ -3074,8 +3426,8 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $am_cv_make_support_nested_variables" >&5 +printf "%s\n" "$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)' @@ -3110,14 +3462,10 @@ VERSION='1.2.4' -cat >>confdefs.h <<_ACEOF -#define PACKAGE "$PACKAGE" -_ACEOF +printf "%s\n" "#define PACKAGE \"$PACKAGE\"" >>confdefs.h -cat >>confdefs.h <<_ACEOF -#define VERSION "$VERSION" -_ACEOF +printf "%s\n" "#define VERSION \"$VERSION\"" >>confdefs.h # Some tools Automake needs. @@ -3137,8 +3485,8 @@ # 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 @@ -3189,7 +3537,7 @@ 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: . +that behaves properly: . If you want to complete the configuration process using your problematic 'rm' anyway, export the environment variable ACCEPT_INFERIOR_RM_PROGRAM @@ -3202,17 +3550,18 @@ -{ $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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether to enable maintainer-specific portions of Makefiles" >&5 +printf %s "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 : +if test ${enable_maintainer_mode+y} +then : enableval=$enable_maintainer_mode; USE_MAINTAINER_MODE=$enableval -else +else $as_nop USE_MAINTAINER_MODE=no fi - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $USE_MAINTAINER_MODE" >&5 -$as_echo "$USE_MAINTAINER_MODE" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $USE_MAINTAINER_MODE" >&5 +printf "%s\n" "$USE_MAINTAINER_MODE" >&6; } if test $USE_MAINTAINER_MODE = yes; then MAINTAINER_MODE_TRUE= MAINTAINER_MODE_FALSE='#' @@ -3268,6 +3617,15 @@ # Checks for programs. + + + + + + + + + ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' @@ -3276,11 +3634,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_CC+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else @@ -3288,11 +3647,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -3303,11 +3666,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +printf "%s\n" "$CC" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -3316,11 +3679,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_CC+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_CC"; then ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. else @@ -3328,11 +3692,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -3343,11 +3711,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 +printf "%s\n" "$ac_ct_CC" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi if test "x$ac_ct_CC" = x; then @@ -3355,8 +3723,8 @@ 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;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac CC=$ac_ct_CC @@ -3369,11 +3737,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_CC+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else @@ -3381,11 +3750,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -3396,11 +3769,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +printf "%s\n" "$CC" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -3409,11 +3782,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_CC+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else @@ -3422,57 +3796,172 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac 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 + 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 + printf "%s\n" "$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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +printf "%s\n" "$CC" >&6; } +else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_CC+y} +then : + printf %s "(cached) " >&6 +else $as_nop + 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 + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + 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" + printf "%s\n" "$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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +printf "%s\n" "$CC" >&6; } +else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_CC+y} +then : + printf %s "(cached) " >&6 +else $as_nop + 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 + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + 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" + printf "%s\n" "$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; } +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 +printf "%s\n" "$ac_ct_CC" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "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:) +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + CC=$ac_ct_CC + fi +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 + # Extract the first word of "${ac_tool_prefix}clang", so it can be a program name with args. +set dummy ${ac_tool_prefix}clang; ac_word=$2 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_CC+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else @@ -3480,11 +3969,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac 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 + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + ac_cv_prog_CC="${ac_tool_prefix}clang" + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -3495,28 +3988,25 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +printf "%s\n" "$CC" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi - test -n "$CC" && break - done fi -if test -z "$CC"; then +if test -z "$ac_cv_prog_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 + # Extract the first word of "clang", so it can be a program name with args. +set dummy clang; ac_word=$2 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_CC+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_CC"; then ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. else @@ -3524,11 +4014,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac 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 + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_CC="clang" + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -3539,50 +4033,48 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 +printf "%s\n" "$ac_ct_CC" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "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;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$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 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;} +test -z "$CC" && { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$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 +printf "%s\n" "$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 +for ac_option in --version -v -V -qversion -version; 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 +printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_compiler $ac_option >&5") 2>conftest.err ac_status=$? if test -s conftest.err; then @@ -3592,7 +4084,7 @@ cat conftest.er1 >&5 fi rm -f conftest.er1 conftest.err - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } done @@ -3600,7 +4092,7 @@ /* end confdefs.h. */ int -main () +main (void) { ; @@ -3612,9 +4104,9 @@ # 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[^ ]*//'` +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5 +printf %s "checking whether the C compiler works... " >&6; } +ac_link_default=`printf "%s\n" "$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.*" @@ -3635,11 +4127,12 @@ *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 +printf "%s\n" "$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 : + printf "%s\n" "$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, @@ -3656,7 +4149,7 @@ # certainly right. break;; *.* ) - if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no; + if test ${ac_cv_exeext+y} && test "$ac_cv_exeext" != no; then :; else ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` fi @@ -3672,44 +4165,46 @@ done test "$ac_cv_exeext" = no && ac_cv_exeext= -else +else $as_nop 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 +if test -z "$ac_file" +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } +printf "%s\n" "$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;} +{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$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; } +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5 +printf %s "checking for C compiler default output file name... " >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5 +printf "%s\n" "$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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5 +printf %s "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 +printf "%s\n" "$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 : + printf "%s\n" "$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 @@ -3723,15 +4218,15 @@ * ) 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;} +else $as_nop + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5 +printf "%s\n" "$ac_cv_exeext" >&6; } rm -f conftest.$ac_ext EXEEXT=$ac_cv_exeext @@ -3740,7 +4235,7 @@ /* end confdefs.h. */ #include int -main () +main (void) { FILE *f = fopen ("conftest.out", "w"); return ferror (f) || fclose (f) != 0; @@ -3752,8 +4247,8 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5 +printf %s "checking whether we are cross compiling... " >&6; } if test "$cross_compiling" != yes; then { { ac_try="$ac_link" case "(($ac_try" in @@ -3761,10 +4256,10 @@ *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 +printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_link") 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } if { ac_try='./conftest$ac_cv_exeext' { { case "(($ac_try" in @@ -3772,39 +4267,40 @@ *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 +printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_try") 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$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. + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error 77 "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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5 +printf "%s\n" "$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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5 +printf %s "checking for suffix of object files... " >&6; } +if test ${ac_cv_objext+y} +then : + printf %s "(cached) " >&6 +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main () +main (void) { ; @@ -3818,11 +4314,12 @@ *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 +printf "%s\n" "$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 : + printf "%s\n" "$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 @@ -3831,31 +4328,32 @@ break;; esac done -else - $as_echo "$as_me: failed program was:" >&5 +else $as_nop + printf "%s\n" "$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;} +{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5 +printf "%s\n" "$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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports GNU C" >&5 +printf %s "checking whether the compiler supports GNU C... " >&6; } +if test ${ac_cv_c_compiler_gnu+y} +then : + printf %s "(cached) " >&6 +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main () +main (void) { #ifndef __GNUC__ choke me @@ -3865,29 +4363,33 @@ return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : ac_compiler_gnu=yes -else +else $as_nop ac_compiler_gnu=no fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5 +printf "%s\n" "$ac_cv_c_compiler_gnu" >&6; } +ac_compiler_gnu=$ac_cv_c_compiler_gnu + if test $ac_compiler_gnu = yes; then GCC=yes else GCC= fi -ac_test_CFLAGS=${CFLAGS+set} +ac_test_CFLAGS=${CFLAGS+y} 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5 +printf %s "checking whether $CC accepts -g... " >&6; } +if test ${ac_cv_prog_cc_g+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_save_c_werror_flag=$ac_c_werror_flag ac_c_werror_flag=yes ac_cv_prog_cc_g=no @@ -3896,57 +4398,60 @@ /* end confdefs.h. */ int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : ac_cv_prog_cc_g=yes -else +else $as_nop CFLAGS="" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : -else +else $as_nop ac_c_werror_flag=$ac_save_c_werror_flag CFLAGS="-g" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +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 +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5 +printf "%s\n" "$ac_cv_prog_cc_g" >&6; } +if test $ac_test_CFLAGS; then CFLAGS=$ac_save_CFLAGS elif test $ac_cv_prog_cc_g = yes; then if test "$GCC" = yes; then @@ -3961,94 +4466,144 @@ 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_prog_cc_stdc=no +if test x$ac_prog_cc_stdc = xno +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC option to enable C11 features" >&5 +printf %s "checking for $CC option to enable C11 features... " >&6; } +if test ${ac_cv_prog_cc_c11+y} +then : + printf %s "(cached) " >&6 +else $as_nop + ac_cv_prog_cc_c11=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]; +$ac_c_conftest_c11_program +_ACEOF +for ac_arg in '' -std=gnu11 +do + CC="$ac_save_CC $ac_arg" + if ac_fn_c_try_compile "$LINENO" +then : + ac_cv_prog_cc_c11=$ac_arg +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam + test "x$ac_cv_prog_cc_c11" != "xno" && break +done +rm -f conftest.$ac_ext +CC=$ac_save_CC +fi -/* 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]; +if test "x$ac_cv_prog_cc_c11" = xno +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 +printf "%s\n" "unsupported" >&6; } +else $as_nop + if test "x$ac_cv_prog_cc_c11" = x +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 +printf "%s\n" "none needed" >&6; } +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c11" >&5 +printf "%s\n" "$ac_cv_prog_cc_c11" >&6; } + CC="$CC $ac_cv_prog_cc_c11" +fi + ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c11 + ac_prog_cc_stdc=c11 +fi +fi +if test x$ac_prog_cc_stdc = xno +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC option to enable C99 features" >&5 +printf %s "checking for $CC option to enable C99 features... " >&6; } +if test ${ac_cv_prog_cc_c99+y} +then : + printf %s "(cached) " >&6 +else $as_nop + ac_cv_prog_cc_c99=no +ac_save_CC=$CC +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$ac_c_conftest_c99_program +_ACEOF +for ac_arg in '' -std=gnu99 -std=c99 -c99 -qlanglvl=extc1x -qlanglvl=extc99 -AC99 -D_STDC_C99= +do + CC="$ac_save_CC $ac_arg" + if ac_fn_c_try_compile "$LINENO" +then : + ac_cv_prog_cc_c99=$ac_arg +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam + test "x$ac_cv_prog_cc_c99" != "xno" && break +done +rm -f conftest.$ac_ext +CC=$ac_save_CC +fi -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; -} +if test "x$ac_cv_prog_cc_c99" = xno +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 +printf "%s\n" "unsupported" >&6; } +else $as_nop + if test "x$ac_cv_prog_cc_c99" = x +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 +printf "%s\n" "none needed" >&6; } +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c99" >&5 +printf "%s\n" "$ac_cv_prog_cc_c99" >&6; } + CC="$CC $ac_cv_prog_cc_c99" +fi + ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c99 + ac_prog_cc_stdc=c99 +fi +fi +if test x$ac_prog_cc_stdc = xno +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC option to enable C89 features" >&5 +printf %s "checking for $CC option to enable C89 features... " >&6; } +if test ${ac_cv_prog_cc_c89+y} +then : + printf %s "(cached) " >&6 +else $as_nop + ac_cv_prog_cc_c89=no +ac_save_CC=$CC +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$ac_c_conftest_c89_program _ACEOF -for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \ - -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" +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 : + if ac_fn_c_try_compile "$LINENO" +then : ac_cv_prog_cc_c89=$ac_arg fi -rm -f core conftest.err conftest.$ac_objext +rm -f core conftest.err conftest.$ac_objext conftest.beam 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 : +if test "x$ac_cv_prog_cc_c89" = xno +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 +printf "%s\n" "unsupported" >&6; } +else $as_nop + if test "x$ac_cv_prog_cc_c89" = x +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 +printf "%s\n" "none needed" >&6; } +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5 +printf "%s\n" "$ac_cv_prog_cc_c89" >&6; } + CC="$CC $ac_cv_prog_cc_c89" +fi + ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c89 + ac_prog_cc_stdc=c89 +fi fi ac_ext=c @@ -4057,21 +4612,23 @@ 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_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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC understands -c and -o together" >&5 +printf %s "checking whether $CC understands -c and -o together... " >&6; } +if test ${am_cv_prog_cc_c_o+y} +then : + printf %s "(cached) " >&6 +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main () +main (void) { ; @@ -4099,8 +4656,8 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $am_cv_prog_cc_c_o" >&5 +printf "%s\n" "$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. @@ -4119,48 +4676,49 @@ ac_config_commands="$ac_config_commands depfiles" - -am_make=${MAKE-make} -cat > confinc << 'END' +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} supports the include directive" >&5 +printf %s "checking whether ${MAKE-make} supports the include directive... " >&6; } +cat > confinc.mk << 'END' am__doit: - @echo this is the am__doit target + @echo this is the am__doit target >confinc.out .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 +# BSD make does it like this. +echo '.include "confinc.mk" # ignored' > confmf.BSD +# Other make implementations (GNU, Solaris 10, AIX) do it like this. +echo 'include confinc.mk # ignored' > confmf.GNU +_am_result=no +for s in GNU BSD; do + { echo "$as_me:$LINENO: ${MAKE-make} -f confmf.$s && cat confinc.out" >&5 + (${MAKE-make} -f confmf.$s && cat confinc.out) >&5 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } + case $?:`cat confinc.out 2>/dev/null` in #( + '0:this is the am__doit target') : + case $s in #( + BSD) : + am__include='.include' am__quote='"' ;; #( + *) : + am__include='include' am__quote='' ;; +esac ;; #( + *) : ;; - esac -fi - - -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $_am_result" >&5 -$as_echo "$_am_result" >&6; } -rm -f confinc confmf +esac + if test "$am__include" != "#"; then + _am_result="yes ($s style)" + break + fi +done +rm -f confinc.* confmf.* +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: ${_am_result}" >&5 +printf "%s\n" "${_am_result}" >&6; } # Check whether --enable-dependency-tracking was given. -if test "${enable_dependency_tracking+set}" = set; then : +if test ${enable_dependency_tracking+y} +then : enableval=$enable_dependency_tracking; fi @@ -4181,11 +4739,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking dependency style of $depcc" >&5 +printf %s "checking dependency style of $depcc... " >&6; } +if test ${am_cv_CC_dependencies_compiler_type+y} +then : + printf %s "(cached) " >&6 +else $as_nop 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 @@ -4292,8 +4851,8 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $am_cv_CC_dependencies_compiler_type" >&5 +printf "%s\n" "$am_cv_CC_dependencies_compiler_type" >&6; } CCDEPMODE=depmode=$am_cv_CC_dependencies_compiler_type if @@ -4313,11 +4872,12 @@ 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -std=c99" >&5 +printf %s "checking whether $CC supports -std=c99... " >&6; } +if eval test \${eso_cv_prog_cc_$flag+y} +then : + printf %s "(cached) " >&6 +else $as_nop eval "eso_cv_prog_cc_$flag=no" ac_ext=c @@ -4348,8 +4908,8 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then : @@ -4366,11 +4926,12 @@ 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -fno-builtin" >&5 +printf %s "checking whether $CC supports -fno-builtin... " >&6; } +if eval test \${eso_cv_prog_cc_$flag+y} +then : + printf %s "(cached) " >&6 +else $as_nop eval "eso_cv_prog_cc_$flag=no" ac_ext=c @@ -4401,8 +4962,8 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then : @@ -4416,11 +4977,12 @@ 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -fno-common" >&5 +printf %s "checking whether $CC supports -fno-common... " >&6; } +if eval test \${eso_cv_prog_cc_$flag+y} +then : + printf %s "(cached) " >&6 +else $as_nop eval "eso_cv_prog_cc_$flag=no" ac_ext=c @@ -4451,8 +5013,8 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then : @@ -4470,22 +5032,24 @@ # Check whether --enable-debug was given. -if test "${enable_debug+set}" = set; then : +if test ${enable_debug+y} +then : enableval=$enable_debug; eso_enable_debug=$enableval -else +else $as_nop 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether debugging code should be created" >&5 +printf %s "checking whether debugging code should be created... " >&6; } +if test ${eso_cv_enable_debug+y} +then : + printf %s "(cached) " >&6 +else $as_nop 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $eso_cv_enable_debug" >&5 +printf "%s\n" "$eso_cv_enable_debug" >&6; } if test x"$eso_cv_enable_debug" = xyes; then @@ -4498,11 +5062,12 @@ 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -g3" >&5 +printf %s "checking whether $CC supports -g3... " >&6; } +if eval test \${eso_cv_prog_cc_$flag+y} +then : + printf %s "(cached) " >&6 +else $as_nop eval "eso_cv_prog_cc_$flag=no" ac_ext=c @@ -4533,8 +5098,8 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then : @@ -4559,11 +5124,12 @@ 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -ggdb" >&5 +printf %s "checking whether $CC supports -ggdb... " >&6; } +if eval test \${eso_cv_prog_cc_$flag+y} +then : + printf %s "(cached) " >&6 +else $as_nop eval "eso_cv_prog_cc_$flag=no" ac_ext=c @@ -4594,8 +5160,8 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then : @@ -4609,11 +5175,12 @@ 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -O0" >&5 +printf %s "checking whether $CC supports -O0... " >&6; } +if eval test \${eso_cv_prog_cc_$flag+y} +then : + printf %s "(cached) " >&6 +else $as_nop eval "eso_cv_prog_cc_$flag=no" ac_ext=c @@ -4644,8 +5211,8 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then : @@ -4659,11 +5226,12 @@ 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -rdynamic" >&5 +printf %s "checking whether $CC supports -rdynamic... " >&6; } +if eval test \${eso_cv_prog_cc_$flag+y} +then : + printf %s "(cached) " >&6 +else $as_nop eval "eso_cv_prog_cc_$flag=no" ac_ext=c @@ -4694,8 +5262,8 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then : @@ -4709,11 +5277,12 @@ 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -Wall" >&5 +printf %s "checking whether $CC supports -Wall... " >&6; } +if eval test \${eso_cv_prog_cc_$flag+y} +then : + printf %s "(cached) " >&6 +else $as_nop eval "eso_cv_prog_cc_$flag=no" ac_ext=c @@ -4744,8 +5313,8 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then : @@ -4759,11 +5328,12 @@ 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -W" >&5 +printf %s "checking whether $CC supports -W... " >&6; } +if eval test \${eso_cv_prog_cc_$flag+y} +then : + printf %s "(cached) " >&6 +else $as_nop eval "eso_cv_prog_cc_$flag=no" ac_ext=c @@ -4794,8 +5364,8 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then : @@ -4823,11 +5393,12 @@ -{ $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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5 +printf %s "checking for grep that handles long lines and -e... " >&6; } +if test ${ac_cv_path_GREP+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -z "$GREP"; then ac_path_GREP_found=false # Loop through the user's path and test for each of PROGNAME-LIST @@ -4835,10 +5406,15 @@ 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 + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + 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" + 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 @@ -4847,13 +5423,13 @@ ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;; *) ac_count=0 - $as_echo_n 0123456789 >"conftest.in" + printf %s 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" + printf "%s\n" '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 @@ -4881,16 +5457,17 @@ fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5 -$as_echo "$ac_cv_path_GREP" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5 +printf "%s\n" "$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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5 +printf %s "checking for egrep... " >&6; } +if test ${ac_cv_path_EGREP+y} +then : + printf %s "(cached) " >&6 +else $as_nop if echo a | $GREP -E '(a|b)' >/dev/null 2>&1 then ac_cv_path_EGREP="$GREP -E" else @@ -4901,10 +5478,15 @@ 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 + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + 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" + 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 @@ -4913,13 +5495,13 @@ ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;; *) ac_count=0 - $as_echo_n 0123456789 >"conftest.in" + printf %s 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" + printf "%s\n" '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 @@ -4948,8 +5530,8 @@ fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5 -$as_echo "$ac_cv_path_EGREP" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5 +printf "%s\n" "$ac_cv_path_EGREP" >&6; } EGREP="$ac_cv_path_EGREP" @@ -4958,22 +5540,24 @@ # Check whether --enable-strict was given. -if test "${enable_strict+set}" = set; then : +if test ${enable_strict+y} +then : enableval=$enable_strict; eso_enable_strict=$enableval -else +else $as_nop 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether strict compiler options should be used" >&5 +printf %s "checking whether strict compiler options should be used... " >&6; } +if test ${eso_cv_enable_strict+y} +then : + printf %s "(cached) " >&6 +else $as_nop 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $eso_cv_enable_strict" >&5 +printf "%s\n" "$eso_cv_enable_strict" >&6; } if test x"$eso_cv_enable_strict" = xyes; then @@ -4992,11 +5576,12 @@ 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -std=c99" >&5 +printf %s "checking whether $CC supports -std=c99... " >&6; } +if eval test \${eso_cv_prog_cc_$flag+y} +then : + printf %s "(cached) " >&6 +else $as_nop eval "eso_cv_prog_cc_$flag=no" ac_ext=c @@ -5027,8 +5612,8 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then : @@ -5044,11 +5629,12 @@ 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -pedantic" >&5 +printf %s "checking whether $CC supports -pedantic... " >&6; } +if eval test \${eso_cv_prog_cc_$flag+y} +then : + printf %s "(cached) " >&6 +else $as_nop eval "eso_cv_prog_cc_$flag=no" ac_ext=c @@ -5079,8 +5665,8 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then : @@ -5098,11 +5684,12 @@ # 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_path_DOXYGEN+y} +then : + printf %s "(cached) " >&6 +else $as_nop case $DOXYGEN in [\\/]* | ?:[\\/]*) ac_cv_path_DOXYGEN="$DOXYGEN" # Let the user override the test with a path. @@ -5112,11 +5699,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac 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 + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + ac_cv_path_DOXYGEN="$as_dir$ac_word$ac_exec_ext" + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -5128,11 +5719,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $DOXYGEN" >&5 +printf "%s\n" "$DOXYGEN" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -5140,11 +5731,12 @@ # 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_path_LATEX+y} +then : + printf %s "(cached) " >&6 +else $as_nop case $LATEX in [\\/]* | ?:[\\/]*) ac_cv_path_LATEX="$LATEX" # Let the user override the test with a path. @@ -5154,11 +5746,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac 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 + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + ac_cv_path_LATEX="$as_dir$ac_word$ac_exec_ext" + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -5170,11 +5766,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $LATEX" >&5 +printf "%s\n" "$LATEX" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -5191,7 +5787,8 @@ # Check whether --enable-static was given. -if test "${enable_static+set}" = set; then : +if test ${enable_static+y} +then : enableval=$enable_static; p=${PACKAGE-default} case $enableval in yes) enable_static=yes ;; @@ -5209,7 +5806,7 @@ IFS=$lt_save_ifs ;; esac -else +else $as_nop enable_static=yes fi @@ -5222,7 +5819,8 @@ # Check whether --enable-shared was given. -if test "${enable_shared+set}" = set; then : +if test ${enable_shared+y} +then : enableval=$enable_shared; p=${PACKAGE-default} case $enableval in yes) enable_shared=yes ;; @@ -5240,7 +5838,7 @@ IFS=$lt_save_ifs ;; esac -else +else $as_nop enable_shared=yes fi @@ -5256,8 +5854,8 @@ 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;} ;; + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&5 +printf "%s\n" "$as_me: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&2;} ;; esac @@ -5277,28 +5875,32 @@ + ltmain=$ac_aux_dir/ltmain.sh -# 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 + + + # 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 + +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking build system type" >&5 +printf %s "checking build system type... " >&6; } +if test ${ac_cv_build+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_build_alias=$build_alias test "x$ac_build_alias" = x && - ac_build_alias=`$SHELL "$ac_aux_dir/config.guess"` + 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 +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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_build" >&5 +printf "%s\n" "$ac_cv_build" >&6; } case $ac_cv_build in *-*-*) ;; *) as_fn_error $? "invalid value of canonical build" "$LINENO" 5;; @@ -5317,21 +5919,22 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking host system type" >&5 +printf %s "checking host system type... " >&6; } +if test ${ac_cv_host+y} +then : + printf %s "(cached) " >&6 +else $as_nop 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 + 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_host" >&5 +printf "%s\n" "$ac_cv_host" >&6; } case $ac_cv_host in *-*-*) ;; *) as_fn_error $? "invalid value of canonical host" "$LINENO" 5;; @@ -5371,8 +5974,8 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to print strings" >&5 +printf %s "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 @@ -5398,12 +6001,12 @@ } 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; } ;; + printf*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: printf" >&5 +printf "%s\n" "printf" >&6; } ;; + print*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: print -r" >&5 +printf "%s\n" "print -r" >&6; } ;; + *) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: cat" >&5 +printf "%s\n" "cat" >&6; } ;; esac @@ -5419,11 +6022,12 @@ -{ $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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for a sed that does not truncate output" >&5 +printf %s "checking for a sed that does not truncate output... " >&6; } +if test ${ac_cv_path_SED+y} +then : + printf %s "(cached) " >&6 +else $as_nop 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" @@ -5437,10 +6041,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_prog in sed gsed; do + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + 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" + 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 @@ -5449,13 +6058,13 @@ ac_cv_path_SED="$ac_path_SED" ac_path_SED_found=:;; *) ac_count=0 - $as_echo_n 0123456789 >"conftest.in" + printf %s 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" + printf "%s\n" '' >> "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 @@ -5483,8 +6092,8 @@ fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_SED" >&5 -$as_echo "$ac_cv_path_SED" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_SED" >&5 +printf "%s\n" "$ac_cv_path_SED" >&6; } SED="$ac_cv_path_SED" rm -f conftest.sed @@ -5501,11 +6110,12 @@ -{ $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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for fgrep" >&5 +printf %s "checking for fgrep... " >&6; } +if test ${ac_cv_path_FGREP+y} +then : + printf %s "(cached) " >&6 +else $as_nop if echo 'ab*c' | $GREP -F 'ab*c' >/dev/null 2>&1 then ac_cv_path_FGREP="$GREP -F" else @@ -5516,10 +6126,15 @@ 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 + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + 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" + 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 @@ -5528,13 +6143,13 @@ ac_cv_path_FGREP="$ac_path_FGREP" ac_path_FGREP_found=:;; *) ac_count=0 - $as_echo_n 0123456789 >"conftest.in" + printf %s 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" + printf "%s\n" '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 @@ -5563,8 +6178,8 @@ fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_FGREP" >&5 -$as_echo "$ac_cv_path_FGREP" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_FGREP" >&5 +printf "%s\n" "$ac_cv_path_FGREP" >&6; } FGREP="$ac_cv_path_FGREP" @@ -5589,17 +6204,18 @@ # Check whether --with-gnu-ld was given. -if test "${with_gnu_ld+set}" = set; then : +if test ${with_gnu_ld+y} +then : withval=$with_gnu_ld; test no = "$withval" || with_gnu_ld=yes -else +else $as_nop 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for ld used by $CC" >&5 +printf %s "checking for ld used by $CC... " >&6; } case $host in *-*-mingw*) # gcc leaves a trailing carriage return, which upsets mingw @@ -5628,15 +6244,16 @@ ;; 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for GNU ld" >&5 +printf %s "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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for non-GNU ld" >&5 +printf %s "checking for non-GNU ld... " >&6; } fi -if ${lt_cv_path_LD+:} false; then : - $as_echo_n "(cached) " >&6 -else +if test ${lt_cv_path_LD+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -z "$LD"; then lt_save_ifs=$IFS; IFS=$PATH_SEPARATOR for ac_dir in $PATH; do @@ -5665,18 +6282,19 @@ LD=$lt_cv_path_LD if test -n "$LD"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LD" >&5 -$as_echo "$LD" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $LD" >&5 +printf "%s\n" "$LD" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if the linker ($LD) is GNU ld" >&5 +printf %s "checking if the linker ($LD) is GNU ld... " >&6; } +if test ${lt_cv_prog_gnu_ld+y} +then : + printf %s "(cached) " >&6 +else $as_nop # 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_gnu_ld" >&5 +printf "%s\n" "$lt_cv_prog_gnu_ld" >&6; } with_gnu_ld=$lt_cv_prog_gnu_ld @@ -5699,11 +6317,12 @@ -{ $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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for BSD- or MS-compatible name lister (nm)" >&5 +printf %s "checking for BSD- or MS-compatible name lister (nm)... " >&6; } +if test ${lt_cv_path_NM+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$NM"; then # Let the user override the test. lt_cv_path_NM=$NM @@ -5753,8 +6372,8 @@ : ${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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_path_NM" >&5 +printf "%s\n" "$lt_cv_path_NM" >&6; } if test no != "$lt_cv_path_NM"; then NM=$lt_cv_path_NM else @@ -5767,11 +6386,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_DUMPBIN+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$DUMPBIN"; then ac_cv_prog_DUMPBIN="$DUMPBIN" # Let the user override the test. else @@ -5779,11 +6399,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -5794,11 +6418,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $DUMPBIN" >&5 +printf "%s\n" "$DUMPBIN" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -5811,11 +6435,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_DUMPBIN+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_DUMPBIN"; then ac_cv_prog_ac_ct_DUMPBIN="$ac_ct_DUMPBIN" # Let the user override the test. else @@ -5823,11 +6448,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -5838,11 +6467,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DUMPBIN" >&5 +printf "%s\n" "$ac_ct_DUMPBIN" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -5854,8 +6483,8 @@ 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;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac DUMPBIN=$ac_ct_DUMPBIN @@ -5883,11 +6512,12 @@ -{ $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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking the name lister ($NM) interface" >&5 +printf %s "checking the name lister ($NM) interface... " >&6; } +if test ${lt_cv_nm_interface+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_nm_interface="BSD nm" echo "int some_variable = 0;" > conftest.$ac_ext (eval echo "\"\$as_me:$LINENO: $ac_compile\"" >&5) @@ -5903,26 +6533,27 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_nm_interface" >&5 +printf "%s\n" "$lt_cv_nm_interface" >&6; } -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ln -s works" >&5 -$as_echo_n "checking whether ln -s works... " >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether ln -s works" >&5 +printf %s "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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no, using $LN_S" >&5 -$as_echo "no, using $LN_S" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no, using $LN_S" >&5 +printf "%s\n" "no, using $LN_S" >&6; } fi # 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking the maximum length of command line arguments" >&5 +printf %s "checking the maximum length of command line arguments... " >&6; } +if test ${lt_cv_sys_max_cmd_len+y} +then : + printf %s "(cached) " >&6 +else $as_nop i=0 teststring=ABCD @@ -6049,11 +6680,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_sys_max_cmd_len" >&5 +printf "%s\n" "$lt_cv_sys_max_cmd_len" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: none" >&5 -$as_echo "none" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none" >&5 +printf "%s\n" "none" >&6; } fi max_cmd_len=$lt_cv_sys_max_cmd_len @@ -6097,11 +6728,12 @@ -{ $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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to convert $build file names to $host format" >&5 +printf %s "checking how to convert $build file names to $host format... " >&6; } +if test ${lt_cv_to_host_file_cmd+y} +then : + printf %s "(cached) " >&6 +else $as_nop case $host in *-*-mingw* ) case $build in @@ -6137,18 +6769,19 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_to_host_file_cmd" >&5 +printf "%s\n" "$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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to convert $build file names to toolchain format" >&5 +printf %s "checking how to convert $build file names to toolchain format... " >&6; } +if test ${lt_cv_to_tool_file_cmd+y} +then : + printf %s "(cached) " >&6 +else $as_nop #assume ordinary cross tools, or native build. lt_cv_to_tool_file_cmd=func_convert_file_noop case $host in @@ -6164,22 +6797,23 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_to_tool_file_cmd" >&5 +printf "%s\n" "$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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $LD option to reload object files" >&5 +printf %s "checking for $LD option to reload object files... " >&6; } +if test ${lt_cv_ld_reload_flag+y} +then : + printf %s "(cached) " >&6 +else $as_nop 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_reload_flag" >&5 +printf "%s\n" "$lt_cv_ld_reload_flag" >&6; } reload_flag=$lt_cv_ld_reload_flag case $reload_flag in "" | " "*) ;; @@ -6212,11 +6846,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_OBJDUMP+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$OBJDUMP"; then ac_cv_prog_OBJDUMP="$OBJDUMP" # Let the user override the test. else @@ -6224,11 +6859,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -6239,11 +6878,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $OBJDUMP" >&5 +printf "%s\n" "$OBJDUMP" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -6252,11 +6891,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_OBJDUMP+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_OBJDUMP"; then ac_cv_prog_ac_ct_OBJDUMP="$ac_ct_OBJDUMP" # Let the user override the test. else @@ -6264,11 +6904,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -6279,11 +6923,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OBJDUMP" >&5 +printf "%s\n" "$ac_ct_OBJDUMP" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi if test "x$ac_ct_OBJDUMP" = x; then @@ -6291,8 +6935,8 @@ 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;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac OBJDUMP=$ac_ct_OBJDUMP @@ -6311,11 +6955,12 @@ -{ $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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to recognize dependent libraries" >&5 +printf %s "checking how to recognize dependent libraries... " >&6; } +if test ${lt_cv_deplibs_check_method+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_file_magic_cmd='$MAGIC_CMD' lt_cv_file_magic_test_file= lt_cv_deplibs_check_method='unknown' @@ -6511,8 +7156,8 @@ esac fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_deplibs_check_method" >&5 -$as_echo "$lt_cv_deplibs_check_method" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_deplibs_check_method" >&5 +printf "%s\n" "$lt_cv_deplibs_check_method" >&6; } file_magic_glob= want_nocaseglob=no @@ -6556,11 +7201,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_DLLTOOL+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$DLLTOOL"; then ac_cv_prog_DLLTOOL="$DLLTOOL" # Let the user override the test. else @@ -6568,11 +7214,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -6583,11 +7233,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $DLLTOOL" >&5 +printf "%s\n" "$DLLTOOL" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -6596,11 +7246,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_DLLTOOL+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_DLLTOOL"; then ac_cv_prog_ac_ct_DLLTOOL="$ac_ct_DLLTOOL" # Let the user override the test. else @@ -6608,11 +7259,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -6623,11 +7278,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DLLTOOL" >&5 +printf "%s\n" "$ac_ct_DLLTOOL" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi if test "x$ac_ct_DLLTOOL" = x; then @@ -6635,8 +7290,8 @@ 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;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac DLLTOOL=$ac_ct_DLLTOOL @@ -6656,11 +7311,12 @@ -{ $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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to associate runtime and link libraries" >&5 +printf %s "checking how to associate runtime and link libraries... " >&6; } +if test ${lt_cv_sharedlib_from_linklib_cmd+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_sharedlib_from_linklib_cmd='unknown' case $host_os in @@ -6683,8 +7339,8 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_sharedlib_from_linklib_cmd" >&5 +printf "%s\n" "$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 @@ -6700,11 +7356,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_AR+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$AR"; then ac_cv_prog_AR="$AR" # Let the user override the test. else @@ -6712,11 +7369,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -6727,11 +7388,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $AR" >&5 +printf "%s\n" "$AR" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -6744,11 +7405,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_AR+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_AR"; then ac_cv_prog_ac_ct_AR="$ac_ct_AR" # Let the user override the test. else @@ -6756,11 +7418,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -6771,11 +7437,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_AR" >&5 +printf "%s\n" "$ac_ct_AR" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -6787,8 +7453,8 @@ 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;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac AR=$ac_ct_AR @@ -6808,30 +7474,32 @@ -{ $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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for archiver @FILE support" >&5 +printf %s "checking for archiver @FILE support... " >&6; } +if test ${lt_cv_ar_at_file+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_ar_at_file=no cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +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 + printf "%s\n" "$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. @@ -6839,7 +7507,7 @@ { { 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } if test 0 -ne "$ac_status"; then lt_cv_ar_at_file=@ @@ -6848,11 +7516,11 @@ rm -f conftest.* libconftest.a fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ar_at_file" >&5 +printf "%s\n" "$lt_cv_ar_at_file" >&6; } if test no = "$lt_cv_ar_at_file"; then archiver_list_spec= @@ -6869,11 +7537,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_STRIP+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$STRIP"; then ac_cv_prog_STRIP="$STRIP" # Let the user override the test. else @@ -6881,11 +7550,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -6896,11 +7569,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $STRIP" >&5 +printf "%s\n" "$STRIP" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -6909,11 +7582,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_STRIP+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_STRIP"; then ac_cv_prog_ac_ct_STRIP="$ac_ct_STRIP" # Let the user override the test. else @@ -6921,11 +7595,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -6936,11 +7614,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_STRIP" >&5 +printf "%s\n" "$ac_ct_STRIP" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi if test "x$ac_ct_STRIP" = x; then @@ -6948,8 +7626,8 @@ 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;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac STRIP=$ac_ct_STRIP @@ -6968,11 +7646,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_RANLIB+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$RANLIB"; then ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test. else @@ -6980,11 +7659,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -6995,11 +7678,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5 +printf "%s\n" "$RANLIB" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -7008,11 +7691,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_RANLIB+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_RANLIB"; then ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test. else @@ -7020,11 +7704,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -7035,11 +7723,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RANLIB" >&5 +printf "%s\n" "$ac_ct_RANLIB" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi if test "x$ac_ct_RANLIB" = x; then @@ -7047,8 +7735,8 @@ 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;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac RANLIB=$ac_ct_RANLIB @@ -7137,11 +7825,12 @@ # 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking command to parse $NM output from $compiler object" >&5 +printf %s "checking command to parse $NM output from $compiler object... " >&6; } +if test ${lt_cv_sys_global_symbol_pipe+y} +then : + printf %s "(cached) " >&6 +else $as_nop # These are sane defaults that work on at least a few old systems. # [They come from Ultrix. What could be older than Ultrix?!! ;)] @@ -7293,14 +7982,14 @@ 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 + printf "%s\n" "$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 + printf "%s\n" "$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 @@ -7369,7 +8058,7 @@ 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && test -s conftest$ac_exeext; then pipe_works=yes fi @@ -7404,11 +8093,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: failed" >&5 +printf "%s\n" "failed" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: ok" >&5 -$as_echo "ok" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: ok" >&5 +printf "%s\n" "ok" >&6; } fi # Response file support. @@ -7454,13 +8143,14 @@ -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for sysroot" >&5 -$as_echo_n "checking for sysroot... " >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for sysroot" >&5 +printf %s "checking for sysroot... " >&6; } # Check whether --with-sysroot was given. -if test "${with_sysroot+set}" = set; then : +if test ${with_sysroot+y} +then : withval=$with_sysroot; -else +else $as_nop with_sysroot=no fi @@ -7478,24 +8168,25 @@ no|'') ;; #( *) - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_sysroot" >&5 -$as_echo "$with_sysroot" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $with_sysroot" >&5 +printf "%s\n" "$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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: ${lt_sysroot:-no}" >&5 +printf "%s\n" "${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 "%s\n" "$as_me:${as_lineno-$LINENO}: checking for a working dd" >&5 +printf %s "checking for a working dd... " >&6; } +if test ${ac_cv_path_lt_DD+y} +then : + printf %s "(cached) " >&6 +else $as_nop printf 0123456789abcdef0123456789abcdef >conftest.i cat conftest.i conftest.i >conftest2.i : ${lt_DD:=$DD} @@ -7506,10 +8197,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_prog in dd; do + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + 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" + 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 \ @@ -7529,15 +8225,16 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_lt_DD" >&5 +printf "%s\n" "$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 "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to truncate binary pipes" >&5 +printf %s "checking how to truncate binary pipes... " >&6; } +if test ${lt_cv_truncate_bin+y} +then : + printf %s "(cached) " >&6 +else $as_nop printf 0123456789abcdef0123456789abcdef >conftest.i cat conftest.i conftest.i >conftest2.i lt_cv_truncate_bin= @@ -7548,8 +8245,8 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_truncate_bin" >&5 +printf "%s\n" "$lt_cv_truncate_bin" >&6; } @@ -7572,7 +8269,8 @@ } # Check whether --enable-libtool-lock was given. -if test "${enable_libtool_lock+set}" = set; then : +if test ${enable_libtool_lock+y} +then : enableval=$enable_libtool_lock; fi @@ -7588,7 +8286,7 @@ 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then case `/usr/bin/file conftest.$ac_objext` in *ELF-32*) @@ -7608,7 +8306,7 @@ 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 + printf "%s\n" "$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 @@ -7646,7 +8344,7 @@ 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then emul=elf case `/usr/bin/file conftest.$ac_objext` in @@ -7687,7 +8385,7 @@ 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then case `/usr/bin/file conftest.o` in *32-bit*) @@ -7750,11 +8448,12 @@ # 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the C compiler needs -belf" >&5 +printf %s "checking whether the C compiler needs -belf... " >&6; } +if test ${lt_cv_cc_needs_belf+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' @@ -7765,19 +8464,20 @@ /* end confdefs.h. */ int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : lt_cv_cc_needs_belf=yes -else +else $as_nop lt_cv_cc_needs_belf=no fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext ac_ext=c ac_cpp='$CPP $CPPFLAGS' @@ -7786,8 +8486,8 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_cc_needs_belf" >&5 +printf "%s\n" "$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 @@ -7800,7 +8500,7 @@ 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then case `/usr/bin/file conftest.o` in *64-bit*) @@ -7837,11 +8537,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_MANIFEST_TOOL+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$MANIFEST_TOOL"; then ac_cv_prog_MANIFEST_TOOL="$MANIFEST_TOOL" # Let the user override the test. else @@ -7849,11 +8550,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -7864,11 +8569,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $MANIFEST_TOOL" >&5 +printf "%s\n" "$MANIFEST_TOOL" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -7877,11 +8582,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_MANIFEST_TOOL+y} +then : + printf %s "(cached) " >&6 +else $as_nop 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 @@ -7889,11 +8595,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -7904,11 +8614,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_MANIFEST_TOOL" >&5 +printf "%s\n" "$ac_ct_MANIFEST_TOOL" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi if test "x$ac_ct_MANIFEST_TOOL" = x; then @@ -7916,8 +8626,8 @@ 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;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac MANIFEST_TOOL=$ac_ct_MANIFEST_TOOL @@ -7927,11 +8637,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $MANIFEST_TOOL is a manifest tool" >&5 +printf %s "checking if $MANIFEST_TOOL is a manifest tool... " >&6; } +if test ${lt_cv_path_mainfest_tool+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_path_mainfest_tool=no echo "$as_me:$LINENO: $MANIFEST_TOOL '-?'" >&5 $MANIFEST_TOOL '-?' 2>conftest.err > conftest.out @@ -7941,8 +8652,8 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_path_mainfest_tool" >&5 +printf "%s\n" "$lt_cv_path_mainfest_tool" >&6; } if test yes != "$lt_cv_path_mainfest_tool"; then MANIFEST_TOOL=: fi @@ -7957,11 +8668,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_DSYMUTIL+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$DSYMUTIL"; then ac_cv_prog_DSYMUTIL="$DSYMUTIL" # Let the user override the test. else @@ -7969,11 +8681,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -7984,11 +8700,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $DSYMUTIL" >&5 +printf "%s\n" "$DSYMUTIL" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -7997,11 +8713,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_DSYMUTIL+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_DSYMUTIL"; then ac_cv_prog_ac_ct_DSYMUTIL="$ac_ct_DSYMUTIL" # Let the user override the test. else @@ -8009,11 +8726,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -8024,11 +8745,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DSYMUTIL" >&5 +printf "%s\n" "$ac_ct_DSYMUTIL" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi if test "x$ac_ct_DSYMUTIL" = x; then @@ -8036,8 +8757,8 @@ 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;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac DSYMUTIL=$ac_ct_DSYMUTIL @@ -8049,11 +8770,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_NMEDIT+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$NMEDIT"; then ac_cv_prog_NMEDIT="$NMEDIT" # Let the user override the test. else @@ -8061,11 +8783,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -8076,11 +8802,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $NMEDIT" >&5 +printf "%s\n" "$NMEDIT" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -8089,11 +8815,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_NMEDIT+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_NMEDIT"; then ac_cv_prog_ac_ct_NMEDIT="$ac_ct_NMEDIT" # Let the user override the test. else @@ -8101,11 +8828,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -8116,11 +8847,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_NMEDIT" >&5 +printf "%s\n" "$ac_ct_NMEDIT" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi if test "x$ac_ct_NMEDIT" = x; then @@ -8128,8 +8859,8 @@ 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;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac NMEDIT=$ac_ct_NMEDIT @@ -8141,11 +8872,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_LIPO+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$LIPO"; then ac_cv_prog_LIPO="$LIPO" # Let the user override the test. else @@ -8153,11 +8885,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -8168,11 +8904,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $LIPO" >&5 +printf "%s\n" "$LIPO" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -8181,11 +8917,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_LIPO+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_LIPO"; then ac_cv_prog_ac_ct_LIPO="$ac_ct_LIPO" # Let the user override the test. else @@ -8193,11 +8930,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -8208,11 +8949,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_LIPO" >&5 +printf "%s\n" "$ac_ct_LIPO" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi if test "x$ac_ct_LIPO" = x; then @@ -8220,8 +8961,8 @@ 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;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac LIPO=$ac_ct_LIPO @@ -8233,11 +8974,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_OTOOL+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$OTOOL"; then ac_cv_prog_OTOOL="$OTOOL" # Let the user override the test. else @@ -8245,11 +8987,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -8260,11 +9006,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $OTOOL" >&5 +printf "%s\n" "$OTOOL" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -8273,11 +9019,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_OTOOL+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_OTOOL"; then ac_cv_prog_ac_ct_OTOOL="$ac_ct_OTOOL" # Let the user override the test. else @@ -8285,11 +9032,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -8300,11 +9051,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OTOOL" >&5 +printf "%s\n" "$ac_ct_OTOOL" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi if test "x$ac_ct_OTOOL" = x; then @@ -8312,8 +9063,8 @@ 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;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac OTOOL=$ac_ct_OTOOL @@ -8325,11 +9076,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_OTOOL64+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$OTOOL64"; then ac_cv_prog_OTOOL64="$OTOOL64" # Let the user override the test. else @@ -8337,11 +9089,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -8352,11 +9108,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $OTOOL64" >&5 +printf "%s\n" "$OTOOL64" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -8365,11 +9121,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_OTOOL64+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_OTOOL64"; then ac_cv_prog_ac_ct_OTOOL64="$ac_ct_OTOOL64" # Let the user override the test. else @@ -8377,11 +9134,15 @@ for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -8392,11 +9153,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OTOOL64" >&5 +printf "%s\n" "$ac_ct_OTOOL64" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi if test "x$ac_ct_OTOOL64" = x; then @@ -8404,8 +9165,8 @@ 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;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac OTOOL64=$ac_ct_OTOOL64 @@ -8440,11 +9201,12 @@ - { $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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for -single_module linker flag" >&5 +printf %s "checking for -single_module linker flag... " >&6; } +if test ${lt_cv_apple_cc_single_mod+y} +then : + printf %s "(cached) " >&6 +else $as_nop 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 @@ -8473,14 +9235,15 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_apple_cc_single_mod" >&5 +printf "%s\n" "$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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for -exported_symbols_list linker flag" >&5 +printf %s "checking for -exported_symbols_list linker flag... " >&6; } +if test ${lt_cv_ld_exported_symbols_list+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_ld_exported_symbols_list=no save_LDFLAGS=$LDFLAGS echo "_main" > conftest.sym @@ -8489,31 +9252,33 @@ /* end confdefs.h. */ int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : lt_cv_ld_exported_symbols_list=yes -else +else $as_nop lt_cv_ld_exported_symbols_list=no fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_exported_symbols_list" >&5 +printf "%s\n" "$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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for -force_load linker flag" >&5 +printf %s "checking for -force_load linker flag... " >&6; } +if test ${lt_cv_ld_force_load+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_ld_force_load=no cat > conftest.c << _LT_EOF int forced_loaded() { return 2;} @@ -8541,8 +9306,8 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_force_load" >&5 +printf "%s\n" "$lt_cv_ld_force_load" >&6; } case $host_os in rhapsody* | darwin1.[012]) _lt_dar_allow_undefined='$wl-undefined ${wl}suppress' ;; @@ -8613,286 +9378,43 @@ esac } -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 +ac_header= ac_cache= +for ac_item in $ac_header_c_list 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 - + if test $ac_cache; then + ac_fn_c_check_header_compile "$LINENO" $ac_header ac_cv_header_$ac_cache "$ac_includes_default" + if eval test \"x\$ac_cv_header_$ac_cache\" = xyes; then + printf "%s\n" "#define $ac_item 1" >> confdefs.h + fi + ac_header= ac_cache= + elif test $ac_header; then + ac_cache=$ac_item + else + ac_header=$ac_item + fi 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 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 +if test $ac_cv_header_stdlib_h = yes && test $ac_cv_header_string_h = yes +then : -# 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 +printf "%s\n" "#define STDC_HEADERS 1" >>confdefs.h 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 +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 +if test "x$ac_cv_header_dlfcn_h" = xyes +then : + printf "%s\n" "#define HAVE_DLFCN_H 1" >>confdefs.h fi -done - @@ -8911,7 +9433,8 @@ # Check whether --with-pic was given. -if test "${with_pic+set}" = set; then : +if test ${with_pic+y} +then : withval=$with_pic; lt_p=${PACKAGE-default} case $withval in yes|no) pic_mode=$withval ;; @@ -8928,7 +9451,7 @@ IFS=$lt_save_ifs ;; esac -else +else $as_nop pic_mode=default fi @@ -8940,7 +9463,8 @@ # Check whether --enable-fast-install was given. -if test "${enable_fast_install+set}" = set; then : +if test ${enable_fast_install+y} +then : enableval=$enable_fast_install; p=${PACKAGE-default} case $enableval in yes) enable_fast_install=yes ;; @@ -8958,7 +9482,7 @@ IFS=$lt_save_ifs ;; esac -else +else $as_nop enable_fast_install=yes fi @@ -8972,11 +9496,12 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking which variant of shared library versioning to provide" >&5 +printf %s "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 : +if test ${with_aix_soname+y} +then : withval=$with_aix_soname; case $withval in aix|svr4|both) ;; @@ -8985,18 +9510,19 @@ ;; esac lt_cv_with_aix_soname=$with_aix_soname -else - if ${lt_cv_with_aix_soname+:} false; then : - $as_echo_n "(cached) " >&6 -else +else $as_nop + if test ${lt_cv_with_aix_soname+y} +then : + printf %s "(cached) " >&6 +else $as_nop 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $with_aix_soname" >&5 +printf "%s\n" "$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', @@ -9078,11 +9604,12 @@ 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for objdir" >&5 +printf %s "checking for objdir... " >&6; } +if test ${lt_cv_objdir+y} +then : + printf %s "(cached) " >&6 +else $as_nop rm -f .libs 2>/dev/null mkdir .libs 2>/dev/null if test -d .libs; then @@ -9093,17 +9620,15 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_objdir" >&5 +printf "%s\n" "$lt_cv_objdir" >&6; } objdir=$lt_cv_objdir -cat >>confdefs.h <<_ACEOF -#define LT_OBJDIR "$lt_cv_objdir/" -_ACEOF +printf "%s\n" "#define LT_OBJDIR \"$lt_cv_objdir/\"" >>confdefs.h @@ -9149,11 +9674,12 @@ 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for ${ac_tool_prefix}file" >&5 +printf %s "checking for ${ac_tool_prefix}file... " >&6; } +if test ${lt_cv_path_MAGIC_CMD+y} +then : + printf %s "(cached) " >&6 +else $as_nop case $MAGIC_CMD in [\\/*] | ?:[\\/]*) lt_cv_path_MAGIC_CMD=$MAGIC_CMD # Let the user override the test with a path. @@ -9202,11 +9728,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $MAGIC_CMD" >&5 +printf "%s\n" "$MAGIC_CMD" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -9215,11 +9741,12 @@ 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for file" >&5 +printf %s "checking for file... " >&6; } +if test ${lt_cv_path_MAGIC_CMD+y} +then : + printf %s "(cached) " >&6 +else $as_nop case $MAGIC_CMD in [\\/*] | ?:[\\/]*) lt_cv_path_MAGIC_CMD=$MAGIC_CMD # Let the user override the test with a path. @@ -9268,11 +9795,11 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $MAGIC_CMD" >&5 +printf "%s\n" "$MAGIC_CMD" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -9357,11 +9884,12 @@ 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -fno-rtti -fno-exceptions" >&5 +printf %s "checking if $compiler supports -fno-rtti -fno-exceptions... " >&6; } +if test ${lt_cv_prog_compiler_rtti_exceptions+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_prog_compiler_rtti_exceptions=no ac_outfile=conftest.$ac_objext echo "$lt_simple_compile_test_code" > conftest.$ac_ext @@ -9392,8 +9920,8 @@ $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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_rtti_exceptions" >&5 +printf "%s\n" "$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" @@ -9750,26 +10278,28 @@ ;; 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $compiler option to produce PIC" >&5 +printf %s "checking for $compiler option to produce PIC... " >&6; } +if test ${lt_cv_prog_compiler_pic+y} +then : + printf %s "(cached) " >&6 +else $as_nop 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic" >&5 +printf "%s\n" "$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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $compiler PIC flag $lt_prog_compiler_pic works" >&5 +printf %s "checking if $compiler PIC flag $lt_prog_compiler_pic works... " >&6; } +if test ${lt_cv_prog_compiler_pic_works+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_prog_compiler_pic_works=no ac_outfile=conftest.$ac_objext echo "$lt_simple_compile_test_code" > conftest.$ac_ext @@ -9800,8 +10330,8 @@ $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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic_works" >&5 +printf "%s\n" "$lt_cv_prog_compiler_pic_works" >&6; } if test yes = "$lt_cv_prog_compiler_pic_works"; then case $lt_prog_compiler_pic in @@ -9829,11 +10359,12 @@ # 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $compiler static flag $lt_tmp_static_flag works" >&5 +printf %s "checking if $compiler static flag $lt_tmp_static_flag works... " >&6; } +if test ${lt_cv_prog_compiler_static_works+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_prog_compiler_static_works=no save_LDFLAGS=$LDFLAGS LDFLAGS="$LDFLAGS $lt_tmp_static_flag" @@ -9857,8 +10388,8 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_static_works" >&5 +printf "%s\n" "$lt_cv_prog_compiler_static_works" >&6; } if test yes = "$lt_cv_prog_compiler_static_works"; then : @@ -9872,11 +10403,12 @@ - { $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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 +printf %s "checking if $compiler supports -c -o file.$ac_objext... " >&6; } +if test ${lt_cv_prog_compiler_c_o+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_prog_compiler_c_o=no $RM -r conftest 2>/dev/null mkdir conftest @@ -9919,19 +10451,20 @@ $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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o" >&5 +printf "%s\n" "$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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 +printf %s "checking if $compiler supports -c -o file.$ac_objext... " >&6; } +if test ${lt_cv_prog_compiler_c_o+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_prog_compiler_c_o=no $RM -r conftest 2>/dev/null mkdir conftest @@ -9974,8 +10507,8 @@ $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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o" >&5 +printf "%s\n" "$lt_cv_prog_compiler_c_o" >&6; } @@ -9983,19 +10516,19 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if we can lock with hard links" >&5 +printf %s "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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $hard_links" >&5 +printf "%s\n" "$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;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: '$CC' does not support '-c -o', so 'make -j' may be unsafe" >&5 +printf "%s\n" "$as_me: WARNING: '$CC' does not support '-c -o', so 'make -j' may be unsafe" >&2;} need_locks=warn fi else @@ -10007,8 +10540,8 @@ - { $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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the $compiler linker ($LD) supports shared libraries" >&5 +printf %s "checking whether the $compiler linker ($LD) supports shared libraries... " >&6; } runpath_var= allow_undefined_flag= @@ -10563,21 +11096,23 @@ 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 + if test ${lt_cv_aix_libpath_+y} +then : + printf %s "(cached) " >&6 +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : lt_aix_libpath_sed=' /Import File Strings/,/^$/ { @@ -10592,7 +11127,7 @@ 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 \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext if test -z "$lt_cv_aix_libpath_"; then lt_cv_aix_libpath_=/usr/lib:/lib @@ -10616,21 +11151,23 @@ 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 + if test ${lt_cv_aix_libpath_+y} +then : + printf %s "(cached) " >&6 +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : lt_aix_libpath_sed=' /Import File Strings/,/^$/ { @@ -10645,7 +11182,7 @@ 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 \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext if test -z "$lt_cv_aix_libpath_"; then lt_cv_aix_libpath_=/usr/lib:/lib @@ -10896,11 +11433,12 @@ # 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $CC understands -b" >&5 +printf %s "checking if $CC understands -b... " >&6; } +if test ${lt_cv_prog_compiler__b+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_prog_compiler__b=no save_LDFLAGS=$LDFLAGS LDFLAGS="$LDFLAGS -b" @@ -10924,8 +11462,8 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler__b" >&5 +printf "%s\n" "$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' @@ -10965,28 +11503,30 @@ # 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the $host_os linker accepts -exported_symbol" >&5 +printf %s "checking whether the $host_os linker accepts -exported_symbol... " >&6; } +if test ${lt_cv_irix_exported_symbol+y} +then : + printf %s "(cached) " >&6 +else $as_nop 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 : +if ac_fn_c_try_link "$LINENO" +then : lt_cv_irix_exported_symbol=yes -else +else $as_nop lt_cv_irix_exported_symbol=no fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_irix_exported_symbol" >&5 +printf "%s\n" "$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 @@ -11266,8 +11806,8 @@ fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ld_shlibs" >&5 -$as_echo "$ld_shlibs" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ld_shlibs" >&5 +printf "%s\n" "$ld_shlibs" >&6; } test no = "$ld_shlibs" && can_build_shared=no with_gnu_ld=$with_gnu_ld @@ -11303,18 +11843,19 @@ # 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether -lc should be explicitly linked in" >&5 +printf %s "checking whether -lc should be explicitly linked in... " >&6; } +if test ${lt_cv_archive_cmds_need_lc+y} +then : + printf %s "(cached) " >&6 +else $as_nop $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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } 2>conftest.err; then soname=conftest lib=conftest @@ -11332,7 +11873,7 @@ 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } then lt_cv_archive_cmds_need_lc=no @@ -11346,8 +11887,8 @@ $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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_archive_cmds_need_lc" >&5 +printf "%s\n" "$lt_cv_archive_cmds_need_lc" >&6; } archive_cmds_need_lc=$lt_cv_archive_cmds_need_lc ;; esac @@ -11506,8 +12047,8 @@ - { $as_echo "$as_me:${as_lineno-$LINENO}: checking dynamic linker characteristics" >&5 -$as_echo_n "checking dynamic linker characteristics... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking dynamic linker characteristics" >&5 +printf %s "checking dynamic linker characteristics... " >&6; } if test yes = "$GCC"; then case $host_os in @@ -12068,9 +12609,10 @@ 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 + if test ${lt_cv_shlibpath_overrides_runpath+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_shlibpath_overrides_runpath=no save_LDFLAGS=$LDFLAGS save_libdir=$libdir @@ -12080,19 +12622,21 @@ /* end confdefs.h. */ int -main () +main (void) { ; 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 : +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 \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext LDFLAGS=$save_LDFLAGS libdir=$save_libdir @@ -12324,8 +12868,8 @@ dynamic_linker=no ;; esac -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $dynamic_linker" >&5 -$as_echo "$dynamic_linker" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $dynamic_linker" >&5 +printf "%s\n" "$dynamic_linker" >&6; } test no = "$dynamic_linker" && can_build_shared=no variables_saved_for_relink="PATH $shlibpath_var $runpath_var" @@ -12446,8 +12990,8 @@ - { $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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to hardcode library paths into programs" >&5 +printf %s "checking how to hardcode library paths into programs... " >&6; } hardcode_action= if test -n "$hardcode_libdir_flag_spec" || test -n "$runpath_var" || @@ -12471,8 +13015,8 @@ # directories. hardcode_action=unsupported fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $hardcode_action" >&5 -$as_echo "$hardcode_action" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $hardcode_action" >&5 +printf "%s\n" "$hardcode_action" >&6; } if test relink = "$hardcode_action" || test yes = "$inherit_rpath"; then @@ -12516,11 +13060,12 @@ 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5 +printf %s "checking for dlopen in -ldl... " >&6; } +if test ${ac_cv_lib_dl_dlopen+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_check_lib_save_LIBS=$LIBS LIBS="-ldl $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -12529,32 +13074,31 @@ /* 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 () +main (void) { return dlopen (); ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : ac_cv_lib_dl_dlopen=yes -else +else $as_nop ac_cv_lib_dl_dlopen=no fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ 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 : +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5 +printf "%s\n" "$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 +else $as_nop lt_cv_dlopen=dyld lt_cv_dlopen_libs= @@ -12574,14 +13118,16 @@ *) ac_fn_c_check_func "$LINENO" "shl_load" "ac_cv_func_shl_load" -if test "x$ac_cv_func_shl_load" = xyes; then : +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 +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for shl_load in -ldld" >&5 +printf %s "checking for shl_load in -ldld... " >&6; } +if test ${ac_cv_lib_dld_shl_load+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_check_lib_save_LIBS=$LIBS LIBS="-ldld $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -12590,41 +13136,42 @@ /* 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 () +main (void) { return shl_load (); ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : ac_cv_lib_dld_shl_load=yes -else +else $as_nop ac_cv_lib_dld_shl_load=no fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ 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 : +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_shl_load" >&5 +printf "%s\n" "$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 +else $as_nop ac_fn_c_check_func "$LINENO" "dlopen" "ac_cv_func_dlopen" -if test "x$ac_cv_func_dlopen" = xyes; then : +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 +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5 +printf %s "checking for dlopen in -ldl... " >&6; } +if test ${ac_cv_lib_dl_dlopen+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_check_lib_save_LIBS=$LIBS LIBS="-ldl $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -12633,37 +13180,37 @@ /* 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 () +main (void) { return dlopen (); ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : ac_cv_lib_dl_dlopen=yes -else +else $as_nop ac_cv_lib_dl_dlopen=no fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ 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 : +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5 +printf "%s\n" "$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 +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for dlopen in -lsvld" >&5 +printf %s "checking for dlopen in -lsvld... " >&6; } +if test ${ac_cv_lib_svld_dlopen+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_check_lib_save_LIBS=$LIBS LIBS="-lsvld $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -12672,37 +13219,37 @@ /* 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 () +main (void) { return dlopen (); ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : ac_cv_lib_svld_dlopen=yes -else +else $as_nop ac_cv_lib_svld_dlopen=no fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ 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 : +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_svld_dlopen" >&5 +printf "%s\n" "$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 +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for dld_link in -ldld" >&5 +printf %s "checking for dld_link in -ldld... " >&6; } +if test ${ac_cv_lib_dld_dld_link+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_check_lib_save_LIBS=$LIBS LIBS="-ldld $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -12711,30 +13258,29 @@ /* 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 () +main (void) { return dld_link (); ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : ac_cv_lib_dld_dld_link=yes -else +else $as_nop ac_cv_lib_dld_dld_link=no fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ 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 : +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_dld_link" >&5 +printf "%s\n" "$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 @@ -12773,11 +13319,12 @@ 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether a program can dlopen itself" >&5 +printf %s "checking whether a program can dlopen itself... " >&6; } +if test ${lt_cv_dlopen_self+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test yes = "$cross_compiling"; then : lt_cv_dlopen_self=cross else @@ -12856,7 +13403,7 @@ 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 + printf "%s\n" "$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=$? @@ -12874,16 +13421,17 @@ fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_dlopen_self" >&5 -$as_echo "$lt_cv_dlopen_self" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_dlopen_self" >&5 +printf "%s\n" "$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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether a statically linked program can dlopen itself" >&5 +printf %s "checking whether a statically linked program can dlopen itself... " >&6; } +if test ${lt_cv_dlopen_self_static+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test yes = "$cross_compiling"; then : lt_cv_dlopen_self_static=cross else @@ -12962,7 +13510,7 @@ 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 + printf "%s\n" "$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=$? @@ -12980,8 +13528,8 @@ fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_dlopen_self_static" >&5 -$as_echo "$lt_cv_dlopen_self_static" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_dlopen_self_static" >&5 +printf "%s\n" "$lt_cv_dlopen_self_static" >&6; } fi CPPFLAGS=$save_CPPFLAGS @@ -13019,13 +13567,13 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether stripping libraries is possible" >&5 +printf %s "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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } else # FIXME - insert some real tests, host_os isn't really good enough case $host_os in @@ -13033,16 +13581,16 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi ;; *) - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } ;; esac fi @@ -13059,13 +13607,13 @@ # 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if libtool supports shared libraries" >&5 +printf %s "checking if libtool supports shared libraries... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $can_build_shared" >&5 +printf "%s\n" "$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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether to build shared libraries" >&5 +printf %s "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 @@ -13089,15 +13637,15 @@ fi ;; esac - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_shared" >&5 -$as_echo "$enable_shared" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $enable_shared" >&5 +printf "%s\n" "$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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether to build static libraries" >&5 +printf %s "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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $enable_static" >&5 +printf "%s\n" "$enable_static" >&6; } @@ -13137,9 +13685,10 @@ # Check whether --enable-threads was given. -if test "${enable_threads+set}" = set; then : +if test ${enable_threads+y} +then : enableval=$enable_threads; cext_enable_threads=$enableval -else +else $as_nop cext_enable_threads=yes fi @@ -13155,11 +13704,12 @@ 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -pthread" >&5 +printf %s "checking whether $CC supports -pthread... " >&6; } +if eval test \${eso_cv_prog_cc_$flag+y} +then : + printf %s "(cached) " >&6 +else $as_nop eval "eso_cv_prog_cc_$flag=no" ac_ext=c @@ -13190,8 +13740,8 @@ 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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } if eval "test \"`echo '$eso_cv_prog_cc_'$flag`\" = yes"; then : @@ -13202,11 +13752,12 @@ fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_create in -lpthread" >&5 -$as_echo_n "checking for pthread_create in -lpthread... " >&6; } -if ${ac_cv_lib_pthread_pthread_create+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for pthread_create in -lpthread" >&5 +printf %s "checking for pthread_create in -lpthread... " >&6; } +if test ${ac_cv_lib_pthread_pthread_create+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_check_lib_save_LIBS=$LIBS LIBS="-lpthread $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -13215,45 +13766,44 @@ /* 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 pthread_create (); int -main () +main (void) { return pthread_create (); ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : ac_cv_lib_pthread_pthread_create=yes -else +else $as_nop ac_cv_lib_pthread_pthread_create=no fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_pthread_pthread_create" >&5 -$as_echo "$ac_cv_lib_pthread_pthread_create" >&6; } -if test "x$ac_cv_lib_pthread_pthread_create" = xyes; then : +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_pthread_pthread_create" >&5 +printf "%s\n" "$ac_cv_lib_pthread_pthread_create" >&6; } +if test "x$ac_cv_lib_pthread_pthread_create" = xyes +then : eso_threads_have_libpthread=yes -else +else $as_nop eso_threads_have_libpthread=no fi - ac_fn_c_check_header_mongrel "$LINENO" "pthread.h" "ac_cv_header_pthread_h" "$ac_includes_default" -if test "x$ac_cv_header_pthread_h" = xyes; then : + ac_fn_c_check_header_compile "$LINENO" "pthread.h" "ac_cv_header_pthread_h" "$ac_includes_default" +if test "x$ac_cv_header_pthread_h" = xyes +then : eso_threads_have_pthread_h=yes -else +else $as_nop eso_threads_have_pthread_h=no fi - if test x"$eso_threads_have_pthread_h" != xyes; then eso_threads_posix=no else @@ -13270,7 +13820,7 @@ if test x"$eso_threads_have_pthread_h" = xyes; then -$as_echo "#define HAVE_PTHREAD_H 1" >>confdefs.h +printf "%s\n" "#define HAVE_PTHREAD_H 1" >>confdefs.h fi @@ -13290,27 +13840,31 @@ fi - if ${eso_cv_threads_posix_header+:} false; then : - $as_echo_n "(cached) " >&6 -else + if test ${eso_cv_threads_posix_header+y} +then : + printf %s "(cached) " >&6 +else $as_nop eso_cv_threads_posix_header=$eso_threads_have_pthread_h fi - if ${eso_cv_threads_posix_lib+:} false; then : - $as_echo_n "(cached) " >&6 -else + if test ${eso_cv_threads_posix_lib+y} +then : + printf %s "(cached) " >&6 +else $as_nop eso_cv_threads_posix_lib=$eso_threads_have_libpthread fi - if ${eso_cv_threads_posix_flags+:} false; then : - $as_echo_n "(cached) " >&6 -else + if test ${eso_cv_threads_posix_flags+y} +then : + printf %s "(cached) " >&6 +else $as_nop eso_cv_threads_posix_flags=$eso_cv_prog_cc_pthread fi - if ${eso_cv_threads_posix+:} false; then : - $as_echo_n "(cached) " >&6 -else + if test ${eso_cv_threads_posix+y} +then : + printf %s "(cached) " >&6 +else $as_nop eso_cv_threads_posix=$eso_threads_posix fi @@ -13320,18 +13874,16 @@ - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether POSIX threads are available" >&5 -$as_echo_n "checking whether POSIX threads are available... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether POSIX threads are available" >&5 +printf %s "checking whether POSIX threads are available... " >&6; } if test x"$eso_cv_threads_posix" = xno; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } else CFLAGS="$CFLAGS -D_REENTRANT" - cat >>confdefs.h <<_ACEOF -#define CX_THREADS_ENABLED 1 -_ACEOF + printf "%s\n" "#define CX_THREADS_ENABLED 1" >>confdefs.h if test x"$eso_cv_threads_posix_lib" = xyes; then @@ -13341,8 +13893,8 @@ LDFLAGS="$LDFLAGS $PTHREAD_CFLAGS" fi - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } fi fi @@ -13350,138 +13902,145 @@ # 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 +# Autoupdate added the next two lines to ensure that your configure +# script's behavior did not change. They are probably safe to remove. -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - $EGREP "memchr" >/dev/null 2>&1; then : +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5 +printf %s "checking for egrep... " >&6; } +if test ${ac_cv_path_EGREP+y} +then : + printf %s "(cached) " >&6 +else $as_nop + 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 + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + 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 + printf %s 0123456789 >"conftest.in" + while : + do + cat "conftest.in" "conftest.in" >"conftest.tmp" + mv "conftest.tmp" "conftest.in" + cp "conftest.in" "conftest.nl" + printf "%s\n" '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_header_stdc=no + ac_cv_path_EGREP=$EGREP fi -rm -f conftest* + fi fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5 +printf "%s\n" "$ac_cv_path_EGREP" >&6; } + EGREP="$ac_cv_path_EGREP" -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* +ac_fn_c_check_header_compile "$LINENO" "stddef.h" "ac_cv_header_stddef_h" "$ac_includes_default" +if test "x$ac_cv_header_stddef_h" = xyes +then : + printf "%s\n" "#define HAVE_STDDEF_H 1" >>confdefs.h fi +ac_fn_c_check_header_compile "$LINENO" "stdint.h" "ac_cv_header_stdint_h" "$ac_includes_default" +if test "x$ac_cv_header_stdint_h" = xyes +then : + printf "%s\n" "#define HAVE_STDINT_H 1" >>confdefs.h -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 +ac_fn_c_check_header_compile "$LINENO" "stdarg.h" "ac_cv_header_stdarg_h" "$ac_includes_default" +if test "x$ac_cv_header_stdarg_h" = xyes +then : + printf "%s\n" "#define HAVE_STDARG_H 1" >>confdefs.h + fi +ac_fn_c_check_header_compile "$LINENO" "inttypes.h" "ac_cv_header_inttypes_h" "$ac_includes_default" +if test "x$ac_cv_header_inttypes_h" = xyes +then : + printf "%s\n" "#define HAVE_INTTYPES_H 1" >>confdefs.h fi +ac_fn_c_check_header_compile "$LINENO" "float.h" "ac_cv_header_float_h" "$ac_includes_default" +if test "x$ac_cv_header_float_h" = xyes +then : + printf "%s\n" "#define HAVE_FLOAT_H 1" >>confdefs.h + 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 +ac_fn_c_check_header_compile "$LINENO" "limits.h" "ac_cv_header_limits_h" "$ac_includes_default" +if test "x$ac_cv_header_limits_h" = xyes +then : + printf "%s\n" "#define HAVE_LIMITS_H 1" >>confdefs.h fi +ac_fn_c_check_header_compile "$LINENO" "locale.h" "ac_cv_header_locale_h" "$ac_includes_default" +if test "x$ac_cv_header_locale_h" = xyes +then : + printf "%s\n" "#define HAVE_LOCALE_H 1" >>confdefs.h -for ac_header in stddef.h stdint.h stdarg.h inttypes.h \ - float.h limits.h locale.h values.h unistd.h -do : - as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -ac_fn_c_check_header_mongrel "$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 +ac_fn_c_check_header_compile "$LINENO" "values.h" "ac_cv_header_values_h" "$ac_includes_default" +if test "x$ac_cv_header_values_h" = xyes +then : + printf "%s\n" "#define HAVE_VALUES_H 1" >>confdefs.h fi +ac_fn_c_check_header_compile "$LINENO" "unistd.h" "ac_cv_header_unistd_h" "$ac_includes_default" +if test "x$ac_cv_header_unistd_h" = xyes +then : + printf "%s\n" "#define HAVE_UNISTD_H 1" >>confdefs.h -done +fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether stat file-mode macros are broken" >&5 -$as_echo_n "checking whether stat file-mode macros are broken... " >&6; } -if ${ac_cv_header_stat_broken+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether stat file-mode macros are broken" >&5 +printf %s "checking whether stat file-mode macros are broken... " >&6; } +if test ${ac_cv_header_stat_broken+y} +then : + printf %s "(cached) " >&6 +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include @@ -13504,34 +14063,36 @@ #endif _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : ac_cv_header_stat_broken=no -else +else $as_nop ac_cv_header_stat_broken=yes fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stat_broken" >&5 -$as_echo "$ac_cv_header_stat_broken" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stat_broken" >&5 +printf "%s\n" "$ac_cv_header_stat_broken" >&6; } if test $ac_cv_header_stat_broken = yes; then -$as_echo "#define STAT_MACROS_BROKEN 1" >>confdefs.h +printf "%s\n" "#define STAT_MACROS_BROKEN 1" >>confdefs.h fi # 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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for an ANSI C-conforming const" >&5 +printf %s "checking for an ANSI C-conforming const... " >&6; } +if test ${ac_cv_c_const+y} +then : + printf %s "(cached) " >&6 +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main () +main (void) { #ifndef __cplusplus @@ -13544,7 +14105,7 @@ /* 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. + /* IBM 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 */ @@ -13572,7 +14133,7 @@ iptr p = 0; ++p; } - { /* AIX XL C 1.02.0.0 rejects this sort of thing, saying + { /* IBM 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; @@ -13588,47 +14149,50 @@ return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : ac_cv_c_const=yes -else +else $as_nop ac_cv_c_const=no fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_const" >&5 -$as_echo "$ac_cv_c_const" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_const" >&5 +printf "%s\n" "$ac_cv_c_const" >&6; } if test $ac_cv_c_const = no; then -$as_echo "#define const /**/" >>confdefs.h +printf "%s\n" "#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 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for inline" >&5 +printf %s "checking for inline... " >&6; } +if test ${ac_cv_c_inline+y} +then : + printf %s "(cached) " >&6 +else $as_nop 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; } +static $ac_kw foo_t static_foo (void) {return 0; } +$ac_kw foo_t foo (void) {return 0; } #endif _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +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 +rm -f core conftest.err conftest.$ac_objext conftest.beam 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_inline" >&5 +printf "%s\n" "$ac_cv_c_inline" >&6; } case $ac_cv_c_inline in inline | yes) ;; @@ -13650,11 +14214,12 @@ - { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports __attribute__(( visibility(\"hidden\") ))" >&5 -$as_echo_n "checking if $CC supports __attribute__(( visibility(\"hidden\") ))... " >&6; } -if ${eso_cv_prog_cc_attribute_visibility_hidden+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $CC supports __attribute__(( visibility(\"hidden\") ))" >&5 +printf %s "checking if $CC supports __attribute__(( visibility(\"hidden\") ))... " >&6; } +if test ${eso_cv_prog_cc_attribute_visibility_hidden+y} +then : + printf %s "(cached) " >&6 +else $as_nop eso_save_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS" @@ -13663,17 +14228,18 @@ /* end confdefs.h. */ void __attribute__((visibility("hidden"))) hidden_function() { } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : eval "eso_cv_prog_cc_attribute_visibility_hidden='yes'" -else +else $as_nop eval "eso_cv_prog_cc_attribute_visibility_hidden='no'" fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext CFLAGS="$eso_save_CFLAGS" fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $eso_cv_prog_cc_attribute_visibility_hidden" >&5 -$as_echo "$eso_cv_prog_cc_attribute_visibility_hidden" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $eso_cv_prog_cc_attribute_visibility_hidden" >&5 +printf "%s\n" "$eso_cv_prog_cc_attribute_visibility_hidden" >&6; } if eval "test x\$eso_cv_prog_cc_attribute_visibility_hidden = xyes"; then : @@ -13690,14 +14256,15 @@ ac_fn_c_check_type "$LINENO" "long long int" "ac_cv_type_long_long_int" "$ac_includes_default" -if test "x$ac_cv_type_long_long_int" = xyes; then : +if test "x$ac_cv_type_long_long_int" = xyes +then : fi if test x"$ac_cv_type_long_long_int" = xyes; then -$as_echo "#define HAVE_LONG_LONG_INT 1" >>confdefs.h +printf "%s\n" "#define HAVE_LONG_LONG_INT 1" >>confdefs.h fi @@ -13705,14 +14272,15 @@ ac_fn_c_check_type "$LINENO" "unsigned long long int" "ac_cv_type_unsigned_long_long_int" "$ac_includes_default" -if test "x$ac_cv_type_unsigned_long_long_int" = xyes; then : +if test "x$ac_cv_type_unsigned_long_long_int" = xyes +then : fi if test x"$ac_cv_type_unsigned_long_long_int" = xyes; then -$as_echo "#define HAVE_UNSIGNED_LONG_LONG_INT 1" >>confdefs.h +printf "%s\n" "#define HAVE_UNSIGNED_LONG_LONG_INT 1" >>confdefs.h fi @@ -13721,21 +14289,20 @@ ac_fn_c_check_type "$LINENO" "intmax_t" "ac_cv_type_intmax_t" "$ac_includes_default" -if test "x$ac_cv_type_intmax_t" = xyes; then : +if test "x$ac_cv_type_intmax_t" = xyes +then : -$as_echo "#define HAVE_INTMAX_T 1" >>confdefs.h +printf "%s\n" "#define HAVE_INTMAX_T 1" >>confdefs.h -else +else $as_nop test $ac_cv_type_long_long_int = yes \ && ac_type='long long int' \ || ac_type='long int' -cat >>confdefs.h <<_ACEOF -#define intmax_t $ac_type -_ACEOF +printf "%s\n" "#define intmax_t $ac_type" >>confdefs.h fi @@ -13746,21 +14313,20 @@ ac_fn_c_check_type "$LINENO" "uintmax_t" "ac_cv_type_uintmax_t" "$ac_includes_default" -if test "x$ac_cv_type_uintmax_t" = xyes; then : +if test "x$ac_cv_type_uintmax_t" = xyes +then : -$as_echo "#define HAVE_UINTMAX_T 1" >>confdefs.h +printf "%s\n" "#define HAVE_UINTMAX_T 1" >>confdefs.h -else +else $as_nop test $ac_cv_type_long_long_int = yes \ && ac_type='unsigned long long int' \ || ac_type='unsigned long int' -cat >>confdefs.h <<_ACEOF -#define uintmax_t $ac_type -_ACEOF +printf "%s\n" "#define uintmax_t $ac_type" >>confdefs.h fi @@ -13769,13 +14335,14 @@ ac_fn_c_check_type "$LINENO" "uintptr_t" "ac_cv_type_uintptr_t" "$ac_includes_default" -if test "x$ac_cv_type_uintptr_t" = xyes; then : +if test "x$ac_cv_type_uintptr_t" = xyes +then : -$as_echo "#define HAVE_UINTPTR_T 1" >>confdefs.h +printf "%s\n" "#define HAVE_UINTPTR_T 1" >>confdefs.h -else +else $as_nop for ac_type in 'unsigned int' 'unsigned long int' \ 'unsigned long long int'; do @@ -13784,7 +14351,7 @@ $ac_includes_default int -main () +main (void) { static int test_array [1 - 2 * !(sizeof (void *) <= sizeof ($ac_type))]; test_array [0] = 0; @@ -13795,17 +14362,16 @@ } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : -cat >>confdefs.h <<_ACEOF -#define uintptr_t $ac_type -_ACEOF +printf "%s\n" "#define uintptr_t $ac_type" >>confdefs.h ac_type= fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext test -z "$ac_type" && break done @@ -13815,11 +14381,12 @@ - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for long double" >&5 -$as_echo_n "checking for long double... " >&6; } -if ${ac_cv_type_long_double+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for long double" >&5 +printf %s "checking for long double... " >&6; } +if test ${ac_cv_type_long_double+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test "$GCC" = yes; then ac_cv_type_long_double=yes @@ -13832,7 +14399,7 @@ long double foo = 0.0L; int -main () +main (void) { static int test_array [1 - 2 * !(/* On Ultrix 4.3 cc, long double is 4 and double is 8. */ sizeof (double) <= sizeof (long double))]; @@ -13843,33 +14410,33 @@ return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : ac_cv_type_long_double=yes -else +else $as_nop ac_cv_type_long_double=no fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_type_long_double" >&5 -$as_echo "$ac_cv_type_long_double" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_type_long_double" >&5 +printf "%s\n" "$ac_cv_type_long_double" >&6; } if test $ac_cv_type_long_double = yes; then -$as_echo "#define HAVE_LONG_DOUBLE 1" >>confdefs.h +printf "%s\n" "#define HAVE_LONG_DOUBLE 1" >>confdefs.h fi ac_fn_c_check_type "$LINENO" "size_t" "ac_cv_type_size_t" "$ac_includes_default" -if test "x$ac_cv_type_size_t" = xyes; then : +if test "x$ac_cv_type_size_t" = xyes +then : -else +else $as_nop -cat >>confdefs.h <<_ACEOF -#define size_t unsigned int -_ACEOF +printf "%s\n" "#define size_t unsigned int" >>confdefs.h fi @@ -13877,36 +14444,39 @@ if test x"$ac_cv_header_stdint_h" = xyes; then ac_fn_c_check_type "$LINENO" "int8_t" "ac_cv_type_int8_t" "#include " -if test "x$ac_cv_type_int8_t" = xyes; then : +if test "x$ac_cv_type_int8_t" = xyes +then : fi ac_fn_c_check_type "$LINENO" "int16_t" "ac_cv_type_int16_t" "#include " -if test "x$ac_cv_type_int16_t" = xyes; then : +if test "x$ac_cv_type_int16_t" = xyes +then : fi ac_fn_c_check_type "$LINENO" "int32_t" "ac_cv_type_int32_t" "#include " -if test "x$ac_cv_type_int32_t" = xyes; then : +if test "x$ac_cv_type_int32_t" = xyes +then : fi ac_fn_c_check_type "$LINENO" "int64_t" "ac_cv_type_int64_t" "#include " -if test "x$ac_cv_type_int64_t" = xyes; then : +if test "x$ac_cv_type_int64_t" = xyes +then : fi fi ac_fn_c_check_type "$LINENO" "ptrdiff_t" "ac_cv_type_ptrdiff_t" "$ac_includes_default" -if test "x$ac_cv_type_ptrdiff_t" = xyes; then : +if test "x$ac_cv_type_ptrdiff_t" = xyes +then : -cat >>confdefs.h <<_ACEOF -#define HAVE_PTRDIFF_T 1 -_ACEOF +printf "%s\n" "#define HAVE_PTRDIFF_T 1" >>confdefs.h fi @@ -13916,12 +14486,13 @@ cext_have_char_bit=no cext_have_char_8_bits=no - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for bits per char" >&5 -$as_echo_n "checking for bits per char... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for bits per char" >&5 +printf %s "checking for bits per char... " >&6; } - if ${cext_cv_have_char_8_bits+:} false; then : - $as_echo_n "(cached) " >&6 -else + if test ${cext_cv_have_char_8_bits+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_ext=c ac_cpp='$CPP $CPPFLAGS' @@ -13944,27 +14515,29 @@ /* end confdefs.h. */ #include int -main () +main (void) { int i = CHAR_BIT; ; return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : cext_have_char_bit=yes -else +else $as_nop cext_have_char_bit=no fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext if test "x$cext_have_char_bit" = "xyes"; then - if test "$cross_compiling" = yes; then : - { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} + if test "$cross_compiling" = yes +then : + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot run test program while cross compiling See \`config.log' for more details" "$LINENO" 5; } -else +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -13979,9 +14552,10 @@ } _ACEOF -if ac_fn_c_try_run "$LINENO"; then : +if ac_fn_c_try_run "$LINENO" +then : cext_have_char_8_bits=yes -else +else $as_nop cext_have_char_8_bits=no fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ @@ -13989,12 +14563,13 @@ fi else - if test "$cross_compiling" = yes; then : - { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} + if test "$cross_compiling" = yes +then : + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot run test program while cross compiling See \`config.log' for more details" "$LINENO" 5; } -else +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -14017,9 +14592,10 @@ } _ACEOF -if ac_fn_c_try_run "$LINENO"; then : +if ac_fn_c_try_run "$LINENO" +then : cext_have_char_8_bits=yes -else +else $as_nop cext_have_char_8_bits=no fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ @@ -14054,15 +14630,15 @@ else if test x"$cext_have_char_bit" = xno; then -$as_echo "#define CHAR_BIT 8" >>confdefs.h +printf "%s\n" "#define CHAR_BIT 8" >>confdefs.h else -$as_echo "#define HAVE_CHAR_BIT 1" >>confdefs.h +printf "%s\n" "#define HAVE_CHAR_BIT 1" >>confdefs.h fi - { $as_echo "$as_me:${as_lineno-$LINENO}: result: 8" >&5 -$as_echo "8" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: 8" >&5 +printf "%s\n" "8" >&6; } fi if test x$cext_have_char_8_bits != xyes; then @@ -14073,17 +14649,19 @@ # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. # This bug is HP SR number 8606223364. -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking size of char" >&5 -$as_echo_n "checking size of char... " >&6; } -if ${ac_cv_sizeof_char+:} false; then : - $as_echo_n "(cached) " >&6 -else - if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (char))" "ac_cv_sizeof_char" "$ac_includes_default"; then : +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking size of char" >&5 +printf %s "checking size of char... " >&6; } +if test ${ac_cv_sizeof_char+y} +then : + printf %s "(cached) " >&6 +else $as_nop + if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (char))" "ac_cv_sizeof_char" "$ac_includes_default" +then : -else +else $as_nop if test "$ac_cv_type_char" = yes; then - { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error 77 "cannot compute sizeof (char) See \`config.log' for more details" "$LINENO" 5; } else @@ -14092,31 +14670,31 @@ fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_char" >&5 -$as_echo "$ac_cv_sizeof_char" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_char" >&5 +printf "%s\n" "$ac_cv_sizeof_char" >&6; } -cat >>confdefs.h <<_ACEOF -#define SIZEOF_CHAR $ac_cv_sizeof_char -_ACEOF +printf "%s\n" "#define SIZEOF_CHAR $ac_cv_sizeof_char" >>confdefs.h # The cast to long int works around a bug in the HP C Compiler # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. # This bug is HP SR number 8606223364. -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking size of short" >&5 -$as_echo_n "checking size of short... " >&6; } -if ${ac_cv_sizeof_short+:} false; then : - $as_echo_n "(cached) " >&6 -else - if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (short))" "ac_cv_sizeof_short" "$ac_includes_default"; then : +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking size of short" >&5 +printf %s "checking size of short... " >&6; } +if test ${ac_cv_sizeof_short+y} +then : + printf %s "(cached) " >&6 +else $as_nop + if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (short))" "ac_cv_sizeof_short" "$ac_includes_default" +then : -else +else $as_nop if test "$ac_cv_type_short" = yes; then - { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error 77 "cannot compute sizeof (short) See \`config.log' for more details" "$LINENO" 5; } else @@ -14125,31 +14703,31 @@ fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_short" >&5 -$as_echo "$ac_cv_sizeof_short" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_short" >&5 +printf "%s\n" "$ac_cv_sizeof_short" >&6; } -cat >>confdefs.h <<_ACEOF -#define SIZEOF_SHORT $ac_cv_sizeof_short -_ACEOF +printf "%s\n" "#define SIZEOF_SHORT $ac_cv_sizeof_short" >>confdefs.h # The cast to long int works around a bug in the HP C Compiler # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. # This bug is HP SR number 8606223364. -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking size of int" >&5 -$as_echo_n "checking size of int... " >&6; } -if ${ac_cv_sizeof_int+:} false; then : - $as_echo_n "(cached) " >&6 -else - if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (int))" "ac_cv_sizeof_int" "$ac_includes_default"; then : +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking size of int" >&5 +printf %s "checking size of int... " >&6; } +if test ${ac_cv_sizeof_int+y} +then : + printf %s "(cached) " >&6 +else $as_nop + if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (int))" "ac_cv_sizeof_int" "$ac_includes_default" +then : -else +else $as_nop if test "$ac_cv_type_int" = yes; then - { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error 77 "cannot compute sizeof (int) See \`config.log' for more details" "$LINENO" 5; } else @@ -14158,31 +14736,31 @@ fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_int" >&5 -$as_echo "$ac_cv_sizeof_int" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_int" >&5 +printf "%s\n" "$ac_cv_sizeof_int" >&6; } -cat >>confdefs.h <<_ACEOF -#define SIZEOF_INT $ac_cv_sizeof_int -_ACEOF +printf "%s\n" "#define SIZEOF_INT $ac_cv_sizeof_int" >>confdefs.h # The cast to long int works around a bug in the HP C Compiler # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. # This bug is HP SR number 8606223364. -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking size of long" >&5 -$as_echo_n "checking size of long... " >&6; } -if ${ac_cv_sizeof_long+:} false; then : - $as_echo_n "(cached) " >&6 -else - if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (long))" "ac_cv_sizeof_long" "$ac_includes_default"; then : +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking size of long" >&5 +printf %s "checking size of long... " >&6; } +if test ${ac_cv_sizeof_long+y} +then : + printf %s "(cached) " >&6 +else $as_nop + if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (long))" "ac_cv_sizeof_long" "$ac_includes_default" +then : -else +else $as_nop if test "$ac_cv_type_long" = yes; then - { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error 77 "cannot compute sizeof (long) See \`config.log' for more details" "$LINENO" 5; } else @@ -14191,31 +14769,31 @@ fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_long" >&5 -$as_echo "$ac_cv_sizeof_long" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_long" >&5 +printf "%s\n" "$ac_cv_sizeof_long" >&6; } -cat >>confdefs.h <<_ACEOF -#define SIZEOF_LONG $ac_cv_sizeof_long -_ACEOF +printf "%s\n" "#define SIZEOF_LONG $ac_cv_sizeof_long" >>confdefs.h # The cast to long int works around a bug in the HP C Compiler # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. # This bug is HP SR number 8606223364. -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking size of long long" >&5 -$as_echo_n "checking size of long long... " >&6; } -if ${ac_cv_sizeof_long_long+:} false; then : - $as_echo_n "(cached) " >&6 -else - if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (long long))" "ac_cv_sizeof_long_long" "$ac_includes_default"; then : +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking size of long long" >&5 +printf %s "checking size of long long... " >&6; } +if test ${ac_cv_sizeof_long_long+y} +then : + printf %s "(cached) " >&6 +else $as_nop + if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (long long))" "ac_cv_sizeof_long_long" "$ac_includes_default" +then : -else +else $as_nop if test "$ac_cv_type_long_long" = yes; then - { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error 77 "cannot compute sizeof (long long) See \`config.log' for more details" "$LINENO" 5; } else @@ -14224,31 +14802,31 @@ fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_long_long" >&5 -$as_echo "$ac_cv_sizeof_long_long" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_long_long" >&5 +printf "%s\n" "$ac_cv_sizeof_long_long" >&6; } -cat >>confdefs.h <<_ACEOF -#define SIZEOF_LONG_LONG $ac_cv_sizeof_long_long -_ACEOF +printf "%s\n" "#define SIZEOF_LONG_LONG $ac_cv_sizeof_long_long" >>confdefs.h # The cast to long int works around a bug in the HP C Compiler # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. # This bug is HP SR number 8606223364. -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking size of size_t" >&5 -$as_echo_n "checking size of size_t... " >&6; } -if ${ac_cv_sizeof_size_t+:} false; then : - $as_echo_n "(cached) " >&6 -else - if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (size_t))" "ac_cv_sizeof_size_t" "$ac_includes_default"; then : +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking size of size_t" >&5 +printf %s "checking size of size_t... " >&6; } +if test ${ac_cv_sizeof_size_t+y} +then : + printf %s "(cached) " >&6 +else $as_nop + if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (size_t))" "ac_cv_sizeof_size_t" "$ac_includes_default" +then : -else +else $as_nop if test "$ac_cv_type_size_t" = yes; then - { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error 77 "cannot compute sizeof (size_t) See \`config.log' for more details" "$LINENO" 5; } else @@ -14257,31 +14835,31 @@ fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_size_t" >&5 -$as_echo "$ac_cv_sizeof_size_t" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_size_t" >&5 +printf "%s\n" "$ac_cv_sizeof_size_t" >&6; } -cat >>confdefs.h <<_ACEOF -#define SIZEOF_SIZE_T $ac_cv_sizeof_size_t -_ACEOF +printf "%s\n" "#define SIZEOF_SIZE_T $ac_cv_sizeof_size_t" >>confdefs.h # The cast to long int works around a bug in the HP C Compiler # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. # This bug is HP SR number 8606223364. -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking size of void *" >&5 -$as_echo_n "checking size of void *... " >&6; } -if ${ac_cv_sizeof_void_p+:} false; then : - $as_echo_n "(cached) " >&6 -else - if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (void *))" "ac_cv_sizeof_void_p" "$ac_includes_default"; then : +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking size of void *" >&5 +printf %s "checking size of void *... " >&6; } +if test ${ac_cv_sizeof_void_p+y} +then : + printf %s "(cached) " >&6 +else $as_nop + if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (void *))" "ac_cv_sizeof_void_p" "$ac_includes_default" +then : -else +else $as_nop if test "$ac_cv_type_void_p" = yes; then - { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error 77 "cannot compute sizeof (void *) See \`config.log' for more details" "$LINENO" 5; } else @@ -14290,14 +14868,12 @@ fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_void_p" >&5 -$as_echo "$ac_cv_sizeof_void_p" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_void_p" >&5 +printf "%s\n" "$ac_cv_sizeof_void_p" >&6; } -cat >>confdefs.h <<_ACEOF -#define SIZEOF_VOID_P $ac_cv_sizeof_void_p -_ACEOF +printf "%s\n" "#define SIZEOF_VOID_P $ac_cv_sizeof_void_p" >>confdefs.h @@ -14306,8 +14882,8 @@ fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for an integer type with the same size as size_t" >&5 -$as_echo_n "checking for an integer type with the same size as size_t... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for an integer type with the same size as size_t" >&5 +printf %s "checking for an integer type with the same size as size_t... " >&6; } case $ac_cv_sizeof_size_t in $ac_cv_sizeof_short) @@ -14327,12 +14903,13 @@ ;; esac - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $cext_size_type" >&5 -$as_echo "$cext_size_type" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $cext_size_type" >&5 +printf "%s\n" "$cext_size_type" >&6; } - if ${cext_cv_type_size_type+:} false; then : - $as_echo_n "(cached) " >&6 -else + if test ${cext_cv_type_size_type+y} +then : + printf %s "(cached) " >&6 +else $as_nop cext_cv_type_size_type=$cext_size_type @@ -14343,38 +14920,38 @@ ac_fn_c_check_member "$LINENO" "struct lconv" "decimal_point" "ac_cv_member_struct_lconv_decimal_point" "#include " -if test "x$ac_cv_member_struct_lconv_decimal_point" = xyes; then : +if test "x$ac_cv_member_struct_lconv_decimal_point" = xyes +then : -cat >>confdefs.h <<_ACEOF -#define HAVE_STRUCT_LCONV_DECIMAL_POINT 1 -_ACEOF +printf "%s\n" "#define HAVE_STRUCT_LCONV_DECIMAL_POINT 1" >>confdefs.h fi ac_fn_c_check_member "$LINENO" "struct lconv" "thousands_sep" "ac_cv_member_struct_lconv_thousands_sep" "#include " -if test "x$ac_cv_member_struct_lconv_thousands_sep" = xyes; then : +if test "x$ac_cv_member_struct_lconv_thousands_sep" = xyes +then : -cat >>confdefs.h <<_ACEOF -#define HAVE_STRUCT_LCONV_THOUSANDS_SEP 1 -_ACEOF +printf "%s\n" "#define HAVE_STRUCT_LCONV_THOUSANDS_SEP 1" >>confdefs.h fi # Check whether --enable-largefile was given. -if test "${enable_largefile+set}" = set; then : +if test ${enable_largefile+y} +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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for special C compiler options needed for large files" >&5 +printf %s "checking for special C compiler options needed for large files... " >&6; } +if test ${ac_cv_sys_largefile_CC+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_cv_sys_largefile_CC=no if test "$GCC" != yes; then ac_save_CC=$CC @@ -14388,44 +14965,47 @@ 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)) +#define LARGE_OFF_T (((off_t) 1 << 31 << 31) - 1 + ((off_t) 1 << 31 << 31)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; int -main () +main (void) { ; return 0; } _ACEOF - if ac_fn_c_try_compile "$LINENO"; then : + if ac_fn_c_try_compile "$LINENO" +then : break fi -rm -f core conftest.err conftest.$ac_objext +rm -f core conftest.err conftest.$ac_objext conftest.beam CC="$CC -n32" - if ac_fn_c_try_compile "$LINENO"; then : + if ac_fn_c_try_compile "$LINENO" +then : ac_cv_sys_largefile_CC=' -n32'; break fi -rm -f core conftest.err conftest.$ac_objext +rm -f core conftest.err conftest.$ac_objext conftest.beam 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sys_largefile_CC" >&5 +printf "%s\n" "$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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for _FILE_OFFSET_BITS value needed for large files" >&5 +printf %s "checking for _FILE_OFFSET_BITS value needed for large files... " >&6; } +if test ${ac_cv_sys_file_offset_bits+y} +then : + printf %s "(cached) " >&6 +else $as_nop while :; do cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -14434,22 +15014,23 @@ 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)) +#define LARGE_OFF_T (((off_t) 1 << 31 << 31) - 1 + ((off_t) 1 << 31 << 31)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +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 +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #define _FILE_OFFSET_BITS 64 @@ -14458,43 +15039,43 @@ 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)) +#define LARGE_OFF_T (((off_t) 1 << 31 << 31) - 1 + ((off_t) 1 << 31 << 31)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +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 +rm -f core conftest.err conftest.$ac_objext conftest.beam 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sys_file_offset_bits" >&5 +printf "%s\n" "$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 +printf "%s\n" "#define _FILE_OFFSET_BITS $ac_cv_sys_file_offset_bits" >>confdefs.h ;; 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 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for _LARGE_FILES value needed for large files" >&5 +printf %s "checking for _LARGE_FILES value needed for large files... " >&6; } +if test ${ac_cv_sys_large_files+y} +then : + printf %s "(cached) " >&6 +else $as_nop while :; do cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -14503,22 +15084,23 @@ 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)) +#define LARGE_OFF_T (((off_t) 1 << 31 << 31) - 1 + ((off_t) 1 << 31 << 31)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +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 +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #define _LARGE_FILES 1 @@ -14527,73 +15109,90 @@ 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)) +#define LARGE_OFF_T (((off_t) 1 << 31 << 31) - 1 + ((off_t) 1 << 31 << 31)) int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]; int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +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 +rm -f core conftest.err conftest.$ac_objext conftest.beam 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sys_large_files" >&5 +printf "%s\n" "$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 +printf "%s\n" "#define _LARGE_FILES $ac_cv_sys_large_files" >>confdefs.h ;; esac rm -rf conftest* fi +fi +# Checks for library functions. +ac_fn_c_check_func "$LINENO" "strchr" "ac_cv_func_strchr" +if test "x$ac_cv_func_strchr" = xyes +then : + printf "%s\n" "#define HAVE_STRCHR 1" >>confdefs.h + fi +ac_fn_c_check_func "$LINENO" "memcpy" "ac_cv_func_memcpy" +if test "x$ac_cv_func_memcpy" = xyes +then : + printf "%s\n" "#define HAVE_MEMCPY 1" >>confdefs.h +fi +ac_fn_c_check_func "$LINENO" "sprintf" "ac_cv_func_sprintf" +if test "x$ac_cv_func_sprintf" = xyes +then : + printf "%s\n" "#define HAVE_SPRINTF 1" >>confdefs.h -# Checks for library functions. -for ac_func in strchr memcpy sprintf localeconv -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 +ac_fn_c_check_func "$LINENO" "localeconv" "ac_cv_func_localeconv" +if test "x$ac_cv_func_localeconv" = xyes +then : + printf "%s\n" "#define HAVE_LOCALECONV 1" >>confdefs.h fi -done -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether lstat correctly handles trailing slash" >&5 -$as_echo_n "checking whether lstat correctly handles trailing slash... " >&6; } -if ${ac_cv_func_lstat_dereferences_slashed_symlink+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether lstat correctly handles trailing slash" >&5 +printf %s "checking whether lstat correctly handles trailing slash... " >&6; } +if test ${ac_cv_func_lstat_dereferences_slashed_symlink+y} +then : + printf %s "(cached) " >&6 +else $as_nop rm -f conftest.sym conftest.file echo >conftest.file if test "$as_ln_s" = "ln -s" && ln -s conftest.file conftest.sym; then - if test "$cross_compiling" = yes; then : - ac_cv_func_lstat_dereferences_slashed_symlink=no -else + if test "$cross_compiling" = yes +then : + case "$host_os" in # (( + # Guess yes on glibc systems. + *-gnu*) ac_cv_func_lstat_dereferences_slashed_symlink=yes ;; + # If we don't know, assume the worst. + *) ac_cv_func_lstat_dereferences_slashed_symlink=no ;; + esac +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $ac_includes_default int -main () +main (void) { struct stat sbuf; /* Linux will dereference the symlink and fail, as required by POSIX. @@ -14604,9 +15203,10 @@ return 0; } _ACEOF -if ac_fn_c_try_run "$LINENO"; then : +if ac_fn_c_try_run "$LINENO" +then : ac_cv_func_lstat_dereferences_slashed_symlink=yes -else +else $as_nop ac_cv_func_lstat_dereferences_slashed_symlink=no fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ @@ -14621,14 +15221,12 @@ rm -f conftest.sym conftest.file fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_lstat_dereferences_slashed_symlink" >&5 -$as_echo "$ac_cv_func_lstat_dereferences_slashed_symlink" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_lstat_dereferences_slashed_symlink" >&5 +printf "%s\n" "$ac_cv_func_lstat_dereferences_slashed_symlink" >&6; } test $ac_cv_func_lstat_dereferences_slashed_symlink = yes && -cat >>confdefs.h <<_ACEOF -#define LSTAT_FOLLOWS_SLASHED_SYMLINK 1 -_ACEOF +printf "%s\n" "#define LSTAT_FOLLOWS_SLASHED_SYMLINK 1" >>confdefs.h if test "x$ac_cv_func_lstat_dereferences_slashed_symlink" = xno; then @@ -14640,19 +15238,21 @@ fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether lstat accepts an empty string" >&5 -$as_echo_n "checking whether lstat accepts an empty string... " >&6; } -if ${ac_cv_func_lstat_empty_string_bug+:} false; then : - $as_echo_n "(cached) " >&6 -else - if test "$cross_compiling" = yes; then : +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether lstat accepts an empty string" >&5 +printf %s "checking whether lstat accepts an empty string... " >&6; } +if test ${ac_cv_func_lstat_empty_string_bug+y} +then : + printf %s "(cached) " >&6 +else $as_nop + if test "$cross_compiling" = yes +then : ac_cv_func_lstat_empty_string_bug=yes -else +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $ac_includes_default int -main () +main (void) { struct stat sbuf; return lstat ("", &sbuf) == 0; @@ -14660,9 +15260,10 @@ return 0; } _ACEOF -if ac_fn_c_try_run "$LINENO"; then : +if ac_fn_c_try_run "$LINENO" +then : ac_cv_func_lstat_empty_string_bug=no -else +else $as_nop ac_cv_func_lstat_empty_string_bug=yes fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ @@ -14670,8 +15271,8 @@ fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_lstat_empty_string_bug" >&5 -$as_echo "$ac_cv_func_lstat_empty_string_bug" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_lstat_empty_string_bug" >&5 +printf "%s\n" "$ac_cv_func_lstat_empty_string_bug" >&6; } if test $ac_cv_func_lstat_empty_string_bug = yes; then case " $LIBOBJS " in *" lstat.$ac_objext "* ) ;; @@ -14680,25 +15281,25 @@ esac -cat >>confdefs.h <<_ACEOF -#define HAVE_LSTAT_EMPTY_STRING_BUG 1 -_ACEOF +printf "%s\n" "#define HAVE_LSTAT_EMPTY_STRING_BUG 1" >>confdefs.h fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether stat accepts an empty string" >&5 -$as_echo_n "checking whether stat accepts an empty string... " >&6; } -if ${ac_cv_func_stat_empty_string_bug+:} false; then : - $as_echo_n "(cached) " >&6 -else - if test "$cross_compiling" = yes; then : +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether stat accepts an empty string" >&5 +printf %s "checking whether stat accepts an empty string... " >&6; } +if test ${ac_cv_func_stat_empty_string_bug+y} +then : + printf %s "(cached) " >&6 +else $as_nop + if test "$cross_compiling" = yes +then : ac_cv_func_stat_empty_string_bug=yes -else +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $ac_includes_default int -main () +main (void) { struct stat sbuf; return stat ("", &sbuf) == 0; @@ -14706,9 +15307,10 @@ return 0; } _ACEOF -if ac_fn_c_try_run "$LINENO"; then : +if ac_fn_c_try_run "$LINENO" +then : ac_cv_func_stat_empty_string_bug=no -else +else $as_nop ac_cv_func_stat_empty_string_bug=yes fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ @@ -14716,8 +15318,8 @@ fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_stat_empty_string_bug" >&5 -$as_echo "$ac_cv_func_stat_empty_string_bug" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_stat_empty_string_bug" >&5 +printf "%s\n" "$ac_cv_func_stat_empty_string_bug" >&6; } if test $ac_cv_func_stat_empty_string_bug = yes; then case " $LIBOBJS " in *" stat.$ac_objext "* ) ;; @@ -14726,9 +15328,7 @@ esac -cat >>confdefs.h <<_ACEOF -#define HAVE_STAT_EMPTY_STRING_BUG 1 -_ACEOF +printf "%s\n" "#define HAVE_STAT_EMPTY_STRING_BUG 1" >>confdefs.h fi @@ -14740,15 +15340,17 @@ # Check for availability of va_copy(). This is ISO C. Available with # gcc since version 3.0. - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for an implementation of va_copy()" >&5 -$as_echo_n "checking for an implementation of va_copy()... " >&6; } -if ${eso_cv_have_va_copy+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for an implementation of va_copy()" >&5 +printf %s "checking for an implementation of va_copy()... " >&6; } +if test ${eso_cv_have_va_copy+y} +then : + printf %s "(cached) " >&6 +else $as_nop - if test "$cross_compiling" = yes; then : + if test "$cross_compiling" = yes +then : eso_cv_have_va_copy=no -else +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -14772,7 +15374,7 @@ } int -main () +main (void) { f(0, 42); @@ -14782,9 +15384,10 @@ } _ACEOF -if ac_fn_c_try_run "$LINENO"; then : +if ac_fn_c_try_run "$LINENO" +then : eso_cv_have_va_copy=yes -else +else $as_nop eso_cv_have_va_copy=no fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ @@ -14793,21 +15396,23 @@ fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $eso_cv_have_va_copy" >&5 -$as_echo "$eso_cv_have_va_copy" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $eso_cv_have_va_copy" >&5 +printf "%s\n" "$eso_cv_have_va_copy" >&6; } # Check for availability of __va_copy(). Some compilers provide # this. Available with gcc since version 2.8.1. - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for an implementation of __va_copy()" >&5 -$as_echo_n "checking for an implementation of __va_copy()... " >&6; } -if ${eso_cv_have__va_copy+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for an implementation of __va_copy()" >&5 +printf %s "checking for an implementation of __va_copy()... " >&6; } +if test ${eso_cv_have__va_copy+y} +then : + printf %s "(cached) " >&6 +else $as_nop - if test "$cross_compiling" = yes; then : + if test "$cross_compiling" = yes +then : eso_cv_have__va_copy=no -else +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -14832,7 +15437,7 @@ } int -main () +main (void) { f(0, 42); @@ -14842,9 +15447,10 @@ } _ACEOF -if ac_fn_c_try_run "$LINENO"; then : +if ac_fn_c_try_run "$LINENO" +then : eso_cv_have__va_copy=yes -else +else $as_nop eso_cv_have__va_copy=no fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ @@ -14853,20 +15459,20 @@ fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $eso_cv_have__va_copy" >&5 -$as_echo "$eso_cv_have__va_copy" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $eso_cv_have__va_copy" >&5 +printf "%s\n" "$eso_cv_have__va_copy" >&6; } if test "x$eso_cv_have_va_copy" = "xyes"; then eso_func_va_copy=va_copy - $as_echo "#define HAVE_VA_COPY 1" >>confdefs.h + printf "%s\n" "#define HAVE_VA_COPY 1" >>confdefs.h else if test "x$eso_cv_have__va_copy" = "xyes"; then eso_func_va_copy=__va_copy - $as_echo "#define HAVE___VA_COPY 1" >>confdefs.h + printf "%s\n" "#define HAVE___VA_COPY 1" >>confdefs.h fi fi @@ -14875,24 +15481,24 @@ if test -n "$eso_func_va_copy"; then - cat >>confdefs.h <<_ACEOF -#define CX_VA_COPY $eso_func_va_copy -_ACEOF + printf "%s\n" "#define CX_VA_COPY $eso_func_va_copy" >>confdefs.h - $as_echo "#define HAVE_VA_COPY_STYLE_FUNCTION 1" >>confdefs.h + printf "%s\n" "#define HAVE_VA_COPY_STYLE_FUNCTION 1" >>confdefs.h fi # Check whether va_lists can be copied by value - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether va_lists can be copied by value" >&5 -$as_echo_n "checking whether va_lists can be copied by value... " >&6; } -if ${eso_cv_have_va_value_copy+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether va_lists can be copied by value" >&5 +printf %s "checking whether va_lists can be copied by value... " >&6; } +if test ${eso_cv_have_va_value_copy+y} +then : + printf %s "(cached) " >&6 +else $as_nop - if test "$cross_compiling" = yes; then : + if test "$cross_compiling" = yes +then : eso_cv_have_va_value_copy=no -else +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -14916,7 +15522,7 @@ } int -main () +main (void) { f(0, 42); @@ -14926,9 +15532,10 @@ } _ACEOF -if ac_fn_c_try_run "$LINENO"; then : +if ac_fn_c_try_run "$LINENO" +then : eso_cv_have_va_value_copy=yes -else +else $as_nop eso_cv_have_va_value_copy=no fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ @@ -14937,26 +15544,28 @@ fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $eso_cv_have_va_value_copy" >&5 -$as_echo "$eso_cv_have_va_value_copy" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $eso_cv_have_va_value_copy" >&5 +printf "%s\n" "$eso_cv_have_va_value_copy" >&6; } if test "x$eso_cv_have_va_value_copy" = "xyes"; then - $as_echo "#define HAVE_VA_LIST_COPY_BY_VALUE 1" >>confdefs.h + printf "%s\n" "#define HAVE_VA_LIST_COPY_BY_VALUE 1" >>confdefs.h fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether realloc(NULL,) works" >&5 -$as_echo_n "checking whether realloc(NULL,) works... " >&6; } -if ${eso_cv_have_sane_realloc+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether realloc(NULL,) works" >&5 +printf %s "checking whether realloc(NULL,) works... " >&6; } +if test ${eso_cv_have_sane_realloc+y} +then : + printf %s "(cached) " >&6 +else $as_nop - if test "$cross_compiling" = yes; then : + if test "$cross_compiling" = yes +then : eso_cv_have_sane_realloc=no -else +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -14964,7 +15573,7 @@ #include int -main () +main (void) { return realloc (0, sizeof (int)) == 0; @@ -14974,9 +15583,10 @@ } _ACEOF -if ac_fn_c_try_run "$LINENO"; then : +if ac_fn_c_try_run "$LINENO" +then : eso_cv_have_sane_realloc=yes -else +else $as_nop eso_cv_have_sane_realloc=no fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ @@ -14985,17 +15595,97 @@ fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $eso_cv_have_sane_realloc" >&5 -$as_echo "$eso_cv_have_sane_realloc" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $eso_cv_have_sane_realloc" >&5 +printf "%s\n" "$eso_cv_have_sane_realloc" >&6; } if test x$eso_cv_have_sane_realloc = xyes; then - $as_echo "#define HAVE_WORKING_REALLOC 1" >>confdefs.h + printf "%s\n" "#define HAVE_WORKING_REALLOC 1" >>confdefs.h fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC options needed to detect all undeclared functions" >&5 +printf %s "checking for $CC options needed to detect all undeclared functions... " >&6; } +if test ${ac_cv_c_undeclared_builtin_options+y} +then : + printf %s "(cached) " >&6 +else $as_nop + ac_save_CFLAGS=$CFLAGS + ac_cv_c_undeclared_builtin_options='cannot detect' + for ac_arg in '' -fno-builtin; do + CFLAGS="$ac_save_CFLAGS $ac_arg" + # This test program should *not* compile successfully. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main (void) +{ +(void) strchr; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO" +then : + +else $as_nop + # This test program should compile successfully. + # No library function is consistently available on + # freestanding implementations, so test against a dummy + # declaration. Include always-available headers on the + # off chance that they somehow elicit warnings. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +#include +#include +#include +extern void ac_decl (int, char *); + +int +main (void) +{ +(void) ac_decl (0, (char *) 0); + (void) ac_decl; + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO" +then : + if test x"$ac_arg" = x +then : + ac_cv_c_undeclared_builtin_options='none needed' +else $as_nop + ac_cv_c_undeclared_builtin_options=$ac_arg +fi + break +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext + done + CFLAGS=$ac_save_CFLAGS + +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_undeclared_builtin_options" >&5 +printf "%s\n" "$ac_cv_c_undeclared_builtin_options" >&6; } + case $ac_cv_c_undeclared_builtin_options in #( + 'cannot detect') : + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "cannot make $CC report undeclared builtins +See \`config.log' for more details" "$LINENO" 5; } ;; #( + 'none needed') : + ac_c_undeclared_builtin_options='' ;; #( + *) : + ac_c_undeclared_builtin_options=$ac_cv_c_undeclared_builtin_options ;; +esac + @@ -15009,13 +15699,13 @@ 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 : + ac_fn_check_decl "$LINENO" "strdup" "ac_cv_have_decl_strdup" "#include +" "$ac_c_undeclared_builtin_options" "CFLAGS" +if test "x$ac_cv_have_decl_strdup" = xyes +then : fi - eso_save_CFLAGS="$CFLAGS" if test x"$GCC" = xyes; then @@ -15023,7 +15713,8 @@ fi ac_fn_c_check_func "$LINENO" "strdup" "ac_cv_func_strdup" -if test "x$ac_cv_func_strdup" = xyes; then : +if test "x$ac_cv_func_strdup" = xyes +then : fi @@ -15039,7 +15730,7 @@ 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 + printf "%s\n" "#define HAVE_STRDUP 1" >>confdefs.h fi @@ -15059,13 +15750,13 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu - ac_fn_c_check_decl "$LINENO" "stpcpy" "ac_cv_have_decl_stpcpy" "#include -" -if test "x$ac_cv_have_decl_stpcpy" = xyes; then : + ac_fn_check_decl "$LINENO" "stpcpy" "ac_cv_have_decl_stpcpy" "#include +" "$ac_c_undeclared_builtin_options" "CFLAGS" +if test "x$ac_cv_have_decl_stpcpy" = xyes +then : fi - eso_save_CFLAGS="$CFLAGS" if test x"$GCC" = xyes; then @@ -15073,7 +15764,8 @@ fi ac_fn_c_check_func "$LINENO" "stpcpy" "ac_cv_func_stpcpy" -if test "x$ac_cv_func_stpcpy" = xyes; then : +if test "x$ac_cv_func_stpcpy" = xyes +then : fi @@ -15089,7 +15781,7 @@ if test x"$ac_cv_have_decl_stpcpy" = xyes && test x"$ac_cv_func_stpcpy" = xyes; then - $as_echo "#define HAVE_STPCPY 1" >>confdefs.h + printf "%s\n" "#define HAVE_STPCPY 1" >>confdefs.h fi @@ -15110,16 +15802,16 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu - ac_fn_c_check_decl "$LINENO" "vsnprintf" "ac_cv_have_decl_vsnprintf" " + ac_fn_check_decl "$LINENO" "vsnprintf" "ac_cv_have_decl_vsnprintf" " #include #include -" -if test "x$ac_cv_have_decl_vsnprintf" = xyes; then : +" "$ac_c_undeclared_builtin_options" "CFLAGS" +if test "x$ac_cv_have_decl_vsnprintf" = xyes +then : fi - eso_save_CFLAGS="$CFLAGS" if test x"$GCC" = xyes; then @@ -15127,7 +15819,8 @@ fi ac_fn_c_check_func "$LINENO" "vsnprintf" "ac_cv_func_vsnprintf" -if test "x$ac_cv_func_vsnprintf" = xyes; then : +if test "x$ac_cv_func_vsnprintf" = xyes +then : fi @@ -15143,7 +15836,7 @@ if test x"$ac_cv_have_decl_vsnprintf" = xyes && test x"$ac_cv_func_vsnprintf" = xyes; then - $as_echo "#define HAVE_VSNPRINTF 1" >>confdefs.h + printf "%s\n" "#define HAVE_VSNPRINTF 1" >>confdefs.h fi @@ -15156,11 +15849,12 @@ - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether vsnprintf has C99 semantics" >&5 -$as_echo_n "checking whether vsnprintf has C99 semantics... " >&6; } -if ${eso_cv_func_vsnprintf_c99+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether vsnprintf has C99 semantics" >&5 +printf %s "checking whether vsnprintf has C99 semantics... " >&6; } +if test ${eso_cv_func_vsnprintf_c99+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_ext=c ac_cpp='$CPP $CPPFLAGS' @@ -15179,9 +15873,10 @@ CPPFLAGS="$CPPFLAGS $CFLAGS" fi - if test "$cross_compiling" = yes; then : + if test "$cross_compiling" = yes +then : eso_cv_func_vsnprintf_c99=no -else +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -15209,7 +15904,7 @@ } int -main () +main (void) { doit((char*)"1234567"); @@ -15220,9 +15915,10 @@ } _ACEOF -if ac_fn_c_try_run "$LINENO"; then : +if ac_fn_c_try_run "$LINENO" +then : eso_cv_func_vsnprintf_c99=yes -else +else $as_nop eso_cv_func_vsnprintf_c99=no fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ @@ -15243,8 +15939,8 @@ fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $eso_cv_func_vsnprintf_c99" >&5 -$as_echo "$eso_cv_func_vsnprintf_c99" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $eso_cv_func_vsnprintf_c99" >&5 +printf "%s\n" "$eso_cv_func_vsnprintf_c99" >&6; } # 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 @@ -15252,7 +15948,7 @@ # manual. if test x$eso_cv_func_vsnprintf_c99 = xyes; then - $as_echo "#define HAVE_VSNPRINTF_C99 1" >>confdefs.h + printf "%s\n" "#define HAVE_VSNPRINTF_C99 1" >>confdefs.h fi @@ -15285,9 +15981,10 @@ - if test "$cross_compiling" = yes; then : + if test "$cross_compiling" = yes +then : eso_have_printf_str_format_null=no -else +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -15296,7 +15993,7 @@ #include int -main () +main (void) { char s[128]; @@ -15309,9 +16006,10 @@ } _ACEOF -if ac_fn_c_try_run "$LINENO"; then : +if ac_fn_c_try_run "$LINENO" +then : eso_have_printf_str_format_null=yes -else +else $as_nop eso_have_printf_str_format_null=no fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ @@ -15320,7 +16018,7 @@ if test x$eso_have_printf_str_format_null = xyes; then - $as_echo "#define HAVE_PRINTF_STR_FMT_NULL 1" >>confdefs.h + printf "%s\n" "#define HAVE_PRINTF_STR_FMT_NULL 1" >>confdefs.h fi @@ -15329,9 +16027,10 @@ - if test "$cross_compiling" = yes; then : + if test "$cross_compiling" = yes +then : eso_have_printf_ptr_format_nil=no -else +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -15340,7 +16039,7 @@ #include int -main () +main (void) { char s[128]; @@ -15353,9 +16052,10 @@ } _ACEOF -if ac_fn_c_try_run "$LINENO"; then : +if ac_fn_c_try_run "$LINENO" +then : eso_have_printf_ptr_format_nil=yes -else +else $as_nop eso_have_printf_ptr_format_nil=no fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ @@ -15364,7 +16064,7 @@ if test x$eso_have_printf_ptr_format_nil = xyes; then - $as_echo "#define HAVE_PRINTF_PTR_FMT_NIL 1" >>confdefs.h + printf "%s\n" "#define HAVE_PRINTF_PTR_FMT_NIL 1" >>confdefs.h fi @@ -15373,9 +16073,10 @@ - if test "$cross_compiling" = yes; then : + if test "$cross_compiling" = yes +then : eso_have_printf_ptr_format_alternate=no -else +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -15384,7 +16085,7 @@ #include int -main () +main (void) { char s1[128], s2[128]; @@ -15398,9 +16099,10 @@ } _ACEOF -if ac_fn_c_try_run "$LINENO"; then : +if ac_fn_c_try_run "$LINENO" +then : eso_have_printf_ptr_format_alternate=yes -else +else $as_nop eso_have_printf_ptr_format_alternate=no fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ @@ -15409,7 +16111,7 @@ if test x$eso_have_printf_ptr_format_alternate = xyes; then - $as_echo "#define HAVE_PRINTF_PTR_FMT_ALTERNATE 1" >>confdefs.h + printf "%s\n" "#define HAVE_PRINTF_PTR_FMT_ALTERNATE 1" >>confdefs.h fi @@ -15418,9 +16120,10 @@ - if test "$cross_compiling" = yes; then : + if test "$cross_compiling" = yes +then : eso_have_printf_ptr_format_signed=no -else +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -15428,7 +16131,7 @@ #include int -main () +main (void) { char s[128]; @@ -15441,9 +16144,10 @@ } _ACEOF -if ac_fn_c_try_run "$LINENO"; then : +if ac_fn_c_try_run "$LINENO" +then : eso_have_printf_ptr_format_signed=yes -else +else $as_nop eso_have_printf_ptr_format_signed=no fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ @@ -15452,7 +16156,7 @@ if test x$eso_have_printf_ptr_format_signed = xyes; then - $as_echo "#define HAVE_PRINTF_PTR_FMT_SIGNED 1" >>confdefs.h + printf "%s\n" "#define HAVE_PRINTF_PTR_FMT_SIGNED 1" >>confdefs.h fi @@ -15462,9 +16166,10 @@ - if test "$cross_compiling" = yes; then : + if test "$cross_compiling" = yes +then : eso_have_printf_flt_format_g_std=no -else +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -15472,7 +16177,7 @@ #include int -main () +main (void) { char s1[128], s2[128]; @@ -15487,9 +16192,10 @@ } _ACEOF -if ac_fn_c_try_run "$LINENO"; then : +if ac_fn_c_try_run "$LINENO" +then : eso_have_printf_flt_format_g_std=yes -else +else $as_nop eso_have_printf_flt_format_g_std=no fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ @@ -15498,7 +16204,7 @@ if test x$eso_have_printf_flt_format_g_std = xyes; then - $as_echo "#define HAVE_PRINTF_FLT_FMT_G_STD 1" >>confdefs.h + printf "%s\n" "#define HAVE_PRINTF_FLT_FMT_G_STD 1" >>confdefs.h fi @@ -15514,13 +16220,13 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu - ac_fn_c_check_decl "$LINENO" "snprintf" "ac_cv_have_decl_snprintf" "#include -" -if test "x$ac_cv_have_decl_snprintf" = xyes; then : + ac_fn_check_decl "$LINENO" "snprintf" "ac_cv_have_decl_snprintf" "#include +" "$ac_c_undeclared_builtin_options" "CFLAGS" +if test "x$ac_cv_have_decl_snprintf" = xyes +then : fi - eso_save_CFLAGS="$CFLAGS" if test x"$GCC" = xyes; then @@ -15528,7 +16234,8 @@ fi ac_fn_c_check_func "$LINENO" "snprintf" "ac_cv_func_snprintf" -if test "x$ac_cv_func_snprintf" = xyes; then : +if test "x$ac_cv_func_snprintf" = xyes +then : fi @@ -15544,7 +16251,7 @@ if test x"$ac_cv_have_decl_snprintf" = xyes && test x"$ac_cv_func_snprintf" = xyes; then - $as_echo "#define HAVE_SNPRINTF 1" >>confdefs.h + printf "%s\n" "#define HAVE_SNPRINTF 1" >>confdefs.h fi @@ -15563,16 +16270,16 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu - ac_fn_c_check_decl "$LINENO" "vasprintf" "ac_cv_have_decl_vasprintf" " + ac_fn_check_decl "$LINENO" "vasprintf" "ac_cv_have_decl_vasprintf" " #include #include -" -if test "x$ac_cv_have_decl_vasprintf" = xyes; then : +" "$ac_c_undeclared_builtin_options" "CFLAGS" +if test "x$ac_cv_have_decl_vasprintf" = xyes +then : fi - eso_save_CFLAGS="$CFLAGS" if test x"$GCC" = xyes; then @@ -15580,7 +16287,8 @@ fi ac_fn_c_check_func "$LINENO" "vasprintf" "ac_cv_func_vasprintf" -if test "x$ac_cv_func_vasprintf" = xyes; then : +if test "x$ac_cv_func_vasprintf" = xyes +then : fi @@ -15596,7 +16304,7 @@ if test x"$ac_cv_have_decl_vasprintf" = xyes && test x"$ac_cv_func_vasprintf" = xyes; then - $as_echo "#define HAVE_VASPRINTF 1" >>confdefs.h + printf "%s\n" "#define HAVE_VASPRINTF 1" >>confdefs.h fi @@ -15612,15 +16320,15 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu - ac_fn_c_check_decl "$LINENO" "asprintf" "ac_cv_have_decl_asprintf" " + ac_fn_check_decl "$LINENO" "asprintf" "ac_cv_have_decl_asprintf" " #include -" -if test "x$ac_cv_have_decl_asprintf" = xyes; then : +" "$ac_c_undeclared_builtin_options" "CFLAGS" +if test "x$ac_cv_have_decl_asprintf" = xyes +then : fi - eso_save_CFLAGS="$CFLAGS" if test x"$GCC" = xyes; then @@ -15628,7 +16336,8 @@ fi ac_fn_c_check_func "$LINENO" "asprintf" "ac_cv_func_asprintf" -if test "x$ac_cv_func_asprintf" = xyes; then : +if test "x$ac_cv_func_asprintf" = xyes +then : fi @@ -15644,7 +16353,7 @@ if test x"$ac_cv_have_decl_asprintf" = xyes && test x"$ac_cv_func_asprintf" = xyes; then - $as_echo "#define HAVE_ASPRINTF 1" >>confdefs.h + printf "%s\n" "#define HAVE_ASPRINTF 1" >>confdefs.h fi @@ -15663,13 +16372,13 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu - ac_fn_c_check_decl "$LINENO" "sysconf" "ac_cv_have_decl_sysconf" "#include -" -if test "x$ac_cv_have_decl_sysconf" = xyes; then : + ac_fn_check_decl "$LINENO" "sysconf" "ac_cv_have_decl_sysconf" "#include +" "$ac_c_undeclared_builtin_options" "CFLAGS" +if test "x$ac_cv_have_decl_sysconf" = xyes +then : fi - eso_save_CFLAGS="$CFLAGS" if test x"$GCC" = xyes; then @@ -15677,7 +16386,8 @@ fi ac_fn_c_check_func "$LINENO" "sysconf" "ac_cv_func_sysconf" -if test "x$ac_cv_func_sysconf" = xyes; then : +if test "x$ac_cv_func_sysconf" = xyes +then : fi @@ -15693,7 +16403,7 @@ if test x"$ac_cv_have_decl_sysconf" = xyes && test x"$ac_cv_func_sysconf" = xyes; then - $as_echo "#define HAVE_SYSCONF 1" >>confdefs.h + printf "%s\n" "#define HAVE_SYSCONF 1" >>confdefs.h fi @@ -15712,13 +16422,13 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu - ac_fn_c_check_decl "$LINENO" "fpathconf" "ac_cv_have_decl_fpathconf" "#include -" -if test "x$ac_cv_have_decl_fpathconf" = xyes; then : + ac_fn_check_decl "$LINENO" "fpathconf" "ac_cv_have_decl_fpathconf" "#include +" "$ac_c_undeclared_builtin_options" "CFLAGS" +if test "x$ac_cv_have_decl_fpathconf" = xyes +then : fi - eso_save_CFLAGS="$CFLAGS" if test x"$GCC" = xyes; then @@ -15726,7 +16436,8 @@ fi ac_fn_c_check_func "$LINENO" "fpathconf" "ac_cv_func_fpathconf" -if test "x$ac_cv_func_fpathconf" = xyes; then : +if test "x$ac_cv_func_fpathconf" = xyes +then : fi @@ -15742,7 +16453,7 @@ if test x"$ac_cv_have_decl_fpathconf" = xyes && test x"$ac_cv_func_fpathconf" = xyes; then - $as_echo "#define HAVE_FPATHCONF 1" >>confdefs.h + printf "%s\n" "#define HAVE_FPATHCONF 1" >>confdefs.h fi @@ -15759,13 +16470,13 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu - ac_fn_c_check_decl "$LINENO" "pathconf" "ac_cv_have_decl_pathconf" "#include -" -if test "x$ac_cv_have_decl_pathconf" = xyes; then : + ac_fn_check_decl "$LINENO" "pathconf" "ac_cv_have_decl_pathconf" "#include +" "$ac_c_undeclared_builtin_options" "CFLAGS" +if test "x$ac_cv_have_decl_pathconf" = xyes +then : fi - eso_save_CFLAGS="$CFLAGS" if test x"$GCC" = xyes; then @@ -15773,7 +16484,8 @@ fi ac_fn_c_check_func "$LINENO" "pathconf" "ac_cv_func_pathconf" -if test "x$ac_cv_func_pathconf" = xyes; then : +if test "x$ac_cv_func_pathconf" = xyes +then : fi @@ -15789,7 +16501,7 @@ if test x"$ac_cv_have_decl_pathconf" = xyes && test x"$ac_cv_func_pathconf" = xyes; then - $as_echo "#define HAVE_PATHCONF 1" >>confdefs.h + printf "%s\n" "#define HAVE_PATHCONF 1" >>confdefs.h fi @@ -15839,7 +16551,7 @@ # Library log domain -$as_echo "#define CX_LOG_DOMAIN \"CxLib\"" >>confdefs.h +printf "%s\n" "#define CX_LOG_DOMAIN \"CxLib\"" >>confdefs.h ac_config_files="$ac_config_files Makefile Doxyfile cext.pc cext/Makefile tests/Makefile" @@ -15871,8 +16583,8 @@ 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;} ;; + *_cv_*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 +printf "%s\n" "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; esac case $ac_var in #( _ | IFS | as_nl) ;; #( @@ -15902,15 +16614,15 @@ /^ac_cv_env_/b end t clear :clear - s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/ + s/^\([^=]*\)=\(.*[{}].*\)$/test ${\1+y} || &/ 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;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5 +printf "%s\n" "$as_me: updating cache $cache_file" >&6;} if test ! -f "$cache_file" || test -h "$cache_file"; then cat confcache >"$cache_file" else @@ -15924,8 +16636,8 @@ 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;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5 +printf "%s\n" "$as_me: not updating unwritable cache $cache_file" >&6;} fi fi rm -f confcache @@ -15942,7 +16654,7 @@ 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"` + ac_i=`printf "%s\n" "$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" @@ -15953,14 +16665,14 @@ 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; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking that generated files are newer than configure" >&5 +printf %s "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; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: done" >&5 +printf "%s\n" "done" >&6; } if test -n "$EXEEXT"; then am__EXEEXT_TRUE= am__EXEEXT_FALSE='#' @@ -15986,8 +16698,8 @@ 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;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5 +printf "%s\n" "$as_me: creating $CONFIG_STATUS" >&6;} as_write_fail=0 cat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1 #! $SHELL @@ -16010,14 +16722,16 @@ # Be more Bourne compatible DUALCASE=1; export DUALCASE # for MKS sh -if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : +as_nop=: +if test ${ZSH_VERSION+y} && (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 +else $as_nop case `(set -o) 2>/dev/null` in #( *posix*) : set -o posix ;; #( @@ -16027,46 +16741,46 @@ fi + +# Reset variables that may have inherited troublesome values from +# the environment. + +# IFS needs to be set, to space, tab, and newline, in precisely that order. +# (If _AS_PATH_WALK were called with IFS unset, it would have the +# side effect of setting IFS to empty, thus disabling word splitting.) +# Quoting is to prevent editors from complaining about space-tab. 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 +IFS=" "" $as_nl" + +PS1='$ ' +PS2='> ' +PS4='+ ' + +# Ensure predictable behavior from utilities with locale-dependent output. +LC_ALL=C +export LC_ALL +LANGUAGE=C +export LANGUAGE + +# We cannot yet rely on "unset" to work, but we need these variables +# to be unset--not just set to an empty or harmless value--now, to +# avoid bugs in old shells (e.g. pre-3.0 UWIN ksh). This construct +# also avoids known problems related to "unset" and subshell syntax +# in other old shells (e.g. bash 2.01 and pdksh 5.2.14). +for as_var in BASH_ENV ENV MAIL MAILPATH CDPATH +do eval test \${$as_var+y} \ + && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : +done + +# Ensure that fds 0, 1, and 2 are open. +if (exec 3>&0) 2>/dev/null; then :; else exec 0&1) 2>/dev/null; then :; else exec 1>/dev/null; fi +if (exec 3>&2) ; then :; else exec 2>/dev/null; fi # The user is always right. -if test "${PATH_SEPARATOR+set}" != set; then +if ${PATH_SEPARATOR+false} :; 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 || @@ -16075,13 +16789,6 @@ 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 #(( @@ -16090,8 +16797,12 @@ 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 + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + test -r "$as_dir$0" && as_myself=$as_dir$0 && break done IFS=$as_save_IFS @@ -16103,30 +16814,10 @@ 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 + printf "%s\n" "$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] @@ -16139,13 +16830,14 @@ 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 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 fi - $as_echo "$as_me: error: $2" >&2 + printf "%s\n" "$as_me: error: $2" >&2 as_fn_exit $as_status } # as_fn_error + # as_fn_set_status STATUS # ----------------------- # Set $? to STATUS, without forking. @@ -16172,18 +16864,20 @@ { 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 : +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 +else $as_nop as_fn_append () { eval $1=\$$1\$2 @@ -16195,12 +16889,13 @@ # 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 : +if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null +then : eval 'as_fn_arith () { as_val=$(( $* )) }' -else +else $as_nop as_fn_arith () { as_val=`expr "$@" || test $? -eq 1` @@ -16231,7 +16926,7 @@ $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ X"$0" : 'X\(//\)$' \| \ X"$0" : 'X\(/\)' \| . 2>/dev/null || -$as_echo X/"$0" | +printf "%s\n" X/"$0" | sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/ q @@ -16253,6 +16948,10 @@ as_cr_digits='0123456789' as_cr_alnum=$as_cr_Letters$as_cr_digits + +# Determine whether it's possible to make 'echo' print without a newline. +# These variables are no longer used directly by Autoconf, but are AC_SUBSTed +# for compatibility with existing Makefiles. ECHO_C= ECHO_N= ECHO_T= case `echo -n x` in #((((( -n*) @@ -16266,6 +16965,12 @@ ECHO_N='-n';; esac +# For backward compatibility with old third-party macros, we provide +# the shell variables $as_echo and $as_echo_n. New code should use +# AS_ECHO(["message"]) and AS_ECHO_N(["message"]), respectively. +as_echo='printf %s\n' +as_echo_n='printf %s' + rm -f conf$$ conf$$.exe conf$$.file if test -d conf$$.dir; then rm -f conf$$.dir/conf$$.file @@ -16307,7 +17012,7 @@ as_dirs= while :; do case $as_dir in #( - *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( + *\'*) as_qdir=`printf "%s\n" "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( *) as_qdir=$as_dir;; esac as_dirs="'$as_qdir' $as_dirs" @@ -16316,7 +17021,7 @@ X"$as_dir" : 'X\(//\)[^/]' \| \ X"$as_dir" : 'X\(//\)$' \| \ X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || -$as_echo X"$as_dir" | +printf "%s\n" X"$as_dir" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q @@ -16379,7 +17084,7 @@ # values after options handling. ac_log=" This file was extended by C Extension Library $as_me 1.2.4, which was -generated by GNU Autoconf 2.69. Invocation command line was +generated by GNU Autoconf 2.71. Invocation command line was CONFIG_FILES = $CONFIG_FILES CONFIG_HEADERS = $CONFIG_HEADERS @@ -16441,14 +17146,16 @@ Report bugs to ." _ACEOF +ac_cs_config=`printf "%s\n" "$ac_configure_args" | sed "$ac_safe_unquote"` +ac_cs_config_escaped=`printf "%s\n" "$ac_cs_config" | sed "s/^ //; s/'/'\\\\\\\\''/g"` cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 -ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" +ac_cs_config='$ac_cs_config_escaped' ac_cs_version="\\ C Extension Library config.status 1.2.4 -configured by $0, generated by GNU Autoconf 2.69, +configured by $0, generated by GNU Autoconf 2.71, with options \\"\$ac_cs_config\\" -Copyright (C) 2012 Free Software Foundation, Inc. +Copyright (C) 2021 Free Software Foundation, Inc. This config.status script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it." @@ -16488,15 +17195,15 @@ -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 ;; + printf "%s\n" "$ac_cs_version"; exit ;; --config | --confi | --conf | --con | --co | --c ) - $as_echo "$ac_cs_config"; exit ;; + printf "%s\n" "$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"` ;; + *\'*) ac_optarg=`printf "%s\n" "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; '') as_fn_error $? "missing file argument" ;; esac as_fn_append CONFIG_FILES " '$ac_optarg'" @@ -16504,7 +17211,7 @@ --header | --heade | --head | --hea ) $ac_shift case $ac_optarg in - *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; + *\'*) ac_optarg=`printf "%s\n" "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; esac as_fn_append CONFIG_HEADERS " '$ac_optarg'" ac_need_defaults=false;; @@ -16513,7 +17220,7 @@ as_fn_error $? "ambiguous option: \`$1' Try \`$0 --help' for more information.";; --help | --hel | -h ) - $as_echo "$ac_cs_usage"; exit ;; + printf "%s\n" "$ac_cs_usage"; exit ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil | --si | --s) ac_cs_silent=: ;; @@ -16541,7 +17248,7 @@ 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 + \printf "%s\n" "running CONFIG_SHELL=$SHELL \$*" >&6 CONFIG_SHELL='$SHELL' export CONFIG_SHELL exec "\$@" @@ -16555,7 +17262,7 @@ sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX ## Running $as_me. ## _ASBOX - $as_echo "$ac_log" + printf "%s\n" "$ac_log" } >&5 _ACEOF @@ -16563,7 +17270,7 @@ # # INIT-COMMANDS # -AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir" +AMDEP_TRUE="$AMDEP_TRUE" MAKE="${MAKE-make}" # The HP-UX ksh and POSIX shell print the target directory to stdout @@ -17142,9 +17849,9 @@ # 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 + test ${CONFIG_FILES+y} || CONFIG_FILES=$config_files + test ${CONFIG_HEADERS+y} || CONFIG_HEADERS=$config_headers + test ${CONFIG_COMMANDS+y} || CONFIG_COMMANDS=$config_commands fi # Have a temporary directory for convenience. Make it in the build tree @@ -17480,7 +18187,7 @@ 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 + case $ac_f in *\'*) ac_f=`printf "%s\n" "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac as_fn_append ac_file_inputs " '$ac_f'" done @@ -17488,17 +18195,17 @@ # 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' + printf "%s\n" "$*" | 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;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5 +printf "%s\n" "$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" | + ac_sed_conf_input=`printf "%s\n" "$configure_input" | sed 's/[\\\\&|]/\\\\&/g'`;; #( *) ac_sed_conf_input=$configure_input;; esac @@ -17515,7 +18222,7 @@ X"$ac_file" : 'X\(//\)[^/]' \| \ X"$ac_file" : 'X\(//\)$' \| \ X"$ac_file" : 'X\(/\)' \| . 2>/dev/null || -$as_echo X"$ac_file" | +printf "%s\n" X"$ac_file" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q @@ -17539,9 +18246,9 @@ case "$ac_dir" in .) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; *) - ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` + ac_dir_suffix=/`printf "%s\n" "$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|/||'` + ac_top_builddir_sub=`printf "%s\n" "$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/ ;; @@ -17603,8 +18310,8 @@ 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;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5 +printf "%s\n" "$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=' @@ -17648,9 +18355,9 @@ { 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' + { printf "%s\n" "$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' +printf "%s\n" "$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" @@ -17666,20 +18373,20 @@ # if test x"$ac_file" != x-; then { - $as_echo "/* $configure_input */" \ + printf "%s\n" "/* $configure_input */" >&1 \ && 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;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: $ac_file is unchanged" >&5 +printf "%s\n" "$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 */" \ + printf "%s\n" "/* $configure_input */" >&1 \ && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs" \ || as_fn_error $? "could not create -" "$LINENO" 5 fi @@ -17699,7 +18406,7 @@ X"$_am_arg" : 'X\(//\)[^/]' \| \ X"$_am_arg" : 'X\(//\)$' \| \ X"$_am_arg" : 'X\(/\)' \| . 2>/dev/null || -$as_echo X"$_am_arg" | +printf "%s\n" X"$_am_arg" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q @@ -17719,8 +18426,8 @@ 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;} + :C) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: executing $ac_file commands" >&5 +printf "%s\n" "$as_me: executing $ac_file commands" >&6;} ;; esac @@ -17730,29 +18437,35 @@ # 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 + # TODO: see whether this extra hack can be removed once we start + # requiring Autoconf 2.70 or later. + case $CONFIG_FILES in #( + *\'*) : + eval set x "$CONFIG_FILES" ;; #( + *) : + set x $CONFIG_FILES ;; #( + *) : + ;; +esac shift - for mf + # Used to flag and report bootstrapping failures. + am_rc=0 + for am_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 + am_mf=`printf "%s\n" "$am_mf" | sed -e 's/:.*$//'` + # Check whether this is an Automake generated Makefile which includes + # dependency-tracking related rules and includes. + # Grep'ing the whole file directly is not great: 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 -n 's,^am--depfiles:.*,X,p' "$am_mf" | grep X >/dev/null 2>&1 \ + || continue + am_dirpart=`$as_dirname -- "$am_mf" || +$as_expr X"$am_mf" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$am_mf" : 'X\(//\)[^/]' \| \ + X"$am_mf" : 'X\(//\)$' \| \ + X"$am_mf" : 'X\(/\)' \| . 2>/dev/null || +printf "%s\n" X"$am_mf" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q @@ -17770,53 +18483,50 @@ 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\(\/\/\)[^/].*/{ + am_filepart=`$as_basename -- "$am_mf" || +$as_expr X/"$am_mf" : '.*/\([^/][^/]*\)/*$' \| \ + X"$am_mf" : 'X\(//\)$' \| \ + X"$am_mf" : 'X\(/\)' \| . 2>/dev/null || +printf "%s\n" X/"$am_mf" | + sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/ q } - /^X\(\/\/\)$/{ + /^X\/\(\/\/\)$/{ s//\1/ q } - /^X\(\/\).*/{ + /^X\/\(\/\).*/{ s//\1/ q } s/.*/./; q'` - as_dir=$dirpart/$fdir; as_fn_mkdir_p - # echo "creating $dirpart/$file" - echo '# dummy' > "$dirpart/$file" - done + { echo "$as_me:$LINENO: cd "$am_dirpart" \ + && sed -e '/# am--include-marker/d' "$am_filepart" \ + | $MAKE -f - am--depfiles" >&5 + (cd "$am_dirpart" \ + && sed -e '/# am--include-marker/d' "$am_filepart" \ + | $MAKE -f - am--depfiles) >&5 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } || am_rc=$? done + if test $am_rc -ne 0; then + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "Something went wrong bootstrapping makefile fragments + for automatic dependency tracking. If GNU make was not used, consider + re-running the configure script with MAKE=\"gmake\" (or whatever is + necessary). You can also try re-running configure with the + '--disable-dependency-tracking' option to at least be able to build + the package (albeit without support for automatic dependency tracking). +See \`config.log' for more details" "$LINENO" 5; } + fi + { am_dirpart=; unset am_dirpart;} + { am_filepart=; unset am_filepart;} + { am_mf=; unset am_mf;} + { am_rc=; unset am_rc;} + rm -f conftest-deps.mk } ;; "libtool":C) @@ -18346,6 +19056,7 @@ esac + ltmain=$ac_aux_dir/ltmain.sh @@ -18617,8 +19328,8 @@ if test -f $cfgfile; then if cmp -s $tcfgfile $cfgfile; then - { $as_echo "$as_me:${as_lineno-$LINENO}: $cfgfile is unchanged" >&5 -$as_echo "$as_me: $cfgfile is unchanged" >&6;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: $cfgfile is unchanged" >&5 +printf "%s\n" "$as_me: $cfgfile is unchanged" >&6;} rm -f $tcfgfile else mv $tcfgfile $cfgfile @@ -18661,7 +19372,8 @@ $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;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5 +printf "%s\n" "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;} fi + diff -Nru cpl-7.1.4+ds/libcext/Makefile.in cpl-7.2.2+ds/libcext/Makefile.in --- cpl-7.1.4+ds/libcext/Makefile.in 2021-05-07 12:09:58.000000000 +0000 +++ cpl-7.2.2+ds/libcext/Makefile.in 2022-04-29 14:56:23.000000000 +0000 @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.15.1 from Makefile.am. +# Makefile.in generated by automake 1.16.3 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2017 Free Software Foundation, Inc. +# Copyright (C) 1994-2020 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -168,9 +168,9 @@ $(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 + cscope distdir distdir-am 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. @@ -238,6 +238,8 @@ DIST_ARCHIVES = $(distdir).tar.gz GZIP_ENV = --best DIST_TARGETS = dist-gzip +# Exists only to be overridden by the user if desired. +AM_DISTCHECK_DVI_TARGET = dvi distuninstallcheck_listfiles = find . -type f -print am__distuninstallcheck_listfiles = $(distuninstallcheck_listfiles) \ | sed 's|^\./|$(prefix)/|' | grep -v '$(infodir)/dir$$' @@ -254,7 +256,6 @@ CCDEPMODE = @CCDEPMODE@ CEXT_INCLUDES = @CEXT_INCLUDES@ CFLAGS = @CFLAGS@ -CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ CX_DEBUG_FLAGS = @CX_DEBUG_FLAGS@ CYGPATH_W = @CYGPATH_W@ @@ -365,6 +366,7 @@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ @@ -416,8 +418,8 @@ 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);; \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__maybe_remake_depfiles)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__maybe_remake_depfiles);; \ esac; $(top_srcdir)/admin/doxygen.am $(am__empty): @@ -586,7 +588,10 @@ -rm -f cscope.out cscope.in.out cscope.po.out cscope.files @MAINTAINER_MODE_FALSE@dist-hook: -distdir: $(DISTFILES) +distdir: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) distdir-am + +distdir-am: $(DISTFILES) $(am__remove_distdir) test -d "$(distdir)" || mkdir "$(distdir)" @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ @@ -669,6 +674,10 @@ tardir=$(distdir) && $(am__tar) | XZ_OPT=$${XZ_OPT--e} xz -c >$(distdir).tar.xz $(am__post_remove_distdir) +dist-zstd: distdir + tardir=$(distdir) && $(am__tar) | zstd -c $${ZSTD_CLEVEL-$${ZSTD_OPT--19}} >$(distdir).tar.zst + $(am__post_remove_distdir) + dist-tarZ: distdir @echo WARNING: "Support for distribution archives compressed with" \ "legacy program 'compress' is deprecated." >&2 @@ -711,6 +720,8 @@ eval GZIP= gzip $(GZIP_ENV) -dc $(distdir).shar.gz | unshar ;;\ *.zip*) \ unzip $(distdir).zip ;;\ + *.tar.zst*) \ + zstd -dc $(distdir).tar.zst | $(am__untar) ;;\ esac chmod -R a-w $(distdir) chmod u+w $(distdir) @@ -726,7 +737,7 @@ $(DISTCHECK_CONFIGURE_FLAGS) \ --srcdir=../.. --prefix="$$dc_install_base" \ && $(MAKE) $(AM_MAKEFLAGS) \ - && $(MAKE) $(AM_MAKEFLAGS) dvi \ + && $(MAKE) $(AM_MAKEFLAGS) $(AM_DISTCHECK_DVI_TARGET) \ && $(MAKE) $(AM_MAKEFLAGS) check \ && $(MAKE) $(AM_MAKEFLAGS) install \ && $(MAKE) $(AM_MAKEFLAGS) installcheck \ @@ -893,8 +904,8 @@ am--refresh check check-am clean clean-cscope clean-generic \ clean-libtool clean-local cscope cscopelist-am ctags ctags-am \ dist dist-all dist-bzip2 dist-gzip dist-hook dist-lzip \ - dist-shar dist-tarZ dist-xz dist-zip distcheck distclean \ - distclean-generic distclean-hdr distclean-libtool \ + dist-shar dist-tarZ dist-xz dist-zip dist-zstd distcheck \ + distclean 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 \ diff -Nru cpl-7.1.4+ds/libcext/tests/Makefile.in cpl-7.2.2+ds/libcext/tests/Makefile.in --- cpl-7.1.4+ds/libcext/tests/Makefile.in 2021-05-07 12:09:58.000000000 +0000 +++ cpl-7.2.2+ds/libcext/tests/Makefile.in 2022-04-29 14:56:23.000000000 +0000 @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.15.1 from Makefile.am. +# Makefile.in generated by automake 1.16.3 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2017 Free Software Foundation, Inc. +# Copyright (C) 1994-2020 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -156,7 +156,11 @@ am__v_at_1 = DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) depcomp = $(SHELL) $(top_srcdir)/admin/depcomp -am__depfiles_maybe = depfiles +am__maybe_remake_depfiles = depfiles +am__depfiles_remade = ./$(DEPDIR)/cxdeque-test.Po \ + ./$(DEPDIR)/cxlist-test.Po ./$(DEPDIR)/cxmap-test.Po \ + ./$(DEPDIR)/cxslist-test.Po ./$(DEPDIR)/cxstring-test.Po \ + ./$(DEPDIR)/cxtree-test.Po ./$(DEPDIR)/cxtypes-test.Po am__mv = mv -f COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) @@ -390,6 +394,7 @@ bases='$(TEST_LOGS)'; \ bases=`for i in $$bases; do echo $$i; done | sed 's/\.log$$//'`; \ bases=`echo $$bases` +AM_TESTSUITE_SUMMARY_HEADER = ' for $(PACKAGE_STRING)' RECHECK_LOGS = $(TEST_LOGS) AM_RECURSIVE_TARGETS = check recheck TEST_SUITE_LOG = test-suite.log @@ -427,7 +432,6 @@ CCDEPMODE = @CCDEPMODE@ CEXT_INCLUDES = @CEXT_INCLUDES@ CFLAGS = @CFLAGS@ -CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ CX_DEBUG_FLAGS = @CX_DEBUG_FLAGS@ CYGPATH_W = @CYGPATH_W@ @@ -538,6 +542,7 @@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ @@ -589,8 +594,8 @@ *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);; \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ esac; $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) @@ -645,13 +650,19 @@ distclean-compile: -rm -f *.tab.c -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cxdeque-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cxlist-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cxmap-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cxslist-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cxstring-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cxtree-test.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cxtypes-test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cxdeque-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cxlist-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cxmap-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cxslist-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cxstring-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cxtree-test.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cxtypes-test.Po@am__quote@ # am--include-marker + +$(am__depfiles_remade): + @$(MKDIR_P) $(@D) + @echo '# dummy' >$@-t && $(am__mv) $@-t $@ + +am--depfiles: $(am__depfiles_remade) .c.o: @am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @@ -839,7 +850,7 @@ test x"$$VERBOSE" = x || cat $(TEST_SUITE_LOG); \ fi; \ echo "$${col}$$br$${std}"; \ - echo "$${col}Testsuite summary for $(PACKAGE_STRING)$${std}"; \ + echo "$${col}Testsuite summary"$(AM_TESTSUITE_SUMMARY_HEADER)"$${std}"; \ echo "$${col}$$br$${std}"; \ create_testsuite_report --maybe-color; \ echo "$$col$$br$$std"; \ @@ -852,7 +863,7 @@ fi; \ $$success || exit 1 -check-TESTS: +check-TESTS: $(check_PROGRAMS) @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) @@ -937,7 +948,10 @@ @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) +distdir: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) distdir-am + +distdir-am: $(DISTFILES) @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ list='$(DISTFILES)'; \ @@ -1014,7 +1028,13 @@ mostlyclean-am distclean: distclean-am - -rm -rf ./$(DEPDIR) + -rm -f ./$(DEPDIR)/cxdeque-test.Po + -rm -f ./$(DEPDIR)/cxlist-test.Po + -rm -f ./$(DEPDIR)/cxmap-test.Po + -rm -f ./$(DEPDIR)/cxslist-test.Po + -rm -f ./$(DEPDIR)/cxstring-test.Po + -rm -f ./$(DEPDIR)/cxtree-test.Po + -rm -f ./$(DEPDIR)/cxtypes-test.Po -rm -f Makefile distclean-am: clean-am distclean-compile distclean-generic \ distclean-tags @@ -1060,7 +1080,13 @@ installcheck-am: maintainer-clean: maintainer-clean-am - -rm -rf ./$(DEPDIR) + -rm -f ./$(DEPDIR)/cxdeque-test.Po + -rm -f ./$(DEPDIR)/cxlist-test.Po + -rm -f ./$(DEPDIR)/cxmap-test.Po + -rm -f ./$(DEPDIR)/cxslist-test.Po + -rm -f ./$(DEPDIR)/cxstring-test.Po + -rm -f ./$(DEPDIR)/cxtree-test.Po + -rm -f ./$(DEPDIR)/cxtypes-test.Po -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic @@ -1081,19 +1107,20 @@ .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 +.PHONY: CTAGS GTAGS TAGS all all-am am--depfiles 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 diff -Nru cpl-7.1.4+ds/libltdl/aclocal.m4 cpl-7.2.2+ds/libltdl/aclocal.m4 --- cpl-7.1.4+ds/libltdl/aclocal.m4 2021-05-07 12:10:00.000000000 +0000 +++ cpl-7.2.2+ds/libltdl/aclocal.m4 2022-04-29 14:56:24.000000000 +0000 @@ -1,6 +1,6 @@ -# generated automatically by aclocal 1.15.1 -*- Autoconf -*- +# generated automatically by aclocal 1.15 -*- Autoconf -*- -# Copyright (C) 1996-2017 Free Software Foundation, Inc. +# 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, @@ -20,7 +20,7 @@ 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-2017 Free Software Foundation, Inc. +# 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, @@ -35,7 +35,7 @@ [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.1], [], +m4_if([$1], [1.15], [], [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl ]) @@ -51,14 +51,14 @@ # 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.1])dnl +[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-2017 Free Software Foundation, Inc. +# 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, @@ -110,7 +110,7 @@ # AM_CONDITIONAL -*- Autoconf -*- -# Copyright (C) 1997-2017 Free Software Foundation, Inc. +# 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, @@ -141,7 +141,7 @@ Usually this means the macro was only invoked conditionally.]]) fi])]) -# Copyright (C) 1999-2017 Free Software Foundation, Inc. +# 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, @@ -332,7 +332,7 @@ # Generate code to set up dependency tracking. -*- Autoconf -*- -# Copyright (C) 1999-2017 Free Software Foundation, Inc. +# 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, @@ -408,7 +408,7 @@ # Do all the work for Automake. -*- Autoconf -*- -# Copyright (C) 1996-2017 Free Software Foundation, Inc. +# 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, @@ -605,7 +605,7 @@ done echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count]) -# Copyright (C) 2001-2017 Free Software Foundation, Inc. +# 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, @@ -626,7 +626,7 @@ fi AC_SUBST([install_sh])]) -# Copyright (C) 2003-2017 Free Software Foundation, Inc. +# 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, @@ -647,7 +647,7 @@ # Check to see how 'make' treats includes. -*- Autoconf -*- -# Copyright (C) 2001-2017 Free Software Foundation, Inc. +# 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, @@ -697,7 +697,7 @@ # Fake the existence of programs that GNU maintainers use. -*- Autoconf -*- -# Copyright (C) 1997-2017 Free Software Foundation, Inc. +# 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, @@ -736,7 +736,7 @@ # Helper functions for option handling. -*- Autoconf -*- -# Copyright (C) 2001-2017 Free Software Foundation, Inc. +# 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, @@ -765,7 +765,7 @@ AC_DEFUN([_AM_IF_OPTION], [m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])]) -# Copyright (C) 1999-2017 Free Software Foundation, Inc. +# 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, @@ -812,7 +812,7 @@ # For backward compatibility. AC_DEFUN_ONCE([AM_PROG_CC_C_O], [AC_REQUIRE([AC_PROG_CC])]) -# Copyright (C) 2001-2017 Free Software Foundation, Inc. +# 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, @@ -831,7 +831,7 @@ # Check to make sure that the build environment is sane. -*- Autoconf -*- -# Copyright (C) 1996-2017 Free Software Foundation, Inc. +# 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, @@ -912,7 +912,7 @@ rm -f conftest.file ]) -# Copyright (C) 2009-2017 Free Software Foundation, Inc. +# 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, @@ -972,7 +972,7 @@ _AM_SUBST_NOTMAKE([AM_BACKSLASH])dnl ]) -# Copyright (C) 2001-2017 Free Software Foundation, Inc. +# 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, @@ -1000,7 +1000,7 @@ INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s" AC_SUBST([INSTALL_STRIP_PROGRAM])]) -# Copyright (C) 2006-2017 Free Software Foundation, Inc. +# 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, @@ -1019,7 +1019,7 @@ # Check how to create a tarball. -*- Autoconf -*- -# Copyright (C) 2004-2017 Free Software Foundation, Inc. +# 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, diff -Nru cpl-7.1.4+ds/libltdl/configure cpl-7.2.2+ds/libltdl/configure --- cpl-7.1.4+ds/libltdl/configure 2021-05-07 12:10:00.000000000 +0000 +++ cpl-7.2.2+ds/libltdl/configure 2022-04-29 14:56:24.000000000 +0000 @@ -14947,6 +14947,7 @@ 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. diff -Nru cpl-7.1.4+ds/libltdl/Makefile.in cpl-7.2.2+ds/libltdl/Makefile.in --- cpl-7.1.4+ds/libltdl/Makefile.in 2021-05-07 12:10:00.000000000 +0000 +++ cpl-7.2.2+ds/libltdl/Makefile.in 2022-04-29 14:56:24.000000000 +0000 @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.15.1 from Makefile.am. +# Makefile.in generated by automake 1.15 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2017 Free Software Foundation, Inc. +# 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, @@ -935,7 +935,7 @@ ! -type d ! -perm -444 -exec $(install_sh) -c -m a+r {} {} \; \ || chmod -R a+r "$(distdir)" dist-gzip: distdir - tardir=$(distdir) && $(am__tar) | eval GZIP= gzip $(GZIP_ENV) -c >$(distdir).tar.gz + tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz $(am__post_remove_distdir) dist-bzip2: distdir @@ -961,7 +961,7 @@ @echo WARNING: "Support for shar distribution archives is" \ "deprecated." >&2 @echo WARNING: "It will be removed altogether in Automake 2.0" >&2 - shar $(distdir) | eval GZIP= gzip $(GZIP_ENV) -c >$(distdir).shar.gz + shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz $(am__post_remove_distdir) dist-zip: distdir @@ -979,7 +979,7 @@ distcheck: dist case '$(DIST_ARCHIVES)' in \ *.tar.gz*) \ - eval GZIP= gzip $(GZIP_ENV) -dc $(distdir).tar.gz | $(am__untar) ;;\ + GZIP=$(GZIP_ENV) gzip -dc $(distdir).tar.gz | $(am__untar) ;;\ *.tar.bz2*) \ bzip2 -dc $(distdir).tar.bz2 | $(am__untar) ;;\ *.tar.lz*) \ @@ -989,7 +989,7 @@ *.tar.Z*) \ uncompress -c $(distdir).tar.Z | $(am__untar) ;;\ *.shar.gz*) \ - eval GZIP= gzip $(GZIP_ENV) -dc $(distdir).shar.gz | unshar ;;\ + GZIP=$(GZIP_ENV) gzip -dc $(distdir).shar.gz | unshar ;;\ *.zip*) \ unzip $(distdir).zip ;;\ esac diff -Nru cpl-7.1.4+ds/m4/cpl.m4 cpl-7.2.2+ds/m4/cpl.m4 --- cpl-7.1.4+ds/m4/cpl.m4 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/m4/cpl.m4 2022-04-29 14:56:02.000000000 +0000 @@ -220,6 +220,12 @@ AC_DEFINE_UNQUOTED([CPL_CFITSIO_VERSION], [$cpl_cfitsio_version_found], [used version of CFITSIO]) + AC_DEFINE_UNQUOTED([CPL_CFITSIO_MAJOR], + [$cpl_cfitsio_major], + [major version of CFITSIO]) + AC_DEFINE_UNQUOTED([CPL_CFITSIO_MINOR], + [$cpl_cfitsio_minor], + [minor version of CFITSIO]) AC_MSG_RESULT([$cpl_cfitsio_version_found]) fi @@ -1414,17 +1420,20 @@ LIBCPLDRS='-lcpldrs' LIBCPLUI='-lcplui' LIBCPLDFS='-lcpldfs' + LIBCPLGASGANO='-lcplgasgano' else LIBCPLCORE='$(top_builddir)/cplcore/libcplcore.la' LIBCPLDRS='$(top_builddir)/cpldrs/libcpldrs.la' LIBCPLUI='$(top_builddir)/cplui/libcplui.la' LIBCPLDFS='$(top_builddir)/cpldfs/libcpldfs.la' + LIBCPLGASGANO='$(top_builddir)/cpljava/libcplgasgano.la' fi AC_SUBST(LIBCPLCORE) AC_SUBST(LIBCPLDRS) AC_SUBST(LIBCPLUI) AC_SUBST(LIBCPLDFS) + AC_SUBST(LIBCPLGASGANO) ]) diff -Nru cpl-7.1.4+ds/Makefile.am cpl-7.2.2+ds/Makefile.am --- cpl-7.1.4+ds/Makefile.am 2021-05-07 12:09:09.000000000 +0000 +++ cpl-7.2.2+ds/Makefile.am 2022-04-29 14:56:02.000000000 +0000 @@ -1,7 +1,7 @@ ## Process this file with automake to produce Makefile.in ## This file is part of the ESO Common Pipeline Library -## Copyright (C) 2001-2017 European Southern Observatory +## Copyright (C) 2001-2022 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 diff -Nru cpl-7.1.4+ds/Makefile.in cpl-7.2.2+ds/Makefile.in --- cpl-7.1.4+ds/Makefile.in 2021-05-07 12:10:10.000000000 +0000 +++ cpl-7.2.2+ds/Makefile.in 2022-04-29 14:56:28.000000000 +0000 @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.15.1 from Makefile.am. +# Makefile.in generated by automake 1.16.3 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2017 Free Software Foundation, Inc. +# Copyright (C) 1994-2020 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -169,9 +169,9 @@ $(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 + cscope distdir distdir-am 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. @@ -239,6 +239,8 @@ DIST_ARCHIVES = $(distdir).tar.gz GZIP_ENV = --best DIST_TARGETS = dist-gzip +# Exists only to be overridden by the user if desired. +AM_DISTCHECK_DVI_TARGET = dvi distuninstallcheck_listfiles = find . -type f -print am__distuninstallcheck_listfiles = $(distuninstallcheck_listfiles) \ | sed 's|^\./|$(prefix)/|' | grep -v '$(infodir)/dir$$' @@ -261,6 +263,7 @@ CPLCORE_INCLUDES = @CPLCORE_INCLUDES@ CPLDFS_INCLUDES = @CPLDFS_INCLUDES@ CPLDRS_INCLUDES = @CPLDRS_INCLUDES@ +CPLJAVA_INCLUDES = @CPLJAVA_INCLUDES@ CPLUI_INCLUDES = @CPLUI_INCLUDES@ CPL_BINARY_AGE = @CPL_BINARY_AGE@ CPL_BINARY_VERSION = @CPL_BINARY_VERSION@ @@ -321,6 +324,7 @@ LIBCPLCORE = @LIBCPLCORE@ LIBCPLDFS = @LIBCPLDFS@ LIBCPLDRS = @LIBCPLDRS@ +LIBCPLGASGANO = @LIBCPLGASGANO@ LIBCPLUI = @LIBCPLUI@ LIBFFTW = @LIBFFTW@ LIBFFTWF = @LIBFFTWF@ @@ -427,6 +431,7 @@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ @@ -482,8 +487,8 @@ 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);; \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__maybe_remake_depfiles)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__maybe_remake_depfiles);; \ esac; $(top_srcdir)/admin/doxygen.am $(am__empty): @@ -650,7 +655,10 @@ -rm -f cscope.out cscope.in.out cscope.po.out cscope.files @MAINTAINER_MODE_FALSE@dist-hook: -distdir: $(DISTFILES) +distdir: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) distdir-am + +distdir-am: $(DISTFILES) $(am__remove_distdir) test -d "$(distdir)" || mkdir "$(distdir)" @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ @@ -733,6 +741,10 @@ tardir=$(distdir) && $(am__tar) | XZ_OPT=$${XZ_OPT--e} xz -c >$(distdir).tar.xz $(am__post_remove_distdir) +dist-zstd: distdir + tardir=$(distdir) && $(am__tar) | zstd -c $${ZSTD_CLEVEL-$${ZSTD_OPT--19}} >$(distdir).tar.zst + $(am__post_remove_distdir) + dist-tarZ: distdir @echo WARNING: "Support for distribution archives compressed with" \ "legacy program 'compress' is deprecated." >&2 @@ -775,6 +787,8 @@ eval GZIP= gzip $(GZIP_ENV) -dc $(distdir).shar.gz | unshar ;;\ *.zip*) \ unzip $(distdir).zip ;;\ + *.tar.zst*) \ + zstd -dc $(distdir).tar.zst | $(am__untar) ;;\ esac chmod -R a-w $(distdir) chmod u+w $(distdir) @@ -790,7 +804,7 @@ $(DISTCHECK_CONFIGURE_FLAGS) \ --srcdir=../.. --prefix="$$dc_install_base" \ && $(MAKE) $(AM_MAKEFLAGS) \ - && $(MAKE) $(AM_MAKEFLAGS) dvi \ + && $(MAKE) $(AM_MAKEFLAGS) $(AM_DISTCHECK_DVI_TARGET) \ && $(MAKE) $(AM_MAKEFLAGS) check \ && $(MAKE) $(AM_MAKEFLAGS) install \ && $(MAKE) $(AM_MAKEFLAGS) installcheck \ @@ -957,8 +971,8 @@ am--refresh check check-am clean clean-cscope clean-generic \ clean-libtool clean-local cscope cscopelist-am ctags ctags-am \ dist dist-all dist-bzip2 dist-gzip dist-hook dist-lzip \ - dist-shar dist-tarZ dist-xz dist-zip distcheck distclean \ - distclean-generic distclean-hdr distclean-libtool \ + dist-shar dist-tarZ dist-xz dist-zip dist-zstd distcheck \ + distclean 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 \ @@ -990,7 +1004,7 @@ @MAINTAINER_MODE_TRUE@doxygen: doxygen-am -@MAINTAINER_MODE_TRUE@doxygen-am: +@MAINTAINER_MODE_TRUE@doxygen-am: Doxyfile @MAINTAINER_MODE_TRUE@ @if test -f $(DOXYGEN_BUILD_DIR)/Doxyfile; then \ @MAINTAINER_MODE_TRUE@ echo "cd $(DOXYGEN_BUILD_DIR) && $(DOXYGEN)"; \ @MAINTAINER_MODE_TRUE@ d=`pwd`; cd $(DOXYGEN_BUILD_DIR) && $(DOXYGEN); cd $$d; \ @@ -1013,9 +1027,16 @@ @$(NORMAL_INSTALL) @if test -d $(DOXYGEN_BUILD_DIR)/html; then \ echo "$(mkinstalldirs) $(DESTDIR)$(apidocdir)"; \ - $(mkinstalldirs) $(DESTDIR)$(apidocdir); \ - list="`ls -1 $(DOXYGEN_BUILD_DIR)/html`"; \ - for p in $$list; do \ + $(mkinstalldirs) $(DESTDIR)$(apidocdir) || exit 1; \ + basedirstrip=`echo "$(DOXYGEN_BUILD_DIR)/html" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list="`find $(DOXYGEN_BUILD_DIR)/html -type f`"; \ + docfiles="`for f in $$list; do echo $$f; done | sed -e \"s|^$$basedirstrip/||;t\"`"; \ + case $$docfiles in \ + */*) $(mkinstalldirs) `echo "$$docfiles" | \ + sed '/\//!d;s|^|$(DESTDIR)$(apidocdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for p in $$docfiles; do \ if test -f $(DOXYGEN_BUILD_DIR)/html/$$p; then \ echo " $(INSTALL_DATA) $(DOXYGEN_BUILD_DIR)/html/$$p $(DESTDIR)$(apidocdir)/$$p"; \ $(INSTALL_DATA) $(DOXYGEN_BUILD_DIR)/html/$$p $(DESTDIR)$(apidocdir)/$$p; \ @@ -1028,11 +1049,20 @@ uninstall-doxygen: @$(NORMAL_UNINSTALL) - @list="`ls -1 $(DESTDIR)$(apidocdir)`"; \ - for p in $$list; do \ - echo " rm -f $(DESTDIR)$(apidocdir)/$$p"; \ - rm -f $(DESTDIR)$(apidocdir)/$$p; \ - done + @if test -d $(DESTDIR)$(apidocdir); then \ + list="`ls -1 $(DESTDIR)$(apidocdir)`"; \ + for p in $$list; do \ + if test -d $(DESTDIR)$(apidocdir)/$$p; then \ + echo " rm -rf $(DESTDIR)$(apidocdir)/$$p"; \ + rm -rf $(DESTDIR)$(apidocdir)/$$p; \ + else \ + echo " rm -f $(DESTDIR)$(apidocdir)/$$p"; \ + rm -f $(DESTDIR)$(apidocdir)/$$p; \ + fi; \ + done; \ + else \ + echo "Nothing to be done for \`$@'."; \ + fi $(DOXYGEN_RECURSIVE_TARGETS): @set fnord $(MAKEFLAGS); amf=$$2; \ diff -Nru cpl-7.1.4+ds/NEWS cpl-7.2.2+ds/NEWS --- cpl-7.1.4+ds/NEWS 2021-05-07 12:09:09.000000000 +0000 +++ cpl-7.2.2+ds/NEWS 2022-04-29 14:56:01.000000000 +0000 @@ -1,3 +1,38 @@ +What's new in CPL 7.2.2 +======================= + - Make build system version check work for cfitsio 4.1.0. + - cpl_propertylist_save(): Fixed a memory error when an integer type property + is too long to fit in a FITS card. + - cpl_geom_img_offset_combine(): Fixed a documentation bug +What's new in CPL 7.2.1 +======================= + - Fixed possible memory corruption in cpl_dfs_setup_product_header(). + - Add missing language linkage specification in the cpl_wlcalib module. +What's new in CPL 7.2 +===================== + - New interfaces added: + cpl_parameter_new_enum_from_array() + cpl_matrix_solve_svd_threshold() + cpl_polynomial_eval_2d() + cpl_polynomial_eval_3d() + - Support for trivariate polynomials was added to the function + cpl_polynomial_fit() + - cpl_polynomials_fit() takes into account uncertainties of the + sample values if they are provided. +What's new in CPL 7.1.5 +======================= + - Added FITS keyword HDRVER to the list of forbidden keywords when generating + products using cpl_dfs_setup_product_header(). + - Translate the FITS keyword RADECSYS to RADESYS to comply with ESO data + standards when creating data product headers using + cpl_dfs_setup_product_header() + - Fixed memory leak in cpl_fit_lvmq() + - Fixed various compiler warnings reported by recent gcc versions + - Remove misleading message on missing flop counting support introduced in + CPL 7.1.4 from the CPL feature/dependencies description. + - Improved doxygen documentation (added search box, fixed missing + documentation of the cpl_ppm module, changes to cpl_image_move(), + cpl_mask_move(), title page) What's new in CPL 7.1.4 ======================= - Require C99 complex arithmetic when building CPL. Fail at configuration diff -Nru cpl-7.1.4+ds/README cpl-7.2.2+ds/README --- cpl-7.1.4+ds/README 2021-05-07 12:09:08.000000000 +0000 +++ cpl-7.2.2+ds/README 2022-04-29 14:56:01.000000000 +0000 @@ -17,7 +17,7 @@ About CPL --------- -This is version 7.1.4 of the ESO Common Pipeline libraries (CPL). +This is version 7.2.2 of the ESO Common Pipeline libraries (CPL). This package includes libraries that are central to the development and execution of pipeline recipes as they are operated by ESO for all VLT