subroutine subbasin_read_climate(humi, mb, ra, subp, tmn, tmx, tx)
!**** PURPOSE: this subroutine reads climate data
! & hydrological data from runoff.dat
!**** CALLED IN: MAIN
!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
! PARAMETERS & VARIABLES
!
! >>>>> COMMON PARAMETERS & VARIABLES
! daylen(j) = day length in subbasin
! humi(j) = air humidity in the subbasin, %
! ida = current day in the year (Julian day)
! mb = number of subbasins
!block pit = parameter for estimation of the day length
! precip = precipitation in the current subbasin, mm
! ra(j) = radiation, J/cm^2
! subp(j) = daily precipitation in the subbasin, mm
! tmn(j) = daily min temp in the subbasin, degree C
! tmx(j) = daily max temp in the subbasin, degree C
! tx(j) = daily aver temp in the subbasin, degree C
! ylc(j) = cos(lat()/clt), lat() - latitude, clt=57.296,
! used to calc rmx in evap
! yls(j) = sin(lat()/clt), lat() - latitude, clt=57.296,
! used to calc rmx in evap
! >>>>>
! >>>>> STATIC PARAMETERS
! ch = parameter for estim. day length
! h = parameter for estim. day length
! id = day
! iiyr = year
! imn = month
! k = count parameter
! sd = parameter for estim. day length
! xi = day (real(dp) number)
! >>>>>
!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
use input, only : read_real_column
real(dp), dimension(:), intent(inout) :: humi
integer, intent(inout) :: mb
real(dp), dimension(:), intent(inout) :: ra
real(dp), dimension(:), intent(inout) :: subp
real(dp), dimension(:), intent(inout) :: tmn
real(dp), dimension(:), intent(inout) :: tmx
real(dp), dimension(:), intent(inout) :: tx
integer k, fid
real(dp), dimension(mb) :: mx, mn
!**** READ CLIMATE DATA & MEASURED DISCHARGE (current day)
fid = subbasin_climate_file_id
call read_real_column(fid, array=tx, index=tmean_column_ix) ! no skip
call read_real_column(fid, array=tmn, index=tmin_column_ix, skip=-mb)
call read_real_column(fid, array=tmx, index=tmax_column_ix, skip=-mb)
call read_real_column(fid, array=subp, index=precipitation_column_ix, skip=-mb)
if (radiation_column_ix > 0) then
call read_real_column(fid, array=ra, index=radiation_column_ix, skip=-mb)
else
ra = 1.
end if
if (humidity_column_ix > 0) then
call read_real_column(fid, array=humi, index=humidity_column_ix, skip=-mb)
else
humi = - 999.9
end if
! In order to avoid errors if Tmax < Tmin the following conversion is done
do k = 1, mb
mx(k) = max(tmx(k), tmn(k))
mn(k) = min(tmx(k), tmn(k))
tmx(k) = mx(k)
tmn(k) = mn(k)
end do
end subroutine subbasin_read_climate