source: trunk/LMDZ.MARS/libf/phymars/dyn1d/init_testphys1d_mod.F90 @ 3739

Last change on this file since 3739 was 3739, checked in by emillour, 7 weeks ago

Mars PCM:
Code tidying: put routines in modules, remove useless "return" statements, etc.
EM

File size: 33.2 KB
Line 
1MODULE init_testphys1d_mod
2
3implicit none
4
5contains
6
7SUBROUTINE init_testphys1d(start1Dname,startfiname,therestart1D,therestartfi,ngrid,nlayer,odpref,               &
8                           nq,q,time,psurf,u,v,temp,ndt,ptif,pks,dttestphys,zqsat,dq,dqdyn,day0,day,gru,grv,w,  &
9                           play,plev,latitude,longitude,cell_area,atm_wat_profile,atm_wat_tau,q_def_h2o_vap)
10
11use ioipsl_getincom,          only: getin ! To use 'getin'
12use comcstfi_h,               only: pi, rad, omeg, g, mugaz, rcp, r, cpp
13use time_phylmdz_mod,         only: daysec, steps_per_sol, outputs_per_sol, iphysiq
14use planete_h,                only: year_day, periheli, aphelie, peri_day, obliquit, emin_turb, lmixmin
15use surfdat_h,                only: albedodat, z0_default, z0, emissiv, emisice, albedice, iceradius, dtemisice,      &
16                                    zmea, zstd, zsig, zgam, zthe, hmons, summit, base, phisfi, watercaptag, watercap, &
17                                    tsurf, emis, qsurf, perennial_co2ice, ini_surfdat_h_slope_var, end_surfdat_h_slope_var
18use infotrac,                 only: nqtot, tname, nqperes, nqfils
19use read_profile_mod,         only: read_profile
20use iostart,                  only: open_startphy, get_var, close_startphy
21use physics_distribution_mod, only: init_physics_distribution
22use comsoil_h,                only: volcapa, nsoilmx, inertiesoil, inertiedat, layer, mlayer, flux_geo, tsoil, &
23                                    adsorption_soil, qsoil, igcm_h2o_ice_soil, porosity_reg,                   &
24                                    ini_comsoil_h_slope_var, end_comsoil_h_slope_var, ads_massive_ice
25use comvert_mod,              only: ap, bp, aps, bps, pa, preff, presnivs, pseudoalt, scaleheight
26use dimradmars_mod,           only: tauvis, totcloudfrac, albedo, ini_dimradmars_mod_slope_var, end_dimradmars_mod_slope_var
27use regular_lonlat_mod,       only: init_regular_lonlat
28use mod_interface_dyn_phys,   only: init_interface_dyn_phys
29use geometry_mod,             only: init_geometry, init_geometry_cell_area_for_outputs
30use dimphy,                   only: init_dimphy
31use comgeomfi_h,              only: sinlat, ini_fillgeom
32use slope_mod,                only: theta_sl, psi_sl
33use comslope_mod,             only: def_slope, subslope_dist
34use dust_param_mod,           only: tauscaling
35use tracer_mod,               only: igcm_co2
36use logic_mod,                only: hybrid
37use vertical_layers_mod,      only: init_vertical_layers
38use inichim_newstart_mod,     only: inichim_newstart
39use mod_grid_phy_lmdz,        only: regular_lonlat
40use phys_state_var_init_mod,  only: phys_state_var_init
41use turb_mod,                 only: q2
42use nonoro_gwd_ran_mod,       only: du_nonoro_gwd, dv_nonoro_gwd
43use conf_phys_mod,            only: conf_phys
44use paleoclimate_mod,         only: paleoclimate, ini_paleoclimate_h, end_paleoclimate_h, h2o_ice_depth
45use comslope_mod,             only: nslope, subslope_dist, ini_comslope_h, end_comslope_h
46use co2condens_mod,           only: CO2cond_ps
47use callkeys_mod, only: water, photochem, callthermos
48use call_dayperi_mod, only: call_dayperi
49! Mostly for XIOS outputs:
50use mod_const_mpi,            only: COMM_LMDZ
51
52implicit none
53
54include "dimensions.h"
55
56!=======================================================================
57! Arguments
58!=======================================================================
59integer,      intent(in) :: ngrid, nlayer
60real,         intent(in) :: odpref                     ! DOD reference pressure (Pa)
61character(*), intent(in) :: start1Dname, startfiname   ! Name of starting files for 1D
62logical,      intent(in) :: therestart1D, therestartfi ! Use of starting files for 1D
63
64integer, intent(inout) :: nq
65
66real, dimension(:,:,:), allocatable, intent(out) :: q     ! tracer mixing ratio (e.g. kg/kg)
67real,                                intent(out) :: time  ! time (0<time<1; time=0.5 at noon)
68real,                                intent(out) :: psurf ! Surface pressure
69real, dimension(nlayer),             intent(out) :: u, v  ! zonal, meridional wind
70real, dimension(nlayer),             intent(out) :: temp  ! temperature at the middle of the layers
71integer,                             intent(out) :: ndt
72real,                                intent(out) :: ptif, pks
73real,                                intent(out) :: dttestphys                   ! testphys1d timestep
74real, dimension(:),     allocatable, intent(out) :: zqsat
75real, dimension(:,:,:), allocatable, intent(out) :: dq, dqdyn                    ! Physical and dynamical tandencies
76integer,                             intent(out) :: day0                         ! initial (sol ; =0 at Ls=0) and final date
77real,                                intent(out) :: day                          ! date during the run
78real,                                intent(out) :: gru, grv                     ! prescribed "geostrophic" background wind
79real, dimension(nlayer),             intent(out) :: w                            ! "Dummy wind" in 1D
80real, dimension(nlayer),             intent(out) :: play                         ! Pressure at the middle of the layers (Pa)
81real, dimension(nlayer + 1),         intent(out) :: plev                         ! intermediate pressure levels (pa)
82real, dimension(1),                  intent(out) :: latitude, longitude, cell_area
83real,                                intent(out) :: atm_wat_profile, atm_wat_tau ! Force atmospheric water profiles
84real, dimension(nlayer),             intent(out) :: q_def_h2o_vap                ! User-defined atmospheric water profile
85
86!=======================================================================
87! Local variables
88!=======================================================================
89integer                   :: ierr, iq, j, ilayer, isoil, nlevel, nsoil, flagthermo, flagh2o, nslope_tmp
90integer                   :: dayn ! Final date
91real, dimension(nlayer)   :: zlay ! altitude estimee dans les couches (km)
92real, dimension(0:nlayer) :: tmp1, tmp2
93
94! Dummy variables along "dynamics scalar grid"
95real, dimension(:,:,:,:), allocatable :: qdyn
96real, dimension(:,:),     allocatable :: psdyn
97
98! Use of starting files for 1D
99logical                :: found
100character(30)          :: header
101real, dimension(100)   :: tab_cntrl
102
103! New flag to compute paleo orbital configurations + few variables JN
104logical :: paleomars
105real    :: halfaxe, eccentric, Lsperi
106
107! MVals: isotopes as in the dynamics (CRisi)
108integer                                  :: ipere, ierr0
109character(30), dimension(:), allocatable :: tnom_transp ! transporting fluid short name
110character(80)                            :: line        ! to store a line of text
111logical                                  :: continu
112
113! LL: Possibility to add subsurface ice
114real    :: ice_depth          ! depth of the ice table, ice_depth < 0. means no ice
115real    :: inertieice         ! ice thermal inertia
116integer :: iref
117
118! LL: Subsurface water ice
119real :: rho_H2O_ice           ! Density (kg/m^3) of water ice
120
121!=======================================================================
122! Code
123!=======================================================================
124!------------------------------------------------------
125! Prescribed constants to be set here
126!------------------------------------------------------
127! Mars planetary constants
128! ------------------------
129rad = 3397200.            ! mars radius (m) ~3397200 m
130daysec = 88775.           ! length of a sol (s) ~88775 s
131omeg = 4.*asin(1.)/daysec ! rotation rate (rad.s-1)
132g = 3.72                  ! gravity (m.s-2) ~3.72
133mugaz = 43.49             ! atmosphere molar mass (g.mol-1) ~43.49
134rcp = .256793             ! = r/cp ~0.256793
135r = 8.314511*1000./mugaz
136cpp = r/rcp
137year_day = 669            ! length of year (sols) ~668.6
138periheli = 206.66         ! minimum sun-mars distance (Mkm) ~206.66
139aphelie = 249.22          ! maximum sun-mars distance (Mkm) ~249.22
140halfaxe = 227.94          ! demi-grand axe de l'ellipse
141peri_day = 485.           ! perihelion date (sols since N. Spring)
142obliquit = 25.2           ! Obliquity (deg) ~25.2
143eccentric = 0.0934        ! Eccentricity (0.0934)
144Lsperi = 251.             ! Solar longitude of perihelion
145
146! Planetary Boundary Layer and Turbulence parameters
147! --------------------------------------------------
148z0_default = 1.e-2 ! surface roughness (m) ~0.01
149emin_turb = 1.e-6  ! minimal turbulent energy ~1.e-8
150lmixmin = 30       ! mixing length ~100
151
152! Cap properties and surface emissivities
153! ---------------------------------------
154emissiv = 0.95         ! Bare ground emissivity ~.95
155emisice(1) = 0.95      ! Northern cap emissivity
156emisice(2) = 0.95      ! Southern cap emisssivity
157albedice(1) = 0.5      ! Northern cap albedo
158albedice(2) = 0.5      ! Southern cap albedo
159iceradius(1) = 100.e-6 ! mean scat radius of CO2 snow (north)
160iceradius(2) = 100.e-6 ! mean scat radius of CO2 snow (south)
161dtemisice(1) = 2.      ! time scale for snow metamorphism (north)
162dtemisice(2) = 2.      ! time scale for snow metamorphism (south)
163
164! Water ice properties
165! ---------------------------------------
166inertieice = 2100.
167rho_H2O_ice = 920.
168
169! Mesh surface (not a very usefull quantity in 1D)
170! ------------------------------------------------
171cell_area(1) = 1.
172
173! Check if there is a 'traceur.def' file and process it
174! Load tracer names from file 'traceur.def'
175! -----------------------------------------------------
176open(90,file = 'traceur.def',status = 'old',form = 'formatted',iostat = ierr)
177if (ierr /= 0) then
178    write(*,*) 'Cannot find required file "traceur.def"'
179    write(*,*) ' If you want to run with tracers, I need it'
180    write(*,*) ' ... might as well stop here ...'
181    error stop
182else
183    write(*,*) "init_testphys1d: Reading file traceur.def"
184    ! read number of tracers:
185    read(90,*,iostat = ierr) nq
186    nqtot = nq ! set value of nqtot (in infotrac module) as nq
187    if (ierr /= 0) then
188        write(*,*) "init_testphys1d: error reading number of tracers"
189        write(*,*) "   (first line of traceur.def) "
190        error stop
191    endif
192    if (nq < 1) then
193        write(*,*) "init_testphys1d: error number of tracers"
194        write(*,*) "is nq=",nq," but must be >=1!"
195        error stop
196    endif
197endif
198
199! Allocate arrays
200allocate(tname(nq),q(1,nlayer,nq),zqsat(nlayer))
201allocate(dq(1,nlayer,nq),dqdyn(1,nlayer,nq),tnom_transp(nq))
202
203! Read tracer names from file traceur.def
204do iq = 1,nq
205    read(90,'(80a)',iostat = ierr) line ! store the line from traceur.def
206    if (ierr /= 0) then
207        error stop 'init_testphys1d: error reading tracer names...'
208    endif
209    ! if format is tnom_0, tnom_transp (isotopes)
210    read(line,*,iostat = ierr0) tname(iq),tnom_transp(iq)
211    if (ierr0 /= 0) then
212        read(line,*) tname(iq)
213        tnom_transp(iq) = 'air'
214    endif
215enddo
216close(90)
217
218! Isotopes: as in the 3D case we have to determine father/son relations for isotopes and carrying fluid
219allocate(nqfils(nqtot))
220nqperes = 0
221nqfils = 0
222do iq = 1,nqtot
223    if (tnom_transp(iq) == 'air') then
224        ! ceci est un traceur père
225        write(*,*) 'Le traceur',iq,', appele ',trim(tname(iq)),', est un pere'
226        nqperes = nqperes + 1
227    else !if (tnom_transp(iq) == 'air') then
228        ! ceci est un fils. Qui est son père?
229        write(*,*) 'Le traceur',iq,', appele ',trim(tname(iq)),', est un fils'
230        continu = .true.
231        ipere = 1
232        do while (continu)
233            if (tnom_transp(iq) == tname(ipere)) then
234                ! Son père est ipere
235                write(*,*) 'Le traceur',iq,'appele ',trim(tname(iq)),' est le fils de ',ipere,'appele ',trim(tname(ipere))
236                nqfils(ipere) = nqfils(ipere) + 1
237                continu = .false.
238            else !if (tnom_transp(iq) == tnom_0(ipere)) then
239                ipere = ipere + 1
240                if (ipere > nqtot) then
241                    write(*,*) 'Le traceur',iq,'appele ',trim(tname(iq)),', est orpelin.'
242                    call abort_gcm('infotrac_init','Un traceur est orphelin',1)
243                endif !if (ipere > nqtot) then
244            endif !if (tnom_transp(iq) == tnom_0(ipere)) then
245        enddo !do while (continu)
246    endif !if (tnom_transp(iq) == 'air') then
247enddo !do iq=1,nqtot
248write(*,*) 'nqperes=',nqperes
249write(*,*) 'nqfils=',nqfils
250
251#ifdef CPP_XIOS
252    call init_physics_distribution(regular_lonlat,4,1,1,1,nlayer,COMM_LMDZ)
253#else
254    call init_physics_distribution(regular_lonlat,4,1,1,1,nlayer,1)
255#endif
256
257! Date and local time at beginning of run
258! ---------------------------------------
259if (.not. therestartfi) then
260    ! Date (in sols since spring solstice) at beginning of run
261    day0 = 0 ! default value for day0
262    write(*,*) 'Initial date (in martian sols; =0 at Ls=0)?'
263    call getin("day0",day0)
264    day = float(day0)
265    write(*,*) " day0 = ",day0
266    ! Local time at beginning of run
267    time = 0 ! default value for time
268    write(*,*)'Initial local time (in hours, between 0 and 24)?'
269    call getin("time",time)
270    write(*,*)" time = ",time
271    time = time/24. ! convert time (hours) to fraction of sol
272else
273    call open_startphy(trim(startfiname))
274    call get_var("controle",tab_cntrl,found)
275    if (.not. found) then
276        call abort_physic("open_startphy","tabfi: Failed reading <controle> array",1)
277    else
278        write(*,*)'tabfi: tab_cntrl',tab_cntrl
279    endif
280    day0 = tab_cntrl(3)
281    day = float(day0)
282
283    call get_var("Time",time,found)
284    call close_startphy
285endif !(.not. therestartfi)
286
287! Discretization (Definition of grid and time steps)
288! --------------------------------------------------
289nlevel = nlayer + 1
290nsoil = nsoilmx
291
292steps_per_sol = 48 ! Default value for day_step (old name for steps_per_sol)
293write(*,*)'Number of time steps per sol?'
294call getin("day_step",steps_per_sol)
295write(*,*) " steps_per_sol (aka day_step) = ",steps_per_sol
296
297outputs_per_sol = steps_per_sol ! Default value for outputs_per_sol
298
299ndt = 10 ! Default value for ndt
300write(*,*)'Number of sols to run?'
301call getin("ndt",ndt)
302write(*,*) " ndt = ",ndt
303
304dayn = day0 + ndt
305ndt = ndt*steps_per_sol
306dttestphys = daysec/steps_per_sol
307
308! Imposed surface pressure
309! ------------------------
310psurf = 610. ! Default value for psurf
311write(*,*) 'Surface pressure (Pa)?'
312if (.not. therestart1D) then
313    call getin("psurf",psurf)
314else
315    open(3,file = trim(start1Dname),status = "old",action = "read")
316    read(3,*) header, psurf
317endif
318write(*,*) " psurf = ",psurf
319
320! Coefficient to control the surface pressure change
321! To be defined in "callphys.def" so that the PEM can read it asa well
322! If CO2cond_ps = 0, surface pressure is kept constant; If CO2cond_ps = 1, surface pressure varies normally
323! CO2cond_ps = 300*400/144.37e6 = 8.31e-4 (ratio of polar cap surface over planetary surface) is a typical value for tests
324! --------------------------------------------------------------------
325CO2cond_ps = 1. ! Default value
326write(*,*) 'Coefficient to control the surface pressure change?'
327call getin("CO2cond_ps",CO2cond_ps)
328if (CO2cond_ps < 0. .or. CO2cond_ps > 1.) then
329    write(*,*) 'Value for ''CO2cond_ps'' is not between 0 and 1.'
330    error stop 'Please, specify a correct value!'
331endif
332
333! Reference pressures
334pa = 20.     ! Transition pressure (for hybrid coord.)
335preff = 610. ! Reference surface pressure
336
337! Aerosol properties
338! ------------------
339tauvis = 0.2 ! Default value for tauvis (dust opacity)
340write(*,'("Reference dust opacity at ",f4.0," Pa?")') odpref
341call getin("tauvis",tauvis)
342write(*,*) " tauvis =",tauvis
343
344! Orbital parameters
345! ------------------
346if (.not. therestartfi) then
347    paleomars = .false. ! Default: no water ice reservoir
348    call getin("paleomars",paleomars)
349    write(*,*) "paleomars=", paleomars
350    if (paleomars) then
351        write(*,*) "Orbital parameters taken from callphys.def"
352
353        write(*,*)'Obliquity?'
354        call getin("obliquit",obliquit)
355        write(*,*) " obliquit =",obliquit
356
357        write(*,*) 'Eccentricity (0<e<1)?'
358        call getin('eccentric',eccentric)
359        write(*,*)"eccentric =",eccentric
360        if (eccentric < 0. .or. eccentric > 1.) then
361            write(*,*) 'Value for ''eccentric'' is not between 0 and 1.'
362            error stop 'Please, specify a correct value!'
363        endif
364
365        call getin('Lsperi',Lsperi)
366        write(*,*) 'Solar longitude of perihelion (0<Ls<360)?'
367        write(*,*)"Lsperi =",Lsperi
368        if (eccentric < 0. .or. eccentric > 360.) then
369            write(*,*) 'Value for ''Lsperi'' is not between 0 and 360.'
370            error stop 'Please, specify a correct value!'
371        endif
372       
373        Lsperi = Lsperi*pi/180. ! Convert to rad for peri_day
374        periheli = halfaxe*(1. - eccentric)
375        aphelie = halfaxe*(1. + eccentric)
376        call call_dayperi(Lsperi,eccentric,peri_day,year_day)
377        write(*,*) "Corresponding orbital params for PCM"
378        write(*,*) "   periheli =",periheli
379        write(*,*) "   aphelie  =",aphelie
380        write(*,*) "   peri_day =",peri_day
381    else
382        write(*,*) "Default present-day orbital parameters"
383     endif
384else
385    write(*,*) "Orbital parameters taken from startfi.nc"
386endif !(.not. therestartfi)
387
388! Latitude/longitude
389! ------------------
390latitude = 0. ! default value for latitude
391write(*,*) 'Latitude (in degrees)?'
392call getin("latitude",latitude(1))
393write(*,*) " latitude =",latitude
394latitude = latitude*pi/180.
395longitude = 0.
396longitude = longitude*pi/180.
397
398! Some initializations (some of which have already been done above!)
399! and loads parameters set in callphys.def and allocates some arrays
400! Mars possible matter with dttestphys in input and include!!!
401! Initializations below should mimick what is done in iniphysiq for 3D GCM
402call init_interface_dyn_phys
403call init_regular_lonlat(1,1,longitude,latitude,(/0.,0./),(/0.,0./))
404call init_geometry(1,longitude,latitude,(/0.,0.,0.,0./),(/0.,0.,0.,0./),cell_area,[1])
405call init_geometry_cell_area_for_outputs(1,cell_area)
406! Ehouarn: init_vertial_layers called later (because disvert not called yet)
407! call init_vertical_layers(nlayer,preff,scaleheight,ap,bp,aps,bps,presnivs,pseudoalt)
408call init_dimphy(1,nlayer) ! Initialize dimphy module
409call phys_state_var_init(1,llm,nq,tname,day0,dayn,time,daysec,dttestphys,rad,g,r,cpp,nqperes,nqfils) ! MVals: variables isotopes
410call ini_fillgeom(1,latitude,longitude,(/1.0/))
411call conf_phys(1,llm,nq)
412call initracer(ngrid,nq,qsurf)
413
414! In 1D model physics are called every time step
415! ovverride iphysiq value that has been set by conf_phys
416if (iphysiq /= 1) then
417    write(*,*) "init_testphys1d: setting iphysiq=1"
418    iphysiq = 1
419endif
420
421! Initialize local slope parameters
422! ---------------------------------
423nslope_tmp = nslope
424write(*,*)'Number of slopes?' ! Number of subgrid scale slopes
425call getin("nslope",nslope_tmp)
426write(*,*) " nslope = ", nslope_tmp
427if (.not. therestartfi) then
428    nslope = nslope_tmp
429    call end_comslope_h
430    call ini_comslope_h(1,nslope)
431    select case (nslope)
432        case(1)
433            ! Sub-slopes parameters (minimum/maximun angles)
434            def_slope(1) = -90.
435            def_slope(2) = 90.
436            ! Fraction of subslopes in mesh
437            subslope_dist(1,1) = 1.
438        case(3)
439            ! Sub-slopes parameters (minimum/maximun angles)
440            def_slope(1) = -50.
441            def_slope(2) = -3.
442            def_slope(3) = 3.
443            def_slope(4) = 50.
444            ! Fraction of subslopes in mesh
445            subslope_dist(1,1) = 0.1
446            subslope_dist(1,2) = 0.8
447            subslope_dist(1,3) = 0.1
448        case(5)
449            ! Sub-slopes parameters (minimum/maximun angles)
450            def_slope(1) = -43.
451            def_slope(2) = -9.
452            def_slope(3) = -3.
453            def_slope(4) = 3.
454            def_slope(5) = 9.
455            def_slope(6) = 43.
456            ! Fraction of subslopes in mesh
457            subslope_dist(1,1) = 0.025
458            subslope_dist(1,2) = 0.075
459            subslope_dist(1,3) = 0.8
460            subslope_dist(1,4) = 0.075
461            subslope_dist(1,5) = 0.025
462        case(7)
463            ! Sub-slopes parameters (minimum/maximun angles)
464            def_slope(1) = -43.
465            def_slope(2) = -19.
466            def_slope(3) = -9.
467            def_slope(4) = -3.
468            def_slope(5) = 3.
469            def_slope(6) = 9.
470            def_slope(7) = 19.
471            def_slope(8) = 43.
472            ! Fraction of subslopes in mesh
473            subslope_dist(1,1) = 0.01
474            subslope_dist(1,2) = 0.02
475            subslope_dist(1,3) = 0.06
476            subslope_dist(1,4) = 0.8
477            subslope_dist(1,5) = 0.06
478            subslope_dist(1,6) = 0.02
479            subslope_dist(1,7) = 0.01
480        case default
481            error stop 'Number of slopes not possible: nslope should be 1, 3, 5 or 7!'
482    end select
483
484    call end_surfdat_h_slope_var
485    call ini_surfdat_h_slope_var(1,nq,nslope)
486    call end_comsoil_h_slope_var
487    call ini_comsoil_h_slope_var(1,nslope)
488    call end_dimradmars_mod_slope_var
489    call ini_dimradmars_mod_slope_var(1,nslope)
490    call end_paleoclimate_h
491    call ini_paleoclimate_h(1,nslope)
492else
493    if (nslope /= nslope_tmp) then
494        error stop 'Number of slopes not compatible between "startfi.nc" and "run.def".'
495    else
496        write(*,*) 'Be careful: subslopes distribution and definition are taken from "startfi.nc" and not initialized by default!'
497    endif
498endif
499
500! Slope inclination angle (deg) 0: horizontal, 90: vertical
501theta_sl = 0. ! default: no inclination
502call getin("slope_inclination",theta_sl)
503
504! Slope orientation (deg)
505! 0 == Northward, 90 == Eastward, 180 == Southward, 270 == Westward
506psi_sl = 0. ! default value
507call getin("slope_orientation",psi_sl)
508
509! Initialize tracers (surface and atmosphere)
510!--------------------------------------------
511write(*,*) "init_testphys1d: initializing tracers"
512if (.not. therestart1D) then
513    call read_profile(nq,nlayer,qsurf(1,:,1),q)
514    do iq = 1,nq
515        qsurf(1,iq,:) = qsurf(1,iq,1)
516    enddo
517else
518    do iq = 1,nq
519        read(3,*) header, (qsurf(1,iq,j), j = 1,size(qsurf,3)), (q(1,ilayer,iq), ilayer = 1,nlayer)
520        if (trim(tname(iq)) /= trim(header)) then
521            write(*,*) 'Tracer names between "traceur.def" and "'//trim(start1Dname)//'" do not match!'
522            write(*,*) 'Please, write the tracer names in the same order for both files.'
523            error stop
524        endif
525    enddo
526endif
527
528! Initialize albedo / soil thermal inertia
529! ----------------------------------------
530if (.not. therestartfi) then
531    albedodat(1) = 0.2 ! default value for albedodat
532    write(*,*)'Albedo of bare ground?'
533    call getin("albedo",albedodat(1))
534    write(*,*) " albedo = ",albedodat(1)
535    albedo(1,:,:) = albedodat(1)
536
537    inertiedat(1,1) = 400 ! default value for inertiedat
538    write(*,*)'Soil thermal inertia (SI)?'
539    call getin("inertia",inertiedat(1,1))
540    write(*,*) " inertia = ",inertiedat(1,1)
541
542    ice_depth = -1 ! default value: no ice
543    call getin("subsurface_ice_depth",ice_depth)
544    write(*,*) " subsurface_ice_depth = ",ice_depth
545    h2o_ice_depth(:,:) = ice_depth
546    z0(1) = z0_default ! default value for roughness
547    write(*,*) 'Surface roughness length z0 (m)?'
548    call getin("z0",z0(1))
549    write(*,*) " z0 = ",z0(1)
550endif !(.not. therestartfi)
551
552! For the gravity wave scheme
553! ---------------------------
554zmea(1) = 0.
555zstd(1) = 0.
556zsig(1) = 0.
557zgam(1) = 0.
558zthe(1) = 0.
559
560! For the non-orographic gravity waves scheme
561du_nonoro_gwd(1,:) = 0
562dv_nonoro_gwd(1,:) = 0
563
564! For the slope wind scheme
565! -------------------------
566hmons(1) = 0.
567write(*,*)'hmons is initialized to ',hmons(1)
568summit(1) = 0.
569write(*,*)'summit is initialized to ',summit(1)
570base(1) = 0.
571
572! Default values initializing the coefficients calculated later
573! -------------------------------------------------------------
574tauscaling(1) = 1.   ! calculated in aeropacity_mod.F
575totcloudfrac(1) = 1. ! calculated in watercloud_mod.F
576
577! Specific initializations for "physiq"
578! -------------------------------------
579! surface geopotential is not used (or useful) since in 1D
580! everything is controled by surface pressure
581phisfi(1) = 0.
582
583! Initialization to take into account prescribed winds
584! ----------------------------------------------------
585ptif = 2.*omeg*sinlat(1)
586
587! Geostrophic wind
588gru = 10. ! default value for gru
589write(*,*)'zonal eastward component of the geostrophic wind (m/s)?'
590call getin("u",gru)
591write(*,*) " u = ",gru
592grv = 0. !default value for grv
593write(*,*)'meridional northward component of the geostrophic wind (m/s)?'
594call getin("v",grv)
595write(*,*) " v = ",grv
596
597! Initialize winds for first time step
598!-------------------------------------
599if (.not. therestart1D) then
600    u = gru
601    v = grv
602else
603    read(3,*) header, (u(ilayer), ilayer = 1,nlayer)
604    read(3,*) header, (v(ilayer), ilayer = 1,nlayer)
605endif
606w = 0. ! default: no vertical wind
607
608! Initialize turbulent kinetic energy
609!------------------------------------
610q2 = 0.
611
612! CO2 ice on the surface
613! ----------------------
614if (.not. therestartfi) then
615    qsurf(1,igcm_co2,:) = 0. ! default value for co2ice
616    write(*,*)'Initial CO2 ice on the surface (kg.m-2)'
617    call getin("co2ice",qsurf(1,igcm_co2,1))
618    qsurf(1,igcm_co2,:) = qsurf(1,igcm_co2,1)
619    write(*,*) " co2ice = ",qsurf(1,igcm_co2,1)
620endif !(.not. therestartfi)
621
622! Emissivity
623! ----------
624if (.not. therestartfi) then
625    emis = emissiv
626    if (qsurf(1,igcm_co2,1) == 1.) then
627        emis = emisice(1) ! northern hemisphere
628        if (latitude(1) < 0) emis = emisice(2) ! southern hemisphere
629    endif
630endif !(.not. therestartfi)
631
632! Compute pressures and altitudes of atmospheric levels
633! -----------------------------------------------------
634! Vertical Coordinates
635! """"""""""""""""""""
636hybrid = .true.
637write(*,*)'Hybrid coordinates?'
638call getin("hybrid",hybrid)
639write(*,*) " hybrid = ", hybrid
640
641call disvert_noterre
642! Now that disvert has been called, initialize module vertical_layers_mod
643call init_vertical_layers(nlayer,preff,scaleheight,ap,bp,aps,bps,presnivs,pseudoalt)
644
645plev = ap + psurf*bp
646play = aps + psurf*bps
647zlay = -200.*r*log(play/plev(1))/g
648
649! Initialize temperature profile
650! ------------------------------
651pks = psurf**rcp
652
653! Altitude in km in profile: divide zlay by 1000
654tmp1(0) = 0.
655tmp1(1:) = zlay/1000.
656
657call profile(nlayer + 1,tmp1,tmp2)
658
659if (.not. therestart1D) then
660    tsurf = tmp2(0)
661    temp = tmp2(1:)
662else
663    read(3,*) header, (tsurf(1,j), j = 1,size(tsurf,2)), (temp(ilayer), ilayer = 1,nlayer)
664    close(3)
665endif
666
667! Initialize soil properties, temperature and content
668! ------------------------------------------
669volcapa = 1.e6 ! volumetric heat capacity
670
671if (.not. therestartfi) qsoil = 0.
672
673if (.not. therestartfi) then
674    ! Initialize depths
675    ! -----------------
676    do isoil = 0,nsoil - 1
677       mlayer(isoil) = 2.e-4*(1 + isoil**2.9*(1 - exp(-real(isoil)/20.))) ! mid layer depth
678    enddo
679    do isoil = 1,nsoil - 1
680       layer(isoil) = (mlayer(isoil) + mlayer(isoil - 1))/2
681    enddo
682    layer(nsoil) = 2*mlayer(nsoil - 1) - mlayer(nsoil - 2)
683
684    ! Creating the new soil inertia table if there is subsurface ice:
685    if (ice_depth > 0) then
686        iref = 1 ! ice/regolith boundary index
687        if (ice_depth < layer(1)) then
688            inertiedat(1,1) = sqrt(layer(1)/((ice_depth/inertiedat(1,1)**2) + ((layer(1) - ice_depth)/inertieice**2)))
689            inertiedat(1,2:) = inertieice
690            if(adsorption_soil) then
691            ! add subsurface ice in qsoil if one runs with adsorption
692               if(ads_massive_ice) then
693                   qsoil(1,1,igcm_h2o_ice_soil,:) = (ice_depth-layer(2))/(layer(1) - layer(2))*rho_H2O_ice ! assume no porosity in the ice
694                   qsoil(1,2:,igcm_h2o_ice_soil,:) = rho_H2O_ice
695               else
696                   qsoil(1,1,igcm_h2o_ice_soil,:) = (ice_depth-layer(2))/(layer(1) - layer(2))*porosity_reg*rho_H2O_ice
697                   qsoil(1,2:,igcm_h2o_ice_soil,:) = porosity_reg*rho_H2O_ice
698               endif           
699            endif
700        else ! searching for the ice/regolith boundary:
701            do isoil = 1,nsoil
702                if ((ice_depth >= layer(isoil)) .and. (ice_depth < layer(isoil + 1))) then
703                    iref = isoil + 1
704                    exit
705                endif
706            enddo
707            ! We then change the soil inertia table:
708            inertiedat(1,:iref - 1) = inertiedat(1,1)
709            ! We compute the transition in layer(iref)
710            inertiedat(1,iref) =  sqrt((layer(iref) - layer(iref - 1))/(((ice_depth - layer(iref - 1))/inertiedat(1,1)**2) + ((layer(iref) - ice_depth)/inertieice**2)))
711            ! Finally, we compute the underlying ice:
712            inertiedat(1,iref + 1:) = inertieice
713           
714            if(adsorption_soil) then
715            ! add subsurface ice in qsoil if one runs with adsorption
716                qsoil(1,:iref - 1,igcm_h2o_ice_soil,:) = 0.
717                if(ads_massive_ice) then
718                   qsoil(1,iref+1:,igcm_h2o_ice_soil,:) = rho_H2O_ice
719                   qsoil(1,iref,igcm_h2o_ice_soil,:) = (ice_depth-layer(iref))/(layer(iref-1) - layer(iref))*rho_H2O_ice
720                else
721                   qsoil(1,iref+1:,igcm_h2o_ice_soil,:) = porosity_reg*rho_H2O_ice
722                   qsoil(1,iref,igcm_h2o_ice_soil,:) = (ice_depth-layer(iref))/(layer(iref-1) - layer(iref))*porosity_reg*rho_H2O_ice
723                endif
724            endif
725        endif ! (ice_depth < layer(1))
726    else ! ice_depth < 0 all is set to surface thermal inertia
727        inertiedat(1,:) = inertiedat(1,1) ! soil thermal inertia
728    endif ! ice_depth > 0
729   
730    do isoil = 1,nsoil
731        inertiesoil(1,isoil,:) = inertiedat(1,isoil)
732        tsoil(1,isoil,:) = tsurf(1,:) ! soil temperature
733    enddo
734endif !(.not. therestartfi)
735
736! Initialize subsurface geothermal flux
737! -------------------------------------
738flux_geo = 0.
739call getin("flux_geo",flux_geo(1,1))
740write(*,*) " flux_geo = ",flux_geo(1,1)
741flux_geo = flux_geo(1,1)
742
743
744! Initialize traceurs
745! -------------------
746if (photochem .or. callthermos) then
747    write(*,*) 'Initializing chemical species'
748    ! flagthermo=0: initialize over all atmospheric layers
749    flagthermo = 0
750    ! check if "h2o_vap" has already been initialized
751    ! (it has been if there is a "profile_h2o_vap" file around)
752    inquire(file = "profile_h2o_vap",exist = found)
753    if (found) then
754        flagh2o = 0 ! 0: do not initialize h2o_vap
755    else
756        flagh2o = 1 ! 1: initialize h2o_vap in inichim_newstart
757    endif
758
759    ! hack to accomodate that inichim_newstart assumes that
760    ! q & psurf arrays are on the dynamics scalar grid
761    allocate(qdyn(2,1,llm,nq),psdyn(2,1))
762    qdyn(1,1,1:llm,1:nq) = q(1,1:llm,1:nq)
763    psdyn(1:2,1) = psurf
764    call inichim_newstart(ngrid,nq,qdyn,qsurf(1,:,1),psdyn,flagh2o,flagthermo)
765    q(1,1:llm,1:nq) = qdyn(1,1,1:llm,1:nq)
766endif
767
768! Check if the surface is a water ice reservoir
769! ---------------------------------------------
770if (.not. therestartfi) watercap(1,:) = 0 ! Initialize watercap
771watercaptag(1) = .false. ! Default: no water ice reservoir
772write(*,*)'Water ice cap on ground?'
773call getin("watercaptag",watercaptag)
774write(*,*) " watercaptag = ",watercaptag
775
776! Initialize perennial_co2ice
777! ---------------------------
778if (.not. therestartfi .and. paleoclimate) perennial_co2ice = 0.
779
780! Check if the atmospheric water profile is specified
781! ---------------------------------------------------
782! Adding an option to force atmospheric water values
783atm_wat_profile = -1. ! Default: free atmospheric water profile
784q_def_h2o_vap = 0. ! Default
785if (water) then
786    write(*,*)'Force atmospheric water vapor profile (mixing ratio in kg/kg)?'
787    call getin('atm_wat_profile',atm_wat_profile)
788    write(*,*) 'atm_wat_profile = ', atm_wat_profile
789    if (abs(atm_wat_profile + 1.) < 1.e-15) then ! if == -1.
790        write(*,*) 'Free atmospheric water vapor profile'
791        write(*,*) 'Total water is conserved in the column'
792    else if (abs(atm_wat_profile) < 1.e-15) then ! if == 0.
793        write(*,*) 'Dry atmospheric water vapor profile'
794    else if (0. < atm_wat_profile .and. atm_wat_profile <= 1.) then ! if 0. <= and <= 1.
795        write(*,*) 'Prescribed uniform atmospheric water vapor profile'
796        write(*,*) 'Unless it reaches saturation (maximal value)'
797    else if (abs(atm_wat_profile + 2.) < 1.e-15) then ! if == -2.
798        write(*,*) 'Prescribed user-defined atmospheric water vapor profile'
799        write(*,*) 'Unless it reaches saturation (maximal value)'
800        open(10,file = 'profile_def_h2o_vap',status = 'old',form = 'formatted',action = 'read',iostat = ierr)
801        if (ierr == 0) then
802            do ilayer = 1,nlayer
803                read(10,*) q_def_h2o_vap(ilayer)
804            enddo
805        else
806            error stop 'File "profile_def_h2o_vap" was not found!'
807        endif
808        close(10)
809    else
810        error stop 'Water vapor profile value is not correct!'
811    endif
812endif
813
814! Check if the atmospheric water profile relaxation is specified
815! --------------------------------------------------------------
816! Adding an option to relax atmospheric water values
817atm_wat_tau = -1. ! Default: no time relaxation
818if (water) then
819    write(*,*) 'Relax atmospheric water vapor profile with time constant (s)?'
820    call getin('atm_wat_tau',atm_wat_tau)
821    write(*,*) 'atm_wat_tau = ', atm_wat_tau
822    if (atm_wat_tau < 0.) then
823        write(*,*) 'Atmospheric water vapor profile is not relaxed (forcing).'
824    else
825        if (0. <= atm_wat_profile .and. atm_wat_profile <= 1. .or. abs(atm_wat_profile + 2.) < 1.e-15) then
826            write(*,*) 'Relaxed atmospheric water vapor profile towards ', atm_wat_profile
827            write(*,*) 'Unless it reaches saturation (maximal value)'
828        else
829            write(*,*) 'Reference atmospheric water vapor profile not known!'
830            error stop 'Please, specify atm_wat_profile'
831        endif
832    endif
833endif
834
835END SUBROUTINE init_testphys1d
836
837END MODULE init_testphys1d_mod
Note: See TracBrowser for help on using the repository browser.