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).
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer, | private, | parameter | :: | dp | = | real64 |
the numbers are written in double precision (whatever |
| 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 |
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.
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| character(len=:), | public, | allocatable | :: | s |
the storage |
||
| integer, | public | :: | n | = | 0 |
number of characters used |
| 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) |
Make sure the buffer has room for nchars more characters.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(text_buffer), | intent(inout) | :: | me | |||
| integer, | intent(in) | :: | nchars |
Empty the buffer (the storage is kept, to be reused).
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(text_buffer), | intent(inout) | :: | me |
Append a string.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(text_buffer), | intent(inout) | :: | me | |||
| character(len=*), | intent(in) | :: | str |
Append an integer.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(text_buffer), | intent(inout) | :: | me | |||
| integer, | intent(in) | :: | i |
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).
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(text_buffer), | intent(inout) | :: | me | |||
| real(kind=wp), | intent(in) | :: | x |
the number (converted to double precision, if |
(), correctly rounded to an integer, when the
result is about to . ok is false if
(no exact power of ten).
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=dp), | intent(in) | :: | a | |||
| integer, | intent(in) | :: | k | |||
| integer(kind=int64), | intent(out) | :: | im | |||
| logical, | intent(out) | :: | ok |
Dekker's exact product: exactly (barring overflow), without FMA.
| Type | Intent | Optional | 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 |
Veltkamp's split of a double into two halves of 26 bits: .
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=dp), | intent(in) | :: | a | |||
| real(kind=dp), | intent(out) | :: | h | |||
| real(kind=dp), | intent(out) | :: | l |
Append a JSON array of real numbers ([x1, x2, ...]).
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(text_buffer), | intent(inout) | :: | me | |||
| real(kind=wp), | intent(in), | dimension(:) | :: | 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).
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(text_buffer), | intent(inout) | :: | me | |||
| real(kind=wp), | intent(in), | dimension(:) | :: | x |
Append the decimal digits of an integer.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(text_buffer), | intent(inout) | :: | me | |||
| integer(kind=int64), | intent(in) | :: | i | |||
| logical, | intent(in) | :: | negative |