Air mass: Difference between revisions

6,516 bytes added ,  3 years ago
→‎{{header|REXX}}: added the computer programming language REXX.
m (added whitespace.)
(→‎{{header|REXX}}: added the computer programming language REXX.)
Line 148:
=={{header|REXX}}==
{{trans|FreeBASIC}}
<lang rexx>/*REXX pgm calculates the air mass above an observer and an object for various angles.*/
<lang rexx></lang>
numeric digits (length(pi()) - length(.)) % 4 /*calculate the number of digits to use*/
output
parse arg aLO aHI aBY oHT . /*obtain optional arguments from the CL*/
<pre>
if aLO=='' | aLO=="," then aLO= 0 /*not specified? Then use the default.*/
if aHI=='' | aHI=="," then aHI= 90 /* " " " " " " */
if aBY=='' | aBY=="," then aBY= 5 /* " " " " " " */
if oHT=='' | oHT=="," then oHT= 13700 /* " " " " " " */
w= 30; @ama= 'air mass at' /*column width for the two air_masses. */
say 'angle|'center(@ama "sea level", w) center(@ama comma(oHT) "meters", w)
say '─────┼'copies(center("", w, '─'), 2)'─'
y= left('', w-20) /*pad for alignment of the output cols.*/
 
do j=aLO to aHI by aBY; am0= airM(0, j); amht= airM(oHT, j)
say center(j, 5)'│'right( format(am0, , 8), w-10)y right( format(amht, , 8), w-10)y
end /*j*/
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
airM: procedure; parse arg a,z; if z==0 then return 1; return colD(a, z) / colD(a, 0)
d2r: return r2r( arg(1) * pi() / 180) /*convert degrees ──► radians. */
pi: pi= 3.1415926535897932384626433832795028841971693993751058209749445923078; return pi
rho: procedure; parse arg a; return exp(-a / 8500)
r2r: return arg(1) // (pi() * 2) /*normalize radians ──► a unit circle. */
e: e= 2.718281828459045235360287471352662497757247093699959574966967627724; return e
comma: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ?
/*──────────────────────────────────────────────────────────────────────────────────────*/
cos: procedure; parse arg x; x= r2r(x); a= abs(x); numeric fuzz min(6, digits() - 3)
hpi= pi*.5; if a=pi then return -1; if a=hpi | a=hpi*3 then return 0; z= 1
if a=pi/3 then return .5; if a=pi*2/3 then return -.5; _= 1
x= x*x; p= z; do k=2 by 2; _= -_ * x / (k*(k-1)); z= z + _
if z=p then leave; p= z; end; return z
/*──────────────────────────────────────────────────────────────────────────────────────*/
exp: procedure; parse arg x; ix= x%1; if abs(x-ix)>.5 then ix= ix + sign(x); x= x-ix
z=1; _=1; w=z; do j=1; _= _*x/j; z=(z+_)/1; if z==w then leave; w=z; end
if z\==0 then z= z * e() ** ix; return z/1
/*──────────────────────────────────────────────────────────────────────────────────────*/
sqrt: procedure; parse arg x; if x=0 then return 0; d= digits(); numeric digits; h= d+6
numeric form; parse value format(x,2,1,,0) 'E0' with g 'E' _ .; g= g * .5'e'_ % 2
m.=9; do j=0 while h>9; m.j= h; h= h%2 + 1; end /*j*/
do k=j+5 to 0 by -1; numeric digits m.k; g= (g+x/g)*.5; end /*k*/
numeric digits d; return g/1
/*──────────────────────────────────────────────────────────────────────────────────────*/
elev: procedure; parse arg a,z,d; earthRad= 6371000 /*earth radius in meters.*/
aa= earthRad + a; return sqrt(aa**2 + d**2 - 2*d*aa*cos( d2r(180-z) ) ) - earthRad
/*──────────────────────────────────────────────────────────────────────────────────────*/
colD: procedure; parse arg a,z; sum= 0; d= 0; dd= .001; infinity= 10000000
do while d<infinity; delta= max(dd, dd*d)
sum= sum + rho( elev(a, z, d + 0.5*delta) ) * delta; d= d + delta
end /*while*/
return sum</lang>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
angle| air mass at sea level air mass at 13,700 meters
─────┼─────────────────────────────────────────────────────────────
0 │ 1.00000000 1.00000000
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.30419190
45 │ 1.41234169 1.41234567
50 │ 1.55280404 1.55281025
55 │ 1.73875921 1.73876915
60 │ 1.99212000 1.99213665
65 │ 2.35199740 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
</pre>