Skip to content

Fortran SDK

Install

cd sdk/fortran
cmake -B build
cmake --build build

Produces libtimenow_fortran.a. Requires libcurl.

Quick Start

program main
    use timenow_mod
    implicit none

    type(timenow_client)  :: client
    type(solar_result)    :: solar
    type(jetlag_result)   :: jetlag
    integer               :: ierr

    call timenow_init(client, "http://localhost:8090")

    ! Solar time for London
    call timenow_get_solar(client, 51.5074d0, -0.1278d0, solar, ierr)
    if (ierr == 0) then
        print *, "Solar time: ", trim(solar%local_solar_time)
        print *, "Offset:", solar%civil_solar_offset_min, " min"
    end if

    ! Social jetlag
    call timenow_get_jetlag(client, 39.47d0, 75.99d0, jetlag, ierr)
    if (ierr == 0) then
        print *, "Risk: ", trim(jetlag%risk_level)
    end if

    call timenow_cleanup(client)
end program

Link with: gfortran myapp.f90 -ltimenow_fortran -lcurl -o myapp

Subroutines

Subroutine Parameters Output API endpoint
timenow_init client [, base_url]
timenow_cleanup client
timenow_get_solar client, lat, lng, result, ierr solar_result GET /solar
timenow_get_jetlag client, lat, lng, result, ierr jetlag_result GET /solar/jetlag
timenow_get_prayer client, lat, lng, json_buf, ierr raw JSON GET /solar/prayer
timenow_get_almanac client, lat, lng, json_buf, ierr raw JSON GET /solar/almanac
timenow_get_health client, json_buf, ierr raw JSON GET /health
timenow_get_raw client, endpoint, json_buf, ierr raw JSON Any GET

Types

type :: timenow_client
    character(len=256) :: base_url = 'http://localhost:8090'
    type(c_ptr)        :: curl_handle = c_null_ptr
end type

type :: solar_result
    real(c_double)     :: lat, lng
    character(len=64)  :: local_solar_time, solar_noon, sunrise, sunset
    real(c_double)     :: solar_elevation_deg, civil_solar_offset_min
    character(len=4096):: raw_json
end type

type :: jetlag_result
    character(len=32)  :: risk_level
    real(c_double)     :: civil_solar_offset_min, weekly_sleep_loss_min, annual_sleep_loss_h
    character(len=128) :: equivalent_flight
    character(len=256) :: verdict
    character(len=4096):: raw_json
end type

Error Handling

All subroutines use an ierr integer output parameter:

  • 0 — success
  • 1–99 — libcurl error code
  • ≥400 — HTTP status code
call timenow_get_solar(client, 999.0d0, 0.0d0, solar, ierr)
if (ierr /= 0) then
    print *, "Error code:", ierr
end if