source: LMDZ6/trunk/libf/dyn3d/leapfrog.F90 @ 5267

Last change on this file since 5267 was 5267, checked in by abarral, 2 days ago

Remove CPP_IOIPSL cpp keys uses

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