stringifor_test_parse_large_csv Program

Uses

  • program~~stringifor_test_parse_large_csv~~UsesGraph program~stringifor_test_parse_large_csv stringifor_test_parse_large_csv module~stringifor stringifor program~stringifor_test_parse_large_csv->module~stringifor module~stringifor_string_t stringifor_string_t module~stringifor->module~stringifor_string_t penf penf module~stringifor->penf module~stringifor_string_t->penf befor64 befor64 module~stringifor_string_t->befor64 face face module~stringifor_string_t->face iso_fortran_env iso_fortran_env module~stringifor_string_t->iso_fortran_env

StringiFor csv_naive_parser test.


Calls

program~~stringifor_test_parse_large_csv~~CallsGraph program~stringifor_test_parse_large_csv stringifor_test_parse_large_csv none~join string%join program~stringifor_test_parse_large_csv->none~join proc~read_file~2 string%read_file program~stringifor_test_parse_large_csv->proc~read_file~2 proc~split string%split program~stringifor_test_parse_large_csv->proc~split proc~split_chunked string%split_chunked program~stringifor_test_parse_large_csv->proc~split_chunked proc~join_characters string%join_characters none~join->proc~join_characters proc~join_strings string%join_strings none~join->proc~join_strings proc~chars string%chars proc~read_file~2->proc~chars proc~read_lines~2 string%read_lines proc~read_file~2->proc~read_lines~2 proc~upper string%upper proc~read_file~2->proc~upper proc~partition string%partition proc~split->proc~partition proc~unique string%unique proc~split->proc~unique proc~split_chunked->proc~split proc~end_with string%end_with proc~split_chunked->proc~end_with proc~start_with string%start_with proc~split_chunked->proc~start_with proc~read_line string%read_line proc~read_lines~2->proc~read_line proc~replace string%replace proc~unique->proc~replace proc~read_line->proc~chars proc~read_line->proc~upper proc~replace_one_occurrence string%replace_one_occurrence proc~replace->proc~replace_one_occurrence

Variables

Type Attributes Name Initial
type(string) :: csv

The CSV file as a single stream.

type(string), allocatable :: rows(:)

The CSV table rows.

type(string), allocatable :: columns(:)

The CSV table columns.

type(string), allocatable :: cells(:,:)

The CSV table cells.

integer :: rows_number

The CSV file rows number.

integer :: columns_number

The CSV file columns number.

integer :: c

Counter.

integer :: r

Counter.

logical :: test_passed(1)

List of passed tests.


Source Code

program stringifor_test_parse_large_csv
!< StringiFor `csv_naive_parser` test.
use stringifor

implicit none
type(string)                  :: csv            !< The CSV file as a single stream.
type(string), allocatable     :: rows(:)        !< The CSV table rows.
type(string), allocatable     :: columns(:)     !< The CSV table columns.
type(string), allocatable     :: cells(:,:)     !< The CSV table cells.
integer                       :: rows_number    !< The CSV file rows number.
integer                       :: columns_number !< The CSV file columns number.
integer                       :: c, r           !< Counter.
logical                       :: test_passed(1) !< List of passed tests.

test_passed = .false.

call csv%read_file(file='src/tests/stringifor/stringifor_test_parse_large_csv.csv', is_fast=.true.)
call csv%split_chunked(tokens=rows, sep=new_line('a'), chunks=10) ! get the CSV file rows
rows_number = size(rows, dim=1)                                   ! get the CSV file rows number
columns_number = rows(1)%count(',') + 1                           ! get the CSV file columns number
allocate(cells(1:columns_number, 1:rows_number))                  ! allocate the CSV file cells
do r=1, rows_number                                               ! parse all cells
  call rows(r)%split(tokens=columns, sep=',')                     ! get current columns
  cells(1:columns_number, r) = columns                            ! save current columns into cells
enddo

! now you can do whatever with your parsed data
! print the table in markdown syntax
print "(A)", 'A markdown-formatted table'
print "(A)", ''
print "(A)", '|'//csv%join(array=cells(:, 1), sep='|')//'|'
do c=1, columns_number
   columns(c) = '----' ! re-use columns for printing separators
enddo
print "(A)", '|'//csv%join(array=columns, sep='|')//'|'
do r=2, rows_number
  print "(A)", '|'//csv%join(array=cells(:, r), sep='|')//'|'
enddo
print "(A)", ''

test_passed = .true.
print "(A,L1)", new_line('a')//'Are all tests passed? ', all(test_passed)
endprogram stringifor_test_parse_large_csv