source: LMDZ5/trunk/libf/dyn3d/leapfrog.F @ 1614

Last change on this file since 1614 was 1614, checked in by Ehouarn Millour, 12 years ago

Correction to enforce having 1+1=2 in the dynamics.
Still not sure why changing surface pressure during dissipation step leads to having 1+1!=2. But clearly there is no reason to recompute polar surface pressure during a dissipation step.
EM

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 25.2 KB
Line 
1!
2! $Id: leapfrog.F 1614 2012-02-03 10:07:08Z emillour $
3!
4c
5c
6      SUBROUTINE leapfrog(ucov,vcov,teta,ps,masse,phis,q,clesphy0,
7     &                    time_0)
8
9
10cIM : pour sortir les param. du modele dans un fis. netcdf 110106
11#ifdef CPP_IOIPSL
12      use IOIPSL
13#endif
14      USE infotrac
15      USE guide_mod, ONLY : guide_main
16      USE write_field
17      USE control_mod
18      IMPLICIT NONE
19
20c      ......   Version  du 10/01/98    ..........
21
22c             avec  coordonnees  verticales hybrides
23c   avec nouveaux operat. dissipation * ( gradiv2,divgrad2,nxgraro2 )
24
25c=======================================================================
26c
27c   Auteur:  P. Le Van /L. Fairhead/F.Hourdin
28c   -------
29c
30c   Objet:
31c   ------
32c
33c   GCM LMD nouvelle grille
34c
35c=======================================================================
36c
37c  ... Dans inigeom , nouveaux calculs pour les elongations  cu , cv
38c      et possibilite d'appeler une fonction f(y)  a derivee tangente
39c      hyperbolique a la  place de la fonction a derivee sinusoidale.
40
41c  ... Possibilite de choisir le shema pour l'advection de
42c        q  , en modifiant iadv dans traceur.def  (10/02) .
43c
44c      Pour Van-Leer + Vapeur d'eau saturee, iadv(1)=4. (F.Codron,10/99)
45c      Pour Van-Leer iadv=10
46c
47c-----------------------------------------------------------------------
48c   Declarations:
49c   -------------
50
51#include "dimensions.h"
52#include "paramet.h"
53#include "comconst.h"
54#include "comdissnew.h"
55#include "comvert.h"
56#include "comgeom.h"
57#include "logic.h"
58#include "temps.h"
59#include "ener.h"
60#include "description.h"
61#include "serre.h"
62!#include "com_io_dyn.h"
63#include "iniprint.h"
64#include "academic.h"
65
66! FH 2008/05/09 On elimine toutes les clefs physiques dans la dynamique
67! #include "clesphys.h"
68
69      INTEGER         longcles
70      PARAMETER     ( longcles = 20 )
71      REAL  clesphy0( longcles )
72
73      real zqmin,zqmax
74
75c   variables dynamiques
76      REAL vcov(ip1jm,llm),ucov(ip1jmp1,llm) ! vents covariants
77      REAL teta(ip1jmp1,llm)                 ! temperature potentielle
78      REAL q(ip1jmp1,llm,nqtot)               ! champs advectes
79      REAL ps(ip1jmp1)                       ! pression  au sol
80      REAL p (ip1jmp1,llmp1  )               ! pression aux interfac.des couches
81      REAL pks(ip1jmp1)                      ! exner au  sol
82      REAL pk(ip1jmp1,llm)                   ! exner au milieu des couches
83      REAL pkf(ip1jmp1,llm)                  ! exner filt.au milieu des couches
84      REAL masse(ip1jmp1,llm)                ! masse d'air
85      REAL phis(ip1jmp1)                     ! geopotentiel au sol
86      REAL phi(ip1jmp1,llm)                  ! geopotentiel
87      REAL w(ip1jmp1,llm)                    ! vitesse verticale
88
89c variables dynamiques intermediaire pour le transport
90      REAL pbaru(ip1jmp1,llm),pbarv(ip1jm,llm) !flux de masse
91
92c   variables dynamiques au pas -1
93      REAL vcovm1(ip1jm,llm),ucovm1(ip1jmp1,llm)
94      REAL tetam1(ip1jmp1,llm),psm1(ip1jmp1)
95      REAL massem1(ip1jmp1,llm)
96
97c   tendances dynamiques
98      REAL dv(ip1jm,llm),du(ip1jmp1,llm)
99      REAL dteta(ip1jmp1,llm),dq(ip1jmp1,llm,nqtot),dp(ip1jmp1)
100
101c   tendances de la dissipation
102      REAL dvdis(ip1jm,llm),dudis(ip1jmp1,llm)
103      REAL dtetadis(ip1jmp1,llm)
104
105c   tendances physiques
106      REAL dvfi(ip1jm,llm),dufi(ip1jmp1,llm)
107      REAL dtetafi(ip1jmp1,llm),dqfi(ip1jmp1,llm,nqtot),dpfi(ip1jmp1)
108
109c   variables pour le fichier histoire
110      REAL dtav      ! intervalle de temps elementaire
111
112      REAL tppn(iim),tpps(iim),tpn,tps
113c
114      INTEGER itau,itaufinp1,iav
115!      INTEGER  iday ! jour julien
116      REAL       time
117
118      REAL  SSUM
119      REAL time_0 , finvmaold(ip1jmp1,llm)
120
121cym      LOGICAL  lafin
122      LOGICAL :: lafin=.false.
123      INTEGER ij,iq,l
124      INTEGER ik
125
126      real time_step, t_wrt, t_ops
127
128!      REAL rdayvrai,rdaym_ini
129! jD_cur: jour julien courant
130! jH_cur: heure julienne courante
131      REAL :: jD_cur, jH_cur
132      INTEGER :: an, mois, jour
133      REAL :: secondes
134
135      LOGICAL first,callinigrads
136cIM : pour sortir les param. du modele dans un fis. netcdf 110106
137      save first
138      data first/.true./
139      real dt_cum
140      character*10 infile
141      integer zan, tau0, thoriid
142      integer nid_ctesGCM
143      save nid_ctesGCM
144      real degres
145      real rlong(iip1), rlatg(jjp1)
146      real zx_tmp_2d(iip1,jjp1)
147      integer ndex2d(iip1*jjp1)
148      logical ok_sync
149      parameter (ok_sync = .true.)
150      logical physic
151
152      data callinigrads/.true./
153      character*10 string10
154
155      REAL alpha(ip1jmp1,llm),beta(ip1jmp1,llm)
156      REAL :: flxw(ip1jmp1,llm)  ! flux de masse verticale
157
158c+jld variables test conservation energie
159      REAL ecin(ip1jmp1,llm),ecin0(ip1jmp1,llm)
160C     Tendance de la temp. potentiel d (theta)/ d t due a la
161C     tansformation d'energie cinetique en energie thermique
162C     cree par la dissipation
163      REAL dtetaecdt(ip1jmp1,llm)
164      REAL vcont(ip1jm,llm),ucont(ip1jmp1,llm)
165      REAL vnat(ip1jm,llm),unat(ip1jmp1,llm)
166      REAL      d_h_vcol, d_qt, d_qw, d_ql, d_ec
167      CHARACTER*15 ztit
168!IM   INTEGER   ip_ebil_dyn  ! PRINT level for energy conserv. diag.
169!IM   SAVE      ip_ebil_dyn
170!IM   DATA      ip_ebil_dyn/0/
171c-jld
172
173      character*80 dynhist_file, dynhistave_file
174      character(len=*),parameter :: modname="leapfrog"
175      character*80 abort_message
176
177      logical dissip_conservative
178      save dissip_conservative
179      data dissip_conservative/.true./
180
181      LOGICAL prem
182      save prem
183      DATA prem/.true./
184      INTEGER testita
185      PARAMETER (testita = 9)
186
187      logical , parameter :: flag_verif = .false.
188     
189
190      integer itau_w   ! pas de temps ecriture = itap + itau_phy
191
192
193      itaufin   = nday*day_step
194      itaufinp1 = itaufin +1
195      itau = 0
196      physic=.true.
197      if (iflag_phys==0.or.iflag_phys==2) physic=.false.
198
199c      iday = day_ini+itau/day_step
200c      time = REAL(itau-(iday-day_ini)*day_step)/day_step+time_0
201c         IF(time.GT.1.) THEN
202c          time = time-1.
203c          iday = iday+1
204c         ENDIF
205
206
207c-----------------------------------------------------------------------
208c   On initialise la pression et la fonction d'Exner :
209c   --------------------------------------------------
210
211      dq(:,:,:)=0.
212      CALL pression ( ip1jmp1, ap, bp, ps, p       )
213      if (disvert_type==1) then
214        CALL exner_hyb( ip1jmp1, ps, p,alpha,beta, pks, pk, pkf )
215      else ! we assume that we are in the disvert_type==2 case
216        CALL exner_milieu( ip1jmp1, ps, p, beta, pks, pk, pkf )
217      endif
218
219c-----------------------------------------------------------------------
220c   Debut de l'integration temporelle:
221c   ----------------------------------
222
223   1  CONTINUE ! Matsuno Forward step begins here
224
225      jD_cur = jD_ref + day_ini - day_ref +                             &
226     &          int (itau * dtvr / daysec)
227      jH_cur = jH_ref + start_time +                                    &
228     &          (itau * dtvr / daysec - int(itau * dtvr / daysec))
229      jD_cur = jD_cur + int(jH_cur)
230      jH_cur = jH_cur - int(jH_cur)
231
232
233#ifdef CPP_IOIPSL
234      if (ok_guide) then
235        call guide_main(itau,ucov,vcov,teta,q,masse,ps)
236      endif
237#endif
238
239
240c
241c     IF( MOD( itau, 10* day_step ).EQ.0 )  THEN
242c       CALL  test_period ( ucov,vcov,teta,q,p,phis )
243c       PRINT *,' ----   Test_period apres continue   OK ! -----', itau
244c     ENDIF
245c
246
247! Save fields obtained at previous time step as '...m1'
248      CALL SCOPY( ijmllm ,vcov , 1, vcovm1 , 1 )
249      CALL SCOPY( ijp1llm,ucov , 1, ucovm1 , 1 )
250      CALL SCOPY( ijp1llm,teta , 1, tetam1 , 1 )
251      CALL SCOPY( ijp1llm,masse, 1, massem1, 1 )
252      CALL SCOPY( ip1jmp1, ps  , 1,   psm1 , 1 )
253
254      forward = .TRUE.
255      leapf   = .FALSE.
256      dt      =  dtvr
257
258c   ...    P.Le Van .26/04/94  ....
259
260      CALL SCOPY   ( ijp1llm,   masse, 1, finvmaold,     1 )
261      CALL filtreg ( finvmaold ,jjp1, llm, -2,2, .TRUE., 1 )
262
263   2  CONTINUE ! Matsuno backward or leapfrog step begins here
264
265c-----------------------------------------------------------------------
266
267c   date:
268c   -----
269
270
271c   gestion des appels de la physique et des dissipations:
272c   ------------------------------------------------------
273c
274c   ...    P.Le Van  ( 6/02/95 )  ....
275
276      apphys = .FALSE.
277      statcl = .FALSE.
278      conser = .FALSE.
279      apdiss = .FALSE.
280
281      IF( purmats ) THEN
282      ! Purely Matsuno time stepping
283         IF( MOD(itau,iconser) .EQ.0.AND.  forward    ) conser = .TRUE.
284         IF( MOD(itau,dissip_period ).EQ.0.AND..NOT.forward )
285     s        apdiss = .TRUE.
286         IF( MOD(itau,iphysiq ).EQ.0.AND..NOT.forward
287     s          .and. physic                        ) apphys = .TRUE.
288      ELSE
289      ! Leapfrog/Matsuno time stepping
290         IF( MOD(itau   ,iconser) .EQ. 0              ) conser = .TRUE.
291         IF( MOD(itau+1,dissip_period).EQ.0 .AND. .NOT. forward )
292     s        apdiss = .TRUE.
293         IF( MOD(itau+1,iphysiq).EQ.0.AND.physic       ) apphys=.TRUE.
294      END IF
295
296! Ehouarn: for Shallow Water case (ie: 1 vertical layer),
297!          supress dissipation step
298      if (llm.eq.1) then
299        apdiss=.false.
300      endif
301
302c-----------------------------------------------------------------------
303c   calcul des tendances dynamiques:
304c   --------------------------------
305
306      ! compute geopotential phi()
307      CALL geopot  ( ip1jmp1, teta  , pk , pks,  phis  , phi   )
308
309      time = jD_cur + jH_cur
310      CALL caldyn
311     $  ( itau,ucov,vcov,teta,ps,masse,pk,pkf,phis ,
312     $    phi,conser,du,dv,dteta,dp,w, pbaru,pbarv, time )
313
314
315c-----------------------------------------------------------------------
316c   calcul des tendances advection des traceurs (dont l'humidite)
317c   -------------------------------------------------------------
318
319      IF( forward. OR . leapf )  THEN
320
321         CALL caladvtrac(q,pbaru,pbarv,
322     *        p, masse, dq,  teta,
323     .        flxw, pk)
324         
325         IF (offline) THEN
326Cmaf stokage du flux de masse pour traceurs OFF-LINE
327
328#ifdef CPP_IOIPSL
329           CALL fluxstokenc(pbaru,pbarv,masse,teta,phi,phis,
330     .   dtvr, itau)
331#endif
332
333
334         ENDIF ! of IF (offline)
335c
336      ENDIF ! of IF( forward. OR . leapf )
337
338
339c-----------------------------------------------------------------------
340c   integrations dynamique et traceurs:
341c   ----------------------------------
342
343
344       CALL integrd ( 2,vcovm1,ucovm1,tetam1,psm1,massem1 ,
345     $         dv,du,dteta,dq,dp,vcov,ucov,teta,q,ps,masse,phis ,
346     $              finvmaold                                    )
347
348
349c .P.Le Van (26/04/94  ajout de  finvpold dans l'appel d'integrd)
350c
351c-----------------------------------------------------------------------
352c   calcul des tendances physiques:
353c   -------------------------------
354c    ########   P.Le Van ( Modif le  6/02/95 )   ###########
355c
356       IF( purmats )  THEN
357          IF( itau.EQ.itaufin.AND..NOT.forward ) lafin = .TRUE.
358       ELSE
359          IF( itau+1. EQ. itaufin )              lafin = .TRUE.
360       ENDIF
361c
362c
363       IF( apphys )  THEN
364c
365c     .......   Ajout   P.Le Van ( 17/04/96 )   ...........
366c
367
368         CALL pression (  ip1jmp1, ap, bp, ps,  p      )
369         if (disvert_type==1) then
370           CALL exner_hyb(  ip1jmp1, ps, p,alpha,beta,pks, pk, pkf )
371         else ! we assume that we are in the disvert_type==2 case
372           CALL exner_milieu( ip1jmp1, ps, p, beta, pks, pk, pkf )
373         endif
374
375!           rdaym_ini  = itau * dtvr / daysec
376!           rdayvrai   = rdaym_ini  + day_ini
377!           jD_cur = jD_ref + day_ini - day_ref
378!     $        + int (itau * dtvr / daysec)
379!           jH_cur = jH_ref +                                            &
380!     &              (itau * dtvr / daysec - int(itau * dtvr / daysec))
381           jD_cur = jD_ref + day_ini - day_ref +                        &
382     &          int (itau * dtvr / daysec)
383           jH_cur = jH_ref + start_time +                               &
384     &          (itau * dtvr / daysec - int(itau * dtvr / daysec))
385           jD_cur = jD_cur + int(jH_cur)
386           jH_cur = jH_cur - int(jH_cur)
387!         write(lunout,*)'itau, jD_cur = ', itau, jD_cur, jH_cur
388!         call ju2ymds(jD_cur+jH_cur, an, mois, jour, secondes)
389!         write(lunout,*)'current date = ',an, mois, jour, secondes
390
391c rajout debug
392c       lafin = .true.
393
394
395c   Inbterface avec les routines de phylmd (phymars ... )
396c   -----------------------------------------------------
397
398c+jld
399
400c  Diagnostique de conservation de l'énergie : initialisation
401         IF (ip_ebil_dyn.ge.1 ) THEN
402          ztit='bil dyn'
403! Ehouarn: be careful, diagedyn is Earth-specific (includes ../phylmd/..)!
404           IF (planet_type.eq."earth") THEN
405            CALL diagedyn(ztit,2,1,1,dtphys
406     &    , ucov    , vcov , ps, p ,pk , teta , q(:,:,1), q(:,:,2))
407           ENDIF
408         ENDIF ! of IF (ip_ebil_dyn.ge.1 )
409c-jld
410#ifdef CPP_IOIPSL
411cIM : pour sortir les param. du modele dans un fis. netcdf 110106
412         IF (first) THEN
413          first=.false.
414#include "ini_paramLMDZ_dyn.h"
415         ENDIF
416c
417#include "write_paramLMDZ_dyn.h"
418c
419#endif
420! #endif of #ifdef CPP_IOIPSL
421         CALL calfis( lafin , jD_cur, jH_cur,
422     $               ucov,vcov,teta,q,masse,ps,p,pk,phis,phi ,
423     $               du,dv,dteta,dq,
424     $               flxw,
425     $               clesphy0, dufi,dvfi,dtetafi,dqfi,dpfi  )
426
427         IF (ok_strato) THEN
428           CALL top_bound( vcov,ucov,teta,masse,dufi,dvfi,dtetafi)
429         ENDIF
430       
431c      ajout des tendances physiques:
432c      ------------------------------
433          CALL addfi( dtphys, leapf, forward   ,
434     $                  ucov, vcov, teta , q   ,ps ,
435     $                 dufi, dvfi, dtetafi , dqfi ,dpfi  )
436c
437c  Diagnostique de conservation de l'énergie : difference
438         IF (ip_ebil_dyn.ge.1 ) THEN
439          ztit='bil phys'
440          IF (planet_type.eq."earth") THEN
441           CALL diagedyn(ztit,2,1,1,dtphys
442     &     , ucov    , vcov , ps, p ,pk , teta , q(:,:,1), q(:,:,2))
443          ENDIF
444         ENDIF ! of IF (ip_ebil_dyn.ge.1 )
445
446       ENDIF ! of IF( apphys )
447
448      IF(iflag_phys.EQ.2) THEN ! "Newtonian" case
449!   Academic case : Simple friction and Newtonan relaxation
450!   -------------------------------------------------------
451        DO l=1,llm   
452          DO ij=1,ip1jmp1
453           teta(ij,l)=teta(ij,l)-dtvr*
454     &      (teta(ij,l)-tetarappel(ij,l))*(knewt_g+knewt_t(l)*clat4(ij))
455          ENDDO
456        ENDDO ! of DO l=1,llm
457       
458        if (planet_type.eq."giant") then
459          ! add an intrinsic heat flux at the base of the atmosphere
460          teta(:,1)=teta(:,1)+dtvr*aire(:)*ihf/cpp/masse(:,1)
461        endif
462
463        call friction(ucov,vcov,dtvr)
464       
465        ! Sponge layer (if any)
466        IF (ok_strato) THEN
467          dufi(:,:)=0.
468          dvfi(:,:)=0.
469          dtetafi(:,:)=0.
470          dqfi(:,:,:)=0.
471          dpfi(:)=0.
472          CALL top_bound(vcov,ucov,teta,masse,dufi,dvfi,dtetafi)
473          CALL addfi( dtvr, leapf, forward   ,
474     $                  ucov, vcov, teta , q   ,ps ,
475     $                 dufi, dvfi, dtetafi , dqfi ,dpfi  )
476        ENDIF ! of IF (ok_strato)
477      ENDIF ! of IF (iflag_phys.EQ.2)
478
479
480c-jld
481
482        CALL pression ( ip1jmp1, ap, bp, ps, p                  )
483        if (disvert_type==1) then
484          CALL exner_hyb( ip1jmp1, ps, p,alpha,beta, pks, pk, pkf )
485        else ! we assume that we are in the disvert_type==2 case
486          CALL exner_milieu( ip1jmp1, ps, p, beta, pks, pk, pkf )
487        endif
488
489
490c-----------------------------------------------------------------------
491c   dissipation horizontale et verticale  des petites echelles:
492c   ----------------------------------------------------------
493
494      IF(apdiss) THEN
495
496
497c   calcul de l'energie cinetique avant dissipation
498        call covcont(llm,ucov,vcov,ucont,vcont)
499        call enercin(vcov,ucov,vcont,ucont,ecin0)
500
501c   dissipation
502        CALL dissip(vcov,ucov,teta,p,dvdis,dudis,dtetadis)
503        ucov=ucov+dudis
504        vcov=vcov+dvdis
505c       teta=teta+dtetadis
506
507
508c------------------------------------------------------------------------
509        if (dissip_conservative) then
510C       On rajoute la tendance due a la transform. Ec -> E therm. cree
511C       lors de la dissipation
512            call covcont(llm,ucov,vcov,ucont,vcont)
513            call enercin(vcov,ucov,vcont,ucont,ecin)
514            dtetaecdt= (ecin0-ecin)/ pk
515c           teta=teta+dtetaecdt
516            dtetadis=dtetadis+dtetaecdt
517        endif
518        teta=teta+dtetadis
519c------------------------------------------------------------------------
520
521
522c    .......        P. Le Van (  ajout  le 17/04/96  )   ...........
523c   ...      Calcul de la valeur moyenne, unique de h aux poles  .....
524c
525
526        DO l  =  1, llm
527          DO ij =  1,iim
528           tppn(ij)  = aire(  ij    ) * teta(  ij    ,l)
529           tpps(ij)  = aire(ij+ip1jm) * teta(ij+ip1jm,l)
530          ENDDO
531           tpn  = SSUM(iim,tppn,1)/apoln
532           tps  = SSUM(iim,tpps,1)/apols
533
534          DO ij = 1, iip1
535           teta(  ij    ,l) = tpn
536           teta(ij+ip1jm,l) = tps
537          ENDDO
538        ENDDO
539
540        if (1 == 0) then
541!!! Ehouarn: lines here 1) kill 1+1=2 in the dynamics
542!!!                     2) should probably not be here anyway
543!!! but are kept for those who would want to revert to previous behaviour
544           DO ij =  1,iim
545             tppn(ij)  = aire(  ij    ) * ps (  ij    )
546             tpps(ij)  = aire(ij+ip1jm) * ps (ij+ip1jm)
547           ENDDO
548             tpn  = SSUM(iim,tppn,1)/apoln
549             tps  = SSUM(iim,tpps,1)/apols
550
551           DO ij = 1, iip1
552             ps(  ij    ) = tpn
553             ps(ij+ip1jm) = tps
554           ENDDO
555        endif ! of if (1 == 0)
556
557      END IF ! of IF(apdiss)
558
559c ajout debug
560c              IF( lafin ) then 
561c                abort_message = 'Simulation finished'
562c                call abort_gcm(modname,abort_message,0)
563c              ENDIF
564       
565c   ********************************************************************
566c   ********************************************************************
567c   .... fin de l'integration dynamique  et physique pour le pas itau ..
568c   ********************************************************************
569c   ********************************************************************
570
571c   preparation du pas d'integration suivant  ......
572
573      IF ( .NOT.purmats ) THEN
574c       ........................................................
575c       ..............  schema matsuno + leapfrog  ..............
576c       ........................................................
577
578            IF(forward. OR. leapf) THEN
579              itau= itau + 1
580c              iday= day_ini+itau/day_step
581c              time= REAL(itau-(iday-day_ini)*day_step)/day_step+time_0
582c                IF(time.GT.1.) THEN
583c                  time = time-1.
584c                  iday = iday+1
585c                ENDIF
586            ENDIF
587
588
589            IF( itau. EQ. itaufinp1 ) then 
590              if (flag_verif) then
591                write(79,*) 'ucov',ucov
592                write(80,*) 'vcov',vcov
593                write(81,*) 'teta',teta
594                write(82,*) 'ps',ps
595                write(83,*) 'q',q
596                WRITE(85,*) 'q1 = ',q(:,:,1)
597                WRITE(86,*) 'q3 = ',q(:,:,3)
598              endif
599
600              abort_message = 'Simulation finished'
601
602              call abort_gcm(modname,abort_message,0)
603            ENDIF
604c-----------------------------------------------------------------------
605c   ecriture du fichier histoire moyenne:
606c   -------------------------------------
607
608            IF(MOD(itau,iperiod).EQ.0 .OR. itau.EQ.itaufin) THEN
609               IF(itau.EQ.itaufin) THEN
610                  iav=1
611               ELSE
612                  iav=0
613               ENDIF
614               
615               IF (ok_dynzon) THEN
616#ifdef CPP_IOIPSL
617                 CALL bilan_dyn(2,dtvr*iperiod,dtvr*day_step*periodav,
618     &                 ps,masse,pk,pbaru,pbarv,teta,phi,ucov,vcov,q)
619#endif
620               END IF
621               IF (ok_dyn_ave) THEN
622#ifdef CPP_IOIPSL
623                 CALL writedynav(itau,vcov,
624     &                 ucov,teta,pk,phi,q,masse,ps,phis)
625#endif
626               ENDIF
627
628            ENDIF ! of IF((MOD(itau,iperiod).EQ.0).OR.(itau.EQ.itaufin))
629
630c-----------------------------------------------------------------------
631c   ecriture de la bande histoire:
632c   ------------------------------
633
634            IF( MOD(itau,iecri).EQ.0) THEN
635             ! Ehouarn: output only during LF or Backward Matsuno
636             if (leapf.or.(.not.leapf.and.(.not.forward))) then
637              CALL geopot(ip1jmp1,teta,pk,pks,phis,phi)
638              unat=0.
639              do l=1,llm
640                unat(iip2:ip1jm,l)=ucov(iip2:ip1jm,l)/cu(iip2:ip1jm)
641                vnat(:,l)=vcov(:,l)/cv(:)
642              enddo
643#ifdef CPP_IOIPSL
644              if (ok_dyn_ins) then
645!               write(lunout,*) "leapfrog: call writehist, itau=",itau
646               CALL writehist(itau,vcov,ucov,teta,phi,q,masse,ps,phis)
647!               call WriteField('ucov',reshape(ucov,(/iip1,jmp1,llm/)))
648!               call WriteField('vcov',reshape(vcov,(/iip1,jjm,llm/)))
649!              call WriteField('teta',reshape(teta,(/iip1,jmp1,llm/)))
650!               call WriteField('ps',reshape(ps,(/iip1,jmp1/)))
651!               call WriteField('masse',reshape(masse,(/iip1,jmp1,llm/)))
652              endif ! of if (ok_dyn_ins)
653#endif
654! For some Grads outputs of fields
655              if (output_grads_dyn) then
656#include "write_grads_dyn.h"
657              endif
658             endif ! of if (leapf.or.(.not.leapf.and.(.not.forward)))
659            ENDIF ! of IF(MOD(itau,iecri).EQ.0)
660
661            IF(itau.EQ.itaufin) THEN
662
663
664!              if (planet_type.eq."earth") then
665! Write an Earth-format restart file
666                CALL dynredem1("restart.nc",start_time,
667     &                         vcov,ucov,teta,q,masse,ps)
668!              endif ! of if (planet_type.eq."earth")
669
670              CLOSE(99)
671              !!! Ehouarn: Why not stop here and now?
672            ENDIF ! of IF (itau.EQ.itaufin)
673
674c-----------------------------------------------------------------------
675c   gestion de l'integration temporelle:
676c   ------------------------------------
677
678            IF( MOD(itau,iperiod).EQ.0 )    THEN
679                    GO TO 1
680            ELSE IF ( MOD(itau-1,iperiod). EQ. 0 ) THEN
681
682                   IF( forward )  THEN
683c      fin du pas forward et debut du pas backward
684
685                      forward = .FALSE.
686                        leapf = .FALSE.
687                           GO TO 2
688
689                   ELSE
690c      fin du pas backward et debut du premier pas leapfrog
691
692                        leapf =  .TRUE.
693                        dt  =  2.*dtvr
694                        GO TO 2
695                   END IF ! of IF (forward)
696            ELSE
697
698c      ......   pas leapfrog  .....
699
700                 leapf = .TRUE.
701                 dt  = 2.*dtvr
702                 GO TO 2
703            END IF ! of IF (MOD(itau,iperiod).EQ.0)
704                   !    ELSEIF (MOD(itau-1,iperiod).EQ.0)
705
706      ELSE ! of IF (.not.purmats)
707
708c       ........................................................
709c       ..............       schema  matsuno        ...............
710c       ........................................................
711            IF( forward )  THEN
712
713             itau =  itau + 1
714c             iday = day_ini+itau/day_step
715c             time = REAL(itau-(iday-day_ini)*day_step)/day_step+time_0
716c
717c                  IF(time.GT.1.) THEN
718c                   time = time-1.
719c                   iday = iday+1
720c                  ENDIF
721
722               forward =  .FALSE.
723               IF( itau. EQ. itaufinp1 ) then 
724                 abort_message = 'Simulation finished'
725                 call abort_gcm(modname,abort_message,0)
726               ENDIF
727               GO TO 2
728
729            ELSE ! of IF(forward) i.e. backward step
730
731              IF(MOD(itau,iperiod).EQ.0 .OR. itau.EQ.itaufin) THEN
732               IF(itau.EQ.itaufin) THEN
733                  iav=1
734               ELSE
735                  iav=0
736               ENDIF
737
738               IF (ok_dynzon) THEN
739#ifdef CPP_IOIPSL
740                 CALL bilan_dyn(2,dtvr*iperiod,dtvr*day_step*periodav,
741     &                 ps,masse,pk,pbaru,pbarv,teta,phi,ucov,vcov,q)
742#endif
743               ENDIF
744               IF (ok_dyn_ave) THEN
745#ifdef CPP_IOIPSL
746                 CALL writedynav(itau,vcov,
747     &                 ucov,teta,pk,phi,q,masse,ps,phis)
748#endif
749               ENDIF
750
751              ENDIF ! of IF(MOD(itau,iperiod).EQ.0 .OR. itau.EQ.itaufin)
752
753              IF(MOD(itau,iecri         ).EQ.0) THEN
754c              IF(MOD(itau,iecri*day_step).EQ.0) THEN
755                CALL geopot(ip1jmp1,teta,pk,pks,phis,phi)
756                unat=0.
757                do l=1,llm
758                  unat(iip2:ip1jm,l)=ucov(iip2:ip1jm,l)/cu(iip2:ip1jm)
759                  vnat(:,l)=vcov(:,l)/cv(:)
760                enddo
761#ifdef CPP_IOIPSL
762              if (ok_dyn_ins) then
763!                write(lunout,*) "leapfrog: call writehist (b)",
764!     &                        itau,iecri
765                CALL writehist(itau,vcov,ucov,teta,phi,q,masse,ps,phis)
766              endif ! of if (ok_dyn_ins)
767#endif
768! For some Grads outputs
769                if (output_grads_dyn) then
770#include "write_grads_dyn.h"
771                endif
772
773              ENDIF ! of IF(MOD(itau,iecri         ).EQ.0)
774
775              IF(itau.EQ.itaufin) THEN
776!                if (planet_type.eq."earth") then
777                  CALL dynredem1("restart.nc",start_time,
778     &                           vcov,ucov,teta,q,masse,ps)
779!                endif ! of if (planet_type.eq."earth")
780              ENDIF ! of IF(itau.EQ.itaufin)
781
782              forward = .TRUE.
783              GO TO  1
784
785            ENDIF ! of IF (forward)
786
787      END IF ! of IF(.not.purmats)
788
789      STOP
790      END
Note: See TracBrowser for help on using the repository browser.