Index: LMDZ4/trunk/libf/dyn3d/ce0l.F
===================================================================
--- LMDZ4/trunk/libf/dyn3d/ce0l.F	(revision 1318)
+++ 	(revision )
@@ -1,75 +1,0 @@
-!
-! $Id$
-!
-       PROGRAM create_etat0_limit
-#ifdef CPP_EARTH
-! This prog. is designed to work for Earth
-       USE dimphy
-       USE comgeomphy
-       USE infotrac
-#ifdef CPP_IOIPSL
-       use ioipsl, only: ioconf_calendar
-#endif
-       IMPLICIT NONE
-c
-c
-c     Programme d'appel a etat0, creation des etats initiaux et limit_netcdf
-c   
-c
-c     interbar = .T . si appel a  interpol. barycentrique inter_barxy
-c
-c     extrap   = .T . si on fait une extrapolation de donnees , comme pour
-c       les  SST  lorsque  le fichier ne contient pas uniquement  des points 
-c     oceaniques .
-c
-c     oldice   = .T. si l'on veut garder les anciennes glaces , obtenues
-c     par  grille_m  ( grid_atob ) .
-c
-c     on cree le masque dans etat0 que l'on passe ensuite dans limit pour 
-c     garder les coherences
-
-      LOGICAL interbar, extrap , oldice
-      PARAMETER ( interbar = .true. , extrap = .FALSE. , oldice=.false.)
-#include "dimensions.h"
-#include "paramet.h"
-#include "indicesol.h"
-#include  "control.h"
-      REAL :: masque(iip1,jjp1)
-!      REAL :: pctsrf(iim*(jjm-1)+2, nbsrf)
-
-      IF (config_inca /= 'none') THEN
-#ifdef INCA
-         call init_const_lmdz(
-     $        nbtr,anneeref,dayref,
-     $        iphysiq, day_step,nday)
-#endif
-         print *, 'nbtr =' , nbtr 
-      END IF
-
-      CALL Init_Phys_lmdz(iim,jjp1,llm,1,(/(jjm-1)*iim+2/))
-      PRINT *,'---> klon=',klon
-      call InitComgeomphy
-
-#ifdef CPP_IOIPSL
-      call ioconf_calendar('360d')
-#endif
-
-      WRITE(6,*) '  *********************  '
-      WRITE(6,*) ' interbar = ',interbar
-      CALL etat0_netcdf ( interbar, masque )
-c
-      WRITE(6,1)
-      WRITE(6,*) '  *********************  '
-      WRITE(6,*) '  ***  Limit_netcdf ***  '
-      WRITE(6,*) '  *********************  '
-      WRITE(6,1)
-      
-c     
-      CALL  limit_netcdf ( interbar, extrap , oldice, masque)
-
-1     FORMAT(//)
-
-#endif
-! of #ifdef CPP_EARTH
-      STOP
-      END
Index: LMDZ4/trunk/libf/dyn3d/ce0l.F90
===================================================================
--- LMDZ4/trunk/libf/dyn3d/ce0l.F90	(revision 1319)
+++ LMDZ4/trunk/libf/dyn3d/ce0l.F90	(revision 1319)
@@ -0,0 +1,100 @@
+!
+! $Id$
+!
+!-------------------------------------------------------------------------------
+!
+PROGRAM ce0l
+!
+!-------------------------------------------------------------------------------
+! Purpose: Calls etat0, creates initial states and limit_netcdf
+!
+!     interbar=.T. for barycentric interpolation inter_barxy
+!     extrap  =.T. for data extrapolation, like for the SSTs when file does not
+!                  contain ocean points only.
+!     oldice  =.T. for old-style ice, obtained using grille_m (grid_atob).
+!     masque is created in etat0, passed to limit to ensure consistancy.
+!-------------------------------------------------------------------------------
+#ifdef CPP_EARTH
+! This prog. is designed to work for Earth
+  USE dimphy
+  USE comgeomphy
+  USE infotrac
+
+#ifdef CPP_IOIPSL
+  USE ioipsl, ONLY: ioconf_calendar
+#endif
+
+#endif
+  IMPLICIT NONE
+#ifndef CPP_EARTH
+  WRITE(lunout,*)'limit_netcdf: Earth-specific routine, needs Earth physics'
+#else
+!-------------------------------------------------------------------------------
+! Local variables:
+  LOGICAL, PARAMETER :: interbar=.TRUE., extrap=.FALSE., oldice=.FALSE.
+#include "dimensions.h"
+#include "paramet.h"
+#include "indicesol.h"
+#include "iniprint.h"
+#include "control.h"
+#include "temps.h"
+#include "logic.h"
+  INTEGER, PARAMETER            :: longcles=20
+  REAL,    DIMENSION(longcles)  :: clesphy0
+  REAL,    DIMENSION(iip1,jjp1) :: masque
+  CHARACTER(LEN=15)             :: calnd
+!-------------------------------------------------------------------------------
+  CALL conf_gcm( 99, .TRUE. , clesphy0 )
+
+  CALL Init_Phys_lmdz(iim,jjp1,llm,1,(/(jjm-1)*iim+2/))
+  WRITE(lunout,*)'---> klon=',klon
+  CALL InitComgeomphy
+
+#ifdef CPP_IOIPSL
+  SELECT CASE(calend)
+    CASE('earth_360d');CALL ioconf_calendar('360d');      calnd='a 360 jours/an'
+    CASE('earth_365d');CALL ioconf_calendar('noleap');    calnd='a 365 jours/an'
+    CASE('earth_366d');CALL ioconf_calendar('366d');      calnd='bissextile'
+    CASE('gregorian'); CALL ioconf_calendar('gregorian'); calnd='gregorien'
+    CASE('standard');  CALL ioconf_calendar('gregorian'); calnd='gregorien'
+    CASE('julian');    CALL ioconf_calendar('julian');    calnd='julien'
+    CASE('proleptic_gregorian'); CALL ioconf_calendar('gregorian')
+  !--- DC Bof...  => IOIPSL a mettre a jour: proleptic_gregorian /= gregorian
+    CASE DEFAULT
+      CALL abort_gcm('ce0l','Mauvais choix de calendrier',1)
+  END SELECT
+  WRITE(lunout,*)'CALENDRIER CHOISI: Terrestre '//TRIM(calnd)
+#endif
+
+  IF (config_inca /= 'none') THEN
+#ifdef INCA
+    CALL init_const_lmdz(nbtr,anneeref,dayref,iphysiq,day_step,nday)
+    CALL init_inca_para(iim,jjm+1,klon,1,klon_mpi_para_nb,0)
+    WRITE(lunout,*)'nbtr =' , nbtr 
+#endif
+  END IF
+
+  WRITE(lunout,'(//)')
+  WRITE(lunout,*) '  *********************  '
+  WRITE(lunout,*) '  ***  etat0_netcdf ***  '
+  WRITE(lunout,*) '  *********************  '
+  WRITE(lunout,'(//)')
+  WRITE(lunout,*) ' interbar = ',interbar
+  CALL etat0_netcdf(interbar,masque,ok_etat0)
+
+  IF(ok_limit) THEN
+  WRITE(lunout,'(//)')
+  WRITE(lunout,*) '  *********************  '
+  WRITE(lunout,*) '  ***  Limit_netcdf ***  '
+  WRITE(lunout,*) '  *********************  '
+  WRITE(lunout,'(//)')
+  CALL limit_netcdf(interbar,extrap,oldice,masque)
+  END IF
+
+#endif
+! of #ifndef CPP_EARTH #else
+  STOP
+
+END PROGRAM ce0l
+!
+!-------------------------------------------------------------------------------
Index: LMDZ4/trunk/libf/dyn3d/comdissnew.h
===================================================================
--- LMDZ4/trunk/libf/dyn3d/comdissnew.h	(revision 1318)
+++ LMDZ4/trunk/libf/dyn3d/comdissnew.h	(revision 1319)
@@ -1,10 +1,16 @@
 !
-! $Header$
+! $Id$
 !
-c-----------------------------------------------------------------------
-c INCLUDE comdissnew.h
+!
+!  ATTENTION!!!!: ce fichier include est compatible format fixe/format libre
+!                 veillez à n'utiliser que des ! pour les commentaires
+!                 et à bien positionner les & des lignes de continuation 
+!                 (les placer en colonne 6 et en colonne 73)
+!
+!-----------------------------------------------------------------------
+! INCLUDE 'comdissnew.h'
 
-      COMMON/comdissnew/ lstardis,nitergdiv,nitergrot,niterh,tetagdiv,
-     1                   tetagrot,tetatemp,coefdis 
+      COMMON/comdissnew/ lstardis,nitergdiv,nitergrot,niterh,tetagdiv,  &
+     &                   tetagrot,tetatemp,coefdis 
 
       LOGICAL lstardis
@@ -12,7 +18,7 @@
       REAL     tetagdiv, tetagrot,  tetatemp, coefdis
 
-c
-c ... Les parametres de ce common comdissnew sont  lues par defrun_new 
-c              sur le fichier  run.def    ....
-c
-c-----------------------------------------------------------------------
+!
+! ... Les parametres de ce common comdissnew sont  lues par defrun_new 
+!              sur le fichier  run.def    ....
+!
+!-----------------------------------------------------------------------
Index: LMDZ4/trunk/libf/dyn3d/conf_gcm.F
===================================================================
--- LMDZ4/trunk/libf/dyn3d/conf_gcm.F	(revision 1318)
+++ LMDZ4/trunk/libf/dyn3d/conf_gcm.F	(revision 1319)
@@ -769,6 +769,23 @@
        CALL getin('ok_gradsfile',ok_gradsfile)
 
+!Config  Key  = ok_limit
+!Config  Desc = creation des fichiers limit dans create_etat0_limit
+!Config  Def  = y
+!Config  Help = production du fichier limit.nc requise
+
+       ok_limit = .TRUE.
+       CALL getin('ok_limit',ok_limit)
+
+!Config  Key  = ok_etat0
+!Config  Desc = creation des fichiers etat0 dans create_etat0_limit
+!Config  Def  = y
+!Config  Help = production des fichiers start.nc, startphy.nc requise
+
+      ok_etat0 = .TRUE.
+      CALL getin('ok_etat0',ok_etat0)
+
       write(lunout,*)' #########################################'
-      write(lunout,*)' Configuration des parametres du gcm: '
+      write(lunout,*)' Configuration des parametres de create_etat0'
+     &             //'_limit: '
       write(lunout,*)' planet_type = ', planet_type
       write(lunout,*)' calend = ', calend
@@ -809,4 +826,6 @@
       write(lunout,*)' ok_strato = ', ok_strato
       write(lunout,*)' ok_gradsfile = ', ok_gradsfile
+      write(lunout,*)' ok_limit = ', ok_limit
+      write(lunout,*)' ok_etat0 = ', ok_etat0
 c
       RETURN
Index: LMDZ4/trunk/libf/dyn3d/etat0_netcdf.F
===================================================================
--- LMDZ4/trunk/libf/dyn3d/etat0_netcdf.F	(revision 1318)
+++ 	(revision )
@@ -1,791 +1,0 @@
-!
-! $Header$
-!
-c
-c
-      SUBROUTINE etat0_netcdf (interbar, masque)
-#ifdef CPP_EARTH        
-      USE startvar
-      USE ioipsl
-      USE dimphy
-      USE infotrac
-      USE fonte_neige_mod
-      USE pbl_surface_mod
-      USE phys_state_var_mod
-      USE filtreg_mod
-      use regr_lat_time_climoz_m, only: regr_lat_time_climoz
-      use conf_phys_m, only: conf_phys
-#endif
-!#endif of #ifdef CPP_EARTH
-      use netcdf, only: nf90_open, NF90_NOWRITE, nf90_close
-      !
-      IMPLICIT NONE
-      !
-#include "dimensions.h"
-#include "paramet.h"
-      !
-      !
-!      INTEGER, PARAMETER :: KIDIA=1, KFDIA=iim*(jjm-1)+2, 
-!     .KLON=KFDIA-KIDIA+1,KLEV=llm
-      !
-#ifdef CPP_EARTH    
-#include "comgeom2.h"
-#include "comvert.h"
-#include "comconst.h"
-#include "indicesol.h"
-#include "dimsoil.h"
-#include "temps.h"
-#endif
-!#endif of #ifdef CPP_EARTH
-      ! arguments:
-      LOGICAL interbar
-      REAL :: masque(iip1,jjp1)
-
-#ifdef CPP_EARTH
-      ! local variables:
-      REAL :: latfi(klon), lonfi(klon)
-      REAL :: orog(iip1,jjp1), rugo(iip1,jjp1)
-      REAL :: psol(iip1, jjp1), phis(iip1, jjp1)
-      REAL :: p3d(iip1, jjp1, llm+1)
-      REAL :: uvent(iip1, jjp1, llm)
-      REAL :: vvent(iip1, jjm, llm)
-      REAL :: t3d(iip1, jjp1, llm), tpot(iip1, jjp1, llm)
-      REAL :: qsat(iip1, jjp1, llm)
-      REAL,ALLOCATABLE :: q3d(:, :, :,:)
-      REAL :: tsol(klon), qsol(klon), sn(klon)
-!!      REAL :: tsolsrf(klon,nbsrf)
-      real qsolsrf(klon,nbsrf),snsrf(klon,nbsrf) 
-      REAL :: albe(klon,nbsrf), evap(klon,nbsrf)
-      REAL :: alblw(klon,nbsrf)
-      REAL :: tsoil(klon,nsoilmx,nbsrf) 
-      REAL :: frugs(klon,nbsrf), agesno(klon,nbsrf)
-      REAL :: rugmer(klon)
-      REAL :: qd(iip1, jjp1, llm)
-      REAL :: run_off_lic_0(klon)
-      ! declarations pour lecture glace de mer
-      REAL :: rugv(klon)
-      INTEGER :: iml_lic, jml_lic, llm_tmp, ttm_tmp, iret
-      INTEGER :: itaul(1), fid
-      REAL :: lev(1), date
-      REAL, ALLOCATABLE, DIMENSION(:,:) :: lon_lic, lat_lic
-      REAL, ALLOCATABLE, DIMENSION(:)  :: dlon_lic, dlat_lic
-      REAL, ALLOCATABLE, DIMENSION (:,:) :: fraclic
-      REAL :: flic_tmp(iip1, jjp1)
-      REAL :: champint(iim, jjp1)
-      !
-
-      CHARACTER(len=80) :: varname
-      !
-      INTEGER :: i,j, ig, l, ji,ii1,ii2
-      REAL :: xpi
-      !
-      REAL :: alpha(iip1,jjp1,llm),beta(iip1,jjp1,llm)
-      REAL :: pk(iip1,jjp1,llm), pls(iip1,jjp1,llm), pks(ip1jmp1)
-      REAL :: workvar(iip1,jjp1,llm)
-      !
-      REAL ::  prefkap, unskap
-      !
-      real :: time_step,t_ops,t_wrt
-
-#include "comdissnew.h"
-#include "control.h"
-#include "serre.h"
-#include "clesphys.h"
-
-      INTEGER  ::        longcles
-      PARAMETER      ( longcles  = 20 )
-      REAL :: clesphy0 ( longcles       )
-      REAL :: p(iip1,jjp1,llm)
-      INTEGER :: itau, iday
-      REAL :: masse(iip1,jjp1,llm)
-      REAL :: xpn,xps,xppn(iim),xpps(iim)
-      real :: time
-      REAL :: phi(ip1jmp1,llm)
-      REAL :: pbaru(ip1jmp1,llm),pbarv(ip1jm,llm)
-      REAL :: w(ip1jmp1,llm)
-      REAL ::phystep
-CC      REAL :: rugsrel(iip1*jjp1)
-      REAL :: fder(klon)
-!!      real zrel(iip1*jjp1),chmin,chmax
-
-!!      CHARACTER(len=80) :: visu_file
-      INTEGER :: visuid
-
-! pour la lecture du fichier masque ocean
-      integer :: nid_o2a
-      logical :: couple = .false.
-      INTEGER :: iml_omask, jml_omask
-      REAL, ALLOCATABLE, DIMENSION(:,:) :: lon_omask, lat_omask
-      REAL, ALLOCATABLE, DIMENSION(:)  :: dlon_omask, dlat_omask
-      REAL, ALLOCATABLE, DIMENSION (:,:) :: ocemask, ocetmp
-      real, dimension(klon) :: ocemask_fi
-      integer :: isst(klon-2)
-      real zx_tmp_2d(iim,jjp1)
-
-      REAL :: dummy
-
-      logical              :: ok_newmicro
-      integer              :: iflag_radia
-      logical              :: ok_journe, ok_mensuel, ok_instan, ok_hf
-      logical              :: ok_LES
-      LOGICAL              :: ok_ade, ok_aie, aerosol_couple, new_aod
-      INTEGER              :: flag_aerosol
-      REAL                 :: bl95_b0, bl95_b1
-      real                 :: fact_cldcon, facttemps,ratqsbas,ratqshaut
-      real                 :: tau_ratqs
-      integer              :: iflag_cldcon
-      integer              :: iflag_ratqs
-      integer :: iflag_coupl
-      integer :: iflag_clos
-      integer :: iflag_wake
-      integer :: iflag_thermals,nsplit_thermals
-      real    :: tau_thermals
-      integer :: iflag_thermals_ed,iflag_thermals_optflux
-      REAL      :: solarlong0
-      real :: seuil_inversion
-
-      integer  read_climoz ! read ozone climatology
-C     Allowed values are 0, 1 and 2
-C     0: do not read an ozone climatology
-C     1: read a single ozone climatology that will be used day and night
-C     2: read two ozone climatologies, the average day and night
-C     climatology and the daylight climatology
-
-      !
-      !   Constantes 
-      !
-      pi     = 4. * ATAN(1.)
-      rad    = 6371229.
-      omeg   = 4.* ASIN(1.)/(24.*3600.)
-      g      = 9.8
-      daysec = 86400.
-      kappa  = 0.2857143
-      cpp    = 1004.70885
-      !
-      preff     = 101325.
-      pa        =  50000.
-      unskap = 1./kappa
-      !
-      jmp1    = jjm + 1
-      !
-      !    Construct a grid
-      !
-
-!      CALL defrun_new(99,.TRUE.,clesphy0)
-      CALL conf_gcm( 99, .TRUE. , clesphy0 )
-      call conf_phys(  ok_journe, ok_mensuel, ok_instan, ok_hf, ok_LES, &
-     &                 solarlong0,seuil_inversion,                      &
-     &                 fact_cldcon, facttemps,ok_newmicro,iflag_radia,  &
-     &                 iflag_cldcon,                                    &
-     &                 iflag_ratqs,ratqsbas,ratqshaut,tau_ratqs,        &
-     &                 ok_ade, ok_aie, aerosol_couple,                  &
-     &                 flag_aerosol, new_aod,                           &
-     &                 bl95_b0, bl95_b1,                                &
-     &                 iflag_thermals,nsplit_thermals,tau_thermals,     &
-     &                 iflag_thermals_ed,iflag_thermals_optflux,        &
-     &                 iflag_coupl,iflag_clos,iflag_wake, read_climoz )
-
-! co2_ppm0 : initial value of atmospheric CO2 from .def file (co2_ppm value)
-      co2_ppm0 = co2_ppm
-
-      dtvr   = daysec/FLOAT(day_step)
-      print*,'dtvr',dtvr
-
-      CALL iniconst()
-      CALL inigeom()
-
-! Initialisation pour traceurs
-      call infotrac_init
-      ALLOCATE(q3d(iip1, jjp1, llm, nqtot))
-
-      CALL inifilr()
-      CALL phys_state_var_init(read_climoz)
-      !
-      latfi(1) = ASIN(1.0)
-      DO j = 2, jjm
-        DO i = 1, iim
-          latfi((j-2)*iim+1+i)=  rlatu(j)
-        ENDDO
-      ENDDO
-      latfi(klon) = - ASIN(1.0)
-      !
-      lonfi(1) = 0.0
-      DO j = 2, jjm
-        DO i = 1, iim
-          lonfi((j-2)*iim+1+i) =  rlonv(i)
-        ENDDO
-      ENDDO
-      lonfi(klon) = 0.0
-      !
-      xpi = 2.0 * ASIN(1.0)
-      DO ig = 1, klon
-        latfi(ig) = latfi(ig) * 180.0 / xpi
-        lonfi(ig) = lonfi(ig) * 180.0 / xpi
-      ENDDO
-      !
-      rlat(1) = ASIN(1.0)
-      DO j = 2, jjm
-        DO i = 1, iim
-          rlat((j-2)*iim+1+i)=  rlatu(j)
-        ENDDO
-      ENDDO
-      rlat(klon) = - ASIN(1.0)
-      !
-      rlon(1) = 0.0
-      DO j = 2, jjm
-        DO i = 1, iim
-          rlon((j-2)*iim+1+i) =  rlonv(i)
-        ENDDO
-      ENDDO
-      rlon(klon) = 0.0
-      !
-      xpi = 2.0 * ASIN(1.0)
-      DO ig = 1, klon
-        rlat(ig) = rlat(ig) * 180.0 / xpi
-        rlon(ig) = rlon(ig) * 180.0 / xpi
-      ENDDO
-      !
-      
-
-
-C
-C En cas de simulation couplee, lecture du masque ocean issu du modele ocean
-C utilise pour calculer les poids et pour assurer l'adequation entre les
-C fractions d'ocean vu par l'atmosphere et l'ocean. Sinon, on cree le masque 
-C a partir du fichier relief
-C
-
-      write(*,*)'Essai de lecture masque ocean'
-      iret = nf90_open("o2a.nc", NF90_NOWRITE, nid_o2a)
-      if (iret .ne. 0) then
-        write(*,*)'ATTENTION!! pas de fichier o2a.nc trouve'
-        write(*,*)'Run force'
-        varname = 'masque'
-        masque(:,:) = 0.0
-        CALL startget(varname, iip1, jjp1, rlonv, rlatu, masque, 0.0,
-     ,  jjm ,rlonu,rlatv , interbar )
-        WRITE(*,*) 'MASQUE construit : Masque'
-        WRITE(*,'(97I1)') nINT(masque(:,:))
-        call gr_dyn_fi(1, iip1, jjp1, klon, masque, zmasq)
-        WHERE (zmasq(1 : klon) .LT. EPSFRA)
-            zmasq(1 : klon) = 0.
-        END WHERE 
-        WHERE (1. - zmasq(1 : klon) .LT. EPSFRA)
-            zmasq(1 : klon) = 1.
-        END WHERE 
-      else
-        couple = .true.
-        iret = nf90_close(nid_o2a)
-        call flininfo("o2a.nc", iml_omask, jml_omask, llm_tmp, ttm_tmp
-     $    , nid_o2a)
-        if (iml_omask /= iim .or. jml_omask /= jjp1) then
-          write(*,*)'Dimensions non compatibles pour masque ocean'
-          write(*,*)'iim = ',iim,' iml_omask = ',iml_omask
-          write(*,*)'jjp1 = ',jjp1,' jml_omask = ',jml_omask
-          stop
-        endif
-        ALLOCATE(lat_omask(iml_omask, jml_omask), stat=iret)
-        ALLOCATE(lon_omask(iml_omask, jml_omask), stat=iret)
-        ALLOCATE(dlon_omask(iml_omask), stat=iret)
-        ALLOCATE(dlat_omask(jml_omask), stat=iret)
-        ALLOCATE(ocemask(iml_omask, jml_omask), stat=iret)
-        ALLOCATE(ocetmp(iml_omask, jml_omask), stat=iret)
-        CALL flinopen("o2a.nc", .FALSE., iml_omask, jml_omask, llm_tmp
-     $    , lon_omask, lat_omask, lev, ttm_tmp, itaul, date, dt, fid)
-        CALL flinget(fid, 'OceMask', iml_omask, jml_omask, llm_tmp, 
-     $      ttm_tmp, 1, 1, ocetmp)
-        CALL flinclo(fid)
-        dlon_omask(1 : iml_omask) = lon_omask(1 : iml_omask, 1)
-        dlat_omask(1 : jml_omask) = lat_omask(1 , 1 : jml_omask)
-        ocemask = ocetmp
-        if (dlat_omask(1) < dlat_omask(jml_omask)) then
-          do j = 1, jml_omask
-            ocemask(:,j) = ocetmp(:,jml_omask-j+1)
-          enddo
-        endif 
-C
-C passage masque ocean a la grille physique
-C
-        write(*,*)'ocemask '
-        write(*,'(96i1)')int(ocemask)
-        ocemask_fi(1) = ocemask(1,1)
-        do j = 2, jjm
-          do i = 1, iim
-            ocemask_fi((j-2)*iim + i + 1) = ocemask(i,j)
-          enddo
-        enddo
-        ocemask_fi(klon) = ocemask(1,jjp1)
-        zmasq = 1. - ocemask_fi
-      endif
-
-      call gr_fi_dyn(1, klon, iip1, jjp1, zmasq, masque)
-
-      varname = 'relief'
-      ! This line needs to be replaced by a call to restget to get the values in the restart file
-      orog(:,:) = 0.0
-       CALL startget(varname, iip1, jjp1, rlonv, rlatu, orog, 0.0 ,
-     , jjm ,rlonu,rlatv , interbar, masque )
-      !
-      WRITE(*,*) 'OUT OF GET VARIABLE : Relief'
-!      WRITE(*,'(49I1)') INT(orog(:,:))
-      !
-      varname = 'rugosite'
-      ! This line needs to be replaced by a call to restget to get the values in the restart file
-      rugo(:,:) = 0.0
-       CALL startget(varname, iip1, jjp1, rlonv, rlatu, rugo, 0.0 ,
-     , jjm, rlonu,rlatv , interbar )
-      !
-      WRITE(*,*) 'OUT OF GET VARIABLE : Rugosite' 
-!      WRITE(*,'(49I1)') INT(rugo(:,:)*10)
-      !
-C
-C on initialise les sous surfaces
-C
-      pctsrf=0.
-c
-      varname = 'psol'
-      psol(:,:) = 0.0
-      CALL startget(varname, iip1, jjp1, rlonv, rlatu, psol, 0.0 ,
-     , jjm ,rlonu,rlatv , interbar )
-      !
-      !  Compute here the pressure on the intermediate levels. One would expect that this is available in the GCM 
-      !  anyway.
-      !
-!      WRITE(*,*) 'PSOL :', psol(10,20)
-!      WRITE(*,*) ap(:), bp(:)
-      CALL pression(ip1jmp1, ap, bp, psol, p3d)
-!      WRITE(*,*) 'P3D :', p3d(10,20,:)
-      CALL exner_hyb(ip1jmp1, psol, p3d, alpha, beta, pks, pk, workvar)
-!      WRITE(*,*) 'PK:', pk(10,20,:)
-      !
-      !
-      !
-      prefkap =  preff  ** kappa
-!      WRITE(*,*) 'unskap, cpp,  preff :', unskap, cpp,  preff
-      DO l = 1, llm
-        DO j=1,jjp1
-          DO i =1, iip1
-            pls(i,j,l) = preff * ( pk(i,j,l)/cpp) ** unskap
-           ENDDO
-        ENDDO
-      ENDDO
-      !
-!      WRITE(*,*) 'PLS :', pls(10,20,:)
-      !
-      varname = 'surfgeo'
-      phis(:,:) = 0.0
-      CALL startget(varname, iip1, jjp1, rlonv, rlatu, phis, 0.0 ,
-     , jjm ,rlonu,rlatv, interbar )
-      !
-      varname = 'u'
-      uvent(:,:,:) = 0.0
-      CALL startget(varname, iip1, jjp1, rlonu, rlatu, llm, pls,
-     . workvar, uvent, 0.0, jjm ,rlonv, rlatv, interbar )
-      !  
-      varname = 'v'
-      vvent(:,:,:) = 0.0
-      CALL startget(varname, iip1, jjm, rlonv, rlatv, llm, pls,
-     . workvar, vvent, 0.0, jjp1, rlonu, rlatu, interbar )
-      !
-      varname = 't'
-      t3d(:,:,:) = 0.0
-      CALL startget(varname, iip1, jjp1, rlonv, rlatu, llm, pls,
-     . workvar, t3d, 0.0 , jjm, rlonu, rlatv , interbar )
-      !
-      WRITE(*,*) 'T3D min,max:',minval(t3d(:,:,:)),
-     .                          maxval(t3d(:,:,:))
-      varname = 'tpot'
-      tpot(:,:,:) = 0.0
-      CALL startget(varname, iip1, jjp1, rlonv, rlatu, llm, pls,
-     . pk, tpot, 0.0 , jjm, rlonu, rlatv , interbar )
-      !
-      WRITE(*,*) 'T3D min,max:',minval(t3d(:,:,:)),
-     .                          maxval(t3d(:,:,:))
-      WRITE(*,*) 'PLS min,max:',minval(pls(:,:,:)),
-     .                          maxval(pls(:,:,:))
-
-c Calcul de l'humidite a saturation
-      print*,'avant q_sat'
-      call q_sat(llm*jjp1*iip1,t3d,pls,qsat)
-      print*,'apres q_sat'
-
-      WRITE(*,*) 'QSAT min,max:',minval(qsat(:,:,:)),
-     .                           maxval(qsat(:,:,:))
-      !
-CC      WRITE(*,*) 'QSAT :', qsat(10,20,:)
-      !
-      varname = 'q'
-      qd(:,:,:) = 0.0
-      q3d(:,:,:,:) = 0.0
-      WRITE(*,*) 'QSAT min,max:',minval(qsat(:,:,:)),
-     .                           maxval(qsat(:,:,:))
-      CALL startget(varname, iip1, jjp1, rlonv, rlatu, llm, pls,
-     . qsat, qd, 0.0, jjm, rlonu, rlatv , interbar )
-      q3d(:,:,:,1) = qd(:,:,:)
-      !
-
-!     Ozone climatology:
-      if (read_climoz >= 1) call regr_lat_time_climoz(read_climoz)
-
-      varname = 'tsol'
-      ! This line needs to be replaced by a call to restget to get the values in the restart file
-      tsol(:) = 0.0
-      CALL startget(varname, iip1, jjp1, rlonv, rlatu, klon, tsol, 0.0,
-     .    jjm, rlonu, rlatv , interbar )
-      !
-      WRITE(*,*) 'TSOL construit :'
-!      WRITE(*,'(48I3)') INT(TSOL(2:klon)-273)
-      !
-      varname = 'qsol'
-      qsol(:) = 0.0
-      CALL startget(varname, iip1, jjp1, rlonv, rlatu, klon, qsol, 0.0,
-     .   jjm, rlonu, rlatv , interbar )
-      !
-      varname = 'snow'
-      sn(:) = 0.0
-      CALL startget(varname, iip1, jjp1, rlonv, rlatu, klon, sn, 0.0,
-     .    jjm, rlonu, rlatv , interbar )
-      !
-      varname = 'rads'
-      radsol(:) = 0.0
-      CALL startget(varname,iip1,jjp1,rlonv,rlatu,klon,radsol,0.0,
-     .    jjm, rlonu, rlatv , interbar )
-      !
-      varname = 'rugmer'
-      rugmer(:) = 0.0
-      CALL startget(varname,iip1,jjp1,rlonv,rlatu,klon,rugmer,0.0,
-     .     jjm, rlonu, rlatv , interbar )
-      !
-!      varname = 'agesno'
-!      agesno(:) = 0.0
-!      CALL startget(varname,iip1,jjp1,rlonv,rlatu,klon,agesno,0.0,
-!     .     jjm, rlonu, rlatv , interbar )
-
-      varname = 'zmea'
-      zmea(:) = 0.0
-      CALL startget(varname,iip1,jjp1,rlonv,rlatu,klon,zmea,0.0,
-     .     jjm, rlonu, rlatv , interbar )
-
-      varname = 'zstd'
-      zstd(:) = 0.0
-      CALL startget(varname,iip1,jjp1,rlonv,rlatu,klon,zstd,0.0,
-     .     jjm, rlonu, rlatv , interbar )
-      varname = 'zsig'
-      zsig(:) = 0.0
-      CALL startget(varname,iip1,jjp1,rlonv,rlatu,klon,zsig,0.0,
-     .     jjm, rlonu, rlatv , interbar )
-      varname = 'zgam'
-      zgam(:) = 0.0
-      CALL startget(varname,iip1,jjp1,rlonv,rlatu,klon,zgam,0.0,
-     .     jjm, rlonu, rlatv , interbar )
-      varname = 'zthe'
-      zthe(:) = 0.0
-      CALL startget(varname,iip1,jjp1,rlonv,rlatu,klon,zthe,0.0,
-     .     jjm, rlonu, rlatv , interbar )
-      varname = 'zpic'
-      zpic(:) = 0.0
-      CALL startget(varname,iip1,jjp1,rlonv,rlatu,klon,zpic,0.0,
-     .     jjm, rlonu, rlatv , interbar )
-      varname = 'zval'
-      zval(:) = 0.0
-      CALL startget(varname,iip1,jjp1,rlonv,rlatu,klon,zval,0.0,
-     .     jjm, rlonu, rlatv , interbar )
-c
-cc      rugsrel(:) = 0.0
-cc      IF(ok_orodr)  THEN
-cc        DO i = 1, iip1* jjp1
-cc         rugsrel(i) = MAX( 1.e-05, zstd(i)* zsig(i) /2. )
-cc        ENDDO
-cc      ENDIF
-
-
-C
-C lecture du fichier glace de terre pour fixer la fraction de terre 
-C et de glace de terre
-C
-      CALL flininfo("landiceref.nc", iml_lic, jml_lic,llm_tmp, ttm_tmp
-     $    , fid)
-      ALLOCATE(lat_lic(iml_lic, jml_lic), stat=iret)
-      ALLOCATE(lon_lic(iml_lic, jml_lic), stat=iret)
-      ALLOCATE(dlon_lic(iml_lic), stat=iret)
-      ALLOCATE(dlat_lic(jml_lic), stat=iret)
-      ALLOCATE(fraclic(iml_lic, jml_lic), stat=iret)
-      CALL flinopen("landiceref.nc", .FALSE., iml_lic, jml_lic, llm_tmp
-     $    , lon_lic, lat_lic, lev, ttm_tmp, itaul, date, dt, fid)
-      CALL flinget(fid, 'landice', iml_lic, jml_lic, llm_tmp, ttm_tmp
-     $    , 1, 1, fraclic)
-      CALL flinclo(fid)
-C
-C interpolation sur la grille T du modele
-C
-      WRITE(*,*) 'dimensions de landice iml_lic, jml_lic : ', 
-     $    iml_lic, jml_lic
-c
-C sil les coordonnees sont en degres, on les transforme
-C
-      IF( MAXVAL( lon_lic(:,:) ) .GT. 2.0 * asin(1.0) )  THEN
-          lon_lic(:,:) = lon_lic(:,:) * 2.0* ASIN(1.0) / 180.
-      ENDIF 
-      IF( maxval( lat_lic(:,:) ) .GT. 2.0 * asin(1.0)) THEN 
-          lat_lic(:,:) = lat_lic(:,:) * 2.0 * asin(1.0) / 180.
-      ENDIF 
-
-      dlon_lic(1 : iml_lic) = lon_lic(1 : iml_lic, 1)
-      dlat_lic(1 : jml_lic) = lat_lic(1 , 1 : jml_lic) 
-C
-      CALL grille_m(iml_lic, jml_lic, dlon_lic, dlat_lic, fraclic
-     $    ,iim, jjp1,
-     $    rlonv, rlatu, flic_tmp(1 : iim, 1 : jjp1))
-cx$$$      flic_tmp(1 : iim, 1 : jjp1) = champint(1: iim, 1 : jjp1)
-      flic_tmp(iip1, 1 : jjp1) = flic_tmp(1 , 1 : jjp1)
-C
-C passage sur la grille physique
-C
-      CALL gr_dyn_fi(1, iip1, jjp1, klon, flic_tmp,
-     $    pctsrf(1:klon, is_lic))
-C adequation avec le maque terre/mer
-c      zmasq(157) = 0.
-      WHERE (pctsrf(1 : klon, is_lic) .LT. EPSFRA ) 
-          pctsrf(1 : klon, is_lic) = 0. 
-      END WHERE
-      WHERE (zmasq( 1 : klon) .LT. EPSFRA) 
-          pctsrf(1 : klon, is_lic) = 0.
-      END WHERE 
-      pctsrf(1 : klon, is_ter) = zmasq(1 : klon)
-      DO ji = 1, klon
-        IF (zmasq(ji) .GT. EPSFRA) THEN 
-            IF ( pctsrf(ji, is_lic) .GE. zmasq(ji)) THEN
-                pctsrf(ji, is_lic) = zmasq(ji)
-                pctsrf(ji, is_ter) = 0.
-            ELSE 
-                pctsrf(ji,is_ter) = zmasq(ji) - pctsrf(ji, is_lic)
-                IF (pctsrf(ji,is_ter) .LT. EPSFRA) THEN
-                    pctsrf(ji,is_ter) = 0.
-                    pctsrf(ji, is_lic) = zmasq(ji)
-                ENDIF 
-            ENDIF 
-        ENDIF 
-      END DO 
-C
-C sous surface ocean et glace de mer (pour demarrer on met glace de mer a 0)
-C
-      pctsrf(1 : klon, is_oce) = (1. - zmasq(1 : klon))
-
-
-      WHERE (pctsrf(1 : klon, is_oce) .LT. EPSFRA)
-          pctsrf(1 : klon, is_oce) = 0.
-      END WHERE 
-
-      if (couple) pctsrf(1 : klon, is_oce) = ocemask_fi(1 : klon)
-
-      isst = 0
-      where (pctsrf(2:klon-1,is_oce) >0.) isst = 1
-C
-C verif que somme des sous surface = 1
-C
-      ji=count( (abs( sum(pctsrf(1 : klon, 1 : nbsrf),dim=2))-1.0) 
-     $    .GT. EPSFRA)
-      IF (ji .NE. 0) THEN
-          WRITE(*,*) 'pb repartition sous maille pour ',ji,' points'
-      ENDIF 
-
-!      where (pctsrf(1:klon, is_ter) >= .5) 
-!        pctsrf(1:klon, is_ter) = 1.
-!        pctsrf(1:klon, is_oce) = 0.
-!        pctsrf(1:klon, is_sic) = 0.
-!        pctsrf(1:klon, is_lic) = 0.
-!        zmasq = 1.
-!      endwhere
-!      where (pctsrf(1:klon, is_lic) >= .5) 
-!        pctsrf(1:klon, is_ter) = 0.
-!        pctsrf(1:klon, is_oce) = 0.
-!        pctsrf(1:klon, is_sic) = 0.
-!        pctsrf(1:klon, is_lic) = 1.
-!        zmasq = 1.
-!      endwhere
-!      where (pctsrf(1:klon, is_oce) >= .5) 
-!        pctsrf(1:klon, is_ter) = 0.
-!        pctsrf(1:klon, is_oce) = 1.
-!        pctsrf(1:klon, is_sic) = 0.
-!        pctsrf(1:klon, is_lic) = 0.
-!        zmasq = 0.
-!      endwhere
-!      where (pctsrf(1:klon, is_sic) >= .5) 
-!        pctsrf(1:klon, is_ter) = 0.
-!        pctsrf(1:klon, is_oce) = 0.
-!        pctsrf(1:klon, is_sic) = 1.
-!        pctsrf(1:klon, is_lic) = 0.
-!        zmasq = 0.
-!      endwhere
-!      call gr_fi_dyn(1, klon, iip1, jjp1, zmasq, masque)
-C
-C verif que somme des sous surface = 1
-C
-!      ji=count( (abs( sum(pctsrf(1 : klon, 1 : nbsrf), dim = 2)) - 1.0 ) 
-!     $    .GT. EPSFRA)
-!      IF (ji .NE. 0) THEN
-!          WRITE(*,*) 'pb repartition sous maille pour ',ji,' points'
-!     ENDIF 
-
-      CALL gr_fi_ecrit(1,klon,iim,jjp1,zmasq,zx_tmp_2d)
-      write(*,*)'zmasq = '
-      write(*,'(96i1)')nint(zx_tmp_2d)
-      call gr_fi_dyn(1, klon, iip1, jjp1, zmasq, masque)
-      WRITE(*,*) 'MASQUE construit : Masque'
-      WRITE(*,'(97I1)') nINT(masque(:,:))
-
-
-
-C Calcul intermediaire
-c 
-      CALL massdair( p3d, masse  )
-c
-
-      print *,' ALPHAX ',alphax
-
-      DO  l = 1, llm
-        DO  i    = 1, iim
-          xppn(i) = aire( i, 1   ) * masse(  i     ,  1   , l )
-          xpps(i) = aire( i,jjp1 ) * masse(  i     , jjp1 , l )
-        ENDDO
-          xpn      = SUM(xppn)/apoln
-          xps      = SUM(xpps)/apols
-        DO i   = 1, iip1
-          masse(   i   ,   1     ,  l )   = xpn
-          masse(   i   ,   jjp1  ,  l )   = xps
-        ENDDO
-      ENDDO
-      q3d(iip1,:,:,:) = q3d(1,:,:,:)
-      phis(iip1,:) = phis(1,:)
-
-C Ecriture
-      CALL inidissip( lstardis, nitergdiv, nitergrot, niterh   ,
-     *                tetagdiv, tetagrot , tetatemp              )
-      print*,'sortie inidissip'
-      itau = 0
-      itau_dyn = 0
-      itau_phy = 0
-      iday = dayref +itau/day_step
-      time = real(itau-(iday-dayref)*day_step)/day_step
-c     
-      IF(time.GT.1)  THEN
-       time = time - 1
-       iday = iday + 1
-      ENDIF
-      day_ref = dayref
-      annee_ref = anneeref
-
-      CALL geopot  ( ip1jmp1, tpot  , pk , pks,  phis  , phi   )
-      print*,'sortie geopot'
-      
-      CALL caldyn0 ( itau,uvent,vvent,tpot,psol,masse,pk,phis ,
-     *                phi,w, pbaru,pbarv,time+iday-dayref   )
-       print*,'sortie caldyn0'     
-      CALL dynredem0("start.nc",dayref,phis)
-      print*,'sortie dynredem0'
-      CALL dynredem1("start.nc",0.0,vvent,uvent,tpot,q3d,masse ,
-     .                            psol)
-      print*,'sortie dynredem1' 
-C
-C Ecriture etat initial physique
-C
-      write(*,*)'phystep ',dtvr,iphysiq,nbapp_rad
-      phystep   = dtvr * FLOAT(iphysiq)
-      radpas    = NINT (86400./phystep/ FLOAT(nbapp_rad) )
-      write(*,*)'phystep =', phystep, radpas
-cIM : lecture de co2_ppm & solaire ds physiq.def
-c     co2_ppm   = 348.0
-c     solaire   = 1365.0
-
-c
-c Initialisation 
-c tsol, qsol, sn,albe, evap,tsoil,rain_fall, snow_fall,solsw, sollw,frugs
-c
-      ftsol(:,is_ter) = tsol
-      ftsol(:,is_lic) = tsol
-      ftsol(:,is_oce) = tsol
-      ftsol(:,is_sic) = tsol
-      snsrf(:,is_ter) = sn
-      snsrf(:,is_lic) = sn
-      snsrf(:,is_oce) = sn
-      snsrf(:,is_sic) = sn
-      falb1(:,is_ter) = 0.08
-      falb1(:,is_lic) = 0.6
-      falb1(:,is_oce) = 0.5
-      falb1(:,is_sic) = 0.6
-      falb2 = falb1
-      evap(:,:) = 0.
-      qsolsrf(:,is_ter) = 150
-      qsolsrf(:,is_lic) = 150
-      qsolsrf(:,is_oce) = 150.
-      qsolsrf(:,is_sic) = 150.
-      do i = 1, nbsrf
-        do j = 1, nsoilmx
-          tsoil(:,j,i) = tsol
-        enddo
-      enddo
-      rain_fall = 0.; snow_fall = 0.
-      solsw = 165.
-      sollw = -53.
-      t_ancien = 273.15
-      q_ancien = 0.
-      agesno = 0.
-c
-      frugs(1:klon,is_oce) = rugmer(1:klon)
-      frugs(1:klon,is_ter) = MAX(1.0e-05, zstd(1:klon)*zsig(1:klon)/2.0)
-      frugs(1:klon,is_lic) = MAX(1.0e-05, zstd(1:klon)*zsig(1:klon)/2.0)
-      frugs(1:klon,is_sic) = 0.001
-      fder = 0.0
-      clwcon = 0.0
-      rnebcon = 0.0
-      ratqs = 0.0
-      run_off_lic_0 = 0.0 
-      rugoro = 0.0
-
-c
-c Avant l'appel a phyredem, on initialize les modules de surface
-c avec les valeurs qui vont etre ecrit dans startphy.nc
-c
-      dummy = 1.0
-      pbl_tke(:,:,:) = 1.e-8 
-      zmax0(:) = 40.
-      f0(:) = 1.e-5
-      ema_work1(:,:) = 0.
-      ema_work2(:,:) = 0.
-      wake_deltat(:,:) = 0.
-      wake_deltaq(:,:) = 0.
-      wake_s(:) = 0.
-      wake_cstar(:) = 0.
-      wake_fip(:) = 0.
-
-      call fonte_neige_init(run_off_lic_0)
-      call pbl_surface_init(qsol, fder, snsrf, qsolsrf,
-     $     evap, frugs, agesno, tsoil)
-
-      call phyredem("startphy.nc")
-
-
-
-C     Sortie Visu pour les champs dynamiques
-cc      if (1.eq.0 ) then
-cc      print*,'sortie visu'
-cc      time_step = 1.
-cc      t_ops = 2.
-cc      t_wrt = 2.
-cc      itau = 2.
-cc      visu_file='Etat0_visu.nc'
-cc      CALL initdynav(visu_file,dayref,anneeref,time_step,
-cc     .              t_ops, t_wrt, visuid)
-cc      CALL writedynav(visuid, itau,vvent ,
-cc     .                uvent,tpot,pk,phi,q3d,masse,psol,phis)
-cc      else
-         print*,'CCCCCCCCCCCCCCCCCC REACTIVER SORTIE VISU DANS ETAT0'
-cc      endif
-      print*,'entree histclo'
-      CALL histclo
-
-#endif 
-!#endif of #ifdef CPP_EARTH
-      RETURN
-      !
-      END SUBROUTINE etat0_netcdf
Index: LMDZ4/trunk/libf/dyn3d/etat0_netcdf.F90
===================================================================
--- LMDZ4/trunk/libf/dyn3d/etat0_netcdf.F90	(revision 1319)
+++ LMDZ4/trunk/libf/dyn3d/etat0_netcdf.F90	(revision 1319)
@@ -0,0 +1,506 @@
+!
+! $Id$
+!
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE etat0_netcdf(ib, masque, letat0)
+!
+!-------------------------------------------------------------------------------
+! Purpose: Creates initial states
+!-------------------------------------------------------------------------------
+! Note: This routine is designed to work for Earth
+!-------------------------------------------------------------------------------
+#ifdef CPP_EARTH
+  USE startvar
+  USE ioipsl
+  USE dimphy
+  USE infotrac
+  USE fonte_neige_mod
+  USE pbl_surface_mod
+  USE phys_state_var_mod
+  USE filtreg_mod
+  USE regr_lat_time_climoz_m, ONLY: regr_lat_time_climoz
+  USE conf_phys_m,            ONLY: conf_phys
+  USE netcdf, ONLY : NF90_OPEN, NF90_NOWRITE, NF90_CLOSE, NF90_NOERR
+#endif
+  IMPLICIT NONE
+!-------------------------------------------------------------------------------
+! Arguments:
+#include "dimensions.h"
+#include "paramet.h"
+#include "iniprint.h"
+  LOGICAL,                    INTENT(IN)    :: ib     ! barycentric interpolat.
+  REAL, DIMENSION(iip1,jjp1), INTENT(INOUT) :: masque ! land mask
+  LOGICAL,                    INTENT(IN)    :: letat0 ! F: masque only required
+#ifndef CPP_EARTH
+  WRITE(lunout,*)'limit_netcdf: Earth-specific routine, needs Earth physics'
+#else
+!-------------------------------------------------------------------------------
+! Local variables:
+#include "comgeom2.h"
+#include "comvert.h"
+#include "comconst.h"
+#include "indicesol.h"
+#include "dimsoil.h"
+#include "temps.h"
+  REAL,    DIMENSION(klon)                 :: tsol, qsol
+  REAL,    DIMENSION(klon)                 :: sn, rugmer, run_off_lic_0
+  REAL,    DIMENSION(iip1,jjp1)            :: orog, rugo, psol, phis
+  REAL,    DIMENSION(iip1,jjp1,llm+1)      :: p3d
+  REAL,    DIMENSION(iip1,jjp1,llm)        :: uvent, t3d, tpot, qsat, qd
+  REAL,    DIMENSION(iip1,jjm ,llm)        :: vvent
+  REAL,    DIMENSION(:,:,:,:), ALLOCATABLE :: q3d
+  REAL,    DIMENSION(klon,nbsrf)           :: qsolsrf, snsrf, evap
+  REAL,    DIMENSION(klon,nbsrf)           :: frugs, agesno
+  REAL,    DIMENSION(klon,nsoilmx,nbsrf)   :: tsoil
+
+!--- Local variables for sea-ice reading:
+  INTEGER                                  :: iml_lic, jml_lic, llm_tmp
+  INTEGER                                  :: ttm_tmp, iret, fid
+  INTEGER, DIMENSION(1)                    :: itaul
+  REAL,    DIMENSION(1)                    :: lev
+  REAL                                     :: date
+  REAL,    DIMENSION(:,:),   ALLOCATABLE   ::  lon_lic,  lat_lic, fraclic
+  REAL,    DIMENSION(:),     ALLOCATABLE   :: dlon_lic, dlat_lic
+  REAL,    DIMENSION(iip1,jjp1)            :: flic_tmp
+
+!--- Misc
+  CHARACTER(LEN=80)                        :: x, fmt
+  INTEGER                                  :: i, j, l, ji
+  REAL,    DIMENSION(iip1,jjp1,llm)        :: alpha, beta, pk, pls, y
+  REAL,    DIMENSION(ip1jmp1)              :: pks
+
+#include "comdissnew.h"
+#include "control.h"
+#include "serre.h"
+#include "clesphys.h"
+
+  REAL,    DIMENSION(iip1,jjp1,llm)        :: masse
+  INTEGER :: itau, iday
+  REAL    :: xpn, xps, time, phystep
+  REAL,    DIMENSION(iim)                  :: xppn, xpps
+  REAL,    DIMENSION(ip1jmp1,llm)          :: pbaru, phi, w
+  REAL,    DIMENSION(ip1jm  ,llm)          :: pbarv
+  REAL,    DIMENSION(klon)                 :: fder
+
+!--- Local variables for ocean mask reading:
+  INTEGER :: nid_o2a, iml_omask, jml_omask
+  LOGICAL :: couple=.FALSE.
+  REAL,    DIMENSION(:,:), ALLOCATABLE ::  lon_omask, lat_omask, ocemask, ocetmp
+  REAL,    DIMENSION(:),   ALLOCATABLE :: dlon_omask,dlat_omask
+  REAL,    DIMENSION(klon)             :: ocemask_fi
+  INTEGER, DIMENSION(klon-2)           :: isst
+  REAL,    DIMENSION(iim,jjp1)         :: zx_tmp_2d
+  REAL    :: dummy
+  LOGICAL :: ok_newmicro, ok_journe, ok_mensuel, ok_instan, ok_hf
+  LOGICAL :: ok_LES, ok_ade, ok_aie, aerosol_couple, new_aod
+  INTEGER :: iflag_radia, flag_aerosol
+  REAL    :: bl95_b0, bl95_b1, fact_cldcon, facttemps, ratqsbas, ratqshaut
+  REAL    :: tau_ratqs
+  INTEGER :: iflag_cldcon, iflag_ratqs, iflag_coupl, iflag_clos, iflag_wake
+  INTEGER :: iflag_thermals, nsplit_thermals
+  INTEGER :: iflag_thermals_ed, iflag_thermals_optflux
+  REAL    :: tau_thermals, solarlong0,  seuil_inversion
+  INTEGER :: read_climoz ! read ozone climatology
+!  Allowed values are 0, 1 and 2
+!     0: do not read an ozone climatology
+!     1: read a single ozone climatology that will be used day and night
+!     2: read two ozone climatologies, the average day and night
+!     climatology and the daylight climatology
+!-------------------------------------------------------------------------------
+!--- Constants
+  pi     = 4. * ATAN(1.)
+  rad    = 6371229.
+  daysec = 86400.
+  omeg   = 2.*pi/daysec
+  g      = 9.8
+  kappa  = 0.2857143
+  cpp    = 1004.70885
+  preff  = 101325.
+  pa     = 50000.
+  jmp1   = jjm + 1
+
+!--- CONSTRUCT A GRID
+  CALL conf_phys(  ok_journe, ok_mensuel, ok_instan, ok_hf, ok_LES,     &
+                   solarlong0,seuil_inversion,                          &
+                   fact_cldcon, facttemps,ok_newmicro,iflag_radia,      &
+                   iflag_cldcon,                                        &
+                   iflag_ratqs,ratqsbas,ratqshaut,tau_ratqs,            &
+                   ok_ade, ok_aie, aerosol_couple,                      &
+                   flag_aerosol, new_aod,                               &
+                   bl95_b0, bl95_b1,                                    &
+                   iflag_thermals,nsplit_thermals,tau_thermals,         &
+                   iflag_thermals_ed,iflag_thermals_optflux,            &
+                   iflag_coupl,iflag_clos,iflag_wake, read_climoz )
+
+! co2_ppm0 : initial value of atmospheric CO2 from .def file (co2_ppm value)
+  co2_ppm0 = co2_ppm
+
+  dtvr   = daysec/FLOAT(day_step)
+  WRITE(lunout,*)'dtvr',dtvr
+
+  CALL iniconst()
+  CALL inigeom()
+
+!--- Initializations for tracers
+  CALL infotrac_init
+  ALLOCATE(q3d(iip1,jjp1,llm,nqtot))
+
+  CALL inifilr()
+  CALL phys_state_var_init(read_climoz)
+
+  rlat(1) = ASIN(1.0)
+  DO j=2,jjm; rlat((j-2)*iim+2:(j-1)*iim+1)=rlatu(j);     END DO
+  rlat(klon) = - ASIN(1.0)
+  rlat(:)=rlat(:)*(180.0/pi)
+
+  rlon(1) = 0.0
+  DO j=2,jjm; rlon((j-2)*iim+2:(j-1)*iim+1)=rlonv(1:iim); END DO
+  rlon(klon) = 0.0
+  rlon(:)=rlon(:)*(180.0/pi)
+
+! For a coupled simulation, the ocean mask from ocean model is used to compute
+! the weights an to insure ocean fractions are the same for atmosphere and ocean
+! Otherwise, mask is created using Relief file.
+
+  WRITE(lunout,*)'Essai de lecture masque ocean'
+  iret = NF90_OPEN("o2a.nc", NF90_NOWRITE, nid_o2a)
+  IF(iret/=NF90_NOERR) THEN
+    WRITE(lunout,*)'ATTENTION!! pas de fichier o2a.nc trouve'
+    WRITE(lunout,*)'Run force'
+    x='masque'
+    masque(:,:)=0.0
+    CALL startget(x, iip1, jjp1, rlonv, rlatu, masque, 0.0, jjm, rlonu,    &
+                  rlatv, ib)
+    WRITE(lunout,*)'MASQUE construit : Masque'
+    WRITE(lunout,'(97I1)') nINT(masque)
+    CALL gr_dyn_fi(1, iip1, jjp1, klon, masque, zmasq)
+    WHERE(   zmasq(:)<EPSFRA) zmasq(:)=0.
+    WHERE(1.-zmasq(:)<EPSFRA) zmasq(:)=1.
+  ELSE
+    couple=.true.
+    iret=NF90_CLOSE(nid_o2a)
+    CALL flininfo("o2a.nc", iml_omask, jml_omask, llm_tmp, ttm_tmp, nid_o2a)
+    IF(iml_omask/=iim .OR.jml_omask/=jjp1) THEN
+      WRITE(lunout,*)'Dimensions non compatibles pour masque ocean'
+      WRITE(lunout,*)'iim = ',iim,' iml_omask = ',iml_omask
+      WRITE(lunout,*)'jjp1 = ',jjp1,' jml_omask = ',jml_omask
+      CALL abort_gcm('etat0_netcdf','Dimensions non compatibles pour masque oc&
+     &ean',1)
+    END IF
+    ALLOCATE(  ocemask(iml_omask,jml_omask),   ocetmp(iml_omask,jml_omask))
+    ALLOCATE(lon_omask(iml_omask,jml_omask),lat_omask(iml_omask,jml_omask))
+    ALLOCATE(dlon_omask(iml_omask),dlat_omask(jml_omask))
+    CALL flinopen("o2a.nc", .FALSE., iml_omask, jml_omask, llm_tmp,            &
+                   lon_omask, lat_omask, lev, ttm_tmp, itaul, date, dt, fid)
+    CALL flinget(fid,'OceMask',iml_omask,jml_omask,llm_tmp,ttm_tmp,1,1,ocetmp)
+    CALL flinclo(fid)
+    dlon_omask(:)=lon_omask(:,1)
+    dlat_omask(:)=lat_omask(1,:)
+    ocemask=ocetmp
+    IF(dlat_omask(1)<dlat_omask(jml_omask)) THEN
+      DO j=1,jml_omask
+        ocemask(:,j) = ocetmp(:,jml_omask-j+1)
+      END DO
+    END IF 
+    ALLOCATE(   ocemask(iml_omask,jml_omask),   ocetmp(iml_omask,jml_omask))
+    ALLOCATE( lon_omask(iml_omask,jml_omask),lat_omask(iml_omask,jml_omask))
+    ALLOCATE(dlon_omask(iml_omask),         dlat_omask(jml_omask))
+    CALL flinopen("o2a.nc", .FALSE., iml_omask, jml_omask, llm_tmp, lon_omask, &
+                  lat_omask, lev, ttm_tmp, itaul, date, dt, fid)
+    CALL flinget(fid, 'OceMask', iml_omask, jml_omask, llm_tmp, ttm_tmp,       &
+                  1, 1, ocetmp)
+    CALL flinclo(fid)
+    dlon_omask(1:iml_omask) = lon_omask(1:iml_omask,1)
+    dlat_omask(1:jml_omask) = lat_omask(1,1:jml_omask)
+    ocemask = ocetmp
+    IF(dlat_omask(1)<dlat_omask(jml_omask)) THEN
+      DO j=1,jml_omask
+        ocemask(:,j) = ocetmp(:,jml_omask-j+1)
+      END DO
+    END IF
+!
+! Ocean mask to physical grid
+!*******************************************************************************
+    WRITE(lunout,*)'ocemask '
+    WRITE(fmt,"(i4,'i1)')")iml_omask ; fmt='('//ADJUSTL(fmt)
+    WRITE(lunout,fmt)int(ocemask)
+    ocemask_fi(1)=ocemask(1,1)
+    DO j=2,jjm; ocemask_fi((j-2)*iim+1:iim+1)=ocemask(1:iim,j); END DO
+    ocemask_fi(klon)=ocemask(1,jjp1)
+    zmasq=1.-ocemask_fi
+  END IF
+
+  CALL gr_fi_dyn(1,klon,iip1,jjp1,zmasq,masque)
+
+  ! The startget calls need to be replaced by a call to restget to get the
+  ! values in the restart file
+  x = 'relief'; orog(:,:) = 0.0
+  CALL startget(x,iip1,jjp1,rlonv,rlatu,          orog, 0.0,jjm,rlonu,rlatv,ib,&
+                masque)
+
+  x = 'rugosite'; rugo(:,:) = 0.0
+  CALL startget(x,iip1,jjp1,rlonv,rlatu,          rugo, 0.0,jjm, rlonu,rlatv,ib)
+!  WRITE(lunout,'(49I1)') INT(orog(:,:)*10)
+!  WRITE(lunout,'(49I1)') INT(rugo(:,:)*10)
+
+! Sub-surfaces initialization
+!*******************************************************************************
+  pctsrf=0.
+  x = 'psol'; psol(:,:) = 0.0
+  CALL startget(x,iip1,jjp1,rlonv,rlatu,psol,0.0,jjm,rlonu,rlatv,ib)
+!  WRITE(lunout,*) 'PSOL :', psol(10,20)
+!  WRITE(lunout,*) ap(:), bp(:)
+
+! Mid-levels pressure computation
+!*******************************************************************************
+  CALL pression(ip1jmp1, ap, bp, psol, p3d)
+  CALL exner_hyb(ip1jmp1, psol, p3d, alpha, beta, pks, pk, y)
+  pls(:,:,:)=preff*(pk(:,:,:)/cpp)**(1./kappa)
+!  WRITE(lunout,*) 'P3D :', p3d(10,20,:)
+!  WRITE(lunout,*) 'PK:',    pk(10,20,:)
+!  WRITE(lunout,*) 'PLS :', pls(10,20,:)
+
+  x = 'surfgeo'; phis(:,:) = 0.0
+  CALL startget(x,iip1,jjp1,rlonv,rlatu,          phis, 0.0,jjm, rlonu,rlatv,ib)
+
+  x = 'u';    uvent(:,:,:) = 0.0
+  CALL startget(x,iip1,jjp1,rlonu,rlatu,llm,pls,y,uvent,0.0,jjm, rlonv,rlatv,ib)
+
+  x = 'v';    vvent(:,:,:) = 0.0
+  CALL startget(x,iip1,jjm, rlonv,rlatv,llm,pls,y,vvent,0.0,jjp1,rlonu,rlatu,ib)
+
+  x = 't';    t3d(:,:,:) = 0.0
+  CALL startget(x,iip1,jjp1,rlonv,rlatu,llm,pls,y,t3d,  0.0,jjm, rlonu,rlatv,ib)
+
+  x = 'tpot'; tpot(:,:,:) = 0.0
+  CALL startget(x,iip1,jjp1,rlonv,rlatu,llm,pls,pk,tpot,0.0,jjm, rlonu,rlatv,ib)
+
+  WRITE(lunout,*) 'T3D min,max:',minval(t3d(:,:,:)),maxval(t3d(:,:,:))
+  WRITE(lunout,*) 'PLS min,max:',minval(pls(:,:,:)),maxval(pls(:,:,:))
+
+! Humidity at saturation computation
+!*******************************************************************************
+  WRITE(lunout,*) 'avant q_sat'
+  CALL q_sat(llm*jjp1*iip1, t3d, pls, qsat)
+  WRITE(lunout,*) 'apres q_sat'
+  WRITE(lunout,*) 'QSAT min,max:',minval(qsat(:,:,:)),maxval(qsat(:,:,:))
+!  WRITE(lunout,*) 'QSAT :',qsat(10,20,:)
+
+  x = 'q';    qd (:,:,:) = 0.0
+  CALL startget(x,iip1,jjp1,rlonv,rlatu,llm,pls,qsat,qd,0.0,jjm, rlonu,rlatv,ib)
+  q3d(:,:,:,:) = 0.0 ; q3d(:,:,:,1) = qd(:,:,:)
+
+!--- OZONE CLIMATOLOGY
+  IF(read_climoz>=1) CALL regr_lat_time_climoz(read_climoz)
+
+  x = 'tsol'; tsol(:) = 0.0
+  CALL startget(x,iip1,jjp1,rlonv,rlatu,klon,tsol,  0.0,jjm,rlonu,rlatv,ib)
+
+  x = 'qsol';  qsol(:) = 0.0
+  CALL startget(x,iip1,jjp1,rlonv,rlatu,klon,qsol,  0.0,jjm,rlonu,rlatv,ib)
+
+  x = 'snow';  sn(:) = 0.0
+  CALL startget(x,iip1,jjp1,rlonv,rlatu,klon,sn,    0.0,jjm,rlonu,rlatv,ib)
+
+  x = 'rads';  radsol(:) = 0.0
+  CALL startget(x,iip1,jjp1,rlonv,rlatu,klon,radsol,0.0,jjm,rlonu,rlatv,ib)
+
+  x = 'rugmer'; rugmer(:) = 0.0
+  CALL startget(x,iip1,jjp1,rlonv,rlatu,klon,rugmer,0.0,jjm,rlonu,rlatv,ib)
+
+  x = 'zmea';  zmea(:) = 0.0
+  CALL startget(x,iip1,jjp1,rlonv,rlatu,klon,zmea,  0.0,jjm,rlonu,rlatv,ib)
+
+  x = 'zstd';  zstd(:) = 0.0
+  CALL startget(x,iip1,jjp1,rlonv,rlatu,klon,zstd,  0.0,jjm,rlonu,rlatv,ib)
+
+  x = 'zsig';  zsig(:) = 0.0
+  CALL startget(x,iip1,jjp1,rlonv,rlatu,klon,zsig,  0.0,jjm,rlonu,rlatv,ib)
+
+  x = 'zgam';  zgam(:) = 0.0
+  CALL startget(x,iip1,jjp1,rlonv,rlatu,klon,zgam,  0.0,jjm,rlonu,rlatv,ib)
+
+  x = 'zthe';  zthe(:) = 0.0
+  CALL startget(x,iip1,jjp1,rlonv,rlatu,klon,zthe,  0.0,jjm,rlonu,rlatv,ib)
+
+  x = 'zpic';  zpic(:) = 0.0
+  CALL startget(x,iip1,jjp1,rlonv,rlatu,klon,zpic,  0.0,jjm,rlonu,rlatv,ib)
+
+  x = 'zval';  zval(:) = 0.0
+  CALL startget(x,iip1,jjp1,rlonv,rlatu,klon,zval,  0.0,jjm,rlonu,rlatv,ib)
+
+!  WRITE(lunout,'(48I3)') 'TSOL :', INT(tsol(2:klon)-273)
+
+! Soil ice file reading for soil fraction and soil ice fraction
+!*******************************************************************************
+  CALL flininfo("landiceref.nc", iml_lic, jml_lic, llm_tmp, ttm_tmp, fid)
+  ALLOCATE( lat_lic(iml_lic,jml_lic),lon_lic(iml_lic, jml_lic))
+  ALLOCATE(dlat_lic(jml_lic),       dlon_lic(iml_lic))
+  ALLOCATE( fraclic(iml_lic,jml_lic))
+  CALL flinopen("landiceref.nc", .FALSE., iml_lic, jml_lic, llm_tmp,           &
+                lon_lic, lat_lic, lev, ttm_tmp, itaul, date, dt, fid)
+  CALL flinget(fid, 'landice', iml_lic, jml_lic, llm_tmp, ttm_tmp, 1,1, fraclic)
+  CALL flinclo(fid)
+
+! Interpolation on model T-grid
+!*******************************************************************************
+  WRITE(lunout,*)'dimensions de landice iml_lic, jml_lic : ',iml_lic,jml_lic
+! conversion if coordinates are in degrees
+  IF(MAXVAL(lon_lic)>pi) lon_lic=lon_lic*pi/180.
+  IF(MAXVAL(lat_lic)>pi) lat_lic=lat_lic*pi/180.
+  dlon_lic(:)=lon_lic(:,1)
+  dlat_lic(:)=lat_lic(1,:)
+  CALL grille_m( iml_lic, jml_lic, dlon_lic, dlat_lic, fraclic, iim,jjp1,      &
+                 rlonv, rlatu, flic_tmp(1:iim,:) )
+  flic_tmp(iip1,:)=flic_tmp(1,:)
+
+!--- To the physical grid
+  CALL gr_dyn_fi(1, iip1, jjp1, klon, flic_tmp, pctsrf(:,is_lic))
+
+!--- Adequation with soil/sea mask
+  WHERE(pctsrf(:,is_lic)<EPSFRA) pctsrf(:,is_lic)=0. 
+  WHERE(zmasq(:)<EPSFRA)         pctsrf(:,is_lic)=0.
+  pctsrf(:,is_ter)=zmasq(:)
+  DO ji=1,klon
+    IF(zmasq(ji)>EPSFRA) THEN 
+      IF(pctsrf(ji,is_lic)>=zmasq(ji)) THEN
+        pctsrf(ji,is_lic)=zmasq(ji)
+        pctsrf(ji,is_ter)=0.
+      ELSE
+        pctsrf(ji,is_ter)=zmasq(ji)-pctsrf(ji,is_lic)
+        IF(pctsrf(ji,is_ter)<EPSFRA) THEN
+          pctsrf(ji,is_ter)=0.
+          pctsrf(ji,is_lic)=zmasq(ji)
+        END IF 
+      END IF 
+    END IF 
+  END DO 
+
+! sub-surface ocean and sea ice (sea ice set to zero for start)
+!*******************************************************************************
+  pctsrf(:,is_oce)=(1.-zmasq(:))
+  WHERE(pctsrf(:,is_oce)<EPSFRA) pctsrf(:,is_oce)=0.
+  IF(couple) pctsrf(:,is_oce)=ocemask_fi(:)
+  isst=0
+  WHERE(pctsrf(2:klon-1,is_oce)>0.) isst=1
+
+! It is checked that the sub-surfaces sum is equal to 1
+!*******************************************************************************
+  ji=COUNT((ABS(SUM(pctsrf(:,:),dim=2))-1.0)>EPSFRA)
+  IF(ji/=0) WRITE(lunout,*) 'pb repartition sous maille pour ',ji,' points'
+  CALL gr_fi_ecrit(1, klon, iim, jjp1, zmasq, zx_tmp_2d)
+!  WRITE(fmt,"(i3,')')")iim; fmt='(i'//ADJUSTL(fmt)
+!  WRITE(lunout,*)'zmasq = '
+!  WRITE(lunout,TRIM(fmt))NINT(zx_tmp_2d)
+  CALL gr_fi_dyn(1, klon, iip1, jjp1, zmasq, masque)
+  WRITE(fmt,"(i4,'i1)')")iip1 ; fmt='('//ADJUSTL(fmt)
+  WRITE(lunout,*) 'MASQUE construit : Masque'
+  WRITE(lunout,TRIM(fmt))NINT(masque(:,:))
+
+! Intermediate computation
+!*******************************************************************************
+  CALL massdair(p3d,masse)
+  WRITE(lunout,*)' ALPHAX ',alphax
+  DO l=1,llm
+    xppn(:)=aire(1:iim,1   )*masse(1:iim,1   ,l)
+    xpps(:)=aire(1:iim,jjp1)*masse(1:iim,jjp1,l)
+    xpn=SUM(xppn)/apoln
+    xps=SUM(xpps)/apols
+    masse(:,1   ,l)=xpn
+    masse(:,jjp1,l)=xps
+  END DO
+  q3d(iip1,:,:,:)=q3d(1,:,:,:)
+  phis(iip1,:) = phis(1,:)
+
+  IF(.NOT.letat0) RETURN
+
+! Writing
+!*******************************************************************************
+  CALL inidissip(lstardis,nitergdiv,nitergrot,niterh,tetagdiv,tetagrot,tetatemp)
+  WRITE(lunout,*)'sortie inidissip'
+  itau=0
+  itau_dyn=0
+  itau_phy=0
+  iday=dayref+itau/day_step
+  time=FLOAT(itau-(iday-dayref)*day_step)/day_step
+  IF(time>1.) THEN
+   time=time-1
+   iday=iday+1
+  END IF
+  day_ref=dayref
+  annee_ref=anneeref
+
+  CALL geopot( ip1jmp1, tpot, pk, pks, phis, phi )
+  WRITE(lunout,*)'sortie geopot'
+
+  CALL caldyn0( itau, uvent, vvent, tpot, psol, masse, pk, phis,               &
+                phi,  w, pbaru, pbarv, time+iday-dayref)
+  WRITE(lunout,*)'sortie caldyn0'     
+  CALL dynredem0( "start.nc", dayref, phis)
+  WRITE(lunout,*)'sortie dynredem0'
+  CALL dynredem1( "start.nc", 0.0, vvent, uvent, tpot, q3d, masse, psol)
+  WRITE(lunout,*)'sortie dynredem1' 
+
+! Physical initial state writting
+!*******************************************************************************
+  WRITE(lunout,*)'phystep ',dtvr,iphysiq,nbapp_rad
+  phystep   = dtvr * FLOAT(iphysiq)
+  radpas    = NINT (86400./phystep/ FLOAT(nbapp_rad) )
+  WRITE(lunout,*)'phystep =', phystep, radpas
+
+! Init: tsol, qsol, sn, evap, tsoil, rain_fall, snow_fall, solsw, sollw, frugs
+!*******************************************************************************
+  DO i=1,nbsrf; ftsol(:,i) = tsol; END DO
+  DO i=1,nbsrf; snsrf(:,i) = sn;   END DO
+  falb1(:,is_ter) = 0.08; falb1(:,is_lic) = 0.6
+  falb1(:,is_oce) = 0.5;  falb1(:,is_sic) = 0.6
+  falb2 = falb1
+  evap(:,:) = 0.
+  DO i=1,nbsrf; qsolsrf(:,i)=150.; END DO
+  DO i=1,nbsrf; DO j=1,nsoilmx; tsoil(:,j,i) = tsol; END DO; END DO
+  rain_fall = 0.; snow_fall = 0.
+  solsw = 165.;   sollw = -53.
+  t_ancien = 273.15
+  q_ancien = 0.
+  agesno = 0.
+  frugs(:,is_oce) = rugmer(:)
+  frugs(:,is_ter) = MAX(1.0e-05,zstd(:)*zsig(:)/2.0)
+  frugs(:,is_lic) = MAX(1.0e-05,zstd(:)*zsig(:)/2.0)
+  frugs(:,is_sic) = 0.001
+  fder = 0.0
+  clwcon = 0.0
+  rnebcon = 0.0
+  ratqs = 0.0
+  run_off_lic_0 = 0.0 
+  rugoro = 0.0
+
+! Before phyredem calling, surface modules and values to be saved in startphy.nc
+! are initialized
+!*******************************************************************************
+  dummy = 1.0
+  pbl_tke(:,:,:) = 1.e-8 
+  zmax0(:) = 40.
+  f0(:) = 1.e-5
+  ema_work1(:,:) = 0.
+  ema_work2(:,:) = 0.
+  wake_deltat(:,:) = 0.
+  wake_deltaq(:,:) = 0.
+  wake_s(:) = 0.
+  wake_cstar(:) = 0.
+  wake_fip(:) = 0.
+  CALL fonte_neige_init(run_off_lic_0)
+  CALL pbl_surface_init( qsol, fder, snsrf, qsolsrf, evap, frugs, agesno, tsoil )
+  CALL phyredem( "startphy.nc" )
+
+  WRITE(lunout,*)'CCCCCCCCCCCCCCCCCC REACTIVER SORTIE VISU DANS ETAT0'
+  WRITE(lunout,*)'entree histclo'
+  CALL histclo()
+
+#endif 
+!#endif of #ifdef CPP_EARTH
+  RETURN
+
+END SUBROUTINE etat0_netcdf
+!
+!-------------------------------------------------------------------------------
Index: LMDZ4/trunk/libf/dyn3d/limit_netcdf.F
===================================================================
--- LMDZ4/trunk/libf/dyn3d/limit_netcdf.F	(revision 1318)
+++ 	(revision )
@@ -1,1334 +1,0 @@
-!
-! $Id$
-!
-C
-C
-      SUBROUTINE limit_netcdf(interbar, extrap, oldice, masque)
-#ifdef CPP_EARTH
-! This routine is designed to work for Earth
-      USE dimphy
-      use phys_state_var_mod , ONLY : pctsrf
-      IMPLICIT none
-c
-c-------------------------------------------------------------
-C Author : L. Fairhead
-C Date   : 27/01/94
-C Objet  : Construction des fichiers de conditions aux limites
-C          pour le nouveau
-C          modele a partir de fichiers de climatologie. Les deux
-C          grilles doivent etre regulieres
-c
-c Modifie par z.x.li (le23mars1994)
-c Modifie par L. Fairhead (fairhead@lmd.jussieu.fr) septembre 1999
-c                         pour lecture netcdf dans LMDZ.3.3
-c Modifie par P;Le Van  ,  juillet 2001
-c-------------------------------------------------------------
-c
-#include "dimensions.h"
-#include "paramet.h"
-#include "control.h"
-#include "logic.h"
-#include "netcdf.inc"
-#include "comvert.h"
-#include "comgeom2.h"
-#include "comconst.h"
-cy#include "dimphy.h"
-#include "indicesol.h"
-#include "iniprint.h"
-c
-c-----------------------------------------------------------------------
-      LOGICAL interbar, extrap, oldice
-
-      REAL phy_nat(klon,360), phy_nat0(klon)
-      REAL phy_alb(klon,360)
-      REAL phy_sst(klon,360)
-      REAL phy_bil(klon,360)
-      REAL phy_rug(klon,360)
-      REAL phy_ice(klon)
-c
-      real pctsrf_t(klon,nbsrf,360)
-
-      REAL verif
-
-      REAL masque(iip1,jjp1)
-      REAL mask(iim,jjp1)
-CPB
-C newlmt indique l'utilisation de la sous-maille fractionnelle
-C tandis que l'ancien codage utilise l'indicateur du sol (0,1,2,3)
-      LOGICAL newlmt, fracterre
-      PARAMETER(newlmt=.TRUE.)
-      PARAMETER(fracterre = .TRUE.) 
-
-C Declarations pour le champ de depart
-      INTEGER imdep, jmdep,lmdep
-      INTEGER  tbid
-      PARAMETER ( tbid = 60 )        ! >52 semaines
-      REAL  timecoord(tbid)
-c
-      REAL , ALLOCATABLE :: dlon_msk(:), dlat_msk(:)
-      REAL , ALLOCATABLE :: lonmsk_ini(:), latmsk_ini(:)
-      REAL , ALLOCATABLE :: dlon(:), dlat(:)
-      REAL , ALLOCATABLE :: dlon_ini(:), dlat_ini(:)
-      REAL , ALLOCATABLE :: champ_msk(:), champ(:)
-      REAL , ALLOCATABLE :: work(:,:)
-
-      CHARACTER*25 title
-
-C Declarations pour le champ interpole 2D
-      REAL champint(iim,jjp1)
-      real chmin,chmax
-
-C Declarations pour le champ interpole 3D
-      REAL champtime(iim,jjp1,tbid)
-      REAL timeyear(tbid)
-      REAL champan(iip1,jjp1,366)
-
-C Declarations pour l'inteprolation verticale
-      REAL ax(tbid), ay(tbid)
-      REAL by
-      REAL yder(tbid)
-
-
-      INTEGER ierr
-      INTEGER dimfirst(3)
-      INTEGER dimlast(3)
-c
-      INTEGER nid, ndim, ntim
-      INTEGER dims(2), debut(2), epais(2)
-      INTEGER id_tim
-      INTEGER id_NAT, id_SST, id_BILS, id_RUG, id_ALB
-CPB
-      INTEGER id_FOCE, id_FSIC, id_FTER, id_FLIC
-
-      INTEGER i, j, k, l, ji
-c declarations pour lecture glace de mer
-      INTEGER :: iml_lic, jml_lic, llm_tmp, ttm_tmp, iret
-      INTEGER :: itaul(1), fid
-      REAL :: lev(1), date, dt
-      REAL, ALLOCATABLE, DIMENSION(:,:) :: lon_lic, lat_lic
-      REAL, ALLOCATABLE, DIMENSION(:)  :: dlon_lic, dlat_lic
-      REAL, ALLOCATABLE, DIMENSION (:,:) :: fraclic
-      REAL :: flic_tmp(iip1, jjp1)
-
-c Diverses variables locales
-      REAL time
-! pour la lecture du fichier masque ocean
-      integer :: nid_o2a
-      logical :: couple = .false.
-      INTEGER :: iml_omask, jml_omask
-      REAL, ALLOCATABLE, DIMENSION(:,:) :: lon_omask, lat_omask
-      REAL, ALLOCATABLE, DIMENSION(:)  :: dlon_omask, dlat_omask
-      REAL, ALLOCATABLE, DIMENSION (:,:) :: ocemask, ocetmp
-      real, dimension(klon) :: ocemask_fi
-
-      INTEGER          longcles
-      PARAMETER      ( longcles = 20 )
-      REAL  clesphy0 ( longcles      )
-#include "serre.h"
-      INTEGER ncid,varid,ndimid(4),dimid
-      character*30 namedim
-      CHARACTER*80 :: varname
-
-cIM28/02/2002 <== PM
-      REAL tmidmonth(12)
-      SAVE tmidmonth
-      DATA tmidmonth/15,45,75,105,135,165,195,225,255,285,315,345/
-
-c initialisations:
-      CALL conf_gcm( 99, .TRUE. , clesphy0 )
-
-
-      pi     = 4. * ATAN(1.)
-      rad    = 6 371 229.
-      omeg   = 4.* ASIN(1.)/(24.*3600.)
-      g      = 9.8
-      daysec = 86400.
-      kappa  = 0.2857143
-      cpp    = 1004.70885
-      dtvr    = daysec/FLOAT(day_step)
-      CALL inigeom
-c
-C Traitement du relief au sol
-c
-      write(*,*) 'Traitement du relief au sol pour fabriquer masque'
-      ierr = NF_OPEN('Relief.nc', NF_NOWRITE, ncid)
-
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF
-
-      ierr = NF_INQ_VARID(ncid,'RELIEF',varid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF
-      ierr = NF_INQ_VARDIMID (ncid,varid,ndimid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF
-      ierr = NF_INQ_DIM(ncid,ndimid(1), namedim, imdep)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF
-      print*,'variable ', namedim, 'dimension ', imdep
-      ierr = NF_INQ_VARID(ncid,namedim,dimid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF
-
-      ALLOCATE( lonmsk_ini(imdep) )
-      ALLOCATE(   dlon_msk(imdep) )
-
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(ncid,dimid,lonmsk_ini)
-#else
-      ierr = NF_GET_VAR_REAL(ncid,dimid,lonmsk_ini)
-#endif
-
-c
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF
-      ierr = NF_INQ_DIM(ncid,ndimid(2), namedim, jmdep)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF
-      print*,'variable ', namedim, 'dimension ', jmdep
-      ierr = NF_INQ_VARID(ncid,namedim,dimid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF
-
-      ALLOCATE( latmsk_ini(jmdep) )
-      ALLOCATE(   dlat_msk(jmdep) )
-      ALLOCATE(  champ_msk(imdep*jmdep) )
-
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(ncid,dimid,latmsk_ini)
-#else
-      ierr = NF_GET_VAR_REAL(ncid,dimid,latmsk_ini)
-#endif
-c
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(ncid,varid,champ_msk)
-#else
-      ierr = NF_GET_VAR_REAL(ncid,varid,champ_msk)
-#endif
-c
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF
-c
-      title='RELIEF'
-
-      CALL conf_dat2d(title,imdep, jmdep, lonmsk_ini, latmsk_ini,
-     . dlon_msk, dlat_msk, champ_msk, interbar  )
-
-      DO i = 1, iim
-      DO j = 1, jjp1
-         mask(i,j) = masque(i,j)
-      ENDDO
-      ENDDO
-      WRITE(*,*) 'MASK:'
-      WRITE(*,'(96i1)')INT(mask)     
-      ierr = NF_CLOSE(ncid)
-c
-c
-C Traitement de la rugosite
-c
-      PRINT*, 'Traitement de la rugosite'
-      ierr = NF_OPEN('Rugos.nc', NF_NOWRITE, ncid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF
-
-      ierr = NF_INQ_VARID(ncid,'RUGOS',varid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF
-      ierr = NF_INQ_VARDIMID (ncid,varid,ndimid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      ierr = NF_INQ_DIM(ncid,ndimid(1), namedim, imdep)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      print*,'variable ', namedim, 'dimension ', imdep
-      ierr = NF_INQ_VARID(ncid,namedim,dimid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-
-      ALLOCATE( dlon_ini(imdep) )
-      ALLOCATE(     dlon(imdep) )
-
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(ncid,dimid,dlon_ini)
-#else
-      ierr = NF_GET_VAR_REAL(ncid,dimid,dlon_ini)
-#endif
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      ierr = NF_INQ_DIM(ncid,ndimid(2), namedim, jmdep)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      print*,'variable ', namedim, 'dimension ', jmdep
-      ierr = NF_INQ_VARID(ncid,namedim,dimid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-
-      ALLOCATE( dlat_ini(jmdep) )
-      ALLOCATE(     dlat(jmdep) )
-
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(ncid,dimid,dlat_ini)
-#else
-      ierr = NF_GET_VAR_REAL(ncid,dimid,dlat_ini)
-#endif
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      ierr = NF_INQ_DIM(ncid,ndimid(3), namedim, lmdep)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF
-      print*,'variable ', namedim, 'dimension ', lmdep
-      ierr = NF_INQ_VARID(ncid,namedim,dimid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(ncid,dimid,timecoord)
-#else
-      ierr = NF_GET_VAR_REAL(ncid,dimid,timecoord)
-#endif
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF
-c
-      ALLOCATE( champ(imdep*jmdep) )
-
-      DO  200 l = 1, lmdep
-         dimfirst(1) = 1
-         dimfirst(2) = 1
-         dimfirst(3) = l
-c
-         dimlast(1) = imdep
-         dimlast(2) = jmdep
-         dimlast(3) = 1
-c
-         PRINT*,'Lecture temporelle et int. horizontale ',l,timecoord(l)
-         print*,dimfirst,dimlast
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VARA_DOUBLE(ncid,varid,dimfirst,dimlast,champ)
-#else
-         ierr = NF_GET_VARA_REAL(ncid,varid,dimfirst,dimlast,champ)
-#endif
-         if (ierr.ne.0) then
-           print *, NF_STRERROR(ierr)
-           STOP
-         ENDIF 
-   
-        title = 'Rugosite Amip '
-c
-        CALL conf_dat2d(title,imdep, jmdep, dlon_ini, dlat_ini,
-     .                      dlon, dlat, champ, interbar          )
-
-       IF ( interbar )   THEN
-         DO j = 1, imdep * jmdep
-           champ(j) = LOG(champ(j))
-         ENDDO
-
-        IF( l.EQ.1 )  THEN
-         WRITE(6,*) '-------------------------------------------------',
-     ,'------------------------'
-         WRITE(6,*) '$$$ Utilisation de l interpolation barycentrique ',
-     , ' pour la rugosite $$$ '
-         WRITE(6,*) '-------------------------------------------------',
-     ,'------------------------'
-        ENDIF
-        CALL inter_barxy ( imdep,jmdep -1,dlon,dlat,champ ,
-     ,                  iim,jjm,rlonu,rlatv, jjp1,champint )
-         DO j=1,jjp1
-          DO i=1,iim
-           champint(i,j)=EXP(champint(i,j))
-          ENDDO
-         ENDDO
-
-         DO j = 1, jjp1
-           DO i = 1, iim
-             IF(NINT(mask(i,j)).NE.1)  THEN
-               champint( i,j ) = 0.001
-             ENDIF
-           ENDDO
-         ENDDO
-      ELSE
-         CALL rugosite(imdep, jmdep, dlon, dlat, champ,
-     .             iim, jjp1, rlonv, rlatu, champint, mask)
-      ENDIF
-         DO j = 1,jjp1
-         DO i = 1, iim
-            champtime (i,j,l) = champint(i,j)
-         ENDDO
-         ENDDO
-200      CONTINUE
-c
-      DO l = 1, lmdep
-         timeyear(l) = timecoord(l)
-      ENDDO
-
-      PRINT 222, timeyear(:lmdep)
-222   FORMAT(2x,' Time year ',10f6.1)
-c
-        
-      PRINT*, 'Interpolation temporelle dans l annee'
-
-      DO j = 1, jjp1
-      DO i = 1, iim
-          DO l = 1, lmdep
-            ax(l) = timeyear(l)
-            ay(l) = champtime (i,j,l)
-          ENDDO
-          CALL SPLINE(ax,ay,lmdep,1.e30,1.e30,yder)
-          DO k = 1, 360
-            time = FLOAT(k-1)
-            CALL SPLINT(ax,ay,yder,lmdep,time,by)
-            champan(i,j,k) = by
-          ENDDO
-      ENDDO
-      ENDDO
-      DO k = 1, 360
-      DO j = 1, jjp1
-         champan(iip1,j,k) = champan(1,j,k)
-      ENDDO
-        IF ( k.EQ.10 )  THEN
-          DO j = 1, jjp1
-            CALL minmax( iip1,champan(1,j,10),chmin,chmax )
-            PRINT *,' Rugosite au temps 10 ', chmin,chmax,j
-          ENDDO
-        ENDIF
-      ENDDO
-c
-      DO k = 1, 360
-         CALL gr_dyn_fi(1,iip1,jjp1,klon,champan(1,1,k), phy_rug(1,k))
-      ENDDO
-c
-      ierr = NF_CLOSE(ncid)
-
-       DEALLOCATE( dlon      )
-       DEALLOCATE( dlon_ini  )
-       DEALLOCATE( dlat      )
-       DEALLOCATE( dlat_ini  )
-       DEALLOCATE( champ     )
-c
-c
-C Traitement de la glace oceanique
-c
-      PRINT*, 'Traitement de la glace oceanique'
-
-      ierr = NF_OPEN('amipbc_sic_1x1.nc', NF_NOWRITE, ncid)
-      if (ierr.ne.0) THEN
-        ierr = NF_OPEN('amipbc_sic_1x1_clim.nc', NF_NOWRITE, ncid)
-        if (ierr.ne.0) THEN
-          print *, NF_STRERROR(ierr)
-          STOP
-        endif
-      ENDIF
-
-cIM22/02/2002
-cIM07/03/2002 AMIP.nc & amip79to95.nc
-cIM   ierr = NF_INQ_VARID(ncid,'SEA_ICE',varid)
-cIM07/03/2002 amipbc_sic_1x1_clim.nc & amipbc_sic_1x1.nc
-      ierr = NF_INQ_VARID(ncid,'sicbcs',varid)
-cIM22/02/2002
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr),'sicbcs'
-        STOP
-      ENDIF
-      ierr = NF_INQ_VARDIMID (ncid,varid,ndimid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      ierr = NF_INQ_DIM(ncid,ndimid(1), namedim, imdep)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      print*,'variable ', namedim, 'dimension ', imdep
-      ierr = NF_INQ_VARID(ncid,namedim,dimid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-
-      ALLOCATE ( dlon_ini(imdep) )
-      ALLOCATE (     dlon(imdep) )
-
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(ncid,dimid,dlon_ini)
-#else
-      ierr = NF_GET_VAR_REAL(ncid,dimid,dlon_ini)
-#endif
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      ierr = NF_INQ_DIM(ncid,ndimid(2), namedim, jmdep)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      print*,'variable ', namedim, jmdep
-      ierr = NF_INQ_VARID(ncid,namedim,dimid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-
-      ALLOCATE ( dlat_ini(jmdep) )
-      ALLOCATE (     dlat(jmdep) )
-
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(ncid,dimid,dlat_ini)
-#else
-      ierr = NF_GET_VAR_REAL(ncid,dimid,dlat_ini)
-#endif
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      ierr = NF_INQ_DIM(ncid,ndimid(3), namedim, lmdep)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      print*,'variable ', namedim, lmdep
-cIM28/02/2002
-cPM28/02/2002 : nouvelle coord temporelle fichiers AMIP pas en jours
-c               Ici on suppose qu'on a 12 mois (de 30 jours).
-      IF (lmdep.NE.12) THEN
-          print *, 'Unknown AMIP file: not 12 months ?'
-          STOP
-       ENDIF
-cIM28/02/2002
-      ierr = NF_INQ_VARID(ncid,namedim,dimid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(ncid,dimid,timecoord)
-#else
-      ierr = NF_GET_VAR_REAL(ncid,dimid,timecoord)
-#endif
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-c
-      ALLOCATE ( champ(imdep*jmdep) )
-
-      DO l = 1, lmdep
-         dimfirst(1) = 1
-         dimfirst(2) = 1
-         dimfirst(3) = l
-c
-         dimlast(1) = imdep
-         dimlast(2) = jmdep
-         dimlast(3) = 1
-c
-         PRINT*,'Lecture temporelle et int. horizontale ',l,timecoord(l)
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VARA_DOUBLE(ncid,varid,dimfirst,dimlast,champ)
-#else
-         ierr = NF_GET_VARA_REAL(ncid,varid,dimfirst,dimlast,champ)
-#endif
-         if (ierr.ne.0) then
-           print *, NF_STRERROR(ierr)
-           STOP
-         ENDIF
- 
-         title = 'Sea-ice Amip '
-c
-         CALL conf_dat2d(title,imdep, jmdep, dlon_ini, dlat_ini,
-     .                        dlon, dlat, champ, interbar          )
-c
-      IF( oldice )  THEN
-                 CALL sea_ice(imdep, jmdep, dlon, dlat, champ,
-     .             iim, jjp1, rlonv, rlatu, champint )
-      ELSEIF ( interbar )  THEN
-       IF( l.EQ.1 )  THEN
-        WRITE(6,*) '-------------------------------------------------',
-     ,'------------------------'
-        WRITE(6,*) '$$$ Utilisation de l interpolation barycentrique ',
-     , ' pour Sea-ice Amip  $$$ '
-        WRITE(6,*) '-------------------------------------------------',
-     ,'------------------------'
-       ENDIF
-cIM07/03/2002 
-cIM22/02/2002 : Sea-ice Amip entre 0. et 1.
-cIM    PRINT*,'SUB. limit_netcdf.F IM : Sea-ice et SST Amip_new clim' 
-cIM   DO j = 1, imdep * jmdep
-cIM28/02/2002 <==PM         champ(j) = champ(j)/100.
-cIM14/03/2002      champ(j) = max(0.0,(min(1.0, (champ(j)/100.) )))
-cIM      champ(j) = amax1(0.0,(amin1(1.0, (champ(j)/100.) )))
-cIM   ENDDO
-cIM22/02/2002
-         CALL inter_barxy ( imdep,jmdep -1,dlon, dlat ,
-     ,     champ, iim, jjm, rlonu, rlatv, jjp1, champint )
-      ELSE
-         CALL sea_ice(imdep, jmdep, dlon, dlat, champ,
-     .             iim, jjp1, rlonv, rlatu, champint )
-      ENDIF
-         DO j = 1,jjp1
-         DO i = 1, iim
-            champtime (i,j,l) = champint(i,j)
-         ENDDO
-         ENDDO
-      ENDDO
-c
-      DO l = 1, lmdep
-cIM28/02/2002 <== PM  timeyear(l) = timecoord(l)
-cIM      timeyear(l) = timecoord(l)
-cIM07/03/2002      
-         timeyear(l) = tmidmonth(l)
-      ENDDO
-      PRINT 222,  timeyear(:lmdep)
-c
-      PRINT*, 'Interpolation temporelle'
-      DO j = 1, jjp1
-      DO i = 1, iim
-          DO l = 1, lmdep
-            ax(l) = timeyear(l)
-            ay(l) = champtime (i,j,l)
-          ENDDO
-          CALL SPLINE(ax,ay,lmdep,1.e30,1.e30,yder)
-          DO k = 1, 360
-            time = FLOAT(k-1)
-            CALL SPLINT(ax,ay,yder,lmdep,time,by)
-            champan(i,j,k) = by
-          ENDDO
-      ENDDO
-      ENDDO
-      DO k = 1, 360
-      DO j = 1, jjp1
-         champan(iip1, j, k) = champan(1, j, k)
-      ENDDO
-        IF ( k.EQ.10 )  THEN
-          DO j = 1, jjp1
-            CALL minmax( iip1,champan(1,j,10),chmin,chmax )
-            PRINT *,' Sea ice au temps 10 ', chmin,chmax,j
-          ENDDO
-        ENDIF
-      ENDDO
-c
-cIM14/03/2002 : Sea-ice Amip entre 0. et 1.
-      PRINT*,'SUB. limit_netcdf.F IM : Sea-ice Amipbc '
-      DO k = 1, 360
-      DO j = 1, jjp1
-      DO i = 1, iim
-        champan(i, j, k) = 
-     $ amax1(0.0,(amin1(1.0,(champan(i, j, k)/100.))))
-      ENDDO
-        champan(iip1, j, k) = champan(1, j, k)
-      ENDDO
-      ENDDO
-cIM14/03/2002
-
-      DO k = 1, 360
-         CALL gr_dyn_fi(1, iip1, jjp1, klon,
-     .                  champan(1,1,k), phy_ice)
-        IF ( newlmt) THEN
-
-CPB  en attendant de mettre fraction de terre
-c
-          WHERE(phy_ice(1:klon) .GE. 1.) phy_ice(1 : klon) = 1.
-          WHERE(phy_ice(1:klon) .LT. EPSFRA) phy_ice(1 : klon) = 0.
-c 
-          IF (fracterre ) THEN
-c            WRITE(*,*) 'passe dans cas fracterre' 
-            pctsrf_t(:,is_ter,k) = pctsrf(:,is_ter)
-            pctsrf_t(:,is_lic,k) = pctsrf(:,is_lic)
-            pctsrf_t(1:klon,is_sic,k) =   phy_ice(1:klon) 
-     $            - pctsrf_t(1:klon,is_lic,k)
-c Il y a des cas ou il y a de la glace dans landiceref et pas dans AMIP
-            WHERE (pctsrf_t(1:klon,is_sic,k) .LE. 0)
-              pctsrf_t(1:klon,is_sic,k) = 0.
-            END WHERE 
-            WHERE( 1. - zmasq(1:klon) .LT. EPSFRA)
-              pctsrf_t(1:klon,is_sic,k) = 0.
-              pctsrf_t(1:klon,is_oce,k) = 0.
-            END WHERE
-            DO i = 1, klon
-              IF ( 1. - zmasq(i) .GT. EPSFRA) THEN 
-                IF ( pctsrf_t(i,is_sic,k) .GE. 1 - zmasq(i)) THEN
-                  pctsrf_t(i,is_sic,k) = 1 - zmasq(i)
-                  pctsrf_t(i,is_oce,k) = 0.
-                ELSE 
-                  pctsrf_t(i,is_oce,k) = 1 - zmasq(i) 
-     $                    - pctsrf_t(i,is_sic,k)
-                  IF (pctsrf_t(i,is_oce,k) .LT. EPSFRA) THEN
-                    pctsrf_t(i,is_oce,k) = 0.
-                    pctsrf_t(i,is_sic,k) = 1 - zmasq(i)
-                  ENDIF 
-                ENDIF
-              ENDIF  
-              if (pctsrf_t(i,is_oce,k) .lt. 0.) then
-                WRITE(*,*) 'pb sous maille au point : i,k '
-     $              , i,k,pctsrf_t(:,is_oce,k)
-              ENDIF
-              IF ( abs( pctsrf_t(i, is_ter,k) + pctsrf_t(i, is_lic,k) + 
-     $          pctsrf_t(i, is_oce,k) + pctsrf_t(i, is_sic,k)  - 1.) 
-     $            .GT. EPSFRA) THEN 
-                  WRITE(*,*) 'physiq : pb sous surface au point ', i, 
-     $                pctsrf_t(i, 1 : nbsrf,k), phy_ice(i)
-              ENDIF 
-            END DO
-          ELSE 
-            DO i = 1, klon
-              pctsrf_t(i,is_ter,k) = pctsrf(i,is_ter)
-              IF (NINT(pctsrf(i,is_ter)).EQ.1 ) THEN
-                pctsrf_t(i,is_sic,k) = 0.
-                pctsrf_t(i,is_oce,k) = 0.                  
-                IF(phy_ice(i) .GE. 1.e-5) THEN
-                  pctsrf_t(i,is_lic,k) = phy_ice(i)
-                  pctsrf_t(i,is_ter,k) = pctsrf_t(i,is_ter,k) 
-     .                                   - pctsrf_t(i,is_lic,k)
-                ELSE
-                  pctsrf_t(i,is_lic,k) = 0.
-                ENDIF 
-              ELSE
-                pctsrf_t(i,is_lic,k) = 0. 
-                IF(phy_ice(i) .GE. 1.e-5) THEN 
-                  pctsrf_t(i,is_ter,k) = 0.
-                  pctsrf_t(i,is_sic,k) = phy_ice(i)
-                  pctsrf_t(i,is_oce,k) = 1. - pctsrf_t(i,is_sic,k)
-                ELSE
-                  pctsrf_t(i,is_sic,k) = 0.
-                  pctsrf_t(i,is_oce,k) = 1.                      
-                ENDIF 
-              ENDIF
-              verif = pctsrf_t(i,is_ter,k) +
-     .                pctsrf_t(i,is_oce,k) + 
-     .                pctsrf_t(i,is_sic,k) +
-     .                pctsrf_t(i,is_lic,k)
-              IF ( verif .LT. 1. - 1.e-5 .OR. 
-     $             verif .GT. 1 + 1.e-5) THEN  
-                WRITE(*,*) 'pb sous maille au point : i,k,verif '
-     $                    , i,k,verif
-              ENDIF 
-            END DO
-          ENDIF 
-        ELSE  
-          DO i = 1, klon
-            phy_nat(i,k) = phy_nat0(i)
-            IF ( (phy_ice(i) - 0.5).GE.1.e-5 ) THEN
-              IF (NINT(phy_nat0(i)).EQ.0) THEN
-                phy_nat(i,k) = 3.0
-              ELSE
-                phy_nat(i,k) = 2.0
-              ENDIF
-            ENDIF
-            IF( NINT(phy_nat(i,k)).EQ.0 ) THEN
-              IF ( phy_rug(i,k).NE.0.001 ) phy_rug(i,k) = 0.001
-            ENDIF
-          END DO
-        ENDIF
-      ENDDO
-c
-
-      ierr = NF_CLOSE(ncid)
-c
-       DEALLOCATE( dlon      )
-       DEALLOCATE( dlon_ini  )
-       DEALLOCATE( dlat      )
-       DEALLOCATE( dlat_ini  )
-       DEALLOCATE( champ     )
-
-477    continue
-c
-C Traitement de la sst
-c
-      PRINT*, 'Traitement de la sst'
-c     ierr = NF_OPEN('AMIP_SST.nc', NF_NOWRITE, ncid)
-      ierr = NF_OPEN('amipbc_sst_1x1.nc', NF_NOWRITE, ncid)
-      if (ierr.ne.0) THEN
-        ierr = NF_OPEN('amipbc_sst_1x1_clim.nc', NF_NOWRITE, ncid)
-        if (ierr.ne.0) THEN
-          print *, NF_STRERROR(ierr)
-          STOP
-        endif
-      ENDIF
-
-cIM22/02/2002
-cIM   ierr = NF_INQ_VARID(ncid,'SST',varid)
-      ierr = NF_INQ_VARID(ncid,'tosbcs',varid)
-cIM22/02/2002
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF
-      ierr = NF_INQ_VARDIMID (ncid,varid,ndimid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      ierr = NF_INQ_DIM(ncid,ndimid(1), namedim, imdep)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      print*,'variable SST ', namedim,'dimension ', imdep
-      ierr = NF_INQ_VARID(ncid,namedim,dimid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
- 
-      ALLOCATE( dlon_ini(imdep) )
-      ALLOCATE(     dlon(imdep) )
-
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(ncid,dimid,dlon_ini)
-#else
-      ierr = NF_GET_VAR_REAL(ncid,dimid,dlon_ini)
-#endif
-
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      ierr = NF_INQ_DIM(ncid,ndimid(2), namedim, jmdep)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      print*,'variable SST ', namedim, 'dimension ', jmdep
-      ierr = NF_INQ_VARID(ncid,namedim,dimid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-
-      ALLOCATE( dlat_ini(jmdep) )
-      ALLOCATE(     dlat(jmdep) )
-
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(ncid,dimid,dlat_ini)
-#else
-      ierr = NF_GET_VAR_REAL(ncid,dimid,dlat_ini)
-#endif
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      ierr = NF_INQ_DIM(ncid,ndimid(3), namedim, lmdep)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      print*,'variable ', namedim, 'dimension ', lmdep
-cIM28/02/2002
-cPM28/02/2002 : nouvelle coord temporelle fichiers AMIP pas en jours
-c               Ici on suppose qu'on a 12 mois (de 30 jours).
-      IF (lmdep.NE.12) THEN
-          print *, 'Unknown AMIP file: not 12 months ?'
-          STOP
-       ENDIF
-cIM28/02/2002
-      ierr = NF_INQ_VARID(ncid,namedim,dimid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(ncid,dimid,timecoord)
-#else
-      ierr = NF_GET_VAR_REAL(ncid,dimid,timecoord)
-#endif
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-
-       ALLOCATE( champ(imdep*jmdep) )
-       IF( extrap )   THEN
-         ALLOCATE ( work(imdep,jmdep) )
-       ENDIF
-c
-      DO l = 1, lmdep
-         dimfirst(1) = 1
-         dimfirst(2) = 1
-         dimfirst(3) = l
-c
-         dimlast(1) = imdep
-         dimlast(2) = jmdep
-         dimlast(3) = 1
-c
-         PRINT*,'Lecture temporelle et int. horizontale ',l,timecoord(l)
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VARA_DOUBLE(ncid,varid,dimfirst,dimlast,champ)
-#else
-         ierr = NF_GET_VARA_REAL(ncid,varid,dimfirst,dimlast,champ)
-#endif
-         if (ierr.ne.0) then
-           print *, NF_STRERROR(ierr)
-           STOP
-         ENDIF
-
-         title='Sst Amip'
-c
-         CALL conf_dat2d(title,imdep, jmdep, dlon_ini, dlat_ini,
-     .                            dlon, dlat, champ, interbar     )
-       IF ( extrap )  THEN
-        CALL extrapol(champ, imdep, jmdep, 999999.,.TRUE.,.TRUE.,2,work)
-       ENDIF
-c
-
-      IF ( interbar )  THEN
-        IF( l.EQ.1 )  THEN
-         WRITE(6,*) '-------------------------------------------------',
-     ,'------------------------'
-         WRITE(6,*) '$$$ Utilisation de l interpolation barycentrique ',
-     , ' pour la Sst Amip $$$ '
-         WRITE(6,*) '-------------------------------------------------',
-     ,'------------------------'
-        ENDIF
-       CALL inter_barxy ( imdep,jmdep -1,dlon, dlat ,
-     , champ, iim, jjm, rlonu, rlatv, jjp1, champint )
-      ELSE
-       CALL grille_m(imdep, jmdep, dlon, dlat, champ,
-     .          iim, jjp1, rlonv, rlatu, champint   )
-      ENDIF
-
-         DO j = 1,jjp1
-         DO i = 1, iim
-            champtime (i,j,l) = champint(i,j)
-         ENDDO
-         ENDDO
-      ENDDO
-c
-      DO l = 1, lmdep
-cIM28/02/2002 <==PM  timeyear(l) = timecoord(l)
-         timeyear(l) = tmidmonth(l)
-      ENDDO
-      print 222,  timeyear(:lmdep)
-c
-C interpolation temporelle
-      DO j = 1, jjp1
-      DO i = 1, iim
-          DO l = 1, lmdep
-            ax(l) = timeyear(l)
-            ay(l) = champtime (i,j,l)
-          ENDDO
-          CALL SPLINE(ax,ay,lmdep,1.e30,1.e30,yder)
-          DO k = 1, 360
-            time = FLOAT(k-1)
-            CALL SPLINT(ax,ay,yder,lmdep,time,by)
-            champan(i,j,k) = by
-          ENDDO
-      ENDDO
-      ENDDO
-      DO k = 1, 360
-      DO j = 1, jjp1
-         champan(iip1,j,k) = champan(1,j,k)
-      ENDDO
-        IF ( k.EQ.10 )  THEN
-          DO j = 1, jjp1
-            CALL minmax( iip1,champan(1,j,10),chmin,chmax )
-            PRINT *,' SST au temps 10 ', chmin,chmax,j
-          ENDDO
-        ENDIF
-      ENDDO
-c
-cIM14/03/2002 : SST amipbc greater then 271.38
-      PRINT*,'SUB. limit_netcdf.F IM : SST Amipbc >= 271.38 '
-      DO k = 1, 360
-      DO j = 1, jjp1
-      DO i = 1, iim
-         champan(i, j, k) = amax1(champan(i, j, k), 271.38)
-      ENDDO
-         champan(iip1, j, k) = champan(1, j, k)
-      ENDDO
-      ENDDO
-cIM14/03/2002
-      DO k = 1, 360
-         CALL gr_dyn_fi(1, iip1, jjp1, klon, 
-     .                  champan(1,1,k), phy_sst(1,k))
-      ENDDO
-c
-      ierr = NF_CLOSE(ncid)
-c
-       DEALLOCATE( dlon      )
-       DEALLOCATE( dlon_ini  )
-       DEALLOCATE( dlat      )
-       DEALLOCATE( dlat_ini  )
-       DEALLOCATE( champ     )
-c
-C Traitement de l'albedo
-c
-      PRINT*, 'Traitement de l albedo'
-      ierr = NF_OPEN('Albedo.nc', NF_NOWRITE, ncid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF
-      ierr = NF_INQ_VARID(ncid,'ALBEDO',varid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF
-      ierr = NF_INQ_VARDIMID (ncid,varid,ndimid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      ierr = NF_INQ_DIM(ncid,ndimid(1), namedim, imdep)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      print*,'variable ', namedim, 'dimension ', imdep
-      ierr = NF_INQ_VARID(ncid,namedim,dimid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-
-      ALLOCATE ( dlon_ini(imdep) )
-      ALLOCATE (     dlon(imdep) )
-
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(ncid,dimid,dlon_ini)
-#else
-      ierr = NF_GET_VAR_REAL(ncid,dimid,dlon_ini)
-#endif
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      ierr = NF_INQ_DIM(ncid,ndimid(2), namedim, jmdep)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      print*,'variable ', namedim, 'dimension ', jmdep
-      ierr = NF_INQ_VARID(ncid,namedim,dimid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-
-      ALLOCATE ( dlat_ini(jmdep) )
-      ALLOCATE (     dlat(jmdep) )
-
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(ncid,dimid,dlat_ini)
-#else
-      ierr = NF_GET_VAR_REAL(ncid,dimid,dlat_ini)
-#endif
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      ierr = NF_INQ_DIM(ncid,ndimid(3), namedim, lmdep)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      print*,'variable ', namedim, 'dimension ', lmdep
-      ierr = NF_INQ_VARID(ncid,namedim,dimid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(ncid,dimid,timecoord)
-#else
-      ierr = NF_GET_VAR_REAL(ncid,dimid,timecoord)
-#endif
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-c
-      ALLOCATE ( champ(imdep*jmdep) )
-
-      DO l = 1, lmdep
-         dimfirst(1) = 1
-         dimfirst(2) = 1
-         dimfirst(3) = l
-c
-         dimlast(1) = imdep
-         dimlast(2) = jmdep
-         dimlast(3) = 1
-c
-         PRINT*,'Lecture temporelle et int. horizontale ',l,timecoord(l)
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VARA_DOUBLE(ncid,varid,dimfirst,dimlast,champ)
-#else
-         ierr = NF_GET_VARA_REAL(ncid,varid,dimfirst,dimlast,champ)
-#endif
-         if (ierr.ne.0) then
-           print *, NF_STRERROR(ierr)
-           STOP
-         ENDIF
-
-         title='Albedo Amip'
-c
-         CALL conf_dat2d(title,imdep, jmdep, dlon_ini, dlat_ini,
-     .                            dlon, dlat, champ, interbar      )
-c
-c
-      IF ( interbar )  THEN
-        IF( l.EQ.1 )  THEN
-         WRITE(6,*) '-------------------------------------------------',
-     ,'------------------------'
-         WRITE(6,*) '$$$ Utilisation de l interpolation barycentrique ',
-     , ' pour l Albedo Amip $$$ '
-         WRITE(6,*) '-------------------------------------------------',
-     ,'------------------------'
-        ENDIF
-
-       CALL inter_barxy ( imdep,jmdep -1,dlon, dlat ,
-     , champ, iim, jjm, rlonu, rlatv, jjp1, champint )
-      ELSE
-       CALL grille_m(imdep, jmdep, dlon, dlat, champ,
-     .          iim, jjp1, rlonv, rlatu, champint   )
-      ENDIF
-c
-         DO j = 1,jjp1
-         DO i = 1, iim
-            champtime (i, j, l) = champint(i, j)
-         ENDDO
-         ENDDO
-      ENDDO
-c
-      DO l = 1, lmdep
-         timeyear(l) = timecoord(l)
-      ENDDO
-      print 222,  timeyear(:lmdep)
-c
-C interpolation temporelle
-      DO j = 1, jjp1
-      DO i = 1, iim
-          DO l = 1, lmdep
-            ax(l) = timeyear(l)
-            ay(l) = champtime (i, j, l)
-          ENDDO
-          CALL SPLINE(ax,ay,lmdep,1.e30,1.e30,yder)
-          DO k = 1, 360
-            time = FLOAT(k-1)
-            CALL SPLINT(ax,ay,yder,lmdep,time,by)
-            champan(i,j,k) = by
-          ENDDO
-      ENDDO
-      ENDDO
-      DO k = 1, 360
-      DO j = 1, jjp1
-         champan(iip1, j, k) = champan(1, j, k)
-      ENDDO
-        IF ( k.EQ.10 )  THEN
-          DO j = 1, jjp1
-            CALL minmax( iip1,champan(1,j,10),chmin,chmax )
-            PRINT *,' Albedo au temps 10 ', chmin,chmax,j
-          ENDDO
-        ENDIF
-      ENDDO
-c
-      DO k = 1, 360
-         CALL gr_dyn_fi(1, iip1, jjp1, klon,
-     .                  champan(1,1,k), phy_alb(1,k))
-      ENDDO
-c
-      ierr = NF_CLOSE(ncid)
-c
-c
-      DO k = 1, 360
-      DO i = 1, klon
-         phy_bil(i,k) = 0.0
-      ENDDO
-      ENDDO
-c
-      PRINT*, 'Ecriture du fichier limit'
-c
-      ierr = NF_CREATE ("limit.nc", NF_CLOBBER, nid)
-c
-      ierr = NF_PUT_ATT_TEXT (nid, NF_GLOBAL, "title", 30,
-     .                       "Fichier conditions aux limites")
-      ierr = NF_DEF_DIM (nid, "points_physiques", klon, ndim)
-      ierr = NF_DEF_DIM (nid, "time", NF_UNLIMITED, ntim)
-c
-      dims(1) = ndim
-      dims(2) = ntim
-c
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid, "TEMPS", NF_DOUBLE, 1,ntim, id_tim)
-#else
-      ierr = NF_DEF_VAR (nid, "TEMPS", NF_FLOAT, 1,ntim, id_tim)
-#endif
-      ierr = NF_PUT_ATT_TEXT (nid, id_tim, "title", 17,
-     .                        "Jour dans l annee")
-      IF (newlmt) THEN
-c
-#ifdef NC_DOUBLE
-        ierr = NF_DEF_VAR (nid, "FOCE", NF_DOUBLE, 2,dims, id_FOCE)
-#else
-        ierr = NF_DEF_VAR (nid, "FOCE", NF_FLOAT, 2,dims, id_FOCE)
-#endif
-        ierr = NF_PUT_ATT_TEXT (nid, id_FOCE, "title", 14,
-     .                      "Fraction ocean")
-c
-#ifdef NC_DOUBLE
-        ierr = NF_DEF_VAR (nid, "FSIC", NF_DOUBLE, 2,dims, id_FSIC)
-#else
-        ierr = NF_DEF_VAR (nid, "FSIC", NF_FLOAT, 2,dims, id_FSIC)
-#endif
-        ierr = NF_PUT_ATT_TEXT (nid, id_FSIC, "title", 21,
-     .                      "Fraction glace de mer")
-c
-#ifdef NC_DOUBLE
-        ierr = NF_DEF_VAR (nid, "FTER", NF_DOUBLE, 2,dims, id_FTER)
-#else
-        ierr = NF_DEF_VAR (nid, "FTER", NF_FLOAT, 2,dims, id_FTER)
-#endif
-        ierr = NF_PUT_ATT_TEXT (nid, id_FTER, "title", 14,
-     .                      "Fraction terre")
-c
-#ifdef NC_DOUBLE
-        ierr = NF_DEF_VAR (nid, "FLIC", NF_DOUBLE, 2,dims, id_FLIC)
-#else
-        ierr = NF_DEF_VAR (nid, "FLIC", NF_FLOAT, 2,dims, id_FLIC)
-#endif
-        ierr = NF_PUT_ATT_TEXT (nid, id_FLIC, "title", 17,
-     .                      "Fraction land ice")
-c
-      ELSE 
-#ifdef NC_DOUBLE
-        ierr = NF_DEF_VAR (nid, "NAT", NF_DOUBLE, 2,dims, id_NAT)
-#else
-        ierr = NF_DEF_VAR (nid, "NAT", NF_FLOAT, 2,dims, id_NAT)
-#endif
-        ierr = NF_PUT_ATT_TEXT (nid, id_NAT, "title", 23,
-     .                      "Nature du sol (0,1,2,3)")
-      ENDIF 
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid, "SST", NF_DOUBLE, 2,dims, id_SST)
-#else
-      ierr = NF_DEF_VAR (nid, "SST", NF_FLOAT, 2,dims, id_SST)
-#endif
-      ierr = NF_PUT_ATT_TEXT (nid, id_SST, "title", 35,
-     .                      "Temperature superficielle de la mer")
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid, "BILS", NF_DOUBLE, 2,dims, id_BILS)
-#else
-      ierr = NF_DEF_VAR (nid, "BILS", NF_FLOAT, 2,dims, id_BILS)
-#endif
-      ierr = NF_PUT_ATT_TEXT (nid, id_BILS, "title", 32,
-     .                        "Reference flux de chaleur au sol")
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid, "ALB", NF_DOUBLE, 2,dims, id_ALB)
-#else
-      ierr = NF_DEF_VAR (nid, "ALB", NF_FLOAT, 2,dims, id_ALB)
-#endif
-      ierr = NF_PUT_ATT_TEXT (nid, id_ALB, "title", 19,
-     .                        "Albedo a la surface")
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid, "RUG", NF_DOUBLE, 2,dims, id_RUG)
-#else
-      ierr = NF_DEF_VAR (nid, "RUG", NF_FLOAT, 2,dims, id_RUG)
-#endif
-      ierr = NF_PUT_ATT_TEXT (nid, id_RUG, "title", 8,
-     .                        "Rugosite")
-c
-      ierr = NF_ENDDEF(nid)
-c
-      DO k = 1, 360
-c
-      debut(1) = 1
-      debut(2) = k
-      epais(1) = klon
-      epais(2) = 1
-c
-#ifdef NC_DOUBLE
-      ierr = NF_PUT_VAR1_DOUBLE (nid,id_tim,k,DBLE(k))
-c
-      IF (newlmt ) THEN
-          ierr = NF_PUT_VARA_DOUBLE (nid,id_FOCE,debut,epais
-     $        ,pctsrf_t(1,is_oce,k))
-          ierr = NF_PUT_VARA_DOUBLE (nid,id_FSIC,debut,epais
-     $        ,pctsrf_t(1,is_sic,k))
-          ierr = NF_PUT_VARA_DOUBLE (nid,id_FTER,debut,epais
-     $        ,pctsrf_t(1,is_ter,k))
-          ierr = NF_PUT_VARA_DOUBLE (nid,id_FLIC,debut,epais
-     $        ,pctsrf_t(1,is_lic,k))
-      ELSE 
-          ierr = NF_PUT_VARA_DOUBLE (nid,id_NAT,debut,epais
-     $        ,phy_nat(1,k))
-      ENDIF 
-c
-      ierr = NF_PUT_VARA_DOUBLE (nid,id_SST,debut,epais,phy_sst(1,k))
-      ierr = NF_PUT_VARA_DOUBLE (nid,id_BILS,debut,epais,phy_bil(1,k))
-      ierr = NF_PUT_VARA_DOUBLE (nid,id_ALB,debut,epais,phy_alb(1,k))
-      ierr = NF_PUT_VARA_DOUBLE (nid,id_RUG,debut,epais,phy_rug(1,k))
-#else
-      ierr = NF_PUT_VAR1_REAL (nid,id_tim,k,FLOAT(k))
-      IF (newlmt ) THEN
-          ierr = NF_PUT_VARA_REAL (nid,id_FOCE,debut,epais
-     $        ,pctsrf_t(1,is_oce,k))
-          ierr = NF_PUT_VARA_REAL (nid,id_FSIC,debut,epais
-     $        ,pctsrf_t(1,is_sic,k))
-          ierr = NF_PUT_VARA_REAL (nid,id_FTER,debut,epais
-     $        ,pctsrf_t(1,is_ter,k))
-          ierr = NF_PUT_VARA_REAL (nid,id_FLIC,debut,epais
-     $        ,pctsrf_t(1,is_lic,k))
-      ELSE 
-          ierr = NF_PUT_VARA_REAL (nid,id_NAT,debut,epais
-     $        ,phy_nat(1,k))
-      ENDIF 
-      ierr = NF_PUT_VARA_REAL (nid,id_SST,debut,epais,phy_sst(1,k))
-      ierr = NF_PUT_VARA_REAL (nid,id_BILS,debut,epais,phy_bil(1,k))
-      ierr = NF_PUT_VARA_REAL (nid,id_ALB,debut,epais,phy_alb(1,k))
-      ierr = NF_PUT_VARA_REAL (nid,id_RUG,debut,epais,phy_rug(1,k))
-#endif
-c
-      ENDDO
-c
-      ierr = NF_CLOSE(nid)
-c
-#else
-      WRITE(lunout,*)
-     & 'limit_netcdf: Earth-specific routine, needs Earth physics'
-#endif
-! of #ifdef CPP_EARTH
-      STOP
-      END
Index: LMDZ4/trunk/libf/dyn3d/limit_netcdf.F90
===================================================================
--- LMDZ4/trunk/libf/dyn3d/limit_netcdf.F90	(revision 1319)
+++ LMDZ4/trunk/libf/dyn3d/limit_netcdf.F90	(revision 1319)
@@ -0,0 +1,617 @@
+!
+! $Id$
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE limit_netcdf(interbar, extrap, oldice, masque)
+!
+!-------------------------------------------------------------------------------
+! Author : L. Fairhead, 27/01/94
+!-------------------------------------------------------------------------------
+! Purpose: Boundary conditions files building for new model using climatologies.
+!          Both grids have to be regular.
+!-------------------------------------------------------------------------------
+! Note: This routine is designed to work for Earth
+!-------------------------------------------------------------------------------
+! Modification history:
+!  * 23/03/1994: Z. X. Li
+!  *    09/1999: L. Fairhead (netcdf reading in LMDZ.3.3)
+!  *    07/2001: P. Le Van
+!  *    11/2009: L. Guez     (ozone day & night climatos, see etat0_netcdf.F90)
+!  *    12/2009: D. Cugnet   (f77->f90, calendars, files from coupled runs)
+!-------------------------------------------------------------------------------
+#ifdef CPP_EARTH
+  USE dimphy
+  USE ioipsl,             ONLY : ioget_year_len
+  USE phys_state_var_mod, ONLY : pctsrf
+  USE netcdf,             ONLY : NF90_OPEN,    NF90_CREATE,  NF90_CLOSE,       &
+                   NF90_DEF_DIM, NF90_DEF_VAR, NF90_PUT_VAR, NF90_PUT_ATT,     &
+                   NF90_NOERR,   NF90_NOWRITE, NF90_DOUBLE,  NF90_GLOBAL,      &
+		   NF90_CLOBBER, NF90_ENDDEF,  NF90_UNLIMITED
+#endif
+  IMPLICIT NONE
+!-------------------------------------------------------------------------------
+! Arguments:
+#include "dimensions.h"
+#include "paramet.h"
+#include "iniprint.h"
+  LOGICAL,                    INTENT(IN) :: interbar ! barycentric interpolation
+  LOGICAL,                    INTENT(IN) :: extrap   ! SST extrapolation flag
+  LOGICAL,                    INTENT(IN) :: oldice   ! old way ice computation
+  REAL, DIMENSION(iip1,jjp1), INTENT(IN) :: masque   ! land mask
+#ifndef CPP_EARTH
+  WRITE(lunout,*)'limit_netcdf: Earth-specific routine, needs Earth physics'
+#else
+!-------------------------------------------------------------------------------
+! Local variables:
+#include "control.h"
+#include "logic.h"
+#include "comvert.h"
+#include "comgeom2.h"
+#include "comconst.h"
+#include "indicesol.h"
+
+!--- For fractionary sub-cell use (old coding used soil index: 0,1,2,3) --------
+  LOGICAL, PARAMETER :: fracterre=.TRUE.
+
+!--- INPUT NETCDF FILES NAMES --------------------------------------------------
+  CHARACTER(LEN=25) :: icefile, sstfile, dumstr
+  CHARACTER(LEN=25), PARAMETER :: famipsst='amipbc_sst_1x1.nc        ',        &
+                                  famipsic='amipbc_sic_1x1.nc        ',        &
+                                  fclimsst='amipbc_sst_1x1_clim.nc   ',        &
+                                  fclimsic='amipbc_sic_1x1_clim.nc   ',        &
+                                  fcpldsst='cpl_atm_sst.nc           ',        &
+                                  fcpldsic='cpl_atm_sic.nc           ',        &
+                                  frugo   ='Rugos.nc                 ',        &
+                                  falbe   ='Albedo.nc                '
+
+!--- OUTPUT VARIABLES FOR NETCDF FILE ------------------------------------------
+  REAL,   DIMENSION(klon)                :: fi_ice, verif
+  REAL,   DIMENSION(:,:),   POINTER      :: phy_rug=>NULL(), phy_ice=>NULL()
+  REAL,   DIMENSION(:,:),   POINTER      :: phy_sst=>NULL(), phy_alb=>NULL()
+  REAL,   DIMENSION(:,:),   ALLOCATABLE  :: phy_bil
+  REAL,   DIMENSION(:,:,:), ALLOCATABLE  :: pctsrf_t
+  INTEGER                                :: nbad
+
+!--- VARIABLES FOR OUTPUT FILE WRITING -----------------------------------------
+  INTEGER :: ierr, nid, ndim, ntim, k
+  INTEGER, DIMENSION(2) :: dims
+  INTEGER :: id_tim,  id_SST,  id_BILS, id_RUG, id_ALB
+  INTEGER :: id_FOCE, id_FSIC, id_FTER, id_FLIC
+  INTEGER :: NF90_FORMAT
+  LOGICAL :: lCPL                    !--- T: IPCC-IPSL cpl model output files
+
+!--- MICS (PHYSICAL KEYS, TIME) ------------------------------------------------
+!  INTEGER, PARAMETER        :: longcles=20
+!  REAL, DIMENSION(longcles) :: clesphy0
+  INTEGER                   :: ndays
+  
+!--- INITIALIZATIONS -----------------------------------------------------------
+#ifdef NC_DOUBLE
+  NF90_FORMAT=NF90_DOUBLE
+#else
+  NF90_FORMAT=NF90_FLOAT
+#endif
+
+!  CALL conf_gcm(99, .TRUE., clesphy0)
+  pi    = 4.*ATAN(1.)
+  rad   = 6371229.
+  daysec= 86400.
+  omeg  = 2.*pi/daysec
+  g     = 9.8
+  kappa = 0.2857143
+  cpp   = 1004.70885
+  dtvr  = daysec/FLOAT(day_step)
+  CALL inigeom
+
+!--- Beware: anneeref (from gcm.def) is used to determine output time sampling
+  ndays=ioget_year_len(anneeref)
+
+!--- RUGOSITY TREATMENT --------------------------------------------------------
+  WRITE(lunout,*) 'Traitement de la rugosite'
+  CALL get_2Dfield(frugo,'RUG',interbar,ndays,phy_rug,mask=masque(1:iim,:))
+
+!--- OCEAN TREATMENT -----------------------------------------------------------
+  PRINT*, 'Traitement de la glace oceanique' ; icefile=''; lCPL=.FALSE.
+
+! Input SIC file selection
+  icefile='fake'
+  IF(NF90_OPEN(famipsic,NF90_NOWRITE,nid)==NF90_NOERR) icefile=TRIM(famipsic)
+  IF(NF90_OPEN(fclimsic,NF90_NOWRITE,nid)==NF90_NOERR) icefile=TRIM(fclimsic)
+  IF(NF90_OPEN(fcpldsic,NF90_NOWRITE,nid)==NF90_NOERR) icefile=TRIM(fcpldsic)
+  SELECT CASE(icefile)
+    CASE(famipsic); dumstr='Amip.'
+    CASE(fclimsic); dumstr='Amip climatologique.'
+    CASE(fcpldsic); dumstr='de sortie du modele couplé IPSL/IPCC.';lCPL=.TRUE.
+    CASE('fake');   CALL abort_gcm('limit_netcdf','Fichier SIC non reconnu.',1)
+  END SELECT
+  ierr=NF90_CLOSE(nid)
+  WRITE(lunout,*)'Pour la glace de mer a ete choisi un fichier '//TRIM(dumstr)
+
+  CALL get_2Dfield(icefile,'SIC',interbar,ndays,phy_ice,flag=oldice)
+
+  ALLOCATE(pctsrf_t(klon,nbsrf,ndays))
+  DO k=1,ndays
+    fi_ice=phy_ice(:,k)
+    WHERE(fi_ice>=1.0  ) fi_ice=1.0
+    WHERE(fi_ice<EPSFRA) fi_ice=0.0
+    IF(fracterre) THEN
+      pctsrf_t(:,is_ter,k)=pctsrf(:,is_ter)       ! land soil
+      pctsrf_t(:,is_lic,k)=pctsrf(:,is_lic)       ! land ice
+      IF(lCPL) THEN                              ! SIC=pICE*(1-LIC-TER)
+        pctsrf_t(:,is_sic,k)=fi_ice*(1-pctsrf(:,is_lic)-pctsrf(:,is_ter))
+      ELSE                                        ! SIC=pICE-LIC
+        pctsrf_t(:,is_sic,k)=fi_ice-pctsrf_t(:,is_lic,k)
+      END IF
+      WHERE(pctsrf_t(:,is_sic,k)<=0) pctsrf_t(:,is_sic,k)=0.
+      WHERE(1.0-zmasq<EPSFRA)
+        pctsrf_t(:,is_sic,k)=0.0
+        pctsrf_t(:,is_oce,k)=0.0
+      ELSEWHERE
+        WHERE(pctsrf_t(:,is_sic,k)>=1.0-zmasq)
+          pctsrf_t(:,is_sic,k)=1.0-zmasq
+          pctsrf_t(:,is_oce,k)=0.0
+        ELSEWHERE
+          pctsrf_t(:,is_oce,k)=1.0-zmasq-pctsrf_t(:,is_sic,k)
+          WHERE(pctsrf_t(:,is_oce,k)<EPSFRA)
+            pctsrf_t(:,is_oce,k)=0.0
+            pctsrf_t(:,is_sic,k)=1.0-zmasq
+          END WHERE
+        END WHERE
+      END WHERE
+      nbad=COUNT(pctsrf_t(:,is_oce,k)<0.0)
+      IF(nbad>0) WRITE(lunout,*) 'pb sous maille pour nb point = ',nbad
+      nbad=COUNT(abs(sum(pctsrf_t(:,:,k),dim=2)-1.0)>EPSFRA)
+      IF(nbad>0) WRITE(lunout,*) 'pb sous surface pour nb points = ',nbad
+    ELSE 
+      pctsrf_t(:,is_ter,k)=pctsrf(:,is_ter)
+      WHERE(NINT(pctsrf(:,is_ter))==1)
+        pctsrf_t(:,is_sic,k)=0.
+        pctsrf_t(:,is_oce,k)=0.                  
+        WHERE(fi_ice>=1.e-5)
+          pctsrf_t(:,is_lic,k)=fi_ice
+          pctsrf_t(:,is_ter,k)=pctsrf_t(:,is_ter,k)-pctsrf_t(:,is_lic,k)
+        ELSEWHERE
+          pctsrf_t(:,is_lic,k)=0.0
+        END WHERE
+      ELSEWHERE
+        pctsrf_t(:,is_lic,k) = 0.0 
+        WHERE(fi_ice>=1.e-5)
+          pctsrf_t(:,is_ter,k)=0.0
+          pctsrf_t(:,is_sic,k)=fi_ice
+          pctsrf_t(:,is_oce,k)=1.0-pctsrf_t(:,is_sic,k)
+        ELSEWHERE
+          pctsrf_t(:,is_sic,k)=0.0
+          pctsrf_t(:,is_oce,k)=1.0
+        END WHERE
+      END WHERE
+      verif=sum(pctsrf_t(:,:,k),dim=2)
+      nbad=COUNT(verif<1.0-1.e-5.OR.verif>1.0+1.e-5)
+      IF(nbad>0) WRITE(lunout,*) 'pb sous maille pour nb point = ',nbad
+    END IF 
+  END DO
+  DEALLOCATE(phy_ice)
+
+!--- SST TREATMENT -------------------------------------------------------------
+  WRITE(lunout,*) 'Traitement de la sst' ; sstfile=''; lCPL=.FALSE.
+
+! Input SST file selection
+  sstfile='fake'
+  IF(NF90_OPEN(famipsst,NF90_NOWRITE,nid)==NF90_NOERR) sstfile=TRIM(famipsst)
+  IF(NF90_OPEN(fclimsst,NF90_NOWRITE,nid)==NF90_NOERR) sstfile=TRIM(fclimsst)
+  IF(NF90_OPEN(fcpldsst,NF90_NOWRITE,nid)==NF90_NOERR) sstfile=TRIM(fcpldsst)
+  SELECT CASE(icefile)
+    CASE(famipsic); dumstr='Amip.'
+    CASE(fclimsic); dumstr='Amip climatologique.'
+    CASE(fcpldsic); dumstr='de sortie du modele couplé IPSL/IPCC.';lCPL=.TRUE.
+    CASE('fake');   CALL abort_gcm('limit_netcdf','Fichier SST non reconnu',1)
+  END SELECT
+  ierr=NF90_CLOSE(nid)
+  WRITE(lunout,*)'Pour la temperature de mer a ete choisi un fichier '//TRIM(dumstr)
+
+  CALL get_2Dfield(trim(sstfile),'SST',interbar,ndays,phy_sst,flag=extrap)
+
+!--- ALBEDO TREATMENT ----------------------------------------------------------
+  WRITE(lunout,*) 'Traitement de l albedo'
+  CALL get_2Dfield(falbe,'ALB',interbar,ndays,phy_alb)
+
+!--- REFERENCE GROUND HEAT FLUX TREATMENT --------------------------------------
+  ALLOCATE(phy_bil(klon,ndays)); phy_bil=0.0
+
+!--- OUTPUT FILE WRITING -------------------------------------------------------
+  WRITE(lunout,*) 'Ecriture du fichier limit'
+
+  !--- File creation
+  ierr=NF90_CREATE("limit.nc",NF90_CLOBBER,nid)
+  ierr=NF90_PUT_ATT(nid,NF90_GLOBAL,"title","Fichier conditions aux limites")
+
+  !--- Dimensions creation
+  ierr=NF90_DEF_DIM(nid,"points_physiques",klon,ndim)
+  ierr=NF90_DEF_DIM(nid,"time",NF90_UNLIMITED,ntim)
+
+  dims=(/ndim,ntim/)
+
+  !--- Variables creation
+  ierr=NF90_DEF_VAR(nid,"TEMPS",NF90_FORMAT,dims,id_tim)
+  ierr=NF90_DEF_VAR(nid,"FOCE", NF90_FORMAT,dims,id_FOCE)
+  ierr=NF90_DEF_VAR(nid,"FSIC", NF90_FORMAT,dims,id_FSIC)
+  ierr=NF90_DEF_VAR(nid,"FTER", NF90_FORMAT,dims,id_FTER)
+  ierr=NF90_DEF_VAR(nid,"FLIC", NF90_FORMAT,dims,id_FLIC)
+  ierr=NF90_DEF_VAR(nid,"SST",  NF90_FORMAT,dims,id_SST)
+  ierr=NF90_DEF_VAR(nid,"BILS", NF90_FORMAT,dims,id_BILS)
+  ierr=NF90_DEF_VAR(nid,"ALB",  NF90_FORMAT,dims,id_ALB)
+  ierr=NF90_DEF_VAR(nid,"RUG",  NF90_FORMAT,dims,id_RUG)
+
+  !--- Attributes creation
+  ierr=NF90_PUT_ATT(nid,id_tim, "title","Jour dans l annee")
+  ierr=NF90_PUT_ATT(nid,id_FOCE,"title","Fraction ocean")
+  ierr=NF90_PUT_ATT(nid,id_FSIC,"title","Fraction glace de mer")
+  ierr=NF90_PUT_ATT(nid,id_FTER,"title","Fraction terre")
+  ierr=NF90_PUT_ATT(nid,id_FLIC,"title","Fraction land ice")
+  ierr=NF90_PUT_ATT(nid,id_SST ,"title","Temperature superficielle de la mer")
+  ierr=NF90_PUT_ATT(nid,id_BILS,"title","Reference flux de chaleur au sol")
+  ierr=NF90_PUT_ATT(nid,id_ALB, "title","Albedo a la surface")
+  ierr=NF90_PUT_ATT(nid,id_RUG, "title","Rugosite")
+
+  ierr=NF90_ENDDEF(nid)
+
+  !--- Variables saving
+  ierr=NF90_PUT_VAR(nid,id_tim,(/(DBLE(k),k=1,ndays)/))
+  ierr=NF90_PUT_VAR(nid,id_FOCE,pctsrf_t(:,is_oce,:),(/1,1/),(/klon,ndays/))
+  ierr=NF90_PUT_VAR(nid,id_FSIC,pctsrf_t(:,is_sic,:),(/1,1/),(/klon,ndays/))
+  ierr=NF90_PUT_VAR(nid,id_FTER,pctsrf_t(:,is_ter,:),(/1,1/),(/klon,ndays/))
+  ierr=NF90_PUT_VAR(nid,id_FLIC,pctsrf_t(:,is_lic,:),(/1,1/),(/klon,ndays/))
+  ierr=NF90_PUT_VAR(nid,id_SST ,phy_sst(:,:),(/1,1/),(/klon,ndays/))
+  ierr=NF90_PUT_VAR(nid,id_BILS,phy_bil(:,:),(/1,1/),(/klon,ndays/))
+  ierr=NF90_PUT_VAR(nid,id_ALB ,phy_alb(:,:),(/1,1/),(/klon,ndays/))
+  ierr=NF90_PUT_VAR(nid,id_RUG ,phy_rug(:,:),(/1,1/),(/klon,ndays/))
+
+  ierr=NF90_CLOSE(nid)
+
+  DEALLOCATE(pctsrf_t,phy_sst,phy_bil,phy_alb,phy_rug)
+#endif
+! of #ifdef CPP_EARTH
+  STOP
+
+
+!===============================================================================
+!
+  CONTAINS
+!
+!===============================================================================
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE get_2Dfield(fnam, mode, ibar, ndays, champo, flag, mask)
+!
+!-------------------------------------------------------------------------------
+! Comments:
+!   There are two assumptions concerning the NetCDF files, that are satisfied
+!   with files that are conforming NC convention:
+!     1) The last dimension of the variables used is the time record.
+!     2) Dimensional variables have the same names as corresponding dimensions.
+!-------------------------------------------------------------------------------
+  USE netcdf, ONLY : NF90_OPEN,    NF90_INQ_VARID, NF90_INQUIRE_VARIABLE,      &
+                     NF90_CLOSE,   NF90_INQ_DIMID, NF90_INQUIRE_DIMENSION,     &
+                     NF90_GET_VAR, NF90_GET_ATT
+  USE dimphy, ONLY : klon
+  USE phys_state_var_mod, ONLY : pctsrf
+  IMPLICIT NONE
+#include "dimensions.h"
+#include "paramet.h"
+#include "comgeom2.h"
+#include "control.h"
+#include "indicesol.h"
+#include "iniprint.h"
+!-------------------------------------------------------------------------------
+! Arguments:
+  CHARACTER(LEN=*),  INTENT(IN)     :: fnam     ! NetCDF file name
+  CHARACTER(LEN=3),  INTENT(IN)     :: mode     ! RUG, SIC, SST or ALB
+  LOGICAL,           INTENT(IN)     :: ibar     ! interp on pressure levels
+  INTEGER,           INTENT(IN)     :: ndays    ! current year number of days
+  REAL,    POINTER,  DIMENSION(:,:) :: champo   ! output field = f(t)
+  LOGICAL, OPTIONAL,                      INTENT(IN) :: flag
+! flag=T means:   extrapolation (SST case)  or  old ice (SIC case)
+  REAL,    OPTIONAL, DIMENSION(iim,jjp1), INTENT(IN) :: mask
+!-------------------------------------------------------------------------------
+! Local variables:
+!--- NetCDF
+  INTEGER :: ierr, ncid, varid                  ! NetCDF identifiers
+  CHARACTER(LEN=30)               :: dnam       ! dimension name
+  CHARACTER(LEN=80)               :: varname    ! NetCDF variable name
+!--- dimensions
+  INTEGER,           DIMENSION(4) :: dids       ! NetCDF dimensions identifiers
+  REAL, ALLOCATABLE, DIMENSION(:) :: dlon_ini   ! initial longitudes vector
+  REAL, ALLOCATABLE, DIMENSION(:) :: dlat_ini   ! initial latitudes  vector
+  REAL, POINTER,     DIMENSION(:) :: dlon, dlat ! reordered lon/lat  vectors
+!--- fields
+  INTEGER :: imdep, jmdep, lmdep                ! dimensions of 'champ'
+  REAL, ALLOCATABLE, DIMENSION(:) :: champ      ! wanted field on initial grid
+  REAL, ALLOCATABLE, DIMENSION(:) :: yder, timeyear
+  REAL,              DIMENSION(iim,jjp1) :: champint   ! interpolated field
+  REAL, ALLOCATABLE, DIMENSION(:,:,:)    :: champtime
+  REAL, ALLOCATABLE, DIMENSION(:,:,:)    :: champan
+  REAL                              :: time, by
+!--- input files
+  CHARACTER(LEN=20)                 :: cal_in   ! calendar
+  INTEGER                           :: ndays_in ! number of days
+!--- misc
+  INTEGER :: i, j, k, l                         ! loop counters
+  REAL, ALLOCATABLE, DIMENSION(:,:) :: work     ! used for extrapolation
+  CHARACTER(LEN=25)                 :: title    ! for messages
+  LOGICAL                           :: extrp    ! flag for extrapolation
+  REAL                              :: chmin, chmax
+!-------------------------------------------------------------------------------
+!---Variables depending on keyword 'mode' --------------------------------------
+  NULLIFY(champo)
+  SELECT CASE(mode)
+    CASE('RUG'); varname='RUGOS';  title='Rugosite'
+    CASE('SIC'); varname='sicbcs'; title='Sea-ice'
+    CASE('SST'); varname='tosbcs'; title='SST'
+    CASE('ALB'); varname='ALBEDO'; title='Albedo'
+  END SELECT
+  extrp=(flag.AND.mode=='SST')
+
+!--- GETTING SOME DIMENSIONAL VARIABLES FROM FILE ------------------------------
+  ierr=NF90_OPEN(fnam,NF90_NOWRITE,ncid);                  CALL ncerr(ierr,fnam)
+  ierr=NF90_INQ_VARID(ncid,varname,varid);                 CALL ncerr(ierr,fnam)
+  ierr=NF90_INQUIRE_VARIABLE(ncid,varid,dimids=dids);      CALL ncerr(ierr,fnam)
+
+!--- Longitude
+  ierr=NF90_INQUIRE_DIMENSION(ncid,dids(1),name=dnam,len=imdep)
+  CALL ncerr(ierr,fnam); ALLOCATE(dlon_ini(imdep),dlon(imdep))
+  ierr=NF90_INQ_VARID(ncid,dnam,varid);                    CALL ncerr(ierr,fnam)
+  ierr=NF90_GET_VAR(ncid,varid,dlon_ini);                  CALL ncerr(ierr,fnam)
+  WRITE(lunout,*) 'variable ', dnam, 'dimension ', imdep
+
+!--- Latitude
+  ierr=NF90_INQUIRE_DIMENSION(ncid,dids(2),name=dnam,len=jmdep)
+  CALL ncerr(ierr,fnam); ALLOCATE(dlat_ini(jmdep),dlat(jmdep))
+  ierr=NF90_INQ_VARID(ncid,dnam,varid);                    CALL ncerr(ierr,fnam)
+  ierr=NF90_GET_VAR(ncid,varid,dlat_ini);                  CALL ncerr(ierr,fnam)
+  WRITE(lunout,*) 'variable ', dnam, 'dimension ', jmdep
+
+!--- Time (variable is not needed - it is rebuilt - but calendar is)
+  ierr=NF90_INQUIRE_DIMENSION(ncid,dids(3),name=dnam,len=lmdep)
+  CALL ncerr(ierr,fnam); ALLOCATE(timeyear(lmdep))
+  ierr=NF90_INQ_VARID(ncid,dnam,varid);                    CALL ncerr(ierr,fnam)
+  cal_in=' '
+  ierr=NF90_GET_ATT(ncid,varid,'calendar',cal_in)
+  IF(ierr/=NF90_NOERR) THEN
+    SELECT CASE(mode)
+      CASE('RUG','ALB'); cal_in='360d'
+      CASE('SIC','SST'); cal_in='gregorian'
+    END SELECT
+    WRITE(lunout,*)'ATTENTION: variable ''time'' sans attribut ''calendrier'' d&
+     &ans '//TRIM(fnam)//'. On choisit la valeur par defaut.'
+  END IF
+  WRITE(lunout,*) 'variable ', dnam, 'dimension ', lmdep, 'calendrier ', cal_in
+
+!--- CONSTRUCTING THE INPUT TIME VECTOR FOR INTERPOLATION ----------------------
+  !--- Determining input file number of days, depending on calendar
+  ndays_in=year_len(anneeref,cal_in)
+
+!--- Time vector reconstruction (time vector from file is not trusted)
+!--- If input records are not monthly, time sampling has to be constant !
+  timeyear=mid_months(anneeref,cal_in,lmdep)
+  IF(lmdep/=12) WRITE(lunout,'(a,i3,a)')'Note: les fichiers de '//TRIM(mode)   &
+    //' ne comportent pas 12, mais ',lmdep,' renregistrements.'
+
+!--- GETTING THE FIELD AND INTERPOLATING IT ------------------------------------
+  ALLOCATE(champ(imdep*jmdep),champtime(iim,jjp1,lmdep))
+  IF(extrp) ALLOCATE(work(imdep,jmdep))
+
+  WRITE(lunout,*)
+  WRITE(lunout,'(a,i3,a)')'LECTURE ET INTERPOLATION HORIZ. DE ',lmdep,' CHAMPS.'
+  ierr=NF90_INQ_VARID(ncid,varname,varid);                 CALL ncerr(ierr,fnam)
+  DO l=1,lmdep
+    ierr=NF90_GET_VAR(ncid,varid,champ,(/1,1,l/),(/imdep,jmdep,1/))
+    CALL ncerr(ierr,fnam)
+    CALL conf_dat2d(title,imdep,jmdep,dlon_ini,dlat_ini,dlon,dlat,champ,ibar)
+
+    IF(extrp) CALL extrapol(champ,imdep,jmdep,999999.,.TRUE.,.TRUE.,2,work)
+
+    IF(ibar.AND..NOT.(mode=='SIC'.AND.flag)) THEN
+      IF(l==1) THEN
+        WRITE(lunout,*)                                                        &
+  '-------------------------------------------------------------------------'
+        WRITE(lunout,*)                                                        &
+  '$$$ Utilisation de l''interpolation barycentrique pour '//TRIM(title)//' $$$'
+        WRITE(lunout,*)                                                        &
+  '-------------------------------------------------------------------------'
+      END IF
+      IF(mode=='RUG') champ=LOG(champ)
+      CALL inter_barxy(imdep, jmdep-1, dlon, dlat, champ, iim, jjm, rlonu,     &
+                         rlatv, jjp1, champint)
+      IF(mode=='RUG') THEN
+        champint=EXP(champint)
+        WHERE(NINT(mask)/=1) champint=0.001
+      END IF
+    ELSE
+      SELECT CASE(mode)
+        CASE('RUG');       CALL rugosite(imdep, jmdep, dlon, dlat, champ,      &
+                                    iim, jjp1, rlonv, rlatu, champint, mask)
+        CASE('SIC');       CALL sea_ice (imdep, jmdep, dlon, dlat, champ,      &
+                                    iim, jjp1, rlonv, rlatu, champint)
+        CASE('SST','ALB'); CALL grille_m(imdep, jmdep, dlon, dlat, champ,      &
+                                    iim, jjp1, rlonv, rlatu, champint)
+      END SELECT
+    END IF
+    champtime(:,:,l)=champint
+  END DO
+  ierr=NF90_CLOSE(ncid);                                   CALL ncerr(ierr,fnam)
+
+  DEALLOCATE(dlon_ini,dlat_ini,dlon,dlat,champ)
+  IF(extrp) DEALLOCATE(work)
+
+!--- TIME INTERPOLATION --------------------------------------------------------
+  WRITE(lunout,*)
+  WRITE(lunout,*)'INTERPOLATION TEMPORELLE.'
+  WRITE(lunout,"(2x,' Vecteur temps en entree: ',10f6.1)") timeyear
+  WRITE(lunout,"(2x,' Vecteur temps en sortie de 0 a ',i3)") ndays
+  ALLOCATE(yder(lmdep),champan(iip1,jjp1,ndays))
+  DO j=1,jjp1
+    DO i=1,iim
+      CALL spline(timeyear,champtime(i,j,:),lmdep,1.e30,1.e30,yder)
+      DO k=1,ndays
+        time=FLOAT((k-1)*ndays_in)/FLOAT(ndays)
+        CALL splint(timeyear,champtime(i,j,:),yder,lmdep,time,by)
+        champan(i,j,k) = by
+      END DO
+    END DO
+  END DO
+  champan(iip1,:,:)=champan(1,:,:)
+  DEALLOCATE(yder,champtime,timeyear)
+
+!--- Checking the result
+  DO j=1,jjp1
+    CALL minmax(iip1,champan(1,j,10),chmin,chmax)
+    WRITE(lunout,*)' '//TRIM(title)//' au temps 10 ',chmin,chmax,j
+  END DO
+
+!--- SPECIAL FILTER FOR SST: SST>271.38 ----------------------------------------
+  IF(mode=='SST') THEN
+    WRITE(lunout,*) 'Filtrage de la SST: SST >= 271.38'
+    WHERE(champan<271.38) champan=271.38
+  END IF
+
+!--- SPECIAL FILTER FOR SIC: 0.0<SIC<1.0 ---------------------------------------
+  IF(mode=='SIC') THEN
+    WRITE(lunout,*) 'Filtrage de la SIC: 0.0 < Sea-ice < 1.0'
+    champan(:,:,:)=champan(:,:,:)/100.
+    champan(iip1,:,:)=champan(1,:,:)
+    WHERE(champan>1.0) champan=1.0
+    WHERE(champan<0.0) champan=0.0
+  END IF
+
+write(*,*)'coin1'
+!--- DYNAMICAL TO PHYSICAL GRID ------------------------------------------------
+  ALLOCATE(champo(klon,ndays))
+  DO k=1,ndays
+    CALL gr_dyn_fi(1,iip1,jjp1,klon,champan(1,1,k),champo(1,k))
+  END DO
+write(*,*)'coin2'
+  DEALLOCATE(champan)
+write(*,*)'coin3'
+END SUBROUTINE get_2Dfield
+!
+!-------------------------------------------------------------------------------
+
+
+
+!-------------------------------------------------------------------------------
+!
+FUNCTION year_len(y,cal_in)
+!
+!-------------------------------------------------------------------------------
+  USE ioipsl, ONLY : ioget_calendar,ioconf_calendar,lock_calendar,ioget_year_len
+  IMPLICIT NONE
+!-------------------------------------------------------------------------------
+! Arguments:
+  INTEGER                       :: year_len
+  INTEGER,           INTENT(IN) :: y
+  CHARACTER(LEN=*),  INTENT(IN) :: cal_in
+!-------------------------------------------------------------------------------
+! Local variables:
+  CHARACTER(LEN=20)             :: cal_out              ! calendar (for outputs)
+!-------------------------------------------------------------------------------
+!--- Getting the input calendar to reset at the end of the function
+  CALL ioget_calendar(cal_out)
+
+!--- Unlocking calendar and setting it to wanted one
+  CALL lock_calendar(.FALSE.); CALL ioconf_calendar(TRIM(cal_in))
+
+!--- Getting the number of days in this year
+  year_len=ioget_year_len(y)
+
+!--- Back to original calendar
+  CALL lock_calendar(.FALSE.); CALL ioconf_calendar(TRIM(cal_out))
+
+END FUNCTION year_len
+!
+!-------------------------------------------------------------------------------
+
+
+!-------------------------------------------------------------------------------
+!
+FUNCTION mid_months(y,cal_in,nm)
+!
+!-------------------------------------------------------------------------------
+  USE ioipsl, ONLY : ioget_calendar,ioconf_calendar,lock_calendar,ioget_mon_len
+  IMPLICIT NONE
+!-------------------------------------------------------------------------------
+! Arguments:
+  INTEGER,                INTENT(IN) :: y               ! year
+  CHARACTER(LEN=*),       INTENT(IN) :: cal_in          ! calendar
+  INTEGER,                INTENT(IN) :: nm              ! months/year number
+  REAL,    DIMENSION(nm)             :: mid_months      ! mid-month times
+!-------------------------------------------------------------------------------
+! Local variables:
+  CHARACTER(LEN=99)                  :: mess            ! error message
+  CHARACTER(LEN=20)                  :: cal_out         ! calendar (for outputs)
+  INTEGER, DIMENSION(nm)             :: mnth            ! months lengths (days)
+  INTEGER                            :: m               ! months counter
+  INTEGER                            :: nd              ! number of days
+!-------------------------------------------------------------------------------
+  nd=year_len(y,cal_in)
+
+  IF(nm==12) THEN
+
+  !--- Getting the input calendar to reset at the end of the function
+    CALL ioget_calendar(cal_out)
+
+  !--- Unlocking calendar and setting it to wanted one
+    CALL lock_calendar(.FALSE.); CALL ioconf_calendar(TRIM(cal_in))
+
+  !--- Getting the length of each month
+    DO m=1,nm; mnth(m)=ioget_mon_len(y,m); END DO
+
+  !--- Back to original calendar
+    CALL lock_calendar(.FALSE.); CALL ioconf_calendar(TRIM(cal_out))
+
+  ELSE IF(MODULO(nd,nm)/=0) THEN
+    WRITE(mess,'(a,i3,a,i3,a)')'Unconsistent calendar: ',nd,' days/year, but ',&
+      nm,' months/year. Months number should divide days number.'
+    CALL abort_gcm('mid_months',TRIM(mess),1)
+
+  ELSE
+    mnth=(/(m,m=1,nm,nd/nm)/)
+  END IF
+
+!--- Mid-months times
+  mid_months(1)=0.5*FLOAT(mnth(1))
+  DO k=2,nm
+    mid_months(k)=mid_months(k-1)+0.5*FLOAT(mnth(k-1)+mnth(k))
+  END DO
+
+END FUNCTION mid_months
+!
+!-------------------------------------------------------------------------------
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE ncerr(ncres,fnam)
+!
+!-------------------------------------------------------------------------------
+! Purpose: NetCDF errors handling.
+!-------------------------------------------------------------------------------
+  USE netcdf, ONLY : NF90_NOERR, NF90_STRERROR
+  IMPLICIT NONE
+!-------------------------------------------------------------------------------
+! Arguments:
+  INTEGER,          INTENT(IN) :: ncres
+  CHARACTER(LEN=*), INTENT(IN) :: fnam
+!-------------------------------------------------------------------------------
+#include "iniprint.h"
+  IF(ncres/=NF90_NOERR) THEN
+    WRITE(lunout,*)'Problem with file '//TRIM(fnam)//' in routine limit_netcdf.'
+    CALL abort_gcm('limit_netcdf',NF90_STRERROR(ncres),1)
+  END IF
+
+END SUBROUTINE ncerr
+!
+!-------------------------------------------------------------------------------
+
+
+END SUBROUTINE limit_netcdf
Index: LMDZ4/trunk/libf/dyn3d/logic.h
===================================================================
--- LMDZ4/trunk/libf/dyn3d/logic.h	(revision 1318)
+++ LMDZ4/trunk/libf/dyn3d/logic.h	(revision 1319)
@@ -1,4 +1,4 @@
 !
-! $Header$
+! $Id$
 !
 !
@@ -9,9 +9,11 @@
       COMMON/logic/ purmats,iflag_phys,forward,leapf,apphys,            &
      &  statcl,conser,apdiss,apdelq,saison,ecripar,fxyhypb,ysinus       &
-     &  ,read_start,ok_guide,ok_strato,ok_gradsfile
+     &  ,read_start,ok_guide,ok_strato,ok_gradsfile                     &
+     &  ,ok_limit,ok_etat0
 
       LOGICAL purmats,forward,leapf,apphys,statcl,conser,               &
      & apdiss,apdelq,saison,ecripar,fxyhypb,ysinus                      &
-     &  ,read_start,ok_guide,ok_strato,ok_gradsfile
+     &  ,read_start,ok_guide,ok_strato,ok_gradsfile                     &
+     &  ,ok_limit,ok_etat0
 
       INTEGER iflag_phys
Index: LMDZ4/trunk/libf/dyn3d/startvar.F
===================================================================
--- LMDZ4/trunk/libf/dyn3d/startvar.F	(revision 1318)
+++ 	(revision )
@@ -1,1193 +1,0 @@
-!
-! $Id$
-!
-      MODULE startvar
-#ifdef CPP_EARTH
-! This module is designed to work for Earth (and with ioipsl)
-    !
-    !
-    !      There are three ways to access data from the database of atmospheric data which 
-    !       can be used to initialize the model. This depends on the type of field which needs 
-    !       to be extracted. In any case the call should come after a restget and should be of the type :
-    !                CALL startget(...)
-    !
-    !       We will details the possible arguments to startget here :
-    !
-    !        - A 2D variable on the dynamical grid :
-    !           CALL startget(varname, iml, jml, lon_in, lat_in, champ, val_ex, jml2, lon_in2, lat_in2, interbar )             
-    !
-    !        - A 1D variable on the physical grid :
-    !            CALL startget(varname, iml, jml, lon_in, lat_in, nbindex, champ, val_exp, jml2, lon_in2, lat_in2, interbar )
-    !
-    !
-    !         - A 3D variable on the dynamical grid :
-    !            CALL startget(varname, iml, jml, lon_in, lat_in, lml, pls, workvar, champ, val_exp, jml2, lon_in2, lat_in2, interbar )
-    !
-    !
-    !         There is special constraint on the atmospheric data base except that the 
-    !         the data needs to be in netCDF and the variables should have the the following 
-    !        names in the file :
-    !
-    !      'RELIEF'  : High resolution orography 
-    !       'ST'            : Surface temperature
-    !       'CDSW'     : Soil moisture
-    !       'Z'               : Surface geopotential
-    !       'SP'            : Surface pressure
-    !        'U'              : East ward wind
-    !        'V'              : Northward wind
-    !        'TEMP'             : Temperature
-    !        'R'             : Relative humidity
-    !      
-      USE ioipsl
-    !
-    !
-      IMPLICIT NONE
-    !
-    !
-      PRIVATE
-      PUBLIC startget
-    !
-    !
-      INTERFACE startget
-        MODULE PROCEDURE startget_phys2d, startget_phys1d, startget_dyn
-      END INTERFACE
-    !
-      INTEGER, SAVE :: fid_phys, fid_dyn
-      INTEGER, SAVE  :: iml_phys, iml_rel, iml_dyn
-      INTEGER, SAVE :: jml_phys,  jml_rel, jml_dyn
-      INTEGER, SAVE ::  llm_dyn, ttm_dyn
-      REAL, ALLOCATABLE, SAVE, DIMENSION (:,:)  :: lon_phys, lon_rug,
-     . lon_alb, lon_rel, lon_dyn
-      REAL, ALLOCATABLE, SAVE, DIMENSION (:,:)  :: lat_phys, lat_rug,
-     . lat_alb, lat_rel, lat_dyn
-      REAL, ALLOCATABLE, SAVE, DIMENSION (:)  :: levdyn_ini
-      REAL, ALLOCATABLE, SAVE, DIMENSION (:,:)  :: relief, zstd, zsig,
-     . zgam, zthe, zpic, zval
-      REAL, ALLOCATABLE, SAVE, DIMENSION (:,:)  :: rugo, masque, phis
-    !
-      REAL, ALLOCATABLE, SAVE, DIMENSION (:,:)  :: tsol, qsol, psol_dyn
-      REAL, ALLOCATABLE, SAVE, DIMENSION (:,:,:)  ::   var_ana3d
-    !
-      CONTAINS
-    !
-    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-    !
-      SUBROUTINE startget_phys2d(varname, iml, jml, lon_in, lat_in,
-     . champ, val_exp, jml2, lon_in2, lat_in2 , interbar, masque_lu )
-    !
-    !    There is a big mess with the size in logitude, should it be iml or iml+1.
-    !    I have chosen to use the iml+1 as an argument to this routine and we declare
-    !   internaly smaler fields when needed. This needs to be cleared once and for all in LMDZ. 
-    !  A convention is required.
-    !
-    !
-      CHARACTER*(*), INTENT(in) :: varname
-      INTEGER, INTENT(in) :: iml, jml ,jml2
-      REAL, INTENT(in) :: lon_in(iml), lat_in(jml)
-      REAL, INTENT(in) :: lon_in2(iml), lat_in2(jml2)
-      REAL, INTENT(inout) :: champ(iml,jml)
-      REAL, INTENT(in) :: val_exp
-      REAL, INTENT(in), optional :: masque_lu(iml,jml) 
-      LOGICAL interbar
-    !
-    !   This routine only works if the variable does not exist or is constant
-    !
-      IF ( MINVAL(champ(:,:)).EQ.MAXVAL(champ(:,:)) .AND. 
-     .MINVAL(champ(:,:)).EQ.val_exp ) THEN
-          !
-          SELECTCASE(varname)
-              !
-              CASE ('relief')
-                  !
-                  !  If we do not have the orography we need to get it
-                  !
-                  IF ( .NOT.ALLOCATED(relief)) THEN
-                      !
-                    if (present(masque_lu)) then
-                      CALL start_init_orog( iml, jml, lon_in, lat_in,
-     .                    jml2,lon_in2,lat_in2, interbar, masque_lu )
-                    else
-                      CALL start_init_orog( iml, jml, lon_in, lat_in,
-     .                    jml2,lon_in2,lat_in2, interbar)
-                    endif
-                      !
-                  ENDIF
-                  !
-                  IF (SIZE(relief) .NE. SIZE(champ)) THEN
-                      !
-                      WRITE(*,*) 'STARTVAR module has been',
-     .' initialized to the wrong size'
-                      STOP
-                      !
-                  ENDIF
-                  !
-                  champ(:,:) = relief(:,:)
-                  !
-              CASE ('rugosite')
-                  !
-                  !  If we do not have the orography we need to get it
-                  !
-                  IF ( .NOT.ALLOCATED(rugo)) THEN
-                      !
-                      CALL start_init_orog( iml, jml, lon_in, lat_in,
-     .                    jml2,lon_in2,lat_in2 , interbar )
-                      !
-                  ENDIF
-                  !
-                  IF (SIZE(rugo) .NE. SIZE(champ)) THEN
-                      !
-                      WRITE(*,*) 
-     .  'STARTVAR module has been initialized to the wrong size'
-                      STOP
-                      !
-                  ENDIF
-                  !
-                  champ(:,:) = rugo(:,:)
-                  !
-              CASE ('masque')
-                  !
-                  !  If we do not have the orography we need to get it
-                  !
-                  IF ( .NOT.ALLOCATED(masque)) THEN
-                      !
-                      CALL start_init_orog( iml, jml, lon_in, lat_in,
-     .                     jml2,lon_in2,lat_in2 , interbar )
-                      !
-                  ENDIF
-                  !
-                  IF (SIZE(masque) .NE. SIZE(champ)) THEN
-                      !
-                      WRITE(*,*) 
-     .   'STARTVAR module has been initialized to the wrong size'
-                      STOP
-                      !
-                  ENDIF
-                  !
-                  champ(:,:) = masque(:,:)
-                  !
-              CASE ('surfgeo')
-                  !
-                  !  If we do not have the orography we need to get it
-                  !
-                  IF ( .NOT.ALLOCATED(phis)) THEN
-                      !
-                      CALL start_init_orog( iml, jml, lon_in, lat_in,
-     .                   jml2,lon_in2, lat_in2 , interbar )
-                      !
-                  ENDIF
-                  !
-                  IF (SIZE(phis) .NE. SIZE(champ)) THEN
-                      !
-                      WRITE(*,*)
-     . 'STARTVAR module has been initialized to the wrong size'
-                      STOP
-                      !
-                  ENDIF
-                  !
-                  champ(:,:) = phis(:,:)
-                  !
-              CASE ('psol')
-                  !
-                  !  If we do not have the orography we need to get it
-                  !
-                  IF ( .NOT.ALLOCATED(psol_dyn)) THEN
-                      !
-                      CALL start_init_dyn( iml, jml, lon_in, lat_in,
-     .                   jml2,lon_in2, lat_in2 , interbar )
-                      !
-                  ENDIF
-                  !
-                  IF (SIZE(psol_dyn) .NE. SIZE(champ)) THEN
-                      !
-                      WRITE(*,*)
-     . 'STARTVAR module has been initialized to the wrong size'
-                      STOP
-                      !
-                  ENDIF
-                  !
-                  champ(:,:) = psol_dyn(:,:)
-                  !
-              CASE DEFAULT
-                  !
-                  WRITE(*,*) 'startget_phys2d'
-                  WRITE(*,*) 'No rule is present to extract variable', 
-     .                 varname(:LEN_TRIM(varname)),' from any data set'
-                  STOP
-                  !
-          END SELECT
-          !
-      ELSE
-          !
-          ! There are a few fields we might need if we need to interpolate 3D filed. Thus if they come through here we
-          ! will catch them
-          !
-          SELECTCASE(varname)
-              !
-              CASE ('surfgeo')
-                  !
-                  IF ( .NOT.ALLOCATED(phis)) THEN
-                      ALLOCATE(phis(iml,jml))
-                  ENDIF
-                  !
-                  IF (SIZE(phis) .NE. SIZE(champ)) THEN
-                      !
-                      WRITE(*,*)
-     .  'STARTVAR module has been initialized to the wrong size'
-                      STOP
-                      !
-                  ENDIF
-                  !
-                  phis(:,:) = champ(:,:)
-                  !
-          END SELECT
-          !
-      ENDIF
-    !
-      END SUBROUTINE startget_phys2d
-    !
-    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-    !
-      SUBROUTINE start_init_orog ( iml,jml,lon_in, lat_in,jml2,lon_in2 ,
-     ,   lat_in2 , interbar, masque_lu )
-    !
-      INTEGER, INTENT(in) :: iml, jml, jml2
-      REAL, INTENT(in) :: lon_in(iml), lat_in(jml)
-      REAL, INTENT(in) :: lon_in2(iml), lat_in2(jml2)
-      REAL, intent(in), optional :: masque_lu(iml,jml)
-      LOGICAL interbar
-    !
-    !  LOCAL
-    !
-      LOGICAL interbar2
-      REAL :: lev(1), date, dt,chmin,chmax
-      INTEGER :: itau(1), fid
-      INTEGER ::  llm_tmp, ttm_tmp
-      INTEGER :: i, j
-      INTEGER :: iret
-      CHARACTER*25 title
-      REAL, ALLOCATABLE :: relief_hi(:,:)
-      REAL, ALLOCATABLE :: lon_rad(:), lat_rad(:)
-      REAL, ALLOCATABLE :: lon_ini(:), lat_ini(:)
-      REAL, ALLOCATABLE :: tmp_var(:,:)
-      INTEGER, ALLOCATABLE :: tmp_int(:,:)
-    !
-      CHARACTER*120 :: orogfname
-      LOGICAL :: check=.TRUE.
-    !
-    !
-      orogfname = 'Relief.nc'
-    !
-      IF ( check ) WRITE(*,*) 'Reading the high resolution orography'
-    !
-      CALL flininfo(orogfname,iml_rel, jml_rel, llm_tmp, ttm_tmp, fid)
-    !
-      ALLOCATE (lat_rel(iml_rel,jml_rel), stat=iret)
-      ALLOCATE (lon_rel(iml_rel,jml_rel), stat=iret)
-      ALLOCATE (relief_hi(iml_rel,jml_rel), stat=iret)
-    !
-      CALL flinopen(orogfname, .FALSE., iml_rel, jml_rel, 
-     .llm_tmp, lon_rel, lat_rel, lev, ttm_tmp,
-     .      itau, date, dt, fid)
-    !
-      CALL flinget(fid, 'RELIEF', iml_rel, jml_rel, llm_tmp, 
-     . ttm_tmp, 1, 1, relief_hi)
-    !
-      CALL flinclo(fid)
-    !
-    !   In case we have a file which is in degrees we do the transformation
-    !
-      ALLOCATE(lon_rad(iml_rel))
-      ALLOCATE(lon_ini(iml_rel))
-
-      IF ( MAXVAL(lon_rel(:,:)) .GT. 2.0 * ASIN(1.0) ) THEN
-          lon_ini(:) = lon_rel(:,1) * 2.0 * ASIN(1.0) / 180.0
-      ELSE
-          lon_ini(:) = lon_rel(:,1) 
-      ENDIF
-
-      ALLOCATE(lat_rad(jml_rel))
-      ALLOCATE(lat_ini(jml_rel))
-
-      IF ( MAXVAL(lat_rel(:,:)) .GT. 2.0 * ASIN(1.0) ) THEN
-          lat_ini(:) = lat_rel(1,:) * 2.0 * ASIN(1.0) / 180.0
-      ELSE
-          lat_ini(:) = lat_rel(1,:) 
-      ENDIF
-    !
-    !
-
-      title='RELIEF'
-
-      interbar2 = .FALSE.
-      CALL conf_dat2d(title,iml_rel, jml_rel, lon_ini, lat_ini,
-     . lon_rad, lat_rad, relief_hi , interbar2  )
-
-      IF ( check ) WRITE(*,*) 'Computes all the parameters needed',
-     .' for the gravity wave drag code'
-    !
-    !    Allocate the data we need to put in the interpolated fields
-    !
-    !            RELIEF:  orographie moyenne
-      ALLOCATE(relief(iml,jml))
-    !            zphi :  orographie moyenne
-      ALLOCATE(phis(iml,jml))
-    !             zstd:  deviation standard de l'orographie sous-maille
-      ALLOCATE(zstd(iml,jml))
-    !             zsig:  pente de l'orographie sous-maille 
-      ALLOCATE(zsig(iml,jml))
-    !             zgam:  anisotropy de l'orographie sous maille
-      ALLOCATE(zgam(iml,jml))
-    !             zthe:  orientation de l'axe oriente dans la direction
-    !                    de plus grande pente de l'orographie sous maille
-      ALLOCATE(zthe(iml,jml))
-    !             zpic:  hauteur pics de la SSO
-      ALLOCATE(zpic(iml,jml))
-    !             zval:  hauteur vallees de la SSO
-      ALLOCATE(zval(iml,jml))
-    !             masque : Masque terre ocean
-      ALLOCATE(tmp_int(iml,jml))
-      ALLOCATE(masque(iml,jml))
-
-      masque = -99999.
-      if (present(masque_lu)) then
-        masque = masque_lu
-      endif
-    !
-      CALL grid_noro(iml_rel, jml_rel, lon_rad, lat_rad, relief_hi,
-     . iml-1, jml, lon_in, lat_in, 
-     . phis, relief, zstd, zsig, zgam, zthe, zpic, zval, masque)
-      phis = phis * 9.81
-    !
-!      masque(:,:) = FLOAT(tmp_int(:,:))
-    !
-    !  Compute surface roughness
-    !
-      IF ( check ) WRITE(*,*) 
-     .'Compute surface roughness induced by the orography'
-    !
-      ALLOCATE(rugo(iml,jml))
-      ALLOCATE(tmp_var(iml-1,jml))
-    !
-      CALL rugsoro(iml_rel, jml_rel, lon_rad, lat_rad, relief_hi,
-     . iml-1, jml, lon_in, lat_in, tmp_var)
-    !
-      DO j = 1, jml
-        DO i = 1, iml-1
-          rugo(i,j) = tmp_var(i,j)
-        ENDDO
-        rugo(iml,j) = tmp_var(1,j)
-      ENDDO
-c
-cc   ***   rugo  n'est pas utilise pour l'instant  ******
-    !
-    !   Build land-sea mask
-    !
-    !
-      RETURN
-    !
-      END SUBROUTINE start_init_orog
-    !
-    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-    !
-      SUBROUTINE startget_phys1d(varname, iml, jml, lon_in, 
-     .lat_in, nbindex, champ, val_exp ,jml2, lon_in2, lat_in2,interbar)
-    !
-      CHARACTER*(*), INTENT(in) :: varname
-      INTEGER, INTENT(in) :: iml, jml, nbindex, jml2
-      REAL, INTENT(in) :: lon_in(iml), lat_in(jml)
-      REAL, INTENT(in) :: lon_in2(iml), lat_in2(jml2)
-      REAL, INTENT(inout) :: champ(nbindex)
-      REAL, INTENT(in) :: val_exp
-      LOGICAL interbar
-    !
-    !
-    !   This routine only works if the variable does not exist or is constant
-    !
-      IF ( MINVAL(champ(:)).EQ.MAXVAL(champ(:)) .AND. 
-     .MINVAL(champ(:)).EQ.val_exp ) THEN
-          SELECTCASE(varname)
-            CASE ('tsol')
-              IF ( .NOT.ALLOCATED(tsol)) THEN
-                CALL start_init_phys( iml, jml, lon_in, lat_in,
-     .              jml2, lon_in2, lat_in2, interbar )
-              ENDIF
-              IF ( SIZE(tsol) .NE. SIZE(lon_in)*SIZE(lat_in) ) THEN
-                WRITE(*,*) 
-     . 'STARTVAR module has been initialized to the wrong size'
-                 STOP
-              ENDIF
-              CALL gr_dyn_fi(1, iml, jml, nbindex, tsol, champ)
-            CASE ('qsol')
-              IF ( .NOT.ALLOCATED(qsol)) THEN
-                CALL start_init_phys( iml, jml, lon_in, lat_in,
-     .              jml2, lon_in2,lat_in2 , interbar )
-              ENDIF
-              IF ( SIZE(qsol) .NE. SIZE(lon_in)*SIZE(lat_in) ) THEN
-                WRITE(*,*) 
-     . 'STARTVAR module has been initialized to the wrong size'
-                STOP
-              ENDIF
-              CALL gr_dyn_fi(1, iml, jml, nbindex, qsol, champ)
-            CASE ('psol')
-              IF ( .NOT.ALLOCATED(psol_dyn)) THEN
-                CALL start_init_dyn( iml, jml, lon_in, lat_in,
-     .              jml2, lon_in2,lat_in2 , interbar )
-              ENDIF
-              IF (SIZE(psol_dyn) .NE. SIZE(lon_in)*SIZE(lat_in)) THEN
-                WRITE(*,*) 
-     . 'STARTVAR module has been initialized to the wrong size'
-                STOP
-              ENDIF
-              CALL gr_dyn_fi(1, iml, jml, nbindex, psol_dyn, champ)
-            CASE ('zmea')
-              IF ( .NOT.ALLOCATED(relief)) THEN
-                CALL start_init_orog( iml, jml, lon_in, lat_in,
-     .            jml2, lon_in2,lat_in2 , interbar )
-              ENDIF
-              IF ( SIZE(relief) .NE. SIZE(lon_in)*SIZE(lat_in) ) THEN
-                WRITE(*,*)
-     . 'STARTVAR module has been initialized to the wrong size'
-                 STOP
-              ENDIF
-              CALL gr_dyn_fi(1, iml, jml, nbindex, relief, champ)
-            CASE ('zstd')
-              IF ( .NOT.ALLOCATED(zstd)) THEN
-                CALL start_init_orog( iml, jml, lon_in, lat_in,
-     .              jml2, lon_in2,lat_in2 , interbar )
-              ENDIF
-              IF ( SIZE(zstd) .NE. SIZE(lon_in)*SIZE(lat_in) ) THEN
-                WRITE(*,*)
-     . 'STARTVAR module has been initialized to the wrong size'
-                 STOP
-              ENDIF
-              CALL gr_dyn_fi(1, iml, jml, nbindex,zstd, champ)
-            CASE ('zsig')
-              IF ( .NOT.ALLOCATED(zsig)) THEN
-                CALL start_init_orog( iml, jml, lon_in, lat_in,
-     .               jml2, lon_in2,lat_in2 , interbar )
-              ENDIF
-              IF ( SIZE(zsig) .NE. SIZE(lon_in)*SIZE(lat_in) ) THEN
-                WRITE(*,*)
-     . 'STARTVAR module has been initialized to the wrong size'
-                 STOP
-              ENDIF
-              CALL gr_dyn_fi(1, iml, jml, nbindex,zsig, champ)
-            CASE ('zgam')
-              IF ( .NOT.ALLOCATED(zgam)) THEN
-                CALL start_init_orog( iml, jml, lon_in, lat_in,
-     .            jml2, lon_in2,lat_in2 , interbar )
-              ENDIF
-              IF ( SIZE(zgam) .NE. SIZE(lon_in)*SIZE(lat_in) ) THEN
-                WRITE(*,*)
-     . 'STARTVAR module has been initialized to the wrong size'
-                 STOP
-              ENDIF
-              CALL gr_dyn_fi(1, iml, jml, nbindex,zgam, champ)
-            CASE ('zthe')
-              IF ( .NOT.ALLOCATED(zthe)) THEN
-                CALL start_init_orog( iml, jml, lon_in, lat_in,
-     .            jml2, lon_in2,lat_in2 , interbar )
-              ENDIF
-              IF ( SIZE(zthe) .NE. SIZE(lon_in)*SIZE(lat_in) ) THEN
-                WRITE(*,*)
-     . 'STARTVAR module has been initialized to the wrong size'
-                 STOP
-              ENDIF
-              CALL gr_dyn_fi(1, iml, jml, nbindex,zthe, champ)
-            CASE ('zpic')
-              IF ( .NOT.ALLOCATED(zpic)) THEN
-                CALL start_init_orog( iml, jml, lon_in, lat_in,
-     .            jml2, lon_in2,lat_in2 , interbar )
-              ENDIF
-              IF ( SIZE(zpic) .NE. SIZE(lon_in)*SIZE(lat_in) ) THEN
-                WRITE(*,*)
-     . 'STARTVAR module has been initialized to the wrong size'
-                 STOP
-              ENDIF
-              CALL gr_dyn_fi(1, iml, jml, nbindex,zpic, champ)
-            CASE ('zval')
-              IF ( .NOT.ALLOCATED(zval)) THEN
-                CALL start_init_orog( iml, jml, lon_in, lat_in,
-     .            jml2, lon_in2,lat_in2 , interbar )
-              ENDIF
-              IF ( SIZE(zval) .NE. SIZE(lon_in)*SIZE(lat_in) ) THEN
-                WRITE(*,*)
-     . 'STARTVAR module has been initialized to the wrong size'
-                 STOP
-              ENDIF
-              CALL gr_dyn_fi(1, iml, jml, nbindex,zval, champ)
-            CASE ('rads')
-                  champ(:) = 0.0
-            CASE ('snow')
-                  champ(:) = 0.0
-cIM "slab" ocean
-            CASE ('tslab')
-                   champ(:) = 0.0
-            CASE ('seaice')
-                  champ(:) = 0.0
-            CASE ('rugmer')
-                  champ(:) = 0.001
-            CASE ('agsno')
-                  champ(:) = 50.0
-            CASE DEFAULT
-              WRITE(*,*) 'startget_phys1d'
-              WRITE(*,*) 'No rule is present to extract variable  ',
-     . varname(:LEN_TRIM(varname)),' from any data set'
-              STOP
-          END SELECT
-      ELSE
-        !
-        ! If we see tsol we catch it as we may need it for a 3D interpolation
-        !
-        SELECTCASE(varname)
-          CASE ('tsol')
-            IF ( .NOT.ALLOCATED(tsol)) THEN
-              ALLOCATE(tsol(SIZE(lon_in),SIZE(lat_in) ))
-            ENDIF
-            CALL gr_fi_dyn(1, iml, jml, nbindex, champ, tsol)
-        END SELECT
-      ENDIF
-      END SUBROUTINE startget_phys1d
-    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-    !
-      SUBROUTINE start_init_phys( iml, jml, lon_in, lat_in, jml2,
-     .                 lon_in2, lat_in2 , interbar )
-    !
-      INTEGER, INTENT(in) :: iml, jml ,jml2
-      REAL, INTENT(in) :: lon_in(iml), lat_in(jml)
-      REAL, INTENT(in) :: lon_in2(iml), lat_in2(jml2)
-      LOGICAL interbar
-    !
-    !  LOCAL
-    !
-!ac     REAL :: lev(1), date, dt
-      REAL :: date, dt
-      REAL, DIMENSION(:), ALLOCATABLE :: levphys_ini
-!ac
-      INTEGER :: itau(1)
-      INTEGER ::  llm_tmp, ttm_tmp
-      INTEGER :: i, j
-    !
-      CHARACTER*25 title
-      CHARACTER*120 :: physfname
-      LOGICAL :: check=.TRUE.
-    !
-      REAL, ALLOCATABLE :: lon_rad(:), lat_rad(:)
-      REAL, ALLOCATABLE :: lon_ini(:), lat_ini(:)
-      REAL, ALLOCATABLE :: var_ana(:,:), tmp_var(:,:)
-    !
-      physfname = 'ECPHY.nc'
-    !
-      IF ( check ) WRITE(*,*) 'Opening the surface analysis'
-    !
-      CALL flininfo(physfname, iml_phys, jml_phys, llm_tmp,
-     . ttm_tmp, fid_phys)
-    !
-      ALLOCATE (lat_phys(iml_phys,jml_phys))
-      ALLOCATE (lon_phys(iml_phys,jml_phys))
-!ac
-      ALLOCATE (levphys_ini(llm_tmp))
-    !
-!      CALL flinopen(physfname, .FALSE., iml_phys, jml_phys, 
-!     . llm_tmp, lon_phys, lat_phys, lev, ttm_tmp, 
-!     . itau, date, dt, fid_phys)
-    !
-      CALL flinopen(physfname, .FALSE., iml_phys, jml_phys, 
-     . llm_tmp, lon_phys, lat_phys, levphys_ini, ttm_tmp, 
-     . itau, date, dt, fid_phys)
-    !
-      DEALLOCATE (levphys_ini)
-!ac
-    !
-    ! Allocate the space we will need to get the data out of this file
-    !
-      ALLOCATE(var_ana(iml_phys, jml_phys))
-    !
-    !   In case we have a file which is in degrees we do the transformation
-    !
-      ALLOCATE(lon_rad(iml_phys))
-      ALLOCATE(lon_ini(iml_phys))
-
-      IF ( MAXVAL(lon_phys(:,:)) .GT. 2.0 * ASIN(1.0) ) THEN
-          lon_ini(:) = lon_phys(:,1) * 2.0 * ASIN(1.0) / 180.0
-      ELSE
-          lon_ini(:) = lon_phys(:,1) 
-      ENDIF
-
-      ALLOCATE(lat_rad(jml_phys))
-      ALLOCATE(lat_ini(jml_phys))
-
-      IF ( MAXVAL(lat_phys(:,:)) .GT. 2.0 * ASIN(1.0) ) THEN
-          lat_ini(:) = lat_phys(1,:) * 2.0 * ASIN(1.0) / 180.0
-      ELSE
-          lat_ini(:) = lat_phys(1,:) 
-      ENDIF
-
-
-    !
-    !   We get the two standard varibales
-    !   Surface temperature
-    !
-      ALLOCATE(tsol(iml,jml))
-      ALLOCATE(tmp_var(iml-1,jml))
-    !
-    !
-
-      CALL flinget(fid_phys, 'ST', iml_phys, jml_phys, 
-     .llm_tmp, ttm_tmp, 1, 1, var_ana)
-
-      title='ST'
-      CALL conf_dat2d(title,iml_phys, jml_phys, lon_ini, lat_ini,
-     . lon_rad, lat_rad, var_ana , interbar  )
-
-      IF ( interbar )   THEN
-        WRITE(6,*) '-------------------------------------------------',
-     ,'--------------'
-        WRITE(6,*) '$$$ Utilisation de l interpolation barycentrique ',
-     , ' pour  ST $$$ '
-        WRITE(6,*) '-------------------------------------------------',
-     ,'--------------'
-        CALL inter_barxy ( iml_phys,jml_phys -1,lon_rad,lat_rad ,
-     ,   var_ana, iml-1, jml-1, lon_in2, lat_in2, jml, tmp_var   ) 
-      ELSE
-        CALL grille_m(iml_phys, jml_phys, lon_rad, lat_rad,
-     .    var_ana, iml-1, jml, lon_in, lat_in, tmp_var     )
-      ENDIF
-
-      CALL gr_int_dyn(tmp_var, tsol, iml-1, jml)
-    !
-    ! Soil moisture
-    !
-      ALLOCATE(qsol(iml,jml))
-      CALL flinget(fid_phys, 'CDSW', iml_phys, jml_phys,
-     . llm_tmp, ttm_tmp, 1, 1, var_ana)
-
-      title='CDSW'
-      CALL conf_dat2d(title,iml_phys, jml_phys, lon_ini, lat_ini,
-     . lon_rad, lat_rad, var_ana, interbar  )
-
-      IF ( interbar )   THEN
-        WRITE(6,*) '-------------------------------------------------',
-     ,'--------------'
-        WRITE(6,*) '$$$ Utilisation de l interpolation barycentrique ',
-     , ' pour  CDSW $$$ '
-        WRITE(6,*) '-------------------------------------------------',
-     ,'--------------'
-        CALL inter_barxy ( iml_phys,jml_phys -1,lon_rad,lat_rad ,
-     ,   var_ana, iml-1, jml-1, lon_in2, lat_in2, jml, tmp_var  )
-      ELSE
-        CALL grille_m(iml_phys, jml_phys, lon_rad, lat_rad,
-     .    var_ana, iml-1, jml, lon_in, lat_in, tmp_var     )
-      ENDIF
-c
-        CALL gr_int_dyn(tmp_var, qsol, iml-1, jml)
-    !
-       CALL flinclo(fid_phys)
-    !
-      END SUBROUTINE start_init_phys
-    !
-    !
-    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-    !
-    !
-      SUBROUTINE startget_dyn(varname, iml, jml, lon_in, lat_in,
-     . lml, pls, workvar, champ, val_exp,jml2, lon_in2, lat_in2 ,
-     ,  interbar )
-    !
-    !   ARGUMENTS
-    !
-      CHARACTER*(*), INTENT(in) :: varname
-      INTEGER, INTENT(in) :: iml, jml, lml, jml2
-      REAL, INTENT(in) :: lon_in(iml), lat_in(jml)
-      REAL, INTENT(in) :: lon_in2(iml), lat_in2(jml2)
-      REAL, INTENT(in) :: pls(iml, jml, lml)
-      REAL, INTENT(in) :: workvar(iml, jml, lml)
-      REAL, INTENT(inout) :: champ(iml, jml, lml)
-      REAL, INTENT(in) :: val_exp
-      LOGICAL interbar
-    !
-    !    LOCAL
-    !
-      INTEGER :: il, ij, ii
-      REAL :: xppn, xpps
-    !
-#include "dimensions.h"
-#include "paramet.h"
-#include "comgeom2.h"
-#include "comconst.h"
-    !
-    !   This routine only works if the variable does not exist or is constant
-    !
-      IF ( MINVAL(champ(:,:,:)).EQ.MAXVAL(champ(:,:,:)) .AND.
-     . MINVAL(champ(:,:,:)).EQ.val_exp ) THEN
-        !
-        SELECTCASE(varname)
-          CASE ('u')
-            IF ( .NOT.ALLOCATED(psol_dyn)) THEN
-              CALL start_init_dyn( iml, jml, lon_in, lat_in, jml2 ,
-     .          lon_in2,lat_in2 , interbar )
-            ENDIF
-            CALL start_inter_3d('U', iml, jml, lml, lon_in,
-     .       lat_in, jml2, lon_in2, lat_in2,  pls, champ,interbar )
-            DO il=1,lml
-              DO ij=1,jml
-                DO ii=1,iml-1
-                  champ(ii,ij,il) = champ(ii,ij,il) * cu(ii,ij)
-                ENDDO
-                champ(iml,ij, il) = champ(1,ij, il)
-              ENDDO
-            ENDDO
-          CASE ('v')
-            IF ( .NOT.ALLOCATED(psol_dyn)) THEN
-              CALL start_init_dyn( iml, jml, lon_in, lat_in , jml2, 
-     .           lon_in2, lat_in2 , interbar )
-            ENDIF
-            CALL start_inter_3d('V', iml, jml, lml, lon_in, 
-     .       lat_in, jml2, lon_in2, lat_in2,  pls, champ, interbar )
-            DO il=1,lml
-              DO ij=1,jml
-                DO ii=1,iml-1
-                  champ(ii,ij,il) = champ(ii,ij,il) * cv(ii,ij)
-                ENDDO
-                champ(iml,ij, il) = champ(1,ij, il)
-              ENDDO
-            ENDDO
-          CASE ('t')
-            IF ( .NOT.ALLOCATED(psol_dyn)) THEN
-              CALL start_init_dyn( iml, jml, lon_in, lat_in, jml2 ,
-     .           lon_in2, lat_in2 ,interbar )
-            ENDIF
-            CALL start_inter_3d('TEMP', iml, jml, lml, lon_in,
-     .       lat_in, jml2, lon_in2, lat_in2,  pls, champ, interbar )
- 
-          CASE ('tpot')
-            IF ( .NOT.ALLOCATED(psol_dyn)) THEN
-              CALL start_init_dyn( iml, jml, lon_in, lat_in , jml2 ,
-     .            lon_in2, lat_in2 , interbar )
-            ENDIF
-            CALL start_inter_3d('TEMP', iml, jml, lml, lon_in,
-     .       lat_in, jml2, lon_in2, lat_in2,  pls, champ, interbar )
-            IF ( MINVAL(workvar(:,:,:)) .NE. MAXVAL(workvar(:,:,:)) )
-     .                                    THEN
-              DO il=1,lml
-                DO ij=1,jml
-                  DO ii=1,iml-1
-                    champ(ii,ij,il) = champ(ii,ij,il) * cpp 
-     .                                 / workvar(ii,ij,il)
-                  ENDDO
-                  champ(iml,ij,il) = champ(1,ij,il)
-                ENDDO
-              ENDDO
-              DO il=1,lml
-                xppn = SUM(aire(:,1)*champ(:,1,il))/apoln
-                xpps = SUM(aire(:,jml)*champ(:,jml,il))/apols
-                champ(:,1,il) = xppn
-                champ(:,jml,il) = xpps
-              ENDDO
-            ELSE
-              WRITE(*,*)'Could not compute potential temperature as the'
-              WRITE(*,*)'Exner function is missing or constant.'
-              STOP
-            ENDIF
-          CASE ('q')
-            IF ( .NOT.ALLOCATED(psol_dyn)) THEN
-              CALL start_init_dyn( iml, jml, lon_in, lat_in, jml2 ,
-     .           lon_in2, lat_in2 , interbar )
-            ENDIF
-            CALL start_inter_3d('R', iml, jml, lml, lon_in, lat_in,
-     .        jml2, lon_in2, lat_in2,  pls, champ, interbar )
-            IF ( MINVAL(workvar(:,:,:)) .NE. MAXVAL(workvar(:,:,:)) ) 
-     .                                     THEN
-              DO il=1,lml
-                DO ij=1,jml
-                  DO ii=1,iml-1
-                    champ(ii,ij,il) = 0.01 * champ(ii,ij,il) *
-     .                                       workvar(ii,ij,il)
-                  ENDDO
-                  champ(iml,ij,il) = champ(1,ij,il)
-                ENDDO
-              ENDDO
-              WHERE ( champ .LT. 0.) champ = 1.0E-10
-              DO il=1,lml
-                xppn = SUM(aire(:,1)*champ(:,1,il))/apoln
-                xpps = SUM(aire(:,jml)*champ(:,jml,il))/apols
-                champ(:,1,il) = xppn
-                champ(:,jml,il) = xpps
-              ENDDO
-            ELSE
-              WRITE(*,*)'Could not compute specific humidity as the'
-              WRITE(*,*)'saturated humidity is missing or constant.'
-              STOP
-            ENDIF
-          CASE DEFAULT
-            WRITE(*,*) 'startget_dyn'
-            WRITE(*,*) 'No rule is present to extract variable  ',
-     . varname(:LEN_TRIM(varname)),' from any data set'
-            STOP
-          END SELECT
-      ENDIF
-      END SUBROUTINE startget_dyn
-    !
-    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-    !
-      SUBROUTINE start_init_dyn( iml, jml, lon_in, lat_in,jml2,lon_in2 ,
-     ,             lat_in2 , interbar )
-    !
-      INTEGER, INTENT(in) :: iml, jml, jml2
-      REAL, INTENT(in) :: lon_in(iml), lat_in(jml)
-      REAL, INTENT(in) :: lon_in2(iml), lat_in2(jml2)
-      LOGICAL interbar
-    !
-    !  LOCAL
-    !
-      REAL :: lev(1), date, dt
-      INTEGER :: itau(1)
-      INTEGER :: i, j
-      integer :: iret
-    !
-      CHARACTER*120 :: physfname
-      LOGICAL :: check=.TRUE.
-    !
-      REAL, ALLOCATABLE :: lon_rad(:), lat_rad(:)
-      REAL, ALLOCATABLE :: lon_ini(:), lat_ini(:)
-      REAL, ALLOCATABLE :: var_ana(:,:), tmp_var(:,:), z(:,:)
-      REAL, ALLOCATABLE :: xppn(:), xpps(:)
-      LOGICAL :: allo
-    !
-    !
-#include "dimensions.h"
-#include "paramet.h"
-#include "comgeom2.h"
-
-      CHARACTER*25 title
-
-    !
-      physfname = 'ECDYN.nc'
-    !
-      IF ( check ) WRITE(*,*) 'Opening the surface analysis'
-    !
-      CALL flininfo(physfname, iml_dyn, jml_dyn, llm_dyn,
-     .                            ttm_dyn, fid_dyn)
-      IF ( check ) WRITE(*,*) 'Values read: ', iml_dyn, jml_dyn, 
-     .                                         llm_dyn, ttm_dyn
-    !
-      ALLOCATE (lat_dyn(iml_dyn,jml_dyn), stat=iret)
-      ALLOCATE (lon_dyn(iml_dyn,jml_dyn), stat=iret)
-      ALLOCATE (levdyn_ini(llm_dyn), stat=iret)
-    !
-      CALL flinopen(physfname, .FALSE., iml_dyn, jml_dyn, llm_dyn,
-     . lon_dyn, lat_dyn, levdyn_ini, ttm_dyn, 
-     . itau, date, dt, fid_dyn)
-    !
-
-      allo = allocated (var_ana)
-      if (allo) then
-        DEALLOCATE(var_ana, stat=iret)
-      endif
-      ALLOCATE(var_ana(iml_dyn, jml_dyn), stat=iret)
-
-      allo = allocated (lon_rad)
-      if (allo) then
-        DEALLOCATE(lon_rad, stat=iret)
-      endif
-
-      ALLOCATE(lon_rad(iml_dyn), stat=iret)
-      ALLOCATE(lon_ini(iml_dyn))
-       
-      IF ( MAXVAL(lon_dyn(:,:)) .GT. 2.0 * ASIN(1.0) ) THEN
-          lon_ini(:) = lon_dyn(:,1) * 2.0 * ASIN(1.0) / 180.0
-      ELSE
-          lon_ini(:) = lon_dyn(:,1) 
-      ENDIF
-
-      ALLOCATE(lat_rad(jml_dyn))
-      ALLOCATE(lat_ini(jml_dyn))
-
-      IF ( MAXVAL(lat_dyn(:,:)) .GT. 2.0 * ASIN(1.0) ) THEN
-          lat_ini(:) = lat_dyn(1,:) * 2.0 * ASIN(1.0) / 180.0
-      ELSE
-          lat_ini(:) = lat_dyn(1,:) 
-      ENDIF
-    !
-
-
-      ALLOCATE(z(iml, jml))
-      ALLOCATE(tmp_var(iml-1,jml))
-    !
-      CALL flinget(fid_dyn, 'Z', iml_dyn, jml_dyn, 0, ttm_dyn,
-     .              1, 1, var_ana)
-c
-      title='Z'
-      CALL conf_dat2d( title,iml_dyn, jml_dyn,lon_ini, lat_ini,
-     . lon_rad, lat_rad, var_ana, interbar  )
-c
-      IF ( interbar )   THEN
-        WRITE(6,*) '-------------------------------------------------',
-     ,'--------------'
-        WRITE(6,*) '$$$ Utilisation de l interpolation barycentrique ',
-     , ' pour  Z  $$$ '
-        WRITE(6,*) '-------------------------------------------------',
-     ,'--------------'
-        CALL inter_barxy ( iml_dyn,jml_dyn -1,lon_rad,lat_rad ,
-     ,    var_ana, iml-1, jml-1, lon_in2, lat_in2, jml, tmp_var) 
-      ELSE
-        CALL grille_m(iml_dyn, jml_dyn , lon_rad, lat_rad, var_ana,
-     .               iml-1, jml, lon_in, lat_in, tmp_var)
-      ENDIF
-
-      CALL gr_int_dyn(tmp_var, z, iml-1, jml)
-    !
-      ALLOCATE(psol_dyn(iml, jml))
-    !
-      CALL flinget(fid_dyn, 'SP', iml_dyn, jml_dyn, 0, ttm_dyn,
-     .              1, 1, var_ana)
-
-       title='SP'
-      CALL conf_dat2d( title,iml_dyn, jml_dyn,lon_ini, lat_ini,
-     . lon_rad, lat_rad, var_ana, interbar  )
-
-      IF ( interbar )   THEN
-        WRITE(6,*) '-------------------------------------------------',
-     ,'--------------'
-        WRITE(6,*) '$$$ Utilisation de l interpolation barycentrique ',
-     , ' pour  SP  $$$ '
-        WRITE(6,*) '-------------------------------------------------',
-     ,'--------------'
-        CALL inter_barxy ( iml_dyn,jml_dyn -1,lon_rad,lat_rad ,
-     ,    var_ana, iml-1, jml-1, lon_in2, lat_in2, jml, tmp_var) 
-      ELSE
-        CALL grille_m(iml_dyn, jml_dyn , lon_rad, lat_rad, var_ana,
-     .             iml-1, jml, lon_in, lat_in, tmp_var  )
-      ENDIF
-
-      CALL gr_int_dyn(tmp_var, psol_dyn, iml-1, jml)
-    !
-      IF ( .NOT.ALLOCATED(tsol)) THEN
-    !   These variables may have been allocated by the need to 
-    !   create a start field for them or by the varibale
-    !   coming out of the restart file. In case we dor have it we will initialize it.
-    !
-        CALL start_init_phys( iml, jml, lon_in, lat_in,jml2,lon_in2,
-     .                 lat_in2 , interbar )
-      ELSE
-        IF ( SIZE(tsol) .NE. SIZE(psol_dyn) ) THEN
-        WRITE(*,*) 'start_init_dyn :'
-        WRITE(*,*) 'The temperature field we have does not ',
-     .             'have the right size'
-        STOP
-      ENDIF
-      ENDIF
-      IF ( .NOT.ALLOCATED(phis)) THEN
-            !
-            !    These variables may have been allocated by the need to create a start field for them or by the varibale
-            !     coming out of the restart file. In case we dor have it we will initialize it.
-            !
-        CALL start_init_orog( iml, jml, lon_in, lat_in, jml2, lon_in2 ,
-     .      lat_in2 , interbar )
-            !
-      ELSE
-            !
-          IF (SIZE(phis) .NE. SIZE(psol_dyn)) THEN
-                !
-              WRITE(*,*) 'start_init_dyn :'
-              WRITE(*,*) 'The orography field we have does not ',
-     .                   ' have the right size'
-              STOP
-          ENDIF
-            !
-      ENDIF
-    !
-    !     PSOL is computed in Pascals
-    !
-    !
-      DO j = 1, jml
-        DO i = 1, iml-1
-          psol_dyn(i,j) = psol_dyn(i,j)*(1.0+(z(i,j)-phis(i,j)) 
-     .                    /287.0/tsol(i,j))
-        ENDDO
-        psol_dyn(iml,j) = psol_dyn(1,j)
-      ENDDO
-    !
-    !
-      ALLOCATE(xppn(iml-1))
-      ALLOCATE(xpps(iml-1)) 
-    !
-      DO  i   = 1, iml-1
-        xppn(i) = aire( i,1) * psol_dyn( i,1)
-        xpps(i) = aire( i,jml) * psol_dyn( i,jml)
-      ENDDO
-    !
-      DO i   = 1, iml
-        psol_dyn(i,1    )  = SUM(xppn)/apoln
-        psol_dyn(i,jml)  = SUM(xpps)/apols
-      ENDDO
-    !
-      RETURN
-    !
-      END SUBROUTINE start_init_dyn
-    !
-    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-    !
-      SUBROUTINE start_inter_3d(varname, iml, jml, lml, lon_in,
-     .      lat_in, jml2, lon_in2, lat_in2, pls_in, var3d, interbar )
-    !
-    !    This subroutine gets a variables from a 3D file and does the interpolations needed
-    !
-    !
-    !    ARGUMENTS
-    !
-      CHARACTER*(*) :: varname
-      INTEGER :: iml, jml, lml, jml2
-      REAL :: lon_in(iml), lat_in(jml), pls_in(iml, jml, lml)
-      REAL :: lon_in2(iml) , lat_in2(jml2)
-      REAL :: var3d(iml, jml, lml)
-      LOGICAL interbar
-      real chmin,chmax
-    !
-    !  LOCAL
-    !
-      CHARACTER*25 title
-      INTEGER :: ii, ij, il, jsort,i,j,l
-      REAL :: bx, by
-      REAL, ALLOCATABLE :: lon_rad(:), lat_rad(:)
-      REAL, ALLOCATABLE :: lon_ini(:), lat_ini(:) , lev_dyn(:)
-      REAL, ALLOCATABLE :: var_tmp2d(:,:), var_tmp3d(:,:,:)
-      REAL, ALLOCATABLE :: ax(:), ay(:), yder(:)
-!       REAL, ALLOCATABLE :: varrr(:,:,:)
-      INTEGER, ALLOCATABLE :: lind(:)
-    !
-      LOGICAL :: check = .TRUE.
-    !
-      IF ( .NOT. ALLOCATED(var_ana3d)) THEN
-          ALLOCATE(var_ana3d(iml_dyn, jml_dyn, llm_dyn))
-      ENDIF
-!          ALLOCATE(varrr(iml_dyn, jml_dyn, llm_dyn))
-    !
-    !
-      IF ( check) WRITE(*,*) 'Going into flinget to extract the 3D ',
-     .  ' field.', fid_dyn
-      IF ( check) WRITE(*,*) fid_dyn, varname, iml_dyn, jml_dyn,
-     .                        llm_dyn,ttm_dyn
-    !
-      CALL flinget(fid_dyn, varname, iml_dyn, jml_dyn, llm_dyn, 
-     . ttm_dyn, 1, 1, var_ana3d)
-    !
-      IF ( check) WRITE(*,*) 'Allocating space for the interpolation',
-     . iml, jml, llm_dyn
-    !
-      ALLOCATE(lon_rad(iml_dyn))
-      ALLOCATE(lon_ini(iml_dyn))
-
-      IF ( MAXVAL(lon_dyn(:,:)) .GT. 2.0 * ASIN(1.0) ) THEN
-          lon_ini(:) = lon_dyn(:,1) * 2.0 * ASIN(1.0) / 180.0
-      ELSE
-          lon_ini(:) = lon_dyn(:,1) 
-      ENDIF
-
-      ALLOCATE(lat_rad(jml_dyn))
-      ALLOCATE(lat_ini(jml_dyn))
-
-      ALLOCATE(lev_dyn(llm_dyn))
-
-      IF ( MAXVAL(lat_dyn(:,:)) .GT. 2.0 * ASIN(1.0) ) THEN
-          lat_ini(:) = lat_dyn(1,:) * 2.0 * ASIN(1.0) / 180.0
-      ELSE
-          lat_ini(:) = lat_dyn(1,:) 
-      ENDIF
-    !
-
-      CALL conf_dat3d ( varname,iml_dyn, jml_dyn, llm_dyn, lon_ini, 
-     . lat_ini, levdyn_ini, lon_rad, lat_rad, lev_dyn, var_ana3d  ,
-     ,  interbar                                                   )
-
-      ALLOCATE(var_tmp2d(iml-1, jml))
-      ALLOCATE(var_tmp3d(iml, jml, llm_dyn))
-      ALLOCATE(ax(llm_dyn))
-      ALLOCATE(ay(llm_dyn))
-      ALLOCATE(yder(llm_dyn))
-      ALLOCATE(lind(llm_dyn))
-    !
- 
-      DO il=1,llm_dyn
-        !
-      IF( interbar )  THEN
-       IF( il.EQ.1 )  THEN
-        WRITE(6,*) '-------------------------------------------------',
-     ,'--------------'
-        WRITE(6,*) '$$$ Utilisation de l interpolation barycentrique ',
-     , ' pour ', varname
-        WRITE(6,*) '-------------------------------------------------',
-     ,'--------------'
-       ENDIF
-       CALL inter_barxy ( iml_dyn, jml_dyn -1,lon_rad, lat_rad, 
-     , var_ana3d(:,:,il),iml-1, jml2, lon_in2, lat_in2,jml,var_tmp2d ) 
-      ELSE
-       CALL grille_m(iml_dyn, jml_dyn, lon_rad, lat_rad, 
-     .  var_ana3d(:,:,il), iml-1, jml, lon_in, lat_in, var_tmp2d )
-      ENDIF
-        !
-        CALL gr_int_dyn(var_tmp2d, var_tmp3d(:,:,il), iml-1, jml)
-        !
-       ENDDO
-       !
-          DO il=1,llm_dyn
-            lind(il) = llm_dyn-il+1
-          ENDDO
-    !
-c
-c  ... Pour l'interpolation verticale ,on interpole du haut de l'atmosphere
-c                    vers  le  sol  ...
-c
-      DO ij=1,jml
-        DO ii=1,iml-1
-          !
-          ax(:) = lev_dyn(lind(:)) 
-          ay(:) = var_tmp3d(ii, ij, lind(:))
-          !
-         
-          CALL SPLINE(ax, ay, llm_dyn, 1.e30, 1.e30, yder)
-          !
-          DO il=1,lml
-            bx = pls_in(ii, ij, il)
-            CALL SPLINT(ax, ay, yder, llm_dyn, bx, by)
-            var3d(ii, ij, il) = by
-          ENDDO
-          !
-        ENDDO
-        var3d(iml, ij, :) = var3d(1, ij, :) 
-      ENDDO
-
-      do il=1,lml
-        call minmax(iml*jml,var3d(1,1,il),chmin,chmax)
-      SELECTCASE(varname)
-       CASE('U')
-          WRITE(*,*) ' U  min max l ',il,chmin,chmax
-       CASE('V')
-          WRITE(*,*) ' V  min max l ',il,chmin,chmax
-       CASE('TEMP')
-          WRITE(*,*) ' TEMP  min max l ',il,chmin,chmax
-       CASE('R')
-          WRITE(*,*) ' R  min max l ',il,chmin,chmax
-      END SELECT
-           enddo
-
-      DEALLOCATE(lon_rad)
-      DEALLOCATE(lon_ini)
-      DEALLOCATE(lat_rad)
-      DEALLOCATE(lat_ini)
-      DEALLOCATE(lev_dyn)
-      DEALLOCATE(var_tmp2d)
-      DEALLOCATE(var_tmp3d)
-      DEALLOCATE(ax)
-      DEALLOCATE(ay)
-      DEALLOCATE(yder)
-      DEALLOCATE(lind)
-
-    !
-      RETURN
-    !
-      END SUBROUTINE start_inter_3d
-    !
-#endif
-! of #ifdef CPP_EARTH
-      END MODULE startvar
Index: LMDZ4/trunk/libf/dyn3d/startvar.F90
===================================================================
--- LMDZ4/trunk/libf/dyn3d/startvar.F90	(revision 1319)
+++ LMDZ4/trunk/libf/dyn3d/startvar.F90	(revision 1319)
@@ -0,0 +1,767 @@
+!
+! $Id$
+!
+!*******************************************************************************
+!
+MODULE startvar
+!
+!*******************************************************************************
+!
+!-------------------------------------------------------------------------------
+! Purpose: Access data from the database of atmospheric to initialize the model.
+!-------------------------------------------------------------------------------
+! Comments:
+!
+!    *  This module is designed to work for Earth (and with ioipsl)
+!
+!    *  There are three ways to acces data, depending on the type of field
+!  which needs to be extracted. In any case the call should come after a restget
+!  and should be of the type :                     CALL startget(...)
+!
+!  - A 1D variable on the physical grid :
+!    CALL startget(varname, iml, jml,  lon_in,  lat_in,  nbindex,              &
+!           champ, val_exp,      jml2, lon_in2, lat_in2, ibar )
+!
+!  - A 2D variable on the dynamical grid :
+!    CALL startget(varname, iml, jml,  lon_in,  lat_in,                        &
+!           champ, val_exp,      jml2, lon_in2, lat_in2, ibar )             
+!
+!  - A 3D variable on the dynamical grid :
+!    CALL startget(varname, iml, jml,  lon_in,  lat_in,  lml, pls, workvar,    &
+!           champ, val_exp,      jml2, lon_in2, lat_in2, ibar )
+!
+!    *  Data needs to be in NetCDF format
+!
+!    *  Variables should have the following names in the files:
+!            'RELIEF' : High resolution orography 
+!            'ST'     : Surface temperature
+!            'CDSW'   : Soil moisture
+!            'Z'      : Surface geopotential
+!            'SP'     : Surface pressure
+!            'U'      : East ward wind
+!            'V'      : Northward wind
+!            'TEMP'   : Temperature
+!            'R'      : Relative humidity
+!
+!   *   There is a big mess with the longitude size. Should it be iml or iml+1 ?
+!  I have chosen to use the iml+1 as an argument to this routine and we declare
+!  internaly smaller fields when needed. This needs to be cleared once and for
+!  all in LMDZ. A convention is required.
+!-------------------------------------------------------------------------------
+#ifdef CPP_EARTH
+  USE ioipsl
+  IMPLICIT NONE
+
+  PRIVATE
+  PUBLIC startget
+  INTERFACE startget
+    MODULE PROCEDURE startget_phys1d, startget_phys2d, startget_dyn
+  END INTERFACE
+
+  REAL,    SAVE :: deg2rad,  pi
+  INTEGER, SAVE ::           iml_rel,  jml_rel
+  INTEGER, SAVE :: fid_phys, iml_phys, jml_phys
+  INTEGER, SAVE :: fid_dyn,  iml_dyn,  jml_dyn,  llm_dyn,  ttm_dyn
+  REAL, DIMENSION(:,:),   ALLOCATABLE, TARGET, SAVE :: lon_phys, lon_dyn
+  REAL, DIMENSION(:,:),   ALLOCATABLE, TARGET, SAVE :: lat_phys, lat_dyn
+  REAL, DIMENSION(:,:),   ALLOCATABLE, TARGET, SAVE :: lon_rug, lon_alb, lon_rel
+  REAL, DIMENSION(:,:),   ALLOCATABLE, TARGET, SAVE :: lat_rug, lat_alb, lat_rel
+  REAL, DIMENSION(:),     ALLOCATABLE, TARGET, SAVE :: levdyn_ini
+  REAL, DIMENSION(:,:),   ALLOCATABLE, TARGET, SAVE :: relief, zstd, zsig, zgam
+  REAL, DIMENSION(:,:),   ALLOCATABLE, TARGET, SAVE :: masque, zthe, zpic, zval
+  REAL, DIMENSION(:,:),   ALLOCATABLE, TARGET, SAVE :: rugo, phis, tsol, qsol
+  REAL, DIMENSION(:,:),   ALLOCATABLE, TARGET, SAVE :: psol_dyn
+  REAL, DIMENSION(:,:,:), ALLOCATABLE, TARGET, SAVE :: var_ana3d
+
+   CONTAINS
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE startget_phys1d(varname, iml, jml, lon_in, lat_in, nbindex, champ,  &
+                           val_exp ,jml2, lon_in2, lat_in2, ibar)
+!
+!-------------------------------------------------------------------------------
+! Comment:
+!   This routine only works if the variable does not exist or is constant.
+!-------------------------------------------------------------------------------
+! Arguments:
+  CHARACTER(LEN=*),         INTENT(IN)    :: varname
+  INTEGER,                  INTENT(IN)    :: iml, jml
+  REAL, DIMENSION(iml),     INTENT(IN)    :: lon_in
+  REAL, DIMENSION(jml),     INTENT(IN)    :: lat_in
+  INTEGER,                  INTENT(IN)    :: nbindex
+  REAL, DIMENSION(nbindex), INTENT(INOUT) :: champ
+  REAL,                     INTENT(IN)    :: val_exp
+  INTEGER,                  INTENT(IN)    :: jml2
+  REAL, DIMENSION(iml),     INTENT(IN)    :: lon_in2
+  REAL, DIMENSION(jml2),    INTENT(IN)    :: lat_in2
+  LOGICAL,                  INTENT(IN)    :: ibar
+!-------------------------------------------------------------------------------
+! Local variables:
+#include "iniprint.h"
+  REAL, DIMENSION(:,:), POINTER :: v2d
+!-------------------------------------------------------------------------------
+  v2d=>NULL()
+  IF(MINVAL(champ)==MAXVAL(champ).AND.MINVAL(champ)==val_exp) THEN
+
+!--- CHECKING IF THE FIELD IS KNOWN ; READING UNALLOCATED FILES
+    SELECT CASE(varname)
+      CASE('tsol')
+        IF(.NOT.ALLOCATED(tsol))                                               &
+         CALL start_init_phys(iml,jml,lon_in,lat_in,jml2,lon_in2,lat_in2,ibar)
+      CASE('qsol')
+        IF(.NOT.ALLOCATED(qsol))                                               &
+         CALL start_init_phys(iml,jml,lon_in,lat_in,jml2,lon_in2,lat_in2,ibar)
+      CASE('psol')
+        IF(.NOT.ALLOCATED(psol_dyn))                                           &
+         CALL start_init_dyn (iml,jml,lon_in,lat_in,jml2,lon_in2,lat_in2,ibar)
+      CASE('zmea','zstd','zsig','zgam','zthe','zpic','zval')
+        IF(.NOT.ALLOCATED(relief))                                             &
+         CALL start_init_orog(iml,jml,lon_in,lat_in)
+      CASE('rads','snow','tslab','seaice','rugmer','agsno')
+      CASE DEFAULT
+        WRITE(lunout,*)'startget_phys1d'
+        WRITE(lunout,*)'No rule is present to extract variable '//TRIM(varname)&
+                     //' from any data set'; STOP
+    END SELECT
+
+!--- SELECTING v2d FOR WANTED VARIABLE AND CHEKING ITS SIZE
+    SELECT CASE(varname)
+      CASE('rads','snow','tslab','seaice');  champ=0.0
+      CASE('rugmer');                        champ(:)=0.001
+      CASE('agsno');                         champ(:)=50.0
+      CASE DEFAULT
+        SELECT CASE(varname)
+          CASE('tsol'); v2d=>tsol
+          CASE('qsol'); v2d=>qsol
+          CASE('psol'); v2d=>psol_dyn
+          CASE('zmea'); v2d=>relief
+          CASE('zstd'); v2d=>zstd
+          CASE('zsig'); v2d=>zsig
+          CASE('zgam'); v2d=>zgam
+          CASE('zthe'); v2d=>zthe
+          CASE('zpic'); v2d=>zpic
+          CASE('zval'); v2d=>zval
+        END SELECT
+        IF(SIZE(v2d)/=SIZE(lon_in)*SIZE(lat_in)) THEN
+         WRITE(lunout,*)'STARTVAR module has been initialized to the wrong size'
+         STOP
+        END IF
+        CALL gr_dyn_fi(1,iml,jml,nbindex,v2d,champ)
+    END SELECT
+
+  ELSE
+
+!--- SOME FIELDS ARE CAUGHT: MAY BE NEEDED FOR A 3D INTEPROLATION
+    SELECT CASE(varname)
+      CASE('tsol')
+        IF(.NOT.ALLOCATED(tsol)) ALLOCATE(tsol(iml,jml))
+        CALL gr_fi_dyn(1,iml,jml,nbindex,champ,tsol)
+    END SELECT
+
+  END IF
+
+END SUBROUTINE  startget_phys1d
+!
+!-------------------------------------------------------------------------------
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE startget_phys2d(varname, iml, jml, lon_in, lat_in, champ, val_exp,  &
+                           jml2, lon_in2, lat_in2 , ibar, msk)
+!
+!-------------------------------------------------------------------------------
+! Comment:
+!   This routine only works if the variable does not exist or is constant.
+!-------------------------------------------------------------------------------
+! Arguments:
+  CHARACTER(LEN=*),         INTENT(IN)           :: varname
+  INTEGER,                  INTENT(IN)           :: iml, jml
+  REAL, DIMENSION(iml),     INTENT(IN)           :: lon_in
+  REAL, DIMENSION(jml),     INTENT(IN)           :: lat_in
+  REAL, DIMENSION(iml,jml), INTENT(INOUT)        :: champ
+  REAL,                     INTENT(IN)           :: val_exp
+  INTEGER,                  INTENT(IN)           :: jml2
+  REAL, DIMENSION(iml),     INTENT(IN)           :: lon_in2
+  REAL, DIMENSION(jml2),    INTENT(IN)           :: lat_in2
+  LOGICAL,                  INTENT(IN)           :: ibar
+  REAL, DIMENSION(iml,jml), INTENT(IN), OPTIONAL :: msk
+!-------------------------------------------------------------------------------
+! Local variables:
+#include "iniprint.h"
+  REAL, DIMENSION(:,:), POINTER :: v2d=>NULL()
+  LOGICAL                       :: lrelief1, lrelief2
+!-------------------------------------------------------------------------------
+  v2d=>NULL()
+  lrelief1=(.NOT.ALLOCATED(relief).AND.     PRESENT(msk))
+  lrelief2=(.NOT.ALLOCATED(relief).AND..NOT.PRESENT(msk))
+  IF(MINVAL(champ)==MAXVAL(champ).AND.MINVAL(champ)==val_exp) THEN
+
+!--- CHECKING IF THE FIELD IS KNOWN ; READING UNALLOCATED FILES
+    SELECT CASE(varname)
+      CASE('psol')
+        IF(.NOT.ALLOCATED(psol_dyn))                                           &
+          CALL start_init_dyn (iml,jml,lon_in,lat_in,jml2,lon_in2,lat_in2,ibar)
+      CASE('relief')
+        IF(lrelief1)             CALL start_init_orog(iml,jml,lon_in,lat_in,msk)
+        IF(lrelief2)             CALL start_init_orog(iml,jml,lon_in,lat_in)
+      CASE('surfgeo')
+        IF(.NOT.ALLOCATED(phis)) CALL start_init_orog(iml,jml,lon_in,lat_in)
+      CASE('rugosite','masque')
+        IF(.NOT.ALLOCATED(rugo)) CALL start_init_orog(iml,jml,lon_in,lat_in)
+      CASE DEFAULT
+        WRITE(lunout,*)'startget_phys2d'
+        WRITE(lunout,*)'No rule is present to extract variable '//TRIM(varname)&
+                     //' from any data set'; STOP
+    END SELECT
+
+!--- SELECTING v2d FOR WANTED VARIABLE AND CHEKING ITS SIZE
+    SELECT CASE(varname)
+      CASE('psol');     v2d=>psol_dyn
+      CASE('relief');   v2d=>relief
+      CASE('rugosite'); v2d=>rugo
+      CASE('masque');   v2d=>masque
+      CASE('surfgeo');  v2d=>phis
+    END SELECT
+    IF(SIZE(champ)/=SIZE(v2d)) THEN
+      WRITE(lunout,*) 'STARTVAR module has been initialized to the wrong size'
+      STOP
+    END IF
+
+    champ(:,:)=v2d(:,:)
+
+  ELSE
+
+!--- SOME FIELDS ARE CAUGHT: MAY BE NEEDED FOR A 3D INTEPROLATION
+    SELECT CASE(varname)
+      CASE ('surfgeo')
+        IF(.NOT.ALLOCATED(phis)) ALLOCATE(phis(iml,jml))
+        IF(SIZE(phis)/=SIZE(champ)) THEN
+         WRITE(lunout,*)'STARTVAR module has been initialized to the wrong size'
+         STOP
+        END IF
+        phis(:,:)=champ(:,:)
+    END SELECT
+
+  END IF
+
+END SUBROUTINE startget_phys2d
+!
+!-------------------------------------------------------------------------------
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE startget_dyn(varname, iml, jml,  lon_in,  lat_in,  lml, pls,workvar,&
+                     champ, val_exp,  jml2, lon_in2, lat_in2, ibar)
+!-------------------------------------------------------------------------------
+! Comment:
+!   This routine only works if the variable does not exist or is constant.
+!-------------------------------------------------------------------------------
+! Arguments:
+  CHARACTER(LEN=*),             INTENT(IN)    :: varname
+  INTEGER,                      INTENT(IN)    :: iml, jml
+  REAL, DIMENSION(iml),         INTENT(IN)    :: lon_in
+  REAL, DIMENSION(jml),         INTENT(IN)    :: lat_in
+  INTEGER,                      INTENT(IN)    :: lml
+  REAL, DIMENSION(iml,jml,lml), INTENT(IN)    :: pls, workvar
+  REAL, DIMENSION(iml,jml,lml), INTENT(INOUT) :: champ
+  REAL,                         INTENT(IN)    :: val_exp
+  INTEGER,                      INTENT(IN)    :: jml2
+  REAL, DIMENSION(iml),         INTENT(IN)    :: lon_in2
+  REAL, DIMENSION(jml2),        INTENT(IN)    :: lat_in2
+  LOGICAL,                      INTENT(IN)    :: ibar
+!-------------------------------------------------------------------------------
+! Local variables:
+#include "iniprint.h"
+#include "dimensions.h"
+#include "comconst.h"
+#include "paramet.h"
+#include "comgeom2.h"
+  REAL, DIMENSION(:,:,:), POINTER :: v3d=>NULL()
+  CHARACTER(LEN=10) :: vname
+  INTEGER :: il
+  REAL    :: xppn, xpps
+!-------------------------------------------------------------------------------
+  NULLIFY(v3d)
+  IF(MINVAL(champ)==MAXVAL(champ).AND.MINVAL(champ)==val_exp) THEN
+
+!--- READING UNALLOCATED FILES
+    IF(.NOT.ALLOCATED(psol_dyn))                                               &
+      CALL start_init_dyn(iml,jml,lon_in,lat_in,jml2,lon_in2,lat_in2,ibar)
+
+!--- CHECKING IF THE FIELD IS KNOWN AND INTERPOLATING 3D FIELDS
+    SELECT CASE(varname)
+      CASE('u');        vname='U'
+      CASE('v');        vname='V'
+      CASE('t','tpot'); vname='TEMP'
+      CASE('q');        vname='R'
+      CASE DEFAULT
+        WRITE(lunout,*)'startget_dyn'
+        WRITE(lunout,*)'No rule is present to extract variable '//TRIM(varname)&
+                //' from any data set'; STOP
+    END SELECT
+    CALL start_inter_3d(TRIM(vname), iml, jml, lml, lon_in, lat_in, jml2,      &
+                        lon_in2, lat_in2,  pls, champ,ibar )
+
+!--- COMPUTING THE REQUIRED FILED
+    SELECT CASE(varname)
+      CASE('u')                                            !--- Eastward wind
+        DO il=1,lml; champ(:,:,il)=champ(:,:,il)*cu(:,1:jml); END DO
+        champ(iml,:,:)=champ(1,:,:)
+
+      CASE('v')                                            !--- Northward wind
+        DO il=1,lml; champ(:,:,il)=champ(:,:,il)*cv(:,1:jml); END DO
+        champ(iml,:,:)=champ(1,:,:)
+
+      CASE('tpot')                                         !--- Temperature
+        IF(MINVAL(workvar)/=MAXVAL(workvar)) THEN
+          champ=champ*cpp/workvar
+          DO il=1,lml
+            xppn = SUM(aire(:,1  )*champ(:,1  ,il))/apoln
+            xpps = SUM(aire(:,jml)*champ(:,jml,il))/apols
+            champ(:,1  ,il) = xppn
+            champ(:,jml,il) = xpps
+          END DO
+        ELSE
+          WRITE(lunout,*)'Could not compute potential temperature as the'
+          WRITE(lunout,*)'Exner function is missing or constant.'; STOP
+        END IF
+
+      CASE('q')                                            !--- Relat. humidity
+        IF(MINVAL(workvar)/=MAXVAL(workvar)) THEN
+          champ=0.01*champ*workvar
+          WHERE(champ<0.) champ=1.0E-10
+          DO il=1,lml
+            xppn = SUM(aire(:,1  )*champ(:,1  ,il))/apoln
+            xpps = SUM(aire(:,jml)*champ(:,jml,il))/apols
+            champ(:,1  ,il) = xppn
+            champ(:,jml,il) = xpps
+          END DO
+        ELSE
+          WRITE(lunout,*)'Could not compute specific humidity as the'
+          WRITE(lunout,*)'saturated humidity is missing or constant.'; STOP
+        END IF
+
+    END SELECT
+
+  END IF
+
+END SUBROUTINE startget_dyn
+!
+!-------------------------------------------------------------------------------
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE start_init_orog(iml,jml,lon_in,lat_in,masque_lu)
+!
+!-------------------------------------------------------------------------------
+! Arguments:
+  INTEGER,                  INTENT(IN)           :: iml, jml
+  REAL, DIMENSION(iml),     INTENT(IN)           :: lon_in
+  REAL, DIMENSION(jml),     INTENT(IN)           :: lat_in
+  REAL, DIMENSION(iml,jml), INTENT(IN), OPTIONAL :: masque_lu
+!-------------------------------------------------------------------------------
+! Local variables:
+#include "iniprint.h"
+  CHARACTER(LEN=25)     :: title
+  CHARACTER(LEN=120)    :: orofname
+  LOGICAL               :: check=.TRUE.
+  REAL,    DIMENSION(1) :: lev
+  REAL                  :: date, dt
+  INTEGER, DIMENSION(1) :: itau
+  INTEGER               :: fid, llm_tmp, ttm_tmp
+  REAL,    DIMENSION(:,:), ALLOCATABLE :: relief_hi, tmp_var
+  REAL,    DIMENSION(:),   ALLOCATABLE :: lon_rad, lat_rad, lon_ini, lat_ini
+!-------------------------------------------------------------------------------
+  pi=2.0*ASIN(1.0); deg2rad=pi/180.0
+
+  orofname = 'Relief.nc'; title='RELIEF'
+  IF(check) WRITE(lunout,*)'Reading the high resolution orography'
+  CALL flininfo(orofname, iml_rel, jml_rel, llm_tmp, ttm_tmp, fid)
+
+  ALLOCATE(lat_rel(iml_rel,jml_rel),lon_rel(iml_rel,jml_rel))
+  CALL flinopen(orofname, .FALSE., iml_rel, jml_rel, llm_tmp, lon_rel, lat_rel,&
+                lev, ttm_tmp, itau, date, dt, fid)
+  ALLOCATE(relief_hi(iml_rel,jml_rel))
+  CALL flinget(fid, title, iml_rel, jml_rel, llm_tmp, ttm_tmp, 1, 1, relief_hi)
+  CALL flinclo(fid)
+
+!--- IF ANGLES ARE IN DEGREES, THEY ARE CONVERTED INTO RADIANS
+  ALLOCATE(lon_ini(iml_rel),lat_ini(jml_rel))
+  lon_ini(:)=lon_rel(:,1); IF(MAXVAL(lon_rel)>pi) lon_ini=lon_ini*deg2rad
+  lat_ini(:)=lat_rel(1,:); IF(MAXVAL(lat_rel)>pi) lat_ini=lat_ini*deg2rad
+
+!--- FIELDS ARE PROCESSED TO BE ON STANDARD ANGULAR DOMAINS
+  ALLOCATE(lon_rad(iml_rel),lat_rad(jml_rel))
+  CALL conf_dat2d(title, iml_rel, jml_rel, lon_ini, lat_ini, lon_rad, lat_rad, &
+                  relief_hi, .FALSE.)
+  DEALLOCATE(lon_ini,lat_ini)
+
+!--- COMPUTING THE REQUIRED FIELDS USING ROUTINE grid_noro
+  IF(check) WRITE(lunout,*)'Computes all parameters needed for gravity wave dra&
+     &g code'
+
+  ALLOCATE(phis(iml,jml))      ! Geopotentiel au sol
+  ALLOCATE(zstd(iml,jml))      ! Deviation standard de l'orographie sous-maille
+  ALLOCATE(zsig(iml,jml))      ! Pente de l'orographie sous-maille 
+  ALLOCATE(zgam(iml,jml))      ! Anisotropie de l'orographie sous maille
+  ALLOCATE(zthe(iml,jml))      ! Orientation axe +grande pente d'oro sous maille
+  ALLOCATE(zpic(iml,jml))      ! Hauteur pics de la SSO
+  ALLOCATE(zval(iml,jml))      ! Hauteur vallees de la SSO
+  ALLOCATE(relief(iml,jml))    ! Orographie moyenne
+  ALLOCATE(masque(iml,jml))    ! Masque terre ocean
+  masque = -99999.
+  IF(PRESENT(masque_lu)) masque=masque_lu
+
+  CALL grid_noro(iml_rel, jml_rel, lon_rad, lat_rad, relief_hi, iml-1, jml,    &
+       lon_in, lat_in, phis, relief, zstd, zsig, zgam, zthe, zpic, zval, masque)
+  phis = phis * 9.81
+
+!--- SURFACE ROUGHNESS COMPUTATION (UNUSED FOR THE MOMENT !!! )
+  IF(check) WRITE(lunout,*)'Compute surface roughness induced by the orography'
+  ALLOCATE(rugo   (iml  ,jml))
+  ALLOCATE(tmp_var(iml-1,jml))
+  CALL rugsoro(iml_rel, jml_rel, lon_rad, lat_rad, relief_hi, iml-1, jml,      &
+       lon_in, lat_in, tmp_var)
+  rugo(1:iml-1,:)=tmp_var; rugo(iml,:)=tmp_var(1,:)
+  DEALLOCATE(relief_hi,tmp_var,lon_rad,lat_rad)
+  RETURN
+
+END SUBROUTINE start_init_orog
+!
+!-------------------------------------------------------------------------------
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE start_init_phys(iml,jml,lon_in,lat_in,jml2,lon_in2,lat_in2,ibar)
+!
+!-------------------------------------------------------------------------------
+! Arguments:
+  INTEGER,               INTENT(IN) :: iml, jml
+  REAL, DIMENSION(iml),  INTENT(IN) :: lon_in
+  REAL, DIMENSION(jml),  INTENT(IN) :: lat_in
+  INTEGER,               INTENT(IN) :: jml2
+  REAL, DIMENSION(iml),  INTENT(IN) :: lon_in2
+  REAL, DIMENSION(jml2), INTENT(IN) :: lat_in2
+  LOGICAL,               INTENT(IN) :: ibar
+!-------------------------------------------------------------------------------
+! Local variables:
+#include "iniprint.h"
+  CHARACTER(LEN=25)     :: title
+  CHARACTER(LEN=120)    :: physfname
+  LOGICAL               :: check=.TRUE.
+  REAL                  :: date, dt
+  INTEGER, DIMENSION(1) :: itau
+  INTEGER               :: llm_tmp, ttm_tmp
+  REAL,    DIMENSION(:,:), ALLOCATABLE :: var_ana
+  REAL,    DIMENSION(:),   ALLOCATABLE :: lon_rad, lat_rad, lon_ini, lat_ini
+  REAL,    DIMENSION(:),   ALLOCATABLE :: levphys_ini
+!-------------------------------------------------------------------------------
+  physfname = 'ECPHY.nc'; pi=2.0*ASIN(1.0); deg2rad=pi/180.0
+  IF(check) WRITE(lunout,*)'Opening the surface analysis'
+  CALL flininfo(physfname, iml_phys, jml_phys, llm_tmp, ttm_tmp, fid_phys)
+
+  ALLOCATE(lat_phys(iml_phys,jml_phys))
+  ALLOCATE(lon_phys(iml_phys,jml_phys))
+  ALLOCATE(levphys_ini(llm_tmp))
+  CALL flinopen(physfname, .FALSE., iml_phys, jml_phys, llm_tmp, lon_phys,     &
+                lat_phys, levphys_ini, ttm_tmp, itau, date, dt, fid_phys)
+  DEALLOCATE(levphys_ini)
+
+!--- IF ANGLES ARE IN DEGREES, THEY ARE CONVERTED INTO RADIANS
+  ALLOCATE(lon_ini(iml_phys),lat_ini(jml_phys))
+  lon_ini(:)=lon_phys(:,1); IF(MAXVAL(lon_phys)>pi) lon_ini=lon_ini*deg2rad
+  lat_ini(:)=lat_phys(1,:); IF(MAXVAL(lat_phys)>pi) lat_ini=lat_ini*deg2rad
+
+  ALLOCATE(var_ana(iml_phys,jml_phys),lon_rad(iml_phys),lat_rad(jml_phys))
+
+!--- SURFACE TEMPERATURE
+  title='ST'
+  ALLOCATE(tsol(iml,jml))
+  CALL flinget(fid_phys,title,iml_phys,jml_phys,llm_tmp,ttm_tmp,1,1,var_ana)
+  CALL conf_dat2d(title,iml_phys, jml_phys, lon_ini, lat_ini, lon_rad, lat_rad,&
+                  var_ana , ibar  )
+  CALL interp_startvar(title, ibar, .TRUE.,                                    &
+      iml_phys, jml_phys, lon_rad, lat_rad, var_ana, iml, jml, jml-1,          &
+      lon_in,   lat_in,   lon_in2, lat_in2, tsol)
+
+!--- SOIL MOISTURE
+  title='CDSW'
+  ALLOCATE(qsol(iml,jml))
+  CALL flinget(fid_phys,title,iml_phys,jml_phys,llm_tmp,ttm_tmp,1,1,var_ana)
+  CALL conf_dat2d(title,iml_phys, jml_phys, lon_ini, lat_ini, lon_rad, lat_rad,&
+                  var_ana, ibar  )
+  CALL interp_startvar(title, ibar, .TRUE.,                                    &
+      iml_phys, jml_phys, lon_rad, lat_rad, var_ana, iml, jml, jml-1,          &
+      lon_in,   lat_in,   lon_in2, lat_in2, qsol)
+
+  CALL flinclo(fid_phys)
+
+  DEALLOCATE(var_ana,lon_rad,lat_rad,lon_ini,lat_ini)
+
+END SUBROUTINE start_init_phys
+!
+!-------------------------------------------------------------------------------
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE start_init_dyn(iml,jml,lon_in,lat_in,jml2,lon_in2,lat_in2,ibar)
+!
+!-------------------------------------------------------------------------------
+! Arguments:
+  INTEGER,               INTENT(IN) :: iml, jml
+  REAL, DIMENSION(iml),  INTENT(IN) :: lon_in
+  REAL, DIMENSION(jml),  INTENT(IN) :: lat_in
+  INTEGER,               INTENT(IN) :: jml2
+  REAL, DIMENSION(iml),  INTENT(IN) :: lon_in2
+  REAL, DIMENSION(jml2), INTENT(IN) :: lat_in2
+  LOGICAL,               INTENT(IN) :: ibar
+!-------------------------------------------------------------------------------
+! Local variables:
+#include "iniprint.h"
+#include "dimensions.h"
+#include "paramet.h"
+#include "comgeom2.h"
+  CHARACTER(LEN=25)     :: title
+  CHARACTER(LEN=120)    :: physfname
+  LOGICAL               :: check=.TRUE.
+  REAL                  :: date, dt
+  INTEGER, DIMENSION(1) :: itau
+  INTEGER               :: i, j
+  REAL,    DIMENSION(:,:), ALLOCATABLE :: var_ana, z
+  REAL,    DIMENSION(:),   ALLOCATABLE :: lon_rad, lat_rad, lon_ini, lat_ini
+  REAL,    DIMENSION(:),   ALLOCATABLE :: xppn, xpps
+!-------------------------------------------------------------------------------
+
+!--- KINETIC ENERGY
+  physfname = 'ECDYN.nc'; pi=2.0*ASIN(1.0); deg2rad=pi/180.0
+  IF(check) WRITE(lunout,*) 'Opening the surface analysis'
+  CALL flininfo(physfname, iml_dyn, jml_dyn, llm_dyn, ttm_dyn, fid_dyn)
+  IF(check) WRITE(lunout,*) 'Values read: ', iml_dyn, jml_dyn, llm_dyn, ttm_dyn
+
+  ALLOCATE(lat_dyn(iml_dyn,jml_dyn))
+  ALLOCATE(lon_dyn(iml_dyn,jml_dyn))
+  ALLOCATE(levdyn_ini(llm_dyn))
+  CALL flinopen(physfname, .FALSE., iml_dyn, jml_dyn, llm_dyn, lon_dyn,lat_dyn,&
+                levdyn_ini, ttm_dyn, itau, date, dt, fid_dyn)
+
+!--- IF ANGLES ARE IN DEGREES, THEY ARE CONVERTED INTO RADIANS
+  ALLOCATE(lon_ini(iml_dyn),lat_ini(jml_dyn))
+  lon_ini(:)=lon_dyn(:,1); IF(MAXVAL(lon_dyn)>pi) lon_ini=lon_ini*deg2rad
+  lat_ini(:)=lat_dyn(1,:); IF(MAXVAL(lat_dyn)>pi) lat_ini=lat_ini*deg2rad
+
+  ALLOCATE(var_ana(iml_dyn,jml_dyn),lon_rad(iml_dyn),lat_rad(jml_dyn))
+
+!--- SURFACE GEOPOTENTIAL
+  title='Z'
+  ALLOCATE(z(iml,jml))
+  CALL flinget(fid_dyn, title, iml_dyn, jml_dyn, 0, ttm_dyn, 1, 1, var_ana)
+  CALL conf_dat2d(title, iml_dyn, jml_dyn, lon_ini, lat_ini, lon_rad, lat_rad, &
+                  var_ana, ibar)
+  CALL interp_startvar(title, ibar, .TRUE.,                                    &
+      iml_dyn, jml_dyn, lon_rad, lat_rad, var_ana, iml, jml, jml-1,            &
+      lon_in,  lat_in,  lon_in2, lat_in2, z)
+
+!--- SURFACE PRESSURE
+  title='SP'
+  ALLOCATE(psol_dyn(iml,jml))
+  CALL flinget(fid_dyn, title, iml_dyn, jml_dyn, 0, ttm_dyn, 1, 1, var_ana)
+  CALL conf_dat2d(title, iml_dyn, jml_dyn, lon_ini, lat_ini, lon_rad, lat_rad, &
+                  var_ana, ibar)
+  CALL interp_startvar(title, ibar, .TRUE.,                                    &
+      iml_dyn, jml_dyn, lon_rad, lat_rad, var_ana, iml, jml, jml-1,            &
+      lon_in,  lat_in,  lon_in2, lat_in2, psol_dyn)
+
+  DEALLOCATE(var_ana,lon_rad,lat_rad,lon_ini,lat_ini)
+
+!--- ALLOCATION OF VARIABLES CREATED IN OR COMING FROM RESTART FILE
+  IF(.NOT.ALLOCATED(tsol)) THEN
+    CALL start_init_phys(iml,jml,lon_in,lat_in,jml2,lon_in2,lat_in2,ibar)
+  ELSE
+    IF(SIZE(tsol)/=SIZE(psol_dyn)) THEN
+      WRITE(lunout,*)'start_init_dyn :'
+      WRITE(lunout,*)'The temperature field we have does not have the right size'
+      STOP
+    END IF
+  END IF
+
+  IF(.NOT.ALLOCATED(phis)) THEN
+    CALL start_init_orog(iml,jml,lon_in,lat_in)
+  ELSE
+    IF(SIZE(phis)/=SIZE(psol_dyn)) THEN
+      WRITE(lunout,*)'start_init_dyn :'
+      WRITE(lunout,*)'The orography field we have does not have the right size'
+      STOP
+    END IF
+  END IF
+
+!--- PSOL IS COMPUTED IN PASCALS
+  DO j = 1, jml
+    DO i = 1, iml-1
+      psol_dyn(i,j) = psol_dyn(i,j)*(1.0+(z(i,j)-phis(i,j))/287.0/tsol(i,j))
+    END DO
+    psol_dyn(iml,j) = psol_dyn(1,j)
+  END DO
+  DEALLOCATE(z)
+
+  ALLOCATE(xppn(iml-1),xpps(iml-1)) 
+  DO i = 1, iml-1
+    xppn(i) = aire( i,1) * psol_dyn( i,1)
+    xpps(i) = aire( i,jml) * psol_dyn( i,jml)
+  END DO
+  DO i = 1, iml
+    psol_dyn(i,1  ) = SUM(xppn)/apoln
+    psol_dyn(i,jml) = SUM(xpps)/apols
+  END DO
+  DEALLOCATE(xppn,xpps) 
+
+  RETURN
+
+END SUBROUTINE start_init_dyn
+!
+!-------------------------------------------------------------------------------
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE start_inter_3d(varname, iml, jml, lml, lon_in, lat_in, jml2,lon_in2,&
+                          lat_in2, pls_in, var3d, ibar)
+!
+!-------------------------------------------------------------------------------
+! Arguments:
+  CHARACTER(LEN=*),             INTENT(IN)    :: varname
+  INTEGER,                      INTENT(IN)    :: iml, jml, lml
+  REAL, DIMENSION(iml),         INTENT(IN)    :: lon_in
+  REAL, DIMENSION(jml),         INTENT(IN)    :: lat_in
+  INTEGER,                      INTENT(IN)    :: jml2
+  REAL, DIMENSION(iml),         INTENT(IN)    :: lon_in2
+  REAL, DIMENSION(jml2),        INTENT(IN)    :: lat_in2
+  REAL, DIMENSION(iml,jml,lml), INTENT(IN)    :: pls_in
+  REAL, DIMENSION(iml,jml,lml), INTENT(OUT)   :: var3d
+  LOGICAL,                      INTENT(IN)    :: ibar
+!-------------------------------------------------------------------------------
+! Local variables:
+#include "iniprint.h"
+  LOGICAL               :: check=.TRUE.
+  REAL                  :: bx, by, chmin, chmax
+  INTEGER               :: ii, ij, il
+  REAL,    DIMENSION(:,:,:), ALLOCATABLE :: var_tmp3d
+  REAL,    DIMENSION(:),     ALLOCATABLE :: lon_rad, lat_rad, lon_ini, lat_ini
+  REAL,    DIMENSION(:),     ALLOCATABLE :: lev_dyn, ax, ay, yder
+  INTEGER, DIMENSION(:),     ALLOCATABLE :: lind
+!-------------------------------------------------------------------------------
+  IF(check) WRITE(lunout,*)'Going into flinget to extract the 3D  field.'
+  IF(check) WRITE(lunout,*)fid_dyn, varname, iml_dyn, jml_dyn, llm_dyn, ttm_dyn
+  IF(check) WRITE(lunout,*)'Allocating space for interpolation',iml,jml,llm_dyn
+
+  IF(.NOT.ALLOCATED(var_ana3d)) ALLOCATE(var_ana3d(iml_dyn,jml_dyn,llm_dyn))
+  CALL flinget(fid_dyn,varname,iml_dyn,jml_dyn,llm_dyn,ttm_dyn,1,1,var_ana3d)
+
+!--- IF ANGLES ARE IN DEGREES, THEY ARE CONVERTED INTO RADIANS
+  ALLOCATE(lon_ini(iml_dyn),lat_ini(jml_dyn))
+  lon_ini(:)=lon_dyn(:,1); IF(MAXVAL(lon_dyn)>pi) lon_ini=lon_ini*deg2rad
+  lat_ini(:)=lat_dyn(1,:); IF(MAXVAL(lat_dyn)>pi) lat_ini=lat_ini*deg2rad
+
+!--- FIELDS ARE PROCESSED TO BE ON STANDARD ANGULAR DOMAINS
+  ALLOCATE(lon_rad(iml_dyn),lat_rad(jml_dyn),lev_dyn(llm_dyn))
+  CALL conf_dat3d (varname, iml_dyn, jml_dyn, llm_dyn, lon_ini, lat_ini,       &
+                   levdyn_ini, lon_rad, lat_rad, lev_dyn, var_ana3d, ibar)
+  DEALLOCATE(lon_ini,lat_ini)
+
+!--- COMPUTING THE REQUIRED FIELDS USING ROUTINE grid_noro
+  ALLOCATE(var_tmp3d(iml,jml,llm_dyn))
+  DO il=1,llm_dyn
+    CALL interp_startvar(varname, ibar, il==1,                                 &
+      iml_dyn, jml_dyn, lon_rad, lat_rad, var_ana3d(:,:,il), iml, jml, jml2,   &
+      lon_in,  lat_in,  lon_in2, lat_in2, var_tmp3d(:,:,il))
+  END DO
+  DEALLOCATE(lon_rad,lat_rad)
+
+  ALLOCATE(lind(llm_dyn))
+  DO il=1,llm_dyn
+    lind(il) = llm_dyn-il+1
+  END DO
+
+!--- VERTICAL INTERPOLATION IS PERFORMED FROM TOP OF ATMOSPHERE TO GROUND
+  ALLOCATE(ax(llm_dyn),ay(llm_dyn),yder(llm_dyn))
+  DO ij=1,jml
+    DO ii=1,iml-1
+      ax(:)=lev_dyn(lind(:)) 
+      ay(:)=var_tmp3d(ii,ij,lind(:))
+      CALL SPLINE(ax, ay, llm_dyn, 1.e30, 1.e30, yder)
+      DO il=1,lml
+        bx=pls_in(ii,ij,il)
+        CALL SPLINT(ax, ay, yder, llm_dyn, bx, by)
+        var3d(ii,ij,il) = by
+      END DO
+    END DO
+    var3d(iml,ij,:) = var3d(1,ij,:) 
+  END DO
+  DEALLOCATE(var_tmp3d,lev_dyn,ax,ay,yder,lind)
+
+  DO il=1,lml
+    CALL minmax(iml*jml,var3d(1,1,il),chmin,chmax)
+    WRITE(lunout,*)' '//TRIM(varname)//'  min max l ',il,chmin,chmax
+  END DO
+
+  RETURN
+
+END SUBROUTINE start_inter_3d
+!
+!-------------------------------------------------------------------------------
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE interp_startvar(vname, ibar, ibeg, ii, jj,    lon,  lat,  vari,     &
+                                 i1, j1, j2, lon1, lat1, lon2, lat2, varo)
+!
+!-------------------------------------------------------------------------------
+! Arguments:
+  CHARACTER(LEN=*),       INTENT(IN)  :: vname
+  LOGICAL,                INTENT(IN)  :: ibar, ibeg
+  INTEGER,                INTENT(IN)  :: ii, jj
+  REAL, DIMENSION(ii),    INTENT(IN)  :: lon
+  REAL, DIMENSION(jj),    INTENT(IN)  :: lat
+  REAL, DIMENSION(ii,jj), INTENT(IN)  :: vari
+  INTEGER,                INTENT(IN)  :: i1, j1, j2
+  REAL, DIMENSION(i1),    INTENT(IN)  :: lon1
+  REAL, DIMENSION(j1),    INTENT(IN)  :: lat1
+  REAL, DIMENSION(i1),    INTENT(IN)  :: lon2
+  REAL, DIMENSION(j2),    INTENT(IN)  :: lat2
+  REAL, DIMENSION(i1,j1), INTENT(OUT) :: varo
+!-------------------------------------------------------------------------------
+! Local variables:
+#include "iniprint.h"
+  REAL, DIMENSION(i1-1,j1) :: vtmp
+!-------------------------------------------------------------------------------
+  IF(ibar) THEN
+    IF(ibeg) THEN
+      WRITE(lunout,*)                                                          &
+               '---------------------------------------------------------------'
+      WRITE(lunout,*)                                                          &
+ '$$$ Utilisation de l interpolation barycentrique  pour  '//TRIM(vname)//' $$$'
+      WRITE(lunout,*)                                                          &
+               '---------------------------------------------------------------'
+    END IF
+    CALL inter_barxy(ii, jj-1, lon, lat, vari, i1-1, j2, lon2, lat2, j1, vtmp)
+  ELSE
+    CALL grille_m   (ii, jj,   lon, lat, vari, i1-1, j1, lon1, lat1,     vtmp)
+  END IF
+  CALL gr_int_dyn(vtmp, varo, i1-1, j1)
+
+END SUBROUTINE interp_startvar
+!
+!-------------------------------------------------------------------------------
+
+#endif
+! of #ifdef CPP_EARTH
+
+END MODULE startvar
+!
+!*******************************************************************************
Index: LMDZ4/trunk/libf/dyn3dpar/ce0l.F
===================================================================
--- LMDZ4/trunk/libf/dyn3dpar/ce0l.F	(revision 1318)
+++ 	(revision )
@@ -1,86 +1,0 @@
-!
-! $Id$
-!
-       PROGRAM create_etat0_limit
-#ifdef CPP_EARTH
-! This prog. is designed to work for Earth
-       USE dimphy
-       USE comgeomphy
-       USE mod_phys_lmdz_para
-       USE mod_const_mpi
-       USE infotrac
-#ifdef CPP_IOIPSL
-       use ioipsl, only: ioconf_calendar
-#endif
-       IMPLICIT NONE
-c
-c
-c     Programme d'appel a etat0, creation des etats initiaux et limit_netcdf
-c   
-c
-c     interbar = .T . si appel a  interpol. barycentrique inter_barxy
-c
-c     extrap   = .T . si on fait une extrapolation de donnees , comme pour
-c       les  SST  lorsque  le fichier ne contient pas uniquement  des points 
-c     oceaniques .
-c
-c     oldice   = .T. si l'on veut garder les anciennes glaces , obtenues
-c     par  grille_m  ( grid_atob ) .
-c
-c     on cree le masque dans etat0 que l'on passe ensuite dans limit pour 
-c     garder les coherences
-
-      LOGICAL interbar, extrap , oldice
-      PARAMETER ( interbar = .true. , extrap = .FALSE. , oldice=.false.)
-#include "dimensions.h"
-#include "paramet.h"
-#include "indicesol.h"
-#include  "control.h"
-      REAL :: masque(iip1,jjp1)
-!      REAL :: pctsrf(iim*(jjm-1)+2, nbsrf)
-
-      IF (config_inca /= 'none') THEN
-#ifdef INCA
-         call init_const_lmdz(
-     $        nbtr,anneeref,dayref,
-     $        iphysiq, day_step,nday)
-#endif
-         print *, 'nbtr =' , nbtr 
-      END IF
-
-      CALL init_mpi
-
-
-      CALL Init_Phys_lmdz(iim,jjp1,llm,1,(/(jjm-1)*iim+2/))
-      PRINT *,'---> klon=',klon
-
-      IF (mpi_size>1 .OR. omp_size>1) THEN
-        CALL abort_gcm('create_etat0_limit','In parallel mode, 
-     &                 create_etat0_limit must be called only 
-     &                 for 1 process and 1 task')
-      ENDIF
-      call InitComgeomphy
-
-#ifdef CPP_IOIPSL
-      call ioconf_calendar('360d')
-#endif
-
-      WRITE(6,*) '  *********************  '
-      WRITE(6,*) ' interbar = ',interbar
-      CALL etat0_netcdf ( interbar, masque )
-c
-      WRITE(6,1)
-      WRITE(6,*) '  *********************  '
-      WRITE(6,*) '  ***  Limit_netcdf ***  '
-      WRITE(6,*) '  *********************  '
-      WRITE(6,1)
-      
-c     
-      CALL  limit_netcdf ( interbar, extrap , oldice, masque)
-
-1     FORMAT(//)
-
-#endif
-! of #ifdef CPP_EARTH
-      STOP
-      END
Index: LMDZ4/trunk/libf/dyn3dpar/ce0l.F90
===================================================================
--- LMDZ4/trunk/libf/dyn3dpar/ce0l.F90	(revision 1319)
+++ LMDZ4/trunk/libf/dyn3dpar/ce0l.F90	(revision 1319)
@@ -0,0 +1,110 @@
+!
+! $Id$
+!
+!-------------------------------------------------------------------------------
+!
+PROGRAM ce0l
+!
+!-------------------------------------------------------------------------------
+! Purpose: Calls etat0, creates initial states and limit_netcdf
+!
+!     interbar=.T. for barycentric interpolation inter_barxy
+!     extrap  =.T. for data extrapolation, like for the SSTs when file does not
+!                  contain ocean points only.
+!     oldice  =.T. for old-style ice, obtained using grille_m (grid_atob).
+!     masque is created in etat0, passed to limit to ensure consistancy.
+!-------------------------------------------------------------------------------
+#ifdef CPP_EARTH
+! This prog. is designed to work for Earth
+  USE dimphy
+  USE comgeomphy
+  USE mod_phys_lmdz_para
+  USE mod_const_mpi
+  USE infotrac
+
+#ifdef CPP_IOIPSL
+  USE ioipsl, ONLY: ioconf_calendar
+#endif
+
+#endif
+  IMPLICIT NONE
+#ifndef CPP_EARTH
+  WRITE(lunout,*)'limit_netcdf: Earth-specific routine, needs Earth physics'
+#else
+!-------------------------------------------------------------------------------
+! Local variables:
+  LOGICAL, PARAMETER :: interbar=.TRUE., extrap=.FALSE., oldice=.FALSE.
+#include "dimensions.h"
+#include "paramet.h"
+#include "indicesol.h"
+#include "iniprint.h"
+#include "control.h"
+#include "temps.h"
+#include "logic.h"
+  INTEGER, PARAMETER            :: longcles=20
+  REAL,    DIMENSION(longcles)  :: clesphy0
+  REAL,    DIMENSION(iip1,jjp1) :: masque
+  CHARACTER(LEN=15)             :: calnd
+!-------------------------------------------------------------------------------
+  CALL conf_gcm( 99, .TRUE. , clesphy0 )
+
+  CALL init_mpi
+
+  CALL Init_Phys_lmdz(iim,jjp1,llm,1,(/(jjm-1)*iim+2/))
+  WRITE(lunout,*)'---> klon=',klon
+  IF (mpi_size>1 .OR. omp_size>1) THEN
+       CALL abort_gcm('ce0l','In parallel mode,                         &
+ &                 ce0l must be called only                             &
+ &                 for 1 process and 1 task')
+  ENDIF
+
+  CALL InitComgeomphy
+
+#ifdef CPP_IOIPSL
+  SELECT CASE(calend)
+    CASE('earth_360d');CALL ioconf_calendar('360d');      calnd='a 360 jours/an'
+    CASE('earth_365d');CALL ioconf_calendar('noleap');    calnd='a 365 jours/an'
+    CASE('earth_366d');CALL ioconf_calendar('366d');      calnd='bissextile'
+    CASE('gregorian'); CALL ioconf_calendar('gregorian'); calnd='gregorien'
+    CASE('standard');  CALL ioconf_calendar('gregorian'); calnd='gregorien'
+    CASE('julian');    CALL ioconf_calendar('julian');    calnd='julien'
+    CASE('proleptic_gregorian'); CALL ioconf_calendar('gregorian')
+  !--- DC Bof...  => IOIPSL a mettre a jour: proleptic_gregorian /= gregorian
+    CASE DEFAULT
+      CALL abort_gcm('ce0l','Mauvais choix de calendrier',1)
+  END SELECT
+  WRITE(lunout,*)'CALENDRIER CHOISI: Terrestre '//TRIM(calnd)
+#endif
+
+  IF (config_inca /= 'none') THEN
+#ifdef INCA
+    CALL init_const_lmdz(nbtr,anneeref,dayref,iphysiq,day_step,nday)
+    CALL init_inca_para(iim,jjm+1,klon,1,klon_mpi_para_nb,0)
+    WRITE(lunout,*)'nbtr =' , nbtr 
+#endif
+  END IF
+
+  WRITE(lunout,'(//)')
+  WRITE(lunout,*) '  *********************  '
+  WRITE(lunout,*) '  ***  etat0_netcdf ***  '
+  WRITE(lunout,*) '  *********************  '
+  WRITE(lunout,'(//)')
+  WRITE(lunout,*) ' interbar = ',interbar
+  CALL etat0_netcdf(interbar,masque,ok_etat0)
+
+  IF(ok_limit) THEN
+  WRITE(lunout,'(//)')
+  WRITE(lunout,*) '  *********************  '
+  WRITE(lunout,*) '  ***  Limit_netcdf ***  '
+  WRITE(lunout,*) '  *********************  '
+  WRITE(lunout,'(//)')
+  CALL limit_netcdf(interbar,extrap,oldice,masque)
+  END IF
+
+#endif
+! of #ifndef CPP_EARTH #else
+  STOP
+
+END PROGRAM ce0l
+!
+!-------------------------------------------------------------------------------
Index: LMDZ4/trunk/libf/dyn3dpar/comdissnew.h
===================================================================
--- LMDZ4/trunk/libf/dyn3dpar/comdissnew.h	(revision 1318)
+++ LMDZ4/trunk/libf/dyn3dpar/comdissnew.h	(revision 1319)
@@ -1,10 +1,16 @@
 !
-! $Header$
+! $Id$
 !
-c-----------------------------------------------------------------------
-c INCLUDE comdissnew.h
+!
+!  ATTENTION!!!!: ce fichier include est compatible format fixe/format libre
+!                 veillez à n'utiliser que des ! pour les commentaires
+!                 et à bien positionner les & des lignes de continuation 
+!                 (les placer en colonne 6 et en colonne 73)
+!
+!-----------------------------------------------------------------------
+! INCLUDE 'comdissnew.h'
 
-      COMMON/comdissnew/ lstardis,nitergdiv,nitergrot,niterh,tetagdiv,
-     1                   tetagrot,tetatemp,coefdis 
+      COMMON/comdissnew/ lstardis,nitergdiv,nitergrot,niterh,tetagdiv,  &
+     &                   tetagrot,tetatemp,coefdis 
 
       LOGICAL lstardis
@@ -12,7 +18,7 @@
       REAL     tetagdiv, tetagrot,  tetatemp, coefdis
 
-c
-c ... Les parametres de ce common comdissnew sont  lues par defrun_new 
-c              sur le fichier  run.def    ....
-c
-c-----------------------------------------------------------------------
+!
+! ... Les parametres de ce common comdissnew sont  lues par defrun_new 
+!              sur le fichier  run.def    ....
+!
+!-----------------------------------------------------------------------
Index: LMDZ4/trunk/libf/dyn3dpar/conf_gcm.F
===================================================================
--- LMDZ4/trunk/libf/dyn3dpar/conf_gcm.F	(revision 1318)
+++ LMDZ4/trunk/libf/dyn3dpar/conf_gcm.F	(revision 1319)
@@ -353,8 +353,4 @@
        iphysiq = 5
        CALL getin('iphysiq', iphysiq)
-
-ccc   .... P.Le Van, ajout le 03/01/96 pour l'ecriture phys ...
-c
-
 
 !Config  Key  = ip_ebil_dyn
@@ -819,6 +815,23 @@
        CALL getin('ok_gradsfile',ok_gradsfile)
 
+!Config  Key  = ok_limit
+!Config  Desc = creation des fichiers limit dans create_etat0_limit
+!Config  Def  = y
+!Config  Help = production du fichier limit.nc requise
+
+       ok_limit = .TRUE.
+       CALL getin('ok_limit',ok_limit)
+
+!Config  Key  = ok_etat0
+!Config  Desc = creation des fichiers etat0 dans create_etat0_limit
+!Config  Def  = y
+!Config  Help = production des fichiers start.nc, startphy.nc requise
+
+      ok_etat0 = .TRUE.
+      CALL getin('ok_etat0',ok_etat0)
+
       write(lunout,*)' #########################################'
-      write(lunout,*)' Configuration des parametres du gcm: '
+      write(lunout,*)' Configuration des parametres de create_etat0'
+     &             //'_limit: '
       write(lunout,*)' planet_type = ', planet_type
       write(lunout,*)' calend = ', calend
@@ -862,4 +875,6 @@
       write(lunout,*)' ok_strato = ', ok_strato
       write(lunout,*)' ok_gradsfile = ', ok_gradsfile
+      write(lunout,*)' ok_limit = ', ok_limit
+      write(lunout,*)' ok_etat0 = ', ok_etat0
 c
       RETURN
Index: LMDZ4/trunk/libf/dyn3dpar/etat0_netcdf.F
===================================================================
--- LMDZ4/trunk/libf/dyn3dpar/etat0_netcdf.F	(revision 1318)
+++ 	(revision )
@@ -1,791 +1,0 @@
-!
-! $Header$
-!
-c
-c
-      SUBROUTINE etat0_netcdf (interbar, masque)
-#ifdef CPP_EARTH        
-      USE startvar
-      USE ioipsl
-      USE dimphy
-      USE infotrac
-      USE fonte_neige_mod
-      USE pbl_surface_mod
-      USE phys_state_var_mod
-      USE filtreg_mod
-      use regr_lat_time_climoz_m, only: regr_lat_time_climoz
-      use conf_phys_m, only: conf_phys
-#endif
-!#endif of #ifdef CPP_EARTH
-      use netcdf, only: nf90_open, NF90_NOWRITE, nf90_close
-      !
-      IMPLICIT NONE
-      !
-#include "dimensions.h"
-#include "paramet.h"
-      !
-      !
-!      INTEGER, PARAMETER :: KIDIA=1, KFDIA=iim*(jjm-1)+2, 
-!     .KLON=KFDIA-KIDIA+1,KLEV=llm
-      !
-#ifdef CPP_EARTH    
-#include "comgeom2.h"
-#include "comvert.h"
-#include "comconst.h"
-#include "indicesol.h"
-#include "dimsoil.h"
-#include "temps.h"
-#endif
-!#endif of #ifdef CPP_EARTH
-      ! arguments:
-      LOGICAL interbar
-      REAL :: masque(iip1,jjp1)
-
-#ifdef CPP_EARTH
-      ! local variables:
-      REAL :: latfi(klon), lonfi(klon)
-      REAL :: orog(iip1,jjp1), rugo(iip1,jjp1)
-      REAL :: psol(iip1, jjp1), phis(iip1, jjp1)
-      REAL :: p3d(iip1, jjp1, llm+1)
-      REAL :: uvent(iip1, jjp1, llm)
-      REAL :: vvent(iip1, jjm, llm)
-      REAL :: t3d(iip1, jjp1, llm), tpot(iip1, jjp1, llm)
-      REAL :: qsat(iip1, jjp1, llm)
-      REAL,ALLOCATABLE :: q3d(:, :, :,:)
-      REAL :: tsol(klon), qsol(klon), sn(klon)
-!!      REAL :: tsolsrf(klon,nbsrf)
-      real qsolsrf(klon,nbsrf),snsrf(klon,nbsrf) 
-      REAL :: albe(klon,nbsrf), evap(klon,nbsrf)
-      REAL :: alblw(klon,nbsrf)
-      REAL :: tsoil(klon,nsoilmx,nbsrf) 
-      REAL :: frugs(klon,nbsrf), agesno(klon,nbsrf)
-      REAL :: rugmer(klon)
-      REAL :: qd(iip1, jjp1, llm)
-      REAL :: run_off_lic_0(klon)
-      ! declarations pour lecture glace de mer
-      REAL :: rugv(klon)
-      INTEGER :: iml_lic, jml_lic, llm_tmp, ttm_tmp, iret
-      INTEGER :: itaul(1), fid
-      REAL :: lev(1), date
-      REAL, ALLOCATABLE, DIMENSION(:,:) :: lon_lic, lat_lic
-      REAL, ALLOCATABLE, DIMENSION(:)  :: dlon_lic, dlat_lic
-      REAL, ALLOCATABLE, DIMENSION (:,:) :: fraclic
-      REAL :: flic_tmp(iip1, jjp1)
-      REAL :: champint(iim, jjp1)
-      !
-
-      CHARACTER(len=80) :: varname
-      !
-      INTEGER :: i,j, ig, l, ji,ii1,ii2
-      REAL :: xpi
-      !
-      REAL :: alpha(iip1,jjp1,llm),beta(iip1,jjp1,llm)
-      REAL :: pk(iip1,jjp1,llm), pls(iip1,jjp1,llm), pks(ip1jmp1)
-      REAL :: workvar(iip1,jjp1,llm)
-      !
-      REAL ::  prefkap, unskap
-      !
-      real :: time_step,t_ops,t_wrt
-
-#include "comdissnew.h"
-#include "control.h"
-#include "serre.h"
-#include "clesphys.h"
-
-      INTEGER  ::        longcles
-      PARAMETER      ( longcles  = 20 )
-      REAL :: clesphy0 ( longcles       )
-      REAL :: p(iip1,jjp1,llm)
-      INTEGER :: itau, iday
-      REAL :: masse(iip1,jjp1,llm)
-      REAL :: xpn,xps,xppn(iim),xpps(iim)
-      real :: time
-      REAL :: phi(ip1jmp1,llm)
-      REAL :: pbaru(ip1jmp1,llm),pbarv(ip1jm,llm)
-      REAL :: w(ip1jmp1,llm)
-      REAL ::phystep
-CC      REAL :: rugsrel(iip1*jjp1)
-      REAL :: fder(klon)
-!!      real zrel(iip1*jjp1),chmin,chmax
-
-!!      CHARACTER(len=80) :: visu_file
-      INTEGER :: visuid
-
-! pour la lecture du fichier masque ocean
-      integer :: nid_o2a
-      logical :: couple = .false.
-      INTEGER :: iml_omask, jml_omask
-      REAL, ALLOCATABLE, DIMENSION(:,:) :: lon_omask, lat_omask
-      REAL, ALLOCATABLE, DIMENSION(:)  :: dlon_omask, dlat_omask
-      REAL, ALLOCATABLE, DIMENSION (:,:) :: ocemask, ocetmp
-      real, dimension(klon) :: ocemask_fi
-      integer :: isst(klon-2)
-      real zx_tmp_2d(iim,jjp1)
-
-      REAL :: dummy
-
-      logical              :: ok_newmicro
-      integer              :: iflag_radia
-      logical              :: ok_journe, ok_mensuel, ok_instan, ok_hf
-      logical              :: ok_LES
-      LOGICAL              :: ok_ade, ok_aie, aerosol_couple, new_aod
-      INTEGER              :: flag_aerosol
-      REAL                 :: bl95_b0, bl95_b1
-      real                 :: fact_cldcon, facttemps,ratqsbas,ratqshaut
-      real                 :: tau_ratqs
-      integer              :: iflag_cldcon
-      integer              :: iflag_ratqs
-      integer :: iflag_coupl
-      integer :: iflag_clos
-      integer :: iflag_wake
-      integer :: iflag_thermals,nsplit_thermals
-      real    :: tau_thermals
-      integer :: iflag_thermals_ed,iflag_thermals_optflux
-      REAL      :: solarlong0
-      real :: seuil_inversion
-
-      integer  read_climoz ! read ozone climatology
-C     Allowed values are 0, 1 and 2
-C     0: do not read an ozone climatology
-C     1: read a single ozone climatology that will be used day and night
-C     2: read two ozone climatologies, the average day and night
-C     climatology and the daylight climatology
-
-      !
-      !   Constantes 
-      !
-      pi     = 4. * ATAN(1.)
-      rad    = 6371229.
-      omeg   = 4.* ASIN(1.)/(24.*3600.)
-      g      = 9.8
-      daysec = 86400.
-      kappa  = 0.2857143
-      cpp    = 1004.70885
-      !
-      preff     = 101325.
-      pa        =  50000.
-      unskap = 1./kappa
-      !
-      jmp1    = jjm + 1
-      !
-      !    Construct a grid
-      !
-
-!      CALL defrun_new(99,.TRUE.,clesphy0)
-      CALL conf_gcm( 99, .TRUE. , clesphy0 )
-      call conf_phys(  ok_journe, ok_mensuel, ok_instan, ok_hf, ok_LES, &
-     &                 solarlong0,seuil_inversion,                      &
-     &                 fact_cldcon, facttemps,ok_newmicro,iflag_radia,  &
-     &                 iflag_cldcon,                                    &
-     &                 iflag_ratqs,ratqsbas,ratqshaut,tau_ratqs,        &
-     &                 ok_ade, ok_aie, aerosol_couple,                  &
-     &                 flag_aerosol, new_aod,                           &
-     &                 bl95_b0, bl95_b1,                                &
-     &                 iflag_thermals,nsplit_thermals,tau_thermals,     &
-     &                 iflag_thermals_ed,iflag_thermals_optflux,        &
-     &                 iflag_coupl,iflag_clos,iflag_wake, read_climoz )
-
-! co2_ppm0 : initial value of atmospheric CO2 from .def file (co2_ppm value)
-      co2_ppm0 = co2_ppm
-
-      dtvr   = daysec/FLOAT(day_step)
-      print*,'dtvr',dtvr
-
-      CALL iniconst()
-      CALL inigeom()
-
-! Initialisation pour traceurs
-      call infotrac_init
-      ALLOCATE(q3d(iip1, jjp1, llm, nqtot))
-
-      CALL inifilr()
-      CALL phys_state_var_init(read_climoz)
-      !
-      latfi(1) = ASIN(1.0)
-      DO j = 2, jjm
-        DO i = 1, iim
-          latfi((j-2)*iim+1+i)=  rlatu(j)
-        ENDDO
-      ENDDO
-      latfi(klon) = - ASIN(1.0)
-      !
-      lonfi(1) = 0.0
-      DO j = 2, jjm
-        DO i = 1, iim
-          lonfi((j-2)*iim+1+i) =  rlonv(i)
-        ENDDO
-      ENDDO
-      lonfi(klon) = 0.0
-      !
-      xpi = 2.0 * ASIN(1.0)
-      DO ig = 1, klon
-        latfi(ig) = latfi(ig) * 180.0 / xpi
-        lonfi(ig) = lonfi(ig) * 180.0 / xpi
-      ENDDO
-      !
-      rlat(1) = ASIN(1.0)
-      DO j = 2, jjm
-        DO i = 1, iim
-          rlat((j-2)*iim+1+i)=  rlatu(j)
-        ENDDO
-      ENDDO
-      rlat(klon) = - ASIN(1.0)
-      !
-      rlon(1) = 0.0
-      DO j = 2, jjm
-        DO i = 1, iim
-          rlon((j-2)*iim+1+i) =  rlonv(i)
-        ENDDO
-      ENDDO
-      rlon(klon) = 0.0
-      !
-      xpi = 2.0 * ASIN(1.0)
-      DO ig = 1, klon
-        rlat(ig) = rlat(ig) * 180.0 / xpi
-        rlon(ig) = rlon(ig) * 180.0 / xpi
-      ENDDO
-      !
-      
-
-
-C
-C En cas de simulation couplee, lecture du masque ocean issu du modele ocean
-C utilise pour calculer les poids et pour assurer l'adequation entre les
-C fractions d'ocean vu par l'atmosphere et l'ocean. Sinon, on cree le masque 
-C a partir du fichier relief
-C
-
-      write(*,*)'Essai de lecture masque ocean'
-      iret = nf90_open("o2a.nc", NF90_NOWRITE, nid_o2a)
-      if (iret .ne. 0) then
-        write(*,*)'ATTENTION!! pas de fichier o2a.nc trouve'
-        write(*,*)'Run force'
-        varname = 'masque'
-        masque(:,:) = 0.0
-        CALL startget(varname, iip1, jjp1, rlonv, rlatu, masque, 0.0,
-     ,  jjm ,rlonu,rlatv , interbar )
-        WRITE(*,*) 'MASQUE construit : Masque'
-        WRITE(*,'(97I1)') nINT(masque(:,:))
-        call gr_dyn_fi(1, iip1, jjp1, klon, masque, zmasq)
-        WHERE (zmasq(1 : klon) .LT. EPSFRA)
-            zmasq(1 : klon) = 0.
-        END WHERE 
-        WHERE (1. - zmasq(1 : klon) .LT. EPSFRA)
-            zmasq(1 : klon) = 1.
-        END WHERE 
-      else
-        couple = .true.
-        iret = nf90_close(nid_o2a)
-        call flininfo("o2a.nc", iml_omask, jml_omask, llm_tmp, ttm_tmp
-     $    , nid_o2a)
-        if (iml_omask /= iim .or. jml_omask /= jjp1) then
-          write(*,*)'Dimensions non compatibles pour masque ocean'
-          write(*,*)'iim = ',iim,' iml_omask = ',iml_omask
-          write(*,*)'jjp1 = ',jjp1,' jml_omask = ',jml_omask
-          stop
-        endif
-        ALLOCATE(lat_omask(iml_omask, jml_omask), stat=iret)
-        ALLOCATE(lon_omask(iml_omask, jml_omask), stat=iret)
-        ALLOCATE(dlon_omask(iml_omask), stat=iret)
-        ALLOCATE(dlat_omask(jml_omask), stat=iret)
-        ALLOCATE(ocemask(iml_omask, jml_omask), stat=iret)
-        ALLOCATE(ocetmp(iml_omask, jml_omask), stat=iret)
-        CALL flinopen("o2a.nc", .FALSE., iml_omask, jml_omask, llm_tmp
-     $    , lon_omask, lat_omask, lev, ttm_tmp, itaul, date, dt, fid)
-        CALL flinget(fid, 'OceMask', iml_omask, jml_omask, llm_tmp, 
-     $      ttm_tmp, 1, 1, ocetmp)
-        CALL flinclo(fid)
-        dlon_omask(1 : iml_omask) = lon_omask(1 : iml_omask, 1)
-        dlat_omask(1 : jml_omask) = lat_omask(1 , 1 : jml_omask)
-        ocemask = ocetmp
-        if (dlat_omask(1) < dlat_omask(jml_omask)) then
-          do j = 1, jml_omask
-            ocemask(:,j) = ocetmp(:,jml_omask-j+1)
-          enddo
-        endif 
-C
-C passage masque ocean a la grille physique
-C
-        write(*,*)'ocemask '
-        write(*,'(96i1)')int(ocemask)
-        ocemask_fi(1) = ocemask(1,1)
-        do j = 2, jjm
-          do i = 1, iim
-            ocemask_fi((j-2)*iim + i + 1) = ocemask(i,j)
-          enddo
-        enddo
-        ocemask_fi(klon) = ocemask(1,jjp1)
-        zmasq = 1. - ocemask_fi
-      endif
-
-      call gr_fi_dyn(1, klon, iip1, jjp1, zmasq, masque)
-
-      varname = 'relief'
-      ! This line needs to be replaced by a call to restget to get the values in the restart file
-      orog(:,:) = 0.0
-       CALL startget(varname, iip1, jjp1, rlonv, rlatu, orog, 0.0 ,
-     , jjm ,rlonu,rlatv , interbar, masque )
-      !
-      WRITE(*,*) 'OUT OF GET VARIABLE : Relief'
-!      WRITE(*,'(49I1)') INT(orog(:,:))
-      !
-      varname = 'rugosite'
-      ! This line needs to be replaced by a call to restget to get the values in the restart file
-      rugo(:,:) = 0.0
-       CALL startget(varname, iip1, jjp1, rlonv, rlatu, rugo, 0.0 ,
-     , jjm, rlonu,rlatv , interbar )
-      !
-      WRITE(*,*) 'OUT OF GET VARIABLE : Rugosite' 
-!      WRITE(*,'(49I1)') INT(rugo(:,:)*10)
-      !
-C
-C on initialise les sous surfaces
-C
-      pctsrf=0.
-c
-      varname = 'psol'
-      psol(:,:) = 0.0
-      CALL startget(varname, iip1, jjp1, rlonv, rlatu, psol, 0.0 ,
-     , jjm ,rlonu,rlatv , interbar )
-      !
-      !  Compute here the pressure on the intermediate levels. One would expect that this is available in the GCM 
-      !  anyway.
-      !
-!      WRITE(*,*) 'PSOL :', psol(10,20)
-!      WRITE(*,*) ap(:), bp(:)
-      CALL pression(ip1jmp1, ap, bp, psol, p3d)
-!      WRITE(*,*) 'P3D :', p3d(10,20,:)
-      CALL exner_hyb(ip1jmp1, psol, p3d, alpha, beta, pks, pk, workvar)
-!      WRITE(*,*) 'PK:', pk(10,20,:)
-      !
-      !
-      !
-      prefkap =  preff  ** kappa
-!      WRITE(*,*) 'unskap, cpp,  preff :', unskap, cpp,  preff
-      DO l = 1, llm
-        DO j=1,jjp1
-          DO i =1, iip1
-            pls(i,j,l) = preff * ( pk(i,j,l)/cpp) ** unskap
-           ENDDO
-        ENDDO
-      ENDDO
-      !
-!      WRITE(*,*) 'PLS :', pls(10,20,:)
-      !
-      varname = 'surfgeo'
-      phis(:,:) = 0.0
-      CALL startget(varname, iip1, jjp1, rlonv, rlatu, phis, 0.0 ,
-     , jjm ,rlonu,rlatv, interbar )
-      !
-      varname = 'u'
-      uvent(:,:,:) = 0.0
-      CALL startget(varname, iip1, jjp1, rlonu, rlatu, llm, pls,
-     . workvar, uvent, 0.0, jjm ,rlonv, rlatv, interbar )
-      !  
-      varname = 'v'
-      vvent(:,:,:) = 0.0
-      CALL startget(varname, iip1, jjm, rlonv, rlatv, llm, pls,
-     . workvar, vvent, 0.0, jjp1, rlonu, rlatu, interbar )
-      !
-      varname = 't'
-      t3d(:,:,:) = 0.0
-      CALL startget(varname, iip1, jjp1, rlonv, rlatu, llm, pls,
-     . workvar, t3d, 0.0 , jjm, rlonu, rlatv , interbar )
-      !
-      WRITE(*,*) 'T3D min,max:',minval(t3d(:,:,:)),
-     .                          maxval(t3d(:,:,:))
-      varname = 'tpot'
-      tpot(:,:,:) = 0.0
-      CALL startget(varname, iip1, jjp1, rlonv, rlatu, llm, pls,
-     . pk, tpot, 0.0 , jjm, rlonu, rlatv , interbar )
-      !
-      WRITE(*,*) 'T3D min,max:',minval(t3d(:,:,:)),
-     .                          maxval(t3d(:,:,:))
-      WRITE(*,*) 'PLS min,max:',minval(pls(:,:,:)),
-     .                          maxval(pls(:,:,:))
-
-c Calcul de l'humidite a saturation
-      print*,'avant q_sat'
-      call q_sat(llm*jjp1*iip1,t3d,pls,qsat)
-      print*,'apres q_sat'
-
-      WRITE(*,*) 'QSAT min,max:',minval(qsat(:,:,:)),
-     .                           maxval(qsat(:,:,:))
-      !
-CC      WRITE(*,*) 'QSAT :', qsat(10,20,:)
-      !
-      varname = 'q'
-      qd(:,:,:) = 0.0
-      q3d(:,:,:,:) = 0.0
-      WRITE(*,*) 'QSAT min,max:',minval(qsat(:,:,:)),
-     .                           maxval(qsat(:,:,:))
-      CALL startget(varname, iip1, jjp1, rlonv, rlatu, llm, pls,
-     . qsat, qd, 0.0, jjm, rlonu, rlatv , interbar )
-      q3d(:,:,:,1) = qd(:,:,:)
-      !
-
-!     Ozone climatology:
-      if (read_climoz >= 1) call regr_lat_time_climoz(read_climoz)
-
-      varname = 'tsol'
-      ! This line needs to be replaced by a call to restget to get the values in the restart file
-      tsol(:) = 0.0
-      CALL startget(varname, iip1, jjp1, rlonv, rlatu, klon, tsol, 0.0,
-     .    jjm, rlonu, rlatv , interbar )
-      !
-      WRITE(*,*) 'TSOL construit :'
-!      WRITE(*,'(48I3)') INT(TSOL(2:klon)-273)
-      !
-      varname = 'qsol'
-      qsol(:) = 0.0
-      CALL startget(varname, iip1, jjp1, rlonv, rlatu, klon, qsol, 0.0,
-     .   jjm, rlonu, rlatv , interbar )
-      !
-      varname = 'snow'
-      sn(:) = 0.0
-      CALL startget(varname, iip1, jjp1, rlonv, rlatu, klon, sn, 0.0,
-     .    jjm, rlonu, rlatv , interbar )
-      !
-      varname = 'rads'
-      radsol(:) = 0.0
-      CALL startget(varname,iip1,jjp1,rlonv,rlatu,klon,radsol,0.0,
-     .    jjm, rlonu, rlatv , interbar )
-      !
-      varname = 'rugmer'
-      rugmer(:) = 0.0
-      CALL startget(varname,iip1,jjp1,rlonv,rlatu,klon,rugmer,0.0,
-     .     jjm, rlonu, rlatv , interbar )
-      !
-!      varname = 'agesno'
-!      agesno(:) = 0.0
-!      CALL startget(varname,iip1,jjp1,rlonv,rlatu,klon,agesno,0.0,
-!     .     jjm, rlonu, rlatv , interbar )
-
-      varname = 'zmea'
-      zmea(:) = 0.0
-      CALL startget(varname,iip1,jjp1,rlonv,rlatu,klon,zmea,0.0,
-     .     jjm, rlonu, rlatv , interbar )
-
-      varname = 'zstd'
-      zstd(:) = 0.0
-      CALL startget(varname,iip1,jjp1,rlonv,rlatu,klon,zstd,0.0,
-     .     jjm, rlonu, rlatv , interbar )
-      varname = 'zsig'
-      zsig(:) = 0.0
-      CALL startget(varname,iip1,jjp1,rlonv,rlatu,klon,zsig,0.0,
-     .     jjm, rlonu, rlatv , interbar )
-      varname = 'zgam'
-      zgam(:) = 0.0
-      CALL startget(varname,iip1,jjp1,rlonv,rlatu,klon,zgam,0.0,
-     .     jjm, rlonu, rlatv , interbar )
-      varname = 'zthe'
-      zthe(:) = 0.0
-      CALL startget(varname,iip1,jjp1,rlonv,rlatu,klon,zthe,0.0,
-     .     jjm, rlonu, rlatv , interbar )
-      varname = 'zpic'
-      zpic(:) = 0.0
-      CALL startget(varname,iip1,jjp1,rlonv,rlatu,klon,zpic,0.0,
-     .     jjm, rlonu, rlatv , interbar )
-      varname = 'zval'
-      zval(:) = 0.0
-      CALL startget(varname,iip1,jjp1,rlonv,rlatu,klon,zval,0.0,
-     .     jjm, rlonu, rlatv , interbar )
-c
-cc      rugsrel(:) = 0.0
-cc      IF(ok_orodr)  THEN
-cc        DO i = 1, iip1* jjp1
-cc         rugsrel(i) = MAX( 1.e-05, zstd(i)* zsig(i) /2. )
-cc        ENDDO
-cc      ENDIF
-
-
-C
-C lecture du fichier glace de terre pour fixer la fraction de terre 
-C et de glace de terre
-C
-      CALL flininfo("landiceref.nc", iml_lic, jml_lic,llm_tmp, ttm_tmp
-     $    , fid)
-      ALLOCATE(lat_lic(iml_lic, jml_lic), stat=iret)
-      ALLOCATE(lon_lic(iml_lic, jml_lic), stat=iret)
-      ALLOCATE(dlon_lic(iml_lic), stat=iret)
-      ALLOCATE(dlat_lic(jml_lic), stat=iret)
-      ALLOCATE(fraclic(iml_lic, jml_lic), stat=iret)
-      CALL flinopen("landiceref.nc", .FALSE., iml_lic, jml_lic, llm_tmp
-     $    , lon_lic, lat_lic, lev, ttm_tmp, itaul, date, dt, fid)
-      CALL flinget(fid, 'landice', iml_lic, jml_lic, llm_tmp, ttm_tmp
-     $    , 1, 1, fraclic)
-      CALL flinclo(fid)
-C
-C interpolation sur la grille T du modele
-C
-      WRITE(*,*) 'dimensions de landice iml_lic, jml_lic : ', 
-     $    iml_lic, jml_lic
-c
-C sil les coordonnees sont en degres, on les transforme
-C
-      IF( MAXVAL( lon_lic(:,:) ) .GT. 2.0 * asin(1.0) )  THEN
-          lon_lic(:,:) = lon_lic(:,:) * 2.0* ASIN(1.0) / 180.
-      ENDIF 
-      IF( maxval( lat_lic(:,:) ) .GT. 2.0 * asin(1.0)) THEN 
-          lat_lic(:,:) = lat_lic(:,:) * 2.0 * asin(1.0) / 180.
-      ENDIF 
-
-      dlon_lic(1 : iml_lic) = lon_lic(1 : iml_lic, 1)
-      dlat_lic(1 : jml_lic) = lat_lic(1 , 1 : jml_lic) 
-C
-      CALL grille_m(iml_lic, jml_lic, dlon_lic, dlat_lic, fraclic
-     $    ,iim, jjp1,
-     $    rlonv, rlatu, flic_tmp(1 : iim, 1 : jjp1))
-cx$$$      flic_tmp(1 : iim, 1 : jjp1) = champint(1: iim, 1 : jjp1)
-      flic_tmp(iip1, 1 : jjp1) = flic_tmp(1 , 1 : jjp1)
-C
-C passage sur la grille physique
-C
-      CALL gr_dyn_fi(1, iip1, jjp1, klon, flic_tmp,
-     $    pctsrf(1:klon, is_lic))
-C adequation avec le maque terre/mer
-c      zmasq(157) = 0.
-      WHERE (pctsrf(1 : klon, is_lic) .LT. EPSFRA ) 
-          pctsrf(1 : klon, is_lic) = 0. 
-      END WHERE
-      WHERE (zmasq( 1 : klon) .LT. EPSFRA) 
-          pctsrf(1 : klon, is_lic) = 0.
-      END WHERE 
-      pctsrf(1 : klon, is_ter) = zmasq(1 : klon)
-      DO ji = 1, klon
-        IF (zmasq(ji) .GT. EPSFRA) THEN 
-            IF ( pctsrf(ji, is_lic) .GE. zmasq(ji)) THEN
-                pctsrf(ji, is_lic) = zmasq(ji)
-                pctsrf(ji, is_ter) = 0.
-            ELSE 
-                pctsrf(ji,is_ter) = zmasq(ji) - pctsrf(ji, is_lic)
-                IF (pctsrf(ji,is_ter) .LT. EPSFRA) THEN
-                    pctsrf(ji,is_ter) = 0.
-                    pctsrf(ji, is_lic) = zmasq(ji)
-                ENDIF 
-            ENDIF 
-        ENDIF 
-      END DO 
-C
-C sous surface ocean et glace de mer (pour demarrer on met glace de mer a 0)
-C
-      pctsrf(1 : klon, is_oce) = (1. - zmasq(1 : klon))
-
-
-      WHERE (pctsrf(1 : klon, is_oce) .LT. EPSFRA)
-          pctsrf(1 : klon, is_oce) = 0.
-      END WHERE 
-
-      if (couple) pctsrf(1 : klon, is_oce) = ocemask_fi(1 : klon)
-
-      isst = 0
-      where (pctsrf(2:klon-1,is_oce) >0.) isst = 1
-C
-C verif que somme des sous surface = 1
-C
-      ji=count( (abs( sum(pctsrf(1 : klon, 1 : nbsrf),dim=2))-1.0) 
-     $    .GT. EPSFRA)
-      IF (ji .NE. 0) THEN
-          WRITE(*,*) 'pb repartition sous maille pour ',ji,' points'
-      ENDIF 
-
-!      where (pctsrf(1:klon, is_ter) >= .5) 
-!        pctsrf(1:klon, is_ter) = 1.
-!        pctsrf(1:klon, is_oce) = 0.
-!        pctsrf(1:klon, is_sic) = 0.
-!        pctsrf(1:klon, is_lic) = 0.
-!        zmasq = 1.
-!      endwhere
-!      where (pctsrf(1:klon, is_lic) >= .5) 
-!        pctsrf(1:klon, is_ter) = 0.
-!        pctsrf(1:klon, is_oce) = 0.
-!        pctsrf(1:klon, is_sic) = 0.
-!        pctsrf(1:klon, is_lic) = 1.
-!        zmasq = 1.
-!      endwhere
-!      where (pctsrf(1:klon, is_oce) >= .5) 
-!        pctsrf(1:klon, is_ter) = 0.
-!        pctsrf(1:klon, is_oce) = 1.
-!        pctsrf(1:klon, is_sic) = 0.
-!        pctsrf(1:klon, is_lic) = 0.
-!        zmasq = 0.
-!      endwhere
-!      where (pctsrf(1:klon, is_sic) >= .5) 
-!        pctsrf(1:klon, is_ter) = 0.
-!        pctsrf(1:klon, is_oce) = 0.
-!        pctsrf(1:klon, is_sic) = 1.
-!        pctsrf(1:klon, is_lic) = 0.
-!        zmasq = 0.
-!      endwhere
-!      call gr_fi_dyn(1, klon, iip1, jjp1, zmasq, masque)
-C
-C verif que somme des sous surface = 1
-C
-!      ji=count( (abs( sum(pctsrf(1 : klon, 1 : nbsrf), dim = 2)) - 1.0 ) 
-!     $    .GT. EPSFRA)
-!      IF (ji .NE. 0) THEN
-!          WRITE(*,*) 'pb repartition sous maille pour ',ji,' points'
-!     ENDIF 
-
-      CALL gr_fi_ecrit(1,klon,iim,jjp1,zmasq,zx_tmp_2d)
-      write(*,*)'zmasq = '
-      write(*,'(96i1)')nint(zx_tmp_2d)
-      call gr_fi_dyn(1, klon, iip1, jjp1, zmasq, masque)
-      WRITE(*,*) 'MASQUE construit : Masque'
-      WRITE(*,'(97I1)') nINT(masque(:,:))
-
-
-
-C Calcul intermediaire
-c 
-      CALL massdair( p3d, masse  )
-c
-
-      print *,' ALPHAX ',alphax
-
-      DO  l = 1, llm
-        DO  i    = 1, iim
-          xppn(i) = aire( i, 1   ) * masse(  i     ,  1   , l )
-          xpps(i) = aire( i,jjp1 ) * masse(  i     , jjp1 , l )
-        ENDDO
-          xpn      = SUM(xppn)/apoln
-          xps      = SUM(xpps)/apols
-        DO i   = 1, iip1
-          masse(   i   ,   1     ,  l )   = xpn
-          masse(   i   ,   jjp1  ,  l )   = xps
-        ENDDO
-      ENDDO
-      q3d(iip1,:,:,:) = q3d(1,:,:,:)
-      phis(iip1,:) = phis(1,:)
-
-C Ecriture
-      CALL inidissip( lstardis, nitergdiv, nitergrot, niterh   ,
-     *                tetagdiv, tetagrot , tetatemp              )
-      print*,'sortie inidissip'
-      itau = 0
-      itau_dyn = 0
-      itau_phy = 0
-      iday = dayref +itau/day_step
-      time = real(itau-(iday-dayref)*day_step)/day_step
-c     
-      IF(time.GT.1)  THEN
-       time = time - 1
-       iday = iday + 1
-      ENDIF
-      day_ref = dayref
-      annee_ref = anneeref
-
-      CALL geopot  ( ip1jmp1, tpot  , pk , pks,  phis  , phi   )
-      print*,'sortie geopot'
-      
-      CALL caldyn0 ( itau,uvent,vvent,tpot,psol,masse,pk,phis ,
-     *                phi,w, pbaru,pbarv,time+iday-dayref   )
-       print*,'sortie caldyn0'     
-      CALL dynredem0("start.nc",dayref,phis)
-      print*,'sortie dynredem0'
-      CALL dynredem1("start.nc",0.0,vvent,uvent,tpot,q3d,masse ,
-     .                            psol)
-      print*,'sortie dynredem1' 
-C
-C Ecriture etat initial physique
-C
-      write(*,*)'phystep ',dtvr,iphysiq,nbapp_rad
-      phystep   = dtvr * FLOAT(iphysiq)
-      radpas    = NINT (86400./phystep/ FLOAT(nbapp_rad) )
-      write(*,*)'phystep =', phystep, radpas
-cIM : lecture de co2_ppm & solaire ds physiq.def
-c     co2_ppm   = 348.0
-c     solaire   = 1365.0
-
-c
-c Initialisation 
-c tsol, qsol, sn,albe, evap,tsoil,rain_fall, snow_fall,solsw, sollw,frugs
-c
-      ftsol(:,is_ter) = tsol
-      ftsol(:,is_lic) = tsol
-      ftsol(:,is_oce) = tsol
-      ftsol(:,is_sic) = tsol
-      snsrf(:,is_ter) = sn
-      snsrf(:,is_lic) = sn
-      snsrf(:,is_oce) = sn
-      snsrf(:,is_sic) = sn
-      falb1(:,is_ter) = 0.08
-      falb1(:,is_lic) = 0.6
-      falb1(:,is_oce) = 0.5
-      falb1(:,is_sic) = 0.6
-      falb2 = falb1
-      evap(:,:) = 0.
-      qsolsrf(:,is_ter) = 150
-      qsolsrf(:,is_lic) = 150
-      qsolsrf(:,is_oce) = 150.
-      qsolsrf(:,is_sic) = 150.
-      do i = 1, nbsrf
-        do j = 1, nsoilmx
-          tsoil(:,j,i) = tsol
-        enddo
-      enddo
-      rain_fall = 0.; snow_fall = 0.
-      solsw = 165.
-      sollw = -53.
-      t_ancien = 273.15
-      q_ancien = 0.
-      agesno = 0.
-c
-      frugs(1:klon,is_oce) = rugmer(1:klon)
-      frugs(1:klon,is_ter) = MAX(1.0e-05, zstd(1:klon)*zsig(1:klon)/2.0)
-      frugs(1:klon,is_lic) = MAX(1.0e-05, zstd(1:klon)*zsig(1:klon)/2.0)
-      frugs(1:klon,is_sic) = 0.001
-      fder = 0.0
-      clwcon = 0.0
-      rnebcon = 0.0
-      ratqs = 0.0
-      run_off_lic_0 = 0.0 
-      rugoro = 0.0
-
-c
-c Avant l'appel a phyredem, on initialize les modules de surface
-c avec les valeurs qui vont etre ecrit dans startphy.nc
-c
-      dummy = 1.0
-      pbl_tke(:,:,:) = 1.e-8 
-      zmax0(:) = 40.
-      f0(:) = 1.e-5
-      ema_work1(:,:) = 0.
-      ema_work2(:,:) = 0.
-      wake_deltat(:,:) = 0.
-      wake_deltaq(:,:) = 0.
-      wake_s(:) = 0.
-      wake_cstar(:) = 0.
-      wake_fip(:) = 0.
-
-      call fonte_neige_init(run_off_lic_0)
-      call pbl_surface_init(qsol, fder, snsrf, qsolsrf,
-     $     evap, frugs, agesno, tsoil)
-
-      call phyredem("startphy.nc")
-
-
-
-C     Sortie Visu pour les champs dynamiques
-cc      if (1.eq.0 ) then
-cc      print*,'sortie visu'
-cc      time_step = 1.
-cc      t_ops = 2.
-cc      t_wrt = 2.
-cc      itau = 2.
-cc      visu_file='Etat0_visu.nc'
-cc      CALL initdynav(visu_file,dayref,anneeref,time_step,
-cc     .              t_ops, t_wrt, visuid)
-cc      CALL writedynav(visuid, itau,vvent ,
-cc     .                uvent,tpot,pk,phi,q3d,masse,psol,phis)
-cc      else
-         print*,'CCCCCCCCCCCCCCCCCC REACTIVER SORTIE VISU DANS ETAT0'
-cc      endif
-      print*,'entree histclo'
-      CALL histclo
-
-#endif 
-!#endif of #ifdef CPP_EARTH
-      RETURN
-      !
-      END SUBROUTINE etat0_netcdf
Index: LMDZ4/trunk/libf/dyn3dpar/etat0_netcdf.F90
===================================================================
--- LMDZ4/trunk/libf/dyn3dpar/etat0_netcdf.F90	(revision 1319)
+++ LMDZ4/trunk/libf/dyn3dpar/etat0_netcdf.F90	(revision 1319)
@@ -0,0 +1,506 @@
+!
+! $Id$
+!
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE etat0_netcdf(ib, masque, letat0)
+!
+!-------------------------------------------------------------------------------
+! Purpose: Creates initial states
+!-------------------------------------------------------------------------------
+! Note: This routine is designed to work for Earth
+!-------------------------------------------------------------------------------
+#ifdef CPP_EARTH
+  USE startvar
+  USE ioipsl
+  USE dimphy
+  USE infotrac
+  USE fonte_neige_mod
+  USE pbl_surface_mod
+  USE phys_state_var_mod
+  USE filtreg_mod
+  USE regr_lat_time_climoz_m, ONLY: regr_lat_time_climoz
+  USE conf_phys_m,            ONLY: conf_phys
+  USE netcdf, ONLY : NF90_OPEN, NF90_NOWRITE, NF90_CLOSE, NF90_NOERR
+#endif
+  IMPLICIT NONE
+!-------------------------------------------------------------------------------
+! Arguments:
+#include "dimensions.h"
+#include "paramet.h"
+#include "iniprint.h"
+  LOGICAL,                    INTENT(IN)    :: ib     ! barycentric interpolat.
+  REAL, DIMENSION(iip1,jjp1), INTENT(INOUT) :: masque ! land mask
+  LOGICAL,                    INTENT(IN)    :: letat0 ! F: masque only required
+#ifndef CPP_EARTH
+  WRITE(lunout,*)'limit_netcdf: Earth-specific routine, needs Earth physics'
+#else
+!-------------------------------------------------------------------------------
+! Local variables:
+#include "comgeom2.h"
+#include "comvert.h"
+#include "comconst.h"
+#include "indicesol.h"
+#include "dimsoil.h"
+#include "temps.h"
+  REAL,    DIMENSION(klon)                 :: tsol, qsol
+  REAL,    DIMENSION(klon)                 :: sn, rugmer, run_off_lic_0
+  REAL,    DIMENSION(iip1,jjp1)            :: orog, rugo, psol, phis
+  REAL,    DIMENSION(iip1,jjp1,llm+1)      :: p3d
+  REAL,    DIMENSION(iip1,jjp1,llm)        :: uvent, t3d, tpot, qsat, qd
+  REAL,    DIMENSION(iip1,jjm ,llm)        :: vvent
+  REAL,    DIMENSION(:,:,:,:), ALLOCATABLE :: q3d
+  REAL,    DIMENSION(klon,nbsrf)           :: qsolsrf, snsrf, evap
+  REAL,    DIMENSION(klon,nbsrf)           :: frugs, agesno
+  REAL,    DIMENSION(klon,nsoilmx,nbsrf)   :: tsoil
+
+!--- Local variables for sea-ice reading:
+  INTEGER                                  :: iml_lic, jml_lic, llm_tmp
+  INTEGER                                  :: ttm_tmp, iret, fid
+  INTEGER, DIMENSION(1)                    :: itaul
+  REAL,    DIMENSION(1)                    :: lev
+  REAL                                     :: date
+  REAL,    DIMENSION(:,:),   ALLOCATABLE   ::  lon_lic,  lat_lic, fraclic
+  REAL,    DIMENSION(:),     ALLOCATABLE   :: dlon_lic, dlat_lic
+  REAL,    DIMENSION(iip1,jjp1)            :: flic_tmp
+
+!--- Misc
+  CHARACTER(LEN=80)                        :: x, fmt
+  INTEGER                                  :: i, j, l, ji
+  REAL,    DIMENSION(iip1,jjp1,llm)        :: alpha, beta, pk, pls, y
+  REAL,    DIMENSION(ip1jmp1)              :: pks
+
+#include "comdissnew.h"
+#include "control.h"
+#include "serre.h"
+#include "clesphys.h"
+
+  REAL,    DIMENSION(iip1,jjp1,llm)        :: masse
+  INTEGER :: itau, iday
+  REAL    :: xpn, xps, time, phystep
+  REAL,    DIMENSION(iim)                  :: xppn, xpps
+  REAL,    DIMENSION(ip1jmp1,llm)          :: pbaru, phi, w
+  REAL,    DIMENSION(ip1jm  ,llm)          :: pbarv
+  REAL,    DIMENSION(klon)                 :: fder
+
+!--- Local variables for ocean mask reading:
+  INTEGER :: nid_o2a, iml_omask, jml_omask
+  LOGICAL :: couple=.FALSE.
+  REAL,    DIMENSION(:,:), ALLOCATABLE ::  lon_omask, lat_omask, ocemask, ocetmp
+  REAL,    DIMENSION(:),   ALLOCATABLE :: dlon_omask,dlat_omask
+  REAL,    DIMENSION(klon)             :: ocemask_fi
+  INTEGER, DIMENSION(klon-2)           :: isst
+  REAL,    DIMENSION(iim,jjp1)         :: zx_tmp_2d
+  REAL    :: dummy
+  LOGICAL :: ok_newmicro, ok_journe, ok_mensuel, ok_instan, ok_hf
+  LOGICAL :: ok_LES, ok_ade, ok_aie, aerosol_couple, new_aod
+  INTEGER :: iflag_radia, flag_aerosol
+  REAL    :: bl95_b0, bl95_b1, fact_cldcon, facttemps, ratqsbas, ratqshaut
+  REAL    :: tau_ratqs
+  INTEGER :: iflag_cldcon, iflag_ratqs, iflag_coupl, iflag_clos, iflag_wake
+  INTEGER :: iflag_thermals, nsplit_thermals
+  INTEGER :: iflag_thermals_ed, iflag_thermals_optflux
+  REAL    :: tau_thermals, solarlong0,  seuil_inversion
+  INTEGER :: read_climoz ! read ozone climatology
+!  Allowed values are 0, 1 and 2
+!     0: do not read an ozone climatology
+!     1: read a single ozone climatology that will be used day and night
+!     2: read two ozone climatologies, the average day and night
+!     climatology and the daylight climatology
+!-------------------------------------------------------------------------------
+!--- Constants
+  pi     = 4. * ATAN(1.)
+  rad    = 6371229.
+  daysec = 86400.
+  omeg   = 2.*pi/daysec
+  g      = 9.8
+  kappa  = 0.2857143
+  cpp    = 1004.70885
+  preff  = 101325.
+  pa     = 50000.
+  jmp1   = jjm + 1
+
+!--- CONSTRUCT A GRID
+  CALL conf_phys(  ok_journe, ok_mensuel, ok_instan, ok_hf, ok_LES,     &
+                   solarlong0,seuil_inversion,                          &
+                   fact_cldcon, facttemps,ok_newmicro,iflag_radia,      &
+                   iflag_cldcon,                                        &
+                   iflag_ratqs,ratqsbas,ratqshaut,tau_ratqs,            &
+                   ok_ade, ok_aie, aerosol_couple,                      &
+                   flag_aerosol, new_aod,                               &
+                   bl95_b0, bl95_b1,                                    &
+                   iflag_thermals,nsplit_thermals,tau_thermals,         &
+                   iflag_thermals_ed,iflag_thermals_optflux,            &
+                   iflag_coupl,iflag_clos,iflag_wake, read_climoz )
+
+! co2_ppm0 : initial value of atmospheric CO2 from .def file (co2_ppm value)
+  co2_ppm0 = co2_ppm
+
+  dtvr   = daysec/FLOAT(day_step)
+  WRITE(lunout,*)'dtvr',dtvr
+
+  CALL iniconst()
+  CALL inigeom()
+
+!--- Initializations for tracers
+  CALL infotrac_init
+  ALLOCATE(q3d(iip1,jjp1,llm,nqtot))
+
+  CALL inifilr()
+  CALL phys_state_var_init(read_climoz)
+
+  rlat(1) = ASIN(1.0)
+  DO j=2,jjm; rlat((j-2)*iim+2:(j-1)*iim+1)=rlatu(j);     END DO
+  rlat(klon) = - ASIN(1.0)
+  rlat(:)=rlat(:)*(180.0/pi)
+
+  rlon(1) = 0.0
+  DO j=2,jjm; rlon((j-2)*iim+2:(j-1)*iim+1)=rlonv(1:iim); END DO
+  rlon(klon) = 0.0
+  rlon(:)=rlon(:)*(180.0/pi)
+
+! For a coupled simulation, the ocean mask from ocean model is used to compute
+! the weights an to insure ocean fractions are the same for atmosphere and ocean
+! Otherwise, mask is created using Relief file.
+
+  WRITE(lunout,*)'Essai de lecture masque ocean'
+  iret = NF90_OPEN("o2a.nc", NF90_NOWRITE, nid_o2a)
+  IF(iret/=NF90_NOERR) THEN
+    WRITE(lunout,*)'ATTENTION!! pas de fichier o2a.nc trouve'
+    WRITE(lunout,*)'Run force'
+    x='masque'
+    masque(:,:)=0.0
+    CALL startget(x, iip1, jjp1, rlonv, rlatu, masque, 0.0, jjm, rlonu,    &
+                  rlatv, ib)
+    WRITE(lunout,*)'MASQUE construit : Masque'
+    WRITE(lunout,'(97I1)') nINT(masque)
+    CALL gr_dyn_fi(1, iip1, jjp1, klon, masque, zmasq)
+    WHERE(   zmasq(:)<EPSFRA) zmasq(:)=0.
+    WHERE(1.-zmasq(:)<EPSFRA) zmasq(:)=1.
+  ELSE
+    couple=.true.
+    iret=NF90_CLOSE(nid_o2a)
+    CALL flininfo("o2a.nc", iml_omask, jml_omask, llm_tmp, ttm_tmp, nid_o2a)
+    IF(iml_omask/=iim .OR.jml_omask/=jjp1) THEN
+      WRITE(lunout,*)'Dimensions non compatibles pour masque ocean'
+      WRITE(lunout,*)'iim = ',iim,' iml_omask = ',iml_omask
+      WRITE(lunout,*)'jjp1 = ',jjp1,' jml_omask = ',jml_omask
+      CALL abort_gcm('etat0_netcdf','Dimensions non compatibles pour masque oc&
+     &ean',1)
+    END IF
+    ALLOCATE(  ocemask(iml_omask,jml_omask),   ocetmp(iml_omask,jml_omask))
+    ALLOCATE(lon_omask(iml_omask,jml_omask),lat_omask(iml_omask,jml_omask))
+    ALLOCATE(dlon_omask(iml_omask),dlat_omask(jml_omask))
+    CALL flinopen("o2a.nc", .FALSE., iml_omask, jml_omask, llm_tmp,            &
+                   lon_omask, lat_omask, lev, ttm_tmp, itaul, date, dt, fid)
+    CALL flinget(fid,'OceMask',iml_omask,jml_omask,llm_tmp,ttm_tmp,1,1,ocetmp)
+    CALL flinclo(fid)
+    dlon_omask(:)=lon_omask(:,1)
+    dlat_omask(:)=lat_omask(1,:)
+    ocemask=ocetmp
+    IF(dlat_omask(1)<dlat_omask(jml_omask)) THEN
+      DO j=1,jml_omask
+        ocemask(:,j) = ocetmp(:,jml_omask-j+1)
+      END DO
+    END IF 
+    ALLOCATE(   ocemask(iml_omask,jml_omask),   ocetmp(iml_omask,jml_omask))
+    ALLOCATE( lon_omask(iml_omask,jml_omask),lat_omask(iml_omask,jml_omask))
+    ALLOCATE(dlon_omask(iml_omask),         dlat_omask(jml_omask))
+    CALL flinopen("o2a.nc", .FALSE., iml_omask, jml_omask, llm_tmp, lon_omask, &
+                  lat_omask, lev, ttm_tmp, itaul, date, dt, fid)
+    CALL flinget(fid, 'OceMask', iml_omask, jml_omask, llm_tmp, ttm_tmp,       &
+                  1, 1, ocetmp)
+    CALL flinclo(fid)
+    dlon_omask(1:iml_omask) = lon_omask(1:iml_omask,1)
+    dlat_omask(1:jml_omask) = lat_omask(1,1:jml_omask)
+    ocemask = ocetmp
+    IF(dlat_omask(1)<dlat_omask(jml_omask)) THEN
+      DO j=1,jml_omask
+        ocemask(:,j) = ocetmp(:,jml_omask-j+1)
+      END DO
+    END IF
+!
+! Ocean mask to physical grid
+!*******************************************************************************
+    WRITE(lunout,*)'ocemask '
+    WRITE(fmt,"(i4,'i1)')")iml_omask ; fmt='('//ADJUSTL(fmt)
+    WRITE(lunout,fmt)int(ocemask)
+    ocemask_fi(1)=ocemask(1,1)
+    DO j=2,jjm; ocemask_fi((j-2)*iim+1:iim+1)=ocemask(1:iim,j); END DO
+    ocemask_fi(klon)=ocemask(1,jjp1)
+    zmasq=1.-ocemask_fi
+  END IF
+
+  CALL gr_fi_dyn(1,klon,iip1,jjp1,zmasq,masque)
+
+  ! The startget calls need to be replaced by a call to restget to get the
+  ! values in the restart file
+  x = 'relief'; orog(:,:) = 0.0
+  CALL startget(x,iip1,jjp1,rlonv,rlatu,          orog, 0.0,jjm,rlonu,rlatv,ib,&
+                masque)
+
+  x = 'rugosite'; rugo(:,:) = 0.0
+  CALL startget(x,iip1,jjp1,rlonv,rlatu,          rugo, 0.0,jjm, rlonu,rlatv,ib)
+!  WRITE(lunout,'(49I1)') INT(orog(:,:)*10)
+!  WRITE(lunout,'(49I1)') INT(rugo(:,:)*10)
+
+! Sub-surfaces initialization
+!*******************************************************************************
+  pctsrf=0.
+  x = 'psol'; psol(:,:) = 0.0
+  CALL startget(x,iip1,jjp1,rlonv,rlatu,psol,0.0,jjm,rlonu,rlatv,ib)
+!  WRITE(lunout,*) 'PSOL :', psol(10,20)
+!  WRITE(lunout,*) ap(:), bp(:)
+
+! Mid-levels pressure computation
+!*******************************************************************************
+  CALL pression(ip1jmp1, ap, bp, psol, p3d)
+  CALL exner_hyb(ip1jmp1, psol, p3d, alpha, beta, pks, pk, y)
+  pls(:,:,:)=preff*(pk(:,:,:)/cpp)**(1./kappa)
+!  WRITE(lunout,*) 'P3D :', p3d(10,20,:)
+!  WRITE(lunout,*) 'PK:',    pk(10,20,:)
+!  WRITE(lunout,*) 'PLS :', pls(10,20,:)
+
+  x = 'surfgeo'; phis(:,:) = 0.0
+  CALL startget(x,iip1,jjp1,rlonv,rlatu,          phis, 0.0,jjm, rlonu,rlatv,ib)
+
+  x = 'u';    uvent(:,:,:) = 0.0
+  CALL startget(x,iip1,jjp1,rlonu,rlatu,llm,pls,y,uvent,0.0,jjm, rlonv,rlatv,ib)
+
+  x = 'v';    vvent(:,:,:) = 0.0
+  CALL startget(x,iip1,jjm, rlonv,rlatv,llm,pls,y,vvent,0.0,jjp1,rlonu,rlatu,ib)
+
+  x = 't';    t3d(:,:,:) = 0.0
+  CALL startget(x,iip1,jjp1,rlonv,rlatu,llm,pls,y,t3d,  0.0,jjm, rlonu,rlatv,ib)
+
+  x = 'tpot'; tpot(:,:,:) = 0.0
+  CALL startget(x,iip1,jjp1,rlonv,rlatu,llm,pls,pk,tpot,0.0,jjm, rlonu,rlatv,ib)
+
+  WRITE(lunout,*) 'T3D min,max:',minval(t3d(:,:,:)),maxval(t3d(:,:,:))
+  WRITE(lunout,*) 'PLS min,max:',minval(pls(:,:,:)),maxval(pls(:,:,:))
+
+! Humidity at saturation computation
+!*******************************************************************************
+  WRITE(lunout,*) 'avant q_sat'
+  CALL q_sat(llm*jjp1*iip1, t3d, pls, qsat)
+  WRITE(lunout,*) 'apres q_sat'
+  WRITE(lunout,*) 'QSAT min,max:',minval(qsat(:,:,:)),maxval(qsat(:,:,:))
+!  WRITE(lunout,*) 'QSAT :',qsat(10,20,:)
+
+  x = 'q';    qd (:,:,:) = 0.0
+  CALL startget(x,iip1,jjp1,rlonv,rlatu,llm,pls,qsat,qd,0.0,jjm, rlonu,rlatv,ib)
+  q3d(:,:,:,:) = 0.0 ; q3d(:,:,:,1) = qd(:,:,:)
+
+!--- OZONE CLIMATOLOGY
+  IF(read_climoz>=1) CALL regr_lat_time_climoz(read_climoz)
+
+  x = 'tsol'; tsol(:) = 0.0
+  CALL startget(x,iip1,jjp1,rlonv,rlatu,klon,tsol,  0.0,jjm,rlonu,rlatv,ib)
+
+  x = 'qsol';  qsol(:) = 0.0
+  CALL startget(x,iip1,jjp1,rlonv,rlatu,klon,qsol,  0.0,jjm,rlonu,rlatv,ib)
+
+  x = 'snow';  sn(:) = 0.0
+  CALL startget(x,iip1,jjp1,rlonv,rlatu,klon,sn,    0.0,jjm,rlonu,rlatv,ib)
+
+  x = 'rads';  radsol(:) = 0.0
+  CALL startget(x,iip1,jjp1,rlonv,rlatu,klon,radsol,0.0,jjm,rlonu,rlatv,ib)
+
+  x = 'rugmer'; rugmer(:) = 0.0
+  CALL startget(x,iip1,jjp1,rlonv,rlatu,klon,rugmer,0.0,jjm,rlonu,rlatv,ib)
+
+  x = 'zmea';  zmea(:) = 0.0
+  CALL startget(x,iip1,jjp1,rlonv,rlatu,klon,zmea,  0.0,jjm,rlonu,rlatv,ib)
+
+  x = 'zstd';  zstd(:) = 0.0
+  CALL startget(x,iip1,jjp1,rlonv,rlatu,klon,zstd,  0.0,jjm,rlonu,rlatv,ib)
+
+  x = 'zsig';  zsig(:) = 0.0
+  CALL startget(x,iip1,jjp1,rlonv,rlatu,klon,zsig,  0.0,jjm,rlonu,rlatv,ib)
+
+  x = 'zgam';  zgam(:) = 0.0
+  CALL startget(x,iip1,jjp1,rlonv,rlatu,klon,zgam,  0.0,jjm,rlonu,rlatv,ib)
+
+  x = 'zthe';  zthe(:) = 0.0
+  CALL startget(x,iip1,jjp1,rlonv,rlatu,klon,zthe,  0.0,jjm,rlonu,rlatv,ib)
+
+  x = 'zpic';  zpic(:) = 0.0
+  CALL startget(x,iip1,jjp1,rlonv,rlatu,klon,zpic,  0.0,jjm,rlonu,rlatv,ib)
+
+  x = 'zval';  zval(:) = 0.0
+  CALL startget(x,iip1,jjp1,rlonv,rlatu,klon,zval,  0.0,jjm,rlonu,rlatv,ib)
+
+!  WRITE(lunout,'(48I3)') 'TSOL :', INT(tsol(2:klon)-273)
+
+! Soil ice file reading for soil fraction and soil ice fraction
+!*******************************************************************************
+  CALL flininfo("landiceref.nc", iml_lic, jml_lic, llm_tmp, ttm_tmp, fid)
+  ALLOCATE( lat_lic(iml_lic,jml_lic),lon_lic(iml_lic, jml_lic))
+  ALLOCATE(dlat_lic(jml_lic),       dlon_lic(iml_lic))
+  ALLOCATE( fraclic(iml_lic,jml_lic))
+  CALL flinopen("landiceref.nc", .FALSE., iml_lic, jml_lic, llm_tmp,           &
+                lon_lic, lat_lic, lev, ttm_tmp, itaul, date, dt, fid)
+  CALL flinget(fid, 'landice', iml_lic, jml_lic, llm_tmp, ttm_tmp, 1,1, fraclic)
+  CALL flinclo(fid)
+
+! Interpolation on model T-grid
+!*******************************************************************************
+  WRITE(lunout,*)'dimensions de landice iml_lic, jml_lic : ',iml_lic,jml_lic
+! conversion if coordinates are in degrees
+  IF(MAXVAL(lon_lic)>pi) lon_lic=lon_lic*pi/180.
+  IF(MAXVAL(lat_lic)>pi) lat_lic=lat_lic*pi/180.
+  dlon_lic(:)=lon_lic(:,1)
+  dlat_lic(:)=lat_lic(1,:)
+  CALL grille_m( iml_lic, jml_lic, dlon_lic, dlat_lic, fraclic, iim,jjp1,      &
+                 rlonv, rlatu, flic_tmp(1:iim,:) )
+  flic_tmp(iip1,:)=flic_tmp(1,:)
+
+!--- To the physical grid
+  CALL gr_dyn_fi(1, iip1, jjp1, klon, flic_tmp, pctsrf(:,is_lic))
+
+!--- Adequation with soil/sea mask
+  WHERE(pctsrf(:,is_lic)<EPSFRA) pctsrf(:,is_lic)=0. 
+  WHERE(zmasq(:)<EPSFRA)         pctsrf(:,is_lic)=0.
+  pctsrf(:,is_ter)=zmasq(:)
+  DO ji=1,klon
+    IF(zmasq(ji)>EPSFRA) THEN 
+      IF(pctsrf(ji,is_lic)>=zmasq(ji)) THEN
+        pctsrf(ji,is_lic)=zmasq(ji)
+        pctsrf(ji,is_ter)=0.
+      ELSE
+        pctsrf(ji,is_ter)=zmasq(ji)-pctsrf(ji,is_lic)
+        IF(pctsrf(ji,is_ter)<EPSFRA) THEN
+          pctsrf(ji,is_ter)=0.
+          pctsrf(ji,is_lic)=zmasq(ji)
+        END IF 
+      END IF 
+    END IF 
+  END DO 
+
+! sub-surface ocean and sea ice (sea ice set to zero for start)
+!*******************************************************************************
+  pctsrf(:,is_oce)=(1.-zmasq(:))
+  WHERE(pctsrf(:,is_oce)<EPSFRA) pctsrf(:,is_oce)=0.
+  IF(couple) pctsrf(:,is_oce)=ocemask_fi(:)
+  isst=0
+  WHERE(pctsrf(2:klon-1,is_oce)>0.) isst=1
+
+! It is checked that the sub-surfaces sum is equal to 1
+!*******************************************************************************
+  ji=COUNT((ABS(SUM(pctsrf(:,:),dim=2))-1.0)>EPSFRA)
+  IF(ji/=0) WRITE(lunout,*) 'pb repartition sous maille pour ',ji,' points'
+  CALL gr_fi_ecrit(1, klon, iim, jjp1, zmasq, zx_tmp_2d)
+!  WRITE(fmt,"(i3,')')")iim; fmt='(i'//ADJUSTL(fmt)
+!  WRITE(lunout,*)'zmasq = '
+!  WRITE(lunout,TRIM(fmt))NINT(zx_tmp_2d)
+  CALL gr_fi_dyn(1, klon, iip1, jjp1, zmasq, masque)
+  WRITE(fmt,"(i4,'i1)')")iip1 ; fmt='('//ADJUSTL(fmt)
+  WRITE(lunout,*) 'MASQUE construit : Masque'
+  WRITE(lunout,TRIM(fmt))NINT(masque(:,:))
+
+! Intermediate computation
+!*******************************************************************************
+  CALL massdair(p3d,masse)
+  WRITE(lunout,*)' ALPHAX ',alphax
+  DO l=1,llm
+    xppn(:)=aire(1:iim,1   )*masse(1:iim,1   ,l)
+    xpps(:)=aire(1:iim,jjp1)*masse(1:iim,jjp1,l)
+    xpn=SUM(xppn)/apoln
+    xps=SUM(xpps)/apols
+    masse(:,1   ,l)=xpn
+    masse(:,jjp1,l)=xps
+  END DO
+  q3d(iip1,:,:,:)=q3d(1,:,:,:)
+  phis(iip1,:) = phis(1,:)
+
+  IF(.NOT.letat0) RETURN
+
+! Writing
+!*******************************************************************************
+  CALL inidissip(lstardis,nitergdiv,nitergrot,niterh,tetagdiv,tetagrot,tetatemp)
+  WRITE(lunout,*)'sortie inidissip'
+  itau=0
+  itau_dyn=0
+  itau_phy=0
+  iday=dayref+itau/day_step
+  time=FLOAT(itau-(iday-dayref)*day_step)/day_step
+  IF(time>1.) THEN
+   time=time-1
+   iday=iday+1
+  END IF
+  day_ref=dayref
+  annee_ref=anneeref
+
+  CALL geopot( ip1jmp1, tpot, pk, pks, phis, phi )
+  WRITE(lunout,*)'sortie geopot'
+
+  CALL caldyn0( itau, uvent, vvent, tpot, psol, masse, pk, phis,               &
+                phi,  w, pbaru, pbarv, time+iday-dayref)
+  WRITE(lunout,*)'sortie caldyn0'     
+  CALL dynredem0( "start.nc", dayref, phis)
+  WRITE(lunout,*)'sortie dynredem0'
+  CALL dynredem1( "start.nc", 0.0, vvent, uvent, tpot, q3d, masse, psol)
+  WRITE(lunout,*)'sortie dynredem1' 
+
+! Physical initial state writting
+!*******************************************************************************
+  WRITE(lunout,*)'phystep ',dtvr,iphysiq,nbapp_rad
+  phystep   = dtvr * FLOAT(iphysiq)
+  radpas    = NINT (86400./phystep/ FLOAT(nbapp_rad) )
+  WRITE(lunout,*)'phystep =', phystep, radpas
+
+! Init: tsol, qsol, sn, evap, tsoil, rain_fall, snow_fall, solsw, sollw, frugs
+!*******************************************************************************
+  DO i=1,nbsrf; ftsol(:,i) = tsol; END DO
+  DO i=1,nbsrf; snsrf(:,i) = sn;   END DO
+  falb1(:,is_ter) = 0.08; falb1(:,is_lic) = 0.6
+  falb1(:,is_oce) = 0.5;  falb1(:,is_sic) = 0.6
+  falb2 = falb1
+  evap(:,:) = 0.
+  DO i=1,nbsrf; qsolsrf(:,i)=150.; END DO
+  DO i=1,nbsrf; DO j=1,nsoilmx; tsoil(:,j,i) = tsol; END DO; END DO
+  rain_fall = 0.; snow_fall = 0.
+  solsw = 165.;   sollw = -53.
+  t_ancien = 273.15
+  q_ancien = 0.
+  agesno = 0.
+  frugs(:,is_oce) = rugmer(:)
+  frugs(:,is_ter) = MAX(1.0e-05,zstd(:)*zsig(:)/2.0)
+  frugs(:,is_lic) = MAX(1.0e-05,zstd(:)*zsig(:)/2.0)
+  frugs(:,is_sic) = 0.001
+  fder = 0.0
+  clwcon = 0.0
+  rnebcon = 0.0
+  ratqs = 0.0
+  run_off_lic_0 = 0.0 
+  rugoro = 0.0
+
+! Before phyredem calling, surface modules and values to be saved in startphy.nc
+! are initialized
+!*******************************************************************************
+  dummy = 1.0
+  pbl_tke(:,:,:) = 1.e-8 
+  zmax0(:) = 40.
+  f0(:) = 1.e-5
+  ema_work1(:,:) = 0.
+  ema_work2(:,:) = 0.
+  wake_deltat(:,:) = 0.
+  wake_deltaq(:,:) = 0.
+  wake_s(:) = 0.
+  wake_cstar(:) = 0.
+  wake_fip(:) = 0.
+  CALL fonte_neige_init(run_off_lic_0)
+  CALL pbl_surface_init( qsol, fder, snsrf, qsolsrf, evap, frugs, agesno, tsoil )
+  CALL phyredem( "startphy.nc" )
+
+  WRITE(lunout,*)'CCCCCCCCCCCCCCCCCC REACTIVER SORTIE VISU DANS ETAT0'
+  WRITE(lunout,*)'entree histclo'
+  CALL histclo()
+
+#endif 
+!#endif of #ifdef CPP_EARTH
+  RETURN
+
+END SUBROUTINE etat0_netcdf
+!
+!-------------------------------------------------------------------------------
Index: LMDZ4/trunk/libf/dyn3dpar/limit_netcdf.F
===================================================================
--- LMDZ4/trunk/libf/dyn3dpar/limit_netcdf.F	(revision 1318)
+++ 	(revision )
@@ -1,1334 +1,0 @@
-!
-! $Id$
-!
-C
-C
-      SUBROUTINE limit_netcdf(interbar, extrap, oldice, masque)
-#ifdef CPP_EARTH
-! This routine is designed to work for Earth
-      USE dimphy
-      use phys_state_var_mod , ONLY : pctsrf
-      IMPLICIT none
-c
-c-------------------------------------------------------------
-C Author : L. Fairhead
-C Date   : 27/01/94
-C Objet  : Construction des fichiers de conditions aux limites
-C          pour le nouveau
-C          modele a partir de fichiers de climatologie. Les deux
-C          grilles doivent etre regulieres
-c
-c Modifie par z.x.li (le23mars1994)
-c Modifie par L. Fairhead (fairhead@lmd.jussieu.fr) septembre 1999
-c                         pour lecture netcdf dans LMDZ.3.3
-c Modifie par P;Le Van  ,  juillet 2001
-c-------------------------------------------------------------
-c
-#include "dimensions.h"
-#include "paramet.h"
-#include "control.h"
-#include "logic.h"
-#include "netcdf.inc"
-#include "comvert.h"
-#include "comgeom2.h"
-#include "comconst.h"
-cy#include "dimphy.h"
-#include "indicesol.h"
-#include "iniprint.h"
-c
-c-----------------------------------------------------------------------
-      LOGICAL interbar, extrap, oldice
-
-      REAL phy_nat(klon,360), phy_nat0(klon)
-      REAL phy_alb(klon,360)
-      REAL phy_sst(klon,360)
-      REAL phy_bil(klon,360)
-      REAL phy_rug(klon,360)
-      REAL phy_ice(klon)
-c
-      real pctsrf_t(klon,nbsrf,360)
-
-      REAL verif
-
-      REAL masque(iip1,jjp1)
-      REAL mask(iim,jjp1)
-CPB
-C newlmt indique l'utilisation de la sous-maille fractionnelle
-C tandis que l'ancien codage utilise l'indicateur du sol (0,1,2,3)
-      LOGICAL newlmt, fracterre
-      PARAMETER(newlmt=.TRUE.)
-      PARAMETER(fracterre = .TRUE.) 
-
-C Declarations pour le champ de depart
-      INTEGER imdep, jmdep,lmdep
-      INTEGER  tbid
-      PARAMETER ( tbid = 60 )        ! >52 semaines
-      REAL  timecoord(tbid)
-c
-      REAL , ALLOCATABLE :: dlon_msk(:), dlat_msk(:)
-      REAL , ALLOCATABLE :: lonmsk_ini(:), latmsk_ini(:)
-      REAL , ALLOCATABLE :: dlon(:), dlat(:)
-      REAL , ALLOCATABLE :: dlon_ini(:), dlat_ini(:)
-      REAL , ALLOCATABLE :: champ_msk(:), champ(:)
-      REAL , ALLOCATABLE :: work(:,:)
-
-      CHARACTER*25 title
-
-C Declarations pour le champ interpole 2D
-      REAL champint(iim,jjp1)
-      real chmin,chmax
-
-C Declarations pour le champ interpole 3D
-      REAL champtime(iim,jjp1,tbid)
-      REAL timeyear(tbid)
-      REAL champan(iip1,jjp1,366)
-
-C Declarations pour l'inteprolation verticale
-      REAL ax(tbid), ay(tbid)
-      REAL by
-      REAL yder(tbid)
-
-
-      INTEGER ierr
-      INTEGER dimfirst(3)
-      INTEGER dimlast(3)
-c
-      INTEGER nid, ndim, ntim
-      INTEGER dims(2), debut(2), epais(2)
-      INTEGER id_tim
-      INTEGER id_NAT, id_SST, id_BILS, id_RUG, id_ALB
-CPB
-      INTEGER id_FOCE, id_FSIC, id_FTER, id_FLIC
-
-      INTEGER i, j, k, l, ji
-c declarations pour lecture glace de mer
-      INTEGER :: iml_lic, jml_lic, llm_tmp, ttm_tmp, iret
-      INTEGER :: itaul(1), fid
-      REAL :: lev(1), date, dt
-      REAL, ALLOCATABLE, DIMENSION(:,:) :: lon_lic, lat_lic
-      REAL, ALLOCATABLE, DIMENSION(:)  :: dlon_lic, dlat_lic
-      REAL, ALLOCATABLE, DIMENSION (:,:) :: fraclic
-      REAL :: flic_tmp(iip1, jjp1)
-
-c Diverses variables locales
-      REAL time
-! pour la lecture du fichier masque ocean
-      integer :: nid_o2a
-      logical :: couple = .false.
-      INTEGER :: iml_omask, jml_omask
-      REAL, ALLOCATABLE, DIMENSION(:,:) :: lon_omask, lat_omask
-      REAL, ALLOCATABLE, DIMENSION(:)  :: dlon_omask, dlat_omask
-      REAL, ALLOCATABLE, DIMENSION (:,:) :: ocemask, ocetmp
-      real, dimension(klon) :: ocemask_fi
-
-      INTEGER          longcles
-      PARAMETER      ( longcles = 20 )
-      REAL  clesphy0 ( longcles      )
-#include "serre.h"
-      INTEGER ncid,varid,ndimid(4),dimid
-      character*30 namedim
-      CHARACTER*80 :: varname
-
-cIM28/02/2002 <== PM
-      REAL tmidmonth(12)
-      SAVE tmidmonth
-      DATA tmidmonth/15,45,75,105,135,165,195,225,255,285,315,345/
-
-c initialisations:
-      CALL conf_gcm( 99, .TRUE. , clesphy0 )
-
-
-      pi     = 4. * ATAN(1.)
-      rad    = 6 371 229.
-      omeg   = 4.* ASIN(1.)/(24.*3600.)
-      g      = 9.8
-      daysec = 86400.
-      kappa  = 0.2857143
-      cpp    = 1004.70885
-      dtvr    = daysec/FLOAT(day_step)
-      CALL inigeom
-c
-C Traitement du relief au sol
-c
-      write(*,*) 'Traitement du relief au sol pour fabriquer masque'
-      ierr = NF_OPEN('Relief.nc', NF_NOWRITE, ncid)
-
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF
-
-      ierr = NF_INQ_VARID(ncid,'RELIEF',varid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF
-      ierr = NF_INQ_VARDIMID (ncid,varid,ndimid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF
-      ierr = NF_INQ_DIM(ncid,ndimid(1), namedim, imdep)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF
-      print*,'variable ', namedim, 'dimension ', imdep
-      ierr = NF_INQ_VARID(ncid,namedim,dimid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF
-
-      ALLOCATE( lonmsk_ini(imdep) )
-      ALLOCATE(   dlon_msk(imdep) )
-
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(ncid,dimid,lonmsk_ini)
-#else
-      ierr = NF_GET_VAR_REAL(ncid,dimid,lonmsk_ini)
-#endif
-
-c
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF
-      ierr = NF_INQ_DIM(ncid,ndimid(2), namedim, jmdep)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF
-      print*,'variable ', namedim, 'dimension ', jmdep
-      ierr = NF_INQ_VARID(ncid,namedim,dimid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF
-
-      ALLOCATE( latmsk_ini(jmdep) )
-      ALLOCATE(   dlat_msk(jmdep) )
-      ALLOCATE(  champ_msk(imdep*jmdep) )
-
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(ncid,dimid,latmsk_ini)
-#else
-      ierr = NF_GET_VAR_REAL(ncid,dimid,latmsk_ini)
-#endif
-c
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(ncid,varid,champ_msk)
-#else
-      ierr = NF_GET_VAR_REAL(ncid,varid,champ_msk)
-#endif
-c
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF
-c
-      title='RELIEF'
-
-      CALL conf_dat2d(title,imdep, jmdep, lonmsk_ini, latmsk_ini,
-     . dlon_msk, dlat_msk, champ_msk, interbar  )
-
-      DO i = 1, iim
-      DO j = 1, jjp1
-         mask(i,j) = masque(i,j)
-      ENDDO
-      ENDDO
-      WRITE(*,*) 'MASK:'
-      WRITE(*,'(96i1)')INT(mask)     
-      ierr = NF_CLOSE(ncid)
-c
-c
-C Traitement de la rugosite
-c
-      PRINT*, 'Traitement de la rugosite'
-      ierr = NF_OPEN('Rugos.nc', NF_NOWRITE, ncid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF
-
-      ierr = NF_INQ_VARID(ncid,'RUGOS',varid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF
-      ierr = NF_INQ_VARDIMID (ncid,varid,ndimid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      ierr = NF_INQ_DIM(ncid,ndimid(1), namedim, imdep)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      print*,'variable ', namedim, 'dimension ', imdep
-      ierr = NF_INQ_VARID(ncid,namedim,dimid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-
-      ALLOCATE( dlon_ini(imdep) )
-      ALLOCATE(     dlon(imdep) )
-
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(ncid,dimid,dlon_ini)
-#else
-      ierr = NF_GET_VAR_REAL(ncid,dimid,dlon_ini)
-#endif
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      ierr = NF_INQ_DIM(ncid,ndimid(2), namedim, jmdep)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      print*,'variable ', namedim, 'dimension ', jmdep
-      ierr = NF_INQ_VARID(ncid,namedim,dimid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-
-      ALLOCATE( dlat_ini(jmdep) )
-      ALLOCATE(     dlat(jmdep) )
-
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(ncid,dimid,dlat_ini)
-#else
-      ierr = NF_GET_VAR_REAL(ncid,dimid,dlat_ini)
-#endif
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      ierr = NF_INQ_DIM(ncid,ndimid(3), namedim, lmdep)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF
-      print*,'variable ', namedim, 'dimension ', lmdep
-      ierr = NF_INQ_VARID(ncid,namedim,dimid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(ncid,dimid,timecoord)
-#else
-      ierr = NF_GET_VAR_REAL(ncid,dimid,timecoord)
-#endif
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF
-c
-      ALLOCATE( champ(imdep*jmdep) )
-
-      DO  200 l = 1, lmdep
-         dimfirst(1) = 1
-         dimfirst(2) = 1
-         dimfirst(3) = l
-c
-         dimlast(1) = imdep
-         dimlast(2) = jmdep
-         dimlast(3) = 1
-c
-         PRINT*,'Lecture temporelle et int. horizontale ',l,timecoord(l)
-         print*,dimfirst,dimlast
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VARA_DOUBLE(ncid,varid,dimfirst,dimlast,champ)
-#else
-         ierr = NF_GET_VARA_REAL(ncid,varid,dimfirst,dimlast,champ)
-#endif
-         if (ierr.ne.0) then
-           print *, NF_STRERROR(ierr)
-           STOP
-         ENDIF 
-   
-        title = 'Rugosite Amip '
-c
-        CALL conf_dat2d(title,imdep, jmdep, dlon_ini, dlat_ini,
-     .                      dlon, dlat, champ, interbar          )
-
-       IF ( interbar )   THEN
-         DO j = 1, imdep * jmdep
-           champ(j) = LOG(champ(j))
-         ENDDO
-
-        IF( l.EQ.1 )  THEN
-         WRITE(6,*) '-------------------------------------------------',
-     ,'------------------------'
-         WRITE(6,*) '$$$ Utilisation de l interpolation barycentrique ',
-     , ' pour la rugosite $$$ '
-         WRITE(6,*) '-------------------------------------------------',
-     ,'------------------------'
-        ENDIF
-        CALL inter_barxy ( imdep,jmdep -1,dlon,dlat,champ ,
-     ,                  iim,jjm,rlonu,rlatv, jjp1,champint )
-         DO j=1,jjp1
-          DO i=1,iim
-           champint(i,j)=EXP(champint(i,j))
-          ENDDO
-         ENDDO
-
-         DO j = 1, jjp1
-           DO i = 1, iim
-             IF(NINT(mask(i,j)).NE.1)  THEN
-               champint( i,j ) = 0.001
-             ENDIF
-           ENDDO
-         ENDDO
-      ELSE
-         CALL rugosite(imdep, jmdep, dlon, dlat, champ,
-     .             iim, jjp1, rlonv, rlatu, champint, mask)
-      ENDIF
-         DO j = 1,jjp1
-         DO i = 1, iim
-            champtime (i,j,l) = champint(i,j)
-         ENDDO
-         ENDDO
-200      CONTINUE
-c
-      DO l = 1, lmdep
-         timeyear(l) = timecoord(l)
-      ENDDO
-
-      PRINT 222, timeyear(:lmdep)
-222   FORMAT(2x,' Time year ',10f6.1)
-c
-        
-      PRINT*, 'Interpolation temporelle dans l annee'
-
-      DO j = 1, jjp1
-      DO i = 1, iim
-          DO l = 1, lmdep
-            ax(l) = timeyear(l)
-            ay(l) = champtime (i,j,l)
-          ENDDO
-          CALL SPLINE(ax,ay,lmdep,1.e30,1.e30,yder)
-          DO k = 1, 360
-            time = FLOAT(k-1)
-            CALL SPLINT(ax,ay,yder,lmdep,time,by)
-            champan(i,j,k) = by
-          ENDDO
-      ENDDO
-      ENDDO
-      DO k = 1, 360
-      DO j = 1, jjp1
-         champan(iip1,j,k) = champan(1,j,k)
-      ENDDO
-        IF ( k.EQ.10 )  THEN
-          DO j = 1, jjp1
-            CALL minmax( iip1,champan(1,j,10),chmin,chmax )
-            PRINT *,' Rugosite au temps 10 ', chmin,chmax,j
-          ENDDO
-        ENDIF
-      ENDDO
-c
-      DO k = 1, 360
-         CALL gr_dyn_fi(1,iip1,jjp1,klon,champan(1,1,k), phy_rug(1,k))
-      ENDDO
-c
-      ierr = NF_CLOSE(ncid)
-
-       DEALLOCATE( dlon      )
-       DEALLOCATE( dlon_ini  )
-       DEALLOCATE( dlat      )
-       DEALLOCATE( dlat_ini  )
-       DEALLOCATE( champ     )
-c
-c
-C Traitement de la glace oceanique
-c
-      PRINT*, 'Traitement de la glace oceanique'
-
-      ierr = NF_OPEN('amipbc_sic_1x1.nc', NF_NOWRITE, ncid)
-      if (ierr.ne.0) THEN
-        ierr = NF_OPEN('amipbc_sic_1x1_clim.nc', NF_NOWRITE, ncid)
-        if (ierr.ne.0) THEN
-          print *, NF_STRERROR(ierr)
-          STOP
-        endif
-      ENDIF
-
-cIM22/02/2002
-cIM07/03/2002 AMIP.nc & amip79to95.nc
-cIM   ierr = NF_INQ_VARID(ncid,'SEA_ICE',varid)
-cIM07/03/2002 amipbc_sic_1x1_clim.nc & amipbc_sic_1x1.nc
-      ierr = NF_INQ_VARID(ncid,'sicbcs',varid)
-cIM22/02/2002
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr),'sicbcs'
-        STOP
-      ENDIF
-      ierr = NF_INQ_VARDIMID (ncid,varid,ndimid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      ierr = NF_INQ_DIM(ncid,ndimid(1), namedim, imdep)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      print*,'variable ', namedim, 'dimension ', imdep
-      ierr = NF_INQ_VARID(ncid,namedim,dimid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-
-      ALLOCATE ( dlon_ini(imdep) )
-      ALLOCATE (     dlon(imdep) )
-
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(ncid,dimid,dlon_ini)
-#else
-      ierr = NF_GET_VAR_REAL(ncid,dimid,dlon_ini)
-#endif
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      ierr = NF_INQ_DIM(ncid,ndimid(2), namedim, jmdep)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      print*,'variable ', namedim, jmdep
-      ierr = NF_INQ_VARID(ncid,namedim,dimid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-
-      ALLOCATE ( dlat_ini(jmdep) )
-      ALLOCATE (     dlat(jmdep) )
-
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(ncid,dimid,dlat_ini)
-#else
-      ierr = NF_GET_VAR_REAL(ncid,dimid,dlat_ini)
-#endif
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      ierr = NF_INQ_DIM(ncid,ndimid(3), namedim, lmdep)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      print*,'variable ', namedim, lmdep
-cIM28/02/2002
-cPM28/02/2002 : nouvelle coord temporelle fichiers AMIP pas en jours
-c               Ici on suppose qu'on a 12 mois (de 30 jours).
-      IF (lmdep.NE.12) THEN
-          print *, 'Unknown AMIP file: not 12 months ?'
-          STOP
-       ENDIF
-cIM28/02/2002
-      ierr = NF_INQ_VARID(ncid,namedim,dimid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(ncid,dimid,timecoord)
-#else
-      ierr = NF_GET_VAR_REAL(ncid,dimid,timecoord)
-#endif
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-c
-      ALLOCATE ( champ(imdep*jmdep) )
-
-      DO l = 1, lmdep
-         dimfirst(1) = 1
-         dimfirst(2) = 1
-         dimfirst(3) = l
-c
-         dimlast(1) = imdep
-         dimlast(2) = jmdep
-         dimlast(3) = 1
-c
-         PRINT*,'Lecture temporelle et int. horizontale ',l,timecoord(l)
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VARA_DOUBLE(ncid,varid,dimfirst,dimlast,champ)
-#else
-         ierr = NF_GET_VARA_REAL(ncid,varid,dimfirst,dimlast,champ)
-#endif
-         if (ierr.ne.0) then
-           print *, NF_STRERROR(ierr)
-           STOP
-         ENDIF
- 
-         title = 'Sea-ice Amip '
-c
-         CALL conf_dat2d(title,imdep, jmdep, dlon_ini, dlat_ini,
-     .                        dlon, dlat, champ, interbar          )
-c
-      IF( oldice )  THEN
-                 CALL sea_ice(imdep, jmdep, dlon, dlat, champ,
-     .             iim, jjp1, rlonv, rlatu, champint )
-      ELSEIF ( interbar )  THEN
-       IF( l.EQ.1 )  THEN
-        WRITE(6,*) '-------------------------------------------------',
-     ,'------------------------'
-        WRITE(6,*) '$$$ Utilisation de l interpolation barycentrique ',
-     , ' pour Sea-ice Amip  $$$ '
-        WRITE(6,*) '-------------------------------------------------',
-     ,'------------------------'
-       ENDIF
-cIM07/03/2002 
-cIM22/02/2002 : Sea-ice Amip entre 0. et 1.
-cIM    PRINT*,'SUB. limit_netcdf.F IM : Sea-ice et SST Amip_new clim' 
-cIM   DO j = 1, imdep * jmdep
-cIM28/02/2002 <==PM         champ(j) = champ(j)/100.
-cIM14/03/2002      champ(j) = max(0.0,(min(1.0, (champ(j)/100.) )))
-cIM      champ(j) = amax1(0.0,(amin1(1.0, (champ(j)/100.) )))
-cIM   ENDDO
-cIM22/02/2002
-         CALL inter_barxy ( imdep,jmdep -1,dlon, dlat ,
-     ,     champ, iim, jjm, rlonu, rlatv, jjp1, champint )
-      ELSE
-         CALL sea_ice(imdep, jmdep, dlon, dlat, champ,
-     .             iim, jjp1, rlonv, rlatu, champint )
-      ENDIF
-         DO j = 1,jjp1
-         DO i = 1, iim
-            champtime (i,j,l) = champint(i,j)
-         ENDDO
-         ENDDO
-      ENDDO
-c
-      DO l = 1, lmdep
-cIM28/02/2002 <== PM  timeyear(l) = timecoord(l)
-cIM      timeyear(l) = timecoord(l)
-cIM07/03/2002      
-         timeyear(l) = tmidmonth(l)
-      ENDDO
-      PRINT 222,  timeyear(:lmdep)
-c
-      PRINT*, 'Interpolation temporelle'
-      DO j = 1, jjp1
-      DO i = 1, iim
-          DO l = 1, lmdep
-            ax(l) = timeyear(l)
-            ay(l) = champtime (i,j,l)
-          ENDDO
-          CALL SPLINE(ax,ay,lmdep,1.e30,1.e30,yder)
-          DO k = 1, 360
-            time = FLOAT(k-1)
-            CALL SPLINT(ax,ay,yder,lmdep,time,by)
-            champan(i,j,k) = by
-          ENDDO
-      ENDDO
-      ENDDO
-      DO k = 1, 360
-      DO j = 1, jjp1
-         champan(iip1, j, k) = champan(1, j, k)
-      ENDDO
-        IF ( k.EQ.10 )  THEN
-          DO j = 1, jjp1
-            CALL minmax( iip1,champan(1,j,10),chmin,chmax )
-            PRINT *,' Sea ice au temps 10 ', chmin,chmax,j
-          ENDDO
-        ENDIF
-      ENDDO
-c
-cIM14/03/2002 : Sea-ice Amip entre 0. et 1.
-      PRINT*,'SUB. limit_netcdf.F IM : Sea-ice Amipbc '
-      DO k = 1, 360
-      DO j = 1, jjp1
-      DO i = 1, iim
-        champan(i, j, k) = 
-     $ amax1(0.0,(amin1(1.0,(champan(i, j, k)/100.))))
-      ENDDO
-        champan(iip1, j, k) = champan(1, j, k)
-      ENDDO
-      ENDDO
-cIM14/03/2002
-
-      DO k = 1, 360
-         CALL gr_dyn_fi(1, iip1, jjp1, klon,
-     .                  champan(1,1,k), phy_ice)
-        IF ( newlmt) THEN
-
-CPB  en attendant de mettre fraction de terre
-c
-          WHERE(phy_ice(1:klon) .GE. 1.) phy_ice(1 : klon) = 1.
-          WHERE(phy_ice(1:klon) .LT. EPSFRA) phy_ice(1 : klon) = 0.
-c 
-          IF (fracterre ) THEN
-c            WRITE(*,*) 'passe dans cas fracterre' 
-            pctsrf_t(:,is_ter,k) = pctsrf(:,is_ter)
-            pctsrf_t(:,is_lic,k) = pctsrf(:,is_lic)
-            pctsrf_t(1:klon,is_sic,k) =   phy_ice(1:klon) 
-     $            - pctsrf_t(1:klon,is_lic,k)
-c Il y a des cas ou il y a de la glace dans landiceref et pas dans AMIP
-            WHERE (pctsrf_t(1:klon,is_sic,k) .LE. 0)
-              pctsrf_t(1:klon,is_sic,k) = 0.
-            END WHERE 
-            WHERE( 1. - zmasq(1:klon) .LT. EPSFRA)
-              pctsrf_t(1:klon,is_sic,k) = 0.
-              pctsrf_t(1:klon,is_oce,k) = 0.
-            END WHERE
-            DO i = 1, klon
-              IF ( 1. - zmasq(i) .GT. EPSFRA) THEN 
-                IF ( pctsrf_t(i,is_sic,k) .GE. 1 - zmasq(i)) THEN
-                  pctsrf_t(i,is_sic,k) = 1 - zmasq(i)
-                  pctsrf_t(i,is_oce,k) = 0.
-                ELSE 
-                  pctsrf_t(i,is_oce,k) = 1 - zmasq(i) 
-     $                    - pctsrf_t(i,is_sic,k)
-                  IF (pctsrf_t(i,is_oce,k) .LT. EPSFRA) THEN
-                    pctsrf_t(i,is_oce,k) = 0.
-                    pctsrf_t(i,is_sic,k) = 1 - zmasq(i)
-                  ENDIF 
-                ENDIF
-              ENDIF  
-              if (pctsrf_t(i,is_oce,k) .lt. 0.) then
-                WRITE(*,*) 'pb sous maille au point : i,k '
-     $              , i,k,pctsrf_t(:,is_oce,k)
-              ENDIF
-              IF ( abs( pctsrf_t(i, is_ter,k) + pctsrf_t(i, is_lic,k) + 
-     $          pctsrf_t(i, is_oce,k) + pctsrf_t(i, is_sic,k)  - 1.) 
-     $            .GT. EPSFRA) THEN 
-                  WRITE(*,*) 'physiq : pb sous surface au point ', i, 
-     $                pctsrf_t(i, 1 : nbsrf,k), phy_ice(i)
-              ENDIF 
-            END DO
-          ELSE 
-            DO i = 1, klon
-              pctsrf_t(i,is_ter,k) = pctsrf(i,is_ter)
-              IF (NINT(pctsrf(i,is_ter)).EQ.1 ) THEN
-                pctsrf_t(i,is_sic,k) = 0.
-                pctsrf_t(i,is_oce,k) = 0.                  
-                IF(phy_ice(i) .GE. 1.e-5) THEN
-                  pctsrf_t(i,is_lic,k) = phy_ice(i)
-                  pctsrf_t(i,is_ter,k) = pctsrf_t(i,is_ter,k) 
-     .                                   - pctsrf_t(i,is_lic,k)
-                ELSE
-                  pctsrf_t(i,is_lic,k) = 0.
-                ENDIF 
-              ELSE
-                pctsrf_t(i,is_lic,k) = 0. 
-                IF(phy_ice(i) .GE. 1.e-5) THEN 
-                  pctsrf_t(i,is_ter,k) = 0.
-                  pctsrf_t(i,is_sic,k) = phy_ice(i)
-                  pctsrf_t(i,is_oce,k) = 1. - pctsrf_t(i,is_sic,k)
-                ELSE
-                  pctsrf_t(i,is_sic,k) = 0.
-                  pctsrf_t(i,is_oce,k) = 1.                      
-                ENDIF 
-              ENDIF
-              verif = pctsrf_t(i,is_ter,k) +
-     .                pctsrf_t(i,is_oce,k) + 
-     .                pctsrf_t(i,is_sic,k) +
-     .                pctsrf_t(i,is_lic,k)
-              IF ( verif .LT. 1. - 1.e-5 .OR. 
-     $             verif .GT. 1 + 1.e-5) THEN  
-                WRITE(*,*) 'pb sous maille au point : i,k,verif '
-     $                    , i,k,verif
-              ENDIF 
-            END DO
-          ENDIF 
-        ELSE  
-          DO i = 1, klon
-            phy_nat(i,k) = phy_nat0(i)
-            IF ( (phy_ice(i) - 0.5).GE.1.e-5 ) THEN
-              IF (NINT(phy_nat0(i)).EQ.0) THEN
-                phy_nat(i,k) = 3.0
-              ELSE
-                phy_nat(i,k) = 2.0
-              ENDIF
-            ENDIF
-            IF( NINT(phy_nat(i,k)).EQ.0 ) THEN
-              IF ( phy_rug(i,k).NE.0.001 ) phy_rug(i,k) = 0.001
-            ENDIF
-          END DO
-        ENDIF
-      ENDDO
-c
-
-      ierr = NF_CLOSE(ncid)
-c
-       DEALLOCATE( dlon      )
-       DEALLOCATE( dlon_ini  )
-       DEALLOCATE( dlat      )
-       DEALLOCATE( dlat_ini  )
-       DEALLOCATE( champ     )
-
-477    continue
-c
-C Traitement de la sst
-c
-      PRINT*, 'Traitement de la sst'
-c     ierr = NF_OPEN('AMIP_SST.nc', NF_NOWRITE, ncid)
-      ierr = NF_OPEN('amipbc_sst_1x1.nc', NF_NOWRITE, ncid)
-      if (ierr.ne.0) THEN
-        ierr = NF_OPEN('amipbc_sst_1x1_clim.nc', NF_NOWRITE, ncid)
-        if (ierr.ne.0) THEN
-          print *, NF_STRERROR(ierr)
-          STOP
-        endif
-      ENDIF
-
-cIM22/02/2002
-cIM   ierr = NF_INQ_VARID(ncid,'SST',varid)
-      ierr = NF_INQ_VARID(ncid,'tosbcs',varid)
-cIM22/02/2002
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF
-      ierr = NF_INQ_VARDIMID (ncid,varid,ndimid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      ierr = NF_INQ_DIM(ncid,ndimid(1), namedim, imdep)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      print*,'variable SST ', namedim,'dimension ', imdep
-      ierr = NF_INQ_VARID(ncid,namedim,dimid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
- 
-      ALLOCATE( dlon_ini(imdep) )
-      ALLOCATE(     dlon(imdep) )
-
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(ncid,dimid,dlon_ini)
-#else
-      ierr = NF_GET_VAR_REAL(ncid,dimid,dlon_ini)
-#endif
-
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      ierr = NF_INQ_DIM(ncid,ndimid(2), namedim, jmdep)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      print*,'variable SST ', namedim, 'dimension ', jmdep
-      ierr = NF_INQ_VARID(ncid,namedim,dimid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-
-      ALLOCATE( dlat_ini(jmdep) )
-      ALLOCATE(     dlat(jmdep) )
-
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(ncid,dimid,dlat_ini)
-#else
-      ierr = NF_GET_VAR_REAL(ncid,dimid,dlat_ini)
-#endif
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      ierr = NF_INQ_DIM(ncid,ndimid(3), namedim, lmdep)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      print*,'variable ', namedim, 'dimension ', lmdep
-cIM28/02/2002
-cPM28/02/2002 : nouvelle coord temporelle fichiers AMIP pas en jours
-c               Ici on suppose qu'on a 12 mois (de 30 jours).
-      IF (lmdep.NE.12) THEN
-          print *, 'Unknown AMIP file: not 12 months ?'
-          STOP
-       ENDIF
-cIM28/02/2002
-      ierr = NF_INQ_VARID(ncid,namedim,dimid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(ncid,dimid,timecoord)
-#else
-      ierr = NF_GET_VAR_REAL(ncid,dimid,timecoord)
-#endif
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-
-       ALLOCATE( champ(imdep*jmdep) )
-       IF( extrap )   THEN
-         ALLOCATE ( work(imdep,jmdep) )
-       ENDIF
-c
-      DO l = 1, lmdep
-         dimfirst(1) = 1
-         dimfirst(2) = 1
-         dimfirst(3) = l
-c
-         dimlast(1) = imdep
-         dimlast(2) = jmdep
-         dimlast(3) = 1
-c
-         PRINT*,'Lecture temporelle et int. horizontale ',l,timecoord(l)
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VARA_DOUBLE(ncid,varid,dimfirst,dimlast,champ)
-#else
-         ierr = NF_GET_VARA_REAL(ncid,varid,dimfirst,dimlast,champ)
-#endif
-         if (ierr.ne.0) then
-           print *, NF_STRERROR(ierr)
-           STOP
-         ENDIF
-
-         title='Sst Amip'
-c
-         CALL conf_dat2d(title,imdep, jmdep, dlon_ini, dlat_ini,
-     .                            dlon, dlat, champ, interbar     )
-       IF ( extrap )  THEN
-        CALL extrapol(champ, imdep, jmdep, 999999.,.TRUE.,.TRUE.,2,work)
-       ENDIF
-c
-
-      IF ( interbar )  THEN
-        IF( l.EQ.1 )  THEN
-         WRITE(6,*) '-------------------------------------------------',
-     ,'------------------------'
-         WRITE(6,*) '$$$ Utilisation de l interpolation barycentrique ',
-     , ' pour la Sst Amip $$$ '
-         WRITE(6,*) '-------------------------------------------------',
-     ,'------------------------'
-        ENDIF
-       CALL inter_barxy ( imdep,jmdep -1,dlon, dlat ,
-     , champ, iim, jjm, rlonu, rlatv, jjp1, champint )
-      ELSE
-       CALL grille_m(imdep, jmdep, dlon, dlat, champ,
-     .          iim, jjp1, rlonv, rlatu, champint   )
-      ENDIF
-
-         DO j = 1,jjp1
-         DO i = 1, iim
-            champtime (i,j,l) = champint(i,j)
-         ENDDO
-         ENDDO
-      ENDDO
-c
-      DO l = 1, lmdep
-cIM28/02/2002 <==PM  timeyear(l) = timecoord(l)
-         timeyear(l) = tmidmonth(l)
-      ENDDO
-      print 222,  timeyear(:lmdep)
-c
-C interpolation temporelle
-      DO j = 1, jjp1
-      DO i = 1, iim
-          DO l = 1, lmdep
-            ax(l) = timeyear(l)
-            ay(l) = champtime (i,j,l)
-          ENDDO
-          CALL SPLINE(ax,ay,lmdep,1.e30,1.e30,yder)
-          DO k = 1, 360
-            time = FLOAT(k-1)
-            CALL SPLINT(ax,ay,yder,lmdep,time,by)
-            champan(i,j,k) = by
-          ENDDO
-      ENDDO
-      ENDDO
-      DO k = 1, 360
-      DO j = 1, jjp1
-         champan(iip1,j,k) = champan(1,j,k)
-      ENDDO
-        IF ( k.EQ.10 )  THEN
-          DO j = 1, jjp1
-            CALL minmax( iip1,champan(1,j,10),chmin,chmax )
-            PRINT *,' SST au temps 10 ', chmin,chmax,j
-          ENDDO
-        ENDIF
-      ENDDO
-c
-cIM14/03/2002 : SST amipbc greater then 271.38
-      PRINT*,'SUB. limit_netcdf.F IM : SST Amipbc >= 271.38 '
-      DO k = 1, 360
-      DO j = 1, jjp1
-      DO i = 1, iim
-         champan(i, j, k) = amax1(champan(i, j, k), 271.38)
-      ENDDO
-         champan(iip1, j, k) = champan(1, j, k)
-      ENDDO
-      ENDDO
-cIM14/03/2002
-      DO k = 1, 360
-         CALL gr_dyn_fi(1, iip1, jjp1, klon, 
-     .                  champan(1,1,k), phy_sst(1,k))
-      ENDDO
-c
-      ierr = NF_CLOSE(ncid)
-c
-       DEALLOCATE( dlon      )
-       DEALLOCATE( dlon_ini  )
-       DEALLOCATE( dlat      )
-       DEALLOCATE( dlat_ini  )
-       DEALLOCATE( champ     )
-c
-C Traitement de l'albedo
-c
-      PRINT*, 'Traitement de l albedo'
-      ierr = NF_OPEN('Albedo.nc', NF_NOWRITE, ncid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF
-      ierr = NF_INQ_VARID(ncid,'ALBEDO',varid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF
-      ierr = NF_INQ_VARDIMID (ncid,varid,ndimid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      ierr = NF_INQ_DIM(ncid,ndimid(1), namedim, imdep)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      print*,'variable ', namedim, 'dimension ', imdep
-      ierr = NF_INQ_VARID(ncid,namedim,dimid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-
-      ALLOCATE ( dlon_ini(imdep) )
-      ALLOCATE (     dlon(imdep) )
-
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(ncid,dimid,dlon_ini)
-#else
-      ierr = NF_GET_VAR_REAL(ncid,dimid,dlon_ini)
-#endif
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      ierr = NF_INQ_DIM(ncid,ndimid(2), namedim, jmdep)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      print*,'variable ', namedim, 'dimension ', jmdep
-      ierr = NF_INQ_VARID(ncid,namedim,dimid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-
-      ALLOCATE ( dlat_ini(jmdep) )
-      ALLOCATE (     dlat(jmdep) )
-
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(ncid,dimid,dlat_ini)
-#else
-      ierr = NF_GET_VAR_REAL(ncid,dimid,dlat_ini)
-#endif
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      ierr = NF_INQ_DIM(ncid,ndimid(3), namedim, lmdep)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-      print*,'variable ', namedim, 'dimension ', lmdep
-      ierr = NF_INQ_VARID(ncid,namedim,dimid)
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-#ifdef NC_DOUBLE
-      ierr = NF_GET_VAR_DOUBLE(ncid,dimid,timecoord)
-#else
-      ierr = NF_GET_VAR_REAL(ncid,dimid,timecoord)
-#endif
-      if (ierr.ne.0) then
-        print *, NF_STRERROR(ierr)
-        STOP
-      ENDIF 
-c
-      ALLOCATE ( champ(imdep*jmdep) )
-
-      DO l = 1, lmdep
-         dimfirst(1) = 1
-         dimfirst(2) = 1
-         dimfirst(3) = l
-c
-         dimlast(1) = imdep
-         dimlast(2) = jmdep
-         dimlast(3) = 1
-c
-         PRINT*,'Lecture temporelle et int. horizontale ',l,timecoord(l)
-#ifdef NC_DOUBLE
-         ierr = NF_GET_VARA_DOUBLE(ncid,varid,dimfirst,dimlast,champ)
-#else
-         ierr = NF_GET_VARA_REAL(ncid,varid,dimfirst,dimlast,champ)
-#endif
-         if (ierr.ne.0) then
-           print *, NF_STRERROR(ierr)
-           STOP
-         ENDIF
-
-         title='Albedo Amip'
-c
-         CALL conf_dat2d(title,imdep, jmdep, dlon_ini, dlat_ini,
-     .                            dlon, dlat, champ, interbar      )
-c
-c
-      IF ( interbar )  THEN
-        IF( l.EQ.1 )  THEN
-         WRITE(6,*) '-------------------------------------------------',
-     ,'------------------------'
-         WRITE(6,*) '$$$ Utilisation de l interpolation barycentrique ',
-     , ' pour l Albedo Amip $$$ '
-         WRITE(6,*) '-------------------------------------------------',
-     ,'------------------------'
-        ENDIF
-
-       CALL inter_barxy ( imdep,jmdep -1,dlon, dlat ,
-     , champ, iim, jjm, rlonu, rlatv, jjp1, champint )
-      ELSE
-       CALL grille_m(imdep, jmdep, dlon, dlat, champ,
-     .          iim, jjp1, rlonv, rlatu, champint   )
-      ENDIF
-c
-         DO j = 1,jjp1
-         DO i = 1, iim
-            champtime (i, j, l) = champint(i, j)
-         ENDDO
-         ENDDO
-      ENDDO
-c
-      DO l = 1, lmdep
-         timeyear(l) = timecoord(l)
-      ENDDO
-      print 222,  timeyear(:lmdep)
-c
-C interpolation temporelle
-      DO j = 1, jjp1
-      DO i = 1, iim
-          DO l = 1, lmdep
-            ax(l) = timeyear(l)
-            ay(l) = champtime (i, j, l)
-          ENDDO
-          CALL SPLINE(ax,ay,lmdep,1.e30,1.e30,yder)
-          DO k = 1, 360
-            time = FLOAT(k-1)
-            CALL SPLINT(ax,ay,yder,lmdep,time,by)
-            champan(i,j,k) = by
-          ENDDO
-      ENDDO
-      ENDDO
-      DO k = 1, 360
-      DO j = 1, jjp1
-         champan(iip1, j, k) = champan(1, j, k)
-      ENDDO
-        IF ( k.EQ.10 )  THEN
-          DO j = 1, jjp1
-            CALL minmax( iip1,champan(1,j,10),chmin,chmax )
-            PRINT *,' Albedo au temps 10 ', chmin,chmax,j
-          ENDDO
-        ENDIF
-      ENDDO
-c
-      DO k = 1, 360
-         CALL gr_dyn_fi(1, iip1, jjp1, klon,
-     .                  champan(1,1,k), phy_alb(1,k))
-      ENDDO
-c
-      ierr = NF_CLOSE(ncid)
-c
-c
-      DO k = 1, 360
-      DO i = 1, klon
-         phy_bil(i,k) = 0.0
-      ENDDO
-      ENDDO
-c
-      PRINT*, 'Ecriture du fichier limit'
-c
-      ierr = NF_CREATE ("limit.nc", NF_CLOBBER, nid)
-c
-      ierr = NF_PUT_ATT_TEXT (nid, NF_GLOBAL, "title", 30,
-     .                       "Fichier conditions aux limites")
-      ierr = NF_DEF_DIM (nid, "points_physiques", klon, ndim)
-      ierr = NF_DEF_DIM (nid, "time", NF_UNLIMITED, ntim)
-c
-      dims(1) = ndim
-      dims(2) = ntim
-c
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid, "TEMPS", NF_DOUBLE, 1,ntim, id_tim)
-#else
-      ierr = NF_DEF_VAR (nid, "TEMPS", NF_FLOAT, 1,ntim, id_tim)
-#endif
-      ierr = NF_PUT_ATT_TEXT (nid, id_tim, "title", 17,
-     .                        "Jour dans l annee")
-      IF (newlmt) THEN
-c
-#ifdef NC_DOUBLE
-        ierr = NF_DEF_VAR (nid, "FOCE", NF_DOUBLE, 2,dims, id_FOCE)
-#else
-        ierr = NF_DEF_VAR (nid, "FOCE", NF_FLOAT, 2,dims, id_FOCE)
-#endif
-        ierr = NF_PUT_ATT_TEXT (nid, id_FOCE, "title", 14,
-     .                      "Fraction ocean")
-c
-#ifdef NC_DOUBLE
-        ierr = NF_DEF_VAR (nid, "FSIC", NF_DOUBLE, 2,dims, id_FSIC)
-#else
-        ierr = NF_DEF_VAR (nid, "FSIC", NF_FLOAT, 2,dims, id_FSIC)
-#endif
-        ierr = NF_PUT_ATT_TEXT (nid, id_FSIC, "title", 21,
-     .                      "Fraction glace de mer")
-c
-#ifdef NC_DOUBLE
-        ierr = NF_DEF_VAR (nid, "FTER", NF_DOUBLE, 2,dims, id_FTER)
-#else
-        ierr = NF_DEF_VAR (nid, "FTER", NF_FLOAT, 2,dims, id_FTER)
-#endif
-        ierr = NF_PUT_ATT_TEXT (nid, id_FTER, "title", 14,
-     .                      "Fraction terre")
-c
-#ifdef NC_DOUBLE
-        ierr = NF_DEF_VAR (nid, "FLIC", NF_DOUBLE, 2,dims, id_FLIC)
-#else
-        ierr = NF_DEF_VAR (nid, "FLIC", NF_FLOAT, 2,dims, id_FLIC)
-#endif
-        ierr = NF_PUT_ATT_TEXT (nid, id_FLIC, "title", 17,
-     .                      "Fraction land ice")
-c
-      ELSE 
-#ifdef NC_DOUBLE
-        ierr = NF_DEF_VAR (nid, "NAT", NF_DOUBLE, 2,dims, id_NAT)
-#else
-        ierr = NF_DEF_VAR (nid, "NAT", NF_FLOAT, 2,dims, id_NAT)
-#endif
-        ierr = NF_PUT_ATT_TEXT (nid, id_NAT, "title", 23,
-     .                      "Nature du sol (0,1,2,3)")
-      ENDIF 
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid, "SST", NF_DOUBLE, 2,dims, id_SST)
-#else
-      ierr = NF_DEF_VAR (nid, "SST", NF_FLOAT, 2,dims, id_SST)
-#endif
-      ierr = NF_PUT_ATT_TEXT (nid, id_SST, "title", 35,
-     .                      "Temperature superficielle de la mer")
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid, "BILS", NF_DOUBLE, 2,dims, id_BILS)
-#else
-      ierr = NF_DEF_VAR (nid, "BILS", NF_FLOAT, 2,dims, id_BILS)
-#endif
-      ierr = NF_PUT_ATT_TEXT (nid, id_BILS, "title", 32,
-     .                        "Reference flux de chaleur au sol")
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid, "ALB", NF_DOUBLE, 2,dims, id_ALB)
-#else
-      ierr = NF_DEF_VAR (nid, "ALB", NF_FLOAT, 2,dims, id_ALB)
-#endif
-      ierr = NF_PUT_ATT_TEXT (nid, id_ALB, "title", 19,
-     .                        "Albedo a la surface")
-#ifdef NC_DOUBLE
-      ierr = NF_DEF_VAR (nid, "RUG", NF_DOUBLE, 2,dims, id_RUG)
-#else
-      ierr = NF_DEF_VAR (nid, "RUG", NF_FLOAT, 2,dims, id_RUG)
-#endif
-      ierr = NF_PUT_ATT_TEXT (nid, id_RUG, "title", 8,
-     .                        "Rugosite")
-c
-      ierr = NF_ENDDEF(nid)
-c
-      DO k = 1, 360
-c
-      debut(1) = 1
-      debut(2) = k
-      epais(1) = klon
-      epais(2) = 1
-c
-#ifdef NC_DOUBLE
-      ierr = NF_PUT_VAR1_DOUBLE (nid,id_tim,k,DBLE(k))
-c
-      IF (newlmt ) THEN
-          ierr = NF_PUT_VARA_DOUBLE (nid,id_FOCE,debut,epais
-     $        ,pctsrf_t(1,is_oce,k))
-          ierr = NF_PUT_VARA_DOUBLE (nid,id_FSIC,debut,epais
-     $        ,pctsrf_t(1,is_sic,k))
-          ierr = NF_PUT_VARA_DOUBLE (nid,id_FTER,debut,epais
-     $        ,pctsrf_t(1,is_ter,k))
-          ierr = NF_PUT_VARA_DOUBLE (nid,id_FLIC,debut,epais
-     $        ,pctsrf_t(1,is_lic,k))
-      ELSE 
-          ierr = NF_PUT_VARA_DOUBLE (nid,id_NAT,debut,epais
-     $        ,phy_nat(1,k))
-      ENDIF 
-c
-      ierr = NF_PUT_VARA_DOUBLE (nid,id_SST,debut,epais,phy_sst(1,k))
-      ierr = NF_PUT_VARA_DOUBLE (nid,id_BILS,debut,epais,phy_bil(1,k))
-      ierr = NF_PUT_VARA_DOUBLE (nid,id_ALB,debut,epais,phy_alb(1,k))
-      ierr = NF_PUT_VARA_DOUBLE (nid,id_RUG,debut,epais,phy_rug(1,k))
-#else
-      ierr = NF_PUT_VAR1_REAL (nid,id_tim,k,FLOAT(k))
-      IF (newlmt ) THEN
-          ierr = NF_PUT_VARA_REAL (nid,id_FOCE,debut,epais
-     $        ,pctsrf_t(1,is_oce,k))
-          ierr = NF_PUT_VARA_REAL (nid,id_FSIC,debut,epais
-     $        ,pctsrf_t(1,is_sic,k))
-          ierr = NF_PUT_VARA_REAL (nid,id_FTER,debut,epais
-     $        ,pctsrf_t(1,is_ter,k))
-          ierr = NF_PUT_VARA_REAL (nid,id_FLIC,debut,epais
-     $        ,pctsrf_t(1,is_lic,k))
-      ELSE 
-          ierr = NF_PUT_VARA_REAL (nid,id_NAT,debut,epais
-     $        ,phy_nat(1,k))
-      ENDIF 
-      ierr = NF_PUT_VARA_REAL (nid,id_SST,debut,epais,phy_sst(1,k))
-      ierr = NF_PUT_VARA_REAL (nid,id_BILS,debut,epais,phy_bil(1,k))
-      ierr = NF_PUT_VARA_REAL (nid,id_ALB,debut,epais,phy_alb(1,k))
-      ierr = NF_PUT_VARA_REAL (nid,id_RUG,debut,epais,phy_rug(1,k))
-#endif
-c
-      ENDDO
-c
-      ierr = NF_CLOSE(nid)
-c
-#else
-      WRITE(lunout,*)
-     & 'limit_netcdf: Earth-specific routine, needs Earth physics'
-#endif
-! of #ifdef CPP_EARTH
-      STOP
-      END
Index: LMDZ4/trunk/libf/dyn3dpar/limit_netcdf.F90
===================================================================
--- LMDZ4/trunk/libf/dyn3dpar/limit_netcdf.F90	(revision 1319)
+++ LMDZ4/trunk/libf/dyn3dpar/limit_netcdf.F90	(revision 1319)
@@ -0,0 +1,617 @@
+!
+! $Id$
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE limit_netcdf(interbar, extrap, oldice, masque)
+!
+!-------------------------------------------------------------------------------
+! Author : L. Fairhead, 27/01/94
+!-------------------------------------------------------------------------------
+! Purpose: Boundary conditions files building for new model using climatologies.
+!          Both grids have to be regular.
+!-------------------------------------------------------------------------------
+! Note: This routine is designed to work for Earth
+!-------------------------------------------------------------------------------
+! Modification history:
+!  * 23/03/1994: Z. X. Li
+!  *    09/1999: L. Fairhead (netcdf reading in LMDZ.3.3)
+!  *    07/2001: P. Le Van
+!  *    11/2009: L. Guez     (ozone day & night climatos, see etat0_netcdf.F90)
+!  *    12/2009: D. Cugnet   (f77->f90, calendars, files from coupled runs)
+!-------------------------------------------------------------------------------
+#ifdef CPP_EARTH
+  USE dimphy
+  USE ioipsl,             ONLY : ioget_year_len
+  USE phys_state_var_mod, ONLY : pctsrf
+  USE netcdf,             ONLY : NF90_OPEN,    NF90_CREATE,  NF90_CLOSE,       &
+                   NF90_DEF_DIM, NF90_DEF_VAR, NF90_PUT_VAR, NF90_PUT_ATT,     &
+                   NF90_NOERR,   NF90_NOWRITE, NF90_DOUBLE,  NF90_GLOBAL,      &
+		   NF90_CLOBBER, NF90_ENDDEF,  NF90_UNLIMITED
+#endif
+  IMPLICIT NONE
+!-------------------------------------------------------------------------------
+! Arguments:
+#include "dimensions.h"
+#include "paramet.h"
+#include "iniprint.h"
+  LOGICAL,                    INTENT(IN) :: interbar ! barycentric interpolation
+  LOGICAL,                    INTENT(IN) :: extrap   ! SST extrapolation flag
+  LOGICAL,                    INTENT(IN) :: oldice   ! old way ice computation
+  REAL, DIMENSION(iip1,jjp1), INTENT(IN) :: masque   ! land mask
+#ifndef CPP_EARTH
+  WRITE(lunout,*)'limit_netcdf: Earth-specific routine, needs Earth physics'
+#else
+!-------------------------------------------------------------------------------
+! Local variables:
+#include "control.h"
+#include "logic.h"
+#include "comvert.h"
+#include "comgeom2.h"
+#include "comconst.h"
+#include "indicesol.h"
+
+!--- For fractionary sub-cell use (old coding used soil index: 0,1,2,3) --------
+  LOGICAL, PARAMETER :: fracterre=.TRUE.
+
+!--- INPUT NETCDF FILES NAMES --------------------------------------------------
+  CHARACTER(LEN=25) :: icefile, sstfile, dumstr
+  CHARACTER(LEN=25), PARAMETER :: famipsst='amipbc_sst_1x1.nc        ',        &
+                                  famipsic='amipbc_sic_1x1.nc        ',        &
+                                  fclimsst='amipbc_sst_1x1_clim.nc   ',        &
+                                  fclimsic='amipbc_sic_1x1_clim.nc   ',        &
+                                  fcpldsst='cpl_atm_sst.nc           ',        &
+                                  fcpldsic='cpl_atm_sic.nc           ',        &
+                                  frugo   ='Rugos.nc                 ',        &
+                                  falbe   ='Albedo.nc                '
+
+!--- OUTPUT VARIABLES FOR NETCDF FILE ------------------------------------------
+  REAL,   DIMENSION(klon)                :: fi_ice, verif
+  REAL,   DIMENSION(:,:),   POINTER      :: phy_rug=>NULL(), phy_ice=>NULL()
+  REAL,   DIMENSION(:,:),   POINTER      :: phy_sst=>NULL(), phy_alb=>NULL()
+  REAL,   DIMENSION(:,:),   ALLOCATABLE  :: phy_bil
+  REAL,   DIMENSION(:,:,:), ALLOCATABLE  :: pctsrf_t
+  INTEGER                                :: nbad
+
+!--- VARIABLES FOR OUTPUT FILE WRITING -----------------------------------------
+  INTEGER :: ierr, nid, ndim, ntim, k
+  INTEGER, DIMENSION(2) :: dims
+  INTEGER :: id_tim,  id_SST,  id_BILS, id_RUG, id_ALB
+  INTEGER :: id_FOCE, id_FSIC, id_FTER, id_FLIC
+  INTEGER :: NF90_FORMAT
+  LOGICAL :: lCPL                    !--- T: IPCC-IPSL cpl model output files
+
+!--- MICS (PHYSICAL KEYS, TIME) ------------------------------------------------
+!  INTEGER, PARAMETER        :: longcles=20
+!  REAL, DIMENSION(longcles) :: clesphy0
+  INTEGER                   :: ndays
+  
+!--- INITIALIZATIONS -----------------------------------------------------------
+#ifdef NC_DOUBLE
+  NF90_FORMAT=NF90_DOUBLE
+#else
+  NF90_FORMAT=NF90_FLOAT
+#endif
+
+!  CALL conf_gcm(99, .TRUE., clesphy0)
+  pi    = 4.*ATAN(1.)
+  rad   = 6371229.
+  daysec= 86400.
+  omeg  = 2.*pi/daysec
+  g     = 9.8
+  kappa = 0.2857143
+  cpp   = 1004.70885
+  dtvr  = daysec/FLOAT(day_step)
+  CALL inigeom
+
+!--- Beware: anneeref (from gcm.def) is used to determine output time sampling
+  ndays=ioget_year_len(anneeref)
+
+!--- RUGOSITY TREATMENT --------------------------------------------------------
+  WRITE(lunout,*) 'Traitement de la rugosite'
+  CALL get_2Dfield(frugo,'RUG',interbar,ndays,phy_rug,mask=masque(1:iim,:))
+
+!--- OCEAN TREATMENT -----------------------------------------------------------
+  PRINT*, 'Traitement de la glace oceanique' ; icefile=''; lCPL=.FALSE.
+
+! Input SIC file selection
+  icefile='fake'
+  IF(NF90_OPEN(famipsic,NF90_NOWRITE,nid)==NF90_NOERR) icefile=TRIM(famipsic)
+  IF(NF90_OPEN(fclimsic,NF90_NOWRITE,nid)==NF90_NOERR) icefile=TRIM(fclimsic)
+  IF(NF90_OPEN(fcpldsic,NF90_NOWRITE,nid)==NF90_NOERR) icefile=TRIM(fcpldsic)
+  SELECT CASE(icefile)
+    CASE(famipsic); dumstr='Amip.'
+    CASE(fclimsic); dumstr='Amip climatologique.'
+    CASE(fcpldsic); dumstr='de sortie du modele couplé IPSL/IPCC.';lCPL=.TRUE.
+    CASE('fake');   CALL abort_gcm('limit_netcdf','Fichier SIC non reconnu.',1)
+  END SELECT
+  ierr=NF90_CLOSE(nid)
+  WRITE(lunout,*)'Pour la glace de mer a ete choisi un fichier '//TRIM(dumstr)
+
+  CALL get_2Dfield(icefile,'SIC',interbar,ndays,phy_ice,flag=oldice)
+
+  ALLOCATE(pctsrf_t(klon,nbsrf,ndays))
+  DO k=1,ndays
+    fi_ice=phy_ice(:,k)
+    WHERE(fi_ice>=1.0  ) fi_ice=1.0
+    WHERE(fi_ice<EPSFRA) fi_ice=0.0
+    IF(fracterre) THEN
+      pctsrf_t(:,is_ter,k)=pctsrf(:,is_ter)       ! land soil
+      pctsrf_t(:,is_lic,k)=pctsrf(:,is_lic)       ! land ice
+      IF(lCPL) THEN                              ! SIC=pICE*(1-LIC-TER)
+        pctsrf_t(:,is_sic,k)=fi_ice*(1-pctsrf(:,is_lic)-pctsrf(:,is_ter))
+      ELSE                                        ! SIC=pICE-LIC
+        pctsrf_t(:,is_sic,k)=fi_ice-pctsrf_t(:,is_lic,k)
+      END IF
+      WHERE(pctsrf_t(:,is_sic,k)<=0) pctsrf_t(:,is_sic,k)=0.
+      WHERE(1.0-zmasq<EPSFRA)
+        pctsrf_t(:,is_sic,k)=0.0
+        pctsrf_t(:,is_oce,k)=0.0
+      ELSEWHERE
+        WHERE(pctsrf_t(:,is_sic,k)>=1.0-zmasq)
+          pctsrf_t(:,is_sic,k)=1.0-zmasq
+          pctsrf_t(:,is_oce,k)=0.0
+        ELSEWHERE
+          pctsrf_t(:,is_oce,k)=1.0-zmasq-pctsrf_t(:,is_sic,k)
+          WHERE(pctsrf_t(:,is_oce,k)<EPSFRA)
+            pctsrf_t(:,is_oce,k)=0.0
+            pctsrf_t(:,is_sic,k)=1.0-zmasq
+          END WHERE
+        END WHERE
+      END WHERE
+      nbad=COUNT(pctsrf_t(:,is_oce,k)<0.0)
+      IF(nbad>0) WRITE(lunout,*) 'pb sous maille pour nb point = ',nbad
+      nbad=COUNT(abs(sum(pctsrf_t(:,:,k),dim=2)-1.0)>EPSFRA)
+      IF(nbad>0) WRITE(lunout,*) 'pb sous surface pour nb points = ',nbad
+    ELSE 
+      pctsrf_t(:,is_ter,k)=pctsrf(:,is_ter)
+      WHERE(NINT(pctsrf(:,is_ter))==1)
+        pctsrf_t(:,is_sic,k)=0.
+        pctsrf_t(:,is_oce,k)=0.                  
+        WHERE(fi_ice>=1.e-5)
+          pctsrf_t(:,is_lic,k)=fi_ice
+          pctsrf_t(:,is_ter,k)=pctsrf_t(:,is_ter,k)-pctsrf_t(:,is_lic,k)
+        ELSEWHERE
+          pctsrf_t(:,is_lic,k)=0.0
+        END WHERE
+      ELSEWHERE
+        pctsrf_t(:,is_lic,k) = 0.0 
+        WHERE(fi_ice>=1.e-5)
+          pctsrf_t(:,is_ter,k)=0.0
+          pctsrf_t(:,is_sic,k)=fi_ice
+          pctsrf_t(:,is_oce,k)=1.0-pctsrf_t(:,is_sic,k)
+        ELSEWHERE
+          pctsrf_t(:,is_sic,k)=0.0
+          pctsrf_t(:,is_oce,k)=1.0
+        END WHERE
+      END WHERE
+      verif=sum(pctsrf_t(:,:,k),dim=2)
+      nbad=COUNT(verif<1.0-1.e-5.OR.verif>1.0+1.e-5)
+      IF(nbad>0) WRITE(lunout,*) 'pb sous maille pour nb point = ',nbad
+    END IF 
+  END DO
+  DEALLOCATE(phy_ice)
+
+!--- SST TREATMENT -------------------------------------------------------------
+  WRITE(lunout,*) 'Traitement de la sst' ; sstfile=''; lCPL=.FALSE.
+
+! Input SST file selection
+  sstfile='fake'
+  IF(NF90_OPEN(famipsst,NF90_NOWRITE,nid)==NF90_NOERR) sstfile=TRIM(famipsst)
+  IF(NF90_OPEN(fclimsst,NF90_NOWRITE,nid)==NF90_NOERR) sstfile=TRIM(fclimsst)
+  IF(NF90_OPEN(fcpldsst,NF90_NOWRITE,nid)==NF90_NOERR) sstfile=TRIM(fcpldsst)
+  SELECT CASE(icefile)
+    CASE(famipsic); dumstr='Amip.'
+    CASE(fclimsic); dumstr='Amip climatologique.'
+    CASE(fcpldsic); dumstr='de sortie du modele couplé IPSL/IPCC.';lCPL=.TRUE.
+    CASE('fake');   CALL abort_gcm('limit_netcdf','Fichier SST non reconnu',1)
+  END SELECT
+  ierr=NF90_CLOSE(nid)
+  WRITE(lunout,*)'Pour la temperature de mer a ete choisi un fichier '//TRIM(dumstr)
+
+  CALL get_2Dfield(trim(sstfile),'SST',interbar,ndays,phy_sst,flag=extrap)
+
+!--- ALBEDO TREATMENT ----------------------------------------------------------
+  WRITE(lunout,*) 'Traitement de l albedo'
+  CALL get_2Dfield(falbe,'ALB',interbar,ndays,phy_alb)
+
+!--- REFERENCE GROUND HEAT FLUX TREATMENT --------------------------------------
+  ALLOCATE(phy_bil(klon,ndays)); phy_bil=0.0
+
+!--- OUTPUT FILE WRITING -------------------------------------------------------
+  WRITE(lunout,*) 'Ecriture du fichier limit'
+
+  !--- File creation
+  ierr=NF90_CREATE("limit.nc",NF90_CLOBBER,nid)
+  ierr=NF90_PUT_ATT(nid,NF90_GLOBAL,"title","Fichier conditions aux limites")
+
+  !--- Dimensions creation
+  ierr=NF90_DEF_DIM(nid,"points_physiques",klon,ndim)
+  ierr=NF90_DEF_DIM(nid,"time",NF90_UNLIMITED,ntim)
+
+  dims=(/ndim,ntim/)
+
+  !--- Variables creation
+  ierr=NF90_DEF_VAR(nid,"TEMPS",NF90_FORMAT,dims,id_tim)
+  ierr=NF90_DEF_VAR(nid,"FOCE", NF90_FORMAT,dims,id_FOCE)
+  ierr=NF90_DEF_VAR(nid,"FSIC", NF90_FORMAT,dims,id_FSIC)
+  ierr=NF90_DEF_VAR(nid,"FTER", NF90_FORMAT,dims,id_FTER)
+  ierr=NF90_DEF_VAR(nid,"FLIC", NF90_FORMAT,dims,id_FLIC)
+  ierr=NF90_DEF_VAR(nid,"SST",  NF90_FORMAT,dims,id_SST)
+  ierr=NF90_DEF_VAR(nid,"BILS", NF90_FORMAT,dims,id_BILS)
+  ierr=NF90_DEF_VAR(nid,"ALB",  NF90_FORMAT,dims,id_ALB)
+  ierr=NF90_DEF_VAR(nid,"RUG",  NF90_FORMAT,dims,id_RUG)
+
+  !--- Attributes creation
+  ierr=NF90_PUT_ATT(nid,id_tim, "title","Jour dans l annee")
+  ierr=NF90_PUT_ATT(nid,id_FOCE,"title","Fraction ocean")
+  ierr=NF90_PUT_ATT(nid,id_FSIC,"title","Fraction glace de mer")
+  ierr=NF90_PUT_ATT(nid,id_FTER,"title","Fraction terre")
+  ierr=NF90_PUT_ATT(nid,id_FLIC,"title","Fraction land ice")
+  ierr=NF90_PUT_ATT(nid,id_SST ,"title","Temperature superficielle de la mer")
+  ierr=NF90_PUT_ATT(nid,id_BILS,"title","Reference flux de chaleur au sol")
+  ierr=NF90_PUT_ATT(nid,id_ALB, "title","Albedo a la surface")
+  ierr=NF90_PUT_ATT(nid,id_RUG, "title","Rugosite")
+
+  ierr=NF90_ENDDEF(nid)
+
+  !--- Variables saving
+  ierr=NF90_PUT_VAR(nid,id_tim,(/(DBLE(k),k=1,ndays)/))
+  ierr=NF90_PUT_VAR(nid,id_FOCE,pctsrf_t(:,is_oce,:),(/1,1/),(/klon,ndays/))
+  ierr=NF90_PUT_VAR(nid,id_FSIC,pctsrf_t(:,is_sic,:),(/1,1/),(/klon,ndays/))
+  ierr=NF90_PUT_VAR(nid,id_FTER,pctsrf_t(:,is_ter,:),(/1,1/),(/klon,ndays/))
+  ierr=NF90_PUT_VAR(nid,id_FLIC,pctsrf_t(:,is_lic,:),(/1,1/),(/klon,ndays/))
+  ierr=NF90_PUT_VAR(nid,id_SST ,phy_sst(:,:),(/1,1/),(/klon,ndays/))
+  ierr=NF90_PUT_VAR(nid,id_BILS,phy_bil(:,:),(/1,1/),(/klon,ndays/))
+  ierr=NF90_PUT_VAR(nid,id_ALB ,phy_alb(:,:),(/1,1/),(/klon,ndays/))
+  ierr=NF90_PUT_VAR(nid,id_RUG ,phy_rug(:,:),(/1,1/),(/klon,ndays/))
+
+  ierr=NF90_CLOSE(nid)
+
+  DEALLOCATE(pctsrf_t,phy_sst,phy_bil,phy_alb,phy_rug)
+#endif
+! of #ifdef CPP_EARTH
+  STOP
+
+
+!===============================================================================
+!
+  CONTAINS
+!
+!===============================================================================
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE get_2Dfield(fnam, mode, ibar, ndays, champo, flag, mask)
+!
+!-------------------------------------------------------------------------------
+! Comments:
+!   There are two assumptions concerning the NetCDF files, that are satisfied
+!   with files that are conforming NC convention:
+!     1) The last dimension of the variables used is the time record.
+!     2) Dimensional variables have the same names as corresponding dimensions.
+!-------------------------------------------------------------------------------
+  USE netcdf, ONLY : NF90_OPEN,    NF90_INQ_VARID, NF90_INQUIRE_VARIABLE,      &
+                     NF90_CLOSE,   NF90_INQ_DIMID, NF90_INQUIRE_DIMENSION,     &
+                     NF90_GET_VAR, NF90_GET_ATT
+  USE dimphy, ONLY : klon
+  USE phys_state_var_mod, ONLY : pctsrf
+  IMPLICIT NONE
+#include "dimensions.h"
+#include "paramet.h"
+#include "comgeom2.h"
+#include "control.h"
+#include "indicesol.h"
+#include "iniprint.h"
+!-------------------------------------------------------------------------------
+! Arguments:
+  CHARACTER(LEN=*),  INTENT(IN)     :: fnam     ! NetCDF file name
+  CHARACTER(LEN=3),  INTENT(IN)     :: mode     ! RUG, SIC, SST or ALB
+  LOGICAL,           INTENT(IN)     :: ibar     ! interp on pressure levels
+  INTEGER,           INTENT(IN)     :: ndays    ! current year number of days
+  REAL,    POINTER,  DIMENSION(:,:) :: champo   ! output field = f(t)
+  LOGICAL, OPTIONAL,                      INTENT(IN) :: flag
+! flag=T means:   extrapolation (SST case)  or  old ice (SIC case)
+  REAL,    OPTIONAL, DIMENSION(iim,jjp1), INTENT(IN) :: mask
+!-------------------------------------------------------------------------------
+! Local variables:
+!--- NetCDF
+  INTEGER :: ierr, ncid, varid                  ! NetCDF identifiers
+  CHARACTER(LEN=30)               :: dnam       ! dimension name
+  CHARACTER(LEN=80)               :: varname    ! NetCDF variable name
+!--- dimensions
+  INTEGER,           DIMENSION(4) :: dids       ! NetCDF dimensions identifiers
+  REAL, ALLOCATABLE, DIMENSION(:) :: dlon_ini   ! initial longitudes vector
+  REAL, ALLOCATABLE, DIMENSION(:) :: dlat_ini   ! initial latitudes  vector
+  REAL, POINTER,     DIMENSION(:) :: dlon, dlat ! reordered lon/lat  vectors
+!--- fields
+  INTEGER :: imdep, jmdep, lmdep                ! dimensions of 'champ'
+  REAL, ALLOCATABLE, DIMENSION(:) :: champ      ! wanted field on initial grid
+  REAL, ALLOCATABLE, DIMENSION(:) :: yder, timeyear
+  REAL,              DIMENSION(iim,jjp1) :: champint   ! interpolated field
+  REAL, ALLOCATABLE, DIMENSION(:,:,:)    :: champtime
+  REAL, ALLOCATABLE, DIMENSION(:,:,:)    :: champan
+  REAL                              :: time, by
+!--- input files
+  CHARACTER(LEN=20)                 :: cal_in   ! calendar
+  INTEGER                           :: ndays_in ! number of days
+!--- misc
+  INTEGER :: i, j, k, l                         ! loop counters
+  REAL, ALLOCATABLE, DIMENSION(:,:) :: work     ! used for extrapolation
+  CHARACTER(LEN=25)                 :: title    ! for messages
+  LOGICAL                           :: extrp    ! flag for extrapolation
+  REAL                              :: chmin, chmax
+!-------------------------------------------------------------------------------
+!---Variables depending on keyword 'mode' --------------------------------------
+  NULLIFY(champo)
+  SELECT CASE(mode)
+    CASE('RUG'); varname='RUGOS';  title='Rugosite'
+    CASE('SIC'); varname='sicbcs'; title='Sea-ice'
+    CASE('SST'); varname='tosbcs'; title='SST'
+    CASE('ALB'); varname='ALBEDO'; title='Albedo'
+  END SELECT
+  extrp=(flag.AND.mode=='SST')
+
+!--- GETTING SOME DIMENSIONAL VARIABLES FROM FILE ------------------------------
+  ierr=NF90_OPEN(fnam,NF90_NOWRITE,ncid);                  CALL ncerr(ierr,fnam)
+  ierr=NF90_INQ_VARID(ncid,varname,varid);                 CALL ncerr(ierr,fnam)
+  ierr=NF90_INQUIRE_VARIABLE(ncid,varid,dimids=dids);      CALL ncerr(ierr,fnam)
+
+!--- Longitude
+  ierr=NF90_INQUIRE_DIMENSION(ncid,dids(1),name=dnam,len=imdep)
+  CALL ncerr(ierr,fnam); ALLOCATE(dlon_ini(imdep),dlon(imdep))
+  ierr=NF90_INQ_VARID(ncid,dnam,varid);                    CALL ncerr(ierr,fnam)
+  ierr=NF90_GET_VAR(ncid,varid,dlon_ini);                  CALL ncerr(ierr,fnam)
+  WRITE(lunout,*) 'variable ', dnam, 'dimension ', imdep
+
+!--- Latitude
+  ierr=NF90_INQUIRE_DIMENSION(ncid,dids(2),name=dnam,len=jmdep)
+  CALL ncerr(ierr,fnam); ALLOCATE(dlat_ini(jmdep),dlat(jmdep))
+  ierr=NF90_INQ_VARID(ncid,dnam,varid);                    CALL ncerr(ierr,fnam)
+  ierr=NF90_GET_VAR(ncid,varid,dlat_ini);                  CALL ncerr(ierr,fnam)
+  WRITE(lunout,*) 'variable ', dnam, 'dimension ', jmdep
+
+!--- Time (variable is not needed - it is rebuilt - but calendar is)
+  ierr=NF90_INQUIRE_DIMENSION(ncid,dids(3),name=dnam,len=lmdep)
+  CALL ncerr(ierr,fnam); ALLOCATE(timeyear(lmdep))
+  ierr=NF90_INQ_VARID(ncid,dnam,varid);                    CALL ncerr(ierr,fnam)
+  cal_in=' '
+  ierr=NF90_GET_ATT(ncid,varid,'calendar',cal_in)
+  IF(ierr/=NF90_NOERR) THEN
+    SELECT CASE(mode)
+      CASE('RUG','ALB'); cal_in='360d'
+      CASE('SIC','SST'); cal_in='gregorian'
+    END SELECT
+    WRITE(lunout,*)'ATTENTION: variable ''time'' sans attribut ''calendrier'' d&
+     &ans '//TRIM(fnam)//'. On choisit la valeur par defaut.'
+  END IF
+  WRITE(lunout,*) 'variable ', dnam, 'dimension ', lmdep, 'calendrier ', cal_in
+
+!--- CONSTRUCTING THE INPUT TIME VECTOR FOR INTERPOLATION ----------------------
+  !--- Determining input file number of days, depending on calendar
+  ndays_in=year_len(anneeref,cal_in)
+
+!--- Time vector reconstruction (time vector from file is not trusted)
+!--- If input records are not monthly, time sampling has to be constant !
+  timeyear=mid_months(anneeref,cal_in,lmdep)
+  IF(lmdep/=12) WRITE(lunout,'(a,i3,a)')'Note: les fichiers de '//TRIM(mode)   &
+    //' ne comportent pas 12, mais ',lmdep,' renregistrements.'
+
+!--- GETTING THE FIELD AND INTERPOLATING IT ------------------------------------
+  ALLOCATE(champ(imdep*jmdep),champtime(iim,jjp1,lmdep))
+  IF(extrp) ALLOCATE(work(imdep,jmdep))
+
+  WRITE(lunout,*)
+  WRITE(lunout,'(a,i3,a)')'LECTURE ET INTERPOLATION HORIZ. DE ',lmdep,' CHAMPS.'
+  ierr=NF90_INQ_VARID(ncid,varname,varid);                 CALL ncerr(ierr,fnam)
+  DO l=1,lmdep
+    ierr=NF90_GET_VAR(ncid,varid,champ,(/1,1,l/),(/imdep,jmdep,1/))
+    CALL ncerr(ierr,fnam)
+    CALL conf_dat2d(title,imdep,jmdep,dlon_ini,dlat_ini,dlon,dlat,champ,ibar)
+
+    IF(extrp) CALL extrapol(champ,imdep,jmdep,999999.,.TRUE.,.TRUE.,2,work)
+
+    IF(ibar.AND..NOT.(mode=='SIC'.AND.flag)) THEN
+      IF(l==1) THEN
+        WRITE(lunout,*)                                                        &
+  '-------------------------------------------------------------------------'
+        WRITE(lunout,*)                                                        &
+  '$$$ Utilisation de l''interpolation barycentrique pour '//TRIM(title)//' $$$'
+        WRITE(lunout,*)                                                        &
+  '-------------------------------------------------------------------------'
+      END IF
+      IF(mode=='RUG') champ=LOG(champ)
+      CALL inter_barxy(imdep, jmdep-1, dlon, dlat, champ, iim, jjm, rlonu,     &
+                         rlatv, jjp1, champint)
+      IF(mode=='RUG') THEN
+        champint=EXP(champint)
+        WHERE(NINT(mask)/=1) champint=0.001
+      END IF
+    ELSE
+      SELECT CASE(mode)
+        CASE('RUG');       CALL rugosite(imdep, jmdep, dlon, dlat, champ,      &
+                                    iim, jjp1, rlonv, rlatu, champint, mask)
+        CASE('SIC');       CALL sea_ice (imdep, jmdep, dlon, dlat, champ,      &
+                                    iim, jjp1, rlonv, rlatu, champint)
+        CASE('SST','ALB'); CALL grille_m(imdep, jmdep, dlon, dlat, champ,      &
+                                    iim, jjp1, rlonv, rlatu, champint)
+      END SELECT
+    END IF
+    champtime(:,:,l)=champint
+  END DO
+  ierr=NF90_CLOSE(ncid);                                   CALL ncerr(ierr,fnam)
+
+  DEALLOCATE(dlon_ini,dlat_ini,dlon,dlat,champ)
+  IF(extrp) DEALLOCATE(work)
+
+!--- TIME INTERPOLATION --------------------------------------------------------
+  WRITE(lunout,*)
+  WRITE(lunout,*)'INTERPOLATION TEMPORELLE.'
+  WRITE(lunout,"(2x,' Vecteur temps en entree: ',10f6.1)") timeyear
+  WRITE(lunout,"(2x,' Vecteur temps en sortie de 0 a ',i3)") ndays
+  ALLOCATE(yder(lmdep),champan(iip1,jjp1,ndays))
+  DO j=1,jjp1
+    DO i=1,iim
+      CALL spline(timeyear,champtime(i,j,:),lmdep,1.e30,1.e30,yder)
+      DO k=1,ndays
+        time=FLOAT((k-1)*ndays_in)/FLOAT(ndays)
+        CALL splint(timeyear,champtime(i,j,:),yder,lmdep,time,by)
+        champan(i,j,k) = by
+      END DO
+    END DO
+  END DO
+  champan(iip1,:,:)=champan(1,:,:)
+  DEALLOCATE(yder,champtime,timeyear)
+
+!--- Checking the result
+  DO j=1,jjp1
+    CALL minmax(iip1,champan(1,j,10),chmin,chmax)
+    WRITE(lunout,*)' '//TRIM(title)//' au temps 10 ',chmin,chmax,j
+  END DO
+
+!--- SPECIAL FILTER FOR SST: SST>271.38 ----------------------------------------
+  IF(mode=='SST') THEN
+    WRITE(lunout,*) 'Filtrage de la SST: SST >= 271.38'
+    WHERE(champan<271.38) champan=271.38
+  END IF
+
+!--- SPECIAL FILTER FOR SIC: 0.0<SIC<1.0 ---------------------------------------
+  IF(mode=='SIC') THEN
+    WRITE(lunout,*) 'Filtrage de la SIC: 0.0 < Sea-ice < 1.0'
+    champan(:,:,:)=champan(:,:,:)/100.
+    champan(iip1,:,:)=champan(1,:,:)
+    WHERE(champan>1.0) champan=1.0
+    WHERE(champan<0.0) champan=0.0
+  END IF
+
+write(*,*)'coin1'
+!--- DYNAMICAL TO PHYSICAL GRID ------------------------------------------------
+  ALLOCATE(champo(klon,ndays))
+  DO k=1,ndays
+    CALL gr_dyn_fi(1,iip1,jjp1,klon,champan(1,1,k),champo(1,k))
+  END DO
+write(*,*)'coin2'
+  DEALLOCATE(champan)
+write(*,*)'coin3'
+END SUBROUTINE get_2Dfield
+!
+!-------------------------------------------------------------------------------
+
+
+
+!-------------------------------------------------------------------------------
+!
+FUNCTION year_len(y,cal_in)
+!
+!-------------------------------------------------------------------------------
+  USE ioipsl, ONLY : ioget_calendar,ioconf_calendar,lock_calendar,ioget_year_len
+  IMPLICIT NONE
+!-------------------------------------------------------------------------------
+! Arguments:
+  INTEGER                       :: year_len
+  INTEGER,           INTENT(IN) :: y
+  CHARACTER(LEN=*),  INTENT(IN) :: cal_in
+!-------------------------------------------------------------------------------
+! Local variables:
+  CHARACTER(LEN=20)             :: cal_out              ! calendar (for outputs)
+!-------------------------------------------------------------------------------
+!--- Getting the input calendar to reset at the end of the function
+  CALL ioget_calendar(cal_out)
+
+!--- Unlocking calendar and setting it to wanted one
+  CALL lock_calendar(.FALSE.); CALL ioconf_calendar(TRIM(cal_in))
+
+!--- Getting the number of days in this year
+  year_len=ioget_year_len(y)
+
+!--- Back to original calendar
+  CALL lock_calendar(.FALSE.); CALL ioconf_calendar(TRIM(cal_out))
+
+END FUNCTION year_len
+!
+!-------------------------------------------------------------------------------
+
+
+!-------------------------------------------------------------------------------
+!
+FUNCTION mid_months(y,cal_in,nm)
+!
+!-------------------------------------------------------------------------------
+  USE ioipsl, ONLY : ioget_calendar,ioconf_calendar,lock_calendar,ioget_mon_len
+  IMPLICIT NONE
+!-------------------------------------------------------------------------------
+! Arguments:
+  INTEGER,                INTENT(IN) :: y               ! year
+  CHARACTER(LEN=*),       INTENT(IN) :: cal_in          ! calendar
+  INTEGER,                INTENT(IN) :: nm              ! months/year number
+  REAL,    DIMENSION(nm)             :: mid_months      ! mid-month times
+!-------------------------------------------------------------------------------
+! Local variables:
+  CHARACTER(LEN=99)                  :: mess            ! error message
+  CHARACTER(LEN=20)                  :: cal_out         ! calendar (for outputs)
+  INTEGER, DIMENSION(nm)             :: mnth            ! months lengths (days)
+  INTEGER                            :: m               ! months counter
+  INTEGER                            :: nd              ! number of days
+!-------------------------------------------------------------------------------
+  nd=year_len(y,cal_in)
+
+  IF(nm==12) THEN
+
+  !--- Getting the input calendar to reset at the end of the function
+    CALL ioget_calendar(cal_out)
+
+  !--- Unlocking calendar and setting it to wanted one
+    CALL lock_calendar(.FALSE.); CALL ioconf_calendar(TRIM(cal_in))
+
+  !--- Getting the length of each month
+    DO m=1,nm; mnth(m)=ioget_mon_len(y,m); END DO
+
+  !--- Back to original calendar
+    CALL lock_calendar(.FALSE.); CALL ioconf_calendar(TRIM(cal_out))
+
+  ELSE IF(MODULO(nd,nm)/=0) THEN
+    WRITE(mess,'(a,i3,a,i3,a)')'Unconsistent calendar: ',nd,' days/year, but ',&
+      nm,' months/year. Months number should divide days number.'
+    CALL abort_gcm('mid_months',TRIM(mess),1)
+
+  ELSE
+    mnth=(/(m,m=1,nm,nd/nm)/)
+  END IF
+
+!--- Mid-months times
+  mid_months(1)=0.5*FLOAT(mnth(1))
+  DO k=2,nm
+    mid_months(k)=mid_months(k-1)+0.5*FLOAT(mnth(k-1)+mnth(k))
+  END DO
+
+END FUNCTION mid_months
+!
+!-------------------------------------------------------------------------------
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE ncerr(ncres,fnam)
+!
+!-------------------------------------------------------------------------------
+! Purpose: NetCDF errors handling.
+!-------------------------------------------------------------------------------
+  USE netcdf, ONLY : NF90_NOERR, NF90_STRERROR
+  IMPLICIT NONE
+!-------------------------------------------------------------------------------
+! Arguments:
+  INTEGER,          INTENT(IN) :: ncres
+  CHARACTER(LEN=*), INTENT(IN) :: fnam
+!-------------------------------------------------------------------------------
+#include "iniprint.h"
+  IF(ncres/=NF90_NOERR) THEN
+    WRITE(lunout,*)'Problem with file '//TRIM(fnam)//' in routine limit_netcdf.'
+    CALL abort_gcm('limit_netcdf',NF90_STRERROR(ncres),1)
+  END IF
+
+END SUBROUTINE ncerr
+!
+!-------------------------------------------------------------------------------
+
+
+END SUBROUTINE limit_netcdf
Index: LMDZ4/trunk/libf/dyn3dpar/logic.h
===================================================================
--- LMDZ4/trunk/libf/dyn3dpar/logic.h	(revision 1318)
+++ LMDZ4/trunk/libf/dyn3dpar/logic.h	(revision 1319)
@@ -1,4 +1,4 @@
 !
-! $Header$
+! $Id$
 !
 !
@@ -9,9 +9,11 @@
       COMMON/logic/ purmats,iflag_phys,forward,leapf,apphys,            &
      &  statcl,conser,apdiss,apdelq,saison,ecripar,fxyhypb,ysinus       &
-     &  ,read_start,ok_guide,ok_strato,ok_gradsfile
+     &  ,read_start,ok_guide,ok_strato,ok_gradsfile                     &
+     &  ,ok_limit,ok_etat0
 
       LOGICAL purmats,forward,leapf,apphys,statcl,conser,               &
      & apdiss,apdelq,saison,ecripar,fxyhypb,ysinus                      &
-     &  ,read_start,ok_guide,ok_strato,ok_gradsfile
+     &  ,read_start,ok_guide,ok_strato,ok_gradsfile                     &
+     &  ,ok_limit,ok_etat0
 
       INTEGER iflag_phys
Index: LMDZ4/trunk/libf/dyn3dpar/startvar.F
===================================================================
--- LMDZ4/trunk/libf/dyn3dpar/startvar.F	(revision 1318)
+++ 	(revision )
@@ -1,1193 +1,0 @@
-!
-! $Id$
-!
-      MODULE startvar
-#ifdef CPP_EARTH
-! This module is designed to work for Earth (and with ioipsl)
-    !
-    !
-    !      There are three ways to access data from the database of atmospheric data which 
-    !       can be used to initialize the model. This depends on the type of field which needs 
-    !       to be extracted. In any case the call should come after a restget and should be of the type :
-    !                CALL startget(...)
-    !
-    !       We will details the possible arguments to startget here :
-    !
-    !        - A 2D variable on the dynamical grid :
-    !           CALL startget(varname, iml, jml, lon_in, lat_in, champ, val_ex, jml2, lon_in2, lat_in2, interbar )             
-    !
-    !        - A 1D variable on the physical grid :
-    !            CALL startget(varname, iml, jml, lon_in, lat_in, nbindex, champ, val_exp, jml2, lon_in2, lat_in2, interbar )
-    !
-    !
-    !         - A 3D variable on the dynamical grid :
-    !            CALL startget(varname, iml, jml, lon_in, lat_in, lml, pls, workvar, champ, val_exp, jml2, lon_in2, lat_in2, interbar )
-    !
-    !
-    !         There is special constraint on the atmospheric data base except that the 
-    !         the data needs to be in netCDF and the variables should have the the following 
-    !        names in the file :
-    !
-    !      'RELIEF'  : High resolution orography 
-    !       'ST'            : Surface temperature
-    !       'CDSW'     : Soil moisture
-    !       'Z'               : Surface geopotential
-    !       'SP'            : Surface pressure
-    !        'U'              : East ward wind
-    !        'V'              : Northward wind
-    !        'TEMP'             : Temperature
-    !        'R'             : Relative humidity
-    !      
-      USE ioipsl
-    !
-    !
-      IMPLICIT NONE
-    !
-    !
-      PRIVATE
-      PUBLIC startget
-    !
-    !
-      INTERFACE startget
-        MODULE PROCEDURE startget_phys2d, startget_phys1d, startget_dyn
-      END INTERFACE
-    !
-      INTEGER, SAVE :: fid_phys, fid_dyn
-      INTEGER, SAVE  :: iml_phys, iml_rel, iml_dyn
-      INTEGER, SAVE :: jml_phys,  jml_rel, jml_dyn
-      INTEGER, SAVE ::  llm_dyn, ttm_dyn
-      REAL, ALLOCATABLE, SAVE, DIMENSION (:,:)  :: lon_phys, lon_rug,
-     . lon_alb, lon_rel, lon_dyn
-      REAL, ALLOCATABLE, SAVE, DIMENSION (:,:)  :: lat_phys, lat_rug,
-     . lat_alb, lat_rel, lat_dyn
-      REAL, ALLOCATABLE, SAVE, DIMENSION (:)  :: levdyn_ini
-      REAL, ALLOCATABLE, SAVE, DIMENSION (:,:)  :: relief, zstd, zsig,
-     . zgam, zthe, zpic, zval
-      REAL, ALLOCATABLE, SAVE, DIMENSION (:,:)  :: rugo, masque, phis
-    !
-      REAL, ALLOCATABLE, SAVE, DIMENSION (:,:)  :: tsol, qsol, psol_dyn
-      REAL, ALLOCATABLE, SAVE, DIMENSION (:,:,:)  ::   var_ana3d
-    !
-      CONTAINS
-    !
-    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-    !
-      SUBROUTINE startget_phys2d(varname, iml, jml, lon_in, lat_in,
-     . champ, val_exp, jml2, lon_in2, lat_in2 , interbar, masque_lu )
-    !
-    !    There is a big mess with the size in logitude, should it be iml or iml+1.
-    !    I have chosen to use the iml+1 as an argument to this routine and we declare
-    !   internaly smaler fields when needed. This needs to be cleared once and for all in LMDZ. 
-    !  A convention is required.
-    !
-    !
-      CHARACTER*(*), INTENT(in) :: varname
-      INTEGER, INTENT(in) :: iml, jml ,jml2
-      REAL, INTENT(in) :: lon_in(iml), lat_in(jml)
-      REAL, INTENT(in) :: lon_in2(iml), lat_in2(jml2)
-      REAL, INTENT(inout) :: champ(iml,jml)
-      REAL, INTENT(in) :: val_exp
-      REAL, INTENT(in), optional :: masque_lu(iml,jml) 
-      LOGICAL interbar
-    !
-    !   This routine only works if the variable does not exist or is constant
-    !
-      IF ( MINVAL(champ(:,:)).EQ.MAXVAL(champ(:,:)) .AND. 
-     .MINVAL(champ(:,:)).EQ.val_exp ) THEN
-          !
-          SELECTCASE(varname)
-              !
-              CASE ('relief')
-                  !
-                  !  If we do not have the orography we need to get it
-                  !
-                  IF ( .NOT.ALLOCATED(relief)) THEN
-                      !
-                    if (present(masque_lu)) then
-                      CALL start_init_orog( iml, jml, lon_in, lat_in,
-     .                    jml2,lon_in2,lat_in2, interbar, masque_lu )
-                    else
-                      CALL start_init_orog( iml, jml, lon_in, lat_in,
-     .                    jml2,lon_in2,lat_in2, interbar)
-                    endif
-                      !
-                  ENDIF
-                  !
-                  IF (SIZE(relief) .NE. SIZE(champ)) THEN
-                      !
-                      WRITE(*,*) 'STARTVAR module has been',
-     .' initialized to the wrong size'
-                      STOP
-                      !
-                  ENDIF
-                  !
-                  champ(:,:) = relief(:,:)
-                  !
-              CASE ('rugosite')
-                  !
-                  !  If we do not have the orography we need to get it
-                  !
-                  IF ( .NOT.ALLOCATED(rugo)) THEN
-                      !
-                      CALL start_init_orog( iml, jml, lon_in, lat_in,
-     .                    jml2,lon_in2,lat_in2 , interbar )
-                      !
-                  ENDIF
-                  !
-                  IF (SIZE(rugo) .NE. SIZE(champ)) THEN
-                      !
-                      WRITE(*,*) 
-     .  'STARTVAR module has been initialized to the wrong size'
-                      STOP
-                      !
-                  ENDIF
-                  !
-                  champ(:,:) = rugo(:,:)
-                  !
-              CASE ('masque')
-                  !
-                  !  If we do not have the orography we need to get it
-                  !
-                  IF ( .NOT.ALLOCATED(masque)) THEN
-                      !
-                      CALL start_init_orog( iml, jml, lon_in, lat_in,
-     .                     jml2,lon_in2,lat_in2 , interbar )
-                      !
-                  ENDIF
-                  !
-                  IF (SIZE(masque) .NE. SIZE(champ)) THEN
-                      !
-                      WRITE(*,*) 
-     .   'STARTVAR module has been initialized to the wrong size'
-                      STOP
-                      !
-                  ENDIF
-                  !
-                  champ(:,:) = masque(:,:)
-                  !
-              CASE ('surfgeo')
-                  !
-                  !  If we do not have the orography we need to get it
-                  !
-                  IF ( .NOT.ALLOCATED(phis)) THEN
-                      !
-                      CALL start_init_orog( iml, jml, lon_in, lat_in,
-     .                   jml2,lon_in2, lat_in2 , interbar )
-                      !
-                  ENDIF
-                  !
-                  IF (SIZE(phis) .NE. SIZE(champ)) THEN
-                      !
-                      WRITE(*,*)
-     . 'STARTVAR module has been initialized to the wrong size'
-                      STOP
-                      !
-                  ENDIF
-                  !
-                  champ(:,:) = phis(:,:)
-                  !
-              CASE ('psol')
-                  !
-                  !  If we do not have the orography we need to get it
-                  !
-                  IF ( .NOT.ALLOCATED(psol_dyn)) THEN
-                      !
-                      CALL start_init_dyn( iml, jml, lon_in, lat_in,
-     .                   jml2,lon_in2, lat_in2 , interbar )
-                      !
-                  ENDIF
-                  !
-                  IF (SIZE(psol_dyn) .NE. SIZE(champ)) THEN
-                      !
-                      WRITE(*,*)
-     . 'STARTVAR module has been initialized to the wrong size'
-                      STOP
-                      !
-                  ENDIF
-                  !
-                  champ(:,:) = psol_dyn(:,:)
-                  !
-              CASE DEFAULT
-                  !
-                  WRITE(*,*) 'startget_phys2d'
-                  WRITE(*,*) 'No rule is present to extract variable', 
-     .                 varname(:LEN_TRIM(varname)),' from any data set'
-                  STOP
-                  !
-          END SELECT
-          !
-      ELSE
-          !
-          ! There are a few fields we might need if we need to interpolate 3D filed. Thus if they come through here we
-          ! will catch them
-          !
-          SELECTCASE(varname)
-              !
-              CASE ('surfgeo')
-                  !
-                  IF ( .NOT.ALLOCATED(phis)) THEN
-                      ALLOCATE(phis(iml,jml))
-                  ENDIF
-                  !
-                  IF (SIZE(phis) .NE. SIZE(champ)) THEN
-                      !
-                      WRITE(*,*)
-     .  'STARTVAR module has been initialized to the wrong size'
-                      STOP
-                      !
-                  ENDIF
-                  !
-                  phis(:,:) = champ(:,:)
-                  !
-          END SELECT
-          !
-      ENDIF
-    !
-      END SUBROUTINE startget_phys2d
-    !
-    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-    !
-      SUBROUTINE start_init_orog ( iml,jml,lon_in, lat_in,jml2,lon_in2 ,
-     ,   lat_in2 , interbar, masque_lu )
-    !
-      INTEGER, INTENT(in) :: iml, jml, jml2
-      REAL, INTENT(in) :: lon_in(iml), lat_in(jml)
-      REAL, INTENT(in) :: lon_in2(iml), lat_in2(jml2)
-      REAL, intent(in), optional :: masque_lu(iml,jml)
-      LOGICAL interbar
-    !
-    !  LOCAL
-    !
-      LOGICAL interbar2
-      REAL :: lev(1), date, dt,chmin,chmax
-      INTEGER :: itau(1), fid
-      INTEGER ::  llm_tmp, ttm_tmp
-      INTEGER :: i, j
-      INTEGER :: iret
-      CHARACTER*25 title
-      REAL, ALLOCATABLE :: relief_hi(:,:)
-      REAL, ALLOCATABLE :: lon_rad(:), lat_rad(:)
-      REAL, ALLOCATABLE :: lon_ini(:), lat_ini(:)
-      REAL, ALLOCATABLE :: tmp_var(:,:)
-      INTEGER, ALLOCATABLE :: tmp_int(:,:)
-    !
-      CHARACTER*120 :: orogfname
-      LOGICAL :: check=.TRUE.
-    !
-    !
-      orogfname = 'Relief.nc'
-    !
-      IF ( check ) WRITE(*,*) 'Reading the high resolution orography'
-    !
-      CALL flininfo(orogfname,iml_rel, jml_rel, llm_tmp, ttm_tmp, fid)
-    !
-      ALLOCATE (lat_rel(iml_rel,jml_rel), stat=iret)
-      ALLOCATE (lon_rel(iml_rel,jml_rel), stat=iret)
-      ALLOCATE (relief_hi(iml_rel,jml_rel), stat=iret)
-    !
-      CALL flinopen(orogfname, .FALSE., iml_rel, jml_rel, 
-     .llm_tmp, lon_rel, lat_rel, lev, ttm_tmp,
-     .      itau, date, dt, fid)
-    !
-      CALL flinget(fid, 'RELIEF', iml_rel, jml_rel, llm_tmp, 
-     . ttm_tmp, 1, 1, relief_hi)
-    !
-      CALL flinclo(fid)
-    !
-    !   In case we have a file which is in degrees we do the transformation
-    !
-      ALLOCATE(lon_rad(iml_rel))
-      ALLOCATE(lon_ini(iml_rel))
-
-      IF ( MAXVAL(lon_rel(:,:)) .GT. 2.0 * ASIN(1.0) ) THEN
-          lon_ini(:) = lon_rel(:,1) * 2.0 * ASIN(1.0) / 180.0
-      ELSE
-          lon_ini(:) = lon_rel(:,1) 
-      ENDIF
-
-      ALLOCATE(lat_rad(jml_rel))
-      ALLOCATE(lat_ini(jml_rel))
-
-      IF ( MAXVAL(lat_rel(:,:)) .GT. 2.0 * ASIN(1.0) ) THEN
-          lat_ini(:) = lat_rel(1,:) * 2.0 * ASIN(1.0) / 180.0
-      ELSE
-          lat_ini(:) = lat_rel(1,:) 
-      ENDIF
-    !
-    !
-
-      title='RELIEF'
-
-      interbar2 = .FALSE.
-      CALL conf_dat2d(title,iml_rel, jml_rel, lon_ini, lat_ini,
-     . lon_rad, lat_rad, relief_hi , interbar2  )
-
-      IF ( check ) WRITE(*,*) 'Computes all the parameters needed',
-     .' for the gravity wave drag code'
-    !
-    !    Allocate the data we need to put in the interpolated fields
-    !
-    !            RELIEF:  orographie moyenne
-      ALLOCATE(relief(iml,jml))
-    !            zphi :  orographie moyenne
-      ALLOCATE(phis(iml,jml))
-    !             zstd:  deviation standard de l'orographie sous-maille
-      ALLOCATE(zstd(iml,jml))
-    !             zsig:  pente de l'orographie sous-maille 
-      ALLOCATE(zsig(iml,jml))
-    !             zgam:  anisotropy de l'orographie sous maille
-      ALLOCATE(zgam(iml,jml))
-    !             zthe:  orientation de l'axe oriente dans la direction
-    !                    de plus grande pente de l'orographie sous maille
-      ALLOCATE(zthe(iml,jml))
-    !             zpic:  hauteur pics de la SSO
-      ALLOCATE(zpic(iml,jml))
-    !             zval:  hauteur vallees de la SSO
-      ALLOCATE(zval(iml,jml))
-    !             masque : Masque terre ocean
-      ALLOCATE(tmp_int(iml,jml))
-      ALLOCATE(masque(iml,jml))
-
-      masque = -99999.
-      if (present(masque_lu)) then
-        masque = masque_lu
-      endif
-    !
-      CALL grid_noro(iml_rel, jml_rel, lon_rad, lat_rad, relief_hi,
-     . iml-1, jml, lon_in, lat_in, 
-     . phis, relief, zstd, zsig, zgam, zthe, zpic, zval, masque)
-      phis = phis * 9.81
-    !
-!      masque(:,:) = FLOAT(tmp_int(:,:))
-    !
-    !  Compute surface roughness
-    !
-      IF ( check ) WRITE(*,*) 
-     .'Compute surface roughness induced by the orography'
-    !
-      ALLOCATE(rugo(iml,jml))
-      ALLOCATE(tmp_var(iml-1,jml))
-    !
-      CALL rugsoro(iml_rel, jml_rel, lon_rad, lat_rad, relief_hi,
-     . iml-1, jml, lon_in, lat_in, tmp_var)
-    !
-      DO j = 1, jml
-        DO i = 1, iml-1
-          rugo(i,j) = tmp_var(i,j)
-        ENDDO
-        rugo(iml,j) = tmp_var(1,j)
-      ENDDO
-c
-cc   ***   rugo  n'est pas utilise pour l'instant  ******
-    !
-    !   Build land-sea mask
-    !
-    !
-      RETURN
-    !
-      END SUBROUTINE start_init_orog
-    !
-    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-    !
-      SUBROUTINE startget_phys1d(varname, iml, jml, lon_in, 
-     .lat_in, nbindex, champ, val_exp ,jml2, lon_in2, lat_in2,interbar)
-    !
-      CHARACTER*(*), INTENT(in) :: varname
-      INTEGER, INTENT(in) :: iml, jml, nbindex, jml2
-      REAL, INTENT(in) :: lon_in(iml), lat_in(jml)
-      REAL, INTENT(in) :: lon_in2(iml), lat_in2(jml2)
-      REAL, INTENT(inout) :: champ(nbindex)
-      REAL, INTENT(in) :: val_exp
-      LOGICAL interbar
-    !
-    !
-    !   This routine only works if the variable does not exist or is constant
-    !
-      IF ( MINVAL(champ(:)).EQ.MAXVAL(champ(:)) .AND. 
-     .MINVAL(champ(:)).EQ.val_exp ) THEN
-          SELECTCASE(varname)
-            CASE ('tsol')
-              IF ( .NOT.ALLOCATED(tsol)) THEN
-                CALL start_init_phys( iml, jml, lon_in, lat_in,
-     .              jml2, lon_in2, lat_in2, interbar )
-              ENDIF
-              IF ( SIZE(tsol) .NE. SIZE(lon_in)*SIZE(lat_in) ) THEN
-                WRITE(*,*) 
-     . 'STARTVAR module has been initialized to the wrong size'
-                 STOP
-              ENDIF
-              CALL gr_dyn_fi(1, iml, jml, nbindex, tsol, champ)
-            CASE ('qsol')
-              IF ( .NOT.ALLOCATED(qsol)) THEN
-                CALL start_init_phys( iml, jml, lon_in, lat_in,
-     .              jml2, lon_in2,lat_in2 , interbar )
-              ENDIF
-              IF ( SIZE(qsol) .NE. SIZE(lon_in)*SIZE(lat_in) ) THEN
-                WRITE(*,*) 
-     . 'STARTVAR module has been initialized to the wrong size'
-                STOP
-              ENDIF
-              CALL gr_dyn_fi(1, iml, jml, nbindex, qsol, champ)
-            CASE ('psol')
-              IF ( .NOT.ALLOCATED(psol_dyn)) THEN
-                CALL start_init_dyn( iml, jml, lon_in, lat_in,
-     .              jml2, lon_in2,lat_in2 , interbar )
-              ENDIF
-              IF (SIZE(psol_dyn) .NE. SIZE(lon_in)*SIZE(lat_in)) THEN
-                WRITE(*,*) 
-     . 'STARTVAR module has been initialized to the wrong size'
-                STOP
-              ENDIF
-              CALL gr_dyn_fi(1, iml, jml, nbindex, psol_dyn, champ)
-            CASE ('zmea')
-              IF ( .NOT.ALLOCATED(relief)) THEN
-                CALL start_init_orog( iml, jml, lon_in, lat_in,
-     .            jml2, lon_in2,lat_in2 , interbar )
-              ENDIF
-              IF ( SIZE(relief) .NE. SIZE(lon_in)*SIZE(lat_in) ) THEN
-                WRITE(*,*)
-     . 'STARTVAR module has been initialized to the wrong size'
-                 STOP
-              ENDIF
-              CALL gr_dyn_fi(1, iml, jml, nbindex, relief, champ)
-            CASE ('zstd')
-              IF ( .NOT.ALLOCATED(zstd)) THEN
-                CALL start_init_orog( iml, jml, lon_in, lat_in,
-     .              jml2, lon_in2,lat_in2 , interbar )
-              ENDIF
-              IF ( SIZE(zstd) .NE. SIZE(lon_in)*SIZE(lat_in) ) THEN
-                WRITE(*,*)
-     . 'STARTVAR module has been initialized to the wrong size'
-                 STOP
-              ENDIF
-              CALL gr_dyn_fi(1, iml, jml, nbindex,zstd, champ)
-            CASE ('zsig')
-              IF ( .NOT.ALLOCATED(zsig)) THEN
-                CALL start_init_orog( iml, jml, lon_in, lat_in,
-     .               jml2, lon_in2,lat_in2 , interbar )
-              ENDIF
-              IF ( SIZE(zsig) .NE. SIZE(lon_in)*SIZE(lat_in) ) THEN
-                WRITE(*,*)
-     . 'STARTVAR module has been initialized to the wrong size'
-                 STOP
-              ENDIF
-              CALL gr_dyn_fi(1, iml, jml, nbindex,zsig, champ)
-            CASE ('zgam')
-              IF ( .NOT.ALLOCATED(zgam)) THEN
-                CALL start_init_orog( iml, jml, lon_in, lat_in,
-     .            jml2, lon_in2,lat_in2 , interbar )
-              ENDIF
-              IF ( SIZE(zgam) .NE. SIZE(lon_in)*SIZE(lat_in) ) THEN
-                WRITE(*,*)
-     . 'STARTVAR module has been initialized to the wrong size'
-                 STOP
-              ENDIF
-              CALL gr_dyn_fi(1, iml, jml, nbindex,zgam, champ)
-            CASE ('zthe')
-              IF ( .NOT.ALLOCATED(zthe)) THEN
-                CALL start_init_orog( iml, jml, lon_in, lat_in,
-     .            jml2, lon_in2,lat_in2 , interbar )
-              ENDIF
-              IF ( SIZE(zthe) .NE. SIZE(lon_in)*SIZE(lat_in) ) THEN
-                WRITE(*,*)
-     . 'STARTVAR module has been initialized to the wrong size'
-                 STOP
-              ENDIF
-              CALL gr_dyn_fi(1, iml, jml, nbindex,zthe, champ)
-            CASE ('zpic')
-              IF ( .NOT.ALLOCATED(zpic)) THEN
-                CALL start_init_orog( iml, jml, lon_in, lat_in,
-     .            jml2, lon_in2,lat_in2 , interbar )
-              ENDIF
-              IF ( SIZE(zpic) .NE. SIZE(lon_in)*SIZE(lat_in) ) THEN
-                WRITE(*,*)
-     . 'STARTVAR module has been initialized to the wrong size'
-                 STOP
-              ENDIF
-              CALL gr_dyn_fi(1, iml, jml, nbindex,zpic, champ)
-            CASE ('zval')
-              IF ( .NOT.ALLOCATED(zval)) THEN
-                CALL start_init_orog( iml, jml, lon_in, lat_in,
-     .            jml2, lon_in2,lat_in2 , interbar )
-              ENDIF
-              IF ( SIZE(zval) .NE. SIZE(lon_in)*SIZE(lat_in) ) THEN
-                WRITE(*,*)
-     . 'STARTVAR module has been initialized to the wrong size'
-                 STOP
-              ENDIF
-              CALL gr_dyn_fi(1, iml, jml, nbindex,zval, champ)
-            CASE ('rads')
-                  champ(:) = 0.0
-            CASE ('snow')
-                  champ(:) = 0.0
-cIM "slab" ocean
-            CASE ('tslab')
-                   champ(:) = 0.0
-            CASE ('seaice')
-                  champ(:) = 0.0
-            CASE ('rugmer')
-                  champ(:) = 0.001
-            CASE ('agsno')
-                  champ(:) = 50.0
-            CASE DEFAULT
-              WRITE(*,*) 'startget_phys1d'
-              WRITE(*,*) 'No rule is present to extract variable  ',
-     . varname(:LEN_TRIM(varname)),' from any data set'
-              STOP
-          END SELECT
-      ELSE
-        !
-        ! If we see tsol we catch it as we may need it for a 3D interpolation
-        !
-        SELECTCASE(varname)
-          CASE ('tsol')
-            IF ( .NOT.ALLOCATED(tsol)) THEN
-              ALLOCATE(tsol(SIZE(lon_in),SIZE(lat_in) ))
-            ENDIF
-            CALL gr_fi_dyn(1, iml, jml, nbindex, champ, tsol)
-        END SELECT
-      ENDIF
-      END SUBROUTINE startget_phys1d
-    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-    !
-      SUBROUTINE start_init_phys( iml, jml, lon_in, lat_in, jml2,
-     .                 lon_in2, lat_in2 , interbar )
-    !
-      INTEGER, INTENT(in) :: iml, jml ,jml2
-      REAL, INTENT(in) :: lon_in(iml), lat_in(jml)
-      REAL, INTENT(in) :: lon_in2(iml), lat_in2(jml2)
-      LOGICAL interbar
-    !
-    !  LOCAL
-    !
-!ac     REAL :: lev(1), date, dt
-      REAL :: date, dt
-      REAL, DIMENSION(:), ALLOCATABLE :: levphys_ini
-!ac
-      INTEGER :: itau(1)
-      INTEGER ::  llm_tmp, ttm_tmp
-      INTEGER :: i, j
-    !
-      CHARACTER*25 title
-      CHARACTER*120 :: physfname
-      LOGICAL :: check=.TRUE.
-    !
-      REAL, ALLOCATABLE :: lon_rad(:), lat_rad(:)
-      REAL, ALLOCATABLE :: lon_ini(:), lat_ini(:)
-      REAL, ALLOCATABLE :: var_ana(:,:), tmp_var(:,:)
-    !
-      physfname = 'ECPHY.nc'
-    !
-      IF ( check ) WRITE(*,*) 'Opening the surface analysis'
-    !
-      CALL flininfo(physfname, iml_phys, jml_phys, llm_tmp,
-     . ttm_tmp, fid_phys)
-    !
-      ALLOCATE (lat_phys(iml_phys,jml_phys))
-      ALLOCATE (lon_phys(iml_phys,jml_phys))
-!ac
-      ALLOCATE (levphys_ini(llm_tmp))
-    !
-!      CALL flinopen(physfname, .FALSE., iml_phys, jml_phys, 
-!     . llm_tmp, lon_phys, lat_phys, lev, ttm_tmp, 
-!     . itau, date, dt, fid_phys)
-    !
-      CALL flinopen(physfname, .FALSE., iml_phys, jml_phys, 
-     . llm_tmp, lon_phys, lat_phys, levphys_ini, ttm_tmp, 
-     . itau, date, dt, fid_phys)
-    !
-      DEALLOCATE (levphys_ini)
-!ac
-    !
-    ! Allocate the space we will need to get the data out of this file
-    !
-      ALLOCATE(var_ana(iml_phys, jml_phys))
-    !
-    !   In case we have a file which is in degrees we do the transformation
-    !
-      ALLOCATE(lon_rad(iml_phys))
-      ALLOCATE(lon_ini(iml_phys))
-
-      IF ( MAXVAL(lon_phys(:,:)) .GT. 2.0 * ASIN(1.0) ) THEN
-          lon_ini(:) = lon_phys(:,1) * 2.0 * ASIN(1.0) / 180.0
-      ELSE
-          lon_ini(:) = lon_phys(:,1) 
-      ENDIF
-
-      ALLOCATE(lat_rad(jml_phys))
-      ALLOCATE(lat_ini(jml_phys))
-
-      IF ( MAXVAL(lat_phys(:,:)) .GT. 2.0 * ASIN(1.0) ) THEN
-          lat_ini(:) = lat_phys(1,:) * 2.0 * ASIN(1.0) / 180.0
-      ELSE
-          lat_ini(:) = lat_phys(1,:) 
-      ENDIF
-
-
-    !
-    !   We get the two standard varibales
-    !   Surface temperature
-    !
-      ALLOCATE(tsol(iml,jml))
-      ALLOCATE(tmp_var(iml-1,jml))
-    !
-    !
-
-      CALL flinget(fid_phys, 'ST', iml_phys, jml_phys, 
-     .llm_tmp, ttm_tmp, 1, 1, var_ana)
-
-      title='ST'
-      CALL conf_dat2d(title,iml_phys, jml_phys, lon_ini, lat_ini,
-     . lon_rad, lat_rad, var_ana , interbar  )
-
-      IF ( interbar )   THEN
-        WRITE(6,*) '-------------------------------------------------',
-     ,'--------------'
-        WRITE(6,*) '$$$ Utilisation de l interpolation barycentrique ',
-     , ' pour  ST $$$ '
-        WRITE(6,*) '-------------------------------------------------',
-     ,'--------------'
-        CALL inter_barxy ( iml_phys,jml_phys -1,lon_rad,lat_rad ,
-     ,   var_ana, iml-1, jml-1, lon_in2, lat_in2, jml, tmp_var   ) 
-      ELSE
-        CALL grille_m(iml_phys, jml_phys, lon_rad, lat_rad,
-     .    var_ana, iml-1, jml, lon_in, lat_in, tmp_var     )
-      ENDIF
-
-      CALL gr_int_dyn(tmp_var, tsol, iml-1, jml)
-    !
-    ! Soil moisture
-    !
-      ALLOCATE(qsol(iml,jml))
-      CALL flinget(fid_phys, 'CDSW', iml_phys, jml_phys,
-     . llm_tmp, ttm_tmp, 1, 1, var_ana)
-
-      title='CDSW'
-      CALL conf_dat2d(title,iml_phys, jml_phys, lon_ini, lat_ini,
-     . lon_rad, lat_rad, var_ana, interbar  )
-
-      IF ( interbar )   THEN
-        WRITE(6,*) '-------------------------------------------------',
-     ,'--------------'
-        WRITE(6,*) '$$$ Utilisation de l interpolation barycentrique ',
-     , ' pour  CDSW $$$ '
-        WRITE(6,*) '-------------------------------------------------',
-     ,'--------------'
-        CALL inter_barxy ( iml_phys,jml_phys -1,lon_rad,lat_rad ,
-     ,   var_ana, iml-1, jml-1, lon_in2, lat_in2, jml, tmp_var  )
-      ELSE
-        CALL grille_m(iml_phys, jml_phys, lon_rad, lat_rad,
-     .    var_ana, iml-1, jml, lon_in, lat_in, tmp_var     )
-      ENDIF
-c
-        CALL gr_int_dyn(tmp_var, qsol, iml-1, jml)
-    !
-       CALL flinclo(fid_phys)
-    !
-      END SUBROUTINE start_init_phys
-    !
-    !
-    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-    !
-    !
-      SUBROUTINE startget_dyn(varname, iml, jml, lon_in, lat_in,
-     . lml, pls, workvar, champ, val_exp,jml2, lon_in2, lat_in2 ,
-     ,  interbar )
-    !
-    !   ARGUMENTS
-    !
-      CHARACTER*(*), INTENT(in) :: varname
-      INTEGER, INTENT(in) :: iml, jml, lml, jml2
-      REAL, INTENT(in) :: lon_in(iml), lat_in(jml)
-      REAL, INTENT(in) :: lon_in2(iml), lat_in2(jml2)
-      REAL, INTENT(in) :: pls(iml, jml, lml)
-      REAL, INTENT(in) :: workvar(iml, jml, lml)
-      REAL, INTENT(inout) :: champ(iml, jml, lml)
-      REAL, INTENT(in) :: val_exp
-      LOGICAL interbar
-    !
-    !    LOCAL
-    !
-      INTEGER :: il, ij, ii
-      REAL :: xppn, xpps
-    !
-#include "dimensions.h"
-#include "paramet.h"
-#include "comgeom2.h"
-#include "comconst.h"
-    !
-    !   This routine only works if the variable does not exist or is constant
-    !
-      IF ( MINVAL(champ(:,:,:)).EQ.MAXVAL(champ(:,:,:)) .AND.
-     . MINVAL(champ(:,:,:)).EQ.val_exp ) THEN
-        !
-        SELECTCASE(varname)
-          CASE ('u')
-            IF ( .NOT.ALLOCATED(psol_dyn)) THEN
-              CALL start_init_dyn( iml, jml, lon_in, lat_in, jml2 ,
-     .          lon_in2,lat_in2 , interbar )
-            ENDIF
-            CALL start_inter_3d('U', iml, jml, lml, lon_in,
-     .       lat_in, jml2, lon_in2, lat_in2,  pls, champ,interbar )
-            DO il=1,lml
-              DO ij=1,jml
-                DO ii=1,iml-1
-                  champ(ii,ij,il) = champ(ii,ij,il) * cu(ii,ij)
-                ENDDO
-                champ(iml,ij, il) = champ(1,ij, il)
-              ENDDO
-            ENDDO
-          CASE ('v')
-            IF ( .NOT.ALLOCATED(psol_dyn)) THEN
-              CALL start_init_dyn( iml, jml, lon_in, lat_in , jml2, 
-     .           lon_in2, lat_in2 , interbar )
-            ENDIF
-            CALL start_inter_3d('V', iml, jml, lml, lon_in, 
-     .       lat_in, jml2, lon_in2, lat_in2,  pls, champ, interbar )
-            DO il=1,lml
-              DO ij=1,jml
-                DO ii=1,iml-1
-                  champ(ii,ij,il) = champ(ii,ij,il) * cv(ii,ij)
-                ENDDO
-                champ(iml,ij, il) = champ(1,ij, il)
-              ENDDO
-            ENDDO
-          CASE ('t')
-            IF ( .NOT.ALLOCATED(psol_dyn)) THEN
-              CALL start_init_dyn( iml, jml, lon_in, lat_in, jml2 ,
-     .           lon_in2, lat_in2 ,interbar )
-            ENDIF
-            CALL start_inter_3d('TEMP', iml, jml, lml, lon_in,
-     .       lat_in, jml2, lon_in2, lat_in2,  pls, champ, interbar )
- 
-          CASE ('tpot')
-            IF ( .NOT.ALLOCATED(psol_dyn)) THEN
-              CALL start_init_dyn( iml, jml, lon_in, lat_in , jml2 ,
-     .            lon_in2, lat_in2 , interbar )
-            ENDIF
-            CALL start_inter_3d('TEMP', iml, jml, lml, lon_in,
-     .       lat_in, jml2, lon_in2, lat_in2,  pls, champ, interbar )
-            IF ( MINVAL(workvar(:,:,:)) .NE. MAXVAL(workvar(:,:,:)) )
-     .                                    THEN
-              DO il=1,lml
-                DO ij=1,jml
-                  DO ii=1,iml-1
-                    champ(ii,ij,il) = champ(ii,ij,il) * cpp 
-     .                                 / workvar(ii,ij,il)
-                  ENDDO
-                  champ(iml,ij,il) = champ(1,ij,il)
-                ENDDO
-              ENDDO
-              DO il=1,lml
-                xppn = SUM(aire(:,1)*champ(:,1,il))/apoln
-                xpps = SUM(aire(:,jml)*champ(:,jml,il))/apols
-                champ(:,1,il) = xppn
-                champ(:,jml,il) = xpps
-              ENDDO
-            ELSE
-              WRITE(*,*)'Could not compute potential temperature as the'
-              WRITE(*,*)'Exner function is missing or constant.'
-              STOP
-            ENDIF
-          CASE ('q')
-            IF ( .NOT.ALLOCATED(psol_dyn)) THEN
-              CALL start_init_dyn( iml, jml, lon_in, lat_in, jml2 ,
-     .           lon_in2, lat_in2 , interbar )
-            ENDIF
-            CALL start_inter_3d('R', iml, jml, lml, lon_in, lat_in,
-     .        jml2, lon_in2, lat_in2,  pls, champ, interbar )
-            IF ( MINVAL(workvar(:,:,:)) .NE. MAXVAL(workvar(:,:,:)) ) 
-     .                                     THEN
-              DO il=1,lml
-                DO ij=1,jml
-                  DO ii=1,iml-1
-                    champ(ii,ij,il) = 0.01 * champ(ii,ij,il) *
-     .                                       workvar(ii,ij,il)
-                  ENDDO
-                  champ(iml,ij,il) = champ(1,ij,il)
-                ENDDO
-              ENDDO
-              WHERE ( champ .LT. 0.) champ = 1.0E-10
-              DO il=1,lml
-                xppn = SUM(aire(:,1)*champ(:,1,il))/apoln
-                xpps = SUM(aire(:,jml)*champ(:,jml,il))/apols
-                champ(:,1,il) = xppn
-                champ(:,jml,il) = xpps
-              ENDDO
-            ELSE
-              WRITE(*,*)'Could not compute specific humidity as the'
-              WRITE(*,*)'saturated humidity is missing or constant.'
-              STOP
-            ENDIF
-          CASE DEFAULT
-            WRITE(*,*) 'startget_dyn'
-            WRITE(*,*) 'No rule is present to extract variable  ',
-     . varname(:LEN_TRIM(varname)),' from any data set'
-            STOP
-          END SELECT
-      ENDIF
-      END SUBROUTINE startget_dyn
-    !
-    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-    !
-      SUBROUTINE start_init_dyn( iml, jml, lon_in, lat_in,jml2,lon_in2 ,
-     ,             lat_in2 , interbar )
-    !
-      INTEGER, INTENT(in) :: iml, jml, jml2
-      REAL, INTENT(in) :: lon_in(iml), lat_in(jml)
-      REAL, INTENT(in) :: lon_in2(iml), lat_in2(jml2)
-      LOGICAL interbar
-    !
-    !  LOCAL
-    !
-      REAL :: lev(1), date, dt
-      INTEGER :: itau(1)
-      INTEGER :: i, j
-      integer :: iret
-    !
-      CHARACTER*120 :: physfname
-      LOGICAL :: check=.TRUE.
-    !
-      REAL, ALLOCATABLE :: lon_rad(:), lat_rad(:)
-      REAL, ALLOCATABLE :: lon_ini(:), lat_ini(:)
-      REAL, ALLOCATABLE :: var_ana(:,:), tmp_var(:,:), z(:,:)
-      REAL, ALLOCATABLE :: xppn(:), xpps(:)
-      LOGICAL :: allo
-    !
-    !
-#include "dimensions.h"
-#include "paramet.h"
-#include "comgeom2.h"
-
-      CHARACTER*25 title
-
-    !
-      physfname = 'ECDYN.nc'
-    !
-      IF ( check ) WRITE(*,*) 'Opening the surface analysis'
-    !
-      CALL flininfo(physfname, iml_dyn, jml_dyn, llm_dyn,
-     .                            ttm_dyn, fid_dyn)
-      IF ( check ) WRITE(*,*) 'Values read: ', iml_dyn, jml_dyn, 
-     .                                         llm_dyn, ttm_dyn
-    !
-      ALLOCATE (lat_dyn(iml_dyn,jml_dyn), stat=iret)
-      ALLOCATE (lon_dyn(iml_dyn,jml_dyn), stat=iret)
-      ALLOCATE (levdyn_ini(llm_dyn), stat=iret)
-    !
-      CALL flinopen(physfname, .FALSE., iml_dyn, jml_dyn, llm_dyn,
-     . lon_dyn, lat_dyn, levdyn_ini, ttm_dyn, 
-     . itau, date, dt, fid_dyn)
-    !
-
-      allo = allocated (var_ana)
-      if (allo) then
-        DEALLOCATE(var_ana, stat=iret)
-      endif
-      ALLOCATE(var_ana(iml_dyn, jml_dyn), stat=iret)
-
-      allo = allocated (lon_rad)
-      if (allo) then
-        DEALLOCATE(lon_rad, stat=iret)
-      endif
-
-      ALLOCATE(lon_rad(iml_dyn), stat=iret)
-      ALLOCATE(lon_ini(iml_dyn))
-       
-      IF ( MAXVAL(lon_dyn(:,:)) .GT. 2.0 * ASIN(1.0) ) THEN
-          lon_ini(:) = lon_dyn(:,1) * 2.0 * ASIN(1.0) / 180.0
-      ELSE
-          lon_ini(:) = lon_dyn(:,1) 
-      ENDIF
-
-      ALLOCATE(lat_rad(jml_dyn))
-      ALLOCATE(lat_ini(jml_dyn))
-
-      IF ( MAXVAL(lat_dyn(:,:)) .GT. 2.0 * ASIN(1.0) ) THEN
-          lat_ini(:) = lat_dyn(1,:) * 2.0 * ASIN(1.0) / 180.0
-      ELSE
-          lat_ini(:) = lat_dyn(1,:) 
-      ENDIF
-    !
-
-
-      ALLOCATE(z(iml, jml))
-      ALLOCATE(tmp_var(iml-1,jml))
-    !
-      CALL flinget(fid_dyn, 'Z', iml_dyn, jml_dyn, 0, ttm_dyn,
-     .              1, 1, var_ana)
-c
-      title='Z'
-      CALL conf_dat2d( title,iml_dyn, jml_dyn,lon_ini, lat_ini,
-     . lon_rad, lat_rad, var_ana, interbar  )
-c
-      IF ( interbar )   THEN
-        WRITE(6,*) '-------------------------------------------------',
-     ,'--------------'
-        WRITE(6,*) '$$$ Utilisation de l interpolation barycentrique ',
-     , ' pour  Z  $$$ '
-        WRITE(6,*) '-------------------------------------------------',
-     ,'--------------'
-        CALL inter_barxy ( iml_dyn,jml_dyn -1,lon_rad,lat_rad ,
-     ,    var_ana, iml-1, jml-1, lon_in2, lat_in2, jml, tmp_var) 
-      ELSE
-        CALL grille_m(iml_dyn, jml_dyn , lon_rad, lat_rad, var_ana,
-     .               iml-1, jml, lon_in, lat_in, tmp_var)
-      ENDIF
-
-      CALL gr_int_dyn(tmp_var, z, iml-1, jml)
-    !
-      ALLOCATE(psol_dyn(iml, jml))
-    !
-      CALL flinget(fid_dyn, 'SP', iml_dyn, jml_dyn, 0, ttm_dyn,
-     .              1, 1, var_ana)
-
-       title='SP'
-      CALL conf_dat2d( title,iml_dyn, jml_dyn,lon_ini, lat_ini,
-     . lon_rad, lat_rad, var_ana, interbar  )
-
-      IF ( interbar )   THEN
-        WRITE(6,*) '-------------------------------------------------',
-     ,'--------------'
-        WRITE(6,*) '$$$ Utilisation de l interpolation barycentrique ',
-     , ' pour  SP  $$$ '
-        WRITE(6,*) '-------------------------------------------------',
-     ,'--------------'
-        CALL inter_barxy ( iml_dyn,jml_dyn -1,lon_rad,lat_rad ,
-     ,    var_ana, iml-1, jml-1, lon_in2, lat_in2, jml, tmp_var) 
-      ELSE
-        CALL grille_m(iml_dyn, jml_dyn , lon_rad, lat_rad, var_ana,
-     .             iml-1, jml, lon_in, lat_in, tmp_var  )
-      ENDIF
-
-      CALL gr_int_dyn(tmp_var, psol_dyn, iml-1, jml)
-    !
-      IF ( .NOT.ALLOCATED(tsol)) THEN
-    !   These variables may have been allocated by the need to 
-    !   create a start field for them or by the varibale
-    !   coming out of the restart file. In case we dor have it we will initialize it.
-    !
-        CALL start_init_phys( iml, jml, lon_in, lat_in,jml2,lon_in2,
-     .                 lat_in2 , interbar )
-      ELSE
-        IF ( SIZE(tsol) .NE. SIZE(psol_dyn) ) THEN
-        WRITE(*,*) 'start_init_dyn :'
-        WRITE(*,*) 'The temperature field we have does not ',
-     .             'have the right size'
-        STOP
-      ENDIF
-      ENDIF
-      IF ( .NOT.ALLOCATED(phis)) THEN
-            !
-            !    These variables may have been allocated by the need to create a start field for them or by the varibale
-            !     coming out of the restart file. In case we dor have it we will initialize it.
-            !
-        CALL start_init_orog( iml, jml, lon_in, lat_in, jml2, lon_in2 ,
-     .      lat_in2 , interbar )
-            !
-      ELSE
-            !
-          IF (SIZE(phis) .NE. SIZE(psol_dyn)) THEN
-                !
-              WRITE(*,*) 'start_init_dyn :'
-              WRITE(*,*) 'The orography field we have does not ',
-     .                   ' have the right size'
-              STOP
-          ENDIF
-            !
-      ENDIF
-    !
-    !     PSOL is computed in Pascals
-    !
-    !
-      DO j = 1, jml
-        DO i = 1, iml-1
-          psol_dyn(i,j) = psol_dyn(i,j)*(1.0+(z(i,j)-phis(i,j)) 
-     .                    /287.0/tsol(i,j))
-        ENDDO
-        psol_dyn(iml,j) = psol_dyn(1,j)
-      ENDDO
-    !
-    !
-      ALLOCATE(xppn(iml-1))
-      ALLOCATE(xpps(iml-1)) 
-    !
-      DO  i   = 1, iml-1
-        xppn(i) = aire( i,1) * psol_dyn( i,1)
-        xpps(i) = aire( i,jml) * psol_dyn( i,jml)
-      ENDDO
-    !
-      DO i   = 1, iml
-        psol_dyn(i,1    )  = SUM(xppn)/apoln
-        psol_dyn(i,jml)  = SUM(xpps)/apols
-      ENDDO
-    !
-      RETURN
-    !
-      END SUBROUTINE start_init_dyn
-    !
-    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-    !
-      SUBROUTINE start_inter_3d(varname, iml, jml, lml, lon_in,
-     .      lat_in, jml2, lon_in2, lat_in2, pls_in, var3d, interbar )
-    !
-    !    This subroutine gets a variables from a 3D file and does the interpolations needed
-    !
-    !
-    !    ARGUMENTS
-    !
-      CHARACTER*(*) :: varname
-      INTEGER :: iml, jml, lml, jml2
-      REAL :: lon_in(iml), lat_in(jml), pls_in(iml, jml, lml)
-      REAL :: lon_in2(iml) , lat_in2(jml2)
-      REAL :: var3d(iml, jml, lml)
-      LOGICAL interbar
-      real chmin,chmax
-    !
-    !  LOCAL
-    !
-      CHARACTER*25 title
-      INTEGER :: ii, ij, il, jsort,i,j,l
-      REAL :: bx, by
-      REAL, ALLOCATABLE :: lon_rad(:), lat_rad(:)
-      REAL, ALLOCATABLE :: lon_ini(:), lat_ini(:) , lev_dyn(:)
-      REAL, ALLOCATABLE :: var_tmp2d(:,:), var_tmp3d(:,:,:)
-      REAL, ALLOCATABLE :: ax(:), ay(:), yder(:)
-!       REAL, ALLOCATABLE :: varrr(:,:,:)
-      INTEGER, ALLOCATABLE :: lind(:)
-    !
-      LOGICAL :: check = .TRUE.
-    !
-      IF ( .NOT. ALLOCATED(var_ana3d)) THEN
-          ALLOCATE(var_ana3d(iml_dyn, jml_dyn, llm_dyn))
-      ENDIF
-!          ALLOCATE(varrr(iml_dyn, jml_dyn, llm_dyn))
-    !
-    !
-      IF ( check) WRITE(*,*) 'Going into flinget to extract the 3D ',
-     .  ' field.', fid_dyn
-      IF ( check) WRITE(*,*) fid_dyn, varname, iml_dyn, jml_dyn,
-     .                        llm_dyn,ttm_dyn
-    !
-      CALL flinget(fid_dyn, varname, iml_dyn, jml_dyn, llm_dyn, 
-     . ttm_dyn, 1, 1, var_ana3d)
-    !
-      IF ( check) WRITE(*,*) 'Allocating space for the interpolation',
-     . iml, jml, llm_dyn
-    !
-      ALLOCATE(lon_rad(iml_dyn))
-      ALLOCATE(lon_ini(iml_dyn))
-
-      IF ( MAXVAL(lon_dyn(:,:)) .GT. 2.0 * ASIN(1.0) ) THEN
-          lon_ini(:) = lon_dyn(:,1) * 2.0 * ASIN(1.0) / 180.0
-      ELSE
-          lon_ini(:) = lon_dyn(:,1) 
-      ENDIF
-
-      ALLOCATE(lat_rad(jml_dyn))
-      ALLOCATE(lat_ini(jml_dyn))
-
-      ALLOCATE(lev_dyn(llm_dyn))
-
-      IF ( MAXVAL(lat_dyn(:,:)) .GT. 2.0 * ASIN(1.0) ) THEN
-          lat_ini(:) = lat_dyn(1,:) * 2.0 * ASIN(1.0) / 180.0
-      ELSE
-          lat_ini(:) = lat_dyn(1,:) 
-      ENDIF
-    !
-
-      CALL conf_dat3d ( varname,iml_dyn, jml_dyn, llm_dyn, lon_ini, 
-     . lat_ini, levdyn_ini, lon_rad, lat_rad, lev_dyn, var_ana3d  ,
-     ,  interbar                                                   )
-
-      ALLOCATE(var_tmp2d(iml-1, jml))
-      ALLOCATE(var_tmp3d(iml, jml, llm_dyn))
-      ALLOCATE(ax(llm_dyn))
-      ALLOCATE(ay(llm_dyn))
-      ALLOCATE(yder(llm_dyn))
-      ALLOCATE(lind(llm_dyn))
-    !
- 
-      DO il=1,llm_dyn
-        !
-      IF( interbar )  THEN
-       IF( il.EQ.1 )  THEN
-        WRITE(6,*) '-------------------------------------------------',
-     ,'--------------'
-        WRITE(6,*) '$$$ Utilisation de l interpolation barycentrique ',
-     , ' pour ', varname
-        WRITE(6,*) '-------------------------------------------------',
-     ,'--------------'
-       ENDIF
-       CALL inter_barxy ( iml_dyn, jml_dyn -1,lon_rad, lat_rad, 
-     , var_ana3d(:,:,il),iml-1, jml2, lon_in2, lat_in2,jml,var_tmp2d ) 
-      ELSE
-       CALL grille_m(iml_dyn, jml_dyn, lon_rad, lat_rad, 
-     .  var_ana3d(:,:,il), iml-1, jml, lon_in, lat_in, var_tmp2d )
-      ENDIF
-        !
-        CALL gr_int_dyn(var_tmp2d, var_tmp3d(:,:,il), iml-1, jml)
-        !
-       ENDDO
-       !
-          DO il=1,llm_dyn
-            lind(il) = llm_dyn-il+1
-          ENDDO
-    !
-c
-c  ... Pour l'interpolation verticale ,on interpole du haut de l'atmosphere
-c                    vers  le  sol  ...
-c
-      DO ij=1,jml
-        DO ii=1,iml-1
-          !
-          ax(:) = lev_dyn(lind(:)) 
-          ay(:) = var_tmp3d(ii, ij, lind(:))
-          !
-         
-          CALL SPLINE(ax, ay, llm_dyn, 1.e30, 1.e30, yder)
-          !
-          DO il=1,lml
-            bx = pls_in(ii, ij, il)
-            CALL SPLINT(ax, ay, yder, llm_dyn, bx, by)
-            var3d(ii, ij, il) = by
-          ENDDO
-          !
-        ENDDO
-        var3d(iml, ij, :) = var3d(1, ij, :) 
-      ENDDO
-
-      do il=1,lml
-        call minmax(iml*jml,var3d(1,1,il),chmin,chmax)
-      SELECTCASE(varname)
-       CASE('U')
-          WRITE(*,*) ' U  min max l ',il,chmin,chmax
-       CASE('V')
-          WRITE(*,*) ' V  min max l ',il,chmin,chmax
-       CASE('TEMP')
-          WRITE(*,*) ' TEMP  min max l ',il,chmin,chmax
-       CASE('R')
-          WRITE(*,*) ' R  min max l ',il,chmin,chmax
-      END SELECT
-           enddo
-
-      DEALLOCATE(lon_rad)
-      DEALLOCATE(lon_ini)
-      DEALLOCATE(lat_rad)
-      DEALLOCATE(lat_ini)
-      DEALLOCATE(lev_dyn)
-      DEALLOCATE(var_tmp2d)
-      DEALLOCATE(var_tmp3d)
-      DEALLOCATE(ax)
-      DEALLOCATE(ay)
-      DEALLOCATE(yder)
-      DEALLOCATE(lind)
-
-    !
-      RETURN
-    !
-      END SUBROUTINE start_inter_3d
-    !
-#endif
-! of #ifdef CPP_EARTH
-      END MODULE startvar
Index: LMDZ4/trunk/libf/dyn3dpar/startvar.F90
===================================================================
--- LMDZ4/trunk/libf/dyn3dpar/startvar.F90	(revision 1319)
+++ LMDZ4/trunk/libf/dyn3dpar/startvar.F90	(revision 1319)
@@ -0,0 +1,767 @@
+!
+! $Id$
+!
+!*******************************************************************************
+!
+MODULE startvar
+!
+!*******************************************************************************
+!
+!-------------------------------------------------------------------------------
+! Purpose: Access data from the database of atmospheric to initialize the model.
+!-------------------------------------------------------------------------------
+! Comments:
+!
+!    *  This module is designed to work for Earth (and with ioipsl)
+!
+!    *  There are three ways to acces data, depending on the type of field
+!  which needs to be extracted. In any case the call should come after a restget
+!  and should be of the type :                     CALL startget(...)
+!
+!  - A 1D variable on the physical grid :
+!    CALL startget(varname, iml, jml,  lon_in,  lat_in,  nbindex,              &
+!           champ, val_exp,      jml2, lon_in2, lat_in2, ibar )
+!
+!  - A 2D variable on the dynamical grid :
+!    CALL startget(varname, iml, jml,  lon_in,  lat_in,                        &
+!           champ, val_exp,      jml2, lon_in2, lat_in2, ibar )             
+!
+!  - A 3D variable on the dynamical grid :
+!    CALL startget(varname, iml, jml,  lon_in,  lat_in,  lml, pls, workvar,    &
+!           champ, val_exp,      jml2, lon_in2, lat_in2, ibar )
+!
+!    *  Data needs to be in NetCDF format
+!
+!    *  Variables should have the following names in the files:
+!            'RELIEF' : High resolution orography 
+!            'ST'     : Surface temperature
+!            'CDSW'   : Soil moisture
+!            'Z'      : Surface geopotential
+!            'SP'     : Surface pressure
+!            'U'      : East ward wind
+!            'V'      : Northward wind
+!            'TEMP'   : Temperature
+!            'R'      : Relative humidity
+!
+!   *   There is a big mess with the longitude size. Should it be iml or iml+1 ?
+!  I have chosen to use the iml+1 as an argument to this routine and we declare
+!  internaly smaller fields when needed. This needs to be cleared once and for
+!  all in LMDZ. A convention is required.
+!-------------------------------------------------------------------------------
+#ifdef CPP_EARTH
+  USE ioipsl
+  IMPLICIT NONE
+
+  PRIVATE
+  PUBLIC startget
+  INTERFACE startget
+    MODULE PROCEDURE startget_phys1d, startget_phys2d, startget_dyn
+  END INTERFACE
+
+  REAL,    SAVE :: deg2rad,  pi
+  INTEGER, SAVE ::           iml_rel,  jml_rel
+  INTEGER, SAVE :: fid_phys, iml_phys, jml_phys
+  INTEGER, SAVE :: fid_dyn,  iml_dyn,  jml_dyn,  llm_dyn,  ttm_dyn
+  REAL, DIMENSION(:,:),   ALLOCATABLE, TARGET, SAVE :: lon_phys, lon_dyn
+  REAL, DIMENSION(:,:),   ALLOCATABLE, TARGET, SAVE :: lat_phys, lat_dyn
+  REAL, DIMENSION(:,:),   ALLOCATABLE, TARGET, SAVE :: lon_rug, lon_alb, lon_rel
+  REAL, DIMENSION(:,:),   ALLOCATABLE, TARGET, SAVE :: lat_rug, lat_alb, lat_rel
+  REAL, DIMENSION(:),     ALLOCATABLE, TARGET, SAVE :: levdyn_ini
+  REAL, DIMENSION(:,:),   ALLOCATABLE, TARGET, SAVE :: relief, zstd, zsig, zgam
+  REAL, DIMENSION(:,:),   ALLOCATABLE, TARGET, SAVE :: masque, zthe, zpic, zval
+  REAL, DIMENSION(:,:),   ALLOCATABLE, TARGET, SAVE :: rugo, phis, tsol, qsol
+  REAL, DIMENSION(:,:),   ALLOCATABLE, TARGET, SAVE :: psol_dyn
+  REAL, DIMENSION(:,:,:), ALLOCATABLE, TARGET, SAVE :: var_ana3d
+
+   CONTAINS
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE startget_phys1d(varname, iml, jml, lon_in, lat_in, nbindex, champ,  &
+                           val_exp ,jml2, lon_in2, lat_in2, ibar)
+!
+!-------------------------------------------------------------------------------
+! Comment:
+!   This routine only works if the variable does not exist or is constant.
+!-------------------------------------------------------------------------------
+! Arguments:
+  CHARACTER(LEN=*),         INTENT(IN)    :: varname
+  INTEGER,                  INTENT(IN)    :: iml, jml
+  REAL, DIMENSION(iml),     INTENT(IN)    :: lon_in
+  REAL, DIMENSION(jml),     INTENT(IN)    :: lat_in
+  INTEGER,                  INTENT(IN)    :: nbindex
+  REAL, DIMENSION(nbindex), INTENT(INOUT) :: champ
+  REAL,                     INTENT(IN)    :: val_exp
+  INTEGER,                  INTENT(IN)    :: jml2
+  REAL, DIMENSION(iml),     INTENT(IN)    :: lon_in2
+  REAL, DIMENSION(jml2),    INTENT(IN)    :: lat_in2
+  LOGICAL,                  INTENT(IN)    :: ibar
+!-------------------------------------------------------------------------------
+! Local variables:
+#include "iniprint.h"
+  REAL, DIMENSION(:,:), POINTER :: v2d
+!-------------------------------------------------------------------------------
+  v2d=>NULL()
+  IF(MINVAL(champ)==MAXVAL(champ).AND.MINVAL(champ)==val_exp) THEN
+
+!--- CHECKING IF THE FIELD IS KNOWN ; READING UNALLOCATED FILES
+    SELECT CASE(varname)
+      CASE('tsol')
+        IF(.NOT.ALLOCATED(tsol))                                               &
+         CALL start_init_phys(iml,jml,lon_in,lat_in,jml2,lon_in2,lat_in2,ibar)
+      CASE('qsol')
+        IF(.NOT.ALLOCATED(qsol))                                               &
+         CALL start_init_phys(iml,jml,lon_in,lat_in,jml2,lon_in2,lat_in2,ibar)
+      CASE('psol')
+        IF(.NOT.ALLOCATED(psol_dyn))                                           &
+         CALL start_init_dyn (iml,jml,lon_in,lat_in,jml2,lon_in2,lat_in2,ibar)
+      CASE('zmea','zstd','zsig','zgam','zthe','zpic','zval')
+        IF(.NOT.ALLOCATED(relief))                                             &
+         CALL start_init_orog(iml,jml,lon_in,lat_in)
+      CASE('rads','snow','tslab','seaice','rugmer','agsno')
+      CASE DEFAULT
+        WRITE(lunout,*)'startget_phys1d'
+        WRITE(lunout,*)'No rule is present to extract variable '//TRIM(varname)&
+                     //' from any data set'; STOP
+    END SELECT
+
+!--- SELECTING v2d FOR WANTED VARIABLE AND CHEKING ITS SIZE
+    SELECT CASE(varname)
+      CASE('rads','snow','tslab','seaice');  champ=0.0
+      CASE('rugmer');                        champ(:)=0.001
+      CASE('agsno');                         champ(:)=50.0
+      CASE DEFAULT
+        SELECT CASE(varname)
+          CASE('tsol'); v2d=>tsol
+          CASE('qsol'); v2d=>qsol
+          CASE('psol'); v2d=>psol_dyn
+          CASE('zmea'); v2d=>relief
+          CASE('zstd'); v2d=>zstd
+          CASE('zsig'); v2d=>zsig
+          CASE('zgam'); v2d=>zgam
+          CASE('zthe'); v2d=>zthe
+          CASE('zpic'); v2d=>zpic
+          CASE('zval'); v2d=>zval
+        END SELECT
+        IF(SIZE(v2d)/=SIZE(lon_in)*SIZE(lat_in)) THEN
+         WRITE(lunout,*)'STARTVAR module has been initialized to the wrong size'
+         STOP
+        END IF
+        CALL gr_dyn_fi(1,iml,jml,nbindex,v2d,champ)
+    END SELECT
+
+  ELSE
+
+!--- SOME FIELDS ARE CAUGHT: MAY BE NEEDED FOR A 3D INTEPROLATION
+    SELECT CASE(varname)
+      CASE('tsol')
+        IF(.NOT.ALLOCATED(tsol)) ALLOCATE(tsol(iml,jml))
+        CALL gr_fi_dyn(1,iml,jml,nbindex,champ,tsol)
+    END SELECT
+
+  END IF
+
+END SUBROUTINE  startget_phys1d
+!
+!-------------------------------------------------------------------------------
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE startget_phys2d(varname, iml, jml, lon_in, lat_in, champ, val_exp,  &
+                           jml2, lon_in2, lat_in2 , ibar, msk)
+!
+!-------------------------------------------------------------------------------
+! Comment:
+!   This routine only works if the variable does not exist or is constant.
+!-------------------------------------------------------------------------------
+! Arguments:
+  CHARACTER(LEN=*),         INTENT(IN)           :: varname
+  INTEGER,                  INTENT(IN)           :: iml, jml
+  REAL, DIMENSION(iml),     INTENT(IN)           :: lon_in
+  REAL, DIMENSION(jml),     INTENT(IN)           :: lat_in
+  REAL, DIMENSION(iml,jml), INTENT(INOUT)        :: champ
+  REAL,                     INTENT(IN)           :: val_exp
+  INTEGER,                  INTENT(IN)           :: jml2
+  REAL, DIMENSION(iml),     INTENT(IN)           :: lon_in2
+  REAL, DIMENSION(jml2),    INTENT(IN)           :: lat_in2
+  LOGICAL,                  INTENT(IN)           :: ibar
+  REAL, DIMENSION(iml,jml), INTENT(IN), OPTIONAL :: msk
+!-------------------------------------------------------------------------------
+! Local variables:
+#include "iniprint.h"
+  REAL, DIMENSION(:,:), POINTER :: v2d=>NULL()
+  LOGICAL                       :: lrelief1, lrelief2
+!-------------------------------------------------------------------------------
+  v2d=>NULL()
+  lrelief1=(.NOT.ALLOCATED(relief).AND.     PRESENT(msk))
+  lrelief2=(.NOT.ALLOCATED(relief).AND..NOT.PRESENT(msk))
+  IF(MINVAL(champ)==MAXVAL(champ).AND.MINVAL(champ)==val_exp) THEN
+
+!--- CHECKING IF THE FIELD IS KNOWN ; READING UNALLOCATED FILES
+    SELECT CASE(varname)
+      CASE('psol')
+        IF(.NOT.ALLOCATED(psol_dyn))                                           &
+          CALL start_init_dyn (iml,jml,lon_in,lat_in,jml2,lon_in2,lat_in2,ibar)
+      CASE('relief')
+        IF(lrelief1)             CALL start_init_orog(iml,jml,lon_in,lat_in,msk)
+        IF(lrelief2)             CALL start_init_orog(iml,jml,lon_in,lat_in)
+      CASE('surfgeo')
+        IF(.NOT.ALLOCATED(phis)) CALL start_init_orog(iml,jml,lon_in,lat_in)
+      CASE('rugosite','masque')
+        IF(.NOT.ALLOCATED(rugo)) CALL start_init_orog(iml,jml,lon_in,lat_in)
+      CASE DEFAULT
+        WRITE(lunout,*)'startget_phys2d'
+        WRITE(lunout,*)'No rule is present to extract variable '//TRIM(varname)&
+                     //' from any data set'; STOP
+    END SELECT
+
+!--- SELECTING v2d FOR WANTED VARIABLE AND CHEKING ITS SIZE
+    SELECT CASE(varname)
+      CASE('psol');     v2d=>psol_dyn
+      CASE('relief');   v2d=>relief
+      CASE('rugosite'); v2d=>rugo
+      CASE('masque');   v2d=>masque
+      CASE('surfgeo');  v2d=>phis
+    END SELECT
+    IF(SIZE(champ)/=SIZE(v2d)) THEN
+      WRITE(lunout,*) 'STARTVAR module has been initialized to the wrong size'
+      STOP
+    END IF
+
+    champ(:,:)=v2d(:,:)
+
+  ELSE
+
+!--- SOME FIELDS ARE CAUGHT: MAY BE NEEDED FOR A 3D INTEPROLATION
+    SELECT CASE(varname)
+      CASE ('surfgeo')
+        IF(.NOT.ALLOCATED(phis)) ALLOCATE(phis(iml,jml))
+        IF(SIZE(phis)/=SIZE(champ)) THEN
+         WRITE(lunout,*)'STARTVAR module has been initialized to the wrong size'
+         STOP
+        END IF
+        phis(:,:)=champ(:,:)
+    END SELECT
+
+  END IF
+
+END SUBROUTINE startget_phys2d
+!
+!-------------------------------------------------------------------------------
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE startget_dyn(varname, iml, jml,  lon_in,  lat_in,  lml, pls,workvar,&
+                     champ, val_exp,  jml2, lon_in2, lat_in2, ibar)
+!-------------------------------------------------------------------------------
+! Comment:
+!   This routine only works if the variable does not exist or is constant.
+!-------------------------------------------------------------------------------
+! Arguments:
+  CHARACTER(LEN=*),             INTENT(IN)    :: varname
+  INTEGER,                      INTENT(IN)    :: iml, jml
+  REAL, DIMENSION(iml),         INTENT(IN)    :: lon_in
+  REAL, DIMENSION(jml),         INTENT(IN)    :: lat_in
+  INTEGER,                      INTENT(IN)    :: lml
+  REAL, DIMENSION(iml,jml,lml), INTENT(IN)    :: pls, workvar
+  REAL, DIMENSION(iml,jml,lml), INTENT(INOUT) :: champ
+  REAL,                         INTENT(IN)    :: val_exp
+  INTEGER,                      INTENT(IN)    :: jml2
+  REAL, DIMENSION(iml),         INTENT(IN)    :: lon_in2
+  REAL, DIMENSION(jml2),        INTENT(IN)    :: lat_in2
+  LOGICAL,                      INTENT(IN)    :: ibar
+!-------------------------------------------------------------------------------
+! Local variables:
+#include "iniprint.h"
+#include "dimensions.h"
+#include "comconst.h"
+#include "paramet.h"
+#include "comgeom2.h"
+  REAL, DIMENSION(:,:,:), POINTER :: v3d=>NULL()
+  CHARACTER(LEN=10) :: vname
+  INTEGER :: il
+  REAL    :: xppn, xpps
+!-------------------------------------------------------------------------------
+  NULLIFY(v3d)
+  IF(MINVAL(champ)==MAXVAL(champ).AND.MINVAL(champ)==val_exp) THEN
+
+!--- READING UNALLOCATED FILES
+    IF(.NOT.ALLOCATED(psol_dyn))                                               &
+      CALL start_init_dyn(iml,jml,lon_in,lat_in,jml2,lon_in2,lat_in2,ibar)
+
+!--- CHECKING IF THE FIELD IS KNOWN AND INTERPOLATING 3D FIELDS
+    SELECT CASE(varname)
+      CASE('u');        vname='U'
+      CASE('v');        vname='V'
+      CASE('t','tpot'); vname='TEMP'
+      CASE('q');        vname='R'
+      CASE DEFAULT
+        WRITE(lunout,*)'startget_dyn'
+        WRITE(lunout,*)'No rule is present to extract variable '//TRIM(varname)&
+                //' from any data set'; STOP
+    END SELECT
+    CALL start_inter_3d(TRIM(vname), iml, jml, lml, lon_in, lat_in, jml2,      &
+                        lon_in2, lat_in2,  pls, champ,ibar )
+
+!--- COMPUTING THE REQUIRED FILED
+    SELECT CASE(varname)
+      CASE('u')                                            !--- Eastward wind
+        DO il=1,lml; champ(:,:,il)=champ(:,:,il)*cu(:,1:jml); END DO
+        champ(iml,:,:)=champ(1,:,:)
+
+      CASE('v')                                            !--- Northward wind
+        DO il=1,lml; champ(:,:,il)=champ(:,:,il)*cv(:,1:jml); END DO
+        champ(iml,:,:)=champ(1,:,:)
+
+      CASE('tpot')                                         !--- Temperature
+        IF(MINVAL(workvar)/=MAXVAL(workvar)) THEN
+          champ=champ*cpp/workvar
+          DO il=1,lml
+            xppn = SUM(aire(:,1  )*champ(:,1  ,il))/apoln
+            xpps = SUM(aire(:,jml)*champ(:,jml,il))/apols
+            champ(:,1  ,il) = xppn
+            champ(:,jml,il) = xpps
+          END DO
+        ELSE
+          WRITE(lunout,*)'Could not compute potential temperature as the'
+          WRITE(lunout,*)'Exner function is missing or constant.'; STOP
+        END IF
+
+      CASE('q')                                            !--- Relat. humidity
+        IF(MINVAL(workvar)/=MAXVAL(workvar)) THEN
+          champ=0.01*champ*workvar
+          WHERE(champ<0.) champ=1.0E-10
+          DO il=1,lml
+            xppn = SUM(aire(:,1  )*champ(:,1  ,il))/apoln
+            xpps = SUM(aire(:,jml)*champ(:,jml,il))/apols
+            champ(:,1  ,il) = xppn
+            champ(:,jml,il) = xpps
+          END DO
+        ELSE
+          WRITE(lunout,*)'Could not compute specific humidity as the'
+          WRITE(lunout,*)'saturated humidity is missing or constant.'; STOP
+        END IF
+
+    END SELECT
+
+  END IF
+
+END SUBROUTINE startget_dyn
+!
+!-------------------------------------------------------------------------------
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE start_init_orog(iml,jml,lon_in,lat_in,masque_lu)
+!
+!-------------------------------------------------------------------------------
+! Arguments:
+  INTEGER,                  INTENT(IN)           :: iml, jml
+  REAL, DIMENSION(iml),     INTENT(IN)           :: lon_in
+  REAL, DIMENSION(jml),     INTENT(IN)           :: lat_in
+  REAL, DIMENSION(iml,jml), INTENT(IN), OPTIONAL :: masque_lu
+!-------------------------------------------------------------------------------
+! Local variables:
+#include "iniprint.h"
+  CHARACTER(LEN=25)     :: title
+  CHARACTER(LEN=120)    :: orofname
+  LOGICAL               :: check=.TRUE.
+  REAL,    DIMENSION(1) :: lev
+  REAL                  :: date, dt
+  INTEGER, DIMENSION(1) :: itau
+  INTEGER               :: fid, llm_tmp, ttm_tmp
+  REAL,    DIMENSION(:,:), ALLOCATABLE :: relief_hi, tmp_var
+  REAL,    DIMENSION(:),   ALLOCATABLE :: lon_rad, lat_rad, lon_ini, lat_ini
+!-------------------------------------------------------------------------------
+  pi=2.0*ASIN(1.0); deg2rad=pi/180.0
+
+  orofname = 'Relief.nc'; title='RELIEF'
+  IF(check) WRITE(lunout,*)'Reading the high resolution orography'
+  CALL flininfo(orofname, iml_rel, jml_rel, llm_tmp, ttm_tmp, fid)
+
+  ALLOCATE(lat_rel(iml_rel,jml_rel),lon_rel(iml_rel,jml_rel))
+  CALL flinopen(orofname, .FALSE., iml_rel, jml_rel, llm_tmp, lon_rel, lat_rel,&
+                lev, ttm_tmp, itau, date, dt, fid)
+  ALLOCATE(relief_hi(iml_rel,jml_rel))
+  CALL flinget(fid, title, iml_rel, jml_rel, llm_tmp, ttm_tmp, 1, 1, relief_hi)
+  CALL flinclo(fid)
+
+!--- IF ANGLES ARE IN DEGREES, THEY ARE CONVERTED INTO RADIANS
+  ALLOCATE(lon_ini(iml_rel),lat_ini(jml_rel))
+  lon_ini(:)=lon_rel(:,1); IF(MAXVAL(lon_rel)>pi) lon_ini=lon_ini*deg2rad
+  lat_ini(:)=lat_rel(1,:); IF(MAXVAL(lat_rel)>pi) lat_ini=lat_ini*deg2rad
+
+!--- FIELDS ARE PROCESSED TO BE ON STANDARD ANGULAR DOMAINS
+  ALLOCATE(lon_rad(iml_rel),lat_rad(jml_rel))
+  CALL conf_dat2d(title, iml_rel, jml_rel, lon_ini, lat_ini, lon_rad, lat_rad, &
+                  relief_hi, .FALSE.)
+  DEALLOCATE(lon_ini,lat_ini)
+
+!--- COMPUTING THE REQUIRED FIELDS USING ROUTINE grid_noro
+  IF(check) WRITE(lunout,*)'Computes all parameters needed for gravity wave dra&
+     &g code'
+
+  ALLOCATE(phis(iml,jml))      ! Geopotentiel au sol
+  ALLOCATE(zstd(iml,jml))      ! Deviation standard de l'orographie sous-maille
+  ALLOCATE(zsig(iml,jml))      ! Pente de l'orographie sous-maille 
+  ALLOCATE(zgam(iml,jml))      ! Anisotropie de l'orographie sous maille
+  ALLOCATE(zthe(iml,jml))      ! Orientation axe +grande pente d'oro sous maille
+  ALLOCATE(zpic(iml,jml))      ! Hauteur pics de la SSO
+  ALLOCATE(zval(iml,jml))      ! Hauteur vallees de la SSO
+  ALLOCATE(relief(iml,jml))    ! Orographie moyenne
+  ALLOCATE(masque(iml,jml))    ! Masque terre ocean
+  masque = -99999.
+  IF(PRESENT(masque_lu)) masque=masque_lu
+
+  CALL grid_noro(iml_rel, jml_rel, lon_rad, lat_rad, relief_hi, iml-1, jml,    &
+       lon_in, lat_in, phis, relief, zstd, zsig, zgam, zthe, zpic, zval, masque)
+  phis = phis * 9.81
+
+!--- SURFACE ROUGHNESS COMPUTATION (UNUSED FOR THE MOMENT !!! )
+  IF(check) WRITE(lunout,*)'Compute surface roughness induced by the orography'
+  ALLOCATE(rugo   (iml  ,jml))
+  ALLOCATE(tmp_var(iml-1,jml))
+  CALL rugsoro(iml_rel, jml_rel, lon_rad, lat_rad, relief_hi, iml-1, jml,      &
+       lon_in, lat_in, tmp_var)
+  rugo(1:iml-1,:)=tmp_var; rugo(iml,:)=tmp_var(1,:)
+  DEALLOCATE(relief_hi,tmp_var,lon_rad,lat_rad)
+  RETURN
+
+END SUBROUTINE start_init_orog
+!
+!-------------------------------------------------------------------------------
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE start_init_phys(iml,jml,lon_in,lat_in,jml2,lon_in2,lat_in2,ibar)
+!
+!-------------------------------------------------------------------------------
+! Arguments:
+  INTEGER,               INTENT(IN) :: iml, jml
+  REAL, DIMENSION(iml),  INTENT(IN) :: lon_in
+  REAL, DIMENSION(jml),  INTENT(IN) :: lat_in
+  INTEGER,               INTENT(IN) :: jml2
+  REAL, DIMENSION(iml),  INTENT(IN) :: lon_in2
+  REAL, DIMENSION(jml2), INTENT(IN) :: lat_in2
+  LOGICAL,               INTENT(IN) :: ibar
+!-------------------------------------------------------------------------------
+! Local variables:
+#include "iniprint.h"
+  CHARACTER(LEN=25)     :: title
+  CHARACTER(LEN=120)    :: physfname
+  LOGICAL               :: check=.TRUE.
+  REAL                  :: date, dt
+  INTEGER, DIMENSION(1) :: itau
+  INTEGER               :: llm_tmp, ttm_tmp
+  REAL,    DIMENSION(:,:), ALLOCATABLE :: var_ana
+  REAL,    DIMENSION(:),   ALLOCATABLE :: lon_rad, lat_rad, lon_ini, lat_ini
+  REAL,    DIMENSION(:),   ALLOCATABLE :: levphys_ini
+!-------------------------------------------------------------------------------
+  physfname = 'ECPHY.nc'; pi=2.0*ASIN(1.0); deg2rad=pi/180.0
+  IF(check) WRITE(lunout,*)'Opening the surface analysis'
+  CALL flininfo(physfname, iml_phys, jml_phys, llm_tmp, ttm_tmp, fid_phys)
+
+  ALLOCATE(lat_phys(iml_phys,jml_phys))
+  ALLOCATE(lon_phys(iml_phys,jml_phys))
+  ALLOCATE(levphys_ini(llm_tmp))
+  CALL flinopen(physfname, .FALSE., iml_phys, jml_phys, llm_tmp, lon_phys,     &
+                lat_phys, levphys_ini, ttm_tmp, itau, date, dt, fid_phys)
+  DEALLOCATE(levphys_ini)
+
+!--- IF ANGLES ARE IN DEGREES, THEY ARE CONVERTED INTO RADIANS
+  ALLOCATE(lon_ini(iml_phys),lat_ini(jml_phys))
+  lon_ini(:)=lon_phys(:,1); IF(MAXVAL(lon_phys)>pi) lon_ini=lon_ini*deg2rad
+  lat_ini(:)=lat_phys(1,:); IF(MAXVAL(lat_phys)>pi) lat_ini=lat_ini*deg2rad
+
+  ALLOCATE(var_ana(iml_phys,jml_phys),lon_rad(iml_phys),lat_rad(jml_phys))
+
+!--- SURFACE TEMPERATURE
+  title='ST'
+  ALLOCATE(tsol(iml,jml))
+  CALL flinget(fid_phys,title,iml_phys,jml_phys,llm_tmp,ttm_tmp,1,1,var_ana)
+  CALL conf_dat2d(title,iml_phys, jml_phys, lon_ini, lat_ini, lon_rad, lat_rad,&
+                  var_ana , ibar  )
+  CALL interp_startvar(title, ibar, .TRUE.,                                    &
+      iml_phys, jml_phys, lon_rad, lat_rad, var_ana, iml, jml, jml-1,          &
+      lon_in,   lat_in,   lon_in2, lat_in2, tsol)
+
+!--- SOIL MOISTURE
+  title='CDSW'
+  ALLOCATE(qsol(iml,jml))
+  CALL flinget(fid_phys,title,iml_phys,jml_phys,llm_tmp,ttm_tmp,1,1,var_ana)
+  CALL conf_dat2d(title,iml_phys, jml_phys, lon_ini, lat_ini, lon_rad, lat_rad,&
+                  var_ana, ibar  )
+  CALL interp_startvar(title, ibar, .TRUE.,                                    &
+      iml_phys, jml_phys, lon_rad, lat_rad, var_ana, iml, jml, jml-1,          &
+      lon_in,   lat_in,   lon_in2, lat_in2, qsol)
+
+  CALL flinclo(fid_phys)
+
+  DEALLOCATE(var_ana,lon_rad,lat_rad,lon_ini,lat_ini)
+
+END SUBROUTINE start_init_phys
+!
+!-------------------------------------------------------------------------------
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE start_init_dyn(iml,jml,lon_in,lat_in,jml2,lon_in2,lat_in2,ibar)
+!
+!-------------------------------------------------------------------------------
+! Arguments:
+  INTEGER,               INTENT(IN) :: iml, jml
+  REAL, DIMENSION(iml),  INTENT(IN) :: lon_in
+  REAL, DIMENSION(jml),  INTENT(IN) :: lat_in
+  INTEGER,               INTENT(IN) :: jml2
+  REAL, DIMENSION(iml),  INTENT(IN) :: lon_in2
+  REAL, DIMENSION(jml2), INTENT(IN) :: lat_in2
+  LOGICAL,               INTENT(IN) :: ibar
+!-------------------------------------------------------------------------------
+! Local variables:
+#include "iniprint.h"
+#include "dimensions.h"
+#include "paramet.h"
+#include "comgeom2.h"
+  CHARACTER(LEN=25)     :: title
+  CHARACTER(LEN=120)    :: physfname
+  LOGICAL               :: check=.TRUE.
+  REAL                  :: date, dt
+  INTEGER, DIMENSION(1) :: itau
+  INTEGER               :: i, j
+  REAL,    DIMENSION(:,:), ALLOCATABLE :: var_ana, z
+  REAL,    DIMENSION(:),   ALLOCATABLE :: lon_rad, lat_rad, lon_ini, lat_ini
+  REAL,    DIMENSION(:),   ALLOCATABLE :: xppn, xpps
+!-------------------------------------------------------------------------------
+
+!--- KINETIC ENERGY
+  physfname = 'ECDYN.nc'; pi=2.0*ASIN(1.0); deg2rad=pi/180.0
+  IF(check) WRITE(lunout,*) 'Opening the surface analysis'
+  CALL flininfo(physfname, iml_dyn, jml_dyn, llm_dyn, ttm_dyn, fid_dyn)
+  IF(check) WRITE(lunout,*) 'Values read: ', iml_dyn, jml_dyn, llm_dyn, ttm_dyn
+
+  ALLOCATE(lat_dyn(iml_dyn,jml_dyn))
+  ALLOCATE(lon_dyn(iml_dyn,jml_dyn))
+  ALLOCATE(levdyn_ini(llm_dyn))
+  CALL flinopen(physfname, .FALSE., iml_dyn, jml_dyn, llm_dyn, lon_dyn,lat_dyn,&
+                levdyn_ini, ttm_dyn, itau, date, dt, fid_dyn)
+
+!--- IF ANGLES ARE IN DEGREES, THEY ARE CONVERTED INTO RADIANS
+  ALLOCATE(lon_ini(iml_dyn),lat_ini(jml_dyn))
+  lon_ini(:)=lon_dyn(:,1); IF(MAXVAL(lon_dyn)>pi) lon_ini=lon_ini*deg2rad
+  lat_ini(:)=lat_dyn(1,:); IF(MAXVAL(lat_dyn)>pi) lat_ini=lat_ini*deg2rad
+
+  ALLOCATE(var_ana(iml_dyn,jml_dyn),lon_rad(iml_dyn),lat_rad(jml_dyn))
+
+!--- SURFACE GEOPOTENTIAL
+  title='Z'
+  ALLOCATE(z(iml,jml))
+  CALL flinget(fid_dyn, title, iml_dyn, jml_dyn, 0, ttm_dyn, 1, 1, var_ana)
+  CALL conf_dat2d(title, iml_dyn, jml_dyn, lon_ini, lat_ini, lon_rad, lat_rad, &
+                  var_ana, ibar)
+  CALL interp_startvar(title, ibar, .TRUE.,                                    &
+      iml_dyn, jml_dyn, lon_rad, lat_rad, var_ana, iml, jml, jml-1,            &
+      lon_in,  lat_in,  lon_in2, lat_in2, z)
+
+!--- SURFACE PRESSURE
+  title='SP'
+  ALLOCATE(psol_dyn(iml,jml))
+  CALL flinget(fid_dyn, title, iml_dyn, jml_dyn, 0, ttm_dyn, 1, 1, var_ana)
+  CALL conf_dat2d(title, iml_dyn, jml_dyn, lon_ini, lat_ini, lon_rad, lat_rad, &
+                  var_ana, ibar)
+  CALL interp_startvar(title, ibar, .TRUE.,                                    &
+      iml_dyn, jml_dyn, lon_rad, lat_rad, var_ana, iml, jml, jml-1,            &
+      lon_in,  lat_in,  lon_in2, lat_in2, psol_dyn)
+
+  DEALLOCATE(var_ana,lon_rad,lat_rad,lon_ini,lat_ini)
+
+!--- ALLOCATION OF VARIABLES CREATED IN OR COMING FROM RESTART FILE
+  IF(.NOT.ALLOCATED(tsol)) THEN
+    CALL start_init_phys(iml,jml,lon_in,lat_in,jml2,lon_in2,lat_in2,ibar)
+  ELSE
+    IF(SIZE(tsol)/=SIZE(psol_dyn)) THEN
+      WRITE(lunout,*)'start_init_dyn :'
+      WRITE(lunout,*)'The temperature field we have does not have the right size'
+      STOP
+    END IF
+  END IF
+
+  IF(.NOT.ALLOCATED(phis)) THEN
+    CALL start_init_orog(iml,jml,lon_in,lat_in)
+  ELSE
+    IF(SIZE(phis)/=SIZE(psol_dyn)) THEN
+      WRITE(lunout,*)'start_init_dyn :'
+      WRITE(lunout,*)'The orography field we have does not have the right size'
+      STOP
+    END IF
+  END IF
+
+!--- PSOL IS COMPUTED IN PASCALS
+  DO j = 1, jml
+    DO i = 1, iml-1
+      psol_dyn(i,j) = psol_dyn(i,j)*(1.0+(z(i,j)-phis(i,j))/287.0/tsol(i,j))
+    END DO
+    psol_dyn(iml,j) = psol_dyn(1,j)
+  END DO
+  DEALLOCATE(z)
+
+  ALLOCATE(xppn(iml-1),xpps(iml-1)) 
+  DO i = 1, iml-1
+    xppn(i) = aire( i,1) * psol_dyn( i,1)
+    xpps(i) = aire( i,jml) * psol_dyn( i,jml)
+  END DO
+  DO i = 1, iml
+    psol_dyn(i,1  ) = SUM(xppn)/apoln
+    psol_dyn(i,jml) = SUM(xpps)/apols
+  END DO
+  DEALLOCATE(xppn,xpps) 
+
+  RETURN
+
+END SUBROUTINE start_init_dyn
+!
+!-------------------------------------------------------------------------------
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE start_inter_3d(varname, iml, jml, lml, lon_in, lat_in, jml2,lon_in2,&
+                          lat_in2, pls_in, var3d, ibar)
+!
+!-------------------------------------------------------------------------------
+! Arguments:
+  CHARACTER(LEN=*),             INTENT(IN)    :: varname
+  INTEGER,                      INTENT(IN)    :: iml, jml, lml
+  REAL, DIMENSION(iml),         INTENT(IN)    :: lon_in
+  REAL, DIMENSION(jml),         INTENT(IN)    :: lat_in
+  INTEGER,                      INTENT(IN)    :: jml2
+  REAL, DIMENSION(iml),         INTENT(IN)    :: lon_in2
+  REAL, DIMENSION(jml2),        INTENT(IN)    :: lat_in2
+  REAL, DIMENSION(iml,jml,lml), INTENT(IN)    :: pls_in
+  REAL, DIMENSION(iml,jml,lml), INTENT(OUT)   :: var3d
+  LOGICAL,                      INTENT(IN)    :: ibar
+!-------------------------------------------------------------------------------
+! Local variables:
+#include "iniprint.h"
+  LOGICAL               :: check=.TRUE.
+  REAL                  :: bx, by, chmin, chmax
+  INTEGER               :: ii, ij, il
+  REAL,    DIMENSION(:,:,:), ALLOCATABLE :: var_tmp3d
+  REAL,    DIMENSION(:),     ALLOCATABLE :: lon_rad, lat_rad, lon_ini, lat_ini
+  REAL,    DIMENSION(:),     ALLOCATABLE :: lev_dyn, ax, ay, yder
+  INTEGER, DIMENSION(:),     ALLOCATABLE :: lind
+!-------------------------------------------------------------------------------
+  IF(check) WRITE(lunout,*)'Going into flinget to extract the 3D  field.'
+  IF(check) WRITE(lunout,*)fid_dyn, varname, iml_dyn, jml_dyn, llm_dyn, ttm_dyn
+  IF(check) WRITE(lunout,*)'Allocating space for interpolation',iml,jml,llm_dyn
+
+  IF(.NOT.ALLOCATED(var_ana3d)) ALLOCATE(var_ana3d(iml_dyn,jml_dyn,llm_dyn))
+  CALL flinget(fid_dyn,varname,iml_dyn,jml_dyn,llm_dyn,ttm_dyn,1,1,var_ana3d)
+
+!--- IF ANGLES ARE IN DEGREES, THEY ARE CONVERTED INTO RADIANS
+  ALLOCATE(lon_ini(iml_dyn),lat_ini(jml_dyn))
+  lon_ini(:)=lon_dyn(:,1); IF(MAXVAL(lon_dyn)>pi) lon_ini=lon_ini*deg2rad
+  lat_ini(:)=lat_dyn(1,:); IF(MAXVAL(lat_dyn)>pi) lat_ini=lat_ini*deg2rad
+
+!--- FIELDS ARE PROCESSED TO BE ON STANDARD ANGULAR DOMAINS
+  ALLOCATE(lon_rad(iml_dyn),lat_rad(jml_dyn),lev_dyn(llm_dyn))
+  CALL conf_dat3d (varname, iml_dyn, jml_dyn, llm_dyn, lon_ini, lat_ini,       &
+                   levdyn_ini, lon_rad, lat_rad, lev_dyn, var_ana3d, ibar)
+  DEALLOCATE(lon_ini,lat_ini)
+
+!--- COMPUTING THE REQUIRED FIELDS USING ROUTINE grid_noro
+  ALLOCATE(var_tmp3d(iml,jml,llm_dyn))
+  DO il=1,llm_dyn
+    CALL interp_startvar(varname, ibar, il==1,                                 &
+      iml_dyn, jml_dyn, lon_rad, lat_rad, var_ana3d(:,:,il), iml, jml, jml2,   &
+      lon_in,  lat_in,  lon_in2, lat_in2, var_tmp3d(:,:,il))
+  END DO
+  DEALLOCATE(lon_rad,lat_rad)
+
+  ALLOCATE(lind(llm_dyn))
+  DO il=1,llm_dyn
+    lind(il) = llm_dyn-il+1
+  END DO
+
+!--- VERTICAL INTERPOLATION IS PERFORMED FROM TOP OF ATMOSPHERE TO GROUND
+  ALLOCATE(ax(llm_dyn),ay(llm_dyn),yder(llm_dyn))
+  DO ij=1,jml
+    DO ii=1,iml-1
+      ax(:)=lev_dyn(lind(:)) 
+      ay(:)=var_tmp3d(ii,ij,lind(:))
+      CALL SPLINE(ax, ay, llm_dyn, 1.e30, 1.e30, yder)
+      DO il=1,lml
+        bx=pls_in(ii,ij,il)
+        CALL SPLINT(ax, ay, yder, llm_dyn, bx, by)
+        var3d(ii,ij,il) = by
+      END DO
+    END DO
+    var3d(iml,ij,:) = var3d(1,ij,:) 
+  END DO
+  DEALLOCATE(var_tmp3d,lev_dyn,ax,ay,yder,lind)
+
+  DO il=1,lml
+    CALL minmax(iml*jml,var3d(1,1,il),chmin,chmax)
+    WRITE(lunout,*)' '//TRIM(varname)//'  min max l ',il,chmin,chmax
+  END DO
+
+  RETURN
+
+END SUBROUTINE start_inter_3d
+!
+!-------------------------------------------------------------------------------
+
+
+!-------------------------------------------------------------------------------
+!
+SUBROUTINE interp_startvar(vname, ibar, ibeg, ii, jj,    lon,  lat,  vari,     &
+                                 i1, j1, j2, lon1, lat1, lon2, lat2, varo)
+!
+!-------------------------------------------------------------------------------
+! Arguments:
+  CHARACTER(LEN=*),       INTENT(IN)  :: vname
+  LOGICAL,                INTENT(IN)  :: ibar, ibeg
+  INTEGER,                INTENT(IN)  :: ii, jj
+  REAL, DIMENSION(ii),    INTENT(IN)  :: lon
+  REAL, DIMENSION(jj),    INTENT(IN)  :: lat
+  REAL, DIMENSION(ii,jj), INTENT(IN)  :: vari
+  INTEGER,                INTENT(IN)  :: i1, j1, j2
+  REAL, DIMENSION(i1),    INTENT(IN)  :: lon1
+  REAL, DIMENSION(j1),    INTENT(IN)  :: lat1
+  REAL, DIMENSION(i1),    INTENT(IN)  :: lon2
+  REAL, DIMENSION(j2),    INTENT(IN)  :: lat2
+  REAL, DIMENSION(i1,j1), INTENT(OUT) :: varo
+!-------------------------------------------------------------------------------
+! Local variables:
+#include "iniprint.h"
+  REAL, DIMENSION(i1-1,j1) :: vtmp
+!-------------------------------------------------------------------------------
+  IF(ibar) THEN
+    IF(ibeg) THEN
+      WRITE(lunout,*)                                                          &
+               '---------------------------------------------------------------'
+      WRITE(lunout,*)                                                          &
+ '$$$ Utilisation de l interpolation barycentrique  pour  '//TRIM(vname)//' $$$'
+      WRITE(lunout,*)                                                          &
+               '---------------------------------------------------------------'
+    END IF
+    CALL inter_barxy(ii, jj-1, lon, lat, vari, i1-1, j2, lon2, lat2, j1, vtmp)
+  ELSE
+    CALL grille_m   (ii, jj,   lon, lat, vari, i1-1, j1, lon1, lat1,     vtmp)
+  END IF
+  CALL gr_int_dyn(vtmp, varo, i1-1, j1)
+
+END SUBROUTINE interp_startvar
+!
+!-------------------------------------------------------------------------------
+
+#endif
+! of #ifdef CPP_EARTH
+
+END MODULE startvar
+!
+!*******************************************************************************
Index: LMDZ4/trunk/libf/phylmd/phyetat0.F
===================================================================
--- LMDZ4/trunk/libf/phylmd/phyetat0.F	(revision 1318)
+++ LMDZ4/trunk/libf/phylmd/phyetat0.F	(revision 1319)
@@ -228,4 +228,5 @@
      $          'coherente ', i, zmasq(i), pctsrf(i, is_ter)
      $          ,pctsrf(i, is_lic)
+            zmasq(i) = fractint(i)
         ENDIF 
       END DO 
@@ -237,4 +238,5 @@
      $          'coherente ', i, zmasq(i) , pctsrf(i, is_oce)
      $          ,pctsrf(i, is_sic)
+            zmasq(i) = fractint(i)
         ENDIF 
       END DO 
Index: LMDZ4/trunk/libf/phylmd/physiq.F
===================================================================
--- LMDZ4/trunk/libf/phylmd/physiq.F	(revision 1318)
+++ LMDZ4/trunk/libf/phylmd/physiq.F	(revision 1319)
@@ -2548,5 +2548,5 @@
 
 !   les ratqs sont une combinaison de ratqss et ratqsc
-       print*,'PHYLMD NOUVEAU TAU_RATQS ',tau_ratqs
+!       print*,'PHYLMD NOUVEAU TAU_RATQS ',tau_ratqs
 
          if (tau_ratqs>1.e-10) then
Index: LMDZ4/trunk/libf/phylmd/readaerosol.F90
===================================================================
--- LMDZ4/trunk/libf/phylmd/readaerosol.F90	(revision 1318)
+++ LMDZ4/trunk/libf/phylmd/readaerosol.F90	(revision 1319)
@@ -200,4 +200,5 @@
     REAL, DIMENSION(klon,12), INTENT(OUT) :: psurf_out    ! Surface pression for 12 months
     REAL, DIMENSION(klon,12), INTENT(OUT) :: load_out     ! Aerosol mass load in each column
+    INTEGER                               :: nbr_tsteps   ! number of month in file read
 
 ! Local variables
@@ -273,4 +274,15 @@
           CALL abort_gcm('get_aero_fromfile', 'latitudes do not correspond between file and model',1)
        END IF
+
+! 1.5) Check number of month in file opened
+!
+!**************************************************************************************************
+       ierr = nf90_inq_dimid(ncid, 'TIME',dimid)
+       CALL check_err( nf90_inquire_dimension(ncid, dimid, len = nbr_tsteps) )
+!       IF (nbr_tsteps /= 12 .AND. nbr_tsteps /= 14) THEN
+       IF (nbr_tsteps /= 12 ) THEN
+         CALL abort_gcm('get_aero_fromfile', 'not the right number of months in aerosol file read (should be 12 for the moment)',1)
+       ENDIF
+
 
 ! 2) Check if old or new file is avalabale.
