Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FreePascal language support #377

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 126 additions & 0 deletions demo/pascal/Demo.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
program Demo;

{$mode objfpc}{$H+}

uses
Classes,
SysUtils,
Astronomy;

const
Months: array[1..12] of string = (
'January', 'February', 'March', 'April',
'May', 'June', 'July', 'August',
'September', 'October', 'November', 'December');

// Observer site: Slovakia/Bratislava
Latitude: Double = 48.143889;
Longitude: Double = 17.109722;
Elevation: Double = 124;

// ICRS equatorial coordinates of the star HD1 (Henry Draper catalog, star #1)
RA_ICRS: Double = 1.2961219444444443; // degrees
DE_ICRS: Double = 67.84007388888888; // degrees

var
at1: AstroTime;
st1: Double;
ptr: PAstroTime;
mph: AstroAngleResult;
MoonPhase: string;
lap: AstroApsis;
sss: AstroSeasons;
obs: AstroObserver;
coo: AstroEquatorial;

function ToDateString(Event: AstroTime): string;
var
t: AstroUTC;
begin
t := Astronomy_UtcFromTime(Event);
ToDateString := '' + IntToStr(t.Year) + '. ' + Months[t.Month] + '. ' + IntToStr(t.Day) + '. ';
end;

BEGIN
at1 := Astronomy_MakeTime(2025, 1, 20, 22, 20, 0.5);
WriteLn('Astro time for 2025-Jan-20 at 22:20:30 -> ', at1.UT:20:6, #10#13);

// Define an observer site
obs.Latitude := Latitude;
obs.Longitude := Longitude;
obs.Height := Elevation;

at1 := Astronomy_CurrentTime();
WriteLn('Current astro time: ', at1.UT:20:6, #10#13);

WriteLn('Body name: ', Astronomy_BodyName(AstroBody.BODY_SUN), #10#13);

WriteLn('Body code for "Earth": [', Astronomy_BodyCode(PChar('Earth')), ']', #10#13);

// Calculate Greenwich sidereal time using current time
ptr := New(PAstroTime);
ptr^.UT := at1.UT;
ptr^.TT := at1.TT;
ptr^.ST := 0 / 0; // gives NaN, must be set, otherwise GAST calculation doesn't work
st1 := Astronomy_SiderealTime(ptr);
WriteLn('Greenwich apparent sidereal time: ', st1:20:6, ' hours', #10#13);

// Get the current moon phase
mph := Astronomy_MoonPhase(at1);
if mph.Status <> AstroStatus.ASTRO_SUCCESS then
WriteLn('An error occured during the Moon phase calculation!')
else begin
if (mph.Angle = 0) or (mph.Angle = 360) then MoonPhase := 'New Moon';
if (mph.Angle > 0) and (mph.Angle < 90) then MoonPhase := 'Waxing Crescent';
if mph.Angle = 90 then MoonPhase := 'First quarter';
if (mph.Angle > 90) and (mph.Angle < 180) then MoonPhase := 'Waxing Gibbous';
if mph.Angle = 180 then MoonPhase := 'Full Moon';
if (mph.Angle > 180) and (mph.Angle < 270) then MoonPhase := 'Waning Gibbous';
if mph.Angle = 270 then MoonPhase := 'Last quarter';
if (mph.Angle > 270) and (mph.Angle < 360) then MoonPhase := 'Waning Crescent';
WriteLn('Current Moon phase: ' + MoonPhase + #10#13);
end;

// Search for the first lunar apsis event since now
lap := Astronomy_SearchLunarApsis(at1);
if lap.Status <> AstroStatus.ASTRO_SUCCESS then
WriteLn('An error occured during the Moon apsis calculation!')
else
WriteLn('Next Lunar ', lap.Kind, ' occurs at ', ToDateString(lap.Time), ' at the distance of ', lap.DistKM:12:3, ' km from Earth.');

// Search for next lunar apsis event
lap := Astronomy_NextLunarApsis(lap);
if lap.Status <> AstroStatus.ASTRO_SUCCESS then
WriteLn('An error occured during the Moon apsis calculation!')
else
WriteLn('Next Lunar ', lap.Kind, ' occurs at ', ToDateString(lap.Time), ' at the distance of ', lap.DistKM:12:3, ' km from Earth.', #10#13);

// Search for seasons in 2025
sss := Astronomy_Seasons(2025);
if sss.Status <> AstroStatus.ASTRO_SUCCESS then
WriteLn('An error occured during the 2025 seasons calculation!')
else begin
WriteLn('2025 march equinox occurs at: ', ToDateString(sss.MarEquinox));
WriteLn('2025 june solstice occurs at: ', ToDateString(sss.JunSolstice));
WriteLn('2025 sept equinox occurs at: ', ToDateString(sss.SepEquinox));
WriteLn('2025 dec solstice occurs at: ', ToDateString(sss.DecSolstice), #10#13);
end;

// Find equatorial coordinates of date for the star HD1 as seen from Slovakia/Bratislava
if Astronomy_DefineStar(AstroBody.BODY_STAR1, RA_ICRS / 15.0, DE_ICRS, 1000.0) <> AstroStatus.ASTRO_SUCCESS then
WriteLn('An error occured during defining a custom star!')
else begin
coo := Astronomy_Equator(AstroBody.BODY_STAR1, ptr, obs, AstroEquatorDate.EQUATOR_OF_DATE, AstroAberration.NO_ABERRATION);
if coo.Status <> AstroStatus.ASTRO_SUCCESS then
WriteLn('An error occured during the coordinate conversion!')
else begin
WriteLn('Equatorial coordinates of the HD1 star at ', ToDateString(at1));
WriteLn('Right ascension: ', coo.RA:12:3, ' hours');
WriteLn('Declination: ', coo.Dec:12:3, ' degrees');
end;
end;

// Release the dynamically allocated object used in the previous calculations
Dispose(ptr);
END.

13 changes: 13 additions & 0 deletions demo/pascal/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Astronomy Engine examples in Pascal
---
### [Various](Demo.pas)
The demo program shows following astronomy calculations:
- Setting up the observer site
- Creating `AstroTime` object for a fixed date/time
- Creating `AstroTime` object for the `now` moment for later calcualtions
- Calculating and displaying the current Moon phase
- Calculating upcoming lunar apsis events
- Calculating the equinox and solstice events for the year 2025
- Calculating the equatorial coordinates of date for the star HD1 from Henry Draper catalog for the current observer site

To execute this demo (after build) you will also need the `Astronomy.dll` binary built from Astronomy Engine C/C++ project!
28 changes: 28 additions & 0 deletions source/c/Astronomy.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.12.35527.113 d17.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Astronomy", "Astronomy.vcxproj", "{E5211E34-82B2-4995-80C3-AAB72E89C6CF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E5211E34-82B2-4995-80C3-AAB72E89C6CF}.Debug|x64.ActiveCfg = Debug|x64
{E5211E34-82B2-4995-80C3-AAB72E89C6CF}.Debug|x64.Build.0 = Debug|x64
{E5211E34-82B2-4995-80C3-AAB72E89C6CF}.Debug|x86.ActiveCfg = Debug|Win32
{E5211E34-82B2-4995-80C3-AAB72E89C6CF}.Debug|x86.Build.0 = Debug|Win32
{E5211E34-82B2-4995-80C3-AAB72E89C6CF}.Release|x64.ActiveCfg = Release|x64
{E5211E34-82B2-4995-80C3-AAB72E89C6CF}.Release|x64.Build.0 = Release|x64
{E5211E34-82B2-4995-80C3-AAB72E89C6CF}.Release|x86.ActiveCfg = Release|Win32
{E5211E34-82B2-4995-80C3-AAB72E89C6CF}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
137 changes: 137 additions & 0 deletions source/c/Astronomy.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
<ProjectGuid>{E5211E34-82B2-4995-80C3-AAB72E89C6CF}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;ASTRONOMY_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level3</WarningLevel>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PreprocessorDefinitions>_DEBUG;_WINDOWS;_USRDLL;ASTRONOMY_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level3</WarningLevel>
<LanguageStandard>stdcpp17</LanguageStandard>
<LanguageStandard_C>stdc17</LanguageStandard_C>
<SDLCheck>false</SDLCheck>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;ASTRONOMY_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level3</WarningLevel>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<PreprocessorDefinitions>NDEBUG;_WINDOWS;_USRDLL;ASTRONOMY_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level3</WarningLevel>
<LanguageStandard>stdcpp17</LanguageStandard>
<LanguageStandard_C>stdc17</LanguageStandard_C>
<SDLCheck>false</SDLCheck>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="astronomy.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="astronomy.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
13 changes: 13 additions & 0 deletions source/c/README.Windows.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Astronomy Engine (C/C++) for Windows platform

We include the project file (.vcxproj) and solution file (.sln) so that you can easily build the Astronomy Engine on the Windows platform using Visual Studio.

## Build

Open and build the `Astronomy.sln` file in Visual Studio (2022 and newer).
Please note that the `Desktop development with C++` workload is required to build the Astronomy Engine in Visual Studio.
A dynamic link library file `Astronomy.dll` is created on a successful build as an output.

## Language bindings possibility

The Astronomy Engine (C/C++) project is built in a way that allows to create [language binding](https://en.wikipedia.org/wiki/Language_binding) for other programming languages that support _external functions_. This way one can call C/C++ functions from Pascal language for example.
Loading