Skip to content

Commit cc641dd

Browse files
committed
Deploying to stdlib-fpm from @ f58da3b 🚀
1 parent 1786fd1 commit cc641dd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+9113
-6576
lines changed

array1.dat

Lines changed: 0 additions & 4 deletions
This file was deleted.

array2.dat

Lines changed: 0 additions & 4 deletions
This file was deleted.

array4.dat

Lines changed: 0 additions & 3 deletions
This file was deleted.

array5.dat

Lines changed: 0 additions & 2 deletions
This file was deleted.

fpm.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ license = "MIT"
44
author = "stdlib contributors"
55
maintainer = "@fortran-lang/stdlib"
66
copyright = "2019-2021 stdlib contributors"
7+
8+
[dev-dependencies]
9+
test-drive.git = "https://github.com/fortran-lang/test-drive"

src/stdlib_io.f90

Lines changed: 49 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ module stdlib_io
1717
! Private API that is exposed so that we can test it in tests
1818
public :: parse_mode
1919

20+
! Format strings with edit descriptors for each type and kind
21+
character(*), parameter :: &
22+
FMT_INT = '(*(i0,1x))', &
23+
FMT_REAL_SP = '(*(es15.8e2,1x))', &
24+
FMT_REAL_DP = '(*(es24.16e3,1x))', &
25+
FMT_REAL_QP = '(*(es44.35e4,1x))', &
26+
FMT_COMPLEX_SP = '(*(es15.8e2,1x,es15.8e2))', &
27+
FMT_COMPLEX_DP = '(*(es24.16e3,1x,es24.16e3))', &
28+
FMT_COMPLEX_QP = '(*(es44.35e4,1x,es44.35e4))'
29+
2030
interface loadtxt
2131
!! version: experimental
2232
!!
@@ -91,11 +101,11 @@ subroutine loadtxt_rsp(filename, d)
91101
ncol = number_of_columns(s)
92102

93103
! determine number or rows
94-
nrow = number_of_rows_numeric(s)
104+
nrow = number_of_rows(s)
95105

96106
allocate(d(nrow, ncol))
97107
do i = 1, nrow
98-
read(s, *) d(i, :)
108+
read(s, FMT_REAL_sp) d(i, :)
99109
end do
100110
close(s)
101111

@@ -138,11 +148,11 @@ subroutine loadtxt_rdp(filename, d)
138148
ncol = number_of_columns(s)
139149

140150
! determine number or rows
141-
nrow = number_of_rows_numeric(s)
151+
nrow = number_of_rows(s)
142152

143153
allocate(d(nrow, ncol))
144154
do i = 1, nrow
145-
read(s, *) d(i, :)
155+
read(s, FMT_REAL_dp) d(i, :)
146156
end do
147157
close(s)
148158

@@ -185,11 +195,11 @@ subroutine loadtxt_rqp(filename, d)
185195
ncol = number_of_columns(s)
186196

187197
! determine number or rows
188-
nrow = number_of_rows_numeric(s)
198+
nrow = number_of_rows(s)
189199

190200
allocate(d(nrow, ncol))
191201
do i = 1, nrow
192-
read(s, *) d(i, :)
202+
read(s, FMT_REAL_qp) d(i, :)
193203
end do
194204
close(s)
195205

@@ -232,11 +242,11 @@ subroutine loadtxt_iint8(filename, d)
232242
ncol = number_of_columns(s)
233243

234244
! determine number or rows
235-
nrow = number_of_rows_numeric(s)
245+
nrow = number_of_rows(s)
236246

237247
allocate(d(nrow, ncol))
238248
do i = 1, nrow
239-
read(s, *) d(i, :)
249+
read(s, *) d(i, :)
240250
end do
241251
close(s)
242252

@@ -279,11 +289,11 @@ subroutine loadtxt_iint16(filename, d)
279289
ncol = number_of_columns(s)
280290

281291
! determine number or rows
282-
nrow = number_of_rows_numeric(s)
292+
nrow = number_of_rows(s)
283293

284294
allocate(d(nrow, ncol))
285295
do i = 1, nrow
286-
read(s, *) d(i, :)
296+
read(s, *) d(i, :)
287297
end do
288298
close(s)
289299

@@ -326,11 +336,11 @@ subroutine loadtxt_iint32(filename, d)
326336
ncol = number_of_columns(s)
327337

328338
! determine number or rows
329-
nrow = number_of_rows_numeric(s)
339+
nrow = number_of_rows(s)
330340

331341
allocate(d(nrow, ncol))
332342
do i = 1, nrow
333-
read(s, *) d(i, :)
343+
read(s, *) d(i, :)
334344
end do
335345
close(s)
336346

@@ -373,11 +383,11 @@ subroutine loadtxt_iint64(filename, d)
373383
ncol = number_of_columns(s)
374384

375385
! determine number or rows
376-
nrow = number_of_rows_numeric(s)
386+
nrow = number_of_rows(s)
377387

378388
allocate(d(nrow, ncol))
379389
do i = 1, nrow
380-
read(s, *) d(i, :)
390+
read(s, *) d(i, :)
381391
end do
382392
close(s)
383393

@@ -418,13 +428,14 @@ subroutine loadtxt_csp(filename, d)
418428

419429
! determine number of columns
420430
ncol = number_of_columns(s)
431+
ncol = ncol / 2
421432

422433
! determine number or rows
423-
nrow = number_of_rows_numeric(s)
434+
nrow = number_of_rows(s)
424435

425436
allocate(d(nrow, ncol))
426437
do i = 1, nrow
427-
read(s, *) d(i, :)
438+
read(s, FMT_COMPLEX_sp) d(i, :)
428439
end do
429440
close(s)
430441

@@ -465,13 +476,14 @@ subroutine loadtxt_cdp(filename, d)
465476

466477
! determine number of columns
467478
ncol = number_of_columns(s)
479+
ncol = ncol / 2
468480

469481
! determine number or rows
470-
nrow = number_of_rows_numeric(s)
482+
nrow = number_of_rows(s)
471483

472484
allocate(d(nrow, ncol))
473485
do i = 1, nrow
474-
read(s, *) d(i, :)
486+
read(s, FMT_COMPLEX_dp) d(i, :)
475487
end do
476488
close(s)
477489

@@ -512,13 +524,14 @@ subroutine loadtxt_cqp(filename, d)
512524

513525
! determine number of columns
514526
ncol = number_of_columns(s)
527+
ncol = ncol / 2
515528

516529
! determine number or rows
517-
nrow = number_of_rows_numeric(s)
530+
nrow = number_of_rows(s)
518531

519532
allocate(d(nrow, ncol))
520533
do i = 1, nrow
521-
read(s, *) d(i, :)
534+
read(s, FMT_COMPLEX_qp) d(i, :)
522535
end do
523536
close(s)
524537

@@ -548,7 +561,7 @@ subroutine savetxt_rsp(filename, d)
548561
integer :: s, i
549562
s = open(filename, "w")
550563
do i = 1, size(d, 1)
551-
write(s, *) d(i, :)
564+
write(s, FMT_REAL_sp) d(i, :)
552565
end do
553566
close(s)
554567
end subroutine savetxt_rsp
@@ -575,7 +588,7 @@ subroutine savetxt_rdp(filename, d)
575588
integer :: s, i
576589
s = open(filename, "w")
577590
do i = 1, size(d, 1)
578-
write(s, *) d(i, :)
591+
write(s, FMT_REAL_dp) d(i, :)
579592
end do
580593
close(s)
581594
end subroutine savetxt_rdp
@@ -602,7 +615,7 @@ subroutine savetxt_rqp(filename, d)
602615
integer :: s, i
603616
s = open(filename, "w")
604617
do i = 1, size(d, 1)
605-
write(s, *) d(i, :)
618+
write(s, FMT_REAL_qp) d(i, :)
606619
end do
607620
close(s)
608621
end subroutine savetxt_rqp
@@ -629,7 +642,7 @@ subroutine savetxt_iint8(filename, d)
629642
integer :: s, i
630643
s = open(filename, "w")
631644
do i = 1, size(d, 1)
632-
write(s, *) d(i, :)
645+
write(s, FMT_INT) d(i, :)
633646
end do
634647
close(s)
635648
end subroutine savetxt_iint8
@@ -656,7 +669,7 @@ subroutine savetxt_iint16(filename, d)
656669
integer :: s, i
657670
s = open(filename, "w")
658671
do i = 1, size(d, 1)
659-
write(s, *) d(i, :)
672+
write(s, FMT_INT) d(i, :)
660673
end do
661674
close(s)
662675
end subroutine savetxt_iint16
@@ -683,7 +696,7 @@ subroutine savetxt_iint32(filename, d)
683696
integer :: s, i
684697
s = open(filename, "w")
685698
do i = 1, size(d, 1)
686-
write(s, *) d(i, :)
699+
write(s, FMT_INT) d(i, :)
687700
end do
688701
close(s)
689702
end subroutine savetxt_iint32
@@ -710,7 +723,7 @@ subroutine savetxt_iint64(filename, d)
710723
integer :: s, i
711724
s = open(filename, "w")
712725
do i = 1, size(d, 1)
713-
write(s, *) d(i, :)
726+
write(s, FMT_INT) d(i, :)
714727
end do
715728
close(s)
716729
end subroutine savetxt_iint64
@@ -737,7 +750,7 @@ subroutine savetxt_csp(filename, d)
737750
integer :: s, i
738751
s = open(filename, "w")
739752
do i = 1, size(d, 1)
740-
write(s, *) d(i, :)
753+
write(s, FMT_COMPLEX_sp) d(i, :)
741754
end do
742755
close(s)
743756
end subroutine savetxt_csp
@@ -764,7 +777,7 @@ subroutine savetxt_cdp(filename, d)
764777
integer :: s, i
765778
s = open(filename, "w")
766779
do i = 1, size(d, 1)
767-
write(s, *) d(i, :)
780+
write(s, FMT_COMPLEX_dp) d(i, :)
768781
end do
769782
close(s)
770783
end subroutine savetxt_cdp
@@ -791,7 +804,7 @@ subroutine savetxt_cqp(filename, d)
791804
integer :: s, i
792805
s = open(filename, "w")
793806
do i = 1, size(d, 1)
794-
write(s, *) d(i, :)
807+
write(s, FMT_COMPLEX_qp) d(i, :)
795808
end do
796809
close(s)
797810
end subroutine savetxt_cqp
@@ -821,36 +834,24 @@ integer function number_of_columns(s)
821834
end function number_of_columns
822835

823836

824-
integer function number_of_rows_numeric(s) result(nrows)
837+
integer function number_of_rows(s) result(nrows)
825838
!! version: experimental
826839
!!
827-
!! determine number or rows
828-
integer,intent(in)::s
840+
!! Determine the number or rows in a file
841+
integer, intent(in)::s
829842
integer :: ios
830843

831-
real :: r
832-
complex :: z
833-
834844
rewind(s)
835845
nrows = 0
836846
do
837-
read(s, *, iostat=ios) r
847+
read(s, *, iostat=ios)
838848
if (ios /= 0) exit
839849
nrows = nrows + 1
840850
end do
841851

842852
rewind(s)
843853

844-
! If there are no rows of real numbers, it may be that they are complex
845-
if( nrows == 0) then
846-
do
847-
read(s, *, iostat=ios) z
848-
if (ios /= 0) exit
849-
nrows = nrows + 1
850-
end do
851-
rewind(s)
852-
end if
853-
end function number_of_rows_numeric
854+
end function number_of_rows
854855

855856

856857
integer function open(filename, mode, iostat) result(u)
@@ -988,4 +989,4 @@ character(3) function parse_mode(mode) result(mode_)
988989

989990
end function parse_mode
990991

991-
end module
992+
end module stdlib_io

0 commit comments

Comments
 (0)