From 84c2069410ca640df7664399046e4b70ac2649e2 Mon Sep 17 00:00:00 2001
From: Antoine Cyril David Hoffmann <ahoffman@spcpc606.epfl.ch>
Date: Mon, 14 Dec 2020 09:03:26 +0100
Subject: [PATCH] Added checkpoint saving rate as input parameter

---
 matlab/write_fort90.m       |  1 +
 src/diagnose.F90            | 10 +++++-----
 src/diagnostics_par_mod.F90 |  5 ++---
 wk/setup.m                  |  1 +
 4 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/matlab/write_fort90.m b/matlab/write_fort90.m
index 87fdab4b..f6d04f34 100644
--- a/matlab/write_fort90.m
+++ b/matlab/write_fort90.m
@@ -28,6 +28,7 @@ fprintf(fid,['  nsave_0d = ', num2str(OUTPUTS.nsave_0d),'\n']);
 fprintf(fid,['  nsave_1d = ', num2str(OUTPUTS.nsave_1d),'\n']);
 fprintf(fid,['  nsave_2d = ', num2str(OUTPUTS.nsave_2d),'\n']);
 fprintf(fid,['  nsave_5d = ', num2str(OUTPUTS.nsave_5d),'\n']);
+fprintf(fid,['  nsave_cp = ', num2str(OUTPUTS.nsave_cp),'\n']);
 fprintf(fid,['  write_Na00    = ', OUTPUTS.write_Na00,'\n']);
 fprintf(fid,['  write_moments = ', OUTPUTS.write_moments,'\n']);
 fprintf(fid,['  write_phi     = ', OUTPUTS.write_phi,'\n']);
diff --git a/src/diagnose.F90 b/src/diagnose.F90
index 47f83a16..073bd3c2 100644
--- a/src/diagnose.F90
+++ b/src/diagnose.F90
@@ -255,12 +255,12 @@ SUBROUTINE diagnose(kstep)
      END IF
 
      !                       2.5   Backups
-     nsave_cp = INT(5/dt)
-     IF (MOD(cstep, nsave_cp) == 0) THEN
-       CALL checkpoint_save(cp_counter)
-       cp_counter = cp_counter + 1
+     IF (nsave_cp .NE. 0) THEN
+       IF (MOD(cstep, nsave_cp) == 0) THEN
+         CALL checkpoint_save(cp_counter)
+         cp_counter = cp_counter + 1
+       ENDIF
      ENDIF
-
   !_____________________________________________________________________________
   !                   3.   Final diagnostics
 
diff --git a/src/diagnostics_par_mod.F90 b/src/diagnostics_par_mod.F90
index 30a6424b..5a6d168c 100644
--- a/src/diagnostics_par_mod.F90
+++ b/src/diagnostics_par_mod.F90
@@ -11,8 +11,7 @@ MODULE diagnostics_par
   LOGICAL, PUBLIC, PROTECTED :: write_non_lin=.TRUE.
   LOGICAL, PUBLIC, PROTECTED :: write_doubleprecision=.FALSE.
 
-  INTEGER, PUBLIC, PROTECTED :: nsave_0d , nsave_1d , nsave_2d , nsave_5d
-  INTEGER, PUBLIC :: nsave_cp = 1e4
+  INTEGER, PUBLIC, PROTECTED :: nsave_0d , nsave_1d , nsave_2d , nsave_5d, nsave_cp
 
   !  HDF5 file
   CHARACTER(len=256), PUBLIC :: resfile0 = "results"   ! Head of main result file name
@@ -35,7 +34,7 @@ CONTAINS
     USE prec_const
     IMPLICIT NONE
 
-    NAMELIST /OUTPUT_PAR/ nsave_0d , nsave_1d , nsave_2d , nsave_5d
+    NAMELIST /OUTPUT_PAR/ nsave_0d , nsave_1d , nsave_2d , nsave_5d, nsave_cp
     NAMELIST /OUTPUT_PAR/ write_Na00, write_moments, write_phi, write_non_lin, write_doubleprecision
     NAMELIST /OUTPUT_PAR/ resfile0, rstfile0, job2load
 
diff --git a/wk/setup.m b/wk/setup.m
index 6a2205ae..1d84c183 100644
--- a/wk/setup.m
+++ b/wk/setup.m
@@ -84,6 +84,7 @@ OUTPUTS.nsave_0d = floor(1.0/SPS0D/DT);
 OUTPUTS.nsave_1d = 0;
 OUTPUTS.nsave_2d = floor(1.0/SPS2D/DT);
 OUTPUTS.nsave_5d = floor(1.0/SPS5D/DT);
+OUTPUTS.nsave_cp = floor(1.0/SPSCP/DT);
 OUTPUTS.write_Na00    = '.true.';
 OUTPUTS.write_moments = '.true.';
 OUTPUTS.write_phi     = '.true.';
-- 
GitLab