Soil Water Balance (SWB2)
Loading...
Searching...
No Matches
solar_calculations.F90
Go to the documentation of this file.
2
3 use iso_c_binding
6 use exceptions
7 implicit none
8
9 real (c_float) :: earth_sun_dist_dr
10 real (c_float) :: solar_declination_delta
11
12contains
13
14 !> Calculate the number of daylight hours at a location.
15 !!
16 !! @param[in] dOmega_s Sunset hour angle in Radians.
17 !! @retval rN Number of daylight hours.
18 !!
19 !! @note Implementation follows equation 34, Allen and others (1998).
20 !!
21 !! @note Allen, R.G., and others, 1998, FAO Irrigation and Drainage Paper No. 56,
22 !! "Crop Evapotranspiration (Guidelines for computing crop water
23 !! requirements)", Food and Agriculture Organization, Rome, Italy.
24 function daylight_hours( dOmega_s ) result(dN) bind(c)
25
26 real (c_double), intent(in) :: domega_s
27 real (c_double) :: dn
28
29 dn = 24_c_double / pi * domega_s
30
31 end function daylight_hours
32
33
34! ***** TO ACCESS THE ABOVE FUNCTION FROM PYTHON VIA CTYPES (once the proper shared library has been created):
35! from ctypes import *
36! libf = CDLL("libsntemp_lib.dylib")
37! libf.daylight_hours.restype = c_double
38! libf.daylight_hours(byref(c_double(0.8)))
39
40! IF one does not wish to add the 'byref' function call as shown above, the Fortran code itself
41! may be modified to force values to be passed by value rather than by reference:
42!
43! subroutine daylight_hours_c(dOmega_s, dN) bind(c, name="daylight_hours_c")
44!
45! real (c_double), intent(in), value :: dOmega_s
46! real (c_double), intent(out) :: dN
47!
48! dN = daylight_hours(dOmega_s)
49!
50! end subroutine daylight_hours_c
51
52 !------------------------------------------------------------------------------------------------
53
54 !> Calculate extraterrestrial radiation given latitude and time of year.
55 !!
56 !! @param[in] dLatitude Latitude of grid cell in RADIANS.
57 !! @param[in] dDelta Solar declination in RADIANS.
58 !! @param[in] dOmega_s Sunset hour angle in RADIANS.
59 !! @param[in] dDsubR Inverse relative distance Earth-Sun.
60 !!
61 !! @retval rRa Extraterrestrial radiation in MJ / m**2 / day.
62 !!
63 !! @note 1 MJ = 1e6 Joules; 1 Joule = 1 Watt / sec.
64 !! @note Therefore, multiply by 1e6 and divide by 86400 to get W/m*2-day.
65 !!
66 !! @note Source
67 !! Equation 21, Allen and others (1998).
68 !!
69 !! @note Reference
70 !! Allen, R.G., and others, 1998, FAO Irrigation and Drainage Paper No. 56,
71 !! "Crop Evapotranspiration (Guidelines for computing crop water
72 !! requirements)", Food and Agriculture Organization, Rome, Italy.
73 !!
74 !! @sa http://www.fao.org/docrep/x0490e/x0490e07.htm#solar%20radiation
75
76 elemental function extraterrestrial_radiation__ra(dLatitude, dDelta, dOmega_s, dDsubR) result(dRa)
77
78 ! [ ARGUMENTS ]
79 real (c_double), intent(in) :: dlatitude
80 real (c_double), intent(in) :: ddelta
81 real (c_double), intent(in) :: domega_s
82 real (c_double), intent(in) :: ddsubr
83
84 ! [ LOCALS ]
85 real (c_double) :: dra
86 real (c_double) :: dparta, dpartb
87 real (c_double), parameter :: dgsc = 0.0820_c_double ! MJ / m**2 / min
88
89 dparta = domega_s * sin( dlatitude ) * sin( ddelta )
90 dpartb = cos( dlatitude ) * cos( ddelta ) * sin( domega_s )
91
92 dra = 24_c_double * 60_c_double * dgsc * ddsubr * ( dparta + dpartb ) / pi
93
95
96
97 !------------------------------------------------------------------------------------------------
98
99 !> Calculate net shortwave radiation
100 !!
101 !! @param[in] dRs Incoming shortwave solar radiation, in MJ / m**2 / day
102 !! @param[in] dAlbedo Albedo or canopy reflection coefficient; 0.23 for grass reference crop
103 !! @retval dRns Net shortwave radiation, in MJ / m**2 / day
104 !!
105 !! @note Implementation follows equation 38, Allen and others (1998).
106 !!
107 !! @note Reference:
108 !! Allen, R.G., and others, 1998, FAO Irrigation and Drainage Paper No. 56,
109 !! "Crop Evapotranspiration (Guidelines for computing crop water
110 !! requirements)", Food and Agriculture Organization, Rome, Italy.
111
112 function net_shortwave_radiation__rns(dRs, dAlbedo) result(dRns)
113
114 real(c_double), intent(in) :: drs
115 real(c_double), intent(in) :: dalbedo
116
117 ! [ LOCALS ]
118 real(c_double) :: drns
119
120 drns = (1_c_double - dalbedo) * drs
121
123
124 !------------------------------------------------------------------------------------------------
125
126 !> Calculate the solar declination for a given day of the year.
127 !!
128 !! @param[in] iDayOfYear Integer day of the year (January 1 = 1)
129 !! @param[in] iNumDaysInYear Number of days in the current year
130 !! @retval dDelta Solar declination, in RADIANS
131 !!
132 !! @note Implementation follows equation XXX? in:
133 !!
134 !! @note Allen, R.G., and others, 1998, FAO Irrigation and Drainage Paper No. 56,
135 !! "Crop Evapotranspiration (Guidelines for computing crop water
136 !! requirements)", Food and Agriculture Organization, Rome, Italy.
137
138 elemental function solar_declination_simple__delta(iDayOfYear, iNumDaysInYear) result(dDelta)
139
140 integer (c_int), intent(in) :: idayofyear
141 integer (c_int), intent(in) :: inumdaysinyear
142 real (c_double) :: ddelta
143
144 ddelta = 0.409_c_double &
145 * sin( (twopi * real(idayofyear, c_double) / real(inumdaysinyear, c_double) ) &
146 - 1.39_c_double)
147
149
150
151 !------------------------------------------------------------------------------------------------
152
153 !> Calculate the solar declination for a given day of the year.
154 !!
155 !! @param[in] iDayOfYear Integer day of the year (January 1 = 1)
156 !! @param[in] iNumDaysInYear Number of days in the current year
157 !! @retval dDelta Solar declination, in RADIANS
158 !!
159 !! @note Implementation follows equation 1.3.1 in Iqbal (1983).
160 !!
161 !! @note Iqbal (1983) reports maximum error of 0.0006 radians; if the last two terms are omitted,
162 !! the reported accuracy drops to 0.0035 radians.
163 !!
164 !! @note Reference:
165 !! Iqbal, Muhammad (1983-09-28). An Introduction To Solar Radiation (p. 10). Elsevier Science. Kindle Edition.
166
167 elemental function solar_declination__delta(iDayOfYear, iNumDaysInYear) result(dDelta)
168
169 integer (c_int), intent(in) :: idayofyear
170 integer (c_int), intent(in) :: inumdaysinyear
171 real (c_double) :: ddelta
172
173 ! [ LOCALS ]
174 real (c_double) :: dgamma
175
176 dgamma = day_angle__gamma( idayofyear, inumdaysinyear )
177
178 ddelta = 0.006918_c_double &
179 - 0.399912_c_double * cos( dgamma ) &
180 + 0.070257_c_double * sin( dgamma ) &
181 - 0.006758_c_double * cos( 2.0_c_double * dgamma ) &
182 + 0.000907_c_double * sin( 2.0_c_double * dgamma ) &
183 - 0.002697_c_double * cos( 3.0_c_double * dgamma ) &
184 + 0.00148_c_double * sin( 3.0_c_double * dgamma )
185
186
187 end function solar_declination__delta
188
189
190 !------------------------------------------------------------------------------------------------
191
192 !> Calculate the inverse relative Earth-Sun distance for a given day of the year.
193 !!
194 !! @param[in] iDayOfYear Integer day of the year (January 1 = 1)
195 !! @param[in] iNumDaysInYear Number of days in the current year
196 !! @retval dDsubR Relative Earth-Sun distance
197 !!
198 !! @note Implementation follows equation 23, Allen and others (1998): <BR>
199 !! @f$ d_r = 1 + 0.033 \cos \left( \frac{ 2 \pi }{365} J \right) @f$ <BR><BR>
200 !! where: <BR>
201 !! @f$ d_r @f$ is the inverse relative distance between Earth and the Sun <BR>
202 !! @f$ J @f$ is the current day of the year <BR>
203 !!
204 !! @note References:
205 !! Allen, R.G., and others, 1998, FAO Irrigation and Drainage Paper No. 56,
206 !! "Crop Evapotranspiration (Guidelines for computing crop water
207 !! requirements)", Food and Agriculture Organization, Rome, Italy.
208 !!
209 !! @note Duffie, J.A., Beckman, W.A. Solar Engineering of Thermal Processes. New York: Wiley, 1980.
210 !!
211 !! @note Equation 1.2.3 in Iqbal, Muhammad (1983-09-28). An Introduction To Solar Radiation (p. 28).
212 !! Elsevier Science. Kindle Edition.
213
214 elemental function relative_earth_sun_distance__d_r( iDayOfYear, iNumDaysInYear ) result( dDsubR )
215
216 ! [ ARGUMENTS ]
217 integer (c_int), intent(in) :: idayofyear
218 integer (c_int), intent(in) :: inumdaysinyear
219 real (c_double) :: ddsubr
220
221 ddsubr = 1.0_c_double + 0.033_c_double &
222 * cos( twopi * real( idayofyear, c_double ) &
223 / real( inumdaysinyear, c_double ) )
224
226
227 !------------------------------------------------------------------------------------------------
228
229 !> Calculate sunrise/sunset angle, in RADIANS.
230 !!
231 !! @param[in] dLatitude Latitude, in RADIANS
232 !! @param[in] dDelta Solar declination, in RADIANS
233 !! @retval dOmega_s Sunset angle, in RADIANS
234 !!
235 !! @note Implementation follows equation 25, Allen and others (1998).
236 !!
237 !! @note Hour angle is zero at solar noon. Definition in Iqbal (1983) yields positive values before solar noon,
238 !! and negative values following solar noon.
239 !!
240 !! @note Reference:
241 !! Allen, R.G., and others, 1998, FAO Irrigation and Drainage Paper No. 56,
242 !! "Crop Evapotranspiration (Guidelines for computing crop water
243 !! requirements)", Food and Agriculture Organization, Rome, Italy.
244
245 elemental function sunrise_sunset_angle__omega_s( dLatitude, dDelta ) result( dOmega_s )
246
247 real (c_double), intent(in) :: dlatitude
248 real (c_double), intent(in) :: ddelta
249 real (c_double) :: domega_s
250
251 domega_s = acos( - tan(dlatitude) * tan(ddelta) )
252
254
255 !------------------------------------------------------------------------------------------------
256
257 !> Calculate shortwave solar radiation.
258 !!
259 !! Calculates the solar radiation using Hargreave's radiation formula.
260 !! For use when percent possible daily sunshine value is not available.
261 !!
262 !! @param[in] dRa Extraterrestrial radiation, in MJ / m**2 / day
263 !! @param[in] rTMin Minimum daily air temperature, in &deg;C
264 !! @param[in] rTMax Maximum daily air temperature, in &deg;C
265 !! @retval dRa Solar radiation, in MJ / m**2 / day
266 !!
267 !! @note Implementation follows equation 50, Allen and others (1998).
268 !!
269 !! @note Reference:
270 !! Allen, R.G., and others, 1998, FAO Irrigation and Drainage Paper No. 56,
271 !! "Crop Evapotranspiration (Guidelines for computing crop water
272 !! requirements)", Food and Agriculture Organization, Rome, Italy.
273
274 function solar_radiation_hargreaves__rs( dRa, fTMin, fTMax ) result( dRs ) bind(c)
275
276 real (c_double), intent(in) :: dra
277 real (c_float), intent(in) :: ftmin
278 real (c_float), intent(in) :: ftmax
279 real (c_double) :: drs
280
281 ! [ LOCALS ]
282 real (c_double), parameter :: dkrs = 0.175
283 real (c_double) :: tmink
284 real (c_double) :: tmaxk
285
286 tmink = c_to_k(real(ftmin, c_double))
287 tmaxk = c_to_k(real(ftmax, c_double))
288
289 drs = dkrs * sqrt( tmaxk - tmink ) * dra
290
292
293 !------------------------------------------------------------------------------------------------
294
295 !> Estimate percent of possible sunshine.
296 !!
297 !! This function follows from equation 5 in "The Rational Use of the FAO Blaney-Criddle
298 !! substituting the rearranged Hargreaves solar radiation formula into
299 !! equation 5 results in the formulation below
300 !!
301 !! @param[in] fTMax Maximum daily air temperature, in &deg;K
302 !! @param[in] fTMin Minimum daily air temperature, in &deg;K
303 !! @retval fPsun Percentage of possible sunshine, dimensionless percentage
304 !!
305 !! @todo [Need to add reference here...]
306
307 elemental function estimate_percent_of_possible_sunshine__psun(fTMax, fTMin) result(fPsun)
308
309 real (c_float), intent(in) :: ftmax ! Kelvin degrees
310 real (c_float), intent(in) :: ftmin ! Kelvin degrees
311 real (c_float) :: fpsun
312
313 ! [ LOCALS ]
314 real (c_float), parameter :: fkrs = 0.175
315
316 fpsun = ( 2_c_float * fkrs * sqrt( ftmax - ftmin ) ) - 0.5_c_float
317
318 if ( fpsun < 0_c_float ) then
319 fpsun = 0_c_float
320 elseif ( fpsun > 1.0_c_float ) then
321 fpsun = 100_c_float
322 else
323 fpsun = fpsun * 100_c_float
324 endif
325
327
328 !------------------------------------------------------------------------------------------------
329
330 !> Calculate clear sky solar radiation.
331 !!
332 !! Calculate the clear sky solar radiation (i.e. when rPctSun = 100,
333 !! n/N=1. Required for computing net longwave radiation.
334 !!
335 !! @param[in] dRa Extraterrestrial radiation, in MJ / m**2 / day
336 !! @param[in] dAs Solar radiation regression constant, expressing the fraction
337 !! of extraterrestrial radiation that reaches earth on OVERCAST days.
338 !! @param[in] sBs Solar radiation regression constant. As + Bs express the fraction
339 !! of extraterrestrial radiation that reaches earth on CLEAR days.
340 !! @retval dRso Clear sky solar radiation, in MJ / m**2 / day
341 !!
342 !! @note Implementation follows equation 36, Allen and others (1998).
343 !!
344 !! @note Reference:
345 !! Allen, R.G., and others, 1998, FAO Irrigation and Drainage Paper No. 56,
346 !! "Crop Evapotranspiration (Guidelines for computing crop water
347 !! requirements)", Food and Agriculture Organization, Rome, Italy.
348
349 function clear_sky_solar_radiation__rso( dRa, dAs, dBs ) result( dRso ) bind(c)
350
351 real (c_double), intent(in) :: dra
352 real (c_double), intent(in), optional :: das
353 real (c_double), intent(in),optional :: dbs
354 real (c_double) :: drso
355
356 ! [ LOCALS ]
357 real (c_double) :: das_l
358 real (c_double) :: dbs_l
359
360 ! assign default value to As if none is provided
361 if ( present( das ) ) then
362 das_l = das
363 else
364 das_l = 0.25_c_double
365 end if
366
367 ! assign default value to Bs if none is provided
368 if ( present( dbs ) ) then
369 dbs_l = dbs
370 else
371 dbs_l = 0.5_c_double
372 end if
373
374 drso = (das_l + dbs_l * dra)
375
377
378 !------------------------------------------------------------------------------------------------
379
380 !> Calculate the clear sky solar radiation.
381 !!
382 !! Calculate the clear sky solar radiation (i.e. when rPctSun = 100,
383 !! n/N=1. Required for computing net longwave radiation.
384 !! For use when no regression coefficients (A, B) are known.
385 !!
386 !! @param[in] dRa Extraterrestrial radiation, in MJ / m**2 / day
387 !! @param[in] fElevation Elevation, in METERS above sea level
388 !! @retval dRso Clear sky solar radiation, in MJ / m**2 / day
389 !!
390 !! @note Implementation follows equation 37, Allen and others (1998).
391 !!
392 !! @note Reference:
393 !! Allen, R.G., and others, 1998, FAO Irrigation and Drainage Paper No. 56,
394 !! "Crop Evapotranspiration (Guidelines for computing crop water
395 !! requirements)", Food and Agriculture Organization, Rome, Italy.
396
397 function clear_sky_solar_radiation_noab__rso(dRa, fElevation) result(dRso)
398
399 real (c_double), intent(in) :: dra
400 real (c_float), intent(in) :: felevation
401 real (c_double) :: drso
402
403 drso = ( 0.75_c_double + 1.0e-5_c_double * felevation ) * dra
404
406
407 !------------------------------------------------------------------------------------------------
408
409 !> Calculate solar radiation by means of the Angstrom formula.
410 !!
411 !! @param[in] dRa Extraterrestrial radiation in MJ / m**2 / day
412 !! @param[in] dAs Solar radiation regression constant, expressing the fraction
413 !! of extraterrestrial radiation that reaches earth on OVERCAST days.
414 !! @param[in] dBs Solar radiation regression constant. As + Bs express the fraction
415 !! of extraterrestrial radiation that reaches earth on CLEAR days.
416 !! @param[in] fPctSun Percent of TOTAL number of sunshine hours during which the
417 !! sun actually shown.
418 !! @retval fRs Solar radiation in MJ / m**2 / day
419 !!
420 !! @notes
421 !! Implementation follows equation 35, Allen and others (1998).
422 !!
423 !! Reference:
424 !! Allen, R.G., and others, 1998, FAO Irrigation and Drainage Paper No. 56,
425 !! "Crop Evapotranspiration (Guidelines for computing crop water
426 !! requirements)", Food and Agriculture Organization, Rome, Italy.
427
428 elemental function solar_radiation__rs(dRa, dAs, dBs, fPctSun) result(dRs)
429
430 real (c_double), intent(in) :: dra
431 real (c_double), intent(in) :: das
432 real (c_double), intent(in) :: dbs
433 real (c_double), intent(in) :: fpctsun
434 real (c_double) :: drs
435
436 drs = ( das + (dbs * fpctsun / 100_c_double ) ) * dra
437
438 end function solar_radiation__rs
439
440 !------------------------------------------------------------------------------------------------
441
442 !> Calculate net longwave radiation flux.
443 !!
444 !! @param[in] fTMin Minimum daily air temperature, in &deg;C
445 !! @param[in] fTMax Maximum daily air temperature, in &deg;C
446 !! @param[in] dRs Measured or calculated shortwave solar radiation, in MJ / m**2 / day
447 !! @param[in] dRso Calculated clear-sky radiation, in MJ / m**2 / day
448 !! @retval dRnl Net longwave solar radiation flux (incoming minus outgoing), in MJ / m**2 / day
449 !!
450 !! @note
451 !! Implementation follows equation 39, Allen and others (1998).
452 !!
453 !! @note
454 !! Reference:
455 !! Allen, R.G., and others, 1998, FAO Irrigation and Drainage Paper No. 56,
456 !! "Crop Evapotranspiration (Guidelines for computing crop water
457 !! requirements)", Food and Agriculture Organization, Rome, Italy.
458
459 elemental function net_longwave_radiation__rnl(fTMin, fTMax, dRs, dRso) result(dRnl)
460
461 real(c_float), intent(in) :: ftmin
462 real(c_float), intent(in) :: ftmax
463 real(c_double), intent(in) :: drs
464 real(c_double), intent(in) :: drso
465 real(c_double) :: drnl
466
467 ! [ LOCALS ]
468 real(c_double) :: dtavg_k
469 real(c_double) :: dtavg_4
470 real (c_double) :: d_ea
471 real (c_double) :: dcloudfrac
472 real (c_double), parameter :: dsigma = 4.903e-9_c_double
473
474 dtavg_k = c_to_k((real(ftmin, c_double) + real(ftmax, c_double) ) / 2.0_c_double )
475
476 dtavg_4 = dtavg_k * dtavg_k * dtavg_k * dtavg_k * dsigma
477 d_ea = dewpoint_vapor_pressure__e_a( ftmin )
478
479 dcloudfrac = min( drs / drso, 1.0_c_double )
480
481 drnl = dtavg_4 * ( 0.34_c_double - 0.14_c_double * sqrt( d_ea ) ) &
482 * ( 1.35_c_double * dcloudfrac - 0.35_c_double )
483
484 end function net_longwave_radiation__rnl
485
486 !------------------------------------------------------------------------------------------------
487
488 !> Calculate the day angle in RADIANS.
489 !!
490 !! This function expresses the integer day number as an angle (in
491 !! radians). Output values range from 0 (on January 1st) to
492 !! just less than @f$ 2\pi @f$ on December 31st.
493 !!
494 !! @param[in] iDayOfYear Current day of the year.
495 !! @param[in] iNumDaysInYear Number of days in the current year.
496 !! @retval dGamma Day angle in RADIANS.
497 !!
498 !! @note Implementation follows equation 1.2.2 in Iqbal (1983)
499 !!
500 !! @note Reference:
501 !! Iqbal, Muhammad (1983-09-28). An Introduction To Solar Radiation (p. 3). Elsevier Science. Kindle Edition.
502
503 elemental function day_angle__gamma(iDayOfYear, iNumDaysInYear) result(dGamma)
504
505 integer (c_int), intent(in) :: idayofyear
506 integer (c_int), intent(in) :: inumdaysinyear
507 real (c_double) :: dgamma
508
509 dgamma = twopi * ( real(idayofyear, c_double) - 1.0_c_double ) / real(inumdaysinyear, c_double)
510
511 end function day_angle__gamma
512
513 !------------------------------------------------------------------------------------------------
514
515
516 !> Calculate the solar altitude given the zenith angle.
517 !!
518 !! @param[in] rTheta_z Solar zenith angle for given location and time, in RADIANS
519 !!
520 !! @retval rAlpha Solar altitude angle for given location and time, in RADIANS
521
522 function solar_altitude__alpha( dTheta_z ) result( dAlpha ) bind(c)
523
524 real (c_double), intent(in) :: dtheta_z
525 real (c_double) :: dalpha
526
527 call assert( dtheta_z >= 0.0_c_double .and. dtheta_z <= halfpi, &
528 "Internal programming error: solar zenith angle must be in radians and in the range 0 to pi/2", &
529 __file__, __line__)
530
531 dalpha = halfpi - dalpha
532
533 end function solar_altitude__alpha
534
535
536 !------------------------------------------------------------------------------------------------
537
538 !> Calculate solar zenith angle given latitude, declination, and (optionally) hour angle.
539 !!
540 !! Calculate solar zenith. Solar zenith angle is the angle between a point directly overhead and
541 !! the center of the sun's disk.
542 !!
543 !! @param[in] rLatitude Latitude of location for which estimate is being made, in RADIANS
544 !! @param[in] rDelta Solar declination angle, in RADIANS
545 !! @param[in] rOmega [OPTIONAL] Hour angle, measured at the celestial pole between the observer's meridian
546 !! and the solar meridian, in RADIANS.
547 !!
548 !! @retval rTheta_z Solar zenith angle for given location and time, in RADIANS
549 !!
550 !! @note Implementation follows equation 9.67, Jacobson, 2005
551 !!
552 !! @note
553 !! Reference:
554 !! Jacobson, M.Z., 2005, Fundamentals of atmospheric modeling, Second Edition:
555 !! Cambridge University Press.
556
557 function zenith_angle__theta_z( dLatitude, dDelta, dOmega ) result( dTheta_z ) bind(c)
558
559 real (c_double), intent(in) :: dlatitude
560 real (c_double), intent(in) :: ddelta
561 real (c_double), intent(in), optional :: domega
562
563 ! [ LOCALS ]
564 real (c_double) :: dtheta_z
565 real (c_double) :: domega_l
566
567 if ( present( domega ) ) then
568 domega_l = domega_l
569 else
570 domega_l = 0.0_c_double
571 endif
572
573 call assert( dlatitude <= halfpi .and. dlatitude >= -halfpi , &
574 "Internal programming error: Latitude must be expressed in RADIANS and range from -pi/2 to pi/2", &
575 __file__, __line__ )
576
577
578 dtheta_z = acos( sin(dlatitude) * sin(ddelta) + cos(dlatitude) * cos(ddelta) * cos(domega_l ) )
579
580 end function zenith_angle__theta_z
581
582 !------------------------------------------------------------------------------------------------
583
584 !> Calculate solar azimuth angle.
585 !!
586 !! @param[in] rAlpha Solar altitude angle, in RADIANS.
587 !! @param[in] rLatitude Latitude of location for which estimate is being made, in RADIANS.
588 !! @param[in] rDelta Solar declination angle, in RADIANS.
589 !!
590 !! @retval rPsi Solar azimuth angle, in RADIANS.
591 !!
592 !! @note Implementation follows equation 1.5.2a in Iqbal (1983).
593 !!
594 !! @note Reference:
595 !! Iqbal, Muhammad (1983-09-28). An Introduction To Solar Radiation (p. 15). Elsevier Science. Kindle Edition.
596
597 function azimuth_angle__psi(rAlpha, rLatitude, rDelta) result(rPsi) bind(c)
598
599 real (c_double), intent(in) :: ralpha
600 real (c_double), intent(in) :: rlatitude
601 real (c_double), intent(in) :: rdelta
602 real (c_double) :: rpsi
603
604 ! [ LOCALS ]
605 real (c_double) :: rtempval
606
607 rtempval = ( sin( ralpha ) * sin( rlatitude ) - sin( rdelta ) ) &
608 / ( cos( ralpha ) * cos( rlatitude ) )
609
610 ! avoid a NaN; cap value at 1.0
611 if ( abs( rtempval ) > 1.0_c_double ) rtempval = sign( 1.0_c_double, rtempval )
612
613 rpsi = acos( rtempval )
614
615 end function azimuth_angle__psi
616
617end module solar_calculations
This module contains physical constants and convenience functions aimed at performing unit conversion...
real(c_double), parameter, public twopi
real(c_double), parameter, public pi
real(c_double), parameter, public halfpi
elemental real(c_double) function dewpoint_vapor_pressure__e_a(ftmin)
real(c_double) function azimuth_angle__psi(ralpha, rlatitude, rdelta)
Calculate solar azimuth angle.
elemental real(c_double) function solar_declination_simple__delta(idayofyear, inumdaysinyear)
Calculate the solar declination for a given day of the year.
real(c_double) function solar_radiation_hargreaves__rs(dra, ftmin, ftmax)
Calculate shortwave solar radiation.
elemental real(c_double) function solar_declination__delta(idayofyear, inumdaysinyear)
Calculate the solar declination for a given day of the year.
elemental real(c_float) function estimate_percent_of_possible_sunshine__psun(ftmax, ftmin)
Estimate percent of possible sunshine.
real(c_float) earth_sun_dist_dr
real(c_double) function net_shortwave_radiation__rns(drs, dalbedo)
Calculate net shortwave radiation.
real(c_double) function solar_altitude__alpha(dtheta_z)
Calculate the solar altitude given the zenith angle.
real(c_double) function clear_sky_solar_radiation__rso(dra, das, dbs)
Calculate clear sky solar radiation.
real(c_double) function daylight_hours(domega_s)
Calculate the number of daylight hours at a location.
real(c_double) function clear_sky_solar_radiation_noab__rso(dra, felevation)
Calculate the clear sky solar radiation.
elemental real(c_double) function day_angle__gamma(idayofyear, inumdaysinyear)
Calculate the day angle in RADIANS.
elemental real(c_double) function relative_earth_sun_distance__d_r(idayofyear, inumdaysinyear)
Calculate the inverse relative Earth-Sun distance for a given day of the year.
elemental real(c_double) function sunrise_sunset_angle__omega_s(dlatitude, ddelta)
Calculate sunrise/sunset angle, in RADIANS.
elemental real(c_double) function extraterrestrial_radiation__ra(dlatitude, ddelta, domega_s, ddsubr)
Calculate extraterrestrial radiation given latitude and time of year.
elemental real(c_double) function net_longwave_radiation__rnl(ftmin, ftmax, drs, drso)
Calculate net longwave radiation flux.
elemental real(c_double) function solar_radiation__rs(dra, das, dbs, fpctsun)
Calculate solar radiation by means of the Angstrom formula.
real(c_float) solar_declination_delta
real(c_double) function zenith_angle__theta_z(dlatitude, ddelta, domega)
Calculate solar zenith angle given latitude, declination, and (optionally) hour angle.