[cig-commits] r22798 - in seismo/3D/SPECFEM3D/trunk: . DATA DATA/meshfem3D_files src/generate_databases src/meshfem3D src/shared src/specfem3D

lefebvre at geodynamics.org lefebvre at geodynamics.org
Wed Sep 18 07:35:14 PDT 2013


Author: lefebvre
Date: 2013-09-18 07:35:14 -0700 (Wed, 18 Sep 2013)
New Revision: 22798

Added:
   seismo/3D/SPECFEM3D/trunk/.gitignore
   seismo/3D/SPECFEM3D/trunk/src/generate_databases/generate_databases_adios_stubs.f90
   seismo/3D/SPECFEM3D/trunk/src/generate_databases/model_gll_adios.F90
   seismo/3D/SPECFEM3D/trunk/src/generate_databases/model_ipati_adios.F90
   seismo/3D/SPECFEM3D/trunk/src/generate_databases/read_partition_files_adios.F90
   seismo/3D/SPECFEM3D/trunk/src/generate_databases/save_arrays_solver_adios.F90
   seismo/3D/SPECFEM3D/trunk/src/generate_databases/save_moho_adios.F90
   seismo/3D/SPECFEM3D/trunk/src/meshfem3D/meshfem3D_adios_stubs.f90
   seismo/3D/SPECFEM3D/trunk/src/meshfem3D/save_databases_adios.F90
   seismo/3D/SPECFEM3D/trunk/src/shared/adios_helpers.f90
   seismo/3D/SPECFEM3D/trunk/src/shared/adios_helpers_definitions.f90
   seismo/3D/SPECFEM3D/trunk/src/shared/adios_helpers_writers.f90
   seismo/3D/SPECFEM3D/trunk/src/shared/adios_manager.F90
   seismo/3D/SPECFEM3D/trunk/src/shared/adios_manager_stubs.f90
   seismo/3D/SPECFEM3D/trunk/src/shared/safe_alloc_mod.f90
   seismo/3D/SPECFEM3D/trunk/src/specfem3D/read_mesh_databases.F90
   seismo/3D/SPECFEM3D/trunk/src/specfem3D/read_mesh_databases_adios.F90
   seismo/3D/SPECFEM3D/trunk/src/specfem3D/save_kernels_adios.F90
   seismo/3D/SPECFEM3D/trunk/src/specfem3D/specfem3D_adios_stubs.f90
Removed:
   seismo/3D/SPECFEM3D/trunk/src/specfem3D/read_mesh_databases.f90
Modified:
   seismo/3D/SPECFEM3D/trunk/DATA/CMTSOLUTION
   seismo/3D/SPECFEM3D/trunk/DATA/FORCESOLUTION
   seismo/3D/SPECFEM3D/trunk/DATA/Par_file
   seismo/3D/SPECFEM3D/trunk/DATA/STATIONS
   seismo/3D/SPECFEM3D/trunk/DATA/meshfem3D_files/Mesh_Par_file
   seismo/3D/SPECFEM3D/trunk/DATA/meshfem3D_files/interfaces.dat
   seismo/3D/SPECFEM3D/trunk/configure
   seismo/3D/SPECFEM3D/trunk/configure.ac
   seismo/3D/SPECFEM3D/trunk/src/generate_databases/Makefile.in
   seismo/3D/SPECFEM3D/trunk/src/generate_databases/create_regions_mesh.f90
   seismo/3D/SPECFEM3D/trunk/src/generate_databases/generate_databases.f90
   seismo/3D/SPECFEM3D/trunk/src/generate_databases/generate_databases_par.f90
   seismo/3D/SPECFEM3D/trunk/src/generate_databases/get_model.f90
   seismo/3D/SPECFEM3D/trunk/src/meshfem3D/Makefile.in
   seismo/3D/SPECFEM3D/trunk/src/meshfem3D/create_regions_mesh.f90
   seismo/3D/SPECFEM3D/trunk/src/meshfem3D/meshfem3D.f90
   seismo/3D/SPECFEM3D/trunk/src/shared/constants.h.in
   seismo/3D/SPECFEM3D/trunk/src/shared/read_parameter_file.f90
   seismo/3D/SPECFEM3D/trunk/src/specfem3D/Makefile.in
   seismo/3D/SPECFEM3D/trunk/src/specfem3D/finalize_simulation.f90
   seismo/3D/SPECFEM3D/trunk/src/specfem3D/initialize_simulation.f90
   seismo/3D/SPECFEM3D/trunk/src/specfem3D/save_adjoint_kernels.f90
   seismo/3D/SPECFEM3D/trunk/src/specfem3D/specfem3D.f90
   seismo/3D/SPECFEM3D/trunk/src/specfem3D/specfem3D_par.f90
Log:
Merge branch 'adios'. Merging problem solved.

Conflicts:
	flags.guess
	src/specfem3D/initialize_simulation.f90
	src/specfem3D/iterate_time.F90
	src/specfem3D/save_adjoint_kernels.f90

Added: seismo/3D/SPECFEM3D/trunk/.gitignore
===================================================================
--- seismo/3D/SPECFEM3D/trunk/.gitignore	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/.gitignore	2013-09-18 14:35:14 UTC (rev 22798)
@@ -0,0 +1,4 @@
+*o
+*mod
+.*swp
+.*swo

Modified: seismo/3D/SPECFEM3D/trunk/DATA/CMTSOLUTION
===================================================================
--- seismo/3D/SPECFEM3D/trunk/DATA/CMTSOLUTION	2013-09-17 22:36:21 UTC (rev 22797)
+++ seismo/3D/SPECFEM3D/trunk/DATA/CMTSOLUTION	2013-09-18 14:35:14 UTC (rev 22798)
@@ -2,9 +2,9 @@
 event name:       hom_explosion
 time shift:       0.0000
 half duration:    5.0
-latitude:       67000.0
-longitude:      67000.0
-depth:            25.0
+latitude:       33.6
+longitude:      -118.4
+depth:           10.0
 Mrr:       1.000000e+23
 Mtt:       1.000000e+23
 Mpp:       1.000000e+23

Modified: seismo/3D/SPECFEM3D/trunk/DATA/FORCESOLUTION
===================================================================
--- seismo/3D/SPECFEM3D/trunk/DATA/FORCESOLUTION	2013-09-17 22:36:21 UTC (rev 22797)
+++ seismo/3D/SPECFEM3D/trunk/DATA/FORCESOLUTION	2013-09-18 14:35:14 UTC (rev 22798)
@@ -1,9 +1,9 @@
 FORCE  001
 time shift:     0.0000
 hdur:           0.5
-latitude:       67000.0
-longitude:      67000.0
-depth:          25.0
+latitude:       33.6
+longitude:      -118.4
+depth:           10.0
 factor force source:             1.d15
 component dir vect source E:     1.d0
 component dir vect source N:     -2.d0

Modified: seismo/3D/SPECFEM3D/trunk/DATA/Par_file
===================================================================
--- seismo/3D/SPECFEM3D/trunk/DATA/Par_file	2013-09-17 22:36:21 UTC (rev 22797)
+++ seismo/3D/SPECFEM3D/trunk/DATA/Par_file	2013-09-18 14:35:14 UTC (rev 22798)
@@ -5,18 +5,18 @@
 SIMULATION_TYPE                 = 1
 # 0 = earthquake simulation,  1/2/3 = three steps in noise simulation
 NOISE_TOMOGRAPHY                = 0
-SAVE_FORWARD                    = .false.
+SAVE_FORWARD                    = .true.
 
 # UTM projection parameters
 UTM_PROJECTION_ZONE             = 11
-SUPPRESS_UTM_PROJECTION         = .true.
+SUPPRESS_UTM_PROJECTION         = .false.
 
 # number of MPI processors
 NPROC                           = 4
 
 # time step parameters
-NSTEP                           = 1000
-DT                              = 0.05d0
+NSTEP                           = 2000
+DT                              = 0.03
 
 # number of nodes for 2D and 3D shape functions for hexahedra
 # we use either 8-node mesh elements (bricks) or 27-node elements.
@@ -35,7 +35,7 @@
 MODEL                           = default
 
 # parameters describing the model
-APPROXIMATE_OCEAN_LOAD          = .false.
+APPROXIMATE_OCEAN_LOAD                          = .false.
 TOPOGRAPHY                      = .false.
 ATTENUATION                     = .false.
 FULL_ATTENUATION_SOLID          = .false.
@@ -50,7 +50,7 @@
 OLSEN_ATTENUATION_RATIO         = 0.05
 
 # C-PML boundary conditions for a regional simulation
-PML_CONDITIONS                  = .false.
+PML_CONDITIONS          = .false.
 
 # C-PML top surface
 PML_INSTEAD_OF_FREE_SURFACE     = .false.
@@ -58,14 +58,14 @@
 # C-PML dominant frequency
 f0_FOR_PML                      = 12.7
 
-# parameters used to rotate C-PML boundary conditions by a given angle (not implemented yet)
+# parameters used to rotate C-PML boundary conditions by a given angle (not completed yet)
 # ROTATE_PML_ACTIVATE           = .false.
 # ROTATE_PML_ANGLE              = 0.
 
-# Stacey absorbing boundary conditions for a regional simulation (obsolete, using CPML above is much better)
+# absorbing boundary conditions for a regional simulation
 STACEY_ABSORBING_CONDITIONS     = .false.
 
-# Stacey absorbing top surface (defined in mesh as 'free_surface_file') (obsolete, using CPML above is much better)
+# absorbing top surface (defined in mesh as 'free_surface_file')
 STACEY_INSTEAD_OF_FREE_SURFACE  = .false.
 
 # save AVS or OpenDX movies
@@ -81,13 +81,13 @@
 HDUR_MOVIE                      = 0.0
 
 # save AVS or OpenDX mesh files to check the mesh
-SAVE_MESH_FILES                 = .false.
+SAVE_MESH_FILES                 = .true.
 
 # path to store the local database file on each node
 LOCAL_PATH                      = ../OUTPUT_FILES/DATABASES_MPI
 
 # interval at which we output time step info and max of norm of displacement
-NTSTEP_BETWEEN_OUTPUT_INFO      = 500
+NTSTEP_BETWEEN_OUTPUT_INFO      = 100
 
 # interval in time steps for writing of seismograms
 NTSTEP_BETWEEN_OUTPUT_SEISMOS   = 10000
@@ -119,3 +119,8 @@
 # set to true to use GPUs
 GPU_MODE                        = .false.
 
+# ADIOS Options for I/Os
+ADIOS_ENABLED                   = .true.
+ADIOS_FOR_DATABASES             = .true.
+ADIOS_FOR_MESH                  = .true.
+ADIOS_FOR_KERNELS               = .true.

Modified: seismo/3D/SPECFEM3D/trunk/DATA/STATIONS
===================================================================
--- seismo/3D/SPECFEM3D/trunk/DATA/STATIONS	2013-09-17 22:36:21 UTC (rev 22797)
+++ seismo/3D/SPECFEM3D/trunk/DATA/STATIONS	2013-09-18 14:35:14 UTC (rev 22798)
@@ -1,57 +1,3 @@
-X1 DB 67000.00 0.000000 0.0 0.0
-X2 DB 67000.00 1196.429 0.0 0.0
-X3 DB 67000.00 2392.857 0.0 0.0
-X4 DB 67000.00 3589.286 0.0 0.0
-X5 DB 67000.00 4785.714 0.0 0.0
-X6 DB 67000.00 5982.143 0.0 0.0
-X7 DB 67000.00 7178.571 0.0 0.0
-X8 DB 67000.00 8375.000 0.0 0.0
-X9 DB 67000.00 9571.429 0.0 0.0
-X10 DB 67000.00 10767.86 0.0 0.0
-X11 DB 67000.00 11964.29 0.0 0.0
-X12 DB 67000.00 13160.71 0.0 0.0
-X13 DB 67000.00 14357.14 0.0 0.0
-X14 DB 67000.00 15553.57 0.0 0.0
-X15 DB 67000.00 16750.00 0.0 0.0
-X16 DB 67000.00 17946.43 0.0 0.0
-X17 DB 67000.00 19142.86 0.0 0.0
-X18 DB 67000.00 20339.29 0.0 0.0
-X19 DB 67000.00 21535.71 0.0 0.0
-X20 DB 67000.00 22732.14 0.0 0.0
-X21 DB 67000.00 23928.57 0.0 0.0
-X22 DB 67000.00 25125.00 0.0 0.0
-X23 DB 67000.00 26321.43 0.0 0.0
-X24 DB 67000.00 27517.86 0.0 0.0
-X25 DB 67000.00 28714.29 0.0 0.0
-X26 DB 67000.00 29910.71 0.0 0.0
-X27 DB 67000.00 31107.14 0.0 0.0
-X28 DB 67000.00 32303.57 0.0 0.0
-X29 DB 67000.00 33500.00 0.0 0.0
-X30 DB 67000.00 34696.43 0.0 0.0
-X31 DB 67000.00 35892.86 0.0 0.0
-X32 DB 67000.00 37089.29 0.0 0.0
-X33 DB 67000.00 38285.71 0.0 0.0
-X34 DB 67000.00 39482.14 0.0 0.0
-X35 DB 67000.00 40678.57 0.0 0.0
-X36 DB 67000.00 41875.00 0.0 0.0
-X37 DB 67000.00 43071.43 0.0 0.0
-X38 DB 67000.00 44267.86 0.0 0.0
-X39 DB 67000.00 45464.29 0.0 0.0
-X40 DB 67000.00 46660.71 0.0 0.0
-X41 DB 67000.00 47857.14 0.0 0.0
-X42 DB 67000.00 49053.57 0.0 0.0
-X43 DB 67000.00 50250.00 0.0 0.0
-X44 DB 67000.00 51446.43 0.0 0.0
-X45 DB 67000.00 52642.86 0.0 0.0
-X46 DB 67000.00 53839.29 0.0 0.0
-X47 DB 67000.00 55035.71 0.0 0.0
-X48 DB 67000.00 56232.14 0.0 0.0
-X49 DB 67000.00 57428.57 0.0 0.0
-X50 DB 67000.00 58625.00 0.0 0.0
-X51 DB 67000.00 59821.43 0.0 0.0
-X52 DB 67000.00 61017.86 0.0 0.0
-X53 DB 67000.00 62214.29 0.0 0.0
-X54 DB 67000.00 63410.71 0.0 0.0
-X55 DB 67000.00 64607.14 0.0 0.0
-X56 DB 67000.00 65803.57 0.0 0.0
-X57 DB 67000.00 67000.00 0.0 0.0
+K400  CE   34.0370  -118.1780    0.0    100.0
+K851  CE   34.0700  -118.3460    0.0    100.0
+K853  CE   34.0770  -118.2860    0.0    100.0

Modified: seismo/3D/SPECFEM3D/trunk/DATA/meshfem3D_files/Mesh_Par_file
===================================================================
--- seismo/3D/SPECFEM3D/trunk/DATA/meshfem3D_files/Mesh_Par_file	2013-09-17 22:36:21 UTC (rev 22797)
+++ seismo/3D/SPECFEM3D/trunk/DATA/meshfem3D_files/Mesh_Par_file	2013-09-18 14:35:14 UTC (rev 22798)
@@ -18,8 +18,8 @@
 NEX_ETA                         = 64
 
 # number of MPI processors along xi and eta (can be different)
-NPROC_XI                        = 4
-NPROC_ETA                       = 4
+NPROC_XI                        = 2
+NPROC_ETA                       = 2
 
 # Regular/irregular mesh
 USE_REGULAR_MESH                = .false.
@@ -45,7 +45,7 @@
 #     anisotropy_flag  : 0=no anisotropy/ 1,2,.. check with implementation in aniso_model.f90
 #     domain_id        : 1=acoustic / 2=elastic
 1  1200  1500  750  40.0  0  2
-2  1100  1000  0    50.0  0  1
+2  1100  1600  0    50.0  0  1
 3  1000  1500  700  0     0  2
 4  1300  1400  700  50.0  0  2
 # number of regions

Modified: seismo/3D/SPECFEM3D/trunk/DATA/meshfem3D_files/interfaces.dat
===================================================================
--- seismo/3D/SPECFEM3D/trunk/DATA/meshfem3D_files/interfaces.dat	2013-09-17 22:36:21 UTC (rev 22797)
+++ seismo/3D/SPECFEM3D/trunk/DATA/meshfem3D_files/interfaces.dat	2013-09-18 14:35:14 UTC (rev 22798)
@@ -1,15 +1,21 @@
 # number of interfaces
- 1
+ 2
 #
 # We describe each interface below, structured as a 2D-grid, with several parameters : 
 # number of points along XI and ETA, minimal XI ETA coordinates 
 # and spacing between points which must be constant.
 # Then the records contain the Z coordinates of the NXI x NETA points.
 #
-# interface number 1 (topography, top of the mesh)
+# interface number 1 
 # SUPPRESS_UTM_PROJECTION  NXI  NETA LONG_MIN   LAT_MIN    SPACING_XI SPACING_ETA
- .false.                   1401 1001 -121.d0    32.d0      0.005d0    0.005d0
- topo.dat
+ .true.                    161  144  316000.d0  3655000.d0 20000.d0    20000.d0
+ interface1.dat
+# interface number 2 (topography, top of the mesh)
+ .false. 1401 1001 -121.d0 32.d0 0.005d0 0.005d0
+ interface2.dat
 #
-# number of spectral elements in the vertical direction
- 15
+# for each layer, we give the number of spectral elements in the vertical direction
+# layer number 1 (bottom layer)
+ 11
+# layer number 2 (top layer)
+ 4

Modified: seismo/3D/SPECFEM3D/trunk/configure
===================================================================
--- seismo/3D/SPECFEM3D/trunk/configure	2013-09-17 22:36:21 UTC (rev 22797)
+++ seismo/3D/SPECFEM3D/trunk/configure	2013-09-18 14:35:14 UTC (rev 22798)
@@ -1,22 +1,20 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.69 for Specfem 3D 2.1.0.
+# Generated by GNU Autoconf 2.63 for Specfem 3D 2.1.0.
 #
 # Report bugs to <jtromp AT princeton.edu>.
 #
-#
-# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
-#
-#
+# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
+# 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
 # This configure script is free software; the Free Software Foundation
 # gives unlimited permission to copy, distribute and modify it.
-## -------------------- ##
-## M4sh Initialization. ##
-## -------------------- ##
+## --------------------- ##
+## M4sh Initialization.  ##
+## --------------------- ##
 
 # Be more Bourne compatible
 DUALCASE=1; export DUALCASE # for MKS sh
-if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
   emulate sh
   NULLCMD=:
   # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
@@ -24,15 +22,23 @@
   alias -g '${1+"$@"}'='"$@"'
   setopt NO_GLOB_SUBST
 else
-  case `(set -o) 2>/dev/null` in #(
-  *posix*) :
-    set -o posix ;; #(
-  *) :
-     ;;
+  case `(set -o) 2>/dev/null` in
+  *posix*) set -o posix ;;
 esac
+
 fi
 
 
+
+
+# PATH needs CR
+# Avoid depending upon Character Ranges.
+as_cr_letters='abcdefghijklmnopqrstuvwxyz'
+as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+as_cr_Letters=$as_cr_letters$as_cr_LETTERS
+as_cr_digits='0123456789'
+as_cr_alnum=$as_cr_Letters$as_cr_digits
+
 as_nl='
 '
 export as_nl
@@ -40,13 +46,7 @@
 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
+if (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then
   as_echo='printf %s\n'
   as_echo_n='printf %s'
 else
@@ -57,7 +57,7 @@
     as_echo_body='eval expr "X$1" : "X\\(.*\\)"'
     as_echo_n_body='eval
       arg=$1;
-      case $arg in #(
+      case $arg in
       *"$as_nl"*)
 	expr "X$arg" : "X\\(.*\\)$as_nl";
 	arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;;
@@ -80,7 +80,14 @@
   }
 fi
 
+# Support unset when possible.
+if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then
+  as_unset=unset
+else
+  as_unset=false
+fi
 
+
 # IFS
 # We need space, tab and new line, in precisely that order.  Quoting is
 # there to prevent editors from complaining about space-tab.
@@ -89,16 +96,15 @@
 IFS=" ""	$as_nl"
 
 # Find who we are.  Look in the path if we contain no directory separator.
-as_myself=
-case $0 in #((
+case $0 in
   *[\\/]* ) as_myself=$0 ;;
   *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
 for as_dir in $PATH
 do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
-    test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
-  done
+  test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
+done
 IFS=$as_save_IFS
 
      ;;
@@ -110,16 +116,12 @@
 fi
 if test ! -f "$as_myself"; then
   $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
-  exit 1
+  { (exit 1); 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 || :
+# Work around bugs in pre-3.0 UWIN ksh.
+for as_var in ENV MAIL MAILPATH
+do ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var
 done
 PS1='$ '
 PS2='> '
@@ -131,345 +133,330 @@
 LANGUAGE=C
 export LANGUAGE
 
+# Required to use basename.
+if expr a : '\(a\)' >/dev/null 2>&1 &&
+   test "X`expr 00001 : '.*\(...\)'`" = X001; then
+  as_expr=expr
+else
+  as_expr=false
+fi
+
+if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then
+  as_basename=basename
+else
+  as_basename=false
+fi
+
+
+# Name of the executable.
+as_me=`$as_basename -- "$0" ||
+$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
+	 X"$0" : 'X\(//\)$' \| \
+	 X"$0" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X/"$0" |
+    sed '/^.*\/\([^/][^/]*\)\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\/\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\/\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+
 # CDPATH.
-(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+$as_unset CDPATH
 
-# Use a proper internal environment variable to ensure we don't fall
-  # into an infinite loop, continuously re-executing ourselves.
-  if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then
-    _as_can_reexec=no; export _as_can_reexec;
-    # We cannot yet assume a decent shell, so we have to provide a
-# neutralization value for shells without unset; and this also
-# works around shells that cannot unset nonexistent variables.
-# Preserve -v and -x to the replacement shell.
-BASH_ENV=/dev/null
-ENV=/dev/null
-(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
-case $- in # ((((
-  *v*x* | *x*v* ) as_opts=-vx ;;
-  *v* ) as_opts=-v ;;
-  *x* ) as_opts=-x ;;
-  * ) as_opts= ;;
-esac
-exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"}
-# Admittedly, this is quite paranoid, since all the known shells bail
-# out after a failed `exec'.
-$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2
-as_fn_exit 255
-  fi
-  # We don't want this to propagate to other subprocesses.
-          { _as_can_reexec=; unset _as_can_reexec;}
+
 if test "x$CONFIG_SHELL" = x; then
-  as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then :
-  emulate sh
-  NULLCMD=:
-  # Pre-4.2 versions of Zsh do word splitting on \${1+\"\$@\"}, which
-  # is contrary to our usage.  Disable this feature.
-  alias -g '\${1+\"\$@\"}'='\"\$@\"'
-  setopt NO_GLOB_SUBST
+  if (eval ":") 2>/dev/null; then
+  as_have_required=yes
 else
-  case \`(set -o) 2>/dev/null\` in #(
-  *posix*) :
-    set -o posix ;; #(
-  *) :
-     ;;
-esac
+  as_have_required=no
 fi
-"
-  as_required="as_fn_return () { (exit \$1); }
-as_fn_success () { as_fn_return 0; }
-as_fn_failure () { as_fn_return 1; }
-as_fn_ret_success () { return 0; }
-as_fn_ret_failure () { return 1; }
 
+  if test $as_have_required = yes &&	 (eval ":
+(as_func_return () {
+  (exit \$1)
+}
+as_func_success () {
+  as_func_return 0
+}
+as_func_failure () {
+  as_func_return 1
+}
+as_func_ret_success () {
+  return 0
+}
+as_func_ret_failure () {
+  return 1
+}
+
 exitcode=0
-as_fn_success || { exitcode=1; echo as_fn_success failed.; }
-as_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; }
-as_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; }
-as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; }
-if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then :
+if as_func_success; then
+  :
+else
+  exitcode=1
+  echo as_func_success failed.
+fi
 
+if as_func_failure; then
+  exitcode=1
+  echo as_func_failure succeeded.
+fi
+
+if as_func_ret_success; then
+  :
 else
-  exitcode=1; echo positional parameters were not saved.
+  exitcode=1
+  echo as_func_ret_success failed.
 fi
-test x\$exitcode = x0 || exit 1
-test -x / || exit 1"
-  as_suggested="  as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO
-  as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO
-  eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" &&
-  test \"x\`expr \$as_lineno_1'\$as_run' + 1\`\" = \"x\$as_lineno_2'\$as_run'\"' || exit 1
-test \$(( 1 + 1 )) = 2 || exit 1"
-  if (eval "$as_required") 2>/dev/null; then :
-  as_have_required=yes
+
+if as_func_ret_failure; then
+  exitcode=1
+  echo as_func_ret_failure succeeded.
+fi
+
+if ( set x; as_func_ret_success y && test x = \"\$1\" ); then
+  :
 else
-  as_have_required=no
+  exitcode=1
+  echo positional parameters were not saved.
 fi
-  if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null; then :
 
+test \$exitcode = 0) || { (exit 1); exit 1; }
+
+(
+  as_lineno_1=\$LINENO
+  as_lineno_2=\$LINENO
+  test \"x\$as_lineno_1\" != \"x\$as_lineno_2\" &&
+  test \"x\`expr \$as_lineno_1 + 1\`\" = \"x\$as_lineno_2\") || { (exit 1); exit 1; }
+") 2> /dev/null; then
+  :
 else
-  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-as_found=false
+  as_candidate_shells=
+    as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
 for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH
 do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
-  as_found=:
-  case $as_dir in #(
+  case $as_dir in
 	 /*)
 	   for as_base in sh bash ksh sh5; do
-	     # Try only shells that exist, to save several forks.
-	     as_shell=$as_dir/$as_base
-	     if { test -f "$as_shell" || test -f "$as_shell.exe"; } &&
-		    { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$as_shell"; } 2>/dev/null; then :
-  CONFIG_SHELL=$as_shell as_have_required=yes
-		   if { $as_echo "$as_bourne_compatible""$as_suggested" | as_run=a "$as_shell"; } 2>/dev/null; then :
-  break 2
-fi
-fi
+	     as_candidate_shells="$as_candidate_shells $as_dir/$as_base"
 	   done;;
        esac
-  as_found=false
 done
-$as_found || { if { test -f "$SHELL" || test -f "$SHELL.exe"; } &&
-	      { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$SHELL"; } 2>/dev/null; then :
-  CONFIG_SHELL=$SHELL as_have_required=yes
-fi; }
 IFS=$as_save_IFS
 
 
-      if test "x$CONFIG_SHELL" != x; then :
-  export CONFIG_SHELL
-             # We cannot yet assume a decent shell, so we have to provide a
-# neutralization value for shells without unset; and this also
-# works around shells that cannot unset nonexistent variables.
-# Preserve -v and -x to the replacement shell.
-BASH_ENV=/dev/null
-ENV=/dev/null
-(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
-case $- in # ((((
-  *v*x* | *x*v* ) as_opts=-vx ;;
-  *v* ) as_opts=-v ;;
-  *x* ) as_opts=-x ;;
-  * ) as_opts= ;;
+      for as_shell in $as_candidate_shells $SHELL; do
+	 # Try only shells that exist, to save several forks.
+	 if { test -f "$as_shell" || test -f "$as_shell.exe"; } &&
+		{ ("$as_shell") 2> /dev/null <<\_ASEOF
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
+  emulate sh
+  NULLCMD=:
+  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '${1+"$@"}'='"$@"'
+  setopt NO_GLOB_SUBST
+else
+  case `(set -o) 2>/dev/null` in
+  *posix*) set -o posix ;;
 esac
-exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"}
-# Admittedly, this is quite paranoid, since all the known shells bail
-# out after a failed `exec'.
-$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2
-exit 255
+
 fi
 
-    if test x$as_have_required = xno; then :
-  $as_echo "$0: This script requires a shell more modern than all"
-  $as_echo "$0: the shells that I found on your system."
-  if test x${ZSH_VERSION+set} = xset ; then
-    $as_echo "$0: In particular, zsh $ZSH_VERSION has bugs and should"
-    $as_echo "$0: be upgraded to zsh 4.3.4 or later."
-  else
-    $as_echo "$0: Please tell bug-autoconf at gnu.org and jtromp AT
-$0: princeton.edu about your system, including any error
-$0: possibly output before this message. Then install a
-$0: modern shell, or manually run the script under such a
-$0: shell if you do have one."
-  fi
-  exit 1
+
+:
+_ASEOF
+}; then
+  CONFIG_SHELL=$as_shell
+	       as_have_required=yes
+	       if { "$as_shell" 2> /dev/null <<\_ASEOF
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
+  emulate sh
+  NULLCMD=:
+  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
+  # is contrary to our usage.  Disable this feature.
+  alias -g '${1+"$@"}'='"$@"'
+  setopt NO_GLOB_SUBST
+else
+  case `(set -o) 2>/dev/null` in
+  *posix*) set -o posix ;;
+esac
+
 fi
+
+
+:
+(as_func_return () {
+  (exit $1)
+}
+as_func_success () {
+  as_func_return 0
+}
+as_func_failure () {
+  as_func_return 1
+}
+as_func_ret_success () {
+  return 0
+}
+as_func_ret_failure () {
+  return 1
+}
+
+exitcode=0
+if as_func_success; then
+  :
+else
+  exitcode=1
+  echo as_func_success failed.
 fi
+
+if as_func_failure; then
+  exitcode=1
+  echo as_func_failure succeeded.
 fi
-SHELL=${CONFIG_SHELL-/bin/sh}
-export SHELL
-# Unset more variables known to interfere with behavior of common tools.
-CLICOLOR_FORCE= GREP_OPTIONS=
-unset CLICOLOR_FORCE GREP_OPTIONS
 
-## --------------------- ##
-## M4sh Shell Functions. ##
-## --------------------- ##
-# as_fn_unset VAR
-# ---------------
-# Portably unset VAR.
-as_fn_unset ()
-{
-  { eval $1=; unset $1;}
-}
-as_unset=as_fn_unset
+if as_func_ret_success; then
+  :
+else
+  exitcode=1
+  echo as_func_ret_success failed.
+fi
 
-# as_fn_set_status STATUS
-# -----------------------
-# Set $? to STATUS, without forking.
-as_fn_set_status ()
-{
-  return $1
-} # as_fn_set_status
+if as_func_ret_failure; then
+  exitcode=1
+  echo as_func_ret_failure succeeded.
+fi
 
-# as_fn_exit STATUS
-# -----------------
-# Exit the shell with STATUS, even in a "trap 0" or "set -e" context.
-as_fn_exit ()
-{
-  set +e
-  as_fn_set_status $1
-  exit $1
-} # as_fn_exit
+if ( set x; as_func_ret_success y && test x = "$1" ); then
+  :
+else
+  exitcode=1
+  echo positional parameters were not saved.
+fi
 
-# as_fn_mkdir_p
-# -------------
-# Create "$as_dir" as a directory, including parents if necessary.
-as_fn_mkdir_p ()
-{
+test $exitcode = 0) || { (exit 1); exit 1; }
 
-  case $as_dir in #(
-  -*) as_dir=./$as_dir;;
-  esac
-  test -d "$as_dir" || eval $as_mkdir_p || {
-    as_dirs=
-    while :; do
-      case $as_dir in #(
-      *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'(
-      *) as_qdir=$as_dir;;
-      esac
-      as_dirs="'$as_qdir' $as_dirs"
-      as_dir=`$as_dirname -- "$as_dir" ||
-$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
-	 X"$as_dir" : 'X\(//\)[^/]' \| \
-	 X"$as_dir" : 'X\(//\)$' \| \
-	 X"$as_dir" : 'X\(/\)' \| . 2>/dev/null ||
-$as_echo X"$as_dir" |
-    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
-	    s//\1/
-	    q
-	  }
-	  /^X\(\/\/\)[^/].*/{
-	    s//\1/
-	    q
-	  }
-	  /^X\(\/\/\)$/{
-	    s//\1/
-	    q
-	  }
-	  /^X\(\/\).*/{
-	    s//\1/
-	    q
-	  }
-	  s/.*/./; q'`
-      test -d "$as_dir" && break
-    done
-    test -z "$as_dirs" || eval "mkdir $as_dirs"
-  } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir"
+(
+  as_lineno_1=$LINENO
+  as_lineno_2=$LINENO
+  test "x$as_lineno_1" != "x$as_lineno_2" &&
+  test "x`expr $as_lineno_1 + 1`" = "x$as_lineno_2") || { (exit 1); exit 1; }
 
+_ASEOF
+}; then
+  break
+fi
 
-} # as_fn_mkdir_p
+fi
 
-# as_fn_executable_p FILE
-# -----------------------
-# Test if FILE is an executable regular file.
-as_fn_executable_p ()
-{
-  test -f "$1" && test -x "$1"
-} # as_fn_executable_p
-# as_fn_append VAR VALUE
-# ----------------------
-# Append the text in VALUE to the end of the definition contained in VAR. Take
-# advantage of any shell optimizations that allow amortized linear growth over
-# repeated appends, instead of the typical quadratic growth present in naive
-# implementations.
-if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then :
-  eval 'as_fn_append ()
-  {
-    eval $1+=\$2
-  }'
-else
-  as_fn_append ()
-  {
-    eval $1=\$$1\$2
-  }
-fi # as_fn_append
+      done
 
-# as_fn_arith ARG...
-# ------------------
-# Perform arithmetic evaluation on the ARGs, and store the result in the
-# global $as_val. Take advantage of shells that can avoid forks. The arguments
-# must be portable across $(()) and expr.
-if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then :
-  eval 'as_fn_arith ()
-  {
-    as_val=$(( $* ))
-  }'
-else
-  as_fn_arith ()
-  {
-    as_val=`expr "$@" || test $? -eq 1`
-  }
-fi # as_fn_arith
+      if test "x$CONFIG_SHELL" != x; then
+  for as_var in BASH_ENV ENV
+	do ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var
+	done
+	export CONFIG_SHELL
+	exec "$CONFIG_SHELL" "$as_myself" ${1+"$@"}
+fi
 
 
-# as_fn_error STATUS ERROR [LINENO LOG_FD]
-# ----------------------------------------
-# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are
-# provided, also output the error to LOG_FD, referencing LINENO. Then exit the
-# script with STATUS, using 1 if that was 0.
-as_fn_error ()
-{
-  as_status=$1; test $as_status -eq 0 && as_status=1
-  if test "$4"; then
-    as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
-    $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4
-  fi
-  $as_echo "$as_me: error: $2" >&2
-  as_fn_exit $as_status
-} # as_fn_error
+    if test $as_have_required = no; then
+  echo This script requires a shell more modern than all the
+      echo shells that I found on your system.  Please install a
+      echo modern shell, or manually run the script under such a
+      echo shell if you do have one.
+      { (exit 1); exit 1; }
+fi
 
-if expr a : '\(a\)' >/dev/null 2>&1 &&
-   test "X`expr 00001 : '.*\(...\)'`" = X001; then
-  as_expr=expr
+
+fi
+
+fi
+
+
+
+(eval "as_func_return () {
+  (exit \$1)
+}
+as_func_success () {
+  as_func_return 0
+}
+as_func_failure () {
+  as_func_return 1
+}
+as_func_ret_success () {
+  return 0
+}
+as_func_ret_failure () {
+  return 1
+}
+
+exitcode=0
+if as_func_success; then
+  :
 else
-  as_expr=false
+  exitcode=1
+  echo as_func_success failed.
 fi
 
-if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then
-  as_basename=basename
+if as_func_failure; then
+  exitcode=1
+  echo as_func_failure succeeded.
+fi
+
+if as_func_ret_success; then
+  :
 else
-  as_basename=false
+  exitcode=1
+  echo as_func_ret_success failed.
 fi
 
-if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then
-  as_dirname=dirname
+if as_func_ret_failure; then
+  exitcode=1
+  echo as_func_ret_failure succeeded.
+fi
+
+if ( set x; as_func_ret_success y && test x = \"\$1\" ); then
+  :
 else
-  as_dirname=false
+  exitcode=1
+  echo positional parameters were not saved.
 fi
 
-as_me=`$as_basename -- "$0" ||
-$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
-	 X"$0" : 'X\(//\)$' \| \
-	 X"$0" : 'X\(/\)' \| . 2>/dev/null ||
-$as_echo X/"$0" |
-    sed '/^.*\/\([^/][^/]*\)\/*$/{
-	    s//\1/
-	    q
-	  }
-	  /^X\/\(\/\/\)$/{
-	    s//\1/
-	    q
-	  }
-	  /^X\/\(\/\).*/{
-	    s//\1/
-	    q
-	  }
-	  s/.*/./; q'`
+test \$exitcode = 0") || {
+  echo No shell found that supports shell functions.
+  echo Please tell bug-autoconf at gnu.org about your system,
+  echo including any error possibly output before this message.
+  echo This can help us improve future autoconf versions.
+  echo Configuration will now proceed without shell functions.
+}
 
-# Avoid depending upon Character Ranges.
-as_cr_letters='abcdefghijklmnopqrstuvwxyz'
-as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
-as_cr_Letters=$as_cr_letters$as_cr_LETTERS
-as_cr_digits='0123456789'
-as_cr_alnum=$as_cr_Letters$as_cr_digits
 
 
-  as_lineno_1=$LINENO as_lineno_1a=$LINENO
-  as_lineno_2=$LINENO as_lineno_2a=$LINENO
-  eval 'test "x$as_lineno_1'$as_run'" != "x$as_lineno_2'$as_run'" &&
-  test "x`expr $as_lineno_1'$as_run' + 1`" = "x$as_lineno_2'$as_run'"' || {
-  # Blame Lee E. McMahon (1931-1989) for sed's syntax.  :-)
+  as_lineno_1=$LINENO
+  as_lineno_2=$LINENO
+  test "x$as_lineno_1" != "x$as_lineno_2" &&
+  test "x`expr $as_lineno_1 + 1`" = "x$as_lineno_2" || {
+
+  # Create $as_me.lineno as a copy of $as_myself, but with $LINENO
+  # uniformly replaced by the line number.  The first 'sed' inserts a
+  # line-number line after each line using $LINENO; the second 'sed'
+  # does the real work.  The second script uses 'N' to pair each
+  # line-number line with the line containing $LINENO, and appends
+  # trailing '-' during substitution so that $LINENO is not a special
+  # case at line end.
+  # (Raja R Harinath suggested sed '=', and Paul Eggert wrote the
+  # scripts with optimization help from Paolo Bonzini.  Blame Lee
+  # E. McMahon (1931-1989) for sed's syntax.  :-)
   sed -n '
     p
     /[$]LINENO/=
@@ -486,12 +473,9 @@
       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; }
+    { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2
+   { (exit 1); exit 1; }; }
 
-  # If we had to re-execute with $CONFIG_SHELL, we're ensured to have
-  # already done that, so ensure we don't try to do so again and fall
-  # in an infinite loop.  This has already happened in practice.
-  _as_can_reexec=no; export _as_can_reexec
   # Don't try to exec as it changes $[0], causing all sort of problems
   # (the dirname of $[0] is not the place where we might find the
   # original and so on.  Autoconf is especially sensitive to this).
@@ -500,18 +484,29 @@
   exit
 }
 
+
+if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then
+  as_dirname=dirname
+else
+  as_dirname=false
+fi
+
 ECHO_C= ECHO_N= ECHO_T=
-case `echo -n x` in #(((((
+case `echo -n x` in
 -n*)
-  case `echo 'xy\c'` in
+  case `echo 'x\c'` in
   *c*) ECHO_T='	';;	# ECHO_T is single tab character.
-  xy)  ECHO_C='\c';;
-  *)   echo `echo ksh88 bug on AIX 6.1` > /dev/null
-       ECHO_T='	';;
+  *)   ECHO_C='\c';;
   esac;;
 *)
   ECHO_N='-n';;
 esac
+if expr a : '\(a\)' >/dev/null 2>&1 &&
+   test "X`expr 00001 : '.*\(...\)'`" = X001; then
+  as_expr=expr
+else
+  as_expr=false
+fi
 
 rm -f conf$$ conf$$.exe conf$$.file
 if test -d conf$$.dir; then
@@ -526,29 +521,49 @@
     # ... but there are two gotchas:
     # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
     # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
-    # In both cases, we have to default to `cp -pR'.
+    # In both cases, we have to default to `cp -p'.
     ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
-      as_ln_s='cp -pR'
+      as_ln_s='cp -p'
   elif ln conf$$.file conf$$ 2>/dev/null; then
     as_ln_s=ln
   else
-    as_ln_s='cp -pR'
+    as_ln_s='cp -p'
   fi
 else
-  as_ln_s='cp -pR'
+  as_ln_s='cp -p'
 fi
 rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file
 rmdir conf$$.dir 2>/dev/null
 
 if mkdir -p . 2>/dev/null; then
-  as_mkdir_p='mkdir -p "$as_dir"'
+  as_mkdir_p=:
 else
   test -d ./-p && rmdir ./-p
   as_mkdir_p=false
 fi
 
-as_test_x='test -x'
-as_executable_p=as_fn_executable_p
+if test -x / >/dev/null 2>&1; then
+  as_test_x='test -x'
+else
+  if ls -dL / >/dev/null 2>&1; then
+    as_ls_L_option=L
+  else
+    as_ls_L_option=
+  fi
+  as_test_x='
+    eval sh -c '\''
+      if test -d "$1"; then
+	test -d "$1/.";
+      else
+	case $1 in
+	-*)set "./$1";;
+	esac;
+	case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in
+	???[sx]*):;;*)false;;esac;fi
+    '\'' sh
+  '
+fi
+as_executable_p=$as_test_x
 
 # Sed expression to map a string onto a valid CPP name.
 as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
@@ -557,11 +572,11 @@
 as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
 
 
-test -n "$DJDIR" || exec 7<&0 </dev/null
-exec 6>&1
 
+exec 7<&0 </dev/null 6>&1
+
 # Name of the host.
-# hostname on some systems (SVR3.2, old GNU/Linux) returns a bogus exit status,
+# hostname on some systems (SVR3.2, Linux) returns a bogus exit status,
 # so uname gets run too.
 ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q`
 
@@ -576,6 +591,7 @@
 subdirs=
 MFLAGS=
 MAKEFLAGS=
+SHELL=${CONFIG_SHELL-/bin/sh}
 
 # Identity of this package.
 PACKAGE_NAME='Specfem 3D'
@@ -583,7 +599,6 @@
 PACKAGE_VERSION='2.1.0'
 PACKAGE_STRING='Specfem 3D 2.1.0'
 PACKAGE_BUGREPORT='jtromp AT princeton.edu'
-PACKAGE_URL=''
 
 ac_unique_file="README"
 # Factoring default headers for most tests.
@@ -642,6 +657,10 @@
 SCOTCH_INCLUDEDIR
 SCOTCH_DIR
 USE_BUNDLED_SCOTCH
+MXML_LIB
+MXML_INC
+ADIOS_LIB
+ADIOS_INC
 PTHREAD_CFLAGS
 PTHREAD_LIBS
 PTHREAD_CC
@@ -691,6 +710,8 @@
 PYTHON
 COND_OPENMP_FALSE
 COND_OPENMP_TRUE
+COND_ADIOS_FALSE
+COND_ADIOS_TRUE
 COND_CUDA5_FALSE
 COND_CUDA5_TRUE
 COND_CUDA_FALSE
@@ -739,7 +760,6 @@
 program_transform_name
 prefix
 exec_prefix
-PACKAGE_URL
 PACKAGE_BUGREPORT
 PACKAGE_STRING
 PACKAGE_VERSION
@@ -754,6 +774,7 @@
 with_mpi
 enable_double_precision
 with_cuda
+with_adios
 with_openmp
 with_scotch_dir
 with_scotch_includedir
@@ -762,7 +783,6 @@
       ac_precious_vars='build_alias
 host_alias
 target_alias
-PYTHON
 FC
 FCFLAGS
 LDFLAGS
@@ -773,6 +793,10 @@
 CPP
 YACC
 YFLAGS
+ADIOS_INC
+ADIOS_LIB
+MXML_INC
+MXML_LIB
 USE_BUNDLED_SCOTCH
 SCOTCH_DIR
 SCOTCH_INCLUDEDIR
@@ -786,6 +810,7 @@
 MPI_INC
 OPENMP_LIB
 LOCAL_PATH_IS_ALSO_GLOBAL
+PYTHON
 PYTHONPATH'
 
 
@@ -849,9 +874,8 @@
   fi
 
   case $ac_option in
-  *=?*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;;
-  *=)   ac_optarg= ;;
-  *)    ac_optarg=yes ;;
+  *=*)	ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;;
+  *)	ac_optarg=yes ;;
   esac
 
   # Accept the important Cygnus configure options, so we can diagnose typos.
@@ -896,7 +920,8 @@
     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_echo "$as_me: error: invalid feature name: $ac_useropt" >&2
+   { (exit 1); exit 1; }; }
     ac_useropt_orig=$ac_useropt
     ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
     case $ac_user_opts in
@@ -922,7 +947,8 @@
     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_echo "$as_me: error: invalid feature name: $ac_useropt" >&2
+   { (exit 1); exit 1; }; }
     ac_useropt_orig=$ac_useropt
     ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
     case $ac_user_opts in
@@ -1126,7 +1152,8 @@
     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_echo "$as_me: error: invalid package name: $ac_useropt" >&2
+   { (exit 1); exit 1; }; }
     ac_useropt_orig=$ac_useropt
     ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
     case $ac_user_opts in
@@ -1142,7 +1169,8 @@
     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_echo "$as_me: error: invalid package name: $ac_useropt" >&2
+   { (exit 1); exit 1; }; }
     ac_useropt_orig=$ac_useropt
     ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
     case $ac_user_opts in
@@ -1172,17 +1200,17 @@
   | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*)
     x_libraries=$ac_optarg ;;
 
-  -*) as_fn_error $? "unrecognized option: \`$ac_option'
-Try \`$0 --help' for more information"
+  -*) { $as_echo "$as_me: error: unrecognized option: $ac_option
+Try \`$0 --help' for more information." >&2
+   { (exit 1); exit 1; }; }
     ;;
 
   *=*)
     ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='`
     # Reject names that are not valid shell variable names.
-    case $ac_envvar in #(
-      '' | [0-9]* | *[!_$as_cr_alnum]* )
-      as_fn_error $? "invalid variable name: \`$ac_envvar'" ;;
-    esac
+    expr "x$ac_envvar" : ".*[^_$as_cr_alnum]" >/dev/null &&
+      { $as_echo "$as_me: error: invalid variable name: $ac_envvar" >&2
+   { (exit 1); exit 1; }; }
     eval $ac_envvar=\$ac_optarg
     export $ac_envvar ;;
 
@@ -1191,7 +1219,7 @@
     $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2
     expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null &&
       $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2
-    : "${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}"
+    : ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}
     ;;
 
   esac
@@ -1199,13 +1227,15 @@
 
 if test -n "$ac_prev"; then
   ac_option=--`echo $ac_prev | sed 's/_/-/g'`
-  as_fn_error $? "missing argument to $ac_option"
+  { $as_echo "$as_me: error: missing argument to $ac_option" >&2
+   { (exit 1); exit 1; }; }
 fi
 
 if test -n "$ac_unrecognized_opts"; then
   case $enable_option_checking in
     no) ;;
-    fatal) as_fn_error $? "unrecognized options: $ac_unrecognized_opts" ;;
+    fatal) { $as_echo "$as_me: error: unrecognized options: $ac_unrecognized_opts" >&2
+   { (exit 1); exit 1; }; } ;;
     *)     $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;;
   esac
 fi
@@ -1228,7 +1258,8 @@
     [\\/$]* | ?:[\\/]* )  continue;;
     NONE | '' ) case $ac_var in *prefix ) continue;; esac;;
   esac
-  as_fn_error $? "expected an absolute directory name for --$ac_var: $ac_val"
+  { $as_echo "$as_me: error: expected an absolute directory name for --$ac_var: $ac_val" >&2
+   { (exit 1); exit 1; }; }
 done
 
 # There might be people who depend on the old broken behavior: `$host'
@@ -1242,6 +1273,8 @@
 if test "x$host_alias" != x; then
   if test "x$build_alias" = x; then
     cross_compiling=maybe
+    $as_echo "$as_me: WARNING: If you wanted to set the --build type, don't use --host.
+    If a cross compiler is detected then cross compile mode will be used." >&2
   elif test "x$build_alias" != "x$host_alias"; then
     cross_compiling=yes
   fi
@@ -1256,9 +1289,11 @@
 ac_pwd=`pwd` && test -n "$ac_pwd" &&
 ac_ls_di=`ls -di .` &&
 ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` ||
-  as_fn_error $? "working directory cannot be determined"
+  { $as_echo "$as_me: error: working directory cannot be determined" >&2
+   { (exit 1); exit 1; }; }
 test "X$ac_ls_di" = "X$ac_pwd_ls_di" ||
-  as_fn_error $? "pwd does not report name of working directory"
+  { $as_echo "$as_me: error: pwd does not report name of working directory" >&2
+   { (exit 1); exit 1; }; }
 
 
 # Find the source files, if location was not specified.
@@ -1297,11 +1332,13 @@
 fi
 if test ! -r "$srcdir/$ac_unique_file"; then
   test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .."
-  as_fn_error $? "cannot find sources ($ac_unique_file) in $srcdir"
+  { $as_echo "$as_me: error: cannot find sources ($ac_unique_file) in $srcdir" >&2
+   { (exit 1); exit 1; }; }
 fi
 ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work"
 ac_abs_confdir=`(
-	cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg"
+	cd "$srcdir" && test -r "./$ac_unique_file" || { $as_echo "$as_me: error: $ac_msg" >&2
+   { (exit 1); exit 1; }; }
 	pwd)`
 # When building in place, set srcdir=.
 if test "$ac_abs_confdir" = "$ac_pwd"; then
@@ -1341,7 +1378,7 @@
       --help=short        display options specific to this package
       --help=recursive    display the short help of all the included packages
   -V, --version           display version information and exit
-  -q, --quiet, --silent   do not print \`checking ...' messages
+  -q, --quiet, --silent   do not print \`checking...' messages
       --cache-file=FILE   cache test results in FILE [disabled]
   -C, --config-cache      alias for \`--cache-file=config.cache'
   -n, --no-create         do not create output files
@@ -1409,6 +1446,7 @@
   --with-pyre             build Pyrized version [default=no]
   --with-mpi              build parallel version [default=yes]
   --with-cuda             build CUDA GPU enabled version [default=no]
+  --with-adios            build ADIOS enabled version [default=no]
   --with-openmp           build OpenMP enabled version [default=no]
   --with-scotch-dir       define the root path to Scotch (e.g. /opt/scotch/)
   --with-scotch-includedir
@@ -1418,7 +1456,6 @@
                           /opt/scotch/lib)
 
 Some influential environment variables:
-  PYTHON      the Python interpreter
   FC          Fortran compiler command
   FCFLAGS     Fortran compiler flags
   LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
@@ -1426,15 +1463,18 @@
   LIBS        libraries to pass to the linker, e.g. -l<library>
   CC          C compiler command
   CFLAGS      C compiler flags
-  CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
+  CPPFLAGS    C/C++/Objective C preprocessor flags, e.g. -I<include dir> if
               you have headers in a nonstandard directory <include dir>
   CPP         C preprocessor
-  YACC        The `Yet Another Compiler Compiler' implementation to use.
-              Defaults to the first program found out of: `bison -y', `byacc',
-              `yacc'.
+  YACC        The `Yet Another C Compiler' implementation to use. Defaults to
+              the first program found out of: `bison -y', `byacc', `yacc'.
   YFLAGS      The list of arguments that will be passed by default to $YACC.
               This script will default YFLAGS to the empty string to avoid a
               default value of `-d' given by some make applications.
+  ADIOS_INC   Directory where ADIOS headers are installed
+  ADIOS_LIB   Directory where ADIOS libraries are installed
+  MXML_INC    Directory where MXML headers are installed
+  MXML_LIB    Directory where MXML libraries are installed
   USE_BUNDLED_SCOTCH
               Set to 1 to always use the bundled Scotch library
   SCOTCH_DIR  Directory where Scotch is installed
@@ -1454,6 +1494,7 @@
   LOCAL_PATH_IS_ALSO_GLOBAL
               files on a local path on each node are also seen as global with
               same path [default=true]
+  PYTHON      Python interpreter
   PYTHONPATH  Python module search path
 
 Use these variables to override the choices made by `configure' or to help
@@ -1523,393 +1564,21 @@
 if $ac_init_version; then
   cat <<\_ACEOF
 Specfem 3D configure 2.1.0
-generated by GNU Autoconf 2.69
+generated by GNU Autoconf 2.63
 
-Copyright (C) 2012 Free Software Foundation, Inc.
+Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
+2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
 This configure script is free software; the Free Software Foundation
 gives unlimited permission to copy, distribute and modify it.
 _ACEOF
   exit
 fi
-
-## ------------------------ ##
-## Autoconf initialization. ##
-## ------------------------ ##
-
-# ac_fn_fc_try_compile LINENO
-# ---------------------------
-# Try to compile conftest.$ac_ext, and return whether this succeeded.
-ac_fn_fc_try_compile ()
-{
-  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
-  rm -f conftest.$ac_objext
-  if { { ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
-$as_echo "$ac_try_echo"; } >&5
-  (eval "$ac_compile") 2>conftest.err
-  ac_status=$?
-  if test -s conftest.err; then
-    grep -v '^ *+' conftest.err >conftest.er1
-    cat conftest.er1 >&5
-    mv -f conftest.er1 conftest.err
-  fi
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; } && {
-	 test -z "$ac_fc_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then :
-  ac_retval=0
-else
-  $as_echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_retval=1
-fi
-  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
-  as_fn_set_status $ac_retval
-
-} # ac_fn_fc_try_compile
-
-# ac_fn_c_try_compile LINENO
-# --------------------------
-# Try to compile conftest.$ac_ext, and return whether this succeeded.
-ac_fn_c_try_compile ()
-{
-  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
-  rm -f conftest.$ac_objext
-  if { { ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
-$as_echo "$ac_try_echo"; } >&5
-  (eval "$ac_compile") 2>conftest.err
-  ac_status=$?
-  if test -s conftest.err; then
-    grep -v '^ *+' conftest.err >conftest.er1
-    cat conftest.er1 >&5
-    mv -f conftest.er1 conftest.err
-  fi
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then :
-  ac_retval=0
-else
-  $as_echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_retval=1
-fi
-  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
-  as_fn_set_status $ac_retval
-
-} # ac_fn_c_try_compile
-
-# ac_fn_c_try_link LINENO
-# -----------------------
-# Try to link conftest.$ac_ext, and return whether this succeeded.
-ac_fn_c_try_link ()
-{
-  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
-  rm -f conftest.$ac_objext conftest$ac_exeext
-  if { { ac_try="$ac_link"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
-$as_echo "$ac_try_echo"; } >&5
-  (eval "$ac_link") 2>conftest.err
-  ac_status=$?
-  if test -s conftest.err; then
-    grep -v '^ *+' conftest.err >conftest.er1
-    cat conftest.er1 >&5
-    mv -f conftest.er1 conftest.err
-  fi
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; } && {
-	 test -z "$ac_c_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest$ac_exeext && {
-	 test "$cross_compiling" = yes ||
-	 test -x conftest$ac_exeext
-       }; then :
-  ac_retval=0
-else
-  $as_echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_retval=1
-fi
-  # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information
-  # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would
-  # interfere with the next link command; also delete a directory that is
-  # left behind by Apple's compiler.  We do this before executing the actions.
-  rm -rf conftest.dSYM conftest_ipa8_conftest.oo
-  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
-  as_fn_set_status $ac_retval
-
-} # ac_fn_c_try_link
-
-# ac_fn_c_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_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 jtromp AT princeton.edu ##
-## -------------------------------------- ##"
-     ) | 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_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_header_compile LINENO HEADER VAR INCLUDES
-# -------------------------------------------------------
-# Tests whether HEADER exists and can be compiled using the include files in
-# INCLUDES, setting the cache variable VAR accordingly.
-ac_fn_c_check_header_compile ()
-{
-  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
-$as_echo_n "checking for $2... " >&6; }
-if eval \${$3+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-$4
-#include <$2>
-_ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
-  eval "$3=yes"
-else
-  eval "$3=no"
-fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-fi
-eval ac_res=\$$3
-	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
-$as_echo "$ac_res" >&6; }
-  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
-
-} # ac_fn_c_check_header_compile
-
-# ac_fn_fc_try_link LINENO
-# ------------------------
-# Try to link conftest.$ac_ext, and return whether this succeeded.
-ac_fn_fc_try_link ()
-{
-  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
-  rm -f conftest.$ac_objext conftest$ac_exeext
-  if { { ac_try="$ac_link"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
-$as_echo "$ac_try_echo"; } >&5
-  (eval "$ac_link") 2>conftest.err
-  ac_status=$?
-  if test -s conftest.err; then
-    grep -v '^ *+' conftest.err >conftest.er1
-    cat conftest.er1 >&5
-    mv -f conftest.er1 conftest.err
-  fi
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; } && {
-	 test -z "$ac_fc_werror_flag" ||
-	 test ! -s conftest.err
-       } && test -s conftest$ac_exeext && {
-	 test "$cross_compiling" = yes ||
-	 test -x conftest$ac_exeext
-       }; then :
-  ac_retval=0
-else
-  $as_echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-	ac_retval=1
-fi
-  # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information
-  # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would
-  # interfere with the next link command; also delete a directory that is
-  # left behind by Apple's compiler.  We do this before executing the actions.
-  rm -rf conftest.dSYM conftest_ipa8_conftest.oo
-  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
-  as_fn_set_status $ac_retval
-
-} # ac_fn_fc_try_link
 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 Specfem 3D $as_me 2.1.0, which was
-generated by GNU Autoconf 2.69.  Invocation command line was
+generated by GNU Autoconf 2.63.  Invocation command line was
 
   $ $0 $@
 
@@ -1945,8 +1614,8 @@
 do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
-    $as_echo "PATH: $as_dir"
-  done
+  $as_echo "PATH: $as_dir"
+done
 IFS=$as_save_IFS
 
 } >&5
@@ -1983,9 +1652,9 @@
       ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;;
     esac
     case $ac_pass in
-    1) as_fn_append ac_configure_args0 " '$ac_arg'" ;;
+    1) ac_configure_args0="$ac_configure_args0 '$ac_arg'" ;;
     2)
-      as_fn_append ac_configure_args1 " '$ac_arg'"
+      ac_configure_args1="$ac_configure_args1 '$ac_arg'"
       if test $ac_must_keep_next = true; then
 	ac_must_keep_next=false # Got value, back to normal.
       else
@@ -2001,13 +1670,13 @@
 	  -* ) ac_must_keep_next=true ;;
 	esac
       fi
-      as_fn_append ac_configure_args " '$ac_arg'"
+      ac_configure_args="$ac_configure_args '$ac_arg'"
       ;;
     esac
   done
 done
-{ ac_configure_args0=; unset ac_configure_args0;}
-{ ac_configure_args1=; unset ac_configure_args1;}
+$as_unset ac_configure_args0 || test "${ac_configure_args0+set}" != set || { ac_configure_args0=; export ac_configure_args0; }
+$as_unset ac_configure_args1 || test "${ac_configure_args1+set}" != set || { ac_configure_args1=; export ac_configure_args1; }
 
 # When interrupted or exit'd, cleanup temporary files, and complete
 # config.log.  We remove comments because anyway the quotes in there
@@ -2019,9 +1688,11 @@
   {
     echo
 
-    $as_echo "## ---------------- ##
+    cat <<\_ASBOX
+## ---------------- ##
 ## Cache variables. ##
-## ---------------- ##"
+## ---------------- ##
+_ASBOX
     echo
     # The following way of writing the cache mishandles newlines in values,
 (
@@ -2030,13 +1701,13 @@
     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
+      *_cv_*) { $as_echo "$as_me:$LINENO: WARNING: cache variable $ac_var contains a newline" >&5
 $as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;;
       esac
       case $ac_var in #(
       _ | IFS | as_nl) ;; #(
       BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #(
-      *) { eval $ac_var=; unset $ac_var;} ;;
+      *) $as_unset $ac_var ;;
       esac ;;
     esac
   done
@@ -2055,9 +1726,11 @@
 )
     echo
 
-    $as_echo "## ----------------- ##
+    cat <<\_ASBOX
+## ----------------- ##
 ## Output variables. ##
-## ----------------- ##"
+## ----------------- ##
+_ASBOX
     echo
     for ac_var in $ac_subst_vars
     do
@@ -2070,9 +1743,11 @@
     echo
 
     if test -n "$ac_subst_files"; then
-      $as_echo "## ------------------- ##
+      cat <<\_ASBOX
+## ------------------- ##
 ## File substitutions. ##
-## ------------------- ##"
+## ------------------- ##
+_ASBOX
       echo
       for ac_var in $ac_subst_files
       do
@@ -2086,9 +1761,11 @@
     fi
 
     if test -s confdefs.h; then
-      $as_echo "## ----------- ##
+      cat <<\_ASBOX
+## ----------- ##
 ## confdefs.h. ##
-## ----------- ##"
+## ----------- ##
+_ASBOX
       echo
       cat confdefs.h
       echo
@@ -2102,53 +1779,46 @@
     exit $exit_status
 ' 0
 for ac_signal in 1 2 13 15; do
-  trap 'ac_signal='$ac_signal'; as_fn_exit 1' $ac_signal
+  trap 'ac_signal='$ac_signal'; { (exit 1); exit 1; }' $ac_signal
 done
 ac_signal=0
 
 # confdefs.h avoids OS command line length limits that DEFS can exceed.
 rm -f -r conftest* confdefs.h
 
-$as_echo "/* confdefs.h */" > confdefs.h
-
 # Predefined preprocessor variables.
 
 cat >>confdefs.h <<_ACEOF
 #define PACKAGE_NAME "$PACKAGE_NAME"
 _ACEOF
 
+
 cat >>confdefs.h <<_ACEOF
 #define PACKAGE_TARNAME "$PACKAGE_TARNAME"
 _ACEOF
 
+
 cat >>confdefs.h <<_ACEOF
 #define PACKAGE_VERSION "$PACKAGE_VERSION"
 _ACEOF
 
+
 cat >>confdefs.h <<_ACEOF
 #define PACKAGE_STRING "$PACKAGE_STRING"
 _ACEOF
 
+
 cat >>confdefs.h <<_ACEOF
 #define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT"
 _ACEOF
 
-cat >>confdefs.h <<_ACEOF
-#define PACKAGE_URL "$PACKAGE_URL"
-_ACEOF
 
-
 # Let the site file select an alternate cache file if it wants to.
 # Prefer an explicitly selected file to automatically selected ones.
 ac_site_file1=NONE
 ac_site_file2=NONE
 if test -n "$CONFIG_SITE"; then
-  # We do not want a PATH search for config.site.
-  case $CONFIG_SITE in #((
-    -*)  ac_site_file1=./$CONFIG_SITE;;
-    */*) ac_site_file1=$CONFIG_SITE;;
-    *)   ac_site_file1=./$CONFIG_SITE;;
-  esac
+  ac_site_file1=$CONFIG_SITE
 elif test "x$prefix" != xNONE; then
   ac_site_file1=$prefix/share/config.site
   ac_site_file2=$prefix/etc/config.site
@@ -2159,23 +1829,19 @@
 for ac_site_file in "$ac_site_file1" "$ac_site_file2"
 do
   test "x$ac_site_file" = xNONE && continue
-  if test /dev/null != "$ac_site_file" && test -r "$ac_site_file"; then
-    { $as_echo "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5
+  if test -r "$ac_site_file"; then
+    { $as_echo "$as_me:$LINENO: loading site script $ac_site_file" >&5
 $as_echo "$as_me: loading site script $ac_site_file" >&6;}
     sed 's/^/| /' "$ac_site_file" >&5
-    . "$ac_site_file" \
-      || { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "failed to load site script $ac_site_file
-See \`config.log' for more details" "$LINENO" 5; }
+    . "$ac_site_file"
   fi
 done
 
 if test -r "$cache_file"; then
-  # Some versions of bash will fail to source /dev/null (special files
-  # actually), so we avoid doing that.  DJGPP emulates it as a regular file.
-  if test /dev/null != "$cache_file" && test -f "$cache_file"; then
-    { $as_echo "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5
+  # Some versions of bash will fail to source /dev/null (special
+  # files actually), so we avoid doing that.
+  if test -f "$cache_file"; then
+    { $as_echo "$as_me:$LINENO: loading cache $cache_file" >&5
 $as_echo "$as_me: loading cache $cache_file" >&6;}
     case $cache_file in
       [\\/]* | ?:[\\/]* ) . "$cache_file";;
@@ -2183,7 +1849,7 @@
     esac
   fi
 else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5
+  { $as_echo "$as_me:$LINENO: creating cache $cache_file" >&5
 $as_echo "$as_me: creating cache $cache_file" >&6;}
   >$cache_file
 fi
@@ -2198,11 +1864,11 @@
   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:$LINENO: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5
 $as_echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;}
       ac_cache_corrupted=: ;;
     ,set)
-      { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5
+      { $as_echo "$as_me:$LINENO: error: \`$ac_var' was not set in the previous run" >&5
 $as_echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;}
       ac_cache_corrupted=: ;;
     ,);;
@@ -2212,17 +1878,17 @@
 	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:$LINENO: error: \`$ac_var' has changed since the previous run:" >&5
 $as_echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;}
 	  ac_cache_corrupted=:
 	else
-	  { $as_echo "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5
+	  { $as_echo "$as_me:$LINENO: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5
 $as_echo "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;}
 	  eval $ac_var=\$ac_old_val
 	fi
-	{ $as_echo "$as_me:${as_lineno-$LINENO}:   former value:  \`$ac_old_val'" >&5
+	{ $as_echo "$as_me:$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:$LINENO:   current value: \`$ac_new_val'" >&5
 $as_echo "$as_me:   current value: \`$ac_new_val'" >&2;}
       fi;;
   esac
@@ -2234,21 +1900,44 @@
     esac
     case " $ac_configure_args " in
       *" '$ac_arg' "*) ;; # Avoid dups.  Use of quotes ensures accuracy.
-      *) as_fn_append ac_configure_args " '$ac_arg'" ;;
+      *) ac_configure_args="$ac_configure_args '$ac_arg'" ;;
     esac
   fi
 done
 if $ac_cache_corrupted; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+  { $as_echo "$as_me:$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:$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
+  { { $as_echo "$as_me:$LINENO: error: run \`make distclean' and/or \`rm $cache_file' and start over" >&5
+$as_echo "$as_me: error: run \`make distclean' and/or \`rm $cache_file' and start over" >&2;}
+   { (exit 1); exit 1; }; }
 fi
-## -------------------- ##
-## Main body of script. ##
-## -------------------- ##
 
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
 ac_ext=c
 ac_cpp='$CPP $CPPFLAGS'
 ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
@@ -2278,7 +1967,9 @@
   fi
 done
 if test -z "$ac_aux_dir"; then
-  as_fn_error $? "cannot find install-sh, install.sh, or shtool in \"$srcdir\" \"$srcdir/..\" \"$srcdir/../..\"" "$LINENO" 5
+  { { $as_echo "$as_me:$LINENO: error: cannot find install-sh or install.sh in \"$srcdir\" \"$srcdir/..\" \"$srcdir/../..\"" >&5
+$as_echo "$as_me: error: cannot find install-sh or install.sh in \"$srcdir\" \"$srcdir/..\" \"$srcdir/../..\"" >&2;}
+   { (exit 1); exit 1; }; }
 fi
 
 # These three variables are undocumented and unsupported,
@@ -2292,27 +1983,35 @@
 
 # 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:$LINENO: error: cannot run $SHELL $ac_aux_dir/config.sub" >&5
+$as_echo "$as_me: error: cannot run $SHELL $ac_aux_dir/config.sub" >&2;}
+   { (exit 1); exit 1; }; }
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking build system type" >&5
+{ $as_echo "$as_me:$LINENO: checking build system type" >&5
 $as_echo_n "checking build system type... " >&6; }
-if ${ac_cv_build+:} false; then :
+if test "${ac_cv_build+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
   ac_build_alias=$build_alias
 test "x$ac_build_alias" = x &&
   ac_build_alias=`$SHELL "$ac_aux_dir/config.guess"`
 test "x$ac_build_alias" = x &&
-  as_fn_error $? "cannot guess build type; you must specify one" "$LINENO" 5
+  { { $as_echo "$as_me:$LINENO: error: cannot guess build type; you must specify one" >&5
+$as_echo "$as_me: error: cannot guess build type; you must specify one" >&2;}
+   { (exit 1); exit 1; }; }
 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
+  { { $as_echo "$as_me:$LINENO: error: $SHELL $ac_aux_dir/config.sub $ac_build_alias failed" >&5
+$as_echo "$as_me: error: $SHELL $ac_aux_dir/config.sub $ac_build_alias failed" >&2;}
+   { (exit 1); exit 1; }; }
 
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_build" >&5
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_build" >&5
 $as_echo "$ac_cv_build" >&6; }
 case $ac_cv_build in
 *-*-*) ;;
-*) as_fn_error $? "invalid value of canonical build" "$LINENO" 5;;
+*) { { $as_echo "$as_me:$LINENO: error: invalid value of canonical build" >&5
+$as_echo "$as_me: error: invalid value of canonical build" >&2;}
+   { (exit 1); exit 1; }; };;
 esac
 build=$ac_cv_build
 ac_save_IFS=$IFS; IFS='-'
@@ -2328,24 +2027,28 @@
 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 "$as_me:$LINENO: checking host system type" >&5
 $as_echo_n "checking host system type... " >&6; }
-if ${ac_cv_host+:} false; then :
+if test "${ac_cv_host+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
   if test "x$host_alias" = x; then
   ac_cv_host=$ac_cv_build
 else
   ac_cv_host=`$SHELL "$ac_aux_dir/config.sub" $host_alias` ||
-    as_fn_error $? "$SHELL $ac_aux_dir/config.sub $host_alias failed" "$LINENO" 5
+    { { $as_echo "$as_me:$LINENO: error: $SHELL $ac_aux_dir/config.sub $host_alias failed" >&5
+$as_echo "$as_me: error: $SHELL $ac_aux_dir/config.sub $host_alias failed" >&2;}
+   { (exit 1); exit 1; }; }
 fi
 
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_host" >&5
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_host" >&5
 $as_echo "$ac_cv_host" >&6; }
 case $ac_cv_host in
 *-*-*) ;;
-*) as_fn_error $? "invalid value of canonical host" "$LINENO" 5;;
+*) { { $as_echo "$as_me:$LINENO: error: invalid value of canonical host" >&5
+$as_echo "$as_me: error: invalid value of canonical host" >&2;}
+   { (exit 1); exit 1; }; };;
 esac
 host=$ac_cv_host
 ac_save_IFS=$IFS; IFS='-'
@@ -2366,7 +2069,7 @@
 
 
 # Check whether --with-pyre was given.
-if test "${with_pyre+set}" = set; then :
+if test "${with_pyre+set}" = set; then
   withval=$with_pyre; want_pyre="$withval"
 else
   want_pyre=no
@@ -2383,7 +2086,7 @@
 
 
 # Check whether --with-mpi was given.
-if test "${with_mpi+set}" = set; then :
+if test "${with_mpi+set}" = set; then
   withval=$with_mpi; want_mpi="$withval"
 else
   want_mpi=yes
@@ -2399,7 +2102,7 @@
 
 
 # Check whether --enable-double-precision was given.
-if test "${enable_double_precision+set}" = set; then :
+if test "${enable_double_precision+set}" = set; then
   enableval=$enable_double_precision; want_double_precision="$enableval"
 else
   want_double_precision=no
@@ -2417,7 +2120,7 @@
 
 
 # Check whether --with-cuda was given.
-if test "${with_cuda+set}" = set; then :
+if test "${with_cuda+set}" = set; then
   withval=$with_cuda; want_cuda="$withval"
 else
   want_cuda=no
@@ -2442,8 +2145,25 @@
 
 
 
+# Check whether --with-adios was given.
+if test "${with_adios+set}" = set; then
+  withval=$with_adios; want_adios="$withval"
+else
+  want_adios=no
+fi
+
+ if test "$want_adios" != no; then
+  COND_ADIOS_TRUE=
+  COND_ADIOS_FALSE='#'
+else
+  COND_ADIOS_TRUE='#'
+  COND_ADIOS_FALSE=
+fi
+
+
+
 # Check whether --with-openmp was given.
-if test "${with_openmp+set}" = set; then :
+if test "${with_openmp+set}" = set; then
   withval=$with_openmp; want_openmp="$withval"
 else
   want_openmp=no
@@ -2466,12 +2186,10 @@
 
 
 
-
-
         if test -n "$PYTHON"; then
       # If the user set $PYTHON, use it and don't search something else.
-      { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $PYTHON version is >= 2.3" >&5
-$as_echo_n "checking whether $PYTHON version is >= 2.3... " >&6; }
+      { $as_echo "$as_me:$LINENO: checking whether $PYTHON version >= 2.3" >&5
+$as_echo_n "checking whether $PYTHON version >= 2.3... " >&6; }
       prog="import sys
 # split strings by '.' and convert to numeric.  Append some zeros
 # because we need at least 4 digits for the hex conversion.
@@ -2485,25 +2203,26 @@
    ($PYTHON -c "$prog") >&5 2>&5
    ac_status=$?
    echo "$as_me:$LINENO: \$? = $ac_status" >&5
-   (exit $ac_status); }; then :
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+   (exit $ac_status); }; then
+  { $as_echo "$as_me:$LINENO: result: yes" >&5
 $as_echo "yes" >&6; }
 else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-			       as_fn_error $? "Python interpreter is too old" "$LINENO" 5
+  { { $as_echo "$as_me:$LINENO: error: too old" >&5
+$as_echo "$as_me: error: too old" >&2;}
+   { (exit 1); exit 1; }; }
 fi
+
       am_display_PYTHON=$PYTHON
     else
       # Otherwise, try each interpreter until we find one that satisfies
       # VERSION.
-      { $as_echo "$as_me:${as_lineno-$LINENO}: checking for a Python interpreter with version >= 2.3" >&5
+      { $as_echo "$as_me:$LINENO: checking for a Python interpreter with version >= 2.3" >&5
 $as_echo_n "checking for a Python interpreter with version >= 2.3... " >&6; }
-if ${am_cv_pathless_PYTHON+:} false; then :
+if test "${am_cv_pathless_PYTHON+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
 
-	for am_cv_pathless_PYTHON in python python2 python3 python3.2 python3.1 python3.0 python2.7  python2.6 python2.5 python2.4 python2.3 python2.2 python2.1 python2.0 none; do
+	for am_cv_pathless_PYTHON in python python2 python3 python3.0 python2.5 python2.4 python2.3 python2.2 python2.1 python2.0 none; do
 	  test "$am_cv_pathless_PYTHON" = none && break
 	  prog="import sys
 # split strings by '.' and convert to numeric.  Append some zeros
@@ -2518,12 +2237,13 @@
    ($am_cv_pathless_PYTHON -c "$prog") >&5 2>&5
    ac_status=$?
    echo "$as_me:$LINENO: \$? = $ac_status" >&5
-   (exit $ac_status); }; then :
+   (exit $ac_status); }; then
   break
 fi
+
 	done
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_pathless_PYTHON" >&5
+{ $as_echo "$as_me:$LINENO: result: $am_cv_pathless_PYTHON" >&5
 $as_echo "$am_cv_pathless_PYTHON" >&6; }
       # Set $PYTHON to the absolute path of $am_cv_pathless_PYTHON.
       if test "$am_cv_pathless_PYTHON" = none; then
@@ -2531,9 +2251,9 @@
       else
         # Extract the first word of "$am_cv_pathless_PYTHON", so it can be a program name with args.
 set dummy $am_cv_pathless_PYTHON; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_PYTHON+:} false; then :
+if test "${ac_cv_path_PYTHON+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
   case $PYTHON in
@@ -2546,14 +2266,14 @@
 do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
     ac_cv_path_PYTHON="$as_dir/$ac_word$ac_exec_ext"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
 done
-  done
+done
 IFS=$as_save_IFS
 
   ;;
@@ -2561,10 +2281,10 @@
 fi
 PYTHON=$ac_cv_path_PYTHON
 if test -n "$PYTHON"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PYTHON" >&5
+  { $as_echo "$as_me:$LINENO: result: $PYTHON" >&5
 $as_echo "$PYTHON" >&6; }
 else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+  { $as_echo "$as_me:$LINENO: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
@@ -2575,18 +2295,20 @@
 
 
   if test "$PYTHON" = :; then
-      as_fn_error $? "no suitable Python interpreter found" "$LINENO" 5
+      { { $as_echo "$as_me:$LINENO: error: no suitable Python interpreter found" >&5
+$as_echo "$as_me: error: no suitable Python interpreter found" >&2;}
+   { (exit 1); exit 1; }; }
   else
 
 
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $am_display_PYTHON version" >&5
+  { $as_echo "$as_me:$LINENO: checking for $am_display_PYTHON version" >&5
 $as_echo_n "checking for $am_display_PYTHON version... " >&6; }
-if ${am_cv_python_version+:} false; then :
+if test "${am_cv_python_version+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
   am_cv_python_version=`$PYTHON -c "import sys; sys.stdout.write(sys.version[:3])"`
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_python_version" >&5
+{ $as_echo "$as_me:$LINENO: result: $am_cv_python_version" >&5
 $as_echo "$am_cv_python_version" >&6; }
   PYTHON_VERSION=$am_cv_python_version
 
@@ -2598,23 +2320,23 @@
 
 
 
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $am_display_PYTHON platform" >&5
+  { $as_echo "$as_me:$LINENO: checking for $am_display_PYTHON platform" >&5
 $as_echo_n "checking for $am_display_PYTHON platform... " >&6; }
-if ${am_cv_python_platform+:} false; then :
+if test "${am_cv_python_platform+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
   am_cv_python_platform=`$PYTHON -c "import sys; sys.stdout.write(sys.platform)"`
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_python_platform" >&5
+{ $as_echo "$as_me:$LINENO: result: $am_cv_python_platform" >&5
 $as_echo "$am_cv_python_platform" >&6; }
   PYTHON_PLATFORM=$am_cv_python_platform
 
 
 
 
-            { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $am_display_PYTHON script directory" >&5
+                { $as_echo "$as_me:$LINENO: checking for $am_display_PYTHON script directory" >&5
 $as_echo_n "checking for $am_display_PYTHON script directory... " >&6; }
-if ${am_cv_python_pythondir+:} false; then :
+if test "${am_cv_python_pythondir+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
   if test "x$prefix" = xNONE
@@ -2623,7 +2345,8 @@
      else
        am_py_prefix=$prefix
      fi
-     am_cv_python_pythondir=`$PYTHON -c "import sys; from distutils import sysconfig; sys.stdout.write(sysconfig.get_python_lib(0,0,prefix='$am_py_prefix'))" 2>/dev/null`
+     am_cv_python_pythondir=`$PYTHON -c "import sys; from distutils import sysconfig; sys.stdout.write(sysconfig.get_python_lib(0,0,prefix='$am_py_prefix'))" 2>/dev/null ||
+     echo "$PYTHON_PREFIX/lib/python$PYTHON_VERSION/site-packages"`
      case $am_cv_python_pythondir in
      $am_py_prefix*)
        am__strip_prefix=`echo "$am_py_prefix" | sed 's|.|.|g'`
@@ -2640,7 +2363,7 @@
      esac
 
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_python_pythondir" >&5
+{ $as_echo "$as_me:$LINENO: result: $am_cv_python_pythondir" >&5
 $as_echo "$am_cv_python_pythondir" >&6; }
   pythondir=$am_cv_python_pythondir
 
@@ -2649,9 +2372,9 @@
   pkgpythondir=\${pythondir}/$PACKAGE
 
 
-        { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $am_display_PYTHON extension module directory" >&5
+            { $as_echo "$as_me:$LINENO: checking for $am_display_PYTHON extension module directory" >&5
 $as_echo_n "checking for $am_display_PYTHON extension module directory... " >&6; }
-if ${am_cv_python_pyexecdir+:} false; then :
+if test "${am_cv_python_pyexecdir+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
   if test "x$exec_prefix" = xNONE
@@ -2660,7 +2383,8 @@
      else
        am_py_exec_prefix=$exec_prefix
      fi
-     am_cv_python_pyexecdir=`$PYTHON -c "import sys; from distutils import sysconfig; sys.stdout.write(sysconfig.get_python_lib(1,0,prefix='$am_py_exec_prefix'))" 2>/dev/null`
+     am_cv_python_pyexecdir=`$PYTHON -c "import sys; from distutils import sysconfig; sys.stdout.write(sysconfig.get_python_lib(1,0,prefix='$am_py_exec_prefix'))" 2>/dev/null ||
+     echo "$PYTHON_EXEC_PREFIX/lib/python$PYTHON_VERSION/site-packages"`
      case $am_cv_python_pyexecdir in
      $am_py_exec_prefix*)
        am__strip_prefix=`echo "$am_py_exec_prefix" | sed 's|.|.|g'`
@@ -2677,7 +2401,7 @@
      esac
 
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_python_pyexecdir" >&5
+{ $as_echo "$as_me:$LINENO: result: $am_cv_python_pyexecdir" >&5
 $as_echo "$am_cv_python_pyexecdir" >&6; }
   pyexecdir=$am_cv_python_pyexecdir
 
@@ -2693,7 +2417,7 @@
 
 # $Id$
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $am_display_PYTHON sysconfig" >&5
+{ $as_echo "$as_me:$LINENO: checking $am_display_PYTHON sysconfig" >&5
 $as_echo_n "checking $am_display_PYTHON sysconfig... " >&6; }
 cat >sysconfig.py <<END_OF_PYTHON
 import os, sys
@@ -2774,13 +2498,18 @@
 END_OF_PYTHON
 eval `$PYTHON sysconfig.py 2>/dev/null`
 if test -n "$PYTHON_INCDIR"; then
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: ok" >&5
+    { $as_echo "$as_me:$LINENO: result: ok" >&5
 $as_echo "ok" >&6; }
 else
-    as_fn_error $? "\"failed
+    { { $as_echo "$as_me:$LINENO: error: \"failed
 
 Run '$PYTHON sysconfig.py' to see what went wrong.
-\"" "$LINENO" 5
+\"" >&5
+$as_echo "$as_me: error: \"failed
+
+Run '$PYTHON sysconfig.py' to see what went wrong.
+\"" >&2;}
+   { (exit 1); exit 1; }; }
 fi
 rm -f sysconfig.py sysconfig.pyc
 PYTHON_INCDIR=$PYTHON_INCDIR
@@ -2825,13 +2554,13 @@
 ac_link='$FC -o conftest$ac_exeext $FCFLAGS $LDFLAGS $ac_fcflags_srcext conftest.$ac_ext $LIBS >&5'
 ac_compiler_gnu=$ac_cv_fc_compiler_gnu
 if test -n "$ac_tool_prefix"; then
-  for ac_prog in gfortran g95 xlf95 f95 fort ifort ifc efc pgfortran pgf95 lf95 ftn nagfor xlf90 f90 pgf90 pghpf epcf90 g77 xlf f77 frt pgf77 cf77 fort77 fl32 af77
+  for ac_prog in gfortran g95 xlf95 f95 fort ifort ifc efc pgf95 lf95 ftn xlf90 f90 pgf90 pghpf epcf90 g77 xlf f77 frt pgf77 cf77 fort77 fl32 af77
   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 "$as_me:$LINENO: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_prog_FC+:} false; then :
+if test "${ac_cv_prog_FC+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
   if test -n "$FC"; then
@@ -2842,24 +2571,24 @@
 do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
     ac_cv_prog_FC="$ac_tool_prefix$ac_prog"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
 done
-  done
+done
 IFS=$as_save_IFS
 
 fi
 fi
 FC=$ac_cv_prog_FC
 if test -n "$FC"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $FC" >&5
+  { $as_echo "$as_me:$LINENO: result: $FC" >&5
 $as_echo "$FC" >&6; }
 else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+  { $as_echo "$as_me:$LINENO: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
@@ -2869,13 +2598,13 @@
 fi
 if test -z "$FC"; then
   ac_ct_FC=$FC
-  for ac_prog in gfortran g95 xlf95 f95 fort ifort ifc efc pgfortran pgf95 lf95 ftn nagfor xlf90 f90 pgf90 pghpf epcf90 g77 xlf f77 frt pgf77 cf77 fort77 fl32 af77
+  for ac_prog in gfortran g95 xlf95 f95 fort ifort ifc efc pgf95 lf95 ftn xlf90 f90 pgf90 pghpf epcf90 g77 xlf f77 frt pgf77 cf77 fort77 fl32 af77
 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 "$as_me:$LINENO: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_prog_ac_ct_FC+:} false; then :
+if test "${ac_cv_prog_ac_ct_FC+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
   if test -n "$ac_ct_FC"; then
@@ -2886,24 +2615,24 @@
 do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
     ac_cv_prog_ac_ct_FC="$ac_prog"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
 done
-  done
+done
 IFS=$as_save_IFS
 
 fi
 fi
 ac_ct_FC=$ac_cv_prog_ac_ct_FC
 if test -n "$ac_ct_FC"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_FC" >&5
+  { $as_echo "$as_me:$LINENO: result: $ac_ct_FC" >&5
 $as_echo "$ac_ct_FC" >&6; }
 else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+  { $as_echo "$as_me:$LINENO: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
@@ -2916,7 +2645,7 @@
   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:$LINENO: WARNING: using cross tools not prefixed with host triplet" >&5
 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
 ac_tool_warned=yes ;;
 esac
@@ -2926,32 +2655,45 @@
 
 
 # Provide some information about the compiler.
-$as_echo "$as_me:${as_lineno-$LINENO}: checking for Fortran compiler version" >&5
+$as_echo "$as_me:$LINENO: checking for Fortran compiler version" >&5
 set X $ac_compile
 ac_compiler=$2
-for ac_option in --version -v -V -qversion; do
-  { { ac_try="$ac_compiler $ac_option >&5"
+{ (ac_try="$ac_compiler --version >&5"
 case "(($ac_try" in
   *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
   *) ac_try_echo=$ac_try;;
 esac
-eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
-$as_echo "$ac_try_echo"; } >&5
-  (eval "$ac_compiler $ac_option >&5") 2>conftest.err
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compiler --version >&5") 2>&5
   ac_status=$?
-  if test -s conftest.err; then
-    sed '10a\
-... rest of stderr output deleted ...
-         10q' conftest.err >conftest.er1
-    cat conftest.er1 >&5
-  fi
-  rm -f conftest.er1 conftest.err
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; }
-done
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }
+{ (ac_try="$ac_compiler -v >&5"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compiler -v >&5") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }
+{ (ac_try="$ac_compiler -V >&5"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compiler -V >&5") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }
 rm -f a.out
 
-cat > conftest.$ac_ext <<_ACEOF
+cat >conftest.$ac_ext <<_ACEOF
       program main
 
       end
@@ -2961,8 +2703,8 @@
 # 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 Fortran compiler works" >&5
-$as_echo_n "checking whether the Fortran compiler works... " >&6; }
+{ $as_echo "$as_me:$LINENO: checking for Fortran compiler default output file name" >&5
+$as_echo_n "checking for Fortran compiler default output file name... " >&6; }
 ac_link_default=`$as_echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'`
 
 # The possible output files:
@@ -2978,17 +2720,17 @@
 done
 rm -f $ac_rmfiles
 
-if { { ac_try="$ac_link_default"
+if { (ac_try="$ac_link_default"
 case "(($ac_try" in
   *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
   *) ac_try_echo=$ac_try;;
 esac
-eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
-$as_echo "$ac_try_echo"; } >&5
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
   (eval "$ac_link_default") 2>&5
   ac_status=$?
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; }; then :
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; 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,
@@ -3005,7 +2747,7 @@
 	# certainly right.
 	break;;
     *.* )
-	if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no;
+        if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no;
 	then :; else
 	   ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
 	fi
@@ -3024,41 +2766,84 @@
 else
   ac_file=''
 fi
-if test -z "$ac_file"; then :
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-$as_echo "$as_me: failed program was:" >&5
+
+{ $as_echo "$as_me:$LINENO: result: $ac_file" >&5
+$as_echo "$ac_file" >&6; }
+if test -z "$ac_file"; then
+  $as_echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+{ { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error 77 "Fortran 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; }
+{ { $as_echo "$as_me:$LINENO: error: Fortran compiler cannot create executables
+See \`config.log' for more details." >&5
+$as_echo "$as_me: error: Fortran compiler cannot create executables
+See \`config.log' for more details." >&2;}
+   { (exit 77); exit 77; }; }; }
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for Fortran compiler default output file name" >&5
-$as_echo_n "checking for Fortran compiler default output file name... " >&6; }
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5
-$as_echo "$ac_file" >&6; }
+
 ac_exeext=$ac_cv_exeext
 
+# Check that the compiler produces executables we can run.  If not, either
+# the compiler is broken, or we cross compile.
+{ $as_echo "$as_me:$LINENO: checking whether the Fortran compiler works" >&5
+$as_echo_n "checking whether the Fortran compiler works... " >&6; }
+# FIXME: These cross compiler hacks should be removed for Autoconf 3.0
+# If not cross compiling, check that we can run a simple program.
+if test "$cross_compiling" != yes; then
+  if { ac_try='./$ac_file'
+  { (case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_try") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+    cross_compiling=no
+  else
+    if test "$cross_compiling" = maybe; then
+	cross_compiling=yes
+    else
+	{ { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+{ { $as_echo "$as_me:$LINENO: error: cannot run Fortran compiled programs.
+If you meant to cross compile, use \`--host'.
+See \`config.log' for more details." >&5
+$as_echo "$as_me: error: cannot run Fortran compiled programs.
+If you meant to cross compile, use \`--host'.
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }; }
+    fi
+  fi
+fi
+{ $as_echo "$as_me:$LINENO: result: yes" >&5
+$as_echo "yes" >&6; }
+
 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
+# Check that the compiler produces executables we can run.  If not, either
+# the compiler is broken, or we cross compile.
+{ $as_echo "$as_me:$LINENO: checking whether we are cross compiling" >&5
+$as_echo_n "checking whether we are cross compiling... " >&6; }
+{ $as_echo "$as_me:$LINENO: result: $cross_compiling" >&5
+$as_echo "$cross_compiling" >&6; }
+
+{ $as_echo "$as_me:$LINENO: checking for suffix of executables" >&5
 $as_echo_n "checking for suffix of executables... " >&6; }
-if { { ac_try="$ac_link"
+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_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
   (eval "$ac_link") 2>&5
   ac_status=$?
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; }; then :
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; 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
@@ -3073,93 +2858,44 @@
   esac
 done
 else
-  { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+  { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "cannot compute suffix of executables: cannot compile and link
-See \`config.log' for more details" "$LINENO" 5; }
+{ { $as_echo "$as_me:$LINENO: error: cannot compute suffix of executables: cannot compile and link
+See \`config.log' for more details." >&5
+$as_echo "$as_me: error: cannot compute suffix of executables: cannot compile and link
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }; }
 fi
-rm -f conftest conftest$ac_cv_exeext
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5
+
+rm -f conftest$ac_cv_exeext
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_exeext" >&5
 $as_echo "$ac_cv_exeext" >&6; }
 
 rm -f conftest.$ac_ext
 EXEEXT=$ac_cv_exeext
 ac_exeext=$EXEEXT
-cat > conftest.$ac_ext <<_ACEOF
-      program main
-      open(unit=9,file='conftest.out')
-      close(unit=9)
-
-      end
-_ACEOF
-ac_clean_files="$ac_clean_files conftest.out"
-# Check that the compiler produces executables we can run.  If not, either
-# the compiler is broken, or we cross compile.
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5
-$as_echo_n "checking whether we are cross compiling... " >&6; }
-if test "$cross_compiling" != yes; then
-  { { ac_try="$ac_link"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
-$as_echo "$ac_try_echo"; } >&5
-  (eval "$ac_link") 2>&5
-  ac_status=$?
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; }
-  if { ac_try='./conftest$ac_cv_exeext'
-  { { case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
-$as_echo "$ac_try_echo"; } >&5
-  (eval "$ac_try") 2>&5
-  ac_status=$?
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; }; }; then
-    cross_compiling=no
-  else
-    if test "$cross_compiling" = maybe; then
-	cross_compiling=yes
-    else
-	{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "cannot run Fortran compiled programs.
-If you meant to cross compile, use \`--host'.
-See \`config.log' for more details" "$LINENO" 5; }
-    fi
-  fi
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5
-$as_echo "$cross_compiling" >&6; }
-
-rm -f conftest.$ac_ext conftest$ac_cv_exeext conftest.out
-ac_clean_files=$ac_clean_files_save
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5
+{ $as_echo "$as_me:$LINENO: checking for suffix of object files" >&5
 $as_echo_n "checking for suffix of object files... " >&6; }
-if ${ac_cv_objext+:} false; then :
+if test "${ac_cv_objext+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
-  cat > conftest.$ac_ext <<_ACEOF
+  cat >conftest.$ac_ext <<_ACEOF
       program main
 
       end
 _ACEOF
 rm -f conftest.o conftest.obj
-if { { ac_try="$ac_compile"
+if { (ac_try="$ac_compile"
 case "(($ac_try" in
   *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
   *) ac_try_echo=$ac_try;;
 esac
-eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
-$as_echo "$ac_try_echo"; } >&5
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
   (eval "$ac_compile") 2>&5
   ac_status=$?
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; }; then :
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; then
   for ac_file in conftest.o conftest.obj conftest.*; do
   test -f "$ac_file" || continue;
   case $ac_file in
@@ -3172,14 +2908,18 @@
   $as_echo "$as_me: failed program was:" >&5
 sed 's/^/| /' conftest.$ac_ext >&5
 
-{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+{ { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "cannot compute suffix of object files: cannot compile
-See \`config.log' for more details" "$LINENO" 5; }
+{ { $as_echo "$as_me:$LINENO: error: cannot compute suffix of object files: cannot compile
+See \`config.log' for more details." >&5
+$as_echo "$as_me: error: cannot compute suffix of object files: cannot compile
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }; }
 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 "$as_me:$LINENO: result: $ac_cv_objext" >&5
 $as_echo "$ac_cv_objext" >&6; }
 OBJEXT=$ac_cv_objext
 ac_objext=$OBJEXT
@@ -3187,12 +2927,12 @@
 # input file.  (Note that this only needs to work for GNU compilers.)
 ac_save_ext=$ac_ext
 ac_ext=F
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU Fortran compiler" >&5
+{ $as_echo "$as_me:$LINENO: checking whether we are using the GNU Fortran compiler" >&5
 $as_echo_n "checking whether we are using the GNU Fortran compiler... " >&6; }
-if ${ac_cv_fc_compiler_gnu+:} false; then :
+if test "${ac_cv_fc_compiler_gnu+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
-  cat > conftest.$ac_ext <<_ACEOF
+  cat >conftest.$ac_ext <<_ACEOF
       program main
 #ifndef __GNUC__
        choke me
@@ -3200,44 +2940,86 @@
 
       end
 _ACEOF
-if ac_fn_fc_try_compile "$LINENO"; then :
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_fc_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
   ac_compiler_gnu=yes
 else
-  ac_compiler_gnu=no
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_compiler_gnu=no
 fi
+
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 ac_cv_fc_compiler_gnu=$ac_compiler_gnu
 
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_fc_compiler_gnu" >&5
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_fc_compiler_gnu" >&5
 $as_echo "$ac_cv_fc_compiler_gnu" >&6; }
 ac_ext=$ac_save_ext
-ac_test_FCFLAGS=${FCFLAGS+set}
-ac_save_FCFLAGS=$FCFLAGS
+ac_test_FFLAGS=${FCFLAGS+set}
+ac_save_FFLAGS=$FCFLAGS
 FCFLAGS=
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $FC accepts -g" >&5
+{ $as_echo "$as_me:$LINENO: checking whether $FC accepts -g" >&5
 $as_echo_n "checking whether $FC accepts -g... " >&6; }
-if ${ac_cv_prog_fc_g+:} false; then :
+if test "${ac_cv_prog_fc_g+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
   FCFLAGS=-g
-cat > conftest.$ac_ext <<_ACEOF
+cat >conftest.$ac_ext <<_ACEOF
       program main
 
       end
 _ACEOF
-if ac_fn_fc_try_compile "$LINENO"; then :
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_fc_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
   ac_cv_prog_fc_g=yes
 else
-  ac_cv_prog_fc_g=no
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_cv_prog_fc_g=no
 fi
+
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_fc_g" >&5
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_prog_fc_g" >&5
 $as_echo "$ac_cv_prog_fc_g" >&6; }
-if test "$ac_test_FCFLAGS" = set; then
-  FCFLAGS=$ac_save_FCFLAGS
+if test "$ac_test_FFLAGS" = set; then
+  FCFLAGS=$ac_save_FFLAGS
 elif test $ac_cv_prog_fc_g = yes; then
   if test "x$ac_cv_fc_compiler_gnu" = xyes; then
     FCFLAGS="-g -O2"
@@ -3252,11 +3034,6 @@
   fi
 fi
 
-if test $ac_compiler_gnu = yes; then
-  GFC=yes
-else
-  GFC=
-fi
 ac_ext=c
 ac_cpp='$CPP $CPPFLAGS'
 ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
@@ -3271,10 +3048,12 @@
 
 
 flags_guess="$SHELL flags.guess"
-{ $as_echo "$as_me:${as_lineno-$LINENO}: running $flags_guess" >&5
+{ $as_echo "$as_me:$LINENO: running $flags_guess" >&5
 $as_echo "$as_me: running $flags_guess" >&6;}
 flags=`$flags_guess` ||
-    as_fn_error $? "$flags_guess failed" "$LINENO" 5
+    { { $as_echo "$as_me:$LINENO: error: $flags_guess failed" >&5
+$as_echo "$as_me: error: $flags_guess failed" >&2;}
+   { (exit 1); exit 1; }; }
 eval $flags
 
 
@@ -3282,21 +3061,38 @@
 ac_compile='$FC -c $FCFLAGS $ac_fcflags_srcext conftest.$ac_ext >&5'
 ac_link='$FC -o conftest$ac_exeext $FCFLAGS $LDFLAGS $ac_fcflags_srcext conftest.$ac_ext $LIBS >&5'
 ac_compiler_gnu=$ac_cv_fc_compiler_gnu
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to get verbose linking output from $FC" >&5
+{ $as_echo "$as_me:$LINENO: checking how to get verbose linking output from $FC" >&5
 $as_echo_n "checking how to get verbose linking output from $FC... " >&6; }
-if ${ac_cv_prog_fc_v+:} false; then :
+if test "${ac_cv_prog_fc_v+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
-  cat > conftest.$ac_ext <<_ACEOF
+  cat >conftest.$ac_ext <<_ACEOF
       program main
 
       end
 _ACEOF
-if ac_fn_fc_try_compile "$LINENO"; then :
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_fc_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
   ac_cv_prog_fc_v=
 # Try some options frequently used verbose output
 for ac_verb in -v -verbose --verbose -V -\#\#\#; do
-  cat > conftest.$ac_ext <<_ACEOF
+  cat >conftest.$ac_ext <<_ACEOF
       program main
 
       end
@@ -3306,18 +3102,17 @@
 # 1 to this macro) to the Fortran compiler in order to get
 # "verbose" output that we can then parse for the Fortran linker
 # flags.
-ac_save_FCFLAGS=$FCFLAGS
+ac_save_FFLAGS=$FCFLAGS
 FCFLAGS="$FCFLAGS $ac_verb"
 eval "set x $ac_link"
 shift
-$as_echo "$as_me:${as_lineno-$LINENO}: $*" >&5
+$as_echo "$as_me:$LINENO: $*" >&5
 # gfortran 4.3 outputs lines setting COLLECT_GCC_OPTIONS, COMPILER_PATH,
 # LIBRARY_PATH; skip all such settings.
 ac_fc_v_output=`eval $ac_link 5>&1 2>&1 |
-  sed '/^Driving:/d; /^Configured with:/d;
-      '"/^[_$as_cr_Letters][_$as_cr_alnum]*=/d"`
+  grep -v 'Driving:' | grep -v "^[_$as_cr_Letters][_$as_cr_alnum]*="`
 $as_echo "$ac_fc_v_output" >&5
-FCFLAGS=$ac_save_FCFLAGS
+FCFLAGS=$ac_save_FFLAGS
 
 rm -rf conftest*
 
@@ -3332,16 +3127,9 @@
 #        that detects unbalanced quotes in FLIBS should be implemented
 #        and (ugh) tested at some point.
 case $ac_fc_v_output in
-  # With xlf replace commas with spaces,
-  # and remove "-link" and closing parenthesis.
+  # If we are using xlf then replace all the commas with spaces.
   *xlfentry*)
-    ac_fc_v_output=`echo $ac_fc_v_output |
-      sed '
-        s/,/ /g
-        s/ -link / /g
-        s/) *$//
-      '
-    ` ;;
+    ac_fc_v_output=`echo $ac_fc_v_output | sed 's/,/ /g'` ;;
 
   # With Intel ifc, ignore the quoted -mGLOB_options_string stuff (quoted
   # $LIBS confuse us, and the libraries appear later in the output anyway).
@@ -3353,20 +3141,10 @@
   # Doubly-quoted arguments were reported for "PGF90/x86 Linux/x86 5.0-2".
   *-cmdline\ * | *-ignore\ * | *-def\ *)
     ac_fc_v_output=`echo $ac_fc_v_output | sed "\
-	s/-cmdline  *'[^']*'/ /g; s/-cmdline  *\"[^\"]*\"/ /g
-	s/-ignore  *'[^']*'/ /g; s/-ignore  *\"[^\"]*\"/ /g
-	s/-def  *'[^']*'/ /g; s/-def  *\"[^\"]*\"/ /g"` ;;
+        s/-cmdline  *'[^']*'/ /g; s/-cmdline  *\"[^\"]*\"/ /g
+        s/-ignore  *'[^']*'/ /g; s/-ignore  *\"[^\"]*\"/ /g
+        s/-def  *'[^']*'/ /g; s/-def  *\"[^\"]*\"/ /g"` ;;
 
-  # If we are using fort77 (the f2c wrapper) then filter output and delete quotes.
-  *fort77*f2c*gcc*)
-    ac_fc_v_output=`echo "$ac_fc_v_output" | sed -n '
-        /:[	 ]\+Running[	 ]\{1,\}"gcc"/{
-          /"-c"/d
-          /[.]c"*/d
-          s/^.*"gcc"/"gcc"/
-          s/"//gp
-        }'` ;;
-
   # If we are using Cray Fortran then delete quotes.
   *cft90*)
     ac_fc_v_output=`echo $ac_fc_v_output | sed 's/"//g'` ;;
@@ -3376,35 +3154,39 @@
   # look for -l* and *.a constructs in the output
   for ac_arg in $ac_fc_v_output; do
      case $ac_arg in
-	[\\/]*.a | ?:[\\/]*.a | -[lLRu]*)
-	  ac_cv_prog_fc_v=$ac_verb
-	  break 2 ;;
+        [\\/]*.a | ?:[\\/]*.a | -[lLRu]*)
+          ac_cv_prog_fc_v=$ac_verb
+          break 2 ;;
      esac
   done
 done
 if test -z "$ac_cv_prog_fc_v"; then
-   { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cannot determine how to obtain linking information from $FC" >&5
+   { $as_echo "$as_me:$LINENO: WARNING: cannot determine how to obtain linking information from $FC" >&5
 $as_echo "$as_me: WARNING: cannot determine how to obtain linking information from $FC" >&2;}
 fi
 else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: compilation failed" >&5
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	{ $as_echo "$as_me:$LINENO: WARNING: compilation failed" >&5
 $as_echo "$as_me: WARNING: compilation failed" >&2;}
 fi
+
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_fc_v" >&5
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_prog_fc_v" >&5
 $as_echo "$ac_cv_prog_fc_v" >&6; }
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for Fortran libraries of $FC" >&5
+{ $as_echo "$as_me:$LINENO: checking for Fortran libraries of $FC" >&5
 $as_echo_n "checking for Fortran libraries of $FC... " >&6; }
-if ${ac_cv_fc_libs+:} false; then :
+if test "${ac_cv_fc_libs+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
   if test "x$FCLIBS" != "x"; then
   ac_cv_fc_libs="$FCLIBS" # Let the user override the test.
 else
 
-cat > conftest.$ac_ext <<_ACEOF
+cat >conftest.$ac_ext <<_ACEOF
       program main
 
       end
@@ -3414,18 +3196,17 @@
 # 1 to this macro) to the Fortran compiler in order to get
 # "verbose" output that we can then parse for the Fortran linker
 # flags.
-ac_save_FCFLAGS=$FCFLAGS
+ac_save_FFLAGS=$FCFLAGS
 FCFLAGS="$FCFLAGS $ac_cv_prog_fc_v"
 eval "set x $ac_link"
 shift
-$as_echo "$as_me:${as_lineno-$LINENO}: $*" >&5
+$as_echo "$as_me:$LINENO: $*" >&5
 # gfortran 4.3 outputs lines setting COLLECT_GCC_OPTIONS, COMPILER_PATH,
 # LIBRARY_PATH; skip all such settings.
 ac_fc_v_output=`eval $ac_link 5>&1 2>&1 |
-  sed '/^Driving:/d; /^Configured with:/d;
-      '"/^[_$as_cr_Letters][_$as_cr_alnum]*=/d"`
+  grep -v 'Driving:' | grep -v "^[_$as_cr_Letters][_$as_cr_alnum]*="`
 $as_echo "$ac_fc_v_output" >&5
-FCFLAGS=$ac_save_FCFLAGS
+FCFLAGS=$ac_save_FFLAGS
 
 rm -rf conftest*
 
@@ -3440,16 +3221,9 @@
 #        that detects unbalanced quotes in FLIBS should be implemented
 #        and (ugh) tested at some point.
 case $ac_fc_v_output in
-  # With xlf replace commas with spaces,
-  # and remove "-link" and closing parenthesis.
+  # If we are using xlf then replace all the commas with spaces.
   *xlfentry*)
-    ac_fc_v_output=`echo $ac_fc_v_output |
-      sed '
-        s/,/ /g
-        s/ -link / /g
-        s/) *$//
-      '
-    ` ;;
+    ac_fc_v_output=`echo $ac_fc_v_output | sed 's/,/ /g'` ;;
 
   # With Intel ifc, ignore the quoted -mGLOB_options_string stuff (quoted
   # $LIBS confuse us, and the libraries appear later in the output anyway).
@@ -3461,20 +3235,10 @@
   # Doubly-quoted arguments were reported for "PGF90/x86 Linux/x86 5.0-2".
   *-cmdline\ * | *-ignore\ * | *-def\ *)
     ac_fc_v_output=`echo $ac_fc_v_output | sed "\
-	s/-cmdline  *'[^']*'/ /g; s/-cmdline  *\"[^\"]*\"/ /g
-	s/-ignore  *'[^']*'/ /g; s/-ignore  *\"[^\"]*\"/ /g
-	s/-def  *'[^']*'/ /g; s/-def  *\"[^\"]*\"/ /g"` ;;
+        s/-cmdline  *'[^']*'/ /g; s/-cmdline  *\"[^\"]*\"/ /g
+        s/-ignore  *'[^']*'/ /g; s/-ignore  *\"[^\"]*\"/ /g
+        s/-def  *'[^']*'/ /g; s/-def  *\"[^\"]*\"/ /g"` ;;
 
-  # If we are using fort77 (the f2c wrapper) then filter output and delete quotes.
-  *fort77*f2c*gcc*)
-    ac_fc_v_output=`echo "$ac_fc_v_output" | sed -n '
-        /:[	 ]\+Running[	 ]\{1,\}"gcc"/{
-          /"-c"/d
-          /[.]c"*/d
-          s/^.*"gcc"/"gcc"/
-          s/"//gp
-        }'` ;;
-
   # If we are using Cray Fortran then delete quotes.
   *cft90*)
     ac_fc_v_output=`echo $ac_fc_v_output | sed 's/"//g'` ;;
@@ -3492,8 +3256,8 @@
   shift
   ac_arg=$1
   case $ac_arg in
-	[\\/]*.a | ?:[\\/]*.a)
-	    ac_exists=false
+        [\\/]*.a | ?:[\\/]*.a)
+            ac_exists=false
   for ac_i in $ac_cv_fc_libs; do
     if test x"$ac_arg" = x"$ac_i"; then
       ac_exists=true
@@ -3501,14 +3265,15 @@
     fi
   done
 
-  if test x"$ac_exists" = xtrue; then :
-
+  if test x"$ac_exists" = xtrue; then
+  :
 else
   ac_cv_fc_libs="$ac_cv_fc_libs $ac_arg"
 fi
-	  ;;
-	-bI:*)
-	    ac_exists=false
+
+          ;;
+        -bI:*)
+            ac_exists=false
   for ac_i in $ac_cv_fc_libs; do
     if test x"$ac_arg" = x"$ac_i"; then
       ac_exists=true
@@ -3516,8 +3281,8 @@
     fi
   done
 
-  if test x"$ac_exists" = xtrue; then :
-
+  if test x"$ac_exists" = xtrue; then
+  :
 else
   if test "$ac_compiler_gnu" = yes; then
   for ac_link_opt in $ac_arg; do
@@ -3527,22 +3292,18 @@
   ac_cv_fc_libs="$ac_cv_fc_libs $ac_arg"
 fi
 fi
-	  ;;
-	  # Ignore these flags.
-	-lang* | -lcrt*.o | -lc | -lgcc* | -lSystem | -libmil | -little \
-	  |-LANG:=* | -LIST:* | -LNO:* | -link)
-	  ;;
-	-lkernel32)
-	  case $host_os in
-	  *cygwin*) ;;
-	  *) ac_cv_fc_libs="$ac_cv_fc_libs $ac_arg"
-	    ;;
-	  esac
-	  ;;
-	-[LRuYz])
-	  # These flags, when seen by themselves, take an argument.
-	  # We remove the space between option and argument and re-iterate
-	  # unless we find an empty arg or a new option (starting with -)
+
+          ;;
+          # Ignore these flags.
+        -lang* | -lcrt*.o | -lc | -lgcc* | -lSystem | -libmil | -LANG:=* | -LIST:* | -LNO:*)
+          ;;
+        -lkernel32)
+          test x"$CYGWIN" != xyes && ac_cv_fc_libs="$ac_cv_fc_libs $ac_arg"
+          ;;
+        -[LRuYz])
+          # These flags, when seen by themselves, take an argument.
+          # We remove the space between option and argument and re-iterate
+          # unless we find an empty arg or a new option (starting with -)
 	  case $2 in
 	     "" | -*);;
 	     *)
@@ -3551,10 +3312,10 @@
 		set X $ac_arg "$@"
 		;;
 	  esac
-	  ;;
-	-YP,*)
-	  for ac_j in `$as_echo "$ac_arg" | sed -e 's/-YP,/-L/;s/:/ -L/g'`; do
-	      ac_exists=false
+          ;;
+        -YP,*)
+          for ac_j in `$as_echo "$ac_arg" | sed -e 's/-YP,/-L/;s/:/ -L/g'`; do
+              ac_exists=false
   for ac_i in $ac_cv_fc_libs; do
     if test x"$ac_j" = x"$ac_i"; then
       ac_exists=true
@@ -3562,16 +3323,17 @@
     fi
   done
 
-  if test x"$ac_exists" = xtrue; then :
-
+  if test x"$ac_exists" = xtrue; then
+  :
 else
   ac_arg="$ac_arg $ac_j"
-			       ac_cv_fc_libs="$ac_cv_fc_libs $ac_j"
+                               ac_cv_fc_libs="$ac_cv_fc_libs $ac_j"
 fi
-	  done
-	  ;;
-	-[lLR]*)
-	    ac_exists=false
+
+          done
+          ;;
+        -[lLR]*)
+            ac_exists=false
   for ac_i in $ac_cv_fc_libs; do
     if test x"$ac_arg" = x"$ac_i"; then
       ac_exists=true
@@ -3579,16 +3341,17 @@
     fi
   done
 
-  if test x"$ac_exists" = xtrue; then :
-
+  if test x"$ac_exists" = xtrue; then
+  :
 else
   ac_cv_fc_libs="$ac_cv_fc_libs $ac_arg"
 fi
-	  ;;
+
+          ;;
 	-zallextract*| -zdefaultextract)
 	  ac_cv_fc_libs="$ac_cv_fc_libs $ac_arg"
 	  ;;
-	  # Ignore everything else.
+          # Ignore everything else.
   esac
 done
 # restore positional arguments
@@ -3600,9 +3363,9 @@
 case `(uname -sr) 2>/dev/null` in
    "SunOS 5"*)
       ac_ld_run_path=`$as_echo "$ac_fc_v_output" |
-			sed -n 's,^.*LD_RUN_PATH *= *\(/[^ ]*\).*$,-R\1,p'`
+                        sed -n 's,^.*LD_RUN_PATH *= *\(/[^ ]*\).*$,-R\1,p'`
       test "x$ac_ld_run_path" != x &&
-	if test "$ac_compiler_gnu" = yes; then
+        if test "$ac_compiler_gnu" = yes; then
   for ac_link_opt in $ac_ld_run_path; do
     ac_cv_fc_libs="$ac_cv_fc_libs -Xlinker $ac_link_opt"
   done
@@ -3614,7 +3377,7 @@
 fi # test "x$[]_AC_LANG_PREFIX[]LIBS" = "x"
 
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_fc_libs" >&5
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_fc_libs" >&5
 $as_echo "$ac_cv_fc_libs" >&6; }
 FCLIBS="$ac_cv_fc_libs"
 
@@ -3633,9 +3396,9 @@
 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 "$as_me:$LINENO: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_prog_CC+:} false; then :
+if test "${ac_cv_prog_CC+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
   if test -n "$CC"; then
@@ -3646,24 +3409,24 @@
 do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$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
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
 done
-  done
+done
 IFS=$as_save_IFS
 
 fi
 fi
 CC=$ac_cv_prog_CC
 if test -n "$CC"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+  { $as_echo "$as_me:$LINENO: result: $CC" >&5
 $as_echo "$CC" >&6; }
 else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+  { $as_echo "$as_me:$LINENO: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
@@ -3673,9 +3436,9 @@
   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 "$as_me:$LINENO: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_prog_ac_ct_CC+:} false; then :
+if test "${ac_cv_prog_ac_ct_CC+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
   if test -n "$ac_ct_CC"; then
@@ -3686,24 +3449,24 @@
 do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$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
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
 done
-  done
+done
 IFS=$as_save_IFS
 
 fi
 fi
 ac_ct_CC=$ac_cv_prog_ac_ct_CC
 if test -n "$ac_ct_CC"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
+  { $as_echo "$as_me:$LINENO: result: $ac_ct_CC" >&5
 $as_echo "$ac_ct_CC" >&6; }
 else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+  { $as_echo "$as_me:$LINENO: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
@@ -3712,7 +3475,7 @@
   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:$LINENO: WARNING: using cross tools not prefixed with host triplet" >&5
 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
 ac_tool_warned=yes ;;
 esac
@@ -3726,9 +3489,9 @@
           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 "$as_me:$LINENO: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_prog_CC+:} false; then :
+if test "${ac_cv_prog_CC+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
   if test -n "$CC"; then
@@ -3739,24 +3502,24 @@
 do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$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
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
 done
-  done
+done
 IFS=$as_save_IFS
 
 fi
 fi
 CC=$ac_cv_prog_CC
 if test -n "$CC"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+  { $as_echo "$as_me:$LINENO: result: $CC" >&5
 $as_echo "$CC" >&6; }
 else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+  { $as_echo "$as_me:$LINENO: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
@@ -3766,9 +3529,9 @@
 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 "$as_me:$LINENO: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_prog_CC+:} false; then :
+if test "${ac_cv_prog_CC+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
   if test -n "$CC"; then
@@ -3780,18 +3543,18 @@
 do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$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
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
 done
-  done
+done
 IFS=$as_save_IFS
 
 if test $ac_prog_rejected = yes; then
@@ -3810,10 +3573,10 @@
 fi
 CC=$ac_cv_prog_CC
 if test -n "$CC"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+  { $as_echo "$as_me:$LINENO: result: $CC" >&5
 $as_echo "$CC" >&6; }
 else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+  { $as_echo "$as_me:$LINENO: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
@@ -3825,9 +3588,9 @@
   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 "$as_me:$LINENO: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_prog_CC+:} false; then :
+if test "${ac_cv_prog_CC+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
   if test -n "$CC"; then
@@ -3838,24 +3601,24 @@
 do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$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
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
 done
-  done
+done
 IFS=$as_save_IFS
 
 fi
 fi
 CC=$ac_cv_prog_CC
 if test -n "$CC"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+  { $as_echo "$as_me:$LINENO: result: $CC" >&5
 $as_echo "$CC" >&6; }
 else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+  { $as_echo "$as_me:$LINENO: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
@@ -3869,9 +3632,9 @@
 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 "$as_me:$LINENO: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_prog_ac_ct_CC+:} false; then :
+if test "${ac_cv_prog_ac_ct_CC+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
   if test -n "$ac_ct_CC"; then
@@ -3882,24 +3645,24 @@
 do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$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
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
 done
-  done
+done
 IFS=$as_save_IFS
 
 fi
 fi
 ac_ct_CC=$ac_cv_prog_ac_ct_CC
 if test -n "$ac_ct_CC"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
+  { $as_echo "$as_me:$LINENO: result: $ac_ct_CC" >&5
 $as_echo "$ac_ct_CC" >&6; }
 else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+  { $as_echo "$as_me:$LINENO: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
@@ -3912,7 +3675,7 @@
   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:$LINENO: WARNING: using cross tools not prefixed with host triplet" >&5
 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
 ac_tool_warned=yes ;;
 esac
@@ -3923,42 +3686,62 @@
 fi
 
 
-test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+test -z "$CC" && { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "no acceptable C compiler found in \$PATH
-See \`config.log' for more details" "$LINENO" 5; }
+{ { $as_echo "$as_me:$LINENO: error: no acceptable C compiler found in \$PATH
+See \`config.log' for more details." >&5
+$as_echo "$as_me: error: no acceptable C compiler found in \$PATH
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }; }
 
 # Provide some information about the compiler.
-$as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5
+$as_echo "$as_me:$LINENO: checking for C compiler version" >&5
 set X $ac_compile
 ac_compiler=$2
-for ac_option in --version -v -V -qversion; do
-  { { ac_try="$ac_compiler $ac_option >&5"
+{ (ac_try="$ac_compiler --version >&5"
 case "(($ac_try" in
   *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
   *) ac_try_echo=$ac_try;;
 esac
-eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
-$as_echo "$ac_try_echo"; } >&5
-  (eval "$ac_compiler $ac_option >&5") 2>conftest.err
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compiler --version >&5") 2>&5
   ac_status=$?
-  if test -s conftest.err; then
-    sed '10a\
-... rest of stderr output deleted ...
-         10q' conftest.err >conftest.er1
-    cat conftest.er1 >&5
-  fi
-  rm -f conftest.er1 conftest.err
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; }
-done
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }
+{ (ac_try="$ac_compiler -v >&5"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compiler -v >&5") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }
+{ (ac_try="$ac_compiler -V >&5"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compiler -V >&5") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5
+{ $as_echo "$as_me:$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 :
+if test "${ac_cv_c_compiler_gnu+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
-  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 
 #ifdef FC_DUMMY_MAIN
@@ -3980,16 +3763,37 @@
   return 0;
 }
 _ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
   ac_compiler_gnu=yes
 else
-  ac_compiler_gnu=no
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_compiler_gnu=no
 fi
+
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 ac_cv_c_compiler_gnu=$ac_compiler_gnu
 
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_c_compiler_gnu" >&5
 $as_echo "$ac_cv_c_compiler_gnu" >&6; }
 if test $ac_compiler_gnu = yes; then
   GCC=yes
@@ -3998,16 +3802,20 @@
 fi
 ac_test_CFLAGS=${CFLAGS+set}
 ac_save_CFLAGS=$CFLAGS
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5
+{ $as_echo "$as_me:$LINENO: checking whether $CC accepts -g" >&5
 $as_echo_n "checking whether $CC accepts -g... " >&6; }
-if ${ac_cv_prog_cc_g+:} false; then :
+if test "${ac_cv_prog_cc_g+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
   ac_save_c_werror_flag=$ac_c_werror_flag
    ac_c_werror_flag=yes
    ac_cv_prog_cc_g=no
    CFLAGS="-g"
-   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+   cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 
 #ifdef FC_DUMMY_MAIN
@@ -4026,11 +3834,35 @@
   return 0;
 }
 _ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
   ac_cv_prog_cc_g=yes
 else
-  CFLAGS=""
-      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	CFLAGS=""
+      cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 
 #ifdef FC_DUMMY_MAIN
@@ -4049,12 +3881,36 @@
   return 0;
 }
 _ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  :
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
 
-else
-  ac_c_werror_flag=$ac_save_c_werror_flag
+	ac_c_werror_flag=$ac_save_c_werror_flag
 	 CFLAGS="-g"
-	 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+	 cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 
 #ifdef FC_DUMMY_MAIN
@@ -4073,17 +3929,42 @@
   return 0;
 }
 _ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
   ac_cv_prog_cc_g=yes
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+
 fi
+
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
+
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
+
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
    ac_c_werror_flag=$ac_save_c_werror_flag
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_prog_cc_g" >&5
 $as_echo "$ac_cv_prog_cc_g" >&6; }
 if test "$ac_test_CFLAGS" = set; then
   CFLAGS=$ac_save_CFLAGS
@@ -4100,18 +3981,23 @@
     CFLAGS=
   fi
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5
+{ $as_echo "$as_me:$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 :
+if test "${ac_cv_prog_cc_c89+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
   ac_cv_prog_cc_c89=no
 ac_save_CC=$CC
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 #include <stdarg.h>
 #include <stdio.h>
-struct stat;
+#include <sys/types.h>
+#include <sys/stat.h>
 /* 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);
@@ -4171,9 +4057,32 @@
 	-Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"
 do
   CC="$ac_save_CC $ac_arg"
-  if ac_fn_c_try_compile "$LINENO"; then :
+  rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
   ac_cv_prog_cc_c89=$ac_arg
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+
 fi
+
 rm -f core conftest.err conftest.$ac_objext
   test "x$ac_cv_prog_cc_c89" != "xno" && break
 done
@@ -4184,19 +4093,17 @@
 # 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 "$as_me:$LINENO: result: none needed" >&5
 $as_echo "none needed" >&6; } ;;
   xno)
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5
+    { $as_echo "$as_me:$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 "$as_me:$LINENO: result: $ac_cv_prog_cc_c89" >&5
 $as_echo "$ac_cv_prog_cc_c89" >&6; } ;;
 esac
-if test "x$ac_cv_prog_cc_c89" != xno; then :
 
-fi
 
 ac_ext=c
 ac_cpp='$CPP $CPPFLAGS'
@@ -4210,9 +4117,9 @@
 ac_link='$FC -o conftest$ac_exeext $FCFLAGS $LDFLAGS $ac_fcflags_srcext conftest.$ac_ext $LIBS >&5'
 ac_compiler_gnu=$ac_cv_fc_compiler_gnu
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for dummy main to link with Fortran libraries" >&5
+{ $as_echo "$as_me:$LINENO: checking for dummy main to link with Fortran libraries" >&5
 $as_echo_n "checking for dummy main to link with Fortran libraries... " >&6; }
-if ${ac_cv_fc_dummy_main+:} false; then :
+if test "${ac_cv_fc_dummy_main+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
   ac_fc_dm_save_LIBS=$LIBS
@@ -4225,7 +4132,11 @@
 ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
  # First, try linking without a dummy main:
- cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+ cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 
 #ifdef FC_DUMMY_MAIN
@@ -4244,17 +4155,46 @@
   return 0;
 }
 _ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext && {
+	 test "$cross_compiling" = yes ||
+	 $as_test_x conftest$ac_exeext
+       }; then
   ac_cv_fortran_dummy_main=none
 else
-  ac_cv_fortran_dummy_main=unknown
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_cv_fortran_dummy_main=unknown
 fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
 
+rm -rf conftest.dSYM
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+
  if test $ac_cv_fortran_dummy_main = unknown; then
    for ac_func in MAIN__ MAIN_ __main MAIN _MAIN __MAIN main_ main__ _main; do
-     cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+     cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 #define $ac_fortran_dm_var $ac_func
 #ifdef FC_DUMMY_MAIN
@@ -4273,11 +4213,38 @@
   return 0;
 }
 _ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext && {
+	 test "$cross_compiling" = yes ||
+	 $as_test_x conftest$ac_exeext
+       }; then
   ac_cv_fortran_dummy_main=$ac_func; break
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+
 fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
+
+rm -rf conftest.dSYM
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
    done
  fi
  ac_ext=${ac_fc_srcext-f}
@@ -4289,10 +4256,10 @@
  LIBS=$ac_fc_dm_save_LIBS
 
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_fc_dummy_main" >&5
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_fc_dummy_main" >&5
 $as_echo "$ac_cv_fc_dummy_main" >&6; }
 FC_DUMMY_MAIN=$ac_cv_fc_dummy_main
-if test "$FC_DUMMY_MAIN" != unknown; then :
+if test "$FC_DUMMY_MAIN" != unknown; then
   if test $FC_DUMMY_MAIN != none; then
 
 cat >>confdefs.h <<_ACEOF
@@ -4301,17 +4268,23 @@
 
   if test "x$ac_cv_fc_dummy_main" = "x$ac_cv_f77_dummy_main"; then
 
-$as_echo "#define FC_DUMMY_MAIN_EQ_F77 1" >>confdefs.h
+cat >>confdefs.h <<\_ACEOF
+#define FC_DUMMY_MAIN_EQ_F77 1
+_ACEOF
 
   fi
 fi
 else
-  { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+  { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "linking to Fortran libraries from C fails
-See \`config.log' for more details" "$LINENO" 5; }
+{ { $as_echo "$as_me:$LINENO: error: linking to Fortran libraries from C fails
+See \`config.log' for more details." >&5
+$as_echo "$as_me: error: linking to Fortran libraries from C fails
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }; }
 fi
 
+
 ac_ext=c
 ac_cpp='$CPP $CPPFLAGS'
 ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
@@ -4322,12 +4295,12 @@
 ac_compile='$FC -c $FCFLAGS $ac_fcflags_srcext conftest.$ac_ext >&5'
 ac_link='$FC -o conftest$ac_exeext $FCFLAGS $LDFLAGS $ac_fcflags_srcext conftest.$ac_ext $LIBS >&5'
 ac_compiler_gnu=$ac_cv_fc_compiler_gnu
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for Fortran name-mangling scheme" >&5
+{ $as_echo "$as_me:$LINENO: checking for Fortran name-mangling scheme" >&5
 $as_echo_n "checking for Fortran name-mangling scheme... " >&6; }
-if ${ac_cv_fc_mangling+:} false; then :
+if test "${ac_cv_fc_mangling+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
-  cat > conftest.$ac_ext <<_ACEOF
+  cat >conftest.$ac_ext <<_ACEOF
       subroutine foobar()
       return
       end
@@ -4335,7 +4308,24 @@
       return
       end
 _ACEOF
-if ac_fn_fc_try_compile "$LINENO"; then :
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_fc_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
   mv conftest.$ac_objext cfortran_test.$ac_objext
 
   ac_save_LIBS=$LIBS
@@ -4350,7 +4340,11 @@
   for ac_foobar in foobar FOOBAR; do
     for ac_underscore in "" "_"; do
       ac_func="$ac_foobar$ac_underscore"
-      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+      cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 
 /* Override any GCC internal prototype to avoid an error.
@@ -4376,11 +4370,38 @@
   return 0;
 }
 _ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext && {
+	 test "$cross_compiling" = yes ||
+	 $as_test_x conftest$ac_exeext
+       }; then
   ac_success=yes; break 2
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+
 fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
+
+rm -rf conftest.dSYM
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
     done
   done
   ac_ext=${ac_fc_srcext-f}
@@ -4408,7 +4429,11 @@
      ac_success_extra=no
      for ac_extra in "" "_"; do
 	ac_func="$ac_foo_bar$ac_underscore$ac_extra"
-	cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+	cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 
 /* Override any GCC internal prototype to avoid an error.
@@ -4434,11 +4459,38 @@
   return 0;
 }
 _ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext && {
+	 test "$cross_compiling" = yes ||
+	 $as_test_x conftest$ac_exeext
+       }; then
   ac_success_extra=yes; break
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+
 fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
+
+rm -rf conftest.dSYM
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
      done
      ac_ext=${ac_fc_srcext-f}
 ac_compile='$FC -c $FCFLAGS $ac_fcflags_srcext conftest.$ac_ext >&5'
@@ -4447,16 +4499,16 @@
 
      if test "$ac_success_extra" = "yes"; then
 	ac_cv_fc_mangling="$ac_case case"
-	if test -z "$ac_underscore"; then
-	   ac_cv_fc_mangling="$ac_cv_fc_mangling, no underscore"
+        if test -z "$ac_underscore"; then
+           ac_cv_fc_mangling="$ac_cv_fc_mangling, no underscore"
 	else
-	   ac_cv_fc_mangling="$ac_cv_fc_mangling, underscore"
-	fi
-	if test -z "$ac_extra"; then
-	   ac_cv_fc_mangling="$ac_cv_fc_mangling, no extra underscore"
+           ac_cv_fc_mangling="$ac_cv_fc_mangling, underscore"
+        fi
+        if test -z "$ac_extra"; then
+           ac_cv_fc_mangling="$ac_cv_fc_mangling, no extra underscore"
 	else
-	   ac_cv_fc_mangling="$ac_cv_fc_mangling, extra underscore"
-	fi
+           ac_cv_fc_mangling="$ac_cv_fc_mangling, extra underscore"
+        fi
       else
 	ac_cv_fc_mangling="unknown"
       fi
@@ -4468,15 +4520,22 @@
   rm -rf conftest*
   rm -f cfortran_test*
 else
-  { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	{ { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "cannot compile a simple Fortran program
-See \`config.log' for more details" "$LINENO" 5; }
+{ { $as_echo "$as_me:$LINENO: error: cannot compile a simple Fortran program
+See \`config.log' for more details." >&5
+$as_echo "$as_me: error: cannot compile a simple Fortran program
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }; }
 fi
+
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_fc_mangling" >&5
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_fc_mangling" >&5
 $as_echo "$ac_cv_fc_mangling" >&6; }
 
 ac_ext=c
@@ -4489,51 +4548,85 @@
 ac_compile='$FC -c $FCFLAGS $ac_fcflags_srcext conftest.$ac_ext >&5'
 ac_link='$FC -o conftest$ac_exeext $FCFLAGS $LDFLAGS $ac_fcflags_srcext conftest.$ac_ext $LIBS >&5'
 ac_compiler_gnu=$ac_cv_fc_compiler_gnu
+
+
 case $ac_cv_fc_mangling in
   "lower case, no underscore, no extra underscore")
-	  $as_echo "#define FC_FUNC(name,NAME) name" >>confdefs.h
+          cat >>confdefs.h <<\_ACEOF
+#define FC_FUNC(name,NAME) name
+_ACEOF
 
-	  $as_echo "#define FC_FUNC_(name,NAME) name" >>confdefs.h
+          cat >>confdefs.h <<\_ACEOF
+#define FC_FUNC_(name,NAME) name
+_ACEOF
  ;;
   "lower case, no underscore, extra underscore")
-	  $as_echo "#define FC_FUNC(name,NAME) name" >>confdefs.h
+          cat >>confdefs.h <<\_ACEOF
+#define FC_FUNC(name,NAME) name
+_ACEOF
 
-	  $as_echo "#define FC_FUNC_(name,NAME) name ## _" >>confdefs.h
+          cat >>confdefs.h <<\_ACEOF
+#define FC_FUNC_(name,NAME) name ## _
+_ACEOF
  ;;
   "lower case, underscore, no extra underscore")
-	  $as_echo "#define FC_FUNC(name,NAME) name ## _" >>confdefs.h
+          cat >>confdefs.h <<\_ACEOF
+#define FC_FUNC(name,NAME) name ## _
+_ACEOF
 
-	  $as_echo "#define FC_FUNC_(name,NAME) name ## _" >>confdefs.h
+          cat >>confdefs.h <<\_ACEOF
+#define FC_FUNC_(name,NAME) name ## _
+_ACEOF
  ;;
   "lower case, underscore, extra underscore")
-	  $as_echo "#define FC_FUNC(name,NAME) name ## _" >>confdefs.h
+          cat >>confdefs.h <<\_ACEOF
+#define FC_FUNC(name,NAME) name ## _
+_ACEOF
 
-	  $as_echo "#define FC_FUNC_(name,NAME) name ## __" >>confdefs.h
+          cat >>confdefs.h <<\_ACEOF
+#define FC_FUNC_(name,NAME) name ## __
+_ACEOF
  ;;
   "upper case, no underscore, no extra underscore")
-	  $as_echo "#define FC_FUNC(name,NAME) NAME" >>confdefs.h
+          cat >>confdefs.h <<\_ACEOF
+#define FC_FUNC(name,NAME) NAME
+_ACEOF
 
-	  $as_echo "#define FC_FUNC_(name,NAME) NAME" >>confdefs.h
+          cat >>confdefs.h <<\_ACEOF
+#define FC_FUNC_(name,NAME) NAME
+_ACEOF
  ;;
   "upper case, no underscore, extra underscore")
-	  $as_echo "#define FC_FUNC(name,NAME) NAME" >>confdefs.h
+          cat >>confdefs.h <<\_ACEOF
+#define FC_FUNC(name,NAME) NAME
+_ACEOF
 
-	  $as_echo "#define FC_FUNC_(name,NAME) NAME ## _" >>confdefs.h
+          cat >>confdefs.h <<\_ACEOF
+#define FC_FUNC_(name,NAME) NAME ## _
+_ACEOF
  ;;
   "upper case, underscore, no extra underscore")
-	  $as_echo "#define FC_FUNC(name,NAME) NAME ## _" >>confdefs.h
+          cat >>confdefs.h <<\_ACEOF
+#define FC_FUNC(name,NAME) NAME ## _
+_ACEOF
 
-	  $as_echo "#define FC_FUNC_(name,NAME) NAME ## _" >>confdefs.h
+          cat >>confdefs.h <<\_ACEOF
+#define FC_FUNC_(name,NAME) NAME ## _
+_ACEOF
  ;;
   "upper case, underscore, extra underscore")
-	  $as_echo "#define FC_FUNC(name,NAME) NAME ## _" >>confdefs.h
+          cat >>confdefs.h <<\_ACEOF
+#define FC_FUNC(name,NAME) NAME ## _
+_ACEOF
 
-	  $as_echo "#define FC_FUNC_(name,NAME) NAME ## __" >>confdefs.h
+          cat >>confdefs.h <<\_ACEOF
+#define FC_FUNC_(name,NAME) NAME ## __
+_ACEOF
  ;;
   *)
-	  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unknown Fortran name-mangling scheme" >&5
+          { $as_echo "$as_me:$LINENO: WARNING: unknown Fortran name-mangling scheme" >&5
 $as_echo "$as_me: WARNING: unknown Fortran name-mangling scheme" >&2;}
-	  ;;
+          ;;
 esac
 
 ac_ext=c
@@ -4551,39 +4644,60 @@
 ac_compile='$FC -c $FCFLAGS $ac_fcflags_srcext conftest.$ac_ext >&5'
 ac_link='$FC -o conftest$ac_exeext $FCFLAGS $LDFLAGS $ac_fcflags_srcext conftest.$ac_ext $LIBS >&5'
 ac_compiler_gnu=$ac_cv_fc_compiler_gnu
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for Fortran flag to compile .f90 files" >&5
+{ $as_echo "$as_me:$LINENO: checking for Fortran flag to compile .f90 files" >&5
 $as_echo_n "checking for Fortran flag to compile .f90 files... " >&6; }
-if ${ac_cv_fc_srcext_f90+:} false; then :
+if test "${ac_cv_fc_srcext_f90+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
   ac_ext=f90
 ac_fcflags_srcext_save=$ac_fcflags_srcext
 ac_fcflags_srcext=
 ac_cv_fc_srcext_f90=unknown
-case $ac_ext in #(
-  [fF]77) ac_try=f77;; #(
-  *) ac_try=f95;;
-esac
-for ac_flag in none -qsuffix=f=f90 -Tf "-x $ac_try"; do
+for ac_flag in none -qsuffix=f=f90 -Tf; do
   test "x$ac_flag" != xnone && ac_fcflags_srcext="$ac_flag"
-  cat > conftest.$ac_ext <<_ACEOF
+  cat >conftest.$ac_ext <<_ACEOF
       program main
 
       end
 _ACEOF
-if ac_fn_fc_try_compile "$LINENO"; then :
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_fc_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
   ac_cv_fc_srcext_f90=$ac_flag; break
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+
 fi
+
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 done
 rm -f conftest.$ac_objext conftest.f90
 ac_fcflags_srcext=$ac_fcflags_srcext_save
 
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_fc_srcext_f90" >&5
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_fc_srcext_f90" >&5
 $as_echo "$ac_cv_fc_srcext_f90" >&6; }
 if test "x$ac_cv_fc_srcext_f90" = xunknown; then
-  as_fn_error $? "Fortran could not compile .f90 files" "$LINENO" 5
+  { { $as_echo "$as_me:$LINENO: error: Fortran could not compile .f90 files" >&5
+$as_echo "$as_me: error: Fortran could not compile .f90 files" >&2;}
+   { (exit 1); exit 1; }; }
 else
   ac_fc_srcext=f90
   if test "x$ac_cv_fc_srcext_f90" = xnone; then
@@ -4605,38 +4719,63 @@
 ac_compile='$FC -c $FCFLAGS $ac_fcflags_srcext conftest.$ac_ext >&5'
 ac_link='$FC -o conftest$ac_exeext $FCFLAGS $LDFLAGS $ac_fcflags_srcext conftest.$ac_ext $LIBS >&5'
 ac_compiler_gnu=$ac_cv_fc_compiler_gnu
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for Fortran flag needed to accept free-form source" >&5
-$as_echo_n "checking for Fortran flag needed to accept free-form source... " >&6; }
-if ${ac_cv_fc_freeform+:} false; then :
+{ $as_echo "$as_me:$LINENO: checking for Fortran flag needed to allow free-form source" >&5
+$as_echo_n "checking for Fortran flag needed to allow free-form source... " >&6; }
+if test "${ac_cv_fc_freeform+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
   ac_cv_fc_freeform=unknown
 ac_fc_freeform_FCFLAGS_save=$FCFLAGS
 for ac_flag in none -ffree-form -FR -free -qfree -Mfree -Mfreeform \
-	       -freeform "-f free" -8 +source=free -nfix --nfix -Free
+               -freeform "-f free"
 do
   test "x$ac_flag" != xnone && FCFLAGS="$ac_fc_freeform_FCFLAGS_save $ac_flag"
-  cat > conftest.$ac_ext <<_ACEOF
+  cat >conftest.$ac_ext <<_ACEOF
 
   program freeform
        ! FIXME: how to best confuse non-freeform compilers?
        print *, 'Hello ', &
-          'world.'
+           'world.'
        end
 _ACEOF
-if ac_fn_fc_try_compile "$LINENO"; then :
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_fc_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
   ac_cv_fc_freeform=$ac_flag; break
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+
 fi
+
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 done
 rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
 FCFLAGS=$ac_fc_freeform_FCFLAGS_save
 
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_fc_freeform" >&5
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_fc_freeform" >&5
 $as_echo "$ac_cv_fc_freeform" >&6; }
 if test "x$ac_cv_fc_freeform" = xunknown; then
-  as_fn_error 77 "Fortran does not accept free-form source" "$LINENO" 5
+  { { $as_echo "$as_me:$LINENO: error: Fortran does not accept free-form source" >&5
+$as_echo "$as_me: error: Fortran does not accept free-form source" >&2;}
+   { (exit 77); exit 77; }; }
 else
   if test "x$ac_cv_fc_freeform" != xnone; then
     FCFLAGS="$FCFLAGS $ac_cv_fc_freeform"
@@ -4657,9 +4796,9 @@
 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 "$as_me:$LINENO: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_prog_CC+:} false; then :
+if test "${ac_cv_prog_CC+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
   if test -n "$CC"; then
@@ -4670,24 +4809,24 @@
 do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$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
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
 done
-  done
+done
 IFS=$as_save_IFS
 
 fi
 fi
 CC=$ac_cv_prog_CC
 if test -n "$CC"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+  { $as_echo "$as_me:$LINENO: result: $CC" >&5
 $as_echo "$CC" >&6; }
 else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+  { $as_echo "$as_me:$LINENO: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
@@ -4697,9 +4836,9 @@
   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 "$as_me:$LINENO: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_prog_ac_ct_CC+:} false; then :
+if test "${ac_cv_prog_ac_ct_CC+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
   if test -n "$ac_ct_CC"; then
@@ -4710,24 +4849,24 @@
 do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$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
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
 done
-  done
+done
 IFS=$as_save_IFS
 
 fi
 fi
 ac_ct_CC=$ac_cv_prog_ac_ct_CC
 if test -n "$ac_ct_CC"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
+  { $as_echo "$as_me:$LINENO: result: $ac_ct_CC" >&5
 $as_echo "$ac_ct_CC" >&6; }
 else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+  { $as_echo "$as_me:$LINENO: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
@@ -4736,7 +4875,7 @@
   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:$LINENO: WARNING: using cross tools not prefixed with host triplet" >&5
 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
 ac_tool_warned=yes ;;
 esac
@@ -4750,9 +4889,9 @@
           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 "$as_me:$LINENO: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_prog_CC+:} false; then :
+if test "${ac_cv_prog_CC+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
   if test -n "$CC"; then
@@ -4763,24 +4902,24 @@
 do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$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
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
 done
-  done
+done
 IFS=$as_save_IFS
 
 fi
 fi
 CC=$ac_cv_prog_CC
 if test -n "$CC"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+  { $as_echo "$as_me:$LINENO: result: $CC" >&5
 $as_echo "$CC" >&6; }
 else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+  { $as_echo "$as_me:$LINENO: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
@@ -4790,9 +4929,9 @@
 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 "$as_me:$LINENO: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_prog_CC+:} false; then :
+if test "${ac_cv_prog_CC+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
   if test -n "$CC"; then
@@ -4804,18 +4943,18 @@
 do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$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
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
 done
-  done
+done
 IFS=$as_save_IFS
 
 if test $ac_prog_rejected = yes; then
@@ -4834,10 +4973,10 @@
 fi
 CC=$ac_cv_prog_CC
 if test -n "$CC"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+  { $as_echo "$as_me:$LINENO: result: $CC" >&5
 $as_echo "$CC" >&6; }
 else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+  { $as_echo "$as_me:$LINENO: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
@@ -4849,9 +4988,9 @@
   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 "$as_me:$LINENO: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_prog_CC+:} false; then :
+if test "${ac_cv_prog_CC+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
   if test -n "$CC"; then
@@ -4862,24 +5001,24 @@
 do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$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
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
 done
-  done
+done
 IFS=$as_save_IFS
 
 fi
 fi
 CC=$ac_cv_prog_CC
 if test -n "$CC"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
+  { $as_echo "$as_me:$LINENO: result: $CC" >&5
 $as_echo "$CC" >&6; }
 else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+  { $as_echo "$as_me:$LINENO: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
@@ -4893,9 +5032,9 @@
 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 "$as_me:$LINENO: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_prog_ac_ct_CC+:} false; then :
+if test "${ac_cv_prog_ac_ct_CC+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
   if test -n "$ac_ct_CC"; then
@@ -4906,24 +5045,24 @@
 do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$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
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
 done
-  done
+done
 IFS=$as_save_IFS
 
 fi
 fi
 ac_ct_CC=$ac_cv_prog_ac_ct_CC
 if test -n "$ac_ct_CC"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
+  { $as_echo "$as_me:$LINENO: result: $ac_ct_CC" >&5
 $as_echo "$ac_ct_CC" >&6; }
 else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+  { $as_echo "$as_me:$LINENO: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
@@ -4936,7 +5075,7 @@
   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:$LINENO: WARNING: using cross tools not prefixed with host triplet" >&5
 $as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
 ac_tool_warned=yes ;;
 esac
@@ -4947,42 +5086,62 @@
 fi
 
 
-test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+test -z "$CC" && { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "no acceptable C compiler found in \$PATH
-See \`config.log' for more details" "$LINENO" 5; }
+{ { $as_echo "$as_me:$LINENO: error: no acceptable C compiler found in \$PATH
+See \`config.log' for more details." >&5
+$as_echo "$as_me: error: no acceptable C compiler found in \$PATH
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }; }
 
 # Provide some information about the compiler.
-$as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5
+$as_echo "$as_me:$LINENO: checking for C compiler version" >&5
 set X $ac_compile
 ac_compiler=$2
-for ac_option in --version -v -V -qversion; do
-  { { ac_try="$ac_compiler $ac_option >&5"
+{ (ac_try="$ac_compiler --version >&5"
 case "(($ac_try" in
   *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
   *) ac_try_echo=$ac_try;;
 esac
-eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
-$as_echo "$ac_try_echo"; } >&5
-  (eval "$ac_compiler $ac_option >&5") 2>conftest.err
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compiler --version >&5") 2>&5
   ac_status=$?
-  if test -s conftest.err; then
-    sed '10a\
-... rest of stderr output deleted ...
-         10q' conftest.err >conftest.er1
-    cat conftest.er1 >&5
-  fi
-  rm -f conftest.er1 conftest.err
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; }
-done
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }
+{ (ac_try="$ac_compiler -v >&5"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compiler -v >&5") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }
+{ (ac_try="$ac_compiler -V >&5"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compiler -V >&5") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5
+{ $as_echo "$as_me:$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 :
+if test "${ac_cv_c_compiler_gnu+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
-  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 
 #ifdef FC_DUMMY_MAIN
@@ -5004,16 +5163,37 @@
   return 0;
 }
 _ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
   ac_compiler_gnu=yes
 else
-  ac_compiler_gnu=no
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_compiler_gnu=no
 fi
+
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 ac_cv_c_compiler_gnu=$ac_compiler_gnu
 
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_c_compiler_gnu" >&5
 $as_echo "$ac_cv_c_compiler_gnu" >&6; }
 if test $ac_compiler_gnu = yes; then
   GCC=yes
@@ -5022,16 +5202,20 @@
 fi
 ac_test_CFLAGS=${CFLAGS+set}
 ac_save_CFLAGS=$CFLAGS
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5
+{ $as_echo "$as_me:$LINENO: checking whether $CC accepts -g" >&5
 $as_echo_n "checking whether $CC accepts -g... " >&6; }
-if ${ac_cv_prog_cc_g+:} false; then :
+if test "${ac_cv_prog_cc_g+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
   ac_save_c_werror_flag=$ac_c_werror_flag
    ac_c_werror_flag=yes
    ac_cv_prog_cc_g=no
    CFLAGS="-g"
-   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+   cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 
 #ifdef FC_DUMMY_MAIN
@@ -5050,11 +5234,35 @@
   return 0;
 }
 _ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
   ac_cv_prog_cc_g=yes
 else
-  CFLAGS=""
-      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	CFLAGS=""
+      cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 
 #ifdef FC_DUMMY_MAIN
@@ -5073,12 +5281,36 @@
   return 0;
 }
 _ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  :
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
 
-else
-  ac_c_werror_flag=$ac_save_c_werror_flag
+	ac_c_werror_flag=$ac_save_c_werror_flag
 	 CFLAGS="-g"
-	 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+	 cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 
 #ifdef FC_DUMMY_MAIN
@@ -5097,17 +5329,42 @@
   return 0;
 }
 _ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
   ac_cv_prog_cc_g=yes
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+
 fi
+
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
+
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
+
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
    ac_c_werror_flag=$ac_save_c_werror_flag
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_prog_cc_g" >&5
 $as_echo "$ac_cv_prog_cc_g" >&6; }
 if test "$ac_test_CFLAGS" = set; then
   CFLAGS=$ac_save_CFLAGS
@@ -5124,18 +5381,23 @@
     CFLAGS=
   fi
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5
+{ $as_echo "$as_me:$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 :
+if test "${ac_cv_prog_cc_c89+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
   ac_cv_prog_cc_c89=no
 ac_save_CC=$CC
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 #include <stdarg.h>
 #include <stdio.h>
-struct stat;
+#include <sys/types.h>
+#include <sys/stat.h>
 /* 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);
@@ -5195,9 +5457,32 @@
 	-Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"
 do
   CC="$ac_save_CC $ac_arg"
-  if ac_fn_c_try_compile "$LINENO"; then :
+  rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
   ac_cv_prog_cc_c89=$ac_arg
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+
 fi
+
 rm -f core conftest.err conftest.$ac_objext
   test "x$ac_cv_prog_cc_c89" != "xno" && break
 done
@@ -5208,19 +5493,17 @@
 # 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 "$as_me:$LINENO: result: none needed" >&5
 $as_echo "none needed" >&6; } ;;
   xno)
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5
+    { $as_echo "$as_me:$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 "$as_me:$LINENO: result: $ac_cv_prog_cc_c89" >&5
 $as_echo "$ac_cv_prog_cc_c89" >&6; } ;;
 esac
-if test "x$ac_cv_prog_cc_c89" != xno; then :
 
-fi
 
 ac_ext=${ac_fc_srcext-f}
 ac_compile='$FC -c $FCFLAGS $ac_fcflags_srcext conftest.$ac_ext >&5'
@@ -5239,14 +5522,14 @@
 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 "$as_me:$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 :
+  if test "${ac_cv_prog_CPP+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
       # Double quotes because CPP needs to be expanded
@@ -5261,7 +5544,11 @@
   # <limits.h> 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
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 #ifdef __STDC__
 # include <limits.h>
@@ -5270,34 +5557,78 @@
 #endif
 		     Syntax error
 _ACEOF
-if ac_fn_c_try_cpp "$LINENO"; then :
+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:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null && {
+	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       }; then
+  :
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
 
-else
   # Broken: fails on valid input.
 continue
 fi
-rm -f conftest.err conftest.i conftest.$ac_ext
 
+rm -f conftest.err 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
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 #include <ac_nonexistent.h>
 _ACEOF
-if ac_fn_c_try_cpp "$LINENO"; then :
+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:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null && {
+	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       }; then
   # Broken: success on invalid input.
 continue
 else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
   # Passes both tests.
 ac_preproc_ok=:
 break
 fi
-rm -f conftest.err conftest.i conftest.$ac_ext
 
+rm -f conftest.err 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 :
+rm -f conftest.err conftest.$ac_ext
+if $ac_preproc_ok; then
   break
 fi
 
@@ -5309,7 +5640,7 @@
 else
   ac_cv_prog_CPP=$CPP
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5
+{ $as_echo "$as_me:$LINENO: result: $CPP" >&5
 $as_echo "$CPP" >&6; }
 ac_preproc_ok=false
 for ac_c_preproc_warn_flag in '' yes
@@ -5320,7 +5651,11 @@
   # <limits.h> 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
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 #ifdef __STDC__
 # include <limits.h>
@@ -5329,40 +5664,87 @@
 #endif
 		     Syntax error
 _ACEOF
-if ac_fn_c_try_cpp "$LINENO"; then :
+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:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null && {
+	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       }; then
+  :
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
 
-else
   # Broken: fails on valid input.
 continue
 fi
-rm -f conftest.err conftest.i conftest.$ac_ext
 
+rm -f conftest.err 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
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 #include <ac_nonexistent.h>
 _ACEOF
-if ac_fn_c_try_cpp "$LINENO"; then :
+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:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null && {
+	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       }; then
   # Broken: success on invalid input.
 continue
 else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
   # Passes both tests.
 ac_preproc_ok=:
 break
 fi
-rm -f conftest.err conftest.i conftest.$ac_ext
 
+rm -f conftest.err 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 :
-
+rm -f 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:$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; }
+{ { $as_echo "$as_me:$LINENO: error: C preprocessor \"$CPP\" fails sanity check
+See \`config.log' for more details." >&5
+$as_echo "$as_me: error: C preprocessor \"$CPP\" fails sanity check
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }; }
 fi
 
 ac_ext=c
@@ -5372,9 +5754,9 @@
 ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5
+{ $as_echo "$as_me:$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 :
+if test "${ac_cv_path_GREP+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
   if test -z "$GREP"; then
@@ -5385,10 +5767,10 @@
 do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
-    for ac_prog in grep ggrep; do
+  for ac_prog in grep ggrep; do
     for ac_exec_ext in '' $ac_executable_extensions; do
       ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext"
-      as_fn_executable_p "$ac_path_GREP" || continue
+      { test -f "$ac_path_GREP" && $as_test_x "$ac_path_GREP"; } || continue
 # Check for GNU ac_path_GREP and select it if it is found.
   # Check for GNU $ac_path_GREP
 case `"$ac_path_GREP" --version 2>&1` in
@@ -5405,7 +5787,7 @@
     $as_echo 'GREP' >> "conftest.nl"
     "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break
     diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
-    as_fn_arith $ac_count + 1 && ac_count=$as_val
+    ac_count=`expr $ac_count + 1`
     if test $ac_count -gt ${ac_path_GREP_max-0}; then
       # Best one so far, save it but keep looking for a better one
       ac_cv_path_GREP="$ac_path_GREP"
@@ -5420,24 +5802,26 @@
       $ac_path_GREP_found && break 3
     done
   done
-  done
+done
 IFS=$as_save_IFS
   if test -z "$ac_cv_path_GREP"; then
-    as_fn_error $? "no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5
+    { { $as_echo "$as_me:$LINENO: error: no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" >&5
+$as_echo "$as_me: error: no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" >&2;}
+   { (exit 1); exit 1; }; }
   fi
 else
   ac_cv_path_GREP=$GREP
 fi
 
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_path_GREP" >&5
 $as_echo "$ac_cv_path_GREP" >&6; }
  GREP="$ac_cv_path_GREP"
 
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5
+{ $as_echo "$as_me:$LINENO: checking for egrep" >&5
 $as_echo_n "checking for egrep... " >&6; }
-if ${ac_cv_path_EGREP+:} false; then :
+if test "${ac_cv_path_EGREP+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
   if echo a | $GREP -E '(a|b)' >/dev/null 2>&1
@@ -5451,10 +5835,10 @@
 do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
-    for ac_prog in egrep; do
+  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
+      { test -f "$ac_path_EGREP" && $as_test_x "$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
@@ -5471,7 +5855,7 @@
     $as_echo 'EGREP' >> "conftest.nl"
     "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break
     diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
-    as_fn_arith $ac_count + 1 && ac_count=$as_val
+    ac_count=`expr $ac_count + 1`
     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"
@@ -5486,10 +5870,12 @@
       $ac_path_EGREP_found && break 3
     done
   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
+    { { $as_echo "$as_me:$LINENO: error: no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" >&5
+$as_echo "$as_me: error: no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" >&2;}
+   { (exit 1); exit 1; }; }
   fi
 else
   ac_cv_path_EGREP=$EGREP
@@ -5497,17 +5883,21 @@
 
    fi
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_path_EGREP" >&5
 $as_echo "$ac_cv_path_EGREP" >&6; }
  EGREP="$ac_cv_path_EGREP"
 
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5
+{ $as_echo "$as_me:$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 :
+if test "${ac_cv_header_stdc+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
-  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 #include <stdlib.h>
 #include <stdarg.h>
@@ -5530,23 +5920,48 @@
   return 0;
 }
 _ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
   ac_cv_header_stdc=yes
 else
-  ac_cv_header_stdc=no
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	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
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 #include <string.h>
 
 _ACEOF
 if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
-  $EGREP "memchr" >/dev/null 2>&1; then :
-
+  $EGREP "memchr" >/dev/null 2>&1; then
+  :
 else
   ac_cv_header_stdc=no
 fi
@@ -5556,14 +5971,18 @@
 
 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
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 #include <stdlib.h>
 
 _ACEOF
 if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
-  $EGREP "free" >/dev/null 2>&1; then :
-
+  $EGREP "free" >/dev/null 2>&1; then
+  :
 else
   ac_cv_header_stdc=no
 fi
@@ -5573,10 +5992,14 @@
 
 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 :
+  if test "$cross_compiling" = yes; then
   :
 else
-  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 #include <ctype.h>
 #include <stdlib.h>
@@ -5603,33 +6026,118 @@
   return 0;
 }
 _ACEOF
-if ac_fn_c_try_run "$LINENO"; then :
+rm -f 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:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_link") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && { 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:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_try") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  :
+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
 
-else
-  ac_cv_header_stdc=no
+( exit $ac_status )
+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
+rm -rf conftest.dSYM
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
 fi
 
+
 fi
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5
+{ $as_echo "$as_me:$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
+cat >>confdefs.h <<\_ACEOF
+#define STDC_HEADERS 1
+_ACEOF
 
 fi
 
 # On IRIX 5.3, sys/types and inttypes.h are conflicting.
+
+
+
+
+
+
+
+
+
 for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \
 		  inttypes.h stdint.h unistd.h
-do :
-  as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
-ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default
-"
-if eval test \"x\$"$as_ac_Header"\" = x"yes"; then :
+do
+as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
+{ $as_echo "$as_me:$LINENO: checking for $ac_header" >&5
+$as_echo_n "checking for $ac_header... " >&6; }
+if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
+  $as_echo_n "(cached) " >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+
+#include <$ac_header>
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  eval "$as_ac_Header=yes"
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	eval "$as_ac_Header=no"
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+ac_res=`eval 'as_val=${'$as_ac_Header'}
+		 $as_echo "$as_val"'`
+	       { $as_echo "$as_me:$LINENO: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+as_val=`eval 'as_val=${'$as_ac_Header'}
+		 $as_echo "$as_val"'`
+   if test "x$as_val" = x""yes; then
   cat >>confdefs.h <<_ACEOF
 #define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
 _ACEOF
@@ -5639,22 +6147,288 @@
 done
 
 
-ac_fn_c_check_header_mongrel "$LINENO" "emmintrin.h" "ac_cv_header_emmintrin_h" "$ac_includes_default"
-if test "x$ac_cv_header_emmintrin_h" = xyes; then :
+if test "${ac_cv_header_emmintrin_h+set}" = set; then
+  { $as_echo "$as_me:$LINENO: checking for emmintrin.h" >&5
+$as_echo_n "checking for emmintrin.h... " >&6; }
+if test "${ac_cv_header_emmintrin_h+set}" = set; then
+  $as_echo_n "(cached) " >&6
+fi
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_header_emmintrin_h" >&5
+$as_echo "$ac_cv_header_emmintrin_h" >&6; }
+else
+  # Is the header compilable?
+{ $as_echo "$as_me:$LINENO: checking emmintrin.h usability" >&5
+$as_echo_n "checking emmintrin.h usability... " >&6; }
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+#include <emmintrin.h>
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_header_compiler=yes
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
 
-$as_echo "#define HAVE_EMMINTRIN 1" >>confdefs.h
+	ac_header_compiler=no
+fi
 
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
+$as_echo "$ac_header_compiler" >&6; }
+
+# Is the header present?
+{ $as_echo "$as_me:$LINENO: checking emmintrin.h presence" >&5
+$as_echo_n "checking emmintrin.h presence... " >&6; }
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <emmintrin.h>
+_ACEOF
+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:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null && {
+	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       }; then
+  ac_header_preproc=yes
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+  ac_header_preproc=no
 fi
 
+rm -f conftest.err conftest.$ac_ext
+{ $as_echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
+$as_echo "$ac_header_preproc" >&6; }
 
-ac_fn_c_check_header_mongrel "$LINENO" "xmmintrin.h" "ac_cv_header_xmmintrin_h" "$ac_includes_default"
-if test "x$ac_cv_header_xmmintrin_h" = xyes; then :
+# So?  What about this header?
+case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
+  yes:no: )
+    { $as_echo "$as_me:$LINENO: WARNING: emmintrin.h: accepted by the compiler, rejected by the preprocessor!" >&5
+$as_echo "$as_me: WARNING: emmintrin.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
+    { $as_echo "$as_me:$LINENO: WARNING: emmintrin.h: proceeding with the compiler's result" >&5
+$as_echo "$as_me: WARNING: emmintrin.h: proceeding with the compiler's result" >&2;}
+    ac_header_preproc=yes
+    ;;
+  no:yes:* )
+    { $as_echo "$as_me:$LINENO: WARNING: emmintrin.h: present but cannot be compiled" >&5
+$as_echo "$as_me: WARNING: emmintrin.h: present but cannot be compiled" >&2;}
+    { $as_echo "$as_me:$LINENO: WARNING: emmintrin.h:     check for missing prerequisite headers?" >&5
+$as_echo "$as_me: WARNING: emmintrin.h:     check for missing prerequisite headers?" >&2;}
+    { $as_echo "$as_me:$LINENO: WARNING: emmintrin.h: see the Autoconf documentation" >&5
+$as_echo "$as_me: WARNING: emmintrin.h: see the Autoconf documentation" >&2;}
+    { $as_echo "$as_me:$LINENO: WARNING: emmintrin.h:     section \"Present But Cannot Be Compiled\"" >&5
+$as_echo "$as_me: WARNING: emmintrin.h:     section \"Present But Cannot Be Compiled\"" >&2;}
+    { $as_echo "$as_me:$LINENO: WARNING: emmintrin.h: proceeding with the preprocessor's result" >&5
+$as_echo "$as_me: WARNING: emmintrin.h: proceeding with the preprocessor's result" >&2;}
+    { $as_echo "$as_me:$LINENO: WARNING: emmintrin.h: in the future, the compiler will take precedence" >&5
+$as_echo "$as_me: WARNING: emmintrin.h: in the future, the compiler will take precedence" >&2;}
+    ( cat <<\_ASBOX
+## -------------------------------------- ##
+## Report this to jtromp AT princeton.edu ##
+## -------------------------------------- ##
+_ASBOX
+     ) | sed "s/^/$as_me: WARNING:     /" >&2
+    ;;
+esac
+{ $as_echo "$as_me:$LINENO: checking for emmintrin.h" >&5
+$as_echo_n "checking for emmintrin.h... " >&6; }
+if test "${ac_cv_header_emmintrin_h+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  ac_cv_header_emmintrin_h=$ac_header_preproc
+fi
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_header_emmintrin_h" >&5
+$as_echo "$ac_cv_header_emmintrin_h" >&6; }
 
-$as_echo "#define HAVE_XMMINTRIN 1" >>confdefs.h
+fi
+if test "x$ac_cv_header_emmintrin_h" = x""yes; then
 
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_EMMINTRIN 1
+_ACEOF
+
 fi
 
 
+if test "${ac_cv_header_xmmintrin_h+set}" = set; then
+  { $as_echo "$as_me:$LINENO: checking for xmmintrin.h" >&5
+$as_echo_n "checking for xmmintrin.h... " >&6; }
+if test "${ac_cv_header_xmmintrin_h+set}" = set; then
+  $as_echo_n "(cached) " >&6
+fi
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_header_xmmintrin_h" >&5
+$as_echo "$ac_cv_header_xmmintrin_h" >&6; }
+else
+  # Is the header compilable?
+{ $as_echo "$as_me:$LINENO: checking xmmintrin.h usability" >&5
+$as_echo_n "checking xmmintrin.h usability... " >&6; }
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+#include <xmmintrin.h>
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_header_compiler=yes
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_header_compiler=no
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
+$as_echo "$ac_header_compiler" >&6; }
+
+# Is the header present?
+{ $as_echo "$as_me:$LINENO: checking xmmintrin.h presence" >&5
+$as_echo_n "checking xmmintrin.h presence... " >&6; }
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <xmmintrin.h>
+_ACEOF
+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:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null && {
+	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       }; then
+  ac_header_preproc=yes
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+  ac_header_preproc=no
+fi
+
+rm -f conftest.err conftest.$ac_ext
+{ $as_echo "$as_me:$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:$LINENO: WARNING: xmmintrin.h: accepted by the compiler, rejected by the preprocessor!" >&5
+$as_echo "$as_me: WARNING: xmmintrin.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
+    { $as_echo "$as_me:$LINENO: WARNING: xmmintrin.h: proceeding with the compiler's result" >&5
+$as_echo "$as_me: WARNING: xmmintrin.h: proceeding with the compiler's result" >&2;}
+    ac_header_preproc=yes
+    ;;
+  no:yes:* )
+    { $as_echo "$as_me:$LINENO: WARNING: xmmintrin.h: present but cannot be compiled" >&5
+$as_echo "$as_me: WARNING: xmmintrin.h: present but cannot be compiled" >&2;}
+    { $as_echo "$as_me:$LINENO: WARNING: xmmintrin.h:     check for missing prerequisite headers?" >&5
+$as_echo "$as_me: WARNING: xmmintrin.h:     check for missing prerequisite headers?" >&2;}
+    { $as_echo "$as_me:$LINENO: WARNING: xmmintrin.h: see the Autoconf documentation" >&5
+$as_echo "$as_me: WARNING: xmmintrin.h: see the Autoconf documentation" >&2;}
+    { $as_echo "$as_me:$LINENO: WARNING: xmmintrin.h:     section \"Present But Cannot Be Compiled\"" >&5
+$as_echo "$as_me: WARNING: xmmintrin.h:     section \"Present But Cannot Be Compiled\"" >&2;}
+    { $as_echo "$as_me:$LINENO: WARNING: xmmintrin.h: proceeding with the preprocessor's result" >&5
+$as_echo "$as_me: WARNING: xmmintrin.h: proceeding with the preprocessor's result" >&2;}
+    { $as_echo "$as_me:$LINENO: WARNING: xmmintrin.h: in the future, the compiler will take precedence" >&5
+$as_echo "$as_me: WARNING: xmmintrin.h: in the future, the compiler will take precedence" >&2;}
+    ( cat <<\_ASBOX
+## -------------------------------------- ##
+## Report this to jtromp AT princeton.edu ##
+## -------------------------------------- ##
+_ASBOX
+     ) | sed "s/^/$as_me: WARNING:     /" >&2
+    ;;
+esac
+{ $as_echo "$as_me:$LINENO: checking for xmmintrin.h" >&5
+$as_echo_n "checking for xmmintrin.h... " >&6; }
+if test "${ac_cv_header_xmmintrin_h+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  ac_cv_header_xmmintrin_h=$ac_header_preproc
+fi
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_header_xmmintrin_h" >&5
+$as_echo "$ac_cv_header_xmmintrin_h" >&6; }
+
+fi
+if test "x$ac_cv_header_xmmintrin_h" = x""yes; then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_XMMINTRIN 1
+_ACEOF
+
+fi
+
+
 ac_ext=${ac_fc_srcext-f}
 ac_compile='$FC -c $FCFLAGS $ac_fcflags_srcext conftest.$ac_ext >&5'
 ac_link='$FC -o conftest$ac_exeext $FCFLAGS $LDFLAGS $ac_fcflags_srcext conftest.$ac_ext $LIBS >&5'
@@ -5670,7 +6444,7 @@
 
 
 # Check whether --with-scotch-dir was given.
-if test "${with_scotch_dir+set}" = set; then :
+if test "${with_scotch_dir+set}" = set; then
   withval=$with_scotch_dir;
  ac_scotch_dir="$withval";
 
@@ -5679,7 +6453,7 @@
 
 
 # Check whether --with-scotch-includedir was given.
-if test "${with_scotch_includedir+set}" = set; then :
+if test "${with_scotch_includedir+set}" = set; then
   withval=$with_scotch_includedir;
  ac_scotch_include_dir="$withval";
 
@@ -5688,7 +6462,7 @@
 
 
 # Check whether --with-scotch-libdir was given.
-if test "${with_scotch_libdir+set}" = set; then :
+if test "${with_scotch_libdir+set}" = set; then
   withval=$with_scotch_libdir;
  ac_scotch_lib_dir="$withval";
 
@@ -5718,30 +6492,55 @@
   if test -n "${ac_scotch_lib_dir}"; then
     LDFLAGS="${LDFLAGS} -L${ac_scotch_lib_dir}";
   fi
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for scotchfarchinit  in -lscotch" >&5
+  { $as_echo "$as_me:$LINENO: checking for scotchfarchinit  in -lscotch" >&5
 $as_echo_n "checking for scotchfarchinit  in -lscotch... " >&6; }
-if ${ac_cv_lib_scotch_scotchfarchinit_+:} false; then :
+if test "${ac_cv_lib_scotch_scotchfarchinit_+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
   ac_check_lib_save_LIBS=$LIBS
 LIBS="-lscotch -lscotcherr $LIBS"
-cat > conftest.$ac_ext <<_ACEOF
+cat >conftest.$ac_ext <<_ACEOF
       program main
       call scotchfarchinit
       end
 _ACEOF
-if ac_fn_fc_try_link "$LINENO"; then :
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_fc_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext && {
+	 test "$cross_compiling" = yes ||
+	 $as_test_x conftest$ac_exeext
+       }; then
   ac_cv_lib_scotch_scotchfarchinit_=yes
 else
-  ac_cv_lib_scotch_scotchfarchinit_=no
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_cv_lib_scotch_scotchfarchinit_=no
 fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
+
+rm -rf conftest.dSYM
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
 LIBS=$ac_check_lib_save_LIBS
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_scotch_scotchfarchinit_" >&5
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_lib_scotch_scotchfarchinit_" >&5
 $as_echo "$ac_cv_lib_scotch_scotchfarchinit_" >&6; }
-if test "x$ac_cv_lib_scotch_scotchfarchinit_" = xyes; then :
+if test "x$ac_cv_lib_scotch_scotchfarchinit_" = x""yes; then
   scotch_lib="yes";
 else
   scotch_lib="no";LDFLAGS=${ac_save_ldflags}
@@ -5759,31 +6558,35 @@
 
 fi
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether Scotch is usable" >&5
+{ $as_echo "$as_me:$LINENO: checking whether Scotch is usable" >&5
 $as_echo_n "checking whether Scotch is usable... " >&6; }
 if test "x${scotch_usable}" = "xyes"; then
 
-$as_echo "#define HAVE_SCOTCH 1" >>confdefs.h
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_SCOTCH 1
+_ACEOF
 
  USE_BUNDLED_SCOTCH=0
  SCOTCH_DIR="${ac_scotch_dir}"
  SCOTCH_LIBDIR="${ac_scotch_lib_dir}"
  SCOTCH_INCLUDEDIR="${ac_scotch_include_dir}"
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+ { $as_echo "$as_me:$LINENO: result: yes" >&5
 $as_echo "yes" >&6; }
 else
 
-$as_echo "#define HAVE_SCOTCH 1" >>confdefs.h
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_SCOTCH 1
+_ACEOF
 
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: no, using bundled scotch instead" >&5
+ { $as_echo "$as_me:$LINENO: result: no, using bundled scotch instead" >&5
 $as_echo "no, using bundled scotch instead" >&6; }
  for ac_prog in flex lex
 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 "$as_me:$LINENO: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_prog_LEX+:} false; then :
+if test "${ac_cv_prog_LEX+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
   if test -n "$LEX"; then
@@ -5794,24 +6597,24 @@
 do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
     ac_cv_prog_LEX="$ac_prog"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
 done
-  done
+done
 IFS=$as_save_IFS
 
 fi
 fi
 LEX=$ac_cv_prog_LEX
 if test -n "$LEX"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LEX" >&5
+  { $as_echo "$as_me:$LINENO: result: $LEX" >&5
 $as_echo "$LEX" >&6; }
 else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+  { $as_echo "$as_me:$LINENO: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
@@ -5827,8 +6630,7 @@
 b { REJECT; }
 c { yymore (); }
 d { yyless (1); }
-e { /* IRIX 6.5 flex 2.5.4 underquotes its yyless argument.  */
-    yyless ((input () != 0)); }
+e { yyless (input () != 0); }
 f { unput (yytext[0]); }
 . { BEGIN INITIAL; }
 %%
@@ -5841,20 +6643,20 @@
   return ! yylex () + ! yywrap ();
 }
 _ACEOF
-{ { ac_try="$LEX conftest.l"
+{ (ac_try="$LEX conftest.l"
 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_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
   (eval "$LEX conftest.l") 2>&5
   ac_status=$?
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; }
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking lex output file root" >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }
+{ $as_echo "$as_me:$LINENO: checking lex output file root" >&5
 $as_echo_n "checking lex output file root... " >&6; }
-if ${ac_cv_prog_lex_root+:} false; then :
+if test "${ac_cv_prog_lex_root+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
 
@@ -5863,17 +6665,19 @@
 elif test -f lexyy.c; then
   ac_cv_prog_lex_root=lexyy
 else
-  as_fn_error $? "cannot find output from $LEX; giving up" "$LINENO" 5
+  { { $as_echo "$as_me:$LINENO: error: cannot find output from $LEX; giving up" >&5
+$as_echo "$as_me: error: cannot find output from $LEX; giving up" >&2;}
+   { (exit 1); exit 1; }; }
 fi
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_lex_root" >&5
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_prog_lex_root" >&5
 $as_echo "$ac_cv_prog_lex_root" >&6; }
 LEX_OUTPUT_ROOT=$ac_cv_prog_lex_root
 
 if test -z "${LEXLIB+set}"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking lex library" >&5
+  { $as_echo "$as_me:$LINENO: checking lex library" >&5
 $as_echo_n "checking lex library... " >&6; }
-if ${ac_cv_lib_lex+:} false; then :
+if test "${ac_cv_lib_lex+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
 
@@ -5881,28 +6685,55 @@
     ac_cv_lib_lex='none needed'
     for ac_lib in '' -lfl -ll; do
       LIBS="$ac_lib $ac_save_LIBS"
-      cat > conftest.$ac_ext <<_ACEOF
+      cat >conftest.$ac_ext <<_ACEOF
 `cat $LEX_OUTPUT_ROOT.c`
 _ACEOF
-if ac_fn_fc_try_link "$LINENO"; then :
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_fc_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext && {
+	 test "$cross_compiling" = yes ||
+	 $as_test_x conftest$ac_exeext
+       }; then
   ac_cv_lib_lex=$ac_lib
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+
 fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
+
+rm -rf conftest.dSYM
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
       test "$ac_cv_lib_lex" != 'none needed' && break
     done
     LIBS=$ac_save_LIBS
 
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_lex" >&5
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_lib_lex" >&5
 $as_echo "$ac_cv_lib_lex" >&6; }
   test "$ac_cv_lib_lex" != 'none needed' && LEXLIB=$ac_cv_lib_lex
 fi
 
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether yytext is a pointer" >&5
+{ $as_echo "$as_me:$LINENO: checking whether yytext is a pointer" >&5
 $as_echo_n "checking whether yytext is a pointer... " >&6; }
-if ${ac_cv_prog_lex_yytext_pointer+:} false; then :
+if test "${ac_cv_prog_lex_yytext_pointer+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
   # POSIX says lex can declare yytext either as a pointer or an array; the
@@ -5911,39 +6742,69 @@
 ac_cv_prog_lex_yytext_pointer=no
 ac_save_LIBS=$LIBS
 LIBS="$LEXLIB $ac_save_LIBS"
-cat > conftest.$ac_ext <<_ACEOF
-
-  #define YYTEXT_POINTER 1
+cat >conftest.$ac_ext <<_ACEOF
+#define YYTEXT_POINTER 1
 `cat $LEX_OUTPUT_ROOT.c`
 _ACEOF
-if ac_fn_fc_try_link "$LINENO"; then :
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_fc_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext && {
+	 test "$cross_compiling" = yes ||
+	 $as_test_x conftest$ac_exeext
+       }; then
   ac_cv_prog_lex_yytext_pointer=yes
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+
 fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
+
+rm -rf conftest.dSYM
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
 LIBS=$ac_save_LIBS
 
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_lex_yytext_pointer" >&5
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_prog_lex_yytext_pointer" >&5
 $as_echo "$ac_cv_prog_lex_yytext_pointer" >&6; }
 if test $ac_cv_prog_lex_yytext_pointer = yes; then
 
-$as_echo "#define YYTEXT_POINTER 1" >>confdefs.h
+cat >>confdefs.h <<\_ACEOF
+#define YYTEXT_POINTER 1
+_ACEOF
 
 fi
 rm -f conftest.l $LEX_OUTPUT_ROOT.c
 
 fi
  if test -z "$LEX" || test "X$LEX" = "Xno"; then
-   as_fn_error $? "No suitable lex found" "$LINENO" 5
+   { { $as_echo "$as_me:$LINENO: error: No suitable lex found" >&5
+$as_echo "$as_me: error: No suitable lex found" >&2;}
+   { (exit 1); exit 1; }; }
  fi
  for ac_prog in 'bison -y' byacc
 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 "$as_me:$LINENO: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_prog_YACC+:} false; then :
+if test "${ac_cv_prog_YACC+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
   if test -n "$YACC"; then
@@ -5954,24 +6815,24 @@
 do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
     ac_cv_prog_YACC="$ac_prog"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
 done
-  done
+done
 IFS=$as_save_IFS
 
 fi
 fi
 YACC=$ac_cv_prog_YACC
 if test -n "$YACC"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $YACC" >&5
+  { $as_echo "$as_me:$LINENO: result: $YACC" >&5
 $as_echo "$YACC" >&6; }
 else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+  { $as_echo "$as_me:$LINENO: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
@@ -5981,7 +6842,9 @@
 test -n "$YACC" || YACC="yacc"
 
  if test -z "$YACC" || test "X$YACC" = "Xno"; then
-   as_fn_error $? "No suitable yacc or bison found" "$LINENO" 5
+   { { $as_echo "$as_me:$LINENO: error: No suitable yacc or bison found" >&5
+$as_echo "$as_me: error: No suitable yacc or bison found" >&2;}
+   { (exit 1); exit 1; }; }
  fi
 
 
@@ -6006,9 +6869,13 @@
         CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
         save_LIBS="$LIBS"
         LIBS="$PTHREAD_LIBS $LIBS"
-        { $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS" >&5
+        { $as_echo "$as_me:$LINENO: checking for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS" >&5
 $as_echo_n "checking for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS... " >&6; }
-        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+        cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 
 /* Override any GCC internal prototype to avoid an error.
@@ -6034,12 +6901,39 @@
   return 0;
 }
 _ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext && {
+	 test "$cross_compiling" = yes ||
+	 $as_test_x conftest$ac_exeext
+       }; then
   acx_pthread_ok=yes
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+
 fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-        { $as_echo "$as_me:${as_lineno-$LINENO}: result: $acx_pthread_ok" >&5
+
+rm -rf conftest.dSYM
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+        { $as_echo "$as_me:$LINENO: result: $acx_pthread_ok" >&5
 $as_echo "$acx_pthread_ok" >&6; }
         if test x"$acx_pthread_ok" = xno; then
                 PTHREAD_LIBS=""
@@ -6101,12 +6995,12 @@
 
         case $flag in
                 none)
-                { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether pthreads work without any flags" >&5
+                { $as_echo "$as_me:$LINENO: checking whether pthreads work without any flags" >&5
 $as_echo_n "checking whether pthreads work without any flags... " >&6; }
                 ;;
 
                 -*)
-                { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether pthreads work with $flag" >&5
+                { $as_echo "$as_me:$LINENO: checking whether pthreads work with $flag" >&5
 $as_echo_n "checking whether pthreads work with $flag... " >&6; }
                 PTHREAD_CFLAGS="$flag"
                 ;;
@@ -6114,9 +7008,9 @@
 		pthread-config)
 		# Extract the first word of "pthread-config", so it can be a program name with args.
 set dummy pthread-config; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_prog_acx_pthread_config+:} false; then :
+if test "${ac_cv_prog_acx_pthread_config+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
   if test -n "$acx_pthread_config"; then
@@ -6127,14 +7021,14 @@
 do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
     ac_cv_prog_acx_pthread_config="yes"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
 done
-  done
+done
 IFS=$as_save_IFS
 
   test -z "$ac_cv_prog_acx_pthread_config" && ac_cv_prog_acx_pthread_config="no"
@@ -6142,10 +7036,10 @@
 fi
 acx_pthread_config=$ac_cv_prog_acx_pthread_config
 if test -n "$acx_pthread_config"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $acx_pthread_config" >&5
+  { $as_echo "$as_me:$LINENO: result: $acx_pthread_config" >&5
 $as_echo "$acx_pthread_config" >&6; }
 else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+  { $as_echo "$as_me:$LINENO: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
@@ -6156,7 +7050,7 @@
 		;;
 
                 *)
-                { $as_echo "$as_me:${as_lineno-$LINENO}: checking for the pthreads library -l$flag" >&5
+                { $as_echo "$as_me:$LINENO: checking for the pthreads library -l$flag" >&5
 $as_echo_n "checking for the pthreads library -l$flag... " >&6; }
                 PTHREAD_LIBS="-l$flag"
                 ;;
@@ -6176,7 +7070,11 @@
         # pthread_cleanup_push because it is one of the few pthread
         # functions on Solaris that doesn't have a non-functional libc stub.
         # We try pthread_create on general principles.
-        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+        cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 #include <pthread.h>
 #ifdef FC_DUMMY_MAIN
@@ -6197,16 +7095,43 @@
   return 0;
 }
 _ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext && {
+	 test "$cross_compiling" = yes ||
+	 $as_test_x conftest$ac_exeext
+       }; then
   acx_pthread_ok=yes
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+
 fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
 
+rm -rf conftest.dSYM
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+
         LIBS="$save_LIBS"
         CFLAGS="$save_CFLAGS"
 
-        { $as_echo "$as_me:${as_lineno-$LINENO}: result: $acx_pthread_ok" >&5
+        { $as_echo "$as_me:$LINENO: result: $acx_pthread_ok" >&5
 $as_echo "$acx_pthread_ok" >&6; }
         if test "x$acx_pthread_ok" = xyes; then
                 break;
@@ -6225,11 +7150,15 @@
         CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
 
         # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
-	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for joinable pthread attribute" >&5
+	{ $as_echo "$as_me:$LINENO: checking for joinable pthread attribute" >&5
 $as_echo_n "checking for joinable pthread attribute... " >&6; }
 	attr_name=unknown
 	for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
-	    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+	    cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 #include <pthread.h>
 #ifdef FC_DUMMY_MAIN
@@ -6248,13 +7177,40 @@
   return 0;
 }
 _ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext && {
+	 test "$cross_compiling" = yes ||
+	 $as_test_x conftest$ac_exeext
+       }; then
   attr_name=$attr; break
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+
 fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
+
+rm -rf conftest.dSYM
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
 	done
-        { $as_echo "$as_me:${as_lineno-$LINENO}: result: $attr_name" >&5
+        { $as_echo "$as_me:$LINENO: result: $attr_name" >&5
 $as_echo "$attr_name" >&6; }
         if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
 
@@ -6264,14 +7220,14 @@
 
         fi
 
-        { $as_echo "$as_me:${as_lineno-$LINENO}: checking if more special flags are required for pthreads" >&5
+        { $as_echo "$as_me:$LINENO: checking if more special flags are required for pthreads" >&5
 $as_echo_n "checking if more special flags are required for pthreads... " >&6; }
         flag=no
         case "${host_cpu}-${host_os}" in
             *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";;
             *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;
         esac
-        { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${flag}" >&5
+        { $as_echo "$as_me:$LINENO: result: ${flag}" >&5
 $as_echo "${flag}" >&6; }
         if test "x$flag" != xno; then
             PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
@@ -6286,9 +7242,9 @@
 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 "$as_me:$LINENO: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_prog_PTHREAD_CC+:} false; then :
+if test "${ac_cv_prog_PTHREAD_CC+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
   if test -n "$PTHREAD_CC"; then
@@ -6299,24 +7255,24 @@
 do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
     ac_cv_prog_PTHREAD_CC="$ac_prog"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
 done
-  done
+done
 IFS=$as_save_IFS
 
 fi
 fi
 PTHREAD_CC=$ac_cv_prog_PTHREAD_CC
 if test -n "$PTHREAD_CC"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PTHREAD_CC" >&5
+  { $as_echo "$as_me:$LINENO: result: $PTHREAD_CC" >&5
 $as_echo "$PTHREAD_CC" >&6; }
 else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+  { $as_echo "$as_me:$LINENO: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
@@ -6338,12 +7294,14 @@
 
 # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
 if test x"$acx_pthread_ok" = xyes; then
-        { $as_echo "$as_me:${as_lineno-$LINENO}: result: pthread found" >&5
+        { $as_echo "$as_me:$LINENO: result: pthread found" >&5
 $as_echo "pthread found" >&6; }
         :
 else
         acx_pthread_ok=no
-        as_fn_error $? "pthread not found" "$LINENO" 5
+        { { $as_echo "$as_me:$LINENO: error: pthread not found" >&5
+$as_echo "$as_me: error: pthread not found" >&2;}
+   { (exit 1); exit 1; }; }
 fi
 ac_ext=${ac_fc_srcext-f}
 ac_compile='$FC -c $FCFLAGS $ac_fcflags_srcext conftest.$ac_ext >&5'
@@ -6523,6 +7481,11 @@
 
 
 
+
+
+
+
+
 if test x"$MPIFC" = x; then
     MPIFC=mpif90
 fi
@@ -6559,60 +7522,72 @@
     pyspecfem3D="$builddir/pyspecfem3D"
     cd $srcdir
 
-    { $as_echo "$as_me:${as_lineno-$LINENO}: downloading missing Python dependencies" >&5
+    { $as_echo "$as_me:$LINENO: downloading missing Python dependencies" >&5
 $as_echo "$as_me: downloading missing Python dependencies" >&6;}
     if { ac_try='$pyspecfem3D setup.py install_deps -zmxd $builddir/deps >&5 2>&5'
-  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
   (eval $ac_try) 2>&5
   ac_status=$?
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; }; }; then :
-
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  :
 else
-  { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+  { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "cannot download missing Python dependencies
-See \`config.log' for more details" "$LINENO" 5; }
+{ { $as_echo "$as_me:$LINENO: error: cannot download missing Python dependencies
+See \`config.log' for more details." >&5
+$as_echo "$as_me: error: cannot download missing Python dependencies
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }; }
 fi
 
-    { $as_echo "$as_me:${as_lineno-$LINENO}: building Python dependencies" >&5
+
+    { $as_echo "$as_me:$LINENO: building Python dependencies" >&5
 $as_echo "$as_me: building Python dependencies" >&6;}
     if { ac_try='$pyspecfem3D setup.py develop -H None -f $builddir/deps -s $builddir -d $builddir/python >&5 2>&5'
-  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
   (eval $ac_try) 2>&5
   ac_status=$?
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; }; }; then :
-
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  :
 else
-  { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+  { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "building Python dependencies
-See \`config.log' for more details" "$LINENO" 5; }
+{ { $as_echo "$as_me:$LINENO: error: building Python dependencies
+See \`config.log' for more details." >&5
+$as_echo "$as_me: error: building Python dependencies
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }; }
 fi
 
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for egg-related flags" >&5
+
+    { $as_echo "$as_me:$LINENO: checking for egg-related flags" >&5
 $as_echo_n "checking for egg-related flags... " >&6; }
     if { ac_try='$pyspecfem3D setup.py egg_flags >&5 2>&5'
-  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
   (eval $ac_try) 2>&5
   ac_status=$?
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; }; }; then :
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: ok" >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  { $as_echo "$as_me:$LINENO: result: ok" >&5
 $as_echo "ok" >&6; }
            . egg-flags.sh
            rm -f egg-flags.sh
 
 else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: failed" >&5
+  { $as_echo "$as_me:$LINENO: result: failed" >&5
 $as_echo "failed" >&6; }
-          { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+          { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "cannot scan Python eggs for flags
-See \`config.log' for more details" "$LINENO" 5; }
+{ { $as_echo "$as_me:$LINENO: error: cannot scan Python eggs for flags
+See \`config.log' for more details." >&5
+$as_echo "$as_me: error: cannot scan Python eggs for flags
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }; }
 fi
 
+
     cd $builddir
     rm -f pyspecfem3D
     PYTHONPATH="$save_PYTHONPATH"
@@ -6632,10 +7607,8 @@
 
 if test "$want_mpi" = yes; then
 
-# Use 'mpi' module or 'mpif.h', as appropriate.  UNFINISHED.
-# The default actions are to create FILENAME that either uses the
-# appropriate module or includes the existing mpif.h.
-# This strategy doesn't play well with "implicit none": whether the
+# Use 'mpi' module or 'mpif.h', as appropriate.  UNFINISHED.  This
+# strategy doesn't play well with "implicit none": whether the
 # generated header must be included before or after "implicit none"
 # depends upon the result of the test!  It might be possible to make
 # "use mpi" always work: simply generate an 'mpi' module if the MPI
@@ -6652,15 +7625,14 @@
 trap "rm \"$cfgfile\"; exit 1" 1 2 15
 rm -f "$cfgfile"
 
-cit_fc_header=none
 cit_fc_save_fc=$FC
 cit_fc_save_fcflags=$FCFLAGS
 FC=$MPIFC
 FCFLAGS="$FCFLAGS $FLAGS_CHECK"
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether \"use mpi\" works" >&5
+{ $as_echo "$as_me:$LINENO: checking whether \"use mpi\" works" >&5
 $as_echo_n "checking whether \"use mpi\" works... " >&6; }
-cat > conftest.$ac_ext <<_ACEOF
+cat >conftest.$ac_ext <<_ACEOF
 
           program main
 
@@ -6672,27 +7644,102 @@
       end
 
 _ACEOF
-if ac_fn_fc_try_compile "$LINENO"; then :
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_fc_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
 
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+    { $as_echo "$as_me:$LINENO: result: yes" >&5
 $as_echo "yes" >&6; }
-    :
+    cit_fc_header="use mpi"
 
 else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
 
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+
+    { $as_echo "$as_me:$LINENO: result: no" >&5
 $as_echo "no" >&6; }
+    { $as_echo "$as_me:$LINENO: checking whether mpif.h works" >&5
+$as_echo_n "checking whether mpif.h works... " >&6; }
+    cat >conftest.$ac_ext <<_ACEOF
 
-        { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+              program main
+
+      include 'mpif.h'
+      integer ier
+      call MPI_INIT(ier)
+      call MPI_FINALIZE(ier)
+
+      end
+
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_fc_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+
+        { $as_echo "$as_me:$LINENO: result: yes" >&5
+$as_echo "yes" >&6; }
+        if test "$ofile" = "mpif.h"; then
+            cit_fc_header=none
+        else
+            cit_fc_header="include 'mpif.h'"
+        fi
+
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+
+        { $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+        { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "cannot compile a trivial MPI program using $MPIFC
-See \`config.log' for more details" "$LINENO" 5; }
+{ { $as_echo "$as_me:$LINENO: error: cannot compile a trivial MPI program using $MPIFC
+See \`config.log' for more details." >&5
+$as_echo "$as_me: error: cannot compile a trivial MPI program using $MPIFC
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }; }
 
 fi
+
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
 if test "$cit_fc_header" != "none"; then
-    { $as_echo "$as_me:${as_lineno-$LINENO}: creating $ofile" >&5
+    { $as_echo "$as_me:$LINENO: creating $ofile" >&5
 $as_echo "$as_me: creating $ofile" >&6;}
     cat >"$cfgfile" <<END_OF_HEADER
 ! $ofile.  Generated by configure.
@@ -6724,9 +7771,9 @@
 ac_compile='$FC -c $FCFLAGS $ac_fcflags_srcext conftest.$ac_ext >&5'
 ac_link='$FC -o conftest$ac_exeext $FCFLAGS $LDFLAGS $ac_fcflags_srcext conftest.$ac_ext $LIBS >&5'
 ac_compiler_gnu=$ac_cv_fc_compiler_gnu
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for alternate main to link with Fortran libraries" >&5
+{ $as_echo "$as_me:$LINENO: checking for alternate main to link with Fortran libraries" >&5
 $as_echo_n "checking for alternate main to link with Fortran libraries... " >&6; }
-if ${ac_cv_fc_main+:} false; then :
+if test "${ac_cv_fc_main+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
   ac_fc_m_save_LIBS=$LIBS
@@ -6740,7 +7787,11 @@
 ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
 ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
-   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+   cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 #ifdef FC_DUMMY_MAIN_EQ_F77
 #  undef F77_DUMMY_MAIN
@@ -6765,30 +7816,81 @@
   return 0;
 }
 _ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
   mv conftest.$ac_objext cfortran_test.$ac_objext
 else
-  { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	{ { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "cannot compile a simple C program
-See \`config.log' for more details" "$LINENO" 5; }
+{ { $as_echo "$as_me:$LINENO: error: cannot compile a simple C program
+See \`config.log' for more details." >&5
+$as_echo "$as_me: error: cannot compile a simple C program
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }; }
 fi
+
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
    ac_ext=${ac_fc_srcext-f}
 ac_compile='$FC -c $FCFLAGS $ac_fcflags_srcext conftest.$ac_ext >&5'
 ac_link='$FC -o conftest$ac_exeext $FCFLAGS $LDFLAGS $ac_fcflags_srcext conftest.$ac_ext $LIBS >&5'
 ac_compiler_gnu=$ac_cv_fc_compiler_gnu
 
-   cat > conftest.$ac_ext <<_ACEOF
+   cat >conftest.$ac_ext <<_ACEOF
       subroutine foobar()
       return
       end
 _ACEOF
-if ac_fn_fc_try_link "$LINENO"; then :
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_fc_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext && {
+	 test "$cross_compiling" = yes ||
+	 $as_test_x conftest$ac_exeext
+       }; then
   ac_cv_fortran_main=$ac_func; break
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+
 fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
+
+rm -rf conftest.dSYM
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
    rm -f cfortran_test* conftest*
  done
  ac_cv_fc_main=$ac_cv_fortran_main
@@ -6796,7 +7898,7 @@
  LIBS=$ac_fc_m_save_LIBS
 
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_fc_main" >&5
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_fc_main" >&5
 $as_echo "$ac_cv_fc_main" >&6; }
 
 cat >>confdefs.h <<_ACEOF
@@ -6812,13 +7914,283 @@
 
 fi
 
+if test "$want_adios" = yes; then
+
+  ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+  if test "${ac_cv_header_mxml_h+set}" = set; then
+  { $as_echo "$as_me:$LINENO: checking for mxml.h" >&5
+$as_echo_n "checking for mxml.h... " >&6; }
+if test "${ac_cv_header_mxml_h+set}" = set; then
+  $as_echo_n "(cached) " >&6
+fi
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_header_mxml_h" >&5
+$as_echo "$ac_cv_header_mxml_h" >&6; }
+else
+  # Is the header compilable?
+{ $as_echo "$as_me:$LINENO: checking mxml.h usability" >&5
+$as_echo_n "checking mxml.h usability... " >&6; }
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+#include <mxml.h>
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_header_compiler=yes
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	ac_header_compiler=no
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
+$as_echo "$ac_header_compiler" >&6; }
+
+# Is the header present?
+{ $as_echo "$as_me:$LINENO: checking mxml.h presence" >&5
+$as_echo_n "checking mxml.h presence... " >&6; }
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <mxml.h>
+_ACEOF
+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:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null && {
+	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       }; then
+  ac_header_preproc=yes
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+  ac_header_preproc=no
+fi
+
+rm -f conftest.err conftest.$ac_ext
+{ $as_echo "$as_me:$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:$LINENO: WARNING: mxml.h: accepted by the compiler, rejected by the preprocessor!" >&5
+$as_echo "$as_me: WARNING: mxml.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
+    { $as_echo "$as_me:$LINENO: WARNING: mxml.h: proceeding with the compiler's result" >&5
+$as_echo "$as_me: WARNING: mxml.h: proceeding with the compiler's result" >&2;}
+    ac_header_preproc=yes
+    ;;
+  no:yes:* )
+    { $as_echo "$as_me:$LINENO: WARNING: mxml.h: present but cannot be compiled" >&5
+$as_echo "$as_me: WARNING: mxml.h: present but cannot be compiled" >&2;}
+    { $as_echo "$as_me:$LINENO: WARNING: mxml.h:     check for missing prerequisite headers?" >&5
+$as_echo "$as_me: WARNING: mxml.h:     check for missing prerequisite headers?" >&2;}
+    { $as_echo "$as_me:$LINENO: WARNING: mxml.h: see the Autoconf documentation" >&5
+$as_echo "$as_me: WARNING: mxml.h: see the Autoconf documentation" >&2;}
+    { $as_echo "$as_me:$LINENO: WARNING: mxml.h:     section \"Present But Cannot Be Compiled\"" >&5
+$as_echo "$as_me: WARNING: mxml.h:     section \"Present But Cannot Be Compiled\"" >&2;}
+    { $as_echo "$as_me:$LINENO: WARNING: mxml.h: proceeding with the preprocessor's result" >&5
+$as_echo "$as_me: WARNING: mxml.h: proceeding with the preprocessor's result" >&2;}
+    { $as_echo "$as_me:$LINENO: WARNING: mxml.h: in the future, the compiler will take precedence" >&5
+$as_echo "$as_me: WARNING: mxml.h: in the future, the compiler will take precedence" >&2;}
+    ( cat <<\_ASBOX
+## -------------------------------------- ##
+## Report this to jtromp AT princeton.edu ##
+## -------------------------------------- ##
+_ASBOX
+     ) | sed "s/^/$as_me: WARNING:     /" >&2
+    ;;
+esac
+{ $as_echo "$as_me:$LINENO: checking for mxml.h" >&5
+$as_echo_n "checking for mxml.h... " >&6; }
+if test "${ac_cv_header_mxml_h+set}" = set; then
+  $as_echo_n "(cached) " >&6
+else
+  ac_cv_header_mxml_h=$ac_header_preproc
+fi
+{ $as_echo "$as_me:$LINENO: result: $ac_cv_header_mxml_h" >&5
+$as_echo "$ac_cv_header_mxml_h" >&6; }
+
+fi
+if test "x$ac_cv_header_mxml_h" = x""yes; then
+  :
+else
+
+    { { $as_echo "$as_me:$LINENO: error: mxml C header not found; try CPPFLAGS=\"-I<mxml include dir>\"" >&5
+$as_echo "$as_me: error: mxml C header not found; try CPPFLAGS=\"-I<mxml include dir>\"" >&2;}
+   { (exit 1); exit 1; }; }
+
+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:$LINENO: checking for mxmlNewXML in -lmxml" >&5
+$as_echo_n "checking for mxmlNewXML in -lmxml... " >&6; }
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <mxml.h>
+#ifdef FC_DUMMY_MAIN
+#ifndef FC_DUMMY_MAIN_EQ_F77
+#  ifdef __cplusplus
+     extern "C"
+#  endif
+   int FC_DUMMY_MAIN() { return 1; }
+#endif
+#endif
+int
+main ()
+{
+mxml_node_t *xml = mxmlNewXML("1.0");
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  { $as_echo "$as_me:$LINENO: result: yes" >&5
+$as_echo "yes" >&6; }
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	{ $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+     { { $as_echo "$as_me:$LINENO: error: mxml library not found; try LDFLAGS=\"-L<mxml lib dir>\"" >&5
+$as_echo "$as_me: error: mxml library not found; try LDFLAGS=\"-L<mxml lib dir>\"" >&2;}
+   { (exit 1); exit 1; }; }
+
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+  ac_ext=${ac_fc_srcext-f}
+ac_compile='$FC -c $FCFLAGS $ac_fcflags_srcext conftest.$ac_ext >&5'
+ac_link='$FC -o conftest$ac_exeext $FCFLAGS $LDFLAGS $ac_fcflags_srcext conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_fc_compiler_gnu
+
+  { $as_echo "$as_me:$LINENO: checking for adios_init in -ladiosf" >&5
+$as_echo_n "checking for adios_init in -ladiosf... " >&6; }
+      FC_BCK=$FC
+  FC=$MPIFC
+  cat >conftest.$ac_ext <<_ACEOF
+      program main
+use adios_write_mod; call adios_init_noxml(MPI_COMM_WORLD, ierr)
+      end
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_fc_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  { $as_echo "$as_me:$LINENO: result: yes" >&5
+$as_echo "yes" >&6; }
+else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	{ $as_echo "$as_me:$LINENO: result: no" >&5
+$as_echo "no" >&6; }
+     { { $as_echo "$as_me:$LINENO: error: adiosf library not found; try LDFLAGS=\"-L<adios lib dir>\"
+					     and FCFLAGS=\"-I<adios inc dir>\"" >&5
+$as_echo "$as_me: error: adiosf library not found; try LDFLAGS=\"-L<adios lib dir>\"
+					     and FCFLAGS=\"-I<adios inc dir>\"" >&2;}
+   { (exit 1); exit 1; }; }
+
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext    FC=$FC_BCK
+
+fi
+
 if test "$want_cuda" = yes; then
 
   # Extract the first word of "nvcc", so it can be a program name with args.
 set dummy nvcc; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_NVCC+:} false; then :
+if test "${ac_cv_path_NVCC+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
   case $NVCC in
@@ -6831,14 +8203,14 @@
 do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
-    for ac_exec_ext in '' $ac_executable_extensions; do
-  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+  for ac_exec_ext in '' $ac_executable_extensions; do
+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
     ac_cv_path_NVCC="$as_dir/$ac_word$ac_exec_ext"
-    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
 done
-  done
+done
 IFS=$as_save_IFS
 
   ;;
@@ -6846,19 +8218,22 @@
 fi
 NVCC=$ac_cv_path_NVCC
 if test -n "$NVCC"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $NVCC" >&5
+  { $as_echo "$as_me:$LINENO: result: $NVCC" >&5
 $as_echo "$NVCC" >&6; }
 else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+  { $as_echo "$as_me:$LINENO: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
 
   if test -z "$NVCC" ; then
-    { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+    { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "cannot find 'nvcc' program.
-See \`config.log' for more details" "$LINENO" 5; }
+{ { $as_echo "$as_me:$LINENO: error: cannot find 'nvcc' program.
+See \`config.log' for more details." >&5
+$as_echo "$as_me: error: cannot find 'nvcc' program.
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }; }
     NVCC=`echo "Error: nvcc is not installed." ; false`
   fi
 
@@ -6876,7 +8251,7 @@
 FC=$FC
 FCFLAGS="$FCFLAGS $FLAGS_CHECK"
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether OpenMP directives work" >&5
+{ $as_echo "$as_me:$LINENO: checking whether OpenMP directives work" >&5
 $as_echo_n "checking whether OpenMP directives work... " >&6; }
 
 #AC_COMPILE_IFELSE(_CIT_FC_TRIVIAL_OPENMP_PROGRAM, [
@@ -6886,7 +8261,7 @@
 #    AC_MSG_FAILURE([cannot compile a trivial OpenMP program using $FC])
 #])
 
-cat > conftest.$ac_ext <<_ACEOF
+cat >conftest.$ac_ext <<_ACEOF
 
       program main
 
@@ -6904,38 +8279,72 @@
       end
 
 _ACEOF
-if ac_fn_fc_try_link "$LINENO"; then :
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
+$as_echo "$ac_try_echo") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_fc_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext && {
+	 test "$cross_compiling" = yes ||
+	 $as_test_x conftest$ac_exeext
+       }; then
 
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+    { $as_echo "$as_me:$LINENO: result: yes" >&5
 $as_echo "yes" >&6; }
 
 else
+  $as_echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
 
-    { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+
+    { $as_echo "$as_me:$LINENO: result: no" >&5
 $as_echo "no" >&6; }
-    { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+    { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "cannot link a trivial OpenMP program using $FC with flags: $FLAGS_CHECK
-See \`config.log' for more details" "$LINENO" 5; }
+{ { $as_echo "$as_me:$LINENO: error: cannot link a trivial OpenMP program using $FC with flags: $FLAGS_CHECK
+See \`config.log' for more details." >&5
+$as_echo "$as_me: error: cannot link a trivial OpenMP program using $FC with flags: $FLAGS_CHECK
+See \`config.log' for more details." >&2;}
+   { (exit 1); exit 1; }; }; }
 
 fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
 
+rm -rf conftest.dSYM
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+
 FC=$cit_fc_save_fc
 FCFLAGS=$cit_fc_save_fcflags
 
 
-ac_ext=c
-ac_cpp='$CPP $CPPFLAGS'
-ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
-ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
-ac_compiler_gnu=$ac_cv_c_compiler_gnu
+ac_ext=${ac_fc_srcext-f}
+ac_compile='$FC -c $FCFLAGS $ac_fcflags_srcext conftest.$ac_ext >&5'
+ac_link='$FC -o conftest$ac_exeext $FCFLAGS $LDFLAGS $ac_fcflags_srcext conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_fc_compiler_gnu
 
 
 fi
 
+#mpbl: adding flags to config.h.in through autoheader in order to save them into the adios file.
+configure_flags_str="FC=$FC FCFLAGS=$FLAGS_NO_CHECK"
 
+cat >>confdefs.h <<_ACEOF
+#define CONFIGURE_FLAGS "${configure_flags_str}"
+_ACEOF
+
+
 # Checks for library functions.
 
 ac_config_files="$ac_config_files Makefile src/meshfem3D/Makefile src/decompose_mesh/Makefile src/specfem3D/Makefile src/generate_databases/Makefile src/shared/constants.h src/shared/precision.h src/decompose_mesh/scotch/src/Makefile.inc src/check_mesh_quality_CUBIT_Abaqus/Makefile"
@@ -6967,13 +8376,13 @@
     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
+      *_cv_*) { $as_echo "$as_me:$LINENO: WARNING: cache variable $ac_var contains a newline" >&5
 $as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;;
       esac
       case $ac_var in #(
       _ | IFS | as_nl) ;; #(
       BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #(
-      *) { eval $ac_var=; unset $ac_var;} ;;
+      *) $as_unset $ac_var ;;
       esac ;;
     esac
   done
@@ -6981,8 +8390,8 @@
   (set) 2>&1 |
     case $as_nl`(ac_space=' '; set) 2>&1` in #(
     *${as_nl}ac_space=\ *)
-      # `set' does not quote correctly, so add quotes: double-quote
-      # substitution turns \\\\ into \\, and sed turns \\ into \.
+      # `set' does not quote correctly, so add quotes (double-quote
+      # substitution turns \\\\ into \\, and sed turns \\ into \).
       sed -n \
 	"s/'/'\\\\''/g;
 	  s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p"
@@ -7004,23 +8413,12 @@
      :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
+    test "x$cache_file" != "x/dev/null" &&
+      { $as_echo "$as_me:$LINENO: updating cache $cache_file" >&5
 $as_echo "$as_me: updating cache $cache_file" >&6;}
-      if test ! -f "$cache_file" || test -h "$cache_file"; then
-	cat confcache >"$cache_file"
-      else
-        case $cache_file in #(
-        */* | ?:*)
-	  mv -f confcache "$cache_file"$$ &&
-	  mv -f "$cache_file"$$ "$cache_file" ;; #(
-        *)
-	  mv -f confcache "$cache_file" ;;
-	esac
-      fi
-    fi
+    cat confcache >$cache_file
   else
-    { $as_echo "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5
+    { $as_echo "$as_me:$LINENO: not updating unwritable cache $cache_file" >&5
 $as_echo "$as_me: not updating unwritable cache $cache_file" >&6;}
   fi
 fi
@@ -7034,15 +8432,14 @@
 
 ac_libobjs=
 ac_ltlibobjs=
-U=
 for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue
   # 1. Remove the extension, and $U if already installed.
   ac_script='s/\$U\././;s/\.o$//;s/\.obj$//'
   ac_i=`$as_echo "$ac_i" | sed "$ac_script"`
   # 2. Prepend LIBOBJDIR.  When used with automake>=1.10 LIBOBJDIR
   #    will be set to the directory where LIBOBJS objects are built.
-  as_fn_append ac_libobjs " \${LIBOBJDIR}$ac_i\$U.$ac_objext"
-  as_fn_append ac_ltlibobjs " \${LIBOBJDIR}$ac_i"'$U.lo'
+  ac_libobjs="$ac_libobjs \${LIBOBJDIR}$ac_i\$U.$ac_objext"
+  ac_ltlibobjs="$ac_ltlibobjs \${LIBOBJDIR}$ac_i"'$U.lo'
 done
 LIBOBJS=$ac_libobjs
 
@@ -7050,34 +8447,55 @@
 
 
 if test -z "${COND_PYRE_TRUE}" && test -z "${COND_PYRE_FALSE}"; then
-  as_fn_error $? "conditional \"COND_PYRE\" was never defined.
-Usually this means the macro was only invoked conditionally." "$LINENO" 5
+  { { $as_echo "$as_me:$LINENO: error: conditional \"COND_PYRE\" was never defined.
+Usually this means the macro was only invoked conditionally." >&5
+$as_echo "$as_me: error: conditional \"COND_PYRE\" was never defined.
+Usually this means the macro was only invoked conditionally." >&2;}
+   { (exit 1); exit 1; }; }
 fi
 if test -z "${COND_MPI_TRUE}" && test -z "${COND_MPI_FALSE}"; then
-  as_fn_error $? "conditional \"COND_MPI\" was never defined.
-Usually this means the macro was only invoked conditionally." "$LINENO" 5
+  { { $as_echo "$as_me:$LINENO: error: conditional \"COND_MPI\" was never defined.
+Usually this means the macro was only invoked conditionally." >&5
+$as_echo "$as_me: error: conditional \"COND_MPI\" was never defined.
+Usually this means the macro was only invoked conditionally." >&2;}
+   { (exit 1); exit 1; }; }
 fi
 if test -z "${COND_CUDA_TRUE}" && test -z "${COND_CUDA_FALSE}"; then
-  as_fn_error $? "conditional \"COND_CUDA\" was never defined.
-Usually this means the macro was only invoked conditionally." "$LINENO" 5
+  { { $as_echo "$as_me:$LINENO: error: conditional \"COND_CUDA\" was never defined.
+Usually this means the macro was only invoked conditionally." >&5
+$as_echo "$as_me: error: conditional \"COND_CUDA\" was never defined.
+Usually this means the macro was only invoked conditionally." >&2;}
+   { (exit 1); exit 1; }; }
 fi
 if test -z "${COND_CUDA5_TRUE}" && test -z "${COND_CUDA5_FALSE}"; then
-  as_fn_error $? "conditional \"COND_CUDA5\" was never defined.
-Usually this means the macro was only invoked conditionally." "$LINENO" 5
+  { { $as_echo "$as_me:$LINENO: error: conditional \"COND_CUDA5\" was never defined.
+Usually this means the macro was only invoked conditionally." >&5
+$as_echo "$as_me: error: conditional \"COND_CUDA5\" was never defined.
+Usually this means the macro was only invoked conditionally." >&2;}
+   { (exit 1); exit 1; }; }
 fi
+if test -z "${COND_ADIOS_TRUE}" && test -z "${COND_ADIOS_FALSE}"; then
+  { { $as_echo "$as_me:$LINENO: error: conditional \"COND_ADIOS\" was never defined.
+Usually this means the macro was only invoked conditionally." >&5
+$as_echo "$as_me: error: conditional \"COND_ADIOS\" was never defined.
+Usually this means the macro was only invoked conditionally." >&2;}
+   { (exit 1); exit 1; }; }
+fi
 if test -z "${COND_OPENMP_TRUE}" && test -z "${COND_OPENMP_FALSE}"; then
-  as_fn_error $? "conditional \"COND_OPENMP\" was never defined.
-Usually this means the macro was only invoked conditionally." "$LINENO" 5
+  { { $as_echo "$as_me:$LINENO: error: conditional \"COND_OPENMP\" was never defined.
+Usually this means the macro was only invoked conditionally." >&5
+$as_echo "$as_me: error: conditional \"COND_OPENMP\" was never defined.
+Usually this means the macro was only invoked conditionally." >&2;}
+   { (exit 1); exit 1; }; }
 fi
 
-: "${CONFIG_STATUS=./config.status}"
+: ${CONFIG_STATUS=./config.status}
 ac_write_fail=0
 ac_clean_files_save=$ac_clean_files
 ac_clean_files="$ac_clean_files $CONFIG_STATUS"
-{ $as_echo "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5
+{ $as_echo "$as_me:$LINENO: creating $CONFIG_STATUS" >&5
 $as_echo "$as_me: creating $CONFIG_STATUS" >&6;}
-as_write_fail=0
-cat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1
+cat >$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 #! $SHELL
 # Generated by $as_me.
 # Run this file to recreate the current configuration.
@@ -7087,18 +8505,17 @@
 debug=false
 ac_cs_recheck=false
 ac_cs_silent=false
-
 SHELL=\${CONFIG_SHELL-$SHELL}
-export SHELL
-_ASEOF
-cat >>$CONFIG_STATUS <<\_ASEOF || as_write_fail=1
-## -------------------- ##
-## M4sh Initialization. ##
-## -------------------- ##
+_ACEOF
 
+cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
+## --------------------- ##
+## M4sh Initialization.  ##
+## --------------------- ##
+
 # Be more Bourne compatible
 DUALCASE=1; export DUALCASE # for MKS sh
-if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
   emulate sh
   NULLCMD=:
   # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
@@ -7106,15 +8523,23 @@
   alias -g '${1+"$@"}'='"$@"'
   setopt NO_GLOB_SUBST
 else
-  case `(set -o) 2>/dev/null` in #(
-  *posix*) :
-    set -o posix ;; #(
-  *) :
-     ;;
+  case `(set -o) 2>/dev/null` in
+  *posix*) set -o posix ;;
 esac
+
 fi
 
 
+
+
+# PATH needs CR
+# Avoid depending upon Character Ranges.
+as_cr_letters='abcdefghijklmnopqrstuvwxyz'
+as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+as_cr_Letters=$as_cr_letters$as_cr_LETTERS
+as_cr_digits='0123456789'
+as_cr_alnum=$as_cr_Letters$as_cr_digits
+
 as_nl='
 '
 export as_nl
@@ -7122,13 +8547,7 @@
 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
+if (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then
   as_echo='printf %s\n'
   as_echo_n='printf %s'
 else
@@ -7139,7 +8558,7 @@
     as_echo_body='eval expr "X$1" : "X\\(.*\\)"'
     as_echo_n_body='eval
       arg=$1;
-      case $arg in #(
+      case $arg in
       *"$as_nl"*)
 	expr "X$arg" : "X\\(.*\\)$as_nl";
 	arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;;
@@ -7162,7 +8581,14 @@
   }
 fi
 
+# Support unset when possible.
+if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then
+  as_unset=unset
+else
+  as_unset=false
+fi
 
+
 # IFS
 # We need space, tab and new line, in precisely that order.  Quoting is
 # there to prevent editors from complaining about space-tab.
@@ -7171,16 +8597,15 @@
 IFS=" ""	$as_nl"
 
 # Find who we are.  Look in the path if we contain no directory separator.
-as_myself=
-case $0 in #((
+case $0 in
   *[\\/]* ) as_myself=$0 ;;
   *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
 for as_dir in $PATH
 do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
-    test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
-  done
+  test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
+done
 IFS=$as_save_IFS
 
      ;;
@@ -7192,16 +8617,12 @@
 fi
 if test ! -f "$as_myself"; then
   $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
-  exit 1
+  { (exit 1); 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 || :
+# Work around bugs in pre-3.0 UWIN ksh.
+for as_var in ENV MAIL MAILPATH
+do ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var
 done
 PS1='$ '
 PS2='> '
@@ -7213,89 +8634,7 @@
 LANGUAGE=C
 export LANGUAGE
 
-# CDPATH.
-(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
-
-
-# as_fn_error STATUS ERROR [LINENO LOG_FD]
-# ----------------------------------------
-# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are
-# provided, also output the error to LOG_FD, referencing LINENO. Then exit the
-# script with STATUS, using 1 if that was 0.
-as_fn_error ()
-{
-  as_status=$1; test $as_status -eq 0 && as_status=1
-  if test "$4"; then
-    as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
-    $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4
-  fi
-  $as_echo "$as_me: error: $2" >&2
-  as_fn_exit $as_status
-} # as_fn_error
-
-
-# as_fn_set_status STATUS
-# -----------------------
-# Set $? to STATUS, without forking.
-as_fn_set_status ()
-{
-  return $1
-} # as_fn_set_status
-
-# as_fn_exit STATUS
-# -----------------
-# Exit the shell with STATUS, even in a "trap 0" or "set -e" context.
-as_fn_exit ()
-{
-  set +e
-  as_fn_set_status $1
-  exit $1
-} # as_fn_exit
-
-# as_fn_unset VAR
-# ---------------
-# Portably unset VAR.
-as_fn_unset ()
-{
-  { eval $1=; unset $1;}
-}
-as_unset=as_fn_unset
-# as_fn_append VAR VALUE
-# ----------------------
-# Append the text in VALUE to the end of the definition contained in VAR. Take
-# advantage of any shell optimizations that allow amortized linear growth over
-# repeated appends, instead of the typical quadratic growth present in naive
-# implementations.
-if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then :
-  eval 'as_fn_append ()
-  {
-    eval $1+=\$2
-  }'
-else
-  as_fn_append ()
-  {
-    eval $1=\$$1\$2
-  }
-fi # as_fn_append
-
-# as_fn_arith ARG...
-# ------------------
-# Perform arithmetic evaluation on the ARGs, and store the result in the
-# global $as_val. Take advantage of shells that can avoid forks. The arguments
-# must be portable across $(()) and expr.
-if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then :
-  eval 'as_fn_arith ()
-  {
-    as_val=$(( $* ))
-  }'
-else
-  as_fn_arith ()
-  {
-    as_val=`expr "$@" || test $? -eq 1`
-  }
-fi # as_fn_arith
-
-
+# Required to use basename.
 if expr a : '\(a\)' >/dev/null 2>&1 &&
    test "X`expr 00001 : '.*\(...\)'`" = X001; then
   as_expr=expr
@@ -7309,12 +8648,8 @@
   as_basename=false
 fi
 
-if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then
-  as_dirname=dirname
-else
-  as_dirname=false
-fi
 
+# Name of the executable.
 as_me=`$as_basename -- "$0" ||
 $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
 	 X"$0" : 'X\(//\)$' \| \
@@ -7334,25 +8669,76 @@
 	  }
 	  s/.*/./; q'`
 
-# Avoid depending upon Character Ranges.
-as_cr_letters='abcdefghijklmnopqrstuvwxyz'
-as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
-as_cr_Letters=$as_cr_letters$as_cr_LETTERS
-as_cr_digits='0123456789'
-as_cr_alnum=$as_cr_Letters$as_cr_digits
+# CDPATH.
+$as_unset CDPATH
 
+
+
+  as_lineno_1=$LINENO
+  as_lineno_2=$LINENO
+  test "x$as_lineno_1" != "x$as_lineno_2" &&
+  test "x`expr $as_lineno_1 + 1`" = "x$as_lineno_2" || {
+
+  # Create $as_me.lineno as a copy of $as_myself, but with $LINENO
+  # uniformly replaced by the line number.  The first 'sed' inserts a
+  # line-number line after each line using $LINENO; the second 'sed'
+  # does the real work.  The second script uses 'N' to pair each
+  # line-number line with the line containing $LINENO, and appends
+  # trailing '-' during substitution so that $LINENO is not a special
+  # case at line end.
+  # (Raja R Harinath suggested sed '=', and Paul Eggert wrote the
+  # scripts with optimization help from Paolo Bonzini.  Blame Lee
+  # E. McMahon (1931-1989) for sed's syntax.  :-)
+  sed -n '
+    p
+    /[$]LINENO/=
+  ' <$as_myself |
+    sed '
+      s/[$]LINENO.*/&-/
+      t lineno
+      b
+      :lineno
+      N
+      :loop
+      s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/
+      t loop
+      s/-\n.*//
+    ' >$as_me.lineno &&
+  chmod +x "$as_me.lineno" ||
+    { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2
+   { (exit 1); exit 1; }; }
+
+  # Don't try to exec as it changes $[0], causing all sort of problems
+  # (the dirname of $[0] is not the place where we might find the
+  # original and so on.  Autoconf is especially sensitive to this).
+  . "./$as_me.lineno"
+  # Exit status is that of the last command.
+  exit
+}
+
+
+if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then
+  as_dirname=dirname
+else
+  as_dirname=false
+fi
+
 ECHO_C= ECHO_N= ECHO_T=
-case `echo -n x` in #(((((
+case `echo -n x` in
 -n*)
-  case `echo 'xy\c'` in
+  case `echo 'x\c'` in
   *c*) ECHO_T='	';;	# ECHO_T is single tab character.
-  xy)  ECHO_C='\c';;
-  *)   echo `echo ksh88 bug on AIX 6.1` > /dev/null
-       ECHO_T='	';;
+  *)   ECHO_C='\c';;
   esac;;
 *)
   ECHO_N='-n';;
 esac
+if expr a : '\(a\)' >/dev/null 2>&1 &&
+   test "X`expr 00001 : '.*\(...\)'`" = X001; then
+  as_expr=expr
+else
+  as_expr=false
+fi
 
 rm -f conf$$ conf$$.exe conf$$.file
 if test -d conf$$.dir; then
@@ -7367,86 +8753,50 @@
     # ... but there are two gotchas:
     # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
     # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
-    # In both cases, we have to default to `cp -pR'.
+    # In both cases, we have to default to `cp -p'.
     ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
-      as_ln_s='cp -pR'
+      as_ln_s='cp -p'
   elif ln conf$$.file conf$$ 2>/dev/null; then
     as_ln_s=ln
   else
-    as_ln_s='cp -pR'
+    as_ln_s='cp -p'
   fi
 else
-  as_ln_s='cp -pR'
+  as_ln_s='cp -p'
 fi
 rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file
 rmdir conf$$.dir 2>/dev/null
 
-
-# as_fn_mkdir_p
-# -------------
-# Create "$as_dir" as a directory, including parents if necessary.
-as_fn_mkdir_p ()
-{
-
-  case $as_dir in #(
-  -*) as_dir=./$as_dir;;
-  esac
-  test -d "$as_dir" || eval $as_mkdir_p || {
-    as_dirs=
-    while :; do
-      case $as_dir in #(
-      *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'(
-      *) as_qdir=$as_dir;;
-      esac
-      as_dirs="'$as_qdir' $as_dirs"
-      as_dir=`$as_dirname -- "$as_dir" ||
-$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
-	 X"$as_dir" : 'X\(//\)[^/]' \| \
-	 X"$as_dir" : 'X\(//\)$' \| \
-	 X"$as_dir" : 'X\(/\)' \| . 2>/dev/null ||
-$as_echo X"$as_dir" |
-    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
-	    s//\1/
-	    q
-	  }
-	  /^X\(\/\/\)[^/].*/{
-	    s//\1/
-	    q
-	  }
-	  /^X\(\/\/\)$/{
-	    s//\1/
-	    q
-	  }
-	  /^X\(\/\).*/{
-	    s//\1/
-	    q
-	  }
-	  s/.*/./; q'`
-      test -d "$as_dir" && break
-    done
-    test -z "$as_dirs" || eval "mkdir $as_dirs"
-  } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir"
-
-
-} # as_fn_mkdir_p
 if mkdir -p . 2>/dev/null; then
-  as_mkdir_p='mkdir -p "$as_dir"'
+  as_mkdir_p=:
 else
   test -d ./-p && rmdir ./-p
   as_mkdir_p=false
 fi
 
+if test -x / >/dev/null 2>&1; then
+  as_test_x='test -x'
+else
+  if ls -dL / >/dev/null 2>&1; then
+    as_ls_L_option=L
+  else
+    as_ls_L_option=
+  fi
+  as_test_x='
+    eval sh -c '\''
+      if test -d "$1"; then
+	test -d "$1/.";
+      else
+	case $1 in
+	-*)set "./$1";;
+	esac;
+	case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in
+	???[sx]*):;;*)false;;esac;fi
+    '\'' sh
+  '
+fi
+as_executable_p=$as_test_x
 
-# as_fn_executable_p FILE
-# -----------------------
-# Test if FILE is an executable regular file.
-as_fn_executable_p ()
-{
-  test -f "$1" && test -x "$1"
-} # as_fn_executable_p
-as_test_x='test -x'
-as_executable_p=as_fn_executable_p
-
 # Sed expression to map a string onto a valid CPP name.
 as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
 
@@ -7455,19 +8805,13 @@
 
 
 exec 6>&1
-## ----------------------------------- ##
-## Main body of $CONFIG_STATUS script. ##
-## ----------------------------------- ##
-_ASEOF
-test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1
 
-cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
-# Save the log message, to keep $0 and so on meaningful, and to
+# Save the log message, to keep $[0] and so on meaningful, and to
 # report actual input values of CONFIG_FILES etc. instead of their
 # values after options handling.
 ac_log="
 This file was extended by Specfem 3D $as_me 2.1.0, which was
-generated by GNU Autoconf 2.69.  Invocation command line was
+generated by GNU Autoconf 2.63.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
   CONFIG_HEADERS  = $CONFIG_HEADERS
@@ -7498,15 +8842,13 @@
 
 cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
 ac_cs_usage="\
-\`$as_me' instantiates files and other configuration actions
-from templates according to the current configuration.  Unless the files
-and actions are specified as TAGs, all are instantiated by default.
+\`$as_me' instantiates files from templates according to the
+current configuration.
 
-Usage: $0 [OPTION]... [TAG]...
+Usage: $0 [OPTION]... [FILE]...
 
   -h, --help       print this help, then exit
   -V, --version    print version number and configuration settings, then exit
-      --config     print configuration, then exit
   -q, --quiet, --silent
                    do not print progress messages
   -d, --debug      don't remove temporary files
@@ -7522,17 +8864,16 @@
 Configuration headers:
 $config_headers
 
-Report bugs to <jtromp AT princeton.edu>."
+Report bugs to <bug-autoconf at gnu.org>."
 
 _ACEOF
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
-ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
 ac_cs_version="\\
 Specfem 3D config.status 2.1.0
-configured by $0, generated by GNU Autoconf 2.69,
-  with options \\"\$ac_cs_config\\"
+configured by $0, generated by GNU Autoconf 2.63,
+  with options \\"`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\"
 
-Copyright (C) 2012 Free Software Foundation, Inc.
+Copyright (C) 2008 Free Software Foundation, Inc.
 This config.status script is free software; the Free Software Foundation
 gives unlimited permission to copy, distribute and modify it."
 
@@ -7547,16 +8888,11 @@
 while test $# != 0
 do
   case $1 in
-  --*=?*)
+  --*=*)
     ac_option=`expr "X$1" : 'X\([^=]*\)='`
     ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'`
     ac_shift=:
     ;;
-  --*=)
-    ac_option=`expr "X$1" : 'X\([^=]*\)='`
-    ac_optarg=
-    ac_shift=:
-    ;;
   *)
     ac_option=$1
     ac_optarg=$2
@@ -7570,29 +8906,27 @@
     ac_cs_recheck=: ;;
   --version | --versio | --versi | --vers | --ver | --ve | --v | -V )
     $as_echo "$ac_cs_version"; exit ;;
-  --config | --confi | --conf | --con | --co | --c )
-    $as_echo "$ac_cs_config"; exit ;;
   --debug | --debu | --deb | --de | --d | -d )
     debug=: ;;
   --file | --fil | --fi | --f )
     $ac_shift
     case $ac_optarg in
     *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;;
-    '') as_fn_error $? "missing file argument" ;;
     esac
-    as_fn_append CONFIG_FILES " '$ac_optarg'"
+    CONFIG_FILES="$CONFIG_FILES '$ac_optarg'"
     ac_need_defaults=false;;
   --header | --heade | --head | --hea )
     $ac_shift
     case $ac_optarg in
     *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;;
     esac
-    as_fn_append CONFIG_HEADERS " '$ac_optarg'"
+    CONFIG_HEADERS="$CONFIG_HEADERS '$ac_optarg'"
     ac_need_defaults=false;;
   --he | --h)
     # Conflict between --help and --header
-    as_fn_error $? "ambiguous option: \`$1'
-Try \`$0 --help' for more information.";;
+    { $as_echo "$as_me: error: ambiguous option: $1
+Try \`$0 --help' for more information." >&2
+   { (exit 1); exit 1; }; };;
   --help | --hel | -h )
     $as_echo "$ac_cs_usage"; exit ;;
   -q | -quiet | --quiet | --quie | --qui | --qu | --q \
@@ -7600,10 +8934,11 @@
     ac_cs_silent=: ;;
 
   # This is an error.
-  -*) as_fn_error $? "unrecognized option: \`$1'
-Try \`$0 --help' for more information." ;;
+  -*) { $as_echo "$as_me: error: unrecognized option: $1
+Try \`$0 --help' for more information." >&2
+   { (exit 1); exit 1; }; } ;;
 
-  *) as_fn_append ac_config_targets " $1"
+  *) ac_config_targets="$ac_config_targets $1"
      ac_need_defaults=false ;;
 
   esac
@@ -7620,7 +8955,7 @@
 _ACEOF
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 if \$ac_cs_recheck; then
-  set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion
+  set X '$SHELL' '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion
   shift
   \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6
   CONFIG_SHELL='$SHELL'
@@ -7660,7 +8995,9 @@
     "src/decompose_mesh/scotch/src/Makefile.inc") CONFIG_FILES="$CONFIG_FILES src/decompose_mesh/scotch/src/Makefile.inc" ;;
     "src/check_mesh_quality_CUBIT_Abaqus/Makefile") CONFIG_FILES="$CONFIG_FILES src/check_mesh_quality_CUBIT_Abaqus/Makefile" ;;
 
-  *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
+  *) { { $as_echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5
+$as_echo "$as_me: error: invalid argument: $ac_config_target" >&2;}
+   { (exit 1); exit 1; }; };;
   esac
 done
 
@@ -7682,24 +9019,26 @@
 # after its creation but before its name has been assigned to `$tmp'.
 $debug ||
 {
-  tmp= ac_tmp=
+  tmp=
   trap 'exit_status=$?
-  : "${ac_tmp:=$tmp}"
-  { test ! -d "$ac_tmp" || rm -fr "$ac_tmp"; } && exit $exit_status
+  { test -z "$tmp" || test ! -d "$tmp" || rm -fr "$tmp"; } && exit $exit_status
 ' 0
-  trap 'as_fn_exit 1' 1 2 13 15
+  trap '{ (exit 1); exit 1; }' 1 2 13 15
 }
 # Create a (secure) tmp directory for tmp files.
 
 {
   tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` &&
-  test -d "$tmp"
+  test -n "$tmp" && test -d "$tmp"
 }  ||
 {
   tmp=./conf$$-$RANDOM
   (umask 077 && mkdir "$tmp")
-} || as_fn_error $? "cannot create a temporary directory in ." "$LINENO" 5
-ac_tmp=$tmp
+} ||
+{
+   $as_echo "$as_me: cannot create a temporary directory in ." >&2
+   { (exit 1); exit 1; }
+}
 
 # Set up the scripts for CONFIG_FILES section.
 # No need to generate them if there are no CONFIG_FILES.
@@ -7707,13 +9046,8 @@
 if test -n "$CONFIG_FILES"; then
 
 
-ac_cr=`echo X | tr X '\015'`
-# On cygwin, bash can eat \r inside `` if the user requested igncr.
-# But we know of no other shell where ac_cr would be empty at this
-# point, so we can use a bashism as a fallback.
-if test "x$ac_cr" = x; then
-  eval ac_cr=\$\'\\r\'
-fi
+ac_cr='
+'
 ac_cs_awk_cr=`$AWK 'BEGIN { print "a\rb" }' </dev/null 2>/dev/null`
 if test "$ac_cs_awk_cr" = "a${ac_cr}b"; then
   ac_cs_awk_cr='\\r'
@@ -7721,7 +9055,7 @@
   ac_cs_awk_cr=$ac_cr
 fi
 
-echo 'BEGIN {' >"$ac_tmp/subs1.awk" &&
+echo 'BEGIN {' >"$tmp/subs1.awk" &&
 _ACEOF
 
 
@@ -7730,18 +9064,24 @@
   echo "$ac_subst_vars" | sed 's/.*/&!$&$ac_delim/' &&
   echo "_ACEOF"
 } >conf$$subs.sh ||
-  as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5
-ac_delim_num=`echo "$ac_subst_vars" | grep -c '^'`
+  { { $as_echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5
+$as_echo "$as_me: error: could not make $CONFIG_STATUS" >&2;}
+   { (exit 1); exit 1; }; }
+ac_delim_num=`echo "$ac_subst_vars" | grep -c '$'`
 ac_delim='%!_!# '
 for ac_last_try in false false false false false :; do
   . ./conf$$subs.sh ||
-    as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5
+    { { $as_echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5
+$as_echo "$as_me: error: could not make $CONFIG_STATUS" >&2;}
+   { (exit 1); exit 1; }; }
 
   ac_delim_n=`sed -n "s/.*$ac_delim\$/X/p" conf$$subs.awk | grep -c X`
   if test $ac_delim_n = $ac_delim_num; then
     break
   elif $ac_last_try; then
-    as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5
+    { { $as_echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5
+$as_echo "$as_me: error: could not make $CONFIG_STATUS" >&2;}
+   { (exit 1); exit 1; }; }
   else
     ac_delim="$ac_delim!$ac_delim _$ac_delim!! "
   fi
@@ -7749,7 +9089,7 @@
 rm -f conf$$subs.sh
 
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
-cat >>"\$ac_tmp/subs1.awk" <<\\_ACAWK &&
+cat >>"\$tmp/subs1.awk" <<\\_ACAWK &&
 _ACEOF
 sed -n '
 h
@@ -7763,7 +9103,7 @@
 t delim
 :nl
 h
-s/\(.\{148\}\)..*/\1/
+s/\(.\{148\}\).*/\1/
 t more1
 s/["\\]/\\&/g; s/^/"/; s/$/\\n"\\/
 p
@@ -7777,7 +9117,7 @@
 t nl
 :delim
 h
-s/\(.\{148\}\)..*/\1/
+s/\(.\{148\}\).*/\1/
 t more2
 s/["\\]/\\&/g; s/^/"/; s/$/"/
 p
@@ -7797,7 +9137,7 @@
 rm -f conf$$subs.awk
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 _ACAWK
-cat >>"\$ac_tmp/subs1.awk" <<_ACAWK &&
+cat >>"\$tmp/subs1.awk" <<_ACAWK &&
   for (key in S) S_is_set[key] = 1
   FS = ""
 
@@ -7829,29 +9169,23 @@
   sed "s/$ac_cr\$//; s/$ac_cr/$ac_cs_awk_cr/g"
 else
   cat
-fi < "$ac_tmp/subs1.awk" > "$ac_tmp/subs.awk" \
-  || as_fn_error $? "could not setup config files machinery" "$LINENO" 5
+fi < "$tmp/subs1.awk" > "$tmp/subs.awk" \
+  || { { $as_echo "$as_me:$LINENO: error: could not setup config files machinery" >&5
+$as_echo "$as_me: error: could not setup config files machinery" >&2;}
+   { (exit 1); exit 1; }; }
 _ACEOF
 
-# VPATH may cause trouble with some makes, so we remove sole $(srcdir),
-# ${srcdir} and @srcdir@ entries from VPATH if srcdir is ".", strip leading and
+# VPATH may cause trouble with some makes, so we remove $(srcdir),
+# ${srcdir} and @srcdir@ from VPATH if srcdir is ".", strip leading and
 # trailing colons and then remove the whole line if VPATH becomes empty
 # (actually we leave an empty line to preserve line numbers).
 if test "x$srcdir" = x.; then
-  ac_vpsub='/^[	 ]*VPATH[	 ]*=[	 ]*/{
-h
-s///
-s/^/:/
-s/[	 ]*$/:/
-s/:\$(srcdir):/:/g
-s/:\${srcdir}:/:/g
-s/:@srcdir@:/:/g
-s/^:*//
+  ac_vpsub='/^[	 ]*VPATH[	 ]*=/{
+s/:*\$(srcdir):*/:/
+s/:*\${srcdir}:*/:/
+s/:*@srcdir@:*/:/
+s/^\([^=]*=[	 ]*\):*/\1/
 s/:*$//
-x
-s/\(=[	 ]*\).*/\1/
-G
-s/\n//
 s/^[^=]*=[	 ]*$//
 }'
 fi
@@ -7863,7 +9197,7 @@
 # No need to generate them if there are no CONFIG_HEADERS.
 # This happens for instance with `./config.status Makefile'.
 if test -n "$CONFIG_HEADERS"; then
-cat >"$ac_tmp/defines.awk" <<\_ACAWK ||
+cat >"$tmp/defines.awk" <<\_ACAWK ||
 BEGIN {
 _ACEOF
 
@@ -7875,11 +9209,13 @@
 # handling of long lines.
 ac_delim='%!_!# '
 for ac_last_try in false false :; do
-  ac_tt=`sed -n "/$ac_delim/p" confdefs.h`
-  if test -z "$ac_tt"; then
+  ac_t=`sed -n "/$ac_delim/p" confdefs.h`
+  if test -z "$ac_t"; then
     break
   elif $ac_last_try; then
-    as_fn_error $? "could not make $CONFIG_HEADERS" "$LINENO" 5
+    { { $as_echo "$as_me:$LINENO: error: could not make $CONFIG_HEADERS" >&5
+$as_echo "$as_me: error: could not make $CONFIG_HEADERS" >&2;}
+   { (exit 1); exit 1; }; }
   else
     ac_delim="$ac_delim!$ac_delim _$ac_delim!! "
   fi
@@ -7964,7 +9300,9 @@
 _ACAWK
 _ACEOF
 cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
-  as_fn_error $? "could not setup config headers machinery" "$LINENO" 5
+  { { $as_echo "$as_me:$LINENO: error: could not setup config headers machinery" >&5
+$as_echo "$as_me: error: could not setup config headers machinery" >&2;}
+   { (exit 1); exit 1; }; }
 fi # test -n "$CONFIG_HEADERS"
 
 
@@ -7977,7 +9315,9 @@
   esac
   case $ac_mode$ac_tag in
   :[FHL]*:*);;
-  :L* | :C*:*) as_fn_error $? "invalid tag \`$ac_tag'" "$LINENO" 5;;
+  :L* | :C*:*) { { $as_echo "$as_me:$LINENO: error: invalid tag $ac_tag" >&5
+$as_echo "$as_me: error: invalid tag $ac_tag" >&2;}
+   { (exit 1); exit 1; }; };;
   :[FH]-) ac_tag=-:-;;
   :[FH]*) ac_tag=$ac_tag:$ac_tag.in;;
   esac
@@ -7996,7 +9336,7 @@
     for ac_f
     do
       case $ac_f in
-      -) ac_f="$ac_tmp/stdin";;
+      -) ac_f="$tmp/stdin";;
       *) # Look for the file first in the build tree, then in the source tree
 	 # (if the path is not absolute).  The absolute path cannot be DOS-style,
 	 # because $ac_f cannot contain `:'.
@@ -8005,10 +9345,12 @@
 	   [\\/$]*) false;;
 	   *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";;
 	   esac ||
-	   as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5;;
+	   { { $as_echo "$as_me:$LINENO: error: cannot find input file: $ac_f" >&5
+$as_echo "$as_me: error: cannot find input file: $ac_f" >&2;}
+   { (exit 1); exit 1; }; };;
       esac
       case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac
-      as_fn_append ac_file_inputs " '$ac_f'"
+      ac_file_inputs="$ac_file_inputs '$ac_f'"
     done
 
     # Let's still pretend it is `configure' which instantiates (i.e., don't
@@ -8019,7 +9361,7 @@
 	`' 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:$LINENO: creating $ac_file" >&5
 $as_echo "$as_me: creating $ac_file" >&6;}
     fi
     # Neutralize special characters interpreted by sed in replacement strings.
@@ -8031,8 +9373,10 @@
     esac
 
     case $ac_tag in
-    *:-:* | *:-) cat >"$ac_tmp/stdin" \
-      || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;;
+    *:-:* | *:-) cat >"$tmp/stdin" \
+      || { { $as_echo "$as_me:$LINENO: error: could not create $ac_file" >&5
+$as_echo "$as_me: error: could not create $ac_file" >&2;}
+   { (exit 1); exit 1; }; } ;;
     esac
     ;;
   esac
@@ -8060,7 +9404,47 @@
 	    q
 	  }
 	  s/.*/./; q'`
-  as_dir="$ac_dir"; as_fn_mkdir_p
+  { as_dir="$ac_dir"
+  case $as_dir in #(
+  -*) as_dir=./$as_dir;;
+  esac
+  test -d "$as_dir" || { $as_mkdir_p && mkdir -p "$as_dir"; } || {
+    as_dirs=
+    while :; do
+      case $as_dir in #(
+      *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'(
+      *) as_qdir=$as_dir;;
+      esac
+      as_dirs="'$as_qdir' $as_dirs"
+      as_dir=`$as_dirname -- "$as_dir" ||
+$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	 X"$as_dir" : 'X\(//\)[^/]' \| \
+	 X"$as_dir" : 'X\(//\)$' \| \
+	 X"$as_dir" : 'X\(/\)' \| . 2>/dev/null ||
+$as_echo X"$as_dir" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)[^/].*/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\/\)$/{
+	    s//\1/
+	    q
+	  }
+	  /^X\(\/\).*/{
+	    s//\1/
+	    q
+	  }
+	  s/.*/./; q'`
+      test -d "$as_dir" && break
+    done
+    test -z "$as_dirs" || eval "mkdir $as_dirs"
+  } || test -d "$as_dir" || { { $as_echo "$as_me:$LINENO: error: cannot create directory $as_dir" >&5
+$as_echo "$as_me: error: cannot create directory $as_dir" >&2;}
+   { (exit 1); exit 1; }; }; }
   ac_builddir=.
 
 case "$ac_dir" in
@@ -8108,6 +9492,7 @@
 # If the template does not know about datarootdir, expand it.
 # FIXME: This hack should be removed a few years after 2.60.
 ac_datarootdir_hack=; ac_datarootdir_seen=
+
 ac_sed_dataroot='
 /datarootdir/ {
   p
@@ -8117,11 +9502,12 @@
 /@docdir@/p
 /@infodir@/p
 /@localedir@/p
-/@mandir@/p'
+/@mandir@/p
+'
 case `eval "sed -n \"\$ac_sed_dataroot\" $ac_file_inputs"` in
 *datarootdir*) ac_datarootdir_seen=yes;;
 *@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*)
-  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5
+  { $as_echo "$as_me:$LINENO: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5
 $as_echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;}
 _ACEOF
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
@@ -8131,7 +9517,7 @@
   s&@infodir@&$infodir&g
   s&@localedir@&$localedir&g
   s&@mandir@&$mandir&g
-  s&\\\${datarootdir}&$datarootdir&g' ;;
+    s&\\\${datarootdir}&$datarootdir&g' ;;
 esac
 _ACEOF
 
@@ -8157,24 +9543,27 @@
 s&@abs_top_builddir@&$ac_abs_top_builddir&;t t
 $ac_datarootdir_hack
 "
-eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$ac_tmp/subs.awk" \
-  >$ac_tmp/out || as_fn_error $? "could not create $ac_file" "$LINENO" 5
+eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$tmp/subs.awk" >$tmp/out \
+  || { { $as_echo "$as_me:$LINENO: error: could not create $ac_file" >&5
+$as_echo "$as_me: error: could not create $ac_file" >&2;}
+   { (exit 1); exit 1; }; }
 
 test -z "$ac_datarootdir_hack$ac_datarootdir_seen" &&
-  { ac_out=`sed -n '/\${datarootdir}/p' "$ac_tmp/out"`; test -n "$ac_out"; } &&
-  { ac_out=`sed -n '/^[	 ]*datarootdir[	 ]*:*=/p' \
-      "$ac_tmp/out"`; test -z "$ac_out"; } &&
-  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir'
-which seems to be undefined.  Please make sure it is defined" >&5
+  { ac_out=`sed -n '/\${datarootdir}/p' "$tmp/out"`; test -n "$ac_out"; } &&
+  { ac_out=`sed -n '/^[	 ]*datarootdir[	 ]*:*=/p' "$tmp/out"`; test -z "$ac_out"; } &&
+  { $as_echo "$as_me:$LINENO: WARNING: $ac_file contains a reference to the variable \`datarootdir'
+which seems to be undefined.  Please make sure it is defined." >&5
 $as_echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir'
-which seems to be undefined.  Please make sure it is defined" >&2;}
+which seems to be undefined.  Please make sure it is defined." >&2;}
 
-  rm -f "$ac_tmp/stdin"
+  rm -f "$tmp/stdin"
   case $ac_file in
-  -) cat "$ac_tmp/out" && rm -f "$ac_tmp/out";;
-  *) rm -f "$ac_file" && mv "$ac_tmp/out" "$ac_file";;
+  -) cat "$tmp/out" && rm -f "$tmp/out";;
+  *) rm -f "$ac_file" && mv "$tmp/out" "$ac_file";;
   esac \
-  || as_fn_error $? "could not create $ac_file" "$LINENO" 5
+  || { { $as_echo "$as_me:$LINENO: error: could not create $ac_file" >&5
+$as_echo "$as_me: error: could not create $ac_file" >&2;}
+   { (exit 1); exit 1; }; }
  ;;
   :H)
   #
@@ -8183,21 +9572,27 @@
   if test x"$ac_file" != x-; then
     {
       $as_echo "/* $configure_input  */" \
-      && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs"
-    } >"$ac_tmp/config.h" \
-      || as_fn_error $? "could not create $ac_file" "$LINENO" 5
-    if diff "$ac_file" "$ac_tmp/config.h" >/dev/null 2>&1; then
-      { $as_echo "$as_me:${as_lineno-$LINENO}: $ac_file is unchanged" >&5
+      && eval '$AWK -f "$tmp/defines.awk"' "$ac_file_inputs"
+    } >"$tmp/config.h" \
+      || { { $as_echo "$as_me:$LINENO: error: could not create $ac_file" >&5
+$as_echo "$as_me: error: could not create $ac_file" >&2;}
+   { (exit 1); exit 1; }; }
+    if diff "$ac_file" "$tmp/config.h" >/dev/null 2>&1; then
+      { $as_echo "$as_me:$LINENO: $ac_file is unchanged" >&5
 $as_echo "$as_me: $ac_file is unchanged" >&6;}
     else
       rm -f "$ac_file"
-      mv "$ac_tmp/config.h" "$ac_file" \
-	|| as_fn_error $? "could not create $ac_file" "$LINENO" 5
+      mv "$tmp/config.h" "$ac_file" \
+	|| { { $as_echo "$as_me:$LINENO: error: could not create $ac_file" >&5
+$as_echo "$as_me: error: could not create $ac_file" >&2;}
+   { (exit 1); exit 1; }; }
     fi
   else
     $as_echo "/* $configure_input  */" \
-      && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs" \
-      || as_fn_error $? "could not create -" "$LINENO" 5
+      && eval '$AWK -f "$tmp/defines.awk"' "$ac_file_inputs" \
+      || { { $as_echo "$as_me:$LINENO: error: could not create -" >&5
+$as_echo "$as_me: error: could not create -" >&2;}
+   { (exit 1); exit 1; }; }
   fi
  ;;
 
@@ -8207,12 +9602,15 @@
 done # for ac_tag
 
 
-as_fn_exit 0
+{ (exit 0); exit 0; }
 _ACEOF
+chmod +x $CONFIG_STATUS
 ac_clean_files=$ac_clean_files_save
 
 test $ac_write_fail = 0 ||
-  as_fn_error $? "write failure creating $CONFIG_STATUS" "$LINENO" 5
+  { { $as_echo "$as_me:$LINENO: error: write failure creating $CONFIG_STATUS" >&5
+$as_echo "$as_me: error: write failure creating $CONFIG_STATUS" >&2;}
+   { (exit 1); exit 1; }; }
 
 
 # configure is writing to config.log, and then calls config.status.
@@ -8233,10 +9631,10 @@
   exec 5>>config.log
   # Use ||, not &&, to avoid exiting from the if with $? = 1, which
   # would make configure fail if this is the last instruction.
-  $ac_cs_success || as_fn_exit 1
+  $ac_cs_success || { (exit 1); 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:$LINENO: WARNING: unrecognized options: $ac_unrecognized_opts" >&5
 $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;}
 fi
 
@@ -8244,3 +9642,4 @@
 #daniel: adding custom lines to config.h.in through autoheader
 
 
+

Modified: seismo/3D/SPECFEM3D/trunk/configure.ac
===================================================================
--- seismo/3D/SPECFEM3D/trunk/configure.ac	2013-09-17 22:36:21 UTC (rev 22797)
+++ seismo/3D/SPECFEM3D/trunk/configure.ac	2013-09-18 14:35:14 UTC (rev 22798)
@@ -55,6 +55,13 @@
 AM_CONDITIONAL([COND_CUDA], [test "$want_cuda" != no])
 AM_CONDITIONAL([COND_CUDA5], [test "$want_cuda" = cuda5])
 
+AC_ARG_WITH([adios],
+    [AC_HELP_STRING([--with-adios],
+        [build ADIOS enabled version @<:@default=no@:>@])],
+    [want_adios="$withval"],
+    [want_adios=no])
+AM_CONDITIONAL([COND_ADIOS], [test "$want_adios" != no])
+
 AC_ARG_WITH([openmp],
     [AS_HELP_STRING([--with-openmp],
         [build OpenMP enabled version @<:@default=no@:>@])],
@@ -350,6 +357,11 @@
 
 # influential environment variables
 
+AC_ARG_VAR(ADIOS_INC, [Directory where ADIOS headers are installed])
+AC_ARG_VAR(ADIOS_LIB, [Directory where ADIOS libraries are installed])
+AC_ARG_VAR(MXML_INC, [Directory where MXML headers are installed])
+AC_ARG_VAR(MXML_LIB, [Directory where MXML libraries are installed])
+
 AC_ARG_VAR(USE_BUNDLED_SCOTCH, [Set to 1 to always use the bundled Scotch library])
 AC_ARG_VAR(SCOTCH_DIR, [Directory where Scotch is installed])
 AC_ARG_VAR(SCOTCH_INCLUDEDIR, [Directory where Scotch headers are installed])
@@ -440,6 +452,12 @@
     CIT_FC_MAIN
 fi
 
+if test "$want_adios" = yes; then
+  CIT_MXML_HEADER
+  CIT_MXML_LIB
+  CIT_ADIOS_LIB
+fi	
+
 if test "$want_cuda" = yes; then
     CIT_CUDA_COMPILER
 fi
@@ -448,6 +466,10 @@
     CIT_FC_OPENMP_MODULE([$FC],[$FLAGS_CHECK])        
 fi
 
+#mpbl: adding flags to config.h.in through autoheader in order to save them into the adios file.
+configure_flags_str="FC=$FC FCFLAGS=$FLAGS_NO_CHECK" 
+AC_DEFINE_UNQUOTED([CONFIGURE_FLAGS],["${configure_flags_str}"],
+          [configuration flags to be save in the adios output file.])
 
 # Checks for library functions.
 

Modified: seismo/3D/SPECFEM3D/trunk/src/generate_databases/Makefile.in
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/generate_databases/Makefile.in	2013-09-17 22:36:21 UTC (rev 22797)
+++ seismo/3D/SPECFEM3D/trunk/src/generate_databases/Makefile.in	2013-09-18 14:35:14 UTC (rev 22798)
@@ -47,8 +47,17 @@
 # Output files directory
 OUTPUT=../../OUTPUT_FILES
 
-FCCOMPILE_CHECK =@FCENV@ ${FC} ${FCFLAGS} $(FLAGS_CHECK) -I${SHARED}
-MPIFCCOMPILE_CHECK =@FCENV@ ${MPIFC} ${FCFLAGS} $(FLAGS_CHECK) -I${SHARED}
+# ADIOS
+# with configure: ./configure --with-adios ADIOS_LIB=.. ADIOS_INC=.. MPI_INC=..
+ at COND_ADIOS_TRUE@ADIOS_LIBS = -ladiosf -lmxml
+ at COND_ADIOS_FALSE@ADIOS_LIBS = 
+
+ADIOS_LIB_LOCATION = @ADIOS_LIB@ @MXML_LIB@
+ADIOS_LINK = $(ADIOS_LIB_LOCATION) $(ADIOS_LIBS)
+ADIOS_INC = @ADIOS_INC@ -I../../setup -I../../ 
+
+FCCOMPILE_CHECK =@FCENV@ ${FC} ${FCFLAGS} $(FLAGS_CHECK) -I${SHARED} ${ADIOS_LINK}
+MPIFCCOMPILE_CHECK =@FCENV@ ${MPIFC} ${FCFLAGS} $(FLAGS_CHECK) -I${SHARED} ${ADIOS_LINK}
 @COND_MPI_TRUE at FCLINK = $(MPIFCCOMPILE_CHECK)
 @COND_MPI_FALSE at FCLINK = $(FCCOMPILE_CHECK)
 
@@ -124,6 +133,26 @@
 	$O/memory_eval.o \
 	$(EMPTY_MACRO)
 
+# using ADIOS files
+ADIOS_PREOBJECTS= \
+	$O/adios_manager.shared_adios.o  \
+	$O/adios_helpers_definitions.shared_adios.o  \
+	$O/adios_helpers_writers.shared_adios.o  \
+	$O/adios_helpers.shared_adios.o
+ADIOS_OBJECTS= \
+	$O/read_partition_files_adios.adios.o \
+	$O/save_arrays_solver_adios.adios.o \
+	$O/save_moho_adios.adios.o \
+	$O/model_gll_adios.adios.o \
+	$O/model_ipati_adios.adios.o
+
+ADIOS_STUBS = \
+	$O/adios_manager_stubs.shared_noadios.o \
+	$O/generate_databases_adios_stubs.noadios.o
+
+ at COND_ADIOS_FALSE@ADIOS_OBJECTS = $(ADIOS_STUBS)
+ at COND_ADIOS_FALSE@ADIOS_PREOBJECTS =
+
 KEEP_MAIN_PROGRAM_SEPARATE = $O/program_generate_databases.o
 
 # objects toggled between the parallel and serial version
@@ -133,7 +162,8 @@
 LIBGENDATABASES = $L/libgendatabases.a
 
 # objects for the pure Fortran version
- at COND_PYRE_FALSE@XGENERATE_DATABASES_OBJECTS = $(LIBGENDATABASES)
+ at COND_PYRE_FALSE@XGENERATE_DATABASES_OBJECTS = $(ADIOS_PREOBJECTS) \
+	$(LIBGENDATABASES) $(ADIOS_OBJECTS)
 
 ####
 #### targets
@@ -167,7 +197,7 @@
 
 # rules for the pure Fortran version
 @COND_PYRE_FALSE at xgenerate_databases: $(XGENERATE_DATABASES_OBJECTS) $(COND_MPI_OBJECTS) $(KEEP_MAIN_PROGRAM_SEPARATE)
- at COND_PYRE_FALSE@	${FCLINK} -o ${E}/xgenerate_databases $(KEEP_MAIN_PROGRAM_SEPARATE) $(COND_MPI_OBJECTS) $(XGENERATE_DATABASES_OBJECTS) $(MPILIBS)
+ at COND_PYRE_FALSE@	${FCLINK} -o ${E}/xgenerate_databases $(KEEP_MAIN_PROGRAM_SEPARATE) $(COND_MPI_OBJECTS) $(XGENERATE_DATABASES_OBJECTS) $(MPILIBS) $(ADIOS_LINK)
 @COND_PYRE_FALSE@
 @COND_PYRE_FALSE@# solver also depends on values from mesher
 
@@ -190,15 +220,45 @@
 ####
 #### rule to build each .o file below
 ####
+#######################################
 
 ###
+### ADIOS compilation
+###
+
+$O/%.adios.o: %.F90 ${SHARED}constants.h
+	${MPIFCCOMPILE_CHECK} -c $(ADIOS_INC) $(FCFLAGS) $(MPI_INC) -o $@ $<
+
+$O/%.adios.o: %.f90 ${SHARED}constants.h
+	${MPIFCCOMPILE_CHECK} -c $(ADIOS_INC) $(FCFLAGS) $(MPI_INC) -o $@ $<
+
+$O/%.noadios.o: %.F90 
+	${FC} -c -o $@ $<
+
+$O/%.noadios.o: %.f90 
+	${FC} -c -o $@ $<
+
+$O/%.shared_noadios.o: ${SHARED}/%.f90 .FORCE
+	${MPIFC} -c -o $@ $<
+
+$O/%.shared_adios.o: ${SHARED}/%.f90 ${SHARED}/constants.h .FORCE
+	${MPIFC} -c $(ADIOS_INC) $(FCFLAGS) $(MPI_INC) -o $@ $<
+
+$O/%.shared_adios.o: ${SHARED}/%.F90 ${SHARED}/constants.h .FORCE
+	${MPIFC} -c $(ADIOS_INC) $(FCFLAGS) $(MPI_INC) -o $@ $<
+
+.FORCE:
+
+#######################################
+
+###
 ### not optimized flags (not dependent on values from mesher anymore)
 ###
 
 $O/%.o: %.f90 $(SHARED)constants.h
-	${FCCOMPILE_CHECK} -c -o $@ $<
+	${MPIFCCOMPILE_CHECK} -c -o $@ $<
 
-$O/%.shared.o: $(SHARED)%.f90 $(SHARED)constants.h
+$O/%.shared.o: $(SHARED)%.f90 $(SHARED)constants.h .FORCE
 	${FCCOMPILE_CHECK} -c -o $@ $<
 
 ###

Modified: seismo/3D/SPECFEM3D/trunk/src/generate_databases/create_regions_mesh.f90
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/generate_databases/create_regions_mesh.f90	2013-09-17 22:36:21 UTC (rev 22797)
+++ seismo/3D/SPECFEM3D/trunk/src/generate_databases/create_regions_mesh.f90	2013-09-18 14:35:14 UTC (rev 22798)
@@ -28,25 +28,27 @@
   subroutine create_regions_mesh()
 
 ! create the different regions of the mesh
-  use generate_databases_par, only: &
-    nspec => NSPEC_AB,nglob => NGLOB_AB, &
-    ibool,xstore,ystore,zstore, &
-    npointot,myrank,LOCAL_PATH, &
-    nnodes_ext_mesh,nelmnts_ext_mesh, &
-    nodes_coords_ext_mesh, elmnts_ext_mesh, &
-    max_memory_size,num_interfaces_ext_mesh, max_interface_size_ext_mesh, &
-    my_neighbours_ext_mesh, my_nelmnts_neighbours_ext_mesh, &
-    my_interfaces_ext_mesh, &
-    ibool_interfaces_ext_mesh, nibool_interfaces_ext_mesh, &
-    STACEY_ABSORBING_CONDITIONS, nspec2D_xmin, nspec2D_xmax, nspec2D_ymin, nspec2D_ymax, &
-    NSPEC2D_BOTTOM, NSPEC2D_TOP,&
-    ibelm_xmin, ibelm_xmax, ibelm_ymin, ibelm_ymax, ibelm_bottom, ibelm_top, &
-    nodes_ibelm_xmin,nodes_ibelm_xmax,nodes_ibelm_ymin,nodes_ibelm_ymax,&
-    nodes_ibelm_bottom,nodes_ibelm_top, &
-    SAVE_MESH_FILES,PML_CONDITIONS,FULL_ATTENUATION_SOLID, &
-    ANISOTROPY,NPROC,APPROXIMATE_OCEAN_LOAD,OLSEN_ATTENUATION_RATIO, &
-    ATTENUATION,USE_OLSEN_ATTENUATION, &
-    nspec2D_moho_ext,ibelm_moho,nodes_ibelm_moho
+  use generate_databases_par, only:                                            & 
+      nspec => NSPEC_AB,nglob => NGLOB_AB,                                     & 
+      ibool,xstore,ystore,zstore,                                              & 
+      npointot,myrank,LOCAL_PATH,                                              & 
+      nnodes_ext_mesh,nelmnts_ext_mesh,                                        & 
+      nodes_coords_ext_mesh, elmnts_ext_mesh,                                  & 
+      max_memory_size,num_interfaces_ext_mesh, max_interface_size_ext_mesh,    & 
+      my_neighbours_ext_mesh, my_nelmnts_neighbours_ext_mesh,                  & 
+      my_interfaces_ext_mesh,                                                  & 
+      ibool_interfaces_ext_mesh, nibool_interfaces_ext_mesh,                   & 
+      STACEY_ABSORBING_CONDITIONS, nspec2D_xmin, nspec2D_xmax,                 & 
+      nspec2D_ymin, nspec2D_ymax,                                              & 
+      NSPEC2D_BOTTOM, NSPEC2D_TOP,                                             & 
+      ibelm_xmin, ibelm_xmax, ibelm_ymin, ibelm_ymax, ibelm_bottom, ibelm_top, & 
+      nodes_ibelm_xmin,nodes_ibelm_xmax,nodes_ibelm_ymin,nodes_ibelm_ymax,     & 
+      nodes_ibelm_bottom,nodes_ibelm_top,                                      & 
+      SAVE_MESH_FILES,PML_CONDITIONS,FULL_ATTENUATION_SOLID,                   & 
+      ANISOTROPY,NPROC,APPROXIMATE_OCEAN_LOAD,OLSEN_ATTENUATION_RATIO,         & 
+      ATTENUATION,USE_OLSEN_ATTENUATION,                                       & 
+      nspec2D_moho_ext,ibelm_moho,nodes_ibelm_moho,                            & 
+      ADIOS_FOR_MESH
 
   use create_regions_mesh_ext_par
   use fault_generate_databases, only: fault_read_input,fault_setup, &
@@ -250,10 +252,21 @@
     call flush_IMAIN()
   endif
   !call create_name_database(prname,myrank,LOCAL_PATH)
+  if (ADIOS_FOR_MESH) then
+    call save_arrays_solver_ext_mesh_adios(nspec, nglob,                   &
+                                           APPROXIMATE_OCEAN_LOAD,         &
+                                           ibool, num_interfaces_ext_mesh, &
+                                           my_neighbours_ext_mesh,         &
+                                           nibool_interfaces_ext_mesh,     &
+                                           max_interface_size_ext_mesh,    &
+                                           ibool_interfaces_ext_mesh,      &
+                                           SAVE_MESH_FILES,ANISOTROPY)
+  else
   call save_arrays_solver_ext_mesh(nspec,nglob_dummy,APPROXIMATE_OCEAN_LOAD,ibool, &
                         num_interfaces_ext_mesh,my_neighbours_ext_mesh,nibool_interfaces_ext_mesh, &
                         max_interface_size_ext_mesh,ibool_interfaces_ext_mesh, &
                         SAVE_MESH_FILES,ANISOTROPY)
+  endif
 
 ! saves faults
   if( ANY_FAULT ) then
@@ -1026,33 +1039,38 @@
 
   subroutine crm_save_moho()
 
+  use generate_databases_par, only: ADIOS_FOR_MESH
   use create_regions_mesh_ext_par
   implicit none
   ! local parameters
   integer :: ier
 
-  ! saves moho files: total number of elements, corner points, all points
-  open(unit=27,file=prname(1:len_trim(prname))//'ibelm_moho.bin', &
-        status='unknown',form='unformatted',iostat=ier)
-  if( ier /= 0 ) stop 'error opening ibelm_moho.bin file'
-  write(27) NSPEC2D_MOHO
-  write(27) ibelm_moho_top
-  write(27) ibelm_moho_bot
-  write(27) ijk_moho_top
-  write(27) ijk_moho_bot
-  close(27)
-  open(unit=27,file=prname(1:len_trim(prname))//'normal_moho.bin', &
-        status='unknown',form='unformatted',iostat=ier)
-  if( ier /= 0 ) stop 'error opening normal_moho.bin file'
-  write(27) normal_moho_top
-  write(27) normal_moho_bot
-  close(27)
-  open(unit=27,file=prname(1:len_trim(prname))//'is_moho.bin', &
-    status='unknown',form='unformatted',iostat=ier)
-  if( ier /= 0 ) stop 'error opening is_moho.bin file'
-  write(27) is_moho_top
-  write(27) is_moho_bot
-  close(27)
+  if (ADIOS_FOR_MESH) then
+    call crm_save_moho_adios()
+  else
+    ! saves moho files: total number of elements, corner points, all points
+    open(unit=27,file=prname(1:len_trim(prname))//'ibelm_moho.bin', &
+          status='unknown',form='unformatted',iostat=ier)
+    if( ier /= 0 ) stop 'error opening ibelm_moho.bin file'
+    write(27) NSPEC2D_MOHO
+    write(27) ibelm_moho_top
+    write(27) ibelm_moho_bot
+    write(27) ijk_moho_top
+    write(27) ijk_moho_bot
+    close(27)
+    open(unit=27,file=prname(1:len_trim(prname))//'normal_moho.bin', &
+          status='unknown',form='unformatted',iostat=ier)
+    if( ier /= 0 ) stop 'error opening normal_moho.bin file'
+    write(27) normal_moho_top
+    write(27) normal_moho_bot
+    close(27)
+    open(unit=27,file=prname(1:len_trim(prname))//'is_moho.bin', &
+      status='unknown',form='unformatted',iostat=ier)
+    if( ier /= 0 ) stop 'error opening is_moho.bin file'
+    write(27) is_moho_top
+    write(27) is_moho_bot
+    close(27)
+  endif
 
   end subroutine crm_save_moho
 

Modified: seismo/3D/SPECFEM3D/trunk/src/generate_databases/generate_databases.f90
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/generate_databases/generate_databases.f90	2013-09-17 22:36:21 UTC (rev 22797)
+++ seismo/3D/SPECFEM3D/trunk/src/generate_databases/generate_databases.f90	2013-09-18 14:35:14 UTC (rev 22798)
@@ -188,6 +188,8 @@
 
   subroutine generate_databases
 
+  use adios_manager_mod
+  use mpi
   use generate_databases_par
 
   implicit none
@@ -233,8 +235,17 @@
     call flush_IMAIN()
   endif
 
+  ! Initialize ADIOS I/O
+  if (ADIOS_ENABLED) then
+    call adios_setup()
+  endif
+
 ! reads Databases files
-  call read_partition_files()
+  if (ADIOS_FOR_DATABASES) then
+    call read_partition_files_adios()
+  else
+    call read_partition_files()
+  endif
 
 ! external mesh creation
   call setup_mesh()
@@ -242,6 +253,9 @@
 ! finalize mesher
   call finalize_databases()
 
+  if (ADIOS_ENABLED) then
+    call adios_cleanup()
+  endif
   end subroutine generate_databases
 
 !
@@ -269,6 +283,9 @@
                         USE_RICKER_TIME_FUNCTION,OLSEN_ATTENUATION_RATIO,PML_CONDITIONS, &
                         PML_INSTEAD_OF_FREE_SURFACE,f0_FOR_PML,IMODEL,FULL_ATTENUATION_SOLID,TRAC_PATH)
 
+  call read_adios_parameters(ADIOS_ENABLED, ADIOS_FOR_DATABASES, &
+                             ADIOS_FOR_MESH, ADIOS_FOR_KERNELS)
+
 ! check that the code is running with the requested nb of processes
   if(sizeprocs /= NPROC) then
     if( myrank == 0 ) then

Added: seismo/3D/SPECFEM3D/trunk/src/generate_databases/generate_databases_adios_stubs.f90
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/generate_databases/generate_databases_adios_stubs.f90	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/src/generate_databases/generate_databases_adios_stubs.f90	2013-09-18 14:35:14 UTC (rev 22798)
@@ -0,0 +1,77 @@
+
+!==============================================================================
+!> \file generate_databases_adios_stubs.f90
+!!
+!!  Stubs for ADIOS functions. Avoid link error when not configured with
+!!  ADIOS.
+!!      
+!! \author MPBL
+!==============================================================================
+
+!--------------------------------------.
+! Subroutines from model_gll_adios.F90 |
+!--------------------------------------'
+
+subroutine model_gll_adios()
+  use adios_manager_mod
+
+  call no_adios_err()  
+end subroutine 
+
+!----------------------------------------.
+! Subroutines from model_ipati_adios.F90 |
+!----------------------------------------'
+
+subroutine model_ipati_adios()
+  use adios_manager_mod
+
+  call no_adios_err()  
+end subroutine model_ipati_adios 
+
+subroutine model_ipati_water_adios()
+  use adios_manager_mod
+
+  call no_adios_err()  
+end subroutine model_ipati_water_adios
+
+subroutine read_model_vp_rho_adios()
+  use adios_manager_mod
+
+  call no_adios_err()  
+end subroutine read_model_vp_rho_adios
+
+!-------------------------------------------------.
+! Subroutines from read_partition_files_adios.F90 |
+!-------------------------------------------------'
+
+subroutine read_partition_files_adios()
+  use adios_manager_mod
+
+  call no_adios_err()  
+end subroutine read_partition_files_adios
+
+!-----------------------------------------------.
+! Subroutines from save_arrays_solver_adios.F90 |
+!-----------------------------------------------'
+
+subroutine save_arrays_solver_ext_mesh_adios()
+  use adios_manager_mod
+
+  call no_adios_err()  
+end subroutine 
+
+subroutine save_arrays_solver_files_adios()
+  use adios_manager_mod
+
+  call no_adios_err()  
+end subroutine save_arrays_solver_files_adios
+
+!--------------------------------------.
+! Subroutines from save_moho_adios.F90 |
+!--------------------------------------'
+
+subroutine crm_save_moho_adios()
+  use adios_manager_mod
+
+  call no_adios_err()  
+end subroutine crm_save_moho_adios

Modified: seismo/3D/SPECFEM3D/trunk/src/generate_databases/generate_databases_par.f90
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/generate_databases/generate_databases_par.f90	2013-09-17 22:36:21 UTC (rev 22797)
+++ seismo/3D/SPECFEM3D/trunk/src/generate_databases/generate_databases_par.f90	2013-09-18 14:35:14 UTC (rev 22798)
@@ -69,6 +69,9 @@
 
   character(len=256) OUTPUT_FILES,LOCAL_PATH,TOMOGRAPHY_PATH,TRAC_PATH
 
+  logical :: ADIOS_ENABLED
+  logical :: ADIOS_FOR_DATABASES, ADIOS_FOR_MESH, ADIOS_FOR_KERNELS
+
 ! parameters deduced from parameters read from file
   integer :: NPROC
 

Modified: seismo/3D/SPECFEM3D/trunk/src/generate_databases/get_model.f90
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/generate_databases/get_model.f90	2013-09-17 22:36:21 UTC (rev 22797)
+++ seismo/3D/SPECFEM3D/trunk/src/generate_databases/get_model.f90	2013-09-18 14:35:14 UTC (rev 22798)
@@ -476,7 +476,7 @@
 
 ! reads in material parameters from external binary files
 
-  use generate_databases_par,only: IMODEL
+  use generate_databases_par,only: IMODEL, ADIOS_FOR_MESH
 
   use create_regions_mesh_ext_par
 
@@ -498,15 +498,27 @@
     ! note:
     ! import the model from files in SPECFEM format
     ! note that those those files should be saved in LOCAL_PATH
-    call model_gll(myrank,nspec,LOCAL_PATH)
+    if (ADIOS_FOR_MESH) then
+      call model_gll_adios(myrank,nspec,LOCAL_PATH)
+    else
+      call model_gll(myrank,nspec,LOCAL_PATH)
+    endif
 
   case( IMODEL_IPATI )
     ! import the model from modified files in SPECFEM format
-    call model_ipati(myrank,nspec,LOCAL_PATH)
+    if (ADIOS_FOR_MESH) then
+      call model_ipati_adios(myrank,nspec,LOCAL_PATH)
+    else
+      call model_ipati(myrank,nspec,LOCAL_PATH)
+    endif
 
   case( IMODEL_IPATI_WATER )
     ! import the model from modified files in SPECFEM format
-    call model_ipati_water(myrank,nspec,LOCAL_PATH)
+    if (ADIOS_FOR_MESH) then
+      call model_ipati_water_adios(myrank,nspec,LOCAL_PATH)
+    else
+      call model_ipati_water(myrank,nspec,LOCAL_PATH)
+    endif
 
   end select
 

Added: seismo/3D/SPECFEM3D/trunk/src/generate_databases/model_gll_adios.F90
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/generate_databases/model_gll_adios.F90	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/src/generate_databases/model_gll_adios.F90	2013-09-18 14:35:14 UTC (rev 22798)
@@ -0,0 +1,135 @@
+!=====================================================================
+!
+!               S p e c f e m 3 D  V e r s i o n  2 . 1
+!               ---------------------------------------
+!
+!          Main authors: Dimitri Komatitsch and Jeroen Tromp
+!    Princeton University, USA and CNRS / INRIA / University of Pau
+! (c) Princeton University / California Institute of Technology and CNRS / INRIA / University of Pau
+!                             July 2012
+!
+! This 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 02110-1301 USA.
+!
+!=====================================================================
+
+
+!==============================================================================
+!> Read rho, vp, vs from model_values.bp
+!
+! based on modified GLL mesh output from mesher 
+! used for iterative inversion procedures
+!
+! \param myrank rank of the mpi process
+! \param nspec  number of spectral elements in the model
+! \param LOCAL_PATH path where the '.bp' file is located
+subroutine model_gll_adios(myrank,nspec,LOCAL_PATH)
+
+  use mpi
+  use adios_read_mod
+  use create_regions_mesh_ext_par
+  use generate_databases_par, only: sizeprocs
+
+  implicit none
+
+  integer, intent(in) :: myrank,nspec
+  character(len=256) :: LOCAL_PATH
+
+  ! local parameters
+  real, dimension(:,:,:,:),allocatable :: vp_read,vs_read,rho_read
+  integer :: ier
+
+  ! ADIOS stuffs
+  character(len=256) :: database_name
+  integer(kind=8) :: handle, sel
+  integer(kind=8), dimension(1) :: start, count_ad
+  integer :: local_dim_rho, local_dim_vp, local_dim_vs
+
+  ! density
+  allocate( rho_read(NGLLX,NGLLY,NGLLZ,nspec),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array rho_read'
+  ! vp
+  allocate( vp_read(NGLLX,NGLLY,NGLLZ,nspec),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array vp_read'
+  ! vs
+  allocate( vs_read(NGLLX,NGLLY,NGLLZ,nspec),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array vs_read'
+
+  !-------------------------------------.
+  ! Open ADIOS Database file, read mode |
+  !-------------------------------------'
+  database_name = adjustl(LOCAL_PATH)
+  database_name = database_name(1:len_trim(database_name)) //"/model_values.bp"
+
+  call adios_read_init_method (ADIOS_READ_METHOD_BP, MPI_COMM_WORLD, &
+                               "verbose=1", ier)
+  call adios_read_open_file (handle, database_name, 0, MPI_COMM_WORLD, ier)
+
+  !------------------------.
+  ! Get the 'chunks' sizes |
+  !------------------------'
+  call adios_get_scalar(handle, "rho/local_dim", local_dim_rho, ier)
+  call adios_get_scalar(handle, "vp/local_dim", local_dim_vp, ier)
+  call adios_get_scalar(handle, "vs/local_dim", local_dim_vs, ier)
+  
+  start(1) = local_dim_rho * myrank
+  count_ad(1) = NGLLX * NGLLY * NGLLZ * nspec
+  call adios_selection_boundingbox(sel, 1, start, count_ad)
+  call adios_schedule_read(handle, sel, "rho/array", 0, 1, &
+                           rho_read, ier)
+  call adios_schedule_read(handle, sel, "vp/array", 0, 1, &
+                           vp_read, ier)
+  call adios_schedule_read(handle, sel, "vp/array", 0, 1, &
+                           vp_read, ier)
+
+  !---------------------------------------.
+  ! Perform read and close the adios file |
+  !---------------------------------------'
+  call adios_perform_reads(handle, ier)
+  call adios_read_close(handle,ier)
+  call adios_read_finalize_method(ADIOS_READ_METHOD_BP, ier)
+
+  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+  !!! in cases where density structure is not given
+  !!! modify according to your desire
+
+  !  rho_read = 1000.0
+  !  where ( mustore > 100.0 )  &
+  !           rho_read = (1.6612 * (vp_read / 1000.0)     &
+  !                      -0.4720 * (vp_read / 1000.0)**2  &
+  !                      +0.0671 * (vp_read / 1000.0)**3  &
+  !                      -0.0043 * (vp_read / 1000.0)**4  &
+  !                      +0.000106*(vp_read / 1000.0)**5 )*1000.0
+
+  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+  !!! in cases where shear wavespeed structure is not given
+  !!! modify according to your desire
+
+  !   vs_read = 0.0
+  !   where ( mustore > 100.0 )       vs_read = vp_read / sqrt(3.0)
+
+  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+  !!! update arrays that will be saved and used in the solver xspecfem3D
+  !!! the following part is neccessary if you uncommented something above
+
+  rhostore    = rho_read
+  kappastore  = rhostore * ( vp_read * vp_read - FOUR_THIRDS * vs_read * vs_read )
+  mustore     = rhostore * vs_read * vs_read
+  rho_vp = rhostore * vp_read
+  rho_vs = rhostore * vs_read
+
+  ! free memory
+  deallocate( rho_read,vp_read,vs_read)
+
+  end subroutine model_gll_adios

Added: seismo/3D/SPECFEM3D/trunk/src/generate_databases/model_ipati_adios.F90
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/generate_databases/model_ipati_adios.F90	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/src/generate_databases/model_ipati_adios.F90	2013-09-18 14:35:14 UTC (rev 22798)
@@ -0,0 +1,213 @@
+!=====================================================================
+!
+!               S p e c f e m 3 D  V e r s i o n  2 . 1
+!               ---------------------------------------
+!
+!          Main authors: Dimitri Komatitsch and Jeroen Tromp
+!    Princeton University, USA and CNRS / INRIA / University of Pau
+! (c) Princeton University / California Institute of Technology and CNRS / INRIA / University of Pau
+!                             July 2012
+!
+! This 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 02110-1301 USA.
+!
+!=====================================================================
+
+
+!-----------------------------------------------------------------------------
+!
+! IPATI
+!
+! based on given rho and vp structure for GLL files
+!
+!------------------------------------------------------------------------------
+subroutine model_ipati_adios(myrank,nspec,LOCAL_PATH)
+
+  use mpi
+  use adios_read_mod
+  use create_regions_mesh_ext_par
+  use generate_databases_par, only: sizeprocs
+
+  implicit none
+
+  integer, intent(in) :: myrank,nspec
+  character(len=256) :: LOCAL_PATH
+
+  ! local parameters
+  real, dimension(:,:,:,:),allocatable :: vp_read,vs_read,rho_read
+  integer :: ier
+
+  ! ---------------------------------------------------------------------------
+  ! note: vp not vs structure is available 
+  ! (as is often the case in exploration seismology),
+  ! scaling factor
+  real, parameter :: SCALING_FACTOR = 1.0/1.8
+  ! ---------------------------------------------------------------------------
+
+  ! user output
+  if (myrank==0) then
+    write(IMAIN,*)
+    write(IMAIN,*) 'using external IPATI model from:',trim(LOCAL_PATH)
+    write(IMAIN,*) 'scaling factor: ',SCALING_FACTOR
+    write(IMAIN,*)
+  endif
+
+  ! density
+  allocate( rho_read(NGLLX,NGLLY,NGLLZ,nspec),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array rho_read'
+  ! vp
+  allocate( vp_read(NGLLX,NGLLY,NGLLZ,nspec),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array vp_read'
+  ! vs scaled from vp
+  allocate( vs_read(NGLLX,NGLLY,NGLLZ,nspec),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array vs_read'
+
+  call read_model_vp_rho_adios(myrank, nspec, LOCAL_PATH, &
+                               rho_read, vp_read)
+
+  ! scaling
+  vs_read = vp_read * SCALING_FACTOR
+
+  ! isotropic model parameters
+  rhostore    = rho_read
+  kappastore  = rhostore * ( vp_read * vp_read - FOUR_THIRDS * vs_read * vs_read )
+  mustore     = rhostore * vs_read * vs_read
+  rho_vp = rhostore * vp_read
+  rho_vs = rhostore * vs_read
+
+  ! free memory
+  deallocate( rho_read,vp_read,vs_read)
+
+end subroutine model_ipati_adios
+
+!
+!-------------------------------------------------------------------------------------------------
+!
+
+subroutine model_ipati_water_adios(myrank,nspec,LOCAL_PATH)
+
+  use create_regions_mesh_ext_par
+  implicit none
+
+  integer, intent(in) :: myrank,nspec
+  character(len=256) :: LOCAL_PATH
+
+  ! local parameters
+  real, dimension(:,:,:,:),allocatable :: vp_read,vs_read,rho_read
+  integer :: ispec,ier
+
+  ! -----------------------------------------------------------------------------
+
+  ! note: vp not vs structure is available (as is often the case in exploration seismology),
+  ! scaling factor
+  real, parameter :: SCALING_FACTOR = 1.0/1.8
+
+  ! -----------------------------------------------------------------------------
+
+  ! user output
+  if (myrank==0) then
+    write(IMAIN,*)
+    write(IMAIN,*) 'using external IPATI_WATER model from:',trim(LOCAL_PATH)
+    write(IMAIN,*) 'scaling factor: ',SCALING_FACTOR
+    write(IMAIN,*)
+  endif
+
+  ! density
+  allocate( rho_read(NGLLX,NGLLY,NGLLZ,nspec),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array rho_read'
+  ! vp
+  allocate( vp_read(NGLLX,NGLLY,NGLLZ,nspec),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array vp_read'
+  ! vs scaled from vp
+  allocate( vs_read(NGLLX,NGLLY,NGLLZ,nspec),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array vs_read'
+
+  call read_model_vp_rho_adios(myrank, nspec, LOCAL_PATH, &
+                               rho_read, vp_read)
+
+  ! scaling
+  vs_read = vp_read * SCALING_FACTOR
+
+  ! overwrites only elastic elements
+  do ispec=1,nspec
+    ! assumes water layer with acoustic elements are set properly
+    ! only overwrites elastic elements
+    if( ispec_is_elastic(ispec)) then
+      ! isotropic model parameters
+      rhostore(:,:,:,ispec) = rho_read(:,:,:,ispec)
+      kappastore(:,:,:,ispec) = rhostore(:,:,:,ispec) * ( vp_read(:,:,:,ispec) * vp_read(:,:,:,ispec) &
+                                    - FOUR_THIRDS * vs_read(:,:,:,ispec) * vs_read(:,:,:,ispec) )
+      mustore(:,:,:,ispec) = rhostore(:,:,:,ispec) * vs_read(:,:,:,ispec) * vs_read(:,:,:,ispec)
+      rho_vp(:,:,:,ispec) = rhostore(:,:,:,ispec) * vp_read(:,:,:,ispec)
+      rho_vs(:,:,:,ispec) = rhostore(:,:,:,ispec) * vs_read(:,:,:,ispec)
+    endif
+  enddo
+
+  ! free memory
+  deallocate( rho_read,vp_read,vs_read)
+
+end subroutine model_ipati_water_adios
+
+subroutine read_model_vp_rho_adios (myrank, nspec, LOCAL_PATH, &
+                                    rho_read, vp_read)
+
+  use mpi
+  use adios_read_mod
+  use create_regions_mesh_ext_par
+  use generate_databases_par, only: sizeprocs
+
+  implicit none
+
+  integer, intent(in) :: myrank,nspec
+  character(len=256), intent(in) :: LOCAL_PATH
+  real, dimension(:,:,:,:), intent(inout) :: vp_read,rho_read
+
+  ! ADIOS stuffs
+  character(len=256) :: database_name
+  integer(kind=8) :: handle, sel
+  integer(kind=8), dimension(1) :: start, count_ad
+  integer :: local_dim_rho, local_dim_vp
+  integer :: ier
+
+  !-------------------------------------.
+  ! Open ADIOS Database file, read mode |
+  !-------------------------------------'
+  database_name = adjustl(LOCAL_PATH)
+  database_name = database_name(1:len_trim(database_name)) //"/model_values.bp"
+
+  call adios_read_init_method (ADIOS_READ_METHOD_BP, MPI_COMM_WORLD, &
+                               "verbose=1", ier)
+  call adios_read_open_file (handle, database_name, 0, MPI_COMM_WORLD, ier)
+
+  !------------------------.
+  ! Get the 'chunks' sizes |
+  !------------------------'
+  call adios_get_scalar(handle, "rho/local_dim", local_dim_rho, ier)
+  call adios_get_scalar(handle, "vp/local_dim", local_dim_vp, ier)
+  
+  start(1) = local_dim_rho * myrank
+  count_ad(1) = NGLLX * NGLLY * NGLLZ * nspec
+  call adios_selection_boundingbox(sel, 1, start, count_ad)
+  call adios_schedule_read(handle, sel, "rho/array", 0, 1, &
+                           rho_read, ier)
+  call adios_schedule_read(handle, sel, "vp/array", 0, 1, &
+                           vp_read, ier)
+
+  !---------------------------------------.
+  ! Perform read and close the adios file |
+  !---------------------------------------'
+  call adios_perform_reads(handle, ier)
+  call adios_read_close(handle,ier)
+  call adios_read_finalize_method(ADIOS_READ_METHOD_BP, ier)
+end subroutine read_model_vp_rho_adios

Added: seismo/3D/SPECFEM3D/trunk/src/generate_databases/read_partition_files_adios.F90
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/generate_databases/read_partition_files_adios.F90	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/src/generate_databases/read_partition_files_adios.F90	2013-09-18 14:35:14 UTC (rev 22798)
@@ -0,0 +1,385 @@
+!=====================================================================
+!
+!               S p e c f e m 3 D  V e r s i o n  2 . 1
+!               ---------------------------------------
+!
+!          Main authors: Dimitri Komatitsch and Jeroen Tromp
+!    Princeton University, USA and CNRS / INRIA / University of Pau
+! (c) Princeton University / California Institute of Technology and CNRS / INRIA / University of Pau
+!                             July 2012
+!
+! This 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 02110-1301 USA.
+!
+!=====================================================================
+!
+
+!==============================================================================
+!> Reads in Database.bp file
+subroutine read_partition_files_adios()
+
+  use mpi
+  use adios_read_mod
+  use generate_databases_par
+
+  implicit none
+
+  character(len=256) :: database_name
+  integer(kind=8) :: handle
+
+  integer(kind=8), dimension(256),target :: selections
+  integer :: sel_num
+  integer(kind=8), pointer :: sel => null()
+  integer(kind=8), dimension(1) :: start, count
+
+  integer :: local_dim_nodes_coords,    local_dim_matpropl,           &
+             local_dim_material_index,  local_dim_elmnts_mesh,        &
+             local_dim_ibelm_xmin,      local_dim_nodes_ibelm_xmin,   &
+             local_dim_ibelm_xmax,      local_dim_nodes_ibelm_xmax,   &
+             local_dim_ibelm_ymin,      local_dim_nodes_ibelm_ymin,   &
+             local_dim_ibelm_ymax,      local_dim_nodes_ibelm_ymax,   &
+             local_dim_ibelm_bottom,    local_dim_nodes_ibelm_bottom, &
+             local_dim_ibelm_top,       local_dim_nodes_ibelm_top,    &
+             local_dim_neighbours_mesh, local_dim_num_elmnts_mesh,    &
+             local_dim_interfaces_mesh
+
+  integer :: num_xmin, num_xmax, num_ymin, num_ymax, num_top, num_bottom,num, &
+             num_spec, num_int
+
+  sel_num = 0
+
+  !-------------------------------------.
+  ! Open ADIOS Database file, read mode |
+  !-------------------------------------'
+  database_name = adjustl(LOCAL_PATH)
+  database_name = database_name(1:len_trim(database_name)) // "/Database.bp"
+
+  call adios_read_init_method (ADIOS_READ_METHOD_BP, MPI_COMM_WORLD, &
+                               "verbose=1", ier)
+  call adios_read_open_file (handle, database_name, 0, MPI_COMM_WORLD, ier)
+
+  !------------------------.
+  ! Get the 'chunks' sizes |
+  !------------------------'
+  call adios_get_scalar(handle, "nodes_coords/local_dim", &
+                        local_dim_nodes_coords, ier)
+  call adios_get_scalar(handle, "matpropl/local_dim", &
+                        local_dim_matpropl, ier)
+  call adios_get_scalar(handle, "material_index/local_dim", &
+                        local_dim_material_index, ier)
+  call adios_get_scalar(handle, "elmnts_mesh/local_dim", &
+                        local_dim_elmnts_mesh, ier)
+
+  call adios_get_scalar(handle, "ibelm_xmin/local_dim", &
+                        local_dim_ibelm_xmin, ier)
+  call adios_get_scalar(handle, "nodes_ibelm_xmin/local_dim", &
+                        local_dim_nodes_ibelm_xmin, ier)
+  call adios_get_scalar(handle, "ibelm_xmax/local_dim", &
+                        local_dim_ibelm_xmax, ier)
+  call adios_get_scalar(handle, "nodes_ibelm_xmax/local_dim", &
+                        local_dim_nodes_ibelm_xmax, ier)
+  call adios_get_scalar(handle, "ibelm_ymin/local_dim", &
+                        local_dim_ibelm_ymin, ier)
+  call adios_get_scalar(handle, "nodes_ibelm_ymin/local_dim", &
+                        local_dim_nodes_ibelm_ymin, ier)
+  call adios_get_scalar(handle, "ibelm_ymax/local_dim", &
+                        local_dim_ibelm_ymax, ier)
+  call adios_get_scalar(handle, "nodes_ibelm_ymax/local_dim", &
+                        local_dim_nodes_ibelm_ymax, ier)
+  call adios_get_scalar(handle, "ibelm_bottom/local_dim", &
+                        local_dim_ibelm_bottom, ier)
+  call adios_get_scalar(handle, "nodes_ibelm_bottom/local_dim", &
+                        local_dim_nodes_ibelm_bottom, ier)
+  call adios_get_scalar(handle, "ibelm_top/local_dim", &
+                        local_dim_ibelm_top, ier)
+  call adios_get_scalar(handle, "nodes_ibelm_top/local_dim", &
+                        local_dim_nodes_ibelm_top, ier)
+
+  call adios_get_scalar(handle, "neighbours_mesh/local_dim", &
+                        local_dim_neighbours_mesh, ier)
+  call adios_get_scalar(handle, "num_elmnts_mesh/local_dim", &
+                        local_dim_num_elmnts_mesh, ier)
+  call adios_get_scalar(handle, "interfaces_mesh/local_dim", &
+                        local_dim_interfaces_mesh, ier)
+
+  !------------------------------------------------------------------.
+  ! Get scalar values. Might be differents for different processors. |
+  ! Hence the selection writeblock.                                  |
+  !------------------------------------------------------------------'
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_writeblock(sel, myrank)
+  call adios_schedule_read(handle, sel, "/nglob", 0, 1, nnodes_ext_mesh, ier)
+  call adios_schedule_read(handle, sel, "/nspec", 0, 1, nelmnts_ext_mesh, ier)
+  ! read physical properties of the materials
+  ! added poroelastic properties and filled with 0 the last 10 entries 
+  ! for elastic/acoustic
+  call adios_schedule_read(handle, sel, "/nmaterials", 0, 1, nmat_ext_mesh, ier)
+  call adios_schedule_read(handle, sel, "/nundef_materials", 0, 1, &
+                           nundefMat_ext_mesh, ier)
+  call adios_schedule_read(handle, sel, "/nspec2d_xmin", 0, 1, nspec2D_xmin, ier)
+  call adios_schedule_read(handle, sel, "/nspec2d_xmax", 0, 1, nspec2D_xmax, ier)
+  call adios_schedule_read(handle, sel, "/nspec2d_ymin", 0, 1, nspec2D_ymin, ier)
+  call adios_schedule_read(handle, sel, "/nspec2d_ymax", 0, 1, nspec2D_ymax, ier)
+  call adios_schedule_read(handle, sel, "/nspec2d_bottom", 0, 1, &
+                           nspec2D_bottom_ext, ier)
+  call adios_schedule_read(handle, sel, "/nspec2d_top", 0, 1, &
+                           nspec2D_top_ext, ier)
+  ! MPI interfaces between different partitions
+  num_interfaces_ext_mesh = 0
+  max_interface_size_ext_mesh = 0
+  if( NPROC > 1 ) then
+    ! format: #number_of_MPI_interfaces  
+    !         #maximum_number_of_elements_on_each_interface
+    call adios_schedule_read(handle, sel, "/nb_interfaces", 0, 1, &
+                             num_interfaces_ext_mesh, ier)
+    call adios_schedule_read(handle, sel, "/nspec_interfaces_max", 0, 1, &
+                             max_interface_size_ext_mesh, ier)
+  endif
+  ! Perform the read, so we can use the values.
+  call adios_perform_reads(handle, ier)
+
+  NSPEC_AB = nelmnts_ext_mesh
+  NSPEC2D_BOTTOM = nspec2D_bottom_ext
+  NSPEC2D_TOP = nspec2D_top_ext
+
+  !---------------------------------------------.
+  ! Allocate arrays with previously read values |
+  !---------------------------------------------'
+  allocate(nodes_coords_ext_mesh(NDIM,nnodes_ext_mesh),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array nodes_coords_ext_mesh'
+  allocate(materials_ext_mesh(16,nmat_ext_mesh),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array materials_ext_mesh'
+  allocate(undef_mat_prop(6,nundefMat_ext_mesh),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array undef_mat_prop'
+  allocate(elmnts_ext_mesh(NGNOD,nelmnts_ext_mesh),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array elmnts_ext_mesh'
+  allocate(mat_ext_mesh(2,nelmnts_ext_mesh),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array mat_ext_mesh'
+
+  allocate(ibelm_xmin(nspec2D_xmin),&
+           nodes_ibelm_xmin(NGNOD2D,nspec2D_xmin),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array ibelm_xmin etc.'
+  allocate(ibelm_xmax(nspec2D_xmax),&
+           nodes_ibelm_xmax(NGNOD2D,nspec2D_xmax),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array ibelm_xmax etc.'
+  allocate(ibelm_ymin(nspec2D_ymin), &
+           nodes_ibelm_ymin(NGNOD2D,nspec2D_ymin),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array ibelm_ymin'
+  allocate(ibelm_ymax(nspec2D_ymax),&
+           nodes_ibelm_ymax(NGNOD2D,nspec2D_ymax),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array ibelm_ymax etc.'
+  allocate(ibelm_bottom(nspec2D_bottom_ext),&
+           nodes_ibelm_bottom(NGNOD2D,nspec2D_bottom_ext),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array ibelm_bottom etc.'
+  allocate(ibelm_top(nspec2D_top_ext), &
+           nodes_ibelm_top(NGNOD2D,nspec2D_top_ext),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array ibelm_top etc.'
+  ! allocates interfaces
+  allocate(my_neighbours_ext_mesh(num_interfaces_ext_mesh),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array my_neighbours_ext_mesh'
+  allocate(my_nelmnts_neighbours_ext_mesh(num_interfaces_ext_mesh),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array my_nelmnts_neighbours_ext_mesh'
+  allocate(my_interfaces_ext_mesh(6,max_interface_size_ext_mesh, &
+                                  num_interfaces_ext_mesh),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array my_interfaces_ext_mesh'
+  allocate(ibool_interfaces_ext_mesh(NGLLX*NGLLX*max_interface_size_ext_mesh, &
+                                    num_interfaces_ext_mesh),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array ibool_interfaces_ext_mesh'
+  allocate(nibool_interfaces_ext_mesh(num_interfaces_ext_mesh),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array nibool_interfaces_ext_mesh'
+
+  !---------------------------.
+  ! Read arrays from Database |
+  !---------------------------'
+  start(1) = local_dim_nodes_coords * myrank
+  count(1) = 3 * nnodes_ext_mesh
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count)
+  ! Remember: "nodes_coords" has been transposed in meshfem3D
+  call adios_schedule_read(handle, sel, "nodes_coords/array", 0, 1, &
+                           nodes_coords_ext_mesh, ier)
+
+  start(1) = local_dim_matpropl* myrank
+  count(1) = 16 * nmat_ext_mesh 
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count)
+  ! Remember: "matpropl" has been transposed in meshfem3D
+  call adios_schedule_read(handle, sel, "matpropl/array", 0, 1, &
+                           materials_ext_mesh, ier)
+
+  start(1) = local_dim_material_index * myrank
+  count(1) = 2 * nelmnts_ext_mesh 
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count)
+  call adios_schedule_read(handle, sel, "material_index/array", 0, 1, &
+                           mat_ext_mesh, ier)
+
+  start(1) = local_dim_elmnts_mesh * myrank
+  count(1) = NGNOD * nelmnts_ext_mesh 
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count)
+  call adios_schedule_read(handle, sel, "elmnts_mesh/array", 0, 1, &
+                           elmnts_ext_mesh, ier)
+
+  start(1) = local_dim_ibelm_xmin * myrank
+  count(1) = nspec2D_xmin
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count)
+  call adios_schedule_read(handle, sel, "ibelm_xmin/array", 0, 1, &
+                           ibelm_xmin, ier)
+
+  start(1) = local_dim_nodes_ibelm_xmin * myrank
+  count(1) = nspec2D_xmin * NGNOD2D 
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count)
+  call adios_schedule_read(handle, sel, "nodes_ibelm_xmin/array", 0, 1, &
+                           nodes_ibelm_xmin, ier)
+  start(1) = local_dim_ibelm_xmax * myrank
+  count(1) = nspec2D_xmax
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count)
+  call adios_schedule_read(handle, sel, "ibelm_xmax/array", 0, 1, &
+                           ibelm_xmax, ier)
+  start(1) = local_dim_nodes_ibelm_xmax * myrank
+  count(1) = nspec2D_xmax * NGNOD2D 
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count)
+  call adios_schedule_read(handle, sel, "nodes_ibelm_xmax/array", 0, 1, &
+                           nodes_ibelm_xmax, ier)
+  start(1) = local_dim_ibelm_ymin * myrank
+  count(1) = nspec2D_ymin
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count)
+  call adios_schedule_read(handle, sel, "ibelm_ymin/array", 0, 1, &
+                           ibelm_ymin, ier)
+  start(1) = local_dim_nodes_ibelm_ymin * myrank
+  count(1) = nspec2D_ymin * NGNOD2D 
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count)
+  call adios_schedule_read(handle, sel, "nodes_ibelm_ymin/array", 0, 1, &
+                           nodes_ibelm_ymin, ier)
+  start(1) = local_dim_ibelm_ymax * myrank
+  count(1) = nspec2D_ymax
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count)
+  call adios_schedule_read(handle, sel, "ibelm_ymax/array", 0, 1, &
+                           ibelm_ymax, ier)
+  start(1) = local_dim_nodes_ibelm_ymax * myrank
+  count(1) = nspec2D_ymax * NGNOD2D 
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count)
+  call adios_schedule_read(handle, sel, "nodes_ibelm_ymax/array", 0, 1, &
+                           nodes_ibelm_ymax, ier)
+  start(1) = local_dim_ibelm_bottom * myrank
+  count(1) = nspec2D_bottom_ext
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count)
+  call adios_schedule_read(handle, sel, "ibelm_bottom/array", 0, 1, &
+                           ibelm_bottom, ier)
+  start(1) = local_dim_nodes_ibelm_bottom * myrank
+  count(1) = nspec2D_bottom_ext * NGNOD2D 
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count)
+  call adios_schedule_read(handle, sel, "nodes_ibelm_bottom/array", 0, 1, &
+                           nodes_ibelm_bottom, ier)
+  start(1) = local_dim_ibelm_top * myrank
+  count(1) = nspec2D_top_ext
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count)
+  call adios_schedule_read(handle, sel, "ibelm_top/array", 0, 1, &
+                           ibelm_top, ier)
+  start(1) = local_dim_nodes_ibelm_top * myrank
+  count(1) = nspec2D_top_ext * NGNOD2D 
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count)
+  call adios_schedule_read(handle, sel, "nodes_ibelm_top/array", 0, 1, &
+                           nodes_ibelm_top, ier)
+
+  start(1) = local_dim_neighbours_mesh * myrank
+  count(1) = num_interfaces_ext_mesh 
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count)
+  call adios_schedule_read(handle, sel, "neighbours_mesh/array", 0, 1, &
+                           my_neighbours_ext_mesh, ier)
+  start(1) = local_dim_num_elmnts_mesh * myrank
+  count(1) = num_interfaces_ext_mesh 
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count)
+  call adios_schedule_read(handle, sel, "num_elmnts_mesh/array", 0, 1, &
+                           my_nelmnts_neighbours_ext_mesh, ier)
+  start(1) = local_dim_interfaces_mesh * myrank
+  count(1) = 6 * num_interfaces_ext_mesh * max_interface_size_ext_mesh
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count)
+  call adios_schedule_read(handle, sel, "interfaces_mesh/array", 0, 1, &
+                           my_interfaces_ext_mesh, ier)
+
+  call adios_perform_reads(handle, ier)
+  call adios_read_close(handle,ier)
+  call adios_read_finalize_method(ADIOS_READ_METHOD_BP, ier)
+
+  ! reads number of C-PML elements in the global mesh
+  nspec_cpml_tot = 0
+  nspec_cpml = 0
+
+  ! TODO make 'undef_mat_prop' ADIOS compliant.
+  ! TODO CPML in meshfem w/ and w/o ADIOS
+  ! TODO SAVE_MOHO_MESH w/ ADIOS (not in meshfem)
+
+  !-----------------------------.
+  ! Fetch and print come stats. |
+  !-----------------------------'
+  !call sum_all_i(nspec_ab,num_spec)
+  !call sum_all_i(nnodes_ext_mesh,num)
+  !call sum_all_i(nspec2D_xmin,num_xmin)
+  !call sum_all_i(nspec2D_xmax,num_xmax)
+  !call sum_all_i(nspec2D_ymin,num_ymin)
+  !call sum_all_i(nspec2D_ymax,num_ymax)
+  !call sum_all_i(nspec2D_top_ext,num_top)
+  !call sum_all_i(nspec2D_bottom_ext,num_bottom)
+  !call sum_all_i(num_interfaces_ext_mesh,num_int)
+  !if(myrank == 0) then
+    !write(IMAIN,*) ' total number of spectral elements: ',num_spec
+    !write(IMAIN,*) '  external mesh points: ',num
+    !write(IMAIN,*) '  defined materials: ',nmat_ext_mesh
+    !write(IMAIN,*) '  undefined materials: ',nundefMat_ext_mesh
+    !write(IMAIN,*) '  absorbing boundaries: '
+    !write(IMAIN,*) '    xmin,xmax: ',num_xmin,num_xmax
+    !write(IMAIN,*) '    ymin,ymax: ',num_ymin,num_ymax
+    !write(IMAIN,*) '    bottom,top: ',num_bottom,num_top
+    !write(IMAIN,*) '  number of MPI partition interfaces: ',num_int
+  !endif
+  !call sync_all()
+
+end subroutine read_partition_files_adios

Added: seismo/3D/SPECFEM3D/trunk/src/generate_databases/save_arrays_solver_adios.F90
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/generate_databases/save_arrays_solver_adios.F90	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/src/generate_databases/save_arrays_solver_adios.F90	2013-09-18 14:35:14 UTC (rev 22798)
@@ -0,0 +1,1523 @@
+!=====================================================================
+!
+!               S p e c f e m 3 D  V e r s i o n  2 . 1
+!               ---------------------------------------
+!
+!          Main authors: Dimitri Komatitsch and Jeroen Tromp
+!    Princeton University, USA and CNRS / INRIA / University of Pau
+! (c) Princeton University / California Institute of Technology and CNRS / INRIA / University of Pau
+!                             July 2012
+!
+! This 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 02110-1301 USA.
+!
+!=====================================================================
+
+!==============================================================================
+!> \file save_arrays_solver_adios.F90
+!!
+!! \author MPBL
+!==============================================================================
+
+!==============================================================================
+!> \def STRINGIFY_VAR(a)
+!! Macro taking a variable and returning the stringified variable and 
+!! the variable itself.
+!! STRINGIFY_VAR(x) expand as:
+!!   "x", x
+!! x being the variable name inside the code.
+#ifdef __INTEL_COMPILER
+#define STRINGIFY_VAR(a) #a, a
+#else
+#define STRINGIFY_VAR(a) "a", a
+#endif
+
+! for external mesh
+
+subroutine save_arrays_solver_ext_mesh_adios(nspec, nglob,                   &
+                                        APPROXIMATE_OCEAN_LOAD,              &
+                                       ibool, num_interfaces_ext_mesh,       &
+                                       my_neighbours_ext_mesh,               &
+                                       nibool_interfaces_ext_mesh,           &
+                                       max_interface_size_ext_mesh,          &
+                                       ibool_interfaces_ext_mesh,            &
+                                       SAVE_MESH_FILES,ANISOTROPY)
+
+  use generate_databases_par, only: nspec_cpml, CPML_width_x, CPML_width_y, &
+                                    CPML_width_z, CPML_to_spec,             &
+                                    CPML_regions, is_CPML, nspec_cpml_tot,  &
+                                    d_store_x, d_store_y, d_store_z,        &
+                                    k_store_x, k_store_y, k_store_z,        &
+                                    alpha_store,                            &
+                                    nspec2D_xmin, nspec2D_xmax,             &
+                                    nspec2D_ymin, nspec2D_ymax,             &
+                                    NSPEC2D_BOTTOM, NSPEC2D_TOP,            &
+                                    ibelm_xmin, ibelm_xmax,ibelm_ymin,      &
+                                    ibelm_ymax, ibelm_bottom, ibelm_top,    &
+                                    PML_CONDITIONS,                         &
+                                    !for adjoint tomography
+                                    SIMULATION_TYPE, SAVE_FORWARD,          &
+                                    mask_ibool_interior_domain,             &
+                                    nglob_interface_PML_acoustic,           &
+                                    points_interface_PML_acoustic,          &
+                                    nglob_interface_PML_elastic,            &
+                                    points_interface_PML_elastic,           &
+                                    STACEY_ABSORBING_CONDITIONS,            &
+                                    LOCAL_PATH, myrank, sizeprocs,          &
+                                    nspec_ab
+  use mpi
+  use adios_helpers_mod
+  use create_regions_mesh_ext_par
+
+  implicit none
+
+  integer :: nspec,nglob
+  ! ocean load
+  logical :: APPROXIMATE_OCEAN_LOAD
+  ! mesh coordinates
+  integer, dimension(NGLLX,NGLLY,NGLLZ,nspec) :: ibool
+  ! MPI interfaces
+  integer :: num_interfaces_ext_mesh
+  integer, dimension(num_interfaces_ext_mesh) :: my_neighbours_ext_mesh
+  integer, dimension(num_interfaces_ext_mesh) :: nibool_interfaces_ext_mesh
+  integer :: max_interface_size_ext_mesh
+  integer, dimension(NGLLX * NGLLX * max_interface_size_ext_mesh, &
+                     num_interfaces_ext_mesh) :: ibool_interfaces_ext_mesh
+
+  logical :: SAVE_MESH_FILES
+  logical :: ANISOTROPY
+
+  ! local parameters
+  integer, dimension(:,:), allocatable :: ibool_interfaces_ext_mesh_dummy
+  integer :: max_nibool_interfaces_ext_mesh
+
+  integer :: ier,i
+
+  !--- Local parameters for ADIOS ---
+  character(len=256) :: output_name
+  character(len=64), parameter :: group_name  = "SPECFEM3D_EXTERNAL_MESH"
+  integer(kind=8) :: group, handle
+  integer(kind=8) :: groupsize, totalsize
+  integer :: local_dim
+
+  !--- Variables to allreduce - wmax stands for world_max
+  integer :: nglob_wmax, nspec_wmax, nspec_cpml_wmax,              &
+             CPML_width_x_wmax, CPML_width_y_wmax, CPML_width_z_wmax,          &
+             nglob_interface_PML_acoustic_wmax,                                &
+             nglob_interface_PML_elastic_wmax, num_abs_boundary_faces_wmax,    &
+             nspec2d_xmin_wmax, nspec2d_xmax_wmax,                             &
+             nspec2d_ymin_wmax, nspec2d_ymax_wmax,                             &
+             nspec2d_bottom_wmax, nspec2d_top_wmax,                            &
+             num_free_surface_faces_wmax, num_coupling_ac_el_faces_wmax,       &
+             num_coupling_ac_po_faces_wmax, num_coupling_el_po_faces_wmax,     &
+             num_interfaces_ext_mesh_wmax, max_interface_size_ext_mesh_wmax,   &
+             nspec_inner_acoustic_wmax, nspec_outer_acoustic_wmax,             &
+             num_phase_ispec_acoustic_wmax, nspec_inner_elastic_wmax,          &
+             nspec_outer_elastic_wmax, num_phase_ispec_elastic_wmax,           &
+             nspec_inner_poroelastic_wmax, nspec_outer_poroelastic_wmax,       &
+             num_phase_ispec_poroelastic_wmax, num_colors_outer_acoustic_wmax, &
+             num_colors_inner_acoustic_wmax, num_colors_outer_elastic_wmax,    &
+             num_colors_inner_elastic_wmax, nglob_dummy_wmax,                  &
+             nglob_ocean_wmax, nglob_xy_wmax, nspec_ab_wmax, nspec_aniso_wmax, &
+             max_nibool_interfaces_ext_mesh_wmax
+
+  integer, parameter :: num_vars = 40
+  integer, dimension(num_vars) :: max_global_values
+
+  !---------------------------.
+  ! Setup the values to write |
+  !---------------------------'
+  !MPI interfaces
+  max_nibool_interfaces_ext_mesh = maxval(nibool_interfaces_ext_mesh(:))
+
+  allocate(ibool_interfaces_ext_mesh_dummy(max_nibool_interfaces_ext_mesh, &
+                                           num_interfaces_ext_mesh),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array'
+  do i = 1, num_interfaces_ext_mesh
+     ibool_interfaces_ext_mesh_dummy(:,i) = &
+         ibool_interfaces_ext_mesh(1:max_nibool_interfaces_ext_mesh,i)
+  enddo
+
+  !-----------------------------------------------------------------.
+  ! Get maximum value for each variable used to define a local_dim. |
+  ! ADIOS write equally sized chunks for each processor.            |
+  !-----------------------------------------------------------------'
+  ! Filling a temporary array to avoid doing allreduces for each var.
+  max_global_values(1)  = nglob
+  max_global_values(2)  = nspec 
+  max_global_values(3)  = max_nibool_interfaces_ext_mesh
+  max_global_values(4)  = nspec_cpml 
+  max_global_values(5)  = CPML_width_x 
+  max_global_values(6)  = CPML_width_y 
+  max_global_values(7)  = CPML_width_z 
+  max_global_values(8)  = nglob_interface_PML_acoustic 
+  max_global_values(9)  = nglob_interface_PML_elastic 
+  max_global_values(10) = num_abs_boundary_faces 
+  max_global_values(11) = nspec2d_xmin
+  max_global_values(12) = nspec2d_xmax
+  max_global_values(13) = nspec2d_ymin
+  max_global_values(14) = nspec2d_ymax
+  max_global_values(15) = nspec2d_bottom
+  max_global_values(16) = nspec2d_top 
+  max_global_values(17) = num_free_surface_faces
+  max_global_values(18) = num_coupling_ac_el_faces
+  max_global_values(19) = num_coupling_ac_po_faces
+  max_global_values(20) = num_coupling_el_po_faces
+  max_global_values(21) = num_interfaces_ext_mesh
+  max_global_values(22) = max_interface_size_ext_mesh
+  max_global_values(23) = nspec_inner_acoustic
+  max_global_values(24) = nspec_outer_acoustic
+  max_global_values(25) = num_phase_ispec_acoustic
+  max_global_values(26) = nspec_inner_elastic
+  max_global_values(27) = nspec_outer_elastic
+  max_global_values(28) = num_phase_ispec_elastic
+  max_global_values(29) = nspec_inner_poroelastic
+  max_global_values(30) = nspec_outer_poroelastic
+  max_global_values(31) = num_phase_ispec_poroelastic
+  max_global_values(32) = num_colors_outer_acoustic
+  max_global_values(33) = num_colors_inner_acoustic
+  max_global_values(34) = num_colors_outer_elastic
+  max_global_values(35) = num_colors_inner_elastic
+  max_global_values(36) = nglob_dummy
+  max_global_values(37) = nglob_ocean
+  max_global_values(38) = nglob_xy
+  max_global_values(39) = nspec_ab
+  max_global_values(40) = nspec_aniso
+
+  call MPI_Allreduce(MPI_IN_PLACE, max_global_values, num_vars, &
+                     MPI_INTEGER, MPI_MAX, MPI_COMM_WORLD, ier)
+  if( ier /= 0 ) call exit_MPI(myrank,'Allreduce to get max values failed.')
+
+  nglob_wmax                          = max_global_values(1)
+  nspec_wmax                          = max_global_values(2)
+  max_nibool_interfaces_ext_mesh_wmax = max_global_values(3)
+  nspec_cpml_wmax                     = max_global_values(4)
+  CPML_width_x_wmax                   = max_global_values(5)
+  CPML_width_y_wmax                   = max_global_values(6)
+  CPML_width_z_wmax                   = max_global_values(7)
+  nglob_interface_PML_acoustic_wmax   = max_global_values(8)
+  nglob_interface_PML_elastic_wmax    = max_global_values(9)
+  num_abs_boundary_faces_wmax         = max_global_values(10)
+  nspec2d_xmin_wmax                   = max_global_values(11)
+  nspec2d_xmax_wmax                   = max_global_values(12)
+  nspec2d_ymin_wmax                   = max_global_values(13)
+  nspec2d_ymax_wmax                   = max_global_values(14)
+  nspec2d_bottom_wmax                 = max_global_values(15)
+  nspec2d_top_wmax                    = max_global_values(16)
+  num_free_surface_faces_wmax         = max_global_values(17)
+  num_coupling_ac_el_faces_wmax       = max_global_values(18)
+  num_coupling_ac_po_faces_wmax       = max_global_values(19)
+  num_coupling_el_po_faces_wmax       = max_global_values(20)
+  num_interfaces_ext_mesh_wmax        = max_global_values(21)
+  max_interface_size_ext_mesh_wmax    = max_global_values(22)
+  nspec_inner_acoustic_wmax           = max_global_values(23)
+  nspec_outer_acoustic_wmax           = max_global_values(24)
+  num_phase_ispec_acoustic_wmax       = max_global_values(25)
+  nspec_inner_elastic_wmax            = max_global_values(26)
+  nspec_outer_elastic_wmax            = max_global_values(27)
+  num_phase_ispec_elastic_wmax        = max_global_values(28)
+  nspec_inner_poroelastic_wmax        = max_global_values(29)
+  nspec_outer_poroelastic_wmax        = max_global_values(30)
+  num_phase_ispec_poroelastic_wmax    = max_global_values(31)
+  num_colors_outer_acoustic_wmax      = max_global_values(32)
+  num_colors_inner_acoustic_wmax      = max_global_values(33)
+  num_colors_outer_elastic_wmax       = max_global_values(34)
+  num_colors_inner_elastic_wmax       = max_global_values(35)
+  nglob_dummy_wmax                    = max_global_values(36)
+  nglob_ocean_wmax                    = max_global_values(37)
+  nglob_xy_wmax                       = max_global_values(38)
+  nspec_ab_wmax                       = max_global_values(39)
+  nspec_aniso_wmax                    = max_global_values(40)
+
+  ! save arrays for the solver to run.
+  !-----------------------------------.
+  ! Setup ADIOS for the current group |
+  !-----------------------------------'
+  groupsize = 0
+  output_name = LOCAL_PATH(1:len_trim(LOCAL_PATH)) // "/external_mesh.bp"
+  call adios_declare_group(group, group_name, "", 1, ier)
+  call adios_select_method(group, ADIOS_TRANSPORT_METHOD, "", "", ier)
+
+  !------------------------.
+  ! Define ADIOS Variables |
+  !------------------------'
+  call define_adios_scalar(group, groupsize, "", STRINGIFY_VAR(nspec)) 
+  call define_adios_scalar(group, groupsize, "", STRINGIFY_VAR(nglob)) 
+
+  local_dim = NGLLX * NGLLY * NGLLZ * nspec_wmax
+  call define_adios_global_array1D(group, groupsize, local_dim, &
+                                   "", STRINGIFY_VAR(ibool))
+
+  local_dim = nglob_dummy_wmax
+  call define_adios_global_array1D(group, groupsize, local_dim, &
+                                   "", "x_global", xstore_dummy)
+  call define_adios_global_array1D(group, groupsize, local_dim, &
+                                   "", "y_global", ystore_dummy)
+  call define_adios_global_array1D(group, groupsize, local_dim, &
+                                   "", "z_global", zstore_dummy)
+
+  ! this array is needed for acoustic simulations but also for elastic 
+  ! simulations with CPML, thus we allocate it and read it in all cases
+  ! (whether the simulation is acoustic, elastic, or acoustic/elastic)
+  local_dim = NGLLX * NGLLY * NGLLZ * nspec_wmax
+  call define_adios_global_array1D(group, groupsize, &
+                                   local_dim, "", STRINGIFY_VAR(xixstore))
+  call define_adios_global_array1D(group, groupsize, &
+                                   local_dim, "", STRINGIFY_VAR(xiystore))
+  call define_adios_global_array1D(group, groupsize, &
+                                   local_dim, "", STRINGIFY_VAR(xizstore))
+  call define_adios_global_array1D(group, groupsize, &
+                                   local_dim, "", STRINGIFY_VAR(etaxstore))
+  call define_adios_global_array1D(group, groupsize, &
+                                   local_dim, "", STRINGIFY_VAR(etaystore))
+  call define_adios_global_array1D(group, groupsize, &
+                                   local_dim, "", STRINGIFY_VAR(etazstore))
+  call define_adios_global_array1D(group, groupsize, &
+                                   local_dim, "", STRINGIFY_VAR(gammaxstore))
+  call define_adios_global_array1D(group, groupsize, &
+                                   local_dim, "", STRINGIFY_VAR(gammaystore))
+  call define_adios_global_array1D(group, groupsize, &
+                                   local_dim, "", STRINGIFY_VAR(gammazstore))
+  call define_adios_global_array1D(group, groupsize, &
+                                   local_dim, "", STRINGIFY_VAR(jacobianstore))
+  call define_adios_global_array1D(group, groupsize, &
+                                   local_dim, "", STRINGIFY_VAR(kappastore))
+  call define_adios_global_array1D(group, groupsize, &
+                                   local_dim, "", STRINGIFY_VAR(mustore))
+  call define_adios_global_array1D(group, groupsize, &
+                                   local_dim, "", STRINGIFY_VAR(rhostore))
+
+  local_dim = nspec_wmax
+  call define_adios_global_array1D(group, groupsize, &
+                                   local_dim, "",               &
+                                   STRINGIFY_VAR(ispec_is_acoustic))
+  call define_adios_global_array1D(group, groupsize, &
+                                   local_dim, "",               &
+                                   STRINGIFY_VAR(ispec_is_elastic))
+  call define_adios_global_array1D(group, groupsize, &
+                                   local_dim, "",               &
+                                   STRINGIFY_VAR(ispec_is_poroelastic))
+
+  ! acoustic
+  if( ACOUSTIC_SIMULATION ) then
+    local_dim = nglob_wmax
+    call define_adios_global_array1D(group, groupsize, &
+                                     local_dim, "",               &
+                                     STRINGIFY_VAR(rmass_acoustic))
+    call define_adios_global_array1D(group, groupsize, &
+                                     local_dim, "",               &
+                                     STRINGIFY_VAR(rmass_acoustic_interface))
+  endif
+
+  ! elastic
+  if( ELASTIC_SIMULATION ) then
+    local_dim = nglob_wmax
+    call define_adios_global_array1D(group, groupsize, &
+                                     local_dim, "", STRINGIFY_VAR(rmass))
+    if(PML_CONDITIONS)then
+       if(ACOUSTIC_SIMULATION)then
+          local_dim = nglob_wmax
+          call define_adios_global_array1D(group, groupsize, &
+                                           local_dim, "",    &
+                                        STRINGIFY_VAR(rmass_elastic_interface))
+       endif
+    endif
+    if( APPROXIMATE_OCEAN_LOAD) then
+      local_dim = nglob_ocean_wmax
+      call define_adios_global_array1D(group, groupsize, &
+                                       local_dim, "",               &
+                                       STRINGIFY_VAR(rmass_ocean_load))
+    endif
+    !pll Stacey
+    local_dim = NGLLX * NGLLY * NGLLZ * nspec_wmax
+    call define_adios_global_array1D(group, groupsize, &
+                                     local_dim, "", STRINGIFY_VAR(rho_vp))
+    call define_adios_global_array1D(group, groupsize, &
+                                     local_dim, "", STRINGIFY_VAR(rho_vs))
+  endif
+
+  ! poroelastic
+  if( POROELASTIC_SIMULATION ) then
+    local_dim = nglob_wmax
+    call define_adios_global_array1D(group, groupsize, &
+                                     local_dim, "",               &
+                                     STRINGIFY_VAR(rmass_solid_poroelastic))
+    call define_adios_global_array1D(group, groupsize, &
+                                     local_dim, "",               &
+                                     STRINGIFY_VAR(rmass_fluid_poroelastic))
+    local_dim = 2 * NGLLX * NGLLY * NGLLZ * nspec_wmax
+    call define_adios_global_array1D(group, groupsize, &
+                                     local_dim, "",               &
+                                     STRINGIFY_VAR(rhoarraystore))
+    local_dim = 3 * NGLLX * NGLLY * NGLLZ * nspec_wmax
+    call define_adios_global_array1D(group, groupsize, &
+                                     local_dim, "",               &
+                                     STRINGIFY_VAR(kappaarraystore))
+    local_dim = 6 * NGLLX * NGLLY * NGLLZ * nspec_wmax
+    call define_adios_global_array1D(group, groupsize, &
+                                     local_dim, "",               &
+                                     STRINGIFY_VAR(permstore))
+    local_dim = NGLLX * NGLLY * NGLLZ * nspec_wmax
+    call define_adios_global_array1D(group, groupsize, &
+                                     local_dim, "",               &
+                                     STRINGIFY_VAR(etastore))
+    call define_adios_global_array1D(group, groupsize, &
+                                     local_dim, "",               &
+                                     STRINGIFY_VAR(tortstore))
+    call define_adios_global_array1D(group, groupsize, &
+                                     local_dim, "",               &
+                                     STRINGIFY_VAR(phistore))
+    call define_adios_global_array1D(group, groupsize, &
+                                     local_dim, "",               &
+                                     STRINGIFY_VAR(rho_vpI))
+    call define_adios_global_array1D(group, groupsize, &
+                                     local_dim, "",               &
+                                     STRINGIFY_VAR(rho_vpII))
+    call define_adios_global_array1D(group, groupsize, &
+                                     local_dim, "",               &
+                                     STRINGIFY_VAR(rho_vsI))
+  endif
+
+  ! C-PML absorbing boundary conditions
+  if( PML_CONDITIONS ) then
+    call define_adios_scalar(group, groupsize, "", STRINGIFY_VAR(nspec_cpml)) 
+    call define_adios_scalar(group, groupsize, "", STRINGIFY_VAR(CPML_width_x)) 
+    call define_adios_scalar(group, groupsize, "", STRINGIFY_VAR(CPML_width_y)) 
+    call define_adios_scalar(group, groupsize, "", STRINGIFY_VAR(CPML_width_z)) 
+    if( nspec_cpml > 0 ) then
+      local_dim = nspec_cpml_wmax
+      call define_adios_global_array1D(group, groupsize, &
+                                       local_dim, "",               &
+                                       STRINGIFY_VAR(CPML_regions))
+      call define_adios_global_array1D(group, groupsize, &
+                                       local_dim, "",               &
+                                       STRINGIFY_VAR(CPML_to_spec))
+      local_dim = nspec_ab_wmax
+      call define_adios_global_array1D(group, groupsize, &
+                                       local_dim, "", STRINGIFY_VAR(is_CPML))
+      local_dim = NGLLX * NGLLY * NGLLZ * nspec_cpml_wmax
+      call define_adios_global_array1D(group, groupsize, &
+                                       local_dim, "", STRINGIFY_VAR(d_store_x))
+      call define_adios_global_array1D(group, groupsize, &
+                                       local_dim, "", STRINGIFY_VAR(d_store_y))
+      call define_adios_global_array1D(group, groupsize, &
+                                       local_dim, "", STRINGIFY_VAR(d_store_z))
+      call define_adios_global_array1D(group, groupsize, &
+                                       local_dim, "", STRINGIFY_VAR(k_store_x))
+      call define_adios_global_array1D(group, groupsize, &
+                                       local_dim, "", STRINGIFY_VAR(k_store_y))
+      call define_adios_global_array1D(group, groupsize, &
+                                       local_dim, "", STRINGIFY_VAR(k_store_z))
+      call define_adios_global_array1D(group, groupsize, &
+                                       local_dim, "",               &
+                                       STRINGIFY_VAR(alpha_store))
+      ! -----------------------------------------------------------------------
+      ! for adjoint tomography
+      ! save the array stored the points on interface between PML and interior
+      ! computational domain
+      ! -----------------------------------------------------------------------
+      if((SIMULATION_TYPE == 1 .and. SAVE_FORWARD) &
+          .or. SIMULATION_TYPE == 3) then
+        call define_adios_scalar(group, groupsize, "", &
+                                 STRINGIFY_VAR(nglob_interface_PML_acoustic)) 
+        call define_adios_scalar(group, groupsize, "", &
+                                 STRINGIFY_VAR(nglob_interface_PML_elastic)) 
+        if(nglob_interface_PML_acoustic > 0) then
+          local_dim = nglob_interface_PML_acoustic_wmax
+          call define_adios_global_array1D(group, groupsize, &
+                                           local_dim, "",               &
+                                  STRINGIFY_VAR(points_interface_PML_acoustic))
+        endif
+        if(nglob_interface_PML_elastic > 0) then
+          local_dim = nglob_interface_PML_elastic_wmax
+          call define_adios_global_array1D(group, groupsize, &
+                                           local_dim, "",               &
+                                  STRINGIFY_VAR(points_interface_PML_elastic))
+        endif
+      endif
+    endif
+  endif
+
+  ! absorbing boundary surface
+  call define_adios_scalar(group, groupsize, "", &
+                           STRINGIFY_VAR(num_abs_boundary_faces)) 
+  if(PML_CONDITIONS)then
+    if( num_abs_boundary_faces > 0 ) then
+      local_dim = num_abs_boundary_faces_wmax
+      call define_adios_global_array1D(group, groupsize, &
+                                       local_dim, "",               &
+                                       STRINGIFY_VAR(abs_boundary_ispec))
+      local_dim = 3 * NGLLSQUARE * num_abs_boundary_faces_wmax
+      call define_adios_global_array1D(group, groupsize, &
+                                       local_dim, "",               &
+                                       STRINGIFY_VAR(abs_boundary_ijk))
+      local_dim = NGLLSQUARE * num_abs_boundary_faces_wmax
+      call define_adios_global_array1D(group, groupsize, &
+                                       local_dim, "",               &
+                                       STRINGIFY_VAR(abs_boundary_jacobian2Dw))
+      local_dim = NDIM * NGLLSQUARE * num_abs_boundary_faces_wmax
+      call define_adios_global_array1D(group, groupsize, &
+                                       local_dim, "",               &
+                                       STRINGIFY_VAR(abs_boundary_normal))
+    endif
+  else
+    if( num_abs_boundary_faces > 0 ) then
+      local_dim = num_abs_boundary_faces_wmax
+      call define_adios_global_array1D(group, groupsize, &
+                                       local_dim, "",               &
+                                       STRINGIFY_VAR(abs_boundary_ispec))
+      local_dim = 3 * NGLLSQUARE * num_abs_boundary_faces_wmax
+      call define_adios_global_array1D(group, groupsize, &
+                                       local_dim, "",               &
+                                       STRINGIFY_VAR(abs_boundary_ijk))
+      local_dim = NGLLSQUARE * num_abs_boundary_faces_wmax
+      call define_adios_global_array1D(group, groupsize, &
+                                       local_dim, "",               &
+                                       STRINGIFY_VAR(abs_boundary_jacobian2Dw))
+      local_dim = NDIM * NGLLSQUARE * num_abs_boundary_faces_wmax
+      call define_adios_global_array1D(group, groupsize, &
+                                       local_dim, "",               &
+                                       STRINGIFY_VAR(abs_boundary_normal))
+      if( STACEY_ABSORBING_CONDITIONS ) then
+        ! store mass matrix contributions
+        if(ELASTIC_SIMULATION ) then
+          local_dim = nglob_xy_wmax
+          call define_adios_global_array1D(group, groupsize, &
+                                           local_dim, "",               &
+                                           STRINGIFY_VAR(rmassx))
+          call define_adios_global_array1D(group, groupsize, &
+                                           local_dim, "",               &
+                                           STRINGIFY_VAR(rmassy))
+          call define_adios_global_array1D(group, groupsize, &
+                                           local_dim, "",               &
+                                           STRINGIFY_VAR(rmassz))
+        endif
+        if(ACOUSTIC_SIMULATION) then
+          local_dim = nglob_xy_wmax
+          call define_adios_global_array1D(group, groupsize, &
+                                           local_dim, "",               &
+                                           STRINGIFY_VAR(rmassz_acoustic))
+        endif
+      endif
+    endif
+  endif
+
+  call define_adios_scalar(group, groupsize, "", STRINGIFY_VAR(nspec2d_xmin))
+  call define_adios_scalar(group, groupsize, "", STRINGIFY_VAR(nspec2d_xmax))
+  call define_adios_scalar(group, groupsize, "", STRINGIFY_VAR(nspec2d_ymin))
+  call define_adios_scalar(group, groupsize, "", STRINGIFY_VAR(nspec2d_ymax))
+  call define_adios_scalar(group, groupsize, "", STRINGIFY_VAR(nspec2d_bottom))
+  call define_adios_scalar(group, groupsize, "", STRINGIFY_VAR(nspec2d_top)) 
+
+  if (nspec2d_xmin .ne. 0) then
+    local_dim = nspec2d_xmin_wmax 
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", STRINGIFY_VAR(ibelm_xmin))
+  endif 
+  if (nspec2d_xmax .ne. 0) then
+    local_dim = nspec2d_xmax_wmax 
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", STRINGIFY_VAR(ibelm_xmax))
+  endif
+  if (nspec2d_ymin .ne. 0) then
+    local_dim = nspec2d_ymin_wmax 
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", STRINGIFY_VAR(ibelm_ymin))
+  endif                                   
+  if (nspec2d_ymax .ne. 0) then
+    local_dim = nspec2d_ymax_wmax 
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", STRINGIFY_VAR(ibelm_ymax))
+  endif
+  if (nspec2d_bottom .ne. 0) then
+    local_dim = nspec2d_bottom_wmax 
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", STRINGIFY_VAR(ibelm_bottom))
+  endif
+  if (nspec2d_top .ne. 0) then
+    local_dim = nspec2d_top_wmax 
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", STRINGIFY_VAR(ibelm_top))
+  endif                                 
+
+  ! free surface
+  call define_adios_scalar(group, groupsize, "", &
+                           STRINGIFY_VAR(num_free_surface_faces))
+  if( num_free_surface_faces > 0 ) then
+    local_dim = num_free_surface_faces_wmax
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", STRINGIFY_VAR(free_surface_ispec))
+    local_dim = 3 * NGLLSQUARE * num_free_surface_faces_wmax
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", STRINGIFY_VAR(free_surface_ijk))
+    local_dim = NGLLSQUARE * num_free_surface_faces_wmax
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                   "", STRINGIFY_VAR(free_surface_jacobian2Dw))
+    local_dim = NDIM * NGLLSQUARE * num_free_surface_faces_wmax
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", STRINGIFY_VAR(free_surface_normal))
+  endif
+
+  ! acoustic-elastic coupling surface
+  call define_adios_scalar(group, groupsize, "", &
+                           STRINGIFY_VAR(num_coupling_ac_el_faces))
+  if( num_coupling_ac_el_faces > 0 ) then
+    local_dim = num_coupling_ac_el_faces_wmax
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", STRINGIFY_VAR(coupling_ac_el_ispec))
+    local_dim = 3 * NGLLSQUARE * num_coupling_ac_el_faces_wmax
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", STRINGIFY_VAR(coupling_ac_el_ijk))
+    local_dim = NGLLSQUARE * num_coupling_ac_el_faces_wmax
+    call define_adios_global_array1D(group, groupsize, local_dim, "", &
+                                     STRINGIFY_VAR(coupling_ac_el_jacobian2Dw))
+    local_dim = NDIM * NGLLSQUARE * num_coupling_ac_el_faces_wmax
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", STRINGIFY_VAR(coupling_ac_el_normal))
+  endif
+
+  ! acoustic-poroelastic coupling surface
+  call define_adios_scalar(group, groupsize, "", &
+                           STRINGIFY_VAR(num_coupling_ac_po_faces))
+  if( num_coupling_ac_po_faces > 0 ) then
+    local_dim = num_coupling_ac_po_faces_wmax
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", STRINGIFY_VAR(coupling_ac_po_ispec))
+    local_dim = 3 * NGLLSQUARE * num_coupling_ac_po_faces_wmax
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", STRINGIFY_VAR(coupling_ac_po_ijk))
+    local_dim = NGLLSQUARE * num_coupling_ac_po_faces_wmax
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                  "", STRINGIFY_VAR(coupling_ac_po_jacobian2Dw))
+    local_dim = NDIM * NGLLSQUARE * num_coupling_ac_po_faces_wmax
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", STRINGIFY_VAR(coupling_ac_po_normal))
+  endif
+
+  ! elastic-poroelastic coupling surface
+  call define_adios_scalar(group, groupsize, "", &
+                           STRINGIFY_VAR(num_coupling_el_po_faces))
+  if( num_coupling_el_po_faces > 0 ) then
+    local_dim = num_coupling_el_po_faces_wmax
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", STRINGIFY_VAR(coupling_el_po_ispec))
+    local_dim = num_coupling_el_po_faces_wmax
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", STRINGIFY_VAR(coupling_po_el_ispec))
+    local_dim = 3 * NGLLSQUARE * num_coupling_el_po_faces_wmax
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", STRINGIFY_VAR(coupling_el_po_ijk))
+    local_dim = 3 * NGLLSQUARE * num_coupling_el_po_faces_wmax
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", STRINGIFY_VAR(coupling_po_el_ijk))
+    local_dim = NGLLSQUARE * num_coupling_el_po_faces_wmax
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                  "", STRINGIFY_VAR(coupling_el_po_jacobian2Dw))
+    local_dim = NDIM * NGLLSQUARE * num_coupling_el_po_faces_wmax
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", STRINGIFY_VAR(coupling_el_po_normal))
+  endif
+
+  call define_adios_scalar(group, groupsize, "", &
+                           STRINGIFY_VAR(num_interfaces_ext_mesh))
+  if( num_interfaces_ext_mesh > 0 ) then
+    call define_adios_scalar(group, groupsize, "", &
+                             STRINGIFY_VAR(max_nibool_interfaces_ext_mesh))
+    local_dim = num_interfaces_ext_mesh_wmax
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", STRINGIFY_VAR(my_neighbours_ext_mesh))
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                 "", STRINGIFY_VAR(nibool_interfaces_ext_mesh))
+    local_dim = max_nibool_interfaces_ext_mesh_wmax &
+              * num_interfaces_ext_mesh_wmax
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                             "", STRINGIFY_VAR(ibool_interfaces_ext_mesh_dummy))
+  endif
+
+  ! anisotropy
+  if( ELASTIC_SIMULATION .and. ANISOTROPY ) then
+    local_dim = NGLLX * NGLLY * NGLLZ * nspec_aniso_wmax
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", STRINGIFY_VAR(c11store))
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", STRINGIFY_VAR(c12store))
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", STRINGIFY_VAR(c13store))
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", STRINGIFY_VAR(c14store))
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", STRINGIFY_VAR(c15store))
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", STRINGIFY_VAR(c16store))
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", STRINGIFY_VAR(c22store))
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", STRINGIFY_VAR(c23store))
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", STRINGIFY_VAR(c24store))
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", STRINGIFY_VAR(c25store))
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", STRINGIFY_VAR(c26store))
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", STRINGIFY_VAR(c33store))
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", STRINGIFY_VAR(c34store))
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", STRINGIFY_VAR(c35store))
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", STRINGIFY_VAR(c36store))
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", STRINGIFY_VAR(c44store))
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", STRINGIFY_VAR(c45store))
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", STRINGIFY_VAR(c46store))
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", STRINGIFY_VAR(c55store))
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", STRINGIFY_VAR(c56store))
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", STRINGIFY_VAR(c66store))
+  endif
+
+  ! inner/outer elements
+  local_dim = nspec_wmax
+  call define_adios_global_array1D(group, groupsize, local_dim, &
+                                   "", STRINGIFY_VAR(ispec_is_inner))
+
+  if( ACOUSTIC_SIMULATION ) then
+    call define_adios_scalar(group, groupsize, "", &
+                             STRINGIFY_VAR(nspec_inner_acoustic))
+    call define_adios_scalar(group, groupsize, "", &
+                             STRINGIFY_VAR(nspec_outer_acoustic))
+    call define_adios_scalar(group, groupsize, "", &
+                             STRINGIFY_VAR(num_phase_ispec_acoustic))
+    if(num_phase_ispec_acoustic > 0 ) then
+      local_dim = num_phase_ispec_acoustic_wmax * 2
+      call define_adios_global_array1D(group, groupsize, local_dim, &
+                                 "", STRINGIFY_VAR(phase_ispec_inner_acoustic))
+    endif
+  endif
+
+  if( ELASTIC_SIMULATION ) then
+    call define_adios_scalar(group, groupsize, "", &
+                             STRINGIFY_VAR(nspec_inner_elastic))
+    call define_adios_scalar(group, groupsize, "", &
+                             STRINGIFY_VAR(nspec_outer_elastic))
+    call define_adios_scalar(group, groupsize, "", &
+                             STRINGIFY_VAR(num_phase_ispec_elastic))
+    if(num_phase_ispec_elastic > 0 ) then
+      local_dim = num_phase_ispec_elastic_wmax * 2
+      call define_adios_global_array1D(group, groupsize, local_dim, &
+                                 "", STRINGIFY_VAR(phase_ispec_inner_elastic))
+    endif
+  endif
+
+  if( POROELASTIC_SIMULATION ) then
+    call define_adios_scalar(group, groupsize, "", &
+                             STRINGIFY_VAR(nspec_inner_poroelastic))
+    call define_adios_scalar(group, groupsize, "", &
+                             STRINGIFY_VAR(nspec_outer_poroelastic))
+    call define_adios_scalar(group, groupsize, "", &
+                             STRINGIFY_VAR(num_phase_ispec_poroelastic))
+    if(num_phase_ispec_poroelastic > 0 ) then
+      local_dim = num_phase_ispec_poroelastic_wmax * 2
+      call define_adios_global_array1D(group, groupsize, local_dim, &
+                              "", STRINGIFY_VAR(phase_ispec_inner_poroelastic))
+    endif
+  endif
+
+  ! mesh coloring
+  if( USE_MESH_COLORING_GPU ) then
+    if( ACOUSTIC_SIMULATION ) then
+      call define_adios_scalar(group, groupsize, "", &
+                               STRINGIFY_VAR(num_colors_outer_acoustic))
+      call define_adios_scalar(group, groupsize, "", &
+                               STRINGIFY_VAR(num_colors_inner_acoustic))
+      local_dim = num_colors_outer_acoustic_wmax &
+                + num_colors_inner_acoustic_wmax
+      call define_adios_global_array1D(group, groupsize, local_dim, &
+                              "", STRINGIFY_VAR(num_elem_colors_acoustic))
+    endif
+    if( ELASTIC_SIMULATION ) then
+      call define_adios_scalar(group, groupsize, "", &
+                               STRINGIFY_VAR(num_colors_outer_elastic))
+      call define_adios_scalar(group, groupsize, "", &
+                               STRINGIFY_VAR(num_colors_inner_elastic))
+      local_dim = num_colors_outer_elastic_wmax &
+                + num_colors_inner_elastic_wmax
+      call define_adios_global_array1D(group, groupsize, local_dim, &
+                              "", STRINGIFY_VAR(num_elem_colors_elastic))
+    endif
+  endif
+
+  !------------------------------------------------------------.
+  ! Open an handler to the ADIOS file and setup the group size |
+  !------------------------------------------------------------'
+  call adios_open(handle, group_name, output_name, "w", &
+                  MPI_COMM_WORLD, ier);
+  call adios_group_size (handle, groupsize, totalsize, ier)
+
+  !------------------------------------------.
+  ! Write previously defined ADIOS variables |
+  !------------------------------------------'
+  call adios_write(handle, STRINGIFY_VAR(nspec), ier) 
+  call adios_write(handle, STRINGIFY_VAR(nglob), ier) 
+
+  local_dim = NGLLX * NGLLY * NGLLZ * nspec_wmax
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   STRINGIFY_VAR(ibool))
+
+  local_dim = nglob_dummy_wmax
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   "x_global", xstore_dummy)
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   "y_global", ystore_dummy)
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   "z_global", zstore_dummy)
+
+  ! this array is needed for acoustic simulations but also for elastic 
+  ! simulations with CPML, thus we allocate it and read it in all cases
+  ! (whether the simulation is acoustic, elastic, or acoustic/elastic)
+  local_dim = NGLLX * NGLLY * NGLLZ * nspec_wmax
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(xixstore))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(xiystore))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(xizstore))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(etaxstore))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(etaystore))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(etazstore))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(gammaxstore))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(gammaystore))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(gammazstore))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(jacobianstore))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(kappastore))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(mustore))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(rhostore))
+
+  local_dim = nspec_wmax
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   STRINGIFY_VAR(ispec_is_acoustic))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   STRINGIFY_VAR(ispec_is_elastic))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   STRINGIFY_VAR(ispec_is_poroelastic))
+
+  ! acoustic
+  if( ACOUSTIC_SIMULATION ) then
+    local_dim = nglob_wmax
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(rmass_acoustic))
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(rmass_acoustic_interface))
+  endif
+
+  ! elastic
+  if( ELASTIC_SIMULATION ) then
+    local_dim = nglob_wmax
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                     local_dim, STRINGIFY_VAR(rmass))
+    if(PML_CONDITIONS)then
+       if(ACOUSTIC_SIMULATION)then
+          local_dim = nglob_wmax
+          call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                           local_dim,                 &
+                                        STRINGIFY_VAR(rmass_elastic_interface))
+       endif
+    endif
+    if( APPROXIMATE_OCEAN_LOAD) then
+      local_dim = nglob_ocean_wmax
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                       STRINGIFY_VAR(rmass_ocean_load))
+    endif
+    !pll Stacey
+    local_dim = NGLLX * NGLLY * NGLLZ * nspec_wmax
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(rho_vp))
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(rho_vs))
+  endif
+
+! poroelastic
+  if( POROELASTIC_SIMULATION ) then
+    local_dim = nglob_wmax
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(rmass_solid_poroelastic))
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(rmass_fluid_poroelastic))
+
+    local_dim = 2 * NGLLX * NGLLY * NGLLZ * nspec_wmax
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(rhoarraystore))
+
+    local_dim = 3 * NGLLX * NGLLY * NGLLZ * nspec_wmax
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(kappaarraystore))
+
+    local_dim = 6 * NGLLX * NGLLY * NGLLZ * nspec_wmax
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(permstore))
+
+    local_dim = NGLLX * NGLLY * NGLLZ * nspec_wmax
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(etastore))
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(tortstore))
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(phistore))
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(rho_vpI))
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(rho_vpII))
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(rho_vsI))
+  endif
+
+! C-PML absorbing boundary conditions
+  if( PML_CONDITIONS ) then
+    call adios_write(handle, STRINGIFY_VAR(nspec_cpml), ier) 
+    call adios_write(handle, STRINGIFY_VAR(CPML_width_x), ier) 
+    call adios_write(handle, STRINGIFY_VAR(CPML_width_y), ier) 
+    call adios_write(handle, STRINGIFY_VAR(CPML_width_z), ier) 
+    if( nspec_cpml > 0 ) then
+      local_dim = nspec_cpml_wmax
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                       STRINGIFY_VAR(CPML_regions))
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                       STRINGIFY_VAR(CPML_to_spec))
+
+      local_dim = nspec_ab_wmax
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                       STRINGIFY_VAR(is_CPML))
+
+      local_dim = NGLLX * NGLLY * NGLLZ * nspec_cpml_wmax
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                       STRINGIFY_VAR(d_store_x))
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                       STRINGIFY_VAR(d_store_y))
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                       STRINGIFY_VAR(d_store_z))
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                       STRINGIFY_VAR(k_store_x))
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                       STRINGIFY_VAR(k_store_y))
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                       STRINGIFY_VAR(k_store_z))
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                       STRINGIFY_VAR(alpha_store))
+      ! -----------------------------------------------------------------------
+      ! for adjoint tomography
+      ! save the array stored the points on interface between PML and interior
+      ! computational domain
+      ! -----------------------------------------------------------------------
+      if((SIMULATION_TYPE == 1 .and. SAVE_FORWARD) &
+          .or. SIMULATION_TYPE == 3) then
+        call adios_write(handle, &
+                         STRINGIFY_VAR(nglob_interface_PML_acoustic), ier) 
+        call adios_write(handle, &
+                         STRINGIFY_VAR(nglob_interface_PML_elastic), ier) 
+        if(nglob_interface_PML_acoustic > 0) then
+          local_dim = nglob_interface_PML_acoustic_wmax
+          call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                          local_dim,                  &
+                                  STRINGIFY_VAR(points_interface_PML_acoustic))
+        endif
+        if(nglob_interface_PML_elastic > 0) then
+          local_dim = nglob_interface_PML_elastic_wmax
+          call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                           local_dim,                 &
+                                  STRINGIFY_VAR(points_interface_PML_elastic))
+        endif
+      endif
+    endif
+  endif
+
+  ! absorbing boundary surface
+  call adios_write(handle, STRINGIFY_VAR(num_abs_boundary_faces), ier) 
+  if(PML_CONDITIONS)then
+    if( num_abs_boundary_faces > 0 ) then
+      local_dim = num_abs_boundary_faces_wmax
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                       local_dim,                 &
+                                       STRINGIFY_VAR(abs_boundary_ispec))
+      local_dim = 3 * NGLLSQUARE * num_abs_boundary_faces_wmax
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                       local_dim,                 &
+                                       STRINGIFY_VAR(abs_boundary_ijk))
+      local_dim = NGLLSQUARE * num_abs_boundary_faces_wmax
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                       local_dim,                 &
+                                       STRINGIFY_VAR(abs_boundary_jacobian2Dw))
+      local_dim = NDIM * NGLLSQUARE * num_abs_boundary_faces_wmax
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                       local_dim,                 &
+                                       STRINGIFY_VAR(abs_boundary_normal))
+    endif
+  else
+    if( num_abs_boundary_faces > 0 ) then
+      local_dim = num_abs_boundary_faces_wmax
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                       local_dim,                 &
+                                       STRINGIFY_VAR(abs_boundary_ispec))
+      local_dim = 3 * NGLLSQUARE * num_abs_boundary_faces_wmax
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                       local_dim,                 &
+                                       STRINGIFY_VAR(abs_boundary_ijk))
+      local_dim = NGLLSQUARE * num_abs_boundary_faces_wmax
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                       local_dim,                 &
+                                       STRINGIFY_VAR(abs_boundary_jacobian2Dw))
+      local_dim = NDIM * NGLLSQUARE * num_abs_boundary_faces_wmax
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                       local_dim,                 &
+                                       STRINGIFY_VAR(abs_boundary_normal))
+      if( STACEY_ABSORBING_CONDITIONS ) then
+        ! store mass matrix contributions
+        if(ELASTIC_SIMULATION ) then
+          local_dim = nglob_xy_wmax
+          call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                           local_dim,                 &
+                                           STRINGIFY_VAR(rmassx))
+          call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                           local_dim,                 &
+                                           STRINGIFY_VAR(rmassy))
+          call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                           local_dim,                 &
+                                           STRINGIFY_VAR(rmassz))
+        endif
+        if(ACOUSTIC_SIMULATION) then
+          local_dim = nglob_xy_wmax
+          call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                           local_dim,                 &
+                                           STRINGIFY_VAR(rmassz_acoustic))
+        endif
+      endif
+    endif
+  endif
+
+  call adios_write(handle, STRINGIFY_VAR(nspec2d_xmin), ier)
+  call adios_write(handle, STRINGIFY_VAR(nspec2d_xmax), ier)
+  call adios_write(handle, STRINGIFY_VAR(nspec2d_ymin), ier)
+  call adios_write(handle, STRINGIFY_VAR(nspec2d_ymax), ier)
+  call adios_write(handle, STRINGIFY_VAR(nspec2d_bottom), ier)
+  call adios_write(handle, STRINGIFY_VAR(nspec2d_top), ier) 
+
+  if (nspec2d_xmin .ne. 0) then
+      local_dim = nspec2d_xmin_wmax 
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                       STRINGIFY_VAR(ibelm_xmin))
+  endif 
+  if (nspec2d_xmax .ne. 0) then
+    local_dim = nspec2d_xmax_wmax 
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(ibelm_xmax))
+  endif 
+  if (nspec2d_ymin .ne. 0) then
+    local_dim = nspec2d_ymin_wmax 
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(ibelm_ymin))
+  endif 
+  if (nspec2d_ymax .ne. 0) then
+    local_dim = nspec2d_ymax_wmax 
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(ibelm_ymax))
+  endif 
+  if (nspec2d_bottom .ne. 0) then
+    local_dim = nspec2d_bottom_wmax 
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(ibelm_bottom))
+  endif 
+  if (nspec2d_top .ne. 0) then
+    local_dim = nspec2d_top_wmax 
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(ibelm_top))
+  endif 
+
+  ! free surface
+  call adios_write(handle, STRINGIFY_VAR(num_free_surface_faces), ier)
+  if( num_free_surface_faces > 0 ) then
+    local_dim = num_free_surface_faces_wmax
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(free_surface_ispec))
+    local_dim = 3 * NGLLSQUARE * num_free_surface_faces_wmax
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(free_surface_ijk))
+    local_dim = NGLLSQUARE * num_free_surface_faces_wmax
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   STRINGIFY_VAR(free_surface_jacobian2Dw))
+    local_dim = NDIM * NGLLSQUARE * num_free_surface_faces_wmax
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(free_surface_normal))
+  endif
+
+  ! acoustic-elastic coupling surface
+  call adios_write(handle, STRINGIFY_VAR(num_coupling_ac_el_faces), ier)
+  if( num_coupling_ac_el_faces > 0 ) then
+    local_dim = num_coupling_ac_el_faces_wmax
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(coupling_ac_el_ispec))
+    local_dim = 3 * NGLLSQUARE * num_coupling_ac_el_faces_wmax
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(coupling_ac_el_ijk))
+    local_dim = NGLLSQUARE * num_coupling_ac_el_faces_wmax
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                STRINGIFY_VAR(coupling_ac_el_jacobian2Dw))
+    local_dim = NDIM * NGLLSQUARE * num_coupling_ac_el_faces_wmax
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(coupling_ac_el_normal))
+  endif
+
+  ! acoustic-poroelastic coupling surface
+  call adios_write(handle, STRINGIFY_VAR(num_coupling_ac_po_faces), ier)
+  if( num_coupling_ac_po_faces > 0 ) then
+    local_dim = num_coupling_ac_po_faces_wmax
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(coupling_ac_po_ispec))
+    local_dim = 3 * NGLLSQUARE * num_coupling_ac_po_faces_wmax
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(coupling_ac_po_ijk))
+    local_dim = NGLLSQUARE * num_coupling_ac_po_faces_wmax
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                  STRINGIFY_VAR(coupling_ac_po_jacobian2Dw))
+    local_dim = NDIM * NGLLSQUARE * num_coupling_ac_po_faces_wmax
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(coupling_ac_po_normal))
+  endif
+
+  ! elastic-poroelastic coupling surface
+  call adios_write(handle, STRINGIFY_VAR(num_coupling_el_po_faces), ier)
+  if( num_coupling_el_po_faces > 0 ) then
+    local_dim = num_coupling_el_po_faces_wmax
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(coupling_el_po_ispec))
+    local_dim = num_coupling_el_po_faces_wmax
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(coupling_po_el_ispec))
+    local_dim = 3 * NGLLSQUARE * num_coupling_el_po_faces_wmax
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(coupling_el_po_ijk))
+    local_dim = 3 * NGLLSQUARE * num_coupling_el_po_faces_wmax
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(coupling_po_el_ijk))
+    local_dim = NGLLSQUARE * num_coupling_el_po_faces_wmax
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                  STRINGIFY_VAR(coupling_el_po_jacobian2Dw))
+    local_dim = NDIM * NGLLSQUARE * num_coupling_el_po_faces_wmax
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(coupling_el_po_normal))
+  endif
+
+  call adios_write(handle, STRINGIFY_VAR(num_interfaces_ext_mesh), ier)
+  if( num_interfaces_ext_mesh > 0 ) then
+    call adios_write(handle, STRINGIFY_VAR(max_nibool_interfaces_ext_mesh), ier)
+    local_dim = num_interfaces_ext_mesh_wmax
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(my_neighbours_ext_mesh))
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                 STRINGIFY_VAR(nibool_interfaces_ext_mesh))
+    local_dim = max_nibool_interfaces_ext_mesh_wmax &
+              * num_interfaces_ext_mesh_wmax
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                             STRINGIFY_VAR(ibool_interfaces_ext_mesh_dummy))
+  endif
+
+! anisotropy
+  if( ELASTIC_SIMULATION .and. ANISOTROPY ) then
+    local_dim = NGLLX * NGLLY * NGLLZ * nspec_aniso_wmax
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(c11store))
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(c12store))
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(c13store))
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(c14store))
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(c15store))
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(c16store))
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(c22store))
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(c23store))
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(c24store))
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(c25store))
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(c26store))
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(c33store))
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(c34store))
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(c35store))
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(c36store))
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(c44store))
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(c45store))
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(c46store))
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(c55store))
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(c56store))
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(c66store))
+  endif
+
+  ! inner/outer elements
+  local_dim = nspec_wmax
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   STRINGIFY_VAR(ispec_is_inner))
+
+  if( ACOUSTIC_SIMULATION ) then
+    call adios_write(handle, STRINGIFY_VAR(nspec_inner_acoustic), ier)
+    call adios_write(handle, STRINGIFY_VAR(nspec_outer_acoustic), ier)
+    call adios_write(handle, STRINGIFY_VAR(num_phase_ispec_acoustic), ier)
+    if(num_phase_ispec_acoustic > 0 ) then
+      local_dim = num_phase_ispec_acoustic_wmax * 2
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                 STRINGIFY_VAR(phase_ispec_inner_acoustic))
+    endif
+  endif
+
+  if( ELASTIC_SIMULATION ) then
+    call adios_write(handle, STRINGIFY_VAR(nspec_inner_elastic), ier)
+    call adios_write(handle, STRINGIFY_VAR(nspec_outer_elastic), ier)
+    call adios_write(handle, STRINGIFY_VAR(num_phase_ispec_elastic), ier)
+    if(num_phase_ispec_elastic > 0 ) then
+      local_dim = num_phase_ispec_elastic_wmax * 2
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                 STRINGIFY_VAR(phase_ispec_inner_elastic))
+    endif
+  endif
+
+  if( POROELASTIC_SIMULATION ) then
+    call adios_write(handle, STRINGIFY_VAR(nspec_inner_poroelastic), ier)
+    call adios_write(handle, STRINGIFY_VAR(nspec_outer_poroelastic), ier)
+    call adios_write(handle, STRINGIFY_VAR(num_phase_ispec_poroelastic), ier)
+    if(num_phase_ispec_poroelastic > 0 ) then
+      local_dim = num_phase_ispec_poroelastic_wmax * 2
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                              STRINGIFY_VAR(phase_ispec_inner_poroelastic))
+    endif
+  endif
+
+  ! mesh coloring
+  if( USE_MESH_COLORING_GPU ) then
+    if( ACOUSTIC_SIMULATION ) then
+      call adios_write(handle, STRINGIFY_VAR(num_colors_outer_acoustic), ier)
+      call adios_write(handle, STRINGIFY_VAR(num_colors_inner_acoustic), ier)
+      local_dim = num_colors_outer_acoustic_wmax &
+                + num_colors_inner_acoustic_wmax
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                              STRINGIFY_VAR(num_elem_colors_acoustic))
+    endif
+    if( ELASTIC_SIMULATION ) then
+      call adios_write(handle, STRINGIFY_VAR(num_colors_outer_elastic), ier)
+      call adios_write(handle, STRINGIFY_VAR(num_colors_inner_elastic), ier)
+      local_dim = num_colors_outer_elastic_wmax &
+                + num_colors_inner_elastic_wmax
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                              STRINGIFY_VAR(num_elem_colors_elastic))
+    endif
+  endif
+
+  !----------------------------------.
+  ! Perform the actual write to disk |
+  !----------------------------------'
+  call adios_set_path(handle, "", ier)                          
+  call adios_close(handle, ier)
+
+  ! stores arrays in binary files
+  if( SAVE_MESH_FILES ) then
+    call save_arrays_solver_files_adios(nspec,nglob,ibool, nspec_wmax, &
+                                        nglob_wmax)
+
+    ! debug: saves 1. MPI interface
+    !if( num_interfaces_ext_mesh >= 1 ) then
+    !  filename = prname(1:len_trim(prname))//'MPI_1_points'
+    !  call write_VTK_data_points(nglob, &
+    !                    xstore_dummy,ystore_dummy,zstore_dummy, &
+    !                    ibool_interfaces_ext_mesh_dummy(1:nibool_interfaces_ext_mesh(1),1), &
+    !                    nibool_interfaces_ext_mesh(1), &
+    !                    filename)
+    !endif
+  endif
+
+  ! cleanup
+  deallocate(ibool_interfaces_ext_mesh_dummy,stat=ier)
+  if( ier /= 0 ) stop 'error deallocating array ibool_interfaces_ext_mesh_dummy'
+
+  if( nspec_cpml_tot > 0 ) then
+     deallocate(CPML_to_spec,stat=ier); if( ier /= 0 ) stop 'error deallocating array CPML_to_spec'
+     deallocate(CPML_regions,stat=ier); if( ier /= 0 ) stop 'error deallocating array CPML_regions'
+     deallocate(is_CPML,stat=ier); if( ier /= 0 ) stop 'error deallocating array is_CPML'
+  endif
+
+  if( PML_CONDITIONS ) then
+     deallocate(d_store_x,stat=ier); if( ier /= 0 ) stop 'error deallocating array d_store_x'
+     deallocate(d_store_y,stat=ier); if( ier /= 0 ) stop 'error deallocating array d_store_y'
+     deallocate(d_store_z,stat=ier); if( ier /= 0 ) stop 'error deallocating array d_store_z'
+     deallocate(k_store_x,stat=ier); if( ier /= 0 ) stop 'error deallocating array d_store_x'
+     deallocate(k_store_y,stat=ier); if( ier /= 0 ) stop 'error deallocating array d_store_y'
+     deallocate(k_store_z,stat=ier); if( ier /= 0 ) stop 'error deallocating array d_store_z'
+     deallocate(alpha_store,stat=ier); if( ier /= 0 ) stop 'error deallocating array alpha_store'
+     if((SIMULATION_TYPE == 1 .and. SAVE_FORWARD) .or. SIMULATION_TYPE == 3) then
+       deallocate(mask_ibool_interior_domain,stat=ier)
+       if(ier /= 0) stop 'error deallocating array mask_ibool_interior_domain'
+
+       if(nglob_interface_PML_acoustic > 0) then
+         deallocate(points_interface_PML_acoustic,stat=ier)
+         if( ier /= 0 ) stop 'error deallocating array points_interface_PML_acoustic'
+       endif
+
+       if(nglob_interface_PML_elastic > 0) then
+         deallocate(points_interface_PML_elastic,stat=ier)
+         if( ier /= 0 ) stop 'error deallocating array points_interface_PML_elastic'
+       endif
+     endif
+  endif
+
+end subroutine save_arrays_solver_ext_mesh_adios
+
+
+!------------------------------------------------------------------------------
+
+subroutine save_arrays_solver_files_adios(nspec,nglob,ibool, nspec_wmax, &
+                                          nglob_wmax)
+
+  use mpi                                          
+  use generate_databases_par, only: myrank, LOCAL_PATH,     &
+                                    xstore, ystore, zstore, &
+                                    sizeprocs
+  use create_regions_mesh_ext_par
+  use adios_helpers_mod
+
+  implicit none
+
+  integer :: nspec, nglob
+  integer :: nspec_wmax, nglob_wmax
+  ! mesh coordinates
+  integer, dimension(NGLLX,NGLLY,NGLLZ,nspec) :: ibool
+
+  ! local parameters
+  real(kind=CUSTOM_REAL), dimension(:,:,:,:), allocatable :: vp_tmp, &
+                                                             vs_tmp, rho_tmp
+  integer :: ier
+  integer, dimension(:), allocatable :: iglob_tmp
+
+  !--- Local parameters for ADIOS ---
+  character(len=256) :: output_name
+  integer(kind=8) :: group, handle
+  integer(kind=8) :: groupsize, totalsize
+  integer :: local_dim
+  character(len=64), parameter :: group_name_coords  = "SPECFEM3D_MESH_COORDS"
+  character(len=64), parameter :: group_name_values = "SPECFEM3D_MODEL_VALUES"
+
+  if( myrank == 0) then
+    write(IMAIN,*) '     saving mesh files for VisIt. ADIOS format'
+    call flush_IMAIN()
+  endif
+
+#if 1
+  !-----------------------------------.
+  ! Setup ADIOS for the current group |
+  !-----------------------------------'
+  groupsize = 0
+  output_name = LOCAL_PATH(1:len_trim(LOCAL_PATH)) // "/mesh_coordinates.bp"
+  call adios_declare_group(group, group_name_coords, "", 1, ier)
+  call adios_select_method(group, ADIOS_TRANSPORT_METHOD, "", "", ier)
+
+  !------------------------.
+  ! Define ADIOS Variables |
+  !------------------------'
+  call define_adios_scalar(group, groupsize, "", STRINGIFY_VAR(ngllx)) 
+  call define_adios_scalar(group, groupsize, "", STRINGIFY_VAR(nglly)) 
+  call define_adios_scalar(group, groupsize, "", STRINGIFY_VAR(ngllz)) 
+
+  call define_adios_scalar(group, groupsize, "", STRINGIFY_VAR(nspec)) 
+  call define_adios_scalar(group, groupsize, "", STRINGIFY_VAR(nglob)) 
+
+  local_dim = nglob_wmax
+  call define_adios_global_array1D(group, groupsize, local_dim, &
+                                   "", "x_global", xstore_dummy)
+  call define_adios_global_array1D(group, groupsize, local_dim, &
+                                   "", "y_global", ystore_dummy)
+  call define_adios_global_array1D(group, groupsize, local_dim, &
+                                   "", "z_global", zstore_dummy)
+
+  local_dim = NGLLX * NGLLY * NGLLZ * nspec_wmax 
+  call define_adios_global_array1D(group, groupsize, local_dim, &
+                                   "", STRINGIFY_VAR(xstore))
+  call define_adios_global_array1D(group, groupsize, local_dim, &
+                                   "", STRINGIFY_VAR(ystore))
+  call define_adios_global_array1D(group, groupsize, local_dim, &
+                                   "", STRINGIFY_VAR(zstore))
+
+  local_dim = NGLLX * NGLLY * NGLLZ * nspec_wmax
+  call define_adios_global_array1D(group, groupsize, local_dim, &
+                                   "", STRINGIFY_VAR(ibool))
+
+  !------------------------------------------------------------.
+  ! Open an handler to the ADIOS file and setup the group size |
+  !------------------------------------------------------------'
+  call adios_open(handle, group_name_coords, output_name, "w", &
+                  MPI_COMM_WORLD, ier);
+  call adios_group_size (handle, groupsize, totalsize, ier)
+
+  !------------------------------------------.
+  ! Write previously defined ADIOS variables |
+  !------------------------------------------'
+  call adios_write(handle, STRINGIFY_VAR(ngllx), ier) 
+  call adios_write(handle, STRINGIFY_VAR(nglly), ier) 
+  call adios_write(handle, STRINGIFY_VAR(ngllz), ier) 
+
+  call adios_write(handle, STRINGIFY_VAR(nspec), ier) 
+  call adios_write(handle, STRINGIFY_VAR(nglob), ier) 
+
+  local_dim = nglob_wmax
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   "x_global", xstore_dummy)
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   "y_global", ystore_dummy)
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   "z_global", zstore_dummy)
+
+  local_dim = NGLLX * NGLLY * NGLLZ * nspec_wmax
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   STRINGIFY_VAR(xstore))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   STRINGIFY_VAR(ystore))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   STRINGIFY_VAR(zstore))
+
+  local_dim = NGLLX * NGLLY * NGLLZ * nspec_wmax
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   STRINGIFY_VAR(ibool))
+
+  !----------------------------------.
+  ! Perform the actual write to disk |
+  !----------------------------------'
+  call adios_set_path(handle, "", ier)                          
+  call adios_close(handle, ier)
+#endif  
+#if 1
+  !----------------------------------.
+  ! Set up the model values to write |
+  !----------------------------------'
+  allocate( vp_tmp(NGLLX,NGLLY,NGLLZ,nspec), stat=ier); if( ier /= 0 ) stop 'error allocating array '
+  allocate( vs_tmp(NGLLX,NGLLY,NGLLZ,nspec), stat=ier); if( ier /= 0 ) stop 'error allocating array '
+  allocate( rho_tmp(NGLLX,NGLLY,NGLLZ,nspec), stat=ier); if( ier /= 0 ) stop 'error allocating array '
+  ! vp (for checking the mesh and model)
+  !minimum = minval( abs(rho_vp) )
+  !if( minimum(1) /= 0.0 ) then
+  !  vp_tmp = (FOUR_THIRDS * mustore + kappastore) / rho_vp
+  !else
+  !  vp_tmp = 0.0
+  !endif
+  vp_tmp = 0.0
+  where( rho_vp /= 0._CUSTOM_REAL ) vp_tmp = (FOUR_THIRDS * mustore + kappastore) / rho_vp
+  ! vs (for checking the mesh and model)
+  !minimum = minval( abs(rho_vs) )
+  !if( minimum(1) /= 0.0 ) then
+  !  vs_tmp = mustore / rho_vs
+  !else
+  !  vs_tmp = 0.0
+  !endif
+  vs_tmp = 0.0
+  where( rho_vs /= 0._CUSTOM_REAL )  vs_tmp = mustore / rho_vs
+  ! outputs density model for check
+  rho_tmp = 0.0
+  where( rho_vp /= 0._CUSTOM_REAL ) rho_tmp = rho_vp**2 / (FOUR_THIRDS * mustore + kappastore)
+
+  !-----------------------------------.
+  ! Setup ADIOS for the current group |
+  !-----------------------------------'
+  groupsize = 0
+  output_name = LOCAL_PATH(1:len_trim(LOCAL_PATH)) // "/model_values.bp"
+  call adios_declare_group(group, group_name_values, "", 1, ier)
+  call adios_select_method(group, ADIOS_TRANSPORT_METHOD, "", "", ier)
+
+  !------------------------.
+  ! Define ADIOS Variables |
+  !------------------------'
+  call define_adios_scalar(group, groupsize, "", STRINGIFY_VAR(ngllx)) 
+  call define_adios_scalar(group, groupsize, "", STRINGIFY_VAR(nglly)) 
+  call define_adios_scalar(group, groupsize, "", STRINGIFY_VAR(ngllz)) 
+
+  call define_adios_scalar(group, groupsize, "", STRINGIFY_VAR(nspec)) 
+  call define_adios_scalar(group, groupsize, "", STRINGIFY_VAR(nglob)) 
+
+  local_dim = NGLLX * NGLLY * NGLLZ * nspec_wmax
+  call define_adios_global_array1D(group, groupsize, local_dim, &
+                                   "", "vp", vp_tmp)
+  call define_adios_global_array1D(group, groupsize, local_dim, &
+                                   "", "vs", vs_tmp)
+  call define_adios_global_array1D(group, groupsize, local_dim, &
+                                   "", "rho", rho_tmp)
+
+  !------------------------------------------------------------.
+  ! Open an handler to the ADIOS file and setup the group size |
+  !------------------------------------------------------------'
+  call adios_open(handle, group_name_values, output_name, "w", &
+                  MPI_COMM_WORLD, ier);
+  call adios_group_size (handle, groupsize, totalsize, ier)
+
+  !------------------------------------------.
+  ! Write previously defined ADIOS variables |
+  !------------------------------------------'
+  call adios_write(handle, STRINGIFY_VAR(ngllx), ier) 
+  call adios_write(handle, STRINGIFY_VAR(nglly), ier) 
+  call adios_write(handle, STRINGIFY_VAR(ngllz), ier) 
+
+  call adios_write(handle, STRINGIFY_VAR(nspec), ier) 
+  call adios_write(handle, STRINGIFY_VAR(nglob), ier) 
+
+  local_dim = NGLLX * NGLLY * NGLLZ * nspec_wmax
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   "vp", vp_tmp)
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   "vs", vs_tmp)
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   "rho", rho_tmp)
+
+  !----------------------------------.
+  ! Perform the actual write to disk |
+  !----------------------------------'
+  call adios_set_path(handle, "", ier)                          
+  call adios_close(handle, ier)
+
+  deallocate(vp_tmp)
+  deallocate(vs_tmp)
+  deallocate(rho_tmp)
+#endif
+
+end subroutine save_arrays_solver_files_adios

Added: seismo/3D/SPECFEM3D/trunk/src/generate_databases/save_moho_adios.F90
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/generate_databases/save_moho_adios.F90	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/src/generate_databases/save_moho_adios.F90	2013-09-18 14:35:14 UTC (rev 22798)
@@ -0,0 +1,178 @@
+!=====================================================================
+!
+!               S p e c f e m 3 D  V e r s i o n  2 . 1
+!               ---------------------------------------
+!
+!          Main authors: Dimitri Komatitsch and Jeroen Tromp
+!    Princeton University, USA and CNRS / INRIA / University of Pau
+! (c) Princeton University / California Institute of Technology and CNRS / INRIA / University of Pau
+!                             July 2012
+!
+! This 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 02110-1301 USA.
+!
+!=====================================================================
+
+!==============================================================================
+!> \file save_arrays_solver_adios.F90
+!!
+!! \author MPBL
+!==============================================================================
+
+!==============================================================================
+!> \def STRINGIFY_VAR(a)
+!! Macro taking a variable and returning the stringified variable and 
+!! the variable itself.
+!! STRINGIFY_VAR(x) expand as:
+!!   "x", x
+!! x being the variable name inside the code.
+#ifdef __INTEL_COMPILER
+#define STRINGIFY_VAR(a) #a, a
+#else
+#define STRINGIFY_VAR(a) "a", a
+#endif
+
+!==============================================================================
+!> Save Moho informtaion using ADIOS
+subroutine crm_save_moho_adios()
+
+  use mpi
+  use adios_helpers_mod
+  use generate_databases_par, only : myrank, sizeprocs, LOCAL_PATH, &
+                                     NSPEC_AB
+  use create_regions_mesh_ext_par
+
+  implicit none
+
+  ! local parameters
+  integer :: ier
+
+  !--- Local parameters for ADIOS ---
+  character(len=256) :: output_name
+  character(len=64), parameter :: group_name  = "SPECFEM3D_MOHO"
+  integer(kind=8) :: group, handle
+  integer(kind=8) :: groupsize, totalsize
+  integer :: local_dim
+
+  !--- Variables to allreduce - wmax stands for world_max
+  integer :: nspec_wmax, nspec2d_moho_wmax
+
+  integer, parameter :: num_vars = 2
+  integer, dimension(num_vars) :: max_global_values
+
+  !-----------------------------------------------------------------.
+  ! Get maximum value for each variable used to define a local_dim. |
+  ! ADIOS write equally sized chunks for each processor.            |
+  !-----------------------------------------------------------------'
+  ! Filling a temporary array to avoid doing allreduces for each var.
+  max_global_values(1) = nspec_ab
+  max_global_values(2) = nspec2d_moho 
+
+  call MPI_Allreduce(MPI_IN_PLACE, max_global_values, num_vars, &
+                     MPI_INTEGER, MPI_MAX, MPI_COMM_WORLD, ier)
+  if( ier /= 0 ) call exit_MPI(myrank,'Allreduce to get max values failed.')
+
+  nspec_wmax        = max_global_values(1)
+  nspec2d_moho_wmax = max_global_values(2)
+
+  !-----------------------------------.
+  ! Setup ADIOS for the current group |
+  !-----------------------------------'
+  groupsize = 0
+  output_name = LOCAL_PATH(1:len_trim(LOCAL_PATH)) // "/moho.bp"
+  call adios_declare_group(group, group_name, "", 1, ier)
+  call adios_select_method(group, ADIOS_TRANSPORT_METHOD, "", "", ier)
+
+  !------------------------.
+  ! Define ADIOS Variables |
+  !------------------------'
+  call define_adios_scalar(group, groupsize, "", "nspec", NSPEC_AB) 
+  call define_adios_scalar(group, groupsize, "", STRINGIFY_VAR(nspec2d_moho)) 
+
+  local_dim = nspec2d_moho_wmax
+  call define_adios_global_array1D(group, groupsize, &
+                                   local_dim, "",    &
+                                   STRINGIFY_VAR(ibelm_moho_top))
+  call define_adios_global_array1D(group, groupsize, &
+                                   local_dim, "",    &
+                                   STRINGIFY_VAR(ibelm_moho_bot))
+
+  local_dim = 3 * NGLLSQUARE * nspec2d_moho_wmax
+  call define_adios_global_array1D(group, groupsize, &
+                                   local_dim, "",    &
+                                   STRINGIFY_VAR(ijk_moho_top))
+  call define_adios_global_array1D(group, groupsize, &
+                                   local_dim, "",    &
+                                   STRINGIFY_VAR(ijk_moho_bot))
+
+  local_dim = NDIM * NGLLSQUARE * nspec2d_moho_wmax
+  call define_adios_global_array1D(group, groupsize, &
+                                   local_dim, "",    &
+                                   STRINGIFY_VAR(normal_moho_top))
+  call define_adios_global_array1D(group, groupsize, &
+                                   local_dim, "",    &
+                                   STRINGIFY_VAR(normal_moho_bot))
+
+  local_dim = nspec_wmax
+  call define_adios_global_array1D(group, groupsize, &
+                                   local_dim, "",    &
+                                   STRINGIFY_VAR(is_moho_top))
+  call define_adios_global_array1D(group, groupsize, &
+                                   local_dim, "",    &
+                                   STRINGIFY_VAR(is_moho_bot))
+
+  !------------------------------------------------------------.
+  ! Open an handler to the ADIOS file and setup the group size |
+  !------------------------------------------------------------'
+  call adios_open(handle, group_name, output_name, "w", &
+                  MPI_COMM_WORLD, ier);
+  call adios_group_size (handle, groupsize, totalsize, ier)
+
+  !------------------------------------------.
+  ! Write previously defined ADIOS variables |
+  !------------------------------------------'
+  call adios_write(handle, "nspec", NSPEC_AB, ier) 
+  call adios_write(handle, STRINGIFY_VAR(nspec2d_moho), ier) 
+
+  local_dim = nspec2d_moho_wmax
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(ibelm_moho_top))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(ibelm_moho_bot))
+  
+  local_dim = 3 * NGLLSQUARE * nspec2d_moho_wmax
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(ijk_moho_top))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(ijk_moho_bot))
+
+  local_dim = NDIM * NGLLSQUARE * nspec2d_moho_wmax
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(normal_moho_top))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(normal_moho_bot))
+
+  local_dim = nspec_wmax
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(is_moho_top))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(is_moho_bot))
+
+  !----------------------------------.
+  ! Perform the actual write to disk |
+  !----------------------------------'
+  call adios_set_path(handle, "", ier)                          
+  call adios_close(handle, ier)
+end subroutine crm_save_moho_adios
+

Modified: seismo/3D/SPECFEM3D/trunk/src/meshfem3D/Makefile.in
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/meshfem3D/Makefile.in	2013-09-17 22:36:21 UTC (rev 22797)
+++ seismo/3D/SPECFEM3D/trunk/src/meshfem3D/Makefile.in	2013-09-18 14:35:14 UTC (rev 22798)
@@ -44,8 +44,17 @@
 FLAGS_CHECK = @FLAGS_CHECK@
 FCFLAGS_f90 = @FCFLAGS_f90@
 
-FCCOMPILE_CHECK =@FCENV@ ${FC} ${FCFLAGS} $(FLAGS_CHECK) -I${SHARED}
-MPIFCCOMPILE_CHECK =@FCENV@ ${MPIFC} ${FCFLAGS} $(FLAGS_CHECK) -I${SHARED}
+# ADIOS
+# with configure: ./configure --with-adios ADIOS_LIB=.. ADIOS_INC=.. MPI_INC=..
+ at COND_ADIOS_TRUE@ADIOS_LIBS = -ladiosf -lmxml
+ at COND_ADIOS_FALSE@ADIOS_LIBS = 
+
+ADIOS_LIB_LOCATION = @ADIOS_LIB@ @MXML_LIB@
+ADIOS_LINK = $(ADIOS_LIB_LOCATION) $(ADIOS_LIBS)
+ADIOS_INC = @ADIOS_INC@ -I../../setup -I../../ 
+
+FCCOMPILE_CHECK =@FCENV@ ${FC} ${FCFLAGS} $(FLAGS_CHECK) -I${SHARED} ${ADIOS_LINK}
+MPIFCCOMPILE_CHECK =@FCENV@ ${MPIFC} ${FCFLAGS} $(FLAGS_CHECK) -I${SHARED} ${ADIOS_LINK}
 @COND_MPI_TRUE at FCLINK = $(MPIFCCOMPILE_CHECK)
 @COND_MPI_FALSE at FCLINK = $(FCCOMPILE_CHECK)
 
@@ -79,6 +88,7 @@
 @COND_PYRE_FALSE at COND_PYRE_OBJECTS = $O/read_value_mesh_parameters.o $O/get_value_parameters.o
 
 libmeshfem_a_OBJECTS = \
+	$O/safe_alloc_mod.shared.o \
 	$O/store_coords.o \
 	$O/read_mesh_parameter_file.o \
 	$O/check_mesh_quality.o \
@@ -107,6 +117,23 @@
 	$O/utm_geo.o \
 	$(EMPTY_MACRO)
 
+# using ADIOS files
+ADIOS_PREOBJECTS= \
+	$O/adios_manager.shared_adios.o  \
+	$O/adios_helpers_definitions.shared_adios.o  \
+	$O/adios_helpers_writers.shared_adios.o  \
+	$O/adios_helpers.shared_adios.o
+ADIOS_OBJECTS= \
+	$O/save_databases_adios.adios.o 
+
+ADIOS_STUBS = \
+	$O/adios_manager_stubs.shared_noadios.o \
+	$O/meshfem3D_adios_stubs.noadios.o
+
+ at COND_ADIOS_FALSE@ADIOS_OBJECTS = $(ADIOS_STUBS)
+ at COND_ADIOS_FALSE@ADIOS_PREOBJECTS =
+
+
 # objects toggled between the parallel and serial version
 @COND_MPI_TRUE at COND_MPI_OBJECTS = $O/parallel.o
 @COND_MPI_FALSE at COND_MPI_OBJECTS = $O/serial.o
@@ -114,7 +141,7 @@
 LIBMESHFEM = $(COND_PYRE_OBJECTS) $L/libmeshfem.a
 
 # objects for the pure Fortran version
- at COND_PYRE_FALSE@XMESHFEM_OBJECTS = $O/program_meshfem3D.o $(LIBMESHFEM)
+ at COND_PYRE_FALSE@XMESHFEM_OBJECTS = $(ADIOS_PREOBJECTS) $O/program_meshfem3D.o $(LIBMESHFEM) $(ADIOS_OBJECTS)
 
 ####
 #### targets
@@ -142,7 +169,7 @@
 
 # rules for the pure Fortran version
 @COND_PYRE_FALSE at xmeshfem3D: $(XMESHFEM_OBJECTS) $(COND_MPI_OBJECTS)
- at COND_PYRE_FALSE@	${FCLINK} -o ${E}/xmeshfem3D $(XMESHFEM_OBJECTS) $(COND_MPI_OBJECTS) $(MPILIBS)
+ at COND_PYRE_FALSE@	${FCLINK} -o ${E}/xmeshfem3D $(XMESHFEM_OBJECTS) $(COND_MPI_OBJECTS) $(MPILIBS) ${ADIOS_LIBS} ${O}/safe_alloc_mod.shared.o
 @COND_PYRE_FALSE@
 @COND_PYRE_FALSE@# solver also depends on values from mesher
 
@@ -163,13 +190,42 @@
 ####
 #### rule to build each .o file below
 ####
+#######################################
 
 ###
+### ADIOS compilation
+###
+
+$O/%.adios.o: %.F90 ${SHARED}constants.h
+	${MPIFCCOMPILE_CHECK} -c $(ADIOS_INC) $(FCFLAGS) $(MPI_INC) -o $@ $<
+
+$O/%.adios.o: %.f90 ${SHARED}constants.h
+	${MPIFCCOMPILE_CHECK} -c $(ADIOS_INC) $(FCFLAGS) $(MPI_INC) -o $@ $<
+
+$O/%.noadios.o: %.F90 
+	${FC} -c -o $@ $<
+
+$O/%.noadios.o: %.f90
+	${FC} -c -o $@ $<
+
+$O/%.shared_noadios.o: ${SHARED}/%.f90 .FORCE
+	${MPIFC} -c -o $@ $<
+
+$O/%.shared_adios.o: ${SHARED}/%.f90 ${SHARED}/constants.h .FORCE
+	${MPIFC} -c $(ADIOS_INC) $(FCFLAGS) $(MPI_INC) -o $@ $<
+
+$O/%.shared_adios.o: ${SHARED}/%.F90 ${SHARED}/constants.h .FORCE
+	${MPIFC} -c $(ADIOS_INC) $(FCFLAGS) $(MPI_INC) -o $@ $<
+
+.FORCE:
+
+#######################################
+###
 ### not optimized flags (not dependent on values from mesher anymore)
 ###
 
-$O/%.shared.o: $(SHARED)%.f90 $(SHARED)constants.h
-	${FCCOMPILE_CHECK} -c -o $@ $<
+$O/%.shared.o: $(SHARED)%.f90 $(SHARED)constants.h .FORCE
+	${MPIFCCOMPILE_CHECK} -c -o $@ $<
 
 ###
 ### C compilation
@@ -250,7 +306,7 @@
 	${FCCOMPILE_CHECK} -c -o $O/read_topo_bathy_file.o ${SHARED}/read_topo_bathy_file.f90
 
 $O/create_regions_mesh.o: ${SHARED}constants.h create_regions_mesh.f90
-	${FCCOMPILE_CHECK} -c -o $O/create_regions_mesh.o create_regions_mesh.f90
+	${MPIFCCOMPILE_CHECK} -c -o $O/create_regions_mesh.o create_regions_mesh.f90
 
 $O/create_name_database.o: ${SHARED}constants.h create_name_database.f90
 	${FCCOMPILE_CHECK} -c -o $O/create_name_database.o create_name_database.f90

Modified: seismo/3D/SPECFEM3D/trunk/src/meshfem3D/create_regions_mesh.f90
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/meshfem3D/create_regions_mesh.f90	2013-09-17 22:36:21 UTC (rev 22797)
+++ seismo/3D/SPECFEM3D/trunk/src/meshfem3D/create_regions_mesh.f90	2013-09-18 14:35:14 UTC (rev 22798)
@@ -34,11 +34,15 @@
                                NSPEC2DMAX_XMIN_XMAX,NSPEC2DMAX_YMIN_YMAX,NSPEC2D_BOTTOM,NSPEC2D_TOP, &
                                NPROC_XI,NPROC_ETA, &
                                nsubregions,subregions,nblayers,ner_layer,NMATERIALS,material_properties, &
-                               myrank,LOCAL_PATH,UTM_X_MIN,UTM_X_MAX,UTM_Y_MIN,UTM_Y_MAX,Z_DEPTH_BLOCK, &
+                               myrank, sizeprocs, &
+							   LOCAL_PATH,UTM_X_MIN,UTM_X_MAX,UTM_Y_MIN,UTM_Y_MAX,Z_DEPTH_BLOCK, &
                                CREATE_ABAQUS_FILES,CREATE_DX_FILES,CREATE_VTK_FILES, &
-                               USE_REGULAR_MESH,NDOUBLINGS,ner_doublings)
+                               USE_REGULAR_MESH,NDOUBLINGS,ner_doublings, &
+                               ADIOS_ENABLED, ADIOS_FOR_DATABASES)
 
     ! create the different regions of the mesh
+  use adios_manager_mod
+  use mpi
 
     implicit none
 
@@ -58,6 +62,7 @@
 
     logical USE_REGULAR_MESH
     logical CREATE_ABAQUS_FILES,CREATE_DX_FILES,CREATE_VTK_FILES
+    logical ADIOS_ENABLED, ADIOS_FOR_DATABASES
 
     integer NDOUBLINGS
     integer, dimension(2) :: ner_doublings
@@ -114,7 +119,7 @@
     logical, dimension(:,:), allocatable :: iboun
 
     ! proc numbers for MPI
-    integer myrank
+    integer myrank, sizeprocs
 
     ! variables for creating array ibool (some arrays also used for AVS or DX files)
     integer, dimension(:), allocatable :: iglob,locval
@@ -468,6 +473,11 @@
        call exit_MPI(myrank,'incorrect global ibool numbering')
     endif
 
+    !--- Initialize ADIOS and setup the buffer size
+    if (ADIOS_ENABLED) then
+      call adios_setup()
+    endif
+
     ! outputs mesh file for visualization
     call create_visual_files(CREATE_ABAQUS_FILES,CREATE_DX_FILES,CREATE_VTK_FILES, &
                             nspec,nglob, &
@@ -486,6 +496,17 @@
                           nodes_coords(:,1),nodes_coords(:,2),nodes_coords(:,3),ibool, &
                           CREATE_VTK_FILES,prname)
 
+  ! saves mesh as databases file
+  if (ADIOS_FOR_DATABASES) then 
+    call save_databases_adios(LOCAL_PATH, myrank, sizeprocs, &
+       nspec,nglob,iproc_xi,iproc_eta, &
+       NPROC_XI,NPROC_ETA,addressing,iMPIcut_xi,iMPIcut_eta,&
+       ibool,nodes_coords,true_material_num, &
+       nspec2D_xmin,nspec2D_xmax,nspec2D_ymin,nspec2D_ymax, &
+       NSPEC2D_BOTTOM,NSPEC2D_TOP, NSPEC2DMAX_XMIN_XMAX,NSPEC2DMAX_YMIN_YMAX, &
+       ibelm_xmin,ibelm_xmax,ibelm_ymin,ibelm_ymax,ibelm_bottom,ibelm_top,&
+       NMATERIALS,material_properties)
+  else
     ! saves mesh as databases file
     call save_databases(prname,nspec,nglob,iproc_xi,iproc_eta, &
                       NPROC_XI,NPROC_ETA,addressing,iMPIcut_xi,iMPIcut_eta,&
@@ -494,7 +515,13 @@
                       NSPEC2DMAX_XMIN_XMAX,NSPEC2DMAX_YMIN_YMAX, &
                       ibelm_xmin,ibelm_xmax,ibelm_ymin,ibelm_ymax,ibelm_bottom,ibelm_top,&
                       NMATERIALS,material_properties)
+  endif
 
+    !--- Clean ADIOS. Make sure everything is already written
+    if (ADIOS_ENABLED) then
+      call adios_cleanup()
+    endif
+
   end subroutine create_regions_mesh
 
 end module createRegMesh

Modified: seismo/3D/SPECFEM3D/trunk/src/meshfem3D/meshfem3D.f90
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/meshfem3D/meshfem3D.f90	2013-09-17 22:36:21 UTC (rev 22797)
+++ seismo/3D/SPECFEM3D/trunk/src/meshfem3D/meshfem3D.f90	2013-09-18 14:35:14 UTC (rev 22798)
@@ -345,6 +345,8 @@
   logical PML_CONDITIONS,PML_INSTEAD_OF_FREE_SURFACE,FULL_ATTENUATION_SOLID
   integer MOVIE_TYPE,IMODEL
   character(len=256) OUTPUT_FILES,LOCAL_PATH,TOMOGRAPHY_PATH,TRAC_PATH
+  logical :: ADIOS_ENABLED, ADIOS_FOR_DATABASES, ADIOS_FOR_MESH, &
+             ADIOS_FOR_KERNELS
 
 ! ************** PROGRAM STARTS HERE **************
 
@@ -387,6 +389,9 @@
                         USE_RICKER_TIME_FUNCTION,OLSEN_ATTENUATION_RATIO,PML_CONDITIONS, &
                         PML_INSTEAD_OF_FREE_SURFACE,f0_FOR_PML,IMODEL,FULL_ATTENUATION_SOLID,TRAC_PATH)
 
+  call read_adios_parameters(ADIOS_ENABLED, ADIOS_FOR_DATABASES, &
+                             ADIOS_FOR_MESH, ADIOS_FOR_KERNELS)
+
 ! read the mesh parameter file
 ! nullify(subregions,material_properties)
   call read_mesh_parameter_file(LATITUDE_MIN,LATITUDE_MAX,LONGITUDE_MIN,LONGITUDE_MAX, &
@@ -815,9 +820,11 @@
                          NSPEC2DMAX_XMIN_XMAX,NSPEC2DMAX_YMIN_YMAX,NSPEC2D_BOTTOM,NSPEC2D_TOP, &
                          NPROC_XI,NPROC_ETA, &
                          NSUBREGIONS,subregions,number_of_layers,ner_layer,NMATERIALS,material_properties, &
-                         myrank,LOCAL_PATH,UTM_X_MIN,UTM_X_MAX,UTM_Y_MIN,UTM_Y_MAX,Z_DEPTH_BLOCK,&
+                         myrank, sizeprocs, &
+                         LOCAL_PATH,UTM_X_MIN,UTM_X_MAX,UTM_Y_MIN,UTM_Y_MAX,Z_DEPTH_BLOCK,&
                          CREATE_ABAQUS_FILES,CREATE_DX_FILES,CREATE_VTK_FILES, &
-                         USE_REGULAR_MESH,NDOUBLINGS,ner_doublings)
+                        USE_REGULAR_MESH,NDOUBLINGS,ner_doublings, &
+                        ADIOS_ENABLED, ADIOS_FOR_DATABASES)
 
   if(myrank == 0) then
 ! compare to exact theoretical value (bottom is always flat)

Added: seismo/3D/SPECFEM3D/trunk/src/meshfem3D/meshfem3D_adios_stubs.f90
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/meshfem3D/meshfem3D_adios_stubs.f90	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/src/meshfem3D/meshfem3D_adios_stubs.f90	2013-09-18 14:35:14 UTC (rev 22798)
@@ -0,0 +1,15 @@
+
+!==============================================================================
+!> \file meshfem3D_adios_stubs.f90
+!!
+!!  Stubs for ADIOS functions. Avoid link error when not configured with
+!!  ADIOS.
+!!      
+!! \author MPBL
+!==============================================================================
+
+subroutine save_databases_adios()
+  use adios_manager_mod
+
+  call no_adios_err()  
+end subroutine save_databases_adios

Added: seismo/3D/SPECFEM3D/trunk/src/meshfem3D/save_databases_adios.F90
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/meshfem3D/save_databases_adios.F90	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/src/meshfem3D/save_databases_adios.F90	2013-09-18 14:35:14 UTC (rev 22798)
@@ -0,0 +1,739 @@
+!=====================================================================
+!
+!               S p e c f e m 3 D  V e r s i o n  2 . 1
+!               ---------------------------------------
+!
+!          Main authors: Dimitri Komatitsch and Jeroen Tromp
+!    Princeton University, USA and CNRS / INRIA / University of Pau
+! (c) Princeton University / California Institute of Technology and CNRS / INRIA / University of Pau
+!                             July 2012
+!
+! This 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 02110-1301 USA.
+!
+!=====================================================================
+
+!==============================================================================
+!> \file save_databases_adios.F90
+!!
+!! \author MPBL
+!==============================================================================
+
+!==============================================================================
+!> \def STRINGIFY_VAR(a)
+!! Macro taking a variable and returning the stringified variable and 
+!! the variable itself.
+!! STRINGIFY_VAR(x) expand as:
+!!   "x", x
+!! x being the variable name inside the code.
+#ifdef __INTEL_COMPILER
+#define STRINGIFY_VAR(a) #a, a
+#else
+#define STRINGIFY_VAR(a) "a", a
+#endif
+
+!==============================================================================
+subroutine save_databases_adios(LOCAL_PATH, myrank, sizeprocs, &
+   nspec,nglob,iproc_xi,iproc_eta, &
+   NPROC_XI,NPROC_ETA,addressing,iMPIcut_xi,iMPIcut_eta,&
+   ibool,nodes_coords,true_material_num, &
+   nspec2D_xmin,nspec2D_xmax,nspec2D_ymin,nspec2D_ymax, &
+   NSPEC2D_BOTTOM,NSPEC2D_TOP, NSPEC2DMAX_XMIN_XMAX,NSPEC2DMAX_YMIN_YMAX, &
+   ibelm_xmin,ibelm_xmax,ibelm_ymin,ibelm_ymax,ibelm_bottom,ibelm_top,&
+   NMATERIALS,material_properties)
+  
+  use mpi
+  use adios_helpers_mod
+  use safe_alloc_mod
+
+  implicit none
+
+  include "constants.h"
+  include "constants_meshfem3D.h"
+
+  ! MPI variables
+  integer :: myrank, sizeprocs
+
+  ! number of spectral elements in each block
+  integer nspec
+
+  ! number of vertices in each block
+  integer nglob
+
+  ! MPI cartesian topology
+  ! E for East (= XI_MIN), W for West (= XI_MAX), 
+  ! S for South (= ETA_MIN), N for North (= ETA_MAX)
+  integer, parameter :: W=1,E=2,S=3,N=4,NW=5,NE=6,SE=7,SW=8
+  integer iproc_xi,iproc_eta
+  integer NPROC_XI,NPROC_ETA
+  logical iMPIcut_xi(2,nspec),iMPIcut_eta(2,nspec)
+  integer addressing(0:NPROC_XI-1,0:NPROC_ETA-1)
+
+  ! arrays with the mesh
+  integer ibool(NGLLX_M,NGLLY_M,NGLLZ_M,nspec)
+  double precision :: nodes_coords(nglob,3)
+
+  integer true_material_num(nspec)
+  integer(kind=4), dimension(2,nspec) :: material_index
+
+  ! boundary parameters locator
+  integer NSPEC2D_BOTTOM,NSPEC2D_TOP,NSPEC2DMAX_XMIN_XMAX,NSPEC2DMAX_YMIN_YMAX
+  integer nspec2D_xmin,nspec2D_xmax,nspec2D_ymin,nspec2D_ymax
+  integer ibelm_xmin(NSPEC2DMAX_XMIN_XMAX),ibelm_xmax(NSPEC2DMAX_XMIN_XMAX)
+  integer ibelm_ymin(NSPEC2DMAX_YMIN_YMAX),ibelm_ymax(NSPEC2DMAX_YMIN_YMAX)
+  integer ibelm_bottom(NSPEC2D_BOTTOM)
+  integer ibelm_top(NSPEC2D_TOP)
+
+  ! material properties
+  integer :: NMATERIALS, nundef_materials
+  ! first dimension  : material_id
+  ! second dimension : #rho  #vp  #vs  #Q_flag  #anisotropy_flag #domain_id
+  double precision , dimension(NMATERIALS,6) ::  material_properties
+  double precision , dimension(16,NMATERIALS) :: matpropl
+  integer :: i,ispec,iglob,ier
+  ! dummy_nspec_cpml is used here to match the read instructions 
+  ! in generate_databases/read_partition_files.f90
+  integer :: dummy_nspec_cpml
+
+  ! name of the database files
+  character(len=256) LOCAL_PATH 
+
+  ! for MPI interfaces
+  integer ::  nb_interfaces,nspec_interfaces_max,idoubl
+  logical, dimension(8) ::  interfaces
+  integer, dimension(8) ::  nspec_interface
+
+  integer, parameter :: IIN_database = 15
+
+  integer :: ngnod, ngnod2d
+
+  !--- Local parameters for ADIOS ---
+  character(len=256) :: output_name
+  character(len=64), parameter :: group_name  = "SPECFEM3D_DATABASES"
+  integer(kind=8) :: group, handle
+  integer(kind=8) :: groupsize, totalsize
+  integer :: local_dim, global_dim, offset, varid
+  
+  !--- Variables to allreduce - wmax stands for world_max
+  integer :: nglob_wmax, nspec_wmax, nmaterials_wmax, &
+             nspec2d_xmin_wmax, nspec2d_xmax_wmax,    &
+             nspec2d_ymin_wmax, nspec2d_ymax_wmax,    &
+             nspec2d_bottom_wmax, nspec2d_top_wmax,   &
+             nb_interfaces_wmax, nspec_interfaces_max_wmax
+  integer, parameter :: num_vars = 11
+  integer, dimension(num_vars) :: max_global_values
+
+  !--- Temporary arrays for writes
+  integer, dimension(:,:), allocatable :: nodes_ibelm_xmin, nodes_ibelm_xmax, &
+                                          nodes_ibelm_ymin, nodes_ibelm_ymax, &
+                                          nodes_ibelm_bottom, nodes_ibelm_top
+  integer, dimension(:), allocatable :: neighbours_mesh, num_elmnts_mesh
+  integer, dimension(:,:,:), allocatable :: interfaces_mesh
+  integer, dimension(:,:), allocatable :: elmnts_mesh
+  integer :: interface_num, ispec_interface
+
+  !---------------------------.
+  ! Setup the values to write |
+  !---------------------------'
+  ngnod   = NGLLX_M * NGLLY_M *  NGLLZ_M
+  ngnod2d = NGLLX_M * NGLLY_M
+
+  ! pad dummy zeros to fill up 16 entries (poroelastic medium not allowed)
+  matpropl(:,:) = 0.d0
+  matpropl(1:6, :) = transpose(material_properties(:,1:6))
+  
+  nundef_materials = 0
+
+  material_index (:,:)=1
+  do ispec = 1, nspec
+    material_index(2, :)     = 1
+    material_index(1, ispec) = true_material_num(ispec)
+  enddo 
+
+  call safe_alloc(nodes_ibelm_xmin,ngnod2d, nspec2d_xmin, "nodes_ibelm_xmin")
+  call safe_alloc(nodes_ibelm_xmax,ngnod2d, nspec2d_xmax, "nodes_ibelm_xmax")
+  call safe_alloc(nodes_ibelm_ymin,ngnod2d, nspec2d_ymin, "nodes_ibelm_ymin")
+  call safe_alloc(nodes_ibelm_ymax, ngnod2d, nspec2d_ymax, "nodes_ibelm_ymax")
+  call safe_alloc(nodes_ibelm_bottom, ngnod2d, nspec2d_bottom, &
+                  "nodes_ibelm_bottom")
+  call safe_alloc(nodes_ibelm_top, ngnod2d, nspec2d_top, "nodes_ibelm_top")
+  call safe_alloc(elmnts_mesh, NGNOD, nspec, "elmnts_mesh")
+
+  do ispec = 1, nspec 
+    elmnts_mesh(1,ispec) = ibool(1,1,1,ispec)
+    elmnts_mesh(2,ispec) = ibool(2,1,1,ispec)
+    elmnts_mesh(3,ispec) = ibool(2,2,1,ispec)
+    elmnts_mesh(4,ispec) = ibool(1,2,1,ispec)
+    elmnts_mesh(5,ispec) = ibool(1,1,2,ispec)
+    elmnts_mesh(6,ispec) = ibool(2,1,2,ispec)
+    elmnts_mesh(7,ispec) = ibool(2,2,2,ispec)
+    elmnts_mesh(8,ispec) = ibool(1,2,2,ispec)
+  enddo
+
+  do i=1,nspec2d_xmin
+      nodes_ibelm_xmin(1, i) = ibool(1,1,1,ibelm_xmin(i))
+      nodes_ibelm_xmin(2, i) = ibool(1,NGLLY_M,1,ibelm_xmin(i))
+      nodes_ibelm_xmin(3, i) = ibool(1,1,NGLLZ_M,ibelm_xmin(i))
+      nodes_ibelm_xmin(4, i) = ibool(1,NGLLY_M,NGLLZ_M,ibelm_xmin(i))
+  enddo
+  do i=1,nspec2D_xmax
+    nodes_ibelm_xmax(1, i) = ibool(NGLLX_M,1,1,ibelm_xmax(i))
+    nodes_ibelm_xmax(2, i) = ibool(NGLLX_M,NGLLY_M,1,ibelm_xmax(i))
+    nodes_ibelm_xmax(3, i) = ibool(NGLLX_M,1,NGLLZ_M,ibelm_xmax(i))
+    nodes_ibelm_xmax(4, i) = ibool(NGLLX_M,NGLLY_M,NGLLZ_M, ibelm_xmax(i))
+  enddo
+  do i=1,nspec2D_ymin
+    nodes_ibelm_ymin(1, i) = ibool(1,1,1,ibelm_ymin(i))
+    nodes_ibelm_ymin(2, i) = ibool(NGLLX_M,1,1,ibelm_ymin(i))
+    nodes_ibelm_ymin(3, i) = ibool(1,1,NGLLZ_M,ibelm_ymin(i))
+    nodes_ibelm_ymin(4, i) = ibool(NGLLX_M,1,NGLLZ_M,ibelm_ymin(i))
+  enddo
+  do i=1,nspec2D_ymax
+    nodes_ibelm_ymax(1, i) = ibool(NGLLX_M,NGLLY_M,1,ibelm_ymax(i))
+    nodes_ibelm_ymax(2, i) = ibool(1,NGLLY_M,1,ibelm_ymax(i))
+    nodes_ibelm_ymax(3, i) = ibool(NGLLX_M,NGLLY_M,NGLLZ_M,ibelm_ymax(i))
+    nodes_ibelm_ymax(4, i) = ibool(1,NGLLY_M,NGLLZ_M,ibelm_ymax(i))
+  enddo
+  do i=1,NSPEC2D_BOTTOM
+    nodes_ibelm_bottom(1, i) = ibool(1,1,1,ibelm_bottom(i))
+    nodes_ibelm_bottom(2, i) = ibool(NGLLX_M,1,1,ibelm_bottom(i))
+    nodes_ibelm_bottom(3, i) = ibool(NGLLX_M,NGLLY_M,1,ibelm_bottom(i))
+    nodes_ibelm_bottom(4, i) = ibool(1,NGLLY_M,1,ibelm_bottom(i))
+  enddo
+  do i=1,NSPEC2D_TOP
+    nodes_ibelm_top(1, i) = ibool(1,1,NGLLZ_M,ibelm_top(i))
+    nodes_ibelm_top(2, i) = ibool(NGLLX_M,1,NGLLZ_M,ibelm_top(i))
+    nodes_ibelm_top(3, i) = ibool(NGLLX_M,NGLLY_M,NGLLZ_M,ibelm_top(i))
+    nodes_ibelm_top(4, i) = ibool(1,NGLLY_M,NGLLZ_M,ibelm_top(i))
+  enddo
+
+  ! JC JC todo: implement C-PML code in internal mesher
+  ! dummy_nspec_cpml is used here to match the read instructions 
+  ! in generate_databases/read_partition_files.f90
+  dummy_nspec_cpml = 0
+
+  nb_interfaces = 0
+  nspec_interfaces_max = 0
+  if(NPROC_XI >= 2 .or. NPROC_ETA >= 2) then
+    nb_interfaces = 4
+    interfaces(W:N) = .true.
+    interfaces(NW:SW) = .false.
+    if(iproc_xi == 0) then
+       nb_interfaces =  nb_interfaces -1
+       interfaces(W) = .false.
+    endif
+    if(iproc_xi == NPROC_XI-1) then
+       nb_interfaces =  nb_interfaces -1
+       interfaces(E) = .false.
+    endif
+    if(iproc_eta == 0) then
+       nb_interfaces =  nb_interfaces -1
+       interfaces(S) = .false.
+    endif
+    if(iproc_eta == NPROC_ETA-1) then
+       nb_interfaces =  nb_interfaces -1
+       interfaces(N) = .false.
+    endif
+
+    if((interfaces(W) .eqv. .true.) .and. (interfaces(N) .eqv. .true.)) then
+         interfaces(NW) = .true.
+         nb_interfaces =  nb_interfaces +1
+    endif
+    if((interfaces(N) .eqv. .true.) .and. (interfaces(E) .eqv. .true.)) then
+         interfaces(NE) = .true.
+         nb_interfaces =  nb_interfaces +1
+    endif
+    if((interfaces(E) .eqv. .true.) .and. (interfaces(S) .eqv. .true.)) then
+         interfaces(SE) = .true.
+         nb_interfaces =  nb_interfaces +1
+    endif
+    if((interfaces(W) .eqv. .true.) .and. (interfaces(S) .eqv. .true.)) then
+         interfaces(SW) = .true.
+         nb_interfaces =  nb_interfaces +1
+    endif
+
+    nspec_interface(:) = 0
+    if(interfaces(W)) &
+        nspec_interface(W) = count(iMPIcut_xi(1,:) .eqv. .true.)
+    if(interfaces(E)) &
+        nspec_interface(E) = count(iMPIcut_xi(2,:) .eqv. .true.)
+    if(interfaces(S)) &
+        nspec_interface(S) = count(iMPIcut_eta(1,:) .eqv. .true.)
+    if(interfaces(N)) &
+        nspec_interface(N) = count(iMPIcut_eta(2,:) .eqv. .true.)
+    if(interfaces(NW)) &
+        nspec_interface(NW) = count((iMPIcut_xi(1,:) .eqv. .true.) &
+            .and. (iMPIcut_eta(2,:) .eqv. .true.))
+    if(interfaces(NE)) &
+        nspec_interface(NE) = count((iMPIcut_xi(2,:) .eqv. .true.) &
+            .and. (iMPIcut_eta(2,:) .eqv. .true.))
+    if(interfaces(SE)) &
+        nspec_interface(SE) = count((iMPIcut_xi(2,:) .eqv. .true.) &
+            .and. (iMPIcut_eta(1,:) .eqv. .true.))
+    if(interfaces(SW)) &
+        nspec_interface(SW) = count((iMPIcut_xi(1,:) .eqv. .true.) &
+            .and. (iMPIcut_eta(1,:) .eqv. .true.))
+
+    nspec_interfaces_max = maxval(nspec_interface)
+    
+    call safe_alloc(neighbours_mesh, nb_interfaces, "neighbours_mesh")
+    call safe_alloc(num_elmnts_mesh, nb_interfaces, "num_elmnts_mesh")
+    call safe_alloc(interfaces_mesh, 6, nspec_interfaces_max, nb_interfaces, &
+                    "interfaces_mesh")
+
+    interface_num = 1
+    neighbours_mesh(:) = 0
+    num_elmnts_mesh(:) = 0
+    interfaces_mesh(:,:,:) = 0
+
+    if(interfaces(W)) then
+      neighbours_mesh(interface_num) = addressing(iproc_xi-1,iproc_eta)
+      num_elmnts_mesh(interface_num) = nspec_interface(W)
+      ispec_interface = 1
+      do ispec = 1,nspec
+        if(iMPIcut_xi(1,ispec)) then 
+          interfaces_mesh(1, ispec_interface, interface_num) = ispec
+          interfaces_mesh(2, ispec_interface, interface_num) = 4
+          interfaces_mesh(3, ispec_interface, interface_num) &
+              = ibool(1,1,1,ispec)
+          interfaces_mesh(4, ispec_interface, interface_num) &
+              = ibool(1,2,1,ispec)
+          interfaces_mesh(5, ispec_interface, interface_num) &
+              = ibool(1,1,2,ispec)
+          interfaces_mesh(6, ispec_interface, interface_num) &
+              = ibool(1,2,2,ispec)
+          ispec_interface = ispec_interface + 1
+         endif                               
+      enddo
+      interface_num = interface_num +1
+    endif
+
+    if(interfaces(E)) then
+      neighbours_mesh(interface_num) = addressing(iproc_xi+1,iproc_eta)
+      num_elmnts_mesh(interface_num) = nspec_interface(E)
+      ispec_interface = 1
+      do ispec = 1,nspec
+        if(iMPIcut_xi(2,ispec)) then
+          interfaces_mesh(1, ispec_interface, interface_num) = ispec
+          interfaces_mesh(2, ispec_interface, interface_num) = 4
+          interfaces_mesh(3, ispec_interface, interface_num) &
+              = ibool(2,1,1,ispec)
+          interfaces_mesh(4, ispec_interface, interface_num) &
+              = ibool(2,2,1,ispec)
+          interfaces_mesh(5, ispec_interface, interface_num) &
+              = ibool(2,1,2,ispec)
+          interfaces_mesh(6, ispec_interface, interface_num) &
+              = ibool(2,2,2,ispec)
+          ispec_interface = ispec_interface + 1
+         endif                                
+      enddo
+      interface_num = interface_num +1
+    endif
+
+    if(interfaces(S)) then
+      neighbours_mesh(interface_num) = addressing(iproc_xi,iproc_eta-1)
+      num_elmnts_mesh(interface_num) = nspec_interface(S)
+      ispec_interface = 1
+      do ispec = 1,nspec
+        if(iMPIcut_eta(1,ispec)) then
+          interfaces_mesh(1, ispec_interface, interface_num) = ispec
+          interfaces_mesh(2, ispec_interface, interface_num) = 4
+          interfaces_mesh(3, ispec_interface, interface_num) &
+              = ibool(1,1,1,ispec)
+          interfaces_mesh(4, ispec_interface, interface_num) &
+              = ibool(2,1,1,ispec)
+          interfaces_mesh(5, ispec_interface, interface_num) &
+              = ibool(1,1,2,ispec)
+          interfaces_mesh(6, ispec_interface, interface_num) &
+              = ibool(2,1,2,ispec)
+          ispec_interface = ispec_interface + 1
+        endif                                          
+      enddo
+      interface_num = interface_num +1
+    endif
+
+    if(interfaces(N)) then
+      neighbours_mesh(interface_num) = addressing(iproc_xi,iproc_eta+1)
+      num_elmnts_mesh(interface_num) = nspec_interface(N)
+      ispec_interface = 1
+      do ispec = 1,nspec
+        if(iMPIcut_eta(2,ispec)) then
+          interfaces_mesh(1, ispec_interface, interface_num) = ispec
+          interfaces_mesh(2, ispec_interface, interface_num) = 4
+          interfaces_mesh(3, ispec_interface, interface_num) &
+              = ibool(2,2,1,ispec)
+          interfaces_mesh(4, ispec_interface, interface_num) &
+              = ibool(1,2,1,ispec)
+          interfaces_mesh(5, ispec_interface, interface_num) &
+              = ibool(2,2,2,ispec)
+          interfaces_mesh(6, ispec_interface, interface_num) &
+              = ibool(1,2,2,ispec)
+          ispec_interface = ispec_interface + 1
+        endif
+      enddo
+      interface_num = interface_num +1
+    endif
+
+    if(interfaces(NW)) then
+      neighbours_mesh(interface_num) = addressing(iproc_xi-1,iproc_eta+1)
+      num_elmnts_mesh(interface_num) = nspec_interface(NW)
+      ispec_interface = 1
+      do ispec = 1,nspec
+        if((iMPIcut_xi(1,ispec) .eqv. .true.) &
+            .and. (iMPIcut_eta(2,ispec) .eqv. .true.))  then
+          interfaces_mesh(1, ispec_interface, interface_num) = ispec
+          interfaces_mesh(2, ispec_interface, interface_num) = 2
+          interfaces_mesh(3, ispec_interface, interface_num) &
+              = ibool(1,2,1,ispec)
+          interfaces_mesh(4, ispec_interface, interface_num) &
+              = ibool(1,2,2,ispec)
+          interfaces_mesh(5, ispec_interface, interface_num) = -1
+          interfaces_mesh(6, ispec_interface, interface_num) = -1
+          ispec_interface = ispec_interface + 1
+        endif
+      enddo
+      interface_num = interface_num +1
+    endif
+
+    if(interfaces(NE)) then
+      neighbours_mesh(interface_num) = addressing(iproc_xi+1,iproc_eta+1)
+      num_elmnts_mesh(interface_num) = nspec_interface(NE)
+      ispec_interface = 1
+      do ispec = 1,nspec
+        if((iMPIcut_xi(2,ispec) .eqv. .true.) &
+            .and. (iMPIcut_eta(2,ispec) .eqv. .true.))  then
+          interfaces_mesh(1, ispec_interface, interface_num) = ispec
+          interfaces_mesh(2, ispec_interface, interface_num) = 2
+          interfaces_mesh(3, ispec_interface, interface_num) &
+              = ibool(2,2,1,ispec)
+          interfaces_mesh(4, ispec_interface, interface_num) &
+              = ibool(2,2,2,ispec)
+          interfaces_mesh(5, ispec_interface, interface_num) = -1
+          interfaces_mesh(6, ispec_interface, interface_num) = -1
+          ispec_interface = ispec_interface + 1
+        endif
+      enddo
+      interface_num = interface_num +1
+    endif
+
+    if(interfaces(SE)) then
+      neighbours_mesh(interface_num) = addressing(iproc_xi+1,iproc_eta-1)
+      num_elmnts_mesh(interface_num) = nspec_interface(SE)
+      ispec_interface = 1
+      do ispec = 1,nspec
+        if((iMPIcut_xi(2,ispec) .eqv. .true.) &
+            .and. (iMPIcut_eta(1,ispec) .eqv. .true.))  then
+          interfaces_mesh(1, ispec_interface, interface_num) = ispec
+          interfaces_mesh(2, ispec_interface, interface_num) = 2
+          interfaces_mesh(3, ispec_interface, interface_num) &
+              = ibool(2,1,1,ispec)
+          interfaces_mesh(4, ispec_interface, interface_num) &
+              = ibool(2,1,2,ispec)
+          interfaces_mesh(5, ispec_interface, interface_num) = -1
+          interfaces_mesh(6, ispec_interface, interface_num) = -1
+          ispec_interface = ispec_interface + 1
+        endif
+      enddo
+      interface_num = interface_num +1
+    endif
+
+    if(interfaces(SW)) then
+      neighbours_mesh(interface_num) = addressing(iproc_xi-1,iproc_eta-1)
+      num_elmnts_mesh(interface_num) = nspec_interface(SW)
+      ispec_interface = 1
+      do ispec = 1,nspec
+        if((iMPIcut_xi(1,ispec) .eqv. .true.) &
+            .and. (iMPIcut_eta(1,ispec) .eqv. .true.))  then
+          interfaces_mesh(1, ispec_interface, interface_num) = ispec
+          interfaces_mesh(2, ispec_interface, interface_num) = 2
+          interfaces_mesh(3, ispec_interface, interface_num) &
+              = ibool(1,1,1,ispec)
+          interfaces_mesh(4, ispec_interface, interface_num) &
+              = ibool(1,1,2,ispec)
+          interfaces_mesh(5, ispec_interface, interface_num) = -1
+          interfaces_mesh(6, ispec_interface, interface_num) = -1
+          ispec_interface = ispec_interface + 1
+        endif
+      enddo
+      interface_num = interface_num +1
+    endif
+
+  endif
+
+  !-----------------------------------------------------------------.
+  ! Get maximum value for each variable used to define a local_dim. |
+  ! ADIOS write equally sized chunks for each processor.            |
+  !-----------------------------------------------------------------'
+  ! Filling a temporary array to avoid doing allreduces for each var.
+  max_global_values(1) = nglob
+  max_global_values(2) = nspec
+  max_global_values(3) = NMATERIALS
+  max_global_values(4) = nspec2d_xmin
+  max_global_values(5) = nspec2d_xmax
+  max_global_values(6) = nspec2d_ymin
+  max_global_values(7) = nspec2d_ymax
+  max_global_values(8) = nspec2d_bottom
+  max_global_values(9) = nspec2d_top
+  max_global_values(10) = nb_interfaces
+  max_global_values(11) = nspec_interfaces_max
+
+  call MPI_Allreduce(MPI_IN_PLACE, max_global_values, num_vars, &
+                     MPI_INTEGER, MPI_MAX, MPI_COMM_WORLD, ier)
+  if( ier /= 0 ) call exit_MPI(myrank,'Allreduce to get max values failed.')
+
+  nglob_wmax          = max_global_values(1)
+  nspec_wmax          = max_global_values(2)
+  nmaterials_wmax     = max_global_values(3)
+  nspec2d_xmin_wmax   = max_global_values(4)
+  nspec2d_xmax_wmax   = max_global_values(5)
+  nspec2d_ymin_wmax   = max_global_values(6)
+  nspec2d_ymax_wmax   = max_global_values(7)
+  nspec2d_bottom_wmax = max_global_values(8)
+  nspec2d_top_wmax    = max_global_values(9)
+  nb_interfaces_wmax  = max_global_values(10)
+  nspec_interfaces_max_wmax = max_global_values(11)
+
+  !-----------------------------------.
+  ! Setup ADIOS for the current group |
+  !-----------------------------------'
+  groupsize = 0
+  output_name = LOCAL_PATH(1:len_trim(LOCAL_PATH)) // "/Database.bp"
+  call adios_declare_group(group, group_name, "", 1, ier)
+  call adios_select_method(group, ADIOS_TRANSPORT_METHOD, "", "", ier)
+
+  !------------------------.
+  ! Define ADIOS Variables |
+  !------------------------'
+  call define_adios_scalar(group, groupsize, "", STRINGIFY_VAR(ngllx)) 
+  call define_adios_scalar(group, groupsize, "", STRINGIFY_VAR(nglly)) 
+  call define_adios_scalar(group, groupsize, "", STRINGIFY_VAR(ngllz)) 
+
+  call define_adios_scalar(group, groupsize, "", STRINGIFY_VAR(ngllx_m)) 
+  call define_adios_scalar(group, groupsize, "", STRINGIFY_VAR(nglly_m)) 
+  call define_adios_scalar(group, groupsize, "", STRINGIFY_VAR(ngllz_m)) 
+  call define_adios_scalar(group, groupsize, "", STRINGIFY_VAR(ngnod)) 
+  call define_adios_scalar(group, groupsize, "", STRINGIFY_VAR(ngnod2d)) 
+
+  call define_adios_scalar(group, groupsize, "", STRINGIFY_VAR(nglob)) 
+  call define_adios_scalar(group, groupsize, "", STRINGIFY_VAR(nmaterials)) 
+  call define_adios_scalar(group, groupsize, "", & 
+                           STRINGIFY_VAR(nundef_materials)) 
+  call define_adios_scalar(group, groupsize, "", STRINGIFY_VAR(nspec)) 
+
+  call define_adios_scalar(group, groupsize, "", STRINGIFY_VAR(nspec2d_xmin))
+  call define_adios_scalar(group, groupsize, "", STRINGIFY_VAR(nspec2d_xmax))
+  call define_adios_scalar(group, groupsize, "", STRINGIFY_VAR(nspec2d_ymin))
+  call define_adios_scalar(group, groupsize, "", STRINGIFY_VAR(nspec2d_ymax))
+  call define_adios_scalar(group, groupsize, "", STRINGIFY_VAR(nspec2d_bottom))
+  call define_adios_scalar(group, groupsize, "", STRINGIFY_VAR(nspec2d_top)) 
+
+  call define_adios_scalar(group, groupsize, "", "nspec_cpml",dummy_nspec_cpml)
+
+  call define_adios_scalar(group, groupsize, "", STRINGIFY_VAR(nb_interfaces)) 
+  call define_adios_scalar(group, groupsize, "", &
+                           STRINGIFY_VAR(nspec_interfaces_max)) 
+
+  local_dim = 3 * nglob_wmax
+  call define_adios_global_array1D(group, groupsize, local_dim, &
+                                   "", STRINGIFY_VAR(nodes_coords))
+  local_dim = 16 * nmaterials_wmax
+  call define_adios_global_array1D(group, groupsize, local_dim, &
+                                   "", STRINGIFY_VAR(matpropl))
+  local_dim = 2 * nspec_wmax
+  call define_adios_global_array1D(group, groupsize, local_dim, &
+                                   "", STRINGIFY_VAR(material_index))
+  local_dim = NGLLX_M * NGLLY_M * NGLLZ_M * nspec_wmax
+  call define_adios_global_array1D(group, groupsize, local_dim, &
+                                   "", STRINGIFY_VAR(elmnts_mesh))
+
+  local_dim = nspec2d_xmin_wmax 
+  call define_adios_global_array1D(group, groupsize, local_dim, &
+                                   "", STRINGIFY_VAR(ibelm_xmin))
+  local_dim = NGNOD2D * nspec2d_xmin_wmax                                 
+  call define_adios_global_array1D(group, groupsize, local_dim, &
+                                   "", STRINGIFY_VAR(nodes_ibelm_xmin))
+  local_dim = nspec2d_xmax_wmax 
+  call define_adios_global_array1D(group, groupsize, local_dim, &
+                                   "", STRINGIFY_VAR(ibelm_xmax))
+  local_dim = NGNOD2D * nspec2d_xmax_wmax                                 
+  call define_adios_global_array1D(group, groupsize, local_dim, &
+                                   "", STRINGIFY_VAR(nodes_ibelm_xmax))
+  local_dim = nspec2d_ymin_wmax 
+  call define_adios_global_array1D(group, groupsize, local_dim, &
+                                   "", STRINGIFY_VAR(ibelm_ymin))
+  local_dim = NGNOD2D * nspec2d_ymin_wmax                                 
+  call define_adios_global_array1D(group, groupsize, local_dim, &
+                                   "", STRINGIFY_VAR(nodes_ibelm_ymin))
+  local_dim = nspec2d_ymax_wmax 
+  call define_adios_global_array1D(group, groupsize, local_dim, &
+                                   "", STRINGIFY_VAR(ibelm_ymax))
+  local_dim = NGNOD2D * nspec2d_ymax_wmax                                 
+  call define_adios_global_array1D(group, groupsize, local_dim, &
+                                   "", STRINGIFY_VAR(nodes_ibelm_ymax))
+  local_dim = nspec2d_bottom_wmax 
+  call define_adios_global_array1D(group, groupsize, local_dim, &
+                                   "", STRINGIFY_VAR(ibelm_bottom))
+  local_dim = NGNOD2D * nspec2d_bottom_wmax                                 
+  call define_adios_global_array1D(group, groupsize, local_dim, &
+                                   "", STRINGIFY_VAR(nodes_ibelm_bottom))
+  local_dim = nspec2d_top_wmax 
+  call define_adios_global_array1D(group, groupsize, local_dim, &
+                                   "", STRINGIFY_VAR(ibelm_top))
+  local_dim = NGNOD2D * nspec2d_top_wmax                                 
+  call define_adios_global_array1D(group, groupsize, local_dim, &
+                                   "", STRINGIFY_VAR(nodes_ibelm_top))
+
+  local_dim = nb_interfaces_wmax 
+  call define_adios_global_array1D(group, groupsize, local_dim, &
+                                   "", STRINGIFY_VAR(neighbours_mesh))
+  call define_adios_global_array1D(group, groupsize, local_dim, &
+                                   "", STRINGIFY_VAR(num_elmnts_mesh))
+  local_dim = 6 * nb_interfaces_wmax * nspec_interfaces_max_wmax
+  call define_adios_global_array1D(group, groupsize, local_dim, &
+                                    "", STRINGIFY_VAR(interfaces_mesh))
+
+  !------------------------------------------------------------.
+  ! Open an handler to the ADIOS file and setup the group size |
+  !------------------------------------------------------------'
+  call adios_open(handle, group_name, output_name, "w", &
+                  MPI_COMM_WORLD, ier);
+  call adios_group_size (handle, groupsize, totalsize, ier)
+
+  !------------------------------------------.
+  ! Write previously defined ADIOS variables |
+  !------------------------------------------'
+  call adios_write(handle, STRINGIFY_VAR(ngllx), ier)
+  call adios_write(handle, STRINGIFY_VAR(nglly), ier)
+  call adios_write(handle, STRINGIFY_VAR(ngllz), ier)
+
+  call adios_write(handle, STRINGIFY_VAR(ngllx_m), ier)
+  call adios_write(handle, STRINGIFY_VAR(nglly_m), ier)
+  call adios_write(handle, STRINGIFY_VAR(ngllz_m), ier)
+  call adios_write(handle, STRINGIFY_VAR(ngnod), ier)
+  call adios_write(handle, STRINGIFY_VAR(ngnod2d), ier)
+
+  call adios_write(handle, STRINGIFY_VAR(nglob), ier)
+  call adios_write(handle, STRINGIFY_VAR(nmaterials), ier)
+  call adios_write(handle, STRINGIFY_VAR(nundef_materials), ier)
+  call adios_write(handle, STRINGIFY_VAR(nspec), ier)
+
+  call adios_write(handle, STRINGIFY_VAR(nspec2d_xmin), ier)
+  call adios_write(handle, STRINGIFY_VAR(nspec2d_xmax), ier)
+  call adios_write(handle, STRINGIFY_VAR(nspec2d_ymin), ier)
+  call adios_write(handle, STRINGIFY_VAR(nspec2d_ymax), ier)
+  call adios_write(handle, STRINGIFY_VAR(nspec2d_bottom), ier)
+  call adios_write(handle, STRINGIFY_VAR(nspec2d_top), ier)
+
+  call adios_write(handle, "nspec_cpml", dummy_nspec_cpml, ier)
+
+  call adios_write(handle, STRINGIFY_VAR(nb_interfaces), ier)
+  call adios_write(handle, STRINGIFY_VAR(nspec_interfaces_max), ier)
+
+  ! NOTE: Do not put any wmax variables, it will try to access
+  !       too many values in the arrays.
+  local_dim = 3 * nglob
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   "nodes_coords", transpose(nodes_coords))
+  local_dim = 16 * nmaterials
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   STRINGIFY_VAR(matpropl))
+  local_dim = 2 * nspec
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   STRINGIFY_VAR(material_index))
+  ! WARNING: the order is a little bit different than for Fortran outpu
+  !          It should not matter, but it may.
+  local_dim = NGLLX_M * NGLLY_M * NGLLZ_M * nspec_wmax
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   STRINGIFY_VAR(elmnts_mesh))
+
+  local_dim = nspec2d_xmin_wmax
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   STRINGIFY_VAR(ibelm_xmin))
+  if (nspec2d_xmin .ne. 0) then
+    local_dim = NGNOD2D * nspec2d_xmin_wmax
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(nodes_ibelm_xmin))
+  endif
+  local_dim = nspec2d_xmax_wmax
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   STRINGIFY_VAR(ibelm_xmax))
+  if (nspec2d_xmax .ne. 0) then
+    local_dim = NGNOD2D * nspec2d_xmax_wmax
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(nodes_ibelm_xmax))
+  endif
+  local_dim = nspec2d_ymin_wmax
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   STRINGIFY_VAR(ibelm_ymin))
+  if (nspec2d_ymin .ne. 0) then
+    local_dim = NGNOD2D * nspec2d_ymin_wmax
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(nodes_ibelm_ymin))
+  endif
+  local_dim = nspec2d_ymax_wmax
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   STRINGIFY_VAR(ibelm_ymax))
+  if (nspec2d_ymax .ne. 0) then                                   
+  local_dim = NGNOD2D * nspec2d_ymax_wmax
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   STRINGIFY_VAR(nodes_ibelm_ymax))
+  endif
+  local_dim = nspec2d_bottom_wmax
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   STRINGIFY_VAR(ibelm_bottom))
+  if (nspec2d_bottom .ne. 0) then
+    local_dim = NGNOD2D * nspec2d_bottom_wmax
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(nodes_ibelm_bottom))
+  endif                                 
+  local_dim = nspec2d_top_wmax
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   STRINGIFY_VAR(ibelm_top))
+  if (nspec2d_top .ne. 0) then
+    local_dim = NGNOD2D * nspec2d_top_wmax
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(nodes_ibelm_top))
+  endif
+
+  local_dim = nb_interfaces_wmax
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   STRINGIFY_VAR(neighbours_mesh))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   STRINGIFY_VAR(num_elmnts_mesh))
+  local_dim = 6 * nb_interfaces_wmax * nspec_interfaces_max_wmax
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   STRINGIFY_VAR(interfaces_mesh))
+
+  !----------------------------------.
+  ! Perform the actual write to disk |
+  !----------------------------------'
+  call adios_set_path(handle, "", ier)                          
+  call adios_close(handle, ier)
+
+  !---------------------------.
+  ! Clean up temporary arrays |
+  !---------------------------'
+  call safe_dealloc(nodes_ibelm_xmin, "nodes_ibelm_xmin")
+  call safe_dealloc(nodes_ibelm_xmax, "nodes_ibelm_xmax")
+  call safe_dealloc(nodes_ibelm_ymin, "nodes_ibelm_ymin")
+  call safe_dealloc(nodes_ibelm_ymax, "nodes_ibelm_ymax")
+  call safe_dealloc(nodes_ibelm_bottom, "nodes_ibelm_bottom")
+  call safe_dealloc(nodes_ibelm_top, "nodes_ibelm_top")
+
+  call safe_dealloc(neighbours_mesh, "neighbours_mesh")
+  call safe_dealloc(num_elmnts_mesh, "num_elmnts_mesh")
+  call safe_dealloc(interfaces_mesh, "interfaces_mesh")
+  call safe_dealloc(elmnts_mesh, "elmnts_mesh")
+
+end subroutine save_databases_adios

Added: seismo/3D/SPECFEM3D/trunk/src/shared/adios_helpers.f90
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/shared/adios_helpers.f90	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/src/shared/adios_helpers.f90	2013-09-18 14:35:14 UTC (rev 22798)
@@ -0,0 +1,81 @@
+!=====================================================================
+!
+!          S p e c f e m 3 D  G l o b e  V e r s i o n  5 . 1
+!          --------------------------------------------------
+!
+!          Main authors: Dimitri Komatitsch and Jeroen Tromp
+!                        Princeton University, USA
+!             and University of Pau / CNRS / INRIA, France
+! (c) Princeton University / California Institute of Technology and University of Pau / CNRS / INRIA
+!                            April 2011
+!
+! This 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 02110-1301 USA.
+!
+!=====================================================================
+
+
+!===============================================================================
+!> Helpers to set up adios features.
+!! * Error checking
+!! * Scalar definition
+!! * Global arrays definition
+!!
+!! \author MPBL      
+!-------------------------------------------------------------------------------
+module adios_helpers_mod
+  use adios_helpers_definitions_mod
+  use adios_helpers_writers_mod
+  implicit none
+
+  private
+
+  ! from this module. No 'imports'
+  public :: check_adios_err
+
+  ! from adios_helpers_definitions_mod
+  public :: define_adios_scalar
+  public :: define_adios_global_real_1d_array
+  public :: define_adios_global_double_1d_array
+  public :: define_adios_global_integer_1d_array
+  public :: define_adios_global_long_1d_array
+  public :: define_adios_global_logical_1d_array
+  public :: define_adios_global_array1D
+
+  ! from adios_helpers_writers_mod
+  public :: write_adios_global_real_1d_array
+  public :: write_adios_global_double_1d_array
+  public :: write_adios_global_integer_1d_array
+  public :: write_adios_global_long_1d_array
+  public :: write_adios_global_logical_1d_array
+  public :: write_adios_global_1d_array
+contains
+
+!===============================================================================
+!> Get the ADIOS error message from an adios error number if there is an error.
+!! \param adios_err The error code considered.
+subroutine check_adios_err(myrank, adios_err)
+  use adios_read_mod
+  implicit none
+  integer, intent(in) :: myrank, adios_err
+  character(len=1024) :: msg
+
+  if (adios_err /= 0) then
+    call adios_errmsg(msg)
+    print *, "process: ", myrank, ", error: ", msg
+    stop
+  endif
+end subroutine check_adios_err
+
+end module adios_helpers_mod

Added: seismo/3D/SPECFEM3D/trunk/src/shared/adios_helpers_definitions.f90
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/shared/adios_helpers_definitions.f90	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/src/shared/adios_helpers_definitions.f90	2013-09-18 14:35:14 UTC (rev 22798)
@@ -0,0 +1,1172 @@
+!=====================================================================
+!
+!          S p e c f e m 3 D  G l o b e  V e r s i o n  5 . 1
+!          --------------------------------------------------
+!
+!          Main authors: Dimitri Komatitsch and Jeroen Tromp
+!                        Princeton University, USA
+!             and University of Pau / CNRS / INRIA, France
+! (c) Princeton University / California Institute of Technology and University of Pau / CNRS / INRIA
+!                            April 2011
+!
+! This 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 02110-1301 USA.
+!
+!=====================================================================
+
+
+!===============================================================================
+!> Helpers to set up adios features.
+!! * Scalar definition
+!! * Global arrays definition
+!!
+!! \author MPBL      
+!-------------------------------------------------------------------------------
+module adios_helpers_definitions_mod
+  implicit none
+
+  private
+
+  public :: define_adios_scalar
+  public :: define_adios_global_real_1d_array
+  public :: define_adios_global_double_1d_array
+  public :: define_adios_global_integer_1d_array
+  public :: define_adios_global_long_1d_array
+  public :: define_adios_global_logical_1d_array
+  public :: define_adios_global_array1D
+
+  ! Generic interface to define scalar variables in ADIOS 
+  interface define_adios_scalar
+    module procedure define_adios_double_scalar
+    module procedure define_adios_float_scalar
+    module procedure define_adios_integer_scalar
+    module procedure define_adios_byte_scalar
+  end interface define_adios_scalar
+
+  interface define_adios_global_real_1d_array
+    module procedure define_adios_global_1d_real_1d
+    module procedure define_adios_global_1d_real_2d
+    module procedure define_adios_global_1d_real_3d
+    module procedure define_adios_global_1d_real_4d
+    module procedure define_adios_global_1d_real_5d
+  end interface define_adios_global_real_1d_array
+
+  interface define_adios_global_double_1d_array
+    module procedure define_adios_global_1d_double_1d
+    module procedure define_adios_global_1d_double_2d
+    module procedure define_adios_global_1d_double_3d
+    module procedure define_adios_global_1d_double_4d
+    module procedure define_adios_global_1d_double_5d
+  end interface define_adios_global_double_1d_array
+
+  interface define_adios_global_integer_1d_array
+    module procedure define_adios_global_1d_int_1d
+    module procedure define_adios_global_1d_int_2d
+    module procedure define_adios_global_1d_int_3d
+    module procedure define_adios_global_1d_int_4d
+    module procedure define_adios_global_1d_int_5d
+  end interface define_adios_global_integer_1d_array
+
+  interface define_adios_global_long_1d_array
+    module procedure define_adios_global_1d_long_1d
+    module procedure define_adios_global_1d_long_2d
+    module procedure define_adios_global_1d_long_3d
+    module procedure define_adios_global_1d_long_4d
+    module procedure define_adios_global_1d_long_5d
+  end interface define_adios_global_long_1d_array
+
+  interface define_adios_global_logical_1d_array
+    module procedure define_adios_global_1d_logical_1d
+    module procedure define_adios_global_1d_logical_2d
+    module procedure define_adios_global_1d_logical_3d
+    module procedure define_adios_global_1d_logical_4d
+    module procedure define_adios_global_1d_logical_5d
+  end interface define_adios_global_logical_1d_array
+
+  ! Cannot include an interface in another interface
+  interface define_adios_global_array1D
+    module procedure define_adios_global_1d_int_1d
+    module procedure define_adios_global_1d_int_2d
+    module procedure define_adios_global_1d_int_3d
+    module procedure define_adios_global_1d_int_4d
+    module procedure define_adios_global_1d_int_5d
+
+    module procedure define_adios_global_1d_long_1d
+    module procedure define_adios_global_1d_long_2d
+    module procedure define_adios_global_1d_long_3d
+    module procedure define_adios_global_1d_long_4d
+    module procedure define_adios_global_1d_long_5d
+
+    module procedure define_adios_global_1d_logical_1d
+    module procedure define_adios_global_1d_logical_2d
+    module procedure define_adios_global_1d_logical_3d
+    module procedure define_adios_global_1d_logical_4d
+    module procedure define_adios_global_1d_logical_5d
+
+    module procedure define_adios_global_1d_real_1d
+    module procedure define_adios_global_1d_real_2d
+    module procedure define_adios_global_1d_real_3d
+    module procedure define_adios_global_1d_real_4d
+    module procedure define_adios_global_1d_real_5d
+
+    module procedure define_adios_global_1d_double_1d
+    module procedure define_adios_global_1d_double_2d
+    module procedure define_adios_global_1d_double_3d
+    module procedure define_adios_global_1d_double_4d
+    module procedure define_adios_global_1d_double_5d
+  end interface define_adios_global_array1D
+
+contains
+
+
+!===============================================================================
+!> Define an ADIOS scalar double precision variable and autoincrement 
+!! the adios group size by (8).
+!! \param adios_group The adios group where the variables belongs
+!! \param group_size_inc The inout adios group size to increment
+!!                       with the size of the variable
+!! \param path The logical path structuring the data and containing
+!!             the variable 
+!! \param name The variable name in the ADIOS file.
+!! \param var The variable to be defined. Used for type inference. Can be
+!!            ignored.
+!!
+!! \note 'name' and 'var' are written as successive arguments on purpose.
+!!       One should be able to define a macro such as:
+!!       #define STRINGIFY_VAR(x) #x, x
+!!       Calling define_adios_double_scalar with such a macro will be done as:
+!!       call define_adios_double_scalar(group, size, path, STRINGIFY_VAR(x))
+!!       as STRINGIFY_VAR(x) expand as:
+!!       "x", x
+!!       x being the variable name inside the code.
+subroutine define_adios_double_scalar (adios_group, group_size_inc,  &
+    path, name, var)
+  use adios_write_mod
+  implicit none
+  ! Arguments
+  integer(kind=8),  intent(in)    :: adios_group
+  integer(kind=8),  intent(inout) :: group_size_inc
+  character(len=*), intent(in)    :: name, path
+  real(kind=8),     intent(in)    :: var
+  ! Local Variables
+  integer(kind=8)                  :: varid ! dummy variable, adios use var name
+
+  ! adios: 6 == real(kind=8) 
+  call adios_define_var (adios_group, name, path, 6,  "", "", "", varid)
+  group_size_inc = group_size_inc + 8
+end subroutine define_adios_double_scalar
+
+
+!===============================================================================
+!> Define an ADIOS scalar single precision variable and autoincrement 
+!! the adios group size by (8).
+!! \param adios_group The adios group where the variables belongs
+!! \param group_size_inc The inout adios group size to increment
+!!                       with the size of the variable
+!! \param path The logical path structuring the data and containing
+!!             the variable 
+!! \param name The variable name in the ADIOS file.
+!! \param var The variable to be defined. Used for type inference. Can be
+!             ignored.
+!!
+!! \note See define_adios_double_scalar()
+subroutine define_adios_float_scalar(adios_group, group_size_inc,  &
+    path, name, var)
+  use adios_write_mod
+  implicit none
+  ! Arguments
+  integer(kind=8),  intent(in)    :: adios_group
+  integer(kind=8),  intent(inout) :: group_size_inc
+  character(len=*), intent(in)    :: name, path
+  real(kind=4),     intent(in)    :: var
+  ! Local Variables
+  integer(kind=8)                  :: varid ! dummy variable, adios use var name
+
+  ! adios: 6 == real(kind=8) 
+  call adios_define_var (adios_group, name, path, 5,  "", "", "", varid)
+  group_size_inc = group_size_inc + 4
+end subroutine define_adios_float_scalar
+
+
+!===============================================================================
+!> Define an ADIOS scalar integer variable and autoincrement the adios
+!! group size by (4).
+!! \param adios_group The adios group where the variables belongs
+!! \param group_size_inc The inout adios group size to increment
+!!                       with the size of the variable
+!! \param path The logical path structuring the data and containing
+!!             the variable 
+!! \param name The variable name in the ADIOS file.
+!! \param var The variable to be defined. Used for type inference. Can be
+!             ignored.
+!!
+!! \note See define_adios_double_scalar()
+subroutine define_adios_integer_scalar(adios_group, group_size_inc,  &
+    path, name, var)
+  use adios_write_mod
+  implicit none
+  ! Arguments
+  integer(kind=8),  intent(in)     :: adios_group
+  character(len=*), intent(in)     :: name, path
+  integer(kind=8),  intent(inout)  :: group_size_inc
+  integer(kind=4),     intent(in)  :: var
+  ! Local Variables
+  integer(kind=8)                  :: varid ! dummy variable, adios use var name
+
+  ! adios: 2 ~ integer(kind=4) 
+  call adios_define_var (adios_group, name, path, adios_integer,  &
+      "", "", "", varid)
+  group_size_inc = group_size_inc + 4
+end subroutine define_adios_integer_scalar
+
+!===============================================================================
+!> Define an ADIOS scalar byte variable and autoincrement the adios
+!! group size by (1).
+!! \param adios_group The adios group where the variables belongs
+!! \param group_size_inc The inout adios group size to increment
+!!                       with the size of the variable
+!! \param path The logical path structuring the data and containing
+!!             the variable 
+!! \param name The variable name in the ADIOS file.
+!! \param var The variable to be defined. Used for type inference. Can be
+!             ignored.
+!!
+!! \note See define_adios_double_scalar()
+subroutine define_adios_byte_scalar (adios_group, group_size_inc, &
+    name, path, var)
+  use adios_write_mod
+  implicit none
+  ! Arguments
+  integer(kind=8),  intent(in)     :: adios_group
+  character(len=*), intent(in)     :: name, path
+  integer(kind=8),  intent(inout)  :: group_size_inc
+  byte,     intent(in)             :: var
+  ! Local Variables
+  integer(kind=8)                  :: varid ! dummy variable, adios use var name
+
+  ! adios: 0 == byte == any_data_type(kind=1) 
+  call adios_define_var (adios_group, name, path, 0,  "", "", "", varid)
+  group_size_inc = group_size_inc + 1
+end subroutine define_adios_byte_scalar
+
+
+!===============================================================================
+!> Define the dimensions that will be written along a global array in ADIOS.
+!! \param adios_group The adios group where the variables belongs
+!! \param group_size_inc The inout adios group size to increment
+!!                       with the size of the variable
+!! \param array_name The variable to be defined. This is actually the path for
+!!                   ADIOS. The values are stored in array_name/array
+!! \param local_dim The local dimension of the array.
+subroutine define_adios_global_dims_1d(adios_group, group_size_inc, &
+    array_name, local_dim)
+  implicit none
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_group
+  character(len=*), intent(in) :: array_name
+  integer, intent(in) :: local_dim
+  integer(kind=8), intent(inout) :: group_size_inc
+
+  call define_adios_integer_scalar (adios_group, &
+      group_size_inc, array_name, "local_dim", local_dim)
+  call define_adios_integer_scalar (adios_group, &
+      group_size_inc, array_name, "global_dim", local_dim)
+  call define_adios_integer_scalar (adios_group, &
+      group_size_inc, array_name, "offset", local_dim)
+end subroutine define_adios_global_dims_1d
+
+
+!===============================================================================
+!> Define a real global array in ADIOS regardless of the array shape
+!! \param adios_group The adios group where the variables belongs
+!! \param group_size_inc The inout adios group size to increment
+!!                       with the size of the variable
+!! \param array_name The variable to be defined. This is actually the path for
+!!                   ADIOS. The values are stored in array_name/array
+!! \param local_dim The local dimension of the array.
+subroutine define_adios_global_1d_real_generic(adios_group, group_size_inc, &
+    array_name, local_dim)
+  use adios_write_mod
+  implicit none
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_group
+  character(len=*), intent(in) :: array_name
+  integer, intent(in) :: local_dim
+  integer(kind=8), intent(inout) :: group_size_inc
+  ! Variables
+  integer(kind=8) :: var_id
+  
+  ! Define the dimensions of the array. local_dim used as a dummy
+  ! variable to call the integer routine.
+  call define_adios_global_dims_1d(adios_group, group_size_inc, array_name, &
+      local_dim)
+
+  call adios_define_var(adios_group, "array", array_name, 5, &
+      array_name // "/local_dim", array_name // "/global_dim", &
+      array_name // "/offset", var_id)
+  group_size_inc = group_size_inc + local_dim*4
+end subroutine define_adios_global_1d_real_generic
+
+!===============================================================================
+!> Define a global ADIOS 1D real array and autoincrement the adios
+!! group size.
+!! \param adios_group The adios group where the variables belongs
+!! \param group_size_inc The inout adios group size to increment
+!!                       with the size of the variable
+!! \param local_dim The local dimension of the array.
+!! \param path The path where array name lie.
+!! \param array_name The variable to be defined. This is actually the path for
+!!                   ADIOS. The values are stored in array_name/array
+!! \param var The variabe to define. Used for type and shape inference.
+!! \note This function define local, global and offset sizes as well as the
+!!       array to store the values in.
+subroutine define_adios_global_1d_real_1d(adios_group, group_size_inc, &
+    local_dim, path, array_name, var)
+  use adios_write_mod
+  implicit none
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_group
+  character(len=*), intent(in) :: path, array_name
+  integer, intent(in) :: local_dim
+  integer(kind=8), intent(inout) :: group_size_inc
+  real, dimension(:), intent(in) :: var
+ 
+  call define_adios_global_1d_real_generic(adios_group, group_size_inc, &
+      array_name, local_dim)
+end subroutine define_adios_global_1d_real_1d
+
+
+!===============================================================================
+!> Define a global ADIOS 1D real array and autoincrement the adios
+!! group size.
+!! \param adios_group The adios group where the variables belongs
+!! \param group_size_inc The inout adios group size to increment
+!!                       with the size of the variable
+!! \param local_dim The local dimension of the array.
+!! \param path The path where array name lie.
+!! \param array_name The variable to be defined. This is actually the path for
+!!                   ADIOS. The values are stored in array_name/array
+!! \param var The variabe to define. Used for type and shape inference.
+!! \note This function define local, global and offset sizes as well as the
+!!       array to store the values in.
+subroutine define_adios_global_1d_real_2d(adios_group, group_size_inc, &
+    local_dim, path, array_name, var)
+  use adios_write_mod
+  implicit none
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_group
+  character(len=*), intent(in) :: path, array_name
+  integer, intent(in) :: local_dim
+  integer(kind=8), intent(inout) :: group_size_inc
+  real, dimension(:,:), intent(in) :: var
+
+  call define_adios_global_1d_real_generic(adios_group, group_size_inc, &
+      array_name, local_dim)
+end subroutine define_adios_global_1d_real_2d
+
+
+!===============================================================================
+!> Define a global ADIOS 1D real array and autoincrement the adios
+!! group size.
+!! \param adios_group The adios group where the variables belongs
+!! \param group_size_inc The inout adios group size to increment
+!!                       with the size of the variable
+!! \param local_dim The local dimension of the array.
+!! \param path The path where array name lie.
+!! \param array_name The variable to be defined. This is actually the path for
+!!                   ADIOS. The values are stored in array_name/array
+!! \param var The variabe to define. Used for type and shape inference.
+!! \note This function define local, global and offset sizes as well as the
+!!       array to store the values in.
+subroutine define_adios_global_1d_real_3d(adios_group, group_size_inc, &
+    local_dim, path, array_name, var)
+  use adios_write_mod
+  implicit none
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_group
+  character(len=*), intent(in) :: path, array_name
+  integer, intent(in) :: local_dim
+  integer(kind=8), intent(inout) :: group_size_inc
+  real, dimension(:,:,:), intent(in) :: var
+
+  call define_adios_global_1d_real_generic(adios_group, group_size_inc, &
+      array_name, local_dim)
+end subroutine define_adios_global_1d_real_3d
+
+
+!===============================================================================
+!> Define a global ADIOS 1D real array and autoincrement the adios
+!! group size.
+!! \param adios_group The adios group where the variables belongs
+!! \param group_size_inc The inout adios group size to increment
+!!                       with the size of the variable
+!! \param local_dim The local dimension of the array.
+!! \param path The path where array name lie.
+!! \param array_name The variable to be defined. This is actually the path for
+!!                   ADIOS. The values are stored in array_name/array
+!! \param var The variabe to define. Used for type and shape inference.
+!! \note This function define local, global and offset sizes as well as the
+!!       array to store the values in.
+subroutine define_adios_global_1d_real_4d(adios_group, group_size_inc, &
+    local_dim, path, array_name, var)
+  use adios_write_mod
+  implicit none
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_group
+  character(len=*), intent(in) :: path, array_name
+  integer, intent(in) :: local_dim
+  integer(kind=8), intent(inout) :: group_size_inc
+  real, dimension(:,:,:,:), intent(in) :: var
+
+  call define_adios_global_1d_real_generic(adios_group, group_size_inc, &
+      array_name, local_dim)
+end subroutine define_adios_global_1d_real_4d
+
+
+!===============================================================================
+!> Define a global ADIOS 1D real array and autoincrement the adios
+!! group size.
+!! \param adios_group The adios group where the variables belongs
+!! \param group_size_inc The inout adios group size to increment
+!!                       with the size of the variable
+!! \param local_dim The local dimension of the array.
+!! \param path The path where array name lie.
+!! \param array_name The variable to be defined. This is actually the path for
+!!                   ADIOS. The values are stored in array_name/array
+!! \param var The variabe to define. Used for type and shape inference.
+!! \note This function define local, global and offset sizes as well as the
+!!       array to store the values in.
+subroutine define_adios_global_1d_real_5d(adios_group, group_size_inc, &
+    local_dim, path, array_name, var)
+  use adios_write_mod
+  implicit none
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_group
+  character(len=*), intent(in) :: path, array_name
+  integer, intent(in) :: local_dim
+  integer(kind=8), intent(inout) :: group_size_inc
+  real, dimension(:,:,:,:,:), intent(in) :: var
+
+  call define_adios_global_1d_real_generic(adios_group, group_size_inc, &
+      array_name, local_dim)
+end subroutine define_adios_global_1d_real_5d
+
+
+!===============================================================================
+!> Define a double global array in ADIOS regardless of the array shape
+!! \param adios_group The adios group where the variables belongs
+!! \param group_size_inc The inout adios group size to increment
+!!                       with the size of the variable
+!! \param array_name The variable to be defined. This is actually the path for
+!!                   ADIOS. The values are stored in array_name/array
+!! \param local_dim The local dimension of the array.
+subroutine define_adios_global_1d_double_generic(adios_group, group_size_inc, &
+    array_name, local_dim)
+  use adios_write_mod
+  implicit none
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_group
+  character(len=*), intent(in) :: array_name
+  integer, intent(in) :: local_dim
+  integer(kind=8), intent(inout) :: group_size_inc
+  ! Variables
+  integer(kind=8) :: var_id
+  
+  ! Define the dimensions of the array. local_dim used as a dummy
+  ! variable to call the integer routine.
+  call define_adios_global_dims_1d(adios_group, group_size_inc, array_name, &
+      local_dim)
+
+  call adios_define_var(adios_group, "array", array_name, 6, &
+      array_name // "/local_dim", array_name // "/global_dim", &
+      array_name // "/offset", var_id)
+  group_size_inc = group_size_inc + local_dim*8
+end subroutine define_adios_global_1d_double_generic
+
+!===============================================================================
+!> Define a global ADIOS 1D double array and autoincrement the adios
+!! group size.
+!! \param adios_group The adios group where the variables belongs
+!! \param group_size_inc The inout adios group size to increment
+!!                       with the size of the variable
+!! \param local_dim The local dimension of the array.
+!! \param path The path where array name lie.
+!! \param array_name The variable to be defined. This is actually the path for
+!!                   ADIOS. The values are stored in array_name/array
+!! \param var The variabe to define. Used for type and shape inference.
+!! \note This function define local, global and offset sizes as well as the
+!!       array to store the values in.
+subroutine define_adios_global_1d_double_1d(adios_group, group_size_inc, &
+    local_dim, path, array_name, var)
+  use adios_write_mod
+  implicit none
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_group
+  character(len=*), intent(in) :: path, array_name
+  integer, intent(in) :: local_dim
+  integer(kind=8), intent(inout) :: group_size_inc
+  real(kind=8), dimension(:), intent(in) :: var
+ 
+  call define_adios_global_1d_double_generic(adios_group, group_size_inc, &
+      array_name, local_dim)
+end subroutine define_adios_global_1d_double_1d
+
+
+!===============================================================================
+!> Define a global ADIOS 1D double array and autoincrement the adios
+!! group size.
+!! \param adios_group The adios group where the variables belongs
+!! \param group_size_inc The inout adios group size to increment
+!!                       with the size of the variable
+!! \param local_dim The local dimension of the array.
+!! \param path The path where array name lie.
+!! \param array_name The variable to be defined. This is actually the path for
+!!                   ADIOS. The values are stored in array_name/array
+!! \param var The variabe to define. Used for type and shape inference.
+!! \note This function define local, global and offset sizes as well as the
+!!       array to store the values in.
+subroutine define_adios_global_1d_double_2d(adios_group, group_size_inc, &
+    local_dim, path, array_name, var)
+  use adios_write_mod
+  implicit none
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_group
+  character(len=*), intent(in) :: path, array_name
+  integer, intent(in) :: local_dim
+  integer(kind=8), intent(inout) :: group_size_inc
+  real(kind=8), dimension(:,:), intent(in) :: var
+
+  call define_adios_global_1d_double_generic(adios_group, group_size_inc, &
+      array_name, local_dim)
+end subroutine define_adios_global_1d_double_2d
+
+
+!===============================================================================
+!> Define a global ADIOS 1D double array and autoincrement the adios
+!! group size.
+!! \param adios_group The adios group where the variables belongs
+!! \param group_size_inc The inout adios group size to increment
+!!                       with the size of the variable
+!! \param local_dim The local dimension of the array.
+!! \param path The path where array name lie.
+!! \param array_name The variable to be defined. This is actually the path for
+!!                   ADIOS. The values are stored in array_name/array
+!! \param var The variabe to define. Used for type and shape inference.
+!! \note This function define local, global and offset sizes as well as the
+!!       array to store the values in.
+subroutine define_adios_global_1d_double_3d(adios_group, group_size_inc, &
+    local_dim, path, array_name, var)
+  use adios_write_mod
+  implicit none
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_group
+  character(len=*), intent(in) :: path, array_name
+  integer, intent(in) :: local_dim
+  integer(kind=8), intent(inout) :: group_size_inc
+  real(kind=8), dimension(:,:,:), intent(in) :: var
+
+  call define_adios_global_1d_double_generic(adios_group, group_size_inc, &
+      array_name, local_dim)
+end subroutine define_adios_global_1d_double_3d
+
+
+!===============================================================================
+!> Define a global ADIOS 1D double array and autoincrement the adios
+!! group size.
+!! \param adios_group The adios group where the variables belongs
+!! \param group_size_inc The inout adios group size to increment
+!!                       with the size of the variable
+!! \param local_dim The local dimension of the array.
+!! \param path The path where array name lie.
+!! \param array_name The variable to be defined. This is actually the path for
+!!                   ADIOS. The values are stored in array_name/array
+!! \param var The variabe to define. Used for type and shape inference.
+!! \note This function define local, global and offset sizes as well as the
+!!       array to store the values in.
+subroutine define_adios_global_1d_double_4d(adios_group, group_size_inc, &
+    local_dim, path, array_name, var)
+  use adios_write_mod
+  implicit none
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_group
+  character(len=*), intent(in) :: path, array_name
+  integer, intent(in) :: local_dim
+  integer(kind=8), intent(inout) :: group_size_inc
+  real(kind=8), dimension(:,:,:,:), intent(in) :: var
+
+  call define_adios_global_1d_double_generic(adios_group, group_size_inc, &
+      array_name, local_dim)
+end subroutine define_adios_global_1d_double_4d
+
+
+!===============================================================================
+!> Define a global ADIOS 1D double array and autoincrement the adios
+!! group size.
+!! \param adios_group The adios group where the variables belongs
+!! \param group_size_inc The inout adios group size to increment
+!!                       with the size of the variable
+!! \param local_dim The local dimension of the array.
+!! \param path The path where array name lie.
+!! \param array_name The variable to be defined. This is actually the path for
+!!                   ADIOS. The values are stored in array_name/array
+!! \param var The variabe to define. Used for type and shape inference.
+!! \note This function define local, global and offset sizes as well as the
+!!       array to store the values in.
+subroutine define_adios_global_1d_double_5d(adios_group, group_size_inc, &
+    local_dim, path, array_name, var)
+  use adios_write_mod
+  implicit none
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_group
+  character(len=*), intent(in) :: path, array_name
+  integer, intent(in) :: local_dim
+  integer(kind=8), intent(inout) :: group_size_inc
+  real(kind=8), dimension(:,:,:,:,:), intent(in) :: var
+
+  call define_adios_global_1d_double_generic(adios_group, group_size_inc, &
+      array_name, local_dim)
+end subroutine define_adios_global_1d_double_5d
+
+
+!===============================================================================
+!> Define a integer global array in ADIOS regardless of the array shape
+!! \param adios_group The adios group where the variables belongs
+!! \param group_size_inc The inout adios group size to increment
+!!                       with the size of the variable
+!! \param array_name The variable to be defined. This is actually the path for
+!!                   ADIOS. The values are stored in array_name/array
+!! \param local_dim The local dimension of the array.
+subroutine define_adios_global_1d_int_generic(adios_group, group_size_inc, &
+    array_name, local_dim)
+  use adios_write_mod
+  implicit none
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_group
+  character(len=*), intent(in) :: array_name
+  integer, intent(in) :: local_dim
+  integer(kind=8), intent(inout) :: group_size_inc
+  ! Variables
+  integer(kind=8) :: var_id
+  
+  ! Define the dimensions of the array. local_dim used as a dummy
+  ! variable to call the integer routine.
+  call define_adios_global_dims_1d(adios_group, group_size_inc, array_name, &
+      local_dim)
+
+  call adios_define_var(adios_group, "array", array_name, 2, &
+      array_name // "/local_dim", array_name // "/global_dim", &
+      array_name // "/offset", var_id)
+  group_size_inc = group_size_inc + local_dim*4
+end subroutine define_adios_global_1d_int_generic
+
+!===============================================================================
+!> Define a global ADIOS 1D int array and autoincrement the adios
+!! group size.
+!! \param adios_group The adios group where the variables belongs
+!! \param group_size_inc The inout adios group size to increment
+!!                       with the size of the variable
+!! \param local_dim The local dimension of the array.
+!! \param path The path where array name lie.
+!! \param array_name The variable to be defined. This is actually the path for
+!!                   ADIOS. The values are stored in array_name/array
+!! \param var The variabe to define. Used for type and shape inference.
+!! \note This function define local, global and offset sizes as well as the
+!!       array to store the values in.
+subroutine define_adios_global_1d_int_1d(adios_group, group_size_inc, &
+    local_dim, path, array_name, var)
+  use adios_write_mod
+  implicit none
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_group
+  character(len=*), intent(in) :: path, array_name
+  integer, intent(in) :: local_dim
+  integer(kind=8), intent(inout) :: group_size_inc
+  integer(kind=4), dimension(:), intent(in) :: var
+ 
+  call define_adios_global_1d_int_generic(adios_group, group_size_inc, &
+      array_name, local_dim)
+end subroutine define_adios_global_1d_int_1d
+
+
+!===============================================================================
+!> Define a global ADIOS 1D int array and autoincrement the adios
+!! group size.
+!! \param adios_group The adios group where the variables belongs
+!! \param group_size_inc The inout adios group size to increment
+!!                       with the size of the variable
+!! \param local_dim The local dimension of the array.
+!! \param path The path where array name lie.
+!! \param array_name The variable to be defined. This is actually the path for
+!!                   ADIOS. The values are stored in array_name/array
+!! \param var The variabe to define. Used for type and shape inference.
+!! \note This function define local, global and offset sizes as well as the
+!!       array to store the values in.
+subroutine define_adios_global_1d_int_2d(adios_group, group_size_inc, &
+    local_dim, path, array_name, var)
+  use adios_write_mod
+  implicit none
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_group
+  character(len=*), intent(in) :: path, array_name
+  integer, intent(in) :: local_dim
+  integer(kind=8), intent(inout) :: group_size_inc
+  integer(kind=4), dimension(:,:), intent(in) :: var
+
+  call define_adios_global_1d_int_generic(adios_group, group_size_inc, &
+      array_name, local_dim)
+end subroutine define_adios_global_1d_int_2d
+
+
+!===============================================================================
+!> Define a global ADIOS 1D int array and autoincrement the adios
+!! group size.
+!! \param adios_group The adios group where the variables belongs
+!! \param group_size_inc The inout adios group size to increment
+!!                       with the size of the variable
+!! \param local_dim The local dimension of the array.
+!! \param path The path where array name lie.
+!! \param array_name The variable to be defined. This is actually the path for
+!!                   ADIOS. The values are stored in array_name/array
+!! \param var The variabe to define. Used for type and shape inference.
+!! \note This function define local, global and offset sizes as well as the
+!!       array to store the values in.
+subroutine define_adios_global_1d_int_3d(adios_group, group_size_inc, &
+    local_dim, path, array_name, var)
+  use adios_write_mod
+  implicit none
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_group
+  character(len=*), intent(in) :: path, array_name
+  integer, intent(in) :: local_dim
+  integer(kind=8), intent(inout) :: group_size_inc
+  integer(kind=4), dimension(:,:,:), intent(in) :: var
+
+  call define_adios_global_1d_int_generic(adios_group, group_size_inc, &
+      array_name, local_dim)
+end subroutine define_adios_global_1d_int_3d
+
+
+!===============================================================================
+!> Define a global ADIOS 1D int array and autoincrement the adios
+!! group size.
+!! \param adios_group The adios group where the variables belongs
+!! \param group_size_inc The inout adios group size to increment
+!!                       with the size of the variable
+!! \param local_dim The local dimension of the array.
+!! \param path The path where array name lie.
+!! \param array_name The variable to be defined. This is actually the path for
+!!                   ADIOS. The values are stored in array_name/array
+!! \param var The variabe to define. Used for type and shape inference.
+!! \note This function define local, global and offset sizes as well as the
+!!       array to store the values in.
+subroutine define_adios_global_1d_int_4d(adios_group, group_size_inc, &
+    local_dim, path, array_name, var)
+  use adios_write_mod
+  implicit none
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_group
+  character(len=*), intent(in) :: path, array_name
+  integer, intent(in) :: local_dim
+  integer(kind=8), intent(inout) :: group_size_inc
+  integer(kind=4), dimension(:,:,:,:), intent(in) :: var
+
+  call define_adios_global_1d_int_generic(adios_group, group_size_inc, &
+      array_name, local_dim)
+end subroutine define_adios_global_1d_int_4d
+
+
+!===============================================================================
+!> Define a global ADIOS 1D int array and autoincrement the adios
+!! group size.
+!! \param adios_group The adios group where the variables belongs
+!! \param group_size_inc The inout adios group size to increment
+!!                       with the size of the variable
+!! \param local_dim The local dimension of the array.
+!! \param path The path where array name lie.
+!! \param array_name The variable to be defined. This is actually the path for
+!!                   ADIOS. The values are stored in array_name/array
+!! \param var The variabe to define. Used for type and shape inference.
+!! \note This function define local, global and offset sizes as well as the
+!!       array to store the values in.
+subroutine define_adios_global_1d_int_5d(adios_group, group_size_inc, &
+    local_dim, path, array_name, var)
+  use adios_write_mod
+  implicit none
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_group
+  character(len=*), intent(in) :: path, array_name
+  integer, intent(in) :: local_dim
+  integer(kind=8), intent(inout) :: group_size_inc
+  integer(kind=4), dimension(:,:,:,:,:), intent(in) :: var
+
+  call define_adios_global_1d_int_generic(adios_group, group_size_inc, &
+      array_name, local_dim)
+end subroutine define_adios_global_1d_int_5d
+
+
+!===============================================================================
+!> Define a long integer global array in ADIOS regardless of the array shape
+!! \param adios_group The adios group where the variables belongs
+!! \param group_size_inc The inout adios group size to increment
+!!                       with the size of the variable
+!! \param array_name The variable to be defined. This is actually the path for
+!!                   ADIOS. The values are stored in array_name/array
+!! \param local_dim The local dimension of the array.
+subroutine define_adios_global_1d_long_generic(adios_group, group_size_inc, &
+    array_name, local_dim)
+  use adios_write_mod
+  implicit none
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_group
+  character(len=*), intent(in) :: array_name
+  integer, intent(in) :: local_dim
+  integer(kind=8), intent(inout) :: group_size_inc
+  ! Variables
+  integer(kind=8) :: var_id
+  
+  ! Define the dimensions of the array. local_dim used as a dummy
+  ! variable to call the integer routine.
+  call define_adios_global_dims_1d(adios_group, group_size_inc, array_name, &
+      local_dim)
+
+  call adios_define_var(adios_group, "array", array_name, adios_long, &
+      array_name // "/local_dim", array_name // "/global_dim", &
+      array_name // "/offset", var_id)
+  group_size_inc = group_size_inc + local_dim*8
+end subroutine define_adios_global_1d_long_generic
+
+!===============================================================================
+!> Define a global ADIOS 1D long array and autoincrement the adios
+!! group size.
+!! \param adios_group The adios group where the variables belongs
+!! \param group_size_inc The inout adios group size to increment
+!!                       with the size of the variable
+!! \param local_dim The local dimension of the array.
+!! \param path The path where array name lie.
+!! \param array_name The variable to be defined. This is actually the path for
+!!                   ADIOS. The values are stored in array_name/array
+!! \param var The variabe to define. Used for type and shape inference.
+!! \note This function define local, global and offset sizes as well as the
+!!       array to store the values in.
+subroutine define_adios_global_1d_long_1d(adios_group, group_size_inc, &
+    local_dim, path, array_name, var)
+  use adios_write_mod
+  implicit none
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_group
+  character(len=*), intent(in) :: path, array_name
+  integer, intent(in) :: local_dim
+  integer(kind=8), intent(inout) :: group_size_inc
+  integer(kind=8), dimension(:), intent(in) :: var
+ 
+  call define_adios_global_1d_long_generic(adios_group, group_size_inc, &
+      array_name, local_dim)
+end subroutine define_adios_global_1d_long_1d
+
+
+!===============================================================================
+!> Define a global ADIOS 1D long array and autoincrement the adios
+!! group size.
+!! \param adios_group The adios group where the variables belongs
+!! \param group_size_inc The inout adios group size to increment
+!!                       with the size of the variable
+!! \param local_dim The local dimension of the array.
+!! \param path The path where array name lie.
+!! \param array_name The variable to be defined. This is actually the path for
+!!                   ADIOS. The values are stored in array_name/array
+!! \param var The variabe to define. Used for type and shape inference.
+!! \note This function define local, global and offset sizes as well as the
+!!       array to store the values in.
+subroutine define_adios_global_1d_long_2d(adios_group, group_size_inc, &
+    local_dim, path, array_name, var)
+  use adios_write_mod
+  implicit none
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_group
+  character(len=*), intent(in) :: path, array_name
+  integer, intent(in) :: local_dim
+  integer(kind=8), intent(inout) :: group_size_inc
+  integer(kind=8), dimension(:,:), intent(in) :: var
+
+  call define_adios_global_1d_long_generic(adios_group, group_size_inc, &
+      array_name, local_dim)
+end subroutine define_adios_global_1d_long_2d
+
+
+!===============================================================================
+!> Define a global ADIOS 1D int array and autoincrement the adios
+!! group size.
+!! \param adios_group The adios group where the variables belongs
+!! \param group_size_inc The inout adios group size to increment
+!!                       with the size of the variable
+!! \param local_dim The local dimension of the array.
+!! \param path The path where array name lie.
+!! \param array_name The variable to be defined. This is actually the path for
+!!                   ADIOS. The values are stored in array_name/array
+!! \param var The variabe to define. Used for type and shape inference.
+!! \note This function define local, global and offset sizes as well as the
+!!       array to store the values in.
+subroutine define_adios_global_1d_long_3d(adios_group, group_size_inc, &
+    local_dim, path, array_name, var)
+  use adios_write_mod
+  implicit none
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_group
+  character(len=*), intent(in) :: path, array_name
+  integer, intent(in) :: local_dim
+  integer(kind=8), intent(inout) :: group_size_inc
+  integer(kind=8), dimension(:,:,:), intent(in) :: var
+
+  call define_adios_global_1d_long_generic(adios_group, group_size_inc, &
+      array_name, local_dim)
+end subroutine define_adios_global_1d_long_3d
+
+
+!===============================================================================
+!> Define a global ADIOS 1D int array and autoincrement the adios
+!! group size.
+!! \param adios_group The adios group where the variables belongs
+!! \param group_size_inc The inout adios group size to increment
+!!                       with the size of the variable
+!! \param local_dim The local dimension of the array.
+!! \param path The path where array name lie.
+!! \param array_name The variable to be defined. This is actually the path for
+!!                   ADIOS. The values are stored in array_name/array
+!! \param var The variabe to define. Used for type and shape inference.
+!! \note This function define local, global and offset sizes as well as the
+!!       array to store the values in.
+subroutine define_adios_global_1d_long_4d(adios_group, group_size_inc, &
+    local_dim, path, array_name, var)
+  use adios_write_mod
+  implicit none
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_group
+  character(len=*), intent(in) :: path, array_name
+  integer, intent(in) :: local_dim
+  integer(kind=8), intent(inout) :: group_size_inc
+  integer(kind=8), dimension(:,:,:,:), intent(in) :: var
+
+  call define_adios_global_1d_long_generic(adios_group, group_size_inc, &
+      array_name, local_dim)
+end subroutine define_adios_global_1d_long_4d
+
+
+!===============================================================================
+!> Define a global ADIOS 1D long array and autoincrement the adios
+!! group size.
+!! \param adios_group The adios group where the variables belongs
+!! \param group_size_inc The inout adios group size to increment
+!!                       with the size of the variable
+!! \param local_dim The local dimension of the array.
+!! \param path The path where array name lie.
+!! \param array_name The variable to be defined. This is actually the path for
+!!                   ADIOS. The values are stored in array_name/array
+!! \param var The variabe to define. Used for type and shape inference.
+!! \note This function define local, global and offset sizes as well as the
+!!       array to store the values in.
+subroutine define_adios_global_1d_long_5d(adios_group, group_size_inc, &
+    local_dim, path, array_name, var)
+  use adios_write_mod
+  implicit none
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_group
+  character(len=*), intent(in) :: path, array_name
+  integer, intent(in) :: local_dim
+  integer(kind=8), intent(inout) :: group_size_inc
+  integer(kind=8), dimension(:,:,:,:,:), intent(in) :: var
+
+  call define_adios_global_1d_long_generic(adios_group, group_size_inc, &
+      array_name, local_dim)
+end subroutine define_adios_global_1d_long_5d
+
+!===============================================================================
+!> Define a logical global array in ADIOS regardless of the array shape
+!! \param adios_group The adios group where the variables belongs
+!! \param group_size_inc The inout adios group size to increment
+!!                       with the size of the variable
+!! \param array_name The variable to be defined. This is actually the path for
+!!                   ADIOS. The values are stored in array_name/array
+!! \param local_dim The local dimension of the array.
+subroutine define_adios_global_1d_logical_generic(adios_group, group_size_inc, &
+    array_name, local_dim)
+  use adios_write_mod
+  implicit none
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_group
+  character(len=*), intent(in) :: array_name
+  integer, intent(in) :: local_dim
+  integer(kind=8), intent(inout) :: group_size_inc
+  ! Variables
+  integer(kind=8) :: var_id
+  
+  ! Define the dimensions of the array. local_dim used as a dummy
+  ! variable to call the integer routine.
+  call define_adios_global_dims_1d(adios_group, group_size_inc, array_name, &
+      local_dim)
+
+  ! The Fortran standard does not specify how variables of LOGICAL type are
+  ! represented, beyond requiring that LOGICAL variables of default kind 
+  ! have the same storage size as default INTEGER and REAL variables. 
+  ! Hence the 'adios_integer' (2) data type to store logical values
+  call adios_define_var(adios_group, "array", array_name, 2, &
+      array_name // "/local_dim", array_name // "/global_dim", &
+      array_name // "/offset", var_id)
+  group_size_inc = group_size_inc + local_dim*4
+end subroutine define_adios_global_1d_logical_generic
+
+!===============================================================================
+!> Define a global ADIOS 1D logical array and autoincrement the adios
+!! group size.
+!! \param adios_group The adios group where the variables belongs
+!! \param group_size_inc The inout adios group size to increment
+!!                       with the size of the variable
+!! \param local_dim The local dimension of the array.
+!! \param path The path where array name lie.
+!! \param array_name The variable to be defined. This is actually the path for
+!!                   ADIOS. The values are stored in array_name/array
+!! \param var The variabe to define. Used for type and shape inference.
+!! \note This function define local, global and offset sizes as well as the
+!!       array to store the values in.
+subroutine define_adios_global_1d_logical_1d(adios_group, group_size_inc, &
+    local_dim, path, array_name, var)
+  use adios_write_mod
+  implicit none
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_group
+  character(len=*), intent(in) :: path, array_name
+  integer, intent(in) :: local_dim
+  integer(kind=8), intent(inout) :: group_size_inc
+  logical, dimension(:), intent(in) :: var
+ 
+  call define_adios_global_1d_logical_generic(adios_group, group_size_inc, &
+      array_name, local_dim)
+end subroutine define_adios_global_1d_logical_1d
+
+
+!===============================================================================
+!> Define a global ADIOS 1D logical array and autoincrement the adios
+!! group size.
+!! \param adios_group The adios group where the variables belongs
+!! \param group_size_inc The inout adios group size to increment
+!!                       with the size of the variable
+!! \param local_dim The local dimension of the array.
+!! \param path The path where array name lie.
+!! \param array_name The variable to be defined. This is actually the path for
+!!                   ADIOS. The values are stored in array_name/array
+!! \param var The variabe to define. Used for type and shape inference.
+!! \note This function define local, global and offset sizes as well as the
+!!       array to store the values in.
+subroutine define_adios_global_1d_logical_2d(adios_group, group_size_inc, &
+    local_dim, path, array_name, var)
+  use adios_write_mod
+  implicit none
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_group
+  character(len=*), intent(in) :: path, array_name
+  integer, intent(in) :: local_dim
+  integer(kind=8), intent(inout) :: group_size_inc
+  logical, dimension(:,:), intent(in) :: var
+
+  call define_adios_global_1d_logical_generic(adios_group, group_size_inc, &
+      array_name, local_dim)
+end subroutine define_adios_global_1d_logical_2d
+
+
+!===============================================================================
+!> Define a global ADIOS 1D logical array and autoincrement the adios
+!! group size.
+!! \param adios_group The adios group where the variables belongs
+!! \param group_size_inc The inout adios group size to increment
+!!                       with the size of the variable
+!! \param local_dim The local dimension of the array.
+!! \param path The path where array name lie.
+!! \param array_name The variable to be defined. This is actually the path for
+!!                   ADIOS. The values are stored in array_name/array
+!! \param var The variabe to define. Used for type and shape inference.
+!! \note This function define local, global and offset sizes as well as the
+!!       array to store the values in.
+subroutine define_adios_global_1d_logical_3d(adios_group, group_size_inc, &
+    local_dim, path, array_name, var)
+  use adios_write_mod
+  implicit none
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_group
+  character(len=*), intent(in) :: path, array_name
+  integer, intent(in) :: local_dim
+  integer(kind=8), intent(inout) :: group_size_inc
+  logical, dimension(:,:,:), intent(in) :: var
+
+  call define_adios_global_1d_logical_generic(adios_group, group_size_inc, &
+      array_name, local_dim)
+end subroutine define_adios_global_1d_logical_3d
+
+
+!===============================================================================
+!> Define a global ADIOS 1D logical array and autoincrement the adios
+!! group size.
+!! \param adios_group The adios group where the variables belongs
+!! \param group_size_inc The inout adios group size to increment
+!!                       with the size of the variable
+!! \param local_dim The local dimension of the array.
+!! \param path The path where array name lie.
+!! \param array_name The variable to be defined. This is actually the path for
+!!                   ADIOS. The values are stored in array_name/array
+!! \param var The variabe to define. Used for type and shape inference.
+!! \note This function define local, global and offset sizes as well as the
+!!       array to store the values in.
+subroutine define_adios_global_1d_logical_4d(adios_group, group_size_inc, &
+    local_dim, path, array_name, var)
+  use adios_write_mod
+  implicit none
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_group
+  character(len=*), intent(in) :: path, array_name
+  integer, intent(in) :: local_dim
+  integer(kind=8), intent(inout) :: group_size_inc
+  logical, dimension(:,:,:,:), intent(in) :: var
+
+  call define_adios_global_1d_logical_generic(adios_group, group_size_inc, &
+      array_name, local_dim)
+end subroutine define_adios_global_1d_logical_4d
+
+
+!===============================================================================
+!> Define a global ADIOS 1D logical array and autoincrement the adios
+!! group size.
+!! \param adios_group The adios group where the variables belongs
+!! \param group_size_inc The inout adios group size to increment
+!!                       with the size of the variable
+!! \param local_dim The local dimension of the array.
+!! \param path The path where array name lie.
+!! \param array_name The variable to be defined. This is actually the path for
+!!                   ADIOS. The values are stored in array_name/array
+!! \param var The variabe to define. Used for type and shape inference.
+!! \note This function define local, global and offset sizes as well as the
+!!       array to store the values in.
+subroutine define_adios_global_1d_logical_5d(adios_group, group_size_inc, &
+    local_dim, path, array_name, var)
+  use adios_write_mod
+  implicit none
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_group
+  character(len=*), intent(in) :: path, array_name
+  integer, intent(in) :: local_dim
+  integer(kind=8), intent(inout) :: group_size_inc
+  logical, dimension(:,:,:,:,:), intent(in) :: var
+
+  call define_adios_global_1d_logical_generic(adios_group, group_size_inc, &
+      array_name, local_dim)
+end subroutine define_adios_global_1d_logical_5d
+
+end module adios_helpers_definitions_mod

Added: seismo/3D/SPECFEM3D/trunk/src/shared/adios_helpers_writers.f90
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/shared/adios_helpers_writers.f90	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/src/shared/adios_helpers_writers.f90	2013-09-18 14:35:14 UTC (rev 22798)
@@ -0,0 +1,848 @@
+!=====================================================================
+!
+!          S p e c f e m 3 D  G l o b e  V e r s i o n  5 . 1
+!          --------------------------------------------------
+!
+!          Main authors: Dimitri Komatitsch and Jeroen Tromp
+!                        Princeton University, USA
+!             and University of Pau / CNRS / INRIA, France
+! (c) Princeton University / California Institute of Technology and University of Pau / CNRS / INRIA
+!                            April 2011
+!
+! This 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 02110-1301 USA.
+!
+!=====================================================================
+
+
+!===============================================================================
+!> Helpers to set up adios features.
+!! * Scalar definition
+!! * Global arrays definition
+!!
+!! \note We do not define function to write scalars variables into adios
+!!       since it is already a single function call.
+!!
+!! \author MPBL      
+!-------------------------------------------------------------------------------
+module adios_helpers_writers_mod
+  implicit none
+
+  private
+
+  public :: write_adios_global_real_1d_array
+  public :: write_adios_global_double_1d_array
+  public :: write_adios_global_integer_1d_array
+  public :: write_adios_global_long_1d_array
+  public :: write_adios_global_logical_1d_array
+  public :: write_adios_global_1d_array
+
+  interface write_adios_global_real_1d_array
+    module procedure write_adios_global_1d_real_1d
+    module procedure write_adios_global_1d_real_2d
+    module procedure write_adios_global_1d_real_3d
+    module procedure write_adios_global_1d_real_4d
+    module procedure write_adios_global_1d_real_5d
+  end interface write_adios_global_real_1d_array
+
+  interface write_adios_global_double_1d_array
+    module procedure write_adios_global_1d_double_1d
+    module procedure write_adios_global_1d_double_2d
+    module procedure write_adios_global_1d_double_3d
+    module procedure write_adios_global_1d_double_4d
+    module procedure write_adios_global_1d_double_5d
+  end interface write_adios_global_double_1d_array
+
+  interface write_adios_global_integer_1d_array
+    module procedure write_adios_global_1d_integer_1d
+    module procedure write_adios_global_1d_integer_2d
+    module procedure write_adios_global_1d_integer_3d
+    module procedure write_adios_global_1d_integer_4d
+    module procedure write_adios_global_1d_integer_5d
+  end interface write_adios_global_integer_1d_array
+
+  interface write_adios_global_long_1d_array
+    module procedure write_adios_global_1d_long_1d
+    module procedure write_adios_global_1d_long_2d
+    module procedure write_adios_global_1d_long_3d
+    module procedure write_adios_global_1d_long_4d
+    module procedure write_adios_global_1d_long_5d
+  end interface write_adios_global_long_1d_array
+
+  interface write_adios_global_logical_1d_array
+    module procedure write_adios_global_1d_logical_1d
+    module procedure write_adios_global_1d_logical_2d
+    module procedure write_adios_global_1d_logical_3d
+    module procedure write_adios_global_1d_logical_4d
+    module procedure write_adios_global_1d_logical_5d
+  end interface write_adios_global_logical_1d_array
+
+  interface write_adios_global_1d_array
+    module procedure write_adios_global_1d_integer_1d
+    module procedure write_adios_global_1d_integer_2d
+    module procedure write_adios_global_1d_integer_3d
+    module procedure write_adios_global_1d_integer_4d
+    module procedure write_adios_global_1d_integer_5d
+
+    module procedure write_adios_global_1d_long_1d
+    module procedure write_adios_global_1d_long_2d
+    module procedure write_adios_global_1d_long_3d
+    module procedure write_adios_global_1d_long_4d
+    module procedure write_adios_global_1d_long_5d
+
+    module procedure write_adios_global_1d_logical_1d
+    module procedure write_adios_global_1d_logical_2d
+    module procedure write_adios_global_1d_logical_3d
+    module procedure write_adios_global_1d_logical_4d
+    module procedure write_adios_global_1d_logical_5d
+
+    module procedure write_adios_global_1d_real_1d
+    module procedure write_adios_global_1d_real_2d
+    module procedure write_adios_global_1d_real_3d
+    module procedure write_adios_global_1d_real_4d
+    module procedure write_adios_global_1d_real_5d
+
+    module procedure write_adios_global_1d_double_1d
+    module procedure write_adios_global_1d_double_2d
+    module procedure write_adios_global_1d_double_3d
+    module procedure write_adios_global_1d_double_4d
+    module procedure write_adios_global_1d_double_5d
+  end interface write_adios_global_1d_array
+
+contains
+
+
+!===============================================================================
+subroutine write_1D_global_array_adios_dims(adios_handle, myrank, &
+    local_dim, sizeprocs, path)
+  use adios_write_mod
+
+  implicit none
+
+  integer(kind=8), intent(in) :: adios_handle
+  integer, intent(in) :: sizeprocs, local_dim, myrank
+  character(len=*), intent(in) :: path
+
+  integer :: adios_err
+
+  call adios_write(adios_handle, path // "/local_dim", &
+                   local_dim, adios_err)
+  call adios_write(adios_handle, path // "/global_dim", &
+                   local_dim*sizeprocs, adios_err)
+  call adios_write(adios_handle, path // "/offset", &
+                   local_dim*myrank, adios_err)
+end subroutine write_1D_global_array_adios_dims
+
+
+!===============================================================================
+!> Schedule an ADIOS single precision global 1d array for write
+!! \param adios_handle The adios handle to the file to be written
+!! \param myrank The rank of the MPI process involved
+!! \param sizeprocs The number of MPI process in the communicator writing the
+!!                  variable
+!! \param local_dim The number of elements to be writen by each process. Might
+!!                  eventually be padded.
+!! \param path The logical path structuring the data and containing
+!!             the variable 
+!! \param array_name The array name in the ADIOS file.
+!! \param array The array to be written
+subroutine write_adios_global_1d_real_1d(adios_handle, myrank, sizeprocs, &
+    local_dim, array_name, array)
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_handle
+  integer, intent(in) :: myrank, sizeprocs, local_dim
+  character(len=*) :: array_name
+  real, dimension(:), intent(in) :: array
+  ! Variables
+  integer :: adios_err
+
+  call write_1D_global_array_adios_dims(adios_handle, myrank, &
+      local_dim, sizeprocs, array_name)
+  call adios_write(adios_handle, array_name // "/array", array, adios_err)
+end subroutine write_adios_global_1d_real_1d
+
+
+!===============================================================================
+!> Schedule an ADIOS single precision global 1d array for write
+!! \param adios_handle The adios handle to the file to be written
+!! \param myrank The rank of the MPI process involved
+!! \param sizeprocs The number of MPI process in the communicator writing the
+!!                  variable
+!! \param local_dim The number of elements to be writen by each process. Might
+!!                  eventually be padded.
+!! \param path The logical path structuring the data and containing
+!!             the variable 
+!! \param array_name The array name in the ADIOS file.
+!! \param array The array to be written
+subroutine write_adios_global_1d_real_2d(adios_handle, myrank, sizeprocs, &
+    local_dim, array_name, array)
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_handle
+  integer, intent(in) :: myrank, sizeprocs, local_dim
+  character(len=*) :: array_name
+  real, dimension(:,:), intent(in) :: array
+  ! Variables
+  integer :: adios_err
+
+  call write_1D_global_array_adios_dims(adios_handle, myrank, &
+      local_dim, sizeprocs, array_name)
+  call adios_write(adios_handle, array_name // "/array", array, adios_err)
+end subroutine write_adios_global_1d_real_2d
+
+
+!===============================================================================
+!> Schedule an ADIOS single precision global 1d array for write
+!! \param adios_handle The adios handle to the file to be written
+!! \param myrank The rank of the MPI process involved
+!! \param sizeprocs The number of MPI process in the communicator writing the
+!!                  variable
+!! \param local_dim The number of elements to be writen by each process. Might
+!!                  eventually be padded.
+!! \param path The logical path structuring the data and containing
+!!             the variable 
+!! \param array_name The array name in the ADIOS file.
+!! \param array The array to be written
+subroutine write_adios_global_1d_real_3d(adios_handle, myrank, sizeprocs, &
+    local_dim, array_name, array)
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_handle
+  integer, intent(in) :: myrank, sizeprocs, local_dim
+  character(len=*) :: array_name
+  real, dimension(:,:,:), intent(in) :: array
+  ! Variables
+  integer :: adios_err
+
+  call write_1D_global_array_adios_dims(adios_handle, myrank, &
+      local_dim, sizeprocs, array_name)
+  call adios_write(adios_handle, array_name // "/array", array, adios_err)
+end subroutine write_adios_global_1d_real_3d
+
+
+!===============================================================================
+!> Schedule an ADIOS single precision global 1d array for write
+!! \param adios_handle The adios handle to the file to be written
+!! \param myrank The rank of the MPI process involved
+!! \param sizeprocs The number of MPI process in the communicator writing the
+!!                  variable
+!! \param local_dim The number of elements to be writen by each process. Might
+!!                  eventually be padded.
+!! \param path The logical path structuring the data and containing
+!!             the variable 
+!! \param array_name The array name in the ADIOS file.
+!! \param array The array to be written
+subroutine write_adios_global_1d_real_4d(adios_handle, myrank, sizeprocs, &
+    local_dim, array_name, array)
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_handle
+  integer, intent(in) :: myrank, sizeprocs, local_dim
+  character(len=*) :: array_name
+  real, dimension(:,:,:,:), intent(in) :: array
+  ! Variables
+  integer :: adios_err
+
+  call write_1D_global_array_adios_dims(adios_handle, myrank, &
+      local_dim, sizeprocs, array_name)
+  call adios_write(adios_handle, array_name // "/array", array, adios_err)
+end subroutine write_adios_global_1d_real_4d
+
+
+!===============================================================================
+!> Schedule an ADIOS single precision global 1d array for write
+!! \param adios_handle The adios handle to the file to be written
+!! \param myrank The rank of the MPI process involved
+!! \param sizeprocs The number of MPI process in the communicator writing the
+!!                  variable
+!! \param local_dim The number of elements to be writen by each process. Might
+!!                  eventually be padded.
+!! \param path The logical path structuring the data and containing
+!!             the variable 
+!! \param array_name The array name in the ADIOS file.
+!! \param array The array to be written
+subroutine write_adios_global_1d_real_5d(adios_handle, myrank, sizeprocs, &
+    local_dim, array_name, array)
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_handle
+  integer, intent(in) :: myrank, sizeprocs, local_dim
+  character(len=*) :: array_name
+  real, dimension(:,:,:,:,:), intent(in) :: array
+  ! Variables
+  integer :: adios_err
+
+  call write_1D_global_array_adios_dims(adios_handle, myrank, &
+      local_dim, sizeprocs, array_name)
+  call adios_write(adios_handle, array_name // "/array", array, adios_err)
+end subroutine write_adios_global_1d_real_5d
+
+
+!===============================================================================
+!> Schedule an ADIOS double precision global 1d array for write
+!! \param adios_handle The adios handle to the file to be written
+!! \param myrank The rank of the MPI process involved
+!! \param sizeprocs The number of MPI process in the communicator writing the
+!!                  variable
+!! \param local_dim The number of elements to be writen by each process. Might
+!!                  eventually be padded.
+!! \param path The logical path structuring the data and containing
+!!             the variable 
+!! \param array_name The array name in the ADIOS file.
+!! \param array The array to be written
+subroutine write_adios_global_1d_double_1d(adios_handle, myrank, sizeprocs, &
+    local_dim, array_name, array)
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_handle
+  integer, intent(in) :: myrank, sizeprocs, local_dim
+  character(len=*) :: array_name
+  real(kind=8), dimension(:), intent(in) :: array
+  ! Variables
+  integer :: adios_err
+
+  call write_1D_global_array_adios_dims(adios_handle, myrank, &
+      local_dim, sizeprocs, array_name)
+  call adios_write(adios_handle, array_name // "/array", array, adios_err)
+end subroutine write_adios_global_1d_double_1d
+
+
+!===============================================================================
+!> Schedule an ADIOS double precision global 1d array for write
+!! \param adios_handle The adios handle to the file to be written
+!! \param myrank The rank of the MPI process involved
+!! \param sizeprocs The number of MPI process in the communicator writing the
+!!                  variable
+!! \param local_dim The number of elements to be writen by each process. Might
+!!                  eventually be padded.
+!! \param path The logical path structuring the data and containing
+!!             the variable 
+!! \param array_name The array name in the ADIOS file.
+!! \param array The array to be written
+subroutine write_adios_global_1d_double_2d(adios_handle, myrank, sizeprocs, &
+    local_dim, array_name, array)
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_handle
+  integer, intent(in) :: myrank, sizeprocs, local_dim
+  character(len=*) :: array_name
+  real(kind=8), dimension(:,:), intent(in) :: array
+  ! Variables
+  integer :: adios_err
+
+  call write_1D_global_array_adios_dims(adios_handle, myrank, &
+      local_dim, sizeprocs, array_name)
+  call adios_write(adios_handle, array_name // "/array", array, adios_err)
+end subroutine write_adios_global_1d_double_2d
+
+
+!===============================================================================
+!> Schedule an ADIOS double precision global 1d array for write
+!! \param adios_handle The adios handle to the file to be written
+!! \param myrank The rank of the MPI process involved
+!! \param sizeprocs The number of MPI process in the communicator writing the
+!!                  variable
+!! \param local_dim The number of elements to be writen by each process. Might
+!!                  eventually be padded.
+!! \param path The logical path structuring the data and containing
+!!             the variable 
+!! \param array_name The array name in the ADIOS file.
+!! \param array The array to be written
+subroutine write_adios_global_1d_double_3d(adios_handle, myrank, sizeprocs, &
+    local_dim, array_name, array)
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_handle
+  integer, intent(in) :: myrank, sizeprocs, local_dim
+  character(len=*) :: array_name
+  real(kind=8), dimension(:,:,:), intent(in) :: array
+  ! Variables
+  integer :: adios_err
+
+  call write_1D_global_array_adios_dims(adios_handle, myrank, &
+      local_dim, sizeprocs, array_name)
+  call adios_write(adios_handle, array_name // "/array", array, adios_err)
+end subroutine write_adios_global_1d_double_3d
+
+
+!===============================================================================
+!> Schedule an ADIOS double precision global 1d array for write
+!! \param adios_handle The adios handle to the file to be written
+!! \param myrank The rank of the MPI process involved
+!! \param sizeprocs The number of MPI process in the communicator writing the
+!!                  variable
+!! \param local_dim The number of elements to be writen by each process. Might
+!!                  eventually be padded.
+!! \param path The logical path structuring the data and containing
+!!             the variable 
+!! \param array_name The array name in the ADIOS file.
+!! \param array The array to be written
+subroutine write_adios_global_1d_double_4d(adios_handle, myrank, sizeprocs, &
+    local_dim, array_name, array)
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_handle
+  integer, intent(in) :: myrank, sizeprocs, local_dim
+  character(len=*) :: array_name
+  real(kind=8), dimension(:,:,:,:), intent(in) :: array
+  ! Variables
+  integer :: adios_err
+
+  call write_1D_global_array_adios_dims(adios_handle, myrank, &
+      local_dim, sizeprocs, array_name)
+  call adios_write(adios_handle, array_name // "/array", array, adios_err)
+end subroutine write_adios_global_1d_double_4d
+
+
+!===============================================================================
+!> Schedule an ADIOS double precision global 1d array for write
+!! \param adios_handle The adios handle to the file to be written
+!! \param myrank The rank of the MPI process involved
+!! \param sizeprocs The number of MPI process in the communicator writing the
+!!                  variable
+!! \param local_dim The number of elements to be writen by each process. Might
+!!                  eventually be padded.
+!! \param path The logical path structuring the data and containing
+!!             the variable 
+!! \param array_name The array name in the ADIOS file.
+!! \param array The array to be written
+subroutine write_adios_global_1d_double_5d(adios_handle, myrank, sizeprocs, &
+    local_dim, array_name, array)
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_handle
+  integer, intent(in) :: myrank, sizeprocs, local_dim
+  character(len=*) :: array_name
+  real(kind=8), dimension(:,:,:,:,:), intent(in) :: array
+  ! Variables
+  integer :: adios_err
+
+  call write_1D_global_array_adios_dims(adios_handle, myrank, &
+      local_dim, sizeprocs, array_name)
+  call adios_write(adios_handle, array_name // "/array", array, adios_err)
+end subroutine write_adios_global_1d_double_5d
+
+
+!===============================================================================
+!> Schedule an ADIOS integer global 1d array for write
+!! \param adios_handle The adios handle to the file to be written
+!! \param myrank The rank of the MPI process involved
+!! \param sizeprocs The number of MPI process in the communicator writing the
+!!                  variable
+!! \param local_dim The number of elements to be writen by each process. Might
+!!                  eventually be padded.
+!! \param path The logical path structuring the data and containing
+!!             the variable 
+!! \param array_name The array name in the ADIOS file.
+!! \param array The array to be written
+subroutine write_adios_global_1d_integer_1d(adios_handle, myrank, sizeprocs, &
+    local_dim, array_name, array)
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_handle
+  integer, intent(in) :: myrank, sizeprocs, local_dim
+  character(len=*) :: array_name
+  integer(kind=4), dimension(:), intent(in) :: array
+  ! Variables
+  integer :: adios_err
+
+  call write_1D_global_array_adios_dims(adios_handle, myrank, &
+      local_dim, sizeprocs, array_name)
+  call adios_write(adios_handle, array_name // "/array", array, adios_err)
+end subroutine write_adios_global_1d_integer_1d
+
+
+!===============================================================================
+!> Schedule an ADIOS integer global 1d array for write
+!! \param adios_handle The adios handle to the file to be written
+!! \param myrank The rank of the MPI process involved
+!! \param sizeprocs The number of MPI process in the communicator writing the
+!!                  variable
+!! \param local_dim The number of elements to be writen by each process. Might
+!!                  eventually be padded.
+!! \param path The logical path structuring the data and containing
+!!             the variable 
+!! \param array_name The array name in the ADIOS file.
+!! \param array The array to be written
+subroutine write_adios_global_1d_integer_2d(adios_handle, myrank, sizeprocs, &
+    local_dim, array_name, array)
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_handle
+  integer, intent(in) :: myrank, sizeprocs, local_dim
+  character(len=*) :: array_name
+  integer(kind=4), dimension(:,:), intent(in) :: array
+  ! Variables
+  integer :: adios_err
+
+  call write_1D_global_array_adios_dims(adios_handle, myrank, &
+      local_dim, sizeprocs, array_name)
+  call adios_write(adios_handle, array_name // "/array", array, adios_err)
+end subroutine write_adios_global_1d_integer_2d
+
+
+!===============================================================================
+!> Schedule an ADIOS integer global 1d array for write
+!! \param adios_handle The adios handle to the file to be written
+!! \param myrank The rank of the MPI process involved
+!! \param sizeprocs The number of MPI process in the communicator writing the
+!!                  variable
+!! \param local_dim The number of elements to be writen by each process. Might
+!!                  eventually be padded.
+!! \param path The logical path structuring the data and containing
+!!             the variable 
+!! \param array_name The array name in the ADIOS file.
+!! \param array The array to be written
+subroutine write_adios_global_1d_integer_3d(adios_handle, myrank, sizeprocs, &
+    local_dim, array_name, array)
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_handle
+  integer, intent(in) :: myrank, sizeprocs, local_dim
+  character(len=*) :: array_name
+  integer(kind=4), dimension(:,:,:), intent(in) :: array
+  ! Variables
+  integer :: adios_err
+
+  call write_1D_global_array_adios_dims(adios_handle, myrank, &
+      local_dim, sizeprocs, array_name)
+  call adios_write(adios_handle, array_name // "/array", array, adios_err)
+end subroutine write_adios_global_1d_integer_3d
+
+
+!===============================================================================
+!> Schedule an ADIOS integer global 1d array for write
+!! \param adios_handle The adios handle to the file to be written
+!! \param myrank The rank of the MPI process involved
+!! \param sizeprocs The number of MPI process in the communicator writing the
+!!                  variable
+!! \param local_dim The number of elements to be writen by each process. Might
+!!                  eventually be padded.
+!! \param path The logical path structuring the data and containing
+!!             the variable 
+!! \param array_name The array name in the ADIOS file.
+!! \param array The array to be written
+subroutine write_adios_global_1d_integer_4d(adios_handle, myrank, sizeprocs, &
+    local_dim, array_name, array)
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_handle
+  integer, intent(in) :: myrank, sizeprocs, local_dim
+  character(len=*) :: array_name
+  integer(kind=4), dimension(:,:,:,:), intent(in) :: array
+  ! Variables
+  integer :: adios_err
+
+  call write_1D_global_array_adios_dims(adios_handle, myrank, &
+      local_dim, sizeprocs, array_name)
+  call adios_write(adios_handle, array_name // "/array", array, adios_err)
+end subroutine write_adios_global_1d_integer_4d
+
+
+!===============================================================================
+!> Schedule an ADIOS integer global 1d array for write
+!! \param adios_handle The adios handle to the file to be written
+!! \param myrank The rank of the MPI process involved
+!! \param sizeprocs The number of MPI process in the communicator writing the
+!!                  variable
+!! \param local_dim The number of elements to be writen by each process. Might
+!!                  eventually be padded.
+!! \param path The logical path structuring the data and containing
+!!             the variable 
+!! \param array_name The array name in the ADIOS file.
+!! \param array The array to be written
+subroutine write_adios_global_1d_integer_5d(adios_handle, myrank, sizeprocs, &
+    local_dim, array_name, array)
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_handle
+  integer, intent(in) :: myrank, sizeprocs, local_dim
+  character(len=*) :: array_name
+  integer(kind=4), dimension(:,:,:,:,:), intent(in) :: array
+  ! Variables
+  integer :: adios_err
+
+  call write_1D_global_array_adios_dims(adios_handle, myrank, &
+      local_dim, sizeprocs, array_name)
+  call adios_write(adios_handle, array_name // "/array", array, adios_err)
+end subroutine write_adios_global_1d_integer_5d
+
+
+!===============================================================================
+!> Schedule an ADIOS long global 1d array for write
+!! \param adios_handle The adios handle to the file to be written
+!! \param myrank The rank of the MPI process involved
+!! \param sizeprocs The number of MPI process in the communicator writing the
+!!                  variable
+!! \param local_dim The number of elements to be writen by each process. Might
+!!                  eventually be padded.
+!! \param path The logical path structuring the data and containing
+!!             the variable 
+!! \param array_name The array name in the ADIOS file.
+!! \param array The array to be written
+subroutine write_adios_global_1d_long_1d(adios_handle, myrank, sizeprocs, &
+    local_dim, array_name, array)
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_handle
+  integer, intent(in) :: myrank, sizeprocs, local_dim
+  character(len=*) :: array_name
+  integer(kind=8), dimension(:), intent(in) :: array
+  ! Variables
+  integer :: adios_err
+
+  call write_1D_global_array_adios_dims(adios_handle, myrank, &
+      local_dim, sizeprocs, array_name)
+  call adios_write(adios_handle, array_name // "/array", array, adios_err)
+end subroutine write_adios_global_1d_long_1d
+
+
+!===============================================================================
+!> Schedule an ADIOS long global 1d array for write
+!! \param adios_handle The adios handle to the file to be written
+!! \param myrank The rank of the MPI process involved
+!! \param sizeprocs The number of MPI process in the communicator writing the
+!!                  variable
+!! \param local_dim The number of elements to be writen by each process. Might
+!!                  eventually be padded.
+!! \param path The logical path structuring the data and containing
+!!             the variable 
+!! \param array_name The array name in the ADIOS file.
+!! \param array The array to be written
+subroutine write_adios_global_1d_long_2d(adios_handle, myrank, sizeprocs, &
+    local_dim, array_name, array)
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_handle
+  integer, intent(in) :: myrank, sizeprocs, local_dim
+  character(len=*) :: array_name
+  integer(kind=8), dimension(:,:), intent(in) :: array
+  ! Variables
+  integer :: adios_err
+
+  call write_1D_global_array_adios_dims(adios_handle, myrank, &
+      local_dim, sizeprocs, array_name)
+  call adios_write(adios_handle, array_name // "/array", array, adios_err)
+end subroutine write_adios_global_1d_long_2d
+
+
+!===============================================================================
+!> Schedule an ADIOS long global 1d array for write
+!! \param adios_handle The adios handle to the file to be written
+!! \param myrank The rank of the MPI process involved
+!! \param sizeprocs The number of MPI process in the communicator writing the
+!!                  variable
+!! \param local_dim The number of elements to be writen by each process. Might
+!!                  eventually be padded.
+!! \param path The logical path structuring the data and containing
+!!             the variable 
+!! \param array_name The array name in the ADIOS file.
+!! \param array The array to be written
+subroutine write_adios_global_1d_long_3d(adios_handle, myrank, sizeprocs, &
+    local_dim, array_name, array)
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_handle
+  integer, intent(in) :: myrank, sizeprocs, local_dim
+  character(len=*) :: array_name
+  integer(kind=8), dimension(:,:,:), intent(in) :: array
+  ! Variables
+  integer :: adios_err
+
+  call write_1D_global_array_adios_dims(adios_handle, myrank, &
+      local_dim, sizeprocs, array_name)
+  call adios_write(adios_handle, array_name // "/array", array, adios_err)
+end subroutine write_adios_global_1d_long_3d
+
+
+!===============================================================================
+!> Schedule an ADIOS integer global 1d array for write
+!! \param adios_handle The adios handle to the file to be written
+!! \param myrank The rank of the MPI process involved
+!! \param sizeprocs The number of MPI process in the communicator writing the
+!!                  variable
+!! \param local_dim The number of elements to be writen by each process. Might
+!!                  eventually be padded.
+!! \param path The logical path structuring the data and containing
+!!             the variable 
+!! \param array_name The array name in the ADIOS file.
+!! \param array The array to be written
+subroutine write_adios_global_1d_long_4d(adios_handle, myrank, sizeprocs, &
+    local_dim, array_name, array)
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_handle
+  integer, intent(in) :: myrank, sizeprocs, local_dim
+  character(len=*) :: array_name
+  integer(kind=8), dimension(:,:,:,:), intent(in) :: array
+  ! Variables
+  integer :: adios_err
+
+  call write_1D_global_array_adios_dims(adios_handle, myrank, &
+      local_dim, sizeprocs, array_name)
+  call adios_write(adios_handle, array_name // "/array", array, adios_err)
+end subroutine write_adios_global_1d_long_4d
+
+
+!===============================================================================
+!> Schedule an ADIOS long global 1d array for write
+!! \param adios_handle The adios handle to the file to be written
+!! \param myrank The rank of the MPI process involved
+!! \param sizeprocs The number of MPI process in the communicator writing the
+!!                  variable
+!! \param local_dim The number of elements to be writen by each process. Might
+!!                  eventually be padded.
+!! \param path The logical path structuring the data and containing
+!!             the variable 
+!! \param array_name The array name in the ADIOS file.
+!! \param array The array to be written
+subroutine write_adios_global_1d_long_5d(adios_handle, myrank, sizeprocs, &
+    local_dim, array_name, array)
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_handle
+  integer, intent(in) :: myrank, sizeprocs, local_dim
+  character(len=*) :: array_name
+  integer(kind=8), dimension(:,:,:,:,:), intent(in) :: array
+  ! Variables
+  integer :: adios_err
+
+  call write_1D_global_array_adios_dims(adios_handle, myrank, &
+      local_dim, sizeprocs, array_name)
+  call adios_write(adios_handle, array_name // "/array", array, adios_err)
+end subroutine write_adios_global_1d_long_5d
+
+
+!===============================================================================
+!> Schedule an ADIOS logical global 1d array for write
+!! \param adios_handle The adios handle to the file to be written
+!! \param myrank The rank of the MPI process involved
+!! \param sizeprocs The number of MPI process in the communicator writing the
+!!                  variable
+!! \param local_dim The number of elements to be writen by each process. Might
+!!                  eventually be padded.
+!! \param path The logical path structuring the data and containing
+!!             the variable 
+!! \param array_name The array name in the ADIOS file.
+!! \param array The array to be written
+subroutine write_adios_global_1d_logical_1d(adios_handle, myrank, sizeprocs, &
+    local_dim, array_name, array)
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_handle
+  integer, intent(in) :: myrank, sizeprocs, local_dim
+  character(len=*) :: array_name
+  logical, dimension(:), intent(in) :: array
+  ! Variables
+  integer :: adios_err
+
+  call write_1D_global_array_adios_dims(adios_handle, myrank, &
+      local_dim, sizeprocs, array_name)
+  call adios_write(adios_handle, array_name // "/array", array, adios_err)
+end subroutine write_adios_global_1d_logical_1d
+
+
+!===============================================================================
+!> Schedule an ADIOS integer global 1d array for write
+!! \param adios_handle The adios handle to the file to be written
+!! \param myrank The rank of the MPI process involved
+!! \param sizeprocs The number of MPI process in the communicator writing the
+!!                  variable
+!! \param local_dim The number of elements to be writen by each process. Might
+!!                  eventually be padded.
+!! \param path The logical path structuring the data and containing
+!!             the variable 
+!! \param array_name The array name in the ADIOS file.
+!! \param array The array to be written
+subroutine write_adios_global_1d_logical_2d(adios_handle, myrank, sizeprocs, &
+    local_dim, array_name, array)
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_handle
+  integer, intent(in) :: myrank, sizeprocs, local_dim
+  character(len=*) :: array_name
+  logical, dimension(:,:), intent(in) :: array
+  ! Variables
+  integer :: adios_err
+
+  call write_1D_global_array_adios_dims(adios_handle, myrank, &
+      local_dim, sizeprocs, array_name)
+  call adios_write(adios_handle, array_name // "/array", array, adios_err)
+end subroutine write_adios_global_1d_logical_2d
+
+
+!===============================================================================
+!> Schedule an ADIOS integer global 1d array for write
+!! \param adios_handle The adios handle to the file to be written
+!! \param myrank The rank of the MPI process involved
+!! \param sizeprocs The number of MPI process in the communicator writing the
+!!                  variable
+!! \param local_dim The number of elements to be writen by each process. Might
+!!                  eventually be padded.
+!! \param path The logical path structuring the data and containing
+!!             the variable 
+!! \param array_name The array name in the ADIOS file.
+!! \param array The array to be written
+subroutine write_adios_global_1d_logical_3d(adios_handle, myrank, sizeprocs, &
+    local_dim, array_name, array)
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_handle
+  integer, intent(in) :: myrank, sizeprocs, local_dim
+  character(len=*) :: array_name
+  logical, dimension(:,:,:), intent(in) :: array
+  ! Variables
+  integer :: adios_err
+
+  call write_1D_global_array_adios_dims(adios_handle, myrank, &
+      local_dim, sizeprocs, array_name)
+  call adios_write(adios_handle, array_name // "/array", array, adios_err)
+end subroutine write_adios_global_1d_logical_3d
+
+
+!===============================================================================
+!> Schedule an ADIOS logical global 1d array for write
+!! \param adios_handle The adios handle to the file to be written
+!! \param myrank The rank of the MPI process involved
+!! \param sizeprocs The number of MPI process in the communicator writing the
+!!                  variable
+!! \param local_dim The number of elements to be writen by each process. Might
+!!                  eventually be padded.
+!! \param path The logical path structuring the data and containing
+!!             the variable 
+!! \param array_name The array name in the ADIOS file.
+!! \param array The array to be written
+subroutine write_adios_global_1d_logical_4d(adios_handle, myrank, sizeprocs, &
+    local_dim, array_name, array)
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_handle
+  integer, intent(in) :: myrank, sizeprocs, local_dim
+  character(len=*) :: array_name
+  logical, dimension(:,:,:,:), intent(in) :: array
+  ! Variables
+  integer :: adios_err
+
+  call write_1D_global_array_adios_dims(adios_handle, myrank, &
+      local_dim, sizeprocs, array_name)
+  call adios_write(adios_handle, array_name // "/array", array, adios_err)
+end subroutine write_adios_global_1d_logical_4d
+
+
+!===============================================================================
+!> Schedule an ADIOS logical global 1d array for write
+!! \param adios_handle The adios handle to the file to be written
+!! \param myrank The rank of the MPI process involved
+!! \param sizeprocs The number of MPI process in the communicator writing the
+!!                  variable
+!! \param local_dim The number of elements to be writen by each process. Might
+!!                  eventually be padded.
+!! \param path The logical path structuring the data and containing
+!!             the variable 
+!! \param array_name The array name in the ADIOS file.
+!! \param array The array to be written
+subroutine write_adios_global_1d_logical_5d(adios_handle, myrank, sizeprocs, &
+    local_dim, array_name, array)
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_handle
+  integer, intent(in) :: myrank, sizeprocs, local_dim
+  character(len=*) :: array_name
+  logical, dimension(:,:,:,:,:), intent(in) :: array
+  ! Variables
+  integer :: adios_err
+
+  call write_1D_global_array_adios_dims(adios_handle, myrank, &
+      local_dim, sizeprocs, array_name)
+  call adios_write(adios_handle, array_name // "/array", array, adios_err)
+end subroutine write_adios_global_1d_logical_5d
+
+
+end module adios_helpers_writers_mod

Added: seismo/3D/SPECFEM3D/trunk/src/shared/adios_manager.F90
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/shared/adios_manager.F90	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/src/shared/adios_manager.F90	2013-09-18 14:35:14 UTC (rev 22798)
@@ -0,0 +1,38 @@
+!==============================================================================
+!> Tools to setup and cleanup ADIOS
+!------------------------------------------------------------------------------
+module adios_manager_mod
+
+contains
+
+!==============================================================================
+!> Initialize ADIOS and setup the xml output file
+subroutine adios_setup()
+  use mpi
+  use adios_write_mod, only: adios_init
+
+  implicit none
+
+  include 'constants.h'
+
+  integer :: adios_err
+
+  call adios_init_noxml (MPI_COMM_WORLD, adios_err);
+  call adios_allocate_buffer (ADIOS_BUFFER_SIZE_IN_MB, adios_err)
+end subroutine adios_setup
+
+!==============================================================================
+!> Finalize ADIOS. Must be called once everything is written down.
+subroutine adios_cleanup()
+  use mpi
+  use adios_write_mod, only: adios_finalize
+
+  implicit none
+  integer :: myrank
+  integer :: adios_err, ierr
+
+  call MPI_Comm_rank(MPI_COMM_WORLD, myrank, ierr)
+  call adios_finalize (myrank, adios_err)
+end subroutine adios_cleanup
+
+end module adios_manager_mod

Added: seismo/3D/SPECFEM3D/trunk/src/shared/adios_manager_stubs.f90
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/shared/adios_manager_stubs.f90	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/src/shared/adios_manager_stubs.f90	2013-09-18 14:35:14 UTC (rev 22798)
@@ -0,0 +1,38 @@
+!==============================================================================
+!> Tools to setup and cleanup ADIOS
+!------------------------------------------------------------------------------
+module adios_manager_mod
+
+contains
+
+subroutine no_adios_err()
+  use mpi
+
+  implicit none
+
+  integer :: myrank, code, ier 
+  
+  call MPI_Comm_rank(MPI_COMM_WORLD, myrank, ier)
+  if (myrank == 0) then
+    print *, "----------------------------------------------------"
+    print *, "Not configure to be compile with ADIOS."
+    print *, "Check your par_file and set ADIOS_ENABLED to .false."
+    print *, "or reconfigure using --with-adios."
+    print *, "----------------------------------------------------"
+  endif
+  call MPI_Abort(MPI_COMM_WORLD, code, ier)
+end subroutine 
+
+!==============================================================================
+!> Initialize ADIOS and setup the xml output file
+subroutine adios_setup()
+  call no_adios_err()
+end subroutine adios_setup
+
+!==============================================================================
+!> Finalize ADIOS. Must be called once everything is written down.
+subroutine adios_cleanup()
+  call no_adios_err()
+end subroutine adios_cleanup
+
+end module adios_manager_mod

Modified: seismo/3D/SPECFEM3D/trunk/src/shared/constants.h.in
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/shared/constants.h.in	2013-09-17 22:36:21 UTC (rev 22797)
+++ seismo/3D/SPECFEM3D/trunk/src/shared/constants.h.in	2013-09-18 14:35:14 UTC (rev 22798)
@@ -107,6 +107,10 @@
 ! ignore variable name field (junk) at the beginning of each input line
   logical, parameter :: IGNORE_JUNK = .true.,DONT_IGNORE_JUNK = .false.
 
+  ! size of the ADIOS buffer to use
+  integer, parameter :: ADIOS_BUFFER_SIZE_IN_MB = 200
+  character(len=256), parameter :: ADIOS_TRANSPORT_METHOD = 'MPI'
+
 !!-----------------------------------------------------------
 !!
 !! total energy calculation

Modified: seismo/3D/SPECFEM3D/trunk/src/shared/read_parameter_file.f90
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/shared/read_parameter_file.f90	2013-09-17 22:36:21 UTC (rev 22797)
+++ seismo/3D/SPECFEM3D/trunk/src/shared/read_parameter_file.f90	2013-09-18 14:35:14 UTC (rev 22798)
@@ -380,3 +380,38 @@
 
   end subroutine read_gpu_mode
 
+!===============================================================================
+!> Read ADIOS related flags from the Par_file
+!! \param ADIOS_ENABLED Main flag to decide if ADIOS is used. If setted to
+!!                      false no other parameter is taken into account.
+!! \param ADIOS_FOR_DATABASES Flag to indicate if the databases are written
+!!                            and read with the help of ADIOS.
+!! \param ADIOS_FOR_MESH flag to indicate if the mesh (generate database) is
+!!                       written using ADIOS.
+!! \author MPBL
+subroutine read_adios_parameters(ADIOS_ENABLED, ADIOS_FOR_DATABASES, &
+                                 ADIOS_FOR_MESH, ADIOS_FOR_KERNELS) 
+  implicit none
+  include "constants.h"
+  
+  logical, intent(out) :: ADIOS_ENABLED, ADIOS_FOR_DATABASES, &
+                          ADIOS_FOR_MESH, ADIOS_FOR_KERNELS
+
+  ! initialize flags to false
+  ADIOS_ENABLED       = .false.
+  ADIOS_FOR_DATABASES = .false.
+  ADIOS_FOR_MESH      = .false.
+  ADIOS_FOR_KERNELS   = .false.
+  ! opens file Par_file
+  call open_parameter_file()
+  call read_value_logical(ADIOS_ENABLED, 'solver.ADIOS_ENABLED')
+  if (ADIOS_ENABLED) then
+    call read_value_logical(ADIOS_FOR_DATABASES, 'solver.ADIOS_FOR_DATABASES')
+    call read_value_logical(ADIOS_FOR_MESH, 'solver.ADIOS_FOR_MESH')
+    call read_value_logical(ADIOS_FOR_KERNELS, 'solver.ADIOS_FOR_KERNELS')
+  endif 
+  call close_parameter_file()
+        
+end subroutine read_adios_parameters
+
+

Added: seismo/3D/SPECFEM3D/trunk/src/shared/safe_alloc_mod.f90
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/shared/safe_alloc_mod.f90	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/src/shared/safe_alloc_mod.f90	2013-09-18 14:35:14 UTC (rev 22798)
@@ -0,0 +1,1182 @@
+
+
+!==============================================================================
+!> \file  safe_alloc_mod.f90
+!! \brief Helper module for (de)allocation error check.
+!!
+!! \author MPBL
+!==============================================================================
+
+!==============================================================================
+!> Helpers (de)allocate arrays of various types and dimensions. Check errors.
+!!
+!! \note The routine of this module only allow to allocate arrays starting at
+!!       index 1. If you want custom bound, write your own allocation. You can
+!!       still use the error checking routines, though.
+!!
+!! \author MPBL
+!------------------------------------------------------------------------------
+module safe_alloc_mod
+
+  implicit none
+  
+  private
+
+  public :: safe_alloc
+  public :: safe_dealloc
+
+  public :: check_alloc_err
+  public :: check_dealloc_err
+
+  interface safe_alloc
+    module procedure safe_alloc_float_1d
+    module procedure safe_alloc_float_2d
+    module procedure safe_alloc_float_3d
+    module procedure safe_alloc_float_4d
+    module procedure safe_alloc_float_5d
+
+    module procedure safe_alloc_double_1d
+    module procedure safe_alloc_double_2d
+    module procedure safe_alloc_double_3d
+    module procedure safe_alloc_double_4d
+    module procedure safe_alloc_double_5d
+
+    module procedure safe_alloc_int_1d
+    module procedure safe_alloc_int_2d
+    module procedure safe_alloc_int_3d
+    module procedure safe_alloc_int_4d
+    module procedure safe_alloc_int_5d
+
+    module procedure safe_alloc_long_1d
+    module procedure safe_alloc_long_2d
+    module procedure safe_alloc_long_3d
+    module procedure safe_alloc_long_4d
+    module procedure safe_alloc_long_5d
+
+    !module procedure safe_alloc_byte_1d
+    !module procedure safe_alloc_byte_2d
+    !module procedure safe_alloc_byte_3d
+    !module procedure safe_alloc_byte_4d
+    !module procedure safe_alloc_byte_5d
+
+    module procedure safe_alloc_logical_1d
+    module procedure safe_alloc_logical_2d
+    module procedure safe_alloc_logical_3d
+    module procedure safe_alloc_logical_4d
+    module procedure safe_alloc_logical_5d
+  end interface safe_alloc
+
+  interface safe_dealloc
+    module procedure safe_dealloc_float_1d
+    module procedure safe_dealloc_float_2d
+    module procedure safe_dealloc_float_3d
+    module procedure safe_dealloc_float_4d
+    module procedure safe_dealloc_float_5d
+
+    module procedure safe_dealloc_double_1d
+    module procedure safe_dealloc_double_2d
+    module procedure safe_dealloc_double_3d
+    module procedure safe_dealloc_double_4d
+    module procedure safe_dealloc_double_5d
+
+    module procedure safe_dealloc_int_1d
+    module procedure safe_dealloc_int_2d
+    module procedure safe_dealloc_int_3d
+    module procedure safe_dealloc_int_4d
+    module procedure safe_dealloc_int_5d
+
+    module procedure safe_dealloc_long_1d
+    module procedure safe_dealloc_long_2d
+    module procedure safe_dealloc_long_3d
+    module procedure safe_dealloc_long_4d
+    module procedure safe_dealloc_long_5d
+
+    !module procedure safe_dealloc_byte_1d
+    !module procedure safe_dealloc_byte_2d
+    !module procedure safe_dealloc_byte_3d
+    !module procedure safe_dealloc_byte_4d
+    !module procedure safe_dealloc_byte_5d
+
+    module procedure safe_dealloc_logical_1d
+    module procedure safe_dealloc_logical_2d
+    module procedure safe_dealloc_logical_3d
+    module procedure safe_dealloc_logical_4d
+    module procedure safe_dealloc_logical_5d
+  end interface safe_dealloc
+
+contains
+
+!==============================================================================
+!>
+subroutine check_alloc_err(ier, usr_msg)
+  use iso_fortran_env, only : error_unit
+  use mpi
+
+  integer, intent(in) :: ier
+  character(len=*), intent(in), optional :: usr_msg
+
+  integer :: myrank, mpi_er
+
+  if(ier /= 0) then 
+    call MPI_Comm_rank(MPI_COMM_WORLD, myrank, mpi_er)
+    if (present(usr_msg)) then
+      write(error_unit, "('Process ', i6.6, " // &
+                        "': Allocation error. ', A)") myrank, usr_msg
+    else
+      write(error_unit, "('Process ', i6.6, ': Allocation error. " // &
+                        " No user message specfified.')") myrank
+    endif
+    !call exit(ier)
+    call MPI_Abort(MPI_COMM_WORLD, ier, mpi_er)
+  endif
+end subroutine check_alloc_err
+
+!==============================================================================
+!>
+subroutine check_dealloc_err(ier, usr_msg)
+  use iso_fortran_env, only : error_unit
+  use mpi
+
+  integer, intent(in) :: ier
+	character(len=*), intent(in), optional :: usr_msg
+
+  integer :: myrank, mpi_er
+
+  if(ier /= 0) then 
+    call MPI_Comm_rank(MPI_COMM_WORLD, myrank, mpi_er)
+    if (present(usr_msg)) then
+      write(error_unit, "('Process ', i6.6, " // &
+                        "': Deallocation error. ', A)") myrank, usr_msg
+    else
+      write(error_unit, "('Process ', i6.6, ': Deallocation error. " // &
+                        " No user message specfified.')") myrank
+    endif
+    !call exit(ier)
+    call MPI_Abort(MPI_COMM_WORLD, ier, mpi_er)
+  endif
+end subroutine check_dealloc_err
+
+!==============================================================================
+!> Allocate a 1D float array and check for errors
+!! \param array The array to allocate 
+!! \param dim1 The dimension of the array
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_alloc_float_1d(array, dim1, usr_msg)
+	! Arguments
+  real(kind=4), dimension(:), allocatable, intent(inout) :: array
+  integer, intent(in) :: dim1
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  allocate(array(dim1), stat=ier)
+  call check_alloc_err(ier, usr_msg)
+end subroutine safe_alloc_float_1d
+
+!==============================================================================
+!> Allocate a 2D float array and check for errors
+!! \param array The array to allocate 
+!! \param dim1 The 1st dimension of the array
+!! \param dim2 The 2nd dimension of the array
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_alloc_float_2d(array, dim1, dim2, usr_msg)
+	! Arguments
+  real(kind=4), dimension(:,:), allocatable, intent(inout) :: array
+  integer, intent(in) :: dim1, dim2
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  allocate(array(dim1, dim2), stat=ier)
+  call check_alloc_err(ier, usr_msg)
+end subroutine safe_alloc_float_2d
+
+!==============================================================================
+!> Allocate a 3D float array and check for errors
+!! \param array The array to allocate 
+!! \param dim1 The 1st dimension of the array
+!! \param dim2 The 2nd dimension of the array
+!! \param dim3 The 3rd dimension of the array
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_alloc_float_3d(array, dim1, dim2, dim3, usr_msg)
+	! Arguments
+  real(kind=4), dimension(:,:,:), allocatable, intent(inout) :: array
+  integer, intent(in) :: dim1, dim2, dim3
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  allocate(array(dim1, dim2, dim3), stat=ier)
+  call check_alloc_err(ier, usr_msg)
+end subroutine safe_alloc_float_3d
+
+!==============================================================================
+!> Allocate a 4D float array and check for errors
+!! \param array The array to allocate 
+!! \param dim1 The 1st dimension of the array
+!! \param dim2 The 2nd dimension of the array
+!! \param dim3 The 3rd dimension of the array
+!! \param dim4 The 4th dimension of the array
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_alloc_float_4d(array, dim1, dim2, dim3, dim4, usr_msg)
+	! Arguments
+  real(kind=4), dimension(:,:,:,:), allocatable, intent(inout) :: array
+  integer, intent(in) :: dim1, dim2, dim3, dim4
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  allocate(array(dim1, dim2, dim3, dim4), stat=ier)
+  call check_alloc_err(ier, usr_msg)
+end subroutine safe_alloc_float_4d
+
+!==============================================================================
+!> Allocate a 1D float array and check for errors
+!! \param array The array to allocate 
+!! \param dim1 The 1st dimension of the array
+!! \param dim2 The 2nd dimension of the array
+!! \param dim3 The 3rd dimension of the array
+!! \param dim4 The 4th dimension of the array
+!! \param dim5 The 5th dimension of the array
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_alloc_float_5d(array, dim1, dim2, dim3, dim4, dim5, usr_msg)
+	! Arguments
+  real(kind=4), dimension(:,:,:,:,:), allocatable, intent(inout) :: array
+  integer, intent(in) :: dim1, dim2, dim3, dim4, dim5
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  allocate(array(dim1, dim2, dim3, dim4, dim5), stat=ier)
+  call check_alloc_err(ier, usr_msg)
+end subroutine safe_alloc_float_5d
+
+!==============================================================================
+!> Allocate a 1D double array and check for errors
+!! \param array The array to allocate 
+!! \param dim1 The dimension of the array
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_alloc_double_1d(array, dim1, usr_msg)
+	! Arguments
+  real(kind=8), dimension(:), allocatable, intent(inout) :: array
+  integer, intent(in) :: dim1
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  allocate(array(dim1), stat=ier)
+  call check_alloc_err(ier, usr_msg)
+end subroutine safe_alloc_double_1d
+
+!==============================================================================
+!> Allocate a 2D double array and check for errors
+!! \param array The array to allocate 
+!! \param dim1 The 1st dimension of the array
+!! \param dim2 The 2nd dimension of the array
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_alloc_double_2d(array, dim1, dim2, usr_msg)
+	! Arguments
+  real(kind=8), dimension(:,:), allocatable, intent(inout) :: array
+  integer, intent(in) :: dim1, dim2
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  allocate(array(dim1, dim2), stat=ier)
+  call check_alloc_err(ier, usr_msg)
+end subroutine safe_alloc_double_2d
+
+!==============================================================================
+!> Allocate a 3D double array and check for errors
+!! \param array The array to allocate 
+!! \param dim1 The 1st dimension of the array
+!! \param dim2 The 2nd dimension of the array
+!! \param dim3 The 3rd dimension of the array
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_alloc_double_3d(array, dim1, dim2, dim3, usr_msg)
+	! Arguments
+  real(kind=8), dimension(:,:,:), allocatable, intent(inout) :: array
+  integer, intent(in) :: dim1, dim2, dim3
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  allocate(array(dim1, dim2, dim3), stat=ier)
+  call check_alloc_err(ier, usr_msg)
+end subroutine safe_alloc_double_3d
+
+!==============================================================================
+!> Allocate a 4D double array and check for errors
+!! \param array The array to allocate 
+!! \param dim1 The 1st dimension of the array
+!! \param dim2 The 2nd dimension of the array
+!! \param dim3 The 3rd dimension of the array
+!! \param dim4 The 4th dimension of the array
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_alloc_double_4d(array, dim1, dim2, dim3, dim4, usr_msg)
+	! Arguments
+  real(kind=8), dimension(:,:,:,:), allocatable, intent(inout) :: array
+  integer, intent(in) :: dim1, dim2, dim3, dim4
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  allocate(array(dim1, dim2, dim3, dim4), stat=ier)
+  call check_alloc_err(ier, usr_msg)
+end subroutine safe_alloc_double_4d
+
+!==============================================================================
+!> Allocate a 1D double array and check for errors
+!! \param array The array to allocate 
+!! \param dim1 The 1st dimension of the array
+!! \param dim2 The 2nd dimension of the array
+!! \param dim3 The 3rd dimension of the array
+!! \param dim4 The 4th dimension of the array
+!! \param dim5 The 5th dimension of the array
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_alloc_double_5d(array, dim1, dim2, dim3, dim4, dim5, usr_msg)
+	! Arguments
+  real(kind=8), dimension(:,:,:,:,:), allocatable, intent(inout) :: array
+  integer, intent(in) :: dim1, dim2, dim3, dim4, dim5
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  allocate(array(dim1, dim2, dim3, dim4, dim5), stat=ier)
+  call check_alloc_err(ier, usr_msg)
+end subroutine safe_alloc_double_5d
+
+!==============================================================================
+!> Allocate a 1D int array and check for errors
+!! \param array The array to allocate 
+!! \param dim1 The dimension of the array
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_alloc_int_1d(array, dim1, usr_msg)
+	! Arguments
+  integer(kind=4), dimension(:), allocatable, intent(inout) :: array
+  integer, intent(in) :: dim1
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  allocate(array(dim1), stat=ier)
+  call check_alloc_err(ier, usr_msg)
+end subroutine safe_alloc_int_1d
+
+!==============================================================================
+!> Allocate a 2D int array and check for errors
+!! \param array The array to allocate 
+!! \param dim1 The 1st dimension of the array
+!! \param dim2 The 2nd dimension of the array
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_alloc_int_2d(array, dim1, dim2, usr_msg)
+	! Arguments
+  integer(kind=4), dimension(:,:), allocatable, intent(inout) :: array
+  integer, intent(in) :: dim1, dim2
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  allocate(array(dim1, dim2), stat=ier)
+  call check_alloc_err(ier, usr_msg)
+end subroutine safe_alloc_int_2d
+
+!==============================================================================
+!> Allocate a 3D int array and check for errors
+!! \param array The array to allocate 
+!! \param dim1 The 1st dimension of the array
+!! \param dim2 The 2nd dimension of the array
+!! \param dim3 The 3rd dimension of the array
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_alloc_int_3d(array, dim1, dim2, dim3, usr_msg)
+	! Arguments
+  integer(kind=4), dimension(:,:,:), allocatable, intent(inout) :: array
+  integer, intent(in) :: dim1, dim2, dim3
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  allocate(array(dim1, dim2, dim3), stat=ier)
+  call check_alloc_err(ier, usr_msg)
+end subroutine safe_alloc_int_3d
+
+!==============================================================================
+!> Allocate a 4D int array and check for errors
+!! \param array The array to allocate 
+!! \param dim1 The 1st dimension of the array
+!! \param dim2 The 2nd dimension of the array
+!! \param dim3 The 3rd dimension of the array
+!! \param dim4 The 4th dimension of the array
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_alloc_int_4d(array, dim1, dim2, dim3, dim4, usr_msg)
+	! Arguments
+  integer(kind=4), dimension(:,:,:,:), allocatable, intent(inout) :: array
+  integer, intent(in) :: dim1, dim2, dim3, dim4
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  allocate(array(dim1, dim2, dim3, dim4), stat=ier)
+  call check_alloc_err(ier, usr_msg)
+end subroutine safe_alloc_int_4d
+
+!==============================================================================
+!> Allocate a 1D int array and check for errors
+!! \param array The array to allocate 
+!! \param dim1 The 1st dimension of the array
+!! \param dim2 The 2nd dimension of the array
+!! \param dim3 The 3rd dimension of the array
+!! \param dim4 The 4th dimension of the array
+!! \param dim5 The 5th dimension of the array
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_alloc_int_5d(array, dim1, dim2, dim3, dim4, dim5, usr_msg)
+	! Arguments
+  integer(kind=4), dimension(:,:,:,:,:), allocatable, intent(inout) :: array
+  integer, intent(in) :: dim1, dim2, dim3, dim4, dim5
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  allocate(array(dim1, dim2, dim3, dim4, dim5), stat=ier)
+  call check_alloc_err(ier, usr_msg)
+end subroutine safe_alloc_int_5d
+
+!==============================================================================
+!> Allocate a 1D long array and check for errors
+!! \param array The array to allocate 
+!! \param dim1 The dimension of the array
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_alloc_long_1d(array, dim1, usr_msg)
+	! Arguments
+  integer(kind=8), dimension(:), allocatable, intent(inout) :: array
+  integer, intent(in) :: dim1
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  allocate(array(dim1), stat=ier)
+  call check_alloc_err(ier, usr_msg)
+end subroutine safe_alloc_long_1d
+
+!==============================================================================
+!> Allocate a 2D long array and check for errors
+!! \param array The array to allocate 
+!! \param dim1 The 1st dimension of the array
+!! \param dim2 The 2nd dimension of the array
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_alloc_long_2d(array, dim1, dim2, usr_msg)
+	! Arguments
+  integer(kind=8), dimension(:,:), allocatable, intent(inout) :: array
+  integer, intent(in) :: dim1, dim2
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  allocate(array(dim1, dim2), stat=ier)
+  call check_alloc_err(ier, usr_msg)
+end subroutine safe_alloc_long_2d
+
+!==============================================================================
+!> Allocate a 3D long array and check for errors
+!! \param array The array to allocate 
+!! \param dim1 The 1st dimension of the array
+!! \param dim2 The 2nd dimension of the array
+!! \param dim3 The 3rd dimension of the array
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_alloc_long_3d(array, dim1, dim2, dim3, usr_msg)
+	! Arguments
+  integer(kind=8), dimension(:,:,:), allocatable, intent(inout) :: array
+  integer, intent(in) :: dim1, dim2, dim3
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  allocate(array(dim1, dim2, dim3), stat=ier)
+  call check_alloc_err(ier, usr_msg)
+end subroutine safe_alloc_long_3d
+
+!==============================================================================
+!> Allocate a 4D long array and check for errors
+!! \param array The array to allocate 
+!! \param dim1 The 1st dimension of the array
+!! \param dim2 The 2nd dimension of the array
+!! \param dim3 The 3rd dimension of the array
+!! \param dim4 The 4th dimension of the array
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_alloc_long_4d(array, dim1, dim2, dim3, dim4, usr_msg)
+	! Arguments
+  integer(kind=8), dimension(:,:,:,:), allocatable, intent(inout) :: array
+  integer, intent(in) :: dim1, dim2, dim3, dim4
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  allocate(array(dim1, dim2, dim3, dim4), stat=ier)
+  call check_alloc_err(ier, usr_msg)
+end subroutine safe_alloc_long_4d
+
+!==============================================================================
+!> Allocate a 1D long array and check for errors
+!! \param array The array to allocate 
+!! \param dim1 The 1st dimension of the array
+!! \param dim2 The 2nd dimension of the array
+!! \param dim3 The 3rd dimension of the array
+!! \param dim4 The 4th dimension of the array
+!! \param dim5 The 5th dimension of the array
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_alloc_long_5d(array, dim1, dim2, dim3, dim4, dim5, usr_msg)
+	! Arguments
+  integer(kind=8), dimension(:,:,:,:,:), allocatable, intent(inout) :: array
+  integer, intent(in) :: dim1, dim2, dim3, dim4, dim5
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  allocate(array(dim1, dim2, dim3, dim4, dim5), stat=ier)
+  call check_alloc_err(ier, usr_msg)
+end subroutine safe_alloc_long_5d
+
+!!==============================================================================
+!!> Allocate a 1D byte array and check for errors
+!!! \param array The array to allocate 
+!!! \param dim1 The dimension of the array
+!!! \param usr_msg A custom error message to print if allocation fails.
+!subroutine safe_alloc_byte_1d(array, dim1, usr_msg)
+	!! Arguments
+  !byte, dimension(:), allocatable, intent(inout) :: array
+  !integer, intent(in) :: dim1
+  !character(len=*), intent(in), optional :: usr_msg
+  !! Local parameters
+  !integer :: ier
+!	
+  !allocate(array(dim1), stat=ier)
+  !call check_alloc_err(ier, usr_msg)
+!end subroutine safe_alloc_byte_1d
+!
+!!==============================================================================
+!!> Allocate a 2D byte array and check for errors
+!!! \param array The array to allocate 
+!!! \param dim1 The 1st dimension of the array
+!!! \param dim2 The 2nd dimension of the array
+!!! \param usr_msg A custom error message to print if allocation fails.
+!subroutine safe_alloc_byte_2d(array, dim1, dim2, usr_msg)
+	!! Arguments
+  !byte, dimension(:,:), allocatable, intent(inout) :: array
+  !integer, intent(in) :: dim1, dim2
+  !character(len=*), intent(in), optional :: usr_msg
+  !! Local parameters
+  !integer :: ier
+!	
+  !allocate(array(dim1, dim2), stat=ier)
+  !call check_alloc_err(ier, usr_msg)
+!end subroutine safe_alloc_byte_2d
+!
+!!==============================================================================
+!!> Allocate a 3D byte array and check for errors
+!!! \param array The array to allocate 
+!!! \param dim1 The 1st dimension of the array
+!!! \param dim2 The 2nd dimension of the array
+!!! \param dim3 The 3rd dimension of the array
+!!! \param usr_msg A custom error message to print if allocation fails.
+!subroutine safe_alloc_byte_3d(array, dim1, dim2, dim3, usr_msg)
+	!! Arguments
+  !byte, dimension(:,:,:), allocatable, intent(inout) :: array
+  !integer, intent(in) :: dim1, dim2, dim3
+  !character(len=*), intent(in), optional :: usr_msg
+  !! Local parameters
+  !integer :: ier
+!	
+  !allocate(array(dim1, dim2, dim3), stat=ier)
+  !call check_alloc_err(ier, usr_msg)
+!end subroutine safe_alloc_byte_3d
+!
+!!==============================================================================
+!!> Allocate a 4D byte array and check for errors
+!!! \param array The array to allocate 
+!!! \param dim1 The 1st dimension of the array
+!!! \param dim2 The 2nd dimension of the array
+!!! \param dim3 The 3rd dimension of the array
+!!! \param dim4 The 4th dimension of the array
+!!! \param usr_msg A custom error message to print if allocation fails.
+!subroutine safe_alloc_byte_4d(array, dim1, dim2, dim3, dim4, usr_msg)
+	!! Arguments
+  !byte, dimension(:,:,:,:), allocatable, intent(inout) :: array
+  !integer, intent(in) :: dim1, dim2, dim3, dim4
+  !character(len=*), intent(in), optional :: usr_msg
+  !! Local parameters
+  !integer :: ier
+!	
+  !allocate(array(dim1, dim2, dim3, dim4), stat=ier)
+  !call check_alloc_err(ier, usr_msg)
+!end subroutine safe_alloc_byte_4d
+!
+!!==============================================================================
+!!> Allocate a 1D byte array and check for errors
+!!! \param array The array to allocate 
+!!! \param dim1 The 1st dimension of the array
+!!! \param dim2 The 2nd dimension of the array
+!!! \param dim3 The 3rd dimension of the array
+!!! \param dim4 The 4th dimension of the array
+!!! \param dim5 The 5th dimension of the array
+!!! \param usr_msg A custom error message to print if allocation fails.
+!subroutine safe_alloc_byte_5d(array, dim1, dim2, dim3, dim4, dim5, usr_msg)
+	!! Arguments
+  !byte, dimension(:,:,:,:,:), allocatable, intent(inout) :: array
+  !integer, intent(in) :: dim1, dim2, dim3, dim4, dim5
+  !character(len=*), intent(in), optional :: usr_msg
+  !! Local parameters
+  !integer :: ier
+!	
+  !allocate(array(dim1, dim2, dim3, dim4, dim5), stat=ier)
+  !call check_alloc_err(ier, usr_msg)
+!end subroutine safe_alloc_byte_5d
+
+!==============================================================================
+!> Allocate a 1D logical array and check for errors
+!! \param array The array to allocate 
+!! \param dim1 The dimension of the array
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_alloc_logical_1d(array, dim1, usr_msg)
+	! Arguments
+  logical, dimension(:), allocatable, intent(inout) :: array
+  integer, intent(in) :: dim1
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  allocate(array(dim1), stat=ier)
+  call check_alloc_err(ier, usr_msg)
+end subroutine safe_alloc_logical_1d
+
+!==============================================================================
+!> Allocate a 2D logical array and check for errors
+!! \param array The array to allocate 
+!! \param dim1 The 1st dimension of the array
+!! \param dim2 The 2nd dimension of the array
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_alloc_logical_2d(array, dim1, dim2, usr_msg)
+	! Arguments
+  logical, dimension(:,:), allocatable, intent(inout) :: array
+  integer, intent(in) :: dim1, dim2
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  allocate(array(dim1, dim2), stat=ier)
+  call check_alloc_err(ier, usr_msg)
+end subroutine safe_alloc_logical_2d
+
+!==============================================================================
+!> Allocate a 3D logical array and check for errors
+!! \param array The array to allocate 
+!! \param dim1 The 1st dimension of the array
+!! \param dim2 The 2nd dimension of the array
+!! \param dim3 The 3rd dimension of the array
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_alloc_logical_3d(array, dim1, dim2, dim3, usr_msg)
+	! Arguments
+  logical, dimension(:,:,:), allocatable, intent(inout) :: array
+  integer, intent(in) :: dim1, dim2, dim3
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  allocate(array(dim1, dim2, dim3), stat=ier)
+  call check_alloc_err(ier, usr_msg)
+end subroutine safe_alloc_logical_3d
+
+!==============================================================================
+!> Allocate a 4D logical array and check for errors
+!! \param array The array to allocate 
+!! \param dim1 The 1st dimension of the array
+!! \param dim2 The 2nd dimension of the array
+!! \param dim3 The 3rd dimension of the array
+!! \param dim4 The 4th dimension of the array
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_alloc_logical_4d(array, dim1, dim2, dim3, dim4, usr_msg)
+	! Arguments
+  logical, dimension(:,:,:,:), allocatable, intent(inout) :: array
+  integer, intent(in) :: dim1, dim2, dim3, dim4
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  allocate(array(dim1, dim2, dim3, dim4), stat=ier)
+  call check_alloc_err(ier, usr_msg)
+end subroutine safe_alloc_logical_4d
+
+!==============================================================================
+!> Allocate a 1D logical array and check for errors
+!! \param array The array to allocate 
+!! \param dim1 The 1st dimension of the array
+!! \param dim2 The 2nd dimension of the array
+!! \param dim3 The 3rd dimension of the array
+!! \param dim4 The 4th dimension of the array
+!! \param dim5 The 5th dimension of the array
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_alloc_logical_5d(array, dim1, dim2, dim3, dim4, dim5, usr_msg)
+	! Arguments
+  logical, dimension(:,:,:,:,:), allocatable, intent(inout) :: array
+  integer, intent(in) :: dim1, dim2, dim3, dim4, dim5
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  allocate(array(dim1, dim2, dim3, dim4, dim5), stat=ier)
+  call check_alloc_err(ier, usr_msg)
+end subroutine safe_alloc_logical_5d
+
+!==============================================================================
+!> Deallocate a 1D float array and check for errors
+!! \param array The array to allocate 
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_dealloc_float_1d(array, usr_msg)
+	! Arguments
+  real(kind=4), dimension(:), allocatable, intent(inout) :: array
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  deallocate(array, stat=ier)
+  call check_dealloc_err(ier, usr_msg)
+end subroutine safe_dealloc_float_1d
+
+!==============================================================================
+!> Deallocate a 2D float array and check for errors
+!! \param array The array to allocate 
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_dealloc_float_2d(array, usr_msg)
+	! Arguments
+  real(kind=4), dimension(:,:), allocatable, intent(inout) :: array
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  deallocate(array, stat=ier)
+  call check_dealloc_err(ier, usr_msg)
+end subroutine safe_dealloc_float_2d
+
+!==============================================================================
+!> Deallocate a 3D float array and check for errors
+!! \param array The array to allocate 
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_dealloc_float_3d(array, usr_msg)
+	! Arguments
+  real(kind=4), dimension(:,:,:), allocatable, intent(inout) :: array
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  deallocate(array, stat=ier)
+  call check_dealloc_err(ier, usr_msg)
+end subroutine safe_dealloc_float_3d
+
+!==============================================================================
+!> Deallocate a 4D float array and check for errors
+!! \param array The array to allocate 
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_dealloc_float_4d(array, usr_msg)
+	! Arguments
+  real(kind=4), dimension(:,:,:,:), allocatable, intent(inout) :: array
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  deallocate(array, stat=ier)
+  call check_dealloc_err(ier, usr_msg)
+end subroutine safe_dealloc_float_4d
+
+!==============================================================================
+!> Deallocate a 5D float array and check for errors
+!! \param array The array to allocate 
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_dealloc_float_5d(array, usr_msg)
+	! Arguments
+  real(kind=4), dimension(:,:,:,:,:), allocatable, intent(inout) :: array
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  deallocate(array, stat=ier)
+  call check_dealloc_err(ier, usr_msg)
+end subroutine safe_dealloc_float_5d
+
+!==============================================================================
+!> Deallocate a 1D double array and check for errors
+!! \param array The array to allocate 
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_dealloc_double_1d(array, usr_msg)
+	! Arguments
+  real(kind=8), dimension(:), allocatable, intent(inout) :: array
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  deallocate(array, stat=ier)
+  call check_dealloc_err(ier, usr_msg)
+end subroutine safe_dealloc_double_1d
+
+!==============================================================================
+!> Deallocate a 2D double array and check for errors
+!! \param array The array to allocate 
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_dealloc_double_2d(array, usr_msg)
+	! Arguments
+  real(kind=8), dimension(:,:), allocatable, intent(inout) :: array
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  deallocate(array, stat=ier)
+  call check_dealloc_err(ier, usr_msg)
+end subroutine safe_dealloc_double_2d
+
+!==============================================================================
+!> Deallocate a 3D double array and check for errors
+!! \param array The array to allocate 
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_dealloc_double_3d(array, usr_msg)
+	! Arguments
+  real(kind=8), dimension(:,:,:), allocatable, intent(inout) :: array
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  deallocate(array, stat=ier)
+  call check_dealloc_err(ier, usr_msg)
+end subroutine safe_dealloc_double_3d
+
+!==============================================================================
+!> Deallocate a 4D double array and check for errors
+!! \param array The array to allocate 
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_dealloc_double_4d(array, usr_msg)
+	! Arguments
+  real(kind=8), dimension(:,:,:,:), allocatable, intent(inout) :: array
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  deallocate(array, stat=ier)
+  call check_dealloc_err(ier, usr_msg)
+end subroutine safe_dealloc_double_4d
+
+!==============================================================================
+!> Deallocate a 5D double array and check for errors
+!! \param array The array to allocate 
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_dealloc_double_5d(array, usr_msg)
+	! Arguments
+  real(kind=8), dimension(:,:,:,:,:), allocatable, intent(inout) :: array
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  deallocate(array, stat=ier)
+  call check_dealloc_err(ier, usr_msg)
+end subroutine safe_dealloc_double_5d
+
+!==============================================================================
+!> Deallocate a 1D int array and check for errors
+!! \param array The array to allocate 
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_dealloc_int_1d(array, usr_msg)
+	! Arguments
+  integer(kind=4), dimension(:), allocatable, intent(inout) :: array
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  deallocate(array, stat=ier)
+  call check_dealloc_err(ier, usr_msg)
+end subroutine safe_dealloc_int_1d
+
+!==============================================================================
+!> Deallocate a 2D int array and check for errors
+!! \param array The array to allocate 
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_dealloc_int_2d(array, usr_msg)
+	! Arguments
+  integer(kind=4), dimension(:,:), allocatable, intent(inout) :: array
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  deallocate(array, stat=ier)
+  call check_dealloc_err(ier, usr_msg)
+end subroutine safe_dealloc_int_2d
+
+!==============================================================================
+!> Deallocate a 3D int array and check for errors
+!! \param array The array to allocate 
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_dealloc_int_3d(array, usr_msg)
+	! Arguments
+  integer(kind=4), dimension(:,:,:), allocatable, intent(inout) :: array
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  deallocate(array, stat=ier)
+  call check_dealloc_err(ier, usr_msg)
+end subroutine safe_dealloc_int_3d
+
+!==============================================================================
+!> Deallocate a 4D int array and check for errors
+!! \param array The array to allocate 
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_dealloc_int_4d(array, usr_msg)
+	! Arguments
+  integer(kind=4), dimension(:,:,:,:), allocatable, intent(inout) :: array
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  deallocate(array, stat=ier)
+  call check_dealloc_err(ier, usr_msg)
+end subroutine safe_dealloc_int_4d
+
+!==============================================================================
+!> Deallocate a 5D int array and check for errors
+!! \param array The array to allocate 
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_dealloc_int_5d(array, usr_msg)
+	! Arguments
+  integer(kind=4), dimension(:,:,:,:,:), allocatable, intent(inout) :: array
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  deallocate(array, stat=ier)
+  call check_dealloc_err(ier, usr_msg)
+end subroutine safe_dealloc_int_5d
+
+!==============================================================================
+!> Deallocate a 1D long array and check for errors
+!! \param array The array to allocate 
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_dealloc_long_1d(array, usr_msg)
+	! Arguments
+  integer(kind=8), dimension(:), allocatable, intent(inout) :: array
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  deallocate(array, stat=ier)
+  call check_dealloc_err(ier, usr_msg)
+end subroutine safe_dealloc_long_1d
+
+!==============================================================================
+!> Deallocate a 2D long array and check for errors
+!! \param array The array to allocate 
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_dealloc_long_2d(array, usr_msg)
+	! Arguments
+  integer(kind=8), dimension(:,:), allocatable, intent(inout) :: array
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  deallocate(array, stat=ier)
+  call check_dealloc_err(ier, usr_msg)
+end subroutine safe_dealloc_long_2d
+
+!==============================================================================
+!> Deallocate a 3D long array and check for errors
+!! \param array The array to allocate 
+!!dim1 The 1st dimension of the array
+!! \param dim2 The 2nd dimension of the array
+!! \param dim3 The 3rd dimension of the array
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_dealloc_long_3d(array, usr_msg)
+	! Arguments
+  integer(kind=8), dimension(:,:,:), allocatable, intent(inout) :: array
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  deallocate(array, stat=ier)
+  call check_dealloc_err(ier, usr_msg)
+end subroutine safe_dealloc_long_3d
+
+!==============================================================================
+!> Deallocate a 4D long array and check for errors
+!! \param array The array to allocate 
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_dealloc_long_4d(array, usr_msg)
+	! Arguments
+  integer(kind=8), dimension(:,:,:,:), allocatable, intent(inout) :: array
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  deallocate(array, stat=ier)
+  call check_dealloc_err(ier, usr_msg)
+end subroutine safe_dealloc_long_4d
+
+!==============================================================================
+!> Deallocate a 5D long array and check for errors
+!! \param array The array to allocate 
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_dealloc_long_5d(array, usr_msg)
+	! Arguments
+  integer(kind=8), dimension(:,:,:,:,:), allocatable, intent(inout) :: array
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  deallocate(array, stat=ier)
+  call check_dealloc_err(ier, usr_msg)
+end subroutine safe_dealloc_long_5d
+
+!!==============================================================================
+!!> Deallocate a 1D byte array and check for errors
+!!! \param array The array to allocate 
+!!! \param usr_msg A custom error message to print if allocation fails.
+!subroutine safe_dealloc_byte_1d(array, usr_msg)
+	!! Arguments
+  !byte, dimension(:), allocatable, intent(inout) :: array
+  !character(len=*), intent(in), optional :: usr_msg
+  !! Local parameters
+  !integer :: ier
+!	
+  !deallocate(array, stat=ier)
+  !call check_dealloc_err(ier, usr_msg)
+!end subroutine safe_dealloc_byte_1d
+!
+!!==============================================================================
+!!> Deallocate a 2D byte array and check for errors
+!!! \param array The array to allocate 
+!!! \param usr_msg A custom error message to print if allocation fails.
+!subroutine safe_dealloc_byte_2d(array, usr_msg)
+	!! Arguments
+  !byte, dimension(:,:), allocatable, intent(inout) :: array
+  !character(len=*), intent(in), optional :: usr_msg
+  !! Local parameters
+  !integer :: ier
+!	
+  !deallocate(array, stat=ier)
+  !call check_dealloc_err(ier, usr_msg)
+!end subroutine safe_dealloc_byte_2d
+!
+!!==============================================================================
+!!> Deallocate a 3D byte array and check for errors
+!!! \param array The array to allocate 
+!!! \param usr_msg A custom error message to print if allocation fails.
+!subroutine safe_dealloc_byte_3d(array, usr_msg)
+	!! Arguments
+  !byte, dimension(:,:,:), allocatable, intent(inout) :: array
+  !character(len=*), intent(in), optional :: usr_msg
+  !! Local parameters
+  !integer :: ier
+!	
+  !deallocate(array, stat=ier)
+  !call check_dealloc_err(ier, usr_msg)
+!end subroutine safe_dealloc_byte_3d
+!
+!!==============================================================================
+!!> Deallocate a 4D byte array and check for errors
+!!! \param array The array to allocate 
+!!! \param usr_msg A custom error message to print if allocation fails.
+!subroutine safe_dealloc_byte_4d(array, usr_msg)
+	!! Arguments
+  !byte, dimension(:,:,:,:), allocatable, intent(inout) :: array
+  !character(len=*), intent(in), optional :: usr_msg
+  !! Local parameters
+  !integer :: ier
+!	
+  !deallocate(array, stat=ier)
+  !call check_dealloc_err(ier, usr_msg)
+!end subroutine safe_dealloc_byte_4d
+!
+!!==============================================================================
+!!> Deallocate a 5D byte array and check for errors
+!!! \param array The array to allocate 
+!!! \param usr_msg A custom error message to print if allocation fails.
+!subroutine safe_dealloc_byte_5d(array, usr_msg)
+	!! Arguments
+  !byte, dimension(:,:,:,:,:), allocatable, intent(inout) :: array
+  !character(len=*), intent(in), optional :: usr_msg
+  !! Local parameters
+  !integer :: ier
+!	
+  !deallocate(array, stat=ier)
+  !call check_dealloc_err(ier, usr_msg)
+!end subroutine safe_dealloc_byte_5d
+
+!==============================================================================
+!> Deallocate a 1D logical array and check for errors
+!! \param array The array to allocate 
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_dealloc_logical_1d(array, usr_msg)
+	! Arguments
+  logical, dimension(:), allocatable, intent(inout) :: array
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  deallocate(array, stat=ier)
+  call check_dealloc_err(ier, usr_msg)
+end subroutine safe_dealloc_logical_1d
+
+!==============================================================================
+!> Deallocate a 2D logical array and check for errors
+!! \param array The array to allocate 
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_dealloc_logical_2d(array, usr_msg)
+	! Arguments
+  logical, dimension(:,:), allocatable, intent(inout) :: array
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  deallocate(array, stat=ier)
+  call check_dealloc_err(ier, usr_msg)
+end subroutine safe_dealloc_logical_2d
+
+!==============================================================================
+!> Deallocate a 3D logical array and check for errors
+!! \param array The array to allocate 
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_dealloc_logical_3d(array, usr_msg)
+	! Arguments
+  logical, dimension(:,:,:), allocatable, intent(inout) :: array
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  deallocate(array, stat=ier)
+  call check_dealloc_err(ier, usr_msg)
+end subroutine safe_dealloc_logical_3d
+
+!==============================================================================
+!> Deallocate a 4D logical array and check for errors
+!! \param array The array to allocate 
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_dealloc_logical_4d(array, usr_msg)
+	! Arguments
+  logical, dimension(:,:,:,:), allocatable, intent(inout) :: array
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  deallocate(array, stat=ier)
+  call check_dealloc_err(ier, usr_msg)
+end subroutine safe_dealloc_logical_4d
+
+!==============================================================================
+!> Deallocate a 1D logical array and check for errors
+!! \param array The array to allocate 
+!! \param usr_msg A custom error message to print if allocation fails.
+subroutine safe_dealloc_logical_5d(array, usr_msg)
+	! Arguments
+  logical, dimension(:,:,:,:,:), allocatable, intent(inout) :: array
+  character(len=*), intent(in), optional :: usr_msg
+  ! Local parameters
+  integer :: ier
+	
+  deallocate(array, stat=ier)
+  call check_dealloc_err(ier, usr_msg)
+end subroutine safe_dealloc_logical_5d
+
+end module safe_alloc_mod

Modified: seismo/3D/SPECFEM3D/trunk/src/specfem3D/Makefile.in
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/specfem3D/Makefile.in	2013-09-17 22:36:21 UTC (rev 22797)
+++ seismo/3D/SPECFEM3D/trunk/src/specfem3D/Makefile.in	2013-09-18 14:35:14 UTC (rev 22798)
@@ -277,7 +277,39 @@
 	$O/read_value_parameters.shared.o \
 	$(EMPTY_MACRO)
 
+# using ADIOS files
+ADIOS_PREOBJECTS = \
+	$O/adios_manager.shared_adios.o  \
+	$O/adios_helpers_definitions.shared_adios.o \
+	$O/adios_helpers_writers.shared_adios.o \
+	$O/adios_helpers.shared_adios.o
 
+ADIOS_OBJECTS= \
+	$O/read_mesh_databases_adios.adios.o \
+	$O/save_kernels_adios.adios.o
+
+ADIOS_STUBS = \
+	$O/adios_manager_stubs.shared_noadios.o \
+	$O/specfem3D_adios_stubs.noadios.o
+
+#@COND_ADIOS_TRUE at XSPECFEM_OBJECTS_ADIOS = $(ADIOS_PREOBJECTS) $(XSPECFEM_OBJECTS_PRE) $(ADIOS_OBJECTS)
+#@COND_ADIOS_FALSE at XSPECFEM_OBJECTS_ADIOS = $(ADIOS_STUBS) $(XSPECFEM_OBJECTS_PRE)
+ at COND_ADIOS_FALSE@ADIOS_OBJECTS = $(ADIOS_STUBS)
+ at COND_ADIOS_FALSE@ADIOS_PREOBJECTS=
+
+# ADIOS
+# with configure: ./configure --with-cuda ADIOS_LIB=.. ADIOS_INC=.. MPI_INC=..
+ at COND_ADIOS_TRUE@ADIOS_LIBS = -ladiosf -lmxml
+ at COND_ADIOS_FALSE@ADIOS_LIBS = 
+
+ADIOS_LIB_LOCATION = @ADIOS_LIB@ @MXML_LIB@
+ADIOS_LINK = $(ADIOS_LIB_LOCATION) $(ADIOS_LIBS)
+ADIOS_INC = @ADIOS_INC@ -I../../setup -I../../ 
+
+#@COND_ADIOS_TRUE at CPPFLAGS = -I../../setup @CPPFLAGS@
+ at COND_ADIOS_TRUE@MPIFCCOMPILE_CHECK =@FCENV@ ${MPIFC} ${FCFLAGS} $(ADIOS_INC) $(FLAGS_CHECK)
+ at COND_ADIOS_TRUE@MPIFCCOMPILE_NO_CHECK =@FCENV@ ${MPIFC} ${FCFLAGS} $(ADIOS_INC) $(FLAGS_NO_CHECK)
+
 # objects toggled between the parallel and serial version
 @COND_MPI_TRUE at COND_MPI_OBJECTS = $O/parallel.o
 @COND_MPI_FALSE at COND_MPI_OBJECTS = $O/serial.o
@@ -289,8 +321,8 @@
 LIBSPECFEM = $L/libspecfem.a
 
 # objects for the pure Fortran version
- at COND_PYRE_FALSE@@COND_CUDA_TRUE at XSPECFEM_OBJECTS = $(SOLVER_ARRAY_OBJECTS) $(LIBSPECFEM) $(CUDA_OBJECTS)
- at COND_PYRE_FALSE@@COND_CUDA_FALSE at XSPECFEM_OBJECTS = $(SOLVER_ARRAY_OBJECTS) $(LIBSPECFEM) $(CUDA_STUBS)
+ at COND_PYRE_FALSE@@COND_CUDA_TRUE at XSPECFEM_OBJECTS = $(ADIOS_PREOBJECTS) $(SOLVER_ARRAY_OBJECTS) $(LIBSPECFEM) $(CUDA_OBJECTS) $(ADIOS_OBJECTS)
+ at COND_PYRE_FALSE@@COND_CUDA_FALSE at XSPECFEM_OBJECTS = $(ADIOS_PREOBJECTS) $(SOLVER_ARRAY_OBJECTS) $(LIBSPECFEM) $(CUDA_STUBS) $(ADIOS_OBJECTS)
 
 #######################################
 
@@ -326,9 +358,9 @@
 @COND_PYRE_FALSE@# solver also depends on values from mesher
 @COND_PYRE_FALSE at xspecfem3D: $(XSPECFEM_OBJECTS) $(COND_MPI_OBJECTS) $(COND_OPENMP_OBJECTS)
 @COND_PYRE_FALSE@@COND_CUDA_TRUE@@COND_CUDA5_TRUE@	${NVCCLINK} -o $(CUDA_DEVICE_OBJ) $(CUDA_OBJECTS)
- at COND_PYRE_FALSE@@COND_CUDA_TRUE@@COND_CUDA5_TRUE@	${FCLINK} -o ${E}/xspecfem3D $(XSPECFEM_OBJECTS) $(CUDA_DEVICE_OBJ) $(COND_MPI_OBJECTS) $(MPILIBS) $(COND_OPENMP_OBJECTS) $(OPENMP_LIBS) $(CUDA_LINK)
- at COND_PYRE_FALSE@@COND_CUDA_TRUE@@COND_CUDA5_FALSE@	${FCLINK} -o ${E}/xspecfem3D $(XSPECFEM_OBJECTS) $(COND_MPI_OBJECTS) $(MPILIBS) $(COND_OPENMP_OBJECTS) $(OPENMP_LIBS) $(CUDA_LINK)
- at COND_PYRE_FALSE@@COND_CUDA_FALSE@	${FCLINK} -o ${E}/xspecfem3D $(XSPECFEM_OBJECTS) $(COND_MPI_OBJECTS) $(MPILIBS) $(COND_OPENMP_OBJECTS) $(OPENMP_LIBS) $(CUDA_LINK)
+ at COND_PYRE_FALSE@@COND_CUDA_TRUE@@COND_CUDA5_TRUE@	${FCLINK} -o ${E}/xspecfem3D $(XSPECFEM_OBJECTS) $(CUDA_DEVICE_OBJ) $(COND_MPI_OBJECTS) $(MPILIBS) $(COND_OPENMP_OBJECTS) $(OPENMP_LIBS) $(CUDA_LINK) $(ADIOS_LINK) $(LDFLAGS)
+ at COND_PYRE_FALSE@@COND_CUDA_TRUE@@COND_CUDA5_FALSE@	${FCLINK} -o ${E}/xspecfem3D $(XSPECFEM_OBJECTS) $(COND_MPI_OBJECTS) $(MPILIBS) $(COND_OPENMP_OBJECTS) $(OPENMP_LIBS) $(CUDA_LINK) $(ADIOS_LINK) $(LDFLAGS)
+ at COND_PYRE_FALSE@@COND_CUDA_FALSE@	${FCLINK} -o ${E}/xspecfem3D $(XSPECFEM_OBJECTS) $(COND_MPI_OBJECTS) $(MPILIBS) $(COND_OPENMP_OBJECTS) $(OPENMP_LIBS) $(CUDA_LINK) $(ADIOS_LINK) $(LDFLAGS)
 @COND_PYRE_FALSE@
 
 convolve_source_timefunction: xconvolve_source_timefunction
@@ -388,7 +420,37 @@
 ###
 ### optimized flags (not dependent on values from mesher anymore)
 ###
+#######################################
 
+###
+### ADIOS compilation
+###
+
+$O/%.adios.o: %.F90
+	${MPIFCCOMPILE_CHECK} -c $(ADIOS_INC) $(FCFLAGS) $(MPI_INC) -o $@ $<
+
+$O/%.adios.o: %.f90
+	${MPIFCCOMPILE_CHECK} -c $(ADIOS_INC) $(FCFLAGS) $(MPI_INC) -o $@ $<
+
+$O/%.noadios.o: %.F90 
+	${FC} -c -o $@ $<
+
+$O/%.noadios.o: %.f90 
+	${FC} -c -o $@ $<
+
+$O/%.shared_noadios.o: ${SHARED}/%.f90 .FORCE
+	${MPIFC} -c -o $@ $<
+
+$O/%.shared_adios.o: ${SHARED}/%.f90 ${SHARED}/constants.h .FORCE
+	${MPIFC} -c $(ADIOS_INC) $(FCFLAGS) $(MPI_INC) -o $@ $<
+
+$O/%.shared_adios.o: ${SHARED}/%.F90 ${SHARED}/constants.h .FORCE
+	${MPIFC} -c $(ADIOS_INC) $(FCFLAGS) $(MPI_INC) -o $@ $<
+
+# Force adios helpers to be recompiled.
+.FORCE:
+
+#######################################
 $O/%.o: %.f90 $(SHARED)constants.h
 	${FCCOMPILE_CHECK} -c -o $@ $<
 

Modified: seismo/3D/SPECFEM3D/trunk/src/specfem3D/finalize_simulation.f90
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/specfem3D/finalize_simulation.f90	2013-09-17 22:36:21 UTC (rev 22797)
+++ seismo/3D/SPECFEM3D/trunk/src/specfem3D/finalize_simulation.f90	2013-09-18 14:35:14 UTC (rev 22798)
@@ -28,6 +28,7 @@
 
   subroutine finalize_simulation()
 
+  use adios_manager_mod
   use specfem_par
   use specfem_par_elastic
   use specfem_par_acoustic
@@ -265,6 +266,10 @@
   deallocate(ibelm_bottom)
   deallocate(ibelm_top)
 
+  if (ADIOS_ENABLED) then
+    call adios_cleanup()
+  endif
+
 ! close the main output file
   if(myrank == 0) then
     write(IMAIN,*)

Modified: seismo/3D/SPECFEM3D/trunk/src/specfem3D/initialize_simulation.f90
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/specfem3D/initialize_simulation.f90	2013-09-17 22:36:21 UTC (rev 22797)
+++ seismo/3D/SPECFEM3D/trunk/src/specfem3D/initialize_simulation.f90	2013-09-18 14:35:14 UTC (rev 22798)
@@ -28,6 +28,7 @@
 
   subroutine initialize_simulation()
 
+  use adios_manager_mod
   use specfem_par
   use specfem_par_elastic
   use specfem_par_acoustic
@@ -52,6 +53,9 @@
                         USE_RICKER_TIME_FUNCTION,OLSEN_ATTENUATION_RATIO,PML_CONDITIONS, &
                         PML_INSTEAD_OF_FREE_SURFACE,f0_FOR_PML,IMODEL,FULL_ATTENUATION_SOLID,TRAC_PATH)
 
+  call read_adios_parameters(ADIOS_ENABLED, ADIOS_FOR_DATABASES, &
+                             ADIOS_FOR_MESH, ADIOS_FOR_KERNELS)
+
 !! DK DK added this for now (March 2013) because CPML is not yet implemented for USE_DEVILLE_PRODUCTS;
 !! DK DK we will soon add it (in a month or so)
   if(PML_CONDITIONS .and. USE_DEVILLE_PRODUCTS) &
@@ -134,19 +138,29 @@
     call flush_IMAIN()
   endif
 
+  if (ADIOS_ENABLED) then
+    call adios_setup()
+  endif
+
   ! reads in numbers of spectral elements and points for the part of the mesh handled by this process
   call create_name_database(prname,myrank,LOCAL_PATH)
   if (OLD_TEST_TO_FIX_ONE_DAY) call create_name_database(dsmname,myrank,TRAC_PATH)  !! VM VM
-  open(unit=IIN,file=prname(1:len_trim(prname))//'external_mesh.bin',status='old',&
-        action='read',form='unformatted',iostat=ier)
-  if( ier /= 0 ) then
-    print*,'error: could not open database '
-    print*,'path: ',prname(1:len_trim(prname))//'external_mesh.bin'
-    call exit_mpi(myrank,'error opening database')
+ 
+
+  if (ADIOS_FOR_MESH) then
+    call read_mesh_for_init(NSPEC_AB, NGLOB_AB)
+  else
+	 open(unit=IIN,file=prname(1:len_trim(prname))//'external_mesh.bin',status='old',&
+          action='read',form='unformatted',iostat=ier)
+    if( ier /= 0 ) then
+      print*,'error: could not open database '
+      print*,'path: ',prname(1:len_trim(prname))//'external_mesh.bin'
+      call exit_mpi(myrank,'error opening database')
+    endif
+    read(IIN) NSPEC_AB
+    read(IIN) NGLOB_AB
+    close(IIN)
   endif
-  read(IIN) NSPEC_AB
-  read(IIN) NGLOB_AB
-  close(IIN)
 
   ! attenuation arrays size
   if( ATTENUATION ) then
@@ -236,7 +250,6 @@
 
   implicit none
 
-  integer :: sizeprocs
   integer :: ier
 
   character(len=256) :: HEADER_FILE
@@ -403,14 +416,6 @@
     NSPEC_BOUN = 1
   endif
 
-  ! transversely isotropic kernel flags
-  if( SIMULATION_TYPE == 3 ) then
-    if( SAVE_TRANSVERSE_KL .eqv. .true. .and. ANISOTROPIC_KL .eqv. .false. ) then
-      call exit_mpi(myrank, &
-        'for kernel simulations with SAVE_TRANSVERSE_KL set to .true., please also set ANISOTROPIC_KL to .true. in constants.h')
-    endif
-  endif
-
   end subroutine initialize_simulation_adjoint
 
 !

Copied: seismo/3D/SPECFEM3D/trunk/src/specfem3D/read_mesh_databases.F90 (from rev 22778, seismo/3D/SPECFEM3D/trunk/src/specfem3D/read_mesh_databases.f90)
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/specfem3D/read_mesh_databases.F90	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/src/specfem3D/read_mesh_databases.F90	2013-09-18 14:35:14 UTC (rev 22798)
@@ -0,0 +1,1182 @@
+!=====================================================================
+!
+!               S p e c f e m 3 D  V e r s i o n  2 . 1
+!               ---------------------------------------
+!
+!          Main authors: Dimitri Komatitsch and Jeroen Tromp
+!    Princeton University, USA and CNRS / INRIA / University of Pau
+! (c) Princeton University / California Institute of Technology and CNRS / INRIA / University of Pau
+!                             July 2012
+!
+! This 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 02110-1301 USA.
+!
+!=====================================================================
+!
+! United States and French Government Sponsorship Acknowledged.
+
+  subroutine read_mesh_databases()
+
+  use pml_par
+
+  use specfem_par
+  use specfem_par_elastic
+  use specfem_par_acoustic
+  use specfem_par_poroelastic
+
+  implicit none
+
+  real(kind=CUSTOM_REAL):: minl,maxl,min_all,max_all
+  integer :: ier,inum
+
+! start reading the databases
+
+! info about external mesh simulation
+  call create_name_database(prname,myrank,LOCAL_PATH)
+  open(unit=27,file=prname(1:len_trim(prname))//'external_mesh.bin',status='old',&
+      action='read',form='unformatted',iostat=ier)
+  if( ier /= 0 ) then
+    print*,'error: could not open database '
+    print*,'path: ',prname(1:len_trim(prname))//'external_mesh.bin'
+    call exit_mpi(myrank,'error opening database')
+  endif
+
+  read(27) NSPEC_AB
+  read(27) NGLOB_AB
+
+  read(27) ibool
+
+  read(27) xstore
+  read(27) ystore
+  read(27) zstore
+
+  read(27) xix
+  read(27) xiy
+  read(27) xiz
+  read(27) etax
+  read(27) etay
+  read(27) etaz
+  read(27) gammax
+  read(27) gammay
+  read(27) gammaz
+  read(27) jacobian
+
+  read(27) kappastore
+  read(27) mustore
+
+  read(27) ispec_is_acoustic
+  read(27) ispec_is_elastic
+  read(27) ispec_is_poroelastic
+
+  ! acoustic
+  ! number of acoustic elements in this partition
+  nspec_acoustic = count(ispec_is_acoustic(:))
+  ! all processes will have acoustic_simulation set if any flag is .true.
+  call any_all_l( ANY(ispec_is_acoustic), ACOUSTIC_SIMULATION )
+  if( ACOUSTIC_SIMULATION ) then
+    ! potentials
+    allocate(potential_acoustic(NGLOB_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array potential_acoustic'
+    allocate(potential_dot_acoustic(NGLOB_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array potential_dot_acoustic'
+    allocate(potential_dot_dot_acoustic(NGLOB_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array potential_dot_dot_acoustic'
+    allocate(potential_dot_dot_acoustic_interface(NGLOB_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array potential_dot_dot_acoustic_interface'
+    if( SIMULATION_TYPE /= 1 ) then
+      allocate(potential_acoustic_adj_coupling(NGLOB_AB),stat=ier)
+      if( ier /= 0 ) stop 'error allocating array potential_acoustic_adj_coupling'
+    endif
+    ! mass matrix, density
+    allocate(rmass_acoustic(NGLOB_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array rmass_acoustic'
+    allocate(rmass_acoustic_interface(NGLOB_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array rmass_acoustic_interface'
+    read(27) rmass_acoustic
+    read(27) rmass_acoustic_interface
+
+    ! initializes mass matrix contribution
+    allocate(rmassz_acoustic(NGLOB_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array rmassz_acoustic'
+    rmassz_acoustic(:) = 0._CUSTOM_REAL
+  endif
+
+! this array is needed for acoustic simulations but also for elastic simulations with CPML,
+! thus we now allocate it and read it in all cases (whether the simulation is acoustic, elastic, or acoustic/elastic)
+  allocate(rhostore(NGLLX,NGLLY,NGLLZ,NSPEC_AB),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array rhostore'
+  read(27) rhostore
+
+  ! elastic
+  ! number of elastic elements in this partition
+  nspec_elastic = count(ispec_is_elastic(:))
+
+  ! elastic simulation
+  call any_all_l( ANY(ispec_is_elastic), ELASTIC_SIMULATION )
+  if( ELASTIC_SIMULATION ) then
+    ! displacement,velocity,acceleration
+    allocate(displ(NDIM,NGLOB_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array displ'
+    allocate(veloc(NDIM,NGLOB_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array veloc'
+    allocate(accel(NDIM,NGLOB_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array accel'
+    if( SIMULATION_TYPE /= 1 ) then
+      allocate(accel_adj_coupling(NDIM,NGLOB_AB),stat=ier)
+      if( ier /= 0 ) stop 'error allocating array accel_adj_coupling'
+    endif
+
+    ! allocates mass matrix
+    allocate(rmass(NGLOB_AB),stat=ier)
+
+    if(PML_CONDITIONS)then
+       if(ACOUSTIC_SIMULATION)then
+          allocate(rmass_elastic_interface(NGLOB_AB),stat=ier)
+          if( ier /= 0 ) stop 'error allocating array rmass_elastic_interface'
+          rmass_elastic_interface(:) = 0._CUSTOM_REAL
+          if(SIMULATION_TYPE == 3)then
+            allocate(accel_interface(NDIM,NGLOB_AB),stat=ier)
+            if( ier /= 0 ) stop 'error allocating array accel_interface'
+            accel_interface(:,:) = 0._CUSTOM_REAL
+          else
+            allocate(accel_interface(NDIM,1),stat=ier)
+            if( ier /= 0 ) stop 'error allocating array accel_interface'
+            accel_interface(:,:) = 0._CUSTOM_REAL
+          endif
+       else
+          allocate(rmass_elastic_interface(1),stat=ier)
+          allocate(accel_interface(NDIM,1),stat=ier)
+       endif
+    else
+      allocate(rmass_elastic_interface(1),stat=ier)
+      allocate(accel_interface(NDIM,1),stat=ier)
+    endif
+
+    if( ier /= 0 ) stop 'error allocating array rmass'
+    ! initializes mass matrix contributions
+    allocate(rmassx(NGLOB_AB), &
+             rmassy(NGLOB_AB), &
+             rmassz(NGLOB_AB), &
+             stat=ier)
+    if( ier /= 0 ) stop 'error allocating array rmassx,rmassy,rmassz'
+    rmassx(:) = 0._CUSTOM_REAL
+    rmassy(:) = 0._CUSTOM_REAL
+    rmassz(:) = 0._CUSTOM_REAL
+
+    allocate(rho_vp(NGLLX,NGLLY,NGLLZ,NSPEC_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array rho_vp'
+    allocate(rho_vs(NGLLX,NGLLY,NGLLZ,NSPEC_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array rho_vs'
+    allocate(c11store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
+            c12store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
+            c13store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
+            c14store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
+            c15store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
+            c16store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
+            c22store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
+            c23store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
+            c24store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
+            c25store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
+            c26store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
+            c33store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
+            c34store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
+            c35store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
+            c36store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
+            c44store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
+            c45store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
+            c46store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
+            c55store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
+            c56store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
+            c66store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array c11store etc.'
+
+    ! note: currently, they need to be defined, as they are used in the routine arguments
+    !          for compute_forces_viscoelastic_Deville()
+    allocate(R_xx(NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB,N_SLS), &
+            R_yy(NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB,N_SLS), &
+            R_xy(NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB,N_SLS), &
+            R_xz(NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB,N_SLS), &
+            R_yz(NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB,N_SLS),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array R_xx etc.'
+
+    ! needed for attenuation and/or kernel computations
+    allocate(epsilondev_xx(NGLLX,NGLLY,NGLLZ,NSPEC_STRAIN_ONLY), &
+            epsilondev_yy(NGLLX,NGLLY,NGLLZ,NSPEC_STRAIN_ONLY), &
+            epsilondev_xy(NGLLX,NGLLY,NGLLZ,NSPEC_STRAIN_ONLY), &
+            epsilondev_xz(NGLLX,NGLLY,NGLLZ,NSPEC_STRAIN_ONLY), &
+            epsilondev_yz(NGLLX,NGLLY,NGLLZ,NSPEC_STRAIN_ONLY),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array epsilondev_xx etc.'
+
+    allocate(R_trace(NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB_kappa,N_SLS),&
+             epsilondev_trace(NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB_kappa),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array R_trace etc.'
+
+    ! note: needed for argument of deville routine
+    allocate(epsilon_trace_over_3(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array epsilon_trace_over_3'
+
+    ! needed for attenuation
+    allocate(one_minus_sum_beta(NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB), &
+            factor_common(N_SLS,NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array one_minus_sum_beta etc.'
+
+    allocate(one_minus_sum_beta_kappa(NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB_kappa), &
+             factor_common_kappa(N_SLS,NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB_kappa),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array one_minus_sum_beta_kappa etc.'
+
+    ! reads mass matrices
+    read(27,iostat=ier) rmass
+    if( ier /= 0 ) stop 'error reading in array rmass'
+
+    if(PML_CONDITIONS)then !need to be optimized
+       if(ACOUSTIC_SIMULATION)then
+          read(27,iostat=ier) rmass_elastic_interface
+          if( ier /= 0 ) stop 'error reading in array rmass_elastic_interface'
+       endif
+    endif
+
+    if( APPROXIMATE_OCEAN_LOAD ) then
+      ! ocean mass matrix
+      allocate(rmass_ocean_load(NGLOB_AB),stat=ier)
+      if( ier /= 0 ) stop 'error allocating array rmass_ocean_load'
+      read(27) rmass_ocean_load
+    else
+      ! dummy allocation
+      allocate(rmass_ocean_load(1),stat=ier)
+      if( ier /= 0 ) stop 'error allocating dummy array rmass_ocean_load'
+    endif
+
+    !pll material parameters for stacey conditions
+    read(27,iostat=ier) rho_vp
+    if( ier /= 0 ) stop 'error reading in array rho_vp'
+    read(27,iostat=ier) rho_vs
+    if( ier /= 0 ) stop 'error reading in array rho_vs'
+
+!! DK DK rhostore is now allocated and read in all cases (see above)
+!   ! checks if rhostore is available for gravity
+!   if( GRAVITY ) then
+!
+!     if( .not. ACOUSTIC_SIMULATION ) then
+!       ! rho array needed for gravity
+!       allocate(rhostore(NGLLX,NGLLY,NGLLZ,NSPEC_AB),stat=ier)
+!       if( ier /= 0 ) stop 'error allocating array rhostore'
+!
+!       ! extract rho information from mu = rho * vs * vs and rho_vs = rho * vs
+!       rhostore = 0.0_CUSTOM_REAL
+!       where( mustore > TINYVAL )
+!         rhostore = (rho_vs*rho_vs) / mustore
+!       endwhere
+!
+!       ! note: the construct below leads to a segmentation fault (ifort v11.1). not sure why...
+!       !          (where statement - standard fortran 95)
+!       !where( mustore > TINYVAL )
+!       !  rhostore = (rho_vs*rho_vs) / mustore
+!       !elsewhere
+!       !  rhostore = 0.0_CUSTOM_REAL
+!       !endwhere
+!     endif
+!   endif
+  else
+    ! no elastic attenuation & anisotropy
+    ATTENUATION = .false.
+    ANISOTROPY = .false.
+  endif
+
+  ! poroelastic
+  call any_all_l( ANY(ispec_is_poroelastic), POROELASTIC_SIMULATION )
+  if( POROELASTIC_SIMULATION ) then
+
+    if( GPU_MODE ) call exit_mpi(myrank,'POROELASTICITY not supported by GPU mode yet...')
+
+    ! displacement,velocity,acceleration for the solid (s) & fluid (w) phases
+    allocate(displs_poroelastic(NDIM,NGLOB_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array displs_poroelastic'
+    allocate(velocs_poroelastic(NDIM,NGLOB_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array velocs_poroelastic'
+    allocate(accels_poroelastic(NDIM,NGLOB_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array accels_poroelastic'
+    allocate(displw_poroelastic(NDIM,NGLOB_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array displw_poroelastic'
+    allocate(velocw_poroelastic(NDIM,NGLOB_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array velocw_poroelastic'
+    allocate(accelw_poroelastic(NDIM,NGLOB_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array accelw_poroelastic'
+
+    allocate(rmass_solid_poroelastic(NGLOB_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array rmass_solid_poroelastic'
+    allocate(rmass_fluid_poroelastic(NGLOB_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array rmass_fluid_poroelastic'
+
+    allocate(rhoarraystore(2,NGLLX,NGLLY,NGLLZ,NSPEC_AB), &
+             kappaarraystore(3,NGLLX,NGLLY,NGLLZ,NSPEC_AB), &
+             etastore(NGLLX,NGLLY,NGLLZ,NSPEC_AB), &
+             tortstore(NGLLX,NGLLY,NGLLZ,NSPEC_AB), &
+             phistore(NGLLX,NGLLY,NGLLZ,NSPEC_AB), &
+             permstore(6,NGLLX,NGLLY,NGLLZ,NSPEC_AB), &
+             rho_vpI(NGLLX,NGLLY,NGLLZ,NSPEC_AB), &
+             rho_vpII(NGLLX,NGLLY,NGLLZ,NSPEC_AB), &
+             rho_vsI(NGLLX,NGLLY,NGLLZ,NSPEC_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array poroelastic properties'
+
+    ! needed for kernel computations
+    allocate(epsilonsdev_xx(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            epsilonsdev_yy(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            epsilonsdev_xy(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            epsilonsdev_xz(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            epsilonsdev_yz(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            epsilonwdev_xx(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            epsilonwdev_yy(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            epsilonwdev_xy(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            epsilonwdev_xz(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            epsilonwdev_yz(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array epsilonsdev_xx etc.'
+
+    allocate(epsilons_trace_over_3(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            epsilonw_trace_over_3(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array epsilons_trace_over_3 etc.'
+
+
+    read(27) rmass_solid_poroelastic
+    read(27) rmass_fluid_poroelastic
+    read(27) rhoarraystore
+    read(27) kappaarraystore
+    read(27) etastore
+    read(27) tortstore
+    read(27) permstore
+    read(27) phistore
+    read(27) rho_vpI
+    read(27) rho_vpII
+    read(27) rho_vsI
+  endif
+
+  ! checks simulation types are valid
+  if( (.not. ACOUSTIC_SIMULATION ) .and. &
+     (.not. ELASTIC_SIMULATION ) .and. &
+     (.not. POROELASTIC_SIMULATION ) ) then
+     close(27)
+     call exit_mpi(myrank,'error no simulation type defined')
+  endif
+
+  ! C-PML absorbing boundary conditions
+  NSPEC_CPML = 0
+  if( PML_CONDITIONS ) then
+    read(27) NSPEC_CPML
+    read(27) CPML_width_x
+    read(27) CPML_width_y
+    read(27) CPML_width_z
+
+    allocate(is_CPML(NSPEC_AB),stat=ier)
+    if(ier /= 0) stop 'error allocating array is_CPML'
+
+! make sure there are no PMLs by default,
+! and then below if NSPEC_CPML > 0 we will need the real flags for this mesh from the disk
+    is_CPML(:) = .false.
+
+    if( NSPEC_CPML > 0 ) then
+      allocate(CPML_regions(NSPEC_CPML),stat=ier)
+      if(ier /= 0) stop 'error allocating array CPML_regions'
+      allocate(CPML_to_spec(NSPEC_CPML),stat=ier)
+      if(ier /= 0) stop 'error allocating array CPML_to_spec'
+      allocate(d_store_x(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
+      if(ier /= 0) stop 'error allocating array d_store_x'
+      allocate(d_store_y(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
+      if(ier /= 0) stop 'error allocating array d_store_y'
+      allocate(d_store_z(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
+      if(ier /= 0) stop 'error allocating array d_store_z'
+      allocate(K_store_x(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
+      if(ier /= 0) stop 'error allocating array K_store_x'
+      allocate(K_store_y(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
+      if(ier /= 0) stop 'error allocating array K_store_y'
+      allocate(K_store_z(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
+      if(ier /= 0) stop 'error allocating array K_store_z'
+      allocate(alpha_store(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
+      if(ier /= 0) stop 'error allocating array alpha_store'
+
+      read(27) CPML_regions
+      read(27) CPML_to_spec
+      read(27) is_CPML
+      read(27) d_store_x
+      read(27) d_store_y
+      read(27) d_store_z
+      read(27) k_store_x
+      read(27) k_store_y
+      read(27) k_store_z
+      read(27) alpha_store
+
+      if((SIMULATION_TYPE == 1 .and. SAVE_FORWARD) .or. SIMULATION_TYPE == 3) then
+        read(27) nglob_interface_PML_acoustic
+        read(27) nglob_interface_PML_elastic
+        if(nglob_interface_PML_acoustic > 0) then
+          allocate(points_interface_PML_acoustic(nglob_interface_PML_acoustic),stat=ier)
+          if(ier /= 0) stop 'error allocating array points_interface_PML_acoustic'
+          read(27) points_interface_PML_acoustic
+        endif
+        if(nglob_interface_PML_elastic > 0) then
+          allocate(points_interface_PML_elastic(nglob_interface_PML_elastic),stat=ier)
+          if(ier /= 0) stop 'error allocating array points_interface_PML_elastic'
+          read(27) points_interface_PML_elastic
+        endif
+      endif
+    endif
+  else
+    ! allocate with a dummy size of zero just to be able to use this array as argument in subroutine calls
+    allocate(is_CPML(0),stat=ier)
+  endif
+
+  ! absorbing boundary surface
+  read(27) num_abs_boundary_faces
+
+  ! checks
+  if( num_abs_boundary_faces < 0 ) then
+    print*,'read_mesh_databases: reading in negative num_abs_boundary_faces ',num_abs_boundary_faces,'...resetting to zero'
+    num_abs_boundary_faces = 0
+  endif
+  allocate(abs_boundary_ispec(num_abs_boundary_faces), &
+          abs_boundary_ijk(3,NGLLSQUARE,num_abs_boundary_faces), &
+          abs_boundary_jacobian2Dw(NGLLSQUARE,num_abs_boundary_faces), &
+          abs_boundary_normal(NDIM,NGLLSQUARE,num_abs_boundary_faces),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array abs_boundary_ispec etc.'
+
+  if (OLD_TEST_TO_FIX_ONE_DAY) then
+     ! VM for new method
+!! DK DK for VM VM: these two arrays are undeclared, thus I comment them out for now otherwise the code does not compile
+!! VM VM : I already declared these two array in the specfem_par module
+     allocate(Veloc_dsm_boundary(3,Ntime_step_dsm,NGLLSQUARE,num_abs_boundary_faces))
+     allocate(Tract_dsm_boundary(3,Ntime_step_dsm,NGLLSQUARE,num_abs_boundary_faces))
+     open(unit=IIN_veloc_dsm,file=dsmname(1:len_trim(dsmname))//'vel.bin',status='old', &
+          action='read',form='unformatted',iostat=ier)
+     open(unit=IIN_tract_dsm,file=dsmname(1:len_trim(dsmname))//'tract.bin',status='old', &
+          action='read',form='unformatted',iostat=ier)
+  else
+     allocate(Veloc_dsm_boundary(1,1,1,1))
+     allocate(Tract_dsm_boundary(1,1,1,1))
+  endif
+
+  if(PML_CONDITIONS)then
+     if( num_abs_boundary_faces > 0 ) then
+       read(27) abs_boundary_ispec
+       read(27) abs_boundary_ijk
+       read(27) abs_boundary_jacobian2Dw
+       read(27) abs_boundary_normal
+     endif
+  else
+     if( num_abs_boundary_faces > 0 ) then
+       read(27) abs_boundary_ispec
+       read(27) abs_boundary_ijk
+       read(27) abs_boundary_jacobian2Dw
+       read(27) abs_boundary_normal
+       if( STACEY_ABSORBING_CONDITIONS ) then
+          ! store mass matrix contributions
+          if(ELASTIC_SIMULATION) then
+           read(27) rmassx
+           read(27) rmassy
+           read(27) rmassz
+          endif
+          if(ACOUSTIC_SIMULATION) then
+           read(27) rmassz_acoustic
+          endif
+       endif
+     endif
+  endif
+
+  read(27) nspec2D_xmin
+  read(27) nspec2D_xmax
+  read(27) nspec2D_ymin
+  read(27) nspec2D_ymax
+  read(27) NSPEC2D_BOTTOM
+  read(27) NSPEC2D_TOP
+
+  allocate(ibelm_xmin(nspec2D_xmin),ibelm_xmax(nspec2D_xmax), &
+       ibelm_ymin(nspec2D_ymin),ibelm_ymax(nspec2D_ymax), &
+       ibelm_bottom(NSPEC2D_BOTTOM),ibelm_top(NSPEC2D_TOP),stat=ier)
+  if(ier /= 0) stop 'error allocating arrays ibelm_xmin,ibelm_xmax etc.'
+  read(27) ibelm_xmin
+  read(27) ibelm_xmax
+  read(27) ibelm_ymin
+  read(27) ibelm_ymax
+  read(27) ibelm_bottom
+  read(27) ibelm_top
+
+  ! free surface
+  read(27) num_free_surface_faces
+  allocate(free_surface_ispec(num_free_surface_faces), &
+          free_surface_ijk(3,NGLLSQUARE,num_free_surface_faces), &
+          free_surface_jacobian2Dw(NGLLSQUARE,num_free_surface_faces), &
+          free_surface_normal(NDIM,NGLLSQUARE,num_free_surface_faces),stat=ier)
+  if(ier /= 0) stop 'error allocating arrays free_surface_ispec etc.'
+  if( num_free_surface_faces > 0 ) then
+    read(27) free_surface_ispec
+    read(27) free_surface_ijk
+    read(27) free_surface_jacobian2Dw
+    read(27) free_surface_normal
+  endif
+
+  ! acoustic-elastic coupling surface
+  read(27) num_coupling_ac_el_faces
+  allocate(coupling_ac_el_normal(NDIM,NGLLSQUARE,num_coupling_ac_el_faces), &
+          coupling_ac_el_jacobian2Dw(NGLLSQUARE,num_coupling_ac_el_faces), &
+          coupling_ac_el_ijk(3,NGLLSQUARE,num_coupling_ac_el_faces), &
+          coupling_ac_el_ispec(num_coupling_ac_el_faces),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array coupling_ac_el_normal etc.'
+  if( num_coupling_ac_el_faces > 0 ) then
+    read(27) coupling_ac_el_ispec
+    read(27) coupling_ac_el_ijk
+    read(27) coupling_ac_el_jacobian2Dw
+    read(27) coupling_ac_el_normal
+  endif
+
+  ! acoustic-poroelastic coupling surface
+  read(27) num_coupling_ac_po_faces
+  allocate(coupling_ac_po_normal(NDIM,NGLLSQUARE,num_coupling_ac_po_faces), &
+          coupling_ac_po_jacobian2Dw(NGLLSQUARE,num_coupling_ac_po_faces), &
+          coupling_ac_po_ijk(3,NGLLSQUARE,num_coupling_ac_po_faces), &
+          coupling_ac_po_ispec(num_coupling_ac_po_faces),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array coupling_ac_po_normal etc.'
+  if( num_coupling_ac_po_faces > 0 ) then
+    read(27) coupling_ac_po_ispec
+    read(27) coupling_ac_po_ijk
+    read(27) coupling_ac_po_jacobian2Dw
+    read(27) coupling_ac_po_normal
+  endif
+
+  ! elastic-poroelastic coupling surface
+  read(27) num_coupling_el_po_faces
+  allocate(coupling_el_po_normal(NDIM,NGLLSQUARE,num_coupling_el_po_faces), &
+          coupling_el_po_jacobian2Dw(NGLLSQUARE,num_coupling_el_po_faces), &
+          coupling_el_po_ijk(3,NGLLSQUARE,num_coupling_el_po_faces), &
+          coupling_po_el_ijk(3,NGLLSQUARE,num_coupling_el_po_faces), &
+          coupling_el_po_ispec(num_coupling_el_po_faces), &
+          coupling_po_el_ispec(num_coupling_el_po_faces),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array coupling_el_po_normal etc.'
+  if( num_coupling_el_po_faces > 0 ) then
+    read(27) coupling_el_po_ispec
+    read(27) coupling_po_el_ispec
+    read(27) coupling_el_po_ijk
+    read(27) coupling_po_el_ijk
+    read(27) coupling_el_po_jacobian2Dw
+    read(27) coupling_el_po_normal
+  endif
+
+  ! MPI interfaces
+  read(27) num_interfaces_ext_mesh
+  allocate(my_neighbours_ext_mesh(num_interfaces_ext_mesh), &
+          nibool_interfaces_ext_mesh(num_interfaces_ext_mesh),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array my_neighbours_ext_mesh etc.'
+  if( num_interfaces_ext_mesh > 0 ) then
+    read(27) max_nibool_interfaces_ext_mesh
+    allocate(ibool_interfaces_ext_mesh(max_nibool_interfaces_ext_mesh,num_interfaces_ext_mesh),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array ibool_interfaces_ext_mesh'
+    read(27) my_neighbours_ext_mesh
+    read(27) nibool_interfaces_ext_mesh
+    read(27) ibool_interfaces_ext_mesh
+  else
+    max_nibool_interfaces_ext_mesh = 0
+    allocate(ibool_interfaces_ext_mesh(0,0),stat=ier)
+  endif
+
+  if( ELASTIC_SIMULATION .and. ANISOTROPY ) then
+    read(27) c11store
+    read(27) c12store
+    read(27) c13store
+    read(27) c14store
+    read(27) c15store
+    read(27) c16store
+    read(27) c22store
+    read(27) c23store
+    read(27) c24store
+    read(27) c25store
+    read(27) c26store
+    read(27) c33store
+    read(27) c34store
+    read(27) c35store
+    read(27) c36store
+    read(27) c44store
+    read(27) c45store
+    read(27) c46store
+    read(27) c55store
+    read(27) c56store
+    read(27) c66store
+  endif
+
+  ! inner / outer elements
+  allocate(ispec_is_inner(NSPEC_AB),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array ispec_is_inner'
+  read(27) ispec_is_inner
+
+  if( ACOUSTIC_SIMULATION ) then
+    read(27) nspec_inner_acoustic,nspec_outer_acoustic
+    read(27) num_phase_ispec_acoustic
+    if( num_phase_ispec_acoustic < 0 ) stop 'error acoustic simulation: num_phase_ispec_acoustic is < zero'
+    allocate( phase_ispec_inner_acoustic(num_phase_ispec_acoustic,2),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array phase_ispec_inner_acoustic'
+    if(num_phase_ispec_acoustic > 0 ) read(27) phase_ispec_inner_acoustic
+  endif
+
+  if( ELASTIC_SIMULATION ) then
+    read(27) nspec_inner_elastic,nspec_outer_elastic
+    read(27) num_phase_ispec_elastic
+    if( num_phase_ispec_elastic < 0 ) stop 'error elastic simulation: num_phase_ispec_elastic is < zero'
+    allocate( phase_ispec_inner_elastic(num_phase_ispec_elastic,2),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array phase_ispec_inner_elastic'
+    if(num_phase_ispec_elastic > 0 ) read(27) phase_ispec_inner_elastic
+  endif
+
+  if( POROELASTIC_SIMULATION ) then
+    read(27) nspec_inner_poroelastic,nspec_outer_poroelastic
+    read(27) num_phase_ispec_poroelastic
+    if( num_phase_ispec_poroelastic < 0 ) stop 'error poroelastic simulation: num_phase_ispec_poroelastic is < zero'
+    allocate( phase_ispec_inner_poroelastic(num_phase_ispec_poroelastic,2),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array phase_ispec_inner_poroelastic'
+    if(num_phase_ispec_poroelastic > 0 ) read(27) phase_ispec_inner_poroelastic
+  endif
+
+! mesh coloring for GPUs
+  if( USE_MESH_COLORING_GPU ) then
+    ! acoustic domain colors
+    if( ACOUSTIC_SIMULATION ) then
+      read(27) num_colors_outer_acoustic,num_colors_inner_acoustic
+
+      allocate(num_elem_colors_acoustic(num_colors_outer_acoustic + num_colors_inner_acoustic),stat=ier)
+      if( ier /= 0 ) stop 'error allocating num_elem_colors_acoustic array'
+
+      read(27) num_elem_colors_acoustic
+    endif
+    ! elastic domain colors
+    if( ELASTIC_SIMULATION ) then
+      read(27) num_colors_outer_elastic,num_colors_inner_elastic
+
+      allocate(num_elem_colors_elastic(num_colors_outer_elastic + num_colors_inner_elastic),stat=ier)
+      if( ier /= 0 ) stop 'error allocating num_elem_colors_elastic array'
+
+      read(27) num_elem_colors_elastic
+    endif
+  else
+    ! allocates dummy arrays
+    if( ACOUSTIC_SIMULATION ) then
+      num_colors_outer_acoustic = 0
+      num_colors_inner_acoustic = 0
+      allocate(num_elem_colors_acoustic(num_colors_outer_acoustic + num_colors_inner_acoustic),stat=ier)
+      if( ier /= 0 ) stop 'error allocating num_elem_colors_acoustic array'
+    endif
+    if( ELASTIC_SIMULATION ) then
+      num_colors_outer_elastic = 0
+      num_colors_inner_elastic = 0
+      allocate(num_elem_colors_elastic(num_colors_outer_elastic + num_colors_inner_elastic),stat=ier)
+      if( ier /= 0 ) stop 'error allocating num_elem_colors_elastic array'
+    endif
+  endif
+  close(27)
+
+  ! outputs total element numbers
+  call sum_all_i(count(ispec_is_acoustic(:)),inum)
+  if( myrank == 0 ) then
+    write(IMAIN,*) 'total acoustic elements    :',inum
+  endif
+  call sum_all_i(count(ispec_is_elastic(:)),inum)
+  if( myrank == 0 ) then
+    write(IMAIN,*) 'total elastic elements     :',inum
+  endif
+  call sum_all_i(count(ispec_is_poroelastic(:)),inum)
+  if( myrank == 0 ) then
+    write(IMAIN,*) 'total poroelastic elements :',inum
+    call flush_IMAIN()
+  endif
+
+  ! debug
+  !call sum_all_i(num_interfaces_ext_mesh,inum)
+  !if(myrank == 0) then
+  !  write(IMAIN,*) 'number of MPI partition interfaces: ',inum
+  !  write(IMAIN,*)
+  !endif
+
+  ! MPI communications
+  if( ACOUSTIC_SIMULATION ) then
+    allocate(buffer_send_scalar_ext_mesh(max_nibool_interfaces_ext_mesh,num_interfaces_ext_mesh), &
+             buffer_recv_scalar_ext_mesh(max_nibool_interfaces_ext_mesh,num_interfaces_ext_mesh), &
+             request_send_scalar_ext_mesh(num_interfaces_ext_mesh), &
+             request_recv_scalar_ext_mesh(num_interfaces_ext_mesh), &
+             stat=ier)
+    if( ier /= 0 ) stop 'error allocating array buffer_send_scalar_ext_mesh,.. for acoustic simulations'
+  endif
+  if( ELASTIC_SIMULATION ) then
+    allocate(buffer_send_vector_ext_mesh(NDIM,max_nibool_interfaces_ext_mesh,num_interfaces_ext_mesh), &
+             buffer_recv_vector_ext_mesh(NDIM,max_nibool_interfaces_ext_mesh,num_interfaces_ext_mesh), &
+             request_send_vector_ext_mesh(num_interfaces_ext_mesh), &
+             request_recv_vector_ext_mesh(num_interfaces_ext_mesh), &
+             stat=ier)
+    if( ier /= 0 ) stop 'error allocating array buffer_send_vector_ext_mesh,.. for elastic simulations'
+  endif
+  if( POROELASTIC_SIMULATION ) then
+    allocate(buffer_send_vector_ext_mesh_s(NDIM,max_nibool_interfaces_ext_mesh,num_interfaces_ext_mesh), &
+             buffer_recv_vector_ext_mesh_s(NDIM,max_nibool_interfaces_ext_mesh,num_interfaces_ext_mesh), &
+             buffer_send_vector_ext_mesh_w(NDIM,max_nibool_interfaces_ext_mesh,num_interfaces_ext_mesh), &
+             buffer_recv_vector_ext_mesh_w(NDIM,max_nibool_interfaces_ext_mesh,num_interfaces_ext_mesh), &
+             request_send_vector_ext_mesh_s(num_interfaces_ext_mesh), &
+             request_recv_vector_ext_mesh_s(num_interfaces_ext_mesh), &
+             request_send_vector_ext_mesh_w(num_interfaces_ext_mesh), &
+             request_recv_vector_ext_mesh_w(num_interfaces_ext_mesh), &
+             stat=ier)
+    if( ier /= 0 ) stop 'error allocating array buffer_send_vector_ext_mesh_s,.. for poroelastic simulations'
+  endif
+
+  ! gets model dimensions
+  minl = minval( xstore )
+  maxl = maxval( xstore )
+  call min_all_all_cr(minl,min_all)
+  call max_all_all_cr(maxl,max_all)
+  LONGITUDE_MIN = min_all
+  LONGITUDE_MAX = max_all
+
+  minl = minval( ystore )
+  maxl = maxval( ystore )
+  call min_all_all_cr(minl,min_all)
+  call max_all_all_cr(maxl,max_all)
+  LATITUDE_MIN = min_all
+  LATITUDE_MAX = max_all
+
+  ! checks courant criteria on mesh
+  if( ELASTIC_SIMULATION ) then
+    call check_mesh_resolution(myrank,NSPEC_AB,NGLOB_AB, &
+                              ibool,xstore,ystore,zstore, &
+                              kappastore,mustore,rho_vp,rho_vs, &
+                              DT,model_speed_max,min_resolved_period, &
+                              LOCAL_PATH,SAVE_MESH_FILES)
+
+  else if( POROELASTIC_SIMULATION ) then
+    allocate(rho_vp(NGLLX,NGLLY,NGLLZ,NSPEC_AB))
+    allocate(rho_vs(NGLLX,NGLLY,NGLLZ,NSPEC_AB))
+    rho_vp = 0.0_CUSTOM_REAL
+    rho_vs = 0.0_CUSTOM_REAL
+    call check_mesh_resolution_poro(myrank,NSPEC_AB,NGLOB_AB,ibool,xstore,ystore,zstore, &
+                                    DT,model_speed_max,min_resolved_period, &
+                                    phistore,tortstore,rhoarraystore,rho_vpI,rho_vpII,rho_vsI, &
+                                    LOCAL_PATH,SAVE_MESH_FILES)
+    deallocate(rho_vp,rho_vs)
+  else if( ACOUSTIC_SIMULATION ) then
+    allocate(rho_vp(NGLLX,NGLLY,NGLLZ,NSPEC_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array rho_vp'
+    allocate(rho_vs(NGLLX,NGLLY,NGLLZ,NSPEC_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array rho_vs'
+    rho_vp = sqrt( kappastore / rhostore ) * rhostore
+    rho_vs = 0.0_CUSTOM_REAL
+    call check_mesh_resolution(myrank,NSPEC_AB,NGLOB_AB, &
+                              ibool,xstore,ystore,zstore, &
+                              kappastore,mustore,rho_vp,rho_vs, &
+                              DT,model_speed_max,min_resolved_period, &
+                              LOCAL_PATH,SAVE_MESH_FILES)
+    deallocate(rho_vp,rho_vs)
+  endif
+
+  ! reads adjoint parameters
+  call read_mesh_databases_adjoint()
+
+  end subroutine read_mesh_databases
+
+
+!
+!-------------------------------------------------------------------------------------------------
+!
+
+  subroutine read_mesh_databases_adjoint()
+
+! reads in moho meshes
+
+  use specfem_par
+  use specfem_par_elastic
+  use specfem_par_acoustic
+  use specfem_par_poroelastic
+  implicit none
+
+  integer :: ier
+
+  ! allocates adjoint arrays for elastic simulations
+  if( ELASTIC_SIMULATION .and. SIMULATION_TYPE == 3 ) then
+    ! backward displacement,velocity,acceleration fields
+    allocate(b_displ(NDIM,NGLOB_ADJOINT),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array b_displ'
+    allocate(b_veloc(NDIM,NGLOB_ADJOINT),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array b_veloc'
+    allocate(b_accel(NDIM,NGLOB_ADJOINT),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array b_accel'
+
+    ! adjoint kernels
+
+    ! primary, isotropic kernels
+    ! density kernel
+    allocate(rho_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array rho_kl'
+
+    if (ANISOTROPIC_KL) then
+      ! anisotropic kernels
+      allocate(cijkl_kl(21,NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT),stat=ier)
+      if( ier /= 0 ) stop 'error allocating array cijkl_kl'
+      !dummy
+      allocate(mu_kl(1,1,1,1))
+      allocate(kappa_kl(1,1,1,1))
+    else
+      ! shear modulus kernel
+      allocate(mu_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT),stat=ier)
+      if( ier /= 0 ) stop 'error allocating array mu_kl'
+      ! compressional modulus kernel
+      allocate(kappa_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT),stat=ier)
+      if( ier /= 0 ) stop 'error allocating array kappa_kl'
+      !dummy
+      allocate(cijkl_kl(1,1,1,1,1))
+    endif
+
+    ! noise source strength kernel
+    if (NOISE_TOMOGRAPHY == 3) then
+      allocate(sigma_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT),stat=ier)
+      if( ier /= 0 ) stop 'error allocating array sigma_kl'
+    endif
+
+    ! preconditioner
+    if ( APPROXIMATE_HESS_KL ) then
+      allocate(hess_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT),stat=ier)
+      if( ier /= 0 ) stop 'error allocating array hess_kl'
+    else
+      ! dummy allocation
+      allocate(hess_kl(0,0,0,0),stat=ier)
+      if( ier /= 0 ) stop 'error allocating dummy array hess_kl'
+    endif
+
+    ! MPI handling
+    allocate(b_request_send_vector_ext_mesh(num_interfaces_ext_mesh), &
+             b_request_recv_vector_ext_mesh(num_interfaces_ext_mesh), &
+             b_buffer_send_vector_ext_mesh(NDIM,max_nibool_interfaces_ext_mesh,num_interfaces_ext_mesh), &
+             b_buffer_recv_vector_ext_mesh(NDIM,max_nibool_interfaces_ext_mesh,num_interfaces_ext_mesh),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array b_request_send_vector_ext_mesh etc.'
+
+    ! allocates attenuation solids
+    allocate(b_R_xx(NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB,N_SLS), &
+             b_R_yy(NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB,N_SLS), &
+             b_R_xy(NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB,N_SLS), &
+             b_R_xz(NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB,N_SLS), &
+             b_R_yz(NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB,N_SLS),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array b_R_xx etc.'
+
+    ! note: these arrays are needed for attenuation and/or kernel computations
+    allocate(b_epsilondev_xx(NGLLX,NGLLY,NGLLZ,NSPEC_STRAIN_ONLY), &
+            b_epsilondev_yy(NGLLX,NGLLY,NGLLZ,NSPEC_STRAIN_ONLY), &
+            b_epsilondev_xy(NGLLX,NGLLY,NGLLZ,NSPEC_STRAIN_ONLY), &
+            b_epsilondev_xz(NGLLX,NGLLY,NGLLZ,NSPEC_STRAIN_ONLY), &
+            b_epsilondev_yz(NGLLX,NGLLY,NGLLZ,NSPEC_STRAIN_ONLY),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array b_epsilon_dev_xx etc.'
+    ! needed for kernel computations
+    allocate(b_epsilon_trace_over_3(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array b_epsilon_trace_over_3'
+
+    ! allocates attenuation solids for considering kappa
+    allocate(b_R_trace(NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB_kappa,N_SLS),&
+             b_epsilondev_trace(NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB_kappa),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array b_R_trace etc.'
+
+  else
+    ! modification: Camille Mazoyer
+    ! dummy allocation
+    allocate(b_displ(1,1),stat=ier)
+    if( ier /= 0 ) stop 'error allocating dummy array b_displ'
+    allocate(b_veloc(1,1),stat=ier)
+    if( ier /= 0 ) stop 'error allocating dummy array b_veloc'
+    allocate(b_accel(1,1),stat=ier)
+    if( ier /= 0 ) stop 'error allocating dummy array b_accel'
+
+  endif
+
+  ! allocates adjoint arrays for acoustic simulations
+  if( ACOUSTIC_SIMULATION .and. SIMULATION_TYPE == 3 ) then
+
+    ! backward potentials
+    allocate(b_potential_acoustic(NGLOB_ADJOINT), &
+            b_potential_dot_acoustic(NGLOB_ADJOINT), &
+            b_potential_dot_dot_acoustic(NGLOB_ADJOINT),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array b_potential_acoustic etc.'
+
+    ! kernels
+    allocate(rho_ac_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            rhop_ac_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            kappa_ac_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            alpha_ac_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array rho_ac_kl etc.'
+
+    ! preconditioner
+    if ( APPROXIMATE_HESS_KL ) then
+      allocate(hess_ac_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT),stat=ier)
+      if( ier /= 0 ) stop 'error allocating array hess_ac_kl'
+    else
+      ! dummy allocation
+      allocate(hess_ac_kl(0,0,0,0),stat=ier)
+      if( ier /= 0 ) stop 'error allocating dummy array hess_ac_kl'
+    endif
+
+    ! MPI handling
+    allocate(b_request_send_scalar_ext_mesh(num_interfaces_ext_mesh), &
+      b_request_recv_scalar_ext_mesh(num_interfaces_ext_mesh), &
+      b_buffer_send_scalar_ext_mesh(max_nibool_interfaces_ext_mesh,num_interfaces_ext_mesh), &
+      b_buffer_recv_scalar_ext_mesh(max_nibool_interfaces_ext_mesh,num_interfaces_ext_mesh),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array b_request_send_scalar_ext_mesh'
+
+  else
+
+    ! backward potentials
+    allocate(b_potential_acoustic(1), &
+            b_potential_dot_acoustic(1), &
+            b_potential_dot_dot_acoustic(1),stat=ier)
+    if( ier /= 0 ) stop 'error allocating dummy array b_potential_acoustic etc.'
+
+    ! kernels
+    allocate(rho_ac_kl(1,1,1,1), &
+            rhop_ac_kl(1,1,1,1), &
+            kappa_ac_kl(1,1,1,1), &
+            alpha_ac_kl(1,1,1,1),stat=ier)
+    if( ier /= 0 ) stop 'error allocating dummy array rho_ac_kl etc.'
+
+    ! MPI handling
+    allocate(b_request_send_scalar_ext_mesh(1), &
+            b_request_recv_scalar_ext_mesh(1), &
+            b_buffer_send_scalar_ext_mesh(1,1), &
+            b_buffer_recv_scalar_ext_mesh(1,1),stat=ier)
+    if( ier /= 0 ) stop 'error allocating dummy array b_request_send_scalar_ext_mesh etc.'
+
+  endif
+
+  ! ADJOINT moho
+  ! moho boundary
+  if( ELASTIC_SIMULATION ) then
+    ! always needed to be allocated for routine arguments
+    allocate( is_moho_top(NSPEC_BOUN),is_moho_bot(NSPEC_BOUN),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array is_moho_top etc.'
+
+    if( SAVE_MOHO_MESH .and. SIMULATION_TYPE == 3 ) then
+
+      if (ADIOS_FOR_MESH) then
+        call read_moho_mesh_adjoint_adios()
+      else
+        ! boundary elements
+        !open(unit=27,file=prname(1:len_trim(prname))//'ibelm_moho.bin',status='unknown',form='unformatted')
+        open(unit=27,file=prname(1:len_trim(prname))//'ibelm_moho.bin',status='old',&
+              form='unformatted',iostat=ier)
+        if( ier /= 0 ) then
+          print*,'error: could not open ibelm_moho '
+          print*,'path: ',prname(1:len_trim(prname))//'ibelm_moho.bin'
+          call exit_mpi(myrank,'error opening ibelm_moho')
+        endif
+
+        read(27) NSPEC2D_MOHO
+
+        ! allocates arrays for moho mesh
+        allocate(ibelm_moho_bot(NSPEC2D_MOHO), &
+                ibelm_moho_top(NSPEC2D_MOHO), &
+                normal_moho_top(NDIM,NGLLSQUARE,NSPEC2D_MOHO), &
+                normal_moho_bot(NDIM,NGLLSQUARE,NSPEC2D_MOHO), &
+                ijk_moho_bot(3,NGLLSQUARE,NSPEC2D_MOHO), &
+                ijk_moho_top(3,NGLLSQUARE,NSPEC2D_MOHO),stat=ier)
+        if( ier /= 0 ) stop 'error allocating array ibelm_moho_bot etc.'
+
+        read(27) ibelm_moho_top
+        read(27) ibelm_moho_bot
+        read(27) ijk_moho_top
+        read(27) ijk_moho_bot
+
+        close(27)
+
+        ! normals
+        open(unit=27,file=prname(1:len_trim(prname))//'normal_moho.bin',status='old',&
+              form='unformatted',iostat=ier)
+        if( ier /= 0 ) then
+          print*,'error: could not open normal_moho '
+          print*,'path: ',prname(1:len_trim(prname))//'normal_moho.bin'
+          call exit_mpi(myrank,'error opening normal_moho')
+        endif
+
+        read(27) normal_moho_top
+        read(27) normal_moho_bot
+        close(27)
+
+        ! flags
+        open(unit=27,file=prname(1:len_trim(prname))//'is_moho.bin',status='old',&
+              form='unformatted',iostat=ier)
+        if( ier /= 0 ) then
+          print*,'error: could not open is_moho '
+          print*,'path: ',prname(1:len_trim(prname))//'is_moho.bin'
+          call exit_mpi(myrank,'error opening is_moho')
+        endif
+
+        read(27) is_moho_top
+        read(27) is_moho_bot
+
+        close(27)
+      endif
+
+      ! moho kernel
+      allocate( moho_kl(NGLLSQUARE,NSPEC2D_MOHO),stat=ier)
+      if( ier /= 0 ) stop 'error allocating array moho_kl'
+      moho_kl = 0._CUSTOM_REAL
+
+    else
+      NSPEC2D_MOHO = 1
+    endif
+
+    ! always needed to be allocated for routine arguments
+    allocate( dsdx_top(NDIM,NDIM,NGLLX,NGLLY,NGLLZ,NSPEC2D_MOHO), &
+             dsdx_bot(NDIM,NDIM,NGLLX,NGLLY,NGLLZ,NSPEC2D_MOHO), &
+             b_dsdx_top(NDIM,NDIM,NGLLX,NGLLY,NGLLZ,NSPEC2D_MOHO), &
+             b_dsdx_bot(NDIM,NDIM,NGLLX,NGLLY,NGLLZ,NSPEC2D_MOHO),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array dsdx_top etc.'
+  endif
+
+  ! allocates adjoint arrays for poroelastic simulations
+  if( POROELASTIC_SIMULATION .and. SIMULATION_TYPE == 3 ) then
+    ! backward displacement,velocity,acceleration for the solid (s) & fluid (w) phases
+    allocate(b_displs_poroelastic(NDIM,NGLOB_ADJOINT),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array b_displs_poroelastic'
+    allocate(b_velocs_poroelastic(NDIM,NGLOB_ADJOINT),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array b_velocs_poroelastic'
+    allocate(b_accels_poroelastic(NDIM,NGLOB_ADJOINT),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array b_accels_poroelastic'
+    allocate(b_displw_poroelastic(NDIM,NGLOB_ADJOINT),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array b_displw_poroelastic'
+    allocate(b_velocw_poroelastic(NDIM,NGLOB_ADJOINT),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array b_velocw_poroelastic'
+    allocate(b_accelw_poroelastic(NDIM,NGLOB_ADJOINT),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array b_accelw_poroelastic'
+
+    ! adjoint kernels
+
+    ! primary, isotropic kernels
+    allocate(rhot_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            rhof_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            sm_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            eta_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), stat=ier)
+    if( ier /= 0 ) stop 'error allocating array rhot_kl etc.'
+    allocate(mufr_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array mufr_kl'
+    allocate(B_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            C_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            M_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), stat=ier)
+    if( ier /= 0 ) stop 'error allocating array B_kl etc.'
+
+    ! density, isotropic kernels
+    allocate(rhob_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            rhofb_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            phi_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), stat=ier)
+    if( ier /= 0 ) stop 'error allocating array rhob_kl etc.'
+    allocate(mufrb_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array mufrb_kl'
+    allocate(Bb_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            Cb_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            Mb_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), stat=ier)
+    if( ier /= 0 ) stop 'error allocating array Bb_kl etc.'
+
+    ! wavespeed, isotropic kernels
+    allocate(rhobb_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            rhofbb_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            phib_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            ratio_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), stat=ier)
+    if( ier /= 0 ) stop 'error allocating array rhobb_kl etc.'
+    allocate(cs_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array cs_kl'
+    allocate(cpI_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            cpII_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), stat=ier)
+    if( ier /= 0 ) stop 'error allocating array cpI_kl etc.'
+
+    ! MPI handling
+    allocate(b_request_send_vector_ext_meshs(num_interfaces_ext_mesh), &
+      b_request_recv_vector_ext_meshs(num_interfaces_ext_mesh), &
+      b_buffer_send_vector_ext_meshs(NDIM,max_nibool_interfaces_ext_mesh,num_interfaces_ext_mesh), &
+      b_buffer_recv_vector_ext_meshs(NDIM,max_nibool_interfaces_ext_mesh,num_interfaces_ext_mesh),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array b_request_send_vector_ext_meshs etc.'
+
+    allocate(b_request_send_vector_ext_meshw(num_interfaces_ext_mesh), &
+      b_request_recv_vector_ext_meshw(num_interfaces_ext_mesh), &
+      b_buffer_send_vector_ext_meshw(NDIM,max_nibool_interfaces_ext_mesh,num_interfaces_ext_mesh), &
+      b_buffer_recv_vector_ext_meshw(NDIM,max_nibool_interfaces_ext_mesh,num_interfaces_ext_mesh),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array b_request_send_vector_ext_meshw etc.'
+
+    ! arrays needed for kernel computations
+    allocate(b_epsilonsdev_xx(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            b_epsilonsdev_yy(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            b_epsilonsdev_xy(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            b_epsilonsdev_xz(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            b_epsilonsdev_yz(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            b_epsilonwdev_xx(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            b_epsilonwdev_yy(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            b_epsilonwdev_xy(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            b_epsilonwdev_xz(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            b_epsilonwdev_yz(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array b_epsilonsdev_xx etc.'
+
+    allocate(b_epsilons_trace_over_3(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            b_epsilonw_trace_over_3(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array b_epsilons_trace_over_3 etc.'
+
+  else ! dummy arrays
+
+    ! backward displacement,velocity,acceleration for the solid (s) & fluid (w)
+    ! phases
+    allocate(b_displs_poroelastic(1,1),stat=ier)
+    if( ier /= 0 ) stop 'error allocating dummy array b_displs_poroelastic'
+    allocate(b_velocs_poroelastic(1,1),stat=ier)
+    if( ier /= 0 ) stop 'error allocating dummy array b_velocs_poroelastic'
+    allocate(b_accels_poroelastic(1,1),stat=ier)
+    if( ier /= 0 ) stop 'error allocating dummy array b_accels_poroelastic'
+    allocate(b_displw_poroelastic(1,1),stat=ier)
+    if( ier /= 0 ) stop 'error allocating dummy array b_displw_poroelastic'
+    allocate(b_velocw_poroelastic(1,1),stat=ier)
+    if( ier /= 0 ) stop 'error allocating dummy array b_velocw_poroelastic'
+    allocate(b_accelw_poroelastic(1,1),stat=ier)
+    if( ier /= 0 ) stop 'error allocating dummy array b_accelw_poroelastic'
+
+    ! adjoint kernels
+
+    ! primary, isotropic kernels
+    allocate(rhot_kl(1,1,1,1), &
+            rhof_kl(1,1,1,1), &
+            sm_kl(1,1,1,1), &
+            eta_kl(1,1,1,1), stat=ier)
+    if( ier /= 0 ) stop 'error allocating dummy array rhot_kl etc.'
+    allocate(mufr_kl(1,1,1,1),stat=ier)
+    if( ier /= 0 ) stop 'error allocating dummy array mufr_kl'
+    allocate(B_kl(1,1,1,1), &
+            C_kl(1,1,1,1), &
+            M_kl(1,1,1,1), stat=ier)
+    if( ier /= 0 ) stop 'error allocating dummy array B_kl etc.'
+
+    ! density, isotropic kernels
+    allocate(rhob_kl(1,1,1,1), &
+            rhofb_kl(1,1,1,1), &
+            phi_kl(1,1,1,1), stat=ier)
+    if( ier /= 0 ) stop 'error allocating dummy array rhob_kl etc.'
+    allocate(mufrb_kl(1,1,1,1),stat=ier)
+    if( ier /= 0 ) stop 'error allocating dummy array mufrb_kl'
+    allocate(Bb_kl(1,1,1,1), &
+            Cb_kl(1,1,1,1), &
+            Mb_kl(1,1,1,1), stat=ier)
+    if( ier /= 0 ) stop 'error allocating dummy array Bb_kl etc.'
+
+    ! wavespeed, isotropic kernels
+    allocate(rhobb_kl(1,1,1,1), &
+            rhofbb_kl(1,1,1,1), &
+            phib_kl(1,1,1,1), &
+            ratio_kl(1,1,1,1), stat=ier)
+    if( ier /= 0 ) stop 'error allocating dummy array rhobb_kl etc.'
+    allocate(cs_kl(1,1,1,1),stat=ier)
+    if( ier /= 0 ) stop 'error allocating dummy array cs_kl'
+    allocate(cpI_kl(1,1,1,1), &
+            cpII_kl(1,1,1,1), stat=ier)
+    if( ier /= 0 ) stop 'error allocating dummy array cpI_kl etc.'
+
+  endif
+
+  end subroutine read_mesh_databases_adjoint

Deleted: seismo/3D/SPECFEM3D/trunk/src/specfem3D/read_mesh_databases.f90
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/specfem3D/read_mesh_databases.f90	2013-09-17 22:36:21 UTC (rev 22797)
+++ seismo/3D/SPECFEM3D/trunk/src/specfem3D/read_mesh_databases.f90	2013-09-18 14:35:14 UTC (rev 22798)
@@ -1,1179 +0,0 @@
-!=====================================================================
-!
-!               S p e c f e m 3 D  V e r s i o n  2 . 1
-!               ---------------------------------------
-!
-!          Main authors: Dimitri Komatitsch and Jeroen Tromp
-!    Princeton University, USA and CNRS / INRIA / University of Pau
-! (c) Princeton University / California Institute of Technology and CNRS / INRIA / University of Pau
-!                             July 2012
-!
-! This 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 02110-1301 USA.
-!
-!=====================================================================
-!
-! United States and French Government Sponsorship Acknowledged.
-
-  subroutine read_mesh_databases()
-
-  use pml_par
-
-  use specfem_par
-  use specfem_par_elastic
-  use specfem_par_acoustic
-  use specfem_par_poroelastic
-
-  implicit none
-
-  real(kind=CUSTOM_REAL):: minl,maxl,min_all,max_all
-  integer :: ier,inum
-
-! start reading the databases
-
-! info about external mesh simulation
-  call create_name_database(prname,myrank,LOCAL_PATH)
-  open(unit=27,file=prname(1:len_trim(prname))//'external_mesh.bin',status='old',&
-      action='read',form='unformatted',iostat=ier)
-  if( ier /= 0 ) then
-    print*,'error: could not open database '
-    print*,'path: ',prname(1:len_trim(prname))//'external_mesh.bin'
-    call exit_mpi(myrank,'error opening database')
-  endif
-
-  read(27) NSPEC_AB
-  read(27) NGLOB_AB
-
-  read(27) ibool
-
-  read(27) xstore
-  read(27) ystore
-  read(27) zstore
-
-  read(27) xix
-  read(27) xiy
-  read(27) xiz
-  read(27) etax
-  read(27) etay
-  read(27) etaz
-  read(27) gammax
-  read(27) gammay
-  read(27) gammaz
-  read(27) jacobian
-
-  read(27) kappastore
-  read(27) mustore
-
-  read(27) ispec_is_acoustic
-  read(27) ispec_is_elastic
-  read(27) ispec_is_poroelastic
-
-  ! acoustic
-  ! number of acoustic elements in this partition
-  nspec_acoustic = count(ispec_is_acoustic(:))
-  ! all processes will have acoustic_simulation set if any flag is .true.
-  call any_all_l( ANY(ispec_is_acoustic), ACOUSTIC_SIMULATION )
-  if( ACOUSTIC_SIMULATION ) then
-    ! potentials
-    allocate(potential_acoustic(NGLOB_AB),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array potential_acoustic'
-    allocate(potential_dot_acoustic(NGLOB_AB),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array potential_dot_acoustic'
-    allocate(potential_dot_dot_acoustic(NGLOB_AB),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array potential_dot_dot_acoustic'
-    allocate(potential_dot_dot_acoustic_interface(NGLOB_AB),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array potential_dot_dot_acoustic_interface'
-    if( SIMULATION_TYPE /= 1 ) then
-      allocate(potential_acoustic_adj_coupling(NGLOB_AB),stat=ier)
-      if( ier /= 0 ) stop 'error allocating array potential_acoustic_adj_coupling'
-    endif
-    ! mass matrix, density
-    allocate(rmass_acoustic(NGLOB_AB),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array rmass_acoustic'
-    allocate(rmass_acoustic_interface(NGLOB_AB),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array rmass_acoustic_interface'
-    read(27) rmass_acoustic
-    read(27) rmass_acoustic_interface
-
-    ! initializes mass matrix contribution
-    allocate(rmassz_acoustic(NGLOB_AB),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array rmassz_acoustic'
-    rmassz_acoustic(:) = 0._CUSTOM_REAL
-  endif
-
-! this array is needed for acoustic simulations but also for elastic simulations with CPML,
-! thus we now allocate it and read it in all cases (whether the simulation is acoustic, elastic, or acoustic/elastic)
-  allocate(rhostore(NGLLX,NGLLY,NGLLZ,NSPEC_AB),stat=ier)
-  if( ier /= 0 ) stop 'error allocating array rhostore'
-  read(27) rhostore
-
-  ! elastic
-  ! number of elastic elements in this partition
-  nspec_elastic = count(ispec_is_elastic(:))
-
-  ! elastic simulation
-  call any_all_l( ANY(ispec_is_elastic), ELASTIC_SIMULATION )
-  if( ELASTIC_SIMULATION ) then
-    ! displacement,velocity,acceleration
-    allocate(displ(NDIM,NGLOB_AB),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array displ'
-    allocate(veloc(NDIM,NGLOB_AB),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array veloc'
-    allocate(accel(NDIM,NGLOB_AB),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array accel'
-    if( SIMULATION_TYPE /= 1 ) then
-      allocate(accel_adj_coupling(NDIM,NGLOB_AB),stat=ier)
-      if( ier /= 0 ) stop 'error allocating array accel_adj_coupling'
-    endif
-
-    ! allocates mass matrix
-    allocate(rmass(NGLOB_AB),stat=ier)
-
-    if(PML_CONDITIONS)then
-       if(ACOUSTIC_SIMULATION)then
-          allocate(rmass_elastic_interface(NGLOB_AB),stat=ier)
-          if( ier /= 0 ) stop 'error allocating array rmass_elastic_interface'
-          rmass_elastic_interface(:) = 0._CUSTOM_REAL
-          if(SIMULATION_TYPE == 3)then
-            allocate(accel_interface(NDIM,NGLOB_AB),stat=ier)
-            if( ier /= 0 ) stop 'error allocating array accel_interface'
-            accel_interface(:,:) = 0._CUSTOM_REAL
-          else
-            allocate(accel_interface(NDIM,1),stat=ier)
-            if( ier /= 0 ) stop 'error allocating array accel_interface'
-            accel_interface(:,:) = 0._CUSTOM_REAL
-          endif
-       else
-          allocate(rmass_elastic_interface(1),stat=ier)
-          allocate(accel_interface(NDIM,1),stat=ier)
-       endif
-    else
-      allocate(rmass_elastic_interface(1),stat=ier)
-      allocate(accel_interface(NDIM,1),stat=ier)
-    endif
-
-    if( ier /= 0 ) stop 'error allocating array rmass'
-    ! initializes mass matrix contributions
-    allocate(rmassx(NGLOB_AB), &
-             rmassy(NGLOB_AB), &
-             rmassz(NGLOB_AB), &
-             stat=ier)
-    if( ier /= 0 ) stop 'error allocating array rmassx,rmassy,rmassz'
-    rmassx(:) = 0._CUSTOM_REAL
-    rmassy(:) = 0._CUSTOM_REAL
-    rmassz(:) = 0._CUSTOM_REAL
-
-    allocate(rho_vp(NGLLX,NGLLY,NGLLZ,NSPEC_AB),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array rho_vp'
-    allocate(rho_vs(NGLLX,NGLLY,NGLLZ,NSPEC_AB),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array rho_vs'
-    allocate(c11store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
-            c12store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
-            c13store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
-            c14store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
-            c15store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
-            c16store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
-            c22store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
-            c23store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
-            c24store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
-            c25store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
-            c26store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
-            c33store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
-            c34store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
-            c35store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
-            c36store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
-            c44store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
-            c45store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
-            c46store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
-            c55store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
-            c56store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
-            c66store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array c11store etc.'
-
-    ! note: currently, they need to be defined, as they are used in the routine arguments
-    !          for compute_forces_viscoelastic_Deville()
-    allocate(R_xx(NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB,N_SLS), &
-            R_yy(NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB,N_SLS), &
-            R_xy(NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB,N_SLS), &
-            R_xz(NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB,N_SLS), &
-            R_yz(NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB,N_SLS),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array R_xx etc.'
-
-    ! needed for attenuation and/or kernel computations
-    allocate(epsilondev_xx(NGLLX,NGLLY,NGLLZ,NSPEC_STRAIN_ONLY), &
-            epsilondev_yy(NGLLX,NGLLY,NGLLZ,NSPEC_STRAIN_ONLY), &
-            epsilondev_xy(NGLLX,NGLLY,NGLLZ,NSPEC_STRAIN_ONLY), &
-            epsilondev_xz(NGLLX,NGLLY,NGLLZ,NSPEC_STRAIN_ONLY), &
-            epsilondev_yz(NGLLX,NGLLY,NGLLZ,NSPEC_STRAIN_ONLY),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array epsilondev_xx etc.'
-
-    allocate(R_trace(NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB_kappa,N_SLS),&
-             epsilondev_trace(NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB_kappa),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array R_trace etc.'
-
-    ! note: needed for argument of deville routine
-    allocate(epsilon_trace_over_3(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array epsilon_trace_over_3'
-
-    ! needed for attenuation
-    allocate(one_minus_sum_beta(NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB), &
-            factor_common(N_SLS,NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array one_minus_sum_beta etc.'
-
-    allocate(one_minus_sum_beta_kappa(NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB_kappa), &
-             factor_common_kappa(N_SLS,NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB_kappa),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array one_minus_sum_beta_kappa etc.'
-
-    ! reads mass matrices
-    read(27,iostat=ier) rmass
-    if( ier /= 0 ) stop 'error reading in array rmass'
-
-    if(PML_CONDITIONS)then !need to be optimized
-       if(ACOUSTIC_SIMULATION)then
-          read(27,iostat=ier) rmass_elastic_interface
-          if( ier /= 0 ) stop 'error reading in array rmass_elastic_interface'
-       endif
-    endif
-
-    if( APPROXIMATE_OCEAN_LOAD ) then
-      ! ocean mass matrix
-      allocate(rmass_ocean_load(NGLOB_AB),stat=ier)
-      if( ier /= 0 ) stop 'error allocating array rmass_ocean_load'
-      read(27) rmass_ocean_load
-    else
-      ! dummy allocation
-      allocate(rmass_ocean_load(1),stat=ier)
-      if( ier /= 0 ) stop 'error allocating dummy array rmass_ocean_load'
-    endif
-
-    !pll material parameters for stacey conditions
-    read(27,iostat=ier) rho_vp
-    if( ier /= 0 ) stop 'error reading in array rho_vp'
-    read(27,iostat=ier) rho_vs
-    if( ier /= 0 ) stop 'error reading in array rho_vs'
-
-!! DK DK rhostore is now allocated and read in all cases (see above)
-!   ! checks if rhostore is available for gravity
-!   if( GRAVITY ) then
-!
-!     if( .not. ACOUSTIC_SIMULATION ) then
-!       ! rho array needed for gravity
-!       allocate(rhostore(NGLLX,NGLLY,NGLLZ,NSPEC_AB),stat=ier)
-!       if( ier /= 0 ) stop 'error allocating array rhostore'
-!
-!       ! extract rho information from mu = rho * vs * vs and rho_vs = rho * vs
-!       rhostore = 0.0_CUSTOM_REAL
-!       where( mustore > TINYVAL )
-!         rhostore = (rho_vs*rho_vs) / mustore
-!       endwhere
-!
-!       ! note: the construct below leads to a segmentation fault (ifort v11.1). not sure why...
-!       !          (where statement - standard fortran 95)
-!       !where( mustore > TINYVAL )
-!       !  rhostore = (rho_vs*rho_vs) / mustore
-!       !elsewhere
-!       !  rhostore = 0.0_CUSTOM_REAL
-!       !endwhere
-!     endif
-!   endif
-  else
-    ! no elastic attenuation & anisotropy
-    ATTENUATION = .false.
-    ANISOTROPY = .false.
-  endif
-
-  ! poroelastic
-  call any_all_l( ANY(ispec_is_poroelastic), POROELASTIC_SIMULATION )
-  if( POROELASTIC_SIMULATION ) then
-
-    if( GPU_MODE ) call exit_mpi(myrank,'POROELASTICITY not supported by GPU mode yet...')
-
-    ! displacement,velocity,acceleration for the solid (s) & fluid (w) phases
-    allocate(displs_poroelastic(NDIM,NGLOB_AB),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array displs_poroelastic'
-    allocate(velocs_poroelastic(NDIM,NGLOB_AB),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array velocs_poroelastic'
-    allocate(accels_poroelastic(NDIM,NGLOB_AB),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array accels_poroelastic'
-    allocate(displw_poroelastic(NDIM,NGLOB_AB),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array displw_poroelastic'
-    allocate(velocw_poroelastic(NDIM,NGLOB_AB),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array velocw_poroelastic'
-    allocate(accelw_poroelastic(NDIM,NGLOB_AB),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array accelw_poroelastic'
-
-    allocate(rmass_solid_poroelastic(NGLOB_AB),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array rmass_solid_poroelastic'
-    allocate(rmass_fluid_poroelastic(NGLOB_AB),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array rmass_fluid_poroelastic'
-
-    allocate(rhoarraystore(2,NGLLX,NGLLY,NGLLZ,NSPEC_AB), &
-             kappaarraystore(3,NGLLX,NGLLY,NGLLZ,NSPEC_AB), &
-             etastore(NGLLX,NGLLY,NGLLZ,NSPEC_AB), &
-             tortstore(NGLLX,NGLLY,NGLLZ,NSPEC_AB), &
-             phistore(NGLLX,NGLLY,NGLLZ,NSPEC_AB), &
-             permstore(6,NGLLX,NGLLY,NGLLZ,NSPEC_AB), &
-             rho_vpI(NGLLX,NGLLY,NGLLZ,NSPEC_AB), &
-             rho_vpII(NGLLX,NGLLY,NGLLZ,NSPEC_AB), &
-             rho_vsI(NGLLX,NGLLY,NGLLZ,NSPEC_AB),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array poroelastic properties'
-
-    ! needed for kernel computations
-    allocate(epsilonsdev_xx(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
-            epsilonsdev_yy(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
-            epsilonsdev_xy(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
-            epsilonsdev_xz(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
-            epsilonsdev_yz(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
-            epsilonwdev_xx(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
-            epsilonwdev_yy(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
-            epsilonwdev_xy(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
-            epsilonwdev_xz(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
-            epsilonwdev_yz(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array epsilonsdev_xx etc.'
-
-    allocate(epsilons_trace_over_3(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
-            epsilonw_trace_over_3(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array epsilons_trace_over_3 etc.'
-
-
-    read(27) rmass_solid_poroelastic
-    read(27) rmass_fluid_poroelastic
-    read(27) rhoarraystore
-    read(27) kappaarraystore
-    read(27) etastore
-    read(27) tortstore
-    read(27) permstore
-    read(27) phistore
-    read(27) rho_vpI
-    read(27) rho_vpII
-    read(27) rho_vsI
-  endif
-
-  ! checks simulation types are valid
-  if( (.not. ACOUSTIC_SIMULATION ) .and. &
-     (.not. ELASTIC_SIMULATION ) .and. &
-     (.not. POROELASTIC_SIMULATION ) ) then
-     close(27)
-     call exit_mpi(myrank,'error no simulation type defined')
-  endif
-
-  ! C-PML absorbing boundary conditions
-  NSPEC_CPML = 0
-  if( PML_CONDITIONS ) then
-    read(27) NSPEC_CPML
-    read(27) CPML_width_x
-    read(27) CPML_width_y
-    read(27) CPML_width_z
-
-    allocate(is_CPML(NSPEC_AB),stat=ier)
-    if(ier /= 0) stop 'error allocating array is_CPML'
-
-! make sure there are no PMLs by default,
-! and then below if NSPEC_CPML > 0 we will need the real flags for this mesh from the disk
-    is_CPML(:) = .false.
-
-    if( NSPEC_CPML > 0 ) then
-      allocate(CPML_regions(NSPEC_CPML),stat=ier)
-      if(ier /= 0) stop 'error allocating array CPML_regions'
-      allocate(CPML_to_spec(NSPEC_CPML),stat=ier)
-      if(ier /= 0) stop 'error allocating array CPML_to_spec'
-      allocate(d_store_x(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
-      if(ier /= 0) stop 'error allocating array d_store_x'
-      allocate(d_store_y(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
-      if(ier /= 0) stop 'error allocating array d_store_y'
-      allocate(d_store_z(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
-      if(ier /= 0) stop 'error allocating array d_store_z'
-      allocate(K_store_x(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
-      if(ier /= 0) stop 'error allocating array K_store_x'
-      allocate(K_store_y(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
-      if(ier /= 0) stop 'error allocating array K_store_y'
-      allocate(K_store_z(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
-      if(ier /= 0) stop 'error allocating array K_store_z'
-      allocate(alpha_store(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
-      if(ier /= 0) stop 'error allocating array alpha_store'
-
-      read(27) CPML_regions
-      read(27) CPML_to_spec
-      read(27) is_CPML
-      read(27) d_store_x
-      read(27) d_store_y
-      read(27) d_store_z
-      read(27) k_store_x
-      read(27) k_store_y
-      read(27) k_store_z
-      read(27) alpha_store
-
-      if((SIMULATION_TYPE == 1 .and. SAVE_FORWARD) .or. SIMULATION_TYPE == 3) then
-        read(27) nglob_interface_PML_acoustic
-        read(27) nglob_interface_PML_elastic
-        if(nglob_interface_PML_acoustic > 0) then
-          allocate(points_interface_PML_acoustic(nglob_interface_PML_acoustic),stat=ier)
-          if(ier /= 0) stop 'error allocating array points_interface_PML_acoustic'
-          read(27) points_interface_PML_acoustic
-        endif
-        if(nglob_interface_PML_elastic > 0) then
-          allocate(points_interface_PML_elastic(nglob_interface_PML_elastic),stat=ier)
-          if(ier /= 0) stop 'error allocating array points_interface_PML_elastic'
-          read(27) points_interface_PML_elastic
-        endif
-      endif
-    endif
-  else
-    ! allocate with a dummy size of zero just to be able to use this array as argument in subroutine calls
-    allocate(is_CPML(0),stat=ier)
-  endif
-
-  ! absorbing boundary surface
-  read(27) num_abs_boundary_faces
-
-  ! checks
-  if( num_abs_boundary_faces < 0 ) then
-    print*,'read_mesh_databases: reading in negative num_abs_boundary_faces ',num_abs_boundary_faces,'...resetting to zero'
-    num_abs_boundary_faces = 0
-  endif
-  allocate(abs_boundary_ispec(num_abs_boundary_faces), &
-          abs_boundary_ijk(3,NGLLSQUARE,num_abs_boundary_faces), &
-          abs_boundary_jacobian2Dw(NGLLSQUARE,num_abs_boundary_faces), &
-          abs_boundary_normal(NDIM,NGLLSQUARE,num_abs_boundary_faces),stat=ier)
-  if( ier /= 0 ) stop 'error allocating array abs_boundary_ispec etc.'
-
-  if (OLD_TEST_TO_FIX_ONE_DAY) then
-     ! VM for new method
-!! DK DK for VM VM: these two arrays are undeclared, thus I comment them out for now otherwise the code does not compile
-!! VM VM : I already declared these two array in the specfem_par module
-     allocate(Veloc_dsm_boundary(3,Ntime_step_dsm,NGLLSQUARE,num_abs_boundary_faces))
-     allocate(Tract_dsm_boundary(3,Ntime_step_dsm,NGLLSQUARE,num_abs_boundary_faces))
-     open(unit=IIN_veloc_dsm,file=dsmname(1:len_trim(dsmname))//'vel.bin',status='old', &
-          action='read',form='unformatted',iostat=ier)
-     open(unit=IIN_tract_dsm,file=dsmname(1:len_trim(dsmname))//'tract.bin',status='old', &
-          action='read',form='unformatted',iostat=ier)
-  else
-     allocate(Veloc_dsm_boundary(1,1,1,1))
-     allocate(Tract_dsm_boundary(1,1,1,1))
-  endif
-
-  if(PML_CONDITIONS)then
-     if( num_abs_boundary_faces > 0 ) then
-       read(27) abs_boundary_ispec
-       read(27) abs_boundary_ijk
-       read(27) abs_boundary_jacobian2Dw
-       read(27) abs_boundary_normal
-     endif
-  else
-     if( num_abs_boundary_faces > 0 ) then
-       read(27) abs_boundary_ispec
-       read(27) abs_boundary_ijk
-       read(27) abs_boundary_jacobian2Dw
-       read(27) abs_boundary_normal
-       if( STACEY_ABSORBING_CONDITIONS ) then
-          ! store mass matrix contributions
-          if(ELASTIC_SIMULATION) then
-           read(27) rmassx
-           read(27) rmassy
-           read(27) rmassz
-          endif
-          if(ACOUSTIC_SIMULATION) then
-           read(27) rmassz_acoustic
-          endif
-       endif
-     endif
-  endif
-
-  read(27) nspec2D_xmin
-  read(27) nspec2D_xmax
-  read(27) nspec2D_ymin
-  read(27) nspec2D_ymax
-  read(27) NSPEC2D_BOTTOM
-  read(27) NSPEC2D_TOP
-
-  allocate(ibelm_xmin(nspec2D_xmin),ibelm_xmax(nspec2D_xmax), &
-       ibelm_ymin(nspec2D_ymin),ibelm_ymax(nspec2D_ymax), &
-       ibelm_bottom(NSPEC2D_BOTTOM),ibelm_top(NSPEC2D_TOP),stat=ier)
-  if(ier /= 0) stop 'error allocating arrays ibelm_xmin,ibelm_xmax etc.'
-  read(27) ibelm_xmin
-  read(27) ibelm_xmax
-  read(27) ibelm_ymin
-  read(27) ibelm_ymax
-  read(27) ibelm_bottom
-  read(27) ibelm_top
-
-  ! free surface
-  read(27) num_free_surface_faces
-  allocate(free_surface_ispec(num_free_surface_faces), &
-          free_surface_ijk(3,NGLLSQUARE,num_free_surface_faces), &
-          free_surface_jacobian2Dw(NGLLSQUARE,num_free_surface_faces), &
-          free_surface_normal(NDIM,NGLLSQUARE,num_free_surface_faces),stat=ier)
-  if(ier /= 0) stop 'error allocating arrays free_surface_ispec etc.'
-  if( num_free_surface_faces > 0 ) then
-    read(27) free_surface_ispec
-    read(27) free_surface_ijk
-    read(27) free_surface_jacobian2Dw
-    read(27) free_surface_normal
-  endif
-
-  ! acoustic-elastic coupling surface
-  read(27) num_coupling_ac_el_faces
-  allocate(coupling_ac_el_normal(NDIM,NGLLSQUARE,num_coupling_ac_el_faces), &
-          coupling_ac_el_jacobian2Dw(NGLLSQUARE,num_coupling_ac_el_faces), &
-          coupling_ac_el_ijk(3,NGLLSQUARE,num_coupling_ac_el_faces), &
-          coupling_ac_el_ispec(num_coupling_ac_el_faces),stat=ier)
-  if( ier /= 0 ) stop 'error allocating array coupling_ac_el_normal etc.'
-  if( num_coupling_ac_el_faces > 0 ) then
-    read(27) coupling_ac_el_ispec
-    read(27) coupling_ac_el_ijk
-    read(27) coupling_ac_el_jacobian2Dw
-    read(27) coupling_ac_el_normal
-  endif
-
-  ! acoustic-poroelastic coupling surface
-  read(27) num_coupling_ac_po_faces
-  allocate(coupling_ac_po_normal(NDIM,NGLLSQUARE,num_coupling_ac_po_faces), &
-          coupling_ac_po_jacobian2Dw(NGLLSQUARE,num_coupling_ac_po_faces), &
-          coupling_ac_po_ijk(3,NGLLSQUARE,num_coupling_ac_po_faces), &
-          coupling_ac_po_ispec(num_coupling_ac_po_faces),stat=ier)
-  if( ier /= 0 ) stop 'error allocating array coupling_ac_po_normal etc.'
-  if( num_coupling_ac_po_faces > 0 ) then
-    read(27) coupling_ac_po_ispec
-    read(27) coupling_ac_po_ijk
-    read(27) coupling_ac_po_jacobian2Dw
-    read(27) coupling_ac_po_normal
-  endif
-
-  ! elastic-poroelastic coupling surface
-  read(27) num_coupling_el_po_faces
-  allocate(coupling_el_po_normal(NDIM,NGLLSQUARE,num_coupling_el_po_faces), &
-          coupling_el_po_jacobian2Dw(NGLLSQUARE,num_coupling_el_po_faces), &
-          coupling_el_po_ijk(3,NGLLSQUARE,num_coupling_el_po_faces), &
-          coupling_po_el_ijk(3,NGLLSQUARE,num_coupling_el_po_faces), &
-          coupling_el_po_ispec(num_coupling_el_po_faces), &
-          coupling_po_el_ispec(num_coupling_el_po_faces),stat=ier)
-  if( ier /= 0 ) stop 'error allocating array coupling_el_po_normal etc.'
-  if( num_coupling_el_po_faces > 0 ) then
-    read(27) coupling_el_po_ispec
-    read(27) coupling_po_el_ispec
-    read(27) coupling_el_po_ijk
-    read(27) coupling_po_el_ijk
-    read(27) coupling_el_po_jacobian2Dw
-    read(27) coupling_el_po_normal
-  endif
-
-  ! MPI interfaces
-  read(27) num_interfaces_ext_mesh
-  allocate(my_neighbours_ext_mesh(num_interfaces_ext_mesh), &
-          nibool_interfaces_ext_mesh(num_interfaces_ext_mesh),stat=ier)
-  if( ier /= 0 ) stop 'error allocating array my_neighbours_ext_mesh etc.'
-  if( num_interfaces_ext_mesh > 0 ) then
-    read(27) max_nibool_interfaces_ext_mesh
-    allocate(ibool_interfaces_ext_mesh(max_nibool_interfaces_ext_mesh,num_interfaces_ext_mesh),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array ibool_interfaces_ext_mesh'
-    read(27) my_neighbours_ext_mesh
-    read(27) nibool_interfaces_ext_mesh
-    read(27) ibool_interfaces_ext_mesh
-  else
-    max_nibool_interfaces_ext_mesh = 0
-    allocate(ibool_interfaces_ext_mesh(0,0),stat=ier)
-  endif
-
-  if( ELASTIC_SIMULATION .and. ANISOTROPY ) then
-    read(27) c11store
-    read(27) c12store
-    read(27) c13store
-    read(27) c14store
-    read(27) c15store
-    read(27) c16store
-    read(27) c22store
-    read(27) c23store
-    read(27) c24store
-    read(27) c25store
-    read(27) c26store
-    read(27) c33store
-    read(27) c34store
-    read(27) c35store
-    read(27) c36store
-    read(27) c44store
-    read(27) c45store
-    read(27) c46store
-    read(27) c55store
-    read(27) c56store
-    read(27) c66store
-  endif
-
-  ! inner / outer elements
-  allocate(ispec_is_inner(NSPEC_AB),stat=ier)
-  if( ier /= 0 ) stop 'error allocating array ispec_is_inner'
-  read(27) ispec_is_inner
-
-  if( ACOUSTIC_SIMULATION ) then
-    read(27) nspec_inner_acoustic,nspec_outer_acoustic
-    read(27) num_phase_ispec_acoustic
-    if( num_phase_ispec_acoustic < 0 ) stop 'error acoustic simulation: num_phase_ispec_acoustic is < zero'
-    allocate( phase_ispec_inner_acoustic(num_phase_ispec_acoustic,2),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array phase_ispec_inner_acoustic'
-    if(num_phase_ispec_acoustic > 0 ) read(27) phase_ispec_inner_acoustic
-  endif
-
-  if( ELASTIC_SIMULATION ) then
-    read(27) nspec_inner_elastic,nspec_outer_elastic
-    read(27) num_phase_ispec_elastic
-    if( num_phase_ispec_elastic < 0 ) stop 'error elastic simulation: num_phase_ispec_elastic is < zero'
-    allocate( phase_ispec_inner_elastic(num_phase_ispec_elastic,2),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array phase_ispec_inner_elastic'
-    if(num_phase_ispec_elastic > 0 ) read(27) phase_ispec_inner_elastic
-  endif
-
-  if( POROELASTIC_SIMULATION ) then
-    read(27) nspec_inner_poroelastic,nspec_outer_poroelastic
-    read(27) num_phase_ispec_poroelastic
-    if( num_phase_ispec_poroelastic < 0 ) stop 'error poroelastic simulation: num_phase_ispec_poroelastic is < zero'
-    allocate( phase_ispec_inner_poroelastic(num_phase_ispec_poroelastic,2),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array phase_ispec_inner_poroelastic'
-    if(num_phase_ispec_poroelastic > 0 ) read(27) phase_ispec_inner_poroelastic
-  endif
-
-! mesh coloring for GPUs
-  if( USE_MESH_COLORING_GPU ) then
-    ! acoustic domain colors
-    if( ACOUSTIC_SIMULATION ) then
-      read(27) num_colors_outer_acoustic,num_colors_inner_acoustic
-
-      allocate(num_elem_colors_acoustic(num_colors_outer_acoustic + num_colors_inner_acoustic),stat=ier)
-      if( ier /= 0 ) stop 'error allocating num_elem_colors_acoustic array'
-
-      read(27) num_elem_colors_acoustic
-    endif
-    ! elastic domain colors
-    if( ELASTIC_SIMULATION ) then
-      read(27) num_colors_outer_elastic,num_colors_inner_elastic
-
-      allocate(num_elem_colors_elastic(num_colors_outer_elastic + num_colors_inner_elastic),stat=ier)
-      if( ier /= 0 ) stop 'error allocating num_elem_colors_elastic array'
-
-      read(27) num_elem_colors_elastic
-    endif
-  else
-    ! allocates dummy arrays
-    if( ACOUSTIC_SIMULATION ) then
-      num_colors_outer_acoustic = 0
-      num_colors_inner_acoustic = 0
-      allocate(num_elem_colors_acoustic(num_colors_outer_acoustic + num_colors_inner_acoustic),stat=ier)
-      if( ier /= 0 ) stop 'error allocating num_elem_colors_acoustic array'
-    endif
-    if( ELASTIC_SIMULATION ) then
-      num_colors_outer_elastic = 0
-      num_colors_inner_elastic = 0
-      allocate(num_elem_colors_elastic(num_colors_outer_elastic + num_colors_inner_elastic),stat=ier)
-      if( ier /= 0 ) stop 'error allocating num_elem_colors_elastic array'
-    endif
-  endif
-
-  close(27)
-
-  ! outputs total element numbers
-  call sum_all_i(count(ispec_is_acoustic(:)),inum)
-  if( myrank == 0 ) then
-    write(IMAIN,*) 'total acoustic elements    :',inum
-  endif
-  call sum_all_i(count(ispec_is_elastic(:)),inum)
-  if( myrank == 0 ) then
-    write(IMAIN,*) 'total elastic elements     :',inum
-  endif
-  call sum_all_i(count(ispec_is_poroelastic(:)),inum)
-  if( myrank == 0 ) then
-    write(IMAIN,*) 'total poroelastic elements :',inum
-    call flush_IMAIN()
-  endif
-
-  ! debug
-  !call sum_all_i(num_interfaces_ext_mesh,inum)
-  !if(myrank == 0) then
-  !  write(IMAIN,*) 'number of MPI partition interfaces: ',inum
-  !  write(IMAIN,*)
-  !endif
-
-  ! MPI communications
-  if( ACOUSTIC_SIMULATION ) then
-    allocate(buffer_send_scalar_ext_mesh(max_nibool_interfaces_ext_mesh,num_interfaces_ext_mesh), &
-             buffer_recv_scalar_ext_mesh(max_nibool_interfaces_ext_mesh,num_interfaces_ext_mesh), &
-             request_send_scalar_ext_mesh(num_interfaces_ext_mesh), &
-             request_recv_scalar_ext_mesh(num_interfaces_ext_mesh), &
-             stat=ier)
-    if( ier /= 0 ) stop 'error allocating array buffer_send_scalar_ext_mesh,.. for acoustic simulations'
-  endif
-  if( ELASTIC_SIMULATION ) then
-    allocate(buffer_send_vector_ext_mesh(NDIM,max_nibool_interfaces_ext_mesh,num_interfaces_ext_mesh), &
-             buffer_recv_vector_ext_mesh(NDIM,max_nibool_interfaces_ext_mesh,num_interfaces_ext_mesh), &
-             request_send_vector_ext_mesh(num_interfaces_ext_mesh), &
-             request_recv_vector_ext_mesh(num_interfaces_ext_mesh), &
-             stat=ier)
-    if( ier /= 0 ) stop 'error allocating array buffer_send_vector_ext_mesh,.. for elastic simulations'
-  endif
-  if( POROELASTIC_SIMULATION ) then
-    allocate(buffer_send_vector_ext_mesh_s(NDIM,max_nibool_interfaces_ext_mesh,num_interfaces_ext_mesh), &
-             buffer_recv_vector_ext_mesh_s(NDIM,max_nibool_interfaces_ext_mesh,num_interfaces_ext_mesh), &
-             buffer_send_vector_ext_mesh_w(NDIM,max_nibool_interfaces_ext_mesh,num_interfaces_ext_mesh), &
-             buffer_recv_vector_ext_mesh_w(NDIM,max_nibool_interfaces_ext_mesh,num_interfaces_ext_mesh), &
-             request_send_vector_ext_mesh_s(num_interfaces_ext_mesh), &
-             request_recv_vector_ext_mesh_s(num_interfaces_ext_mesh), &
-             request_send_vector_ext_mesh_w(num_interfaces_ext_mesh), &
-             request_recv_vector_ext_mesh_w(num_interfaces_ext_mesh), &
-             stat=ier)
-    if( ier /= 0 ) stop 'error allocating array buffer_send_vector_ext_mesh_s,.. for poroelastic simulations'
-  endif
-
-  ! gets model dimensions
-  minl = minval( xstore )
-  maxl = maxval( xstore )
-  call min_all_all_cr(minl,min_all)
-  call max_all_all_cr(maxl,max_all)
-  LONGITUDE_MIN = min_all
-  LONGITUDE_MAX = max_all
-
-  minl = minval( ystore )
-  maxl = maxval( ystore )
-  call min_all_all_cr(minl,min_all)
-  call max_all_all_cr(maxl,max_all)
-  LATITUDE_MIN = min_all
-  LATITUDE_MAX = max_all
-
-  ! checks courant criteria on mesh
-  if( ELASTIC_SIMULATION ) then
-    call check_mesh_resolution(myrank,NSPEC_AB,NGLOB_AB, &
-                              ibool,xstore,ystore,zstore, &
-                              kappastore,mustore,rho_vp,rho_vs, &
-                              DT,model_speed_max,min_resolved_period, &
-                              LOCAL_PATH,SAVE_MESH_FILES)
-
-  else if( POROELASTIC_SIMULATION ) then
-    allocate(rho_vp(NGLLX,NGLLY,NGLLZ,NSPEC_AB))
-    allocate(rho_vs(NGLLX,NGLLY,NGLLZ,NSPEC_AB))
-    rho_vp = 0.0_CUSTOM_REAL
-    rho_vs = 0.0_CUSTOM_REAL
-    call check_mesh_resolution_poro(myrank,NSPEC_AB,NGLOB_AB,ibool,xstore,ystore,zstore, &
-                                    DT,model_speed_max,min_resolved_period, &
-                                    phistore,tortstore,rhoarraystore,rho_vpI,rho_vpII,rho_vsI, &
-                                    LOCAL_PATH,SAVE_MESH_FILES)
-    deallocate(rho_vp,rho_vs)
-  else if( ACOUSTIC_SIMULATION ) then
-    allocate(rho_vp(NGLLX,NGLLY,NGLLZ,NSPEC_AB),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array rho_vp'
-    allocate(rho_vs(NGLLX,NGLLY,NGLLZ,NSPEC_AB),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array rho_vs'
-    rho_vp = sqrt( kappastore / rhostore ) * rhostore
-    rho_vs = 0.0_CUSTOM_REAL
-    call check_mesh_resolution(myrank,NSPEC_AB,NGLOB_AB, &
-                              ibool,xstore,ystore,zstore, &
-                              kappastore,mustore,rho_vp,rho_vs, &
-                              DT,model_speed_max,min_resolved_period, &
-                              LOCAL_PATH,SAVE_MESH_FILES)
-    deallocate(rho_vp,rho_vs)
-  endif
-
-  ! reads adjoint parameters
-  call read_mesh_databases_adjoint()
-
-  end subroutine read_mesh_databases
-
-
-!
-!-------------------------------------------------------------------------------------------------
-!
-
-  subroutine read_mesh_databases_adjoint()
-
-! reads in moho meshes
-
-  use specfem_par
-  use specfem_par_elastic
-  use specfem_par_acoustic
-  use specfem_par_poroelastic
-  implicit none
-
-  integer :: ier
-
-  ! allocates adjoint arrays for elastic simulations
-  if( ELASTIC_SIMULATION .and. SIMULATION_TYPE == 3 ) then
-    ! backward displacement,velocity,acceleration fields
-    allocate(b_displ(NDIM,NGLOB_ADJOINT),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array b_displ'
-    allocate(b_veloc(NDIM,NGLOB_ADJOINT),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array b_veloc'
-    allocate(b_accel(NDIM,NGLOB_ADJOINT),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array b_accel'
-
-    ! adjoint kernels
-
-    ! primary, isotropic kernels
-    ! density kernel
-    allocate(rho_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array rho_kl'
-
-    if (ANISOTROPIC_KL) then
-      ! anisotropic kernels
-      allocate(cijkl_kl(21,NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT),stat=ier)
-      if( ier /= 0 ) stop 'error allocating array cijkl_kl'
-      !dummy
-      allocate(mu_kl(1,1,1,1))
-      allocate(kappa_kl(1,1,1,1))
-    else
-      ! shear modulus kernel
-      allocate(mu_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT),stat=ier)
-      if( ier /= 0 ) stop 'error allocating array mu_kl'
-      ! compressional modulus kernel
-      allocate(kappa_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT),stat=ier)
-      if( ier /= 0 ) stop 'error allocating array kappa_kl'
-      !dummy
-      allocate(cijkl_kl(1,1,1,1,1))
-    endif
-
-    ! noise source strength kernel
-    if (NOISE_TOMOGRAPHY == 3) then
-      allocate(sigma_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT),stat=ier)
-      if( ier /= 0 ) stop 'error allocating array sigma_kl'
-    endif
-
-    ! preconditioner
-    if ( APPROXIMATE_HESS_KL ) then
-      allocate(hess_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT),stat=ier)
-      if( ier /= 0 ) stop 'error allocating array hess_kl'
-    else
-      ! dummy allocation
-      allocate(hess_kl(0,0,0,0),stat=ier)
-      if( ier /= 0 ) stop 'error allocating dummy array hess_kl'
-    endif
-
-    ! MPI handling
-    allocate(b_request_send_vector_ext_mesh(num_interfaces_ext_mesh), &
-             b_request_recv_vector_ext_mesh(num_interfaces_ext_mesh), &
-             b_buffer_send_vector_ext_mesh(NDIM,max_nibool_interfaces_ext_mesh,num_interfaces_ext_mesh), &
-             b_buffer_recv_vector_ext_mesh(NDIM,max_nibool_interfaces_ext_mesh,num_interfaces_ext_mesh),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array b_request_send_vector_ext_mesh etc.'
-
-    ! allocates attenuation solids
-    allocate(b_R_xx(NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB,N_SLS), &
-             b_R_yy(NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB,N_SLS), &
-             b_R_xy(NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB,N_SLS), &
-             b_R_xz(NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB,N_SLS), &
-             b_R_yz(NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB,N_SLS),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array b_R_xx etc.'
-
-    ! note: these arrays are needed for attenuation and/or kernel computations
-    allocate(b_epsilondev_xx(NGLLX,NGLLY,NGLLZ,NSPEC_STRAIN_ONLY), &
-            b_epsilondev_yy(NGLLX,NGLLY,NGLLZ,NSPEC_STRAIN_ONLY), &
-            b_epsilondev_xy(NGLLX,NGLLY,NGLLZ,NSPEC_STRAIN_ONLY), &
-            b_epsilondev_xz(NGLLX,NGLLY,NGLLZ,NSPEC_STRAIN_ONLY), &
-            b_epsilondev_yz(NGLLX,NGLLY,NGLLZ,NSPEC_STRAIN_ONLY),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array b_epsilon_dev_xx etc.'
-    ! needed for kernel computations
-    allocate(b_epsilon_trace_over_3(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array b_epsilon_trace_over_3'
-
-    ! allocates attenuation solids for considering kappa
-    allocate(b_R_trace(NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB_kappa,N_SLS),&
-             b_epsilondev_trace(NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB_kappa),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array b_R_trace etc.'
-
-  else
-    ! modification: Camille Mazoyer
-    ! dummy allocation
-    allocate(b_displ(1,1),stat=ier)
-    if( ier /= 0 ) stop 'error allocating dummy array b_displ'
-    allocate(b_veloc(1,1),stat=ier)
-    if( ier /= 0 ) stop 'error allocating dummy array b_veloc'
-    allocate(b_accel(1,1),stat=ier)
-    if( ier /= 0 ) stop 'error allocating dummy array b_accel'
-
-  endif
-
-  ! allocates adjoint arrays for acoustic simulations
-  if( ACOUSTIC_SIMULATION .and. SIMULATION_TYPE == 3 ) then
-
-    ! backward potentials
-    allocate(b_potential_acoustic(NGLOB_ADJOINT), &
-            b_potential_dot_acoustic(NGLOB_ADJOINT), &
-            b_potential_dot_dot_acoustic(NGLOB_ADJOINT),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array b_potential_acoustic etc.'
-
-    ! kernels
-    allocate(rho_ac_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
-            rhop_ac_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
-            kappa_ac_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
-            alpha_ac_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array rho_ac_kl etc.'
-
-    ! preconditioner
-    if ( APPROXIMATE_HESS_KL ) then
-      allocate(hess_ac_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT),stat=ier)
-      if( ier /= 0 ) stop 'error allocating array hess_ac_kl'
-    else
-      ! dummy allocation
-      allocate(hess_ac_kl(0,0,0,0),stat=ier)
-      if( ier /= 0 ) stop 'error allocating dummy array hess_ac_kl'
-    endif
-
-    ! MPI handling
-    allocate(b_request_send_scalar_ext_mesh(num_interfaces_ext_mesh), &
-      b_request_recv_scalar_ext_mesh(num_interfaces_ext_mesh), &
-      b_buffer_send_scalar_ext_mesh(max_nibool_interfaces_ext_mesh,num_interfaces_ext_mesh), &
-      b_buffer_recv_scalar_ext_mesh(max_nibool_interfaces_ext_mesh,num_interfaces_ext_mesh),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array b_request_send_scalar_ext_mesh'
-
-  else
-
-    ! backward potentials
-    allocate(b_potential_acoustic(1), &
-            b_potential_dot_acoustic(1), &
-            b_potential_dot_dot_acoustic(1),stat=ier)
-    if( ier /= 0 ) stop 'error allocating dummy array b_potential_acoustic etc.'
-
-    ! kernels
-    allocate(rho_ac_kl(1,1,1,1), &
-            rhop_ac_kl(1,1,1,1), &
-            kappa_ac_kl(1,1,1,1), &
-            alpha_ac_kl(1,1,1,1),stat=ier)
-    if( ier /= 0 ) stop 'error allocating dummy array rho_ac_kl etc.'
-
-    ! MPI handling
-    allocate(b_request_send_scalar_ext_mesh(1), &
-            b_request_recv_scalar_ext_mesh(1), &
-            b_buffer_send_scalar_ext_mesh(1,1), &
-            b_buffer_recv_scalar_ext_mesh(1,1),stat=ier)
-    if( ier /= 0 ) stop 'error allocating dummy array b_request_send_scalar_ext_mesh etc.'
-
-  endif
-
-  ! ADJOINT moho
-  ! moho boundary
-  if( ELASTIC_SIMULATION ) then
-    ! always needed to be allocated for routine arguments
-    allocate( is_moho_top(NSPEC_BOUN),is_moho_bot(NSPEC_BOUN),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array is_moho_top etc.'
-
-    if( SAVE_MOHO_MESH .and. SIMULATION_TYPE == 3 ) then
-
-      ! boundary elements
-      !open(unit=27,file=prname(1:len_trim(prname))//'ibelm_moho.bin',status='unknown',form='unformatted')
-      open(unit=27,file=prname(1:len_trim(prname))//'ibelm_moho.bin',status='old',&
-            form='unformatted',iostat=ier)
-      if( ier /= 0 ) then
-        print*,'error: could not open ibelm_moho '
-        print*,'path: ',prname(1:len_trim(prname))//'ibelm_moho.bin'
-        call exit_mpi(myrank,'error opening ibelm_moho')
-      endif
-
-      read(27) NSPEC2D_MOHO
-
-      ! allocates arrays for moho mesh
-      allocate(ibelm_moho_bot(NSPEC2D_MOHO), &
-              ibelm_moho_top(NSPEC2D_MOHO), &
-              normal_moho_top(NDIM,NGLLSQUARE,NSPEC2D_MOHO), &
-              normal_moho_bot(NDIM,NGLLSQUARE,NSPEC2D_MOHO), &
-              ijk_moho_bot(3,NGLLSQUARE,NSPEC2D_MOHO), &
-              ijk_moho_top(3,NGLLSQUARE,NSPEC2D_MOHO),stat=ier)
-      if( ier /= 0 ) stop 'error allocating array ibelm_moho_bot etc.'
-
-      read(27) ibelm_moho_top
-      read(27) ibelm_moho_bot
-      read(27) ijk_moho_top
-      read(27) ijk_moho_bot
-
-      close(27)
-
-      ! normals
-      open(unit=27,file=prname(1:len_trim(prname))//'normal_moho.bin',status='old',&
-            form='unformatted',iostat=ier)
-      if( ier /= 0 ) then
-        print*,'error: could not open normal_moho '
-        print*,'path: ',prname(1:len_trim(prname))//'normal_moho.bin'
-        call exit_mpi(myrank,'error opening normal_moho')
-      endif
-
-      read(27) normal_moho_top
-      read(27) normal_moho_bot
-      close(27)
-
-      ! flags
-      open(unit=27,file=prname(1:len_trim(prname))//'is_moho.bin',status='old',&
-            form='unformatted',iostat=ier)
-      if( ier /= 0 ) then
-        print*,'error: could not open is_moho '
-        print*,'path: ',prname(1:len_trim(prname))//'is_moho.bin'
-        call exit_mpi(myrank,'error opening is_moho')
-      endif
-
-      read(27) is_moho_top
-      read(27) is_moho_bot
-
-      close(27)
-
-      ! moho kernel
-      allocate( moho_kl(NGLLSQUARE,NSPEC2D_MOHO),stat=ier)
-      if( ier /= 0 ) stop 'error allocating array moho_kl'
-      moho_kl = 0._CUSTOM_REAL
-
-    else
-      NSPEC2D_MOHO = 1
-    endif
-
-    ! always needed to be allocated for routine arguments
-    allocate( dsdx_top(NDIM,NDIM,NGLLX,NGLLY,NGLLZ,NSPEC2D_MOHO), &
-             dsdx_bot(NDIM,NDIM,NGLLX,NGLLY,NGLLZ,NSPEC2D_MOHO), &
-             b_dsdx_top(NDIM,NDIM,NGLLX,NGLLY,NGLLZ,NSPEC2D_MOHO), &
-             b_dsdx_bot(NDIM,NDIM,NGLLX,NGLLY,NGLLZ,NSPEC2D_MOHO),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array dsdx_top etc.'
-  endif
-
-  ! allocates adjoint arrays for poroelastic simulations
-  if( POROELASTIC_SIMULATION .and. SIMULATION_TYPE == 3 ) then
-    ! backward displacement,velocity,acceleration for the solid (s) & fluid (w) phases
-    allocate(b_displs_poroelastic(NDIM,NGLOB_ADJOINT),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array b_displs_poroelastic'
-    allocate(b_velocs_poroelastic(NDIM,NGLOB_ADJOINT),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array b_velocs_poroelastic'
-    allocate(b_accels_poroelastic(NDIM,NGLOB_ADJOINT),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array b_accels_poroelastic'
-    allocate(b_displw_poroelastic(NDIM,NGLOB_ADJOINT),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array b_displw_poroelastic'
-    allocate(b_velocw_poroelastic(NDIM,NGLOB_ADJOINT),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array b_velocw_poroelastic'
-    allocate(b_accelw_poroelastic(NDIM,NGLOB_ADJOINT),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array b_accelw_poroelastic'
-
-    ! adjoint kernels
-
-    ! primary, isotropic kernels
-    allocate(rhot_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
-            rhof_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
-            sm_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
-            eta_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), stat=ier)
-    if( ier /= 0 ) stop 'error allocating array rhot_kl etc.'
-    allocate(mufr_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array mufr_kl'
-    allocate(B_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
-            C_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
-            M_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), stat=ier)
-    if( ier /= 0 ) stop 'error allocating array B_kl etc.'
-
-    ! density, isotropic kernels
-    allocate(rhob_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
-            rhofb_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
-            phi_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), stat=ier)
-    if( ier /= 0 ) stop 'error allocating array rhob_kl etc.'
-    allocate(mufrb_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array mufrb_kl'
-    allocate(Bb_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
-            Cb_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
-            Mb_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), stat=ier)
-    if( ier /= 0 ) stop 'error allocating array Bb_kl etc.'
-
-    ! wavespeed, isotropic kernels
-    allocate(rhobb_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
-            rhofbb_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
-            phib_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
-            ratio_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), stat=ier)
-    if( ier /= 0 ) stop 'error allocating array rhobb_kl etc.'
-    allocate(cs_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array cs_kl'
-    allocate(cpI_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
-            cpII_kl(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), stat=ier)
-    if( ier /= 0 ) stop 'error allocating array cpI_kl etc.'
-
-    ! MPI handling
-    allocate(b_request_send_vector_ext_meshs(num_interfaces_ext_mesh), &
-      b_request_recv_vector_ext_meshs(num_interfaces_ext_mesh), &
-      b_buffer_send_vector_ext_meshs(NDIM,max_nibool_interfaces_ext_mesh,num_interfaces_ext_mesh), &
-      b_buffer_recv_vector_ext_meshs(NDIM,max_nibool_interfaces_ext_mesh,num_interfaces_ext_mesh),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array b_request_send_vector_ext_meshs etc.'
-
-    allocate(b_request_send_vector_ext_meshw(num_interfaces_ext_mesh), &
-      b_request_recv_vector_ext_meshw(num_interfaces_ext_mesh), &
-      b_buffer_send_vector_ext_meshw(NDIM,max_nibool_interfaces_ext_mesh,num_interfaces_ext_mesh), &
-      b_buffer_recv_vector_ext_meshw(NDIM,max_nibool_interfaces_ext_mesh,num_interfaces_ext_mesh),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array b_request_send_vector_ext_meshw etc.'
-
-    ! arrays needed for kernel computations
-    allocate(b_epsilonsdev_xx(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
-            b_epsilonsdev_yy(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
-            b_epsilonsdev_xy(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
-            b_epsilonsdev_xz(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
-            b_epsilonsdev_yz(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
-            b_epsilonwdev_xx(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
-            b_epsilonwdev_yy(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
-            b_epsilonwdev_xy(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
-            b_epsilonwdev_xz(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
-            b_epsilonwdev_yz(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array b_epsilonsdev_xx etc.'
-
-    allocate(b_epsilons_trace_over_3(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
-            b_epsilonw_trace_over_3(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array b_epsilons_trace_over_3 etc.'
-
-  else ! dummy arrays
-
-    ! backward displacement,velocity,acceleration for the solid (s) & fluid (w)
-    ! phases
-    allocate(b_displs_poroelastic(1,1),stat=ier)
-    if( ier /= 0 ) stop 'error allocating dummy array b_displs_poroelastic'
-    allocate(b_velocs_poroelastic(1,1),stat=ier)
-    if( ier /= 0 ) stop 'error allocating dummy array b_velocs_poroelastic'
-    allocate(b_accels_poroelastic(1,1),stat=ier)
-    if( ier /= 0 ) stop 'error allocating dummy array b_accels_poroelastic'
-    allocate(b_displw_poroelastic(1,1),stat=ier)
-    if( ier /= 0 ) stop 'error allocating dummy array b_displw_poroelastic'
-    allocate(b_velocw_poroelastic(1,1),stat=ier)
-    if( ier /= 0 ) stop 'error allocating dummy array b_velocw_poroelastic'
-    allocate(b_accelw_poroelastic(1,1),stat=ier)
-    if( ier /= 0 ) stop 'error allocating dummy array b_accelw_poroelastic'
-
-    ! adjoint kernels
-
-    ! primary, isotropic kernels
-    allocate(rhot_kl(1,1,1,1), &
-            rhof_kl(1,1,1,1), &
-            sm_kl(1,1,1,1), &
-            eta_kl(1,1,1,1), stat=ier)
-    if( ier /= 0 ) stop 'error allocating dummy array rhot_kl etc.'
-    allocate(mufr_kl(1,1,1,1),stat=ier)
-    if( ier /= 0 ) stop 'error allocating dummy array mufr_kl'
-    allocate(B_kl(1,1,1,1), &
-            C_kl(1,1,1,1), &
-            M_kl(1,1,1,1), stat=ier)
-    if( ier /= 0 ) stop 'error allocating dummy array B_kl etc.'
-
-    ! density, isotropic kernels
-    allocate(rhob_kl(1,1,1,1), &
-            rhofb_kl(1,1,1,1), &
-            phi_kl(1,1,1,1), stat=ier)
-    if( ier /= 0 ) stop 'error allocating dummy array rhob_kl etc.'
-    allocate(mufrb_kl(1,1,1,1),stat=ier)
-    if( ier /= 0 ) stop 'error allocating dummy array mufrb_kl'
-    allocate(Bb_kl(1,1,1,1), &
-            Cb_kl(1,1,1,1), &
-            Mb_kl(1,1,1,1), stat=ier)
-    if( ier /= 0 ) stop 'error allocating dummy array Bb_kl etc.'
-
-    ! wavespeed, isotropic kernels
-    allocate(rhobb_kl(1,1,1,1), &
-            rhofbb_kl(1,1,1,1), &
-            phib_kl(1,1,1,1), &
-            ratio_kl(1,1,1,1), stat=ier)
-    if( ier /= 0 ) stop 'error allocating dummy array rhobb_kl etc.'
-    allocate(cs_kl(1,1,1,1),stat=ier)
-    if( ier /= 0 ) stop 'error allocating dummy array cs_kl'
-    allocate(cpI_kl(1,1,1,1), &
-            cpII_kl(1,1,1,1), stat=ier)
-    if( ier /= 0 ) stop 'error allocating dummy array cpI_kl etc.'
-
-  endif
-
-  end subroutine read_mesh_databases_adjoint

Added: seismo/3D/SPECFEM3D/trunk/src/specfem3D/read_mesh_databases_adios.F90
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/specfem3D/read_mesh_databases_adios.F90	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/src/specfem3D/read_mesh_databases_adios.F90	2013-09-18 14:35:14 UTC (rev 22798)
@@ -0,0 +1,1914 @@
+!=====================================================================
+!
+!               S p e c f e m 3 D  V e r s i o n  2 . 1
+!               ---------------------------------------
+!
+!          Main authors: Dimitri Komatitsch and Jeroen Tromp
+!    Princeton University, USA and CNRS / INRIA / University of Pau
+! (c) Princeton University / California Institute of Technology and CNRS / INRIA / University of Pau
+!                             July 2012
+!
+! This 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 02110-1301 USA.
+!
+!=====================================================================
+!
+! United States and French Government Sponsorship Acknowledged.
+
+!==============================================================================
+subroutine read_mesh_for_init(nspec, nglob)
+
+  use mpi
+  use adios_read_mod
+  use specfem_par, only : myrank, LOCAL_PATH
+
+  implicit none
+  ! Paramters
+  integer, intent(inout) :: nspec, nglob
+  ! Local variables
+  character(len=256) :: database_name
+  integer(kind=8) :: handle, sel
+  integer         :: ier
+
+  !-------------------------------------.
+  ! Open ADIOS Database file, read mode |
+  !-------------------------------------'
+  database_name = adjustl(LOCAL_PATH)
+  database_name = database_name(1:len_trim(database_name)) // "/external_mesh.bp"
+
+  call adios_read_init_method (ADIOS_READ_METHOD_BP, MPI_COMM_WORLD, &
+                               "verbose=1", ier)
+  call adios_read_open_file (handle, database_name, 0, MPI_COMM_WORLD, ier)
+
+  !------------------------------------.
+  ! Read variables from the adios file |
+  !------------------------------------'
+  call adios_selection_writeblock(sel, myrank)
+  call adios_schedule_read(handle, sel, "/nspec", 0, 1, nspec, ier)
+  call adios_schedule_read(handle, sel, "/nglob", 0, 1, nglob, ier)
+
+  !--------------------------------------------.
+  ! Perform the reads and close the adios file |
+  !--------------------------------------------'
+  call adios_perform_reads(handle, ier)
+  call adios_read_close(handle,ier)
+  call adios_read_finalize_method(ADIOS_READ_METHOD_BP, ier)
+
+end subroutine read_mesh_for_init
+
+!==============================================================================
+subroutine read_mesh_databases_adios()
+
+  use mpi
+  use adios_read_mod
+
+  use pml_par
+
+  use specfem_par
+  use specfem_par_elastic
+  use specfem_par_acoustic
+  use specfem_par_poroelastic
+
+  implicit none
+
+  real(kind=CUSTOM_REAL):: minl,maxl,min_all,max_all
+  integer :: ier,inum
+
+  character(len=256) :: database_name
+  integer(kind=8) :: handle
+
+  integer(kind=8), dimension(256),target :: selections
+  integer :: sel_num
+  integer(kind=8), pointer :: sel => null()
+  integer(kind=8), dimension(1) :: start, count_ad
+
+  integer :: local_dim_ibool, local_dim_x_global, local_dim_y_global,          & 
+             local_dim_z_global, local_dim_xixstore, local_dim_xiystore,       & 
+             local_dim_xizstore, local_dim_etaxstore, local_dim_etaystore,     & 
+             local_dim_etazstore, local_dim_gammaxstore,                       & 
+             local_dim_gammaystore, local_dim_gammazstore,                     & 
+             local_dim_jacobianstore, local_dim_kappastore,                    & 
+             local_dim_mustore, local_dim_rhostore,                            & 
+             local_dim_ispec_is_acoustic, local_dim_ispec_is_elastic,          & 
+             local_dim_ispec_is_poroelastic, local_dim_rmass,                  & 
+             local_dim_rmass_ocean_load, local_dim_rmass_acoustic,             & 
+             local_dim_rmass_acoustic_interface, local_dim_rmass_elastic,      & 
+             local_dim_rmass_elastic_interface, local_dim_rho_vp,              & 
+             local_dim_rho_vs, local_dim_abs_boundary_ispec,                   & 
+             local_dim_abs_boundary_ijk, local_dim_abs_boundary_jacobian2Dw,   & 
+             local_dim_abs_boundary_normal, local_dim_ibelm_xmin,              & 
+             local_dim_ibelm_ymin, local_dim_ibelm_bottom,                     & 
+             local_dim_ibelm_top, local_dim_free_surface_ispec,                & 
+             local_dim_free_surface_ijk, local_dim_free_surface_jacobian2Dw,   & 
+             local_dim_free_surface_normal, local_dim_coupling_ac_el_ispec,    & 
+             local_dim_coupling_ac_el_ijk,                                     &
+             local_dim_coupling_ac_el_jacobian2Dw,                             & 
+             local_dim_coupling_ac_el_normal, local_dim_my_neighbours_ext_mesh,& 
+             local_dim_nibool_interfaces_ext_mesh,                             & 
+             local_dim_ibool_interfaces_ext_mesh,                              & 
+             local_dim_ispec_is_inner, local_dim_phase_ispec_inner_acoustic,   & 
+             local_dim_phase_ispec_inner_elastic, local_dim_ibelm_xmax,        & 
+             local_dim_ibelm_ymax, local_dim_rmass_solid_poroelastic,          &
+             local_dim_rmass_fluid_poroelastic, local_dim_rhoarraystore,       &
+             local_dim_kappaarraystore, local_dim_permstore,                   &
+             local_dim_etastore, local_dim_tortstore, local_dim_phistore,      &
+             local_dim_rho_vpI, local_dim_rho_vpII, local_dim_rho_vsI,         &
+             local_dim_CPML_regions, local_dim_CPML_to_spec, local_dim_is_CPML,&
+             local_dim_d_store_x, local_dim_d_store_y, local_dim_d_store_z,    &
+             local_dim_k_store_x, local_dim_k_store_y, local_dim_k_store_z,    &
+             local_dim_alpha_store, local_dim_points_interface_PML_acoustic,   &
+             local_dim_points_interface_PML_elastic,                           &
+             local_dim_rmassx, local_dim_rmassy, local_dim_rmassz,             &
+             local_dim_rmassz_acoustic, local_dim_coupling_el_po_ispec,        &
+             local_dim_coupling_po_el_ispec, local_dim_coupling_el_po_ijk,     &
+             local_dim_coupling_po_el_ijk,                                     &
+             local_dim_coupling_el_po_jacobian2Dw,                             &
+             local_dim_coupling_el_po_normal, local_dim_c11store,              &
+             local_dim_phase_ispec_inner_poroelastic,                          &
+             local_dim_num_elem_colors_acoustic,                               &
+             local_dim_num_elem_colors_elastic, local_dim_coupling_ac_po_ispec,&
+             local_dim_coupling_ac_po_ijk,                                     &
+             local_dim_coupling_ac_po_jacobian2Dw,                             &
+             local_dim_coupling_ac_po_normal
+
+  !-------------------------------------.
+  ! Open ADIOS Database file, read mode |
+  !-------------------------------------'
+  sel_num = 0             
+
+  database_name = adjustl(LOCAL_PATH)
+  database_name = database_name(1:len_trim(database_name)) // "/external_mesh.bp"
+
+  call adios_read_init_method (ADIOS_READ_METHOD_BP, MPI_COMM_WORLD, &
+                               "verbose=1", ier)
+  call adios_read_open_file (handle, database_name, 0, MPI_COMM_WORLD, ier)
+
+  !------------------------------------------------------------------.
+  ! Get scalar values. Might be differents for different processors. |
+  ! Hence the selection writeblock.                                  |
+  ! ONLY NSPEC_AB and NGLOB_AB
+  !------------------------------------------------------------------'
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_writeblock(sel, myrank)
+  call adios_schedule_read(handle, sel, "/nspec", 0, 1, NSPEC_AB, ier)
+  call adios_schedule_read(handle, sel, "/nglob", 0, 1, NGLOB_AB, ier)
+  call adios_perform_reads(handle, ier)
+
+  !----------------------------------------------.
+  ! Fetch values to compute the simulation type. |
+  !----------------------------------------------'
+  sel_num = 0             
+  call adios_get_scalar(handle, "ispec_is_acoustic/local_dim",&
+                        local_dim_ispec_is_acoustic,ier)
+  call adios_get_scalar(handle, "ispec_is_elastic/local_dim",&
+                        local_dim_ispec_is_elastic,ier)
+  call adios_get_scalar(handle, "ispec_is_poroelastic/local_dim",&
+                        local_dim_ispec_is_poroelastic,ier)
+
+  start(1) = local_dim_ispec_is_acoustic * myrank
+  count_ad(1) = NSPEC_AB 
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count_ad)
+  call adios_schedule_read(handle, sel, "ispec_is_acoustic/array", 0, 1, &
+                           ispec_is_acoustic, ier)
+  call adios_schedule_read(handle, sel, "ispec_is_elastic/array", 0, 1, &
+                           ispec_is_elastic, ier)
+  call adios_schedule_read(handle, sel, "ispec_is_poroelastic/array", 0, 1, &
+                           ispec_is_poroelastic, ier)
+  ! Perform the read, so we can use the values.
+  call adios_perform_reads(handle, ier)
+  ! number of acoustic elements in this partition
+  nspec_acoustic = count(ispec_is_acoustic(:))
+  ! all processes will have acoustic_simulation set if any flag is .true.
+  call any_all_l( ANY(ispec_is_acoustic), ACOUSTIC_SIMULATION )
+  ! number of elastic elements in this partition
+  nspec_elastic = count(ispec_is_elastic(:))
+  ! elastic simulation
+  call any_all_l( ANY(ispec_is_elastic), ELASTIC_SIMULATION )
+  ! poroelastic
+  call any_all_l( ANY(ispec_is_poroelastic), POROELASTIC_SIMULATION )
+
+  ! checks simulation types are valid
+  if( (.not. ACOUSTIC_SIMULATION ) .and. &
+      (.not. ELASTIC_SIMULATION ) .and. &
+      (.not. POROELASTIC_SIMULATION ) ) then
+     call exit_mpi(myrank,'error no simulation type defined')
+  endif
+
+  ! outputs total element numbers
+  call sum_all_i(count(ispec_is_acoustic(:)),inum)
+  if( myrank == 0 ) then
+    write(IMAIN,*) 'total acoustic elements    :',inum
+  endif
+  call sum_all_i(count(ispec_is_elastic(:)),inum)
+  if( myrank == 0 ) then
+    write(IMAIN,*) 'total elastic elements     :',inum
+  endif
+  call sum_all_i(count(ispec_is_poroelastic(:)),inum)
+  if( myrank == 0 ) then
+    write(IMAIN,*) 'total poroelastic elements :',inum
+    call flush_IMAIN()
+  endif
+
+  !------------------------------------------------------------------.
+  ! Get scalar values. Might be differents for different processors. |
+  ! Hence the selection writeblock.                                  |
+  !------------------------------------------------------------------'
+  sel_num = 1             
+  sel => selections(sel_num)
+  call adios_selection_writeblock(sel, myrank)
+
+  NSPEC_CPML = 0
+  if( PML_CONDITIONS ) then
+    call adios_schedule_read(handle, sel, "/nspec_cpml", 0, 1, nspec_cpml, ier)
+    call adios_schedule_read(handle, sel, "/CPML_width_x", 0, 1, &
+                             CPML_width_x, ier)
+    call adios_schedule_read(handle, sel, "/CPML_width_y", 0, 1, &
+                             CPML_width_y, ier)
+    call adios_schedule_read(handle, sel, "/CPML_width_x", 0, 1, &
+                             CPML_width_z, ier)
+    if( nspec_cpml > 0 ) then
+      if((SIMULATION_TYPE == 1 .and. SAVE_FORWARD) &
+          .or. SIMULATION_TYPE == 3) then
+        call adios_schedule_read(handle, sel, "/nglob_interface_PML_acoustic", &
+                                 0, 1, nglob_interface_PML_acoustic, ier)
+        call adios_schedule_read(handle, sel, "/nglob_interface_PML_elastic", &
+                                 0, 1, nglob_interface_PML_elastic, ier)
+      endif
+    endif
+  endif
+
+  call adios_schedule_read(handle, sel, "/num_abs_boundary_faces", 0, 1, &
+                           num_abs_boundary_faces, ier)
+
+  call adios_schedule_read(handle, sel, "/nspec2d_xmin", 0, 1, &
+                           nspec2d_xmin, ier)
+  call adios_schedule_read(handle, sel, "/nspec2d_xmax", 0, 1, &
+                           nspec2d_xmax, ier)
+  call adios_schedule_read(handle, sel, "/nspec2d_ymin", 0, 1, &
+                           nspec2d_ymin, ier)
+  call adios_schedule_read(handle, sel, "/nspec2d_ymax", 0, 1, &
+                           nspec2d_ymax, ier)
+  call adios_schedule_read(handle, sel, "/nspec2d_bottom", 0, 1, &
+                           nspec2d_bottom, ier)
+  call adios_schedule_read(handle, sel, "/nspec2d_top", 0, 1, &
+                           nspec2d_top, ier)
+
+  call adios_schedule_read(handle, sel, "/num_free_surface_faces", 0, 1, &
+                           num_free_surface_faces, ier)
+  call adios_schedule_read(handle, sel, "/num_coupling_ac_el_faces", 0, 1, &
+                           num_coupling_ac_el_faces, ier)
+  call adios_schedule_read(handle, sel, "/num_coupling_ac_po_faces", 0, 1, &
+                           num_coupling_ac_po_faces, ier)
+  call adios_schedule_read(handle, sel, "/num_coupling_el_po_faces", 0, 1, &
+                           num_coupling_el_po_faces, ier)
+  call adios_schedule_read(handle, sel, "/num_interfaces_ext_mesh", 0, 1, &
+                           num_interfaces_ext_mesh, ier)
+  call adios_schedule_read(handle, sel, "/max_nibool_interfaces_ext_mesh", 0, 1, &
+                           max_nibool_interfaces_ext_mesh, ier)
+
+  if( ACOUSTIC_SIMULATION ) then
+    call adios_schedule_read(handle, sel, "/nspec_inner_acoustic", 0, 1, &
+                             nspec_inner_acoustic, ier)
+    call adios_schedule_read(handle, sel, "/nspec_outer_acoustic", 0, 1, &
+                             nspec_outer_acoustic, ier)
+    call adios_schedule_read(handle, sel, "/num_phase_ispec_acoustic", 0, 1, &
+                             num_phase_ispec_acoustic, ier)
+  endif
+
+  if( ELASTIC_SIMULATION ) then
+    call adios_schedule_read(handle, sel, "/nspec_inner_elastic", 0, 1, &
+                             nspec_inner_elastic, ier)
+    call adios_schedule_read(handle, sel, "/nspec_outer_elastic", 0, 1, &
+                             nspec_outer_elastic, ier)
+    call adios_schedule_read(handle, sel, "/num_phase_ispec_elastic", 0, 1, &
+                             num_phase_ispec_elastic, ier)
+  endif
+
+  if( POROELASTIC_SIMULATION) then
+    call adios_schedule_read(handle, sel, "/nspec_inner_poroelastic", 0, 1, &
+                             nspec_inner_poroelastic, ier)
+    call adios_schedule_read(handle, sel, "/nspec_outer_poroelastic", 0, 1, &
+                             nspec_outer_poroelastic, ier)
+    call adios_schedule_read(handle, sel, "/num_phase_ispec_poroelastic", 0, 1,&
+                             num_phase_ispec_poroelastic, ier)
+  endif
+
+  num_colors_outer_acoustic = 0
+  num_colors_inner_acoustic = 0
+  num_colors_outer_elastic = 0
+  num_colors_inner_elastic = 0
+  if( USE_MESH_COLORING_GPU ) then
+    if( ACOUSTIC_SIMULATION ) then
+      call adios_schedule_read(handle, sel, "/num_colors_outer_acoustic", &
+                               0, 1, num_colors_outer_acoustic, ier)
+      call adios_schedule_read(handle, sel, "/num_colors_outer_acoustic", &
+                               0, 1, num_colors_inner_acoustic, ier)
+    endif
+    if( ELASTIC_SIMULATION ) then
+      call adios_schedule_read(handle, sel, "/num_colors_outer_elastic", &
+                               0, 1, num_colors_outer_elastic, ier)
+      call adios_schedule_read(handle, sel, "/num_colors_outer_elastic", &
+                               0, 1, num_colors_inner_elastic, ier)
+    endif
+  endif
+  ! Perform the read, so we can use the values.
+  call adios_perform_reads(handle, ier)
+
+
+  !------------------------.
+  ! Get the 'chunks' sizes |
+  !------------------------'
+  call adios_get_scalar(handle, "ibool/local_dim",&
+                        local_dim_ibool,ier)
+  call adios_get_scalar(handle, "x_global/local_dim",&
+                        local_dim_x_global,ier)
+  call adios_get_scalar(handle, "y_global/local_dim",&
+                        local_dim_y_global,ier)
+  call adios_get_scalar(handle, "z_global/local_dim",&
+                        local_dim_z_global,ier)
+  call adios_get_scalar(handle, "xixstore/local_dim",&
+                        local_dim_xixstore,ier)
+  call adios_get_scalar(handle, "xiystore/local_dim",&
+                        local_dim_xiystore,ier)
+  call adios_get_scalar(handle, "xizstore/local_dim",&
+                        local_dim_xizstore,ier)
+  call adios_get_scalar(handle, "etaxstore/local_dim",&
+                        local_dim_etaxstore,ier)
+  call adios_get_scalar(handle, "etaystore/local_dim",&
+                        local_dim_etaystore,ier)
+  call adios_get_scalar(handle, "etazstore/local_dim",&
+                        local_dim_etazstore,ier)
+  call adios_get_scalar(handle, "gammaxstore/local_dim",&
+                        local_dim_gammaxstore,ier)
+  call adios_get_scalar(handle, "gammaystore/local_dim",&
+                        local_dim_gammaystore,ier)
+  call adios_get_scalar(handle, "gammazstore/local_dim",&
+                        local_dim_gammazstore,ier)
+  call adios_get_scalar(handle, "jacobianstore/local_dim",&
+                        local_dim_jacobianstore,ier)
+  call adios_get_scalar(handle, "kappastore/local_dim",&
+                        local_dim_kappastore,ier)
+  call adios_get_scalar(handle, "mustore/local_dim",&
+                        local_dim_mustore,ier)
+  call adios_get_scalar(handle, "rhostore/local_dim",&
+                        local_dim_rhostore,ier)
+  if( ACOUSTIC_SIMULATION ) then
+    call adios_get_scalar(handle, "rmass_acoustic/local_dim",&
+                          local_dim_rmass_acoustic,ier)
+    call adios_get_scalar(handle, "rmass_acoustic_interface/local_dim",&
+                          local_dim_rmass_acoustic_interface,ier)
+  endif 
+  if( ELASTIC_SIMULATION ) then
+    call adios_get_scalar(handle, "rmass/local_dim",&
+                          local_dim_rmass,ier)
+    if(PML_CONDITIONS)then
+       if(ACOUSTIC_SIMULATION)then
+          call adios_get_scalar(handle, "rmass_elastic_interface/local_dim",&
+                                local_dim_rmass_elastic_interface,ier)
+       endif
+    endif
+    if( APPROXIMATE_OCEAN_LOAD) then
+      call adios_get_scalar(handle, "rmass_ocean_load/local_dim",&
+                            local_dim_rmass_ocean_load,ier)
+    endif
+    call adios_get_scalar(handle, "rho_vp/local_dim",&
+                          local_dim_rho_vp,ier)
+    call adios_get_scalar(handle, "rho_vs/local_dim",&
+                          local_dim_rho_vs,ier)
+  endif 
+  if( POROELASTIC_SIMULATION ) then
+    call adios_get_scalar(handle, "rmass_solid_poroelastic/local_dim",&
+                          local_dim_rmass_solid_poroelastic,ier)
+    call adios_get_scalar(handle, "rmass_fluid_poroelastic/local_dim",&
+                          local_dim_rmass_fluid_poroelastic,ier)
+    call adios_get_scalar(handle, "rhoarraystore/local_dim",&
+                          local_dim_rhoarraystore,ier)
+    call adios_get_scalar(handle, "kappaarraystore/local_dim",&
+                          local_dim_kappaarraystore,ier)
+    call adios_get_scalar(handle, "permstore/local_dim",&
+                          local_dim_permstore,ier)
+    call adios_get_scalar(handle, "etastore/local_dim",&
+                          local_dim_etastore,ier)
+    call adios_get_scalar(handle, "tortstore/local_dim",&
+                          local_dim_tortstore,ier)
+    call adios_get_scalar(handle, "phistore/local_dim",&
+                          local_dim_phistore,ier)
+    call adios_get_scalar(handle, "rho_vpI/local_dim",&
+                          local_dim_rho_vpI,ier)
+    call adios_get_scalar(handle, "rho_vpII/local_dim",&
+                          local_dim_rho_vpII,ier)
+    call adios_get_scalar(handle, "rho_vsI/local_dim",&
+                          local_dim_rho_vsI,ier)
+  endif 
+  if( PML_CONDITIONS ) then
+    if( nspec_cpml > 0 ) then
+      call adios_get_scalar(handle, "CPML_regions/local_dim",&
+                            local_dim_CPML_regions, ier)
+      call adios_get_scalar(handle, "CPML_to_spec/local_dim",&
+                            local_dim_CPML_to_spec, ier)
+      call adios_get_scalar(handle, "is_CPML/local_dim",&
+                            local_dim_is_CPML, ier)
+      call adios_get_scalar(handle, "d_store_x/local_dim",&
+                            local_dim_d_store_x, ier)
+      call adios_get_scalar(handle, "d_store_y/local_dim",&
+                            local_dim_d_store_y, ier)
+      call adios_get_scalar(handle, "d_store_z/local_dim",&
+                            local_dim_d_store_z, ier)
+      call adios_get_scalar(handle, "k_store_x/local_dim",&
+                            local_dim_k_store_x, ier)
+      call adios_get_scalar(handle, "k_store_y/local_dim",&
+                            local_dim_k_store_y, ier)
+      call adios_get_scalar(handle, "k_store_z/local_dim",&
+                            local_dim_k_store_z, ier)
+      call adios_get_scalar(handle, "alpha_store/local_dim",&
+                            local_dim_alpha_store, ier)
+      if((SIMULATION_TYPE == 1 .and. SAVE_FORWARD) &
+          .or. SIMULATION_TYPE == 3) then
+        if(nglob_interface_PML_acoustic > 0) then
+          call adios_get_scalar(handle, "points_interface_PML_acoustic/local_dim",&
+                                local_dim_points_interface_PML_acoustic, ier)
+        endif
+        if(nglob_interface_PML_elastic > 0) then
+          call adios_get_scalar(handle, "points_interface_PML_elastic/local_dim",&
+                                local_dim_points_interface_PML_elastic, ier)
+        endif
+      endif
+    endif
+  endif
+
+  if(PML_CONDITIONS)then
+    if( num_abs_boundary_faces > 0 ) then
+      call adios_get_scalar(handle, "abs_boundary_ispec/local_dim",&
+                            local_dim_abs_boundary_ispec,ier)
+      call adios_get_scalar(handle, "abs_boundary_ijk/local_dim",&
+                            local_dim_abs_boundary_ijk,ier)
+      call adios_get_scalar(handle, "abs_boundary_jacobian2Dw/local_dim",&
+                            local_dim_abs_boundary_jacobian2Dw,ier)
+      call adios_get_scalar(handle, "abs_boundary_normal/local_dim",&
+                            local_dim_abs_boundary_normal,ier)
+    endif
+  else
+    if( num_abs_boundary_faces > 0 ) then
+      call adios_get_scalar(handle, "abs_boundary_ispec/local_dim",&
+                            local_dim_abs_boundary_ispec,ier)
+      call adios_get_scalar(handle, "abs_boundary_ijk/local_dim",&
+                            local_dim_abs_boundary_ijk,ier)
+      call adios_get_scalar(handle, "abs_boundary_jacobian2Dw/local_dim",&
+                            local_dim_abs_boundary_jacobian2Dw,ier)
+      call adios_get_scalar(handle, "abs_boundary_normal/local_dim",&
+                            local_dim_abs_boundary_normal,ier)
+      if( STACEY_ABSORBING_CONDITIONS ) then
+        ! store mass matrix contributions
+        if(ELASTIC_SIMULATION ) then
+          call adios_get_scalar(handle, "rmassx/local_dim",&
+                                local_dim_rmassx, ier)
+          call adios_get_scalar(handle, "rmassy/local_dim",&
+                                local_dim_rmassy, ier)
+          call adios_get_scalar(handle, "rmassz/local_dim",&
+                                local_dim_rmassz, ier)
+        endif
+        if(ACOUSTIC_SIMULATION) then
+          call adios_get_scalar(handle, "rmassz_acoustic/local_dim",&
+                                local_dim_rmassz_acoustic, ier)
+        endif
+      endif
+    endif
+  endif
+
+  call adios_get_scalar(handle, "ibelm_xmin/local_dim",&
+                        local_dim_ibelm_xmin,ier)
+  call adios_get_scalar(handle, "ibelm_xmax/local_dim",&
+                        local_dim_ibelm_xmax,ier)
+  call adios_get_scalar(handle, "ibelm_ymin/local_dim",&
+                        local_dim_ibelm_ymin,ier)
+  call adios_get_scalar(handle, "ibelm_ymax/local_dim",&
+                        local_dim_ibelm_ymax,ier)
+  call adios_get_scalar(handle, "ibelm_bottom/local_dim",&
+                        local_dim_ibelm_bottom,ier)
+  call adios_get_scalar(handle, "ibelm_top/local_dim",&
+                        local_dim_ibelm_top,ier)
+
+  if( num_free_surface_faces > 0 ) then
+    call adios_get_scalar(handle, "free_surface_ispec/local_dim",&
+                          local_dim_free_surface_ispec,ier)
+    call adios_get_scalar(handle, "free_surface_ijk/local_dim",&
+                          local_dim_free_surface_ijk,ier)
+    call adios_get_scalar(handle, "free_surface_jacobian2Dw/local_dim",&
+                          local_dim_free_surface_jacobian2Dw,ier)
+    call adios_get_scalar(handle, "free_surface_normal/local_dim",&
+                          local_dim_free_surface_normal,ier)
+  endif
+  if( num_coupling_ac_el_faces > 0 ) then
+    call adios_get_scalar(handle, "coupling_ac_el_ispec/local_dim",&
+                          local_dim_coupling_ac_el_ispec,ier)
+    call adios_get_scalar(handle, "coupling_ac_el_ijk/local_dim",&
+                          local_dim_coupling_ac_el_ijk,ier)
+    call adios_get_scalar(handle, "coupling_ac_el_jacobian2Dw/local_dim",&
+                          local_dim_coupling_ac_el_jacobian2Dw,ier)
+    call adios_get_scalar(handle, "coupling_ac_el_normal/local_dim",&
+                          local_dim_coupling_ac_el_normal,ier)
+  endif
+  if( num_coupling_ac_po_faces > 0 ) then
+    call adios_get_scalar(handle, "coupling_ac_po_ispec/local_dim",&
+                          local_dim_coupling_ac_po_ispec, ier)
+    call adios_get_scalar(handle, "coupling_ac_po_ijk/local_dim",&
+                          local_dim_coupling_ac_po_ijk, ier)
+    call adios_get_scalar(handle, "coupling_ac_po_jacobian2Dw/local_dim",&
+                          local_dim_coupling_ac_po_jacobian2Dw, ier)
+    call adios_get_scalar(handle, "coupling_ac_po_normal/local_dim",&
+                          local_dim_coupling_ac_po_normal, ier)
+  endif
+  if( num_coupling_el_po_faces > 0 ) then
+    call adios_get_scalar(handle, "coupling_el_po_ispec/local_dim",&
+                          local_dim_coupling_el_po_ispec, ier)
+    call adios_get_scalar(handle, "coupling_po_el_ispec/local_dim",&
+                          local_dim_coupling_po_el_ispec, ier)
+    call adios_get_scalar(handle, "coupling_el_po_ijk/local_dim",&
+                          local_dim_coupling_el_po_ijk, ier)
+    call adios_get_scalar(handle, "coupling_po_el_ijk/local_dim",&
+                          local_dim_coupling_po_el_ijk, ier)
+    call adios_get_scalar(handle, "coupling_el_po_jacobian2Dw/local_dim",&
+                          local_dim_coupling_el_po_jacobian2Dw, ier)
+    call adios_get_scalar(handle, "coupling_el_po_normal/local_dim",&
+                          local_dim_coupling_el_po_normal, ier)
+  endif
+  if( num_interfaces_ext_mesh > 0 ) then
+    call adios_get_scalar(handle, "my_neighbours_ext_mesh/local_dim",&
+                          local_dim_my_neighbours_ext_mesh,ier)
+    call adios_get_scalar(handle, "nibool_interfaces_ext_mesh/local_dim",&
+                          local_dim_nibool_interfaces_ext_mesh,ier)
+    call adios_get_scalar(handle, "ibool_interfaces_ext_mesh_dummy/local_dim",&
+                          local_dim_ibool_interfaces_ext_mesh, ier)
+  endif
+  if( ELASTIC_SIMULATION .and. ANISOTROPY ) then
+    call adios_get_scalar(handle, "c11store/local_dim",&
+                          local_dim_c11store, ier)
+  endif
+  call adios_get_scalar(handle, "ispec_is_inner/local_dim",&
+                        local_dim_ispec_is_inner,ier)
+  if( ACOUSTIC_SIMULATION ) then
+    if(num_phase_ispec_acoustic > 0 ) then
+      call adios_get_scalar(handle, "phase_ispec_inner_acoustic/local_dim",&
+                            local_dim_phase_ispec_inner_acoustic,ier)
+    endif
+  endif
+  if( ELASTIC_SIMULATION ) then
+    if(num_phase_ispec_elastic > 0 ) then
+      call adios_get_scalar(handle, "phase_ispec_inner_elastic/local_dim",&
+                            local_dim_phase_ispec_inner_elastic,ier)
+    endif
+  endif
+  if( POROELASTIC_SIMULATION ) then
+    if(num_phase_ispec_poroelastic > 0 ) then
+      call adios_get_scalar(handle, "phase_ispec_inner_poroelastic/local_dim",&
+                            local_dim_phase_ispec_inner_poroelastic,ier)
+    endif
+  endif
+  if( USE_MESH_COLORING_GPU ) then
+    if( ACOUSTIC_SIMULATION ) then
+      call adios_get_scalar(handle, "num_elem_colors_acoustic/local_dim",&
+                            local_dim_num_elem_colors_acoustic, ier)
+    endif
+    if( ELASTIC_SIMULATION ) then
+      call adios_get_scalar(handle, "num_elem_colors_elastic/local_dim",&
+                            local_dim_num_elem_colors_elastic, ier)
+    endif
+  endif
+
+!TODO
+#if 1
+  !---------------------------------------------.
+  ! Allocate arrays with previously read values |
+  !---------------------------------------------'
+  if( ACOUSTIC_SIMULATION ) then
+    ! potentials
+    allocate(potential_acoustic(NGLOB_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array potential_acoustic'
+    allocate(potential_dot_acoustic(NGLOB_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array potential_dot_acoustic'
+    allocate(potential_dot_dot_acoustic(NGLOB_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array potential_dot_dot_acoustic'
+    allocate(potential_dot_dot_acoustic_interface(NGLOB_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array potential_dot_dot_acoustic_interface'
+    if( SIMULATION_TYPE /= 1 ) then
+      allocate(potential_acoustic_adj_coupling(NGLOB_AB),stat=ier)
+      if( ier /= 0 ) stop 'error allocating array potential_acoustic_adj_coupling'
+    endif
+    ! mass matrix, density
+    allocate(rmass_acoustic(NGLOB_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array rmass_acoustic'
+    allocate(rmass_acoustic_interface(NGLOB_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array rmass_acoustic_interface'
+
+    ! initializes mass matrix contribution
+    allocate(rmassz_acoustic(NGLOB_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array rmassz_acoustic'
+    rmassz_acoustic(:) = 0._CUSTOM_REAL
+  endif
+
+  ! this array is needed for acoustic simulations but also for elastic 
+  ! simulations with CPML, thus we now allocate it and read it in all 
+  ! cases (whether the simulation is acoustic, elastic, or acoustic/elastic)
+  allocate(rhostore(NGLLX,NGLLY,NGLLZ,NSPEC_AB),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array rhostore'
+
+!TODO
+#endif
+  ! elastic simulation
+  if( ELASTIC_SIMULATION ) then
+!TODO
+#if 1
+    ! displacement,velocity,acceleration
+    allocate(displ(NDIM,NGLOB_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array displ'
+    allocate(veloc(NDIM,NGLOB_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array veloc'
+    allocate(accel(NDIM,NGLOB_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array accel'
+    if( SIMULATION_TYPE /= 1 ) then
+      allocate(accel_adj_coupling(NDIM,NGLOB_AB),stat=ier)
+      if( ier /= 0 ) stop 'error allocating array accel_adj_coupling'
+    endif
+
+    ! allocates mass matrix
+    allocate(rmass(NGLOB_AB),stat=ier)
+
+    if(PML_CONDITIONS)then
+       if(ACOUSTIC_SIMULATION)then
+          allocate(rmass_elastic_interface(NGLOB_AB),stat=ier)
+          if( ier /= 0 ) stop 'error allocating array rmass_elastic_interface'
+          rmass_elastic_interface(:) = 0._CUSTOM_REAL
+          if(SIMULATION_TYPE == 3)then
+            allocate(accel_interface(NDIM,NGLOB_AB),stat=ier)
+            if( ier /= 0 ) stop 'error allocating array accel_interface'
+            accel_interface(:,:) = 0._CUSTOM_REAL
+          else
+            allocate(accel_interface(NDIM,1),stat=ier)
+            if( ier /= 0 ) stop 'error allocating array accel_interface'
+            accel_interface(:,:) = 0._CUSTOM_REAL
+          endif
+       else
+          allocate(rmass_elastic_interface(1),stat=ier)
+          allocate(accel_interface(NDIM,1),stat=ier)
+       endif
+    else
+      allocate(rmass_elastic_interface(1),stat=ier)
+      allocate(accel_interface(NDIM,1),stat=ier)
+    endif
+
+    if( ier /= 0 ) stop 'error allocating array rmass'
+    ! initializes mass matrix contributions
+    allocate(rmassx(NGLOB_AB), &
+             rmassy(NGLOB_AB), &
+             rmassz(NGLOB_AB), &
+             stat=ier)
+    if( ier /= 0 ) stop 'error allocating array rmassx,rmassy,rmassz'
+    rmassx(:) = 0._CUSTOM_REAL
+    rmassy(:) = 0._CUSTOM_REAL
+    rmassz(:) = 0._CUSTOM_REAL
+
+    allocate(rho_vp(NGLLX,NGLLY,NGLLZ,NSPEC_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array rho_vp'
+    allocate(rho_vs(NGLLX,NGLLY,NGLLZ,NSPEC_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array rho_vs'
+    rho_vp = 0.0_CUSTOM_REAL
+    rho_vs = 0.0_CUSTOM_REAL
+    allocate(c11store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
+            c12store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
+            c13store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
+            c14store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
+            c15store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
+            c16store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
+            c22store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
+            c23store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
+            c24store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
+            c25store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
+            c26store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
+            c33store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
+            c34store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
+            c35store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
+            c36store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
+            c44store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
+            c45store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
+            c46store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
+            c55store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
+            c56store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO), &
+            c66store(NGLLX,NGLLY,NGLLZ,NSPEC_ANISO),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array c11store etc.'
+
+    ! note: currently, they need to be defined, as they are used in the 
+    !       routine arguments for compute_forces_viscoelastic_Deville()
+    allocate(R_xx(NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB,N_SLS), &
+            R_yy(NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB,N_SLS), &
+            R_xy(NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB,N_SLS), &
+            R_xz(NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB,N_SLS), &
+            R_yz(NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB,N_SLS),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array R_xx etc.'
+
+    ! needed for attenuation and/or kernel computations
+    allocate(epsilondev_xx(NGLLX,NGLLY,NGLLZ,NSPEC_STRAIN_ONLY), &
+            epsilondev_yy(NGLLX,NGLLY,NGLLZ,NSPEC_STRAIN_ONLY), &
+            epsilondev_xy(NGLLX,NGLLY,NGLLZ,NSPEC_STRAIN_ONLY), &
+            epsilondev_xz(NGLLX,NGLLY,NGLLZ,NSPEC_STRAIN_ONLY), &
+            epsilondev_yz(NGLLX,NGLLY,NGLLZ,NSPEC_STRAIN_ONLY),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array epsilondev_xx etc.'
+
+    allocate(R_trace(NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB_kappa,N_SLS),&
+             epsilondev_trace(NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB_kappa),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array R_trace etc.'
+
+    ! note: needed for argument of deville routine
+    allocate(epsilon_trace_over_3(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array epsilon_trace_over_3'
+
+    ! needed for attenuation
+    allocate(one_minus_sum_beta(NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB), &
+            factor_common(N_SLS,NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array one_minus_sum_beta etc.'
+
+    allocate(one_minus_sum_beta_kappa(NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB_kappa), &
+             factor_common_kappa(N_SLS,NGLLX,NGLLY,NGLLZ,NSPEC_ATTENUATION_AB_kappa),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array one_minus_sum_beta_kappa etc.'
+
+    if( APPROXIMATE_OCEAN_LOAD ) then
+      ! ocean mass matrix
+      allocate(rmass_ocean_load(NGLOB_AB),stat=ier)
+      if( ier /= 0 ) stop 'error allocating array rmass_ocean_load'
+    else
+      ! dummy allocation
+      allocate(rmass_ocean_load(1),stat=ier)
+      if( ier /= 0 ) stop 'error allocating dummy array rmass_ocean_load'
+    endif
+! TODO    
+#endif
+  else
+    ! no elastic attenuation & anisotropy
+    ATTENUATION = .false.
+    ANISOTROPY = .false.
+  endif
+
+  if( POROELASTIC_SIMULATION ) then
+
+    if( GPU_MODE ) &
+        call exit_mpi(myrank,'POROELASTICITY not supported by GPU mode yet...')
+
+    ! displacement,velocity,acceleration for the solid (s) & fluid (w) phases
+    allocate(displs_poroelastic(NDIM,NGLOB_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array displs_poroelastic'
+    allocate(velocs_poroelastic(NDIM,NGLOB_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array velocs_poroelastic'
+    allocate(accels_poroelastic(NDIM,NGLOB_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array accels_poroelastic'
+    allocate(displw_poroelastic(NDIM,NGLOB_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array displw_poroelastic'
+    allocate(velocw_poroelastic(NDIM,NGLOB_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array velocw_poroelastic'
+    allocate(accelw_poroelastic(NDIM,NGLOB_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array accelw_poroelastic'
+
+    allocate(rmass_solid_poroelastic(NGLOB_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array rmass_solid_poroelastic'
+    allocate(rmass_fluid_poroelastic(NGLOB_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array rmass_fluid_poroelastic'
+
+    allocate(rhoarraystore(2,NGLLX,NGLLY,NGLLZ,NSPEC_AB), &
+             kappaarraystore(3,NGLLX,NGLLY,NGLLZ,NSPEC_AB), &
+             etastore(NGLLX,NGLLY,NGLLZ,NSPEC_AB), &
+             tortstore(NGLLX,NGLLY,NGLLZ,NSPEC_AB), &
+             phistore(NGLLX,NGLLY,NGLLZ,NSPEC_AB), &
+             permstore(6,NGLLX,NGLLY,NGLLZ,NSPEC_AB), &
+             rho_vpI(NGLLX,NGLLY,NGLLZ,NSPEC_AB), &
+             rho_vpII(NGLLX,NGLLY,NGLLZ,NSPEC_AB), &
+             rho_vsI(NGLLX,NGLLY,NGLLZ,NSPEC_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array poroelastic properties'
+
+    ! needed for kernel computations
+    allocate(epsilonsdev_xx(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            epsilonsdev_yy(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            epsilonsdev_xy(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            epsilonsdev_xz(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            epsilonsdev_yz(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            epsilonwdev_xx(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            epsilonwdev_yy(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            epsilonwdev_xy(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            epsilonwdev_xz(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            epsilonwdev_yz(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array epsilonsdev_xx etc.'
+
+    allocate(epsilons_trace_over_3(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT), &
+            epsilonw_trace_over_3(NGLLX,NGLLY,NGLLZ,NSPEC_ADJOINT),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array epsilons_trace_over_3 etc.'
+  endif
+
+  ! C-PML absorbing boundary conditions
+  if( PML_CONDITIONS ) then
+    allocate(is_CPML(NSPEC_AB),stat=ier)
+    if(ier /= 0) stop 'error allocating array is_CPML'
+
+    ! make sure there are no PMLs by default,
+    ! and then below if NSPEC_CPML > 0 we will need the real flags 
+    ! for this mesh from the disk
+    is_CPML(:) = .false.
+
+    if( NSPEC_CPML > 0 ) then
+      allocate(CPML_regions(NSPEC_CPML),stat=ier)
+      if(ier /= 0) stop 'error allocating array CPML_regions'
+      allocate(CPML_to_spec(NSPEC_CPML),stat=ier)
+      if(ier /= 0) stop 'error allocating array CPML_to_spec'
+      allocate(d_store_x(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
+      if(ier /= 0) stop 'error allocating array d_store_x'
+      allocate(d_store_y(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
+      if(ier /= 0) stop 'error allocating array d_store_y'
+      allocate(d_store_z(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
+      if(ier /= 0) stop 'error allocating array d_store_z'
+      allocate(K_store_x(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
+      if(ier /= 0) stop 'error allocating array K_store_x'
+      allocate(K_store_y(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
+      if(ier /= 0) stop 'error allocating array K_store_y'
+      allocate(K_store_z(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
+      if(ier /= 0) stop 'error allocating array K_store_z'
+      allocate(alpha_store(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
+      if(ier /= 0) stop 'error allocating array alpha_store'
+
+      if((SIMULATION_TYPE == 1 .and. SAVE_FORWARD) .or. SIMULATION_TYPE == 3) then
+        if(nglob_interface_PML_acoustic > 0) then
+          allocate(points_interface_PML_acoustic(nglob_interface_PML_acoustic),stat=ier)
+          if(ier /= 0) stop 'error allocating array points_interface_PML_acoustic'
+        endif
+        if(nglob_interface_PML_elastic > 0) then
+          allocate(points_interface_PML_elastic(nglob_interface_PML_elastic),stat=ier)
+          if(ier /= 0) stop 'error allocating array points_interface_PML_elastic'
+        endif
+      endif
+    endif
+  else
+    ! allocate with a dummy size of zero just to be able to use this array 
+    ! as argument in subroutine calls
+    allocate(is_CPML(0),stat=ier)
+  endif
+
+  ! absorbing boundary surface
+  allocate(abs_boundary_ispec(num_abs_boundary_faces), &
+          abs_boundary_ijk(3,NGLLSQUARE,num_abs_boundary_faces), &
+          abs_boundary_jacobian2Dw(NGLLSQUARE,num_abs_boundary_faces), &
+          abs_boundary_normal(NDIM,NGLLSQUARE,num_abs_boundary_faces),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array abs_boundary_ispec etc.'
+
+  if (OLD_TEST_TO_FIX_ONE_DAY) then
+    ! VM for new method
+    !! DK DK for VM VM: these two arrays are undeclared, thus I comment them out i
+    ! for now otherwise the code does not compile
+    !! VM VM : I already declared these two array in the specfem_par module
+    allocate(Veloc_dsm_boundary(3,Ntime_step_dsm,NGLLSQUARE,num_abs_boundary_faces))
+    allocate(Tract_dsm_boundary(3,Ntime_step_dsm,NGLLSQUARE,num_abs_boundary_faces))
+    open(unit=IIN_veloc_dsm,file=dsmname(1:len_trim(dsmname))//'vel.bin',status='old', &
+         action='read',form='unformatted',iostat=ier)
+    open(unit=IIN_tract_dsm,file=dsmname(1:len_trim(dsmname))//'tract.bin',status='old', &
+         action='read',form='unformatted',iostat=ier)
+  else
+     allocate(Veloc_dsm_boundary(1,1,1,1))
+     allocate(Tract_dsm_boundary(1,1,1,1))
+  endif
+
+  allocate(ibelm_xmin(nspec2D_xmin),ibelm_xmax(nspec2D_xmax), &
+       ibelm_ymin(nspec2D_ymin),ibelm_ymax(nspec2D_ymax), &
+       ibelm_bottom(NSPEC2D_BOTTOM),ibelm_top(NSPEC2D_TOP),stat=ier)
+  if(ier /= 0) stop 'error allocating arrays ibelm_xmin,ibelm_xmax etc.'
+
+  ! free surface
+  allocate(free_surface_ispec(num_free_surface_faces), &
+          free_surface_ijk(3,NGLLSQUARE,num_free_surface_faces), &
+          free_surface_jacobian2Dw(NGLLSQUARE,num_free_surface_faces), &
+          free_surface_normal(NDIM,NGLLSQUARE,num_free_surface_faces),stat=ier)
+  if(ier /= 0) stop 'error allocating arrays free_surface_ispec etc.'
+
+  ! acoustic-elastic coupling surface
+  allocate(coupling_ac_el_normal(NDIM,NGLLSQUARE,num_coupling_ac_el_faces), &
+          coupling_ac_el_jacobian2Dw(NGLLSQUARE,num_coupling_ac_el_faces), &
+          coupling_ac_el_ijk(3,NGLLSQUARE,num_coupling_ac_el_faces), &
+          coupling_ac_el_ispec(num_coupling_ac_el_faces),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array coupling_ac_el_normal etc.'
+
+  ! acoustic-poroelastic coupling surface
+  allocate(coupling_ac_po_normal(NDIM,NGLLSQUARE,num_coupling_ac_po_faces), &
+          coupling_ac_po_jacobian2Dw(NGLLSQUARE,num_coupling_ac_po_faces), &
+          coupling_ac_po_ijk(3,NGLLSQUARE,num_coupling_ac_po_faces), &
+          coupling_ac_po_ispec(num_coupling_ac_po_faces),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array coupling_ac_po_normal etc.'
+
+  ! elastic-poroelastic coupling surface
+  allocate(coupling_el_po_normal(NDIM,NGLLSQUARE,num_coupling_el_po_faces), &
+          coupling_el_po_jacobian2Dw(NGLLSQUARE,num_coupling_el_po_faces), &
+          coupling_el_po_ijk(3,NGLLSQUARE,num_coupling_el_po_faces), &
+          coupling_po_el_ijk(3,NGLLSQUARE,num_coupling_el_po_faces), &
+          coupling_el_po_ispec(num_coupling_el_po_faces), &
+          coupling_po_el_ispec(num_coupling_el_po_faces),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array coupling_el_po_normal etc.'
+
+  ! MPI interfaces
+  allocate(my_neighbours_ext_mesh(num_interfaces_ext_mesh), &
+          nibool_interfaces_ext_mesh(num_interfaces_ext_mesh),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array my_neighbours_ext_mesh etc.'
+  if( num_interfaces_ext_mesh > 0 ) then
+    allocate(ibool_interfaces_ext_mesh(max_nibool_interfaces_ext_mesh, &
+                                       num_interfaces_ext_mesh),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array ibool_interfaces_ext_mesh'
+  else
+    max_nibool_interfaces_ext_mesh = 0
+    allocate(ibool_interfaces_ext_mesh(0,0),stat=ier)
+  endif
+
+  ! inner / outer elements
+  allocate(ispec_is_inner(NSPEC_AB),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array ispec_is_inner'
+
+  if( ACOUSTIC_SIMULATION ) then
+    if( num_phase_ispec_acoustic < 0 ) stop 'error acoustic simulation:' // &
+                                    'num_phase_ispec_acoustic is < zero'
+    allocate( phase_ispec_inner_acoustic(num_phase_ispec_acoustic,2),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array phase_ispec_inner_acoustic'
+  endif
+
+  if( ELASTIC_SIMULATION ) then
+    if( num_phase_ispec_elastic < 0 ) stop 'error elastic simulation:' // &
+                                   'num_phase_ispec_elastic is < zero'
+    allocate( phase_ispec_inner_elastic(num_phase_ispec_elastic,2),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array phase_ispec_inner_elastic'
+  endif
+
+  if( POROELASTIC_SIMULATION ) then
+    if( num_phase_ispec_poroelastic < 0 ) stop 'error poroelastic simulation:'&
+                                       'num_phase_ispec_poroelastic is < zero'
+    allocate( phase_ispec_inner_poroelastic(num_phase_ispec_poroelastic,2), &
+              stat=ier)
+    if( ier /= 0 ) stop 'error allocating array phase_ispec_inner_poroelastic'
+  endif
+
+  ! mesh coloring for GPUs
+  if( USE_MESH_COLORING_GPU ) then
+    ! acoustic domain colors
+    if( ACOUSTIC_SIMULATION ) then
+      allocate(num_elem_colors_acoustic(num_colors_outer_acoustic &
+                                      + num_colors_inner_acoustic),stat=ier)
+      if( ier /= 0 ) stop 'error allocating num_elem_colors_acoustic array'
+    endif
+    ! elastic domain colors
+    if( ELASTIC_SIMULATION ) then
+      read(27) num_colors_outer_elastic,num_colors_inner_elastic
+
+      allocate(num_elem_colors_elastic(num_colors_outer_elastic &
+                                     + num_colors_inner_elastic),stat=ier)
+      if( ier /= 0 ) stop 'error allocating num_elem_colors_elastic array'
+    endif
+  else
+    ! allocates dummy arrays
+    if( ACOUSTIC_SIMULATION ) then
+      allocate(num_elem_colors_acoustic(num_colors_outer_acoustic &
+                                      + num_colors_inner_acoustic),stat=ier)
+      if( ier /= 0 ) stop 'error allocating num_elem_colors_acoustic array'
+    endif
+    if( ELASTIC_SIMULATION ) then
+      allocate(num_elem_colors_elastic(num_colors_outer_elastic &
+                                     + num_colors_inner_elastic),stat=ier)
+      if( ier /= 0 ) stop 'error allocating num_elem_colors_elastic array'
+    endif
+  endif
+
+  !-----------------------------------.
+  ! Read arrays from external_mesh.bp |
+  !-----------------------------------'
+  start(1) = local_dim_ibool * myrank
+  count_ad(1) = NGLLX * NGLLY * NGLLZ * NSPEC_AB
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count_ad)
+  call adios_schedule_read(handle, sel, "ibool/array", 0, 1, &
+                           ibool, ier)
+  start(1) = local_dim_x_global * myrank
+  count_ad(1) = NGLOB_AB
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count_ad)
+  call adios_schedule_read(handle, sel, "x_global/array", 0, 1, &
+                           xstore, ier)
+  start(1) = local_dim_y_global * myrank
+  count_ad(1) = NGLOB_AB
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count_ad)
+  call adios_schedule_read(handle, sel, "y_global/array", 0, 1, &
+                           ystore, ier)
+  start(1) = local_dim_z_global * myrank
+  count_ad(1) = NGLOB_AB
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count_ad)
+  call adios_schedule_read(handle, sel, "z_global/array", 0, 1, &
+                           zstore, ier)
+
+  start(1) = local_dim_xixstore * myrank
+  count_ad(1) = NGLLX * NGLLY * NGLLZ * NSPEC_AB
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count_ad)
+  call adios_schedule_read(handle, sel, "xixstore/array", 0, 1, &
+                           xix, ier)
+  call adios_schedule_read(handle, sel, "xiystore/array", 0, 1, &
+                           xiy, ier)
+  call adios_schedule_read(handle, sel, "xizstore/array", 0, 1, &
+                           xiz, ier)
+  call adios_schedule_read(handle, sel, "etaxstore/array", 0, 1, &
+                           etax, ier)
+  call adios_schedule_read(handle, sel, "etaystore/array", 0, 1, &
+                           etay, ier)
+  call adios_schedule_read(handle, sel, "etazstore/array", 0, 1, &
+                           etaz, ier)
+  call adios_schedule_read(handle, sel, "gammaxstore/array", 0, 1, &
+                           gammax, ier)
+  call adios_schedule_read(handle, sel, "gammaystore/array", 0, 1, &
+                           gammay, ier)
+  call adios_schedule_read(handle, sel, "gammazstore/array", 0, 1, &
+                           gammaz, ier)
+  call adios_schedule_read(handle, sel, "jacobianstore/array", 0, 1, &
+                           jacobian, ier)
+  call adios_schedule_read(handle, sel, "kappastore/array", 0, 1, &
+                           kappastore, ier)
+  call adios_schedule_read(handle, sel, "mustore/array", 0, 1, &
+                           mustore, ier)
+  call adios_schedule_read(handle, sel, "rhostore/array", 0, 1, &
+                           rhostore, ier)
+
+  if( ACOUSTIC_SIMULATION ) then
+    start(1) = local_dim_rmass_acoustic * myrank
+    count_ad(1) = NGLOB_AB 
+    sel_num = sel_num+1
+    sel => selections(sel_num)
+    call adios_selection_boundingbox (sel , 1, start, count_ad)
+    call adios_schedule_read(handle, sel, "rmass_acoustic/array", 0, 1, &
+                             rmass_acoustic, ier)
+    call adios_schedule_read(handle, sel, "rmass_acoustic_interface/array", &
+                             0, 1, rmass_acoustic_interface, ier)
+  endif
+
+  if( ELASTIC_SIMULATION ) then
+    start(1) = local_dim_rmass * myrank
+    count_ad(1) = NGLOB_AB
+    sel_num = sel_num+1
+    sel => selections(sel_num)
+    call adios_selection_boundingbox (sel , 1, start, count_ad)
+    call adios_schedule_read(handle, sel, "rmass/array", 0, 1, &
+                             rmass, ier)
+
+    if(PML_CONDITIONS)then !need to be optimized
+       if(ACOUSTIC_SIMULATION)then
+          start(1) = local_dim_rmass * myrank
+          count_ad(1) = NGLOB_AB
+          sel_num = sel_num+1
+          sel => selections(sel_num)
+          call adios_selection_boundingbox (sel , 1, start, count_ad)
+          call adios_schedule_read(handle, sel,                           &
+                                   "rmass_elastic_interface/array", 0, 1, &
+                                    rmass_elastic_interface, ier)
+       endif
+    endif
+
+    if( APPROXIMATE_OCEAN_LOAD ) then
+      ! ocean mass matrix
+      start(1) = local_dim_rmass_ocean_load * myrank
+      count_ad(1) = NGLOB_AB !nglob_ocean 
+      sel_num = sel_num+1
+      sel => selections(sel_num)
+      call adios_selection_boundingbox (sel , 1, start, count_ad)
+      call adios_schedule_read(handle, sel, "rmass_ocean_load/array", 0, 1, &
+                               rmass_ocean_load, ier)
+    endif
+
+    !pll material parameters for stacey conditions
+    start(1) = local_dim_rho_vp * myrank
+    count_ad(1) = NGLLX * NGLLY * NGLLZ * NSPEC_AB
+    sel_num = sel_num+1
+    sel => selections(sel_num)
+    call adios_selection_boundingbox (sel , 1, start, count_ad)
+    call adios_schedule_read(handle, sel, "rho_vp/array", 0, 1, &
+                             rho_vp, ier)
+    call adios_schedule_read(handle, sel, "rho_vs/array", 0, 1, &
+                             rho_vs, ier)
+  endif
+
+  if( POROELASTIC_SIMULATION ) then
+    start(1) = local_dim_rmass_solid_poroelastic * myrank
+    count_ad(1) = NGLOB_AB 
+    sel_num = sel_num+1
+    sel => selections(sel_num)
+    call adios_selection_boundingbox (sel , 1, start, count_ad)
+    call adios_schedule_read(handle, sel, "rmass_solid_poroelastic/array", &
+                             0, 1, rmass_solid_poroelastic, ier)
+    call adios_schedule_read(handle, sel, "rmass_fluid_poroelastic/array", &
+                             0, 1, rmass_fluid_poroelastic, ier)
+
+    start(1) = local_dim_rhoarraystore * myrank
+    count_ad(1) = 2 * NGLLX * NGLLY * NGLLZ * NSPEC_AB
+    sel_num = sel_num+1
+    sel => selections(sel_num)
+    call adios_selection_boundingbox (sel , 1, start, count_ad)
+    call adios_schedule_read(handle, sel, "rhoarraystore/array", 0, 1, &
+                             rhoarraystore, ier)
+
+    start(1) = local_dim_kappaarraystore* myrank
+    count_ad(1) = 3 * NGLLX * NGLLY * NGLLZ * NSPEC_AB
+    sel_num = sel_num+1
+    sel => selections(sel_num)
+    call adios_selection_boundingbox (sel , 1, start, count_ad)
+    call adios_schedule_read(handle, sel, "kappaarraystore/array", 0, 1, &
+                             kappaarraystore, ier)
+    
+    start(1) = local_dim_permstore * myrank
+    count_ad(1) =  6 * NGLLX * NGLLY * NGLLZ * NSPEC_AB
+    sel_num = sel_num+1
+    sel => selections(sel_num)
+    call adios_selection_boundingbox (sel , 1, start, count_ad)
+    call adios_schedule_read(handle, sel, "permstore/array", 0, 1, &
+                             permstore, ier)
+
+    start(1) = local_dim_etastore * myrank
+    count_ad(1) = NGLLX * NGLLY * NGLLZ * NSPEC_AB
+    sel_num = sel_num+1
+    sel => selections(sel_num)
+    call adios_selection_boundingbox (sel , 1, start, count_ad)
+    call adios_schedule_read(handle, sel, "etastore/array", 0, 1, &
+                             etastore, ier)
+    call adios_schedule_read(handle, sel, "tortstore/array", 0, 1, &
+                             tortstore, ier)
+    call adios_schedule_read(handle, sel, "phistore/array", 0, 1, &
+                             phistore, ier)
+    call adios_schedule_read(handle, sel, "rho_vpI/array", 0, 1, &
+                             rho_vpI, ier)
+    call adios_schedule_read(handle, sel, "rho_vpII/array", 0, 1, &
+                             rho_vpII, ier)
+    call adios_schedule_read(handle, sel, "rho_vsI/array", 0, 1, &
+                             rho_vsI, ier)
+  endif
+
+  ! C-PML absorbing boundary conditions
+  if( PML_CONDITIONS ) then
+    if( NSPEC_CPML > 0 ) then
+
+      start(1) = local_dim_CPML_regions * myrank
+      count_ad(1) = nspec_cpml
+      sel_num = sel_num+1
+      sel => selections(sel_num)
+      call adios_selection_boundingbox (sel , 1, start, count_ad)
+      call adios_schedule_read(handle, sel, "CPML_regions/array", 0, 1, &
+                               CPML_regions, ier)
+      call adios_schedule_read(handle, sel, "CPML_to_spec/array", 0, 1, &
+                               CPML_to_spec, ier)
+
+      start(1) = local_dim_is_cpml * myrank
+      count_ad(1) = NSPEC_AB
+      sel_num = sel_num+1
+      sel => selections(sel_num)
+      call adios_selection_boundingbox (sel , 1, start, count_ad)
+      call adios_schedule_read(handle, sel, "is_CPML/array", 0, 1, &
+                               is_CPML, ier)
+
+      start(1) = local_dim_d_store_x * myrank
+      count_ad(1) = NGLLX * NGLLY * NGLLZ * nspec_cpml
+      sel_num = sel_num+1
+      sel => selections(sel_num)
+      call adios_selection_boundingbox (sel , 1, start, count_ad)
+      call adios_schedule_read(handle, sel, "d_store_x/array", 0, 1, &
+                               d_store_x, ier)
+      call adios_schedule_read(handle, sel, "d_store_y/array", 0, 1, &
+                               d_store_y, ier)
+      call adios_schedule_read(handle, sel, "d_store_z/array", 0, 1, &
+                               d_store_z, ier)
+      call adios_schedule_read(handle, sel, "k_store_x/array", 0, 1, &
+                               k_store_x, ier)
+      call adios_schedule_read(handle, sel, "k_store_y/array", 0, 1, &
+                               k_store_y, ier)
+      call adios_schedule_read(handle, sel, "k_store_z/array", 0, 1, &
+                               k_store_z, ier)
+      call adios_schedule_read(handle, sel, "alpha_store/array", 0, 1, &
+                               alpha_store, ier)
+
+      if((SIMULATION_TYPE == 1 .and. SAVE_FORWARD) .or. SIMULATION_TYPE == 3) then
+        if(nglob_interface_PML_acoustic > 0) then
+          start(1) = local_dim_points_interface_PML_acoustic* myrank
+          count_ad(1) = nglob_interface_PML_acoustic
+          sel_num = sel_num+1
+          sel => selections(sel_num)
+          call adios_selection_boundingbox (sel , 1, start, count_ad)
+          call adios_schedule_read(handle, sel, &
+                                   "points_interface_PML_acoustic/array", &
+                                   0, 1, points_interface_PML_acoustic , ier)
+        endif
+        if(nglob_interface_PML_elastic > 0) then
+          start(1) = local_dim_points_interface_PML_elastic* myrank
+          count_ad(1) = nglob_interface_PML_elastic
+          sel_num = sel_num+1
+          sel => selections(sel_num)
+          call adios_selection_boundingbox (sel , 1, start, count_ad)
+          call adios_schedule_read(handle, sel, &
+                                   "points_interface_PML_elastic/array", &
+                                   0, 1, points_interface_PML_elastic , ier)
+        endif
+      endif
+    endif
+  endif
+
+  if(PML_CONDITIONS)then
+     if( num_abs_boundary_faces > 0 ) then
+        start(1) = local_dim_abs_boundary_ispec * myrank
+        count_ad(1) = num_abs_boundary_faces
+        sel_num = sel_num+1
+        sel => selections(sel_num)
+        call adios_selection_boundingbox (sel , 1, start, count_ad)
+        call adios_schedule_read(handle, sel, "abs_boundary_ispec/array", &
+                                 0, 1, abs_boundary_ispec, ier)
+
+        start(1) = local_dim_abs_boundary_ijk * myrank
+        count_ad(1) = 3 * NGLLSQUARE * num_abs_boundary_faces
+        sel_num = sel_num+1
+        sel => selections(sel_num)
+        call adios_selection_boundingbox (sel , 1, start, count_ad)
+        call adios_schedule_read(handle, sel, "abs_boundary_ijk/array", &
+                                 0, 1, abs_boundary_ijk, ier)
+
+        start(1) = local_dim_abs_boundary_jacobian2Dw * myrank
+        count_ad(1) = NGLLSQUARE * num_abs_boundary_faces
+        sel_num = sel_num+1
+        sel => selections(sel_num)
+        call adios_selection_boundingbox (sel , 1, start, count_ad)
+        call adios_schedule_read(handle, sel, "abs_boundary_jacobian2Dw/array", &
+                                 0, 1, abs_boundary_jacobian2Dw, ier)
+
+        start(1) = local_dim_abs_boundary_normal * myrank
+        count_ad(1) = NDIM * NGLLSQUARE * num_abs_boundary_faces
+        sel_num = sel_num+1
+        sel => selections(sel_num)
+        call adios_selection_boundingbox (sel , 1, start, count_ad)
+        call adios_schedule_read(handle, sel, "abs_boundary_normal/array", &
+                                 0, 1, abs_boundary_normal, ier)
+     endif
+  else
+     if( num_abs_boundary_faces > 0 ) then
+        start(1) = local_dim_abs_boundary_ispec * myrank
+        count_ad(1) = num_abs_boundary_faces
+        sel_num = sel_num+1
+        sel => selections(sel_num)
+        call adios_selection_boundingbox (sel , 1, start, count_ad)
+        call adios_schedule_read(handle, sel, "abs_boundary_ispec/array", &
+                                 0, 1, abs_boundary_ispec, ier)
+
+        start(1) = local_dim_abs_boundary_ijk * myrank
+        count_ad(1) = 3 * NGLLSQUARE * num_abs_boundary_faces
+        sel_num = sel_num+1
+        sel => selections(sel_num)
+        call adios_selection_boundingbox (sel , 1, start, count_ad)
+        call adios_schedule_read(handle, sel, "abs_boundary_ijk/array", &
+                                 0, 1, abs_boundary_ijk, ier)
+
+        start(1) = local_dim_abs_boundary_jacobian2Dw * myrank
+        count_ad(1) = NGLLSQUARE * num_abs_boundary_faces
+        sel_num = sel_num+1
+        sel => selections(sel_num)
+        call adios_selection_boundingbox (sel , 1, start, count_ad)
+        call adios_schedule_read(handle, sel, "abs_boundary_jacobian2Dw/array", &
+                                 0, 1, abs_boundary_jacobian2Dw, ier)
+
+        start(1) = local_dim_abs_boundary_normal * myrank
+        count_ad(1) = NDIM * NGLLSQUARE * num_abs_boundary_faces
+        sel_num = sel_num+1
+        sel => selections(sel_num)
+        call adios_selection_boundingbox (sel , 1, start, count_ad)
+        call adios_schedule_read(handle, sel, "abs_boundary_normal/array", &
+                                 0, 1, abs_boundary_normal, ier)
+
+       if( STACEY_ABSORBING_CONDITIONS ) then
+          ! store mass matrix contributions
+          if(ELASTIC_SIMULATION) then
+            start(1) = local_dim_rmassx * myrank
+            count_ad(1) = NGLOB_AB  ! == nglob_xy in generate_databse
+            sel_num = sel_num+1
+            sel => selections(sel_num)
+            call adios_selection_boundingbox (sel , 1, start, count_ad)
+            call adios_schedule_read(handle, sel, "rmassx/array", 0, 1, &
+                                     rmassx, ier)
+            call adios_schedule_read(handle, sel, "rmassy/array", 0, 1, &
+                                     rmassy, ier)
+            call adios_schedule_read(handle, sel, "rmassz/array", 0, 1, &
+                                     rmassz, ier)
+          endif
+          if(ACOUSTIC_SIMULATION) then
+            start(1) = local_dim_rmassz_acoustic * myrank
+            count_ad(1) = NGLOB_AB ! == nglob_xy in generate_databse 
+            sel_num = sel_num+1
+            sel => selections(sel_num)
+            call adios_selection_boundingbox (sel , 1, start, count_ad)
+            call adios_schedule_read(handle, sel, "rmassx/array", 0, 1, &
+                                     rmassx, ier)
+            call adios_schedule_read(handle, sel, "rmassy/array", 0, 1, &
+                                     rmassy, ier)
+            call adios_schedule_read(handle, sel, "rmassz_acoustic/array", &
+                                     0, 1, rmassz_acoustic, ier)
+          endif
+       endif
+     endif
+  endif
+
+  start(1) = local_dim_ibelm_xmin * myrank
+  count_ad(1) = nspec2D_xmin 
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count_ad)
+  call adios_schedule_read(handle, sel, "ibelm_xmin/array", 0, 1, &
+                           ibelm_xmin, ier)
+
+  start(1) = local_dim_ibelm_xmax * myrank
+  count_ad(1) = nspec2D_xmax 
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count_ad)
+  call adios_schedule_read(handle, sel, "ibelm_xmax/array", 0, 1, &
+                           ibelm_xmax, ier)
+
+  start(1) = local_dim_ibelm_ymin * myrank
+  count_ad(1) = nspec2D_ymin 
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count_ad)
+  call adios_schedule_read(handle, sel, "ibelm_ymin/array", 0, 1, &
+                           ibelm_ymin, ier)
+
+  start(1) = local_dim_ibelm_ymax * myrank
+  count_ad(1) = nspec2D_ymax 
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count_ad)
+  call adios_schedule_read(handle, sel, "ibelm_ymax/array", 0, 1, &
+                           ibelm_ymax, ier)
+
+  start(1) = local_dim_ibelm_bottom * myrank
+  count_ad(1) = nspec2D_bottom 
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count_ad)
+  call adios_schedule_read(handle, sel, "ibelm_bottom/array", 0, 1, &
+                           ibelm_bottom, ier)
+
+  start(1) = local_dim_ibelm_top * myrank
+  count_ad(1) = nspec2D_top 
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count_ad)
+  call adios_schedule_read(handle, sel, "ibelm_top/array", 0, 1, &
+                           ibelm_top, ier)
+
+  ! free surface
+  if( num_free_surface_faces > 0 ) then
+
+    start(1) = local_dim_free_surface_ispec * myrank
+    count_ad(1) = num_free_surface_faces
+    sel_num = sel_num+1
+    sel => selections(sel_num)
+    call adios_selection_boundingbox (sel , 1, start, count_ad)
+    call adios_schedule_read(handle, sel, "free_surface_ispec/array", 0, 1, &
+                             free_surface_ispec, ier)
+
+    start(1) = local_dim_free_surface_ijk * myrank
+    count_ad(1) = 3 * NGLLSQUARE * num_free_surface_faces
+    sel_num = sel_num+1
+    sel => selections(sel_num)
+    call adios_selection_boundingbox (sel , 1, start, count_ad)
+    call adios_schedule_read(handle, sel, "free_surface_ijk/array", 0, 1, &
+                             free_surface_ijk, ier)
+
+    start(1) = local_dim_free_surface_ijk* myrank
+    count_ad(1) = NGLLSQUARE * num_free_surface_faces
+    sel_num = sel_num+1
+    sel => selections(sel_num)
+    call adios_selection_boundingbox (sel , 1, start, count_ad)
+    call adios_schedule_read(handle, sel, "free_surface_ijk/array", 0, 1, &
+                             free_surface_ijk, ier)
+
+    start(1) = local_dim_free_surface_normal * myrank
+    count_ad(1) = NDIM * NGLLSQUARE * num_free_surface_faces
+    sel_num = sel_num+1
+    sel => selections(sel_num)
+    call adios_selection_boundingbox (sel , 1, start, count_ad)
+    call adios_schedule_read(handle, sel, "free_surface_normal/array", 0, 1, &
+                             free_surface_normal, ier)
+  endif
+
+  ! acoustic-elastic coupling surface
+  if( num_coupling_ac_el_faces > 0 ) then
+
+    start(1) = local_dim_coupling_ac_el_ispec * myrank
+    count_ad(1) = num_coupling_ac_el_faces
+    sel_num = sel_num+1
+    sel => selections(sel_num)
+    call adios_selection_boundingbox (sel , 1, start, count_ad)
+    call adios_schedule_read(handle, sel, "coupling_ac_el_ispec/array", 0, 1, &
+                             coupling_ac_el_ispec, ier)
+
+    start(1) = local_dim_coupling_ac_el_ijk * myrank
+    count_ad(1) = 3 * NGLLSQUARE * num_coupling_ac_el_faces
+    sel_num = sel_num+1
+    sel => selections(sel_num)
+    call adios_selection_boundingbox (sel , 1, start, count_ad)
+    call adios_schedule_read(handle, sel, "coupling_ac_el_ijk/array", 0, 1, &
+                             coupling_ac_el_ijk, ier)
+
+    start(1) = local_dim_coupling_ac_el_jacobian2Dw * myrank
+    count_ad(1) = NGLLSQUARE * num_coupling_ac_el_faces
+    sel_num = sel_num+1
+    sel => selections(sel_num)
+    call adios_selection_boundingbox (sel , 1, start, count_ad)
+    call adios_schedule_read(handle, sel, "coupling_ac_el_jacobian2Dw/array", 0, 1, &
+                             coupling_ac_el_jacobian2Dw, ier)
+    start(1) = local_dim_coupling_ac_el_normal * myrank
+    count_ad(1) = NDIM * NGLLSQUARE * num_coupling_ac_el_faces
+    sel_num = sel_num+1
+    sel => selections(sel_num)
+    call adios_selection_boundingbox (sel , 1, start, count_ad)
+    call adios_schedule_read(handle, sel, "coupling_ac_el_normal/array", 0, 1, &
+                             coupling_ac_el_normal, ier)
+  endif
+
+  ! acoustic-poroelastic coupling surface
+  if( num_coupling_ac_po_faces > 0 ) then
+
+    start(1) = local_dim_coupling_ac_po_ispec * myrank
+    count_ad(1) = num_coupling_ac_po_faces
+    sel_num = sel_num+1
+    sel => selections(sel_num)
+    call adios_selection_boundingbox (sel , 1, start, count_ad)
+    call adios_schedule_read(handle, sel, "coupling_ac_po_ispec/array", 0, 1, &
+                             coupling_ac_po_ispec, ier)
+
+    start(1) = local_dim_coupling_ac_po_ijk * myrank
+    count_ad(1) = 3 * NGLLSQUARE * num_coupling_ac_po_faces
+    sel_num = sel_num+1
+    sel => selections(sel_num)
+    call adios_selection_boundingbox (sel , 1, start, count_ad)
+    call adios_schedule_read(handle, sel, "coupling_ac_po_ijk/array", 0, 1, &
+                             coupling_ac_po_ijk, ier)
+
+    start(1) = local_dim_coupling_ac_po_jacobian2Dw * myrank
+    count_ad(1) = NGLLSQUARE * num_coupling_ac_po_faces
+    sel_num = sel_num+1
+    sel => selections(sel_num)
+    call adios_selection_boundingbox (sel , 1, start, count_ad)
+    call adios_schedule_read(handle, sel, "coupling_ac_po_jacobian2Dw/array", 0, 1, &
+                             coupling_ac_po_jacobian2Dw, ier)
+
+    start(1) = local_dim_coupling_ac_po_normal * myrank
+    count_ad(1) = NDIM * NGLLSQUARE * num_coupling_ac_po_faces
+    sel_num = sel_num+1
+    sel => selections(sel_num)
+    call adios_selection_boundingbox (sel , 1, start, count_ad)
+    call adios_schedule_read(handle, sel, "coupling_ac_po_normal/array", 0, 1, &
+                             coupling_ac_po_normal, ier)
+  endif
+
+  ! elastic-poroelastic coupling surface
+  if( num_coupling_el_po_faces > 0 ) then
+
+    start(1) = local_dim_coupling_el_po_ispec * myrank
+    count_ad(1) = num_coupling_el_po_faces
+    sel_num = sel_num+1
+    sel => selections(sel_num)
+    call adios_selection_boundingbox (sel , 1, start, count_ad)
+    call adios_schedule_read(handle, sel, "coupling_el_po_ispec/array", 0, 1, &
+                             coupling_el_po_ispec, ier)
+    call adios_schedule_read(handle, sel, "coupling_po_el_ispec/array", 0, 1, &
+                             coupling_po_el_ispec, ier)
+
+    start(1) = local_dim_coupling_el_po_ijk * myrank
+    count_ad(1) = 3 * NGLLSQUARE * num_coupling_el_po_faces
+    sel_num = sel_num+1
+    sel => selections(sel_num)
+    call adios_selection_boundingbox (sel , 1, start, count_ad)
+    call adios_schedule_read(handle, sel, "coupling_el_po_ijk/array", 0, 1, &
+                             coupling_el_po_ijk, ier)
+    call adios_schedule_read(handle, sel, "coupling_po_el_ijk/array", 0, 1, &
+                             coupling_po_el_ijk, ier)
+
+    start(1) = local_dim_coupling_el_po_jacobian2Dw * myrank
+    count_ad(1) = NGLLSQUARE * num_coupling_el_po_faces
+    sel_num = sel_num+1
+    sel => selections(sel_num)
+    call adios_selection_boundingbox (sel , 1, start, count_ad)
+    call adios_schedule_read(handle, sel, "coupling_el_po_jacobian2Dw/array", 0, 1, &
+                             coupling_el_po_jacobian2Dw, ier)
+
+    start(1) = local_dim_coupling_el_po_normal * myrank
+    count_ad(1) = NDIM * NGLLSQUARE * num_coupling_el_po_faces
+    sel_num = sel_num+1
+    sel => selections(sel_num)
+    call adios_selection_boundingbox (sel , 1, start, count_ad)
+    call adios_schedule_read(handle, sel, "coupling_el_po_normal/array", 0, 1, &
+                             coupling_el_po_normal, ier)
+  endif
+
+  ! MPI interfaces
+  if( num_interfaces_ext_mesh > 0 ) then
+    start(1) = local_dim_my_neighbours_ext_mesh * myrank
+    count_ad(1) = num_interfaces_ext_mesh
+    sel_num = sel_num+1
+    sel => selections(sel_num)
+    call adios_selection_boundingbox (sel , 1, start, count_ad)
+    call adios_schedule_read(handle, sel, "my_neighbours_ext_mesh/array", 0, 1, &
+                             my_neighbours_ext_mesh, ier)
+    call adios_schedule_read(handle, sel, "nibool_interfaces_ext_mesh/array", 0, 1, &
+                             nibool_interfaces_ext_mesh, ier)
+
+    start(1) = local_dim_ibool_interfaces_ext_mesh * myrank
+    count_ad(1) = max_nibool_interfaces_ext_mesh * num_interfaces_ext_mesh
+    sel_num = sel_num+1
+    sel => selections(sel_num)
+    call adios_selection_boundingbox (sel , 1, start, count_ad)
+    call adios_schedule_read(handle, sel, "ibool_interfaces_ext_mesh_dummy/array", 0, 1, &
+                             ibool_interfaces_ext_mesh, ier)
+  endif
+
+  if( ELASTIC_SIMULATION .and. ANISOTROPY ) then
+    start(1) = local_dim_c11store * myrank
+    count_ad(1) = NGLLX * NGLLY * NGLLZ * nspec_aniso
+    sel_num = sel_num+1
+    sel => selections(sel_num)
+    call adios_selection_boundingbox (sel , 1, start, count_ad)
+    call adios_schedule_read(handle, sel, "c11store/array", 0, 1, &
+                             c11store, ier)
+    call adios_schedule_read(handle, sel, "c12store/array", 0, 1, &
+                             c12store, ier)
+    call adios_schedule_read(handle, sel, "c13store/array", 0, 1, &
+                             c13store, ier)
+    call adios_schedule_read(handle, sel, "c14store/array", 0, 1, &
+                             c14store, ier)
+    call adios_schedule_read(handle, sel, "c15store/array", 0, 1, &
+                             c15store, ier)
+    call adios_schedule_read(handle, sel, "c16store/array", 0, 1, &
+                             c16store, ier)
+    call adios_schedule_read(handle, sel, "c22store/array", 0, 1, &
+                             c22store, ier)
+    call adios_schedule_read(handle, sel, "c23store/array", 0, 1, &
+                             c23store, ier)
+    call adios_schedule_read(handle, sel, "c24store/array", 0, 1, &
+                             c24store, ier)
+    call adios_schedule_read(handle, sel, "c25store/array", 0, 1, &
+                             c25store, ier)
+    call adios_schedule_read(handle, sel, "c26store/array", 0, 1, &
+                             c26store, ier)
+    call adios_schedule_read(handle, sel, "c33store/array", 0, 1, &
+                             c33store, ier)
+    call adios_schedule_read(handle, sel, "c34store/array", 0, 1, &
+                             c34store, ier)
+    call adios_schedule_read(handle, sel, "c35store/array", 0, 1, &
+                             c35store, ier)
+    call adios_schedule_read(handle, sel, "c36store/array", 0, 1, &
+                             c36store, ier)
+    call adios_schedule_read(handle, sel, "c44store/array", 0, 1, &
+                             c44store, ier)
+    call adios_schedule_read(handle, sel, "c45store/array", 0, 1, &
+                             c45store, ier)
+    call adios_schedule_read(handle, sel, "c46store/array", 0, 1, &
+                             c46store, ier)
+    call adios_schedule_read(handle, sel, "c55store/array", 0, 1, &
+                             c55store, ier)
+    call adios_schedule_read(handle, sel, "c56store/array", 0, 1, &
+                             c56store, ier)
+    call adios_schedule_read(handle, sel, "c66store/array", 0, 1, &
+                             c66store, ier)
+  endif
+
+  ! inner / outer elements
+  start(1) = local_dim_ispec_is_inner * myrank
+  count_ad(1) = NSPEC_AB 
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count_ad)
+  call adios_schedule_read(handle, sel, "ispec_is_inner/array", 0, 1, &
+                           ispec_is_inner, ier)
+
+  if( ACOUSTIC_SIMULATION ) then
+    if(num_phase_ispec_acoustic > 0 ) then
+      start(1) = local_dim_phase_ispec_inner_acoustic * myrank
+      count_ad(1) = num_phase_ispec_acoustic * 2
+      sel_num = sel_num+1
+      sel => selections(sel_num)
+      call adios_selection_boundingbox (sel , 1, start, count_ad)
+      call adios_schedule_read(handle, sel, "phase_ispec_inner_acoustic/array", 0, 1, &
+                               phase_ispec_inner_acoustic, ier)
+    endif
+  endif
+
+  if( ELASTIC_SIMULATION ) then
+    if(num_phase_ispec_elastic > 0 ) then
+      start(1) = local_dim_phase_ispec_inner_elastic * myrank
+      count_ad(1) = num_phase_ispec_elastic * 2
+      sel_num = sel_num+1
+      sel => selections(sel_num)
+      call adios_selection_boundingbox (sel , 1, start, count_ad)
+      call adios_schedule_read(handle, sel, "phase_ispec_inner_elastic/array", 0, 1, &
+                               phase_ispec_inner_elastic, ier)
+    endif
+  endif
+
+  if( POROELASTIC_SIMULATION ) then
+    if(num_phase_ispec_poroelastic > 0 ) then
+      start(1) = local_dim_phase_ispec_inner_poroelastic * myrank
+      count_ad(1) = num_phase_ispec_poroelastic * 2
+      sel_num = sel_num+1
+      sel => selections(sel_num)
+      call adios_selection_boundingbox (sel , 1, start, count_ad)
+      call adios_schedule_read(handle, sel, "phase_ispec_inner_poroelastic/array", 0, 1, &
+                               phase_ispec_inner_poroelastic, ier)
+    endif
+  endif
+
+  ! mesh coloring for GPUs
+  if( USE_MESH_COLORING_GPU ) then
+    ! acoustic domain colors
+    if( ACOUSTIC_SIMULATION ) then
+      start(1) = local_dim_num_elem_colors_acoustic * myrank
+      count_ad(1) = num_colors_outer_acoustic + num_colors_inner_acoustic
+      sel_num = sel_num+1
+      sel => selections(sel_num)
+      call adios_selection_boundingbox (sel , 1, start, count_ad)
+      call adios_schedule_read(handle, sel, "num_elem_colors_acoustic/array", 0, 1, &
+                               num_elem_colors_acoustic, ier)
+    endif
+    ! elastic domain colors
+    if( ELASTIC_SIMULATION ) then
+      start(1) = local_dim_num_elem_colors_elastic * myrank
+      count_ad(1) = num_colors_outer_elastic + num_colors_inner_elastic
+      sel_num = sel_num+1
+      sel => selections(sel_num)
+      call adios_selection_boundingbox (sel , 1, start, count_ad)
+      call adios_schedule_read(handle, sel, "num_elem_colors_elastic/array", 0, 1, &
+                               num_elem_colors_elastic, ier)
+    endif
+  endif
+
+  !---------------------------------------------------------------.
+  ! Perform the reads and close the ADIOS 'external_mesh.bp' file |
+  !---------------------------------------------------------------'
+  call adios_perform_reads(handle, ier)
+  call adios_read_close(handle,ier)
+  call adios_read_finalize_method(ADIOS_READ_METHOD_BP, ier)
+
+  !call read_mesh_databases2()
+  !call check_mesh_database()
+
+  ! debug
+  !call sum_all_i(num_interfaces_ext_mesh,inum)
+  !if(myrank == 0) then
+  !  write(IMAIN,*) 'number of MPI partition interfaces: ',inum
+  !  write(IMAIN,*)
+  !endif
+
+  ! MPI communications
+  allocate(buffer_send_vector_ext_mesh(NDIM,max_nibool_interfaces_ext_mesh,num_interfaces_ext_mesh), &
+    buffer_recv_vector_ext_mesh(NDIM,max_nibool_interfaces_ext_mesh,num_interfaces_ext_mesh), &
+    buffer_send_scalar_ext_mesh(max_nibool_interfaces_ext_mesh,num_interfaces_ext_mesh), &
+    buffer_recv_scalar_ext_mesh(max_nibool_interfaces_ext_mesh,num_interfaces_ext_mesh), &
+    request_send_vector_ext_mesh(num_interfaces_ext_mesh), &
+    request_recv_vector_ext_mesh(num_interfaces_ext_mesh), &
+    request_send_scalar_ext_mesh(num_interfaces_ext_mesh), &
+    request_recv_scalar_ext_mesh(num_interfaces_ext_mesh), &
+    buffer_send_vector_ext_mesh_s(NDIM,max_nibool_interfaces_ext_mesh,num_interfaces_ext_mesh), &
+    buffer_recv_vector_ext_mesh_s(NDIM,max_nibool_interfaces_ext_mesh,num_interfaces_ext_mesh), &
+    buffer_send_vector_ext_mesh_w(NDIM,max_nibool_interfaces_ext_mesh,num_interfaces_ext_mesh), &
+    buffer_recv_vector_ext_mesh_w(NDIM,max_nibool_interfaces_ext_mesh,num_interfaces_ext_mesh), &
+    request_send_vector_ext_mesh_s(num_interfaces_ext_mesh), &
+    request_recv_vector_ext_mesh_s(num_interfaces_ext_mesh), &
+    request_send_vector_ext_mesh_w(num_interfaces_ext_mesh), &
+    request_recv_vector_ext_mesh_w(num_interfaces_ext_mesh),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array buffer_send_vector_ext_mesh etc.'
+
+  ! gets model dimensions
+  minl = minval( xstore )
+  maxl = maxval( xstore )
+  call min_all_all_cr(minl,min_all)
+  call max_all_all_cr(maxl,max_all)
+  LONGITUDE_MIN = min_all
+  LONGITUDE_MAX = max_all
+
+  minl = minval( ystore )
+  maxl = maxval( ystore )
+  call min_all_all_cr(minl,min_all)
+  call max_all_all_cr(maxl,max_all)
+  LATITUDE_MIN = min_all
+  LATITUDE_MAX = max_all
+
+  ! checks courant criteria on mesh
+  if( ELASTIC_SIMULATION ) then
+    call check_mesh_resolution(myrank,NSPEC_AB,NGLOB_AB, &
+                              ibool,xstore,ystore,zstore, &
+                              kappastore,mustore,rho_vp,rho_vs, &
+                              DT,model_speed_max,min_resolved_period, &
+                              LOCAL_PATH,SAVE_MESH_FILES)
+
+  else if( POROELASTIC_SIMULATION ) then
+    allocate(rho_vp(NGLLX,NGLLY,NGLLZ,NSPEC_AB))
+    allocate(rho_vs(NGLLX,NGLLY,NGLLZ,NSPEC_AB))
+    rho_vp = 0.0_CUSTOM_REAL
+    rho_vs = 0.0_CUSTOM_REAL
+    call check_mesh_resolution_poro(myrank,NSPEC_AB,NGLOB_AB,ibool,xstore,ystore,zstore, &
+                                    DT,model_speed_max,min_resolved_period, &
+                                    phistore,tortstore,rhoarraystore,rho_vpI,rho_vpII,rho_vsI, &
+                                    LOCAL_PATH,SAVE_MESH_FILES)
+    deallocate(rho_vp,rho_vs)
+  else if( ACOUSTIC_SIMULATION ) then
+    allocate(rho_vp(NGLLX,NGLLY,NGLLZ,NSPEC_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array rho_vp'
+    allocate(rho_vs(NGLLX,NGLLY,NGLLZ,NSPEC_AB),stat=ier)
+    if( ier /= 0 ) stop 'error allocating array rho_vs'
+    rho_vp = sqrt( kappastore / rhostore ) * rhostore
+    rho_vs = 0.0_CUSTOM_REAL
+    call check_mesh_resolution(myrank,NSPEC_AB,NGLOB_AB, &
+                              ibool,xstore,ystore,zstore, &
+                              kappastore,mustore,rho_vp,rho_vs, &
+                              DT,model_speed_max,min_resolved_period, &
+                              LOCAL_PATH,SAVE_MESH_FILES)
+    deallocate(rho_vp,rho_vs)
+  endif
+
+  ! reads adjoint parameters
+  call read_mesh_databases_adjoint()
+
+end subroutine read_mesh_databases_adios
+
+
+!-------------------------------------------------------------------------------
+!> Reads in moho meshes
+subroutine read_moho_mesh_adjoint_adios()
+  use mpi
+  use adios_read_mod
+
+  use specfem_par
+  use specfem_par_elastic
+  use specfem_par_acoustic
+  use specfem_par_poroelastic
+  implicit none
+
+  character(len=256) :: database_name
+  integer(kind=8) :: handle
+
+  integer(kind=8), dimension(256),target :: selections
+  integer :: sel_num
+  integer(kind=8), pointer :: sel => null()
+  integer(kind=8), dimension(1) :: start, count_ad
+
+  integer :: local_dim_ibelm_moho_bot,  local_dim_ibelm_moho_top,  &
+             local_dim_ijk_moho_bot,    local_dim_ijk_moho_top,    &
+             local_dim_normal_moho_bot, local_dim_normal_moho_top, &
+             local_dim_is_moho_bot,     local_dim_is_moho_top
+
+  integer :: ier
+
+  !-------------------------------------.
+  ! Open ADIOS Database file, read mode |
+  !-------------------------------------'
+  sel_num = 0             
+
+  database_name = adjustl(LOCAL_PATH)
+  database_name = database_name(1:len_trim(database_name)) // "/moho.bp"
+
+  call adios_read_init_method (ADIOS_READ_METHOD_BP, MPI_COMM_WORLD, &
+                               "verbose=1", ier)
+  call adios_read_open_file (handle, database_name, 0, MPI_COMM_WORLD, ier)
+
+  !------------------------------------------------------------------.
+  ! Get scalar values. Might be differents for different processors. |
+  ! Hence the selection writeblock.                                  |
+  ! ONLY NSPEC_AB and NGLOB_AB
+  !------------------------------------------------------------------'
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_writeblock(sel, myrank)
+  call adios_schedule_read(handle, sel, "/nspec2d_moho", 0, 1, &
+                           NSPEC2D_MOHO, ier)
+  call adios_perform_reads(handle, ier)
+
+  !----------------------------------------------.
+  ! Fetch values to compute the simulation type. |
+  !----------------------------------------------'
+  sel_num = 0             
+  call adios_get_scalar(handle, "ibelm_moho_bot/local_dim",&
+                        local_dim_ibelm_moho_bot ,ier)
+  call adios_get_scalar(handle, "ibelm_moho_top/local_dim",&
+                        local_dim_ibelm_moho_top ,ier)
+
+  call adios_get_scalar(handle, "ijk_moho_bot/local_dim",&
+                        local_dim_ijk_moho_bot ,ier)
+  call adios_get_scalar(handle, "ijk_moho_top/local_dim",&
+                        local_dim_ijk_moho_top ,ier)
+
+  call adios_get_scalar(handle,"normal_moho_bot /local_dim",&
+                        local_dim_normal_moho_bot ,ier)
+  call adios_get_scalar(handle, "normal_moho_top/local_dim",&
+                        local_dim_normal_moho_top ,ier)
+
+  call adios_get_scalar(handle, "is_moho_bot/local_dim",&
+                        local_dim_is_moho_bot ,ier)
+  call adios_get_scalar(handle, "is_moho_top/local_dim",&
+                        local_dim_is_moho_top ,ier)
+
+  !---------------------------------------------.
+  ! Allocate arrays with previously read values |
+  !---------------------------------------------'
+  allocate(ibelm_moho_bot(NSPEC2D_MOHO), &
+          ibelm_moho_top(NSPEC2D_MOHO), &
+          normal_moho_top(NDIM,NGLLSQUARE,NSPEC2D_MOHO), &
+          normal_moho_bot(NDIM,NGLLSQUARE,NSPEC2D_MOHO), &
+          ijk_moho_bot(3,NGLLSQUARE,NSPEC2D_MOHO), &
+          ijk_moho_top(3,NGLLSQUARE,NSPEC2D_MOHO),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array ibelm_moho_bot etc.'
+
+  !-----------------------------------.
+  ! Read arrays from external_mesh.bp |
+  !-----------------------------------'
+  start(1) = local_dim_ibelm_moho_bot * myrank
+  count_ad(1) = NSPEC2D_MOHO
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count_ad)
+  call adios_schedule_read(handle, sel, "ibelm_moho_bot/array", 0, 1, &
+                           ibelm_moho_bot, ier)
+  start(1) = local_dim_ibelm_moho_top * myrank
+  count_ad(1) = NSPEC2D_MOHO
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count_ad)
+  call adios_schedule_read(handle, sel, "ibelm_moho_top/array", 0, 1, &
+                           ibelm_moho_top, ier)
+
+  start(1) = local_dim_ijk_moho_bot * myrank
+  count_ad(1) = 3 * NGLLSQUARE * NSPEC2D_MOHO
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count_ad)
+  call adios_schedule_read(handle, sel, "ijk_moho_bot/array", 0, 1, &
+                           ijk_moho_bot, ier)
+  start(1) = local_dim_ijk_moho_top * myrank
+  count_ad(1) = 3 * NGLLSQUARE * NSPEC2D_MOHO
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count_ad)
+  call adios_schedule_read(handle, sel, "ijk_moho_top/array", 0, 1, &
+                           ijk_moho_top, ier)
+
+  start(1) = local_dim_normal_moho_bot * myrank
+  count_ad(1) = NDIM * NGLLSQUARE * NSPEC2D_MOHO
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count_ad)
+  call adios_schedule_read(handle, sel, "normal_moho_bot/array", 0, 1, &
+                           normal_moho_bot, ier)
+  start(1) = local_dim_normal_moho_top * myrank
+  count_ad(1) = NDIM * NGLLSQUARE * NSPEC2D_MOHO
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count_ad)
+  call adios_schedule_read(handle, sel, "normal_moho_top/array", 0, 1, &
+                           normal_moho_top, ier)
+
+  start(1) = local_dim_is_moho_bot * myrank
+  count_ad(1) = NSPEC_AB
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count_ad)
+  call adios_schedule_read(handle, sel, "is_moho_bot/array", 0, 1, &
+                           is_moho_bot, ier)
+  start(1) = local_dim_is_moho_top * myrank
+  count_ad(1) = NSPEC_AB
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count_ad)
+  call adios_schedule_read(handle, sel, "is_moho_top/array", 0, 1, &
+                           is_moho_top, ier)
+
+  !---------------------------------------------------------------.
+  ! Perform the reads and close the ADIOS 'external_mesh.bp' file |
+  !---------------------------------------------------------------'
+  call adios_perform_reads(handle, ier)
+  call adios_read_close(handle,ier)
+  call adios_read_finalize_method(ADIOS_READ_METHOD_BP, ier)
+
+end subroutine read_moho_mesh_adjoint_adios

Modified: seismo/3D/SPECFEM3D/trunk/src/specfem3D/save_adjoint_kernels.f90
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/specfem3D/save_adjoint_kernels.f90	2013-09-17 22:36:21 UTC (rev 22797)
+++ seismo/3D/SPECFEM3D/trunk/src/specfem3D/save_adjoint_kernels.f90	2013-09-18 14:35:14 UTC (rev 22798)
@@ -26,52 +26,54 @@
 !
 ! United States and French Government Sponsorship Acknowledged.
 
-  subroutine save_adjoint_kernels()
 
+!==============================================================================
+! \file save_adjoint_kernels
+!
+! TODO   
+! * Better doxygen documentation.
+! * Change '27' for IOUT as in Daniel modification
+!==============================================================================
+
+
+!==============================================================================
+!> Save kernels.
+subroutine save_adjoint_kernels()
+
   use specfem_par
   use specfem_par_acoustic
   use specfem_par_elastic
   use specfem_par_poroelastic
 
   implicit none
-  ! local parameters
-  integer:: ispec,i,j,k,ier
-  real(kind=CUSTOM_REAL), dimension(:,:,:,:), allocatable :: weights_kernel
 
+  integer(kind=8) :: adios_handle
+
   ! flag to save GLL weights
   logical,parameter :: SAVE_WEIGHTS = .false.
 
+  if (ADIOS_FOR_KERNELS) then
+    call define_kernel_adios_variables(adios_handle, SAVE_WEIGHTS)
+  endif
+
   ! acoustic domains
   if( ACOUSTIC_SIMULATION ) then
-    call save_kernels_acoustic()
+    call save_kernels_acoustic(adios_handle)
   endif
 
   ! elastic domains
   if( ELASTIC_SIMULATION ) then
-    call save_kernels_elastic()
+    call save_kernels_elastic(adios_handle)
   endif
 
   if( POROELASTIC_SIMULATION ) then
-    call save_kernels_poroelastic()
+    call save_kernels_poroelastic(adios_handle)
   endif
 
-  ! save weights for volume integration, in order to benchmark the kernels with analytical expressions
+  ! save weights for volume integration, 
+  ! in order to benchmark the kernels with analytical expressions
   if( SAVE_WEIGHTS ) then
-    allocate(weights_kernel(NGLLX,NGLLY,NGLLZ,NSPEC_AB),stat=ier)
-    if( ier /= 0 ) stop 'error allocating array weights_kernel'
-    do ispec = 1, NSPEC_AB
-        do k = 1, NGLLZ
-          do j = 1, NGLLY
-            do i = 1, NGLLX
-              weights_kernel(i,j,k,ispec) = wxgll(i) * wygll(j) * wzgll(k) * jacobian(i,j,k,ispec)
-            enddo ! i
-          enddo ! j
-        enddo ! k
-    enddo ! ispec
-    open(unit=IOUT,file=prname(1:len_trim(prname))//'weights_kernel.bin',status='unknown',form='unformatted',iostat=ier)
-    if( ier /= 0 ) stop 'error opening file weights_kernel.bin'
-    write(IOUT) weights_kernel
-    close(IOUT)
+    call save_weights_kernel()
   endif
 
   ! for noise simulations --- noise strength kernel
@@ -81,21 +83,62 @@
 
   ! for preconditioner
   if ( APPROXIMATE_HESS_KL ) then
-    call save_kernels_hessian()
+    call save_kernels_hessian(adios_handle)
   endif
 
-  end subroutine save_adjoint_kernels
+  if (ADIOS_FOR_KERNELS) then
+    call perform_write_adios_kernels(adios_handle)
+  endif
 
-!
-!-------------------------------------------------------------------------------------------------
-!
+end subroutine save_adjoint_kernels
 
-  subroutine save_kernels_acoustic()
+!==============================================================================
+!> Save weights for volume integration, 
+!! in order to benchmark the kernels with analytical expressions.
+subroutine save_weights_kernel()
+  use specfem_par
+  use specfem_par_acoustic
+  use specfem_par_elastic
+  use specfem_par_poroelastic
 
+  implicit none
+
+  ! local parameters
+  integer:: ispec,i,j,k,ier
+  real(kind=CUSTOM_REAL), dimension(:,:,:,:), allocatable :: weights_kernel
+
+  allocate(weights_kernel(NGLLX,NGLLY,NGLLZ,NSPEC_AB),stat=ier)
+  if( ier /= 0 ) stop 'error allocating array weights_kernel'
+  do ispec = 1, NSPEC_AB
+      do k = 1, NGLLZ
+        do j = 1, NGLLY
+          do i = 1, NGLLX
+            weights_kernel(i,j,k,ispec) = wxgll(i) * wygll(j) * wzgll(k) * jacobian(i,j,k,ispec)
+          enddo ! i
+        enddo ! j
+      enddo ! k
+  enddo ! ispec
+
+  open(unit=27,file=prname(1:len_trim(prname))//'weights_kernel.bin',status='unknown',form='unformatted',iostat=ier)
+  if( ier /= 0 ) stop 'error opening file weights_kernel.bin'
+  write(27) weights_kernel
+  close(27)
+  
+  deallocate(weights_kernel,stat=ier)
+  if( ier /= 0 ) stop 'error allocating array weights_kernel'
+end subroutine save_weights_kernel
+
+!==============================================================================
+!> Save acoustic related kernels
+subroutine save_kernels_acoustic(adios_handle)
+
   use specfem_par
   use specfem_par_acoustic
 
   implicit none
+
+  integer(kind=8) :: adios_handle
+
   ! local parameters
   integer:: ispec,i,j,k,ier
 
@@ -122,40 +165,44 @@
 
   enddo
 
-  ! save kernels to binary files
-  open(unit=IOUT,file=prname(1:len_trim(prname))//'rho_acoustic_kernel.bin',status='unknown',form='unformatted',iostat=ier)
-  if( ier /= 0 ) stop 'error opening file rho_acoustic_kernel.bin'
-  write(IOUT) rho_ac_kl
-  close(IOUT)
+  if (ADIOS_FOR_KERNELS) then
+    call save_kernels_acoustic_adios(adios_handle)
+  else
+    ! save kernels to binary files
+    open(unit=27,file=prname(1:len_trim(prname))//'rho_acoustic_kernel.bin',status='unknown',form='unformatted',iostat=ier)
+    if( ier /= 0 ) stop 'error opening file rho_acoustic_kernel.bin'
+    write(27) rho_ac_kl
+    close(27)
 
-  open(unit=IOUT,file=prname(1:len_trim(prname))//'kappa_acoustic_kernel.bin',status='unknown',form='unformatted',iostat=ier)
-  if( ier /= 0 ) stop 'error opening file kappa_acoustic_kernel.bin'
-  write(IOUT) kappa_ac_kl
-  close(IOUT)
+    open(unit=27,file=prname(1:len_trim(prname))//'kappa_acoustic_kernel.bin',status='unknown',form='unformatted',iostat=ier)
+    if( ier /= 0 ) stop 'error opening file kappa_acoustic_kernel.bin'
+    write(27) kappa_ac_kl
+    close(27)
 
-  open(unit=IOUT,file=prname(1:len_trim(prname))//'rhop_acoustic_kernel.bin',status='unknown',form='unformatted',iostat=ier)
-  if( ier /= 0 ) stop 'error opening file rhop_acoustic_kernel.bin'
-  write(IOUT) rhop_ac_kl
-  close(IOUT)
+    open(unit=27,file=prname(1:len_trim(prname))//'rhop_acoustic_kernel.bin',status='unknown',form='unformatted',iostat=ier)
+    if( ier /= 0 ) stop 'error opening file rhop_acoustic_kernel.bin'
+    write(27) rhop_ac_kl
+    close(27)
 
-  open(unit=IOUT,file=prname(1:len_trim(prname))//'alpha_acoustic_kernel.bin',status='unknown',form='unformatted',iostat=ier)
-  if( ier /= 0 ) stop 'error opening file alpha_acoustic_kernel.bin'
-  write(IOUT) alpha_ac_kl
-  close(IOUT)
+    open(unit=27,file=prname(1:len_trim(prname))//'alpha_acoustic_kernel.bin',status='unknown',form='unformatted',iostat=ier)
+    if( ier /= 0 ) stop 'error opening file alpha_acoustic_kernel.bin'
+    write(27) alpha_ac_kl
+    close(27)
 
-  end subroutine save_kernels_acoustic
+  endif
+end subroutine save_kernels_acoustic
 
+!==============================================================================
+!> Save elastic related kernels
+subroutine save_kernels_elastic(adios_handle)
 
-!
-!-------------------------------------------------------------------------------------------------
-!
-
-  subroutine save_kernels_elastic()
-
   use specfem_par
   use specfem_par_elastic
 
   implicit none
+
+  integer(kind=8) :: adios_handle
+
   ! local parameters
   integer:: ispec,i,j,k,iglob,ier
   real(kind=CUSTOM_REAL) :: rhol,mul,kappal
@@ -313,84 +360,93 @@
 
   enddo
 
-  if( ANISOTROPIC_KL ) then
-    ! outputs transverse isotropic kernels only
-    if( SAVE_TRANSVERSE_KL ) then
-      ! transverse isotropic kernels
-      ! (alpha_v, alpha_h, beta_v, beta_h, eta, rho ) parameterization
-      open(unit=IOUT,file=trim(prname)//'alphav_kernel.bin',status='unknown',form='unformatted',action='write')
-      write(IOUT) alphav_kl
-      close(IOUT)
-      open(unit=IOUT,file=trim(prname)//'alphah_kernel.bin',status='unknown',form='unformatted',action='write')
-      write(IOUT) alphah_kl
-      close(IOUT)
-      open(unit=IOUT,file=trim(prname)//'betav_kernel.bin',status='unknown',form='unformatted',action='write')
-      write(IOUT) betav_kl
-      close(IOUT)
-      open(unit=IOUT,file=trim(prname)//'betah_kernel.bin',status='unknown',form='unformatted',action='write')
-      write(IOUT) betah_kl
-      close(IOUT)
-      open(unit=IOUT,file=trim(prname)//'eta_kernel.bin',status='unknown',form='unformatted',action='write')
-      write(IOUT) eta_kl
-      close(IOUT)
+  if (ADIOS_FOR_KERNELS) then
+    call save_kernels_elastic_adios(adios_handle)
+  else
+    if (ANISOTROPIC_KL) then
 
-      ! transverse isotropic test kernels
-      open(unit=IOUT,file=trim(prname)//'alpha_kernel.bin',status='unknown',form='unformatted',action='write')
-      write(IOUT) alpha_kl
-      close(IOUT)
-      open(unit=IOUT,file=trim(prname)//'beta_kernel.bin',status='unknown',form='unformatted',action='write')
-      write(IOUT) beta_kl
-      close(IOUT)
+       ! outputs transverse isotropic kernels only
+       if (SAVE_TRANSVERSE_KL) then
+         ! transverse isotropic kernels
+         ! (alpha_v, alpha_h, beta_v, beta_h, eta, rho ) parameterization
+         open(unit=27,file=trim(prname)//'alphav_kernel.bin',status='unknown',form='unformatted',action='write')
+         write(27) alphav_kl
+         close(27)
+         open(unit=27,file=trim(prname)//'alphah_kernel.bin',status='unknown',form='unformatted',action='write')
+         write(27) alphah_kl
+         close(27)
+         open(unit=27,file=trim(prname)//'betav_kernel.bin',status='unknown',form='unformatted',action='write')
+         write(27) betav_kl
+         close(27)
+         open(unit=27,file=trim(prname)//'betah_kernel.bin',status='unknown',form='unformatted',action='write')
+         write(27) betah_kl
+         close(27)
+         open(unit=27,file=trim(prname)//'eta_kernel.bin',status='unknown',form='unformatted',action='write')
+         write(27) eta_kl
+         close(27)
+
+         ! transverse isotropic test kernels
+         open(unit=27,file=trim(prname)//'alpha_kernel.bin',status='unknown',form='unformatted',action='write')
+         write(27)  alpha_kl
+         close(27)
+         open(unit=27,file=trim(prname)//'beta_kernel.bin',status='unknown',form='unformatted',action='write')
+         write(27)  beta_kl
+         close(27)
+
+       else
+         ! fully anisotropic kernels
+         ! note: the C_ij and density kernels are not for relative perturbations (delta ln( m_i) = delta m_i / m_i),
+         !          but absolute perturbations (delta m_i = m_i - m_0).
+         ! Kappa and mu are for absolute perturbations, can be used to check with purely isotropic versions.
+         open(unit=27,file=trim(prname)//'rho_kernel.bin',status='unknown',form='unformatted',action='write')
+         write(27)  - rho_kl
+         close(27)
+         open(unit=27,file=trim(prname)//'cijkl_kernel.bin',status='unknown',form='unformatted',action='write')
+         write(27) - cijkl_kl
+         close(27)
+
+        endif
+
     else
-      ! fully anisotropic kernels
-      ! note: the C_ij and density kernels are not for relative perturbations (delta ln( m_i) = delta m_i / m_i),
-      !          but absolute perturbations (delta m_i = m_i - m_0).
-      ! Kappa and mu are for absolute perturbations, can be used to check with purely isotropic versions.
-      open(unit=IOUT,file=trim(prname)//'rho_kernel.bin',status='unknown',form='unformatted',action='write')
-      write(IOUT) - rho_kl
-      close(IOUT)
-      open(unit=IOUT,file=trim(prname)//'cijkl_kernel.bin',status='unknown',form='unformatted',action='write')
-      write(IOUT) - cijkl_kl
-      close(IOUT)
-    endif
-  else
-    ! save kernels to binary files
-    open(unit=IOUT,file=prname(1:len_trim(prname))//'rho_kernel.bin',status='unknown',form='unformatted',iostat=ier)
-    if( ier /= 0 ) stop 'error opening file rho_kernel.bin'
-    write(IOUT) rho_kl
-    close(IOUT)
 
-    open(unit=IOUT,file=prname(1:len_trim(prname))//'mu_kernel.bin',status='unknown',form='unformatted',iostat=ier)
-    if( ier /= 0 ) stop 'error opening file mu_kernel.bin'
-    write(IOUT) mu_kl
-    close(IOUT)
+      ! save kernels to binary files
+      open(unit=27,file=prname(1:len_trim(prname))//'rho_kernel.bin',status='unknown',form='unformatted',iostat=ier)
+      if( ier /= 0 ) stop 'error opening file rho_kernel.bin'
+      write(27) rho_kl
+      close(27)
 
-    open(unit=IOUT,file=prname(1:len_trim(prname))//'kappa_kernel.bin',status='unknown',form='unformatted',iostat=ier)
-    if( ier /= 0 ) stop 'error opening file kappa_kernel.bin'
-    write(IOUT) kappa_kl
-    close(IOUT)
+      open(unit=27,file=prname(1:len_trim(prname))//'mu_kernel.bin',status='unknown',form='unformatted',iostat=ier)
+      if( ier /= 0 ) stop 'error opening file mu_kernel.bin'
+      write(27) mu_kl
+      close(27)
 
-    open(unit=IOUT,file=prname(1:len_trim(prname))//'rhop_kernel.bin',status='unknown',form='unformatted',iostat=ier)
-    if( ier /= 0 ) stop 'error opening file rhop_kernel.bin'
-    write(IOUT) rhop_kl
-    close(IOUT)
+      open(unit=27,file=prname(1:len_trim(prname))//'kappa_kernel.bin',status='unknown',form='unformatted',iostat=ier)
+      if( ier /= 0 ) stop 'error opening file kappa_kernel.bin'
+      write(27) kappa_kl
+      close(27)
 
-    open(unit=IOUT,file=prname(1:len_trim(prname))//'beta_kernel.bin',status='unknown',form='unformatted',iostat=ier)
-    if( ier /= 0 ) stop 'error opening file beta_kernel.bin'
-    write(IOUT) beta_kl
-    close(IOUT)
+      open(unit=27,file=prname(1:len_trim(prname))//'rhop_kernel.bin',status='unknown',form='unformatted',iostat=ier)
+      if( ier /= 0 ) stop 'error opening file rhop_kernel.bin'
+      write(27) rhop_kl
+      close(27)
 
-    open(unit=IOUT,file=prname(1:len_trim(prname))//'alpha_kernel.bin',status='unknown',form='unformatted',iostat=ier)
-    if( ier /= 0 ) stop 'error opening file alpha_kernel.bin'
-    write(IOUT) alpha_kl
-    close(IOUT)
-  endif ! ANISOTROPIC_KL
+      open(unit=27,file=prname(1:len_trim(prname))//'beta_kernel.bin',status='unknown',form='unformatted',iostat=ier)
+      if( ier /= 0 ) stop 'error opening file beta_kernel.bin'
+      write(27) beta_kl
+      close(27)
 
-  if (SAVE_MOHO_MESH) then
-    open(unit=IOUT,file=prname(1:len_trim(prname))//'moho_kernel.bin',status='unknown',form='unformatted',iostat=ier)
-    if( ier /= 0 ) stop 'error opening file moho_kernel.bin'
-    write(IOUT) moho_kl
-    close(IOUT)
+      open(unit=27,file=prname(1:len_trim(prname))//'alpha_kernel.bin',status='unknown',form='unformatted',iostat=ier)
+      if( ier /= 0 ) stop 'error opening file alpha_kernel.bin'
+      write(27) alpha_kl
+      close(27)
+    endif
+
+    if (SAVE_MOHO_MESH) then
+      open(unit=27,file=prname(1:len_trim(prname))//'moho_kernel.bin',status='unknown',form='unformatted',iostat=ier)
+      if( ier /= 0 ) stop 'error opening file moho_kernel.bin'
+      write(27) moho_kl
+      close(27)
+    endif
   endif
 
   ! frees temporary arrays
@@ -402,19 +458,19 @@
   else
     deallocate(rhop_kl,alpha_kl,beta_kl)
   endif
+end subroutine save_kernels_elastic
 
-  end subroutine save_kernels_elastic
+!==============================================================================
+!> Save poroelastic related kernels
+subroutine save_kernels_poroelastic(adios_handle)
 
-!
-!-------------------------------------------------------------------------------------------------
-!
-
-  subroutine save_kernels_poroelastic
-
   use specfem_par
   use specfem_par_poroelastic
 
   implicit none
+
+  integer(kind=8) :: adios_handle
+
   ! local parameters
   integer:: ispec,i,j,k,ier
   real(kind=CUSTOM_REAL) :: rhol_s,rhol_f,rhol_bar,phil,tortl
@@ -643,141 +699,154 @@
   enddo
 
   ! save kernels to binary files
+  if (ADIOS_FOR_KERNELS) then
+    call save_kernels_poroelastic_adios(adios_handle)
+  else
+    ! primary kernels
+    open(unit=27,file=prname(1:len_trim(prname))//'rhot_primeporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
+    if( ier /= 0 ) stop 'error opening file rhot_primeporo_kernel.bin'
+    write(27) rhot_kl
+    close(27)
+    open(unit=27,file=prname(1:len_trim(prname))//'rhof_primeporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
+    if( ier /= 0 ) stop 'error opening file rhof_primeporo_kernel.bin'
+    write(27) rhof_kl
+    close(27)
+    open(unit=27,file=prname(1:len_trim(prname))//'sm_primeporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
+    if( ier /= 0 ) stop 'error opening file sm_primeporo_kernel.bin'
+    write(27) sm_kl
+    close(27)
+    open(unit=27,file=prname(1:len_trim(prname))//'eta_primeporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
+    if( ier /= 0 ) stop 'error opening file eta_primeporo_kernel.bin'
+    write(27) eta_kl
+    close(27)
+    open(unit=27,file=prname(1:len_trim(prname))//'mufr_primeporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
+    if( ier /= 0 ) stop 'error opening file mufr_primeporo_kernel.bin'
+    write(27) mufr_kl
+    close(27)
+    open(unit=27,file=prname(1:len_trim(prname))//'B_primeporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
+    if( ier /= 0 ) stop 'error opening file B_primeporo_kernel.bin'
+    write(27) B_kl
+    close(27)
+    open(unit=27,file=prname(1:len_trim(prname))//'C_primeporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
+    if( ier /= 0 ) stop 'error opening file C_primeporo_kernel.bin'
+    write(27) C_kl
+    close(27)
+    open(unit=27,file=prname(1:len_trim(prname))//'M_primeporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
+    if( ier /= 0 ) stop 'error opening file M_primeporo_kernel.bin'
+    write(27) M_kl
+    close(27)
 
-  ! primary kernels
-  open(unit=IOUT,file=prname(1:len_trim(prname))//'rhot_primeporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
-  if( ier /= 0 ) stop 'error opening file rhot_primeporo_kernel.bin'
-  write(IOUT) rhot_kl
-  close(IOUT)
-  open(unit=IOUT,file=prname(1:len_trim(prname))//'rhof_primeporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
-  if( ier /= 0 ) stop 'error opening file rhof_primeporo_kernel.bin'
-  write(IOUT) rhof_kl
-  close(IOUT)
-  open(unit=IOUT,file=prname(1:len_trim(prname))//'sm_primeporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
-  if( ier /= 0 ) stop 'error opening file sm_primeporo_kernel.bin'
-  write(IOUT) sm_kl
-  close(IOUT)
-  open(unit=IOUT,file=prname(1:len_trim(prname))//'eta_primeporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
-  if( ier /= 0 ) stop 'error opening file eta_primeporo_kernel.bin'
-  write(IOUT) eta_kl
-  close(IOUT)
-  open(unit=IOUT,file=prname(1:len_trim(prname))//'mufr_primeporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
-  if( ier /= 0 ) stop 'error opening file mufr_primeporo_kernel.bin'
-  write(IOUT) mufr_kl
-  close(IOUT)
-  open(unit=IOUT,file=prname(1:len_trim(prname))//'B_primeporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
-  if( ier /= 0 ) stop 'error opening file B_primeporo_kernel.bin'
-  write(IOUT) B_kl
-  close(IOUT)
-  open(unit=IOUT,file=prname(1:len_trim(prname))//'C_primeporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
-  if( ier /= 0 ) stop 'error opening file C_primeporo_kernel.bin'
-  write(IOUT) C_kl
-  close(IOUT)
-  open(unit=IOUT,file=prname(1:len_trim(prname))//'M_primeporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
-  if( ier /= 0 ) stop 'error opening file M_primeporo_kernel.bin'
-  write(IOUT) M_kl
-  close(IOUT)
+    ! density kernels
+    open(unit=27,file=prname(1:len_trim(prname))//'rhob_densityporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
+    if( ier /= 0 ) stop 'error opening file rhob_densityporo_kernel.bin'
+    write(27) rhob_kl
+    close(27)
+    open(unit=27,file=prname(1:len_trim(prname))//'rhofb_densityporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
+    if( ier /= 0 ) stop 'error opening file rhofb_densityporo_kernel.bin'
+    write(27) rhofb_kl
+    close(27)
+    open(unit=27,file=prname(1:len_trim(prname))//'phi_densityporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
+    if( ier /= 0 ) stop 'error opening file phi_densityporo_kernel.bin'
+    write(27) phi_kl
+    close(27)
+    open(unit=27,file=prname(1:len_trim(prname))//'mufrb_densityporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
+    if( ier /= 0 ) stop 'error opening file mufrb_densityporo_kernel.bin'
+    write(27) mufrb_kl
+    close(27)
+    open(unit=27,file=prname(1:len_trim(prname))//'Bb_densityporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
+    if( ier /= 0 ) stop 'error opening file Bb_densityporo_kernel.bin'
+    write(27) Bb_kl
+    close(27)
+    open(unit=27,file=prname(1:len_trim(prname))//'Cb_densityporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
+    if( ier /= 0 ) stop 'error opening file Cb_densityporo_kernel.bin'
+    write(27) Cb_kl
+    close(27)
+    open(unit=27,file=prname(1:len_trim(prname))//'Mb_densityporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
+    if( ier /= 0 ) stop 'error opening file Mb_densityporo_kernel.bin'
+    write(27) Mb_kl
+    close(27)
 
-  ! density kernels
-  open(unit=IOUT,file=prname(1:len_trim(prname))//'rhob_densityporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
-  if( ier /= 0 ) stop 'error opening file rhob_densityporo_kernel.bin'
-  write(IOUT) rhob_kl
-  close(IOUT)
-  open(unit=IOUT,file=prname(1:len_trim(prname))//'rhofb_densityporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
-  if( ier /= 0 ) stop 'error opening file rhofb_densityporo_kernel.bin'
-  write(IOUT) rhofb_kl
-  close(IOUT)
-  open(unit=IOUT,file=prname(1:len_trim(prname))//'phi_densityporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
-  if( ier /= 0 ) stop 'error opening file phi_densityporo_kernel.bin'
-  write(IOUT) phi_kl
-  close(IOUT)
-  open(unit=IOUT,file=prname(1:len_trim(prname))//'mufrb_densityporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
-  if( ier /= 0 ) stop 'error opening file mufrb_densityporo_kernel.bin'
-  write(IOUT) mufrb_kl
-  close(IOUT)
-  open(unit=IOUT,file=prname(1:len_trim(prname))//'Bb_densityporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
-  if( ier /= 0 ) stop 'error opening file Bb_densityporo_kernel.bin'
-  write(IOUT) Bb_kl
-  close(IOUT)
-  open(unit=IOUT,file=prname(1:len_trim(prname))//'Cb_densityporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
-  if( ier /= 0 ) stop 'error opening file Cb_densityporo_kernel.bin'
-  write(IOUT) Cb_kl
-  close(IOUT)
-  open(unit=IOUT,file=prname(1:len_trim(prname))//'Mb_densityporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
-  if( ier /= 0 ) stop 'error opening file Mb_densityporo_kernel.bin'
-  write(IOUT) Mb_kl
-  close(IOUT)
+    ! wavespeed kernels
+    open(unit=27,file=prname(1:len_trim(prname))//'rhobb_waveporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
+    if( ier /= 0 ) stop 'error opening file rhobb_waveporo_kernel.bin'
+    write(27) rhobb_kl
+    close(27)
+    open(unit=27,file=prname(1:len_trim(prname))//'rhofbb_waveporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
+    if( ier /= 0 ) stop 'error opening file rhofbb_waveporo_kernel.bin'
+    write(27) rhofbb_kl
+    close(27)
+    open(unit=27,file=prname(1:len_trim(prname))//'phib_waveporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
+    if( ier /= 0 ) stop 'error opening file phib_waveporo_kernel.bin'
+    write(27) phib_kl
+    close(27)
+    open(unit=27,file=prname(1:len_trim(prname))//'cs_waveporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
+    if( ier /= 0 ) stop 'error opening file cs_waveporo_kernel.bin'
+    write(27) cs_kl
+    close(27)
+    open(unit=27,file=prname(1:len_trim(prname))//'cpI_waveporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
+    if( ier /= 0 ) stop 'error opening file cpI_waveporo_kernel.bin'
+    write(27) cpI_kl
+    close(27)
+    open(unit=27,file=prname(1:len_trim(prname))//'cpII_waveporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
+    if( ier /= 0 ) stop 'error opening file cpII_waveporo_kernel.bin'
+    write(27) cpII_kl
+    close(27)
+    open(unit=27,file=prname(1:len_trim(prname))//'ratio_waveporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
+    if( ier /= 0 ) stop 'error opening file ratio_waveporo_kernel.bin'
+    write(27) ratio_kl
+    close(27)
 
-  ! wavespeed kernels
-  open(unit=IOUT,file=prname(1:len_trim(prname))//'rhobb_waveporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
-  if( ier /= 0 ) stop 'error opening file rhobb_waveporo_kernel.bin'
-  write(IOUT) rhobb_kl
-  close(IOUT)
-  open(unit=IOUT,file=prname(1:len_trim(prname))//'rhofbb_waveporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
-  if( ier /= 0 ) stop 'error opening file rhofbb_waveporo_kernel.bin'
-  write(IOUT) rhofbb_kl
-  close(IOUT)
-  open(unit=IOUT,file=prname(1:len_trim(prname))//'phib_waveporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
-  if( ier /= 0 ) stop 'error opening file phib_waveporo_kernel.bin'
-  write(IOUT) phib_kl
-  close(IOUT)
-  open(unit=IOUT,file=prname(1:len_trim(prname))//'cs_waveporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
-  if( ier /= 0 ) stop 'error opening file cs_waveporo_kernel.bin'
-  write(IOUT) cs_kl
-  close(IOUT)
-  open(unit=IOUT,file=prname(1:len_trim(prname))//'cpI_waveporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
-  if( ier /= 0 ) stop 'error opening file cpI_waveporo_kernel.bin'
-  write(IOUT) cpI_kl
-  close(IOUT)
-  open(unit=IOUT,file=prname(1:len_trim(prname))//'cpII_waveporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
-  if( ier /= 0 ) stop 'error opening file cpII_waveporo_kernel.bin'
-  write(IOUT) cpII_kl
-  close(IOUT)
-  open(unit=IOUT,file=prname(1:len_trim(prname))//'ratio_waveporo_kernel.bin',status='unknown',form='unformatted',iostat=ier)
-  if( ier /= 0 ) stop 'error opening file ratio_waveporo_kernel.bin'
-  write(IOUT) ratio_kl
-  close(IOUT)
+  endif
+end subroutine save_kernels_poroelastic
 
-  end subroutine save_kernels_poroelastic
+!==============================================================================
+!> Save hessians
+subroutine save_kernels_hessian(adios_handle)
 
-!
-!-------------------------------------------------------------------------------------------------
-!
-
-  subroutine save_kernels_hessian()
-
   use specfem_par
   use specfem_par_elastic
   use specfem_par_acoustic
 
   implicit none
+
+  integer(kind=8) :: adios_handle
+
   integer :: ier
 
   ! acoustic domains
   if( ACOUSTIC_SIMULATION ) then
     ! scales approximate hessian
     hess_ac_kl(:,:,:,:) = 2._CUSTOM_REAL * hess_ac_kl(:,:,:,:)
-
-    ! stores into file
-    open(unit=IOUT,file=trim(prname)//'hess_acoustic_kernel.bin', &
-          status='unknown',form='unformatted',action='write',iostat=ier)
-    if( ier /= 0 ) stop 'error opening file hess_acoustic_kernel.bin'
-    write(IOUT) hess_ac_kl
-    close(IOUT)
   endif
 
   ! elastic domains
   if( ELASTIC_SIMULATION ) then
     ! scales approximate hessian
     hess_kl(:,:,:,:) = 2._CUSTOM_REAL * hess_kl(:,:,:,:)
+  endif
 
-    ! stores into file
-    open(unit=IOUT,file=trim(prname)//'hess_kernel.bin', &
-          status='unknown',form='unformatted',action='write',iostat=ier)
-    if( ier /= 0 ) stop 'error opening file hess_kernel.bin'
-    write(IOUT) hess_kl
-    close(IOUT)
+  if (ADIOS_FOR_KERNELS) then
+    call save_kernels_hessian_adios(adios_handle)
+  else
+    ! acoustic domains
+    if( ACOUSTIC_SIMULATION ) then
+      ! stores into file
+      open(unit=27,file=trim(prname)//'hess_acoustic_kernel.bin', &
+            status='unknown',form='unformatted',action='write',iostat=ier)
+      if( ier /= 0 ) stop 'error opening file hess_acoustic_kernel.bin'
+      write(27) hess_ac_kl
+      close(27)
+    endif
+
+    ! elastic domains
+    if( ELASTIC_SIMULATION ) then
+      ! stores into file
+      open(unit=27,file=trim(prname)//'hess_kernel.bin', &
+            status='unknown',form='unformatted',action='write',iostat=ier)
+      if( ier /= 0 ) stop 'error opening file hess_kernel.bin'
+      write(27) hess_kl
+      close(27)
+    endif
   endif
+end subroutine save_kernels_hessian
 
-  end subroutine save_kernels_hessian
-

Added: seismo/3D/SPECFEM3D/trunk/src/specfem3D/save_kernels_adios.F90
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/specfem3D/save_kernels_adios.F90	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/src/specfem3D/save_kernels_adios.F90	2013-09-18 14:35:14 UTC (rev 22798)
@@ -0,0 +1,470 @@
+!=====================================================================
+!
+!               S p e c f e m 3 D  V e r s i o n  2 . 1
+!               ---------------------------------------
+!
+!          Main authors: Dimitri Komatitsch and Jeroen Tromp
+!    Princeton University, USA and CNRS / INRIA / University of Pau
+! (c) Princeton University / California Institute of Technology and CNRS / INRIA / University of Pau
+!                             July 2012
+!
+! This 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 02110-1301 USA.
+!
+!=====================================================================
+!
+! United States and French Government Sponsorship Acknowledged.
+
+
+!==============================================================================
+!> \file save_kernels_adios.f90
+!! \brief Save kernels arrays to file with the help of the ADIOS library.
+!! \author MPBL
+!==============================================================================
+
+!> \def STRINGIFY_VAR(a)
+!! Macro taking a variable and returning the stringified variable and 
+!! the variable itself. 
+!! STRINGIFY_VAR(x) expand as:
+!!   "x", x
+!! x being the variable name inside the code.
+#ifdef __INTEL_COMPILER
+#define STRINGIFY_VAR(a) #a, a
+#else
+#define STRINGIFY_VAR(a) "a", a
+#endif
+
+!==============================================================================
+!> Define all the kernels that will be written to the ADIOS file.
+!! \param[INOUT] adios_handle The handle pointing on the open ADIOS file
+!!                            intended to store kernels data.
+!! \note Everything is define in this single function, even the group size.
+!!       It is the reason why this function require only an handle on an ADIOS
+!!       file as an argument.
+subroutine define_kernel_adios_variables(handle, SAVE_WEIGHTS)
+
+  use mpi
+  use adios_write_mod
+
+  use adios_helpers_mod
+
+  use specfem_par
+  use specfem_par_acoustic
+  use specfem_par_elastic
+  use specfem_par_poroelastic
+
+  implicit none
+
+  ! Parameters
+  integer(kind=8), intent(INOUT) :: handle 
+  logical, intent(IN) :: SAVE_WEIGHTS
+  ! Variables
+  character(len=256) :: output_name, group_name
+  integer(kind=8) :: group, groupsize, adios_totalsize
+  integer :: local_dim, comm, adios_err, ierr
+  !--- Variables to allreduce - wmax stands for world_max
+  integer :: nspec_wmax, ier
+  integer, parameter :: num_vars = 1
+  integer, dimension(num_vars) :: max_global_values
+  ! Type inference for define_adios_global_array1D. Avoid additional args.
+  real(kind=CUSTOM_REAL), dimension(1,1,1,1) :: dummy_kernel
+
+  output_name = "OUTPUT_FILES/kernels.bp" 
+  group_name = "SPECFEM3D_KERNELS"
+  call MPI_Comm_dup (MPI_COMM_WORLD, comm, ierr)
+
+  groupsize = 0
+  call adios_declare_group(group, group_name, "", 0, adios_err)
+  call adios_select_method(group, "MPI", "", "", adios_err)
+
+  max_global_values(1) = NSPEC_AB
+
+  call MPI_Allreduce(MPI_IN_PLACE, max_global_values, num_vars, &
+                     MPI_INTEGER, MPI_MAX, MPI_COMM_WORLD, ier)
+  if( ier /= 0 ) call exit_MPI(myrank,'Allreduce to get max values failed.')
+
+  nspec_wmax = max_global_values(1)
+
+  call define_adios_scalar(group, groupsize, "", "nspec", NSPEC_AB) 
+
+  local_dim = NGLLX * NGLLY * NGLLZ * nspec_wmax
+
+  if( SAVE_WEIGHTS ) then
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", "weights_kernel", dummy_kernel)
+  endif                                   
+
+  if( ACOUSTIC_SIMULATION ) then
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", "rho_ac_kl", dummy_kernel)
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", "kappa_ac_kl", dummy_kernel)
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", "rhop_ac_kl", dummy_kernel)
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", "alpha_ac_kl", dummy_kernel)
+  endif                                   
+
+  if( ELASTIC_SIMULATION ) then
+    if (ANISOTROPIC_KL) then
+      if (SAVE_TRANSVERSE_KL) then
+        call define_adios_global_array1D(group, groupsize, local_dim, &
+                                         "", "alphav_kl", dummy_kernel)
+        call define_adios_global_array1D(group, groupsize, local_dim, &
+                                         "", "alphah_kl", dummy_kernel)
+        call define_adios_global_array1D(group, groupsize, local_dim, &
+                                         "", "betav_kl", dummy_kernel)
+        call define_adios_global_array1D(group, groupsize, local_dim, &
+                                         "", "betah_kl", dummy_kernel)
+        call define_adios_global_array1D(group, groupsize, local_dim, &
+                                         "", "eta_kl", dummy_kernel)
+        call define_adios_global_array1D(group, groupsize, local_dim, &
+                                         "", "alpha_kl", dummy_kernel)
+        call define_adios_global_array1D(group, groupsize, local_dim, &
+                                         "", "beta_kl", dummy_kernel)
+      else
+        call define_adios_global_array1D(group, groupsize, local_dim, &
+                                         "", "rho_kl", dummy_kernel)
+        call define_adios_global_array1D(group, groupsize, local_dim, &
+                                         "", "cijkl_kl", dummy_kernel)
+      endif
+    else
+      call define_adios_global_array1D(group, groupsize, local_dim, &
+                                       "", "rho_kl", dummy_kernel)
+      call define_adios_global_array1D(group, groupsize, local_dim, &
+                                       "", "mu_kl", dummy_kernel)
+      call define_adios_global_array1D(group, groupsize, local_dim, &
+                                       "", "kappa_kl", dummy_kernel)
+      call define_adios_global_array1D(group, groupsize, local_dim, &
+                                       "", "rhop_kl", dummy_kernel)
+      call define_adios_global_array1D(group, groupsize, local_dim, &
+                                       "", "beta_kl", dummy_kernel)
+      call define_adios_global_array1D(group, groupsize, local_dim, &
+                                       "", "alpha_kl", dummy_kernel)
+    endif
+    if (SAVE_MOHO_MESH) then
+      call define_adios_global_array1D(group, groupsize, local_dim, &
+                                       "", "moho_kl", dummy_kernel)
+    endif                                   
+  endif                                   
+
+  if( POROELASTIC_SIMULATION ) then
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", "rhot_kl", dummy_kernel)
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", "rhof_kl", dummy_kernel)
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", "sm_kl", dummy_kernel)
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", "eta_kl", dummy_kernel)
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", "mufr_kl", dummy_kernel)
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", "B_kl", dummy_kernel)
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", "C_kl", dummy_kernel)
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", "M_kl", dummy_kernel)
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", "rhofb_kl", dummy_kernel)
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", "phi_kl", dummy_kernel)
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", "mufrb_kl", dummy_kernel)
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", "Bb_kl", dummy_kernel)
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", "Cb_kl", dummy_kernel)
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", "Mb_kl", dummy_kernel)
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", "rhofbb_kl", dummy_kernel)
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", "phib_kl", dummy_kernel)
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", "cs_kl", dummy_kernel)
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", "cpI_kl", dummy_kernel)
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", "cpII_kl", dummy_kernel)
+    call define_adios_global_array1D(group, groupsize, local_dim, &
+                                     "", "ratio_kl", dummy_kernel)
+  endif                                   
+
+  if ( APPROXIMATE_HESS_KL ) then
+    if( ACOUSTIC_SIMULATION ) then
+      call define_adios_global_array1D(group, groupsize, local_dim, &
+                                       "", "hess_ac_kl", dummy_kernel)
+    endif
+    if( ELASTIC_SIMULATION ) then
+      call define_adios_global_array1D(group, groupsize, local_dim, &
+                                       "", "hess_kl", dummy_kernel)
+    endif
+  endif
+
+  !------------------------------------------------------------.
+  ! Open the handle to file containing all the ADIOS variables |
+  ! previously defined                                         |
+  !------------------------------------------------------------'
+  call adios_open (handle, group_name, outputname, "w", comm, adios_err)
+  call adios_group_size (handle, groupsize, adios_totalsize, adios_err)
+
+  call adios_write(handle, "nspec", NSPEC_AB, ier) 
+end subroutine define_kernel_adios_variables
+
+!==============================================================================
+!> Perform the actual write of all the kernels variables to file.
+!! \param[IN] adios_handle The handle pointing on the open ADIOS file intended 
+!!                         to store kernels.
+!!
+!! \note Obviously this is a general routine that should be extracted and used
+!!       everywhere as the 'adios_handle' argument can be used for any kind of
+!!       ADIOS file.
+!!       The only reason such a routine is defined is to avoid using 
+!!       ADIOS modules in non ADIOS file, in case the ADIOS library is not
+!!       available on the system.
+subroutine perform_write_adios_kernels(handle)
+  
+  use adios_write_mod
+
+  implicit none
+
+  ! Parameters
+  integer(kind=8), intent(in) :: handle
+  ! Variables
+  integer :: adios_err
+
+  call adios_close(handle, adios_err)
+end subroutine perform_write_adios_kernels
+
+
+!==============================================================================
+!> Save weights for volume integration, 
+!! in order to benchmark the kernels with analytical expressions.
+!subroutine save_weights_kernel_adios(weights_kernel)
+  !use specfem_par
+  !use specfem_par_acoustic
+  !use specfem_par_elastic
+  !use specfem_par_poroelastic
+
+  !implicit none
+  !! local parameters
+  !real(kind=CUSTOM_REAL), dimension(:,:,:,:), allocatable :: weights_kernel
+
+  !!allocate(weights_kernel(NGLLX,NGLLY,NGLLZ,NSPEC_AB),stat=ier)
+  
+  !return 
+!end subroutine save_weights_kernel_adios
+
+!==============================================================================
+!> Save acoustic related kernels
+subroutine save_kernels_acoustic_adios(handle)
+
+  use specfem_par
+  use specfem_par_acoustic
+  use adios_helpers_mod
+
+  implicit none
+
+  ! Parameters
+  integer(kind=8), intent(in) :: handle
+  ! local parameters
+  integer:: local_dim
+
+  local_dim = NGLLX * NGLLY * NGLLZ * NSPEC_AB 
+
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(rho_ac_kl))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(kappa_ac_kl))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(rhop_ac_kl))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(alpha_ac_kl))
+end subroutine save_kernels_acoustic_adios
+
+!==============================================================================
+!> Save elastic related kernels
+subroutine save_kernels_elastic_adios(handle, alphav_kl, alphah_kl, &
+                                      betav_kl, betah_kl, eta_kl,   &
+                                      rhop_kl, alpha_kl, beta_kl)
+
+  use specfem_par
+  use specfem_par_elastic
+  use adios_helpers_mod
+
+  implicit none
+
+  ! Parameters
+  integer(kind=8), intent(in) :: handle
+  ! local parameters
+  integer:: local_dim
+
+  ! Transverse isotropic paramters
+  real(kind=CUSTOM_REAL), dimension(:,:,:,:):: &
+    alphav_kl,alphah_kl,betav_kl,betah_kl, &
+    eta_kl, rhop_kl, alpha_kl, beta_kl
+
+  local_dim = NGLLX * NGLLY * NGLLZ * NSPEC_AB 
+
+  if (ANISOTROPIC_KL) then
+    ! outputs transverse isotropic kernels only
+    if (SAVE_TRANSVERSE_KL) then
+      ! transverse isotropic kernels
+      ! (alpha_v, alpha_h, beta_v, beta_h, eta, rho ) parameterization
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                       local_dim, STRINGIFY_VAR(alphav_kl))
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                       local_dim, STRINGIFY_VAR(alphah_kl))
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                       local_dim, STRINGIFY_VAR(betav_kl))
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                       local_dim, STRINGIFY_VAR(betah_kl))
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                       local_dim, STRINGIFY_VAR(eta_kl))
+
+      ! transverse isotropic test kernels
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                       local_dim, STRINGIFY_VAR(alpha_kl))
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                       local_dim, STRINGIFY_VAR(beta_kl))
+    else
+      ! fully anisotropic kernels
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                       local_dim, "rho_kl", -rho_kl)
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                       local_dim, "cijkl_kl", -cijkl_kl)
+    endif
+  else
+    ! save kernels to binary files
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                     local_dim, STRINGIFY_VAR(rho_kl))
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                     local_dim, STRINGIFY_VAR(mu_kl))
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                     local_dim, STRINGIFY_VAR(kappa_kl))
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                     local_dim, STRINGIFY_VAR(rhop_kl))
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                     local_dim, STRINGIFY_VAR(beta_kl))
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                     local_dim, STRINGIFY_VAR(alpha_kl))
+  endif
+
+  if (SAVE_MOHO_MESH) then
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                     local_dim, STRINGIFY_VAR(moho_kl))
+  endif
+
+end subroutine save_kernels_elastic_adios
+
+!==============================================================================
+!> Save poroelastic related kernels
+subroutine save_kernels_poroelastic_adios(handle)
+
+  use specfem_par
+  use specfem_par_poroelastic
+  use adios_helpers_mod
+
+  implicit none
+
+  ! Parameters
+  integer(kind=8), intent(in) :: handle
+  ! local parameters
+  integer :: local_dim
+
+  local_dim = NGLLX * NGLLY * NGLLZ * NSPEC_AB 
+
+  ! primary kernels
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(rhot_kl))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(rhof_kl))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(sm_kl))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(eta_kl))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(mufr_kl))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(B_kl))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(C_kl))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(M_kl))
+
+  ! density kernels
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(rhob_kl))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(rhofb_kl))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(phi_kl))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(mufrb_kl))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(Bb_kl))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(Cb_kl))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(Mb_kl))
+
+  ! wavespeed kernels
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(rhobb_kl))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(rhofbb_kl))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(phib_kl))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(cs_kl))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(cpI_kl))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(cpII_kl))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                   local_dim, STRINGIFY_VAR(ratio_kl))
+
+end subroutine save_kernels_poroelastic_adios
+
+!==============================================================================
+!> Save hessians
+subroutine save_kernels_hessian_adios(handle)
+
+  use specfem_par
+  use specfem_par_elastic
+  use specfem_par_acoustic
+  use adios_helpers_mod
+
+  implicit none
+
+  ! Parameters
+  integer(kind=8), intent(in) :: handle
+  integer :: local_dim
+
+  local_dim = NGLLX * NGLLY * NGLLZ * NSPEC_AB 
+
+  ! acoustic domains
+  if( ACOUSTIC_SIMULATION ) then
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                     local_dim, STRINGIFY_VAR(hess_ac_kl))
+  endif
+  ! elastic domains
+  if( ELASTIC_SIMULATION ) then
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, &
+                                     local_dim, STRINGIFY_VAR(hess_kl))
+  endif
+
+end subroutine save_kernels_hessian_adios
+

Modified: seismo/3D/SPECFEM3D/trunk/src/specfem3D/specfem3D.f90
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/specfem3D/specfem3D.f90	2013-09-17 22:36:21 UTC (rev 22797)
+++ seismo/3D/SPECFEM3D/trunk/src/specfem3D/specfem3D.f90	2013-09-18 14:35:14 UTC (rev 22798)
@@ -332,14 +332,19 @@
   ! force Flush-To-Zero if available to avoid very slow Gradual Underflow trapping
   call force_ftz()
 
-! reads in parameters
+  ! reads in parameters
   call initialize_simulation()
 
+  ! reads in external mesh
+  if (ADIOS_FOR_MESH) then
+    call read_mesh_databases_adios()
+  else
+    call read_mesh_databases()
+  endif
+    !call read_mesh_databases()
+    !call read_mesh_databases_adios()
 
-! reads in external mesh
-  call read_mesh_databases()
 
-
 ! sets up reference element GLL points/weights/derivatives
   call setup_GLL_points()
 

Added: seismo/3D/SPECFEM3D/trunk/src/specfem3D/specfem3D_adios_stubs.f90
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/specfem3D/specfem3D_adios_stubs.f90	                        (rev 0)
+++ seismo/3D/SPECFEM3D/trunk/src/specfem3D/specfem3D_adios_stubs.f90	2013-09-18 14:35:14 UTC (rev 22798)
@@ -0,0 +1,71 @@
+
+!==============================================================================
+!> \file specfem3D_adios_stubs.f90
+!!
+!!  Stubs for ADIOS functions. Avoid link error when not configured with
+!!  ADIOS.
+!!      
+!! \author MPBL
+!==============================================================================
+
+!------------------------------------------------.
+! Subroutines from read_mesh_databases_adios.F90 |
+!------------------------------------------------'
+
+subroutine read_mesh_for_init()
+  use adios_manager_mod
+
+  call no_adios_err()  
+end subroutine read_mesh_for_init 
+
+subroutine read_mesh_databases_adios()
+  use adios_manager_mod
+
+  call no_adios_err()  
+end subroutine read_mesh_databases_adios
+
+subroutine read_moho_mesh_adjoint_adios()
+  use adios_manager_mod
+
+  call no_adios_err()  
+end subroutine read_moho_mesh_adjoint_adios
+
+!-----------------------------------------.
+! Subroutines from save_kernels_adios.F90 |
+!-----------------------------------------'
+
+subroutine define_kernel_adios_variables()
+  use adios_manager_mod
+
+  call no_adios_err()  
+end subroutine define_kernel_adios_variables 
+
+subroutine perform_write_adios_kernels()
+  use adios_manager_mod
+
+  call no_adios_err()  
+end subroutine 
+
+subroutine save_kernels_acoustic_adios()
+  use adios_manager_mod
+
+  call no_adios_err()  
+end subroutine 
+
+subroutine save_kernels_elastic_adios()
+  use adios_manager_mod
+
+  call no_adios_err()  
+end subroutine 
+
+subroutine save_kernels_poroelastic_adios()
+  use adios_manager_mod
+
+  call no_adios_err()  
+end subroutine save_kernels_poroelastic_adios
+
+subroutine save_kernels_hessian_adios()
+  use adios_manager_mod
+
+  call no_adios_err()  
+end subroutine save_kernels_hessian_adios

Modified: seismo/3D/SPECFEM3D/trunk/src/specfem3D/specfem3D_par.f90
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/specfem3D/specfem3D_par.f90	2013-09-17 22:36:21 UTC (rev 22797)
+++ seismo/3D/SPECFEM3D/trunk/src/specfem3D/specfem3D_par.f90	2013-09-18 14:35:14 UTC (rev 22798)
@@ -160,7 +160,7 @@
   double precision, dimension(:,:), allocatable :: hxir_store,hetar_store,hgammar_store
 
 ! proc numbers for MPI
-  integer :: myrank
+  integer :: myrank, sizeprocs
 
 ! timer MPI
   double precision, external :: wtime
@@ -202,6 +202,9 @@
 
   character(len=256) OUTPUT_FILES,LOCAL_PATH,TOMOGRAPHY_PATH,prname,dsmname,TRAC_PATH
 
+  logical :: ADIOS_ENABLED
+  logical :: ADIOS_FOR_DATABASES, ADIOS_FOR_MESH, ADIOS_FOR_KERNELS
+
 ! names of the data files for all the processors in MPI
   character(len=256) outputname
 
@@ -535,9 +538,9 @@
   integer, dimension(:), allocatable :: b_request_recv_vector_ext_meshs
   integer, dimension(:), allocatable :: b_request_recv_vector_ext_meshw
 
+
 end module specfem_par_poroelastic
 
-
 !=====================================================================
 
 module specfem_par_movie
@@ -593,4 +596,3 @@
   logical :: MOVIE_SIMULATION
 
 end module specfem_par_movie
-



More information about the CIG-COMMITS mailing list