SolTrack
SolTrack is a simple, free, fast and accurate C routine to compute the position of the Sun
All Data Structures Files Functions Variables Macros
SolTrack.h (SolTrack version 2.2, revision 13, hash 9f77eee, 2017-09-09)
Go to the documentation of this file.
1 /*
2  SolTrack: a simple, free, fast and accurate C routine to compute the position of the Sun
3 
4 
5  Copyright (c) 2014-2017 Marc van der Sluys, Paul van Kan and Jurgen Reintjes,
6  Lectorate of Sustainable Energy, HAN University of applied sciences, Arnhem, The Netherlands
7 
8 
9  This file is part of the SolTrack package, see: http://soltrack.sourceforge.net
10  SolTrack is derived from libTheSky (http://libthesky.sourceforge.net) under the terms of the GPL v.3
11 
12  This is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published
13  by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
14 
15  This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License along with this code. If not, see
19  <http://www.gnu.org/licenses/>.
20 */
21 
22 
23 #ifndef __SOLTRACK_H
24 #define __SOLTRACK_H
25 
26 
27 #include "stdio.h"
28 #include "math.h"
29 
30 
31 // Constants:
32 #define PI 3.14159265358979323846 // Pi
33 #define TWO_PI 6.28318530717958647693 // 2 pi
34 #define MPI 3.14159265358979323846e6 // One Megapi...
35 #define R2D 57.2957795130823208768 // Radians to degrees conversion factor
36 #define R2H 3.81971863420548805845 // Radians to hours conversion factor
37 
38 
39 
40 
41 // Structs:
42 
44 struct Time {
46  double second;
47 };
48 
49 
51 struct Location {
52  double longitude, latitude;
53  double sinLat, cosLat;
54  double pressure, temperature;
55 };
56 
57 
59 struct Position {
60  double julianDay, tJD, tJC,tJC2;
61  double longitude, distance;
62  double obliquity,cosObliquity, nutationLon;
63  double rightAscension,declination, hourAngle,agst;
64  double altitude, altitudeRefract,azimuthRefract;
65  double hourAngleRefract, declinationRefract;
66 };
67 
68 
70 struct RiseSet {
71  double riseTime, transitTime, setTime;
72  double riseAzimuth, transitAltitude, setAzimuth;
73 };
74 
75 
76 // Function prototypes:
77 void SolTrack(struct Time time, struct Location location, struct Position *position, int useDegrees, int useNorthEqualsZero, int computeRefrEquatorial, int computeDistance);
78 double computeJulianDay(int year, int month, int day, int hour, int minute, double second);
79 void computeLongitude(int computeDistance, struct Position *position);
80 void convertEclipticToEquatorial(double longitude, double cosObliquity, double *rightAscension, double *declination);
81 void convertEquatorialToHorizontal(struct Location location, struct Position *position);
82 void eq2horiz(double sinLat, double cosLat, double longitude, double rightAscension, double declination, double agst, double *azimuth, double *sinAlt);
83 void convertHorizontalToEquatorial(double sinLat, double cosLat, double azimuth, double altitude, double *hourAngle, double *declination);
84 void setNorthToZero(double *azimuth, double *hourAngle, int computeRefrEquatorial);
85 void convertRadiansToDegrees(double *longitude, double *rightAscension, double *declination, \
86  double *altitude, double *azimuthRefract, double *altitudeRefract, \
87  double *hourAngle, double *declinationRefract, int computeRefrEquatorial);
88 double STatan2(double y, double x);
89 
90 void SolTrack_RiseSet(struct Time time, struct Location location, struct Position *position, struct RiseSet *riseSet, double sa0, int useDegrees, int useNorthEqualsZero);
91 double rev(double angle);
92 double rev2(double angle);
93 #endif
double rev2(double angle)
Fold an angle to take a value between -pi and pi.
Definition: SolTrack_RiseSet.c:167
double rightAscension
Definition: SolTrack.h:63
double second
Definition: SolTrack.h:46
void SolTrack_RiseSet(struct Time time, struct Location location, struct Position *position, struct RiseSet *riseSet, double sa0, int useDegrees, int useNorthEqualsZero)
Compute rise, transit and set times for the Sun, as well as their azimuths/altitude.
Definition: SolTrack_RiseSet.c:26
double rev(double angle)
Fold an angle to take a value between 0 and 2pi.
Definition: SolTrack_RiseSet.c:157
double azimuthRefract
Definition: SolTrack.h:64
void convertEquatorialToHorizontal(struct Location location, struct Position *position)
Convert equatorial to horizontal coordinates.
Definition: SolTrack.c:203
int minute
Definition: SolTrack.h:45
int hour
Definition: SolTrack.h:45
int year
Definition: SolTrack.h:45
double STatan2(double y, double x)
My version of the atan2() function - ~39% faster than built-in (in terms of number of instructions) ...
Definition: SolTrack.c:356
double longitude
Definition: SolTrack.h:52
double transitTime
Definition: SolTrack.h:71
double transitAltitude
Definition: SolTrack.h:72
double computeJulianDay(int year, int month, int day, int hour, int minute, double second)
Compute the Julian Day from the date and time.
Definition: SolTrack.c:109
double longitude
Definition: SolTrack.h:61
double sinLat
Definition: SolTrack.h:53
double tJD
Definition: SolTrack.h:60
void computeLongitude(int computeDistance, struct Position *position)
Compute the ecliptic longitude of the Sun for a given Julian Day.
Definition: SolTrack.c:135
double obliquity
Definition: SolTrack.h:62
void convertRadiansToDegrees(double *longitude, double *rightAscension, double *declination, double *altitude, double *azimuthRefract, double *altitudeRefract, double *hourAngle, double *declinationRefract, int computeRefrEquatorial)
Convert final results from radians to degrees.
Definition: SolTrack.c:327
void convertHorizontalToEquatorial(double sinLat, double cosLat, double azimuth, double altitude, double *hourAngle, double *declination)
Convert (refraction-corrected) horizontal coordinates to equatorial coordinates.
Definition: SolTrack.c:272
void setNorthToZero(double *azimuth, double *hourAngle, int computeRefrEquatorial)
Convert the South=0 convention to North=0 convention for azimuth and hour angle.
Definition: SolTrack.c:298
void convertEclipticToEquatorial(double longitude, double cosObliquity, double *rightAscension, double *declination)
Convert ecliptic coordinates to equatorial coordinates.
Definition: SolTrack.c:184
Position of the Sun.
Definition: SolTrack.h:59
int month
Definition: SolTrack.h:45
Rise and set data for the Sun.
Definition: SolTrack.h:70
void SolTrack(struct Time time, struct Location location, struct Position *position, int useDegrees, int useNorthEqualsZero, int computeRefrEquatorial, int computeDistance)
Main function to compute the position of the Sun.
Definition: SolTrack.c:41
double temperature
Definition: SolTrack.h:54
void eq2horiz(double sinLat, double cosLat, double longitude, double rightAscension, double declination, double agst, double *azimuth, double *sinAlt)
Convert equatorial coordinates to horizontal coordinates.
Definition: SolTrack.c:243
Date and time to compute the Sun&#39;s position for, in UT.
Definition: SolTrack.h:44
int day
Definition: SolTrack.h:45
Location to compute the Sun&#39;s position for.
Definition: SolTrack.h:51
double hourAngleRefract
Definition: SolTrack.h:65