From 46ffe31f03318cebd461999e118b66067cb66046 Mon Sep 17 00:00:00 2001
From: dave <dave@dtu.dk>
Date: Mon, 10 Oct 2016 16:58:11 +0200
Subject: [PATCH] prepost.MannTurb64: exe on scratch dir, remove _ 64bit
 creator adds

---
 wetb/prepost/Simulations.py                   | 23 +++++++++++++++----
 wetb/prepost/prepost.py                       |  1 +
 .../demo_dlc/ref/pbs_in_turb/turb_s100_10ms.p |  7 +++++-
 .../demo_dlc/ref/pbs_in_turb/turb_s101_11ms.p |  7 +++++-
 4 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/wetb/prepost/Simulations.py b/wetb/prepost/Simulations.py
index f3690dcf..427e89f4 100755
--- a/wetb/prepost/Simulations.py
+++ b/wetb/prepost/Simulations.py
@@ -5275,7 +5275,7 @@ class MannTurb64(prepost.PBSScript):
 
     Following tags have to be defined:
         * [tu_model]
-        * [Turb base name]
+        * [turb_base_name]
         * [MannAlfaEpsilon]
         * [MannL]
         * [MannGamma]
@@ -5321,10 +5321,10 @@ class MannTurb64(prepost.PBSScript):
             # only relevant for cases with turbulence
             if '[tu_model]' in case and int(case['[tu_model]']) == 0:
                 continue
-            if '[Turb base name]' not in case:
+            if '[turb_base_name]' not in case:
                 continue
 
-            base_name = case['[Turb base name]']
+            base_name = case['[turb_base_name]']
             # pbs_in/out dir can contain subdirs, only take the inner directory
             out_base = misc.path_split_dirs(case['[pbs_out_dir]'])[0]
             turb = case['[turb_dir]']
@@ -5333,11 +5333,24 @@ class MannTurb64(prepost.PBSScript):
             self.path_pbs_o = os.path.join(out_base, turb, base_name + '.out')
             self.path_pbs_i = os.path.join(self.pbs_in_dir, base_name + '.p')
 
+            # apply winefix
             self.prelude = self.winefix
+            # browse to scratch dir
+            self.prelude += 'cd {}\n'.format(self.scratchdir)
+
+            self.coda = '# COPY BACK FROM SCRATCH AND RENAME, remove _ at end\n'
+            # copy back to turb dir at the end
             if case['[turb_db_dir]'] is not None:
-                self.prelude += 'cd %s' % case['[turb_db_dir]']
+                dst = os.path.join('$PBS_O_WORKDIR', case['[turb_db_dir]'],
+                                   base_name)
             else:
-                self.prelude += 'cd %s' % case['[turb_dir]']
+                dst = os.path.join('$PBS_O_WORKDIR', case['[turb_dir]'],
+                                   base_name)
+            # FIXME: Mann64 turb exe creator adds an underscore to output
+            for comp in list('uvw'):
+                src = '{}_{}.bin'.format(base_name, comp)
+                dst2 = '{}{}.bin'.format(dst, comp)
+                self.coda += 'cp {} {}\n'.format(src, dst2)
 
             # alfaeps, L, gamma, seed, nr_u, nr_v, nr_w, du, dv, dw high_freq_comp
             rpl = (float(case['[MannAlfaEpsilon]']),
diff --git a/wetb/prepost/prepost.py b/wetb/prepost/prepost.py
index c706aa79..2bc93cb5 100644
--- a/wetb/prepost/prepost.py
+++ b/wetb/prepost/prepost.py
@@ -97,6 +97,7 @@ exit
         self.prelude = ''
         self.execution = ''
         self.coda = ''
+        self.scratchdir = '/scratch/$USER/$PBS_JOBID/'
 
     def check_dirs(self):
         """Create the directories of std out, std error and pbs file if they
diff --git a/wetb/prepost/tests/data/demo_dlc/ref/pbs_in_turb/turb_s100_10ms.p b/wetb/prepost/tests/data/demo_dlc/ref/pbs_in_turb/turb_s100_10ms.p
index 92897be0..79b15e56 100644
--- a/wetb/prepost/tests/data/demo_dlc/ref/pbs_in_turb/turb_s100_10ms.p
+++ b/wetb/prepost/tests/data/demo_dlc/ref/pbs_in_turb/turb_s100_10ms.p
@@ -27,7 +27,8 @@ echo "PRELUDE"
 echo "------------------------------------------------------------------------"
 
 winefix
-cd ../turb/
+cd /scratch/$USER/$PBS_JOBID/
+
 
 echo ""
 echo "------------------------------------------------------------------------"
@@ -43,6 +44,10 @@ echo "------------------------------------------------------------------------"
 echo "CODA"
 echo "------------------------------------------------------------------------"
 
+# COPY BACK FROM SCRATCH AND RENAME, remove _ at end
+cp turb_s100_10ms_u.bin $PBS_O_WORKDIR/../turb/turb_s100_10msu.bin
+cp turb_s100_10ms_v.bin $PBS_O_WORKDIR/../turb/turb_s100_10msv.bin
+cp turb_s100_10ms_w.bin $PBS_O_WORKDIR/../turb/turb_s100_10msw.bin
 
 
 echo ""
diff --git a/wetb/prepost/tests/data/demo_dlc/ref/pbs_in_turb/turb_s101_11ms.p b/wetb/prepost/tests/data/demo_dlc/ref/pbs_in_turb/turb_s101_11ms.p
index 05f0d068..7997dc29 100644
--- a/wetb/prepost/tests/data/demo_dlc/ref/pbs_in_turb/turb_s101_11ms.p
+++ b/wetb/prepost/tests/data/demo_dlc/ref/pbs_in_turb/turb_s101_11ms.p
@@ -27,7 +27,8 @@ echo "PRELUDE"
 echo "------------------------------------------------------------------------"
 
 winefix
-cd ../turb/
+cd /scratch/$USER/$PBS_JOBID/
+
 
 echo ""
 echo "------------------------------------------------------------------------"
@@ -43,6 +44,10 @@ echo "------------------------------------------------------------------------"
 echo "CODA"
 echo "------------------------------------------------------------------------"
 
+# COPY BACK FROM SCRATCH AND RENAME, remove _ at end
+cp turb_s101_11ms_u.bin $PBS_O_WORKDIR/../turb/turb_s101_11msu.bin
+cp turb_s101_11ms_v.bin $PBS_O_WORKDIR/../turb/turb_s101_11msv.bin
+cp turb_s101_11ms_w.bin $PBS_O_WORKDIR/../turb/turb_s101_11msw.bin
 
 
 echo ""
-- 
GitLab