From c8473b72241a07bc4b507050f81ca056067f2e00 Mon Sep 17 00:00:00 2001
From: Matthias Schmiddunser <matthias.schmiddunser@uni-tuebingen.de>
Date: Wed, 3 Dec 2014 13:09:47 +0100
Subject: [PATCH] Reducing Output - saving files periodically

Changing write_global_output so that the current output file is always kept
temporarily and deleted after the next output file was written. When
time = n*savstep+savoffset the files are kept permanently.
---
 src/module_definitions.f90  |  2 ++
 src/read_input_file.f90     |  8 ++++++++
 src/write_global_output.f90 | 17 ++++++++++++++---
 test/input_schmiddu.txt     | 14 ++++++++++++++
 4 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/src/module_definitions.f90 b/src/module_definitions.f90
index 403757a5..0314e1c5 100644
--- a/src/module_definitions.f90
+++ b/src/module_definitions.f90
@@ -263,6 +263,8 @@ module definitions
       integer levelcut
       integer levelapprox
       integer nstep
+      integer savstep
+      integer savoffset
       integer nstep_spinup
       integer noctreemax
       integer levelmax_oct
diff --git a/src/read_input_file.f90 b/src/read_input_file.f90
index 1746cc18..04e504ed 100644
--- a/src/read_input_file.f90
+++ b/src/read_input_file.f90
@@ -162,6 +162,14 @@ params%nstep_spinup=0
 if (iproc==0) call scanfile (params%infile,'nstep_spinup',params%nstep_spinup,ires)
 call mpi_bcast(params%nstep_spinup,1,mpi_integer,0,mpi_comm_world,ierr)
 
+params%savstep=1
+if (iproc==0) call scanfile (params%infile,'savstep',params%savstep,ires)
+call mpi_bcast(params%savstep,1,mpi_integer,0,mpi_comm_world,ierr)
+
+params%savoffset=0
+if (iproc==0) call scanfile (params%infile,'savoffset',params%savoffset,ires)
+call mpi_bcast(params%savoffset,1,mpi_integer,0,mpi_comm_world,ierr)
+
 !=====[material properties]====================================================
 
 material0=0
diff --git a/src/write_global_output.f90 b/src/write_global_output.f90
index 112cdc1f..a6872b82 100644
--- a/src/write_global_output.f90
+++ b/src/write_global_output.f90
@@ -67,9 +67,9 @@ character*5 outputtype
 !(((((((((((((((( declaration of the subroutine internal variables )))))))))))))
 !------------------------------------------------------------------------------|
 
-integer i,j,is,k,err,size_str(2)
-integer iproc,nproc,ierr
-character*4 cistep,citer
+integer i,j,is,k,err,size_str(2),stat
+integer iproc,nproc,ierr,prevstep
+character*4 cistep,citer,cprevstep
 character(len=5) :: outdir
 
 !------------------------------------------------------------------------------|
@@ -235,6 +235,17 @@ if (iproc.eq.0) then
 
    close (9)
 
+   !delete file from previous timestep if not marked for permanent save
+   !mschmiddunser 12.14
+   if (outputtype=='final') then
+     prevstep = istep-1
+       if (prevstep < params%savoffset .AND. prevstep >=0 .OR. &
+         prevstep >= params%savoffset .AND. (.NOT. mod(prevstep-params%savoffset,params%savstep)==0)) then
+           call int_to_char (cprevstep,4,prevstep)
+           open (91,file=trim(outdir)//'/time_'//cprevstep//'.bin',iostat=stat,status='old',form='unformatted')
+           if (stat.eq.0) close(91, status='delete')
+       end if
+   end if
 end if
 
 return
diff --git a/test/input_schmiddu.txt b/test/input_schmiddu.txt
index ed959a80..ebb65f58 100644
--- a/test/input_schmiddu.txt
+++ b/test/input_schmiddu.txt
@@ -46,6 +46,20 @@ produce the DoRuRes. DoRuRe stands for 'Douar Run Report'.
       compute_qpgram = F
 
 
+SAVING
+_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
+The current output file is always kept temporarily and deleted after the next
+output file was written. When time equals n*savstep + savoffset the files are
+kept permanently.
+
+[int] savoffset is the timestep from which on output will be saved
+
+      savoffset = 1
+
+[int] every savstep'th value after savoffset will be saved
+
+      savstep = 2
+
 RESTART
 _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
 
-- 
GitLab