From 8afa485da5dce4a737d503f384c78fd78d614b3f Mon Sep 17 00:00:00 2001
From: JJDHooghiem <joramjd@gmail.com>
Date: Fri, 25 Feb 2022 14:31:49 +0100
Subject: [PATCH] minor changes for finer control over cycle window and
 platform

---
 da/cyclecontrol/initexit_cteco2.py                |  4 ++++
 da/obsoperators/observationoperator_tm5_cteco2.py | 13 ++++++++++---
 da/platform/snellius.py                           |  6 ++++--
 da/tools/general.py                               |  3 ++-
 4 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/da/cyclecontrol/initexit_cteco2.py b/da/cyclecontrol/initexit_cteco2.py
index 19081fa4..85a2d5a0 100755
--- a/da/cyclecontrol/initexit_cteco2.py
+++ b/da/cyclecontrol/initexit_cteco2.py
@@ -187,6 +187,10 @@ class CycleControl(dict):
 
         if cyclelength == 'infinite':
             enddate = finaldate
+        elif cyclelength == 'year': 
+            enddate = advance_time(startdate, 'year')
+        elif cyclelength == 'month': 
+            enddate = advance_time(startdate, 'month')
         else:
             enddate = advance_time(startdate, cyclelength)
 
diff --git a/da/obsoperators/observationoperator_tm5_cteco2.py b/da/obsoperators/observationoperator_tm5_cteco2.py
index c3fc66d3..b4386dfe 100755
--- a/da/obsoperators/observationoperator_tm5_cteco2.py
+++ b/da/obsoperators/observationoperator_tm5_cteco2.py
@@ -108,9 +108,11 @@ class TM5ObservationOperator(ObservationOperator):
                 # and change items for transition from 25 to 34 layers for od meteo in dec 2005
                 if 'my.source.proj' in list(self.tm_settings.keys()):
                     newitems = {'my.basedir' : self.dacycle['dir.exec'],
+                                'my.project.dir' : os.path.join(self.dacycle['dir.exec'],self.tm_settings['my.basename']),
+                                'my.run.dir' : os.path.join(self.dacycle['dir.exec'],self.tm_settings['my.basename'],'rundir'),
                                 'istart' : self.transitionvalue,
-                                 'my.source.proj' : newdirs,
-                                 'build.copy.dirs' : newdirs}
+                                'my.source.proj' : newdirs,
+                                'build.copy.dirs' : newdirs}
                 else:
                     newitems = {'my.basedir' : self.dacycle['dir.exec'],
                                 'istart' : self.transitionvalue,
@@ -132,7 +134,12 @@ class TM5ObservationOperator(ObservationOperator):
             else:        
                 logging.info('First time step, setting up and compiling the TM5 model before proceeding!')
                 # Modify the rc-file to reflect directory structure defined by CTDAS
-                newitems = {'my.basedir': self.dacycle['dir.exec']}
+                if 'my.source.proj' in list(self.tm_settings.keys()):
+                    newitems = { 'my.project.dir' : os.path.join(self.dacycle['dir.exec'],self.tm_settings['my.basename']) } 
+                    create_dirs(newitems['my.project.dir'])  # WP Create folder before replacing in rc-file, otherwise folder is not recognized and replaced in keys
+                else:
+                    newitems = {'my.basedir': self.dacycle['dir.exec']}
+
 
             self.modify_rc(newitems)
             self.modify_rc(newitemsmeteo)
diff --git a/da/platform/snellius.py b/da/platform/snellius.py
index 4ef04249..c05dfb95 100644
--- a/da/platform/snellius.py
+++ b/da/platform/snellius.py
@@ -100,8 +100,10 @@ class SnelliusPlatform(Platform):
                    """#SBATCH -n jobnodes \n""" + \
                    """#SBATCH -t jobtime \n""" + \
                    """#SBATCH -o joblog \n""" + \
-                   """module load ctdas2022 \n""" + \
-           """\n"""
+                   """#SBATCH --mem 64G \n""" + \
+                   """module load NCO/5.0.1-foss-2021a \n""" + \
+                   """module load tm5mpgompi \n""" + \
+                   """\n"""
 
         if 'depends' in joboptions:
             template += """#$ -hold_jid depends \n"""
diff --git a/da/tools/general.py b/da/tools/general.py
index c451a008..e43e519c 100755
--- a/da/tools/general.py
+++ b/da/tools/general.py
@@ -101,6 +101,8 @@ def advance_time(time_in, interval):
             time_out = datetime.datetime(time_in.year, time_in.month + 1, 1, time_in.hour, 0, 0)
         else: 
             time_out = datetime.datetime(time_in.year + 1, 1, 1, time_in.hour, 0, 0)  # end of year provision
+    elif interval == 'year':                       # if yearly will run until next year 
+        time_out = datetime.datetime(time_in.year+1, time_in.month, time_in.day, time_in.hour, 0, 0)
     elif interval == 'week':
         time_out = time_in + datetime.timedelta(days=7)
     elif isinstance(interval, datetime.timedelta):
@@ -111,7 +113,6 @@ def advance_time(time_in, interval):
     return time_out
 
 
-
 def to_datetime(datestring, fmt=None):
     """ convert a date string to a datetime object """
   
-- 
GitLab