From b4b5e3650f9d568cc20cbed7b9c43a9165dc3a8c Mon Sep 17 00:00:00 2001
From: Thomas Dethinne <tdethinne@uliege.be>
Date: Thu, 7 Nov 2024 10:35:53 +0100
Subject: [PATCH] remove CAR code from iniglf

---
 couplage/MAR/call_caraib.f90 | 32 +++++++++++++++++++++++++++++++-
 couplage/MAR/iniglf.f90      | 36 ++++++++++++------------------------
 2 files changed, 43 insertions(+), 25 deletions(-)

diff --git a/couplage/MAR/call_caraib.f90 b/couplage/MAR/call_caraib.f90
index 0368fc4..039b11f 100644
--- a/couplage/MAR/call_caraib.f90
+++ b/couplage/MAR/call_caraib.f90
@@ -21,6 +21,7 @@
         use mardim
         use marcar
         use mar_ge
+        use mar_vb
 
         IMPLICIT NONE
   
@@ -93,9 +94,38 @@
     ! +--CASES called in iniglf.f90
     ! +  ==========================
     ! +
-        
+        ! check if a .nc exists
         CASE(10)
             INQUIRE(FILE="MARglf.nc", EXIST=file_exists)
+        
+        CASE(11)
+            if (file_exists) then
+                call CF_READ2D('MARglf.nc','LAI',1,mx,my,nvx,lai_caraib)
+                call CF_READ2D('MARglf.nc','GLF',1,mx,my,nvx,glf_caraib)
+            else
+                open(unit=11, status='old', form='unformatted', file='MARglf.DAT')
+                rewind 11
+            endif
+        ! Read th NESTOR file of CARAIB file dependinf on the coupling
+        CASE(12)
+            if (file_exists) then
+                glf2VB=glf_caraib
+                LAI2VB=lai_caraib
+
+                iyr_VB = iyrrGE
+                mma_VB = mmarGE
+                jda_VB = jdarGE
+                jhu_VB = jhurGE +1
+                
+            !!!!!!!!!!!!!!!!!!!
+                jdh_VB = 6 ! temps entre 2 forçage --> hard codé ici
+            !!!!!!!!!!!!!!!!!!!
+            else
+                read(11) iyr_VB, mma_VB, jda_VB, jhu_VB, jdh_VB
+                read(11) glf2VB
+       
+                read(11) LAI2VB
+            endif
 
         CASE DEFAULT
             write(6, *) "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
diff --git a/couplage/MAR/iniglf.f90 b/couplage/MAR/iniglf.f90
index 987d839..1c4c9d4 100644
--- a/couplage/MAR/iniglf.f90
+++ b/couplage/MAR/iniglf.f90
@@ -114,14 +114,12 @@ subroutine INIglf(ihamr_glf, nhamr_glf, newglfINI)
 
         if(jdh_VB == 0) jdh_VB = -1
 
-        if (.not. file_exists .or. .not. CARcoupling) then
-         open(unit=11, status='old', form='unformatted', file='MARglf.DAT')
-         rewind 11
+        ! Read th NESTOR file of CARAIB file dependinf on the coupling
+        if (CARcoupling .eq. .true.) then
+            call call_caraib(11)
         else
-
-            call CF_READ2D('MARglf.nc','LAI',1,mx,my,nvx,lai_caraib)
-            call CF_READ2D('MARglf.nc','GLF',1,mx,my,nvx,glf_caraib)
-   
+            open(unit=11, status='old', form='unformatted', file='MARglf.DAT')
+            rewind 11
         endif
 
 11      continue
@@ -153,24 +151,14 @@ subroutine INIglf(ihamr_glf, nhamr_glf, newglfINI)
         ! +  ----------------------------
         ! +
         !On lit les infos dans le fichier
-        if (.not. file_exists) then
-         read(11) iyr_VB, mma_VB, jda_VB, jhu_VB, jdh_VB
-         read(11) glf2VB
-
-         read(11) LAI2VB
-
-        else
-            glf2VB=glf_caraib
-            LAI2VB=lai_caraib
-
-            iyr_VB = iyrrGE
-            mma_VB = mmarGE
-            jda_VB = jdarGE
-            jhu_VB = jhurGE +1
+        if (CARcoupling .eq. .true.) then
+            call call_caraib(12)
             
-        !!!!!!!!!!!!!!!!!!!
-            jdh_VB = 6 ! temps entre 2 forçage --> hard codé ici
-        !!!!!!!!!!!!!!!!!!!
+        else
+            read(11) iyr_VB, mma_VB, jda_VB, jhu_VB, jdh_VB
+            read(11) glf2VB
+   
+            read(11) LAI2VB
 
         endif
         ! +
-- 
GitLab