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

Last change on this file since 1592 was 1592, checked in by Ehouarn Millour, 13 years ago

Minor cleanup: remove unused variables nbetat, nbetatmoy and nbetatdem.
EM

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 24.7 KB
Line 
1!
2! $Id: leapfrog.F 1592 2011-11-26 06:57:55Z 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
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
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      CALL geopot  ( ip1jmp1, teta  , pk , pks,  phis  , phi   )
307
308      time = jD_cur + jH_cur
309      CALL caldyn
310     $  ( itau,ucov,vcov,teta,ps,masse,pk,pkf,phis ,
311     $    phi,conser,du,dv,dteta,dp,w, pbaru,pbarv, time )
312
313
314c-----------------------------------------------------------------------
315c   calcul des tendances advection des traceurs (dont l'humidite)
316c   -------------------------------------------------------------
317
318      IF( forward. OR . leapf )  THEN
319
320         CALL caladvtrac(q,pbaru,pbarv,
321     *        p, masse, dq,  teta,
322     .        flxw, pk)
323         
324         IF (offline) THEN
325Cmaf stokage du flux de masse pour traceurs OFF-LINE
326
327#ifdef CPP_IOIPSL
328           CALL fluxstokenc(pbaru,pbarv,masse,teta,phi,phis,
329     .   dtvr, itau)
330#endif
331
332
333         ENDIF ! of IF (offline)
334c
335      ENDIF ! of IF( forward. OR . leapf )
336
337
338c-----------------------------------------------------------------------
339c   integrations dynamique et traceurs:
340c   ----------------------------------
341
342
343       CALL integrd ( 2,vcovm1,ucovm1,tetam1,psm1,massem1 ,
344     $         dv,du,dteta,dq,dp,vcov,ucov,teta,q,ps,masse,phis ,
345     $              finvmaold                                    )
346
347
348c .P.Le Van (26/04/94  ajout de  finvpold dans l'appel d'integrd)
349c
350c-----------------------------------------------------------------------
351c   calcul des tendances physiques:
352c   -------------------------------
353c    ########   P.Le Van ( Modif le  6/02/95 )   ###########
354c
355       IF( purmats )  THEN
356          IF( itau.EQ.itaufin.AND..NOT.forward ) lafin = .TRUE.
357       ELSE
358          IF( itau+1. EQ. itaufin )              lafin = .TRUE.
359       ENDIF
360c
361c
362       IF( apphys )  THEN
363c
364c     .......   Ajout   P.Le Van ( 17/04/96 )   ...........
365c
366
367         CALL pression (  ip1jmp1, ap, bp, ps,  p      )
368         if (disvert_type==1) then
369           CALL exner_hyb(  ip1jmp1, ps, p,alpha,beta,pks, pk, pkf )
370         else ! we assume that we are in the disvert_type==2 case
371           CALL exner_milieu( ip1jmp1, ps, p, beta, pks, pk, pkf )
372         endif
373
374!           rdaym_ini  = itau * dtvr / daysec
375!           rdayvrai   = rdaym_ini  + day_ini
376!           jD_cur = jD_ref + day_ini - day_ref
377!     $        + int (itau * dtvr / daysec)
378!           jH_cur = jH_ref +                                            &
379!     &              (itau * dtvr / daysec - int(itau * dtvr / daysec))
380           jD_cur = jD_ref + day_ini - day_ref +                        &
381     &          int (itau * dtvr / daysec)
382           jH_cur = jH_ref + start_time +                               &
383     &          (itau * dtvr / daysec - int(itau * dtvr / daysec))
384           jD_cur = jD_cur + int(jH_cur)
385           jH_cur = jH_cur - int(jH_cur)
386!         write(lunout,*)'itau, jD_cur = ', itau, jD_cur, jH_cur
387!         call ju2ymds(jD_cur+jH_cur, an, mois, jour, secondes)
388!         write(lunout,*)'current date = ',an, mois, jour, secondes
389
390c rajout debug
391c       lafin = .true.
392
393
394c   Inbterface avec les routines de phylmd (phymars ... )
395c   -----------------------------------------------------
396
397c+jld
398
399c  Diagnostique de conservation de l'énergie : initialisation
400         IF (ip_ebil_dyn.ge.1 ) THEN
401          ztit='bil dyn'
402! Ehouarn: be careful, diagedyn is Earth-specific (includes ../phylmd/..)!
403           IF (planet_type.eq."earth") THEN
404            CALL diagedyn(ztit,2,1,1,dtphys
405     &    , ucov    , vcov , ps, p ,pk , teta , q(:,:,1), q(:,:,2))
406           ENDIF
407         ENDIF ! of IF (ip_ebil_dyn.ge.1 )
408c-jld
409#ifdef CPP_IOIPSL
410cIM : pour sortir les param. du modele dans un fis. netcdf 110106
411         IF (first) THEN
412          first=.false.
413#include "ini_paramLMDZ_dyn.h"
414         ENDIF
415c
416#include "write_paramLMDZ_dyn.h"
417c
418#endif
419! #endif of #ifdef CPP_IOIPSL
420         CALL calfis( lafin , jD_cur, jH_cur,
421     $               ucov,vcov,teta,q,masse,ps,p,pk,phis,phi ,
422     $               du,dv,dteta,dq,
423     $               flxw,
424     $               clesphy0, dufi,dvfi,dtetafi,dqfi,dpfi  )
425
426         IF (ok_strato) THEN
427           CALL top_bound( vcov,ucov,teta,masse,dufi,dvfi,dtetafi)
428         ENDIF
429       
430c      ajout des tendances physiques:
431c      ------------------------------
432          CALL addfi( dtphys, leapf, forward   ,
433     $                  ucov, vcov, teta , q   ,ps ,
434     $                 dufi, dvfi, dtetafi , dqfi ,dpfi  )
435c
436c  Diagnostique de conservation de l'énergie : difference
437         IF (ip_ebil_dyn.ge.1 ) THEN
438          ztit='bil phys'
439          IF (planet_type.eq."earth") THEN
440           CALL diagedyn(ztit,2,1,1,dtphys
441     &     , ucov    , vcov , ps, p ,pk , teta , q(:,:,1), q(:,:,2))
442          ENDIF
443         ENDIF ! of IF (ip_ebil_dyn.ge.1 )
444
445       ENDIF ! of IF( apphys )
446
447      IF(iflag_phys.EQ.2) THEN ! "Newtonian" case
448!   Academic case : Simple friction and Newtonan relaxation
449!   -------------------------------------------------------
450        DO l=1,llm   
451          DO ij=1,ip1jmp1
452           teta(ij,l)=teta(ij,l)-dtvr*
453     &      (teta(ij,l)-tetarappel(ij,l))*(knewt_g+knewt_t(l)*clat4(ij))
454          ENDDO
455        ENDDO ! of DO l=1,llm
456       
457        if (planet_type.eq."giant") then
458          ! add an intrinsic heat flux at the base of the atmosphere
459          teta(:,1)=teta(:,1)+dtvr*aire(:)*ihf/cpp/masse(:,1)
460        endif
461
462        call friction(ucov,vcov,dtvr)
463       
464        ! Sponge layer (if any)
465        IF (ok_strato) THEN
466          dufi(:,:)=0.
467          dvfi(:,:)=0.
468          dtetafi(:,:)=0.
469          dqfi(:,:,:)=0.
470          dpfi(:)=0.
471          CALL top_bound(vcov,ucov,teta,masse,dufi,dvfi,dtetafi)
472          CALL addfi( dtvr, leapf, forward   ,
473     $                  ucov, vcov, teta , q   ,ps ,
474     $                 dufi, dvfi, dtetafi , dqfi ,dpfi  )
475        ENDIF ! of IF (ok_strato)
476      ENDIF ! of IF (iflag_phys.EQ.2)
477
478
479c-jld
480
481        CALL pression ( ip1jmp1, ap, bp, ps, p                  )
482        if (disvert_type==1) then
483          CALL exner_hyb( ip1jmp1, ps, p,alpha,beta, pks, pk, pkf )
484        else ! we assume that we are in the disvert_type==2 case
485          CALL exner_milieu( ip1jmp1, ps, p, beta, pks, pk, pkf )
486        endif
487
488
489c-----------------------------------------------------------------------
490c   dissipation horizontale et verticale  des petites echelles:
491c   ----------------------------------------------------------
492
493      IF(apdiss) THEN
494
495
496c   calcul de l'energie cinetique avant dissipation
497        call covcont(llm,ucov,vcov,ucont,vcont)
498        call enercin(vcov,ucov,vcont,ucont,ecin0)
499
500c   dissipation
501        CALL dissip(vcov,ucov,teta,p,dvdis,dudis,dtetadis)
502        ucov=ucov+dudis
503        vcov=vcov+dvdis
504c       teta=teta+dtetadis
505
506
507c------------------------------------------------------------------------
508        if (dissip_conservative) then
509C       On rajoute la tendance due a la transform. Ec -> E therm. cree
510C       lors de la dissipation
511            call covcont(llm,ucov,vcov,ucont,vcont)
512            call enercin(vcov,ucov,vcont,ucont,ecin)
513            dtetaecdt= (ecin0-ecin)/ pk
514c           teta=teta+dtetaecdt
515            dtetadis=dtetadis+dtetaecdt
516        endif
517        teta=teta+dtetadis
518c------------------------------------------------------------------------
519
520
521c    .......        P. Le Van (  ajout  le 17/04/96  )   ...........
522c   ...      Calcul de la valeur moyenne, unique de h aux poles  .....
523c
524
525        DO l  =  1, llm
526          DO ij =  1,iim
527           tppn(ij)  = aire(  ij    ) * teta(  ij    ,l)
528           tpps(ij)  = aire(ij+ip1jm) * teta(ij+ip1jm,l)
529          ENDDO
530           tpn  = SSUM(iim,tppn,1)/apoln
531           tps  = SSUM(iim,tpps,1)/apols
532
533          DO ij = 1, iip1
534           teta(  ij    ,l) = tpn
535           teta(ij+ip1jm,l) = tps
536          ENDDO
537        ENDDO
538
539        DO ij =  1,iim
540          tppn(ij)  = aire(  ij    ) * ps (  ij    )
541          tpps(ij)  = aire(ij+ip1jm) * ps (ij+ip1jm)
542        ENDDO
543          tpn  = SSUM(iim,tppn,1)/apoln
544          tps  = SSUM(iim,tpps,1)/apols
545
546        DO ij = 1, iip1
547          ps(  ij    ) = tpn
548          ps(ij+ip1jm) = tps
549        ENDDO
550
551
552      END IF ! of IF(apdiss)
553
554c ajout debug
555c              IF( lafin ) then 
556c                abort_message = 'Simulation finished'
557c                call abort_gcm(modname,abort_message,0)
558c              ENDIF
559       
560c   ********************************************************************
561c   ********************************************************************
562c   .... fin de l'integration dynamique  et physique pour le pas itau ..
563c   ********************************************************************
564c   ********************************************************************
565
566c   preparation du pas d'integration suivant  ......
567
568      IF ( .NOT.purmats ) THEN
569c       ........................................................
570c       ..............  schema matsuno + leapfrog  ..............
571c       ........................................................
572
573            IF(forward. OR. leapf) THEN
574              itau= itau + 1
575c              iday= day_ini+itau/day_step
576c              time= REAL(itau-(iday-day_ini)*day_step)/day_step+time_0
577c                IF(time.GT.1.) THEN
578c                  time = time-1.
579c                  iday = iday+1
580c                ENDIF
581            ENDIF
582
583
584            IF( itau. EQ. itaufinp1 ) then 
585              if (flag_verif) then
586                write(79,*) 'ucov',ucov
587                write(80,*) 'vcov',vcov
588                write(81,*) 'teta',teta
589                write(82,*) 'ps',ps
590                write(83,*) 'q',q
591                WRITE(85,*) 'q1 = ',q(:,:,1)
592                WRITE(86,*) 'q3 = ',q(:,:,3)
593              endif
594
595              abort_message = 'Simulation finished'
596
597              call abort_gcm(modname,abort_message,0)
598            ENDIF
599c-----------------------------------------------------------------------
600c   ecriture du fichier histoire moyenne:
601c   -------------------------------------
602
603            IF(MOD(itau,iperiod).EQ.0 .OR. itau.EQ.itaufin) THEN
604               IF(itau.EQ.itaufin) THEN
605                  iav=1
606               ELSE
607                  iav=0
608               ENDIF
609               
610               IF (ok_dynzon) THEN
611#ifdef CPP_IOIPSL
612                 CALL bilan_dyn(2,dtvr*iperiod,dtvr*day_step*periodav,
613     &                 ps,masse,pk,pbaru,pbarv,teta,phi,ucov,vcov,q)
614#endif
615               END IF
616               IF (ok_dyn_ave) THEN
617#ifdef CPP_IOIPSL
618                 CALL writedynav(itau,vcov,
619     &                 ucov,teta,pk,phi,q,masse,ps,phis)
620#endif
621               ENDIF
622
623            ENDIF ! of IF((MOD(itau,iperiod).EQ.0).OR.(itau.EQ.itaufin))
624
625c-----------------------------------------------------------------------
626c   ecriture de la bande histoire:
627c   ------------------------------
628
629            IF( MOD(itau,iecri).EQ.0) THEN
630             ! Ehouarn: output only during LF or Backward Matsuno
631             if (leapf.or.(.not.leapf.and.(.not.forward))) then
632              CALL geopot(ip1jmp1,teta,pk,pks,phis,phi)
633              unat=0.
634              do l=1,llm
635                unat(iip2:ip1jm,l)=ucov(iip2:ip1jm,l)/cu(iip2:ip1jm)
636                vnat(:,l)=vcov(:,l)/cv(:)
637              enddo
638#ifdef CPP_IOIPSL
639              if (ok_dyn_ins) then
640!               write(lunout,*) "leapfrog: call writehist, itau=",itau
641               CALL writehist(itau,vcov,ucov,teta,phi,q,masse,ps,phis)
642!               call WriteField('ucov',reshape(ucov,(/iip1,jmp1,llm/)))
643!               call WriteField('vcov',reshape(vcov,(/iip1,jjm,llm/)))
644!              call WriteField('teta',reshape(teta,(/iip1,jmp1,llm/)))
645!               call WriteField('ps',reshape(ps,(/iip1,jmp1/)))
646!               call WriteField('masse',reshape(masse,(/iip1,jmp1,llm/)))
647              endif ! of if (ok_dyn_ins)
648#endif
649! For some Grads outputs of fields
650              if (output_grads_dyn) then
651#include "write_grads_dyn.h"
652              endif
653             endif ! of if (leapf.or.(.not.leapf.and.(.not.forward)))
654            ENDIF ! of IF(MOD(itau,iecri).EQ.0)
655
656            IF(itau.EQ.itaufin) THEN
657
658
659!              if (planet_type.eq."earth") then
660! Write an Earth-format restart file
661                CALL dynredem1("restart.nc",start_time,
662     &                         vcov,ucov,teta,q,masse,ps)
663!              endif ! of if (planet_type.eq."earth")
664
665              CLOSE(99)
666            ENDIF ! of IF (itau.EQ.itaufin)
667
668c-----------------------------------------------------------------------
669c   gestion de l'integration temporelle:
670c   ------------------------------------
671
672            IF( MOD(itau,iperiod).EQ.0 )    THEN
673                    GO TO 1
674            ELSE IF ( MOD(itau-1,iperiod). EQ. 0 ) THEN
675
676                   IF( forward )  THEN
677c      fin du pas forward et debut du pas backward
678
679                      forward = .FALSE.
680                        leapf = .FALSE.
681                           GO TO 2
682
683                   ELSE
684c      fin du pas backward et debut du premier pas leapfrog
685
686                        leapf =  .TRUE.
687                        dt  =  2.*dtvr
688                        GO TO 2
689                   END IF ! of IF (forward)
690            ELSE
691
692c      ......   pas leapfrog  .....
693
694                 leapf = .TRUE.
695                 dt  = 2.*dtvr
696                 GO TO 2
697            END IF ! of IF (MOD(itau,iperiod).EQ.0)
698                   !    ELSEIF (MOD(itau-1,iperiod).EQ.0)
699
700      ELSE ! of IF (.not.purmats)
701
702c       ........................................................
703c       ..............       schema  matsuno        ...............
704c       ........................................................
705            IF( forward )  THEN
706
707             itau =  itau + 1
708c             iday = day_ini+itau/day_step
709c             time = REAL(itau-(iday-day_ini)*day_step)/day_step+time_0
710c
711c                  IF(time.GT.1.) THEN
712c                   time = time-1.
713c                   iday = iday+1
714c                  ENDIF
715
716               forward =  .FALSE.
717               IF( itau. EQ. itaufinp1 ) then 
718                 abort_message = 'Simulation finished'
719                 call abort_gcm(modname,abort_message,0)
720               ENDIF
721               GO TO 2
722
723            ELSE ! of IF(forward) i.e. backward step
724
725              IF(MOD(itau,iperiod).EQ.0 .OR. itau.EQ.itaufin) THEN
726               IF(itau.EQ.itaufin) THEN
727                  iav=1
728               ELSE
729                  iav=0
730               ENDIF
731
732               IF (ok_dynzon) THEN
733#ifdef CPP_IOIPSL
734                 CALL bilan_dyn(2,dtvr*iperiod,dtvr*day_step*periodav,
735     &                 ps,masse,pk,pbaru,pbarv,teta,phi,ucov,vcov,q)
736#endif
737               ENDIF
738               IF (ok_dyn_ave) THEN
739#ifdef CPP_IOIPSL
740                 CALL writedynav(itau,vcov,
741     &                 ucov,teta,pk,phi,q,masse,ps,phis)
742#endif
743               ENDIF
744
745              ENDIF ! of IF(MOD(itau,iperiod).EQ.0 .OR. itau.EQ.itaufin)
746
747              IF(MOD(itau,iecri         ).EQ.0) THEN
748c              IF(MOD(itau,iecri*day_step).EQ.0) THEN
749                CALL geopot(ip1jmp1,teta,pk,pks,phis,phi)
750                unat=0.
751                do l=1,llm
752                  unat(iip2:ip1jm,l)=ucov(iip2:ip1jm,l)/cu(iip2:ip1jm)
753                  vnat(:,l)=vcov(:,l)/cv(:)
754                enddo
755#ifdef CPP_IOIPSL
756              if (ok_dyn_ins) then
757!                write(lunout,*) "leapfrog: call writehist (b)",
758!     &                        itau,iecri
759                CALL writehist(itau,vcov,ucov,teta,phi,q,masse,ps,phis)
760              endif ! of if (ok_dyn_ins)
761#endif
762! For some Grads outputs
763                if (output_grads_dyn) then
764#include "write_grads_dyn.h"
765                endif
766
767              ENDIF ! of IF(MOD(itau,iecri         ).EQ.0)
768
769              IF(itau.EQ.itaufin) THEN
770!                if (planet_type.eq."earth") then
771                  CALL dynredem1("restart.nc",start_time,
772     &                           vcov,ucov,teta,q,masse,ps)
773!                endif ! of if (planet_type.eq."earth")
774              ENDIF ! of IF(itau.EQ.itaufin)
775
776              forward = .TRUE.
777              GO TO  1
778
779            ENDIF ! of IF (forward)
780
781      END IF ! of IF(.not.purmats)
782
783      STOP
784      END
Note: See TracBrowser for help on using the repository browser.