source: LMDZ6/trunk/libf/phylmd/dyn1d/old_lmdz1d.f90 @ 5271

Last change on this file since 5271 was 5271, checked in by abarral, 2 days ago

Move dimensions.h into a module
Nb: doesn't compile yet

File size: 51.4 KB
Line 
1!
2! $Id: lmdz1d.F90 3540 2019-06-25 14:50:13Z fairhead $
3!
4
5      SUBROUTINE old_lmdz1d
6
7   USE ioipsl, only: ju2ymds, ymds2ju, ioconf_calendar,getin
8   USE phys_state_var_mod, ONLY : phys_state_var_init, phys_state_var_end, &
9       clwcon, detr_therm, &
10       qsol, fevap, z0m, z0h, agesno, &
11       du_gwd_rando, du_gwd_front, entr_therm, f0, fm_therm, &
12       falb_dir, falb_dif, &
13       ftsol, beta_aridity, pbl_tke, pctsrf, radsol, rain_fall, snow_fall, ratqs, &
14       rnebcon, rugoro, sig1, w01, solaire_etat0, sollw, sollwdown, &
15       solsw, solswfdiff, t_ancien, q_ancien, u_ancien, v_ancien, &
16       wake_delta_pbl_TKE, delta_tsurf, wake_fip, wake_pe, &
17       wake_deltaq, wake_deltat, wake_s, awake_s, wake_dens, &
18       awake_dens, cv_gen, wake_cstar, &
19       zgam, zmax0, zmea, zpic, zsig, &
20       zstd, zthe, zval, ale_bl, ale_bl_trig, alp_bl, &
21       ql_ancien, qs_ancien, qbs_ancien, cf_ancien, rvc_ancien, &
22       prlw_ancien, prsw_ancien, prbsw_ancien, prw_ancien, &
23       u10m,v10m,ale_wake,ale_bl_stat
24
25 
26   USE dimphy
27   USE surface_data, only : type_ocean,ok_veget
28   USE pbl_surface_mod, only : ftsoil, pbl_surface_init, &
29                                 pbl_surface_final
30   USE fonte_neige_mod, only : fonte_neige_init, fonte_neige_final
31
32   USE infotrac ! new
33   USE control_mod
34   USE indice_sol_mod
35   USE phyaqua_mod
36!  USE mod_1D_cases_read
37   USE mod_1D_cases_read2
38   USE mod_1D_amma_read
39   USE print_control_mod, ONLY: lunout, prt_level
40   USE iniphysiq_mod, ONLY: iniphysiq
41   USE mod_const_mpi, ONLY: comm_lmdz
42   USE physiq_mod, ONLY: physiq
43   USE comvert_mod, ONLY: presnivs, ap, bp, dpres,nivsig, nivsigs, pa, &
44                          preff, aps, bps, pseudoalt, scaleheight
45   USE temps_mod, ONLY: annee_ref, calend, day_end, day_ini, day_ref, &
46                        itau_dyn, itau_phy, start_time, year_len
47   USE phys_cal_mod, ONLY : year_len_phys_cal_mod => year_len
48   USE lmdz_cppkeys_wrapper, ONLY: CPPKEY_OUTPUTPHYSSCM
49
50      USE dimensions_mod, ONLY: iim, jjm, llm, ndm
51implicit none
52
53      INCLUDE "YOMCST.h"
54!!      INCLUDE "control.h"
55      INCLUDE "clesphys.h"
56      INCLUDE "dimsoil.h"
57!      INCLUDE "indicesol.h"
58
59      INCLUDE "compar1d.h"
60      INCLUDE "flux_arp.h"
61      INCLUDE "date_cas.h"
62      INCLUDE "tsoilnudge.h"
63      INCLUDE "fcg_gcssold.h"
64!!!      INCLUDE "fbforcing.h"
65      INCLUDE "compbl.h"
66
67!=====================================================================
68! DECLARATIONS
69!=====================================================================
70
71!---------------------------------------------------------------------
72!  Externals
73!---------------------------------------------------------------------
74      external fq_sat
75      real fq_sat
76
77!---------------------------------------------------------------------
78!  Arguments d' initialisations de la physique (USER DEFINE)
79!---------------------------------------------------------------------
80
81      integer, parameter :: ngrid=1
82      real :: zcufi    = 1.
83      real :: zcvfi    = 1.
84
85!-      real :: nat_surf
86!-      logical :: ok_flux_surf
87!-      real :: fsens
88!-      real :: flat
89!-      real :: tsurf
90!-      real :: rugos
91!-      real :: qsol(1:2)
92!-      real :: qsurf
93!-      real :: psurf
94!-      real :: zsurf
95!-      real :: albedo
96!-
97!-      real :: time     = 0.
98!-      real :: time_ini
99!-      real :: xlat
100!-      real :: xlon
101!-      real :: wtsurf
102!-      real :: wqsurf
103!-      real :: restart_runoff
104!-      real :: xagesno
105!-      real :: qsolinp
106!-      real :: zpicinp
107!-
108      real :: fnday
109      real :: day, daytime
110      real :: day1
111      real :: heure
112      integer :: jour
113      integer :: mois
114      integer :: an
115 
116!---------------------------------------------------------------------
117!  Declarations related to forcing and initial profiles
118!---------------------------------------------------------------------
119
120        integer :: kmax = llm
121        integer llm700,nq1,nq2
122        INTEGER, PARAMETER :: nlev_max=1000, nqmx=1000
123        real timestep, frac
124        real height(nlev_max),tttprof(nlev_max),qtprof(nlev_max)
125        real  uprof(nlev_max),vprof(nlev_max),e12prof(nlev_max)
126        real  ugprof(nlev_max),vgprof(nlev_max),wfls(nlev_max)
127        real  dqtdxls(nlev_max),dqtdyls(nlev_max)
128        real  dqtdtls(nlev_max),thlpcar(nlev_max)
129        real  qprof(nlev_max,nqmx)
130
131!        integer :: forcing_type
132        logical :: forcing_les     = .false.
133        logical :: forcing_armcu   = .false.
134        logical :: forcing_rico    = .false.
135        logical :: forcing_radconv = .false.
136        logical :: forcing_toga    = .false.
137        logical :: forcing_twpice  = .false.
138        logical :: forcing_amma    = .false.
139        logical :: forcing_dice    = .false.
140        logical :: forcing_gabls4  = .false.
141
142        logical :: forcing_GCM2SCM = .false.
143        logical :: forcing_GCSSold = .false.
144        logical :: forcing_sandu   = .false.
145        logical :: forcing_astex   = .false.
146        logical :: forcing_fire    = .false.
147        logical :: forcing_case    = .false.
148        logical :: forcing_case2   = .false.
149        logical :: forcing_SCM   = .false.
150        integer :: type_ts_forcing ! 0 = SST constant; 1 = SST read from a file
151!                                                            (cf read_tsurf1d.F)
152
153real wwww
154!vertical advection computation
155!       real d_t_z(llm), d_q_z(llm)
156!       real d_t_dyn_z(llm), dq_dyn_z(llm)
157!       real zz(llm)
158!       real zfact
159
160!flag forcings
161        logical :: nudge_wind=.true.
162        logical :: nudge_thermo=.false.
163        logical :: cptadvw=.true.
164!=====================================================================
165! DECLARATIONS FOR EACH CASE
166!=====================================================================
167!
168      INCLUDE "old_1D_decl_cases.h"
169!
170!---------------------------------------------------------------------
171!  Declarations related to nudging
172!---------------------------------------------------------------------
173     integer :: nudge_max
174     parameter (nudge_max=9)
175     integer :: inudge_RHT=1
176     integer :: inudge_UV=2
177     logical :: nudge(nudge_max)
178     real :: t_targ(llm)
179     real :: rh_targ(llm)
180     real :: u_targ(llm)
181     real :: v_targ(llm)
182!
183!---------------------------------------------------------------------
184!  Declarations related to vertical discretization:
185!---------------------------------------------------------------------
186      real :: pzero=1.e5
187      real :: play (llm),zlay (llm),sig_s(llm),plev(llm+1)
188      real :: playd(llm),zlayd(llm),ap_amma(llm+1),bp_amma(llm+1)
189
190!---------------------------------------------------------------------
191!  Declarations related to variables
192!---------------------------------------------------------------------
193
194      real :: phi(llm)
195      real :: teta(llm),tetal(llm),temp(llm),u(llm),v(llm),w(llm)
196      REAL rot(1, llm) ! relative vorticity, in s-1
197      real :: rlat_rad(1),rlon_rad(1)
198      real :: omega(llm+1),omega2(llm),rho(llm+1)
199      real :: ug(llm),vg(llm),fcoriolis
200      real :: sfdt, cfdt
201      real :: du_phys(llm),dv_phys(llm),dt_phys(llm)
202      real :: dt_dyn(llm)
203      real :: dt_cooling(llm),d_t_adv(llm),d_t_nudge(llm)
204      real :: d_u_nudge(llm),d_v_nudge(llm)
205      real :: du_adv(llm),dv_adv(llm)
206      real :: du_age(llm),dv_age(llm)
207      real :: alpha
208      real :: ttt
209
210      REAL, ALLOCATABLE, DIMENSION(:,:):: q
211      REAL, ALLOCATABLE, DIMENSION(:,:):: dq
212      REAL, ALLOCATABLE, DIMENSION(:,:):: dq_dyn
213      REAL, ALLOCATABLE, DIMENSION(:,:):: d_q_adv
214      REAL, ALLOCATABLE, DIMENSION(:,:):: d_q_nudge
215!      REAL, ALLOCATABLE, DIMENSION(:):: d_th_adv
216
217!---------------------------------------------------------------------
218!  Initialization of surface variables
219!---------------------------------------------------------------------
220      real :: run_off_lic_0(1)
221      real :: fder(1),snsrf(1,nbsrf),qsurfsrf(1,nbsrf)
222      real :: tsoil(1,nsoilmx,nbsrf)
223!     real :: agesno(1,nbsrf)
224
225!---------------------------------------------------------------------
226!  Call to phyredem
227!---------------------------------------------------------------------
228      logical :: ok_writedem =.true.
229      real :: sollw_in = 0.
230      real :: solsw_in = 0.
231     
232!---------------------------------------------------------------------
233!  Call to physiq
234!---------------------------------------------------------------------
235      logical :: firstcall=.true.
236      logical :: lastcall=.false.
237      real :: phis(1)    = 0.0
238      real :: dpsrf(1)
239
240!---------------------------------------------------------------------
241!  Initializations of boundary conditions
242!---------------------------------------------------------------------
243      real, allocatable :: phy_nat (:)  ! 0=ocean libre,1=land,2=glacier,3=banquise
244      real, allocatable :: phy_alb (:)  ! Albedo land only (old value condsurf_jyg=0.3)
245      real, allocatable :: phy_sst (:)  ! SST (will not be used; cf read_tsurf1d.F)
246      real, allocatable :: phy_bil (:)  ! Ne sert que pour les slab_ocean
247      real, allocatable :: phy_rug (:) ! Longueur rugosite utilisee sur land only
248      real, allocatable :: phy_ice (:) ! Fraction de glace
249      real, allocatable :: phy_fter(:) ! Fraction de terre
250      real, allocatable :: phy_foce(:) ! Fraction de ocean
251      real, allocatable :: phy_fsic(:) ! Fraction de glace
252      real, allocatable :: phy_flic(:) ! Fraction de glace
253
254!---------------------------------------------------------------------
255!  Fichiers et d'autres variables
256!---------------------------------------------------------------------
257      integer :: k,l,i,it=1,mxcalc
258      integer :: nsrf
259      integer jcode
260      INTEGER read_climoz
261!
262      integer :: it_end ! iteration number of the last call
263!Al1
264      integer ecrit_slab_oc !1=ecrit,-1=lit,0=no file
265      data ecrit_slab_oc/-1/
266!
267!     if flag_inhib_forcing = 0, tendencies of forcing are added
268!                           <> 0, tendencies of forcing are not added
269      INTEGER :: flag_inhib_forcing = 0
270
271!=====================================================================
272! INITIALIZATIONS
273!=====================================================================
274      du_phys(:)=0.
275      dv_phys(:)=0.
276      dt_phys(:)=0.
277      dt_dyn(:)=0.
278      dt_cooling(:)=0.
279      d_t_adv(:)=0.
280      d_t_nudge(:)=0.
281      d_u_nudge(:)=0.
282      d_v_nudge(:)=0.
283      du_adv(:)=0.
284      dv_adv(:)=0.
285      du_age(:)=0.
286      dv_age(:)=0.
287     
288! Initialization of Common turb_forcing
289       dtime_frcg = 0.
290       Turb_fcg_gcssold=.false.
291       hthturb_gcssold = 0.
292       hqturb_gcssold = 0.
293
294
295
296
297!---------------------------------------------------------------------
298! OPTIONS OF THE 1D SIMULATION (lmdz1d.def => unicol.def)
299!---------------------------------------------------------------------
300!Al1
301        call conf_unicol
302!Al1 moves this gcssold var from common fcg_gcssold to
303        Turb_fcg_gcssold = xTurb_fcg_gcssold
304! --------------------------------------------------------------------
305        close(1)
306!Al1
307        write(*,*) 'lmdz1d.def lu => unicol.def'
308
309! forcing_type defines the way the SCM is forced:
310!forcing_type = 0 ==> forcing_les = .true.
311!             initial profiles from file prof.inp.001
312!             no forcing by LS convergence ;
313!             surface temperature imposed ;
314!             radiative cooling may be imposed (iflag_radia=0 in physiq.def)
315!forcing_type = 1 ==> forcing_radconv = .true.
316!             idem forcing_type = 0, but the imposed radiative cooling
317!             is set to 0 (hence, if iflag_radia=0 in physiq.def,
318!             then there is no radiative cooling at all)
319!forcing_type = 2 ==> forcing_toga = .true.
320!             initial profiles from TOGA-COARE IFA files
321!             LS convergence and SST imposed from TOGA-COARE IFA files
322!forcing_type = 3 ==> forcing_GCM2SCM = .true.
323!             initial profiles from the GCM output
324!             LS convergence imposed from the GCM output
325!forcing_type = 4 ==> forcing_twpice = .true.
326!             initial profiles from TWP-ICE cdf file
327!             LS convergence, omega and SST imposed from TWP-ICE files
328!forcing_type = 5 ==> forcing_rico = .true.
329!             initial profiles from RICO files
330!             LS convergence imposed from RICO files
331!forcing_type = 6 ==> forcing_amma = .true.
332!             initial profiles from AMMA nc file
333!             LS convergence, omega and surface fluxes imposed from AMMA file 
334!forcing_type = 7 ==> forcing_dice = .true.
335!             initial profiles and large scale forcings in dice_driver.nc
336!             Different stages: soil model alone, atm. model alone
337!             then both models coupled
338!forcing_type = 8 ==> forcing_gabls4 = .true.
339!             initial profiles and large scale forcings in gabls4_driver.nc
340!forcing_type >= 100 ==> forcing_case = .true.
341!             initial profiles and large scale forcings in cas.nc
342!             LS convergence, omega and SST imposed from CINDY-DYNAMO files
343!             101=cindynamo
344!             102=bomex
345!forcing_type >= 100 ==> forcing_case2 = .true.
346!             temporary flag while all the 1D cases are not whith the same cas.nc forcing file
347!             103=arm_cu2 ie arm_cu with new forcing format
348!             104=rico2 ie rico with new forcing format
349!forcing_type = 40 ==> forcing_GCSSold = .true.
350!             initial profile from GCSS file
351!             LS convergence imposed from GCSS file
352!forcing_type = 50 ==> forcing_fire = .true.
353!             forcing from fire.nc
354!forcing_type = 59 ==> forcing_sandu = .true.
355!             initial profiles from sanduref file: see prof.inp.001
356!             SST varying with time and divergence constante: see ifa_sanduref.txt file
357!             Radiation has to be computed interactively
358!forcing_type = 60 ==> forcing_astex = .true.
359!             initial profiles from file: see prof.inp.001
360!             SST,divergence,ug,vg,ufa,vfa varying with time : see ifa_astex.txt file
361!             Radiation has to be computed interactively
362!forcing_type = 61 ==> forcing_armcu = .true.
363!             initial profiles from file: see prof.inp.001
364!             sensible and latent heat flux imposed: see ifa_arm_cu_1.txt
365!             large scale advective forcing & radiative tendencies applied below 1000m: see ifa_arm_cu_2.txt
366!             use geostrophic wind ug=10m/s vg=0m/s. Duration of the case 53100s
367!             Radiation to be switched off
368!
369      if (forcing_type <=0) THEN
370       forcing_les = .true.
371      elseif (forcing_type .eq.1) THEN
372       forcing_radconv = .true.
373      elseif (forcing_type .eq.2) THEN
374       forcing_toga    = .true.
375      elseif (forcing_type .eq.3) THEN
376       forcing_GCM2SCM = .true.
377      elseif (forcing_type .eq.4) THEN
378       forcing_twpice = .true.
379      elseif (forcing_type .eq.5) THEN
380       forcing_rico = .true.
381      elseif (forcing_type .eq.6) THEN
382       forcing_amma = .true.
383      elseif (forcing_type .eq.7) THEN
384       forcing_dice = .true.
385      elseif (forcing_type .eq.8) THEN
386       forcing_gabls4 = .true.
387      elseif (forcing_type .eq.101) THEN ! Cindynamo starts 1-10-2011 0h
388       forcing_case = .true.
389       year_ini_cas=2011
390       mth_ini_cas=10
391       day_deb=1
392       heure_ini_cas=0.
393       pdt_cas=3*3600.         ! forcing frequency
394      elseif (forcing_type .eq.102) THEN ! Bomex starts 24-6-1969 0h
395       forcing_case = .true.
396       year_ini_cas=1969
397       mth_ini_cas=6
398       day_deb=24
399       heure_ini_cas=0.
400       pdt_cas=1800.         ! forcing frequency
401      elseif (forcing_type .eq.103) THEN ! Arm_cu starts 21-6-1997 11h30
402       forcing_case2 = .true.
403       year_ini_cas=1997
404       mth_ini_cas=6
405       day_deb=21
406       heure_ini_cas=11.5
407       pdt_cas=1800.         ! forcing frequency
408      elseif (forcing_type .eq.104) THEN ! rico starts 16-12-2004 0h
409       forcing_case2 = .true.
410       year_ini_cas=2004
411       mth_ini_cas=12
412       day_deb=16
413       heure_ini_cas=0.
414       pdt_cas=1800.         ! forcing frequency
415      elseif (forcing_type .eq.105) THEN ! bomex starts 16-12-2004 0h
416       forcing_case2 = .true.
417       year_ini_cas=1969
418       mth_ini_cas=6
419       day_deb=24
420       heure_ini_cas=0.
421       pdt_cas=1800.         ! forcing frequency
422      elseif (forcing_type .eq.106) THEN ! ayotte_24SC starts 6-11-1992 0h
423       forcing_case2 = .true.
424       year_ini_cas=1992
425       mth_ini_cas=11
426       day_deb=6
427       heure_ini_cas=10.
428       pdt_cas=86400.        ! forcing frequency
429      elseif (forcing_type .eq.113) THEN ! Arm_cu starts 21-6-1997 11h30
430       forcing_SCM = .true.
431       year_ini_cas=1997
432       ! It is possible that those parameters are run twice.
433       call getin('anneeref',year_ini_cas)
434       call getin('dayref',day_deb)
435       mth_ini_cas=1 ! pour le moment on compte depuis le debut de l'annee
436       call getin('time_ini',heure_ini_cas)
437      elseif (forcing_type .eq.40) THEN
438       forcing_GCSSold = .true.
439      elseif (forcing_type .eq.50) THEN
440       forcing_fire = .true.
441      elseif (forcing_type .eq.59) THEN
442       forcing_sandu   = .true.
443      elseif (forcing_type .eq.60) THEN
444       forcing_astex   = .true.
445      elseif (forcing_type .eq.61) THEN
446       forcing_armcu = .true.
447       IF(llm.NE.19.AND.llm.NE.40) stop 'Erreur nombre de niveaux !!'
448      else
449       write (*,*) 'ERROR : unknown forcing_type ', forcing_type
450       stop 'Forcing_type should be 0,1,2,3,4,5,6 or 40,59,60,61'
451      ENDIF
452      print*,"forcing type=",forcing_type
453
454! if type_ts_forcing=0, the surface temp of 1D simulation is constant in time
455! (specified by tsurf in lmdz1d.def); if type_ts_forcing=1, the surface temperature
456! varies in time according to a forcing (e.g. forcing_toga) and is passed to read_tsurf1d.F
457! through the common sst_forcing.
458
459        type_ts_forcing = 0
460        if (forcing_toga.or.forcing_sandu.or.forcing_astex .or. forcing_dice)                 &
461     &    type_ts_forcing = 1
462!
463! Initialization of the logical switch for nudging
464     jcode = iflag_nudge
465     do i = 1,nudge_max
466       nudge(i) = mod(jcode,10) .ge. 1
467       jcode = jcode/10
468     enddo
469!---------------------------------------------------------------------
470!  Definition of the run
471!---------------------------------------------------------------------
472
473      call conf_gcm( 99, .TRUE. )
474     
475!-----------------------------------------------------------------------
476      allocate( phy_nat (year_len))  ! 0=ocean libre,1=land,2=glacier,3=banquise
477      phy_nat(:)=0.0
478      allocate( phy_alb (year_len))  ! Albedo land only (old value condsurf_jyg=0.3)
479      allocate( phy_sst (year_len))  ! SST (will not be used; cf read_tsurf1d.F)
480      allocate( phy_bil (year_len))  ! Ne sert que pour les slab_ocean
481      phy_bil(:)=1.0
482      allocate( phy_rug (year_len)) ! Longueur rugosite utilisee sur land only
483      allocate( phy_ice (year_len)) ! Fraction de glace
484      phy_ice(:)=0.0
485      allocate( phy_fter(year_len)) ! Fraction de terre
486      phy_fter(:)=0.0
487      allocate( phy_foce(year_len)) ! Fraction de ocean
488      phy_foce(:)=0.0
489      allocate( phy_fsic(year_len)) ! Fraction de glace
490      phy_fsic(:)=0.0
491      allocate( phy_flic(year_len)) ! Fraction de glace
492      phy_flic(:)=0.0
493!-----------------------------------------------------------------------
494!   Choix du calendrier
495!   -------------------
496
497!      calend = 'earth_365d'
498      if (calend == 'earth_360d') then
499        call ioconf_calendar('360_day')
500        write(*,*)'CALENDRIER CHOISI: Terrestre a 360 jours/an'
501      else if (calend == 'earth_365d') then
502        call ioconf_calendar('noleap')
503        write(*,*)'CALENDRIER CHOISI: Terrestre a 365 jours/an'
504      else if (calend == 'earth_366d') then
505        call ioconf_calendar('all_leap')
506        write(*,*)'CALENDRIER CHOISI: Terrestre bissextile'
507      else if (calend == 'gregorian') then
508        stop 'gregorian calend should not be used by normal user'
509        call ioconf_calendar('gregorian') ! not to be used by normal users
510        write(*,*)'CALENDRIER CHOISI: Gregorien'
511      else
512        write (*,*) 'ERROR : unknown calendar ', calend
513        stop 'calend should be 360d,earth_365d,earth_366d,gregorian'
514      endif
515!-----------------------------------------------------------------------
516!
517!c Date :
518!      La date est supposee donnee sous la forme [annee, numero du jour dans
519!      l annee] ; l heure est donnee dans time_ini, lu dans lmdz1d.def.
520!      On appelle ymds2ju pour convertir [annee, jour] en [jour Julien].
521!      Le numero du jour est dans "day". L heure est traitee separement.
522!      La date complete est dans "daytime" (l'unite est le jour).
523      if (nday>0) then
524         fnday=nday
525      else
526         fnday=-nday/float(day_step)
527      endif
528      print *,'fnday=',fnday
529!     start_time doit etre en FRACTION DE JOUR
530      start_time=time_ini/24.
531
532! Special case for arm_cu which lasts less than one day : 53100s !! (MPL 20111026)
533      IF(forcing_type .EQ. 61) fnday=53100./86400.
534      IF(forcing_type .EQ. 103) fnday=53100./86400.
535! Special case for amma which lasts less than one day : 64800s !! (MPL 20120216)
536      IF(forcing_type .EQ. 6) fnday=64800./86400.
537!     IF(forcing_type .EQ. 6) fnday=50400./86400.
538 IF(forcing_type .EQ. 8 ) fnday=129600./86400.
539      annee_ref = anneeref
540      mois = 1
541      day_ref = dayref
542      heure = 0.
543      itau_dyn = 0
544      itau_phy = 0
545      call ymds2ju(annee_ref,mois,day_ref,heure,day)
546      day_ini = int(day)
547      day_end = day_ini + int(fnday)
548
549      IF (forcing_type .eq.2) THEN
550! Convert the initial date of Toga-Coare to Julian day
551      call ymds2ju                                                          &
552     & (year_ini_toga,mth_ini_toga,day_ini_toga,heure,day_ju_ini_toga)
553
554      ELSEIF (forcing_type .eq.4) THEN
555! Convert the initial date of TWPICE to Julian day
556      call ymds2ju                                                          &
557     & (year_ini_twpi,mth_ini_twpi,day_ini_twpi,heure_ini_twpi              &
558     & ,day_ju_ini_twpi)
559      ELSEIF (forcing_type .eq.6) THEN
560! Convert the initial date of AMMA to Julian day
561      call ymds2ju                                                          &
562     & (year_ini_amma,mth_ini_amma,day_ini_amma,heure_ini_amma              &
563     & ,day_ju_ini_amma)
564      ELSEIF (forcing_type .eq.7) THEN
565! Convert the initial date of DICE to Julian day
566      call ymds2ju                                                         &
567     & (year_ini_dice,mth_ini_dice,day_ini_dice,heure_ini_dice             &
568     & ,day_ju_ini_dice)
569 ELSEIF (forcing_type .eq.8 ) THEN
570! Convert the initial date of GABLS4 to Julian day
571      call ymds2ju                                                         &
572     & (year_ini_gabls4,mth_ini_gabls4,day_ini_gabls4,heure_ini_gabls4     &
573     & ,day_ju_ini_gabls4)
574      ELSEIF (forcing_type .gt.100) THEN
575! Convert the initial date to Julian day
576      day_ini_cas=day_deb
577      print*,'time case',year_ini_cas,mth_ini_cas,day_ini_cas
578      call ymds2ju                                                         &
579     & (year_ini_cas,mth_ini_cas,day_ini_cas,heure_ini_cas*3600            &
580     & ,day_ju_ini_cas)
581      print*,'time case 2',day_ini_cas,day_ju_ini_cas
582      ELSEIF (forcing_type .eq.59) THEN
583! Convert the initial date of Sandu case to Julian day
584      call ymds2ju                                                          &
585     &   (year_ini_sandu,mth_ini_sandu,day_ini_sandu,                       &
586     &    time_ini*3600.,day_ju_ini_sandu)
587
588      ELSEIF (forcing_type .eq.60) THEN
589! Convert the initial date of Astex case to Julian day
590      call ymds2ju                                                          &
591     &   (year_ini_astex,mth_ini_astex,day_ini_astex,                        &
592     &    time_ini*3600.,day_ju_ini_astex)
593
594      ELSEIF (forcing_type .eq.61) THEN
595! Convert the initial date of Arm_cu case to Julian day
596      call ymds2ju                                                          &
597     & (year_ini_armcu,mth_ini_armcu,day_ini_armcu,heure_ini_armcu          &
598     & ,day_ju_ini_armcu)
599      ENDIF
600
601      IF (forcing_type .gt.100) THEN
602      daytime = day + heure_ini_cas/24. ! 1st day and initial time of the simulation
603      ELSE
604      daytime = day + time_ini/24. ! 1st day and initial time of the simulation
605      ENDIF
606! Print out the actual date of the beginning of the simulation :
607      call ju2ymds(daytime,year_print, month_print,day_print,sec_print)
608      print *,' Time of beginning : ',                                      &
609     &        year_print, month_print, day_print, sec_print
610
611!---------------------------------------------------------------------
612! Initialization of dimensions, geometry and initial state
613!---------------------------------------------------------------------
614!      call init_phys_lmdz(1,1,llm,1,(/1/)) ! job now done via iniphysiq
615!     but we still need to initialize dimphy module (klon,klev,etc.)  here.
616      call init_dimphy1D(1,llm)
617      call suphel
618      call init_infotrac
619
620      if (nqtot>nqmx) STOP 'Augmenter nqmx dans lmdz1d.F'
621      allocate(q(llm,nqtot)) ; q(:,:)=0.
622      allocate(dq(llm,nqtot))
623      allocate(dq_dyn(llm,nqtot))
624      allocate(d_q_adv(llm,nqtot))
625      allocate(d_q_nudge(llm,nqtot))
626!      allocate(d_th_adv(llm))
627
628      q(:,:) = 0.
629      dq(:,:) = 0.
630      dq_dyn(:,:) = 0.
631      d_q_adv(:,:) = 0.
632      d_q_nudge(:,:) = 0.
633
634!
635!   No ozone climatology need be read in this pre-initialization
636!          (phys_state_var_init is called again in physiq)
637      read_climoz = 0
638      nsw=6          ! EV et LF: sinon, falb_dir et falb_dif ne peuvent etre alloues
639
640
641      call phys_state_var_init(read_climoz)
642
643      if (ngrid.ne.klon) then
644         print*,'stop in inifis'
645         print*,'Probleme de dimensions :'
646         print*,'ngrid = ',ngrid
647         print*,'klon  = ',klon
648         stop
649      endif
650!!!=====================================================================
651!!! Feedback forcing values for Gateaux differentiation (al1)
652!!!=====================================================================
653!!! Surface Planck forcing bracketing call radiation
654!!      surf_Planck = 0.
655!!      surf_Conv   = 0.
656!!      write(*,*) 'Gateaux-dif Planck,Conv:',surf_Planck,surf_Conv
657!!! a mettre dans le lmdz1d.def ou autre
658!!
659!!
660      qsol = qsolinp
661      qsurf = fq_sat(tsurf,psurf/100.)
662      beta_surf = 1.
663      beta_aridity(:,:) = beta_surf
664      day1= day_ini
665      time=daytime-day
666      ts_toga(1)=tsurf ! needed by read_tsurf1d.F
667      rho(1)=psurf/(rd*tsurf*(1.+(rv/rd-1.)*qsurf))
668
669!
670!! mpl et jyg le 22/08/2012 :
671!!  pour que les cas a flux de surface imposes marchent
672      IF(.NOT.ok_flux_surf.or.max(abs(wtsurf),abs(wqsurf))>0.) THEN
673       fsens=-wtsurf*rcpd*rho(1)
674       flat=-wqsurf*rlvtt*rho(1)
675       print *,'Flux: ok_flux wtsurf wqsurf',ok_flux_surf,wtsurf,wqsurf
676      ENDIF
677      print*,'Flux sol ',fsens,flat
678!!      ok_flux_surf=.false.
679!!      fsens=-wtsurf*rcpd*rho(1)
680!!      flat=-wqsurf*rlvtt*rho(1)
681!!!!
682
683! Vertical discretization and pressure levels at half and mid levels:
684
685      pa   = 5e4
686!!      preff= 1.01325e5
687      preff = psurf
688      IF (ok_old_disvert) THEN
689        call disvert0(pa,preff,ap,bp,dpres,presnivs,nivsigs,nivsig)
690        print *,'On utilise disvert0'
691        aps(1:llm)=0.5*(ap(1:llm)+ap(2:llm+1))
692        bps(1:llm)=0.5*(bp(1:llm)+bp(2:llm+1))
693        scaleheight=8.
694        pseudoalt(1:llm)=-scaleheight*log(presnivs(1:llm)/preff)
695      ELSE
696        call disvert()
697        print *,'On utilise disvert'
698!       Nouvelle version disvert permettant d imposer ap,bp (modif L.Guez) MPL 18092012
699!       Dans ce cas, on lit ap,bp dans le fichier hybrid.txt
700      ENDIF
701
702      sig_s=presnivs/preff
703      plev =ap+bp*psurf
704      play = 0.5*(plev(1:llm)+plev(2:llm+1))
705      zlay=-rd*300.*log(play/psurf)/rg ! moved after reading profiles
706
707      IF (forcing_type .eq. 59) THEN
708! pour forcing_sandu, on cherche l'indice le plus proche de 700hpa#3000m
709      write(*,*) '***********************'
710      do l = 1, llm
711       write(*,*) 'l,play(l),presnivs(l): ',l,play(l),presnivs(l)
712       if (trouve_700 .and. play(l).le.70000) then
713         llm700=l
714         print *,'llm700,play=',llm700,play(l)/100.
715         trouve_700= .false.
716       endif
717      enddo
718      write(*,*) '***********************'
719      ENDIF
720
721!
722!=====================================================================
723! EVENTUALLY, READ FORCING DATA :
724!=====================================================================
725
726      INCLUDE "old_1D_read_forc_cases.h"
727
728      if (forcing_GCM2SCM) then
729        write (*,*) 'forcing_GCM2SCM not yet implemented'
730        stop 'in initialization'
731      endif ! forcing_GCM2SCM
732
733      print*,'mxcalc=',mxcalc
734!     print*,'zlay=',zlay(mxcalc)
735      print*,'play=',play(mxcalc)
736
737!Al1 pour SST forced, appell?? depuis ocean_forced_noice
738! EV tg instead of ts_cur
739
740      tg = tsurf ! SST used in read_tsurf1d
741!=====================================================================
742! Initialisation de la physique :
743!=====================================================================
744
745!  Rq: conf_phys.F90 lit tous les flags de physiq.def; conf_phys appele depuis physiq.F
746!
747! day_step, iphysiq lus dans gcm.def ci-dessus
748! timestep: calcule ci-dessous from rday et day_step
749! ngrid=1
750! llm: defini dans .../modipsl/modeles/LMDZ4/libf/grid/dimension
751! rday: defini dans suphel.F (86400.)
752! day_ini: lu dans run.def (dayref)
753! rlat_rad,rlon-rad: transformes en radian de rlat,rlon lus dans lmdz1d.def (en degres)
754! airefi,zcufi,zcvfi initialises au debut de ce programme
755! rday,ra,rg,rd,rcpd declares dans YOMCST.h et calcules dans suphel.F
756      day_step = float(nsplit_phys)*day_step/float(iphysiq)
757      write (*,*) 'Time step divided by nsplit_phys (=',nsplit_phys,')'
758      timestep =rday/day_step
759      dtime_frcg = timestep
760!
761      zcufi=airefi
762      zcvfi=airefi
763!
764      rlat_rad(1)=xlat*rpi/180.
765      rlon_rad(1)=xlon*rpi/180.
766
767     ! iniphysiq will call iniaqua who needs year_len from phys_cal_mod
768     year_len_phys_cal_mod=year_len
769           
770     ! Ehouarn: iniphysiq requires arrays related to (3D) dynamics grid,
771     ! e.g. for cell boundaries, which are meaningless in 1D; so pad these
772     ! with '0.' when necessary
773      call iniphysiq(iim,jjm,llm, &
774           1,comm_lmdz, &
775           rday,day_ini,timestep,  &
776           (/rlat_rad(1),0./),(/0./), &
777           (/0.,0./),(/rlon_rad(1),0./),  &
778           (/ (/airefi,0./),(/0.,0./) /), &
779           (/zcufi,0.,0.,0./), &
780           (/zcvfi,0./), &
781           ra,rg,rd,rcpd,1)
782      print*,'apres iniphysiq'
783
784! 2 PARAMETRES QUI DEVRAIENT ETRE LUS DANS run.def MAIS NE LE SONT PAS ICI:
785      co2_ppm= 330.0
786      solaire=1370.0
787
788! Ecriture du startphy avant le premier appel a la physique.
789! On le met juste avant pour avoir acces a tous les champs
790
791      if (ok_writedem) then
792
793!--------------------------------------------------------------------------
794! pbl_surface_init (called here) and pbl_surface_final (called by phyredem)
795! need : qsol fder snow qsurf evap rugos agesno ftsoil
796!--------------------------------------------------------------------------
797
798        type_ocean = "force"
799        run_off_lic_0(1) = restart_runoff
800        call fonte_neige_init(run_off_lic_0)
801
802        fder=0.
803        snsrf(1,:)=snowmass ! masse de neige des sous surface
804        print *, 'snsrf', snsrf
805        qsurfsrf(1,:)=qsurf ! humidite de l'air des sous surface
806        fevap=0.
807        z0m(1,:)=rugos     ! couverture de neige des sous surface
808        z0h(1,:)=rugosh    ! couverture de neige des sous surface
809        agesno  = xagesno
810        tsoil(:,:,:)=tsurf
811!------ AMMA 2e run avec modele sol et rayonnement actif (MPL 23052012)
812!       tsoil(1,1,1)=299.18
813!       tsoil(1,2,1)=300.08
814!       tsoil(1,3,1)=301.88
815!       tsoil(1,4,1)=305.48
816!       tsoil(1,5,1)=308.00
817!       tsoil(1,6,1)=308.00
818!       tsoil(1,7,1)=308.00
819!       tsoil(1,8,1)=308.00
820!       tsoil(1,9,1)=308.00
821!       tsoil(1,10,1)=308.00
822!       tsoil(1,11,1)=308.00
823!-----------------------------------------------------------------------
824        call pbl_surface_init(fder, snsrf, qsurfsrf, tsoil)
825
826!------------------ prepare limit conditions for limit.nc -----------------
827!--   Ocean force
828
829        print*,'avant phyredem'
830        pctsrf(1,:)=0.
831          if (nat_surf.eq.0.) then
832          pctsrf(1,is_oce)=1.
833          pctsrf(1,is_ter)=0.
834          pctsrf(1,is_lic)=0.
835          pctsrf(1,is_sic)=0.
836        else if (nat_surf .eq. 1) then
837          pctsrf(1,is_oce)=0.
838          pctsrf(1,is_ter)=1.
839          pctsrf(1,is_lic)=0.
840          pctsrf(1,is_sic)=0.
841        else if (nat_surf .eq. 2) then
842          pctsrf(1,is_oce)=0.
843          pctsrf(1,is_ter)=0.
844          pctsrf(1,is_lic)=1.
845          pctsrf(1,is_sic)=0.
846        else if (nat_surf .eq. 3) then
847          pctsrf(1,is_oce)=0.
848          pctsrf(1,is_ter)=0.
849          pctsrf(1,is_lic)=0.
850          pctsrf(1,is_sic)=1.
851
852     end if
853
854        print*,'nat_surf,pctsrf(1,is_oce),pctsrf(1,is_ter)',nat_surf         &
855     &        ,pctsrf(1,is_oce),pctsrf(1,is_ter)
856
857        zmasq=pctsrf(1,is_ter)+pctsrf(1,is_lic)
858        zpic = zpicinp
859        ftsol=tsurf
860        falb_dir=albedo
861        falb_dif=albedo
862        rugoro=rugos
863        t_ancien(1,:)=temp(:)
864        q_ancien(1,:)=q(:,1)
865        ql_ancien = 0.
866        qs_ancien = 0.
867        prlw_ancien = 0.
868        prsw_ancien = 0.
869        prw_ancien = 0.
870        IF ( ok_bs ) THEN
871          qbs_ancien = 0.
872          prbsw_ancien = 0.
873        ENDIF
874        IF ( ok_ice_supersat ) THEN
875          cf_ancien = 0.
876          rvc_ancien = 0.
877        ENDIF
878!jyg<
879!!        pbl_tke(:,:,:)=1.e-8
880        pbl_tke(:,:,:)=0.
881        pbl_tke(:,2,:)=1.e-2
882        PRINT *, ' pbl_tke dans lmdz1d '
883        if (prt_level .ge. 5) then
884         DO nsrf = 1,4
885           PRINT *,'pbl_tke(1,:,',nsrf,') ',pbl_tke(1,:,nsrf)
886         ENDDO
887        end if
888
889!>jyg
890
891        rain_fall=0.
892        snow_fall=0.
893        solsw=0.
894        solswfdiff=0.
895        sollw=0.
896        sollwdown=rsigma*tsurf**4
897        radsol=0.
898        rnebcon=0.
899        ratqs=0.
900        clwcon=0.
901        zmax0 = 0.
902        zmea=zsurf
903        zstd=0.
904        zsig=0.
905        zgam=0.
906        zval=0.
907        zthe=0.
908        sig1=0.
909        w01=0.
910!
911        wake_deltaq = 0.
912        wake_deltat = 0.
913        wake_delta_pbl_TKE(:,:,:) = 0.
914        delta_tsurf = 0.
915        wake_fip = 0.
916        wake_pe = 0.
917        wake_s = 0.
918        awake_s = 0.
919        wake_dens = 0.
920        awake_dens = 0.
921        cv_gen = 0.
922        wake_cstar = 0.
923        ale_bl = 0.
924        ale_bl_trig = 0.
925        alp_bl = 0.
926        IF (ALLOCATED(du_gwd_rando)) du_gwd_rando = 0.
927        IF (ALLOCATED(du_gwd_front)) du_gwd_front = 0.
928        entr_therm = 0.
929        detr_therm = 0.
930        f0 = 0.
931        fm_therm = 0.
932        u_ancien(1,:)=u(:)
933        v_ancien(1,:)=v(:)
934
935        u10m=0.
936        v10m=0.
937        ale_wake=0.
938        ale_bl_stat=0.
939 
940!------------------------------------------------------------------------
941! Make file containing restart for the physics (startphy.nc)
942!
943! NB: List of the variables to be written by phyredem (via put_field):
944! rlon,rlat,zmasq,pctsrf(:,is_ter),pctsrf(:,is_lic),pctsrf(:,is_oce)
945! pctsrf(:,is_sic),ftsol(:,nsrf),tsoil(:,isoil,nsrf),qsurf(:,nsrf)
946! qsol,falb_dir(:,nsrf),falb_dif(:,nsrf),evap(:,nsrf),snow(:,nsrf)
947! radsol,solsw,solswfdiff,sollw, sollwdown,fder,rain_fall,snow_fall,frugs(:,nsrf)
948! agesno(:,nsrf),zmea,zstd,zsig,zgam,zthe,zpic,zval,rugoro
949! t_ancien,q_ancien,,frugs(:,is_oce),clwcon(:,1),rnebcon(:,1),ratqs(:,1)
950! run_off_lic_0,pbl_tke(:,1:klev,nsrf), zmax0,f0,sig1,w01
951! wake_deltat,wake_deltaq,wake_s,awake_s,wake_dens,awake_dens,cv_gen,wake_cstar,
952! wake_fip,wake_delta_pbl_tke(:,1:klev,nsrf)
953!
954! NB2: The content of the startphy.nc file depends on some flags defined in
955! the ".def" files. However, since conf_phys is not called in lmdz1d.F90, these flags have
956! to be set at some arbitratry convenient values.
957!------------------------------------------------------------------------
958!Al1 =============== restart option ==========================
959        iflag_physiq=0
960        call getin('iflag_physiq',iflag_physiq)
961
962        if (.not.restart) then
963          iflag_pbl = 5
964          call phyredem ("startphy.nc")
965        else
966! (desallocations)
967        print*,'callin surf final'
968          call pbl_surface_final( fder, snsrf, qsurfsrf, tsoil)
969        print*,'after surf final'
970          CALL fonte_neige_final(run_off_lic_0)
971        endif
972
973        ok_writedem=.false.
974        print*,'apres phyredem'
975
976      endif ! ok_writedem
977     
978!------------------------------------------------------------------------
979! Make file containing boundary conditions (limit.nc) **Al1->restartdyn***
980! --------------------------------------------------
981! NB: List of the variables to be written in limit.nc
982!     (by writelim.F, subroutine of 1DUTILS.h):
983!        phy_nat,phy_alb,phy_sst,phy_bil,phy_rug,phy_ice,
984!        phy_fter,phy_foce,phy_flic,phy_fsic)
985!------------------------------------------------------------------------
986      do i=1,year_len
987        phy_nat(i)  = nat_surf
988        phy_alb(i)  = albedo
989        phy_sst(i)  = tsurf ! read_tsurf1d will be used instead
990        phy_rug(i)  = rugos
991        phy_fter(i) = pctsrf(1,is_ter)
992        phy_foce(i) = pctsrf(1,is_oce)
993        phy_fsic(i) = pctsrf(1,is_sic)
994        phy_flic(i) = pctsrf(1,is_lic)
995      enddo
996
997! fabrication de limit.nc
998      call writelim (1,phy_nat,phy_alb,phy_sst,phy_bil,phy_rug,             &
999     &               phy_ice,phy_fter,phy_foce,phy_flic,phy_fsic)
1000
1001
1002      call phys_state_var_end
1003!Al1
1004      if (restart) then
1005        print*,'call to restart dyn 1d'
1006        Call dyn1deta0("start1dyn.nc",plev,play,phi,phis,presnivs,          &
1007     &              u,v,temp,q,omega2)
1008
1009       print*,'fnday,annee_ref,day_ref,day_ini',                            &
1010     &     fnday,annee_ref,day_ref,day_ini
1011!**      call ymds2ju(annee_ref,mois,day_ini,heure,day)
1012       day = day_ini
1013       day_end = day_ini + nday
1014       daytime = day + time_ini/24. ! 1st day and initial time of the simulation
1015
1016! Print out the actual date of the beginning of the simulation :
1017       call ju2ymds(daytime, an, mois, jour, heure)
1018       print *,' Time of beginning : y m d h',an, mois,jour,heure/3600.
1019
1020       day = int(daytime)
1021       time=daytime-day
1022 
1023       print*,'****** intialised fields from restart1dyn *******'
1024       print*,'plev,play,phi,phis,presnivs,u,v,temp,q,omega2'
1025       print*,'temp(1),q(1,1),u(1),v(1),plev(1),phis :'
1026       print*,temp(1),q(1,1),u(1),v(1),plev(1),phis
1027! raz for safety
1028       do l=1,llm
1029         dq_dyn(l,1) = 0.
1030       enddo
1031      endif
1032!Al1 ================  end restart =================================
1033      IF (ecrit_slab_oc.eq.1) then
1034         open(97,file='div_slab.dat',STATUS='UNKNOWN')
1035       elseif (ecrit_slab_oc.eq.0) then
1036         open(97,file='div_slab.dat',STATUS='OLD')
1037       endif
1038!
1039!---------------------------------------------------------------------
1040!    Initialize target profile for RHT nudging if needed
1041!---------------------------------------------------------------------
1042      if (nudge(inudge_RHT)) then
1043        call nudge_RHT_init(plev,play,temp,q(:,1),t_targ,rh_targ)
1044      endif
1045      if (nudge(inudge_UV)) then
1046        call nudge_UV_init(plev,play,u,v,u_targ,v_targ)
1047      endif
1048!
1049!=====================================================================
1050IF (CPPKEY_OUTPUTPHYSSCM) THEN
1051       CALL iophys_ini(timestep)
1052END IF
1053! START OF THE TEMPORAL LOOP :
1054!=====================================================================
1055           
1056      it_end = nint(fnday*day_step)
1057!test JLD     it_end = 10
1058      do while(it.le.it_end)
1059
1060       if (prt_level.ge.1) then
1061         print*,'XXXXXXXXXXXXXXXXXXX ITAP,day,time=',                       &
1062     &             it,day,time,it_end,day_step
1063         print*,'PAS DE TEMPS ',timestep
1064       endif
1065!Al1 demande de restartphy.nc
1066       if (it.eq.it_end) lastcall=.True.
1067
1068!---------------------------------------------------------------------
1069!  Geopotential :
1070!---------------------------------------------------------------------
1071
1072        phi(1)=RD*temp(1)*(plev(1)-play(1))/(.5*(plev(1)+play(1)))
1073        do l = 1, llm-1
1074          phi(l+1)=phi(l)+RD*(temp(l)+temp(l+1))*                           &
1075     &    (play(l)-play(l+1))/(play(l)+play(l+1))
1076        enddo
1077
1078!---------------------------------------------------------------------
1079! Interpolation of forcings in time and onto model levels
1080!---------------------------------------------------------------------
1081
1082      INCLUDE "old_1D_interp_cases.h"
1083
1084      if (forcing_GCM2SCM) then
1085        write (*,*) 'forcing_GCM2SCM not yet implemented'
1086        stop 'in time loop'
1087      endif ! forcing_GCM2SCM
1088
1089!!!!---------------------------------------------------------------------
1090!!!!  Geopotential :
1091!!!!---------------------------------------------------------------------
1092!!!
1093!!!        phi(1)=RD*temp(1)*(plev(1)-play(1))/(.5*(plev(1)+play(1)))
1094!!!        do l = 1, llm-1
1095!!!          phi(l+1)=phi(l)+RD*(temp(l)+temp(l+1))*                           &
1096!!!     &    (play(l)-play(l+1))/(play(l)+play(l+1))
1097!!!        enddo
1098
1099!---------------------------------------------------------------------
1100! Listing output for debug prt_level>=1
1101!---------------------------------------------------------------------
1102       if (prt_level>=1) then
1103         print *,' avant physiq : -------- day time ',day,time
1104         write(*,*) 'firstcall,lastcall,phis',                               &
1105     &               firstcall,lastcall,phis
1106       end if
1107       if (prt_level>=5) then
1108         write(*,'(a10,2a4,4a13)') 'BEFOR1 IT=','it','l',                   &
1109     &        'presniv','plev','play','phi'
1110         write(*,'(a10,2i4,4f13.2)') ('BEFOR1 IT= ',it,l,                   &
1111     &         presnivs(l),plev(l),play(l),phi(l),l=1,llm)
1112         write(*,'(a11,2a4,a11,6a8)') 'BEFOR2','it','l',                    &
1113     &         'presniv','u','v','temp','q1','q2','omega2'
1114         write(*,'(a11,2i4,f11.2,5f8.2,e10.2)') ('BEFOR2 IT= ',it,l,         &
1115     &   presnivs(l),u(l),v(l),temp(l),q(l,1),q(l,2),omega2(l),l=1,llm)
1116       endif
1117
1118!---------------------------------------------------------------------
1119!   Call physiq :
1120!---------------------------------------------------------------------
1121       call physiq(ngrid,llm, &
1122                    firstcall,lastcall,timestep, &
1123                    plev,play,phi,phis,presnivs, &
1124                    u,v, rot, temp,q,omega2, &
1125                    du_phys,dv_phys,dt_phys,dq,dpsrf)
1126                firstcall=.false.
1127
1128!---------------------------------------------------------------------
1129! Listing output for debug
1130!---------------------------------------------------------------------
1131        if (prt_level>=5) then
1132          write(*,'(a11,2a4,4a13)') 'AFTER1 IT=','it','l',                  &
1133     &        'presniv','plev','play','phi'
1134          write(*,'(a11,2i4,4f13.2)') ('AFTER1 it= ',it,l,                  &
1135     &    presnivs(l),plev(l),play(l),phi(l),l=1,llm)
1136          write(*,'(a11,2a4,a11,6a8)') 'AFTER2','it','l',                   &
1137     &         'presniv','u','v','temp','q1','q2','omega2'
1138          write(*,'(a11,2i4,f11.2,5f8.2,e10.2)') ('AFTER2 it= ',it,l,       &
1139     &    presnivs(l),u(l),v(l),temp(l),q(l,1),q(l,2),omega2(l),l=1,llm)
1140          write(*,'(a11,2a4,a11,5a8)') 'AFTER3','it','l',                   &
1141     &         'presniv','du_phys','dv_phys','dt_phys','dq1','dq2'   
1142           write(*,'(a11,2i4,f11.2,5f8.2)') ('AFTER3 it= ',it,l,            &
1143     &      presnivs(l),86400*du_phys(l),86400*dv_phys(l),                   &
1144     &       86400*dt_phys(l),86400*dq(l,1),dq(l,2),l=1,llm)
1145          write(*,*) 'dpsrf',dpsrf
1146        endif
1147!---------------------------------------------------------------------
1148!   Add physical tendencies :
1149!---------------------------------------------------------------------
1150
1151       fcoriolis=2.*sin(rpi*xlat/180.)*romega
1152       if (forcing_radconv .or. forcing_fire) then
1153         fcoriolis=0.0
1154         dt_cooling=0.0
1155         d_t_adv=0.0
1156         d_q_adv=0.0
1157       endif
1158!      print*, 'calcul de fcoriolis ', fcoriolis
1159
1160       if (forcing_toga .or. forcing_GCSSold .or. forcing_twpice            &
1161     &    .or.forcing_amma .or. forcing_type.eq.101) then
1162         fcoriolis=0.0 ; ug=0. ; vg=0.
1163       endif
1164
1165       if(forcing_rico) then
1166          dt_cooling=0.
1167       endif
1168
1169!CRio:Attention modif sp??cifique cas de Caroline
1170      if (forcing_type==-1) then
1171         fcoriolis=0.
1172!Nudging
1173       
1174!on calcule dt_cooling
1175        do l=1,llm
1176        if (play(l).ge.20000.) then
1177            dt_cooling(l)=-1.5/86400.
1178        elseif ((play(l).ge.10000.).and.((play(l).lt.20000.))) then
1179            dt_cooling(l)=-1.5/86400.*(play(l)-10000.)/(10000.)-1./86400.*(20000.-play(l))/10000.*(temp(l)-200.)
1180        else
1181            dt_cooling(l)=-1.*(temp(l)-200.)/86400.
1182        endif
1183        enddo
1184
1185      endif     
1186!RC
1187      if (forcing_sandu) then
1188         ug(1:llm)=u_mod(1:llm)
1189         vg(1:llm)=v_mod(1:llm)
1190      endif
1191
1192      IF (prt_level >= 5) print*, 'fcoriolis, xlat,mxcalc ', &
1193                                   fcoriolis, xlat,mxcalc
1194
1195!       print *,'u-ug=',u-ug
1196
1197!!!!!!!!!!!!!!!!!!!!!!!!
1198! Geostrophic wind
1199! Le calcul ci dessous est insuffisamment precis
1200!      du_age(1:mxcalc)=fcoriolis*(v(1:mxcalc)-vg(1:mxcalc))
1201!      dv_age(1:mxcalc)=-fcoriolis*(u(1:mxcalc)-ug(1:mxcalc))
1202!!!!!!!!!!!!!!!!!!!!!!!!
1203       sfdt = sin(0.5*fcoriolis*timestep)
1204       cfdt = cos(0.5*fcoriolis*timestep)
1205!       print *,'fcoriolis,sfdt,cfdt,timestep',fcoriolis,sfdt,cfdt,timestep
1206!
1207        du_age(1:mxcalc)= -2.*sfdt/timestep*                                &
1208     &          (sfdt*(u(1:mxcalc)-ug(1:mxcalc)) -                          &
1209     &           cfdt*(v(1:mxcalc)-vg(1:mxcalc))  )
1210!!     : fcoriolis*(v(1:mxcalc)-vg(1:mxcalc))
1211!
1212       dv_age(1:mxcalc)= -2.*sfdt/timestep*                                 &
1213     &          (cfdt*(u(1:mxcalc)-ug(1:mxcalc)) +                           &
1214     &           sfdt*(v(1:mxcalc)-vg(1:mxcalc))  )
1215!!     : -fcoriolis*(u(1:mxcalc)-ug(1:mxcalc))
1216!
1217!!!!!!!!!!!!!!!!!!!!!!!!
1218!  Nudging
1219!!!!!!!!!!!!!!!!!!!!!!!!
1220      d_t_nudge(:) = 0.
1221      d_q_nudge(:,:) = 0.
1222      d_u_nudge(:) = 0.
1223      d_v_nudge(:) = 0.
1224      if (nudge(inudge_RHT)) then
1225        call nudge_RHT(timestep,plev,play,t_targ,rh_targ,temp,q(:,1),     &
1226    &                  d_t_nudge,d_q_nudge(:,1))
1227      endif
1228      if (nudge(inudge_UV)) then
1229        call nudge_UV(timestep,plev,play,u_targ,v_targ,u,v,     &
1230    &                  d_u_nudge,d_v_nudge)
1231      endif
1232!
1233       if (forcing_fire) THEN
1234
1235!let ww=if ( alt le 1100 ) then alt*-0.00001 else 0
1236!let wt=if ( alt le 1100 ) then min( -3.75e-5 , -7.5e-8*alt)  else 0
1237!let wq=if ( alt le 1100 ) then max( 1.5e-8 , 3e-11*alt)  else 0
1238           d_t_adv=0.
1239           d_q_adv=0.
1240           teta=temp*(pzero/play)**rkappa
1241           d_t_adv=0.
1242           d_q_adv=0.
1243           do l=2,llm-1
1244              if (zlay(l)<=1100) then
1245                  wwww=-0.00001*zlay(l)
1246                  d_t_adv(l)=-wwww*(teta(l)-teta(l+1))/(zlay(l)-zlay(l+1)) /(pzero/play(l))**rkappa
1247                  d_q_adv(l,1:2)=-wwww*(q(l,1:2)-q(l+1,1:2))/(zlay(l)-zlay(l+1))
1248                  d_t_adv(l)=d_t_adv(l)+min(-3.75e-5 , -7.5e-8*zlay(l))
1249                  d_q_adv(l,1)=d_q_adv(l,1)+max( 1.5e-8 , 3e-11*zlay(l))
1250              endif
1251           enddo
1252
1253        endif
1254
1255!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1256!         call  writefield_phy('dv_age' ,dv_age,llm)
1257!         call  writefield_phy('du_age' ,du_age,llm)
1258!         call  writefield_phy('du_phys' ,du_phys,llm)
1259!         call  writefield_phy('u_tend' ,u,llm)
1260!         call  writefield_phy('u_g' ,ug,llm)
1261!
1262!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1263!! Increment state variables
1264!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1265    IF (flag_inhib_forcing == 0) then ! if tendency of forcings should be added
1266
1267! pour les cas sandu et astex, on reclacule u,v,q,temp et teta dans 1D_nudge_sandu_astex.h
1268! au dessus de 700hpa, on relaxe vers les profils initiaux
1269      if (forcing_sandu .OR. forcing_astex) then
1270      INCLUDE "1D_nudge_sandu_astex.h"
1271      else
1272        u(1:mxcalc)=u(1:mxcalc) + timestep*(                                &
1273     &              du_phys(1:mxcalc)                                       &
1274     &             +du_age(1:mxcalc)+du_adv(1:mxcalc)                       &
1275     &             +d_u_nudge(1:mxcalc) )           
1276        v(1:mxcalc)=v(1:mxcalc) + timestep*(                                 &
1277     &              dv_phys(1:mxcalc)                                       &
1278     &             +dv_age(1:mxcalc)+dv_adv(1:mxcalc)                       &
1279     &             +d_v_nudge(1:mxcalc) )
1280        q(1:mxcalc,:)=q(1:mxcalc,:)+timestep*(                              &
1281     &                dq(1:mxcalc,:)                                        &
1282     &               +d_q_adv(1:mxcalc,:)                                   &
1283     &               +d_q_nudge(1:mxcalc,:) )
1284
1285        if (prt_level.ge.3) then
1286          print *,                                                          &
1287     &    'physiq-> temp(1),dt_phys(1),d_t_adv(1),dt_cooling(1) ',         &
1288     &              temp(1),dt_phys(1),d_t_adv(1),dt_cooling(1)
1289           print* ,'dv_phys=',dv_phys
1290           print* ,'dv_age=',dv_age
1291           print* ,'dv_adv=',dv_adv
1292           print* ,'d_v_nudge=',d_v_nudge
1293           print*, v
1294           print*, vg
1295        endif
1296
1297        temp(1:mxcalc)=temp(1:mxcalc)+timestep*(                            &
1298     &              dt_phys(1:mxcalc)                                       &
1299     &             +d_t_adv(1:mxcalc)                                      &
1300     &             +d_t_nudge(1:mxcalc)                                      &
1301     &             +dt_cooling(1:mxcalc))  ! Taux de chauffage ou refroid.
1302
1303IF (CPPKEY_OUTPUTPHYSSCM) THEN
1304      CALL iophys_ecrit('d_t_adv',klev,'d_t_adv','m/s',d_t_adv)
1305      CALL iophys_ecrit('d_t_nudge',klev,'d_t_nudge','m/s',d_t_nudge)
1306END IF
1307
1308      endif  ! forcing_sandu or forcing_astex
1309
1310        teta=temp*(pzero/play)**rkappa
1311!
1312!---------------------------------------------------------------------
1313!   Nudge soil temperature if requested
1314!---------------------------------------------------------------------
1315
1316      IF (nudge_tsoil .AND. .NOT. lastcall) THEN
1317       ftsoil(1,isoil_nudge,:) = ftsoil(1,isoil_nudge,:)                     &
1318     &  -timestep/tau_soil_nudge*(ftsoil(1,isoil_nudge,:)-Tsoil_nudge)
1319      ENDIF
1320
1321!---------------------------------------------------------------------
1322!   Add large-scale tendencies (advection, etc) :
1323!---------------------------------------------------------------------
1324
1325!cc nrlmd
1326!cc        tmpvar=teta
1327!cc        call advect_vert(llm,omega,timestep,tmpvar,plev)
1328!cc
1329!cc        teta(1:mxcalc)=tmpvar(1:mxcalc)
1330!cc        tmpvar(:)=q(:,1)
1331!cc        call advect_vert(llm,omega,timestep,tmpvar,plev)
1332!cc        q(1:mxcalc,1)=tmpvar(1:mxcalc)
1333!cc        tmpvar(:)=q(:,2)
1334!cc        call advect_vert(llm,omega,timestep,tmpvar,plev)
1335!cc        q(1:mxcalc,2)=tmpvar(1:mxcalc)
1336
1337   END IF ! end if tendency of tendency should be added
1338
1339!---------------------------------------------------------------------
1340!   Air temperature :
1341!---------------------------------------------------------------------       
1342        if (lastcall) then
1343          print*,'Pas de temps final ',it
1344          call ju2ymds(daytime, an, mois, jour, heure)
1345          print*,'a la date : a m j h',an, mois, jour ,heure/3600.
1346        endif
1347
1348!  incremente day time
1349!        print*,'daytime bef',daytime,1./day_step
1350        daytime = daytime+1./day_step
1351!Al1dbg
1352        day = int(daytime+0.1/day_step)
1353!        time = max(daytime-day,0.0)
1354!Al1&jyg: correction de bug
1355!cc        time = real(mod(it,day_step))/day_step
1356        time = time_ini/24.+real(mod(it,day_step))/day_step
1357!        print*,'daytime nxt time',daytime,time
1358        it=it+1
1359
1360      enddo
1361
1362!Al1
1363      if (ecrit_slab_oc.ne.-1) close(97)
1364
1365!Al1 Call to 1D equivalent of dynredem (an,mois,jour,heure ?)
1366! -------------------------------------
1367       call dyn1dredem("restart1dyn.nc",                                    &
1368     &              plev,play,phi,phis,presnivs,                            &
1369     &              u,v,temp,q,omega2)
1370
1371        CALL abort_gcm ('lmdz1d   ','The End  ',0)
1372
1373        END SUBROUTINE old_lmdz1d
1374
1375        INCLUDE "old_1DUTILS_read_interp.h"
Note: See TracBrowser for help on using the repository browser.