source: trunk/libf/dyn3d/leapfrog.F @ 125

Last change on this file since 125 was 119, checked in by slebonnois, 14 years ago

Sebastien Lebonnois: apres validation des versions Venus et Titan,
correction d'un certain nombre de bugs.

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