diff --git a/Makefile.in b/Makefile.in
index e675f1d61b146abb7ec0d3180ce999eaa5e1d32a..7c684baa03c9c226948d88a3a4e63f0fc1820e9d 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -89,7 +89,8 @@ build_triplet = @build@
 host_triplet = @host@
 subdir = .
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/m4/acx_fc_module.m4 \
+am__aclocal_m4_deps = $(top_srcdir)/m4/acx_fc_line_length.m4 \
+	$(top_srcdir)/m4/acx_fc_module.m4 \
 	$(top_srcdir)/m4/acx_fc_pp.m4 $(top_srcdir)/m4/acx_lang_lib.m4 \
 	$(top_srcdir)/m4/acx_lang_openmp.m4 \
 	$(top_srcdir)/m4/acx_lang_package.m4 \
diff --git a/aclocal.m4 b/aclocal.m4
index 235baa61dbbc6685caa53c7ee062c0f3949f6ce6..ba2d4f7311961d1aafd0c7e4ec9e34a02ff310d2 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -1545,6 +1545,7 @@ AC_SUBST([am__tar])
 AC_SUBST([am__untar])
 ]) # _AM_PROG_TAR
 
+m4_include([m4/acx_fc_line_length.m4])
 m4_include([m4/acx_fc_module.m4])
 m4_include([m4/acx_fc_pp.m4])
 m4_include([m4/acx_lang_lib.m4])
diff --git a/configure b/configure
index b33f04dc2848616c02f916c75f180c1504ba5be4..a106cd8e2eca6ed01ed805dd2ca681706f4fa48f 100755
--- a/configure
+++ b/configure
@@ -16291,6 +16291,89 @@ else $as_nop
 fi
 
 
+               acx_fc_line_length_none_in_cache=no
+   if test ${acx_cv_fc_line_length_unlimited+y}
+then :
+  case $acx_cv_fc_line_length_unlimited in #(
+  none) :
+    acx_fc_line_length_none_in_cache=yes ;; #(
+  '') :
+    acx_cv_fc_line_length_unlimited=none ;; #(
+  *) :
+     ;;
+esac
+fi
+   acx_save_FCFLAGS=$FCFLAGS
+   ac_fc_line_len_string=unlimited
+	               ac_fc_line_len=0
+                       ac_fc_line_length_test='
+      subroutine longer_than_132(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,'\
+'arg9,arg10,arg11,arg12,arg13,arg14,arg15,arg16,arg17,arg18,arg19)'
+: ${ac_fc_line_len_string=$ac_fc_line_len}
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for Fortran flag needed to accept $ac_fc_line_len_string column source lines" >&5
+printf %s "checking for Fortran flag needed to accept $ac_fc_line_len_string column source lines... " >&6; }
+if test ${acx_cv_fc_line_length_unlimited+y}
+then :
+  printf %s "(cached) " >&6
+else $as_nop
+  acx_cv_fc_line_length_unlimited=unknown
+ac_fc_line_length_FCFLAGS_save=$FCFLAGS
+for ac_flag in none \
+	       -ffree-line-length-none -ffixed-line-length-none \
+	       -ffree-line-length-huge \
+	       -ffree-line-length-$ac_fc_line_len \
+	       -ffixed-line-length-$ac_fc_line_len \
+	       -qfixed=$ac_fc_line_len -Mextend \
+	       -$ac_fc_line_len -extend_source \
+	       -W$ac_fc_line_len -W +extend_source +es -wide --wide -w -e \
+               -f -Wf,-f -xline
+do
+  test "x$ac_flag" != xnone && FCFLAGS="$ac_fc_line_length_FCFLAGS_save $ac_flag"
+  cat > conftest.$ac_ext <<_ACEOF
+$ac_fc_line_length_test
+        implicit integer (a)
+      end subroutine
+_ACEOF
+if ac_fn_fc_try_compile "$LINENO"
+then :
+  acx_cv_fc_line_length_unlimited=$ac_flag; break
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
+done
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+FCFLAGS=$ac_fc_line_length_FCFLAGS_save
+
+fi
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $acx_cv_fc_line_length_unlimited" >&5
+printf "%s\n" "$acx_cv_fc_line_length_unlimited" >&6; }
+if test "x$acx_cv_fc_line_length_unlimited" = xunknown; then
+  :
+else
+  if test "x$acx_cv_fc_line_length_unlimited" != xnone; then
+    FCFLAGS="$FCFLAGS $acx_cv_fc_line_length_unlimited"
+  fi
+
+fi
+
+
+   FCFLAGS=$acx_save_FCFLAGS
+         if test "x$acx_cv_fc_line_length_unlimited$acx_fc_line_length_none_in_cache" = xnoneno
+then :
+  acx_cv_fc_line_length_unlimited=
+fi
+   if test "x$acx_cv_fc_line_length_unlimited" = xunknown
+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 $? "unable to detect Fortran compiler flag needed to accept unlimited column source lines
+See \`config.log' for more details" "$LINENO" 5; }
+else $as_nop
+  if test -n "$acx_cv_fc_line_length_unlimited"
+then :
+  as_fn_append FCFLAGS " $acx_cv_fc_line_length_unlimited"
+fi
+fi
+
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for Fortran compiler module file naming template" >&5
 printf %s "checking for Fortran compiler module file naming template... " >&6; }
    if test ${acx_cv_fc_module_naming_upper+y} && test ${acx_cv_fc_module_naming_ext+y}
diff --git a/configure.ac b/configure.ac
index b585065a4a422c61b54f95fbd650b4d539662ca4..531c814b9a6d406c71004483118973e1141d2678 100644
--- a/configure.ac
+++ b/configure.ac
@@ -38,6 +38,8 @@ dnl expand to ACX_FC_PP_SRCEXT:
 m4_pushdef([AC_FC_SRCEXT], [ACX_FC_PP_SRCEXT($@)])
 AC_FC_SRCEXT([f90])
 m4_popdef([AC_FC_SRCEXT])
+dnl Handle possibly long expansions of the preprocessor macro __FILE__:
+ACX_FC_LINE_LENGTH([unlimited])
 ACX_FC_MODULE_NAMING([AC_SUBST([FCMODEXT], ["$acx_cv_fc_module_naming_ext"])])
 AM_CONDITIONAL([FCMODUC], [test x"$acx_cv_fc_module_naming_upper" = xyes])
 ACX_FC_MODULE_IN_FLAG([AC_SUBST([FCMODINC], ["$acx_cv_fc_module_in_flag"])])
diff --git a/doc/Makefile.in b/doc/Makefile.in
index 4850eeb64a008a201e55a9010b5fc8ed650aa607..227648e429d85663bf25b01df9b3455aa601ca48 100644
--- a/doc/Makefile.in
+++ b/doc/Makefile.in
@@ -89,7 +89,8 @@ build_triplet = @build@
 host_triplet = @host@
 subdir = doc
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/m4/acx_fc_module.m4 \
+am__aclocal_m4_deps = $(top_srcdir)/m4/acx_fc_line_length.m4 \
+	$(top_srcdir)/m4/acx_fc_module.m4 \
 	$(top_srcdir)/m4/acx_fc_pp.m4 $(top_srcdir)/m4/acx_lang_lib.m4 \
 	$(top_srcdir)/m4/acx_lang_openmp.m4 \
 	$(top_srcdir)/m4/acx_lang_package.m4 \
diff --git a/examples/Makefile.in b/examples/Makefile.in
index adbcbd21dbad94463b2d44820b85c46c2420b6d1..67a2562af8f7c8c69ede521710da51ba3733540b 100644
--- a/examples/Makefile.in
+++ b/examples/Makefile.in
@@ -103,7 +103,8 @@ host_triplet = @host@
 @ENABLE_EXAMPLES_TRUE@	test_cf_timeaxis$(EXEEXT) uniq$(EXEEXT)
 subdir = examples
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/m4/acx_fc_module.m4 \
+am__aclocal_m4_deps = $(top_srcdir)/m4/acx_fc_line_length.m4 \
+	$(top_srcdir)/m4/acx_fc_module.m4 \
 	$(top_srcdir)/m4/acx_fc_pp.m4 $(top_srcdir)/m4/acx_lang_lib.m4 \
 	$(top_srcdir)/m4/acx_lang_openmp.m4 \
 	$(top_srcdir)/m4/acx_lang_package.m4 \
diff --git a/include/Makefile.in b/include/Makefile.in
index 8b83f157812db5e31ac926ecd40c8fb5328d39a4..6394297949be98fbb4a87621312a5107fa7fee09 100644
--- a/include/Makefile.in
+++ b/include/Makefile.in
@@ -90,7 +90,8 @@ build_triplet = @build@
 host_triplet = @host@
 subdir = include
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/m4/acx_fc_module.m4 \
+am__aclocal_m4_deps = $(top_srcdir)/m4/acx_fc_line_length.m4 \
+	$(top_srcdir)/m4/acx_fc_module.m4 \
 	$(top_srcdir)/m4/acx_fc_pp.m4 $(top_srcdir)/m4/acx_lang_lib.m4 \
 	$(top_srcdir)/m4/acx_lang_openmp.m4 \
 	$(top_srcdir)/m4/acx_lang_package.m4 \
diff --git a/m4/acx_fc_line_length.m4 b/m4/acx_fc_line_length.m4
new file mode 100644
index 0000000000000000000000000000000000000000..02569f5de82186286d72fc27d9190f65e51438c2
--- /dev/null
+++ b/m4/acx_fc_line_length.m4
@@ -0,0 +1,60 @@
+# ACX_FC_LINE_LENGTH([LENGTH = 132],
+#                    [ACTION-IF-SUCCESS = APPEND-FCFLAGS],
+#                    [ACTION-IF-FAILURE = FAILURE])
+# -----------------------------------------------------------------------------
+# Finds the Fortran compiler flag needed to accept lines of length LENGTH,
+# where LENGTH may be 80, 132 (default), or 'unlimited' for longer lines. The
+# result is either "unknown", or the actual compiler flag required to to accept
+# lines of length LENGTH.
+#
+# If successful, runs ACTION-IF-SUCCESS (defaults to appending the result to
+# FCFLAGS), otherwise runs ACTION-IF-FAILURE (defaults to failing with an error
+# message).
+#
+# The flag is cached in the acx_cv_fc_line_length_[]LENGTH.
+#
+# The implementation is based on the standard Autoconf macro AC_FC_LINE_LENGTH,
+# which is monkey-patched to reduce the number of LANG switches and to avoid
+# false negative results with the GFortran '-fimplicit-none' flag.
+#
+AC_DEFUN([ACX_FC_LINE_LENGTH],
+  [AC_LANG_ASSERT([Fortran])dnl
+dnl Fail instead of warning:
+   m4_bmatch(m4_default([$1], [132]),
+     [unlimited\|132\|80], [],
+     [m4_fatal([Invalid LENGTH argument for $0: '$1'])])dnl
+dnl Monkey-patch AC_FC_LINE_LENGTH:
+   m4_pushdef([acx_cache_var], [acx_cv_fc_line_length_$1])dnl
+   m4_pushdef([ac_cv_fc_line_length], [acx_cache_var])dnl
+   m4_pushdef([AC_FC_LINE_LENGTH],
+     m4_bpatsubsts(m4_dquote(m4_defn([AC_FC_LINE_LENGTH])),
+       [\$ac_fc_line_length_test$], [\&
+        implicit integer (a)],
+       [AC_LANG_P\(OP\|USH\)(\[?Fortran\]?)]))dnl
+dnl This macro does not have a special meaning for the value 'none'
+dnl but AC_FC_LINE_LENGTH does. To account for the difference, we need to know
+dnl whether 'none' came from the cache variable and set the cache variable to
+dnl 'none' if it is set to an empty string:
+   acx_fc_line_length_none_in_cache=no
+   AS_VAR_SET_IF([acx_cache_var],
+     [AS_CASE([$acx_cache_var],
+        [none], [acx_fc_line_length_none_in_cache=yes],
+        [''], [acx_cache_var=none])])
+dnl AC_FC_LINE_LENGTH changes the FCFLAGS, which we do not want:
+   acx_save_FCFLAGS=$FCFLAGS
+   m4_quote(AC_FC_LINE_LENGTH([$1], [], [:]))
+   FCFLAGS=$acx_save_FCFLAGS
+   m4_popdef([AC_FC_LINE_LENGTH])dnl
+   m4_popdef([ac_cv_fc_line_length])dnl
+dnl Set the cache variable to an empty string if the value 'none' was set by
+dnl AC_FC_LINE_LENGTH but not if the variable had it before the expansion:
+   AS_IF([test "x$acx_cache_var$acx_fc_line_length_none_in_cache" = xnoneno],
+     [acx_cache_var=])
+   AS_VAR_IF([acx_cache_var], [unknown],
+     [m4_default([$3],
+        [AC_MSG_FAILURE([unable to detect Fortran compiler flag needed to dnl
+accept m4_default([$1], [132]) column source lines])])],
+     [m4_default([$2],
+        [AS_IF([test -n "$acx_cache_var"],
+           [AS_VAR_APPEND([FCFLAGS], [" $acx_cache_var"])])])])
+   m4_popdef([acx_cache_var])])
diff --git a/src/Makefile.in b/src/Makefile.in
index dc50abb2d50e661bbdf92874b04c34f107b641b4..bc5f762518828c966e31875ebab26e8680e8b05c 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -107,7 +107,8 @@ host_triplet = @host@
 @ENABLE_OPENMP_TRUE@am__append_1 = $(FCMODINC). -Xcompiler $(OPENMP_FCFLAG)
 subdir = src
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/m4/acx_fc_module.m4 \
+am__aclocal_m4_deps = $(top_srcdir)/m4/acx_fc_line_length.m4 \
+	$(top_srcdir)/m4/acx_fc_module.m4 \
 	$(top_srcdir)/m4/acx_fc_pp.m4 $(top_srcdir)/m4/acx_lang_lib.m4 \
 	$(top_srcdir)/m4/acx_lang_openmp.m4 \
 	$(top_srcdir)/m4/acx_lang_package.m4 \
diff --git a/test/Makefile.in b/test/Makefile.in
index 2f7114fbbc2f6675b60d0e745d1668768fabbdaa..afc8ab890714bbbb7461495b76b0bd23e4bdd200 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -91,7 +91,8 @@ check_PROGRAMS = test_runner$(EXEEXT)
 TESTS = test_runner$(EXEEXT)
 subdir = test
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/m4/acx_fc_module.m4 \
+am__aclocal_m4_deps = $(top_srcdir)/m4/acx_fc_line_length.m4 \
+	$(top_srcdir)/m4/acx_fc_module.m4 \
 	$(top_srcdir)/m4/acx_fc_pp.m4 $(top_srcdir)/m4/acx_lang_lib.m4 \
 	$(top_srcdir)/m4/acx_lang_openmp.m4 \
 	$(top_srcdir)/m4/acx_lang_package.m4 \