source: codes/icosagcm/branches/SATURN_DYNAMICO/LMDZ.COMMON/libf/dyn3d/leapfrog.F

Last change on this file was 222, checked in by ymipsl, 10 years ago

Creating temporary dynamico/lmdz/saturn branche

YM

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