From 416cc0a5ddbfcd17e44339b0bf6bd9fc73466c74 Mon Sep 17 00:00:00 2001
From: Grzegorz Kowal <grzegorz@amuncode.org>
Date: Fri, 18 Nov 2016 11:39:17 -0200
Subject: [PATCH] IO: Flush HDF5 files to disk before closing them.

Signed-off-by: Grzegorz Kowal <grzegorz@amuncode.org>
---
 src/io.F90 | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/src/io.F90 b/src/io.F90
index de269d1..4c5aa6b 100644
--- a/src/io.F90
+++ b/src/io.F90
@@ -860,8 +860,9 @@ module io
 !
     use error          , only : print_error
     use hdf5           , only : hid_t
-    use hdf5           , only : H5F_ACC_TRUNC_F
-    use hdf5           , only : h5open_f, h5close_f, h5fcreate_f, h5fclose_f
+    use hdf5           , only : H5F_ACC_TRUNC_F, H5F_SCOPE_GLOBAL_F
+    use hdf5           , only : h5open_f, h5close_f, h5fcreate_f, h5fflush_f   &
+                              , h5fclose_f
     use mpitools       , only : nproc
 
 ! local variables are not implicit by default
@@ -924,6 +925,10 @@ module io
 !
     call write_datablocks_h5(fid)
 
+! flush the file
+!
+    call h5fflush_f(fid, H5F_SCOPE_GLOBAL_F, err)
+
 ! close the file
 !
     call h5fclose_f(fid, err)
@@ -972,8 +977,9 @@ module io
 !
     use error          , only : print_error
     use hdf5           , only : hid_t
-    use hdf5           , only : H5F_ACC_TRUNC_F
-    use hdf5           , only : h5open_f, h5close_f, h5fcreate_f, h5fclose_f
+    use hdf5           , only : H5F_ACC_TRUNC_F, H5F_SCOPE_GLOBAL_F
+    use hdf5           , only : h5open_f, h5close_f, h5fcreate_f, h5fflush_f   &
+                              , h5fclose_f
     use mpitools       , only : nproc
 
 ! local variables are not implicit by default
@@ -1056,6 +1062,10 @@ module io
 
     end select
 
+! flush the file
+!
+    call h5fflush_f(fid, H5F_SCOPE_GLOBAL_F, err)
+
 ! close the file
 !
     call h5fclose_f(fid, err)