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

Last change on this file since 2038 was 2038, checked in by fhourdin, 10 years ago

Possibilité d'imposer le nombre de pas de temps de la simulation avec nday<0
If nday<0, nday is the total number of time step of the simulation

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