Index: /trunk/LMDZ.TITAN/libf/phytitan/callcorrk.F90
===================================================================
--- /trunk/LMDZ.TITAN/libf/phytitan/callcorrk.F90	(revision 1821)
+++ /trunk/LMDZ.TITAN/libf/phytitan/callcorrk.F90	(revision 1822)
@@ -6,13 +6,12 @@
           fluxabs_sw,fluxtop_dn,                               &
           OLR_nu,OSR_nu,                                       &
-          firstcall,lastcall)
+          lastcall)
 
       use mod_phys_lmdz_para, only : is_master
       use radinc_h
       use radcommon_h
-      use datafile_mod, only: datadir
-      use ioipsl_getin_p_mod, only: getin_p
       use gases_h
       USE tracer_h
+      use callkeys_mod, only: global1d, szangle
       use comcstfi_mod, only: pi, mugaz, cpp
       use callkeys_mod, only: diurnal,tracer,        &
@@ -58,5 +57,4 @@
       REAL,INTENT(IN) :: fract(ngrid)              ! Fraction of day.
       REAL,INTENT(IN) :: dist_star                 ! Distance star-planet (AU).
-      logical,intent(in) :: firstcall              ! Signals first call to physics.
       logical,intent(in) :: lastcall               ! Signals last call to physics.
       
@@ -107,15 +105,6 @@
       INTEGER ig,l,k,nw
 
-      real szangle
-      logical global1d
-      save szangle,global1d
-!$OMP THREADPRIVATE(szangle,global1d)
       real*8 taugsurf(L_NSPECTV,L_NGAUSS-1)
       real*8 taugsurfi(L_NSPECTI,L_NGAUSS-1)
-
-
-      ! Miscellaneous :
-      character(len=10) :: tmp1
-      character(len=10) :: tmp2
 
       logical OLRz
@@ -127,58 +116,6 @@
 
 
-!===============================================================
-!           I.a Initialization on first call
-!===============================================================
-
-
-      if(firstcall) then
-
-         call system('rm -f surf_vals_long.out')
-
-!--------------------------------------------------
-!             Set up correlated k
-!--------------------------------------------------
-
-
-         print*, "callcorrk: Correlated-k data base folder:",trim(datadir)
-         call getin_p("corrkdir",corrkdir)
-         print*, "corrkdir = ",corrkdir
-         write( tmp1, '(i3)' ) L_NSPECTI
-         write( tmp2, '(i3)' ) L_NSPECTV
-         banddir=trim(adjustl(tmp1))//'x'//trim(adjustl(tmp2))
-         banddir=trim(adjustl(corrkdir))//'/'//trim(adjustl(banddir))
-
-         call setspi            ! Basic infrared properties.
-         call setspv            ! Basic visible properties.
-         call sugas_corrk       ! Set up gaseous absorption properties.
-
-         OLR_nu(:,:) = 0.
-         OSR_nu(:,:) = 0.
-
-         if (ngrid.eq.1) then
-            PRINT*, 'Simulate global averaged conditions ?'
-            global1d = .false. ! default value
-            call getin_p("global1d",global1d)
-            write(*,*) "global1d = ",global1d
-            
-            ! Test of incompatibility : if global1d is true, there should not be any diurnal cycle.
-            if (global1d.and.diurnal) then
-               print*,'if global1d is true, diurnal must be set to false'
-               stop
-            endif
-
-            if (global1d) then
-               PRINT *,'Solar Zenith angle (deg.) ?'
-               PRINT *,'(assumed for averaged solar flux S/4)'
-               szangle=60.0  ! default value
-               call getin_p("szangle",szangle)
-               write(*,*) "szangle = ",szangle
-            endif
-         endif
-
-      end if ! of if (firstcall)
-
-!=======================================================================
-!          I.b  Initialization on every call   
+!=======================================================================
+!             I.  Initialization on every call   
 !=======================================================================
  
@@ -361,6 +298,6 @@
             endif
             
-            call optcv(dtauv,tauv,taucumv,plevrad,                 &
-                 wbarv,cosbv,tauray,tmid,pmid,taugsurf)
+            call optcv(pq,plevrad,tmid,pmid,                       &
+                 dtauv,tauv,taucumv,wbarv,cosbv,tauray,taugsurf)
 
             call sfluxv(dtauv,tauv,taucumv,albv,dwnv,wbarv,cosbv,  &
@@ -403,6 +340,6 @@
 !-----------------------------------------------------------------------
 
-         call optci(plevrad,tlevrad,dtaui,taucumi,                  &
-              cosbi,wbari,tmid,pmid,taugsurfi)
+         call optci(pq,plevrad,tlevrad,tmid,pmid,                   &
+              dtaui,taucumi,cosbi,wbari,taugsurfi)
 
          call sfluxi(plevrad,tlevrad,dtaui,taucumi,ubari,albi,      &
Index: /trunk/LMDZ.TITAN/libf/phytitan/callkeys_mod.F90
===================================================================
--- /trunk/LMDZ.TITAN/libf/phytitan/callkeys_mod.F90	(revision 1821)
+++ /trunk/LMDZ.TITAN/libf/phytitan/callkeys_mod.F90	(revision 1822)
@@ -14,8 +14,8 @@
       logical,save :: strictboundcorrk                                     
 !$OMP THREADPRIVATE(strictboundcorrk)
-
       logical,save :: callchim, callmufi, callclouds
 !$OMP THREADPRIVATE(callchim,callmufi,callclouds)
-
+      logical,save :: global1d
+!$OMP THREADPRIVATE(global1d)
       logical,save :: enertest
       logical,save :: nonideal
@@ -40,5 +40,4 @@
       integer,save :: ichim
 !$OMP THREADPRIVATE(ichim)
-
       integer,save :: iddist
       integer,save :: iradia
@@ -51,4 +50,6 @@
 !$OMP THREADPRIVATE(df_mufi, rm_mufi, rho_aer_mufi,p_prod,tx_prod,rc_prod,air_rad)
 
+      real,save :: szangle
+!$OMP THREADPRIVATE(szangle)
       real,save :: Fat1AU
       real,save :: stelTbb
Index: /trunk/LMDZ.TITAN/libf/phytitan/datafile_mod.F90
===================================================================
--- /trunk/LMDZ.TITAN/libf/phytitan/datafile_mod.F90	(revision 1821)
+++ /trunk/LMDZ.TITAN/libf/phytitan/datafile_mod.F90	(revision 1822)
@@ -14,6 +14,14 @@
       character(len=12),parameter :: surfdir="surface_data"
       
+      ! Default directories for correlated-k data
+      ! Set in inifis_mod
+      character(LEN=100),save :: corrkdir = 'datagcm/corrk_data/50X50'
+      character(LEN=100),save :: banddir  = 'datagcm/corrk_data/50X50/50x50'
+!$OMP THREADPRIVATE(corrkdir,banddir)
+      
       ! Default directory for microphysics
-      character(LEN=300),save :: config_mufi ='datagcm/microphysics/config.cfg'
+      ! Set in inifis_mod
+      character(LEN=100),save :: config_mufi ='datagcm/microphysics/config.cfg'
+!$OMP THREADPRIVATE(config_mufi)
 
       end module datafile_mod
Index: /trunk/LMDZ.TITAN/libf/phytitan/inifis_mod.F90
===================================================================
--- /trunk/LMDZ.TITAN/libf/phytitan/inifis_mod.F90	(revision 1821)
+++ /trunk/LMDZ.TITAN/libf/phytitan/inifis_mod.F90	(revision 1822)
@@ -10,5 +10,5 @@
 
   use radinc_h, only: ini_radinc_h
-  use datafile_mod, only: datadir,config_mufi
+  use datafile_mod
   use comdiurn_h, only: sinlat, coslat, sinlon, coslon
   use comgeomfi_h, only: totarea, totarea_planet
@@ -220,4 +220,32 @@
      call getin_p("corrk",corrk)
      write(*,*) " corrk = ",corrk
+     
+     if (corrk) then
+       ! default path is set in datadir
+       write(*,*) "callcorrk: Correlated-k data base folder:",trim(datadir)
+       call getin_p("corrkdir",corrkdir)
+       write(*,*) " corrkdir = ",corrkdir
+     endif
+     
+     if (corrk .and. ngrid.eq.1) then
+       write(*,*) "simulate global averaged conditions ?"
+       global1d = .false. ! default value
+       call getin_p("global1d",global1d)
+       write(*,*) " global1d = ",global1d
+       
+       ! Test of incompatibility : if global1d is true, there should not be any diurnal cycle.
+       if (global1d.and.diurnal) then
+          write(*,*) "if global1d is true, diurnal must be set to false"
+          stop
+       endif
+
+       if (global1d) then
+          write(*,*) "Solar Zenith angle (deg.) ?"
+          write(*,*) "(assumed for averaged solar flux S/4)"
+          szangle=60.0  ! default value
+          call getin_p("szangle",szangle)
+          write(*,*) " szangle = ",szangle
+       endif
+     endif
 
      write(*,*) "prohibit calculations outside corrk T grid?"
@@ -349,32 +377,40 @@
      df_mufi=2.0 ! default value
      call getin_p("df_mufi",df_mufi)
+     write(*,*)" df_mufi = ",df_mufi
 
      write(*,*) "Monomer radius (m) ?"
      rm_mufi=6.66e-08 ! default value
      call getin_p("rm_mufi",rm_mufi)
+     write(*,*)" rm_mufi = ",rm_mufi
 
      write(*,*) "Aerosol density (kg.m-3)?"
      rho_aer_mufi=1.e3 ! default value
      call getin_p("rho_aer_mufi",rho_aer_mufi)
+     write(*,*)" rho_aer_mufi = ",rho_aer_mufi
 
      write(*,*) "Pressure level of aer. production (Pa) ?"
      p_prod=1.0 ! default value
      call getin_p("p_prod",p_prod)
+     write(*,*)" p_prod = ",p_prod
      
      write(*,*) "Aerosol production rate (kg.m-2.s-1) ?"
      tx_prod=3.5e-13 ! default value
      call getin_p("tx_prod",tx_prod)
+     write(*,*)" tx_prod = ",tx_prod
 
      write(*,*) "Equivalent radius production (m) ?"
      rc_prod=2.0e-8 ! default value
      call getin_p("rc_prod",rc_prod)
+     write(*,*)" rhc_prod = ",rc_prod
 
      write(*,*) "Radius of air (nitrogen) molecule (m) ?"
      air_rad=1.75e-10 ! default value
      call getin_p("air_rad",air_rad)
+     write(*,*)" air_rad = ",air_rad
 
      write(*,*) "Path to microphys. config file ?"
      config_mufi='datagcm/microphysics/config.cfg' ! default value
      call getin_p("config_mufi",config_mufi)
+     write(*,*)" config_mufi = ",config_mufi
 
 ! Soil model
Index: /trunk/LMDZ.TITAN/libf/phytitan/optci.F90
===================================================================
--- /trunk/LMDZ.TITAN/libf/phytitan/optci.F90	(revision 1821)
+++ /trunk/LMDZ.TITAN/libf/phytitan/optci.F90	(revision 1822)
@@ -1,4 +1,4 @@
-subroutine optci(PLEV,TLEV,DTAUI,TAUCUMI,      &
-     COSBI,WBARI,TMID,PMID,TAUGSURF)
+subroutine optci(PQ,PLEV,TLEV,TMID,PMID,      &
+     DTAUI,TAUCUMI,COSBI,WBARI,TAUGSURF)
 
   use radinc_h
@@ -17,5 +17,5 @@
   !     and COSBAR. For each level it calculates TAU.
   !     
-  !     TAUI(L,LW) is the cumulative optical depth at level L (or alternatively
+  !     TAUCUMI(L,LW) is the cumulative optical depth at level L (or alternatively
   !     at the *bottom* of layer L), LW is the spectral wavelength interval.
   !     
@@ -26,17 +26,24 @@
   !     -------
   !     Adapted from the NASA Ames code by R. Wordsworth (2009)
+  !     Clean and adaptation to Titan by J. Vatant d'Ollone (2016-17)
   !     
   !==================================================================
 
 
-  real*8 DTAUI(L_NLAYRAD,L_NSPECTI,L_NGAUSS)
+  !==========================================================
+  ! Input/Output
+  !==========================================================
+  REAL*8, INTENT(IN)  :: PQ ! Tracers (kg/kg_of_air).
+  REAL*8, INTENT(IN)  :: PLEV(L_LEVELS), TLEV(L_LEVELS)
+  REAL*8, INTENT(IN)  :: TMID(L_LEVELS), PMID(L_LEVELS)
+  
+  REAL*8, INTENT(OUT) :: DTAUI(L_NLAYRAD,L_NSPECTI,L_NGAUSS) 
+  REAL*8, INTENT(OUT) :: TAUCUMI(L_LEVELS,L_NSPECTI,L_NGAUSS)
+  REAL*8, INTENT(OUT) :: COSBI(L_NLAYRAD,L_NSPECTI,L_NGAUSS)
+  REAL*8, INTENT(OUT) :: WBARI(L_NLAYRAD,L_NSPECTI,L_NGAUSS)
+  REAL*8, INTENT(OUT) :: TAUGSURF(L_NSPECTI,L_NGAUSS-1)
+  ! ==========================================================
+  
   real*8 DTAUKI(L_LEVELS,L_NSPECTI,L_NGAUSS)
-  real*8 TAUI(L_NLEVRAD,L_NSPECTI,L_NGAUSS)
-  real*8 TAUCUMI(L_LEVELS,L_NSPECTI,L_NGAUSS)
-  real*8 PLEV(L_LEVELS)
-  real*8 TLEV(L_LEVELS)
-  real*8 TMID(L_LEVELS), PMID(L_LEVELS)
-  real*8 COSBI(L_NLAYRAD,L_NSPECTI,L_NGAUSS)
-  real*8 WBARI(L_NLAYRAD,L_NSPECTI,L_NGAUSS)
 
   ! Titan customisation
@@ -58,5 +65,4 @@
   real*8  LCOEF(4), LKCOEF(L_LEVELS,4)
 
-  real*8 taugsurf(L_NSPECTI,L_NGAUSS-1)
   real*8 DCONT
   double precision wn_cont, p_cont, p_air, T_cont, dtemp, dtempc
Index: /trunk/LMDZ.TITAN/libf/phytitan/optcv.F90
===================================================================
--- /trunk/LMDZ.TITAN/libf/phytitan/optcv.F90	(revision 1821)
+++ /trunk/LMDZ.TITAN/libf/phytitan/optcv.F90	(revision 1822)
@@ -1,4 +1,4 @@
-SUBROUTINE OPTCV(DTAUV,TAUV,TAUCUMV,PLEV,  &
-     WBARV,COSBV,TAURAY,TMID,PMID,TAUGSURF)
+SUBROUTINE OPTCV(PQ,PLEV,TMID,PMID,  &
+     DTAUV,TAUV,TAUCUMV,WBARV,COSBV,TAURAY,TAUGSURF)
 
   use radinc_h
@@ -19,4 +19,5 @@
   !     -------
   !     Adapted from the NASA Ames code by R. Wordsworth (2009)
+  !     Clean and adaptation to Titan by J. Vatant d'Ollone (2016-17)
   !     
   !==================================================================
@@ -37,12 +38,19 @@
 
 
-  real*8 DTAUV(L_NLAYRAD,L_NSPECTV,L_NGAUSS)
+  !==========================================================
+  ! Input/Output
+  !==========================================================
+  REAL*8, INTENT(IN)  :: PQ ! Tracers (kg/kg_of_air).
+  REAL*8, INTENT(IN)  :: PLEV(L_LEVELS)
+  REAL*8, INTENT(IN)  :: TMID(L_LEVELS), PMID(L_LEVELS)
+  
+  REAL*8, INTENT(OUT) :: DTAUV(L_NLAYRAD,L_NSPECTV,L_NGAUSS)
+  REAL*8, INTENT(OUT) :: TAUV(L_NLEVRAD,L_NSPECTV,L_NGAUSS)
+  REAL*8, INTENT(OUT) :: TAUCUMV(L_LEVELS,L_NSPECTV,L_NGAUSS)
+  REAL*8, INTENT(OUT) :: COSBV(L_NLAYRAD,L_NSPECTV,L_NGAUSS)
+  REAL*8, INTENT(OUT) :: WBARV(L_NLAYRAD,L_NSPECTV,L_NGAUSS)
+  ! ==========================================================
+  
   real*8 DTAUKV(L_LEVELS,L_NSPECTV,L_NGAUSS)
-  real*8 TAUV(L_NLEVRAD,L_NSPECTV,L_NGAUSS)
-  real*8 TAUCUMV(L_LEVELS,L_NSPECTV,L_NGAUSS)
-  real*8 PLEV(L_LEVELS)
-  real*8 TMID(L_LEVELS), PMID(L_LEVELS)
-  real*8 COSBV(L_NLAYRAD,L_NSPECTV,L_NGAUSS)
-  real*8 WBARV(L_NLAYRAD,L_NSPECTV,L_NGAUSS)
 
   ! Titan customisation
Index: /trunk/LMDZ.TITAN/libf/phytitan/physiq_mod.F90
===================================================================
--- /trunk/LMDZ.TITAN/libf/phytitan/physiq_mod.F90	(revision 1821)
+++ /trunk/LMDZ.TITAN/libf/phytitan/physiq_mod.F90	(revision 1822)
@@ -20,4 +20,5 @@
       use comsaison_h, only: mu0, fract, dist_star, declin, right_ascen
       use comsoil_h, only: nsoilmx, layer, mlayer, inertiedat
+      use datafile_mod, only: datadir, corrkdir, banddir
       use geometry_mod, only: latitude, longitude, cell_area
       USE comgeomfi_h, only: totarea, totarea_planet
@@ -37,4 +38,5 @@
       use callkeys_mod
       use vertical_layers_mod, only: presnivs, pseudoalt
+      use ioipsl_getin_p_mod, only: getin_p
 #ifdef CPP_XIOS      
       use xios_output_mod, only: initialize_xios_output, &
@@ -308,4 +310,5 @@
 
 
+
 ! local variables for DIAGNOSTICS : (diagfi & stat)
 ! -------------------------------------------------
@@ -349,4 +352,8 @@
       real,allocatable,dimension(:,:),save :: qsurf_hist
 !$OMP THREADPRIVATE(qsurf_hist)
+   
+      ! Miscellaneous :
+      character(len=10) :: tmp1
+      character(len=10) :: tmp2
 
 ! Local variables for Titan chemistry and microphysics (JVO 2017)
@@ -458,4 +465,26 @@
          zdtlw(:,:) = 0.0
 
+!        Initialize setup for correlated-k radiative transfer
+!        JVO 17 : Was in callcorrk firstcall, but we need spectral intervals for microphysics
+!        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+         if (corrk) then
+         
+           call system('rm -f surf_vals_long.out')
+
+           write( tmp1, '(i3)' ) L_NSPECTI
+           write( tmp2, '(i3)' ) L_NSPECTV
+           banddir=trim(adjustl(tmp1))//'x'//trim(adjustl(tmp2))
+           banddir=trim(adjustl(corrkdir))//'/'//trim(adjustl(banddir))
+
+           call setspi            ! Basic infrared properties.
+           call setspv            ! Basic visible properties.
+           call sugas_corrk       ! Set up gaseous absorption properties.
+         
+           OLR_nu(:,:) = 0.
+           OSR_nu(:,:) = 0.
+           
+         endif
+
 !        Initialize names, timestep and saturation profiles for chemistry
 !        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -517,5 +546,4 @@
            stop
          endif
-
          write (*,*) 'In physiq day_ini =', day_ini
 
@@ -792,5 +820,5 @@
                               fluxsurfabs_sw,fluxtop_lw,                          &
                               fluxabs_sw,fluxtop_dn,OLR_nu,OSR_nu,                &
-                              firstcall,lastcall)
+                              lastcall)
 
                ! Radiative flux from the sky absorbed by the surface (W.m-2).
Index: /trunk/LMDZ.TITAN/libf/phytitan/radinc_h.F90
===================================================================
--- /trunk/LMDZ.TITAN/libf/phytitan/radinc_h.F90	(revision 1821)
+++ /trunk/LMDZ.TITAN/libf/phytitan/radinc_h.F90	(revision 1822)
@@ -79,10 +79,4 @@
       !real*8,parameter :: NTfac = 1.0D+2    
 
-      character(len=100),save :: corrkdir
-!$OMP THREADPRIVATE(corrkdir)
-
-      character(len=100),save :: banddir
-!$OMP THREADPRIVATE(banddir)
-
 contains
 
Index: /trunk/LMDZ.TITAN/libf/phytitan/setspi.F90
===================================================================
--- /trunk/LMDZ.TITAN/libf/phytitan/setspi.F90	(revision 1821)
+++ /trunk/LMDZ.TITAN/libf/phytitan/setspi.F90	(revision 1822)
@@ -22,7 +22,7 @@
 !==================================================================
 
-      use radinc_h,    only: L_NSPECTI,corrkdir,banddir,NTstar,NTstop,NTfac
+      use radinc_h,    only: L_NSPECTI,NTstar,NTstop,NTfac
       use radcommon_h, only: BWNI,WNOI,DWNI,WAVEI,planckir,sigma
-      use datafile_mod, only: datadir
+      use datafile_mod, only: datadir, corrkdir, banddir
       use comcstfi_mod, only: pi
 
Index: /trunk/LMDZ.TITAN/libf/phytitan/setspv.F90
===================================================================
--- /trunk/LMDZ.TITAN/libf/phytitan/setspv.F90	(revision 1821)
+++ /trunk/LMDZ.TITAN/libf/phytitan/setspv.F90	(revision 1822)
@@ -23,8 +23,8 @@
 !==================================================================
 
-      use radinc_h,    only: L_NSPECTV, corrkdir, banddir
+      use radinc_h,    only: L_NSPECTV
       use radcommon_h, only: BWNV,WNOV,DWNV,WAVEV, &
                              STELLARF,TAURAY
-      use datafile_mod, only: datadir
+      use datafile_mod, only: datadir, corrkdir, banddir
       use callkeys_mod, only: Fat1AU,rayleigh
 
Index: /trunk/LMDZ.TITAN/libf/phytitan/sugas_corrk.F90
===================================================================
--- /trunk/LMDZ.TITAN/libf/phytitan/sugas_corrk.F90	(revision 1821)
+++ /trunk/LMDZ.TITAN/libf/phytitan/sugas_corrk.F90	(revision 1822)
@@ -25,5 +25,5 @@
       use radcommon_h, only : gasv,gasi,FZEROI,FZEROV,gweight
       use radcommon_h, only : WNOI,WNOV
-      use datafile_mod, only: datadir
+      use datafile_mod, only: datadir, corrkdir, banddir
       use comcstfi_mod, only: mugaz
       use gases_h
