source: LMDZ6/branches/Ocean_skin/libf/dyn3d/gcm.F90 @ 3605

Last change on this file since 3605 was 3605, checked in by lguez, 4 years ago

Merge revisions 3427:3600 of trunk into branch Ocean_skin

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