Solar position algorithm
4.5.1. Theoretic background and model
Numerous algorithms are available for the purpose of calculating the solar position. The accuracy and computation time of the available algorithms vary greatly, however. In the present work, the SG2 algorithm of Ph. Blanc and L. Wald (2012) has been implemented. The SG2 algorithm is a numerically significantly optimised version of the SPA algorithm provided by NREL (Reda and Afshin, 2005). The SPA algorithm, in turn, is based on the astronomical algorithms provided by Jean Meeus (1998) in his book first published in 1991. The SPA algorithm, based on Meeus work, has long been the gold standard as Reda and Afshin specify a maximum uncertainty of ±0.0003° for the years ranging from 2000 b.c. to 6000 a.d.
Based on Blanc and Wald’s numerical optimisations, the SG2 algorithm is several orders of magnitude faster than the original SPA algorithm and provides a maximum uncertainty of the solar vector of less than ±0.0025°. This value still exceeds by far the accuracy required for most practical applications, whereas computational performance is crucial for many practical purposes. For this reason, the SG2 algorithm has been implemented here.
4.5.2. Implementation
For the actual implementation in Pascal, the original publication (Blanc and Wald, 2012) and a validated implementation in C and Python provided by PSL university (O.I.E. Mines-ParisTech, 2022) have been used.
The code has been implemented in the library rc_sunpos_sg2. It encapsulates the class TSunposIrradiance containing the following methods:

The key method is the calcSunPos function, which returns the solar angles for a specified date. The function JulianD allows converting standard date and time values into a single numeric Julian-date value (of type double). Apart from the SG2 code, the class also contains functions for irradiance evaluation. These are covered in section 6.2.5.
4.5.3. Testing and validation
The validation has been done with multiple comparisons against free online tools using the SG2 algorithm. In particular, however, the validation example provided in the appendix of the SPA paper (Reda and Afshin, 2005) is used here to demonstrate the validity of the implementation.

The code used to perform the solar position calculation for the given validation parameters in the present implementation is:

Table 4 shows the calculation result of the RadiCal implementation compared to the solar position
stated in the SPA paper. As can be seen, the deviation ranges well below the specified uncertainty.
