Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.

### SunHrs

Makada Dec 23, 2020 08:14 AM

Hi,

I would like to know what i am doing wrong with my code regarding the SunHrs calculation.

With the code below from shortcut i have all day sun being calculated, while sun isnt shining at all.

The PotSlrW is always a 1 or 2 digit number, while the SlrW is often 2 or 3 digit number.

I see a piece of code from other user where the following piece (written fat) of code has been removed.

Then the PotSlrW is showing more realistic values, but im  not sure if that is ok to do...

"PotSlrW=SIN(SunElevation*3.141593/180)*1373"

What is the correct wat to have it working correctly?

``` Scan(12,Sec,10,0) VoltDiff(SlrW,1,mV250,7,True,0,250,1,0) 'Calculate flux density SlrW=SlrW*43.30879		'Calculate solar position
SolarPosition(SolPos(),RTime(),1*3600,51.483172,3.622999,0,BP_mbar,AirTC)
'Calculate potential radiation for time & position (multiply sine of solar elevation angle by solar constant 1373)
PotSlrW=SIN(SunElevation*3.141593/180)*1373
If PotSlrW<0 Then PotSlrW=0
'If the measured value (W/m^2) is greater than 0.4 * the potential solar radiation (W/m^2)
'and the sine of the sun elevation angle (degrees) is great than 0.1 (elevation angle of 6 degrees)
'than it has been sunny for the current scan.
If SlrW>0.4*PotSlrW And SIN(SunElevation)>0.1 Then
'Calculate sun hours for scan time in seconds
SunHrs=1/3600*12
Else
'Set sun hours for scan time in seconds to 0
SunHrs=0
EndIf```

With kind regards.

aks Dec 28, 2020 01:36 PM

Earlier in the program do you have declaration : "Angledegrees" anywhere? This statement essentially converts degrees to radians for you. It should be declared before the begin program statement.

If that is the case then you do not need the degrees to radian conversion in the statement

"PotSlrW=SIN(SunElevation*3.141593/180)*1373"

Makada Dec 28, 2020 01:51 PM

Hi aks,

Yes i have AngleDegrees just before the main scan, is that ok?

With kind regards.

aks Dec 28, 2020 02:24 PM

You can leave that but then remove the potentisl solar radiation should eb calculated as following:

PotSlrW=SIN(SunElevation)*1373"

Alternatively you cn remove the "Angledegrees" but then you will have to modify the following statement

`If SlrW>0.4*PotSlrW And SIN(SunElevation)>0.1 Then to`
`If SlrW>0.4*PotSlrW And SIN(SunElevation*3.141593/180)>0.1 Then`

Makada Dec 29, 2020 08:55 AM

Thanks alot aks.