source: LMDZ5/branches/testing/libf/dyn3dpar/leapfrog_p.F @ 2119

Last change on this file since 2119 was 2056, checked in by Laurent Fairhead, 10 years ago

Merged trunk changes r1997:2055 into testing branch

  • Property copyright set to
    Name of program: LMDZ
    Creation date: 1984
    Version: LMDZ5
    License: CeCILL version 2
    Holder: Laboratoire de m\'et\'eorologie dynamique, CNRS, UMR 8539
    See the license file in the root directory
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 55.8 KB
RevLine 
[764]1!
[1279]2! $Id: leapfrog_p.F 2056 2014-06-11 13:46:46Z fhourdin $
[630]3!
4c
5c
6
[1146]7      SUBROUTINE leapfrog_p(ucov,vcov,teta,ps,masse,phis,q,clesphy0,
[630]8     &                    time_0)
9
[2056]10      use exner_hyb_m, only: exner_hyb
11      use exner_milieu_m, only: exner_milieu
12      use exner_hyb_p_m, only: exner_hyb_p
13      use exner_milieu_p_m, only: exner_milieu_p
[630]14       USE misc_mod
[1864]15       USE parallel_lmdz
[630]16       USE times
17       USE mod_hallo
18       USE Bands
19       USE Write_Field
20       USE Write_Field_p
21       USE vampir
[985]22       USE timer_filtre, ONLY : print_filtre_timer
[1999]23       USE infotrac, ONLY: nqtot
[1279]24       USE guide_p_mod, ONLY : guide_main
25       USE getparam
[1999]26       USE control_mod, ONLY: nday, day_step, planet_type, offline,
27     &                       iconser, iphysiq, iperiod, dissip_period,
28     &                       iecri, ip_ebil_dyn, ok_dynzon, ok_dyn_ins,
29     &                       periodav, ok_dyn_ave, output_grads_dyn,
30     &                       iapp_tracvl
[630]31      IMPLICIT NONE
32
33c      ......   Version  du 10/01/98    ..........
34
35c             avec  coordonnees  verticales hybrides
36c   avec nouveaux operat. dissipation * ( gradiv2,divgrad2,nxgraro2 )
37
38c=======================================================================
39c
40c   Auteur:  P. Le Van /L. Fairhead/F.Hourdin
41c   -------
42c
43c   Objet:
44c   ------
45c
46c   GCM LMD nouvelle grille
47c
48c=======================================================================
49c
50c  ... Dans inigeom , nouveaux calculs pour les elongations  cu , cv
51c      et possibilite d'appeler une fonction f(y)  a derivee tangente
52c      hyperbolique a la  place de la fonction a derivee sinusoidale.
53
54c  ... Possibilite de choisir le shema pour l'advection de
55c        q  , en modifiant iadv dans traceur.def  (10/02) .
56c
57c      Pour Van-Leer + Vapeur d'eau saturee, iadv(1)=4. (F.Codron,10/99)
58c      Pour Van-Leer iadv=10
59c
60c-----------------------------------------------------------------------
61c   Declarations:
62c   -------------
63
64#include "dimensions.h"
65#include "paramet.h"
66#include "comconst.h"
67#include "comdissnew.h"
68#include "comvert.h"
69#include "comgeom.h"
70#include "logic.h"
71#include "temps.h"
72#include "ener.h"
73#include "description.h"
74#include "serre.h"
[1403]75!#include "com_io_dyn.h"
[630]76#include "iniprint.h"
77#include "academic.h"
78     
[1999]79      INTEGER,PARAMETER :: longcles = 20
80      REAL,INTENT(IN) :: clesphy0( longcles ) ! not used
81      REAL,INTENT(IN) :: time_0 ! not used
[630]82
[1999]83c   dynamical variables:
84      REAL,INTENT(INOUT) :: ucov(ip1jmp1,llm)    ! zonal covariant wind
85      REAL,INTENT(INOUT) :: vcov(ip1jm,llm)      ! meridional covariant wind
86      REAL,INTENT(INOUT) :: teta(ip1jmp1,llm)    ! potential temperature
87      REAL,INTENT(INOUT) :: ps(ip1jmp1)          ! surface pressure (Pa)
88      REAL,INTENT(INOUT) :: masse(ip1jmp1,llm)   ! air mass
89      REAL,INTENT(INOUT) :: phis(ip1jmp1)        ! geopotentiat at the surface
90      REAL,INTENT(INOUT) :: q(ip1jmp1,llm,nqtot) ! advected tracers
91
92      REAL,SAVE :: p (ip1jmp1,llmp1  )       ! interlayer pressure
93      REAL,SAVE :: pks(ip1jmp1)              ! exner at the surface
94      REAL,SAVE :: pk(ip1jmp1,llm)           ! exner at mid-layer
95      REAL,SAVE :: pkf(ip1jmp1,llm)          ! filtered exner at mid-layer
96      REAL,SAVE :: phi(ip1jmp1,llm)          ! geopotential
97      REAL,SAVE :: w(ip1jmp1,llm)            ! vertical velocity
98
[630]99      real zqmin,zqmax
100
101c variables dynamiques intermediaire pour le transport
[774]102      REAL,SAVE :: pbaru(ip1jmp1,llm),pbarv(ip1jm,llm) !flux de masse
[630]103
104c   variables dynamiques au pas -1
[774]105      REAL,SAVE :: vcovm1(ip1jm,llm),ucovm1(ip1jmp1,llm)
106      REAL,SAVE :: tetam1(ip1jmp1,llm),psm1(ip1jmp1)
107      REAL,SAVE :: massem1(ip1jmp1,llm)
[630]108
109c   tendances dynamiques
[774]110      REAL,SAVE :: dv(ip1jm,llm),du(ip1jmp1,llm)
[1146]111      REAL,SAVE :: dteta(ip1jmp1,llm),dp(ip1jmp1)
112      REAL,DIMENSION(:,:,:), ALLOCATABLE, SAVE :: dq
[630]113
114c   tendances de la dissipation
[774]115      REAL,SAVE :: dvdis(ip1jm,llm),dudis(ip1jmp1,llm)
116      REAL,SAVE :: dtetadis(ip1jmp1,llm)
[630]117
118c   tendances physiques
[774]119      REAL,SAVE :: dvfi(ip1jm,llm),dufi(ip1jmp1,llm)
120      REAL,SAVE :: dtetafi(ip1jmp1,llm)
[1146]121      REAL,SAVE :: dpfi(ip1jmp1)
122      REAL,DIMENSION(:,:,:),ALLOCATABLE,SAVE :: dqfi
[630]123
124c   variables pour le fichier histoire
125      REAL dtav      ! intervalle de temps elementaire
126
127      REAL tppn(iim),tpps(iim),tpn,tps
128c
129      INTEGER itau,itaufinp1,iav
[1279]130!      INTEGER  iday ! jour julien
131      REAL       time
[630]132
133      REAL  SSUM
[1665]134!      REAL,SAVE :: finvmaold(ip1jmp1,llm)
[630]135
136cym      LOGICAL  lafin
[774]137      LOGICAL :: lafin
[630]138      INTEGER ij,iq,l
139      INTEGER ik
140
141      real time_step, t_wrt, t_ops
142
[1279]143! jD_cur: jour julien courant
144! jH_cur: heure julienne courante
145      REAL :: jD_cur, jH_cur
146      INTEGER :: an, mois, jour
147      REAL :: secondes
148
[1707]149      logical :: physic
[630]150      LOGICAL first,callinigrads
151
152      data callinigrads/.true./
153      character*10 string10
154
[960]155      REAL,SAVE :: flxw(ip1jmp1,llm) ! flux de masse verticale
[630]156
157c+jld variables test conservation energie
[774]158      REAL,SAVE :: ecin(ip1jmp1,llm),ecin0(ip1jmp1,llm)
[630]159C     Tendance de la temp. potentiel d (theta)/ d t due a la
160C     tansformation d'energie cinetique en energie thermique
161C     cree par la dissipation
[774]162      REAL,SAVE :: dtetaecdt(ip1jmp1,llm)
163      REAL,SAVE :: vcont(ip1jm,llm),ucont(ip1jmp1,llm)
164      REAL,SAVE :: vnat(ip1jm,llm),unat(ip1jmp1,llm)
[630]165      REAL      d_h_vcol, d_qt, d_qw, d_ql, d_ec
166      CHARACTER*15 ztit
[764]167!      INTEGER   ip_ebil_dyn  ! PRINT level for energy conserv. diag.
168!      SAVE      ip_ebil_dyn
169!      DATA      ip_ebil_dyn/0/
[630]170c-jld
171
172      character*80 dynhist_file, dynhistave_file
[1520]173      character(len=*),parameter :: modname="leapfrog"
[630]174      character*80 abort_message
175
176
[774]177      logical,PARAMETER :: dissip_conservative=.TRUE.
178 
[630]179      INTEGER testita
180      PARAMETER (testita = 9)
[1286]181
182      logical , parameter :: flag_verif = .false.
[630]183     
[764]184c declaration liees au parallelisme
[630]185      INTEGER :: ierr
[774]186      LOGICAL :: FirstCaldyn
187      LOGICAL :: FirstPhysic
[630]188      INTEGER :: ijb,ije,j,i
189      type(Request) :: TestRequest
190      type(Request) :: Request_Dissip
191      type(Request) :: Request_physic
[774]192      REAL,SAVE :: dvfi_tmp(iip1,llm),dufi_tmp(iip1,llm)
[1146]193      REAL,SAVE :: dtetafi_tmp(iip1,llm)
194      REAL,DIMENSION(:,:,:),ALLOCATABLE,SAVE :: dqfi_tmp
[774]195      REAL,SAVE :: dpfi_tmp(iip1)
196
197      INTEGER :: true_itau
198      INTEGER :: iapptrac
199      INTEGER :: AdjustCount
[1279]200!      INTEGER :: var_time
[774]201      LOGICAL :: ok_start_timer=.FALSE.
[1146]202      LOGICAL, SAVE :: firstcall=.TRUE.
[774]203
204c$OMP MASTER
[630]205      ItCount=0
[774]206c$OMP END MASTER     
207      true_itau=0
208      FirstCaldyn=.TRUE.
209      FirstPhysic=.TRUE.
210      iapptrac=0
211      AdjustCount = 0
212      lafin=.false.
[630]213     
[2056]214      if (nday>=0) then
215         itaufin   = nday*day_step
216      else
217         itaufin   = -nday
218      endif
219
[630]220      itaufinp1 = itaufin +1
221
222      itau = 0
[1707]223      physic=.true.
224      if (iflag_phys==0.or.iflag_phys==2) physic=.false.
[1279]225!      iday = day_ini+itau/day_step
[1403]226!      time = REAL(itau-(iday-day_ini)*day_step)/day_step+time_0
[1279]227!         IF(time.GT.1.) THEN
228!          time = time-1.
229!          iday = iday+1
230!         ENDIF
[630]231
[1146]232c Allocate variables depending on dynamic variable nqtot
233c$OMP MASTER
234         IF (firstcall) THEN
235            firstcall=.FALSE.
236            ALLOCATE(dq(ip1jmp1,llm,nqtot))
237            ALLOCATE(dqfi(ip1jmp1,llm,nqtot))
238            ALLOCATE(dqfi_tmp(iip1,llm,nqtot))
239         END IF
240c$OMP END MASTER     
241c$OMP BARRIER
242
[630]243c-----------------------------------------------------------------------
244c   On initialise la pression et la fonction d'Exner :
245c   --------------------------------------------------
246
[774]247c$OMP MASTER
[1454]248      dq(:,:,:)=0.
[630]249      CALL pression ( ip1jmp1, ap, bp, ps, p       )
[1665]250      if (pressure_exner) then
[2056]251        CALL exner_hyb( ip1jmp1, ps, p, pks, pk, pkf )
[1665]252      else
[2056]253        CALL exner_milieu( ip1jmp1, ps, p, pks, pk, pkf )
[1520]254      endif
[774]255c$OMP END MASTER
[630]256c-----------------------------------------------------------------------
257c   Debut de l'integration temporelle:
258c   ----------------------------------
[764]259c et du parallelisme !!
[630]260
[1665]261   1  CONTINUE ! Matsuno Forward step begins here
[630]262
[1665]263      jD_cur = jD_ref + day_ini - day_ref +                             &
264     &          itau/day_step
265      jH_cur = jH_ref + start_time +                                    &
266     &         mod(itau,day_step)/float(day_step)
267      if (jH_cur > 1.0 ) then
268        jD_cur = jD_cur +1.
269        jH_cur = jH_cur -1.
270      endif
[985]271
[630]272
273#ifdef CPP_IOIPSL
[1279]274      if (ok_guide) then
275!$OMP MASTER
276        call guide_main(itau,ucov,vcov,teta,q,masse,ps)
277!$OMP END MASTER
278!$OMP BARRIER
[630]279      endif
280#endif
[1279]281
[630]282c
283c     IF( MOD( itau, 10* day_step ).EQ.0 )  THEN
284c       CALL  test_period ( ucov,vcov,teta,q,p,phis )
285c       PRINT *,' ----   Test_period apres continue   OK ! -----', itau
286c     ENDIF
287c
288cym      CALL SCOPY( ijmllm ,vcov , 1, vcovm1 , 1 )
289cym      CALL SCOPY( ijp1llm,ucov , 1, ucovm1 , 1 )
290cym      CALL SCOPY( ijp1llm,teta , 1, tetam1 , 1 )
291cym      CALL SCOPY( ijp1llm,masse, 1, massem1, 1 )
292cym      CALL SCOPY( ip1jmp1, ps  , 1,   psm1 , 1 )
293
294       if (FirstCaldyn) then
[774]295c$OMP MASTER
[630]296         ucovm1=ucov
297         vcovm1=vcov
298         tetam1= teta
299         massem1= masse
300         psm1= ps
[1665]301
302! Ehouarn: finvmaold is actually not used       
303!         finvmaold = masse
304!         CALL filtreg ( finvmaold ,jjp1, llm, -2,2, .TRUE., 1 )
[774]305c$OMP END MASTER
306c$OMP BARRIER
[630]307       else
[1146]308! Save fields obtained at previous time step as '...m1'
[630]309         ijb=ij_begin
310         ije=ij_end
[774]311
312c$OMP MASTER           
[630]313         psm1     (ijb:ije) = ps    (ijb:ije)
[774]314c$OMP END MASTER
315
316c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)         
[949]317         DO l=1,llm     
[774]318           ije=ij_end
[949]319           ucovm1   (ijb:ije,l) = ucov  (ijb:ije,l)
[774]320           tetam1   (ijb:ije,l) = teta  (ijb:ije,l)
321           massem1  (ijb:ije,l) = masse (ijb:ije,l)
[1665]322!           finvmaold(ijb:ije,l)=masse(ijb:ije,l)
[949]323                 
[774]324           if (pole_sud) ije=ij_end-iip1
325           vcovm1(ijb:ije,l) = vcov  (ijb:ije,l)
[630]326       
[774]327
328         ENDDO
[985]329c$OMP ENDDO 
[774]330
[1665]331! Ehouarn: finvmaold not used
332!          CALL filtreg_p ( finvmaold ,jj_begin,jj_end,jjp1,
333!     .                    llm, -2,2, .TRUE., 1 )
[774]334
[1146]335       endif ! of if (FirstCaldyn)
[630]336       
337      forward = .TRUE.
338      leapf   = .FALSE.
339      dt      =  dtvr
340
341c   ...    P.Le Van .26/04/94  ....
342
343cym      CALL SCOPY   ( ijp1llm,   masse, 1, finvmaold,     1 )
344cym      CALL filtreg ( finvmaold ,jjp1, llm, -2,2, .TRUE., 1 )
345
[764]346cym  ne sert a rien
[630]347cym      call minmax(ijp1llm,q(:,:,3),zqmin,zqmax)
348
[1665]349   2  CONTINUE ! Matsuno backward or leapfrog step begins here
[630]350
[774]351c$OMP MASTER
[630]352      ItCount=ItCount+1
[995]353      if (MOD(ItCount,1)==1) then
[630]354        debug=.true.
355      else
356        debug=.false.
357      endif
[774]358c$OMP END MASTER
[630]359c-----------------------------------------------------------------------
360
361c   date:
362c   -----
363
364
365c   gestion des appels de la physique et des dissipations:
366c   ------------------------------------------------------
367c
368c   ...    P.Le Van  ( 6/02/95 )  ....
369
370      apphys = .FALSE.
371      statcl = .FALSE.
372      conser = .FALSE.
373      apdiss = .FALSE.
[1502]374
[630]375      IF( purmats ) THEN
[1403]376      ! Purely Matsuno time stepping
[630]377         IF( MOD(itau,iconser) .EQ.0.AND.  forward    ) conser = .TRUE.
[1502]378         IF( MOD(itau,dissip_period ).EQ.0.AND..NOT.forward )
379     s        apdiss = .TRUE.
[630]380         IF( MOD(itau,iphysiq ).EQ.0.AND..NOT.forward
[1707]381     s          .and. physic                        ) apphys = .TRUE.
[630]382      ELSE
[1403]383      ! Leapfrog/Matsuno time stepping
[630]384         IF( MOD(itau   ,iconser) .EQ. 0              ) conser = .TRUE.
[1502]385         IF( MOD(itau+1,dissip_period).EQ.0 .AND. .NOT. forward )
386     s        apdiss = .TRUE.
[1707]387         IF( MOD(itau+1,iphysiq).EQ.0.AND.physic) apphys=.TRUE.
[630]388      END IF
389
[1403]390! Ehouarn: for Shallow Water case (ie: 1 vertical layer),
391!          supress dissipation step
392      if (llm.eq.1) then
393        apdiss=.false.
394      endif
395
[630]396cym    ---> Pour le moment     
397cym      apphys = .FALSE.
398      statcl = .FALSE.
[1403]399      conser = .FALSE. ! ie: no output of control variables to stdout in //
[630]400     
401      if (firstCaldyn) then
[774]402c$OMP MASTER
[630]403          call SetDistrib(jj_Nb_Caldyn)
[774]404c$OMP END MASTER
405c$OMP BARRIER
[630]406          firstCaldyn=.FALSE.
407cym          call InitTime
[774]408c$OMP MASTER
[630]409          call Init_timer
[774]410c$OMP END MASTER
[630]411      endif
[774]412
413c$OMP MASTER     
414      IF (ok_start_timer) THEN
415        CALL InitTime
[949]416        ok_start_timer=.FALSE.
[774]417      ENDIF     
418c$OMP END MASTER     
419     
[630]420      if (Adjust) then
[774]421c$OMP MASTER
422        AdjustCount=AdjustCount+1
423        if (iapptrac==iapp_tracvl .and. (forward. OR . leapf)
424     &         .and. itau/iphysiq>2 .and. Adjustcount>30) then
[630]425           AdjustCount=0
426           call allgather_timer_average
427
[1664]428        if (prt_level > 9) then
[630]429       
[949]430        print *,'*********************************'
431        print *,'******    TIMER CALDYN     ******'
432        do i=0,mpi_size-1
433          print *,'proc',i,' :   Nb Bandes  :',jj_nb_caldyn(i),
[630]434     &            '  : temps moyen :',
435     &             timer_average(jj_nb_caldyn(i),timer_caldyn,i),
436     &            '+-',timer_delta(jj_nb_caldyn(i),timer_caldyn,i)
437        enddo
438     
439        print *,'*********************************'
[949]440        print *,'******    TIMER VANLEER    ******'
441        do i=0,mpi_size-1
442          print *,'proc',i,' :   Nb Bandes  :',jj_nb_vanleer(i),
[630]443     &            '  : temps moyen :',
444     &             timer_average(jj_nb_vanleer(i),timer_vanleer,i),
445     &            '+-',timer_delta(jj_nb_vanleer(i),timer_vanleer,i)
446        enddo
447     
448        print *,'*********************************'
[949]449        print *,'******    TIMER DISSIP    ******'
450        do i=0,mpi_size-1
451          print *,'proc',i,' :   Nb Bandes  :',jj_nb_dissip(i),
[630]452     &            '  : temps moyen :',
453     &             timer_average(jj_nb_dissip(i),timer_dissip,i),
454     &             '+-',timer_delta(jj_nb_dissip(i),timer_dissip,i)
455        enddo
456       
[949]457        if (mpi_rank==0) call WriteBands
458       
[630]459       endif
460       
[949]461         call AdjustBands_caldyn
[630]462         if (mpi_rank==0) call WriteBands
[949]463         
464         call Register_SwapFieldHallo(ucov,ucov,ip1jmp1,llm,
[630]465     &                                jj_Nb_caldyn,0,0,TestRequest)
466         call Register_SwapFieldHallo(ucovm1,ucovm1,ip1jmp1,llm,
467     &                                jj_Nb_caldyn,0,0,TestRequest)
468         call Register_SwapFieldHallo(vcov,vcov,ip1jm,llm,
469     &                                jj_Nb_caldyn,0,0,TestRequest)
470         call Register_SwapFieldHallo(vcovm1,vcovm1,ip1jm,llm,
471     &                                jj_Nb_caldyn,0,0,TestRequest)
472         call Register_SwapFieldHallo(teta,teta,ip1jmp1,llm,
473     &                                jj_Nb_caldyn,0,0,TestRequest)
474         call Register_SwapFieldHallo(tetam1,tetam1,ip1jmp1,llm,
475     &                                jj_Nb_caldyn,0,0,TestRequest)
476         call Register_SwapFieldHallo(masse,masse,ip1jmp1,llm,
477     &                                jj_Nb_caldyn,0,0,TestRequest)
478         call Register_SwapFieldHallo(massem1,massem1,ip1jmp1,llm,
479     &                                jj_Nb_caldyn,0,0,TestRequest)
480         call Register_SwapFieldHallo(ps,ps,ip1jmp1,1,
481     &                                jj_Nb_caldyn,0,0,TestRequest)
482         call Register_SwapFieldHallo(psm1,psm1,ip1jmp1,1,
483     &                                jj_Nb_caldyn,0,0,TestRequest)
484         call Register_SwapFieldHallo(pkf,pkf,ip1jmp1,llm,
485     &                                jj_Nb_caldyn,0,0,TestRequest)
486         call Register_SwapFieldHallo(pk,pk,ip1jmp1,llm,
487     &                                jj_Nb_caldyn,0,0,TestRequest)
488         call Register_SwapFieldHallo(pks,pks,ip1jmp1,1,
489     &                                jj_Nb_caldyn,0,0,TestRequest)
490         call Register_SwapFieldHallo(phis,phis,ip1jmp1,1,
491     &                                jj_Nb_caldyn,0,0,TestRequest)
[774]492         call Register_SwapFieldHallo(phi,phi,ip1jmp1,llm,
[630]493     &                                jj_Nb_caldyn,0,0,TestRequest)
[1665]494!         call Register_SwapFieldHallo(finvmaold,finvmaold,ip1jmp1,llm,
495!     &                                jj_Nb_caldyn,0,0,TestRequest)
[630]496 
[1146]497        do j=1,nqtot
[764]498         call Register_SwapFieldHallo(q(1,1,j),q(1,1,j),ip1jmp1,llm,
499     &                                jj_nb_caldyn,0,0,TestRequest)
500        enddo
501
[630]502         call SetDistrib(jj_nb_caldyn)
503         call SendRequest(TestRequest)
504         call WaitRequest(TestRequest)
505         
[949]506        call AdjustBands_dissip
507        call AdjustBands_physic
[774]508
[630]509      endif
[774]510c$OMP END MASTER 
[630]511      endif       
[774]512     
[630]513     
514     
515c-----------------------------------------------------------------------
516c   calcul des tendances dynamiques:
517c   --------------------------------
[774]518c$OMP BARRIER
519c$OMP MASTER
[630]520       call VTb(VThallo)
[985]521c$OMP END MASTER
522
[630]523       call Register_Hallo(ucov,ip1jmp1,llm,1,1,1,1,TestRequest)
524       call Register_Hallo(vcov,ip1jm,llm,1,1,1,1,TestRequest)
525       call Register_Hallo(teta,ip1jmp1,llm,1,1,1,1,TestRequest)
526       call Register_Hallo(ps,ip1jmp1,1,1,2,2,1,TestRequest)
527       call Register_Hallo(pkf,ip1jmp1,llm,1,1,1,1,TestRequest)
528       call Register_Hallo(pk,ip1jmp1,llm,1,1,1,1,TestRequest)
529       call Register_Hallo(pks,ip1jmp1,1,1,1,1,1,TestRequest)
530       call Register_Hallo(p,ip1jmp1,llmp1,1,1,1,1,TestRequest)
531       
[1146]532c       do j=1,nqtot
[630]533c         call Register_Hallo(q(1,1,j),ip1jmp1,llm,1,1,1,1,
534c     *                       TestRequest)
535c        enddo
536
537       call SendRequest(TestRequest)
[985]538c$OMP BARRIER
[630]539       call WaitRequest(TestRequest)
[985]540
541c$OMP MASTER
[630]542       call VTe(VThallo)
[985]543c$OMP END MASTER
544c$OMP BARRIER
[764]545     
[949]546      if (debug) then       
[985]547!$OMP BARRIER
548!$OMP MASTER
[630]549        call WriteField_p('ucov',reshape(ucov,(/iip1,jmp1,llm/)))
550        call WriteField_p('vcov',reshape(vcov,(/iip1,jjm,llm/)))
551        call WriteField_p('teta',reshape(teta,(/iip1,jmp1,llm/)))
552        call WriteField_p('ps',reshape(ps,(/iip1,jmp1/)))
553        call WriteField_p('masse',reshape(masse,(/iip1,jmp1,llm/)))
[949]554        call WriteField_p('pk',reshape(pk,(/iip1,jmp1,llm/)))
[630]555        call WriteField_p('pks',reshape(pks,(/iip1,jmp1/)))
556        call WriteField_p('pkf',reshape(pkf,(/iip1,jmp1,llm/)))
557        call WriteField_p('phis',reshape(phis,(/iip1,jmp1/)))
[1146]558        do j=1,nqtot
[764]559          call WriteField_p('q'//trim(int2str(j)),
560     .                reshape(q(:,:,j),(/iip1,jmp1,llm/)))
[985]561        enddo
562!$OMP END MASTER       
563c$OMP BARRIER
[630]564      endif
[985]565
[630]566     
567      True_itau=True_itau+1
[774]568
569c$OMP MASTER
[1146]570      IF (prt_level>9) THEN
571        WRITE(lunout,*)"leapfrog_p: Iteration No",True_itau
572      ENDIF
[630]573
574
575      call start_timer(timer_caldyn)
576
[1665]577      ! compute geopotential phi()
[630]578      CALL geopot_p  ( ip1jmp1, teta  , pk , pks,  phis  , phi   )
579
580     
581      call VTb(VTcaldyn)
[774]582c$OMP END MASTER
[1279]583!      var_time=time+iday-day_ini
[764]584
[985]585c$OMP BARRIER
586!      CALL FTRACE_REGION_BEGIN("caldyn")
[1279]587      time = jD_cur + jH_cur
[630]588      CALL caldyn_p
589     $  ( itau,ucov,vcov,teta,ps,masse,pk,pkf,phis ,
[1279]590     $    phi,conser,du,dv,dteta,dp,w, pbaru,pbarv, time )
[764]591
[985]592!      CALL FTRACE_REGION_END("caldyn")
[1279]593
[774]594c$OMP MASTER
[630]595      call VTe(VTcaldyn)
[774]596c$OMP END MASTER     
[985]597
598cc$OMP BARRIER
599cc$OMP MASTER
[1279]600!      call WriteField_p('du',reshape(du,(/iip1,jmp1,llm/)))
601!      call WriteField_p('dv',reshape(dv,(/iip1,jjm,llm/)))
602!      call WriteField_p('dteta',reshape(dteta,(/iip1,jmp1,llm/)))
603!      call WriteField_p('dp',reshape(dp,(/iip1,jmp1/)))
604!      call WriteField_p('w',reshape(w,(/iip1,jmp1,llm/)))
605!      call WriteField_p('pbaru',reshape(pbaru,(/iip1,jmp1,llm/)))
606!      call WriteField_p('pbarv',reshape(pbarv,(/iip1,jjm,llm/)))
607!      call WriteField_p('p',reshape(p,(/iip1,jmp1,llmp1/)))
608!      call WriteField_p('masse',reshape(masse,(/iip1,jmp1,llm/)))
609!      call WriteField_p('pk',reshape(pk,(/iip1,jmp1,llm/)))
[985]610cc$OMP END MASTER
[630]611
612c-----------------------------------------------------------------------
613c   calcul des tendances advection des traceurs (dont l'humidite)
614c   -------------------------------------------------------------
615
616      IF( forward. OR . leapf )  THEN
[1999]617! Ehouarn: NB: fields sent to advtrac are those at the beginning of the time step
[960]618         CALL caladvtrac_p(q,pbaru,pbarv,
619     *        p, masse, dq,  teta,
620     .        flxw,pk, iapptrac)
[985]621
[1454]622C        Stokage du flux de masse pour traceurs OFF-LINE
623         IF (offline .AND. .NOT. adjust) THEN
624            CALL fluxstokenc_p(pbaru,pbarv,masse,teta,phi,phis,
625     .           dtvr, itau)
626         ENDIF
[985]627
[1146]628      ENDIF ! of IF( forward. OR . leapf )
[630]629
630c-----------------------------------------------------------------------
631c   integrations dynamique et traceurs:
632c   ----------------------------------
[774]633
634c$OMP MASTER
[630]635       call VTb(VTintegre)
[774]636c$OMP END MASTER
[764]637c      call WriteField_p('ucovm1',reshape(ucovm1,(/iip1,jmp1,llm/)))
638c      call WriteField_p('vcovm1',reshape(vcovm1,(/iip1,jjm,llm/)))
639c      call WriteField_p('tetam1',reshape(tetam1,(/iip1,jmp1,llm/)))
640c      call WriteField_p('psm1',reshape(psm1,(/iip1,jmp1/)))
641c      call WriteField_p('ucov',reshape(ucov,(/iip1,jmp1,llm/)))
642c      call WriteField_p('vcov',reshape(vcov,(/iip1,jjm,llm/)))
643c      call WriteField_p('teta',reshape(teta,(/iip1,jmp1,llm/)))
644c      call WriteField_p('ps',reshape(ps,(/iip1,jmp1/)))
[774]645cc$OMP PARALLEL DEFAULT(SHARED)
[985]646c$OMP BARRIER
647!       CALL FTRACE_REGION_BEGIN("integrd")
[1146]648
[630]649       CALL integrd_p ( 2,vcovm1,ucovm1,tetam1,psm1,massem1 ,
[1665]650     $         dv,du,dteta,dq,dp,vcov,ucov,teta,q,ps,masse,phis )
651!     $              finvmaold                                    )
[630]652
[985]653!       CALL FTRACE_REGION_END("integrd")
654c$OMP BARRIER
655cc$OMP MASTER
[764]656c      call WriteField_p('ucovm1',reshape(ucovm1,(/iip1,jmp1,llm/)))
657c      call WriteField_p('vcovm1',reshape(vcovm1,(/iip1,jjm,llm/)))
658c      call WriteField_p('tetam1',reshape(tetam1,(/iip1,jmp1,llm/)))
659c      call WriteField_p('psm1',reshape(psm1,(/iip1,jmp1/)))
660c      call WriteField_p('ucov',reshape(ucov,(/iip1,jmp1,llm/)))
661c      call WriteField_p('vcov',reshape(vcov,(/iip1,jjm,llm/)))
662c      call WriteField_p('teta',reshape(teta,(/iip1,jmp1,llm/)))
663c      call WriteField_p('dteta',reshape(dteta,(/iip1,jmp1,llm/)))
[985]664c
665c      call WriteField_p('ps',reshape(ps,(/iip1,jmp1/)))
[1146]666c      do j=1,nqtot
[985]667c        call WriteField_p('q'//trim(int2str(j)),
668c     .                reshape(q(:,:,j),(/iip1,jmp1,llm/)))
669c        call WriteField_p('dq'//trim(int2str(j)),
670c     .                reshape(dq(:,:,j),(/iip1,jmp1,llm/)))
671c      enddo
672cc$OMP END MASTER
[764]673
[985]674
[774]675c$OMP MASTER
[630]676       call VTe(VTintegre)
[774]677c$OMP END MASTER
[630]678c .P.Le Van (26/04/94  ajout de  finvpold dans l'appel d'integrd)
679c
680c-----------------------------------------------------------------------
681c   calcul des tendances physiques:
682c   -------------------------------
683c    ########   P.Le Van ( Modif le  6/02/95 )   ###########
684c
685       IF( purmats )  THEN
686          IF( itau.EQ.itaufin.AND..NOT.forward ) lafin = .TRUE.
687       ELSE
688          IF( itau+1. EQ. itaufin )              lafin = .TRUE.
689       ENDIF
[774]690
691cc$OMP END PARALLEL
692
[630]693c
694c
695       IF( apphys )  THEN
696c
697c     .......   Ajout   P.Le Van ( 17/04/96 )   ...........
698c
[774]699cc$OMP PARALLEL DEFAULT(SHARED)
700cc$OMP+         PRIVATE(rdaym_ini,rdayvrai,ijb,ije)
[764]701
702c$OMP MASTER
[630]703         call suspend_timer(timer_caldyn)
[1146]704
[1403]705        if (prt_level >= 10) then
[1146]706         write(lunout,*)
707     &   'leapfrog_p: Entree dans la physique : Iteration No ',true_itau
[1403]708        endif
[764]709c$OMP END MASTER
710
[630]711         CALL pression_p (  ip1jmp1, ap, bp, ps,  p      )
[764]712
[985]713c$OMP BARRIER
[1665]714         if (pressure_exner) then
[2056]715           CALL exner_hyb_p(  ip1jmp1, ps, p,pks, pk, pkf )
[1665]716         else
[2056]717           CALL exner_milieu_p( ip1jmp1, ps, p, pks, pk, pkf )
[1520]718         endif
[2056]719! Appel a geopot ajoute le 2014/05/08 pour garantir la convergence numerique
720! avec dyn3dmem
721      CALL geopot  ( ip1jmp1, teta  , pk , pks,  phis  , phi   )
[985]722c$OMP BARRIER
[1279]723           jD_cur = jD_ref + day_ini - day_ref
[1665]724     $        + itau/day_step
[1707]725
726           IF (planet_type .eq."generic") THEN
727              ! AS: we make jD_cur to be pday
728              jD_cur = int(day_ini + itau/day_step)
729           ENDIF
730
[1665]731           jH_cur = jH_ref + start_time +                                &
732     &              mod(itau,day_step)/float(day_step)
[1279]733!         call ju2ymds(jD_cur+jH_cur, an, mois, jour, secondes)
[1665]734           if (jH_cur > 1.0 ) then
735             jD_cur = jD_cur +1.
736             jH_cur = jH_cur -1.
737           endif
[630]738
739c rajout debug
740c       lafin = .true.
741
742
743c   Inbterface avec les routines de phylmd (phymars ... )
744c   -----------------------------------------------------
745
746c+jld
747
[764]748c  Diagnostique de conservation de l'energie : initialisation
[630]749      IF (ip_ebil_dyn.ge.1 ) THEN
750          ztit='bil dyn'
[1146]751! Ehouarn: be careful, diagedyn is Earth-specific (includes ../phylmd/..)!
752           IF (planet_type.eq."earth") THEN
[1665]753#ifdef CPP_EARTH
[1146]754            CALL diagedyn(ztit,2,1,1,dtphys
755     &    , ucov    , vcov , ps, p ,pk , teta , q(:,:,1), q(:,:,2))
[1665]756#endif
[1146]757           ENDIF
[630]758      ENDIF
759c-jld
[764]760c$OMP BARRIER
761c$OMP MASTER
[630]762        call VTb(VThallo)
[985]763c$OMP END MASTER
764
[630]765        call SetTag(Request_physic,800)
[949]766       
[630]767        call Register_SwapFieldHallo(ucov,ucov,ip1jmp1,llm,
768     *                               jj_Nb_physic,2,2,Request_physic)
769       
770        call Register_SwapFieldHallo(vcov,vcov,ip1jm,llm,
771     *                               jj_Nb_physic,2,2,Request_physic)
772       
773        call Register_SwapFieldHallo(teta,teta,ip1jmp1,llm,
774     *                               jj_Nb_physic,2,2,Request_physic)
775       
[1279]776        call Register_SwapFieldHallo(masse,masse,ip1jmp1,llm,
777     *                               jj_Nb_physic,1,2,Request_physic)
778
[1999]779        call Register_SwapFieldHallo(ps,ps,ip1jmp1,1,
780     *                               jj_Nb_physic,2,2,Request_physic)
781
[630]782        call Register_SwapFieldHallo(p,p,ip1jmp1,llmp1,
783     *                               jj_Nb_physic,2,2,Request_physic)
784       
785        call Register_SwapFieldHallo(pk,pk,ip1jmp1,llm,
786     *                               jj_Nb_physic,2,2,Request_physic)
787       
788        call Register_SwapFieldHallo(phis,phis,ip1jmp1,1,
789     *                               jj_Nb_physic,2,2,Request_physic)
790       
791        call Register_SwapFieldHallo(phi,phi,ip1jmp1,llm,
792     *                               jj_Nb_physic,2,2,Request_physic)
793       
794        call Register_SwapFieldHallo(w,w,ip1jmp1,llm,
795     *                               jj_Nb_physic,2,2,Request_physic)
796       
[949]797c        call SetDistrib(jj_nb_vanleer)
[1146]798        do j=1,nqtot
[630]799 
800          call Register_SwapFieldHallo(q(1,1,j),q(1,1,j),ip1jmp1,llm,
801     *                               jj_Nb_physic,2,2,Request_physic)
802        enddo
[960]803
[630]804        call Register_SwapFieldHallo(flxw,flxw,ip1jmp1,llm,
805     *                               jj_Nb_physic,2,2,Request_physic)
[949]806       
[630]807        call SendRequest(Request_Physic)
[985]808c$OMP BARRIER
[630]809        call WaitRequest(Request_Physic)       
[985]810
811c$OMP BARRIER
812c$OMP MASTER
813        call SetDistrib(jj_nb_Physic)
[949]814        call VTe(VThallo)
815       
816        call VTb(VTphysiq)
[764]817c$OMP END MASTER
818c$OMP BARRIER
819
[949]820cc$OMP MASTER       
[764]821c      call WriteField_p('ucovfi',reshape(ucov,(/iip1,jmp1,llm/)))
822c      call WriteField_p('vcovfi',reshape(vcov,(/iip1,jjm,llm/)))
823c      call WriteField_p('tetafi',reshape(teta,(/iip1,jmp1,llm/)))
824c      call WriteField_p('pfi',reshape(p,(/iip1,jmp1,llmp1/)))
825c      call WriteField_p('pkfi',reshape(pk,(/iip1,jmp1,llm/)))
826cc$OMP END MASTER
827cc$OMP BARRIER
[985]828!        CALL FTRACE_REGION_BEGIN("calfis")
[1279]829        CALL calfis_p(lafin ,jD_cur, jH_cur,
[630]830     $               ucov,vcov,teta,q,masse,ps,p,pk,phis,phi ,
[960]831     $               du,dv,dteta,dq,
[630]832     $               flxw,
833     $               clesphy0, dufi,dvfi,dtetafi,dqfi,dpfi  )
[985]834!        CALL FTRACE_REGION_END("calfis")
[630]835        ijb=ij_begin
836        ije=ij_end 
837        if ( .not. pole_nord) then
[764]838c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
839          DO l=1,llm
840          dufi_tmp(1:iip1,l)   = dufi(ijb:ijb+iim,l)
841          dvfi_tmp(1:iip1,l)   = dvfi(ijb:ijb+iim,l) 
842          dtetafi_tmp(1:iip1,l)= dtetafi(ijb:ijb+iim,l) 
843          dqfi_tmp(1:iip1,l,:) = dqfi(ijb:ijb+iim,l,:) 
844          ENDDO
845c$OMP END DO NOWAIT
846
847c$OMP MASTER
[630]848          dpfi_tmp(1:iip1)     = dpfi(ijb:ijb+iim) 
[764]849c$OMP END MASTER
[1146]850        endif ! of if ( .not. pole_nord)
[764]851
852c$OMP BARRIER
853c$OMP MASTER
[949]854        call SetDistrib(jj_nb_Physic_bis)
[630]855
856        call VTb(VThallo)
[985]857c$OMP END MASTER
858c$OMP BARRIER
[630]859 
860        call Register_Hallo(dufi,ip1jmp1,llm,
861     *                      1,0,0,1,Request_physic)
862       
863        call Register_Hallo(dvfi,ip1jm,llm,
864     *                      1,0,0,1,Request_physic)
865       
866        call Register_Hallo(dtetafi,ip1jmp1,llm,
867     *                      1,0,0,1,Request_physic)
868
869        call Register_Hallo(dpfi,ip1jmp1,1,
870     *                      1,0,0,1,Request_physic)
871
[1146]872        do j=1,nqtot
[630]873          call Register_Hallo(dqfi(1,1,j),ip1jmp1,llm,
874     *                        1,0,0,1,Request_physic)
875        enddo
876       
877        call SendRequest(Request_Physic)
[985]878c$OMP BARRIER
[630]879        call WaitRequest(Request_Physic)
880             
[985]881c$OMP BARRIER
882c$OMP MASTER
[630]883        call VTe(VThallo)
884 
885        call SetDistrib(jj_nb_Physic)
[764]886c$OMP END MASTER
[949]887c$OMP BARRIER       
888                ijb=ij_begin
889        if (.not. pole_nord) then
890       
[764]891c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
892          DO l=1,llm
893            dufi(ijb:ijb+iim,l) = dufi(ijb:ijb+iim,l)+dufi_tmp(1:iip1,l)
894            dvfi(ijb:ijb+iim,l) = dvfi(ijb:ijb+iim,l)+dvfi_tmp(1:iip1,l)
895            dtetafi(ijb:ijb+iim,l) = dtetafi(ijb:ijb+iim,l)
896     &                              +dtetafi_tmp(1:iip1,l)
897            dqfi(ijb:ijb+iim,l,:) = dqfi(ijb:ijb+iim,l,:)
898     &                              + dqfi_tmp(1:iip1,l,:)
899          ENDDO
900c$OMP END DO NOWAIT
901
902c$OMP MASTER
[630]903          dpfi(ijb:ijb+iim)   = dpfi(ijb:ijb+iim)+ dpfi_tmp(1:iip1)
[764]904c$OMP END MASTER
[949]905         
[1146]906        endif ! of if (.not. pole_nord)
[764]907c$OMP BARRIER
[949]908cc$OMP MASTER       
[630]909c      call WriteField_p('dufi',reshape(dufi,(/iip1,jmp1,llm/)))
910c      call WriteField_p('dvfi',reshape(dvfi,(/iip1,jjm,llm/)))
911c      call WriteField_p('dtetafi',reshape(dtetafi,(/iip1,jmp1,llm/)))
912c      call WriteField_p('dpfi',reshape(dpfi,(/iip1,jmp1/)))
[764]913cc$OMP END MASTER
[630]914c     
[1146]915c      do j=1,nqtot
[630]916c        call WriteField_p('dqfi'//trim(int2str(j)),
917c     .                reshape(dqfi(:,:,j),(/iip1,jmp1,llm/)))
918c      enddo
919
920c      ajout des tendances physiques:
921c      ------------------------------
[1146]922          CALL addfi_p( dtphys, leapf, forward   ,
[630]923     $                  ucov, vcov, teta , q   ,ps ,
924     $                 dufi, dvfi, dtetafi , dqfi ,dpfi  )
[1999]925          ! since addfi updates ps(), also update p(), masse() and pk()
926          CALL pression_p(ip1jmp1,ap,bp,ps,p)
927c$OMP BARRIER
928          CALL massdair_p(p,masse)
929c$OMP BARRIER
930          if (pressure_exner) then
[2056]931            CALL exner_hyb_p(ip1jmp1,ps,p,pks,pk,pkf)
[1999]932          else
[2056]933            CALL exner_milieu_p(ip1jmp1,ps,p,pks,pk,pkf)
[1999]934          endif
935c$OMP BARRIER
936         
[1795]937         IF (ok_strato) THEN
938           CALL top_bound_p(vcov,ucov,teta,masse,dtphys)
939         ENDIF
940       
[764]941c$OMP BARRIER
942c$OMP MASTER
[630]943        call VTe(VTphysiq)
944
945        call VTb(VThallo)
[985]946c$OMP END MASTER
[630]947
948        call SetTag(Request_physic,800)
949        call Register_SwapField(ucov,ucov,ip1jmp1,llm,
950     *                               jj_Nb_caldyn,Request_physic)
951       
952        call Register_SwapField(vcov,vcov,ip1jm,llm,
953     *                               jj_Nb_caldyn,Request_physic)
954       
955        call Register_SwapField(teta,teta,ip1jmp1,llm,
956     *                               jj_Nb_caldyn,Request_physic)
957       
[1279]958        call Register_SwapField(masse,masse,ip1jmp1,llm,
959     *                               jj_Nb_caldyn,Request_physic)
960
[1999]961        call Register_SwapField(ps,ps,ip1jmp1,1,
962     *                               jj_Nb_caldyn,Request_physic)
963
[630]964        call Register_SwapField(p,p,ip1jmp1,llmp1,
965     *                               jj_Nb_caldyn,Request_physic)
966       
967        call Register_SwapField(pk,pk,ip1jmp1,llm,
968     *                               jj_Nb_caldyn,Request_physic)
969       
970        call Register_SwapField(phis,phis,ip1jmp1,1,
971     *                               jj_Nb_caldyn,Request_physic)
972       
973        call Register_SwapField(phi,phi,ip1jmp1,llm,
974     *                               jj_Nb_caldyn,Request_physic)
975       
976        call Register_SwapField(w,w,ip1jmp1,llm,
977     *                               jj_Nb_caldyn,Request_physic)
978
[1146]979        do j=1,nqtot
[630]980       
981          call Register_SwapField(q(1,1,j),q(1,1,j),ip1jmp1,llm,
982     *                               jj_Nb_caldyn,Request_physic)
983       
984        enddo
985
986        call SendRequest(Request_Physic)
[985]987c$OMP BARRIER
[630]988        call WaitRequest(Request_Physic)     
989
[985]990c$OMP BARRIER
991c$OMP MASTER
992       call VTe(VThallo)
993       call SetDistrib(jj_Nb_caldyn)
[764]994c$OMP END MASTER
995c$OMP BARRIER
[630]996c
[764]997c  Diagnostique de conservation de l'energie : difference
[630]998      IF (ip_ebil_dyn.ge.1 ) THEN
999          ztit='bil phys'
1000          CALL diagedyn(ztit,2,1,1,dtphys
1001     e  , ucov    , vcov , ps, p ,pk , teta , q(:,:,1), q(:,:,2))
1002      ENDIF
[764]1003
1004cc$OMP MASTER     
1005c      if (debug) then
1006c       call WriteField_p('ucovfi',reshape(ucov,(/iip1,jmp1,llm/)))
1007c       call WriteField_p('vcovfi',reshape(vcov,(/iip1,jjm,llm/)))
1008c       call WriteField_p('tetafi',reshape(teta,(/iip1,jmp1,llm/)))
1009c      endif
1010cc$OMP END MASTER
1011
[630]1012
[1146]1013c-jld
1014c$OMP MASTER
1015         call resume_timer(timer_caldyn)
1016         if (FirstPhysic) then
1017           ok_start_timer=.TRUE.
1018           FirstPhysic=.false.
1019         endif
1020c$OMP END MASTER
1021       ENDIF ! of IF( apphys )
1022
1023      IF(iflag_phys.EQ.2) THEN ! "Newtonian" case
[1454]1024!   Academic case : Simple friction and Newtonan relaxation
1025!   -------------------------------------------------------
[1864]1026c$OMP MASTER
1027         if (FirstPhysic) then
1028           ok_start_timer=.TRUE.
1029           FirstPhysic=.false.
1030         endif
1031c$OMP END MASTER
1032
[630]1033       ijb=ij_begin
1034       ije=ij_end
[1403]1035!$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
1036       do l=1,llm
[1454]1037        teta(ijb:ije,l)=teta(ijb:ije,l)-dtvr*
1038     &         (teta(ijb:ije,l)-tetarappel(ijb:ije,l))*
1039     &                  (knewt_g+knewt_t(l)*clat4(ijb:ije))
1040       enddo ! of do l=1,llm
[1403]1041!$OMP END DO
[630]1042
[1505]1043!$OMP MASTER
1044       if (planet_type.eq."giant") then
1045         ! add an intrinsic heat flux at the base of the atmosphere
1046         teta(ijb:ije,1) = teta(ijb:ije,1)
1047     &        + dtvr * aire(ijb:ije) * ihf / cpp / masse(ijb:ije,1)
1048       endif
1049!$OMP END MASTER
1050!$OMP BARRIER
1051
[630]1052       call Register_Hallo(ucov,ip1jmp1,llm,0,1,1,0,Request_Physic)
1053       call Register_Hallo(vcov,ip1jm,llm,1,1,1,1,Request_Physic)
1054       call SendRequest(Request_Physic)
[1279]1055c$OMP BARRIER
[630]1056       call WaitRequest(Request_Physic)     
[1403]1057c$OMP BARRIER
[1454]1058       call friction_p(ucov,vcov,dtvr)
[1403]1059!$OMP BARRIER
[1454]1060
1061        ! Sponge layer (if any)
1062        IF (ok_strato) THEN
[1795]1063          CALL top_bound_p(vcov,ucov,teta,masse,dtvr)
[1454]1064!$OMP BARRIER
1065        ENDIF ! of IF (ok_strato)
[1146]1066      ENDIF ! of IF(iflag_phys.EQ.2)
[630]1067
1068
[985]1069        CALL pression_p ( ip1jmp1, ap, bp, ps, p                  )
[774]1070c$OMP BARRIER
[1665]1071        if (pressure_exner) then
[2056]1072          CALL exner_hyb_p( ip1jmp1, ps, p, pks, pk, pkf )
[1665]1073        else
[2056]1074          CALL exner_milieu_p( ip1jmp1, ps, p, pks, pk, pkf )
[1520]1075        endif
[774]1076c$OMP BARRIER
[1999]1077        CALL massdair_p(p,masse)
1078c$OMP BARRIER
[630]1079
[774]1080cc$OMP END PARALLEL
[630]1081
1082c-----------------------------------------------------------------------
1083c   dissipation horizontale et verticale  des petites echelles:
1084c   ----------------------------------------------------------
1085
1086      IF(apdiss) THEN
[774]1087cc$OMP  PARALLEL DEFAULT(SHARED)
1088cc$OMP+          PRIVATE(ijb,ije,tppn,tpn,tpps,tps)
[764]1089c$OMP MASTER
[630]1090        call suspend_timer(timer_caldyn)
[949]1091       
1092c       print*,'Entree dans la dissipation : Iteration No ',true_itau
[630]1093c   calcul de l'energie cinetique avant dissipation
[949]1094c       print *,'Passage dans la dissipation'
[630]1095
1096        call VTb(VThallo)
[764]1097c$OMP END MASTER
[630]1098
[764]1099c$OMP BARRIER
[985]1100
[630]1101        call Register_SwapFieldHallo(ucov,ucov,ip1jmp1,llm,
1102     *                          jj_Nb_dissip,1,1,Request_dissip)
1103
1104        call Register_SwapFieldHallo(vcov,vcov,ip1jm,llm,
1105     *                          jj_Nb_dissip,1,1,Request_dissip)
1106
1107        call Register_SwapField(teta,teta,ip1jmp1,llm,
1108     *                          jj_Nb_dissip,Request_dissip)
1109
1110        call Register_SwapField(p,p,ip1jmp1,llmp1,
1111     *                          jj_Nb_dissip,Request_dissip)
1112
1113        call Register_SwapField(pk,pk,ip1jmp1,llm,
1114     *                          jj_Nb_dissip,Request_dissip)
1115
1116        call SendRequest(Request_dissip)       
[985]1117c$OMP BARRIER
[630]1118        call WaitRequest(Request_dissip)       
[985]1119
1120c$OMP BARRIER
1121c$OMP MASTER
[630]1122        call SetDistrib(jj_Nb_dissip)
[949]1123        call VTe(VThallo)
[630]1124        call VTb(VTdissipation)
[949]1125        call start_timer(timer_dissip)
[764]1126c$OMP END MASTER
1127c$OMP BARRIER
1128
[630]1129        call covcont_p(llm,ucov,vcov,ucont,vcont)
1130        call enercin_p(vcov,ucov,vcont,ucont,ecin0)
1131
1132c   dissipation
1133
[985]1134!        CALL FTRACE_REGION_BEGIN("dissip")
[630]1135        CALL dissip_p(vcov,ucov,teta,p,dvdis,dudis,dtetadis)
[985]1136!        CALL FTRACE_REGION_END("dissip")
[764]1137         
[949]1138        ijb=ij_begin
1139        ije=ij_end
1140c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)       
1141        DO l=1,llm
1142          ucov(ijb:ije,l)=ucov(ijb:ije,l)+dudis(ijb:ije,l)
[764]1143        ENDDO
[949]1144c$OMP END DO NOWAIT       
1145        if (pole_sud) ije=ije-iip1
1146c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)       
1147        DO l=1,llm
1148          vcov(ijb:ije,l)=vcov(ijb:ije,l)+dvdis(ijb:ije,l)
[764]1149        ENDDO
[949]1150c$OMP END DO NOWAIT       
[764]1151
[630]1152c       teta=teta+dtetadis
1153
1154
1155c------------------------------------------------------------------------
1156        if (dissip_conservative) then
1157C       On rajoute la tendance due a la transform. Ec -> E therm. cree
1158C       lors de la dissipation
[764]1159c$OMP BARRIER
1160c$OMP MASTER
[630]1161            call suspend_timer(timer_dissip)
[949]1162            call VTb(VThallo)
[985]1163c$OMP END MASTER
[630]1164            call Register_Hallo(ucov,ip1jmp1,llm,1,1,1,1,Request_Dissip)
1165            call Register_Hallo(vcov,ip1jm,llm,1,1,1,1,Request_Dissip)
1166            call SendRequest(Request_Dissip)
[985]1167c$OMP BARRIER
[630]1168            call WaitRequest(Request_Dissip)
[985]1169c$OMP MASTER
[630]1170            call VTe(VThallo)
1171            call resume_timer(timer_dissip)
[764]1172c$OMP END MASTER
[949]1173c$OMP BARRIER           
[630]1174            call covcont_p(llm,ucov,vcov,ucont,vcont)
1175            call enercin_p(vcov,ucov,vcont,ucont,ecin)
1176           
[949]1177            ijb=ij_begin
1178            ije=ij_end
1179c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)           
1180            do l=1,llm
1181              do ij=ijb,ije
1182                dtetaecdt(ij,l)= (ecin0(ij,l)-ecin(ij,l))/ pk(ij,l)
1183                dtetadis(ij,l)=dtetadis(ij,l)+dtetaecdt(ij,l)
[630]1184              enddo
[949]1185            enddo
1186c$OMP END DO NOWAIT           
[1403]1187       endif ! of if (dissip_conservative)
[630]1188
1189       ijb=ij_begin
1190       ije=ij_end
[949]1191c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)           
1192         do l=1,llm
1193           do ij=ijb,ije
[630]1194              teta(ij,l)=teta(ij,l)+dtetadis(ij,l)
[949]1195           enddo
1196         enddo
1197c$OMP END DO NOWAIT         
[630]1198c------------------------------------------------------------------------
1199
1200
1201c    .......        P. Le Van (  ajout  le 17/04/96  )   ...........
1202c   ...      Calcul de la valeur moyenne, unique de h aux poles  .....
1203c
1204
1205        ijb=ij_begin
1206        ije=ij_end
1207         
1208        if (pole_nord) then
[764]1209c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
[630]1210          DO l  =  1, llm
1211            DO ij =  1,iim
1212             tppn(ij)  = aire(  ij    ) * teta(  ij    ,l)
1213            ENDDO
1214             tpn  = SSUM(iim,tppn,1)/apoln
1215
1216            DO ij = 1, iip1
1217             teta(  ij    ,l) = tpn
1218            ENDDO
1219          ENDDO
[764]1220c$OMP END DO NOWAIT
1221
[1665]1222         if (1 == 0) then
1223!!! Ehouarn: lines here 1) kill 1+1=2 in the dynamics
1224!!!                     2) should probably not be here anyway
1225!!! but are kept for those who would want to revert to previous behaviour
[764]1226c$OMP MASTER               
[630]1227          DO ij =  1,iim
1228            tppn(ij)  = aire(  ij    ) * ps (  ij    )
1229          ENDDO
1230            tpn  = SSUM(iim,tppn,1)/apoln
1231 
1232          DO ij = 1, iip1
1233            ps(  ij    ) = tpn
1234          ENDDO
[764]1235c$OMP END MASTER
[1665]1236         endif ! of if (1 == 0)
1237        endif ! of of (pole_nord)
[630]1238       
1239        if (pole_sud) then
[764]1240c$OMP DO SCHEDULE(STATIC,OMP_CHUNK)
[630]1241          DO l  =  1, llm
1242            DO ij =  1,iim
1243             tpps(ij)  = aire(ij+ip1jm) * teta(ij+ip1jm,l)
1244            ENDDO
1245             tps  = SSUM(iim,tpps,1)/apols
1246
1247            DO ij = 1, iip1
1248             teta(ij+ip1jm,l) = tps
1249            ENDDO
1250          ENDDO
[764]1251c$OMP END DO NOWAIT
1252
[1665]1253         if (1 == 0) then
1254!!! Ehouarn: lines here 1) kill 1+1=2 in the dynamics
1255!!!                     2) should probably not be here anyway
1256!!! but are kept for those who would want to revert to previous behaviour
[764]1257c$OMP MASTER               
[630]1258          DO ij =  1,iim
1259            tpps(ij)  = aire(ij+ip1jm) * ps (ij+ip1jm)
1260          ENDDO
1261            tps  = SSUM(iim,tpps,1)/apols
1262 
1263          DO ij = 1, iip1
1264            ps(ij+ip1jm) = tps
1265          ENDDO
[764]1266c$OMP END MASTER
[1665]1267         endif ! of if (1 == 0)
1268        endif ! of if (pole_sud)
[630]1269
[764]1270
1271c$OMP BARRIER
1272c$OMP MASTER
[630]1273        call VTe(VTdissipation)
1274
1275        call stop_timer(timer_dissip)
[949]1276       
[630]1277        call VTb(VThallo)
[985]1278c$OMP END MASTER
[630]1279        call Register_SwapField(ucov,ucov,ip1jmp1,llm,
1280     *                          jj_Nb_caldyn,Request_dissip)
1281
1282        call Register_SwapField(vcov,vcov,ip1jm,llm,
1283     *                          jj_Nb_caldyn,Request_dissip)
1284
1285        call Register_SwapField(teta,teta,ip1jmp1,llm,
1286     *                          jj_Nb_caldyn,Request_dissip)
1287
1288        call Register_SwapField(p,p,ip1jmp1,llmp1,
1289     *                          jj_Nb_caldyn,Request_dissip)
1290
1291        call Register_SwapField(pk,pk,ip1jmp1,llm,
1292     *                          jj_Nb_caldyn,Request_dissip)
1293
1294        call SendRequest(Request_dissip)       
[985]1295c$OMP BARRIER
[630]1296        call WaitRequest(Request_dissip)       
[985]1297
1298c$OMP BARRIER
1299c$OMP MASTER
[630]1300        call SetDistrib(jj_Nb_caldyn)
1301        call VTe(VThallo)
1302        call resume_timer(timer_caldyn)
[961]1303c        print *,'fin dissipation'
[764]1304c$OMP END MASTER
[985]1305c$OMP BARRIER
[1403]1306      END IF ! of IF(apdiss)
[630]1307
[774]1308cc$OMP END PARALLEL
1309
[630]1310c ajout debug
1311c              IF( lafin ) then 
1312c                abort_message = 'Simulation finished'
1313c                call abort_gcm(modname,abort_message,0)
1314c              ENDIF
1315       
1316c   ********************************************************************
1317c   ********************************************************************
1318c   .... fin de l'integration dynamique  et physique pour le pas itau ..
1319c   ********************************************************************
1320c   ********************************************************************
1321
1322c   preparation du pas d'integration suivant  ......
1323cym      call WriteField('ucov',reshape(ucov,(/iip1,jmp1,llm/)))
1324cym      call WriteField('vcov',reshape(vcov,(/iip1,jjm,llm/)))
[774]1325c$OMP MASTER     
[630]1326      call stop_timer(timer_caldyn)
[774]1327c$OMP END MASTER
[630]1328      IF (itau==itaumax) then
[774]1329c$OMP MASTER
[630]1330            call allgather_timer_average
1331
1332      if (mpi_rank==0) then
1333       
1334        print *,'*********************************'
[949]1335        print *,'******    TIMER CALDYN     ******'
1336        do i=0,mpi_size-1
1337          print *,'proc',i,' :   Nb Bandes  :',jj_nb_caldyn(i),
[630]1338     &            '  : temps moyen :',
1339     &             timer_average(jj_nb_caldyn(i),timer_caldyn,i)
1340        enddo
1341     
1342        print *,'*********************************'
[949]1343        print *,'******    TIMER VANLEER    ******'
1344        do i=0,mpi_size-1
1345          print *,'proc',i,' :   Nb Bandes  :',jj_nb_vanleer(i),
[630]1346     &            '  : temps moyen :',
1347     &             timer_average(jj_nb_vanleer(i),timer_vanleer,i)
1348        enddo
1349     
1350        print *,'*********************************'
[949]1351        print *,'******    TIMER DISSIP    ******'
1352        do i=0,mpi_size-1
1353          print *,'proc',i,' :   Nb Bandes  :',jj_nb_dissip(i),
[630]1354     &            '  : temps moyen :',
1355     &             timer_average(jj_nb_dissip(i),timer_dissip,i)
1356        enddo
[949]1357       
1358        print *,'*********************************'
1359        print *,'******    TIMER PHYSIC    ******'
1360        do i=0,mpi_size-1
1361          print *,'proc',i,' :   Nb Bandes  :',jj_nb_physic(i),
[630]1362     &            '  : temps moyen :',
1363     &             timer_average(jj_nb_physic(i),timer_physic,i)
1364        enddo
[949]1365       
[630]1366      endif 
1367     
1368      print *,'Taille du Buffer MPI (REAL*8)',MaxBufferSize
1369      print *,'Taille du Buffer MPI utilise (REAL*8)',MaxBufferSize_Used
1370      print *, 'Temps total ecoule sur la parallelisation :',DiffTime()
1371      print *, 'Temps CPU ecoule sur la parallelisation :',DiffCpuTime()
[985]1372      CALL print_filtre_timer
[1279]1373      call fin_getparam
[630]1374        call finalize_parallel
[774]1375c$OMP END MASTER
[985]1376c$OMP BARRIER
[949]1377        RETURN
[1910]1378      ENDIF ! of IF (itau==itaumax)
[630]1379     
1380      IF ( .NOT.purmats ) THEN
1381c       ........................................................
1382c       ..............  schema matsuno + leapfrog  ..............
1383c       ........................................................
1384
1385            IF(forward. OR. leapf) THEN
1386              itau= itau + 1
[1279]1387!              iday= day_ini+itau/day_step
[1403]1388!              time= REAL(itau-(iday-day_ini)*day_step)/day_step+time_0
[1279]1389!                IF(time.GT.1.) THEN
1390!                  time = time-1.
1391!                  iday = iday+1
1392!                ENDIF
[630]1393            ENDIF
1394
1395
[1286]1396            IF( itau. EQ. itaufinp1 ) then
[630]1397
[1286]1398              if (flag_verif) then
1399                write(79,*) 'ucov',ucov
1400                write(80,*) 'vcov',vcov
1401                write(81,*) 'teta',teta
1402                write(82,*) 'ps',ps
1403                write(83,*) 'q',q
1404                WRITE(85,*) 'q1 = ',q(:,:,1)
1405                WRITE(86,*) 'q3 = ',q(:,:,3)
1406              endif
1407 
1408
[774]1409c$OMP MASTER
[1279]1410              call fin_getparam
[764]1411              call finalize_parallel
[774]1412c$OMP END MASTER
[630]1413              abort_message = 'Simulation finished'
1414              call abort_gcm(modname,abort_message,0)
[985]1415              RETURN
[630]1416            ENDIF
1417c-----------------------------------------------------------------------
1418c   ecriture du fichier histoire moyenne:
1419c   -------------------------------------
1420
1421            IF(MOD(itau,iperiod).EQ.0 .OR. itau.EQ.itaufin) THEN
[774]1422c$OMP BARRIER
[630]1423               IF(itau.EQ.itaufin) THEN
1424                  iav=1
1425               ELSE
1426                  iav=0
1427               ENDIF
1428#ifdef CPP_IOIPSL
[1146]1429             IF (ok_dynzon) THEN
1430              CALL bilan_dyn_p(2,dtvr*iperiod,dtvr*day_step*periodav,
1431     ,             ps,masse,pk,pbaru,pbarv,teta,phi,ucov,vcov,q)
1432              ENDIF !ok_dynzon
[630]1433#endif
[1403]1434               IF (ok_dyn_ave) THEN
1435!$OMP MASTER
1436#ifdef CPP_IOIPSL
1437! Ehouarn: Gather fields and make master send to output
1438                call Gather_Field(vcov,ip1jm,llm,0)
1439                call Gather_Field(ucov,ip1jmp1,llm,0)
1440                call Gather_Field(teta,ip1jmp1,llm,0)
1441                call Gather_Field(pk,ip1jmp1,llm,0)
1442                call Gather_Field(phi,ip1jmp1,llm,0)
1443                do iq=1,nqtot
1444                  call Gather_Field(q(1,1,iq),ip1jmp1,llm,0)
1445                enddo
1446                call Gather_Field(masse,ip1jmp1,llm,0)
1447                call Gather_Field(ps,ip1jmp1,1,0)
1448                call Gather_Field(phis,ip1jmp1,1,0)
1449                if (mpi_rank==0) then
1450                 CALL writedynav(itau,vcov,
1451     &                 ucov,teta,pk,phi,q,masse,ps,phis)
1452                endif
1453#endif
1454!$OMP END MASTER
1455               ENDIF ! of IF (ok_dyn_ave)
1456            ENDIF ! of IF((MOD(itau,iperiod).EQ.0).OR.(itau.EQ.itaufin))
[630]1457
1458c-----------------------------------------------------------------------
1459c   ecriture de la bande histoire:
1460c   ------------------------------
1461
[1403]1462            IF( MOD(itau,iecri).EQ.0) THEN
1463             ! Ehouarn: output only during LF or Backward Matsuno
1464             if (leapf.or.(.not.leapf.and.(.not.forward))) then
[774]1465c$OMP BARRIER
1466c$OMP MASTER
[1146]1467              CALL geopot_p(ip1jmp1,teta,pk,pks,phis,phi)
[774]1468       
[949]1469cym        unat=0.
1470       
[1146]1471              ijb=ij_begin
1472              ije=ij_end
[949]1473       
[1146]1474              if (pole_nord) then
1475                ijb=ij_begin+iip1
1476                unat(1:iip1,:)=0.
1477              endif
[949]1478       
[1146]1479              if (pole_sud) then
1480                ije=ij_end-iip1
1481                unat(ij_end-iip1+1:ij_end,:)=0.
1482              endif
[949]1483           
[1146]1484              do l=1,llm
1485                unat(ijb:ije,l)=ucov(ijb:ije,l)/cu(ijb:ije)
1486              enddo
[630]1487
[1146]1488              ijb=ij_begin
1489              ije=ij_end
1490              if (pole_sud) ije=ij_end-iip1
[949]1491       
[1146]1492              do l=1,llm
1493                vnat(ijb:ije,l)=vcov(ijb:ije,l)/cv(ijb:ije)
1494              enddo
[949]1495       
[630]1496#ifdef CPP_IOIPSL
[1403]1497              if (ok_dyn_ins) then
1498! Ehouarn: Gather fields and make master write to output
1499                call Gather_Field(vcov,ip1jm,llm,0)
1500                call Gather_Field(ucov,ip1jmp1,llm,0)
1501                call Gather_Field(teta,ip1jmp1,llm,0)
1502                call Gather_Field(phi,ip1jmp1,llm,0)
1503                do iq=1,nqtot
1504                  call Gather_Field(q(1,1,iq),ip1jmp1,llm,0)
1505                enddo
1506                call Gather_Field(masse,ip1jmp1,llm,0)
1507                call Gather_Field(ps,ip1jmp1,1,0)
1508                call Gather_Field(phis,ip1jmp1,1,0)
1509                if (mpi_rank==0) then
1510                 CALL writehist(itau,vcov,ucov,teta,phi,q,masse,ps,phis)
1511                endif
[1279]1512!              CALL writehist_p(histid,histvid, itau,vcov,
1513!     &                         ucov,teta,phi,q,masse,ps,phis)
[1403]1514! or use writefield_p
1515!      call WriteField_p('ucov',reshape(ucov,(/iip1,jmp1,llm/)))
1516!      call WriteField_p('vcov',reshape(vcov,(/iip1,jjm,llm/)))
1517!      call WriteField_p('teta',reshape(teta,(/iip1,jmp1,llm/)))
1518!      call WriteField_p('ps',reshape(ps,(/iip1,jmp1/)))
1519              endif ! of if (ok_dyn_ins)
[630]1520#endif
[1146]1521! For some Grads outputs of fields
1522              if (output_grads_dyn) then
1523! Ehouarn: hope this works the way I think it does:
1524                  call Gather_Field(unat,ip1jmp1,llm,0)
1525                  call Gather_Field(vnat,ip1jm,llm,0)
1526                  call Gather_Field(teta,ip1jmp1,llm,0)
1527                  call Gather_Field(ps,ip1jmp1,1,0)
1528                  do iq=1,nqtot
1529                    call Gather_Field(q(1,1,iq),ip1jmp1,llm,0)
1530                  enddo
1531                  if (mpi_rank==0) then
1532#include "write_grads_dyn.h"
1533                  endif
1534              endif ! of if (output_grads_dyn)
[774]1535c$OMP END MASTER
[1403]1536             endif ! of if (leapf.or.(.not.leapf.and.(.not.forward)))
[1146]1537            ENDIF ! of IF(MOD(itau,iecri).EQ.0)
[630]1538
1539            IF(itau.EQ.itaufin) THEN
1540
[774]1541c$OMP BARRIER
1542c$OMP MASTER
[630]1543
[1454]1544!              if (planet_type.eq."earth") then
[1146]1545! Write an Earth-format restart file
1546                CALL dynredem1_p("restart.nc",0.0,
1547     &                           vcov,ucov,teta,q,masse,ps)
[1454]1548!              endif ! of if (planet_type.eq."earth")
[630]1549
[1279]1550!              CLOSE(99)
[774]1551c$OMP END MASTER
[1146]1552            ENDIF ! of IF (itau.EQ.itaufin)
[630]1553
1554c-----------------------------------------------------------------------
1555c   gestion de l'integration temporelle:
1556c   ------------------------------------
1557
1558            IF( MOD(itau,iperiod).EQ.0 )    THEN
1559                    GO TO 1
1560            ELSE IF ( MOD(itau-1,iperiod). EQ. 0 ) THEN
1561
1562                   IF( forward )  THEN
1563c      fin du pas forward et debut du pas backward
1564
1565                      forward = .FALSE.
1566                        leapf = .FALSE.
1567                           GO TO 2
1568
1569                   ELSE
1570c      fin du pas backward et debut du premier pas leapfrog
1571
1572                        leapf =  .TRUE.
1573                        dt  =  2.*dtvr
1574                        GO TO 2
1575                   END IF
1576            ELSE
1577
1578c      ......   pas leapfrog  .....
1579
1580                 leapf = .TRUE.
1581                 dt  = 2.*dtvr
1582                 GO TO 2
[1146]1583            END IF ! of IF (MOD(itau,iperiod).EQ.0)
1584                   !    ELSEIF (MOD(itau-1,iperiod).EQ.0)
[630]1585
1586
[1146]1587      ELSE ! of IF (.not.purmats)
1588
[630]1589c       ........................................................
1590c       ..............       schema  matsuno        ...............
1591c       ........................................................
1592            IF( forward )  THEN
1593
1594             itau =  itau + 1
[1279]1595!             iday = day_ini+itau/day_step
[1403]1596!             time = REAL(itau-(iday-day_ini)*day_step)/day_step+time_0
[1279]1597!
1598!                  IF(time.GT.1.) THEN
1599!                   time = time-1.
1600!                   iday = iday+1
1601!                  ENDIF
[630]1602
1603               forward =  .FALSE.
1604               IF( itau. EQ. itaufinp1 ) then 
[774]1605c$OMP MASTER
[1279]1606                 call fin_getparam
[949]1607                 call finalize_parallel
[774]1608c$OMP END MASTER
[630]1609                 abort_message = 'Simulation finished'
1610                 call abort_gcm(modname,abort_message,0)
[985]1611                 RETURN
[630]1612               ENDIF
1613               GO TO 2
1614
[1403]1615            ELSE ! of IF(forward) i.e. backward step
[630]1616
[1146]1617              IF(MOD(itau,iperiod).EQ.0 .OR. itau.EQ.itaufin) THEN
[630]1618               IF(itau.EQ.itaufin) THEN
1619                  iav=1
1620               ELSE
1621                  iav=0
1622               ENDIF
1623#ifdef CPP_IOIPSL
[1146]1624               IF (ok_dynzon) THEN
1625               CALL bilan_dyn_p(2,dtvr*iperiod,dtvr*day_step*periodav,
[985]1626     ,           ps,masse,pk,pbaru,pbarv,teta,phi,ucov,vcov,q)
[1146]1627               END IF !ok_dynzon
[630]1628#endif
[1403]1629               IF (ok_dyn_ave) THEN
1630!$OMP MASTER
1631#ifdef CPP_IOIPSL
1632! Ehouarn: Gather fields and make master send to output
1633                call Gather_Field(vcov,ip1jm,llm,0)
1634                call Gather_Field(ucov,ip1jmp1,llm,0)
1635                call Gather_Field(teta,ip1jmp1,llm,0)
1636                call Gather_Field(pk,ip1jmp1,llm,0)
1637                call Gather_Field(phi,ip1jmp1,llm,0)
1638                do iq=1,nqtot
1639                  call Gather_Field(q(1,1,iq),ip1jmp1,llm,0)
1640                enddo
1641                call Gather_Field(masse,ip1jmp1,llm,0)
1642                call Gather_Field(ps,ip1jmp1,1,0)
1643                call Gather_Field(phis,ip1jmp1,1,0)
1644                if (mpi_rank==0) then
1645                 CALL writedynav(itau,vcov,
1646     &                 ucov,teta,pk,phi,q,masse,ps,phis)
1647                endif
1648#endif
1649!$OMP END MASTER
1650               ENDIF ! of IF (ok_dyn_ave)
1651
[1146]1652              ENDIF ! of IF(MOD(itau,iperiod).EQ.0 .OR. itau.EQ.itaufin)
[630]1653
[1146]1654
[1403]1655               IF(MOD(itau,iecri         ).EQ.0) THEN
1656c              IF(MOD(itau,iecri*day_step).EQ.0) THEN
[774]1657c$OMP BARRIER
1658c$OMP MASTER
[1146]1659                CALL geopot_p(ip1jmp1,teta,pk,pks,phis,phi)
[630]1660
1661cym        unat=0.
[1146]1662                ijb=ij_begin
1663                ije=ij_end
[949]1664       
[1146]1665                if (pole_nord) then
1666                  ijb=ij_begin+iip1
1667                  unat(1:iip1,:)=0.
1668                endif
[949]1669       
[1146]1670                if (pole_sud) then
1671                  ije=ij_end-iip1
1672                  unat(ij_end-iip1+1:ij_end,:)=0.
1673                endif
[949]1674           
[1146]1675                do l=1,llm
1676                  unat(ijb:ije,l)=ucov(ijb:ije,l)/cu(ijb:ije)
1677                enddo
[630]1678
[1146]1679                ijb=ij_begin
1680                ije=ij_end
1681                if (pole_sud) ije=ij_end-iip1
[949]1682       
[1146]1683                do l=1,llm
1684                  vnat(ijb:ije,l)=vcov(ijb:ije,l)/cv(ijb:ije)
1685                enddo
[630]1686
1687#ifdef CPP_IOIPSL
[1403]1688              if (ok_dyn_ins) then
1689! Ehouarn: Gather fields and make master send to output
1690                call Gather_Field(vcov,ip1jm,llm,0)
1691                call Gather_Field(ucov,ip1jmp1,llm,0)
1692                call Gather_Field(teta,ip1jmp1,llm,0)
1693                call Gather_Field(phi,ip1jmp1,llm,0)
1694                do iq=1,nqtot
1695                  call Gather_Field(q(1,1,iq),ip1jmp1,llm,0)
1696                enddo
1697                call Gather_Field(masse,ip1jmp1,llm,0)
1698                call Gather_Field(ps,ip1jmp1,1,0)
1699                call Gather_Field(phis,ip1jmp1,1,0)
1700                if (mpi_rank==0) then
1701                 CALL writehist(itau,vcov,ucov,teta,phi,q,masse,ps,phis)
1702                endif
[1279]1703!                CALL writehist_p(histid, histvid, itau,vcov ,
1704!     &                           ucov,teta,phi,q,masse,ps,phis)
[1403]1705              endif ! of if (ok_dyn_ins)
[1146]1706#endif
1707! For some Grads output (but does it work?)
1708                if (output_grads_dyn) then
1709                  call Gather_Field(unat,ip1jmp1,llm,0)
1710                  call Gather_Field(vnat,ip1jm,llm,0)
1711                  call Gather_Field(teta,ip1jmp1,llm,0)
1712                  call Gather_Field(ps,ip1jmp1,1,0)
1713                  do iq=1,nqtot
1714                    call Gather_Field(q(1,1,iq),ip1jmp1,llm,0)
1715                  enddo
[630]1716c     
[1146]1717                  if (mpi_rank==0) then
1718#include "write_grads_dyn.h"
1719                  endif
1720                endif ! of if (output_grads_dyn)
[630]1721
[774]1722c$OMP END MASTER
[1403]1723              ENDIF ! of IF(MOD(itau,iecri).EQ.0)
[630]1724
[1146]1725              IF(itau.EQ.itaufin) THEN
[1454]1726!                if (planet_type.eq."earth") then
[774]1727c$OMP MASTER
1728                   CALL dynredem1_p("restart.nc",0.0,
[1146]1729     .                               vcov,ucov,teta,q,masse,ps)
[774]1730c$OMP END MASTER
[1454]1731!                endif ! of if (planet_type.eq."earth")
[1146]1732              ENDIF ! of IF(itau.EQ.itaufin)
[630]1733
[1146]1734              forward = .TRUE.
1735              GO TO  1
[630]1736
[1146]1737            ENDIF ! of IF (forward)
1738
1739      END IF ! of IF(.not.purmats)
[774]1740c$OMP MASTER
[1279]1741      call fin_getparam
[1146]1742      call finalize_parallel
[774]1743c$OMP END MASTER
[1146]1744      RETURN
[630]1745      END
Note: See TracBrowser for help on using the repository browser.