### Python Example for CalcephBin.orient_order
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/examples/multiple_orient_order.rst
Shows how to use the Calceph Python wrapper to open an ephemeris file, compute orientation and order, and then close the file. This example requires the 'calcephpy' package to be installed.
```Python
from calcephpy import *
jd0=2442457
dt=0.5E0
peph = CalcephBin.open("example1.dat")
P = peph.orient_order(jd0, dt, NaifId.MOON,
Constants.USE_NAIFID+Constants.UNIT_RAD+Constants.UNIT_SEC, 0)
print(P)
peph.close()
```
--------------------------------
### Install GCC and CMake for Anaconda (Linux Example)
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/calceph.install.pythonusage.rst
Install the GCC compiler and CMake using conda on Linux. This is part of the Anaconda installation process for Calceph.
```bash
conda install gcc_linux-64 cmake make
```
--------------------------------
### Install Calceph Library
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/calceph.install.cusage.rst
Installs the Calceph library files, headers, and documentation to specified directories. Requires write permissions for the installation paths. The default installation prefix is /usr/local.
```bash
cmake --build . --target install
```
--------------------------------
### Get File Version in Fortran 2003
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/examples/multiple_getfileversion.rst
This Fortran 2003 example shows how to open an ephemeris file and get its version. It uses C interoperability for the file handle and version string.
```fortran
integer res
character(len=CALCEPH_MAX_CONSTANTVALUE) version
TYPE(C_PTR) :: peph
peph = calceph_open("example1.dat"//C_NULL_CHAR)
if (C_ASSOCIATED(peph)) then
res = calceph_getfileversion(peph, version)
write (*,*) "The version of the file is ", version
call calceph_close(peph)
endif
```
--------------------------------
### Install Project Components with CMake
Source: https://github.com/imcce_calceph/calceph/blob/master/src/CMakeLists.txt
Configures installation of headers, modules, and targets based on build options like CALCEPH_INSTALL and ENABLE_FORTRAN. Handles runtime installation for shared libraries on Windows.
```cmake
if (CALCEPH_INSTALL)
install(FILES calceph.h COMPONENT dev DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
if (ENABLE_FORTRAN)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/f90calceph.h" COMPONENT dev DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/calceph.mod" COMPONENT dev DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
endif()
install(TARGETS calceph EXPORT calcephTargets ARCHIVE COMPONENT dev DESTINATION "${CMAKE_INSTALL_LIBDIR}" LIBRARY COMPONENT lib DESTINATION "${CMAKE_INSTALL_LIBDIR}")
if (WIN32)
if (BUILD_SHARED_LIBS)
install(TARGETS calceph RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
endif()
endif()
target_include_directories(calceph PUBLIC $ )
endif()
target_include_directories(calceph PUBLIC $ )
target_include_directories(calceph INTERFACE $ )
target_include_directories(calceph INTERFACE $ )
```
--------------------------------
### Build and Install CALCEPH from Source (Unix-like)
Source: https://github.com/imcce_calceph/calceph/blob/master/README.rst
Builds, tests, and installs the CALCEPH library from source on Unix-like systems using CMake. Installs to the default directory.
```bash
cmake -S . -B build
cmake --build build --target all
cmake --build build --target test
cmake --build build --target install
```
--------------------------------
### Build and Install CALCEPH from Source with Custom Prefix (Unix-like)
Source: https://github.com/imcce_calceph/calceph/blob/master/README.rst
Builds, tests, and installs the CALCEPH library from source on Unix-like systems using CMake, specifying a custom installation directory.
```bash
cmake -DCMAKE_INSTALL_PREFIX=*dir* -S . -B build
cmake --build build --target all
cmake --build build --target test
cmake --build build --target install
```
--------------------------------
### Install Calceph with GCC/Gfortran
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/calceph.install.cusage.rst
Use these steps to install Calceph when using GCC and Gfortran compilers. Ensure you replace \"/home/mylogin/mydir\" with your desired installation directory.
```bash
tar xzf calceph-|version|.tar.gz
cd calceph-|version|
mkdir build
cd build
CC=gcc FC=gfortran cmake -DCMAKE_INSTALL_PREFIX=/home/mylogin/mydir ..
cmake --build . --target all
cmake --build . --target test
cmake --build . --target install
```
--------------------------------
### Install Calceph with LLVM/Flang Compilers
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/calceph.install.cusage.rst
This sequence installs Calceph using LLVM Clang (CC=clang) and Flang (FC=flang) compilers. Remember to substitute \"/home/mylogin/mydir\" with your chosen installation directory.
```bash
tar xzf calceph-|version|.tar.gz
cd calceph-|version|
mkdir build
cd build
CC=clang FC=flang cmake -DCMAKE_INSTALL_PREFIX=/home/mylogin/mydir ..
cmake --build . --target all
cmake --build . --target test
cmake --build . --target install
```
--------------------------------
### Get Version String
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/calceph.misc.pythonusage.rst
Retrieves the version of the Calcephpy library as a string. This is a simple utility to check the installed library version.
```python
from calcephpy import *
print('version=', getversion_str())
```
--------------------------------
### Get Moon ID in Python
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/examples/multiple_getidbyname.rst
Python example for fetching the Moon's ID using the calcephpy library. Demonstrates both standard and NAIF IDs.
```Python
from calcephpy import *
peph = CalcephBin.open("example1.dat")
# print the id of the Moon using the old numbering system
moon = peph.getidbyname('Moon', 0)
print(moon)
# print the id of the Moon using the NAIF identification numbering system
moon = peph.getidbyname('Moon', Constants.USE_NAIFID)
print(moon)
print(NaifId.MOON)
peph.close()
```
--------------------------------
### Get Constant Values in Python
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/examples/multiple_getconstantvs.rst
Python example using `calcephpy` to open an ephemeris file, retrieve constant values using `getconstantvs`, and close the file.
```Python
from calcephpy import *
peph = CalcephBin.open("example1.dat")
mission_units = peph.getconstantvs("MISSION_UNITS")
print(mission_units)
peph.close()
```
--------------------------------
### Get File Version in Python
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/examples/multiple_getfileversion.rst
A Python example using the calcephpy library to open an ephemeris file and print its version. This is a concise way to access file information.
```python
from calcephpy import *
peph = CalcephBin.open("example1.dat")
version = peph.getfileversion()
print(version)
peph.close()
```
--------------------------------
### Install Calceph with Microsoft Visual C++
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/calceph.install.cusage.rst
Instructions for installing Calceph with Microsoft Visual C++ compilers, using NMake Makefiles. Replace \"/home/mylogin/mydir\" with your desired installation path.
```bash
tar xzf calceph-|version|.tar.gz
cd calceph-|version|
mkdir build
cd build
cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=/home/mylogin/mydir ..
cmake --build . --target all
cmake --build . --target test
cmake --build . --target install
```
--------------------------------
### Install CALCEPH with Pip (System)
Source: https://github.com/imcce_calceph/calceph/blob/master/README.rst
Installs the latest CALCEPH library system-wide. Requires administrative rights.
```bash
pip install calcephpy
```
--------------------------------
### Build and Install CALCEPH from Source (Windows MSVC)
Source: https://github.com/imcce_calceph/calceph/blob/master/README.rst
Builds, tests, and installs the CALCEPH library from source on Windows using CMake with the Microsoft Visual C++ compiler, specifying a custom installation directory.
```bash
cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX="C:\CALCEPH" -S . -B build
cmake --build build --target all
cmake --build build --target test
cmake --build build --target install
```
--------------------------------
### Set Installation Directories
Source: https://github.com/imcce_calceph/calceph/blob/master/CMakeLists.txt
Configures standard installation directories based on whether the system is UNIX-like or not. This ensures files are placed in expected locations.
```cmake
if(UNIX)
include(GNUInstallDirs)
else()
set(CMAKE_INSTALL_LIBDIR "lib")
set(CMAKE_INSTALL_DATADIR "share")
set(CMAKE_INSTALL_INCLUDEDIR "include")
set(CMAKE_INSTALL_BINDIR "bin")
set(CMAKE_INSTALL_LIBEXECDIR "libexec")
set(CMAKE_INSTALL_MANDIR "share/man")
endif()
```
--------------------------------
### Install Python Packages for Documentation
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/calceph.install.cusage.rst
Install necessary Python packages for building Calceph documentation using pip3. This command installs Sphinx and related libraries.
```bash
pip3 install Sphinx six sphinx-fortran sphinx-rtd-theme sphinxcontrib-matlabdomain
```
--------------------------------
### Build CALCEPH from Source (Unix)
Source: https://context7.com/imcce_calceph/calceph/llms.txt
Builds, tests, and installs the CALCEPH library from source using CMake. Specify a custom installation prefix with -DCMAKE_INSTALL_PREFIX.
```bash
cmake -S . -B build
cmake --build build --target all
cmake --build build --target test
cmake --build build --target install
# To change install prefix:
cmake -DCMAKE_INSTALL_PREFIX=/opt/calceph -S . -B build
```
--------------------------------
### Install CALCEPH with Pip (User)
Source: https://github.com/imcce_calceph/calceph/blob/master/README.rst
Installs the latest CALCEPH library for the current user. Requires NumPy to be installed.
```bash
pip install --user calcephpy
```
--------------------------------
### Install Calceph with Intel Compilers
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/calceph.install.cusage.rst
Follow these instructions to install Calceph using Intel C++ (icc) and Fortran (ifort) compilers. Customize \"/home/mylogin/mydir\" to your target installation path.
```bash
tar xzf calceph-|version|.tar.gz
cd calceph-|version|
mkdir build
cd build
CC=icc FC=ifort cmake -DCMAKE_INSTALL_PREFIX=/home/mylogin/mydir ..
cmake --build . --target all
cmake --build . --target test
cmake --build . --target install
```
--------------------------------
### Install Calceph Python Interface (pip)
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/calceph.install.pythonusage.rst
Install the calcephpy library using pip after its requirements have been met.
```bash
pip install calcephpy
```
--------------------------------
### Install Calceph Python Interface Requirements (pip)
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/calceph.install.pythonusage.rst
Install the necessary Python packages (Cython, setuptools, numpy) using pip before installing the calcephpy library.
```bash
pip install Cython setuptools numpy
```
--------------------------------
### Install CALCEPH Python Binding
Source: https://context7.com/imcce_calceph/calceph/llms.txt
Installs or upgrades the calcephpy Python package using pip. Use --user for local installation.
```bash
pip install --user calcephpy
pip install --user --upgrade calcephpy # upgrade
```
--------------------------------
### Install CALCEPH Python Package (pip)
Source: https://github.com/imcce_calceph/calceph/blob/master/readme.txt
Commands to install the CALCEPH Python package using pip. Use --user for user-specific installation or without for system-wide installation if administrative rights are available.
```bash
pip install --user calcephpy
```
```bash
pip install calcephpy
```
```bash
pip install --user --upgrade calcephpy
```
--------------------------------
### C API Example
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/condsingle/single_sgetconstant.rst
Example of using calceph_sgetconstant in C to retrieve the Astronomical Unit (UA).
```APIDOC
## calceph_sgetconstant (C API)
### Description
Retrieves a specific constant value from an opened ephemeris file.
### Function Signature
`int calceph_sgetconstant(const char *name, double *value);`
### Parameters
#### Path Parameters
- **name** (const char *) - The name of the constant to retrieve (e.g., "UA").
- **value** (double *) - A pointer to a double where the retrieved constant value will be stored.
### Request Example
```c
int res;
double UA;
calceph_sopen("example1.dat");
res = calceph_sgetconstant("UA", &UA);
if (res)
{
printf("astronomical unit=%23.16E\n", UA);
}
```
### Response
#### Success Response (1)
- **value** (double) - The value of the requested constant.
#### Error Response (0)
- Indicates an error occurred during retrieval.
```
--------------------------------
### Set up Visual Studio Compiler Environment (Windows)
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/calceph.install.pythonusage.rst
Execute this command in your terminal before installing the library on Windows if using Microsoft Visual Studio. Adjust the path based on your Visual Studio version.
```bash
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat"
```
--------------------------------
### Get Timespan in Python
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/examples/multiple_gettimespan.rst
A Python example using the `calcephpy` library to open an ephemeris file and get its time span. This requires the `calcephpy` package to be installed.
```python
from calcephpy import *
peph = CalcephBin.open("example1.dat")
firsttime, lasttime, continuous = peph.gettimespan()
print(firsttime, lasttime, continuous)
peph.close()
```
--------------------------------
### Compiling on Windows Systems
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/calceph.interface.f2003usage.rst
Link against the 'libcalceph.lib' library. Use compiler options like /I and /LIBPATH: for non-standard installation locations.
```bash
gfortran.exe /out:myprogram.exe myprogram.f libcalceph.lib
```
--------------------------------
### Get Position Record Index 2 Example
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/calceph.multiple_getpositionrecordindex2.rst
This example demonstrates how to retrieve and display position records from an ephemeris file using the `multiple_getpositionrecordindex2` function. It iterates through the records to show their details.
```Python
from calceph import \n\n# Load ephemeris file\neph = calceph.Ephemeris("de430.bsp")\n\n# Get number of position records\nnrecords = eph.getnumberofpositionrecords(1, 2, 1, 0)\n\n# Iterate through records and display details\nfor i in range(nrecords):\n target, center, frame, segid, t1, t2, timescale = eph.multiple_getpositionrecordindex2(1, 2, 1, 0, i)\n print(f"Record {i}: Target={target}, Center={center}, Frame={frame}, SegID={segid}, T1={t1}, T2={t2}, Timescale={timescale}")
```
--------------------------------
### Get Position Record Index (MATLAB/Mex)
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/examples/multiple_getpositionrecordindex2.rst
MATLAB/Mex example to access ephemeris data. This snippet opens an ephemeris file, retrieves the record count, and then iterates to get the details of each position record.
```MATLAB
peph = CalcephBin.open('example1.dat');
n = peph.getpositionrecordcount()
for j=1:n
[itarget, icenter, firsttime, lasttime, iframe, iseg] = peph.getpositionrecordindex2(j)
end
peph.close();
```
--------------------------------
### C Example for calceph_orient_order
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/examples/multiple_orient_order.rst
Demonstrates opening an ephemeris file, prefetching data, calculating orientation and order, and closing the file using the C API. Ensure the ephemeris file 'example1.dat' exists.
```C
int res;
int j;
double jd0=2442457;
double dt1=0.5E0;
t_calcephbin *peph;
double P[3];
/* open the ephemeris file */
peph = calceph_open("example1.dat");
if (peph)
{
calceph_prefetch(peph);
calceph_orient_order(peph, jd0, dt1, NAIFID_MOON,
CALCEPH_USE_NAIFID+CALCEPH_UNIT_RAD+CALCEPH_UNIT_SEC,
0,
P);
for(j=0; j<3; j++) printf("%23.16E\n", P[j]);
/* close the ephemeris file */
calceph_close(peph);
}
```
--------------------------------
### Get Position Record Index (Python)
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/examples/multiple_getpositionrecordindex2.rst
Python example for iterating through ephemeris records. It opens a file, gets the total number of records, and then retrieves and prints the details for each record using `getpositionrecordindex2`.
```Python
from calcephpy import *
peph = CalcephBin.open("example1.dat")
n = peph.getpositionrecordcount()
for j in range(1, n+1):
itarget, icenter, firsttime, lasttime, iframe, iseg = peph.getpositionrecordindex2(j)
print(itarget, icenter, firsttime, lasttime, iframe, iseg)
peph.close()
```
--------------------------------
### Get Moon ID in Fortran 2003
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/examples/multiple_getidbyname.rst
Shows how to get the Moon's ID using the old and NAIF numbering systems in Fortran 2003. Requires proper C interoperability setup.
```Fortran
integer res
integer moon
TYPE(C_PTR) :: peph
peph = calceph_open("example1.dat"//C_NULL_CHAR)
if (C_ASSOCIATED(peph)) then
! print the id of the Moon using the old numbering system
if (calceph_getidbyname(peph, "Moon"//C_NULL_CHAR, 0, moon).eq.1) then
write (*,*) "Moon=", moon
endif
! print the id of the Moon using the NAIF identification numbering system
if (calceph_getidbyname(peph, "Moon"//C_NULL_CHAR, CALCEPH_USE_NAIFID, moon).eq.1) then
write (*,*) "Moon=", moon
endif
call calceph_close(peph)
endif
```
--------------------------------
### Get Timescale in Python
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/examples/multiple_gettimescale.rst
Opens an ephemeris file and retrieves its time scale using the Python wrapper. Ensure calcephpy is installed.
```Python
from calcephpy import *
peph = CalcephBin.open("example1.dat")
timescale = peph.gettimescale()
print(timescale)
peph.close()
```
--------------------------------
### Get Timespan in C
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/condsingle/single_sgettimespan.rst
Use `calceph_sgettimespan` to retrieve the start and end Julian dates and continuity flag from an opened ephemeris file.
```c
int res;
double jdfirst, jdlast;
int cont;
calceph_sopen("example1.dat");
res = calceph_sgettimespan(&jdfirst, &jdlast, &cont);
printf("data available between [ %f, %f ]. continuous=%d\n",
jdfirst, jdlast, cont);
```
--------------------------------
### Get Constant Values in Mex
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/examples/multiple_getconstantvs.rst
Mex function example to open an ephemeris file, retrieve constant values using `getconstantvs`, and close the file.
```Mex
peph = CalcephBin.open('example1.dat');
mission_units = peph.getconstantvs('MISSION_UNITS')
peph.close();
```
--------------------------------
### Compiling on Unix-like Systems
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/calceph.interface.f2003usage.rst
Link against the 'libcalceph' library using the -lcalceph flag. Adjust include and library paths if installed in a non-standard location.
```bash
gfortran -I/usr/local/include myprogram.f -o myprogram -lcalceph
```
--------------------------------
### Get Moon Identification Number
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/calceph.multiple_getidbyname.rst
This example demonstrates how to retrieve the identification number for the Moon using the multiple_getidbyname function. Ensure the 'calceph' library is imported.
```python
import calceph
# Get the identification number of the Moon
moon_id = calceph.multiple_getidbyname('Moon')
# Print the result
print(f'The identification number of the Moon is: {moon_id}')
```
--------------------------------
### Compute heliocentric coordinates of Mars
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/calceph.multiple_compute_unit.rst
This example demonstrates how to get the heliocentric coordinates of Mars at a specific time, with output units specified for kilometers and seconds.
```Python
import calceph
# Open the ephemeris file
eph = calceph.open()
# Define the time
JD0 = 2442457.5
time = 0.0
# Define the target and center
target = "Mars"
center = "Sun"
# Define the units for position and velocity
# CALCEPH_UNIT_KM for kilometers, CALCEPH_UNIT_SEC for seconds
unit = calceph.CALCEPH_UNIT_KM + calceph.CALCEPH_UNIT_SEC
# Compute the ephemeris
PV = calceph.compute_unit(eph, JD0, time, target, center, unit)
# Print the results
print(f"Position (km): {PV[0:3]}")
print(f"Velocity (km/s): {PV[3:6]}")
# Close the ephemeris file
calceph.close(eph)
```
--------------------------------
### Get AU Constant in Python
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/examples/multiple_getconstantsd.rst
Opens an ephemeris file and retrieves the value of the AU constant using the Python wrapper. Assumes the calcephpy library is installed.
```Python
from calcephpy import *
peph = CalcephBin.open("example1.dat")
AU = peph.getconstantsd("AU")
print(AU)
peph.close()
```
--------------------------------
### Compile on Windows with SDK
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/calceph.interface.cusage.rst
Link the libcalceph.lib library when compiling your C program on Windows using the Windows SDK.
```bash
cl.exe /out:myprogram myprogram.c libcalceph.lib
```
--------------------------------
### Fortran 2003 Example: Calceph API Usage
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/condsingle/single_prog.rst
Shows how to use the Calceph API in Fortran 2003, including opening/closing ephemeris files, retrieving constants, computing coordinates, and listing all available constants. Uses ISO_C_BINDING for C compatibility.
```fortran
USE, INTRINSIC :: ISO_C_BINDING
use calceph
implicit none
integer res
real(8) AU, EMRAT, GM_Mer
real(8) jd0
real(8) dt
real(8) PV(6)
integer j
real(8) valueconstant
character(len=CALCEPH_MAX_CONSTANTNAME) nameconstant
jd0 = 2442457
dt = 0.5E0
! open the ephemeris file
res = calceph_sopen("example1.dat"//C_NULL_CHAR)
if (res.eq.1) then
write (*,*) "The ephemeris is already opened"
! print the values of AU, EMRAT and GM_Mer
if (calceph_sgetconstant("AU"//C_NULL_CHAR, AU).eq.1) then
write (*,*) "AU=", AU
endif
if (calceph_sgetconstant("EMRAT"//C_NULL_CHAR,EMRAT).eq.1) then
write (*,*) "EMRAT=", EMRAT
endif
if (calceph_sgetconstant("GM_Mer"//C_NULL_CHAR,GM_Mer).eq.1) then
write (*,*) "GM_Mer=", GM_Mer
endif
! compute and print the coordinates
! the geocentric moon coordinates
res = calceph_scompute(jd0, dt, 10, 3, PV)
call printcoord(PV,"geocentric coordinates of the Moon")
! the value TT-TDB
if (calceph_scompute(jd0, dt, 16, 0, PV).eq.1) then
write (*,*) "TT-TDB = ", PV(1)
endif
! the heliocentric coordinates of Mars
res = calceph_scompute(jd0, dt, 4, 11, PV)
call printcoord(PV,"heliocentric coordinates of Mars")
! print the whole list of the constants
write (*,*) "list of constants"
do j=1, calceph_sgetconstantcount()
res = calceph_sgetconstantindex(j,nameconstant, valueconstant)
write (*,*) nameconstant,"=",valueconstant
enddo
! close the ephemeris file
call calceph_sclose
write (*,*) "The ephemeris is already closed"
else
write (*,*) "The ephemeris can't be opened"
endif
```
--------------------------------
### Get Timespan in Mex
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/examples/multiple_gettimespan.rst
This Mex example shows how to open an ephemeris file and retrieve its time span using the `CalcephBin` object. This is typically used within MATLAB.
```matlab
peph = CalcephBin.open('example1.dat');
[firsttime, lasttime, continuous ] = peph.gettimespan()
peph.close();
```
--------------------------------
### Fortran 2003 Example for calceph_orient_order
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/examples/multiple_orient_order.rst
Shows how to use the Calceph API with Fortran 2003, including opening the ephemeris file, performing the orientation and order calculation, and closing the file. Requires a Fortran compiler supporting F2003 and the C-interoperability features.
```Fortran
integer res
real(8) jd0
real(8) dt1
real(8) P(3)
TYPE(C_PTR) :: peph
jd0 = 2442457
dt1 = 0.5D0
peph = calceph_open("example1.dat"//C_NULL_CHAR)
if (C_ASSOCIATED(peph)) then
res = calceph_orient_order(peph,jd0, dt1, NAIFID_MOON,
& CALCEPH_USE_NAIFID+CALCEPH_UNIT_RAD+CALCEPH_UNIT_SEC,
& 0, P)
write(*,*) P
call calceph_close(peph)
endif
```
--------------------------------
### Get Constant Vector Data in Mex
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/examples/multiple_getconstantvd.rst
MATLAB Mex example demonstrating opening an ephemeris file, fetching a constant's vector data, and closing the file.
```MATLAB
peph = CalcephBin.open('example1.dat');
radii = peph.getconstantvd('BODY399_RADII')
peph.close();
```
--------------------------------
### Setup Python Tests and Build
Source: https://github.com/imcce_calceph/calceph/blob/master/pythonapi/src/CMakeLists.txt
Configures and builds the Python API extension if Python tests are enabled. This includes copying necessary files, setting up Cython compilation flags, and defining a custom build target.
```cmake
if (ENABLE_PYTHON_TESTS)
FILE(COPY calcephpy.pxd DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
if(HAVE_CYTHON_NOEXCEPT)
message(STATUS "Cython supports the keyword noexcept")
SET(CYTHON_NOEXCEPT noexcept)
else()
message(STATUS "Cython doesn't support the keyword noexcept")
SET(CYTHON_NOEXCEPT)
endif()
CONFIGURE_FILE(calcephpy.pyx.in calcephpy.pyx @ONLY)
CONFIGURE_FILE(setup.py.in setup.py @ONLY)
add_custom_target( calcephpy_c ALL
COMMAND "${Python_EXECUTABLE}" setup.py build_ext -i
DEPENDS setup.py calcephpy.pyx calcephpy.pxd calceph
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
VERBATIM)
endif()
```
--------------------------------
### Get Moon Libration Angles
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/calceph.multiple_orient_unit.rst
Example demonstrating how to retrieve libration angles for the Moon at a specific time. Ensure the ephemeris file is opened prior to calling this function.
```Python
import calceph
# Open the ephemeris file
eph = calceph.open("de430.bsp")
# Define time and target
JD0 = 2442457.5
time = 0.0
target = calceph.NAIF_MOON
# Define units for output (e.g., radians for angles, seconds for derivatives)
# For libration angles, we typically use Euler angles.
# CALCEPH_OUTPUT_EULERANGLES is the default if CALCEPH_OUTPUT_NUTATIONANGLES is not specified.
# CALCEPH_UNIT_RAD for angles, CALCEPH_UNIT_SEC for derivatives.
unit = calceph.CALCEPH_UNIT_RAD + calceph.CALCEPH_UNIT_SEC
# Get the orientation (libration angles and derivatives)
PV = eph.orient(JD0, time, target, unit)
# Print the results
print(f"Libration angles (rad): {PV[0:3]}")
print(f"Libration angle derivatives (rad/s): {PV[3:6]}")
# Close the ephemeris file
eph.close()
```
--------------------------------
### Get Name of Earth-Moon Barycenter by NAIF ID
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/calceph.multiple_getnamebyidss.rst
This example demonstrates how to retrieve the name of the Earth-Moon barycenter using its NAIF ID. Ensure the calceph library is imported.
```python
import calceph
# Get the name of the Earth-Moon barycenter (NAIF ID 301)
name = calceph.getnamebyid(301)
print(f"The name for NAIF ID 301 is: {name}")
```
--------------------------------
### Calceph Single File Usage Example
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/condsingle/calceph.single.rst
Demonstrates the equivalent usage of calceph functions for single file access, including opening, computing, and closing the ephemeris file.
```fortran
calceph_sopen("ephemerisfile.dat")
calceph_scompute(46550D0, 0, 3, 12, PV)
calceph_sclose()
```
--------------------------------
### Compute Heliocentric Coordinates for Multiple Times
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/calceph.multiple_compute.rst
This example shows how to compute the heliocentric coordinates of Mars for two different Julian dates. Ensure the `calceph` library is installed and imported.
```python
import calceph
# Define the Julian dates for computation
# 2442457.5 corresponds to 1975-01-01 12:00:00 TT
# 2442457.9 corresponds to 1975-01-01 21:36:00 TT
jd1 = 2442457.5
jd2 = 2442457.9
# Compute heliocentric coordinates for Mars (body ID 4)
# The result will be a list of arrays, one for each time point.
# Each array contains [x, y, z] coordinates in AU.
coords = calceph.multiple_compute([jd1, jd2], 4)
# Print the results
print(f"Heliocentric coordinates of Mars at JD {jd1}:")
print(f" X: {coords[0][0]:.6f} AU, Y: {coords[0][1]:.6f} AU, Z: {coords[0][2]:.6f} AU")
print(f"Heliocentric coordinates of Mars at JD {jd2}:")
print(f" X: {coords[1][0]:.6f} AU, Y: {coords[1][1]:.6f} AU, Z: {coords[1][2]:.6f} AU")
```
--------------------------------
### Get Timespan in Fortran 90
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/examples/multiple_gettimespan.rst
This Fortran 90 example demonstrates retrieving the time span from an ephemeris file using the `F90` calcephapi. Ensure the `f90calceph_open` function is available.
```fortran
integer*8 peph
integer res
integer continuous
double precision firsttime, lasttime
res = f90calceph_open(peph, "example1.dat")
if (res.eq.1) then
if (f90calceph_gettimespan(peph, firsttime, lasttime, continuous).eq.1) then
write (*,*) firsttime, lasttime, countinuous
endif
call f90calceph_close(peph)
endif
```
--------------------------------
### Get Position Record Index in Python
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/examples/multiple_getpositionrecordindex.rst
Uses the calcephpy library to open an ephemeris file and iterate through position records, printing their details. Requires the calcephpy package to be installed.
```Python
from calcephpy import *
peph = CalcephBin.open("example1.dat")
n = peph.getpositionrecordcount()
for j in range(1, n+1):
itarget, icenter, firsttime, lasttime, iframe = peph.getpositionrecordindex(j)
print(itarget, icenter, firsttime, lasttime, iframe)
peph.close()
```
--------------------------------
### Build Calceph Documentation
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/calceph.install.cusage.rst
Generates the documentation for the |LIBRARYNAME|, provided that ENABLE_DOC was set to ON during the CMake configuration.
```bash
cmake --build . --target doc
```
--------------------------------
### Get Constant Values in Fortran 90
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/examples/multiple_getconstantvs.rst
This Fortran 90 example demonstrates retrieving constant values using `f90calceph_open` and `calceph_getconstantvs`. It utilizes allocatable arrays for dynamic sizing.
```Fortran
integer*8 peph
integer res, nvalue
character(len=CALCEPH_MAX_CONSTANTVALUE), allocatable :: mission_units
character(len=CALCEPH_MAX_CONSTANTVALUE) svalue
res = f90calceph_open(peph, "example1.dat")
if (res.eq.1) then
! get the number of values
nvalue = calceph_getconstantss(peph, "MISSION_UNITS", svalue)
! fill the array
allocate(mission_units(1:nvalue))
res = calceph_getconstantvs(peph, "MISSION_UNITS", mission_units, nvalue)
write(*,*) mission_units
call f90calceph_close(peph)
endif
```
--------------------------------
### Get Constant in Mex (MATLAB)
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/examples/multiple_getconstantss.rst
This Mex example for MATLAB shows how to open an ephemeris file and retrieve a constant. It's suitable for users working within the MATLAB environment.
```MATLAB
peph = CalcephBin.open('example1.dat');
UNIT = peph.getconstantss('UNIT')
peph.close();
```
--------------------------------
### Open, Get Constant, Compute Unit, and Close Ephemeris (Python)
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/examples/simple_program.rst
Demonstrates opening an ephemeris, getting a constant, computing a unit vector, and closing the ephemeris using the Python wrapper. Requires 'example1.dat'.
```Python
from calcephpy import *
peph = CalcephBin.open("example1.dat")
AU = peph.getconstant("AU")
jd0 = 2451542
dt = 0.5
PV = peph.compute_unit(jd0, dt, NaifId.MOON, NaifId.EARTH,
Constants.UNIT_KM+Constants.UNIT_SEC+Constants.USE_NAIFID)
print(PV)
peph.close()
```
--------------------------------
### C Example: Calceph API Usage
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/condsingle/single_prog.rst
Demonstrates opening an ephemeris file, retrieving constants like AU, EMRAT, and GM_Mer, computing geocentric and heliocentric coordinates, and calculating TT-TDB. Requires 'calceph.h' and an ephemeris file.
```c
#include
#include "calceph.h"
/*-----------------------------------------------------------------*/
/* main program */
/*-----------------------------------------------------------------*/
int main()
{
int res;
double AU, EMRAT, GM_Mer;
double jd0=2451624;
double dt=0.5E0;
double PV[6];
/* open the ephemeris file */
res = calceph_sopen("example1.dat");
if (res)
{
printf("The ephemeris is already opened\n");
/* print the values of AU, EMRAT and GM_Mer */
if (calceph_sgetconstant("AU", &AU))
printf("AU=%23.16E\n", AU);
if (calceph_sgetconstant("EMRAT", &EMRAT))
printf("EMRAT=%23.16E\n", EMRAT);
if (calceph_sgetconstant("GM_Mer", &GM_Mer))
printf("GM_Mer=%23.16E\n", GM_Mer);
/* compute and print the coordinates */
/* the geocentric moon coordinates in AU and AU/day */
calceph_scompute(jd0, dt, 10, 3, PV);
printcoord(PV,"geocentric coordinates of the Moon in AU and AU/day");
/* the value TT-TDB */
calceph_scompute(jd0, dt, 16, 0, PV);
printf("TT-TDB = %23.16E\n", PV[0]);
/* the heliocentric coordinates of Mars */
calceph_scompute(jd0, dt, 4, 11, PV);
printcoord(PV,"heliocentric coordinates of Mars");
/* close the ephemeris file */
calceph_sclose();
printf("The ephemeris is already closed\n");
}
else
{
printf("The ephemeris can't be opened\n");
}
return res;
}
```
--------------------------------
### Get Position Record Index in Mex (MATLAB)
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/examples/multiple_getpositionrecordindex.rst
Opens an ephemeris file and retrieves position record information. This example is intended for use within MATLAB's Mex environment.
```MATLAB
peph = CalcephBin.open('example1.dat');
n = peph.getpositionrecordcount()
for j=1:n
[itarget, icenter, firsttime, lasttime, iframe] = peph.getpositionrecordindex(j)
end
peph.close();
```
--------------------------------
### Get File Version in Mex (MATLAB)
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/examples/multiple_getfileversion.rst
This Mex file example for MATLAB shows how to open an ephemeris file and retrieve its version. It's suitable for integration within MATLAB scripts.
```matlab
peph = CalcephBin.open('example1.dat');
version = peph.getfileversion()
peph.close();
```
--------------------------------
### Test Calceph Build
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/calceph.install.cusage.rst
Verifies that the |LIBRARYNAME| was built correctly. If errors occur, they should be reported with relevant details.
```bash
cmake --build . --target test
```
--------------------------------
### Get Constant in Python
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/examples/multiple_getconstantss.rst
A Python example using the `calcephpy` library to open an ephemeris file, retrieve the 'UNIT' constant, and print its value. This is a concise way to access constants in Python.
```Python
from calcephpy import *
peph = CalcephBin.open("example1.dat")
UNIT = peph.getconstantss("UNIT")
print(UNIT)
peph.close()
```
--------------------------------
### Get Number of Constants in Ephemeris File
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/calceph.multiple_getconstantcount.rst
This example demonstrates how to use the `getconstantcount` function to retrieve and print the number of constants available in an ephemeris file. Ensure the ephemeris file is accessible.
```python
from calceph import calceph
eph = calceph.Ephemeris("de421.bsp")
print(eph.getconstantcount())
```
--------------------------------
### Get Constant Vector Data in Python
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/examples/multiple_getconstantvd.rst
A Python example showing how to open an ephemeris file, retrieve a constant's vector values, print them, and close the file using the calcephpy library.
```Python
from calcephpy import *
peph = CalcephBin.open("example1.dat")
radii = peph.getconstantvd("BODY399_RADII")
print(radii)
peph.close()
```
--------------------------------
### Compile on Unix-like System
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/calceph.interface.f9xusage.rst
Link against the libcalceph library using gfortran on Unix-like systems. Adjust include and library paths if installed in a non-standard location.
```bash
gfortran -I/usr/local/include myprogram.f -o myprogram -lcalceph
```
--------------------------------
### Build PyPI Package
Source: https://github.com/imcce_calceph/calceph/blob/master/readme_for_developers.txt
Build the Python package archive in the 'dist' directory.
```bash
make package_pypi
```
--------------------------------
### Get Constant in Fortran 2003
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/examples/multiple_getconstantss.rst
This Fortran 2003 example shows how to access ephemeris constants. It opens a file, retrieves the 'UNIT' constant, and prints it. Note the use of C_CHAR and C_PTR for interoperability.
```Fortran
character(len=CALCEPH_MAX_CONSTANTVALUE, kind=C_CHAR) UNIT
TYPE(C_PTR) :: peph
peph = calceph_open("example1.dat"//C_NULL_CHAR)
if (C_ASSOCIATED(peph)) then
! print the value of UNIT
if (calceph_getconstantss(peph, "UNIT"//C_NULL_CHAR, UNIT).eq.1) then
write (*,*) "UNIT=", trim(UNIT)
endif
call calceph_close(peph)
endif
```
--------------------------------
### Get Version String
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/calceph.misc.mexusage.rst
Retrieves the version of the Calceph library as a string.
```python
version = calceph_getversion_str()
```
--------------------------------
### Get Position Record Index (Fortran 90)
Source: https://github.com/imcce_calceph/calceph/blob/master/doc/source/examples/multiple_getpositionrecordindex2.rst
Shows how to access position record information using Fortran 90. This example opens an ephemeris file and loops through each record to extract and print its details.
```Fortran
integer*8 peph
integer j, itarget, icenter, iframe, iseg
real*8 firsttime, lasttime
integer res
res = f90calceph_open(peph, "example1.dat")
if (res.eq.1) then
do j=1, f90calceph_getpositionrecordcount(peph)
res = f90calceph_getpositionrecordindex2(peph,j,itarget, icenter, firsttime, lasttime, iframe, iseg)
write (*,*) itarget, icenter, firsttime, lasttime, iframe, iseg
enddo
call f90calceph_close(peph)
endif
```