[cig-commits] r22929 - in seismo/3D/SPECFEM3D_GLOBE/trunk: . DATA EXAMPLES/benchmarks/attenuation_benchmark_GJI_2002_versus_normal_modes EXAMPLES/benchmarks/prem_ani_noocean_Q_Cowling_Bolivia_9s/SEMD/DATA EXAMPLES/benchmarks/prem_ani_noocean_Q_Cowling_Vanuatu/SEMD/DATA EXAMPLES/benchmarks/prem_iso_noocean_Q_Cowling_Vanuatu/SEMD/DATA EXAMPLES/global_PREM_kernels/amplitude/DATA EXAMPLES/global_PREM_kernels/traveltime/DATA EXAMPLES/global_s362ani/DATA EXAMPLES/global_s362ani_shakemovie/DATA EXAMPLES/global_s362ani_small/DATA EXAMPLES/noise_examples/global_long EXAMPLES/noise_examples/global_short EXAMPLES/noise_examples/regional EXAMPLES/noise_examples/test_global EXAMPLES/noise_examples/test_regional EXAMPLES/regional_Greece_noise_small/DATA EXAMPLES/regional_Greece_small/DATA EXAMPLES/regional_MiddleEast/DATA EXAMPLES/small_benchmark_run_to_test_more_complex_Earth EXAMPLES/small_benchmark_run_to_test_very_simple_Earth setup src/cuda src/meshfem3D src/shared src/specfem3D

danielpeter at geodynamics.org danielpeter at geodynamics.org
Mon Oct 7 08:14:09 PDT 2013


Author: danielpeter
Date: 2013-10-07 08:14:08 -0700 (Mon, 07 Oct 2013)
New Revision: 22929

Added:
   seismo/3D/SPECFEM3D_GLOBE/trunk/setup/config.fh.in
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/get_absorb_adios.F90
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/model_gll_adios.F90
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/shared/adios_helpers_definitions.f90
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/shared/adios_helpers_writers.f90
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/read_arrays_solver_adios.F90
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/save_kernels_adios.F90
Removed:
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/get_absorb_adios.f90
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/read_arrays_solver_adios.f90
Modified:
   seismo/3D/SPECFEM3D_GLOBE/trunk/DATA/Par_file
   seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/benchmarks/attenuation_benchmark_GJI_2002_versus_normal_modes/Par_file
   seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/benchmarks/prem_ani_noocean_Q_Cowling_Bolivia_9s/SEMD/DATA/Par_file
   seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/benchmarks/prem_ani_noocean_Q_Cowling_Vanuatu/SEMD/DATA/Par_file
   seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/benchmarks/prem_iso_noocean_Q_Cowling_Vanuatu/SEMD/DATA/Par_file
   seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/global_PREM_kernels/amplitude/DATA/Par_file
   seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/global_PREM_kernels/traveltime/DATA/Par_file
   seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/global_s362ani/DATA/Par_file
   seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/global_s362ani_shakemovie/DATA/Par_file
   seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/global_s362ani_small/DATA/Par_file
   seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/global_s362ani_small/DATA/STATIONS
   seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/global_long/Par_file_NOISE_1_attenuation
   seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/global_long/Par_file_NOISE_1_noattenuation
   seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/global_long/Par_file_NOISE_2_attenuation
   seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/global_long/Par_file_NOISE_2_noattenuation
   seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/global_long/Par_file_NOISE_3_noattenuation
   seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/global_short/Par_file_NOISE_1_attenuation
   seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/global_short/Par_file_NOISE_1_noattenuation
   seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/global_short/Par_file_NOISE_2_attenuation
   seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/global_short/Par_file_NOISE_2_noattenuation
   seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/global_short/Par_file_NOISE_3_noattenuation
   seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/regional/Par_file_NOISE_1_attenuation
   seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/regional/Par_file_NOISE_1_noattenuation
   seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/regional/Par_file_NOISE_2_attenuation
   seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/regional/Par_file_NOISE_2_noattenuation
   seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/regional/Par_file_NOISE_3_noattenuation
   seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/test_global/Par_file_NOISE_1_attenuation
   seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/test_global/Par_file_NOISE_1_noattenuation
   seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/test_global/Par_file_NOISE_2_attenuation
   seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/test_global/Par_file_NOISE_2_noattenuation
   seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/test_global/Par_file_NOISE_3_noattenuation
   seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/test_regional/Par_file_NOISE_1_attenuation
   seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/test_regional/Par_file_NOISE_1_noattenuation
   seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/test_regional/Par_file_NOISE_2_attenuation
   seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/test_regional/Par_file_NOISE_2_noattenuation
   seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/test_regional/Par_file_NOISE_3_noattenuation
   seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/regional_Greece_noise_small/DATA/Par_file
   seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/regional_Greece_small/DATA/Par_file
   seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/regional_MiddleEast/DATA/Par_file
   seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/small_benchmark_run_to_test_more_complex_Earth/Par_file
   seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/small_benchmark_run_to_test_very_simple_Earth/Par_file
   seismo/3D/SPECFEM3D_GLOBE/trunk/Makefile.in
   seismo/3D/SPECFEM3D_GLOBE/trunk/configure
   seismo/3D/SPECFEM3D_GLOBE/trunk/configure.ac
   seismo/3D/SPECFEM3D_GLOBE/trunk/flags.guess
   seismo/3D/SPECFEM3D_GLOBE/trunk/setup/config.h.in
   seismo/3D/SPECFEM3D_GLOBE/trunk/setup/constants.h.in
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/cuda/rules.mk
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/cuda/specfem3D_gpu_cuda_method_stubs.c
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/create_regions_mesh.F90
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/create_regions_mesh_adios.f90
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/get_absorb.f90
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/model_gll.f90
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/model_s362ani.f90
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/rules.mk
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/save_arrays_solver.f90
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/save_arrays_solver_adios.F90
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/test_MPI_interfaces.f90
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/write_AVS_DX_global_chunks_data_adios.f90
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/write_AVS_DX_global_data_adios.f90
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/write_AVS_DX_global_faces_data_adios.f90
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/write_AVS_DX_surface_data_adios.f90
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/shared/adios_helpers.f90
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/shared/adios_manager.F90
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/shared/adios_method_stubs.f90
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/shared/broadcast_computed_parameters.f90
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/shared/parallel.f90
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/shared/read_parameter_file.f90
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/shared/rules.mk
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/shared/shared_par.f90
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/compute_forces_crust_mantle_Dev.F90
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/compute_forces_inner_core_Dev.F90
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/compute_forces_outer_core_Dev.F90
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/compute_forces_viscoelastic_calling_routine.F90
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/compute_stacey_outer_core.f90
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/finalize_simulation.f90
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/get_attenuation.f90
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/iterate_time.F90
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/prepare_timerun.f90
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/read_attenuation_adios.f90
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/read_forward_arrays_adios.F90
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/read_mesh_databases.F90
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/read_mesh_databases_adios.f90
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/rules.mk
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/save_forward_arrays_adios.F90
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/save_kernels.f90
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/save_regular_kernels.f90
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/specfem3D_par.F90
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/write_movie_output.f90
   seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/write_specfem_adios_header.F90
Log:
updates adios routines and configuration

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/DATA/Par_file
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/DATA/Par_file	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/DATA/Par_file	2013-10-07 15:14:08 UTC (rev 22929)
@@ -196,4 +196,6 @@
 ADIOS_FOR_ARRAYS_SOLVER         = .true.
 ADIOS_FOR_SOLVER_MESHFILES      = .true.
 ADIOS_FOR_AVS_DX                = .true.
+ADIOS_FOR_KERNELS               = .true.
+ADIOS_FOR_MODELS                = .true.
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/benchmarks/attenuation_benchmark_GJI_2002_versus_normal_modes/Par_file
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/benchmarks/attenuation_benchmark_GJI_2002_versus_normal_modes/Par_file	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/benchmarks/attenuation_benchmark_GJI_2002_versus_normal_modes/Par_file	2013-10-07 15:14:08 UTC (rev 22929)
@@ -189,4 +189,6 @@
 ADIOS_FOR_ARRAYS_SOLVER         = .true.
 ADIOS_FOR_SOLVER_MESHFILES      = .true.
 ADIOS_FOR_AVS_DX                = .true.
+ADIOS_FOR_KERNELS               = .true.
+ADIOS_FOR_MODELS                = .true.
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/benchmarks/prem_ani_noocean_Q_Cowling_Bolivia_9s/SEMD/DATA/Par_file
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/benchmarks/prem_ani_noocean_Q_Cowling_Bolivia_9s/SEMD/DATA/Par_file	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/benchmarks/prem_ani_noocean_Q_Cowling_Bolivia_9s/SEMD/DATA/Par_file	2013-10-07 15:14:08 UTC (rev 22929)
@@ -197,4 +197,6 @@
 ADIOS_FOR_ARRAYS_SOLVER         = .true.
 ADIOS_FOR_SOLVER_MESHFILES      = .true.
 ADIOS_FOR_AVS_DX                = .true.
+ADIOS_FOR_KERNELS               = .true.
+ADIOS_FOR_MODELS                = .true.
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/benchmarks/prem_ani_noocean_Q_Cowling_Vanuatu/SEMD/DATA/Par_file
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/benchmarks/prem_ani_noocean_Q_Cowling_Vanuatu/SEMD/DATA/Par_file	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/benchmarks/prem_ani_noocean_Q_Cowling_Vanuatu/SEMD/DATA/Par_file	2013-10-07 15:14:08 UTC (rev 22929)
@@ -197,4 +197,6 @@
 ADIOS_FOR_ARRAYS_SOLVER         = .true.
 ADIOS_FOR_SOLVER_MESHFILES      = .true.
 ADIOS_FOR_AVS_DX                = .true.
+ADIOS_FOR_KERNELS               = .true.
+ADIOS_FOR_MODELS                = .true.
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/benchmarks/prem_iso_noocean_Q_Cowling_Vanuatu/SEMD/DATA/Par_file
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/benchmarks/prem_iso_noocean_Q_Cowling_Vanuatu/SEMD/DATA/Par_file	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/benchmarks/prem_iso_noocean_Q_Cowling_Vanuatu/SEMD/DATA/Par_file	2013-10-07 15:14:08 UTC (rev 22929)
@@ -197,4 +197,6 @@
 ADIOS_FOR_ARRAYS_SOLVER         = .true.
 ADIOS_FOR_SOLVER_MESHFILES      = .true.
 ADIOS_FOR_AVS_DX                = .true.
+ADIOS_FOR_KERNELS               = .true.
+ADIOS_FOR_MODELS                = .true.
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/global_PREM_kernels/amplitude/DATA/Par_file
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/global_PREM_kernels/amplitude/DATA/Par_file	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/global_PREM_kernels/amplitude/DATA/Par_file	2013-10-07 15:14:08 UTC (rev 22929)
@@ -197,4 +197,6 @@
 ADIOS_FOR_ARRAYS_SOLVER         = .true.
 ADIOS_FOR_SOLVER_MESHFILES      = .true.
 ADIOS_FOR_AVS_DX                = .true.
+ADIOS_FOR_KERNELS               = .true.
+ADIOS_FOR_MODELS                = .true.
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/global_PREM_kernels/traveltime/DATA/Par_file
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/global_PREM_kernels/traveltime/DATA/Par_file	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/global_PREM_kernels/traveltime/DATA/Par_file	2013-10-07 15:14:08 UTC (rev 22929)
@@ -197,4 +197,6 @@
 ADIOS_FOR_ARRAYS_SOLVER         = .true.
 ADIOS_FOR_SOLVER_MESHFILES      = .true.
 ADIOS_FOR_AVS_DX                = .true.
+ADIOS_FOR_KERNELS               = .true.
+ADIOS_FOR_MODELS                = .true.
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/global_s362ani/DATA/Par_file
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/global_s362ani/DATA/Par_file	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/global_s362ani/DATA/Par_file	2013-10-07 15:14:08 UTC (rev 22929)
@@ -197,4 +197,6 @@
 ADIOS_FOR_ARRAYS_SOLVER         = .true.
 ADIOS_FOR_SOLVER_MESHFILES      = .true.
 ADIOS_FOR_AVS_DX                = .true.
+ADIOS_FOR_KERNELS               = .true.
+ADIOS_FOR_MODELS                = .true.
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/global_s362ani_shakemovie/DATA/Par_file
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/global_s362ani_shakemovie/DATA/Par_file	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/global_s362ani_shakemovie/DATA/Par_file	2013-10-07 15:14:08 UTC (rev 22929)
@@ -197,4 +197,6 @@
 ADIOS_FOR_ARRAYS_SOLVER         = .true.
 ADIOS_FOR_SOLVER_MESHFILES      = .true.
 ADIOS_FOR_AVS_DX                = .true.
+ADIOS_FOR_KERNELS               = .true.
+ADIOS_FOR_MODELS                = .true.
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/global_s362ani_small/DATA/Par_file
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/global_s362ani_small/DATA/Par_file	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/global_s362ani_small/DATA/Par_file	2013-10-07 15:14:08 UTC (rev 22929)
@@ -197,4 +197,6 @@
 ADIOS_FOR_ARRAYS_SOLVER         = .true.
 ADIOS_FOR_SOLVER_MESHFILES      = .true.
 ADIOS_FOR_AVS_DX                = .true.
+ADIOS_FOR_KERNELS               = .true.
+ADIOS_FOR_MODELS                = .true.
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/global_s362ani_small/DATA/STATIONS
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/global_s362ani_small/DATA/STATIONS	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/global_s362ani_small/DATA/STATIONS	2013-10-07 15:14:08 UTC (rev 22929)
@@ -4,4 +4,4 @@
 LIT        HT       40.10080    22.49000    480.0     0.0
 ZKR        GE       35.11470    26.21700    270.0     0.0
 S001       XS       37.28300    21.71800    156.0     0.0
-126A       TA       32.6462   -104.02      1032.0     0.0
\ No newline at end of file
+126A       TA       32.6462   -104.02000    1032.0    0.0

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/global_long/Par_file_NOISE_1_attenuation
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/global_long/Par_file_NOISE_1_attenuation	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/global_long/Par_file_NOISE_1_attenuation	2013-10-07 15:14:08 UTC (rev 22929)
@@ -197,4 +197,6 @@
 ADIOS_FOR_ARRAYS_SOLVER         = .true.
 ADIOS_FOR_SOLVER_MESHFILES      = .true.
 ADIOS_FOR_AVS_DX                = .true.
+ADIOS_FOR_KERNELS               = .true.
+ADIOS_FOR_MODELS                = .true.
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/global_long/Par_file_NOISE_1_noattenuation
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/global_long/Par_file_NOISE_1_noattenuation	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/global_long/Par_file_NOISE_1_noattenuation	2013-10-07 15:14:08 UTC (rev 22929)
@@ -197,4 +197,6 @@
 ADIOS_FOR_ARRAYS_SOLVER         = .true.
 ADIOS_FOR_SOLVER_MESHFILES      = .true.
 ADIOS_FOR_AVS_DX                = .true.
+ADIOS_FOR_KERNELS               = .true.
+ADIOS_FOR_MODELS                = .true.
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/global_long/Par_file_NOISE_2_attenuation
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/global_long/Par_file_NOISE_2_attenuation	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/global_long/Par_file_NOISE_2_attenuation	2013-10-07 15:14:08 UTC (rev 22929)
@@ -197,4 +197,6 @@
 ADIOS_FOR_ARRAYS_SOLVER         = .true.
 ADIOS_FOR_SOLVER_MESHFILES      = .true.
 ADIOS_FOR_AVS_DX                = .true.
+ADIOS_FOR_KERNELS               = .true.
+ADIOS_FOR_MODELS                = .true.
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/global_long/Par_file_NOISE_2_noattenuation
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/global_long/Par_file_NOISE_2_noattenuation	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/global_long/Par_file_NOISE_2_noattenuation	2013-10-07 15:14:08 UTC (rev 22929)
@@ -197,4 +197,6 @@
 ADIOS_FOR_ARRAYS_SOLVER         = .true.
 ADIOS_FOR_SOLVER_MESHFILES      = .true.
 ADIOS_FOR_AVS_DX                = .true.
+ADIOS_FOR_KERNELS               = .true.
+ADIOS_FOR_MODELS                = .true.
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/global_long/Par_file_NOISE_3_noattenuation
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/global_long/Par_file_NOISE_3_noattenuation	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/global_long/Par_file_NOISE_3_noattenuation	2013-10-07 15:14:08 UTC (rev 22929)
@@ -197,4 +197,6 @@
 ADIOS_FOR_ARRAYS_SOLVER         = .true.
 ADIOS_FOR_SOLVER_MESHFILES      = .true.
 ADIOS_FOR_AVS_DX                = .true.
+ADIOS_FOR_KERNELS               = .true.
+ADIOS_FOR_MODELS                = .true.
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/global_short/Par_file_NOISE_1_attenuation
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/global_short/Par_file_NOISE_1_attenuation	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/global_short/Par_file_NOISE_1_attenuation	2013-10-07 15:14:08 UTC (rev 22929)
@@ -197,4 +197,6 @@
 ADIOS_FOR_ARRAYS_SOLVER         = .true.
 ADIOS_FOR_SOLVER_MESHFILES      = .true.
 ADIOS_FOR_AVS_DX                = .true.
+ADIOS_FOR_KERNELS               = .true.
+ADIOS_FOR_MODELS                = .true.
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/global_short/Par_file_NOISE_1_noattenuation
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/global_short/Par_file_NOISE_1_noattenuation	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/global_short/Par_file_NOISE_1_noattenuation	2013-10-07 15:14:08 UTC (rev 22929)
@@ -197,4 +197,6 @@
 ADIOS_FOR_ARRAYS_SOLVER         = .true.
 ADIOS_FOR_SOLVER_MESHFILES      = .true.
 ADIOS_FOR_AVS_DX                = .true.
+ADIOS_FOR_KERNELS               = .true.
+ADIOS_FOR_MODELS                = .true.
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/global_short/Par_file_NOISE_2_attenuation
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/global_short/Par_file_NOISE_2_attenuation	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/global_short/Par_file_NOISE_2_attenuation	2013-10-07 15:14:08 UTC (rev 22929)
@@ -197,4 +197,6 @@
 ADIOS_FOR_ARRAYS_SOLVER         = .true.
 ADIOS_FOR_SOLVER_MESHFILES      = .true.
 ADIOS_FOR_AVS_DX                = .true.
+ADIOS_FOR_KERNELS               = .true.
+ADIOS_FOR_MODELS                = .true.
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/global_short/Par_file_NOISE_2_noattenuation
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/global_short/Par_file_NOISE_2_noattenuation	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/global_short/Par_file_NOISE_2_noattenuation	2013-10-07 15:14:08 UTC (rev 22929)
@@ -197,4 +197,6 @@
 ADIOS_FOR_ARRAYS_SOLVER         = .true.
 ADIOS_FOR_SOLVER_MESHFILES      = .true.
 ADIOS_FOR_AVS_DX                = .true.
+ADIOS_FOR_KERNELS               = .true.
+ADIOS_FOR_MODELS                = .true.
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/global_short/Par_file_NOISE_3_noattenuation
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/global_short/Par_file_NOISE_3_noattenuation	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/global_short/Par_file_NOISE_3_noattenuation	2013-10-07 15:14:08 UTC (rev 22929)
@@ -197,4 +197,6 @@
 ADIOS_FOR_ARRAYS_SOLVER         = .true.
 ADIOS_FOR_SOLVER_MESHFILES      = .true.
 ADIOS_FOR_AVS_DX                = .true.
+ADIOS_FOR_KERNELS               = .true.
+ADIOS_FOR_MODELS                = .true.
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/regional/Par_file_NOISE_1_attenuation
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/regional/Par_file_NOISE_1_attenuation	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/regional/Par_file_NOISE_1_attenuation	2013-10-07 15:14:08 UTC (rev 22929)
@@ -197,4 +197,6 @@
 ADIOS_FOR_ARRAYS_SOLVER         = .true.
 ADIOS_FOR_SOLVER_MESHFILES      = .true.
 ADIOS_FOR_AVS_DX                = .true.
+ADIOS_FOR_KERNELS               = .true.
+ADIOS_FOR_MODELS                = .true.
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/regional/Par_file_NOISE_1_noattenuation
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/regional/Par_file_NOISE_1_noattenuation	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/regional/Par_file_NOISE_1_noattenuation	2013-10-07 15:14:08 UTC (rev 22929)
@@ -197,4 +197,6 @@
 ADIOS_FOR_ARRAYS_SOLVER         = .true.
 ADIOS_FOR_SOLVER_MESHFILES      = .true.
 ADIOS_FOR_AVS_DX                = .true.
+ADIOS_FOR_KERNELS               = .true.
+ADIOS_FOR_MODELS                = .true.
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/regional/Par_file_NOISE_2_attenuation
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/regional/Par_file_NOISE_2_attenuation	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/regional/Par_file_NOISE_2_attenuation	2013-10-07 15:14:08 UTC (rev 22929)
@@ -197,4 +197,6 @@
 ADIOS_FOR_ARRAYS_SOLVER         = .true.
 ADIOS_FOR_SOLVER_MESHFILES      = .true.
 ADIOS_FOR_AVS_DX                = .true.
+ADIOS_FOR_KERNELS               = .true.
+ADIOS_FOR_MODELS                = .true.
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/regional/Par_file_NOISE_2_noattenuation
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/regional/Par_file_NOISE_2_noattenuation	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/regional/Par_file_NOISE_2_noattenuation	2013-10-07 15:14:08 UTC (rev 22929)
@@ -197,4 +197,6 @@
 ADIOS_FOR_ARRAYS_SOLVER         = .true.
 ADIOS_FOR_SOLVER_MESHFILES      = .true.
 ADIOS_FOR_AVS_DX                = .true.
+ADIOS_FOR_KERNELS               = .true.
+ADIOS_FOR_MODELS                = .true.
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/regional/Par_file_NOISE_3_noattenuation
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/regional/Par_file_NOISE_3_noattenuation	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/regional/Par_file_NOISE_3_noattenuation	2013-10-07 15:14:08 UTC (rev 22929)
@@ -197,4 +197,6 @@
 ADIOS_FOR_ARRAYS_SOLVER         = .true.
 ADIOS_FOR_SOLVER_MESHFILES      = .true.
 ADIOS_FOR_AVS_DX                = .true.
+ADIOS_FOR_KERNELS               = .true.
+ADIOS_FOR_MODELS                = .true.
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/test_global/Par_file_NOISE_1_attenuation
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/test_global/Par_file_NOISE_1_attenuation	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/test_global/Par_file_NOISE_1_attenuation	2013-10-07 15:14:08 UTC (rev 22929)
@@ -127,7 +127,36 @@
 # print source time function
 PRINT_SOURCE_TIME_FUNCTION      = .true.
 
-# output kernels on a regular grid instead of on the mesh points
+#-----------------------------------------------------------
+#
+#  adjoint kernel outputs
+#
+#-----------------------------------------------------------
+
+# this parameter must be set to .true. to compute anisotropic kernels
+# in crust and mantle (related to the 21 Cij in geographical coordinates)
+# default is .false. to compute isotropic kernels (related to alpha and beta)
+ANISOTROPIC_KL                  = .false.
+
+# output only transverse isotropic kernels (alpha_v,alpha_h,beta_v,beta_h,eta,rho)
+# rather than fully anisotropic kernels when ANISOTROPIC_KL above is set to .true.
+# means to save radial anisotropic kernels, i.e., sensitivity kernels for beta_v, beta_h, etc.
+SAVE_TRANSVERSE_KL_ONLY         = .false.
+
+# output approximate Hessian in crust mantle region.
+# means to save the preconditioning for gradients, they are cross correlations between forward and adjoint accelerations.
+APPROXIMATE_HESS_KL             = .false.
+
+# forces transverse isotropy for all mantle elements
+# (default is to use transverse isotropy only between MOHO and 220)
+# means we allow radial anisotropy between the bottom of the crust to the bottom of the transition zone, i.e., 660~km depth.
+USE_FULL_TISO_MANTLE            = .false.
+
+# output kernel mask to zero out source region
+# to remove large values near the sources in the sensitivity kernels
+SAVE_SOURCE_MASK                = .false.
+
+# output kernels on a regular grid instead of on the GLL mesh points (a bit expensive)
 SAVE_REGULAR_KL                 = .false.
 
 #-----------------------------------------------------------
@@ -142,4 +171,6 @@
 ADIOS_FOR_ARRAYS_SOLVER         = .true.
 ADIOS_FOR_SOLVER_MESHFILES      = .true.
 ADIOS_FOR_AVS_DX                = .true.
+ADIOS_FOR_KERNELS               = .true.
+ADIOS_FOR_MODELS                = .true.
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/test_global/Par_file_NOISE_1_noattenuation
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/test_global/Par_file_NOISE_1_noattenuation	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/test_global/Par_file_NOISE_1_noattenuation	2013-10-07 15:14:08 UTC (rev 22929)
@@ -127,7 +127,36 @@
 # print source time function
 PRINT_SOURCE_TIME_FUNCTION      = .true.
 
-# output kernels on a regular grid instead of on the mesh points
+#-----------------------------------------------------------
+#
+#  adjoint kernel outputs
+#
+#-----------------------------------------------------------
+
+# this parameter must be set to .true. to compute anisotropic kernels
+# in crust and mantle (related to the 21 Cij in geographical coordinates)
+# default is .false. to compute isotropic kernels (related to alpha and beta)
+ANISOTROPIC_KL                  = .false.
+
+# output only transverse isotropic kernels (alpha_v,alpha_h,beta_v,beta_h,eta,rho)
+# rather than fully anisotropic kernels when ANISOTROPIC_KL above is set to .true.
+# means to save radial anisotropic kernels, i.e., sensitivity kernels for beta_v, beta_h, etc.
+SAVE_TRANSVERSE_KL_ONLY         = .false.
+
+# output approximate Hessian in crust mantle region.
+# means to save the preconditioning for gradients, they are cross correlations between forward and adjoint accelerations.
+APPROXIMATE_HESS_KL             = .false.
+
+# forces transverse isotropy for all mantle elements
+# (default is to use transverse isotropy only between MOHO and 220)
+# means we allow radial anisotropy between the bottom of the crust to the bottom of the transition zone, i.e., 660~km depth.
+USE_FULL_TISO_MANTLE            = .false.
+
+# output kernel mask to zero out source region
+# to remove large values near the sources in the sensitivity kernels
+SAVE_SOURCE_MASK                = .false.
+
+# output kernels on a regular grid instead of on the GLL mesh points (a bit expensive)
 SAVE_REGULAR_KL                 = .false.
 
 #-----------------------------------------------------------
@@ -142,4 +171,6 @@
 ADIOS_FOR_ARRAYS_SOLVER         = .true.
 ADIOS_FOR_SOLVER_MESHFILES      = .true.
 ADIOS_FOR_AVS_DX                = .true.
+ADIOS_FOR_KERNELS               = .true.
+ADIOS_FOR_MODELS                = .true.
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/test_global/Par_file_NOISE_2_attenuation
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/test_global/Par_file_NOISE_2_attenuation	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/test_global/Par_file_NOISE_2_attenuation	2013-10-07 15:14:08 UTC (rev 22929)
@@ -127,7 +127,36 @@
 # print source time function
 PRINT_SOURCE_TIME_FUNCTION      = .true.
 
-# output kernels on a regular grid instead of on the mesh points
+#-----------------------------------------------------------
+#
+#  adjoint kernel outputs
+#
+#-----------------------------------------------------------
+
+# this parameter must be set to .true. to compute anisotropic kernels
+# in crust and mantle (related to the 21 Cij in geographical coordinates)
+# default is .false. to compute isotropic kernels (related to alpha and beta)
+ANISOTROPIC_KL                  = .false.
+
+# output only transverse isotropic kernels (alpha_v,alpha_h,beta_v,beta_h,eta,rho)
+# rather than fully anisotropic kernels when ANISOTROPIC_KL above is set to .true.
+# means to save radial anisotropic kernels, i.e., sensitivity kernels for beta_v, beta_h, etc.
+SAVE_TRANSVERSE_KL_ONLY         = .false.
+
+# output approximate Hessian in crust mantle region.
+# means to save the preconditioning for gradients, they are cross correlations between forward and adjoint accelerations.
+APPROXIMATE_HESS_KL             = .false.
+
+# forces transverse isotropy for all mantle elements
+# (default is to use transverse isotropy only between MOHO and 220)
+# means we allow radial anisotropy between the bottom of the crust to the bottom of the transition zone, i.e., 660~km depth.
+USE_FULL_TISO_MANTLE            = .false.
+
+# output kernel mask to zero out source region
+# to remove large values near the sources in the sensitivity kernels
+SAVE_SOURCE_MASK                = .false.
+
+# output kernels on a regular grid instead of on the GLL mesh points (a bit expensive)
 SAVE_REGULAR_KL                 = .false.
 
 #-----------------------------------------------------------
@@ -142,4 +171,6 @@
 ADIOS_FOR_ARRAYS_SOLVER         = .true.
 ADIOS_FOR_SOLVER_MESHFILES      = .true.
 ADIOS_FOR_AVS_DX                = .true.
+ADIOS_FOR_KERNELS               = .true.
+ADIOS_FOR_MODELS                = .true.
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/test_global/Par_file_NOISE_2_noattenuation
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/test_global/Par_file_NOISE_2_noattenuation	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/test_global/Par_file_NOISE_2_noattenuation	2013-10-07 15:14:08 UTC (rev 22929)
@@ -127,7 +127,36 @@
 # print source time function
 PRINT_SOURCE_TIME_FUNCTION      = .true.
 
-# output kernels on a regular grid instead of on the mesh points
+#-----------------------------------------------------------
+#
+#  adjoint kernel outputs
+#
+#-----------------------------------------------------------
+
+# this parameter must be set to .true. to compute anisotropic kernels
+# in crust and mantle (related to the 21 Cij in geographical coordinates)
+# default is .false. to compute isotropic kernels (related to alpha and beta)
+ANISOTROPIC_KL                  = .false.
+
+# output only transverse isotropic kernels (alpha_v,alpha_h,beta_v,beta_h,eta,rho)
+# rather than fully anisotropic kernels when ANISOTROPIC_KL above is set to .true.
+# means to save radial anisotropic kernels, i.e., sensitivity kernels for beta_v, beta_h, etc.
+SAVE_TRANSVERSE_KL_ONLY         = .false.
+
+# output approximate Hessian in crust mantle region.
+# means to save the preconditioning for gradients, they are cross correlations between forward and adjoint accelerations.
+APPROXIMATE_HESS_KL             = .false.
+
+# forces transverse isotropy for all mantle elements
+# (default is to use transverse isotropy only between MOHO and 220)
+# means we allow radial anisotropy between the bottom of the crust to the bottom of the transition zone, i.e., 660~km depth.
+USE_FULL_TISO_MANTLE            = .false.
+
+# output kernel mask to zero out source region
+# to remove large values near the sources in the sensitivity kernels
+SAVE_SOURCE_MASK                = .false.
+
+# output kernels on a regular grid instead of on the GLL mesh points (a bit expensive)
 SAVE_REGULAR_KL                 = .false.
 
 #-----------------------------------------------------------
@@ -142,4 +171,6 @@
 ADIOS_FOR_ARRAYS_SOLVER         = .true.
 ADIOS_FOR_SOLVER_MESHFILES      = .true.
 ADIOS_FOR_AVS_DX                = .true.
+ADIOS_FOR_KERNELS               = .true.
+ADIOS_FOR_MODELS                = .true.
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/test_global/Par_file_NOISE_3_noattenuation
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/test_global/Par_file_NOISE_3_noattenuation	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/test_global/Par_file_NOISE_3_noattenuation	2013-10-07 15:14:08 UTC (rev 22929)
@@ -127,7 +127,36 @@
 # print source time function
 PRINT_SOURCE_TIME_FUNCTION      = .true.
 
-# output kernels on a regular grid instead of on the mesh points
+#-----------------------------------------------------------
+#
+#  adjoint kernel outputs
+#
+#-----------------------------------------------------------
+
+# this parameter must be set to .true. to compute anisotropic kernels
+# in crust and mantle (related to the 21 Cij in geographical coordinates)
+# default is .false. to compute isotropic kernels (related to alpha and beta)
+ANISOTROPIC_KL                  = .false.
+
+# output only transverse isotropic kernels (alpha_v,alpha_h,beta_v,beta_h,eta,rho)
+# rather than fully anisotropic kernels when ANISOTROPIC_KL above is set to .true.
+# means to save radial anisotropic kernels, i.e., sensitivity kernels for beta_v, beta_h, etc.
+SAVE_TRANSVERSE_KL_ONLY         = .false.
+
+# output approximate Hessian in crust mantle region.
+# means to save the preconditioning for gradients, they are cross correlations between forward and adjoint accelerations.
+APPROXIMATE_HESS_KL             = .false.
+
+# forces transverse isotropy for all mantle elements
+# (default is to use transverse isotropy only between MOHO and 220)
+# means we allow radial anisotropy between the bottom of the crust to the bottom of the transition zone, i.e., 660~km depth.
+USE_FULL_TISO_MANTLE            = .false.
+
+# output kernel mask to zero out source region
+# to remove large values near the sources in the sensitivity kernels
+SAVE_SOURCE_MASK                = .false.
+
+# output kernels on a regular grid instead of on the GLL mesh points (a bit expensive)
 SAVE_REGULAR_KL                 = .false.
 
 #-----------------------------------------------------------
@@ -142,4 +171,6 @@
 ADIOS_FOR_ARRAYS_SOLVER         = .true.
 ADIOS_FOR_SOLVER_MESHFILES      = .true.
 ADIOS_FOR_AVS_DX                = .true.
+ADIOS_FOR_KERNELS               = .true.
+ADIOS_FOR_MODELS                = .true.
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/test_regional/Par_file_NOISE_1_attenuation
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/test_regional/Par_file_NOISE_1_attenuation	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/test_regional/Par_file_NOISE_1_attenuation	2013-10-07 15:14:08 UTC (rev 22929)
@@ -127,7 +127,36 @@
 # print source time function
 PRINT_SOURCE_TIME_FUNCTION      = .true.
 
-# output kernels on a regular grid instead of on the mesh points
+#-----------------------------------------------------------
+#
+#  adjoint kernel outputs
+#
+#-----------------------------------------------------------
+
+# this parameter must be set to .true. to compute anisotropic kernels
+# in crust and mantle (related to the 21 Cij in geographical coordinates)
+# default is .false. to compute isotropic kernels (related to alpha and beta)
+ANISOTROPIC_KL                  = .false.
+
+# output only transverse isotropic kernels (alpha_v,alpha_h,beta_v,beta_h,eta,rho)
+# rather than fully anisotropic kernels when ANISOTROPIC_KL above is set to .true.
+# means to save radial anisotropic kernels, i.e., sensitivity kernels for beta_v, beta_h, etc.
+SAVE_TRANSVERSE_KL_ONLY         = .false.
+
+# output approximate Hessian in crust mantle region.
+# means to save the preconditioning for gradients, they are cross correlations between forward and adjoint accelerations.
+APPROXIMATE_HESS_KL             = .false.
+
+# forces transverse isotropy for all mantle elements
+# (default is to use transverse isotropy only between MOHO and 220)
+# means we allow radial anisotropy between the bottom of the crust to the bottom of the transition zone, i.e., 660~km depth.
+USE_FULL_TISO_MANTLE            = .false.
+
+# output kernel mask to zero out source region
+# to remove large values near the sources in the sensitivity kernels
+SAVE_SOURCE_MASK                = .false.
+
+# output kernels on a regular grid instead of on the GLL mesh points (a bit expensive)
 SAVE_REGULAR_KL                 = .false.
 
 #-----------------------------------------------------------
@@ -142,4 +171,6 @@
 ADIOS_FOR_ARRAYS_SOLVER         = .true.
 ADIOS_FOR_SOLVER_MESHFILES      = .true.
 ADIOS_FOR_AVS_DX                = .true.
+ADIOS_FOR_KERNELS               = .true.
+ADIOS_FOR_MODELS                = .true.
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/test_regional/Par_file_NOISE_1_noattenuation
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/test_regional/Par_file_NOISE_1_noattenuation	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/test_regional/Par_file_NOISE_1_noattenuation	2013-10-07 15:14:08 UTC (rev 22929)
@@ -127,7 +127,36 @@
 # print source time function
 PRINT_SOURCE_TIME_FUNCTION      = .true.
 
-# output kernels on a regular grid instead of on the mesh points
+#-----------------------------------------------------------
+#
+#  adjoint kernel outputs
+#
+#-----------------------------------------------------------
+
+# this parameter must be set to .true. to compute anisotropic kernels
+# in crust and mantle (related to the 21 Cij in geographical coordinates)
+# default is .false. to compute isotropic kernels (related to alpha and beta)
+ANISOTROPIC_KL                  = .false.
+
+# output only transverse isotropic kernels (alpha_v,alpha_h,beta_v,beta_h,eta,rho)
+# rather than fully anisotropic kernels when ANISOTROPIC_KL above is set to .true.
+# means to save radial anisotropic kernels, i.e., sensitivity kernels for beta_v, beta_h, etc.
+SAVE_TRANSVERSE_KL_ONLY         = .false.
+
+# output approximate Hessian in crust mantle region.
+# means to save the preconditioning for gradients, they are cross correlations between forward and adjoint accelerations.
+APPROXIMATE_HESS_KL             = .false.
+
+# forces transverse isotropy for all mantle elements
+# (default is to use transverse isotropy only between MOHO and 220)
+# means we allow radial anisotropy between the bottom of the crust to the bottom of the transition zone, i.e., 660~km depth.
+USE_FULL_TISO_MANTLE            = .false.
+
+# output kernel mask to zero out source region
+# to remove large values near the sources in the sensitivity kernels
+SAVE_SOURCE_MASK                = .false.
+
+# output kernels on a regular grid instead of on the GLL mesh points (a bit expensive)
 SAVE_REGULAR_KL                 = .false.
 
 #-----------------------------------------------------------
@@ -142,4 +171,6 @@
 ADIOS_FOR_ARRAYS_SOLVER         = .true.
 ADIOS_FOR_SOLVER_MESHFILES      = .true.
 ADIOS_FOR_AVS_DX                = .true.
+ADIOS_FOR_KERNELS               = .true.
+ADIOS_FOR_MODELS                = .true.
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/test_regional/Par_file_NOISE_2_attenuation
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/test_regional/Par_file_NOISE_2_attenuation	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/test_regional/Par_file_NOISE_2_attenuation	2013-10-07 15:14:08 UTC (rev 22929)
@@ -127,7 +127,36 @@
 # print source time function
 PRINT_SOURCE_TIME_FUNCTION      = .true.
 
-# output kernels on a regular grid instead of on the mesh points
+#-----------------------------------------------------------
+#
+#  adjoint kernel outputs
+#
+#-----------------------------------------------------------
+
+# this parameter must be set to .true. to compute anisotropic kernels
+# in crust and mantle (related to the 21 Cij in geographical coordinates)
+# default is .false. to compute isotropic kernels (related to alpha and beta)
+ANISOTROPIC_KL                  = .false.
+
+# output only transverse isotropic kernels (alpha_v,alpha_h,beta_v,beta_h,eta,rho)
+# rather than fully anisotropic kernels when ANISOTROPIC_KL above is set to .true.
+# means to save radial anisotropic kernels, i.e., sensitivity kernels for beta_v, beta_h, etc.
+SAVE_TRANSVERSE_KL_ONLY         = .false.
+
+# output approximate Hessian in crust mantle region.
+# means to save the preconditioning for gradients, they are cross correlations between forward and adjoint accelerations.
+APPROXIMATE_HESS_KL             = .false.
+
+# forces transverse isotropy for all mantle elements
+# (default is to use transverse isotropy only between MOHO and 220)
+# means we allow radial anisotropy between the bottom of the crust to the bottom of the transition zone, i.e., 660~km depth.
+USE_FULL_TISO_MANTLE            = .false.
+
+# output kernel mask to zero out source region
+# to remove large values near the sources in the sensitivity kernels
+SAVE_SOURCE_MASK                = .false.
+
+# output kernels on a regular grid instead of on the GLL mesh points (a bit expensive)
 SAVE_REGULAR_KL                 = .false.
 
 #-----------------------------------------------------------
@@ -142,4 +171,6 @@
 ADIOS_FOR_ARRAYS_SOLVER         = .true.
 ADIOS_FOR_SOLVER_MESHFILES      = .true.
 ADIOS_FOR_AVS_DX                = .true.
+ADIOS_FOR_KERNELS               = .true.
+ADIOS_FOR_MODELS                = .true.
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/test_regional/Par_file_NOISE_2_noattenuation
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/test_regional/Par_file_NOISE_2_noattenuation	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/test_regional/Par_file_NOISE_2_noattenuation	2013-10-07 15:14:08 UTC (rev 22929)
@@ -127,7 +127,36 @@
 # print source time function
 PRINT_SOURCE_TIME_FUNCTION      = .true.
 
-# output kernels on a regular grid instead of on the mesh points
+#-----------------------------------------------------------
+#
+#  adjoint kernel outputs
+#
+#-----------------------------------------------------------
+
+# this parameter must be set to .true. to compute anisotropic kernels
+# in crust and mantle (related to the 21 Cij in geographical coordinates)
+# default is .false. to compute isotropic kernels (related to alpha and beta)
+ANISOTROPIC_KL                  = .false.
+
+# output only transverse isotropic kernels (alpha_v,alpha_h,beta_v,beta_h,eta,rho)
+# rather than fully anisotropic kernels when ANISOTROPIC_KL above is set to .true.
+# means to save radial anisotropic kernels, i.e., sensitivity kernels for beta_v, beta_h, etc.
+SAVE_TRANSVERSE_KL_ONLY         = .false.
+
+# output approximate Hessian in crust mantle region.
+# means to save the preconditioning for gradients, they are cross correlations between forward and adjoint accelerations.
+APPROXIMATE_HESS_KL             = .false.
+
+# forces transverse isotropy for all mantle elements
+# (default is to use transverse isotropy only between MOHO and 220)
+# means we allow radial anisotropy between the bottom of the crust to the bottom of the transition zone, i.e., 660~km depth.
+USE_FULL_TISO_MANTLE            = .false.
+
+# output kernel mask to zero out source region
+# to remove large values near the sources in the sensitivity kernels
+SAVE_SOURCE_MASK                = .false.
+
+# output kernels on a regular grid instead of on the GLL mesh points (a bit expensive)
 SAVE_REGULAR_KL                 = .false.
 
 #-----------------------------------------------------------
@@ -142,4 +171,6 @@
 ADIOS_FOR_ARRAYS_SOLVER         = .true.
 ADIOS_FOR_SOLVER_MESHFILES      = .true.
 ADIOS_FOR_AVS_DX                = .true.
+ADIOS_FOR_KERNELS               = .true.
+ADIOS_FOR_MODELS                = .true.
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/test_regional/Par_file_NOISE_3_noattenuation
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/test_regional/Par_file_NOISE_3_noattenuation	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/noise_examples/test_regional/Par_file_NOISE_3_noattenuation	2013-10-07 15:14:08 UTC (rev 22929)
@@ -127,7 +127,36 @@
 # print source time function
 PRINT_SOURCE_TIME_FUNCTION      = .true.
 
-# output kernels on a regular grid instead of on the mesh points
+#-----------------------------------------------------------
+#
+#  adjoint kernel outputs
+#
+#-----------------------------------------------------------
+
+# this parameter must be set to .true. to compute anisotropic kernels
+# in crust and mantle (related to the 21 Cij in geographical coordinates)
+# default is .false. to compute isotropic kernels (related to alpha and beta)
+ANISOTROPIC_KL                  = .false.
+
+# output only transverse isotropic kernels (alpha_v,alpha_h,beta_v,beta_h,eta,rho)
+# rather than fully anisotropic kernels when ANISOTROPIC_KL above is set to .true.
+# means to save radial anisotropic kernels, i.e., sensitivity kernels for beta_v, beta_h, etc.
+SAVE_TRANSVERSE_KL_ONLY         = .false.
+
+# output approximate Hessian in crust mantle region.
+# means to save the preconditioning for gradients, they are cross correlations between forward and adjoint accelerations.
+APPROXIMATE_HESS_KL             = .false.
+
+# forces transverse isotropy for all mantle elements
+# (default is to use transverse isotropy only between MOHO and 220)
+# means we allow radial anisotropy between the bottom of the crust to the bottom of the transition zone, i.e., 660~km depth.
+USE_FULL_TISO_MANTLE            = .false.
+
+# output kernel mask to zero out source region
+# to remove large values near the sources in the sensitivity kernels
+SAVE_SOURCE_MASK                = .false.
+
+# output kernels on a regular grid instead of on the GLL mesh points (a bit expensive)
 SAVE_REGULAR_KL                 = .false.
 
 #-----------------------------------------------------------
@@ -142,4 +171,6 @@
 ADIOS_FOR_ARRAYS_SOLVER         = .true.
 ADIOS_FOR_SOLVER_MESHFILES      = .true.
 ADIOS_FOR_AVS_DX                = .true.
+ADIOS_FOR_KERNELS               = .true.
+ADIOS_FOR_MODELS                = .true.
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/regional_Greece_noise_small/DATA/Par_file
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/regional_Greece_noise_small/DATA/Par_file	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/regional_Greece_noise_small/DATA/Par_file	2013-10-07 15:14:08 UTC (rev 22929)
@@ -197,4 +197,6 @@
 ADIOS_FOR_ARRAYS_SOLVER         = .true.
 ADIOS_FOR_SOLVER_MESHFILES      = .true.
 ADIOS_FOR_AVS_DX                = .true.
+ADIOS_FOR_KERNELS               = .true.
+ADIOS_FOR_MODELS                = .true.
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/regional_Greece_small/DATA/Par_file
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/regional_Greece_small/DATA/Par_file	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/regional_Greece_small/DATA/Par_file	2013-10-07 15:14:08 UTC (rev 22929)
@@ -197,4 +197,6 @@
 ADIOS_FOR_ARRAYS_SOLVER         = .true.
 ADIOS_FOR_SOLVER_MESHFILES      = .true.
 ADIOS_FOR_AVS_DX                = .true.
+ADIOS_FOR_KERNELS               = .true.
+ADIOS_FOR_MODELS                = .true.
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/regional_MiddleEast/DATA/Par_file
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/regional_MiddleEast/DATA/Par_file	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/regional_MiddleEast/DATA/Par_file	2013-10-07 15:14:08 UTC (rev 22929)
@@ -197,4 +197,6 @@
 ADIOS_FOR_ARRAYS_SOLVER         = .true.
 ADIOS_FOR_SOLVER_MESHFILES      = .true.
 ADIOS_FOR_AVS_DX                = .true.
+ADIOS_FOR_KERNELS               = .true.
+ADIOS_FOR_MODELS                = .true.
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/small_benchmark_run_to_test_more_complex_Earth/Par_file
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/small_benchmark_run_to_test_more_complex_Earth/Par_file	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/small_benchmark_run_to_test_more_complex_Earth/Par_file	2013-10-07 15:14:08 UTC (rev 22929)
@@ -197,4 +197,6 @@
 ADIOS_FOR_ARRAYS_SOLVER         = .true.
 ADIOS_FOR_SOLVER_MESHFILES      = .true.
 ADIOS_FOR_AVS_DX                = .true.
+ADIOS_FOR_KERNELS               = .true.
+ADIOS_FOR_MODELS                = .true.
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/small_benchmark_run_to_test_very_simple_Earth/Par_file
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/small_benchmark_run_to_test_very_simple_Earth/Par_file	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/EXAMPLES/small_benchmark_run_to_test_very_simple_Earth/Par_file	2013-10-07 15:14:08 UTC (rev 22929)
@@ -197,4 +197,6 @@
 ADIOS_FOR_ARRAYS_SOLVER         = .true.
 ADIOS_FOR_SOLVER_MESHFILES      = .true.
 ADIOS_FOR_AVS_DX                = .true.
+ADIOS_FOR_KERNELS               = .true.
+ADIOS_FOR_MODELS                = .true.
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/Makefile.in
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/Makefile.in	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/Makefile.in	2013-10-07 15:14:08 UTC (rev 22929)
@@ -106,7 +106,7 @@
 @COND_CUDA_TRUE@@COND_CUDA5_TRUE at NVCCLINK = $(NVCCLINK_BASE) -dlink $(GENCODE)
 @COND_CUDA_TRUE@@COND_CUDA5_FALSE at NVCCLINK = $(NVCCLINK_BASE) -DUSE_OLDER_CUDA4_GPU $(GENCODE)
 
- at COND_CUDA_FALSE@NVCC_FLAGS = $(MPI_INC)
+ at COND_CUDA_FALSE@NVCC_FLAGS =
 @COND_CUDA_FALSE at NVCCLINK = $(NVCC) $(NVCC_FLAGS)
 
 #######################################
@@ -119,23 +119,57 @@
 @COND_VTK_TRUE at VTK = yes
 @COND_VTK_FALSE at VTK = no
 
- at COND_VTK_TRUE@CPPFLAGS += -DWITH_VTK
- at COND_VTK_TRUE@FCCOMPILE_CHECK += -DWITH_VTK
-#@COND_VTK_TRUE at FCCOMPILE_NO_CHECK += -DWITH_VTK
- at COND_VTK_TRUE@MPIFCCOMPILE_CHECK += -DWITH_VTK
-#@COND_VTK_TRUE at MPIFCCOMPILE_NO_CHECK += -DWITH_VTK
+ at COND_VTK_TRUE@VTK_LIBS = -lvtkHybrid -lvtkVolumeRendering -lvtkRendering \
+    -lvtkIO -lvtkGenericFiltering -lvtkGraphics -lvtkImaging -lvtkFiltering \
+    -lvtkCommon -lvtkftgl -lvtkfreetype -lvtkDICOMParser -lvtkexpat \
+    -lvtktiff -lvtkpng -lvtkjpeg -lvtkzlib -lvtksys
+ at COND_VTK_FALSE@VTK_LIBS =
 
+VTK_LINK = $(VTK_LIBS)
+
+## conditional compilation flag
+#ifeq ($(findstring xlf,$(FC)),xlf)
+## ibm compiler flag
+#VTK_FLAG = -WF,-DWITH_VTK
+#else
+## gnu,intel,pgi,..
+#VTK_FLAG = -DWITH_VTK
+#endif
+
+#@COND_VTK_TRUE at CPPFLAGS += $(VTK_FLAG)
+#@COND_VTK_TRUE at FCCOMPILE_CHECK += $(VTK_FLAG)
+##@COND_VTK_TRUE at FCCOMPILE_NO_CHECK += $(VTK_FLAG)
+#@COND_VTK_TRUE at MPIFCCOMPILE_CHECK += $(VTK_FLAG)
+##@COND_VTK_TRUE at MPIFCCOMPILE_NO_CHECK += $(VTK_FLAG)
+
+ at COND_VTK_TRUE@MPILIBS += $(VTK_LINK)
+
 #######################################
 ####
 #### ADIOS
-#### with configure: ./configure --with-adios ..
+#### with configure: ./configure --with-cuda ADIOS_LIB=.. ADIOS_INC=.. MPI_INC=..
 ####
 #######################################
 
 @COND_ADIOS_TRUE at ADIOS = yes
 @COND_ADIOS_FALSE at ADIOS = no
 
+ 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@
+
+#@COND_ADIOS_TRUE at CPPFLAGS += $(ADIOS_INC)
+#@COND_ADIOS_TRUE at FCCOMPILE_CHECK += $(ADIOS_INC)
+##@COND_ADIOS_TRUE at FCCOMPILE_NO_CHECK += $(ADIOS_INC)
+#@COND_ADIOS_TRUE at MPIFCCOMPILE_CHECK += $(ADIOS_INC)
+##@COND_ADIOS_TRUE at MPIFCCOMPILE_NO_CHECK += $(ADIOS_INC)
+
+ at COND_ADIOS_TRUE@MPILIBS += $(ADIOS_LINK)
+
+
 #######################################
 ####
 #### FORCE_VECTORIZATION
@@ -145,14 +179,23 @@
 @COND_VECTORIZATION_TRUE at FORCE_VECTORIZATION = yes
 @COND_VECTORIZATION_FALSE at FORCE_VECTORIZATION = no
 
- at COND_VECTORIZATION_TRUE@CPPFLAGS += -DFORCE_VECTORIZATION
- at COND_VECTORIZATION_TRUE@FCCOMPILE_CHECK += -DFORCE_VECTORIZATION
-#@COND_VECTORIZATION_TRUE at FCCOMPILE_NO_CHECK += -DFORCE_VECTORIZATION
- at COND_VECTORIZATION_TRUE@MPIFCCOMPILE_CHECK += -DFORCE_VECTORIZATION
-#@COND_VECTORIZATION_TRUE at MPIFCCOMPILE_NO_CHECK += -DFORCE_VECTORIZATION
+# conditional compilation flag
+#ifeq ($(findstring xlf,$(FC)),xlf)
+## ibm compiler flag
+#VEC_FLAG = -WF,-DFORCE_VECTORIZATION
+#else
+## gnu,intel,pgi,..
+#VEC_FLAG = -DFORCE_VECTORIZATION
+#endif
 
+#@COND_VECTORIZATION_TRUE at CPPFLAGS += $(VEC_FLAG)
+#@COND_VECTORIZATION_TRUE at FCCOMPILE_CHECK += $(VEC_FLAG)
+##@COND_VECTORIZATION_TRUE at FCCOMPILE_NO_CHECK += $(VEC_FLAG)
+#@COND_VECTORIZATION_TRUE at MPIFCCOMPILE_CHECK += $(VEC_FLAG)
+##@COND_VECTORIZATION_TRUE at MPIFCCOMPILE_NO_CHECK += $(VEC_FLAG)
 
 
+
 #######################################
 ####
 #### directories

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/configure
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/configure	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/configure	2013-10-07 15:14:08 UTC (rev 22929)
@@ -1,6 +1,6 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.69 for Specfem3D Globe 6.0.0.
+# Generated by GNU Autoconf 2.69 for Specfem3D_Globe 6.0.0.
 #
 # Report bugs to <jtromp AT princeton.edu>.
 #
@@ -578,10 +578,10 @@
 MAKEFLAGS=
 
 # Identity of this package.
-PACKAGE_NAME='Specfem3D Globe'
+PACKAGE_NAME='Specfem3D_Globe'
 PACKAGE_TARNAME='Specfem3DGlobe'
 PACKAGE_VERSION='6.0.0'
-PACKAGE_STRING='Specfem3D Globe 6.0.0'
+PACKAGE_STRING='Specfem3D_Globe 6.0.0'
 PACKAGE_BUGREPORT='jtromp AT princeton.edu'
 PACKAGE_URL=''
 
@@ -629,15 +629,21 @@
 ac_empty
 FC_MODINC
 FC_MODEXT
+NVCC
+CONFIGURE_FLAGS
 LOCAL_PATH_IS_ALSO_GLOBAL
 RANLIB
 ARFLAGS
 AR
-MPI_INC
 CUDA_INC
 CUDA_LIB
+ADIOS_LIB
+ADIOS_INC
+MXML_LIB
+MXML_INC
 FLAGS_NO_CHECK
 FLAGS_CHECK
+MPI_INC
 MPILIBS
 MPIFC
 EGREP
@@ -736,11 +742,15 @@
 CPP
 MPIFC
 MPILIBS
+MPI_INC
 FLAGS_CHECK
 FLAGS_NO_CHECK
+MXML_INC
+MXML_LIB
+ADIOS_INC
+ADIOS_LIB
 CUDA_LIB
 CUDA_INC
-MPI_INC
 AR
 ARFLAGS
 RANLIB
@@ -1285,7 +1295,7 @@
   # Omit some internal or obsolete options to make the list less imposing.
   # This message is too long to be a string in the A/UX 3.1 sh.
   cat <<_ACEOF
-\`configure' configures Specfem3D Globe 6.0.0 to adapt to many kinds of systems.
+\`configure' configures Specfem3D_Globe 6.0.0 to adapt to many kinds of systems.
 
 Usage: $0 [OPTION]... [VAR=VALUE]...
 
@@ -1350,7 +1360,7 @@
 
 if test -n "$ac_init_help"; then
   case $ac_init_help in
-     short | recursive ) echo "Configuration of Specfem3D Globe 6.0.0:";;
+     short | recursive ) echo "Configuration of Specfem3D_Globe 6.0.0:";;
    esac
   cat <<\_ACEOF
 
@@ -1368,7 +1378,7 @@
   --with-vtk              build VTK enabled version [default=no]
   --with-adios            build ADIOS enabled version [default=no]
   --with-vec              build FORCE_VECTORIZATION enabled version
-                          [default=no]
+                          [default=yes]
 
 Some influential environment variables:
   FC          Fortran compiler command
@@ -1383,14 +1393,18 @@
   CPP         C preprocessor
   MPIFC       MPI Fortran compiler command
   MPILIBS     extra libraries for linking MPI programs
+  MPI_INC     Directory where MPI include file mpi.h is installed, which is
+              needed by ADIOS/CUDA when compiling
   FLAGS_CHECK Fortran compiler flags for non-critical subroutines
   FLAGS_NO_CHECK
               Fortran compiler flags for creating fast, production-run code
               for critical subroutines
-  CUDA_LIB    Location of CUDA library libcudart
-  CUDA_INC    Location of CUDA include files
-  MPI_INC     Location of MPI include mpi.h, which is needed by nvcc when
-              compiling cuda files
+  MXML_INC    Directory where MXML headers are installed
+  MXML_LIB    Directory where MXML libraries are installed
+  ADIOS_INC   Directory where ADIOS headers are installed
+  ADIOS_LIB   Directory where ADIOS libraries are installed
+  CUDA_LIB    Directory where CUDA library libcudart is installed
+  CUDA_INC    Directory where CUDA include files are installed
   AR          ar library creation
   ARFLAGS     ar flag library creation
   RANLIB      ranlib library creation
@@ -1464,7 +1478,7 @@
 test -n "$ac_init_help" && exit $ac_status
 if $ac_init_version; then
   cat <<\_ACEOF
-Specfem3D Globe configure 6.0.0
+Specfem3D_Globe configure 6.0.0
 generated by GNU Autoconf 2.69
 
 Copyright (C) 2012 Free Software Foundation, Inc.
@@ -1804,7 +1818,7 @@
 This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
 
-It was created by Specfem3D Globe $as_me 6.0.0, which was
+It was created by Specfem3D_Globe $as_me 6.0.0, which was
 generated by GNU Autoconf 2.69.  Invocation command line was
 
   $ $0 $@
@@ -2153,10 +2167,17 @@
 
 
 
+
 ac_config_headers="$ac_config_headers setup/config.h"
 
 
 
+
+############################################################
+
+$as_echo "## ---------------------------- ##
+## setting up compilation flags ##
+## ---------------------------- ##"
 ac_aux_dir=
 for ac_dir in "$srcdir" "$srcdir/.." "$srcdir/../.."; do
   if test -f "$ac_dir/install-sh"; then
@@ -2263,6 +2284,7 @@
 ###
 ### precision
 ###
+
 # Check whether --enable-double-precision was given.
 if test "${enable_double_precision+set}" = set; then :
   enableval=$enable_double_precision; want_double_precision="$enableval"
@@ -2284,6 +2306,7 @@
 ### CUDA
 ###
 
+
 # Check whether --with-cuda was given.
 if test "${with_cuda+set}" = set; then :
   withval=$with_cuda; want_cuda="$withval"
@@ -2312,6 +2335,7 @@
 ### VTK
 ###
 
+
 # Check whether --with-vtk was given.
 if test "${with_vtk+set}" = set; then :
   withval=$with_vtk; want_vtk="$withval"
@@ -2332,6 +2356,7 @@
 ### ADIOS
 ###
 
+
 # Check whether --with-adios was given.
 if test "${with_adios+set}" = set; then :
   withval=$with_adios; want_adios="$withval"
@@ -2348,16 +2373,16 @@
 fi
 
 
-
 ###
 ### FORCE_VECTORIZATION
 ###
 
+
 # Check whether --with-vec was given.
 if test "${with_vec+set}" = set; then :
   withval=$with_vec; want_vec="$withval"
 else
-  want_vec=no
+  want_vec=yes
 fi
 
  if test "$want_vec" != no; then
@@ -2369,6 +2394,8 @@
 fi
 
 
+############################################################
+
 # Checks for programs.
 
 # a courtesy to the installed base of users
@@ -5220,6 +5247,8 @@
 ac_compiler_gnu=$ac_cv_fc_compiler_gnu
 
 
+############################################################
+
 # influential environment variables
 
 
@@ -5229,26 +5258,49 @@
 
 
 
+# adios
 
 
 
 
 
+# cuda
 
-if test x"$MPIFC" = x; then
+
+
+
+
+
+
+# scratch disks
+
+
+############################################################
+
+# tests
+if test x"$MPIFC" = x; then :
+
     MPIFC=mpif90
+
 fi
 
+if test x"$LOCAL_PATH_IS_ALSO_GLOBAL" = x; then :
 
-if test x"$LOCAL_PATH_IS_ALSO_GLOBAL" = x; then
     LOCAL_PATH_IS_ALSO_GLOBAL=true
+
 fi
 
+if test x"$MPI_INC" != x; then :
 
+  CPPFLAGS+=" $MPI_INC"
+  FCFLAGS+=" $MPI_INC"
+  FLAGS_CHECK+=" $MPI_INC"
+  FLAGS_NO_CHECK+=" $MPI_INC"
 
+fi
+
 # Checks for libraries.
 
-
 # Checks for header files.
 
 
@@ -5365,16 +5417,108 @@
 
 
 
-if test "$want_adios" != no; then
+###
+### ADIOS
+###
 
+if test "$want_adios" != no; then :
 
+  $as_echo "## ----- ##
+## ADIOS ##
+## ----- ##"
+  { $as_echo "$as_me:${as_lineno-$LINENO}: ADIOS is enabled" >&5
+$as_echo "$as_me: ADIOS is enabled" >&6;}
 
+  # adds include/library directories to compile flags
+  if test x"$$MXML_INC" != x; then :
+
+    CPPFLAGS+=" $MXML_INC"
+
+fi
+  if test x"$MXML_LIB" != x; then :
+
+    LDFLAGS+=" $MXML_LIB"
+
+fi
+  if test x"$ADIOS_INC" != x; then :
+
+    CPPFLAGS+=" $ADIOS_INC"
+    FCFLAGS+=" $ADIOS_INC"
+    FLAGS_CHECK+=" $ADIOS_INC"
+    FLAGS_NO_CHECK+=" $ADIOS_INC"
+
+fi
+  if test x"$ADIOS_LIB" != x; then :
+
+    LDFLAGS+=" $ADIOS_LIB"
+
+fi
+
+  # checks
+
   ac_ext=c
 ac_cpp='$CPP $CPPFLAGS'
 ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
 ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
 ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
+  ac_fn_c_check_header_mongrel "$LINENO" "mxml.h" "ac_cv_header_mxml_h" "$ac_includes_default"
+if test "x$ac_cv_header_mxml_h" = xyes; then :
+
+else
+
+    as_fn_error $? "mxml C header not found; try CPPFLAGS=\"-I<mxml include dir>\"" "$LINENO" 5
+
+fi
+
+
+
+  ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for mxmlNewXML in -lmxml" >&5
+$as_echo_n "checking for mxmlNewXML in -lmxml... " >&6; }
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* 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
+if ac_fn_c_try_compile "$LINENO"; then :
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+     as_fn_error $? "mxml library not found; try LDFLAGS=\"-L<mxml lib dir>\"" "$LINENO" 5
+
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+
+  ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
   ac_fn_c_check_header_mongrel "$LINENO" "adios.h" "ac_cv_header_adios_h" "$ac_includes_default"
 if test "x$ac_cv_header_adios_h" = xyes; then :
 
@@ -5412,9 +5556,167 @@
 fi
 rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext    FC=$FC_BCK
 
+
 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=$FCFLAGS $FLAGS_CHECK"
+#AC_DEFINE_UNQUOTED([CONFIGURE_FLAGS],["${configure_flags_str}"],
+ #         [configuration flags to be saved in the adios output file.])
+CONFIGURE_FLAGS="FC=$FC FCFLAGS=$FCFLAGS"
+
+
+###
+### CUDA
+###
+
+if test "$want_cuda" != no; then :
+
+  $as_echo "## ---- ##
+## CUDA ##
+## ---- ##"
+  { $as_echo "$as_me:${as_lineno-$LINENO}: CUDA is enabled" >&5
+$as_echo "$as_me: CUDA is enabled" >&6;}
+
+  # checks
+
+  # 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_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_NVCC+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $NVCC in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_NVCC="$NVCC" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_NVCC="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+NVCC=$ac_cv_path_NVCC
+if test -n "$NVCC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $NVCC" >&5
+$as_echo "$NVCC" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$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: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "cannot find 'nvcc' program.
+See \`config.log' for more details" "$LINENO" 5; }
+    NVCC=`echo "Error: nvcc is not installed." ; false`
+  fi
+
+
+fi
+
+###
+### FORCE_VECTORIZATION
+###
+
+if test "$want_vec" != no; then :
+
+  $as_echo "## ------------------- ##
+## FORCE VECTORIZATION ##
+## ------------------- ##"
+  { $as_echo "$as_me:${as_lineno-$LINENO}: FORCE_VECTORIZATION is enabled" >&5
+$as_echo "$as_me: FORCE_VECTORIZATION is enabled" >&6;}
+
+  # adds conditional compilation flag
+  # fortran compiler
+  case $FC in #(
+  # ibm compiler flag
+    *xlf*|*/*xlf*) :
+    VEC_FLAG="-WF,-DFORCE_VECTORIZATION" ;; #(
+  *) :
+    # default: gnu,intel,pgi,..
+    VEC_FLAG="-DFORCE_VECTORIZATION"
+   ;;
+esac
+  FLAGS_CHECK+=" $VEC_FLAG"
+  FLAGS_NO_CHECK+=" $VEC_FLAG"
+  # c compiler
+  case $CC in #(
+  # ibm compiler flag
+    *xlc*|*/*xlc*) :
+    VEC_FLAG="-DFORCE_VECTORIZATION" ;; #(
+  *) :
+    # default: gnu,intel,pgi,..
+    VEC_FLAG="-DFORCE_VECTORIZATION"
+   ;;
+esac
+  CPPFLAGS+=" $VEC_FLAG"
+
+
+fi
+
+###
+### VTK
+###
+
+if test "$want_vtk" != no; then :
+
+  $as_echo "## --- ##
+## VTK ##
+## --- ##"
+  { $as_echo "$as_me:${as_lineno-$LINENO}: VTK is enabled" >&5
+$as_echo "$as_me: VTK is enabled" >&6;}
+
+  # adds conditional compilation flag
+  # fortran compiler
+  case $FC in #(
+  # ibm compiler flag
+    *xlf*|*/*xlf*) :
+    VTK_FLAG="-WF,-DWITH_VTK" ;; #(
+  *) :
+    # default: gnu,intel,pgi,..
+    VTK_FLAG="-DWITH_VTK"
+   ;;
+esac
+  FLAGS_CHECK+=" $VTK_FLAG"
+  FLAGS_NO_CHECK+=" $VTK_FLAG"
+  # c compiler
+  case $CC in #(
+  # ibm compiler flag
+    *xlc*|*/*xlc*) :
+    VTK_FLAG="-DWITH_VTK" ;; #(
+  *) :
+    # default: gnu,intel,pgi,..
+    VTK_FLAG="-DWITH_VTK"
+   ;;
+esac
+  CPPFLAGS+=" $VTK_FLAG"
+
+
+fi
+
+############################################################
+
 # Checks for typedefs, structures, and compiler characteristics.
+$as_echo "## ----------------- ##
+## module extensions ##
+## ----------------- ##"
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking Fortran 90 module extension" >&5
 $as_echo_n "checking Fortran 90 module extension... " >&6; }
@@ -5614,10 +5916,12 @@
 
 
 # Checks for library functions.
+$as_echo "## ----------------------------------- ##
+## setting up default simulation setup ##
+## ----------------------------------- ##"
 
+ac_config_files="$ac_config_files Makefile setup/constants.h setup/precision.h setup/config.fh"
 
-ac_config_files="$ac_config_files Makefile setup/constants.h setup/precision.h"
-
 ac_config_files="$ac_config_files DATA/Par_file:DATA/Par_file DATA/CMTSOLUTION:DATA/CMTSOLUTION DATA/STATIONS:DATA/STATIONS"
 
 ac_config_links="$ac_config_links DATA/crust2.0:DATA/crust2.0 DATA/crustmap:DATA/crustmap DATA/epcrust:DATA/epcrust DATA/eucrust-07:DATA/eucrust-07 DATA/heterogen:DATA/heterogen DATA/Lebedev_sea99:DATA/Lebedev_sea99 DATA/Montagner_model:DATA/Montagner_model DATA/old:DATA/old DATA/PPM:DATA/PPM DATA/QRFSI12:DATA/QRFSI12 DATA/s20rts:DATA/s20rts DATA/s362ani:DATA/s362ani DATA/s40rts:DATA/s40rts DATA/Simons_model:DATA/Simons_model DATA/topo_bathy:DATA/topo_bathy DATA/Zhao_JP_model:DATA/Zhao_JP_model"
@@ -6161,7 +6465,7 @@
 # report actual input values of CONFIG_FILES etc. instead of their
 # values after options handling.
 ac_log="
-This file was extended by Specfem3D Globe $as_me 6.0.0, which was
+This file was extended by Specfem3D_Globe $as_me 6.0.0, which was
 generated by GNU Autoconf 2.69.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
@@ -6231,7 +6535,7 @@
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
 ac_cs_version="\\
-Specfem3D Globe config.status 6.0.0
+Specfem3D_Globe config.status 6.0.0
 configured by $0, generated by GNU Autoconf 2.69,
   with options \\"\$ac_cs_config\\"
 
@@ -6356,6 +6660,7 @@
     "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
     "setup/constants.h") CONFIG_FILES="$CONFIG_FILES setup/constants.h" ;;
     "setup/precision.h") CONFIG_FILES="$CONFIG_FILES setup/precision.h" ;;
+    "setup/config.fh") CONFIG_FILES="$CONFIG_FILES setup/config.fh" ;;
     "DATA/Par_file") CONFIG_FILES="$CONFIG_FILES DATA/Par_file:DATA/Par_file" ;;
     "DATA/CMTSOLUTION") CONFIG_FILES="$CONFIG_FILES DATA/CMTSOLUTION:DATA/CMTSOLUTION" ;;
     "DATA/STATIONS") CONFIG_FILES="$CONFIG_FILES DATA/STATIONS:DATA/STATIONS" ;;
@@ -7006,6 +7311,7 @@
 
 
 
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: " >&5
 $as_echo "" >&6; }
 sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/configure.ac
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/configure.ac	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/configure.ac	2013-10-07 15:14:08 UTC (rev 22929)
@@ -6,13 +6,19 @@
 dnl
 dnl You must have recent versions of Autoconf and Automake installed.
 
+############################################################
 
 AC_PREREQ(2.61)
-AC_INIT([Specfem3D Globe], [6.0.0], [jtromp AT princeton.edu], [Specfem3DGlobe])
+AC_INIT([Specfem3D_Globe], [6.0.0], [jtromp AT princeton.edu], [Specfem3DGlobe])
 AC_CONFIG_SRCDIR([src/specfem3D/specfem3D.F90])
+
 AC_CONFIG_HEADER([setup/config.h])
+
 AC_CONFIG_MACRO_DIR([m4])
 
+############################################################
+
+AS_BOX([setting up compilation flags])
 AC_CANONICAL_HOST
 
 # 'configure' options
@@ -20,6 +26,7 @@
 ###
 ### precision
 ###
+
 AC_ARG_ENABLE([double-precision],
     [AS_HELP_STRING([--enable-double-precision],
         [solver in double precision @<:@default=no@:>@])],
@@ -38,6 +45,7 @@
 ###
 ### CUDA
 ###
+
 AC_ARG_WITH([cuda],
     [AC_HELP_STRING([--with-cuda],
         [build cuda GPU enabled version @<:@default=no@:>@])],
@@ -49,6 +57,7 @@
 ###
 ### VTK
 ###
+
 AC_ARG_WITH([vtk],
     [AC_HELP_STRING([--with-vtk],
         [build VTK enabled version @<:@default=no@:>@])],
@@ -59,6 +68,7 @@
 ###
 ### ADIOS
 ###
+
 AC_ARG_WITH([adios],
     [AC_HELP_STRING([--with-adios],
         [build ADIOS enabled version @<:@default=no@:>@])],
@@ -66,17 +76,19 @@
     [want_adios=no])
 AM_CONDITIONAL([COND_ADIOS], [test "$want_adios" != no])
 
-
 ###
 ### FORCE_VECTORIZATION
 ###
+
 AC_ARG_WITH([vec],
     [AC_HELP_STRING([--with-vec],
-        [build FORCE_VECTORIZATION enabled version @<:@default=no@:>@])],
+        [build FORCE_VECTORIZATION enabled version @<:@default=yes@:>@])],
     [want_vec="$withval"],
-    [want_vec=no])
+    [want_vec=yes])
 AM_CONDITIONAL([COND_VECTORIZATION], [test "$want_vec" != no])
 
+############################################################
+
 # Checks for programs.
 
 # a courtesy to the installed base of users
@@ -113,45 +125,171 @@
 AC_CHECK_HEADER(xmmintrin.h,AC_DEFINE([HAVE_XMMINTRIN],[1],[Define if xmmintrin.h]))
 AC_LANG_POP(C)
 
+############################################################
+
 # influential environment variables
 
 AC_ARG_VAR(MPIFC, [MPI Fortran compiler command])
 AC_ARG_VAR(MPILIBS, [extra libraries for linking MPI programs])
+AC_ARG_VAR(MPI_INC,[Directory where MPI include file mpi.h is installed, which is needed by ADIOS/CUDA when compiling])
+
 AC_ARG_VAR(FLAGS_CHECK, [Fortran compiler flags for non-critical subroutines])
 AC_ARG_VAR(FLAGS_NO_CHECK, [Fortran compiler flags for creating fast, production-run code for critical subroutines])
 
-AC_ARG_VAR(CUDA_LIB,[Location of CUDA library libcudart])
-AC_ARG_VAR(CUDA_INC,[Location of CUDA include files])
-AC_ARG_VAR(MPI_INC,[Location of MPI include mpi.h, which is needed by nvcc when compiling cuda files])
+# adios
+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(ADIOS_INC, [Directory where ADIOS headers are installed])
+AC_ARG_VAR(ADIOS_LIB, [Directory where ADIOS libraries are installed])
 
+# cuda
+AC_ARG_VAR(CUDA_LIB,[Directory where CUDA library libcudart is installed])
+AC_ARG_VAR(CUDA_INC,[Directory where CUDA include files are installed])
+
 AC_ARG_VAR(AR, [ar library creation])
 AC_ARG_VAR(ARFLAGS, [ar flag library creation])
 AC_ARG_VAR(RANLIB, [ranlib library creation])
 
-if test x"$MPIFC" = x; then
+# scratch disks
+AC_ARG_VAR(LOCAL_PATH_IS_ALSO_GLOBAL, [files on a local path on each node are also seen as global with same path @<:@default=true@:>@])
+
+############################################################
+
+# tests
+AS_IF([test x"$MPIFC" = x],[
     MPIFC=mpif90
-fi
+])
 
-AC_ARG_VAR(LOCAL_PATH_IS_ALSO_GLOBAL, [files on a local path on each node are also seen as global with same path @<:@default=true@:>@])
-if test x"$LOCAL_PATH_IS_ALSO_GLOBAL" = x; then
+AS_IF([test x"$LOCAL_PATH_IS_ALSO_GLOBAL" = x],[
     LOCAL_PATH_IS_ALSO_GLOBAL=true
-fi
+])
 
+AS_IF([test x"$MPI_INC" != x],[
+  CPPFLAGS+=" $MPI_INC"
+  FCFLAGS+=" $MPI_INC"
+  FLAGS_CHECK+=" $MPI_INC"
+  FLAGS_NO_CHECK+=" $MPI_INC"
+])
 
-
 # Checks for libraries.
 
-
 # Checks for header files.
 
 CIT_FC_MPI_HEADER([$MPIFC], [$FLAGS_CHECK])
 
-if test "$want_adios" != no; then
-    CIT_ADIOS_HEADER
-    CIT_ADIOS_LIB
-fi
+###
+### ADIOS
+###
 
+AS_IF([test "$want_adios" != no],[
+  AS_BOX([ADIOS])
+  AC_MSG_NOTICE([ADIOS is enabled])
+
+  # adds include/library directories to compile flags
+  AS_IF([test x"$$MXML_INC" != x],[
+    CPPFLAGS+=" $MXML_INC"
+  ])
+  AS_IF([test x"$MXML_LIB" != x],[
+    LDFLAGS+=" $MXML_LIB"
+  ])
+  AS_IF([test x"$ADIOS_INC" != x],[
+    CPPFLAGS+=" $ADIOS_INC"
+    FCFLAGS+=" $ADIOS_INC"
+    FLAGS_CHECK+=" $ADIOS_INC"
+    FLAGS_NO_CHECK+=" $ADIOS_INC"
+  ])
+  AS_IF([test x"$ADIOS_LIB" != x],[
+    LDFLAGS+=" $ADIOS_LIB"
+  ])
+
+  # checks
+  CIT_MXML_HEADER
+  CIT_MXML_LIB
+  CIT_ADIOS_HEADER
+  CIT_ADIOS_LIB
+])
+
+#mpbl: adding flags to config.h.in through autoheader in order to save them into the adios file.
+#configure_flags_str="FC=$FC FCFLAGS=$FCFLAGS $FLAGS_CHECK"
+#AC_DEFINE_UNQUOTED([CONFIGURE_FLAGS],["${configure_flags_str}"],
+ #         [configuration flags to be saved in the adios output file.])
+CONFIGURE_FLAGS="FC=$FC FCFLAGS=$FCFLAGS"
+AC_SUBST([CONFIGURE_FLAGS])
+
+###
+### CUDA
+###
+
+AS_IF([test "$want_cuda" != no],[
+  AS_BOX([CUDA])
+  AC_MSG_NOTICE([CUDA is enabled])
+
+  # checks
+  CIT_CUDA_COMPILER
+])
+
+###
+### FORCE_VECTORIZATION
+###
+
+AS_IF([test "$want_vec" != no],[
+  AS_BOX([FORCE VECTORIZATION])
+  AC_MSG_NOTICE([FORCE_VECTORIZATION is enabled])
+
+  # adds conditional compilation flag
+  # fortran compiler
+  AS_CASE([$FC],
+    # ibm compiler flag
+    [*xlf*|*/*xlf*], [VEC_FLAG="-WF,-DFORCE_VECTORIZATION"],
+    # default: gnu,intel,pgi,..
+    [VEC_FLAG="-DFORCE_VECTORIZATION"]
+  )
+  FLAGS_CHECK+=" $VEC_FLAG"
+  FLAGS_NO_CHECK+=" $VEC_FLAG"
+  # c compiler
+  AS_CASE([$CC],
+    # ibm compiler flag
+    [*xlc*|*/*xlc*], [VEC_FLAG="-DFORCE_VECTORIZATION"],
+    # default: gnu,intel,pgi,..
+    [VEC_FLAG="-DFORCE_VECTORIZATION"]
+  )
+  CPPFLAGS+=" $VEC_FLAG"
+
+])
+
+###
+### VTK
+###
+
+AS_IF([test "$want_vtk" != no],[
+  AS_BOX([VTK])
+  AC_MSG_NOTICE([VTK is enabled])
+
+  # adds conditional compilation flag 
+  # fortran compiler
+  AS_CASE([$FC],
+    # ibm compiler flag
+    [*xlf*|*/*xlf*], [VTK_FLAG="-WF,-DWITH_VTK"],
+    # default: gnu,intel,pgi,..
+    [VTK_FLAG="-DWITH_VTK"]
+  )
+  FLAGS_CHECK+=" $VTK_FLAG"
+  FLAGS_NO_CHECK+=" $VTK_FLAG"
+  # c compiler
+  AS_CASE([$CC],
+    # ibm compiler flag
+    [*xlc*|*/*xlc*], [VTK_FLAG="-DWITH_VTK"],
+    # default: gnu,intel,pgi,..
+    [VTK_FLAG="-DWITH_VTK"]
+  )
+  CPPFLAGS+=" $VTK_FLAG"
+
+])
+
+############################################################
+
 # Checks for typedefs, structures, and compiler characteristics.
+AS_BOX([module extensions])
 
 CIT_FC_MODULE_EXTENSION
 AC_SUBST([FC_MODEXT])
@@ -165,12 +303,13 @@
 AC_SUBST([FC_MODDIR])
 
 # Checks for library functions.
+AS_BOX([setting up default simulation setup])
 
-
 AC_CONFIG_FILES([
     Makefile
     setup/constants.h
     setup/precision.h
+    setup/config.fh
 ])
 AC_CONFIG_FILES([
     DATA/Par_file:DATA/Par_file
@@ -203,14 +342,15 @@
 
 #daniel: adding custom lines to config.h.in through autoheader
 AH_BOTTOM([
-/* Uncomment and define to select optimized file i/o for regional simulations */
+/* Define to select optimized file i/o for regional simulations */
 /* map fails when output files are > 4GB, which is often the case for GPU simulations */
-// #define USE_MAP_FUNCTION
+#undef USE_MAP_FUNCTION
 ])
 
 
 dnl FYI, this is not a "result", but AS_ECHO is not available in 2.61, and it
 dnl basically works like a portable echo.
+
 AC_MSG_RESULT([])
 AS_BOX([$PACKAGE_NAME $PACKAGE_VERSION])
 AC_MSG_RESULT([])

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/flags.guess
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/flags.guess	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/flags.guess	2013-10-07 15:14:08 UTC (rev 22929)
@@ -37,14 +37,14 @@
         #
         # Cray Fortran
         #
-        DEF_FFLAGS="-O3 -Onoaggress -Oipa0 -hfp2 -Ovector3 -Oscalar3 -Ocache2 -Ounroll2 -Ofusion2 -M 1438 -DFORCE_VECTORIZATION" # turn on optimization; -Oaggress -Oipa4 would make it even more aggressive
+        DEF_FFLAGS="-O3 -Onoaggress -Oipa0 -hfp2 -Ovector3 -Oscalar3 -Ocache2 -Ounroll2 -Ofusion2 -M 1438" # turn on optimization; -Oaggress -Oipa4 would make it even more aggressive
         # -eC -eD -ec -en -eI -ea -g -G0 -M 1438  # turn on full debugging and range checking
         ;;
     pgf95|*/pgf95|pgf90|*/pgf90)
         #
         # Portland PGI
         #
-        DEF_FFLAGS="-fast -Mnobounds -DFORCE_VECTORIZATION -Minline -Mneginfo -Mdclchk -Knoieee -Minform=warn -Mdaz -Mflushz -Mvect -mcmodel=medium"
+        DEF_FFLAGS="-fast -Mnobounds -Minline -Mneginfo -Mdclchk -Knoieee -Minform=warn -Mdaz -Mflushz -Mvect -mcmodel=medium"
         # -Mbounds
         # -fastsse -tp amd64e -Msmart
         ;;
@@ -57,7 +57,7 @@
 # parallel file systems like SFS 3.2 / Lustre 1.8. If omitted
 # I/O throughput lingers at 2.5 MB/s, with it it can increase to ~44 MB/s
 # However it does not make much of a difference on NFS mounted volumes or with SFS 3.1.1 / Lustre 1.6.7.1 
-        DEF_FFLAGS="-O3 -DFORCE_VECTORIZATION -check nobounds -xHost -ftz -assume buffered_io -assume byterecl -align sequence -vec-report0 -std03 -diag-disable 6477 -implicitnone -warn truncated_source -warn argument_checking -warn unused -warn declarations -warn alignments -warn ignore_loc -warn usage" # -mcmodel=medium -shared-intel
+        DEF_FFLAGS="-O3 -check nobounds -xHost -ftz -assume buffered_io -assume byterecl -align sequence -vec-report0 -std03 -diag-disable 6477 -implicitnone -warn truncated_source -warn argument_checking -warn unused -warn declarations -warn alignments -warn ignore_loc -warn usage" # -mcmodel=medium -shared-intel
 ##############################################################################################################################
 ##############################################################################################################################
 ##############################################################################################################################
@@ -66,15 +66,15 @@
 ##############################################################################################################################
 ##############################################################################################################################
         # useful for debugging...
-        # for debugging: change -O3 -DFORCE_VECTORIZATION -check nobounds to      -check all -debug -g -O0 -fp-stack-check -traceback -ftrapuv
+        # for debugging: change -O3 -check nobounds to      -check all -debug -g -O0 -fp-stack-check -traceback -ftrapuv
         #
         ;;
     gfortran|*/gfortran|f95|*/f95)
         #
         # GNU gfortran
         #
-        DEF_FFLAGS="-std=gnu -fimplicit-none -frange-check -O2 -fmax-errors=10 -pedantic -pedantic-errors -Waliasing -Wampersand -Wcharacter-truncation -Wline-truncation -Wsurprising -Wno-tabs -Wunderflow -DFORCE_VECTORIZATION " # -mcmodel=medium
-        # useful for debugging: replace -DFORCE_VECTORIZATION with -ffpe-trap=overflow,zero -fbacktrace -fbounds-check
+        DEF_FFLAGS="-std=gnu -fimplicit-none -frange-check -O2 -fmax-errors=10 -pedantic -pedantic-errors -Waliasing -Wampersand -Wcharacter-truncation -Wline-truncation -Wsurprising -Wno-tabs -Wunderflow " # -mcmodel=medium
+        # useful for debugging: add -ffpe-trap=overflow,zero -fbacktrace -fbounds-check
         ;;
     g95|*/g95)
         #
@@ -147,12 +147,12 @@
         # CFLAGS = -Wl,-relax
         #
 # deleted -qxflag=dvz because it requires handler function __xl_dzx and thus linking will fail 
-        DEF_FFLAGS="-O4 -qnostrict -qassert=contig -qhot -q64 -qtune=auto -qarch=auto -qcache=auto -qfree=f90 -qsuffix=f=f90 -qhalt=w -qlanglvl=2003std -g -qsuppress=1518-234 -qsuppress=1518-317 -qsuppress=1518-318 -qsuppress=1500-036 -Q -Q+rank,swap_all -Wl,-relax -WF,-DFORCE_VECTORIZATION"
+        DEF_FFLAGS="-O4 -qnostrict -qassert=contig -qhot -q64 -qtune=auto -qarch=auto -qcache=auto -qfree=f90 -qsuffix=f=f90 -qhalt=w -qlanglvl=2003std -g -qsuppress=1518-234 -qsuppress=1518-317 -qsuppress=1518-318 -qsuppress=1500-036 -Q -Q+rank,swap_all -Wl,-relax"
         # Options -qreport -qsource -qlist create a *.lst file containing detailed information about vectorization.
         # On IBM BlueGene at IDRIS (France) use:
         # -qtune=auto -qarch=450d -qsave     instead of -qtune=auto -qarch=auto
         #
-        # to debug with IBM xlf, remove -Wl,-relax -WF,-DFORCE_VECTORIZATION and add -g -O0 -C -qddim -qfullpath -qflttrap=overflow:zerodivide:invalid:enable -qfloat=nans -qinitauto=7FBFFFFF
+        # to debug with IBM xlf, remove -Wl,-relax and add -g -O0 -C -qddim -qfullpath -qflttrap=overflow:zerodivide:invalid:enable -qfloat=nans -qinitauto=7FBFFFFF
         #
         ;;
     pathf90|*/pathf90)

Added: seismo/3D/SPECFEM3D_GLOBE/trunk/setup/config.fh.in
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/setup/config.fh.in	                        (rev 0)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/setup/config.fh.in	2013-10-07 15:14:08 UTC (rev 22929)
@@ -0,0 +1,19 @@
+! for ADIOS header informations
+
+! configuration flags to be saved in the adios output file.
+#define CONFIGURE_FLAGS "@CONFIGURE_FLAGS@"
+
+! Define to the full name and version of this package.
+#define PACKAGE_STRING "@PACKAGE_STRING@"
+
+!> \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

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/setup/config.h.in
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/setup/config.h.in	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/setup/config.h.in	2013-10-07 15:14:08 UTC (rev 22929)
@@ -69,7 +69,7 @@
 #undef STDC_HEADERS
 
 
-/* Uncomment and define to select optimized file i/o for regional simulations */
+/* Define to select optimized file i/o for regional simulations */
 /* map fails when output files are > 4GB, which is often the case for GPU simulations */
-// #define USE_MAP_FUNCTION
+#undef USE_MAP_FUNCTION
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/setup/constants.h.in
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/setup/constants.h.in	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/setup/constants.h.in	2013-10-07 15:14:08 UTC (rev 22929)
@@ -255,6 +255,16 @@
 
 !!-----------------------------------------------------------
 !!
+!! ADIOS Related values
+!!
+!!-----------------------------------------------------------
+
+  integer, parameter :: ADIOS_BUFFER_SIZE_IN_MB = 200
+  character(len=256), parameter :: ADIOS_TRANSPORT_METHOD = 'MPI'
+
+
+!!-----------------------------------------------------------
+!!
 !! adjoint kernel outputs
 !!
 !!-----------------------------------------------------------

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/src/cuda/rules.mk
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/cuda/rules.mk	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/cuda/rules.mk	2013-10-07 15:14:08 UTC (rev 22929)
@@ -79,6 +79,6 @@
 	${NVCC} -c $< -o $@ $(NVCC_FLAGS)
 
 $O/%.cudacc.o: $S/%.c ${SETUP}/config.h
-	${CC} -c $(CPPFLAGS) $(CFLAGS) $(MPI_INC) -o $@ $< 
+	${CC} -c $(CPPFLAGS) $(CFLAGS) -o $@ $<
 
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/src/cuda/specfem3D_gpu_cuda_method_stubs.c
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/cuda/specfem3D_gpu_cuda_method_stubs.c	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/cuda/specfem3D_gpu_cuda_method_stubs.c	2013-10-07 15:14:08 UTC (rev 22929)
@@ -1,4 +1,4 @@
-/*
+/* 
 !=====================================================================
 !
 !          S p e c f e m 3 D  G l o b e  V e r s i o n  6 . 0
@@ -34,8 +34,8 @@
 
 typedef float realw;
 
+ 
 
-
 //
 // src/cuda/assemble_MPI_scalar_cuda.cu
 //
@@ -43,12 +43,12 @@
 void FC_FUNC_(transfer_boun_pot_from_device,
               TRANSFER_BOUN_POT_FROM_DEVICE)(long* Mesh_pointer_f,
                                              realw* send_potential_dot_dot_buffer,
-                                             int* FORWARD_OR_ADJOINT){}
+                                             int* FORWARD_OR_ADJOINT){} 
 
 void FC_FUNC_(transfer_asmbl_pot_to_device,
               TRANSFER_ASMBL_POT_TO_DEVICE)(long* Mesh_pointer,
                                             realw* buffer_recv_scalar,
-                                            int* FORWARD_OR_ADJOINT) {}
+                                            int* FORWARD_OR_ADJOINT) {} 
 
 
 //
@@ -59,13 +59,13 @@
               TRANSFER_BOUN_ACCEL_FROM_DEVICE)(long* Mesh_pointer_f,
                                                realw* send_accel_buffer,
                                                int* IREGION,
-                                               int* FORWARD_OR_ADJOINT){}
+                                               int* FORWARD_OR_ADJOINT){} 
 
 void FC_FUNC_(transfer_asmbl_accel_to_device,
               TRANSFER_ASMBL_ACCEL_TO_DEVICE)(long* Mesh_pointer,
                                               realw* buffer_recv_vector,
                                               int* IREGION,
-                                              int* FORWARD_OR_ADJOINT) {}
+                                              int* FORWARD_OR_ADJOINT) {} 
 
 
 //
@@ -73,58 +73,58 @@
 //
 
 void FC_FUNC_(pause_for_debug,
-              PAUSE_FOR_DEBUG)() {}
+              PAUSE_FOR_DEBUG)() {} 
 
 void FC_FUNC_(output_free_device_memory,
-              OUTPUT_FREE_DEVICE_MEMORY)(int* myrank) {}
+              OUTPUT_FREE_DEVICE_MEMORY)(int* myrank) {} 
 
 void FC_FUNC_(get_free_device_memory,
-              get_FREE_DEVICE_MEMORY)(realw* free, realw* used, realw* total ) {}
+              get_FREE_DEVICE_MEMORY)(realw* free, realw* used, realw* total ) {} 
 
 void FC_FUNC_(check_norm_acoustic_from_device,
               CHECK_NORM_ACOUSTIC_FROM_DEVICE)(realw* norm,
                                                   long* Mesh_pointer_f,
-                                                  int* FORWARD_OR_ADJOINT) {}
+                                                  int* FORWARD_OR_ADJOINT) {} 
 
 void FC_FUNC_(check_norm_elastic_from_device,
               CHECK_NORM_ELASTIC_FROM_DEVICE)(realw* norm,
                                               long* Mesh_pointer_f,
-                                              int* FORWARD_OR_ADJOINT) {}
+                                              int* FORWARD_OR_ADJOINT) {} 
 
 void FC_FUNC_(check_norm_strain_from_device,
               CHECK_NORM_STRAIN_FROM_DEVICE)(realw* strain_norm,
                                              realw* strain_norm2,
-                                             long* Mesh_pointer_f) {}
+                                             long* Mesh_pointer_f) {} 
 
  void FC_FUNC_(check_max_norm_displ_gpu,
- CHECK_MAX_NORM_DISPL_GPU)(int* size, realw* displ,long* Mesh_pointer_f,int* announceID) {}
+ CHECK_MAX_NORM_DISPL_GPU)(int* size, realw* displ,long* Mesh_pointer_f,int* announceID) {} 
 
  void FC_FUNC_(check_max_norm_vector,
- CHECK_MAX_NORM_VECTOR)(int* size, realw* vector1, int* announceID) {}
+ CHECK_MAX_NORM_VECTOR)(int* size, realw* vector1, int* announceID) {} 
 
  void FC_FUNC_(check_max_norm_displ,
- CHECK_MAX_NORM_DISPL)(int* size, realw* displ, int* announceID) {}
+ CHECK_MAX_NORM_DISPL)(int* size, realw* displ, int* announceID) {} 
 
  void FC_FUNC_(check_max_norm_b_displ_gpu,
- CHECK_MAX_NORM_B_DISPL_GPU)(int* size, realw* b_displ,long* Mesh_pointer_f,int* announceID) {}
+ CHECK_MAX_NORM_B_DISPL_GPU)(int* size, realw* b_displ,long* Mesh_pointer_f,int* announceID) {} 
 
  void FC_FUNC_(check_max_norm_b_accel_gpu,
- CHECK_MAX_NORM_B_ACCEL_GPU)(int* size, realw* b_accel,long* Mesh_pointer_f,int* announceID) {}
+ CHECK_MAX_NORM_B_ACCEL_GPU)(int* size, realw* b_accel,long* Mesh_pointer_f,int* announceID) {} 
 
  void FC_FUNC_(check_max_norm_b_veloc_gpu,
- CHECK_MAX_NORM_B_VELOC_GPU)(int* size, realw* b_veloc,long* Mesh_pointer_f,int* announceID) {}
+ CHECK_MAX_NORM_B_VELOC_GPU)(int* size, realw* b_veloc,long* Mesh_pointer_f,int* announceID) {} 
 
  void FC_FUNC_(check_max_norm_b_displ,
- CHECK_MAX_NORM_B_DISPL)(int* size, realw* b_displ,int* announceID) {}
+ CHECK_MAX_NORM_B_DISPL)(int* size, realw* b_displ,int* announceID) {} 
 
  void FC_FUNC_(check_max_norm_b_accel,
- CHECK_MAX_NORM_B_ACCEL)(int* size, realw* b_accel,int* announceID) {}
+ CHECK_MAX_NORM_B_ACCEL)(int* size, realw* b_accel,int* announceID) {} 
 
  void FC_FUNC_(check_error_vectors,
- CHECK_ERROR_VECTORS)(int* sizef, realw* vector1,realw* vector2) {}
+ CHECK_ERROR_VECTORS)(int* sizef, realw* vector1,realw* vector2) {} 
 
  void FC_FUNC_(get_max_accel,
- GET_MAX_ACCEL)(int* itf,int* sizef,long* Mesh_pointer) {}
+ GET_MAX_ACCEL)(int* itf,int* sizef,long* Mesh_pointer) {} 
 
 
 //
@@ -134,12 +134,12 @@
 void FC_FUNC_(compute_add_sources_cuda,
               COMPUTE_ADD_SOURCES_CUDA)(long* Mesh_pointer_f,
                                         int* NSOURCESf,
-                                        double* h_stf_pre_compute) {}
+                                        double* h_stf_pre_compute) {} 
 
 void FC_FUNC_(compute_add_sources_backward_cuda,
               COMPUTE_ADD_SOURCES_BACKWARD_CUDA)(long* Mesh_pointer_f,
                                                  int* NSOURCESf,
-                                                 double* h_stf_pre_compute) {}
+                                                 double* h_stf_pre_compute) {} 
 
 void FC_FUNC_(compute_add_sources_adjoint_cuda,
               COMPUTE_ADD_SOURCES_ADJOINT_CUDA)(long* Mesh_pointer,
@@ -147,7 +147,7 @@
                                                 realw* h_adj_sourcearrays,
                                                 int* h_islice_selected_rec,
                                                 int* h_ispec_selected_rec,
-                                                int* time_index) {}
+                                                int* time_index) {} 
 
 
 //
@@ -156,23 +156,23 @@
 
 void FC_FUNC_(compute_coupling_fluid_cmb_cuda,
               COMPUTE_COUPLING_FLUID_CMB_CUDA)(long* Mesh_pointer_f,
-                                               int* FORWARD_OR_ADJOINT) {}
+                                               int* FORWARD_OR_ADJOINT) {} 
 
 void FC_FUNC_(compute_coupling_fluid_icb_cuda,
               COMPUTE_COUPLING_FLUID_ICB_CUDA)(long* Mesh_pointer_f,
-                                               int* FORWARD_OR_ADJOINT) {}
+                                               int* FORWARD_OR_ADJOINT) {} 
 
 void FC_FUNC_(compute_coupling_cmb_fluid_cuda,
               COMPUTE_COUPLING_CMB_FLUID_CUDA)(long* Mesh_pointer_f,
-                                               int* FORWARD_OR_ADJOINT) {}
+                                               int* FORWARD_OR_ADJOINT) {} 
 
 void FC_FUNC_(compute_coupling_icb_fluid_cuda,
               COMPUTE_COUPLING_ICB_FLUID_CUDA)(long* Mesh_pointer_f,
-                                               int* FORWARD_OR_ADJOINT) {}
+                                               int* FORWARD_OR_ADJOINT) {} 
 
 void FC_FUNC_(compute_coupling_ocean_cuda,
               COMPUTE_COUPLING_OCEAN_CUDA)(long* Mesh_pointer_f,
-                                           int* FORWARD_OR_ADJOINT) {}
+                                           int* FORWARD_OR_ADJOINT) {} 
 
 
 //
@@ -182,7 +182,7 @@
 void FC_FUNC_(compute_forces_crust_mantle_cuda,
               COMPUTE_FORCES_CRUST_MANTLE_CUDA)(long* Mesh_pointer_f,
                                                 int* iphase,
-                                                int* FORWARD_OR_ADJOINT_f) {}
+                                                int* FORWARD_OR_ADJOINT_f) {} 
 
 
 //
@@ -192,7 +192,7 @@
 void FC_FUNC_(compute_forces_inner_core_cuda,
               COMPUTE_FORCES_INNER_CORE_CUDA)(long* Mesh_pointer_f,
                                               int* iphase,
-                                              int* FORWARD_OR_ADJOINT_f) {}
+                                              int* FORWARD_OR_ADJOINT_f) {} 
 
 
 //
@@ -203,7 +203,7 @@
               COMPUTE_FORCES_OUTER_CORE_CUDA)(long* Mesh_pointer_f,
                                               int* iphase,
                                               realw* time_f,
-                                              int* FORWARD_OR_ADJOINT_f) {}
+                                              int* FORWARD_OR_ADJOINT_f) {} 
 
 
 //
@@ -211,22 +211,22 @@
 //
 
 void FC_FUNC_(compute_kernels_cm_cuda,
-              COMPUTE_KERNELS_CM_CUDA)(long* Mesh_pointer,realw* deltat_f) {}
+              COMPUTE_KERNELS_CM_CUDA)(long* Mesh_pointer,realw* deltat_f) {} 
 
 void FC_FUNC_(compute_kernels_ic_cuda,
-              COMPUTE_KERNELS_IC_CUDA)(long* Mesh_pointer,realw* deltat_f) {}
+              COMPUTE_KERNELS_IC_CUDA)(long* Mesh_pointer,realw* deltat_f) {} 
 
 void FC_FUNC_(compute_kernels_oc_cuda,
-              COMPUTE_KERNELS_OC_CUDA)(long* Mesh_pointer,realw* deltat_f) {}
+              COMPUTE_KERNELS_OC_CUDA)(long* Mesh_pointer,realw* deltat_f) {} 
 
 void FC_FUNC_(compute_kernels_strgth_noise_cu,
               COMPUTE_KERNELS_STRGTH_NOISE_CU)(long* Mesh_pointer,
                                                realw* h_noise_surface_movie,
-                                               realw* deltat_f) {}
+                                               realw* deltat_f) {} 
 
 void FC_FUNC_(compute_kernels_hess_cuda,
               COMPUTE_KERNELS_HESS_CUDA)(long* Mesh_pointer,
-                                         realw* deltat_f) {}
+                                         realw* deltat_f) {} 
 
 
 //
@@ -236,16 +236,16 @@
 void FC_FUNC_(compute_stacey_acoustic_cuda,
               COMPUTE_STACEY_ACOUSTIC_CUDA)(long* Mesh_pointer_f,
                                             realw* absorb_potential,
-                                            int* itype) {}
+                                            int* itype) {} 
 
 void FC_FUNC_(compute_stacey_acoustic_backward_cuda,
               COMPUTE_STACEY_ACOUSTIC_BACKWARD_CUDA)(long* Mesh_pointer_f,
                                                      realw* absorb_potential,
-                                                     int* itype) {}
+                                                     int* itype) {} 
 
 void FC_FUNC_(compute_stacey_acoustic_undoatt_cuda,
               COMPUTE_STACEY_ACOUSTIC_UNDOATT_CUDA)(long* Mesh_pointer_f,
-                                                    int* itype) {}
+                                                    int* itype) {} 
 
 
 //
@@ -255,16 +255,16 @@
 void FC_FUNC_(compute_stacey_elastic_cuda,
               COMPUTE_STACEY_ELASTIC_CUDA)(long* Mesh_pointer_f,
                                            realw* absorb_field,
-                                           int* itype) {}
+                                           int* itype) {} 
 
 void FC_FUNC_(compute_stacey_elastic_backward_cuda,
               COMPUTE_STACEY_ELASTIC_BACKWARD_CUDA)(long* Mesh_pointer_f,
                                                     realw* absorb_field,
-                                                    int* itype) {}
+                                                    int* itype) {} 
 
 void FC_FUNC_(compute_stacey_elastic_undoatt_cuda,
               COMPUTE_STACEY_ELASTIC_UNDOATT_CUDA)(long* Mesh_pointer_f,
-                                                   int* itype) {}
+                                                   int* itype) {} 
 
 
 //
@@ -272,39 +272,39 @@
 //
 
 void FC_FUNC_(initialize_cuda_device,
-              INITIALIZE_CUDA_DEVICE)(int* myrank_f,int* ncuda_devices) {
+              INITIALIZE_CUDA_DEVICE)(int* myrank_f,int* ncuda_devices) { 
  fprintf(stderr,"ERROR: GPU_MODE enabled without GPU/CUDA Support. To enable GPU support, reconfigure with --with-cuda flag.\n");
  exit(1);
-}
+} 
 
 
 //
 // src/cuda/noise_tomography_cuda.cu
 //
 
-void FC_FUNC_(fortranflush,FORTRANFLUSH)(int* rank){}
+void FC_FUNC_(fortranflush,FORTRANFLUSH)(int* rank){} 
 
-void FC_FUNC_(fortranprint,FORTRANPRINT)(int* id) {}
+void FC_FUNC_(fortranprint,FORTRANPRINT)(int* id) {} 
 
-void FC_FUNC_(fortranprintf,FORTRANPRINTF)(realw* val) {}
+void FC_FUNC_(fortranprintf,FORTRANPRINTF)(realw* val) {} 
 
-void FC_FUNC_(fortranprintd,FORTRANPRINTD)(double* val) {}
+void FC_FUNC_(fortranprintd,FORTRANPRINTD)(double* val) {} 
 
-void FC_FUNC_(make_displ_rand,MAKE_DISPL_RAND)(long* Mesh_pointer_f,realw* h_displ) {}
+void FC_FUNC_(make_displ_rand,MAKE_DISPL_RAND)(long* Mesh_pointer_f,realw* h_displ) {} 
 
 void FC_FUNC_(noise_transfer_surface_to_host,
               NOISE_TRANSFER_SURFACE_TO_HOST)(long* Mesh_pointer_f,
-                                              realw* h_noise_surface_movie) {}
+                                              realw* h_noise_surface_movie) {} 
 
 void FC_FUNC_(noise_add_source_master_rec_cu,
               NOISE_ADD_SOURCE_MASTER_REC_CU)(long* Mesh_pointer_f,
                                               int* it_f,
                                               int* irec_master_noise_f,
-                                              int* islice_selected_rec) {}
+                                              int* islice_selected_rec) {} 
 
 void FC_FUNC_(noise_add_surface_movie_cuda,
               NOISE_ADD_SURFACE_MOVIE_CUDA)(long* Mesh_pointer_f,
-                                            realw* h_noise_surface_movie) {}
+                                            realw* h_noise_surface_movie) {} 
 
 
 //
@@ -339,7 +339,7 @@
                                         int* SAVE_BOUNDARY_MESH_f,
                                         int* USE_MESH_COLORING_GPU_f,
                                         int* ANISOTROPIC_KL_f,int* APPROXIMATE_HESS_KL_f,
-                                        realw* deltat_f,realw* b_deltat_f) {}
+                                        realw* deltat_f,realw* b_deltat_f) {} 
 
 void FC_FUNC_(prepare_fields_rotation_device,
               PREPARE_FIELDS_ROTATION_DEVICE)(long* Mesh_pointer_f,
@@ -349,7 +349,7 @@
                                               realw* b_two_omega_earth_f,
                                               realw* b_A_array_rotation,
                                               realw* b_B_array_rotation,
-                                              int* NSPEC_OUTER_CORE_ROTATION) {}
+                                              int* NSPEC_OUTER_CORE_ROTATION) {} 
 
 void FC_FUNC_(prepare_fields_gravity_device,
               PREPARE_FIELDS_gravity_DEVICE)(long* Mesh_pointer_f,
@@ -363,7 +363,7 @@
                                              realw* minus_g_icb,
                                              realw* minus_g_cmb,
                                              double* RHO_BOTTOM_OC,
-                                             double* RHO_TOP_OC) {}
+                                             double* RHO_TOP_OC) {} 
 
 void FC_FUNC_(prepare_fields_attenuat_device,
               PREPARE_FIELDS_ATTENUAT_DEVICE)(long* Mesh_pointer_f,
@@ -392,7 +392,7 @@
                                                  realw* factor_common_inner_core,
                                                  realw* one_minus_sum_beta_inner_core,
                                                  realw* alphaval,realw* betaval,realw* gammaval,
-                                                 realw* b_alphaval,realw* b_betaval,realw* b_gammaval) {}
+                                                 realw* b_alphaval,realw* b_betaval,realw* b_gammaval) {} 
 
 void FC_FUNC_(prepare_fields_strain_device,
               PREPARE_FIELDS_STRAIN_DEVICE)(long* Mesh_pointer_f,
@@ -419,7 +419,7 @@
                                             realw* b_epsilondev_xz_inner_core,
                                             realw* b_epsilondev_yz_inner_core,
                                             realw* eps_trace_over_3_inner_core,
-                                            realw* b_eps_trace_over_3_inner_core) {}
+                                            realw* b_eps_trace_over_3_inner_core) {} 
 
 void FC_FUNC_(prepare_fields_absorb_device,
               PREPARE_FIELDS_ABSORB_DEVICE)(long* Mesh_pointer_f,
@@ -448,7 +448,7 @@
                                             int* ibelm_ymin_outer_core,int* ibelm_ymax_outer_core,
                                             realw* jacobian2D_xmin_outer_core, realw* jacobian2D_xmax_outer_core,
                                             realw* jacobian2D_ymin_outer_core, realw* jacobian2D_ymax_outer_core,
-                                            realw* vp_outer_core) {}
+                                            realw* vp_outer_core) {} 
 
 void FC_FUNC_(prepare_mpi_buffers_device,
               PREPARE_MPI_BUFFERS_DEVICE)(long* Mesh_pointer_f,
@@ -463,7 +463,7 @@
                                           int* num_interfaces_outer_core,
                                           int* max_nibool_interfaces_oc,
                                           int* nibool_interfaces_outer_core,
-                                          int* ibool_interfaces_outer_core){}
+                                          int* ibool_interfaces_outer_core){} 
 
 void FC_FUNC_(prepare_fields_noise_device,
               PREPARE_FIELDS_NOISE_DEVICE)(long* Mesh_pointer_f,
@@ -475,14 +475,14 @@
                                            realw* normal_y_noise,
                                            realw* normal_z_noise,
                                            realw* mask_noise,
-                                           realw* jacobian2D_top_crust_mantle) {}
+                                           realw* jacobian2D_top_crust_mantle) {} 
 
 void FC_FUNC_(prepare_oceans_device,
               PREPARE_OCEANS_DEVICE)(long* Mesh_pointer_f,
                                      int* npoin_oceans,
                                      int* h_iglob_ocean_load,
                                      realw* h_rmass_ocean_load_selected,
-                                     realw* h_normal_ocean_load) {}
+                                     realw* h_normal_ocean_load) {} 
 
 void FC_FUNC_(prepare_crust_mantle_device,
              PREPARE_CRUST_MANTLE_DEVICE)(long* Mesh_pointer_f,
@@ -514,7 +514,7 @@
                                           int* NCHUNKS_VAL,
                                           int* num_colors_outer,
                                           int* num_colors_inner,
-                                          int* num_elem_colors) {}
+                                          int* num_elem_colors) {} 
 
 void FC_FUNC_(prepare_outer_core_device,
               PREPARE_OUTER_CORE_DEVICE)(long* Mesh_pointer_f,
@@ -539,7 +539,7 @@
                                          int* h_ibelm_bottom_outer_core,
                                          int* num_colors_outer,
                                          int* num_colors_inner,
-                                         int* num_elem_colors) {}
+                                         int* num_elem_colors) {} 
 
 void FC_FUNC_(prepare_inner_core_device,
               PREPARE_INNER_CORE_DEVICE)(long* Mesh_pointer_f,
@@ -562,11 +562,11 @@
                                          int* h_ibelm_top_inner_core,
                                          int* num_colors_outer,
                                          int* num_colors_inner,
-                                         int* num_elem_colors) {}
+                                         int* num_elem_colors) {} 
 
 void FC_FUNC_(prepare_cleanup_device,
               PREPARE_CLEANUP_DEVICE)(long* Mesh_pointer_f,
-              int* NCHUNKS_VAL) {}
+              int* NCHUNKS_VAL) {} 
 
 
 //
@@ -574,88 +574,88 @@
 //
 
 void FC_FUNC_(transfer_fields_cm_to_device,
-              TRANSFER_FIELDS_CM_TO_DEVICE)(int* size, realw* displ, realw* veloc, realw* accel,long* Mesh_pointer_f) {}
+              TRANSFER_FIELDS_CM_TO_DEVICE)(int* size, realw* displ, realw* veloc, realw* accel,long* Mesh_pointer_f) {} 
 
 void FC_FUNC_(transfer_fields_ic_to_device,
-              TRANSFER_FIELDS_IC_TO_DEVICE)(int* size, realw* displ, realw* veloc, realw* accel,long* Mesh_pointer_f) {}
+              TRANSFER_FIELDS_IC_TO_DEVICE)(int* size, realw* displ, realw* veloc, realw* accel,long* Mesh_pointer_f) {} 
 
 void FC_FUNC_(transfer_fields_oc_to_device,
-              TRANSFER_FIELDS_OC_TO_DEVICE)(int* size, realw* displ, realw* veloc, realw* accel,long* Mesh_pointer_f) {}
+              TRANSFER_FIELDS_OC_TO_DEVICE)(int* size, realw* displ, realw* veloc, realw* accel,long* Mesh_pointer_f) {} 
 
 void FC_FUNC_(transfer_b_fields_cm_to_device,
               TRANSFER_FIELDS_B_CM_TO_DEVICE)(int* size, realw* b_displ, realw* b_veloc, realw* b_accel,
-                                              long* Mesh_pointer_f) {}
+                                              long* Mesh_pointer_f) {} 
 
 void FC_FUNC_(transfer_b_fields_ic_to_device,
               TRANSFER_FIELDS_B_IC_TO_DEVICE)(int* size, realw* b_displ, realw* b_veloc, realw* b_accel,
-                                              long* Mesh_pointer_f) {}
+                                              long* Mesh_pointer_f) {} 
 
 void FC_FUNC_(transfer_b_fields_oc_to_device,
               TRANSFER_FIELDS_B_OC_TO_DEVICE)(int* size, realw* b_displ, realw* b_veloc, realw* b_accel,
-                                              long* Mesh_pointer_f) {}
+                                              long* Mesh_pointer_f) {} 
 
 void FC_FUNC_(transfer_fields_cm_from_device,
-              TRANSFER_FIELDS_CM_FROM_DEVICE)(int* size, realw* displ, realw* veloc, realw* accel,long* Mesh_pointer_f) {}
+              TRANSFER_FIELDS_CM_FROM_DEVICE)(int* size, realw* displ, realw* veloc, realw* accel,long* Mesh_pointer_f) {} 
 
 void FC_FUNC_(transfer_fields_ic_from_device,
-              TRANSFER_FIELDS_IC_FROM_DEVICE)(int* size, realw* displ, realw* veloc, realw* accel,long* Mesh_pointer_f) {}
+              TRANSFER_FIELDS_IC_FROM_DEVICE)(int* size, realw* displ, realw* veloc, realw* accel,long* Mesh_pointer_f) {} 
 
 void FC_FUNC_(transfer_fields_oc_from_device,
-              TRANSFER_FIELDS_OC_FROM_DEVICE)(int* size, realw* displ, realw* veloc, realw* accel,long* Mesh_pointer_f) {}
+              TRANSFER_FIELDS_OC_FROM_DEVICE)(int* size, realw* displ, realw* veloc, realw* accel,long* Mesh_pointer_f) {} 
 
 void FC_FUNC_(transfer_b_fields_cm_from_device,
               TRANSFER_B_FIELDS_CM_FROM_DEVICE)(int* size, realw* b_displ, realw* b_veloc, realw* b_accel,
-                                                long* Mesh_pointer_f) {}
+                                                long* Mesh_pointer_f) {} 
 
 void FC_FUNC_(transfer_b_fields_ic_from_device,
               TRANSFER_B_FIELDS_IC_FROM_DEVICE)(int* size, realw* b_displ, realw* b_veloc, realw* b_accel,
-                                                long* Mesh_pointer_f) {}
+                                                long* Mesh_pointer_f) {} 
 
 void FC_FUNC_(transfer_b_fields_oc_from_device,
               TRANSFER_B_FIELDS_OC_FROM_DEVICE)(int* size, realw* b_displ, realw* b_veloc, realw* b_accel,
-                                                long* Mesh_pointer_f) {}
+                                                long* Mesh_pointer_f) {} 
 
 void FC_FUNC_(transfer_displ_cm_from_device,
-              TRANSFER_DISPL_CM_FROM_DEVICE)(int* size, realw* displ, long* Mesh_pointer_f) {}
+              TRANSFER_DISPL_CM_FROM_DEVICE)(int* size, realw* displ, long* Mesh_pointer_f) {} 
 
 void FC_FUNC_(transfer_b_displ_cm_from_device,
-              TRANSFER_B_DISPL_CM_FROM_DEVICE)(int* size, realw* displ, long* Mesh_pointer_f) {}
+              TRANSFER_B_DISPL_CM_FROM_DEVICE)(int* size, realw* displ, long* Mesh_pointer_f) {} 
 
 void FC_FUNC_(transfer_displ_ic_from_device,
-              TRANSFER_DISPL_IC_FROM_DEVICE)(int* size, realw* displ, long* Mesh_pointer_f) {}
+              TRANSFER_DISPL_IC_FROM_DEVICE)(int* size, realw* displ, long* Mesh_pointer_f) {} 
 
 void FC_FUNC_(transfer_b_displ_ic_from_device,
-              TRANSFER_B_DISPL_IC_FROM_DEVICE)(int* size, realw* displ, long* Mesh_pointer_f) {}
+              TRANSFER_B_DISPL_IC_FROM_DEVICE)(int* size, realw* displ, long* Mesh_pointer_f) {} 
 
 void FC_FUNC_(transfer_displ_oc_from_device,
-              TRANSFER_DISPL_OC_FROM_DEVICE)(int* size, realw* displ, long* Mesh_pointer_f) {}
+              TRANSFER_DISPL_OC_FROM_DEVICE)(int* size, realw* displ, long* Mesh_pointer_f) {} 
 
 void FC_FUNC_(transfer_b_displ_oc_from_device,
-              TRANSFER_B_DISPL_OC_FROM_DEVICE)(int* size, realw* displ, long* Mesh_pointer_f) {}
+              TRANSFER_B_DISPL_OC_FROM_DEVICE)(int* size, realw* displ, long* Mesh_pointer_f) {} 
 
 void FC_FUNC_(transfer_veloc_cm_from_device,
-              TRANSFER_VELOC_CM_FROM_DEVICE)(int* size, realw* veloc, long* Mesh_pointer_f) {}
+              TRANSFER_VELOC_CM_FROM_DEVICE)(int* size, realw* veloc, long* Mesh_pointer_f) {} 
 
 void FC_FUNC_(transfer_veloc_ic_from_device,
-              TRANSFER_VELOC_IC_FROM_DEVICE)(int* size, realw* veloc, long* Mesh_pointer_f) {}
+              TRANSFER_VELOC_IC_FROM_DEVICE)(int* size, realw* veloc, long* Mesh_pointer_f) {} 
 
 void FC_FUNC_(transfer_veloc_oc_from_device,
-              TRANSFER_VELOC_OC_FROM_DEVICE)(int* size, realw* veloc, long* Mesh_pointer_f) {}
+              TRANSFER_VELOC_OC_FROM_DEVICE)(int* size, realw* veloc, long* Mesh_pointer_f) {} 
 
 void FC_FUNC_(transfer_accel_cm_to_device,
-              TRANSFER_ACCEL_CM_TO_DEVICE)(int* size, realw* accel,long* Mesh_pointer_f) {}
+              TRANSFER_ACCEL_CM_TO_DEVICE)(int* size, realw* accel,long* Mesh_pointer_f) {} 
 
 void FC_FUNC_(transfer_accel_cm_from_device,
-              TRANSFER_ACCEL_CM_FROM_DEVICE)(int* size, realw* accel,long* Mesh_pointer_f) {}
+              TRANSFER_ACCEL_CM_FROM_DEVICE)(int* size, realw* accel,long* Mesh_pointer_f) {} 
 
 void FC_FUNC_(transfer_b_accel_cm_from_device,
-              TRANSFER_B_ACCEL_CM_FROM_DEVICE)(int* size, realw* b_accel,long* Mesh_pointer_f) {}
+              TRANSFER_B_ACCEL_CM_FROM_DEVICE)(int* size, realw* b_accel,long* Mesh_pointer_f) {} 
 
 void FC_FUNC_(transfer_accel_ic_from_device,
-              TRANSFER_ACCEL_IC_FROM_DEVICE)(int* size, realw* accel,long* Mesh_pointer_f) {}
+              TRANSFER_ACCEL_IC_FROM_DEVICE)(int* size, realw* accel,long* Mesh_pointer_f) {} 
 
 void FC_FUNC_(transfer_accel_oc_from_device,
-              TRANSFER_ACCEL_OC_FROM_DEVICE)(int* size, realw* accel,long* Mesh_pointer_f) {}
+              TRANSFER_ACCEL_OC_FROM_DEVICE)(int* size, realw* accel,long* Mesh_pointer_f) {} 
 
 void FC_FUNC_(transfer_strain_cm_from_device,
               TRANSFER_STRAIN_CM_FROM_DEVICE)(long* Mesh_pointer,
@@ -664,7 +664,7 @@
                                                   realw* epsilondev_yy,
                                                   realw* epsilondev_xy,
                                                   realw* epsilondev_xz,
-                                                  realw* epsilondev_yz) {}
+                                                  realw* epsilondev_yz) {} 
 
 void FC_FUNC_(transfer_b_strain_cm_to_device,
               TRANSFER_B_STRAIN_CM_TO_DEVICE)(long* Mesh_pointer,
@@ -672,7 +672,7 @@
                                               realw* epsilondev_yy,
                                               realw* epsilondev_xy,
                                               realw* epsilondev_xz,
-                                              realw* epsilondev_yz) {}
+                                              realw* epsilondev_yz) {} 
 
 void FC_FUNC_(transfer_strain_ic_from_device,
               TRANSFER_STRAIN_IC_FROM_DEVICE)(long* Mesh_pointer,
@@ -681,7 +681,7 @@
                                               realw* epsilondev_yy,
                                               realw* epsilondev_xy,
                                               realw* epsilondev_xz,
-                                              realw* epsilondev_yz) {}
+                                              realw* epsilondev_yz) {} 
 
 void FC_FUNC_(transfer_b_strain_ic_to_device,
               TRANSFER_B_STRAIN_IC_TO_DEVICE)(long* Mesh_pointer,
@@ -689,7 +689,7 @@
                                               realw* epsilondev_yy,
                                               realw* epsilondev_xy,
                                               realw* epsilondev_xz,
-                                              realw* epsilondev_yz) {}
+                                              realw* epsilondev_yz) {} 
 
 void FC_FUNC_(transfer_b_rmemory_cm_to_device,
               TRANSFER_B_RMEMORY_CM_TO_DEVICE)(long* Mesh_pointer,
@@ -697,7 +697,7 @@
                                                realw* b_R_yy,
                                                realw* b_R_xy,
                                                realw* b_R_xz,
-                                               realw* b_R_yz) {}
+                                               realw* b_R_yz) {} 
 
 void FC_FUNC_(transfer_b_rmemory_ic_to_device,
               TRANSFER_B_RMEMORY_IC_TO_DEVICE)(long* Mesh_pointer,
@@ -705,17 +705,17 @@
                                                realw* b_R_yy,
                                                realw* b_R_xy,
                                                realw* b_R_xz,
-                                               realw* b_R_yz) {}
+                                               realw* b_R_yz) {} 
 
 void FC_FUNC_(transfer_rotation_from_device,
               TRANSFER_ROTATION_FROM_DEVICE)(long* Mesh_pointer,
                                              realw* A_array_rotation,
-                                             realw* B_array_rotation) {}
+                                             realw* B_array_rotation) {} 
 
 void FC_FUNC_(transfer_b_rotation_to_device,
               TRANSFER_B_ROTATION_TO_DEVICE)(long* Mesh_pointer,
                                               realw* A_array_rotation,
-                                              realw* B_array_rotation) {}
+                                              realw* B_array_rotation) {} 
 
 void FC_FUNC_(transfer_kernels_cm_to_host,
               TRANSFER_KERNELS_CM_TO_HOST)(long* Mesh_pointer,
@@ -723,30 +723,30 @@
                                            realw* h_alpha_kl,
                                            realw* h_beta_kl,
                                            realw* h_cijkl_kl,
-                                           int* NSPEC) {}
+                                           int* NSPEC) {} 
 
 void FC_FUNC_(transfer_kernels_ic_to_host,
               TRANSFER_KERNELS_IC_TO_HOST)(long* Mesh_pointer,
                                            realw* h_rho_kl,
                                            realw* h_alpha_kl,
                                            realw* h_beta_kl,
-                                           int* NSPEC) {}
+                                           int* NSPEC) {} 
 
 void FC_FUNC_(transfer_kernels_oc_to_host,
               TRANSFER_KERNELS_OC_TO_HOST)(long* Mesh_pointer,
                                            realw* h_rho_kl,
                                            realw* h_alpha_kl,
-                                           int* NSPEC) {}
+                                           int* NSPEC) {} 
 
 void FC_FUNC_(transfer_kernels_noise_to_host,
               TRANSFER_KERNELS_NOISE_TO_HOST)(long* Mesh_pointer,
                                               realw* h_Sigma_kl,
-                                              int* NSPEC) {}
+                                              int* NSPEC) {} 
 
 void FC_FUNC_(transfer_kernels_hess_cm_tohost,
               TRANSFER_KERNELS_HESS_CM_TOHOST)(long* Mesh_pointer,
                                               realw* h_hess_kl,
-                                              int* NSPEC) {}
+                                              int* NSPEC) {} 
 
 
 //
@@ -758,39 +758,39 @@
                                           realw* deltat_f,
                                           realw* deltatsqover2_f,
                                           realw* deltatover2_f,
-                                          int* FORWARD_OR_ADJOINT) {}
+                                          int* FORWARD_OR_ADJOINT) {} 
 
 void FC_FUNC_(update_displacement_cm_cuda,
               UPDATE_DISPLACMENT_CM_CUDA)(long* Mesh_pointer_f,
                                           realw* deltat_f,
                                           realw* deltatsqover2_f,
                                           realw* deltatover2_f,
-                                          int* FORWARD_OR_ADJOINT) {}
+                                          int* FORWARD_OR_ADJOINT) {} 
 
 void FC_FUNC_(update_displacement_oc_cuda,
               UPDATE_DISPLACEMENT_OC_cuda)(long* Mesh_pointer_f,
                                            realw* deltat_f,
                                            realw* deltatsqover2_f,
                                            realw* deltatover2_f,
-                                           int* FORWARD_OR_ADJOINT) {}
+                                           int* FORWARD_OR_ADJOINT) {} 
 
 void FC_FUNC_(multiply_accel_elastic_cuda,
               MULTIPLY_ACCEL_ELASTIC_CUDA)(long* Mesh_pointer,
-                                           int* FORWARD_OR_ADJOINT) {}
+                                           int* FORWARD_OR_ADJOINT) {} 
 
 void FC_FUNC_(update_veloc_elastic_cuda,
               UPDATE_VELOC_ELASTIC_CUDA)(long* Mesh_pointer,
                                          realw* deltatover2_f,
-                                         int* FORWARD_OR_ADJOINT) {}
+                                         int* FORWARD_OR_ADJOINT) {} 
 
 void FC_FUNC_(multiply_accel_acoustic_cuda,
               MULTIPLY_ACCEL_ACOUSTIC_CUDA)(long* Mesh_pointer,
-                                            int* FORWARD_OR_ADJOINT) {}
+                                            int* FORWARD_OR_ADJOINT) {} 
 
 void FC_FUNC_(update_veloc_acoustic_cuda,
               UPDATE_VELOC_ACOUSTIC_CUDA)(long* Mesh_pointer,
                                           realw* deltatover2_f,
-                                          int* FORWARD_OR_ADJOINT) {}
+                                          int* FORWARD_OR_ADJOINT) {} 
 
 
 //
@@ -810,5 +810,5 @@
                                                int* number_receiver_global,
                                                int* ispec_selected_rec,
                                                int* ispec_selected_source,
-                                               int* ibool) {}
+                                               int* ibool) {} 
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/create_regions_mesh.F90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/create_regions_mesh.F90	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/create_regions_mesh.F90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -499,6 +499,8 @@
   ! local parameters
   integer :: ier
 
+  ! adios needs properly initialized arrays, otherwise its intrinsic check procedures will cause undefined operations
+
   ! new attenuation definition on all GLL points
   ! attenuation
   if (ATTENUATION) then
@@ -513,11 +515,15 @@
           tau_e_store(N_SLS,ATT1,ATT2,ATT3,nspec_att),stat=ier)
   if(ier /= 0) stop 'error in allocate 1'
 
+  Qmu_store(:,:,:,:) = 0.0; tau_e_store(:,:,:,:,:) = 0.0
+
   ! array with model density
   allocate(rhostore(NGLLX,NGLLY,NGLLZ,nspec), &
           dvpstore(NGLLX,NGLLY,NGLLZ,nspec),stat=ier)
   if(ier /= 0) stop 'error in allocate 6'
 
+  rhostore(:,:,:,:) = 0.0; dvpstore(:,:,:,:) = 0.0
+
   ! for anisotropy
   allocate(kappavstore(NGLLX,NGLLY,NGLLZ,nspec), &
           muvstore(NGLLX,NGLLY,NGLLZ,nspec), &
@@ -527,6 +533,11 @@
           ispec_is_tiso(nspec),stat=ier)
   if(ier /= 0) stop 'error in allocate 7'
 
+  kappavstore(:,:,:,:) = 0.0; kappahstore(:,:,:,:) = 0.0
+  muvstore(:,:,:,:) = 0.0; muhstore(:,:,:,:) = 0.0
+  eta_anisostore(:,:,:,:) = 0.0
+  ispec_is_tiso(:) = .false.
+
   ! Stacey absorbing boundaries
   if(NCHUNKS /= 6) then
     nspec_stacey = nspec
@@ -537,6 +548,8 @@
           rho_vs(NGLLX,NGLLY,NGLLZ,nspec_stacey),stat=ier)
   if(ier /= 0) stop 'error in allocate 8'
 
+  rho_vp(:,:,:,:) = 0.0; rho_vs(:,:,:,:) = 0.0
+
   ! anisotropy
   if((ANISOTROPIC_INNER_CORE .and. iregion_code == IREGION_INNER_CORE) .or. &
      (ANISOTROPIC_3D_MANTLE .and. iregion_code == IREGION_CRUST_MANTLE)) then
@@ -567,52 +580,78 @@
           c66store(NGLLX,NGLLY,NGLLZ,nspec_ani),stat=ier)
   if(ier /= 0) stop 'error in allocate 9'
 
+  c11store(:,:,:,:) = 0.0; c12store(:,:,:,:) = 0.0; c13store(:,:,:,:) = 0.0
+  c14store(:,:,:,:) = 0.0; c15store(:,:,:,:) = 0.0; c16store(:,:,:,:) = 0.0
+  c22store(:,:,:,:) = 0.0; c23store(:,:,:,:) = 0.0; c24store(:,:,:,:) = 0.0
+  c25store(:,:,:,:) = 0.0; c26store(:,:,:,:) = 0.0; c33store(:,:,:,:) = 0.0
+  c34store(:,:,:,:) = 0.0; c35store(:,:,:,:) = 0.0; c36store(:,:,:,:) = 0.0
+  c44store(:,:,:,:) = 0.0; c45store(:,:,:,:) = 0.0; c46store(:,:,:,:) = 0.0
+  c55store(:,:,:,:) = 0.0; c56store(:,:,:,:) = 0.0; c66store(:,:,:,:) = 0.0
+
   ! boundary locator
   allocate(iboun(6,nspec),stat=ier)
   if(ier /= 0) stop 'error in allocate 10'
 
   ! boundary parameters locator
   allocate(ibelm_xmin(NSPEC2DMAX_XMIN_XMAX), &
-          ibelm_xmax(NSPEC2DMAX_XMIN_XMAX), &
-          ibelm_ymin(NSPEC2DMAX_YMIN_YMAX), &
-          ibelm_ymax(NSPEC2DMAX_YMIN_YMAX), &
-          ibelm_bottom(NSPEC2D_BOTTOM), &
-          ibelm_top(NSPEC2D_TOP),stat=ier)
+           ibelm_xmax(NSPEC2DMAX_XMIN_XMAX), &
+           ibelm_ymin(NSPEC2DMAX_YMIN_YMAX), &
+           ibelm_ymax(NSPEC2DMAX_YMIN_YMAX), &
+           ibelm_bottom(NSPEC2D_BOTTOM), &
+           ibelm_top(NSPEC2D_TOP),stat=ier)
   if(ier /= 0) stop 'error in allocate 11'
 
+  ibelm_xmin(:) = 0; ibelm_xmax(:) = 0
+  ibelm_ymin(:) = 0; ibelm_ymax(:) = 0
+  ibelm_bottom(:) = 0; ibelm_top(:) = 0
+
   ! 2-D jacobians and normals
   allocate(jacobian2D_xmin(NGLLY,NGLLZ,NSPEC2DMAX_XMIN_XMAX), &
-          jacobian2D_xmax(NGLLY,NGLLZ,NSPEC2DMAX_XMIN_XMAX), &
-          jacobian2D_ymin(NGLLX,NGLLZ,NSPEC2DMAX_YMIN_YMAX), &
-          jacobian2D_ymax(NGLLX,NGLLZ,NSPEC2DMAX_YMIN_YMAX), &
-          jacobian2D_bottom(NGLLX,NGLLY,NSPEC2D_BOTTOM), &
-          jacobian2D_top(NGLLX,NGLLY,NSPEC2D_TOP),stat=ier)
+           jacobian2D_xmax(NGLLY,NGLLZ,NSPEC2DMAX_XMIN_XMAX), &
+           jacobian2D_ymin(NGLLX,NGLLZ,NSPEC2DMAX_YMIN_YMAX), &
+           jacobian2D_ymax(NGLLX,NGLLZ,NSPEC2DMAX_YMIN_YMAX), &
+           jacobian2D_bottom(NGLLX,NGLLY,NSPEC2D_BOTTOM), &
+           jacobian2D_top(NGLLX,NGLLY,NSPEC2D_TOP),stat=ier)
   if(ier /= 0) stop 'error in allocate 12'
 
+  jacobian2D_xmin(:,:,:) = 0.0; jacobian2D_xmax(:,:,:) = 0.0
+  jacobian2D_ymin(:,:,:) = 0.0; jacobian2D_ymax(:,:,:) = 0.0
+  jacobian2D_bottom(:,:,:) = 0.0; jacobian2D_top(:,:,:) = 0.0
+
   allocate(normal_xmin(NDIM,NGLLY,NGLLZ,NSPEC2DMAX_XMIN_XMAX), &
-          normal_xmax(NDIM,NGLLY,NGLLZ,NSPEC2DMAX_XMIN_XMAX), &
-          normal_ymin(NDIM,NGLLX,NGLLZ,NSPEC2DMAX_YMIN_YMAX), &
-          normal_ymax(NDIM,NGLLX,NGLLZ,NSPEC2DMAX_YMIN_YMAX), &
-          normal_bottom(NDIM,NGLLX,NGLLY,NSPEC2D_BOTTOM), &
-          normal_top(NDIM,NGLLX,NGLLY,NSPEC2D_TOP),stat=ier)
+           normal_xmax(NDIM,NGLLY,NGLLZ,NSPEC2DMAX_XMIN_XMAX), &
+           normal_ymin(NDIM,NGLLX,NGLLZ,NSPEC2DMAX_YMIN_YMAX), &
+           normal_ymax(NDIM,NGLLX,NGLLZ,NSPEC2DMAX_YMIN_YMAX), &
+           normal_bottom(NDIM,NGLLX,NGLLY,NSPEC2D_BOTTOM), &
+           normal_top(NDIM,NGLLX,NGLLY,NSPEC2D_TOP),stat=ier)
   if(ier /= 0) stop 'error in allocate 13'
 
+  normal_xmin(:,:,:,:) = 0.0; normal_xmax(:,:,:,:) = 0.0
+  normal_ymin(:,:,:,:) = 0.0; normal_ymax(:,:,:,:) = 0.0
+  normal_bottom(:,:,:,:) = 0.0; normal_top(:,:,:,:) = 0.0
+
   ! Stacey
   if( ipass == 1 .and. NCHUNKS /= 6 ) then
     allocate(nimin(2,NSPEC2DMAX_YMIN_YMAX), &
-            nimax(2,NSPEC2DMAX_YMIN_YMAX), &
-            njmin(2,NSPEC2DMAX_XMIN_XMAX), &
-            njmax(2,NSPEC2DMAX_XMIN_XMAX), &
-            nkmin_xi(2,NSPEC2DMAX_XMIN_XMAX), &
-            nkmin_eta(2,NSPEC2DMAX_YMIN_YMAX),stat=ier)
+             nimax(2,NSPEC2DMAX_YMIN_YMAX), &
+             njmin(2,NSPEC2DMAX_XMIN_XMAX), &
+             njmax(2,NSPEC2DMAX_XMIN_XMAX), &
+             nkmin_xi(2,NSPEC2DMAX_XMIN_XMAX), &
+             nkmin_eta(2,NSPEC2DMAX_YMIN_YMAX),stat=ier)
     if(ier /= 0) stop 'error in allocate 14'
   endif
 
+  nimin(:,:) = 0; nimax(:,:) = 0
+  njmin(:,:) = 0; njmax(:,:) = 0
+  nkmin_xi(:,:) = 0; nkmin_eta(:,:) = 0
+
   ! MPI cut-planes parameters along xi and along eta
   allocate(iMPIcut_xi(2,nspec), &
-          iMPIcut_eta(2,nspec),stat=ier)
+           iMPIcut_eta(2,nspec),stat=ier)
   if(ier /= 0) stop 'error in allocate 15'
 
+  iMPIcut_xi(:,:) = .false.; iMPIcut_eta(:,:) = .false.
+
   ! MPI buffer indices
   !
   ! define maximum size for message buffers
@@ -623,34 +662,44 @@
 
   if( ipass == 1 ) then
     allocate(iboolleft_xi(NGLOB2DMAX_XMIN_XMAX(iregion_code)), &
-            iboolright_xi(NGLOB2DMAX_XMIN_XMAX(iregion_code)), &
-            iboolleft_eta(NGLOB2DMAX_YMIN_YMAX(iregion_code)), &
-            iboolright_eta(NGLOB2DMAX_YMIN_YMAX(iregion_code)), &
-            stat=ier)
+             iboolright_xi(NGLOB2DMAX_XMIN_XMAX(iregion_code)), &
+             iboolleft_eta(NGLOB2DMAX_YMIN_YMAX(iregion_code)), &
+             iboolright_eta(NGLOB2DMAX_YMIN_YMAX(iregion_code)), &
+             stat=ier)
     if(ier /= 0) stop 'error in allocate 15b'
 
+    iboolleft_xi(:) = 0; iboolright_xi(:) = 0
+    iboolleft_eta(:) = 0; iboolright_eta(:) = 0
+
     allocate(ibool1D_leftxi_lefteta(NGLOB1D_RADIAL_MAX), &
-            ibool1D_rightxi_lefteta(NGLOB1D_RADIAL_MAX), &
-            ibool1D_leftxi_righteta(NGLOB1D_RADIAL_MAX), &
-            ibool1D_rightxi_righteta(NGLOB1D_RADIAL_MAX), &
-            stat=ier)
+             ibool1D_rightxi_lefteta(NGLOB1D_RADIAL_MAX), &
+             ibool1D_leftxi_righteta(NGLOB1D_RADIAL_MAX), &
+             ibool1D_rightxi_righteta(NGLOB1D_RADIAL_MAX), &
+             stat=ier)
     if(ier /= 0) stop 'error in allocate 15c'
 
+    ibool1D_leftxi_lefteta(:) = 0; ibool1D_rightxi_lefteta(:) = 0
+    ibool1D_leftxi_righteta(:) = 0; ibool1D_rightxi_righteta(:) = 0
+
     allocate(xyz1D_leftxi_lefteta(NGLOB1D_RADIAL_MAX,NDIM), &
-            xyz1D_rightxi_lefteta(NGLOB1D_RADIAL_MAX,NDIM), &
-            xyz1D_leftxi_righteta(NGLOB1D_RADIAL_MAX,NDIM), &
-            xyz1D_rightxi_righteta(NGLOB1D_RADIAL_MAX,NDIM), &
-            stat=ier)
+             xyz1D_rightxi_lefteta(NGLOB1D_RADIAL_MAX,NDIM), &
+             xyz1D_leftxi_righteta(NGLOB1D_RADIAL_MAX,NDIM), &
+             xyz1D_rightxi_righteta(NGLOB1D_RADIAL_MAX,NDIM), &
+             stat=ier)
     if(ier /= 0) stop 'error in allocate 15c'
 
+    xyz1D_leftxi_lefteta(:,:) = 0.0; xyz1D_rightxi_lefteta(:,:) = 0.0
+    xyz1D_leftxi_righteta(:,:) = 0.0; xyz1D_rightxi_righteta(:,:) = 0.0
+
     allocate(iboolcorner(NGLOB1D_RADIAL(iregion_code),NUMCORNERS_SHARED), &
-            iboolfaces(NGLOB2DMAX_XY,NUMFACES_SHARED), &
-            stat=ier)
+             iboolfaces(NGLOB2DMAX_XY,NUMFACES_SHARED), &
+             stat=ier)
     if(ier /= 0) stop 'error in allocate 15b'
 
+    iboolcorner(:,:) = 0; iboolfaces(:,:) = 0
+
   endif
 
-
   ! store and save the final arrays only in the second pass
   ! therefore in the first pass some arrays can be allocated with a dummy size
   if(ipass == 1) then
@@ -659,16 +708,20 @@
     nspec_actually = nspec
   endif
   allocate(xixstore(NGLLX,NGLLY,NGLLZ,nspec_actually), &
-          xiystore(NGLLX,NGLLY,NGLLZ,nspec_actually), &
-          xizstore(NGLLX,NGLLY,NGLLZ,nspec_actually), &
-          etaxstore(NGLLX,NGLLY,NGLLZ,nspec_actually), &
-          etaystore(NGLLX,NGLLY,NGLLZ,nspec_actually), &
-          etazstore(NGLLX,NGLLY,NGLLZ,nspec_actually), &
-          gammaxstore(NGLLX,NGLLY,NGLLZ,nspec_actually), &
-          gammaystore(NGLLX,NGLLY,NGLLZ,nspec_actually), &
-          gammazstore(NGLLX,NGLLY,NGLLZ,nspec_actually),stat=ier)
+           xiystore(NGLLX,NGLLY,NGLLZ,nspec_actually), &
+           xizstore(NGLLX,NGLLY,NGLLZ,nspec_actually), &
+           etaxstore(NGLLX,NGLLY,NGLLZ,nspec_actually), &
+           etaystore(NGLLX,NGLLY,NGLLZ,nspec_actually), &
+           etazstore(NGLLX,NGLLY,NGLLZ,nspec_actually), &
+           gammaxstore(NGLLX,NGLLY,NGLLZ,nspec_actually), &
+           gammaystore(NGLLX,NGLLY,NGLLZ,nspec_actually), &
+           gammazstore(NGLLX,NGLLY,NGLLZ,nspec_actually),stat=ier)
   if(ier /= 0) stop 'error in allocate 16'
 
+  xixstore(:,:,:,:) = 0.0; xiystore(:,:,:,:) = 0.0; xizstore(:,:,:,:) = 0.0
+  etaxstore(:,:,:,:) = 0.0; etaystore(:,:,:,:) = 0.0; etazstore(:,:,:,:) = 0.0
+  gammaxstore(:,:,:,:) = 0.0; gammaystore(:,:,:,:) = 0.0; gammazstore(:,:,:,:) = 0.0
+
   ! boundary mesh
   if (ipass == 2 .and. SAVE_BOUNDARY_MESH .and. iregion_code == IREGION_CRUST_MANTLE) then
     NSPEC2D_MOHO = NSPEC2D_TOP
@@ -680,16 +733,22 @@
     NSPEC2D_670 = 1
   endif
   allocate(ibelm_moho_top(NSPEC2D_MOHO),ibelm_moho_bot(NSPEC2D_MOHO), &
-          ibelm_400_top(NSPEC2D_400),ibelm_400_bot(NSPEC2D_400), &
-          ibelm_670_top(NSPEC2D_670),ibelm_670_bot(NSPEC2D_670), &
-          normal_moho(NDIM,NGLLX,NGLLY,NSPEC2D_MOHO), &
-          normal_400(NDIM,NGLLX,NGLLY,NSPEC2D_400), &
-          normal_670(NDIM,NGLLX,NGLLY,NSPEC2D_670), &
-          jacobian2D_moho(NGLLX,NGLLY,NSPEC2D_MOHO), &
-          jacobian2D_400(NGLLX,NGLLY,NSPEC2D_400), &
-          jacobian2D_670(NGLLX,NGLLY,NSPEC2D_670),stat=ier)
+           ibelm_400_top(NSPEC2D_400),ibelm_400_bot(NSPEC2D_400), &
+           ibelm_670_top(NSPEC2D_670),ibelm_670_bot(NSPEC2D_670), &
+           normal_moho(NDIM,NGLLX,NGLLY,NSPEC2D_MOHO), &
+           normal_400(NDIM,NGLLX,NGLLY,NSPEC2D_400), &
+           normal_670(NDIM,NGLLX,NGLLY,NSPEC2D_670), &
+           jacobian2D_moho(NGLLX,NGLLY,NSPEC2D_MOHO), &
+           jacobian2D_400(NGLLX,NGLLY,NSPEC2D_400), &
+           jacobian2D_670(NGLLX,NGLLY,NSPEC2D_670),stat=ier)
   if(ier /= 0) stop 'error in allocate 17'
 
+  ibelm_moho_top(:) = 0; ibelm_moho_bot(:) = 0
+  ibelm_400_top(:) = 0; ibelm_400_bot(:) = 0
+  ibelm_670_top(:) = 0; ibelm_670_bot(:) = 0
+  normal_moho(:,:,:,:) = 0.0; normal_400(:,:,:,:) = 0.0; normal_670(:,:,:,:) = 0.0
+  jacobian2D_moho(:,:,:) = 0.0; jacobian2D_400(:,:,:) = 0.0; jacobian2D_670(:,:,:) = 0.0
+
   end subroutine crm_allocate_arrays
 
 !
@@ -1229,7 +1288,7 @@
 
   if( ADIOS_ENABLED .and. ADIOS_FOR_AVS_DX ) then
     call crm_save_mesh_files_adios(nspec,npointot,iregion_code, &
-        num_ibool_AVS_DX, mask_ibool)
+                                   num_ibool_AVS_DX, mask_ibool)
   else
     call write_AVS_DX_global_data(myrank,prname,nspec,ibool,idoubling, &
         xstore,ystore,zstore, num_ibool_AVS_DX,mask_ibool,npointot)

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/create_regions_mesh_adios.f90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/create_regions_mesh_adios.f90	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/create_regions_mesh_adios.f90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -26,9 +26,9 @@
 !=====================================================================
 
 
-subroutine crm_save_mesh_files_adios(nspec,npointot,iregion_code, &
-    num_ibool_AVS_DX, mask_ibool)
-  use mpi
+  subroutine crm_save_mesh_files_adios(nspec,npointot,iregion_code, &
+                                       num_ibool_AVS_DX, mask_ibool)
+
   use adios_write_mod
 
   use meshfem3d_par,only: &
@@ -67,16 +67,22 @@
   type(avs_dx_surface_t) :: avs_dx_surface_vars
 
   character(len=150) :: reg_name, outputname, group_name
-  integer :: comm, sizeprocs, ier
+  integer :: comm, ier
   integer(kind=8) :: adios_group, group_size_inc, adios_totalsize, adios_handle
 
+  integer :: sizeprocs
+
+  ! number of mpi processes
+  call world_size(sizeprocs)
+
   ! create a prefix for the file name such as LOCAL_PATH/regX_
   call create_name_database_adios(reg_name,iregion_code,LOCAL_PATH)
   outputname = trim(reg_name) // "AVS_DX.bp"
   write(group_name,"('SPECFEM3D_GLOBE_AVS_DX_reg',i1)") iregion_code
-  call world_size(sizeprocs) ! TODO keep it in parameters
+
   ! Alias COMM_WORLD to use ADIOS
-  call MPI_Comm_dup (MPI_COMM_WORLD, comm, ier)
+  call world_duplicate(comm)
+
   group_size_inc = 0
   call adios_declare_group(adios_group, group_name, &
       "", 0, ier)
@@ -171,4 +177,5 @@
       ISOTROPIC_3D_MANTLE)
   call free_AVS_DX_surfaces_data_adios(myrank, avs_dx_surface_vars, &
       ISOTROPIC_3D_MANTLE)
-end subroutine crm_save_mesh_files_adios
+
+  end subroutine crm_save_mesh_files_adios

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/get_absorb.f90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/get_absorb.f90	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/get_absorb.f90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -138,8 +138,9 @@
   ! This files will be saved with the help of ADIOS if the
   ! ADIOS_FOR_ARRAYS_SOLVER flag is set to true in the Par_file
   if( ADIOS_ENABLED .and. ADIOS_FOR_ARRAYS_SOLVER ) then
-    call get_absorb_adios(myrank, iregion, nimin, nimax, njmin, njmax, &
-        nkmin_xi, nkmin_eta, NSPEC2DMAX_XMIN_XMAX,NSPEC2DMAX_YMIN_YMAX)
+    call get_absorb_adios(myrank, iregion, &
+                          nimin, nimax, njmin, njmax, nkmin_xi, nkmin_eta, &
+                          NSPEC2DMAX_XMIN_XMAX,NSPEC2DMAX_YMIN_YMAX)
   else
     open(unit=27,file=prname(1:len_trim(prname))//'stacey.bin', &
           status='unknown',form='unformatted',action='write',iostat=ier)

Copied: seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/get_absorb_adios.F90 (from rev 22910, seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/get_absorb_adios.f90)
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/get_absorb_adios.F90	                        (rev 0)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/get_absorb_adios.F90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -0,0 +1,168 @@
+!=====================================================================
+!
+!          S p e c f e m 3 D  G l o b e  V e r s i o n  6 . 0
+!          --------------------------------------------------
+!
+!          Main authors: Dimitri Komatitsch and Jeroen Tromp
+!                        Princeton University, USA
+!             and CNRS / INRIA / University of Pau, France
+! (c) Princeton University and CNRS / INRIA / University of Pau
+!                            August 2013
+!
+! This 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 get_absorb_adios.f90
+!! \brief Function to write stacey boundary condition to disk with ADIOS.
+!! \author MPBL
+!-------------------------------------------------------------------------------
+
+#include "config.fh"
+
+!===============================================================================
+!> \brief Write stacey boundary conditions to a single file using ADIOS
+!!
+!! \param myrank The MPI rank of the current process
+!! \param iregion The region the absorbing conditon is written for. Check
+!!                constant.h files to see what these regions are.
+!! \param nimin An array to be written
+!! \param nimax An array to be written
+!! \param njmin An array to be written
+!! \param njmax An array to be written
+!! \param nkmin_xi An array to be written
+!! \param nkmin_eta An array to be written
+!! \param NSPEC2DMAX_XMIN_XMAX Integer to compute the size of the arrays
+!!                             in argument
+!! \param NSPEC2DMAX_YMIN_YMAX Integer to compute the size of the arrays
+!!                             in argument
+!!
+!! \note This routine only call adios to write the file to disk, Note that he
+!!       necessary data preparation is done by the get_absorb() routine.
+subroutine get_absorb_adios(myrank, iregion, &
+                            nimin, nimax, njmin, njmax, nkmin_xi, nkmin_eta, &
+                            NSPEC2DMAX_XMIN_XMAX,NSPEC2DMAX_YMIN_YMAX)
+
+  use constants
+  use adios_write_mod
+  use adios_helpers_mod
+  use meshfem3D_par, only: &
+    LOCAL_PATH
+
+  ! Stacey, define flags for absorbing boundaries
+  implicit none
+
+  integer :: myrank
+  integer :: NSPEC2DMAX_XMIN_XMAX,NSPEC2DMAX_YMIN_YMAX
+
+  integer,dimension(2,NSPEC2DMAX_YMIN_YMAX) :: nimin,nimax
+  integer,dimension(2,NSPEC2DMAX_XMIN_XMAX) :: njmin,njmax
+  integer,dimension(2,NSPEC2DMAX_XMIN_XMAX) :: nkmin_xi
+  integer,dimension(2,NSPEC2DMAX_YMIN_YMAX) :: nkmin_eta
+
+  character(len=150) :: outputname, group_name
+  integer :: comm, local_dim, iregion
+  integer(kind=8) :: group_size_inc
+  ! ADIOS variables
+  integer                 :: adios_err
+  integer(kind=8)         :: adios_group, adios_handle
+  integer(kind=8)         :: adios_totalsize
+  character(len=128)      :: region_name
+
+  integer, save :: num_regions_written = 0
+
+  integer :: sizeprocs
+
+  ! number of mpi processes
+  call world_size(sizeprocs)
+
+  ! create a prefix for the file name such as LOCAL_PATH/regX_
+  !call create_name_database_adios(reg_name,iregion,LOCAL_PATH)
+
+  write(region_name,"('reg',i1, '/')") iregion
+
+  ! Postpend the actual file name.
+  !outputname = trim(reg_name) // "stacey.bp"
+  outputname = trim(LOCAL_PATH) // "/stacey.bp"
+
+  ! save these temporary arrays for the solver for Stacey conditions
+  write(group_name,"('SPECFEM3D_GLOBE_STACEY_reg',i1)") iregion
+
+  ! Alias COMM_WORLD to use ADIOS
+  call world_duplicate(comm)
+
+  ! set the adios group size to 0 before incremented by calls to
+  ! helpers functions.
+  group_size_inc = 0
+  call adios_declare_group(adios_group, group_name, &
+                           "", 0, adios_err)
+  ! We set the transport method to 'MPI'. This seems to be the correct choice
+  ! for now. We might want to move this to the constant.h file later on.
+  call adios_select_method(adios_group, "MPI", "", "", adios_err)
+
+  !--- Define ADIOS variables -----------------------------
+  local_dim = 2*NSPEC2DMAX_XMIN_XMAX
+  call define_adios_global_array1D(adios_group, group_size_inc, local_dim, &
+                                   region_name, STRINGIFY_VAR(njmin))
+  call define_adios_global_array1D(adios_group, group_size_inc, local_dim, &
+                                   region_name, STRINGIFY_VAR(njmax))
+  call define_adios_global_array1D(adios_group, group_size_inc, local_dim, &
+                                   region_name, STRINGIFY_VAR(nkmin_xi))
+
+  local_dim = 2*NSPEC2DMAX_YMIN_YMAX
+  call define_adios_global_array1D(adios_group, group_size_inc, local_dim, &
+                                   region_name, STRINGIFY_VAR(nimin))
+  call define_adios_global_array1D(adios_group, group_size_inc, local_dim, &
+                                   region_name, STRINGIFY_VAR(nimax))
+  call define_adios_global_array1D(adios_group, group_size_inc, local_dim, &
+                                   region_name, STRINGIFY_VAR(nkmin_eta))
+
+  !--- Open an ADIOS handler to the restart file. ---------
+  !call adios_open (adios_handle, group_name, &
+  !    outputname, "w", comm, adios_err);
+  if (num_regions_written == 0) then
+    call adios_open (adios_handle, group_name, outputname, "w", comm, adios_err)
+  else
+    call adios_open (adios_handle, group_name, outputname, "a", comm, adios_err);
+  endif
+
+  call adios_group_size (adios_handle, group_size_inc, &
+                         adios_totalsize, adios_err)
+
+  !--- Schedule writes for the previously defined ADIOS variables
+  local_dim = 2*NSPEC2DMAX_XMIN_XMAX
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, &
+                                   local_dim, trim(region_name) // STRINGIFY_VAR(njmin))
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, &
+                                   local_dim, trim(region_name) // STRINGIFY_VAR(njmax))
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, &
+                                   local_dim, trim(region_name) // STRINGIFY_VAR(nkmin_xi))
+
+  local_dim = 2*NSPEC2DMAX_YMIN_YMAX
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, &
+                                   local_dim, trim(region_name) // STRINGIFY_VAR(nimin))
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, &
+                                   local_dim, trim(region_name) // STRINGIFY_VAR(nimax))
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, &
+                                   local_dim, trim(region_name) // STRINGIFY_VAR(nkmin_eta))
+
+  !--- Reset the path to zero and perform the actual write to disk
+  call adios_close(adios_handle, adios_err)
+
+  num_regions_written = num_regions_written + 1
+
+end subroutine get_absorb_adios
+

Deleted: seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/get_absorb_adios.f90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/get_absorb_adios.f90	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/get_absorb_adios.f90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -1,160 +0,0 @@
-!=====================================================================
-!
-!          S p e c f e m 3 D  G l o b e  V e r s i o n  6 . 0
-!          --------------------------------------------------
-!
-!          Main authors: Dimitri Komatitsch and Jeroen Tromp
-!                        Princeton University, USA
-!             and CNRS / INRIA / University of Pau, France
-! (c) Princeton University and CNRS / INRIA / University of Pau
-!                            August 2013
-!
-! This 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 get_absorb_adios.f90
-!! \brief Function to write stacey boundary condition to disk with ADIOS.
-!! \author MPBL
-!-------------------------------------------------------------------------------
-
-!===============================================================================
-!> \brief Write stacey boundary conditions to a single file using ADIOS
-!!
-!! \param myrank The MPI rank of the current process
-!! \param iregion The region the absorbing conditon is written for. Check
-!!                constant.h files to see what these regions are.
-!! \param nimin An array to be written
-!! \param nimax An array to be written
-!! \param njmin An array to be written
-!! \param njmax An array to be written
-!! \param nkmin_xi An array to be written
-!! \param nkmin_eta An array to be written
-!! \param NSPEC2DMAX_XMIN_XMAX Integer to compute the size of the arrays
-!!                             in argument
-!! \param NSPEC2DMAX_YMIN_YMAX Integer to compute the size of the arrays
-!!                             in argument
-!!
-!! \note This routine only call adios to write the file to disk, Note that he
-!!       necessary data preparation is done by the get_absorb() routine.
-subroutine get_absorb_adios(myrank, iregion, nimin, nimax, njmin, njmax, &
-  nkmin_xi, nkmin_eta, NSPEC2DMAX_XMIN_XMAX,NSPEC2DMAX_YMIN_YMAX)
-
-  use constants
-  use mpi
-  use adios_write_mod
-  use meshfem3D_par, only: LOCAL_PATH
-
-  ! Stacey, define flags for absorbing boundaries
-  implicit none
-
-  integer :: myrank
-  integer :: NSPEC2DMAX_XMIN_XMAX,NSPEC2DMAX_YMIN_YMAX
-
-  integer,dimension(2,NSPEC2DMAX_YMIN_YMAX) :: nimin,nimax
-  integer,dimension(2,NSPEC2DMAX_XMIN_XMAX) :: njmin,njmax
-  integer,dimension(2,NSPEC2DMAX_XMIN_XMAX) :: nkmin_xi
-  integer,dimension(2,NSPEC2DMAX_YMIN_YMAX) :: nkmin_eta
-
-  character(len=150) :: reg_name, outputname, group_name
-  integer :: sizeprocs, comm, local_dim, ierr, iregion
-  integer(kind=8) :: group_size_inc
-  ! ADIOS variables
-  integer                 :: adios_err
-  integer(kind=8)         :: adios_group, adios_handle, varid
-  integer(kind=8)         :: adios_groupsize, adios_totalsize
-
-  ! create a prefix for the file name such as LOCAL_PATH/regX_
-  call create_name_database_adios(reg_name,iregion,LOCAL_PATH)
-
-  ! Postpend the actual file name.
-  outputname = trim(reg_name) // "stacey.bp"
-
-  ! save these temporary arrays for the solver for Stacey conditions
-  write(group_name,"('SPECFEM3D_GLOBE_STACEY_reg',i1)") iregion
-  call world_size(sizeprocs) ! TODO keep it in parameters
-  ! Alias COMM_WORLD to use ADIOS
-  call MPI_Comm_dup (MPI_COMM_WORLD, comm, ierr)
-  ! set the adios group size to 0 before incremented by calls to
-  ! helpers functions.
-  group_size_inc = 0
-  call adios_declare_group(adios_group, group_name, &
-      "", 0, adios_err)
-  ! We set the transport method to 'MPI'. This seems to be the correct choice
-  ! for now. We might want to move this to the constant.h file later on.
-  call adios_select_method(adios_group, "MPI", "", "", adios_err)
-
-  !--- Define ADIOS variables -----------------------------
-  local_dim = 2*NSPEC2DMAX_XMIN_XMAX
-  call define_adios_global_integer_1d_array(adios_group, "njmin", &
-      local_dim, group_size_inc)
-  call define_adios_global_integer_1d_array(adios_group, "njmax", &
-      local_dim, group_size_inc)
-  call define_adios_global_integer_1d_array(adios_group, "nkmin_xi", &
-      local_dim, group_size_inc)
-  local_dim = 2*NSPEC2DMAX_YMIN_YMAX
-  call define_adios_global_integer_1d_array(adios_group, "nimin", &
-      local_dim, group_size_inc)
-  call define_adios_global_integer_1d_array(adios_group, "nimax", &
-      local_dim, group_size_inc)
-  call define_adios_global_integer_1d_array(adios_group, "nkmin_eta", &
-      local_dim, group_size_inc)
-
-  !--- Open an ADIOS handler to the restart file. ---------
-  call adios_open (adios_handle, group_name, &
-      outputname, "w", comm, adios_err);
-  call adios_group_size (adios_handle, group_size_inc, &
-                         adios_totalsize, adios_err)
-
-  !--- Schedule writes for the previously defined ADIOS variables
-  local_dim = 2*NSPEC2DMAX_XMIN_XMAX
-  call adios_set_path (adios_handle, "njmin", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", njmin, adios_err)
-
-  call adios_set_path (adios_handle, "njmax", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", njmax, adios_err)
-
-  call adios_set_path (adios_handle, "nkmin_xi", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", nkmin_xi, adios_err)
-
-  local_dim = 2*NSPEC2DMAX_YMIN_YMAX
-  call adios_set_path (adios_handle, "nimin", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", nimin, adios_err)
-
-  call adios_set_path (adios_handle, "nimax", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", nimax, adios_err)
-
-  call adios_set_path (adios_handle, "nkmin_eta", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", nkmin_eta, adios_err)
-
-  !--- Reset the path to zero and perform the actual write to disk
-  call adios_set_path (adios_handle, "", adios_err)
-  call adios_close(adios_handle, adios_err)
-
-end subroutine get_absorb_adios
-

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/model_gll.f90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/model_gll.f90	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/model_gll.f90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -39,6 +39,7 @@
 
   use constants
   use meshfem3D_models_par,only: TRANSVERSE_ISOTROPY
+  use meshfem3D_par, only: ADIOS_ENABLED,ADIOS_FOR_MODELS
 
   implicit none
 
@@ -86,7 +87,11 @@
   if( ier /= 0 ) call exit_MPI(myrank,'error allocating rho_new,.. arrays')
 
   ! reads in model files for each process
-  call read_gll_model(myrank,MGLL_V,NSPEC)
+  if( ADIOS_ENABLED .and. ADIOS_FOR_MODELS ) then
+    call read_gll_model_adios(myrank,MGLL_V,NSPEC)
+  else
+    call read_gll_model(myrank,MGLL_V,NSPEC)
+  endif
 
   ! checks velocity range
   if( .not. TRANSVERSE_ISOTROPY ) then

Added: seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/model_gll_adios.F90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/model_gll_adios.F90	                        (rev 0)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/model_gll_adios.F90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -0,0 +1,130 @@
+!=====================================================================
+!
+!          S p e c f e m 3 D  G l o b e  V e r s i o n  6 . 0
+!          --------------------------------------------------
+!
+!          Main authors: Dimitri Komatitsch and Jeroen Tromp
+!                        Princeton University, USA
+!             and CNRS / INRIA / University of Pau, France
+! (c) Princeton University and CNRS / INRIA / University of Pau
+!                            August 2013
+!
+! This 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.
+!
+!=====================================================================
+
+!--------------------------------------------------------------------------------------------------
+! GLL
+!
+! based on modified GLL mesh output from mesher
+!
+! used for iterative inversion procedures
+!--------------------------------------------------------------------------------------------------
+
+subroutine read_gll_model_adios(myrank,MGLL_V,NSPEC)
+
+  use constants
+  use adios_read_mod
+  use meshfem3D_models_par,only: TRANSVERSE_ISOTROPY
+
+  implicit none
+
+  ! GLL model_variables
+  type model_gll_variables
+    sequence
+    ! tomographic iteration model on GLL points
+    double precision :: scale_velocity,scale_density
+    ! isotropic model
+    real(kind=CUSTOM_REAL),dimension(:,:,:,:),pointer :: vs_new,vp_new,rho_new
+    ! transverse isotropic model
+    real(kind=CUSTOM_REAL),dimension(:,:,:,:),pointer :: vsv_new,vpv_new, &
+      vsh_new,vph_new,eta_new
+    logical :: MODEL_GLL
+    logical,dimension(3) :: dummy_pad ! padding 3 bytes to align the structure
+  end type model_gll_variables
+  type (model_gll_variables) MGLL_V
+
+  integer, dimension(MAX_NUM_REGIONS) :: NSPEC
+  integer :: myrank
+
+  ! local parameters
+  integer :: local_dim, ier
+  character(len=256) :: file_name
+  integer :: comm
+
+  ! ADIOS variables
+  integer                 :: adios_err
+  integer(kind=8)         :: adios_handle ! adios_group
+  integer(kind=8), dimension(1) :: start, count
+
+  integer(kind=8) :: sel
+
+  if( myrank == 0) then
+    write(IMAIN,*)
+    write(IMAIN,*)'reading in model from ',trim(PATHNAME_GLL_modeldir)
+  endif
+
+  ! only crust and mantle
+  write(file_name,'(a,i6.6,a)')                                  &
+        PATHNAME_GLL_modeldir(1:len_trim(PATHNAME_GLL_modeldir)) &
+        // 'model_gll.bp'
+
+  call world_get_comm(comm)
+
+  ! Setup the ADIOS library to read the file
+  call adios_read_init_method (ADIOS_READ_METHOD_BP, comm, &
+      "verbose=1", adios_err)
+  call adios_read_open_file (adios_handle, file_name, 0, comm, ier)
+
+  local_dim = NGLLX * NGLLY * NGLLZ * nspec(IREGION_CRUST_MANTLE)
+  start(1) = local_dim*myrank; count(1) = local_dim
+  call adios_selection_boundingbox (sel , 1, start, count)
+
+  ! reads in model for each partition
+  if( .not. TRANSVERSE_ISOTROPY ) then
+    ! isotropic model
+    ! vp mesh
+    call adios_schedule_read(adios_handle, sel, "reg1/vp/array", 0, 1, &
+        MGLL_V%vp_new(:,:,:,1:nspec(IREGION_CRUST_MANTLE)), adios_err)
+    call adios_schedule_read(adios_handle, sel, "reg1/vs/array", 0, 1, &
+        MGLL_V%vs_new(:,:,:,1:nspec(IREGION_CRUST_MANTLE)), adios_err)
+  else
+    ! transverse isotropic model
+    ! WARNING previously wronly name 'vps' in the adios files
+    ! vp mesh
+    call adios_schedule_read(adios_handle, sel, "reg1/vpv/array", 0, 1, &
+        MGLL_V%vpv_new(:,:,:,1:nspec(IREGION_CRUST_MANTLE)), adios_err)
+    call adios_schedule_read(adios_handle, sel, "reg1/vph/array", 0, 1, &
+        MGLL_V%vph_new(:,:,:,1:nspec(IREGION_CRUST_MANTLE)), adios_err)
+
+    ! vs mesh
+    call adios_schedule_read(adios_handle, sel, "reg1/vsv/array", 0, 1, &
+        MGLL_V%vsv_new(:,:,:,1:nspec(IREGION_CRUST_MANTLE)), adios_err)
+    call adios_schedule_read(adios_handle, sel, "reg1/vsh/array", 0, 1, &
+        MGLL_V%vsh_new(:,:,:,1:nspec(IREGION_CRUST_MANTLE)), adios_err)
+
+    ! eta mesh
+    call adios_schedule_read(adios_handle, sel, "reg1/eta/array", 0, 1, &
+        MGLL_V%eta_new(:,:,:,1:nspec(IREGION_CRUST_MANTLE)), adios_err)
+  endif
+
+  ! rho mesh
+  call adios_schedule_read(adios_handle, sel, "reg1/rho/array", 0, 1, &
+      MGLL_V%rho_new(:,:,:,1:nspec(IREGION_CRUST_MANTLE)), adios_err)
+
+  call adios_perform_reads(adios_handle, adios_err)
+  call adios_read_close(adios_handle, adios_err)
+
+end subroutine read_gll_model_adios

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/model_s362ani.f90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/model_s362ani.f90	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/model_s362ani.f90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -136,7 +136,7 @@
   call bcast_all_ch(kerstr,80)
   call bcast_all_ch(refmdl,80)
 
-  call bcast_all_ch(varstr,maxker,40)
+  call bcast_all_ch_array(varstr,maxker,40)
 
   end subroutine model_s362ani_broadcast
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/rules.mk
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/rules.mk	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/rules.mk	2013-10-07 15:14:08 UTC (rev 22929)
@@ -167,10 +167,19 @@
 ### ADIOS
 ###
 
-adios_OBJECTS = \
-	$O/adios_helpers.shared.o \
-	$O/adios_manager.shared.o \
-	$O/save_arrays_solver_adios.check.o \
+adios_meshfem3D_OBJECTS = \
+	$O/adios_helpers_definitions.shared_adios_module.o \
+	$O/adios_helpers_writers.shared_adios_module.o \
+	$O/adios_helpers.shared_adios.o \
+	$O/adios_manager.shared_adios.o \
+	$O/write_AVS_DX_global_chunks_data_adios.check_adios_module.o \
+	$O/write_AVS_DX_global_data_adios.check_adios_module.o \
+	$O/write_AVS_DX_global_faces_data_adios.check_adios_module.o \
+	$O/write_AVS_DX_surface_data_adios.check_adios_module.o \
+	$O/create_regions_mesh_adios.check_adios.o \
+	$O/get_absorb_adios.check_adios.o \
+	$O/model_gll_adios.check_adios.o \
+	$O/save_arrays_solver_adios.check_adios.o \
 	$(EMPTY_MACRO)
 
 adios_STUBS = \
@@ -179,7 +188,7 @@
 
 # conditional adios linking
 ifeq ($(ADIOS),yes)
-XMESHFEM_OBJECTS += $(adios_OBJECTS)
+XMESHFEM_OBJECTS += $(adios_meshfem3D_OBJECTS)
 else
 XMESHFEM_OBJECTS += $(adios_STUBS)
 endif
@@ -219,3 +228,17 @@
 $O/%.checkmpi.o: $S/%.F90 ${SETUP}/constants.h $O/shared_par.shared_module.o $O/meshfem3D_par.check_module.o
 	${MPIFCCOMPILE_CHECK} ${FCFLAGS_f90} -c -o $@ $<
 
+## adios
+
+$O/%.check_adios_module.o: $S/%.f90 ${SETUP}/constants.h $O/shared_par.shared_module.o $O/meshfem3D_par.check_module.o $O/adios_helpers.shared_adios.o
+	${FCCOMPILE_CHECK} ${FCFLAGS_f90} -c -o $@ $<
+
+$O/%.check_adios_module.o: $S/%.F90 ${SETUP}/constants.h $O/shared_par.shared_module.o $O/meshfem3D_par.check_module.o $O/adios_helpers.shared_adios.o
+	${FCCOMPILE_CHECK} ${FCFLAGS_f90} -c -o $@ $<
+
+$O/%.check_adios.o: $S/%.f90 ${SETUP}/constants.h $O/shared_par.shared_module.o $O/meshfem3D_par.check_module.o $O/adios_helpers.shared_adios.o $O/write_AVS_DX_global_data_adios.check_adios_module.o
+	${FCCOMPILE_CHECK} ${FCFLAGS_f90} -c -o $@ $<
+
+$O/%.check_adios.o: $S/%.F90 ${SETUP}/constants.h $O/shared_par.shared_module.o $O/meshfem3D_par.check_module.o $O/adios_helpers.shared_adios.o $O/write_AVS_DX_global_data_adios.check_adios_module.o
+	${FCCOMPILE_CHECK} ${FCFLAGS_f90} -c -o $@ $<
+

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/save_arrays_solver.f90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/save_arrays_solver.f90	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/save_arrays_solver.f90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -491,66 +491,66 @@
     ! crust mantle
     if( ADIOS_ENABLED .and. ADIOS_FOR_MPI_ARRAYS ) then
       call save_MPI_arrays_adios(myrank,IREGION_CRUST_MANTLE,LOCAL_PATH, &
-          num_interfaces_crust_mantle,max_nibool_interfaces_cm, &
-          my_neighbours_crust_mantle,nibool_interfaces_crust_mantle, &
-          ibool_interfaces_crust_mantle, &
-          nspec_inner_crust_mantle,nspec_outer_crust_mantle, &
-          num_phase_ispec_crust_mantle,phase_ispec_inner_crust_mantle, &
-          num_colors_outer_crust_mantle,num_colors_inner_crust_mantle, &
-          num_elem_colors_crust_mantle)
+                                  num_interfaces_crust_mantle,max_nibool_interfaces_cm, &
+                                  my_neighbours_crust_mantle,nibool_interfaces_crust_mantle, &
+                                  ibool_interfaces_crust_mantle, &
+                                  nspec_inner_crust_mantle,nspec_outer_crust_mantle, &
+                                  num_phase_ispec_crust_mantle,phase_ispec_inner_crust_mantle, &
+                                  num_colors_outer_crust_mantle,num_colors_inner_crust_mantle, &
+                                  num_elem_colors_crust_mantle)
     else
       call save_MPI_arrays(myrank,IREGION_CRUST_MANTLE,LOCAL_PATH, &
-          num_interfaces_crust_mantle,max_nibool_interfaces_cm, &
-          my_neighbours_crust_mantle,nibool_interfaces_crust_mantle, &
-          ibool_interfaces_crust_mantle, &
-          nspec_inner_crust_mantle,nspec_outer_crust_mantle, &
-          num_phase_ispec_crust_mantle,phase_ispec_inner_crust_mantle, &
-          num_colors_outer_crust_mantle,num_colors_inner_crust_mantle, &
-          num_elem_colors_crust_mantle)
+                            num_interfaces_crust_mantle,max_nibool_interfaces_cm, &
+                            my_neighbours_crust_mantle,nibool_interfaces_crust_mantle, &
+                            ibool_interfaces_crust_mantle, &
+                            nspec_inner_crust_mantle,nspec_outer_crust_mantle, &
+                            num_phase_ispec_crust_mantle,phase_ispec_inner_crust_mantle, &
+                            num_colors_outer_crust_mantle,num_colors_inner_crust_mantle, &
+                            num_elem_colors_crust_mantle)
     endif
 
   case( IREGION_OUTER_CORE )
     ! outer core
     if( ADIOS_ENABLED .and. ADIOS_FOR_MPI_ARRAYS ) then
       call save_MPI_arrays_adios(myrank,IREGION_OUTER_CORE,LOCAL_PATH, &
-          num_interfaces_outer_core,max_nibool_interfaces_oc, &
-          my_neighbours_outer_core,nibool_interfaces_outer_core, &
-          ibool_interfaces_outer_core, &
-          nspec_inner_outer_core,nspec_outer_outer_core, &
-          num_phase_ispec_outer_core,phase_ispec_inner_outer_core, &
-          num_colors_outer_outer_core,num_colors_inner_outer_core, &
-          num_elem_colors_outer_core)
+                                  num_interfaces_outer_core,max_nibool_interfaces_oc, &
+                                  my_neighbours_outer_core,nibool_interfaces_outer_core, &
+                                  ibool_interfaces_outer_core, &
+                                  nspec_inner_outer_core,nspec_outer_outer_core, &
+                                  num_phase_ispec_outer_core,phase_ispec_inner_outer_core, &
+                                  num_colors_outer_outer_core,num_colors_inner_outer_core, &
+                                  num_elem_colors_outer_core)
     else
       call save_MPI_arrays(myrank,IREGION_OUTER_CORE,LOCAL_PATH, &
-          num_interfaces_outer_core,max_nibool_interfaces_oc, &
-          my_neighbours_outer_core,nibool_interfaces_outer_core, &
-          ibool_interfaces_outer_core, &
-          nspec_inner_outer_core,nspec_outer_outer_core, &
-          num_phase_ispec_outer_core,phase_ispec_inner_outer_core, &
-          num_colors_outer_outer_core,num_colors_inner_outer_core, &
-          num_elem_colors_outer_core)
+                            num_interfaces_outer_core,max_nibool_interfaces_oc, &
+                            my_neighbours_outer_core,nibool_interfaces_outer_core, &
+                            ibool_interfaces_outer_core, &
+                            nspec_inner_outer_core,nspec_outer_outer_core, &
+                            num_phase_ispec_outer_core,phase_ispec_inner_outer_core, &
+                            num_colors_outer_outer_core,num_colors_inner_outer_core, &
+                            num_elem_colors_outer_core)
     endif
 
   case( IREGION_INNER_CORE )
     ! inner core
     if( ADIOS_ENABLED .and. ADIOS_FOR_MPI_ARRAYS ) then
       call save_MPI_arrays_adios(myrank,IREGION_INNER_CORE,LOCAL_PATH, &
-          num_interfaces_inner_core,max_nibool_interfaces_ic, &
-          my_neighbours_inner_core,nibool_interfaces_inner_core, &
-          ibool_interfaces_inner_core, &
-          nspec_inner_inner_core,nspec_outer_inner_core, &
-          num_phase_ispec_inner_core,phase_ispec_inner_inner_core, &
-          num_colors_outer_inner_core,num_colors_inner_inner_core, &
-          num_elem_colors_inner_core)
+                                  num_interfaces_inner_core,max_nibool_interfaces_ic, &
+                                  my_neighbours_inner_core,nibool_interfaces_inner_core, &
+                                  ibool_interfaces_inner_core, &
+                                  nspec_inner_inner_core,nspec_outer_inner_core, &
+                                  num_phase_ispec_inner_core,phase_ispec_inner_inner_core, &
+                                  num_colors_outer_inner_core,num_colors_inner_inner_core, &
+                                  num_elem_colors_inner_core)
     else
       call save_MPI_arrays(myrank,IREGION_INNER_CORE,LOCAL_PATH, &
-          num_interfaces_inner_core,max_nibool_interfaces_ic, &
-          my_neighbours_inner_core,nibool_interfaces_inner_core, &
-          ibool_interfaces_inner_core, &
-          nspec_inner_inner_core,nspec_outer_inner_core, &
-          num_phase_ispec_inner_core,phase_ispec_inner_inner_core, &
-          num_colors_outer_inner_core,num_colors_inner_inner_core, &
-          num_elem_colors_inner_core)
+                            num_interfaces_inner_core,max_nibool_interfaces_ic, &
+                            my_neighbours_inner_core,nibool_interfaces_inner_core, &
+                            ibool_interfaces_inner_core, &
+                            nspec_inner_inner_core,nspec_outer_inner_core, &
+                            num_phase_ispec_inner_core,phase_ispec_inner_inner_core, &
+                            num_colors_outer_inner_core,num_colors_inner_inner_core, &
+                            num_elem_colors_inner_core)
     endif
   end select
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/save_arrays_solver_adios.F90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/save_arrays_solver_adios.F90	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/save_arrays_solver_adios.F90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -25,11 +25,7 @@
 !
 !=====================================================================
 
-!-------------------------------------------------------------------------------
-!> \file get_absorb_adios.f90
-!! \brief Function to write stacey boundary condition to disk with ADIOS.
-!! \author MPBL
-!-------------------------------------------------------------------------------
+#include "config.fh"
 
 !===============================================================================
 !> \brief Main routine to save the arrays from the mesher to the solver with the
@@ -53,11 +49,11 @@
 !! \param NSPEC2D_BOTTOM Integer to compute the size of the arrays
 !!                       in argument
 subroutine save_arrays_solver_adios(myrank,nspec,nglob,idoubling,ibool, &
-                    iregion_code,xstore,ystore,zstore, &
-                    NSPEC2DMAX_XMIN_XMAX, NSPEC2DMAX_YMIN_YMAX, &
-                    NSPEC2D_TOP,NSPEC2D_BOTTOM)
+                                    iregion_code,xstore,ystore,zstore, &
+                                    NSPEC2DMAX_XMIN_XMAX, NSPEC2DMAX_YMIN_YMAX, &
+                                    NSPEC2D_TOP,NSPEC2D_BOTTOM)
 
-  use mpi
+  use adios_helpers_mod
   use adios_write_mod
 
   use constants
@@ -68,7 +64,7 @@
 
   use meshfem3D_par,only: &
     NCHUNKS,ABSORBING_CONDITIONS,SAVE_MESH_FILES, LOCAL_PATH, &
-    ADIOS_ENABLED,ADIOS_FOR_SOLVER_MESHFILES, &
+    ADIOS_FOR_SOLVER_MESHFILES, &
     ROTATION,EXACT_MASS_MATRIX_FOR_ROTATION
 
   use create_regions_mesh_par2,only: &
@@ -87,7 +83,7 @@
     rho_vp,rho_vs, &
     nspec2D_xmin,nspec2D_xmax,nspec2D_ymin,nspec2D_ymax, &
     ispec_is_tiso,tau_s,T_c_source,tau_e_store,Qmu_store, &
-    prname, nspec_actually, nspec_ani, nspec_stacey, nglob_xy, nglob_oceans
+    nspec_actually, nspec_ani, nspec_stacey, nglob_xy, nglob_oceans ! prname,
 
   implicit none
 
@@ -104,184 +100,265 @@
   double precision,dimension(NGLLX,NGLLY,NGLLZ,nspec) :: xstore,ystore,zstore
 
   ! boundary parameters locator
-  integer :: NSPEC2D_TOP,NSPEC2D_BOTTOM, &
+  integer,intent(in) :: NSPEC2D_TOP,NSPEC2D_BOTTOM, &
       NSPEC2DMAX_XMIN_XMAX, NSPEC2DMAX_YMIN_YMAX
 
   ! local parameters
+  integer :: NSPEC2D_TOP_wmax,NSPEC2D_BOTTOM_wmax, &
+      NSPEC2DMAX_XMIN_XMAX_wmax, NSPEC2DMAX_YMIN_YMAX_wmax
+  integer, parameter :: num_ints_to_reduce = 4
+  integer, dimension(num_ints_to_reduce) :: ints_to_reduce
+
   integer :: i,j,k,ispec,iglob,ier
   real(kind=CUSTOM_REAL),dimension(:),allocatable :: tmp_array_x, &
       tmp_array_y, tmp_array_z
 
   ! local parameters
   character(len=150) :: reg_name, outputname, group_name
-  integer :: ierr, sizeprocs, comm, local_dim
+  integer :: comm, local_dim
   integer(kind=8) :: group_size_inc
   ! ADIOS variables
   integer                 :: adios_err
-  integer(kind=8)         :: adios_group, adios_handle, varid
-  integer(kind=8)         :: adios_groupsize, adios_totalsize
+  integer(kind=8)         :: adios_group, handle
+  integer(kind=8)         :: adios_totalsize
+  character(len=128)      :: region_name, region_name_scalar
 
+  !--- Save the number of region written. Open the file in "w" mode if 0, else
+  !    in "a"  mode
+  integer, save :: num_regions_written = 0
+
+  integer :: sizeprocs
+
+  ! number of mpi processes
+  call world_size(sizeprocs)
+
   ! create a prefix for the file name such as LOCAL_PATH/regX_
   call create_name_database_adios(reg_name,iregion_code,LOCAL_PATH)
+  write(region_name,"('reg',i1, '/')") iregion_code
+  write(region_name_scalar,"('reg',i1)") iregion_code
 
   !---------------------------------------------------------
   !--- Solver data arrays ----------------------------------
   !---------------------------------------------------------
 
-  ! create the name for the database of the current slide and region
-  outputname = trim(reg_name) // "solver_data.bp"
-
   ! save arrays for the solver to run.
   write(group_name,"('SPECFEM3D_GLOBE_ARRAYS_SOLVER_reg',i1)") iregion_code
-  call world_size(sizeprocs) ! TODO keep it in parameters
+
   ! Alias COMM_WORLD to use ADIOS
-  call MPI_Comm_dup (MPI_COMM_WORLD, comm, ierr)
+  call world_duplicate(comm)
+
   ! set the adios group size to 0 before incremented by calls to
   ! helpers functions.
   group_size_inc = 0
   call adios_declare_group(adios_group, group_name, &
-      "", 0, adios_err)
+      "", 1, adios_err)
   ! We set the transport method to 'MPI'. This seems to be the correct choice
   ! for now. We might want to move this to the constant.h file later on.
   call adios_select_method(adios_group, "MPI", "", "", adios_err)
 
   !--- Define ADIOS variables -----------------------------
   ! save nspec and nglob, to be used in combine_paraview_data
-  call define_adios_integer_scalar (adios_group, "nspec", "", &
-      group_size_inc)
-  call define_adios_integer_scalar (adios_group, "nglob", "", &
-      group_size_inc)
+  call define_adios_scalar (adios_group, group_size_inc, &
+                            region_name_scalar, STRINGIFY_VAR(nspec))
+  call define_adios_scalar (adios_group, group_size_inc, &
+                            region_name_scalar, STRINGIFY_VAR(nglob))
 
   local_dim = nglob
-  call define_adios_global_real_1d_array(adios_group, "xstore", &
-      local_dim, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, "ystore", &
-      local_dim, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, "zstore", &
-      local_dim, group_size_inc)
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   "x_global", tmp_array_x)
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   "y_global", tmp_array_y)
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   "z_global", tmp_array_z)
 
   local_dim = NGLLX * NGLLY * NGLLZ * nspec
-  call define_adios_global_real_1d_array(adios_group, "rhostore", &
-      local_dim, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, "kappavstore", &
-      local_dim, group_size_inc)
-  call define_adios_global_integer_1d_array(adios_group, "ibool", &
-      local_dim, group_size_inc)
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(xstore))
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(ystore))
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(zstore))
+
+  local_dim = NGLLX * NGLLY * NGLLZ * nspec
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(rhostore))
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(kappavstore))
+
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(ibool))
+
   if(iregion_code /= IREGION_OUTER_CORE) then
-    if(.not. (ANISOTROPIC_3D_MANTLE .and. &
-        iregion_code == IREGION_CRUST_MANTLE)) then
-      call define_adios_global_real_1d_array(adios_group, "muvstore", &
-          local_dim, group_size_inc)
+
+    if (.not. (ANISOTROPIC_3D_MANTLE .and. &
+               iregion_code == IREGION_CRUST_MANTLE)) then
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                       local_dim, region_name,      &
+                                       STRINGIFY_VAR(muvstore))
     endif
+
     if(TRANSVERSE_ISOTROPY) then
-      if(iregion_code == IREGION_CRUST_MANTLE .and. &
+      if (iregion_code == IREGION_CRUST_MANTLE .and. &
           .not. ANISOTROPIC_3D_MANTLE) then
-        call define_adios_global_real_1d_array(adios_group, "kappahstore", &
-            local_dim, group_size_inc)
-        call define_adios_global_real_1d_array(adios_group, "muhstore", &
-            local_dim, group_size_inc)
-        call define_adios_global_real_1d_array(adios_group, "eta_anisostore", &
-            local_dim, group_size_inc)
+        call define_adios_global_array1D(adios_group, group_size_inc, &
+                                         local_dim, region_name,      &
+                                         STRINGIFY_VAR(kappahstore))
+        call define_adios_global_array1D(adios_group, group_size_inc, &
+                                        local_dim, region_name,       &
+                                        STRINGIFY_VAR(muhstore))
+        call define_adios_global_array1D(adios_group, group_size_inc, &
+                                         local_dim, region_name,      &
+                                         STRINGIFY_VAR(eta_anisostore))
       endif
     endif
   endif
 
   local_dim = nspec
-  call define_adios_global_integer_1d_array(adios_group, "idoubling", &
-      local_dim, group_size_inc)
-  call define_adios_global_integer_1d_array(adios_group, "ispec_is_tiso", &
-      local_dim, group_size_inc)
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(idoubling))
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(ispec_is_tiso))
+
   local_dim = NGLLX * NGLLY * NGLLZ * nspec_actually
-  call define_adios_global_real_1d_array(adios_group, "xixstore", &
-      local_dim, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, "xiystore", &
-      local_dim, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, "xizstore", &
-      local_dim, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, "etaxstore", &
-      local_dim, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, "etaystore", &
-      local_dim, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, "etazstore", &
-      local_dim, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, "gammaxstore", &
-      local_dim, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, "gammaystore", &
-      local_dim, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, "gammazstore", &
-      local_dim, group_size_inc)
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(xixstore))
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(xiystore))
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(xizstore))
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(etaxstore))
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(etaystore))
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(etazstore))
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(gammaxstore))
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(gammaystore))
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(gammazstore))
 
   local_dim = NGLLX * NGLLY * NGLLZ * nspec_ani
   if(iregion_code /= IREGION_OUTER_CORE) then
     !   save anisotropy in the inner core only
     if(ANISOTROPIC_INNER_CORE .and. iregion_code == IREGION_INNER_CORE) then
-      call define_adios_global_real_1d_array(adios_group, "c11store", &
-          local_dim, group_size_inc)
-      call define_adios_global_real_1d_array(adios_group, "c33store", &
-          local_dim, group_size_inc)
-      call define_adios_global_real_1d_array(adios_group, "c12store", &
-          local_dim, group_size_inc)
-      call define_adios_global_real_1d_array(adios_group, "c13store", &
-          local_dim, group_size_inc)
-      call define_adios_global_real_1d_array(adios_group, "c44store", &
-          local_dim, group_size_inc)
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,          &
+                                   STRINGIFY_VAR(c11store))
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,          &
+                                   STRINGIFY_VAR(c33store))
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,          &
+                                   STRINGIFY_VAR(c12store))
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,          &
+                                   STRINGIFY_VAR(c13store))
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,          &
+                                   STRINGIFY_VAR(c44store))
     endif
     if(ANISOTROPIC_3D_MANTLE .and. iregion_code == IREGION_CRUST_MANTLE) then
-      call define_adios_global_real_1d_array(adios_group, "c11store", &
-          local_dim, group_size_inc)
-      call define_adios_global_real_1d_array(adios_group, "c12store", &
-          local_dim, group_size_inc)
-      call define_adios_global_real_1d_array(adios_group, "c13store", &
-          local_dim, group_size_inc)
-      call define_adios_global_real_1d_array(adios_group, "c14store", &
-          local_dim, group_size_inc)
-      call define_adios_global_real_1d_array(adios_group, "c15store", &
-          local_dim, group_size_inc)
-      call define_adios_global_real_1d_array(adios_group, "c16store", &
-          local_dim, group_size_inc)
-      call define_adios_global_real_1d_array(adios_group, "c22store", &
-          local_dim, group_size_inc)
-      call define_adios_global_real_1d_array(adios_group, "c23store", &
-          local_dim, group_size_inc)
-      call define_adios_global_real_1d_array(adios_group, "c24store", &
-          local_dim, group_size_inc)
-      call define_adios_global_real_1d_array(adios_group, "c25store", &
-          local_dim, group_size_inc)
-      call define_adios_global_real_1d_array(adios_group, "c26store", &
-          local_dim, group_size_inc)
-      call define_adios_global_real_1d_array(adios_group, "c33store", &
-          local_dim, group_size_inc)
-      call define_adios_global_real_1d_array(adios_group, "c34store", &
-          local_dim, group_size_inc)
-      call define_adios_global_real_1d_array(adios_group, "c35store", &
-          local_dim, group_size_inc)
-      call define_adios_global_real_1d_array(adios_group, "c36store", &
-          local_dim, group_size_inc)
-      call define_adios_global_real_1d_array(adios_group, "c44store", &
-          local_dim, group_size_inc)
-      call define_adios_global_real_1d_array(adios_group, "c45store", &
-          local_dim, group_size_inc)
-      call define_adios_global_real_1d_array(adios_group, "c46store", &
-          local_dim, group_size_inc)
-      call define_adios_global_real_1d_array(adios_group, "c55store", &
-          local_dim, group_size_inc)
-      call define_adios_global_real_1d_array(adios_group, "c56store", &
-          local_dim, group_size_inc)
-      call define_adios_global_real_1d_array(adios_group, "c66store", &
-          local_dim, group_size_inc)
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,          &
+                                   STRINGIFY_VAR(c11store))
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,          &
+                                   STRINGIFY_VAR(c12store))
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,          &
+                                   STRINGIFY_VAR(c13store))
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,          &
+                                   STRINGIFY_VAR(c14store))
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,          &
+                                   STRINGIFY_VAR(c15store))
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,          &
+                                   STRINGIFY_VAR(c16store))
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,          &
+                                   STRINGIFY_VAR(c22store))
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,          &
+                                   STRINGIFY_VAR(c23store))
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,          &
+                                   STRINGIFY_VAR(c24store))
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,          &
+                                   STRINGIFY_VAR(c25store))
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,          &
+                                   STRINGIFY_VAR(c26store))
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,          &
+                                   STRINGIFY_VAR(c33store))
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,          &
+                                   STRINGIFY_VAR(c34store))
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,          &
+                                   STRINGIFY_VAR(c35store))
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,          &
+                                   STRINGIFY_VAR(c36store))
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,          &
+                                   STRINGIFY_VAR(c44store))
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,          &
+                                   STRINGIFY_VAR(c45store))
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,          &
+                                   STRINGIFY_VAR(c46store))
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,          &
+                                   STRINGIFY_VAR(c55store))
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,          &
+                                   STRINGIFY_VAR(c56store))
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,          &
+                                   STRINGIFY_VAR(c66store))
     endif
   endif
 
   local_dim = NGLLX * NGLLY * NGLLZ * nspec_stacey
   if(ABSORBING_CONDITIONS) then
     if(iregion_code == IREGION_CRUST_MANTLE) then
-      call define_adios_global_real_1d_array(adios_group, "rho_vp", &
-          local_dim, group_size_inc)
-      call define_adios_global_real_1d_array(adios_group, "rho_vs", &
-          local_dim, group_size_inc)
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                       local_dim, region_name,      &
+                                       STRINGIFY_VAR(rho_vp))
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                       local_dim, region_name,      &
+                                       STRINGIFY_VAR(rho_vs))
     else if(iregion_code == IREGION_OUTER_CORE) then
-      call define_adios_global_real_1d_array(adios_group, "rho_vp", &
-          local_dim, group_size_inc)
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                       local_dim, region_name,      &
+                                       STRINGIFY_VAR(rho_vp))
     endif
   endif
 
@@ -289,37 +366,48 @@
   if((NCHUNKS /= 6 .and. ABSORBING_CONDITIONS .and. iregion_code == IREGION_CRUST_MANTLE) .or. &
      (ROTATION .and. EXACT_MASS_MATRIX_FOR_ROTATION .and. iregion_code == IREGION_CRUST_MANTLE) .or. &
      (ROTATION .and. EXACT_MASS_MATRIX_FOR_ROTATION .and. iregion_code == IREGION_INNER_CORE)) then
-    call define_adios_global_real_1d_array(adios_group, "rmassx", &
-        local_dim, group_size_inc)
-    call define_adios_global_real_1d_array(adios_group, "rmassy", &
-        local_dim, group_size_inc)
+    call define_adios_global_array1D(adios_group, group_size_inc, &
+                                     local_dim, region_name,      &
+                                     STRINGIFY_VAR(rmassx))
+    call define_adios_global_array1D(adios_group, group_size_inc, &
+                                     local_dim, region_name,      &
+                                     STRINGIFY_VAR(rmassy))
   endif
   local_dim = nglob
-  call define_adios_global_real_1d_array(adios_group, "rmassz", &
-      local_dim, group_size_inc)
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(rmassz))
 
-  ! mass matrices for backward simulation when ROTATION is .true.
+ ! mass matrices for backward simulation when ROTATION is .true.
   local_dim = nglob_xy
   if(EXACT_MASS_MATRIX_FOR_ROTATION)then
     if((ROTATION .and. iregion_code == IREGION_CRUST_MANTLE) .or. &
        (ROTATION .and. iregion_code == IREGION_INNER_CORE))then
-      call define_adios_global_real_1d_array(adios_group, "b_rmassx", &
-          local_dim, group_size_inc)
-      call define_adios_global_real_1d_array(adios_group, "b_rmassy", &
-          local_dim, group_size_inc)
+      call define_adios_global_real_1d_array(adios_group,group_size_inc, &
+                                             local_dim,region_name, &
+                                             STRINGIFY_VAR(b_rmassx) )
+      call define_adios_global_real_1d_array(adios_group,group_size_inc, &
+                                             local_dim,region_name, &
+                                             STRINGIFY_VAR(b_rmassy) )
     endif
   endif
 
   local_dim = nglob_oceans
   if(OCEANS .and. iregion_code == IREGION_CRUST_MANTLE) then
-    call define_adios_global_real_1d_array(adios_group, "rmass_ocean_load", &
-        local_dim, group_size_inc)
+    call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,        &
+                                   STRINGIFY_VAR(rmass_ocean_load))
   endif
 
+
   !--- Open an ADIOS handler to the restart file. ---------
-  call adios_open (adios_handle, group_name, &
-      outputname, "w", comm, adios_err);
-  call adios_group_size (adios_handle, group_size_inc, &
+  outputname = trim(LOCAL_PATH) // "/solver_data.bp"
+  if (num_regions_written == 0) then
+    call adios_open (handle, group_name, outputname, "w", comm, adios_err)
+  else
+    call adios_open (handle, group_name, outputname, "a", comm, adios_err);
+  endif
+  call adios_group_size (handle, group_size_inc, &
                          adios_totalsize, adios_err)
 
   ! mesh topology
@@ -391,282 +479,153 @@
 
   !--- Schedule writes for the previously defined ADIOS variables
   ! save nspec and nglob, to be used in combine_paraview_data
-  call adios_write(adios_handle, "nspec", nspec, adios_err)
-  call adios_write(adios_handle, "nglob", nglob, adios_err)
+  call adios_write(handle, trim(region_name) // "nspec", nspec, adios_err)
+  call check_adios_err(myrank,adios_err)
+  call adios_write(handle, trim(region_name) // "nglob", nglob, adios_err)
+  call check_adios_err(myrank,adios_err)
 
   local_dim = nglob
-  call adios_set_path (adios_handle, "xstore", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", tmp_array_x, adios_err)
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   trim(region_name) //"x_global", tmp_array_x)
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   trim(region_name) //"y_global", tmp_array_y)
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   trim(region_name) //"z_global", tmp_array_z)
+  local_dim = NGLLX * NGLLY * NGLLZ * nspec
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   trim(region_name) // STRINGIFY_VAR(xstore))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   trim(region_name) // STRINGIFY_VAR(ystore))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   trim(region_name) // STRINGIFY_VAR(zstore))
 
-  call adios_set_path (adios_handle, "ystore", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", tmp_array_y, adios_err)
-
-  call adios_set_path (adios_handle, "zstore", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", tmp_array_z, adios_err)
-
   local_dim = NGLLX * NGLLY * NGLLZ * nspec
-  call adios_set_path (adios_handle, "rhostore", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", rhostore, adios_err)
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   trim(region_name) // STRINGIFY_VAR(rhostore))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                trim(region_name) // STRINGIFY_VAR(kappavstore))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   trim(region_name) // STRINGIFY_VAR(ibool))
 
-  call adios_set_path (adios_handle, "kappavstore", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", kappavstore, adios_err)
-
-  call adios_set_path (adios_handle, "ibool", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", ibool, adios_err)
-
   if(iregion_code /= IREGION_OUTER_CORE) then
-    if(.not. (ANISOTROPIC_3D_MANTLE .and. &
-        iregion_code == IREGION_CRUST_MANTLE)) then
-      call adios_set_path (adios_handle, "muvstore", adios_err)
-      call write_1D_global_array_adios_dims(adios_handle, myrank, &
-          local_dim, sizeprocs)
-      call adios_write(adios_handle, "array", muvstore, adios_err)
+    if (.not. (ANISOTROPIC_3D_MANTLE .and. &
+               iregion_code == IREGION_CRUST_MANTLE)) then
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   trim(region_name) // STRINGIFY_VAR(muvstore))
     endif
     if(TRANSVERSE_ISOTROPY) then
       if(iregion_code == IREGION_CRUST_MANTLE .and. &
           .not. ANISOTROPIC_3D_MANTLE) then
-        call adios_set_path (adios_handle, "kappahstore", adios_err)
-        call write_1D_global_array_adios_dims(adios_handle, myrank, &
-            local_dim, sizeprocs)
-        call adios_write(adios_handle, "array", kappahstore, adios_err)
-
-        call adios_set_path (adios_handle, "muhstore", adios_err)
-        call write_1D_global_array_adios_dims(adios_handle, myrank, &
-            local_dim, sizeprocs)
-        call adios_write(adios_handle, "array", muhstore, adios_err)
-
-        call adios_set_path (adios_handle, "eta_anisostore", adios_err)
-        call write_1D_global_array_adios_dims(adios_handle, myrank, &
-            local_dim, sizeprocs)
-        call adios_write(adios_handle, "array", eta_anisostore, adios_err)
+        call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                trim(region_name) // STRINGIFY_VAR(kappahstore))
+        call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   trim(region_name) // STRINGIFY_VAR(muhstore))
+        call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                             trim(region_name) // STRINGIFY_VAR(eta_anisostore))
       endif
     endif
   endif
 
   local_dim = nspec
-  call adios_set_path (adios_handle, "idoubling", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", idoubling, adios_err)
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                  trim(region_name) // STRINGIFY_VAR(idoubling))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                              trim(region_name) // STRINGIFY_VAR(ispec_is_tiso))
 
-  call adios_set_path (adios_handle, "ispec_is_tiso", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", ispec_is_tiso, adios_err)
-
   local_dim = NGLLX * NGLLY * NGLLZ * nspec_actually
-  call adios_set_path (adios_handle, "xixstore", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", xixstore, adios_err)
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   trim(region_name) // STRINGIFY_VAR(xixstore))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   trim(region_name) // STRINGIFY_VAR(xiystore))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   trim(region_name) // STRINGIFY_VAR(xizstore))
 
-  call adios_set_path (adios_handle, "xiystore", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", xiystore, adios_err)
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                  trim(region_name) // STRINGIFY_VAR(etaxstore))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                  trim(region_name) // STRINGIFY_VAR(etaystore))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                  trim(region_name) // STRINGIFY_VAR(etazstore))
 
-  call adios_set_path (adios_handle, "xizstore", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", xizstore, adios_err)
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                trim(region_name) // STRINGIFY_VAR(gammaxstore))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                trim(region_name) // STRINGIFY_VAR(gammaystore))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                trim(region_name) // STRINGIFY_VAR(gammazstore))
 
-  call adios_set_path (adios_handle, "etaxstore", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", etaxstore, adios_err)
-
-  call adios_set_path (adios_handle, "etaystore", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", etaystore, adios_err)
-
-  call adios_set_path (adios_handle, "etazstore", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", etazstore, adios_err)
-
-  call adios_set_path (adios_handle, "gammaxstore", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", gammaxstore, adios_err)
-
-  call adios_set_path (adios_handle, "gammaystore", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", gammaystore, adios_err)
-
-  call adios_set_path (adios_handle, "gammazstore", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", gammazstore, adios_err)
-
   local_dim = NGLLX * NGLLY * NGLLZ * nspec_ani
   if(iregion_code /= IREGION_OUTER_CORE) then
+
     !   save anisotropy in the inner core only
     if(ANISOTROPIC_INNER_CORE .and. iregion_code == IREGION_INNER_CORE) then
-      call adios_set_path (adios_handle, "c11store", adios_err)
-      call write_1D_global_array_adios_dims(adios_handle, myrank, &
-          local_dim, sizeprocs)
-      call adios_write(adios_handle, "array", c11store, adios_err)
-
-      call adios_set_path (adios_handle, "c33store", adios_err)
-      call write_1D_global_array_adios_dims(adios_handle, myrank, &
-          local_dim, sizeprocs)
-      call adios_write(adios_handle, "array", c33store, adios_err)
-
-      call adios_set_path (adios_handle, "c12store", adios_err)
-      call write_1D_global_array_adios_dims(adios_handle, myrank, &
-          local_dim, sizeprocs)
-      call adios_write(adios_handle, "array", c12store, adios_err)
-
-      call adios_set_path (adios_handle, "c13store", adios_err)
-      call write_1D_global_array_adios_dims(adios_handle, myrank, &
-          local_dim, sizeprocs)
-      call adios_write(adios_handle, "array", c13store, adios_err)
-
-      call adios_set_path (adios_handle, "c44store", adios_err)
-      call write_1D_global_array_adios_dims(adios_handle, myrank, &
-          local_dim, sizeprocs)
-      call adios_write(adios_handle, "array", c44store, adios_err)
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   trim(region_name) // STRINGIFY_VAR(c11store))
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   trim(region_name) // STRINGIFY_VAR(c33store))
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   trim(region_name) // STRINGIFY_VAR(c12store))
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   trim(region_name) // STRINGIFY_VAR(c13store))
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   trim(region_name) // STRINGIFY_VAR(c44store))
     endif
-    if(ANISOTROPIC_3D_MANTLE .and. iregion_code == IREGION_CRUST_MANTLE) then
-      call adios_set_path (adios_handle, "c11store", adios_err)
-      call write_1D_global_array_adios_dims(adios_handle, myrank, &
-          local_dim, sizeprocs)
-      call adios_write(adios_handle, "array", c11store, adios_err)
 
-      call adios_set_path (adios_handle, "c12store", adios_err)
-      call write_1D_global_array_adios_dims(adios_handle, myrank, &
-          local_dim, sizeprocs)
-      call adios_write(adios_handle, "array", c12store, adios_err)
-
-      call adios_set_path (adios_handle, "c13store", adios_err)
-      call write_1D_global_array_adios_dims(adios_handle, myrank, &
-          local_dim, sizeprocs)
-      call adios_write(adios_handle, "array", c13store, adios_err)
-
-      call adios_set_path (adios_handle, "c14store", adios_err)
-      call write_1D_global_array_adios_dims(adios_handle, myrank, &
-          local_dim, sizeprocs)
-      call adios_write(adios_handle, "array", c14store, adios_err)
-
-      call adios_set_path (adios_handle, "c15store", adios_err)
-      call write_1D_global_array_adios_dims(adios_handle, myrank, &
-          local_dim, sizeprocs)
-      call adios_write(adios_handle, "array", c15store, adios_err)
-
-      call adios_set_path (adios_handle, "c16store", adios_err)
-      call write_1D_global_array_adios_dims(adios_handle, myrank, &
-          local_dim, sizeprocs)
-      call adios_write(adios_handle, "array", c16store, adios_err)
-
-      call adios_set_path (adios_handle, "c22store", adios_err)
-      call write_1D_global_array_adios_dims(adios_handle, myrank, &
-          local_dim, sizeprocs)
-      call adios_write(adios_handle, "array", c22store, adios_err)
-
-      call adios_set_path (adios_handle, "c23store", adios_err)
-      call write_1D_global_array_adios_dims(adios_handle, myrank, &
-          local_dim, sizeprocs)
-      call adios_write(adios_handle, "array", c23store, adios_err)
-
-      call adios_set_path (adios_handle, "c24store", adios_err)
-      call write_1D_global_array_adios_dims(adios_handle, myrank, &
-          local_dim, sizeprocs)
-      call adios_write(adios_handle, "array", c24store, adios_err)
-
-      call adios_set_path (adios_handle, "c25store", adios_err)
-      call write_1D_global_array_adios_dims(adios_handle, myrank, &
-          local_dim, sizeprocs)
-      call adios_write(adios_handle, "array", c25store, adios_err)
-
-      call adios_set_path (adios_handle, "c26store", adios_err)
-      call write_1D_global_array_adios_dims(adios_handle, myrank, &
-          local_dim, sizeprocs)
-      call adios_write(adios_handle, "array", c26store, adios_err)
-
-      call adios_set_path (adios_handle, "c33store", adios_err)
-      call write_1D_global_array_adios_dims(adios_handle, myrank, &
-          local_dim, sizeprocs)
-      call adios_write(adios_handle, "array", c33store, adios_err)
-
-      call adios_set_path (adios_handle, "c34store", adios_err)
-      call write_1D_global_array_adios_dims(adios_handle, myrank, &
-          local_dim, sizeprocs)
-      call adios_write(adios_handle, "array", c34store, adios_err)
-
-      call adios_set_path (adios_handle, "c35store", adios_err)
-      call write_1D_global_array_adios_dims(adios_handle, myrank, &
-          local_dim, sizeprocs)
-      call adios_write(adios_handle, "array", c35store, adios_err)
-
-      call adios_set_path (adios_handle, "c36store", adios_err)
-      call write_1D_global_array_adios_dims(adios_handle, myrank, &
-          local_dim, sizeprocs)
-      call adios_write(adios_handle, "array", c36store, adios_err)
-
-      call adios_set_path (adios_handle, "c44store", adios_err)
-      call write_1D_global_array_adios_dims(adios_handle, myrank, &
-          local_dim, sizeprocs)
-      call adios_write(adios_handle, "array", c44store, adios_err)
-
-      call adios_set_path (adios_handle, "c45store", adios_err)
-      call write_1D_global_array_adios_dims(adios_handle, myrank, &
-          local_dim, sizeprocs)
-      call adios_write(adios_handle, "array", c45store, adios_err)
-
-      call adios_set_path (adios_handle, "c46store", adios_err)
-      call write_1D_global_array_adios_dims(adios_handle, myrank, &
-          local_dim, sizeprocs)
-      call adios_write(adios_handle, "array", c46store, adios_err)
-
-      call adios_set_path (adios_handle, "c55store", adios_err)
-      call write_1D_global_array_adios_dims(adios_handle, myrank, &
-          local_dim, sizeprocs)
-      call adios_write(adios_handle, "array", c55store, adios_err)
-
-      call adios_set_path (adios_handle, "c56store", adios_err)
-      call write_1D_global_array_adios_dims(adios_handle, myrank, &
-          local_dim, sizeprocs)
-      call adios_write(adios_handle, "array", c56store, adios_err)
-
-      call adios_set_path (adios_handle, "c66store", adios_err)
-      call write_1D_global_array_adios_dims(adios_handle, myrank, &
-          local_dim, sizeprocs)
-      call adios_write(adios_handle, "array", c66store, adios_err)
+    if(ANISOTROPIC_3D_MANTLE .and. iregion_code == IREGION_CRUST_MANTLE) then
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   trim(region_name) // STRINGIFY_VAR(c11store))
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   trim(region_name) // STRINGIFY_VAR(c12store))
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   trim(region_name) // STRINGIFY_VAR(c13store))
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   trim(region_name) // STRINGIFY_VAR(c14store))
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   trim(region_name) // STRINGIFY_VAR(c15store))
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   trim(region_name) // STRINGIFY_VAR(c16store))
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   trim(region_name) // STRINGIFY_VAR(c22store))
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   trim(region_name) // STRINGIFY_VAR(c23store))
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   trim(region_name) // STRINGIFY_VAR(c24store))
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   trim(region_name) // STRINGIFY_VAR(c25store))
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   trim(region_name) // STRINGIFY_VAR(c33store))
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   trim(region_name) // STRINGIFY_VAR(c34store))
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   trim(region_name) // STRINGIFY_VAR(c35store))
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   trim(region_name) // STRINGIFY_VAR(c36store))
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   trim(region_name) // STRINGIFY_VAR(c44store))
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   trim(region_name) // STRINGIFY_VAR(c45store))
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   trim(region_name) // STRINGIFY_VAR(c46store))
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   trim(region_name) // STRINGIFY_VAR(c55store))
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   trim(region_name) // STRINGIFY_VAR(c56store))
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   trim(region_name) // STRINGIFY_VAR(c66store))
     endif
   endif
 
   local_dim = NGLLX * NGLLY * NGLLZ * nspec_stacey
   if(ABSORBING_CONDITIONS) then
     if(iregion_code == IREGION_CRUST_MANTLE) then
-      call adios_set_path (adios_handle, "rho_vp", adios_err)
-      call write_1D_global_array_adios_dims(adios_handle, myrank, &
-          local_dim, sizeprocs)
-      call adios_write(adios_handle, "array", rho_vp, adios_err)
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     trim(region_name) // STRINGIFY_VAR(rho_vp))
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     trim(region_name) // STRINGIFY_VAR(rho_vs))
 
-      call adios_set_path (adios_handle, "rho_vs", adios_err)
-      call write_1D_global_array_adios_dims(adios_handle, myrank, &
-          local_dim, sizeprocs)
-      call adios_write(adios_handle, "array", rho_vs, adios_err)
-
     else if(iregion_code == IREGION_OUTER_CORE) then
-      call adios_set_path (adios_handle, "rho_vp", adios_err)
-      call write_1D_global_array_adios_dims(adios_handle, myrank, &
-          local_dim, sizeprocs)
-      call adios_write(adios_handle, "array", rho_vp, adios_err)
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     trim(region_name) // STRINGIFY_VAR(rho_vp))
     endif
   endif
 
@@ -675,54 +634,39 @@
   if((NCHUNKS /= 6 .and. ABSORBING_CONDITIONS .and. iregion_code == IREGION_CRUST_MANTLE) .or. &
      (ROTATION .and. EXACT_MASS_MATRIX_FOR_ROTATION .and. iregion_code == IREGION_CRUST_MANTLE) .or. &
      (ROTATION .and. EXACT_MASS_MATRIX_FOR_ROTATION .and. iregion_code == IREGION_INNER_CORE)) then
-    call adios_set_path (adios_handle, "rmassx", adios_err)
-    call write_1D_global_array_adios_dims(adios_handle, myrank, &
-        local_dim, sizeprocs)
-    call adios_write(adios_handle, "array", rmassx, adios_err)
-
-    call adios_set_path (adios_handle, "rmassy", adios_err)
-    call write_1D_global_array_adios_dims(adios_handle, myrank, &
-        local_dim, sizeprocs)
-    call adios_write(adios_handle, "array", rmassy, adios_err)
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     trim(region_name) // STRINGIFY_VAR(rmassx))
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     trim(region_name) // STRINGIFY_VAR(rmassy))
   endif
 
   local_dim = nglob
-  call adios_set_path (adios_handle, "rmassz", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", rmassz, adios_err)
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   trim(region_name) // STRINGIFY_VAR(rmassz))
 
   ! mass matrices for backward simulation when ROTATION is .true.
   local_dim = nglob_xy
   if(EXACT_MASS_MATRIX_FOR_ROTATION)then
     if((ROTATION .and. iregion_code == IREGION_CRUST_MANTLE) .or. &
        (ROTATION .and. iregion_code == IREGION_INNER_CORE))then
-      call adios_set_path (adios_handle, "b_rmassx", adios_err)
-      call write_1D_global_array_adios_dims(adios_handle, myrank, &
-          local_dim, sizeprocs)
-      call adios_write(adios_handle, "array", b_rmassx, adios_err)
-
-      call adios_set_path (adios_handle, "b_rmassy", adios_err)
-      call write_1D_global_array_adios_dims(adios_handle, myrank, &
-          local_dim, sizeprocs)
-      call adios_write(adios_handle, "array", b_rmassy, adios_err)
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                       trim(region_name) // STRINGIFY_VAR(b_rmassx))
+      call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                       trim(region_name) // STRINGIFY_VAR(b_rmassy))
     endif
   endif
 
   ! additional ocean load mass matrix if oceans and if we are in the crust
   local_dim = nglob_oceans
   if(OCEANS .and. iregion_code == IREGION_CRUST_MANTLE) then
-    call adios_set_path (adios_handle, "rmass_ocean_load", adios_err)
-    call write_1D_global_array_adios_dims(adios_handle, myrank, &
-        local_dim, sizeprocs)
-    call adios_write(adios_handle, "array", rmass_ocean_load, adios_err)
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                           trim(region_name) // STRINGIFY_VAR(rmass_ocean_load))
     if(minval(rmass_ocean_load) <= 0._CUSTOM_REAL) &
         call exit_MPI(myrank,'negative mass matrix term for the oceans')
   endif
 
-  !--- Reset the path to zero and perform the actual write to disk
-  call adios_set_path (adios_handle, "", adios_err)
-  call adios_close(adios_handle, adios_err)
+  !--- perform the actual write to disk
+  call adios_close(handle, adios_err)
 
   ! Clean the temporary arrays containing the node information
   deallocate(tmp_array_x)
@@ -733,232 +677,233 @@
   !--- Boundary arrays -------------------------------------
   !---------------------------------------------------------
 
-  ! Postpend the actual file name.
-  outputname = trim(reg_name) // "boundary.bp"
+  ints_to_reduce(1) = NSPEC2D_TOP
+  ints_to_reduce(2) = NSPEC2D_BOTTOM
+  ints_to_reduce(3) = NSPEC2DMAX_XMIN_XMAX
+  ints_to_reduce(4) = NSPEC2DMAX_YMIN_YMAX
 
+  call max_allreduce_i(ints_to_reduce,num_ints_to_reduce)
+
+  NSPEC2D_TOP_wmax          = ints_to_reduce(1)
+  NSPEC2D_BOTTOM_wmax       = ints_to_reduce(2)
+  NSPEC2DMAX_XMIN_XMAX_wmax = ints_to_reduce(3)
+  NSPEC2DMAX_YMIN_YMAX_wmax = ints_to_reduce(4)
+
+  ! debug daniel
+  !call synchronize_all()
+  !print*,myrank,'nspec2d top      :',NSPEC2D_TOP,NSPEC2D_TOP_wmax
+  !print*,myrank,'nspec2d bottom   :',NSPEC2D_BOTTOM,NSPEC2D_BOTTOM_wmax
+  !print*,myrank,'nspec2d xmin_xmax:',NSPEC2DMAX_XMIN_XMAX,NSPEC2DMAX_XMIN_XMAX_wmax
+  !print*,myrank,'nspec2d ymin_ymax:',NSPEC2DMAX_YMIN_YMAX,NSPEC2DMAX_YMIN_YMAX_wmax
+  !call synchronize_all()
+
+  ! checks
+  if( NSPEC2D_TOP /= NSPEC2D_TOP_wmax .or. &
+      NSPEC2D_BOTTOM /= NSPEC2D_BOTTOM_wmax .or. &
+      NSPEC2DMAX_XMIN_XMAX /= NSPEC2DMAX_XMIN_XMAX_wmax .or. &
+      NSPEC2DMAX_YMIN_YMAX /= NSPEC2DMAX_YMIN_YMAX_wmax ) then
+    print*,myrank,'error nspec2d for coupling surfaces'
+    call exit_mpi(myrank,'error nspec2d for coupling surfaces in adios saved file')
+  endif
+
   ! save boundary arrays in ADIOS files
   write(group_name,"('SPECFEM3D_GLOBE_BOUNDARY_reg',i1)") iregion_code
   ! set the adios group size to 0 before incremented by calls to
   ! helpers functions.
   group_size_inc = 0
   call adios_declare_group(adios_group, group_name, &
-      "", 0, adios_err)
+      "", 1, adios_err)
   call adios_select_method(adios_group, "MPI", "", "", adios_err)
 
   !--- Define ADIOS variables -----------------------------
-  call define_adios_integer_scalar (adios_group, "nspec2D_xmin", "", &
-      group_size_inc)
-  call define_adios_integer_scalar (adios_group, "nspec2D_xmax", "", &
-      group_size_inc)
-  call define_adios_integer_scalar (adios_group, "nspec2D_ymin", "", &
-      group_size_inc)
-  call define_adios_integer_scalar (adios_group, "nspec2D_ymax", "", &
-      group_size_inc)
-  call define_adios_integer_scalar (adios_group, "NSPEC2D_BOTTOM", "", &
-      group_size_inc)
-  call define_adios_integer_scalar (adios_group, "NSPEC2D_TOP", "", &
-      group_size_inc)
+  call define_adios_scalar (adios_group, group_size_inc, &
+                            region_name_scalar, STRINGIFY_VAR(nspec2D_xmin))
+  call define_adios_scalar (adios_group, group_size_inc, &
+                            region_name_scalar, STRINGIFY_VAR(nspec2D_xmax))
+  call define_adios_scalar (adios_group, group_size_inc, &
+                            region_name_scalar, STRINGIFY_VAR(nspec2D_ymin))
+  call define_adios_scalar (adios_group, group_size_inc, &
+                            region_name_scalar, STRINGIFY_VAR(nspec2D_ymax))
+  call define_adios_scalar (adios_group, group_size_inc, &
+                            region_name_scalar, STRINGIFY_VAR(NSPEC2D_BOTTOM))
+  call define_adios_scalar (adios_group, group_size_inc, &
+                            region_name_scalar, STRINGIFY_VAR(NSPEC2D_TOP))
 
-  !local_dim = NSPEC2DMAX_XMIN_YMAX
-  local_dim = size (ibelm_xmin)
-  call define_adios_global_integer_1d_array(adios_group, "ibelm_xmin", &
-      local_dim, group_size_inc)
-  call define_adios_global_integer_1d_array(adios_group, "ibelm_xmax", &
-      local_dim, group_size_inc)
+  ! boundary elements
+  local_dim = NSPEC2DMAX_XMIN_XMAX
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(ibelm_xmin))
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(ibelm_xmax))
 
-  !local_dim = NSPEC2DMAX_YMIN_YMAX
-  local_dim = size (ibelm_ymin)
-  call define_adios_global_integer_1d_array(adios_group, "ibelm_ymin", &
-      local_dim, group_size_inc)
-  call define_adios_global_integer_1d_array(adios_group, "ibelm_ymax", &
-      local_dim, group_size_inc)
+  local_dim = NSPEC2DMAX_YMIN_YMAX
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(ibelm_ymin))
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(ibelm_ymax))
 
-  !local_dim = NSPEC2D_BOTTOM
-  local_dim = size (ibelm_bottom)
-  call define_adios_global_integer_1d_array(adios_group, "ibelm_bottom", &
-      local_dim, group_size_inc)
+  local_dim = NSPEC2D_BOTTOM
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(ibelm_bottom))
 
-  !local_dim = NSPEC2D_TOP
-  local_dim = size (ibelm_top)
-  call define_adios_global_integer_1d_array(adios_group, "ibelm_top", &
-      local_dim, group_size_inc)
+  local_dim = NSPEC2D_TOP
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(ibelm_top))
 
-  !local_dim = NDIM*NGLLY*NGLLZ*NSPEC2DMAX_XMIN_XMAX
-  local_dim = size (normal_xmin)
-  call define_adios_global_real_1d_array(adios_group, "normal_xmin", &
-      local_dim, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, "normal_xmax", &
-      local_dim, group_size_inc)
+  ! normals
+  local_dim = NDIM*NGLLY*NGLLZ*NSPEC2DMAX_XMIN_XMAX
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(normal_xmin))
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(normal_xmax))
 
-  !local_dim = NDIM*NGLLX*NGLLZ*NSPEC2DMAX_YMIN_YMAX
-  local_dim = size (normal_ymin)
-  call define_adios_global_real_1d_array(adios_group, "normal_ymin", &
-      local_dim, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, "normal_ymax", &
-      local_dim, group_size_inc)
+  local_dim = NDIM*NGLLX*NGLLZ*NSPEC2DMAX_YMIN_YMAX
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(normal_ymin))
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(normal_ymax))
 
-  !local_dim = NDIM*NGLLX*NGLLY*NSPEC2D_BOTTOM
-  local_dim = size (normal_bottom)
-  call define_adios_global_real_1d_array(adios_group, "normal_bottom", &
-      local_dim, group_size_inc)
+  local_dim = NDIM*NGLLX*NGLLY*NSPEC2D_BOTTOM
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(normal_bottom))
 
-  !local_dim = NDIM*NGLLX*NGLLY*NSPEC2D_TOP
-  local_dim = size (normal_top)
-  call define_adios_global_real_1d_array(adios_group, "normal_top", &
-      local_dim, group_size_inc)
+  local_dim = NDIM*NGLLX*NGLLY*NSPEC2D_TOP
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(normal_top))
 
-  !local_dim = NGLLY*NGLLZ*NSPEC2DMAX_XMIN_XMAX
-  local_dim = size (jacobian2D_xmin)
-  call define_adios_global_real_1d_array(adios_group, "jacobian2D_xmin", &
-      local_dim, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, "jacobian2D_xmax", &
-      local_dim, group_size_inc)
-  !local_dim = NDIM*NGLLX*NGLLZ*NSPEC2DMAX_YMIN_YMAX
-  local_dim = size (jacobian2D_ymin)
-  call define_adios_global_real_1d_array(adios_group, "jacobian2D_ymin", &
-      local_dim, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, "jacobian2D_ymax", &
-      local_dim, group_size_inc)
-  !local_dim = NDIM*NGLLX*NGLLY*NSPEC2D_BOTTOM
-  local_dim = size (jacobian2D_bottom)
-  call define_adios_global_real_1d_array(adios_group, "jacobian2D_bottom", &
-      local_dim, group_size_inc)
-  !local_dim = NDIM*NGLLX*NGLLY*NSPEC2D_TOP
-  local_dim = size (jacobian2D_top)
-  call define_adios_global_real_1d_array(adios_group, "jacobian2D_top", &
-      local_dim, group_size_inc)
+  ! jacobians
+  local_dim = NGLLY*NGLLZ*NSPEC2DMAX_XMIN_XMAX
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(jacobian2D_xmin))
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(jacobian2D_xmax))
 
+  local_dim = NGLLX*NGLLZ*NSPEC2DMAX_YMIN_YMAX
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(jacobian2D_ymin))
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(jacobian2D_ymax))
+
+  local_dim = NGLLX*NGLLY*NSPEC2D_BOTTOM
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(jacobian2D_bottom))
+
+  local_dim = NGLLX*NGLLY*NSPEC2D_TOP
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(jacobian2D_top))
+
   !--- Open an ADIOS handler to the restart file. ---------
-  call adios_open (adios_handle, group_name, &
-      outputname, "w", comm, adios_err);
-  call adios_group_size (adios_handle, group_size_inc, &
+  outputname = trim(LOCAL_PATH) // "/boundary.bp"
+  if (num_regions_written == 0) then
+    call adios_open (handle, group_name, outputname, "w", comm, adios_err)
+  else
+    call adios_open (handle, group_name, outputname, "a", comm, adios_err);
+  endif
+  call adios_group_size (handle, group_size_inc, &
                          adios_totalsize, adios_err)
 
   !--- Schedule writes for the previously defined ADIOS variables
-  call adios_write(adios_handle, "nspec2D_xmin", nspec2D_xmin, adios_err)
-  call adios_write(adios_handle, "nspec2D_xmax", nspec2D_xmax, adios_err)
-  call adios_write(adios_handle, "nspec2D_ymin", nspec2D_ymin, adios_err)
-  call adios_write(adios_handle, "nspec2D_ymax", nspec2D_ymax, adios_err)
-  call adios_write(adios_handle, "NSPEC2D_BOTTOM", NSPEC2D_BOTTOM, adios_err)
-  call adios_write(adios_handle, "NSPEC2D_TOP", NSPEC2D_TOP, adios_err)
+  call adios_write(handle, trim(region_name) // "nspec2D_xmin", nspec2D_xmin, adios_err)
+  call check_adios_err(myrank,adios_err)
+  call adios_write(handle, trim(region_name) // "nspec2D_xmax", nspec2D_xmax, adios_err)
+  call check_adios_err(myrank,adios_err)
+  call adios_write(handle, trim(region_name) // "nspec2D_ymin", nspec2D_ymin, adios_err)
+  call check_adios_err(myrank,adios_err)
+  call adios_write(handle, trim(region_name) // "nspec2D_ymax", nspec2D_ymax, adios_err)
+  call check_adios_err(myrank,adios_err)
+  call adios_write(handle, trim(region_name) // "NSPEC2D_BOTTOM", NSPEC2D_BOTTOM, adios_err)
+  call check_adios_err(myrank,adios_err)
+  call adios_write(handle, trim(region_name) // "NSPEC2D_TOP", NSPEC2D_TOP, adios_err)
+  call check_adios_err(myrank,adios_err)
 
-  !local_dim = NSPEC2DMAX_XMIN_XMAX
-  local_dim = size (ibelm_xmin)
-  call adios_set_path (adios_handle, "ibelm_xmin", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", ibelm_xmin, adios_err)
-  call adios_set_path (adios_handle, "ibelm_xmax", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", ibelm_xmax, adios_err)
+  ! boundary elements
+  local_dim = NSPEC2DMAX_XMIN_XMAX
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                 trim(region_name) // STRINGIFY_VAR(ibelm_xmin))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                 trim(region_name) // STRINGIFY_VAR(ibelm_xmax))
 
-  !local_dim = NSPEC2DMAX_YMIN_YMAX
-  local_dim = size (ibelm_ymin)
-  call adios_set_path (adios_handle, "ibelm_ymin", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", ibelm_ymin, adios_err)
-  call adios_set_path (adios_handle, "ibelm_ymax", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", ibelm_ymax, adios_err)
+  local_dim = NSPEC2DMAX_YMIN_YMAX
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                 trim(region_name) // STRINGIFY_VAR(ibelm_ymin))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                 trim(region_name) // STRINGIFY_VAR(ibelm_ymax))
 
-  !local_dim = NSPEC2D_BOTTOM
-  local_dim = size (ibelm_bottom)
-  call adios_set_path (adios_handle, "ibelm_bottom", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", ibelm_bottom, adios_err)
+  local_dim = NSPEC2D_BOTTOM
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                               trim(region_name) // STRINGIFY_VAR(ibelm_bottom))
 
-  !local_dim = NSPEC2D_TOP
-  local_dim = size (ibelm_top)
-  call adios_set_path (adios_handle, "ibelm_top", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", ibelm_top, adios_err)
+  local_dim = NSPEC2D_TOP
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                  trim(region_name) // STRINGIFY_VAR(ibelm_top))
 
-  !local_dim = NDIM*NGLLY*NGLLZ*NSPEC2DMAX_XMIN_XMAX
-  local_dim = size (normal_xmin)
-  call adios_set_path (adios_handle, "normal_xmin", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", normal_xmin, adios_err)
-  call adios_set_path (adios_handle, "normal_xmax", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", normal_xmax, adios_err)
+  ! normals
+  local_dim = NDIM*NGLLY*NGLLZ*NSPEC2DMAX_XMIN_XMAX
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                trim(region_name) // STRINGIFY_VAR(normal_xmin))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                trim(region_name) // STRINGIFY_VAR(normal_xmax))
 
-  !local_dim = NDIM*NGLLX*NGLLZ*NSPEC2DMAX_YMIN_YMAX
-  local_dim = size (normal_ymin)
-  call adios_set_path (adios_handle, "normal_ymin", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", normal_ymin, adios_err)
-  call adios_set_path (adios_handle, "normal_ymax", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", normal_ymax, adios_err)
+  local_dim = NDIM*NGLLX*NGLLZ*NSPEC2DMAX_YMIN_YMAX
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                trim(region_name) // STRINGIFY_VAR(normal_ymin))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                trim(region_name) // STRINGIFY_VAR(normal_ymax))
 
-  !local_dim = NDIM*NGLLX*NGLLY*NSPEC2D_BOTTOM
-  local_dim = size (normal_bottom)
-  call adios_set_path (adios_handle, "normal_bottom", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", normal_bottom, adios_err)
+  local_dim = NDIM*NGLLX*NGLLY*NSPEC2D_BOTTOM
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                              trim(region_name) // STRINGIFY_VAR(normal_bottom))
 
-  !local_dim = NDIM*NGLLX*NGLLY*NSPEC2D_TOP
-  local_dim = size (normal_top)
-  call adios_set_path (adios_handle, "normal_top", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", normal_top, adios_err)
+  local_dim = NDIM*NGLLX*NGLLY*NSPEC2D_TOP
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                 trim(region_name) // STRINGIFY_VAR(normal_top))
 
-  !local_dim = NGLLY*NGLLZ*NSPEC2DMAX_XMIN_XMAX
-  local_dim = size (jacobian2D_xmin)
-  call adios_set_path (adios_handle, "jacobian2D_xmin", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", jacobian2D_xmin, adios_err)
-  call adios_set_path (adios_handle, "jacobian2D_xmax", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", jacobian2D_xmax, adios_err)
+  ! jacobians
+  local_dim = NGLLY*NGLLZ*NSPEC2DMAX_XMIN_XMAX
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                            trim(region_name) // STRINGIFY_VAR(jacobian2D_xmin))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                            trim(region_name) // STRINGIFY_VAR(jacobian2D_xmax))
 
-  !local_dim = NDIM*NGLLX*NGLLZ*NSPEC2DMAX_YMIN_YMAX
-  local_dim = size (jacobian2D_ymin)
-  call adios_set_path (adios_handle, "jacobian2D_ymin", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", jacobian2D_ymin, adios_err)
-  call adios_set_path (adios_handle, "jacobian2D_ymax", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", jacobian2D_ymax, adios_err)
+  local_dim = NGLLX*NGLLZ*NSPEC2DMAX_YMIN_YMAX
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                            trim(region_name) // STRINGIFY_VAR(jacobian2D_ymin))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                            trim(region_name) // STRINGIFY_VAR(jacobian2D_ymax))
 
-  !local_dim = NDIM*NGLLX*NGLLY*NSPEC2D_BOTTOM
-  local_dim = size (jacobian2D_bottom)
-  call adios_set_path (adios_handle, "jacobian2D_bottom", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", jacobian2D_bottom, adios_err)
+  local_dim = NGLLX*NGLLY*NSPEC2D_BOTTOM
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                          trim(region_name) // STRINGIFY_VAR(jacobian2D_bottom))
 
-  !local_dim = NDIM*NGLLX*NGLLY*NSPEC2D_TOP
-  local_dim = size (jacobian2D_top)
-  call adios_set_path (adios_handle, "jacobian2D_top", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", jacobian2D_top, adios_err)
+  local_dim = NGLLX*NGLLY*NSPEC2D_TOP
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                             trim(region_name) // STRINGIFY_VAR(jacobian2D_top))
 
   !--- Reset the path to zero and perform the actual write to disk
-  call adios_set_path (adios_handle, "", adios_err)
-  call adios_close(adios_handle, adios_err)
+  call adios_close(handle, adios_err)
 
   !---------------------------------------------------------
   !--- Attenuation arrays ----------------------------------
   !---------------------------------------------------------
   if(ATTENUATION) then
-    outputname = trim(reg_name) // "attenuation.bp"
     write(group_name,"('SPECFEM3D_GLOBE_ATTENUATION_reg',i1)") iregion_code
     group_size_inc = 0
     call adios_declare_group(adios_group, group_name, &
@@ -966,54 +911,55 @@
     call adios_select_method(adios_group, "MPI", "", "", adios_err)
 
     !--- Define ADIOS variables -----------------------------
-    call define_adios_double_scalar(adios_group, "T_c_source", "", &
-        group_size_inc)
+    call define_adios_scalar (adios_group, group_size_inc, &
+                              region_name_scalar, STRINGIFY_VAR(t_c_source))
 
     local_dim = size(tau_s)
-    call define_adios_global_double_1d_array(adios_group, "tau_s", &
-        local_dim, group_size_inc)
+    call define_adios_global_array1D(adios_group, group_size_inc, &
+                                     local_dim, region_name,      &
+                                     STRINGIFY_VAR(tau_s))
     local_dim = size(tau_e_store)
-    call define_adios_global_real_1d_array(adios_group, "tau_e_store", &
-        local_dim, group_size_inc)
+    call define_adios_global_array1D(adios_group, group_size_inc, &
+                                     local_dim, region_name,      &
+                                     STRINGIFY_VAR(tau_e_store))
     local_dim = size(Qmu_store)
-    call define_adios_global_real_1d_array(adios_group, "Qmu_store", &
-        local_dim, group_size_inc)
+    call define_adios_global_array1D(adios_group, group_size_inc, &
+                                     local_dim, region_name,      &
+                                     STRINGIFY_VAR(Qmu_store))
 
     !--- Open an ADIOS handler to the restart file. ---------
-    call adios_open (adios_handle, group_name, &
-        outputname, "w", comm, adios_err);
-    call adios_group_size (adios_handle, group_size_inc, &
+    outputname = trim(LOCAL_PATH) // "/attenuation.bp"
+    if (num_regions_written == 0) then
+      call adios_open (handle, group_name, outputname, "w", comm, adios_err)
+    else
+      call adios_open (handle, group_name, outputname, "a", comm, adios_err);
+    endif
+    call adios_group_size (handle, group_size_inc, &
                            adios_totalsize, adios_err)
 
     !--- Schedule writes for the previously defined ADIOS variables
-    call adios_write(adios_handle, "T_c_source", T_c_source, adios_err)
+    call adios_write(handle, trim(region_name) // "T_c_source", &
+                     T_c_source, adios_err)
 
     local_dim = size (tau_s)
-    call adios_set_path (adios_handle, "tau_s", adios_err)
-    call write_1D_global_array_adios_dims(adios_handle, myrank, &
-        local_dim, sizeprocs)
-    call adios_write(adios_handle, "array", tau_s, adios_err)
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     trim(region_name) // STRINGIFY_VAR(tau_s))
     local_dim = size (tau_e_store)
-    call adios_set_path (adios_handle, "tau_e_store", adios_err)
-    call write_1D_global_array_adios_dims(adios_handle, myrank, &
-        local_dim, sizeprocs)
-    call adios_write(adios_handle, "array", tau_e_store, adios_err)
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                trim(region_name) // STRINGIFY_VAR(tau_e_store))
     local_dim = size (Qmu_store)
-    call adios_set_path (adios_handle, "Qmu_store", adios_err)
-    call write_1D_global_array_adios_dims(adios_handle, myrank, &
-        local_dim, sizeprocs)
-    call adios_write(adios_handle, "array", Qmu_store, adios_err)
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                  trim(region_name) // STRINGIFY_VAR(Qmu_store))
 
     !--- Reset the path to zero and perform the actual write to disk
-    call adios_set_path (adios_handle, "", adios_err)
-    call adios_close(adios_handle, adios_err)
+    call adios_close(handle, adios_err)
+
   endif
 
   !---------------------------------------------------------
   !--- dvp arrays ------------------------------------------
   !---------------------------------------------------------
   if(HETEROGEN_3D_MANTLE .and. iregion_code == IREGION_CRUST_MANTLE) then
-    outputname = trim(reg_name) // "dvp.bp"
     write(group_name,"('SPECFEM3D_GLOBE_DVP_reg',i1)") iregion_code
     group_size_inc = 0
     call adios_declare_group(adios_group, group_name, &
@@ -1022,22 +968,23 @@
 
     !--- Define ADIOS variables -----------------------------
     local_dim = size (dvpstore)
-    call define_adios_global_real_1d_array(adios_group, "dvp", &
-        local_dim, group_size_inc)
+    call define_adios_global_array1D(adios_group, group_size_inc, &
+                                     local_dim, region_name,      &
+                                     "dvp", dvpstore)
     !--- Open an ADIOS handler to the restart file. ---------
-    call adios_open (adios_handle, group_name, &
-        outputname, "w", comm, adios_err);
-    call adios_group_size (adios_handle, group_size_inc, &
+    outputname = trim(LOCAL_PATH) // "/dvp.bp"
+    if (num_regions_written == 0) then
+      call adios_open (handle, group_name, outputname, "w", comm, adios_err)
+    else
+      call adios_open (handle, group_name, outputname, "a", comm, adios_err);
+    endif
+    call adios_group_size (handle, group_size_inc, &
                            adios_totalsize, adios_err)
-    call adios_set_path (adios_handle, "dvp", adios_err)
-    !--- Schedule writes for the previously defined ADIOS variables
-    call write_1D_global_array_adios_dims(adios_handle, myrank, &
-        local_dim, sizeprocs)
-    call adios_write(adios_handle, "array", dvpstore, adios_err)
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     trim(region_name) // "dvp", dvpstore)
 
     !--- Reset the path to zero and perform the actual write to disk
-    call adios_set_path (adios_handle, "", adios_err)
-    call adios_close(adios_handle, adios_err)
+    call adios_close(handle, adios_err)
   endif
 
   !---------------------------------------------------------
@@ -1046,14 +993,16 @@
   ! uncomment for vp & vs model storage
   if( SAVE_MESH_FILES ) then
     ! outputs model files in binary format
-    if( ADIOS_ENABLED .and. ADIOS_FOR_SOLVER_MESHFILES ) then
+    if( ADIOS_FOR_SOLVER_MESHFILES) then
       call save_arrays_solver_meshfiles_adios(myrank,iregion_code, &
-          reg_name, nspec)
+                                              reg_name, nspec)
     else
       call save_arrays_solver_meshfiles(myrank,nspec)
     endif
   endif
 
+  num_regions_written = num_regions_written + 1
+
 end subroutine save_arrays_solver_adios
 
 
@@ -1065,20 +1014,23 @@
 !! \param reg_name Output file prefix with the name of the region included
 !! \param nspec Number of GLL points per spectral elements
 subroutine save_arrays_solver_meshfiles_adios(myrank, iregion_code, &
-    reg_name, nspec)
+                                              reg_name, nspec)
 
   ! outputs model files in binary format
-  use mpi
   use adios_write_mod
+  use adios_helpers_mod
   use constants
 
+  use meshfem3D_par, only: &
+    LOCAL_PATH
+
   use meshfem3D_models_par,only: &
-    TRANSVERSE_ISOTROPY,ATTENUATION,ATTENUATION_3D,ATTENUATION_1D_WITH_3D_STORAGE
+    TRANSVERSE_ISOTROPY,ATTENUATION, &
+    ATTENUATION_3D,ATTENUATION_1D_WITH_3D_STORAGE
 
   use create_regions_mesh_par2,only: &
     rhostore,kappavstore,kappahstore,muvstore,muhstore,eta_anisostore, &
-    Qmu_store, &
-    prname
+    Qmu_store !,prname
 
   implicit none
 
@@ -1086,155 +1038,155 @@
   character(len=150) :: reg_name
 
   ! local parameters
-  integer :: i,j,k,ispec,ier
+  integer :: i,j,k,ispec
   real(kind=CUSTOM_REAL) :: scaleval1,scaleval2
   real(kind=CUSTOM_REAL),dimension(:,:,:,:),allocatable :: temp_store
+  real(kind=CUSTOM_REAL), dimension(1,1,1,1) :: dummy_ijke
 
   ! local parameters
   character(len=150) :: outputname, group_name
-  integer :: ierr, sizeprocs, comm, local_dim
+  integer :: comm, local_dim
   integer(kind=8) :: group_size_inc
   ! ADIOS variables
   integer                 :: adios_err
-  integer(kind=8)         :: adios_group, adios_handle, varid
-  integer(kind=8)         :: adios_groupsize, adios_totalsize
+  integer(kind=8)         :: adios_group, handle
+  integer(kind=8)         :: adios_totalsize
+  character(len=128)      :: region_name, region_name_scalar
+  !--- Save the number of region written. Open the file in "w" mode if 0, else
+  !    in "a"  mode
+  integer, save :: num_regions_written = 0
 
+  integer :: sizeprocs
+
+  ! number of mpi processes
+  call world_size(sizeprocs)
+
   ! scaling factors to re-dimensionalize units
   scaleval1 = sngl( sqrt(PI*GRAV*RHOAV)*(R_EARTH/1000.0d0) )
   scaleval2 = sngl( RHOAV/1000.0d0 )
 
-  call world_size(sizeprocs) ! TODO keep it in parameters
-  call MPI_Comm_dup (MPI_COMM_WORLD, comm, ierr)
+  call world_duplicate(comm)
 
   ! isotropic model
-  outputname = trim(reg_name) // "solver_meshfiles.bp"
+  write(region_name,"('reg',i1, '/')") iregion_code
+  write(region_name_scalar,"('reg',i1)") iregion_code
   write(group_name,"('SPECFEM3D_GLOBE_solver_meshfiles_reg',i1)") iregion_code
 
   group_size_inc = 0
 
   call adios_declare_group(adios_group, group_name, &
-      "", 0, adios_err)
+      "", 1, adios_err)
   call adios_select_method(adios_group, "MPI", "", "", adios_err)
 
   !--- Define ADIOS variables -----------------------------
   !--- vp arrays -------------------------------------------
   local_dim = size (kappavstore)
-  call define_adios_global_real_1d_array(adios_group, "vp", &
-      local_dim, group_size_inc)
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   "vp", dummy_ijke)
   !--- vs arrays -------------------------------------------
   local_dim = size (rhostore)
-  call define_adios_global_real_1d_array(adios_group, "vs", &
-      local_dim, group_size_inc)
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   "vs", dummy_ijke)
   !--- rho arrays ------------------------------------------
   local_dim = size (rhostore)
-  call define_adios_global_real_1d_array(adios_group, "rho", &
-      local_dim, group_size_inc)
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                  local_dim, region_name,       &
+                                  "rho", dummy_ijke)
   ! transverse isotropic model
   if( TRANSVERSE_ISOTROPY ) then
     !--- vpv arrays ----------------------------------------
     local_dim = size (kappavstore)
-    call define_adios_global_real_1d_array(adios_group, "vpv", &
-        local_dim, group_size_inc)
+    call define_adios_global_array1D(adios_group, group_size_inc, &
+                                     local_dim, region_name,      &
+                                     "vpv", dummy_ijke)
     !--- vph arrays ----------------------------------------
     local_dim = size (kappavstore)
-    call define_adios_global_real_1d_array(adios_group, "vph", &
-        local_dim, group_size_inc)
+    call define_adios_global_array1D(adios_group, group_size_inc, &
+                                     local_dim, region_name,      &
+                                     "vph", dummy_ijke)
     !--- vsv arrays ----------------------------------------
     local_dim = size (rhostore)
-    call define_adios_global_real_1d_array(adios_group, "vsv", &
-        local_dim, group_size_inc)
+    call define_adios_global_array1D(adios_group, group_size_inc, &
+                                     local_dim, region_name,      &
+                                     "vsv", dummy_ijke)
     !--- vsh arrays ----------------------------------------
     local_dim = size (rhostore)
-    call define_adios_global_real_1d_array(adios_group, "vsh", &
-        local_dim, group_size_inc)
+    call define_adios_global_array1D(adios_group, group_size_inc, &
+                                     local_dim, region_name,      &
+                                     "vsh", dummy_ijke)
     !--- eta arrays ----------------------------------------
     local_dim = size (eta_anisostore)
-    call define_adios_global_real_1d_array(adios_group, "eta", &
-        local_dim, group_size_inc)
+    call define_adios_global_array1D(adios_group, group_size_inc, &
+                                     local_dim, region_name,      &
+                                     "eta", eta_anisostore)
   endif
+
   if( ATTENUATION ) then
     !--- Qmu arrays ----------------------------------------
     local_dim = NGLLX * NGLLY * NGLLZ * nspec
-    call define_adios_global_real_1d_array(adios_group, "qmu", &
-        local_dim, group_size_inc)
+    call define_adios_global_array1D(adios_group, group_size_inc, &
+                                     local_dim, region_name,      &
+                                     "qmu", dummy_ijke)
   endif
 
   !--- Open an ADIOS handler to the restart file. ---------
-  call adios_open (adios_handle, group_name, &
-      outputname, "w", comm, adios_err);
-  call adios_group_size (adios_handle, group_size_inc, &
+  outputname = trim(LOCAL_PATH) // "/solver_meshfiles.bp"
+  if (num_regions_written == 0) then
+    call adios_open (handle, group_name, outputname, "w", comm, adios_err)
+  else
+    call adios_open (handle, group_name, outputname, "a", comm, adios_err);
+  endif
+  call adios_group_size (handle, group_size_inc, &
                          adios_totalsize, adios_err)
 
   !--- Schedule writes for the previously defined ADIOS variables
+  ! TODO Try the new write helpers routines
   !--- vp arrays -------------------------------------------
   local_dim = size (kappavstore)
-  call adios_set_path (adios_handle, "vp", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", &
-      sqrt( (kappavstore+4.*muvstore/3.)/rhostore )*scaleval1, &
-      adios_err)
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                   trim(region_name) // "vp",            &
+                        sqrt( (kappavstore+4.*muvstore/3.)/rhostore )*scaleval1)
+
   !--- vs arrays -------------------------------------------
   local_dim = size (rhostore)
-  call adios_set_path (adios_handle, "vs", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", &
-      sqrt( muvstore/rhostore )*scaleval1, &
-      adios_err)
+  call write_adios_global_1d_array(handle, myrank, sizeprocs,            &
+                                   local_dim, trim(region_name) // "vs", &
+                                   sqrt( muvstore/rhostore )*scaleval1 )
   !--- rho arrays ------------------------------------------
   local_dim = size (rhostore)
-  call adios_set_path (adios_handle, "rho", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", &
-      rhostore *scaleval2, &
-      adios_err)
-
+  call write_adios_global_1d_array(handle, myrank, sizeprocs,             &
+                                   local_dim, trim(region_name) // "rho", &
+                                   rhostore *scaleval2)
   ! transverse isotropic model
   if( TRANSVERSE_ISOTROPY ) then
-    !--- vpv arrays ----------------------------------------
+    !--- vps arrays ----------------------------------------
     local_dim = size (kappavstore)
-    call adios_set_path (adios_handle, "vpv", adios_err)
-    call write_1D_global_array_adios_dims(adios_handle, myrank, &
-        local_dim, sizeprocs)
-    call adios_write(adios_handle, "array", &
-        sqrt( (kappavstore+4.*muvstore/3.)/rhostore )*scaleval1, &
-        adios_err)
-    !--- vph arrays ----------------------------------------
+    call write_adios_global_1d_array(handle, myrank, sizeprocs,             &
+                                     local_dim, trim(region_name) // "vpv", &
+                       sqrt( (kappavstore+4.*muvstore/3.)/rhostore )*scaleval1)
+
     local_dim = size (kappavstore)
-    call adios_set_path (adios_handle, "vph", adios_err)
-    call write_1D_global_array_adios_dims(adios_handle, myrank, &
-        local_dim, sizeprocs)
-    call adios_write(adios_handle, "array", &
-        sqrt( (kappahstore+4.*muhstore/3.)/rhostore )*scaleval1, &
-        adios_err)
+    !--- vph arrays ----------------------------------------
+    call write_adios_global_1d_array(handle, myrank, sizeprocs,             &
+                                     local_dim, trim(region_name) // "vph", &
+                       sqrt( (kappahstore+4.*muhstore/3.)/rhostore )*scaleval1)
     !--- vsv arrays ----------------------------------------
     local_dim = size (rhostore)
-    call adios_set_path (adios_handle, "vsv", adios_err)
-    call write_1D_global_array_adios_dims(adios_handle, myrank, &
-        local_dim, sizeprocs)
-    call adios_write(adios_handle, "array", &
-        sqrt( muvstore/rhostore )*scaleval1, &
-        adios_err)
+    call write_adios_global_1d_array(handle, myrank, sizeprocs,             &
+                                     local_dim, trim(region_name) // "vsv", &
+                                     sqrt( muvstore/rhostore )*scaleval1)
     !--- vsh arrays ----------------------------------------
     local_dim = size (rhostore)
-    call adios_set_path (adios_handle, "vsh", adios_err)
-    call write_1D_global_array_adios_dims(adios_handle, myrank, &
-        local_dim, sizeprocs)
-    call adios_write(adios_handle, "array", &
-        sqrt( muhstore/rhostore )*scaleval1, &
-        adios_err)
+    call write_adios_global_1d_array(handle, myrank, sizeprocs,             &
+                                     local_dim, trim(region_name) // "vsh", &
+                                     sqrt( muhstore/rhostore )*scaleval1)
     !--- eta arrays ----------------------------------------
     local_dim = size (eta_anisostore)
-    call adios_set_path (adios_handle, "eta", adios_err)
-    call write_1D_global_array_adios_dims(adios_handle, myrank, &
-        local_dim, sizeprocs)
-    call adios_write(adios_handle, "array", &
-        eta_anisostore, &
-        adios_err)
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     trim(region_name) // "eta", eta_anisostore)
   endif ! TRANSVERSE_ISOTROPY
-
   ! shear attenuation
   if( ATTENUATION ) then
     !-------------------------------------------------------
@@ -1260,21 +1212,17 @@
     endif
 
     local_dim = NGLLX * NGLLY * NGLLZ * nspec
-    call adios_set_path (adios_handle, "qmu", adios_err)
-    call write_1D_global_array_adios_dims(adios_handle, myrank, &
-        local_dim, sizeprocs)
-    call adios_write(adios_handle, "array", &
-        temp_store, &
-        adios_err)
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                     trim(region_name) // "qmu", temp_store)
 
     ! frees temporary memory
     deallocate(temp_store)
   endif ! ATTENUATION
 
-  !--- Reset the path to zero and perform the actual write to disk
-  call adios_set_path (adios_handle, "", adios_err)
-  call adios_close(adios_handle, adios_err)
+  call adios_close(handle, adios_err)
 
+  num_regions_written = num_regions_written + 1
+
 end subroutine save_arrays_solver_meshfiles_adios
 
 
@@ -1301,10 +1249,12 @@
    phase_ispec_inner, num_colors_outer,num_colors_inner, num_elem_colors)
 
   use constants
-  use mpi
+  use adios_helpers_mod
   use adios_write_mod
+
   implicit none
 
+
   integer :: iregion_code,myrank
   character(len=150) :: LOCAL_PATH
   ! MPI interfaces
@@ -1324,130 +1274,166 @@
 
   ! local parameters
   character(len=150) :: prname, outputname, group_name
-  integer :: ierr, sizeprocs, comm, local_dim
+  integer :: comm, local_dim
   integer(kind=8) :: group_size_inc
   ! ADIOS variables
   integer                 :: adios_err
-  integer(kind=8)         :: adios_group, adios_handle, varid
-  integer(kind=8)         :: adios_groupsize, adios_totalsize
+  integer(kind=8)         :: adios_group, handle
+  integer(kind=8)         :: adios_totalsize
+  character(len=128)      :: region_name, region_name_scalar
+  !--- Save the number of region written. Open the file in "w" mode if 0, else
+  !    in "a"  mode
+  integer, save :: num_regions_written = 0
 
+  integer, parameter :: num_ints_to_reduce = 5
+  integer, dimension(num_ints_to_reduce) :: ints_to_reduce
+  ! wmax = world_max variables to have constant strides in adios file
+  integer :: num_interfaces_wmax, max_nibool_interfaces_wmax, &
+             num_phase_ispec_wmax, num_colors_outer_wmax, num_colors_inner_wmax
+
+  integer :: sizeprocs
+
+  ! number of mpi processes
+  call world_size(sizeprocs)
+
+  ints_to_reduce(1) = num_interfaces
+  ints_to_reduce(2) = max_nibool_interfaces
+  ints_to_reduce(3) = num_phase_ispec
+  ints_to_reduce(4) = num_colors_outer
+  ints_to_reduce(5) = num_colors_inner
+
+  call max_allreduce_i(ints_to_reduce,num_ints_to_reduce)
+
+  num_interfaces_wmax        = ints_to_reduce(1)
+  max_nibool_interfaces_wmax = ints_to_reduce(2)
+  num_phase_ispec_wmax       = ints_to_reduce(3)
+  num_colors_outer_wmax      = ints_to_reduce(4)
+  num_colors_inner_wmax      = ints_to_reduce(5)
+
   ! create the name for the database of the current slide and region
   call create_name_database_adios(prname,iregion_code,LOCAL_PATH)
 
-  outputname = trim(prname) // "solver_data_mpi.bp"
+  outputname = trim(LOCAL_PATH) // "/solver_data_mpi.bp"
+  write(region_name,"('reg',i1, '/')") iregion_code
+  write(region_name_scalar,"('reg',i1)") iregion_code
   write(group_name,"('SPECFEM3D_GLOBE_MPI_ARRAYS_reg',i1)") iregion_code
-  call world_size(sizeprocs) ! TODO keep it in parameters
-  call MPI_Comm_dup (MPI_COMM_WORLD, comm, ierr)
+
+  call world_duplicate(comm)
+
   group_size_inc = 0
   call adios_declare_group(adios_group, group_name, &
-      "", 0, adios_err)
+                           "", 1, adios_err)
   call adios_select_method(adios_group, "MPI", "", "", adios_err)
 
   !--- Define ADIOS variables -----------------------------
   !! MPI interfaces
-  call define_adios_integer_scalar (adios_group, "num_interfaces", "", &
-      group_size_inc)
+  call define_adios_scalar (adios_group, group_size_inc, &
+                            region_name_scalar, STRINGIFY_VAR(num_interfaces))
   if( num_interfaces > 0 ) then
-    call define_adios_integer_scalar(adios_group, "max_nibool_interfaces", &
-        "", group_size_inc)
-    call define_adios_global_integer_1d_array(adios_group, "my_neighbours", &
-        num_interfaces, group_size_inc)
-    call define_adios_global_integer_1d_array(adios_group, "nibool_interfaces",&
-        num_interfaces, group_size_inc)
-    local_dim = max_nibool_interfaces*num_interfaces
-    call define_adios_global_integer_1d_array(adios_group, "ibool_interfaces", &
-        local_dim, group_size_inc)
+    call define_adios_scalar (adios_group, group_size_inc, region_name_scalar, &
+                              STRINGIFY_VAR(max_nibool_interfaces))
+    local_dim = num_interfaces_wmax
+    call define_adios_global_array1D(adios_group, group_size_inc, &
+                                     local_dim, region_name,      &
+                                     STRINGIFY_VAR(my_neighbours))
+    local_dim = num_interfaces_wmax
+    call define_adios_global_array1D(adios_group, group_size_inc, &
+                                     local_dim, region_name,      &
+                                     STRINGIFY_VAR(nibool_interfaces))
+    local_dim = max_nibool_interfaces_wmax * num_interfaces_wmax
+    call define_adios_global_array1D(adios_group, group_size_inc, &
+                                     local_dim, region_name,      &
+                                     STRINGIFY_VAR(ibool_interfaces))
   endif
 
   ! inner/outer elements
-  call define_adios_integer_scalar (adios_group, "nspec_inner", "", &
-      group_size_inc)
-  call define_adios_integer_scalar (adios_group, "nspec_outer", "", &
-      group_size_inc)
-  call define_adios_integer_scalar (adios_group, "num_phase_ispec", "", &
-      group_size_inc)
+  call define_adios_scalar (adios_group, group_size_inc, &
+                            region_name_scalar, STRINGIFY_VAR(nspec_inner))
+  call define_adios_scalar (adios_group, group_size_inc, &
+                            region_name_scalar, STRINGIFY_VAR(nspec_outer))
+  call define_adios_scalar (adios_group, group_size_inc, &
+                            region_name_scalar, STRINGIFY_VAR(num_phase_ispec))
   if(num_phase_ispec > 0 ) then
-    local_dim = num_phase_ispec * 2
-    call define_adios_global_integer_1d_array(adios_group, "phase_ispec_inner", &
-        local_dim, group_size_inc)
+    local_dim = num_phase_ispec_wmax * 2
+    call define_adios_global_array1D(adios_group, group_size_inc, &
+                                     local_dim, region_name,      &
+                                     STRINGIFY_VAR(phase_ispec_inner))
   endif
 
   ! mesh coloring
   if( USE_MESH_COLORING_GPU ) then
-    call define_adios_integer_scalar (adios_group, "num_colors_outer", "", &
-        group_size_inc)
-    call define_adios_integer_scalar (adios_group, "num_colors_inner", "", &
-        group_size_inc)
-    call define_adios_global_integer_1d_array(adios_group, "num_elem_colors", &
-        num_colors_outer + num_colors_inner, group_size_inc)
+    call define_adios_scalar (adios_group, group_size_inc, &
+                            region_name_scalar, STRINGIFY_VAR(num_colors_outer))
+    call define_adios_scalar (adios_group, group_size_inc, &
+                            region_name_scalar, STRINGIFY_VAR(num_colors_inner))
+    local_dim = num_colors_outer_wmax + num_colors_inner_wmax
+    call define_adios_global_array1D(adios_group, group_size_inc, &
+                                     local_dim, region_name,      &
+                                     STRINGIFY_VAR(num_elem_colors))
   endif
 
   !--- Open an ADIOS handler to the restart file. ---------
-  call adios_open (adios_handle, group_name, &
-      outputname, "w", comm, adios_err);
-  call adios_group_size (adios_handle, group_size_inc, &
+  if (num_regions_written == 0) then
+    call adios_open (handle, group_name, outputname, "w", comm, adios_err)
+  else
+    call adios_open (handle, group_name, outputname, "a", comm, adios_err);
+  endif
+  call adios_group_size (handle, group_size_inc, &
                          adios_totalsize, adios_err)
 
   !--- Schedule writes for the previously defined ADIOS variables
   ! MPI interfaces
-  call adios_write(adios_handle, "num_interfaces", num_interfaces, adios_err)
+  call adios_write(handle, trim(region_name) // "num_interfaces", &
+                   num_interfaces, adios_err)
+
   if( num_interfaces > 0 ) then
-    call adios_write(adios_handle, "max_nibool_interfaces", &
+    call adios_write(handle, trim(region_name) // "max_nibool_interfaces", &
         max_nibool_interfaces, adios_err)
+    local_dim = num_interfaces_wmax
+    call write_adios_global_1d_array(handle, myrank, sizeprocs,      &
+                                     local_dim, trim(region_name) // &
+                                     STRINGIFY_VAR(my_neighbours))
+    call write_adios_global_1d_array(handle, myrank, sizeprocs,       &
+                                     local_dim,  trim(region_name) // &
+                                     STRINGIFY_VAR(nibool_interfaces))
 
-    local_dim = num_interfaces
-
-    call adios_set_path (adios_handle, "my_neighbours", adios_err)
-    call write_1D_global_array_adios_dims(adios_handle, myrank, &
-        local_dim, sizeprocs)
-    call adios_write(adios_handle, "array", my_neighbours, adios_err)
-
-    call adios_set_path (adios_handle, "nibool_interfaces", adios_err)
-    call write_1D_global_array_adios_dims(adios_handle, myrank, &
-        local_dim, sizeprocs)
-    call adios_write(adios_handle, "array", nibool_interfaces, adios_err)
-
-    local_dim = max_nibool_interfaces * num_interfaces
-
-    call adios_set_path (adios_handle, "ibool_interfaces", adios_err)
-    call write_1D_global_array_adios_dims(adios_handle, myrank, &
-        local_dim, sizeprocs)
-    call adios_write(adios_handle, "array", &
-        ibool_interfaces, adios_err)
-    call adios_set_path (adios_handle, "", adios_err)
+    local_dim = max_nibool_interfaces_wmax * num_interfaces_wmax
+    call write_adios_global_1d_array(handle, myrank, sizeprocs,      &
+                                     local_dim, trim(region_name) // &
+                                     STRINGIFY_VAR(ibool_interfaces))
   endif
 
   ! inner/outer elements
-  call adios_write(adios_handle, "nspec_inner", nspec_inner, adios_err)
-  call adios_write(adios_handle, "nspec_outer", nspec_outer, adios_err)
-  call adios_write(adios_handle, "num_phase_ispec", num_phase_ispec, adios_err)
+  call adios_write(handle, trim(region_name) // "nspec_inner", &
+                   nspec_inner, adios_err)
+  call adios_write(handle, trim(region_name) // "nspec_outer", &
+                   nspec_outer, adios_err)
+  call adios_write(handle, trim(region_name) // "num_phase_ispec", &
+                   num_phase_ispec, adios_err)
 
   if(num_phase_ispec > 0 ) then
-    local_dim = num_phase_ispec * 2
-    call adios_set_path (adios_handle, "phase_ispec_inner", adios_err)
-    call write_1D_global_array_adios_dims(adios_handle, myrank, &
-        local_dim, sizeprocs)
-    call adios_write(adios_handle, "array", &
-        phase_ispec_inner, adios_err)
-    call adios_set_path (adios_handle, "", adios_err)
+    local_dim = num_phase_ispec_wmax * 2
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                          trim(region_name) // STRINGIFY_VAR(phase_ispec_inner))
   endif
 
   ! mesh coloring
   if( USE_MESH_COLORING_GPU ) then
-    call adios_write(adios_handle, "num_colors_outer", nspec_inner, adios_err)
-    call adios_write(adios_handle, "num_colors_inner", nspec_inner, adios_err)
-    local_dim = num_colors_outer + num_colors_inner
-    call adios_set_path (adios_handle, "num_elem_colors", adios_err)
-    call write_1D_global_array_adios_dims(adios_handle, myrank, &
-        local_dim, sizeprocs)
-    call adios_write(adios_handle, "array", &
-        num_elem_colors, adios_err)
-    call adios_set_path (adios_handle, "", adios_err)
+    call adios_write(handle, trim(region_name) // "num_colors_outer", &
+                     nspec_inner, adios_err)
+    call adios_write(handle, trim(region_name) // "num_colors_inner", &
+                     nspec_inner, adios_err)
+
+    local_dim = num_colors_outer_wmax + num_colors_inner_wmax
+    call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                            trim(region_name) // STRINGIFY_VAR(num_elem_colors))
   endif
 
   !--- Reset the path to zero and perform the actual write to disk
-  call adios_close(adios_handle, adios_err)
+  call adios_close(handle, adios_err)
 
+  num_regions_written = num_regions_written + 1
+
 end subroutine save_MPI_arrays_adios
 
 
@@ -1456,8 +1442,8 @@
 subroutine save_arrays_solver_boundary_adios()
 
 ! saves arrays for boundaries such as MOHO, 400 and 670 discontinuities
+
   use constants
-  use mpi
 
   use meshfem3d_par,only: &
     myrank, LOCAL_PATH
@@ -1471,24 +1457,35 @@
     ibelm_moho_top,ibelm_moho_bot,ibelm_400_top,ibelm_400_bot, &
     ibelm_670_top,ibelm_670_bot,normal_moho,normal_400,normal_670, &
     ispec2D_moho_top,ispec2D_moho_bot,ispec2D_400_top,ispec2D_400_bot, &
-    ispec2D_670_top,ispec2D_670_bot, &
-    prname
+    ispec2D_670_top,ispec2D_670_bot ! prname
 
+  use adios_helpers_mod
+
   implicit none
 
   ! local parameters
   ! local parameters
   character(len=150) :: outputname, group_name
-  integer :: ierr, sizeprocs, comm, local_dim
+  integer :: comm, local_dim
   integer(kind=8) :: group_size_inc
   ! ADIOS variables
   integer                 :: adios_err
-  integer(kind=8)         :: adios_group, adios_handle, varid
-  integer(kind=8)         :: adios_groupsize, adios_totalsize
+  integer(kind=8)         :: adios_group, handle !, varid
+  integer(kind=8)         :: adios_totalsize
+  character(len=128)      :: region_name, region_name_scalar
+  integer, parameter :: iregion_code = IREGION_CRUST_MANTLE
+  !--- Save the number of region written. Open the file in "w" mode if 0, else
+  !    in "a"  mode
+  integer, save :: num_regions_written = 0
 
+  integer :: sizeprocs
+
+  ! number of mpi processes
+  call world_size(sizeprocs)
+
   ! first check the number of surface elements are the same for Moho, 400, 670
   if (.not. SUPPRESS_CRUSTAL_MESH .and. HONOR_1D_SPHERICAL_MOHO) then
-    if (ispec2D_moho_top /= NSPEC2D_MOHO .or. ispec2D_moho_bot /= NSPEC2D_MOHO) &
+    if (ispec2D_moho_top /= NSPEC2D_MOHO .or. ispec2D_moho_bot /= NSPEC2D_MOHO)&
            call exit_mpi(myrank, 'Not the same number of Moho surface elements')
   endif
   if (ispec2D_400_top /= NSPEC2D_400 .or. ispec2D_400_bot /= NSPEC2D_400) &
@@ -1497,132 +1494,134 @@
            call exit_mpi(myrank,'Not the same number of 670 surface elements')
 
   outputname = trim(LOCAL_PATH) // "/boundary_disc.bp"
+  write(region_name,"('reg',i1, '/')") iregion_code
+  write(region_name_scalar,"('reg',i1)") iregion_code
   group_name = "SPECFEM3D_GLOBE_BOUNDARY_DISC"
-  call world_size(sizeprocs) ! TODO keep it in parameters
-  call MPI_Comm_dup (MPI_COMM_WORLD, comm, ierr)
+
+  call world_duplicate(comm)
+
   group_size_inc = 0
   call adios_declare_group(adios_group, group_name, &
-      "", 0, adios_err)
+      "", 1, adios_err)
   call adios_select_method(adios_group, "MPI", "", "", adios_err)
 
   !--- Define ADIOS variables -----------------------------
-  call define_adios_integer_scalar (adios_group, "NSPEC2D_MOHO", "", &
-      group_size_inc)
-  call define_adios_integer_scalar (adios_group, "NSPEC2D_400", "", &
-      group_size_inc)
-  call define_adios_integer_scalar (adios_group, "NSPEC2D_670", "", &
-      group_size_inc)
+  call define_adios_scalar (adios_group, group_size_inc, &
+                            region_name_scalar, STRINGIFY_VAR(nspec2d_moho))
+  call define_adios_scalar (adios_group, group_size_inc, &
+                            region_name_scalar, STRINGIFY_VAR(nspec2d_400))
+  call define_adios_scalar (adios_group, group_size_inc, &
+                            region_name_scalar, STRINGIFY_VAR(nspec2d_670))
 
   local_dim = NSPEC2D_MOHO
-  call define_adios_global_integer_1d_array(adios_group, "ibelm_moho_top", &
-        local_dim, group_size_inc)
-  call define_adios_global_integer_1d_array(adios_group, "ibelm_moho_bot", &
-        local_dim, group_size_inc)
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(ibelm_moho_top))
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(ibelm_moho_bot))
   local_dim = NSPEC2D_400
-  call define_adios_global_integer_1d_array(adios_group, "ibelm_400_top", &
-        local_dim, group_size_inc)
-  call define_adios_global_integer_1d_array(adios_group, "ibelm_400_bot", &
-        local_dim, group_size_inc)
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(ibelm_400_top))
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(ibelm_400_bot))
   local_dim = NSPEC2D_670
-  call define_adios_global_integer_1d_array(adios_group, "ibelm_670_top", &
-        local_dim, group_size_inc)
-  call define_adios_global_integer_1d_array(adios_group, "ibelm_670_bot", &
-        local_dim, group_size_inc)
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(ibelm_670_top))
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(ibelm_670_bot))
   local_dim = NDIM*NGLLX*NGLLY*NSPEC2D_MOHO
-  call define_adios_global_real_1d_array(adios_group, "normal_moho", &
-        local_dim, group_size_inc)
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(normal_moho))
   local_dim = NDIM*NGLLX*NGLLY*NSPEC2D_400
-  call define_adios_global_real_1d_array(adios_group, "normal_400", &
-        local_dim, group_size_inc)
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(normal_400))
   local_dim = NDIM*NGLLX*NGLLY*NSPEC2D_670
-  call define_adios_global_real_1d_array(adios_group, "normal_670", &
-        local_dim, group_size_inc)
+  call define_adios_global_array1D(adios_group, group_size_inc, &
+                                   local_dim, region_name,      &
+                                   STRINGIFY_VAR(normal_670))
 
   !--- Open an ADIOS handler to the restart file. ---------
-  call adios_open (adios_handle, group_name, &
-      outputname, "w", comm, adios_err);
-  call adios_group_size (adios_handle, group_size_inc, &
+  if (num_regions_written == 0) then
+    call adios_open (handle, group_name, outputname, "w", comm, adios_err)
+  else
+    call adios_open (handle, group_name, outputname, "a", comm, adios_err);
+  endif
+  call adios_group_size (handle, group_size_inc, &
                          adios_totalsize, adios_err)
 
   !--- Schedule writes for the previously defined ADIOS variables
-  call adios_write(adios_handle, "NSPEC2D_MOHO", NSPEC2D_MOHO, adios_err)
-  call adios_write(adios_handle, "NSPEC2D_400", NSPEC2D_400, adios_err)
-  call adios_write(adios_handle, "NSPEC2D_670", NSPEC2D_670, adios_err)
+  call adios_write(handle, trim(region_name) // "NSPEC2D_MOHO", &
+                   NSPEC2D_MOHO, adios_err)
+  call adios_write(handle, trim(region_name) // "NSPEC2D_400", &
+                   NSPEC2D_400, adios_err)
+  call adios_write(handle, trim(region_name) // "NSPEC2D_670", &
+                   NSPEC2D_670, adios_err)
 
   local_dim = NSPEC2D_MOHO
-  call adios_set_path (adios_handle, "ibelm_moho_top", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", ibelm_moho_top, adios_err)
-  call adios_set_path (adios_handle, "ibelm_moho_bot", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", ibelm_moho_bot, adios_err)
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                             trim(region_name) // STRINGIFY_VAR(ibelm_moho_top))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                             trim(region_name) // STRINGIFY_VAR(ibelm_moho_bot))
 
   local_dim = NSPEC2D_400
-  call adios_set_path (adios_handle, "ibelm_400_top", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", ibelm_400_top, adios_err)
-  call adios_set_path (adios_handle, "ibelm_400_bot", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", ibelm_400_bot, adios_err)
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                              trim(region_name) // STRINGIFY_VAR(ibelm_400_top))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                              trim(region_name) // STRINGIFY_VAR(ibelm_400_bot))
 
   local_dim = NSPEC2D_670
-  call adios_set_path (adios_handle, "ibelm_670_top", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", ibelm_670_top, adios_err)
-  call adios_set_path (adios_handle, "ibelm_670_bot", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", ibelm_670_bot, adios_err)
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                              trim(region_name) // STRINGIFY_VAR(ibelm_670_top))
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                              trim(region_name) // STRINGIFY_VAR(ibelm_670_bot))
 
   local_dim = NDIM*NGLLX*NGLLY*NSPEC2D_MOHO
-  call adios_set_path (adios_handle, "normal_moho", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", normal_moho, adios_err)
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                trim(region_name) // STRINGIFY_VAR(normal_moho))
 
   local_dim = NDIM*NGLLX*NGLLY*NSPEC2D_400
-  call adios_set_path (adios_handle, "normal_400", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", normal_400, adios_err)
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                 trim(region_name) // STRINGIFY_VAR(normal_400))
 
   local_dim = NDIM*NGLLX*NGLLY*NSPEC2D_670
-  call adios_set_path (adios_handle, "normal_670", adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", normal_670, adios_err)
+  call write_adios_global_1d_array(handle, myrank, sizeprocs, local_dim, &
+                                 trim(region_name) // STRINGIFY_VAR(normal_670))
 
   !--- Reset the path to zero and perform the actual write to disk
-  call adios_set_path (adios_handle, "", adios_err)
-  call adios_close(adios_handle, adios_err)
+  call adios_close(handle, adios_err)
+
+  num_regions_written = num_regions_written + 1
+
 end subroutine save_arrays_solver_boundary_adios
 
-!-------------------------------------------------------------------------------
-!> Write local, global and offset dimensions to ADIOS
-!! \param adios_handle Handle to the adios file
-!! \param local_dim Number of elements to be written by one process
-!! \param sizeprocs Number of MPI processes
-subroutine write_1D_global_array_adios_dims(adios_handle, myrank, &
-    local_dim, sizeprocs)
-  use adios_write_mod
+!!------------------------------------------------------------------------------
+!!> Write local, global and offset dimensions to ADIOS
+!!! \param handle Handle to the adios file
+!!! \param local_dim Number of elements to be written by one process
+!!! \param sizeprocs Number of MPI processes
+!subroutine write_1D_global_array_adios_dims(handle, myrank, &
+    !local_dim, sizeprocs)
+  !use adios_write_mod
 
-  implicit none
+  !implicit none
 
-  integer(kind=8), intent(in) :: adios_handle
-  integer, intent(in) :: sizeprocs, local_dim, myrank
+  !integer(kind=8), intent(in) :: handle
+  !integer, intent(in) :: sizeprocs, local_dim, myrank
 
-  integer :: adios_err
+  !integer :: adios_err
 
-  call adios_write(adios_handle, "local_dim", local_dim, adios_err)
-  call check_adios_err(myrank,adios_err)
-  call adios_write(adios_handle, "global_dim", local_dim*sizeprocs, adios_err)
-  call check_adios_err(myrank,adios_err)
-  call adios_write(adios_handle, "offset", local_dim*myrank, adios_err)
-  call check_adios_err(myrank,adios_err)
-end subroutine write_1D_global_array_adios_dims
+  !call adios_write(handle, "local_dim", local_dim, adios_err)
+  !call check_adios_err(myrank,adios_err)
+  !call adios_write(handle, "global_dim", local_dim*sizeprocs, adios_err)
+  !call check_adios_err(myrank,adios_err)
+  !call adios_write(handle, "offset", local_dim*myrank, adios_err)
+  !call check_adios_err(myrank,adios_err)
+!end subroutine write_1D_global_array_adios_dims
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/test_MPI_interfaces.f90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/test_MPI_interfaces.f90	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/test_MPI_interfaces.f90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -128,19 +128,22 @@
 
   ! master gathers infos
   if( myrank == 0 ) then
+    ! user output
+    write(IMAIN,*) '  maximum interfaces:',max_num
+
     ! array for gathering infos
     allocate(test_interfaces(max_num,0:NPROCTOT),stat=ier)
     if( ier /= 0 ) call exit_mpi(myrank,'error allocating test_interfaces')
-    test_interfaces = -1
+    test_interfaces(:,:) = -1
 
     allocate(test_interfaces_nibool(max_num,0:NPROCTOT),stat=ier)
     if( ier /= 0 ) call exit_mpi(myrank,'error allocating test_interfaces_nibool')
-    test_interfaces_nibool = 0
+    test_interfaces_nibool(:,:) = 0
 
     ! used to store number of interfaces per proc
     allocate(dummy_i(0:NPROCTOT),stat=ier)
     if( ier /= 0 ) call exit_mpi(myrank,'error allocating dummy_i for test interfaces')
-    dummy_i = 0
+    dummy_i(:) = 0
 
     ! sets infos for master process
     test_interfaces(1:num_interfaces,0) = my_neighbours(1:num_interfaces)
@@ -223,6 +226,7 @@
 
     deallocate(dummy_i)
     deallocate(test_interfaces)
+    deallocate(test_interfaces_nibool)
   endif
   call synchronize_all()
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/write_AVS_DX_global_chunks_data_adios.f90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/write_AVS_DX_global_chunks_data_adios.f90	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/write_AVS_DX_global_chunks_data_adios.f90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -55,6 +55,7 @@
 
   use constants
   use adios_write_mod
+  use adios_helpers_mod
 
   implicit none
 
@@ -98,21 +99,24 @@
 
   ! local parameters
   integer ispec
-  integer i,j,k,np
+  !integer i,j,k,np
   integer, dimension(8) :: iglobval
-  integer npoin,numpoin,nspecface,ispecface
+  integer npoin,nspecface !,ispecface,numpoin
 
-  real(kind=CUSTOM_REAL) vmin,vmax
+  !real(kind=CUSTOM_REAL) vmin,vmax
+  !double precision r,rho,vp,vs,Qkappa,Qmu
+  !double precision vpv,vph,vsv,vsh !,eta_aniso
+  !double precision x,y,z,theta,phi_dummy,p20 !,ell,factor,cost
+  !real(kind=CUSTOM_REAL) dvp,dvs
 
-  double precision r,rho,vp,vs,Qkappa,Qmu
-  double precision vpv,vph,vsv,vsh,eta_aniso
-  double precision x,y,z,theta,phi_dummy,cost,p20,ell,factor
-  real(kind=CUSTOM_REAL) dvp,dvs
-
   type(avs_dx_global_chunks_t), intent(inout) :: avs_dx_adios
 
   integer :: ierr
 
+  ! Dummy arrays for type inference inside adios helpers
+  real(kind=4), dimension(1) :: dummy_real1d
+  integer(kind=4), dimension(1) :: dummy_int1d
+
   mask_ibool(:) = .false.
 
   nspecface = 0
@@ -200,42 +204,51 @@
   allocate(avs_dx_adios%iglob4(nspecface), stat=ierr)
   if (ierr /= 0) call exit_MPI(myrank, "Error allocating iglob4.")
 
-  !--- Variables for '...AVS_DXpointschunk.txt'
-  call define_adios_global_real_1d_array(adios_group, "points_chunks/x_value", &
-      npoin, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, "points_chunks/y_value", &
-      npoin, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, "points_chunks/z_value", &
-      npoin, group_size_inc)
+
+  !--- Variables for '...AVS_DXpointschunks.txt'
+  call define_adios_global_array1D(adios_group, group_size_inc, npoin, &
+                                   "", "points_chunks/x_value", dummy_real1d)
+  call define_adios_global_array1D(adios_group, group_size_inc, npoin, &
+                                   "", "points_chunks/y_value", dummy_real1d)
+  call define_adios_global_array1D(adios_group, group_size_inc, npoin, &
+                                   "", "points_chunks/z_value", dummy_real1d)
+
   !--- Variables for '...AVS_DXpointschunk_stability.txt'
-  call define_adios_global_real_1d_array(adios_group, &
-      "points_chunks_stability/vmin", npoin, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, &
-      "points_chunks_stability/vmax", npoin, group_size_inc)
+  call define_adios_global_array1D(adios_group, group_size_inc, npoin, &
+                                   "", "points_chunks/vmin", dummy_real1d)
+  call define_adios_global_array1D(adios_group, group_size_inc, npoin, &
+                                   "", "points_chunks/vmax", dummy_real1d)
+
   !--- Variables for AVS_DXelementschunks.txt
-  call define_adios_global_real_1d_array(adios_group, &
-      "elements_chunks/idoubling", nspecface, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, &
-      "elements_chunks/num_ibool_AVS_DX_iglob1", nspecface, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, &
-      "elements_chunks/num_ibool_AVS_DX_iglob2", nspecface, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, &
-      "elements_chunks/num_ibool_AVS_DX_iglob3", nspecface, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, &
-      "elements_chunks/num_ibool_AVS_DX_iglob4", nspecface, group_size_inc)
+  call define_adios_global_array1D(adios_group, group_size_inc, nspec, &
+                                   "", "elements_chunks/idoubling",    &
+                                   dummy_int1d)
 
-  !--- Variables for AVS_DXelementschunks_dvp_dvs.txt
+  call define_adios_global_array1D(adios_group, group_size_inc, nspecface,     &
+                                "", "elements_chunks/num_ibool_AVS_DX_iglob1", &
+                                   dummy_int1d)
+  call define_adios_global_array1D(adios_group, group_size_inc, nspecface,     &
+                                "", "elements_chunks/num_ibool_AVS_DX_iglob2", &
+                                   dummy_int1d)
+  call define_adios_global_array1D(adios_group, group_size_inc, nspecface,     &
+                                "", "elements_chunks/num_ibool_AVS_DX_iglob3", &
+                                   dummy_int1d)
+  call define_adios_global_array1D(adios_group, group_size_inc, nspecface,     &
+                                "", "elements_chunks/num_ibool_AVS_DX_iglob4", &
+                                   dummy_int1d)
+
   if(ISOTROPIC_3D_MANTLE) then
     allocate(avs_dx_adios%dvp(nspecface), stat=ierr)
     if (ierr /= 0) call exit_MPI(myrank, "Error allocating dvp.")
     allocate(avs_dx_adios%dvs(nspecface), stat=ierr)
     if (ierr /= 0) call exit_MPI(myrank, "Error allocating dvs.")
-    call define_adios_global_real_1d_array(adios_group, &
-        "elements_chunks/dvp", dvp, group_size_inc)
-    call define_adios_global_real_1d_array(adios_group, &
-        "elements_chunks/dvp", dvs, group_size_inc)
+    call define_adios_global_array1D(adios_group, group_size_inc, nspecface, &
+                                     "elements_faces", "dvp", dummy_real1d)
+    call define_adios_global_array1D(adios_group, group_size_inc, nspecface, &
+                                     "elements_faces", "dvs", dummy_real1d)
   endif
 
+
 end subroutine define_AVS_DX_global_chunks_data
 
 !===============================================================================
@@ -918,7 +931,8 @@
                   dvp = dvp + (sqrt((kappavstore(i,j,k,ispec) &
                       +4.*muvstore(i,j,k,ispec)/3.)/rhostore(i,j,k,ispec)) &
                       - sngl(vp))/sngl(vp)
-                  dvs = dvs + (sqrt(muvstore(i,j,k,ispec)/rhostore(i,j,k,ispec)) &
+                  dvs = dvs + (sqrt(muvstore(i,j,k,ispec) &
+                               / rhostore(i,j,k,ispec)) &
                       - sngl(vs))/sngl(vs)
                 endif
 
@@ -1004,6 +1018,7 @@
     sizeprocs, avs_dx_adios, ISOTROPIC_3D_MANTLE)
 
   use adios_write_mod
+  use adios_helpers_mod
   implicit none
   !--- Arguments
   integer(kind=8), intent(in) :: adios_handle
@@ -1012,78 +1027,49 @@
   logical ISOTROPIC_3D_MANTLE
   !--- Variables
   integer :: npoin, nspec
-  integer :: ierr
 
   npoin = avs_dx_adios%npoin
   nspec = avs_dx_adios%nspecface
 
-  call adios_set_path(adios_handle, "points_chunks/x_value", ierr)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      npoin, sizeprocs)
-  call adios_write(adios_handle, "array", avs_dx_adios%x_adios, ierr)
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, npoin, &
+                                   "points_chunks/x_value",                &
+                                   avs_dx_adios%x_adios)
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, npoin, &
+                                   "points_chunks/y_value",                &
+                                   avs_dx_adios%y_adios)
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, npoin, &
+                                   "points_chunks/z_value",                &
+                                   avs_dx_adios%z_adios)
 
-  call adios_set_path(adios_handle, "points_chunks/y_value", ierr)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      npoin, sizeprocs)
-  call adios_write(adios_handle, "array", avs_dx_adios%y_adios, ierr)
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, npoin, &
+                                   "points_chunks/vmin", avs_dx_adios%vmin)
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, npoin, &
+                                   "points_chunks/vmax", avs_dx_adios%vmax)
 
-  call adios_set_path(adios_handle, "points_chunks/z_value", ierr)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      npoin, sizeprocs)
-  call adios_write(adios_handle, "array", avs_dx_adios%z_adios, ierr)
 
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, nspec, &
+                                  "elements_chunks/idoubling",             &
+                                   avs_dx_adios%idoubling)
 
-  call adios_set_path(adios_handle, "points_chunks/vmin", ierr)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      npoin, sizeprocs)
-  call adios_write(adios_handle, "array", avs_dx_adios%vmin, ierr)
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, nspec,    &
+                                   "elements_chunks/num_ibool_AVS_DX_iglob1", &
+                                   avs_dx_adios%iglob1)
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, nspec,    &
+                                   "elements_chunks/num_ibool_AVS_DX_iglob2", &
+                                   avs_dx_adios%iglob2)
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, nspec,    &
+                                   "elements_chunks/num_ibool_AVS_DX_iglob3", &
+                                   avs_dx_adios%iglob3)
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, nspec,    &
+                                   "elements_chunks/num_ibool_AVS_DX_iglob4", &
+                                   avs_dx_adios%iglob4)
 
-  call adios_set_path(adios_handle, "points_chunks/vmax", ierr)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      npoin, sizeprocs)
-  call adios_write(adios_handle, "array", avs_dx_adios%vmax, ierr)
 
-
-  call adios_set_path(adios_handle, "elements_chunks/idoubling", ierr)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      nspec, sizeprocs)
-  call adios_write(adios_handle, "array", avs_dx_adios%idoubling, ierr)
-
-
-  call adios_set_path(adios_handle, &
-      "elements_chunks/num_ibool_AVS_DX_iglob1", ierr)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      nspec, sizeprocs)
-  call adios_write(adios_handle, "array", avs_dx_adios%iglob1, ierr)
-
-  call adios_set_path(adios_handle, &
-      "elements_chunks/num_ibool_AVS_DX_iglob2", ierr)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      nspec, sizeprocs)
-  call adios_write(adios_handle, "array", avs_dx_adios%iglob2, ierr)
-
-  call adios_set_path(adios_handle, &
-      "elements_chunks/num_ibool_AVS_DX_iglob3", ierr)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      nspec, sizeprocs)
-  call adios_write(adios_handle, "array", avs_dx_adios%iglob3, ierr)
-
-  call adios_set_path(adios_handle, &
-      "elements_chunks/num_ibool_AVS_DX_iglob4", ierr)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      nspec, sizeprocs)
-  call adios_write(adios_handle, "array", avs_dx_adios%iglob4, ierr)
-
-
   if(ISOTROPIC_3D_MANTLE) then
-    call adios_set_path(adios_handle, "elements_chunks/dvp", ierr)
-    call write_1D_global_array_adios_dims(adios_handle, myrank, &
-        nspec, sizeprocs)
-    call adios_write(adios_handle, "array", avs_dx_adios%dvp, ierr)
-    call adios_set_path(adios_handle, "elements_chunks/dvs", ierr)
-    call write_1D_global_array_adios_dims(adios_handle, myrank, &
-        nspec, sizeprocs)
-    call adios_write(adios_handle, "array", avs_dx_adios%dvs, ierr)
+    call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, nspec, &
+                                     "elements_chunks/dvp", avs_dx_adios%dvp)
+    call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, nspec, &
+                                     "elements_chunks/dvs", avs_dx_adios%dvs)
   endif
 
 end subroutine write_AVS_DX_global_chunks_data_adios

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/write_AVS_DX_global_data_adios.f90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/write_AVS_DX_global_data_adios.f90	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/write_AVS_DX_global_data_adios.f90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -59,6 +59,8 @@
 
   use constants
   use adios_write_mod
+  use adios_helpers_mod
+
   implicit none
 
   !--- Arguments -------------------------------------------
@@ -72,6 +74,10 @@
   integer ispec, npoin, ierr
   integer iglob1,iglob2,iglob3,iglob4,iglob5,iglob6,iglob7,iglob8
 
+  ! Dummy arrays for type inference inside adios helpers
+  real(kind=4), dimension(1) :: dummy_real1d
+  integer(kind=4), dimension(1) :: dummy_int1d
+
   mask_ibool(:) = .false.
 
   ! mark global AVS or DX points
@@ -128,32 +134,41 @@
   if (ierr /= 0) call exit_MPI(myrank, "Error allocating iglob8.")
 
   !--- Variables for '...AVS_DXpoints.txt'
-  call define_adios_global_real_1d_array(adios_group, "points/x_value", &
-      npoin, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, "points/y_value", &
-      npoin, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, "points/z_value", &
-      npoin, group_size_inc)
+  call define_adios_global_array1D(adios_group, group_size_inc, npoin, &
+                                   "", "points/x_value", dummy_real1d)
+  call define_adios_global_array1D(adios_group, group_size_inc, npoin, &
+                                   "", "points/y_value", dummy_real1d)
+  call define_adios_global_array1D(adios_group, group_size_inc, npoin, &
+                                   "", "points/z_value", dummy_real1d)
+
   !--- Variables for AVS_DXelements.txt
-  call define_adios_global_real_1d_array(adios_group, "elements/idoubling", &
-      nspec, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, &
-      "elements/num_ibool_AVS_DX_iglob1", nspec, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, &
-      "elements/num_ibool_AVS_DX_iglob2", nspec, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, &
-      "elements/num_ibool_AVS_DX_iglob3", nspec, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, &
-      "elements/num_ibool_AVS_DX_iglob4", nspec, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, &
-      "elements/num_ibool_AVS_DX_iglob5", nspec, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, &
-      "elements/num_ibool_AVS_DX_iglob6", nspec, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, &
-      "elements/num_ibool_AVS_DX_iglob7", nspec, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, &
-      "elements/num_ibool_AVS_DX_iglob8", nspec, group_size_inc)
+  call define_adios_global_array1D(adios_group, group_size_inc, nspec,     &
+                                   "", "elements/idoubling", dummy_int1d)
 
+  call define_adios_global_array1D(adios_group, group_size_inc, nspec,     &
+                                   "", "elements/num_ibool_AVS_DX_iglob1", &
+                                   dummy_int1d)
+  call define_adios_global_array1D(adios_group, group_size_inc, nspec,     &
+                                   "", "elements/num_ibool_AVS_DX_iglob2", &
+                                   dummy_int1d)
+  call define_adios_global_array1D(adios_group, group_size_inc, nspec,     &
+                                   "", "elements/num_ibool_AVS_DX_iglob3", &
+                                   dummy_int1d)
+  call define_adios_global_array1D(adios_group, group_size_inc, nspec,     &
+                                   "", "elements/num_ibool_AVS_DX_iglob4", &
+                                   dummy_int1d)
+  call define_adios_global_array1D(adios_group, group_size_inc, nspec,     &
+                                   "", "elements/num_ibool_AVS_DX_iglob5", &
+                                   dummy_int1d)
+  call define_adios_global_array1D(adios_group, group_size_inc, nspec,     &
+                                   "", "elements/num_ibool_AVS_DX_iglob6", &
+                                   dummy_int1d)
+  call define_adios_global_array1D(adios_group, group_size_inc, nspec,     &
+                                   "", "elements/num_ibool_AVS_DX_iglob7", &
+                                   dummy_int1d)
+  call define_adios_global_array1D(adios_group, group_size_inc, nspec,     &
+                                   "", "elements/num_ibool_AVS_DX_iglob8", &
+                                   dummy_int1d)
 end subroutine define_AVS_DX_global_data_adios
 
 
@@ -196,8 +211,6 @@
 
   type(avs_dx_global_t), intent(inout) :: avs_dx_adios
 
-  integer :: ierr
-
 ! erase the logical mask used to mark points already found
   mask_ibool(:) = .false.
 
@@ -341,6 +354,7 @@
     sizeprocs, avs_dx_adios)
 
   use adios_write_mod
+  use adios_helpers_mod
   implicit none
   !--- Arguments
   integer(kind=8), intent(in) :: adios_handle
@@ -348,72 +362,46 @@
   type(avs_dx_global_t), intent(inout) :: avs_dx_adios ! out for adios_write
   !--- Variables
   integer :: npoin, nspec
-  integer :: ierr
 
   npoin = avs_dx_adios%npoin
   nspec = avs_dx_adios%nspec
 
-  call adios_set_path(adios_handle, "points/x_value", ierr)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      npoin, sizeprocs)
-  call adios_write(adios_handle, "array", avs_dx_adios%x_adios, ierr)
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, npoin, &
+                                   "points/x_value", avs_dx_adios%x_adios)
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, npoin, &
+                                   "points/y_value", avs_dx_adios%y_adios)
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, npoin, &
+                                   "points/z_value", avs_dx_adios%z_adios)
 
-  call adios_set_path(adios_handle, "points/y_value", ierr)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      npoin, sizeprocs)
-  call adios_write(adios_handle, "array", avs_dx_adios%y_adios, ierr)
 
-  call adios_set_path(adios_handle, "points/z_value", ierr)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      npoin, sizeprocs)
-  call adios_write(adios_handle, "array", avs_dx_adios%z_adios, ierr)
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, nspec, &
+                                   "elements/idoubling",                   &
+                                   avs_dx_adios%idoubling)
 
-
-  call adios_set_path(adios_handle, "elements/idoubling", ierr)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      nspec, sizeprocs)
-  call adios_write(adios_handle, "array", avs_dx_adios%idoubling, ierr)
-
-
-  call adios_set_path(adios_handle, "elements/num_ibool_AVS_DX_iglob1", ierr)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      nspec, sizeprocs)
-  call adios_write(adios_handle, "array", avs_dx_adios%iglob1, ierr)
-
-  call adios_set_path(adios_handle, "elements/num_ibool_AVS_DX_iglob2", ierr)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      nspec, sizeprocs)
-  call adios_write(adios_handle, "array", avs_dx_adios%iglob2, ierr)
-
-  call adios_set_path(adios_handle, "elements/num_ibool_AVS_DX_iglob3", ierr)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      nspec, sizeprocs)
-  call adios_write(adios_handle, "array", avs_dx_adios%iglob3, ierr)
-
-  call adios_set_path(adios_handle, "elements/num_ibool_AVS_DX_iglob4", ierr)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      nspec, sizeprocs)
-  call adios_write(adios_handle, "array", avs_dx_adios%iglob4, ierr)
-
-  call adios_set_path(adios_handle, "elements/num_ibool_AVS_DX_iglob5", ierr)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      nspec, sizeprocs)
-  call adios_write(adios_handle, "array", avs_dx_adios%iglob5, ierr)
-
-  call adios_set_path(adios_handle, "elements/num_ibool_AVS_DX_iglob6", ierr)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      nspec, sizeprocs)
-  call adios_write(adios_handle, "array", avs_dx_adios%iglob6, ierr)
-
-  call adios_set_path(adios_handle, "elements/num_ibool_AVS_DX_iglob7", ierr)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      nspec, sizeprocs)
-  call adios_write(adios_handle, "array", avs_dx_adios%iglob7, ierr)
-
-  call adios_set_path(adios_handle, "elements/num_ibool_AVS_DX_iglob1", ierr)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      nspec, sizeprocs)
-  call adios_write(adios_handle, "array", avs_dx_adios%iglob8, ierr)
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, nspec, &
+                                   "elements/num_ibool_AVS_DX_iglob1",     &
+                                   avs_dx_adios%iglob1)
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, nspec, &
+                                   "elements/num_ibool_AVS_DX_iglob2",     &
+                                   avs_dx_adios%iglob2)
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, nspec, &
+                                   "elements/num_ibool_AVS_DX_iglob3",     &
+                                   avs_dx_adios%iglob3)
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, nspec, &
+                                   "elements/num_ibool_AVS_DX_iglob4",     &
+                                   avs_dx_adios%iglob4)
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, nspec, &
+                                   "elements/num_ibool_AVS_DX_iglob5",     &
+                                   avs_dx_adios%iglob5)
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, nspec, &
+                                   "elements/num_ibool_AVS_DX_iglob6",     &
+                                   avs_dx_adios%iglob6)
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, nspec, &
+                                   "elements/num_ibool_AVS_DX_iglob7",     &
+                                   avs_dx_adios%iglob7)
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, nspec, &
+                                   "elements/num_ibool_AVS_DX_iglob8",     &
+                                   avs_dx_adios%iglob8)
 end subroutine write_AVS_DX_global_data_adios
 
 !===============================================================================

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/write_AVS_DX_global_faces_data_adios.f90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/write_AVS_DX_global_faces_data_adios.f90	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/write_AVS_DX_global_faces_data_adios.f90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -58,6 +58,7 @@
     group_size_inc, avs_dx_adios)
 
   use constants
+  use adios_helpers_mod
   use adios_write_mod
 
   implicit none
@@ -94,14 +95,14 @@
   integer num_ibool_AVS_DX(npointot)
 
   integer ispec
-  integer i,j,k,np
+  !integer i,j,k,np
   integer iglob1,iglob2,iglob3,iglob4,iglob5,iglob6,iglob7,iglob8
-  integer npoin,numpoin,nspecface,ispecface
+  integer npoin,nspecface !,ispecface,numpoin
 
-  double precision r,rho,vp,vs,Qkappa,Qmu
-  double precision vpv,vph,vsv,vsh,eta_aniso
-  double precision x,y,z,theta,phi_dummy,cost,p20,ell,factor
-  real(kind=CUSTOM_REAL) dvp,dvs
+  !double precision r,rho,vp,vs,Qkappa,Qmu
+  !double precision vpv,vph,vsv,vsh,eta_aniso
+  !double precision x,y,z,theta,phi_dummy,cost,p20,ell,factor
+  !real(kind=CUSTOM_REAL) dvp,dvs
 
 ! for ellipticity
   integer nspl
@@ -116,6 +117,10 @@
 
   integer :: ierr
 
+  ! Dummy arrays for type inference inside adios helpers
+  real(kind=4), dimension(1) :: dummy_real1d
+  integer(kind=4), dimension(1) :: dummy_int1d
+
   ! erase the logical mask used to mark points already found
   mask_ibool(:) = .false.
 
@@ -198,33 +203,38 @@
   if (ierr /= 0) call exit_MPI(myrank, "Error allocating iglob4.")
 
   !--- Variables for '...AVS_DXpointsfaces.txt'
-  call define_adios_global_real_1d_array(adios_group, "points_faces/x_value", &
-      npoin, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, "points_faces/y_value", &
-      npoin, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, "points_faces/z_value", &
-      npoin, group_size_inc)
+  call define_adios_global_array1D(adios_group, group_size_inc, npoin, &
+                                   "", "points_faces/x_value", dummy_real1d)
+  call define_adios_global_array1D(adios_group, group_size_inc, npoin, &
+                                   "", "points_faces/y_value", dummy_real1d)
+  call define_adios_global_array1D(adios_group, group_size_inc, npoin, &
+                                   "", "points_faces/z_value", dummy_real1d)
   !--- Variables for AVS_DXelementsfaces.txt
-  call define_adios_global_real_1d_array(adios_group, &
-      "elements_faces/idoubling", nspecface, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, &
-      "elements_faces/num_ibool_AVS_DX_iglob1", nspecface, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, &
-      "elements_faces/num_ibool_AVS_DX_iglob2", nspecface, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, &
-      "elements_faces/num_ibool_AVS_DX_iglob3", nspecface, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, &
-      "elements_faces/num_ibool_AVS_DX_iglob4", nspecface, group_size_inc)
+  call define_adios_global_array1D(adios_group, group_size_inc, nspecface, &
+                                  "", "elements_faces/idoubling", dummy_int1d)
 
+  call define_adios_global_array1D(adios_group, group_size_inc, nspecface,     &
+                                 "", "elements_faces/num_ibool_AVS_DX_iglob1", &
+                                   dummy_int1d)
+  call define_adios_global_array1D(adios_group, group_size_inc, nspecface,     &
+                                 "", "elements_faces/num_ibool_AVS_DX_iglob2", &
+                                   dummy_int1d)
+  call define_adios_global_array1D(adios_group, group_size_inc,nspecface,      &
+                                 "", "elements_faces/num_ibool_AVS_DX_iglob3", &
+                                   dummy_int1d)
+  call define_adios_global_array1D(adios_group, group_size_inc, nspecface,     &
+                                 "", "elements_faces/num_ibool_AVS_DX_iglob4", &
+                                   dummy_int1d)
+
   if(ISOTROPIC_3D_MANTLE) then
     allocate(avs_dx_adios%dvp(nspecface), stat=ierr)
     if (ierr /= 0) call exit_MPI(myrank, "Error allocating dvp.")
     allocate(avs_dx_adios%dvs(nspecface), stat=ierr)
     if (ierr /= 0) call exit_MPI(myrank, "Error allocating dvs.")
-    call define_adios_global_real_1d_array(adios_group, &
-        "elements_faces/dvp", dvp, group_size_inc)
-    call define_adios_global_real_1d_array(adios_group, &
-        "elements_faces/dvp", dvs, group_size_inc)
+    call define_adios_global_array1D(adios_group, group_size_inc, nspecface, &
+                                     "", "elements_faces/dvp", dummy_real1d)
+    call define_adios_global_array1D(adios_group, group_size_inc, nspecface, &
+                                     "", "elements_faces/dvs", dummy_real1d)
   endif
 
 end subroutine define_AVS_DX_global_faces_data_adios
@@ -539,24 +549,7 @@
       iglob6=ibool(NGLLX,1,NGLLZ,ispec)
       iglob7=ibool(NGLLX,NGLLY,NGLLZ,ispec)
       iglob8=ibool(1,NGLLY,NGLLZ,ispec)
-if (iglob1 > npointot) print *, myrank, "problem with iglob1", iglob1, npointot
-if (iglob2 > npointot) print *, myrank, "problem with iglob2", iglob2, npointot
-if (iglob3 > npointot) print *, myrank, "problem with iglob3", iglob3, npointot
-if (iglob4 > npointot) print *, myrank, "problem with iglob4", iglob4, npointot
-if (iglob5 > npointot) print *, myrank, "problem with iglob5", iglob5, npointot
-if (iglob6 > npointot) print *, myrank, "problem with iglob6", iglob6, npointot
-if (iglob7 > npointot) print *, myrank, "problem with iglob7", iglob7, npointot
-if (iglob8 > npointot) print *, myrank, "problem with iglob8", iglob8, npointot
 
-if (iglob1 < 0) print *, myrank, "problem with iglob1", iglob1, npointot
-if (iglob2 < 0) print *, myrank, "problem with iglob2", iglob2, npointot
-if (iglob3 < 0) print *, myrank, "problem with iglob3", iglob3, npointot
-if (iglob4 < 0) print *, myrank, "problem with iglob4", iglob4, npointot
-if (iglob5 < 0) print *, myrank, "problem with iglob5", iglob5, npointot
-if (iglob6 < 0) print *, myrank, "problem with iglob6", iglob6, npointot
-if (iglob7 < 0) print *, myrank, "problem with iglob7", iglob7, npointot
-if (iglob8 < 0) print *, myrank, "problem with iglob8", iglob8, npointot
-
       ! include lateral variations if needed
       if(ISOTROPIC_3D_MANTLE) then
         ! pick a point within the element and get its radius
@@ -701,6 +694,7 @@
     sizeprocs, avs_dx_adios, ISOTROPIC_3D_MANTLE)
 
   use adios_write_mod
+  use adios_helpers_mod
   implicit none
   !--- Arguments
   integer(kind=8), intent(in) :: adios_handle
@@ -709,67 +703,41 @@
   logical ISOTROPIC_3D_MANTLE
   !--- Variables
   integer :: npoin, nspec
-  integer :: ierr
 
   npoin = avs_dx_adios%npoin
   nspec = avs_dx_adios%nspecface
 
-  call adios_set_path(adios_handle, "points_faces/x_value", ierr)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      npoin, sizeprocs)
-  call adios_write(adios_handle, "array", avs_dx_adios%x_adios, ierr)
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, npoin, &
+                                   "points_faces/x_value", avs_dx_adios%x_adios)
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, npoin, &
+                                   "points_faces/y_value", avs_dx_adios%y_adios)
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, npoin, &
+                                   "points_faces/z_value", avs_dx_adios%z_adios)
 
-  call adios_set_path(adios_handle, "points_faces/y_value", ierr)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      npoin, sizeprocs)
-  call adios_write(adios_handle, "array", avs_dx_adios%y_adios, ierr)
 
-  call adios_set_path(adios_handle, "points_faces/z_value", ierr)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      npoin, sizeprocs)
-  call adios_write(adios_handle, "array", avs_dx_adios%z_adios, ierr)
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, nspec, &
+                                 "elements_faces/idoubling",               &
+                                   avs_dx_adios%idoubling)
 
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, nspec, &
+                                 "elements_faces/num_ibool_AVS_DX_iglob1", &
+                                   avs_dx_adios%iglob1)
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, nspec, &
+                                 "elements_faces/num_ibool_AVS_DX_iglob2", &
+                                   avs_dx_adios%iglob2)
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, nspec, &
+                                 "elements_faces/num_ibool_AVS_DX_iglob3", &
+                                   avs_dx_adios%iglob3)
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, nspec, &
+                                 "elements_faces/num_ibool_AVS_DX_iglob4", &
+                                   avs_dx_adios%iglob4)
 
-  call adios_set_path(adios_handle, "elements_faces/idoubling", ierr)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      nspec, sizeprocs)
-  call adios_write(adios_handle, "array", avs_dx_adios%idoubling, ierr)
 
-
-  call adios_set_path(adios_handle, &
-      "elements_faces/num_ibool_AVS_DX_iglob1", ierr)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      nspec, sizeprocs)
-  call adios_write(adios_handle, "array", avs_dx_adios%iglob1, ierr)
-
-  call adios_set_path(adios_handle, &
-      "elements_faces/num_ibool_AVS_DX_iglob2", ierr)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      nspec, sizeprocs)
-  call adios_write(adios_handle, "array", avs_dx_adios%iglob2, ierr)
-
-  call adios_set_path(adios_handle, &
-      "elements_faces/num_ibool_AVS_DX_iglob3", ierr)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      nspec, sizeprocs)
-  call adios_write(adios_handle, "array", avs_dx_adios%iglob3, ierr)
-
-  call adios_set_path(adios_handle, &
-      "elements_faces/num_ibool_AVS_DX_iglob4", ierr)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      nspec, sizeprocs)
-  call adios_write(adios_handle, "array", avs_dx_adios%iglob4, ierr)
-
-
   if(ISOTROPIC_3D_MANTLE) then
-    call adios_set_path(adios_handle, "elements_faces/dvp", ierr)
-    call write_1D_global_array_adios_dims(adios_handle, myrank, &
-        nspec, sizeprocs)
-    call adios_write(adios_handle, "array", avs_dx_adios%dvp, ierr)
-    call adios_set_path(adios_handle, "elements_faces/dvs", ierr)
-    call write_1D_global_array_adios_dims(adios_handle, myrank, &
-        nspec, sizeprocs)
-    call adios_write(adios_handle, "array", avs_dx_adios%dvs, ierr)
+    call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, nspec, &
+                                     "elements_faces/dvp", avs_dx_adios%dvp)
+    call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, nspec, &
+                                     "elements_faces/dvs", avs_dx_adios%dvs)
   endif
 
 end subroutine write_AVS_DX_global_faces_data_adios

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/write_AVS_DX_surface_data_adios.f90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/write_AVS_DX_surface_data_adios.f90	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/meshfem3D/write_AVS_DX_surface_data_adios.f90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -53,6 +53,7 @@
 
   use constants
   use adios_write_mod
+  use adios_helpers_mod
 
   implicit none
 
@@ -70,10 +71,10 @@
   double precision RICB,RCMB,RTOPDDOUBLEPRIME,R600,R670,R220,R771, &
        R400,R120,R80,RMOHO,RMIDDLE_CRUST,ROCEAN
 
-  double precision r,rho,vp,vs,Qkappa,Qmu
-  double precision vpv,vph,vsv,vsh,eta_aniso
-  double precision x,y,z,theta,phi_dummy,cost,p20,ell,factor
-  real(kind=CUSTOM_REAL) dvp,dvs
+  !double precision r,rho,vp,vs,Qkappa,Qmu
+  !double precision vpv,vph,vsv,vsh,eta_aniso
+  !double precision x,y,z,theta,phi_dummy,cost,p20,ell,factor
+  !real(kind=CUSTOM_REAL) dvp,dvs
 
   double precision xstore(NGLLX,NGLLY,NGLLZ,nspec)
   double precision ystore(NGLLX,NGLLY,NGLLZ,nspec)
@@ -91,9 +92,9 @@
   integer num_ibool_AVS_DX(npointot)
 
   integer ispec
-  integer i,j,k,np
+  !integer i,j,k,np
   integer, dimension(8) :: iglobval
-  integer npoin,numpoin,nspecface,ispecface
+  integer npoin,nspecface !,ispecface,numpoin
 
 ! for ellipticity
   integer nspl
@@ -108,6 +109,10 @@
 
   integer :: ierr
 
+  ! Dummy arrays for type inference inside adios helpers
+  real(kind=4),    dimension(1) :: dummy_real1d
+  integer(kind=4), dimension(1) :: dummy_int1d
+
   ! erase the logical mask used to mark points already found
   mask_ibool(:) = .false.
 
@@ -158,39 +163,47 @@
   if (ierr /= 0) call exit_MPI(myrank, "Error allocating iglob4.")
 
   !--- Variables for '...AVS_DXpointschunk.txt'
-  call define_adios_global_real_1d_array(adios_group, &
-      "points_surfaces/x_value", npoin, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, &
-      "points_surfaces/y_value", npoin, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, &
-      "points_surfaces/z_value", npoin, group_size_inc)
-  !--- Variables for AVS_DXelementschunks.txt
-  call define_adios_global_real_1d_array(adios_group, &
-      "elements_surfaces/idoubling", nspecface, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, &
-      "elements_surfaces/num_ibool_AVS_DX_iglob1", nspecface, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, &
-      "elements_surfaces/num_ibool_AVS_DX_iglob2", nspecface, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, &
-      "elements_surfaces/num_ibool_AVS_DX_iglob3", nspecface, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, &
-      "elements_surfaces/num_ibool_AVS_DX_iglob4", nspecface, group_size_inc)
+  call define_adios_global_array1D(adios_group, group_size_inc, npoin, &
+                                   "", "points_surfaces/x_value", dummy_real1d)
+  call define_adios_global_array1D(adios_group, group_size_inc, npoin, &
+                                   "", "points_surfaces/y_value", dummy_real1d)
+  call define_adios_global_array1D(adios_group, group_size_inc, npoin, &
+                                   "", "points_surfaces/z_value", dummy_real1d)
 
+  !--- Variables for '...AVS_DXpointschunk.txt'
+  call define_adios_global_array1D(adios_group, group_size_inc, nspecface, &
+                                   "", "elements_surfaces/idoubling",      &
+                                   dummy_int1d)
+
+  call define_adios_global_array1D(adios_group, group_size_inc, nspecface,     &
+                              "", "elements_surfaces/num_ibool_AVS_DX_iglob1", &
+                                   dummy_int1d)
+  call define_adios_global_array1D(adios_group, group_size_inc, nspecface,     &
+                              "", "elements_surfaces/num_ibool_AVS_DX_iglob2", &
+                                   dummy_int1d)
+  call define_adios_global_array1D(adios_group, group_size_inc, nspecface,     &
+                              "", "elements_surfaces/num_ibool_AVS_DX_iglob3", &
+                                   dummy_int1d)
+  call define_adios_global_array1D(adios_group, group_size_inc, nspecface,     &
+                              "", "elements_surfaces/num_ibool_AVS_DX_iglob4", &
+                                   dummy_int1d)
+
   !--- Variables for AVS_DXelementschunks_dvp_dvs.txt
   if(ISOTROPIC_3D_MANTLE) then
     allocate(avs_dx_adios%dvp(nspecface), stat=ierr)
     if (ierr /= 0) call exit_MPI(myrank, "Error allocating dvp.")
     allocate(avs_dx_adios%dvs(nspecface), stat=ierr)
     if (ierr /= 0) call exit_MPI(myrank, "Error allocating dvs.")
-    call define_adios_global_real_1d_array(adios_group, &
-        "elements_surfaces/dvp", dvp, group_size_inc)
-    call define_adios_global_real_1d_array(adios_group, &
-        "elements_surfaces/dvp", dvs, group_size_inc)
+    call define_adios_global_array1D(adios_group, group_size_inc, nspecface, &
+                                     "", "elements_surfaces/dvp", dummy_real1d)
+    call define_adios_global_array1D(adios_group, group_size_inc, nspecface, &
+                                     "", "elements_surfaces/dvs", dummy_real1d)
   endif
 
 end subroutine define_AVS_DX_surfaces_data_adios
 
 !===============================================================================
+
 subroutine prepare_AVS_DX_surfaces_data_adios(myrank,prname,nspec,iboun, &
     ibool,idoubling,xstore,ystore,zstore,num_ibool_AVS_DX,mask_ibool,npointot,&
     rhostore,kappavstore,muvstore,nspl,rspl,espl,espl2, &
@@ -442,16 +455,17 @@
 
   ! check that number of surface elements output is okay
   if(ispecface /= nspecface) &
-      call exit_MPI(myrank,'&
-          incorrect number of surface elements in AVS or DX file creation')
+      call exit_MPI(myrank,'incorrect number of surface elements in AVS or DX file creation')
 
 end subroutine prepare_AVS_DX_surfaces_data_adios
 
 !===============================================================================
+
 subroutine write_AVS_DX_surfaces_data_adios(adios_handle, myrank, &
     sizeprocs, avs_dx_adios, ISOTROPIC_3D_MANTLE)
 
   use adios_write_mod
+  use adios_helpers_mod
   implicit none
   !--- Arguments
   integer(kind=8), intent(in) :: adios_handle
@@ -460,68 +474,46 @@
   logical ISOTROPIC_3D_MANTLE
   !--- Variables
   integer :: npoin, nspec
-  integer :: ierr
 
   npoin = avs_dx_adios%npoin
   nspec = avs_dx_adios%nspecface
 
-  call adios_set_path(adios_handle, "points_surfaces/x_value", ierr)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      npoin, sizeprocs)
-  call adios_write(adios_handle, "array", avs_dx_adios%x_adios, ierr)
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, npoin, &
+                                   "points_surfaces/x_value",              &
+                                   avs_dx_adios%x_adios)
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, npoin, &
+                                   "points_surfaces/y_value",              &
+                                   avs_dx_adios%y_adios)
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, npoin, &
+                                   "points_surfaces/z_value",              &
+                                   avs_dx_adios%z_adios)
 
-  call adios_set_path(adios_handle, "points_surfaces/y_value", ierr)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      npoin, sizeprocs)
-  call adios_write(adios_handle, "array", avs_dx_adios%y_adios, ierr)
 
-  call adios_set_path(adios_handle, "points_surfaces/z_value", ierr)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      npoin, sizeprocs)
-  call adios_write(adios_handle, "array", avs_dx_adios%z_adios, ierr)
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, nspec, &
+                                 "elements_surfaces/idoubling",            &
+                                   avs_dx_adios%idoubling)
 
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, nspec,    &
+                                 "elements_surfaces/num_ibool_AVS_DX_iglob1", &
+                                   avs_dx_adios%iglob1)
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, nspec,    &
+                                 "elements_surfaces/num_ibool_AVS_DX_iglob2", &
+                                   avs_dx_adios%iglob2)
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, nspec,    &
+                                 "elements_surfaces/num_ibool_AVS_DX_iglob3", &
+                                   avs_dx_adios%iglob3)
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, nspec,    &
+                                 "elements_surfaces/num_ibool_AVS_DX_iglob4", &
+                                   avs_dx_adios%iglob4)
 
-  call adios_set_path(adios_handle, "elements_surfaces/idoubling", ierr)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      nspec, sizeprocs)
-  call adios_write(adios_handle, "array", avs_dx_adios%idoubling, ierr)
 
-
-  call adios_set_path(adios_handle, &
-      "elements_surfaces/num_ibool_AVS_DX_iglob1", ierr)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      nspec, sizeprocs)
-  call adios_write(adios_handle, "array", avs_dx_adios%iglob1, ierr)
-
-  call adios_set_path(adios_handle, &
-      "elements_surfaces/num_ibool_AVS_DX_iglob2", ierr)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      nspec, sizeprocs)
-  call adios_write(adios_handle, "array", avs_dx_adios%iglob2, ierr)
-
-  call adios_set_path(adios_handle, &
-      "elements_surfaces/num_ibool_AVS_DX_iglob3", ierr)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      nspec, sizeprocs)
-  call adios_write(adios_handle, "array", avs_dx_adios%iglob3, ierr)
-
-  call adios_set_path(adios_handle, &
-      "elements_surfaces/num_ibool_AVS_DX_iglob4", ierr)
-  call write_1D_global_array_adios_dims(adios_handle, myrank, &
-      nspec, sizeprocs)
-  call adios_write(adios_handle, "array", avs_dx_adios%iglob4, ierr)
-
-
   if(ISOTROPIC_3D_MANTLE) then
-    call adios_set_path(adios_handle, "elements_surfaces/dvp", ierr)
-    call write_1D_global_array_adios_dims(adios_handle, myrank, &
-        nspec, sizeprocs)
-    call adios_write(adios_handle, "array", avs_dx_adios%dvp, ierr)
-    call adios_set_path(adios_handle, "elements_surfaces/dvs", ierr)
-    call write_1D_global_array_adios_dims(adios_handle, myrank, &
-        nspec, sizeprocs)
-    call adios_write(adios_handle, "array", avs_dx_adios%dvs, ierr)
+    call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, nspec, &
+                                     "elements_surfaces/dvp", avs_dx_adios%dvp)
+    call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, nspec, &
+                                     "elements_surfaces/dvs", avs_dx_adios%dvs)
   endif
+
 end subroutine write_AVS_DX_surfaces_data_adios
 
 !===============================================================================

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/src/shared/adios_helpers.f90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/shared/adios_helpers.f90	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/shared/adios_helpers.f90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -26,12 +26,44 @@
 !=====================================================================
 
 
-!-------------------------------------------------------------------------------
-!> \file adios_helpers.f90
-!! \brief Helpers to set up adios features.
+!===============================================================================
+!> 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.
@@ -43,314 +75,9 @@
 
   if (adios_err /= 0) then
     call adios_errmsg(msg)
-    print *, "process: ", myrank, ", error: ", msg
-    stop
+    print *, "process: ", myrank, ", error: ", trim(msg)
+    stop 'adios error'
   endif
 end subroutine check_adios_err
 
-
-!===============================================================================
-!> 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 name The variable to be defined
-!! \param path The logical path structuring the data and containing
-!!             the variable
-!! \param group_size_inc The inout adios group size to increment
-!!                       with the size of the variable
-subroutine define_adios_double_scalar (adios_group, name, path, group_size_inc)
-  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
-  ! 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 integer variable and autoincrement the adios
-!! group size by (4).
-!! \param adios_group The adios group where the variables belongs
-!! \param name The variable to be defined
-!! \param path The logical path structuring the data and containing
-!!             the variable
-!! \param group_size_inc The inout adios group size to increment
-!!                       with the size of the variable
-subroutine define_adios_integer_scalar (adios_group, name, path, group_size_inc)
-  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
-  ! 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 name The variable to be defined
-!! \param path The logical path structuring the data and containing
-!!             the variable
-!! \param group_size_inc The inout adios group size to increment
-!!                       with the size of the variable
-subroutine define_adios_byte_scalar (adios_group, name, path, group_size_inc)
-  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
-  ! 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 a local ADIOS array of integers and autoincrement the adios
-!! group size by (4 * number of elements).
-!! \param adios_group The adios group where the variables belongs
-!! \param name The variable to be defined
-!! \param path The logical path structuring the data and containing
-!!             the variable
-!! \param dim The number of elements in the 1D array. Required to
-!!            correctly increment adios group size.
-!! \param dim_str The "stringified" version of dim. Needed by adios
-!!                to define variables
-!! \param group_size_inc The inout adios group size to increment
-!!                       with the size of the variable
-subroutine define_adios_integer_local_array1D (adios_group, name, path, dim, dim_str, group_size_inc)
-  use adios_write_mod
-  implicit none
-  ! Arguments
-  integer(kind=8),  intent(in)     :: adios_group
-  character(len=*), intent(in)     :: name, path, dim_str
-  integer(kind=8),  intent(inout)  :: group_size_inc
-  integer, intent(in)              :: dim
-  ! Local Variables
-  integer(kind=8)                  :: varid ! dummy variable, adios use var name
-
-  ! adios: 2 == integer
-  call adios_define_var (adios_group, name, path, 2,  dim_str, "", "", varid)
-  group_size_inc = group_size_inc + 4*dim
-end subroutine define_adios_integer_local_array1D
-
-!===============================================================================
-!> Define a local ADIOS array of doubles and autoincrement the adios
-!! group size by (8 * number of elements).
-!! \param adios_group The adios group where the variables belongs
-!! \param name The variable to be defined
-!! \param path The logical path structuring the data and containing
-!!             the variable
-!! \param dim The number of elements in the 1D array. Required to
-!!            correctly increment adios group size.
-!! \param dim_str The "stringified" version of dim. Needed by adios
-!!                to define variables
-!! \param group_size_inc The inout adios group size to increment
-!!                       with the size of the variable
-subroutine define_adios_double_local_array1D (adios_group, name, path, dim, dim_str, group_size_inc)
-  use adios_write_mod
-  implicit none
-  ! Arguments
-  integer(kind=8),  intent(in)     :: adios_group
-  character(len=*), intent(in)     :: name, path, dim_str
-  integer(kind=8),  intent(inout)  :: group_size_inc
-  integer, intent(in)              :: dim
-  ! 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, dim_str, "", "", varid)
-  group_size_inc = group_size_inc + 8*dim
-end subroutine define_adios_double_local_array1D
-
-!===============================================================================
-!> Define a local ADIOS string and autoincrement the adios
-!! group size by (1 * string's length).
-!! \param adios_group The adios group where the variables belongs
-!! \param name The variable to be defined
-!! \param path The logical path structuring the data and containing
-!!             the variable
-!! \param len The length of the string(number of character. in Fortran
-!!            it does not include a final '\0' -- null -- character)
-!! \param group_size_inc The inout adios group size to increment
-!!                       with the size of the variable
-!! \note Adios string are scalar values counting for (1) byte. It is
-!!       mandatory to increase the group size by the length of the
-!!       string in order not to overlap 'data regions'.
-subroutine define_adios_string (adios_group, name, path, length, group_size_inc)
-  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                          :: length
-  ! Local Variables
-  integer(kind=8)                  :: varid ! dummy variable, adios use var name
-
-  ! adios: 9 == string
-  call adios_define_var (adios_group, name, path, 9,  "", "", "", varid)
-  group_size_inc = group_size_inc + 1*length
-end subroutine define_adios_string
-
-!===============================================================================
-!> Define a global ADIOS 1D real array and autoincrement the adios
-!! group size.
-!! \param adios_group The adios group where the variables belongs
-!! \param array_name The variable to be defined. This is actually the path for
-!!                   ADIOS. The values are stored in array_name/array
-!! \param len The local dimension of the array.
-!! \param group_size_inc The inout adios group size to increment
-!!                       with the size of the variable
-!! \note This function define local, global and offset sizes as well as the
-!!       array to store the values in.
-subroutine define_adios_global_real_1d_array(adios_group, array_name, &
-    local_dim, group_size_inc)
-  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
-
-  call define_adios_integer_scalar (adios_group, "local_dim", array_name, &
-      group_size_inc)
-  call define_adios_integer_scalar (adios_group, "global_dim", array_name, &
-      group_size_inc)
-  call define_adios_integer_scalar (adios_group, "offset", array_name, &
-      group_size_inc)
-!  call adios_define_var(adios_group, "array", array_name, 6, &
-!      "local_dim", "global_dim", "offset", var_id)
-  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_real_1d_array
-
-!===============================================================================
-!> Define a global ADIOS 1D integer array and autoincrement the adios
-!! group size.
-!! \param adios_group The adios group where the variables belongs
-!! \param array_name The variable to be defined. This is actually the path for
-!!                   ADIOS. The values are stored in array_name/array
-!! \param len The local dimension of the array.
-!! \param group_size_inc The inout adios group size to increment
-!!                       with the size of the variable
-!! \note This function define local, global and offset sizes as well as the
-!!       array to store the values in.
-subroutine define_adios_global_integer_1d_array(adios_group, array_name, &
-    local_dim, group_size_inc)
-  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
-
-  call define_adios_integer_scalar (adios_group, "local_dim", array_name, &
-      group_size_inc)
-  call define_adios_integer_scalar (adios_group, "global_dim", array_name, &
-      group_size_inc)
-  call define_adios_integer_scalar (adios_group, "offset", array_name, &
-      group_size_inc)
-!  call adios_define_var(adios_group, "array", array_name, 6, &
-!      "local_dim", "global_dim", "offset", var_id)
-  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_integer_1d_array
-
-!===============================================================================
-!> Define a global ADIOS 1D logical array and autoincrement the adios
-!! group size.
-!! \param adios_group The adios group where the variables belongs
-!! \param array_name The variable to be defined. This is actually the path for
-!!                   ADIOS. The values are stored in array_name/array
-!! \param len The local dimension of the array.
-!! \param group_size_inc The inout adios group size to increment
-!!                       with the size of the variable
-!! \note This function define local, global and offset sizes as well as the
-!!       array to store the values in.
-subroutine define_adios_global_logical_1d_array(adios_group, array_name, &
-    local_dim, group_size_inc)
-  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
-
-  call define_adios_integer_scalar (adios_group, "local_dim", array_name, &
-      group_size_inc)
-  call define_adios_integer_scalar (adios_group, "global_dim", array_name, &
-      group_size_inc)
-  call define_adios_integer_scalar (adios_group, "offset", array_name, &
-      group_size_inc)
-!  call adios_define_var(adios_group, "array", array_name, 6, &
-!      "local_dim", "global_dim", "offset", var_id)
-  call adios_define_var(adios_group, "array", array_name, 1, &
-      array_name // "/local_dim", array_name // "/global_dim", &
-      array_name // "/offset", var_id)
-  group_size_inc = group_size_inc + local_dim*1
-end subroutine define_adios_global_logical_1d_array
-
-!===============================================================================
-!> Define a global ADIOS 1D real array and autoincrement the adios
-!! group size.
-!! \param adios_group The adios group where the variables belongs
-!! \param array_name The variable to be defined. This is actually the path for
-!!                   ADIOS. The values are stored in array_name/array
-!! \param len The local dimension of the array.
-!! \param group_size_inc The inout adios group size to increment
-!!                       with the size of the variable
-!! \note This function define local, global and offset sizes as well as the
-!!       array to store the values in.
-subroutine define_adios_global_double_1d_array(adios_group, array_name, &
-    local_dim, group_size_inc)
-  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
-
-  call define_adios_integer_scalar (adios_group, "local_dim", array_name, &
-      group_size_inc)
-  call define_adios_integer_scalar (adios_group, "global_dim", array_name, &
-      group_size_inc)
-  call define_adios_integer_scalar (adios_group, "offset", array_name, &
-      group_size_inc)
-  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_double_1d_array
+end module adios_helpers_mod

Added: seismo/3D/SPECFEM3D_GLOBE/trunk/src/shared/adios_helpers_definitions.f90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/shared/adios_helpers_definitions.f90	                        (rev 0)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/shared/adios_helpers_definitions.f90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -0,0 +1,1274 @@
+!=====================================================================
+!
+!          S p e c f e m 3 D  G l o b e  V e r s i o n  6 . 0
+!          --------------------------------------------------
+!
+!          Main authors: Dimitri Komatitsch and Jeroen Tromp
+!                        Princeton University, USA
+!             and CNRS / INRIA / University of Pau, France
+! (c) Princeton University and CNRS / INRIA / University of Pau
+!                            August 2013
+!
+! This 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, trim(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, trim(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
+  ! Local vars
+  !character(len=256) :: full_name
+
+  !full_name = trim(path) // trim(name)
+
+  ! adios: 2 ~ integer(kind=4)
+  call adios_define_var (adios_group, name, trim(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, trim(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, trim(array_name), "local_dim", local_dim)
+  call define_adios_integer_scalar (adios_group, group_size_inc, trim(array_name), "global_dim", local_dim)
+  call define_adios_integer_scalar (adios_group, group_size_inc, trim(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, trim(array_name),local_dim)
+
+  call adios_define_var(adios_group, "array", trim(array_name), 5, &
+      trim(array_name) // "/local_dim", array_name // "/global_dim", &
+      trim(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
+  ! Local vars
+  character(len=256) :: full_name
+
+  full_name = trim(path) // trim(array_name)
+
+  call define_adios_global_1d_real_generic(adios_group, group_size_inc, trim(full_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
+  ! Local vars
+  character(len=256) :: full_name
+
+  full_name = trim(path) // trim(array_name)
+
+  call define_adios_global_1d_real_generic(adios_group, group_size_inc, trim(full_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
+  ! Local vars
+  character(len=256) :: full_name
+
+  full_name = trim(path) // trim(array_name)
+
+  call define_adios_global_1d_real_generic(adios_group, group_size_inc, trim(full_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
+  ! Local vars
+  character(len=256) :: full_name
+
+  full_name = trim(path) // trim(array_name)
+
+  call define_adios_global_1d_real_generic(adios_group, group_size_inc, trim(full_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
+  ! Local vars
+  character(len=256) :: full_name
+
+  full_name = trim(path) // trim(array_name)
+
+  call define_adios_global_1d_real_generic(adios_group, group_size_inc, trim(full_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, trim(array_name), local_dim)
+
+  call adios_define_var(adios_group, "array", trim(array_name), 6, &
+      trim(array_name) // "/local_dim", array_name // "/global_dim", &
+      trim(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
+  ! Local vars
+  character(len=256) :: full_name
+
+  full_name = trim(path) // trim(array_name)
+
+  call define_adios_global_1d_double_generic(adios_group, group_size_inc, trim(full_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
+  ! Local vars
+  character(len=256) :: full_name
+
+  full_name = trim(path) // trim(array_name)
+
+  call define_adios_global_1d_double_generic(adios_group, group_size_inc, trim(full_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
+  ! Local vars
+  character(len=256) :: full_name
+
+  full_name = trim(path) // trim(array_name)
+
+  call define_adios_global_1d_double_generic(adios_group, group_size_inc, trim(full_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
+  ! Local vars
+  character(len=256) :: full_name
+
+  full_name = trim(path) // trim(array_name)
+
+  call define_adios_global_1d_double_generic(adios_group, group_size_inc, trim(full_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
+  ! Local vars
+  character(len=256) :: full_name
+
+  full_name = trim(path) // trim(array_name)
+
+  call define_adios_global_1d_double_generic(adios_group, group_size_inc, trim(full_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, trim(array_name), local_dim)
+
+  call adios_define_var(adios_group, "array", trim(array_name), 2, &
+      trim(array_name) // "/local_dim", array_name // "/global_dim", &
+      trim(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
+  ! Local vars
+  character(len=256) :: full_name
+
+  full_name = trim(path) // trim(array_name)
+
+  call define_adios_global_1d_int_generic(adios_group, group_size_inc, trim(full_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
+  ! Local vars
+  character(len=256) :: full_name
+
+  full_name = trim(path) // trim(array_name)
+
+  call define_adios_global_1d_int_generic(adios_group, group_size_inc, trim(full_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
+  ! Local vars
+  character(len=256) :: full_name
+
+  full_name = trim(path) // trim(array_name)
+
+  call define_adios_global_1d_int_generic(adios_group, group_size_inc, trim(full_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
+  ! Local vars
+  character(len=256) :: full_name
+
+  full_name = trim(path) // trim(array_name)
+
+  call define_adios_global_1d_int_generic(adios_group, group_size_inc, trim(full_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
+  ! Local vars
+  character(len=256) :: full_name
+
+  full_name = trim(path) // trim(array_name)
+
+  call define_adios_global_1d_int_generic(adios_group, group_size_inc, trim(full_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, trim(array_name), local_dim)
+
+  call adios_define_var(adios_group, "array", trim(array_name), adios_long, &
+      trim(array_name) // "/local_dim", array_name // "/global_dim", &
+      trim(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
+  ! Local vars
+  character(len=256) :: full_name
+
+  full_name = trim(path) // trim(array_name)
+
+  call define_adios_global_1d_long_generic(adios_group, group_size_inc, trim(full_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
+  ! Local vars
+  character(len=256) :: full_name
+
+  full_name = trim(path) // trim(array_name)
+
+  call define_adios_global_1d_long_generic(adios_group, group_size_inc, trim(full_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
+  ! Local vars
+  character(len=256) :: full_name
+
+  full_name = trim(path) // trim(array_name)
+
+  call define_adios_global_1d_long_generic(adios_group, group_size_inc, trim(full_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
+  ! Local vars
+  character(len=256) :: full_name
+
+  full_name = trim(path) // trim(array_name)
+
+  call define_adios_global_1d_long_generic(adios_group, group_size_inc, trim(full_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
+  ! Local vars
+  character(len=256) :: full_name
+
+  full_name = trim(path) // trim(array_name)
+
+  call define_adios_global_1d_long_generic(adios_group, group_size_inc, trim(full_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", trim(array_name), 2, &
+      trim(array_name) // "/local_dim", array_name // "/global_dim", &
+      trim(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
+  ! Local vars
+  character(len=256) :: full_name
+
+  full_name = trim(path) // trim(array_name)
+
+  call define_adios_global_1d_logical_generic(adios_group, group_size_inc, trim(full_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
+  ! Local vars
+  character(len=256) :: full_name
+
+  full_name = trim(path) // trim(array_name)
+
+  call define_adios_global_1d_logical_generic(adios_group, group_size_inc, trim(full_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
+  ! Local vars
+  character(len=256) :: full_name
+
+  full_name = trim(path) // trim(array_name)
+
+  call define_adios_global_1d_logical_generic(adios_group, group_size_inc, trim(full_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
+  ! Local vars
+  character(len=256) :: full_name
+
+  full_name = trim(path) // trim(array_name)
+
+  call define_adios_global_1d_logical_generic(adios_group, group_size_inc, trim(full_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
+  ! Local vars
+  character(len=256) :: full_name
+
+  full_name = trim(path) // trim(array_name)
+
+  call define_adios_global_1d_logical_generic(adios_group, group_size_inc, trim(full_name), local_dim)
+  
+end subroutine define_adios_global_1d_logical_5d
+
+end module adios_helpers_definitions_mod

Added: seismo/3D/SPECFEM3D_GLOBE/trunk/src/shared/adios_helpers_writers.f90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/shared/adios_helpers_writers.f90	                        (rev 0)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/shared/adios_helpers_writers.f90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -0,0 +1,906 @@
+!=====================================================================
+!
+!          S p e c f e m 3 D  G l o b e  V e r s i o n  6 . 0
+!          --------------------------------------------------
+!
+!          Main authors: Dimitri Komatitsch and Jeroen Tromp
+!                        Princeton University, USA
+!             and CNRS / INRIA / University of Pau, France
+! (c) Princeton University and CNRS / INRIA / University of Pau
+!                            August 2013
+!
+! This 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
+  character(len=1024) :: msg
+
+  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)
+  if (adios_err /= 0) then
+    call adios_errmsg(msg)
+    print *, "process: ", myrank, ", error: ", trim(msg)
+    stop 'adios error'
+  endif
+
+
+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

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/src/shared/adios_manager.F90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/shared/adios_manager.F90	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/shared/adios_manager.F90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -25,27 +25,51 @@
 !
 !=====================================================================
 
-!> @brief Initialize ADIOS and setup the xml output file
+!==============================================================================
+!> Tools to setup and cleanup ADIOS
+!------------------------------------------------------------------------------
+!module adios_manager_mod
+
+!contains
+
+!==============================================================================
+!> Initialize ADIOS and setup the xml output file
 subroutine adios_setup()
+
+  use constants,only : ADIOS_BUFFER_SIZE_IN_MB
+
   use adios_write_mod, only: adios_init
 
   implicit none
-  integer :: adios_err, sizeMB
 
-  call adios_init_noxml (adios_err);
-  sizeMB = 200 ! TODO 200MB is surely not the right size for the adios buffer
-  call adios_allocate_buffer (sizeMB , adios_err)
+  integer :: adios_err
+  integer :: comm
+
+  call world_get_comm(comm)
+
+  call adios_init_noxml (comm, adios_err);
+
+  !sizeMB = 200 ! TODO 200MB is surely not the right size for the adios buffer
+  !call adios_allocate_buffer (sizeMB , adios_err)
+  call adios_allocate_buffer (ADIOS_BUFFER_SIZE_IN_MB, adios_err)
+
 end subroutine adios_setup
 
-!> @brief Finalize ADIOS. Must be called once everything is written down.
+!==============================================================================
+!> 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
+  integer :: adios_err
 
-  call MPI_Comm_rank(MPI_COMM_WORLD, myrank, ierr)
+  call world_rank(myrank)
+  call synchronize_all()
+
   call adios_finalize (myrank, adios_err)
+
 end subroutine adios_cleanup
+
+!end module adios_manager_mod

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/src/shared/adios_method_stubs.f90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/shared/adios_method_stubs.f90	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/shared/adios_method_stubs.f90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -28,14 +28,41 @@
 
 ! placeholders for non-adios compilation
 
-! for xmeshfem3D compilation
+  subroutine warn_no_adios()
+    stop 'Trying to use ADIOS while not configured for it.'
+  end subroutine warn_no_adios
 
-  subroutine adios_cleanup()
-  end subroutine
+! modules
 
+!  module AVS_DX_global_mod
+!    type avs_dx_global_t
+!    end type avs_dx_global_t
+!  end module AVS_DX_global_mod
+
+!  module AVS_DX_global_faces_mod
+!    type avs_dx_global_faces_t
+!    end type avs_dx_global_faces_t
+!  end module AVS_DX_global_faces_mod
+
+!  module AVS_DX_global_chunks_mod
+!    type avs_dx_global_chunks_t
+!    end type avs_dx_global_chunks_t
+!  end module AVS_DX_global_chunks_mod
+
+!  module AVS_DX_surface_mod
+!    type avs_dx_surface_t
+!    end type avs_dx_surface_t
+!  end module AVS_DX_surface_mod
+
+! for both xmeshfem3D/xspecfem3D compilation
+
   subroutine adios_setup()
+  call warn_no_adios()
   end subroutine
 
+  subroutine adios_cleanup()
+  end subroutine
+
 ! for xmeshfem3D compilation
 
   subroutine crm_save_mesh_files_adios()
@@ -47,12 +74,63 @@
   subroutine save_arrays_solver_adios()
   end subroutine
 
+  subroutine save_arrays_solver_meshfiles_adios()
+  end subroutine
+
   subroutine save_arrays_solver_boundary_adios()
   end subroutine
 
-  subroutine save_mpi_arrays_adios()
+  subroutine save_MPI_arrays_adios()
   end subroutine
 
+  subroutine read_gll_model_adios
+  end subroutine
+  
+!  subroutine prepare_AVS_DX_global_chunks_data_adios()
+!  end subroutine
+!
+!  subroutine write_AVS_DX_global_chunks_data_adios()
+!  end subroutine
+!
+!  subroutine free_AVS_DX_global_chunks_data_adios()
+!  end subroutine
+!
+!  subroutine define_AVS_DX_global_data_adios()
+!  end subroutine
+!
+!  subroutine prepare_AVS_DX_global_data_adios()
+!  end subroutine
+!
+!  subroutine write_AVS_DX_global_data_adios()
+!  end subroutine
+!
+!  subroutine free_AVS_DX_global_data_adios()
+!  end subroutine
+!
+!  subroutine define_AVS_DX_global_faces_data_adios()
+!  end subroutine
+!
+!  subroutine prepare_AVS_DX_global_faces_data_adios()
+!  end subroutine
+!
+!  subroutine write_AVS_DX_global_faces_data_adios()
+!  end subroutine
+!
+!  subroutine free_AVS_DX_global_faces_data_adios()
+!  end subroutine
+!
+!  subroutine define_AVS_DX_surfaces_data_adios()
+!  end subroutine
+!
+!  subroutine prepare_AVS_DX_surfaces_data_adios()
+!  end subroutine
+!
+!  subroutine write_AVS_DX_surfaces_data_adios()
+!  end subroutine
+!
+!  subroutine free_AVS_DX_surfaces_data_adios()
+!  end subroutine
+!
 
 ! for xspecfem3D compilation
 
@@ -89,3 +167,53 @@
   subroutine save_intermediate_forward_arrays_adios()
   end subroutine
 
+!  subroutine define_common_forward_arrays_adios()
+!  end subroutine
+!
+!  subroutine define_rotation_forward_arrays_adios()
+!  end subroutine
+!
+!  subroutine define_attenuation_forward_arrays_adios()
+!  end subroutine
+!
+!  subroutine write_common_forward_arrays_adios()
+!  end subroutine
+!
+!  subroutine write_rotation_forward_arrays_adios()
+!  end subroutine
+!
+!  subroutine write_attenuation_forward_arrays_adios()
+!  end subroutine
+!
+!  subroutine write_1D_global_array_adios_dims()
+!  end subroutine
+!
+
+  subroutine perform_write_adios_kernels()
+  end subroutine
+
+  subroutine define_kernel_adios_variables()
+  end subroutine
+
+  subroutine write_kernels_crust_mantle_adios()
+  end subroutine
+
+  subroutine write_kernels_outer_core_adios()
+  end subroutine
+
+  subroutine write_kernels_inner_core_adios()
+  end subroutine
+
+  subroutine write_kernels_boundary_kl_adios()
+  end subroutine
+
+  subroutine write_kernels_source_derivatives_adios()
+  end subroutine
+
+  subroutine write_kernels_hessian_adios()
+  end subroutine
+
+!
+!  subroutine write_specfem_header_adios()
+!  end subroutine
+

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/src/shared/broadcast_computed_parameters.f90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/shared/broadcast_computed_parameters.f90	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/shared/broadcast_computed_parameters.f90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -39,7 +39,7 @@
   integer, parameter :: nparam_i = 44
   integer, dimension(nparam_i) :: bcast_integer
 
-  integer, parameter :: nparam_l = 54
+  integer, parameter :: nparam_l = 56
   logical, dimension(nparam_l) :: bcast_logical
 
   integer, parameter :: nparam_dp = 32
@@ -55,7 +55,8 @@
     ! funny way to pass parameters in arrays from master to all other processes
     ! rather than single values one by one to reduce MPI communication calls:
     ! sets up broadcasting array
-    bcast_integer = (/MIN_ATTENUATION_PERIOD,MAX_ATTENUATION_PERIOD,NER_CRUST, &
+    bcast_integer = (/ &
+            MIN_ATTENUATION_PERIOD,MAX_ATTENUATION_PERIOD,NER_CRUST, &
             NER_80_MOHO,NER_220_80,NER_400_220,NER_600_400,NER_670_600,NER_771_670, &
             NER_TOPDDOUBLEPRIME_771,NER_CMB_TOPDDOUBLEPRIME,NER_OUTER_CORE, &
             NER_TOP_CENTRAL_CUBE_ICB, &
@@ -73,9 +74,11 @@
             NEX_PER_PROC_XI,NEX_PER_PROC_ETA,ratio_divide_central_cube,&
             MOVIE_VOLUME_TYPE,MOVIE_START,MOVIE_STOP, &
             NOISE_TOMOGRAPHY, &
-            NT_DUMP_ATTENUATION,ATT1,ATT2,ATT3,ATT4,ATT5/)
+            NT_DUMP_ATTENUATION,ATT1,ATT2,ATT3,ATT4,ATT5 &
+            /)
 
-    bcast_logical = (/TRANSVERSE_ISOTROPY,ANISOTROPIC_3D_MANTLE,ANISOTROPIC_INNER_CORE, &
+    bcast_logical = (/ &
+            TRANSVERSE_ISOTROPY,ANISOTROPIC_3D_MANTLE,ANISOTROPIC_INNER_CORE, &
             CRUSTAL,ELLIPTICITY,GRAVITY,ONE_CRUST,ROTATION,ISOTROPIC_3D_MANTLE,HETEROGEN_3D_MANTLE, &
             TOPOGRAPHY,OCEANS,MOVIE_SURFACE,MOVIE_VOLUME,ATTENUATION_3D, &
             RECEIVERS_CAN_BE_BURIED,PRINT_SOURCE_TIME_FUNCTION, &
@@ -90,17 +93,22 @@
             USE_LDDRK,INCREASE_CFL_FOR_LDDRK, &
             ANISOTROPIC_KL,SAVE_TRANSVERSE_KL_ONLY,APPROXIMATE_HESS_KL, &
             USE_FULL_TISO_MANTLE,SAVE_SOURCE_MASK, &
+            EXACT_MASS_MATRIX_FOR_ROTATION,ATTENUATION_1D_WITH_3D_STORAGE, &            
             GPU_MODE, &
             ADIOS_ENABLED,ADIOS_FOR_FORWARD_ARRAYS, &
-            ADIOS_FOR_MPI_ARRAYS,ADIOS_FOR_ARRAYS_SOLVER,ADIOS_FOR_SOLVER_MESHFILES,ADIOS_FOR_AVS_DX,&
-            EXACT_MASS_MATRIX_FOR_ROTATION,ATTENUATION_1D_WITH_3D_STORAGE/)
+            ADIOS_FOR_MPI_ARRAYS,ADIOS_FOR_ARRAYS_SOLVER, &
+            ADIOS_FOR_SOLVER_MESHFILES,ADIOS_FOR_AVS_DX,&
+            ADIOS_FOR_KERNELS,ADIOS_FOR_MODELS &
+            /)
 
-    bcast_double_precision = (/DT,ANGULAR_WIDTH_XI_IN_DEGREES,ANGULAR_WIDTH_ETA_IN_DEGREES,CENTER_LONGITUDE_IN_DEGREES, &
+    bcast_double_precision = (/ &
+            DT,ANGULAR_WIDTH_XI_IN_DEGREES,ANGULAR_WIDTH_ETA_IN_DEGREES,CENTER_LONGITUDE_IN_DEGREES, &
             CENTER_LATITUDE_IN_DEGREES,GAMMA_ROTATION_AZIMUTH,ROCEAN,RMIDDLE_CRUST, &
             RMOHO,R80,R120,R220,R400,R600,R670,R771,RTOPDDOUBLEPRIME,RCMB,RICB, &
             R_CENTRAL_CUBE,RHO_TOP_OC,RHO_BOTTOM_OC,RHO_OCEANS,HDUR_MOVIE, &
             MOVIE_TOP,MOVIE_BOTTOM,MOVIE_WEST,MOVIE_EAST,MOVIE_NORTH,MOVIE_SOUTH,&
-            RMOHO_FICTITIOUS_IN_MESHER,RATIO_BY_WHICH_TO_INCREASE_IT /)
+            RMOHO_FICTITIOUS_IN_MESHER,RATIO_BY_WHICH_TO_INCREASE_IT &
+            /)
   endif
 
   ! broadcasts the information read on the master to the nodes
@@ -240,15 +248,17 @@
     APPROXIMATE_HESS_KL = bcast_logical(43)
     USE_FULL_TISO_MANTLE = bcast_logical(44)
     SAVE_SOURCE_MASK = bcast_logical(45)
-    GPU_MODE = bcast_logical(46)
-    ADIOS_ENABLED = bcast_logical(47)
-    ADIOS_FOR_FORWARD_ARRAYS = bcast_logical(48)
-    ADIOS_FOR_MPI_ARRAYS = bcast_logical(49)
-    ADIOS_FOR_ARRAYS_SOLVER = bcast_logical(50)
-    ADIOS_FOR_SOLVER_MESHFILES = bcast_logical(51)
-    ADIOS_FOR_AVS_DX = bcast_logical(52)
-    EXACT_MASS_MATRIX_FOR_ROTATION = bcast_logical(53)
-    ATTENUATION_1D_WITH_3D_STORAGE = bcast_logical(54)
+    EXACT_MASS_MATRIX_FOR_ROTATION = bcast_logical(46)
+    ATTENUATION_1D_WITH_3D_STORAGE = bcast_logical(47)
+    GPU_MODE = bcast_logical(48)
+    ADIOS_ENABLED = bcast_logical(49)
+    ADIOS_FOR_FORWARD_ARRAYS = bcast_logical(50)
+    ADIOS_FOR_MPI_ARRAYS = bcast_logical(51)
+    ADIOS_FOR_ARRAYS_SOLVER = bcast_logical(52)
+    ADIOS_FOR_SOLVER_MESHFILES = bcast_logical(53)
+    ADIOS_FOR_AVS_DX = bcast_logical(54)
+    ADIOS_FOR_KERNELS = bcast_logical(55)
+    ADIOS_FOR_MODELS = bcast_logical(56)
 
     ! double precisions
     DT = bcast_double_precision(1)

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/src/shared/parallel.f90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/shared/parallel.f90	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/shared/parallel.f90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -93,14 +93,11 @@
 
   implicit none
 
-  integer :: ier,rank
+  integer :: ier
 
-  ! gets callers rank
-  call MPI_COMM_RANK(MPI_COMM_WORLD,rank,ier)
-
   ! synchronizes MPI processes
   call MPI_BARRIER(MPI_COMM_WORLD,ier)
-  if( ier /= 0 ) call exit_mpi(rank,'error synchronize MPI processes')
+  if( ier /= 0 ) stop 'error synchronize MPI processes'
 
   end subroutine synchronize_all
 
@@ -108,6 +105,28 @@
 !-------------------------------------------------------------------------------------------------
 !
 
+  subroutine synchronize_all_comm(comm)
+
+  use mpi
+
+  implicit none
+
+  integer,intent(in) :: comm
+
+  ! local parameters
+  integer :: ier
+
+  ! synchronizes MPI processes
+  call MPI_BARRIER(comm,ier)
+  if( ier /= 0 ) stop 'error synchronize MPI processes for specified communicator'
+
+  end subroutine synchronize_all_comm
+
+
+!
+!-------------------------------------------------------------------------------------------------
+!
+
   integer function null_process()
 
   use mpi
@@ -317,6 +336,34 @@
 !-------------------------------------------------------------------------------------------------
 !
 
+  subroutine max_allreduce_i(buffer,count)
+
+  use mpi
+
+  implicit none
+
+  integer :: count
+  integer,dimension(count),intent(inout) :: buffer
+
+  ! local parameters
+  integer :: ier
+  integer,dimension(count) :: send
+
+  ! seems not to be supported on all kind of MPI implementations...
+  !call MPI_ALLREDUCE(MPI_IN_PLACE, buffer, count, MPI_INTEGER, MPI_MAX, MPI_COMM_WORLD, ier)
+
+  send(:) = buffer(:)
+
+  call MPI_ALLREDUCE(send, buffer, count, MPI_INTEGER, MPI_MAX, MPI_COMM_WORLD, ier)
+  if( ier /= 0 ) stop 'Allreduce to get max values failed.'
+
+  end subroutine max_allreduce_i
+
+
+!
+!-------------------------------------------------------------------------------------------------
+!
+
   subroutine max_all_cr(sendbuf, recvbuf)
 
   use mpi
@@ -367,6 +414,7 @@
 
   end subroutine sum_all_dp
 
+
 !
 !-------------------------------------------------------------------------------------------------
 !
@@ -840,44 +888,6 @@
 !-------------------------------------------------------------------------------------------------
 !
 
-
-
-  subroutine world_size(size)
-
-  use mpi
-
-  implicit none
-
-  integer :: size
-  integer :: ier
-
-  call MPI_COMM_SIZE(MPI_COMM_WORLD,size,ier)
-  if( ier /= 0 ) stop 'error getting MPI world size'
-
-  end subroutine world_size
-
-!
-!-------------------------------------------------------------------------------------------------
-!
-
-  subroutine world_rank(rank)
-
-  use mpi
-
-  implicit none
-
-  integer :: rank
-  integer :: ier
-
-  call MPI_COMM_RANK(MPI_COMM_WORLD,rank,ier)
-  if( ier /= 0 ) stop 'error getting MPI rank'
-
-  end subroutine world_rank
-
-!
-!-------------------------------------------------------------------------------------------------
-!
-
   subroutine gather_all_i(sendbuf, sendcnt, recvbuf, recvcount, NPROC)
 
   use mpi
@@ -996,3 +1006,95 @@
 
   end subroutine gatherv_all_cr
 
+!
+!-------------------------------------------------------------------------------------------------
+!
+
+
+
+  subroutine world_size(size)
+
+  use mpi
+
+  implicit none
+
+  integer,intent(out) :: size
+
+  ! local parameters
+  integer :: ier
+
+  call MPI_COMM_SIZE(MPI_COMM_WORLD,size,ier)
+  if( ier /= 0 ) stop 'error getting MPI world size'
+
+  end subroutine world_size
+
+!
+!-------------------------------------------------------------------------------------------------
+!
+
+  subroutine world_rank(rank)
+
+  use mpi
+
+  implicit none
+
+  integer,intent(out) :: rank
+
+  ! local parameters
+  integer :: ier
+
+  call MPI_COMM_RANK(MPI_COMM_WORLD,rank,ier)
+  if( ier /= 0 ) stop 'error getting MPI rank'
+
+  end subroutine world_rank
+
+!
+!-------------------------------------------------------------------------------------------------
+!
+
+  subroutine world_duplicate(comm)
+
+  use mpi
+
+  implicit none
+
+  integer,intent(out) :: comm
+  integer :: ier
+
+  call MPI_COMM_DUP(MPI_COMM_WORLD,comm,ier)
+  if( ier /= 0 ) stop 'error duplicating MPI_COMM_WORLD communicator'
+
+  end subroutine world_duplicate
+
+!
+!-------------------------------------------------------------------------------------------------
+!
+
+  subroutine world_get_comm(comm)
+
+  use mpi
+
+  implicit none
+
+  integer,intent(out) :: comm
+
+  comm = MPI_COMM_WORLD
+
+  end subroutine world_get_comm
+
+!
+!-------------------------------------------------------------------------------------------------
+!
+
+  subroutine world_get_comm_self(comm)
+
+  use mpi
+
+  implicit none
+
+  integer,intent(out) :: comm
+
+  comm = MPI_COMM_SELF
+
+  end subroutine world_get_comm_self
+

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/src/shared/read_parameter_file.f90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/shared/read_parameter_file.f90	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/shared/read_parameter_file.f90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -240,6 +240,10 @@
   if (ierr /= 0) stop 'an error occurred while reading the parameter file: ADIOS_FOR_SOLVER_MESHFILES'
   call read_value_logical(ADIOS_FOR_AVS_DX, 'solver.ADIOS_FOR_AVS_DX', ierr)
   if (ierr /= 0) stop 'an error occurred while reading the parameter file: ADIOS_FOR_AVS_DX'
+  call read_value_logical(ADIOS_FOR_KERNELS, 'solver.ADIOS_FOR_KERNELS', ierr)
+  if (ierr /= 0) stop 'an error occurred while reading the parameter file: ADIOS_FOR_KERNELS'
+  call read_value_logical(ADIOS_FOR_MODELS, 'solver.ADIOS_FOR_MODELS', ierr)
+  if (ierr /= 0) stop 'an error occurred while reading the parameter file: ADIOS_FOR_MODELS'
 
   ! closes parameter file
   call close_parameter_file()
@@ -286,10 +290,14 @@
 ! please remove these security checks only after validating new features
 
 !! DK DK July 2013: temporary, the time for Matthieu Lefebvre to merge his ADIOS implementation
-  if( ADIOS_ENABLED ) &
-    stop 'ADIOS_ENABLED support not implemented yet'
-  if( ADIOS_ENABLED .and. GPU_MODE ) &
-    stop 'ADIOS_ENABLED support not implemented yet'
+  !if( ADIOS_ENABLED ) &
+  !  stop 'ADIOS_ENABLED support not implemented yet'
+  !if( ADIOS_ENABLED .and. GPU_MODE ) &
+  !  stop 'ADIOS_ENABLED support not implemented yet for GPU_MODE'
+  if( ADIOS_ENABLED .and. SAVE_REGULAR_KL ) &
+    stop 'ADIOS_ENABLED support not implemented yet for SAVE_REGULAR_KL'
+  if( ADIOS_ENABLED .and. UNDO_ATTENUATION .and. SIMULATION_TYPE == 3 ) &
+    stop 'ADIOS_ENABLED support not implemented yet for UNDO_ATTENUATION and SIMULATION_TYPE == 3'
 
   !if( USE_LDDRK ) &
   !  stop 'USE_LDDRK support not implemented yet'

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/src/shared/rules.mk
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/shared/rules.mk	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/shared/rules.mk	2013-10-07 15:14:08 UTC (rev 22929)
@@ -78,8 +78,10 @@
 	$(EMPTY_MACRO)
 
 ADIOS_OBJECTS = \
-  $O/adios_helpers.shared.o \
-  $O/adios_manager.shared.o \
+	$O/adios_helpers_definitions.shared_adios_module.o \
+	$O/adios_helpers_writers.shared_adios_module.o \
+	$O/adios_helpers.shared_adios.o \
+	$O/adios_manager.shared_adios.o \
 	$(EMPTY_MACRO)
 
 ADIOS_STUBS = \
@@ -98,12 +100,13 @@
 #### rule for each .o file below
 ####
 
+##
+## shared
+##
+
 $O/%.shared_module.o: $S/%.f90 ${SETUP}/constants.h
 	${FCCOMPILE_CHECK} ${FCFLAGS_f90} -c -o $@ $<
 
-##
-## shared
-##
 $O/%.shared.o: $S/%.f90 ${SETUP}/constants.h $O/shared_par.shared_module.o
 	${FCCOMPILE_CHECK} ${FCFLAGS_f90} -c -o $@ $<
 
@@ -113,6 +116,18 @@
 $O/%.sharedmpi.o: $S/%.f90 ${SETUP}/constants.h $O/shared_par.shared_module.o
 	${MPIFCCOMPILE_CHECK} ${FCFLAGS_f90} -c -o $@ $<
 
+## adios
+
+$O/%.shared_adios_module.o: $S/%.f90 ${SETUP}/constants.h
+	${FCCOMPILE_CHECK} ${FCFLAGS_f90} -c -o $@ $<
+
+$O/%.shared_adios.o: $S/%.f90 ${SETUP}/constants.h $O/adios_helpers_writers.shared_adios_module.o $O/adios_helpers_definitions.shared_adios_module.o
+	${FCCOMPILE_CHECK} ${FCFLAGS_f90} -c -o $@ $<
+
+$O/%.shared_adios.o: $S/%.F90 ${SETUP}/constants.h $O/adios_helpers_writers.shared_adios_module.o $O/adios_helpers_definitions.shared_adios_module.o
+	${FCCOMPILE_CHECK} ${FCFLAGS_f90} -c -o $@ $<
+
+
 $O/%.cc.o: $S/%.c ${SETUP}/config.h
 	${CC} -c $(CPPFLAGS) $(CFLAGS) -o $@ $< 
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/src/shared/shared_par.f90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/shared/shared_par.f90	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/shared/shared_par.f90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -100,7 +100,7 @@
   ! adios file output
   logical :: ADIOS_ENABLED,ADIOS_FOR_FORWARD_ARRAYS, &
              ADIOS_FOR_MPI_ARRAYS,ADIOS_FOR_ARRAYS_SOLVER,ADIOS_FOR_SOLVER_MESHFILES, &
-             ADIOS_FOR_AVS_DX
+             ADIOS_FOR_AVS_DX,ADIOS_FOR_KERNELS,ADIOS_FOR_MODELS
 
   end module shared_input_parameters
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/compute_forces_crust_mantle_Dev.F90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/compute_forces_crust_mantle_Dev.F90	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/compute_forces_crust_mantle_Dev.F90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -44,7 +44,8 @@
   use constants_solver
 
   use specfem_par,only: &
-    hprime_xx,hprime_xxT,hprimewgll_xx,hprimewgll_xxT,wgllwgll_xy,wgllwgll_xz,wgllwgll_yz,wgll_cube, &
+    hprime_xx,hprime_xxT,hprimewgll_xx,hprimewgll_xxT, &
+    wgll_cube, &
     minus_gravity_table,density_table,minus_deriv_gravity_table, &
     COMPUTE_AND_STORE_STRAIN,USE_LDDRK
 
@@ -72,6 +73,8 @@
 
 #ifdef FORCE_VECTORIZATION
   use specfem_par,only: wgllwgll_xy_3D,wgllwgll_xz_3D,wgllwgll_yz_3D
+#else
+  use specfem_par,only: wgllwgll_xy,wgllwgll_xz,wgllwgll_yz
 #endif
 
 !daniel: att - debug

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/compute_forces_inner_core_Dev.F90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/compute_forces_inner_core_Dev.F90	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/compute_forces_inner_core_Dev.F90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -44,7 +44,8 @@
   use constants_solver
 
   use specfem_par,only: &
-    hprime_xx,hprime_xxT,hprimewgll_xx,hprimewgll_xxT,wgllwgll_xy,wgllwgll_xz,wgllwgll_yz,wgll_cube, &
+    hprime_xx,hprime_xxT,hprimewgll_xx,hprimewgll_xxT, &
+    wgll_cube, &
     minus_gravity_table,density_table,minus_deriv_gravity_table, &
     COMPUTE_AND_STORE_STRAIN,USE_LDDRK
 
@@ -65,6 +66,8 @@
 
 #ifdef FORCE_VECTORIZATION
   use specfem_par,only: wgllwgll_xy_3D,wgllwgll_xz_3D,wgllwgll_yz_3D
+#else
+  use specfem_par,only: wgllwgll_xy,wgllwgll_xz,wgllwgll_yz
 #endif
 
   implicit none

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/compute_forces_outer_core_Dev.F90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/compute_forces_outer_core_Dev.F90	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/compute_forces_outer_core_Dev.F90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -37,7 +37,8 @@
   use constants_solver
 
   use specfem_par,only: &
-    hprime_xx,hprime_xxT,hprimewgll_xx,hprimewgll_xxT,wgllwgll_xy,wgllwgll_xz,wgllwgll_yz,wgll_cube, &
+    hprime_xx,hprime_xxT,hprimewgll_xx,hprimewgll_xxT, &
+    wgll_cube, &
     minus_rho_g_over_kappa_fluid,d_ln_density_dr_table, &
     MOVIE_VOLUME, &
     USE_LDDRK,istage
@@ -54,6 +55,8 @@
 
 #ifdef FORCE_VECTORIZATION
   use specfem_par,only: wgllwgll_xy_3D,wgllwgll_xz_3D,wgllwgll_yz_3D
+#else
+  use specfem_par,only: wgllwgll_xy,wgllwgll_xz,wgllwgll_yz
 #endif
 
   implicit none

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/compute_forces_viscoelastic_calling_routine.F90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/compute_forces_viscoelastic_calling_routine.F90	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/compute_forces_viscoelastic_calling_routine.F90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -41,6 +41,10 @@
   use specfem_par_movie
   implicit none
 
+! note: instead of using size(factor_common_crust_mantle,5), we use the ATT4_VAL/ATT5_VAL in the function calls;
+!       this is due to the size(..) function returning either integer(kind=4) or integer(kind=8)
+!       depending on compiler flags (-mcmedium), leading to unpredictable results
+
   ! local parameters
   ! non blocking MPI
   ! iphase: iphase = 1 is for computing outer elements in the crust_mantle and inner_core regions,
@@ -92,7 +96,7 @@
                                              epsilondev_xz_crust_mantle,epsilondev_yz_crust_mantle, &
                                              eps_trace_over_3_crust_mantle, &
                                              alphaval,betaval,gammaval, &
-                                             factor_common_crust_mantle,size(factor_common_crust_mantle,5), .false. )
+                                             factor_common_crust_mantle,ATT4_VAL, .false. )
         ! inner core region
         call compute_forces_inner_core_Dev(NSPEC_INNER_CORE_STR_OR_ATT,NGLOB_INNER_CORE, &
                                            NSPEC_INNER_CORE_ATTENUATION, &
@@ -109,7 +113,7 @@
                                            epsilondev_xz_inner_core,epsilondev_yz_inner_core, &
                                            eps_trace_over_3_inner_core,&
                                            alphaval,betaval,gammaval, &
-                                           factor_common_inner_core,size(factor_common_inner_core,5)) !!!! , .false. )
+                                           factor_common_inner_core,ATT5_VAL) !!!! , .false. )
       else
         ! no Deville optimization
         ! crust/mantle region
@@ -128,7 +132,7 @@
                                          epsilondev_xz_crust_mantle,epsilondev_yz_crust_mantle, &
                                          eps_trace_over_3_crust_mantle, &
                                          alphaval,betaval,gammaval, &
-                                         factor_common_crust_mantle,size(factor_common_crust_mantle,5)) !!!!!!!!!!!! , .false. )
+                                         factor_common_crust_mantle,ATT4_VAL) !!!!!!!!!!!! , .false. )
         ! inner core region
         call compute_forces_inner_core(NSPEC_INNER_CORE_STR_OR_ATT,NGLOB_INNER_CORE, &
                                        NSPEC_INNER_CORE_ATTENUATION, &
@@ -145,7 +149,7 @@
                                        epsilondev_xz_inner_core,epsilondev_yz_inner_core, &
                                        eps_trace_over_3_inner_core,&
                                        alphaval,betaval,gammaval, &
-                                       factor_common_inner_core,size(factor_common_inner_core,5)) !!!!!!!!!!! , .false. )
+                                       factor_common_inner_core,ATT5_VAL) !!!!!!!!!!! , .false. )
       endif
     else
       ! on GPU
@@ -480,7 +484,7 @@
                                              b_epsilondev_xz_crust_mantle,b_epsilondev_yz_crust_mantle, &
                                              b_eps_trace_over_3_crust_mantle, &
                                              b_alphaval,b_betaval,b_gammaval, &
-                                             factor_common_crust_mantle,size(factor_common_crust_mantle,5), .true. )
+                                             factor_common_crust_mantle,ATT4_VAL, .true. )
         ! inner core region
         call compute_forces_inner_core_Dev(NSPEC_INNER_CORE_ADJOINT,NGLOB_INNER_CORE_ADJOINT, &
                                            NSPEC_INNER_CORE_STR_AND_ATT, &
@@ -497,7 +501,7 @@
                                            b_epsilondev_xz_inner_core,b_epsilondev_yz_inner_core, &
                                            b_eps_trace_over_3_inner_core,&
                                            b_alphaval,b_betaval,b_gammaval, &
-                                           factor_common_inner_core,size(factor_common_inner_core,5)) !!!! , .true. )
+                                           factor_common_inner_core,ATT5_VAL) !!!! , .true. )
       else
         ! no Deville optimization
         ! crust/mantle region
@@ -517,7 +521,7 @@
                                          b_epsilondev_xz_crust_mantle,b_epsilondev_yz_crust_mantle, &
                                          b_eps_trace_over_3_crust_mantle, &
                                          b_alphaval,b_betaval,b_gammaval, &
-                                         factor_common_crust_mantle,size(factor_common_crust_mantle,5)) !!!!!!!!!!!! , .true. )
+                                         factor_common_crust_mantle,ATT4_VAL) !!!!!!!!!!!! , .true. )
         ! inner core region
         call compute_forces_inner_core(NSPEC_INNER_CORE_ADJOINT,NGLOB_INNER_CORE_ADJOINT, &
                                        NSPEC_INNER_CORE_STR_AND_ATT, &
@@ -534,7 +538,7 @@
                                        b_epsilondev_xz_inner_core,b_epsilondev_yz_inner_core, &
                                        b_eps_trace_over_3_inner_core,&
                                        b_alphaval,b_betaval,b_gammaval, &
-                                       factor_common_inner_core,size(factor_common_inner_core,5)) !!!!!!!!!!! , .true. )
+                                       factor_common_inner_core,ATT5_VAL) !!!!!!!!!!! , .true. )
       endif
     else
       ! on GPU

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/compute_stacey_outer_core.f90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/compute_stacey_outer_core.f90	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/compute_stacey_outer_core.f90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -532,9 +532,6 @@
     vp_outer_core, &
     nimin_outer_core,nimax_outer_core,nkmin_eta_outer_core, &
     njmin_outer_core,njmax_outer_core,nkmin_xi_outer_core, &
-    absorb_xmin_outer_core,absorb_xmax_outer_core, &
-    absorb_ymin_outer_core,absorb_ymax_outer_core, &
-    absorb_zmin_outer_core, &
     ibelm_xmin_outer_core,ibelm_xmax_outer_core, &
     ibelm_ymin_outer_core,ibelm_ymax_outer_core, &
     ibelm_bottom_outer_core

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/finalize_simulation.f90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/finalize_simulation.f90	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/finalize_simulation.f90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -88,18 +88,18 @@
 
     ! frees memory
     deallocate(absorb_xmin_crust_mantle, &
-              absorb_xmax_crust_mantle, &
-              absorb_ymin_crust_mantle, &
-              absorb_ymax_crust_mantle, &
-              absorb_xmin_outer_core, &
-              absorb_xmax_outer_core, &
-              absorb_ymin_outer_core, &
-              absorb_ymax_outer_core, &
-              absorb_zmin_outer_core)
+               absorb_xmax_crust_mantle, &
+               absorb_ymin_crust_mantle, &
+               absorb_ymax_crust_mantle, &
+               absorb_xmin_outer_core, &
+               absorb_xmax_outer_core, &
+               absorb_ymin_outer_core, &
+               absorb_ymax_outer_core, &
+               absorb_zmin_outer_core)
   endif
 
   ! save/read the surface movie using the same c routine as we do for absorbing boundaries (file ID is 9)
-  if (NOISE_TOMOGRAPHY/=0) then
+  if( NOISE_TOMOGRAPHY /= 0 ) then
     call close_file_abs(9)
   endif
 
@@ -107,51 +107,23 @@
   call save_forward_arrays()
 
   ! dump kernel arrays
-  if (SIMULATION_TYPE == 3) then
-    ! crust mantle
-    if (SAVE_REGULAR_KL) then
-      call save_regular_kernels_crust_mantle()
-    else
-      call save_kernels_crust_mantle()
-    endif
+  call save_kernels()
 
-    ! noise strength kernel
-    if (NOISE_TOMOGRAPHY == 3) then
-       call save_kernels_strength_noise()
-    endif
-
-    ! outer core
-    call save_kernels_outer_core()
-
-    ! inner core
-    call save_kernels_inner_core()
-
-    ! boundary kernel
-    if (SAVE_BOUNDARY_MESH) then
-      call save_kernels_boundary_kl()
-    endif
-
-    ! approximate hessian
-    if( APPROXIMATE_HESS_KL ) then
-      call save_kernels_hessian()
-    endif
-  endif
-
-  ! save source derivatives for adjoint simulations
-  if (SIMULATION_TYPE == 2 .and. nrec_local > 0) then
-    call save_kernels_source_derivatives()
-  endif
-
   ! vtk visualization
   if( VTK_MODE ) then
     ! closes vtk window
     if(myrank == 0 ) call finish_vtkwindow()
   endif
 
+  ! adios finalizes
+  if( ADIOS_ENABLED ) then
+    call adios_cleanup()
+  endif
+
   ! frees dynamically allocated memory
   call finalize_simulation_cleanup()
 
-  ! close the main output file
+  ! closes the main output file
   if(myrank == 0) then
     write(IMAIN,*)
     write(IMAIN,*) 'End of the simulation'
@@ -160,12 +132,9 @@
     close(IMAIN)
   endif
 
-  ! synchronize all the processes to make sure everybody has finished
+  ! synchronizes all the processes to make sure everybody has finished
   call synchronize_all()
 
-  if (ADIOS_ENABLED) then
-    call adios_cleanup()
-  endif
   end subroutine finalize_simulation
 
 !

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/get_attenuation.f90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/get_attenuation.f90	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/get_attenuation.f90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -25,13 +25,13 @@
 !
 !=====================================================================
 
-  subroutine get_attenuation_model_3D(myrank, prname, &
+  subroutine get_attenuation_model_3D(myrank,iregion_code, &
                                       one_minus_sum_beta, &
                                       factor_common, &
                                       scale_factor, tau_s, vnspec)
 
   use constants_solver
-  use specfem_par,only: ATTENUATION_VAL,ADIOS_ENABLED,ADIOS_FOR_ARRAYS_SOLVER
+  use specfem_par,only: ATTENUATION_VAL,ADIOS_ENABLED,ADIOS_FOR_ARRAYS_SOLVER,LOCAL_PATH
 
   implicit none
 
@@ -47,12 +47,13 @@
 
   double precision, dimension(N_SLS),intent(out) :: tau_s
 
-  character(len=150) :: prname
+  integer :: iregion_code
 
   ! local parameters
   integer :: i,j,k,ispec,ier
   double precision, dimension(N_SLS) :: tau_e, fc
   double precision :: omsb, Q_mu, sf, T_c_source, scale_t
+  character(len=150) :: prname
 
   ! checks if attenuation is on and anything to do
   if( .not. ATTENUATION_VAL) return
@@ -60,12 +61,16 @@
   ! All of the following reads use the output parameters as their temporary arrays
   ! use the filename to determine the actual contents of the read
   if( ADIOS_ENABLED .and. ADIOS_FOR_ARRAYS_SOLVER ) then
-    call read_attenuation_adios(myrank, prname, &
+    call read_attenuation_adios(myrank, iregion_code, &
                                 factor_common, scale_factor, tau_s, vnspec, T_c_source)
   else
+
+    ! opens corresponding databases file
+    call create_name_database(prname,myrank,iregion_code,LOCAL_PATH)
     open(unit=IIN, file=prname(1:len_trim(prname))//'attenuation.bin', &
           status='old',action='read',form='unformatted',iostat=ier)
     if( ier /= 0 ) call exit_MPI(myrank,'error opening file attenuation.bin')
+
     read(IIN) tau_s
     read(IIN) factor_common ! tau_e_store
     read(IIN) scale_factor  ! Qmu_store

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/iterate_time.F90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/iterate_time.F90	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/iterate_time.F90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -261,7 +261,7 @@
   implicit none
 
   real :: currenttime
-  integer :: iglob,inum
+  integer :: iglob,inum,data_size
   real(kind=CUSTOM_REAL),dimension(1):: dummy
 
   ! vtk rendering at frame interval
@@ -295,16 +295,17 @@
 
     ! updates for multiple mpi process
     if( NPROCTOT_VAL > 1 ) then
+      data_size = size(vtkdata)
       if( myrank == 0 ) then
         ! gather data
-        call gatherv_all_cr(vtkdata,size(vtkdata),&
+        call gatherv_all_cr(vtkdata,data_size,&
                             vtkdata_all,vtkdata_points_all,vtkdata_offset_all, &
                             vtkdata_numpoints_all,NPROCTOT_VAL)
         ! updates vtk window
         call visualize_vtkdata(it,currenttime,vtkdata_all)
       else
         ! all other process just send data
-        call gatherv_all_cr(vtkdata,size(vtkdata),&
+        call gatherv_all_cr(vtkdata,data_size,&
                             dummy,vtkdata_points_all,vtkdata_offset_all, &
                             1,NPROCTOT_VAL)
       endif

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/prepare_timerun.f90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/prepare_timerun.f90	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/prepare_timerun.f90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -855,7 +855,6 @@
   double precision :: scale_factor,scale_factor_minus_one
   real(kind=CUSTOM_REAL) :: mul
   integer :: ispec,i,j,k
-  character(len=150) :: prname_l
 
   ! checks if attenuation is on and anything to do
   if( .not. ATTENUATION_VAL ) return
@@ -868,24 +867,14 @@
 
   ! reads in attenuation values
   ! CRUST_MANTLE ATTENUATION
-  if( ADIOS_ENABLED .and. ADIOS_FOR_ARRAYS_SOLVER ) then
-    call create_name_database_adios(prname_l, IREGION_CRUST_MANTLE, LOCAL_PATH)
-  else
-    call create_name_database(prname_l, myrank, IREGION_CRUST_MANTLE, LOCAL_PATH)
-  endif
-  call get_attenuation_model_3D(myrank, prname_l, &
+  call get_attenuation_model_3D(myrank,IREGION_CRUST_MANTLE, &
                                 one_minus_sum_beta_crust_mantle, &
                                 factor_common_crust_mantle, &
                                 factor_scale_crust_mantle,tau_sigma_dble, &
                                 NSPEC_CRUST_MANTLE)
 
   ! INNER_CORE ATTENUATION
-  if( ADIOS_ENABLED .and. ADIOS_FOR_ARRAYS_SOLVER ) then
-    call create_name_database_adios(prname_l, IREGION_INNER_CORE, LOCAL_PATH)
-  else
-    call create_name_database(prname_l, myrank, IREGION_INNER_CORE, LOCAL_PATH)
-  endif
-  call get_attenuation_model_3D(myrank, prname_l, &
+  call get_attenuation_model_3D(myrank,IREGION_INNER_CORE, &
                                 one_minus_sum_beta_inner_core, &
                                 factor_common_inner_core, &
                                 factor_scale_inner_core,tau_sigma_dble, &

Copied: seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/read_arrays_solver_adios.F90 (from rev 22910, seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/read_arrays_solver_adios.f90)
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/read_arrays_solver_adios.F90	                        (rev 0)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/read_arrays_solver_adios.F90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -0,0 +1,452 @@
+!=====================================================================
+!
+!          S p e c f e m 3 D  G l o b e  V e r s i o n  6 . 0
+!          --------------------------------------------------
+!
+!          Main authors: Dimitri Komatitsch and Jeroen Tromp
+!                        Princeton University, USA
+!             and CNRS / INRIA / University of Pau, France
+! (c) Princeton University and CNRS / INRIA / University of Pau
+!                            August 2013
+!
+! This 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.
+!
+!=====================================================================
+
+!===============================================================================
+!> \brief Read adios arrays created by the mesher (file: regX_solver_data.bp)
+subroutine read_arrays_solver_adios(iregion_code,myrank, &
+                                    nspec,nglob,nglob_xy, &
+                                    nspec_iso,nspec_tiso,nspec_ani, &
+                                    rho_vp,rho_vs,xstore,ystore,zstore, &
+                                    xix,xiy,xiz,etax,etay,etaz,gammax,gammay,gammaz, &
+                                    rhostore, kappavstore,muvstore,kappahstore,muhstore,eta_anisostore, &
+                                    c11store,c12store,c13store,c14store,c15store,c16store,c22store, &
+                                    c23store,c24store,c25store,c26store,c33store,c34store,c35store, &
+                                    c36store,c44store,c45store,c46store,c55store,c56store,c66store, &
+                                    ibool,idoubling,ispec_is_tiso, &
+                                    rmassx,rmassy,rmassz,rmass_ocean_load, &
+                                    READ_KAPPA_MU,READ_TISO, &
+                                    b_rmassx,b_rmassy)
+
+  use adios_read_mod
+  use adios_helpers_mod, only: check_adios_err
+
+  use constants_solver
+  use specfem_par,only: &
+    ABSORBING_CONDITIONS, &
+    LOCAL_PATH,ABSORBING_CONDITIONS,&
+    EXACT_MASS_MATRIX_FOR_ROTATION
+
+  implicit none
+
+  integer :: iregion_code,myrank
+  integer :: nspec,nglob,nglob_xy
+  integer :: nspec_iso,nspec_tiso,nspec_ani
+
+  ! Stacey
+  real(kind=CUSTOM_REAL),dimension(NGLLX,NGLLY,NGLLZ,nspec):: rho_vp,rho_vs
+
+  real(kind=CUSTOM_REAL), dimension(nglob) :: xstore,ystore,zstore
+
+  real(kind=CUSTOM_REAL), dimension(NGLLX,NGLLY,NGLLZ,nspec) :: &
+    xix,xiy,xiz,etax,etay,etaz,gammax,gammay,gammaz
+
+  ! material properties
+  real(kind=CUSTOM_REAL),dimension(NGLLX,NGLLY,NGLLZ,nspec_iso) :: &
+    rhostore,kappavstore,muvstore
+
+  ! additional arrays for anisotropy stored only where needed to save memory
+  real(kind=CUSTOM_REAL),dimension(NGLLX,NGLLY,NGLLZ,nspec_tiso) :: &
+    kappahstore,muhstore,eta_anisostore
+
+  ! additional arrays for full anisotropy
+  real(kind=CUSTOM_REAL), dimension(NGLLX,NGLLY,NGLLZ,nspec_ani) :: &
+    c11store,c12store,c13store,c14store,c15store,c16store, &
+    c22store,c23store,c24store,c25store,c26store,c33store,c34store, &
+    c35store,c36store,c44store,c45store,c46store,c55store,c56store,c66store
+
+  ! global addressing
+  integer,dimension(NGLLX,NGLLY,NGLLZ,nspec) :: ibool
+  integer, dimension(nspec) :: idoubling
+  logical, dimension(nspec) :: ispec_is_tiso
+
+  ! mass matrices and additional ocean load mass matrix
+  real(kind=CUSTOM_REAL), dimension(nglob_xy) :: rmassx,rmassy
+  real(kind=CUSTOM_REAL), dimension(nglob_xy) :: b_rmassx,b_rmassy
+
+  real(kind=CUSTOM_REAL), dimension(nglob)    :: rmassz
+  real(kind=CUSTOM_REAL), dimension(NGLOB_CRUST_MANTLE_OCEANS) :: rmass_ocean_load
+
+  ! flags to know if we should read Vs and anisotropy arrays
+  logical :: READ_KAPPA_MU,READ_TISO
+
+  character(len=256) :: file_name
+
+  ! local parameters
+  integer :: ierr, comm, lnspec, lnglob, local_dim
+  ! ADIOS variables
+  integer                 :: adios_err
+  integer(kind=8)         :: adios_handle
+  integer(kind=8), dimension(1) :: start, count
+
+  integer(kind=8), dimension(256),target :: selections
+  integer :: sel_num, i
+  integer(kind=8), pointer :: sel => null()
+
+  character(len=128)      :: region_name, region_name_scalar
+
+  write(region_name,"('reg',i1, '/')") iregion_code
+  write(region_name_scalar,"('reg',i1)") iregion_code
+
+  sel_num = 0
+
+  ! Postpend the actual file name.
+  file_name= trim(LOCAL_PATH) // "/solver_data.bp"
+
+  call world_duplicate(comm)
+
+  ! Setup the ADIOS library to read the file
+  call adios_read_init_method (ADIOS_READ_METHOD_BP, comm, &
+      "verbose=1", adios_err)
+  call check_adios_err(myrank,adios_err)
+  call adios_read_open_file (adios_handle, file_name, 0, comm, ierr)
+  call check_adios_err(myrank,adios_err)
+
+  ! read coordinates of the mesh
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_writeblock(sel, myrank)
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "nspec", 0, 1, &
+     lnspec, adios_err)
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "nglob", 0, 1, &
+     lnglob, adios_err)
+
+  ! mesh coordinates
+  local_dim = nglob
+  start(1) = local_dim*myrank; count(1) = local_dim
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count)
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "x_global/array", 0, 1, &
+      xstore, adios_err)
+  call check_adios_err(myrank,adios_err)
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "y_global/array", 0, 1, &
+      ystore, adios_err)
+  call check_adios_err(myrank,adios_err)
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "z_global/array", 0, 1, &
+      zstore, adios_err)
+  call check_adios_err(myrank,adios_err)
+
+  local_dim = NGLLX * NGLLY * NGLLZ * nspec_iso
+  start(1) = local_dim*myrank; count(1) = local_dim
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count)
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "rhostore/array", 0, 1, &
+      rhostore, adios_err)
+  call check_adios_err(myrank,adios_err)
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "kappavstore/array", 0, 1, &
+      kappavstore, adios_err)
+  call check_adios_err(myrank,adios_err)
+  if(READ_KAPPA_MU) then
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "muvstore/array", 0, 1, &
+        muvstore, adios_err)
+    call check_adios_err(myrank,adios_err)
+  endif
+
+  if(TRANSVERSE_ISOTROPY_VAL .and. READ_TISO) then
+    local_dim = NGLLX * NGLLY * NGLLZ * nspec_tiso
+    start(1) = local_dim*myrank; count(1) = local_dim
+    sel_num = sel_num+1
+    sel => selections(sel_num)
+    call adios_selection_boundingbox (sel , 1, start, count)
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "kappahstore/array", 0, 1, &
+        kappahstore, adios_err)
+    call check_adios_err(myrank,adios_err)
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "muhstore/array", 0, 1, &
+        muhstore, adios_err)
+    call check_adios_err(myrank,adios_err)
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "eta_anisostore/array", 0, 1, &
+        eta_anisostore, adios_err)
+    call check_adios_err(myrank,adios_err)
+  endif
+
+  local_dim = nspec
+  start(1) = local_dim*myrank; count(1) = local_dim
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count)
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "idoubling/array", 0, 1, &
+      idoubling, adios_err)
+  call check_adios_err(myrank,adios_err)
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "ispec_is_tiso/array", 0, 1, &
+      ispec_is_tiso, adios_err)
+  call check_adios_err(myrank,adios_err)
+
+  local_dim = NGLLX * NGLLY * NGLLZ * nspec
+  start(1) = local_dim*myrank; count(1) = local_dim
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count)
+
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "ibool/array", 0, 1, &
+      ibool, adios_err)
+  call check_adios_err(myrank,adios_err)
+
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "xixstore/array", 0, 1, &
+      xix, adios_err)
+  call check_adios_err(myrank,adios_err)
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "xiystore/array", 0, 1, &
+      xiy, adios_err)
+  call check_adios_err(myrank,adios_err)
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "xizstore/array", 0, 1, &
+      xiz, adios_err)
+  call check_adios_err(myrank,adios_err)
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "etaxstore/array", 0, 1, &
+      etax, adios_err)
+  call check_adios_err(myrank,adios_err)
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "etaystore/array", 0, 1, &
+      etay, adios_err)
+  call check_adios_err(myrank,adios_err)
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "etazstore/array", 0, 1, &
+      etaz, adios_err)
+  call check_adios_err(myrank,adios_err)
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "gammaxstore/array", 0, 1, &
+      gammax, adios_err)
+  call check_adios_err(myrank,adios_err)
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "gammaystore/array", 0, 1, &
+      gammay, adios_err)
+  call check_adios_err(myrank,adios_err)
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "gammazstore/array", 0, 1, &
+      gammaz, adios_err)
+  call check_adios_err(myrank,adios_err)
+
+  if(ANISOTROPIC_INNER_CORE_VAL .and. iregion_code == IREGION_INNER_CORE) then
+    local_dim = NGLLX * NGLLY * NGLLZ * nspec_ani
+    start(1) = local_dim*myrank; count(1) = local_dim
+    sel_num = sel_num+1
+    sel => selections(sel_num)
+    call adios_selection_boundingbox (sel , 1, start, count)
+
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "c11store/array", 0, 1, &
+        c11store, adios_err)
+    call check_adios_err(myrank,adios_err)
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "c12store/array", 0, 1, &
+        c12store, adios_err)
+    call check_adios_err(myrank,adios_err)
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "c13store/array", 0, 1, &
+        c13store, adios_err)
+    call check_adios_err(myrank,adios_err)
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "c33store/array", 0, 1, &
+        c33store, adios_err)
+    call check_adios_err(myrank,adios_err)
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "c44store/array", 0, 1, &
+        c44store, adios_err)
+    call check_adios_err(myrank,adios_err)
+  endif
+
+  if(ANISOTROPIC_3D_MANTLE_VAL .and. iregion_code == IREGION_CRUST_MANTLE) then
+    local_dim = NGLLX * NGLLY * NGLLZ * nspec_ani
+    start(1) = local_dim*myrank; count(1) = local_dim
+    sel_num = sel_num+1
+    sel => selections(sel_num)
+    call adios_selection_boundingbox (sel , 1, start, count)
+
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "c11store/array", 0, 1, &
+        c11store, adios_err)
+    call check_adios_err(myrank,adios_err)
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "c12store/array", 0, 1, &
+        c12store, adios_err)
+    call check_adios_err(myrank,adios_err)
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "c13store/array", 0, 1, &
+        c13store, adios_err)
+    call check_adios_err(myrank,adios_err)
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "c14store/array", 0, 1, &
+        c14store, adios_err)
+    call check_adios_err(myrank,adios_err)
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "c15store/array", 0, 1, &
+        c15store, adios_err)
+    call check_adios_err(myrank,adios_err)
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "c16store/array", 0, 1, &
+        c16store, adios_err)
+    call check_adios_err(myrank,adios_err)
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "c22store/array", 0, 1, &
+        c22store, adios_err)
+    call check_adios_err(myrank,adios_err)
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "c23store/array", 0, 1, &
+        c23store, adios_err)
+    call check_adios_err(myrank,adios_err)
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "c24store/array", 0, 1, &
+        c24store, adios_err)
+    call check_adios_err(myrank,adios_err)
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "c25store/array", 0, 1, &
+        c25store, adios_err)
+    call check_adios_err(myrank,adios_err)
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "c26store/array", 0, 1, &
+        c26store, adios_err)
+    call check_adios_err(myrank,adios_err)
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "c33store/array", 0, 1, &
+        c33store, adios_err)
+    call check_adios_err(myrank,adios_err)
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "c34store/array", 0, 1, &
+        c34store, adios_err)
+    call check_adios_err(myrank,adios_err)
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "c35store/array", 0, 1, &
+        c35store, adios_err)
+    call check_adios_err(myrank,adios_err)
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "c36store/array", 0, 1, &
+        c36store, adios_err)
+    call check_adios_err(myrank,adios_err)
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "c44store/array", 0, 1, &
+        c44store, adios_err)
+    call check_adios_err(myrank,adios_err)
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "c45store/array", 0, 1, &
+        c45store, adios_err)
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "c46store/array", 0, 1, &
+        c46store, adios_err)
+    call check_adios_err(myrank,adios_err)
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "c55store/array", 0, 1, &
+        c55store, adios_err)
+    call check_adios_err(myrank,adios_err)
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "c56store/array", 0, 1, &
+        c56store, adios_err)
+    call check_adios_err(myrank,adios_err)
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "c66store/array", 0, 1, &
+        c66store, adios_err)
+    call check_adios_err(myrank,adios_err)
+  endif
+
+  ! Stacey
+  if(ABSORBING_CONDITIONS) then
+    local_dim = NGLLX * NGLLY * NGLLZ * nspec ! nspec_stacey in meshfem3D
+    start(1) = local_dim*myrank; count(1) = local_dim
+    sel_num = sel_num+1
+    sel => selections(sel_num)
+    call adios_selection_boundingbox (sel , 1, start, count)
+
+    if(iregion_code == IREGION_CRUST_MANTLE) then
+      call adios_schedule_read(adios_handle, sel, trim(region_name) // "rho_vp/array", 0, 1, &
+          rho_vp, adios_err)
+      call check_adios_err(myrank,adios_err)
+      call adios_schedule_read(adios_handle, sel, trim(region_name) // "rho_vs/array", 0, 1, &
+          rho_vs, adios_err)
+      call check_adios_err(myrank,adios_err)
+    else if(iregion_code == IREGION_OUTER_CORE) then
+      call adios_schedule_read(adios_handle, sel, trim(region_name) // "rho_vp/array", 0, 1, &
+          rho_vp, adios_err)
+      call check_adios_err(myrank,adios_err)
+    endif
+
+  endif
+
+  ! mass matrices
+  !
+  ! in the case of stacey boundary conditions, add C*deltat/2 contribution to
+  ! the mass matrix on Stacey edges for the crust_mantle and outer_core regions
+  ! but not for the inner_core region thus the mass matrix must be replaced by
+  ! three mass matrices including the "C" damping matrix
+  !
+  ! if absorbing_conditions are not set or if NCHUNKS=6, only one mass matrix
+  ! is needed for the sake of performance, only "rmassz" array will be filled
+  ! and "rmassx" & "rmassy" will be obsolete
+  if( (NCHUNKS_VAL /= 6 .and. ABSORBING_CONDITIONS .and. iregion_code == IREGION_CRUST_MANTLE) .or. &
+      (ROTATION_VAL .and. EXACT_MASS_MATRIX_FOR_ROTATION .and. iregion_code == IREGION_CRUST_MANTLE) .or. &
+      (ROTATION_VAL .and. EXACT_MASS_MATRIX_FOR_ROTATION .and. iregion_code == IREGION_INNER_CORE)) then
+
+    local_dim = nglob_xy
+    start(1) = local_dim*myrank; count(1) = local_dim
+    sel_num = sel_num+1
+    sel => selections(sel_num)
+    call adios_selection_boundingbox (sel , 1, start, count)
+
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "rmassx/array", 0, 1, &
+        rmassx, adios_err)
+    call check_adios_err(myrank,adios_err)
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "rmassy/array", 0, 1, &
+        rmassy, adios_err)
+    call check_adios_err(myrank,adios_err)
+  endif
+
+  local_dim = nglob
+  start(1) = local_dim*myrank; count(1) = local_dim
+  sel_num = sel_num+1
+  sel => selections(sel_num)
+  call adios_selection_boundingbox (sel , 1, start, count)
+
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "rmassz/array", 0, 1, &
+                           rmassz, adios_err)
+  call check_adios_err(myrank,adios_err)
+
+
+  if( (ROTATION_VAL .and. EXACT_MASS_MATRIX_FOR_ROTATION .and. iregion_code == IREGION_CRUST_MANTLE) .or. &
+      (ROTATION_VAL .and. EXACT_MASS_MATRIX_FOR_ROTATION .and. iregion_code == IREGION_INNER_CORE))then
+    local_dim = nglob_xy
+    start(1) = local_dim*myrank; count(1) = local_dim
+    sel_num = sel_num+1
+    sel => selections(sel_num)
+    call adios_selection_boundingbox (sel , 1, start, count)
+
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "b_rmassx/array", 0, 1, &
+                             b_rmassx, adios_err)
+    call check_adios_err(myrank,adios_err)
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "b_rmassy/array", 0, 1, &
+                             b_rmassy, adios_err)
+    call check_adios_err(myrank,adios_err)
+  endif
+
+  ! read additional ocean load mass matrix
+  if(OCEANS_VAL .and. iregion_code == IREGION_CRUST_MANTLE) then
+    local_dim = NGLOB_CRUST_MANTLE_OCEANS ! nglob_oceans
+    start(1) = local_dim*myrank; count(1) = local_dim
+    sel_num = sel_num+1
+    sel => selections(sel_num)
+    call adios_selection_boundingbox (sel , 1, start, count)
+
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "rmass_ocean_load/array", &
+        0, 1, rmass_ocean_load, adios_err)
+    call check_adios_err(myrank,adios_err)
+  endif
+
+  call adios_perform_reads(adios_handle, adios_err)
+  call check_adios_err(myrank,adios_err)
+
+  ! Clean everything and close the ADIOS file
+  do i = 1, sel_num
+    sel => selections(i)
+    call adios_selection_delete(sel)
+  enddo
+  call adios_read_close(adios_handle, adios_err)
+  call check_adios_err(myrank,adios_err)
+  call adios_read_finalize_method(ADIOS_READ_METHOD_BP, adios_err)
+  call check_adios_err(myrank,adios_err)
+
+  call synchronize_all_comm(comm)
+
+  ! checks dimensions
+  if( lnspec /= nspec ) then
+    print*,'error file dimension: nspec in file = ',lnspec, &
+        ' but nspec desired:',nspec
+    print*,'please check file ', file_name
+    call exit_mpi(myrank,'error dimensions in solver_data.bp')
+  endif
+  if( lnglob /= nglob ) then
+    print*,'error file dimension: nglob in file = ',lnglob, &
+        ' but nglob desired:',nglob
+    print*,'please check file ', file_name
+    call exit_mpi(myrank,'error dimensions in solver_data.bp')
+  endif
+
+end subroutine read_arrays_solver_adios

Deleted: seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/read_arrays_solver_adios.f90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/read_arrays_solver_adios.f90	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/read_arrays_solver_adios.f90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -1,488 +0,0 @@
-!=====================================================================
-!
-!          S p e c f e m 3 D  G l o b e  V e r s i o n  6 . 0
-!          --------------------------------------------------
-!
-!          Main authors: Dimitri Komatitsch and Jeroen Tromp
-!                        Princeton University, USA
-!             and CNRS / INRIA / University of Pau, France
-! (c) Princeton University and CNRS / INRIA / University of Pau
-!                            August 2013
-!
-! This 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.
-!
-!=====================================================================
-
-!===============================================================================
-!> \brief Read adios arrays created by the mesher (file: regX_solver_data.bp)
-subroutine read_arrays_solver_adios(iregion_code,myrank, &
-              nspec,nglob,nglob_xy, &
-              nspec_iso,nspec_tiso,nspec_ani, &
-              rho_vp,rho_vs,xstore,ystore,zstore, &
-              xix,xiy,xiz,etax,etay,etaz,gammax,gammay,gammaz, &
-              rhostore, kappavstore,muvstore,kappahstore,muhstore,eta_anisostore, &
-              c11store,c12store,c13store,c14store,c15store,c16store,c22store, &
-              c23store,c24store,c25store,c26store,c33store,c34store,c35store, &
-              c36store,c44store,c45store,c46store,c55store,c56store,c66store, &
-              ibool,idoubling,ispec_is_tiso, &
-              rmassx,rmassy,rmassz,rmass_ocean_load, &
-              READ_KAPPA_MU,READ_TISO, &
-              b_rmassx,b_rmassy)
-
-  use mpi
-  use adios_read_mod
-
-  use constants_solver
-  use specfem_par,only: &
-    ABSORBING_CONDITIONS,TRANSVERSE_ISOTROPY, &
-    ANISOTROPIC_3D_MANTLE,ANISOTROPIC_INNER_CORE,OCEANS,LOCAL_PATH,ABSORBING_CONDITIONS,&
-    EXACT_MASS_MATRIX_FOR_ROTATION
-
-  implicit none
-
-  integer :: iregion_code,myrank
-  integer :: nspec,nglob,nglob_xy
-  integer :: nspec_iso,nspec_tiso,nspec_ani
-
-  ! Stacey
-  real(kind=CUSTOM_REAL),dimension(NGLLX,NGLLY,NGLLZ,nspec):: rho_vp,rho_vs
-
-  real(kind=CUSTOM_REAL), dimension(nglob) :: xstore,ystore,zstore
-
-  real(kind=CUSTOM_REAL), dimension(NGLLX,NGLLY,NGLLZ,nspec) :: &
-    xix,xiy,xiz,etax,etay,etaz,gammax,gammay,gammaz
-
-  ! material properties
-  real(kind=CUSTOM_REAL),dimension(NGLLX,NGLLY,NGLLZ,nspec_iso) :: &
-    rhostore,kappavstore,muvstore
-
-  ! additional arrays for anisotropy stored only where needed to save memory
-  real(kind=CUSTOM_REAL),dimension(NGLLX,NGLLY,NGLLZ,nspec_tiso) :: &
-    kappahstore,muhstore,eta_anisostore
-
-  ! additional arrays for full anisotropy
-  real(kind=CUSTOM_REAL), dimension(NGLLX,NGLLY,NGLLZ,nspec_ani) :: &
-    c11store,c12store,c13store,c14store,c15store,c16store, &
-    c22store,c23store,c24store,c25store,c26store,c33store,c34store, &
-    c35store,c36store,c44store,c45store,c46store,c55store,c56store,c66store
-
-  ! global addressing
-  integer,dimension(NGLLX,NGLLY,NGLLZ,nspec) :: ibool
-  integer, dimension(nspec) :: idoubling
-  logical, dimension(nspec) :: ispec_is_tiso
-
-  ! mass matrices and additional ocean load mass matrix
-  real(kind=CUSTOM_REAL), dimension(nglob_xy) :: rmassx,rmassy
-  real(kind=CUSTOM_REAL), dimension(nglob_xy) :: b_rmassx,b_rmassy
-
-  real(kind=CUSTOM_REAL), dimension(nglob)    :: rmassz
-  real(kind=CUSTOM_REAL), dimension(NGLOB_CRUST_MANTLE_OCEANS) :: rmass_ocean_load
-
-  ! flags to know if we should read Vs and anisotropy arrays
-  logical :: READ_KAPPA_MU,READ_TISO
-
-  character(len=150) :: file_name
-
-  ! local parameters
-  integer :: ierr, comm, lnspec, lnglob, local_dim
-  ! processor identification
-  character(len=150) :: prname
-  ! ADIOS variables
-  integer                 :: adios_err
-  integer(kind=8)         :: adios_group, adios_handle, varid
-  integer(kind=8)         :: adios_groupsize, adios_totalsize
-  integer :: vars_count, attrs_count, current_step, last_step, vsteps
-  character(len=128), dimension(:), allocatable :: adios_names
-  integer(kind=8), dimension(1) :: start, count
-
-  integer(kind=8), dimension(256),target :: selections
-  integer :: sel_num, i
-  integer(kind=8), pointer :: sel => null()
-
-  sel_num = 0
-
-  ! create a prefix for the file name such as LOCAL_PATH/regX_
-  call create_name_database_adios(prname, iregion_code, LOCAL_PATH)
-
-  ! Postpend the actual file name.
-  file_name= trim(prname) // "solver_data.bp"
-  call MPI_Comm_dup (MPI_COMM_WORLD, comm, ierr)
-
-  ! Setup the ADIOS library to read the file
-  call adios_read_init_method (ADIOS_READ_METHOD_BP, comm, &
-      "verbose=1", adios_err)
-  call check_adios_err(myrank,adios_err)
-  call adios_read_open_file (adios_handle, file_name, 0, comm, ierr)
-  call check_adios_err(myrank,adios_err)
-
-  ! read coordinates of the mesh
-  sel_num = sel_num+1
-  sel => selections(sel_num)
-  call adios_selection_writeblock(sel, myrank)
-  call adios_schedule_read(adios_handle, sel, "nspec", 0, 1, &
-     lnspec, adios_err)
-  call adios_schedule_read(adios_handle, sel, "nglob", 0, 1, &
-     lnglob, adios_err)
-  !call adios_get_scalar(adios_handle, "nspec", lnspec, adios_err)
-  !call adios_get_scalar(adios_handle, "nglob", lnglob, adios_err)
-  !call adios_perform_reads(adios_handle, adios_err)
-  !call check_adios_err(myrank,adios_err)
-
-
-  ! mesh coordinates
-  local_dim = nglob
-  start(1) = local_dim*myrank; count(1) = local_dim
-  sel_num = sel_num+1
-  sel => selections(sel_num)
-  call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "xstore/array", 0, 1, &
-      xstore, adios_err)
-  call check_adios_err(myrank,adios_err)
-  call adios_schedule_read(adios_handle, sel, "ystore/array", 0, 1, &
-      ystore, adios_err)
-  call check_adios_err(myrank,adios_err)
-  call adios_schedule_read(adios_handle, sel, "zstore/array", 0, 1, &
-      zstore, adios_err)
-  call check_adios_err(myrank,adios_err)
-  call adios_schedule_read(adios_handle, sel, "rmassz/array", 0, 1, &
-      rmassz, adios_err)
-  call check_adios_err(myrank,adios_err)
-
-  !call adios_perform_reads(adios_handle, adios_err)
-  !call check_adios_err(myrank,adios_err)
-
-  local_dim = NGLLX * NGLLY * NGLLZ * nspec_iso
-  start(1) = local_dim*myrank; count(1) = local_dim
-  sel_num = sel_num+1
-  sel => selections(sel_num)
-  call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "rhostore/array", 0, 1, &
-      rhostore, adios_err)
-  call check_adios_err(myrank,adios_err)
-  call adios_schedule_read(adios_handle, sel, "kappavstore/array", 0, 1, &
-      kappavstore, adios_err)
-  call check_adios_err(myrank,adios_err)
-  if(READ_KAPPA_MU) then
-    call adios_schedule_read(adios_handle, sel, "muvstore/array", 0, 1, &
-        muvstore, adios_err)
-    call check_adios_err(myrank,adios_err)
-  endif
-
-  !call adios_perform_reads(adios_handle, adios_err)
-  !call check_adios_err(myrank,adios_err)
-
-  if(TRANSVERSE_ISOTROPY_VAL .and. READ_TISO) then
-    local_dim = NGLLX * NGLLY * NGLLZ * nspec_tiso
-    start(1) = local_dim*myrank; count(1) = local_dim
-    sel_num = sel_num+1
-    sel => selections(sel_num)
-    call adios_selection_boundingbox (sel , 1, start, count)
-    call adios_schedule_read(adios_handle, sel, "kappahstore/array", 0, 1, &
-        kappahstore, adios_err)
-    call check_adios_err(myrank,adios_err)
-    call adios_schedule_read(adios_handle, sel, "muhstore/array", 0, 1, &
-        muhstore, adios_err)
-    call check_adios_err(myrank,adios_err)
-    call adios_schedule_read(adios_handle, sel, "eta_anisostore/array", 0, 1, &
-        eta_anisostore, adios_err)
-    call check_adios_err(myrank,adios_err)
-  endif
-
-  !call adios_perform_reads(adios_handle, adios_err)
-  !call check_adios_err(myrank,adios_err)
-
-  local_dim = nspec
-  start(1) = local_dim*myrank; count(1) = local_dim
-  sel_num = sel_num+1
-  sel => selections(sel_num)
-  call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "idoubling/array", 0, 1, &
-      idoubling, adios_err)
-  call check_adios_err(myrank,adios_err)
-  call adios_schedule_read(adios_handle, sel, "ispec_is_tiso/array", 0, 1, &
-      ispec_is_tiso, adios_err)
-  call check_adios_err(myrank,adios_err)
-
-  !call adios_perform_reads(adios_handle, adios_err)
-  !call check_adios_err(myrank,adios_err)
-
-  local_dim = NGLLX * NGLLY * NGLLZ * nspec
-  start(1) = local_dim*myrank; count(1) = local_dim
-  sel_num = sel_num+1
-  sel => selections(sel_num)
-  call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "ibool/array", 0, 1, &
-      ibool, adios_err)
-  call check_adios_err(myrank,adios_err)
-  call adios_schedule_read(adios_handle, sel, "xixstore/array", 0, 1, &
-      xix, adios_err)
-  call check_adios_err(myrank,adios_err)
-  call adios_schedule_read(adios_handle, sel, "xiystore/array", 0, 1, &
-      xiy, adios_err)
-  call check_adios_err(myrank,adios_err)
-  call adios_schedule_read(adios_handle, sel, "xizstore/array", 0, 1, &
-      xiz, adios_err)
-  call check_adios_err(myrank,adios_err)
-  call adios_schedule_read(adios_handle, sel, "etaxstore/array", 0, 1, &
-      etax, adios_err)
-  call check_adios_err(myrank,adios_err)
-  call adios_schedule_read(adios_handle, sel, "etaystore/array", 0, 1, &
-      etay, adios_err)
-  call check_adios_err(myrank,adios_err)
-  call adios_schedule_read(adios_handle, sel, "etazstore/array", 0, 1, &
-      etaz, adios_err)
-  call check_adios_err(myrank,adios_err)
-  call adios_schedule_read(adios_handle, sel, "gammaxstore/array", 0, 1, &
-      gammax, adios_err)
-  call check_adios_err(myrank,adios_err)
-  call adios_schedule_read(adios_handle, sel, "gammaystore/array", 0, 1, &
-      gammay, adios_err)
-  call check_adios_err(myrank,adios_err)
-  call adios_schedule_read(adios_handle, sel, "gammazstore/array", 0, 1, &
-      gammaz, adios_err)
-  call check_adios_err(myrank,adios_err)
-
-  !call adios_perform_reads(adios_handle, adios_err)
-  !call check_adios_err(myrank,adios_err)
-
-
-  if(ANISOTROPIC_INNER_CORE_VAL .and. iregion_code == IREGION_INNER_CORE) then
-    local_dim = NGLLX * NGLLY * NGLLZ * nspec_ani
-    start(1) = local_dim*myrank; count(1) = local_dim
-    sel_num = sel_num+1
-    sel => selections(sel_num)
-    call adios_selection_boundingbox (sel , 1, start, count)
-
-    call adios_schedule_read(adios_handle, sel, "c11store/array", 0, 1, &
-        c11store, adios_err)
-    call check_adios_err(myrank,adios_err)
-    call adios_schedule_read(adios_handle, sel, "c12store/array", 0, 1, &
-        c12store, adios_err)
-    call check_adios_err(myrank,adios_err)
-    call adios_schedule_read(adios_handle, sel, "c13store/array", 0, 1, &
-        c13store, adios_err)
-    call check_adios_err(myrank,adios_err)
-    call adios_schedule_read(adios_handle, sel, "c33store/array", 0, 1, &
-        c33store, adios_err)
-    call check_adios_err(myrank,adios_err)
-    call adios_schedule_read(adios_handle, sel, "c44store/array", 0, 1, &
-        c44store, adios_err)
-    call check_adios_err(myrank,adios_err)
-  endif
-
-  if(ANISOTROPIC_3D_MANTLE_VAL .and. iregion_code == IREGION_CRUST_MANTLE) then
-    local_dim = NGLLX * NGLLY * NGLLZ * nspec_ani
-    start(1) = local_dim*myrank; count(1) = local_dim
-    sel_num = sel_num+1
-    sel => selections(sel_num)
-    call adios_selection_boundingbox (sel , 1, start, count)
-
-    call adios_schedule_read(adios_handle, sel, "c11store/array", 0, 1, &
-        c11store, adios_err)
-    call check_adios_err(myrank,adios_err)
-    call adios_schedule_read(adios_handle, sel, "c12store/array", 0, 1, &
-        c12store, adios_err)
-    call check_adios_err(myrank,adios_err)
-    call adios_schedule_read(adios_handle, sel, "c13store/array", 0, 1, &
-        c13store, adios_err)
-    call check_adios_err(myrank,adios_err)
-    call adios_schedule_read(adios_handle, sel, "c14store/array", 0, 1, &
-        c14store, adios_err)
-    call check_adios_err(myrank,adios_err)
-    call adios_schedule_read(adios_handle, sel, "c15store/array", 0, 1, &
-        c15store, adios_err)
-    call check_adios_err(myrank,adios_err)
-    call adios_schedule_read(adios_handle, sel, "c16store/array", 0, 1, &
-        c16store, adios_err)
-    call check_adios_err(myrank,adios_err)
-    call adios_schedule_read(adios_handle, sel, "c22store/array", 0, 1, &
-        c22store, adios_err)
-    call check_adios_err(myrank,adios_err)
-    call adios_schedule_read(adios_handle, sel, "c23store/array", 0, 1, &
-        c23store, adios_err)
-    call check_adios_err(myrank,adios_err)
-    call adios_schedule_read(adios_handle, sel, "c24store/array", 0, 1, &
-        c24store, adios_err)
-    call check_adios_err(myrank,adios_err)
-    call adios_schedule_read(adios_handle, sel, "c25store/array", 0, 1, &
-        c25store, adios_err)
-    call check_adios_err(myrank,adios_err)
-    call adios_schedule_read(adios_handle, sel, "c26store/array", 0, 1, &
-        c26store, adios_err)
-    call check_adios_err(myrank,adios_err)
-    call adios_schedule_read(adios_handle, sel, "c33store/array", 0, 1, &
-        c33store, adios_err)
-    call check_adios_err(myrank,adios_err)
-    call adios_schedule_read(adios_handle, sel, "c34store/array", 0, 1, &
-        c34store, adios_err)
-    call check_adios_err(myrank,adios_err)
-    call adios_schedule_read(adios_handle, sel, "c35store/array", 0, 1, &
-        c35store, adios_err)
-    call check_adios_err(myrank,adios_err)
-    call adios_schedule_read(adios_handle, sel, "c36store/array", 0, 1, &
-        c36store, adios_err)
-    call check_adios_err(myrank,adios_err)
-    call adios_schedule_read(adios_handle, sel, "c44store/array", 0, 1, &
-        c44store, adios_err)
-    call check_adios_err(myrank,adios_err)
-    call adios_schedule_read(adios_handle, sel, "c45store/array", 0, 1, &
-        c45store, adios_err)
-    call adios_schedule_read(adios_handle, sel, "c46store/array", 0, 1, &
-        c46store, adios_err)
-    call check_adios_err(myrank,adios_err)
-    call adios_schedule_read(adios_handle, sel, "c55store/array", 0, 1, &
-        c55store, adios_err)
-    call check_adios_err(myrank,adios_err)
-    call adios_schedule_read(adios_handle, sel, "c56store/array", 0, 1, &
-        c56store, adios_err)
-    call check_adios_err(myrank,adios_err)
-    call adios_schedule_read(adios_handle, sel, "c66store/array", 0, 1, &
-        c66store, adios_err)
-    call check_adios_err(myrank,adios_err)
-  endif
-
-  !call adios_perform_reads(adios_handle, adios_err)
-  !call check_adios_err(myrank,adios_err)
-
-  ! Stacey
-  if(ABSORBING_CONDITIONS) then
-    local_dim = NGLLX * NGLLY * NGLLZ * nspec ! nspec_stacey in meshfem3D
-    start(1) = local_dim*myrank; count(1) = local_dim
-    sel_num = sel_num+1
-    sel => selections(sel_num)
-    call adios_selection_boundingbox (sel , 1, start, count)
-
-    if(iregion_code == IREGION_CRUST_MANTLE) then
-      call adios_schedule_read(adios_handle, sel, "rho_vp/array", 0, 1, &
-          rho_vp, adios_err)
-      call check_adios_err(myrank,adios_err)
-      call adios_schedule_read(adios_handle, sel, "rho_vs/array", 0, 1, &
-          rho_vs, adios_err)
-      call check_adios_err(myrank,adios_err)
-    else if(iregion_code == IREGION_OUTER_CORE) then
-      call adios_schedule_read(adios_handle, sel, "rho_vp/array", 0, 1, &
-          rho_vp, adios_err)
-      call check_adios_err(myrank,adios_err)
-    endif
-
-  endif
-
-  ! mass matrices
-  !
-  ! in the case of Stacey boundary conditions, add C*deltat/2 contribution to
-  ! the mass matrix on Stacey edges for the crust_mantle and outer_core regions
-  ! but not for the inner_core region thus the mass matrix must be replaced by
-  ! three mass matrices including the "C" damping matrix
-  !
-  ! if absorbing_conditions are not set or if NCHUNKS=6, only one mass matrix
-  ! is needed for the sake of performance, only "rmassz" array will be filled
-  ! and "rmassx" & "rmassy" will be obsolete
-  !call adios_perform_reads(adios_handle, adios_err)
-  !call check_adios_err(myrank,adios_err)
-
-  if( (NCHUNKS_VAL /= 6 .and. ABSORBING_CONDITIONS .and. iregion_code == IREGION_CRUST_MANTLE) .or. &
-      (ROTATION_VAL .and. EXACT_MASS_MATRIX_FOR_ROTATION .and. iregion_code == IREGION_CRUST_MANTLE) .or. &
-      (ROTATION_VAL .and. EXACT_MASS_MATRIX_FOR_ROTATION .and. iregion_code == IREGION_INNER_CORE)) then
-
-    local_dim = nglob_xy
-    start(1) = local_dim*myrank; count(1) = local_dim
-    sel_num = sel_num+1
-    sel => selections(sel_num)
-    call adios_selection_boundingbox (sel , 1, start, count)
-
-    call adios_schedule_read(adios_handle, sel, "rmassx/array", 0, 1, &
-        rmassx, adios_err)
-    call check_adios_err(myrank,adios_err)
-    call adios_schedule_read(adios_handle, sel, "rmassy/array", 0, 1, &
-        rmassy, adios_err)
-    call check_adios_err(myrank,adios_err)
-  endif
-
-  local_dim = nglob
-  start(1) = local_dim*myrank; count(1) = local_dim
-  sel_num = sel_num+1
-  sel => selections(sel_num)
-  call adios_selection_boundingbox (sel , 1, start, count)
-
-  call adios_schedule_read(adios_handle, sel, "rmassz/array", 0, 1, &
-      rmassz, adios_err)
-  call check_adios_err(myrank,adios_err)
-
-  if( (ROTATION_VAL .and. EXACT_MASS_MATRIX_FOR_ROTATION .and. iregion_code == IREGION_CRUST_MANTLE) .or. &
-      (ROTATION_VAL .and. EXACT_MASS_MATRIX_FOR_ROTATION .and. iregion_code == IREGION_INNER_CORE))then
-    local_dim = nglob_xy
-    start(1) = local_dim*myrank; count(1) = local_dim
-    sel_num = sel_num+1
-    sel => selections(sel_num)
-    call adios_selection_boundingbox (sel , 1, start, count)
-
-    call adios_schedule_read(adios_handle, sel, "b_rmassx/array", 0, 1, &
-        b_rmassx, adios_err)
-    call check_adios_err(myrank,adios_err)
-    call adios_schedule_read(adios_handle, sel, "b_rmassy/array", 0, 1, &
-        b_rmassy, adios_err)
-    call check_adios_err(myrank,adios_err)
-  endif
-
-  !call adios_perform_reads(adios_handle, adios_err)
-  !call check_adios_err(myrank,adios_err)
-
-  ! read additional ocean load mass matrix
-  if(OCEANS_VAL .and. iregion_code == IREGION_CRUST_MANTLE) then
-    local_dim = NGLOB_CRUST_MANTLE_OCEANS ! nglob_oceans
-    start(1) = local_dim*myrank; count(1) = local_dim
-    sel_num = sel_num+1
-    sel => selections(sel_num)
-    call adios_selection_boundingbox (sel , 1, start, count)
-
-    call adios_schedule_read(adios_handle, sel, "rmass_ocean_load/array", &
-        0, 1, rmass_ocean_load, adios_err)
-    call check_adios_err(myrank,adios_err)
-
-    !call adios_perform_reads(adios_handle, adios_err)
-    !call check_adios_err(myrank,adios_err)
-  endif
-
-
-  call adios_perform_reads(adios_handle, adios_err)
-  call check_adios_err(myrank,adios_err)
-
-
-  ! Clean everything and close the ADIOS file
-  do i = 1, sel_num
-    sel => selections(i)
-    call adios_selection_delete(sel)
-  enddo
-  call adios_read_close(adios_handle, adios_err)
-  call check_adios_err(myrank,adios_err)
-  call adios_read_finalize_method(ADIOS_READ_METHOD_BP, adios_err)
-  call check_adios_err(myrank,adios_err)
-
-  call synchronize_all()
-  ! checks dimensions
-  if( lnspec /= nspec ) then
-    print*,'error file dimension: nspec in file = ',lnspec, &
-        ' but nspec desired:',nspec
-    print*,'please check file ', file_name
-    call exit_mpi(myrank,'error dimensions in solver_data.bp')
-  endif
-  if( lnglob /= nglob ) then
-    print*,'error file dimension: nglob in file = ',lnglob, &
-        ' but nglob desired:',nglob
-    print*,'please check file ', file_name
-    call exit_mpi(myrank,'error dimensions in solver_data.bp')
-  endif
-
-end subroutine read_arrays_solver_adios

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/read_attenuation_adios.f90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/read_attenuation_adios.f90	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/read_attenuation_adios.f90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -29,49 +29,48 @@
 !===============================================================================
 !> \brief Read adios attenuation arrays created by the mesher
 !         (regX_attenuation.bp)
-subroutine read_attenuation_adios(myrank, prname, &
+subroutine read_attenuation_adios(myrank, iregion_code, &
                                   factor_common, scale_factor, tau_s, vnspec, T_c_source)
 
   use constants_solver
-  use mpi
   use adios_read_mod
-  use specfem_par,only: ATTENUATION_VAL
+  use adios_helpers_mod, only: check_adios_err
+  use specfem_par,       only: ATTENUATION_VAL, LOCAL_PATH
 
   implicit none
 
   integer :: myrank
 
   integer :: vnspec
-  real(kind=CUSTOM_REAL), dimension(ATT1_VAL,ATT2_VAL,ATT3_VAL,vnspec)       :: scale_factor
+  real(kind=CUSTOM_REAL), dimension(ATT1_VAL,ATT2_VAL,ATT3_VAL,vnspec) :: scale_factor
   real(kind=CUSTOM_REAL), dimension(N_SLS,ATT1_VAL,ATT2_VAL,ATT3_VAL,vnspec) :: factor_common
   double precision, dimension(N_SLS)                 :: tau_s
 
-  character(len=150) :: prname
+  integer :: iregion_code
 
   ! local parameters
-  integer :: i,j,k,ispec,ier
-  double precision, dimension(N_SLS) :: tau_e, fc
-  double precision :: omsb, Q_mu, sf, T_c_source, scale_t
-  integer :: sizeprocs, comm, ierr
-  character(len=150) :: file_name
-  integer(kind=8) :: group_size_inc
-  integer :: local_dim, global_dim, offset
+  double precision :: T_c_source
+  integer :: comm, ierr
+  character(len=256) :: file_name
+  integer :: local_dim
   ! ADIOS variables
   integer                 :: adios_err
-  integer(kind=8)         :: adios_group, adios_handle, varid, sel
-  integer(kind=8)         :: adios_groupsize, adios_totalsize
-  integer :: vars_count, attrs_count, current_step, last_step, vsteps
-  character(len=128), dimension(:), allocatable :: adios_names
+  integer(kind=8)         :: adios_handle, sel
   integer(kind=8), dimension(1) :: start, count
 
+  character(len=128)      :: region_name, region_name_scalar
+
+  write(region_name,"('reg',i1, '/')") iregion_code
+  write(region_name_scalar,"('reg',i1)") iregion_code
+
   ! checks if attenuation is on and anything to do
   if( .not. ATTENUATION_VAL) return
 
-  call MPI_Comm_dup (MPI_COMM_WORLD, comm, ierr)
+  call world_duplicate(comm)
 
   ! All of the following reads use the output parameters as their temporary arrays
   ! use the filename to determine the actual contents of the read
-  file_name= trim(prname) // "attenuation.bp"
+  file_name= trim(LOCAL_PATH) // "/attenuation.bp"
 
   call adios_read_init_method (ADIOS_READ_METHOD_BP, comm, &
       "verbose=1", adios_err)
@@ -80,7 +79,7 @@
   call check_adios_err(myrank,adios_err)
 
   call adios_selection_writeblock(sel, myrank)
-  call adios_schedule_read(adios_handle, sel, "T_c_source", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "t_c_source", 0, 1, &
      T_c_source, adios_err)
 
   call adios_perform_reads(adios_handle, adios_err)
@@ -89,7 +88,7 @@
   local_dim = size (tau_s)
   start(1) = local_dim*myrank; count(1) = local_dim
   call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "tau_s/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "tau_s/array", 0, 1, &
     tau_s, adios_err)
   call check_adios_err(myrank,adios_err)
 
@@ -99,7 +98,7 @@
   local_dim = size (factor_common)
   start(1) = local_dim*myrank; count(1) = local_dim
   call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "tau_e_store/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "tau_e_store/array", 0, 1, &
     factor_common, adios_err)
   call check_adios_err(myrank,adios_err)
 
@@ -109,7 +108,7 @@
   local_dim = size (scale_factor)
   start(1) = local_dim*myrank; count(1) = local_dim
   call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "Qmu_store/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "Qmu_store/array", 0, 1, &
     scale_factor, adios_err)
   call check_adios_err(myrank,adios_err)
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/read_forward_arrays_adios.F90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/read_forward_arrays_adios.F90	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/read_forward_arrays_adios.F90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -36,8 +36,8 @@
 !!       and read_forward_arrays_adios() are not factorized, because
 !>       the latest read the bp file in "b_" prefixed arrays
 subroutine read_intermediate_forward_arrays_adios()
+
   ! External imports
-  use mpi
   use adios_read_mod
   ! Internal imports
   use specfem_par
@@ -45,28 +45,23 @@
   use specfem_par_innercore
   use specfem_par_outercore
 
+  use adios_helpers_mod, only: check_adios_err
+
   implicit none
   ! Local parameters
-  integer :: sizeprocs, comm, ierr
-  character(len=150) :: file_name
-  integer(kind=8) :: group_size_inc
-  integer :: local_dim, global_dim, offset
-!  integer, parameter :: num_arrays = 9 ! TODO correct number
-!  character(len=256), dimension(num_arrays) :: local_dims1, local_dims2, &
-!      global_dims1, global_dims2, offsets1, offsets2, array_name
+  integer :: comm, ierr
+  character(len=256) :: file_name
+  integer :: local_dim
   ! ADIOS variables
   integer                 :: adios_err
-  integer(kind=8)         :: adios_group, adios_handle, varid, sel
-  integer(kind=8)         :: adios_groupsize, adios_totalsize
-  integer :: vars_count, attrs_count, current_step, last_step, vsteps
-  character(len=128), dimension(:), allocatable :: adios_names
+  integer(kind=8)         :: adios_handle, sel
   integer(kind=8), dimension(1) :: start, count
 
 
   file_name = trim(LOCAL_TMP_PATH) // "/dump_all_arrays_adios.bp"
-  call world_size(sizeprocs)
-  call MPI_Comm_dup (MPI_COMM_WORLD, comm, ierr)
 
+  call world_duplicate(comm)
+
   call adios_read_init_method (ADIOS_READ_METHOD_BP, comm, &
       "verbose=1", adios_err)
   call check_adios_err(myrank,adios_err)
@@ -231,7 +226,7 @@
   call adios_read_finalize_method(ADIOS_READ_METHOD_BP, adios_err)
   call check_adios_err(myrank,adios_err)
 
-  call synchronize_all()
+  call synchronize_all_comm(comm)
 
 end subroutine read_intermediate_forward_arrays_adios
 
@@ -241,8 +236,8 @@
 !!       and read_forward_arrays_adios() are not factorized, because
 !>       the latest read the bp file in "b_" prefixed arrays
 subroutine read_forward_arrays_adios()
+
   ! External imports
-  use mpi
   use adios_read_mod
   ! Internal imports
   use specfem_par
@@ -250,32 +245,30 @@
   use specfem_par_innercore
   use specfem_par_outercore
 
+  use adios_helpers_mod, only: check_adios_err
+
   implicit none
   ! Local parameters
-  integer :: sizeprocs, comm, ierr
-  character(len=150) :: file_name
-  integer(kind=8) :: group_size_inc
-  integer :: local_dim, global_dim, offset
+  integer :: comm, ierr
+  character(len=256) :: file_name
+  integer :: local_dim
   ! ADIOS variables
   integer                 :: adios_err
-  integer(kind=8)         :: adios_group, adios_handle, varid, sel
-  integer(kind=8)         :: adios_groupsize, adios_totalsize
-  integer :: vars_count, attrs_count, current_step, last_step, vsteps
-  character(len=128), dimension(:), allocatable :: adios_names
+  integer(kind=8)         :: adios_handle, sel
   integer(kind=8), dimension(1) :: start, count
 
-
   file_name = trim(LOCAL_TMP_PATH) // "/save_forward_arrays.bp"
-  call world_size(sizeprocs)
-  call MPI_Comm_dup (MPI_COMM_WORLD, comm, ierr)
 
+  call world_duplicate(comm)
+
+  ! opens adios file
   call adios_read_init_method (ADIOS_READ_METHOD_BP, comm, &
       "verbose=1", adios_err)
   call check_adios_err(myrank,adios_err)
   call adios_read_open_file (adios_handle, file_name, 0, comm, ierr)
   call check_adios_err(myrank,adios_err)
 
-
+  ! reads in arrays
   local_dim = NDIM * NGLOB_CRUST_MANTLE
   start(1) = local_dim*myrank; count(1) = local_dim
   call adios_selection_boundingbox (sel , 1, start, count)
@@ -437,6 +430,6 @@
   call adios_read_finalize_method(ADIOS_READ_METHOD_BP, adios_err)
   call check_adios_err(myrank,adios_err)
 
-  call synchronize_all()
+  call synchronize_all_comm(comm)
 
 end subroutine read_forward_arrays_adios

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/read_mesh_databases.F90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/read_mesh_databases.F90	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/read_mesh_databases.F90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -39,6 +39,18 @@
   double precision :: tCPU
   double precision, external :: wtime
 
+#ifdef USE_SERIAL_CASCADE_FOR_IOs
+  logical,parameter :: SYNC_READING = .false.
+#else
+  logical,parameter :: SYNC_READING = .true.
+#endif
+
+  ! user output
+  if( myrank == 0 ) then
+    write(IMAIN,*) 'mesh databases:'
+    call flush_IMAIN()
+  endif
+
   ! get MPI starting time
   time_start = wtime()
 
@@ -52,39 +64,72 @@
   ! read arrays created by the mesher
 
   ! reads "solver_data.bin" files for crust and mantle
+  if( SYNC_READING ) call synchronize_all()
+  if( myrank == 0 ) then
+    write(IMAIN,*) '  reading in crust/mantle databases...'
+    call flush_IMAIN()
+  endif
   call read_mesh_databases_CM()
 
   ! reads "solver_data.bin" files for outer core
+  if( SYNC_READING ) call synchronize_all()
+  if( myrank == 0 ) then
+    write(IMAIN,*) '  reading in outer core databases...'
+    call flush_IMAIN()
+  endif
   call read_mesh_databases_OC()
 
   ! reads "solver_data.bin" files for inner core
+  if( SYNC_READING ) call synchronize_all()
+  if( myrank == 0 ) then
+    write(IMAIN,*) '  reading in inner core databases...'
+    call flush_IMAIN()
+  endif
   call read_mesh_databases_IC()
 
   ! reads "boundary.bin" files to couple mantle with outer core and inner core boundaries
-  if( ADIOS_ENABLED .and. ADIOS_FOR_ARRAYS_SOLVER ) then
-    call read_mesh_databases_coupling_adios()
-  else
-    call read_mesh_databases_coupling()
+  if( SYNC_READING ) call synchronize_all()
+  if( myrank == 0 ) then
+    write(IMAIN,*) '  reading in coupling surface databases...'
+    call flush_IMAIN()
   endif
+  call read_mesh_databases_coupling()
 
   ! reads "addressing.txt" 2-D addressing (needed for Stacey boundaries)
+  if( SYNC_READING ) call synchronize_all()
+  if( myrank == 0 ) then
+    write(IMAIN,*) '  reading in addressing...'
+    call flush_IMAIN()
+  endif
   call read_mesh_databases_addressing()
 
+
   ! sets up MPI interfaces, inner/outer elements and mesh coloring
+  if( SYNC_READING ) call synchronize_all()
+  if( myrank == 0 ) then
+    write(IMAIN,*) '  reading in mpi databases...'
+    call flush_IMAIN()
+  endif
   call read_mesh_databases_MPI()
 
   ! absorbing boundaries
   if(ABSORBING_CONDITIONS) then
     ! reads "stacey.bin" files
-    if( ADIOS_ENABLED .and. ADIOS_FOR_ARRAYS_SOLVER ) then
-      call read_mesh_databases_stacey_adios()
-    else
-      call read_mesh_databases_stacey()
+    if( SYNC_READING ) call synchronize_all()
+    if( myrank == 0 ) then
+      write(IMAIN,*) '  reading in stacey databases...'
+      call flush_IMAIN()
     endif
+    call read_mesh_databases_stacey()
   endif
 
   ! kernels on regular grids
   if (SAVE_REGULAR_KL) then
+    if( SYNC_READING ) call synchronize_all()
+    if( myrank == 0 ) then
+      write(IMAIN,*) '  reading in regular kernel databases...'
+      call flush_IMAIN()
+    endif
     call read_mesh_databases_regular_kl()
   endif
 
@@ -176,48 +221,48 @@
   ! reads databases file
   if( ADIOS_ENABLED .and. ADIOS_FOR_ARRAYS_SOLVER ) then
     call read_arrays_solver_adios(IREGION_CRUST_MANTLE,myrank, &
-        NSPEC_CRUST_MANTLE,NGLOB_CRUST_MANTLE,NGLOB_XY_CM, &
-        nspec_iso,nspec_tiso,nspec_ani, &
-        rho_vp_crust_mantle,rho_vs_crust_mantle, &
-        xstore_crust_mantle,ystore_crust_mantle,zstore_crust_mantle, &
-        xix_crust_mantle,xiy_crust_mantle,xiz_crust_mantle, &
-        etax_crust_mantle,etay_crust_mantle,etaz_crust_mantle, &
-        gammax_crust_mantle,gammay_crust_mantle,gammaz_crust_mantle, &
-        rhostore_crust_mantle,kappavstore_crust_mantle,muvstore_crust_mantle, &
-        kappahstore_crust_mantle,muhstore_crust_mantle,eta_anisostore_crust_mantle, &
-        c11store_crust_mantle,c12store_crust_mantle,c13store_crust_mantle, &
-        c14store_crust_mantle,c15store_crust_mantle,c16store_crust_mantle, &
-        c22store_crust_mantle,c23store_crust_mantle,c24store_crust_mantle, &
-        c25store_crust_mantle,c26store_crust_mantle,c33store_crust_mantle, &
-        c34store_crust_mantle,c35store_crust_mantle,c36store_crust_mantle, &
-        c44store_crust_mantle,c45store_crust_mantle,c46store_crust_mantle, &
-        c55store_crust_mantle,c56store_crust_mantle,c66store_crust_mantle, &
-        ibool_crust_mantle,dummy_idoubling,ispec_is_tiso_crust_mantle, &
-        rmassx_crust_mantle,rmassy_crust_mantle,rmassz_crust_mantle,rmass_ocean_load, &
-        READ_KAPPA_MU,READ_TISO, &
-        b_rmassx_crust_mantle,b_rmassy_crust_mantle)
+                                  NSPEC_CRUST_MANTLE,NGLOB_CRUST_MANTLE,NGLOB_XY_CM, &
+                                  nspec_iso,nspec_tiso,nspec_ani, &
+                                  rho_vp_crust_mantle,rho_vs_crust_mantle, &
+                                  xstore_crust_mantle,ystore_crust_mantle,zstore_crust_mantle, &
+                                  xix_crust_mantle,xiy_crust_mantle,xiz_crust_mantle, &
+                                  etax_crust_mantle,etay_crust_mantle,etaz_crust_mantle, &
+                                  gammax_crust_mantle,gammay_crust_mantle,gammaz_crust_mantle, &
+                                  rhostore_crust_mantle,kappavstore_crust_mantle,muvstore_crust_mantle, &
+                                  kappahstore_crust_mantle,muhstore_crust_mantle,eta_anisostore_crust_mantle, &
+                                  c11store_crust_mantle,c12store_crust_mantle,c13store_crust_mantle, &
+                                  c14store_crust_mantle,c15store_crust_mantle,c16store_crust_mantle, &
+                                  c22store_crust_mantle,c23store_crust_mantle,c24store_crust_mantle, &
+                                  c25store_crust_mantle,c26store_crust_mantle,c33store_crust_mantle, &
+                                  c34store_crust_mantle,c35store_crust_mantle,c36store_crust_mantle, &
+                                  c44store_crust_mantle,c45store_crust_mantle,c46store_crust_mantle, &
+                                  c55store_crust_mantle,c56store_crust_mantle,c66store_crust_mantle, &
+                                  ibool_crust_mantle,dummy_idoubling,ispec_is_tiso_crust_mantle, &
+                                  rmassx_crust_mantle,rmassy_crust_mantle,rmassz_crust_mantle,rmass_ocean_load, &
+                                  READ_KAPPA_MU,READ_TISO, &
+                                  b_rmassx_crust_mantle,b_rmassy_crust_mantle)
   else
     call read_arrays_solver(IREGION_CRUST_MANTLE,myrank, &
-        NSPEC_CRUST_MANTLE,NGLOB_CRUST_MANTLE,NGLOB_XY_CM, &
-        nspec_iso,nspec_tiso,nspec_ani, &
-        rho_vp_crust_mantle,rho_vs_crust_mantle, &
-        xstore_crust_mantle,ystore_crust_mantle,zstore_crust_mantle, &
-        xix_crust_mantle,xiy_crust_mantle,xiz_crust_mantle, &
-        etax_crust_mantle,etay_crust_mantle,etaz_crust_mantle, &
-        gammax_crust_mantle,gammay_crust_mantle,gammaz_crust_mantle, &
-        rhostore_crust_mantle,kappavstore_crust_mantle,muvstore_crust_mantle, &
-        kappahstore_crust_mantle,muhstore_crust_mantle,eta_anisostore_crust_mantle, &
-        c11store_crust_mantle,c12store_crust_mantle,c13store_crust_mantle, &
-        c14store_crust_mantle,c15store_crust_mantle,c16store_crust_mantle, &
-        c22store_crust_mantle,c23store_crust_mantle,c24store_crust_mantle, &
-        c25store_crust_mantle,c26store_crust_mantle,c33store_crust_mantle, &
-        c34store_crust_mantle,c35store_crust_mantle,c36store_crust_mantle, &
-        c44store_crust_mantle,c45store_crust_mantle,c46store_crust_mantle, &
-        c55store_crust_mantle,c56store_crust_mantle,c66store_crust_mantle, &
-        ibool_crust_mantle,dummy_idoubling,ispec_is_tiso_crust_mantle, &
-        rmassx_crust_mantle,rmassy_crust_mantle,rmassz_crust_mantle,rmass_ocean_load, &
-        READ_KAPPA_MU,READ_TISO, &
-        b_rmassx_crust_mantle,b_rmassy_crust_mantle)
+                            NSPEC_CRUST_MANTLE,NGLOB_CRUST_MANTLE,NGLOB_XY_CM, &
+                            nspec_iso,nspec_tiso,nspec_ani, &
+                            rho_vp_crust_mantle,rho_vs_crust_mantle, &
+                            xstore_crust_mantle,ystore_crust_mantle,zstore_crust_mantle, &
+                            xix_crust_mantle,xiy_crust_mantle,xiz_crust_mantle, &
+                            etax_crust_mantle,etay_crust_mantle,etaz_crust_mantle, &
+                            gammax_crust_mantle,gammay_crust_mantle,gammaz_crust_mantle, &
+                            rhostore_crust_mantle,kappavstore_crust_mantle,muvstore_crust_mantle, &
+                            kappahstore_crust_mantle,muhstore_crust_mantle,eta_anisostore_crust_mantle, &
+                            c11store_crust_mantle,c12store_crust_mantle,c13store_crust_mantle, &
+                            c14store_crust_mantle,c15store_crust_mantle,c16store_crust_mantle, &
+                            c22store_crust_mantle,c23store_crust_mantle,c24store_crust_mantle, &
+                            c25store_crust_mantle,c26store_crust_mantle,c33store_crust_mantle, &
+                            c34store_crust_mantle,c35store_crust_mantle,c36store_crust_mantle, &
+                            c44store_crust_mantle,c45store_crust_mantle,c46store_crust_mantle, &
+                            c55store_crust_mantle,c56store_crust_mantle,c66store_crust_mantle, &
+                            ibool_crust_mantle,dummy_idoubling,ispec_is_tiso_crust_mantle, &
+                            rmassx_crust_mantle,rmassy_crust_mantle,rmassz_crust_mantle,rmass_ocean_load, &
+                            READ_KAPPA_MU,READ_TISO, &
+                            b_rmassx_crust_mantle,b_rmassy_crust_mantle)
   endif
 
   ! check that the number of points in this slice is correct
@@ -263,7 +308,6 @@
     nullify(b_rmassz_crust_mantle)
   endif
 
-
   end subroutine read_mesh_databases_CM
 
 !
@@ -309,51 +353,50 @@
   if(ier /= 0) stop 'error allocating dummy rmass and dummy ispec/idoubling in outer core'
 
   ! reads in mesh arrays
-
   if( ADIOS_ENABLED .and. ADIOS_FOR_ARRAYS_SOLVER ) then
     call read_arrays_solver_adios(IREGION_OUTER_CORE,myrank, &
-              NSPEC_OUTER_CORE,NGLOB_OUTER_CORE,NGLOB_XY_dummy, &
-              nspec_iso,nspec_tiso,nspec_ani, &
-              vp_outer_core,dummy_array, &
-              xstore_outer_core,ystore_outer_core,zstore_outer_core, &
-              xix_outer_core,xiy_outer_core,xiz_outer_core, &
-              etax_outer_core,etay_outer_core,etaz_outer_core, &
-              gammax_outer_core,gammay_outer_core,gammaz_outer_core, &
-              rhostore_outer_core,kappavstore_outer_core,dummy_array, &
-              dummy_array,dummy_array,dummy_array, &
-              dummy_array,dummy_array,dummy_array, &
-              dummy_array,dummy_array,dummy_array, &
-              dummy_array,dummy_array,dummy_array, &
-              dummy_array,dummy_array,dummy_array, &
-              dummy_array,dummy_array,dummy_array, &
-              dummy_array,dummy_array,dummy_array, &
-              dummy_array,dummy_array,dummy_array, &
-              ibool_outer_core,dummy_idoubling_outer_core,dummy_ispec_is_tiso, &
-              dummy_rmass,dummy_rmass,rmass_outer_core,dummy_array, &
-              READ_KAPPA_MU,READ_TISO, &
-              dummy_rmass,dummy_rmass)
+                                  NSPEC_OUTER_CORE,NGLOB_OUTER_CORE,NGLOB_XY_dummy, &
+                                  nspec_iso,nspec_tiso,nspec_ani, &
+                                  vp_outer_core,dummy_array, &
+                                  xstore_outer_core,ystore_outer_core,zstore_outer_core, &
+                                  xix_outer_core,xiy_outer_core,xiz_outer_core, &
+                                  etax_outer_core,etay_outer_core,etaz_outer_core, &
+                                  gammax_outer_core,gammay_outer_core,gammaz_outer_core, &
+                                  rhostore_outer_core,kappavstore_outer_core,dummy_array, &
+                                  dummy_array,dummy_array,dummy_array, &
+                                  dummy_array,dummy_array,dummy_array, &
+                                  dummy_array,dummy_array,dummy_array, &
+                                  dummy_array,dummy_array,dummy_array, &
+                                  dummy_array,dummy_array,dummy_array, &
+                                  dummy_array,dummy_array,dummy_array, &
+                                  dummy_array,dummy_array,dummy_array, &
+                                  dummy_array,dummy_array,dummy_array, &
+                                  ibool_outer_core,dummy_idoubling_outer_core,dummy_ispec_is_tiso, &
+                                  dummy_rmass,dummy_rmass,rmass_outer_core,dummy_array, &
+                                  READ_KAPPA_MU,READ_TISO, &
+                                  dummy_rmass,dummy_rmass)
   else
     call read_arrays_solver(IREGION_OUTER_CORE,myrank, &
-              NSPEC_OUTER_CORE,NGLOB_OUTER_CORE,NGLOB_XY_dummy, &
-              nspec_iso,nspec_tiso,nspec_ani, &
-              vp_outer_core,dummy_array, &
-              xstore_outer_core,ystore_outer_core,zstore_outer_core, &
-              xix_outer_core,xiy_outer_core,xiz_outer_core, &
-              etax_outer_core,etay_outer_core,etaz_outer_core, &
-              gammax_outer_core,gammay_outer_core,gammaz_outer_core, &
-              rhostore_outer_core,kappavstore_outer_core,dummy_array, &
-              dummy_array,dummy_array,dummy_array, &
-              dummy_array,dummy_array,dummy_array, &
-              dummy_array,dummy_array,dummy_array, &
-              dummy_array,dummy_array,dummy_array, &
-              dummy_array,dummy_array,dummy_array, &
-              dummy_array,dummy_array,dummy_array, &
-              dummy_array,dummy_array,dummy_array, &
-              dummy_array,dummy_array,dummy_array, &
-              ibool_outer_core,dummy_idoubling_outer_core,dummy_ispec_is_tiso, &
-              dummy_rmass,dummy_rmass,rmass_outer_core,dummy_array, &
-              READ_KAPPA_MU,READ_TISO, &
-              dummy_rmass,dummy_rmass)
+                            NSPEC_OUTER_CORE,NGLOB_OUTER_CORE,NGLOB_XY_dummy, &
+                            nspec_iso,nspec_tiso,nspec_ani, &
+                            vp_outer_core,dummy_array, &
+                            xstore_outer_core,ystore_outer_core,zstore_outer_core, &
+                            xix_outer_core,xiy_outer_core,xiz_outer_core, &
+                            etax_outer_core,etay_outer_core,etaz_outer_core, &
+                            gammax_outer_core,gammay_outer_core,gammaz_outer_core, &
+                            rhostore_outer_core,kappavstore_outer_core,dummy_array, &
+                            dummy_array,dummy_array,dummy_array, &
+                            dummy_array,dummy_array,dummy_array, &
+                            dummy_array,dummy_array,dummy_array, &
+                            dummy_array,dummy_array,dummy_array, &
+                            dummy_array,dummy_array,dummy_array, &
+                            dummy_array,dummy_array,dummy_array, &
+                            dummy_array,dummy_array,dummy_array, &
+                            dummy_array,dummy_array,dummy_array, &
+                            ibool_outer_core,dummy_idoubling_outer_core,dummy_ispec_is_tiso, &
+                            dummy_rmass,dummy_rmass,rmass_outer_core,dummy_array, &
+                            READ_KAPPA_MU,READ_TISO, &
+                            dummy_rmass,dummy_rmass)
   endif
 
   deallocate(dummy_idoubling_outer_core,dummy_ispec_is_tiso,dummy_rmass)
@@ -434,48 +477,48 @@
   ! reads in arrays
   if( ADIOS_ENABLED .and. ADIOS_FOR_ARRAYS_SOLVER ) then
     call read_arrays_solver_adios(IREGION_INNER_CORE,myrank, &
-              NSPEC_INNER_CORE,NGLOB_INNER_CORE,NGLOB_XY_IC, &
-              nspec_iso,nspec_tiso,nspec_ani, &
-              dummy_array,dummy_array, &
-              xstore_inner_core,ystore_inner_core,zstore_inner_core, &
-              xix_inner_core,xiy_inner_core,xiz_inner_core, &
-              etax_inner_core,etay_inner_core,etaz_inner_core, &
-              gammax_inner_core,gammay_inner_core,gammaz_inner_core, &
-              rhostore_inner_core,kappavstore_inner_core,muvstore_inner_core, &
-              dummy_array,dummy_array,dummy_array, &
-              c11store_inner_core,c12store_inner_core,c13store_inner_core, &
-              dummy_array,dummy_array,dummy_array, &
-              dummy_array,dummy_array,dummy_array, &
-              dummy_array,dummy_array,c33store_inner_core, &
-              dummy_array,dummy_array,dummy_array, &
-              c44store_inner_core,dummy_array,dummy_array, &
-              dummy_array,dummy_array,dummy_array, &
-              ibool_inner_core,idoubling_inner_core,dummy_ispec_is_tiso, &
-              rmassx_inner_core,rmassy_inner_core,rmassz_inner_core,dummy_array, &
-              READ_KAPPA_MU,READ_TISO, &
-              b_rmassx_inner_core,b_rmassy_inner_core)
+                                  NSPEC_INNER_CORE,NGLOB_INNER_CORE,NGLOB_XY_IC, &
+                                  nspec_iso,nspec_tiso,nspec_ani, &
+                                  dummy_array,dummy_array, &
+                                  xstore_inner_core,ystore_inner_core,zstore_inner_core, &
+                                  xix_inner_core,xiy_inner_core,xiz_inner_core, &
+                                  etax_inner_core,etay_inner_core,etaz_inner_core, &
+                                  gammax_inner_core,gammay_inner_core,gammaz_inner_core, &
+                                  rhostore_inner_core,kappavstore_inner_core,muvstore_inner_core, &
+                                  dummy_array,dummy_array,dummy_array, &
+                                  c11store_inner_core,c12store_inner_core,c13store_inner_core, &
+                                  dummy_array,dummy_array,dummy_array, &
+                                  dummy_array,dummy_array,dummy_array, &
+                                  dummy_array,dummy_array,c33store_inner_core, &
+                                  dummy_array,dummy_array,dummy_array, &
+                                  c44store_inner_core,dummy_array,dummy_array, &
+                                  dummy_array,dummy_array,dummy_array, &
+                                  ibool_inner_core,idoubling_inner_core,dummy_ispec_is_tiso, &
+                                  rmassx_inner_core,rmassy_inner_core,rmassz_inner_core,dummy_array, &
+                                  READ_KAPPA_MU,READ_TISO, &
+                                  b_rmassx_inner_core,b_rmassy_inner_core)
   else
     call read_arrays_solver(IREGION_INNER_CORE,myrank, &
-              NSPEC_INNER_CORE,NGLOB_INNER_CORE,NGLOB_XY_IC, &
-              nspec_iso,nspec_tiso,nspec_ani, &
-              dummy_array,dummy_array, &
-              xstore_inner_core,ystore_inner_core,zstore_inner_core, &
-              xix_inner_core,xiy_inner_core,xiz_inner_core, &
-              etax_inner_core,etay_inner_core,etaz_inner_core, &
-              gammax_inner_core,gammay_inner_core,gammaz_inner_core, &
-              rhostore_inner_core,kappavstore_inner_core,muvstore_inner_core, &
-              dummy_array,dummy_array,dummy_array, &
-              c11store_inner_core,c12store_inner_core,c13store_inner_core, &
-              dummy_array,dummy_array,dummy_array, &
-              dummy_array,dummy_array,dummy_array, &
-              dummy_array,dummy_array,c33store_inner_core, &
-              dummy_array,dummy_array,dummy_array, &
-              c44store_inner_core,dummy_array,dummy_array, &
-              dummy_array,dummy_array,dummy_array, &
-              ibool_inner_core,idoubling_inner_core,dummy_ispec_is_tiso, &
-              rmassx_inner_core,rmassy_inner_core,rmassz_inner_core,dummy_array, &
-              READ_KAPPA_MU,READ_TISO, &
-              b_rmassx_inner_core,b_rmassy_inner_core)
+                            NSPEC_INNER_CORE,NGLOB_INNER_CORE,NGLOB_XY_IC, &
+                            nspec_iso,nspec_tiso,nspec_ani, &
+                            dummy_array,dummy_array, &
+                            xstore_inner_core,ystore_inner_core,zstore_inner_core, &
+                            xix_inner_core,xiy_inner_core,xiz_inner_core, &
+                            etax_inner_core,etay_inner_core,etaz_inner_core, &
+                            gammax_inner_core,gammay_inner_core,gammaz_inner_core, &
+                            rhostore_inner_core,kappavstore_inner_core,muvstore_inner_core, &
+                            dummy_array,dummy_array,dummy_array, &
+                            c11store_inner_core,c12store_inner_core,c13store_inner_core, &
+                            dummy_array,dummy_array,dummy_array, &
+                            dummy_array,dummy_array,dummy_array, &
+                            dummy_array,dummy_array,c33store_inner_core, &
+                            dummy_array,dummy_array,dummy_array, &
+                            c44store_inner_core,dummy_array,dummy_array, &
+                            dummy_array,dummy_array,dummy_array, &
+                            ibool_inner_core,idoubling_inner_core,dummy_ispec_is_tiso, &
+                            rmassx_inner_core,rmassy_inner_core,rmassz_inner_core,dummy_array, &
+                            READ_KAPPA_MU,READ_TISO, &
+                            b_rmassx_inner_core,b_rmassy_inner_core)
   endif
 
   deallocate(dummy_ispec_is_tiso)
@@ -544,147 +587,174 @@
   integer :: njunk1,njunk2,njunk3
   integer :: ier
 
-  ! user output
-  if( myrank == 0 ) write(IMAIN,*) 'reading coupling surfaces...'
+  ! reads in arrays
+  if( ADIOS_ENABLED .and. ADIOS_FOR_ARRAYS_SOLVER ) then
+    call read_mesh_databases_coupling_adios()
+  else
+    ! crust and mantle
+    ! create name of database
+    call create_name_database(prname,myrank,IREGION_CRUST_MANTLE,LOCAL_PATH)
 
-  ! crust and mantle
-  ! create name of database
-  call create_name_database(prname,myrank,IREGION_CRUST_MANTLE,LOCAL_PATH)
+    ! Stacey put back
+    open(unit=27,file=prname(1:len_trim(prname))//'boundary.bin', &
+          status='old',form='unformatted',action='read',iostat=ier)
+    if( ier /= 0 ) call exit_mpi(myrank,'error opening crust_mantle boundary.bin file')
 
-  ! Stacey put back
-  open(unit=27,file=prname(1:len_trim(prname))//'boundary.bin', &
-        status='old',form='unformatted',action='read',iostat=ier)
-  if( ier /= 0 ) call exit_mpi(myrank,'error opening crust_mantle boundary.bin file')
+    read(27) nspec2D_xmin_crust_mantle
+    read(27) nspec2D_xmax_crust_mantle
+    read(27) nspec2D_ymin_crust_mantle
+    read(27) nspec2D_ymax_crust_mantle
+    read(27) njunk1
+    read(27) njunk2
 
-  read(27) nspec2D_xmin_crust_mantle
-  read(27) nspec2D_xmax_crust_mantle
-  read(27) nspec2D_ymin_crust_mantle
-  read(27) nspec2D_ymax_crust_mantle
-  read(27) njunk1
-  read(27) njunk2
+  ! boundary parameters
+    read(27) ibelm_xmin_crust_mantle
+    read(27) ibelm_xmax_crust_mantle
+    read(27) ibelm_ymin_crust_mantle
+    read(27) ibelm_ymax_crust_mantle
+    read(27) ibelm_bottom_crust_mantle
+    read(27) ibelm_top_crust_mantle
 
-! boundary parameters
-  read(27) ibelm_xmin_crust_mantle
-  read(27) ibelm_xmax_crust_mantle
-  read(27) ibelm_ymin_crust_mantle
-  read(27) ibelm_ymax_crust_mantle
-  read(27) ibelm_bottom_crust_mantle
-  read(27) ibelm_top_crust_mantle
+    read(27) normal_xmin_crust_mantle
+    read(27) normal_xmax_crust_mantle
+    read(27) normal_ymin_crust_mantle
+    read(27) normal_ymax_crust_mantle
+    read(27) normal_bottom_crust_mantle
+    read(27) normal_top_crust_mantle
 
-  read(27) normal_xmin_crust_mantle
-  read(27) normal_xmax_crust_mantle
-  read(27) normal_ymin_crust_mantle
-  read(27) normal_ymax_crust_mantle
-  read(27) normal_bottom_crust_mantle
-  read(27) normal_top_crust_mantle
+    read(27) jacobian2D_xmin_crust_mantle
+    read(27) jacobian2D_xmax_crust_mantle
+    read(27) jacobian2D_ymin_crust_mantle
+    read(27) jacobian2D_ymax_crust_mantle
+    read(27) jacobian2D_bottom_crust_mantle
+    read(27) jacobian2D_top_crust_mantle
+    close(27)
 
-  read(27) jacobian2D_xmin_crust_mantle
-  read(27) jacobian2D_xmax_crust_mantle
-  read(27) jacobian2D_ymin_crust_mantle
-  read(27) jacobian2D_ymax_crust_mantle
-  read(27) jacobian2D_bottom_crust_mantle
-  read(27) jacobian2D_top_crust_mantle
-  close(27)
+    ! read parameters to couple fluid and solid regions
+    !
+    ! outer core
 
-  ! read parameters to couple fluid and solid regions
-  !
-  ! outer core
+    ! create name of database
+    call create_name_database(prname,myrank,IREGION_OUTER_CORE,LOCAL_PATH)
 
-  ! create name of database
-  call create_name_database(prname,myrank,IREGION_OUTER_CORE,LOCAL_PATH)
+    ! boundary parameters
 
-  ! boundary parameters
+    ! Stacey put back
+    open(unit=27,file=prname(1:len_trim(prname))//'boundary.bin', &
+          status='old',form='unformatted',action='read',iostat=ier)
+    if( ier /= 0 ) call exit_mpi(myrank,'error opening outer_core boundary.bin file')
 
-  ! Stacey put back
-  open(unit=27,file=prname(1:len_trim(prname))//'boundary.bin', &
-        status='old',form='unformatted',action='read',iostat=ier)
-  if( ier /= 0 ) call exit_mpi(myrank,'error opening outer_core boundary.bin file')
+    read(27) nspec2D_xmin_outer_core
+    read(27) nspec2D_xmax_outer_core
+    read(27) nspec2D_ymin_outer_core
+    read(27) nspec2D_ymax_outer_core
+    read(27) njunk1
+    read(27) njunk2
 
-  read(27) nspec2D_xmin_outer_core
-  read(27) nspec2D_xmax_outer_core
-  read(27) nspec2D_ymin_outer_core
-  read(27) nspec2D_ymax_outer_core
-  read(27) njunk1
-  read(27) njunk2
+    nspec2D_zmin_outer_core = NSPEC2D_BOTTOM(IREGION_OUTER_CORE)
 
-  nspec2D_zmin_outer_core = NSPEC2D_BOTTOM(IREGION_OUTER_CORE)
+    read(27) ibelm_xmin_outer_core
+    read(27) ibelm_xmax_outer_core
+    read(27) ibelm_ymin_outer_core
+    read(27) ibelm_ymax_outer_core
+    read(27) ibelm_bottom_outer_core
+    read(27) ibelm_top_outer_core
 
-  read(27) ibelm_xmin_outer_core
-  read(27) ibelm_xmax_outer_core
-  read(27) ibelm_ymin_outer_core
-  read(27) ibelm_ymax_outer_core
-  read(27) ibelm_bottom_outer_core
-  read(27) ibelm_top_outer_core
+    read(27) normal_xmin_outer_core
+    read(27) normal_xmax_outer_core
+    read(27) normal_ymin_outer_core
+    read(27) normal_ymax_outer_core
+    read(27) normal_bottom_outer_core
+    read(27) normal_top_outer_core
 
-  read(27) normal_xmin_outer_core
-  read(27) normal_xmax_outer_core
-  read(27) normal_ymin_outer_core
-  read(27) normal_ymax_outer_core
-  read(27) normal_bottom_outer_core
-  read(27) normal_top_outer_core
+    read(27) jacobian2D_xmin_outer_core
+    read(27) jacobian2D_xmax_outer_core
+    read(27) jacobian2D_ymin_outer_core
+    read(27) jacobian2D_ymax_outer_core
+    read(27) jacobian2D_bottom_outer_core
+    read(27) jacobian2D_top_outer_core
+    close(27)
 
-  read(27) jacobian2D_xmin_outer_core
-  read(27) jacobian2D_xmax_outer_core
-  read(27) jacobian2D_ymin_outer_core
-  read(27) jacobian2D_ymax_outer_core
-  read(27) jacobian2D_bottom_outer_core
-  read(27) jacobian2D_top_outer_core
-  close(27)
+    !
+    ! inner core
+    !
 
-  !
-  ! inner core
-  !
+    ! create name of database
+    call create_name_database(prname,myrank,IREGION_INNER_CORE,LOCAL_PATH)
 
-  ! create name of database
-  call create_name_database(prname,myrank,IREGION_INNER_CORE,LOCAL_PATH)
+    ! read info for vertical edges for central cube matching in inner core
+    open(unit=27,file=prname(1:len_trim(prname))//'boundary.bin', &
+          status='old',form='unformatted',action='read',iostat=ier)
+    if( ier /= 0 ) call exit_mpi(myrank,'error opening inner_core boundary.bin file')
 
-  ! read info for vertical edges for central cube matching in inner core
-  open(unit=27,file=prname(1:len_trim(prname))//'boundary.bin', &
-        status='old',form='unformatted',action='read',iostat=ier)
-  if( ier /= 0 ) call exit_mpi(myrank,'error opening inner_core boundary.bin file')
+    read(27) nspec2D_xmin_inner_core
+    read(27) nspec2D_xmax_inner_core
+    read(27) nspec2D_ymin_inner_core
+    read(27) nspec2D_ymax_inner_core
+    read(27) njunk1
+    read(27) njunk2
 
-  read(27) nspec2D_xmin_inner_core
-  read(27) nspec2D_xmax_inner_core
-  read(27) nspec2D_ymin_inner_core
-  read(27) nspec2D_ymax_inner_core
-  read(27) njunk1
-  read(27) njunk2
+    ! boundary parameters
+    read(27) ibelm_xmin_inner_core
+    read(27) ibelm_xmax_inner_core
+    read(27) ibelm_ymin_inner_core
+    read(27) ibelm_ymax_inner_core
+    read(27) ibelm_bottom_inner_core
+    read(27) ibelm_top_inner_core
+    close(27)
 
-  ! boundary parameters
-  read(27) ibelm_xmin_inner_core
-  read(27) ibelm_xmax_inner_core
-  read(27) ibelm_ymin_inner_core
-  read(27) ibelm_ymax_inner_core
-  read(27) ibelm_bottom_inner_core
-  read(27) ibelm_top_inner_core
-  close(27)
+    ! -- Boundary Mesh for crust and mantle ---
+    if (SAVE_BOUNDARY_MESH .and. SIMULATION_TYPE == 3) then
+      call create_name_database(prname,myrank,IREGION_CRUST_MANTLE,LOCAL_PATH)
 
-  ! -- Boundary Mesh for crust and mantle ---
-  if (SAVE_BOUNDARY_MESH .and. SIMULATION_TYPE == 3) then
+      open(unit=27,file=prname(1:len_trim(prname))//'boundary_disc.bin', &
+            status='old',form='unformatted',action='read',iostat=ier)
+      if( ier /= 0 ) call exit_mpi(myrank,'error opening boundary_disc.bin file')
 
-    call create_name_database(prname,myrank,IREGION_CRUST_MANTLE,LOCAL_PATH)
+      read(27) njunk1,njunk2,njunk3
+      if (njunk1 /= NSPEC2D_MOHO .and. njunk2 /= NSPEC2D_400 .and. njunk3 /= NSPEC2D_670) &
+                 call exit_mpi(myrank, 'Error reading ibelm_disc.bin file')
+      read(27) ibelm_moho_top
+      read(27) ibelm_moho_bot
+      read(27) ibelm_400_top
+      read(27) ibelm_400_bot
+      read(27) ibelm_670_top
+      read(27) ibelm_670_bot
+      read(27) normal_moho
+      read(27) normal_400
+      read(27) normal_670
+      close(27)
+    endif
 
-    open(unit=27,file=prname(1:len_trim(prname))//'boundary_disc.bin', &
-          status='old',form='unformatted',action='read',iostat=ier)
-    if( ier /= 0 ) call exit_mpi(myrank,'error opening boundary_disc.bin file')
+  endif ! ADIOS
 
-    read(27) njunk1,njunk2,njunk3
-    if (njunk1 /= NSPEC2D_MOHO .and. njunk2 /= NSPEC2D_400 .and. njunk3 /= NSPEC2D_670) &
-               call exit_mpi(myrank, 'Error reading ibelm_disc.bin file')
-    read(27) ibelm_moho_top
-    read(27) ibelm_moho_bot
-    read(27) ibelm_400_top
-    read(27) ibelm_400_bot
-    read(27) ibelm_670_top
-    read(27) ibelm_670_bot
-    read(27) normal_moho
-    read(27) normal_400
-    read(27) normal_670
-    close(27)
+  ! checks dimensions
+  ! crust mantle
+  if( nspec2d_xmin_crust_mantle < 0 .or. nspec2d_xmin_crust_mantle > NSPEC2DMAX_XMIN_XMAX_CM .or. &
+      nspec2d_xmax_crust_mantle < 0 .or. nspec2d_xmax_crust_mantle > NSPEC2DMAX_XMIN_XMAX_CM .or. &
+      nspec2d_ymin_crust_mantle < 0 .or. nspec2d_ymin_crust_mantle > NSPEC2DMAX_YMIN_YMAX_CM .or. &
+      nspec2d_ymax_crust_mantle < 0 .or. nspec2d_ymax_crust_mantle > NSPEC2DMAX_YMIN_YMAX_CM ) &
+      call exit_mpi(myrank,'error reading crust/mantle boundary')
+  ! outer core
+  if (nspec2D_xmin_outer_core < 0 .or. nspec2d_xmin_outer_core > NSPEC2DMAX_XMIN_XMAX_OC .or. &
+      nspec2D_xmax_outer_core < 0 .or. nspec2d_xmax_outer_core > NSPEC2DMAX_XMIN_XMAX_OC .or. &
+      nspec2D_ymin_outer_core < 0 .or. nspec2d_ymin_outer_core > NSPEC2DMAX_YMIN_YMAX_OC .or. &
+      nspec2D_ymax_outer_core < 0 .or. nspec2d_ymax_outer_core > NSPEC2DMAX_YMIN_YMAX_OC ) &
+    call exit_mpi(myrank, 'Error reading outer core boundary')
+  ! inner core
+  if (nspec2D_xmin_inner_core < 0 .or. nspec2d_xmin_inner_core > NSPEC2DMAX_XMIN_XMAX_IC .or. &
+      nspec2D_xmax_inner_core < 0 .or. nspec2d_xmax_inner_core > NSPEC2DMAX_XMIN_XMAX_IC .or. &
+      nspec2D_ymin_inner_core < 0 .or. nspec2d_ymin_inner_core > NSPEC2DMAX_YMIN_YMAX_IC .or. &
+      nspec2D_ymax_inner_core < 0 .or. nspec2d_ymax_inner_core > NSPEC2DMAX_YMIN_YMAX_IC ) &
+    call exit_mpi(myrank, 'Error reading inner core boundary')
 
+  ! initializes
+  nspec2D_zmin_outer_core = NSPEC2D_BOTTOM(IREGION_OUTER_CORE)
+
+  ! Boundary Mesh for crust and mantle
+  if (SAVE_BOUNDARY_MESH .and. SIMULATION_TYPE == 3) then
     k_top = 1
     k_bot = NGLLZ
-
     ! initialization
     moho_kl = 0.; d400_kl = 0.; d670_kl = 0.; cmb_kl = 0.; icb_kl = 0.
   endif
@@ -883,22 +953,22 @@
 
   ! user output
   if(myrank == 0) then
-    write(IMAIN,*) 'for overlapping of communications with calculations:'
+    write(IMAIN,*) '  for overlapping of communications with calculations:'
     write(IMAIN,*)
 
     percentage_edge = 100. * nspec_outer_crust_mantle / real(NSPEC_CRUST_MANTLE)
-    write(IMAIN,*) 'percentage of edge elements in crust/mantle ',percentage_edge,'%'
-    write(IMAIN,*) 'percentage of volume elements in crust/mantle ',100. - percentage_edge,'%'
+    write(IMAIN,*) '  percentage of edge elements in crust/mantle ',percentage_edge,'%'
+    write(IMAIN,*) '  percentage of volume elements in crust/mantle ',100. - percentage_edge,'%'
     write(IMAIN,*)
 
     percentage_edge = 100.* nspec_outer_outer_core / real(NSPEC_OUTER_CORE)
-    write(IMAIN,*) 'percentage of edge elements in outer core ',percentage_edge,'%'
-    write(IMAIN,*) 'percentage of volume elements in outer core ',100. - percentage_edge,'%'
+    write(IMAIN,*) '  percentage of edge elements in outer core ',percentage_edge,'%'
+    write(IMAIN,*) '  percentage of volume elements in outer core ',100. - percentage_edge,'%'
     write(IMAIN,*)
 
     percentage_edge = 100. * nspec_outer_inner_core / real(NSPEC_INNER_CORE)
-    write(IMAIN,*) 'percentage of edge elements in inner core ',percentage_edge,'%'
-    write(IMAIN,*) 'percentage of volume elements in inner core ',100. - percentage_edge,'%'
+    write(IMAIN,*) '  percentage of edge elements in inner core ',percentage_edge,'%'
+    write(IMAIN,*) '  percentage of volume elements in inner core ',100. - percentage_edge,'%'
     write(IMAIN,*)
     call flush_IMAIN()
   endif
@@ -1177,41 +1247,46 @@
   ! local parameters
   integer :: ier
 
-  ! crust and mantle
+  ! reads in arrays
+  if( ADIOS_ENABLED .and. ADIOS_FOR_ARRAYS_SOLVER ) then
+    call read_mesh_databases_stacey_adios()
+  else
+    ! crust and mantle
 
-  ! create name of database
-  call create_name_database(prname,myrank,IREGION_CRUST_MANTLE,LOCAL_PATH)
+    ! create name of database
+    call create_name_database(prname,myrank,IREGION_CRUST_MANTLE,LOCAL_PATH)
 
-  ! read arrays for Stacey conditions
-  open(unit=27,file=prname(1:len_trim(prname))//'stacey.bin', &
-        status='old',form='unformatted',action='read',iostat=ier)
-  if( ier /= 0 ) call exit_MPI(myrank,'error opening stacey.bin file for crust mantle')
+    ! read arrays for Stacey conditions
+    open(unit=27,file=prname(1:len_trim(prname))//'stacey.bin', &
+          status='old',form='unformatted',action='read',iostat=ier)
+    if( ier /= 0 ) call exit_MPI(myrank,'error opening stacey.bin file for crust mantle')
 
-  read(27) nimin_crust_mantle
-  read(27) nimax_crust_mantle
-  read(27) njmin_crust_mantle
-  read(27) njmax_crust_mantle
-  read(27) nkmin_xi_crust_mantle
-  read(27) nkmin_eta_crust_mantle
-  close(27)
+    read(27) nimin_crust_mantle
+    read(27) nimax_crust_mantle
+    read(27) njmin_crust_mantle
+    read(27) njmax_crust_mantle
+    read(27) nkmin_xi_crust_mantle
+    read(27) nkmin_eta_crust_mantle
+    close(27)
 
-  ! outer core
+    ! outer core
 
-  ! create name of database
-  call create_name_database(prname,myrank,IREGION_OUTER_CORE,LOCAL_PATH)
+    ! create name of database
+    call create_name_database(prname,myrank,IREGION_OUTER_CORE,LOCAL_PATH)
 
-  ! read arrays for Stacey conditions
-  open(unit=27,file=prname(1:len_trim(prname))//'stacey.bin', &
-        status='old',form='unformatted',action='read',iostat=ier)
-  if( ier /= 0 ) call exit_MPI(myrank,'error opening stacey.bin file for outer core')
+    ! read arrays for Stacey conditions
+    open(unit=27,file=prname(1:len_trim(prname))//'stacey.bin', &
+          status='old',form='unformatted',action='read',iostat=ier)
+    if( ier /= 0 ) call exit_MPI(myrank,'error opening stacey.bin file for outer core')
 
-  read(27) nimin_outer_core
-  read(27) nimax_outer_core
-  read(27) njmin_outer_core
-  read(27) njmax_outer_core
-  read(27) nkmin_xi_outer_core
-  read(27) nkmin_eta_outer_core
-  close(27)
+    read(27) nimin_outer_core
+    read(27) nimax_outer_core
+    read(27) njmin_outer_core
+    read(27) njmax_outer_core
+    read(27) nkmin_xi_outer_core
+    read(27) nkmin_eta_outer_core
+    close(27)
+  endif ! ADIOS
 
   end subroutine read_mesh_databases_stacey
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/read_mesh_databases_adios.f90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/read_mesh_databases_adios.f90	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/read_mesh_databases_adios.f90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -30,495 +30,483 @@
 !> \brief Read adios boundary arrays created by the mesher
 !!        (file: regX_boundary.bp)
 subroutine read_mesh_databases_coupling_adios()
+
   use adios_read_mod
 
 ! to couple mantle with outer core
-
-  use mpi
   use specfem_par
   use specfem_par_crustmantle
   use specfem_par_innercore
   use specfem_par_outercore
 
+  use adios_helpers_mod, only: check_adios_err
+
   implicit none
 
   ! local parameters
   integer :: njunk1,njunk2,njunk3
-  integer :: sizeprocs, comm, ierr
-  character(len=150) :: file_name
-  integer(kind=8) :: group_size_inc
-  integer :: local_dim, global_dim, offset
+  integer :: comm, ierr
+  character(len=256) :: file_name
+  integer :: local_dim
   ! ADIOS variables
   integer                 :: adios_err
-  integer(kind=8)         :: adios_group, adios_handle, varid, sel
-  integer(kind=8)         :: adios_groupsize, adios_totalsize
-  integer :: vars_count, attrs_count, current_step, last_step, vsteps
-  character(len=128), dimension(:), allocatable :: adios_names
+  integer(kind=8)         :: adios_handle, sel
   integer(kind=8), dimension(1) :: start, count
 
-  call MPI_Comm_dup (MPI_COMM_WORLD, comm, ierr)
+  character(len=128)      :: region_name
 
-  ! crust and mantle
-  ! create name of database
-  call create_name_database_adios(prname, IREGION_CRUST_MANTLE, LOCAL_PATH)
-  file_name= trim(prname) // "boundary.bp"
+  call world_duplicate(comm)
 
+  file_name= trim(LOCAL_PATH) // "/boundary.bp"
+
+  ! opens adios file
   call adios_read_init_method (ADIOS_READ_METHOD_BP, comm, &
       "verbose=1", adios_err)
   call check_adios_err(myrank,adios_err)
   call adios_read_open_file (adios_handle, file_name, 0, comm, ierr)
   call check_adios_err(myrank,adios_err)
 
+  ! crust and mantle
+
+  write(region_name,"('reg',i1, '/')") IREGION_CRUST_MANTLE
+
   call adios_selection_writeblock(sel, myrank)
-  call adios_schedule_read(adios_handle, sel, "nspec2D_xmin", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "nspec2D_xmin", 0, 1, &
      nspec2D_xmin_crust_mantle, adios_err)
-  call adios_schedule_read(adios_handle, sel, "nspec2D_xmax", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "nspec2D_xmax", 0, 1, &
      nspec2D_xmax_crust_mantle, adios_err)
-  call adios_schedule_read(adios_handle, sel, "nspec2D_ymin", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "nspec2D_ymin", 0, 1, &
      nspec2D_ymin_crust_mantle, adios_err)
-  call adios_schedule_read(adios_handle, sel, "nspec2D_ymax", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "nspec2D_ymax", 0, 1, &
      nspec2D_ymax_crust_mantle, adios_err)
-  !call adios_get_scalar(adios_handle, "nspec2D_xmin", &
-      !nspec2D_xmin_crust_mantle, adios_err)
-  !call adios_get_scalar(adios_handle, "nspec2D_xmax", &
-      !nspec2D_xmax_crust_mantle, adios_err)
-  !call adios_get_scalar(adios_handle, "nspec2D_ymin", &
-      !nspec2D_ymin_crust_mantle, adios_err)
-  !call adios_get_scalar(adios_handle, "nspec2D_ymax", &
-      !nspec2D_ymax_crust_mantle, adios_err)
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "NSPEC2D_BOTTOM", 0, 1, &
+     njunk1, adios_err)
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "NSPEC2D_TOP", 0, 1, &
+     njunk2, adios_err)
+
   call adios_perform_reads(adios_handle, adios_err)
   call check_adios_err(myrank,adios_err)
 
-  !local_dim = NSPEC2DMAX_XMIN_XMAX_CM
-  local_dim = size (ibelm_xmin_crust_mantle)
-  start(1) = local_dim*myrank; count(1) = local_dim
+  ! daniel debug
+  !call synchronize_all()
+  !print*,myrank,'crust mantle'
+  !print*,myrank,'nspec2d xmin:',nspec2d_xmin_crust_mantle
+  !print*,myrank,'nspec2d xmax:',nspec2d_xmax_crust_mantle
+  !print*,myrank,'nspec2d ymin:',nspec2d_ymin_crust_mantle
+  !print*,myrank,'nspec2d ymax:',nspec2d_ymax_crust_mantle
+  !call synchronize_all()
+
+  ! boundary elements
+
+  local_dim = NSPEC2DMAX_XMIN_XMAX_CM
+  start(1) = local_dim * myrank; count(1) = local_dim
+
   call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "ibelm_xmin/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "ibelm_xmin/array", 0, 1, &
     ibelm_xmin_crust_mantle, adios_err)
   call check_adios_err(myrank,adios_err)
-  call adios_schedule_read(adios_handle, sel, "ibelm_xmax/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "ibelm_xmax/array", 0, 1, &
     ibelm_xmax_crust_mantle, adios_err)
   call check_adios_err(myrank,adios_err)
 
   call adios_perform_reads(adios_handle, adios_err)
   call check_adios_err(myrank,adios_err)
 
-  !local_dim = NSPEC2DMAX_YMIN_YMAX_CM
-  local_dim = size (ibelm_ymin_crust_mantle)
-  start(1) = local_dim*myrank; count(1) = local_dim
+  local_dim = NSPEC2DMAX_YMIN_YMAX_CM
+  start(1) = local_dim * myrank; count(1) = local_dim
+
   call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "ibelm_ymin/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "ibelm_ymin/array", 0, 1, &
     ibelm_ymin_crust_mantle, adios_err)
   call check_adios_err(myrank,adios_err)
-  call adios_schedule_read(adios_handle, sel, "ibelm_ymax/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "ibelm_ymax/array", 0, 1, &
     ibelm_ymax_crust_mantle, adios_err)
   call check_adios_err(myrank,adios_err)
 
   call adios_perform_reads(adios_handle, adios_err)
   call check_adios_err(myrank,adios_err)
 
-  !local_dim = NSPEC2D_BOTTOM_CM
-  local_dim = size (ibelm_bottom_crust_mantle)
-  start(1) = local_dim*myrank; count(1) = local_dim
+  local_dim = NSPEC2D_BOTTOM_CM
+  start(1) = local_dim * myrank; count(1) = local_dim
+
   call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "ibelm_bottom/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "ibelm_bottom/array", 0, 1, &
     ibelm_bottom_crust_mantle, adios_err)
   call check_adios_err(myrank,adios_err)
 
   call adios_perform_reads(adios_handle, adios_err)
   call check_adios_err(myrank,adios_err)
 
-  !local_dim = NSPEC2D_TOP_CM
-  local_dim = size (ibelm_top_crust_mantle)
-  start(1) = local_dim*myrank; count(1) = local_dim
+  local_dim = NSPEC2D_TOP_CM
+  start(1) = local_dim * myrank; count(1) = local_dim
+
   call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "ibelm_top/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "ibelm_top/array", 0, 1, &
     ibelm_top_crust_mantle, adios_err)
   call check_adios_err(myrank,adios_err)
 
   call adios_perform_reads(adios_handle, adios_err)
   call check_adios_err(myrank,adios_err)
 
-  !local_dim = NDIM*NGLLY*NGLLZ*NSPEC2DMAX_XMIN_XMAX_CM
-  local_dim = size (normal_xmin_crust_mantle)
-  start(1) = local_dim*myrank; count(1) = local_dim
+  local_dim = NDIM*NGLLY*NGLLZ*NSPEC2DMAX_XMIN_XMAX_CM
+  start(1) = local_dim * myrank; count(1) = local_dim
+
   call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "normal_xmin/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "normal_xmin/array", 0, 1, &
     normal_xmin_crust_mantle, adios_err)
   call check_adios_err(myrank,adios_err)
-  call adios_schedule_read(adios_handle, sel, "normal_xmax/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "normal_xmax/array", 0, 1, &
     normal_xmax_crust_mantle, adios_err)
   call check_adios_err(myrank,adios_err)
 
   call adios_perform_reads(adios_handle, adios_err)
   call check_adios_err(myrank,adios_err)
 
-  !local_dim = NDIM*NGLLX*NGLLZ*NSPEC2DMAX_YMIN_YMAX_CM
-  local_dim = size (normal_ymin_crust_mantle)
-  start(1) = local_dim*myrank; count(1) = local_dim
+  local_dim = NDIM*NGLLX*NGLLZ*NSPEC2DMAX_YMIN_YMAX_CM
+  start(1) = local_dim * myrank; count(1) = local_dim
+
   call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "normal_ymin/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "normal_ymin/array", 0, 1, &
     normal_ymin_crust_mantle, adios_err)
   call check_adios_err(myrank,adios_err)
-  call adios_schedule_read(adios_handle, sel, "normal_ymax/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "normal_ymax/array", 0, 1, &
     normal_ymax_crust_mantle, adios_err)
   call check_adios_err(myrank,adios_err)
 
   call adios_perform_reads(adios_handle, adios_err)
   call check_adios_err(myrank,adios_err)
 
-  !local_dim = NDIM*NGLLX*NGLLY*NSPEC2D_BOTTOM_CM
-  local_dim = size (ibelm_bottom_crust_mantle)
-  start(1) = local_dim*myrank; count(1) = local_dim
+  local_dim = NDIM*NGLLX*NGLLY*NSPEC2D_BOTTOM_CM
+  start(1) = local_dim * myrank; count(1) = local_dim
+
   call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "normal_bottom/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "normal_bottom/array", 0, 1, &
     normal_bottom_crust_mantle, adios_err)
   call check_adios_err(myrank,adios_err)
 
   call adios_perform_reads(adios_handle, adios_err)
   call check_adios_err(myrank,adios_err)
 
-  !local_dim = NDIM*NGLLX*NGLLY*NSPEC2D_TOP_CM
-  local_dim = size (ibelm_top_crust_mantle)
-  start(1) = local_dim*myrank; count(1) = local_dim
+  local_dim = NDIM*NGLLX*NGLLY*NSPEC2D_TOP_CM
+  start(1) = local_dim * myrank; count(1) = local_dim
+
   call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "normal_top/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "normal_top/array", 0, 1, &
     normal_top_crust_mantle, adios_err)
   call check_adios_err(myrank,adios_err)
 
   call adios_perform_reads(adios_handle, adios_err)
   call check_adios_err(myrank,adios_err)
 
-  !local_dim = NGLLY*NGLLZ*NSPEC2DMAX_XMIN_XMAX_CM
-  local_dim = size (jacobian2D_xmin_crust_mantle)
-  start(1) = local_dim*myrank; count(1) = local_dim
+  local_dim = NGLLY*NGLLZ*NSPEC2DMAX_XMIN_XMAX_CM
+  start(1) = local_dim * myrank; count(1) = local_dim
+
   call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "jacobian2D_xmin/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "jacobian2D_xmin/array", 0, 1, &
     jacobian2D_xmin_crust_mantle, adios_err)
   call check_adios_err(myrank,adios_err)
-  call adios_schedule_read(adios_handle, sel, "jacobian2D_xmax/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "jacobian2D_xmax/array", 0, 1, &
     jacobian2D_xmax_crust_mantle, adios_err)
   call check_adios_err(myrank,adios_err)
 
   call adios_perform_reads(adios_handle, adios_err)
   call check_adios_err(myrank,adios_err)
 
-  !local_dim = NGLLX*NGLLZ*NSPEC2DMAX_YMIN_YMAX_CM
-  local_dim = size (jacobian2D_ymin_crust_mantle)
-  start(1) = local_dim*myrank; count(1) = local_dim
+  local_dim = NGLLX*NGLLZ*NSPEC2DMAX_YMIN_YMAX_CM
+  start(1) = local_dim * myrank; count(1) = local_dim
+
   call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "jacobian2D_ymin/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "jacobian2D_ymin/array", 0, 1, &
     jacobian2D_ymin_crust_mantle, adios_err)
   call check_adios_err(myrank,adios_err)
-  call adios_schedule_read(adios_handle, sel, "jacobian2D_ymax/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "jacobian2D_ymax/array", 0, 1, &
     jacobian2D_ymax_crust_mantle, adios_err)
   call check_adios_err(myrank,adios_err)
 
   call adios_perform_reads(adios_handle, adios_err)
   call check_adios_err(myrank,adios_err)
 
-  !local_dim = NGLLX*NGLLY*NSPEC2D_BOTTOM_CM
-  local_dim = size (jacobian2D_bottom_crust_mantle)
-  start(1) = local_dim*myrank; count(1) = local_dim
+  local_dim = NGLLX*NGLLY*NSPEC2D_BOTTOM_CM
+  start(1) = local_dim * myrank; count(1) = local_dim
+
   call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "jacobian2D_bottom/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "jacobian2D_bottom/array", 0, 1, &
     jacobian2D_bottom_crust_mantle, adios_err)
   call check_adios_err(myrank,adios_err)
 
   call adios_perform_reads(adios_handle, adios_err)
   call check_adios_err(myrank,adios_err)
 
-  !local_dim = NGLLX*NGLLY*NSPEC2D_TOP_CM
-  local_dim = size (jacobian2D_top_crust_mantle)
-  start(1) = local_dim*myrank; count(1) = local_dim
+  local_dim = NGLLX*NGLLY*NSPEC2D_TOP_CM
+  start(1) = local_dim * myrank; count(1) = local_dim
+
   call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "jacobian2D_top/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "jacobian2D_top/array", 0, 1, &
     jacobian2D_top_crust_mantle, adios_err)
   call check_adios_err(myrank,adios_err)
 
   call adios_perform_reads(adios_handle, adios_err)
   call check_adios_err(myrank,adios_err)
-! boundary parameters
 
-  ! Close ADIOS handler to the restart file.
-  call adios_selection_delete(sel)
-  call adios_read_close(adios_handle, adios_err)
-  call check_adios_err(myrank,adios_err)
-  call adios_read_finalize_method(ADIOS_READ_METHOD_BP, adios_err)
-  call check_adios_err(myrank,adios_err)
 
   ! read parameters to couple fluid and solid regions
   !
   ! outer core
 
-  ! create name of database
-  call create_name_database_adios(prname, IREGION_OUTER_CORE, LOCAL_PATH)
-  file_name= trim(prname) // "boundary.bp"
+  write(region_name,"('reg',i1, '/')") IREGION_OUTER_CORE
 
-  call adios_read_init_method (ADIOS_READ_METHOD_BP, comm, &
-      "verbose=1", adios_err)
-  call check_adios_err(myrank,adios_err)
-  call adios_read_open_file (adios_handle, file_name, 0, comm, ierr)
-  call check_adios_err(myrank,adios_err)
-
   call adios_selection_writeblock(sel, myrank)
-  call adios_schedule_read(adios_handle, sel, "nspec2D_xmin", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "nspec2D_xmin", 0, 1, &
      nspec2D_xmin_outer_core, adios_err)
-  call adios_schedule_read(adios_handle, sel, "nspec2D_xmax", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "nspec2D_xmax", 0, 1, &
      nspec2D_xmax_outer_core, adios_err)
-  call adios_schedule_read(adios_handle, sel, "nspec2D_ymin", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "nspec2D_ymin", 0, 1, &
      nspec2D_ymin_outer_core, adios_err)
-  call adios_schedule_read(adios_handle, sel, "nspec2D_ymax", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "nspec2D_ymax", 0, 1, &
      nspec2D_ymax_outer_core, adios_err)
-  !call adios_get_scalar(adios_handle, "nspec2D_xmin", &
-      !nspec2D_xmin_outer_core, adios_err)
-  !call adios_get_scalar(adios_handle, "nspec2D_xmax", &
-      !nspec2D_xmax_outer_core, adios_err)
-  !call adios_get_scalar(adios_handle, "nspec2D_ymin", &
-      !nspec2D_ymin_outer_core, adios_err)
-  !call adios_get_scalar(adios_handle, "nspec2D_ymax", &
-      !nspec2D_ymax_outer_core, adios_err)
+
   call adios_perform_reads(adios_handle, adios_err)
   call check_adios_err(myrank,adios_err)
 
-  nspec2D_zmin_outer_core = NSPEC2D_BOTTOM(IREGION_OUTER_CORE)
+  ! daniel debug
+  !call synchronize_all()
+  !print*,myrank,'outer core'
+  !print*,myrank,'nspec2d xmin:',nspec2d_xmin_outer_core
+  !print*,myrank,'nspec2d xmax:',nspec2d_xmax_outer_core
+  !print*,myrank,'nspec2d ymin:',nspec2d_ymin_outer_core
+  !print*,myrank,'nspec2d ymax:',nspec2d_ymax_outer_core
+  !call synchronize_all()
 
-  !local_dim = NSPEC2DMAX_XMIN_XMAX_OC
-  local_dim = size (ibelm_xmin_outer_core)
-  start(1) = local_dim*myrank; count(1) = local_dim
+  ! boundary elements
+
+  local_dim = NSPEC2DMAX_XMIN_XMAX_OC
+  start(1) = local_dim * myrank; count(1) = local_dim
+
   call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "ibelm_xmin/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "ibelm_xmin/array", 0, 1, &
     ibelm_xmin_outer_core, adios_err)
   call check_adios_err(myrank,adios_err)
-  call adios_schedule_read(adios_handle, sel, "ibelm_xmax/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "ibelm_xmax/array", 0, 1, &
     ibelm_xmax_outer_core, adios_err)
   call check_adios_err(myrank,adios_err)
 
   call adios_perform_reads(adios_handle, adios_err)
   call check_adios_err(myrank,adios_err)
 
-  !local_dim = NSPEC2DMAX_YMIN_YMAX_OC
-  local_dim = size (ibelm_ymin_outer_core)
-  start(1) = local_dim*myrank; count(1) = local_dim
+  local_dim = NSPEC2DMAX_YMIN_YMAX_OC
+  start(1) = local_dim * myrank; count(1) = local_dim
+
   call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "ibelm_ymin/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "ibelm_ymin/array", 0, 1, &
     ibelm_ymin_outer_core, adios_err)
   call check_adios_err(myrank,adios_err)
-  call adios_schedule_read(adios_handle, sel, "ibelm_ymax/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "ibelm_ymax/array", 0, 1, &
     ibelm_ymax_outer_core, adios_err)
   call check_adios_err(myrank,adios_err)
 
   call adios_perform_reads(adios_handle, adios_err)
   call check_adios_err(myrank,adios_err)
 
-  !local_dim = NSPEC2D_BOTTOM_OC
-  local_dim = size (ibelm_bottom_outer_core)
-  start(1) = local_dim*myrank; count(1) = local_dim
+  local_dim = NSPEC2D_BOTTOM_OC
+  start(1) = local_dim * myrank; count(1) = local_dim
+
   call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "ibelm_bottom/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "ibelm_bottom/array", 0, 1, &
     ibelm_bottom_outer_core, adios_err)
   call check_adios_err(myrank,adios_err)
 
   call adios_perform_reads(adios_handle, adios_err)
   call check_adios_err(myrank,adios_err)
 
-  !local_dim = NSPEC2D_TOP_OC
-  local_dim = size (ibelm_top_outer_core)
-  start(1) = local_dim*myrank; count(1) = local_dim
+  local_dim = NSPEC2D_TOP_OC
+  start(1) = local_dim * myrank; count(1) = local_dim
+
   call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "ibelm_top/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "ibelm_top/array", 0, 1, &
     ibelm_top_outer_core, adios_err)
   call check_adios_err(myrank,adios_err)
 
   call adios_perform_reads(adios_handle, adios_err)
   call check_adios_err(myrank,adios_err)
 
-  !local_dim = NDIM*NGLLY*NGLLZ*NSPEC2DMAX_XMIN_XMAX_OC
-  local_dim = size (normal_xmin_outer_core)
-  start(1) = local_dim*myrank; count(1) = local_dim
+  ! normals
+
+  local_dim = NDIM*NGLLY*NGLLZ*NSPEC2DMAX_XMIN_XMAX_OC
+  start(1) = local_dim * myrank; count(1) = local_dim
+
   call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "normal_xmin/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "normal_xmin/array", 0, 1, &
     normal_xmin_outer_core, adios_err)
   call check_adios_err(myrank,adios_err)
-  call adios_schedule_read(adios_handle, sel, "normal_xmax/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "normal_xmax/array", 0, 1, &
     normal_xmax_outer_core, adios_err)
   call check_adios_err(myrank,adios_err)
 
   call adios_perform_reads(adios_handle, adios_err)
   call check_adios_err(myrank,adios_err)
 
-  !local_dim = NDIM*NGLLX*NGLLZ*NSPEC2DMAX_YMIN_YMAX_OC
-  local_dim = size (normal_ymin_outer_core)
-  start(1) = local_dim*myrank; count(1) = local_dim
+  local_dim = NDIM*NGLLX*NGLLZ*NSPEC2DMAX_YMIN_YMAX_OC
+  start(1) = local_dim * myrank; count(1) = local_dim
+
   call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "normal_ymin/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "normal_ymin/array", 0, 1, &
     normal_ymin_outer_core, adios_err)
   call check_adios_err(myrank,adios_err)
-  call adios_schedule_read(adios_handle, sel, "normal_ymax/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "normal_ymax/array", 0, 1, &
     normal_ymax_outer_core, adios_err)
   call check_adios_err(myrank,adios_err)
 
   call adios_perform_reads(adios_handle, adios_err)
   call check_adios_err(myrank,adios_err)
 
-  !local_dim = NDIM*NGLLX*NGLLY*NSPEC2D_BOTTOM_OC
-  local_dim = size (normal_bottom_outer_core)
-  start(1) = local_dim*myrank; count(1) = local_dim
+  local_dim = NDIM*NGLLX*NGLLY*NSPEC2D_BOTTOM_OC
+  start(1) = local_dim * myrank; count(1) = local_dim
+
   call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "normal_bottom/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "normal_bottom/array", 0, 1, &
     normal_bottom_outer_core, adios_err)
   call check_adios_err(myrank,adios_err)
 
   call adios_perform_reads(adios_handle, adios_err)
   call check_adios_err(myrank,adios_err)
 
-  !local_dim = NDIM*NGLLX*NGLLY*NSPEC2D_TOP_OC
-  local_dim = size (normal_top_outer_core)
-  start(1) = local_dim*myrank; count(1) = local_dim
+  local_dim = NDIM*NGLLX*NGLLY*NSPEC2D_TOP_OC
+  start(1) = local_dim * myrank; count(1) = local_dim
+
   call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "normal_top/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "normal_top/array", 0, 1, &
     normal_top_outer_core, adios_err)
   call check_adios_err(myrank,adios_err)
 
   call adios_perform_reads(adios_handle, adios_err)
   call check_adios_err(myrank,adios_err)
 
-  !local_dim = NGLLY*NGLLZ*NSPEC2DMAX_XMIN_XMAX_OC
-  local_dim = size (jacobian2D_xmin_outer_core)
-  start(1) = local_dim*myrank; count(1) = local_dim
+  ! jacobians
+
+  local_dim = NGLLY*NGLLZ*NSPEC2DMAX_XMIN_XMAX_OC
+  start(1) = local_dim * myrank; count(1) = local_dim
+
   call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "jacobian2D_xmin/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "jacobian2D_xmin/array", 0, 1, &
     jacobian2D_xmin_outer_core, adios_err)
   call check_adios_err(myrank,adios_err)
-  call adios_schedule_read(adios_handle, sel, "jacobian2D_xmax/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "jacobian2D_xmax/array", 0, 1, &
     jacobian2D_xmax_outer_core, adios_err)
   call check_adios_err(myrank,adios_err)
 
   call adios_perform_reads(adios_handle, adios_err)
   call check_adios_err(myrank,adios_err)
 
-  !local_dim = NGLLX*NGLLZ*NSPEC2DMAX_YMIN_YMAX_OC
-  local_dim = size (jacobian2D_ymin_outer_core)
-  start(1) = local_dim*myrank; count(1) = local_dim
+  local_dim = NGLLX*NGLLZ*NSPEC2DMAX_YMIN_YMAX_OC
+  start(1) = local_dim * myrank; count(1) = local_dim
+
   call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "jacobian2D_ymin/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "jacobian2D_ymin/array", 0, 1, &
     jacobian2D_ymin_outer_core, adios_err)
   call check_adios_err(myrank,adios_err)
-  call adios_schedule_read(adios_handle, sel, "jacobian2D_ymax/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "jacobian2D_ymax/array", 0, 1, &
     jacobian2D_ymax_outer_core, adios_err)
   call check_adios_err(myrank,adios_err)
 
   call adios_perform_reads(adios_handle, adios_err)
   call check_adios_err(myrank,adios_err)
 
+  local_dim = NGLLX*NGLLY*NSPEC2D_BOTTOM_OC
+  start(1) = local_dim * myrank; count(1) = local_dim
 
-  !local_dim = NGLLX*NGLLY*NSPEC2D_BOTTOM_OC
-  local_dim = size (jacobian2D_bottom_outer_core)
-  start(1) = local_dim*myrank; count(1) = local_dim
   call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "jacobian2D_bottom/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "jacobian2D_bottom/array", 0, 1, &
     jacobian2D_bottom_outer_core, adios_err)
   call check_adios_err(myrank,adios_err)
 
   call adios_perform_reads(adios_handle, adios_err)
   call check_adios_err(myrank,adios_err)
 
-  !local_dim = NGLLX*NGLLY*NSPEC2D_TOP_OC
-  local_dim = size (jacobian2D_top_outer_core)
-  start(1) = local_dim*myrank; count(1) = local_dim
+  local_dim = NGLLX*NGLLY*NSPEC2D_TOP_OC
+  start(1) = local_dim * myrank; count(1) = local_dim
+
   call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "jacobian2D_top/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "jacobian2D_top/array", 0, 1, &
     jacobian2D_top_outer_core, adios_err)
   call check_adios_err(myrank,adios_err)
 
   call adios_perform_reads(adios_handle, adios_err)
   call check_adios_err(myrank,adios_err)
-  ! boundary parameters
 
-  ! Close ADIOS handler to the restart file.
-  call adios_selection_delete(sel)
-  call adios_read_close(adios_handle, adios_err)
-  call check_adios_err(myrank,adios_err)
-  call adios_read_finalize_method(ADIOS_READ_METHOD_BP, adios_err)
-  call check_adios_err(myrank,adios_err)
 
-
   ! inner core
 
-  ! create name of database
-  call create_name_database_adios(prname, IREGION_INNER_CORE, LOCAL_PATH)
-  file_name= trim(prname) // "boundary.bp"
+  write(region_name,"('reg',i1, '/')") IREGION_INNER_CORE
 
-  call adios_read_init_method (ADIOS_READ_METHOD_BP, comm, &
-      "verbose=1", adios_err)
-  call check_adios_err(myrank,adios_err)
-  call adios_read_open_file (adios_handle, file_name, 0, comm, ierr)
-  call check_adios_err(myrank,adios_err)
-
+  ! number of elements
   call adios_selection_writeblock(sel, myrank)
-  call adios_schedule_read(adios_handle, sel, "nspec2D_xmin", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "nspec2D_xmin", 0, 1, &
      nspec2D_xmin_inner_core, adios_err)
-  call adios_schedule_read(adios_handle, sel, "nspec2D_xmax", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "nspec2D_xmax", 0, 1, &
      nspec2D_xmax_inner_core, adios_err)
-  call adios_schedule_read(adios_handle, sel, "nspec2D_ymin", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "nspec2D_ymin", 0, 1, &
      nspec2D_ymin_inner_core, adios_err)
-  call adios_schedule_read(adios_handle, sel, "nspec2D_ymax", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "nspec2D_ymax", 0, 1, &
      nspec2D_ymax_inner_core, adios_err)
-  !call adios_get_scalar(adios_handle, "nspec2D_xmin", &
-      !nspec2D_xmin_inner_core, adios_err)
-  !call adios_get_scalar(adios_handle, "nspec2D_xmax", &
-      !nspec2D_xmax_inner_core, adios_err)
-  !call adios_get_scalar(adios_handle, "nspec2D_ymin", &
-      !nspec2D_ymin_inner_core, adios_err)
-  !call adios_get_scalar(adios_handle, "nspec2D_ymax", &
-      !nspec2D_ymax_inner_core, adios_err)
+
   call adios_perform_reads(adios_handle, adios_err)
   call check_adios_err(myrank,adios_err)
 
-  !local_dim = NSPEC2DMAX_XMIN_XMAX_IC
-  local_dim = size (ibelm_xmin_inner_core)
-  start(1) = local_dim*myrank; count(1) = local_dim
+  ! daniel debug
+  !call synchronize_all()
+  !print*,myrank,'inner core'
+  !print*,myrank,'nspec2d xmin:',nspec2d_xmin_inner_core
+  !print*,myrank,'nspec2d xmax:',nspec2d_xmax_inner_core
+  !print*,myrank,'nspec2d ymin:',nspec2d_ymin_inner_core
+  !print*,myrank,'nspec2d ymax:',nspec2d_ymax_inner_core
+  !call synchronize_all()
+
+  ! boundary elements
+
+  local_dim = NSPEC2DMAX_XMIN_XMAX_IC
+  start(1) = local_dim * myrank; count(1) = local_dim
+
   call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "ibelm_xmin/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "ibelm_xmin/array", 0, 1, &
     ibelm_xmin_inner_core, adios_err)
   call check_adios_err(myrank,adios_err)
-  call adios_schedule_read(adios_handle, sel, "ibelm_xmax/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "ibelm_xmax/array", 0, 1, &
     ibelm_xmax_inner_core, adios_err)
   call check_adios_err(myrank,adios_err)
 
   call adios_perform_reads(adios_handle, adios_err)
   call check_adios_err(myrank,adios_err)
 
-  !local_dim = NSPEC2DMAX_YMIN_YMAX_IC
-  local_dim = size (ibelm_ymin_inner_core)
-  start(1) = local_dim*myrank; count(1) = local_dim
+  local_dim = NSPEC2DMAX_YMIN_YMAX_IC
+  start(1) = local_dim * myrank; count(1) = local_dim
+
   call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "ibelm_ymin/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "ibelm_ymin/array", 0, 1, &
     ibelm_ymin_inner_core, adios_err)
   call check_adios_err(myrank,adios_err)
-  call adios_schedule_read(adios_handle, sel, "ibelm_ymax/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "ibelm_ymax/array", 0, 1, &
     ibelm_ymax_inner_core, adios_err)
   call check_adios_err(myrank,adios_err)
 
   call adios_perform_reads(adios_handle, adios_err)
   call check_adios_err(myrank,adios_err)
 
-  !local_dim = NSPEC2D_BOTTOM_IC
-  local_dim = size (ibelm_bottom_inner_core)
-  start(1) = local_dim*myrank; count(1) = local_dim
+  local_dim = NSPEC2D_BOTTOM_IC
+  start(1) = local_dim * myrank; count(1) = local_dim
+
   call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "ibelm_bottom/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "ibelm_bottom/array", 0, 1, &
     ibelm_bottom_inner_core, adios_err)
   call check_adios_err(myrank,adios_err)
 
   call adios_perform_reads(adios_handle, adios_err)
   call check_adios_err(myrank,adios_err)
 
-  !local_dim = NSPEC2D_TOP_IC
-  local_dim = size (ibelm_top_inner_core)
-  start(1) = local_dim*myrank; count(1) = local_dim
+  local_dim = NSPEC2D_TOP_IC
+  start(1) = local_dim * myrank; count(1) = local_dim
+
   call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "ibelm_top/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "ibelm_top/array", 0, 1, &
     ibelm_top_inner_core, adios_err)
   call check_adios_err(myrank,adios_err)
 
@@ -532,91 +520,109 @@
   call adios_read_finalize_method(ADIOS_READ_METHOD_BP, adios_err)
   call check_adios_err(myrank,adios_err)
 
+
   ! -- Boundary Mesh for crust and mantle ---
   if (SAVE_BOUNDARY_MESH .and. SIMULATION_TYPE == 3) then
+
     file_name = LOCAL_PATH // "boundary_disc.bp"
+
+    ! opens adios file
     call adios_read_init_method (ADIOS_READ_METHOD_BP, comm, &
         "verbose=1", adios_err)
     call check_adios_err(myrank,adios_err)
     call adios_read_open_file (adios_handle, file_name, 0, comm, ierr)
     call check_adios_err(myrank,adios_err)
 
+    ! number of elements
     call adios_selection_writeblock(sel, myrank)
-    call adios_schedule_read(adios_handle, sel, "NSPEC2D_MOHO", 0, 1, &
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "NSPEC2D_MOHO", 0, 1, &
        njunk1, adios_err)
-    call adios_schedule_read(adios_handle, sel, "NSPEC2D_400", 0, 1, &
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "NSPEC2D_400", 0, 1, &
        njunk2, adios_err)
-    call adios_schedule_read(adios_handle, sel, "NSPEC2D_670", 0, 1, &
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "NSPEC2D_670", 0, 1, &
        njunk3, adios_err)
+
     call adios_perform_reads(adios_handle, adios_err)
     call check_adios_err(myrank,adios_err)
+
+    ! checks dimensions
     if (njunk1 /= NSPEC2D_MOHO .and. njunk2 /= NSPEC2D_400 .and. &
         njunk3 /= NSPEC2D_670) &
         call exit_mpi(myrank, 'Error reading boundary_disc.bp file')
 
+    ! boundary elements
+
+    ! moho
     local_dim = NSPEC2D_MOHO
     start(1) = local_dim*myrank; count(1) = local_dim
     call adios_selection_boundingbox (sel , 1, start, count)
-    call adios_schedule_read(adios_handle, sel, "ibelm_moho_top/array", 0, 1, &
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "ibelm_moho_top/array", 0, 1, &
       ibelm_moho_bot, adios_err)
     call check_adios_err(myrank,adios_err)
-    call adios_schedule_read(adios_handle, sel, "ibelm_moho_bot/array", 0, 1, &
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "ibelm_moho_bot/array", 0, 1, &
       ibelm_moho_top, adios_err)
     call check_adios_err(myrank,adios_err)
 
     call adios_perform_reads(adios_handle, adios_err)
     call check_adios_err(myrank,adios_err)
 
+    ! 400
     local_dim = NSPEC2D_400
     start(1) = local_dim*myrank; count(1) = local_dim
     call adios_selection_boundingbox (sel , 1, start, count)
-    call adios_schedule_read(adios_handle, sel, "ibelm_400_top/array", 0, 1, &
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "ibelm_400_top/array", 0, 1, &
       ibelm_400_bot, adios_err)
     call check_adios_err(myrank,adios_err)
-    call adios_schedule_read(adios_handle, sel, "ibelm_400_bot/array", 0, 1, &
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "ibelm_400_bot/array", 0, 1, &
       ibelm_400_top, adios_err)
     call check_adios_err(myrank,adios_err)
 
     call adios_perform_reads(adios_handle, adios_err)
     call check_adios_err(myrank,adios_err)
 
+    ! 670
     local_dim = NSPEC2D_670
     start(1) = local_dim*myrank; count(1) = local_dim
     call adios_selection_boundingbox (sel , 1, start, count)
-    call adios_schedule_read(adios_handle, sel, "ibelm_670_top/array", 0, 1, &
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "ibelm_670_top/array", 0, 1, &
       ibelm_670_bot, adios_err)
     call check_adios_err(myrank,adios_err)
-    call adios_schedule_read(adios_handle, sel, "ibelm_670_bot/array", 0, 1, &
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "ibelm_670_bot/array", 0, 1, &
       ibelm_670_top, adios_err)
     call check_adios_err(myrank,adios_err)
 
     call adios_perform_reads(adios_handle, adios_err)
     call check_adios_err(myrank,adios_err)
 
+    ! normals
+
+    ! moho
     local_dim = NDIM*NGLLX*NGLLY*NSPEC2D_MOHO
     start(1) = local_dim*myrank; count(1) = local_dim
     call adios_selection_boundingbox (sel , 1, start, count)
-    call adios_schedule_read(adios_handle, sel, "normal_moho/array", 0, 1, &
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "normal_moho/array", 0, 1, &
       normal_moho, adios_err)
     call check_adios_err(myrank,adios_err)
 
     call adios_perform_reads(adios_handle, adios_err)
     call check_adios_err(myrank,adios_err)
 
+    ! 400
     local_dim = NDIM*NGLLX*NGLLY*NSPEC2D_400
     start(1) = local_dim*myrank; count(1) = local_dim
     call adios_selection_boundingbox (sel , 1, start, count)
-    call adios_schedule_read(adios_handle, sel, "normal_400/array", 0, 1, &
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "normal_400/array", 0, 1, &
       normal_400, adios_err)
     call check_adios_err(myrank,adios_err)
 
     call adios_perform_reads(adios_handle, adios_err)
     call check_adios_err(myrank,adios_err)
 
+    ! 670
     local_dim = NDIM*NGLLX*NGLLY*NSPEC2D_670
     start(1) = local_dim*myrank; count(1) = local_dim
     call adios_selection_boundingbox (sel , 1, start, count)
-    call adios_schedule_read(adios_handle, sel, "normal_670/array", 0, 1, &
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "normal_670/array", 0, 1, &
       normal_670, adios_err)
     call check_adios_err(myrank,adios_err)
 
@@ -630,23 +636,21 @@
     call adios_read_finalize_method(ADIOS_READ_METHOD_BP, adios_err)
     call check_adios_err(myrank,adios_err)
 
-    k_top = 1
-    k_bot = NGLLZ
-
-    ! initialization
-    moho_kl = 0.; d400_kl = 0.; d670_kl = 0.; cmb_kl = 0.; icb_kl = 0.
   endif
 
 end subroutine read_mesh_databases_coupling_adios
 
+!===============================================================================
+
 subroutine read_mesh_databases_addressing_adios()
 
-  use mpi
   use specfem_par
   use specfem_par_crustmantle
   use specfem_par_innercore
   use specfem_par_outercore
 
+  use adios_helpers_mod, only: check_adios_err
+
   implicit none
 
   ! local parameters
@@ -678,6 +682,7 @@
   call bcast_all_i(iproc_xi_slice,NPROCTOT_VAL)
   call bcast_all_i(iproc_eta_slice,NPROCTOT_VAL)
 
+
   ! output a topology map of slices - fix 20x by nproc
   if (myrank == 0 ) then
     if( NCHUNKS_VAL == 6 .and. NPROCTOT_VAL < 1000 ) then
@@ -732,7 +737,7 @@
   endif
 
   ! determine chunk number and local slice coordinates using addressing
-  ! (needed for Stacey conditions)
+  ! (needed for stacey conditions)
   ichunk = ichunk_slice(myrank)
 
 end subroutine read_mesh_databases_addressing_adios
@@ -741,33 +746,36 @@
 !===============================================================================
 !> \brief Read crust mantle MPI arrays from an ADIOS file.
 subroutine read_mesh_databases_MPI_CM_adios()
+
   ! External imports
-  use mpi
   use adios_read_mod
   ! Internal imports
   use specfem_par
   use specfem_par_crustmantle
+  use adios_helpers_mod, only: check_adios_err
+
   implicit none
 
   ! local parameters
-  integer :: sizeprocs, comm, ierr
-  character(len=150) :: file_name
-  integer(kind=8) :: group_size_inc
-  integer :: local_dim, global_dim, offset
+  integer :: comm, ierr
+  character(len=256) :: file_name
   ! ADIOS variables
   integer                 :: adios_err
-  integer(kind=8)         :: adios_group, adios_handle, varid, sel
-  integer(kind=8)         :: adios_groupsize, adios_totalsize
-  integer :: vars_count, attrs_count, current_step, last_step, vsteps
-  character(len=128), dimension(:), allocatable :: adios_names
+  integer(kind=8)         :: adios_handle, sel
   integer(kind=8), dimension(1) :: start, count
 
-  ! create the name for the database of the current slide and region
-  call create_name_database_adios(prname, IREGION_CRUST_MANTLE, LOCAL_PATH)
+  integer :: local_dim_my_neighbours, local_dim_nibool_interfaces, &
+             local_dim_ibool_interfaces, local_dim_phase_ispec_inner, &
+             local_dim_num_elem_colors
 
-  file_name= trim(prname) // "solver_data_mpi.bp"
-  call MPI_Comm_dup (MPI_COMM_WORLD, comm, ierr)
+  character(len=128)      :: region_name
 
+  write(region_name,"('reg',i1, '/')") IREGION_CRUST_MANTLE
+
+  file_name= trim(LOCAL_PATH) // "/solver_data_mpi.bp"
+
+  call world_duplicate(comm)
+
   call adios_read_init_method (ADIOS_READ_METHOD_BP, comm, &
       "verbose=1", adios_err)
   call check_adios_err(myrank,adios_err)
@@ -776,13 +784,42 @@
 
   ! MPI interfaces
   call adios_selection_writeblock(sel, myrank)
-  call adios_schedule_read(adios_handle, sel, "num_interfaces", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "num_interfaces", 0, 1, &
      num_interfaces_crust_mantle, adios_err)
-  !call adios_get_scalar(adios_handle, "num_interfaces", &
-      !num_interfaces_crust_mantle, adios_err)
   call adios_perform_reads(adios_handle, adios_err)
   call check_adios_err(myrank,adios_err)
 
+  call adios_selection_writeblock(sel, myrank)
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "nspec_inner", &
+    0, 1, nspec_inner_crust_mantle, adios_err)
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "nspec_outer", &
+    0, 1, nspec_outer_crust_mantle, adios_err)
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "num_phase_ispec", &
+    0, 1, num_phase_ispec_crust_mantle, adios_err)
+
+  call adios_perform_reads(adios_handle, adios_err)
+  call check_adios_err(myrank,adios_err)
+
+  !----------------------------------------.
+  ! Get local_dim to avoid buffer overflow |
+  !----------------------------------------'
+  if( num_interfaces_crust_mantle > 0 ) then
+    call adios_get_scalar(adios_handle, trim(region_name) // "my_neighbours/local_dim", &
+                          local_dim_my_neighbours, adios_err)
+    call adios_get_scalar(adios_handle, trim(region_name) // "nibool_interfaces/local_dim", &
+                          local_dim_nibool_interfaces, adios_err)
+    call adios_get_scalar(adios_handle, trim(region_name) // "ibool_interfaces/local_dim", &
+                          local_dim_ibool_interfaces, adios_err)
+  endif
+  if(num_phase_ispec_crust_mantle > 0 ) then
+    call adios_get_scalar(adios_handle, trim(region_name) // "phase_ispec_inner/local_dim", &
+                          local_dim_phase_ispec_inner, adios_err)
+  endif
+  if( USE_MESH_COLORING_GPU ) then
+    call adios_get_scalar(adios_handle, trim(region_name) // "num_elem_colors/local_dim", &
+                          local_dim_num_elem_colors, adios_err)
+  endif
+
   allocate(my_neighbours_crust_mantle(num_interfaces_crust_mantle), &
           nibool_interfaces_crust_mantle(num_interfaces_crust_mantle), &
           stat=ierr)
@@ -791,9 +828,7 @@
 
   if( num_interfaces_crust_mantle > 0 ) then
     call adios_selection_writeblock(sel, myrank)
-    !call adios_get_scalar(adios_handle, "max_nibool_interfaces", &
-      !max_nibool_interfaces_cm, adios_err)
-    call adios_schedule_read(adios_handle, sel, "max_nibool_interfaces", 0, 1, &
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "max_nibool_interfaces", 0, 1, &
        max_nibool_interfaces_cm, adios_err)
     call adios_perform_reads(adios_handle, adios_err)
     call check_adios_err(myrank,adios_err)
@@ -803,23 +838,23 @@
     if( ierr /= 0 ) call exit_mpi(myrank, &
         'error allocating array ibool_interfaces_crust_mantle')
 
-    local_dim = num_interfaces_crust_mantle
-    start(1) = local_dim*myrank; count(1) = local_dim
+    start(1) = local_dim_my_neighbours * myrank
+    count(1) = num_interfaces_crust_mantle
     call adios_selection_boundingbox (sel , 1, start, count)
-    call adios_schedule_read(adios_handle, sel, "my_neighbours/array", 0, 1, &
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "my_neighbours/array", 0, 1, &
       my_neighbours_crust_mantle, adios_err)
     call check_adios_err(myrank,adios_err)
-    call adios_schedule_read(adios_handle, sel, "nibool_interfaces/array", &
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "nibool_interfaces/array", &
       0, 1, nibool_interfaces_crust_mantle, adios_err)
     call check_adios_err(myrank,adios_err)
 
     call adios_perform_reads(adios_handle, adios_err)
     call check_adios_err(myrank,adios_err)
 
-    local_dim = max_nibool_interfaces_cm * num_interfaces_crust_mantle
-    start(1) = local_dim*myrank; count(1) = local_dim
+    start(1) = local_dim_ibool_interfaces * myrank
+    count(1) = max_nibool_interfaces_cm * num_interfaces_crust_mantle
     call adios_selection_boundingbox (sel , 1, start, count)
-    call adios_schedule_read(adios_handle, sel, &
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // &
       "ibool_interfaces/array", 0, 1, &
       ibool_interfaces_crust_mantle, adios_err)
     call check_adios_err(myrank,adios_err)
@@ -835,21 +870,6 @@
   endif
 
   ! inner / outer elements
-  call adios_selection_writeblock(sel, myrank)
-  call adios_schedule_read(adios_handle, sel, "nspec_inner", &
-    0, 1, nspec_inner_crust_mantle, adios_err)
-  call adios_schedule_read(adios_handle, sel, "nspec_outer", &
-    0, 1, nspec_outer_crust_mantle, adios_err)
-  call adios_schedule_read(adios_handle, sel, "num_phase_ispec", &
-    0, 1, num_phase_ispec_crust_mantle, adios_err)
-  !call adios_get_scalar(adios_handle, "nspec_inner", &
-      !nspec_inner_crust_mantle, adios_err)
-  !call adios_get_scalar(adios_handle, "nspec_outer", &
-      !nspec_outer_crust_mantle, adios_err)
-  !call adios_get_scalar(adios_handle, "num_phase_ispec", &
-      !num_phase_ispec_crust_mantle, adios_err)
-  call adios_perform_reads(adios_handle, adios_err)
-  call check_adios_err(myrank,adios_err)
 
   if( num_phase_ispec_crust_mantle < 0 ) &
       call exit_mpi(myrank,'error num_phase_ispec_crust_mantle is < zero')
@@ -860,10 +880,10 @@
       'error allocating array phase_ispec_inner_crust_mantle')
 
   if(num_phase_ispec_crust_mantle > 0 ) then
-    local_dim = num_phase_ispec_crust_mantle * 2
-    start(1) = local_dim*myrank; count(1) = local_dim
+    start(1) = local_dim_phase_ispec_inner * myrank
+    count(1) = num_phase_ispec_crust_mantle * 2
     call adios_selection_boundingbox (sel , 1, start, count)
-    call adios_schedule_read(adios_handle, sel, &
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // &
       "phase_ispec_inner/array", 0, 1, &
       phase_ispec_inner_crust_mantle, adios_err)
     call check_adios_err(myrank,adios_err)
@@ -875,16 +895,14 @@
   ! mesh coloring for GPUs
   if( USE_MESH_COLORING_GPU ) then
     call adios_selection_writeblock(sel, myrank)
-    call adios_schedule_read(adios_handle, sel, "num_colors_outer", &
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "num_colors_outer", &
       0, 1, num_colors_outer_crust_mantle, adios_err)
-    call adios_schedule_read(adios_handle, sel, "num_colors_inner", &
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "num_colors_inner", &
       0, 1, num_colors_inner_crust_mantle, adios_err)
-    !call adios_get_scalar(adios_handle, "num_colors_outer", &
-        !num_colors_outer_crust_mantle, adios_err)
-    !call adios_get_scalar(adios_handle, "num_colors_inner", &
-        !num_colors_inner_crust_mantle, adios_err)
+
     call adios_perform_reads(adios_handle, adios_err)
     call check_adios_err(myrank,adios_err)
+
     ! colors
 
     allocate(num_elem_colors_crust_mantle(num_colors_outer_crust_mantle +&
@@ -892,10 +910,10 @@
     if( ierr /= 0 ) &
       call exit_mpi(myrank,'error allocating num_elem_colors_crust_mantle array')
 
-    local_dim = num_colors_outer_crust_mantle + num_colors_inner_crust_mantle
-    start(1) = local_dim*myrank; count(1) = local_dim
+    start(1) = local_dim_num_elem_colors * myrank
+    count(1)= num_colors_outer_crust_mantle + num_colors_inner_crust_mantle
     call adios_selection_boundingbox (sel , 1, start, count)
-    call adios_schedule_read(adios_handle, sel, &
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // &
       "num_elem_colors/array", 0, 1, &
       num_elem_colors_crust_mantle, adios_err)
     call check_adios_err(myrank,adios_err)
@@ -919,38 +937,41 @@
   call adios_read_finalize_method(ADIOS_READ_METHOD_BP, adios_err)
   call check_adios_err(myrank,adios_err)
 
-  call synchronize_all()
+  call synchronize_all_comm(comm)
 
 end subroutine read_mesh_databases_MPI_CM_adios
 
 !===============================================================================
 !> \brief Read outer core MPI arrays from an ADIOS file.
 subroutine read_mesh_databases_MPI_OC_adios()
-  use mpi
+
   use adios_read_mod
   use specfem_par
   use specfem_par_outercore
+
+  use adios_helpers_mod, only: check_adios_err
+
   implicit none
 
   ! local parameters
-  integer :: sizeprocs, comm, ierr
-  character(len=150) :: file_name
-  integer(kind=8) :: group_size_inc
-  integer :: local_dim, global_dim, offset
+  integer :: comm, ierr
+  character(len=256) :: file_name
   ! ADIOS variables
   integer                 :: adios_err
-  integer(kind=8)         :: adios_group, adios_handle, varid, sel
-  integer(kind=8)         :: adios_groupsize, adios_totalsize
-  integer :: vars_count, attrs_count, current_step, last_step, vsteps
-  character(len=128), dimension(:), allocatable :: adios_names
+  integer(kind=8)         :: adios_handle, sel
   integer(kind=8), dimension(1) :: start, count
 
-  ! create the name for the database of the current slide and region
-  call create_name_database_adios(prname, IREGION_OUTER_CORE, LOCAL_PATH)
+  integer :: local_dim_my_neighbours, local_dim_nibool_interfaces, &
+             local_dim_ibool_interfaces, local_dim_phase_ispec_inner, &
+             local_dim_num_elem_colors
 
-  file_name= trim(prname) // "solver_data_mpi.bp"
-  call MPI_Comm_dup (MPI_COMM_WORLD, comm, ierr)
+  character(len=128)      :: region_name
 
+  write(region_name,"('reg',i1, '/')") IREGION_OUTER_CORE
+  file_name= trim(LOCAL_PATH) // "/solver_data_mpi.bp"
+
+  call world_duplicate(comm)
+
   call adios_read_init_method (ADIOS_READ_METHOD_BP, comm, &
       "verbose=1", adios_err)
   call check_adios_err(myrank,adios_err)
@@ -959,25 +980,52 @@
 
   ! MPI interfaces
   call adios_selection_writeblock(sel, myrank)
-  call adios_schedule_read(adios_handle, sel, "num_interfaces", &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "num_interfaces", &
     0, 1, num_interfaces_outer_core, adios_err)
-  !call adios_get_scalar(adios_handle, "num_interfaces", &
-      !num_interfaces_outer_core, adios_err)
   call adios_perform_reads(adios_handle, adios_err)
   call check_adios_err(myrank,adios_err)
 
+  ! inner / outer elements
+  call adios_selection_writeblock(sel, myrank)
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "nspec_inner", &
+  0, 1, nspec_inner_outer_core, adios_err)
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "nspec_outer", &
+    0, 1, nspec_outer_outer_core, adios_err)
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "num_phase_ispec", &
+    0, 1, num_phase_ispec_outer_core, adios_err)
+  call adios_perform_reads(adios_handle, adios_err)
+  call check_adios_err(myrank,adios_err)
+
   allocate(my_neighbours_outer_core(num_interfaces_outer_core), &
           nibool_interfaces_outer_core(num_interfaces_outer_core), &
           stat=ierr)
   if( ierr /= 0 ) call exit_mpi(myrank, &
       'error allocating array my_neighbours_outer_coreetc.')
 
+  !----------------------------------------.
+  ! Get local_dim to avoid buffer overflow |
+  !----------------------------------------'
+  if( num_interfaces_outer_core > 0 ) then
+    call adios_get_scalar(adios_handle, trim(region_name) // "my_neighbours/local_dim", &
+                          local_dim_my_neighbours, adios_err)
+    call adios_get_scalar(adios_handle, trim(region_name) // "nibool_interfaces/local_dim", &
+                          local_dim_nibool_interfaces, adios_err)
+    call adios_get_scalar(adios_handle, trim(region_name) // "ibool_interfaces/local_dim", &
+                          local_dim_ibool_interfaces, adios_err)
+  endif
+  if(num_phase_ispec_outer_core > 0 ) then
+    call adios_get_scalar(adios_handle, trim(region_name) // "phase_ispec_inner/local_dim", &
+                          local_dim_phase_ispec_inner, adios_err)
+  endif
+  if( USE_MESH_COLORING_GPU ) then
+    call adios_get_scalar(adios_handle, trim(region_name) // "num_elem_colors/local_dim", &
+                          local_dim_num_elem_colors, adios_err)
+  endif
+
   if( num_interfaces_outer_core> 0 ) then
     call adios_selection_writeblock(sel, myrank)
-    call adios_schedule_read(adios_handle, sel, "max_nibool_interfaces", &
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "max_nibool_interfaces", &
       0, 1, max_nibool_interfaces_oc, adios_err)
-    !call adios_get_scalar(adios_handle, "max_nibool_interfaces", &
-      !max_nibool_interfaces_oc, adios_err)
     call adios_perform_reads(adios_handle, adios_err)
     call check_adios_err(myrank,adios_err)
 
@@ -986,23 +1034,23 @@
     if( ierr /= 0 ) call exit_mpi(myrank, &
         'error allocating array ibool_interfaces_outer_core')
 
-    local_dim = num_interfaces_outer_core
-    start(1) = local_dim*myrank; count(1) = local_dim
+    start(1) = local_dim_my_neighbours * myrank
+    count(1) = num_interfaces_outer_core
     call adios_selection_boundingbox (sel , 1, start, count)
-    call adios_schedule_read(adios_handle, sel, "my_neighbours/array", 0, 1, &
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "my_neighbours/array", 0, 1, &
       my_neighbours_outer_core, adios_err)
     call check_adios_err(myrank,adios_err)
-    call adios_schedule_read(adios_handle, sel, "nibool_interfaces/array", &
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "nibool_interfaces/array", &
       0, 1, nibool_interfaces_outer_core, adios_err)
     call check_adios_err(myrank,adios_err)
 
     call adios_perform_reads(adios_handle, adios_err)
     call check_adios_err(myrank,adios_err)
 
-    local_dim = max_nibool_interfaces_oc * num_interfaces_outer_core
-    start(1) = local_dim*myrank; count(1) = local_dim
+    start(1) = local_dim_ibool_interfaces * myrank
+    count(1) = max_nibool_interfaces_oc * num_interfaces_outer_core
     call adios_selection_boundingbox (sel , 1, start, count)
-    call adios_schedule_read(adios_handle, sel, &
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // &
       "ibool_interfaces/array", 0, 1, &
       ibool_interfaces_outer_core, adios_err)
     call check_adios_err(myrank,adios_err)
@@ -1017,23 +1065,6 @@
         'error allocating array dummy ibool_interfaces_outer_core')
   endif
 
-  ! inner / outer elements
-  call adios_selection_writeblock(sel, myrank)
-  call adios_schedule_read(adios_handle, sel, "nspec_inner", &
-  0, 1, nspec_inner_outer_core, adios_err)
-  call adios_schedule_read(adios_handle, sel, "nspec_outer", &
-    0, 1, nspec_outer_outer_core, adios_err)
-  call adios_schedule_read(adios_handle, sel, "num_phase_ispec", &
-    0, 1, num_phase_ispec_outer_core, adios_err)
-  !call adios_get_scalar(adios_handle, "nspec_inner", &
-      !nspec_inner_outer_core, adios_err)
-  !call adios_get_scalar(adios_handle, "nspec_outer", &
-      !nspec_outer_outer_core, adios_err)
-  !call adios_get_scalar(adios_handle, "num_phase_ispec", &
-      !num_phase_ispec_outer_core, adios_err)
-  call adios_perform_reads(adios_handle, adios_err)
-  call check_adios_err(myrank,adios_err)
-
   if( num_phase_ispec_outer_core< 0 ) &
       call exit_mpi(myrank,'error num_phase_ispec_outer_core is < zero')
 
@@ -1043,10 +1074,10 @@
       'error allocating array phase_ispec_inner_outer_core')
 
   if(num_phase_ispec_outer_core> 0 ) then
-    local_dim = num_phase_ispec_outer_core * 2
-    start(1) = local_dim*myrank; count(1) = local_dim
+    start(1) = local_dim_phase_ispec_inner * myrank
+    count(1) = num_phase_ispec_outer_core * 2
     call adios_selection_boundingbox (sel , 1, start, count)
-    call adios_schedule_read(adios_handle, sel, &
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // &
       "phase_ispec_inner/array", 0, 1, &
       phase_ispec_inner_outer_core, adios_err)
     call check_adios_err(myrank,adios_err)
@@ -1058,16 +1089,13 @@
   ! mesh coloring for GPUs
   if( USE_MESH_COLORING_GPU ) then
     call adios_selection_writeblock(sel, myrank)
-    call adios_schedule_read(adios_handle, sel, "num_colors_outer", &
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "num_colors_outer", &
       0, 1, num_colors_outer_outer_core, adios_err)
-    call adios_schedule_read(adios_handle, sel, "num_colors_inner", &
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "num_colors_inner", &
       0, 1, num_colors_inner_outer_core, adios_err)
-    !call adios_get_scalar(adios_handle, "num_colors_outer", &
-        !num_colors_outer_outer_core, adios_err)
-    !call adios_get_scalar(adios_handle, "num_colors_inner", &
-        !num_colors_inner_outer_core, adios_err)
     call adios_perform_reads(adios_handle, adios_err)
     call check_adios_err(myrank,adios_err)
+
     ! colors
 
     allocate(num_elem_colors_outer_core(num_colors_outer_outer_core+&
@@ -1075,10 +1103,10 @@
     if( ierr /= 0 ) &
       call exit_mpi(myrank,'error allocating num_elem_colors_outer_core array')
 
-    local_dim = num_colors_outer_outer_core+ num_colors_inner_outer_core
-    start(1) = local_dim*myrank; count(1) = local_dim
+    start(1) = local_dim_num_elem_colors * myrank
+    count(1)= num_colors_outer_outer_core + num_colors_inner_outer_core
     call adios_selection_boundingbox (sel , 1, start, count)
-    call adios_schedule_read(adios_handle, sel, &
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // &
       "num_elem_colors/array", 0, 1, &
       num_elem_colors_outer_core, adios_err)
     call check_adios_err(myrank,adios_err)
@@ -1102,7 +1130,7 @@
   call adios_read_finalize_method(ADIOS_READ_METHOD_BP, adios_err)
   call check_adios_err(myrank,adios_err)
 
-  call synchronize_all()
+  call synchronize_all_comm(comm)
 
 end subroutine read_mesh_databases_MPI_OC_adios
 
@@ -1110,32 +1138,34 @@
 !===============================================================================
 !> \brief Read outer core MPI arrays from an ADIOS file.
 subroutine read_mesh_databases_MPI_IC_adios()
-  use mpi
+
   use adios_read_mod
-
   use specfem_par
   use specfem_par_innercore
+  use adios_helpers_mod, only: check_adios_err
+
   implicit none
 
   ! local parameters
-  integer :: sizeprocs, comm, ierr
-  character(len=150) :: file_name
-  integer(kind=8) :: group_size_inc
-  integer :: local_dim, global_dim, offset
+  integer :: comm, ierr
+  character(len=256) :: file_name
   ! ADIOS variables
   integer                 :: adios_err
-  integer(kind=8)         :: adios_group, adios_handle, varid, sel
-  integer(kind=8)         :: adios_groupsize, adios_totalsize
-  integer :: vars_count, attrs_count, current_step, last_step, vsteps
-  character(len=128), dimension(:), allocatable :: adios_names
+  integer(kind=8)         :: adios_handle, sel
   integer(kind=8), dimension(1) :: start, count
 
-  ! create the name for the database of the current slide and region
-  call create_name_database_adios(prname, IREGION_INNER_CORE, LOCAL_PATH)
+  integer :: local_dim_my_neighbours, local_dim_nibool_interfaces, &
+             local_dim_ibool_interfaces, local_dim_phase_ispec_inner, &
+             local_dim_num_elem_colors
 
-  file_name= trim(prname) // "solver_data_mpi.bp"
-  call MPI_Comm_dup (MPI_COMM_WORLD, comm, ierr)
+  character(len=128)      :: region_name
 
+  write(region_name,"('reg',i1, '/')") IREGION_INNER_CORE
+
+  file_name= trim(LOCAL_PATH) // "/solver_data_mpi.bp"
+
+  call world_duplicate(comm)
+
   call adios_read_init_method (ADIOS_READ_METHOD_BP, comm, &
       "verbose=1", adios_err)
   call check_adios_err(myrank,adios_err)
@@ -1144,13 +1174,43 @@
 
   ! MPI interfaces
   call adios_selection_writeblock(sel, myrank)
-  call adios_schedule_read(adios_handle, sel, "num_interfaces", &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "num_interfaces", &
     0, 1, num_interfaces_inner_core, adios_err)
-  !call adios_get_scalar(adios_handle, "num_interfaces", &
-      !num_interfaces_inner_core, adios_err)
   call adios_perform_reads(adios_handle, adios_err)
   call check_adios_err(myrank,adios_err)
 
+  ! inner / outer elements
+  call adios_selection_writeblock(sel, myrank)
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "nspec_inner", &
+    0, 1, nspec_inner_inner_core, adios_err)
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "nspec_outer", &
+    0, 1, nspec_outer_inner_core, adios_err)
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "num_phase_ispec", &
+    0, 1, num_phase_ispec_inner_core, adios_err)
+
+  call adios_perform_reads(adios_handle, adios_err)
+  call check_adios_err(myrank,adios_err)
+
+  !----------------------------------------.
+  ! Get local_dim to avoid buffer overflow |
+  !----------------------------------------'
+  if( num_interfaces_inner_core > 0 ) then
+    call adios_get_scalar(adios_handle, trim(region_name) // "my_neighbours/local_dim", &
+                          local_dim_my_neighbours, adios_err)
+    call adios_get_scalar(adios_handle, trim(region_name) // "nibool_interfaces/local_dim", &
+                          local_dim_nibool_interfaces, adios_err)
+    call adios_get_scalar(adios_handle, trim(region_name) // "ibool_interfaces/local_dim", &
+                          local_dim_ibool_interfaces, adios_err)
+  endif
+  if(num_phase_ispec_inner_core > 0 ) then
+    call adios_get_scalar(adios_handle, trim(region_name) // "phase_ispec_inner/local_dim", &
+                          local_dim_phase_ispec_inner, adios_err)
+  endif
+  if( USE_MESH_COLORING_GPU ) then
+    call adios_get_scalar(adios_handle, trim(region_name) // "num_elem_colors/local_dim", &
+                          local_dim_num_elem_colors, adios_err)
+  endif
+
   allocate(my_neighbours_inner_core(num_interfaces_inner_core), &
           nibool_interfaces_inner_core(num_interfaces_inner_core), &
           stat=ierr)
@@ -1159,10 +1219,9 @@
 
   if( num_interfaces_inner_core > 0 ) then
     call adios_selection_writeblock(sel, myrank)
-    call adios_schedule_read(adios_handle, sel, "max_nibool_interfaces", &
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "max_nibool_interfaces", &
       0, 1, max_nibool_interfaces_ic, adios_err)
-    !call adios_get_scalar(adios_handle, "max_nibool_interfaces", &
-      !max_nibool_interfaces_ic, adios_err)
+
     call adios_perform_reads(adios_handle, adios_err)
     call check_adios_err(myrank,adios_err)
 
@@ -1171,23 +1230,23 @@
     if( ierr /= 0 ) call exit_mpi(myrank, &
         'error allocating array ibool_interfaces_inner_core')
 
-    local_dim = num_interfaces_inner_core
-    start(1) = local_dim*myrank; count(1) = local_dim
+    start(1) = local_dim_my_neighbours * myrank
+    count(1) = num_interfaces_inner_core
     call adios_selection_boundingbox (sel , 1, start, count)
-    call adios_schedule_read(adios_handle, sel, "my_neighbours/array", 0, 1, &
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "my_neighbours/array", 0, 1, &
       my_neighbours_inner_core, adios_err)
     call check_adios_err(myrank,adios_err)
-    call adios_schedule_read(adios_handle, sel, "nibool_interfaces/array", &
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "nibool_interfaces/array", &
       0, 1, nibool_interfaces_inner_core, adios_err)
     call check_adios_err(myrank,adios_err)
 
     call adios_perform_reads(adios_handle, adios_err)
     call check_adios_err(myrank,adios_err)
 
-    local_dim = max_nibool_interfaces_ic * num_interfaces_inner_core
-    start(1) = local_dim*myrank; count(1) = local_dim
+    start(1) = local_dim_ibool_interfaces * myrank
+    count(1) = max_nibool_interfaces_ic * num_interfaces_inner_core
     call adios_selection_boundingbox (sel , 1, start, count)
-    call adios_schedule_read(adios_handle, sel, &
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // &
       "ibool_interfaces/array", 0, 1, &
       ibool_interfaces_inner_core, adios_err)
     call check_adios_err(myrank,adios_err)
@@ -1202,23 +1261,6 @@
         'error allocating array dummy ibool_interfaces_inner_core')
   endif
 
-  ! inner / outer elements
-  call adios_selection_writeblock(sel, myrank)
-  call adios_schedule_read(adios_handle, sel, "nspec_inner", &
-    0, 1, nspec_inner_inner_core, adios_err)
-  call adios_schedule_read(adios_handle, sel, "nspec_outer", &
-    0, 1, nspec_outer_inner_core, adios_err)
-  call adios_schedule_read(adios_handle, sel, "num_phase_ispec", &
-    0, 1, num_phase_ispec_inner_core, adios_err)
-  !call adios_get_scalar(adios_handle, "nspec_inner", &
-      !nspec_inner_inner_core, adios_err)
-  !call adios_get_scalar(adios_handle, "nspec_outer", &
-      !nspec_outer_inner_core, adios_err)
-  !call adios_get_scalar(adios_handle, "num_phase_ispec", &
-      !num_phase_ispec_inner_core, adios_err)
-  call adios_perform_reads(adios_handle, adios_err)
-  call check_adios_err(myrank,adios_err)
-
   if( num_phase_ispec_inner_core < 0 ) &
       call exit_mpi(myrank,'error num_phase_ispec_inner_core is < zero')
 
@@ -1228,10 +1270,10 @@
       'error allocating array phase_ispec_inner_inner_core')
 
   if(num_phase_ispec_inner_core > 0 ) then
-    local_dim = num_phase_ispec_inner_core * 2
-    start(1) = local_dim*myrank; count(1) = local_dim
+    start(1) = local_dim_phase_ispec_inner * myrank
+    count(1) = num_phase_ispec_inner_core * 2
     call adios_selection_boundingbox (sel , 1, start, count)
-    call adios_schedule_read(adios_handle, sel, &
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // &
       "phase_ispec_inner/array", 0, 1, &
       phase_ispec_inner_inner_core, adios_err)
     call check_adios_err(myrank,adios_err)
@@ -1243,14 +1285,11 @@
   ! mesh coloring for GPUs
   if( USE_MESH_COLORING_GPU ) then
     call adios_selection_writeblock(sel, myrank)
-    call adios_schedule_read(adios_handle, sel, "num_colors_outer", &
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "num_colors_outer", &
       0, 1, num_colors_outer_inner_core, adios_err)
-    call adios_schedule_read(adios_handle, sel, "num_colors_inner", &
+    call adios_schedule_read(adios_handle, sel, trim(region_name) // "num_colors_inner", &
       0, 1, num_colors_inner_inner_core, adios_err)
-    !call adios_get_scalar(adios_handle, "num_colors_outer", &
-        !num_colors_outer_inner_core, adios_err)
-    !call adios_get_scalar(adios_handle, "num_colors_inner", &
-        !num_colors_inner_inner_core, adios_err)
+
     call adios_perform_reads(adios_handle, adios_err)
     call check_adios_err(myrank,adios_err)
     ! colors
@@ -1260,8 +1299,8 @@
     if( ierr /= 0 ) &
       call exit_mpi(myrank,'error allocating num_elem_colors_inner_core array')
 
-    local_dim = num_colors_outer_inner_core + num_colors_inner_inner_core
-    start(1) = local_dim*myrank; count(1) = local_dim
+    start(1) = local_dim_num_elem_colors * myrank
+    count(1)= num_colors_outer_inner_core + num_colors_inner_inner_core
     call adios_selection_boundingbox (sel , 1, start, count)
     call adios_schedule_read(adios_handle, sel, &
       "num_elem_colors/array", 0, 1, &
@@ -1287,7 +1326,7 @@
   call adios_read_finalize_method(ADIOS_READ_METHOD_BP, adios_err)
   call check_adios_err(myrank,adios_err)
 
-  call synchronize_all()
+  call synchronize_all_comm(comm)
 
 end subroutine read_mesh_databases_MPI_IC_adios
 
@@ -1296,36 +1335,34 @@
 !> \brief Read Stacey BC arrays from an ADIOS file.
 subroutine read_mesh_databases_stacey_adios()
 
-  use mpi
   use adios_read_mod
-
   use specfem_par
   use specfem_par_crustmantle
   use specfem_par_innercore
   use specfem_par_outercore
+  use adios_helpers_mod, only: check_adios_err
 
   implicit none
 
   ! local parameters
-  integer :: ierr, comm, lnspec, lnglob, local_dim
+  integer :: ierr, comm, local_dim
   ! processor identification
-  character(len=150) :: reg_name, file_name
+  character(len=256) :: file_name
   ! ADIOS variables
   integer                 :: adios_err
-  integer(kind=8)         :: adios_group, adios_handle, varid, sel
-  integer(kind=8)         :: adios_groupsize, adios_totalsize
-  integer :: vars_count, attrs_count, current_step, last_step, vsteps
-  character(len=128), dimension(:), allocatable :: adios_names
+  integer(kind=8)         :: adios_handle, sel
   integer(kind=8), dimension(1) :: start, count
 
+  character(len=128)      :: region_name
+
+  call world_duplicate(comm)
+
+  file_name= trim(LOCAL_PATH) // "/stacey.bp"
+
   ! crust and mantle
 
-  ! create name of database
-  call create_name_database_adios(reg_name, IREGION_CRUST_MANTLE, LOCAL_PATH)
+  write(region_name,"('reg',i1, '/')") IREGION_CRUST_MANTLE
 
-  file_name= trim(reg_name) // "stacey.bp"
-  call MPI_Comm_dup (MPI_COMM_WORLD, comm, ierr)
-
   call adios_read_init_method (ADIOS_READ_METHOD_BP, comm, &
       "verbose=1", adios_err)
   call check_adios_err(myrank,adios_err)
@@ -1336,15 +1373,15 @@
   local_dim = 2*NSPEC2DMAX_XMIN_XMAX_CM
   start(1) = local_dim*myrank; count(1) = local_dim
   call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "njmin/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "njmin/array", 0, 1, &
       njmin_crust_mantle, adios_err)
   call check_adios_err(myrank,adios_err)
   call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "njmax/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "njmax/array", 0, 1, &
       njmax_crust_mantle, adios_err)
   call check_adios_err(myrank,adios_err)
   call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "nkmin_xi/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "nkmin_xi/array", 0, 1, &
       nkmin_xi_crust_mantle, adios_err)
   call check_adios_err(myrank,adios_err)
 
@@ -1354,15 +1391,15 @@
   local_dim = 2*NSPEC2DMAX_YMIN_YMAX_CM
   start(1) = local_dim*myrank; count(1) = local_dim
   call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "nimin/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "nimin/array", 0, 1, &
       nimin_crust_mantle, adios_err)
   call check_adios_err(myrank,adios_err)
   call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "nimax/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "nimax/array", 0, 1, &
       nimax_crust_mantle, adios_err)
   call check_adios_err(myrank,adios_err)
   call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "nkmin_eta/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "nkmin_eta/array", 0, 1, &
       nkmin_eta_crust_mantle, adios_err)
   call check_adios_err(myrank,adios_err)
 
@@ -1370,38 +1407,26 @@
   call check_adios_err(myrank,adios_err)
 
   call adios_selection_delete(sel)
-  call adios_read_close(adios_handle, adios_err)
-  call check_adios_err(myrank,adios_err)
-  call adios_read_finalize_method(ADIOS_READ_METHOD_BP, adios_err)
-  call check_adios_err(myrank,adios_err)
 
+
   ! outer core
 
-  ! create name of database
-  call create_name_database_adios(reg_name, IREGION_OUTER_CORE, LOCAL_PATH)
+  write(region_name,"('reg',i1, '/')") IREGION_OUTER_CORE
 
-  file_name= trim(reg_name) // "stacey.bp"
-  call MPI_Comm_dup (MPI_COMM_WORLD, comm, ierr)
-
-  call adios_read_init_method (ADIOS_READ_METHOD_BP, comm, &
-      "verbose=1", adios_err)
-  call check_adios_err(myrank,adios_err)
-  call adios_read_open_file (adios_handle, file_name, 0, comm, ierr)
-  call check_adios_err(myrank,adios_err)
   ! read arrays for Stacey conditions
 
   local_dim = 2*NSPEC2DMAX_XMIN_XMAX_OC
   start(1) = local_dim*myrank; count(1) = local_dim
   call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "njmin/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "njmin/array", 0, 1, &
       njmin_outer_core, adios_err)
   call check_adios_err(myrank,adios_err)
   call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "njmax/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "njmax/array", 0, 1, &
       njmax_outer_core, adios_err)
   call check_adios_err(myrank,adios_err)
   call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "nkmin_xi/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "nkmin_xi/array", 0, 1, &
       nkmin_xi_outer_core, adios_err)
   call check_adios_err(myrank,adios_err)
 
@@ -1411,15 +1436,15 @@
   local_dim = 2*NSPEC2DMAX_YMIN_YMAX_OC
   start(1) = local_dim*myrank; count(1) = local_dim
   call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "nimin/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "nimin/array", 0, 1, &
       nimin_outer_core, adios_err)
   call check_adios_err(myrank,adios_err)
   call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "nimax/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "nimax/array", 0, 1, &
       nimax_outer_core, adios_err)
   call check_adios_err(myrank,adios_err)
   call adios_selection_boundingbox (sel , 1, start, count)
-  call adios_schedule_read(adios_handle, sel, "nkmin_eta/array", 0, 1, &
+  call adios_schedule_read(adios_handle, sel, trim(region_name) // "nkmin_eta/array", 0, 1, &
       nkmin_eta_outer_core, adios_err)
   call check_adios_err(myrank,adios_err)
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/rules.mk
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/rules.mk	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/rules.mk	2013-10-07 15:14:08 UTC (rev 22929)
@@ -184,14 +184,17 @@
 ###
 
 adios_OBJECTS = \
-	$O/adios_helpers.shared.o \
-	$O/adios_manager.shared.o \
-	$O/read_arrays_solver_adios.solverstatic.o \
-	$O/read_attenuation_adios.solverstatic.o \
-	$O/read_forward_arrays_adios.solverstatic.o \
-	$O/read_mesh_databases_adios.solverstatic.o \
-	$O/save_forward_arrays_adios.solverstatic.o \
-	$O/write_specfem_adios_header.solverstatic.o \
+	$O/adios_helpers_definitions.shared_adios_module.o \
+	$O/adios_helpers_writers.shared_adios_module.o \
+	$O/adios_helpers.shared_adios.o \
+	$O/adios_manager.shared_adios.o \
+	$O/read_arrays_solver_adios.solverstatic_adios.o \
+	$O/read_attenuation_adios.solverstatic_adios.o \
+	$O/read_forward_arrays_adios.solverstatic_adios.o \
+	$O/read_mesh_databases_adios.solverstatic_adios.o \
+	$O/save_forward_arrays_adios.solverstatic_adios.o \
+	$O/save_kernels_adios.solverstatic_adios.o \
+	$O/write_specfem_adios_header.solverstatic_adios.o \
 	$(EMPTY_MACRO)
 
 adios_STUBS = \
@@ -298,6 +301,13 @@
 ## DK DK add OpenMP compiler flag here if needed
 	${FCCOMPILE_CHECK} ${FCFLAGS_f90} -c -qsmp=omp -o $@ $<
 
+
+$O/%.solverstatic_adios.o: $S/%.f90 ${SETUP}/constants.h ${OUTPUT}/values_from_mesher.h $O/shared_par.shared_module.o $O/specfem3D_par.solverstatic_module.o $O/adios_helpers.shared_adios.o
+	${FCCOMPILE_CHECK} ${FCFLAGS_f90} -c -o $@ $<
+
+$O/%.solverstatic_adios.o: $S/%.F90 ${SETUP}/constants.h ${OUTPUT}/values_from_mesher.h $O/shared_par.shared_module.o $O/specfem3D_par.solverstatic_module.o $O/adios_helpers.shared_adios.o
+	${FCCOMPILE_CHECK} ${FCFLAGS_f90} -c -o $@ $<
+
 ###
 ### no dependence on values from mesher here
 ###
@@ -314,8 +324,8 @@
 ###
 
 $O/%.visualcc.o: $S/%.cpp ${SETUP}/config.h
-	${CC} -c $(CPPFLAGS) $(MPI_INC) -o $@ $<
+	${CC} -c $(CPPFLAGS) -o $@ $<
 
 $O/%.visualc.o: $S/%.c ${SETUP}/config.h
-	${CC} -c $(CPPFLAGS) $(MPI_INC) -o $@ $<
+	${CC} -c $(CPPFLAGS) -o $@ $<
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/save_forward_arrays_adios.F90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/save_forward_arrays_adios.F90	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/save_forward_arrays_adios.F90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -31,14 +31,17 @@
 !! \author MPBL
 !-------------------------------------------------------------------------------
 
+#include "config.fh"
+
+
 !-------------------------------------------------------------------------------
 !> \brief Write intermediate forward arrays in an ADIOS file.
 !!
 !! This subroutine is only used when NUMBER_OF_RUNS > 1 and
 !! NUMBER_OF_THIS_RUN < NUMBER_OF_RUNS.
 subroutine save_intermediate_forward_arrays_adios()
+
   ! External imports
-  use mpi
   use adios_write_mod
   ! Internal imports
   use specfem_par
@@ -46,26 +49,26 @@
   use specfem_par_innercore
   use specfem_par_outercore
 
+  use adios_helpers_mod, only: check_adios_err
+
   implicit none
   ! Local parameters
-  integer :: sizeprocs, comm, ierr
+  integer :: comm
   character(len=150) :: outputname
   integer(kind=8) :: group_size_inc
-  integer :: local_dim, global_dim, offset
   ! ADIOS variables
   integer                 :: adios_err
-  integer(kind=8)         :: adios_group, adios_handle, varid
-  integer(kind=8)         :: adios_groupsize, adios_totalsize
+  integer(kind=8)         :: adios_group, adios_handle
+  integer(kind=8)         :: adios_totalsize
 
   outputname = trim(LOCAL_TMP_PATH) // "/dump_all_arrays_adios.bp"
-  call world_size(sizeprocs) ! TODO keep it in parameters
-  call MPI_Comm_dup (MPI_COMM_WORLD, comm, ierr)
+
+  call world_duplicate(comm)
+
   group_size_inc = 0
   call adios_declare_group(adios_group, "SPECFEM3D_GLOBE_FORWARD_ARRAYS", &
       "", 1, adios_err)
-!  call check_adios_err(myrank,adios_err)
   call adios_select_method(adios_group, "MPI", "", "", adios_err)
-!  call check_adios_err(myrank,adios_err)
 
   ! Define ADIOS variables
   call define_common_forward_arrays_adios(adios_group, group_size_inc)
@@ -75,22 +78,19 @@
   ! Open an ADIOS handler to the restart file.
   call adios_open (adios_handle, "SPECFEM3D_GLOBE_FORWARD_ARRAYS", &
       outputname, "w", comm, adios_err);
-!  call check_adios_err(myrank,adios_err)
   call adios_group_size (adios_handle, group_size_inc, &
                          adios_totalsize, adios_err)
-!  call check_adios_err(myrank,adios_err)
 
   ! Issue the order to write the previously defined variable to the ADIOS file
-  call write_common_forward_arrays_adios(adios_handle, sizeprocs)
-  call write_rotation_forward_arrays_adios(adios_handle, sizeprocs)
-  call write_attenuation_forward_arrays_adios(adios_handle, sizeprocs)
+  call write_common_forward_arrays_adios(adios_handle)
+  call write_rotation_forward_arrays_adios(adios_handle)
+  call write_attenuation_forward_arrays_adios(adios_handle)
   ! Reset the path to its original value to avoid bugs.
   call adios_set_path (adios_handle, "", adios_err)
-!  call check_adios_err(myrank,adios_err)
 
   ! Close ADIOS handler to the restart file.
   call adios_close(adios_handle, adios_err)
-!  call check_adios_err(myrank,adios_err)
+
 end subroutine save_intermediate_forward_arrays_adios
 
 !-------------------------------------------------------------------------------
@@ -101,8 +101,8 @@
 !! save_intermediate_forward_arrays_adios() execpt than some arrays
 !! are only dumped if ROTATION and ATTENUATION are set to .true.
 subroutine save_forward_arrays_adios()
+
   ! External imports
-  use mpi
   use adios_write_mod
   ! Internal imports
   use specfem_par
@@ -110,33 +110,32 @@
   use specfem_par_innercore
   use specfem_par_outercore
 
+  use adios_helpers_mod, only: check_adios_err
+
+
   implicit none
   ! Local parameters
-  integer :: sizeprocs, comm, ierr
+  integer :: comm
   character(len=150) :: outputname
   integer(kind=8) :: group_size_inc
-  integer :: local_dim, global_dim, offset
-!  integer, parameter :: num_arrays = 9 ! TODO correct number
-!  character(len=256), dimension(num_arrays) :: local_dims1, local_dims2, &
-!      global_dims1, global_dims2, offsets1, offsets2, array_name
   ! ADIOS variables
   integer                 :: adios_err
-  integer(kind=8)         :: adios_group, adios_handle, varid
-  integer(kind=8)         :: adios_groupsize, adios_totalsize
+  integer(kind=8)         :: adios_group, adios_handle
+  integer(kind=8)         :: adios_totalsize
 
   outputname = trim(LOCAL_TMP_PATH) // "/save_forward_arrays.bp"
-  call world_size(sizeprocs)
-  call MPI_Comm_dup (MPI_COMM_WORLD, comm, ierr)
+
+  call world_duplicate(comm)
+
   group_size_inc = 0
 
   call adios_declare_group(adios_group, "SPECFEM3D_GLOBE_FORWARD_ARRAYS", &
       "", 1, adios_err)
-!  call check_adios_err(myrank,adios_err)
   call adios_select_method(adios_group, "MPI", "", "", adios_err)
-!  call check_adios_err(myrank,adios_err)
 
   ! Define ADIOS variables
   call define_common_forward_arrays_adios(adios_group, group_size_inc)
+  ! TODO check following:
   ! conditional definition of vars seem to mess with the group size,
   ! even if the variables are conditionnaly written.
 !  if (ROTATION_VAL) then
@@ -149,26 +148,23 @@
   ! Open an ADIOS handler to the restart file.
   call adios_open (adios_handle, "SPECFEM3D_GLOBE_FORWARD_ARRAYS", &
       outputname, "w", comm, adios_err);
-!  call check_adios_err(myrank,adios_err)
   call adios_group_size (adios_handle, group_size_inc, &
                          adios_totalsize, adios_err)
-!  call check_adios_err(myrank,adios_err)
 
   ! Issue the order to write the previously defined variable to the ADIOS file
-  call write_common_forward_arrays_adios(adios_handle, sizeprocs)
+  call write_common_forward_arrays_adios(adios_handle)
   if (ROTATION_VAL) then
-      call write_rotation_forward_arrays_adios(adios_handle, sizeprocs)
+      call write_rotation_forward_arrays_adios(adios_handle)
   endif
   if (ATTENUATION_VAL) then
-    call write_attenuation_forward_arrays_adios(adios_handle, sizeprocs)
+    call write_attenuation_forward_arrays_adios(adios_handle)
   endif
   ! Reset the path to its original value to avoid bugs.
   call adios_set_path (adios_handle, "", adios_err)
-!  call check_adios_err(myrank,adios_err)
 
   ! Close ADIOS handler to the restart file.
   call adios_close(adios_handle, adios_err)
-!  call check_adios_err(myrank,adios_err)
+
 end subroutine save_forward_arrays_adios
 
 !-------------------------------------------------------------------------------
@@ -183,6 +179,8 @@
   use specfem_par_innercore
   use specfem_par_outercore
 
+  use adios_helpers_mod
+
   implicit none
 
   integer(kind=8), intent(in) :: adios_group
@@ -191,52 +189,53 @@
   integer :: local_dim
 
   local_dim = NDIM * NGLOB_CRUST_MANTLE
-  call define_adios_global_real_1d_array(adios_group, "displ_crust_mantle", &
-      local_dim, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, "veloc_crust_mantle", &
-      local_dim, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, "accel_crust_mantle", &
-      local_dim, group_size_inc)
+  call define_adios_global_array1D(adios_group, group_size_inc, local_dim, &
+                                   "", STRINGIFY_VAR(displ_crust_mantle))
+  call define_adios_global_array1D(adios_group, group_size_inc, local_dim, &
+                                   "", STRINGIFY_VAR(veloc_crust_mantle))
+  call define_adios_global_array1D(adios_group, group_size_inc, local_dim, &
+                                   "", STRINGIFY_VAR(accel_crust_mantle))
 
   local_dim = NDIM * NGLOB_INNER_CORE
-  call define_adios_global_real_1d_array(adios_group, "displ_inner_core", &
-      local_dim, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, "veloc_inner_core", &
-      local_dim, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, "accel_inner_core", &
-      local_dim, group_size_inc)
+  call define_adios_global_array1D(adios_group, group_size_inc, local_dim, &
+                                   "", STRINGIFY_VAR(displ_inner_core))
+  call define_adios_global_array1D(adios_group, group_size_inc, local_dim, &
+                                   "", STRINGIFY_VAR(veloc_inner_core))
+  call define_adios_global_array1D(adios_group, group_size_inc, local_dim, &
+                                   "", STRINGIFY_VAR(accel_inner_core))
 
   local_dim = NGLOB_OUTER_CORE
-  call define_adios_global_real_1d_array(adios_group, "displ_outer_core", &
-      local_dim, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, "veloc_outer_core", &
-      local_dim, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, "accel_outer_core", &
-      local_dim, group_size_inc)
+  call define_adios_global_array1D(adios_group, group_size_inc, local_dim, &
+                                   "", STRINGIFY_VAR(displ_outer_core))
+  call define_adios_global_array1D(adios_group, group_size_inc, local_dim, &
+                                   "", STRINGIFY_VAR(veloc_outer_core))
+  call define_adios_global_array1D(adios_group, group_size_inc, local_dim, &
+                                   "", STRINGIFY_VAR(accel_outer_core))
 
   local_dim = NGLLX * NGLLY * NGLLZ * NSPEC_CRUST_MANTLE_STR_OR_ATT
-  call define_adios_global_real_1d_array(adios_group, &
-      "epsilondev_xx_crust_mantle", local_dim, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, &
-      "epsilondev_yy_crust_mantle", local_dim, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, &
-      "epsilondev_xy_crust_mantle", local_dim, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, &
-      "epsilondev_xz_crust_mantle", local_dim, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, &
-      "epsilondev_yz_crust_mantle", local_dim, group_size_inc)
+  call define_adios_global_array1D(adios_group, group_size_inc, local_dim, &
+                                  "", STRINGIFY_VAR(epsilondev_xx_crust_mantle))
+  call define_adios_global_array1D(adios_group, group_size_inc, local_dim, &
+                                  "", STRINGIFY_VAR(epsilondev_yy_crust_mantle))
+  call define_adios_global_array1D(adios_group, group_size_inc, local_dim, &
+                                  "", STRINGIFY_VAR(epsilondev_xy_crust_mantle))
+  call define_adios_global_array1D(adios_group, group_size_inc, local_dim, &
+                                  "", STRINGIFY_VAR(epsilondev_xz_crust_mantle))
+  call define_adios_global_array1D(adios_group, group_size_inc, local_dim, &
+                                  "", STRINGIFY_VAR(epsilondev_yz_crust_mantle))
 
+
   local_dim = NGLLX * NGLLY * NGLLZ * NSPEC_INNER_CORE_STR_OR_ATT
-  call define_adios_global_real_1d_array(adios_group, &
-      "epsilondev_xx_inner_core", local_dim, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, &
-      "epsilondev_yy_inner_core", local_dim, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, &
-      "epsilondev_xy_inner_core", local_dim, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, &
-      "epsilondev_xz_inner_core", local_dim, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, &
-      "epsilondev_yz_inner_core", local_dim, group_size_inc)
+  call define_adios_global_array1D(adios_group, group_size_inc, local_dim, &
+                                 "", STRINGIFY_VAR(epsilondev_xx_inner_core))
+  call define_adios_global_array1D(adios_group, group_size_inc, local_dim, &
+                                 "", STRINGIFY_VAR(epsilondev_yy_inner_core))
+  call define_adios_global_array1D(adios_group, group_size_inc, local_dim, &
+                                 "", STRINGIFY_VAR(epsilondev_xy_inner_core))
+  call define_adios_global_array1D(adios_group, group_size_inc, local_dim, &
+                                 "", STRINGIFY_VAR(epsilondev_xz_inner_core))
+  call define_adios_global_array1D(adios_group, group_size_inc, local_dim, &
+                                 "", STRINGIFY_VAR(epsilondev_yz_inner_core))
 end subroutine define_common_forward_arrays_adios
 
 !-------------------------------------------------------------------------------
@@ -251,6 +250,8 @@
   use specfem_par_innercore
   use specfem_par_outercore
 
+  use adios_helpers_mod
+
   implicit none
 
   integer(kind=8), intent(in) :: adios_group
@@ -259,10 +260,10 @@
   integer :: local_dim
 
   local_dim = NGLLX * NGLLY * NGLLZ * NSPEC_OUTER_CORE_ROTATION
-  call define_adios_global_real_1d_array(adios_group, &
-      "A_array_rotation", local_dim, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, &
-      "B_array_rotation", local_dim, group_size_inc)
+  call define_adios_global_array1D(adios_group, group_size_inc, local_dim, &
+                                   "", STRINGIFY_VAR(A_array_rotation))
+  call define_adios_global_array1D(adios_group, group_size_inc, local_dim, &
+                                   "", STRINGIFY_VAR(B_array_rotation))
 end subroutine define_rotation_forward_arrays_adios
 
 !-------------------------------------------------------------------------------
@@ -277,6 +278,8 @@
   use specfem_par_innercore
   use specfem_par_outercore
 
+  use adios_helpers_mod
+
   implicit none
 
   integer(kind=8), intent(in) :: adios_group
@@ -285,200 +288,132 @@
   integer :: local_dim
 
   local_dim = N_SLS*NGLLX*NGLLY*NGLLZ*NSPEC_CRUST_MANTLE_ATTENUATION
-  call define_adios_global_real_1d_array(adios_group, &
-      "R_xx_crust_mantle", local_dim, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, &
-      "R_yy_crust_mantle", local_dim, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, &
-      "R_xy_crust_mantle", local_dim, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, &
-      "R_xz_crust_mantle", local_dim, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, &
-      "R_yz_crust_mantle", local_dim, group_size_inc)
+  call define_adios_global_array1D(adios_group, group_size_inc, local_dim, &
+                                   "", STRINGIFY_VAR(R_xx_crust_mantle))
+  call define_adios_global_array1D(adios_group, group_size_inc, local_dim, &
+                                   "", STRINGIFY_VAR(R_yy_crust_mantle))
+  call define_adios_global_array1D(adios_group, group_size_inc, local_dim, &
+                                   "", STRINGIFY_VAR(R_xy_crust_mantle))
+  call define_adios_global_array1D(adios_group, group_size_inc, local_dim, &
+                                   "", STRINGIFY_VAR(R_xz_crust_mantle))
+  call define_adios_global_array1D(adios_group, group_size_inc, local_dim, &
+                                   "", STRINGIFY_VAR(R_yz_crust_mantle))
 
   local_dim = N_SLS*NGLLX*NGLLY*NGLLZ*NSPEC_INNER_CORE_ATTENUATION
-  call define_adios_global_real_1d_array(adios_group, &
-      "R_xx_inner_core", local_dim, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, &
-      "R_yy_inner_core", local_dim, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, &
-      "R_xy_inner_core", local_dim, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, &
-      "R_xz_inner_core", local_dim, group_size_inc)
-  call define_adios_global_real_1d_array(adios_group, &
-      "R_yz_inner_core", local_dim, group_size_inc)
+  call define_adios_global_array1D(adios_group, group_size_inc, local_dim, &
+                                   "", STRINGIFY_VAR(R_xx_inner_core))
+  call define_adios_global_array1D(adios_group, group_size_inc, local_dim, &
+                                   "", STRINGIFY_VAR(R_yy_inner_core))
+  call define_adios_global_array1D(adios_group, group_size_inc, local_dim, &
+                                   "", STRINGIFY_VAR(R_xy_inner_core))
+  call define_adios_global_array1D(adios_group, group_size_inc, local_dim, &
+                                   "", STRINGIFY_VAR(R_xz_inner_core))
+  call define_adios_global_array1D(adios_group, group_size_inc, local_dim, &
+                                   "", STRINGIFY_VAR(R_yz_inner_core))
 end subroutine define_attenuation_forward_arrays_adios
 
 !-------------------------------------------------------------------------------
 !>  Schedule writes of ADIOS forward arrays that are always dumped.
 !! \param adios_handle The handle to the adios bp file
 !! \param group_size_inc The number of MPI processes involved in the writting
-subroutine write_common_forward_arrays_adios(adios_handle, sizeprocs)
+subroutine write_common_forward_arrays_adios(adios_handle)
+
   use adios_write_mod
   use specfem_par
   use specfem_par_crustmantle
   use specfem_par_innercore
   use specfem_par_outercore
 
+  use adios_helpers_mod
+
   implicit none
 
   integer(kind=8), intent(in) :: adios_handle
-  integer, intent(in) :: sizeprocs
 
-  integer :: local_dim, adios_err
+  integer :: local_dim !, adios_err
 
-  local_dim = NDIM * NGLOB_CRUST_MANTLE
-  call adios_set_path (adios_handle, "displ_crust_mantle", adios_err)
-  call check_adios_err(myrank,adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", displ_crust_mantle, adios_err)
-  call check_adios_err(myrank,adios_err)
+  integer :: sizeprocs
 
-  call adios_set_path (adios_handle, "veloc_crust_mantle", adios_err)
-  call check_adios_err(myrank,adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", veloc_crust_mantle, adios_err)
-  call check_adios_err(myrank,adios_err)
+  ! number of mpi processes
+  call world_size(sizeprocs)
 
-  call adios_set_path (adios_handle, "accel_crust_mantle", adios_err)
-  call check_adios_err(myrank,adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", accel_crust_mantle, adios_err)
-  call check_adios_err(myrank,adios_err)
+  local_dim = NDIM * NGLOB_CRUST_MANTLE
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, &
+                                  local_dim, STRINGIFY_VAR(displ_crust_mantle))
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, &
+                                  local_dim, STRINGIFY_VAR(veloc_crust_mantle))
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, &
+                                  local_dim, STRINGIFY_VAR(accel_crust_mantle))
 
   local_dim = NDIM * NGLOB_INNER_CORE
-  call adios_set_path (adios_handle, "displ_inner_core", adios_err)
-  call check_adios_err(myrank,adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", displ_inner_core, adios_err)
-  call check_adios_err(myrank,adios_err)
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, &
+                                  local_dim, STRINGIFY_VAR(displ_inner_core))
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, &
+                                  local_dim, STRINGIFY_VAR(veloc_inner_core))
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, &
+                                  local_dim, STRINGIFY_VAR(accel_inner_core))
 
-  call adios_set_path (adios_handle, "veloc_inner_core", adios_err)
-  call check_adios_err(myrank,adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", veloc_inner_core, adios_err)
-  call check_adios_err(myrank,adios_err)
-
-  call adios_set_path (adios_handle, "accel_inner_core", adios_err)
-  call check_adios_err(myrank,adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", accel_inner_core, adios_err)
-  call check_adios_err(myrank,adios_err)
-  call adios_set_path (adios_handle, "", adios_err)
-  call check_adios_err(myrank,adios_err)
-
   local_dim = NGLOB_OUTER_CORE
-  call adios_set_path (adios_handle, "displ_outer_core", adios_err)
-  call check_adios_err(myrank,adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", displ_outer_core, adios_err)
-  call check_adios_err(myrank,adios_err)
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, &
+                                  local_dim, STRINGIFY_VAR(displ_outer_core))
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, &
+                                  local_dim, STRINGIFY_VAR(veloc_outer_core))
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, &
+                                  local_dim, STRINGIFY_VAR(accel_outer_core))
 
-  call adios_set_path (adios_handle, "veloc_outer_core", adios_err)
-  call check_adios_err(myrank,adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", veloc_outer_core, adios_err)
-  call check_adios_err(myrank,adios_err)
-
-  call adios_set_path (adios_handle, "accel_outer_core", adios_err)
-  call check_adios_err(myrank,adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", accel_outer_core, adios_err)
-  call check_adios_err(myrank,adios_err)
-
   local_dim = NGLLX * NGLLY * NGLLZ * NSPEC_CRUST_MANTLE_STR_OR_ATT
-  call adios_set_path (adios_handle, "epsilondev_xx_crust_mantle", adios_err)
-  call check_adios_err(myrank,adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", epsilondev_xx_crust_mantle, adios_err)
-  call check_adios_err(myrank,adios_err)
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, &
+                           local_dim, STRINGIFY_VAR(epsilondev_xx_crust_mantle))
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, &
+                           local_dim, STRINGIFY_VAR(epsilondev_yy_crust_mantle))
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, &
+                           local_dim, STRINGIFY_VAR(epsilondev_xy_crust_mantle))
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, &
+                           local_dim, STRINGIFY_VAR(epsilondev_xz_crust_mantle))
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, &
+                           local_dim, STRINGIFY_VAR(epsilondev_yz_crust_mantle))
 
-  call adios_set_path (adios_handle, "epsilondev_yy_crust_mantle", adios_err)
-  call check_adios_err(myrank,adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", epsilondev_yy_crust_mantle, adios_err)
-  call check_adios_err(myrank,adios_err)
-
-  call adios_set_path (adios_handle, "epsilondev_xy_crust_mantle", adios_err)
-  call check_adios_err(myrank,adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", epsilondev_xy_crust_mantle, adios_err)
-  call check_adios_err(myrank,adios_err)
-
-  call adios_set_path (adios_handle, "epsilondev_xz_crust_mantle", adios_err)
-  call check_adios_err(myrank,adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", epsilondev_xz_crust_mantle, adios_err)
-  call check_adios_err(myrank,adios_err)
-
-  call adios_set_path (adios_handle, "epsilondev_yz_crust_mantle", adios_err)
-  call check_adios_err(myrank,adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", epsilondev_yz_crust_mantle, adios_err)
-  call check_adios_err(myrank,adios_err)
-
   local_dim = NGLLX * NGLLY * NGLLZ * NSPEC_INNER_CORE_STR_OR_ATT
-  call adios_set_path (adios_handle, "epsilondev_xx_inner_core", adios_err)
-  call check_adios_err(myrank,adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", epsilondev_xx_inner_core, adios_err)
-  call check_adios_err(myrank,adios_err)
-
-  call adios_set_path (adios_handle, "epsilondev_yy_inner_core", adios_err)
-  call check_adios_err(myrank,adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", epsilondev_yy_inner_core, adios_err)
-  call check_adios_err(myrank,adios_err)
-
-  call adios_set_path (adios_handle, "epsilondev_xy_inner_core", adios_err)
-  call check_adios_err(myrank,adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", epsilondev_xy_inner_core, adios_err)
-  call check_adios_err(myrank,adios_err)
-
-  call adios_set_path (adios_handle, "epsilondev_xz_inner_core", adios_err)
-  call check_adios_err(myrank,adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", epsilondev_xz_inner_core, adios_err)
-  call check_adios_err(myrank,adios_err)
-
-  call adios_set_path (adios_handle, "epsilondev_yz_inner_core", adios_err)
-  call check_adios_err(myrank,adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", epsilondev_yz_inner_core, adios_err)
-  call check_adios_err(myrank,adios_err)
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, &
+                             local_dim, STRINGIFY_VAR(epsilondev_xx_inner_core))
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, &
+                             local_dim, STRINGIFY_VAR(epsilondev_yy_inner_core))
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, &
+                             local_dim, STRINGIFY_VAR(epsilondev_xy_inner_core))
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, &
+                             local_dim, STRINGIFY_VAR(epsilondev_xz_inner_core))
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, &
+                             local_dim, STRINGIFY_VAR(epsilondev_yz_inner_core))
 end subroutine write_common_forward_arrays_adios
 
 !-------------------------------------------------------------------------------
 !>  Schedule writes of ADIOS forward arrays that are dumped if ROTATION is true.
 !! \param adios_handle The handle to the adios bp file
-!! \param group_size_inc The number of MPI processes involved in the writting
-subroutine write_rotation_forward_arrays_adios(adios_handle, sizeprocs)
+subroutine write_rotation_forward_arrays_adios(adios_handle)
+
   use adios_write_mod
   use specfem_par
   use specfem_par_crustmantle
   use specfem_par_innercore
   use specfem_par_outercore
 
+  use adios_helpers_mod
+
   implicit none
 
   integer(kind=8), intent(in) :: adios_handle
-  integer, intent(in) :: sizeprocs
 
-  integer :: local_dim, adios_err
+  integer :: local_dim !, adios_err
+  integer :: sizeprocs
 
-  local_dim = NGLLX * NGLLY * NGLLZ * NSPEC_OUTER_CORE_ROTATION
-  call adios_set_path (adios_handle, "A_array_rotation", adios_err)
-  call check_adios_err(myrank,adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", A_array_rotation, adios_err)
-  call check_adios_err(myrank,adios_err)
+  ! number of mpi processes
+  call world_size(sizeprocs)
 
-  call adios_set_path (adios_handle, "B_array_rotation", adios_err)
-  call check_adios_err(myrank,adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", B_array_rotation, adios_err)
-  call check_adios_err(myrank,adios_err)
+  local_dim = NGLLX * NGLLY * NGLLZ * NSPEC_OUTER_CORE_ROTATION
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, &
+                                  local_dim, STRINGIFY_VAR(A_array_rotation))
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, &
+                                  local_dim, STRINGIFY_VAR(B_array_rotation))
 end subroutine write_rotation_forward_arrays_adios
 
 !-------------------------------------------------------------------------------
@@ -486,107 +421,74 @@
 !!  is true.
 !! \param adios_handle The handle to the adios bp file
 !! \param group_size_inc The number of MPI processes involved in the writting
-subroutine write_attenuation_forward_arrays_adios(adios_handle, sizeprocs)
+subroutine write_attenuation_forward_arrays_adios(adios_handle)
+
   use adios_write_mod
   use specfem_par
   use specfem_par_crustmantle
   use specfem_par_innercore
   use specfem_par_outercore
 
+  use adios_helpers_mod
+
   implicit none
 
   integer(kind=8), intent(in) :: adios_handle
-  integer, intent(in) :: sizeprocs
 
-  integer :: local_dim, adios_err
+  integer :: local_dim !, adios_err
+  integer :: sizeprocs
 
+  ! number of mpi processes
+  call world_size(sizeprocs)
+
   local_dim = N_SLS*NGLLX*NGLLY*NGLLZ*NSPEC_CRUST_MANTLE_ATTENUATION
-  call adios_set_path (adios_handle, "R_xx_crust_mantle", adios_err)
-  call check_adios_err(myrank,adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", R_xx_crust_mantle, adios_err)
-  call check_adios_err(myrank,adios_err)
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, &
+                                  local_dim, STRINGIFY_VAR(R_xx_crust_mantle))
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, &
+                                  local_dim, STRINGIFY_VAR(R_yy_crust_mantle))
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, &
+                                  local_dim, STRINGIFY_VAR(R_xy_crust_mantle))
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, &
+                                  local_dim, STRINGIFY_VAR(R_xz_crust_mantle))
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, &
+                                  local_dim, STRINGIFY_VAR(R_yz_crust_mantle))
 
-  call adios_set_path (adios_handle, "R_yy_crust_mantle", adios_err)
-  call check_adios_err(myrank,adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", R_yy_crust_mantle, adios_err)
-  call check_adios_err(myrank,adios_err)
-
-  call adios_set_path (adios_handle, "R_xy_crust_mantle", adios_err)
-  call check_adios_err(myrank,adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", R_xy_crust_mantle, adios_err)
-  call check_adios_err(myrank,adios_err)
-
-  call adios_set_path (adios_handle, "R_xz_crust_mantle", adios_err)
-  call check_adios_err(myrank,adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", R_xz_crust_mantle, adios_err)
-  call check_adios_err(myrank,adios_err)
-
-  call adios_set_path (adios_handle, "R_yz_crust_mantle", adios_err)
-  call check_adios_err(myrank,adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", R_yz_crust_mantle, adios_err)
-  call check_adios_err(myrank,adios_err)
-
   local_dim = N_SLS*NGLLX*NGLLY*NGLLZ*NSPEC_INNER_CORE_ATTENUATION
-  call adios_set_path (adios_handle, "R_xx_inner_core", adios_err)
-  call check_adios_err(myrank,adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", R_xx_inner_core, adios_err)
-  call check_adios_err(myrank,adios_err)
-
-  call adios_set_path (adios_handle, "R_yy_inner_core", adios_err)
-  call check_adios_err(myrank,adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", R_yy_inner_core, adios_err)
-  call check_adios_err(myrank,adios_err)
-
-  call adios_set_path (adios_handle, "R_xy_inner_core", adios_err)
-  call check_adios_err(myrank,adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", R_xy_inner_core, adios_err)
-  call check_adios_err(myrank,adios_err)
-
-  call adios_set_path (adios_handle, "R_xz_inner_core", adios_err)
-  call check_adios_err(myrank,adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", R_xz_inner_core, adios_err)
-  call check_adios_err(myrank,adios_err)
-
-  call adios_set_path (adios_handle, "R_yz_inner_core", adios_err)
-  call check_adios_err(myrank,adios_err)
-  call write_1D_global_array_adios_dims(adios_handle, local_dim, sizeprocs)
-  call adios_write(adios_handle, "array", R_yz_inner_core, adios_err)
-  call check_adios_err(myrank,adios_err)
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, &
+                                  local_dim, STRINGIFY_VAR(R_xx_inner_core))
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, &
+                                  local_dim, STRINGIFY_VAR(R_yy_inner_core))
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, &
+                                  local_dim, STRINGIFY_VAR(R_xy_inner_core))
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, &
+                                  local_dim, STRINGIFY_VAR(R_xz_inner_core))
+  call write_adios_global_1d_array(adios_handle, myrank, sizeprocs, &
+                                  local_dim, STRINGIFY_VAR(R_yz_inner_core))
 end subroutine write_attenuation_forward_arrays_adios
 
-!-------------------------------------------------------------------------------
-!> Write local, global and offset dimensions to ADIOS
-!! \param adios_handle Handle to the adios file
-!! \param local_dim Number of elements to be written by one process
-!! \param sizeprocs Number of MPI processes
-subroutine write_1D_global_array_adios_dims(adios_handle, local_dim, sizeprocs)
-  use adios_write_mod
-  use specfem_par
-  use specfem_par_crustmantle
-  use specfem_par_innercore
-  use specfem_par_outercore
+!!-------------------------------------------------------------------------------
+!!> Write local, global and offset dimensions to ADIOS
+!!! \param adios_handle Handle to the adios file
+!!! \param local_dim Number of elements to be written by one process
+!!! \param sizeprocs Number of MPI processes
+!subroutine write_1D_global_array_adios_dims(adios_handle, local_dim, sizeprocs)
+  !use adios_write_mod
+  !use specfem_par, only: myrank
 
-  implicit none
+  !use adios_helpers_mod, only: check_adios_err
 
-  integer(kind=8), intent(in) :: adios_handle
-  integer, intent(in) :: sizeprocs, local_dim
+  !implicit none
 
-  integer :: adios_err
+  !integer(kind=8), intent(in) :: adios_handle
+  !integer, intent(in) :: sizeprocs, local_dim
 
-  call adios_write(adios_handle, "local_dim", local_dim, adios_err)
-  call check_adios_err(myrank,adios_err)
-  call adios_write(adios_handle, "global_dim", local_dim*sizeprocs, adios_err)
-  call check_adios_err(myrank,adios_err)
-  call adios_write(adios_handle, "offset", local_dim*myrank, adios_err)
-  call check_adios_err(myrank,adios_err)
-end subroutine write_1D_global_array_adios_dims
+  !integer :: adios_err
 
+  !call adios_write(adios_handle, "local_dim", local_dim, adios_err)
+  !call check_adios_err(myrank,adios_err)
+  !call adios_write(adios_handle, "global_dim", local_dim*sizeprocs, adios_err)
+  !call check_adios_err(myrank,adios_err)
+  !call adios_write(adios_handle, "offset", local_dim*myrank, adios_err)
+  !call check_adios_err(myrank,adios_err)
+!end subroutine write_1D_global_array_adios_dims
+

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/save_kernels.f90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/save_kernels.f90	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/save_kernels.f90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -25,6 +25,70 @@
 !
 !=====================================================================
 
+  subroutine save_kernels()
+
+  use constants_solver,only: SAVE_BOUNDARY_MESH
+
+  use specfem_par,only: NOISE_TOMOGRAPHY,SIMULATION_TYPE,nrec_local, &
+    APPROXIMATE_HESS_KL,SAVE_REGULAR_KL, &
+    current_adios_handle,ADIOS_ENABLED,ADIOS_FOR_KERNELS
+
+  implicit none
+
+  ! Open an handler to the ADIOS file in which kernel variables are written.
+  if (((SIMULATION_TYPE == 3) .or. (SIMULATION_TYPE == 2 .and. nrec_local > 0)) &
+      .and. ADIOS_ENABLED .and. ADIOS_FOR_KERNELS) then
+    call define_kernel_adios_variables(current_adios_handle)
+  endif
+
+  ! dump kernel arrays
+  if (SIMULATION_TYPE == 3) then
+    ! crust mantle
+    if (SAVE_REGULAR_KL) then
+      call save_regular_kernels_crust_mantle()
+    else
+      call save_kernels_crust_mantle()
+    endif
+
+    ! noise strength kernel
+    if (NOISE_TOMOGRAPHY == 3) then
+       call save_kernels_strength_noise()
+    endif
+
+    ! outer core
+    call save_kernels_outer_core()
+
+    ! inner core
+    call save_kernels_inner_core()
+
+    ! boundary kernel
+    if (SAVE_BOUNDARY_MESH) then
+      call save_kernels_boundary_kl()
+    endif
+
+    ! approximate hessian
+    if( APPROXIMATE_HESS_KL ) then
+      call save_kernels_hessian()
+    endif
+  endif
+
+  ! save source derivatives for adjoint simulations
+  if (SIMULATION_TYPE == 2 .and. nrec_local > 0) then
+    call save_kernels_source_derivatives()
+  endif
+
+  ! Write ADIOS defined variables to disk.
+  if (((SIMULATION_TYPE == 3) .or. (SIMULATION_TYPE == 2 .and. nrec_local > 0)) &
+      .and. ADIOS_ENABLED .and. ADIOS_FOR_KERNELS) then
+    call perform_write_adios_kernels(current_adios_handle)
+  endif
+
+  end subroutine save_kernels
+
+!
+!-------------------------------------------------------------------------------------------------
+!
+
   subroutine save_kernels_crust_mantle()
 
   use specfem_par
@@ -313,109 +377,120 @@
     enddo
   enddo
 
-  call create_name_database(prname,myrank,IREGION_CRUST_MANTLE,LOCAL_TMP_PATH)
+  ! writes out kernels to files
+  if( ADIOS_ENABLED .and. ADIOS_FOR_KERNELS ) then
+    call write_kernels_crust_mantle_adios(current_adios_handle, &
+                                          mu_kl_crust_mantle, kappa_kl_crust_mantle, rhonotprime_kl_crust_mantle, &
+                                          alphav_kl_crust_mantle,alphah_kl_crust_mantle, &
+                                          betav_kl_crust_mantle,betah_kl_crust_mantle, &
+                                          eta_kl_crust_mantle, &
+                                          bulk_c_kl_crust_mantle,bulk_beta_kl_crust_mantle, &
+                                          bulk_betav_kl_crust_mantle,bulk_betah_kl_crust_mantle)
+  else
 
-  ! For anisotropic kernels
-  if (ANISOTROPIC_KL) then
+    call create_name_database(prname,myrank,IREGION_CRUST_MANTLE,LOCAL_TMP_PATH)
 
-    ! outputs transverse isotropic kernels only
-    if( SAVE_TRANSVERSE_KL_ONLY ) 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_crust_mantle
+    ! For anisotropic kernels
+    if (ANISOTROPIC_KL) then
+
+      ! outputs transverse isotropic kernels only
+      if( SAVE_TRANSVERSE_KL_ONLY ) 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_crust_mantle
+        close(IOUT)
+        open(unit=IOUT,file=trim(prname)//'alphah_kernel.bin',status='unknown',form='unformatted',action='write')
+        write(IOUT) alphah_kl_crust_mantle
+        close(IOUT)
+        open(unit=IOUT,file=trim(prname)//'betav_kernel.bin',status='unknown',form='unformatted',action='write')
+        write(IOUT) betav_kl_crust_mantle
+        close(IOUT)
+        open(unit=IOUT,file=trim(prname)//'betah_kernel.bin',status='unknown',form='unformatted',action='write')
+        write(IOUT) betah_kl_crust_mantle
+        close(IOUT)
+        open(unit=IOUT,file=trim(prname)//'eta_kernel.bin',status='unknown',form='unformatted',action='write')
+        write(IOUT) eta_kl_crust_mantle
+        close(IOUT)
+        open(unit=IOUT,file=trim(prname)//'rho_kernel.bin',status='unknown',form='unformatted',action='write')
+        write(IOUT) rho_kl_crust_mantle
+        close(IOUT)
+
+        ! in case one is interested in primary kernel K_rho
+        !open(unit=IOUT,file=trim(prname)//'rhonotprime_kernel.bin',status='unknown',form='unformatted',action='write')
+        !write(IOUT) rhonotprime_kl_crust_mantle
+        !close(IOUT)
+
+        ! (bulk, beta_v, beta_h, eta, rho ) parameterization: K_eta and K_rho same as above
+        open(unit=IOUT,file=trim(prname)//'bulk_c_kernel.bin',status='unknown',form='unformatted',action='write')
+        write(IOUT) bulk_c_kl_crust_mantle
+        close(IOUT)
+        open(unit=IOUT,file=trim(prname)//'bulk_betav_kernel.bin',status='unknown',form='unformatted',action='write')
+        write(IOUT) bulk_betav_kl_crust_mantle
+        close(IOUT)
+        open(unit=IOUT,file=trim(prname)//'bulk_betah_kernel.bin',status='unknown',form='unformatted',action='write')
+        write(IOUT) bulk_betah_kl_crust_mantle
+        close(IOUT)
+
+        ! to check: isotropic kernels
+        open(unit=IOUT,file=trim(prname)//'alpha_kernel.bin',status='unknown',form='unformatted',action='write')
+        write(IOUT) alpha_kl_crust_mantle
+        close(IOUT)
+        open(unit=IOUT,file=trim(prname)//'beta_kernel.bin',status='unknown',form='unformatted',action='write')
+        write(IOUT) beta_kl_crust_mantle
+        close(IOUT)
+        open(unit=IOUT,file=trim(prname)//'bulk_beta_kernel.bin',status='unknown',form='unformatted',action='write')
+        write(IOUT) bulk_beta_kl_crust_mantle
+        close(IOUT)
+
+      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)
+        open(unit=IOUT,file=trim(prname)//'rho_kernel.bin',status='unknown',form='unformatted',action='write')
+        write(IOUT) - rho_kl_crust_mantle
+        close(IOUT)
+        open(unit=IOUT,file=trim(prname)//'cijkl_kernel.bin',status='unknown',form='unformatted',action='write')
+        write(IOUT) - cijkl_kl_crust_mantle
+        close(IOUT)
+
+      endif
+
+    else
+      ! primary kernels: (rho,kappa,mu) parameterization
+      open(unit=IOUT,file=trim(prname)//'rhonotprime_kernel.bin',status='unknown',form='unformatted',action='write')
+      write(IOUT) rhonotprime_kl_crust_mantle
       close(IOUT)
-      open(unit=IOUT,file=trim(prname)//'alphah_kernel.bin',status='unknown',form='unformatted',action='write')
-      write(IOUT) alphah_kl_crust_mantle
+      open(unit=IOUT,file=trim(prname)//'kappa_kernel.bin',status='unknown',form='unformatted',action='write')
+      write(IOUT) kappa_kl_crust_mantle
       close(IOUT)
-      open(unit=IOUT,file=trim(prname)//'betav_kernel.bin',status='unknown',form='unformatted',action='write')
-      write(IOUT) betav_kl_crust_mantle
+      open(unit=IOUT,file=trim(prname)//'mu_kernel.bin',status='unknown',form='unformatted',action='write')
+      write(IOUT) mu_kl_crust_mantle
       close(IOUT)
-      open(unit=IOUT,file=trim(prname)//'betah_kernel.bin',status='unknown',form='unformatted',action='write')
-      write(IOUT) betah_kl_crust_mantle
-      close(IOUT)
-      open(unit=IOUT,file=trim(prname)//'eta_kernel.bin',status='unknown',form='unformatted',action='write')
-      write(IOUT) eta_kl_crust_mantle
-      close(IOUT)
+
+      ! (rho, alpha, beta ) parameterization
       open(unit=IOUT,file=trim(prname)//'rho_kernel.bin',status='unknown',form='unformatted',action='write')
       write(IOUT) rho_kl_crust_mantle
       close(IOUT)
-
-      ! in case one is interested in primary kernel K_rho
-      !open(unit=IOUT,file=trim(prname)//'rhonotprime_kernel.bin',status='unknown',form='unformatted',action='write')
-      !write(IOUT) rhonotprime_kl_crust_mantle
-      !close(IOUT)
-
-      ! (bulk, beta_v, beta_h, eta, rho ) parameterization: K_eta and K_rho same as above
-      open(unit=IOUT,file=trim(prname)//'bulk_c_kernel.bin',status='unknown',form='unformatted',action='write')
-      write(IOUT) bulk_c_kl_crust_mantle
-      close(IOUT)
-      open(unit=IOUT,file=trim(prname)//'bulk_betav_kernel.bin',status='unknown',form='unformatted',action='write')
-      write(IOUT) bulk_betav_kl_crust_mantle
-      close(IOUT)
-      open(unit=IOUT,file=trim(prname)//'bulk_betah_kernel.bin',status='unknown',form='unformatted',action='write')
-      write(IOUT) bulk_betah_kl_crust_mantle
-      close(IOUT)
-
-      ! to check: isotropic kernels
       open(unit=IOUT,file=trim(prname)//'alpha_kernel.bin',status='unknown',form='unformatted',action='write')
       write(IOUT) alpha_kl_crust_mantle
       close(IOUT)
       open(unit=IOUT,file=trim(prname)//'beta_kernel.bin',status='unknown',form='unformatted',action='write')
       write(IOUT) beta_kl_crust_mantle
       close(IOUT)
+
+      ! (rho, bulk, beta ) parameterization, K_rho same as above
+      open(unit=IOUT,file=trim(prname)//'bulk_c_kernel.bin',status='unknown',form='unformatted',action='write')
+      write(IOUT) bulk_c_kl_crust_mantle
+      close(IOUT)
       open(unit=IOUT,file=trim(prname)//'bulk_beta_kernel.bin',status='unknown',form='unformatted',action='write')
       write(IOUT) bulk_beta_kl_crust_mantle
       close(IOUT)
-
-    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)
-      open(unit=IOUT,file=trim(prname)//'rho_kernel.bin',status='unknown',form='unformatted',action='write')
-      write(IOUT) - rho_kl_crust_mantle
-      close(IOUT)
-      open(unit=IOUT,file=trim(prname)//'cijkl_kernel.bin',status='unknown',form='unformatted',action='write')
-      write(IOUT) - cijkl_kl_crust_mantle
-      close(IOUT)
-
     endif
 
-  else
-    ! primary kernels: (rho,kappa,mu) parameterization
-    open(unit=IOUT,file=trim(prname)//'rhonotprime_kernel.bin',status='unknown',form='unformatted',action='write')
-    write(IOUT) rhonotprime_kl_crust_mantle
-    close(IOUT)
-    open(unit=IOUT,file=trim(prname)//'kappa_kernel.bin',status='unknown',form='unformatted',action='write')
-    write(IOUT) kappa_kl_crust_mantle
-    close(IOUT)
-    open(unit=IOUT,file=trim(prname)//'mu_kernel.bin',status='unknown',form='unformatted',action='write')
-    write(IOUT) mu_kl_crust_mantle
-    close(IOUT)
+  endif ! ADIOS_FOR_KERNELS
 
-    ! (rho, alpha, beta ) parameterization
-    open(unit=IOUT,file=trim(prname)//'rho_kernel.bin',status='unknown',form='unformatted',action='write')
-    write(IOUT) rho_kl_crust_mantle
-    close(IOUT)
-    open(unit=IOUT,file=trim(prname)//'alpha_kernel.bin',status='unknown',form='unformatted',action='write')
-    write(IOUT) alpha_kl_crust_mantle
-    close(IOUT)
-    open(unit=IOUT,file=trim(prname)//'beta_kernel.bin',status='unknown',form='unformatted',action='write')
-    write(IOUT) beta_kl_crust_mantle
-    close(IOUT)
-
-    ! (rho, bulk, beta ) parameterization, K_rho same as above
-    open(unit=IOUT,file=trim(prname)//'bulk_c_kernel.bin',status='unknown',form='unformatted',action='write')
-    write(IOUT) bulk_c_kl_crust_mantle
-    close(IOUT)
-    open(unit=IOUT,file=trim(prname)//'bulk_beta_kernel.bin',status='unknown',form='unformatted',action='write')
-    write(IOUT) bulk_beta_kl_crust_mantle
-    close(IOUT)
-
-
-  endif
-
   ! cleans up temporary kernel arrays
   if( SAVE_TRANSVERSE_KL_ONLY ) then
     deallocate(alphav_kl_crust_mantle,alphah_kl_crust_mantle, &
@@ -465,15 +540,21 @@
     enddo
   enddo
 
-  call create_name_database(prname,myrank,IREGION_OUTER_CORE,LOCAL_TMP_PATH)
+  ! writes out kernels to file
+  if( ADIOS_ENABLED .and. ADIOS_FOR_KERNELS ) then
+    call write_kernels_outer_core_adios(current_adios_handle)
+  else
+    call create_name_database(prname,myrank,IREGION_OUTER_CORE,LOCAL_TMP_PATH)
 
-  open(unit=IOUT,file=trim(prname)//'rho_kernel.bin',status='unknown',form='unformatted',action='write')
-  write(IOUT) rho_kl_outer_core
-  close(IOUT)
-  open(unit=IOUT,file=trim(prname)//'alpha_kernel.bin',status='unknown',form='unformatted',action='write')
-  write(IOUT) alpha_kl_outer_core
-  close(IOUT)
+    open(unit=IOUT,file=trim(prname)//'rho_kernel.bin',status='unknown',form='unformatted',action='write')
+    write(IOUT) rho_kl_outer_core
+    close(IOUT)
+    open(unit=IOUT,file=trim(prname)//'alpha_kernel.bin',status='unknown',form='unformatted',action='write')
+    write(IOUT) alpha_kl_outer_core
+    close(IOUT)
 
+  endif
+
   end subroutine save_kernels_outer_core
 
 !
@@ -515,17 +596,22 @@
     enddo
   enddo
 
-  call create_name_database(prname,myrank,IREGION_INNER_CORE,LOCAL_TMP_PATH)
+  ! writes out kernels to file
+  if( ADIOS_ENABLED .and. ADIOS_FOR_KERNELS ) then
+    call write_kernels_inner_core_adios(current_adios_handle)
+  else
+    call create_name_database(prname,myrank,IREGION_INNER_CORE,LOCAL_TMP_PATH)
 
-  open(unit=IOUT,file=trim(prname)//'rho_kernel.bin',status='unknown',form='unformatted',action='write')
-  write(IOUT) rho_kl_inner_core
-  close(IOUT)
-  open(unit=IOUT,file=trim(prname)//'alpha_kernel.bin',status='unknown',form='unformatted',action='write')
-  write(IOUT) alpha_kl_inner_core
-  close(IOUT)
-  open(unit=IOUT,file=trim(prname)//'beta_kernel.bin',status='unknown',form='unformatted',action='write')
-  write(IOUT) beta_kl_inner_core
-  close(IOUT)
+    open(unit=IOUT,file=trim(prname)//'rho_kernel.bin',status='unknown',form='unformatted',action='write')
+    write(IOUT) rho_kl_inner_core
+    close(IOUT)
+    open(unit=IOUT,file=trim(prname)//'alpha_kernel.bin',status='unknown',form='unformatted',action='write')
+    write(IOUT) alpha_kl_inner_core
+    close(IOUT)
+    open(unit=IOUT,file=trim(prname)//'beta_kernel.bin',status='unknown',form='unformatted',action='write')
+    write(IOUT) beta_kl_inner_core
+    close(IOUT)
+  endif
 
   end subroutine save_kernels_inner_core
 
@@ -554,32 +640,37 @@
   cmb_kl = cmb_kl * scale_kl * 1.d3
   icb_kl = icb_kl * scale_kl * 1.d3
 
-  call create_name_database(prname,myrank,IREGION_CRUST_MANTLE,LOCAL_TMP_PATH)
+  ! writes out kernels to file
+  if( ADIOS_ENABLED .and. ADIOS_FOR_KERNELS ) then
+    call write_kernels_boundary_kl_adios(current_adios_handle)
+  else
+    call create_name_database(prname,myrank,IREGION_CRUST_MANTLE,LOCAL_TMP_PATH)
 
-  if (.not. SUPPRESS_CRUSTAL_MESH .and. HONOR_1D_SPHERICAL_MOHO) then
-    open(unit=IOUT,file=trim(prname)//'moho_kernel.bin',status='unknown',form='unformatted',action='write')
-    write(IOUT) moho_kl
+    if (.not. SUPPRESS_CRUSTAL_MESH .and. HONOR_1D_SPHERICAL_MOHO) then
+      open(unit=IOUT,file=trim(prname)//'moho_kernel.bin',status='unknown',form='unformatted',action='write')
+      write(IOUT) moho_kl
+      close(IOUT)
+    endif
+
+    open(unit=IOUT,file=trim(prname)//'d400_kernel.bin',status='unknown',form='unformatted',action='write')
+    write(IOUT) d400_kl
     close(IOUT)
-  endif
 
-  open(unit=IOUT,file=trim(prname)//'d400_kernel.bin',status='unknown',form='unformatted',action='write')
-  write(IOUT) d400_kl
-  close(IOUT)
+    open(unit=IOUT,file=trim(prname)//'d670_kernel.bin',status='unknown',form='unformatted',action='write')
+    write(IOUT) d670_kl
+    close(IOUT)
 
-  open(unit=IOUT,file=trim(prname)//'d670_kernel.bin',status='unknown',form='unformatted',action='write')
-  write(IOUT) d670_kl
-  close(IOUT)
+    open(unit=IOUT,file=trim(prname)//'CMB_kernel.bin',status='unknown',form='unformatted',action='write')
+    write(IOUT) cmb_kl
+    close(IOUT)
 
-  open(unit=IOUT,file=trim(prname)//'CMB_kernel.bin',status='unknown',form='unformatted',action='write')
-  write(IOUT) cmb_kl
-  close(IOUT)
+    call create_name_database(prname,myrank,IREGION_OUTER_CORE,LOCAL_PATH)
 
-  call create_name_database(prname,myrank,IREGION_OUTER_CORE,LOCAL_PATH)
+    open(unit=IOUT,file=trim(prname)//'ICB_kernel.bin',status='unknown',form='unformatted',action='write')
+    write(IOUT) icb_kl
+    close(IOUT)
+  endif
 
-  open(unit=IOUT,file=trim(prname)//'ICB_kernel.bin',status='unknown',form='unformatted',action='write')
-  write(IOUT) icb_kl
-  close(IOUT)
-
   end subroutine save_kernels_boundary_kl
 
 !
@@ -608,37 +699,44 @@
     moment_der(:,:,irec_local) = matmul(matmul(transpose(nu_source(:,:,irec_local)),moment_der(:,:,irec_local)),&
                nu_source(:,:,irec_local)) * scale_t ** 3 / scale_mass
 
-   ! derivatives for time shift and hduration
+    ! derivatives for time shift and hduration
     stshift_der(irec_local) = stshift_der(irec_local) * scale_displ**2
     shdur_der(irec_local) = shdur_der(irec_local) * scale_displ**2
 
-    write(outputname,'(a,i5.5)') 'OUTPUT_FILES/src_frechet.',number_receiver_global(irec_local)
-    open(unit=IOUT,file=trim(outputname),status='unknown',action='write')
-  !
-  ! r -> z, theta -> -n, phi -> e, plus factor 2 for Mrt,Mrp,Mtp, and 1e-7 to dyne.cm
-  !  Mrr =  Mzz
-  !  Mtt =  Mnn
-  !  Mpp =  Mee
-  !  Mrt = -Mzn
-  !  Mrp =  Mze
-  !  Mtp = -Mne
-  ! for consistency, location derivatives are in the order of [Xr,Xt,Xp]
-  ! minus sign for sloc_der(3,irec_local) to get derivative for depth instead of radius
-
-    write(IOUT,'(g16.5)') moment_der(3,3,irec_local) * 1e-7
-    write(IOUT,'(g16.5)') moment_der(1,1,irec_local) * 1e-7
-    write(IOUT,'(g16.5)') moment_der(2,2,irec_local) * 1e-7
-    write(IOUT,'(g16.5)') -2*moment_der(1,3,irec_local) * 1e-7
-    write(IOUT,'(g16.5)') 2*moment_der(2,3,irec_local) * 1e-7
-    write(IOUT,'(g16.5)') -2*moment_der(1,2,irec_local) * 1e-7
-    write(IOUT,'(g16.5)') sloc_der(2,irec_local)
-    write(IOUT,'(g16.5)') sloc_der(1,irec_local)
-    write(IOUT,'(g16.5)') -sloc_der(3,irec_local)
-    write(IOUT,'(g16.5)') stshift_der(irec_local)
-    write(IOUT,'(g16.5)') shdur_der(irec_local)
-    close(IOUT)
+    ! writes out kernels to file
+    if (.not. ( ADIOS_ENABLED .and. ADIOS_FOR_KERNELS )) then
+      write(outputname,'(a,i5.5)') 'OUTPUT_FILES/src_frechet.',number_receiver_global(irec_local)
+      open(unit=IOUT,file=trim(outputname),status='unknown',action='write')
+      !
+      ! r -> z, theta -> -n, phi -> e, plus factor 2 for Mrt,Mrp,Mtp, and 1e-7 to dyne.cm
+      !  Mrr =  Mzz
+      !  Mtt =  Mnn
+      !  Mpp =  Mee
+      !  Mrt = -Mzn
+      !  Mrp =  Mze
+      !  Mtp = -Mne
+      ! for consistency, location derivatives are in the order of [Xr,Xt,Xp]
+      ! minus sign for sloc_der(3,irec_local) to get derivative for depth instead of radius
+      write(IOUT,'(g16.5)') moment_der(3,3,irec_local) * 1e-7
+      write(IOUT,'(g16.5)') moment_der(1,1,irec_local) * 1e-7
+      write(IOUT,'(g16.5)') moment_der(2,2,irec_local) * 1e-7
+      write(IOUT,'(g16.5)') -2*moment_der(1,3,irec_local) * 1e-7
+      write(IOUT,'(g16.5)') 2*moment_der(2,3,irec_local) * 1e-7
+      write(IOUT,'(g16.5)') -2*moment_der(1,2,irec_local) * 1e-7
+      write(IOUT,'(g16.5)') sloc_der(2,irec_local)
+      write(IOUT,'(g16.5)') sloc_der(1,irec_local)
+      write(IOUT,'(g16.5)') -sloc_der(3,irec_local)
+      write(IOUT,'(g16.5)') stshift_der(irec_local)
+      write(IOUT,'(g16.5)') shdur_der(irec_local)
+      close(IOUT)
+    endif
   enddo
 
+  ! writes out kernels to file
+  if( ADIOS_ENABLED .and. ADIOS_FOR_KERNELS ) then
+    call write_kernels_source_derivatives_adios(current_adios_handle)
+  endif
+
   end subroutine save_kernels_source_derivatives
 
 !
@@ -661,12 +759,17 @@
   ! scales approximate Hessian
   hess_kl_crust_mantle(:,:,:,:) = 2._CUSTOM_REAL * hess_kl_crust_mantle(:,:,:,:) * scale_kl
 
-  ! stores into file
-  call create_name_database(prname,myrank,IREGION_CRUST_MANTLE,LOCAL_TMP_PATH)
+  ! writes out kernels to file
+  if( ADIOS_ENABLED .and. ADIOS_FOR_KERNELS ) then
+    call write_kernels_hessian_adios(current_adios_handle)
+  else
+    ! stores into file
+    call create_name_database(prname,myrank,IREGION_CRUST_MANTLE,LOCAL_TMP_PATH)
 
-  open(unit=IOUT,file=trim(prname)//'hess_kernel.bin',status='unknown',form='unformatted',action='write')
-  write(IOUT) hess_kl_crust_mantle
-  close(IOUT)
+    open(unit=IOUT,file=trim(prname)//'hess_kernel.bin',status='unknown',form='unformatted',action='write')
+    write(IOUT) hess_kl_crust_mantle
+    close(IOUT)
+  endif
 
   end subroutine save_kernels_hessian
 

Added: seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/save_kernels_adios.F90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/save_kernels_adios.F90	                        (rev 0)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/save_kernels_adios.F90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -0,0 +1,688 @@
+!=====================================================================
+!
+!          S p e c f e m 3 D  G l o b e  V e r s i o n  6 . 0
+!          --------------------------------------------------
+!
+!          Main authors: Dimitri Komatitsch and Jeroen Tromp
+!                        Princeton University, USA
+!             and CNRS / INRIA / University of Pau, France
+! (c) Princeton University and CNRS / INRIA / University of Pau
+!                            August 2013
+!
+! This 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_kernels_adios.f90
+!! \brief Save kernels arrays to file with the help of the ADIOS library.
+!! \author MPBL
+!-------------------------------------------------------------------------------
+
+#include "config.fh"
+
+!==============================================================================
+!> 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(adios_handle)
+
+  use adios_write_mod
+
+  implicit none
+
+  ! Parameters
+  integer(kind=8), intent(in) :: adios_handle
+  ! Variables
+  integer :: adios_err
+
+  call adios_close(adios_handle, adios_err)
+
+end subroutine perform_write_adios_kernels
+
+!==============================================================================
+!> 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(adios_handle)
+
+  use adios_write_mod
+
+  use specfem_par ! Just for dimensions. No need of arrays for now.
+  use specfem_par_crustmantle
+  use specfem_par_outercore
+  use specfem_par_innercore
+
+  use adios_helpers_mod
+
+  implicit none
+
+  ! Parameters
+  integer(kind=8), intent(INOUT) :: adios_handle
+  ! Variables
+  character(len=256) :: outputname, group_name
+  integer(kind=8) :: adios_group, group_size_inc, adios_totalsize
+  integer :: local_dim, comm, adios_err
+
+  ! Type inference for define_adios_global_array1D. Avoid additional args.
+  real(kind=CUSTOM_REAL), dimension(1,1,1,1) :: dummy_real4d
+
+  outputname = "OUTPUT_FILES/kernels.bp"
+  group_name = "SPECFEM3D_GLOBE_KERNELS"
+
+  call world_duplicate(comm)
+
+  group_size_inc = 0
+  call adios_declare_group(adios_group, group_name, "", 0, adios_err)
+  call adios_select_method(adios_group, "MPI", "", "", adios_err)
+
+  if (SIMULATION_TYPE == 3) then
+    ! crust mantle
+    if (ANISOTROPIC_KL) then
+
+      ! anisotropic kernels
+      local_dim = NGLLX * NGLLY * NGLLZ * NSPEC_CRUST_MANTLE_ADJOINT
+
+      ! outputs transverse isotropic kernels only
+      if( SAVE_TRANSVERSE_KL_ONLY ) then
+        call define_adios_global_array1D(adios_group, group_size_inc, &
+                                         local_dim, "",               &
+                                         "alphav_kl_crust_mantle",    &
+                                         dummy_real4d)
+        call define_adios_global_array1D(adios_group, group_size_inc, &
+                                         local_dim, "",               &
+                                         "alphah_kl_crust_mantle",    &
+                                         dummy_real4d)
+        call define_adios_global_array1D(adios_group, group_size_inc, &
+                                         local_dim, "",               &
+                                         "betav_kl_crust_mantle",     &
+                                         dummy_real4d)
+        call define_adios_global_array1D(adios_group, group_size_inc, &
+                                         local_dim, "",               &
+                                         "betah_kl_crust_mantle",     &
+                                         dummy_real4d)
+        call define_adios_global_array1D(adios_group, group_size_inc, &
+                                         local_dim, "",               &
+                                         "eta_kl_crust_mantle",       &
+                                         dummy_real4d)
+        call define_adios_global_array1D(adios_group, group_size_inc, &
+                                         local_dim, "",               &
+                                         "rho_kl_crust_mantle",       &
+                                         dummy_real4d)
+        call define_adios_global_array1D(adios_group, group_size_inc, &
+                                         local_dim, "",               &
+                                         "bulk_c_kl_crust_mantle",    &
+                                         dummy_real4d)
+        call define_adios_global_array1D(adios_group, group_size_inc,  &
+                                         local_dim, "",                &
+                                         "bulk_betav_kl_crust_mantle", &
+                                         dummy_real4d)
+        call define_adios_global_array1D(adios_group, group_size_inc,  &
+                                         local_dim, "",                &
+                                         "bulk_betah_kl_crust_mantle", &
+                                         dummy_real4d)
+        call define_adios_global_array1D(adios_group, group_size_inc, &
+                                         local_dim, "",               &
+                                         "alpha_kl_crust_mantle",     &
+                                         dummy_real4d)
+        call define_adios_global_array1D(adios_group, group_size_inc, &
+                                         local_dim, "",               &
+                                         STRINGIFY_VAR(beta_kl_crust_mantle))
+        call define_adios_global_array1D(adios_group, group_size_inc, &
+                                         local_dim, "",               &
+                                         "bulk_beta_kl_crust_mantle", &
+                                         dummy_real4d)
+
+      else
+        call define_adios_global_array1D(adios_group, group_size_inc, &
+                                         local_dim, "",               &
+                                         STRINGIFY_VAR(rho_kl_crust_mantle))
+        local_dim = 21 * NGLLX * NGLLY * NGLLZ * NSPEC_CRUST_MANTLE_ADJOINT
+        call define_adios_global_array1D(adios_group, group_size_inc, &
+                                         local_dim, "",               &
+                                         STRINGIFY_VAR(cijkl_kl_crust_mantle))
+      endif
+
+    else
+
+      ! isotropic kernels
+      local_dim = NGLLX * NGLLY * NGLLZ * NSPEC_CRUST_MANTLE_ADJOINT
+      call define_adios_global_array1D(adios_group, group_size_inc,   &
+                                       local_dim, "",                 &
+                                       "rhonotprime_kl_crust_mantle", &
+                                        dummy_real4d)
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                       local_dim, "",               &
+                                       "kappa_kl_crust_mantle",     &
+                                       dummy_real4d)
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                       local_dim, "",               &
+                                       "mu_kl_crust_mantle",        &
+                                        dummy_real4d)
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                       local_dim, "",               &
+                                       STRINGIFY_VAR(rho_kl_crust_mantle))
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                       local_dim, "",               &
+                                       STRINGIFY_VAR(alpha_kl_crust_mantle))
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                       local_dim, "",               &
+                                       STRINGIFY_VAR(beta_kl_crust_mantle))
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                       local_dim, "",               &
+                                       "bulk_c_kl_crust_mantle",    &
+                                       dummy_real4d)
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                       local_dim, "",               &
+                                       "bulk_beta_kl_crust_mantle", &
+                                       dummy_real4d)
+    endif
+
+    ! noise strength kernel
+    if (NOISE_TOMOGRAPHY == 3) then
+      local_dim = NGLLX * NGLLY * NGLLZ * NSPEC_CRUST_MANTLE_ADJOINT
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                       local_dim, "",               &
+                                       STRINGIFY_VAR(sigma_kl_crust_mantle))
+    endif
+
+    ! outer core
+    local_dim = NSPEC_OUTER_CORE * NGLLX * NGLLY * NGLLZ
+    call define_adios_global_array1D(adios_group, group_size_inc, &
+                                     local_dim, "",               &
+                                     STRINGIFY_VAR(rho_kl_outer_core))
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                       local_dim, "",               &
+                                       STRINGIFY_VAR(alpha_kl_outer_core))
+    if (deviatoric_outercore) then
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                       local_dim, "",               &
+                                       STRINGIFY_VAR(beta_kl_outer_core))
+    endif
+
+    ! inner core
+    local_dim = NSPEC_INNER_CORE * NGLLX * NGLLY * NGLLZ
+    call define_adios_global_array1D(adios_group, group_size_inc, &
+                                     local_dim, "",               &
+                                     STRINGIFY_VAR(rho_kl_inner_core))
+    call define_adios_global_array1D(adios_group, group_size_inc, &
+                                     local_dim, "",               &
+                                     STRINGIFY_VAR(alpha_kl_inner_core))
+    call define_adios_global_array1D(adios_group, group_size_inc, &
+                                     local_dim, "",               &
+                                     STRINGIFY_VAR(beta_kl_inner_core))
+
+    ! boundary kernel
+    if (SAVE_BOUNDARY_MESH) then
+      !call save_kernels_boundary_kl()
+      if (.not. SUPPRESS_CRUSTAL_MESH .and. HONOR_1D_SPHERICAL_MOHO) then
+        local_dim = NSPEC2D_MOHO * NGLLX * NGLLY * NDIM
+        call define_adios_global_array1D(adios_group, group_size_inc, &
+                                         local_dim, "",               &
+                                         STRINGIFY_VAR(moho_kl))
+      endif
+      local_dim = NSPEC2D_400 * NGLLX * NGLLY
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                       local_dim, "",               &
+                                       STRINGIFY_VAR(d400_kl))
+
+      local_dim = NSPEC2D_670 * NGLLX * NGLLY
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                       local_dim, "",               &
+                                       STRINGIFY_VAR(d670_kl))
+
+      local_dim = NSPEC2D_CMB * NGLLX * NGLLY
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                       local_dim, "",               &
+                                       STRINGIFY_VAR(cmb_kl))
+
+      local_dim = NSPEC2D_ICB * NGLLX * NGLLY
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                       local_dim, "",               &
+                                       STRINGIFY_VAR(icb_kl))
+    endif
+
+    ! approximate hessian
+    if( APPROXIMATE_HESS_KL ) then
+      !call save_kernels_hessian()
+      local_dim = NSPEC_CRUST_MANTLE_ADJOINT* NGLLX * NGLLY
+      call define_adios_global_array1D(adios_group, group_size_inc, &
+                                       local_dim, "",               &
+                                       STRINGIFY_VAR(hess_kl_crust_mantle))
+    endif
+  endif
+
+  ! save source derivatives for adjoint simulations
+  if (SIMULATION_TYPE == 2 .and. nrec_local > 0) then
+    local_dim = 3 * 3 * nrec_local
+    call define_adios_global_array1D(adios_group, group_size_inc, &
+                                     local_dim, "",               &
+                                     STRINGIFY_VAR(moment_der))
+
+    local_dim = 3 * nrec_local
+    call define_adios_global_array1D(adios_group, group_size_inc, &
+                                     local_dim, "",               &
+                                     STRINGIFY_VAR(sloc_der))
+
+    local_dim = nrec_local
+    call define_adios_global_array1D(adios_group, group_size_inc, &
+                                     local_dim, "",               &
+                                     STRINGIFY_VAR(stshift_der))
+
+    local_dim = nrec_local
+    call define_adios_global_array1D(adios_group, group_size_inc, &
+                                     local_dim, "",               &
+                                     STRINGIFY_VAR(shdur_der))
+  endif
+
+  ! Open the handle to file containing all the ADIOS variables
+  ! previously defined
+  call adios_open (adios_handle, group_name, &
+      outputname, "w", comm, adios_err);
+  call adios_group_size (adios_handle, group_size_inc, &
+                         adios_totalsize, adios_err)
+
+end subroutine define_kernel_adios_variables
+
+
+!==============================================================================
+!> Schedule ADIOS writes for kernel variables related to the crust mantle.
+!! \param[INOUT] adios_handle The handle pointing on the open ADIOS file
+!!                            intended to store kernels data.
+subroutine write_kernels_crust_mantle_adios(adios_handle, &
+                                            mu_kl_crust_mantle, kappa_kl_crust_mantle, rhonotprime_kl_crust_mantle, &
+                                            alphav_kl_crust_mantle,alphah_kl_crust_mantle, &
+                                            betav_kl_crust_mantle,betah_kl_crust_mantle, &
+                                            eta_kl_crust_mantle, &
+                                            bulk_c_kl_crust_mantle,bulk_beta_kl_crust_mantle, &
+                                            bulk_betav_kl_crust_mantle,bulk_betah_kl_crust_mantle)
+
+  use adios_write_mod
+
+  use specfem_par
+  use specfem_par_crustmantle
+
+  use adios_helpers_mod
+
+  implicit none
+
+  ! Parameters
+  integer(kind=8), intent(INOUT) :: adios_handle
+
+  real(kind=CUSTOM_REAL), dimension(NGLLX,NGLLY,NGLLZ,NSPEC_CRUST_MANTLE_ADJOINT) :: &
+      mu_kl_crust_mantle, kappa_kl_crust_mantle, rhonotprime_kl_crust_mantle, &
+      alphav_kl_crust_mantle,alphah_kl_crust_mantle, &
+      betav_kl_crust_mantle,betah_kl_crust_mantle, &
+      eta_kl_crust_mantle, &
+      bulk_c_kl_crust_mantle,bulk_beta_kl_crust_mantle, &
+      bulk_betav_kl_crust_mantle,bulk_betah_kl_crust_mantle
+
+  ! Variables
+  integer :: local_dim !, adios_err
+  integer :: sizeprocs
+
+  ! number of mpi processes
+  call world_size(sizeprocs)
+
+  ! For anisotropic kernels
+  if (ANISOTROPIC_KL) then
+    local_dim = NGLLX * NGLLY * NGLLZ * NSPEC_CRUST_MANTLE_ADJOINT
+
+    ! outputs transverse isotropic kernels only
+    if( SAVE_TRANSVERSE_KL_ONLY ) then
+      ! transverse isotropic kernels
+      ! (alpha_v, alpha_h, beta_v, beta_h, eta, rho ) parameterization
+      call write_adios_global_1d_array(adios_handle, myrank, &
+                                       sizeprocs, local_dim, &
+                                       STRINGIFY_VAR(alphav_kl_crust_mantle))
+      call write_adios_global_1d_array(adios_handle, myrank, &
+                                       sizeprocs, local_dim, &
+                                       STRINGIFY_VAR(alphah_kl_crust_mantle))
+
+      call write_adios_global_1d_array(adios_handle, myrank, &
+                                       sizeprocs, local_dim, &
+                                       STRINGIFY_VAR(betav_kl_crust_mantle))
+      call write_adios_global_1d_array(adios_handle, myrank, &
+                                       sizeprocs, local_dim, &
+                                       STRINGIFY_VAR(betah_kl_crust_mantle))
+
+      call write_adios_global_1d_array(adios_handle, myrank, &
+                                       sizeprocs, local_dim, &
+                                       STRINGIFY_VAR(eta_kl_crust_mantle))
+
+      call write_adios_global_1d_array(adios_handle, myrank, &
+                                       sizeprocs, local_dim, &
+                                       STRINGIFY_VAR(rho_kl_crust_mantle))
+
+      call write_adios_global_1d_array(adios_handle, myrank, &
+                                       sizeprocs, local_dim, &
+                                       STRINGIFY_VAR(bulk_c_kl_crust_mantle))
+      call write_adios_global_1d_array(adios_handle, myrank, &
+                                       sizeprocs, local_dim, &
+                                      STRINGIFY_VAR(bulk_betav_kl_crust_mantle))
+      call write_adios_global_1d_array(adios_handle, myrank, &
+                                       sizeprocs, local_dim, &
+                                      STRINGIFY_VAR(bulk_betah_kl_crust_mantle))
+
+      call write_adios_global_1d_array(adios_handle, myrank, &
+                                       sizeprocs, local_dim, &
+                                       STRINGIFY_VAR(alpha_kl_crust_mantle))
+      call write_adios_global_1d_array(adios_handle, myrank, &
+                                       sizeprocs, local_dim, &
+                                       STRINGIFY_VAR(beta_kl_crust_mantle))
+
+      call write_adios_global_1d_array(adios_handle, myrank, &
+                                       sizeprocs, local_dim, &
+                                       STRINGIFY_VAR(bulk_beta_kl_crust_mantle))
+    else
+      ! 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)
+      call write_adios_global_1d_array(adios_handle, myrank,  &
+                                       sizeprocs, local_dim,  &
+                                       "rho_kl_crust_mantle", &
+                                       -rho_kl_crust_mantle)
+
+      local_dim = 21 * NGLLX * NGLLY * NGLLZ * NSPEC_CRUST_MANTLE_ADJOINT
+      call write_adios_global_1d_array(adios_handle, myrank,    &
+                                       sizeprocs, local_dim,    &
+                                       "cijkl_kl_crust_mantle", &
+                                       -cijkl_kl_crust_mantle)
+    endif
+  else
+    local_dim = NGLLX * NGLLY * NGLLZ * NSPEC_CRUST_MANTLE_ADJOINT
+
+    ! primary kernels: (rho,kappa,mu) parameterization
+    call write_adios_global_1d_array(adios_handle, myrank, &
+                                     sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(rhonotprime_kl_crust_mantle))
+    call write_adios_global_1d_array(adios_handle, myrank, &
+                                     sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(kappa_kl_crust_mantle))
+    call write_adios_global_1d_array(adios_handle, myrank, &
+                                     sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(mu_kl_crust_mantle))
+
+    ! (rho, alpha, beta ) parameterization
+    call write_adios_global_1d_array(adios_handle, myrank, &
+                                     sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(rho_kl_crust_mantle))
+    call write_adios_global_1d_array(adios_handle, myrank, &
+                                     sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(alpha_kl_crust_mantle))
+    call write_adios_global_1d_array(adios_handle, myrank, &
+                                     sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(beta_kl_crust_mantle))
+
+    ! (rho, bulk, beta ) parameterization, K_rho same as above
+    call write_adios_global_1d_array(adios_handle, myrank, &
+                                     sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(bulk_c_kl_crust_mantle))
+    call write_adios_global_1d_array(adios_handle, myrank, &
+                                     sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(bulk_beta_kl_crust_mantle))
+  endif
+
+end subroutine write_kernels_crust_mantle_adios
+
+
+!==============================================================================
+!> Schedule ADIOS writes for kernel variables related to the outer core.
+!! \param[INOUT] adios_handle The handle pointing on the open ADIOS file
+!!                            intended to store kernels data.
+subroutine write_kernels_outer_core_adios(adios_handle)
+
+  use adios_write_mod
+
+  use specfem_par
+  use specfem_par_outercore
+
+  use adios_helpers_mod
+
+  implicit none
+
+  ! Parameters
+  integer(kind=8), intent(INOUT) :: adios_handle
+  ! Variables
+  integer :: local_dim !, adios_err
+  integer :: sizeprocs
+
+  ! number of mpi processes
+  call world_size(sizeprocs)
+
+  local_dim = NSPEC_OUTER_CORE * NGLLX* NGLLY * NGLLZ
+
+  call write_adios_global_1d_array(adios_handle, myrank, &
+                                   sizeprocs, local_dim, &
+                                   STRINGIFY_VAR(rho_kl_outer_core))
+  call write_adios_global_1d_array(adios_handle, myrank, &
+                                   sizeprocs, local_dim, &
+                                   STRINGIFY_VAR(alpha_kl_outer_core))
+
+  !deviatoric kernel check
+  if( deviatoric_outercore ) then
+    call write_adios_global_1d_array(adios_handle, myrank, &
+                                     sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(beta_kl_outer_core))
+  endif
+
+end subroutine write_kernels_outer_core_adios
+
+
+!==============================================================================
+!> Schedule ADIOS writes for kernel variables related to the inner core.
+!! \param[INOUT] adios_handle The handle pointing on the open ADIOS file
+!!                            intended to store kernels data.
+subroutine write_kernels_inner_core_adios(adios_handle)
+
+  use adios_write_mod
+
+  use specfem_par
+  use specfem_par_innercore
+
+  use adios_helpers_mod
+
+  implicit none
+
+  ! Parameters
+  integer(kind=8), intent(INOUT) :: adios_handle
+  ! Variables
+  integer :: local_dim !, adios_err
+  integer :: sizeprocs
+
+  ! number of mpi processes
+  call world_size(sizeprocs)
+
+  local_dim = NSPEC_INNER_CORE * NGLLX * NGLLY * NGLLZ
+
+  call write_adios_global_1d_array(adios_handle, myrank, &
+                                   sizeprocs, local_dim, &
+                                   STRINGIFY_VAR(rho_kl_inner_core))
+
+  call write_adios_global_1d_array(adios_handle, myrank, &
+                                   sizeprocs, local_dim, &
+                                   STRINGIFY_VAR(alpha_kl_inner_core))
+  call write_adios_global_1d_array(adios_handle, myrank, &
+                                   sizeprocs, local_dim, &
+                                   STRINGIFY_VAR(beta_kl_inner_core))
+end subroutine write_kernels_inner_core_adios
+
+
+!==============================================================================
+!> Schedule ADIOS writes for kernel variables related to the boundaries.
+!! \param[INOUT] adios_handle The handle pointing on the open ADIOS file
+!!                            intended to store kernels data.
+subroutine write_kernels_boundary_kl_adios(adios_handle)
+
+  use adios_write_mod
+
+  use specfem_par
+  use specfem_par_crustmantle
+  use specfem_par_innercore
+
+  use adios_helpers_mod
+
+  implicit none
+
+  ! Parameters
+  integer(kind=8), intent(INOUT) :: adios_handle
+  ! Variables
+  integer :: local_dim !, adios_err
+  integer :: sizeprocs
+
+  ! number of mpi processes
+  call world_size(sizeprocs)
+
+  if (.not. SUPPRESS_CRUSTAL_MESH .and. HONOR_1D_SPHERICAL_MOHO) then
+    local_dim = NSPEC2D_MOHO * NGLLX * NGLLY * NDIM
+
+    call write_adios_global_1d_array(adios_handle, myrank, &
+                                     sizeprocs, local_dim, &
+                                     STRINGIFY_VAR(moho_kl))
+  endif
+
+  local_dim = NSPEC2D_400 * NGLLX * NGLLY
+  call write_adios_global_1d_array(adios_handle, myrank, &
+                                   sizeprocs, local_dim, &
+                                   STRINGIFY_VAR(d400_kl))
+
+  local_dim = NSPEC2D_670 * NGLLX * NGLLY
+  call write_adios_global_1d_array(adios_handle, myrank, &
+                                   sizeprocs, local_dim, &
+                                   STRINGIFY_VAR(d670_kl))
+
+  local_dim = NSPEC2D_CMB * NGLLX * NGLLY
+  call write_adios_global_1d_array(adios_handle, myrank, &
+                                   sizeprocs, local_dim, &
+                                   STRINGIFY_VAR(cmb_kl))
+
+  local_dim = NSPEC2D_ICB * NGLLX * NGLLY
+  call write_adios_global_1d_array(adios_handle, myrank, &
+                                   sizeprocs, local_dim, &
+                                   STRINGIFY_VAR(icb_kl))
+
+end subroutine write_kernels_boundary_kl_adios
+
+
+!==============================================================================
+!> Schedule writes for the source derivatives (moment tensors and source
+!! locations.
+!! \param[INOUT] adios_handle The handle pointing on the open ADIOS file
+!!                            intended to store kernels data.
+!!
+!! \note Not to dump one value at a time (as in the non ADIOS version) data are
+!!       scaled and oriented but are not written in the same order than in the
+!!       non ADIOS version.
+!!       (see save_kernels_source_derivatives in save_kernels.f90)
+subroutine write_kernels_source_derivatives_adios(adios_handle)
+
+  use adios_write_mod
+
+  use specfem_par
+
+  use adios_helpers_mod
+
+  implicit none
+
+  ! Parameters
+  integer(kind=8), intent(INOUT) :: adios_handle
+  ! Variables
+  ! We do not want to change moment_der and sloc as it might introduce future
+  ! concerns if we want to use them after.
+  ! No use of modified moment_der values since it implies to allocate those
+  ! arrays in save_kernels() and to carry them along the way. It might be better
+  ! to transform these arrays in the post processing phase.
+  !real(kind=CUSTOM_REAL), dimension(3,3,nrec_local) :: moment_der_tmp
+  !real(kind=CUSTOM_REAL), dimension(3,nrec_local) :: sloc_der_tmp
+  integer :: local_dim !, adios_err
+  integer :: sizeprocs
+
+  ! number of mpi processes
+  call world_size(sizeprocs)
+
+  !moment_der_tmp(:, :, :) = moment_der(:, :, :) * 1e-7
+  !moment_der_tmp(1, 3, :) = -2 * moment_der(1, 3, :)
+  !moment_der_tmp(2, 3, :) =  2 * moment_der(2, 3, :)
+  !moment_der_tmp(1, 2, :) = -2 * moment_der(1, 2, :)
+  !moment_der_tmp(3, 1, :) = moment_der(1, 3, :)
+  !moment_der_tmp(3, 2, :) = moment_der(2, 3, :)
+  !moment_der_tmp(2, 1, :) = moment_der(1, 2, :)
+  !sloc_der_tmp(:, :) = - sloc_der(:, :)
+  !sloc_der_tmp(3, :) = - sloc_der(3, :)
+
+
+  local_dim = 3 * 3 * nrec_local
+  call write_adios_global_1d_array(adios_handle, myrank, &
+                                   sizeprocs, local_dim, &
+                                   STRINGIFY_VAR(moment_der))
+
+  local_dim = 3 * nrec_local
+  call write_adios_global_1d_array(adios_handle, myrank, &
+                                   sizeprocs, local_dim, &
+                                   STRINGIFY_VAR(sloc_der))
+
+  local_dim = nrec_local
+  call write_adios_global_1d_array(adios_handle, myrank, &
+                                   sizeprocs, local_dim, &
+                                   STRINGIFY_VAR(stshift_der))
+  call write_adios_global_1d_array(adios_handle, myrank, &
+                                   sizeprocs, local_dim, &
+                                   STRINGIFY_VAR(shdur_der))
+
+end subroutine write_kernels_source_derivatives_adios
+
+
+!==============================================================================
+!> Schedule ADIOS writes for kernel variables related to the Hessian.
+!! \param[INOUT] adios_handle The handle pointing on the open ADIOS file
+!!                            intended to store kernels data.
+subroutine write_kernels_hessian_adios(adios_handle)
+
+  use adios_write_mod
+
+  use specfem_par
+  use specfem_par_crustmantle
+
+  use adios_helpers_mod
+
+  implicit none
+
+  ! Parameters
+  integer(kind=8), intent(INOUT) :: adios_handle
+  ! Variables
+  integer :: local_dim !, adios_err
+  integer :: sizeprocs
+
+  ! number of mpi processes
+  call world_size(sizeprocs)
+
+  local_dim = NSPEC_CRUST_MANTLE_ADJOINT* NGLLX * NGLLY
+  ! stores into file
+  call write_adios_global_1d_array(adios_handle, myrank, &
+                                   sizeprocs, local_dim, &
+                                   STRINGIFY_VAR(hess_kl_crust_mantle))
+
+end subroutine write_kernels_hessian_adios

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/save_regular_kernels.f90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/save_regular_kernels.f90	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/save_regular_kernels.f90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -385,108 +385,117 @@
     endif
   enddo
 
-  call create_name_database(prname,myrank,IREGION_CRUST_MANTLE,LOCAL_PATH)
+  ! writes out kernels to file
+  if( ADIOS_ENABLED .and. ADIOS_FOR_KERNELS ) then
+    ! check implementation
+    call exit_mpi(myrank,'saving regular kernels in ADIOS file format is not supported yet')
 
-  ! For anisotropic kernels
-  if (ANISOTROPIC_KL) then
+  else
 
-    ! outputs transverse isotropic kernels only
-    if (SAVE_TRANSVERSE_KL_ONLY) 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_crust_mantle
+    call create_name_database(prname,myrank,IREGION_CRUST_MANTLE,LOCAL_PATH)
+
+    ! For anisotropic kernels
+    if (ANISOTROPIC_KL) then
+
+      ! outputs transverse isotropic kernels only
+      if (SAVE_TRANSVERSE_KL_ONLY) 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_crust_mantle
+        close(IOUT)
+        open(unit=IOUT,file=trim(prname)//'alphah_kernel.bin',status='unknown',form='unformatted',action='write')
+        write(IOUT) alphah_kl_crust_mantle
+        close(IOUT)
+        open(unit=IOUT,file=trim(prname)//'betav_kernel.bin',status='unknown',form='unformatted',action='write')
+        write(IOUT) betav_kl_crust_mantle
+        close(IOUT)
+        open(unit=IOUT,file=trim(prname)//'betah_kernel.bin',status='unknown',form='unformatted',action='write')
+        write(IOUT) betah_kl_crust_mantle
+        close(IOUT)
+        open(unit=IOUT,file=trim(prname)//'eta_kernel.bin',status='unknown',form='unformatted',action='write')
+        write(IOUT) eta_kl_crust_mantle
+        close(IOUT)
+        open(unit=IOUT,file=trim(prname)//'rho_kernel.bin',status='unknown',form='unformatted',action='write')
+        write(IOUT) rho_kl_crust_mantle_reg
+        close(IOUT)
+
+        ! in case one is interested in primary kernel K_rho
+        !open(unit=IOUT,file=trim(prname)//'rhonotprime_kernel.bin',status='unknown',form='unformatted',action='write')
+        !write(IOUT) rhonotprime_kl_crust_mantle
+        !close(IOUT)
+
+        ! (bulk, beta_v, beta_h, eta, rho ) parameterization: K_eta and K_rho same as above
+        open(unit=IOUT,file=trim(prname)//'bulk_c_kernel.bin',status='unknown',form='unformatted',action='write')
+        write(IOUT) bulk_c_kl_crust_mantle
+        close(IOUT)
+        open(unit=IOUT,file=trim(prname)//'bulk_betav_kernel.bin',status='unknown',form='unformatted',action='write')
+        write(IOUT) bulk_betav_kl_crust_mantle
+        close(IOUT)
+        open(unit=IOUT,file=trim(prname)//'bulk_betah_kernel.bin',status='unknown',form='unformatted',action='write')
+        write(IOUT) bulk_betah_kl_crust_mantle
+        close(IOUT)
+
+        ! to check: isotropic kernels
+        open(unit=IOUT,file=trim(prname)//'alpha_kernel.bin',status='unknown',form='unformatted',action='write')
+        write(IOUT) alpha_kl_crust_mantle_reg
+        close(IOUT)
+        open(unit=IOUT,file=trim(prname)//'beta_kernel.bin',status='unknown',form='unformatted',action='write')
+        write(IOUT) beta_kl_crust_mantle_reg
+        close(IOUT)
+        open(unit=IOUT,file=trim(prname)//'bulk_beta_kernel.bin',status='unknown',form='unformatted',action='write')
+        write(IOUT) bulk_beta_kl_crust_mantle
+        close(IOUT)
+
+      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)
+        open(unit=IOUT,file=trim(prname)//'rho_kernel.bin',status='unknown',form='unformatted',action='write')
+        write(IOUT) - rho_kl_crust_mantle_reg
+        close(IOUT)
+        open(unit=IOUT,file=trim(prname)//'cijkl_kernel.bin',status='unknown',form='unformatted',action='write')
+        write(IOUT) - cijkl_kl_crust_mantle_reg
+        close(IOUT)
+
+      endif
+
+    else
+      ! primary kernels: (rho,kappa,mu) parameterization
+      open(unit=IOUT,file=trim(prname)//'rhonotprime_kernel.bin',status='unknown',form='unformatted',action='write')
+      write(IOUT) rhonotprime_kl_crust_mantle
       close(IOUT)
-      open(unit=IOUT,file=trim(prname)//'alphah_kernel.bin',status='unknown',form='unformatted',action='write')
-      write(IOUT) alphah_kl_crust_mantle
+      open(unit=IOUT,file=trim(prname)//'kappa_kernel.bin',status='unknown',form='unformatted',action='write')
+      write(IOUT) kappa_kl_crust_mantle
       close(IOUT)
-      open(unit=IOUT,file=trim(prname)//'betav_kernel.bin',status='unknown',form='unformatted',action='write')
-      write(IOUT) betav_kl_crust_mantle
+      open(unit=IOUT,file=trim(prname)//'mu_kernel.bin',status='unknown',form='unformatted',action='write')
+      write(IOUT) mu_kl_crust_mantle
       close(IOUT)
-      open(unit=IOUT,file=trim(prname)//'betah_kernel.bin',status='unknown',form='unformatted',action='write')
-      write(IOUT) betah_kl_crust_mantle
-      close(IOUT)
-      open(unit=IOUT,file=trim(prname)//'eta_kernel.bin',status='unknown',form='unformatted',action='write')
-      write(IOUT) eta_kl_crust_mantle
-      close(IOUT)
+
+      ! (rho, alpha, beta ) parameterization
       open(unit=IOUT,file=trim(prname)//'rho_kernel.bin',status='unknown',form='unformatted',action='write')
       write(IOUT) rho_kl_crust_mantle_reg
       close(IOUT)
-
-      ! in case one is interested in primary kernel K_rho
-      !open(unit=IOUT,file=trim(prname)//'rhonotprime_kernel.bin',status='unknown',form='unformatted',action='write')
-      !write(IOUT) rhonotprime_kl_crust_mantle
-      !close(IOUT)
-
-      ! (bulk, beta_v, beta_h, eta, rho ) parameterization: K_eta and K_rho same as above
-      open(unit=IOUT,file=trim(prname)//'bulk_c_kernel.bin',status='unknown',form='unformatted',action='write')
-      write(IOUT) bulk_c_kl_crust_mantle
-      close(IOUT)
-      open(unit=IOUT,file=trim(prname)//'bulk_betav_kernel.bin',status='unknown',form='unformatted',action='write')
-      write(IOUT) bulk_betav_kl_crust_mantle
-      close(IOUT)
-      open(unit=IOUT,file=trim(prname)//'bulk_betah_kernel.bin',status='unknown',form='unformatted',action='write')
-      write(IOUT) bulk_betah_kl_crust_mantle
-      close(IOUT)
-
-      ! to check: isotropic kernels
       open(unit=IOUT,file=trim(prname)//'alpha_kernel.bin',status='unknown',form='unformatted',action='write')
       write(IOUT) alpha_kl_crust_mantle_reg
       close(IOUT)
       open(unit=IOUT,file=trim(prname)//'beta_kernel.bin',status='unknown',form='unformatted',action='write')
       write(IOUT) beta_kl_crust_mantle_reg
       close(IOUT)
+
+      ! (rho, bulk, beta ) parameterization, K_rho same as above
+      open(unit=IOUT,file=trim(prname)//'bulk_c_kernel.bin',status='unknown',form='unformatted',action='write')
+      write(IOUT) bulk_c_kl_crust_mantle
+      close(IOUT)
       open(unit=IOUT,file=trim(prname)//'bulk_beta_kernel.bin',status='unknown',form='unformatted',action='write')
       write(IOUT) bulk_beta_kl_crust_mantle
       close(IOUT)
 
-    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)
-      open(unit=IOUT,file=trim(prname)//'rho_kernel.bin',status='unknown',form='unformatted',action='write')
-      write(IOUT) - rho_kl_crust_mantle_reg
-      close(IOUT)
-      open(unit=IOUT,file=trim(prname)//'cijkl_kernel.bin',status='unknown',form='unformatted',action='write')
-      write(IOUT) - cijkl_kl_crust_mantle_reg
-      close(IOUT)
-
     endif
 
-  else
-    ! primary kernels: (rho,kappa,mu) parameterization
-    open(unit=IOUT,file=trim(prname)//'rhonotprime_kernel.bin',status='unknown',form='unformatted',action='write')
-    write(IOUT) rhonotprime_kl_crust_mantle
-    close(IOUT)
-    open(unit=IOUT,file=trim(prname)//'kappa_kernel.bin',status='unknown',form='unformatted',action='write')
-    write(IOUT) kappa_kl_crust_mantle
-    close(IOUT)
-    open(unit=IOUT,file=trim(prname)//'mu_kernel.bin',status='unknown',form='unformatted',action='write')
-    write(IOUT) mu_kl_crust_mantle
-    close(IOUT)
+  endif ! ADIOS_FOR_KERNELS
 
-    ! (rho, alpha, beta ) parameterization
-    open(unit=IOUT,file=trim(prname)//'rho_kernel.bin',status='unknown',form='unformatted',action='write')
-    write(IOUT) rho_kl_crust_mantle_reg
-    close(IOUT)
-    open(unit=IOUT,file=trim(prname)//'alpha_kernel.bin',status='unknown',form='unformatted',action='write')
-    write(IOUT) alpha_kl_crust_mantle_reg
-    close(IOUT)
-    open(unit=IOUT,file=trim(prname)//'beta_kernel.bin',status='unknown',form='unformatted',action='write')
-    write(IOUT) beta_kl_crust_mantle_reg
-    close(IOUT)
-
-    ! (rho, bulk, beta ) parameterization, K_rho same as above
-    open(unit=IOUT,file=trim(prname)//'bulk_c_kernel.bin',status='unknown',form='unformatted',action='write')
-    write(IOUT) bulk_c_kl_crust_mantle
-    close(IOUT)
-    open(unit=IOUT,file=trim(prname)//'bulk_beta_kernel.bin',status='unknown',form='unformatted',action='write')
-    write(IOUT) bulk_beta_kl_crust_mantle
-    close(IOUT)
-
-  endif
-
   ! cleans up temporary kernel arrays
   if (SAVE_TRANSVERSE_KL_ONLY) then
     deallocate(alphav_kl_crust_mantle,alphah_kl_crust_mantle, &

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/specfem3D_par.F90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/specfem3D_par.F90	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/specfem3D_par.F90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -255,13 +255,19 @@
   integer, dimension(:), allocatable :: b_request_send_scalar_oc,b_request_recv_scalar_oc
 
   !-----------------------------------------------------------------
-  ! gpu
+  ! GPU
   !-----------------------------------------------------------------
 
   ! CUDA mesh pointer<->integer wrapper
   integer(kind=8) :: Mesh_pointer
 
   !-----------------------------------------------------------------
+  ! ADIOS
+  !-----------------------------------------------------------------
+  ! adios file handle
+  integer(kind=8) :: current_adios_handle
+
+  !-----------------------------------------------------------------
   ! time scheme
   !-----------------------------------------------------------------
 
@@ -287,6 +293,8 @@
   logical :: you_can_start_doing_IOs
 #endif
 
+
+
 end module specfem_par
 
 

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/write_movie_output.f90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/write_movie_output.f90	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/write_movie_output.f90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -80,7 +80,7 @@
       endif
 
       ! integrates strain
-      call movie_volume_integrate_strain(deltat,size(Ieps_trace_over_3_crust_mantle,4), &
+      call movie_volume_integrate_strain(deltat,NSPEC_CRUST_MANTLE_3DMOVIE, &
                                         eps_trace_over_3_crust_mantle, &
                                         epsilondev_xx_crust_mantle,epsilondev_yy_crust_mantle, &
                                         epsilondev_xy_crust_mantle,epsilondev_xz_crust_mantle, &

Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/write_specfem_adios_header.F90
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/write_specfem_adios_header.F90	2013-10-07 12:24:08 UTC (rev 22928)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/src/specfem3D/write_specfem_adios_header.F90	2013-10-07 15:14:08 UTC (rev 22929)
@@ -36,6 +36,8 @@
 !-------------------------------------------------------------------------------
 !
 
+! TODO routine not used yet...
+
 !> @brief Write simulation parameters into ADIOS result file header.
 !!
 !! Write the ADIOS header containing values to ensure reproductibility of
@@ -43,13 +45,15 @@
 !! DATA/Par_file, DATA/CMTSOLUTION, DATA/STATIONS
 subroutine write_specfem_header_adios()
 
-  use constants
-  use mpi
+!  use constants
+!  use shared_input_parameters
+  use shared_parameters
+
+  use adios_helpers_mod
   use adios_write_mod
+
   use specfem_par, only : myrank, NSOURCES
 
-  use shared_input_parameters
-
   implicit none
 
   !-------------------------------------------------------------------
@@ -71,9 +75,11 @@
   character(len=:),   allocatable :: station_name, network_name
   double precision, allocatable, dimension(:) :: stlat, stlon, stele, stbur
 
+!  character(len=150) :: OUTPUT_FILES,LOCAL_PATH,LOCAL_TMP_PATH,MODEL
+
   ! Adios variables
   integer                 :: adios_err
-  integer(kind=8)         :: adios_group, adios_handle, varid
+  integer(kind=8)         :: adios_group, adios_handle !, varid
   integer(kind=8)         :: adios_groupsize, adios_totalsize
   ! TODO: find a better name once the use of ADIOS is more completely
   !       implemented
@@ -81,8 +87,8 @@
   integer(kind=8)   :: group_size_inc
   integer           :: model_length ! for later reading of MODEL
   integer           :: isource, irec, ier
+  integer :: comm
 
-
   ! only the master needs to read the values to be written
   if(myrank == 0) then
     call adios_declare_group (adios_group, "SPECFEM3D_GLOBE_HEADER",           &
@@ -115,9 +121,10 @@
     call define_stations_variables (adios_group, group_size_inc, NSTATIONS,    &
         station_name_length, network_name_length)
 
+    call world_get_comm_self(comm)
     ! open the file where the headers have to be written
     call adios_open (adios_handle, "SPECFEM3D_GLOBE_HEADER", filename, "w",    &
-                     MPI_COMM_SELF, adios_err);
+                     comm, adios_err);
     ! The group size have been auto-incremented
     adios_groupsize = group_size_inc
     call adios_group_size (adios_handle, adios_groupsize,                      &
@@ -188,14 +195,17 @@
 
   pkg_str_len    = len_trim(PACKAGE_STRING)
   conf_flags_len = len_trim(CONFIGURE_FLAGS)
-  call define_adios_integer_scalar (adios_group, "package_string_length", &
+
+  call define_adios_integer_scalar_s (adios_group, "package_string_length", &
       "/solver_info", group_size_inc)
-  call define_adios_string (adios_group, "package_name", "/solver_info", &
+  call define_adios_string_s (adios_group, "package_name", "/solver_info", &
       pkg_str_len, group_size_inc)
-  call define_adios_integer_scalar (adios_group, "conf_flags_len", &
+
+  call define_adios_integer_scalar_s (adios_group, "conf_flags_len", &
       "/solver_info", group_size_inc)
-  call define_adios_string (adios_group, "conf_flags", "/solver_info", &
+  call define_adios_string_s (adios_group, "conf_flags", "/solver_info", &
       conf_flags_len, group_size_inc)
+
 end subroutine define_solver_info_variables
 
 !> \brief Define ADIOS variable to store values from the Par_file
@@ -204,82 +214,85 @@
 !! \param model_length The number of character of the MODEL string.
 !!                     Usefull for reading back the MODEL
 subroutine define_par_file_variables (adios_group, group_size_inc, model_length)
+
   implicit none
+
   ! Parameters
   integer(kind=8), intent(in)    :: adios_group
   integer(kind=8), intent(inout) :: group_size_inc
   integer, intent(in)            :: model_length ! for later reading of MODEL
 
   !-- double precision variables
-  call define_adios_double_scalar (adios_group, "ANGULAR_WIDTH_XI_IN_DEGREES", &
+  call define_adios_double_scalar_s (adios_group, "ANGULAR_WIDTH_XI_IN_DEGREES", &
       "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_double_scalar (adios_group, "ANGULAR_WIDTH_ETA_IN_DEGREES", &
+  call define_adios_double_scalar_s (adios_group, "ANGULAR_WIDTH_ETA_IN_DEGREES", &
       "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_double_scalar (adios_group, "CENTER_LONGITUDE_IN_DEGREES", &
+  call define_adios_double_scalar_s (adios_group, "CENTER_LONGITUDE_IN_DEGREES", &
       "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_double_scalar (adios_group, "CENTER_LATITUDE_IN_DEGREES", &
+  call define_adios_double_scalar_s (adios_group, "CENTER_LATITUDE_IN_DEGREES", &
       "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_double_scalar (adios_group, "GAMMA_ROTATION_AZIMUTH", &
+  call define_adios_double_scalar_s (adios_group, "GAMMA_ROTATION_AZIMUTH", &
       "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_double_scalar (adios_group, "HDUR_MOVIE", &
+  call define_adios_double_scalar_s (adios_group, "HDUR_MOVIE", &
       "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_double_scalar (adios_group, "MOVIE_TOP_KM", &
+  call define_adios_double_scalar_s (adios_group, "MOVIE_TOP_KM", &
       "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_double_scalar (adios_group, "MOVIE_BOTTOM_KM", &
+  call define_adios_double_scalar_s (adios_group, "MOVIE_BOTTOM_KM", &
       "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_double_scalar (adios_group, "MOVIE_EAST_DEG", &
+  call define_adios_double_scalar_s (adios_group, "MOVIE_EAST_DEG", &
       "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_double_scalar (adios_group, "MOVIE_WEST_DEG", &
+  call define_adios_double_scalar_s (adios_group, "MOVIE_WEST_DEG", &
       "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_double_scalar (adios_group, "MOVIE_NORTH_DEG", &
+  call define_adios_double_scalar_s (adios_group, "MOVIE_NORTH_DEG", &
       "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_double_scalar (adios_group, "MOVIE_SOUTH_DEG", &
+  call define_adios_double_scalar_s (adios_group, "MOVIE_SOUTH_DEG", &
       "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_double_scalar (adios_group, "RECORD_LENGTH_IN_MINUTES", &
+  call define_adios_double_scalar_s (adios_group, "RECORD_LENGTH_IN_MINUTES", &
       "/specfem3D_globe_parameter_file", group_size_inc)
   !-- integer variables
-  call define_adios_integer_scalar (adios_group, "NTSTEP_BETWEEN_OUTPUT_SEISMOS", &
+  call define_adios_integer_scalar_s (adios_group, "NTSTEP_BETWEEN_OUTPUT_SEISMOS", &
       "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_integer_scalar (adios_group, "NTSTEP_BETWEEN_READ_ADJSRC", "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_integer_scalar (adios_group, "NTSTEP_BETWEEN_FRAMES", "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_integer_scalar (adios_group, "NTSTEP_BETWEEN_OUTPUT_INFO", "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_integer_scalar (adios_group, "NUMBER_OF_RUNS", "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_integer_scalar (adios_group, "NUMBER_OF_THIS_RUN", "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_integer_scalar (adios_group, "NCHUNKS", "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_integer_scalar (adios_group, "SIMULATION_TYPE", "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_integer_scalar (adios_group, "MOVIE_VOLUME_TYPE", "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_integer_scalar (adios_group, "MOVIE_START", "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_integer_scalar (adios_group, "MOVIE_STOP", "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_integer_scalar (adios_group, "NEX_XI", "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_integer_scalar (adios_group, "NEX_ETA", "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_integer_scalar (adios_group, "NPROC_XI", "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_integer_scalar (adios_group, "NPROC_ETA", "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_integer_scalar (adios_group, "NOISE_TOMOGRAPHY", "/specfem3D_globe_parameter_file", group_size_inc)
+  call define_adios_integer_scalar_s(adios_group, "NTSTEP_BETWEEN_READ_ADJSRC", "/specfem3D_globe_parameter_file", group_size_inc)
+  call define_adios_integer_scalar_s(adios_group, "NTSTEP_BETWEEN_FRAMES", "/specfem3D_globe_parameter_file", group_size_inc)
+  call define_adios_integer_scalar_s(adios_group, "NTSTEP_BETWEEN_OUTPUT_INFO", "/specfem3D_globe_parameter_file", group_size_inc)
+  call define_adios_integer_scalar_s(adios_group, "NUMBER_OF_RUNS", "/specfem3D_globe_parameter_file", group_size_inc)
+  call define_adios_integer_scalar_s(adios_group, "NUMBER_OF_THIS_RUN", "/specfem3D_globe_parameter_file", group_size_inc)
+  call define_adios_integer_scalar_s(adios_group, "NCHUNKS", "/specfem3D_globe_parameter_file", group_size_inc)
+  call define_adios_integer_scalar_s(adios_group, "SIMULATION_TYPE", "/specfem3D_globe_parameter_file", group_size_inc)
+  call define_adios_integer_scalar_s(adios_group, "MOVIE_VOLUME_TYPE", "/specfem3D_globe_parameter_file", group_size_inc)
+  call define_adios_integer_scalar_s(adios_group, "MOVIE_START", "/specfem3D_globe_parameter_file", group_size_inc)
+  call define_adios_integer_scalar_s(adios_group, "MOVIE_STOP", "/specfem3D_globe_parameter_file", group_size_inc)
+  call define_adios_integer_scalar_s(adios_group, "NEX_XI", "/specfem3D_globe_parameter_file", group_size_inc)
+  call define_adios_integer_scalar_s(adios_group, "NEX_ETA", "/specfem3D_globe_parameter_file", group_size_inc)
+  call define_adios_integer_scalar_s(adios_group, "NPROC_XI", "/specfem3D_globe_parameter_file", group_size_inc)
+  call define_adios_integer_scalar_s(adios_group, "NPROC_ETA", "/specfem3D_globe_parameter_file", group_size_inc)
+  call define_adios_integer_scalar_s(adios_group, "NOISE_TOMOGRAPHY", "/specfem3D_globe_parameter_file", group_size_inc)
   !-- logical variables
-  call define_adios_byte_scalar (adios_group, "ELLIPTICITY", "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_byte_scalar (adios_group, "GRAVITY", "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_byte_scalar (adios_group, "ROTATION", "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_byte_scalar (adios_group, "TOPOGRAPHY", "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_byte_scalar (adios_group, "OCEANS", "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_byte_scalar (adios_group, "MOVIE_SURFACE", "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_byte_scalar (adios_group, "MOVIE_VOLUME", "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_byte_scalar (adios_group, "MOVIE_COARSE", "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_byte_scalar (adios_group, "RECEIVERS_CAN_BE_BURIED", "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_byte_scalar (adios_group, "PRINT_SOURCE_TIME_FUNCTION", "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_byte_scalar (adios_group, "SAVE_MESH_FILES", "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_byte_scalar (adios_group, "ATTENUATION", "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_byte_scalar (adios_group, "ABSORBING_CONDITIONS", "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_byte_scalar (adios_group, "SAVE_FORWARD", "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_byte_scalar (adios_group, "OUTPUT_SEISMOS_ASCII_TEXT", "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_byte_scalar (adios_group, "OUTPUT_SEISMOS_SAC_ALPHANUM", "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_byte_scalar (adios_group, "OUTPUT_SEISMOS_SAC_BINARY", "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_byte_scalar (adios_group, "ROTATE_SEISMOGRAMS_RT", "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_byte_scalar (adios_group, "WRITE_SEISMOGRAMS_BY_MASTER", "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_byte_scalar (adios_group, "SAVE_ALL_SEISMOS_IN_ONE_FILE", "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_byte_scalar (adios_group, "USE_BINARY_FOR_LARGE_FILE", "/specfem3D_globe_parameter_file", group_size_inc)
+  call define_adios_byte_scalar_s(adios_group, "ELLIPTICITY", "/specfem3D_globe_parameter_file", group_size_inc)
+  call define_adios_byte_scalar_s(adios_group, "GRAVITY", "/specfem3D_globe_parameter_file", group_size_inc)
+  call define_adios_byte_scalar_s(adios_group, "ROTATION", "/specfem3D_globe_parameter_file", group_size_inc)
+  call define_adios_byte_scalar_s(adios_group, "TOPOGRAPHY", "/specfem3D_globe_parameter_file", group_size_inc)
+  call define_adios_byte_scalar_s(adios_group, "OCEANS", "/specfem3D_globe_parameter_file", group_size_inc)
+  call define_adios_byte_scalar_s(adios_group, "MOVIE_SURFACE", "/specfem3D_globe_parameter_file", group_size_inc)
+  call define_adios_byte_scalar_s(adios_group, "MOVIE_VOLUME", "/specfem3D_globe_parameter_file", group_size_inc)
+  call define_adios_byte_scalar_s(adios_group, "MOVIE_COARSE", "/specfem3D_globe_parameter_file", group_size_inc)
+  call define_adios_byte_scalar_s(adios_group, "RECEIVERS_CAN_BE_BURIED", "/specfem3D_globe_parameter_file", group_size_inc)
+  call define_adios_byte_scalar_s(adios_group, "PRINT_SOURCE_TIME_FUNCTION", "/specfem3D_globe_parameter_file", group_size_inc)
+  call define_adios_byte_scalar_s(adios_group, "SAVE_MESH_FILES", "/specfem3D_globe_parameter_file", group_size_inc)
+  call define_adios_byte_scalar_s(adios_group, "ATTENUATION", "/specfem3D_globe_parameter_file", group_size_inc)
+  call define_adios_byte_scalar_s(adios_group, "ABSORBING_CONDITIONS", "/specfem3D_globe_parameter_file", group_size_inc)
+  call define_adios_byte_scalar_s(adios_group, "SAVE_FORWARD", "/specfem3D_globe_parameter_file", group_size_inc)
+  call define_adios_byte_scalar_s(adios_group, "OUTPUT_SEISMOS_ASCII_TEXT", "/specfem3D_globe_parameter_file", group_size_inc)
+  call define_adios_byte_scalar_s(adios_group, "OUTPUT_SEISMOS_SAC_ALPHANUM", "/specfem3D_globe_parameter_file", group_size_inc)
+  call define_adios_byte_scalar_s(adios_group, "OUTPUT_SEISMOS_SAC_BINARY", "/specfem3D_globe_parameter_file", group_size_inc)
+  call define_adios_byte_scalar_s(adios_group, "ROTATE_SEISMOGRAMS_RT", "/specfem3D_globe_parameter_file", group_size_inc)
+  call define_adios_byte_scalar_s(adios_group, "WRITE_SEISMOGRAMS_BY_MASTER", "/specfem3D_globe_parameter_file", group_size_inc)
+  call define_adios_byte_scalar_s(adios_group, "SAVE_ALL_SEISMOS_IN_ONE_FILE", "/specfem3D_globe_parameter_file", group_size_inc)
+  call define_adios_byte_scalar_s(adios_group, "USE_BINARY_FOR_LARGE_FILE", "/specfem3D_globe_parameter_file", group_size_inc)
   !-- string variables
-  call define_adios_integer_scalar (adios_group, "model_length", "/specfem3D_globe_parameter_file", group_size_inc)
-  call define_adios_string (adios_group, "MODEL", "/specfem3D_globe_parameter_file", model_length, group_size_inc)
+  call define_adios_integer_scalar_s (adios_group, "model_length", "/specfem3D_globe_parameter_file", group_size_inc)
+  call define_adios_string_s (adios_group, "MODEL", "/specfem3D_globe_parameter_file", model_length, group_size_inc)
+
 end subroutine define_par_file_variables
 
 
@@ -297,31 +310,32 @@
   integer, intent(in) :: NSOURCES, datasource_length, event_name_length
 
   !-- Number of SOURCES inside the CMTSOLUTION file
-  call define_adios_integer_scalar (adios_group, "NSOURCES", "/CMTSOLUTION", group_size_inc)
+  call define_adios_integer_scalar_s (adios_group, "NSOURCES", "/CMTSOLUTION", group_size_inc)
   !-- double precision arrays
-  call define_adios_double_local_array1D (adios_group, "second", "/CMTSOLUTION", NSOURCES, "NSOURCES", group_size_inc)
-  call define_adios_double_local_array1D (adios_group, "time_shift", "/CMTSOLUTION", NSOURCES, "NSOURCES", group_size_inc)
-  call define_adios_double_local_array1D (adios_group, "half_duration", "/CMTSOLUTION", NSOURCES, "NSOURCES", group_size_inc)
-  call define_adios_double_local_array1D (adios_group, "latitude", "/CMTSOLUTION", NSOURCES, "NSOURCES", group_size_inc)
-  call define_adios_double_local_array1D (adios_group, "longitude", "/CMTSOLUTION", NSOURCES, "NSOURCES", group_size_inc)
-  call define_adios_double_local_array1D (adios_group, "depth", "/CMTSOLUTION", NSOURCES, "NSOURCES", group_size_inc)
-  call define_adios_double_local_array1D (adios_group, "mrr", "/CMTSOLUTION", NSOURCES, "NSOURCES", group_size_inc)
-  call define_adios_double_local_array1D (adios_group, "mtt", "/CMTSOLUTION", NSOURCES, "NSOURCES", group_size_inc)
-  call define_adios_double_local_array1D (adios_group, "mpp", "/CMTSOLUTION", NSOURCES, "NSOURCES", group_size_inc)
-  call define_adios_double_local_array1D (adios_group, "mrt", "/CMTSOLUTION", NSOURCES, "NSOURCES", group_size_inc)
-  call define_adios_double_local_array1D (adios_group, "mrp", "/CMTSOLUTION", NSOURCES, "NSOURCES", group_size_inc)
-  call define_adios_double_local_array1D (adios_group, "mtp", "/CMTSOLUTION", NSOURCES, "NSOURCES", group_size_inc)
+  call define_adios_double_local_array1D_s (adios_group, "second", "/CMTSOLUTION", NSOURCES, "NSOURCES", group_size_inc)
+  call define_adios_double_local_array1D_s (adios_group, "time_shift", "/CMTSOLUTION", NSOURCES, "NSOURCES", group_size_inc)
+  call define_adios_double_local_array1D_s (adios_group, "half_duration", "/CMTSOLUTION", NSOURCES, "NSOURCES", group_size_inc)
+  call define_adios_double_local_array1D_s (adios_group, "latitude", "/CMTSOLUTION", NSOURCES, "NSOURCES", group_size_inc)
+  call define_adios_double_local_array1D_s (adios_group, "longitude", "/CMTSOLUTION", NSOURCES, "NSOURCES", group_size_inc)
+  call define_adios_double_local_array1D_s (adios_group, "depth", "/CMTSOLUTION", NSOURCES, "NSOURCES", group_size_inc)
+  call define_adios_double_local_array1D_s (adios_group, "mrr", "/CMTSOLUTION", NSOURCES, "NSOURCES", group_size_inc)
+  call define_adios_double_local_array1D_s (adios_group, "mtt", "/CMTSOLUTION", NSOURCES, "NSOURCES", group_size_inc)
+  call define_adios_double_local_array1D_s (adios_group, "mpp", "/CMTSOLUTION", NSOURCES, "NSOURCES", group_size_inc)
+  call define_adios_double_local_array1D_s (adios_group, "mrt", "/CMTSOLUTION", NSOURCES, "NSOURCES", group_size_inc)
+  call define_adios_double_local_array1D_s (adios_group, "mrp", "/CMTSOLUTION", NSOURCES, "NSOURCES", group_size_inc)
+  call define_adios_double_local_array1D_s (adios_group, "mtp", "/CMTSOLUTION", NSOURCES, "NSOURCES", group_size_inc)
   !-- integer arrays
-  call define_adios_integer_local_array1D (adios_group, "year", "/CMTSOLUTION", NSOURCES, "NSOURCES", group_size_inc)
-  call define_adios_integer_local_array1D (adios_group, "month", "/CMTSOLUTION", NSOURCES, "NSOURCES", group_size_inc)
-  call define_adios_integer_local_array1D (adios_group, "day", "/CMTSOLUTION", NSOURCES, "NSOURCES", group_size_inc)
-  call define_adios_integer_local_array1D (adios_group, "hour", "/CMTSOLUTION", NSOURCES, "NSOURCES", group_size_inc)
-  call define_adios_integer_local_array1D (adios_group, "minute", "/CMTSOLUTION", NSOURCES, "NSOURCES", group_size_inc)
+  call define_adios_integer_local_array1D_s (adios_group, "year", "/CMTSOLUTION", NSOURCES, "NSOURCES", group_size_inc)
+  call define_adios_integer_local_array1D_s (adios_group, "month", "/CMTSOLUTION", NSOURCES, "NSOURCES", group_size_inc)
+  call define_adios_integer_local_array1D_s (adios_group, "day", "/CMTSOLUTION", NSOURCES, "NSOURCES", group_size_inc)
+  call define_adios_integer_local_array1D_s (adios_group, "hour", "/CMTSOLUTION", NSOURCES, "NSOURCES", group_size_inc)
+  call define_adios_integer_local_array1D_s (adios_group, "minute", "/CMTSOLUTION", NSOURCES, "NSOURCES", group_size_inc)
   !-- string
-  call define_adios_integer_scalar (adios_group, "event_name_length", "/CMTSOLUTION", group_size_inc)
-  call define_adios_string (adios_group, "event_name", "/CMTSOLUTION", event_name_length, group_size_inc)
-  call define_adios_integer_scalar (adios_group, "datasource_length", "/CMTSOLUTION", group_size_inc)
-  call define_adios_string (adios_group, "datasource", "/CMTSOLUTION", datasource_length, group_size_inc)
+  call define_adios_integer_scalar_s (adios_group, "event_name_length", "/CMTSOLUTION", group_size_inc)
+  call define_adios_string_s (adios_group, "event_name", "/CMTSOLUTION", event_name_length, group_size_inc)
+  call define_adios_integer_scalar_s (adios_group, "datasource_length", "/CMTSOLUTION", group_size_inc)
+  call define_adios_string_s (adios_group, "datasource", "/CMTSOLUTION", datasource_length, group_size_inc)
+
 end subroutine define_cmtsolution_variables
 
 !> \brief Define ADIOS variable to store values from the STATIONS file
@@ -340,17 +354,18 @@
   integer, intent(in) :: NSTATIONS, station_name_length, network_name_length
 
   !-- Number of STATIONS inside the STATIONS file
-  call define_adios_integer_scalar (adios_group, "NSTATIONS", "/STATIONS", group_size_inc)
+  call define_adios_integer_scalar_s (adios_group, "NSTATIONS", "/STATIONS", group_size_inc)
   !-- double precision arrays
-  call define_adios_double_local_array1D (adios_group, "station_latitude", "/STATIONS", NSTATIONS, "NSTATIONS", group_size_inc)
-  call define_adios_double_local_array1D (adios_group, "station_longitude", "/STATIONS", NSTATIONS, "NSTATIONS", group_size_inc)
-  call define_adios_double_local_array1D (adios_group, "station_elevation", "/STATIONS", NSTATIONS, "NSTATIONS", group_size_inc)
-  call define_adios_double_local_array1D (adios_group, "station_burial", "/STATIONS", NSTATIONS, "NSTATIONS", group_size_inc)
+  call define_adios_double_local_array1D_s (adios_group, "station_latitude", "/STATIONS", NSTATIONS, "NSTATIONS", group_size_inc)
+  call define_adios_double_local_array1D_s (adios_group, "station_longitude", "/STATIONS", NSTATIONS, "NSTATIONS", group_size_inc)
+  call define_adios_double_local_array1D_s (adios_group, "station_elevation", "/STATIONS", NSTATIONS, "NSTATIONS", group_size_inc)
+  call define_adios_double_local_array1D_s (adios_group, "station_burial", "/STATIONS", NSTATIONS, "NSTATIONS", group_size_inc)
   !-- string
-  call define_adios_integer_scalar (adios_group, "station_name_length", "/STATIONS", group_size_inc)
-  call define_adios_integer_scalar (adios_group, "network_name_length", "/STATIONS", group_size_inc)
-  call define_adios_string (adios_group, "station_name", "/STATIONS", station_name_length, group_size_inc)
-  call define_adios_string (adios_group, "network_name", "/STATIONS", network_name_length, group_size_inc)
+  call define_adios_integer_scalar_s (adios_group, "station_name_length", "/STATIONS", group_size_inc)
+  call define_adios_integer_scalar_s (adios_group, "network_name_length", "/STATIONS", group_size_inc)
+  call define_adios_string_s (adios_group, "station_name", "/STATIONS", station_name_length, group_size_inc)
+  call define_adios_string_s (adios_group, "network_name", "/STATIONS", network_name_length, group_size_inc)
+
 end subroutine define_stations_variables
 
 !> \brief Read the 'CMTSOLUTION file' and do not modify nor transform variables
@@ -477,6 +492,9 @@
 !!                     concatenated
 subroutine read_raw_stations (NSTATIONS, stlat, stlon, stele, stbur,           &
     station_name_length, station_name, network_name_length, network_name)
+
+  use constants,only: MAX_LENGTH_STATION_NAME,MAX_LENGTH_NETWORK_NAME,IMAIN
+
   implicit none
   ! Parameters
   integer :: NSTATIONS
@@ -581,7 +599,7 @@
       MOVIE_NORTH_DEG,MOVIE_SOUTH_DEG, RECORD_LENGTH_IN_MINUTES
   logical, intent(in) :: ELLIPTICITY,GRAVITY,ROTATION,TOPOGRAPHY,OCEANS,       &
       MOVIE_SURFACE, MOVIE_VOLUME,MOVIE_COARSE, RECEIVERS_CAN_BE_BURIED,       &
-      PRINT_SOURCE_TIME_FUNCTION, SAVE_MESH_FILES,ATTENUATION, &
+      PRINT_SOURCE_TIME_FUNCTION, SAVE_MESH_FILES,ATTENUATION,                 &
       ABSORBING_CONDITIONS,SAVE_FORWARD, OUTPUT_SEISMOS_ASCII_TEXT,            &
       OUTPUT_SEISMOS_SAC_ALPHANUM,OUTPUT_SEISMOS_SAC_BINARY,                   &
       ROTATE_SEISMOGRAMS_RT,WRITE_SEISMOGRAMS_BY_MASTER,                       &
@@ -720,4 +738,167 @@
 end subroutine write_adios_stations_variables
 
 
+!===============================================================================
+!> 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 name The variable to be defined
+!! \param path The logical path structuring the data and containing
+!!             the variable
+!! \param group_size_inc The inout adios group size to increment
+!!                       with the size of the variable
+subroutine define_adios_double_scalar_s (adios_group, name, path, group_size_inc)
+  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
+  ! 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_s
+
+!===============================================================================
+!> 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 name The variable to be defined
+!! \param path The logical path structuring the data and containing
+!!             the variable
+!! \param group_size_inc The inout adios group size to increment
+!!                       with the size of the variable
+subroutine define_adios_integer_scalar_s (adios_group, name, path, group_size_inc)
+  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
+  ! 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_s
+
+!===============================================================================
+!> 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 name The variable to be defined
+!! \param path The logical path structuring the data and containing
+!!             the variable
+!! \param group_size_inc The inout adios group size to increment
+!!                       with the size of the variable
+subroutine define_adios_byte_scalar_s (adios_group, name, path, group_size_inc)
+  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
+  ! 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_s
+
+!===============================================================================
+!> Define a local ADIOS string and autoincrement the adios
+!! group size by (1 * string's length).
+!! \param adios_group The adios group where the variables belongs
+!! \param name The variable to be defined
+!! \param path The logical path structuring the data and containing
+!!             the variable
+!! \param len The length of the string(number of character. in Fortran
+!!            it does not include a final '\0' -- null -- character)
+!! \param group_size_inc The inout adios group size to increment
+!!                       with the size of the variable
+!! \note Adios string are scalar values counting for (1) byte. It is
+!!       mandatory to increase the group size by the length of the
+!!       string in order not to overlap 'data regions'.
+subroutine define_adios_string_s (adios_group, name, path, length, group_size_inc)
+  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                          :: length
+  ! Local Variables
+  integer(kind=8)                  :: varid ! dummy variable, adios use var name
+
+  ! adios: 9 == string
+  call adios_define_var (adios_group, name, path, 9,  "", "", "", varid)
+  group_size_inc = group_size_inc + 1*length
+
+end subroutine define_adios_string_s
+
+!===============================================================================
+!> Define a local ADIOS array of doubles and autoincrement the adios
+!! group size by (8 * number of elements).
+!! \param adios_group The adios group where the variables belongs
+!! \param name The variable to be defined
+!! \param path The logical path structuring the data and containing
+!!             the variable
+!! \param dim The number of elements in the 1D array. Required to
+!!            correctly increment adios group size.
+!! \param dim_str The "stringified" version of dim. Needed by adios
+!!                to define variables
+!! \param group_size_inc The inout adios group size to increment
+!!                       with the size of the variable
+subroutine define_adios_double_local_array1D_s (adios_group, name, path, dim, dim_str, group_size_inc)
+  use adios_write_mod
+  implicit none
+  ! Arguments
+  integer(kind=8),  intent(in)     :: adios_group
+  character(len=*), intent(in)     :: name, path, dim_str
+  integer(kind=8),  intent(inout)  :: group_size_inc
+  integer, intent(in)              :: dim
+  ! 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, dim_str, "", "", varid)
+  group_size_inc = group_size_inc + 8*dim
+
+end subroutine define_adios_double_local_array1D_s
+
+!===============================================================================
+!> Define a local ADIOS array of integers and autoincrement the adios
+!! group size by (4 * number of elements).
+!! \param adios_group The adios group where the variables belongs
+!! \param name The variable to be defined
+!! \param path The logical path structuring the data and containing
+!!             the variable
+!! \param dim The number of elements in the 1D array. Required to
+!!            correctly increment adios group size.
+!! \param dim_str The "stringified" version of dim. Needed by adios
+!!                to define variables
+!! \param group_size_inc The inout adios group size to increment
+!!                       with the size of the variable
+subroutine define_adios_integer_local_array1D_s (adios_group, name, path, dim, dim_str, group_size_inc)
+  use adios_write_mod
+  implicit none
+  ! Arguments
+  integer(kind=8),  intent(in)     :: adios_group
+  character(len=*), intent(in)     :: name, path, dim_str
+  integer(kind=8),  intent(inout)  :: group_size_inc
+  integer, intent(in)              :: dim
+  ! Local Variables
+  integer(kind=8)                  :: varid ! dummy variable, adios use var name
+
+  ! adios: 2 == integer
+  call adios_define_var (adios_group, name, path, 2,  dim_str, "", "", varid)
+  group_size_inc = group_size_inc + 4*dim
+end subroutine define_adios_integer_local_array1D_s
+
+
 end subroutine write_specfem_header_adios



More information about the CIG-COMMITS mailing list