source: LMDZ6/branches/Amaury_dev/libf/dyn3d/gcm.F90 @ 5106

Last change on this file since 5106 was 5106, checked in by abarral, 8 weeks ago

Turn coefils.h into lmdz_coefils.f90
Put filtreg.F90 inside lmdz_filtreg.F90
Turn mod_filtreg_p.F90 into lmdz_filtreg_p.F90
Delete obsolete parafilt.h*
(lint) remove spaces between routine name and args

  • Property copyright set to
    Name of program: LMDZ
    Creation date: 1984
    Version: LMDZ5
    License: CeCILL version 2
    Holder: Laboratoire de m\'et\'eorologie dynamique, CNRS, UMR 8539
    See the license file in the root directory
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.2 KB
Line 
1
2! $Id: gcm.F90 5106 2024-07-23 20:21:18Z abarral $
3
4
5
6PROGRAM gcm
7
8  USE IOIPSL
9  USE wxios  ! ug Pour les sorties XIOS
10
11  USE lmdz_filtreg, ONLY: inifilr
12  USE infotrac, ONLY: nqtot, init_infotrac
13  USE control_mod
14  USE mod_const_mpi, ONLY: COMM_LMDZ
15  USE temps_mod, ONLY: calend,start_time,annee_ref,day_ref, &
16                     itau_dyn,itau_phy,day_ini,jD_ref,jH_ref,day_end
17  USE comconst_mod, ONLY: cpp, daysec, dtphys, dtvr, g, r, rad
18  USE logic_mod, ONLY: ecripar, iflag_phys, read_start
19
20  USE lmdz_cppkeys_wrapper, ONLY: CPPKEY_PHYS
21
22!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
23  ! FH 2008/05/09 On elimine toutes les clefs physiques dans la dynamique
24  ! A nettoyer. On ne veut qu'une ou deux routines d'interface
25  ! dynamique -> physique pour l'initialisation
26  ! AB 2024/07/20: remplace CPP key by fortran logical, but ^ still relevant, see later use of iniphys later on
27  USE iniphysiq_mod, ONLY: iniphysiq
28!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
29
30  IMPLICIT NONE
31
32  !      ......   Version  du 10/01/98    ..........
33
34  !             avec  coordonnees  verticales hybrides
35  !   avec nouveaux operat. dissipation * ( gradiv2,divgrad2,nxgraro2 )
36
37  !=======================================================================
38
39  !   Auteur:  P. Le Van /L. Fairhead/F.Hourdin
40  !   -------
41
42  !   Objet:
43  !   ------
44
45  !   GCM LMD nouvelle grille
46
47  !=======================================================================
48
49  !  ... Dans inigeom , nouveaux calculs pour les elongations  cu , cv
50  !      et possibilite d'appeler une fonction f(y)  a derivee tangente
51  !      hyperbolique a la  place de la fonction a derivee sinusoidale.
52  !  ... Possibilite de choisir le schema pour l'advection de
53  !        q  , en modifiant iadv dans traceur.def  (MAF,10/02) .
54
55  !      Pour Van-Leer + Vapeur d'eau saturee, iadv(1)=4. (F.Codron,10/99)
56  !      Pour Van-Leer iadv=10
57
58  !-----------------------------------------------------------------------
59  !   Declarations:
60  !   -------------
61
62  include "dimensions.h"
63  include "paramet.h"
64  include "comdissnew.h"
65  include "comgeom.h"
66  include "description.h"
67  include "iniprint.h"
68  include "tracstoke.h"
69
70  REAL zdtvr
71
72  !   variables dynamiques
73  REAL vcov(ip1jm,llm),ucov(ip1jmp1,llm) ! vents covariants
74  REAL teta(ip1jmp1,llm)                 ! temperature potentielle
75  REAL, ALLOCATABLE, DIMENSION(:,:,:):: q! champs advectes
76  REAL ps(ip1jmp1)                       ! pression  au sol
77!  REAL p (ip1jmp1,llmp1  )               ! pression aux interfac.des couches
78  REAL masse(ip1jmp1,llm)                ! masse d'air
79  REAL phis(ip1jmp1)                     ! geopotentiel au sol
80!  REAL phi(ip1jmp1,llm)                  ! geopotentiel
81!  REAL w(ip1jmp1,llm)                    ! vitesse verticale
82
83  ! variables dynamiques intermediaire pour le transport
84
85  !   variables pour le fichier histoire
86  REAL dtav      ! intervalle de temps elementaire
87
88  REAL time_0
89
90  LOGICAL lafin
91
92
93  real time_step, t_wrt, t_ops
94
95  !      LOGICAL call_iniphys
96  !      data call_iniphys/.TRUE./
97
98  !+jld variables test conservation energie
99  !      REAL ecin(ip1jmp1,llm),ecin0(ip1jmp1,llm)
100  !     Tendance de la temp. potentiel d (theta)/ d t due a la
101  !     tansformation d'energie cinetique en energie thermique
102  !     cree par la dissipation
103!  REAL dhecdt(ip1jmp1,llm)
104  !      REAL vcont(ip1jm,llm),ucont(ip1jmp1,llm)
105  !      REAL      d_h_vcol, d_qt, d_qw, d_ql, d_ec
106!  CHARACTER (len=15) :: ztit
107  !-jld
108
109
110  character (len=80) :: dynhist_file, dynhistave_file
111  character (len=20) :: modname
112  character (len=80) :: abort_message
113  ! locales pour gestion du temps
114  INTEGER :: an, mois, jour
115  REAL :: heure
116  logical use_filtre_fft
117
118  !-----------------------------------------------------------------------
119  !   Initialisations:
120  !   ----------------
121
122  abort_message = 'last timestep reached'
123  modname = 'gcm'
124  descript = 'Run GCM LMDZ'
125  lafin    = .FALSE.
126  dynhist_file = 'dyn_hist.nc'
127  dynhistave_file = 'dyn_hist_ave.nc'
128
129
130
131  !----------------------------------------------------------------------
132  !  lecture des fichiers gcm.def ou run.def
133  !  ---------------------------------------
134
135  CALL conf_gcm( 99, .TRUE.)
136
137  if (mod(iphysiq, iperiod) /= 0) CALL abort_gcm("conf_gcm", &
138       "iphysiq must be a multiple of iperiod", 1)
139
140  use_filtre_fft=.FALSE.
141  CALL getin('use_filtre_fft',use_filtre_fft)
142  IF (use_filtre_fft) CALL abort_gcm("gcm", 'FFT filter is not available in ' &
143          // 'the sequential version of the dynamics.', 1)
144
145!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
146  ! Initialisation de XIOS
147!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
148
149  IF (using_xios) THEN
150    CALL wxios_init("LMDZ")
151  ENDIF
152
153
154!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
155  ! FH 2008/05/02
156  ! A nettoyer. On ne veut qu'une ou deux routines d'interface
157  ! dynamique -> physique pour l'initialisation
158!#ifdef CPP_PHYS
159!  CALL Init_Phys_lmdz(iim,jjp1,llm,1,(/(jjm-1)*iim+2/))
160!  !      CALL InitComgeomphy ! now done in iniphysiq
161!#endif
162!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
163  !-----------------------------------------------------------------------
164  !   Choix du calendrier
165  !   -------------------
166
167  !      calend = 'earth_365d'
168
169  if (calend == 'earth_360d') then
170     CALL ioconf_calendar('360_day')
171     write(lunout,*)'CALENDRIER CHOISI: Terrestre a 360 jours/an'
172  else if (calend == 'earth_365d') then
173     CALL ioconf_calendar('noleap')
174     write(lunout,*)'CALENDRIER CHOISI: Terrestre a 365 jours/an'
175  else if (calend == 'gregorian') then
176     CALL ioconf_calendar('gregorian')
177     write(lunout,*)'CALENDRIER CHOISI: Terrestre bissextile'
178  else
179     abort_message = 'Mauvais choix de calendrier'
180     CALL abort_gcm(modname,abort_message,1)
181  endif
182  !-----------------------------------------------------------------------
183
184
185  !------------------------------------
186  !   Initialisation partie parallele
187  !------------------------------------
188
189
190  !-----------------------------------------------------------------------
191  !   Initialisation des traceurs
192  !   ---------------------------
193  !  Choix du nombre de traceurs et du schema pour l'advection
194  !  dans fichier traceur.def, par default ou via INCA
195  CALL init_infotrac
196
197  ! Allocation de la tableau q : champs advectes   
198  allocate(q(ip1jmp1,llm,nqtot))
199
200  !-----------------------------------------------------------------------
201  !   Lecture de l'etat initial :
202  !   ---------------------------
203
204  !  lecture du fichier start.nc
205  if (read_start) then
206     ! we still need to run iniacademic to initialize some
207     ! constants & fields, if we run the 'newtonian' or 'SW' cases:
208     if (iflag_phys/=1) then
209        CALL iniacademic(vcov,ucov,teta,q,masse,ps,phis,time_0)
210     endif
211
212     !        if (planet_type.eq."earth") then
213     ! Load an Earth-format start file
214     CALL dynetat0("start.nc",vcov,ucov, &
215          teta,q,masse,ps,phis, time_0)
216     !        endif ! of if (planet_type.eq."earth")
217
218     !       write(73,*) 'ucov',ucov
219     !       write(74,*) 'vcov',vcov
220     !       write(75,*) 'teta',teta
221     !       write(76,*) 'ps',ps
222     !       write(77,*) 'q',q
223
224  endif ! of if (read_start)
225
226
227  ! le cas echeant, creation d un etat initial
228  IF (prt_level > 9) WRITE(lunout,*) &
229       'GCM: AVANT iniacademic AVANT AVANT AVANT AVANT'
230  if (.not.read_start) then
231     start_time=0.
232     annee_ref=anneeref
233     CALL iniacademic(vcov,ucov,teta,q,masse,ps,phis,time_0)
234  endif
235
236
237  !-----------------------------------------------------------------------
238  !   Lecture des parametres de controle pour la simulation :
239  !   -------------------------------------------------------
240  !  on recalcule eventuellement le pas de temps
241
242  IF(MOD(day_step,iperiod)/=0) THEN
243     abort_message =  &
244          'Il faut choisir un nb de pas par jour multiple de iperiod'
245     CALL abort_gcm(modname,abort_message,1)
246  ENDIF
247
248  IF(MOD(day_step,iphysiq)/=0) THEN
249     abort_message =  &
250          'Il faut choisir un nb de pas par jour multiple de iphysiq'
251     CALL abort_gcm(modname,abort_message,1)
252  ENDIF
253
254  zdtvr    = daysec/REAL(day_step)
255  IF(dtvr/=zdtvr) THEN
256     WRITE(lunout,*) &
257          'WARNING!!! changement de pas de temps',dtvr,'>',zdtvr
258  ENDIF
259
260  ! on remet le calendrier \`a zero si demande
261
262  IF (start_time /= starttime) then
263     WRITE(lunout,*)' GCM: Attention l''heure de depart lue dans le' &
264          ,' fichier restart ne correspond pas a celle lue dans le run.def'
265     IF (raz_date == 1) then
266        WRITE(lunout,*)'Je prends l''heure lue dans run.def'
267        start_time = starttime
268     ELSE
269        CALL abort_gcm("gcm", "'Je m''arrete'", 1)
270     ENDIF
271  ENDIF
272  IF (raz_date == 1) THEN
273     annee_ref = anneeref
274     day_ref = dayref
275     day_ini = dayref
276     itau_dyn = 0
277     itau_phy = 0
278     time_0 = 0.
279     write(lunout,*) &
280          'GCM: On reinitialise a la date lue dans gcm.def'
281  ELSE IF (annee_ref /= anneeref .or. day_ref /= dayref) THEN
282     write(lunout,*) &
283          'GCM: Attention les dates initiales lues dans le fichier'
284     write(lunout,*) &
285          ' restart ne correspondent pas a celles lues dans '
286     write(lunout,*)' gcm.def'
287     write(lunout,*)' annee_ref=',annee_ref," anneeref=",anneeref
288     write(lunout,*)' day_ref=',day_ref," dayref=",dayref
289     write(lunout,*)' Pas de remise a zero'
290  ENDIF
291
292  !      if (annee_ref .ne. anneeref .or. day_ref .ne. dayref) then
293  !        write(lunout,*)
294  !     .  'GCM: Attention les dates initiales lues dans le fichier'
295  !        write(lunout,*)
296  !     .  ' restart ne correspondent pas a celles lues dans '
297  !        write(lunout,*)' gcm.def'
298  !        write(lunout,*)' annee_ref=',annee_ref," anneeref=",anneeref
299  !        write(lunout,*)' day_ref=',day_ref," dayref=",dayref
300  !        if (raz_date .ne. 1) then
301  !          write(lunout,*)
302  !     .    'GCM: On garde les dates du fichier restart'
303  !        else
304  !          annee_ref = anneeref
305  !          day_ref = dayref
306  !          day_ini = dayref
307  !          itau_dyn = 0
308  !          itau_phy = 0
309  !          time_0 = 0.
310  !          write(lunout,*)
311  !     .   'GCM: On reinitialise a la date lue dans gcm.def'
312  !        endif
313  !      ELSE
314  !        raz_date = 0
315  !      endif
316
317  mois = 1
318  heure = 0.
319  CALL ymds2ju(annee_ref, mois, day_ref, heure, jD_ref)
320  jH_ref = jD_ref - int(jD_ref)
321  jD_ref = int(jD_ref)
322
323  CALL ioconf_startdate(INT(jD_ref), jH_ref)
324
325  write(lunout,*)'DEBUG'
326  write(lunout,*)'annee_ref, mois, day_ref, heure, jD_ref'
327  write(lunout,*)annee_ref, mois, day_ref, heure, jD_ref
328  CALL ju2ymds(jD_ref+jH_ref,an, mois, jour, heure)
329  write(lunout,*)'jD_ref+jH_ref,an, mois, jour, heure'
330  write(lunout,*)jD_ref+jH_ref,an, mois, jour, heure
331
332
333  if (iflag_phys==1) then
334     ! these initialisations have already been done (via iniacademic)
335     ! if running in SW or Newtonian mode
336     !-----------------------------------------------------------------------
337     !   Initialisation des constantes dynamiques :
338     !   ------------------------------------------
339     dtvr = zdtvr
340     CALL iniconst
341
342     !-----------------------------------------------------------------------
343     !   Initialisation de la geometrie :
344     !   --------------------------------
345     CALL inigeom
346
347     !-----------------------------------------------------------------------
348     !   Initialisation du filtre :
349     !   --------------------------
350     CALL inifilr
351  endif ! of if (iflag_phys.eq.1)
352
353  !-----------------------------------------------------------------------
354  !   Initialisation de la dissipation :
355  !   ----------------------------------
356
357  CALL inidissip( lstardis, nitergdiv, nitergrot, niterh   , &
358       tetagdiv, tetagrot , tetatemp, vert_prof_dissip)
359
360  !  numero de stockage pour les fichiers de redemarrage:
361
362  !-----------------------------------------------------------------------
363  !   Initialisation des I/O :
364  !   ------------------------
365
366
367  if (nday>=0) then
368     day_end = day_ini + nday
369  else
370     day_end = day_ini - nday/day_step
371  endif
372  WRITE(lunout,300)day_ini,day_end
373300 FORMAT('1'/,15x,'run du jour',i7,2x,'au jour',i7//)
374
375  CALL ju2ymds(jD_ref + day_ini - day_ref, an, mois, jour, heure)
376  write (lunout,301)jour, mois, an
377  CALL ju2ymds(jD_ref + day_end - day_ref, an, mois, jour, heure)
378  write (lunout,302)jour, mois, an
379301 FORMAT('1'/,15x,'run du ', i2,'/',i2,'/',i4)
380302 FORMAT('1'/,15x,'    au ', i2,'/',i2,'/',i4)
381
382  !-----------------------------------------------------------------------
383  !   Initialisation de la physique :
384  !   -------------------------------
385
386  IF ((iflag_phys==1).or.(iflag_phys>=100)) THEN
387    ! Physics:
388    IF (CPPKEY_PHYS) THEN
389      CALL iniphysiq(iim,jjm,llm, &
390          (jjm-1)*iim+2,comm_lmdz, &
391          daysec,day_ini,dtphys/nsplit_phys, &
392          rlatu,rlatv,rlonu,rlonv,aire,cu,cv,rad,g,r,cpp, &
393          iflag_phys)
394    END IF
395  ENDIF ! of IF ((iflag_phys==1).or.(iflag_phys>=100))
396
397  !      if (planet_type.eq."earth") then
398  ! Write an Earth-format restart file
399
400  CALL dynredem0("restart.nc", day_end, phis)
401  !      endif
402
403  ecripar = .TRUE.
404
405  time_step = zdtvr
406  if (ok_dyn_ins) then
407     ! initialize output file for instantaneous outputs
408     ! t_ops = iecri * daysec ! do operations every t_ops
409     t_ops =((1.0*iecri)/day_step) * daysec 
410     t_wrt = daysec ! iecri * daysec ! write output every t_wrt
411     CALL inithist(day_ref,annee_ref,time_step, &
412          t_ops,t_wrt)
413  endif
414
415  IF (ok_dyn_ave) THEN
416     ! initialize output file for averaged outputs
417     t_ops = iperiod * time_step ! do operations every t_ops
418     t_wrt = periodav * daysec   ! write output every t_wrt
419     CALL initdynav(day_ref,annee_ref,time_step, &
420          t_ops,t_wrt)
421  END IF
422  dtav = iperiod*dtvr/daysec
423
424  !  Choix des frequences de stokage pour le offline
425  !      istdyn=day_step/4     ! stockage toutes les 6h=1jour/4
426  !      istdyn=day_step/12     ! stockage toutes les 2h=1jour/12
427  istdyn=day_step/4     ! stockage toutes les 6h=1jour/12
428  istphy=istdyn/iphysiq     
429
430  !-----------------------------------------------------------------------
431  !   Integration temporelle du modele :
432  !   ----------------------------------
433
434  !       write(78,*) 'ucov',ucov
435  !       write(78,*) 'vcov',vcov
436  !       write(78,*) 'teta',teta
437  !       write(78,*) 'ps',ps
438  !       write(78,*) 'q',q
439
440
441  CALL leapfrog(ucov,vcov,teta,ps,masse,phis,q,time_0)
442
443END PROGRAM gcm
Note: See TracBrowser for help on using the repository browser.