From 8341942c5a55cd132e24921e4e40d7f80f07c876 Mon Sep 17 00:00:00 2001
From: thopri <thopri@noc.ac.uk>
Date: Fri, 27 Mar 2020 12:02:27 +0000
Subject: [PATCH] added try except block to provide useful error for time
 counter discprency

---
 inputs/namelist_remote.bdy  |  2 +-
 pynemo/nemo_bdy_extr_tm3.py | 14 +++++++++++---
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/inputs/namelist_remote.bdy b/inputs/namelist_remote.bdy
index bb2a1a7..9eeb1b6 100644
--- a/inputs/namelist_remote.bdy
+++ b/inputs/namelist_remote.bdy
@@ -56,7 +56,7 @@
     ln_mask_file   = .false.              !  =T : read mask from file
     cn_mask_file   = 'mask.nc'            !  name of mask file 
                                           !  (if ln_mask_file=.TRUE.)
-    ln_dyn2d       = .true.              !  boundary conditions for
+    ln_dyn2d       = .false.              !  boundary conditions for
                                           !  barotropic fields
     ln_dyn3d       = .false.              !  boundary conditions for 
                                           !  baroclinic velocities
diff --git a/pynemo/nemo_bdy_extr_tm3.py b/pynemo/nemo_bdy_extr_tm3.py
index 584ff48..9693c19 100644
--- a/pynemo/nemo_bdy_extr_tm3.py
+++ b/pynemo/nemo_bdy_extr_tm3.py
@@ -844,14 +844,22 @@ class Extract:
             for v in self.var_nam:    
                 intfn = interp1d(time_counter, self.d_bdy[v][year]['data'][:,:,:], axis=0,
                                                                  bounds_error=True)
-                self.d_bdy[v][year]['data'] = intfn(np.arange(time_000, time_end, 86400))
+                try:
+                    self.d_bdy[v][year]['data'] = intfn(np.arange(time_000, time_end, 86400))
+                except ValueError as e:
+                    logging.error('Value error in time_counter, does time horizon in data and bdy file match?')
+                    raise ValueError('Value error in time_counter, does time horizon in data and bdy file match?') from e
         else:
             for v in self.var_nam: 
                 for t in range(dstep):
                     intfn = interp1d(time_counter[t::dstep], 
                        self.d_bdy[v].data[t::dstep,:,:], axis=0, bounds_error=True)
-                    self.d_bdy[v].data[t::dstep,:,:] = intfn(np.arange(time_000, 
-                                                                  time_end, 86400)) 
+                    try:
+                        self.d_bdy[v].data[t::dstep, :, :] = intfn(np.arange(time_000,time_end, 86400))
+                    except ValueError as e:
+                        logging.error('Value error in time_counter, does time horizon in data and bdy file match?')
+                        raise ValueError('Value error in time_counter, does time horizon in data and bdy file match?') from e
+
         self.time_counter = time_counter
     
     def write_out(self, year, month, ind, unit_origin):
-- 
GitLab