Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,51 +0,0 @@
|
|||
-----------------------------------------------------------------------
|
||||
-- Angle difference between two bearings
|
||||
-----------------------------------------------------------------------
|
||||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
|
||||
procedure Bearing_Angles is
|
||||
type Real is digits 8;
|
||||
Package Real_Io is new Ada.Text_IO.Float_IO(Real);
|
||||
use Real_IO;
|
||||
type Angles is record
|
||||
B1 : Real;
|
||||
B2 : Real;
|
||||
end record;
|
||||
type Angle_Arr is array(Positive range <>) of Angles;
|
||||
|
||||
function fmod(Left, Right : Real) return Real is
|
||||
Result : Real;
|
||||
begin
|
||||
Result := Left - Right*Real'Truncation(Left / Right);
|
||||
return Result;
|
||||
end fmod;
|
||||
|
||||
The_Angles : Angle_Arr := ((20.0,45.0),(-45.0, 45.0), (-85.0, 90.0),
|
||||
(-95.0, 90.0), (-14.0, 125.0), (29.4803, -88.6381),
|
||||
(-78.3251, -159.036),
|
||||
(-70099.74233810938, 29840.67437876723),
|
||||
(-165313.6666297357, 33693.9894517456),
|
||||
(1174.8380510598456, -154146.66490124757),
|
||||
(60175.77306795546, 42213.07192354373));
|
||||
Diff : Real;
|
||||
|
||||
begin
|
||||
|
||||
for A of The_Angles loop
|
||||
Diff := fmod(A.b2 - A.b1, 360.0);
|
||||
If Diff < -180.0 then
|
||||
Diff := Diff + 360.0;
|
||||
elsif Diff > 180.0 then
|
||||
Diff := Diff - 360.0;
|
||||
end if;
|
||||
|
||||
Put("Difference between ");
|
||||
Put(Item => A.B2, Fore => 7, Aft => 4, Exp => 0);
|
||||
Put(" and ");
|
||||
Put(Item => A.B1, Fore => 7, Aft => 4, Exp => 0);
|
||||
Put(" is ");
|
||||
Put(Item => Diff, Fore => 4, Aft => 4, Exp => 0);
|
||||
New_Line;
|
||||
end loop;
|
||||
|
||||
end Bearing_Angles;
|
||||
|
|
@ -1,149 +0,0 @@
|
|||
******************************************************************
|
||||
* COBOL solution to Angle difference challange
|
||||
* The program was run on OpenCobolIDE
|
||||
* I chose to read the input data from a .txt file that I
|
||||
* created on my PC rather than to hard code it into the
|
||||
* program or enter it as the program was executing.
|
||||
******************************************************************
|
||||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. ANGLE-DIFFERENCE.
|
||||
|
||||
ENVIRONMENT DIVISION.
|
||||
INPUT-OUTPUT SECTION.
|
||||
FILE-CONTROL.
|
||||
|
||||
SELECT IN-FILE ASSIGN TO 'C:\Both\Rosetta\Angle_diff.txt'
|
||||
ORGANIZATION IS LINE SEQUENTIAL.
|
||||
|
||||
DATA DIVISION.
|
||||
|
||||
FILE SECTION.
|
||||
FD IN-FILE.
|
||||
01 IN-RECORD.
|
||||
05 ALPHA-BEARING-1 PIC X(20).
|
||||
05 FILLER PIC X.
|
||||
05 ALPHA-BEARING-2 PIC X(20).
|
||||
|
||||
WORKING-STORAGE SECTION.
|
||||
01 SWITCHES.
|
||||
05 EOF-SWITCH PIC X VALUE 'N'.
|
||||
|
||||
01 COUNTERS.
|
||||
05 REC-CTR PIC 9(3) VALUE 0.
|
||||
|
||||
01 WS-ALPHA-BEARING.
|
||||
05 WS-AB-SIGN PIC X.
|
||||
88 WS-AB-NEGATIVE VALUE "-".
|
||||
05 WS-AB-INTEGER-PART PIC X(6).
|
||||
05 WS-AB-DEC-POINT PIC X.
|
||||
05 WS-AB-DECIMAL-PART PIC X(12).
|
||||
|
||||
01 WS-BEARING-1 PIC S9(6)V9(12).
|
||||
01 WS-BEARING-2 PIC S9(6)V9(12).
|
||||
|
||||
01 WS-BEARING PIC S9(6)V9(12).
|
||||
01 FILLER REDEFINES WS-BEARING.
|
||||
05 WSB-INTEGER-PART PIC X(6).
|
||||
05 WSB-DECIMAL-PART PIC X9(12).
|
||||
|
||||
77 WS-RESULT PIC S9(6)V9(12).
|
||||
77 WS-RESULT-POS PIC 9(6)V9(12).
|
||||
77 WS-INTEGER-PART PIC 9(6).
|
||||
77 WS-DECIMAL-PART PIC V9(12).
|
||||
77 WS-RESULT-OUT PIC ------9.9999.
|
||||
|
||||
PROCEDURE DIVISION.
|
||||
000-MAIN.
|
||||
PERFORM 100-INITIALIZE.
|
||||
PERFORM 200-PROCESS-RECORD
|
||||
UNTIL EOF-SWITCH = 'Y'.
|
||||
PERFORM 300-TERMINATE.
|
||||
STOP RUN.
|
||||
|
||||
100-INITIALIZE.
|
||||
OPEN INPUT IN-FILE.
|
||||
PERFORM 150-READ-RECORD.
|
||||
|
||||
150-READ-RECORD.
|
||||
READ IN-FILE
|
||||
AT END
|
||||
MOVE 'Y' TO EOF-SWITCH
|
||||
NOT AT END
|
||||
COMPUTE REC-CTR = REC-CTR + 1
|
||||
END-READ.
|
||||
|
||||
200-PROCESS-RECORD.
|
||||
MOVE ALPHA-BEARING-1 TO WS-ALPHA-BEARING.
|
||||
PERFORM 250-CONVERT-DATA.
|
||||
MOVE WS-BEARING TO WS-BEARING-1.
|
||||
|
||||
MOVE ALPHA-BEARING-2 TO WS-ALPHA-BEARING.
|
||||
PERFORM 250-CONVERT-DATA.
|
||||
MOVE WS-BEARING TO WS-BEARING-2.
|
||||
|
||||
COMPUTE WS-RESULT = WS-BEARING-2 - WS-BEARING-1.
|
||||
MOVE WS-RESULT TO WS-RESULT-POS.
|
||||
MOVE WS-RESULT-POS TO WS-INTEGER-PART.
|
||||
COMPUTE WS-DECIMAL-PART = WS-RESULT-POS - WS-INTEGER-PART.
|
||||
COMPUTE WS-INTEGER-PART = FUNCTION MOD(WS-INTEGER-PART 360).
|
||||
IF WS-RESULT > 0
|
||||
COMPUTE WS-RESULT = WS-INTEGER-PART + WS-DECIMAL-PART
|
||||
ELSE
|
||||
COMPUTE WS-RESULT =
|
||||
(WS-INTEGER-PART + WS-DECIMAL-PART) * -1
|
||||
END-IF.
|
||||
|
||||
IF WS-RESULT < -180
|
||||
COMPUTE WS-RESULT = WS-RESULT + 360.
|
||||
IF WS-RESULT > 180
|
||||
COMPUTE WS-RESULT = WS-RESULT - 360.
|
||||
COMPUTE WS-RESULT-OUT ROUNDED = WS-RESULT.
|
||||
|
||||
DISPLAY REC-CTR ' ' WS-RESULT-OUT.
|
||||
|
||||
PERFORM 150-READ-RECORD.
|
||||
|
||||
250-CONVERT-DATA.
|
||||
MOVE WS-AB-INTEGER-PART TO WSB-INTEGER-PART.
|
||||
MOVE WS-AB-DECIMAL-PART TO WSB-DECIMAL-PART.
|
||||
IF WS-AB-NEGATIVE
|
||||
SUBTRACT WS-BEARING FROM ZERO
|
||||
GIVING WS-BEARING
|
||||
END-IF.
|
||||
|
||||
300-TERMINATE.
|
||||
DISPLAY 'RECORDS PROCESSED: ' REC-CTR.
|
||||
CLOSE IN-FILE.
|
||||
|
||||
******************************************************************
|
||||
* INPUT FILE ('Angle_diff.txt' stored on my PC at:
|
||||
* 'C:\Both\Rosetta\Angle_diff.txt'
|
||||
******************************************************************
|
||||
* +000020.000000000000 +000045.000000000000
|
||||
* -000045.000000000000 +000045.000000000000
|
||||
* -000085.000000000000 +000090.000000000000
|
||||
* -000095.000000000000 +000090.000000000000
|
||||
* -000045.000000000000 +000125.000000000000
|
||||
* -000045.000000000000 +000145.000000000000
|
||||
* +000029.480300000000 -000088.638100000000
|
||||
* -000078.325100000000 -000159.036000000000
|
||||
* -070099.742338109380 +029840.674378767230
|
||||
* -165313.666629735700 +033693.989451745600
|
||||
* +001174.838051059846 -154146.664901247570
|
||||
* +060175.773067955460 +042213.071923543730
|
||||
******************************************************************
|
||||
* OUTPUT:
|
||||
******************************************************************
|
||||
* 001 25.0000
|
||||
* 002 90.0000
|
||||
* 003 175.0000
|
||||
* 004 -175.0000
|
||||
* 005 170.0000
|
||||
* 006 -170.0000
|
||||
* 007 -118.1184
|
||||
* 008 -80.7109
|
||||
* 009 -139.5833
|
||||
* 010 -72.3439
|
||||
* 011 -161.5030
|
||||
* 012 37.2989
|
||||
******************************************************************
|
||||
|
|
@ -1,134 +0,0 @@
|
|||
<#
|
||||
.Synopsis
|
||||
Gets the difference between two angles between the values of -180 and 180.
|
||||
To see examples use "Get-Examples"
|
||||
.DESCRIPTION
|
||||
This code uses the modulo operator, this is represented with the "%".
|
||||
The modulo operator returns the remainder after division, as displayed below
|
||||
3 % 2 = 1
|
||||
20 % 15 = 5
|
||||
200 % 146 = 54
|
||||
|
||||
.EXAMPLE
|
||||
PS C:\WINDOWS\system32> Get-AngleDiff
|
||||
cmdlet Get-AngleDiff at command pipeline position 1
|
||||
Supply values for the following parameters:
|
||||
angle1: 45
|
||||
angle2: -85
|
||||
|
||||
The difference between 45 and -85 is -130
|
||||
|
||||
PS C:\WINDOWS\system32>
|
||||
|
||||
.EXAMPLE
|
||||
PS C:\WINDOWS\system32> Get-AngleDiff -angle1 50 -angle2 -65
|
||||
|
||||
The difference between 50 and -65 is -115
|
||||
|
||||
PS C:\WINDOWS\system32>
|
||||
|
||||
.EXAMPLE
|
||||
PS C:\WINDOWS\system32> Get-AngleDiff -89 50
|
||||
|
||||
The difference between -89 and 50 is 139
|
||||
|
||||
PS C:\WINDOWS\system32>
|
||||
|
||||
|
||||
#>
|
||||
function Get-AngleDiff
|
||||
{
|
||||
[CmdletBinding()]
|
||||
|
||||
Param
|
||||
(
|
||||
# Angle one input, must be a number
|
||||
[Parameter(Mandatory=$true,
|
||||
ValueFromPipelineByPropertyName=$true)][double]$angle1,
|
||||
|
||||
# Angle two input, must be a number
|
||||
[Parameter(Mandatory=$true,
|
||||
ValueFromPipelineByPropertyName=$true)][double]$angle2
|
||||
)
|
||||
|
||||
Begin
|
||||
{
|
||||
#This is the equation to calculate the difference
|
||||
[double]$Difference = ($angle2 - $angle1) % 360.0
|
||||
}
|
||||
|
||||
Process
|
||||
{
|
||||
#If/IfElse/Else block to return results within the requested range
|
||||
if ($Difference -lt -180.0)
|
||||
{$Difference += 360.0
|
||||
}
|
||||
|
||||
elseif ($Difference -gt 360.0)
|
||||
{$Difference -= 360.0
|
||||
}
|
||||
|
||||
#Writes the values given by the user and the result
|
||||
Write-Host "The difference between $angle1 and $angle2 is $Difference"
|
||||
}
|
||||
|
||||
End
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
<#
|
||||
.Synopsis
|
||||
This is simply the outputs of the Get-AngleDiff Function in a function
|
||||
.EXAMPLE
|
||||
PS C:\WINDOWS\system32> Get-Examples
|
||||
|
||||
Inputs from the -180 to 180 range
|
||||
The difference between 20 and 45 is 25
|
||||
The difference between -45 and 45 is 90
|
||||
The difference between -85 and 90 is 175
|
||||
The difference between -95 and 90 is 185
|
||||
The difference between -45 and 125 is 170
|
||||
The difference between -45 and 145 is 190
|
||||
The difference between -45 and 125 is 170
|
||||
The difference between -45 and 145 is 190
|
||||
The difference between 29.4803 and -88.6381 is -118.1184
|
||||
The difference between -78.3251 and -159.036 is -80.7109
|
||||
|
||||
Inputs from a wider range
|
||||
The difference between -70099.7423381094 and 29840.6743787672 is 220.416716876614
|
||||
The difference between -165313.666629736 and 33693.9894517456 is 287.656081481313
|
||||
The difference between 1174.83805105985 and -154146.664901248 is -161.502952307404
|
||||
The difference between 60175.7730679555 and 42213.0719235437 is 37.2988555882694
|
||||
|
||||
PS C:\WINDOWS\system32>
|
||||
#>
|
||||
|
||||
function Get-Examples
|
||||
{
|
||||
#blank write-host is used for a blank line to make the output look a lil cleaner
|
||||
Write-Host
|
||||
Write-Host "Inputs from the -180 to 180 range"
|
||||
|
||||
Get-AngleDiff 20.0 45.0
|
||||
Get-AngleDiff -45.0 45.0
|
||||
Get-AngleDiff -85.0 90.0
|
||||
Get-AngleDiff -95.0 90.0
|
||||
Get-AngleDiff -45.0 125.0
|
||||
Get-AngleDiff -45.0 145.0
|
||||
Get-AngleDiff -45.0 125.0
|
||||
Get-AngleDiff -45.0 145.0
|
||||
Get-AngleDiff 29.4803 -88.6381
|
||||
Get-AngleDiff -78.3251 -159.036
|
||||
|
||||
Write-Host
|
||||
Write-Host "Inputs from a wider range"
|
||||
|
||||
Get-AngleDiff -70099.74233810938 29840.67437876723
|
||||
Get-AngleDiff -165313.6666297357 33693.9894517456
|
||||
Get-AngleDiff 1174.8380510598456 -154146.66490124757
|
||||
Get-AngleDiff 60175.77306795546 42213.07192354373
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
PS C:\WINDOWS\system32> Get-AngleDiff -45 98
|
||||
The difference between -45 and 98 is 143
|
||||
Loading…
Add table
Add a link
Reference in a new issue