source: LMDZ5/branches/testing/libf/dyn3d/leapfrog.F @ 1669

Last change on this file since 1669 was 1669, checked in by Laurent Fairhead, 12 years ago

Version testing basée sur la r1668

http://lmdz.lmd.jussieu.fr/utilisateurs/distribution-du-modele/versions-intermediaires


Testing release based on r1668

  • 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 1669 2012-10-16 12:41:50Z fairhead $
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
120!     REAL 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      logical physic
152
153      data callinigrads/.true./
154      character*10 string10
155
156      REAL alpha(ip1jmp1,llm),beta(ip1jmp1,llm)
157      REAL :: flxw(ip1jmp1,llm)  ! flux de masse verticale
158
159c+jld variables test conservation energie
160      REAL ecin(ip1jmp1,llm),ecin0(ip1jmp1,llm)
161C     Tendance de la temp. potentiel d (theta)/ d t due a la
162C     tansformation d'energie cinetique en energie thermique
163C     cree par la dissipation
164      REAL dtetaecdt(ip1jmp1,llm)
165      REAL vcont(ip1jm,llm),ucont(ip1jmp1,llm)
166      REAL vnat(ip1jm,llm),unat(ip1jmp1,llm)
167      REAL      d_h_vcol, d_qt, d_qw, d_ql, d_ec
168      CHARACTER*15 ztit
169!IM   INTEGER   ip_ebil_dyn  ! PRINT level for energy conserv. diag.
170!IM   SAVE      ip_ebil_dyn
171!IM   DATA      ip_ebil_dyn/0/
172c-jld
173
174      character*80 dynhist_file, dynhistave_file
175      character(len=*),parameter :: modname="leapfrog"
176      character*80 abort_message
177
178      logical dissip_conservative
179      save dissip_conservative
180      data dissip_conservative/.true./
181
182      LOGICAL prem
183      save prem
184      DATA prem/.true./
185      INTEGER testita
186      PARAMETER (testita = 9)
187
188      logical , parameter :: flag_verif = .false.
189     
190
191      integer itau_w   ! pas de temps ecriture = itap + itau_phy
192
193
194      itaufin   = nday*day_step
195      itaufinp1 = itaufin +1
196      itau = 0
197      physic=.true.
198      if (iflag_phys==0.or.iflag_phys==2) physic=.false.
199
200c      iday = day_ini+itau/day_step
201c      time = REAL(itau-(iday-day_ini)*day_step)/day_step+time_0
202c         IF(time.GT.1.) THEN
203c          time = time-1.
204c          iday = iday+1
205c         ENDIF
206
207
208c-----------------------------------------------------------------------
209c   On initialise la pression et la fonction d'Exner :
210c   --------------------------------------------------
211
212      dq(:,:,:)=0.
213      CALL pression ( ip1jmp1, ap, bp, ps, p       )
214      if (pressure_exner) then
215        CALL exner_hyb( ip1jmp1, ps, p,alpha,beta, pks, pk, pkf )
216      else
217        CALL exner_milieu( ip1jmp1, ps, p, beta, pks, pk, pkf )
218      endif
219
220c-----------------------------------------------------------------------
221c   Debut de l'integration temporelle:
222c   ----------------------------------
223
224   1  CONTINUE ! Matsuno Forward step begins here
225
226      jD_cur = jD_ref + day_ini - day_ref +                             &
227     &          itau/day_step
228      jH_cur = jH_ref + start_time +                                    &
229     &          mod(itau,day_step)/float(day_step)
230      jD_cur = jD_cur + int(jH_cur)
231      jH_cur = jH_cur - int(jH_cur)
232
233
234#ifdef CPP_IOIPSL
235      if (ok_guide) then
236        call guide_main(itau,ucov,vcov,teta,q,masse,ps)
237      endif
238#endif
239
240
241c
242c     IF( MOD( itau, 10* day_step ).EQ.0 )  THEN
243c       CALL  test_period ( ucov,vcov,teta,q,p,phis )
244c       PRINT *,' ----   Test_period apres continue   OK ! -----', itau
245c     ENDIF
246c
247
248! Save fields obtained at previous time step as '...m1'
249      CALL SCOPY( ijmllm ,vcov , 1, vcovm1 , 1 )
250      CALL SCOPY( ijp1llm,ucov , 1, ucovm1 , 1 )
251      CALL SCOPY( ijp1llm,teta , 1, tetam1 , 1 )
252      CALL SCOPY( ijp1llm,masse, 1, massem1, 1 )
253      CALL SCOPY( ip1jmp1, ps  , 1,   psm1 , 1 )
254
255      forward = .TRUE.
256      leapf   = .FALSE.
257      dt      =  dtvr
258
259c   ...    P.Le Van .26/04/94  ....
260! Ehouarn: finvmaold is actually not used
261!      CALL SCOPY   ( ijp1llm,   masse, 1, finvmaold,     1 )
262!      CALL filtreg ( finvmaold ,jjp1, llm, -2,2, .TRUE., 1 )
263
264   2  CONTINUE ! Matsuno backward or leapfrog step begins here
265
266c-----------------------------------------------------------------------
267
268c   date:
269c   -----
270
271
272c   gestion des appels de la physique et des dissipations:
273c   ------------------------------------------------------
274c
275c   ...    P.Le Van  ( 6/02/95 )  ....
276
277      apphys = .FALSE.
278      statcl = .FALSE.
279      conser = .FALSE.
280      apdiss = .FALSE.
281
282      IF( purmats ) THEN
283      ! Purely Matsuno time stepping
284         IF( MOD(itau,iconser) .EQ.0.AND.  forward    ) conser = .TRUE.
285         IF( MOD(itau,dissip_period ).EQ.0.AND..NOT.forward )
286     s        apdiss = .TRUE.
287         IF( MOD(itau,iphysiq ).EQ.0.AND..NOT.forward
288     s          .and. physic                        ) apphys = .TRUE.
289      ELSE
290      ! Leapfrog/Matsuno time stepping
291         IF( MOD(itau   ,iconser) .EQ. 0              ) conser = .TRUE.
292         IF( MOD(itau+1,dissip_period).EQ.0 .AND. .NOT. forward )
293     s        apdiss = .TRUE.
294         IF( MOD(itau+1,iphysiq).EQ.0.AND.physic       ) apphys=.TRUE.
295      END IF
296
297! Ehouarn: for Shallow Water case (ie: 1 vertical layer),
298!          supress dissipation step
299      if (llm.eq.1) then
300        apdiss=.false.
301      endif
302
303c-----------------------------------------------------------------------
304c   calcul des tendances dynamiques:
305c   --------------------------------
306
307      ! compute geopotential phi()
308      CALL geopot  ( ip1jmp1, teta  , pk , pks,  phis  , phi   )
309
310      time = jD_cur + jH_cur
311      CALL caldyn
312     $  ( itau,ucov,vcov,teta,ps,masse,pk,pkf,phis ,
313     $    phi,conser,du,dv,dteta,dp,w, pbaru,pbarv, time )
314
315
316c-----------------------------------------------------------------------
317c   calcul des tendances advection des traceurs (dont l'humidite)
318c   -------------------------------------------------------------
319
320      IF( forward. OR . leapf )  THEN
321! Ehouarn: NB: at this point p with ps are not synchronized
322!              (whereas mass and ps are...)
323         CALL caladvtrac(q,pbaru,pbarv,
324     *        p, masse, dq,  teta,
325     .        flxw, pk)
326         
327         IF (offline) THEN
328Cmaf stokage du flux de masse pour traceurs OFF-LINE
329
330#ifdef CPP_IOIPSL
331           CALL fluxstokenc(pbaru,pbarv,masse,teta,phi,phis,
332     .   dtvr, itau)
333#endif
334
335
336         ENDIF ! of IF (offline)
337c
338      ENDIF ! of IF( forward. OR . leapf )
339
340
341c-----------------------------------------------------------------------
342c   integrations dynamique et traceurs:
343c   ----------------------------------
344
345
346       CALL integrd ( 2,vcovm1,ucovm1,tetam1,psm1,massem1 ,
347     $         dv,du,dteta,dq,dp,vcov,ucov,teta,q,ps,masse,phis )
348!     $              finvmaold                                    )
349
350
351c .P.Le Van (26/04/94  ajout de  finvpold dans l'appel d'integrd)
352c
353c-----------------------------------------------------------------------
354c   calcul des tendances physiques:
355c   -------------------------------
356c    ########   P.Le Van ( Modif le  6/02/95 )   ###########
357c
358       IF( purmats )  THEN
359          IF( itau.EQ.itaufin.AND..NOT.forward ) lafin = .TRUE.
360       ELSE
361          IF( itau+1. EQ. itaufin )              lafin = .TRUE.
362       ENDIF
363c
364c
365       IF( apphys )  THEN
366c
367c     .......   Ajout   P.Le Van ( 17/04/96 )   ...........
368c
369
370         CALL pression (  ip1jmp1, ap, bp, ps,  p      )
371         if (pressure_exner) then
372           CALL exner_hyb(  ip1jmp1, ps, p,alpha,beta,pks, pk, pkf )
373         else
374           CALL exner_milieu( ip1jmp1, ps, p, beta, pks, pk, pkf )
375         endif
376
377!           rdaym_ini  = itau * dtvr / daysec
378!           rdayvrai   = rdaym_ini  + day_ini
379!           jD_cur = jD_ref + day_ini - day_ref
380!     $        + int (itau * dtvr / daysec)
381!           jH_cur = jH_ref +                                            &
382!     &              (itau * dtvr / daysec - int(itau * dtvr / daysec))
383           jD_cur = jD_ref + day_ini - day_ref +                        &
384     &          itau/day_step
385           jH_cur = jH_ref + start_time +                               &
386     &              mod(itau,day_step)/float(day_step)
387           jD_cur = jD_cur + int(jH_cur)
388           jH_cur = jH_cur - int(jH_cur)
389!         write(lunout,*)'itau, jD_cur = ', itau, jD_cur, jH_cur
390!         call ju2ymds(jD_cur+jH_cur, an, mois, jour, secondes)
391!         write(lunout,*)'current date = ',an, mois, jour, secondes
392
393c rajout debug
394c       lafin = .true.
395
396
397c   Inbterface avec les routines de phylmd (phymars ... )
398c   -----------------------------------------------------
399
400c+jld
401
402c  Diagnostique de conservation de l'énergie : initialisation
403         IF (ip_ebil_dyn.ge.1 ) THEN
404          ztit='bil dyn'
405! Ehouarn: be careful, diagedyn is Earth-specific (includes ../phylmd/..)!
406           IF (planet_type.eq."earth") THEN
407#ifdef CPP_EARTH
408            CALL diagedyn(ztit,2,1,1,dtphys
409     &    , ucov    , vcov , ps, p ,pk , teta , q(:,:,1), q(:,:,2))
410#endif
411           ENDIF
412         ENDIF ! of IF (ip_ebil_dyn.ge.1 )
413c-jld
414#ifdef CPP_IOIPSL
415cIM decommenter les 6 lignes suivantes pour sortir quelques parametres dynamiques de LMDZ
416cIM uncomment next 6 lines to get some parameters for LMDZ dynamics
417c        IF (first) THEN
418c         first=.false.
419c#include "ini_paramLMDZ_dyn.h"
420c        ENDIF
421c
422c#include "write_paramLMDZ_dyn.h"
423c
424#endif
425! #endif of #ifdef CPP_IOIPSL
426         CALL calfis( lafin , jD_cur, jH_cur,
427     $               ucov,vcov,teta,q,masse,ps,p,pk,phis,phi ,
428     $               du,dv,dteta,dq,
429     $               flxw,
430     $               clesphy0, dufi,dvfi,dtetafi,dqfi,dpfi  )
431
432         IF (ok_strato) THEN
433           CALL top_bound( vcov,ucov,teta,masse,dufi,dvfi,dtetafi)
434         ENDIF
435       
436c      ajout des tendances physiques:
437c      ------------------------------
438          CALL addfi( dtphys, leapf, forward   ,
439     $                  ucov, vcov, teta , q   ,ps ,
440     $                 dufi, dvfi, dtetafi , dqfi ,dpfi  )
441c
442c  Diagnostique de conservation de l'énergie : difference
443         IF (ip_ebil_dyn.ge.1 ) THEN
444          ztit='bil phys'
445          IF (planet_type.eq."earth") THEN
446           CALL diagedyn(ztit,2,1,1,dtphys
447     &     , ucov    , vcov , ps, p ,pk , teta , q(:,:,1), q(:,:,2))
448          ENDIF
449         ENDIF ! of IF (ip_ebil_dyn.ge.1 )
450
451       ENDIF ! of IF( apphys )
452
453      IF(iflag_phys.EQ.2) THEN ! "Newtonian" case
454!   Academic case : Simple friction and Newtonan relaxation
455!   -------------------------------------------------------
456        DO l=1,llm   
457          DO ij=1,ip1jmp1
458           teta(ij,l)=teta(ij,l)-dtvr*
459     &      (teta(ij,l)-tetarappel(ij,l))*(knewt_g+knewt_t(l)*clat4(ij))
460          ENDDO
461        ENDDO ! of DO l=1,llm
462       
463        if (planet_type.eq."giant") then
464          ! add an intrinsic heat flux at the base of the atmosphere
465          teta(:,1)=teta(:,1)+dtvr*aire(:)*ihf/cpp/masse(:,1)
466        endif
467
468        call friction(ucov,vcov,dtvr)
469       
470        ! Sponge layer (if any)
471        IF (ok_strato) THEN
472          dufi(:,:)=0.
473          dvfi(:,:)=0.
474          dtetafi(:,:)=0.
475          dqfi(:,:,:)=0.
476          dpfi(:)=0.
477          CALL top_bound(vcov,ucov,teta,masse,dufi,dvfi,dtetafi)
478          CALL addfi( dtvr, leapf, forward   ,
479     $                  ucov, vcov, teta , q   ,ps ,
480     $                 dufi, dvfi, dtetafi , dqfi ,dpfi  )
481        ENDIF ! of IF (ok_strato)
482      ENDIF ! of IF (iflag_phys.EQ.2)
483
484
485c-jld
486
487        CALL pression ( ip1jmp1, ap, bp, ps, p                  )
488        if (pressure_exner) then
489          CALL exner_hyb( ip1jmp1, ps, p,alpha,beta, pks, pk, pkf )
490        else
491          CALL exner_milieu( ip1jmp1, ps, p, beta, pks, pk, pkf )
492        endif
493
494
495c-----------------------------------------------------------------------
496c   dissipation horizontale et verticale  des petites echelles:
497c   ----------------------------------------------------------
498
499      IF(apdiss) THEN
500
501
502c   calcul de l'energie cinetique avant dissipation
503        call covcont(llm,ucov,vcov,ucont,vcont)
504        call enercin(vcov,ucov,vcont,ucont,ecin0)
505
506c   dissipation
507        CALL dissip(vcov,ucov,teta,p,dvdis,dudis,dtetadis)
508        ucov=ucov+dudis
509        vcov=vcov+dvdis
510c       teta=teta+dtetadis
511
512
513c------------------------------------------------------------------------
514        if (dissip_conservative) then
515C       On rajoute la tendance due a la transform. Ec -> E therm. cree
516C       lors de la dissipation
517            call covcont(llm,ucov,vcov,ucont,vcont)
518            call enercin(vcov,ucov,vcont,ucont,ecin)
519            dtetaecdt= (ecin0-ecin)/ pk
520c           teta=teta+dtetaecdt
521            dtetadis=dtetadis+dtetaecdt
522        endif
523        teta=teta+dtetadis
524c------------------------------------------------------------------------
525
526
527c    .......        P. Le Van (  ajout  le 17/04/96  )   ...........
528c   ...      Calcul de la valeur moyenne, unique de h aux poles  .....
529c
530
531        DO l  =  1, llm
532          DO ij =  1,iim
533           tppn(ij)  = aire(  ij    ) * teta(  ij    ,l)
534           tpps(ij)  = aire(ij+ip1jm) * teta(ij+ip1jm,l)
535          ENDDO
536           tpn  = SSUM(iim,tppn,1)/apoln
537           tps  = SSUM(iim,tpps,1)/apols
538
539          DO ij = 1, iip1
540           teta(  ij    ,l) = tpn
541           teta(ij+ip1jm,l) = tps
542          ENDDO
543        ENDDO
544
545        if (1 == 0) then
546!!! Ehouarn: lines here 1) kill 1+1=2 in the dynamics
547!!!                     2) should probably not be here anyway
548!!! but are kept for those who would want to revert to previous behaviour
549           DO ij =  1,iim
550             tppn(ij)  = aire(  ij    ) * ps (  ij    )
551             tpps(ij)  = aire(ij+ip1jm) * ps (ij+ip1jm)
552           ENDDO
553             tpn  = SSUM(iim,tppn,1)/apoln
554             tps  = SSUM(iim,tpps,1)/apols
555
556           DO ij = 1, iip1
557             ps(  ij    ) = tpn
558             ps(ij+ip1jm) = tps
559           ENDDO
560        endif ! of if (1 == 0)
561
562      END IF ! of IF(apdiss)
563
564c ajout debug
565c              IF( lafin ) then 
566c                abort_message = 'Simulation finished'
567c                call abort_gcm(modname,abort_message,0)
568c              ENDIF
569       
570c   ********************************************************************
571c   ********************************************************************
572c   .... fin de l'integration dynamique  et physique pour le pas itau ..
573c   ********************************************************************
574c   ********************************************************************
575
576c   preparation du pas d'integration suivant  ......
577
578      IF ( .NOT.purmats ) THEN
579c       ........................................................
580c       ..............  schema matsuno + leapfrog  ..............
581c       ........................................................
582
583            IF(forward. OR. leapf) THEN
584              itau= itau + 1
585c              iday= day_ini+itau/day_step
586c              time= REAL(itau-(iday-day_ini)*day_step)/day_step+time_0
587c                IF(time.GT.1.) THEN
588c                  time = time-1.
589c                  iday = iday+1
590c                ENDIF
591            ENDIF
592
593
594            IF( itau. EQ. itaufinp1 ) then 
595              if (flag_verif) then
596                write(79,*) 'ucov',ucov
597                write(80,*) 'vcov',vcov
598                write(81,*) 'teta',teta
599                write(82,*) 'ps',ps
600                write(83,*) 'q',q
601                WRITE(85,*) 'q1 = ',q(:,:,1)
602                WRITE(86,*) 'q3 = ',q(:,:,3)
603              endif
604
605              abort_message = 'Simulation finished'
606
607              call abort_gcm(modname,abort_message,0)
608            ENDIF
609c-----------------------------------------------------------------------
610c   ecriture du fichier histoire moyenne:
611c   -------------------------------------
612
613            IF(MOD(itau,iperiod).EQ.0 .OR. itau.EQ.itaufin) THEN
614               IF(itau.EQ.itaufin) THEN
615                  iav=1
616               ELSE
617                  iav=0
618               ENDIF
619               
620               IF (ok_dynzon) THEN
621#ifdef CPP_IOIPSL
622                 CALL bilan_dyn(2,dtvr*iperiod,dtvr*day_step*periodav,
623     &                 ps,masse,pk,pbaru,pbarv,teta,phi,ucov,vcov,q)
624#endif
625               END IF
626               IF (ok_dyn_ave) THEN
627#ifdef CPP_IOIPSL
628                 CALL writedynav(itau,vcov,
629     &                 ucov,teta,pk,phi,q,masse,ps,phis)
630#endif
631               ENDIF
632
633            ENDIF ! of IF((MOD(itau,iperiod).EQ.0).OR.(itau.EQ.itaufin))
634
635c-----------------------------------------------------------------------
636c   ecriture de la bande histoire:
637c   ------------------------------
638
639            IF( MOD(itau,iecri).EQ.0) THEN
640             ! Ehouarn: output only during LF or Backward Matsuno
641             if (leapf.or.(.not.leapf.and.(.not.forward))) then
642              CALL geopot(ip1jmp1,teta,pk,pks,phis,phi)
643              unat=0.
644              do l=1,llm
645                unat(iip2:ip1jm,l)=ucov(iip2:ip1jm,l)/cu(iip2:ip1jm)
646                vnat(:,l)=vcov(:,l)/cv(:)
647              enddo
648#ifdef CPP_IOIPSL
649              if (ok_dyn_ins) then
650!               write(lunout,*) "leapfrog: call writehist, itau=",itau
651               CALL writehist(itau,vcov,ucov,teta,phi,q,masse,ps,phis)
652!               call WriteField('ucov',reshape(ucov,(/iip1,jmp1,llm/)))
653!               call WriteField('vcov',reshape(vcov,(/iip1,jjm,llm/)))
654!              call WriteField('teta',reshape(teta,(/iip1,jmp1,llm/)))
655!               call WriteField('ps',reshape(ps,(/iip1,jmp1/)))
656!               call WriteField('masse',reshape(masse,(/iip1,jmp1,llm/)))
657              endif ! of if (ok_dyn_ins)
658#endif
659! For some Grads outputs of fields
660              if (output_grads_dyn) then
661#include "write_grads_dyn.h"
662              endif
663             endif ! of if (leapf.or.(.not.leapf.and.(.not.forward)))
664            ENDIF ! of IF(MOD(itau,iecri).EQ.0)
665
666            IF(itau.EQ.itaufin) THEN
667
668
669!              if (planet_type.eq."earth") then
670! Write an Earth-format restart file
671                CALL dynredem1("restart.nc",start_time,
672     &                         vcov,ucov,teta,q,masse,ps)
673!              endif ! of if (planet_type.eq."earth")
674
675              CLOSE(99)
676              !!! Ehouarn: Why not stop here and now?
677            ENDIF ! of IF (itau.EQ.itaufin)
678
679c-----------------------------------------------------------------------
680c   gestion de l'integration temporelle:
681c   ------------------------------------
682
683            IF( MOD(itau,iperiod).EQ.0 )    THEN
684                    GO TO 1
685            ELSE IF ( MOD(itau-1,iperiod). EQ. 0 ) THEN
686
687                   IF( forward )  THEN
688c      fin du pas forward et debut du pas backward
689
690                      forward = .FALSE.
691                        leapf = .FALSE.
692                           GO TO 2
693
694                   ELSE
695c      fin du pas backward et debut du premier pas leapfrog
696
697                        leapf =  .TRUE.
698                        dt  =  2.*dtvr
699                        GO TO 2
700                   END IF ! of IF (forward)
701            ELSE
702
703c      ......   pas leapfrog  .....
704
705                 leapf = .TRUE.
706                 dt  = 2.*dtvr
707                 GO TO 2
708            END IF ! of IF (MOD(itau,iperiod).EQ.0)
709                   !    ELSEIF (MOD(itau-1,iperiod).EQ.0)
710
711      ELSE ! of IF (.not.purmats)
712
713c       ........................................................
714c       ..............       schema  matsuno        ...............
715c       ........................................................
716            IF( forward )  THEN
717
718             itau =  itau + 1
719c             iday = day_ini+itau/day_step
720c             time = REAL(itau-(iday-day_ini)*day_step)/day_step+time_0
721c
722c                  IF(time.GT.1.) THEN
723c                   time = time-1.
724c                   iday = iday+1
725c                  ENDIF
726
727               forward =  .FALSE.
728               IF( itau. EQ. itaufinp1 ) then 
729                 abort_message = 'Simulation finished'
730                 call abort_gcm(modname,abort_message,0)
731               ENDIF
732               GO TO 2
733
734            ELSE ! of IF(forward) i.e. backward step
735
736              IF(MOD(itau,iperiod).EQ.0 .OR. itau.EQ.itaufin) THEN
737               IF(itau.EQ.itaufin) THEN
738                  iav=1
739               ELSE
740                  iav=0
741               ENDIF
742
743               IF (ok_dynzon) THEN
744#ifdef CPP_IOIPSL
745                 CALL bilan_dyn(2,dtvr*iperiod,dtvr*day_step*periodav,
746     &                 ps,masse,pk,pbaru,pbarv,teta,phi,ucov,vcov,q)
747#endif
748               ENDIF
749               IF (ok_dyn_ave) THEN
750#ifdef CPP_IOIPSL
751                 CALL writedynav(itau,vcov,
752     &                 ucov,teta,pk,phi,q,masse,ps,phis)
753#endif
754               ENDIF
755
756              ENDIF ! of IF(MOD(itau,iperiod).EQ.0 .OR. itau.EQ.itaufin)
757
758              IF(MOD(itau,iecri         ).EQ.0) THEN
759c              IF(MOD(itau,iecri*day_step).EQ.0) THEN
760                CALL geopot(ip1jmp1,teta,pk,pks,phis,phi)
761                unat=0.
762                do l=1,llm
763                  unat(iip2:ip1jm,l)=ucov(iip2:ip1jm,l)/cu(iip2:ip1jm)
764                  vnat(:,l)=vcov(:,l)/cv(:)
765                enddo
766#ifdef CPP_IOIPSL
767              if (ok_dyn_ins) then
768!                write(lunout,*) "leapfrog: call writehist (b)",
769!     &                        itau,iecri
770                CALL writehist(itau,vcov,ucov,teta,phi,q,masse,ps,phis)
771              endif ! of if (ok_dyn_ins)
772#endif
773! For some Grads outputs
774                if (output_grads_dyn) then
775#include "write_grads_dyn.h"
776                endif
777
778              ENDIF ! of IF(MOD(itau,iecri         ).EQ.0)
779
780              IF(itau.EQ.itaufin) THEN
781!                if (planet_type.eq."earth") then
782                  CALL dynredem1("restart.nc",start_time,
783     &                           vcov,ucov,teta,q,masse,ps)
784!                endif ! of if (planet_type.eq."earth")
785              ENDIF ! of IF(itau.EQ.itaufin)
786
787              forward = .TRUE.
788              GO TO  1
789
790            ENDIF ! of IF (forward)
791
792      END IF ! of IF(.not.purmats)
793
794      STOP
795      END
Note: See TracBrowser for help on using the repository browser.