converting daily global radiation into hourly values

I would like to convert daily global radiation into hourly solar radiation. While I do not know the terms, I tried using below equations I found in the papers but I have negative radiation values range between -75 to 100 j/m2/s. Any suggestions are welcome.

# radi(h) = r * radi(daily)


r <- (pi/24) * ( a + b * cos_d (w))* ((cos_d(w) - cos_d(ws)) / (sin_d(ws)-((pi/180) * ws * cos_d(ws))) )

a <- 0.409 + 0.5016 * sin_d(ws - 60)

b <- 0.6609 - 0.4767 * sin_d(ws - 60)

 # W = hour angle of the sun


w <- (360/24) * (h-12.0) # h = time of the day (hour)

ws <- acos_d(-tan_d(phi)*tan_d(sigma))) # ws = sunset hour angle (degree)

phi= 36.20 # phi = location latitude angle

# sigma= declination angle of the sun [degree]


sigma = 23.45 * sin_d (360* ((284+day)/365)) # day=DOY

-

migrated from stackoverflow.comSep 14 '12 at 15:21

This question came from our site for professional and enthusiast programmers.

After testing your equations, it seems to me that all negatives values fall after sunset and before sunrise: wouldn't it be that the equation for r is only meant for daytime hours? In this paper for instance they seem to limit the study from 8am to 4pm. – plannapus Sep 14 '12 at 7:44
w <- (360/24) * (h-12.0) should probably be w <- (360/24) * (12.0-h) since w is zero for solar noon and the morning is positive. But that doesn't really change the negative results. – plannapus Sep 14 '12 at 7:47
Why would like to convert daily global radiation into hourly solar radiation? The answer would help determine the right way to do it. For example, if you want insolation levels on Earth, you need an insolation database, rather than doing it from first principles - weather / climate effects are important. – EnergyNumbers Sep 14 '12 at 19:22

From ?Trig: "Angles are in radians, not degrees (i.e., a right angle is π/2)." You need to convert your angles from degrees to radians, when using the trigonometric functions.
Also cos-1 should probably be acos.
In sin(ws-60) I'm pretty sure 60 is in degree, whereas the result of ws <- acos ... is in radians. – Roland Sep 14 '12 at 9:43