Rebol3 Code Examplex


Air mass

Rebol [
    title: "Rosetta code: Air mass"
    file:  %Air_mass.r3
    url:   https://rosettacode.org/wiki/Air_mass
]

rho: function [
    "Air density ratio (relative to sea level) at altitude a (m), scale height 8500 m"
    a [number!]
][
    exp (a / -8500)
]

height: function [
    "Height above sea level (m) of the point distance d along the line of sight"
    a [number!] "from observer altitude a (m)"
    z [number!] "at zenith angle z (degrees)"
    d [number!]
][
    aa: 6371000 + a
    hh: sqrt ((aa * aa) + (d * d) - (2 * d * aa * cosine (180 - z)))
    hh - 6371000
]

density: function [
    "Integrate air density along the line of sight from altitude a at zenith angle z"
    a [number!] z [number!]
][
    d: sum: 0
    while [d < 10000000] [
        delta: max 0.001 (0.001 * d) ;; coarser steps further out
        sum: sum + ((rho height a z (d + (0.5 * delta))) * delta)
        d: d + delta
    ]
    sum
]

air-mass: function [
    "Relative airmass at altitude a (m) and zenith angle z (deg), normalized so airmass(a, 0) = 1"
    a [number!] z [number!]
][
    (density a z) / (density a 0)
]

print "Angle  0 m         13700 m"
print "------------------------------"
for z 0 90 5 [
    printf [" " 5 " " 11.00000001 " " 11.00000001] [z  air-mass 0 z  air-mass 13700 z]
]

Output:

Angle  0 m         13700 m
------------------------------
 0     1.0         1.0        
 5     1.00380963  1.00380965 
 10    1.01538466  1.01538475 
 15    1.03517744  1.03517765 
 20    1.06399053  1.06399093 
 25    1.10305937  1.10306005 
 30    1.15418974  1.15419083 
 35    1.21998076  1.21998246 
 40    1.30418931  1.3041919  
 45    1.41234169  1.41234567 
 50    1.55280404  1.55281025 
 55    1.73875921  1.73876915 
 60    1.99212     1.99213665 
 65    2.3519974   2.35202722 
 70    2.89531368  2.89537287 
 75    3.79582352  3.79596149 
 80    5.53885809  5.53928113 
 85    10.07896219 10.08115981
 90    34.32981136 34.36666557