FB_CalcSunPosition

FB_CalcSunPosition 1:

Calculation of the position of the sun by means of specifying the date, time, longitude and latitude.

Description

The position of the sun for a given point in time can be calculated according to common methods with a defined accuracy. For applications with moderate requirements, the present block is sufficient. As the basis for this, the SUNAE algorithm was used, which represents a favorable compromise between accuracy and computing effort.

The position of the sun at a fixed observation point is normally determined by specifying two angles. One angle indicates the height above the horizon, where 0° means that the sun is in the horizontal plane of the observation site and 90° means that the sun is directly over the observer's head. The other angle indicates the direction in which the sun is standing. The SUNAE algorithm is used to distinguish whether the observer is standing on the northern hemisphere (longitude > 0 degrees) or on the southern hemisphere (longitude < 0 degrees) of the earth. If the observation point is in the northern hemisphere is, then a value of 0° is assigned for the northern sun direction and it then runs in the clockwise direction around the compass, i.e., 90° is east, 180° is south, 270° is west etc. If the point of observation is in the southern hemisphere, then 0° corresponds to the southern direction and it then runs in the counterclockwise direction, i.e. 90° is east, 180° is north, 270° is west etc.

FB_CalcSunPosition 2:

In specifying the time, the time according to Greenwich Mean Time (GMT) must be given.

The latitude is specified as the distance of a place on the surface of the earth from the equator to the north or to the south in degrees. The latitude can assume a value from 0° (at the equator) to ±90° (at the poles). A positive sign thereby indicates a northern direction and a negative sign a southern direction. The longitude is an angle that can assume values up to ±180° starting from the prime meridian 0° (an artificially determined North-South line). A positive sign indicates a longitude in an eastern direction and a negative sign in a western direction. Examples:

Place

Longitude

Latitude

Sydney, Australia

151,2°

-33,9°

New York, USA

-74,0°

40,7°

London, England

-0,1°

51,5°

Moscow, Russia

37,6°

55,7°

Peking, China

116,3°

39,9°

Dubai, United Arab Emirates

55,3°

25,4°

Rio de Janeiro, Brazil

-43,2°

-22,9°

Hawai, USA

-155,8°

20,2°

Verl, Germany

8,5°

51,9°

If the block FB_CalcSunPosition() returns a negative value for the height of the sun (fSunElevation), then the sun is not visible. This can be used to determine sunrise and sunset.

VAR_INPUT

fDegreeOfLongitude    : LREAL := 8.5;
fDegreeOfLatitude     : LREAL := 51.9;
dtGMT                 : TIMESTRUCT;

fDegreeOfLongitude: Longitude in degrees.

fDegreeofLatitude: Latitude in degrees.

dtGMT: Current time as Greenwich Mean Time (GMT).

VAR_OUTPUT

fSunAzimuth       : LREAL;
fSunElevation     : LREAL;

fSunAzimuth: Direction of the sun (northern hemisphere: 0° north… 90° east… 180° south… 270° west…/southern hemisphere: 0° south… 90° east… 180° north… 270° west…).

fSunElevation: Height of the sun (0° horizontal - 90° vertical).

Sample

PROGRAM MAIN
VAR
  fbCalcSunPosition  : FB_CalcSunPosition;
  fSunAzimuth        : LREAL;
  fSunElevation      : LREAL;
  fbGetSystemTime    : GETSYSTEMTIME;
  fileTime           : T_FILETIME;
END_VAR

fbGetSystemTime(timeLoDW=>fileTime.dwLowDateTime,
        timeHiDW=>fileTime.dwHighDateTime);

fbCalcSunPosition( fDegreeOfLongitude := 8.5,
           fDegreeOfLatitude := 51.9,
           dtGMT := FILETIME_TO_SYSTEMTIME(fileTime));
ffSunAzimuth := fbCalcSunPosition.fSunAzimuth;
fSunElevation := fbCalcSunPosition.fSunElevation;