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

Last change on this file since 2056 was 2056, checked in by Laurent Fairhead, 10 years ago

Merged trunk changes r1997:2055 into testing branch

  • 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
RevLine 
[524]1!
[1279]2! $Id: leapfrog.F 2056 2014-06-11 13:46:46Z fairhead $
3!
[524]4c
5c
[1146]6      SUBROUTINE leapfrog(ucov,vcov,teta,ps,masse,phis,q,clesphy0,
[559]7     &                    time_0)
[524]8
9
[692]10cIM : pour sortir les param. du modele dans un fis. netcdf 110106
[1146]11#ifdef CPP_IOIPSL
12      use IOIPSL
13#endif
[1999]14      USE infotrac, ONLY: nqtot
[1279]15      USE guide_mod, ONLY : guide_main
[1999]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
[2056]21      use exner_hyb_m, only: exner_hyb
22      use exner_milieu_m, only: exner_milieu
23
[524]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"
[1403]68!#include "com_io_dyn.h"
[524]69#include "iniprint.h"
70#include "academic.h"
71
[956]72! FH 2008/05/09 On elimine toutes les clefs physiques dans la dynamique
73! #include "clesphys.h"
[692]74
[1999]75      INTEGER,PARAMETER :: longcles = 20
76      REAL,INTENT(IN) :: clesphy0( longcles ) ! not used
77      REAL,INTENT(IN) :: time_0 ! not used
[524]78
[1999]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
[524]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)
[1146]107      REAL dteta(ip1jmp1,llm),dq(ip1jmp1,llm,nqtot),dp(ip1jmp1)
[524]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)
[1146]115      REAL dtetafi(ip1jmp1,llm),dqfi(ip1jmp1,llm,nqtot),dpfi(ip1jmp1)
[524]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
[1279]123!      INTEGER  iday ! jour julien
124      REAL       time
[524]125
126      REAL  SSUM
[1665]127!     REAL finvmaold(ip1jmp1,llm)
[524]128
[566]129cym      LOGICAL  lafin
130      LOGICAL :: lafin=.false.
[524]131      INTEGER ij,iq,l
132      INTEGER ik
133
134      real time_step, t_wrt, t_ops
135
[1279]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
[524]143      LOGICAL first,callinigrads
[692]144cIM : pour sortir les param. du modele dans un fis. netcdf 110106
145      save first
146      data first/.true./
[1279]147      real dt_cum
[692]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.)
[1529]158      logical physic
[524]159
160      data callinigrads/.true./
161      character*10 string10
162
[960]163      REAL :: flxw(ip1jmp1,llm)  ! flux de masse verticale
[524]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
[692]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/
[524]178c-jld
179
180      character*80 dynhist_file, dynhistave_file
[1520]181      character(len=*),parameter :: modname="leapfrog"
[524]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
[1286]194      logical , parameter :: flag_verif = .false.
[999]195     
196
[825]197      integer itau_w   ! pas de temps ecriture = itap + itau_phy
198
199
[2056]200      if (nday>=0) then
201         itaufin   = nday*day_step
202      else
203         itaufin   = -nday
204      endif
[524]205      itaufinp1 = itaufin +1
[1529]206      itau = 0
207      physic=.true.
208      if (iflag_phys==0.or.iflag_phys==2) physic=.false.
[524]209
[1403]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
[524]216
217
218c-----------------------------------------------------------------------
219c   On initialise la pression et la fonction d'Exner :
220c   --------------------------------------------------
221
[1454]222      dq(:,:,:)=0.
[524]223      CALL pression ( ip1jmp1, ap, bp, ps, p       )
[1665]224      if (pressure_exner) then
[2056]225        CALL exner_hyb( ip1jmp1, ps, p, pks, pk, pkf )
[1665]226      else
[2056]227        CALL exner_milieu( ip1jmp1, ps, p, pks, pk, pkf )
[1520]228      endif
[524]229
230c-----------------------------------------------------------------------
231c   Debut de l'integration temporelle:
232c   ----------------------------------
233
[1665]234   1  CONTINUE ! Matsuno Forward step begins here
[524]235
[1665]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)
[524]242
[1279]243
[524]244#ifdef CPP_IOIPSL
[1279]245      if (ok_guide) then
246        call guide_main(itau,ucov,vcov,teta,q,masse,ps)
[524]247      endif
248#endif
[1279]249
250
[524]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
[1146]257
258! Save fields obtained at previous time step as '...m1'
[524]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  ....
[1665]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 )
[524]273
[1665]274   2  CONTINUE ! Matsuno backward or leapfrog step begins here
[524]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
[1403]293      ! Purely Matsuno time stepping
[524]294         IF( MOD(itau,iconser) .EQ.0.AND.  forward    ) conser = .TRUE.
[1502]295         IF( MOD(itau,dissip_period ).EQ.0.AND..NOT.forward )
296     s        apdiss = .TRUE.
[524]297         IF( MOD(itau,iphysiq ).EQ.0.AND..NOT.forward
[1529]298     s          .and. physic                        ) apphys = .TRUE.
[524]299      ELSE
[1403]300      ! Leapfrog/Matsuno time stepping
[524]301         IF( MOD(itau   ,iconser) .EQ. 0              ) conser = .TRUE.
[1502]302         IF( MOD(itau+1,dissip_period).EQ.0 .AND. .NOT. forward )
303     s        apdiss = .TRUE.
[1529]304         IF( MOD(itau+1,iphysiq).EQ.0.AND.physic       ) apphys=.TRUE.
[524]305      END IF
306
[1403]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
[524]313c-----------------------------------------------------------------------
314c   calcul des tendances dynamiques:
315c   --------------------------------
316
[1665]317      ! compute geopotential phi()
[524]318      CALL geopot  ( ip1jmp1, teta  , pk , pks,  phis  , phi   )
319
[1279]320      time = jD_cur + jH_cur
[524]321      CALL caldyn
322     $  ( itau,ucov,vcov,teta,ps,masse,pk,pkf,phis ,
[1279]323     $    phi,conser,du,dv,dteta,dp,w, pbaru,pbarv, time )
[524]324
[1279]325
[524]326c-----------------------------------------------------------------------
327c   calcul des tendances advection des traceurs (dont l'humidite)
328c   -------------------------------------------------------------
329
330      IF( forward. OR . leapf )  THEN
[1999]331! Ehouarn: NB: fields sent to advtrac are those at the beginning of the time step
[960]332         CALL caladvtrac(q,pbaru,pbarv,
333     *        p, masse, dq,  teta,
334     .        flxw, pk)
335         
[524]336         IF (offline) THEN
337Cmaf stokage du flux de masse pour traceurs OFF-LINE
338
339#ifdef CPP_IOIPSL
[541]340           CALL fluxstokenc(pbaru,pbarv,masse,teta,phi,phis,
341     .   dtvr, itau)
[524]342#endif
343
344
[1146]345         ENDIF ! of IF (offline)
[524]346c
[1146]347      ENDIF ! of IF( forward. OR . leapf )
[524]348
349
350c-----------------------------------------------------------------------
351c   integrations dynamique et traceurs:
352c   ----------------------------------
353
354
355       CALL integrd ( 2,vcovm1,ucovm1,tetam1,psm1,massem1 ,
[1665]356     $         dv,du,dteta,dq,dp,vcov,ucov,teta,q,ps,masse,phis )
357!     $              finvmaold                                    )
[524]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      )
[1665]380         if (pressure_exner) then
[2056]381           CALL exner_hyb(  ip1jmp1, ps, p,pks, pk, pkf )
[1665]382         else
[2056]383           CALL exner_milieu( ip1jmp1, ps, p, pks, pk, pkf )
[1520]384         endif
[524]385
[2056]386! Appel a geopot ajoute le 2014/05/08 pour garantir la convergence numerique
387! avec dyn3dmem
388         CALL geopot  ( ip1jmp1, teta  , pk , pks,  phis  , phi   )
389
[1279]390!           rdaym_ini  = itau * dtvr / daysec
391!           rdayvrai   = rdaym_ini  + day_ini
[1665]392!           jD_cur = jD_ref + day_ini - day_ref
393!     $        + int (itau * dtvr / daysec)
394!           jH_cur = jH_ref +                                            &
395!     &              (itau * dtvr / daysec - int(itau * dtvr / daysec))
396           jD_cur = jD_ref + day_ini - day_ref +                        &
397     &          itau/day_step
[1707]398
399           IF (planet_type .eq."generic") THEN
400              ! AS: we make jD_cur to be pday
401              jD_cur = int(day_ini + itau/day_step)
402           ENDIF
403
[1665]404           jH_cur = jH_ref + start_time +                               &
405     &              mod(itau,day_step)/float(day_step)
406           jD_cur = jD_cur + int(jH_cur)
407           jH_cur = jH_cur - int(jH_cur)
[1279]408!         write(lunout,*)'itau, jD_cur = ', itau, jD_cur, jH_cur
409!         call ju2ymds(jD_cur+jH_cur, an, mois, jour, secondes)
410!         write(lunout,*)'current date = ',an, mois, jour, secondes
[524]411
412c rajout debug
413c       lafin = .true.
414
415
416c   Inbterface avec les routines de phylmd (phymars ... )
417c   -----------------------------------------------------
418
419c+jld
420
421c  Diagnostique de conservation de l'énergie : initialisation
[1146]422         IF (ip_ebil_dyn.ge.1 ) THEN
[524]423          ztit='bil dyn'
[1146]424! Ehouarn: be careful, diagedyn is Earth-specific (includes ../phylmd/..)!
425           IF (planet_type.eq."earth") THEN
[1665]426#ifdef CPP_EARTH
[1146]427            CALL diagedyn(ztit,2,1,1,dtphys
428     &    , ucov    , vcov , ps, p ,pk , teta , q(:,:,1), q(:,:,2))
[1665]429#endif
[1146]430           ENDIF
431         ENDIF ! of IF (ip_ebil_dyn.ge.1 )
[524]432c-jld
[1146]433#ifdef CPP_IOIPSL
[1669]434cIM decommenter les 6 lignes suivantes pour sortir quelques parametres dynamiques de LMDZ
435cIM uncomment next 6 lines to get some parameters for LMDZ dynamics
436c        IF (first) THEN
437c         first=.false.
438c#include "ini_paramLMDZ_dyn.h"
439c        ENDIF
[692]440c
[1669]441c#include "write_paramLMDZ_dyn.h"
[692]442c
[1146]443#endif
444! #endif of #ifdef CPP_IOIPSL
[1279]445         CALL calfis( lafin , jD_cur, jH_cur,
[524]446     $               ucov,vcov,teta,q,masse,ps,p,pk,phis,phi ,
[960]447     $               du,dv,dteta,dq,
[524]448     $               flxw,
449     $               clesphy0, dufi,dvfi,dtetafi,dqfi,dpfi  )
450
451c      ajout des tendances physiques:
452c      ------------------------------
[1146]453          CALL addfi( dtphys, leapf, forward   ,
[524]454     $                  ucov, vcov, teta , q   ,ps ,
455     $                 dufi, dvfi, dtetafi , dqfi ,dpfi  )
[1999]456          ! since addfi updates ps(), also update p(), masse() and pk()
457          CALL pression (ip1jmp1,ap,bp,ps,p)
458          CALL massdair(p,masse)
459          if (pressure_exner) then
[2056]460            CALL exner_hyb(ip1jmp1,ps,p,pks,pk,pkf)
[1999]461          else
[2056]462            CALL exner_milieu(ip1jmp1,ps,p,pks,pk,pkf)
[1999]463          endif
[1795]464
465         IF (ok_strato) THEN
466           CALL top_bound( vcov,ucov,teta,masse,dtphys)
467         ENDIF
468       
[524]469c
470c  Diagnostique de conservation de l'énergie : difference
[1146]471         IF (ip_ebil_dyn.ge.1 ) THEN
[524]472          ztit='bil phys'
[1146]473          IF (planet_type.eq."earth") THEN
474           CALL diagedyn(ztit,2,1,1,dtphys
475     &     , ucov    , vcov , ps, p ,pk , teta , q(:,:,1), q(:,:,2))
476          ENDIF
477         ENDIF ! of IF (ip_ebil_dyn.ge.1 )
478
[1060]479       ENDIF ! of IF( apphys )
[524]480
[1146]481      IF(iflag_phys.EQ.2) THEN ! "Newtonian" case
[1454]482!   Academic case : Simple friction and Newtonan relaxation
483!   -------------------------------------------------------
484        DO l=1,llm   
485          DO ij=1,ip1jmp1
486           teta(ij,l)=teta(ij,l)-dtvr*
487     &      (teta(ij,l)-tetarappel(ij,l))*(knewt_g+knewt_t(l)*clat4(ij))
488          ENDDO
489        ENDDO ! of DO l=1,llm
490       
[1505]491        if (planet_type.eq."giant") then
492          ! add an intrinsic heat flux at the base of the atmosphere
493          teta(:,1)=teta(:,1)+dtvr*aire(:)*ihf/cpp/masse(:,1)
494        endif
495
496        call friction(ucov,vcov,dtvr)
497       
[1454]498        ! Sponge layer (if any)
499        IF (ok_strato) THEN
[1795]500!          dufi(:,:)=0.
501!          dvfi(:,:)=0.
502!          dtetafi(:,:)=0.
503!          dqfi(:,:,:)=0.
504!          dpfi(:)=0.
505!          CALL top_bound(vcov,ucov,teta,masse,dufi,dvfi,dtetafi)
506           CALL top_bound( vcov,ucov,teta,masse,dtvr)
507!          CALL addfi( dtvr, leapf, forward   ,
508!     $                  ucov, vcov, teta , q   ,ps ,
509!     $                 dufi, dvfi, dtetafi , dqfi ,dpfi  )
[1454]510        ENDIF ! of IF (ok_strato)
511      ENDIF ! of IF (iflag_phys.EQ.2)
[524]512
513
514c-jld
515
516        CALL pression ( ip1jmp1, ap, bp, ps, p                  )
[1665]517        if (pressure_exner) then
[2056]518          CALL exner_hyb( ip1jmp1, ps, p, pks, pk, pkf )
[1665]519        else
[2056]520          CALL exner_milieu( ip1jmp1, ps, p, pks, pk, pkf )
[1520]521        endif
[1999]522        CALL massdair(p,masse)
[524]523
524
525c-----------------------------------------------------------------------
526c   dissipation horizontale et verticale  des petites echelles:
527c   ----------------------------------------------------------
528
529      IF(apdiss) THEN
530
531
532c   calcul de l'energie cinetique avant dissipation
533        call covcont(llm,ucov,vcov,ucont,vcont)
534        call enercin(vcov,ucov,vcont,ucont,ecin0)
535
536c   dissipation
537        CALL dissip(vcov,ucov,teta,p,dvdis,dudis,dtetadis)
538        ucov=ucov+dudis
539        vcov=vcov+dvdis
540c       teta=teta+dtetadis
541
542
543c------------------------------------------------------------------------
544        if (dissip_conservative) then
545C       On rajoute la tendance due a la transform. Ec -> E therm. cree
546C       lors de la dissipation
547            call covcont(llm,ucov,vcov,ucont,vcont)
548            call enercin(vcov,ucov,vcont,ucont,ecin)
549            dtetaecdt= (ecin0-ecin)/ pk
550c           teta=teta+dtetaecdt
551            dtetadis=dtetadis+dtetaecdt
552        endif
553        teta=teta+dtetadis
554c------------------------------------------------------------------------
555
556
557c    .......        P. Le Van (  ajout  le 17/04/96  )   ...........
558c   ...      Calcul de la valeur moyenne, unique de h aux poles  .....
559c
560
561        DO l  =  1, llm
562          DO ij =  1,iim
563           tppn(ij)  = aire(  ij    ) * teta(  ij    ,l)
564           tpps(ij)  = aire(ij+ip1jm) * teta(ij+ip1jm,l)
565          ENDDO
566           tpn  = SSUM(iim,tppn,1)/apoln
567           tps  = SSUM(iim,tpps,1)/apols
568
569          DO ij = 1, iip1
570           teta(  ij    ,l) = tpn
571           teta(ij+ip1jm,l) = tps
572          ENDDO
573        ENDDO
574
[1665]575        if (1 == 0) then
576!!! Ehouarn: lines here 1) kill 1+1=2 in the dynamics
577!!!                     2) should probably not be here anyway
578!!! but are kept for those who would want to revert to previous behaviour
579           DO ij =  1,iim
580             tppn(ij)  = aire(  ij    ) * ps (  ij    )
581             tpps(ij)  = aire(ij+ip1jm) * ps (ij+ip1jm)
582           ENDDO
583             tpn  = SSUM(iim,tppn,1)/apoln
584             tps  = SSUM(iim,tpps,1)/apols
[524]585
[1665]586           DO ij = 1, iip1
587             ps(  ij    ) = tpn
588             ps(ij+ip1jm) = tps
589           ENDDO
590        endif ! of if (1 == 0)
[524]591
[1146]592      END IF ! of IF(apdiss)
[524]593
594c ajout debug
595c              IF( lafin ) then 
596c                abort_message = 'Simulation finished'
597c                call abort_gcm(modname,abort_message,0)
598c              ENDIF
599       
600c   ********************************************************************
601c   ********************************************************************
602c   .... fin de l'integration dynamique  et physique pour le pas itau ..
603c   ********************************************************************
604c   ********************************************************************
605
606c   preparation du pas d'integration suivant  ......
607
608      IF ( .NOT.purmats ) THEN
609c       ........................................................
610c       ..............  schema matsuno + leapfrog  ..............
611c       ........................................................
612
613            IF(forward. OR. leapf) THEN
614              itau= itau + 1
[1403]615c              iday= day_ini+itau/day_step
616c              time= REAL(itau-(iday-day_ini)*day_step)/day_step+time_0
617c                IF(time.GT.1.) THEN
618c                  time = time-1.
619c                  iday = iday+1
620c                ENDIF
[524]621            ENDIF
622
623
624            IF( itau. EQ. itaufinp1 ) then 
[999]625              if (flag_verif) then
[1279]626                write(79,*) 'ucov',ucov
627                write(80,*) 'vcov',vcov
628                write(81,*) 'teta',teta
629                write(82,*) 'ps',ps
630                write(83,*) 'q',q
[999]631                WRITE(85,*) 'q1 = ',q(:,:,1)
632                WRITE(86,*) 'q3 = ',q(:,:,3)
633              endif
[524]634
635              abort_message = 'Simulation finished'
636
637              call abort_gcm(modname,abort_message,0)
638            ENDIF
639c-----------------------------------------------------------------------
640c   ecriture du fichier histoire moyenne:
641c   -------------------------------------
642
643            IF(MOD(itau,iperiod).EQ.0 .OR. itau.EQ.itaufin) THEN
644               IF(itau.EQ.itaufin) THEN
645                  iav=1
646               ELSE
647                  iav=0
648               ENDIF
[1146]649               
650               IF (ok_dynzon) THEN
[524]651#ifdef CPP_IOIPSL
[1403]652                 CALL bilan_dyn(2,dtvr*iperiod,dtvr*day_step*periodav,
653     &                 ps,masse,pk,pbaru,pbarv,teta,phi,ucov,vcov,q)
[524]654#endif
[1146]655               END IF
[1403]656               IF (ok_dyn_ave) THEN
657#ifdef CPP_IOIPSL
658                 CALL writedynav(itau,vcov,
659     &                 ucov,teta,pk,phi,q,masse,ps,phis)
660#endif
661               ENDIF
[524]662
[1403]663            ENDIF ! of IF((MOD(itau,iperiod).EQ.0).OR.(itau.EQ.itaufin))
[524]664
665c-----------------------------------------------------------------------
666c   ecriture de la bande histoire:
667c   ------------------------------
668
[1403]669            IF( MOD(itau,iecri).EQ.0) THEN
670             ! Ehouarn: output only during LF or Backward Matsuno
671             if (leapf.or.(.not.leapf.and.(.not.forward))) then
[1146]672              CALL geopot(ip1jmp1,teta,pk,pks,phis,phi)
673              unat=0.
674              do l=1,llm
675                unat(iip2:ip1jm,l)=ucov(iip2:ip1jm,l)/cu(iip2:ip1jm)
676                vnat(:,l)=vcov(:,l)/cv(:)
677              enddo
[524]678#ifdef CPP_IOIPSL
[1403]679              if (ok_dyn_ins) then
680!               write(lunout,*) "leapfrog: call writehist, itau=",itau
681               CALL writehist(itau,vcov,ucov,teta,phi,q,masse,ps,phis)
682!               call WriteField('ucov',reshape(ucov,(/iip1,jmp1,llm/)))
683!               call WriteField('vcov',reshape(vcov,(/iip1,jjm,llm/)))
684!              call WriteField('teta',reshape(teta,(/iip1,jmp1,llm/)))
685!               call WriteField('ps',reshape(ps,(/iip1,jmp1/)))
686!               call WriteField('masse',reshape(masse,(/iip1,jmp1,llm/)))
687              endif ! of if (ok_dyn_ins)
[1146]688#endif
689! For some Grads outputs of fields
[1403]690              if (output_grads_dyn) then
[524]691#include "write_grads_dyn.h"
[1403]692              endif
693             endif ! of if (leapf.or.(.not.leapf.and.(.not.forward)))
[1146]694            ENDIF ! of IF(MOD(itau,iecri).EQ.0)
[524]695
696            IF(itau.EQ.itaufin) THEN
697
698
[1454]699!              if (planet_type.eq."earth") then
[1146]700! Write an Earth-format restart file
[1665]701                CALL dynredem1("restart.nc",start_time,
[1146]702     &                         vcov,ucov,teta,q,masse,ps)
[1454]703!              endif ! of if (planet_type.eq."earth")
[524]704
705              CLOSE(99)
[1665]706              !!! Ehouarn: Why not stop here and now?
[1146]707            ENDIF ! of IF (itau.EQ.itaufin)
[524]708
709c-----------------------------------------------------------------------
710c   gestion de l'integration temporelle:
711c   ------------------------------------
712
713            IF( MOD(itau,iperiod).EQ.0 )    THEN
714                    GO TO 1
715            ELSE IF ( MOD(itau-1,iperiod). EQ. 0 ) THEN
716
717                   IF( forward )  THEN
718c      fin du pas forward et debut du pas backward
719
720                      forward = .FALSE.
721                        leapf = .FALSE.
722                           GO TO 2
723
724                   ELSE
725c      fin du pas backward et debut du premier pas leapfrog
726
727                        leapf =  .TRUE.
728                        dt  =  2.*dtvr
[1146]729                        GO TO 2
730                   END IF ! of IF (forward)
[524]731            ELSE
732
733c      ......   pas leapfrog  .....
734
735                 leapf = .TRUE.
736                 dt  = 2.*dtvr
737                 GO TO 2
[1146]738            END IF ! of IF (MOD(itau,iperiod).EQ.0)
739                   !    ELSEIF (MOD(itau-1,iperiod).EQ.0)
[524]740
[1146]741      ELSE ! of IF (.not.purmats)
[524]742
743c       ........................................................
744c       ..............       schema  matsuno        ...............
745c       ........................................................
746            IF( forward )  THEN
747
748             itau =  itau + 1
[1403]749c             iday = day_ini+itau/day_step
750c             time = REAL(itau-(iday-day_ini)*day_step)/day_step+time_0
751c
752c                  IF(time.GT.1.) THEN
753c                   time = time-1.
754c                   iday = iday+1
755c                  ENDIF
[524]756
757               forward =  .FALSE.
758               IF( itau. EQ. itaufinp1 ) then 
759                 abort_message = 'Simulation finished'
760                 call abort_gcm(modname,abort_message,0)
761               ENDIF
762               GO TO 2
763
[1403]764            ELSE ! of IF(forward) i.e. backward step
[524]765
[1146]766              IF(MOD(itau,iperiod).EQ.0 .OR. itau.EQ.itaufin) THEN
[524]767               IF(itau.EQ.itaufin) THEN
768                  iav=1
769               ELSE
770                  iav=0
771               ENDIF
[1146]772
773               IF (ok_dynzon) THEN
[524]774#ifdef CPP_IOIPSL
[1403]775                 CALL bilan_dyn(2,dtvr*iperiod,dtvr*day_step*periodav,
776     &                 ps,masse,pk,pbaru,pbarv,teta,phi,ucov,vcov,q)
[524]777#endif
[1403]778               ENDIF
779               IF (ok_dyn_ave) THEN
780#ifdef CPP_IOIPSL
781                 CALL writedynav(itau,vcov,
782     &                 ucov,teta,pk,phi,q,masse,ps,phis)
783#endif
784               ENDIF
[524]785
[1146]786              ENDIF ! of IF(MOD(itau,iperiod).EQ.0 .OR. itau.EQ.itaufin)
[524]787
[1146]788              IF(MOD(itau,iecri         ).EQ.0) THEN
[524]789c              IF(MOD(itau,iecri*day_step).EQ.0) THEN
[1146]790                CALL geopot(ip1jmp1,teta,pk,pks,phis,phi)
791                unat=0.
792                do l=1,llm
793                  unat(iip2:ip1jm,l)=ucov(iip2:ip1jm,l)/cu(iip2:ip1jm)
794                  vnat(:,l)=vcov(:,l)/cv(:)
795                enddo
[524]796#ifdef CPP_IOIPSL
[1403]797              if (ok_dyn_ins) then
798!                write(lunout,*) "leapfrog: call writehist (b)",
799!     &                        itau,iecri
800                CALL writehist(itau,vcov,ucov,teta,phi,q,masse,ps,phis)
801              endif ! of if (ok_dyn_ins)
[1146]802#endif
803! For some Grads outputs
804                if (output_grads_dyn) then
[524]805#include "write_grads_dyn.h"
[1146]806                endif
[524]807
[1146]808              ENDIF ! of IF(MOD(itau,iecri         ).EQ.0)
[524]809
[1146]810              IF(itau.EQ.itaufin) THEN
[1454]811!                if (planet_type.eq."earth") then
[1665]812                  CALL dynredem1("restart.nc",start_time,
[1146]813     &                           vcov,ucov,teta,q,masse,ps)
[1454]814!                endif ! of if (planet_type.eq."earth")
[1146]815              ENDIF ! of IF(itau.EQ.itaufin)
[524]816
[1146]817              forward = .TRUE.
818              GO TO  1
[524]819
[1146]820            ENDIF ! of IF (forward)
[524]821
[1146]822      END IF ! of IF(.not.purmats)
[524]823
824      STOP
825      END
Note: See TracBrowser for help on using the repository browser.