11#:include "common.fypp"
22
3- #:set KINDS_TYPES = REAL_KINDS_TYPES + INT_KINDS_TYPES
3+ #:set KINDS_TYPES = REAL_KINDS_TYPES + INT_KINDS_TYPES + CMPLX_KINDS_TYPES
44
55module stdlib_experimental_io
66
@@ -18,21 +18,21 @@ module stdlib_experimental_io
1818 public :: parse_mode
1919
2020 interface loadtxt
21- #:for k1, _ in KINDS_TYPES
22- module procedure loadtxt_${k1}$
21+ #:for k1, t1 in KINDS_TYPES
22+ module procedure loadtxt_${t1[0]}$${ k1}$
2323 #:endfor
2424 end interface loadtxt
2525
2626 interface savetxt
27- #:for k1, _ in KINDS_TYPES
28- module procedure savetxt_${k1}$
27+ #:for k1, t1 in KINDS_TYPES
28+ module procedure savetxt_${t1[0]}$${ k1}$
2929 #:endfor
3030 end interface
3131
3232contains
3333
3434 #:for k1, t1 in KINDS_TYPES
35- subroutine loadtxt_${k1}$(filename, d)
35+ subroutine loadtxt_${t1[0]}$ ${k1}$(filename, d)
3636 ! Loads a 2D array from a text file.
3737 !
3838 ! Arguments
@@ -58,7 +58,7 @@ contains
5858 ! ...
5959 !
6060 integer :: s
61- integer :: nrow,ncol,i
61+ integer :: nrow, ncol, i
6262
6363 s = open(filename)
6464
@@ -74,12 +74,12 @@ contains
7474 end do
7575 close(s)
7676
77- end subroutine loadtxt_${k1}$
77+ end subroutine loadtxt_${t1[0]}$${ k1}$
7878 #:endfor
7979
8080
8181 #:for k1, t1 in KINDS_TYPES
82- subroutine savetxt_${k1}$(filename, d)
82+ subroutine savetxt_${t1[0]}$${ k1}$(filename, d)
8383 ! Saves a 2D array into a text file.
8484 !
8585 ! Arguments
@@ -100,13 +100,13 @@ contains
100100 write(s, *) d(i, :)
101101 end do
102102 close(s)
103- end subroutine savetxt_${k1}$
103+ end subroutine savetxt_${t1[0]}$${ k1}$
104104 #:endfor
105105
106106
107107 integer function number_of_columns(s)
108108 ! determine number of columns
109- integer,intent(in):: s
109+ integer,intent(in) :: s
110110
111111 integer :: ios
112112 character :: c
@@ -126,23 +126,33 @@ contains
126126 end function number_of_columns
127127
128128
129- integer function number_of_rows_numeric(s)
129+ integer function number_of_rows_numeric(s) result(nrows)
130130 ! determine number or rows
131131 integer,intent(in)::s
132132 integer :: ios
133133
134- real::r
134+ real :: r
135+ complex :: z
135136
136137 rewind(s)
137- number_of_rows_numeric = 0
138+ nrows = 0
138139 do
139140 read(s, *, iostat=ios) r
140141 if (ios /= 0) exit
141- number_of_rows_numeric = number_of_rows_numeric + 1
142+ nrows = nrows + 1
142143 end do
143144
144145 rewind(s)
145146
147+ ! If there are no rows of real numbers, it may be that they are complex
148+ if( nrows == 0) then
149+ do
150+ read(s, *, iostat=ios) z
151+ if (ios /= 0) exit
152+ nrows = nrows + 1
153+ end do
154+ rewind(s)
155+ end if
146156 end function number_of_rows_numeric
147157
148158
0 commit comments