solpos00.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. /*============================================================================
  2. *
  3. * NAME: solpos.h
  4. *
  5. * Contains:
  6. * S_solpos (computes the solar position and intensity
  7. * from time and place)
  8. * INPUTS: (from posdata)
  9. * year, month, day, hour, minute, second,
  10. * latitude, longitude, timezone, interval
  11. * OPTIONAL: (from posdata; defaults from S_init function)
  12. * press DEFAULT 1013.0 (standard pressure)
  13. * temp DEFAULT 10.0 (standard temperature)
  14. * tilt DEFAULT 0.0 (horizontal panel)
  15. * aspect DEFAULT 180.0 (South-facing panel)
  16. * sbwid DEFAULT 7.6 (shadowband width)
  17. * sbrad DEFAULT 31.7 (shadowband radius)
  18. * sbsky DEFAULT 0.04 (shadowband sky factor)
  19. *
  20. * OUTPUTS: (posdata) daynum, amass, ampress, azim, cosinc,
  21. * elevref, etr, etrn, etrtilt, prime,
  22. * sbcf, sretr, ssetr, unprime, zenref
  23. *
  24. * RETURNS: Long int status code (defined in solpos.h)
  25. *
  26. * Usage:
  27. * In calling program, along with other 'includes', insert:
  28. *
  29. * #include "solpos.h"
  30. *
  31. * Martin Rymes
  32. * National Renewable Energy Laboratory
  33. * 25 March 1998
  34. *
  35. *----------------------------------------------------------------------------*/
  36. /*============================================================================
  37. *
  38. * Define the function codes
  39. *
  40. *----------------------------------------------------------------------------*/
  41. #define L_DOY 0x0001
  42. #define L_GEOM 0x0002
  43. #define L_ZENETR 0x0004
  44. #define L_SSHA 0x0008
  45. #define L_SBCF 0x0010
  46. #define L_TST 0x0020
  47. #define L_SRSS 0x0040
  48. #define L_SOLAZM 0x0080
  49. #define L_REFRAC 0x0100
  50. #define L_AMASS 0x0200
  51. #define L_PRIME 0x0400
  52. #define L_TILT 0x0800
  53. #define L_ETR 0x1000
  54. #define L_ALL 0xFFFF
  55. /*============================================================================
  56. *
  57. * Define the bit-wise masks for each function
  58. *
  59. *----------------------------------------------------------------------------*/
  60. #define S_DOY ( L_DOY )
  61. #define S_GEOM ( L_GEOM | S_DOY )
  62. #define S_ZENETR ( L_ZENETR | S_GEOM )
  63. #define S_SSHA ( L_SSHA | S_GEOM )
  64. #define S_SBCF ( L_SBCF | S_SSHA )
  65. #define S_TST ( L_TST | S_GEOM )
  66. #define S_SRSS ( L_SRSS | S_SSHA | S_TST )
  67. #define S_SOLAZM ( L_SOLAZM | S_ZENETR )
  68. #define S_REFRAC ( L_REFRAC | S_ZENETR )
  69. #define S_AMASS ( L_AMASS | S_REFRAC )
  70. #define S_PRIME ( L_PRIME | S_AMASS )
  71. #define S_TILT ( L_TILT | S_SOLAZM | S_REFRAC )
  72. #define S_ETR ( L_ETR | S_REFRAC )
  73. #define S_ALL ( L_ALL )
  74. /*============================================================================
  75. *
  76. * Enumerate the error codes
  77. * (Bit positions are from least significant to most significant)
  78. *
  79. *----------------------------------------------------------------------------*/
  80. /* Code Bit Parameter Range
  81. =============== === =================== ============= */
  82. enum
  83. { S_YEAR_ERROR, /* 0 year 1950 - 2050 */
  84. S_MONTH_ERROR, /* 1 month 1 - 12 */
  85. S_DAY_ERROR, /* 2 day-of-month 1 - 31 */
  86. S_DOY_ERROR, /* 3 day-of-year 1 - 366 */
  87. S_HOUR_ERROR, /* 4 hour 0 - 24 */
  88. S_MINUTE_ERROR, /* 5 minute 0 - 59 */
  89. S_SECOND_ERROR, /* 6 second 0 - 59 */
  90. S_TZONE_ERROR, /* 7 time zone -12 - 12 */
  91. S_INTRVL_ERROR, /* 8 interval (seconds) 0 - 28800 */
  92. S_LAT_ERROR, /* 9 latitude -90 - 90 */
  93. S_LON_ERROR, /* 10 longitude -180 - 180 */
  94. S_TEMP_ERROR, /* 11 temperature (deg. C) -100 - 100 */
  95. S_PRESS_ERROR, /* 12 pressure (millibars) 0 - 2000 */
  96. S_TILT_ERROR, /* 13 tilt -90 - 90 */
  97. S_ASPECT_ERROR, /* 14 aspect -360 - 360 */
  98. S_SBWID_ERROR, /* 15 shadow band width (cm) 1 - 100 */
  99. S_SBRAD_ERROR, /* 16 shadow band radius (cm) 1 - 100 */
  100. S_SBSKY_ERROR
  101. }; /* 17 shadow band sky factor -1 - 1 */
  102. struct posdata
  103. {
  104. /***** ALPHABETICAL LIST OF COMMON VARIABLES *****/
  105. /* Each comment begins with a 1-column letter code:
  106. I: INPUT variable
  107. O: OUTPUT variable
  108. T: TRANSITIONAL variable used in the algorithm,
  109. of interest only to the solar radiation
  110. modelers, and available to you because you
  111. may be one of them.
  112. The FUNCTION column indicates which sub-function
  113. within solpos must be switched on using the
  114. "function" parameter to calculate the desired
  115. output variable. All function codes are
  116. defined in the solpos.h file. The default
  117. S_ALL switch calculates all output variables.
  118. Multiple functions may be or'd to create a
  119. composite function switch. For example,
  120. (S_TST | S_SBCF). Specifying only the functions
  121. for required output variables may allow solpos
  122. to execute more quickly.
  123. The S_DOY mask works as a toggle between the
  124. input date represented as a day number (daynum)
  125. or as month and day. To set the switch (to
  126. use daynum input), the function is or'd; to
  127. clear the switch (to use month and day input),
  128. the function is inverted and and'd.
  129. For example:
  130. pdat->function |= S_DOY (sets daynum input)
  131. pdat->function &= ~S_DOY (sets month and day input)
  132. Whichever date form is used, S_solpos will
  133. calculate and return the variables(s) of the
  134. other form. See the soltest.c program for
  135. other examples. */
  136. /* VARIABLE I/O Function Description */
  137. /* ------------- ---- ---------- --------------------------------------- */
  138. int day; /* I/O: S_DOY Day of month (May 27 = 27, etc.)
  139. solpos will CALCULATE this by default,
  140. or will optionally require it as input
  141. depending on the setting of the S_DOY
  142. function switch. */
  143. int daynum; /* I/O: S_DOY Day number (day of year; Feb 1 = 32 )
  144. solpos REQUIRES this by default, but
  145. will optionally calculate it from
  146. month and day depending on the setting
  147. of the S_DOY function switch. */
  148. int function; /* I: Switch to choose functions for desired
  149. output. */
  150. int hour; /* I: Hour of day, 0 - 23, DEFAULT = 12 */
  151. int interval; /* I: Interval of a measurement period in
  152. seconds. Forces solpos to use the
  153. time and date from the interval
  154. midpoint. The INPUT time (hour,
  155. minute, and second) is assumed to
  156. be the END of the measurement
  157. interval. */
  158. int minute; /* I: Minute of hour, 0 - 59, DEFAULT = 0 */
  159. int month; /* I/O: S_DOY Month number (Jan = 1, Feb = 2, etc.)
  160. solpos will CALCULATE this by default,
  161. or will optionally require it as input
  162. depending on the setting of the S_DOY
  163. function switch. */
  164. int second; /* I: Second of minute, 0 - 59, DEFAULT = 0 */
  165. int year; /* I: 4-digit year (2-digit year is NOT
  166. allowed */
  167. /***** FLOATS *****/
  168. float amass; /* O: S_AMASS Relative optical airmass */
  169. float ampress; /* O: S_AMASS Pressure-corrected airmass */
  170. float aspect; /* I: Azimuth of panel surface (direction it
  171. faces) N=0, E=90, S=180, W=270,
  172. DEFAULT = 180 */
  173. float azim; /* O: S_SOLAZM Solar azimuth angle: N=0, E=90, S=180,
  174. W=270 */
  175. float cosinc; /* O: S_TILT Cosine of solar incidence angle on
  176. panel */
  177. float coszen; /* O: S_REFRAC Cosine of refraction corrected solar
  178. zenith angle */
  179. float dayang; /* T: S_GEOM Day angle (daynum*360/year-length)
  180. degrees */
  181. float declin; /* T: S_GEOM Declination--zenith angle of solar noon
  182. at equator, degrees NORTH */
  183. float eclong; /* T: S_GEOM Ecliptic longitude, degrees */
  184. float ecobli; /* T: S_GEOM Obliquity of ecliptic */
  185. float ectime; /* T: S_GEOM Time of ecliptic calculations */
  186. float elevetr; /* O: S_ZENETR Solar elevation, no atmospheric
  187. correction (= ETR) */
  188. float elevref; /* O: S_REFRAC Solar elevation angle,
  189. deg. from horizon, refracted */
  190. float eqntim; /* T: S_TST Equation of time (TST - LMT), minutes */
  191. float erv; /* T: S_GEOM Earth radius vector
  192. (multiplied to solar constant) */
  193. float etr; /* O: S_ETR Extraterrestrial (top-of-atmosphere)
  194. W/sq m global horizontal solar
  195. irradiance */
  196. float etrn; /* O: S_ETR Extraterrestrial (top-of-atmosphere)
  197. W/sq m direct normal solar
  198. irradiance */
  199. float etrtilt; /* O: S_TILT Extraterrestrial (top-of-atmosphere)
  200. W/sq m global irradiance on a tilted
  201. surface */
  202. float gmst; /* T: S_GEOM Greenwich mean sidereal time, hours */
  203. float hrang; /* T: S_GEOM Hour angle--hour of sun from solar noon,
  204. degrees WEST */
  205. float julday; /* T: S_GEOM Julian Day of 1 JAN 2000 minus
  206. 2,400,000 days (in order to regain
  207. single precision) */
  208. float latitude; /* I: Latitude, degrees north (south negative) */
  209. float longitude; /* I: Longitude, degrees east (west negative) */
  210. float lmst; /* T: S_GEOM Local mean sidereal time, degrees */
  211. float mnanom; /* T: S_GEOM Mean anomaly, degrees */
  212. float mnlong; /* T: S_GEOM Mean longitude, degrees */
  213. float rascen; /* T: S_GEOM Right ascension, degrees */
  214. float press; /* I: Surface pressure, millibars, used for
  215. refraction correction and ampress */
  216. float prime; /* O: S_PRIME Factor that normalizes Kt, Kn, etc. */
  217. float sbcf; /* O: S_SBCF Shadow-band correction factor */
  218. float sbwid; /* I: Shadow-band width (cm) */
  219. float sbrad; /* I: Shadow-band radius (cm) */
  220. float sbsky; /* I: Shadow-band sky factor */
  221. float solcon; /* I: Solar constant (NREL uses 1367 W/sq m) */
  222. float ssha; /* T: S_SRHA Sunset(/rise) hour angle, degrees */
  223. float sretr; /* O: S_SRSS Sunrise time, minutes from midnight,
  224. local, WITHOUT refraction */
  225. float ssetr; /* O: S_SRSS Sunset time, minutes from midnight,
  226. local, WITHOUT refraction */
  227. float temp; /* I: Ambient dry-bulb temperature, degrees C,
  228. used for refraction correction */
  229. float tilt; /* I: Degrees tilt from horizontal of panel */
  230. float timezone; /* I: Time zone, east (west negative).
  231. USA: Mountain = -7, Central = -6, etc. */
  232. float tst; /* T: S_TST True solar time, minutes from midnight */
  233. float tstfix; /* T: S_TST True solar time - local standard time */
  234. float unprime; /* O: S_PRIME Factor that denormalizes Kt', Kn', etc. */
  235. float utime; /* T: S_GEOM Universal (Greenwich) standard time */
  236. float zenetr; /* T: S_ZENETR Solar zenith angle, no atmospheric
  237. correction (= ETR) */
  238. float zenref; /* O: S_REFRAC Solar zenith angle, deg. from zenith,
  239. refracted */
  240. };
  241. /* For users that wish to access individual functions, the following table
  242. lists all output and transition variables, the L_ mask for the function
  243. that calculates them, and all the input variables required by that function.
  244. The function variable is set to the L_ mask, which will force S_solpos to
  245. only call the required function. L_ masks may be ORed as desired.
  246. VARIABLE Mask Required Variables
  247. --------- ---------- ---------------------------------------
  248. amass L_AMASS zenref, press
  249. ampress L_AMASS zenref, press
  250. azim L_SOLAZM elevetr, declin, latitude, hrang
  251. cosinc L_TILT azim, aspect, tilt, zenref, coszen,etrn
  252. coszen L_REFRAC elevetr, press, temp
  253. dayang L_GEOM All date, time, and location inputs
  254. declin L_GEOM All date, time, and location inputs
  255. eclong L_GEOM All date, time, and location inputs
  256. ecobli L_GEOM All date, time, and location inputs
  257. ectime L_GEOM All date, time, and location inputs
  258. elevetr L_ZENETR declin, latitude, hrang
  259. elevref L_REFRAC elevetr, press, temp
  260. eqntim L_TST hrang, hour, minute, second, interval
  261. erv L_GEOM All date, time, and location inputs
  262. etr L_ETR coszen, solcon, erv
  263. etrn L_ETR coszen, solcon, erv
  264. etrtilt L_TILT azim, aspect, tilt, zenref, coszen, etrn
  265. gmst L_GEOM All date, time, and location inputs
  266. hrang L_GEOM All date, time, and location inputs
  267. julday L_GEOM All date, time, and location inputs
  268. lmst L_GEOM All date, time, and location inputs
  269. mnanom L_GEOM All date, time, and location inputs
  270. mnlong L_GEOM All date, time, and location inputs
  271. rascen L_GEOM All date, time, and location inputs
  272. prime L_PRIME amass
  273. sbcf L_SBCF latitude, declin, ssha, sbwid, sbrad, sbsky
  274. ssha L_SRHA latitude, declin
  275. sretr L_SRSS ssha, tstfix
  276. ssetr L_SRSS ssha, tstfix
  277. tst L_TST hrang, hour, minute, second, interval
  278. tstfix L_TST hrang, hour, minute, second, interval
  279. unprime L_PRIME amass
  280. utime L_GEOM All date, time, and location inputs
  281. zenetr L_ZENETR declination, latitude, hrang
  282. zenref L_REFRAC elevetr, press, temp
  283. */
  284. /*============================================================================
  285. * Long int function S_solpos, adapted from the NREL VAX solar libraries
  286. *
  287. * This function calculates the apparent solar position and intensity
  288. * (theoretical maximum solar energy) based on the date, time, and
  289. * location on Earth. (DEFAULT values are from the optional S_posinit
  290. * function.)
  291. *
  292. * Requires:
  293. * Date and time:
  294. * year
  295. * month (optional without daynum)
  296. * day (optional without daynum)
  297. * daynum
  298. * hour
  299. * minute
  300. * second
  301. * Location:
  302. * latitude
  303. * longitude
  304. * Location/time adjuster:
  305. * timezone
  306. * Atmospheric pressure and temperature:
  307. * press DEFAULT 1013.0 mb
  308. * temp DEFAULT 10.0 degrees C
  309. * Tilt of flat surface that receives solar energy:
  310. * aspect DEFAULT 180 (South)
  311. * tilt DEFAULT 0 (Horizontal)
  312. * Shadow band parameters:
  313. * sbwid DEFAULT 7.6 cm
  314. * sbrad DEFAULT 31.7 cm
  315. * sbsky DEFAULT 0.04
  316. * Functionality
  317. * function DEFAULT S_ALL (all output parameters computed)
  318. *
  319. * Returns:
  320. * everything defined at the top of this listing.
  321. *----------------------------------------------------------------------------*/
  322. long S_solpos(struct posdata *pdat);
  323. /*============================================================================
  324. * Void function S_init
  325. *
  326. * This function initiates all of the input functions to S_Solpos().
  327. * NOTE: This function is optional if you initialize all input parameters
  328. * in your calling code.
  329. *
  330. * Requires: Pointer to a posdata structure, members of which are
  331. * initialized.
  332. *
  333. * Returns: Void
  334. *
  335. *----------------------------------------------------------------------------*/
  336. void S_init(struct posdata *pdat);
  337. /*============================================================================
  338. * Void function S_decode
  339. *
  340. * This function decodes the error codes from S_solpos return value
  341. *
  342. * INPUTS: Long integer S_solpos return value, struct posdata*
  343. *
  344. * OUTPUTS: Descriptive text of errors to stderr
  345. *----------------------------------------------------------------------------*/
  346. void S_decode(long code, struct posdata *pdat);