Skip to content

Commit 5a0c9ca

Browse files
committed
fixed an issue with reading integers.
switch to ifort for now to avoid gfortran bugs.
1 parent 38b783d commit 5a0c9ca

File tree

5 files changed

+14
-18
lines changed

5 files changed

+14
-18
lines changed

build.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ FORDMD='fortran-csv-module.md' # FORD config file name
1717

1818
#compiler flags:
1919

20-
FCOMPILER='gnu' #Set compiler to gfortran
21-
FCOMPILERFLAGS='-c -O2 -std=f2008'
20+
#FCOMPILER='gnu' #Set compiler to gfortran
21+
#FCOMPILERFLAGS='-c -O2 -std=f2008'
22+
FCOMPILER='intel' #Set compiler to intel
23+
FCOMPILERFLAGS='-c -O2 -warn -stand f08 -traceback'
2224

2325
#build using FoBiS:
2426

fortran-csv-module.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ docmark_alt:
1111
docmark: !
1212
display: public
1313
protected
14+
private
1415
source: true
1516
graph: true
1617
extra_mods: iso_fortran_env:https://gcc.gnu.org/onlinedocs/gfortran/ISO_005fFORTRAN_005fENV.html

src/csv_module.f90

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,8 @@ end subroutine add_cell
433433
!*****************************************************************************************
434434
!>
435435
! Add a vector to a CSV file. Each element is added as a cell to the current line.
436+
!
437+
!@warning There is some bug here with GFortran 6.1 when `val` is a character string.
436438

437439
subroutine add_vector(me,val,int_fmt,real_fmt,trim_str)
438440

@@ -652,7 +654,7 @@ pure elemental subroutine to_integer(str,val,status_ok)
652654

653655
integer :: istat !! read `iostat` error code
654656

655-
read(str,fmt=*,iostat=istat) val
657+
read(str,fmt=default_int_fmt,iostat=istat) val
656658
if (istat==0) then
657659
status_ok = .true.
658660
else
@@ -896,8 +898,6 @@ subroutine get_real_column(me,icol,r,status_ok)
896898
real(wp),dimension(:),allocatable,intent(out) :: r
897899
logical,intent(out) :: status_ok
898900

899-
integer :: i !! counter
900-
901901
if (allocated(me%csv_data)) then
902902
allocate(r(me%n_rows)) ! size the output vector
903903
call me%get_column(icol,r,status_ok)
@@ -922,8 +922,6 @@ subroutine get_integer_column(me,icol,r,status_ok)
922922
integer(ip),dimension(:),allocatable,intent(out) :: r
923923
logical,intent(out) :: status_ok
924924

925-
integer :: i !! counter
926-
927925
if (allocated(me%csv_data)) then
928926
allocate(r(me%n_rows)) ! size the output vector
929927
call me%get_column(icol,r,status_ok)
@@ -948,8 +946,6 @@ subroutine get_logical_column(me,icol,r,status_ok)
948946
logical,dimension(:),allocatable,intent(out) :: r
949947
logical,intent(out) :: status_ok
950948

951-
integer :: i !! counter
952-
953949
if (allocated(me%csv_data)) then
954950
allocate(r(me%n_rows)) ! size the output vector
955951
call me%get_column(icol,r,status_ok)
@@ -974,8 +970,6 @@ subroutine get_character_column(me,icol,r,status_ok)
974970
character(len=*),dimension(:),allocatable,intent(out) :: r
975971
logical,intent(out) :: status_ok
976972

977-
integer :: i !! counter
978-
979973
if (allocated(me%csv_data)) then
980974
allocate(r(me%n_rows)) ! size the output vector
981975
call me%get_column(icol,r,status_ok)
@@ -1000,8 +994,6 @@ subroutine get_csv_string_column(me,icol,r,status_ok)
1000994
type(csv_string),dimension(:),allocatable,intent(out) :: r
1001995
logical,intent(out) :: status_ok
1002996

1003-
integer :: i !! counter
1004-
1005997
if (allocated(me%csv_data)) then
1006998
allocate(r(me%n_rows)) ! size the output vector
1007999
call me%get_column(icol,r,status_ok)
@@ -1164,7 +1156,6 @@ pure subroutine split(str,token,chunk_size,vals)
11641156
integer :: j !! counters
11651157
character(len=:),allocatable :: temp
11661158
integer,dimension(:),allocatable :: itokens
1167-
logical :: finished !! if we are finished counting the tokens
11681159

11691160
temp = str ! make a copy of the string
11701161
len_token = len(token) ! length of the token

src/tests/csv_test.f90

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,16 @@ program csv_test
6161
write(*,*) ''
6262

6363
! now test creating a CSV:
64-
call f2%open('test2.csv',n_cols=3,status_ok=status_ok)
65-
call f2%add(['x','y','z']) ! add header as vector
64+
call f2%open('test2.csv',n_cols=4,status_ok=status_ok)
65+
call f2%add(['x','y','z','t']) ! add header as vector
6666
call f2%next_row()
6767
call f2%add(1.0_wp) ! add as scalars
6868
call f2%add(2.0_wp)
6969
call f2%add(3.0_wp)
70+
call f2%add(.true.)
7071
call f2%next_row()
7172
call f2%add([4.0_wp,5.0_wp,6.0_wp]) ! add as vectors
73+
call f2%add(.false.)
7274
call f2%next_row()
7375
call f2%close(status_ok)
7476

src/utilities_module.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ module utilities_module
1111

1212
integer,parameter :: max_size_for_insertion_sort = 20 !! max size for using insertion sort.
1313

14-
character(len=*),parameter,public :: default_real_fmt = '(ss,E27.17E4)'
14+
character(len=*),parameter,public :: default_real_fmt = '(E27.17E4)'
1515
!! default real number format statement (for writing real values to strings and files).
16-
character(len=*),parameter,public :: default_int_fmt = '(ss,I0)'
16+
character(len=*),parameter,public :: default_int_fmt = '(I256)'
1717
!! minimum width format for integers
1818
integer(ip),parameter :: rp_safety_factor = 1_ip
1919
integer(ip),parameter :: rp_addl_safety = 2_ip

0 commit comments

Comments
 (0)