initialize_csv_file Subroutine

private subroutine initialize_csv_file(me, quote, delimiter, enclose_strings_in_quotes, enclose_all_in_quotes, logical_true_string, logical_false_string, chunk_size, verbose)

Initialize a csv_file.

Type Bound

csv_file

Arguments

Type IntentOptional Attributes Name
class(csv_file), intent(out) :: me
character(len=1), intent(in), optional :: quote

(Default is ")

character(len=1), intent(in), optional :: delimiter

(Default is ,)

logical, intent(in), optional :: enclose_strings_in_quotes

if true, all string cells will be enclosed in quotes. (Default is True)

logical, intent(in), optional :: enclose_all_in_quotes

if true, all cells will be enclosed in quotes. (Default is False)

character(len=1), intent(in), optional :: logical_true_string

when writing a logical true value to a CSV file, this is the string to use (default is T)

character(len=1), intent(in), optional :: logical_false_string

when writing a logical false value to a CSV file, this is the string to use (default is F)

integer, intent(in), optional :: chunk_size

factor for expanding vectors (default is 100)

logical, intent(in), optional :: verbose

print error messages to the console (default is False)


Source Code

    subroutine initialize_csv_file(me,quote,delimiter,&
                                    enclose_strings_in_quotes,&
                                    enclose_all_in_quotes,&
                                    logical_true_string,&
                                    logical_false_string,&
                                    chunk_size,&
                                    verbose)

    implicit none

    class(csv_file),intent(out) :: me
    character(len=1),intent(in),optional :: quote             !! note: can only be one character
                                                              !! (Default is `"`)
    character(len=1),intent(in),optional :: delimiter         !! note: can only be one character
                                                              !! (Default is `,`)
    logical,intent(in),optional :: enclose_strings_in_quotes  !! if true, all string cells
                                                              !! will be enclosed in quotes.
                                                              !! (Default is True)
    logical,intent(in),optional :: enclose_all_in_quotes      !! if true, *all* cells will
                                                              !! be enclosed in quotes.
                                                              !! (Default is False)
    character(len=1),intent(in),optional :: logical_true_string !! when writing a logical `true`
                                                                !! value to a CSV file, this
                                                                !! is the string to use
                                                                !! (default is `T`)
    character(len=1),intent(in),optional :: logical_false_string !! when writing a logical `false`
                                                                 !! value to a CSV file, this
                                                                 !! is the string to use
                                                                 !! (default is `F`)
    integer,intent(in),optional :: chunk_size  !! factor for expanding vectors
                                               !! (default is 100)
    logical,intent(in),optional :: verbose  !! print error messages to the
                                            !! console (default is False)

    if (present(quote)) me%quote = quote
    if (present(delimiter)) me%delimiter = delimiter
    if (present(enclose_strings_in_quotes)) &
        me%enclose_strings_in_quotes = enclose_strings_in_quotes
    if (present(enclose_all_in_quotes)) &
        me%enclose_all_in_quotes = enclose_all_in_quotes
    if (present(logical_true_string))  &
        me%logical_true_string = logical_true_string
    if (present(logical_false_string)) &
        me%logical_false_string = logical_false_string
    if (present(verbose)) me%verbose = verbose
    if (present(chunk_size)) me%chunk_size = chunk_size

    ! override:
    if (me%enclose_all_in_quotes) me%enclose_strings_in_quotes = .true.

    end subroutine initialize_csv_file