subroutine soil_initialise(mb, meap, mstruc, neap, bSubcatch, da, slope_length, stp, ovn, chs, flu, chn, chl, cn2a, cn2b, cn2c, cn2d)
use input, only : input_open_file, input_count_rows, get_config_fid
use output, only : output_register_hydrotope_var
use utilities, only : log_error, random_n
integer, intent(in) :: mb, meap
integer, dimension(:, :, :), intent(in) :: mstruc
integer, intent(inout) :: neap(:)
logical, intent(in) :: bSubcatch
real(dp), intent(in) :: da
real(dp), intent(in) :: slope_length(:)
real(dp), intent(in) :: stp(:)
real(dp), intent(in) :: ovn(mb)
real(dp), intent(in) :: chs(mb)
real(dp), intent(in) :: flu(mb)
real(dp), intent(in) :: chn(mb)
real(dp), intent(in) :: chl(2, mb)
real(dp), dimension(:), intent(in) :: cn2a, cn2b, cn2c, cn2d
integer j
real(dp) ot, ct
read(get_config_fid(), SOIL_PARAMETERS)
if (bSubcatch .AND. icn == 1) call log_error("soil_initialise", &
"Inconsistency in .bsn input file: "// &
"Switch icn is set to 1 and subcatchment calibration is switched ON. "// &
"Either set icn = 0 or deactivate subcatchment calibration.")
if (isc.eq.0) call log_debug("soil_initialise", 'Codes: SC - read, isc =', int=isc)
if (isc.eq.1) call log_debug("soil_initialise", 'Codes: SC - calculated, isc =', int=isc)
if (icn.eq.0) call log_debug("soil_initialise", 'Codes: CN - standard, icn =', int=icn)
if (icn.eq.1) call log_debug("soil_initialise", 'Codes: CN = f(cnum1, cnum3), icn =', int=icn)
surface_runoff_output_id = output_register_hydrotope_var("surface_runoff", .False.)
subsurface_runoff_output_id = output_register_hydrotope_var("subsurface_runoff", .False.)
percolation_output_id = output_register_hydrotope_var("percolation", .False.)
soil_water_index_output_id = output_register_hydrotope_var("soil_water_index", .False.)
soil_input_file_id = input_open_file(soil_input_file)
! **** count number of soils used in simulation (soil.cio)
msdb = input_count_rows(soil_input_file_id, .true.) ! if soil parms read from single soil files then no header
ms = msdb
call soil_allocate(mb, meap)
call soil_read_input(mb, mstruc, neap, cn2a, cn2b, cn2c, cn2d)
!**** COMPUTE TIME OF CONCENTRATION for basins tc()
do j = 1, mb
ot = .0556 * (slope_length(j) * ovn(j)) ** .6 / stp(j) ** .3
ct = .62 * chl(1, j) * chn(j) ** .75 / ((da * flu(j)) ** .125 * chs(j) ** .375)
tc(j) = ot + ct
end do
rn1 = random_n(k7)
end subroutine soil_initialise