Wavelength distribution calculations from actual vs potential solar radiation

RADIN4 is a radiation subroutine that is called ONLY if the hourly input information does not contain all necessary radiation flux values for visible light, NIR and thermal radiation separately. It fills in the values with estimates. In all cases that RADIN4 is called, the hourly input variable RADTOP(2,IHR) contains the measured values of actual total solar radiation (otherwise this variable contains the hourly actual total NIR radiation).
View definitions of variables used in this subroutine:

1) An estimate for the amount of atmosphere that solar radiation
has to pass before it hits the earth surface, AIRMAS, is
calculated. AIRMAS is a function of the cosine of the solar
zenith angle, which determines the length of the pathway and
is corrected for the curvature of the atmosphere and the
refraction of light.
2) The potential direct beam radiation at the earth's surface is
calculated in a Beer's law relationship with the following assumptions:
600 W/m2 of ingoing visible light with an extinction coefficient of 0.160
720 W/m2 of ingoing NIR with an extinction coefficient of 0.050.
From the potential direct beam radiation of the NIR, a term
WATABS is subtracted. WATABS is an estimate for the amount of
NIR solar radiation that is absorbed by atmospheric water. The
estimate is based on an empirical equation, as a function of
the cosine of the solar zenith angle.
3) The amount of diffuse radiation is calculated from an
estimation of the percentage of intercepted radiation that is
scattered downwards. This percentage is assumed to be in a
constant relation to the cosine of the solar zenith angle.
For the visible wavelengths a fraction of 0.4*cos(ZENANG) is
assumed and for NIR the fraction is 0.54*cos(ZENANG).
With this information the potential total visible radiation
and NIR (POTVIS and POTNIR) can be calculated.
4) The ratio of total actual solar radiation and the potential
solar radiation, RATIO, can now be calculated and, assuming
that the wavelength distribution remains the same for the
potential and the actual radiation, the contribution of
visible wavelengths in the total actual radiation can be
estimated (RADABV).
5) Alternatively, instead of calculating RATIO for each hour, a
fixed input value RATIOD can be assigned to RATIO (index IPOT=1!)
and RADABV for visible light and NIR calculated from this value.
7) Finally, the fraction of direct beam radiation in the total
radiation for the visible light and NIR is calculated for
potential radiation (FB1 and FB2), as well as for the actual
radiation ( FBEAM1(1,IHR) and FBEAM1(2,IHR)) using an
empirical equation that is a function of FB1 and FB2, and
RATIO.