Index: trunk/LMDZ.MARS/libf/phymars/albedocaps.F90
===================================================================
--- trunk/LMDZ.MARS/libf/phymars/albedocaps.F90	(revision 2508)
+++ trunk/LMDZ.MARS/libf/phymars/albedocaps.F90	(revision 2609)
@@ -9,4 +9,6 @@
                      emisice, albedice, watercaptag, albedo_h2o_cap, &
                      emissiv, albedodat
+USE mod_phys_lmdz_transfert_para, ONLY: bcast
+USE mod_phys_lmdz_para, ONLY: is_master
 implicit none
 
@@ -23,5 +25,38 @@
 ! local variables:
 logical,save :: firstcall=.true.
+!$OMP THREADPRIVATE(firstcall)
 integer :: ig,icap
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+! local variables:
+real,save :: zls_old ! value of zls from a previous call
+real,save :: pi,radeg ! to convert radians to degrees
+
+!$OMP THREADPRIVATE(zls_old,pi,radeg)
+
+! TES datasets: (hard coded fixed length/sizes; for now)
+integer,parameter :: TESlonsize=72
+! longitudes, in TES files, in degrees, from TESlon(1)=-177.5 to TESlon(72)=177.5
+real,save :: TESlon(TESlonsize) 
+integer,parameter :: TESlatsize=30
+! latitudes (north hemisphere file), in degrees, from TESlatn(1)=31,
+! to TESlatn(30)=89 ; TESlatn(8)=45
+real,save :: TESlatn(TESlatsize)
+! latitudes (south hemisphere file), in degrees, from TESlats(1)=-89,
+! to TESlats(30)=-31 ; TESlats(23)=-45
+real,save :: TESlats(TESlatsize)
+integer,parameter :: TESlssize=72
+! Solar longitude in TES files, TESls(1)=2.5 to TESls(72)=357.5
+real,save :: TESls(TESlssize)
+! TES North albedo (=-1 for missing values)
+real,save :: TESalbn(TESlonsize,TESlatsize,TESlssize)
+! TES South albedo (=-1 for missing values)
+real,save :: TESalbs(TESlonsize,TESlatsize,TESlssize)
+
+!$OMP THREADPRIVATE(TESlon,TESlatn,TESlats,TESls,TESalbn,TESalbs)
+
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
 ! 1. Initializations
@@ -47,7 +82,9 @@
   endif
   
+  call read_TES_icecap_albedo(zls_old,pi,radeg,TESlon,TESlatn,TESlats,TESls,TESalbn,TESalbs)
+  
   firstcall=.false.
 endif ! of if (firstcall)
-
+    
 do ig=1,ngrid
   if (latitude(ig).lt.0.) then
@@ -56,5 +93,5 @@
     icap=1 ! Northern hemisphere
   endif
-
+  
   if (piceco2(ig).gt.0) then
     ! set emissivity of surface to be the ice emissivity
@@ -62,5 +99,5 @@
     ! set the surface albedo to be the ice albedo
     if (TESicealbedo) then
-      call TES_icecap_albedo(zls,ig,psolaralb(ig,1),icap)
+      call TES_icecap_albedo(zls,ig,psolaralb(ig,1),icap,zls_old,pi,radeg,TESlon,TESlatn,TESlats,TESls,TESalbn,TESalbs)
       psolaralb(ig,2)=psolaralb(ig,1)
     else
@@ -82,64 +119,44 @@
   endif ! of if (piceco2(ig).gt.0)
 enddo ! of ig=1,ngrid
+
 end subroutine albedocaps
 
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-subroutine TES_icecap_albedo(zls,ig,alb,icap)
-
-use geometry_mod, only: latitude, longitude ! in radians
-use surfdat_h, only: albedice, TESice_Ncoef, TESice_Scoef
+
+subroutine read_TES_icecap_albedo(zls_old,pi,radeg,TESlon,TESlatn,TESlats,TESls,TESalbn,TESalbs)
+
 use datafile_mod, only: datadir
 use netcdf, only: nf90_open, NF90_NOWRITE, NF90_NOERR, &
                   nf90_strerror, nf90_inq_varid, nf90_get_var, nf90_close
+USE mod_phys_lmdz_para, ONLY: is_master
+USE mod_phys_lmdz_transfert_para, ONLY: bcast
                   
 implicit none
 
 ! arguments:
-real,intent(in) :: zls ! solar longitude (rad)
-integer,intent(in) :: ig ! grid point index
-real,intent(out) :: alb ! (interpolated) TES ice albedo at that grid point
-integer :: icap ! =1: Northern hemisphere =2: Southern hemisphere
 
 ! local variables:
-logical,save :: firstcall=.true.
-real,save :: zls_old ! value of zls from a previous call
-integer,save :: tinf,tsup ! encompassing time indexes of TES data
-real,save :: reltime ! relative position in-between time indexes (in [0;1])
-integer :: latinf,latsup ! encompassing latitude indexes of TES data
-real :: rellat ! relative position in-between latitude indexes (in[0;1])
-integer :: loninf,lonsup ! encompassing longitude indexes of TES data
-real :: rellon !relative position in-between longitude indexes (in[0;1])
-real,save :: pi,radeg ! to convert radians to degrees
-real :: zlsd ! solar longitude, in degrees
-real :: latd ! latitude, in degrees
-real :: lond ! longitude, in degrees
-integer :: i
+real:: zls_old ! value of zls from a previous call
+real:: pi,radeg ! to convert radians to degrees
 character(len=20),parameter :: modname="TES_icecap_albedo"
 
 ! TES datasets: (hard coded fixed length/sizes; for now)
-integer,parameter :: TESlonsize=72
-real,parameter :: TESdeltalon=5.0 ! step in longitude in TES files
+integer,parameter:: TESlonsize=72
 ! longitudes, in TES files, in degrees, from TESlon(1)=-177.5 to TESlon(72)=177.5
-real,save :: TESlon(TESlonsize) 
-integer,parameter :: TESlatsize=30
-real,parameter :: TESdeltalat=2.0 ! step in latitude in TES files
+real:: TESlon(TESlonsize) 
+integer,parameter:: TESlatsize=30
 ! latitudes (north hemisphere file), in degrees, from TESlatn(1)=31,
 ! to TESlatn(30)=89 ; TESlatn(8)=45
-real,parameter :: TESlatnmin=45. ! minimum TES latitude (North hemisphere)
-real,parameter :: TESlatsmax=-45. ! maximum TES latitude (South hemisphere)
-real,save :: TESlatn(TESlatsize)
+real:: TESlatn(TESlatsize)
 ! latitudes (south hemisphere file), in degrees, from TESlats(1)=-89,
 ! to TESlats(30)=-31 ; TESlats(23)=-45
-real,save :: TESlats(TESlatsize)
-integer,parameter :: TESlssize=72
-real,parameter :: TESdeltals=5.0 ! step in solar longitude in TES files
+real:: TESlats(TESlatsize)
+integer,parameter:: TESlssize=72
 ! Solar longitude in TES files, TESls(1)=2.5 to TESls(72)=357.5
-real,save :: TESls(TESlssize)
+real:: TESls(TESlssize)
 ! TES North albedo (=-1 for missing values)
-real,save :: TESalbn(TESlonsize,TESlatsize,TESlssize)
+real:: TESalbn(TESlonsize,TESlatsize,TESlssize)
 ! TES South albedo (=-1 for missing values)
-real,save :: TESalbs(TESlonsize,TESlatsize,TESlssize)
-! encompassing nodes arranged as follow : 4 3
-real :: val(4)                          ! 1 2 
+real:: TESalbs(TESlonsize,TESlatsize,TESlssize)
 
 !NetCDF variables:
@@ -149,5 +166,7 @@
 
 ! 0. Preliminary stuff
-if (firstcall) then
+
+if(is_master) then
+
 ! Load TES albedoes for Northern Hemisphere
   ierr=nf90_open(trim(datadir)//"/npsc_albedo.nc",NF90_NOWRITE,nid)
@@ -273,7 +292,81 @@
 
   zls_old=-999 ! dummy initialization
-
-  firstcall=.false.
-endif ! of if firstcall
+    
+endif !is_master
+    
+    call bcast(TESlon)
+    call bcast(TESlatn)
+    call bcast(TESlats)
+    call bcast(TESls)
+    call bcast(TESalbn)
+    call bcast(TESalbs)
+    call bcast(pi)
+    call bcast(zls_old)
+    call bcast(radeg)
+  
+end subroutine read_TES_icecap_albedo
+
+subroutine TES_icecap_albedo(zls,ig,alb,icap,zls_old,pi,radeg,TESlon,TESlatn,TESlats,TESls,TESalbn,TESalbs)
+
+use geometry_mod, only: latitude, longitude ! in radians
+use surfdat_h, only: albedice, TESice_Ncoef, TESice_Scoef
+use datafile_mod, only: datadir
+use netcdf, only: nf90_open, NF90_NOWRITE, NF90_NOERR, &
+                  nf90_strerror, nf90_inq_varid, nf90_get_var, nf90_close
+USE mod_phys_lmdz_transfert_para, ONLY: bcast
+                  
+implicit none
+
+! arguments:
+real,intent(in) :: zls ! solar longitude (rad)
+integer,intent(in) :: ig ! grid point index
+real,intent(out) :: alb ! (interpolated) TES ice albedo at that grid point
+integer :: icap ! =1: Northern hemisphere =2: Southern hemisphere
+
+! local variables:
+integer,save :: tinf,tsup ! encompassing time indexes of TES data
+real,save :: reltime ! relative position in-between time indexes (in [0;1])
+integer :: latinf,latsup ! encompassing latitude indexes of TES data
+real :: rellat ! relative position in-between latitude indexes (in[0;1])
+integer :: loninf,lonsup ! encompassing longitude indexes of TES data
+real :: rellon !relative position in-between longitude indexes (in[0;1])
+real :: zlsd ! solar longitude, in degrees
+real :: latd ! latitude, in degrees
+real :: lond ! longitude, in degrees
+integer :: i
+
+!$OMP THREADPRIVATE(tinf,tsup,reltime)
+
+! TES datasets: (hard coded fixed length/sizes; for now)
+real,parameter :: TESdeltalon=5.0 ! step in longitude in TES files
+real,parameter :: TESdeltalat=2.0 ! step in latitude in TES files
+real,parameter :: TESlatnmin=45. ! minimum TES latitude (North hemisphere)
+real,parameter :: TESlatsmax=-45. ! maximum TES latitude (South hemisphere)
+! to TESlats(30)=-31 ; TESlats(23)=-45
+real,parameter :: TESdeltals=5.0 ! step in solar longitude in TES files
+
+real:: zls_old ! value of zls from a previous call
+real:: pi,radeg ! to convert radians to degrees
+
+! TES datasets: (hard coded fixed length/sizes; for now)
+integer,parameter:: TESlonsize=72
+! longitudes, in TES files, in degrees, from TESlon(1)=-177.5 to TESlon(72)=177.5
+real:: TESlon(TESlonsize) 
+integer,parameter:: TESlatsize=30
+! latitudes (north hemisphere file), in degrees, from TESlatn(1)=31,
+! to TESlatn(30)=89 ; TESlatn(8)=45
+real:: TESlatn(TESlatsize)
+! latitudes (south hemisphere file), in degrees, from TESlats(1)=-89,
+! to TESlats(30)=-31 ; TESlats(23)=-45
+real:: TESlats(TESlatsize)
+integer,parameter:: TESlssize=72
+! Solar longitude in TES files, TESls(1)=2.5 to TESls(72)=357.5
+real:: TESls(TESlssize)
+! TES North albedo (=-1 for missing values)
+real:: TESalbn(TESlonsize,TESlatsize,TESlssize)
+! TES South albedo (=-1 for missing values)
+real:: TESalbs(TESlonsize,TESlatsize,TESlssize)
+! encompassing nodes arranged as follow : 4 3
+real :: val(4)                          ! 1 2 
 
 ! 1. Identify encompassing latitudes
@@ -281,4 +374,5 @@
 ! Check that latitude is such that there is TES data to use
 ! (ie: latitude 45 deg and poleward) otherwise use 'default' albedoes
+
 latd=latitude(ig)*radeg ! latitude, in degrees
 if (icap.eq.1) then
