Index: trunk/LMDZ.MARS/changelog.txt
===================================================================
--- trunk/LMDZ.MARS/changelog.txt	(revision 3738)
+++ trunk/LMDZ.MARS/changelog.txt	(revision 3739)
@@ -4813,2 +4813,5 @@
 - When atmospheric water profile is monitored, ice value is not put to 0 anymore.
 - The user can now prescribe a specific atmospheric water profile with a file "profile_def_h2o_vap".
+
+== 26/04/2025 == EM
+Code tidying: put routines in modules, remove useless "return" statements, etc.
Index: trunk/LMDZ.MARS/libf/phymars/call_dayperi.F
===================================================================
--- trunk/LMDZ.MARS/libf/phymars/call_dayperi.F	(revision 3738)
+++ trunk/LMDZ.MARS/libf/phymars/call_dayperi.F	(revision 3739)
@@ -1,2 +1,8 @@
+      module call_dayperi_mod
+      
+      implicit none
+      
+      contains
+      
 c *******************************************************
       subroutine call_dayperi(Lsperi,e_elips,dayperi,year_day)
@@ -43,5 +49,6 @@
      &     -x2*sin(Lsperi)/(1+e_elips*cos(Lsperi)) )
        if (dayperi < 0) dayperi=dayperi+year_day
-       return
 
-       end
+       end subroutine call_dayperi
+       
+       end module call_dayperi_mod
Index: trunk/LMDZ.MARS/libf/phymars/co2condens_mod.F
===================================================================
--- trunk/LMDZ.MARS/libf/phymars/co2condens_mod.F	(revision 3738)
+++ trunk/LMDZ.MARS/libf/phymars/co2condens_mod.F	(revision 3739)
@@ -39,4 +39,5 @@
       USE paleoclimate_mod, ONLY: paleoclimate
       use callkeys_mod, only: caps, co2clouds
+      use co2snow_mod, only: co2snow
 
        IMPLICIT NONE
Index: trunk/LMDZ.MARS/libf/phymars/co2sat.F
===================================================================
--- trunk/LMDZ.MARS/libf/phymars/co2sat.F	(revision 3738)
+++ trunk/LMDZ.MARS/libf/phymars/co2sat.F	(revision 3739)
@@ -38,5 +38,4 @@
 c===== END
 c=======================================================================
-      RETURN
       END
 
Index: trunk/LMDZ.MARS/libf/phymars/co2snow.F
===================================================================
--- trunk/LMDZ.MARS/libf/phymars/co2snow.F	(revision 3738)
+++ trunk/LMDZ.MARS/libf/phymars/co2snow.F	(revision 3739)
@@ -1,2 +1,7 @@
+      MODULE co2snow_mod
+      
+      IMPLICIT NONE
+      
+      CONTAINS
 c=======================================================================
 c     Program for simulate the impact of the CO2 snow fall on
@@ -138,4 +143,5 @@
 c END
 c=======================================================================
-      return
-      end 
+      end subroutine co2snow
+
+      END MODULE co2snow_mod
Index: trunk/LMDZ.MARS/libf/phymars/drag_noro_mod.F90
===================================================================
--- trunk/LMDZ.MARS/libf/phymars/drag_noro_mod.F90	(revision 3738)
+++ trunk/LMDZ.MARS/libf/phymars/drag_noro_mod.F90	(revision 3739)
@@ -41,5 +41,5 @@
       REAL, intent(in):: pvar(ndomainsz)       		! sub-grid scale standard deviation
       REAL, intent(in):: psig(ndomainsz)		! sub-grid scale standard slope
-      REAL, intent(in):: pgam(ndomainsz)      		! sub-grid scale standard anisotropy
+      REAL, intent(inout):: pgam(ndomainsz)      	! sub-grid scale standard anisotropy
       REAL, intent(in):: pthe(ndomainsz)		! sub-grid scale principal axes angle
       REAL, intent(in):: u(ndomainsz,nlayer)		! Zonal wind at full levels(m/s)
Index: trunk/LMDZ.MARS/libf/phymars/dyn1d/init_testphys1d_mod.F90
===================================================================
--- trunk/LMDZ.MARS/libf/phymars/dyn1d/init_testphys1d_mod.F90	(revision 3738)
+++ trunk/LMDZ.MARS/libf/phymars/dyn1d/init_testphys1d_mod.F90	(revision 3739)
@@ -46,4 +46,5 @@
 use co2condens_mod,           only: CO2cond_ps
 use callkeys_mod, only: water, photochem, callthermos
+use call_dayperi_mod, only: call_dayperi
 ! Mostly for XIOS outputs:
 use mod_const_mpi,            only: COMM_LMDZ
Index: trunk/LMDZ.MARS/libf/phymars/improvedclouds_mod.F
===================================================================
--- trunk/LMDZ.MARS/libf/phymars/improvedclouds_mod.F	(revision 3738)
+++ trunk/LMDZ.MARS/libf/phymars/improvedclouds_mod.F	(revision 3739)
@@ -624,12 +624,5 @@
       
       ENDIF ! endif test_flag
-!!!!!!!!!!!!!! TESTS OUTPUTS TESTS OUTPUTS TESTS OUTPUTS TESTS OUTPUTS 
-!!!!!!!!!!!!!! TESTS OUTPUTS TESTS OUTPUTS TESTS OUTPUTS TESTS OUTPUTS 
-!!!!!!!!!!!!!! TESTS OUTPUTS TESTS OUTPUTS TESTS OUTPUTS TESTS OUTPUTS 
-
-      return
-
-      
-      
+
       
 cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc      
Index: trunk/LMDZ.MARS/libf/phymars/massflowrateco2.F90
===================================================================
--- trunk/LMDZ.MARS/libf/phymars/massflowrateco2.F90	(revision 3738)
+++ trunk/LMDZ.MARS/libf/phymars/massflowrateco2.F90	(revision 3739)
@@ -528,5 +528,4 @@
   visco = 0.0266958 * sqrt(M2*T) / ( sigma**2. * RGCS )  !!! microPa.s
 
-  return
 !======================================================================================================================!
 ! END =================================================================================================================!
Index: trunk/LMDZ.MARS/libf/phymars/orodrag_mod.F90
===================================================================
--- trunk/LMDZ.MARS/libf/phymars/orodrag_mod.F90	(revision 3738)
+++ trunk/LMDZ.MARS/libf/phymars/orodrag_mod.F90	(revision 3739)
@@ -39,4 +39,5 @@
       USE comcstfi_h, ONLY: g, cpp
       USE yoegwd_h, ONLY: gkwake
+      USE orosetup_mod, ONLY: orosetup
       
       implicit none
@@ -57,5 +58,5 @@
       REAL, intent(in):: pvar(ndomainsz)       ! Sub-grid scale standard deviation 
       REAL, intent(in):: psig(ndomainsz)       ! Sub-grid scale slope 
-      REAL, intent(in):: pgam(ndomainsz)       ! Sub-grid scale anisotropy
+      REAL, intent(inout):: pgam(ndomainsz)       ! Sub-grid scale anisotropy
       REAL, intent(in):: pthe(ndomainsz)       ! Sub-grid scale principal axes angle
       REAL, intent(in):: zgeom(ndomainsz,nlayer)     ! Geopotential height of full levels
Index: trunk/LMDZ.MARS/libf/phymars/orosetup.F90
===================================================================
--- trunk/LMDZ.MARS/libf/phymars/orosetup.F90	(revision 3738)
+++ trunk/LMDZ.MARS/libf/phymars/orosetup.F90	(revision 3739)
@@ -1,2 +1,8 @@
+MODULE orosetup_mod
+
+IMPLICIT NONE
+
+CONTAINS
+
 SUBROUTINE OROSETUP( ngrid, nlayer, ktest, pplev, pplay, pu, pv, pt, zgeom, &
             pvar,pthe, pgam,                                       &
@@ -113,10 +119,8 @@
 ! 1. INITIALIZATION
 !--------------------------------------------------------------------------------
-! 100  CONTINUE  ! continue tag without source, maybe need delete in future
 
       !* 1.1 COMPUTATIONAL CONSTANTS
       kidia=1
       kfdia=ngrid
-! 110  CONTINUE  ! continue tag without source, maybe need delete in future
       ILEVM1=nlayer-1
       ILEVM2=nlayer-2
@@ -129,5 +133,5 @@
 ! 2. Compute all the critical levels and the coeffecients of anisotropy
 !-----------------------------------------------------------------------------------------------------
-! 200  CONTINUE ! continue tag without source, maybe need delete in future
+
       ! 2.1 Define low level wind, project winds in plane of low level wind,
       ! determine sector in which to take the variance and set indicator for critical levels. 
@@ -209,5 +213,4 @@
       enddo      
 
-! 210  CONTINUE ! continue tag without source, maybe need delete in future
       ! Initialize various arrays for the following computes
       DO JL=kidia,kfdia
@@ -329,5 +332,4 @@
 
       ! 2.2 Brunt-vaisala frequency and density at half levels 
- 220  CONTINUE ! continue tag without source, maybe need delete in future
  
       DO JK=ilevh,nlayer
@@ -366,5 +368,4 @@
 
       ! 2.3 Mean flow richardson number and critical height for proude layer    
-! 230  CONTINUE ! continue tag without source, maybe need delete in future
 
       DO JK=2,nlayer
@@ -471,6 +472,5 @@
       end DO
 
-! 260  CONTINUE  ! continue tag without source, maybe need delete in future
-
-  RETURN
-END
+END SUBROUTINE OROSETUP
+
+END MODULE orosetup_mod
Index: trunk/LMDZ.MARS/libf/phymars/tcondwater.F90
===================================================================
--- trunk/LMDZ.MARS/libf/phymars/tcondwater.F90	(revision 3738)
+++ trunk/LMDZ.MARS/libf/phymars/tcondwater.F90	(revision 3739)
@@ -1,3 +1,9 @@
-SUBROUTINE tcondwater(nbpts,p,q,tcond)
+module tcondwater_mod
+
+implicit none
+
+contains
+
+subroutine tcondwater(ngrid,nlay,p,q,tcond)
 IMPLICIT NONE 
 
@@ -7,16 +13,16 @@
 !--------------------------------------------------i
 
-integer, intent(in) :: nbpts
-real, intent(in), dimension(nbpts):: p,q
-real, intent(out), dimension(nbpts):: tcond
+integer, intent(in) :: ngrid, nlay
+real, intent(in) :: p(ngrid,nlay) ! pressure (Pa)
+real, intent(in) :: q(ngrid,nlay) ! water mass mixing ratio (kg/kg_air)
+real, intent(out):: tcond(ngrid,nlay) ! condensation temeprature (K)
 
-real, dimension(nbpts):: res
 real:: x
-integer:: i
-
-do i=1,nbpts
+integer:: i,j
+do i=1,ngrid
+ do j=1,nlay
    !write(*,*) "i en cours", i, "sur nbpts=", nbpts
    !write(*,*) "q(i)",q(i),"p(i)",p(i)
-   x=alog10(MAX(q(i),1e-16)*p(i)/(100.*0.41)) ! max pour erreur q<=0
+   x=alog10(MAX(q(i,j),1e-16)*p(i,j)/(100.*0.41)) ! max pour erreur q<=0
    ! attention change le 0.41 de place le 10 juin 2014 car priorites
    ! fortran dans watersat.F
@@ -26,13 +32,13 @@
    !        + 2.12411064e-04*x**6+1.64642075e-05*x**7+9.22615632e-07*x**8
    !        + 3.18958825e-08*x**9+5.00656720e-10*x**10 degre 10: trop!
-   res(i) = 2.52846556e+02+ 2.39229653e+01*x+ 2.21333897e+00*x**2  &
+   tcond(i,j) = 2.52846556e+02+ 2.39229653e+01*x+ 2.21333897e+00*x**2  &
                 + 1.79977992e-01*x**3+ 1.00068175e-02*x**4+2.55145012e-04*x**5
    !write(*,*) "rex(x) tcondwater AP14! :) :) :) :P", res(i)
+ enddo
 enddo
 
-tcond=res
+end subroutine tcondwater
 
-return 
-end
+end module tcondwater_mod
 !polynome de degre 5 pas 0.0001
 !polynomial coefs [  2.52846556e+02   2.39229653e+01   2.21333897e+00
Index: trunk/LMDZ.MARS/libf/phymars/watercloud_mod.F
===================================================================
--- trunk/LMDZ.MARS/libf/phymars/watercloud_mod.F	(revision 3738)
+++ trunk/LMDZ.MARS/libf/phymars/watercloud_mod.F	(revision 3739)
@@ -20,4 +20,5 @@
       USE improvedclouds_mod, ONLY: improvedclouds
       USE watersat_mod, ONLY: watersat
+      USE tcondwater_mod, ONLY: tcondwater
       use tracer_mod, only: nqmx, igcm_h2o_vap, igcm_h2o_ice,
      &                      igcm_hdo_vap, igcm_hdo_ice,
@@ -244,5 +245,5 @@
          zqvap=zqclf(:,:,igcm_h2o_vap)
          zqice=zqclf(:,:,igcm_h2o_ice)
-         CALL tcondwater(ngrid*nlay,pplay,zqvap+zqice,tcond)
+         CALL tcondwater(ngrid,nlay,pplay,zqvap+zqice,tcond)
          DO l=1,nlay
            DO ig=1,ngrid
