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

Last change on this file since 3095 was 3095, checked in by emillour, 14 months ago

Mars PCM:
Some code tidying:
Made pi in module comcstfi_h a parameter (and not a variable recomputed at
various points by various routines) and added module routine init_comcstfi_h
to cleanly initialize module variables.
Moved iniorbit.F to be a module routine of planete_h since it initializes
(some of ) the module variables it contains.
EM

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