From 20533bf15b0f45b292c7de07a3c4e68b555f566e Mon Sep 17 00:00:00 2001
From: Anthony <anthony.schrapffer@polytechnique.fr>
Date: Fri, 24 Apr 2020 13:45:31 +0200
Subject: [PATCH] Light corrections

---
 F90subroutines/routing_reg.f90            |  4 ++++
 RPPtools.py                               | 14 +++++++++-----
 tests/Iberia_n48/BuildHTUs_IP.pbs         |  2 +-
 tests/Iberia_n48_regular/BuildHTUs_IP.pbs |  2 +-
 4 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/F90subroutines/routing_reg.f90 b/F90subroutines/routing_reg.f90
index f38a21f..2ed9fc4 100644
--- a/F90subroutines/routing_reg.f90
+++ b/F90subroutines/routing_reg.f90
@@ -2707,6 +2707,10 @@ SUBROUTINE routing_reg_end_truncate(nbpt, nbasmax, gridarea, contfrac, nwbas, nu
     !
     DO ib=1,nbpt
        DO ij=1,basin_count(ib)
+          ! Flowing out of the grid
+          IF ( route_togrid_glo(ib,ij) .EQ. 0 ) THEN
+             route_tobasin_glo(ib,ij) = nbasmax + 2
+             route_togrid_glo(ib,ij) = ib
           ! River flows
           IF ( route_togrid_glo(ib,ij) .EQ. -1 ) THEN
              route_tobasin_glo(ib,ij) = nbasmax + 2
diff --git a/RPPtools.py b/RPPtools.py
index 04c7e3c..63ff806 100644
--- a/RPPtools.py
+++ b/RPPtools.py
@@ -192,6 +192,7 @@ class compweights :
         self.area = []
         self.lon = []
         self.lat = []
+        self.hpts = []
         #
         innf=Dataset(weightfile, 'r')
         #
@@ -205,6 +206,7 @@ class compweights :
             self.area.append(innf.variables["hydro_area"][0:maxhpts,i])
             self.lon.append(innf.variables["hydro_lon"][0:maxhpts,i])
             self.lat.append(innf.variables["hydro_lat"][0:maxhpts,i])
+            self.hpts.append(maxhpts)
         #
         innf.close()
         # Find the indicis of the points on the HydroGrid using the coordinates.
@@ -371,15 +373,17 @@ class compweights :
         mxval,nbp=landind.shape
         for ib in range(nbp) :
             if ~np.isnan(landind[0,ib]) :
+                maxhpts = len(hlon[:,ib])
                 j,i=landind[:,ib]
                 self.mask[j,i] = 1.0
                 self.proc[j,i] = ib
                 self.gindex[0,nib] = j
                 self.gindex[1,nib] = i
-                self.hindex[0,:,nib] = hindj[:,ib]
-                self.hindex[1,:,nib] = hindi[:,ib]
-                self.hlon[:,nib] = hlon[:,ib]
-                self.hlat[:,nib] = hlat[:,ib]
-                self.harea[:,nib] = harea[:,ib]
+                self.hindex[0,:maxhpts,nib] = np.reshape(hindj[:,ib],self.hindex[0,:maxhpts,nib].shape)
+                self.hindex[1,:maxhpts,nib] = np.reshape(hindi[:,ib],self.hindex[1,:maxhpts,nib].shape)
+                self.hlon[:maxhpts,nib] = hlon[:,ib]
+                self.hlat[:maxhpts,nib] = hlat[:,ib]
+                self.harea[:maxhpts,nib] = harea[:,ib]
+
                 nib = nib+1
         return nib
diff --git a/tests/Iberia_n48/BuildHTUs_IP.pbs b/tests/Iberia_n48/BuildHTUs_IP.pbs
index b8e5683..11dbcdd 100644
--- a/tests/Iberia_n48/BuildHTUs_IP.pbs
+++ b/tests/Iberia_n48/BuildHTUs_IP.pbs
@@ -17,7 +17,7 @@ source ../../Environment
 #
 # Clean-up. Weights are kept for future runs.
 #
-/bin/rm -f DocumentationInterface *.nc *.txt
+/bin/rm -f DocumentationInterface *graph.nc *.txt
 #
 # Run the Python code to generate the HTUs and write them into a netCDF file.
 #
diff --git a/tests/Iberia_n48_regular/BuildHTUs_IP.pbs b/tests/Iberia_n48_regular/BuildHTUs_IP.pbs
index 5b84498..8e9e843 100644
--- a/tests/Iberia_n48_regular/BuildHTUs_IP.pbs
+++ b/tests/Iberia_n48_regular/BuildHTUs_IP.pbs
@@ -17,7 +17,7 @@ source ../../Environment
 #
 # Clean-up. Weights are kept for future runs.
 #
-/bin/rm -f DocumentationInterface *.nc *.txt
+/bin/rm -f DocumentationInterface *graph.nc *.txt
 #
 # Run the Python code to generate the HTUs and write them into a netCDF file.
 #
-- 
GitLab