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

Last change on this file since 1502 was 1502, checked in by jghattas, 13 years ago

Modifications for variable idissip :

  • Changed name of variable idissip to dissip_period everywhere to be compatible with old .def files.
  • This variable was before read from physiq.def but the value was overwritten by a calculation in inidissip. Now, if dissip_period=0 calculation is done as before(default). Else the value from physiq.def is used directly.
  • leapfrog : added "AND NOT forward" at line 284 (dyn3d) and line 363(dyn3dpar) necessare if dissip_period not a multiple by iperiod.
  • iniconst : removed calculation of dtdiss (calculation done in inidissip)

FC, JG

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 23.6 KB
Line 
1!
2! $Id: leapfrog.F 1502 2011-03-21 16:07:54Z jghattas $
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      INTEGER nbetatmoy, nbetatdem,nbetat
75
76c   variables dynamiques
77      REAL vcov(ip1jm,llm),ucov(ip1jmp1,llm) ! vents covariants
78      REAL teta(ip1jmp1,llm)                 ! temperature potentielle
79      REAL q(ip1jmp1,llm,nqtot)               ! champs advectes
80      REAL ps(ip1jmp1)                       ! pression  au sol
81      REAL p (ip1jmp1,llmp1  )               ! pression aux interfac.des couches
82      REAL pks(ip1jmp1)                      ! exner au  sol
83      REAL pk(ip1jmp1,llm)                   ! exner au milieu des couches
84      REAL pkf(ip1jmp1,llm)                  ! exner filt.au milieu des couches
85      REAL masse(ip1jmp1,llm)                ! masse d'air
86      REAL phis(ip1jmp1)                     ! geopotentiel au sol
87      REAL phi(ip1jmp1,llm)                  ! geopotentiel
88      REAL w(ip1jmp1,llm)                    ! vitesse verticale
89
90c variables dynamiques intermediaire pour le transport
91      REAL pbaru(ip1jmp1,llm),pbarv(ip1jm,llm) !flux de masse
92
93c   variables dynamiques au pas -1
94      REAL vcovm1(ip1jm,llm),ucovm1(ip1jmp1,llm)
95      REAL tetam1(ip1jmp1,llm),psm1(ip1jmp1)
96      REAL massem1(ip1jmp1,llm)
97
98c   tendances dynamiques
99      REAL dv(ip1jm,llm),du(ip1jmp1,llm)
100      REAL dteta(ip1jmp1,llm),dq(ip1jmp1,llm,nqtot),dp(ip1jmp1)
101
102c   tendances de la dissipation
103      REAL dvdis(ip1jm,llm),dudis(ip1jmp1,llm)
104      REAL dtetadis(ip1jmp1,llm)
105
106c   tendances physiques
107      REAL dvfi(ip1jm,llm),dufi(ip1jmp1,llm)
108      REAL dtetafi(ip1jmp1,llm),dqfi(ip1jmp1,llm,nqtot),dpfi(ip1jmp1)
109
110c   variables pour le fichier histoire
111      REAL dtav      ! intervalle de temps elementaire
112
113      REAL tppn(iim),tpps(iim),tpn,tps
114c
115      INTEGER itau,itaufinp1,iav
116!      INTEGER  iday ! jour julien
117      REAL       time
118
119      REAL  SSUM
120      REAL time_0 , finvmaold(ip1jmp1,llm)
121
122cym      LOGICAL  lafin
123      LOGICAL :: lafin=.false.
124      INTEGER ij,iq,l
125      INTEGER ik
126
127      real time_step, t_wrt, t_ops
128
129!      REAL rdayvrai,rdaym_ini
130! jD_cur: jour julien courant
131! jH_cur: heure julienne courante
132      REAL :: jD_cur, jH_cur
133      INTEGER :: an, mois, jour
134      REAL :: secondes
135
136      LOGICAL first,callinigrads
137cIM : pour sortir les param. du modele dans un fis. netcdf 110106
138      save first
139      data first/.true./
140      real dt_cum
141      character*10 infile
142      integer zan, tau0, thoriid
143      integer nid_ctesGCM
144      save nid_ctesGCM
145      real degres
146      real rlong(iip1), rlatg(jjp1)
147      real zx_tmp_2d(iip1,jjp1)
148      integer ndex2d(iip1*jjp1)
149      logical ok_sync
150      parameter (ok_sync = .true.)
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=20) :: modname
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      modname="leapfrog"
196     
197
198      itau = 0
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      CALL exner_hyb( ip1jmp1, ps, p,alpha,beta, pks, pk, pkf )
214
215c-----------------------------------------------------------------------
216c   Debut de l'integration temporelle:
217c   ----------------------------------
218
219   1  CONTINUE
220
221      jD_cur = jD_ref + day_ini - day_ref + int (itau * dtvr / daysec)
222      jH_cur = jH_ref +                                                 &
223     &          (itau * dtvr / daysec - int(itau * dtvr / daysec))
224
225
226#ifdef CPP_IOIPSL
227      if (ok_guide) then
228        call guide_main(itau,ucov,vcov,teta,q,masse,ps)
229      endif
230#endif
231
232
233c
234c     IF( MOD( itau, 10* day_step ).EQ.0 )  THEN
235c       CALL  test_period ( ucov,vcov,teta,q,p,phis )
236c       PRINT *,' ----   Test_period apres continue   OK ! -----', itau
237c     ENDIF
238c
239
240! Save fields obtained at previous time step as '...m1'
241      CALL SCOPY( ijmllm ,vcov , 1, vcovm1 , 1 )
242      CALL SCOPY( ijp1llm,ucov , 1, ucovm1 , 1 )
243      CALL SCOPY( ijp1llm,teta , 1, tetam1 , 1 )
244      CALL SCOPY( ijp1llm,masse, 1, massem1, 1 )
245      CALL SCOPY( ip1jmp1, ps  , 1,   psm1 , 1 )
246
247      forward = .TRUE.
248      leapf   = .FALSE.
249      dt      =  dtvr
250
251c   ...    P.Le Van .26/04/94  ....
252
253      CALL SCOPY   ( ijp1llm,   masse, 1, finvmaold,     1 )
254      CALL filtreg ( finvmaold ,jjp1, llm, -2,2, .TRUE., 1 )
255
256   2  CONTINUE
257
258c-----------------------------------------------------------------------
259
260c   date:
261c   -----
262
263
264c   gestion des appels de la physique et des dissipations:
265c   ------------------------------------------------------
266c
267c   ...    P.Le Van  ( 6/02/95 )  ....
268
269      apphys = .FALSE.
270      statcl = .FALSE.
271      conser = .FALSE.
272      apdiss = .FALSE.
273
274      IF( purmats ) THEN
275      ! Purely Matsuno time stepping
276         IF( MOD(itau,iconser) .EQ.0.AND.  forward    ) conser = .TRUE.
277         IF( MOD(itau,dissip_period ).EQ.0.AND..NOT.forward )
278     s        apdiss = .TRUE.
279         IF( MOD(itau,iphysiq ).EQ.0.AND..NOT.forward
280     s          .and. iflag_phys.EQ.1                 ) apphys = .TRUE.
281      ELSE
282      ! Leapfrog/Matsuno time stepping
283         IF( MOD(itau   ,iconser) .EQ. 0              ) conser = .TRUE.
284         IF( MOD(itau+1,dissip_period).EQ.0 .AND. .NOT. forward )
285     s        apdiss = .TRUE.
286         IF( MOD(itau+1,iphysiq).EQ.0.AND.iflag_phys.EQ.1) apphys=.TRUE.
287      END IF
288
289! Ehouarn: for Shallow Water case (ie: 1 vertical layer),
290!          supress dissipation step
291      if (llm.eq.1) then
292        apdiss=.false.
293      endif
294
295c-----------------------------------------------------------------------
296c   calcul des tendances dynamiques:
297c   --------------------------------
298
299      CALL geopot  ( ip1jmp1, teta  , pk , pks,  phis  , phi   )
300
301      time = jD_cur + jH_cur
302      CALL caldyn
303     $  ( itau,ucov,vcov,teta,ps,masse,pk,pkf,phis ,
304     $    phi,conser,du,dv,dteta,dp,w, pbaru,pbarv, time )
305
306
307c-----------------------------------------------------------------------
308c   calcul des tendances advection des traceurs (dont l'humidite)
309c   -------------------------------------------------------------
310
311      IF( forward. OR . leapf )  THEN
312
313         CALL caladvtrac(q,pbaru,pbarv,
314     *        p, masse, dq,  teta,
315     .        flxw, pk)
316         
317         IF (offline) THEN
318Cmaf stokage du flux de masse pour traceurs OFF-LINE
319
320#ifdef CPP_IOIPSL
321           CALL fluxstokenc(pbaru,pbarv,masse,teta,phi,phis,
322     .   dtvr, itau)
323#endif
324
325
326         ENDIF ! of IF (offline)
327c
328      ENDIF ! of IF( forward. OR . leapf )
329
330
331c-----------------------------------------------------------------------
332c   integrations dynamique et traceurs:
333c   ----------------------------------
334
335
336       CALL integrd ( 2,vcovm1,ucovm1,tetam1,psm1,massem1 ,
337     $         dv,du,dteta,dq,dp,vcov,ucov,teta,q,ps,masse,phis ,
338     $              finvmaold                                    )
339
340
341c .P.Le Van (26/04/94  ajout de  finvpold dans l'appel d'integrd)
342c
343c-----------------------------------------------------------------------
344c   calcul des tendances physiques:
345c   -------------------------------
346c    ########   P.Le Van ( Modif le  6/02/95 )   ###########
347c
348       IF( purmats )  THEN
349          IF( itau.EQ.itaufin.AND..NOT.forward ) lafin = .TRUE.
350       ELSE
351          IF( itau+1. EQ. itaufin )              lafin = .TRUE.
352       ENDIF
353c
354c
355       IF( apphys )  THEN
356c
357c     .......   Ajout   P.Le Van ( 17/04/96 )   ...........
358c
359
360         CALL pression (  ip1jmp1, ap, bp, ps,  p      )
361         CALL exner_hyb(  ip1jmp1, ps, p,alpha,beta,pks, pk, pkf )
362
363!           rdaym_ini  = itau * dtvr / daysec
364!           rdayvrai   = rdaym_ini  + day_ini
365           jD_cur = jD_ref + day_ini - day_ref
366     $        + int (itau * dtvr / daysec)
367           jH_cur = jH_ref +                                            &
368     &              (itau * dtvr / daysec - int(itau * dtvr / daysec))
369!         write(lunout,*)'itau, jD_cur = ', itau, jD_cur, jH_cur
370!         call ju2ymds(jD_cur+jH_cur, an, mois, jour, secondes)
371!         write(lunout,*)'current date = ',an, mois, jour, secondes
372
373c rajout debug
374c       lafin = .true.
375
376
377c   Inbterface avec les routines de phylmd (phymars ... )
378c   -----------------------------------------------------
379
380c+jld
381
382c  Diagnostique de conservation de l'énergie : initialisation
383         IF (ip_ebil_dyn.ge.1 ) THEN
384          ztit='bil dyn'
385! Ehouarn: be careful, diagedyn is Earth-specific (includes ../phylmd/..)!
386           IF (planet_type.eq."earth") THEN
387            CALL diagedyn(ztit,2,1,1,dtphys
388     &    , ucov    , vcov , ps, p ,pk , teta , q(:,:,1), q(:,:,2))
389           ENDIF
390         ENDIF ! of IF (ip_ebil_dyn.ge.1 )
391c-jld
392#ifdef CPP_IOIPSL
393cIM : pour sortir les param. du modele dans un fis. netcdf 110106
394         IF (first) THEN
395          first=.false.
396#include "ini_paramLMDZ_dyn.h"
397         ENDIF
398c
399#include "write_paramLMDZ_dyn.h"
400c
401#endif
402! #endif of #ifdef CPP_IOIPSL
403         CALL calfis( lafin , jD_cur, jH_cur,
404     $               ucov,vcov,teta,q,masse,ps,p,pk,phis,phi ,
405     $               du,dv,dteta,dq,
406     $               flxw,
407     $               clesphy0, dufi,dvfi,dtetafi,dqfi,dpfi  )
408
409         IF (ok_strato) THEN
410           CALL top_bound( vcov,ucov,teta,masse,dufi,dvfi,dtetafi)
411         ENDIF
412       
413c      ajout des tendances physiques:
414c      ------------------------------
415          CALL addfi( dtphys, leapf, forward   ,
416     $                  ucov, vcov, teta , q   ,ps ,
417     $                 dufi, dvfi, dtetafi , dqfi ,dpfi  )
418c
419c  Diagnostique de conservation de l'énergie : difference
420         IF (ip_ebil_dyn.ge.1 ) THEN
421          ztit='bil phys'
422          IF (planet_type.eq."earth") THEN
423           CALL diagedyn(ztit,2,1,1,dtphys
424     &     , ucov    , vcov , ps, p ,pk , teta , q(:,:,1), q(:,:,2))
425          ENDIF
426         ENDIF ! of IF (ip_ebil_dyn.ge.1 )
427
428       ENDIF ! of IF( apphys )
429
430      IF(iflag_phys.EQ.2) THEN ! "Newtonian" case
431!   Academic case : Simple friction and Newtonan relaxation
432!   -------------------------------------------------------
433        DO l=1,llm   
434          DO ij=1,ip1jmp1
435           teta(ij,l)=teta(ij,l)-dtvr*
436     &      (teta(ij,l)-tetarappel(ij,l))*(knewt_g+knewt_t(l)*clat4(ij))
437          ENDDO
438        ENDDO ! of DO l=1,llm
439          call friction(ucov,vcov,dtvr)
440       
441        ! Sponge layer (if any)
442        IF (ok_strato) THEN
443          dufi(:,:)=0.
444          dvfi(:,:)=0.
445          dtetafi(:,:)=0.
446          dqfi(:,:,:)=0.
447          dpfi(:)=0.
448          CALL top_bound(vcov,ucov,teta,masse,dufi,dvfi,dtetafi)
449          CALL addfi( dtvr, leapf, forward   ,
450     $                  ucov, vcov, teta , q   ,ps ,
451     $                 dufi, dvfi, dtetafi , dqfi ,dpfi  )
452        ENDIF ! of IF (ok_strato)
453      ENDIF ! of IF (iflag_phys.EQ.2)
454
455
456c-jld
457
458        CALL pression ( ip1jmp1, ap, bp, ps, p                  )
459        CALL exner_hyb( ip1jmp1, ps, p,alpha,beta, pks, pk, pkf )
460
461
462c-----------------------------------------------------------------------
463c   dissipation horizontale et verticale  des petites echelles:
464c   ----------------------------------------------------------
465
466      IF(apdiss) THEN
467
468
469c   calcul de l'energie cinetique avant dissipation
470        call covcont(llm,ucov,vcov,ucont,vcont)
471        call enercin(vcov,ucov,vcont,ucont,ecin0)
472
473c   dissipation
474        CALL dissip(vcov,ucov,teta,p,dvdis,dudis,dtetadis)
475        ucov=ucov+dudis
476        vcov=vcov+dvdis
477c       teta=teta+dtetadis
478
479
480c------------------------------------------------------------------------
481        if (dissip_conservative) then
482C       On rajoute la tendance due a la transform. Ec -> E therm. cree
483C       lors de la dissipation
484            call covcont(llm,ucov,vcov,ucont,vcont)
485            call enercin(vcov,ucov,vcont,ucont,ecin)
486            dtetaecdt= (ecin0-ecin)/ pk
487c           teta=teta+dtetaecdt
488            dtetadis=dtetadis+dtetaecdt
489        endif
490        teta=teta+dtetadis
491c------------------------------------------------------------------------
492
493
494c    .......        P. Le Van (  ajout  le 17/04/96  )   ...........
495c   ...      Calcul de la valeur moyenne, unique de h aux poles  .....
496c
497
498        DO l  =  1, llm
499          DO ij =  1,iim
500           tppn(ij)  = aire(  ij    ) * teta(  ij    ,l)
501           tpps(ij)  = aire(ij+ip1jm) * teta(ij+ip1jm,l)
502          ENDDO
503           tpn  = SSUM(iim,tppn,1)/apoln
504           tps  = SSUM(iim,tpps,1)/apols
505
506          DO ij = 1, iip1
507           teta(  ij    ,l) = tpn
508           teta(ij+ip1jm,l) = tps
509          ENDDO
510        ENDDO
511
512        DO ij =  1,iim
513          tppn(ij)  = aire(  ij    ) * ps (  ij    )
514          tpps(ij)  = aire(ij+ip1jm) * ps (ij+ip1jm)
515        ENDDO
516          tpn  = SSUM(iim,tppn,1)/apoln
517          tps  = SSUM(iim,tpps,1)/apols
518
519        DO ij = 1, iip1
520          ps(  ij    ) = tpn
521          ps(ij+ip1jm) = tps
522        ENDDO
523
524
525      END IF ! of IF(apdiss)
526
527c ajout debug
528c              IF( lafin ) then 
529c                abort_message = 'Simulation finished'
530c                call abort_gcm(modname,abort_message,0)
531c              ENDIF
532       
533c   ********************************************************************
534c   ********************************************************************
535c   .... fin de l'integration dynamique  et physique pour le pas itau ..
536c   ********************************************************************
537c   ********************************************************************
538
539c   preparation du pas d'integration suivant  ......
540
541      IF ( .NOT.purmats ) THEN
542c       ........................................................
543c       ..............  schema matsuno + leapfrog  ..............
544c       ........................................................
545
546            IF(forward. OR. leapf) THEN
547              itau= itau + 1
548c              iday= day_ini+itau/day_step
549c              time= REAL(itau-(iday-day_ini)*day_step)/day_step+time_0
550c                IF(time.GT.1.) THEN
551c                  time = time-1.
552c                  iday = iday+1
553c                ENDIF
554            ENDIF
555
556
557            IF( itau. EQ. itaufinp1 ) then 
558              if (flag_verif) then
559                write(79,*) 'ucov',ucov
560                write(80,*) 'vcov',vcov
561                write(81,*) 'teta',teta
562                write(82,*) 'ps',ps
563                write(83,*) 'q',q
564                WRITE(85,*) 'q1 = ',q(:,:,1)
565                WRITE(86,*) 'q3 = ',q(:,:,3)
566              endif
567
568              abort_message = 'Simulation finished'
569
570              call abort_gcm(modname,abort_message,0)
571            ENDIF
572c-----------------------------------------------------------------------
573c   ecriture du fichier histoire moyenne:
574c   -------------------------------------
575
576            IF(MOD(itau,iperiod).EQ.0 .OR. itau.EQ.itaufin) THEN
577               IF(itau.EQ.itaufin) THEN
578                  iav=1
579               ELSE
580                  iav=0
581               ENDIF
582               
583               IF (ok_dynzon) THEN
584#ifdef CPP_IOIPSL
585                 CALL bilan_dyn(2,dtvr*iperiod,dtvr*day_step*periodav,
586     &                 ps,masse,pk,pbaru,pbarv,teta,phi,ucov,vcov,q)
587#endif
588               END IF
589               IF (ok_dyn_ave) THEN
590#ifdef CPP_IOIPSL
591                 CALL writedynav(itau,vcov,
592     &                 ucov,teta,pk,phi,q,masse,ps,phis)
593#endif
594               ENDIF
595
596            ENDIF ! of IF((MOD(itau,iperiod).EQ.0).OR.(itau.EQ.itaufin))
597
598c-----------------------------------------------------------------------
599c   ecriture de la bande histoire:
600c   ------------------------------
601
602            IF( MOD(itau,iecri).EQ.0) THEN
603             ! Ehouarn: output only during LF or Backward Matsuno
604             if (leapf.or.(.not.leapf.and.(.not.forward))) then
605              nbetat = nbetatdem
606              CALL geopot(ip1jmp1,teta,pk,pks,phis,phi)
607              unat=0.
608              do l=1,llm
609                unat(iip2:ip1jm,l)=ucov(iip2:ip1jm,l)/cu(iip2:ip1jm)
610                vnat(:,l)=vcov(:,l)/cv(:)
611              enddo
612#ifdef CPP_IOIPSL
613              if (ok_dyn_ins) then
614!               write(lunout,*) "leapfrog: call writehist, itau=",itau
615               CALL writehist(itau,vcov,ucov,teta,phi,q,masse,ps,phis)
616!               call WriteField('ucov',reshape(ucov,(/iip1,jmp1,llm/)))
617!               call WriteField('vcov',reshape(vcov,(/iip1,jjm,llm/)))
618!              call WriteField('teta',reshape(teta,(/iip1,jmp1,llm/)))
619!               call WriteField('ps',reshape(ps,(/iip1,jmp1/)))
620!               call WriteField('masse',reshape(masse,(/iip1,jmp1,llm/)))
621              endif ! of if (ok_dyn_ins)
622#endif
623! For some Grads outputs of fields
624              if (output_grads_dyn) then
625#include "write_grads_dyn.h"
626              endif
627             endif ! of if (leapf.or.(.not.leapf.and.(.not.forward)))
628            ENDIF ! of IF(MOD(itau,iecri).EQ.0)
629
630            IF(itau.EQ.itaufin) THEN
631
632
633!              if (planet_type.eq."earth") then
634! Write an Earth-format restart file
635                CALL dynredem1("restart.nc",0.0,
636     &                         vcov,ucov,teta,q,masse,ps)
637!              endif ! of if (planet_type.eq."earth")
638
639              CLOSE(99)
640            ENDIF ! of IF (itau.EQ.itaufin)
641
642c-----------------------------------------------------------------------
643c   gestion de l'integration temporelle:
644c   ------------------------------------
645
646            IF( MOD(itau,iperiod).EQ.0 )    THEN
647                    GO TO 1
648            ELSE IF ( MOD(itau-1,iperiod). EQ. 0 ) THEN
649
650                   IF( forward )  THEN
651c      fin du pas forward et debut du pas backward
652
653                      forward = .FALSE.
654                        leapf = .FALSE.
655                           GO TO 2
656
657                   ELSE
658c      fin du pas backward et debut du premier pas leapfrog
659
660                        leapf =  .TRUE.
661                        dt  =  2.*dtvr
662                        GO TO 2
663                   END IF ! of IF (forward)
664            ELSE
665
666c      ......   pas leapfrog  .....
667
668                 leapf = .TRUE.
669                 dt  = 2.*dtvr
670                 GO TO 2
671            END IF ! of IF (MOD(itau,iperiod).EQ.0)
672                   !    ELSEIF (MOD(itau-1,iperiod).EQ.0)
673
674      ELSE ! of IF (.not.purmats)
675
676c       ........................................................
677c       ..............       schema  matsuno        ...............
678c       ........................................................
679            IF( forward )  THEN
680
681             itau =  itau + 1
682c             iday = day_ini+itau/day_step
683c             time = REAL(itau-(iday-day_ini)*day_step)/day_step+time_0
684c
685c                  IF(time.GT.1.) THEN
686c                   time = time-1.
687c                   iday = iday+1
688c                  ENDIF
689
690               forward =  .FALSE.
691               IF( itau. EQ. itaufinp1 ) then 
692                 abort_message = 'Simulation finished'
693                 call abort_gcm(modname,abort_message,0)
694               ENDIF
695               GO TO 2
696
697            ELSE ! of IF(forward) i.e. backward step
698
699              IF(MOD(itau,iperiod).EQ.0 .OR. itau.EQ.itaufin) THEN
700               IF(itau.EQ.itaufin) THEN
701                  iav=1
702               ELSE
703                  iav=0
704               ENDIF
705
706               IF (ok_dynzon) THEN
707#ifdef CPP_IOIPSL
708                 CALL bilan_dyn(2,dtvr*iperiod,dtvr*day_step*periodav,
709     &                 ps,masse,pk,pbaru,pbarv,teta,phi,ucov,vcov,q)
710#endif
711               ENDIF
712               IF (ok_dyn_ave) THEN
713#ifdef CPP_IOIPSL
714                 CALL writedynav(itau,vcov,
715     &                 ucov,teta,pk,phi,q,masse,ps,phis)
716#endif
717               ENDIF
718
719              ENDIF ! of IF(MOD(itau,iperiod).EQ.0 .OR. itau.EQ.itaufin)
720
721              IF(MOD(itau,iecri         ).EQ.0) THEN
722c              IF(MOD(itau,iecri*day_step).EQ.0) THEN
723                nbetat = nbetatdem
724                CALL geopot(ip1jmp1,teta,pk,pks,phis,phi)
725                unat=0.
726                do l=1,llm
727                  unat(iip2:ip1jm,l)=ucov(iip2:ip1jm,l)/cu(iip2:ip1jm)
728                  vnat(:,l)=vcov(:,l)/cv(:)
729                enddo
730#ifdef CPP_IOIPSL
731              if (ok_dyn_ins) then
732!                write(lunout,*) "leapfrog: call writehist (b)",
733!     &                        itau,iecri
734                CALL writehist(itau,vcov,ucov,teta,phi,q,masse,ps,phis)
735              endif ! of if (ok_dyn_ins)
736#endif
737! For some Grads outputs
738                if (output_grads_dyn) then
739#include "write_grads_dyn.h"
740                endif
741
742              ENDIF ! of IF(MOD(itau,iecri         ).EQ.0)
743
744              IF(itau.EQ.itaufin) THEN
745!                if (planet_type.eq."earth") then
746                  CALL dynredem1("restart.nc",0.0,
747     &                           vcov,ucov,teta,q,masse,ps)
748!                endif ! of if (planet_type.eq."earth")
749              ENDIF ! of IF(itau.EQ.itaufin)
750
751              forward = .TRUE.
752              GO TO  1
753
754            ENDIF ! of IF (forward)
755
756      END IF ! of IF(.not.purmats)
757
758      STOP
759      END
Note: See TracBrowser for help on using the repository browser.