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

Last change on this file since 2221 was 2221, checked in by Ehouarn Millour, 9 years ago

Some cleanup: remove (unused) clesph0 from dynamics.
EM

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