Skip to content

foresight_sys ​

foresight_sys, minimal libc interop for the services standard Fortran lacks.

Standard Fortran has neither a file rename nor a sub-second sleep. Both are needed by the live (watch) mode: the output page is rewritten into a temporary file and atomically renamed over the published one (the browser must never read a half-written page), and data files are polled at a fixed cadence.

@note POSIX only for now: rename replaces an existing destination atomically on POSIX, whereas on Windows the C runtime rename fails if the destination exists; nanosleep is POSIX. The timespec layout assumes an LP64 ABI (time_t and long both 64 bit), true on Linux and macOS x86_64/aarch64.

Source: src/lib/foresight_sys.F90

Dependencies

Contents ​

Derived Types ​

timespec ​

POSIX struct timespec.

Attributes: bind(C)

Components ​

NameTypeAttributesDescription
tv_secinteger(kind=c_long)Seconds.
tv_nsecinteger(kind=c_long)Nanoseconds, in [0, 999999999].

Interfaces ​

c_rename ​

c_nanosleep ​

Subroutines ​

rename_file ​

Rename (move) file old to new, replacing new if it exists.

On POSIX the replacement is atomic: a concurrent reader sees either the old or the new new, never a partial file. Both paths must be on the same filesystem.

fortran
subroutine rename_file(old, new, iostat)

Arguments

NameTypeIntentAttributesDescription
oldcharacter(len=*)inCurrent path.
newcharacter(len=*)inTarget path.
iostatinteger(kind=I4P)outoptional0 on success, non-zero on failure; if absent, failure stops.

Call graph

sleep_ms ​

Suspend the calling thread for at least milliseconds ms.

An interruption by a signal resumes the sleep for the remaining interval.

fortran
subroutine sleep_ms(milliseconds)

Arguments

NameTypeIntentAttributesDescription
millisecondsinteger(kind=I8P)inInterval to sleep [ms]; non-positive values return immediately.

Call graph