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

Last change on this file since 2278 was 2270, checked in by crisi, 9 years ago

Adding isotopes in the dynamics and more generally tracers of tracers.
CRisi

  • 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: 27.7 KB
Line 
1!
2! $Id: leapfrog.F 2270 2015-05-07 15:45:04Z fhourdin $
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,ok_iso_verif
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        if (ok_iso_verif) then
238           call check_isotopes_seq(q,ip1jmp1,'leapfrog 321')
239        endif !if (ok_iso_verif) then
240
241#ifdef CPP_IOIPSL
242      if (ok_guide) then
243        call guide_main(itau,ucov,vcov,teta,q,masse,ps)
244      endif
245#endif
246
247
248c
249c     IF( MOD( itau, 10* day_step ).EQ.0 )  THEN
250c       CALL  test_period ( ucov,vcov,teta,q,p,phis )
251c       PRINT *,' ----   Test_period apres continue   OK ! -----', itau
252c     ENDIF
253c
254
255! Save fields obtained at previous time step as '...m1'
256      CALL SCOPY( ijmllm ,vcov , 1, vcovm1 , 1 )
257      CALL SCOPY( ijp1llm,ucov , 1, ucovm1 , 1 )
258      CALL SCOPY( ijp1llm,teta , 1, tetam1 , 1 )
259      CALL SCOPY( ijp1llm,masse, 1, massem1, 1 )
260      CALL SCOPY( ip1jmp1, ps  , 1,   psm1 , 1 )
261
262      forward = .TRUE.
263      leapf   = .FALSE.
264      dt      =  dtvr
265
266c   ...    P.Le Van .26/04/94  ....
267! Ehouarn: finvmaold is actually not used
268!      CALL SCOPY   ( ijp1llm,   masse, 1, finvmaold,     1 )
269!      CALL filtreg ( finvmaold ,jjp1, llm, -2,2, .TRUE., 1 )
270
271        if (ok_iso_verif) then
272           call check_isotopes_seq(q,ip1jmp1,'leapfrog 400')
273        endif !if (ok_iso_verif) then
274
275   2  CONTINUE ! Matsuno backward or leapfrog step begins here
276
277c-----------------------------------------------------------------------
278
279c   date:
280c   -----
281
282
283c   gestion des appels de la physique et des dissipations:
284c   ------------------------------------------------------
285c
286c   ...    P.Le Van  ( 6/02/95 )  ....
287
288      apphys = .FALSE.
289      statcl = .FALSE.
290      conser = .FALSE.
291      apdiss = .FALSE.
292
293      IF( purmats ) THEN
294      ! Purely Matsuno time stepping
295         IF( MOD(itau,iconser) .EQ.0.AND.  forward    ) conser = .TRUE.
296         IF( MOD(itau,dissip_period ).EQ.0.AND..NOT.forward )
297     s        apdiss = .TRUE.
298         IF( MOD(itau,iphysiq ).EQ.0.AND..NOT.forward
299     s          .and. physic                        ) apphys = .TRUE.
300      ELSE
301      ! Leapfrog/Matsuno time stepping
302         IF( MOD(itau   ,iconser) .EQ. 0              ) conser = .TRUE.
303         IF( MOD(itau+1,dissip_period).EQ.0 .AND. .NOT. forward )
304     s        apdiss = .TRUE.
305         IF( MOD(itau+1,iphysiq).EQ.0.AND.physic       ) apphys=.TRUE.
306      END IF
307
308! Ehouarn: for Shallow Water case (ie: 1 vertical layer),
309!          supress dissipation step
310      if (llm.eq.1) then
311        apdiss=.false.
312      endif
313
314
315        if (ok_iso_verif) then
316           call check_isotopes_seq(q,ip1jmp1,'leapfrog 589')
317        endif !if (ok_iso_verif) then
318
319c-----------------------------------------------------------------------
320c   calcul des tendances dynamiques:
321c   --------------------------------
322
323      ! compute geopotential phi()
324      CALL geopot  ( ip1jmp1, teta  , pk , pks,  phis  , phi   )
325
326      time = jD_cur + jH_cur
327      CALL caldyn
328     $  ( itau,ucov,vcov,teta,ps,masse,pk,pkf,phis ,
329     $    phi,conser,du,dv,dteta,dp,w, pbaru,pbarv, time )
330
331
332c-----------------------------------------------------------------------
333c   calcul des tendances advection des traceurs (dont l'humidite)
334c   -------------------------------------------------------------
335
336        if (ok_iso_verif) then
337           call check_isotopes_seq(q,ip1jmp1,
338     &           'leapfrog 686: avant caladvtrac')
339        endif !if (ok_iso_verif) then
340
341      IF( forward. OR . leapf )  THEN
342! Ehouarn: NB: fields sent to advtrac are those at the beginning of the time step
343         CALL caladvtrac(q,pbaru,pbarv,
344     *        p, masse, dq,  teta,
345     .        flxw, pk)
346
347         
348         IF (offline) THEN
349Cmaf stokage du flux de masse pour traceurs OFF-LINE
350
351#ifdef CPP_IOIPSL
352           CALL fluxstokenc(pbaru,pbarv,masse,teta,phi,phis,
353     .   dtvr, itau)
354#endif
355
356
357         ENDIF ! of IF (offline)
358c
359      ENDIF ! of IF( forward. OR . leapf )
360
361
362c-----------------------------------------------------------------------
363c   integrations dynamique et traceurs:
364c   ----------------------------------
365
366        if (ok_iso_verif) then
367           write(*,*) 'leapfrog 720'
368           call check_isotopes_seq(q,ip1jmp1,'leapfrog 756')
369        endif !if (ok_iso_verif) then
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       if (ok_iso_verif) then
376          write(*,*) 'leapfrog 724'
377           call check_isotopes_seq(q,ip1jmp1,'leapfrog 762')
378        endif !if (ok_iso_verif) then
379
380c .P.Le Van (26/04/94  ajout de  finvpold dans l'appel d'integrd)
381c
382c-----------------------------------------------------------------------
383c   calcul des tendances physiques:
384c   -------------------------------
385c    ########   P.Le Van ( Modif le  6/02/95 )   ###########
386c
387       IF( purmats )  THEN
388          IF( itau.EQ.itaufin.AND..NOT.forward ) lafin = .TRUE.
389       ELSE
390          IF( itau+1. EQ. itaufin )              lafin = .TRUE.
391       ENDIF
392c
393c
394       IF( apphys )  THEN
395c
396c     .......   Ajout   P.Le Van ( 17/04/96 )   ...........
397c
398
399         CALL pression (  ip1jmp1, ap, bp, ps,  p      )
400         if (pressure_exner) then
401           CALL exner_hyb(  ip1jmp1, ps, p,pks, pk, pkf )
402         else
403           CALL exner_milieu( ip1jmp1, ps, p, pks, pk, pkf )
404         endif
405
406! Appel a geopot ajoute le 2014/05/08 pour garantir la convergence numerique
407! avec dyn3dmem
408         CALL geopot  ( ip1jmp1, teta  , pk , pks,  phis  , phi   )
409
410!           rdaym_ini  = itau * dtvr / daysec
411!           rdayvrai   = rdaym_ini  + day_ini
412!           jD_cur = jD_ref + day_ini - day_ref
413!     $        + int (itau * dtvr / daysec)
414!           jH_cur = jH_ref +                                            &
415!     &              (itau * dtvr / daysec - int(itau * dtvr / daysec))
416           jD_cur = jD_ref + day_ini - day_ref +                        &
417     &          itau/day_step
418
419           IF (planet_type .eq."generic") THEN
420              ! AS: we make jD_cur to be pday
421              jD_cur = int(day_ini + itau/day_step)
422           ENDIF
423
424           jH_cur = jH_ref + start_time +                               &
425     &              mod(itau,day_step)/float(day_step)
426           jD_cur = jD_cur + int(jH_cur)
427           jH_cur = jH_cur - int(jH_cur)
428!         write(lunout,*)'itau, jD_cur = ', itau, jD_cur, jH_cur
429!         call ju2ymds(jD_cur+jH_cur, an, mois, jour, secondes)
430!         write(lunout,*)'current date = ',an, mois, jour, secondes
431
432c rajout debug
433c       lafin = .true.
434
435
436c   Inbterface avec les routines de phylmd (phymars ... )
437c   -----------------------------------------------------
438
439c+jld
440
441c  Diagnostique de conservation de l'énergie : initialisation
442         IF (ip_ebil_dyn.ge.1 ) THEN
443          ztit='bil dyn'
444! Ehouarn: be careful, diagedyn is Earth-specific (includes ../phylmd/..)!
445           IF (planet_type.eq."earth") THEN
446#ifdef CPP_EARTH
447            CALL diagedyn(ztit,2,1,1,dtphys
448     &    , ucov    , vcov , ps, p ,pk , teta , q(:,:,1), q(:,:,2))
449#endif
450           ENDIF
451         ENDIF ! of IF (ip_ebil_dyn.ge.1 )
452c-jld
453#ifdef CPP_IOIPSL
454cIM decommenter les 6 lignes suivantes pour sortir quelques parametres dynamiques de LMDZ
455cIM uncomment next 6 lines to get some parameters for LMDZ dynamics
456c        IF (first) THEN
457c         first=.false.
458c#include "ini_paramLMDZ_dyn.h"
459c        ENDIF
460c
461c#include "write_paramLMDZ_dyn.h"
462c
463#endif
464! #endif of #ifdef CPP_IOIPSL
465#ifdef CPP_PHYS
466         CALL calfis( lafin , jD_cur, jH_cur,
467     $               ucov,vcov,teta,q,masse,ps,p,pk,phis,phi ,
468     $               du,dv,dteta,dq,
469     $               flxw,dufi,dvfi,dtetafi,dqfi,dpfi  )
470#endif
471c      ajout des tendances physiques:
472c      ------------------------------
473          CALL addfi( dtphys, leapf, forward   ,
474     $                  ucov, vcov, teta , q   ,ps ,
475     $                 dufi, dvfi, dtetafi , dqfi ,dpfi  )
476          ! since addfi updates ps(), also update p(), masse() and pk()
477          CALL pression (ip1jmp1,ap,bp,ps,p)
478          CALL massdair(p,masse)
479          if (pressure_exner) then
480            CALL exner_hyb(ip1jmp1,ps,p,pks,pk,pkf)
481          else
482            CALL exner_milieu(ip1jmp1,ps,p,pks,pk,pkf)
483          endif
484
485         IF (ok_strato) THEN
486           CALL top_bound( vcov,ucov,teta,masse,dtphys)
487         ENDIF
488       
489c
490c  Diagnostique de conservation de l'énergie : difference
491         IF (ip_ebil_dyn.ge.1 ) THEN
492          ztit='bil phys'
493          IF (planet_type.eq."earth") THEN
494           CALL diagedyn(ztit,2,1,1,dtphys
495     &     , ucov    , vcov , ps, p ,pk , teta , q(:,:,1), q(:,:,2))
496          ENDIF
497         ENDIF ! of IF (ip_ebil_dyn.ge.1 )
498
499       ENDIF ! of IF( apphys )
500
501      IF(iflag_phys.EQ.2) THEN ! "Newtonian" case
502!   Academic case : Simple friction and Newtonan relaxation
503!   -------------------------------------------------------
504        DO l=1,llm   
505          DO ij=1,ip1jmp1
506           teta(ij,l)=teta(ij,l)-dtvr*
507     &      (teta(ij,l)-tetarappel(ij,l))*(knewt_g+knewt_t(l)*clat4(ij))
508          ENDDO
509        ENDDO ! of DO l=1,llm
510       
511        if (planet_type.eq."giant") then
512          ! add an intrinsic heat flux at the base of the atmosphere
513          teta(:,1)=teta(:,1)+dtvr*aire(:)*ihf/cpp/masse(:,1)
514        endif
515
516        call friction(ucov,vcov,dtvr)
517       
518        ! Sponge layer (if any)
519        IF (ok_strato) THEN
520!          dufi(:,:)=0.
521!          dvfi(:,:)=0.
522!          dtetafi(:,:)=0.
523!          dqfi(:,:,:)=0.
524!          dpfi(:)=0.
525!          CALL top_bound(vcov,ucov,teta,masse,dufi,dvfi,dtetafi)
526           CALL top_bound( vcov,ucov,teta,masse,dtvr)
527!          CALL addfi( dtvr, leapf, forward   ,
528!     $                  ucov, vcov, teta , q   ,ps ,
529!     $                 dufi, dvfi, dtetafi , dqfi ,dpfi  )
530        ENDIF ! of IF (ok_strato)
531      ENDIF ! of IF (iflag_phys.EQ.2)
532
533
534c-jld
535
536        CALL pression ( ip1jmp1, ap, bp, ps, p                  )
537        if (pressure_exner) then
538          CALL exner_hyb( ip1jmp1, ps, p, pks, pk, pkf )
539        else
540          CALL exner_milieu( ip1jmp1, ps, p, pks, pk, pkf )
541        endif
542        CALL massdair(p,masse)
543
544        if (ok_iso_verif) then
545           call check_isotopes_seq(q,ip1jmp1,'leapfrog 1196')
546        endif !if (ok_iso_verif) then
547
548c-----------------------------------------------------------------------
549c   dissipation horizontale et verticale  des petites echelles:
550c   ----------------------------------------------------------
551
552      IF(apdiss) THEN
553
554
555c   calcul de l'energie cinetique avant dissipation
556        call covcont(llm,ucov,vcov,ucont,vcont)
557        call enercin(vcov,ucov,vcont,ucont,ecin0)
558
559c   dissipation
560        CALL dissip(vcov,ucov,teta,p,dvdis,dudis,dtetadis)
561        ucov=ucov+dudis
562        vcov=vcov+dvdis
563c       teta=teta+dtetadis
564
565
566c------------------------------------------------------------------------
567        if (dissip_conservative) then
568C       On rajoute la tendance due a la transform. Ec -> E therm. cree
569C       lors de la dissipation
570            call covcont(llm,ucov,vcov,ucont,vcont)
571            call enercin(vcov,ucov,vcont,ucont,ecin)
572            dtetaecdt= (ecin0-ecin)/ pk
573c           teta=teta+dtetaecdt
574            dtetadis=dtetadis+dtetaecdt
575        endif
576        teta=teta+dtetadis
577c------------------------------------------------------------------------
578
579
580c    .......        P. Le Van (  ajout  le 17/04/96  )   ...........
581c   ...      Calcul de la valeur moyenne, unique de h aux poles  .....
582c
583
584        DO l  =  1, llm
585          DO ij =  1,iim
586           tppn(ij)  = aire(  ij    ) * teta(  ij    ,l)
587           tpps(ij)  = aire(ij+ip1jm) * teta(ij+ip1jm,l)
588          ENDDO
589           tpn  = SSUM(iim,tppn,1)/apoln
590           tps  = SSUM(iim,tpps,1)/apols
591
592          DO ij = 1, iip1
593           teta(  ij    ,l) = tpn
594           teta(ij+ip1jm,l) = tps
595          ENDDO
596        ENDDO
597
598        if (1 == 0) then
599!!! Ehouarn: lines here 1) kill 1+1=2 in the dynamics
600!!!                     2) should probably not be here anyway
601!!! but are kept for those who would want to revert to previous behaviour
602           DO ij =  1,iim
603             tppn(ij)  = aire(  ij    ) * ps (  ij    )
604             tpps(ij)  = aire(ij+ip1jm) * ps (ij+ip1jm)
605           ENDDO
606             tpn  = SSUM(iim,tppn,1)/apoln
607             tps  = SSUM(iim,tpps,1)/apols
608
609           DO ij = 1, iip1
610             ps(  ij    ) = tpn
611             ps(ij+ip1jm) = tps
612           ENDDO
613        endif ! of if (1 == 0)
614
615      END IF ! of IF(apdiss)
616
617c ajout debug
618c              IF( lafin ) then 
619c                abort_message = 'Simulation finished'
620c                call abort_gcm(modname,abort_message,0)
621c              ENDIF
622       
623c   ********************************************************************
624c   ********************************************************************
625c   .... fin de l'integration dynamique  et physique pour le pas itau ..
626c   ********************************************************************
627c   ********************************************************************
628
629c   preparation du pas d'integration suivant  ......
630
631        if (ok_iso_verif) then
632           call check_isotopes_seq(q,ip1jmp1,'leapfrog 1509')
633        endif !if (ok_iso_verif) then
634
635      IF ( .NOT.purmats ) THEN
636c       ........................................................
637c       ..............  schema matsuno + leapfrog  ..............
638c       ........................................................
639
640            IF(forward. OR. leapf) THEN
641              itau= itau + 1
642c              iday= day_ini+itau/day_step
643c              time= REAL(itau-(iday-day_ini)*day_step)/day_step+time_0
644c                IF(time.GT.1.) THEN
645c                  time = time-1.
646c                  iday = iday+1
647c                ENDIF
648            ENDIF
649
650
651            IF( itau. EQ. itaufinp1 ) then 
652              if (flag_verif) then
653                write(79,*) 'ucov',ucov
654                write(80,*) 'vcov',vcov
655                write(81,*) 'teta',teta
656                write(82,*) 'ps',ps
657                write(83,*) 'q',q
658                WRITE(85,*) 'q1 = ',q(:,:,1)
659                WRITE(86,*) 'q3 = ',q(:,:,3)
660              endif
661
662              abort_message = 'Simulation finished'
663
664              call abort_gcm(modname,abort_message,0)
665            ENDIF
666c-----------------------------------------------------------------------
667c   ecriture du fichier histoire moyenne:
668c   -------------------------------------
669
670            IF(MOD(itau,iperiod).EQ.0 .OR. itau.EQ.itaufin) THEN
671               IF(itau.EQ.itaufin) THEN
672                  iav=1
673               ELSE
674                  iav=0
675               ENDIF
676               
677               IF (ok_dynzon) THEN
678#ifdef CPP_IOIPSL
679                 CALL bilan_dyn(2,dtvr*iperiod,dtvr*day_step*periodav,
680     &                 ps,masse,pk,pbaru,pbarv,teta,phi,ucov,vcov,q)
681#endif
682               END IF
683               IF (ok_dyn_ave) THEN
684#ifdef CPP_IOIPSL
685                 CALL writedynav(itau,vcov,
686     &                 ucov,teta,pk,phi,q,masse,ps,phis)
687#endif
688               ENDIF
689
690            ENDIF ! of IF((MOD(itau,iperiod).EQ.0).OR.(itau.EQ.itaufin))
691
692        if (ok_iso_verif) then
693           call check_isotopes_seq(q,ip1jmp1,'leapfrog 1584')
694        endif !if (ok_iso_verif) then
695
696c-----------------------------------------------------------------------
697c   ecriture de la bande histoire:
698c   ------------------------------
699
700            IF( MOD(itau,iecri).EQ.0) THEN
701             ! Ehouarn: output only during LF or Backward Matsuno
702             if (leapf.or.(.not.leapf.and.(.not.forward))) then
703              CALL geopot(ip1jmp1,teta,pk,pks,phis,phi)
704              unat=0.
705              do l=1,llm
706                unat(iip2:ip1jm,l)=ucov(iip2:ip1jm,l)/cu(iip2:ip1jm)
707                vnat(:,l)=vcov(:,l)/cv(:)
708              enddo
709#ifdef CPP_IOIPSL
710              if (ok_dyn_ins) then
711!               write(lunout,*) "leapfrog: call writehist, itau=",itau
712               CALL writehist(itau,vcov,ucov,teta,phi,q,masse,ps,phis)
713!               call WriteField('ucov',reshape(ucov,(/iip1,jmp1,llm/)))
714!               call WriteField('vcov',reshape(vcov,(/iip1,jjm,llm/)))
715!              call WriteField('teta',reshape(teta,(/iip1,jmp1,llm/)))
716!               call WriteField('ps',reshape(ps,(/iip1,jmp1/)))
717!               call WriteField('masse',reshape(masse,(/iip1,jmp1,llm/)))
718              endif ! of if (ok_dyn_ins)
719#endif
720! For some Grads outputs of fields
721              if (output_grads_dyn) then
722#include "write_grads_dyn.h"
723              endif
724             endif ! of if (leapf.or.(.not.leapf.and.(.not.forward)))
725            ENDIF ! of IF(MOD(itau,iecri).EQ.0)
726
727            IF(itau.EQ.itaufin) THEN
728
729
730!              if (planet_type.eq."earth") then
731! Write an Earth-format restart file
732                CALL dynredem1("restart.nc",start_time,
733     &                         vcov,ucov,teta,q,masse,ps)
734!              endif ! of if (planet_type.eq."earth")
735
736              CLOSE(99)
737              !!! Ehouarn: Why not stop here and now?
738            ENDIF ! of IF (itau.EQ.itaufin)
739
740c-----------------------------------------------------------------------
741c   gestion de l'integration temporelle:
742c   ------------------------------------
743
744            IF( MOD(itau,iperiod).EQ.0 )    THEN
745                    GO TO 1
746            ELSE IF ( MOD(itau-1,iperiod). EQ. 0 ) THEN
747
748                   IF( forward )  THEN
749c      fin du pas forward et debut du pas backward
750
751                      forward = .FALSE.
752                        leapf = .FALSE.
753                           GO TO 2
754
755                   ELSE
756c      fin du pas backward et debut du premier pas leapfrog
757
758                        leapf =  .TRUE.
759                        dt  =  2.*dtvr
760                        GO TO 2
761                   END IF ! of IF (forward)
762            ELSE
763
764c      ......   pas leapfrog  .....
765
766                 leapf = .TRUE.
767                 dt  = 2.*dtvr
768                 GO TO 2
769            END IF ! of IF (MOD(itau,iperiod).EQ.0)
770                   !    ELSEIF (MOD(itau-1,iperiod).EQ.0)
771
772      ELSE ! of IF (.not.purmats)
773
774        if (ok_iso_verif) then
775           call check_isotopes_seq(q,ip1jmp1,'leapfrog 1664')
776        endif !if (ok_iso_verif) then
777
778c       ........................................................
779c       ..............       schema  matsuno        ...............
780c       ........................................................
781            IF( forward )  THEN
782
783             itau =  itau + 1
784c             iday = day_ini+itau/day_step
785c             time = REAL(itau-(iday-day_ini)*day_step)/day_step+time_0
786c
787c                  IF(time.GT.1.) THEN
788c                   time = time-1.
789c                   iday = iday+1
790c                  ENDIF
791
792               forward =  .FALSE.
793               IF( itau. EQ. itaufinp1 ) then 
794                 abort_message = 'Simulation finished'
795                 call abort_gcm(modname,abort_message,0)
796               ENDIF
797               GO TO 2
798
799            ELSE ! of IF(forward) i.e. backward step
800 
801        if (ok_iso_verif) then
802           call check_isotopes_seq(q,ip1jmp1,'leapfrog 1698')
803        endif !if (ok_iso_verif) then 
804
805              IF(MOD(itau,iperiod).EQ.0 .OR. itau.EQ.itaufin) THEN
806               IF(itau.EQ.itaufin) THEN
807                  iav=1
808               ELSE
809                  iav=0
810               ENDIF
811
812               IF (ok_dynzon) THEN
813#ifdef CPP_IOIPSL
814                 CALL bilan_dyn(2,dtvr*iperiod,dtvr*day_step*periodav,
815     &                 ps,masse,pk,pbaru,pbarv,teta,phi,ucov,vcov,q)
816#endif
817               ENDIF
818               IF (ok_dyn_ave) THEN
819#ifdef CPP_IOIPSL
820                 CALL writedynav(itau,vcov,
821     &                 ucov,teta,pk,phi,q,masse,ps,phis)
822#endif
823               ENDIF
824
825              ENDIF ! of IF(MOD(itau,iperiod).EQ.0 .OR. itau.EQ.itaufin)
826
827              IF(MOD(itau,iecri         ).EQ.0) THEN
828c              IF(MOD(itau,iecri*day_step).EQ.0) THEN
829                CALL geopot(ip1jmp1,teta,pk,pks,phis,phi)
830                unat=0.
831                do l=1,llm
832                  unat(iip2:ip1jm,l)=ucov(iip2:ip1jm,l)/cu(iip2:ip1jm)
833                  vnat(:,l)=vcov(:,l)/cv(:)
834                enddo
835#ifdef CPP_IOIPSL
836              if (ok_dyn_ins) then
837!                write(lunout,*) "leapfrog: call writehist (b)",
838!     &                        itau,iecri
839                CALL writehist(itau,vcov,ucov,teta,phi,q,masse,ps,phis)
840              endif ! of if (ok_dyn_ins)
841#endif
842! For some Grads outputs
843                if (output_grads_dyn) then
844#include "write_grads_dyn.h"
845                endif
846
847              ENDIF ! of IF(MOD(itau,iecri         ).EQ.0)
848
849              IF(itau.EQ.itaufin) THEN
850!                if (planet_type.eq."earth") then
851                  CALL dynredem1("restart.nc",start_time,
852     &                           vcov,ucov,teta,q,masse,ps)
853!                endif ! of if (planet_type.eq."earth")
854              ENDIF ! of IF(itau.EQ.itaufin)
855
856              forward = .TRUE.
857              GO TO  1
858
859            ENDIF ! of IF (forward)
860
861      END IF ! of IF(.not.purmats)
862
863      STOP
864      END
Note: See TracBrowser for help on using the repository browser.