source: LMDZ4/branches/LMDZ4V5.0-dev/libf/dyn3d/gcm.F @ 1397

Last change on this file since 1397 was 1397, checked in by Ehouarn Millour, 14 years ago

Enable starting a SW run from a start.nc file.

Also fix (for picky compilers) the fact that the last argument of init_phys_lmdz must be an array (of a single element in seq mode).

EM

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.3 KB
Line 
1!
2! $Id: gcm.F 1397 2010-06-02 12:57:39Z emillour $
3!
4c
5c
6      PROGRAM gcm
7
8#ifdef CPP_IOIPSL
9      USE IOIPSL
10#else
11! if not using IOIPSL, we still need to use (a local version of) getin
12      USE ioipsl_getincom
13#endif
14
15      USE filtreg_mod
16      USE infotrac
17      USE control_mod
18
19!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
20! FH 2008/05/09 On elimine toutes les clefs physiques dans la dynamique
21! A nettoyer. On ne veut qu'une ou deux routines d'interface
22! dynamique -> physique pour l'initialisation
23! Ehouarn: for now these only apply to Earth:
24#ifdef CPP_EARTH
25      USE dimphy
26      USE comgeomphy
27      USE mod_phys_lmdz_para, ONLY : klon_mpi_para_nb
28#endif
29!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
30
31      IMPLICIT NONE
32
33c      ......   Version  du 10/01/98    ..........
34
35c             avec  coordonnees  verticales hybrides
36c   avec nouveaux operat. dissipation * ( gradiv2,divgrad2,nxgraro2 )
37
38c=======================================================================
39c
40c   Auteur:  P. Le Van /L. Fairhead/F.Hourdin
41c   -------
42c
43c   Objet:
44c   ------
45c
46c   GCM LMD nouvelle grille
47c
48c=======================================================================
49c
50c  ... Dans inigeom , nouveaux calculs pour les elongations  cu , cv
51c      et possibilite d'appeler une fonction f(y)  a derivee tangente
52c      hyperbolique a la  place de la fonction a derivee sinusoidale.
53c  ... Possibilite de choisir le schema pour l'advection de
54c        q  , en modifiant iadv dans traceur.def  (MAF,10/02) .
55c
56c      Pour Van-Leer + Vapeur d'eau saturee, iadv(1)=4. (F.Codron,10/99)
57c      Pour Van-Leer iadv=10
58c
59c-----------------------------------------------------------------------
60c   Declarations:
61c   -------------
62
63#include "dimensions.h"
64#include "paramet.h"
65#include "comconst.h"
66#include "comdissnew.h"
67#include "comvert.h"
68#include "comgeom.h"
69#include "logic.h"
70#include "temps.h"
71!!!!!!!!!!!#include "control.h"
72#include "ener.h"
73#include "description.h"
74#include "serre.h"
75!#include "com_io_dyn.h"
76#include "iniprint.h"
77#include "tracstoke.h"
78#ifdef INCA
79! Only INCA needs these informations (from the Earth's physics)
80#include "indicesol.h"
81#endif
82      INTEGER         longcles
83      PARAMETER     ( longcles = 20 )
84      REAL  clesphy0( longcles )
85      SAVE  clesphy0
86
87
88
89      REAL zdtvr
90      INTEGER nbetatmoy, nbetatdem,nbetat
91
92c   variables dynamiques
93      REAL vcov(ip1jm,llm),ucov(ip1jmp1,llm) ! vents covariants
94      REAL teta(ip1jmp1,llm)                 ! temperature potentielle
95      REAL, ALLOCATABLE, DIMENSION(:,:,:):: q! champs advectes
96      REAL ps(ip1jmp1)                       ! pression  au sol
97      REAL p (ip1jmp1,llmp1  )               ! pression aux interfac.des couches
98      REAL pks(ip1jmp1)                      ! exner au  sol
99      REAL pk(ip1jmp1,llm)                   ! exner au milieu des couches
100      REAL pkf(ip1jmp1,llm)                  ! exner filt.au milieu des couches
101      REAL masse(ip1jmp1,llm)                ! masse d'air
102      REAL phis(ip1jmp1)                     ! geopotentiel au sol
103      REAL phi(ip1jmp1,llm)                  ! geopotentiel
104      REAL w(ip1jmp1,llm)                    ! vitesse verticale
105
106c variables dynamiques intermediaire pour le transport
107
108c   variables pour le fichier histoire
109      REAL dtav      ! intervalle de temps elementaire
110
111      REAL time_0
112
113      LOGICAL lafin
114      INTEGER ij,iq,l,i,j
115
116
117      real time_step, t_wrt, t_ops
118
119      LOGICAL first
120
121      LOGICAL call_iniphys
122      data call_iniphys/.true./
123
124      REAL alpha(ip1jmp1,llm),beta(ip1jmp1,llm)
125c+jld variables test conservation energie
126c      REAL ecin(ip1jmp1,llm),ecin0(ip1jmp1,llm)
127C     Tendance de la temp. potentiel d (theta)/ d t due a la
128C     tansformation d'energie cinetique en energie thermique
129C     cree par la dissipation
130      REAL dhecdt(ip1jmp1,llm)
131c      REAL vcont(ip1jm,llm),ucont(ip1jmp1,llm)
132c      REAL      d_h_vcol, d_qt, d_qw, d_ql, d_ec
133      CHARACTER (len=15) :: ztit
134c-jld
135
136
137      character (len=80) :: dynhist_file, dynhistave_file
138      character (len=20) :: modname
139      character (len=80) :: abort_message
140! locales pour gestion du temps
141      INTEGER :: an, mois, jour
142      REAL :: heure
143
144
145c-----------------------------------------------------------------------
146c    variables pour l'initialisation de la physique :
147c    ------------------------------------------------
148      INTEGER ngridmx
149      PARAMETER( ngridmx = 2+(jjm-1)*iim - 1/jjm   )
150      REAL zcufi(ngridmx),zcvfi(ngridmx)
151      REAL latfi(ngridmx),lonfi(ngridmx)
152      REAL airefi(ngridmx)
153      SAVE latfi, lonfi, airefi
154
155c-----------------------------------------------------------------------
156c   Initialisations:
157c   ----------------
158
159      abort_message = 'last timestep reached'
160      modname = 'gcm'
161      descript = 'Run GCM LMDZ'
162      lafin    = .FALSE.
163      dynhist_file = 'dyn_hist.nc'
164      dynhistave_file = 'dyn_hist_ave.nc'
165
166
167
168c----------------------------------------------------------------------
169c  lecture des fichiers gcm.def ou run.def
170c  ---------------------------------------
171c
172! Ehouarn: dump possibility of using defrun
173!#ifdef CPP_IOIPSL
174      CALL conf_gcm( 99, .TRUE. , clesphy0 )
175!#else
176!      CALL defrun( 99, .TRUE. , clesphy0 )
177!#endif
178
179!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
180! FH 2008/05/02
181! A nettoyer. On ne veut qu'une ou deux routines d'interface
182! dynamique -> physique pour l'initialisation
183! Ehouarn : temporarily (?) keep this only for Earth
184      if (planet_type.eq."earth") then
185#ifdef CPP_EARTH
186      CALL Init_Phys_lmdz(iim,jjp1,llm,1,(/(jjm-1)*iim+2/))
187      call InitComgeomphy
188#endif
189      endif
190!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
191c-----------------------------------------------------------------------
192c   Choix du calendrier
193c   -------------------
194
195c      calend = 'earth_365d'
196
197#ifdef CPP_IOIPSL
198      if (calend == 'earth_360d') then
199        call ioconf_calendar('360d')
200        write(lunout,*)'CALENDRIER CHOISI: Terrestre a 360 jours/an'
201      else if (calend == 'earth_365d') then
202        call ioconf_calendar('noleap')
203        write(lunout,*)'CALENDRIER CHOISI: Terrestre a 365 jours/an'
204      else if (calend == 'earth_366d') then
205        call ioconf_calendar('gregorian')
206        write(lunout,*)'CALENDRIER CHOISI: Terrestre bissextile'
207      else
208        abort_message = 'Mauvais choix de calendrier'
209        call abort_gcm(modname,abort_message,1)
210      endif
211#endif
212c-----------------------------------------------------------------------
213
214      IF (config_inca /= 'none') THEN
215#ifdef INCA
216      call init_const_lmdz(nbtr,anneeref,dayref,iphysiq,day_step,nday,
217     $        nbsrf, is_oce,is_sic,is_ter,is_lic)
218      call init_inca_para(iim,jjm+1,klon,1,klon_mpi_para_nb,0)
219#endif
220      END IF
221c
222c
223c------------------------------------
224c   Initialisation partie parallele
225c------------------------------------
226
227c
228c
229c-----------------------------------------------------------------------
230c   Initialisation des traceurs
231c   ---------------------------
232c  Choix du nombre de traceurs et du schema pour l'advection
233c  dans fichier traceur.def, par default ou via INCA
234      call infotrac_init
235
236c Allocation de la tableau q : champs advectes   
237      allocate(q(ip1jmp1,llm,nqtot))
238
239c-----------------------------------------------------------------------
240c   Lecture de l'etat initial :
241c   ---------------------------
242
243c  lecture du fichier start.nc
244      if (read_start) then
245      ! we still need to run iniacademic to initialize some
246      ! constants & fields, if we run the 'newtonian' or 'SW' cases:
247        if (iflag_phys.ne.1) then
248          CALL iniacademic(vcov,ucov,teta,q,masse,ps,phis,time_0)
249        endif
250
251        if (planet_type.eq."earth") then
252#ifdef CPP_EARTH
253! Load an Earth-format start file
254         CALL dynetat0("start.nc",vcov,ucov,
255     &              teta,q,masse,ps,phis, time_0)
256#else
257        ! SW model also has Earth-format start files
258        ! (but can be used without the CPP_EARTH directive)
259          if (iflag_phys.eq.0) then
260            CALL dynetat0("start.nc",vcov,ucov,
261     &              teta,q,masse,ps,phis, time_0)
262          endif
263#endif
264        endif ! of if (planet_type.eq."earth")
265       
266c       write(73,*) 'ucov',ucov
267c       write(74,*) 'vcov',vcov
268c       write(75,*) 'teta',teta
269c       write(76,*) 'ps',ps
270c       write(77,*) 'q',q
271
272      endif ! of if (read_start)
273
274      IF (config_inca /= 'none') THEN
275#ifdef INCA
276         call init_inca_dim(klon,llm,iim,jjm,
277     $        rlonu,rlatu,rlonv,rlatv)
278#endif
279      END IF
280
281
282c le cas echeant, creation d un etat initial
283      IF (prt_level > 9) WRITE(lunout,*)
284     .              'GCM: AVANT iniacademic AVANT AVANT AVANT AVANT'
285      if (.not.read_start) then
286         CALL iniacademic(vcov,ucov,teta,q,masse,ps,phis,time_0)
287      endif
288
289
290c-----------------------------------------------------------------------
291c   Lecture des parametres de controle pour la simulation :
292c   -------------------------------------------------------
293c  on recalcule eventuellement le pas de temps
294
295      IF(MOD(day_step,iperiod).NE.0) THEN
296        abort_message =
297     .  'Il faut choisir un nb de pas par jour multiple de iperiod'
298        call abort_gcm(modname,abort_message,1)
299      ENDIF
300
301      IF(MOD(day_step,iphysiq).NE.0) THEN
302        abort_message =
303     * 'Il faut choisir un nb de pas par jour multiple de iphysiq'
304        call abort_gcm(modname,abort_message,1)
305      ENDIF
306
307      zdtvr    = daysec/REAL(day_step)
308        IF(dtvr.NE.zdtvr) THEN
309         WRITE(lunout,*)
310     .    'WARNING!!! changement de pas de temps',dtvr,'>',zdtvr
311        ENDIF
312
313C
314C on remet le calendrier à zero si demande
315c
316      IF (raz_date == 1) THEN
317        annee_ref = anneeref
318        day_ref = dayref
319        day_ini = dayref
320        itau_dyn = 0
321        itau_phy = 0
322        time_0 = 0.
323        write(lunout,*)
324     .   'GCM: On reinitialise a la date lue dans gcm.def'
325      ELSE IF (annee_ref .ne. anneeref .or. day_ref .ne. dayref) THEN
326        write(lunout,*)
327     .  'GCM: Attention les dates initiales lues dans le fichier'
328        write(lunout,*)
329     .  ' restart ne correspondent pas a celles lues dans '
330        write(lunout,*)' gcm.def'
331        write(lunout,*)' annee_ref=',annee_ref," anneeref=",anneeref
332        write(lunout,*)' day_ref=',day_ref," dayref=",dayref
333        write(lunout,*)' Pas de remise a zero'
334      ENDIF
335
336c      if (annee_ref .ne. anneeref .or. day_ref .ne. dayref) then
337c        write(lunout,*)
338c     .  'GCM: Attention les dates initiales lues dans le fichier'
339c        write(lunout,*)
340c     .  ' restart ne correspondent pas a celles lues dans '
341c        write(lunout,*)' gcm.def'
342c        write(lunout,*)' annee_ref=',annee_ref," anneeref=",anneeref
343c        write(lunout,*)' day_ref=',day_ref," dayref=",dayref
344c        if (raz_date .ne. 1) then
345c          write(lunout,*)
346c     .    'GCM: On garde les dates du fichier restart'
347c        else
348c          annee_ref = anneeref
349c          day_ref = dayref
350c          day_ini = dayref
351c          itau_dyn = 0
352c          itau_phy = 0
353c          time_0 = 0.
354c          write(lunout,*)
355c     .   'GCM: On reinitialise a la date lue dans gcm.def'
356c        endif
357c      ELSE
358c        raz_date = 0
359c      endif
360
361#ifdef CPP_IOIPSL
362      mois = 1
363      heure = 0.
364      call ymds2ju(annee_ref, mois, day_ref, heure, jD_ref)
365      jH_ref = jD_ref - int(jD_ref)
366      jD_ref = int(jD_ref)
367
368      call ioconf_startdate(INT(jD_ref), jH_ref)
369
370      write(lunout,*)'DEBUG'
371      write(lunout,*)'annee_ref, mois, day_ref, heure, jD_ref'
372      write(lunout,*)annee_ref, mois, day_ref, heure, jD_ref
373      call ju2ymds(jD_ref+jH_ref,an, mois, jour, heure)
374      write(lunout,*)'jD_ref+jH_ref,an, mois, jour, heure'
375      write(lunout,*)jD_ref+jH_ref,an, mois, jour, heure
376#else
377! Ehouarn: we still need to define JD_ref and JH_ref
378! and since we don't know how many days there are in a year
379! we set JD_ref to 0 (this should be improved ...)
380      jD_ref=0
381      jH_ref=0
382#endif
383
384c  nombre d'etats dans les fichiers demarrage et histoire
385      nbetatdem = nday / iecri
386      nbetatmoy = nday / periodav + 1
387
388      if (iflag_phys.eq.1) then
389      ! these initialisations have already been done (via iniacademic)
390      ! if running in SW or Newtonian mode
391c-----------------------------------------------------------------------
392c   Initialisation des constantes dynamiques :
393c   ------------------------------------------
394        dtvr = zdtvr
395        CALL iniconst
396
397c-----------------------------------------------------------------------
398c   Initialisation de la geometrie :
399c   --------------------------------
400        CALL inigeom
401
402c-----------------------------------------------------------------------
403c   Initialisation du filtre :
404c   --------------------------
405        CALL inifilr
406      endif ! of if (iflag_phys.eq.1)
407c
408c-----------------------------------------------------------------------
409c   Initialisation de la dissipation :
410c   ----------------------------------
411
412      CALL inidissip( lstardis, nitergdiv, nitergrot, niterh   ,
413     *                tetagdiv, tetagrot , tetatemp              )
414
415c-----------------------------------------------------------------------
416c   Initialisation de la physique :
417c   -------------------------------
418
419      IF (call_iniphys.and.(iflag_phys.eq.1)) THEN
420         latfi(1)=rlatu(1)
421         lonfi(1)=0.
422         zcufi(1) = cu(1)
423         zcvfi(1) = cv(1)
424         DO j=2,jjm
425            DO i=1,iim
426               latfi((j-2)*iim+1+i)= rlatu(j)
427               lonfi((j-2)*iim+1+i)= rlonv(i)
428               zcufi((j-2)*iim+1+i) = cu((j-1)*iip1+i)
429               zcvfi((j-2)*iim+1+i) = cv((j-1)*iip1+i)
430            ENDDO
431         ENDDO
432         latfi(ngridmx)= rlatu(jjp1)
433         lonfi(ngridmx)= 0.
434         zcufi(ngridmx) = cu(ip1jm+1)
435         zcvfi(ngridmx) = cv(ip1jm-iim)
436         CALL gr_dyn_fi(1,iip1,jjp1,ngridmx,aire,airefi)
437         WRITE(lunout,*)
438     .       'GCM: WARNING!!! vitesse verticale nulle dans la physique'
439! Earth:
440         if (planet_type.eq."earth") then
441#ifdef CPP_EARTH
442         CALL iniphysiq(ngridmx,llm,daysec,day_ini,dtphys/nsplit_phys ,
443     ,                latfi,lonfi,airefi,zcufi,zcvfi,rad,g,r,cpp     )
444#endif
445         endif ! of if (planet_type.eq."earth")
446         call_iniphys=.false.
447      ENDIF ! of IF (call_iniphys.and.(iflag_phys.eq.1))
448!#endif
449
450c  numero de stockage pour les fichiers de redemarrage:
451
452c-----------------------------------------------------------------------
453c   Initialisation des I/O :
454c   ------------------------
455
456
457      day_end = day_ini + nday
458      WRITE(lunout,300)day_ini,day_end
459 300  FORMAT('1'/,15x,'run du jour',i7,2x,'au jour',i7//)
460
461#ifdef CPP_IOIPSL
462      call ju2ymds(jD_ref + day_ini - day_ref, an, mois, jour, heure)
463      write (lunout,301)jour, mois, an
464      call ju2ymds(jD_ref + day_end - day_ref, an, mois, jour, heure)
465      write (lunout,302)jour, mois, an
466 301  FORMAT('1'/,15x,'run du ', i2,'/',i2,'/',i4)
467 302  FORMAT('1'/,15x,'    au ', i2,'/',i2,'/',i4)
468#endif
469
470      if (planet_type.eq."earth") then
471        CALL dynredem0("restart.nc", day_end, phis)
472      endif
473
474      ecripar = .TRUE.
475
476#ifdef CPP_IOIPSL
477      time_step = zdtvr
478      if (ok_dyn_ins) then
479        ! initialize output file for instantaneous outputs
480        ! t_ops = iecri * daysec ! do operations every t_ops
481        t_ops =((1.0*iecri)/day_step) * daysec 
482        t_wrt = daysec ! iecri * daysec ! write output every t_wrt
483        CALL inithist(day_ref,annee_ref,time_step,
484     &              t_ops,t_wrt)
485      endif
486
487      IF (ok_dyn_ave) THEN
488        ! initialize output file for averaged outputs
489        t_ops = iperiod * time_step ! do operations every t_ops
490        t_wrt = periodav * daysec   ! write output every t_wrt
491        CALL initdynav(day_ref,annee_ref,time_step,
492     &       t_ops,t_wrt)
493      END IF
494      dtav = iperiod*dtvr/daysec
495#endif
496! #endif of #ifdef CPP_IOIPSL
497
498c  Choix des frequences de stokage pour le offline
499c      istdyn=day_step/4     ! stockage toutes les 6h=1jour/4
500c      istdyn=day_step/12     ! stockage toutes les 2h=1jour/12
501      istdyn=day_step/4     ! stockage toutes les 6h=1jour/12
502      istphy=istdyn/iphysiq     
503
504
505c
506c-----------------------------------------------------------------------
507c   Integration temporelle du modele :
508c   ----------------------------------
509
510c       write(78,*) 'ucov',ucov
511c       write(78,*) 'vcov',vcov
512c       write(78,*) 'teta',teta
513c       write(78,*) 'ps',ps
514c       write(78,*) 'q',q
515
516
517      CALL leapfrog(ucov,vcov,teta,ps,masse,phis,q,clesphy0,
518     .              time_0)
519
520      END
521
Note: See TracBrowser for help on using the repository browser.