Air mass: Difference between revisions

4,096 bytes added ,  6 months ago
m
No edit summary
m (→‎{{header|Wren}}: Minor tidy)
 
(5 intermediate revisions by 5 users not shown)
Line 20:
{{trans|Python}}
 
<syntaxhighlight lang="11l">V DEG = 0.017453292519943295769236907684886127134
V RE = 6371000
V dd = 0.001
Line 81:
{{trans|C}}
{{works with|Ada 2012}}
<syntaxhighlight lang=Ada"ada">
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Numerics.Generic_Elementary_Functions;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
 
procedure Main is
Line 140 ⟶ 141:
Put_Line ("------------------------------------");
while z <= 90.0 loop
Put (Item => Integer(z), Exp => 0, ForeWidth => 2, Aft => 0);
Put (Item => air_mass (0.0, z), Fore => 68, Aft => 8, Exp => 0);
Put (Item => air_mass (13_700.0, z), Fore => 8, Aft => 8, Exp => 0);
New_Line;
z := z + 5.0;
end loop;
 
end Main;
</syntaxhighlight>
Line 152 ⟶ 154:
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>
 
=={{header|AWK}}==
<syntaxhighlight lang=AWK"awk">
# syntax: GAWK -f AIR_MASS.AWK
# converted from FreeBASIC
Line 238 ⟶ 240:
==={{header|BASIC256}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="freebasic">global RE, dd, LIM
RE = 6371000 #Earth radius in meters
dd = 0.001 #integrate in this fraction of the distance already covered
Line 285 ⟶ 287:
 
==={{header|FreeBASIC}}===
<syntaxhighlight lang="freebasic">
#define DEG 0.017453292519943295769236907684886127134 'degrees to radians
#define RE 6371000 'Earth radius in meters
Line 355 ⟶ 357:
==={{header|True BASIC}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="qbasic">FUNCTION max(a, b)
IF a > b then LET max = a else LET max = b
END FUNCTION
Line 402 ⟶ 404:
=={{header|C}}==
{{trans|FreeBASIC}}
<syntaxhighlight lang="c">#include <math.h>
#include <stdio.h>
 
Line 475 ⟶ 477:
90 34.32981136 34.36666557
</pre>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{trans|GO}}
{{libheader|SysUtils,StdCtrls}}
 
<syntaxhighlight lang="Delphi">
 
const RE = 6371000; { radius of earth in meters}
const DD = 0.001; { integrate in this fraction of the distance already covered}
const FIN = 1e7; { integrate only to a height of 10000km, effectively infinity}
 
function rho(a: double): double;
{ The density of air as a function of height above sea level.}
begin
Result:=Exp(-a / 8500);
end;
 
function Radians(degrees: double): double;
{ Converts degrees to radians}
begin
Result:= degrees * Pi / 180
end;
 
function Height(A, Z, D: double): double;
{ a = altitude of observer}
{ z = zenith angle (in degrees)}
{ d = distance along line of sight}
var AA,HH: double;
begin
AA := RE + A;
HH := Sqrt(AA*AA + D*D - 2*D*AA*Cos(Radians(180-z)));
Result:= HH - RE;
end;
 
function ColumnDensity(A, Z: double): double;
{ Integrates density along the line of sight.}
var Sum,D,Delta: double;
begin
Sum := 0.0;
D := 0.0;
while D < FIN do
begin
delta := Max(DD, DD*D); { adaptive step size to avoid it taking forever}
Sum:=Sum + Rho(Height(A, Z, D+0.5*Delta)) * Delta;
D:=D + delta;
end;
Result:= Sum;
end;
 
 
function AirMass(A, Z: double): double;
begin
Result:= ColumnDensity(A, Z) / ColumnDensity(a, 0);
end;
 
procedure ShowAirMass(Memo: TMemo);
var Z: integer;
begin
Memo.Lines.Add('Angle 0 m 13700 m');
Memo.Lines.Add('------------------------------------');
Z:=0;
while Z<=90 do
begin
Memo.Lines.Add(Format('%2d %11.8f %11.8f', [z, airmass(0, Z), airmass(13700, Z)]));
Z:=Z+5;
end;
end;
 
 
 
</syntaxhighlight>
{{out}}
<pre>
Angle 0 m 13700 m
------------------------------------
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
 
Elapsed Time: 189.304 ms.
 
</pre>
 
 
=={{header|EasyLang}}==
{{trans|FreeBASIC}}
 
<syntaxhighlight lang=easylang>
func rho a .
return pow 2.718281828459 (-a / 8500)
.
func height a z d .
AA = 6371000 + a
HH = sqrt (AA * AA + d * d - 2 * d * AA * cos (180 - z))
return HH - 6371000
.
func density a z .
while d < 10000000
delta = higher 0.001 (0.001 * d)
sum += rho height a z (d + 0.5 * delta) * delta
d += delta
.
return sum
.
func airmass a z .
return density a z / density a 0
.
numfmt 8 2
print "Angle 0 m 13700 m"
print "------------------------"
for z = 0 step 5 to 90
print z & " " & airmass 0 z & " " & airmass 13700 z
.
</syntaxhighlight>
 
=={{header|Factor}}==
{{trans|FreeBASIC}}
{{works with|Factor|0.99 2021-02-05}}
<syntaxhighlight lang="factor">USING: formatting io kernel math math.functions math.order
math.ranges math.trig sequences ;
 
Line 538 ⟶ 671:
90 34.32981136 34.36666557
</pre>
 
 
=={{header|Go}}==
{{trans|FreeBASIC}}
<syntaxhighlight lang="go">package main
 
import (
Line 622 ⟶ 754:
=={{header|Java}}==
{{trans|FreeBASIC}}
<syntaxhighlight lang="java">public class AirMass {
public static void main(String[] args) {
System.out.println("Angle 0 m 13700 m");
Line 698 ⟶ 830:
 
'''Preliminaries'''
<syntaxhighlight lang="jq">def pi: 4 * (1|atan);
 
def radians: . * pi / 180;
Line 724 ⟶ 856:
| lpad($width);</syntaxhighlight>
'''Physics'''
<syntaxhighlight lang="jq"># constants
def RE: 6371000; # radius of earth in meters
def DD: 0.001; # integrate in this fraction of the distance already covered
Line 782 ⟶ 914:
=={{header|Julia}}==
{{trans|FreeBASIC}}
<syntaxhighlight lang="julia">using Printf
 
const DEG = 0.017453292519943295769236907684886127134 # degrees to radians
Line 841 ⟶ 973:
=={{header|Nim}}==
{{trans|Wren}}
<syntaxhighlight lang=Nim"nim">import math, strformat
 
const
Line 907 ⟶ 1,039:
=={{header|Perl}}==
{{trans|Raku}}
<syntaxhighlight lang="perl">use strict;
use warnings;
use feature <say signatures>;
Line 978 ⟶ 1,110:
 
=={{header|Phix}}==
<!--<syntaxhighlight lang=Phix"phix">(phixonline)-->
<span style="color: #008080;">constant</span> <span style="color: #000000;">RE</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">6371000</span><span style="color: #0000FF;">,</span> <span style="color: #000080;font-style:italic;">// radius of earth in meters</span>
<span style="color: #000000;">DD</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0.001</span><span style="color: #0000FF;">,</span> <span style="color: #000080;font-style:italic;">// integrate in this fraction of the distance already covered</span>
Line 1,041 ⟶ 1,173:
 
=={{header|Python}}==
<syntaxhighlight lang="python">""" Rosetta Code task: Air_mass """
 
from math import sqrt, cos, exp
Line 1,104 ⟶ 1,236:
=={{header|Raku}}==
{{trans|FreeBASIC}}
<syntaxhighlight lang=perl6"raku" line>constant DEG = pi/180; # degrees to radians
constant RE = 6371000; # Earth radius in meters
constant dd = 0.001; # integrate in this fraction of the distance already covered
Line 1,168 ⟶ 1,300:
=={{header|REXX}}==
{{trans|FreeBASIC}}
<syntaxhighlight lang="rexx">/*REXX pgm calculates the air mass above an observer and an object for various angles.*/
numeric digits (length(pi()) - length(.)) % 4 /*calculate the number of digits to use*/
parse arg aLO aHI aBY oHT . /*obtain optional arguments from the CL*/
Line 1,243 ⟶ 1,375:
90 │ 34.32981136 34.36666557
─────┴─────────────────────────────────────────────────────────────
</pre>
 
=={{header|RPL}}==
{{trans|FreeBASIC}}
≪ → a ≪ a NEG 8500 / EXP ≫ ≫ ‘'''RHO'''’ STO
≪ ''''RHO'''(√(aa^2+D^2-2*aa*D*COS(180-Z))-re)' EVAL
≫ ‘'''COLD'''’ STO
6371000 3 PICK OVER + → a z re aa
≪ DEG
z 'Z' STO ''''COLD'''' { D 0 1E7 } 1E-7 ∫ DROP
0 'Z' STO ''''COLD'''' { D 0 1E7 } 1E-7 ∫ DROP /
≫ ≫ ‘'''AM'''’ STO
 
≪ { } 0 90 '''FOR''' z z + z '''AM''' + 5 '''STEP''' ≫
{{out}}
<pre>
1: { 0 1
5 1.00380686363
10 1.01537368745
15 1.03515302646
20 1.06394782383
25 1.10299392042
30 1.15409753978
35 1.21985818096
40 1.30403285254
45 1.41214767977
50 1.55256798138
55 1.73847475415
60 1.99177718552
65 2.35157928673
70 2.89478919419
75 3.79512945489
80 5.53784169364
85 10.0771111633
90 34.3235064081 }
</pre>
 
=={{header|Rust}}==
{{trans|FreeBASIC}}
<syntaxhighlight lang="rust">const RE: f64 = 6371000.0; // Earth radius in meters
const DD: f64 = 0.001; // integrate in this fraction of the distance already covered
const FIN: f64 = 10000000.0; // integrate only to a height of 10000km, effectively infinity
Line 1,325 ⟶ 1,495:
=={{header|Seed7}}==
{{trans|FreeBASIC}}
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i";
include "float.s7i";
include "math.s7i";
Line 1,414 ⟶ 1,584:
{{trans|Go}}
 
<syntaxhighlight lang="swift">import Foundation
 
extension Double {
Line 1,491 ⟶ 1,661:
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang=ecmascript"wren">import "./math" for Math
import "./fmt" for Fmt
 
// constants
Line 1,560 ⟶ 1,730:
=={{header|XPL0}}==
{{trans|FreeBASIC}}
<syntaxhighlight lang=XPL0"xpl0">define DEG = 0.017453292519943295769236907684886127134; \degrees to radians
define RE = 6371000.; \Earth radius in meters
define DD = 0.001; \integrate in this fraction of the distance already covered
9,476

edits