text_buffer Derived Type

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

  • 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

procedure, public :: clear

empty it (keeping the storage)

  • 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

procedure, public :: add_str

append a string

  • 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

procedure, public :: add_int

append an integer

  • 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

procedure, public :: add_real

append a real number (JSON syntax)

  • 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)

procedure, public :: add_real_array

append a JSON array of real numbers

  • 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

procedure, public :: add_real_list

append real numbers separated by commas (no brackets)

  • 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

Source Code

    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.
        character(len=:),allocatable :: s  !! the storage
        integer :: n = 0  !! number of characters used
    contains
        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)
    end type text_buffer