1 |
/* ASCEND modelling environment |
2 |
Copyright (C) 2011 Carnegie Mellon University |
3 |
|
4 |
This program is free software; you can redistribute it and/or modify |
5 |
it under the terms of the GNU General Public License as published by |
6 |
the Free Software Foundation; either version 2, or (at your option) |
7 |
any later version. |
8 |
|
9 |
This program is distributed in the hope that it will be useful, |
10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 |
GNU General Public License for more details. |
13 |
|
14 |
You should have received a copy of the GNU General Public License |
15 |
along with this program; if not, write to the Free Software |
16 |
Foundation, Inc., 59 Temple Place - Suite 330, |
17 |
Boston, MA 02111-1307, USA. |
18 |
*/ |
19 |
|
20 |
/* WARNING: this is a FIRST DRAFT of the code and HAS NOT BEEN CHECKED yet. */ |
21 |
|
22 |
/** @FILE |
23 |
Code reproduced with minor cosmetic changes from: |
24 |
R Grena (2008), An algorithm for the computation of the solar position, |
25 |
Solar Energy (82), pp 462-470. |
26 |
|
27 |
This header file contains the declaration of a class which includes all the |
28 |
input and output data, and the function that performs the calculation. |
29 |
|
30 |
To calculate the sun position, follow these steps: |
31 |
|
32 |
1. include this file. |
33 |
2. declare a variable of type SunCoord. |
34 |
3. Initialise the variable given the 9 input quantities required. |
35 |
This can be done in the declaration, listing the quantities between |
36 |
commas, or calling the function SetCoord(). In both cases, only the first |
37 |
four quantities are required; the others default to standard values |
38 |
(pressure = 1 atm, T = 20 ��C, 0 for all the other quantities) if omitted. |
39 |
Longitude and latitude must be given in RADIANS, pressure in ATM, |
40 |
temperature in ��C. |
41 |
Day, Month and Year are integer, UT in decimal hour from 0 to 24 (e.g. |
42 |
3:30 pm becomes 15.5). |
43 |
4. Call the Calculate() method of the SunCoord object. |
44 |
|
45 |
Example: |
46 |
(see the original publication) |
47 |
|
48 |
Warning: in order to improve accessibility and efficiency, there is not |
49 |
access control in the class. The user is free to directly access and |
50 |
modify all the data and there is not any control of consistency. Some |
51 |
caution in the use of the class is advisable. |
52 |
*/ |
53 |
#ifndef SUNPOS_GRENA_H |
54 |
#define SUNPOS_GRENA_H |
55 |
|
56 |
#include <iostream> |
57 |
#include <cmath> |
58 |
|
59 |
#ifndef PI |
60 |
# define PI 3.14159265358979 |
61 |
#endif |
62 |
|
63 |
/** |
64 |
Structure to hold sun position data, both input data as well as calculated |
65 |
output data. |
66 |
|
67 |
FIXME convert fields p, T to base SI units Pa and K. |
68 |
*/ |
69 |
typedef struct SunPos_struct{ |
70 |
// input data |
71 |
double t; ///< Ephemeris Julian Day, offset such that 0 = noon 1 Jan 2003. |
72 |
double latitude; ///< Latitude (N = positive??), in RADIANS. |
73 |
double longitude; ///< Longitude (E = positive??), in RADIANS. |
74 |
double p; ///< Pressure, in ATM (used for refraction calculation) |
75 |
double T; ///< Temperature, in ��C (used for refraction calculation) |
76 |
} SunPos; |
77 |
|
78 |
// functions |
79 |
|
80 |
/** Calculate time given the input date fields and store it in the SunPos object. |
81 |
@param UT fractional universal time (GMT) in hours from midnight (or fractional hours as required) |
82 |
@param Day Day of the month, starting at 1?? |
83 |
@param Month Month of the year, starting at 1?? |
84 |
@param Year Year, eg 2011. |
85 |
@param Delta_t Difference between UT and Terrestrial Time, in seconds. |
86 |
*/ |
87 |
void SunPos_calc_time(SunPos *S, double UT, int Day, int Month, int Year, double Delta_t); |
88 |
|
89 |
/** Set time directly in days since noon 1 Jan 2003 UTC. */ |
90 |
void SunPos_set_time(SunPos *S, double t); |
91 |
|
92 |
/** Set location of observer on Earth |
93 |
@param latitude latitude in RADIANS! |
94 |
@param longitude longitude in RADIANS! |
95 |
*/ |
96 |
void SunPos_set_lat_long(SunPos *S, double latitude, double longitude); |
97 |
|
98 |
/** Set local atmospheric conditions |
99 |
@param p Pressure in ATM |
100 |
@param T Temperature in ��C |
101 |
*/ |
102 |
void SunPos_set_pressure_temp(SunPos *S, double p, double T) |
103 |
|
104 |
/** |
105 |
Calculate the sun position in local spherical coordinates. |
106 |
@param S sun position input data object (set using above functions) |
107 |
@param zenith zenith angle in radians (output) |
108 |
@param azimuth azimuth angle in radians (output) |
109 |
*/ |
110 |
void SunPos_calc_zen_azi(SunPos *S, double *zenith, double *azimuth); |
111 |
|