source: LMDZ6/branches/contrails/libf/phylmd/dyn1d/old_lmdz1d.f90 @ 5877

Last change on this file since 5877 was 5877, checked in by aborella, 30 hours ago

Bugfix for compiling SCM and with ecRad with contrails

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