71 character(len = *),
intent(in) :: filename
73 character(len = 10) :: dummy
77 integer(i4) :: ii, jj, kk
79 integer(i4) :: nr, nh, max_i
83 real(dp) :: cly, snd, bd
87 integer(i4) :: maxnumberhorizons
89 integer(i4) :: minnumbertillhorizons, maxnumbertillhorizons
97 call check_path_isfile(path = filename, raise=.true.)
98 open(
usoil_database, file = filename, status =
'old', iostat = ios)
118 do while (.NOT. (ios .ne. 0))
119 read(
usoil_database, *, iostat = ios) ii, jj, up, down, cly, snd, bd
122 if(up .ge. down)
then
123 call error_message(
'read_soil_LUT: ERROR occurred: Mixed horizon depths in soil type', &
124 num2str(ii,
'(I3)'),
' and horizon no.', num2str(jj,
'(I3)'))
126 if(cly .lt. 0.0_dp .OR. cly .gt. 100.0_dp .OR. &
127 snd .lt. 0.0_dp .OR. snd .gt. 100.0_dp .OR. &
128 bd .lt. 0.0_dp .OR. bd .gt. 5.0_dp)
then
129 call error_message(
'read_soil_LUT: ERROR occurred: Inappropriate soil properties in soil type', &
130 num2str(ii,
'(I3)'),
' and horizon no.', num2str(jj,
'(I3)'))
134 if ( ii >
size(
soildb%Id) )
call error_message( &
135 "ERROR: nSoil_Types (", num2str(
size(
soildb%Id)), &
136 ") in soil_classdefinition.txt seems to be to low! Tried to read: ", num2str(ii) &
140 if( anint(down, dp) .gt.
soildb%RZdepth(ii) )
soildb%RZdepth(ii) = anint(down, dp)
143 max_i = max(max_i, ii)
147 if ( max_i <
nsoiltypes )
call error_message( &
148 "ERROR: nSoil_Types (", num2str(
size(
soildb%Id)), &
149 ") in soil_classdefinition.txt seems to be to high! Highest read value: ", num2str(max_i) &
153 dmin = minval(
soildb%RZdepth(:),
soildb%RZdepth(:) .gt. 0.0_dp)
157 call error_message(
'read_soil_LUT: ERROR occurred: ', raise=.false.)
158 call error_message(
' Tillage depth is greater than overall minimum total soil depth ', raise=.false.)
159 call error_message(
' So tillage depth should be at least', num2str(dmin,
'(F7.2)'), raise=.false.)
160 call error_message(
' Please adjust!')
177 soildb%nTillHorizons(jj) = nh
181 maxnumberhorizons = maxval(
soildb%nHorizons(:))
201 minnumbertillhorizons = minval(
soildb%nTillHorizons(:))
202 maxnumbertillhorizons = maxval(
soildb%nTillHorizons(:))
205 allocate(
soildb%thetaS(
nsoiltypes, minnumbertillhorizons + 1 : maxnumberhorizons))
208 allocate(
soildb%thetaFC(
nsoiltypes, minnumbertillhorizons + 1 : maxnumberhorizons))
211 allocate(
soildb%thetaPW(
nsoiltypes, minnumbertillhorizons + 1 : maxnumberhorizons))
241 if(cly .lt. 1.0_dp) cly = 1.0_dp
242 if(snd .lt. 1.0_dp) snd = 1.0_dp
245 if((cly + snd) .gt. 100.0_dp)
then
246 cly = cly / (cly + snd)
247 snd = snd / (cly + snd)
253 soildb%UD(jj, nh) = anint(up, dp)
266 if(kk .eq. 1_i4) nh = nh + 1_i4
268 soildb%UD(jj, nh) = anint(up, dp)
269 soildb%LD(jj, nh) = anint(down, dp)
276 if(nh .gt.
soildb%nHorizons(jj))
then
277 call error_message(
'read_soil_LUT: ERROR occurred: ', raise=.false.)
278 call error_message(
' There is something wrong in allocating horizons in soil data base.', raise=.false.)
279 call error_message(
' Please check in code !')
283 if(nh .eq.
soildb%nHorizons(jj)) kk = 0_i4
291 allocate(
soildb%RZdepth(1))
294 allocate(
soildb%depth(1, 1))
295 allocate(
soildb%thetaS_till(1, 1, 1))
296 allocate(
soildb%thetaS(1, 1))
297 allocate(
soildb%thetaFC_till(1, 1, 1))
298 allocate(
soildb%thetaFC(1, 1))
299 allocate(
soildb%thetaPW_till(1, 1, 1))
300 allocate(
soildb%thetaPW(1, 1))
301 allocate(
soildb%Db(1, 1, 1))
302 allocate(
soildb%Ks(1, 1, 1))
307 call check_path_isfile(path = filename, raise=.true.)
308 open(
usoil_database, file = filename, status =
'old', action =
'read')
321 if ( ios /= 0 )
call error_message( &
322 "ERROR: nSoil_Types (", num2str(
nsoiltypes),
") in soil_classdefinition_iFlag_soilDB_1.txt ", &
323 "seems to be higher than available soil types!" &
326 if(cly .lt. 1.0_dp) cly = 1.0_dp
327 if(snd .lt. 1.0_dp) snd = 1.0_dp
340 allocate(
soildb%nHorizons(1))
341 allocate(
soildb%nTillHorizons(1))
343 soildb%nTillHorizons(:) = -9
346 soildb%nTillHorizons(1) = kk
351 if(
soildb%nTillHorizons(1) .eq. -9)
then
354 call error_message(
'***ERROR: specification of tillage depths is not confirming', raise=.false.)
355 call error_message(
' with given depths of soil horizons to be modeled.')
358 call message(
'Tillage layers: the tillage horizons are modelled ')
359 call message(
' upto mHM layers: ', trim(num2str(
soildb%nTillHorizons(1))))
363 call error_message(
'***ERROR: iFlag_soilDB option given does not exist. Only 0 and 1 is taken at the moment.')
394 integer(i4) :: ii, jj, kk
398 real(dp) :: dpth_f, dpth_t
400 integer(i4) :: layer_f, layer_t
402 real(dp),
parameter :: small = 0.000001_dp
405 real(dp),
parameter :: soil_daccuracy = 0.5_dp
412 dmin = minval(
soildb%RZdepth(:),
soildb%RZdepth(:) > 0.0_dp)
416 call error_message(
'generate_soil_database: ERROR occurred: ', raise=.false.)
417 call error_message(
' The depth of soil Horizons provided for modelling is not appropriate', raise=.false.)
418 call error_message(
' The global minimum of total soil horizon depth among all soil type is ', num2str(dmin,
'(F7.2)'), raise=.false.)
419 call error_message(
' Adjust your modeling soil horizon depth in this range', raise=.false.)
420 call error_message(
' OR Increase the soil depth in data base for only those soil types', raise=.false.)
421 call error_message(
' whose total depth is smaller than your given modeling depth.')
426 soildb%Wd(:, :, :) = 0.0_dp
449 do kk = 1,
soildb%nHorizons(ii)
450 if(dpth_f .ge.
soildb%UD(ii, kk) .and. dpth_f .le. (
soildb%LD(ii, kk) - soil_daccuracy)) layer_f = kk
451 if(dpth_t .ge.
soildb%UD(ii, kk) .and. dpth_t .le. (
soildb%LD(ii, kk) - soil_daccuracy)) layer_t = kk
455 if(layer_f .le. 0_i4 .or. layer_t .le. 0_i4)
then
456 call error_message(
'generate_soil_database: ERROR occurred: ', raise=.false.)
457 call error_message(
' Horizon depths to model do not lie in database for soil type', num2str(ii,
'(I3)'), raise=.false.)
458 call error_message(
' Please check!')
460 if(layer_f .gt. layer_t)
then
461 call error_message(
'generate_soil_database: ERROR occurred: ', raise=.false.)
462 call error_message(
' Something is wrong in assignment of modeling soil horizons or', raise=.false.)
463 call error_message(
' database of soil type ', num2str(ii,
'(I3)'), raise=.false.)
464 call error_message(
' Please check!')
468 if(layer_f .eq. layer_t)
then
469 soildb%Wd(ii, jj, layer_f) = 1.0_dp
475 soildb%Wd(ii, jj, layer_f) =
soildb%LD(ii, layer_f) - dpth_f
478 soildb%Wd(ii, jj, layer_t) = (dpth_t + soil_daccuracy) -
soildb%UD(ii, layer_t)
481 if(layer_t - layer_f .gt. 1_i4)
then
482 do kk = layer_f + 1, layer_t - 1
488 if(jj .ne. 1_i4)
then
497 if(sum(
soildb%Wd(ii, jj, :),
soildb%Wd(ii, jj, :) .gt. 0.0_dp) .le. 1.0_dp - small .or. &
498 sum(
soildb%Wd(ii, jj, :),
soildb%Wd(ii, jj, :) .gt. 0.0_dp) .ge. 1.0_dp + small)
then
499 call error_message(
'generate_soil_database: ERROR occurred: ', raise=.false.)
500 call error_message(
' Weight assigned for each soil horizons are not correct.', raise=.false.)
501 call error_message(
' Please check!')
512 allocate(
soildb%Wd(1,1,1))
515 call error_message(
'***ERROR: iFlag_soilDB option given does not exist. Only 0 and 1 is taken at the moment.')