Index: LMDZ6/trunk/libf/dyn3d/guide_mod.F90
===================================================================
--- LMDZ6/trunk/libf/dyn3d/guide_mod.F90	(revision 3992)
+++ LMDZ6/trunk/libf/dyn3d/guide_mod.F90	(revision 3995)
@@ -9,8 +9,9 @@
 !=======================================================================
 
-  USE getparam
+  USE getparam, only: ini_getparam, fin_getparam, getpar
   USE Write_Field
-  use netcdf, only: nf90_nowrite, nf90_open, nf90_inq_varid, nf90_close
-  use pres2lev_mod
+  use netcdf, only: nf90_nowrite, nf90_open, nf90_inq_varid, nf90_close, &
+                    nf90_inq_dimid, nf90_inquire_dimension
+  use pres2lev_mod, only: pres2lev
 
   IMPLICIT NONE
@@ -20,10 +21,12 @@
 ! ---------------------------------------------
   INTEGER, PRIVATE, SAVE  :: iguide_read,iguide_int,iguide_sav
-  INTEGER, PRIVATE, SAVE  :: nlevnc
+  INTEGER, PRIVATE, SAVE  :: nlevnc, guide_plevs
   LOGICAL, PRIVATE, SAVE  :: guide_u,guide_v,guide_T,guide_Q,guide_P
   LOGICAL, PRIVATE, SAVE  :: guide_hr,guide_teta  
   LOGICAL, PRIVATE, SAVE  :: guide_BL,guide_reg,guide_add,gamma4,guide_zon 
-  LOGICAL, PRIVATE, SAVE  :: guide_modele,invert_p,invert_y,ini_anal
-  LOGICAL, PRIVATE, SAVE  :: guide_2D,guide_sav
+  LOGICAL, PRIVATE, SAVE  :: invert_p,invert_y,ini_anal
+  LOGICAL, PRIVATE, SAVE  :: guide_2D,guide_sav,guide_modele
+!FC
+  LOGICAL, PRIVATE, SAVE  :: convert_Pa
   
   REAL, PRIVATE, SAVE     :: tau_min_u,tau_max_u
@@ -49,4 +52,5 @@
   REAL, ALLOCATABLE, DIMENSION(:,:,:), PRIVATE, SAVE   :: tnat1,tnat2
   REAL, ALLOCATABLE, DIMENSION(:,:,:), PRIVATE, SAVE   :: qnat1,qnat2
+  REAL, ALLOCATABLE, DIMENSION(:,:,:), PRIVATE, SAVE   :: pnat1,pnat2
   REAL, ALLOCATABLE, DIMENSION(:,:),   PRIVATE, SAVE   :: psnat1,psnat2
   REAL, ALLOCATABLE, DIMENSION(:),     PRIVATE, SAVE   :: apnc,bpnc
@@ -75,4 +79,5 @@
     CHARACTER (len = 80)   :: abort_message
     CHARACTER (len = 20)   :: modname = 'guide_init'
+    CHARACTER (len = 20)   :: namedim
 
 ! ---------------------------------------------
@@ -140,5 +145,13 @@
         iguide_int=day_step*iguide_int
     ENDIF
-    CALL getpar('guide_modele',.false.,guide_modele,'guidage niveaux modele')
+    CALL getpar('guide_plevs',0,guide_plevs,'niveaux pression fichiers guidage')
+    ! Pour compatibilite avec ancienne version avec guide_modele
+    CALL getpar('guide_modele',.false.,guide_modele,'niveaux pression ap+bp*psol')
+    IF (guide_modele) THEN
+        guide_plevs=1
+    ENDIF
+!FC
+    CALL getpar('convert_Pa',.true.,convert_Pa,'Convert Pressure levels in Pa')
+    ! Fin raccord
     CALL getpar('ini_anal',.false.,ini_anal,'Etat initial = analyse')
     CALL getpar('guide_invertp',.true.,invert_p,'niveaux p inverses')
@@ -153,54 +166,64 @@
 ! ---------------------------------------------
     ncidpl=-99
-    if (guide_modele) then
+    if (guide_plevs.EQ.1) then
        if (ncidpl.eq.-99) then
           rcod=nf90_open('apbp.nc',Nf90_NOWRITe, ncidpl)
           if (rcod.NE.NF_NOERR) THEN
-             CALL abort_gcm(modname, &
-                  'Guide: probleme -> pas de fichier apbp.nc',1)
+             abort_message=' Nudging error -> no file apbp.nc'
+             CALL abort_gcm(modname,abort_message,1)
           endif
        endif
-    else
-         if (guide_u) then
+    elseif (guide_plevs.EQ.2) then
+       if (ncidpl.EQ.-99) then
+          rcod=nf90_open('P.nc',Nf90_NOWRITe,ncidpl)
+          if (rcod.NE.NF_NOERR) THEN
+             abort_message=' Nudging error -> no file P.nc'
+             CALL abort_gcm(modname,abort_message,1)
+          endif
+       endif
+
+    elseif (guide_u) then
            if (ncidpl.eq.-99) then
                rcod=nf90_open('u.nc',Nf90_NOWRITe,ncidpl)
                if (rcod.NE.NF_NOERR) THEN
                   CALL abort_gcm(modname, &
-                       'Guide: probleme -> pas de fichier u.nc',1)
+                       ' Nudging error -> no file u.nc',1)
                endif
            endif
-         elseif (guide_v) then
+
+    elseif (guide_v) then
            if (ncidpl.eq.-99) then
                rcod=nf90_open('v.nc',nf90_nowrite,ncidpl)
                if (rcod.NE.NF_NOERR) THEN
                   CALL abort_gcm(modname, &
-                       'Guide: probleme -> pas de fichier v.nc',1)
+                       ' Nudging error -> no file v.nc',1)
                endif
            endif
-         elseif (guide_T) then
+    elseif (guide_T) then
            if (ncidpl.eq.-99) then
                rcod=nf90_open('T.nc',nf90_nowrite,ncidpl)
                if (rcod.NE.NF_NOERR) THEN
                   CALL abort_gcm(modname, &
-                       'Guide: probleme -> pas de fichier T.nc',1)
+                       ' Nudging error -> no file T.nc',1)
                endif
            endif
-         elseif (guide_Q) then
+    elseif (guide_Q) then
            if (ncidpl.eq.-99) then
                rcod=nf90_open('hur.nc',nf90_nowrite, ncidpl)
                if (rcod.NE.NF_NOERR) THEN
                   CALL abort_gcm(modname, &
-                       'Guide: probleme -> pas de fichier hur.nc',1)
+                       ' Nudging error -> no file hur.nc',1)
                endif
            endif
-         endif
+
+
     endif 
     error=NF_INQ_DIMID(ncidpl,'LEVEL',rid)
     IF (error.NE.NF_NOERR) error=NF_INQ_DIMID(ncidpl,'PRESSURE',rid)
     IF (error.NE.NF_NOERR) THEN
-        CALL abort_gcm(modname,'Guide: probleme lecture niveaux pression',1)
+        CALL abort_gcm(modname,'Nudging: error reading pressure levels',1)
     ENDIF
     error=NF_INQ_DIMLEN(ncidpl,rid,nlevnc)
-    print *,'Guide: nombre niveaux vert. nlevnc', nlevnc 
+    write(*,*)trim(modname)//' : number of vertical levels nlevnc', nlevnc 
     rcod = nf90_close(ncidpl)
 
@@ -208,5 +231,5 @@
 ! Allocation des variables
 ! ---------------------------------------------
-    abort_message='pb in allocation guide'
+    abort_message='nudging allocation error'
 
     ALLOCATE(apnc(nlevnc), stat = error)
@@ -278,5 +301,13 @@
     ENDIF
 
-    IF (guide_P.OR.guide_modele) THEN
+    IF (guide_plevs.EQ.2) THEN
+        ALLOCATE(pnat1(iip1,jjp1,nlevnc), stat = error)
+        IF (error /= 0) CALL abort_gcm(modname,abort_message,1)
+        ALLOCATE(pnat2(iip1,jjp1,nlevnc), stat = error)
+        IF (error /= 0) CALL abort_gcm(modname,abort_message,1)
+        pnat1=0.;pnat2=0.;
+    ENDIF
+
+    IF (guide_P.OR.guide_plevs.EQ.1) THEN
         ALLOCATE(psnat1(iip1,jjp1), stat = error)
         IF (error /= 0) CALL abort_gcm(modname,abort_message,1)
@@ -305,5 +336,6 @@
     IF (guide_T) tnat1=tnat2
     IF (guide_Q) qnat1=qnat2
-    IF (guide_P.OR.guide_modele) psnat1=psnat2
+    IF (guide_plevs.EQ.2) pnat1=pnat2
+    IF (guide_P.OR.guide_plevs.EQ.1) psnat1=psnat2
 
   END SUBROUTINE guide_init
@@ -312,7 +344,9 @@
   SUBROUTINE guide_main(itau,ucov,vcov,teta,q,masse,ps)
 
+    USE exner_hyb_m, ONLY: exner_hyb
+    USE exner_milieu_m, ONLY: exner_milieu
     USE control_mod, ONLY: day_step, iperiod
-    USE comconst_mod, ONLY: dtvr, daysec
-    USE comvert_mod, ONLY: ap, bp, preff, presnivs
+    USE comconst_mod, ONLY: cpp, dtvr, daysec,kappa
+    USE comvert_mod, ONLY: ap, bp, preff, presnivs, pressure_exner
  
     IMPLICIT NONE
@@ -331,5 +365,8 @@
     LOGICAL       :: f_out ! sortie guidage
     REAL, DIMENSION (ip1jmp1,llm) :: f_add ! var aux: champ de guidage
-    REAL, DIMENSION (ip1jmp1,llm) :: p ! besoin si guide_P
+    REAL :: pk(ip1jmp1,llm) ! Exner at mid-layers
+    REAL :: pks(ip1jmp1) ! Exner at the surface
+    REAL :: unskap ! 1./kappa
+    REAL, DIMENSION (ip1jmp1,llmp1) :: p ! Pressure at inter-layers
     ! Compteurs temps:
     INTEGER, SAVE :: step_rea,count_no_rea,itau_test ! lecture guidage
@@ -339,4 +376,5 @@
     
     INTEGER       :: l
+    CHARACTER(LEN=20) :: modname="guide_main"
 
 !-----------------------------------------------------------------------
@@ -379,12 +417,12 @@
         ENDIF
 ! Verification structure guidage
-        IF (guide_u) THEN
-            CALL writefield('unat',unat1)
-            CALL writefield('ucov',RESHAPE(ucov,(/iip1,jjp1,llm/)))
-        ENDIF
-        IF (guide_T) THEN
-            CALL writefield('tnat',tnat1)
-            CALL writefield('teta',RESHAPE(teta,(/iip1,jjp1,llm/)))
-        ENDIF
+!        IF (guide_u) THEN
+!            CALL writefield('unat',unat1)
+!            CALL writefield('ucov',RESHAPE(ucov,(/iip1,jjp1,llm/)))
+!        ENDIF
+!        IF (guide_T) THEN
+!            CALL writefield('tnat',tnat1)
+!            CALL writefield('teta',RESHAPE(teta,(/iip1,jjp1,llm/)))
+!        ENDIF
 
     ENDIF !first
@@ -404,6 +442,7 @@
       IF (reste.EQ.0.) THEN
           IF (itau_test.EQ.itau) THEN
-              write(*,*)'deuxieme passage de advreel a itau=',itau
-              stop
+            write(*,*)trim(modname)//' second pass in advreel at itau=',&
+            itau
+            stop
           ELSE
               IF (guide_v) vnat1=vnat2
@@ -411,9 +450,10 @@
               IF (guide_T) tnat1=tnat2
               IF (guide_Q) qnat1=qnat2
-              IF (guide_P.OR.guide_modele) psnat1=psnat2
+              IF (guide_plevs.EQ.2) pnat1=pnat2
+              IF (guide_P.OR.guide_plevs.EQ.1) psnat1=psnat2
               step_rea=step_rea+1
               itau_test=itau
-              print*,'Lecture fichiers guidage, pas ',step_rea, &
-                    'apres ',count_no_rea,' non lectures'
+              write(*,*)trim(modname)//' Reading nudging files, step ',&
+                     step_rea,'after ',count_no_rea,' skips'
               IF (guide_2D) THEN
                   CALL guide_read2D(step_rea)
@@ -447,5 +487,19 @@
 ! Sauvegarde du guidage?
     f_out=((MOD(itau,iguide_sav).EQ.0).AND.guide_sav)  
-    IF (f_out) CALL guide_out("SP",jjp1,1,ps)
+    IF (f_out) THEN
+      ! compute pressures at layer interfaces
+      CALL pression(ip1jmp1,ap,bp,ps,p)
+      if (pressure_exner) then
+        call exner_hyb(ip1jmp1,ps,p,pks,pk)
+      else
+        call exner_milieu(ip1jmp1,ps,p,pks,pk)
+      endif
+      unskap=1./kappa
+      ! Now compute pressures at mid-layer
+      do l=1,llm
+        p(:,l)=preff*(pk(:,l)/cpp)**unskap
+      enddo
+      CALL guide_out("SP",jjp1,llm,p(:,1:llm))
+    ENDIF
     
     if (guide_u) then
@@ -483,5 +537,5 @@
         if (guide_zon) CALL guide_zonave(2,jjp1,1,f_add(1:ip1jmp1,1))
         CALL guide_addfield(ip1jmp1,1,f_add(1:ip1jmp1,1),alpha_P)
-        IF (f_out) CALL guide_out("ps",jjp1,1,f_add(1:ip1jmp1,1)/factt)
+!        IF (f_out) CALL guide_out("ps",jjp1,1,f_add(1:ip1jmp1,1)/factt)
         ps=ps+f_add(1:ip1jmp1,1)
         CALL pression(ip1jmp1,ap,bp,ps,p)
@@ -637,6 +691,7 @@
   
   INTEGER                            :: i,j,l,ij
+  CHARACTER(LEN=20),PARAMETER :: modname="guide_interp"
   
-    print *,'Guide: conversion variables guidage'
+    write(*,*)trim(modname)//': interpolate nudging variables'
 ! -----------------------------------------------------------------
 ! Calcul des niveaux de pression champs guidage
@@ -664,23 +719,23 @@
     if (first) then
         first=.FALSE.
-        print*,'Guide: verification ordre niveaux verticaux'
-        print*,'LMDZ :'
+        write(*,*)trim(modname)//' : check vertical level order'
+        write(*,*)trim(modname)//' LMDZ :'
         do l=1,llm
-            print*,'PL(',l,')=',(ap(l)+ap(l+1))/2. &
+          write(*,*)trim(modname)//' PL(',l,')=',(ap(l)+ap(l+1))/2. &
                   +psi(1,jjp1)*(bp(l)+bp(l+1))/2.
         enddo
-        print*,'Fichiers guidage'
+        write(*,*)trim(modname)//' nudging file :'
         do l=1,nlevnc
-             print*,'PL(',l,')=',plnc2(1,1,l)
+          write(*,*)trim(modname)//' PL(',l,')=',plnc2(1,1,l)
         enddo
-        print *,'inversion de l''ordre: invert_p=',invert_p
+        write(*,*)trim(modname)//' invert ordering: invert_p=',invert_p
         if (guide_u) then
             do l=1,nlevnc
-                print*,'U(',l,')=',unat2(1,1,l)
+              write(*,*)trim(modname)//' U(',l,')=',unat2(1,1,l)
             enddo
         endif
         if (guide_T) then
             do l=1,nlevnc
-                print*,'T(',l,')=',tnat2(1,1,l)
+              write(*,*)trim(modname)//' T(',l,')=',tnat2(1,1,l)
             enddo
         endif
@@ -881,4 +936,5 @@
     real alphamin,alphamax,xi
     integer i,j,ilon,ilat
+    character(len=20),parameter :: modname="tau2alpha"
 
 
@@ -969,19 +1025,19 @@
             ! Calcul de gamma
             if (abs(grossismx-1.).lt.0.1.or.abs(grossismy-1.).lt.0.1) then
-                 print*,'ATTENTION modele peu zoome'
-                 print*,'ATTENTION on prend une constante de guidage cste'
-                 gamma=0.
+              write(*,*)trim(modname)//' ATTENTION modele peu zoome'
+              write(*,*)trim(modname)//' ATTENTION on prend une constante de guidage cste'
+              gamma=0.
             else
-                gamma=(dxdy_max-2.*dxdy_min)/(dxdy_max-dxdy_min)
-                print*,'gamma=',gamma
-                if (gamma.lt.1.e-5) then
-                  print*,'gamma =',gamma,'<1e-5'
-                  stop
-                endif
-                gamma=log(0.5)/log(gamma)
-                if (gamma4) then 
-                  gamma=min(gamma,4.)
-                endif
-                print*,'gamma=',gamma
+              gamma=(dxdy_max-2.*dxdy_min)/(dxdy_max-dxdy_min)
+              write(*,*)trim(modname)//' gamma=',gamma
+              if (gamma.lt.1.e-5) then
+                write(*,*)trim(modname)//' gamma =',gamma,'<1e-5'
+                stop
+              endif
+              gamma=log(0.5)/log(gamma)
+              if (gamma4) then 
+                gamma=min(gamma,4.)
+              endif
+              write(*,*)trim(modname)//' gamma=',gamma
             endif
         ENDIF !first
@@ -1024,7 +1080,7 @@
     IMPLICIT NONE
 
-#include "netcdf.inc"
-#include "dimensions.h"
-#include "paramet.h"
+    include "netcdf.inc"
+    include "dimensions.h"
+    include "paramet.h"
 
     INTEGER, INTENT(IN)   :: timestep
@@ -1032,13 +1088,14 @@
     LOGICAL, SAVE         :: first=.TRUE.
 ! Identification fichiers et variables NetCDF:
-    INTEGER, SAVE         :: ncidu,varidu,ncidv,varidv,ncidQ
-    INTEGER, SAVE         :: varidQ,ncidt,varidt,ncidps,varidps
-    INTEGER               :: ncidpl,varidpl,varidap,varidbp
+    INTEGER, SAVE         :: ncidu,varidu,ncidv,varidv,ncidp,varidp
+    INTEGER, SAVE         :: ncidQ,varidQ,ncidt,varidt,ncidps,varidps
+    INTEGER               :: ncidpl,varidpl,varidap,varidbp,dimid,lendim
 ! Variables auxiliaires NetCDF:
     INTEGER, DIMENSION(4) :: start,count
     INTEGER               :: status,rcode
-
     CHARACTER (len = 80)   :: abort_message
     CHARACTER (len = 20)   :: modname = 'guide_read'
+    CHARACTER (len = 20)   :: namedim
+
 ! -----------------------------------------------------------------
 ! Premier appel: initialisation de la lecture des fichiers
@@ -1046,107 +1103,190 @@
     if (first) then
          ncidpl=-99
-         print*,'Guide: ouverture des fichiers guidage '
+         write(*,*),trim(modname)//': opening nudging files '
 ! Niveaux de pression si non constants
-         if (guide_modele) then
-             print *,'Lecture du guidage sur niveaux modele'
+         if (guide_plevs.EQ.1) then
+             write(*,*),trim(modname)//' Reading nudging on model levels'
              rcode = nf90_open('apbp.nc', nf90_nowrite, ncidpl)
              IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de fichier apbp.nc'
+              abort_message='Nudging: error -> no file apbp.nc'
               CALL abort_gcm(modname,abort_message,1)
              ENDIF
              rcode = nf90_inq_varid(ncidpl, 'AP', varidap)
              IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de variable AP, fichier apbp.nc'
+              abort_message='Nudging: error -> no AP variable in file apbp.nc'
               CALL abort_gcm(modname,abort_message,1)
              ENDIF
              rcode = nf90_inq_varid(ncidpl, 'BP', varidbp)
              IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de variable BP, fichier apbp.nc'
+              abort_message='Nudging: error -> no BP variable in file apbp.nc'
               CALL abort_gcm(modname,abort_message,1)
              ENDIF
-             print*,'ncidpl,varidap',ncidpl,varidap
+             write(*,*),trim(modname)//' ncidpl,varidap',ncidpl,varidap
          endif
+
+! Pression si guidage sur niveaux P variables
+         if (guide_plevs.EQ.2) then
+             rcode = nf90_open('P.nc', nf90_nowrite, ncidp)
+             IF (rcode.NE.NF_NOERR) THEN
+              abort_message='Nudging: error -> no file P.nc'
+              CALL abort_gcm(modname,abort_message,1)
+             ENDIF
+             rcode = nf90_inq_varid(ncidp, 'PRES', varidp)
+             IF (rcode.NE.NF_NOERR) THEN 
+              abort_message='Nudging: error -> no PRES variable in file P.nc'
+              CALL abort_gcm(modname,abort_message,1)
+             ENDIF
+             write(*,*),trim(modname)//' ncidp,varidp',ncidp,varidp
+             if (ncidpl.eq.-99) ncidpl=ncidp
+         endif
+
 ! Vent zonal
          if (guide_u) then
              rcode = nf90_open('u.nc', nf90_nowrite, ncidu)
              IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de fichier u.nc'
+              abort_message='Nudging: error -> no file u.nc'
               CALL abort_gcm(modname,abort_message,1)
              ENDIF
              rcode = nf90_inq_varid(ncidu, 'UWND', varidu)
              IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de variable UWND, fichier u.nc'
+              abort_message='Nudging: error -> no UWND variable in file u.nc'
               CALL abort_gcm(modname,abort_message,1)
              ENDIF
-             print*,'ncidu,varidu',ncidu,varidu
+             write(*,*),trim(modname)//' ncidu,varidu',ncidu,varidu
              if (ncidpl.eq.-99) ncidpl=ncidu
+
+             status=NF90_INQ_DIMID(ncidu, "LONU", dimid)
+             status=NF90_INQUIRE_DIMENSION(ncidu,dimid,namedim,lendim)
+             IF (lendim .NE. iip1) THEN
+                abort_message='dimension LONU different from iip1 in u.nc'
+                CALL abort_gcm(modname,abort_message,1)
+             ENDIF
+
+             status=NF90_INQ_DIMID(ncidu, "LATU", dimid)
+             status=NF90_INQUIRE_DIMENSION(ncidu,dimid,namedim,lendim)
+             IF (lendim .NE. jjp1) THEN
+                abort_message='dimension LATU different from jjp1 in u.nc'
+                CALL abort_gcm(modname,abort_message,1)
+             ENDIF
+
          endif
+
 ! Vent meridien
          if (guide_v) then
              rcode = nf90_open('v.nc', nf90_nowrite, ncidv)
              IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de fichier v.nc'
+              abort_message='Nudging: error -> no file v.nc'
               CALL abort_gcm(modname,abort_message,1)
              ENDIF
              rcode = nf90_inq_varid(ncidv, 'VWND', varidv)
              IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de variable VWND, fichier v.nc'
+              abort_message='Nudging: error -> no VWND variable in file v.nc'
               CALL abort_gcm(modname,abort_message,1)
              ENDIF
-             print*,'ncidv,varidv',ncidv,varidv
+             write(*,*),trim(modname)//' ncidv,varidv',ncidv,varidv
              if (ncidpl.eq.-99) ncidpl=ncidv
+             
+             status=NF90_INQ_DIMID(ncidv, "LONV", dimid)
+             status=NF90_INQUIRE_DIMENSION(ncidv,dimid,namedim,lendim)
+             
+                IF (lendim .NE. iip1) THEN
+                abort_message='dimension LONV different from iip1 in v.nc'
+                CALL abort_gcm(modname,abort_message,1)
+             ENDIF
+
+
+             status=NF90_INQ_DIMID(ncidv, "LATV", dimid)
+             status=NF90_INQUIRE_DIMENSION(ncidv,dimid,namedim,lendim)
+             IF (lendim .NE. jjm) THEN
+                abort_message='dimension LATV different from jjm in v.nc'
+                CALL abort_gcm(modname,abort_message,1)
+             ENDIF
+        
          endif
+
 ! Temperature
          if (guide_T) then
              rcode = nf90_open('T.nc', nf90_nowrite, ncidt)
              IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de fichier T.nc'
+              abort_message='Nudging: error -> no file T.nc'
               CALL abort_gcm(modname,abort_message,1)
              ENDIF
              rcode = nf90_inq_varid(ncidt, 'AIR', varidt)
              IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de variable AIR, fichier T.nc'
+              abort_message='Nudging: error -> no AIR variable in file T.nc'
               CALL abort_gcm(modname,abort_message,1)
              ENDIF
-             print*,'ncidT,varidT',ncidt,varidt
+             write(*,*),trim(modname)//' ncidT,varidT',ncidt,varidt
              if (ncidpl.eq.-99) ncidpl=ncidt
+
+             status=NF90_INQ_DIMID(ncidt, "LONV", dimid)
+             status=NF90_INQUIRE_DIMENSION(ncidt,dimid,namedim,lendim)
+             IF (lendim .NE. iip1) THEN
+                abort_message='dimension LONV different from iip1 in T.nc'
+                CALL abort_gcm(modname,abort_message,1)
+             ENDIF
+
+             status=NF90_INQ_DIMID(ncidt, "LATU", dimid)
+             status=NF90_INQUIRE_DIMENSION(ncidt,dimid,namedim,lendim)
+             IF (lendim .NE. jjp1) THEN
+                abort_message='dimension LATU different from jjp1 in T.nc'
+                CALL abort_gcm(modname,abort_message,1)
+             ENDIF
+
          endif
+
 ! Humidite
          if (guide_Q) then
              rcode = nf90_open('hur.nc', nf90_nowrite, ncidQ)
              IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de fichier hur.nc'
+              abort_message='Nudging: error -> no file hur.nc'
               CALL abort_gcm(modname,abort_message,1)
              ENDIF
              rcode = nf90_inq_varid(ncidQ, 'RH', varidQ)
              IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de variable RH, fichier hur.nc'
+              abort_message='Nudging: error -> no RH variable in file hur.nc'
               CALL abort_gcm(modname,abort_message,1)
              ENDIF
-             print*,'ncidQ,varidQ',ncidQ,varidQ
+             write(*,*),trim(modname)//' ncidQ,varidQ',ncidQ,varidQ
              if (ncidpl.eq.-99) ncidpl=ncidQ
+
+             status=NF90_INQ_DIMID(ncidQ, "LONV", dimid)
+             status=NF90_INQUIRE_DIMENSION(ncidQ,dimid,namedim,lendim)
+             IF (lendim .NE. iip1) THEN
+                abort_message='dimension LONV different from iip1 in hur.nc'
+                CALL abort_gcm(modname,abort_message,1)
+             ENDIF
+
+             status=NF90_INQ_DIMID(ncidQ, "LATU", dimid)
+             status=NF90_INQUIRE_DIMENSION(ncidQ,dimid,namedim,lendim)
+             IF (lendim .NE. jjp1) THEN
+                abort_message='dimension LATU different from jjp1 in hur.nc'
+                CALL abort_gcm(modname,abort_message,1)
+             ENDIF
+
          endif
+
 ! Pression de surface
          if ((guide_P).OR.(guide_modele)) then
              rcode = nf90_open('ps.nc', nf90_nowrite, ncidps)
              IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de fichier ps.nc'
+              abort_message='Nudging: error -> no file ps.nc'
               CALL abort_gcm(modname,abort_message,1)
              ENDIF
              rcode = nf90_inq_varid(ncidps, 'SP', varidps)
              IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de variable SP, fichier ps.nc'
+              abort_message='Nudging: error -> no SP variable in file ps.nc'
               CALL abort_gcm(modname,abort_message,1)
              ENDIF
-             print*,'ncidps,varidps',ncidps,varidps
+             write(*,*),trim(modname)//' ncidps,varidps',ncidps,varidps
          endif
 ! Coordonnee verticale
-         if (.not.guide_modele) then
+         if (guide_plevs.EQ.0) then
               rcode = nf90_inq_varid(ncidpl, 'LEVEL', varidpl)
               IF (rcode.NE.0) rcode = nf90_inq_varid(ncidpl, 'PRESSURE', varidpl)
-              print*,'ncidpl,varidpl',ncidpl,varidpl
+              write(*,*),trim(modname)//' ncidpl,varidpl',ncidpl,varidpl
          endif
 ! Coefs ap, bp pour calcul de la pression aux differents niveaux
-         if (guide_modele) then
+         if (guide_plevs.EQ.1) then
 #ifdef NC_DOUBLE
              status=NF_GET_VARA_DOUBLE(ncidpl,varidap,1,nlevnc,apnc)
@@ -1156,5 +1296,5 @@
              status=NF_GET_VARA_REAL(ncidpl,varidbp,1,nlevnc,bpnc)
 #endif
-         else
+         ELSEIF (guide_plevs.EQ.0) THEN
 #ifdef NC_DOUBLE
              status=NF_GET_VARA_DOUBLE(ncidpl,varidpl,1,nlevnc,apnc)
@@ -1162,5 +1302,6 @@
              status=NF_GET_VARA_REAL(ncidpl,varidpl,1,nlevnc,apnc)
 #endif
-             apnc=apnc*100.! conversion en Pascals
+!FC Pour les corrections la pression est deja en Pascals on commente la ligne ci-dessous
+             IF(convert_Pa) apnc=apnc*100.! conversion en Pascals
              bpnc(:)=0.
          endif
@@ -1182,4 +1323,18 @@
      count(3)=nlevnc
      count(4)=1
+
+! Pression 
+     if (guide_plevs.EQ.2) then
+#ifdef NC_DOUBLE
+         status=NF_GET_VARA_DOUBLE(ncidp,varidp,start,count,pnat2)
+#else
+         status=NF_GET_VARA_REAL(ncidp,varidp,start,count,pnat2)
+#endif
+         IF (invert_y) THEN
+!           PRINT*,"Invertion impossible actuellement"
+!           CALL abort_gcm(modname,abort_message,1)
+           CALL invert_lat(iip1,jjp1,nlevnc,pnat2)
+         ENDIF
+     endif
 
 !  Vent zonal
@@ -1257,7 +1412,7 @@
     IMPLICIT NONE
 
-#include "netcdf.inc"
-#include "dimensions.h"
-#include "paramet.h"
+    include "netcdf.inc"
+    include "dimensions.h"
+    include "paramet.h"
 
     INTEGER, INTENT(IN)   :: timestep
@@ -1265,6 +1420,6 @@
     LOGICAL, SAVE         :: first=.TRUE.
 ! Identification fichiers et variables NetCDF:
-    INTEGER, SAVE         :: ncidu,varidu,ncidv,varidv,ncidQ
-    INTEGER, SAVE         :: varidQ,ncidt,varidt,ncidps,varidps
+    INTEGER, SAVE         :: ncidu,varidu,ncidv,varidv,ncidp,varidp
+    INTEGER, SAVE         :: ncidQ,varidQ,ncidt,varidt,ncidps,varidps
     INTEGER               :: ncidpl,varidpl,varidap,varidbp
 ! Variables auxiliaires NetCDF:
@@ -1283,107 +1438,122 @@
     if (first) then
          ncidpl=-99
-         print*,'Guide: ouverture des fichiers guidage '
-! Niveaux de pression si non constants
-         if (guide_modele) then
-             print *,'Lecture du guidage sur niveaux modele'
-             rcode = nf90_open('apbp.nc', nf90_nowrite, ncidpl)
-             IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de fichier apbp.nc'
-              CALL abort_gcm(modname,abort_message,1)
-             ENDIF
-             rcode = nf90_inq_varid(ncidpl, 'AP', varidap)
-             IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de variable AP, fichier apbp.nc'
-              CALL abort_gcm(modname,abort_message,1)
-             ENDIF
-             rcode = nf90_inq_varid(ncidpl, 'BP', varidbp)
-             IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de variable BP, fichier apbp.nc'
-              CALL abort_gcm(modname,abort_message,1)
-             ENDIF
-             print*,'ncidpl,varidap',ncidpl,varidap
+         write(*,*)trim(modname)//' : opening nudging files '
+! Ap et Bp si niveaux de pression hybrides
+         if (guide_plevs.EQ.1) then
+           write(*,*)trim(modname)//' Reading nudging on model levels'
+           rcode = nf90_open('apbp.nc', nf90_nowrite, ncidpl)
+           IF (rcode.NE.NF_NOERR) THEN
+             abort_message='Nudging: error -> no file apbp.nc'
+           CALL abort_gcm(modname,abort_message,1)
+           ENDIF
+           rcode = nf90_inq_varid(ncidpl, 'AP', varidap)
+           IF (rcode.NE.NF_NOERR) THEN
+             abort_message='Nudging: error -> no AP variable in file apbp.nc'
+           CALL abort_gcm(modname,abort_message,1)
+           ENDIF
+           rcode = nf90_inq_varid(ncidpl, 'BP', varidbp)
+           IF (rcode.NE.NF_NOERR) THEN
+             abort_message='Nudging: error -> no BP variable in file apbp.nc'
+             CALL abort_gcm(modname,abort_message,1)
+           ENDIF
+           write(*,*)trim(modname)//'ncidpl,varidap',ncidpl,varidap
+         endif
+! Pression
+         if (guide_plevs.EQ.2) then
+           rcode = nf90_open('P.nc', nf90_nowrite, ncidp)
+           IF (rcode.NE.NF_NOERR) THEN
+             abort_message='Nudging: error -> no file P.nc'
+             CALL abort_gcm(modname,abort_message,1)
+           ENDIF
+           rcode = nf90_inq_varid(ncidp, 'PRES', varidp)
+           IF (rcode.NE.NF_NOERR) THEN
+             abort_message='Nudging: error -> no PRES variable in file P.nc'
+             CALL abort_gcm(modname,abort_message,1)
+           ENDIF
+           write(*,*)trim(modname)//' ncidp,varidp',ncidp,varidp
+           if (ncidpl.eq.-99) ncidpl=ncidp
          endif
 ! Vent zonal
          if (guide_u) then
-             rcode = nf90_open('u.nc', nf90_nowrite, ncidu)
-             IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de fichier u.nc'
-              CALL abort_gcm(modname,abort_message,1)
-             ENDIF
-             rcode = nf90_inq_varid(ncidu, 'UWND', varidu)
-             IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de variable UWND, fichier u.nc'
-              CALL abort_gcm(modname,abort_message,1)
-             ENDIF
-             print*,'ncidu,varidu',ncidu,varidu
-             if (ncidpl.eq.-99) ncidpl=ncidu
+           rcode = nf90_open('u.nc', nf90_nowrite, ncidu)
+           IF (rcode.NE.NF_NOERR) THEN
+             abort_message='Nudging: error -> no file u.nc'
+             CALL abort_gcm(modname,abort_message,1)
+           ENDIF
+           rcode = nf90_inq_varid(ncidu, 'UWND', varidu)
+           IF (rcode.NE.NF_NOERR) THEN
+             abort_message='Nudging: error -> no UWND variable in file u.nc'
+             CALL abort_gcm(modname,abort_message,1)
+           ENDIF
+           write(*,*)trim(modname)//' ncidu,varidu',ncidu,varidu
+           if (ncidpl.eq.-99) ncidpl=ncidu
          endif
 ! Vent meridien
          if (guide_v) then
-             rcode = nf90_open('v.nc', nf90_nowrite, ncidv)
-             IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de fichier v.nc'
-              CALL abort_gcm(modname,abort_message,1)
-             ENDIF
-             rcode = nf90_inq_varid(ncidv, 'VWND', varidv)
-             IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de variable VWND, fichier v.nc'
-              CALL abort_gcm(modname,abort_message,1)
-             ENDIF
-             print*,'ncidv,varidv',ncidv,varidv
-             if (ncidpl.eq.-99) ncidpl=ncidv
+           rcode = nf90_open('v.nc', nf90_nowrite, ncidv)
+           IF (rcode.NE.NF_NOERR) THEN
+             abort_message='Nudging: error -> no file v.nc'
+             CALL abort_gcm(modname,abort_message,1)
+           ENDIF
+           rcode = nf90_inq_varid(ncidv, 'VWND', varidv)
+           IF (rcode.NE.NF_NOERR) THEN
+             abort_message='Nudging: error -> no VWND variable in file v.nc'
+             CALL abort_gcm(modname,abort_message,1)
+           ENDIF
+           write(*,*)trim(modname)//' ncidv,varidv',ncidv,varidv
+           if (ncidpl.eq.-99) ncidpl=ncidv
          endif
 ! Temperature
          if (guide_T) then
-             rcode = nf90_open('T.nc', nf90_nowrite, ncidt)
-             IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de fichier T.nc'
-              CALL abort_gcm(modname,abort_message,1)
-             ENDIF
-             rcode = nf90_inq_varid(ncidt, 'AIR', varidt)
-             IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de variable AIR, fichier T.nc'
-              CALL abort_gcm(modname,abort_message,1)
-             ENDIF
-             print*,'ncidT,varidT',ncidt,varidt
-             if (ncidpl.eq.-99) ncidpl=ncidt
+           rcode = nf90_open('T.nc', nf90_nowrite, ncidt)
+           IF (rcode.NE.NF_NOERR) THEN
+             abort_message='Nudging: error -> no file T.nc'
+             CALL abort_gcm(modname,abort_message,1)
+           ENDIF
+           rcode = nf90_inq_varid(ncidt, 'AIR', varidt)
+           IF (rcode.NE.NF_NOERR) THEN
+             abort_message='Nudging: error -> no AIR variable in file T.nc'
+             CALL abort_gcm(modname,abort_message,1)
+           ENDIF
+           write(*,*)trim(modname)//' ncidT,varidT',ncidt,varidt
+           if (ncidpl.eq.-99) ncidpl=ncidt
          endif
 ! Humidite
          if (guide_Q) then
-             rcode = nf90_open('hur.nc', nf90_nowrite, ncidQ)
-             IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de fichier hur.nc'
-              CALL abort_gcm(modname,abort_message,1)
-             ENDIF
-             rcode = nf90_inq_varid(ncidQ, 'RH', varidQ)
-             IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de variable RH, fichier hur.nc'
-              CALL abort_gcm(modname,abort_message,1)
-             ENDIF
-             print*,'ncidQ,varidQ',ncidQ,varidQ
-             if (ncidpl.eq.-99) ncidpl=ncidQ
+           rcode = nf90_open('hur.nc', nf90_nowrite, ncidQ)
+           IF (rcode.NE.NF_NOERR) THEN
+             abort_message='Nudging: error -> no file hur.nc'
+             CALL abort_gcm(modname,abort_message,1)
+           ENDIF
+           rcode = nf90_inq_varid(ncidQ, 'RH', varidQ)
+           IF (rcode.NE.NF_NOERR) THEN
+             abort_message='Nudging: error -> no RH,variable in file hur.nc'
+             CALL abort_gcm(modname,abort_message,1)
+           ENDIF
+           write(*,*)trim(modname)//' ncidQ,varidQ',ncidQ,varidQ
+           if (ncidpl.eq.-99) ncidpl=ncidQ
          endif
 ! Pression de surface
          if ((guide_P).OR.(guide_modele)) then
-             rcode = nf90_open('ps.nc', nf90_nowrite, ncidps)
-             IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de fichier ps.nc'
-              CALL abort_gcm(modname,abort_message,1)
-             ENDIF
-             rcode = nf90_inq_varid(ncidps, 'SP', varidps)
-             IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de variable SP, fichier ps.nc'
-              CALL abort_gcm(modname,abort_message,1)
-             ENDIF
-             print*,'ncidps,varidps',ncidps,varidps
+           rcode = nf90_open('ps.nc', nf90_nowrite, ncidps)
+           IF (rcode.NE.NF_NOERR) THEN
+             abort_message='Nudging: error -> no file ps.nc'
+             CALL abort_gcm(modname,abort_message,1)
+           ENDIF
+           rcode = nf90_inq_varid(ncidps, 'SP', varidps)
+           IF (rcode.NE.NF_NOERR) THEN
+             abort_message='Nudging: error -> no SP variable in file ps.nc'
+             CALL abort_gcm(modname,abort_message,1)
+           ENDIF
+           write(*,*)trim(modname)//' ncidps,varidps',ncidps,varidps
          endif
 ! Coordonnee verticale
-         if (.not.guide_modele) then
-              rcode = nf90_inq_varid(ncidpl, 'LEVEL', varidpl)
-              IF (rcode.NE.0) rcode = nf90_inq_varid(ncidpl, 'PRESSURE', varidpl)
-              print*,'ncidpl,varidpl',ncidpl,varidpl
+         if (guide_plevs.EQ.0) then
+           rcode = nf90_inq_varid(ncidpl, 'LEVEL', varidpl)
+           IF (rcode.NE.0) rcode = nf90_inq_varid(ncidpl, 'PRESSURE', varidpl)
+           write(*,*)trim(modname)//' ncidpl,varidpl',ncidpl,varidpl
          endif
 ! Coefs ap, bp pour calcul de la pression aux differents niveaux
-         if (guide_modele) then
+         if (guide_plevs.EQ.1) then
 #ifdef NC_DOUBLE
              status=NF_GET_VARA_DOUBLE(ncidpl,varidap,1,nlevnc,apnc)
@@ -1393,5 +1563,5 @@
              status=NF_GET_VARA_REAL(ncidpl,varidbp,1,nlevnc,bpnc)
 #endif
-         else
+         elseif (guide_plevs.EQ.0) THEN
 #ifdef NC_DOUBLE
              status=NF_GET_VARA_DOUBLE(ncidpl,varidpl,1,nlevnc,apnc)
@@ -1420,4 +1590,21 @@
      count(4)=1
 
+!  Pression
+     if (guide_plevs.EQ.2) then
+#ifdef NC_DOUBLE
+         status=NF_GET_VARA_DOUBLE(ncidp,varidp,start,count,zu)
+#else
+         status=NF_GET_VARA_REAL(ncidp,varidp,start,count,zu)
+#endif
+         DO i=1,iip1
+             pnat2(i,:,:)=zu(:,:)
+         ENDDO
+
+         IF (invert_y) THEN
+!           PRINT*,"Invertion impossible actuellement"
+!           CALL abort_gcm(modname,abort_message,1)
+           CALL invert_lat(iip1,jjp1,nlevnc,pnat2)
+         ENDIF
+     endif
 !  Vent zonal
      if (guide_u) then
@@ -1490,5 +1677,5 @@
 
 !  Pression de surface
-     if ((guide_P).OR.(guide_modele))  then
+     if ((guide_P).OR.(guide_plevs.EQ.1))  then
          start(3)=timestep
          start(4)=0
@@ -1543,6 +1730,7 @@
     INTEGER                :: ierr, varid,l
     REAL, DIMENSION (iip1,hsize,vsize) :: field2
-
-    print *,'Guide: output timestep',timestep,'var ',varname
+    CHARACTER(LEN=20),PARAMETER :: modname="guide_out"
+
+    write(*,*)trim(modname)//': output timestep',timestep,'var ',varname
     IF (timestep.EQ.0) THEN 
 ! ----------------------------------------------
@@ -1566,6 +1754,6 @@
         ierr=NF_DEF_VAR(nid,"LEVEL",NF_FLOAT,1,id_lev,vid_lev)
         ierr=NF_DEF_VAR(nid,"cu",NF_FLOAT,2,(/id_lonu,id_latu/),vid_cu)
+        ierr=NF_DEF_VAR(nid,"cv",NF_FLOAT,2,(/id_lonv,id_latv/),vid_cv)
         ierr=NF_DEF_VAR(nid,"au",NF_FLOAT,2,(/id_lonu,id_latu/),vid_au)
-        ierr=NF_DEF_VAR(nid,"cv",NF_FLOAT,2,(/id_lonv,id_latv/),vid_cv)
         ierr=NF_DEF_VAR(nid,"av",NF_FLOAT,2,(/id_lonv,id_latv/),vid_av)
         call nf95_def_var(nid, "alpha_T", nf90_float, (/id_lonv, id_latu/), &
@@ -1604,7 +1792,7 @@
 ! --------------------------------------------------------------------
         ierr = NF_REDEF(nid)
-! Surface pressure (GCM)
-        dim3=(/id_lonv,id_latu,id_tim/)
-        ierr = NF_DEF_VAR(nid,"SP",NF_FLOAT,3,dim3,varid)
+! Pressure (GCM)
+        dim4=(/id_lonv,id_latu,id_lev,id_tim/)
+        ierr = NF_DEF_VAR(nid,"SP",NF_FLOAT,4,dim4,varid)
 ! Surface pressure (guidage)
         IF (guide_P) THEN
@@ -1651,6 +1839,6 @@
     SELECT CASE (varname)
     CASE ("SP","ps")
-        start=(/1,1,timestep,0/)
-        count=(/iip1,jjp1,1,0/)
+        start=(/1,1,1,timestep/)
+        count=(/iip1,jjp1,llm,1/)
     CASE ("v","va","vcov")
         start=(/1,1,1,timestep/)
Index: LMDZ6/trunk/libf/dyn3dmem/guide_loc_mod.F90
===================================================================
--- LMDZ6/trunk/libf/dyn3dmem/guide_loc_mod.F90	(revision 3992)
+++ LMDZ6/trunk/libf/dyn3dmem/guide_loc_mod.F90	(revision 3995)
@@ -9,10 +9,10 @@
 !=======================================================================
 
-  USE getparam
+  USE getparam, only: ini_getparam, fin_getparam, getpar
   USE Write_Field_loc
   use netcdf, only: nf90_nowrite, nf90_open, nf90_inq_varid, nf90_close, &
                     nf90_inq_dimid, nf90_inquire_dimension
   USE parallel_lmdz
-  USE pres2lev_mod
+  USE pres2lev_mod, only: pres2lev
 
   IMPLICIT NONE
@@ -63,5 +63,5 @@
   REAL, ALLOCATABLE, DIMENSION(:),   PRIVATE, SAVE   :: psgui1,psgui2
   
-  INTEGER,SAVE,PRIVATE :: ijbu,ijbv,ijeu,ijev,ijnu,ijnv
+  INTEGER,SAVE,PRIVATE :: ijbu,ijbv,ijeu,ijev !,ijnu,ijnv
   INTEGER,SAVE,PRIVATE :: jjbu,jjbv,jjeu,jjev,jjnu,jjnv
 
@@ -175,5 +175,5 @@
           rcod=nf90_open('apbp.nc',Nf90_NOWRITe, ncidpl)
           if (rcod.NE.NF_NOERR) THEN
-             print *,'Guide: probleme -> pas de fichier apbp.nc'
+             abort_message=' Nudging error -> no file apbp.nc'
              CALL abort_gcm(modname,abort_message,1)
           endif
@@ -183,5 +183,5 @@
           rcod=nf90_open('P.nc',Nf90_NOWRITe,ncidpl)
           if (rcod.NE.NF_NOERR) THEN
-             print *,'Guide: probleme -> pas de fichier P.nc'
+             abort_message=' Nudging error -> no file P.nc'
              CALL abort_gcm(modname,abort_message,1)
           endif
@@ -192,5 +192,5 @@
           rcod=nf90_open('u.nc',Nf90_NOWRITe,ncidpl)
           if (rcod.NE.NF_NOERR) THEN
-             print *,'Guide: probleme -> pas de fichier u.nc'
+             abort_message=' Nudging error -> no file u.nc'
              CALL abort_gcm(modname,abort_message,1)
           endif
@@ -203,5 +203,5 @@
           rcod=nf90_open('v.nc',nf90_nowrite,ncidpl)
           if (rcod.NE.NF_NOERR) THEN
-             print *,'Guide: probleme -> pas de fichier v.nc'
+             abort_message=' Nudging error -> no file v.nc'
              CALL abort_gcm(modname,abort_message,1)
           endif
@@ -213,5 +213,5 @@
           rcod=nf90_open('T.nc',nf90_nowrite,ncidpl)
           if (rcod.NE.NF_NOERR) THEN
-             print *,'Guide: probleme -> pas de fichier T.nc'
+             abort_message=' Nudging error -> no file T.nc'
              CALL abort_gcm(modname,abort_message,1)
           endif
@@ -224,5 +224,5 @@
           rcod=nf90_open('hur.nc',nf90_nowrite, ncidpl)
           if (rcod.NE.NF_NOERR) THEN
-             print *,'Guide: probleme -> pas de fichier hur.nc'
+             abort_message=' Nudging error -> no file hur.nc'
              CALL abort_gcm(modname,abort_message,1)
           endif
@@ -234,9 +234,9 @@
     IF (error.NE.NF_NOERR) error=NF_INQ_DIMID(ncidpl,'PRESSURE',rid)
     IF (error.NE.NF_NOERR) THEN
-        print *,'Guide: probleme lecture niveaux pression'
+        abort_message='Nudging: error reading pressure levels'
         CALL abort_gcm(modname,abort_message,1)
     ENDIF
     error=NF_INQ_DIMLEN(ncidpl,rid,nlevnc)
-    print *,'Guide: nombre niveaux vert. nlevnc', nlevnc 
+    write(*,*)trim(modname)//' : number of vertical levels nlevnc', nlevnc
     rcod = nf90_close(ncidpl)
 
@@ -244,5 +244,5 @@
 ! Allocation des variables
 ! ---------------------------------------------
-    abort_message='pb in allocation guide'
+    abort_message='nudging allocation error'
 
     ALLOCATE(apnc(nlevnc), stat = error)
@@ -395,16 +395,20 @@
     
     INTEGER       :: i,j,l
-    INTEGER,EXTERNAL :: OMP_GET_THREAD_NUM
+    CHARACTER(LEN=20) :: modname="guide_main"
        
 !$OMP MASTER    
-    ijbu=ij_begin ; ijeu=ij_end ; ijnu=ijeu-ijbu+1  
+    ijbu=ij_begin ; ijeu=ij_end
     jjbu=jj_begin ; jjeu=jj_end ; jjnu=jjeu-jjbu+1 
-    ijbv=ij_begin ; ijev=ij_end ; ijnv=ijev-ijbv+1   
+    ijbv=ij_begin ; ijev=ij_end
     jjbv=jj_begin ; jjev=jj_end ; jjnv=jjev-jjbv+1 
     IF (pole_sud) THEN
+      ijeu=ij_end-iip1
       ijev=ij_end-iip1
       jjev=jj_end-1
-      ijnv=ijev-ijbv+1
       jjnv=jjev-jjbv+1 
+    ENDIF
+    IF (pole_nord) THEN
+      ijbu=ij_begin+iip1
+      ijbv=ij_begin
     ENDIF
 !$OMP END MASTER
@@ -493,6 +497,7 @@
       IF (reste.EQ.0.) THEN
           IF (itau_test.EQ.itau) THEN
-              write(*,*)'deuxieme passage de advreel a itau=',itau
-              stop
+            write(*,*)trim(modname)//' second pass in advreel at itau=',&
+            itau
+            stop
           ELSE
 !$OMP MASTER
@@ -507,6 +512,8 @@
               step_rea=step_rea+1
               itau_test=itau
-              print*,'Lecture fichiers guidage, pas ',step_rea, &
-                    'apres ',count_no_rea,' non lectures'
+              if (is_master) then
+                write(*,*)trim(modname)//' Reading nudging files, step ',&
+                    step_rea,'after ',count_no_rea,' skips'
+              endif
               IF (guide_2D) THEN
 !$OMP MASTER
@@ -547,5 +554,5 @@
     
     
-        !-----------------------------------------------------------------------
+!-----------------------------------------------------------------------
 !   Ajout des champs de guidage 
 !-----------------------------------------------------------------------
@@ -576,13 +583,4 @@
         ENDDO
 
-!!$OMP MASTER
-!     DO l=1,llm,5
-!         print*,'avant dump2d l=',l,mpi_rank,OMP_GET_THREAD_NUM()
-!         print*,'avant dump2d l=',l,mpi_rank
-!         CALL dump2d(iip1,jjnb_u,p(:,l),'ppp   ')
-!      ENDDO
-!!$OMP END MASTER
-!!$OMP BARRIER
-
         CALL guide_out("SP",jjp1,llm,p(ijb_u:ije_u,1:llm),1.)
     ENDIF
@@ -605,8 +603,12 @@
         if (guide_zon) CALL guide_zonave_u(1,llm,f_addu)
         CALL guide_addfield_u(llm,f_addu,alpha_u)
-!       IF (f_out) CALL guide_out("ua",jjp1,llm,ugui1(ijb_u:ije_u,:),factt)
         IF (f_out) CALL guide_out("ua",jjp1,llm,(1.-tau)*ugui1(ijb_u:ije_u,:)+tau*ugui2(ijb_u:ije_u,:),factt)
         IF (f_out) CALL guide_out("u",jjp1,llm,ucov(ijb_u:ije_u,:),factt)
-        IF (f_out) CALL guide_out("ucov",jjp1,llm,f_addu(ijb_u:ije_u,:)/factt,factt)
+        IF (f_out) THEN
+         ! Ehouarn: fill the gaps adequately...
+         IF (ijbu>ijb_u) f_addu(ijb_u:ijbu-1,:)=0
+         IF (ijeu<ije_u) f_addu(ijeu+1:ije_u,:)=0
+         CALL guide_out("ucov",jjp1,llm,f_addu(ijb_u:ije_u,:)/factt,factt)
+        ENDIF
 !$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
         DO l=1,llm
@@ -703,5 +705,10 @@
         IF (f_out) CALL guide_out("v",jjm,llm,vcov(ijb_v:ije_v,:),factt)
         IF (f_out) CALL guide_out("va",jjm,llm,(1.-tau)*vgui1(ijb_v:ije_v,:)+tau*vgui2(ijb_v:ije_v,:),factt)
-        IF (f_out) CALL guide_out("vcov",jjm,llm,f_addv(:,:)/factt,factt)
+        IF (f_out) THEN
+          ! Ehouarn: Fill in the gaps adequately
+          IF (ijbv>ijb_v) f_addv(ijb_v:ijbv-1,:)=0 
+          IF (ijev<ije_v) f_addv(ijev+1:ije_v,:)=0
+          CALL guide_out("vcov",jjm,llm,f_addv(ijb_v:ije_v,:)/factt,factt)
+        ENDIF
 
 !$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
@@ -939,7 +946,9 @@
   
   INTEGER                            :: i,j,l,ij
+  CHARACTER(LEN=20),PARAMETER :: modname="guide_interp"
   TYPE(Request),SAVE :: Req  
 !$OMP THREADPRIVATE(Req)
-    print *,'Guide: conversion variables guidage'
+    
+    if (is_master) write(*,*)trim(modname)//': interpolate nudging variables'
 ! -----------------------------------------------------------------
 ! Calcul des niveaux de pression champs guidage (pour T et Q)
@@ -986,38 +995,39 @@
         first=.FALSE.
 !$OMP MASTER
-        print*,'Guide: verification ordre niveaux verticaux'
-        print*,'LMDZ :'
+        write(*,*)trim(modname)//' : check vertical level order'
+        write(*,*)trim(modname)//' LMDZ :'
         do l=1,llm
-            print*,'PL(',l,')=',(ap(l)+ap(l+1))/2. &
+          write(*,*)trim(modname)//' PL(',l,')=',(ap(l)+ap(l+1))/2. &
                   +psi(1,jjeu)*(bp(l)+bp(l+1))/2.
         enddo
-        print*,'Fichiers guidage'
+        write(*,*)trim(modname)//' nudging file :'
         SELECT CASE (guide_plevs)
         CASE (0) 
             do l=1,nlevnc
-                 print*,'PL(',l,')=',plnc2(1,jjbu,l)
+              write(*,*)trim(modname)//' PL(',l,')=',plnc2(1,jjbu,l)
             enddo
         CASE (1)
             DO l=1,nlevnc
-                 print*,'PL(',l,')=',apnc(l)+bpnc(l)*psnat2(i,jjbu)
-             ENDDO
+              write(*,*)trim(modname)//' PL(',l,')=',&
+                        apnc(l)+bpnc(l)*psnat2(i,jjbu)
+            ENDDO
         CASE (2)
             do l=1,nlevnc
-                 print*,'PL(',l,')=',pnat2(1,jjbu,l)
+              write(*,*)trim(modname)//' PL(',l,')=',pnat2(1,jjbu,l)
             enddo
         END SELECT
-        print *,'inversion de l''ordre: invert_p=',invert_p
+        write(*,*)trim(modname)//' invert ordering: invert_p=',invert_p
         if (guide_u) then
             do l=1,nlevnc
-                print*,'U(',l,')=',unat2(1,jjbu,l)
+              write(*,*)trim(modname)//' U(',l,')=',unat2(1,jjbu,l)
             enddo
         endif
         if (guide_T) then
             do l=1,nlevnc
-                print*,'T(',l,')=',tnat2(1,jjbu,l)
+              write(*,*)trim(modname)//' T(',l,')=',tnat2(1,jjbu,l)
             enddo
         endif
 !$OMP END MASTER
-    endif
+    endif ! of if (first)
     
 ! -----------------------------------------------------------------
@@ -1415,4 +1425,5 @@
     real alphamin,alphamax,xi
     integer i,j,ilon,ilat
+    character(len=20),parameter :: modname="tau2alpha"
 
 
@@ -1503,19 +1514,19 @@
             ! Calcul de gamma
             if (abs(grossismx-1.).lt.0.1.or.abs(grossismy-1.).lt.0.1) then
-                 print*,'ATTENTION modele peu zoome'
-                 print*,'ATTENTION on prend une constante de guidage cste'
-                 gamma=0.
+              write(*,*)trim(modname)//' ATTENTION modele peu zoome'
+              write(*,*)trim(modname)//' ATTENTION on prend une constante de guidage cste'
+              gamma=0.
             else
-                gamma=(dxdy_max-2.*dxdy_min)/(dxdy_max-dxdy_min)
-                print*,'gamma=',gamma
-                if (gamma.lt.1.e-5) then
-                  print*,'gamma =',gamma,'<1e-5'
-                  stop
-                endif
-                gamma=log(0.5)/log(gamma)
-                if (gamma4) then 
-                  gamma=min(gamma,4.)
-                endif
-                print*,'gamma=',gamma
+              gamma=(dxdy_max-2.*dxdy_min)/(dxdy_max-dxdy_min)
+              write(*,*)trim(modname)//' gamma=',gamma
+              if (gamma.lt.1.e-5) then
+                write(*,*)trim(modname)//' gamma =',gamma,'<1e-5'
+                stop
+              endif
+              gamma=log(0.5)/log(gamma)
+              if (gamma4) then 
+                gamma=min(gamma,4.)
+              endif
+              write(*,*)trim(modname)//' gamma=',gamma
             endif
         ENDIF !first
@@ -1558,7 +1569,7 @@
     IMPLICIT NONE
 
-#include "netcdf.inc"
-#include "dimensions.h"
-#include "paramet.h"
+    include "netcdf.inc"
+    include "dimensions.h"
+    include "paramet.h"
 
     INTEGER, INTENT(IN)   :: timestep
@@ -1582,24 +1593,24 @@
     if (first) then
          ncidpl=-99
-         print*,'Guide: ouverture des fichiers guidage '
+         write(*,*),trim(modname)//': opening nudging files '
 ! Ap et Bp si Niveaux de pression hybrides
          if (guide_plevs.EQ.1) then
-             print *,'Lecture du guidage sur niveaux modele'
+             write(*,*),trim(modname)//' Reading nudging on model levels'
              rcode = nf90_open('apbp.nc', nf90_nowrite, ncidpl)
              IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de fichier apbp.nc'
+              abort_message='Nudging: error -> no file apbp.nc'
               CALL abort_gcm(modname,abort_message,1)
              ENDIF
              rcode = nf90_inq_varid(ncidpl, 'AP', varidap)
              IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de variable AP, fichier apbp.nc'
+              abort_message='Nudging: error -> no AP variable in file apbp.nc'
               CALL abort_gcm(modname,abort_message,1)
              ENDIF
              rcode = nf90_inq_varid(ncidpl, 'BP', varidbp)
              IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de variable BP, fichier apbp.nc'
+              abort_message='Nudging: error -> no BP variable in file apbp.nc'
               CALL abort_gcm(modname,abort_message,1)
              ENDIF
-             print*,'ncidpl,varidap',ncidpl,varidap
+             write(*,*),trim(modname)//' ncidpl,varidap',ncidpl,varidap
          endif
          
@@ -1608,13 +1619,13 @@
              rcode = nf90_open('P.nc', nf90_nowrite, ncidp)
              IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de fichier P.nc'
+              abort_message='Nudging: error -> no file P.nc'
               CALL abort_gcm(modname,abort_message,1)
              ENDIF
              rcode = nf90_inq_varid(ncidp, 'PRES', varidp)
              IF (rcode.NE.NF_NOERR) THEN 
-              print *,'Guide: probleme -> pas de variable PRES, fichier P.nc'
+              abort_message='Nudging: error -> no PRES variable in file P.nc'
               CALL abort_gcm(modname,abort_message,1)
              ENDIF
-             print*,'ncidp,varidp',ncidp,varidp
+             write(*,*),trim(modname)//' ncidp,varidp',ncidp,varidp
              if (ncidpl.eq.-99) ncidpl=ncidp
          endif
@@ -1624,13 +1635,13 @@
              rcode = nf90_open('u.nc', nf90_nowrite, ncidu)
              IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de fichier u.nc'
+              abort_message='Nudging: error -> no file u.nc'
               CALL abort_gcm(modname,abort_message,1)
              ENDIF
              rcode = nf90_inq_varid(ncidu, 'UWND', varidu)
              IF (rcode.NE.NF_NOERR) THEN 
-              print *,'Guide: probleme -> pas de variable UWND, fichier u.nc'
+              abort_message='Nudging: error -> no UWND variable in file u.nc'
               CALL abort_gcm(modname,abort_message,1)
              ENDIF
-             print*,'ncidu,varidu',ncidu,varidu
+             write(*,*),trim(modname)//' ncidu,varidu',ncidu,varidu
              if (ncidpl.eq.-99) ncidpl=ncidu
 
@@ -1639,5 +1650,5 @@
              status=NF90_INQUIRE_DIMENSION(ncidu,dimid,namedim,lendim)
              IF (lendim .NE. iip1) THEN
-                print *,'dimension LONU different from iip1 in u.nc'
+                abort_message='dimension LONU different from iip1 in u.nc'
                 CALL abort_gcm(modname,abort_message,1)
              ENDIF
@@ -1646,5 +1657,5 @@
              status=NF90_INQUIRE_DIMENSION(ncidu,dimid,namedim,lendim)
              IF (lendim .NE. jjp1) THEN
-                print *,'dimension LATU different from jjp1 in u.nc'
+                abort_message='dimension LATU different from jjp1 in u.nc'
                 CALL abort_gcm(modname,abort_message,1)
              ENDIF
@@ -1656,13 +1667,13 @@
              rcode = nf90_open('v.nc', nf90_nowrite, ncidv)
              IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de fichier v.nc'
+              abort_message='Nudging: error -> no file v.nc'
               CALL abort_gcm(modname,abort_message,1)
              ENDIF
              rcode = nf90_inq_varid(ncidv, 'VWND', varidv)
              IF (rcode.NE.NF_NOERR) THEN 
-              print *,'Guide: probleme -> pas de variable VWND, fichier v.nc'
+              abort_message='Nudging: error -> no VWND variable in file v.nc'
               CALL abort_gcm(modname,abort_message,1)
              ENDIF
-             print*,'ncidv,varidv',ncidv,varidv
+             write(*,*),trim(modname)//' ncidv,varidv',ncidv,varidv
              if (ncidpl.eq.-99) ncidpl=ncidv
              
@@ -1671,5 +1682,5 @@
              
                 IF (lendim .NE. iip1) THEN
-                print *,'dimension LONV different from iip1 in v.nc'
+                abort_message='dimension LONV different from iip1 in v.nc'
                 CALL abort_gcm(modname,abort_message,1)
              ENDIF
@@ -1679,5 +1690,5 @@
              status=NF90_INQUIRE_DIMENSION(ncidv,dimid,namedim,lendim)
              IF (lendim .NE. jjm) THEN
-                print *,'dimension LATV different from jjm in v.nc'
+                abort_message='dimension LATV different from jjm in v.nc'
                 CALL abort_gcm(modname,abort_message,1)
              ENDIF
@@ -1689,13 +1700,13 @@
              rcode = nf90_open('T.nc', nf90_nowrite, ncidt)
              IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de fichier T.nc'
+              abort_message='Nudging: error -> no file T.nc'
               CALL abort_gcm(modname,abort_message,1)
              ENDIF
              rcode = nf90_inq_varid(ncidt, 'AIR', varidt)
              IF (rcode.NE.NF_NOERR) THEN 
-              print *,'Guide: probleme -> pas de variable AIR, fichier T.nc'
+              abort_message='Nudging: error -> no AIR variable in file T.nc'
               CALL abort_gcm(modname,abort_message,1)
              ENDIF
-             print*,'ncidT,varidT',ncidt,varidt
+             write(*,*),trim(modname)//' ncidT,varidT',ncidt,varidt
              if (ncidpl.eq.-99) ncidpl=ncidt
 
@@ -1703,5 +1714,5 @@
              status=NF90_INQUIRE_DIMENSION(ncidt,dimid,namedim,lendim)
              IF (lendim .NE. iip1) THEN
-                print *,'dimension LONV different from iip1 in T.nc'
+                abort_message='dimension LONV different from iip1 in T.nc'
                 CALL abort_gcm(modname,abort_message,1)
              ENDIF
@@ -1710,5 +1721,5 @@
              status=NF90_INQUIRE_DIMENSION(ncidt,dimid,namedim,lendim)
              IF (lendim .NE. jjp1) THEN
-                print *,'dimension LATU different from jjp1 in T.nc'
+                abort_message='dimension LATU different from jjp1 in T.nc'
                 CALL abort_gcm(modname,abort_message,1)
              ENDIF
@@ -1720,13 +1731,13 @@
              rcode = nf90_open('hur.nc', nf90_nowrite, ncidQ)
              IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de fichier hur.nc'
+              abort_message='Nudging: error -> no file hur.nc'
               CALL abort_gcm(modname,abort_message,1)
              ENDIF
              rcode = nf90_inq_varid(ncidQ, 'RH', varidQ)
              IF (rcode.NE.NF_NOERR) THEN 
-              print *,'Guide: probleme -> pas de variable RH, fichier hur.nc'
+              abort_message='Nudging: error -> no RH variable in file hur.nc'
               CALL abort_gcm(modname,abort_message,1)
              ENDIF
-             print*,'ncidQ,varidQ',ncidQ,varidQ
+             write(*,*),trim(modname)//' ncidQ,varidQ',ncidQ,varidQ
              if (ncidpl.eq.-99) ncidpl=ncidQ
 
@@ -1735,5 +1746,5 @@
              status=NF90_INQUIRE_DIMENSION(ncidQ,dimid,namedim,lendim)
              IF (lendim .NE. iip1) THEN
-                print *,'dimension LONV different from iip1 in hur.nc'
+                abort_message='dimension LONV different from iip1 in hur.nc'
                 CALL abort_gcm(modname,abort_message,1)
              ENDIF
@@ -1742,5 +1753,5 @@
              status=NF90_INQUIRE_DIMENSION(ncidQ,dimid,namedim,lendim)
              IF (lendim .NE. jjp1) THEN
-                print *,'dimension LATU different from jjp1 in hur.nc'
+                abort_message='dimension LATU different from jjp1 in hur.nc'
                 CALL abort_gcm(modname,abort_message,1)
              ENDIF
@@ -1752,13 +1763,13 @@
              rcode = nf90_open('ps.nc', nf90_nowrite, ncidps)
              IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de fichier ps.nc'
+              abort_message='Nudging: error -> no file ps.nc'
               CALL abort_gcm(modname,abort_message,1)
              ENDIF
              rcode = nf90_inq_varid(ncidps, 'SP', varidps)
              IF (rcode.NE.NF_NOERR) THEN 
-              print *,'Guide: probleme -> pas de variable SP, fichier ps.nc'
+              abort_message='Nudging: error -> no SP variable in file ps.nc'
               CALL abort_gcm(modname,abort_message,1)
              ENDIF
-             print*,'ncidps,varidps',ncidps,varidps
+             write(*,*),trim(modname)//' ncidps,varidps',ncidps,varidps
          endif
 ! Coordonnee verticale
@@ -1766,5 +1777,5 @@
               rcode = nf90_inq_varid(ncidpl, 'LEVEL', varidpl)
               IF (rcode.NE.0) rcode = nf90_inq_varid(ncidpl, 'PRESSURE', varidpl)
-              print*,'ncidpl,varidpl',ncidpl,varidpl
+              write(*,*),trim(modname)//' ncidpl,varidpl',ncidpl,varidpl
          endif
 ! Coefs ap, bp pour calcul de la pression aux differents niveaux
@@ -1911,7 +1922,7 @@
     IMPLICIT NONE
 
-#include "netcdf.inc"
-#include "dimensions.h"
-#include "paramet.h"
+    include "netcdf.inc"
+    include "dimensions.h"
+    include "paramet.h"
 
     INTEGER, INTENT(IN)   :: timestep
@@ -1938,120 +1949,120 @@
     if (first) then
          ncidpl=-99
-         print*,'Guide: ouverture des fichiers guidage '
+         write(*,*)trim(modname)//' : opening nudging files '
 ! Ap et Bp si niveaux de pression hybrides
          if (guide_plevs.EQ.1) then
-             print *,'Lecture du guidage sur niveaux mod�le'
-             rcode = nf90_open('apbp.nc', nf90_nowrite, ncidpl)
-             IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de fichier apbp.nc'
-              CALL abort_gcm(modname,abort_message,1)
-             ENDIF
-             rcode = nf90_inq_varid(ncidpl, 'AP', varidap)
-             IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de variable AP, fichier apbp.nc'
-              CALL abort_gcm(modname,abort_message,1)
-             ENDIF
-             rcode = nf90_inq_varid(ncidpl, 'BP', varidbp)
-             IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de variable BP, fichier apbp.nc'
-              CALL abort_gcm(modname,abort_message,1)
-             ENDIF
-             print*,'ncidpl,varidap',ncidpl,varidap
+           write(*,*)trim(modname)//' Reading nudging on model levels'
+           rcode = nf90_open('apbp.nc', nf90_nowrite, ncidpl)
+           IF (rcode.NE.NF_NOERR) THEN
+             abort_message='Nudging: error -> no file apbp.nc'
+           CALL abort_gcm(modname,abort_message,1)
+           ENDIF
+           rcode = nf90_inq_varid(ncidpl, 'AP', varidap)
+           IF (rcode.NE.NF_NOERR) THEN
+             abort_message='Nudging: error -> no AP variable in file apbp.nc'
+           CALL abort_gcm(modname,abort_message,1)
+           ENDIF
+           rcode = nf90_inq_varid(ncidpl, 'BP', varidbp)
+           IF (rcode.NE.NF_NOERR) THEN
+             abort_message='Nudging: error -> no BP variable in file apbp.nc'
+             CALL abort_gcm(modname,abort_message,1)
+           ENDIF
+           write(*,*)trim(modname)//'ncidpl,varidap',ncidpl,varidap
          endif
 ! Pression
          if (guide_plevs.EQ.2) then
-             rcode = nf90_open('P.nc', nf90_nowrite, ncidp)
-             IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de fichier P.nc'
-              CALL abort_gcm(modname,abort_message,1)
-             ENDIF
-             rcode = nf90_inq_varid(ncidp, 'PRES', varidp)
-             IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de variable PRES, fichier P.nc'
-              CALL abort_gcm(modname,abort_message,1)
-             ENDIF
-             print*,'ncidp,varidp',ncidp,varidp
-             if (ncidpl.eq.-99) ncidpl=ncidp
+           rcode = nf90_open('P.nc', nf90_nowrite, ncidp)
+           IF (rcode.NE.NF_NOERR) THEN
+             abort_message='Nudging: error -> no file P.nc'
+             CALL abort_gcm(modname,abort_message,1)
+           ENDIF
+           rcode = nf90_inq_varid(ncidp, 'PRES', varidp)
+           IF (rcode.NE.NF_NOERR) THEN
+             abort_message='Nudging: error -> no PRES variable in file P.nc'
+             CALL abort_gcm(modname,abort_message,1)
+           ENDIF
+           write(*,*)trim(modname)//' ncidp,varidp',ncidp,varidp
+           if (ncidpl.eq.-99) ncidpl=ncidp
          endif
 ! Vent zonal
          if (guide_u) then
-             rcode = nf90_open('u.nc', nf90_nowrite, ncidu)
-             IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de fichier u.nc'
-              CALL abort_gcm(modname,abort_message,1)
-             ENDIF
-             rcode = nf90_inq_varid(ncidu, 'UWND', varidu)
-             IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de variable UWND, fichier u.nc'
-              CALL abort_gcm(modname,abort_message,1)
-             ENDIF
-             print*,'ncidu,varidu',ncidu,varidu
-             if (ncidpl.eq.-99) ncidpl=ncidu
+           rcode = nf90_open('u.nc', nf90_nowrite, ncidu)
+           IF (rcode.NE.NF_NOERR) THEN
+             abort_message='Nudging: error -> no file u.nc'
+             CALL abort_gcm(modname,abort_message,1)
+           ENDIF
+           rcode = nf90_inq_varid(ncidu, 'UWND', varidu)
+           IF (rcode.NE.NF_NOERR) THEN
+             abort_message='Nudging: error -> no UWND variable in file u.nc'
+             CALL abort_gcm(modname,abort_message,1)
+           ENDIF
+           write(*,*)trim(modname)//' ncidu,varidu',ncidu,varidu
+           if (ncidpl.eq.-99) ncidpl=ncidu
          endif
 
 ! Vent meridien
          if (guide_v) then
-             rcode = nf90_open('v.nc', nf90_nowrite, ncidv)
-             IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de fichier v.nc'
-              CALL abort_gcm(modname,abort_message,1)
-             ENDIF
-             rcode = nf90_inq_varid(ncidv, 'VWND', varidv)
-             IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de variable VWND, fichier v.nc'
-              CALL abort_gcm(modname,abort_message,1)
-             ENDIF
-             print*,'ncidv,varidv',ncidv,varidv
-             if (ncidpl.eq.-99) ncidpl=ncidv
-         endif
+           rcode = nf90_open('v.nc', nf90_nowrite, ncidv)
+           IF (rcode.NE.NF_NOERR) THEN
+             abort_message='Nudging: error -> no file v.nc'
+             CALL abort_gcm(modname,abort_message,1)
+           ENDIF
+           rcode = nf90_inq_varid(ncidv, 'VWND', varidv)
+           IF (rcode.NE.NF_NOERR) THEN
+             abort_message='Nudging: error -> no VWND variable in file v.nc'
+             CALL abort_gcm(modname,abort_message,1)
+           ENDIF
+           write(*,*)trim(modname)//' ncidv,varidv',ncidv,varidv
+           if (ncidpl.eq.-99) ncidpl=ncidv
+        endif
 ! Temperature
          if (guide_T) then
-             rcode = nf90_open('T.nc', nf90_nowrite, ncidt)
-             IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de fichier T.nc'
-              CALL abort_gcm(modname,abort_message,1)
-             ENDIF
-             rcode = nf90_inq_varid(ncidt, 'AIR', varidt)
-             IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de variable AIR, fichier T.nc'
-              CALL abort_gcm(modname,abort_message,1)
-             ENDIF
-             print*,'ncidT,varidT',ncidt,varidt
-             if (ncidpl.eq.-99) ncidpl=ncidt
+           rcode = nf90_open('T.nc', nf90_nowrite, ncidt)
+           IF (rcode.NE.NF_NOERR) THEN
+             abort_message='Nudging: error -> no file T.nc'
+             CALL abort_gcm(modname,abort_message,1)
+           ENDIF
+           rcode = nf90_inq_varid(ncidt, 'AIR', varidt)
+           IF (rcode.NE.NF_NOERR) THEN
+             abort_message='Nudging: error -> no AIR variable in file T.nc'
+             CALL abort_gcm(modname,abort_message,1)
+           ENDIF
+           write(*,*)trim(modname)//' ncidT,varidT',ncidt,varidt
+           if (ncidpl.eq.-99) ncidpl=ncidt
          endif
 ! Humidite
          if (guide_Q) then
-             rcode = nf90_open('hur.nc', nf90_nowrite, ncidQ)
-             IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de fichier hur.nc'
-              CALL abort_gcm(modname,abort_message,1)
-             ENDIF
-             rcode = nf90_inq_varid(ncidQ, 'RH', varidQ)
-             IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de variable RH, fichier hur.nc'
-              CALL abort_gcm(modname,abort_message,1)
-             ENDIF
-             print*,'ncidQ,varidQ',ncidQ,varidQ
-             if (ncidpl.eq.-99) ncidpl=ncidQ
+           rcode = nf90_open('hur.nc', nf90_nowrite, ncidQ)
+           IF (rcode.NE.NF_NOERR) THEN
+             abort_message='Nudging: error -> no file hur.nc'
+             CALL abort_gcm(modname,abort_message,1)
+           ENDIF
+           rcode = nf90_inq_varid(ncidQ, 'RH', varidQ)
+           IF (rcode.NE.NF_NOERR) THEN
+             abort_message='Nudging: error -> no RH,variable in file hur.nc'
+             CALL abort_gcm(modname,abort_message,1)
+           ENDIF
+           write(*,*)trim(modname)//' ncidQ,varidQ',ncidQ,varidQ
+           if (ncidpl.eq.-99) ncidpl=ncidQ
          endif
 ! Pression de surface
          if ((guide_P).OR.(guide_plevs.EQ.1)) then
-             rcode = nf90_open('ps.nc', nf90_nowrite, ncidps)
-             IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de fichier ps.nc'
-              CALL abort_gcm(modname,abort_message,1)
-             ENDIF
-             rcode = nf90_inq_varid(ncidps, 'SP', varidps)
-             IF (rcode.NE.NF_NOERR) THEN
-              print *,'Guide: probleme -> pas de variable SP, fichier ps.nc'
-              CALL abort_gcm(modname,abort_message,1)
-             ENDIF
-             print*,'ncidps,varidps',ncidps,varidps
+           rcode = nf90_open('ps.nc', nf90_nowrite, ncidps)
+           IF (rcode.NE.NF_NOERR) THEN
+             abort_message='Nudging: error -> no file ps.nc'
+             CALL abort_gcm(modname,abort_message,1)
+           ENDIF
+           rcode = nf90_inq_varid(ncidps, 'SP', varidps)
+           IF (rcode.NE.NF_NOERR) THEN
+             abort_message='Nudging: error -> no SP variable in file ps.nc'
+             CALL abort_gcm(modname,abort_message,1)
+           ENDIF
+           write(*,*)trim(modname)//' ncidps,varidps',ncidps,varidps
          endif
 ! Coordonnee verticale
          if (guide_plevs.EQ.0) then
-              rcode = nf90_inq_varid(ncidpl, 'LEVEL', varidpl)
-              IF (rcode.NE.0) rcode = nf90_inq_varid(ncidpl, 'PRESSURE', varidpl)
-              print*,'ncidpl,varidpl',ncidpl,varidpl
+           rcode = nf90_inq_varid(ncidpl, 'LEVEL', varidpl)
+           IF (rcode.NE.0) rcode = nf90_inq_varid(ncidpl, 'PRESSURE', varidpl)
+           write(*,*)trim(modname)//' ncidpl,varidpl',ncidpl,varidpl
          endif
 ! Coefs ap, bp pour calcul de la pression aux differents niveaux
@@ -2247,4 +2258,5 @@
     REAL zu(ip1jmp1),zv(ip1jm), zt(iip1, jjp1), zq(iip1, jjp1)
     REAL, ALLOCATABLE, SAVE, DIMENSION(:,:,:) :: field_glo
+    CHARACTER(LEN=20),PARAMETER :: modname="guide_out"
     
 !$OMP MASTER
@@ -2253,5 +2265,5 @@
 !$OMP BARRIER
 
-    print*,'gvide_out apres allocation ',hsize,vsize
+!    write(*,*)trim(modname)//' after allocation ',hsize,vsize
 
     IF (hsize==jjp1) THEN
@@ -2261,5 +2273,5 @@
     ENDIF
 
-    print*,'guide_out apres gather '
+!    write(*,*)trim(modname)//' after gather '
     CALL Gather_field_u(alpha_u,zu,1)
     CALL Gather_field_u(alpha_t,zt,1)
@@ -2431,6 +2443,4 @@
 !$OMP BARRIER
 
-    RETURN
-
   END SUBROUTINE guide_out
     
Index: LMDZ6/trunk/libf/dyn3dmem/parallel_lmdz.F90
===================================================================
--- LMDZ6/trunk/libf/dyn3dmem/parallel_lmdz.F90	(revision 3992)
+++ LMDZ6/trunk/libf/dyn3dmem/parallel_lmdz.F90	(revision 3995)
@@ -12,6 +12,8 @@
     INTEGER,PARAMETER :: halo_max=3
     
-    LOGICAL,SAVE :: using_mpi
-    LOGICAL,SAVE :: using_omp
+    LOGICAL,SAVE :: using_mpi ! .true. if using MPI
+    LOGICAL,SAVE :: using_omp ! .true. if using OpenMP
+    LOGICAL,SAVE :: is_master ! .true. if the core is both MPI & OpenMP master
+!$OMP THREADPRIVATE(is_master)
     
     integer, save :: mpi_size
@@ -248,4 +250,10 @@
 !$OMP END PARALLEL         
       CALL create_distrib(jj_nb_para,current_dist)
+      
+      IF ((mpi_rank==0).and.(omp_rank==0)) THEN
+        is_master=.true.
+      ELSE
+        is_master=.false.
+      ENDIF
       
     end subroutine init_parallel
