NREL's Solar and Moon Position Algorithm (SAMPA)
This algorithm calculates the solar and lunar zenith and azimuth angles in the period from the year -2000 to 6000, with uncertainties of +/- 0.0003 degrees for the Sun and +/- 0.003 degrees for the Moon, based on the date, time, and location on Earth. The algorithm can be used for solar eclipse monitoring and estimating the reduction in solar irradiance for many applications, such as smart grid, solar energy, etc. The software has not been tested on a variety of platforms and is not guaranteed to work on yours. It is provided here as a convenience.
This algorithm is available in ANSI C; how to use this algorithm and a description of the variables is included in the
sampa.h header file. Further information on this algorithm is available in the following
NREL technical report:
Reda, I. (2010). Solar Eclipse Monitoring for Solar Energy Applications Using the Solar and Moon Position Algorithms. 35 pp.; NREL Report No. TP-3B0-47681. (927 KB PDF Document)
SAMPA.C
Distributed by the National Renewable Energy LaboratorySolar Radiation Research Laboratory
August 2012
NOTICE |
Copyright © 2012, 2017 Alliance for Sustainable Energy, LLC, All Rights Reserved |
These data were produced by The Alliance for Sustainable Energy LLC under Contract No. DE-AC36-08GO28308 with the Department of Energy. For five years from the date permission to assert copyright was obtained, the Government is granted for itself and others acting on its behalf a nonexclusive, paid-up, irrevocable worldwide license in this data to reproduce, prepare derivative works, and perform publicly and display publicly, by or on behalf of the Government. There is provision for the possible extension of the term of this license. Subsequent to that period or any extension granted, the Government is granted for itself and others acting on its behalf a nonexclusive, paid-up, irrevocable worldwide license in this data to reproduce, prepare derivative works, distribute copies to the public, perform publicly and display publicly, and to permit others to do so. The specific term of the license can be identified by inquiry made to Contractor or DOE. NEITHER THE UNITED STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, OR USEFULNESS OF ANY DATA, APPARATUS, PRODUCT, OR PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY OWNED RIGHTS. |
The software is being provided for internal, noncommercial purposes only and shall not be re-distributed. Please contact Jean Schulte in the NREL Commercialization and Technology Transfer Office for information concerning a commercial license to use the software. |
As a condition of using the software in an application, the developer of the application agrees to reference the use of the software and make this notice readily accessible to any end-user in a Help|About screen or equivalent manner. |
SAMPA for ANSI C:
- sampa.c -- C modular code that computes the lunar position in the sky and eclipse conditions, revised December 15, 2023.
- sampa.h -- the header file that must be included in the code that calls "sampa.c"
- spa.c -- NREL's Solar Position Algorithm (SPA) source code that is called by "sampa.c"
- spa.h -- NREL's Solar Position Algorithm (SPA) header file that is included in "sampa.c"
- bird.c -- SERI/NREL Clear Sky Broadband Solar Radiation Model source code, required if the user is interested in modeled irradiance during an eclipse, revised January 15, 2024.
- bird.h -- the header file that is included in "sampa.c"
- sampa_tester.c -- a test code, containing the main() function, that exercises "sampa.c"
Note: An online SAMPA calculator that uses this source code is also available.