Commit cf634ead authored by Oliver Heidmann's avatar Oliver Heidmann
Browse files

Merge branch 'develop' of git.mpimet.mpg.de:cdo into develop

parents 8e4dc5a2 6b56a440
2017-10-20 Uwe Schulzweida
* Ydaystat: don't adjust the output year if the last input year is incomplete (bug fix)
2017-10-08 Uwe Schulzweida
* changed type of nmiss to size_t
......
# Process this file with automake to produce Makefile.in
SUBDIRS = libcdi src contrib test/data test
SUBDIRS = libcdi src/lib/ncl src contrib test/data test
#
EXTRA_DIST=config/default OPERATORS doc/cdo.pdf doc/cdo_cmor.pdf doc/cdo_eca.pdf doc/cdo_magics.pdf doc/cdo_refcard.pdf cdo.spec README
#
......
......@@ -92,7 +92,9 @@ DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
$(top_srcdir)/config/missing \
$(top_srcdir)/config/tap-driver.sh
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/acx_options.m4 \
am__aclocal_m4_deps = $(top_srcdir)/m4/acx_cfortran_flags.m4 \
$(top_srcdir)/m4/acx_check_cfortran.m4 \
$(top_srcdir)/m4/acx_options.m4 \
$(top_srcdir)/m4/ax_cxx_compile_stdcxx.m4 \
$(top_srcdir)/m4/ax_cxx_compile_stdcxx_11.m4 \
$(top_srcdir)/m4/ax_pthread.m4 $(top_srcdir)/m4/libtool.m4 \
......@@ -256,7 +258,8 @@ ENABLE_NETCDF = @ENABLE_NETCDF@
ENABLE_SERVICE = @ENABLE_SERVICE@
ENABLE_THREADS = @ENABLE_THREADS@
EXEEXT = @EXEEXT@
FCFLAGS = @FCFLAGS@
F77 = @F77@
FFLAGS = @FFLAGS@
FGREP = @FGREP@
GREP = @GREP@
GRIB_API_INCLUDE = @GRIB_API_INCLUDE@
......@@ -333,6 +336,7 @@ ac_ct_AR = @ac_ct_AR@
ac_ct_CC = @ac_ct_CC@
ac_ct_CXX = @ac_ct_CXX@
ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
ac_ct_F77 = @ac_ct_F77@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
......@@ -382,7 +386,7 @@ top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
# Process this file with automake to produce Makefile.in
SUBDIRS = libcdi src contrib test/data test
SUBDIRS = libcdi src/lib/ncl src contrib test/data test
#
EXTRA_DIST = config/default OPERATORS doc/cdo.pdf doc/cdo_cmor.pdf doc/cdo_eca.pdf doc/cdo_magics.pdf doc/cdo_refcard.pdf cdo.spec README
#
......
......@@ -1243,6 +1243,8 @@ AC_SUBST([am__tar])
AC_SUBST([am__untar])
]) # _AM_PROG_TAR
m4_include([m4/acx_cfortran_flags.m4])
m4_include([m4/acx_check_cfortran.m4])
m4_include([m4/acx_options.m4])
m4_include([m4/ax_cxx_compile_stdcxx.m4])
m4_include([m4/ax_cxx_compile_stdcxx_11.m4])
......
......@@ -5,6 +5,8 @@
"CPPFLAGS" : "@CPPFLAGS@",
"CXXFLAGS" : "@CXXFLAGS@",
"CFLAGS" : "@CFLAGS@",
"F77" : "@F77@",
"FFLAGS" : "@FFLAGS@",
"LDFLAGS" : "@LDFLAGS@",
"LIBS" : "@LIBS@",
"FCFLAGS" : "@FCFLAGS@",
......
......@@ -128,6 +128,7 @@ case "${HOSTNAME}" in
${CONFPATH}configure --prefix=$HOME/local \
--enable-maintainer-mode \
$CDOLIBS LDFLAGS="-Wl,-rpath,$HOME/local/eccodes-2.3.0/lib" \
F77=gfortran FFLAGS="-g -O2" \
CXX=g++ CXXFLAGS="-g -pipe -Wall -W -Wfloat-equal -pedantic -O3 -fstack-protector" \
CC=gcc CFLAGS="-g -pipe -Wall -W -Wfloat-equal -pedantic -O3 -fstack-protector"
# --with-libxml2=/usr \
......@@ -232,6 +233,7 @@ case "${HOSTNAME}" in
--with-fftw3 \
$CDOLIBS \
LDFLAGS="-Wl,-rpath,/sw/rhel6-x64/eccodes/eccodes-2.3.0-gcc48/lib" \
F77=ifort FFLAGS="-g -O2" \
CXX=icpc CXXFLAGS="-g -Wall -O2 -qopt-report=5 -march=core-avx2" \
CC=icc CFLAGS="-g -Wall -O2 -qopt-report=5 -march=core-avx2"
elif test "$COMP" = pgi ; then
......@@ -245,6 +247,7 @@ case "${HOSTNAME}" in
--with-fftw3 \
$CDOLIBS \
LDFLAGS="-Wl,-rpath,/sw/rhel6-x64/eccodes/eccodes-2.3.0-gcc48/lib" \
F77=gfortran FFLAGS="-g -O2" \
CXX=g++ CXXFLAGS='-g -Wall -O3 -march=native -mavx2' \
CC=gcc CFLAGS='-g -Wall -O3 -march=native -mavx2'
fi
......
This diff is collapsed.
......@@ -34,6 +34,7 @@ AC_CHECK_TOOL([CXX],[g++],[:])
AC_PROG_CC_C99
AM_PROG_CC_C_O
AC_PROG_CXX
AC_PROG_F77
AC_C_RESTRICT
AX_CXX_COMPILE_STDCXX_11
AC_OPENMP
......@@ -51,6 +52,7 @@ AC_PROG_INSTALL
#
FC=no
export FC
#
# ----------------------------------------------------------------------
# Check large file support on 32 bit system
AC_SYS_LARGEFILE
......@@ -104,12 +106,21 @@ case "$CC" in
*) C_VERSION=`$CC -V 2>&1 | head -n 1 | grep -v error`;;
esac
case "$F77" in
pgf*) F77_VERSION=`$F77 -V | head -2 | tail -n 1`;;
gfortran*) F77_VERSION=`$F77 --version | head -n 1`;;
*) F77_VERSION=`$F77 -V 2>&1 | head -n 1 | grep -v error`;;
esac
if test -z "$CXX_VERSION" ; then CXX_VERSION="unknown"; fi;
AC_DEFINE_UNQUOTED(CXX_VERSION, ["$CXX_VERSION"], [CXX Compiler version])
if test -z "$C_VERSION" ; then C_VERSION="unknown"; fi;
AC_DEFINE_UNQUOTED(C_VERSION, ["$C_VERSION"], [C Compiler version])
if test -z "$F77_VERSION" ; then F77_VERSION="unknown"; fi;
AC_DEFINE_UNQUOTED(F77_VERSION, ["$F77_VERSION"], [F77 Compiler version])
# Checks for username, hostname and system type
USERNAME=$LOGNAME
if test -z "$USERNAME" ; then USERNAME=$USER; fi;
......@@ -165,6 +176,35 @@ CXXFLAGS="$CXXFLAGS ${OPENMP_CFLAGS}"
# Add configure options
ACX_OPTIONS
# ----------------------------------------------------------------------
# Create the Interface to Fortran77 routines via cfortran.h
AC_ARG_ENABLE([fortran],
[AS_HELP_STRING([--disable-fortran],
[Omit building of Fortran routines])],
[enable_fortran=${enableval}],[enable_fortran=yes])
AS_IF([test "x${enable_fortran}" = "xyes"], [
dnl ######################################################################
dnl Test whether cfortran.h works correctly
dnl ######################################################################
ACX_FIND_CFORTRAN_DEF
ACX_XLF_QEXTNAME_ADD_APPENDUS
AS_IF([test -n "$F77" -a X"$F77" != Xno],
[ACX_CHECK_CFORTRAN([$srcdir/src],
[AC_DEFINE([HAVE_CF_INTERFACE],[1],
[Defined to 1 if C / Fortran interface cfortran.h works])],
[AS_CASE([x"$acx_cv_cfortran_works"],
[x"error"],
[AC_MSG_NOTICE([Linking/Running with C EXTERNAL built with cfortran.h does not work!])],
[x"compiling with cfortran.h failed"],
[AC_MSG_NOTICE([Compilation with cfortran.h is not working!])],
[x"error compiling Fortran subroutine"],
[AC_MSG_NOTICE([compilation of simple Fortran source failed!])],
[AC_MSG_NOTICE([Unexpected error when linking C and Fortran via cfortran.h!])])
AC_MSG_NOTICE([Disabling cfortran.h bindings generation])
acx_cv_cfortran_works=no])])
])
AM_CONDITIONAL([USE_F77],[test -n "$F77" -a X"$F77" != Xno -a x"$acx_cv_cfortran_works" = xyes])
# ----------------------------------------------------------------------
# configure code from valgrind
......@@ -242,7 +282,7 @@ AM_CONDITIONAL(BUILD_AVX2_TESTS, test x$ac_have_as_avx2 = xyes)
# ----------------------------------------------------------------------
AC_SUBST([CXXFLAGS])
AC_SUBST([CPPFLAGS])
AC_SUBST([FCFLAGS])
AC_SUBST([FFLAGS])
AC_SUBST([CLDFLAGS])
AC_SUBST([CLIBS])
#AC_SUBST([INCLUDES])
......@@ -254,6 +294,8 @@ C_COMPILER="$CC $CFLAGS"
AC_DEFINE_UNQUOTED(C_COMPILER, ["$C_COMPILER"], [C Compiler])
CXX_COMPILER="$CXX $CXXFLAGS"
AC_DEFINE_UNQUOTED(CXX_COMPILER, ["$CXX_COMPILER"], [CXX Compiler])
F77_COMPILER="$F77 $FFLAGS"
AC_DEFINE_UNQUOTED(F77_COMPILER, ["$F77_COMPILER"], [F77 Compiler])
AC_REQUIRE_AUX_FILE([tap-driver.sh])
AC_PROG_AWK
......@@ -268,7 +310,7 @@ AC_CONFIG_FILES([test/Merstat.test test/Zonstat.test test/Mergetime.test],[chmod
AC_CONFIG_FILES([test/Afterburner.test test/Detrend.test test/Arithc.test test/Arith.test test/Expr.test],[chmod a+x "$ac_file"])
AC_CONFIG_FILES([test/Gradsdes.test test/Collgrid.test test/threads.test test/tsformat.test test/wildcard.test],[chmod a+x "$ac_file"])
AC_CONFIG_FILES([test/MapReduce.test test/Ninfo.test],[chmod a+x "$ac_file"])
AC_CONFIG_FILES([Makefile src/Makefile contrib/Makefile test/Makefile test/data/Makefile cdo.spec cdo.settings])
AC_CONFIG_FILES([Makefile src/lib/ncl/Makefile src/Makefile contrib/Makefile test/Makefile test/data/Makefile cdo.spec cdo.settings])
AC_OUTPUT
# ----------------------------------------------------------------------
......
......@@ -81,7 +81,9 @@ subdir = contrib
DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
$(top_srcdir)/config/mkinstalldirs COPYING
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/acx_options.m4 \
am__aclocal_m4_deps = $(top_srcdir)/m4/acx_cfortran_flags.m4 \
$(top_srcdir)/m4/acx_check_cfortran.m4 \
$(top_srcdir)/m4/acx_options.m4 \
$(top_srcdir)/m4/ax_cxx_compile_stdcxx.m4 \
$(top_srcdir)/m4/ax_cxx_compile_stdcxx_11.m4 \
$(top_srcdir)/m4/ax_pthread.m4 $(top_srcdir)/m4/libtool.m4 \
......@@ -166,7 +168,8 @@ ENABLE_NETCDF = @ENABLE_NETCDF@
ENABLE_SERVICE = @ENABLE_SERVICE@
ENABLE_THREADS = @ENABLE_THREADS@
EXEEXT = @EXEEXT@
FCFLAGS = @FCFLAGS@
F77 = @F77@
FFLAGS = @FFLAGS@
FGREP = @FGREP@
GREP = @GREP@
GRIB_API_INCLUDE = @GRIB_API_INCLUDE@
......@@ -243,6 +246,7 @@ ac_ct_AR = @ac_ct_AR@
ac_ct_CC = @ac_ct_CC@
ac_ct_CXX = @ac_ct_CXX@
ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
ac_ct_F77 = @ac_ct_F77@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
......
dnl acx_fc_c_link.m4 --- transform library c flags into version
dnl that suits the fortran compiler
dnl
dnl Copyright (C) 2011 Thomas Jahns <jahns@dkrz.de>
dnl
dnl Version: 1.0
dnl Keywords:
dnl Author: Thomas Jahns <jahns@dkrz.de>
dnl Maintainer: Thomas Jahns <jahns@dkrz.de>
dnl URL: https://www.dkrz.de/redmine/projects/show/scales-ppm
dnl
dnl Redistribution and use in source and binary forms, with or without
dnl modification, are permitted provided that the following conditions are
dnl met:
dnl
dnl Redistributions of source code must retain the above copyright notice,
dnl this list of conditions and the following disclaimer.
dnl
dnl Redistributions in binary form must reproduce the above copyright
dnl notice, this list of conditions and the following disclaimer in the
dnl documentation and/or other materials provided with the distribution.
dnl
dnl Neither the name of the DKRZ GmbH nor the names of its contributors
dnl may be used to endorse or promote products derived from this software
dnl without specific prior written permission.
dnl
dnl THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
dnl IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
dnl TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
dnl PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
dnl OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
dnl EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
dnl PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
dnl PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
dnl LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
dnl NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
dnl SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dnl
dnl ACX_FC_XLF_QEXTNAME_ADD_APPENDUS
dnl Test if compiler is xlf and if -qextname is in use.
dnl Add -Dappendus to CPPFLAGS if the above applies.
dnl
AC_DEFUN([ACX_XLF_QEXTNAME_ADD_APPENDUS],
[AS_CASE([$host],
[*-ibm-aix*],
[AC_MSG_CHECKING([if -Dappendus needs to be added to CPPFLAGS for cfortran.h])
AS_IF([$CC -qversion 2>&1 | grep '^IBM XL C' >/dev/null],
[acx_temp_qextname_f77flags=`echo "$FFLAGS" | sed -n '/-qextname/{ s/^\(.* \)*-qextname\( .*\)*$/-qextname/;p;}'`
acx_temp_qextname_fcflags=`echo "$FCFLAGS" | sed -n '/-qextname/{ s/^\(.* \)*-qextname\( .*\)*$/-qextname/;p;}'`
dnl pretend the same option as for FC was used if F77 isn't used at all
dnl also in case a non-xl compiler is used it will append an underscore
AC_PROVIDE_IFELSE([AC_PROG_F77],,
[AC_PROVIDE_IFELSE([AC_PROG_FC],
[acx_temp_qextname_f77flags=$acx_temp_qextname_fcflags],
[m4_fatal([AC_PROG_F77 or AC_PROG_FC must have been invoked prior to ACX_XLF_QEXTNAME_ADD_APPENDUS])])])
dnl and vice versa for FC
AC_PROVIDE_IFELSE([AC_PROG_FC],
[AS_IF([$FC -qversion 2>&1 | grep '^IBM XL Fortran' >/dev/null],,
[acx_temp_qextname_fcflags=-qextname])],
[AC_PROVIDE_IFELSE([AC_PROG_F77],
[acx_temp_qextname_fcflags=$acx_temp_qextname_f77flags])])
AS_CASE([x"$acx_temp_qextname_fcflags$acx_temp_qextname_f77flags"],
[x-qextname],
[AC_MSG_ERROR([Option -qextname must be provided consistently to F77 and FC])],
[x-qextname-qextname],
[AC_MSG_RESULT([yes])
CPPFLAGS="${CPPFLAGS+$CPPFLAGS }-Dappendus"],
[AC_MSG_RESULT([no])])
],[AC_MSG_RESULT([no])])])])
dnl
dnl automate flag elicitation for cfortran.h
AC_DEFUN([_ACX_FIND_CFORTRAN_DEF],
[AC_REQUIRE([AC_CANONICAL_HOST])
_AC_FORTRAN_ASSERT
AC_LANG_CASE([Fortran],[save_FC=$FC ; acx_FC=$FC],
[Fortran 77],[save_F77=$F77 ; acx_FC=$F77])
AS_CASE([$host],
[x86_64-*-linux-*|i*86-*-linux-*|*-apple-darwin*|ia64-*-linux-*|x86_64-*-freebsd*|i*86-*-freebsd*],
[acx_temp=`$acx_FC -V 2>&1`
AS_IF([echo "$acx_temp" | grep '^Copyright.*\(The Portland Group\|NVIDIA CORPORATION\)' >/dev/null],
[AS_VAR_SET([acx_cf_flag],[-DgFortran])],
[echo "$acx_temp" | grep '^NAG Fortran Compiler Release' >/dev/null],
[AS_VAR_SET([acx_cf_flag],[-DNAGf90Fortran])],
[echo "$acx_temp" | grep '^Intel(R) Fortran.*Compiler' >/dev/null],
[AS_VAR_SET([acx_cf_flag],[-DgFortran])],
[echo "$acx_temp" | grep '^Cray Fortran' >/dev/null],
[AS_VAR_SET([acx_cf_flag],[-DgFortran])],
[acx_temp=`$acx_FC --version 2>&1` \
&& echo $acx_temp | grep '^GNU Fortran' >/dev/null],
[AS_IF([echo $acx_temp | grep g77 >/dev/null],
[AS_VAR_SET([acx_cf_flag],[-Dg77Fortran])],
[dnl assume gfortran
dnl check if compiling with f2c bindings or with default bindings
AS_IF([echo "]AC_LANG_CASE([Fortran],[$FCFLAGS],
[Fortran 77],[$FFLAGS])[" | grep '^\(.* \)*-ff2c\( .*\)*$' >/dev/null],
[AS_VAR_SET([acx_cf_flag],[-Df2cFortran])],
[AS_VAR_SET([acx_cf_flag],[-DgFortran])])])],
[acx_temp=`$acx_FC -v 2>&1` \
&& echo $acx_temp | grep '^f2c'],
[AS_VAR_SET([acx_cf_flag],[-Df2cFortran])])],
[*-ibm-aix*],
[dnl xlc set _IBMR2 so nothing needs to be done
AS_IF([$CC -qversion 2>&1 | grep '^IBM XL C' >/dev/null],,
[dnl but for other compilers set IBMR2Fortran
AS_VAR_SET([acx_cf_flag],[-DIBMR2Fortran])])
],
[*-*-hpux*],
[AS_VAR_SET([acx_cf_flag],[-DhpuxFortran])],
[sx*-*-*|es*-*-*],
[dnl fixme: make sure user is actually using sxf90
dnl but currently there is no alternative I know of
AS_VAR_SET([acx_cf_flag],[-DSXFortran])])])
AC_DEFUN([ACX_FIND_CFORTRAN_DEF],
[AC_CACHE_CHECK([C preprocessor flags for Fortran calling convention cfortran.h],
[acx_cv_cf_flag],
[acx_cv_cf_flag=''
dnl test if user already provided a flag
AS_FOR([MACRO],[macro],[pgiFortran NAGf90Fortran f2cFortran hpuxFortran apolloFortran sunFortran IBMR2Fortran CRAYFortran PATHSCALE_COMPILER gFortran mipsFortran DECFortran vmsFortran CONVEXFortran PowerStationFortran AbsoftUNIXFortran AbsoftProFortran SXFortran],
[acx_temp=`echo "$CPPFLAGS $CFLAGS" | sed -n 's/^\(.* \)*-D\('"MACRO"'\)\( .*\)*$/\2/;t print
b
: print
p'`
AS_IF([test x"$acx_temp" != x],
[AS_IF([test x"$acx_cv_cf_flag" = x],
[acx_cv_cf_flag="$acx_temp (user-specified)"],
[echo ; echo '"'"$acx_cv_cf_flag $acx_temp"'"'
AC_MSG_ERROR([Multiple specification of cfortran.h flags])])])])
dnl find automatically from machine/compiler
AS_IF([test x"$acx_cv_cf_flag" = x],
[AC_PROVIDE_IFELSE([AC_PROG_FC],
[AS_IF([test -n "$FC" -a X"$FC" != Xno],
[AC_LANG_PUSH([Fortran])
AS_VAR_PUSHDEF([acx_cf_flag],[acx_cv_]_AC_LANG_ABBREV[_cf_flag])
_ACX_FIND_CFORTRAN_DEF
AS_VAR_POPDEF([acx_cf_flag])
AC_LANG_POP([Fortran])])])
AC_PROVIDE_IFELSE([AC_PROG_F77],
[AS_IF([test -n "$F77" -a X"$F77" != Xno],
[AC_LANG_PUSH([Fortran 77])
AS_VAR_PUSHDEF([acx_cf_flag],[acx_cv_]_AC_LANG_ABBREV[_cf_flag])
_ACX_FIND_CFORTRAN_DEF
AS_VAR_POPDEF([acx_cf_flag])
AC_LANG_POP([Fortran 77])])])
dnl check f77 flag matches fc flag
AC_PROVIDE_IFELSE([AC_PROG_F77],
[AC_PROVIDE_IFELSE([AC_PROG_FC],
[dnl both FC and F77 are configured
AS_IF([test -z "$F77" -o X"$F77" = Xno],
[acx_cv_cf_flag="$acx_cv_fc_cf_flag (probed)"],
[test -z "$FC" -o X"$FC" = Xno],
[acx_cv_cf_flag="$acx_cv_f77_cf_flag (probed)"],
[AS_IF([test x"$acx_cv_f77_cf_flag" = x"$acx_cv_fc_cf_flag"],
[acx_cv_cf_flag="$acx_cv_f77_cf_flag (probed)"],
[AC_MSG_ERROR([cfortran.h flag for $F77 does not match the flag for $FC.
Have you configured compatible compilers?])])])
],
[acx_cv_cf_flag="$acx_cv_f77_cf_flag (probed)"])],
[acx_cv_cf_flag="$acx_cv_fc_cf_flag (probed)"])
])
])
dnl now that flag is established, add (probed) defines to CPPFLAGS
AS_IF([echo "$acx_cv_cf_flag" | grep ' (probed)$' >/dev/null],
[CPPFLAGS="${CPPFLAGS+$CPPFLAGS }`echo "$acx_cv_cf_flag" | sed 's/ (probed)$//'`"])
])
dnl
dnl Local Variables:
dnl mode: autoconf
dnl license-project-url: "https://www.dkrz.de/redmine/projects/show/scales-ppm"
dnl license-default: "bsd"
dnl End:
dnl acx_check_cfortran.m4 --- test if a program compiled from
dnl a main Fortran program and
dnl C functions gives expected results
dnl
dnl Copyright (C) 2013 Thomas Jahns <jahns@dkrz.de>
dnl
dnl Version: 1.0
dnl Keywords:
dnl Author: Thomas Jahns <jahns@dkrz.de>
dnl Maintainer: Thomas Jahns <jahns@dkrz.de>
dnl URL: https://www.dkrz.de/redmine/projects/show/scales-ppm
dnl
dnl Redistribution and use in source and binary forms, with or without
dnl modification, are permitted provided that the following conditions are
dnl met:
dnl
dnl Redistributions of source code must retain the above copyright notice,
dnl this list of conditions and the following disclaimer.
dnl
dnl Redistributions in binary form must reproduce the above copyright
dnl notice, this list of conditions and the following disclaimer in the
dnl documentation and/or other materials provided with the distribution.
dnl
dnl Neither the name of the DKRZ GmbH nor the names of its contributors
dnl may be used to endorse or promote products derived from this software
dnl without specific prior written permission.
dnl
dnl THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
dnl IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
dnl TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
dnl PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
dnl OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
dnl EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
dnl PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
dnl PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
dnl LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
dnl NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
dnl SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dnl
dnl helper function to emit Fortran test code
AC_DEFUN([_ACX_CHECK_CFORTRAN_FC],
[AC_LANG_PUSH([Fortran])
AC_COMPILE_IFELSE([AC_LANG_SOURCE(
[ MODULE conftest_data
IMPLICIT NONE
PRIVATE
REAL :: ri
PUBLIC :: ri
END MODULE conftest_data
FUNCTION cftstf(v) RESULT(r)
USE conftest_data, ONLY: ri
REAL, INTENT(in) :: v
REAL :: r
r = v * 100.0
ri = 1.0 / v
END FUNCTION cftstf])],
[_AC_RUN_LOG([mv "conftest.$ac_objext" "conftest_f.$ac_objext"],
[_AS_ECHO_LOG([Renaming Fortran object file.])])
save_LIBS=$LIBS
LIBS="conftest_c.$ac_objext conftest_f.$ac_objext $LIBS"
AC_RUN_IFELSE([AC_LANG_PROGRAM(,
[ USE conftest_data, ONLY: ri
IMPLICIT NONE
INTERFACE
FUNCTION cftstc(i, v, p, q) RESULT(f)
INTEGER, INTENT(in) :: i
REAL, INTENT(in) :: v
INTEGER, INTENT(out) :: p
REAL, INTENT(out) :: q
REAL :: f
END FUNCTION cftstc
FUNCTION chtst() result(s)
CHARACTER(99) :: s
END FUNCTION chtst
END INTERFACE
REAL, PARAMETER :: eps = 10e-6
REAL :: foo, boo, too
INTEGER :: bar, baz, i
CHARACTER(99) :: aaaaaa
bar = 5
foo = 0.3
too = cftstc(bar, foo, baz, boo)
IF (ABS(baz - NINT(bar * foo)) /= 0) THEN
WRITE (0, '(2(a,i0))') "error checking, when baz, baz=", baz, &
", NINT(bar * foo) =", NINT(bar * foo)
FLUSH(0)
CALL err_exit
END IF
IF (ABS((ri - 1.0 / (bar * foo)) / ABS(ri)) > eps) THEN
WRITE (0, '(2(a,g24.15))') "error checking ri, ri=", ri, ", 1.0 / &
&(bar * foo) = ", 1.0 / (bar * foo)
FLUSH(0)
CALL err_exit
END IF
IF (ABS((boo - (bar * foo * 100.0))/ABS(boo)) > eps) THEN
WRITE (0, '(2(a,g24.15))') "error checking boo, boo=", boo, &
", bar * foo * 100.0 = ", bar * foo * 100.0
FLUSH(0)
CALL err_exit
END IF
IF (too /= boo) THEN
WRITE (0, '(2(a,g24.15))') "error checking too vs. boo, too=", too, &
", boo = ", boo
FLUSH(0)
CALL err_exit
END IF
aaaaaa = chtst()
DO i = 1, 99
IF (aaaaaa(i:i) /= 'A') THEN
WRITE (0, '(a,i0,a)') "error checking aaaaaa(", i, ")=", &
aaaaaa(i:i)
FLUSH(0)
CALL err_exit
END IF
END DO])],
[acx_cv_cfortran_works=yes],
[acx_cv_cfortran_works="error"],
[AC_MSG_NOTICE([Skipping run test for cfortran.h in cross-compilation mode,])
AC_MSG_NOTICE([link test succeeded.])
acx_cv_cfortran_works=yes])
LIBS=$save_LIBS],
[acx_cv_cfortran_works="error compiling Fortran subroutine"])
AC_LANG_POP([Fortran])])
dnl helper function to emit Fortran 77 test code
AC_DEFUN([_ACX_CHECK_CFORTRAN_F77],
[AC_LANG_PUSH([Fortran 77])
AC_COMPILE_IFELSE([AC_LANG_SOURCE(
[ REAL FUNCTION CFTSTF(v)
REAL RI
COMMON /CFTSTD/ RI
REAL V
REAL R
CFTSTF = V * 100.0
RI = 1.0 / V
END FUNCTION CFTSTF])],
[_AC_RUN_LOG([mv "conftest.$ac_objext" "conftest_f.$ac_objext"],
[_AS_ECHO_LOG([Renaming Fortran object file.])])
save_LIBS=$LIBS
LIBS="conftest_c.$ac_objext conftest_f.$ac_objext $LIBS"
AC_RUN_IFELSE([AC_LANG_PROGRAM(,
[ REAL RI
COMMON /CFTSTD/ RI
REAL EPS
PARAMETER(EPS=10E-6)
REAL FOO, BOO, TOO
INTEGER BAR, BAZ, I
CHARACTER(99) AAAAAA
EXTERNAL CFTSTC, CFTSTF, CHTST, ERR_EXIT
REAL CFTSTC, CFTSTF
CHARACTER(99) CHTST
BAR = 5
FOO = 0.3
TOO = CFTSTC(BAR, FOO, BAZ, BOO)
IF (ABS(BAZ - NINT(BAR * FOO)) /= 0) THEN
WRITE (0, '(2(A,I0))') "ERROR CHECKING, WHEN BAZ, BAZ=", BAZ,
& ", NINT(BAR * FOO) =", NINT(BAR * FOO)
CALL ERR_EXIT
END IF
IF (ABS((RI - 1.0 / (BAR * FOO)) / ABS(RI)) > EPS) THEN
WRITE (0, '(2(A,F24.15))') "ERROR CHECKING RI, RI=", RI, ",
& 1.0 / (BAR * FOO) = ", 1.0 / (BAR * FOO)
CALL err_exit
END IF
IF (ABS((BOO - (BAR * FOO * 100.0))/ABS(BOO)) > EPS) THEN
WRITE (0, '(2(A,F24.15))') "ERROR CHECKING BOO, BOO=", BOO,
& ", BAR * FOO * 100.0 = ", BAR * FOO * 100.0
CALL ERR_EXIT
END IF
IF (TOO /= BOO) THEN
WRITE (0, '(2(A,F24.15))') "ERROR CHECKING TOO VS. BOO, TOO=",
& TOO, ", BOO = ", BOO
CALL ERR_EXIT
END IF
AAAAAA = CHTST()
DO i = 1, 99
IF (AAAAAA(I:I) /= 'A') THEN
WRITE (0, '(A,I0,2A)') "ERROR CHECKING AAAAAA(", I, ")=",
& AAAAAA(I:I)
CALL ERR_EXIT
END IF
END DO])],
[acx_cv_cfortran_works=yes],
[acx_cv_cfortran_works="error"],
[AC_MSG_NOTICE([Skipping run test for cfortran.h in cross-compilation mode,])
AC_MSG_NOTICE([link test succeeded.])
acx_cv_cfortran_works=yes])
LIBS=$save_LIBS],
[acx_cv_cfortran_works="error compiling Fortran subroutine"])
AC_LANG_POP([Fortran 77])])
dnl ACX_CHECK_CFORTRAN([OPTIONAL-CFORTRAN-INC-DIR],[ACTION-IF-SUCCESS],
dnl [ACTION-IF-FAILED])
dnl Test if C compiler can produce objects that link fine to Fortran programs
dnl when using cfortran.h.
dnl
AC_DEFUN([ACX_CHECK_CFORTRAN],
[AC_CACHE_CHECK([if C externals constructed with cfortran.h work],
[acx_cv_cfortran_works],
[acx_cv_cfortran_works=no
save_CPPFLAGS=$CPPFLAGS
CPPFLAGS="-I]m4_ifval([$1],[$1],[$srcdir/include])[ $CPPFLAGS"
dnl build C function
AC_LANG_PUSH([C])
AC_COMPILE_IFELSE([AC_LANG_SOURCE([@%:@include "cfortran.h"
@%:@include <math.h>
@%:@include <stdio.h>
@%:@include <stdlib.h>
PROTOCCALLSFFUN1(FLOAT,CFTSTF,cftstf,FLOAT)
#define conftest_F(v) \
CCALLSFFUN1(CFTSTF,cftstf,FLOAT,(v));
static float
cftstC(int i, float v, int *p, float *q)
{
float f;
*p = (int)roundf(v * i);
*q = f = conftest_F(v * i);
return f;
}
FCALLSCFUN4(FLOAT,cftstC,CFTSTC,cftstc,INT,FLOAT,PINT,PFLOAT)
/* test string returns */
static const char *
conftest_str_C(void)
{
static const char msg@<:@100@:>@ = "AAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
return msg;
}
FCALLSCFUN0(STRING,conftest_str_C,CHTST,chtst)
/* This function is required simply because some Fortran compilers
* won't stop with exit code n when encountering STOP n */
static void
errExit(void)
{
exit(1);
}
FCALLSCSUB0(errExit,ERR_EXIT,err_exit)
])],
[_AC_RUN_LOG([mv "conftest.$ac_objext" "conftest_c.$ac_objext"],
[_AS_ECHO_LOG([Renaming C object file.])])
AC_PROVIDE_IFELSE([AC_PROG_FC],[_ACX_CHECK_CFORTRAN_FC])
AC_PROVIDE_IFELSE([AC_PROG_F77],[_ACX_CHECK_CFORTRAN_F77])
],