text_buffer_module Module

A growable text buffer, with fast number formatting, for writing large JSON files directly (see export_trajectory_json_file).

The numbers are formatted with integer arithmetic instead of formatted write statements. This is much faster, and it can run in parallel (gfortran's formatted I/O is serialized by a lock, even for internal writes). The numbers read back exactly (see add_real).


Uses

  • module~~text_buffer_module~~UsesGraph module~text_buffer_module text_buffer_module ieee_arithmetic ieee_arithmetic module~text_buffer_module->ieee_arithmetic iso_fortran_env iso_fortran_env module~text_buffer_module->iso_fortran_env module~halo_kinds_module halo_kinds_module module~text_buffer_module->module~halo_kinds_module module~halo_kinds_module->iso_fortran_env

Used by

  • module~~text_buffer_module~~UsedByGraph module~text_buffer_module text_buffer_module module~halo_module halo_module module~halo_module->module~text_buffer_module module~halo_eclipse_opt_submodule halo_eclipse_opt_submodule module~halo_eclipse_opt_submodule->module~halo_module

Variables

Type Visibility Attributes Name Initial
integer, private, parameter :: dp = real64

the numbers are written in double precision (whatever wp is)

real(kind=dp), private, parameter, dimension(0:22) :: p10 = [1.0e0_dp, 1.0e1_dp, 1.0e2_dp, 1.0e3_dp, 1.0e4_dp, 1.0e5_dp, 1.0e6_dp, 1.0e7_dp, 1.0e8_dp, 1.0e9_dp, 1.0e10_dp, 1.0e11_dp, 1.0e12_dp, 1.0e13_dp, 1.0e14_dp, 1.0e15_dp, 1.0e16_dp, 1.0e17_dp, 1.0e18_dp, 1.0e19_dp, 1.0e20_dp, 1.0e21_dp, 1.0e22_dp]

the powers of ten that are exactly representable in double precision


Derived Types

type, public ::  text_buffer

a text buffer. text is appended with the add methods, and the result is buf%s(1:buf%n). the storage is on the heap, and grows (doubles) as needed.

Components

Type Visibility Attributes Name Initial
character(len=:), public, allocatable :: s

the storage

integer, public :: n = 0

number of characters used

Type-Bound Procedures

procedure, public :: reserve

make room for this many more characters

procedure, public :: clear

empty it (keeping the storage)

procedure, public :: add_str

append a string

procedure, public :: add_int

append an integer

procedure, public :: add_real

append a real number (JSON syntax)

procedure, public :: add_real_array

append a JSON array of real numbers

procedure, public :: add_real_list

append real numbers separated by commas (no brackets)


Subroutines

private pure subroutine reserve(me, nchars)

Make sure the buffer has room for nchars more characters.

Arguments

Type IntentOptional Attributes Name
class(text_buffer), intent(inout) :: me
integer, intent(in) :: nchars

private pure subroutine clear(me)

Empty the buffer (the storage is kept, to be reused).

Arguments

Type IntentOptional Attributes Name
class(text_buffer), intent(inout) :: me

private pure subroutine add_str(me, str)

Append a string.

Arguments

Type IntentOptional Attributes Name
class(text_buffer), intent(inout) :: me
character(len=*), intent(in) :: str

private pure subroutine add_int(me, i)

Append an integer.

Arguments

Type IntentOptional Attributes Name
class(text_buffer), intent(inout) :: me
integer, intent(in) :: i

private pure subroutine add_real(me, x)

Append a real number, in JSON syntax, in double precision (also when wp is quad precision: the trajectory files are for plotting and SPK files, which are double precision), with 17 significant digits (e.g., 8.2031911203980994E+8; trailing zeros are removed, e.g. 1.5E+0).

Read more…

Arguments

Type IntentOptional Attributes Name
class(text_buffer), intent(inout) :: me
real(kind=wp), intent(in) :: x

the number (converted to double precision, if wp is not)

private pure subroutine scaled(a, k, im, ok)

(), correctly rounded to an integer, when the result is about to . ok is false if (no exact power of ten).

Read more…

Arguments

Type IntentOptional Attributes Name
real(kind=dp), intent(in) :: a
integer, intent(in) :: k
integer(kind=int64), intent(out) :: im
logical, intent(out) :: ok

private pure subroutine two_prod(a, b, p, e)

Dekker's exact product: exactly (barring overflow), without FMA.

Arguments

Type IntentOptional Attributes Name
real(kind=dp), intent(in) :: a
real(kind=dp), intent(in) :: b
real(kind=dp), intent(out) :: p
real(kind=dp), intent(out) :: e

private pure subroutine split(a, h, l)

Veltkamp's split of a double into two halves of 26 bits: .

Arguments

Type IntentOptional Attributes Name
real(kind=dp), intent(in) :: a
real(kind=dp), intent(out) :: h
real(kind=dp), intent(out) :: l

private pure subroutine add_real_array(me, x)

Append a JSON array of real numbers ([x1, x2, ...]).

Arguments

Type IntentOptional Attributes Name
class(text_buffer), intent(inout) :: me
real(kind=wp), intent(in), dimension(:) :: x

private pure subroutine add_real_list(me, x)

Append a list of real numbers, separated by commas (x1, x2, ...: the contents of a JSON array, for writing a large array in pieces).

Arguments

Type IntentOptional Attributes Name
class(text_buffer), intent(inout) :: me
real(kind=wp), intent(in), dimension(:) :: x

private pure subroutine add_digits(me, i, negative)

Append the decimal digits of an integer.

Arguments

Type IntentOptional Attributes Name
class(text_buffer), intent(inout) :: me
integer(kind=int64), intent(in) :: i
logical, intent(in) :: negative