Jump to content

Air mass: Difference between revisions

2,717 bytes added ,  2 years ago
Add Seed7
(Added Go)
(Add Seed7)
Line 692:
90 │ 34.32981136 34.36666557
─────┴─────────────────────────────────────────────────────────────
</pre>
 
=={{header|Seed7}}==
{{trans|FreeBASIC}}
<lang seed7>$ include "seed7_05.s7i";
include "float.s7i";
include "math.s7i";
 
const float: DEG is 0.017453292519943295769236907684886127134; #degrees to radians
const float: RE is 6371000.0; #Earth radius in meters
const float: dd is 0.001; #integrate in this fraction of the distance already covered
const float: FIN is 10000000.0; #integrate only to a height of 10000km, effectively infinity
 
const func float: rho (in float: a) is
#the density of air as a function of height above sea level
return exp(-a / 8500.0);
 
const func float: height (in float: a, in float: z, in float: d) is func
#a is altitude of observer
#z is zenith angle (in degrees)
#d is distance along line of sight
result
var float: r is 0.0;
local
var float: AA is 0.0;
var float: HH is 0.0;
begin
AA := RE + a;
HH := sqrt( AA ** 2.0 + d ** 2.0 - 2.0 * d * AA * cos((180.0 - z) * DEG) );
r := HH - RE;
end func;
 
const func float: columnDensity (in float: a, in float: z) is func
#integrates density along line of sight
result
var float: sum is 0.0;
local
var float: d is 0.0;
var float: delta is 0.0;
begin
while d < FIN do
delta := max(dd, dd * d); #adaptive step size to avoid taking it forever
sum +:= rho(height(a, z, d + 0.5 * delta)) * delta;
d +:= delta;
end while;
end func;
 
const func float: airmass (in float: a, in float: z) is
return columnDensity(a, z) / columnDensity(a, 0.0);
 
const proc: main is func
local
var integer: zz is 0;
var float: z is 0.0;
begin
writeln("Angle 0 m 13700 m");
writeln("------------------------------------");
for zz range 0 to 90 step 5 do
z := flt(zz);
write(z lpad 4);
write(airmass(0.0, z) digits 8 lpad 15);
writeln(airmass(13700.0, z) digits 8 lpad 17);
end for;
end func;</lang>
{{out}}
<pre>
Angle 0 m 13700 m
------------------------------------
0.0 1.00000000 1.00000000
5.0 1.00380963 1.00380965
10.0 1.01538466 1.01538475
15.0 1.03517744 1.03517765
20.0 1.06399053 1.06399093
25.0 1.10305937 1.10306005
30.0 1.15418974 1.15419083
35.0 1.21998076 1.21998246
40.0 1.30418931 1.30419190
45.0 1.41234169 1.41234567
50.0 1.55280404 1.55281025
55.0 1.73875921 1.73876915
60.0 1.99212000 1.99213665
65.0 2.35199740 2.35202722
70.0 2.89531368 2.89537287
75.0 3.79582352 3.79596149
80.0 5.53885809 5.53928113
85.0 10.07896219 10.08115981
90.0 34.32981136 34.36666557
</pre>
 
1,808

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.