source: trunk/LMDZ.COMMON/libf/dyn3d/leapfrog.F @ 271

Last change on this file since 271 was 270, checked in by emillour, 14 years ago

Ehouarn: Mise a jour des dynamiques (seq et ) pour suivre
les changements et developpements de LMDZ5 terrestre
(mise a niveau avec LMDZ5 trunk, rev 1560). Ce qui ne devrais pas changer grand chose au fonctionnement de base du GCM).
Modification importante: correction du bug sur le cumul des flux de masse pour le transport des traceurs (mais dans les faits semble avoir peu d'impact).
(voir "commit_importants.log" pour les details des ajouts et modifications).

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