This code is imported direct from http://rredc.nrel.gov/solar/codesandalgorithms/solpos/ Copyrights are retained in the code for each algorithm used. The library calculates the apparent solar position and intensity (theoretical maximum solar energy) based on the date, time, and location on Earth. The calculated data can be used to predict solar radiation, to be used in meteorological, solar energy and irrigation applications.
solpos00.h
00001 /*============================================================================ 00002 * 00003 * NAME: solpos00.h 00004 * 00005 * Contains: 00006 * S_solpos (computes the solar position and intensity 00007 * from time and place) 00008 * INPUTS: (from posdata) 00009 * year, month, day, hour, minute, second, 00010 * latitude, longitude, timezone, interval 00011 * OPTIONAL: (from posdata; defaults from S_init function) 00012 * press DEFAULT 1013.0 (standard pressure) 00013 * temp DEFAULT 10.0 (standard temperature) 00014 * tilt DEFAULT 0.0 (horizontal panel) 00015 * aspect DEFAULT 180.0 (South-facing panel) 00016 * sbwid DEFAULT 7.6 (shadowband width) 00017 * sbrad DEFAULT 31.7 (shadowband radius) 00018 * sbsky DEFAULT 0.04 (shadowband sky factor) 00019 * 00020 * OUTPUTS: (posdata) daynum, amass, ampress, azim, cosinc, 00021 * elevref, etr, etrn, etrtilt, prime, 00022 * sbcf, sretr, ssetr, unprime, zenref 00023 * 00024 * RETURNS: Long int status code (defined in solpos.h) 00025 * 00026 * Usage: 00027 * In calling program, along with other 'includes', insert: 00028 * 00029 * #include "solpos.h" 00030 * 00031 * Martin Rymes 00032 * National Renewable Energy Laboratory 00033 * 25 March 1998 00034 *----------------------------------------------------------------------------*/ 00035 00036 /*============================================================================ 00037 * 00038 * Define the function codes 00039 * 00040 *----------------------------------------------------------------------------*/ 00041 #define L_DOY 0x0001 00042 #define L_GEOM 0x0002 00043 #define L_ZENETR 0x0004 00044 #define L_SSHA 0x0008 00045 #define L_SBCF 0x0010 00046 #define L_TST 0x0020 00047 #define L_SRSS 0x0040 00048 #define L_SOLAZM 0x0080 00049 #define L_REFRAC 0x0100 00050 #define L_AMASS 0x0200 00051 #define L_PRIME 0x0400 00052 #define L_TILT 0x0800 00053 #define L_ETR 0x1000 00054 #define L_ALL 0xFFFF 00055 00056 /*============================================================================ 00057 * 00058 * Define the bit-wise masks for each function 00059 * 00060 *----------------------------------------------------------------------------*/ 00061 #define S_DOY ( L_DOY ) 00062 #define S_GEOM ( L_GEOM | S_DOY ) 00063 #define S_ZENETR ( L_ZENETR | S_GEOM ) 00064 #define S_SSHA ( L_SSHA | S_GEOM ) 00065 #define S_SBCF ( L_SBCF | S_SSHA ) 00066 #define S_TST ( L_TST | S_GEOM ) 00067 #define S_SRSS ( L_SRSS | S_SSHA | S_TST ) 00068 #define S_SOLAZM ( L_SOLAZM | S_ZENETR ) 00069 #define S_REFRAC ( L_REFRAC | S_ZENETR ) 00070 #define S_AMASS ( L_AMASS | S_REFRAC ) 00071 #define S_PRIME ( L_PRIME | S_AMASS ) 00072 #define S_TILT ( L_TILT | S_SOLAZM | S_REFRAC ) 00073 #define S_ETR ( L_ETR | S_REFRAC ) 00074 #define S_ALL ( L_ALL ) 00075 00076 00077 /*============================================================================ 00078 * 00079 * Enumerate the error codes 00080 * (Bit positions are from least significant to most significant) 00081 * 00082 *----------------------------------------------------------------------------*/ 00083 /* Code Bit Parameter Range 00084 =============== === =================== ============= */ 00085 enum {S_YEAR_ERROR, /* 0 year 1950 - 2050 */ 00086 S_MONTH_ERROR, /* 1 month 1 - 12 */ 00087 S_DAY_ERROR, /* 2 day-of-month 1 - 31 */ 00088 S_DOY_ERROR, /* 3 day-of-year 1 - 366 */ 00089 S_HOUR_ERROR, /* 4 hour 0 - 24 */ 00090 S_MINUTE_ERROR, /* 5 minute 0 - 59 */ 00091 S_SECOND_ERROR, /* 6 second 0 - 59 */ 00092 S_TZONE_ERROR, /* 7 time zone -12 - 12 */ 00093 S_INTRVL_ERROR, /* 8 interval (seconds) 0 - 28800 */ 00094 S_LAT_ERROR, /* 9 latitude -90 - 90 */ 00095 S_LON_ERROR, /* 10 longitude -180 - 180 */ 00096 S_TEMP_ERROR, /* 11 temperature (deg. C) -100 - 100 */ 00097 S_PRESS_ERROR, /* 12 pressure (millibars) 0 - 2000 */ 00098 S_TILT_ERROR, /* 13 tilt -90 - 90 */ 00099 S_ASPECT_ERROR, /* 14 aspect -360 - 360 */ 00100 S_SBWID_ERROR, /* 15 shadow band width (cm) 1 - 100 */ 00101 S_SBRAD_ERROR, /* 16 shadow band radius (cm) 1 - 100 */ 00102 S_SBSKY_ERROR}; /* 17 shadow band sky factor -1 - 1 */ 00103 00104 struct posdata 00105 { 00106 /***** ALPHABETICAL LIST OF COMMON VARIABLES *****/ 00107 /* Each comment begins with a 1-column letter code: 00108 I: INPUT variable 00109 O: OUTPUT variable 00110 T: TRANSITIONAL variable used in the algorithm, 00111 of interest only to the solar radiation 00112 modelers, and available to you because you 00113 may be one of them. 00114 00115 The FUNCTION column indicates which sub-function 00116 within solpos must be switched on using the 00117 "function" parameter to calculate the desired 00118 output variable. All function codes are 00119 defined in the solpos.h file. The default 00120 S_ALL switch calculates all output variables. 00121 Multiple functions may be or'd to create a 00122 composite function switch. For example, 00123 (S_TST | S_SBCF). Specifying only the functions 00124 for required output variables may allow solpos 00125 to execute more quickly. 00126 00127 The S_DOY mask works as a toggle between the 00128 input date represented as a day number (daynum) 00129 or as month and day. To set the switch (to 00130 use daynum input), the function is or'd; to 00131 clear the switch (to use month and day input), 00132 the function is inverted and and'd. 00133 00134 For example: 00135 pdat->function |= S_DOY (sets daynum input) 00136 pdat->function &= ~S_DOY (sets month and day input) 00137 00138 Whichever date form is used, S_solpos will 00139 calculate and return the variables(s) of the 00140 other form. See the soltest.c program for 00141 other examples. */ 00142 00143 /* VARIABLE I/O Function Description */ 00144 /* ------------- ---- ---------- ---------------------------------------*/ 00145 00146 int day; /* I/O: S_DOY Day of month (May 27 = 27, etc.) 00147 solpos will CALCULATE this by default, 00148 or will optionally require it as input 00149 depending on the setting of the S_DOY 00150 function switch. */ 00151 int daynum; /* I/O: S_DOY Day number (day of year; Feb 1 = 32 ) 00152 solpos REQUIRES this by default, but 00153 will optionally calculate it from 00154 month and day depending on the setting 00155 of the S_DOY function switch. */ 00156 int function; /* I: Switch to choose functions for desired 00157 output. */ 00158 int hour; /* I: Hour of day, 0 - 23, DEFAULT = 12 */ 00159 int interval; /* I: Interval of a measurement period in 00160 seconds. Forces solpos to use the 00161 time and date from the interval 00162 midpoint. The INPUT time (hour, 00163 minute, and second) is assumed to 00164 be the END of the measurement 00165 interval. */ 00166 int minute; /* I: Minute of hour, 0 - 59, DEFAULT = 0 */ 00167 int month; /* I/O: S_DOY Month number (Jan = 1, Feb = 2, etc.) 00168 solpos will CALCULATE this by default, 00169 or will optionally require it as input 00170 depending on the setting of the S_DOY 00171 function switch. */ 00172 int second; /* I: Second of minute, 0 - 59, DEFAULT = 0 */ 00173 int year; /* I: 4-digit year (2-digit year is NOT 00174 allowed */ 00175 00176 /***** FLOATS *****/ 00177 00178 float amass; /* O: S_AMASS Relative optical airmass */ 00179 float ampress; /* O: S_AMASS Pressure-corrected airmass */ 00180 float aspect; /* I: Azimuth of panel surface (direction it 00181 faces) N=0, E=90, S=180, W=270, 00182 DEFAULT = 180 */ 00183 float azim; /* O: S_SOLAZM Solar azimuth angle: N=0, E=90, S=180, 00184 W=270 */ 00185 float cosinc; /* O: S_TILT Cosine of solar incidence angle on 00186 panel */ 00187 float coszen; /* O: S_REFRAC Cosine of refraction corrected solar 00188 zenith angle */ 00189 float dayang; /* T: S_GEOM Day angle (daynum*360/year-length) 00190 degrees */ 00191 float declin; /* T: S_GEOM Declination--zenith angle of solar noon 00192 at equator, degrees NORTH */ 00193 float eclong; /* T: S_GEOM Ecliptic longitude, degrees */ 00194 float ecobli; /* T: S_GEOM Obliquity of ecliptic */ 00195 float ectime; /* T: S_GEOM Time of ecliptic calculations */ 00196 float elevetr; /* O: S_ZENETR Solar elevation, no atmospheric 00197 correction (= ETR) */ 00198 float elevref; /* O: S_REFRAC Solar elevation angle, 00199 deg. from horizon, refracted */ 00200 float eqntim; /* T: S_TST Equation of time (TST - LMT), minutes */ 00201 float erv; /* T: S_GEOM Earth radius vector 00202 (multiplied to solar constant) */ 00203 float etr; /* O: S_ETR Extraterrestrial (top-of-atmosphere) 00204 W/sq m global horizontal solar 00205 irradiance */ 00206 float etrn; /* O: S_ETR Extraterrestrial (top-of-atmosphere) 00207 W/sq m direct normal solar 00208 irradiance */ 00209 float etrtilt; /* O: S_TILT Extraterrestrial (top-of-atmosphere) 00210 W/sq m global irradiance on a tilted 00211 surface */ 00212 float gmst; /* T: S_GEOM Greenwich mean sidereal time, hours */ 00213 float hrang; /* T: S_GEOM Hour angle--hour of sun from solar noon, 00214 degrees WEST */ 00215 float julday; /* T: S_GEOM Julian Day of 1 JAN 2000 minus 00216 2,400,000 days (in order to regain 00217 single precision) */ 00218 float latitude; /* I: Latitude, degrees north (south negative) */ 00219 float longitude; /* I: Longitude, degrees east (west negative) */ 00220 float lmst; /* T: S_GEOM Local mean sidereal time, degrees */ 00221 float mnanom; /* T: S_GEOM Mean anomaly, degrees */ 00222 float mnlong; /* T: S_GEOM Mean longitude, degrees */ 00223 float rascen; /* T: S_GEOM Right ascension, degrees */ 00224 float press; /* I: Surface pressure, millibars, used for 00225 refraction correction and ampress */ 00226 float prime; /* O: S_PRIME Factor that normalizes Kt, Kn, etc. */ 00227 float sbcf; /* O: S_SBCF Shadow-band correction factor */ 00228 float sbwid; /* I: Shadow-band width (cm) */ 00229 float sbrad; /* I: Shadow-band radius (cm) */ 00230 float sbsky; /* I: Shadow-band sky factor */ 00231 float solcon; /* I: Solar constant (NREL uses 1367 W/sq m) */ 00232 float ssha; /* T: S_SRHA Sunset(/rise) hour angle, degrees */ 00233 float sretr; /* O: S_SRSS Sunrise time, minutes from midnight, 00234 local, WITHOUT refraction */ 00235 float ssetr; /* O: S_SRSS Sunset time, minutes from midnight, 00236 local, WITHOUT refraction */ 00237 float temp; /* I: Ambient dry-bulb temperature, degrees C, 00238 used for refraction correction */ 00239 float tilt; /* I: Degrees tilt from horizontal of panel */ 00240 float timezone; /* I: Time zone, east (west negative). 00241 USA: Mountain = -7, Central = -6, etc. */ 00242 float tst; /* T: S_TST True solar time, minutes from midnight */ 00243 float tstfix; /* T: S_TST True solar time - local standard time */ 00244 float unprime; /* O: S_PRIME Factor that denormalizes Kt', Kn', etc. */ 00245 float utime; /* T: S_GEOM Universal (Greenwich) standard time */ 00246 float zenetr; /* T: S_ZENETR Solar zenith angle, no atmospheric 00247 correction (= ETR) */ 00248 float zenref; /* O: S_REFRAC Solar zenith angle, deg. from zenith, 00249 refracted */ 00250 }; 00251 00252 /* For users that wish to access individual functions, the following table 00253 lists all output and transition variables, the L_ mask for the function 00254 that calculates them, and all the input variables required by that function. 00255 The function variable is set to the L_ mask, which will force S_solpos to 00256 only call the required function. L_ masks may be ORed as desired. 00257 00258 VARIABLE Mask Required Variables 00259 --------- ---------- --------------------------------------- 00260 amass L_AMASS zenref, press 00261 ampress L_AMASS zenref, press 00262 azim L_SOLAZM elevetr, declin, latitude, hrang 00263 cosinc L_TILT azim, aspect, tilt, zenref, coszen,etrn 00264 coszen L_REFRAC elevetr, press, temp 00265 dayang L_GEOM All date, time, and location inputs 00266 declin L_GEOM All date, time, and location inputs 00267 eclong L_GEOM All date, time, and location inputs 00268 ecobli L_GEOM All date, time, and location inputs 00269 ectime L_GEOM All date, time, and location inputs 00270 elevetr L_ZENETR declin, latitude, hrang 00271 elevref L_REFRAC elevetr, press, temp 00272 eqntim L_TST hrang, hour, minute, second, interval 00273 erv L_GEOM All date, time, and location inputs 00274 etr L_ETR coszen, solcon, erv 00275 etrn L_ETR coszen, solcon, erv 00276 etrtilt L_TILT azim, aspect, tilt, zenref, coszen, etrn 00277 gmst L_GEOM All date, time, and location inputs 00278 hrang L_GEOM All date, time, and location inputs 00279 julday L_GEOM All date, time, and location inputs 00280 lmst L_GEOM All date, time, and location inputs 00281 mnanom L_GEOM All date, time, and location inputs 00282 mnlong L_GEOM All date, time, and location inputs 00283 rascen L_GEOM All date, time, and location inputs 00284 prime L_PRIME amass 00285 sbcf L_SBCF latitude, declin, ssha, sbwid, sbrad, sbsky 00286 ssha L_SRHA latitude, declin 00287 sretr L_SRSS ssha, tstfix 00288 ssetr L_SRSS ssha, tstfix 00289 tst L_TST hrang, hour, minute, second, interval 00290 tstfix L_TST hrang, hour, minute, second, interval 00291 unprime L_PRIME amass 00292 utime L_GEOM All date, time, and location inputs 00293 zenetr L_ZENETR declination, latitude, hrang 00294 zenref L_REFRAC elevetr, press, temp 00295 00296 00297 00298 *============================================================================ 00299 * Long int function S_solpos, adapted from the NREL VAX solar libraries 00300 * 00301 * This function calculates the apparent solar position and intensity 00302 * (theoretical maximum solar energy) based on the date, time, and 00303 * location on Earth. (DEFAULT values are from the optional S_posinit 00304 * function.) 00305 * 00306 * Requires: 00307 * Date and time: 00308 * year 00309 * month (optional without daynum) 00310 * day (optional without daynum) 00311 * daynum 00312 * hour 00313 * minute 00314 * second 00315 * Location: 00316 * latitude 00317 * longitude 00318 * Location/time adjuster: 00319 * timezone 00320 * Atmospheric pressure and temperature: 00321 * press DEFAULT 1013.0 mb 00322 * temp DEFAULT 10.0 degrees C 00323 * Tilt of flat surface that receives solar energy: 00324 * aspect DEFAULT 180 (South) 00325 * tilt DEFAULT 0 (Horizontal) 00326 * Shadow band parameters: 00327 * sbwid DEFAULT 7.6 cm 00328 * sbrad DEFAULT 31.7 cm 00329 * sbsky DEFAULT 0.04 00330 * Functionality 00331 * function DEFAULT S_ALL (all output parameters computed) 00332 * 00333 * Returns: 00334 * everything defined at the top of this listing. 00335 *----------------------------------------------------------------------------*/ 00336 long S_solpos (struct posdata *pdat); 00337 00338 /*============================================================================ 00339 * Void function S_init 00340 * 00341 * This function initiates all of the input functions to S_Solpos(). 00342 * NOTE: This function is optional if you initialize all input parameters 00343 * in your calling code. 00344 * 00345 * Requires: Pointer to a posdata structure, members of which are 00346 * initialized. 00347 * 00348 * Returns: Void 00349 * 00350 *----------------------------------------------------------------------------*/ 00351 void S_init(struct posdata *pdat); 00352 00353 00354 /*============================================================================ 00355 * Void function S_decode 00356 * 00357 * This function decodes the error codes from S_solpos return value 00358 * 00359 * INPUTS: Long integer S_solpos return value, struct posdata* 00360 * 00361 * OUTPUTS: Descriptive text of errors to stderr 00362 *----------------------------------------------------------------------------*/ 00363 void S_decode(long code, struct posdata *pdat); 00364
Generated on Tue Jul 12 2022 17:04:07 by
1.7.2